mirror of
https://github.com/isc-projects/bind9.git
synced 2026-06-10 04:20:00 -04:00
save userconfig as text instead of a cfg_obj tree
once the user configuration has been merged into the effective configuration, it no longer needs to be accessed as a configuration tree, but we still want to be able to show it with 'rndc showconf -user'. because the recursive strucure of cfg_obj objects is fairly large, the canonical text form is a fraction of the size of the configuration tree, so we now save it in that form instead.
This commit is contained in:
parent
6451b08f47
commit
c65b2868ab
2 changed files with 40 additions and 27 deletions
|
|
@ -110,7 +110,7 @@ struct named_server {
|
|||
isc_signal_t *sigusr1;
|
||||
|
||||
cfg_aclconfctx_t *aclctx;
|
||||
cfg_obj_t *userconfig;
|
||||
isc_buffer_t *userconf;
|
||||
cfg_obj_t *effectiveconfig;
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -7889,9 +7889,8 @@ configure_kasplist(const cfg_obj_t *config, dns_kasplist_t *kasplist,
|
|||
}
|
||||
|
||||
static isc_result_t
|
||||
apply_configuration(cfg_obj_t *effectiveconfig, cfg_obj_t *userconfig,
|
||||
cfg_obj_t *bindkeys, named_server_t *server,
|
||||
bool first_time) {
|
||||
apply_configuration(cfg_obj_t *effectiveconfig, cfg_obj_t *bindkeys,
|
||||
named_server_t *server, bool first_time) {
|
||||
const cfg_obj_t *maps[3];
|
||||
const cfg_obj_t *obj = NULL;
|
||||
const cfg_obj_t *options = NULL;
|
||||
|
|
@ -8953,18 +8952,13 @@ apply_configuration(cfg_obj_t *effectiveconfig, cfg_obj_t *userconfig,
|
|||
named_g_defaultconfigtime = isc_time_now();
|
||||
|
||||
/*
|
||||
* Set the current effective and user configuration
|
||||
* Save the current effective configuration
|
||||
*/
|
||||
if (server->effectiveconfig != NULL) {
|
||||
cfg_obj_detach(&server->effectiveconfig);
|
||||
}
|
||||
cfg_obj_attach(effectiveconfig, &server->effectiveconfig);
|
||||
|
||||
if (server->userconfig != NULL) {
|
||||
cfg_obj_detach(&server->userconfig);
|
||||
}
|
||||
cfg_obj_attach(userconfig, &server->userconfig);
|
||||
|
||||
isc_loopmgr_resume();
|
||||
exclusive = false;
|
||||
|
||||
|
|
@ -9083,10 +9077,27 @@ cleanup_aclctx:
|
|||
return result;
|
||||
}
|
||||
|
||||
static void
|
||||
emit_text(void *arg, const char *buf, int len) {
|
||||
ns_dzarg_t *dzarg = arg;
|
||||
isc_result_t result;
|
||||
|
||||
REQUIRE(dzarg != NULL && ISC_MAGIC_VALID(dzarg, DZARG_MAGIC));
|
||||
result = putmem(dzarg->text, buf, len);
|
||||
if (result != ISC_R_SUCCESS && dzarg->result == ISC_R_SUCCESS) {
|
||||
dzarg->result = result;
|
||||
}
|
||||
}
|
||||
|
||||
static isc_result_t
|
||||
load_configuration(named_server_t *server, bool first_time) {
|
||||
isc_result_t result;
|
||||
cfg_obj_t *config = NULL, *bindkeys = NULL, *effective = NULL;
|
||||
ns_dzarg_t dzarg = {
|
||||
.magic = DZARG_MAGIC,
|
||||
.result = ISC_R_SUCCESS,
|
||||
.text = &server->userconf,
|
||||
};
|
||||
|
||||
isc_log_write(NAMED_LOGCATEGORY_GENERAL, NAMED_LOGMODULE_SERVER,
|
||||
ISC_LOG_DEBUG(1), "load_configuration");
|
||||
|
|
@ -9125,8 +9136,19 @@ load_configuration(named_server_t *server, bool first_time) {
|
|||
|
||||
/* Merge and apply */
|
||||
effective = cfg_effective_config(config, named_g_defaultconfig);
|
||||
result = apply_configuration(effective, config, bindkeys, server,
|
||||
first_time);
|
||||
|
||||
/*
|
||||
* Save the user configuration for later reference.
|
||||
* We keep it in text format to save space; we won't need
|
||||
* to access it as a tree again after this.
|
||||
*/
|
||||
if (server->userconf != NULL) {
|
||||
isc_buffer_free(&server->userconf);
|
||||
}
|
||||
isc_buffer_allocate(isc_g_mctx, &server->userconf, BUFSIZ);
|
||||
cfg_printx(config, 0, emit_text, &dzarg);
|
||||
|
||||
result = apply_configuration(effective, bindkeys, server, first_time);
|
||||
|
||||
cleanup:
|
||||
if (bindkeys != NULL) {
|
||||
|
|
@ -9766,8 +9788,8 @@ named_server_destroy(named_server_t **serverp) {
|
|||
isc_tlsctx_cache_detach(&server->tlsctx_client_cache);
|
||||
}
|
||||
|
||||
if (server->userconfig != NULL) {
|
||||
cfg_obj_detach(&server->userconfig);
|
||||
if (server->userconf != NULL) {
|
||||
isc_buffer_free(&server->userconf);
|
||||
}
|
||||
|
||||
if (server->effectiveconfig != NULL) {
|
||||
|
|
@ -13817,18 +13839,6 @@ cleanup:
|
|||
return result;
|
||||
}
|
||||
|
||||
static void
|
||||
emit_text(void *arg, const char *buf, int len) {
|
||||
ns_dzarg_t *dzarg = arg;
|
||||
isc_result_t result;
|
||||
|
||||
REQUIRE(dzarg != NULL && ISC_MAGIC_VALID(dzarg, DZARG_MAGIC));
|
||||
result = putmem(dzarg->text, buf, len);
|
||||
if (result != ISC_R_SUCCESS && dzarg->result == ISC_R_SUCCESS) {
|
||||
dzarg->result = result;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Act on a "showzone" command from the command channel.
|
||||
*/
|
||||
|
|
@ -13898,7 +13908,10 @@ named_server_showconf(named_server_t *server, isc_lex_t *lex,
|
|||
return ISC_R_UNEXPECTEDEND;
|
||||
}
|
||||
if (strcasecmp(arg, "-user") == 0) {
|
||||
config = server->userconfig;
|
||||
putmem(text, isc_buffer_base(server->userconf),
|
||||
isc_buffer_usedlength(server->userconf));
|
||||
result = ISC_R_SUCCESS;
|
||||
goto cleanup;
|
||||
} else if (strcasecmp(arg, "-builtin") == 0) {
|
||||
config = named_g_defaultconfig;
|
||||
} else if (strcasecmp(arg, "-effective") == 0) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue