chiark / gitweb /
noip.c, noip.1: Add IPv6 support.
[preload-hacks] / noip.1
1 .de VS
2 .sp 1
3 .RS
4 .nf
5 .ft B
6 ..
7 .de VE
8 .ft R
9 .fi
10 .RE
11 .sp 1
12 ..
13 .TH noip 1 "5 May 2005" "Straylight/Edgeware" "Preload hacks"
14 .SH NAME
15 noip \- run programs without the ability to use IP sockets
16 .SH SYNOPSIS
17 .B noip
18 .RI [ command
19 .RI [ args ...]]
20 .SH DESCRIPTION
21 The
22 .B noip
23 program runs
24 .I command
25 (by default, the user's shell, as determined by the
26 .B SHELL
27 environment variable) in an environment where attempts to use TCP/IP
28 networking are (mostly) transparently translated into the use of
29 Unix-domain sockets in a private directory.
30 .PP
31 There are many programs which use TCP/IP for their own internal
32 communications needs, largely unnecessarily.  This can present security
33 problems: even if a program binds its listening sockets to
34 .BR localhost ,
35 other users on the same system can still connect, and many such programs
36 don't seem to have authentication systems.
37 .PP
38 .B noip
39 addresses this problem by intercepting a program's networking calls and
40 making it use Unix-domain sockets in a private directory instead of
41 TCP/IP.  Now its communications are truly private to the running user.
42 .SS The socket directory
43 The
44 .B noip
45 program keeps its sockets in a directory whose name can be configured,
46 but by default is
47 .BI noip- \c
48 .IR username ,
49 where
50 .I username
51 is determined by the
52 .B USER
53 or
54 .B LOGNAME
55 environment variables, or is
56 .BI uid- \c
57 .IR realuid 
58 in the temporary directory, which in turn is determined by the
59 .B TMPDIR
60 or
61 .B TMP
62 environment variables, or is
63 .BR /tmp .
64 The sockets in this directory are simply named
65 .IB dottedquad : port
66 after the Internet sockets they represent.
67 .PP
68 If the socket directory does not exist when a program running under
69 .B noip
70 starts up, it is created and made readable and writable only by the
71 current user.  Also, it is scanned and any apparently stale sockets are
72 removed.
73 .SS Configuration
74 The operation of
75 .B noip
76 is controlled by a configuration file.  By default,
77 .B noip
78 reads configuration from
79 .B .noip
80 in the calling user's home directory, as determined by the
81 .B HOME
82 environment, or, failing that, looking up the effective user id in the
83 password database.  However, if the environment variable
84 .B NOIP_CONFIG
85 is set, then the file it names is read instead (assuming it exists; if
86 it doesn't, no configuration is read).
87 .PP
88 The configuration file has a simple line-based format.  A line is
89 ignored if it consists only of whitespace, or if its first whitespace
90 character is
91 .RB ` # '.
92 Otherwise, the first whitespace-delimited word is a keyword and the
93 remainder of the line is a value.  The following keywords are
94 recognized.
95 .TP
96 .BR "debug " [\fInumber\fR]
97 If
98 .I number
99 is nonzero, turn debugging on; if it is zero, turn debugging off.  The
100 default, if no
101 .I number
102 is given, is to turn debugging on.  Debugging is written to standard
103 error.  Some debugging is produced before the configuration file is
104 read; the environment variable
105 .B NOIP_DEBUG
106 can be used to control this.
107 .TP
108 .BI "socketdir " directory
109 Store the Unix-domain sockets in
110 .IR directory 
111 rather than the default.  The environment variable
112 .B NOIP_SOCKETDIR
113 can also be used to control which directory is used for sockets.
114 .TP
115 .BI "autoports " min "\-" max
116 Select which ports are used for implicit binding.  Allocating ports can
117 be a bit slow, since checking whether a Unix domain socket is in use is
118 difficult.  A wide range makes things easier, because
119 .B noip
120 starts by trying ports at random from the given range.  The environment
121 variable
122 .B NOIP_AUTOPORTS
123 can also be used to control which ports are assigned automatically.
124 .TP
125 .BI "realbind " acl-entry
126 Add an entry to the
127 .B realbind
128 access control list (ACL).  When a program attempts to
129 .BR bind (2)
130 a socket to an address, the
131 .B realbind
132 ACL is consulted.  If the address is matched, then the program is
133 allowed to bind a real Internet socket to that address; otherwise, the
134 socket is bound to a Unix-domain socket.  Three environment variables
135 are consulted too:
136 .BR NOIP_REALBIND_BEFORE ,
137 .BR NOIP_REALBIND ,
138 and
139 .BR NOIP_REALBIND_AFTER .
140 The
141 .B _BEFORE
142 rules are inserted at the front of the list; the
143 .B _AFTER
144 rules are appended on the end.  Currently, the rules in
145 .B NOIP_REALBIND
146 are also put at the end (before the
147 .B _AFTER
148 rules), though this may change later.
149 .TP
150 .BI "realconnect " acl-entry
151 Add an entry to the
152 .B realconnect
153 access control list (ACL).  When a program attempts to
154 .BR connect (2)
155 a socket to an address, or to contact another socket using
156 .BR sendto (2)
157 or 
158 .BR sendmsg (2),
159 the
160 .B realconnect
161 ACL is consulted.  If the destination address is matched, then the
162 program is allowed to contact the real Internet socket; otherwise, the
163 attempt is made to contact a Unix-domain socket.  Three environment variables
164 are consulted too:
165 .BR NOIP_REALCONNET_BEFORE ,
166 .BR NOIP_REALCONNECT ,
167 and
168 .BR NOIP_REALCONNECT_AFTER .
169 The
170 .B _BEFORE
171 rules are inserted at the front of the list; the
172 .B _AFTER
173 rules are appended on the end.  Currently, the rules in
174 .B NOIP_REALCONNECT
175 are also put at the end (before the
176 .B _AFTER
177 rules), though this may change later.
178 .PP
179 (Aside: An attempt to connect to a remote host may not be a hopeless failure,
180 even if a real IP socket is denied:
181 .B noip
182 deliberately makes no attempt to check that addresses being bound to
183 sockets correspond to locally available addresses; and besides, sockets
184 can be introduced into the directory by other programs simulating remote
185 servers.)
186 .PP
187 An
188 .I acl-entry
189 is a comma-separated list of entries of the form:
190 .IP
191 .BR + | \-
192 .IR address \c
193 .RB [ \- \c
194 .IR address | \c
195 .BR / \c
196 .IR prefix-length ]| \c
197 .BR local | any
198 .RB [ : \c
199 .IR port [ \c
200 .BI \- \c
201 .IR port ]]
202 .PP
203 (The spaces in the above are optional.)
204 .PP
205 The leading sign says whether
206 matching addresses should be 
207 .I accepted
208 .RB (` + ')
209 or
210 .I denied
211 .RB (` \- ').
212 .PP
213 The IP-address portion may be any of the following
214 .TP
215 .B any
216 Matches all addresses.
217 .TP
218 .B local
219 Matches the address of one of the machine's network interfaces.
220 .TP
221 .I address
222 Matches just the given IPv4 or IPv6 address.  An
223 .I address
224 may be enclosed in square brackets; IPv6 addresses must be so enclosed,
225 because colons are significant in the rest of the ACL syntax.
226 .TP
227 .IB address \- address
228 Matches any address which falls in the given range.  Addresses are
229 compared lexicographically, with octets to the left given precedence
230 over octets to the right.
231 .TP
232 .IB address / prefix-length
233 Matches an address in the given network.
234 .PP
235 The port portion may be omitted (which means `match any port'), or may
236 be a single
237 .I port
238 or a range
239 .IB port \- port
240 to match.
241 .PP
242 Range comparisons are always inclusive of both endpoints.
243 .PP
244 ACL entries are processed in the order they appear in the configuration
245 file.  The default action of an ACL, used if none of its entries match,
246 is the opposite of the last actual entry in the list: if the last entry
247 says `accept', then the default is to deny, and vice-versa.  If the ACL
248 is empty, the default is to deny all addresses.
249 .PP
250 For example, it may be useful to allow access at least to a DNS server.
251 This can be accomplished by adding a line
252 .VS
253 realconnect +1.2.3.4:53
254 .VE
255 to the configuration file, where 1.2.3.4 is the IP address of one of
256 your DNS server. 
257 .SS Example applications
258 SLIME is an Emacs extension for doing interactive programming with Lisp
259 systems.  It communicates with the Lisp system using TCP sockets, since
260 Unix-domain sockets are unavailable on Windows, and besides, they are
261 less well supported by Lisp implementations.  Unfortunately, when the
262 author wrote this program, SLIME applied no authentication on its TCP
263 port, allowing any local user to take over the running Lisp.  Worse,
264 some Lisps are unable to bind a listening socket to a particular
265 address, leaving the socket potentially available to anyone on the
266 network.  By running Emacs under
267 .BR noip ,
268 the security hole is closed completely and no messing with
269 authentication secrets is needed.
270 .PP
271 SSH is an excellent tool for secure communications over hostile
272 networks.  In particular, its ability to forward TCP connections to a
273 port on one side of an SSH tunnel to the other side is very useful.
274 However, such a forwarded port is available to all users on the source
275 side of the tunnel.  Using 
276 .B noip
277 and a suitable configuration, a user can restrict access to a forwarded
278 port to himself or a small group.
279 .SH BUGS
280 .B noip
281 is implemented as an
282 .B LD_PRELOAD
283 hack.  It won't work on setuid programs.  Also, perhaps more
284 importantly, it can't do anything to prevent a
285 .I malicious
286 program's use of networking: a program could theoretically issue sockets
287 system calls directly instead of using the C library calls that
288 .B noip
289 intercepts.  It is intended only as a tool for enhancing the security of
290 software written by well-meaning programmers who don't understand the
291 security aspects of writing networking code.
292 .PP
293 It's very hard to tell exactly what state a Unix-domain socket is in.
294 If the filesystem object isn't there, it's not active, but if it
295 .I is
296 then the socket might be in use or it might be stale.
297 .B noip
298 consults
299 .B /proc/net/unix
300 to decide whether a socket is in use, but this can fail in two ways.
301 Firstly, if the socket is created and renamed, the kernel doesn't
302 notice, and
303 .B noip
304 will think that the new name is stale.  Secondly, if the socket is
305 created, used, unlinked while it's still in use, and recreated, then
306 .B noip
307 will think that it's in use when in fact it's gone stale.  Don't mess
308 with
309 .BR noip 's
310 sockets unless you know what you're doing.
311 .PP
312 The procedure to replace a Unix-domain socket by an Internet one is
313 fairly thorough, but there are some missing cases.  In particular, if
314 the socket being bound or connected is a duplicate (using
315 .BR dup (2))
316 then only one of the copies will be fixed.  Similarly, copies owned by
317 child processes will be unaffected.
318 .PP
319 This manual is surprisingly long and complicated for such a simple hack.
320 .SH AUTHOR
321 Mark Wooding, <mdw@distorted.org.uk>