Fix dns_kasp_attach / dns_kasp_detach usage

The kasp pointers in dns_zone_t should consistently be changed by
dns_kasp_attach and dns_kasp_detach so the usage is balanced.

(cherry picked from commit b41882cc75)
This commit is contained in:
Mark Andrews 2023-02-21 12:15:01 +11:00 committed by Matthijs Mekking
parent 6906a0b185
commit 87602eecd7
2 changed files with 77 additions and 71 deletions

View file

@ -935,8 +935,8 @@ named_zone_configure(const cfg_obj_t *config, const cfg_obj_t *vconfig,
maps[i] = NULL;
if (vconfig != NULL) {
RETERR(named_config_getclass(cfg_tuple_get(vconfig, "class"),
dns_rdataclass_in, &vclass));
CHECK(named_config_getclass(cfg_tuple_get(vconfig, "class"),
dns_rdataclass_in, &vclass));
} else {
vclass = dns_rdataclass_in;
}
@ -947,8 +947,8 @@ named_zone_configure(const cfg_obj_t *config, const cfg_obj_t *vconfig,
zname = cfg_obj_asstring(cfg_tuple_get(zconfig, "name"));
RETERR(named_config_getclass(cfg_tuple_get(zconfig, "class"), vclass,
&zclass));
CHECK(named_config_getclass(cfg_tuple_get(zconfig, "class"), vclass,
&zclass));
dns_zone_setclass(zone, zclass);
if (raw != NULL) {
dns_zone_setclass(raw, zclass);
@ -968,7 +968,7 @@ named_zone_configure(const cfg_obj_t *config, const cfg_obj_t *vconfig,
cpval = isc_mem_strdup(mctx, cfg_obj_asstring(obj));
}
if (cpval == NULL) {
return (ISC_R_NOMEMORY);
CHECK(ISC_R_NOMEMORY);
}
obj = NULL;
@ -983,7 +983,7 @@ named_zone_configure(const cfg_obj_t *config, const cfg_obj_t *vconfig,
"zone '%s': both 'database' and 'dlz' "
"specified",
zname);
return (ISC_R_FAILURE);
CHECK(ISC_R_FAILURE);
}
len = strlen(dlzname) + 5;
@ -994,7 +994,7 @@ named_zone_configure(const cfg_obj_t *config, const cfg_obj_t *vconfig,
result = strtoargv(mctx, cpval, &dbargc, &dbargv);
if (result != ISC_R_SUCCESS && cpval != default_dbtype) {
isc_mem_free(mctx, cpval);
return (result);
CHECK(result);
}
/*
@ -1024,7 +1024,7 @@ named_zone_configure(const cfg_obj_t *config, const cfg_obj_t *vconfig,
isc_log_write(named_g_lctx, NAMED_LOGCATEGORY_GENERAL,
NAMED_LOGMODULE_SERVER, ISC_LOG_ERROR,
"zone '%s': 'file' not specified", zname);
return (ISC_R_FAILURE);
CHECK(ISC_R_FAILURE);
}
if (ztype == dns_zone_secondary || ztype == dns_zone_mirror) {
@ -1057,7 +1057,7 @@ named_zone_configure(const cfg_obj_t *config, const cfg_obj_t *vconfig,
"can only be used with "
"'masterfile-format text'",
zname);
return (ISC_R_FAILURE);
CHECK(ISC_R_FAILURE);
}
if (strcasecmp(masterstylestr, "full") == 0) {
@ -1082,47 +1082,45 @@ named_zone_configure(const cfg_obj_t *config, const cfg_obj_t *vconfig,
size_t signedlen = strlen(filename) + sizeof(SIGNED);
char *signedname;
RETERR(dns_zone_setfile(raw, filename, masterformat,
masterstyle));
CHECK(dns_zone_setfile(raw, filename, masterformat,
masterstyle));
signedname = isc_mem_get(mctx, signedlen);
(void)snprintf(signedname, signedlen, "%s" SIGNED, filename);
result = dns_zone_setfile(zone, signedname,
dns_masterformat_raw, NULL);
isc_mem_put(mctx, signedname, signedlen);
if (result != ISC_R_SUCCESS) {
return (result);
}
CHECK(result);
} else {
RETERR(dns_zone_setfile(zone, filename, masterformat,
masterstyle));
CHECK(dns_zone_setfile(zone, filename, masterformat,
masterstyle));
}
obj = NULL;
result = cfg_map_get(zoptions, "journal", &obj);
if (result == ISC_R_SUCCESS) {
RETERR(dns_zone_setjournal(mayberaw, cfg_obj_asstring(obj)));
CHECK(dns_zone_setjournal(mayberaw, cfg_obj_asstring(obj)));
}
/*
* Notify messages are processed by the raw zone if it exists.
*/
if (ztype == dns_zone_secondary || ztype == dns_zone_mirror) {
RETERR(configure_zone_acl(
zconfig, vconfig, config, allow_notify, ac, mayberaw,
dns_zone_setnotifyacl, dns_zone_clearnotifyacl));
CHECK(configure_zone_acl(zconfig, vconfig, config, allow_notify,
ac, mayberaw, dns_zone_setnotifyacl,
dns_zone_clearnotifyacl));
}
/*
* XXXAG This probably does not make sense for stubs.
*/
RETERR(configure_zone_acl(zconfig, vconfig, config, allow_query, ac,
zone, dns_zone_setqueryacl,
dns_zone_clearqueryacl));
CHECK(configure_zone_acl(zconfig, vconfig, config, allow_query, ac,
zone, dns_zone_setqueryacl,
dns_zone_clearqueryacl));
RETERR(configure_zone_acl(zconfig, vconfig, config, allow_query_on, ac,
zone, dns_zone_setqueryonacl,
dns_zone_clearqueryonacl));
CHECK(configure_zone_acl(zconfig, vconfig, config, allow_query_on, ac,
zone, dns_zone_setqueryonacl,
dns_zone_clearqueryonacl));
obj = NULL;
result = named_config_get(maps, "dialup", &obj);
@ -1179,10 +1177,10 @@ named_zone_configure(const cfg_obj_t *config, const cfg_obj_t *vconfig,
rcvquerystats = NULL;
dnssecsignstats = NULL;
if (statlevel == dns_zonestat_full) {
RETERR(isc_stats_create(mctx, &zoneqrystats,
ns_statscounter_max));
RETERR(dns_rdatatypestats_create(mctx, &rcvquerystats));
RETERR(dns_dnssecsignstats_create(mctx, &dnssecsignstats));
CHECK(isc_stats_create(mctx, &zoneqrystats,
ns_statscounter_max));
CHECK(dns_rdatatypestats_create(mctx, &rcvquerystats));
CHECK(dns_dnssecsignstats_create(mctx, &dnssecsignstats));
}
dns_zone_setrequeststats(zone, zoneqrystats);
dns_zone_setrcvquerystats(zone, rcvquerystats);
@ -1221,7 +1219,7 @@ named_zone_configure(const cfg_obj_t *config, const cfg_obj_t *vconfig,
ISC_LOG_ERROR,
"dnssec-policy '%s' not found ",
kaspname);
RETERR(result);
CHECK(result);
}
dns_zone_setkasp(zone, kasp);
use_kasp = true;
@ -1270,8 +1268,8 @@ named_zone_configure(const cfg_obj_t *config, const cfg_obj_t *vconfig,
dns_ipkeylist_t ipkl;
dns_ipkeylist_init(&ipkl);
RETERR(named_config_getipandkeylist(config, "primaries",
obj, mctx, &ipkl));
CHECK(named_config_getipandkeylist(config, "primaries",
obj, mctx, &ipkl));
dns_zone_setalsonotify(zone, ipkl.addrs, ipkl.keys,
ipkl.tlss, ipkl.count);
dns_ipkeylist_clear(mctx, &ipkl);
@ -1282,28 +1280,30 @@ named_zone_configure(const cfg_obj_t *config, const cfg_obj_t *vconfig,
obj = NULL;
result = named_config_get(maps, "parental-source", &obj);
INSIST(result == ISC_R_SUCCESS && obj != NULL);
RETERR(dns_zone_setparentalsrc4(zone, cfg_obj_assockaddr(obj)));
CHECK(dns_zone_setparentalsrc4(zone, cfg_obj_assockaddr(obj)));
named_add_reserved_dispatch(named_g_server,
cfg_obj_assockaddr(obj));
obj = NULL;
result = named_config_get(maps, "parental-source-v6", &obj);
INSIST(result == ISC_R_SUCCESS && obj != NULL);
RETERR(dns_zone_setparentalsrc6(zone, cfg_obj_assockaddr(obj)));
CHECK(dns_zone_setparentalsrc6(zone, cfg_obj_assockaddr(obj)));
named_add_reserved_dispatch(named_g_server,
cfg_obj_assockaddr(obj));
obj = NULL;
result = named_config_get(maps, "notify-source", &obj);
INSIST(result == ISC_R_SUCCESS && obj != NULL);
RETERR(dns_zone_setnotifysrc4(zone, cfg_obj_assockaddr(obj)));
CHECK(dns_zone_setnotifysrc4(zone, cfg_obj_assockaddr(obj)));
named_add_reserved_dispatch(named_g_server,
cfg_obj_assockaddr(obj));
obj = NULL;
result = named_config_get(maps, "notify-source-v6", &obj);
INSIST(result == ISC_R_SUCCESS && obj != NULL);
RETERR(dns_zone_setnotifysrc6(zone, cfg_obj_assockaddr(obj)));
CHECK(dns_zone_setnotifysrc6(zone, cfg_obj_assockaddr(obj)));
named_add_reserved_dispatch(named_g_server,
cfg_obj_assockaddr(obj));
@ -1315,7 +1315,7 @@ named_zone_configure(const cfg_obj_t *config, const cfg_obj_t *vconfig,
dns_zone_setisself(zone, isself, named_g_server->interfacemgr);
RETERR(configure_zone_acl(
CHECK(configure_zone_acl(
zconfig, vconfig, config, allow_transfer, ac, zone,
dns_zone_setxfracl, dns_zone_clearxfracl));
@ -1353,7 +1353,7 @@ named_zone_configure(const cfg_obj_t *config, const cfg_obj_t *vconfig,
"%" PRId64 "' "
"is too large",
value);
RETERR(ISC_R_RANGE);
CHECK(ISC_R_RANGE);
}
journal_size = (uint32_t)value;
}
@ -1493,7 +1493,7 @@ named_zone_configure(const cfg_obj_t *config, const cfg_obj_t *vconfig,
"%" PRId64 "' "
"is too large",
value);
RETERR(ISC_R_RANGE);
CHECK(ISC_R_RANGE);
}
journal_size = (uint32_t)value;
}
@ -1523,9 +1523,9 @@ named_zone_configure(const cfg_obj_t *config, const cfg_obj_t *vconfig,
if (ztype == dns_zone_primary) {
dns_acl_t *updateacl;
RETERR(configure_zone_acl(
zconfig, vconfig, config, allow_update, ac, mayberaw,
dns_zone_setupdateacl, dns_zone_clearupdateacl));
CHECK(configure_zone_acl(zconfig, vconfig, config, allow_update,
ac, mayberaw, dns_zone_setupdateacl,
dns_zone_clearupdateacl));
updateacl = dns_zone_getupdateacl(mayberaw);
if (updateacl != NULL && dns_acl_isinsecure(updateacl)) {
@ -1536,7 +1536,7 @@ named_zone_configure(const cfg_obj_t *config, const cfg_obj_t *vconfig,
zname);
}
RETERR(configure_zone_ssutable(zoptions, mayberaw, zname));
CHECK(configure_zone_ssutable(zoptions, mayberaw, zname));
}
/*
@ -1613,7 +1613,7 @@ named_zone_configure(const cfg_obj_t *config, const cfg_obj_t *vconfig,
result = named_config_get(maps, "key-directory", &obj);
if (result == ISC_R_SUCCESS) {
filename = cfg_obj_asstring(obj);
RETERR(dns_zone_setkeydirectory(zone, filename));
CHECK(dns_zone_setkeydirectory(zone, filename));
}
obj = NULL;
@ -1655,8 +1655,8 @@ named_zone_configure(const cfg_obj_t *config, const cfg_obj_t *vconfig,
result = named_config_get(maps, "dnssec-loadkeys-interval",
&obj);
INSIST(result == ISC_R_SUCCESS && obj != NULL);
RETERR(dns_zone_setrefreshkeyinterval(zone,
cfg_obj_asuint32(obj)));
CHECK(dns_zone_setrefreshkeyinterval(zone,
cfg_obj_asuint32(obj)));
obj = NULL;
result = cfg_map_get(zoptions, "auto-dnssec", &obj);
@ -1684,10 +1684,10 @@ named_zone_configure(const cfg_obj_t *config, const cfg_obj_t *vconfig,
}
if (ztype == dns_zone_secondary || ztype == dns_zone_mirror) {
RETERR(configure_zone_acl(zconfig, vconfig, config,
allow_update_forwarding, ac, mayberaw,
dns_zone_setforwardacl,
dns_zone_clearforwardacl));
CHECK(configure_zone_acl(zconfig, vconfig, config,
allow_update_forwarding, ac, mayberaw,
dns_zone_setforwardacl,
dns_zone_clearforwardacl));
}
/*%
@ -1699,7 +1699,7 @@ named_zone_configure(const cfg_obj_t *config, const cfg_obj_t *vconfig,
if (obj != NULL) {
dns_ipkeylist_t ipkl;
dns_ipkeylist_init(&ipkl);
RETERR(named_config_getipandkeylist(
CHECK(named_config_getipandkeylist(
config, "parental-agents", obj, mctx, &ipkl));
dns_zone_setparentals(zone, ipkl.addrs, ipkl.keys,
ipkl.tlss, ipkl.count);
@ -1843,7 +1843,7 @@ named_zone_configure(const cfg_obj_t *config, const cfg_obj_t *vconfig,
(void)cfg_map_get(zoptions, "allow-transfer", &obj);
if (obj == NULL) {
dns_acl_t *none;
RETERR(dns_acl_none(mctx, &none));
CHECK(dns_acl_none(mctx, &none));
dns_zone_setxfracl(zone, none);
dns_acl_detach(&none);
}
@ -1868,14 +1868,14 @@ named_zone_configure(const cfg_obj_t *config, const cfg_obj_t *vconfig,
result = named_config_getremotesdef(
named_g_config, "primaries",
DEFAULT_IANA_ROOT_ZONE_PRIMARIES, &obj);
RETERR(result);
CHECK(result);
}
if (obj != NULL) {
dns_ipkeylist_t ipkl;
dns_ipkeylist_init(&ipkl);
RETERR(named_config_getipandkeylist(config, "primaries",
obj, mctx, &ipkl));
CHECK(named_config_getipandkeylist(config, "primaries",
obj, mctx, &ipkl));
dns_zone_setprimaries(mayberaw, ipkl.addrs, ipkl.keys,
ipkl.tlss, ipkl.count);
count = ipkl.count;
@ -1926,29 +1926,29 @@ named_zone_configure(const cfg_obj_t *config, const cfg_obj_t *vconfig,
obj = NULL;
result = named_config_get(maps, "transfer-source", &obj);
INSIST(result == ISC_R_SUCCESS && obj != NULL);
RETERR(dns_zone_setxfrsource4(mayberaw,
cfg_obj_assockaddr(obj)));
CHECK(dns_zone_setxfrsource4(mayberaw,
cfg_obj_assockaddr(obj)));
named_add_reserved_dispatch(named_g_server,
cfg_obj_assockaddr(obj));
obj = NULL;
result = named_config_get(maps, "transfer-source-v6", &obj);
INSIST(result == ISC_R_SUCCESS && obj != NULL);
RETERR(dns_zone_setxfrsource6(mayberaw,
cfg_obj_assockaddr(obj)));
CHECK(dns_zone_setxfrsource6(mayberaw,
cfg_obj_assockaddr(obj)));
named_add_reserved_dispatch(named_g_server,
cfg_obj_assockaddr(obj));
obj = NULL;
result = named_config_get(maps, "alt-transfer-source", &obj);
INSIST(result == ISC_R_SUCCESS && obj != NULL);
RETERR(dns_zone_setaltxfrsource4(mayberaw,
cfg_obj_assockaddr(obj)));
CHECK(dns_zone_setaltxfrsource4(mayberaw,
cfg_obj_assockaddr(obj)));
obj = NULL;
result = named_config_get(maps, "alt-transfer-source-v6", &obj);
INSIST(result == ISC_R_SUCCESS && obj != NULL);
RETERR(dns_zone_setaltxfrsource6(mayberaw,
cfg_obj_assockaddr(obj)));
CHECK(dns_zone_setaltxfrsource6(mayberaw,
cfg_obj_assockaddr(obj)));
obj = NULL;
(void)named_config_get(maps, "use-alt-transfer-source", &obj);
if (obj == NULL) {
@ -1975,15 +1975,21 @@ named_zone_configure(const cfg_obj_t *config, const cfg_obj_t *vconfig,
break;
case dns_zone_staticstub:
RETERR(configure_staticstub(zoptions, zone, zname,
default_dbtype));
CHECK(configure_staticstub(zoptions, zone, zname,
default_dbtype));
break;
default:
break;
}
return (ISC_R_SUCCESS);
result = ISC_R_SUCCESS;
cleanup:
if (kasp != NULL) {
dns_kasp_detach(&kasp);
}
return (result);
}
/*

View file

@ -5881,11 +5881,11 @@ dns_zone_setkasp(dns_zone_t *zone, dns_kasp_t *kasp) {
LOCK_ZONE(zone);
if (zone->kasp != NULL) {
dns_kasp_t *oldkasp = zone->kasp;
zone->kasp = NULL;
dns_kasp_detach(&oldkasp);
dns_kasp_detach(&zone->kasp);
}
if (kasp != NULL) {
dns_kasp_attach(kasp, &zone->kasp);
}
zone->kasp = kasp;
UNLOCK_ZONE(zone);
}