3 .\" $Id: fw.1,v 1.17 2003/11/29 20:36:07 mdw Exp $
7 .\" (c) 1999 Straylight/Edgeware
10 .\"----- Licensing notice ---------------------------------------------------
12 .\" This file is part of the `fw' port forwarder.
14 .\" `fw' is free software; you can redistribute it and/or modify
15 .\" it under the terms of the GNU General Public License as published by
16 .\" the Free Software Foundation; either version 2 of the License, or
17 .\" (at your option) any later version.
19 .\" `fw' is distributed in the hope that it will be useful,
20 .\" but WITHOUT ANY WARRANTY; without even the implied warranty of
21 .\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 .\" GNU General Public License for more details.
24 .\" You should have received a copy of the GNU General Public License
25 .\" along with `fw'; if not, write to the Free Software Foundation,
26 .\" Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
28 .\" ---- Revision history ---------------------------------------------------
31 .\" Revision 1.17 2003/11/29 20:36:07 mdw
32 .\" Privileged outgoing connections.
34 .\" Revision 1.16 2003/11/25 14:46:50 mdw
35 .\" Update docco for new options.
37 .\" Revision 1.15 2003/01/24 20:13:04 mdw
38 .\" Fix bogus examples. Explain quoting rules for `exec' endpoints.
40 .\" Revision 1.14 2002/02/23 00:05:12 mdw
41 .\" Fix spacing around full stops (at last!).
43 .\" Revision 1.13 2002/02/22 23:45:01 mdw
44 .\" Add option to change the listen(2) parameter.
46 .\" Revision 1.12 2001/02/23 09:11:29 mdw
47 .\" Update manual style.
49 .\" Revision 1.11 2001/02/05 19:47:11 mdw
50 .\" Minor fixings to wording.
52 .\" Revision 1.10 2001/02/03 20:30:03 mdw
53 .\" Support re-reading config files on SIGHUP.
55 .\" Revision 1.9 2000/03/23 00:37:33 mdw
56 .\" Add option to change user and group after initialization. Naughtily
57 .\" reassign short equivalents of --grammar and --options.
59 .\" Revision 1.8 1999/12/22 15:44:43 mdw
60 .\" Fix some errors, and document new option.
62 .\" Revision 1.7 1999/10/22 22:45:15 mdw
63 .\" Describe new socket connection options.
65 .\" Revision 1.6 1999/10/10 16:46:29 mdw
66 .\" Include grammar and options references at the end of the manual.
68 .\" Revision 1.5 1999/09/26 18:18:05 mdw
69 .\" Remove a fixed bug from the list. Fix some nasty formatting
72 .\" Revision 1.4 1999/08/19 18:32:48 mdw
73 .\" Improve lexical analysis. In particular, `chmod' patterns don't have to
74 .\" be quoted any more.
76 .\" Revision 1.3 1999/07/30 06:49:00 mdw
77 .\" Minor tidying and typo correction.
79 .\" Revision 1.2 1999/07/26 23:31:04 mdw
80 .\" Document lots of new features and syntax.
83 .\"----- Various bits of fancy styling --------------------------------------
85 .\" --- Indented paragraphs with right-aligned tags ---
89 \h'-\w'\fB\\$1\ \fP'u'\fB\\$1\ \fP\c
92 .\" --- Verbatim-oid typesetting ---
106 .\" --- Grammar markup ---
108 .\" This is mainly for the benefit of the automatic scripts which
109 .\" generate the grammar summary.
128 .\" --- Other bits of styling ---
144 .\"--------------------------------------------------------------------------
146 .TH fw 1 "1 July 1999" "Straylight/Edgeware" "fw port forwarder"
148 .\"--------------------------------------------------------------------------
153 .\"--------------------------------------------------------------------------
166 .\"--------------------------------------------------------------------------
171 program is a simple port forwarder. It supports a number of features
172 the author hasn't found in similar programs:
174 .I "Connection logging"
175 Each connection attempt to the forwarder is logged, giving the time of
176 the connection, the DNS-resolved hostname (if available), and the user
177 name resulting from an RFC931 lookup. These lookups are done
178 asynchronously to the main forwarder's operation.
181 Each forwarded port may have an access control list attached to it.
182 Only authorized hosts are allowed to connect. Access control checks are
183 performed by quick checks on the client's IP address.
185 .I "Nonblocking single-process design"
186 The internal structure of the server is completely nonblocking. The
187 connections don't block; the reading and writing don't block; the name
188 lookups don't block. This is all done in a single process, with the
189 single exception of the DNS resolver.
191 .I "Support for Unix-domain sockets"
192 Connections from and to Unix-domain sockets can be handled just as
193 easily as more normal Internet sockets. Access control doesn't work on
194 Unix domain sockets, though. (Yet.)
195 .SS "Command line options"
198 program understands a few simple command line options:
201 Displays a screen of help text on standard output and exits
204 .B "\-v, \-\-version"
205 Writes the version number to standard output and exits successfully.
208 Writes a terse usage summary to standard output and exits successfully.
210 .B "\-G, \-\-grammar"
211 Writes a summary of the configuration file grammar to standard output
212 and exits successfully.
214 .B "\-O, \-\-options"
215 Writes a summary of the source and target options to standard output and
218 .BI "\-f, \-\-file=" file
219 Read configuration information from
224 configuration file statement.
226 .B "\-d, \-\-daemon, \-\-fork"
227 Forks into the background after reading the configuration and
228 initializing properly.
230 .B "\-l, \-\-syslog, \-\-log"
231 Emit logging information to the system log, rather than standard error.
234 Don't output any logging information. This option is not recommended
235 for normal use, although it can make system call traces clearer so I use
238 .BI "\-s, \-\-setuid=" user
239 Change uid to that of
241 which may be either a user name or uid number, after initializing all
242 the sources. This will usually require elevated privileges.
244 .BI "\-g, \-\-setgid=" group
245 Change gid to that of
247 which may be either a group name or gid number, after initializing all
248 the sources. If the operating system understands supplementary groups
249 then the supplementary groups list is altered to include only
252 Any further command line arguments are interpreted as configuration
253 lines to be read. Configuration supplied in command line arguments has
254 precisely the same syntax as configuration in files. If there are no
255 configuration statements on the command line, and no
257 options were supplied, configuration is read from standard input, if
258 stdin is not a terminal.
260 .\"--------------------------------------------------------------------------
261 .SH "CONFIGURATION LANGUAGE"
265 program has a fairly sophisticated configuration language to let you
266 describe which things should be forwarded where and what special
267 features there should be.
268 .SS "Lexical structure"
269 There are four types of characters.
271 .I "word constituent characters"
272 Word constituent characters are gathered together into words.
273 Depending on its surrounding context, a word might act as a keyword or a
274 string. All alphanumerics are word constituents, as is the hyphen
276 Other characters may change their status in future versions.
278 .I "self-delimiting characters"
279 Self-delimiting characters always stand alone. They act as punctuation,
280 shaping the sequence of words into more complex grammatical forms. The
293 are self-delimiting. Note that while some characters, e.g.,
297 require escaping by the shell, they are mostly optional in the grammar
298 and can tend to be omitted in quick hacks at the shell prompt.
300 .I "whitespace characters"
301 Whitespace characters separate words but are otherwise ignored. All
302 `normal' whitespace characters (e.g., space, tab and newline) are
303 considered to be whitespace for these purposes.
305 .I "special characters"
306 There are three special characters. The
308 character, if it appears at the start of a word, introduces a
310 which extends to the end of the current line or command-line argument.
311 Within a word, it behaves like a normal word-constituent character. The
314 escapes the following character causing it to be interpreted as a word
315 constituent regardless of its normal type. The double-quote
317 escapes all characters other than backslashes up to the next
318 double-quote and causes them to be regarded as word constituents. Note
319 that you don't have to quote a whole word. The backslash can escape a
320 quote character allowing you to insert it into a word if really
324 The overall syntax looks a bit like this:
363 If you prefer, the keyword
371 .SS "Sources and targets"
372 Forwarding is set up by attaching
376 Sources are things which are capable of
378 one end of a data flow on their own, while targets are things which are
379 capable of setting up the other end on demand. In the case of a TCP
380 port forwarder, the part which listens for incoming client connections
381 is the source, while the part which sets up outgoing connections to the
382 destination server is the target.
386 does is set up a collection of sources and targets based on your
387 configuration file so that when a source decides to initiate a data
388 flow, it tells its target to set its end up, and then squirts data back
389 and forth between the two until there's no more.
393 they stay around indefinitely setting up multiple attachments to
396 they set up one connection and then disappear. If all the sources
397 defined are transient, then
399 will quit when no more active sources remain and all connections have
404 program is fairly versatile. It allows you to attach any supported type
405 of source to any supported type of target. This will, I hope, be the
406 case in all future versions.
412 depend on the source or target type, and are therefore described in the
413 sections specific to the various types.
415 .SS "Options structure"
416 Most of the objects that
418 knows about (including sources and targets, but also other more specific
419 things such as socket address types) can have their behaviour modified
422 The options available at a particular point in the configuration depend
425 A global option, outside of a
427 has no context unless it is explicitly qualified, and affects global
428 behaviour. A local option, applied to a source or target in a
430 has the context of the type of source or target to which it is applied,
431 and affects only that source or target.
433 Note that it's important to distinguish between an option's context
434 (which is affected by its qualification) and its local or global
435 status. No matter how qualified, a global option will always control
436 default options for objects, and a local option will only affect a
437 specific source or target.
439 The syntax for qualifying options is like this:
464 Thus, you may qualify either an individual option or a sequence of
465 options. The two are equivalent; for example,
474 exec.rlimit.core = 0;
477 For each option, there is a sequence of prefixes which maximally qualify
478 that option. An option prefixed with this sequence is
479 .IR "fully qualified" .
480 In actual use, some or all of those prefixes may be omitted. However,
481 it's possible for the option to become
483 if you do this. For example, the option
488 .BR socket.unix.fattr.owner .
489 In this case, the ambiguity is benign: a local option will have as its
490 context an appropriate source or target, and both global options
491 actually control the same default. However, the option
497 which have separate defaults, and which one you actually get depends on
498 the exact implementation of
500 option parser. (Currently this would resolve to
502 although this may change in a later version.)
504 In this manual, options are usually shown in their fully-qualified form.
506 .SS "File attributes for created files: `fattr'"
511 sources and targets can create new filesystem objects. The
513 options allow control over the attributes of the newly-created objects.
518 use the same set of defaults, so a prefix of
520 is good enough for setting global options, and the implicit context
521 disambiguates local options.
523 The following file attribute options are supported:
524 .OS "File attribute options (`fattr')"
525 .IB prefix .fattr.mode
529 Sets the permissions mode for a new file. The
531 argument may be either an octal number or a
533 string which acts on the default permissions established by the
536 setting. The characters
540 do not have to be quoted within the mode string.
542 .OS "File attribute options (`fattr')"
543 .IB prefix .fattr.owner
547 Sets the owner for newly created files. On non-broken systems you will
548 need to be the superuser to set the owner on a file. The
550 may either be a numeric uid or a username. The default is not to change
551 the owner of the file once it's created. The synonyms
555 are accepted in place of
558 .OS "File attribute options (`fattr')"
559 .IB prefix .fattr.group
563 Sets the group for newly created files. You will usually need to be a
564 member of the group in question order to set the group of a file. The
566 may either be a numeric gid or a group name. The default is not to
567 change the group of the file once it's created. The synonym
569 is accepted in place of
573 .SS "The `file' source and target types"
576 source and target allow data to move to and from objects other
577 than sockets within the Unix filesystem. (Unix-domain sockets are
584 is used as a source, it is set up immediately.
588 sources and targets is like this:
589 .GS "File sources and targets"
622 .RB [[ : ] file [ : ]]
652 specification describes two files, the first to be used as input, the
653 second to be used as output, each described by an
656 If none of the keywords
661 are given, the type of an
663 is deduced from its nature: if it matches one of the strings
667 or begins with a digit, it's considered to be a file descriptor;
668 otherwise it's interpreted as a filename.
672 spec describes a file by its name within the filesystem. It is opened
673 when needed and closed again after use. For output files, the precise
674 behaviour is controlled by options described below.
678 spec attaches the input or output of the source or target to
683 spec uses an existing open file descriptor, given either by number or a
684 symbolic name. The name
686 refers to standard input (file descriptor 0 on normal systems) and
688 refers to standard output (file descriptor 1). The names work in
689 exactly the same way as the equivalent file descriptor numbers.
693 is omitted, the input
695 is used for both input and output. Exception: if the input refers to
696 standard input then the output will refer to standard output instead.
700 options apply equally to sources and targets. The options are as
707 Whether to create the output file if it doesn't exist. If
709 (the default), an error is reported if the file doesn't exist. If
711 the file is created if it doesn't exist.
716 .BR no | truncate | append
718 Controls the behaviour if the output file already exists. If
720 an error is reported. If
722 (the default), the existing file is replaced by the new data. If
724 the new data is appended to the file.
731 source and target also accept
733 options for controlling the attributes of the created file.
736 Under no circumstances will
738 create a file through a `dangling' symbolic link.
740 .SS "The `exec' source and target types"
743 source and target execute programs and allow access to their standard
744 input and output streams. Both source and target have the same syntax,
746 .GS "Exec source and target"
786 If a single word is given, it is a
788 and will be passed to the Bourne shell for execution. If a
789 bracket-enclosed sequence of words is given, it is considered to be a
790 list of arguments to pass to the program: if a
792 is also supplied, it names the file containing the program to execute;
793 otherwise the file named by the first argument
797 Note that the shell command or program name string must, if present,
798 have any delimiter characters (including
802 quoted; this is not required in the
806 The standard input and output of the program are forwarded to the other
807 end of the connection. The standard error stream is caught by
813 source and target both understand the same set of options. The list of
814 options supported is as follows:
820 Whether to log the start and end of executed programs. If
822 (the default), a log message is emitted when the program is started
823 listing its process id, and another is emitted when the program finishes
824 giving its process id and exit status. If
826 these messages are not emitted. However the standard error stream is
829 abbreviation is accepted as a synonym for
837 Sets the current directory from which the the program should be run.
838 The default is not to change directory. The synonyms
843 are accepted in place of
851 Sets the root directory for the program, using the
853 system call. You must be the superuser for this option to work. The
854 default is not to set a root directory. The synonym
856 is accepted in place of
864 Sets the user (real and effective uid) to run the program as. This will
865 usually require superuser privileges to work. The default is not to
866 change uid. The synonym
868 is accepted in place of
876 Sets the group (real and effective gid) to run the program as. If
877 running with superuser privileges, the supplementary groups list is
878 cleared at the same time. The default is not to change gid (or clear
879 the supplementary groups list). The synonym
881 is accepted in place of
885 .BI exec.rlimit. limit \c
886 .RB [ .hard | .soft ]
890 Set resource limits for the program. The
892 may be one of the resource limit names described in
894 in lower-case and without the
902 is a number, followed optionally by
904 to multiply by 1024 (2\*(ss10\*(se),
906 to multiply by 1048576 (2\*(ss20\*(se), or
908 to multiply by 1073741824 (2\*(ss30\*(se); purists can use upper-case
909 versions of these if they want. If
913 was specified, only the hard or soft limit is set; otherwise both are
914 set to the same value. Only the superuser can raise the hard limit.
915 The soft limit cannot be set above the hard limit.
920 Clears the program's environment.
928 from the program's environment. It is not an error if no variable named
933 .BR exec.env. [ set ]
942 in the program's environment, possibly replacing the existing value.
945 may be omitted if the
947 qualifier is present.
950 Note that environment variable modifications are performed in order,
951 global modifications before local ones.
953 .SS "The `socket' source and target types"
956 source and target provide access to network services. Support is
957 currently provided for TCP/IP and Unix-domain sockets, although other
958 address types can be added with reasonable ease.
960 The syntax for socket sources and targets is:
961 .GS "Socket source and target"
973 .RB [ socket [ .\& ]]
981 .RB [ socket [ .\& ]]
988 The syntax of the source and target addresses depend on the address
989 types, which are described below. The default address type, if no
994 Socket sources support options; socket targets do not. The source
995 options provided are:
1000 .BR unlimited | one-shot
1002 Controls the behaviour of the source when it receives connections. A
1004 limits the number of simultaneous connections. The value
1008 removes any limit on the number of connections possible. The value
1010 will remove the socket source after a single successful connection.
1011 (Connections refused by access control systems don't count here.)
1012 The default is to apply a limit of 256 concurrent connections. Use of
1015 option is not recommended.
1017 .OS "Socket options"
1022 Sets the maximum of the kernel incoming connection queue for this socket
1023 source. This is the number given to the
1025 system call. The default is 5.
1027 .OS "Socket options"
1032 Whether to log incoming connections. If
1034 (the default) incoming connections are logged, together with information
1035 about the client (where available) and whether the connection was
1036 accepted or refused. If
1038 log messages are not generated.
1041 Address types also provide their own options.
1043 .SS "The `inet' socket address type"
1046 address type provides access to TCP ports. The
1048 source and target addresses have the following syntax:
1049 .GS "Socket source and target"
1076 may be given as a port number or a service name from the
1078 file (or YP map if you do that sort of thing). A
1080 may be a textual hostname or a numerical IP address.
1084 source address accepts the following options:
1085 .OS "Socket options"
1086 .B socket.inet.source.addr
1091 Specify the IP address on which to listen for incoming connections. The
1094 which means to listen on all addresses, though it may be useful to
1095 specify this explicitly, if the global setting is different.
1097 .OS "Socket options"
1098 .BR socket.inet.source. [ allow | deny ]
1104 Adds an entry to the source's access control list. If only one
1106 is given, the entry applies only to that address; if two are given, the
1107 first is a network address and the second is a netmask either in
1108 dotted-quad format or a simple number of bits (e.g.,
1112 mean the same), and the entry applies to any address which, when masked
1113 by the netmask, is equal to the masked network address.
1115 .OS "Socket options"
1116 .BR socket.inet.source. [ allow | deny ]
1119 Accept or reject connections from low-numbered `privileged' ports, in
1122 .OS "Socket options"
1123 .B socket.inet.dest.addr
1128 Specify the IP address to bind the local socket to when making an
1129 outbound connection. The default is
1131 which means to use whichever address the kernel thinks is most
1132 convenient. This option is useful if the destination is doing
1133 host-based access control and your server is multi-homed.
1135 .OS "Socket options"
1136 .B socket.inet.dest.priv-port
1140 Make a privileged connection (i.e., from a low-numbered port) to the
1141 target. This only works if
1143 was started with root privileges. However, it still works if
1147 privileges after initialization (the
1149 option). Before dropping privileges,
1151 forks off a separate process which continues to run with root
1152 privileges, and on demand passes sockets bound to privileged ports and
1153 connected to the appropriate peer back to the main program. The
1154 privileged child only passes back sockets connected to peer addresses
1155 named in the configuration; even if the
1157 process is compromised, it can't make privileged connections to other
1158 addresses. Note that because of this privilege separation, it's also
1159 not possible to reconfigure
1161 to make privileged connections to different peer addresses later. by
1162 changing configuration files and sending the daemon a
1166 The access control rules are examined in the order: local entries first,
1167 then global ones, each in the order given in the configuration file.
1168 The first matching entry is used. If no entries match, the behaviour is
1171 of the last entry tried. If there are no entries defined, the default
1172 is to allow all clients.
1174 .SS "The `unix' socket address type"
1177 address type allows access to Unix-domain sockets. The syntax for
1179 source and target addresses is like this:
1180 .GS "Socket source and target"
1189 The following options are supported by the
1191 source address type:
1192 .OS "Socket options"
1193 .BR socket.unix.fattr. *
1197 source address accepts
1199 options to control the attributes of the socket file created.
1202 Sockets are removed if
1204 exits normally (which it will do if it runs out of sources or
1207 shuts down in a clean way).
1209 To forward the local port 25 to a main mail server:
1211 from 25 to mailserv:25
1213 To attach a fortune server to a Unix-domain socket:
1215 from unix:/tmp/fortunes
1216 to exec [/usr/games/fortune] { user nobody }
1218 To fetch a fortune from the server:
1220 from file stdin, stdout to unix:/tmp/fortunes
1225 from file stdin, null to file null, stdout
1228 .\"--------------------------------------------------------------------------
1229 .SH "SIGNAL HANDLING"
1233 program responds to various signals when it's running. If it receives
1240 shutdown: it removes all of its sources, and will exit when no more
1241 connections are running. (Note that if the disposition
1245 does not re-enable the signal. You'll have to send
1253 shutdown: it removes all sources and extant connections and closes down
1254 more-or-less immediately.
1256 Finally, if any configuration files (other than standard input) were
1259 on its command line using the
1263 signal may be sent to instruct
1265 to reload its configuration. Any existing connections are allowed to
1266 run their course. If no such configuration files are available,
1268 just logs a message about the signal and continues.
1271 .\"--------------------------------------------------------------------------
1272 .SH "GRAMMAR SUMMARY"
1336 .SS "File source and target"
1363 .RB [[ : ] fd [ : ]]
1365 .RB | stdin | stdout
1369 .RB [[ : ] file [ : ]]
1395 .RB [ : ] null [ : ]
1397 .SS "Exec source and target"
1437 .SS "Socket source and target"
1449 .RB [ socket [ .\& ]]
1457 .RB [ socket [ .\& ]]
1496 .\"--------------------------------------------------------------------------
1497 .SH "OPTION SUMMARY"
1499 .SS "File attributes (`fattr')"
1500 .IB prefix .fattr.mode
1504 .IB prefix .fattr.owner
1508 .IB prefix .fattr.group
1519 .BR no | truncate | append
1544 .BI exec.rlimit. limit \c
1545 .RB [ .hard | .soft ]
1554 .BR exec.env. [ set ]
1559 .SS "Socket options"
1563 .BR unlimited | one-shot
1573 .BR socket.inet.source. [ allow | deny ]
1579 .BR socket.inet.source. [ allow | deny ]
1582 .B socket.inet.source.addr
1587 .B socket.inet.dest.addr
1592 .B socket.inet.dest.priv-port
1596 .BR socket.unix.fattr. *
1598 .\"--------------------------------------------------------------------------
1601 The syntax for IP addresses and filenames is nasty.
1603 IPv6 is not supported yet. Because of
1605 socket address architecture, it's probably not a major piece of work to
1608 Please inform me of any security problems you think you've identified in
1609 this program. I take security very seriously, and I will fix security
1610 holes as a matter of priority when I find out about them. I will be
1611 annoyed if I have to read about problems on Bugtraq because they weren't
1614 The program is too complicated, and this manual page is too long.
1616 .\"--------------------------------------------------------------------------
1619 Mark Wooding, <mdw@nsict.org>
1621 .\"----- That's all, folks --------------------------------------------------