3 .\" $Id: fw.1,v 1.15 2003/01/24 20:13:04 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.15 2003/01/24 20:13:04 mdw
32 .\" Fix bogus examples. Explain quoting rules for `exec' endpoints.
34 .\" Revision 1.14 2002/02/23 00:05:12 mdw
35 .\" Fix spacing around full stops (at last!).
37 .\" Revision 1.13 2002/02/22 23:45:01 mdw
38 .\" Add option to change the listen(2) parameter.
40 .\" Revision 1.12 2001/02/23 09:11:29 mdw
41 .\" Update manual style.
43 .\" Revision 1.11 2001/02/05 19:47:11 mdw
44 .\" Minor fixings to wording.
46 .\" Revision 1.10 2001/02/03 20:30:03 mdw
47 .\" Support re-reading config files on SIGHUP.
49 .\" Revision 1.9 2000/03/23 00:37:33 mdw
50 .\" Add option to change user and group after initialization. Naughtily
51 .\" reassign short equivalents of --grammar and --options.
53 .\" Revision 1.8 1999/12/22 15:44:43 mdw
54 .\" Fix some errors, and document new option.
56 .\" Revision 1.7 1999/10/22 22:45:15 mdw
57 .\" Describe new socket connection options.
59 .\" Revision 1.6 1999/10/10 16:46:29 mdw
60 .\" Include grammar and options references at the end of the manual.
62 .\" Revision 1.5 1999/09/26 18:18:05 mdw
63 .\" Remove a fixed bug from the list. Fix some nasty formatting
66 .\" Revision 1.4 1999/08/19 18:32:48 mdw
67 .\" Improve lexical analysis. In particular, `chmod' patterns don't have to
68 .\" be quoted any more.
70 .\" Revision 1.3 1999/07/30 06:49:00 mdw
71 .\" Minor tidying and typo correction.
73 .\" Revision 1.2 1999/07/26 23:31:04 mdw
74 .\" Document lots of new features and syntax.
77 .\"----- Various bits of fancy styling --------------------------------------
79 .\" --- Indented paragraphs with right-aligned tags ---
83 \h'-\w'\fB\\$1\ \fP'u'\fB\\$1\ \fP\c
86 .\" --- Verbatim-oid typesetting ---
100 .\" --- Grammar markup ---
102 .\" This is mainly for the benefit of the automatic scripts which
103 .\" generate the grammar summary.
122 .\" --- Other bits of styling ---
138 .\"--------------------------------------------------------------------------
140 .TH fw 1 "1 July 1999" "Straylight/Edgeware" "fw port forwarder"
142 .\"--------------------------------------------------------------------------
147 .\"--------------------------------------------------------------------------
160 .\"--------------------------------------------------------------------------
165 program is a simple port forwarder. It supports a number of features
166 the author hasn't found in similar programs:
168 .I "Connection logging"
169 Each connection attempt to the forwarder is logged, giving the time of
170 the connection, the DNS-resolved hostname (if available), and the user
171 name resulting from an RFC931 lookup. These lookups are done
172 asynchronously to the main forwarder's operation.
175 Each forwarded port may have an access control list attached to it.
176 Only authorized hosts are allowed to connect. Access control checks are
177 performed by quick checks on the client's IP address.
179 .I "Nonblocking single-process design"
180 The internal structure of the server is completely nonblocking. The
181 connections don't block; the reading and writing don't block; the name
182 lookups don't block. This is all done in a single process, with the
183 single exception of the DNS resolver.
185 .I "Support for Unix-domain sockets"
186 Connections from and to Unix-domain sockets can be handled just as
187 easily as more normal Internet sockets. Access control doesn't work on
188 Unix domain sockets, though. (Yet.)
189 .SS "Command line options"
192 program understands a few simple command line options:
195 Displays a screen of help text on standard output and exits
198 .B "\-v, \-\-version"
199 Writes the version number to standard output and exits successfully.
202 Writes a terse usage summary to standard output and exits successfully.
204 .B "\-G, \-\-grammar"
205 Writes a summary of the configuration file grammar to standard output
206 and exits successfully.
208 .B "\-O, \-\-options"
209 Writes a summary of the source and target options to standard output and
212 .BI "\-f, \-\-file=" file
213 Read configuration information from
218 configuration file statement.
220 .B "\-d, \-\-daemon, \-\-fork"
221 Forks into the background after reading the configuration and
222 initializing properly.
224 .B "\-l, \-\-syslog, \-\-log"
225 Emit logging information to the system log, rather than standard error.
228 Don't output any logging information. This option is not recommended
229 for normal use, although it can make system call traces clearer so I use
232 .BI "\-s, \-\-setuid=" user
233 Change uid to that of
235 which may be either a user name or uid number, after initializing all
236 the sources. This will usually require elevated privileges.
238 .BI "\-g, \-\-setgid=" group
239 Change gid to that of
241 which may be either a group name or gid number, after initializing all
242 the sources. If the operating system understands supplementary groups
243 then the supplementary groups list is altered to include only
246 Any further command line arguments are interpreted as configuration
247 lines to be read. Configuration supplied in command line arguments has
248 precisely the same syntax as configuration in files. If there are no
249 configuration statements on the command line, and no
251 options were supplied, configuration is read from standard input, if
252 stdin is not a terminal.
254 .\"--------------------------------------------------------------------------
255 .SH "CONFIGURATION LANGUAGE"
259 program has a fairly sophisticated configuration language to let you
260 describe which things should be forwarded where and what special
261 features there should be.
262 .SS "Lexical structure"
263 There are four types of characters.
265 .I "word constituent characters"
266 Word constituent characters are gathered together into words.
267 Depending on its surrounding context, a word might act as a keyword or a
268 string. All alphanumerics are word constituents, as is the hyphen
270 Other characters may change their status in future versions.
272 .I "self-delimiting characters"
273 Self-delimiting characters always stand alone. They act as punctuation,
274 shaping the sequence of words into more complex grammatical forms. The
287 are self-delimiting. Note that while some characters, e.g.,
291 require escaping by the shell, they are mostly optional in the grammar
292 and can tend to be omitted in quick hacks at the shell prompt.
294 .I "whitespace characters"
295 Whitespace characters separate words but are otherwise ignored. All
296 `normal' whitespace characters (e.g., space, tab and newline) are
297 considered to be whitespace for these purposes.
299 .I "special characters"
300 There are three special characters. The
302 character, if it appears at the start of a word, introduces a
304 which extends to the end of the current line or command-line argument.
305 Within a word, it behaves like a normal word-constituent character. The
308 escapes the following character causing it to be interpreted as a word
309 constituent regardless of its normal type. The double-quote
311 escapes all characters other than backslashes up to the next
312 double-quote and causes them to be regarded as word constituents. Note
313 that you don't have to quote a whole word. The backslash can escape a
314 quote character allowing you to insert it into a word if really
318 The overall syntax looks a bit like this:
357 If you prefer, the keyword
365 .SS "Sources and targets"
366 Forwarding is set up by attaching
370 Sources are things which are capable of
372 one end of a data flow on their own, while targets are things which are
373 capable of setting up the other end on demand. In the case of a TCP
374 port forwarder, the part which listens for incoming client connections
375 is the source, while the part which sets up outgoing connections to the
376 destination server is the target.
380 does is set up a collection of sources and targets based on your
381 configuration file so that when a source decides to initiate a data
382 flow, it tells its target to set its end up, and then squirts data back
383 and forth between the two until there's no more.
387 they stay around indefinitely setting up multiple attachments to
390 they set up one connection and then disappear. If all the sources
391 defined are transient, then
393 will quit when no more active sources remain and all connections have
398 program is fairly versatile. It allows you to attach any supported type
399 of source to any supported type of target. This will, I hope, be the
400 case in all future versions.
406 depend on the source or target type, and are therefore described in the
407 sections specific to the various types.
409 .SS "Options structure"
410 Most of the objects that
412 knows about (including sources and targets, but also other more specific
413 things such as socket address types) can have their behaviour modified
416 The options available at a particular point in the configuration depend
419 A global option, outside of a
421 has no context unless it is explicitly qualified, and affects global
422 behaviour. A local option, applied to a source or target in a
424 has the context of the type of source or target to which it is applied,
425 and affects only that source or target.
427 Note that it's important to distinguish between an option's context
428 (which is affected by its qualification) and its local or global
429 status. No matter how qualified, a global option will always control
430 default options for objects, and a local option will only affect a
431 specific source or target.
433 The syntax for qualifying options is like this:
458 Thus, you may qualify either an individual option or a sequence of
459 options. The two are equivalent; for example,
468 exec.rlimit.core = 0;
471 For each option, there is a sequence of prefixes which maximally qualify
472 that option. An option prefixed with this sequence is
473 .IR "fully qualified" .
474 In actual use, some or all of those prefixes may be omitted. However,
475 it's possible for the option to become
477 if you do this. For example, the option
482 .BR socket.unix.fattr.owner .
483 In this case, the ambiguity is benign: a local option will have as its
484 context an appropriate source or target, and both global options
485 actually control the same default. However, the option
491 which have separate defaults, and which one you actually get depends on
492 the exact implementation of
494 option parser. (Currently this would resolve to
496 although this may change in a later version.)
498 In this manual, options are usually shown in their fully-qualified form.
500 .SS "File attributes for created files: `fattr'"
505 sources and targets can create new filesystem objects. The
507 options allow control over the attributes of the newly-created objects.
512 use the same set of defaults, so a prefix of
514 is good enough for setting global options, and the implicit context
515 disambiguates local options.
517 The following file attribute options are supported:
518 .OS "File attribute options (`fattr')"
519 .IB prefix .fattr.mode
523 Sets the permissions mode for a new file. The
525 argument may be either an octal number or a
527 string which acts on the default permissions established by the
530 setting. The characters
534 do not have to be quoted within the mode string.
536 .OS "File attribute options (`fattr')"
537 .IB prefix .fattr.owner
541 Sets the owner for newly created files. On non-broken systems you will
542 need to be the superuser to set the owner on a file. The
544 may either be a numeric uid or a username. The default is not to change
545 the owner of the file once it's created. The synonyms
549 are accepted in place of
552 .OS "File attribute options (`fattr')"
553 .IB prefix .fattr.group
557 Sets the group for newly created files. You will usually need to be a
558 member of the group in question order to set the group of a file. The
560 may either be a numeric gid or a group name. The default is not to
561 change the group of the file once it's created. The synonym
563 is accepted in place of
567 .SS "The `file' source and target types"
570 source and target allow data to move to and from objects other
571 than sockets within the Unix filesystem. (Unix-domain sockets are
578 is used as a source, it is set up immediately.
582 sources and targets is like this:
583 .GS "File sources and targets"
616 .RB [[ : ] file [ : ]]
646 specification describes two files, the first to be used as input, the
647 second to be used as output, each described by an
650 If none of the keywords
655 are given, the type of an
657 is deduced from its nature: if it matches one of the strings
661 or begins with a digit, it's considered to be a file descriptor;
662 otherwise it's interpreted as a filename.
666 spec describes a file by its name within the filesystem. It is opened
667 when needed and closed again after use. For output files, the precise
668 behaviour is controlled by options described below.
672 spec attaches the input or output of the source or target to
677 spec uses an existing open file descriptor, given either by number or a
678 symbolic name. The name
680 refers to standard input (file descriptor 0 on normal systems) and
682 refers to standard output (file descriptor 1). The names work in
683 exactly the same way as the equivalent file descriptor numbers.
687 is omitted, the input
689 is used for both input and output. Exception: if the input refers to
690 standard input then the output will refer to standard output instead.
694 options apply equally to sources and targets. The options are as
701 Whether to create the output file if it doesn't exist. If
703 (the default), an error is reported if the file doesn't exist. If
705 the file is created if it doesn't exist.
710 .BR no | truncate | append
712 Controls the behaviour if the output file already exists. If
714 an error is reported. If
716 (the default), the existing file is replaced by the new data. If
718 the new data is appended to the file.
725 source and target also accept
727 options for controlling the attributes of the created file.
730 Under no circumstances will
732 create a file through a `dangling' symbolic link.
734 .SS "The `exec' source and target types"
737 source and target execute programs and allow access to their standard
738 input and output streams. Both source and target have the same syntax,
740 .GS "Exec source and target"
780 If a single word is given, it is a
782 and will be passed to the Bourne shell for execution. If a
783 bracket-enclosed sequence of words is given, it is considered to be a
784 list of arguments to pass to the program: if a
786 is also supplied, it names the file containing the program to execute;
787 otherwise the file named by the first argument
791 Note that the shell command or program name string must, if present,
792 have any delimiter characters (including
796 quoted; this is not required in the
800 The standard input and output of the program are forwarded to the other
801 end of the connection. The standard error stream is caught by
807 source and target both understand the same set of options. The list of
808 options supported is as follows:
814 Whether to log the start and end of executed programs. If
816 (the default), a log message is emitted when the program is started
817 listing its process id, and another is emitted when the program finishes
818 giving its process id and exit status. If
820 these messages are not emitted. However the standard error stream is
823 abbreviation is accepted as a synonym for
831 Sets the current directory from which the the program should be run.
832 The default is not to change directory. The synonyms
837 are accepted in place of
845 Sets the root directory for the program, using the
847 system call. You must be the superuser for this option to work. The
848 default is not to set a root directory. The synonym
850 is accepted in place of
858 Sets the user (real and effective uid) to run the program as. This will
859 usually require superuser privileges to work. The default is not to
860 change uid. The synonym
862 is accepted in place of
870 Sets the group (real and effective gid) to run the program as. If
871 running with superuser privileges, the supplementary groups list is
872 cleared at the same time. The default is not to change gid (or clear
873 the supplementary groups list). The synonym
875 is accepted in place of
879 .BI exec.rlimit. limit \c
880 .RB [ .hard | .soft ]
884 Set resource limits for the program. The
886 may be one of the resource limit names described in
888 in lower-case and without the
896 is a number, followed optionally by
898 to multiply by 1024 (2\*(ss10\*(se),
900 to multiply by 1048576 (2\*(ss20\*(se), or
902 to multiply by 1073741824 (2\*(ss30\*(se); purists can use upper-case
903 versions of these if they want. If
907 was specified, only the hard or soft limit is set; otherwise both are
908 set to the same value. Only the superuser can raise the hard limit.
909 The soft limit cannot be set above the hard limit.
914 Clears the program's environment.
922 from the program's environment. It is not an error if no variable named
927 .BR exec.env. [ set ]
936 in the program's environment, possibly replacing the existing value.
939 may be omitted if the
941 qualifier is present.
944 Note that environment variable modifications are performed in order,
945 global modifications before local ones.
947 .SS "The `socket' source and target types"
950 source and target provide access to network services. Support is
951 currently provided for TCP/IP and Unix-domain sockets, although other
952 address types can be added with reasonable ease.
954 The syntax for socket sources and targets is:
955 .GS "Socket source and target"
967 .RB [ socket [ .\& ]]
975 .RB [ socket [ .\& ]]
982 The syntax of the source and target addresses depend on the address
983 types, which are described below. The default address type, if no
988 Socket sources support options; socket targets do not. The source
989 options provided are:
994 .BR unlimited | one-shot
996 Controls the behaviour of the source when it receives connections. A
998 limits the number of simultaneous connections. The value
1002 removes any limit on the number of connections possible. The value
1004 will remove the socket source after a single successful connection.
1005 (Connections refused by access control systems don't count here.)
1006 The default is to apply a limit of 256 concurrent connections. Use of
1009 option is not recommended.
1011 .OS "Socket options"
1016 Sets the maximum of the kernel incoming connection queue for this socket
1017 source. This is the number given to the
1019 system call. The default is 5.
1021 .OS "Socket options"
1026 Whether to log incoming connections. If
1028 (the default) incoming connections are logged, together with information
1029 about the client (where available) and whether the connection was
1030 accepted or refused. If
1032 log messages are not generated.
1035 Address types also provide their own options.
1037 .SS "The `inet' socket address type"
1040 address type provides access to TCP ports. The
1042 source and target addresses have the following syntax:
1043 .GS "Socket source and target"
1070 may be given as a port number or a service name from the
1072 file (or YP map if you do that sort of thing). A
1074 may be a textual hostname or a numerical IP address.
1078 source address accepts the following options:
1079 .OS "Socket options"
1080 .BR socket.inet. [ allow | deny ]
1086 Adds an entry to the source's access control list. If only one
1088 is given, the entry applies only to that address; if two are given, the
1089 first is a network address and the second is a netmask either in
1090 dotted-quad format or a simple number of bits (e.g.,
1094 mean the same), and the entry applies to any address which, when masked
1095 by the netmask, is equal to the masked network address.
1098 The access control rules are examined in the order: local entries first,
1099 then global ones, each in the order given in the configuration file.
1100 The first matching entry is used. If no entries match, the behaviour is
1103 of the last entry tried. If there are no entries defined, the default
1104 is to allow all clients.
1106 .SS "The `unix' socket address type"
1109 address type allows access to Unix-domain sockets. The syntax for
1111 source and target addresses is like this:
1112 .GS "Socket source and target"
1121 The following options are supported by the
1123 source address type:
1124 .OS "Socket options"
1125 .BR socket.unix.fattr. *
1129 source address accepts
1131 options to control the attributes of the socket file created.
1134 Sockets are removed if
1136 exits normally (which it will do if it runs out of sources or
1139 shuts down in a clean way).
1141 To forward the local port 25 to a main mail server:
1143 from 25 to mailserv:25
1145 To attach a fortune server to a Unix-domain socket:
1147 from unix:/tmp/fortunes
1148 to exec [/usr/games/fortune] { user nobody }
1150 To fetch a fortune from the server:
1152 from file stdin, stdout to unix:/tmp/fortunes
1157 from file stdin, null to file null, stdout
1160 .\"--------------------------------------------------------------------------
1161 .SH "SIGNAL HANDLING"
1165 program responds to various signals when it's running. If it receives
1172 shutdown: it removes all of its sources, and will exit when no more
1173 connections are running. (Note that if the disposition
1177 does not re-enable the signal. You'll have to send
1185 shutdown: it removes all sources and extant connections and closes down
1186 more-or-less immediately.
1188 Finally, if any configuration files (other than standard input) were
1191 on its command line using the
1195 signal may be sent to instruct
1197 to reload its configuration. Any existing connections are allowed to
1198 run their course. If no such configuration files are available,
1200 just logs a message about the signal and continues.
1203 .\"--------------------------------------------------------------------------
1204 .SH "GRAMMAR SUMMARY"
1268 .SS "File source and target"
1295 .RB [[ : ] fd [ : ]]
1297 .RB | stdin | stdout
1301 .RB [[ : ] file [ : ]]
1327 .RB [ : ] null [ : ]
1329 .SS "Exec source and target"
1369 .SS "Socket source and target"
1381 .RB [ socket [ .\& ]]
1389 .RB [ socket [ .\& ]]
1428 .\"--------------------------------------------------------------------------
1429 .SH "OPTION SUMMARY"
1431 .SS "File attributes (`fattr')"
1432 .IB prefix .fattr.mode
1436 .IB prefix .fattr.owner
1440 .IB prefix .fattr.group
1451 .BR no | truncate | append
1476 .BI exec.rlimit. limit \c
1477 .RB [ .hard | .soft ]
1486 .BR exec.env. [ set ]
1491 .SS "Socket options"
1495 .BR unlimited | one-shot
1505 .BR socket.inet. [ allow | deny ]
1511 .BR socket.unix.fattr. *
1513 .\"--------------------------------------------------------------------------
1516 The syntax for IP addresses and filenames is nasty.
1518 IPv6 is not supported yet. Because of
1520 socket address architecture, it's probably not a major piece of work to
1523 Please inform me of any security problems you think you've identified in
1524 this program. I take security very seriously, and I will fix security
1525 holes as a matter of priority when I find out about them. I will be
1526 annoyed if I have to read about problems on Bugtraq because they weren't
1529 The program is too complicated, and this manual page is too long.
1531 .\"--------------------------------------------------------------------------
1534 Mark Wooding, <mdw@nsict.org>
1536 .\"----- That's all, folks --------------------------------------------------