3 .\" $Id: fw.1,v 1.2 1999/07/26 23:31:04 mdw Exp $
7 .\" (c) 1999 Straylight/Edgeware
10 .\"----- Licensing notice ---------------------------------------------------
12 .\" This file is part of the `fw' port forwarder.
14 .\" `fw' is free software; you can redistribute it and/or modify
15 .\" it under the terms of the GNU General Public License as published by
16 .\" the Free Software Foundation; either version 2 of the License, or
17 .\" (at your option) any later version.
19 .\" `fw' is distributed in the hope that it will be useful,
20 .\" but WITHOUT ANY WARRANTY; without even the implied warranty of
21 .\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 .\" GNU General Public License for more details.
24 .\" You should have received a copy of the GNU General Public License
25 .\" along with `fw'; if not, write to the Free Software Foundation,
26 .\" Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
28 .\" ---- Revision history ---------------------------------------------------
31 .\" Revision 1.2 1999/07/26 23:31:04 mdw
32 .\" Document lots of new features and syntax.
35 .\"----- Various bits of fancy styling --------------------------------------
37 .\" --- Indented paragraphs with right-aligned tags ---
41 \h'-\w'\fB\\$1\ \fP'u'\fB\\$1\ \fP\c
44 .\" --- Verbatim-oid typesetting ---
58 .\" --- Other bits of styling ---
74 .\"--------------------------------------------------------------------------
76 .TH fw 1 "1 July 1999" fw
78 .\"--------------------------------------------------------------------------
83 .\"--------------------------------------------------------------------------
92 .\"--------------------------------------------------------------------------
97 program is a simple port forwarder. It supports a number of features
98 the author hasn't found in similar programs:
100 .I "Connection logging"
101 Each connection attempt to the forwarder is logged, giving the time of
102 the connection, the DNS-resolved hostname (if available), and the user
103 name resulting from an RFC931 lookup. These lookups are done
104 asynchronously to the main forwarder's operation.
107 Each forwarded port may have an access control list attached to it.
108 Only authorized hosts are allowed to connect. Access control checks are
109 performed by quick checks on the client's IP address.
111 .I "Nonblocking single-process design"
112 The internal structure of the server is completely nonblocking. The
113 connections don't block; the reading and writing don't block; the name
114 lookups don't block. This is all done in a single process, with the
115 single exception of the DNS resolver.
117 .I "Support for Unix-domain sockets"
118 Connections from and to Unix-domain sockets can be handled just as
119 easily as more normal Internet sckets. Access control doesn't work on
120 Unix domain sockets, though. (Yet.)
121 .SS "Command line options"
124 program understands a few simple command line options:
127 Displays a screen of help text on standard output and exits
130 .B "\-v, \-\-version"
131 Writes the version number to standard output and exits successfully.
134 Writes a terse usage summary to standard output and exits successfully.
136 .BI "\-f, \-\-file=" file
137 Read configuration information from
142 configuration file statement.
144 .B "\-d, \-\-daemon, \-\-fork"
145 Forks into the background after reading the configuration and
146 initializing properly.
149 Don't output any logging information. This option is not recommended
150 for normal use, although it can make system call traces clearer so I use
153 Any further command line arguments are interpreted as configuration
154 lines to be read. Configuration supplied in command line arguments has
155 precisely the same syntax as configuration in files. If there are no
156 configurmation statements on the command line, and no
158 options were supplied, configuration is read from standard input, if
159 stdin is not a terminal.
161 .\"--------------------------------------------------------------------------
162 .SH "CONFIGURATION LANGUAGE"
166 program has a fairly sophisticated configuration language to let you
167 describe which things should be forwarded where and what special
168 features there should be.
169 .SS "Lexical structure"
170 There are four types of characters.
172 .I "word constituent characters"
173 Word consistituent characters are gathered together into words.
174 Depending on its surrounding context, a word might act as a keyword or a
175 string. All alphanumerics are word constituents, as is the hyphen
177 Other characters may change their status in future versions.
179 .I "self-delimiting characters"
180 Self-delimiting characters always stand alone. They act as punctuation,
181 shaping the sequence of words into more complex grammatical forms. The
194 are self-delimiting. Note that while some characters, e.g.,
198 require escaping by the shell, they are strictly optional in the grammar
199 and can be omitted in quick hacks at the shell prompt.
201 .I "whitespace characters"
202 Whitespace characters separate words but are otherwise ignored. All
203 `normal' whitespace characters (e.g., space, tab and newline) are
204 considered to be whitespace for these purposes.
206 .I "special characters"
207 There are three special characters. The
209 character, if it appears at the start of a word, introduces a
211 which extends to the end of the current line or command-line argument.
212 Within a word, it behaves like a normal word-constituent character. The
215 escapes the following character causing it to be interpreted as a word
216 constituent regardless of its normal type. The double-quote
218 escapes all characters other than backslashes up to the next
219 double-quote and causes them to be regarded as word constituents. Note
220 that you don't have to quote a whole word. The backslash can escape a
221 quote character allowing you to insert it into a word if really
225 The overall syntax looks a bit like this:
264 If you prefer, the keyword
272 .SS "Sources and targets"
273 Forwarding is set up by attaching
277 Sources are things which are capable of
279 one end of a data flow on their own, while targets are things which are
280 capable of setting up the other end on demand. In the case of a TCP
281 port forwarder, the part which listens for incoming client connections
282 is the source, while the part which sets up outgoing connections to the
283 destination server is the target.
287 does is set up a collection of sources and targets based on your
288 configuration file so that when a source decides to initiate a data
289 flow, it tells its target to set its end up, and then squirts data back
290 and forth between the two until there's no more.
294 they stay around indefinitely setting up multiple attachments to
297 they set up one connection and then disappear. If all the sources
298 defined are transient, then
300 will quit when no more active sources remain and all connections have
305 program is fairly versatile. It allows you to attach any supported type
306 of source to any supported type of target. This will, I hope, be the
307 case in all future versions.
313 depend on the source or target type, and are therefore described in the
314 sections specific to the various types.
316 .SS "Options structure"
317 Most of the objects that
319 knows about (including sources and targets, but also other more specific
320 things such as socket address types) can have their behaviour modified
323 The options available at a particular point in the configuration depend
326 A global option, outside of a
328 has no context unless it is explicitly qualified, and affects global
329 behaviour. Local options, applied to a source or target in a
331 has the context of the type of source or target to which it is applied,
332 and affects only that source or target.
334 Note that it's important to distinguish between an option's context
335 (which is affected by its qualification) and its local or global
336 status. No matter how qualified, a global option will always control
337 default options for objects, and a local option will only affect a
338 specific source or target.
340 The syntax for qualifying options is like this:
365 Thus, you may qualify either an individual option or a sequence of
366 options. The two are equivalent; for example,
375 exec.rlimit.core = 0;
378 For each option, there is a sequence of prefixes which maximally qualify
379 that option. An option prefixed with this sequence is
380 .IR "fully qualified" .
381 In actual use, some or all of those prefixes may be omitted. However,
382 it's possible for the option to become
384 if you do this. For example, the option
389 .BR socket.unix.fattr.owner .
390 In this case, the ambiguity is benign: a local option will have as its
391 context an appropriate source or target, and both global options
392 actually control the same default. However, the option
398 which have separate defaults, and which one you actually get depends on
399 the exact implementation of
401 option parser. (Currently this would resolve to
403 although this may change in a later version.)
405 In this manual, options are usually shown in their fully-qualified form.
407 .SS "The `file' source and target types"
410 source and target allow data to move to and from objects other
411 than sockets within the Unix filesystem. (Unix-domain sockets are
418 is used as a source, it is set up immediately.
422 sources and targets is like this:
456 .RB [[ : ] file [ : ]]
482 .RB [[ : ] null [ : ]]
486 specification describes two files, the first to be used as input, the
487 second to be used as output, each described by an
490 If none of the keywords
495 are given, the type of an
497 is deduced from its nature: if it matches one of the strings
501 or begins with a digit, it's considered to be a file descriptor;
502 otherwise it's interpreted as a filename.
506 spec describes a file by its name within the filesystem. It is opened
507 when needed and closed again after use. For output files, the precise
508 behaviour is controlled by options described below.
512 spec attaches the input or output of the source or target to
517 spec uses an existing open file descriptor, given either by number or a
518 symbolic name. The name
520 refers to standard input (file descriptor 0 on normal systems) and
522 refers to standard output (file descriptor 1). The names work in
523 exactly the same way as the equivalent file descriptor numbers.
527 is omitted, the input
529 is used for both input and output. Exception: if the input refers to
530 standard input then the output will refer to standard output instead.
534 options apply equally to sources and targets. The options are as
541 Whether to create the output file if it doesn't exist. If
543 (the default), an error is reported if the file doesn't exist. If
545 the file is created if it doesn't exist.
550 .BR no | truncate | append
552 Controls the behaviour if the output file already exists. If
554 an error is reported. If
556 (the default), the existing file is replaced by the new data. If
558 the new data is appended to the file.
561 Under no circumstances will
563 create a file through a `dangling' symbolic link.
567 source and target also accept
569 options for controlling the attributes of the created file. The prefix
570 for setting file attributes is
573 .SS "File attributes for created files `fattr'"
578 sources and targets can create new filesystem objects. The
580 options allow control over the attributes of the newly-created objects.
585 use the same set of defaults, so a prefix of
587 is good enough for setting global options, and the implicit context
588 disambiguates local options.
590 The following file attribute options are supported:
592 .IB prefix .fattr.mode
596 Sets the permissions mode for a new file. The
598 argument may be either an octal number or a
600 string which acts on the default permissions established by the
609 characters that will need to be escaped or quoted.
612 .IB prefix .fattr.owner
616 Sets the owner for newly created files. On non-broken systems you will
617 need to be the superuser to set the owner on a file. The
619 may either be a numeric uid or a username. The default is not to change
620 the owner of the file once it's created. The synonyms
624 are accepted in place of
628 .IB prefix .fattr.group
632 Sets the group for newly created files. You will usually need to be a
633 member of the group in question order to set the group of a file. The
635 may either be a numeric gid or a group name. The default is not to
636 change the group of the file once it's created. The synonym
638 is accepted in place of
642 .SS "The `exec' source and target types"
645 source and target execute programs and allow access to their standard
646 input and output streams. Both source and target have the same syntax,
688 If a single word is given, it is a
690 and will be passed to the Bourne shell for execution. If a
691 bracket-enclosed sequence of words is given, it is considered to be a
692 list of arguments to pass to the program: if a
694 is also supplied, it names the file containing the program to execute;
695 otherwise the file named by the first argument
699 The standard input and output of the program are forwarded to the other
700 end of the connection. The standard error stream is caught by
706 source and target both understand the same set of options. The list of
707 options supported is as follows:
713 Whether to log the start and end of executed programs. If
715 (the default), a log message is emitted when the program is started
716 listing its process id, and another is emitted when the program finishes
717 giving its process id and exit status. If
719 these messages are not emitted. However the standard error stream is
722 abbreviation is accepted as a synonym for
730 Sets the current directory from which the the program should be run.
731 The default is not to change directory. The synonyms
736 are accepted in place of
744 Sets the root directory for the program, using the
746 system call. You must be the superuser for this option to work. The
747 default is not to set a root directory. The synonyms
752 are accepted in place of
760 Sets the user (real and effective uid) to run the program as. This will
761 usually require superuser privileges to work. The default is not to
762 change uid. The synonym
764 is accepted in place of
772 Sets the group (real and effective gid) to run the program as. If
773 running with superuser privileges, the supplementary groups list is
774 cleared at the same time. The default is not to change gid (or clear
775 the supplementary groups list). The synonym
777 is accepted in place of
781 .BI exec.rlimit. limit \c
782 .RB [ .hard | .soft ]
786 Set resource limits for the program. The
788 may be one of the resource limit names described in
790 in lower-case and without the
798 is a number, followed optionally by
800 to multiply by 1024 (2\*(ss10\*(se),
802 to multiply by 1048576 (2\*(ss20\*(se), or
804 to multiply by 1073741824 (2\*(ss30\*(se); purists can use upper-case
805 versions of these if they want. If
809 was specified, only the hard or soft limit is set; otherwise both are
810 set to the same value. Only the superuser can raise the hard limit.
811 The soft limit cannot be set above the hard limit.
816 Clears the program's environment.
824 from the program's environment. It is not an error if no variable named
829 .BR exec.env. [ set ]
834 Assignes the variable
838 in the program's environment, possibly replacing the existing value.
841 may be omitted if the
843 qualifier is present.
846 Note that environment variable modifications are performed in order,
847 global modifications before local ones.
849 .SS "The `socket' source and target types"
852 source and target provide access to network services. Support is
853 currently provided for TCP/IP and Unix-domain sockets, although other
854 address types can be added with reasonable ease.
856 The syntax for socket sources and targets is:
884 The syntax of the source and target addresses depend on the address
885 types, which are described below. The default address type, if no
890 Socket sources support options; socket targets do not. The source
891 options provided are:
897 Limits the number of simultaneous connections to this socket to the
899 given. The default is 256.
906 Whether to log incoming connections. If
908 (the default) incoming connections are logged, together with information
909 about the client (where available) and whether the connection was
910 accepted or refused. If
912 log messages are not generated.
915 Address types also provide their own options.
917 .SS "The `inet' socket address type"
920 address type provides access to TCP ports. The
922 source and target addresses have the following syntax:
950 may be given as a port number or a service name from the
952 file (or YP map if you do that sort of thing). A
954 may be a textual hostname or a numerical IP address.
958 source address accepts the following options:
960 .BR socket.inet. [ allow | deny ]
966 Adds an entry to the source's access control list. If only one
968 is given, the entry applies only to that address; if two are given, the
969 first is a network address and the second is a netmask either in
970 dotted-quad format or a simple number of bits (e.g.,
974 mean the same), and the entry applies to any address which, when masked
975 by the netmask, is equal to the masked network address.
978 control rules are examined in the order: local entries first, then
979 global ones, each in the order given in the configuration file. The
980 first matching entry is used. If no entries match, the behaviour is the
982 of the last entry tried. If there are no entries defined, the default
983 is to allow all clients.
986 .SS "The `unix' socket address type"
989 address type allows access to Unix-domain sockets. The syntax for
991 source and target addresses is like this:
1007 source address accepts
1009 options to control the attributes of the socket file created. Sockets
1012 exits normally (which it will do if it runs out of sources or
1013 connections, or if killed by SIGINT or SIGTERM).
1015 To forward the local port 25 to a main mail server:
1017 from 25 to mailserv:25
1019 To attach a fortune server to a Unix-domain socket:
1021 from unix:/tmp/fortunes
1022 to exec [/usr/games/fortune] { user nobody }
1024 To fetch a fortune from the server:
1026 from file stdin, stdout to unix:/tmp/fortunes
1031 from stdin, null to null, stdout
1034 .\"--------------------------------------------------------------------------
1037 The syntax for IP addresses and filenames is nasty. The requirement
1038 that textual permissions strings be quoted is probably nastier.
1040 IPv6 is not supported yet. It's probably not a major piece of work to
1043 Please inform me of any security problems you think you've identified in
1044 this program. I take security very seriously, and I will fix security
1045 holes as a matter of priority when I find out about them. I will be
1046 annoyed if I have to read about problems on Bugtraq because they weren't
1049 .\"--------------------------------------------------------------------------
1052 Mark Wooding, <mdw@nsict.org>
1054 .\"----- That's all, folks --------------------------------------------------