ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/libptytty/doc/libptytty.3.man
Revision: 1.4
Committed: Wed Aug 30 17:36:31 2006 UTC (20 years ago) by root
Content type: application/x-troff-man
Branch: MAIN
CVS Tags: rel-1_1, rel-1_0, rel-1_3, rel-1_2
Changes since 1.3: +13 -10 lines
Log Message:
preliminary sockpuppet support :)

File Contents

# User Rev Content
1 root 1.4 .\" Automatically generated by Pod::Man v1.37, Pod::Parser v1.32
2 root 1.1 .\"
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.4 .TH libptytty 3 "2006-08-30" "" "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 root 1.4 .PP
189     See also the \fIeg/\fR directory, which currently contains the \fIc\-sample.c\fR
190     file that spawns a loginshell from C using libptytty.
191 root 1.1 .SH "DESCRIPTION"
192     .IX Header "DESCRIPTION"
193 root 1.3 Libptytty is a small library that offers pseudo-tty management in an
194     OS-independent way. It was created out of frustration over the many
195     differences of pty/tty handling in different operating systems for the use
196     inside \f(CW\*(C`rxvt\-unicode\*(C'\fR.
197     .PP
198     In addition to offering mere pty/tty management, it also offers session
199     database support (utmp and optional wtmp/lastlog updates for login
200     shells).
201     .PP
202     It also supports fork'ing after startup and dropping privileges in the
203     calling process, so in case the calling process gets compromised by the
204     user starting the program there is less to gain, as only the helper
205     process runs with privileges (e.g. setuid/setgid), which reduces the area
206     of attack immensely.
207     .PP
208     Libptytty is written in \*(C+, but it also offers a C\-only \s-1API\s0.
209 root 1.2 .SH "SECURITY CONSIDERATIONS"
210     .IX Header "SECURITY CONSIDERATIONS"
211     \&\fI\f(BIIt is of paramount importance that you at least read the following
212     paragraph!\fI\fR
213     .PP
214     If you are a typical terminal-like program that just wants one or more
215     ptys, you should call the \f(CW\*(C`ptytty::init ()\*(C'\fR method (C: \f(CW\*(C`ptytty_init ()\*(C'\fR
216     function) as the very first thing in your program:
217     .PP
218     .Vb 5
219     \& int main (int argc, char *argv[])
220     \& {
221     \& // do nothing here
222     \& ptytty::init ();
223     \& // in C: ptytty_init ();
224     .Ve
225     .PP
226     .Vb 2
227     \& // initialise, parse arguments, etc.
228     \& }
229     .Ve
230     .PP
231     This checks wether the program runs setuid or setgid. If yes then it will
232     fork a helper process and drop privileges.
233     .PP
234     Some programs need finer control over if and when this helper process
235     is started, and if and how to drop privileges. For those programs, the
236     methods \f(CW\*(C`ptytty::use_helper\*(C'\fR and \f(CW\*(C`ptytty::drop_privileges\*(C'\fR are more
237     useful.
238     .SH "\*(C+ INTERFACE: THE ptytty CLASS"
239     .IX Header " INTERFACE: THE ptytty CLASS"
240     .Sh "\s-1STATIC\s0 \s-1METHODS\s0"
241     .IX Subsection "STATIC METHODS"
242     .IP "ptytty::init ()" 4
243     .IX Item "ptytty::init ()"
244     The default way to initialise libptytty. Must be called imemdiately as
245     the first thing in the \f(CW\*(C`main\*(C'\fR function, or earlier e.g. during static
246     construction time. The earlier, the better.
247     .Sp
248     This method checks wether the program runs with setuid/setgid permissions
249 root 1.4 and, if yes, spawns a helper process for pty/tty management. It then
250 root 1.2 drops the privileges completely, so the actual program runs without
251     setuid/setgid privileges.
252     .IP "ptytty::use_helper ()" 4
253     .IX Item "ptytty::use_helper ()"
254     Tries to start a helper process that retains privileges even when the
255     calling process does not. This is usually called from \f(CW\*(C`ptytty::init\*(C'\fR when
256     it detects that the program is running setuid or setgid, but can be called
257     manually if it is inconvinient to drop privileges at startup, or when
258     you are not running setuid/setgid but want to drop privileges (e.g. when
259     running as a root-started daemon).
260     .Sp
261     This method will try not to start more than one helper process. The same
262 root 1.4 helper process can usually be used both from the process starting it and
263     all its fork'ed (not exec'ed) children.
264 root 1.2 .IP "ptytty::drop_privileges ()" 4
265     .IX Item "ptytty::drop_privileges ()"
266     Drops privileges completely, i.e. sets real, effective and saved user id
267 root 1.4 to the real user id. Also aborts if this cannot be achieved. Useful to
268 root 1.2 make sure that the process doesn't run with special privileges.
269     .IP "bool success = ptytty::send_fd (int socket, int fd)" 4
270     .IX Item "bool success = ptytty::send_fd (int socket, int fd)"
271     Utility method to send a file descriptor over a unix domain
272     socket. Returns true if successful, false otherwise. This method is only
273     exposed for your convinience and is not required for normal operation.
274     .IP "int fd = ptytty::recv_fd (int socket)" 4
275     .IX Item "int fd = ptytty::recv_fd (int socket)"
276     Utility method to receive a file descriptor over a unix domain
277     socket. Returns the fd if sucecssful and \f(CW\*(C`\-1\*(C'\fR otherwise. This method
278     is only exposed for your convinience and is not required for normal
279     operation.
280     .IP "ptytty *pty = ptytty::create ()" 4
281     .IX Item "ptytty *pty = ptytty::create ()"
282     Creates new ptytty object. Creation does not yet do anything besides
283     allocating the structure.
284     .Sp
285     A static method is used because the actual ptytty implementation can
286     differ at runtime, so you need a dynamic object creation facility.
287     .Sh "\s-1DYNAMIC/SESSION\-RELATED\s0 \s-1DATA\s0 \s-1MEMBERS\s0 \s-1AND\s0 \s-1METHODS\s0"
288     .IX Subsection "DYNAMIC/SESSION-RELATED DATA MEMBERS AND METHODS"
289     .IP "int pty_fd = pty\->pty" 4
290     .IX Item "int pty_fd = pty->pty"
291     .PD 0
292     .IP "int tty_fd = pty\->tty" 4
293     .IX Item "int tty_fd = pty->tty"
294     .PD
295     These members contain the pty and tty file descriptors, respectively. They
296     initially contain \f(CW\*(C`\-1\*(C'\fR until a successful to \f(CW\*(C`ptytty::get\*(C'\fR.
297     .IP "bool success = pty\->get ()" 4
298     .IX Item "bool success = pty->get ()"
299     Tries to find, allocate and initialise a new pty/tty pair. Returns \f(CW\*(C`true\*(C'\fR
300     when successful.
301     .IP "pty\->login (int cmd_pid, bool login_shell, const char *hostname)" 4
302     .IX Item "pty->login (int cmd_pid, bool login_shell, const char *hostname)"
303     Creates an entry in the systems session database(s) (utmp, wtmp, lastlog).
304     \&\f(CW\*(C`cmd_pid\*(C'\fR must be the pid of the process representing the session
305     (such as the login shell), \f(CW\*(C`login_shell\*(C'\fR defines wether the session is
306     associated with a login, which influences wether wtmp and lastlog entries
307     are created, and \f(CW\*(C`hostname\*(C'\fR should identify the \*(L"hostname\*(R" the user logs
308     in from, which often is the value of the \f(CW\*(C`DISPLAY\*(C'\fR variable or tty line
309     in case of local logins.
310     .Sp
311     Calling this method is optional. A session starts at the time of the login
312     call and extends until the ptytty object is destroyed.
313     .IP "pty\->close_tty ()" 4
314     .IX Item "pty->close_tty ()"
315     Closes the tty. Useful after forking in the parent/pty process.
316     .IP "bool success = pty\->make_controlling_tty ()" 4
317     .IX Item "bool success = pty->make_controlling_tty ()"
318     Tries to make the pty/tty pair the controlling terminal of the current
319     process. Useful after forking in the child/tty process.
320     .IP "pty\->set_utf8_mode (bool on)" 4
321     .IX Item "pty->set_utf8_mode (bool on)"
322 root 1.4 On systems supporting special \s-1UTF\-8\s0 line disciplines (e.g. Linux), this
323     tries to enable this discipline for the given pty. Can be called at any
324     time to change the mode.
325 root 1.2 .SH "C INTERFACE: THE ptytty FAMILY OF FUNCTIONS"
326     .IX Header "C INTERFACE: THE ptytty FAMILY OF FUNCTIONS"
327     .IP "ptytty_init ()" 4
328     .IX Item "ptytty_init ()"
329     See \f(CW\*(C`ptytty::init ()\*(C'\fR.
330     .IP "\s-1PTYTTY\s0 ptytty_create ()" 4
331     .IX Item "PTYTTY ptytty_create ()"
332     Creates a new opaque \s-1PTYTTY\s0 object and returns it. Do not try to access it
333 root 1.4 in any way except by testing it for truthness (e.g. \f(CW\*(C`if (pty) ....\*(C'\fR). See
334 root 1.2 \&\f(CW\*(C`ptytty::create ()\*(C'\fR.
335     .IP "int ptytty_pty (\s-1PTYTTY\s0 ptytty)" 4
336     .IX Item "int ptytty_pty (PTYTTY ptytty)"
337     Return the pty file descriptor. See \f(CW\*(C`pty\->pty\*(C'\fR.
338     .IP "int ptytty_tty (\s-1PTYTTY\s0 ptytty)" 4
339     .IX Item "int ptytty_tty (PTYTTY ptytty)"
340     Return the tty file descriptor. See \f(CW\*(C`pty\->tty\*(C'\fR.
341     .IP "void ptytty_delete (\s-1PTYTTY\s0 ptytty)" 4
342     .IX Item "void ptytty_delete (PTYTTY ptytty)"
343     Destroys the \s-1PTYTTY\s0 object, freeing the pty/tty pair and cleaning up the
344     utmp/wtmp/lastlog databases, if initialised/used. Same as \f(CW\*(C`delete pty\*(C'\fR in
345     \&\*(C+.
346     .IP "int ptytty_get (\s-1PTYTTY\s0 ptytty)" 4
347     .IX Item "int ptytty_get (PTYTTY ptytty)"
348     See \f(CW\*(C`pty\->get\*(C'\fR, returns 0 in case of an error, non-zero otherwise.
349     .IP "void ptytty_login (\s-1PTYTTY\s0 ptytty, int cmd_pid, bool login_shell, const char *hostname)" 4
350     .IX Item "void ptytty_login (PTYTTY ptytty, int cmd_pid, bool login_shell, const char *hostname)"
351     See \f(CW\*(C`pty\->login\*(C'\fR.
352     .IP "void ptytty_close_tty (\s-1PTYTTY\s0 ptytty)" 4
353     .IX Item "void ptytty_close_tty (PTYTTY ptytty)"
354     See \f(CW\*(C`pty\->close_tty\*(C'\fR.
355     .IP "int ptytty_make_controlling_tty (\s-1PTYTTY\s0 ptytty)" 4
356     .IX Item "int ptytty_make_controlling_tty (PTYTTY ptytty)"
357     See \f(CW\*(C`pty\->make_controlling_tty\*(C'\fR.
358     .IP "void ptytty_set_utf8_mode (\s-1PTYTTY\s0 ptytty, int on)" 4
359     .IX Item "void ptytty_set_utf8_mode (PTYTTY ptytty, int on)"
360     See \f(CW\*(C`pty\->set_utf8_mode\*(C'\fR.
361     .IP "void ptytty_drop_privileges ()" 4
362     .IX Item "void ptytty_drop_privileges ()"
363     See \f(CW\*(C`ptytty::drop_privileges\*(C'\fR.
364     .IP "void ptytty_use_helper ()" 4
365     .IX Item "void ptytty_use_helper ()"
366     See \f(CW\*(C`ptytty::use_helper\*(C'\fR.
367 root 1.1 .SH "BUGS"
368     .IX Header "BUGS"
369     You kiddin'?
370     .SH "AUTHORS"
371     .IX Header "AUTHORS"
372     Emanuele Giaquinta <e.giaquinta@glauco.it>, Marc Alexander Lehmann
373     <rxvt\-unicode@schmorp.de>.