ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/libptytty/doc/libptytty.3.man
Revision: 1.3
Committed: Mon Jan 23 12:37:09 2006 UTC (20 years, 8 months ago) by root
Content type: application/x-troff-man
Branch: MAIN
CVS Tags: rel-0_1, rel-0_2
Changes since 1.2: +65 -2 lines
Log Message:
*** empty log message ***

File Contents

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