=head1 NAME libptytty - OS independent and secure pty/tty and utmp/wtmp/lastlog handling =head1 SYNOPSIS -lptytty =head1 DESCRIPTION TODO =head1 SECURITY CONSIDERATIONS I<< B >> If you are a typical terminal-like program that just wants one or more ptys, you should call the C method as the very first thing in your program: int main (int argc, char *argv[]) { // do nothing here ptytty::init (); // initialise, parse arguments, etc. } This checks wether the program runs setuid or setgid. If yes then it will fork a helper process and drop privileges. Some programs need finer control over if and when this helper process is started, and if and how to drop privileges. For those programs, the methods C and C are more useful. =head1 THE ptytty CLASS =head2 STATIC METHODS =over 4 =item ptytty::init () The default way to initialise libptytty. Must be called imemdiately as the first thing in the C
function, or earlier e.g. during static construction time. The earlier, the better. This method checks wether the program runs with setuid/setgid permissions and, if yes, spawns a helper process for pty/tty management. IT then drops the privileges completely, so the actual program runs without setuid/setgid privileges. =item ptytty::use_helper () TODO =item ptytty::drop_privileges () Drops privileges completely, i.e. sets real, effective and saved user id to the real user id. Also aborts if this cnanot be achieved. Useful to make sure that the process doesn't run with special privileges. =item bool success = ptytty::send_fd (int socket, int fd) Utility method to send a file descriptor over a unix domain socket. Returns true if successful, false otherwise. This method is only exposed for your convinience and is not required for normal operation. =item int fd = ptytty::recv_fd (int socket) Utility method to receive a file descriptor over a unix domain socket. Returns the fd if sucecssful and C<-1> otherwise. This method is only exposed for your convinience and is not required for normal operation. =item ptytty *pty = ptytty::create () Creates new ptytty object. Creation does not yet do anything besides allocating the structure. A static method is used because the actual ptytty implementation can differ at runtime, so you need a dynamic object creation facility. =back =head2 DYNAMIC/SESSION-RELATED DATA MEMBERS AND METHODS =over 4 =item int pty_fd = pty->pty =item int tty_fd = pty->tty These members contain the pty and tty file descriptors, respectively. They initially contain C<-1> until a successful to C. =item bool success = pty->get () Tries to find, allocate and initialise a new pty/tty pair. Returns C when successful. =item pty->login (int cmd_pid, bool login_shell, const char *hostname) Creates an entry in the systems session database(s) (utmp, wtmp, lastlog). C must be the pid of the process representing the session (such as the login shell), C defines wether the session is associated with a login, which influences wether wtmp and lastlog entries are created, and C should identify the "hostname" the user logs in from, which often is the value of the C variable or tty line in case of local logins. Calling this method is optional. A session starts at the time of the login call and extends until the ptytty object is destroyed. =item pty->close_tty () Closes the tty. Useful after forking in the parent/pty process. =item bool success = pty->make_controlling_tty () Tries to make the pty/tty pair the controlling terminal of the current process. Useful after forking in the child/tty process. =item pty->set_utf8_mode (bool on) On systems supporting special UTF-8 line disciplines (e.g. Linux), tries to enable it for the given pty. Can be called at any time to change the mode. =back =head1 BUGS You kiddin'? =head1 AUTHORS Emanuele Giaquinta L<< >>, Marc Alexander Lehmann L<< >>.