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