ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/libptytty/doc/libptytty.3
Revision: 1.1
Committed: Fri Jan 8 11:48:53 2010 UTC (14 years, 6 months ago) by sf-exg
Branch: MAIN
CVS Tags: rel-1_4, rel-9_12
Log Message:
Switch to automake.

File Contents

# User Rev Content
1 sf-exg 1.1 .\" Automatically generated by Pod::Man 2.12 (Pod::Simple 3.05)
2     .\"
3     .\" Standard preamble:
4     .\" ========================================================================
5     .de Sh \" Subsection heading
6     .br
7     .if t .Sp
8     .ne 5
9     .PP
10     \fB\\$1\fR
11     .PP
12     ..
13     .de Sp \" Vertical space (when we can't use .PP)
14     .if t .sp .5v
15     .if n .sp
16     ..
17     .de Vb \" Begin verbatim text
18     .ft CW
19     .nf
20     .ne \\$1
21     ..
22     .de Ve \" End verbatim text
23     .ft R
24     .fi
25     ..
26     .\" Set up some character translations and predefined strings. \*(-- will
27     .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left
28     .\" double quote, and \*(R" will give a right double quote. \*(C+ will
29     .\" give a nicer C++. Capital omega is used to do unbreakable dashes and
30     .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff,
31     .\" nothing in troff, for use with C<>.
32     .tr \(*W-
33     .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'
34     .ie n \{\
35     . ds -- \(*W-
36     . ds PI pi
37     . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch
38     . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch
39     . ds L" ""
40     . ds R" ""
41     . ds C` ""
42     . ds C' ""
43     'br\}
44     .el\{\
45     . ds -- \|\(em\|
46     . ds PI \(*p
47     . ds L" ``
48     . ds R" ''
49     'br\}
50     .\"
51     .\" If the F register is turned on, we'll generate index entries on stderr for
52     .\" titles (.TH), headers (.SH), subsections (.Sh), items (.Ip), and index
53     .\" entries marked with X<> in POD. Of course, you'll have to process the
54     .\" output yourself in some meaningful fashion.
55     .if \nF \{\
56     . de IX
57     . tm Index:\\$1\t\\n%\t"\\$2"
58     ..
59     . nr % 0
60     . rr F
61     .\}
62     .\"
63     .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2).
64     .\" Fear. Run. Save yourself. No user-serviceable parts.
65     . \" fudge factors for nroff and troff
66     .if n \{\
67     . ds #H 0
68     . ds #V .8m
69     . ds #F .3m
70     . ds #[ \f1
71     . ds #] \fP
72     .\}
73     .if t \{\
74     . ds #H ((1u-(\\\\n(.fu%2u))*.13m)
75     . ds #V .6m
76     . ds #F 0
77     . ds #[ \&
78     . ds #] \&
79     .\}
80     . \" simple accents for nroff and troff
81     .if n \{\
82     . ds ' \&
83     . ds ` \&
84     . ds ^ \&
85     . ds , \&
86     . ds ~ ~
87     . ds /
88     .\}
89     .if t \{\
90     . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u"
91     . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u'
92     . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u'
93     . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u'
94     . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u'
95     . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u'
96     .\}
97     . \" troff and (daisy-wheel) nroff accents
98     .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V'
99     .ds 8 \h'\*(#H'\(*b\h'-\*(#H'
100     .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#]
101     .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H'
102     .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u'
103     .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#]
104     .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#]
105     .ds ae a\h'-(\w'a'u*4/10)'e
106     .ds Ae A\h'-(\w'A'u*4/10)'E
107     . \" corrections for vroff
108     .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u'
109     .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u'
110     . \" for low resolution devices (crt and lpr)
111     .if \n(.H>23 .if \n(.V>19 \
112     \{\
113     . ds : e
114     . ds 8 ss
115     . ds o a
116     . ds d- d\h'-1'\(ga
117     . ds D- D\h'-1'\(hy
118     . ds th \o'bp'
119     . ds Th \o'LP'
120     . ds ae ae
121     . ds Ae AE
122     .\}
123     .rm #[ #] #H #V #F C
124     .\" ========================================================================
125     .\"
126     .IX Title "libptytty 3"
127     .TH libptytty 3 "2007-12-12" "" "LIBPTYTTY"
128     .\" For nroff, turn off justification. Always turn off hyphenation; it makes
129     .\" way too many mistakes in technical documents.
130     .if n .ad l
131     .nh
132     .SH "NAME"
133     libptytty \- OS independent and secure pty/tty and utmp/wtmp/lastlog handling
134     .SH "SYNOPSIS"
135     .IX Header "SYNOPSIS"
136     .Vb 1
137     \& cc ... \-lptytty
138     \&
139     \& #include <libptytty.h>
140     \&
141     \&
142     \& // C++
143     \& ptytty *pty = ptytty::create ();
144     \&
145     \& if (!pty\->get ())
146     \& // error allocating pty
147     \&
148     \& if (we want utmp)
149     \& pty\->login (process_pid, 0, "remote.host");
150     \& else if (we want utmp AND wtmp/lastlog)
151     \& pty\->login (process_pid, 1, "remote.host");
152     \&
153     \& // we are done with it
154     \& delete pty;
155     \&
156     \&
157     \& // C
158     \& PTYTTY pty = ptytty_create ();
159     \&
160     \& if (!ptytty_get (pty))
161     \& // error allocating pty
162     \&
163     \& if (we want utmp)
164     \& ptytty_login (pty, process_pid, 0, "remote.host");
165     \& else if (we want utmp AND wtmp/lastlog)
166     \& ptytty_login (pty, process_pid, 1, "remote.host");
167     \&
168     \& // we are done with it
169     \& ptytty_delete (pty);
170     .Ve
171     .PP
172     See also the \fIeg/\fR directory, which currently contains the \fIc\-sample.c\fR
173     file that spawns a loginshell from C using libptytty.
174     .SH "DESCRIPTION"
175     .IX Header "DESCRIPTION"
176     Libptytty is a small library that offers pseudo-tty management in an
177     OS-independent way. It was created out of frustration over the many
178     differences of pty/tty handling in different operating systems for the use
179     inside \f(CW\*(C`rxvt\-unicode\*(C'\fR.
180     .PP
181     In addition to offering mere pty/tty management, it also offers session
182     database support (utmp and optional wtmp/lastlog updates for login
183     shells).
184     .PP
185     It also supports fork'ing after startup and dropping privileges in the
186     calling process, so in case the calling process gets compromised by the
187     user starting the program there is less to gain, as only the helper
188     process runs with privileges (e.g. setuid/setgid), which reduces the area
189     of attack immensely.
190     .PP
191     Libptytty is written in \*(C+, but it also offers a C\-only \s-1API\s0.
192     .SH "SECURITY CONSIDERATIONS"
193     .IX Header "SECURITY CONSIDERATIONS"
194     \&\fI\f(BIIt is of paramount importance that you at least read the following
195     paragraph!\fI\fR
196     .PP
197     If you write a typical terminal-like program that just wants one or more
198     ptys, you should call the \f(CW\*(C`ptytty::init ()\*(C'\fR method (C: \f(CW\*(C`ptytty_init ()\*(C'\fR
199     function) as the very first thing in your program:
200     .PP
201     .Vb 5
202     \& int main (int argc, char *argv[])
203     \& {
204     \& // do nothing here
205     \& ptytty::init ();
206     \& // in C: ptytty_init ();
207     \&
208     \& // initialise, parse arguments, etc.
209     \& }
210     .Ve
211     .PP
212     This checks wether the program runs setuid or setgid. If yes then it will
213     fork a helper process and drop privileges.
214     .PP
215     Some programs need finer control over if and when this helper process
216     is started, and if and how to drop privileges. For those programs, the
217     methods \f(CW\*(C`ptytty::use_helper\*(C'\fR and \f(CW\*(C`ptytty::drop_privileges\*(C'\fR (and possibly
218     \&\f(CW\*(C`ptytty::sanitise_stdfd\*(C'\fR) are more useful.
219     .SH "\*(C+ INTERFACE: THE ptytty CLASS"
220     .IX Header " INTERFACE: THE ptytty CLASS"
221     .Sh "\s-1STATIC\s0 \s-1METHODS\s0"
222     .IX Subsection "STATIC METHODS"
223     .IP "ptytty::init ()" 4
224     .IX Item "ptytty::init ()"
225     The default way to initialise libptytty. Must be called immediately as
226     the first thing in the \f(CW\*(C`main\*(C'\fR function, or earlier e.g. during static
227     construction time. The earlier, the better.
228     .Sp
229     This method calls \f(CW\*(C`sanitise_stdf\*(C'\fR and then checks wether the program runs
230     with setuid/setgid permissions and, if yes, spawns a helper process for
231     pty/tty management. It then drops the privileges completely, so the actual
232     program runs without setuid/setgid privileges.
233     .IP "ptytty::use_helper ()" 4
234     .IX Item "ptytty::use_helper ()"
235     Tries to start a helper process that retains privileges even when the
236     calling process does not. This is usually called from \f(CW\*(C`ptytty::init\*(C'\fR when
237     it detects that the program is running setuid or setgid, but can be called
238     manually if it is inconvinient to drop privileges at startup, or when
239     you are not running setuid/setgid but want to drop privileges (e.g. when
240     running as a root-started daemon).
241     .Sp
242     This method will try not to start more than one helper process. The same
243     helper process can usually be used both from the process starting it and
244     all its fork'ed (not exec'ed) children.
245     .IP "ptytty::drop_privileges ()" 4
246     .IX Item "ptytty::drop_privileges ()"
247     Drops privileges completely, i.e. sets real, effective and saved user id
248     to the real user id. Also aborts if this cannot be achieved. Useful to
249     make sure that the process doesn't run with special privileges.
250     .IP "ptytty::sanitise_stdfd ()" 4
251     .IX Item "ptytty::sanitise_stdfd ()"
252     Checks wether file descriptors 0, 1 and 2 (stdin, stdout and stderr) are
253     valid (open) and, if not, connects them to \fI/dev/tty\fR or \fI/dev/null\fR if
254     possible (and aborts otherwise). This is necessary because libptytty might
255     want to output error messages to those descriptors, which at the time of
256     outputting the error message, might be connected to something unsuitable
257     opened by the unsuspecting program itself (this can be a security issue).
258     .IP "bool success = ptytty::send_fd (int socket, int fd)" 4
259     .IX Item "bool success = ptytty::send_fd (int socket, int fd)"
260     Utility method to send a file descriptor over a unix domain
261     socket. Returns true if successful, false otherwise. This method is only
262     exposed for your convinience and is not required for normal operation.
263     .IP "int fd = ptytty::recv_fd (int socket)" 4
264     .IX Item "int fd = ptytty::recv_fd (int socket)"
265     Utility method to receive a file descriptor over a unix domain
266     socket. Returns the fd if sucecssful and \f(CW\*(C`\-1\*(C'\fR otherwise. This method
267     is only exposed for your convinience and is not required for normal
268     operation.
269     .IP "ptytty *pty = ptytty::create ()" 4
270     .IX Item "ptytty *pty = ptytty::create ()"
271     Creates new ptytty object. Creation does not yet do anything besides
272     allocating the structure.
273     .Sp
274     A static method is used because the actual ptytty implementation can
275     differ at runtime, so you need a dynamic object creation facility.
276     .Sh "\s-1DYNAMIC/SESSION\-RELATED\s0 \s-1DATA\s0 \s-1MEMBERS\s0 \s-1AND\s0 \s-1METHODS\s0"
277     .IX Subsection "DYNAMIC/SESSION-RELATED DATA MEMBERS AND METHODS"
278     .IP "int pty_fd = pty\->pty" 4
279     .IX Item "int pty_fd = pty->pty"
280     .PD 0
281     .IP "int tty_fd = pty\->tty" 4
282     .IX Item "int tty_fd = pty->tty"
283     .PD
284     These members contain the pty and tty file descriptors, respectively. They
285     initially contain \f(CW\*(C`\-1\*(C'\fR until a successful to \f(CW\*(C`ptytty::get\*(C'\fR.
286     .IP "bool success = pty\->get ()" 4
287     .IX Item "bool success = pty->get ()"
288     Tries to find, allocate and initialise a new pty/tty pair. Returns \f(CW\*(C`true\*(C'\fR
289     when successful.
290     .IP "pty\->login (int cmd_pid, bool login_shell, const char *hostname)" 4
291     .IX Item "pty->login (int cmd_pid, bool login_shell, const char *hostname)"
292     Creates an entry in the systems session database(s) (utmp, wtmp, lastlog).
293     \&\f(CW\*(C`cmd_pid\*(C'\fR must be the pid of the process representing the session
294     (such as the login shell), \f(CW\*(C`login_shell\*(C'\fR defines wether the session is
295     associated with a login, which influences wether wtmp and lastlog entries
296     are created, and \f(CW\*(C`hostname\*(C'\fR should identify the \*(L"hostname\*(R" the user logs
297     in from, which often is the value of the \f(CW\*(C`DISPLAY\*(C'\fR variable or tty line
298     in case of local logins.
299     .Sp
300     Calling this method is optional. A session starts at the time of the login
301     call and extends until the ptytty object is destroyed.
302     .IP "pty\->close_tty ()" 4
303     .IX Item "pty->close_tty ()"
304     Closes the tty. Useful after forking in the parent/pty process.
305     .IP "bool success = pty\->make_controlling_tty ()" 4
306     .IX Item "bool success = pty->make_controlling_tty ()"
307     Tries to make the pty/tty pair the controlling terminal of the current
308     process. Useful after forking in the child/tty process.
309     .IP "pty\->set_utf8_mode (bool on)" 4
310     .IX Item "pty->set_utf8_mode (bool on)"
311     On systems supporting special \s-1UTF\-8\s0 line disciplines (e.g. Linux), this
312     tries to enable this discipline for the given pty. Can be called at any
313     time to change the mode.
314     .SH "C INTERFACE: THE ptytty FAMILY OF FUNCTIONS"
315     .IX Header "C INTERFACE: THE ptytty FAMILY OF FUNCTIONS"
316     .IP "ptytty_init ()" 4
317     .IX Item "ptytty_init ()"
318     See \f(CW\*(C`ptytty::init ()\*(C'\fR.
319     .IP "\s-1PTYTTY\s0 ptytty_create ()" 4
320     .IX Item "PTYTTY ptytty_create ()"
321     Creates a new opaque \s-1PTYTTY\s0 object and returns it. Do not try to access it
322     in any way except by testing it for truthness (e.g. \f(CW\*(C`if (pty) ....\*(C'\fR). See
323     \&\f(CW\*(C`ptytty::create ()\*(C'\fR.
324     .IP "int ptytty_pty (\s-1PTYTTY\s0 ptytty)" 4
325     .IX Item "int ptytty_pty (PTYTTY ptytty)"
326     Return the pty file descriptor. See \f(CW\*(C`pty\->pty\*(C'\fR.
327     .IP "int ptytty_tty (\s-1PTYTTY\s0 ptytty)" 4
328     .IX Item "int ptytty_tty (PTYTTY ptytty)"
329     Return the tty file descriptor. See \f(CW\*(C`pty\->tty\*(C'\fR.
330     .IP "void ptytty_delete (\s-1PTYTTY\s0 ptytty)" 4
331     .IX Item "void ptytty_delete (PTYTTY ptytty)"
332     Destroys the \s-1PTYTTY\s0 object, freeing the pty/tty pair and cleaning up the
333     utmp/wtmp/lastlog databases, if initialised/used. Same as \f(CW\*(C`delete pty\*(C'\fR in
334     \&\*(C+.
335     .IP "int ptytty_get (\s-1PTYTTY\s0 ptytty)" 4
336     .IX Item "int ptytty_get (PTYTTY ptytty)"
337     See \f(CW\*(C`pty\->get\*(C'\fR, returns 0 in case of an error, non-zero otherwise.
338     .IP "void ptytty_login (\s-1PTYTTY\s0 ptytty, int cmd_pid, bool login_shell, const char *hostname)" 4
339     .IX Item "void ptytty_login (PTYTTY ptytty, int cmd_pid, bool login_shell, const char *hostname)"
340     See \f(CW\*(C`pty\->login\*(C'\fR.
341     .IP "void ptytty_close_tty (\s-1PTYTTY\s0 ptytty)" 4
342     .IX Item "void ptytty_close_tty (PTYTTY ptytty)"
343     See \f(CW\*(C`pty\->close_tty\*(C'\fR.
344     .IP "int ptytty_make_controlling_tty (\s-1PTYTTY\s0 ptytty)" 4
345     .IX Item "int ptytty_make_controlling_tty (PTYTTY ptytty)"
346     See \f(CW\*(C`pty\->make_controlling_tty\*(C'\fR.
347     .IP "void ptytty_set_utf8_mode (\s-1PTYTTY\s0 ptytty, int on)" 4
348     .IX Item "void ptytty_set_utf8_mode (PTYTTY ptytty, int on)"
349     See \f(CW\*(C`pty\->set_utf8_mode\*(C'\fR.
350     .IP "void ptytty_drop_privileges ()" 4
351     .IX Item "void ptytty_drop_privileges ()"
352     See \f(CW\*(C`ptytty::drop_privileges\*(C'\fR.
353     .IP "void ptytty_use_helper ()" 4
354     .IX Item "void ptytty_use_helper ()"
355     See \f(CW\*(C`ptytty::use_helper\*(C'\fR.
356     .SH "BUGS"
357     .IX Header "BUGS"
358     You kiddin'?
359     .SH "AUTHORS"
360     .IX Header "AUTHORS"
361     Emanuele Giaquinta <e.giaquinta@glauco.it>, Marc Alexander Lehmann
362     <rxvt\-unicode@schmorp.de>.