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