Tue Apr 21 13:57:12 2020 UTC ()
PR/55193: Jose Luis Duran: Fix wrong location for the db file.


(christos)
diff -r1.22 -r1.23 src/external/bsd/blacklist/bin/blacklistd.8

cvs diff -r1.22 -r1.23 src/external/bsd/blacklist/bin/Attic/blacklistd.8 (switch to unified diff)

--- src/external/bsd/blacklist/bin/Attic/blacklistd.8 2020/03/30 08:45:09 1.22
+++ src/external/bsd/blacklist/bin/Attic/blacklistd.8 2020/04/21 13:57:12 1.23
@@ -1,284 +1,284 @@ @@ -1,284 +1,284 @@
1.\" $NetBSD: blacklistd.8,v 1.22 2020/03/30 08:45:09 wiz Exp $ 1.\" $NetBSD: blacklistd.8,v 1.23 2020/04/21 13:57:12 christos Exp $
2.\" 2.\"
3.\" Copyright (c) 2015 The NetBSD Foundation, Inc. 3.\" Copyright (c) 2015 The NetBSD Foundation, Inc.
4.\" All rights reserved. 4.\" All rights reserved.
5.\" 5.\"
6.\" This code is derived from software contributed to The NetBSD Foundation 6.\" This code is derived from software contributed to The NetBSD Foundation
7.\" by Christos Zoulas. 7.\" by Christos Zoulas.
8.\" 8.\"
9.\" Redistribution and use in source and binary forms, with or without 9.\" Redistribution and use in source and binary forms, with or without
10.\" modification, are permitted provided that the following conditions 10.\" modification, are permitted provided that the following conditions
11.\" are met: 11.\" are met:
12.\" 1. Redistributions of source code must retain the above copyright 12.\" 1. Redistributions of source code must retain the above copyright
13.\" notice, this list of conditions and the following disclaimer. 13.\" notice, this list of conditions and the following disclaimer.
14.\" 2. Redistributions in binary form must reproduce the above copyright 14.\" 2. Redistributions in binary form must reproduce the above copyright
15.\" notice, this list of conditions and the following disclaimer in the 15.\" notice, this list of conditions and the following disclaimer in the
16.\" documentation and/or other materials provided with the distribution. 16.\" documentation and/or other materials provided with the distribution.
17.\" 17.\"
18.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 18.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
19.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 19.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
20.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 20.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 21.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
22.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 27.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28.\" POSSIBILITY OF SUCH DAMAGE. 28.\" POSSIBILITY OF SUCH DAMAGE.
29.\" 29.\"
30.Dd March 29, 2020 30.Dd April 21, 2020
31.Dt BLACKLISTD 8 31.Dt BLACKLISTD 8
32.Os 32.Os
33.Sh NAME 33.Sh NAME
34.Nm blacklistd 34.Nm blacklistd
35.Nd block and release ports on demand to avoid DoS abuse 35.Nd block and release ports on demand to avoid DoS abuse
36.Sh SYNOPSIS 36.Sh SYNOPSIS
37.Nm 37.Nm
38.Op Fl dfrv 38.Op Fl dfrv
39.Op Fl C Ar controlprog 39.Op Fl C Ar controlprog
40.Op Fl c Ar configfile 40.Op Fl c Ar configfile
41.Op Fl D Ar dbfile 41.Op Fl D Ar dbfile
42.Op Fl P Ar sockpathsfile 42.Op Fl P Ar sockpathsfile
43.Op Fl R Ar rulename 43.Op Fl R Ar rulename
44.Op Fl s Ar sockpath 44.Op Fl s Ar sockpath
45.Op Fl t Ar timeout 45.Op Fl t Ar timeout
46.Sh DESCRIPTION 46.Sh DESCRIPTION
47.Nm 47.Nm
48is a daemon similar to 48is a daemon similar to
49.Xr syslogd 8 49.Xr syslogd 8
50that listens to sockets at paths specified in the 50that listens to sockets at paths specified in the
51.Ar sockpathsfile 51.Ar sockpathsfile
52for notifications from other daemons about successful or failed connection 52for notifications from other daemons about successful or failed connection
53attempts. 53attempts.
54If no such file is specified, then it only listens to the socket path 54If no such file is specified, then it only listens to the socket path
55specified by 55specified by
56.Ar sockspath 56.Ar sockspath
57or if that is not specified to 57or if that is not specified to
58.Pa /var/run/blacklistd.sock . 58.Pa /var/run/blacklistd.sock .
59Each notification contains an (action, port, protocol, address, owner) tuple 59Each notification contains an (action, port, protocol, address, owner) tuple
60that identifies the remote connection and the action. 60that identifies the remote connection and the action.
61This tuple is consulted against entries in 61This tuple is consulted against entries in
62.Ar configfile 62.Ar configfile
63with syntax specified in 63with syntax specified in
64.Xr blacklistd.conf 5 . 64.Xr blacklistd.conf 5 .
65If an entry is matched, a state entry is created for that tuple. 65If an entry is matched, a state entry is created for that tuple.
66Each entry contains a number of tries limit and a duration. 66Each entry contains a number of tries limit and a duration.
67.Pp 67.Pp
68The way 68The way
69.Nm 69.Nm
70does configuration entry matching is by having the client side pass the 70does configuration entry matching is by having the client side pass the
71file descriptor associated with the connection the client wants to blacklist 71file descriptor associated with the connection the client wants to blacklist
72as well as passing socket credentials. 72as well as passing socket credentials.
73.Pp 73.Pp
74The file descriptor is used to retrieve information (address and port) 74The file descriptor is used to retrieve information (address and port)
75about the remote side with 75about the remote side with
76.Xr getpeername 2 76.Xr getpeername 2
77and the local side with 77and the local side with
78.Xr getsockname 2 . 78.Xr getsockname 2 .
79.Pp 79.Pp
80By examining the port of the local side, 80By examining the port of the local side,
81.Nm 81.Nm
82can determine if the client program 82can determine if the client program
83.Dq owns 83.Dq owns
84the port. 84the port.
85By examining the optional address portion on the local side, it can match 85By examining the optional address portion on the local side, it can match
86interfaces. 86interfaces.
87By examining the remote address, it can match specific allow or deny rules. 87By examining the remote address, it can match specific allow or deny rules.
88.Pp 88.Pp
89Finally 89Finally
90.Nm 90.Nm
91can examine the socket credentials to match the user in the configuration file. 91can examine the socket credentials to match the user in the configuration file.
92.Pp 92.Pp
93While this works well for TCP sockets, it cannot be relied on for unbound 93While this works well for TCP sockets, it cannot be relied on for unbound
94UDP sockets. 94UDP sockets.
95It is also less meaningful when it comes to connections using non-privileged 95It is also less meaningful when it comes to connections using non-privileged
96ports. 96ports.
97On the other hand, if we receive a request that has a local endpoint indicating 97On the other hand, if we receive a request that has a local endpoint indicating
98a UDP privileged port, we can presume that the client was privileged to be 98a UDP privileged port, we can presume that the client was privileged to be
99able to acquire that port. 99able to acquire that port.
100.Pp 100.Pp
101Once an entry is matched 101Once an entry is matched
102.Nm 102.Nm
103can perform various actions. 103can perform various actions.
104If the action is 104If the action is
105.Dq add 105.Dq add
106and the number of tries limit is reached, then a 106and the number of tries limit is reached, then a
107control script 107control script
108.Ar controlprog 108.Ar controlprog
109is invoked with arguments: 109is invoked with arguments:
110.Bd -literal -offset indent 110.Bd -literal -offset indent
111control add <rulename> <proto> <address> <mask> <port> 111control add <rulename> <proto> <address> <mask> <port>
112.Ed 112.Ed
113.Pp 113.Pp
114and should invoke a packet filter command to block the connection 114and should invoke a packet filter command to block the connection
115specified by the arguments. 115specified by the arguments.
116The 116The
117.Ar rulename 117.Ar rulename
118argument can be set from the command line (default 118argument can be set from the command line (default
119.Dv blacklistd ) . 119.Dv blacklistd ) .
120The script could print a numerical id to stdout as a handle for 120The script could print a numerical id to stdout as a handle for
121the rule that can be used later to remove that connection, but 121the rule that can be used later to remove that connection, but
122that is not required as all information to remove the rule is 122that is not required as all information to remove the rule is
123kept. 123kept.
124.Pp 124.Pp
125If the action is 125If the action is
126.Dq remove 126.Dq remove
127Then the same control script is invoked as: 127Then the same control script is invoked as:
128.Bd -literal -offset indent 128.Bd -literal -offset indent
129control remove <rulename> <proto> <address> <mask> <port> <id> 129control remove <rulename> <proto> <address> <mask> <port> <id>
130.Ed 130.Ed
131.Pp 131.Pp
132where 132where
133.Ar id 133.Ar id
134is the number returned from the 134is the number returned from the
135.Dq add 135.Dq add
136action. 136action.
137.Pp 137.Pp
138.Nm 138.Nm
139maintains a database of known connections in 139maintains a database of known connections in
140.Ar dbfile . 140.Ar dbfile .
141On startup it reads entries from that file, and updates its internal state. 141On startup it reads entries from that file, and updates its internal state.
142.Pp 142.Pp
143.Nm 143.Nm
144checks the list of active entries every 144checks the list of active entries every
145.Ar timeout 145.Ar timeout
146seconds (default 146seconds (default
147.Dv 15 ) 147.Dv 15 )
148and removes entries and block rules using the control program as necessary. 148and removes entries and block rules using the control program as necessary.
149.Pp 149.Pp
150The following options are available: 150The following options are available:
151.Bl -tag -width indent 151.Bl -tag -width indent
152.It Fl C Ar controlprog 152.It Fl C Ar controlprog
153Use 153Use
154.Ar controlprog 154.Ar controlprog
155to communicate with the packet filter, usually 155to communicate with the packet filter, usually
156.Pa /libexec/blacklistd-helper . 156.Pa /libexec/blacklistd-helper .
157The following arguments are passed to the control program: 157The following arguments are passed to the control program:
158.Bl -tag -width protocol 158.Bl -tag -width protocol
159.It action 159.It action
160The action to perform: 160The action to perform:
161.Dv add , 161.Dv add ,
162.Dv rem , 162.Dv rem ,
163or 163or
164.Dv flush 164.Dv flush
165to add, remove or flush a firewall rule. 165to add, remove or flush a firewall rule.
166.It name 166.It name
167The rule name. 167The rule name.
168.It protocol 168.It protocol
169The optional protocol name (can be empty): 169The optional protocol name (can be empty):
170.Dv tcp , 170.Dv tcp ,
171.Dv tcp6 , 171.Dv tcp6 ,
172.Dv udp , 172.Dv udp ,
173.Dv udp6 . 173.Dv udp6 .
174.It address 174.It address
175The IPv4 or IPv6 numeric address to be blocked or released. 175The IPv4 or IPv6 numeric address to be blocked or released.
176.It mask 176.It mask
177The numeric mask to be applied to the blocked or released address 177The numeric mask to be applied to the blocked or released address
178.It port 178.It port
179The optional numeric port to be blocked (can be empty). 179The optional numeric port to be blocked (can be empty).
180.It id 180.It id
181For packet filters that support removal of rules by rule identifier, the 181For packet filters that support removal of rules by rule identifier, the
182identifier of the rule to be removed. 182identifier of the rule to be removed.
183The add command is expected to return the rule identifier string to stdout. 183The add command is expected to return the rule identifier string to stdout.
184.El 184.El
185.It Fl c Ar configuration 185.It Fl c Ar configuration
186The name of the configuration file to read, usually 186The name of the configuration file to read, usually
187.Pa /etc/blacklistd.conf . 187.Pa /etc/blacklistd.conf .
188.It Fl D Ar dbfile 188.It Fl D Ar dbfile
189The Berkeley DB file where 189The Berkeley DB file where
190.Nm 190.Nm
191stores its state, usually 191stores its state, usually
192.Pa /var/run/blacklistd.db . 192.Pa /var/db/blacklistd.db .
193.It Fl d 193.It Fl d
194Normally, 194Normally,
195.Nm 195.Nm
196disassociates itself from the terminal unless the 196disassociates itself from the terminal unless the
197.Fl d 197.Fl d
198flag is specified, in which case it stays in the foreground. 198flag is specified, in which case it stays in the foreground.
199.It Fl f 199.It Fl f
200Truncate the state database and flush all the rules named 200Truncate the state database and flush all the rules named
201.Ar rulename 201.Ar rulename
202are deleted by invoking the control script as: 202are deleted by invoking the control script as:
203.Bd -literal -offset indent 203.Bd -literal -offset indent
204control flush <rulename> 204control flush <rulename>
205.Ed 205.Ed
206.It Fl P Ar sockspathsfile 206.It Fl P Ar sockspathsfile
207A file containing a list of pathnames, one per line that 207A file containing a list of pathnames, one per line that
208.Nm 208.Nm
209will create sockets to listen to. 209will create sockets to listen to.
210This is useful for chrooted environments. 210This is useful for chrooted environments.
211.It Fl R Ar rulename 211.It Fl R Ar rulename
212Specify the default rule name for the packet filter rules, usually 212Specify the default rule name for the packet filter rules, usually
213.Dv blacklistd . 213.Dv blacklistd .
214.It Fl r 214.It Fl r
215Re-read the firewall rules from the internal database, then 215Re-read the firewall rules from the internal database, then
216remove and re-add them. 216remove and re-add them.
217This helps for packet filters that do not retain state across reboots. 217This helps for packet filters that do not retain state across reboots.
218.It Fl s Ar sockpath 218.It Fl s Ar sockpath
219Add 219Add
220.Ar sockpath 220.Ar sockpath
221to the list of Unix sockets 221to the list of Unix sockets
222.Nm 222.Nm
223listens to. 223listens to.
224.It Fl t Ar timeout 224.It Fl t Ar timeout
225The interval in seconds 225The interval in seconds
226.Nm 226.Nm
227polls the state file to update the rules. 227polls the state file to update the rules.
228.It Fl v 228.It Fl v
229Cause 229Cause
230.Nm 230.Nm
231to print 231to print
232diagnostic messages to 232diagnostic messages to
233.Dv stdout 233.Dv stdout
234instead of 234instead of
235.Xr syslogd 8 . 235.Xr syslogd 8 .
236.El 236.El
237.Sh SIGNAL HANDLING 237.Sh SIGNAL HANDLING
238.Nm 238.Nm
239deals with the following signals: 239deals with the following signals:
240.Bl -tag -width "USR2" 240.Bl -tag -width "USR2"
241.It Dv HUP 241.It Dv HUP
242Receipt of this signal causes 242Receipt of this signal causes
243.Nm 243.Nm
244to re-read the configuration file. 244to re-read the configuration file.
245.It Dv INT , Dv TERM & Dv QUIT 245.It Dv INT , Dv TERM & Dv QUIT
246These signals tell 246These signals tell
247.Nm 247.Nm
248to exit in an orderly fashion. 248to exit in an orderly fashion.
249.It Dv USR1 249.It Dv USR1
250This signal tells 250This signal tells
251.Nm 251.Nm
252to increase the internal debugging level by 1. 252to increase the internal debugging level by 1.
253.It Dv USR2 253.It Dv USR2
254This signal tells 254This signal tells
255.Nm 255.Nm
256to decrease the internal debugging level by 1. 256to decrease the internal debugging level by 1.
257.El 257.El
258.Sh FILES 258.Sh FILES
259.Bl -tag -width /libexec/blacklistd-helper -compact 259.Bl -tag -width /libexec/blacklistd-helper -compact
260.It Pa /libexec/blacklistd-helper 260.It Pa /libexec/blacklistd-helper
261Shell script invoked to interface with the packet filter. 261Shell script invoked to interface with the packet filter.
262.It Pa /etc/blacklistd.conf 262.It Pa /etc/blacklistd.conf
263Configuration file. 263Configuration file.
264.It Pa /var/db/blacklistd.db 264.It Pa /var/db/blacklistd.db
265Database of current connection entries. 265Database of current connection entries.
266.It Pa /var/run/blacklistd.sock 266.It Pa /var/run/blacklistd.sock
267Socket to receive connection notifications. 267Socket to receive connection notifications.
268.El 268.El
269.Sh SEE ALSO 269.Sh SEE ALSO
270.Xr blacklistd.conf 5 , 270.Xr blacklistd.conf 5 ,
271.Xr blacklistctl 8 , 271.Xr blacklistctl 8 ,
272.Xr npfctl 8 , 272.Xr npfctl 8 ,
273.Xr syslogd 8 273.Xr syslogd 8
274.Sh HISTORY 274.Sh HISTORY
275.Nm 275.Nm
276first appeared in 276first appeared in
277.Nx 7 . 277.Nx 7 .
278.Fx 278.Fx
279support for 279support for
280.Nm 280.Nm
281was implemented in 281was implemented in
282.Fx 11 . 282.Fx 11 .
283.Sh AUTHORS 283.Sh AUTHORS
284.An Christos Zoulas 284.An Christos Zoulas