acl.c revision ab023a65562e62b85a824509d829b6fad87e00b1
/*
* Copyright (C) 2004 Internet Systems Consortium, Inc. ("ISC")
* Copyright (C) 1999-2002 Internet Software Consortium.
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
* REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
* LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
* OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*/
/* $Id: acl.c,v 1.26 2005/04/27 04:56:44 sra Exp $ */
/*! \file */
#include <config.h>
/*
* Work around silly limitation of isc_mem_get().
*/
if (n == 0)
n = 1;
return (ISC_R_NOMEMORY);
/*
* Must set magic early because we use dns_acl_detach() to clean up.
*/
goto cleanup;
}
return (ISC_R_SUCCESS);
return (result);
}
/*
* Resize the ACL.
*/
unsigned int newalloc;
void *newmem;
if (newalloc < 4)
newalloc = 4;
newalloc * sizeof(dns_aclelement_t));
return (ISC_R_NOMEMORY);
}
/*
* Append the new element.
*/
return (ISC_R_SUCCESS);
}
static isc_result_t
if (result != ISC_R_SUCCESS)
return (result);
return (result);
}
}
}
int *match,
{
unsigned int i;
return (ISC_R_SUCCESS);
}
}
/* No match. */
*match = 0;
return (ISC_R_SUCCESS);
}
{
unsigned int i;
*matchelt = e;
return (ISC_R_SUCCESS);
}
}
return (ISC_R_NOTFOUND);
}
dns_aclelement_t *e,
{
int indirectmatch;
switch (e->type) {
else {
}
if (isc_netaddr_eqprefix(addr,
goto matched;
break;
goto matched;
break;
env,
/*
* Treat negative matches in indirect ACLs as
* "no match".
* That way, a negated indirect ACL will never become
* a surprise positive match through double negation.
* XXXDCL this should be documented.
*/
if (indirectmatch > 0)
goto matchelt_set;
/*
* A negative indirect match may have set *matchelt,
* but we don't want it set when we return.
*/
break;
case dns_aclelementtype_any:
*matchelt = e;
return (ISC_TRUE);
goto nested;
} else {
break;
}
goto nested;
} else {
break;
}
default:
INSIST(0);
break;
}
return (ISC_FALSE);
}
void
}
static void
unsigned int i;
break;
break;
default:
break;
}
}
}
void
unsigned int refs;
if (refs == 0)
}
return (ISC_FALSE);
return (ISC_FALSE);
case dns_aclelementtype_any:
return (ISC_TRUE);
default:
INSIST(0);
return (ISC_FALSE);
}
}
unsigned int i;
if (a == b)
return (ISC_TRUE);
return (ISC_FALSE);
for (i = 0; i < a->length; i++) {
if (! dns_aclelement_equal(&a->elements[i],
&b->elements[i]))
return (ISC_FALSE);
}
return (ISC_TRUE);
}
static isc_boolean_t
is_loopback(dns_aclipprefix_t *p) {
case AF_INET:
if (p->prefixlen == 32 &&
return (ISC_TRUE);
break;
case AF_INET6:
if (p->prefixlen == 128 &&
return (ISC_TRUE);
break;
default:
break;
}
return (ISC_FALSE);
}
dns_acl_isinsecure(dns_acl_t *a) {
unsigned int i;
for (i = 0; i < a->length; i++) {
dns_aclelement_t *e = &a->elements[i];
/* A negated match can never be insecure. */
if (e->negative)
continue;
switch (e->type) {
/* The loopback address is considered secure. */
if (! is_loopback(&e->u.ip_prefix))
return (ISC_TRUE);
continue;
continue;
if (dns_acl_isinsecure(e->u.nestedacl))
return (ISC_TRUE);
continue;
case dns_aclelementtype_any:
return (ISC_TRUE);
default:
INSIST(0);
return (ISC_TRUE);
}
}
/* No insecure elements were found. */
return (ISC_FALSE);
}
if (result != ISC_R_SUCCESS)
goto cleanup_nothing;
if (result != ISC_R_SUCCESS)
goto cleanup_localhost;
return (ISC_R_SUCCESS);
return (result);
}
void
dns_acl_detach(&t->localhost);
dns_acl_detach(&t->localnets);
t->match_mapped = s->match_mapped;
}
void
}