| 1 |
root |
1.1 |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> |
| 2 |
|
|
<html xmlns="http://www.w3.org/1999/xhtml"> |
| 3 |
|
|
<head> |
| 4 |
|
|
<title>libptytty - OS independent and secure pty/tty and utmp/wtmp/lastlog handling</title> |
| 5 |
|
|
<link rev="made" href="mailto:perl-binary@plan9.de" /> |
| 6 |
|
|
</head> |
| 7 |
|
|
|
| 8 |
|
|
<body style="background-color: white"> |
| 9 |
|
|
|
| 10 |
|
|
<p><a name="__index__"></a></p> |
| 11 |
|
|
<!-- INDEX BEGIN --> |
| 12 |
|
|
|
| 13 |
|
|
<ul> |
| 14 |
|
|
|
| 15 |
|
|
<li><a href="#name">NAME</a></li> |
| 16 |
|
|
<li><a href="#synopsis">SYNOPSIS</a></li> |
| 17 |
|
|
<li><a href="#description">DESCRIPTION</a></li> |
| 18 |
root |
1.2 |
<li><a href="#security_considerations">SECURITY CONSIDERATIONS</a></li> |
| 19 |
|
|
<li><a href="#c___interface__the_ptytty_class">C++ INTERFACE: THE ptytty CLASS</a></li> |
| 20 |
|
|
<ul> |
| 21 |
|
|
|
| 22 |
|
|
<li><a href="#static_methods">STATIC METHODS</a></li> |
| 23 |
|
|
<li><a href="#dynamic_sessionrelated_data_members_and_methods">DYNAMIC/SESSION-RELATED DATA MEMBERS AND METHODS</a></li> |
| 24 |
|
|
</ul> |
| 25 |
|
|
|
| 26 |
|
|
<li><a href="#c_interface__the_ptytty_family_of_functions">C INTERFACE: THE ptytty FAMILY OF FUNCTIONS</a></li> |
| 27 |
root |
1.1 |
<li><a href="#bugs">BUGS</a></li> |
| 28 |
|
|
<li><a href="#authors">AUTHORS</a></li> |
| 29 |
|
|
</ul> |
| 30 |
|
|
<!-- INDEX END --> |
| 31 |
|
|
|
| 32 |
|
|
<hr /> |
| 33 |
|
|
<p> |
| 34 |
|
|
</p> |
| 35 |
|
|
<h1><a name="name">NAME</a></h1> |
| 36 |
|
|
<p>libptytty - OS independent and secure pty/tty and utmp/wtmp/lastlog handling</p> |
| 37 |
|
|
<p> |
| 38 |
|
|
</p> |
| 39 |
|
|
<hr /> |
| 40 |
|
|
<h1><a name="synopsis">SYNOPSIS</a></h1> |
| 41 |
|
|
<pre> |
| 42 |
|
|
-lptytty</pre> |
| 43 |
|
|
<p> |
| 44 |
|
|
</p> |
| 45 |
|
|
<hr /> |
| 46 |
|
|
<h1><a name="description">DESCRIPTION</a></h1> |
| 47 |
root |
1.2 |
<p>TODO</p> |
| 48 |
|
|
<p> |
| 49 |
|
|
</p> |
| 50 |
|
|
<hr /> |
| 51 |
|
|
<h1><a name="security_considerations">SECURITY CONSIDERATIONS</a></h1> |
| 52 |
|
|
<p><em><strong>It is of paramount importance that you at least read the following |
| 53 |
|
|
paragraph!</strong> </em>></p> |
| 54 |
|
|
<p>If you are a typical terminal-like program that just wants one or more |
| 55 |
|
|
ptys, you should call the <a href="#item_init"><code>ptytty::init ()</code></a> method (C: <a href="#item_ptytty_init"><code>ptytty_init ()</code></a> |
| 56 |
|
|
function) as the very first thing in your program:</p> |
| 57 |
|
|
<pre> |
| 58 |
|
|
int main (int argc, char *argv[]) |
| 59 |
|
|
{ |
| 60 |
|
|
// do nothing here |
| 61 |
|
|
ptytty::init (); |
| 62 |
|
|
// in C: ptytty_init ();</pre> |
| 63 |
|
|
<pre> |
| 64 |
|
|
// initialise, parse arguments, etc. |
| 65 |
|
|
}</pre> |
| 66 |
|
|
<p>This checks wether the program runs setuid or setgid. If yes then it will |
| 67 |
|
|
fork a helper process and drop privileges.</p> |
| 68 |
|
|
<p>Some programs need finer control over if and when this helper process |
| 69 |
|
|
is started, and if and how to drop privileges. For those programs, the |
| 70 |
|
|
methods <code>ptytty::use_helper</code> and <code>ptytty::drop_privileges</code> are more |
| 71 |
|
|
useful.</p> |
| 72 |
root |
1.1 |
<p> |
| 73 |
|
|
</p> |
| 74 |
|
|
<hr /> |
| 75 |
root |
1.2 |
<h1><a name="c___interface__the_ptytty_class">C++ INTERFACE: THE ptytty CLASS</a></h1> |
| 76 |
|
|
<p> |
| 77 |
|
|
</p> |
| 78 |
|
|
<h2><a name="static_methods">STATIC METHODS</a></h2> |
| 79 |
root |
1.1 |
<dl> |
| 80 |
root |
1.2 |
<dt><strong><a name="item_init">ptytty::init ()</a></strong><br /> |
| 81 |
|
|
</dt> |
| 82 |
|
|
<dd> |
| 83 |
|
|
The default way to initialise libptytty. Must be called imemdiately as |
| 84 |
|
|
the first thing in the <code>main</code> function, or earlier e.g. during static |
| 85 |
|
|
construction time. The earlier, the better. |
| 86 |
|
|
</dd> |
| 87 |
|
|
<dd> |
| 88 |
|
|
<p>This method checks wether the program runs with setuid/setgid permissions |
| 89 |
|
|
and, if yes, spawns a helper process for pty/tty management. IT then |
| 90 |
|
|
drops the privileges completely, so the actual program runs without |
| 91 |
|
|
setuid/setgid privileges.</p> |
| 92 |
|
|
</dd> |
| 93 |
|
|
<p></p> |
| 94 |
|
|
<dt><strong><a name="item_use_helper">ptytty::use_helper ()</a></strong><br /> |
| 95 |
|
|
</dt> |
| 96 |
|
|
<dd> |
| 97 |
|
|
Tries to start a helper process that retains privileges even when the |
| 98 |
|
|
calling process does not. This is usually called from <code>ptytty::init</code> when |
| 99 |
|
|
it detects that the program is running setuid or setgid, but can be called |
| 100 |
|
|
manually if it is inconvinient to drop privileges at startup, or when |
| 101 |
|
|
you are not running setuid/setgid but want to drop privileges (e.g. when |
| 102 |
|
|
running as a root-started daemon). |
| 103 |
|
|
</dd> |
| 104 |
|
|
<dd> |
| 105 |
|
|
<p>This method will try not to start more than one helper process. The same |
| 106 |
|
|
helper process cna usually be used form the process starting it an all its |
| 107 |
|
|
fork'ed (not exec'ed) children</p> |
| 108 |
|
|
</dd> |
| 109 |
|
|
<p></p> |
| 110 |
|
|
<dt><strong><a name="item_drop_privileges">ptytty::drop_privileges ()</a></strong><br /> |
| 111 |
|
|
</dt> |
| 112 |
|
|
<dd> |
| 113 |
|
|
Drops privileges completely, i.e. sets real, effective and saved user id |
| 114 |
|
|
to the real user id. Also aborts if this cnanot be achieved. Useful to |
| 115 |
|
|
make sure that the process doesn't run with special privileges. |
| 116 |
|
|
</dd> |
| 117 |
|
|
<p></p> |
| 118 |
|
|
<dt><strong><a name="item_send_fd">bool success = ptytty::send_fd (int socket, int fd)</a></strong><br /> |
| 119 |
|
|
</dt> |
| 120 |
|
|
<dd> |
| 121 |
|
|
Utility method to send a file descriptor over a unix domain |
| 122 |
|
|
socket. Returns true if successful, false otherwise. This method is only |
| 123 |
|
|
exposed for your convinience and is not required for normal operation. |
| 124 |
|
|
</dd> |
| 125 |
|
|
<p></p> |
| 126 |
|
|
<dt><strong><a name="item_recv_fd">int fd = ptytty::recv_fd (int socket)</a></strong><br /> |
| 127 |
|
|
</dt> |
| 128 |
|
|
<dd> |
| 129 |
|
|
Utility method to receive a file descriptor over a unix domain |
| 130 |
|
|
socket. Returns the fd if sucecssful and <code>-1</code> otherwise. This method |
| 131 |
|
|
is only exposed for your convinience and is not required for normal |
| 132 |
|
|
operation. |
| 133 |
|
|
</dd> |
| 134 |
|
|
<p></p> |
| 135 |
|
|
<dt><strong><a name="item_create">ptytty *pty = ptytty::create ()</a></strong><br /> |
| 136 |
root |
1.1 |
</dt> |
| 137 |
|
|
<dd> |
| 138 |
root |
1.2 |
Creates new ptytty object. Creation does not yet do anything besides |
| 139 |
|
|
allocating the structure. |
| 140 |
|
|
</dd> |
| 141 |
|
|
<dd> |
| 142 |
|
|
<p>A static method is used because the actual ptytty implementation can |
| 143 |
|
|
differ at runtime, so you need a dynamic object creation facility.</p> |
| 144 |
|
|
</dd> |
| 145 |
|
|
<p></p></dl> |
| 146 |
|
|
<p> |
| 147 |
|
|
</p> |
| 148 |
|
|
<h2><a name="dynamic_sessionrelated_data_members_and_methods">DYNAMIC/SESSION-RELATED DATA MEMBERS AND METHODS</a></h2> |
| 149 |
|
|
<dl> |
| 150 |
|
|
<dt><strong><a name="item_pty">int pty_fd = pty->pty</a></strong><br /> |
| 151 |
|
|
</dt> |
| 152 |
|
|
<dt><strong><a name="item_tty">int tty_fd = pty->tty</a></strong><br /> |
| 153 |
|
|
</dt> |
| 154 |
|
|
<dd> |
| 155 |
|
|
These members contain the pty and tty file descriptors, respectively. They |
| 156 |
|
|
initially contain <code>-1</code> until a successful to <code>ptytty::get</code>. |
| 157 |
|
|
</dd> |
| 158 |
|
|
<p></p> |
| 159 |
|
|
<dt><strong><a name="item_get">bool success = pty->get ()</a></strong><br /> |
| 160 |
|
|
</dt> |
| 161 |
|
|
<dd> |
| 162 |
|
|
Tries to find, allocate and initialise a new pty/tty pair. Returns <code>true</code> |
| 163 |
|
|
when successful. |
| 164 |
|
|
</dd> |
| 165 |
|
|
<p></p> |
| 166 |
|
|
<dt><strong><a name="item_login">pty->login (int cmd_pid, bool login_shell, const char *hostname)</a></strong><br /> |
| 167 |
|
|
</dt> |
| 168 |
|
|
<dd> |
| 169 |
|
|
Creates an entry in the systems session <code>database(s)</code> (utmp, wtmp, lastlog). |
| 170 |
|
|
<code>cmd_pid</code> must be the pid of the process representing the session |
| 171 |
|
|
(such as the login shell), <code>login_shell</code> defines wether the session is |
| 172 |
|
|
associated with a login, which influences wether wtmp and lastlog entries |
| 173 |
|
|
are created, and <code>hostname</code> should identify the ``hostname'' the user logs |
| 174 |
|
|
in from, which often is the value of the <code>DISPLAY</code> variable or tty line |
| 175 |
|
|
in case of local logins. |
| 176 |
|
|
</dd> |
| 177 |
|
|
<dd> |
| 178 |
|
|
<p>Calling this method is optional. A session starts at the time of the login |
| 179 |
|
|
call and extends until the ptytty object is destroyed.</p> |
| 180 |
|
|
</dd> |
| 181 |
|
|
<p></p> |
| 182 |
|
|
<dt><strong><a name="item_close_tty">pty->close_tty ()</a></strong><br /> |
| 183 |
|
|
</dt> |
| 184 |
|
|
<dd> |
| 185 |
|
|
Closes the tty. Useful after forking in the parent/pty process. |
| 186 |
|
|
</dd> |
| 187 |
|
|
<p></p> |
| 188 |
|
|
<dt><strong><a name="item_make_controlling_tty">bool success = pty->make_controlling_tty ()</a></strong><br /> |
| 189 |
|
|
</dt> |
| 190 |
|
|
<dd> |
| 191 |
|
|
Tries to make the pty/tty pair the controlling terminal of the current |
| 192 |
|
|
process. Useful after forking in the child/tty process. |
| 193 |
|
|
</dd> |
| 194 |
|
|
<p></p> |
| 195 |
|
|
<dt><strong><a name="item_set_utf8_mode">pty->set_utf8_mode (bool on)</a></strong><br /> |
| 196 |
|
|
</dt> |
| 197 |
|
|
<dd> |
| 198 |
|
|
On systems supporting special UTF-8 line disciplines (e.g. Linux), tries |
| 199 |
|
|
to enable it for the given pty. Can be called at any time to change the |
| 200 |
|
|
mode. |
| 201 |
|
|
</dd> |
| 202 |
|
|
<p></p></dl> |
| 203 |
|
|
<p> |
| 204 |
|
|
</p> |
| 205 |
|
|
<hr /> |
| 206 |
|
|
<h1><a name="c_interface__the_ptytty_family_of_functions">C INTERFACE: THE ptytty FAMILY OF FUNCTIONS</a></h1> |
| 207 |
|
|
<dl> |
| 208 |
|
|
<dt><strong><a name="item_ptytty_init">ptytty_init ()</a></strong><br /> |
| 209 |
|
|
</dt> |
| 210 |
|
|
<dd> |
| 211 |
|
|
See <a href="#item_init"><code>ptytty::init ()</code></a>. |
| 212 |
|
|
|
| 213 |
|
|
</dd> |
| 214 |
|
|
<dd> |
| 215 |
|
|
<pre> |
| 216 |
|
|
|
| 217 |
|
|
=item PTYTTY ptytty_create ()</pre> |
| 218 |
|
|
</dd> |
| 219 |
|
|
<dd> |
| 220 |
|
|
<p>Creates a new opaque PTYTTY object and returns it. Do not try to access it |
| 221 |
|
|
in any way excecp by testing it for truthness (e.g. <code>if (pty) ....</code>). See |
| 222 |
|
|
<a href="#item_create"><code>ptytty::create ()</code></a>.</p> |
| 223 |
|
|
</dd> |
| 224 |
|
|
<p></p> |
| 225 |
|
|
<dt><strong><a name="item_ptytty_pty">int ptytty_pty (PTYTTY ptytty)</a></strong><br /> |
| 226 |
|
|
</dt> |
| 227 |
|
|
<dd> |
| 228 |
|
|
Return the pty file descriptor. See <a href="#item_pty"><code>pty->pty</code></a>. |
| 229 |
|
|
|
| 230 |
|
|
</dd> |
| 231 |
|
|
<dd> |
| 232 |
|
|
<pre> |
| 233 |
|
|
|
| 234 |
|
|
=item int ptytty_tty (PTYTTY ptytty)</pre> |
| 235 |
|
|
</dd> |
| 236 |
|
|
<dd> |
| 237 |
|
|
<p>Return the tty file descriptor. See <a href="#item_tty"><code>pty->tty</code></a>. |
| 238 |
|
|
</p> |
| 239 |
|
|
</dd> |
| 240 |
|
|
<dd> |
| 241 |
|
|
<pre> |
| 242 |
|
|
|
| 243 |
|
|
=item void ptytty_delete (PTYTTY ptytty)</pre> |
| 244 |
|
|
</dd> |
| 245 |
|
|
<dd> |
| 246 |
|
|
<p>Destroys the PTYTTY object, freeing the pty/tty pair and cleaning up the |
| 247 |
|
|
utmp/wtmp/lastlog databases, if initialised/used. Same as <code>delete pty</code> in |
| 248 |
|
|
C++.</p> |
| 249 |
|
|
</dd> |
| 250 |
|
|
<p></p> |
| 251 |
|
|
<dt><strong><a name="item_ptytty_get">int ptytty_get (PTYTTY ptytty)</a></strong><br /> |
| 252 |
|
|
</dt> |
| 253 |
|
|
<dd> |
| 254 |
|
|
See <a href="#item_get"><code>pty->get</code></a>, returns 0 in case of an error, non-zero otherwise. |
| 255 |
|
|
</dd> |
| 256 |
|
|
<p></p> |
| 257 |
|
|
<dt><strong><a name="item_ptytty_login">void ptytty_login (PTYTTY ptytty, int cmd_pid, bool login_shell, const char *hostname)</a></strong><br /> |
| 258 |
|
|
</dt> |
| 259 |
|
|
<dd> |
| 260 |
|
|
See <a href="#item_login"><code>pty->login</code></a>. |
| 261 |
|
|
</dd> |
| 262 |
|
|
<p></p> |
| 263 |
|
|
<dt><strong><a name="item_ptytty_close_tty">void ptytty_close_tty (PTYTTY ptytty)</a></strong><br /> |
| 264 |
|
|
</dt> |
| 265 |
|
|
<dd> |
| 266 |
|
|
See <a href="#item_close_tty"><code>pty->close_tty</code></a>. |
| 267 |
|
|
|
| 268 |
|
|
</dd> |
| 269 |
|
|
<dd> |
| 270 |
|
|
<pre> |
| 271 |
|
|
|
| 272 |
|
|
=item int ptytty_make_controlling_tty (PTYTTY ptytty)</pre> |
| 273 |
|
|
</dd> |
| 274 |
|
|
<dd> |
| 275 |
|
|
<p>See <a href="#item_make_controlling_tty"><code>pty->make_controlling_tty</code></a>. |
| 276 |
|
|
</p> |
| 277 |
|
|
</dd> |
| 278 |
|
|
<dd> |
| 279 |
|
|
<pre> |
| 280 |
|
|
|
| 281 |
|
|
=item void ptytty_set_utf8_mode (PTYTTY ptytty, int on)</pre> |
| 282 |
|
|
</dd> |
| 283 |
|
|
<dd> |
| 284 |
|
|
<p>See <a href="#item_set_utf8_mode"><code>pty->set_utf8_mode</code></a>.</p> |
| 285 |
|
|
</dd> |
| 286 |
|
|
<p></p> |
| 287 |
|
|
<dt><strong><a name="item_ptytty_drop_privileges">void ptytty_drop_privileges ()</a></strong><br /> |
| 288 |
|
|
</dt> |
| 289 |
|
|
<dd> |
| 290 |
|
|
See <code>ptytty::drop_privileges</code>. |
| 291 |
|
|
|
| 292 |
|
|
</dd> |
| 293 |
|
|
<dd> |
| 294 |
|
|
<pre> |
| 295 |
|
|
|
| 296 |
|
|
=item void ptytty_use_helper ()</pre> |
| 297 |
|
|
</dd> |
| 298 |
|
|
<dd> |
| 299 |
|
|
<p>See <code>ptytty::use_helper</code>. |
| 300 |
|
|
|
| 301 |
|
|
</p> |
| 302 |
root |
1.1 |
</dd> |
| 303 |
|
|
<p></p></dl> |
| 304 |
|
|
<p> |
| 305 |
|
|
</p> |
| 306 |
|
|
<hr /> |
| 307 |
|
|
<h1><a name="bugs">BUGS</a></h1> |
| 308 |
root |
1.2 |
<p>You kiddin'? |
| 309 |
|
|
|
| 310 |
|
|
</p> |
| 311 |
root |
1.1 |
<p> |
| 312 |
|
|
</p> |
| 313 |
|
|
<hr /> |
| 314 |
|
|
<h1><a name="authors">AUTHORS</a></h1> |
| 315 |
|
|
<p>Emanuele Giaquinta <em><a href="mailto:<e.giaquinta@glauco.it"><e.giaquinta@glauco.it</a></em>>, Marc Alexander Lehmann |
| 316 |
root |
1.2 |
<em><a href="mailto:<rxvt-unicode@schmorp.de"><rxvt-unicode@schmorp.de</a></em>>. |
| 317 |
|
|
</p> |
| 318 |
root |
1.1 |
|
| 319 |
|
|
</body> |
| 320 |
|
|
|
| 321 |
|
|
</html> |