| 1 |
root |
1.1 |
=head1 NAME |
| 2 |
|
|
|
| 3 |
root |
1.2 |
libptytty - OS independent and secure pty/tty and utmp/wtmp/lastlog handling |
| 4 |
root |
1.1 |
|
| 5 |
|
|
=head1 SYNOPSIS |
| 6 |
|
|
|
| 7 |
root |
1.2 |
-lptytty |
| 8 |
root |
1.1 |
|
| 9 |
|
|
=head1 DESCRIPTION |
| 10 |
|
|
|
| 11 |
root |
1.6 |
TODO |
| 12 |
|
|
|
| 13 |
root |
1.4 |
=head1 SECURITY CONSIDERATIONS |
| 14 |
root |
1.3 |
|
| 15 |
ayin |
1.5 |
I<< B<It is of paramount importance that you at least read the following |
| 16 |
root |
1.4 |
paragraph!> >> |
| 17 |
|
|
|
| 18 |
|
|
If you are a typical terminal-like program that just wants one or more |
| 19 |
|
|
ptys, you should call the C<ptytty::init ()> method as the very first |
| 20 |
|
|
thing in your program: |
| 21 |
|
|
|
| 22 |
|
|
int main (int argc, char *argv[]) |
| 23 |
|
|
{ |
| 24 |
|
|
// do nothing here |
| 25 |
|
|
ptytty::init (); |
| 26 |
|
|
|
| 27 |
|
|
// initialise, parse arguments, etc. |
| 28 |
|
|
} |
| 29 |
|
|
|
| 30 |
|
|
This checks wether the program runs setuid or setgid. If yes then it will |
| 31 |
|
|
fork a helper process and drop privileges. |
| 32 |
|
|
|
| 33 |
root |
1.6 |
Some programs need finer control over if and when this helper process |
| 34 |
|
|
is started, and if and how to drop privileges. For those programs, the |
| 35 |
|
|
methods C<ptytty::use_helper> and C<ptytty::drop_privileges> are more |
| 36 |
|
|
useful. |
| 37 |
|
|
|
| 38 |
|
|
=head1 THE ptytty CLASS |
| 39 |
|
|
|
| 40 |
|
|
=head2 STATIC METHODS |
| 41 |
|
|
|
| 42 |
|
|
=over 4 |
| 43 |
|
|
|
| 44 |
|
|
=item ptytty::init () |
| 45 |
|
|
|
| 46 |
|
|
The default way to initialise libptytty. Must be called imemdiately as |
| 47 |
|
|
the first thing in the C<main> function, or earlier e.g. during static |
| 48 |
|
|
construction time. The earlier, the better. |
| 49 |
|
|
|
| 50 |
|
|
This method checks wether the program runs with setuid/setgid permissions |
| 51 |
|
|
and, if yes, spawns a helper process for pty/tty management. IT then |
| 52 |
|
|
drops the privileges completely, so the actual program runs without |
| 53 |
|
|
setuid/setgid privileges. |
| 54 |
|
|
|
| 55 |
|
|
=item ptytty::use_helper () |
| 56 |
|
|
|
| 57 |
|
|
TODO |
| 58 |
|
|
|
| 59 |
|
|
=item ptytty::drop_privileges () |
| 60 |
|
|
|
| 61 |
|
|
Drops privileges completely, i.e. sets real, effective and saved user id |
| 62 |
|
|
to the real user id. Also aborts if this cnanot be achieved. Useful to |
| 63 |
|
|
make sure that the process doesn't run with special privileges. |
| 64 |
|
|
|
| 65 |
|
|
=item bool success = ptytty::send_fd (int socket, int fd) |
| 66 |
|
|
|
| 67 |
|
|
Utility method to send a file descriptor over a unix domain |
| 68 |
|
|
socket. Returns true if successful, false otherwise. This method is only |
| 69 |
|
|
exposed for your convinience and is not required for normal operation. |
| 70 |
|
|
|
| 71 |
|
|
=item int fd = ptytty::recv_fd (int socket) |
| 72 |
|
|
|
| 73 |
|
|
Utility method to receive a file descriptor over a unix domain |
| 74 |
|
|
socket. Returns the fd if sucecssful and C<-1> otherwise. This method |
| 75 |
|
|
is only exposed for your convinience and is not required for normal |
| 76 |
|
|
operation. |
| 77 |
root |
1.4 |
|
| 78 |
root |
1.6 |
=item ptytty *pty = ptytty::create () |
| 79 |
root |
1.3 |
|
| 80 |
root |
1.6 |
Creates new ptytty object. Creation does not yet do anything besides |
| 81 |
|
|
allocating the structure. |
| 82 |
|
|
|
| 83 |
|
|
A static method is used because the actual ptytty implementation can |
| 84 |
|
|
differ at runtime, so you need a dynamic object creation facility. |
| 85 |
|
|
|
| 86 |
|
|
=back |
| 87 |
|
|
|
| 88 |
|
|
=head2 DYNAMIC/SESSION-RELATED DATA MEMBERS AND METHODS |
| 89 |
root |
1.1 |
|
| 90 |
|
|
=over 4 |
| 91 |
|
|
|
| 92 |
root |
1.6 |
=item int pty_fd = pty->pty |
| 93 |
|
|
|
| 94 |
|
|
=item int tty_fd = pty->tty |
| 95 |
|
|
|
| 96 |
|
|
These members contain the pty and tty file descriptors, respectively. They |
| 97 |
|
|
initially contain C<-1> until a successful to C<ptytty::get>. |
| 98 |
|
|
|
| 99 |
|
|
=item bool success = pty->get () |
| 100 |
|
|
|
| 101 |
|
|
Tries to find, allocate and initialise a new pty/tty pair. Returns C<true> |
| 102 |
|
|
when successful. |
| 103 |
|
|
|
| 104 |
|
|
=item pty->login (int cmd_pid, bool login_shell, const char *hostname) |
| 105 |
|
|
|
| 106 |
|
|
Creates an entry in the systems session database(s) (utmp, wtmp, lastlog). |
| 107 |
|
|
C<cmd_pid> must be the pid of the process representing the session |
| 108 |
|
|
(such as the login shell), C<login_shell> defines wether the session is |
| 109 |
|
|
associated with a login, which influences wether wtmp and lastlog entries |
| 110 |
|
|
are created, and C<hostname> should identify the "hostname" the user logs |
| 111 |
|
|
in from, which often is the value of the C<DISPLAY> variable or tty line |
| 112 |
|
|
in case of local logins. |
| 113 |
|
|
|
| 114 |
|
|
Calling this method is optional. A session starts at the time of the login |
| 115 |
|
|
call and extends until the ptytty object is destroyed. |
| 116 |
|
|
|
| 117 |
|
|
=item pty->close_tty () |
| 118 |
|
|
|
| 119 |
|
|
Closes the tty. Useful after forking in the parent/pty process. |
| 120 |
|
|
|
| 121 |
|
|
=item bool success = pty->make_controlling_tty () |
| 122 |
|
|
|
| 123 |
|
|
Tries to make the pty/tty pair the controlling terminal of the current |
| 124 |
|
|
process. Useful after forking in the child/tty process. |
| 125 |
|
|
|
| 126 |
|
|
=item pty->set_utf8_mode (bool on) |
| 127 |
root |
1.1 |
|
| 128 |
root |
1.6 |
On systems supporting special UTF-8 line disciplines (e.g. Linux), tries |
| 129 |
|
|
to enable it for the given pty. Can be called at any time to change the |
| 130 |
|
|
mode. |
| 131 |
root |
1.1 |
|
| 132 |
|
|
=back |
| 133 |
|
|
|
| 134 |
|
|
=head1 BUGS |
| 135 |
|
|
|
| 136 |
|
|
You kiddin'? |
| 137 |
|
|
|
| 138 |
|
|
=head1 AUTHORS |
| 139 |
|
|
|
| 140 |
|
|
Emanuele Giaquinta L<< <e.giaquinta@glauco.it> >>, Marc Alexander Lehmann |
| 141 |
|
|
L<< <rxvt-unicode@schmorp.de> >>. |