ssu.c revision 28fc90e6c81338c5f34e065fdda49d320e362583
499b34cea04a46823d003d4c0520c8b03e8513cbBrian Wellington * Copyright (C) 2000, 2001 Internet Software Consortium.
dda4bfe6499d09ea8123447579e56069d8176fcbBob Halley * Permission to use, copy, modify, and distribute this software for any
dda4bfe6499d09ea8123447579e56069d8176fcbBob Halley * purpose with or without fee is hereby granted, provided that the above
dda4bfe6499d09ea8123447579e56069d8176fcbBob Halley * copyright notice and this permission notice appear in all copies.
15a44745412679c30a6d022733925af70a38b715David Lawrence * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM
15a44745412679c30a6d022733925af70a38b715David Lawrence * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
15a44745412679c30a6d022733925af70a38b715David Lawrence * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
15a44745412679c30a6d022733925af70a38b715David Lawrence * INTERNET SOFTWARE CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT,
15a44745412679c30a6d022733925af70a38b715David Lawrence * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
15a44745412679c30a6d022733925af70a38b715David Lawrence * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
15a44745412679c30a6d022733925af70a38b715David Lawrence * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
15a44745412679c30a6d022733925af70a38b715David Lawrence * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
28fc90e6c81338c5f34e065fdda49d320e362583Mark Andrews * $Id: ssu.c,v 1.22 2001/08/28 03:58:08 marka Exp $
01d202be8fb07c010388eada31635e40ae3bffe5Brian Wellington * Principal Author: Brian Wellington
6028d1ce0380d0ba7f6c6ecd1ad20b31ddd1becbDavid Lawrence#include <isc/string.h> /* Required for HP/UX (and others?) */
92ef1a9b9dbd48ecb507b42ac62c15afefdaf838David Lawrence#define SSUTABLEMAGIC ISC_MAGIC('S', 'S', 'U', 'T')
92ef1a9b9dbd48ecb507b42ac62c15afefdaf838David Lawrence#define VALID_SSUTABLE(table) ISC_MAGIC_VALID(table, SSUTABLEMAGIC)
92ef1a9b9dbd48ecb507b42ac62c15afefdaf838David Lawrence#define SSURULEMAGIC ISC_MAGIC('S', 'S', 'U', 'R')
92ef1a9b9dbd48ecb507b42ac62c15afefdaf838David Lawrence#define VALID_SSURULE(table) ISC_MAGIC_VALID(table, SSURULEMAGIC)
28fc90e6c81338c5f34e065fdda49d320e362583Mark Andrews unsigned int magic;
01d202be8fb07c010388eada31635e40ae3bffe5Brian Wellington isc_boolean_t grant; /* is this a grant or a deny? */
2fabf91e5bfc718f274e19c5fa8844fdae90ae41Brian Wellington unsigned int matchtype; /* which type of pattern match? */
7dc1fe241043e47a6721fd841e2c52d3691379ebBrian Wellington dns_name_t *identity; /* the identity to match */
7dc1fe241043e47a6721fd841e2c52d3691379ebBrian Wellington dns_name_t *name; /* the name being updated */
01d202be8fb07c010388eada31635e40ae3bffe5Brian Wellington unsigned int ntypes; /* number of data types covered */
01d202be8fb07c010388eada31635e40ae3bffe5Brian Wellington dns_rdatatype_t *types; /* the data types. Can include ANY, */
01d202be8fb07c010388eada31635e40ae3bffe5Brian Wellington /* defaults to all but SIG,SOA,NS if NULL*/
28fc90e6c81338c5f34e065fdda49d320e362583Mark Andrews unsigned int magic;
6fcfd0c35d3fd6aea3d36ad002b68e59ac62fdc7Brian Wellingtondns_ssutable_create(isc_mem_t *mctx, dns_ssutable_t **tablep) {
6fcfd0c35d3fd6aea3d36ad002b68e59ac62fdc7Brian Wellington REQUIRE(tablep != NULL && *tablep == NULL);
6fcfd0c35d3fd6aea3d36ad002b68e59ac62fdc7Brian Wellington table = isc_mem_get(mctx, sizeof(dns_ssutable_t));
6fcfd0c35d3fd6aea3d36ad002b68e59ac62fdc7Brian Wellington isc_mem_put(mctx, table, sizeof(dns_ssutable_t));
6fcfd0c35d3fd6aea3d36ad002b68e59ac62fdc7Brian Wellingtonstatic inline void
6fcfd0c35d3fd6aea3d36ad002b68e59ac62fdc7Brian Wellington dns_ssurule_t *rule = ISC_LIST_HEAD(table->rules);
01d202be8fb07c010388eada31635e40ae3bffe5Brian Wellington isc_mem_put(mctx, rule->identity, sizeof(dns_name_t));
01d202be8fb07c010388eada31635e40ae3bffe5Brian Wellington isc_mem_put(mctx, rule->name, sizeof(dns_name_t));
01d202be8fb07c010388eada31635e40ae3bffe5Brian Wellington isc_mem_put(mctx, rule, sizeof(dns_ssurule_t));
6fcfd0c35d3fd6aea3d36ad002b68e59ac62fdc7Brian Wellington isc_mem_put(mctx, table, sizeof(dns_ssutable_t));
6fcfd0c35d3fd6aea3d36ad002b68e59ac62fdc7Brian Wellingtondns_ssutable_attach(dns_ssutable_t *source, dns_ssutable_t **targetp) {
6fcfd0c35d3fd6aea3d36ad002b68e59ac62fdc7Brian Wellington REQUIRE(targetp != NULL && *targetp == NULL);
6fcfd0c35d3fd6aea3d36ad002b68e59ac62fdc7Brian Wellingtondns_ssutable_detach(dns_ssutable_t **tablep) {
01d202be8fb07c010388eada31635e40ae3bffe5Brian Wellingtondns_ssutable_addrule(dns_ssutable_t *table, isc_boolean_t grant,
7dc1fe241043e47a6721fd841e2c52d3691379ebBrian Wellington dns_name_t *identity, unsigned int matchtype,
7dc1fe241043e47a6721fd841e2c52d3691379ebBrian Wellington REQUIRE(matchtype <= DNS_SSUMATCHTYPE_SELF);
7dc1fe241043e47a6721fd841e2c52d3691379ebBrian Wellington if (matchtype == DNS_SSUMATCHTYPE_WILDCARD)
01d202be8fb07c010388eada31635e40ae3bffe5Brian Wellington rule = isc_mem_get(mctx, sizeof(dns_ssurule_t));
7dc1fe241043e47a6721fd841e2c52d3691379ebBrian Wellington rule->identity = isc_mem_get(mctx, sizeof(dns_name_t));
7dc1fe241043e47a6721fd841e2c52d3691379ebBrian Wellington result = dns_name_dup(identity, mctx, rule->identity);
7dc1fe241043e47a6721fd841e2c52d3691379ebBrian Wellington rule->name = isc_mem_get(mctx, sizeof(dns_name_t));
7dc1fe241043e47a6721fd841e2c52d3691379ebBrian Wellington result = dns_name_dup(name, mctx, rule->name);
01d202be8fb07c010388eada31635e40ae3bffe5Brian Wellington memcpy(rule->types, types, ntypes * sizeof(dns_rdatatype_t));
6fda1577669dca9e0d8e4832e407bac34cc12de6Mark Andrews ISC_LIST_INITANDAPPEND(table->rules, rule, link);
01d202be8fb07c010388eada31635e40ae3bffe5Brian Wellington isc_mem_put(mctx, rule->identity, sizeof(dns_name_t));
01d202be8fb07c010388eada31635e40ae3bffe5Brian Wellington isc_mem_put(mctx, rule->name, sizeof(dns_name_t));
01d202be8fb07c010388eada31635e40ae3bffe5Brian Wellington isc_mem_put(mctx, rule, sizeof(dns_ssurule_t));
01d202be8fb07c010388eada31635e40ae3bffe5Brian Wellingtondns_ssutable_checkrules(dns_ssutable_t *table, dns_name_t *signer,
01d202be8fb07c010388eada31635e40ae3bffe5Brian Wellington unsigned int i;
01d202be8fb07c010388eada31635e40ae3bffe5Brian Wellington REQUIRE(signer == NULL || dns_name_isabsolute(signer));
7dc1fe241043e47a6721fd841e2c52d3691379ebBrian Wellington if (!dns_name_matcheswildcard(signer, rule->identity))
7dc1fe241043e47a6721fd841e2c52d3691379ebBrian Wellington if (!dns_name_equal(signer, rule->identity))
7dc1fe241043e47a6721fd841e2c52d3691379ebBrian Wellington if (rule->matchtype == DNS_SSUMATCHTYPE_NAME) {
7dc1fe241043e47a6721fd841e2c52d3691379ebBrian Wellington else if (rule->matchtype == DNS_SSUMATCHTYPE_SUBDOMAIN) {
7dc1fe241043e47a6721fd841e2c52d3691379ebBrian Wellington if (!dns_name_issubdomain(name, rule->name))
7dc1fe241043e47a6721fd841e2c52d3691379ebBrian Wellington else if (rule->matchtype == DNS_SSUMATCHTYPE_WILDCARD) {
7dc1fe241043e47a6721fd841e2c52d3691379ebBrian Wellington if (!dns_name_matcheswildcard(name, rule->name))
7dc1fe241043e47a6721fd841e2c52d3691379ebBrian Wellington else if (rule->matchtype == DNS_SSUMATCHTYPE_SELF) {
2fabf91e5bfc718f274e19c5fa8844fdae90ae41Brian Wellingtondns_ssurule_isgrant(const dns_ssurule_t *rule) {
2fabf91e5bfc718f274e19c5fa8844fdae90ae41Brian Wellingtondns_ssurule_identity(const dns_ssurule_t *rule) {
2fabf91e5bfc718f274e19c5fa8844fdae90ae41Brian Wellingtondns_ssurule_matchtype(const dns_ssurule_t *rule) {
2fabf91e5bfc718f274e19c5fa8844fdae90ae41Brian Wellingtondns_ssurule_name(const dns_ssurule_t *rule) {
2fabf91e5bfc718f274e19c5fa8844fdae90ae41Brian Wellingtondns_ssurule_types(const dns_ssurule_t *rule, dns_rdatatype_t **types) {
2fabf91e5bfc718f274e19c5fa8844fdae90ae41Brian Wellingtondns_ssutable_firstrule(const dns_ssutable_t *table, dns_ssurule_t **rule) {
2fabf91e5bfc718f274e19c5fa8844fdae90ae41Brian Wellington return (*rule != NULL ? ISC_R_SUCCESS : ISC_R_NOMORE);
2fabf91e5bfc718f274e19c5fa8844fdae90ae41Brian Wellingtondns_ssutable_nextrule(dns_ssurule_t *rule, dns_ssurule_t **nextrule) {
dc1961d96f9d116f77e0ac5e4a0b2bb5bb40328eJames Brister REQUIRE(nextrule != NULL && *nextrule == NULL);