libptytty - OS independent and secure pty/tty and utmp/wtmp/lastlog handling
-lptytty
TODO
It is of paramount importance that you at least read the following paragraph! >
If you are a typical terminal-like program that just wants one or more
ptys, you should call the ptytty::init () method (C: ptytty_init ()
function) as the very first thing in your program:
int main (int argc, char *argv[])
{
// do nothing here
ptytty::init ();
// in C: 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 ptytty::use_helper and ptytty::drop_privileges are more
useful.
main 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.
ptytty::init when
it detects that the program is running setuid or setgid, but can be called
manually if it is inconvinient to drop privileges at startup, or when
you are not running setuid/setgid but want to drop privileges (e.g. when
running as a root-started daemon).
This method will try not to start more than one helper process. The same helper process cna usually be used form the process starting it an all its fork'ed (not exec'ed) children
-1 otherwise. This method
is only exposed for your convinience and is not required for normal
operation.
A static method is used because the actual ptytty implementation can differ at runtime, so you need a dynamic object creation facility.
-1 until a successful to ptytty::get.
true
when successful.
database(s) (utmp, wtmp, lastlog).
cmd_pid must be the pid of the process representing the session
(such as the login shell), login_shell defines wether the session is
associated with a login, which influences wether wtmp and lastlog entries
are created, and hostname should identify the ``hostname'' the user logs
in from, which often is the value of the DISPLAY 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.
ptytty::init ().
=item PTYTTY ptytty_create ()
Creates a new opaque PTYTTY object and returns it. Do not try to access it
in any way excecp by testing it for truthness (e.g. if (pty) ....). See
ptytty::create ().
pty->pty.
=item int ptytty_tty (PTYTTY ptytty)
Return the tty file descriptor. See pty->tty.
=item void ptytty_delete (PTYTTY ptytty)
Destroys the PTYTTY object, freeing the pty/tty pair and cleaning up the
utmp/wtmp/lastlog databases, if initialised/used. Same as delete pty in
C++.
pty->get, returns 0 in case of an error, non-zero otherwise.
pty->login.
pty->close_tty.
=item int ptytty_make_controlling_tty (PTYTTY ptytty)
=item void ptytty_set_utf8_mode (PTYTTY ptytty, int on)
See pty->set_utf8_mode.
ptytty::drop_privileges.
=item void ptytty_use_helper ()
See ptytty::use_helper.
You kiddin'?