3 * Access control list handling
5 * (c) 1999 Straylight/Edgeware
8 /*----- Licensing notice --------------------------------------------------*
10 * This file is part of the `fw' port forwarder.
12 * `fw' is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * `fw' is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with `fw'; if not, write to the Free Software Foundation,
24 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
34 /*----- Header files ------------------------------------------------------*/
38 #include <sys/types.h>
39 #include <sys/socket.h>
40 #include <netinet/in.h>
42 /*----- Data structures ---------------------------------------------------*/
44 /* --- An access control entry --- */
46 typedef struct acl_entry {
47 struct acl_entry *next; /* Next entry in the list */
48 const struct acl_ops *ops; /* Operations for the ACL entry */
49 unsigned act; /* What to do with matching hosts */
52 #define ACL_DENY 0 /* Deny access to matching conns */
53 #define ACL_ALLOW 1 /* Allow access to matching conns */
54 #define ACL_PERM 1u /* Bit mask for permission bit */
56 /* --- Host-based access control --- */
58 typedef struct acl_host {
59 acl_entry a; /* Base structure */
60 struct in_addr addr, mask; /* Address and netmask */
63 /* --- ACL methods --- */
65 typedef struct acl_ops {
66 int (*check)(void */*a*/, struct in_addr /*addr*/, unsigned /*port*/);
67 void (*dump)(void */*a*/, FILE */*fp*/);
68 void (*free)(void */*a*/);
71 /*----- Functions provided ------------------------------------------------*/
73 /* --- @acl_check@ --- *
75 * Arguments: @acl_entry *a@ = pointer to ACL to check against
76 * @struct in_addr addr@ = address to check
77 * @unsigned port@ = port number to check
78 * @int *act@ = verdict (should initially be @ACT_ALLOW@)
80 * Returns: Zero if undecided, nonzero if a rule matched.
82 * Use: Checks an address against an ACL.
85 extern int acl_check(acl_entry */*a*/,
86 struct in_addr /*addr*/, unsigned /*port*/,
89 /* --- @acl_dump@ --- *
91 * Arguments: @acl_entry *a@ = pointer to ACL to dump
92 * @FILE *fp@ = pointer to stream to dump on
96 * Use: Dumps an access control list to an output stream.
99 extern void acl_dump(acl_entry */*a*/, FILE */*fp*/);
101 /* --- @acl_free@ --- *
103 * Arguments: @acl_entry *a@ = pointer to a list of ACLs
107 * Use: Frees all of the memory used by an ACL.
110 extern void acl_free(acl_entry */*a*/);
112 /* --- @acl_addhost@ --- *
114 * Arguments: @acl_entry ***a@ = address of pointer to list tail
115 * @unsigned act@ = what to do with matching addresses
116 * @struct in_addr addr, mask@ = address and mask to match
120 * Use: Adds a host-authentication entry to the end of an access
124 extern void acl_addhost(acl_entry ***/*a*/, unsigned /*act*/,
125 struct in_addr /*addr*/, struct in_addr /*mask*/);
127 /* --- @acl_addpriv@ --- *
129 * Arguments: @acl_entry ***a@ = address of pointer to list tail
130 * @unsigned act@ = what to do with matching addresses
134 * Use: Adds a privileged-port check to the end of an access control
138 extern void acl_addpriv(acl_entry ***/*a*/, unsigned /*act*/);
140 /*----- That's all, folks -------------------------------------------------*/