Update docco for new options.
[fwd] / fw.1
1 .\" -*-nroff-*-
2 .\"
3 .\" $Id: fw.1,v 1.16 2003/11/25 14:46:50 mdw Exp $
4 .\"
5 .\" Manual page for fw
6 .\"
7 .\" (c) 1999 Straylight/Edgeware
8 .\"
9 .
10 .\"----- Licensing notice ---------------------------------------------------
11 .\"
12 .\" This file is part of the `fw' port forwarder.
13 .\"
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.
18 .\"
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.
23 .\"
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.
27 .
28 .\" ---- Revision history ---------------------------------------------------
29 .\"
30 .\" $Log: fw.1,v $
31 .\" Revision 1.16 2003/11/25 14:46:50 mdw
32 .\" Update docco for new options.
33 .\"
34 .\" Revision 1.15 2003/01/24 20:13:04 mdw
35 .\" Fix bogus examples. Explain quoting rules for `exec' endpoints.
36 .\"
37 .\" Revision 1.14 2002/02/23 00:05:12 mdw
38 .\" Fix spacing around full stops (at last!).
39 .\"
40 .\" Revision 1.13 2002/02/22 23:45:01 mdw
41 .\" Add option to change the listen(2) parameter.
42 .\"
43 .\" Revision 1.12 2001/02/23 09:11:29 mdw
44 .\" Update manual style.
45 .\"
46 .\" Revision 1.11 2001/02/05 19:47:11 mdw
47 .\" Minor fixings to wording.
48 .\"
49 .\" Revision 1.10 2001/02/03 20:30:03 mdw
50 .\" Support re-reading config files on SIGHUP.
51 .\"
52 .\" Revision 1.9 2000/03/23 00:37:33 mdw
53 .\" Add option to change user and group after initialization. Naughtily
54 .\" reassign short equivalents of --grammar and --options.
55 .\"
56 .\" Revision 1.8 1999/12/22 15:44:43 mdw
57 .\" Fix some errors, and document new option.
58 .\"
59 .\" Revision 1.7 1999/10/22 22:45:15 mdw
60 .\" Describe new socket connection options.
61 .\"
62 .\" Revision 1.6 1999/10/10 16:46:29 mdw
63 .\" Include grammar and options references at the end of the manual.
64 .\"
65 .\" Revision 1.5 1999/09/26 18:18:05 mdw
66 .\" Remove a fixed bug from the list. Fix some nasty formatting
67 .\" misfeatures.
68 .\"
69 .\" Revision 1.4 1999/08/19 18:32:48 mdw
70 .\" Improve lexical analysis. In particular, `chmod' patterns don't have to
71 .\" be quoted any more.
72 .\"
73 .\" Revision 1.3 1999/07/30 06:49:00 mdw
74 .\" Minor tidying and typo correction.
75 .\"
76 .\" Revision 1.2 1999/07/26 23:31:04 mdw
77 .\" Document lots of new features and syntax.
78 .\"
79 .
80 .\"----- Various bits of fancy styling --------------------------------------
81 .
82 .\" --- Indented paragraphs with right-aligned tags ---
83 .
84 .de hP
85 .IP
86 \h'-\w'\fB\\$1\ \fP'u'\fB\\$1\ \fP\c
87 ..
88 .
89 .\" --- Verbatim-oid typesetting ---
90 .de VS
91 .sp 1
92 .RS
93 .nf
94 .ft B
95 ..
96 .de VE
97 .ft R
98 .fi
99 .RE
100 .sp 1
101 ..
102 .
103 .\" --- Grammar markup ---
104 .\"
105 .\" This is mainly for the benefit of the automatic scripts which
106 .\" generate the grammar summary.
107 .
108 .de GS
109 .PP
110 ..
111 .de GE
112 .PP
113 ..
114 .
115 .de OS
116 .PP
117 ..
118 .de OD
119 .RS
120 ..
121 .de OE
122 .RE
123 ..
124 .
125 .\" --- Other bits of styling ---
126 .
127 .ie t \{\
128 . ds o \(bu
129 . ds ss \s8\u
130 . ds se \d\s0
131 . if \n(.g \{\
132 . fam P
133 . \}
134 .\}
135 .el \{\
136 . ds o o
137 . ds ss ^
138 . ds se
139 .\}
140 .
141 .\"--------------------------------------------------------------------------
142 .
143 .TH fw 1 "1 July 1999" "Straylight/Edgeware" "fw port forwarder"
144 .
145 .\"--------------------------------------------------------------------------
146 .SH NAME
147 .
148 fw \- port forwarder
149 .
150 .\"--------------------------------------------------------------------------
151 .SH SYNOPSIS
152 .
153 .B fw
154 .RB [ \-dlq ]
155 .RB [ \-f
156 .IR file ]
157 .RB [ \-s
158 .IR user ]
159 .RB [ \-g
160 .IR group ]
161 .IR config-stmt ...
162 .
163 .\"--------------------------------------------------------------------------
164 .SH "DESCRIPTION"
165 .
166 The
167 .B fw
168 program is a simple port forwarder. It supports a number of features
169 the author hasn't found in similar programs:
170 .TP
171 .I "Connection logging"
172 Each connection attempt to the forwarder is logged, giving the time of
173 the connection, the DNS-resolved hostname (if available), and the user
174 name resulting from an RFC931 lookup. These lookups are done
175 asynchronously to the main forwarder's operation.
176 .TP
177 .I "Access control"
178 Each forwarded port may have an access control list attached to it.
179 Only authorized hosts are allowed to connect. Access control checks are
180 performed by quick checks on the client's IP address.
181 .TP
182 .I "Nonblocking single-process design"
183 The internal structure of the server is completely nonblocking. The
184 connections don't block; the reading and writing don't block; the name
185 lookups don't block. This is all done in a single process, with the
186 single exception of the DNS resolver.
187 .TP
188 .I "Support for Unix-domain sockets"
189 Connections from and to Unix-domain sockets can be handled just as
190 easily as more normal Internet sockets. Access control doesn't work on
191 Unix domain sockets, though. (Yet.)
192 .SS "Command line options"
193 The
194 .B fw
195 program understands a few simple command line options:
196 .TP
197 .B "\-h, \-\-help"
198 Displays a screen of help text on standard output and exits
199 successfully.
200 .TP
201 .B "\-v, \-\-version"
202 Writes the version number to standard output and exits successfully.
203 .TP
204 .B "\-u, \-\-usage"
205 Writes a terse usage summary to standard output and exits successfully.
206 .TP
207 .B "\-G, \-\-grammar"
208 Writes a summary of the configuration file grammar to standard output
209 and exits successfully.
210 .TP
211 .B "\-O, \-\-options"
212 Writes a summary of the source and target options to standard output and
213 exits successfully.
214 .TP
215 .BI "\-f, \-\-file=" file
216 Read configuration information from
217 .IR file .
218 Equivalent to an
219 .RB ` include
220 .IR file '
221 configuration file statement.
222 .TP
223 .B "\-d, \-\-daemon, \-\-fork"
224 Forks into the background after reading the configuration and
225 initializing properly.
226 .TP
227 .B "\-l, \-\-syslog, \-\-log"
228 Emit logging information to the system log, rather than standard error.
229 .TP
230 .B "\-q, \-\-quiet"
231 Don't output any logging information. This option is not recommended
232 for normal use, although it can make system call traces clearer so I use
233 it when debugging.
234 .TP
235 .BI "\-s, \-\-setuid=" user
236 Change uid to that of
237 .IR user ,
238 which may be either a user name or uid number, after initializing all
239 the sources. This will usually require elevated privileges.
240 .TP
241 .BI "\-g, \-\-setgid=" group
242 Change gid to that of
243 .IR group ,
244 which may be either a group name or gid number, after initializing all
245 the sources. If the operating system understands supplementary groups
246 then the supplementary groups list is altered to include only
247 .IR group .
248 .PP
249 Any further command line arguments are interpreted as configuration
250 lines to be read. Configuration supplied in command line arguments has
251 precisely the same syntax as configuration in files. If there are no
252 configuration statements on the command line, and no
253 .B \-f
254 options were supplied, configuration is read from standard input, if
255 stdin is not a terminal.
256 .
257 .\"--------------------------------------------------------------------------
258 .SH "CONFIGURATION LANGUAGE"
259 .
260 The
261 .B fw
262 program has a fairly sophisticated configuration language to let you
263 describe which things should be forwarded where and what special
264 features there should be.
265 .SS "Lexical structure"
266 There are four types of characters.
267 .TP
268 .I "word constituent characters"
269 Word constituent characters are gathered together into words.
270 Depending on its surrounding context, a word might act as a keyword or a
271 string. All alphanumerics are word constituents, as is the hyphen
272 .RB ` \- '.
273 Other characters may change their status in future versions.
274 .TP
275 .I "self-delimiting characters"
276 Self-delimiting characters always stand alone. They act as punctuation,
277 shaping the sequence of words into more complex grammatical forms. The
278 characters
279 .RB ` { ',
280 .RB ` } ',
281 .RB ` [ ',
282 .RB ` ] ',
283 .RB ` / ',
284 .RB ` , ',
285 .RB ` = ',
286 .RB ` : ',
287 .RB ` ; '
288 and
289 .RB ` . '
290 are self-delimiting. Note that while some characters, e.g.,
291 .RB ` [ '
292 and
293 .RB ` ; ',
294 require escaping by the shell, they are mostly optional in the grammar
295 and can tend to be omitted in quick hacks at the shell prompt.
296 .TP
297 .I "whitespace characters"
298 Whitespace characters separate words but are otherwise ignored. All
299 `normal' whitespace characters (e.g., space, tab and newline) are
300 considered to be whitespace for these purposes.
301 .TP
302 .I "special characters"
303 There are three special characters. The
304 .RB ` # '
305 character, if it appears at the start of a word, introduces a
306 .I comment
307 which extends to the end of the current line or command-line argument.
308 Within a word, it behaves like a normal word-constituent character. The
309 backslash
310 .RB ` \e '
311 escapes the following character causing it to be interpreted as a word
312 constituent regardless of its normal type. The double-quote
313 .RB ` """" '
314 escapes all characters other than backslashes up to the next
315 double-quote and causes them to be regarded as word constituents. Note
316 that you don't have to quote a whole word. The backslash can escape a
317 quote character allowing you to insert it into a word if really
318 necessary.
319 .
320 .SS "Basic syntax"
321 The overall syntax looks a bit like this:
322 .GS "Basic syntax"
323 .I file
324 ::=
325 .I empty
326 |
327 .I file
328 .I stmt
329 .RB [ ; ]
330 .br
331 .I stmt
332 ::=
333 .I option-stmt
334 |
335 .I fw-stmt
336 .br
337 .I fw-stmt
338 ::=
339 .B fw
340 .I source
341 .I options
342 .RB [ to | \-> ]
343 .I target
344 .I options
345 .br
346 .I options
347 ::=
348 .B {
349 .I option-seq
350 .B }
351 .br
352 .I option-seq
353 ::=
354 .I empty
355 |
356 .I option-stmt
357 .RB [ ; ]
358 .I option-seq
359 .GE
360 If you prefer, the keyword
361 .RB ` fw '
362 may be spelt
363 .RB ` forward '
364 or
365 .RB ` from '.
366 All are equivalent.
367 .
368 .SS "Sources and targets"
369 Forwarding is set up by attaching
370 .I targets
371 to
372 .IR sources .
373 Sources are things which are capable of
374 .I initiating
375 one end of a data flow on their own, while targets are things which are
376 capable of setting up the other end on demand. In the case of a TCP
377 port forwarder, the part which listens for incoming client connections
378 is the source, while the part which sets up outgoing connections to the
379 destination server is the target.
380 .PP
381 Essentially, all
382 .B fw
383 does is set up a collection of sources and targets based on your
384 configuration file so that when a source decides to initiate a data
385 flow, it tells its target to set its end up, and then squirts data back
386 and forth between the two until there's no more.
387 .PP
388 Some sources are
389 .IR persistent :
390 they stay around indefinitely setting up multiple attachments to
391 targets. Others are
392 .IR transient :
393 they set up one connection and then disappear. If all the sources
394 defined are transient, then
395 .B fw
396 will quit when no more active sources remain and all connections have
397 terminated.
398 .PP
399 The
400 .B fw
401 program is fairly versatile. It allows you to attach any supported type
402 of source to any supported type of target. This will, I hope, be the
403 case in all future versions.
404 .PP
405 The syntax of a
406 .I source
407 or
408 .I target
409 depend on the source or target type, and are therefore described in the
410 sections specific to the various types.
411 .
412 .SS "Options structure"
413 Most of the objects that
414 .B fw
415 knows about (including sources and targets, but also other more specific
416 things such as socket address types) can have their behaviour modified
417 by
418 .IR options .
419 The options available at a particular point in the configuration depend
420 on the
421 .IR context .
422 A global option, outside of a
423 .I fw-stmt
424 has no context unless it is explicitly qualified, and affects global
425 behaviour. A local option, applied to a source or target in a
426 .IR fw-stmt ,
427 has the context of the type of source or target to which it is applied,
428 and affects only that source or target.
429 .PP
430 Note that it's important to distinguish between an option's context
431 (which is affected by its qualification) and its local or global
432 status. No matter how qualified, a global option will always control
433 default options for objects, and a local option will only affect a
434 specific source or target.
435 .PP
436 The syntax for qualifying options is like this:
437 .GS "Option syntax"
438 .I option-stmt
439 ::=
440 .I q-option
441 .br
442 .I q-option
443 ::=
444 .I option
445 .br
446 |
447 .I prefix
448 .B .\&
449 .I q-option
450 .br
451 |
452 .I prefix
453 .B {
454 .I option-seq
455 .B }
456 .br
457 .I prefix
458 ::=
459 .I word
460 .GE
461 Thus, you may qualify either an individual option or a sequence of
462 options. The two are equivalent; for example,
463 .VS
464 exec.rlimit {
465 core = 0;
466 cpu = 60;
467 }
468 .VE
469 means the same as
470 .VS
471 exec.rlimit.core = 0;
472 exec.rlimit.cpu = 0;
473 .VE
474 For each option, there is a sequence of prefixes which maximally qualify
475 that option. An option prefixed with this sequence is
476 .IR "fully qualified" .
477 In actual use, some or all of those prefixes may be omitted. However,
478 it's possible for the option to become
479 .I ambiguous
480 if you do this. For example, the option
481 .B fattr.owner
482 may refer either to
483 .B file.fattr.owner
484 or to
485 .BR socket.unix.fattr.owner .
486 In this case, the ambiguity is benign: a local option will have as its
487 context an appropriate source or target, and both global options
488 actually control the same default. However, the option
489 .B logging
490 may mean either
491 .B socket.logging
492 or
493 .BR exec.logging ,
494 which have separate defaults, and which one you actually get depends on
495 the exact implementation of
496 .BR fw 's
497 option parser. (Currently this would resolve to
498 .BR exec.logging ,
499 although this may change in a later version.)
500 .PP
501 In this manual, options are usually shown in their fully-qualified form.
502 .
503 .SS "File attributes for created files: `fattr'"
504 Both the
505 .B file
506 and
507 .B socket
508 sources and targets can create new filesystem objects. The
509 .B fattr
510 options allow control over the attributes of the newly-created objects.
511 Both
512 .B file
513 and
514 .B socket
515 use the same set of defaults, so a prefix of
516 .B fattr
517 is good enough for setting global options, and the implicit context
518 disambiguates local options.
519 .PP
520 The following file attribute options are supported:
521 .OS "File attribute options (`fattr')"
522 .IB prefix .fattr.mode
523 .RB [ = ]
524 .I mode
525 .OD
526 Sets the permissions mode for a new file. The
527 .I mode
528 argument may be either an octal number or a
529 .BR chmod (1)-style
530 string which acts on the default permissions established by the
531 prevailing
532 .BR umask (2)
533 setting. The characters
534 .RB ` = '
535 and
536 .RB ` , '
537 do not have to be quoted within the mode string.
538 .OE
539 .OS "File attribute options (`fattr')"
540 .IB prefix .fattr.owner
541 .RB [ = ]
542 .I user
543 .OD
544 Sets the owner for newly created files. On non-broken systems you will
545 need to be the superuser to set the owner on a file. The
546 .I user
547 may either be a numeric uid or a username. The default is not to change
548 the owner of the file once it's created. The synonyms
549 .B uid
550 and
551 .B user
552 are accepted in place of
553 .BR owner .
554 .OE
555 .OS "File attribute options (`fattr')"
556 .IB prefix .fattr.group
557 .RB [ = ]
558 .I group
559 .OD
560 Sets the group for newly created files. You will usually need to be a
561 member of the group in question order to set the group of a file. The
562 .I group
563 may either be a numeric gid or a group name. The default is not to
564 change the group of the file once it's created. The synonym
565 .B gid
566 is accepted in place of
567 .BR group .
568 .OE
569 .
570 .SS "The `file' source and target types"
571 The
572 .B file
573 source and target allow data to move to and from objects other
574 than sockets within the Unix filesystem. (Unix-domain sockets are
575 handled using the
576 .B socket
577 source and target.)
578 .PP
579 If a
580 .B file
581 is used as a source, it is set up immediately.
582 .PP
583 The syntax of
584 .B file
585 sources and targets is like this:
586 .GS "File sources and targets"
587 .I source
588 ::=
589 .I file
590 .br
591 .I target
592 ::=
593 .I file
594 .br
595 .I file
596 ::=
597 .B file
598 .RB [ .\& ]
599 .I fspec
600 .RB [ ,
601 .IR fspec ]
602 .br
603 .I fspec
604 ::=
605 .I fd-spec
606 |
607 .I name-spec
608 |
609 .I null-spec
610 .br
611 .I fd-spec
612 ::=
613 .RB [[ : ] fd [ : ]]
614 .IR number \c
615 .RB | stdin | stdout
616 .br
617 .I name-spec
618 ::=
619 .RB [[ : ] file [ : ]]
620 .I file-name
621 .br
622 .I file-name
623 ::=
624 .I path-seq
625 |
626 .B [
627 .I path-seq
628 .B ]
629 .br
630 .I path-seq
631 ::=
632 .I path-elt
633 |
634 .I path-seq
635 .I path-elt
636 .br
637 .I path-elt
638 ::=
639 .B /
640 |
641 .I word
642 .br
643 .I null-spec
644 ::=
645 .RB [ : ] null [ : ]
646 .GE
647 The
648 .I file
649 specification describes two files, the first to be used as input, the
650 second to be used as output, each described by an
651 .IR fspec .
652 .PP
653 If none of the keywords
654 .RB ` fd ',
655 .RB ` name '
656 or
657 .RB ` null '
658 are given, the type of an
659 .I fspec
660 is deduced from its nature: if it matches one of the strings
661 .RB ` stdin '
662 or
663 .RB ` stdout ',
664 or begins with a digit, it's considered to be a file descriptor;
665 otherwise it's interpreted as a filename.
666 .PP
667 A
668 .RB ` name '
669 spec describes a file by its name within the filesystem. It is opened
670 when needed and closed again after use. For output files, the precise
671 behaviour is controlled by options described below.
672 .PP
673 A
674 .RB ` null '
675 spec attaches the input or output of the source or target to
676 .BR /dev/null .
677 .PP
678 An
679 .RB ` fd '
680 spec uses an existing open file descriptor, given either by number or a
681 symbolic name. The name
682 .RB ` stdin '
683 refers to standard input (file descriptor 0 on normal systems) and
684 .RB ` stdout '
685 refers to standard output (file descriptor 1). The names work in
686 exactly the same way as the equivalent file descriptor numbers.
687 .PP
688 If the output
689 .I fspec
690 is omitted, the input
691 .I fspec
692 is used for both input and output. Exception: if the input refers to
693 standard input then the output will refer to standard output instead.
694 .PP
695 All
696 .B file
697 options apply equally to sources and targets. The options are as
698 follows:
699 .OS "File options"
700 .B file.create
701 .RB [ = ]
702 .BR yes | no
703 .OD
704 Whether to create the output file if it doesn't exist. If
705 .B no
706 (the default), an error is reported if the file doesn't exist. If
707 .BR yes ,
708 the file is created if it doesn't exist.
709 .OE
710 .OS "File options"
711 .B file.open
712 .RB [ = ]
713 .BR no | truncate | append
714 .OD
715 Controls the behaviour if the output file already exists. If
716 .BR no ,
717 an error is reported. If
718 .B truncate
719 (the default), the existing file is replaced by the new data. If
720 .BR append ,
721 the new data is appended to the file.
722 .OE
723 .OS "File options"
724 .BR file.fattr.*
725 .OD
726 The
727 .B file
728 source and target also accept
729 .B fattr
730 options for controlling the attributes of the created file.
731 .OE
732 .PP
733 Under no circumstances will
734 .B fw
735 create a file through a `dangling' symbolic link.
736 .
737 .SS "The `exec' source and target types"
738 The
739 .B exec
740 source and target execute programs and allow access to their standard
741 input and output streams. Both source and target have the same syntax,
742 which is as follows:
743 .GS "Exec source and target"
744 .I source
745 ::=
746 .I exec
747 .br
748 .I target
749 ::=
750 exec
751 .br
752 .I exec
753 ::=
754 .BR exec
755 .RB [ .\& ]
756 .I cmd-spec
757 .br
758 .I cmd-spec
759 ::=
760 .I shell-cmd
761 |
762 .RI [ prog-name ]
763 .B [
764 .I argv0
765 .I arg-seq
766 .B ]
767 .br
768 .I arg-seq
769 ::=
770 .I word
771 |
772 .I arg-seq
773 .I word
774 .br
775 .I shell-cmd
776 ::=
777 .I word
778 .br
779 .I argv0
780 ::=
781 .I word
782 .GE
783 If a single word is given, it is a
784 .I shell-cmd
785 and will be passed to the Bourne shell for execution. If a
786 bracket-enclosed sequence of words is given, it is considered to be a
787 list of arguments to pass to the program: if a
788 .I prog-name
789 is also supplied, it names the file containing the program to execute;
790 otherwise the file named by the first argument
791 .RI ( argv0 )
792 is used.
793 .PP
794 Note that the shell command or program name string must, if present,
795 have any delimiter characters (including
796 .RB ` / '
797 and
798 .RB ` . ')
799 quoted; this is not required in the
800 .RB ` [ '-enclosed
801 argument list.
802 .PP
803 The standard input and output of the program are forwarded to the other
804 end of the connection. The standard error stream is caught by
805 .B fw
806 and logged.
807 .PP
808 The
809 .B exec
810 source and target both understand the same set of options. The list of
811 options supported is as follows:
812 .OS "Exec options"
813 .B exec.logging
814 .RB [ = ]
815 .BR yes | no
816 .OD
817 Whether to log the start and end of executed programs. If
818 .B yes
819 (the default), a log message is emitted when the program is started
820 listing its process id, and another is emitted when the program finishes
821 giving its process id and exit status. If
822 .BR no ,
823 these messages are not emitted. However the standard error stream is
824 still logged. The
825 .B log
826 abbreviation is accepted as a synonym for
827 .BR logging .
828 .OE
829 .OS "Exec options"
830 .B exec.dir
831 .RB [ = ]
832 .I file-name
833 .OD
834 Sets the current directory from which the the program should be run.
835 The default is not to change directory. The synonyms
836 .BR cd ,
837 .B chdir
838 and
839 .B cwd
840 are accepted in place of
841 .BR dir .
842 .OE
843 .OS "Exec options"
844 .B exec.root
845 .RB [ = ]
846 .I file-name
847 .OD
848 Sets the root directory for the program, using the
849 .BR chroot (2)
850 system call. You must be the superuser for this option to work. The
851 default is not to set a root directory. The synonym
852 .B chroot
853 is accepted in place of
854 .BR root .
855 .OE
856 .OS "Exec options"
857 .B exec.user
858 .RB [ = ]
859 .I user
860 .OD
861 Sets the user (real and effective uid) to run the program as. This will
862 usually require superuser privileges to work. The default is not to
863 change uid. The synonym
864 .B uid
865 is accepted in place of
866 .BR user .
867 .OE
868 .OS "Exec options"
869 .B exec.group
870 .RB [ = ]
871 .I group
872 .OD
873 Sets the group (real and effective gid) to run the program as. If
874 running with superuser privileges, the supplementary groups list is
875 cleared at the same time. The default is not to change gid (or clear
876 the supplementary groups list). The synonym
877 .B gid
878 is accepted in place of
879 .BR group .
880 .OE
881 .OS "Exec options"
882 .BI exec.rlimit. limit \c
883 .RB [ .hard | .soft ]
884 .RB [ = ]
885 .I value
886 .OD
887 Set resource limits for the program. The
888 .I limit
889 may be one of the resource limit names described in
890 .BR setrlimit (2),
891 in lower-case and without the
892 .B RLIMIT_
893 prefix; for example,
894 .B RLIMIT_CORE
895 becomes simply
896 .BR core .
897 The
898 .I value
899 is a number, followed optionally by
900 .B k
901 to multiply by 1024 (2\*(ss10\*(se),
902 .B m
903 to multiply by 1048576 (2\*(ss20\*(se), or
904 .B g
905 to multiply by 1073741824 (2\*(ss30\*(se); purists can use upper-case
906 versions of these if they want. If
907 .B .hard
908 or
909 .B .soft
910 was specified, only the hard or soft limit is set; otherwise both are
911 set to the same value. Only the superuser can raise the hard limit.
912 The soft limit cannot be set above the hard limit.
913 .OE
914 .OS "Exec options"
915 .B exec.env.clear
916 .OD
917 Clears the program's environment.
918 .OE
919 .PP
920 .B exec.env.unset
921 .I var
922 .OD
923 Removes
924 .I var
925 from the program's environment. It is not an error if no variable named
926 .I var
927 exists.
928 .OE
929 .OS "Exec options"
930 .BR exec.env. [ set ]
931 .I var
932 .RB [ = ]
933 .I value
934 .OD
935 Assigns the variable
936 .I var
937 the value
938 .I value
939 in the program's environment, possibly replacing the existing value.
940 The
941 .B set
942 may be omitted if the
943 .B env
944 qualifier is present.
945 .OE
946 .PP
947 Note that environment variable modifications are performed in order,
948 global modifications before local ones.
949 .
950 .SS "The `socket' source and target types"
951 The
952 .B socket
953 source and target provide access to network services. Support is
954 currently provided for TCP/IP and Unix-domain sockets, although other
955 address types can be added with reasonable ease.
956 .PP
957 The syntax for socket sources and targets is:
958 .GS "Socket source and target"
959 .ll +8i
960 .I source
961 ::=
962 .I socket-source
963 .br
964 .I target
965 ::=
966 .I socket-target
967 .br
968 .I socket-source
969 ::=
970 .RB [ socket [ .\& ]]
971 .RB [[ : ] \c
972 .IR addr-type \c
973 .RB [ : ]]
974 .I source-addr
975 .br
976 .I socket-target
977 ::=
978 .RB [ socket [ .\& ]]
979 .RB [[ : ] \c
980 .IR addr-type \c
981 .RB [ : ]]
982 .I target-addr
983 .ll -8i
984 .GE
985 The syntax of the source and target addresses depend on the address
986 types, which are described below. The default address type, if no
987 .I addr-type
988 is given, is
989 .BR inet .
990 .PP
991 Socket sources support options; socket targets do not. The source
992 options provided are:
993 .OS "Socket options"
994 .B socket.conn
995 .RB [ = ]
996 .IR number | \c
997 .BR unlimited | one-shot
998 .OD
999 Controls the behaviour of the source when it receives connections. A
1000 .I number
1001 limits the number of simultaneous connections. The value
1002 .B unlimited
1003 (or
1004 .BR infinite )
1005 removes any limit on the number of connections possible. The value
1006 .B one-shot
1007 will remove the socket source after a single successful connection.
1008 (Connections refused by access control systems don't count here.)
1009 The default is to apply a limit of 256 concurrent connections. Use of
1010 the
1011 .B unlimited
1012 option is not recommended.
1013 .OE
1014 .OS "Socket options"
1015 .B socket.listen
1016 .RB [ = ]
1017 .I number
1018 .OD
1019 Sets the maximum of the kernel incoming connection queue for this socket
1020 source. This is the number given to the
1021 .BR listen (2)
1022 system call. The default is 5.
1023 .OE
1024 .OS "Socket options"
1025 .B socket.logging
1026 .RB [ = ]
1027 .BR yes | no
1028 .OD
1029 Whether to log incoming connections. If
1030 .B yes
1031 (the default) incoming connections are logged, together with information
1032 about the client (where available) and whether the connection was
1033 accepted or refused. If
1034 .BR no ,
1035 log messages are not generated.
1036 .OE
1037 .PP
1038 Address types also provide their own options.
1039 .
1040 .SS "The `inet' socket address type"
1041 The
1042 .B inet
1043 address type provides access to TCP ports. The
1044 .B inet
1045 source and target addresses have the following syntax:
1046 .GS "Socket source and target"
1047 .I inet-source-addr
1048 ::=
1049 .RB [ port ]
1050 .I port
1051 .br
1052 .I inet-target-addr
1053 ::=
1054 .I address
1055 .RB [ : ]
1056 .I port
1057 .br
1058 .I address
1059 ::=
1060 .I addr-elt
1061 |
1062 .I address
1063 .I addr-elt
1064 .br
1065 .I addr-elt
1066 ::=
1067 .B .\&
1068 |
1069 .I word
1070 .GE
1071 A
1072 .I port
1073 may be given as a port number or a service name from the
1074 .B /etc/services
1075 file (or YP map if you do that sort of thing). A
1076 .B hostname
1077 may be a textual hostname or a numerical IP address.
1078 .PP
1079 The
1080 .B inet
1081 source address accepts the following options:
1082 .OS "Socket options"
1083 .B socket.inet.source.addr
1084 .RB [ = ]
1085 .RR any | \c
1086 .I addr
1087 .OD
1088 Specify the IP address on which to listen for incoming connections. The
1089 default is
1090 .BR any ,
1091 which means to listen on all addresses, though it may be useful to
1092 specify this explicitly, if the global setting is different.
1093 .OE
1094 .OS "Socket options"
1095 .BR socket.inet.source. [ allow | deny ]
1096 .RB [ host ]
1097 .I addr
1098 .RB [ /
1099 .IR addr ]
1100 .OD
1101 Adds an entry to the source's access control list. If only one
1102 .I address
1103 is given, the entry applies only to that address; if two are given, the
1104 first is a network address and the second is a netmask either in
1105 dotted-quad format or a simple number of bits (e.g.,
1106 .B /255.255.255.192
1107 and
1108 .B /26
1109 mean the same), and the entry applies to any address which, when masked
1110 by the netmask, is equal to the masked network address.
1111 .OE
1112 .OS "Socket options"
1113 .BR socket.inet.source. [ allow | deny ]
1114 .B priv-port
1115 .OD
1116 Accept or reject connections from low-numbered `privileged' ports, in
1117 the range 0--1023.
1118 .OE
1119 .OS "Socket options"
1120 .B socket.inet.dest.addr
1121 .RB [ = ]
1122 .RR any | \c
1123 .I addr
1124 .OD
1125 Specify the IP address to bind the local socket to when making an
1126 outbound connection. The default is
1127 .BR any ,
1128 which means to use whichever address the kernel thinks is most
1129 convenient. This option is useful if the destination is doing
1130 host-based access control and your server is multi-homed.
1131 .OE
1132 .PP
1133 The access control rules are examined in the order: local entries first,
1134 then global ones, each in the order given in the configuration file.
1135 The first matching entry is used. If no entries match, the behaviour is
1136 the
1137 .I opposite
1138 of the last entry tried. If there are no entries defined, the default
1139 is to allow all clients.
1140 .
1141 .SS "The `unix' socket address type"
1142 The
1143 .B unix
1144 address type allows access to Unix-domain sockets. The syntax for
1145 .B unix
1146 source and target addresses is like this:
1147 .GS "Socket source and target"
1148 .I unix-source-addr
1149 ::=
1150 .I file-name
1151 .br
1152 .I unix-target-addr
1153 ::=
1154 .I file-name
1155 .GE
1156 The following options are supported by the
1157 .B unix
1158 source address type:
1159 .OS "Socket options"
1160 .BR socket.unix.fattr. *
1161 .OD
1162 The
1163 .B unix
1164 source address accepts
1165 .B fattr
1166 options to control the attributes of the socket file created.
1167 .OE
1168 .PP
1169 Sockets are removed if
1170 .B fw
1171 exits normally (which it will do if it runs out of sources or
1172 connections, or if
1173 .B fw
1174 shuts down in a clean way).
1175 .SH "EXAMPLES"
1176 To forward the local port 25 to a main mail server:
1177 .VS
1178 from 25 to mailserv:25
1179 .VE
1180 To attach a fortune server to a Unix-domain socket:
1181 .VS
1182 from unix:/tmp/fortunes
1183 to exec [/usr/games/fortune] { user nobody }
1184 .VE
1185 To fetch a fortune from the server:
1186 .VS
1187 from file stdin, stdout to unix:/tmp/fortunes
1188 .VE
1189 To emulate
1190 .BR cat (1):
1191 .VS
1192 from file stdin, null to file null, stdout
1193 .VE
1194 .
1195 .\"--------------------------------------------------------------------------
1196 .SH "SIGNAL HANDLING"
1197 .
1198 The
1199 .B fw
1200 program responds to various signals when it's running. If it receives
1201 .B SIGTERM
1202 or
1203 .BR SIGINT ,
1204 .B fw
1205 performs a
1206 .I graceful
1207 shutdown: it removes all of its sources, and will exit when no more
1208 connections are running. (Note that if the disposition
1209 .B SIGINT
1210 was to ignore it,
1211 .B fw
1212 does not re-enable the signal. You'll have to send
1213 .B SIGTERM
1214 in that case.) If
1215 .B fw
1216 receives
1217 .BR SIGQUIT ,
1218 it performs an
1219 .I abrupt
1220 shutdown: it removes all sources and extant connections and closes down
1221 more-or-less immediately.
1222 .PP
1223 Finally, if any configuration files (other than standard input) were
1224 provided to
1225 .B fw
1226 on its command line using the
1227 .B \-f
1228 option, a
1229 .B SIGHUP
1230 signal may be sent to instruct
1231 .B fw
1232 to reload its configuration. Any existing connections are allowed to
1233 run their course. If no such configuration files are available,
1234 .B fw
1235 just logs a message about the signal and continues.
1236 .PP
1237 .
1238 .\"--------------------------------------------------------------------------
1239 .SH "GRAMMAR SUMMARY"
1240 .
1241 .SS "Basic syntax"
1242 .I file
1243 ::=
1244 .I empty
1245 |
1246 .I file
1247 .I stmt
1248 .RB [ ; ]
1249 .br
1250 .I stmt
1251 ::=
1252 .I option-stmt
1253 |
1254 .I fw-stmt
1255 .br
1256 .I fw-stmt
1257 ::=
1258 .B fw
1259 .I source
1260 .I options
1261 .RB [ to | \-> ]
1262 .I target
1263 .I options
1264 .br
1265 .I options
1266 ::=
1267 .B {
1268 .I option-seq
1269 .B }
1270 .br
1271 .I option-seq
1272 ::=
1273 .I empty
1274 |
1275 .I option-stmt
1276 .RB [ ; ]
1277 .I option-seq
1278 .
1279 .SS "Option syntax"
1280 .I option-stmt
1281 ::=
1282 .I q-option
1283 .br
1284 .I q-option
1285 ::=
1286 .I option
1287 .br
1288 |
1289 .I prefix
1290 .B .\&
1291 .I q-option
1292 .br
1293 |
1294 .I prefix
1295 .B {
1296 .I option-seq
1297 .B }
1298 .br
1299 .I prefix
1300 ::=
1301 .I word
1302 .
1303 .SS "File source and target"
1304 .I source
1305 ::=
1306 .I file
1307 .br
1308 .I target
1309 ::=
1310 .I file
1311 .br
1312 .I file
1313 ::=
1314 .B file
1315 .RB [ .\& ]
1316 .I fspec
1317 .RB [ ,
1318 .IR fspec ]
1319 .br
1320 .I fspec
1321 ::=
1322 .I fd-spec
1323 |
1324 .I name-spec
1325 |
1326 .I null-spec
1327 .br
1328 .I fd-spec
1329 ::=
1330 .RB [[ : ] fd [ : ]]
1331 .IR number \c
1332 .RB | stdin | stdout
1333 .br
1334 .I name-spec
1335 ::=
1336 .RB [[ : ] file [ : ]]
1337 .I file-name
1338 .br
1339 .I file-name
1340 ::=
1341 .I path-seq
1342 |
1343 .B [
1344 .I path-seq
1345 .B ]
1346 .br
1347 .I path-seq
1348 ::=
1349 .I path-elt
1350 |
1351 .I path-seq
1352 .I path-elt
1353 .br
1354 .I path-elt
1355 ::=
1356 .B /
1357 |
1358 .I word
1359 .br
1360 .I null-spec
1361 ::=
1362 .RB [ : ] null [ : ]
1363 .
1364 .SS "Exec source and target"
1365 .I source
1366 ::=
1367 .I exec
1368 .br
1369 .I target
1370 ::=
1371 exec
1372 .br
1373 .I exec
1374 ::=
1375 .BR exec
1376 .RB [ .\& ]
1377 .I cmd-spec
1378 .br
1379 .I cmd-spec
1380 ::=
1381 .I shell-cmd
1382 |
1383 .RI [ prog-name ]
1384 .B [
1385 .I argv0
1386 .I arg-seq
1387 .B ]
1388 .br
1389 .I arg-seq
1390 ::=
1391 .I word
1392 |
1393 .I arg-seq
1394 .I word
1395 .br
1396 .I shell-cmd
1397 ::=
1398 .I word
1399 .br
1400 .I argv0
1401 ::=
1402 .I word
1403 .
1404 .SS "Socket source and target"
1405 .ll +8i
1406 .I source
1407 ::=
1408 .I socket-source
1409 .br
1410 .I target
1411 ::=
1412 .I socket-target
1413 .br
1414 .I socket-source
1415 ::=
1416 .RB [ socket [ .\& ]]
1417 .RB [[ : ] \c
1418 .IR addr-type \c
1419 .RB [ : ]]
1420 .I source-addr
1421 .br
1422 .I socket-target
1423 ::=
1424 .RB [ socket [ .\& ]]
1425 .RB [[ : ] \c
1426 .IR addr-type \c
1427 .RB [ : ]]
1428 .I target-addr
1429 .ll -8i
1430 .PP
1431 .I inet-source-addr
1432 ::=
1433 .RB [ port ]
1434 .I port
1435 .br
1436 .I inet-target-addr
1437 ::=
1438 .I address
1439 .RB [ : ]
1440 .I port
1441 .br
1442 .I address
1443 ::=
1444 .I addr-elt
1445 |
1446 .I address
1447 .I addr-elt
1448 .br
1449 .I addr-elt
1450 ::=
1451 .B .\&
1452 |
1453 .I word
1454 .PP
1455 .I unix-source-addr
1456 ::=
1457 .I file-name
1458 .br
1459 .I unix-target-addr
1460 ::=
1461 .I file-name
1462 .
1463 .\"--------------------------------------------------------------------------
1464 .SH "OPTION SUMMARY"
1465 .
1466 .SS "File attributes (`fattr')"
1467 .IB prefix .fattr.mode
1468 .RB [ = ]
1469 .I mode
1470 .br
1471 .IB prefix .fattr.owner
1472 .RB [ = ]
1473 .I user
1474 .br
1475 .IB prefix .fattr.group
1476 .RB [ = ]
1477 .I group
1478 .
1479 .SS "File options"
1480 .B file.create
1481 .RB [ = ]
1482 .BR yes | no
1483 .br
1484 .B file.open
1485 .RB [ = ]
1486 .BR no | truncate | append
1487 .br
1488 .BR file.fattr. *
1489 .
1490 .SS "Exec options"
1491 .B exec.logging
1492 .RB [ = ]
1493 .BR yes | no
1494 .br
1495 .B exec.dir
1496 .RB [ = ]
1497 .I file-name
1498 .br
1499 .B exec.root
1500 .RB [ = ]
1501 .I file-name
1502 .br
1503 .B exec.user
1504 .RB [ = ]
1505 .I user
1506 .br
1507 .B exec.group
1508 .RB [ = ]
1509 .I group
1510 .br
1511 .BI exec.rlimit. limit \c
1512 .RB [ .hard | .soft ]
1513 .RB [ = ]
1514 .I value
1515 .br
1516 .B exec.env.clear
1517 .br
1518 .B exec.env.unset
1519 .I var
1520 .br
1521 .BR exec.env. [ set ]
1522 .I var
1523 .RB [ = ]
1524 .I value
1525 .
1526 .SS "Socket options"
1527 .B socket.conn
1528 .RB [ = ]
1529 .IR number | \c
1530 .BR unlimited | one-shot
1531 .br
1532 .B socket.listen
1533 .RB [ = ]
1534 .I number
1535 .br
1536 .B socket.logging
1537 .RB [ = ]
1538 .BR yes | no
1539 .PP
1540 .BR socket.inet.source. [ allow | deny ]
1541 .RB [ host ]
1542 .I addr
1543 .RB [ /
1544 .IR addr ]
1545 .br
1546 .BR socket.inet.source. [ allow | deny ]
1547 .B priv-port
1548 .br
1549 .B socket.inet.source.addr
1550 .RB [ = ]
1551 .BR any | \c
1552 .I addr
1553 .br
1554 .B socket.inet.dest.addr
1555 .RB [ = ]
1556 .BR any | \c
1557 .I addr
1558 .PP
1559 .BR socket.unix.fattr. *
1560 .
1561 .\"--------------------------------------------------------------------------
1562 .SH "BUGS"
1563 .
1564 The syntax for IP addresses and filenames is nasty.
1565 .PP
1566 IPv6 is not supported yet. Because of
1567 .BR fw 's
1568 socket address architecture, it's probably not a major piece of work to
1569 add.
1570 .PP
1571 Please inform me of any security problems you think you've identified in
1572 this program. I take security very seriously, and I will fix security
1573 holes as a matter of priority when I find out about them. I will be
1574 annoyed if I have to read about problems on Bugtraq because they weren't
1575 mailed to me first.
1576 .PP
1577 The program is too complicated, and this manual page is too long.
1578 .
1579 .\"--------------------------------------------------------------------------
1580 .SH "AUTHOR"
1581 .
1582 Mark Wooding, <mdw@nsict.org>
1583 .
1584 .\"----- That's all, folks --------------------------------------------------