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 .\"----- Various bits of fancy styling --------------------------------------
30 .\" --- Indented paragraphs with right-aligned tags ---
34 \h'-\w'\fB\\$1\ \fP'u'\fB\\$1\ \fP\c
37 .\" --- Verbatim-oid typesetting ---
51 .\" --- Grammar markup ---
53 .\" This is mainly for the benefit of the automatic scripts which
54 .\" generate the grammar summary.
73 .\" --- Other bits of styling ---
89 .\"--------------------------------------------------------------------------
91 .TH fw 1 "1 July 1999" "Straylight/Edgeware" "fw port forwarder"
93 .\"--------------------------------------------------------------------------
98 .\"--------------------------------------------------------------------------
111 .\"--------------------------------------------------------------------------
116 program is a simple port forwarder. It supports a number of features
117 the author hasn't found in similar programs:
119 .I "Connection logging"
120 Each connection attempt to the forwarder is logged, giving the time of
121 the connection, the DNS-resolved hostname (if available), and the user
122 name resulting from an RFC931 lookup. These lookups are done
123 asynchronously to the main forwarder's operation.
126 Each forwarded port may have an access control list attached to it.
127 Only authorized hosts are allowed to connect. Access control checks are
128 performed by quick checks on the client's IP address.
130 .I "Nonblocking single-process design"
131 The internal structure of the server is completely nonblocking. The
132 connections don't block; the reading and writing don't block; the name
133 lookups don't block. This is all done in a single process, with the
134 single exception of the DNS resolver.
136 .I "Support for Unix-domain sockets"
137 Connections from and to Unix-domain sockets can be handled just as
138 easily as more normal Internet sockets. Access control doesn't work on
139 Unix domain sockets, though. (Yet.)
140 .SS "Command line options"
143 program understands a few simple command line options:
146 Displays a screen of help text on standard output and exits
149 .B "\-v, \-\-version"
150 Writes the version number to standard output and exits successfully.
153 Writes a terse usage summary to standard output and exits successfully.
155 .B "\-G, \-\-grammar"
156 Writes a summary of the configuration file grammar to standard output
157 and exits successfully.
159 .B "\-O, \-\-options"
160 Writes a summary of the source and target options to standard output and
163 .BI "\-f, \-\-file=" file
164 Read configuration information from
169 configuration file statement.
171 .B "\-d, \-\-daemon, \-\-fork"
172 Forks into the background after reading the configuration and
173 initializing properly.
175 .B "\-l, \-\-syslog, \-\-log"
176 Emit logging information to the system log, rather than standard error.
178 .B "\-p, \-\-pidfile=" file
185 is given too, then the process-id is written after forking (obviously).
188 Don't output any logging information. This option is not recommended
189 for normal use, although it can make system call traces clearer so I use
192 .BI "\-s, \-\-setuid=" user
193 Change uid to that of
195 which may be either a user name or uid number, after initializing all
196 the sources. This will usually require elevated privileges.
198 .BI "\-g, \-\-setgid=" group
199 Change gid to that of
201 which may be either a group name or gid number, after initializing all
202 the sources. If the operating system understands supplementary groups
203 then the supplementary groups list is altered to include only
206 Any further command line arguments are interpreted as configuration
207 lines to be read. Configuration supplied in command line arguments has
208 precisely the same syntax as configuration in files. If there are no
209 configuration statements on the command line, and no
211 options were supplied, configuration is read from standard input, if
212 stdin is not a terminal.
214 .\"--------------------------------------------------------------------------
215 .SH "CONFIGURATION LANGUAGE"
219 program has a fairly sophisticated configuration language to let you
220 describe which things should be forwarded where and what special
221 features there should be.
222 .SS "Lexical structure"
223 There are four types of characters.
225 .I "word constituent characters"
226 Word constituent characters are gathered together into words.
227 Depending on its surrounding context, a word might act as a keyword or a
228 string. All alphanumerics are word constituents, as is the hyphen
230 Other characters may change their status in future versions.
232 .I "self-delimiting characters"
233 Self-delimiting characters always stand alone. They act as punctuation,
234 shaping the sequence of words into more complex grammatical forms. The
247 are self-delimiting. Note that while some characters, e.g.,
251 require escaping by the shell, they are mostly optional in the grammar
252 and can tend to be omitted in quick hacks at the shell prompt.
254 .I "whitespace characters"
255 Whitespace characters separate words but are otherwise ignored. All
256 `normal' whitespace characters (e.g., space, tab and newline) are
257 considered to be whitespace for these purposes.
259 .I "special characters"
260 There are three special characters. The
262 character, if it appears at the start of a word, introduces a
264 which extends to the end of the current line or command-line argument.
265 Within a word, it behaves like a normal word-constituent character. The
268 escapes the following character causing it to be interpreted as a word
269 constituent regardless of its normal type. The double-quote
271 escapes all characters other than backslashes up to the next
272 double-quote and causes them to be regarded as word constituents. Note
273 that you don't have to quote a whole word. The backslash can escape a
274 quote character allowing you to insert it into a word if really
278 The overall syntax looks a bit like this:
317 If you prefer, the keyword
325 .SS "Sources and targets"
326 Forwarding is set up by attaching
330 Sources are things which are capable of
332 one end of a data flow on their own, while targets are things which are
333 capable of setting up the other end on demand. In the case of a TCP
334 port forwarder, the part which listens for incoming client connections
335 is the source, while the part which sets up outgoing connections to the
336 destination server is the target.
340 does is set up a collection of sources and targets based on your
341 configuration file so that when a source decides to initiate a data
342 flow, it tells its target to set its end up, and then squirts data back
343 and forth between the two until there's no more.
347 they stay around indefinitely setting up multiple attachments to
350 they set up one connection and then disappear. If all the sources
351 defined are transient, then
353 will quit when no more active sources remain and all connections have
358 program is fairly versatile. It allows you to attach any supported type
359 of source to any supported type of target. This will, I hope, be the
360 case in all future versions.
366 depend on the source or target type, and are therefore described in the
367 sections specific to the various types.
369 .SS "Options structure"
370 Most of the objects that
372 knows about (including sources and targets, but also other more specific
373 things such as socket address types) can have their behaviour modified
376 The options available at a particular point in the configuration depend
379 A global option, outside of a
381 has no context unless it is explicitly qualified, and affects global
382 behaviour. A local option, applied to a source or target in a
384 has the context of the type of source or target to which it is applied,
385 and affects only that source or target.
387 Note that it's important to distinguish between an option's context
388 (which is affected by its qualification) and its local or global
389 status. No matter how qualified, a global option will always control
390 default options for objects, and a local option will only affect a
391 specific source or target.
393 The syntax for qualifying options is like this:
418 Thus, you may qualify either an individual option or a sequence of
419 options. The two are equivalent; for example,
428 exec.rlimit.core = 0;
431 For each option, there is a sequence of prefixes which maximally qualify
432 that option. An option prefixed with this sequence is
433 .IR "fully qualified" .
434 In actual use, some or all of those prefixes may be omitted. However,
435 it's possible for the option to become
437 if you do this. For example, the option
442 .BR socket.unix.fattr.owner .
443 In this case, the ambiguity is benign: a local option will have as its
444 context an appropriate source or target, and both global options
445 actually control the same default. However, the option
451 which have separate defaults, and which one you actually get depends on
452 the exact implementation of
454 option parser. (Currently this would resolve to
456 although this may change in a later version.)
458 In this manual, options are usually shown in their fully-qualified form.
460 .SS "File attributes for created files: `fattr'"
465 sources and targets can create new filesystem objects. The
467 options allow control over the attributes of the newly-created objects.
472 use the same set of defaults, so a prefix of
474 is good enough for setting global options, and the implicit context
475 disambiguates local options.
477 The following file attribute options are supported:
478 .OS "File attribute options (`fattr')"
479 .IB prefix .fattr.mode
483 Sets the permissions mode for a new file. The
485 argument may be either an octal number or a
487 string which acts on the default permissions established by the
490 setting. The characters
494 do not have to be quoted within the mode string.
496 .OS "File attribute options (`fattr')"
497 .IB prefix .fattr.owner
501 Sets the owner for newly created files. On non-broken systems you will
502 need to be the superuser to set the owner on a file. The
504 may either be a numeric uid or a username. The default is not to change
505 the owner of the file once it's created. The synonyms
509 are accepted in place of
512 .OS "File attribute options (`fattr')"
513 .IB prefix .fattr.group
517 Sets the group for newly created files. You will usually need to be a
518 member of the group in question order to set the group of a file. The
520 may either be a numeric gid or a group name. The default is not to
521 change the group of the file once it's created. The synonym
523 is accepted in place of
527 .SS "The `file' source and target types"
530 source and target allow data to move to and from objects other
531 than sockets within the Unix filesystem. (Unix-domain sockets are
538 is used as a source, it is set up immediately.
542 sources and targets is like this:
543 .GS "File sources and targets"
576 .RB [[ : ] name [ : ]]
606 specification describes two files, the first to be used as input, the
607 second to be used as output, each described by an
610 If none of the keywords
615 are given, the type of an
617 is deduced from its nature: if it matches one of the strings
621 or begins with a digit, it's considered to be a file descriptor;
622 otherwise it's interpreted as a filename.
626 spec describes a file by its name within the filesystem. It is opened
627 when needed and closed again after use. For output files, the precise
628 behaviour is controlled by options described below.
632 spec attaches the input or output of the source or target to
637 spec uses an existing open file descriptor, given either by number or a
638 symbolic name. The name
640 refers to standard input (file descriptor 0 on normal systems) and
642 refers to standard output (file descriptor 1). The names work in
643 exactly the same way as the equivalent file descriptor numbers.
647 is omitted, the input
649 is used for both input and output. Exception: if the input refers to
650 standard input then the output will refer to standard output instead.
654 options apply equally to sources and targets. The options are as
661 Whether to create the output file if it doesn't exist. If
663 (the default), an error is reported if the file doesn't exist. If
665 the file is created if it doesn't exist.
670 .BR no | truncate | append
672 Controls the behaviour if the output file already exists. If
674 an error is reported. If
676 (the default), the existing file is replaced by the new data. If
678 the new data is appended to the file.
685 source and target also accept
687 options for controlling the attributes of the created file.
690 Under no circumstances will
692 create a file through a `dangling' symbolic link.
694 .SS "The `exec' source and target types"
697 source and target execute programs and allow access to their standard
698 input and output streams. Both source and target have the same syntax,
700 .GS "Exec source and target"
740 If a single word is given, it is a
742 and will be passed to the Bourne shell for execution. If a
743 bracket-enclosed sequence of words is given, it is considered to be a
744 list of arguments to pass to the program: if a
746 is also supplied, it names the file containing the program to execute;
747 otherwise the file named by the first argument
751 Note that the shell command or program name string must, if present,
752 have any delimiter characters (including
756 quoted; this is not required in the
760 The standard input and output of the program are forwarded to the other
761 end of the connection. The standard error stream is caught by
767 source and target both understand the same set of options. The list of
768 options supported is as follows:
774 Whether to log the start and end of executed programs. If
776 (the default), a log message is emitted when the program is started
777 listing its process id, and another is emitted when the program finishes
778 giving its process id and exit status. If
780 these messages are not emitted. However the standard error stream is
783 abbreviation is accepted as a synonym for
791 Sets the current directory from which the the program should be run.
792 The default is not to change directory. The synonyms
797 are accepted in place of
805 Sets the root directory for the program, using the
807 system call. You must be the superuser for this option to work. The
808 default is not to set a root directory. The synonym
810 is accepted in place of
818 Sets the user (real and effective uid) to run the program as. This will
819 usually require superuser privileges to work. The default is not to
820 change uid. The synonym
822 is accepted in place of
830 Sets the group (real and effective gid) to run the program as. If
831 running with superuser privileges, the supplementary groups list is
832 cleared at the same time. The default is not to change gid (or clear
833 the supplementary groups list). The synonym
835 is accepted in place of
839 .BI exec.rlimit. limit \c
840 .RB [ .hard | .soft ]
844 Set resource limits for the program. The
846 may be one of the resource limit names described in
848 in lower-case and without the
856 is a number, followed optionally by
858 to multiply by 1024 (2\*(ss10\*(se),
860 to multiply by 1048576 (2\*(ss20\*(se), or
862 to multiply by 1073741824 (2\*(ss30\*(se); purists can use upper-case
863 versions of these if they want. If
867 was specified, only the hard or soft limit is set; otherwise both are
868 set to the same value. Only the superuser can raise the hard limit.
869 The soft limit cannot be set above the hard limit.
874 Clears the program's environment.
882 from the program's environment. It is not an error if no variable named
887 .BR exec.env. [ set ]
896 in the program's environment, possibly replacing the existing value.
899 may be omitted if the
901 qualifier is present.
904 Note that environment variable modifications are performed in order,
905 global modifications before local ones.
907 .SS "The `socket' source and target types"
910 source and target provide access to network services. Support is
911 currently provided for TCP/IP and Unix-domain sockets, although other
912 address types can be added with reasonable ease.
914 The syntax for socket sources and targets is:
915 .GS "Socket source and target"
927 .RB [ socket [ .\& ]]
935 .RB [ socket [ .\& ]]
942 The syntax of the source and target addresses depend on the address
943 types, which are described below. The default address type, if no
948 Socket sources support options; socket targets do not. The source
949 options provided are:
954 .BR unlimited | one-shot
956 Controls the behaviour of the source when it receives connections. A
958 limits the number of simultaneous connections. The value
962 removes any limit on the number of connections possible. The value
964 will remove the socket source after a single successful connection.
965 (Connections refused by access control systems don't count here.)
966 The default is to apply a limit of 256 concurrent connections. Use of
969 option is not recommended.
976 Sets the maximum of the kernel incoming connection queue for this socket
977 source. This is the number given to the
979 system call. The default is 5.
986 Whether to log incoming connections. If
988 (the default) incoming connections are logged, together with information
989 about the client (where available) and whether the connection was
990 accepted or refused. If
992 log messages are not generated.
995 Address types also provide their own options.
997 .SS "The `inet' socket address type"
1000 address type provides access to TCP ports. The
1002 source and target addresses have the following syntax:
1003 .GS "Socket source and target"
1030 may be given as a port number or a service name from the
1032 file (or YP map if you do that sort of thing). A
1034 may be a textual hostname or a numerical IP address.
1038 source address accepts the following options:
1039 .OS "Socket options"
1040 .B socket.inet.source.addr
1045 Specify the IP address on which to listen for incoming connections. The
1048 which means to listen on all addresses, though it may be useful to
1049 specify this explicitly, if the global setting is different.
1051 .OS "Socket options"
1052 .BR socket.inet.source. [ 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.
1069 .OS "Socket options"
1070 .BR socket.inet.source. [ allow | deny ]
1073 Accept or reject connections from low-numbered `privileged' ports, in
1076 .OS "Socket options"
1077 .B socket.inet.dest.addr
1082 Specify the IP address to bind the local socket to when making an
1083 outbound connection. The default is
1085 which means to use whichever address the kernel thinks is most
1086 convenient. This option is useful if the destination is doing
1087 host-based access control and your server is multi-homed.
1089 .OS "Socket options"
1090 .B socket.inet.dest.priv-port
1094 Make a privileged connection (i.e., from a low-numbered port) to the
1095 target. This only works if
1097 was started with root privileges. However, it still works if
1101 privileges after initialization (the
1103 option). Before dropping privileges,
1105 forks off a separate process which continues to run with root
1106 privileges, and on demand passes sockets bound to privileged ports and
1107 connected to the appropriate peer back to the main program. The
1108 privileged child only passes back sockets connected to peer addresses
1109 named in the configuration; even if the
1111 process is compromised, it can't make privileged connections to other
1112 addresses. Note that because of this privilege separation, it's also
1113 not possible to reconfigure
1115 to make privileged connections to different peer addresses later by
1116 changing configuration files and sending the daemon a
1120 The access control rules are examined in the order: local entries first,
1121 then global ones, each in the order given in the configuration file.
1122 The first matching entry is used. If no entries match, the behaviour is
1125 of the last entry tried. If there are no entries defined, the default
1126 is to allow all clients.
1128 .SS "The `unix' socket address type"
1131 address type allows access to Unix-domain sockets. The syntax for
1133 source and target addresses is like this:
1134 .GS "Socket source and target"
1143 The following options are supported by the
1145 source address type:
1146 .OS "Socket options"
1147 .BR socket.unix.fattr. *
1151 source address accepts
1153 options to control the attributes of the socket file created.
1156 Sockets are removed if
1158 exits normally (which it will do if it runs out of sources or
1161 shuts down in a clean way).
1163 To forward the local port 25 to a main mail server:
1165 from 25 to mailserv:25
1167 To attach a fortune server to a Unix-domain socket:
1169 from unix:/tmp/fortunes
1170 to exec [/usr/games/fortune] { user nobody }
1172 To fetch a fortune from the server:
1174 from file stdin, stdout to unix:/tmp/fortunes
1179 from file stdin, null to file null, stdout
1181 .sp -1 \" undo final space
1183 .\"--------------------------------------------------------------------------
1184 .SH "SIGNAL HANDLING"
1188 program responds to various signals when it's running. If it receives
1195 shutdown: it removes all of its sources, and will exit when no more
1196 connections are running. (Note that if the disposition
1200 does not re-enable the signal. You'll have to send
1208 shutdown: it removes all sources and extant connections and closes down
1209 more-or-less immediately.
1211 Finally, if any configuration files (other than standard input) were
1214 on its command line using the
1218 signal may be sent to instruct
1220 to reload its configuration. Any existing connections are allowed to
1221 run their course. If no such configuration files are available,
1223 just logs a message about the signal and continues.
1225 .\"--------------------------------------------------------------------------
1226 .SH "GRAMMAR SUMMARY"
1290 .SS "File source and target"
1317 .RB [[ : ] fd [ : ]]
1319 .RB | stdin | stdout
1323 .RB [[ : ] name [ : ]]
1349 .RB [ : ] null [ : ]
1351 .SS "Exec source and target"
1391 .SS "Socket source and target"
1403 .RB [ socket [ .\& ]]
1411 .RB [ socket [ .\& ]]
1450 .\"--------------------------------------------------------------------------
1451 .SH "OPTION SUMMARY"
1453 .SS "File attributes (`fattr')"
1454 .IB prefix .fattr.mode
1458 .IB prefix .fattr.owner
1462 .IB prefix .fattr.group
1473 .BR no | truncate | append
1498 .BI exec.rlimit. limit \c
1499 .RB [ .hard | .soft ]
1508 .BR exec.env. [ set ]
1513 .SS "Socket options"
1517 .BR unlimited | one-shot
1527 .BR socket.inet.source. [ allow | deny ]
1533 .BR socket.inet.source. [ allow | deny ]
1536 .B socket.inet.source.addr
1541 .B socket.inet.dest.addr
1546 .B socket.inet.dest.priv-port
1550 .BR socket.unix.fattr. *
1552 .\"--------------------------------------------------------------------------
1555 The syntax for IP addresses and filenames is nasty.
1557 IPv6 is not supported yet. Because of
1559 socket address architecture, it's probably not a major piece of work to
1562 Please inform me of any security problems you think you've identified in
1563 this program. I take security very seriously, and I will fix security
1564 holes as a matter of priority when I find out about them. I will be
1565 annoyed if I have to read about problems on Bugtraq because they weren't
1568 The program is too complicated, and this manual page is too long.
1570 .\"--------------------------------------------------------------------------
1573 Mark Wooding, <mdw@nsict.org>
1575 .\"----- That's all, folks --------------------------------------------------