acl.c revision 39bb14491fa6d55c83b0a61dc07bf7864a726323
7d32c065c7bb56f281651ae3dd2888f32ce4f1d9Bob Halley * Copyright (C) 1999-2001 Internet Software Consortium.
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley * Permission to use, copy, modify, and distribute this software for any
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley * purpose with or without fee is hereby granted, provided that the above
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley * copyright notice and this permission notice appear in all copies.
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley * INTERNET SOFTWARE CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT,
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley/* $Id: acl.c,v 1.19 2001/01/17 02:58:28 bwelling Exp $ */
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halleydns_acl_create(isc_mem_t *mctx, int n, dns_acl_t **target) {
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley * Work around silly limitation of isc_mem_get().
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley * Must set magic early because we use dns_acl_detach() to clean up.
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley acl->elements = isc_mem_get(mctx, n * sizeof(dns_aclelement_t));
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley memset(acl->elements, 0, n * sizeof(dns_aclelement_t));
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halleydns_acl_appendelement(dns_acl_t *acl, dns_aclelement_t *elt) {
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley * Resize the ACL.
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley unsigned int newalloc;
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley * Append the new element.
55254a46f91419b92eee0d20dfb958e8dd52526cBob Halleydns_acl_anyornone(isc_mem_t *mctx, isc_boolean_t neg, dns_acl_t **target) {
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halleydns_acl_any(isc_mem_t *mctx, dns_acl_t **target) {
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley return (dns_acl_anyornone(mctx, ISC_FALSE, target));
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halleydns_acl_none(isc_mem_t *mctx, dns_acl_t **target) {
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley return (dns_acl_anyornone(mctx, ISC_TRUE, target));
e0df061f35a26d2bbd0986aa889f88b3710b32d4Bob Halley /* No match. */
e0df061f35a26d2bbd0986aa889f88b3710b32d4Bob Halley switch (e->type) {
55254a46f91419b92eee0d20dfb958e8dd52526cBob Halley * Treat negative matches in indirect ACLs as
55254a46f91419b92eee0d20dfb958e8dd52526cBob Halley * "no match".
55254a46f91419b92eee0d20dfb958e8dd52526cBob Halley * That way, a negated indirect ACL will never become
55254a46f91419b92eee0d20dfb958e8dd52526cBob Halley * a surprise positive match through double negation.
55254a46f91419b92eee0d20dfb958e8dd52526cBob Halley * XXXDCL this should be documented.
55254a46f91419b92eee0d20dfb958e8dd52526cBob Halley * A negative indirect match may have set *matchelt,
55254a46f91419b92eee0d20dfb958e8dd52526cBob Halley * but we don't want it set when we return.
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halleydns_acl_attach(dns_acl_t *source, dns_acl_t **target) {
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley unsigned int i;
6e49e91bd08778d7eae45a2229dcf41ed97cc636David Lawrencedns_aclelement_equal(dns_aclelement_t *ea, dns_aclelement_t *eb) {
948eabe2a254a8a278ef6325f3790e75329ee656Bob Halley return (isc_netaddr_equal(&ea->u.ip_prefix.address,
948eabe2a254a8a278ef6325f3790e75329ee656Bob Halley return (dns_name_equal(&ea->u.keyname, &eb->u.keyname));
6e49e91bd08778d7eae45a2229dcf41ed97cc636David Lawrence return (dns_acl_equal(ea->u.nestedacl, eb->u.nestedacl));
948eabe2a254a8a278ef6325f3790e75329ee656Bob Halley unsigned int i;
948eabe2a254a8a278ef6325f3790e75329ee656Bob Halley for (i = 0; i < a->length; i++) {
948eabe2a254a8a278ef6325f3790e75329ee656Bob Halley#define INADDR_LOOPBACK (unsigned long)0x7F000001UL
948eabe2a254a8a278ef6325f3790e75329ee656Bob Halley htonl(p->address.type.in.s_addr) == INADDR_LOOPBACK)
948eabe2a254a8a278ef6325f3790e75329ee656Bob Halley unsigned int i;
948eabe2a254a8a278ef6325f3790e75329ee656Bob Halley for (i = 0; i < a->length; i++) {
948eabe2a254a8a278ef6325f3790e75329ee656Bob Halley /* A negated match can never be insecure. */
948eabe2a254a8a278ef6325f3790e75329ee656Bob Halley switch (e->type) {
948eabe2a254a8a278ef6325f3790e75329ee656Bob Halley /* The loopback address is considered secure. */
948eabe2a254a8a278ef6325f3790e75329ee656Bob Halley /* No insecure elements were found. */
goto cleanup_nothing;
goto cleanup_localhost;
return (ISC_R_SUCCESS);
return (result);