chiark / gitweb /
do not shift by 32
[authbind.git] / authbind.1
1 .\" Hey, Emacs!  This is an -*- nroff -*- source file.
2 .\" Authors: Ian Jackson
3 .\" 
4 .\" authbind is Copyright (C) 1998 Ian Jackson
5 .\"
6 .\" This program is free software; you can redistribute it and/or modify
7 .\" it under the terms of the GNU General Public License as published by
8 .\" the Free Software Foundation; either version 2, or (at your option)
9 .\" any later version.
10 .\"
11 .\" This program is distributed in the hope that it will be useful,
12 .\" but WITHOUT ANY WARRANTY; without even the implied warranty of
13 .\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 .\" GNU General Public License for more details.
15 .\"
16 .\" You should have received a copy of the GNU General Public License
17 .\" along with this program; if not, write to the Free Software Foundation,
18 .\" Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 
19 .\"
20 .TH AUTHBIND 1 "30th August 1998" "Debian Project" "Debian Linux manual"
21 .SH NAME 
22 authbind \- bind sockets to privileged ports without root
23 .SH SYNOPSIS
24 .BR authbind
25 .RI [ options "] " program " [" argument " ...]"
26 .SH DESCRIPTION
27 .B authbind
28 allows a program which does not or should not run as root to bind to
29 low-numbered ports in a controlled way.
30 .PP
31 You must invoke the program using
32 .BR authbind ".  " authbind
33 will set up some environment variables, including an
34 .BR LD_PRELOAD ,
35 which will allow the program (including any subprocesses it may run)
36 to bind to low-numbered (<512) ports if the system is configured to
37 allow this.
38 .SH OPTIONS
39 .TP
40 .B --deep
41 Normally,
42 .B authbind
43 arranges for only the program which it directly invokes to be affected
44 by its special version of
45 .BR bind (2).
46 If you specify
47 .B --deep
48 then all programs which that program invokes directly or indirectly
49 will be affected, so long as they do not unset the environment
50 variables set up by
51 .BR authbind .
52 .TP
53 .BI --depth " levels"
54 Causes
55 .B authbind
56 to affect programs which are
57 .I levels
58 deep in the calling graph.  The default is
59 .BR "--depth 1" .
60 .SH ACCESS CONTROL
61 Access to low numbered ports is controlled by permissions and contents
62 of files in a configuration area,
63 .BR /etc/authbind .
64 .PP
65 Firstly,
66 .BI /etc/authbind/byport/ port
67 is tested.  If this file is accessible for execution to the calling
68 user, according to
69 .BR access (2),
70 then binding to the port is authorised.  If the file can be seen not
71 to exist (the existence check returns
72 .BR ENOENT )
73 then further tests will be used to find authorisation; otherwise,
74 binding is not authorised, and the
75 .B bind
76 call will return with the
77 .B errno
78 value from the
79 .BR access (2)
80 call, usually
81 .B EACCES
82 .RI ( "Permission denied" ).
83 .PP
84 Secondly, if that test fails to resolve the matter,
85 .BI /etc/authbind/byaddr/ addr , port
86 (any protocol) or failing that
87 .BI /etc/authbind/byaddr/ addr : port
88 (IPv4 only)
89 is tested, in the same manner as above.  Here
90 .I addr
91 is as from
92 .BR inet_ntop .
93 Since this is not completely predictable for IPv6,
94 for IPv6 a variant of
95 .I addr
96 is also tested which does not contain any ommitted zeroes or colons.
97 .PP
98 Thirdly, if the question is still unresolved, the file
99 .BI /etc/authbind/byuid/ uid
100 will be opened and read.  If the file does not exist then the binding
101 is not authorised and
102 .B bind
103 will return
104 .B EPERM
105 .RI ( "Operation not permitted" ", or " "Not owner" ).
106 If the file does exist it will be searched for a line of the form
107 .nf
108 .IR             addrmin [\fB\-\fR addrmax ]\fB,\fR portmin \fB\-\fR portmax
109 .IB             addr4 / length : portmin , portmax
110 .fi
111 matching the request.
112 The first form requires that the address lies in the
113 relevant range (inclusive at both ends).
114 The second form requires that the initial
115 .I length
116 bits of
117 .I addr
118 match those in the proposed
119 .B bind
120 call and is only available for IPv4.
121 Addresses can
122 be in any form acceptable to inet_pton.  In both cases
123 the proposed port number must lie is in the inclusive range
124 specified.  If such a line is found then the binding is authorised.
125 Otherwise it is not, and
126 .B bind
127 will fail with
128 .B ENOENT
129 .RI ( "No such file or directory" ).
130 .PP
131 In each case above,
132 .TP
133 .I port
134 is the (local) TCP or UDP port number, expressed as an unsigned
135 integer in the minimal non-zero number of digits, and
136 .PP
137 If a read error occurs, or the directory
138 .B /etc/authbind
139 cannot be accessed, then not only will
140 .B bind
141 fail, but an error message will be printed to stderr.  Unrecognised
142 lines in
143 .BI /etc/authbind/byuid/ uid
144 files are silently ignored (as are lines whose
145 .I addr4
146 has non-zero bits more than
147 .I length
148 from the top) or where
149 .I min
150 is larger than
151 .IR max .
152 .PP
153 Authorising binding to ports from 512 to 1023 inclusive is
154 not recommended.  Some protocols (including some versions of NFS)
155 authorise clients by seeing that they are using a port number in this
156 range.  So by authorising a program to be a server for such a port,
157 you are also authorising it to impersonate the whole host for those
158 protocols.  To make sure that this isn't done by accident,
159 if the port number requested is in the range 512-1023, authbind
160 will expect the permission files to have an additional
161 .B !
162 at the start of their leafname.
163 .SH MECHANISM
164 The shared library loaded using
165 .B LD_PRELOAD
166 overrides the
167 .BR bind (2)
168 system call.  When a program invoked via
169 .B authbind
170 calls
171 .B bind
172 to bind a socket to a low-numbered TCP/IP port, and if the program
173 doesn't already have an effective uid of 0, the version of
174 .B bind
175 supposed by
176 .B authbind
177 forks and executes a setuid-root helper program.  For non-TCP/IP
178 sockets, high-numbered ports, or programs which are already root,
179 .B authbind
180 passes the call to the original
181 .BR bind (2)
182 system call, which is found using
183 .BR dlsym (3)
184 with the handle
185 .BR RTLD_NEXT .
186 .PP
187 .SH ERROR HANDLING
188 Usually the normal C error handling mechanisms apply.  If
189 .B authbind
190 cannot find the program it has been asked to execute it will print a
191 message to stderr and exit with code 255.
192 .PP
193 The helper program usually reports back to the shared library with an
194 exit status containing an
195 .B errno
196 value which encodes whether the
197 .B bind
198 was permitted and successful.  This will be returned to the calling
199 program in the usual way.
200 .PP
201 In the case of apparent configuration or other serious errors the
202 library and/or the helper program may cause messages to be printed to
203 the program's stderr, was well as returning -1 from
204 .BR bind .
205 .SH BUGS
206 .B authbind
207 currently only supports IPv4 and IPv6 sockets.
208 Programs which open other kinds
209 of sockets will not benefit from
210 .BR authbind ,
211 but it won't get in their way.
212 .PP
213 The use of
214 .B LD_PRELOAD
215 makes an
216 .B authbind
217 installation specific to a particular C library.  This version is for
218 GNU/Linux libc6 (glibc2).
219 .PP
220 .B authbind
221 may not operate correctly with multithreaded programs.  It is
222 inherently very difficult (if not impossible) to perform the kind of
223 trickery that authbind does while preventing all undesirable
224 interactions between authbind's activities and those of (say) a
225 threading runtime system.
226 .PP
227 It is quite possible that
228 .B authbind
229 and other programs and facilities which use
230 .B LD_PRELOAD
231 may interfere with each other, causing unpredictable behaviour or even
232 core dumps.
233 .B authbind
234 is known sometimes not to work correctly with
235 .BR fakeroot ,
236 for example (even supposing it could be determined what `correctly'
237 means in this context).
238 .PP
239 .B authbind
240 is ineffective with setuid programs, because they do not honour
241 .B LD_PRELOAD
242 references outside the system directories, for security reasons.  (In
243 fact, setuid programs should not honour
244 .B LD_PRELOAD
245 at all.)
246 Of course a setuid-root program does not need
247 .BR authbind ,
248 but it might be useful to apply it to program which are setuid to
249 another user or setgid.  If the author or builder of such a programs
250 wishes it to use authbind they could have it load the
251 .B libauthbind
252 library explicitly rather than via
253 .BR LD_PRELOAD .
254 .PP
255 Some programs may have trouble because
256 .B authbind
257 spawns a child process `under their feet', causing (for example) a
258 .BR fork (2)
259 to happen and
260 .B SIGCHLD
261 signal to be delivered.  Unfortunately the Unix API does not make
262 it possible to deal with this problem in a sane way.
263 .PP
264 The access control configuration scheme is somewhat strange.
265 .SH FILES AND ENVIRONMENT VARIABLES
266 .TP
267 .I /usr/lib/authbind/libauthbind.so.1.0
268 The shared library which
269 .B authbind
270 causes to be loaded using
271 .BR LD_PRELOAD ,
272 and which actually implements the diversion of
273 .BR bind (2)
274 to an external program.
275 .TP
276 .I LD_PRELOAD
277 The variable used by the dynamic linker when starting dynamically
278 linked programs and deciding which shared libraries to load and
279 modifed by the
280 .B authbind
281 program to allow it to override the usual meaning of
282 .BR bind (2) .
283 .TP
284 .I AUTHBIND_LIB
285 If set, forces
286 .B authbind
287 to use its value as the path to the shared library to put in
288 .BR LD_PRELOAD ,
289 instead of the compiled-in value.  In any case, unless
290 .B --deep
291 was specified,
292 .B authbind
293 will set this variable to the name of the library actually added to
294 .BR LD_PRELOAD ,
295 so that the library can find and remove the right entry.
296 .TP
297 .I AUTHBIND_LEVELS
298 This variable is set by
299 .B authbind
300 to the number of levels left from the
301 .B --depth
302 or
303 .B --deep
304 option, minus one.  It is decremented during
305 .B _init
306 by the library on each program call, and the library will remove
307 itself from the
308 .B LD_PRELOAD
309 when it reaches zero.  The special value
310 .B y
311 means
312 .B --deep
313 was specified.
314 .SH SEE ALSO
315 .BR bind (2),
316 .BR authbind\-helper (8),
317 .BR dlsym (3),
318 .BR ld.so (8)
319 .SH AUTHOR
320 .B authbind
321 and this manpage were written by Ian Jackson.  They are
322 Copyright (C)1998,2012
323 by him and released under the GNU General Public Licence; there is NO
324 WARRANTY.  See
325 .B /usr/doc/authbind/copyright
326 and
327 .B /usr/doc/copyright/GPL
328 for details.