3 .\" $Id: fw.1,v 1.12 2001/02/23 09:11:29 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.12 2001/02/23 09:11:29 mdw
32 .\" Update manual style.
34 .\" Revision 1.11 2001/02/05 19:47:11 mdw
35 .\" Minor fixings to wording.
37 .\" Revision 1.10 2001/02/03 20:30:03 mdw
38 .\" Support re-reading config files on SIGHUP.
40 .\" Revision 1.9 2000/03/23 00:37:33 mdw
41 .\" Add option to change user and group after initialization. Naughtily
42 .\" reassign short equivalents of --grammar and --options.
44 .\" Revision 1.8 1999/12/22 15:44:43 mdw
45 .\" Fix some errors, and document new option.
47 .\" Revision 1.7 1999/10/22 22:45:15 mdw
48 .\" Describe new socket connection options.
50 .\" Revision 1.6 1999/10/10 16:46:29 mdw
51 .\" Include grammar and options references at the end of the manual.
53 .\" Revision 1.5 1999/09/26 18:18:05 mdw
54 .\" Remove a fixed bug from the list. Fix some nasty formatting
57 .\" Revision 1.4 1999/08/19 18:32:48 mdw
58 .\" Improve lexical analysis. In particular, `chmod' patterns don't have to
59 .\" be quoted any more.
61 .\" Revision 1.3 1999/07/30 06:49:00 mdw
62 .\" Minor tidying and typo correction.
64 .\" Revision 1.2 1999/07/26 23:31:04 mdw
65 .\" Document lots of new features and syntax.
68 .\"----- Various bits of fancy styling --------------------------------------
70 .\" --- Indented paragraphs with right-aligned tags ---
74 \h'-\w'\fB\\$1\ \fP'u'\fB\\$1\ \fP\c
77 .\" --- Verbatim-oid typesetting ---
91 .\" --- Grammar markup ---
93 .\" This is mainly for the benefit of the automatic scripts which
94 .\" generate the grammar summary.
113 .\" --- Other bits of styling ---
129 .\"--------------------------------------------------------------------------
131 .TH fw 1 "1 July 1999" "Straylight/Edgeware" "fw port forwarder"
133 .\"--------------------------------------------------------------------------
138 .\"--------------------------------------------------------------------------
151 .\"--------------------------------------------------------------------------
156 program is a simple port forwarder. It supports a number of features
157 the author hasn't found in similar programs:
159 .I "Connection logging"
160 Each connection attempt to the forwarder is logged, giving the time of
161 the connection, the DNS-resolved hostname (if available), and the user
162 name resulting from an RFC931 lookup. These lookups are done
163 asynchronously to the main forwarder's operation.
166 Each forwarded port may have an access control list attached to it.
167 Only authorized hosts are allowed to connect. Access control checks are
168 performed by quick checks on the client's IP address.
170 .I "Nonblocking single-process design"
171 The internal structure of the server is completely nonblocking. The
172 connections don't block; the reading and writing don't block; the name
173 lookups don't block. This is all done in a single process, with the
174 single exception of the DNS resolver.
176 .I "Support for Unix-domain sockets"
177 Connections from and to Unix-domain sockets can be handled just as
178 easily as more normal Internet sockets. Access control doesn't work on
179 Unix domain sockets, though. (Yet.)
180 .SS "Command line options"
183 program understands a few simple command line options:
186 Displays a screen of help text on standard output and exits
189 .B "\-v, \-\-version"
190 Writes the version number to standard output and exits successfully.
193 Writes a terse usage summary to standard output and exits successfully.
195 .B "\-G, \-\-grammar"
196 Writes a summary of the configuration file grammar to standard output
197 and exits successfully.
199 .B "\-O, \-\-options"
200 Writes a summary of the source and target options to standard output and
203 .BI "\-f, \-\-file=" file
204 Read configuration information from
209 configuration file statement.
211 .B "\-d, \-\-daemon, \-\-fork"
212 Forks into the background after reading the configuration and
213 initializing properly.
215 .B "\-l, \-\-syslog, \-\-log"
216 Emit logging information to the system log, rather than standard error.
219 Don't output any logging information. This option is not recommended
220 for normal use, although it can make system call traces clearer so I use
223 .BI "\-s, \-\-setuid=" user
224 Change uid to that of
226 which may be either a user name or uid number, after initializing all
227 the sources. This will usually require elevated privileges.
229 .BI "\-g, \-\-setgid=" group
230 Change gid to that of
232 which may be either a group name or gid number, after initializing all
233 the sources. If the operating system understands supplementary groups
234 then the supplementary groups list is altered to include only
237 Any further command line arguments are interpreted as configuration
238 lines to be read. Configuration supplied in command line arguments has
239 precisely the same syntax as configuration in files. If there are no
240 configuration statements on the command line, and no
242 options were supplied, configuration is read from standard input, if
243 stdin is not a terminal.
245 .\"--------------------------------------------------------------------------
246 .SH "CONFIGURATION LANGUAGE"
250 program has a fairly sophisticated configuration language to let you
251 describe which things should be forwarded where and what special
252 features there should be.
253 .SS "Lexical structure"
254 There are four types of characters.
256 .I "word constituent characters"
257 Word constituent characters are gathered together into words.
258 Depending on its surrounding context, a word might act as a keyword or a
259 string. All alphanumerics are word constituents, as is the hyphen
261 Other characters may change their status in future versions.
263 .I "self-delimiting characters"
264 Self-delimiting characters always stand alone. They act as punctuation,
265 shaping the sequence of words into more complex grammatical forms. The
278 are self-delimiting. Note that while some characters, e.g.,
282 require escaping by the shell, they are mostly optional in the grammar
283 and can tend to be omitted in quick hacks at the shell prompt.
285 .I "whitespace characters"
286 Whitespace characters separate words but are otherwise ignored. All
287 `normal' whitespace characters (e.g., space, tab and newline) are
288 considered to be whitespace for these purposes.
290 .I "special characters"
291 There are three special characters. The
293 character, if it appears at the start of a word, introduces a
295 which extends to the end of the current line or command-line argument.
296 Within a word, it behaves like a normal word-constituent character. The
299 escapes the following character causing it to be interpreted as a word
300 constituent regardless of its normal type. The double-quote
302 escapes all characters other than backslashes up to the next
303 double-quote and causes them to be regarded as word constituents. Note
304 that you don't have to quote a whole word. The backslash can escape a
305 quote character allowing you to insert it into a word if really
309 The overall syntax looks a bit like this:
348 If you prefer, the keyword
356 .SS "Sources and targets"
357 Forwarding is set up by attaching
361 Sources are things which are capable of
363 one end of a data flow on their own, while targets are things which are
364 capable of setting up the other end on demand. In the case of a TCP
365 port forwarder, the part which listens for incoming client connections
366 is the source, while the part which sets up outgoing connections to the
367 destination server is the target.
371 does is set up a collection of sources and targets based on your
372 configuration file so that when a source decides to initiate a data
373 flow, it tells its target to set its end up, and then squirts data back
374 and forth between the two until there's no more.
378 they stay around indefinitely setting up multiple attachments to
381 they set up one connection and then disappear. If all the sources
382 defined are transient, then
384 will quit when no more active sources remain and all connections have
389 program is fairly versatile. It allows you to attach any supported type
390 of source to any supported type of target. This will, I hope, be the
391 case in all future versions.
397 depend on the source or target type, and are therefore described in the
398 sections specific to the various types.
400 .SS "Options structure"
401 Most of the objects that
403 knows about (including sources and targets, but also other more specific
404 things such as socket address types) can have their behaviour modified
407 The options available at a particular point in the configuration depend
410 A global option, outside of a
412 has no context unless it is explicitly qualified, and affects global
413 behaviour. A local option, applied to a source or target in a
415 has the context of the type of source or target to which it is applied,
416 and affects only that source or target.
418 Note that it's important to distinguish between an option's context
419 (which is affected by its qualification) and its local or global
420 status. No matter how qualified, a global option will always control
421 default options for objects, and a local option will only affect a
422 specific source or target.
424 The syntax for qualifying options is like this:
449 Thus, you may qualify either an individual option or a sequence of
450 options. The two are equivalent; for example,
459 exec.rlimit.core = 0;
462 For each option, there is a sequence of prefixes which maximally qualify
463 that option. An option prefixed with this sequence is
464 .IR "fully qualified" .
465 In actual use, some or all of those prefixes may be omitted. However,
466 it's possible for the option to become
468 if you do this. For example, the option
473 .BR socket.unix.fattr.owner .
474 In this case, the ambiguity is benign: a local option will have as its
475 context an appropriate source or target, and both global options
476 actually control the same default. However, the option
482 which have separate defaults, and which one you actually get depends on
483 the exact implementation of
485 option parser. (Currently this would resolve to
487 although this may change in a later version.)
489 In this manual, options are usually shown in their fully-qualified form.
491 .SS "File attributes for created files: `fattr'"
496 sources and targets can create new filesystem objects. The
498 options allow control over the attributes of the newly-created objects.
503 use the same set of defaults, so a prefix of
505 is good enough for setting global options, and the implicit context
506 disambiguates local options.
508 The following file attribute options are supported:
509 .OS "File attribute options (`fattr')"
510 .IB prefix .fattr.mode
514 Sets the permissions mode for a new file. The
516 argument may be either an octal number or a
518 string which acts on the default permissions established by the
521 setting. The characters
525 do not have to be quoted within the mode string.
527 .OS "File attribute options (`fattr')"
528 .IB prefix .fattr.owner
532 Sets the owner for newly created files. On non-broken systems you will
533 need to be the superuser to set the owner on a file. The
535 may either be a numeric uid or a username. The default is not to change
536 the owner of the file once it's created. The synonyms
540 are accepted in place of
543 .OS "File attribute options (`fattr')"
544 .IB prefix .fattr.group
548 Sets the group for newly created files. You will usually need to be a
549 member of the group in question order to set the group of a file. The
551 may either be a numeric gid or a group name. The default is not to
552 change the group of the file once it's created. The synonym
554 is accepted in place of
558 .SS "The `file' source and target types"
561 source and target allow data to move to and from objects other
562 than sockets within the Unix filesystem. (Unix-domain sockets are
569 is used as a source, it is set up immediately.
573 sources and targets is like this:
574 .GS "File sources and targets"
607 .RB [[ : ] file [ : ]]
637 specification describes two files, the first to be used as input, the
638 second to be used as output, each described by an
641 If none of the keywords
646 are given, the type of an
648 is deduced from its nature: if it matches one of the strings
652 or begins with a digit, it's considered to be a file descriptor;
653 otherwise it's interpreted as a filename.
657 spec describes a file by its name within the filesystem. It is opened
658 when needed and closed again after use. For output files, the precise
659 behaviour is controlled by options described below.
663 spec attaches the input or output of the source or target to
668 spec uses an existing open file descriptor, given either by number or a
669 symbolic name. The name
671 refers to standard input (file descriptor 0 on normal systems) and
673 refers to standard output (file descriptor 1). The names work in
674 exactly the same way as the equivalent file descriptor numbers.
678 is omitted, the input
680 is used for both input and output. Exception: if the input refers to
681 standard input then the output will refer to standard output instead.
685 options apply equally to sources and targets. The options are as
692 Whether to create the output file if it doesn't exist. If
694 (the default), an error is reported if the file doesn't exist. If
696 the file is created if it doesn't exist.
701 .BR no | truncate | append
703 Controls the behaviour if the output file already exists. If
705 an error is reported. If
707 (the default), the existing file is replaced by the new data. If
709 the new data is appended to the file.
716 source and target also accept
718 options for controlling the attributes of the created file.
721 Under no circumstances will
723 create a file through a `dangling' symbolic link.
725 .SS "The `exec' source and target types"
728 source and target execute programs and allow access to their standard
729 input and output streams. Both source and target have the same syntax,
731 .GS "Exec source and target"
771 If a single word is given, it is a
773 and will be passed to the Bourne shell for execution. If a
774 bracket-enclosed sequence of words is given, it is considered to be a
775 list of arguments to pass to the program: if a
777 is also supplied, it names the file containing the program to execute;
778 otherwise the file named by the first argument
782 The standard input and output of the program are forwarded to the other
783 end of the connection. The standard error stream is caught by
789 source and target both understand the same set of options. The list of
790 options supported is as follows:
796 Whether to log the start and end of executed programs. If
798 (the default), a log message is emitted when the program is started
799 listing its process id, and another is emitted when the program finishes
800 giving its process id and exit status. If
802 these messages are not emitted. However the standard error stream is
805 abbreviation is accepted as a synonym for
813 Sets the current directory from which the the program should be run.
814 The default is not to change directory. The synonyms
819 are accepted in place of
827 Sets the root directory for the program, using the
829 system call. You must be the superuser for this option to work. The
830 default is not to set a root directory. The synonym
832 is accepted in place of
840 Sets the user (real and effective uid) to run the program as. This will
841 usually require superuser privileges to work. The default is not to
842 change uid. The synonym
844 is accepted in place of
852 Sets the group (real and effective gid) to run the program as. If
853 running with superuser privileges, the supplementary groups list is
854 cleared at the same time. The default is not to change gid (or clear
855 the supplementary groups list). The synonym
857 is accepted in place of
861 .BI exec.rlimit. limit \c
862 .RB [ .hard | .soft ]
866 Set resource limits for the program. The
868 may be one of the resource limit names described in
870 in lower-case and without the
878 is a number, followed optionally by
880 to multiply by 1024 (2\*(ss10\*(se),
882 to multiply by 1048576 (2\*(ss20\*(se), or
884 to multiply by 1073741824 (2\*(ss30\*(se); purists can use upper-case
885 versions of these if they want. If
889 was specified, only the hard or soft limit is set; otherwise both are
890 set to the same value. Only the superuser can raise the hard limit.
891 The soft limit cannot be set above the hard limit.
896 Clears the program's environment.
904 from the program's environment. It is not an error if no variable named
909 .BR exec.env. [ set ]
918 in the program's environment, possibly replacing the existing value.
921 may be omitted if the
923 qualifier is present.
926 Note that environment variable modifications are performed in order,
927 global modifications before local ones.
929 .SS "The `socket' source and target types"
932 source and target provide access to network services. Support is
933 currently provided for TCP/IP and Unix-domain sockets, although other
934 address types can be added with reasonable ease.
936 The syntax for socket sources and targets is:
937 .GS "Socket source and target"
964 The syntax of the source and target addresses depend on the address
965 types, which are described below. The default address type, if no
970 Socket sources support options; socket targets do not. The source
971 options provided are:
976 .BR unlimited | one-shot
978 Controls the behaviour of the source when it receives connections. A
980 limits the number of simultaneous connections. The value
984 removes any limit on the number of connections possible. The value
986 will remove the socket source after a single successful connection.
987 (Connections refused by access control systems don't count here.)
988 The default is to apply a limit of 256 concurrent connections. Use of
991 option is not recommended.
998 Whether to log incoming connections. If
1000 (the default) incoming connections are logged, together with information
1001 about the client (where available) and whether the connection was
1002 accepted or refused. If
1004 log messages are not generated.
1007 Address types also provide their own options.
1009 .SS "The `inet' socket address type"
1012 address type provides access to TCP ports. The
1014 source and target addresses have the following syntax:
1015 .GS "Socket source and target"
1042 may be given as a port number or a service name from the
1044 file (or YP map if you do that sort of thing). A
1046 may be a textual hostname or a numerical IP address.
1050 source address accepts the following options:
1051 .OS "Socket options"
1052 .BR socket.inet. [ allow | deny ]
1058 Adds an entry to the source's access control list. If only one
1060 is given, the entry applies only to that address; if two are given, the
1061 first is a network address and the second is a netmask either in
1062 dotted-quad format or a simple number of bits (e.g.,
1066 mean the same), and the entry applies to any address which, when masked
1067 by the netmask, is equal to the masked network address.
1070 The access control rules are examined in the order: local entries first,
1071 then global ones, each in the order given in the configuration file.
1072 The first matching entry is used. If no entries match, the behaviour is
1075 of the last entry tried. If there are no entries defined, the default
1076 is to allow all clients.
1078 .SS "The `unix' socket address type"
1081 address type allows access to Unix-domain sockets. The syntax for
1083 source and target addresses is like this:
1084 .GS "Socket source and target"
1093 The following options are supported by the
1095 source address type:
1096 .OS "Socket options"
1097 .BR socket.unix.fattr. *
1101 source address accepts
1103 options to control the attributes of the socket file created.
1106 Sockets are removed if
1108 exits normally (which it will do if it runs out of sources or
1111 shuts down in a clean way).
1113 To forward the local port 25 to a main mail server:
1115 from 25 to mailserv:25
1117 To attach a fortune server to a Unix-domain socket:
1119 from unix:/tmp/fortunes
1120 to exec [/usr/games/fortune] { user nobody }
1122 To fetch a fortune from the server:
1124 from file stdin, stdout to unix:/tmp/fortunes
1129 from stdin, null to null, stdout
1132 .\"--------------------------------------------------------------------------
1133 .SH "SIGNAL HANDLING"
1137 program responds to various signals when it's running. If it receives
1144 shutdown: it removes all of its sources, and will exit when no more
1145 connections are running. (Note that if the disposition
1149 does not re-enable the signal. You'll have to send
1157 shutdown: it removes all sources and extant connections and closes down
1158 more-or-less immediately.
1160 Finally, if any configuration files (other than standard input) were
1163 on its command line using the
1167 signal may be sent to instruct
1169 to reload its configuration. Any existing connections are allowed to
1170 run their course. If no such configuration files are available,
1172 just logs a message about the signal and continues.
1175 .\"--------------------------------------------------------------------------
1176 .SH "GRAMMAR SUMMARY"
1240 .SS "File source and target"
1267 .RB [[ : ] fd [ : ]]
1269 .RB | stdin | stdout
1273 .RB [[ : ] file [ : ]]
1299 .RB [ : ] null [ : ]
1301 .SS "Exec source and target"
1341 .SS "Socket source and target"
1400 .\"--------------------------------------------------------------------------
1401 .SH "OPTION SUMMARY"
1403 .SS "File attributes (`fattr')"
1404 .IB prefix .fattr.mode
1408 .IB prefix .fattr.owner
1412 .IB prefix .fattr.group
1423 .BR no | truncate | append
1448 .BI exec.rlimit. limit \c
1449 .RB [ .hard | .soft ]
1458 .BR exec.env. [ set ]
1463 .SS "Socket options"
1467 .BR unlimited | one-shot
1473 .BR socket.inet. [ allow | deny ]
1479 .BR socket.unix.fattr. *
1481 .\"--------------------------------------------------------------------------
1484 The syntax for IP addresses and filenames is nasty.
1486 IPv6 is not supported yet. Because of
1488 socket address architecture, it's probably not a major piece of work to
1491 Please inform me of any security problems you think you've identified in
1492 this program. I take security very seriously, and I will fix security
1493 holes as a matter of priority when I find out about them. I will be
1494 annoyed if I have to read about problems on Bugtraq because they weren't
1497 The program is too complicated, and this manual page is too long.
1499 .\"--------------------------------------------------------------------------
1502 Mark Wooding, <mdw@nsict.org>
1504 .\"----- That's all, folks --------------------------------------------------