patch for samba_dlz

Kristján Valur Jónsson kristjan at rvx.is
Thu Feb 1 16:21:42 UTC 2018


Hello there.  Attached is a patched for samba_dlz.
Please see
https://bugzilla.samba.org/show_bug.cgi?id=13214
and
https://github.com/samba-team/samba/pull/124


-- 
Kv,
Kristján Valur Jónsson, RVX
-------------- next part --------------
From a8d6838fce9ddc0a27a150425a8799ef9a0d80be Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Kristj=C3=A1n=20Valur=20J=C3=B3nsson?= <kristjan at rvx.is>
Date: Tue, 30 Jan 2018 17:14:50 +0000
Subject: [PATCH]  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.

bind does a "reload" of a dlz module by:

 1. Creating a new dlz instance state via dlz_create()
 2. Initializing it with dlz_configure()
 3. Deleting the old instance state via dlz_destroy().

Using a singleton instance would cause samba_dlz to fail after a reload.
I don't know the precise reason, here are two possibles:

 - dlz_configure() on an already running instance would break it somehow.
 - Returning the same pointer from dlz_create() as the one already running may
   confuse the internal bookkeeping in bind. Notice how a new instance is
   created before the old is destroyed.

Note: This effectively undoes revision 34eab45.  The issues with 'state->samdb'
      seem to have been gone away.  newstate->samdb is a talloc_reference() of
      oldstate->samdb() and thus has proper refcounts.  talloc_free(oldstate)
      does not invalidate it.

Signed-off-by: kristján Valur Jónssons <kristjan at rvx.is>

---
 source4/dns_server/dlz_bind9.c | 29 ++++++++++++++++++++++++++---
 1 file changed, 26 insertions(+), 3 deletions(-)

diff --git a/source4/dns_server/dlz_bind9.c b/source4/dns_server/dlz_bind9.c
index 6ef378c75a6..7aaa7463aef 100644
--- a/source4/dns_server/dlz_bind9.c
+++ b/source4/dns_server/dlz_bind9.c
@@ -40,6 +40,16 @@
 #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 by defining the following
+ * 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 +82,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 +627,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 +649,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 +731,11 @@ _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 +750,18 @@ failed:
 _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_free(state);
 }
 
 
-- 
2.15.1.windows.2



More information about the samba-technical mailing list