acl.c revision a1747570262ed336c213aaf6bd31bc91993a46de
7d32c065c7bb56f281651ae3dd2888f32ce4f1d9Bob Halley * Copyright (C) 1999, 2000 Internet Software Consortium.
6017f424ee3c02d7f22132c77576ea38542fa949Andreas Gustafsson * Permission to use, copy, modify, and distribute this software for any
6017f424ee3c02d7f22132c77576ea38542fa949Andreas Gustafsson * purpose with or without fee is hereby granted, provided that the above
6017f424ee3c02d7f22132c77576ea38542fa949Andreas Gustafsson * copyright notice and this permission notice appear in all copies.
6017f424ee3c02d7f22132c77576ea38542fa949Andreas Gustafsson * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
6017f424ee3c02d7f22132c77576ea38542fa949Andreas Gustafsson * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
6017f424ee3c02d7f22132c77576ea38542fa949Andreas Gustafsson * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
6017f424ee3c02d7f22132c77576ea38542fa949Andreas Gustafsson * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
6017f424ee3c02d7f22132c77576ea38542fa949Andreas Gustafsson * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
6017f424ee3c02d7f22132c77576ea38542fa949Andreas Gustafsson * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
6017f424ee3c02d7f22132c77576ea38542fa949Andreas Gustafsson * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
7693d4de8fca501dfe6989a7f30d8d3c86fe096aAndreas Gustafssondns_acl_create(isc_mem_t *mctx, int n, dns_acl_t **target)
a1747570262ed336c213aaf6bd31bc91993a46deAndreas Gustafsson * Work around silly limitation of isc_mem_get().
7693d4de8fca501dfe6989a7f30d8d3c86fe096aAndreas Gustafsson /* Must set magic early because we use dns_acl_detach() to clean up. */
7693d4de8fca501dfe6989a7f30d8d3c86fe096aAndreas Gustafsson acl->elements = isc_mem_get(mctx, n * sizeof(dns_aclelement_t));
7693d4de8fca501dfe6989a7f30d8d3c86fe096aAndreas Gustafsson memset(acl->elements, 0, n * sizeof(dns_aclelement_t));
a1747570262ed336c213aaf6bd31bc91993a46deAndreas Gustafssondns_acl_appendelement(dns_acl_t *acl, dns_aclelement_t *elt)
a1747570262ed336c213aaf6bd31bc91993a46deAndreas Gustafsson * Resize the ACL.
a1747570262ed336c213aaf6bd31bc91993a46deAndreas Gustafsson * Append the new element.
7693d4de8fca501dfe6989a7f30d8d3c86fe096aAndreas Gustafssondns_acl_anyornone(isc_mem_t *mctx, isc_boolean_t neg, dns_acl_t **target)
7693d4de8fca501dfe6989a7f30d8d3c86fe096aAndreas Gustafsson acl->elements[0].type = dns_aclelementtype_any;
7693d4de8fca501dfe6989a7f30d8d3c86fe096aAndreas Gustafssondns_acl_any(isc_mem_t *mctx, dns_acl_t **target) {
7693d4de8fca501dfe6989a7f30d8d3c86fe096aAndreas Gustafsson return (dns_acl_anyornone(mctx, ISC_FALSE, target));
7693d4de8fca501dfe6989a7f30d8d3c86fe096aAndreas Gustafssondns_acl_none(isc_mem_t *mctx, dns_acl_t **target) {
7693d4de8fca501dfe6989a7f30d8d3c86fe096aAndreas Gustafsson return (dns_acl_anyornone(mctx, ISC_TRUE, target));
6017f424ee3c02d7f22132c77576ea38542fa949Andreas Gustafssondns_acl_checkrequest(dns_name_t *signer, isc_sockaddr_t *reqaddr,
a1747570262ed336c213aaf6bd31bc91993a46deAndreas Gustafsson result = dns_acl_match(reqaddr, signer, acl, env,
6017f424ee3c02d7f22132c77576ea38542fa949Andreas Gustafsson goto deny; /* Internal error, already logged. */
6017f424ee3c02d7f22132c77576ea38542fa949Andreas Gustafsson goto deny; /* Negative match or no match. */
6017f424ee3c02d7f22132c77576ea38542fa949Andreas Gustafsson isc_log_write(dns_lctx, DNS_LOGCATEGORY_SECURITY,
6017f424ee3c02d7f22132c77576ea38542fa949Andreas Gustafsson isc_log_write(dns_lctx, DNS_LOGCATEGORY_SECURITY,
6017f424ee3c02d7f22132c77576ea38542fa949Andreas Gustafsson unsigned int i;
6017f424ee3c02d7f22132c77576ea38542fa949Andreas Gustafsson REQUIRE(matchelt == NULL || *matchelt == NULL);
6017f424ee3c02d7f22132c77576ea38542fa949Andreas Gustafsson dns_name_equal(reqsigner, &e->u.keyname))
6017f424ee3c02d7f22132c77576ea38542fa949Andreas Gustafsson result = dns_acl_match(reqaddr, reqsigner,
6017f424ee3c02d7f22132c77576ea38542fa949Andreas Gustafsson * Treat negative matches in indirect ACLs as
6017f424ee3c02d7f22132c77576ea38542fa949Andreas Gustafsson * That way, a negated indirect ACL will never become
6017f424ee3c02d7f22132c77576ea38542fa949Andreas Gustafsson * a surprise positive match through double negation.
6017f424ee3c02d7f22132c77576ea38542fa949Andreas Gustafsson * A negative indirect match may have set *matchelt,
6017f424ee3c02d7f22132c77576ea38542fa949Andreas Gustafsson * but we don't want it set when we return.
a1747570262ed336c213aaf6bd31bc91993a46deAndreas Gustafsson if (env != NULL && env->localhost != NULL) {
a1747570262ed336c213aaf6bd31bc91993a46deAndreas Gustafsson if (env != NULL && env->localnets != NULL) {
6017f424ee3c02d7f22132c77576ea38542fa949Andreas Gustafsson /* No match. */
6017f424ee3c02d7f22132c77576ea38542fa949Andreas Gustafssondns_acl_attach(dns_acl_t *source, dns_acl_t **target)
6017f424ee3c02d7f22132c77576ea38542fa949Andreas Gustafsson unsigned int i;
6017f424ee3c02d7f22132c77576ea38542fa949Andreas Gustafsson dns_aclelement_t *de = &dacl->elements[i];
6017f424ee3c02d7f22132c77576ea38542fa949Andreas Gustafsson dns_name_free(&de->u.keyname, dacl->mctx);
6017f424ee3c02d7f22132c77576ea38542fa949Andreas Gustafsson isc_mem_put(dacl->mctx, dacl, sizeof(*dacl));
6017f424ee3c02d7f22132c77576ea38542fa949Andreas Gustafssondns_aclelement_equal(dns_aclelement_t *ea, dns_aclelement_t *eb)
6017f424ee3c02d7f22132c77576ea38542fa949Andreas Gustafsson return (isc_sockaddr_equal(&ea->u.ip_prefix.address,
6017f424ee3c02d7f22132c77576ea38542fa949Andreas Gustafsson return (dns_name_equal(&ea->u.keyname, &eb->u.keyname));
6017f424ee3c02d7f22132c77576ea38542fa949Andreas Gustafsson return (dns_acl_equal(ea->u.nestedacl, eb->u.nestedacl));
6017f424ee3c02d7f22132c77576ea38542fa949Andreas Gustafssondns_acl_equal(dns_acl_t *a, dns_acl_t *b) {
6017f424ee3c02d7f22132c77576ea38542fa949Andreas Gustafsson unsigned int i;
6017f424ee3c02d7f22132c77576ea38542fa949Andreas Gustafsson for (i = 0; i < a->length; i++) {
6017f424ee3c02d7f22132c77576ea38542fa949Andreas Gustafsson if (! dns_aclelement_equal(&a->elements[i],
a1747570262ed336c213aaf6bd31bc91993a46deAndreas Gustafssondns_aclenv_init(isc_mem_t *mctx, dns_aclenv_t *env)
a1747570262ed336c213aaf6bd31bc91993a46deAndreas Gustafsson result = dns_acl_create(mctx, 0, &env->localhost);
a1747570262ed336c213aaf6bd31bc91993a46deAndreas Gustafsson result = dns_acl_create(mctx, 0, &env->localnets);
a1747570262ed336c213aaf6bd31bc91993a46deAndreas Gustafssonvoid dns_aclenv_copy(dns_aclenv_t *t, dns_aclenv_t *s) {
a1747570262ed336c213aaf6bd31bc91993a46deAndreas Gustafsson dns_acl_attach(s->localhost, &t->localhost);
a1747570262ed336c213aaf6bd31bc91993a46deAndreas Gustafsson dns_acl_attach(s->localnets, &t->localnets);