From 5f9323b9be3227fa3fd81947e26771d7f5c6f068 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristj=C3=A1n=20Valur=20J=C3=B3nsson?= Date: Tue, 30 Jan 2018 17:14:50 +0000 Subject: [PATCH 1/2] https://bugzilla.samba.org/show_bug.cgi?id=13214 Using a singleton instance makes samba_dlz break when named does a "reload". Remove the singleton management and allow named to initialize a new samba_dlz_state, and destroy the old on reload. --- source4/dns_server/dlz_bind9.c | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/source4/dns_server/dlz_bind9.c b/source4/dns_server/dlz_bind9.c index 6ef378c75a6..4364f0be2df 100644 --- a/source4/dns_server/dlz_bind9.c +++ b/source4/dns_server/dlz_bind9.c @@ -40,6 +40,14 @@ #include "dlz_minimal.h" #include "dns_server/dnsserver_common.h" +/* maintaining a singleton will break the 'reload' functionality + * triggered by 'rndc reload' and 'service reload named' which + * is used e.g. by logrotate. It can be enabled with a preprocessor macro + */ +#ifndef DLZ_BIND9_USE_SINGLETON +#define DLS_BIND9_USE_SINGLETON 0 +#endif + struct b9_options { const char *url; const char *debug; @@ -72,8 +80,10 @@ struct dlz_bind9_data { dns_dlz_writeablezone_t *writeable_zone; }; +#if DLZ_BIND9_USE_SINGLETON static struct dlz_bind9_data *dlz_bind9_state = NULL; static int dlz_bind9_state_ref_count = 0; +#endif static const char *zone_prefixes[] = { "CN=MicrosoftDNS,DC=DomainDnsZones", @@ -615,11 +625,13 @@ _PUBLIC_ isc_result_t dlz_create(const char *dlzname, struct ldb_dn *dn; NTSTATUS nt_status; +#if DLZ_BIND9_USE_SINGLETON if (dlz_bind9_state != NULL) { *dbdata = dlz_bind9_state; dlz_bind9_state_ref_count++; return ISC_R_SUCCESS; } +#endif state = talloc_zero(NULL, struct dlz_bind9_data); if (state == NULL) { @@ -635,6 +647,8 @@ _PUBLIC_ isc_result_t dlz_create(const char *dlzname, } va_end(ap); + state->log(ISC_LOG_INFO, "samba_dlz: starting for instance %p", state); + /* Do not install samba signal handlers */ fault_setup_disable(); @@ -715,8 +729,10 @@ _PUBLIC_ isc_result_t dlz_create(const char *dlzname, state->auth_context->generate_session_info_pac = b9_generate_session_info_pac; *dbdata = state; +#if DLZ_BIND9_USE_SINGLETON dlz_bind9_state = state; dlz_bind9_state_ref_count++; +#endif return ISC_R_SUCCESS; @@ -731,14 +747,17 @@ _PUBLIC_ isc_result_t dlz_create(const char *dlzname, _PUBLIC_ void dlz_destroy(void *dbdata) { struct dlz_bind9_data *state = talloc_get_type_abort(dbdata, struct dlz_bind9_data); - state->log(ISC_LOG_INFO, "samba_dlz: shutting down"); - +#if DLZ_BIND9_USE_SINGLETON dlz_bind9_state_ref_count--; if (dlz_bind9_state_ref_count == 0) { - talloc_unlink(state, state->samdb); - talloc_free(state); dlz_bind9_state = NULL; + } else { + return; } +#endif + state->log(ISC_LOG_INFO, "samba_dlz: shutting down instance %p", state); + talloc_unlink(state, state->samdb); + talloc_free(state); } From f0ddf587555d90ed50c924edc32eb0fb6b6af8a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristj=C3=A1n=20Valur=20J=C3=B3nsson?= Date: Tue, 30 Jan 2018 17:34:45 +0000 Subject: [PATCH 2/2] formatting --- source4/dns_server/dlz_bind9.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/source4/dns_server/dlz_bind9.c b/source4/dns_server/dlz_bind9.c index 4364f0be2df..5ed8ec42756 100644 --- a/source4/dns_server/dlz_bind9.c +++ b/source4/dns_server/dlz_bind9.c @@ -40,9 +40,11 @@ #include "dlz_minimal.h" #include "dns_server/dnsserver_common.h" -/* maintaining a singleton will break the 'reload' functionality +/* + * maintaining a singleton will break the 'reload' functionality * triggered by 'rndc reload' and 'service reload named' which - * is used e.g. by logrotate. It can be enabled with a preprocessor macro + * is used e.g. by logrotate. It can be enabled by defining the following + * preprocessor macro */ #ifndef DLZ_BIND9_USE_SINGLETON #define DLS_BIND9_USE_SINGLETON 0 @@ -729,6 +731,7 @@ _PUBLIC_ isc_result_t dlz_create(const char *dlzname, state->auth_context->generate_session_info_pac = b9_generate_session_info_pac; *dbdata = state; + #if DLZ_BIND9_USE_SINGLETON dlz_bind9_state = state; dlz_bind9_state_ref_count++; @@ -747,6 +750,7 @@ _PUBLIC_ isc_result_t dlz_create(const char *dlzname, _PUBLIC_ void dlz_destroy(void *dbdata) { struct dlz_bind9_data *state = talloc_get_type_abort(dbdata, struct dlz_bind9_data); + #if DLZ_BIND9_USE_SINGLETON dlz_bind9_state_ref_count--; if (dlz_bind9_state_ref_count == 0) { @@ -755,6 +759,7 @@ _PUBLIC_ void dlz_destroy(void *dbdata) return; } #endif + state->log(ISC_LOG_INFO, "samba_dlz: shutting down instance %p", state); talloc_unlink(state, state->samdb); talloc_free(state);