1999-12-16 23:11:07 +00:00
|
|
|
/*
|
2005-01-12 01:56:12 +00:00
|
|
|
* Copyright (C) 2004, 2005 Internet Systems Consortium, Inc. ("ISC")
|
2002-02-20 03:35:59 +00:00
|
|
|
* Copyright (C) 1999-2002 Internet Software Consortium.
|
2000-08-01 01:33:37 +00:00
|
|
|
*
|
1999-12-16 23:11:07 +00:00
|
|
|
* Permission to use, copy, modify, and distribute this software for any
|
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
* copyright notice and this permission notice appear in all copies.
|
2000-08-01 01:33:37 +00:00
|
|
|
*
|
2004-03-05 05:14:21 +00:00
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
|
|
|
|
* REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
|
|
* AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
|
|
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
|
|
* LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
|
|
|
|
* OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
|
|
* PERFORMANCE OF THIS SOFTWARE.
|
1999-12-16 23:11:07 +00:00
|
|
|
*/
|
|
|
|
|
2005-03-16 03:34:45 +00:00
|
|
|
/* $Id: aclconf.c,v 1.4 2005/03/16 03:34:45 marka Exp $ */
|
2000-06-22 22:00:42 +00:00
|
|
|
|
1999-12-16 23:11:07 +00:00
|
|
|
#include <config.h>
|
|
|
|
|
2000-08-11 01:53:47 +00:00
|
|
|
#include <isc/mem.h>
|
2000-05-08 19:23:32 +00:00
|
|
|
#include <isc/string.h> /* Required for HP/UX (and others?) */
|
2000-04-28 01:12:23 +00:00
|
|
|
#include <isc/util.h>
|
1999-12-16 23:11:07 +00:00
|
|
|
|
2002-01-04 02:32:16 +00:00
|
|
|
#include <isccfg/namedconf.h>
|
2005-01-11 03:46:11 +00:00
|
|
|
#include <isccfg/aclconf.h>
|
2002-01-04 02:32:16 +00:00
|
|
|
|
2000-05-08 14:38:29 +00:00
|
|
|
#include <dns/acl.h>
|
1999-12-16 23:11:07 +00:00
|
|
|
#include <dns/fixedname.h>
|
2000-01-20 00:59:17 +00:00
|
|
|
#include <dns/log.h>
|
1999-12-16 23:11:07 +00:00
|
|
|
|
2005-03-16 03:34:45 +00:00
|
|
|
#define LOOP_MAGIC ISC_MAGIC('L','O','O','P')
|
2000-11-27 19:42:38 +00:00
|
|
|
|
2000-05-08 14:38:29 +00:00
|
|
|
void
|
2005-01-11 03:46:11 +00:00
|
|
|
cfg_aclconfctx_init(cfg_aclconfctx_t *ctx) {
|
1999-12-16 23:11:07 +00:00
|
|
|
ISC_LIST_INIT(ctx->named_acl_cache);
|
|
|
|
}
|
|
|
|
|
2000-05-08 14:38:29 +00:00
|
|
|
void
|
2005-01-11 03:46:11 +00:00
|
|
|
cfg_aclconfctx_destroy(cfg_aclconfctx_t *ctx) {
|
2000-08-01 01:33:37 +00:00
|
|
|
dns_acl_t *dacl, *next;
|
1999-12-16 23:11:07 +00:00
|
|
|
for (dacl = ISC_LIST_HEAD(ctx->named_acl_cache);
|
|
|
|
dacl != NULL;
|
|
|
|
dacl = next)
|
|
|
|
{
|
|
|
|
next = ISC_LIST_NEXT(dacl, nextincache);
|
|
|
|
dns_acl_detach(&dacl);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-03-04 21:21:39 +00:00
|
|
|
/*
|
|
|
|
* Find the definition of the named acl whose name is "name".
|
|
|
|
*/
|
|
|
|
static isc_result_t
|
|
|
|
get_acl_def(cfg_obj_t *cctx, char *name, cfg_obj_t **ret) {
|
|
|
|
isc_result_t result;
|
|
|
|
cfg_obj_t *acls = NULL;
|
|
|
|
cfg_listelt_t *elt;
|
|
|
|
|
|
|
|
result = cfg_map_get(cctx, "acl", &acls);
|
|
|
|
if (result != ISC_R_SUCCESS)
|
|
|
|
return (result);
|
|
|
|
for (elt = cfg_list_first(acls);
|
|
|
|
elt != NULL;
|
|
|
|
elt = cfg_list_next(elt)) {
|
|
|
|
cfg_obj_t *acl = cfg_listelt_value(elt);
|
|
|
|
const char *aclname = cfg_obj_asstring(cfg_tuple_get(acl, "name"));
|
|
|
|
if (strcasecmp(aclname, name) == 0) {
|
|
|
|
*ret = cfg_tuple_get(acl, "value");
|
|
|
|
return (ISC_R_SUCCESS);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return (ISC_R_NOTFOUND);
|
|
|
|
}
|
|
|
|
|
1999-12-16 23:11:07 +00:00
|
|
|
static isc_result_t
|
2001-03-04 21:21:39 +00:00
|
|
|
convert_named_acl(cfg_obj_t *nameobj, cfg_obj_t *cctx,
|
2005-01-11 03:46:11 +00:00
|
|
|
isc_log_t *lctx, cfg_aclconfctx_t *ctx,
|
|
|
|
isc_mem_t *mctx, dns_acl_t **target)
|
1999-12-16 23:11:07 +00:00
|
|
|
{
|
|
|
|
isc_result_t result;
|
2001-03-04 21:21:39 +00:00
|
|
|
cfg_obj_t *cacl = NULL;
|
1999-12-16 23:11:07 +00:00
|
|
|
dns_acl_t *dacl;
|
2005-03-16 03:34:45 +00:00
|
|
|
dns_acl_t loop;
|
2001-03-04 21:21:39 +00:00
|
|
|
char *aclname = cfg_obj_asstring(nameobj);
|
1999-12-16 23:11:07 +00:00
|
|
|
|
|
|
|
/* Look for an already-converted version. */
|
|
|
|
for (dacl = ISC_LIST_HEAD(ctx->named_acl_cache);
|
|
|
|
dacl != NULL;
|
|
|
|
dacl = ISC_LIST_NEXT(dacl, nextincache))
|
|
|
|
{
|
2001-03-04 21:21:39 +00:00
|
|
|
if (strcasecmp(aclname, dacl->name) == 0) {
|
2005-03-16 03:34:45 +00:00
|
|
|
if (ISC_MAGIC_VALID(dacl, LOOP_MAGIC)) {
|
|
|
|
cfg_obj_log(nameobj, lctx, ISC_LOG_ERROR,
|
|
|
|
"acl loop detected: %s", aclname);
|
|
|
|
return (ISC_R_FAILURE);
|
|
|
|
}
|
1999-12-16 23:11:07 +00:00
|
|
|
dns_acl_attach(dacl, target);
|
2000-08-11 02:11:20 +00:00
|
|
|
return (ISC_R_SUCCESS);
|
1999-12-16 23:11:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
/* Not yet converted. Convert now. */
|
2001-03-04 21:21:39 +00:00
|
|
|
result = get_acl_def(cctx, aclname, &cacl);
|
2000-04-06 22:03:35 +00:00
|
|
|
if (result != ISC_R_SUCCESS) {
|
2005-01-11 03:46:11 +00:00
|
|
|
cfg_obj_log(nameobj, lctx, ISC_LOG_WARNING,
|
2001-03-04 21:21:39 +00:00
|
|
|
"undefined ACL '%s'", aclname);
|
1999-12-16 23:11:07 +00:00
|
|
|
return (result);
|
|
|
|
}
|
2005-03-16 03:34:45 +00:00
|
|
|
/*
|
|
|
|
* Add a loop detection element.
|
|
|
|
*/
|
|
|
|
memset(&loop, 0, sizeof(loop));
|
|
|
|
ISC_LINK_INIT(&loop, nextincache);
|
|
|
|
loop.name = aclname;
|
|
|
|
loop.magic = LOOP_MAGIC;
|
|
|
|
ISC_LIST_APPEND(ctx->named_acl_cache, &loop, nextincache);
|
2005-01-11 03:46:11 +00:00
|
|
|
result = cfg_acl_fromconfig(cacl, cctx, lctx, ctx, mctx, &dacl);
|
2005-03-16 03:34:45 +00:00
|
|
|
ISC_LIST_UNLINK(ctx->named_acl_cache, &loop, nextincache);
|
|
|
|
loop.magic = 0;
|
|
|
|
loop.name = NULL;
|
2000-04-06 22:03:35 +00:00
|
|
|
if (result != ISC_R_SUCCESS)
|
1999-12-16 23:11:07 +00:00
|
|
|
return (result);
|
2000-08-11 01:53:47 +00:00
|
|
|
dacl->name = isc_mem_strdup(dacl->mctx, aclname);
|
2000-08-11 02:11:20 +00:00
|
|
|
if (dacl->name == NULL)
|
|
|
|
return (ISC_R_NOMEMORY);
|
1999-12-16 23:11:07 +00:00
|
|
|
ISC_LIST_APPEND(ctx->named_acl_cache, dacl, nextincache);
|
|
|
|
dns_acl_attach(dacl, target);
|
|
|
|
return (ISC_R_SUCCESS);
|
|
|
|
}
|
|
|
|
|
|
|
|
static isc_result_t
|
2005-01-11 03:46:11 +00:00
|
|
|
convert_keyname(cfg_obj_t *keyobj, isc_log_t *lctx, isc_mem_t *mctx,
|
|
|
|
dns_name_t *dnsname)
|
|
|
|
{
|
1999-12-16 23:11:07 +00:00
|
|
|
isc_result_t result;
|
|
|
|
isc_buffer_t buf;
|
|
|
|
dns_fixedname_t fixname;
|
|
|
|
unsigned int keylen;
|
2001-03-04 21:21:39 +00:00
|
|
|
const char *txtname = cfg_obj_asstring(keyobj);
|
1999-12-16 23:11:07 +00:00
|
|
|
|
|
|
|
keylen = strlen(txtname);
|
103. [func] libisc buffer API changes for <isc/buffer.h>:
Added:
isc_buffer_base(b) (pointer)
isc_buffer_current(b) (pointer)
isc_buffer_active(b) (pointer)
isc_buffer_used(b) (pointer)
isc_buffer_length(b) (int)
isc_buffer_usedlength(b) (int)
isc_buffer_consumedlength(b) (int)
isc_buffer_remaininglength(b) (int)
isc_buffer_activelength(b) (int)
isc_buffer_availablelength(b) (int)
Removed:
ISC_BUFFER_USEDCOUNT(b)
ISC_BUFFER_AVAILABLECOUNT(b)
isc_buffer_type(b)
Changed names:
isc_buffer_used(b, r) ->
isc_buffer_usedregion(b, r)
isc_buffer_available(b, r) ->
isc_buffer_available_region(b, r)
isc_buffer_consumed(b, r) ->
isc_buffer_consumedregion(b, r)
isc_buffer_active(b, r) ->
isc_buffer_activeregion(b, r)
isc_buffer_remaining(b, r) ->
isc_buffer_remainingregion(b, r)
Buffer types were removed, so the ISC_BUFFERTYPE_*
macros are no more, and the type argument to
isc_buffer_init and isc_buffer_allocate were removed.
isc_buffer_putstr is now void (instead of isc_result_t)
and requires that the caller ensure that there
is enough available buffer space for the string.
2000-04-27 00:03:12 +00:00
|
|
|
isc_buffer_init(&buf, txtname, keylen);
|
1999-12-16 23:11:07 +00:00
|
|
|
isc_buffer_add(&buf, keylen);
|
|
|
|
dns_fixedname_init(&fixname);
|
|
|
|
result = dns_name_fromtext(dns_fixedname_name(&fixname), &buf,
|
|
|
|
dns_rootname, ISC_FALSE, NULL);
|
|
|
|
if (result != ISC_R_SUCCESS) {
|
2005-01-11 03:46:11 +00:00
|
|
|
cfg_obj_log(keyobj, lctx, ISC_LOG_WARNING,
|
2001-03-04 21:21:39 +00:00
|
|
|
"key name '%s' is not a valid domain name",
|
|
|
|
txtname);
|
1999-12-16 23:11:07 +00:00
|
|
|
return (result);
|
|
|
|
}
|
|
|
|
return (dns_name_dup(dns_fixedname_name(&fixname), mctx, dnsname));
|
|
|
|
}
|
2000-08-01 01:33:37 +00:00
|
|
|
|
1999-12-16 23:11:07 +00:00
|
|
|
isc_result_t
|
2005-01-11 03:46:11 +00:00
|
|
|
cfg_acl_fromconfig(cfg_obj_t *caml,
|
|
|
|
cfg_obj_t *cctx,
|
|
|
|
isc_log_t *lctx,
|
|
|
|
cfg_aclconfctx_t *ctx,
|
|
|
|
isc_mem_t *mctx,
|
|
|
|
dns_acl_t **target)
|
1999-12-16 23:11:07 +00:00
|
|
|
{
|
|
|
|
isc_result_t result;
|
|
|
|
unsigned int count;
|
|
|
|
dns_acl_t *dacl = NULL;
|
|
|
|
dns_aclelement_t *de;
|
2001-03-04 21:21:39 +00:00
|
|
|
cfg_listelt_t *elt;
|
1999-12-16 23:11:07 +00:00
|
|
|
|
|
|
|
REQUIRE(target != NULL && *target == NULL);
|
2000-08-01 01:33:37 +00:00
|
|
|
|
1999-12-16 23:11:07 +00:00
|
|
|
count = 0;
|
2001-03-04 21:21:39 +00:00
|
|
|
for (elt = cfg_list_first(caml);
|
|
|
|
elt != NULL;
|
|
|
|
elt = cfg_list_next(elt))
|
1999-12-16 23:11:07 +00:00
|
|
|
count++;
|
|
|
|
|
2000-01-13 23:38:55 +00:00
|
|
|
result = dns_acl_create(mctx, count, &dacl);
|
|
|
|
if (result != ISC_R_SUCCESS)
|
|
|
|
return (result);
|
2000-08-01 01:33:37 +00:00
|
|
|
|
1999-12-16 23:11:07 +00:00
|
|
|
de = dacl->elements;
|
2001-03-04 21:21:39 +00:00
|
|
|
for (elt = cfg_list_first(caml);
|
|
|
|
elt != NULL;
|
|
|
|
elt = cfg_list_next(elt))
|
1999-12-16 23:11:07 +00:00
|
|
|
{
|
2001-03-04 21:21:39 +00:00
|
|
|
cfg_obj_t *ce = cfg_listelt_value(elt);
|
|
|
|
if (cfg_obj_istuple(ce)) {
|
|
|
|
/* This must be a negated element. */
|
|
|
|
ce = cfg_tuple_get(ce, "value");
|
|
|
|
de->negative = ISC_TRUE;
|
|
|
|
} else {
|
|
|
|
de->negative = ISC_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cfg_obj_isnetprefix(ce)) {
|
|
|
|
/* Network prefix */
|
1999-12-16 23:11:07 +00:00
|
|
|
de->type = dns_aclelementtype_ipprefix;
|
2001-03-04 21:21:39 +00:00
|
|
|
|
|
|
|
cfg_obj_asnetprefix(ce,
|
|
|
|
&de->u.ip_prefix.address,
|
|
|
|
&de->u.ip_prefix.prefixlen);
|
|
|
|
} else if (cfg_obj_istype(ce, &cfg_type_keyref)) {
|
|
|
|
/* Key name */
|
1999-12-16 23:11:07 +00:00
|
|
|
de->type = dns_aclelementtype_keyname;
|
|
|
|
dns_name_init(&de->u.keyname, NULL);
|
2005-01-11 03:46:11 +00:00
|
|
|
result = convert_keyname(ce, lctx, mctx,
|
|
|
|
&de->u.keyname);
|
1999-12-16 23:11:07 +00:00
|
|
|
if (result != ISC_R_SUCCESS)
|
|
|
|
goto cleanup;
|
2001-03-04 21:21:39 +00:00
|
|
|
} else if (cfg_obj_islist(ce)) {
|
|
|
|
/* Nested ACL */
|
1999-12-16 23:11:07 +00:00
|
|
|
de->type = dns_aclelementtype_nestedacl;
|
2005-01-11 03:46:11 +00:00
|
|
|
result = cfg_acl_fromconfig(ce, cctx, lctx, ctx,
|
|
|
|
mctx, &de->u.nestedacl);
|
1999-12-16 23:11:07 +00:00
|
|
|
if (result != ISC_R_SUCCESS)
|
|
|
|
goto cleanup;
|
2001-03-04 21:21:39 +00:00
|
|
|
} else if (cfg_obj_isstring(ce)) {
|
|
|
|
/* ACL name */
|
|
|
|
char *name = cfg_obj_asstring(ce);
|
|
|
|
if (strcasecmp(name, "localhost") == 0) {
|
|
|
|
de->type = dns_aclelementtype_localhost;
|
|
|
|
} else if (strcasecmp(name, "localnets") == 0) {
|
|
|
|
de->type = dns_aclelementtype_localnets;
|
|
|
|
} else if (strcasecmp(name, "any") == 0) {
|
|
|
|
de->type = dns_aclelementtype_any;
|
|
|
|
} else if (strcasecmp(name, "none") == 0) {
|
|
|
|
de->type = dns_aclelementtype_any;
|
2001-04-12 21:04:14 +00:00
|
|
|
de->negative = ISC_TF(! de->negative);
|
2001-03-04 21:21:39 +00:00
|
|
|
} else {
|
|
|
|
de->type = dns_aclelementtype_nestedacl;
|
2005-01-11 03:46:11 +00:00
|
|
|
result = convert_named_acl(ce, cctx, lctx,
|
|
|
|
ctx, mctx,
|
2001-03-04 21:21:39 +00:00
|
|
|
&de->u.nestedacl);
|
|
|
|
if (result != ISC_R_SUCCESS)
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
} else {
|
2005-01-11 03:46:11 +00:00
|
|
|
cfg_obj_log(ce, lctx, ISC_LOG_WARNING,
|
2001-03-04 21:21:39 +00:00
|
|
|
"address match list contains "
|
|
|
|
"unsupported element type");
|
1999-12-16 23:11:07 +00:00
|
|
|
result = ISC_R_FAILURE;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
de++;
|
|
|
|
dacl->length++;
|
|
|
|
}
|
|
|
|
|
|
|
|
*target = dacl;
|
|
|
|
return (ISC_R_SUCCESS);
|
2000-08-01 01:33:37 +00:00
|
|
|
|
1999-12-16 23:11:07 +00:00
|
|
|
cleanup:
|
|
|
|
dns_acl_detach(&dacl);
|
|
|
|
return (result);
|
|
|
|
}
|