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