From: Alessio Podda Date: Fri, 20 Mar 2026 14:15:21 +0000 (+0100) Subject: DROP: save cfg as cfg_obj_t X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=dc0ebe98368cc4168aae3a9a765f7af2bba99e56;p=thirdparty%2Fbind9.git DROP: save cfg as cfg_obj_t --- diff --git a/bin/named/include/named/server.h b/bin/named/include/named/server.h index b15d6075221..2bcad528368 100644 --- a/bin/named/include/named/server.h +++ b/bin/named/include/named/server.h @@ -110,7 +110,7 @@ struct named_server { isc_signal_t *sigusr1; cfg_aclconfctx_t *aclctx; - isc_buffer_t *userconftext; + cfg_obj_t *userconfig; isc_buffer_t *effectivetext; cfg_obj_t *effectiveconfig; }; diff --git a/bin/named/server.c b/bin/named/server.c index ae869b7f2af..39a3df97569 100644 --- a/bin/named/server.c +++ b/bin/named/server.c @@ -5857,28 +5857,6 @@ emit_text(void *arg, const char *buf, int len) { } } -static isc_result_t -save_zoneconfig(dns_zone_t *zone, const cfg_obj_t *zconfig) { - isc_result_t result; - isc_buffer_t *text = NULL; - - isc_buffer_allocate(isc_g_mctx, &text, 256); - - ns_dzarg_t dzarg = { - .magic = DZARG_MAGIC, - .text = text, - }; - - cfg_printx(zconfig, CFG_PRINTER_ONELINE, emit_text, &dzarg); - CHECK(putnull(text)); - - dns_zone_setcfg(zone, isc_buffer_base(text)); - -cleanup: - isc_buffer_free(&text); - return result; -} - /* * Configure or reconfigure a zone. */ @@ -6081,7 +6059,6 @@ configure_zone(const cfg_obj_t *config, const cfg_obj_t *zconfig, } CHECK(named_zone_configure(config, vconfig, zconfig, aclctx, kasplist, zone, NULL)); - CHECK(save_zoneconfig(zone, zconfig)); dns_zone_attach(zone, &view->redirect); goto cleanup; } @@ -6259,7 +6236,6 @@ configure_zone(const cfg_obj_t *config, const cfg_obj_t *zconfig, */ CHECK(named_zone_configure(config, vconfig, zconfig, aclctx, kasplist, zone, raw)); - CHECK(save_zoneconfig(zone, zconfig)); /* * Add the zone to its view in the new view list. @@ -8849,19 +8825,12 @@ load_configuration(named_server_t *server, bool first_time) { effective = cfg_effective_config(config, builtin); /* - * Save the user configuration in text format, to display with "rndc - * showconf". (Text takes up less memory than an object tree.) + * Save the user configuration for later reference. */ - if (server->userconftext != NULL) { - isc_buffer_free(&server->userconftext); + if (server->userconfig != NULL) { + cfg_obj_detach(&server->userconfig); } - isc_buffer_allocate(isc_g_mctx, &server->userconftext, BUFSIZ); - - dzarg = (ns_dzarg_t){ - .magic = DZARG_MAGIC, - .text = server->userconftext, - }; - cfg_printx(config, 0, emit_text, &dzarg); + cfg_obj_attach(config, &server->userconfig); /* * And finally we apply the effective configuration. @@ -9515,8 +9484,8 @@ named_server_destroy(named_server_t **serverp) { isc_tlsctx_cache_detach(&server->tlsctx_client_cache); } - if (server->userconftext != NULL) { - isc_buffer_free(&server->userconftext); + if (server->userconfig != NULL) { + cfg_obj_detach(&server->userconfig); } if (server->effectivetext != NULL) { @@ -12770,7 +12739,11 @@ named_server_showzone(named_server_t *server, isc_lex_t *lex, isc_result_t result; char zonename[DNS_NAME_FORMATSIZE]; dns_zone_t *zone = NULL; - const char *zconfig = NULL; + const cfg_obj_t *zconfig = NULL; + ns_dzarg_t dzarg = { + .magic = DZARG_MAGIC, + .text = text, + }; REQUIRE(text != NULL); @@ -12788,7 +12761,8 @@ named_server_showzone(named_server_t *server, isc_lex_t *lex, } CHECK(putstr(text, "zone ")); - CHECK(putstr(text, zconfig)); + cfg_printx(zconfig, CFG_PRINTER_ONELINE, emit_text, &dzarg); + CHECK(dzarg.result); CHECK(putstr(text, ";")); result = ISC_R_SUCCESS; @@ -12823,8 +12797,8 @@ named_server_showconf(named_server_t *server, isc_lex_t *lex, } if (strcasecmp(arg, "-user") == 0) { - result = putmem(text, isc_buffer_base(server->userconftext), - isc_buffer_usedlength(server->userconftext)); + cfg_printx(server->userconfig, 0, emit_text, &dzarg); + result = dzarg.result; } else if (strcasecmp(arg, "-effective") == 0) { if (server->effectivetext != NULL) { result = putmem( diff --git a/bin/named/zoneconf.c b/bin/named/zoneconf.c index c3476ce624d..aa06c1fb654 100644 --- a/bin/named/zoneconf.c +++ b/bin/named/zoneconf.c @@ -949,6 +949,12 @@ process_notify_cfg(const cfg_obj_t **maps, dns_zone_t *zone, dns_zone_t *raw) { return ISC_R_SUCCESS; } +static void +detach_cfg(void *arg) { + cfg_obj_t *cfg = (cfg_obj_t *)arg; + cfg_obj_detach(&cfg); +} + isc_result_t named_zone_configure(const cfg_obj_t *config, const cfg_obj_t *vconfig, const cfg_obj_t *zconfig, cfg_aclconfctx_t *aclctx, @@ -1976,6 +1982,11 @@ named_zone_configure(const cfg_obj_t *config, const cfg_obj_t *vconfig, break; } + /* Save the configuration for later use */ + cfg_obj_t *cfg = UNCONST(zconfig); + cfg_obj_ref(cfg); + dns_zone_setcfg(zone, (void *)cfg, detach_cfg); + result = ISC_R_SUCCESS; cleanup: diff --git a/lib/dns/include/dns/zone.h b/lib/dns/include/dns/zone.h index 5964e69ead4..438a88c43f6 100644 --- a/lib/dns/include/dns/zone.h +++ b/lib/dns/include/dns/zone.h @@ -2784,20 +2784,20 @@ dns_zone_unloadplugins(dns_zone_t *zone); */ void -dns_zone_setcfg(dns_zone_t *zone, const char *cfg); +dns_zone_setcfg(dns_zone_t *zone, void *cfg, void (*cfg_detach)(void *)); /*%< - * Save a copy of the configuration text for 'zone', which can be + * Set a pointer to the configuration object for 'zone', which can be * used later to dump the configuration status. * * Requires: * \li 'zone' to be a valid zone. */ -const char * +void * dns_zone_getcfg(dns_zone_t *zone); /*%< - * Return a pointer to the configuration text for 'zone', that was - * previously saved using _setcfg(). + * Return a pointer to the configuration object for 'zone', that was + * previously set using _setcfg(). * * Requires: * \li 'zone' to be a valid zone. diff --git a/lib/dns/zone.c b/lib/dns/zone.c index 741e88a5880..41bc99a0f58 100644 --- a/lib/dns/zone.c +++ b/lib/dns/zone.c @@ -504,8 +504,9 @@ struct dns_zone { void *hooktable; void (*hooktable_free)(isc_mem_t *, void **); - /* Configuration text */ - char *cfg; + /* Configuration object */ + void *cfg; + void (*cfg_detach)(void *); }; #define zonediff_init(z, d) \ @@ -14547,7 +14548,7 @@ zone_shutdown(void *arg) { } /* Detach the zone configuration pointer */ - dns_zone_setcfg(zone, NULL); + dns_zone_setcfg(zone, NULL, NULL); LOCK_ZONE(zone); INSIST(zone != zone->raw); @@ -24099,18 +24100,18 @@ dns_zone_unloadplugins(dns_zone_t *zone) { } void -dns_zone_setcfg(dns_zone_t *zone, const char *cfg) { +dns_zone_setcfg(dns_zone_t *zone, void *cfg, void (*cfg_detach)(void *)) { REQUIRE(DNS_ZONE_VALID(zone)); - if (zone->cfg != NULL) { - isc_mem_free(zone->mctx, zone->cfg); - } - if (cfg != NULL) { - zone->cfg = isc_mem_strdup(zone->mctx, cfg); + if (zone->cfg != NULL && zone->cfg_detach != NULL) { + zone->cfg_detach(zone->cfg); + zone->cfg = NULL; } + zone->cfg = cfg; + zone->cfg_detach = cfg_detach; } -const char * +void * dns_zone_getcfg(dns_zone_t *zone) { REQUIRE(DNS_ZONE_VALID(zone));