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