ssu.c revision 92ef1a9b9dbd48ecb507b42ac62c15afefdaf838
279c6ec074be17dce62dd1b2c6ed7c2cc56a7b78David Lawrence * Copyright (C) 2000, 2001 Internet Software Consortium.
281bfa2a98f1d1721538086e1b550185559f1d8bMark Andrews * Permission to use, copy, modify, and distribute this software for any
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence * purpose with or without fee is hereby granted, provided that the above
7de2c6e6d51f38daeb2d346f3f21dc01ccece6daEvan Hunt * copyright notice and this permission notice appear in all copies.
279c6ec074be17dce62dd1b2c6ed7c2cc56a7b78David Lawrence * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
281bfa2a98f1d1721538086e1b550185559f1d8bMark Andrews * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
281bfa2a98f1d1721538086e1b550185559f1d8bMark Andrews * INTERNET SOFTWARE CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT,
281bfa2a98f1d1721538086e1b550185559f1d8bMark Andrews * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
281bfa2a98f1d1721538086e1b550185559f1d8bMark Andrews * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
281bfa2a98f1d1721538086e1b550185559f1d8bMark Andrews * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
281bfa2a98f1d1721538086e1b550185559f1d8bMark Andrews * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
588f79e557cd66ef77c90378a997b0d377af9db7Tatuya JINMEI 神明達哉 * $Id: ssu.c,v 1.21 2001/06/04 19:33:11 tale Exp $
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * Principal Author: Brian Wellington
a5d43b72413db3edd6b36a58f9bdf2cf6ff692f2Bob Halley#include <isc/string.h> /* Required for HP/UX (and others?) */
8d4257cff01b3821abcb9a21f46c6c6a43bb1e72Bob Halley#define SSUTABLEMAGIC ISC_MAGIC('S', 'S', 'U', 'T')
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein#define VALID_SSUTABLE(table) ISC_MAGIC_VALID(table, SSUTABLEMAGIC)
8d4257cff01b3821abcb9a21f46c6c6a43bb1e72Bob Halley#define SSURULEMAGIC ISC_MAGIC('S', 'S', 'U', 'R')
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein#define VALID_SSURULE(table) ISC_MAGIC_VALID(table, SSURULEMAGIC)
8d4257cff01b3821abcb9a21f46c6c6a43bb1e72Bob Halley isc_boolean_t grant; /* is this a grant or a deny? */
8d4257cff01b3821abcb9a21f46c6c6a43bb1e72Bob Halley unsigned int matchtype; /* which type of pattern match? */
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein dns_name_t *identity; /* the identity to match */
50453ad879d0d93854de5a3385776bd799e8f35cBob Halley unsigned int ntypes; /* number of data types covered */
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein dns_rdatatype_t *types; /* the data types. Can include ANY, */
7005cfed8cd3296d356883dcb414979f22e06b13Brian Wellington /* defaults to all but SIG,SOA,NS if NULL*/
d8dcd6ad4617cc8d7df979bd62101fa9c4bac1bcBob Halley unsigned int references;
a30e7fc23415fd238d067a8a871607bca36068baMichael Graffdns_ssutable_create(isc_mem_t *mctx, dns_ssutable_t **tablep) {
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein table = isc_mem_get(mctx, sizeof(dns_ssutable_t));
703e1c0bb66f3cd3d300358ca0c1fdf3cb5fb1c5Brian Wellington isc_mem_put(mctx, table, sizeof(dns_ssutable_t));
4108eed5092156cf0407a97a9bd8ab7775164694Brian Wellingtonstatic inline void
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein dns_ssurule_t *rule = ISC_LIST_HEAD(table->rules);
876753d5ce1be48f3218fb4875fac501f8adfd6cDavid Lawrence isc_mem_put(mctx, rule->identity, sizeof(dns_name_t));
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein isc_mem_put(mctx, rule->name, sizeof(dns_name_t));
49a2cf8f211213712d452287ae8e121cf59e3178David Lawrence isc_mem_put(mctx, rule, sizeof(dns_ssurule_t));
49a2cf8f211213712d452287ae8e121cf59e3178David Lawrence isc_mem_put(mctx, table, sizeof(dns_ssutable_t));
49a2cf8f211213712d452287ae8e121cf59e3178David Lawrencedns_ssutable_attach(dns_ssutable_t *source, dns_ssutable_t **targetp) {
2b66a51a7d72e9cc07917fb583ad528b0539d2a3Mark Andrewsdns_ssutable_addrule(dns_ssutable_t *table, isc_boolean_t grant,
64b92523f9333ba053f4b2860335583be455b0b3Brian Wellington if (matchtype == DNS_SSUMATCHTYPE_WILDCARD)
289ae548d52bc8f982d9823af64cafda7bd92232Mark Andrews rule = isc_mem_get(mctx, sizeof(dns_ssurule_t));
f54d0c9c6e65de367d4ef08f51d22a2fb4c56208Mark Andrews rule->identity = isc_mem_get(mctx, sizeof(dns_name_t));
f54d0c9c6e65de367d4ef08f51d22a2fb4c56208Mark Andrews result = dns_name_dup(identity, mctx, rule->identity);
f54d0c9c6e65de367d4ef08f51d22a2fb4c56208Mark Andrews rule->name = isc_mem_get(mctx, sizeof(dns_name_t));
cae2cb086244dfb883739edbe79e34756079f70eMark Andrews memcpy(rule->types, types, ntypes * sizeof(dns_rdatatype_t));
9935447b51456f598b45246d0114b8006049244dMark Andrews ISC_LIST_INITANDAPPEND(table->rules, rule, link);
38cd4d14cc341c2663e574035074788bb6f0fce2Evan Hunt isc_mem_put(mctx, rule->identity, sizeof(dns_name_t));
cae2cb086244dfb883739edbe79e34756079f70eMark Andrews isc_mem_put(mctx, rule->name, sizeof(dns_name_t));
f54d0c9c6e65de367d4ef08f51d22a2fb4c56208Mark Andrewsdns_ssutable_checkrules(dns_ssutable_t *table, dns_name_t *signer,
dc2a0aa7aaa8b85398ae183c7274c0eeec5009afMark Andrews unsigned int i;
101a7960b7989a18d873f3302b3b2415aeafb108Mark Andrews REQUIRE(signer == NULL || dns_name_isabsolute(signer));
f8727bd90366af835f551da1b5e1fdfcd2d3d01fBrian Wellington if (!dns_name_matcheswildcard(signer, rule->identity))
f54d0c9c6e65de367d4ef08f51d22a2fb4c56208Mark Andrews if (rule->matchtype == DNS_SSUMATCHTYPE_NAME) {
a5d43b72413db3edd6b36a58f9bdf2cf6ff692f2Bob Halley else if (rule->matchtype == DNS_SSUMATCHTYPE_SUBDOMAIN) {
f54d0c9c6e65de367d4ef08f51d22a2fb4c56208Mark Andrews else if (rule->matchtype == DNS_SSUMATCHTYPE_WILDCARD) {
4423c99613db1399dbb5c51e86ef0d351a1418c2Mark Andrews if (!dns_name_matcheswildcard(name, rule->name))
f54d0c9c6e65de367d4ef08f51d22a2fb4c56208Mark Andrews else if (rule->matchtype == DNS_SSUMATCHTYPE_SELF) {
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 if (rule->types[i] == dns_rdatatype_any ||
f54d0c9c6e65de367d4ef08f51d22a2fb4c56208Mark Andrewsdns_ssurule_isgrant(const dns_ssurule_t *rule) {
f54d0c9c6e65de367d4ef08f51d22a2fb4c56208Mark Andrewsdns_ssurule_identity(const dns_ssurule_t *rule) {
577ca1471960830304d1d2b9bd543fa469af51c1Mark Andrewsdns_ssurule_matchtype(const dns_ssurule_t *rule) {
577ca1471960830304d1d2b9bd543fa469af51c1Mark Andrewsdns_ssurule_types(const dns_ssurule_t *rule, dns_rdatatype_t **types) {
f54d0c9c6e65de367d4ef08f51d22a2fb4c56208Mark Andrewsdns_ssutable_firstrule(const dns_ssutable_t *table, dns_ssurule_t **rule) {
281bfa2a98f1d1721538086e1b550185559f1d8bMark Andrews return (*rule != NULL ? ISC_R_SUCCESS : ISC_R_NOMORE);
f54d0c9c6e65de367d4ef08f51d22a2fb4c56208Mark Andrewsdns_ssutable_nextrule(dns_ssurule_t *rule, dns_ssurule_t **nextrule) {
f54d0c9c6e65de367d4ef08f51d22a2fb4c56208Mark Andrews REQUIRE(nextrule != NULL && *nextrule == NULL);