BIND - Update BIND to 9.5.2
[dragonfly.git] / contrib / bind-9.5.2 / lib / dns / include / dns / acl.h
1 /*
2  * Copyright (C) 2004-2007, 2009  Internet Systems Consortium, Inc. ("ISC")
3  * Copyright (C) 1999-2002  Internet Software Consortium.
4  *
5  * Permission to use, copy, modify, and/or distribute this software for any
6  * purpose with or without fee is hereby granted, provided that the above
7  * copyright notice and this permission notice appear in all copies.
8  *
9  * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
10  * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
11  * AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
12  * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
13  * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
14  * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15  * PERFORMANCE OF THIS SOFTWARE.
16  */
17
18 /* $Id: acl.h,v 1.31.2.2 2009/01/19 23:47:03 tbox Exp $ */
19
20 #ifndef DNS_ACL_H
21 #define DNS_ACL_H 1
22
23 /*****
24  ***** Module Info
25  *****/
26
27 /*! \file dns/acl.h
28  * \brief
29  * Address match list handling.
30  */
31
32 /***
33  *** Imports
34  ***/
35
36 #include <isc/lang.h>
37 #include <isc/magic.h>
38 #include <isc/netaddr.h>
39 #include <isc/refcount.h>
40
41 #include <dns/name.h>
42 #include <dns/types.h>
43 #include <dns/iptable.h>
44
45 /***
46  *** Types
47  ***/
48
49 typedef enum {
50         dns_aclelementtype_ipprefix,
51         dns_aclelementtype_keyname,
52         dns_aclelementtype_nestedacl,
53         dns_aclelementtype_localhost,
54         dns_aclelementtype_localnets,
55         dns_aclelementtype_any
56 } dns_aclelemettype_t;
57
58 typedef struct dns_aclipprefix dns_aclipprefix_t;
59
60 struct dns_aclipprefix {
61         isc_netaddr_t address; /* IP4/IP6 */
62         unsigned int prefixlen;
63 };
64
65 struct dns_aclelement {
66         dns_aclelemettype_t     type;
67         isc_boolean_t           negative;
68         dns_name_t              keyname;
69         dns_acl_t               *nestedacl;
70         int                     node_num;
71 };
72
73 struct dns_acl {
74         unsigned int            magic;
75         isc_mem_t               *mctx;
76         isc_refcount_t          refcount;
77         dns_iptable_t           *iptable;
78 #define node_count              iptable->radix->num_added_node
79         dns_aclelement_t        *elements;
80         isc_boolean_t           has_negatives;
81         unsigned int            alloc;          /*%< Elements allocated */
82         unsigned int            length;         /*%< Elements initialized */
83         char                    *name;          /*%< Temporary use only */
84         ISC_LINK(dns_acl_t)     nextincache;    /*%< Ditto */
85 };
86
87 struct dns_aclenv {
88         dns_acl_t *localhost;
89         dns_acl_t *localnets;
90         isc_boolean_t match_mapped;
91 };
92
93 #define DNS_ACL_MAGIC           ISC_MAGIC('D','a','c','l')
94 #define DNS_ACL_VALID(a)        ISC_MAGIC_VALID(a, DNS_ACL_MAGIC)
95
96 /***
97  *** Functions
98  ***/
99
100 ISC_LANG_BEGINDECLS
101
102 isc_result_t
103 dns_acl_create(isc_mem_t *mctx, int n, dns_acl_t **target);
104 /*%<
105  * Create a new ACL, including an IP table and an array with room
106  * for 'n' ACL elements.  The elements are uninitialized and the
107  * length is 0.
108  */
109
110 isc_result_t
111 dns_acl_any(isc_mem_t *mctx, dns_acl_t **target);
112 /*%<
113  * Create a new ACL that matches everything.
114  */
115
116 isc_result_t
117 dns_acl_none(isc_mem_t *mctx, dns_acl_t **target);
118 /*%<
119  * Create a new ACL that matches nothing.
120  */
121
122 isc_boolean_t
123 dns_acl_isany(dns_acl_t *acl);
124 /*%<
125  * Test whether ACL is set to "{ any; }"
126  */
127
128 isc_boolean_t
129 dns_acl_isnone(dns_acl_t *acl);
130 /*%<
131  * Test whether ACL is set to "{ none; }"
132  */
133
134 isc_result_t
135 dns_acl_merge(dns_acl_t *dest, dns_acl_t *source, isc_boolean_t pos);
136 /*%<
137  * Merge the contents of one ACL into another.  Call dns_iptable_merge()
138  * for the IP tables, then concatenate the element arrays.
139  *
140  * If pos is set to false, then the nested ACL is to be negated.  This
141  * means reverse the sense of each *positive* element or IP table node,
142  * but leave negatives alone, so as to prevent a double-negative causing
143  * an unexpected positive match in the parent ACL.
144  */
145
146 void
147 dns_acl_attach(dns_acl_t *source, dns_acl_t **target);
148
149 void
150 dns_acl_detach(dns_acl_t **aclp);
151
152 isc_boolean_t
153 dns_acl_isinsecure(const dns_acl_t *a);
154 /*%<
155  * Return #ISC_TRUE iff the acl 'a' is considered insecure, that is,
156  * if it contains IP addresses other than those of the local host.
157  * This is intended for applications such as printing warning
158  * messages for suspect ACLs; it is not intended for making access
159  * control decisions.  We make no guarantee that an ACL for which
160  * this function returns #ISC_FALSE is safe.
161  */
162
163 isc_result_t
164 dns_aclenv_init(isc_mem_t *mctx, dns_aclenv_t *env);
165 /*%<
166  * Initialize ACL environment, setting up localhost and localnets ACLs
167  */
168
169 void
170 dns_aclenv_copy(dns_aclenv_t *t, dns_aclenv_t *s);
171
172 void
173 dns_aclenv_destroy(dns_aclenv_t *env);
174
175 isc_result_t
176 dns_acl_match(const isc_netaddr_t *reqaddr,
177               const dns_name_t *reqsigner,
178               const dns_acl_t *acl,
179               const dns_aclenv_t *env,
180               int *match,
181               const dns_aclelement_t **matchelt);
182 /*%<
183  * General, low-level ACL matching.  This is expected to
184  * be useful even for weird stuff like the topology and sortlist statements.
185  *
186  * Match the address 'reqaddr', and optionally the key name 'reqsigner',
187  * against 'acl'.  'reqsigner' may be NULL.
188  *
189  * If there is a match, '*match' will be set to an integer whose absolute
190  * value corresponds to the order in which the matching value was inserted
191  * into the ACL.  For a positive match, this value will be positive; for a
192  * negative match, it will be negative.
193  *
194  * If there is no match, *match will be set to zero.
195  *
196  * If there is a match in the element list (either positive or negative)
197  * and 'matchelt' is non-NULL, *matchelt will be pointed to the matching
198  * element.
199  *
200  * Returns:
201  *\li   #ISC_R_SUCCESS          Always succeeds.
202  */
203
204 isc_boolean_t
205 dns_aclelement_match(const isc_netaddr_t *reqaddr,
206                      const dns_name_t *reqsigner,
207                      const dns_aclelement_t *e,
208                      const dns_aclenv_t *env,
209                      const dns_aclelement_t **matchelt);
210 /*%<
211  * Like dns_acl_match, but matches against the single ACL element 'e'
212  * rather than a complete ACL, and returns ISC_TRUE iff it matched.
213  *
214  * To determine whether the match was positive or negative, the
215  * caller should examine e->negative.  Since the element 'e' may be
216  * a reference to a named ACL or a nested ACL, a matching element
217  * returned through 'matchelt' is not necessarily 'e' itself.
218  */
219
220 ISC_LANG_ENDDECLS
221
222 #endif /* DNS_ACL_H */