xref: /freebsd/contrib/blocklist/lib/libblacklist.3 (revision 5f4c09dd85bff675e0ca63c55ea3c517e0fddfcc)
1*5f4c09ddSEd Maste.\" $NetBSD: libblacklist.3,v 1.10 2020/03/30 15:47:15 christos Exp $
2*5f4c09ddSEd Maste.\"
3*5f4c09ddSEd Maste.\" Copyright (c) 2015 The NetBSD Foundation, Inc.
4*5f4c09ddSEd Maste.\" All rights reserved.
5*5f4c09ddSEd Maste.\"
6*5f4c09ddSEd Maste.\" This code is derived from software contributed to The NetBSD Foundation
7*5f4c09ddSEd Maste.\" by Christos Zoulas.
8*5f4c09ddSEd Maste.\"
9*5f4c09ddSEd Maste.\" Redistribution and use in source and binary forms, with or without
10*5f4c09ddSEd Maste.\" modification, are permitted provided that the following conditions
11*5f4c09ddSEd Maste.\" are met:
12*5f4c09ddSEd Maste.\" 1. Redistributions of source code must retain the above copyright
13*5f4c09ddSEd Maste.\"    notice, this list of conditions and the following disclaimer.
14*5f4c09ddSEd Maste.\" 2. Redistributions in binary form must reproduce the above copyright
15*5f4c09ddSEd Maste.\"    notice, this list of conditions and the following disclaimer in the
16*5f4c09ddSEd Maste.\"    documentation and/or other materials provided with the distribution.
17*5f4c09ddSEd Maste.\"
18*5f4c09ddSEd Maste.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
19*5f4c09ddSEd Maste.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
20*5f4c09ddSEd Maste.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21*5f4c09ddSEd Maste.\" PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
22*5f4c09ddSEd Maste.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23*5f4c09ddSEd Maste.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24*5f4c09ddSEd Maste.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25*5f4c09ddSEd Maste.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26*5f4c09ddSEd Maste.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27*5f4c09ddSEd Maste.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28*5f4c09ddSEd Maste.\" POSSIBILITY OF SUCH DAMAGE.
29*5f4c09ddSEd Maste.\"
30*5f4c09ddSEd Maste.Dd March 30, 2020
31*5f4c09ddSEd Maste.Dt LIBBLACKLIST 3
32*5f4c09ddSEd Maste.Os
33*5f4c09ddSEd Maste.Sh NAME
34*5f4c09ddSEd Maste.Nm blacklist_open ,
35*5f4c09ddSEd Maste.Nm blacklist_close ,
36*5f4c09ddSEd Maste.Nm blacklist_r ,
37*5f4c09ddSEd Maste.Nm blacklist ,
38*5f4c09ddSEd Maste.Nm blacklist_sa ,
39*5f4c09ddSEd Maste.Nm blacklist_sa_r
40*5f4c09ddSEd Maste.Nd Blacklistd notification library
41*5f4c09ddSEd Maste.Sh LIBRARY
42*5f4c09ddSEd Maste.Lb libblacklist
43*5f4c09ddSEd Maste.Sh SYNOPSIS
44*5f4c09ddSEd Maste.In blacklist.h
45*5f4c09ddSEd Maste.Ft struct blacklist *
46*5f4c09ddSEd Maste.Fn blacklist_open "void"
47*5f4c09ddSEd Maste.Ft void
48*5f4c09ddSEd Maste.Fn blacklist_close "struct blacklist *cookie"
49*5f4c09ddSEd Maste.Ft int
50*5f4c09ddSEd Maste.Fn blacklist "int action" "int fd" "const char *msg"
51*5f4c09ddSEd Maste.Ft int
52*5f4c09ddSEd Maste.Fn blacklist_r "struct blacklist *cookie" "int action" "int fd" "const char *msg"
53*5f4c09ddSEd Maste.Ft int
54*5f4c09ddSEd Maste.Fn blacklist_sa "int action" "int fd" "const struct sockaddr *sa" "socklen_t salen" "const char *msg"
55*5f4c09ddSEd Maste.Ft int
56*5f4c09ddSEd Maste.Fn blacklist_sa_r "struct blacklist *cookie" "int action" "int fd" "const struct sockaddr *sa" "socklen_t salen" "const char *msg"
57*5f4c09ddSEd Maste.Sh DESCRIPTION
58*5f4c09ddSEd MasteThese functions can be used by daemons to notify
59*5f4c09ddSEd Maste.Xr blacklistd 8
60*5f4c09ddSEd Masteabout successful and failed remote connections so that blacklistd can
61*5f4c09ddSEd Masteblock or release port access to prevent Denial of Service attacks.
62*5f4c09ddSEd Maste.Pp
63*5f4c09ddSEd MasteThe function
64*5f4c09ddSEd Maste.Fn blacklist_open
65*5f4c09ddSEd Mastecreates the necessary state to communicate with
66*5f4c09ddSEd Maste.Xr blacklistd 8
67*5f4c09ddSEd Masteand returns a pointer to it, or
68*5f4c09ddSEd Maste.Dv NULL
69*5f4c09ddSEd Masteon failure.
70*5f4c09ddSEd Maste.Pp
71*5f4c09ddSEd MasteThe
72*5f4c09ddSEd Maste.Fn blacklist_close
73*5f4c09ddSEd Mastefunction frees all memory and resources used.
74*5f4c09ddSEd Maste.Pp
75*5f4c09ddSEd MasteThe
76*5f4c09ddSEd Maste.Fn blacklist
77*5f4c09ddSEd Mastefunction sends a message to
78*5f4c09ddSEd Maste.Xr blacklistd 8 ,
79*5f4c09ddSEd Mastewith an integer
80*5f4c09ddSEd Maste.Ar action
81*5f4c09ddSEd Masteargument specifying the type of notification,
82*5f4c09ddSEd Mastea file descriptor
83*5f4c09ddSEd Maste.Ar fd
84*5f4c09ddSEd Mastespecifying the accepted file descriptor connected to the client,
85*5f4c09ddSEd Masteand an optional message in the
86*5f4c09ddSEd Maste.Ar msg
87*5f4c09ddSEd Masteargument.
88*5f4c09ddSEd Maste.Pp
89*5f4c09ddSEd MasteThe
90*5f4c09ddSEd Maste.Ar action
91*5f4c09ddSEd Masteparameter can take these values:
92*5f4c09ddSEd Maste.Bl -tag -width ".Va BLACKLIST_ABUSIVE_BEHAVIOR"
93*5f4c09ddSEd Maste.It Va BLACKLIST_AUTH_FAIL
94*5f4c09ddSEd MasteThere was an unsuccessful authentication attempt.
95*5f4c09ddSEd Maste.It Va BLACKLIST_AUTH_OK
96*5f4c09ddSEd MasteA user successfully authenticated.
97*5f4c09ddSEd Maste.It Va BLACKLIST_ABUSIVE_BEHAVIOR
98*5f4c09ddSEd MasteThe sending daemon has detected abusive behavior
99*5f4c09ddSEd Mastefrom the remote system.
100*5f4c09ddSEd MasteThe remote address should
101*5f4c09ddSEd Mastebe blocked as soon as possible.
102*5f4c09ddSEd Maste.It Va BLACKLIST_BAD_USER
103*5f4c09ddSEd MasteThe sending daemon has determined the username
104*5f4c09ddSEd Mastepresented for authentication is invalid.
105*5f4c09ddSEd MasteThe
106*5f4c09ddSEd Maste.Xr blacklistd 8
107*5f4c09ddSEd Mastedaemon compares the username to a configured list of forbidden
108*5f4c09ddSEd Masteusernames and
109*5f4c09ddSEd Masteblocks the address immediately if a forbidden username matches.
110*5f4c09ddSEd Maste(The
111*5f4c09ddSEd Maste.Ar BLACKLIST_BAD_USER
112*5f4c09ddSEd Mastesupport is not currently available.)
113*5f4c09ddSEd Maste.El
114*5f4c09ddSEd Maste.Pp
115*5f4c09ddSEd MasteThe
116*5f4c09ddSEd Maste.Fn blacklist_r
117*5f4c09ddSEd Mastefunction is more efficient because it keeps the blacklist state around.
118*5f4c09ddSEd Maste.Pp
119*5f4c09ddSEd MasteThe
120*5f4c09ddSEd Maste.Fn blacklist_sa
121*5f4c09ddSEd Masteand
122*5f4c09ddSEd Maste.Fn blacklist_sa_r
123*5f4c09ddSEd Mastefunctions can be used with unconnected sockets, where
124*5f4c09ddSEd Maste.Xr getpeername 2
125*5f4c09ddSEd Mastewill not work, the server will pass the peer name in the message.
126*5f4c09ddSEd Maste.Pp
127*5f4c09ddSEd MasteIn all cases the file descriptor passed in the
128*5f4c09ddSEd Maste.Fa fd
129*5f4c09ddSEd Masteargument must be pointing to a valid socket so that
130*5f4c09ddSEd Maste.Xr blacklistd 8
131*5f4c09ddSEd Mastecan establish ownership of the local endpoint
132*5f4c09ddSEd Masteusing
133*5f4c09ddSEd Maste.Xr getsockname 2 .
134*5f4c09ddSEd Maste.Pp
135*5f4c09ddSEd MasteBy default,
136*5f4c09ddSEd Maste.Xr syslogd 8
137*5f4c09ddSEd Masteis used for message logging.
138*5f4c09ddSEd MasteThe internal
139*5f4c09ddSEd Maste.Fn bl_create
140*5f4c09ddSEd Mastefunction can be used to create the required internal
141*5f4c09ddSEd Mastestate and specify a custom logging function.
142*5f4c09ddSEd Maste.Sh RETURN VALUES
143*5f4c09ddSEd MasteThe function
144*5f4c09ddSEd Maste.Fn blacklist_open
145*5f4c09ddSEd Mastereturns a cookie on success and
146*5f4c09ddSEd Maste.Dv NULL
147*5f4c09ddSEd Masteon failure setting
148*5f4c09ddSEd Maste.Dv errno
149*5f4c09ddSEd Masteto an appropriate value.
150*5f4c09ddSEd Maste.Pp
151*5f4c09ddSEd MasteThe functions
152*5f4c09ddSEd Maste.Fn blacklist ,
153*5f4c09ddSEd Maste.Fn blacklist_sa ,
154*5f4c09ddSEd Masteand
155*5f4c09ddSEd Maste.Fn blacklist_sa_r
156*5f4c09ddSEd Mastereturn
157*5f4c09ddSEd Maste.Dv 0
158*5f4c09ddSEd Masteon success and
159*5f4c09ddSEd Maste.Dv \-1
160*5f4c09ddSEd Masteon failure setting
161*5f4c09ddSEd Maste.Dv errno
162*5f4c09ddSEd Masteto an appropriate value.
163*5f4c09ddSEd Maste.Sh SEE ALSO
164*5f4c09ddSEd Maste.Xr blacklistd.conf 5 ,
165*5f4c09ddSEd Maste.Xr blacklistd 8
166*5f4c09ddSEd Maste.Sh AUTHORS
167*5f4c09ddSEd Maste.An Christos Zoulas
168