1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221
|
.TH tcprules 1
.SH NAME
tcprules \- compile rules for tcpserver
.SH SYNOPSIS
.B tcprules
.I rules.cdb
.I rules.tmp
.SH OVERVIEW
.B tcpserver
optionally follows rules to decide whether a TCP connection is acceptable.
For example, a rule of
.EX
18.23.0.32:deny
.EE
prohibits connections from IP address 18.23.0.32.
.B tcprules
reads rules from its standard input
and writes them into
.I rules.cdb
in a binary format suited
for quick access by
.BR tcpserver .
.B tcprules
can be used while
.B tcpserver
is running:
it ensures that
.I rules.cdb
is updated atomically.
It does this by first writing the rules to
.I rules.tmp
and then moving
.I rules.tmp
on top of
.IR rules.cdb .
If
.I rules.tmp
already exists, it is destroyed.
The directories containing
.I rules.cdb
and
.I rules.tmp
must be writable to
.BR tcprules ;
they must also be on the same filesystem.
If there is a problem with the input,
.B tcprules
complains and leaves
.I rules.cdb
alone.
The binary
.I rules.cdb
format is portable across machines.
.SH "RULE FORMAT"
A rule takes up one line.
A file containing rules
may also contain comments: lines beginning with # are ignored.
Each rule contains an
.BR address ,
a colon,
and a list of
.BR instructions ,
with no extra spaces.
When
.B tcpserver
receives a connection from that address,
it follows the instructions.
.SH "ADDRESSES"
.B tcpserver
starts by looking for a rule with address
.IR TCPREMOTEINFO\fB@\fITCPREMOTEIP .
If it doesn't find one, or if
.I TCPREMOTEINFO
is not set, it tries the address
.IR TCPREMOTEIP .
If that doesn't work, it tries shorter and shorter prefixes of
.I TCPREMOTEIP
ending with a dot.
If none of them work, it tries the empty string.
For example, here are some rules:
.EX
joe@127.0.0.1:first
.br
18.23.0.32:second
.br
127.:third
.br
:fourth
.br
::1:fifth
.EE
If
.I TCPREMOTEIP
is
.BR 10.119.75.38 ,
.B tcpserver
will follow the
.B fourth
instructions.
If
.I TCPREMOTEIP
is
.BR ::1 ,
.B tcpserver
will follow the
.B fifth
instructions. Note that you cannot detect IPv4 mapped addresses by
matching "::ffff", as those addresses will be converted to IPv4 before
looking at the rules.
If
.I TCPREMOTEIP
is
.BR 18.23.0.32 ,
.B tcpserver
will follow the
.B second
instructions.
If
.I TCPREMOTEINFO
is
.B bill
and
.I TCPREMOTEIP
is
.BR 127.0.0.1 ,
.B tcpserver
will follow the
.B third
instructions.
If
.I TCPREMOTEINFO
is
.B joe
and
.I TCPREMOTEIP
is
.BR 127.0.0.1 ,
.B tcpserver
will follow the
.B first
instructions.
.SH "ADDRESS RANGES"
.B tcprules
treats
.B 1.2.3.37-53:ins
as an abbreviation
for the rules
.BR 1.2.3.37:ins ,
.BR 1.2.3.38:ins ,
and so on up through
.BR 1.2.3.53:ins .
Similarly,
.BR 10.2-3.:ins
is an abbreviation for
.B 10.2.:ins
and
.BR 10.3.:ins .
.SH "INSTRUCTIONS"
The instructions in a rule must begin with either
.B allow
or
.BR deny .
.B deny
tells
.B tcpserver
to drop the connection without running anything.
For example, the rule
.EX
:deny
.EE
tells
.B tcpserver
to drop all connections that aren't handled by more specific rules.
The instructions may continue with some environment variables,
in the format
.IR ,VAR="VALUE" .
.B tcpserver
adds
.I VAR=VALUE
to the current environment.
For example,
.EX
10.0.:allow,RELAYCLIENT="@fix.me"
.EE
adds
.B RELAYCLIENT=@fix.me
to the environment.
The quotes here may be replaced by any repeated character:
.EX
10.0.:allow,RELAYCLIENT=/@fix.me/
.EE
Any number of variables may be listed:
.EX
127.0.0.1:allow,RELAYCLIENT="",TCPLOCALHOST="movie.edu"
.EE
.SH "SEE ALSO"
tcprulescheck(1),
tcpserver(1),
tcp-environ(5)
|