ssu.c revision dafcb997e390efa4423883dafd100c975c4095d6
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * Copyright (C) 2004 Internet Systems Consortium, Inc. ("ISC")
ec5347e2c775f027573ce5648b910361aa926c01Automatic Updater * Copyright (C) 2000, 2001, 2003 Internet Software Consortium.
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * Permission to use, copy, modify, and distribute this software for any
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * purpose with or without fee is hereby granted, provided that the above
ec5347e2c775f027573ce5648b910361aa926c01Automatic Updater * copyright notice and this permission notice appear in all copies.
1d92d8a2456b23842a649b6104c60a9d6ea25333Brian Wellington * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
271c4c7ffafeb0bda21278af6cac4535c0193f18Automatic Updater * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
1d92d8a2456b23842a649b6104c60a9d6ea25333Brian Wellington * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
1d92d8a2456b23842a649b6104c60a9d6ea25333Brian Wellington * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
1d92d8a2456b23842a649b6104c60a9d6ea25333Brian Wellington * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * PERFORMANCE OF THIS SOFTWARE.
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * $Id: ssu.c,v 1.24 2004/03/05 05:09:25 marka Exp $
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * Principal Author: Brian Wellington
1d92d8a2456b23842a649b6104c60a9d6ea25333Brian Wellington#include <isc/string.h> /* Required for HP/UX (and others?) */
92ef1a9b9dbd48ecb507b42ac62c15afefdaf838David Lawrence#define SSUTABLEMAGIC ISC_MAGIC('S', 'S', 'U', 'T')
7de2c6e6d51f38daeb2d346f3f21dc01ccece6daEvan Hunt#define VALID_SSUTABLE(table) ISC_MAGIC_VALID(table, SSUTABLEMAGIC)
1d92d8a2456b23842a649b6104c60a9d6ea25333Brian Wellington#define SSURULEMAGIC ISC_MAGIC('S', 'S', 'U', 'R')
1d92d8a2456b23842a649b6104c60a9d6ea25333Brian Wellington#define VALID_SSURULE(table) ISC_MAGIC_VALID(table, SSURULEMAGIC)
1d92d8a2456b23842a649b6104c60a9d6ea25333Brian Wellington isc_boolean_t grant; /* is this a grant or a deny? */
1d92d8a2456b23842a649b6104c60a9d6ea25333Brian Wellington unsigned int matchtype; /* which type of pattern match? */
1d92d8a2456b23842a649b6104c60a9d6ea25333Brian Wellington dns_name_t *identity; /* the identity to match */
1d92d8a2456b23842a649b6104c60a9d6ea25333Brian Wellington dns_name_t *name; /* the name being updated */
1d92d8a2456b23842a649b6104c60a9d6ea25333Brian Wellington unsigned int ntypes; /* number of data types covered */
1d92d8a2456b23842a649b6104c60a9d6ea25333Brian Wellington dns_rdatatype_t *types; /* the data types. Can include ANY, */
1d92d8a2456b23842a649b6104c60a9d6ea25333Brian Wellington /* defaults to all but SIG,SOA,NS if NULL*/
1d92d8a2456b23842a649b6104c60a9d6ea25333Brian Wellingtondns_ssutable_create(isc_mem_t *mctx, dns_ssutable_t **tablep) {
1d92d8a2456b23842a649b6104c60a9d6ea25333Brian Wellington REQUIRE(tablep != NULL && *tablep == NULL);
1d92d8a2456b23842a649b6104c60a9d6ea25333Brian Wellington table = isc_mem_get(mctx, sizeof(dns_ssutable_t));
1d92d8a2456b23842a649b6104c60a9d6ea25333Brian Wellington isc_mem_put(mctx, table, sizeof(dns_ssutable_t));
1d92d8a2456b23842a649b6104c60a9d6ea25333Brian Wellingtonstatic inline void
1d92d8a2456b23842a649b6104c60a9d6ea25333Brian Wellington dns_ssurule_t *rule = ISC_LIST_HEAD(table->rules);
1d92d8a2456b23842a649b6104c60a9d6ea25333Brian Wellington isc_mem_put(mctx, rule->identity, sizeof(dns_name_t));
1d92d8a2456b23842a649b6104c60a9d6ea25333Brian Wellington isc_mem_put(mctx, rule->name, sizeof(dns_name_t));
1d92d8a2456b23842a649b6104c60a9d6ea25333Brian Wellington isc_mem_put(mctx, rule, sizeof(dns_ssurule_t));
1d92d8a2456b23842a649b6104c60a9d6ea25333Brian Wellington isc_mem_put(mctx, table, sizeof(dns_ssutable_t));
1d92d8a2456b23842a649b6104c60a9d6ea25333Brian Wellingtondns_ssutable_attach(dns_ssutable_t *source, dns_ssutable_t **targetp) {
1d92d8a2456b23842a649b6104c60a9d6ea25333Brian Wellington REQUIRE(targetp != NULL && *targetp == NULL);
1d92d8a2456b23842a649b6104c60a9d6ea25333Brian Wellingtondns_ssutable_detach(dns_ssutable_t **tablep) {
1d92d8a2456b23842a649b6104c60a9d6ea25333Brian Wellingtondns_ssutable_addrule(dns_ssutable_t *table, isc_boolean_t grant,
1d92d8a2456b23842a649b6104c60a9d6ea25333Brian Wellington dns_name_t *identity, unsigned int matchtype,
1d92d8a2456b23842a649b6104c60a9d6ea25333Brian Wellington REQUIRE(matchtype <= DNS_SSUMATCHTYPE_SELF);
1d92d8a2456b23842a649b6104c60a9d6ea25333Brian Wellington if (matchtype == DNS_SSUMATCHTYPE_WILDCARD)
1d92d8a2456b23842a649b6104c60a9d6ea25333Brian Wellington rule = isc_mem_get(mctx, sizeof(dns_ssurule_t));
1d92d8a2456b23842a649b6104c60a9d6ea25333Brian Wellington rule->identity = isc_mem_get(mctx, sizeof(dns_name_t));
1d92d8a2456b23842a649b6104c60a9d6ea25333Brian Wellington result = dns_name_dup(identity, mctx, rule->identity);
1d92d8a2456b23842a649b6104c60a9d6ea25333Brian Wellington rule->name = isc_mem_get(mctx, sizeof(dns_name_t));
1d92d8a2456b23842a649b6104c60a9d6ea25333Brian Wellington result = dns_name_dup(name, mctx, rule->name);
1d92d8a2456b23842a649b6104c60a9d6ea25333Brian Wellington memcpy(rule->types, types, ntypes * sizeof(dns_rdatatype_t));
1d92d8a2456b23842a649b6104c60a9d6ea25333Brian Wellington ISC_LIST_INITANDAPPEND(table->rules, rule, link);
1d92d8a2456b23842a649b6104c60a9d6ea25333Brian Wellington isc_mem_put(mctx, rule->identity, sizeof(dns_name_t));
91cd0f93ad34d23e8b09dca337120f64fbe8f0a1Andreas Gustafsson isc_mem_put(mctx, rule->name, sizeof(dns_name_t));
1d92d8a2456b23842a649b6104c60a9d6ea25333Brian Wellington isc_mem_put(mctx, rule, sizeof(dns_ssurule_t));
1d92d8a2456b23842a649b6104c60a9d6ea25333Brian Wellingtondns_ssutable_checkrules(dns_ssutable_t *table, dns_name_t *signer,
1d92d8a2456b23842a649b6104c60a9d6ea25333Brian Wellington unsigned int i;
1d92d8a2456b23842a649b6104c60a9d6ea25333Brian Wellington REQUIRE(signer == NULL || dns_name_isabsolute(signer));
1d92d8a2456b23842a649b6104c60a9d6ea25333Brian Wellington if (!dns_name_matcheswildcard(signer, rule->identity))
1d92d8a2456b23842a649b6104c60a9d6ea25333Brian Wellington if (!dns_name_equal(signer, rule->identity))
1d92d8a2456b23842a649b6104c60a9d6ea25333Brian Wellington if (rule->matchtype == DNS_SSUMATCHTYPE_NAME) {
1d92d8a2456b23842a649b6104c60a9d6ea25333Brian Wellington else if (rule->matchtype == DNS_SSUMATCHTYPE_SUBDOMAIN) {
1d92d8a2456b23842a649b6104c60a9d6ea25333Brian Wellington if (!dns_name_issubdomain(name, rule->name))
1d92d8a2456b23842a649b6104c60a9d6ea25333Brian Wellington else if (rule->matchtype == DNS_SSUMATCHTYPE_WILDCARD) {
1d92d8a2456b23842a649b6104c60a9d6ea25333Brian Wellington if (!dns_name_matcheswildcard(name, rule->name))
return (ISC_FALSE);