]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
DROP: save cfg as cfg_obj_t
authorAlessio Podda <alessio@isc.org>
Fri, 20 Mar 2026 14:15:21 +0000 (15:15 +0100)
committerAlessio Podda <alessio@isc.org>
Fri, 20 Mar 2026 14:15:21 +0000 (15:15 +0100)
bin/named/include/named/server.h
bin/named/server.c
bin/named/zoneconf.c
lib/dns/include/dns/zone.h
lib/dns/zone.c

index b15d6075221f35e60b9abaed36cd6bb77412eb41..2bcad5283686458a54a8a2500f328a4a1efd850a 100644 (file)
@@ -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;
 };
index ae869b7f2af37c8c0523c015a07a70e55e2252ce..39a3df97569902477d9a84dce4405f252f34e2fd 100644 (file)
@@ -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(
index c3476ce624d4fc0cf074c03ac8db63b18feebf01..aa06c1fb65440f877115a416dfe3c3eb5152bb37 100644 (file)
@@ -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:
index 5964e69ead451da03eeb83a2ca9d483224406a54..438a88c43f6e0756c446dc84c7f6c7863a21c810 100644 (file)
@@ -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.
index 741e88a58802a7e19625d41bc46d7efbf08e1bc7..41bc99a0f58484d173647445f62ab90b9758cba9 100644 (file)
@@ -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));