File dhcp-4.2.x-disable-unused-ddns-port-in-server.891655.patch of Package dhcp.3227

Author: William Preston <wpreston@suse.com>
Subject: do not bind ddns socket in server when ddns-update-style is none
References: bsc#891655
Upstream: yes

backported from commit 61ef216b8dc05bc4245b61eee812038757d12ffe
by Shawn Routhier <sar@isc.org> with changes.

diff --git a/client/dhclient.c b/client/dhclient.c
index 75b4c19..3c55ec7 100644
--- a/client/dhclient.c
+++ b/client/dhclient.c
@@ -148,7 +148,7 @@ main(int argc, char **argv) {
 #endif
 
 	/* Set up the isc and dns library managers */
-	status = dhcp_context_create();
+	status = dhcp_context_create(DHCP_CONTEXT_PRE_DB | DHCP_CONTEXT_POST_DB);
 	if (status != ISC_R_SUCCESS)
 		log_fatal("Can't initialize context: %s",
 			  isc_result_totext(status));
diff --git a/dhcpctl/dhcpctl.c b/dhcpctl/dhcpctl.c
index 5ec617a..447bccb 100644
--- a/dhcpctl/dhcpctl.c
+++ b/dhcpctl/dhcpctl.c
@@ -48,7 +48,7 @@ dhcpctl_status dhcpctl_initialize ()
 	isc_result_t status;
 
 	/* Set up the isc and dns library managers */
-	status = dhcp_context_create();
+	status = dhcp_context_create(DHCP_CONTEXT_PRE_DB | DHCP_CONTEXT_POST_DB);
 	if (status != ISC_R_SUCCESS)
 		return status;
 
diff --git a/includes/omapip/isclib.h b/includes/omapip/isclib.h
index 4dffcb9..3e3a30d 100644
--- a/includes/omapip/isclib.h
+++ b/includes/omapip/isclib.h
@@ -121,7 +121,9 @@ isclib_make_dst_key(char          *inname,
 		    int            length,
 		    dst_key_t    **dstkey);
 
-isc_result_t dhcp_context_create(void);
+#define DHCP_CONTEXT_PRE_DB  1
+#define DHCP_CONTEXT_POST_DB 2
+isc_result_t dhcp_context_create(int              flags);
 void isclib_cleanup(void);
 
 #endif /* ISCLIB_H */
diff --git a/omapip/isclib.c b/omapip/isclib.c
index 19492d2..147e322 100644
--- a/omapip/isclib.c
+++ b/omapip/isclib.c
@@ -86,98 +86,102 @@ handle_signal(int sig, void (*handler)(int)) {
 }
 
 isc_result_t
-dhcp_context_create(void) {
+dhcp_context_create(int flags) {
 	isc_result_t result;
 
-	/*
-	 * Set up the error messages, this isn't the right place
-	 * for this call but it is convienent for now.
-	 */
-	result = dhcp_result_register();
-	if (result != ISC_R_SUCCESS) {
-		log_fatal("register_table() %s: %u", "failed", result);
-	}
-
-	memset(&dhcp_gbl_ctx, 0, sizeof (dhcp_gbl_ctx));
+	if ((flags & DHCP_CONTEXT_PRE_DB) != 0) {
+		/*
+		 * Set up the error messages, this isn't the right place
+		 * for this call but it is convienent for now.
+		 */
+		result = dhcp_result_register();
+		if (result != ISC_R_SUCCESS) {
+			log_fatal("register_table() %s: %u", "failed", result);
+		}
+
+		memset(&dhcp_gbl_ctx, 0, sizeof (dhcp_gbl_ctx));
 	
-	isc_lib_register();
+		isc_lib_register();
 
-	/* get the current time for use as the random seed */
-	gettimeofday(&cur_tv, (struct timezone *)0);
-	isc_random_seed(cur_tv.tv_sec);
+		/* get the current time for use as the random seed */
+		gettimeofday(&cur_tv, (struct timezone *)0);
+		isc_random_seed(cur_tv.tv_sec);
 
 #if defined (NSUPDATE)
-	result = dns_lib_init();
-	if (result != ISC_R_SUCCESS)
-		goto cleanup;
+		result = dns_lib_init();
+		if (result != ISC_R_SUCCESS)
+			goto cleanup;
+#else
+		/* The dst library is inited as part of dns_lib_init, we don't
+		 * need it if NSUPDATE is enabled */
+		result = dst_lib_init(dhcp_gbl_ctx.mctx, NULL, 0);
+		if (result != ISC_R_SUCCESS)
+			goto cleanup;
 #endif
 
-	result = isc_mem_create(0, 0, &dhcp_gbl_ctx.mctx);
-	if (result != ISC_R_SUCCESS)
-		goto cleanup;
-
-	result = isc_appctx_create(dhcp_gbl_ctx.mctx, &dhcp_gbl_ctx.actx);
-	if (result != ISC_R_SUCCESS)
-		goto cleanup;
-
-	result = isc_app_ctxstart(dhcp_gbl_ctx.actx);
-	if (result != ISC_R_SUCCESS)
-		goto cleanup;
-
-	/*
-	 * Always ignore SIGPIPE.
-	 * Otherwise we will die before the errno == EPIPE
-	 * checks in the socket code are reached.
-	 *
-	 * Note: unlike isc_app_start(), isc_app_ctxstart()
-	 *       does not set any signal handlers.
-	 */
-	result = handle_signal(SIGPIPE, SIG_IGN);
-	if (result != ISC_R_SUCCESS)
-		goto cleanup;
-
-	dhcp_gbl_ctx.actx_started = ISC_TRUE;
-
-	result = isc_taskmgr_createinctx(dhcp_gbl_ctx.mctx,
-					 dhcp_gbl_ctx.actx,
-					 1, 0,
-					 &dhcp_gbl_ctx.taskmgr);
-	if (result != ISC_R_SUCCESS)
-		goto cleanup;
-
-	result = isc_socketmgr_createinctx(dhcp_gbl_ctx.mctx,
-					   dhcp_gbl_ctx.actx,
-					   &dhcp_gbl_ctx.socketmgr);
-	if (result != ISC_R_SUCCESS)
-		goto cleanup;
-
-	result = isc_timermgr_createinctx(dhcp_gbl_ctx.mctx,
-					  dhcp_gbl_ctx.actx,
-					  &dhcp_gbl_ctx.timermgr);
-	if (result != ISC_R_SUCCESS)
-		goto cleanup;
-
-	result = isc_task_create(dhcp_gbl_ctx.taskmgr, 0, &dhcp_gbl_ctx.task);
-	if (result != ISC_R_SUCCESS)
-		goto cleanup;
+		result = isc_mem_create(0, 0, &dhcp_gbl_ctx.mctx);
+		if (result != ISC_R_SUCCESS)
+			goto cleanup;
+
+		result = isc_appctx_create(dhcp_gbl_ctx.mctx, &dhcp_gbl_ctx.actx);
+		if (result != ISC_R_SUCCESS)
+			goto cleanup;
+
+		result = isc_app_ctxstart(dhcp_gbl_ctx.actx);
+		if (result != ISC_R_SUCCESS)
+			goto cleanup;
+
+		/*
+		 * Always ignore SIGPIPE.
+		 * Otherwise we will die before the errno == EPIPE
+		 * checks in the socket code are reached.
+		 *
+		 * Note: unlike isc_app_start(), isc_app_ctxstart()
+		 *       does not set any signal handlers.
+		 */
+		result = handle_signal(SIGPIPE, SIG_IGN);
+		if (result != ISC_R_SUCCESS)
+			goto cleanup;
+
+		dhcp_gbl_ctx.actx_started = ISC_TRUE;
+
+		result = isc_taskmgr_createinctx(dhcp_gbl_ctx.mctx,
+						 dhcp_gbl_ctx.actx,
+						 1, 0,
+						 &dhcp_gbl_ctx.taskmgr);
+		if (result != ISC_R_SUCCESS)
+			goto cleanup;
+
+		result = isc_socketmgr_createinctx(dhcp_gbl_ctx.mctx,
+						   dhcp_gbl_ctx.actx,
+						   &dhcp_gbl_ctx.socketmgr);
+		if (result != ISC_R_SUCCESS)
+			goto cleanup;
+
+		result = isc_timermgr_createinctx(dhcp_gbl_ctx.mctx,
+						  dhcp_gbl_ctx.actx,
+						  &dhcp_gbl_ctx.timermgr);
+		if (result != ISC_R_SUCCESS)
+			goto cleanup;
+
+		result = isc_task_create(dhcp_gbl_ctx.taskmgr, 0, &dhcp_gbl_ctx.task);
+		if (result != ISC_R_SUCCESS)
+			goto cleanup;
+	}
 
 #if defined (NSUPDATE)
-	result = dns_client_createx(dhcp_gbl_ctx.mctx,
-				    dhcp_gbl_ctx.actx,
-				    dhcp_gbl_ctx.taskmgr,
-				    dhcp_gbl_ctx.socketmgr,
-				    dhcp_gbl_ctx.timermgr,
-				    0,
-				    &dhcp_gbl_ctx.dnsclient);
-	if (result != ISC_R_SUCCESS)
-		goto cleanup;
-#else
-	/* The dst library is inited as part of dns_lib_init, we don't
-	 * need it if NSUPDATE is enabled */
-	result = dst_lib_init(dhcp_gbl_ctx.mctx, NULL, 0);
-	if (result != ISC_R_SUCCESS)
-		goto cleanup;
-
+	if ((flags & DHCP_CONTEXT_POST_DB) != 0) {
+ 
+		result = dns_client_createx(dhcp_gbl_ctx.mctx,
+					    dhcp_gbl_ctx.actx,
+					    dhcp_gbl_ctx.taskmgr,
+					    dhcp_gbl_ctx.socketmgr,
+					    dhcp_gbl_ctx.timermgr,
+					    0,
+					    &dhcp_gbl_ctx.dnsclient);
+		if (result != ISC_R_SUCCESS)
+			goto cleanup;
+	}
 #endif
 	return(ISC_R_SUCCESS);
 
diff --git a/omapip/test.c b/omapip/test.c
index 1171317..9251d6d 100644
--- a/omapip/test.c
+++ b/omapip/test.c
@@ -51,7 +51,7 @@ int main (int argc, char **argv)
 	omapi_object_t *connection = (omapi_object_t*)0;
 	isc_result_t status;
 
-	status = dhcp_context_create();
+	status = dhcp_context_create(DHCP_CONTEXT_PRE_DB | DHCP_CONTEXT_POST_DB);
 	if (status != ISC_R_SUCCESS) {
 		fprintf(stderr, "Can't initialize context: %s\n",
 			isc_result_totext(status));
diff --git a/relay/dhcrelay.c b/relay/dhcrelay.c
index efd790f..035f54e 100644
--- a/relay/dhcrelay.c
+++ b/relay/dhcrelay.c
@@ -200,7 +200,7 @@ main(int argc, char **argv) {
 #endif	
 
 	/* Set up the isc and dns library managers */
-	status = dhcp_context_create();
+	status = dhcp_context_create(DHCP_CONTEXT_PRE_DB | DHCP_CONTEXT_POST_DB);
 	if (status != ISC_R_SUCCESS)
 		log_fatal("Can't initialize context: %s",
 			  isc_result_totext(status));
diff --git a/server/dhcpd.c b/server/dhcpd.c
index ef967f1..8887ad5 100644
--- a/server/dhcpd.c
+++ b/server/dhcpd.c
@@ -287,7 +287,7 @@ main(int argc, char **argv) {
                 close(fd);
 
 	/* Set up the isc and dns library managers */
-	status = dhcp_context_create();
+	status = dhcp_context_create(DHCP_CONTEXT_PRE_DB);
 	if (status != ISC_R_SUCCESS)
 		log_fatal("Can't initialize context: %s",
 			  isc_result_totext(status));
@@ -1099,6 +1099,11 @@ void postconf_initialization (int quiet)
 	if (ddns_update_style == DDNS_UPDATE_STYLE_AD_HOC) {
 		log_fatal("ddns-update-style ad_hoc no longer supported");
 	}
+
+	if (ddns_update_style != DDNS_UPDATE_STYLE_NONE && dhcp_context_create(DHCP_CONTEXT_POST_DB)
+	    != ISC_R_SUCCESS)
+		log_fatal("Unable to complete ddns initialization");
+
 #else
 	/* If we don't have support for updates compiled in tell the user */
 	if (ddns_update_style != DDNS_UPDATE_STYLE_NONE) {
-- 
2.1.2

openSUSE Build Service is sponsored by