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