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 .\"--------------------------------------------------------------------------
113 .\"--------------------------------------------------------------------------
118 program is a simple port forwarder. It supports a number of features
119 the author hasn't found in similar programs:
121 .I "Connection logging"
122 Each connection attempt to the forwarder is logged, giving the time of
123 the connection, the DNS-resolved hostname (if available), and the user
124 name resulting from an RFC931 lookup. These lookups are done
125 asynchronously to the main forwarder's operation.
128 Each forwarded port may have an access control list attached to it.
129 Only authorized hosts are allowed to connect. Access control checks are
130 performed by quick checks on the client's IP address.
132 .I "Nonblocking single-process design"
133 The internal structure of the server is completely nonblocking. The
134 connections don't block; the reading and writing don't block; the name
135 lookups don't block. This is all done in a single process, with the
136 single exception of the DNS resolver.
138 .I "Support for Unix-domain sockets"
139 Connections from and to Unix-domain sockets can be handled just as
140 easily as more normal Internet sockets. Access control doesn't work on
141 Unix domain sockets, though. (Yet.)
142 .SS "Command line options"
145 program understands a few simple command line options:
148 Displays a screen of help text on standard output and exits
151 .B "\-v, \-\-version"
152 Writes the version number to standard output and exits successfully.
155 Writes a terse usage summary to standard output and exits successfully.
157 .B "\-G, \-\-grammar"
158 Writes a summary of the configuration file grammar to standard output
159 and exits successfully.
161 .B "\-O, \-\-options"
162 Writes a summary of the source and target options to standard output and
165 .BI "\-f, \-\-file=" file
166 Read configuration information from
171 configuration file statement.
173 .B "\-d, \-\-daemon, \-\-fork"
174 Forks into the background after reading the configuration and
175 initializing properly.
177 .B "\-l, \-\-syslog, \-\-log"
178 Emit logging information to the system log, rather than standard error.
180 .BI "\-p, \-\-pidfile=" file
187 is given too, then the process-id is written after forking (obviously).
190 Don't output any logging information. This option is not recommended
191 for normal use, although it can make system call traces clearer so I use
194 .BI "\-s, \-\-setuid=" user
195 Change uid to that of
197 which may be either a user name or uid number, after initializing all
198 the sources. This will usually require elevated privileges.
200 .BI "\-g, \-\-setgid=" group
201 Change gid to that of
203 which may be either a group name or gid number, after initializing all
204 the sources. If the operating system understands supplementary groups
205 then the supplementary groups list is altered to include only
208 Any further command line arguments are interpreted as configuration
209 lines to be read. Configuration supplied in command line arguments has
210 precisely the same syntax as configuration in files. If there are no
211 configuration statements on the command line, and no
213 options were supplied, configuration is read from standard input, if
214 stdin is not a terminal.
216 .\"--------------------------------------------------------------------------
217 .SH "CONFIGURATION LANGUAGE"
221 program has a fairly sophisticated configuration language to let you
222 describe which things should be forwarded where and what special
223 features there should be.
224 .SS "Lexical structure"
225 There are four types of characters.
227 .I "word constituent characters"
228 Word constituent characters are gathered together into words.
229 Depending on its surrounding context, a word might act as a keyword or a
230 string. All alphanumerics are word constituents, as is the hyphen
232 Other characters may change their status in future versions.
234 .I "self-delimiting characters"
235 Self-delimiting characters always stand alone. They act as punctuation,
236 shaping the sequence of words into more complex grammatical forms. The
249 are self-delimiting. Note that while some characters, e.g.,
253 require escaping by the shell, they are mostly optional in the grammar
254 and can tend to be omitted in quick hacks at the shell prompt.
256 .I "whitespace characters"
257 Whitespace characters separate words but are otherwise ignored. All
258 `normal' whitespace characters (e.g., space, tab and newline) are
259 considered to be whitespace for these purposes.
261 .I "special characters"
262 There are three special characters. The
264 character, if it appears at the start of a word, introduces a
266 which extends to the end of the current line or command-line argument.
267 Within a word, it behaves like a normal word-constituent character. The
270 escapes the following character causing it to be interpreted as a word
271 constituent regardless of its normal type. The double-quote
273 escapes all characters other than backslashes up to the next
274 double-quote and causes them to be regarded as word constituents. Note
275 that you don't have to quote a whole word. The backslash can escape a
276 quote character allowing you to insert it into a word if really
280 The overall syntax looks a bit like this:
319 If you prefer, the keyword
327 .SS "Sources and targets"
328 Forwarding is set up by attaching
332 Sources are things which are capable of
334 one end of a data flow on their own, while targets are things which are
335 capable of setting up the other end on demand. In the case of a TCP
336 port forwarder, the part which listens for incoming client connections
337 is the source, while the part which sets up outgoing connections to the
338 destination server is the target.
342 does is set up a collection of sources and targets based on your
343 configuration file so that when a source decides to initiate a data
344 flow, it tells its target to set its end up, and then squirts data back
345 and forth between the two until there's no more.
349 they stay around indefinitely setting up multiple attachments to
352 they set up one connection and then disappear. If all the sources
353 defined are transient, then
355 will quit when no more active sources remain and all connections have
360 program is fairly versatile. It allows you to attach any supported type
361 of source to any supported type of target. This will, I hope, be the
362 case in all future versions.
368 depend on the source or target type, and are therefore described in the
369 sections specific to the various types.
371 .SS "Options structure"
372 Most of the objects that
374 knows about (including sources and targets, but also other more specific
375 things such as socket address types) can have their behaviour modified
378 The options available at a particular point in the configuration depend
381 A global option, outside of a
383 has no context unless it is explicitly qualified, and affects global
384 behaviour. A local option, applied to a source or target in a
386 has the context of the type of source or target to which it is applied,
387 and affects only that source or target.
389 Note that it's important to distinguish between an option's context
390 (which is affected by its qualification) and its local or global
391 status. No matter how qualified, a global option will always control
392 default options for objects, and a local option will only affect a
393 specific source or target.
395 The syntax for qualifying options is like this:
420 Thus, you may qualify either an individual option or a sequence of
421 options. The two are equivalent; for example,
430 exec.rlimit.core = 0;
433 For each option, there is a sequence of prefixes which maximally qualify
434 that option. An option prefixed with this sequence is
435 .IR "fully qualified" .
436 In actual use, some or all of those prefixes may be omitted. However,
437 it's possible for the option to become
439 if you do this. For example, the option
444 .BR socket.unix.fattr.owner .
445 In this case, the ambiguity is benign: a local option will have as its
446 context an appropriate source or target, and both global options
447 actually control the same default. However, the option
453 which have separate defaults, and which one you actually get depends on
454 the exact implementation of
456 option parser. (Currently this would resolve to
458 although this may change in a later version.)
460 In this manual, options are usually shown in their fully-qualified form.
462 .SS "File attributes for created files: `fattr'"
467 sources and targets can create new filesystem objects. The
469 options allow control over the attributes of the newly-created objects.
474 use the same set of defaults, so a prefix of
476 is good enough for setting global options, and the implicit context
477 disambiguates local options.
479 The following file attribute options are supported:
480 .OS "File attribute options (`fattr')"
481 .IB prefix .fattr.mode
485 Sets the permissions mode for a new file. The
487 argument may be either an octal number or a
489 string which acts on the default permissions established by the
492 setting. The characters
496 do not have to be quoted within the mode string.
498 .OS "File attribute options (`fattr')"
499 .IB prefix .fattr.owner
503 Sets the owner for newly created files. On non-broken systems you will
504 need to be the superuser to set the owner on a file. The
506 may either be a numeric uid or a username. The default is not to change
507 the owner of the file once it's created. The synonyms
511 are accepted in place of
514 .OS "File attribute options (`fattr')"
515 .IB prefix .fattr.group
519 Sets the group for newly created files. You will usually need to be a
520 member of the group in question order to set the group of a file. The
522 may either be a numeric gid or a group name. The default is not to
523 change the group of the file once it's created. The synonym
525 is accepted in place of
529 .SS "The `file' source and target types"
532 source and target allow data to move to and from objects other
533 than sockets within the Unix filesystem. (Unix-domain sockets are
540 is used as a source, it is set up immediately.
544 sources and targets is like this:
545 .GS "File sources and targets"
578 .RB [[ : ] name [ : ]]
608 specification describes two files, the first to be used as input, the
609 second to be used as output, each described by an
612 If none of the keywords
617 are given, the type of an
619 is deduced from its nature: if it matches one of the strings
623 or begins with a digit, it's considered to be a file descriptor;
624 otherwise it's interpreted as a filename.
628 spec describes a file by its name within the filesystem. It is opened
629 when needed and closed again after use. For output files, the precise
630 behaviour is controlled by options described below.
634 spec attaches the input or output of the source or target to
639 spec uses an existing open file descriptor, given either by number or a
640 symbolic name. The name
642 refers to standard input (file descriptor 0 on normal systems) and
644 refers to standard output (file descriptor 1). The names work in
645 exactly the same way as the equivalent file descriptor numbers.
649 is omitted, the input
651 is used for both input and output. Exception: if the input refers to
652 standard input then the output will refer to standard output instead.
656 options apply equally to sources and targets. The options are as
663 Whether to create the output file if it doesn't exist. If
665 (the default), an error is reported if the file doesn't exist. If
667 the file is created if it doesn't exist.
672 .BR no | truncate | append
674 Controls the behaviour if the output file already exists. If
676 an error is reported. If
678 (the default), the existing file is replaced by the new data. If
680 the new data is appended to the file.
687 source and target also accept
689 options for controlling the attributes of the created file.
692 Under no circumstances will
694 create a file through a `dangling' symbolic link.
696 .SS "The `exec' source and target types"
699 source and target execute programs and allow access to their standard
700 input and output streams. Both source and target have the same syntax,
702 .GS "Exec source and target"
742 If a single word is given, it is a
744 and will be passed to the Bourne shell for execution. If a
745 bracket-enclosed sequence of words is given, it is considered to be a
746 list of arguments to pass to the program: if a
748 is also supplied, it names the file containing the program to execute;
749 otherwise the file named by the first argument
753 Note that the shell command or program name string must, if present,
754 have any delimiter characters (including
758 quoted; this is not required in the
762 The standard input and output of the program are forwarded to the other
763 end of the connection. The standard error stream is caught by
769 source and target both understand the same set of options. The list of
770 options supported is as follows:
776 Whether to log the start and end of executed programs. If
778 (the default), a log message is emitted when the program is started
779 listing its process id, and another is emitted when the program finishes
780 giving its process id and exit status. If
782 these messages are not emitted. However the standard error stream is
785 abbreviation is accepted as a synonym for
793 Sets the current directory from which the the program should be run.
794 The default is not to change directory. The synonyms
799 are accepted in place of
807 Sets the root directory for the program, using the
809 system call. You must be the superuser for this option to work. The
810 default is not to set a root directory. The synonym
812 is accepted in place of
820 Sets the user (real and effective uid) to run the program as. This will
821 usually require superuser privileges to work. The default is not to
822 change uid. The synonym
824 is accepted in place of
832 Sets the group (real and effective gid) to run the program as. If
833 running with superuser privileges, the supplementary groups list is
834 cleared at the same time. The default is not to change gid (or clear
835 the supplementary groups list). The synonym
837 is accepted in place of
841 .BI exec.rlimit. limit \c
842 .RB [ .hard | .soft ]
846 Set resource limits for the program. The
848 may be one of the resource limit names described in
850 in lower-case and without the
858 is a number, followed optionally by
860 to multiply by 1024 (2\*(ss10\*(se),
862 to multiply by 1048576 (2\*(ss20\*(se), or
864 to multiply by 1073741824 (2\*(ss30\*(se); purists can use upper-case
865 versions of these if they want. If
869 was specified, only the hard or soft limit is set; otherwise both are
870 set to the same value. Only the superuser can raise the hard limit.
871 The soft limit cannot be set above the hard limit.
876 Clears the program's environment.
884 from the program's environment. It is not an error if no variable named
889 .BR exec.env. [ set ]
898 in the program's environment, possibly replacing the existing value.
901 may be omitted if the
903 qualifier is present.
906 Note that environment variable modifications are performed in order,
907 global modifications before local ones.
909 .SS "The `socket' source and target types"
912 source and target provide access to network services. Support is
913 currently provided for TCP/IP and Unix-domain sockets, although other
914 address types can be added with reasonable ease.
916 The syntax for socket sources and targets is:
917 .GS "Socket source and target"
929 .RB [ socket [ .\& ]]
937 .RB [ socket [ .\& ]]
944 The syntax of the source and target addresses depend on the address
945 types, which are described below. The default address type, if no
950 Socket sources support options; socket targets do not. The source
951 options provided are:
956 .BR unlimited | one-shot
958 Controls the behaviour of the source when it receives connections. A
960 limits the number of simultaneous connections. The value
964 removes any limit on the number of connections possible. The value
966 will remove the socket source after a single successful connection.
967 (Connections refused by access control systems don't count here.)
968 The default is to apply a limit of 256 concurrent connections. Use of
971 option is not recommended.
978 Sets the maximum of the kernel incoming connection queue for this socket
979 source. This is the number given to the
981 system call. The default is 5.
988 Whether to log incoming connections. If
990 (the default) incoming connections are logged, together with information
991 about the client (where available) and whether the connection was
992 accepted or refused. If
994 log messages are not generated.
997 Address types also provide their own options.
999 .SS "The `inet' socket address type"
1002 address type provides access to TCP ports. The
1004 source and target addresses have the following syntax:
1005 .GS "Socket source and target"
1032 may be given as a port number or a service name from the
1034 file (or YP map if you do that sort of thing). A
1036 may be a textual hostname or a numerical IP address.
1040 source address accepts the following options:
1041 .OS "Socket options"
1042 .B socket.inet.source.addr
1047 Specify the IP address on which to listen for incoming connections. The
1050 which means to listen on all addresses, though it may be useful to
1051 specify this explicitly, if the global setting is different.
1053 .OS "Socket options"
1054 .BR socket.inet.source. [ allow | deny ]
1060 Adds an entry to the source's access control list. If only one
1062 is given, the entry applies only to that address; if two are given, the
1063 first is a network address and the second is a netmask either in
1064 dotted-quad format or a simple number of bits (e.g.,
1068 mean the same), and the entry applies to any address which, when masked
1069 by the netmask, is equal to the masked network address.
1071 .OS "Socket options"
1072 .BR socket.inet.source. [ allow | deny ]
1075 Accept or reject connections from low-numbered `privileged' ports, in
1078 .OS "Socket options"
1079 .B socket.inet.dest.addr
1084 Specify the IP address to bind the local socket to when making an
1085 outbound connection. The default is
1087 which means to use whichever address the kernel thinks is most
1088 convenient. This option is useful if the destination is doing
1089 host-based access control and your server is multi-homed.
1091 .OS "Socket options"
1092 .B socket.inet.dest.priv-port
1096 Make a privileged connection (i.e., from a low-numbered port) to the
1097 target. This only works if
1099 was started with root privileges. However, it still works if
1103 privileges after initialization (the
1105 option). Before dropping privileges,
1107 forks off a separate process which continues to run with root
1108 privileges, and on demand passes sockets bound to privileged ports and
1109 connected to the appropriate peer back to the main program. The
1110 privileged child only passes back sockets connected to peer addresses
1111 named in the configuration; even if the
1113 process is compromised, it can't make privileged connections to other
1114 addresses. Note that because of this privilege separation, it's also
1115 not possible to reconfigure
1117 to make privileged connections to different peer addresses later by
1118 changing configuration files and sending the daemon a
1122 The access control rules are examined in the order: local entries first,
1123 then global ones, each in the order given in the configuration file.
1124 The first matching entry is used. If no entries match, the behaviour is
1127 of the last entry tried. If there are no entries defined, the default
1128 is to allow all clients.
1130 .SS "The `unix' socket address type"
1133 address type allows access to Unix-domain sockets. The syntax for
1135 source and target addresses is like this:
1136 .GS "Socket source and target"
1145 The following options are supported by the
1147 source address type:
1148 .OS "Socket options"
1149 .BR socket.unix.fattr. *
1153 source address accepts
1155 options to control the attributes of the socket file created.
1158 Sockets are removed if
1160 exits normally (which it will do if it runs out of sources or
1163 shuts down in a clean way).
1165 To forward the local port 25 to a main mail server:
1167 from 25 to mailserv:25
1169 To attach a fortune server to a Unix-domain socket:
1171 from unix:/tmp/fortunes
1172 to exec [/usr/games/fortune] { user nobody }
1174 To fetch a fortune from the server:
1176 from file stdin, stdout to unix:/tmp/fortunes
1181 from file stdin, null to file null, stdout
1183 .sp -1 \" undo final space
1185 .\"--------------------------------------------------------------------------
1186 .SH "SIGNAL HANDLING"
1190 program responds to various signals when it's running. If it receives
1197 shutdown: it removes all of its sources, and will exit when no more
1198 connections are running. (Note that if the disposition
1202 does not re-enable the signal. You'll have to send
1210 shutdown: it removes all sources and extant connections and closes down
1211 more-or-less immediately.
1213 Finally, if any configuration files (other than standard input) were
1216 on its command line using the
1220 signal may be sent to instruct
1222 to reload its configuration. Any existing connections are allowed to
1223 run their course. If no such configuration files are available,
1225 just logs a message about the signal and continues.
1227 .\"--------------------------------------------------------------------------
1228 .SH "GRAMMAR SUMMARY"
1292 .SS "File source and target"
1319 .RB [[ : ] fd [ : ]]
1321 .RB | stdin | stdout
1325 .RB [[ : ] name [ : ]]
1351 .RB [ : ] null [ : ]
1353 .SS "Exec source and target"
1393 .SS "Socket source and target"
1405 .RB [ socket [ .\& ]]
1413 .RB [ socket [ .\& ]]
1452 .\"--------------------------------------------------------------------------
1453 .SH "OPTION SUMMARY"
1455 .SS "File attributes (`fattr')"
1456 .IB prefix .fattr.mode
1460 .IB prefix .fattr.owner
1464 .IB prefix .fattr.group
1475 .BR no | truncate | append
1500 .BI exec.rlimit. limit \c
1501 .RB [ .hard | .soft ]
1510 .BR exec.env. [ set ]
1515 .SS "Socket options"
1519 .BR unlimited | one-shot
1529 .BR socket.inet.source. [ allow | deny ]
1535 .BR socket.inet.source. [ allow | deny ]
1538 .B socket.inet.source.addr
1543 .B socket.inet.dest.addr
1548 .B socket.inet.dest.priv-port
1552 .BR socket.unix.fattr. *
1554 .\"--------------------------------------------------------------------------
1557 The syntax for IP addresses and filenames is nasty.
1559 IPv6 is not supported yet. Because of
1561 socket address architecture, it's probably not a major piece of work to
1564 Please inform me of any security problems you think you've identified in
1565 this program. I take security very seriously, and I will fix security
1566 holes as a matter of priority when I find out about them. I will be
1567 annoyed if I have to read about problems on Bugtraq because they weren't
1570 The program is too complicated, and this manual page is too long.
1572 .\"--------------------------------------------------------------------------
1575 Mark Wooding, <mdw@nsict.org>
1577 .\"----- That's all, folks --------------------------------------------------