1999-12-16 23:11:07 +00:00
|
|
|
/*
|
2018-02-23 09:53:12 +01:00
|
|
|
* Copyright (C) Internet Systems Consortium, Inc. ("ISC")
|
2000-08-01 01:33:37 +00:00
|
|
|
*
|
2016-06-27 14:56:38 +10:00
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
2018-02-23 09:53:12 +01:00
|
|
|
*
|
|
|
|
* See the COPYRIGHT file distributed with this work for additional
|
|
|
|
* information regarding copyright ownership.
|
1999-12-16 23:11:07 +00:00
|
|
|
*/
|
|
|
|
|
2018-03-28 14:19:37 +02:00
|
|
|
#include <inttypes.h>
|
2018-04-17 08:29:14 -07:00
|
|
|
#include <stdbool.h>
|
2019-06-11 20:32:21 -07:00
|
|
|
#include <stdlib.h>
|
2018-03-28 14:19:37 +02:00
|
|
|
|
2000-08-11 01:53:47 +00:00
|
|
|
#include <isc/mem.h>
|
2017-09-13 19:44:47 +05:30
|
|
|
#include <isc/print.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>
|
2007-09-12 01:09:08 +00:00
|
|
|
#include <dns/iptable.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
|
|
|
|
2008-05-21 23:47:01 +00:00
|
|
|
#define LOOP_MAGIC ISC_MAGIC('L','O','O','P')
|
2000-11-27 19:42:38 +00:00
|
|
|
|
2019-06-11 20:32:21 -07:00
|
|
|
#if defined(HAVE_GEOIP2)
|
|
|
|
static const char *geoip_dbnames[] = {
|
|
|
|
"country",
|
|
|
|
"city",
|
|
|
|
"asnum",
|
|
|
|
"isp",
|
|
|
|
"domain",
|
|
|
|
NULL,
|
|
|
|
};
|
|
|
|
#elif defined(HAVE_GEOIP)
|
|
|
|
static const char *geoip_dbnames[] = {
|
|
|
|
"country",
|
|
|
|
"city",
|
|
|
|
"asnum",
|
|
|
|
"isp",
|
|
|
|
"domain",
|
|
|
|
"netspeed",
|
|
|
|
"org",
|
|
|
|
NULL,
|
|
|
|
};
|
|
|
|
#endif /* HAVE_GEOIP */
|
|
|
|
|
2011-06-17 07:05:02 +00:00
|
|
|
isc_result_t
|
|
|
|
cfg_aclconfctx_create(isc_mem_t *mctx, cfg_aclconfctx_t **ret) {
|
|
|
|
cfg_aclconfctx_t *actx;
|
|
|
|
|
|
|
|
REQUIRE(mctx != NULL);
|
|
|
|
REQUIRE(ret != NULL && *ret == NULL);
|
|
|
|
|
|
|
|
actx = isc_mem_get(mctx, sizeof(*actx));
|
|
|
|
if (actx == NULL)
|
|
|
|
return (ISC_R_NOMEMORY);
|
|
|
|
|
2018-08-01 11:46:11 +02:00
|
|
|
isc_refcount_init(&actx->references, 1);
|
2011-06-17 07:05:02 +00:00
|
|
|
|
|
|
|
actx->mctx = NULL;
|
|
|
|
isc_mem_attach(mctx, &actx->mctx);
|
|
|
|
ISC_LIST_INIT(actx->named_acl_cache);
|
|
|
|
|
2019-06-11 18:36:52 -07:00
|
|
|
#if defined(HAVE_GEOIP) || defined(HAVE_GEOIP2)
|
2013-02-27 17:19:39 -08:00
|
|
|
actx->geoip = NULL;
|
2013-03-01 21:33:49 +11:00
|
|
|
#endif
|
2013-02-27 17:19:39 -08:00
|
|
|
|
2011-06-17 07:05:02 +00:00
|
|
|
*ret = actx;
|
|
|
|
return (ISC_R_SUCCESS);
|
1999-12-16 23:11:07 +00:00
|
|
|
}
|
|
|
|
|
2000-05-08 14:38:29 +00:00
|
|
|
void
|
2011-06-17 07:05:02 +00:00
|
|
|
cfg_aclconfctx_attach(cfg_aclconfctx_t *src, cfg_aclconfctx_t **dest) {
|
|
|
|
REQUIRE(src != NULL);
|
|
|
|
REQUIRE(dest != NULL && *dest == NULL);
|
2007-09-12 01:09:08 +00:00
|
|
|
|
2018-08-17 15:16:59 +02:00
|
|
|
isc_refcount_increment(&src->references);
|
2011-06-17 07:05:02 +00:00
|
|
|
*dest = src;
|
1999-12-16 23:11:07 +00:00
|
|
|
}
|
|
|
|
|
2010-08-11 18:14:20 +00:00
|
|
|
void
|
2011-06-17 07:05:02 +00:00
|
|
|
cfg_aclconfctx_detach(cfg_aclconfctx_t **actxp) {
|
|
|
|
REQUIRE(actxp != NULL && *actxp != NULL);
|
2018-08-28 10:18:59 +02:00
|
|
|
cfg_aclconfctx_t *actx = *actxp;
|
|
|
|
*actxp = NULL;
|
2011-06-17 07:05:02 +00:00
|
|
|
|
2018-08-17 15:16:59 +02:00
|
|
|
if (isc_refcount_decrement(&actx->references) == 1) {
|
2018-08-28 10:18:59 +02:00
|
|
|
dns_acl_t *dacl, *next;
|
|
|
|
isc_refcount_destroy(&actx->references);
|
2011-06-17 07:05:02 +00:00
|
|
|
for (dacl = ISC_LIST_HEAD(actx->named_acl_cache);
|
|
|
|
dacl != NULL;
|
|
|
|
dacl = next)
|
|
|
|
{
|
|
|
|
next = ISC_LIST_NEXT(dacl, nextincache);
|
|
|
|
ISC_LIST_UNLINK(actx->named_acl_cache, dacl,
|
|
|
|
nextincache);
|
|
|
|
dns_acl_detach(&dacl);
|
|
|
|
}
|
|
|
|
isc_mem_putanddetach(&actx->mctx, actx, sizeof(*actx));
|
2010-08-11 18:14:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-03-04 21:21:39 +00:00
|
|
|
/*
|
|
|
|
* Find the definition of the named acl whose name is "name".
|
|
|
|
*/
|
|
|
|
static isc_result_t
|
2006-02-28 02:39:52 +00:00
|
|
|
get_acl_def(const cfg_obj_t *cctx, const char *name, const cfg_obj_t **ret) {
|
2001-03-04 21:21:39 +00:00
|
|
|
isc_result_t result;
|
2006-02-28 02:39:52 +00:00
|
|
|
const cfg_obj_t *acls = NULL;
|
|
|
|
const cfg_listelt_t *elt;
|
2008-05-21 23:47:01 +00:00
|
|
|
|
2001-03-04 21:21:39 +00:00
|
|
|
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)) {
|
2006-02-28 02:39:52 +00:00
|
|
|
const cfg_obj_t *acl = cfg_listelt_value(elt);
|
2019-06-11 18:36:52 -07:00
|
|
|
const char *aclname =
|
|
|
|
cfg_obj_asstring(cfg_tuple_get(acl, "name"));
|
2001-03-04 21:21:39 +00:00
|
|
|
if (strcasecmp(aclname, name) == 0) {
|
2007-09-12 01:09:08 +00:00
|
|
|
if (ret != NULL) {
|
|
|
|
*ret = cfg_tuple_get(acl, "value");
|
|
|
|
}
|
2001-03-04 21:21:39 +00:00
|
|
|
return (ISC_R_SUCCESS);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return (ISC_R_NOTFOUND);
|
|
|
|
}
|
|
|
|
|
1999-12-16 23:11:07 +00:00
|
|
|
static isc_result_t
|
2006-02-28 02:39:52 +00:00
|
|
|
convert_named_acl(const cfg_obj_t *nameobj, const cfg_obj_t *cctx,
|
2005-01-11 03:46:11 +00:00
|
|
|
isc_log_t *lctx, cfg_aclconfctx_t *ctx,
|
2007-10-12 04:17:18 +00:00
|
|
|
isc_mem_t *mctx, unsigned int nest_level,
|
2007-09-14 01:46:06 +00:00
|
|
|
dns_acl_t **target)
|
1999-12-16 23:11:07 +00:00
|
|
|
{
|
|
|
|
isc_result_t result;
|
2006-02-28 02:39:52 +00:00
|
|
|
const 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;
|
2005-08-23 02:36:11 +00:00
|
|
|
const 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);
|
2005-08-23 02:36:11 +00:00
|
|
|
DE_CONST(aclname, loop.name);
|
2005-03-16 03:34:45 +00:00
|
|
|
loop.magic = LOOP_MAGIC;
|
|
|
|
ISC_LIST_APPEND(ctx->named_acl_cache, &loop, nextincache);
|
2007-09-12 01:09:08 +00:00
|
|
|
result = cfg_acl_fromconfig(cacl, cctx, lctx, ctx, mctx,
|
2007-09-14 01:46:06 +00:00
|
|
|
nest_level, &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
|
2006-02-28 02:39:52 +00:00
|
|
|
convert_keyname(const cfg_obj_t *keyobj, isc_log_t *lctx, isc_mem_t *mctx,
|
2005-01-11 03:46:11 +00:00
|
|
|
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);
|
2012-12-08 12:48:57 +11:00
|
|
|
isc_buffer_constinit(&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,
|
2009-09-01 00:22:28 +00:00
|
|
|
dns_rootname, 0, NULL);
|
1999-12-16 23:11:07 +00:00
|
|
|
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
|
|
|
|
2008-10-24 02:28:55 +00:00
|
|
|
/*
|
|
|
|
* Recursively pre-parse an ACL definition to find the total number
|
|
|
|
* of non-IP-prefix elements (localhost, localnets, key) in all nested
|
|
|
|
* ACLs, so that the parent will have enough space allocated for the
|
|
|
|
* elements table after all the nested ACLs have been merged in to the
|
|
|
|
* parent.
|
|
|
|
*/
|
2014-08-03 10:05:02 +10:00
|
|
|
static isc_result_t
|
2009-10-01 04:06:37 +00:00
|
|
|
count_acl_elements(const cfg_obj_t *caml, const cfg_obj_t *cctx,
|
2014-08-03 10:05:02 +10:00
|
|
|
isc_log_t *lctx, cfg_aclconfctx_t *ctx, isc_mem_t *mctx,
|
2018-04-17 08:29:14 -07:00
|
|
|
uint32_t *count, bool *has_negative)
|
2008-10-24 02:28:55 +00:00
|
|
|
{
|
|
|
|
const cfg_listelt_t *elt;
|
|
|
|
isc_result_t result;
|
2018-03-28 14:19:37 +02:00
|
|
|
uint32_t n = 0;
|
2014-08-03 10:05:02 +10:00
|
|
|
|
|
|
|
REQUIRE(count != NULL);
|
2008-10-24 02:28:55 +00:00
|
|
|
|
2009-10-01 04:06:37 +00:00
|
|
|
if (has_negative != NULL)
|
2018-04-17 08:29:14 -07:00
|
|
|
*has_negative = false;
|
2009-10-01 04:06:37 +00:00
|
|
|
|
2008-10-24 02:28:55 +00:00
|
|
|
for (elt = cfg_list_first(caml);
|
|
|
|
elt != NULL;
|
|
|
|
elt = cfg_list_next(elt)) {
|
|
|
|
const cfg_obj_t *ce = cfg_listelt_value(elt);
|
|
|
|
|
2013-02-27 17:19:39 -08:00
|
|
|
/* might be a negated element, in which case get the value. */
|
2009-10-01 04:06:37 +00:00
|
|
|
if (cfg_obj_istuple(ce)) {
|
2013-02-27 17:19:39 -08:00
|
|
|
const cfg_obj_t *negated =
|
|
|
|
cfg_tuple_get(ce, "negated");
|
|
|
|
if (! cfg_obj_isvoid(negated)) {
|
|
|
|
ce = negated;
|
|
|
|
if (has_negative != NULL)
|
2018-04-17 08:29:14 -07:00
|
|
|
*has_negative = true;
|
2013-02-27 17:19:39 -08:00
|
|
|
}
|
2009-10-01 04:06:37 +00:00
|
|
|
}
|
2008-10-24 02:28:55 +00:00
|
|
|
|
|
|
|
if (cfg_obj_istype(ce, &cfg_type_keyref)) {
|
|
|
|
n++;
|
|
|
|
} else if (cfg_obj_islist(ce)) {
|
2018-04-17 08:29:14 -07:00
|
|
|
bool negative;
|
2018-03-28 14:19:37 +02:00
|
|
|
uint32_t sub;
|
2014-08-03 10:05:02 +10:00
|
|
|
result = count_acl_elements(ce, cctx, lctx, ctx, mctx,
|
|
|
|
&sub, &negative);
|
|
|
|
if (result != ISC_R_SUCCESS)
|
|
|
|
return (result);
|
|
|
|
n += sub;
|
2009-10-01 04:06:37 +00:00
|
|
|
if (negative)
|
|
|
|
n++;
|
2019-06-11 18:36:52 -07:00
|
|
|
#if defined(HAVE_GEOIP) || defined(HAVE_GEOIP2)
|
2013-02-27 17:19:39 -08:00
|
|
|
} else if (cfg_obj_istuple(ce) &&
|
|
|
|
cfg_obj_isvoid(cfg_tuple_get(ce, "negated")))
|
|
|
|
{
|
2014-08-03 10:05:02 +10:00
|
|
|
n++;
|
2019-06-11 18:36:52 -07:00
|
|
|
#endif /* HAVE_GEOIP || HAVE_GEOIP2 */
|
2008-10-24 02:28:55 +00:00
|
|
|
} else if (cfg_obj_isstring(ce)) {
|
|
|
|
const char *name = cfg_obj_asstring(ce);
|
|
|
|
if (strcasecmp(name, "localhost") == 0 ||
|
2016-02-23 12:51:34 +05:30
|
|
|
strcasecmp(name, "localnets") == 0 ||
|
|
|
|
strcasecmp(name, "none") == 0)
|
|
|
|
{
|
2008-10-24 02:28:55 +00:00
|
|
|
n++;
|
2016-02-23 12:51:34 +05:30
|
|
|
} else if (strcasecmp(name, "any") != 0) {
|
2014-08-03 10:05:02 +10:00
|
|
|
dns_acl_t *inneracl = NULL;
|
|
|
|
/*
|
|
|
|
* Convert any named acls we reference now if
|
|
|
|
* they have not already been converted.
|
|
|
|
*/
|
|
|
|
result = convert_named_acl(ce, cctx, lctx, ctx,
|
|
|
|
mctx, 0, &inneracl);
|
|
|
|
if (result == ISC_R_SUCCESS) {
|
|
|
|
if (inneracl->has_negatives)
|
|
|
|
n++;
|
|
|
|
else
|
|
|
|
n += inneracl->length;
|
|
|
|
dns_acl_detach(&inneracl);
|
|
|
|
} else
|
|
|
|
return (result);
|
2008-10-24 02:28:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-03 10:05:02 +10:00
|
|
|
*count = n;
|
|
|
|
return (ISC_R_SUCCESS);
|
2008-10-24 02:28:55 +00:00
|
|
|
}
|
|
|
|
|
2019-06-11 20:32:21 -07:00
|
|
|
#if defined(HAVE_GEOIP2)
|
2013-02-27 17:19:39 -08:00
|
|
|
static dns_geoip_subtype_t
|
|
|
|
get_subtype(const cfg_obj_t *obj, isc_log_t *lctx,
|
|
|
|
dns_geoip_subtype_t subtype, const char *dbname)
|
|
|
|
{
|
2019-06-11 18:36:52 -07:00
|
|
|
if (dbname == NULL) {
|
2013-02-27 17:19:39 -08:00
|
|
|
return (subtype);
|
2019-06-11 18:36:52 -07:00
|
|
|
}
|
2013-02-27 17:19:39 -08:00
|
|
|
|
|
|
|
switch (subtype) {
|
|
|
|
case dns_geoip_countrycode:
|
2019-06-11 18:36:52 -07:00
|
|
|
if (strcasecmp(dbname, "city") == 0) {
|
2013-02-27 17:19:39 -08:00
|
|
|
return (dns_geoip_city_countrycode);
|
2019-06-11 18:36:52 -07:00
|
|
|
} else if (strcasecmp(dbname, "country") == 0) {
|
2013-02-27 17:19:39 -08:00
|
|
|
return (dns_geoip_country_code);
|
2019-06-11 18:36:52 -07:00
|
|
|
}
|
2013-02-27 17:19:39 -08:00
|
|
|
cfg_obj_log(obj, lctx, ISC_LOG_ERROR,
|
2019-06-11 20:32:21 -07:00
|
|
|
"invalid database specified for "
|
2013-02-27 17:19:39 -08:00
|
|
|
"country search: ignored");
|
|
|
|
return (subtype);
|
2019-06-11 20:32:21 -07:00
|
|
|
case dns_geoip_countryname:
|
2019-06-11 18:36:52 -07:00
|
|
|
if (strcasecmp(dbname, "city") == 0) {
|
2019-06-11 20:32:21 -07:00
|
|
|
return (dns_geoip_city_countryname);
|
2019-06-11 18:36:52 -07:00
|
|
|
} else if (strcasecmp(dbname, "country") == 0) {
|
2019-06-11 20:32:21 -07:00
|
|
|
return (dns_geoip_country_name);
|
2019-06-11 18:36:52 -07:00
|
|
|
}
|
2013-02-27 17:19:39 -08:00
|
|
|
cfg_obj_log(obj, lctx, ISC_LOG_ERROR,
|
2019-06-11 20:32:21 -07:00
|
|
|
"invalid database specified for "
|
2013-02-27 17:19:39 -08:00
|
|
|
"country search: ignored");
|
|
|
|
return (subtype);
|
2019-06-11 20:32:21 -07:00
|
|
|
case dns_geoip_continentcode:
|
2019-06-11 18:36:52 -07:00
|
|
|
if (strcasecmp(dbname, "city") == 0) {
|
2019-06-11 20:32:21 -07:00
|
|
|
return (dns_geoip_city_continentcode);
|
2019-06-11 18:36:52 -07:00
|
|
|
} else if (strcasecmp(dbname, "country") == 0) {
|
2019-06-11 20:32:21 -07:00
|
|
|
return (dns_geoip_country_continentcode);
|
2019-06-11 18:36:52 -07:00
|
|
|
}
|
2013-02-27 17:19:39 -08:00
|
|
|
cfg_obj_log(obj, lctx, ISC_LOG_ERROR,
|
2019-06-11 20:32:21 -07:00
|
|
|
"invalid database specified for "
|
|
|
|
"continent search: ignored");
|
|
|
|
return (subtype);
|
|
|
|
case dns_geoip_continent:
|
|
|
|
if (strcasecmp(dbname, "city") == 0) {
|
|
|
|
return (dns_geoip_city_continent);
|
|
|
|
} else if (strcasecmp(dbname, "country") == 0) {
|
|
|
|
return (dns_geoip_country_continent);
|
|
|
|
}
|
|
|
|
cfg_obj_log(obj, lctx, ISC_LOG_ERROR,
|
|
|
|
"invalid database specified for "
|
|
|
|
"continent search: ignored");
|
2013-02-27 17:19:39 -08:00
|
|
|
return (subtype);
|
|
|
|
case dns_geoip_region:
|
2019-06-11 18:36:52 -07:00
|
|
|
if (strcasecmp(dbname, "city") == 0) {
|
2013-02-27 17:19:39 -08:00
|
|
|
return (dns_geoip_city_region);
|
2019-06-11 18:36:52 -07:00
|
|
|
}
|
2013-02-27 17:19:39 -08:00
|
|
|
cfg_obj_log(obj, lctx, ISC_LOG_ERROR,
|
2019-06-11 20:32:21 -07:00
|
|
|
"invalid database specified for "
|
|
|
|
"region/subdivision search: ignored");
|
2013-02-27 17:19:39 -08:00
|
|
|
return (subtype);
|
|
|
|
case dns_geoip_regionname:
|
2019-06-11 18:36:52 -07:00
|
|
|
if (strcasecmp(dbname, "city") == 0) {
|
2019-06-11 20:32:21 -07:00
|
|
|
return (dns_geoip_city_regionname);
|
2019-06-11 18:36:52 -07:00
|
|
|
}
|
2013-02-27 17:19:39 -08:00
|
|
|
cfg_obj_log(obj, lctx, ISC_LOG_ERROR,
|
2019-06-11 20:32:21 -07:00
|
|
|
"invalid database specified for "
|
|
|
|
"region/subdivision search: ignored");
|
2013-02-27 17:19:39 -08:00
|
|
|
return (subtype);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Log a warning if the wrong database was specified
|
|
|
|
* on an unambiguous query
|
|
|
|
*/
|
|
|
|
case dns_geoip_city_name:
|
|
|
|
case dns_geoip_city_postalcode:
|
|
|
|
case dns_geoip_city_metrocode:
|
|
|
|
case dns_geoip_city_areacode:
|
|
|
|
case dns_geoip_city_timezonecode:
|
2019-06-11 18:36:52 -07:00
|
|
|
if (strcasecmp(dbname, "city") != 0) {
|
2013-02-27 17:19:39 -08:00
|
|
|
cfg_obj_log(obj, lctx, ISC_LOG_WARNING,
|
2019-06-11 20:32:21 -07:00
|
|
|
"invalid database specified for "
|
2013-02-27 17:19:39 -08:00
|
|
|
"a 'city'-only search type: ignoring");
|
2019-06-11 18:36:52 -07:00
|
|
|
}
|
2013-02-27 17:19:39 -08:00
|
|
|
return (subtype);
|
|
|
|
case dns_geoip_isp_name:
|
2019-06-11 18:36:52 -07:00
|
|
|
if (strcasecmp(dbname, "isp") != 0) {
|
2013-02-27 17:19:39 -08:00
|
|
|
cfg_obj_log(obj, lctx, ISC_LOG_WARNING,
|
2019-06-11 20:32:21 -07:00
|
|
|
"invalid database specified for "
|
2013-02-27 17:19:39 -08:00
|
|
|
"an 'isp' search: ignoring");
|
2019-06-11 18:36:52 -07:00
|
|
|
}
|
2013-02-27 17:19:39 -08:00
|
|
|
return (subtype);
|
|
|
|
case dns_geoip_org_name:
|
2019-06-11 18:36:52 -07:00
|
|
|
if (strcasecmp(dbname, "org") != 0) {
|
2013-02-27 17:19:39 -08:00
|
|
|
cfg_obj_log(obj, lctx, ISC_LOG_WARNING,
|
2019-06-11 20:32:21 -07:00
|
|
|
"invalid database specified for "
|
2013-02-27 17:19:39 -08:00
|
|
|
"an 'org' search: ignoring");
|
2019-06-11 18:36:52 -07:00
|
|
|
}
|
2013-02-27 17:19:39 -08:00
|
|
|
return (subtype);
|
|
|
|
case dns_geoip_as_asnum:
|
2019-06-11 18:36:52 -07:00
|
|
|
if (strcasecmp(dbname, "asnum") != 0) {
|
2013-02-27 17:19:39 -08:00
|
|
|
cfg_obj_log(obj, lctx, ISC_LOG_WARNING,
|
2019-06-11 20:32:21 -07:00
|
|
|
"invalid database specified for "
|
2013-02-27 17:19:39 -08:00
|
|
|
"an 'asnum' search: ignoring");
|
2019-06-11 18:36:52 -07:00
|
|
|
}
|
2013-02-27 17:19:39 -08:00
|
|
|
return (subtype);
|
|
|
|
case dns_geoip_domain_name:
|
2019-06-11 18:36:52 -07:00
|
|
|
if (strcasecmp(dbname, "domain") != 0) {
|
2013-02-27 17:19:39 -08:00
|
|
|
cfg_obj_log(obj, lctx, ISC_LOG_WARNING,
|
2019-06-11 20:32:21 -07:00
|
|
|
"invalid database specified for "
|
2013-02-27 17:19:39 -08:00
|
|
|
"a 'domain' search: ignoring");
|
2019-06-11 18:36:52 -07:00
|
|
|
}
|
2013-02-27 17:19:39 -08:00
|
|
|
return (subtype);
|
|
|
|
case dns_geoip_netspeed_id:
|
2019-06-11 18:36:52 -07:00
|
|
|
if (strcasecmp(dbname, "netspeed") != 0) {
|
2013-02-27 17:19:39 -08:00
|
|
|
cfg_obj_log(obj, lctx, ISC_LOG_WARNING,
|
2019-06-11 20:32:21 -07:00
|
|
|
"invalid database specified for "
|
2013-02-27 17:19:39 -08:00
|
|
|
"a 'netspeed' search: ignoring");
|
2019-06-11 18:36:52 -07:00
|
|
|
}
|
2013-02-27 17:19:39 -08:00
|
|
|
return (subtype);
|
|
|
|
default:
|
|
|
|
INSIST(0);
|
2018-11-07 15:00:07 +07:00
|
|
|
ISC_UNREACHABLE();
|
2013-02-27 17:19:39 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-17 08:29:14 -07:00
|
|
|
static bool
|
2013-02-27 17:19:39 -08:00
|
|
|
geoip_can_answer(dns_aclelement_t *elt, cfg_aclconfctx_t *ctx) {
|
2019-06-11 18:36:52 -07:00
|
|
|
if (ctx->geoip == NULL) {
|
2018-04-17 08:29:14 -07:00
|
|
|
return (true);
|
2019-06-11 18:36:52 -07:00
|
|
|
}
|
2013-02-27 17:19:39 -08:00
|
|
|
|
2019-06-11 20:32:21 -07:00
|
|
|
switch (elt->geoip_elem.subtype) {
|
|
|
|
case dns_geoip_countrycode:
|
|
|
|
case dns_geoip_countryname:
|
|
|
|
case dns_geoip_continentcode:
|
|
|
|
case dns_geoip_continent:
|
|
|
|
if (ctx->geoip->country != NULL ||
|
|
|
|
ctx->geoip->city != NULL)
|
|
|
|
{
|
|
|
|
return (true);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case dns_geoip_country_code:
|
|
|
|
case dns_geoip_country_name:
|
|
|
|
case dns_geoip_country_continentcode:
|
|
|
|
case dns_geoip_country_continent:
|
|
|
|
if (ctx->geoip->country != NULL) {
|
|
|
|
return (true);
|
|
|
|
}
|
|
|
|
/* city db can answer these too, so: */
|
|
|
|
/* FALLTHROUGH */
|
|
|
|
case dns_geoip_region:
|
|
|
|
case dns_geoip_regionname:
|
|
|
|
case dns_geoip_city_countrycode:
|
|
|
|
case dns_geoip_city_countryname:
|
|
|
|
case dns_geoip_city_region:
|
|
|
|
case dns_geoip_city_regionname:
|
|
|
|
case dns_geoip_city_name:
|
|
|
|
case dns_geoip_city_postalcode:
|
|
|
|
case dns_geoip_city_metrocode:
|
|
|
|
case dns_geoip_city_areacode:
|
|
|
|
case dns_geoip_city_continentcode:
|
|
|
|
case dns_geoip_city_continent:
|
|
|
|
case dns_geoip_city_timezonecode:
|
|
|
|
if (ctx->geoip->city != NULL) {
|
|
|
|
return (true);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case dns_geoip_isp_name:
|
|
|
|
if (ctx->geoip->isp != NULL) {
|
|
|
|
return (true);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case dns_geoip_as_asnum:
|
|
|
|
case dns_geoip_org_name:
|
|
|
|
if (ctx->geoip->as != NULL) {
|
|
|
|
return (true);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case dns_geoip_domain_name:
|
|
|
|
if (ctx->geoip->domain != NULL) {
|
|
|
|
return (true);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (false);
|
|
|
|
}
|
|
|
|
|
|
|
|
static isc_result_t
|
|
|
|
parse_geoip_element(const cfg_obj_t *obj, isc_log_t *lctx,
|
|
|
|
cfg_aclconfctx_t *ctx, dns_aclelement_t *dep)
|
|
|
|
{
|
|
|
|
const cfg_obj_t *ge;
|
|
|
|
const char *dbname = NULL;
|
|
|
|
const char *stype = NULL, *search = NULL;
|
|
|
|
dns_geoip_subtype_t subtype;
|
|
|
|
dns_aclelement_t de;
|
|
|
|
size_t len;
|
|
|
|
|
|
|
|
REQUIRE(dep != NULL);
|
|
|
|
|
|
|
|
de = *dep;
|
|
|
|
|
|
|
|
ge = cfg_tuple_get(obj, "db");
|
|
|
|
if (!cfg_obj_isvoid(ge)) {
|
|
|
|
int i;
|
|
|
|
|
|
|
|
dbname = cfg_obj_asstring(ge);
|
|
|
|
|
|
|
|
for (i = 0; geoip_dbnames[i] != NULL; i++) {
|
|
|
|
if (strcasecmp(dbname, geoip_dbnames[i]) == 0) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (geoip_dbnames[i] == NULL) {
|
|
|
|
cfg_obj_log(obj, lctx, ISC_LOG_ERROR,
|
|
|
|
"database '%s' is not defined for GeoIP",
|
|
|
|
dbname);
|
|
|
|
return (ISC_R_UNEXPECTED);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
stype = cfg_obj_asstring(cfg_tuple_get(obj, "subtype"));
|
|
|
|
search = cfg_obj_asstring(cfg_tuple_get(obj, "search"));
|
|
|
|
len = strlen(search);
|
|
|
|
|
|
|
|
if (len == 0) {
|
|
|
|
cfg_obj_log(obj, lctx, ISC_LOG_ERROR,
|
|
|
|
"zero-length geoip search field");
|
|
|
|
return (ISC_R_FAILURE);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (strcasecmp(stype, "country") == 0 && len == 2) {
|
|
|
|
/* Two-letter country code */
|
|
|
|
subtype = dns_geoip_countrycode;
|
|
|
|
strlcpy(de.geoip_elem.as_string, search,
|
|
|
|
sizeof(de.geoip_elem.as_string));
|
|
|
|
} else if (strcasecmp(stype, "country") == 0 && len == 3) {
|
|
|
|
/* Three-letter country code */
|
|
|
|
cfg_obj_log(obj, lctx, ISC_LOG_ERROR,
|
|
|
|
"three-letter country codes are unavailable "
|
|
|
|
"in GeoIP2 databases");
|
|
|
|
return (ISC_R_FAILURE);
|
|
|
|
} else if (strcasecmp(stype, "country") == 0) {
|
|
|
|
/* Country name */
|
|
|
|
subtype = dns_geoip_countryname;
|
|
|
|
strlcpy(de.geoip_elem.as_string, search,
|
|
|
|
sizeof(de.geoip_elem.as_string));
|
|
|
|
} else if (strcasecmp(stype, "continent") == 0 && len == 2) {
|
|
|
|
/* Two-letter continent code */
|
|
|
|
subtype = dns_geoip_continentcode;
|
|
|
|
strlcpy(de.geoip_elem.as_string, search,
|
|
|
|
sizeof(de.geoip_elem.as_string));
|
|
|
|
} else if (strcasecmp(stype, "continent") == 0) {
|
|
|
|
subtype = dns_geoip_continent;
|
|
|
|
strlcpy(de.geoip_elem.as_string, search,
|
|
|
|
sizeof(de.geoip_elem.as_string));
|
|
|
|
} else if ((strcasecmp(stype, "region") == 0 ||
|
|
|
|
strcasecmp(stype, "subdivision") == 0) && len == 2)
|
|
|
|
{
|
|
|
|
/* Two-letter region code */
|
|
|
|
subtype = dns_geoip_region;
|
|
|
|
strlcpy(de.geoip_elem.as_string, search,
|
|
|
|
sizeof(de.geoip_elem.as_string));
|
|
|
|
} else if (strcasecmp(stype, "region") == 0 ||
|
|
|
|
strcasecmp(stype, "subdivision") == 0)
|
|
|
|
{
|
|
|
|
/* Region name */
|
|
|
|
subtype = dns_geoip_regionname;
|
|
|
|
strlcpy(de.geoip_elem.as_string, search,
|
|
|
|
sizeof(de.geoip_elem.as_string));
|
|
|
|
} else if (strcasecmp(stype, "city") == 0) {
|
|
|
|
/* City name */
|
|
|
|
subtype = dns_geoip_city_name;
|
|
|
|
strlcpy(de.geoip_elem.as_string, search,
|
|
|
|
sizeof(de.geoip_elem.as_string));
|
|
|
|
} else if (strcasecmp(stype, "postal") == 0 ||
|
|
|
|
strcasecmp(stype, "postalcode") == 0)
|
|
|
|
{
|
|
|
|
if (len < 7) {
|
|
|
|
subtype = dns_geoip_city_postalcode;
|
|
|
|
strlcpy(de.geoip_elem.as_string, search,
|
|
|
|
sizeof(de.geoip_elem.as_string));
|
|
|
|
} else {
|
|
|
|
cfg_obj_log(obj, lctx, ISC_LOG_ERROR,
|
|
|
|
"geoiop postal code (%s) too long",
|
|
|
|
search);
|
|
|
|
return (ISC_R_FAILURE);
|
|
|
|
}
|
|
|
|
} else if (strcasecmp(stype, "metro") == 0 ||
|
|
|
|
strcasecmp(stype, "metrocode") == 0)
|
|
|
|
{
|
|
|
|
subtype = dns_geoip_city_metrocode;
|
|
|
|
de.geoip_elem.as_int = atoi(search);
|
|
|
|
} else if (strcasecmp(stype, "tz") == 0 ||
|
|
|
|
strcasecmp(stype, "timezone") == 0)
|
|
|
|
{
|
|
|
|
subtype = dns_geoip_city_timezonecode;
|
|
|
|
strlcpy(de.geoip_elem.as_string, search,
|
|
|
|
sizeof(de.geoip_elem.as_string));
|
|
|
|
} else if (strcasecmp(stype, "isp") == 0) {
|
|
|
|
subtype = dns_geoip_isp_name;
|
|
|
|
strlcpy(de.geoip_elem.as_string, search,
|
|
|
|
sizeof(de.geoip_elem.as_string));
|
|
|
|
} else if (strcasecmp(stype, "asnum") == 0) {
|
|
|
|
subtype = dns_geoip_as_asnum;
|
|
|
|
strlcpy(de.geoip_elem.as_string, search,
|
|
|
|
sizeof(de.geoip_elem.as_string));
|
|
|
|
} else if (strcasecmp(stype, "org") == 0) {
|
|
|
|
subtype = dns_geoip_org_name;
|
|
|
|
strlcpy(de.geoip_elem.as_string, search,
|
|
|
|
sizeof(de.geoip_elem.as_string));
|
|
|
|
} else if (strcasecmp(stype, "domain") == 0) {
|
|
|
|
subtype = dns_geoip_domain_name;
|
|
|
|
strlcpy(de.geoip_elem.as_string, search,
|
|
|
|
sizeof(de.geoip_elem.as_string));
|
|
|
|
} else {
|
|
|
|
cfg_obj_log(obj, lctx, ISC_LOG_ERROR,
|
|
|
|
"type '%s' is unavailable "
|
|
|
|
"in GeoIP2 databases", stype);
|
|
|
|
return (ISC_R_FAILURE);
|
|
|
|
}
|
|
|
|
|
|
|
|
de.geoip_elem.subtype = get_subtype(obj, lctx, subtype, dbname);
|
|
|
|
|
|
|
|
if (! geoip_can_answer(&de, ctx)) {
|
|
|
|
cfg_obj_log(obj, lctx, ISC_LOG_ERROR,
|
|
|
|
"no GeoIP2 database installed which can answer "
|
|
|
|
"queries of type '%s'", stype);
|
|
|
|
return (ISC_R_FAILURE);
|
|
|
|
}
|
|
|
|
|
|
|
|
*dep = de;
|
|
|
|
|
|
|
|
return (ISC_R_SUCCESS);
|
|
|
|
}
|
|
|
|
#elif defined(HAVE_GEOIP)
|
|
|
|
static dns_geoip_subtype_t
|
|
|
|
get_subtype(const cfg_obj_t *obj, isc_log_t *lctx,
|
|
|
|
dns_geoip_subtype_t subtype, const char *dbname)
|
|
|
|
{
|
|
|
|
if (dbname == NULL)
|
|
|
|
return (subtype);
|
|
|
|
|
|
|
|
switch (subtype) {
|
|
|
|
case dns_geoip_countrycode:
|
|
|
|
if (strcasecmp(dbname, "city") == 0)
|
|
|
|
return (dns_geoip_city_countrycode);
|
|
|
|
else if (strcasecmp(dbname, "region") == 0)
|
|
|
|
return (dns_geoip_region_countrycode);
|
|
|
|
else if (strcasecmp(dbname, "country") == 0)
|
|
|
|
return (dns_geoip_country_code);
|
|
|
|
cfg_obj_log(obj, lctx, ISC_LOG_ERROR,
|
|
|
|
"invalid GeoIP DB specified for "
|
|
|
|
"country search: ignored");
|
|
|
|
return (subtype);
|
|
|
|
case dns_geoip_countrycode3:
|
|
|
|
if (strcasecmp(dbname, "city") == 0)
|
|
|
|
return (dns_geoip_city_countrycode3);
|
|
|
|
else if (strcasecmp(dbname, "country") == 0)
|
|
|
|
return (dns_geoip_country_code3);
|
|
|
|
cfg_obj_log(obj, lctx, ISC_LOG_ERROR,
|
|
|
|
"invalid GeoIP DB specified for "
|
|
|
|
"country search: ignored");
|
|
|
|
return (subtype);
|
|
|
|
case dns_geoip_countryname:
|
|
|
|
if (strcasecmp(dbname, "city") == 0)
|
|
|
|
return (dns_geoip_city_countryname);
|
|
|
|
else if (strcasecmp(dbname, "country") == 0)
|
|
|
|
return (dns_geoip_country_name);
|
|
|
|
cfg_obj_log(obj, lctx, ISC_LOG_ERROR,
|
|
|
|
"invalid GeoIP DB specified for "
|
|
|
|
"country search: ignored");
|
|
|
|
return (subtype);
|
|
|
|
case dns_geoip_region:
|
|
|
|
if (strcasecmp(dbname, "city") == 0)
|
|
|
|
return (dns_geoip_city_region);
|
|
|
|
else if (strcasecmp(dbname, "region") == 0)
|
|
|
|
return (dns_geoip_region_code);
|
|
|
|
cfg_obj_log(obj, lctx, ISC_LOG_ERROR,
|
|
|
|
"invalid GeoIP DB specified for "
|
|
|
|
"region search: ignored");
|
|
|
|
return (subtype);
|
|
|
|
case dns_geoip_regionname:
|
|
|
|
if (strcasecmp(dbname, "city") == 0)
|
|
|
|
return (dns_geoip_city_region);
|
|
|
|
else if (strcasecmp(dbname, "region") == 0)
|
|
|
|
return (dns_geoip_region_name);
|
|
|
|
cfg_obj_log(obj, lctx, ISC_LOG_ERROR,
|
|
|
|
"invalid GeoIP DB specified for "
|
|
|
|
"region search: ignored");
|
|
|
|
return (subtype);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Log a warning if the wrong database was specified
|
|
|
|
* on an unambiguous query
|
|
|
|
*/
|
|
|
|
case dns_geoip_city_name:
|
|
|
|
case dns_geoip_city_postalcode:
|
|
|
|
case dns_geoip_city_metrocode:
|
|
|
|
case dns_geoip_city_areacode:
|
|
|
|
case dns_geoip_city_continentcode:
|
|
|
|
case dns_geoip_city_timezonecode:
|
|
|
|
if (strcasecmp(dbname, "city") != 0)
|
|
|
|
cfg_obj_log(obj, lctx, ISC_LOG_WARNING,
|
|
|
|
"invalid GeoIP DB specified for "
|
|
|
|
"a 'city'-only search type: ignoring");
|
|
|
|
return (subtype);
|
|
|
|
case dns_geoip_isp_name:
|
|
|
|
if (strcasecmp(dbname, "isp") != 0)
|
|
|
|
cfg_obj_log(obj, lctx, ISC_LOG_WARNING,
|
|
|
|
"invalid GeoIP DB specified for "
|
|
|
|
"an 'isp' search: ignoring");
|
|
|
|
return (subtype);
|
|
|
|
case dns_geoip_org_name:
|
|
|
|
if (strcasecmp(dbname, "org") != 0)
|
|
|
|
cfg_obj_log(obj, lctx, ISC_LOG_WARNING,
|
|
|
|
"invalid GeoIP DB specified for "
|
|
|
|
"an 'org' search: ignoring");
|
|
|
|
return (subtype);
|
|
|
|
case dns_geoip_as_asnum:
|
|
|
|
if (strcasecmp(dbname, "asnum") != 0)
|
|
|
|
cfg_obj_log(obj, lctx, ISC_LOG_WARNING,
|
|
|
|
"invalid GeoIP DB specified for "
|
|
|
|
"an 'asnum' search: ignoring");
|
|
|
|
return (subtype);
|
|
|
|
case dns_geoip_domain_name:
|
|
|
|
if (strcasecmp(dbname, "domain") != 0)
|
|
|
|
cfg_obj_log(obj, lctx, ISC_LOG_WARNING,
|
|
|
|
"invalid GeoIP DB specified for "
|
|
|
|
"a 'domain' search: ignoring");
|
|
|
|
return (subtype);
|
|
|
|
case dns_geoip_netspeed_id:
|
|
|
|
if (strcasecmp(dbname, "netspeed") != 0)
|
|
|
|
cfg_obj_log(obj, lctx, ISC_LOG_WARNING,
|
|
|
|
"invalid GeoIP DB specified for "
|
|
|
|
"a 'netspeed' search: ignoring");
|
|
|
|
return (subtype);
|
|
|
|
default:
|
|
|
|
INSIST(0);
|
|
|
|
ISC_UNREACHABLE();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool
|
|
|
|
geoip_can_answer(dns_aclelement_t *elt, cfg_aclconfctx_t *ctx) {
|
|
|
|
if (ctx->geoip == NULL)
|
|
|
|
return (true);
|
|
|
|
|
2013-02-27 17:19:39 -08:00
|
|
|
switch (elt->geoip_elem.subtype) {
|
|
|
|
case dns_geoip_countrycode:
|
|
|
|
case dns_geoip_countrycode3:
|
|
|
|
case dns_geoip_countryname:
|
|
|
|
if (ctx->geoip->city_v4 != NULL ||
|
|
|
|
ctx->geoip->city_v6 != NULL ||
|
|
|
|
ctx->geoip->country_v4 != NULL ||
|
|
|
|
ctx->geoip->country_v6 != NULL ||
|
|
|
|
ctx->geoip->region != NULL)
|
2018-04-17 08:29:14 -07:00
|
|
|
return (true);
|
2017-08-09 00:17:44 -07:00
|
|
|
/* FALLTHROUGH */
|
2013-02-27 17:19:39 -08:00
|
|
|
case dns_geoip_region:
|
|
|
|
case dns_geoip_regionname:
|
|
|
|
if (ctx->geoip->city_v4 != NULL ||
|
|
|
|
ctx->geoip->city_v6 != NULL ||
|
|
|
|
ctx->geoip->region != NULL)
|
2018-04-17 08:29:14 -07:00
|
|
|
return (true);
|
2017-08-09 00:17:44 -07:00
|
|
|
/* FALLTHROUGH */
|
2013-02-27 17:19:39 -08:00
|
|
|
case dns_geoip_country_code:
|
|
|
|
case dns_geoip_country_code3:
|
|
|
|
case dns_geoip_country_name:
|
|
|
|
if (ctx->geoip->country_v4 != NULL ||
|
|
|
|
ctx->geoip->country_v6 != NULL)
|
2018-04-17 08:29:14 -07:00
|
|
|
return (true);
|
2017-08-09 00:17:44 -07:00
|
|
|
/* FALLTHROUGH */
|
2013-02-27 17:19:39 -08:00
|
|
|
case dns_geoip_region_countrycode:
|
|
|
|
case dns_geoip_region_code:
|
|
|
|
case dns_geoip_region_name:
|
|
|
|
if (ctx->geoip->region != NULL)
|
2018-04-17 08:29:14 -07:00
|
|
|
return (true);
|
2017-08-09 00:17:44 -07:00
|
|
|
/* FALLTHROUGH */
|
2013-02-27 17:19:39 -08:00
|
|
|
case dns_geoip_city_countrycode:
|
|
|
|
case dns_geoip_city_countrycode3:
|
|
|
|
case dns_geoip_city_countryname:
|
|
|
|
case dns_geoip_city_region:
|
|
|
|
case dns_geoip_city_regionname:
|
|
|
|
case dns_geoip_city_name:
|
|
|
|
case dns_geoip_city_postalcode:
|
|
|
|
case dns_geoip_city_metrocode:
|
|
|
|
case dns_geoip_city_areacode:
|
|
|
|
case dns_geoip_city_continentcode:
|
|
|
|
case dns_geoip_city_timezonecode:
|
|
|
|
if (ctx->geoip->city_v4 != NULL ||
|
|
|
|
ctx->geoip->city_v6 != NULL)
|
2018-04-17 08:29:14 -07:00
|
|
|
return (true);
|
2017-08-09 00:17:44 -07:00
|
|
|
/* FALLTHROUGH */
|
2013-02-27 17:19:39 -08:00
|
|
|
case dns_geoip_isp_name:
|
2019-06-11 20:32:21 -07:00
|
|
|
if (ctx->geoip->isp != NULL)
|
2018-04-17 08:29:14 -07:00
|
|
|
return (true);
|
2017-08-09 00:17:44 -07:00
|
|
|
/* FALLTHROUGH */
|
2013-02-27 17:19:39 -08:00
|
|
|
case dns_geoip_org_name:
|
2019-06-11 20:32:21 -07:00
|
|
|
if (ctx->geoip->org != NULL)
|
2018-04-17 08:29:14 -07:00
|
|
|
return (true);
|
2017-08-09 00:17:44 -07:00
|
|
|
/* FALLTHROUGH */
|
2013-02-27 17:19:39 -08:00
|
|
|
case dns_geoip_as_asnum:
|
2019-06-11 20:32:21 -07:00
|
|
|
if (ctx->geoip->as != NULL)
|
2018-04-17 08:29:14 -07:00
|
|
|
return (true);
|
2017-08-09 00:17:44 -07:00
|
|
|
/* FALLTHROUGH */
|
2013-02-27 17:19:39 -08:00
|
|
|
case dns_geoip_domain_name:
|
2019-06-11 20:32:21 -07:00
|
|
|
if (ctx->geoip->domain != NULL)
|
2018-04-17 08:29:14 -07:00
|
|
|
return (true);
|
2017-08-09 00:17:44 -07:00
|
|
|
/* FALLTHROUGH */
|
2013-02-27 17:19:39 -08:00
|
|
|
case dns_geoip_netspeed_id:
|
2019-06-11 20:32:21 -07:00
|
|
|
if (ctx->geoip->netspeed != NULL)
|
2018-04-17 08:29:14 -07:00
|
|
|
return (true);
|
2019-06-11 20:32:21 -07:00
|
|
|
/*
|
|
|
|
* The following enums are only valid with GeoIP2,
|
|
|
|
* not legacy GeoIP.
|
|
|
|
*/
|
|
|
|
case dns_geoip_continentcode:
|
|
|
|
case dns_geoip_continent:
|
|
|
|
case dns_geoip_country_continentcode:
|
|
|
|
case dns_geoip_country_continent:
|
|
|
|
case dns_geoip_city_continent:
|
|
|
|
INSIST(0);
|
2013-02-27 17:19:39 -08:00
|
|
|
}
|
|
|
|
|
2018-04-17 08:29:14 -07:00
|
|
|
return (false);
|
2013-02-27 17:19:39 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
static isc_result_t
|
|
|
|
parse_geoip_element(const cfg_obj_t *obj, isc_log_t *lctx,
|
2014-04-30 20:20:56 -07:00
|
|
|
cfg_aclconfctx_t *ctx, dns_aclelement_t *dep)
|
2013-02-27 17:19:39 -08:00
|
|
|
{
|
|
|
|
const cfg_obj_t *ge;
|
|
|
|
const char *dbname = NULL;
|
2019-06-11 20:32:21 -07:00
|
|
|
const char *stype = NULL, *search = NULL;
|
2013-02-27 17:19:39 -08:00
|
|
|
dns_geoip_subtype_t subtype;
|
2014-04-30 20:20:56 -07:00
|
|
|
dns_aclelement_t de;
|
2014-08-28 21:40:32 -07:00
|
|
|
size_t len;
|
2014-04-30 20:20:56 -07:00
|
|
|
|
|
|
|
REQUIRE(dep != NULL);
|
|
|
|
|
|
|
|
de = *dep;
|
2013-02-27 17:19:39 -08:00
|
|
|
|
|
|
|
ge = cfg_tuple_get(obj, "db");
|
2019-06-11 18:36:52 -07:00
|
|
|
if (!cfg_obj_isvoid(ge)) {
|
2019-06-11 20:32:21 -07:00
|
|
|
int i;
|
|
|
|
|
2013-02-27 17:19:39 -08:00
|
|
|
dbname = cfg_obj_asstring(ge);
|
2019-06-11 20:32:21 -07:00
|
|
|
|
|
|
|
for (i = 0; geoip_dbnames[i] != NULL; i++) {
|
|
|
|
if (strcasecmp(dbname, geoip_dbnames[i]) == 0) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (geoip_dbnames[i] == NULL) {
|
|
|
|
cfg_obj_log(obj, lctx, ISC_LOG_ERROR,
|
|
|
|
"database '%s' is not defined for GeoIP",
|
|
|
|
dbname);
|
|
|
|
}
|
2019-06-11 18:36:52 -07:00
|
|
|
}
|
2013-02-27 17:19:39 -08:00
|
|
|
|
|
|
|
stype = cfg_obj_asstring(cfg_tuple_get(obj, "subtype"));
|
|
|
|
search = cfg_obj_asstring(cfg_tuple_get(obj, "search"));
|
2014-08-28 21:40:32 -07:00
|
|
|
len = strlen(search);
|
2013-02-27 17:19:39 -08:00
|
|
|
|
2014-08-28 21:40:32 -07:00
|
|
|
if (len == 0) {
|
|
|
|
cfg_obj_log(obj, lctx, ISC_LOG_ERROR,
|
|
|
|
"zero-length geoip search field");
|
|
|
|
return (ISC_R_FAILURE);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (strcasecmp(stype, "country") == 0 && len == 2) {
|
2013-02-27 17:19:39 -08:00
|
|
|
/* Two-letter country code */
|
|
|
|
subtype = dns_geoip_countrycode;
|
2014-08-28 21:40:32 -07:00
|
|
|
strlcpy(de.geoip_elem.as_string, search,
|
|
|
|
sizeof(de.geoip_elem.as_string));
|
|
|
|
} else if (strcasecmp(stype, "country") == 0 && len == 3) {
|
2013-02-27 17:19:39 -08:00
|
|
|
/* Three-letter country code */
|
|
|
|
subtype = dns_geoip_countrycode3;
|
2014-08-28 21:40:32 -07:00
|
|
|
strlcpy(de.geoip_elem.as_string, search,
|
|
|
|
sizeof(de.geoip_elem.as_string));
|
2013-02-27 17:19:39 -08:00
|
|
|
} else if (strcasecmp(stype, "country") == 0) {
|
|
|
|
/* Country name */
|
|
|
|
subtype = dns_geoip_countryname;
|
2014-08-28 21:40:32 -07:00
|
|
|
strlcpy(de.geoip_elem.as_string, search,
|
|
|
|
sizeof(de.geoip_elem.as_string));
|
|
|
|
} else if (strcasecmp(stype, "region") == 0 && len == 2) {
|
2013-02-27 17:19:39 -08:00
|
|
|
/* Two-letter region code */
|
|
|
|
subtype = dns_geoip_region;
|
2014-08-28 21:40:32 -07:00
|
|
|
strlcpy(de.geoip_elem.as_string, search,
|
|
|
|
sizeof(de.geoip_elem.as_string));
|
2013-02-27 17:19:39 -08:00
|
|
|
} else if (strcasecmp(stype, "region") == 0) {
|
|
|
|
/* Region name */
|
|
|
|
subtype = dns_geoip_regionname;
|
2014-08-28 21:40:32 -07:00
|
|
|
strlcpy(de.geoip_elem.as_string, search,
|
|
|
|
sizeof(de.geoip_elem.as_string));
|
2013-02-27 17:19:39 -08:00
|
|
|
} else if (strcasecmp(stype, "city") == 0) {
|
|
|
|
/* City name */
|
|
|
|
subtype = dns_geoip_city_name;
|
2014-08-28 21:40:32 -07:00
|
|
|
strlcpy(de.geoip_elem.as_string, search,
|
|
|
|
sizeof(de.geoip_elem.as_string));
|
2015-12-26 10:50:32 -08:00
|
|
|
} else if (strcasecmp(stype, "postal") == 0 ||
|
|
|
|
strcasecmp(stype, "postalcode") == 0)
|
|
|
|
{
|
|
|
|
if (len < 7) {
|
|
|
|
subtype = dns_geoip_city_postalcode;
|
|
|
|
strlcpy(de.geoip_elem.as_string, search,
|
|
|
|
sizeof(de.geoip_elem.as_string));
|
|
|
|
} else {
|
|
|
|
cfg_obj_log(obj, lctx, ISC_LOG_ERROR,
|
|
|
|
"geoiop postal code (%s) too long",
|
|
|
|
search);
|
|
|
|
return (ISC_R_FAILURE);
|
|
|
|
}
|
|
|
|
} else if (strcasecmp(stype, "metro") == 0 ||
|
|
|
|
strcasecmp(stype, "metrocode") == 0)
|
|
|
|
{
|
2013-02-27 17:19:39 -08:00
|
|
|
subtype = dns_geoip_city_metrocode;
|
2014-04-30 20:20:56 -07:00
|
|
|
de.geoip_elem.as_int = atoi(search);
|
2015-12-26 10:50:32 -08:00
|
|
|
} else if (strcasecmp(stype, "area") == 0 ||
|
|
|
|
strcasecmp(stype, "areacode") == 0)
|
|
|
|
{
|
2013-02-27 17:19:39 -08:00
|
|
|
subtype = dns_geoip_city_areacode;
|
2014-04-30 20:20:56 -07:00
|
|
|
de.geoip_elem.as_int = atoi(search);
|
2015-12-26 10:50:32 -08:00
|
|
|
} else if (strcasecmp(stype, "tz") == 0 ||
|
|
|
|
strcasecmp(stype, "timezone") == 0)
|
|
|
|
{
|
2013-02-27 17:19:39 -08:00
|
|
|
subtype = dns_geoip_city_timezonecode;
|
2014-08-28 21:40:32 -07:00
|
|
|
strlcpy(de.geoip_elem.as_string, search,
|
|
|
|
sizeof(de.geoip_elem.as_string));
|
|
|
|
} else if (strcasecmp(stype, "continent") == 0 && len == 2) {
|
2013-02-27 17:19:39 -08:00
|
|
|
/* Two-letter continent code */
|
|
|
|
subtype = dns_geoip_city_continentcode;
|
2014-08-28 21:40:32 -07:00
|
|
|
strlcpy(de.geoip_elem.as_string, search,
|
|
|
|
sizeof(de.geoip_elem.as_string));
|
|
|
|
} else if (strcasecmp(stype, "continent") == 0) {
|
|
|
|
cfg_obj_log(obj, lctx, ISC_LOG_ERROR,
|
|
|
|
"geoiop continent code (%s) too long", search);
|
|
|
|
return (ISC_R_FAILURE);
|
2013-02-27 17:19:39 -08:00
|
|
|
} else if (strcasecmp(stype, "isp") == 0) {
|
|
|
|
subtype = dns_geoip_isp_name;
|
2014-08-28 21:40:32 -07:00
|
|
|
strlcpy(de.geoip_elem.as_string, search,
|
|
|
|
sizeof(de.geoip_elem.as_string));
|
2013-02-27 17:19:39 -08:00
|
|
|
} else if (strcasecmp(stype, "asnum") == 0) {
|
|
|
|
subtype = dns_geoip_as_asnum;
|
2014-08-28 21:40:32 -07:00
|
|
|
strlcpy(de.geoip_elem.as_string, search,
|
|
|
|
sizeof(de.geoip_elem.as_string));
|
2013-02-27 17:19:39 -08:00
|
|
|
} else if (strcasecmp(stype, "org") == 0) {
|
|
|
|
subtype = dns_geoip_org_name;
|
2014-08-28 21:40:32 -07:00
|
|
|
strlcpy(de.geoip_elem.as_string, search,
|
|
|
|
sizeof(de.geoip_elem.as_string));
|
2013-02-27 17:19:39 -08:00
|
|
|
} else if (strcasecmp(stype, "domain") == 0) {
|
|
|
|
subtype = dns_geoip_domain_name;
|
2014-08-28 21:40:32 -07:00
|
|
|
strlcpy(de.geoip_elem.as_string, search,
|
|
|
|
sizeof(de.geoip_elem.as_string));
|
2013-02-27 17:19:39 -08:00
|
|
|
} else if (strcasecmp(stype, "netspeed") == 0) {
|
|
|
|
subtype = dns_geoip_netspeed_id;
|
2014-04-30 20:20:56 -07:00
|
|
|
de.geoip_elem.as_int = atoi(search);
|
2018-11-07 15:00:07 +07:00
|
|
|
} else {
|
2013-02-27 17:19:39 -08:00
|
|
|
INSIST(0);
|
2018-11-07 15:00:07 +07:00
|
|
|
ISC_UNREACHABLE();
|
|
|
|
}
|
2013-02-27 17:19:39 -08:00
|
|
|
|
2014-04-30 20:20:56 -07:00
|
|
|
de.geoip_elem.subtype = get_subtype(obj, lctx, subtype, dbname);
|
2013-02-27 17:19:39 -08:00
|
|
|
|
2014-04-30 20:20:56 -07:00
|
|
|
if (! geoip_can_answer(&de, ctx)) {
|
2013-02-27 17:19:39 -08:00
|
|
|
cfg_obj_log(obj, lctx, ISC_LOG_ERROR,
|
|
|
|
"no GeoIP database installed which can answer "
|
|
|
|
"queries of type '%s'", stype);
|
|
|
|
return (ISC_R_FAILURE);
|
|
|
|
}
|
|
|
|
|
2014-04-30 20:20:56 -07:00
|
|
|
*dep = de;
|
|
|
|
|
2013-02-27 17:19:39 -08:00
|
|
|
return (ISC_R_SUCCESS);
|
|
|
|
}
|
2019-06-11 20:32:21 -07:00
|
|
|
#endif /* HAVE_GEOIP */
|
2013-02-27 17:19:39 -08:00
|
|
|
|
1999-12-16 23:11:07 +00:00
|
|
|
isc_result_t
|
2014-03-07 11:31:51 -08:00
|
|
|
cfg_acl_fromconfig(const cfg_obj_t *caml, const cfg_obj_t *cctx,
|
|
|
|
isc_log_t *lctx, cfg_aclconfctx_t *ctx,
|
|
|
|
isc_mem_t *mctx, unsigned int nest_level,
|
2005-01-11 03:46:11 +00:00
|
|
|
dns_acl_t **target)
|
2014-03-07 11:31:51 -08:00
|
|
|
{
|
|
|
|
return (cfg_acl_fromconfig2(caml, cctx, lctx, ctx, mctx,
|
|
|
|
nest_level, 0, target));
|
|
|
|
}
|
|
|
|
|
|
|
|
isc_result_t
|
|
|
|
cfg_acl_fromconfig2(const cfg_obj_t *caml, const cfg_obj_t *cctx,
|
|
|
|
isc_log_t *lctx, cfg_aclconfctx_t *ctx,
|
|
|
|
isc_mem_t *mctx, unsigned int nest_level,
|
2018-03-28 14:19:37 +02:00
|
|
|
uint16_t family, dns_acl_t **target)
|
1999-12-16 23:11:07 +00:00
|
|
|
{
|
|
|
|
isc_result_t result;
|
2007-09-12 01:09:08 +00:00
|
|
|
dns_acl_t *dacl = NULL, *inneracl = NULL;
|
1999-12-16 23:11:07 +00:00
|
|
|
dns_aclelement_t *de;
|
2006-02-28 02:39:52 +00:00
|
|
|
const cfg_listelt_t *elt;
|
2007-09-14 01:46:06 +00:00
|
|
|
dns_iptable_t *iptab;
|
2007-12-21 06:46:47 +00:00
|
|
|
int new_nest_level = 0;
|
2018-04-17 08:29:14 -07:00
|
|
|
bool setpos;
|
2007-12-21 06:46:47 +00:00
|
|
|
|
|
|
|
if (nest_level != 0)
|
|
|
|
new_nest_level = nest_level - 1;
|
1999-12-16 23:11:07 +00:00
|
|
|
|
2007-09-12 01:09:08 +00:00
|
|
|
REQUIRE(target != NULL);
|
2007-09-14 01:46:06 +00:00
|
|
|
REQUIRE(*target == NULL || DNS_ACL_VALID(*target));
|
2000-08-01 01:33:37 +00:00
|
|
|
|
2007-09-14 01:46:06 +00:00
|
|
|
if (*target != NULL) {
|
|
|
|
/*
|
|
|
|
* If target already points to an ACL, then we're being
|
|
|
|
* called recursively to configure a nested ACL. The
|
|
|
|
* nested ACL's contents should just be absorbed into its
|
|
|
|
* parent ACL.
|
|
|
|
*/
|
2007-10-12 04:17:18 +00:00
|
|
|
dns_acl_attach(*target, &dacl);
|
|
|
|
dns_acl_detach(target);
|
2007-09-14 01:46:06 +00:00
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* Need to allocate a new ACL structure. Count the items
|
2008-10-24 02:28:55 +00:00
|
|
|
* in the ACL definition that will require space in the
|
2009-01-18 18:02:14 +00:00
|
|
|
* elements table. (Note that if nest_level is nonzero,
|
2008-10-24 02:28:55 +00:00
|
|
|
* *everything* goes in the elements table.)
|
2007-09-14 01:46:06 +00:00
|
|
|
*/
|
2018-03-28 14:19:37 +02:00
|
|
|
uint32_t nelem;
|
2008-10-24 02:28:55 +00:00
|
|
|
|
2014-08-03 10:05:02 +10:00
|
|
|
if (nest_level == 0) {
|
|
|
|
result = count_acl_elements(caml, cctx, lctx, ctx,
|
|
|
|
mctx, &nelem, NULL);
|
|
|
|
if (result != ISC_R_SUCCESS)
|
|
|
|
return (result);
|
2019-06-11 18:36:52 -07:00
|
|
|
} else {
|
2018-04-17 08:29:14 -07:00
|
|
|
nelem = cfg_list_length(caml, false);
|
2019-06-11 18:36:52 -07:00
|
|
|
}
|
2008-10-24 02:28:55 +00:00
|
|
|
|
|
|
|
result = dns_acl_create(mctx, nelem, &dacl);
|
2019-06-11 18:36:52 -07:00
|
|
|
if (result != ISC_R_SUCCESS) {
|
2007-09-14 01:46:06 +00:00
|
|
|
return (result);
|
2019-06-11 18:36:52 -07:00
|
|
|
}
|
2007-09-14 01:46:06 +00:00
|
|
|
}
|
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;
|
2008-10-24 02:28:55 +00:00
|
|
|
elt = cfg_list_next(elt)) {
|
2006-02-28 02:39:52 +00:00
|
|
|
const cfg_obj_t *ce = cfg_listelt_value(elt);
|
2018-04-17 08:29:14 -07:00
|
|
|
bool neg = false;
|
2007-09-12 01:09:08 +00:00
|
|
|
|
2014-08-03 10:05:02 +10:00
|
|
|
INSIST(dacl->length <= dacl->alloc);
|
|
|
|
|
2001-03-04 21:21:39 +00:00
|
|
|
if (cfg_obj_istuple(ce)) {
|
2013-02-27 17:19:39 -08:00
|
|
|
/* Might be a negated element */
|
|
|
|
const cfg_obj_t *negated =
|
|
|
|
cfg_tuple_get(ce, "negated");
|
|
|
|
if (! cfg_obj_isvoid(negated)) {
|
2018-04-17 08:29:14 -07:00
|
|
|
neg = true;
|
|
|
|
dacl->has_negatives = true;
|
2013-02-27 17:19:39 -08:00
|
|
|
ce = negated;
|
|
|
|
}
|
|
|
|
}
|
2007-09-12 01:09:08 +00:00
|
|
|
|
2007-09-14 01:46:06 +00:00
|
|
|
/*
|
|
|
|
* If nest_level is nonzero, then every element is
|
|
|
|
* to be stored as a separate, nested ACL rather than
|
|
|
|
* merged into the main iptable.
|
|
|
|
*/
|
|
|
|
iptab = dacl->iptable;
|
2007-10-12 04:17:18 +00:00
|
|
|
|
|
|
|
if (nest_level != 0) {
|
|
|
|
result = dns_acl_create(mctx,
|
2018-04-17 08:29:14 -07:00
|
|
|
cfg_list_length(ce, false),
|
2007-09-14 01:46:06 +00:00
|
|
|
&de->nestedacl);
|
2019-06-11 18:36:52 -07:00
|
|
|
if (result != ISC_R_SUCCESS) {
|
2007-09-14 01:46:06 +00:00
|
|
|
goto cleanup;
|
2019-06-11 18:36:52 -07:00
|
|
|
}
|
2007-09-14 01:46:06 +00:00
|
|
|
iptab = de->nestedacl->iptable;
|
|
|
|
}
|
2001-03-04 21:21:39 +00:00
|
|
|
|
|
|
|
if (cfg_obj_isnetprefix(ce)) {
|
|
|
|
/* Network prefix */
|
2007-09-14 01:46:06 +00:00
|
|
|
isc_netaddr_t addr;
|
|
|
|
unsigned int bitlen;
|
2001-03-04 21:21:39 +00:00
|
|
|
|
2007-09-14 01:46:06 +00:00
|
|
|
cfg_obj_asnetprefix(ce, &addr, &bitlen);
|
2014-03-07 11:31:51 -08:00
|
|
|
if (family != 0 && family != addr.family) {
|
|
|
|
char buf[ISC_NETADDR_FORMATSIZE + 1];
|
|
|
|
isc_netaddr_format(&addr, buf, sizeof(buf));
|
|
|
|
cfg_obj_log(ce, lctx, ISC_LOG_WARNING,
|
|
|
|
"'%s': incorrect address family; "
|
|
|
|
"ignoring", buf);
|
2019-06-11 18:36:52 -07:00
|
|
|
if (nest_level != 0) {
|
2014-03-07 11:31:51 -08:00
|
|
|
dns_acl_detach(&de->nestedacl);
|
2019-06-11 18:36:52 -07:00
|
|
|
}
|
2014-03-07 11:31:51 -08:00
|
|
|
continue;
|
|
|
|
}
|
2016-10-11 14:52:28 +11:00
|
|
|
result = isc_netaddr_prefixok(&addr, bitlen);
|
|
|
|
if (result != ISC_R_SUCCESS) {
|
|
|
|
char buf[ISC_NETADDR_FORMATSIZE + 1];
|
|
|
|
isc_netaddr_format(&addr, buf, sizeof(buf));
|
2016-10-11 15:06:15 +11:00
|
|
|
cfg_obj_log(ce, lctx, ISC_LOG_ERROR,
|
2016-10-11 14:52:28 +11:00
|
|
|
"'%s/%u': address/prefix length "
|
|
|
|
"mismatch", buf, bitlen);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2007-10-18 05:42:03 +00:00
|
|
|
|
2007-12-21 06:46:47 +00:00
|
|
|
/*
|
|
|
|
* If nesting ACLs (nest_level != 0), we negate
|
|
|
|
* the nestedacl element, not the iptable entry.
|
|
|
|
*/
|
2018-04-17 08:29:14 -07:00
|
|
|
setpos = (nest_level != 0 || !neg);
|
2018-04-05 16:23:56 +02:00
|
|
|
result = dns_iptable_addprefix(iptab, &addr, bitlen,
|
2018-04-26 20:57:41 -07:00
|
|
|
setpos);
|
2019-06-11 18:36:52 -07:00
|
|
|
if (result != ISC_R_SUCCESS) {
|
1999-12-16 23:11:07 +00:00
|
|
|
goto cleanup;
|
2019-06-11 18:36:52 -07:00
|
|
|
}
|
2007-09-14 01:46:06 +00:00
|
|
|
|
2007-12-21 06:46:47 +00:00
|
|
|
if (nest_level > 0) {
|
2014-08-03 10:05:02 +10:00
|
|
|
INSIST(dacl->length < dacl->alloc);
|
2007-09-14 01:46:06 +00:00
|
|
|
de->type = dns_aclelementtype_nestedacl;
|
|
|
|
de->negative = neg;
|
2019-06-11 18:36:52 -07:00
|
|
|
} else {
|
2007-09-14 01:46:06 +00:00
|
|
|
continue;
|
2019-06-11 18:36:52 -07:00
|
|
|
}
|
2001-03-04 21:21:39 +00:00
|
|
|
} else if (cfg_obj_islist(ce)) {
|
2007-09-14 01:46:06 +00:00
|
|
|
/*
|
|
|
|
* If we're nesting ACLs, put the nested
|
|
|
|
* ACL onto the elements list; otherwise
|
2007-12-21 06:46:47 +00:00
|
|
|
* merge it into *this* ACL. We nest ACLs
|
|
|
|
* in two cases: 1) sortlist, 2) if the
|
|
|
|
* nested ACL contains negated members.
|
2007-09-14 01:46:06 +00:00
|
|
|
*/
|
2019-06-11 18:36:52 -07:00
|
|
|
if (inneracl != NULL) {
|
2007-12-21 06:46:47 +00:00
|
|
|
dns_acl_detach(&inneracl);
|
2019-06-11 18:36:52 -07:00
|
|
|
}
|
2007-12-21 06:46:47 +00:00
|
|
|
result = cfg_acl_fromconfig(ce, cctx, lctx,
|
|
|
|
ctx, mctx, new_nest_level,
|
|
|
|
&inneracl);
|
2019-06-11 18:36:52 -07:00
|
|
|
if (result != ISC_R_SUCCESS) {
|
2007-12-21 06:46:47 +00:00
|
|
|
goto cleanup;
|
2019-06-11 18:36:52 -07:00
|
|
|
}
|
2007-12-21 06:46:47 +00:00
|
|
|
nested_acl:
|
|
|
|
if (nest_level > 0 || inneracl->has_negatives) {
|
2014-08-03 10:05:02 +10:00
|
|
|
INSIST(dacl->length < dacl->alloc);
|
2007-12-21 06:46:47 +00:00
|
|
|
de->type = dns_aclelementtype_nestedacl;
|
|
|
|
de->negative = neg;
|
2019-06-11 18:36:52 -07:00
|
|
|
if (de->nestedacl != NULL) {
|
2007-12-21 06:46:47 +00:00
|
|
|
dns_acl_detach(&de->nestedacl);
|
2019-06-11 18:36:52 -07:00
|
|
|
}
|
|
|
|
dns_acl_attach(inneracl, &de->nestedacl);
|
2007-12-21 06:46:47 +00:00
|
|
|
dns_acl_detach(&inneracl);
|
|
|
|
/* Fall through. */
|
|
|
|
} else {
|
2014-08-03 10:05:02 +10:00
|
|
|
INSIST(dacl->length + inneracl->length
|
|
|
|
<= dacl->alloc);
|
2019-06-11 18:36:52 -07:00
|
|
|
dns_acl_merge(dacl, inneracl, !neg);
|
2008-07-19 00:09:44 +00:00
|
|
|
de += inneracl->length; /* elements added */
|
2007-10-19 00:28:20 +00:00
|
|
|
dns_acl_detach(&inneracl);
|
2014-08-03 10:05:02 +10:00
|
|
|
INSIST(dacl->length <= dacl->alloc);
|
2007-09-14 01:46:06 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
} else if (cfg_obj_istype(ce, &cfg_type_keyref)) {
|
2007-12-21 06:46:47 +00:00
|
|
|
/* Key name. */
|
2014-08-03 10:05:02 +10:00
|
|
|
INSIST(dacl->length < dacl->alloc);
|
2007-09-14 01:46:06 +00:00
|
|
|
de->type = dns_aclelementtype_keyname;
|
|
|
|
de->negative = neg;
|
|
|
|
dns_name_init(&de->keyname, NULL);
|
|
|
|
result = convert_keyname(ce, lctx, mctx,
|
|
|
|
&de->keyname);
|
2019-06-11 18:36:52 -07:00
|
|
|
if (result != ISC_R_SUCCESS) {
|
2007-09-14 01:46:06 +00:00
|
|
|
goto cleanup;
|
2019-06-11 18:36:52 -07:00
|
|
|
}
|
|
|
|
#if defined(HAVE_GEOIP) || defined(HAVE_GEOIP2)
|
2013-02-27 17:19:39 -08:00
|
|
|
} else if (cfg_obj_istuple(ce) &&
|
|
|
|
cfg_obj_isvoid(cfg_tuple_get(ce, "negated")))
|
|
|
|
{
|
2014-08-03 10:05:02 +10:00
|
|
|
INSIST(dacl->length < dacl->alloc);
|
2013-02-27 17:19:39 -08:00
|
|
|
result = parse_geoip_element(ce, lctx, ctx, de);
|
2019-06-11 18:36:52 -07:00
|
|
|
if (result != ISC_R_SUCCESS) {
|
2013-02-27 17:19:39 -08:00
|
|
|
goto cleanup;
|
2019-06-11 18:36:52 -07:00
|
|
|
}
|
2013-02-27 17:19:39 -08:00
|
|
|
de->type = dns_aclelementtype_geoip;
|
|
|
|
de->negative = neg;
|
2019-06-11 18:36:52 -07:00
|
|
|
#endif /* HAVE_GEOIP || HAVE_GEOIP2 */
|
2001-03-04 21:21:39 +00:00
|
|
|
} else if (cfg_obj_isstring(ce)) {
|
2007-12-21 06:46:47 +00:00
|
|
|
/* ACL name. */
|
2005-08-23 02:36:11 +00:00
|
|
|
const char *name = cfg_obj_asstring(ce);
|
2007-09-14 01:46:06 +00:00
|
|
|
if (strcasecmp(name, "any") == 0) {
|
2007-12-21 06:46:47 +00:00
|
|
|
/* Iptable entry with zero bit length. */
|
2018-04-17 08:29:14 -07:00
|
|
|
setpos = (nest_level != 0 || !neg);
|
2007-11-19 23:13:28 +00:00
|
|
|
result = dns_iptable_addprefix(iptab, NULL, 0,
|
2018-04-26 20:57:41 -07:00
|
|
|
setpos);
|
2019-06-11 18:36:52 -07:00
|
|
|
if (result != ISC_R_SUCCESS) {
|
2007-12-21 06:46:47 +00:00
|
|
|
goto cleanup;
|
2019-06-11 18:36:52 -07:00
|
|
|
}
|
2007-12-21 06:46:47 +00:00
|
|
|
|
|
|
|
if (nest_level != 0) {
|
2014-08-03 10:05:02 +10:00
|
|
|
INSIST(dacl->length < dacl->alloc);
|
2007-12-21 06:46:47 +00:00
|
|
|
de->type = dns_aclelementtype_nestedacl;
|
|
|
|
de->negative = neg;
|
2019-06-11 18:36:52 -07:00
|
|
|
} else {
|
2007-12-21 06:46:47 +00:00
|
|
|
continue;
|
2019-06-11 18:36:52 -07:00
|
|
|
}
|
2007-09-12 01:09:08 +00:00
|
|
|
} else if (strcasecmp(name, "none") == 0) {
|
2007-12-21 06:46:47 +00:00
|
|
|
/* none == !any */
|
|
|
|
/*
|
|
|
|
* We don't unconditional set
|
|
|
|
* dacl->has_negatives and
|
|
|
|
* de->negative to true so we can handle
|
|
|
|
* "!none;".
|
|
|
|
*/
|
2018-04-17 08:29:14 -07:00
|
|
|
setpos = (nest_level != 0 || neg);
|
2007-11-19 23:13:28 +00:00
|
|
|
result = dns_iptable_addprefix(iptab, NULL, 0,
|
2018-04-26 20:57:41 -07:00
|
|
|
setpos);
|
2019-06-11 18:36:52 -07:00
|
|
|
if (result != ISC_R_SUCCESS) {
|
2007-12-21 06:46:47 +00:00
|
|
|
goto cleanup;
|
2019-06-11 18:36:52 -07:00
|
|
|
}
|
2007-12-21 06:46:47 +00:00
|
|
|
|
2019-06-11 18:36:52 -07:00
|
|
|
if (!neg) {
|
2007-12-21 06:46:47 +00:00
|
|
|
dacl->has_negatives = !neg;
|
2019-06-11 18:36:52 -07:00
|
|
|
}
|
2007-12-21 06:46:47 +00:00
|
|
|
|
|
|
|
if (nest_level != 0) {
|
2014-08-03 10:05:02 +10:00
|
|
|
INSIST(dacl->length < dacl->alloc);
|
2007-12-21 06:46:47 +00:00
|
|
|
de->type = dns_aclelementtype_nestedacl;
|
|
|
|
de->negative = !neg;
|
2019-06-11 18:36:52 -07:00
|
|
|
} else {
|
2007-12-21 06:46:47 +00:00
|
|
|
continue;
|
2019-06-11 18:36:52 -07:00
|
|
|
}
|
2007-09-12 01:09:08 +00:00
|
|
|
} else if (strcasecmp(name, "localhost") == 0) {
|
2014-08-03 10:05:02 +10:00
|
|
|
INSIST(dacl->length < dacl->alloc);
|
2001-03-04 21:21:39 +00:00
|
|
|
de->type = dns_aclelementtype_localhost;
|
2007-09-14 01:46:06 +00:00
|
|
|
de->negative = neg;
|
2001-03-04 21:21:39 +00:00
|
|
|
} else if (strcasecmp(name, "localnets") == 0) {
|
2014-08-03 10:05:02 +10:00
|
|
|
INSIST(dacl->length < dacl->alloc);
|
2001-03-04 21:21:39 +00:00
|
|
|
de->type = dns_aclelementtype_localnets;
|
2007-09-14 01:46:06 +00:00
|
|
|
de->negative = neg;
|
2001-03-04 21:21:39 +00:00
|
|
|
} else {
|
2007-12-18 01:53:26 +00:00
|
|
|
if (inneracl != NULL)
|
|
|
|
dns_acl_detach(&inneracl);
|
2014-08-03 10:05:02 +10:00
|
|
|
/*
|
|
|
|
* This call should just find the cached
|
|
|
|
* of the named acl.
|
|
|
|
*/
|
2007-12-18 01:53:26 +00:00
|
|
|
result = convert_named_acl(ce, cctx, lctx, ctx,
|
|
|
|
mctx, new_nest_level,
|
|
|
|
&inneracl);
|
2019-06-11 18:36:52 -07:00
|
|
|
if (result != ISC_R_SUCCESS) {
|
2001-03-04 21:21:39 +00:00
|
|
|
goto cleanup;
|
2019-06-11 18:36:52 -07:00
|
|
|
}
|
2007-09-12 01:09:08 +00:00
|
|
|
|
2007-12-21 06:46:47 +00:00
|
|
|
goto nested_acl;
|
2001-03-04 21:21:39 +00:00
|
|
|
}
|
|
|
|
} 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;
|
|
|
|
}
|
2007-09-12 01:09:08 +00:00
|
|
|
|
2007-09-14 01:46:06 +00:00
|
|
|
/*
|
|
|
|
* This should only be reached for localhost, localnets
|
|
|
|
* and keyname elements, and nested ACLs if nest_level is
|
2008-05-21 23:47:01 +00:00
|
|
|
* nonzero (i.e., in sortlists).
|
2007-09-14 01:46:06 +00:00
|
|
|
*/
|
2007-10-12 04:17:18 +00:00
|
|
|
if (de->nestedacl != NULL &&
|
|
|
|
de->type != dns_aclelementtype_nestedacl)
|
2019-06-11 18:36:52 -07:00
|
|
|
{
|
2007-09-14 01:46:06 +00:00
|
|
|
dns_acl_detach(&de->nestedacl);
|
2019-06-11 18:36:52 -07:00
|
|
|
}
|
2007-09-14 01:46:06 +00:00
|
|
|
|
|
|
|
dacl->node_count++;
|
|
|
|
de->node_num = dacl->node_count;
|
2007-09-12 01:09:08 +00:00
|
|
|
|
1999-12-16 23:11:07 +00:00
|
|
|
dacl->length++;
|
2007-12-21 06:46:47 +00:00
|
|
|
de++;
|
2007-09-14 01:46:06 +00:00
|
|
|
INSIST(dacl->length <= dacl->alloc);
|
1999-12-16 23:11:07 +00:00
|
|
|
}
|
|
|
|
|
2007-10-12 04:17:18 +00:00
|
|
|
dns_acl_attach(dacl, target);
|
|
|
|
result = ISC_R_SUCCESS;
|
2000-08-01 01:33:37 +00:00
|
|
|
|
1999-12-16 23:11:07 +00:00
|
|
|
cleanup:
|
2019-06-11 18:36:52 -07:00
|
|
|
if (inneracl != NULL) {
|
2007-10-12 04:17:18 +00:00
|
|
|
dns_acl_detach(&inneracl);
|
2019-06-11 18:36:52 -07:00
|
|
|
}
|
1999-12-16 23:11:07 +00:00
|
|
|
dns_acl_detach(&dacl);
|
|
|
|
return (result);
|
|
|
|
}
|