aclconf.c revision 3d78993c6d415f600f57520d1566627b5535d715
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * Copyright (C) 2004-2007 Internet Systems Consortium, Inc. ("ISC")
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence * Copyright (C) 1999-2002 Internet Software Consortium.
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * Permission to use, copy, modify, and/or distribute this software for any
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * purpose with or without fee is hereby granted, provided that the above
f389bc2c9e9e434380e10221778b7b548612a67fDavid Lawrence * copyright notice and this permission notice appear in all copies.
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
d09197467bbb156dccf0cbe72bb5c63480d5cfdcDavid Lawrence * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
d09197467bbb156dccf0cbe72bb5c63480d5cfdcDavid Lawrence * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
d09197467bbb156dccf0cbe72bb5c63480d5cfdcDavid Lawrence * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
64ba6e4cc3a0ccf8c8c6349fa75b937ca9bad9a6Michael Graff * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
64ba6e4cc3a0ccf8c8c6349fa75b937ca9bad9a6Michael Graff * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
7829fad4093f2c1985b1efb7cea00287ff015d2bckb * PERFORMANCE OF THIS SOFTWARE.
62ac31d7fd09b0bf2231e5f55ed85aed39bc2df6Evan Hunt/* $Id: aclconf.c,v 1.16 2007/12/18 01:53:26 marka Exp $ */
f389bc2c9e9e434380e10221778b7b548612a67fDavid Lawrence#include <isc/string.h> /* Required for HP/UX (and others?) */
f389bc2c9e9e434380e10221778b7b548612a67fDavid Lawrence * Find the definition of the named acl whose name is "name".
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrenceget_acl_def(const cfg_obj_t *cctx, const char *name, const cfg_obj_t **ret) {
b65f2ab14abb4b6ef906d7d02064fba158f07b1eDavid Lawrence const cfg_obj_t *acl = cfg_listelt_value(elt);
b65f2ab14abb4b6ef906d7d02064fba158f07b1eDavid Lawrence const char *aclname = cfg_obj_asstring(cfg_tuple_get(acl, "name"));
0f5962ac3e4ef336faff68f1cb838505e64665e5David Lawrenceconvert_named_acl(const cfg_obj_t *nameobj, const cfg_obj_t *cctx,
7829fad4093f2c1985b1efb7cea00287ff015d2bckb /* Look for an already-converted version. */
7829fad4093f2c1985b1efb7cea00287ff015d2bckb /* Not yet converted. Convert now. */
7829fad4093f2c1985b1efb7cea00287ff015d2bckb * Add a loop detection element.
8e6b386ab7e2d1bd8efedecbb8f4efb6b572a866Tinderbox User ISC_LIST_APPEND(ctx->named_acl_cache, &loop, nextincache);
7829fad4093f2c1985b1efb7cea00287ff015d2bckb result = cfg_acl_fromconfig(cacl, cctx, lctx, ctx, mctx,
7829fad4093f2c1985b1efb7cea00287ff015d2bckb ISC_LIST_UNLINK(ctx->named_acl_cache, &loop, nextincache);
7829fad4093f2c1985b1efb7cea00287ff015d2bckb ISC_LIST_APPEND(ctx->named_acl_cache, dacl, nextincache);
e59937c7283216ca22ce6e7937b06eab6d97f4acEvan Huntconvert_keyname(const cfg_obj_t *keyobj, isc_log_t *lctx, isc_mem_t *mctx,
7829fad4093f2c1985b1efb7cea00287ff015d2bckb unsigned int keylen;
8e6b386ab7e2d1bd8efedecbb8f4efb6b572a866Tinderbox User result = dns_name_fromtext(dns_fixedname_name(&fixname), &buf,
7829fad4093f2c1985b1efb7cea00287ff015d2bckb "key name '%s' is not a valid domain name",
7829fad4093f2c1985b1efb7cea00287ff015d2bckb return (dns_name_dup(dns_fixedname_name(&fixname), mctx, dnsname));
7829fad4093f2c1985b1efb7cea00287ff015d2bckb unsigned int nest_level,
8e6b386ab7e2d1bd8efedecbb8f4efb6b572a866Tinderbox User * If target already points to an ACL, then we're being
7829fad4093f2c1985b1efb7cea00287ff015d2bckb * called recursively to configure a nested ACL. The
7829fad4093f2c1985b1efb7cea00287ff015d2bckb * nested ACL's contents should just be absorbed into its
7829fad4093f2c1985b1efb7cea00287ff015d2bckb * parent ACL.
7829fad4093f2c1985b1efb7cea00287ff015d2bckb * Need to allocate a new ACL structure. Count the items
7829fad4093f2c1985b1efb7cea00287ff015d2bckb * in the ACL definition and allocate space for that many
7829fad4093f2c1985b1efb7cea00287ff015d2bckb * elements (even though some or all of them may end up in
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein * the iptable instead of the element array).
f036af2c718147408d738081cdb0a564b981b4cdDavid Lawrence isc_boolean_t recurse = ISC_TF(nest_level == 0);
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff /* This must be a negated element. */
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff * If nest_level is nonzero, then every element is
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff * to be stored as a separate, nested ACL rather than
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff * merged into the main iptable.
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff /* Network prefix */
7704a47aec081144bdb7a0218d5e2dd5296b6b08Mark Andrews unsigned int bitlen;
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein * If nesting ACLs (nest_level != 0), we negate
f036af2c718147408d738081cdb0a564b981b4cdDavid Lawrence * the nestedacl element, not the iptable entry
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff result = dns_iptable_addprefix(iptab, &addr, bitlen,
f036af2c718147408d738081cdb0a564b981b4cdDavid Lawrence * If we're nesting ACLs, put the nested
b16d99bac1d100735224ab3eaa84632537ff21b5Mark Andrews * ACL onto the elements list; otherwise
b16d99bac1d100735224ab3eaa84632537ff21b5Mark Andrews * merge it into *this* ACL.
ce376a81fa674d240197628ceb6113a4fa5a1ab3Mukund Sivaraman /* Fall through */
ce376a81fa674d240197628ceb6113a4fa5a1ab3Mukund Sivaraman } else if (cfg_obj_istype(ce, &cfg_type_keyref)) {
ce376a81fa674d240197628ceb6113a4fa5a1ab3Mukund Sivaraman /* Key name */
7554feaef6057f5ea2926076900ac7634b911456Mark Andrews /* ACL name */
f389bc2c9e9e434380e10221778b7b548612a67fDavid Lawrence /* iptable entry with zero bit length */
f389bc2c9e9e434380e10221778b7b548612a67fDavid Lawrence result = dns_iptable_addprefix(iptab, NULL, 0,
f731b5d665e484c9b9634531c791cee9d87ab7a0Automatic Updater } else if (strcasecmp(name, "none") == 0) {
f731b5d665e484c9b9634531c791cee9d87ab7a0Automatic Updater /* negated "any" */
f389bc2c9e9e434380e10221778b7b548612a67fDavid Lawrence result = dns_iptable_addprefix(iptab, NULL, 0,
3911e7610f29dc664cbe8336f35c0652cd74652eMark Andrews } else if (strcasecmp(name, "localhost") == 0) {
3911e7610f29dc664cbe8336f35c0652cd74652eMark Andrews } else if (strcasecmp(name, "localnets") == 0) {
3911e7610f29dc664cbe8336f35c0652cd74652eMark Andrews result = convert_named_acl(ce, cctx, lctx, ctx,
5d79b60fc5e4dad4f04da39570517d20a2425f8bMukund Sivaraman /* Fall through */
5d79b60fc5e4dad4f04da39570517d20a2425f8bMukund Sivaraman "address match list contains "
5d79b60fc5e4dad4f04da39570517d20a2425f8bMukund Sivaraman "unsupported element type");
5d79b60fc5e4dad4f04da39570517d20a2425f8bMukund Sivaraman * This should only be reached for localhost, localnets
5d79b60fc5e4dad4f04da39570517d20a2425f8bMukund Sivaraman * and keyname elements, and nested ACLs if nest_level is
5d79b60fc5e4dad4f04da39570517d20a2425f8bMukund Sivaraman * nonzero (i.e., in sortlists).