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