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