3 .\" $Id: fw.1,v 1.11 2001/02/05 19:47:11 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.11 2001/02/05 19:47:11 mdw
32 .\" Minor fixings to wording.
34 .\" Revision 1.10 2001/02/03 20:30:03 mdw
35 .\" Support re-reading config files on SIGHUP.
37 .\" Revision 1.9 2000/03/23 00:37:33 mdw
38 .\" Add option to change user and group after initialization. Naughtily
39 .\" reassign short equivalents of --grammar and --options.
41 .\" Revision 1.8 1999/12/22 15:44:43 mdw
42 .\" Fix some errors, and document new option.
44 .\" Revision 1.7 1999/10/22 22:45:15 mdw
45 .\" Describe new socket connection options.
47 .\" Revision 1.6 1999/10/10 16:46:29 mdw
48 .\" Include grammar and options references at the end of the manual.
50 .\" Revision 1.5 1999/09/26 18:18:05 mdw
51 .\" Remove a fixed bug from the list. Fix some nasty formatting
54 .\" Revision 1.4 1999/08/19 18:32:48 mdw
55 .\" Improve lexical analysis. In particular, `chmod' patterns don't have to
56 .\" be quoted any more.
58 .\" Revision 1.3 1999/07/30 06:49:00 mdw
59 .\" Minor tidying and typo correction.
61 .\" Revision 1.2 1999/07/26 23:31:04 mdw
62 .\" Document lots of new features and syntax.
65 .\"----- Various bits of fancy styling --------------------------------------
67 .\" --- Indented paragraphs with right-aligned tags ---
71 \h'-\w'\fB\\$1\ \fP'u'\fB\\$1\ \fP\c
74 .\" --- Verbatim-oid typesetting ---
88 .\" --- Grammar markup ---
90 .\" This is mainly for the benefit of the automatic scripts which
91 .\" generate the grammar summary.
110 .\" --- Other bits of styling ---
126 .\"--------------------------------------------------------------------------
128 .TH fw 1 "1 July 1999" fw
130 .\"--------------------------------------------------------------------------
135 .\"--------------------------------------------------------------------------
148 .\"--------------------------------------------------------------------------
153 program is a simple port forwarder. It supports a number of features
154 the author hasn't found in similar programs:
156 .I "Connection logging"
157 Each connection attempt to the forwarder is logged, giving the time of
158 the connection, the DNS-resolved hostname (if available), and the user
159 name resulting from an RFC931 lookup. These lookups are done
160 asynchronously to the main forwarder's operation.
163 Each forwarded port may have an access control list attached to it.
164 Only authorized hosts are allowed to connect. Access control checks are
165 performed by quick checks on the client's IP address.
167 .I "Nonblocking single-process design"
168 The internal structure of the server is completely nonblocking. The
169 connections don't block; the reading and writing don't block; the name
170 lookups don't block. This is all done in a single process, with the
171 single exception of the DNS resolver.
173 .I "Support for Unix-domain sockets"
174 Connections from and to Unix-domain sockets can be handled just as
175 easily as more normal Internet sockets. Access control doesn't work on
176 Unix domain sockets, though. (Yet.)
177 .SS "Command line options"
180 program understands a few simple command line options:
183 Displays a screen of help text on standard output and exits
186 .B "\-v, \-\-version"
187 Writes the version number to standard output and exits successfully.
190 Writes a terse usage summary to standard output and exits successfully.
192 .B "\-G, \-\-grammar"
193 Writes a summary of the configuration file grammar to standard output
194 and exits successfully.
196 .B "\-O, \-\-options"
197 Writes a summary of the source and target options to standard output and
200 .BI "\-f, \-\-file=" file
201 Read configuration information from
206 configuration file statement.
208 .B "\-d, \-\-daemon, \-\-fork"
209 Forks into the background after reading the configuration and
210 initializing properly.
212 .B "\-l, \-\-syslog, \-\-log"
213 Emit logging information to the system log, rather than standard error.
216 Don't output any logging information. This option is not recommended
217 for normal use, although it can make system call traces clearer so I use
220 .BI "\-s, \-\-setuid=" user
221 Change uid to that of
223 which may be either a user name or uid number, after initializing all
224 the sources. This will usually require elevated privileges.
226 .BI "\-g, \-\-setgid=" group
227 Change gid to that of
229 which may be either a group name or gid number, after initializing all
230 the sources. If the operating system understands supplementary groups
231 then the supplementary groups list is altered to include only
234 Any further command line arguments are interpreted as configuration
235 lines to be read. Configuration supplied in command line arguments has
236 precisely the same syntax as configuration in files. If there are no
237 configuration statements on the command line, and no
239 options were supplied, configuration is read from standard input, if
240 stdin is not a terminal.
242 .\"--------------------------------------------------------------------------
243 .SH "CONFIGURATION LANGUAGE"
247 program has a fairly sophisticated configuration language to let you
248 describe which things should be forwarded where and what special
249 features there should be.
250 .SS "Lexical structure"
251 There are four types of characters.
253 .I "word constituent characters"
254 Word constituent characters are gathered together into words.
255 Depending on its surrounding context, a word might act as a keyword or a
256 string. All alphanumerics are word constituents, as is the hyphen
258 Other characters may change their status in future versions.
260 .I "self-delimiting characters"
261 Self-delimiting characters always stand alone. They act as punctuation,
262 shaping the sequence of words into more complex grammatical forms. The
275 are self-delimiting. Note that while some characters, e.g.,
279 require escaping by the shell, they are mostly optional in the grammar
280 and can tend to be omitted in quick hacks at the shell prompt.
282 .I "whitespace characters"
283 Whitespace characters separate words but are otherwise ignored. All
284 `normal' whitespace characters (e.g., space, tab and newline) are
285 considered to be whitespace for these purposes.
287 .I "special characters"
288 There are three special characters. The
290 character, if it appears at the start of a word, introduces a
292 which extends to the end of the current line or command-line argument.
293 Within a word, it behaves like a normal word-constituent character. The
296 escapes the following character causing it to be interpreted as a word
297 constituent regardless of its normal type. The double-quote
299 escapes all characters other than backslashes up to the next
300 double-quote and causes them to be regarded as word constituents. Note
301 that you don't have to quote a whole word. The backslash can escape a
302 quote character allowing you to insert it into a word if really
306 The overall syntax looks a bit like this:
345 If you prefer, the keyword
353 .SS "Sources and targets"
354 Forwarding is set up by attaching
358 Sources are things which are capable of
360 one end of a data flow on their own, while targets are things which are
361 capable of setting up the other end on demand. In the case of a TCP
362 port forwarder, the part which listens for incoming client connections
363 is the source, while the part which sets up outgoing connections to the
364 destination server is the target.
368 does is set up a collection of sources and targets based on your
369 configuration file so that when a source decides to initiate a data
370 flow, it tells its target to set its end up, and then squirts data back
371 and forth between the two until there's no more.
375 they stay around indefinitely setting up multiple attachments to
378 they set up one connection and then disappear. If all the sources
379 defined are transient, then
381 will quit when no more active sources remain and all connections have
386 program is fairly versatile. It allows you to attach any supported type
387 of source to any supported type of target. This will, I hope, be the
388 case in all future versions.
394 depend on the source or target type, and are therefore described in the
395 sections specific to the various types.
397 .SS "Options structure"
398 Most of the objects that
400 knows about (including sources and targets, but also other more specific
401 things such as socket address types) can have their behaviour modified
404 The options available at a particular point in the configuration depend
407 A global option, outside of a
409 has no context unless it is explicitly qualified, and affects global
410 behaviour. A local option, applied to a source or target in a
412 has the context of the type of source or target to which it is applied,
413 and affects only that source or target.
415 Note that it's important to distinguish between an option's context
416 (which is affected by its qualification) and its local or global
417 status. No matter how qualified, a global option will always control
418 default options for objects, and a local option will only affect a
419 specific source or target.
421 The syntax for qualifying options is like this:
446 Thus, you may qualify either an individual option or a sequence of
447 options. The two are equivalent; for example,
456 exec.rlimit.core = 0;
459 For each option, there is a sequence of prefixes which maximally qualify
460 that option. An option prefixed with this sequence is
461 .IR "fully qualified" .
462 In actual use, some or all of those prefixes may be omitted. However,
463 it's possible for the option to become
465 if you do this. For example, the option
470 .BR socket.unix.fattr.owner .
471 In this case, the ambiguity is benign: a local option will have as its
472 context an appropriate source or target, and both global options
473 actually control the same default. However, the option
479 which have separate defaults, and which one you actually get depends on
480 the exact implementation of
482 option parser. (Currently this would resolve to
484 although this may change in a later version.)
486 In this manual, options are usually shown in their fully-qualified form.
488 .SS "File attributes for created files: `fattr'"
493 sources and targets can create new filesystem objects. The
495 options allow control over the attributes of the newly-created objects.
500 use the same set of defaults, so a prefix of
502 is good enough for setting global options, and the implicit context
503 disambiguates local options.
505 The following file attribute options are supported:
506 .OS "File attribute options (`fattr')"
507 .IB prefix .fattr.mode
511 Sets the permissions mode for a new file. The
513 argument may be either an octal number or a
515 string which acts on the default permissions established by the
518 setting. The characters
522 do not have to be quoted within the mode string.
524 .OS "File attribute options (`fattr')"
525 .IB prefix .fattr.owner
529 Sets the owner for newly created files. On non-broken systems you will
530 need to be the superuser to set the owner on a file. The
532 may either be a numeric uid or a username. The default is not to change
533 the owner of the file once it's created. The synonyms
537 are accepted in place of
540 .OS "File attribute options (`fattr')"
541 .IB prefix .fattr.group
545 Sets the group for newly created files. You will usually need to be a
546 member of the group in question order to set the group of a file. The
548 may either be a numeric gid or a group name. The default is not to
549 change the group of the file once it's created. The synonym
551 is accepted in place of
555 .SS "The `file' source and target types"
558 source and target allow data to move to and from objects other
559 than sockets within the Unix filesystem. (Unix-domain sockets are
566 is used as a source, it is set up immediately.
570 sources and targets is like this:
571 .GS "File sources and targets"
604 .RB [[ : ] file [ : ]]
634 specification describes two files, the first to be used as input, the
635 second to be used as output, each described by an
638 If none of the keywords
643 are given, the type of an
645 is deduced from its nature: if it matches one of the strings
649 or begins with a digit, it's considered to be a file descriptor;
650 otherwise it's interpreted as a filename.
654 spec describes a file by its name within the filesystem. It is opened
655 when needed and closed again after use. For output files, the precise
656 behaviour is controlled by options described below.
660 spec attaches the input or output of the source or target to
665 spec uses an existing open file descriptor, given either by number or a
666 symbolic name. The name
668 refers to standard input (file descriptor 0 on normal systems) and
670 refers to standard output (file descriptor 1). The names work in
671 exactly the same way as the equivalent file descriptor numbers.
675 is omitted, the input
677 is used for both input and output. Exception: if the input refers to
678 standard input then the output will refer to standard output instead.
682 options apply equally to sources and targets. The options are as
689 Whether to create the output file if it doesn't exist. If
691 (the default), an error is reported if the file doesn't exist. If
693 the file is created if it doesn't exist.
698 .BR no | truncate | append
700 Controls the behaviour if the output file already exists. If
702 an error is reported. If
704 (the default), the existing file is replaced by the new data. If
706 the new data is appended to the file.
713 source and target also accept
715 options for controlling the attributes of the created file.
718 Under no circumstances will
720 create a file through a `dangling' symbolic link.
722 .SS "The `exec' source and target types"
725 source and target execute programs and allow access to their standard
726 input and output streams. Both source and target have the same syntax,
728 .GS "Exec source and target"
768 If a single word is given, it is a
770 and will be passed to the Bourne shell for execution. If a
771 bracket-enclosed sequence of words is given, it is considered to be a
772 list of arguments to pass to the program: if a
774 is also supplied, it names the file containing the program to execute;
775 otherwise the file named by the first argument
779 The standard input and output of the program are forwarded to the other
780 end of the connection. The standard error stream is caught by
786 source and target both understand the same set of options. The list of
787 options supported is as follows:
793 Whether to log the start and end of executed programs. If
795 (the default), a log message is emitted when the program is started
796 listing its process id, and another is emitted when the program finishes
797 giving its process id and exit status. If
799 these messages are not emitted. However the standard error stream is
802 abbreviation is accepted as a synonym for
810 Sets the current directory from which the the program should be run.
811 The default is not to change directory. The synonyms
816 are accepted in place of
824 Sets the root directory for the program, using the
826 system call. You must be the superuser for this option to work. The
827 default is not to set a root directory. The synonym
829 is accepted in place of
837 Sets the user (real and effective uid) to run the program as. This will
838 usually require superuser privileges to work. The default is not to
839 change uid. The synonym
841 is accepted in place of
849 Sets the group (real and effective gid) to run the program as. If
850 running with superuser privileges, the supplementary groups list is
851 cleared at the same time. The default is not to change gid (or clear
852 the supplementary groups list). The synonym
854 is accepted in place of
858 .BI exec.rlimit. limit \c
859 .RB [ .hard | .soft ]
863 Set resource limits for the program. The
865 may be one of the resource limit names described in
867 in lower-case and without the
875 is a number, followed optionally by
877 to multiply by 1024 (2\*(ss10\*(se),
879 to multiply by 1048576 (2\*(ss20\*(se), or
881 to multiply by 1073741824 (2\*(ss30\*(se); purists can use upper-case
882 versions of these if they want. If
886 was specified, only the hard or soft limit is set; otherwise both are
887 set to the same value. Only the superuser can raise the hard limit.
888 The soft limit cannot be set above the hard limit.
893 Clears the program's environment.
901 from the program's environment. It is not an error if no variable named
906 .BR exec.env. [ set ]
915 in the program's environment, possibly replacing the existing value.
918 may be omitted if the
920 qualifier is present.
923 Note that environment variable modifications are performed in order,
924 global modifications before local ones.
926 .SS "The `socket' source and target types"
929 source and target provide access to network services. Support is
930 currently provided for TCP/IP and Unix-domain sockets, although other
931 address types can be added with reasonable ease.
933 The syntax for socket sources and targets is:
934 .GS "Socket source and target"
961 The syntax of the source and target addresses depend on the address
962 types, which are described below. The default address type, if no
967 Socket sources support options; socket targets do not. The source
968 options provided are:
973 .BR unlimited | one-shot
975 Controls the behaviour of the source when it receives connections. A
977 limits the number of simultaneous connections. The value
981 removes any limit on the number of connections possible. The value
983 will remove the socket source after a single successful connection.
984 (Connections refused by access control systems don't count here.)
985 The default is to apply a limit of 256 concurrent connections. Use of
988 option is not recommended.
995 Whether to log incoming connections. If
997 (the default) incoming connections are logged, together with information
998 about the client (where available) and whether the connection was
999 accepted or refused. If
1001 log messages are not generated.
1004 Address types also provide their own options.
1006 .SS "The `inet' socket address type"
1009 address type provides access to TCP ports. The
1011 source and target addresses have the following syntax:
1012 .GS "Socket source and target"
1039 may be given as a port number or a service name from the
1041 file (or YP map if you do that sort of thing). A
1043 may be a textual hostname or a numerical IP address.
1047 source address accepts the following options:
1048 .OS "Socket options"
1049 .BR socket.inet. [ allow | deny ]
1055 Adds an entry to the source's access control list. If only one
1057 is given, the entry applies only to that address; if two are given, the
1058 first is a network address and the second is a netmask either in
1059 dotted-quad format or a simple number of bits (e.g.,
1063 mean the same), and the entry applies to any address which, when masked
1064 by the netmask, is equal to the masked network address.
1067 The access control rules are examined in the order: local entries first,
1068 then global ones, each in the order given in the configuration file.
1069 The first matching entry is used. If no entries match, the behaviour is
1072 of the last entry tried. If there are no entries defined, the default
1073 is to allow all clients.
1075 .SS "The `unix' socket address type"
1078 address type allows access to Unix-domain sockets. The syntax for
1080 source and target addresses is like this:
1081 .GS "Socket source and target"
1090 The following options are supported by the
1092 source address type:
1093 .OS "Socket options"
1094 .BR socket.unix.fattr. *
1098 source address accepts
1100 options to control the attributes of the socket file created.
1103 Sockets are removed if
1105 exits normally (which it will do if it runs out of sources or
1108 shuts down in a clean way).
1110 To forward the local port 25 to a main mail server:
1112 from 25 to mailserv:25
1114 To attach a fortune server to a Unix-domain socket:
1116 from unix:/tmp/fortunes
1117 to exec [/usr/games/fortune] { user nobody }
1119 To fetch a fortune from the server:
1121 from file stdin, stdout to unix:/tmp/fortunes
1126 from stdin, null to null, stdout
1129 .\"--------------------------------------------------------------------------
1130 .SH "SIGNAL HANDLING"
1134 program responds to various signals when it's running. If it receives
1141 shutdown: it removes all of its sources, and will exit when no more
1142 connections are running. (Note that if the disposition
1146 does not re-enable the signal. You'll have to send
1154 shutdown: it removes all sources and extant connections and closes down
1155 more-or-less immediately.
1157 Finally, if any configuration files (other than standard input) were
1160 on its command line using the
1164 signal may be sent to instruct
1166 to reload its configuration. Any existing connections are allowed to
1167 run their course. If no such configuration files are available,
1169 just logs a message about the signal and continues.
1172 .\"--------------------------------------------------------------------------
1173 .SH "GRAMMAR SUMMARY"
1237 .SS "File source and target"
1264 .RB [[ : ] fd [ : ]]
1266 .RB | stdin | stdout
1270 .RB [[ : ] file [ : ]]
1296 .RB [ : ] null [ : ]
1298 .SS "Exec source and target"
1338 .SS "Socket source and target"
1397 .\"--------------------------------------------------------------------------
1398 .SH "OPTION SUMMARY"
1400 .SS "File attributes (`fattr')"
1401 .IB prefix .fattr.mode
1405 .IB prefix .fattr.owner
1409 .IB prefix .fattr.group
1420 .BR no | truncate | append
1445 .BI exec.rlimit. limit \c
1446 .RB [ .hard | .soft ]
1455 .BR exec.env. [ set ]
1460 .SS "Socket options"
1464 .BR unlimited | one-shot
1470 .BR socket.inet. [ allow | deny ]
1476 .BR socket.unix.fattr. *
1478 .\"--------------------------------------------------------------------------
1481 The syntax for IP addresses and filenames is nasty.
1483 IPv6 is not supported yet. Because of
1485 socket address architecture, it's probably not a major piece of work to
1488 Please inform me of any security problems you think you've identified in
1489 this program. I take security very seriously, and I will fix security
1490 holes as a matter of priority when I find out about them. I will be
1491 annoyed if I have to read about problems on Bugtraq because they weren't
1494 The program is too complicated, and this manual page is too long.
1496 .\"--------------------------------------------------------------------------
1499 Mark Wooding, <mdw@nsict.org>
1501 .\"----- That's all, folks --------------------------------------------------