[SCM] Samba Shared Repository - branch master updated

Jeremy Allison jra at samba.org
Mon Apr 17 21:11:03 UTC 2017


The branch, master has been updated
       via  ab597b9 s4: server: Use state as the talloc context for open_schannel_session_store.
       via  f24ecb0 s4: server: Remove use of talloc_autofree_context as the parent of event_ctx.
       via  fc8f858 s4: messaging: When talloc_free()'ing an event context, only remove msg_dgm_ref's that point to *that* context.
       via  5fe996b s4: server: Add a tevent signal handler for SIGTERM.
       via  139793c s4: server: Add error return checks for tevent_add_fde, tevent_add_timer.
       via  1ae7028 s4: server: Plumb server_state through the irpc messaging for samba_terminate().
       via  d721b8d s4: server: Use server_state as a parameter to max_runtime_handler, not just name.
       via  cc14187 s4: server: Use server_state as a parameter to stdin handler, not just name.
       via  a7d0e54 s4: server: Create a server 'state' struct.
       via  33f5997 s4: server. Whitespace and 80+ column cleanup.
       via  6115738 s4: messaging. Minor cleanup. Check for error returns on imessaging_register calls.
      from  5c04521 s3:tests: Add test for illegal value detection for 'name resolve order'

https://git.samba.org/?p=samba.git;a=shortlog;h=master


- Log -----------------------------------------------------------------
commit ab597b9a47102e111a426640ac3ab32aa291687b
Author: Jeremy Allison <jra at samba.org>
Date:   Mon Apr 3 18:16:02 2017 +0000

    s4: server: Use state as the talloc context for open_schannel_session_store.
    
    Ensure it's freed on all error paths.
    
    Signed-off-by: Jeremy Allison <jra at samba.org>
    Reviewed-by: Volker Lendecke <vl at samba.org>
    
    Autobuild-User(master): Jeremy Allison <jra at samba.org>
    Autobuild-Date(master): Mon Apr 17 23:10:06 CEST 2017 on sn-devel-144

commit f24ecb035b8719c961e1e4ad7c4948f1dbd5165b
Author: Jeremy Allison <jra at samba.org>
Date:   Mon Apr 3 18:04:31 2017 +0000

    s4: server: Remove use of talloc_autofree_context as the parent of event_ctx.
    
    Use state->event_ctx as the parent of the initial imessaging context.
    
    Now we control all exit paths, we can call TALLOC_FREE(state)
    on all of them.
    
    Signed-off-by: Jeremy Allison <jra at samba.org>
    Reviewed-by: Volker Lendecke <vl at samba.org>

commit fc8f858c8cdac4a50517e48d4f5af6273c27b894
Author: Jeremy Allison <jra at samba.org>
Date:   Mon Apr 3 17:58:24 2017 +0000

    s4: messaging: When talloc_free()'ing an event context, only remove msg_dgm_ref's that point to *that* context.
    
    Defensive programming change. Not strictly needed to prevent
    any crash/error.
    
    Signed-off-by: Jeremy Allison <jra at samba.org>
    Reviewed-by: Volker Lendecke <vl at samba.org>

commit 5fe996bc1f0b80e8e68c6fd558222e42b5916b9a
Author: Jeremy Allison <jra at samba.org>
Date:   Fri Mar 31 12:38:14 2017 -0700

    s4: server: Add a tevent signal handler for SIGTERM.
    
    Simplify by removing global state we don't need now
    we're called by tevent (and in the short window where
    we're installed by CatchSignal but before we install
    the tevent handler we don't need the complex global
    state handling as we have no forked children).
    
    We now have access to struct server_state on all
    exit paths - next commits will stop using talloc autofree context.
    
    Signed-off-by: Jeremy Allison <jra at samba.org>
    Reviewed-by: Volker Lendecke <vl at samba.org>

commit 139793ce06ed5611d3eb37fc09f974265289ec55
Author: Jeremy Allison <jra at samba.org>
Date:   Fri Mar 31 12:29:03 2017 -0700

    s4: server: Add error return checks for tevent_add_fde, tevent_add_timer.
    
    Signed-off-by: Jeremy Allison <jra at samba.org>
    Reviewed-by: Volker Lendecke <vl at samba.org>

commit 1ae7028e47076bee2d779a306b5ecb283a02ac0f
Author: Jeremy Allison <jra at samba.org>
Date:   Fri Mar 31 12:23:56 2017 -0700

    s4: server: Plumb server_state through the irpc messaging for samba_terminate().
    
    Use it in the message print to avoid a "unused variable" compile error.
    
    Signed-off-by: Jeremy Allison <jra at samba.org>
    Reviewed-by: Volker Lendecke <vl at samba.org>

commit d721b8d86b2f2355bd74c13da010843afcd8c3d2
Author: Jeremy Allison <jra at samba.org>
Date:   Fri Mar 31 12:00:29 2017 -0700

    s4: server: Use server_state as a parameter to max_runtime_handler, not just name.
    
    Signed-off-by: Jeremy Allison <jra at samba.org>
    Reviewed-by: Volker Lendecke <vl at samba.org>

commit cc14187c5ced700f99162d9e3425bb5b87bb70e9
Author: Jeremy Allison <jra at samba.org>
Date:   Fri Mar 31 11:59:13 2017 -0700

    s4: server: Use server_state as a parameter to stdin handler, not just name.
    
    Signed-off-by: Jeremy Allison <jra at samba.org>
    Reviewed-by: Volker Lendecke <vl at samba.org>

commit a7d0e54969701f61a9b05fd7ef2141e1fd673a81
Author: Jeremy Allison <jra at samba.org>
Date:   Fri Mar 31 11:54:45 2017 -0700

    s4: server: Create a server 'state' struct.
    
    No logic changes, will be used to move allocated
    pointers off the talloc autofree context in a later commit.
    
    Signed-off-by: Jeremy Allison <jra at samba.org>
    Reviewed-by: Volker Lendecke <vl at samba.org>

commit 33f599737d8732fa4f41d696b94ef3f07aae49ff
Author: Jeremy Allison <jra at samba.org>
Date:   Fri Mar 31 11:43:17 2017 -0700

    s4: server. Whitespace and 80+ column cleanup.
    
    No logic changes.
    
    Signed-off-by: Jeremy Allison <jra at samba.org>
    Reviewed-by: Volker Lendecke <vl at samba.org>

commit 61157388e7f6af2c0a408d03944f6f86244e33d6
Author: Jeremy Allison <jra at samba.org>
Date:   Fri Mar 31 11:07:35 2017 -0700

    s4: messaging. Minor cleanup. Check for error returns on imessaging_register calls.
    
    Signed-off-by: Jeremy Allison <jra at samba.org>
    Reviewed-by: Volker Lendecke <vl at samba.org>

-----------------------------------------------------------------------

Summary of changes:
 source4/lib/messaging/messaging.c |  36 ++++--
 source4/lib/messaging/messaging.h |   2 +-
 source4/smbd/server.c             | 263 +++++++++++++++++++++++++++-----------
 3 files changed, 214 insertions(+), 87 deletions(-)


Changeset truncated at 500 lines:

diff --git a/source4/lib/messaging/messaging.c b/source4/lib/messaging/messaging.c
index 844466d..2da0acc 100644
--- a/source4/lib/messaging/messaging.c
+++ b/source4/lib/messaging/messaging.c
@@ -256,18 +256,20 @@ static int imessaging_context_destructor(struct imessaging_context *msg)
 }
 
 /*
- * Cleanup messaging dgm contexts
+ * Cleanup messaging dgm contexts on a specific event context.
  *
  * We must make sure to unref all messaging_dgm_ref's *before* the
  * tevent context goes away. Only when the last ref is freed, the
  * refcounted messaging dgm context will be freed.
  */
-void imessaging_dgm_unref_all(void)
+void imessaging_dgm_unref_ev(struct tevent_context *ev)
 {
 	struct imessaging_context *msg = NULL;
 
 	for (msg = msg_ctxs; msg != NULL; msg = msg->next) {
-		TALLOC_FREE(msg->msg_dgm_ref);
+		if (msg->ev == ev) {
+			TALLOC_FREE(msg->msg_dgm_ref);
+		}
 	}
 }
 
@@ -322,6 +324,7 @@ struct imessaging_context *imessaging_init(TALLOC_CTX *mem_ctx,
 					   struct server_id server_id,
 					   struct tevent_context *ev)
 {
+	NTSTATUS status;
 	struct imessaging_context *msg;
 	bool ok;
 	int ret;
@@ -393,11 +396,28 @@ struct imessaging_context *imessaging_init(TALLOC_CTX *mem_ctx,
 		goto fail;
 	}
 
-	imessaging_register(msg, NULL, MSG_PING, ping_message);
-	imessaging_register(msg, NULL, MSG_REQ_POOL_USAGE, pool_message);
-	imessaging_register(msg, NULL, MSG_IRPC, irpc_handler);
-	imessaging_register(msg, NULL, MSG_REQ_RINGBUF_LOG, ringbuf_log_msg);
-	IRPC_REGISTER(msg, irpc, IRPC_UPTIME, irpc_uptime, msg);
+	status = imessaging_register(msg, NULL, MSG_PING, ping_message);
+	if (!NT_STATUS_IS_OK(status)) {
+		goto fail;
+	}
+	status = imessaging_register(msg, NULL, MSG_REQ_POOL_USAGE,
+				     pool_message);
+	if (!NT_STATUS_IS_OK(status)) {
+		goto fail;
+	}
+	status = imessaging_register(msg, NULL, MSG_IRPC, irpc_handler);
+	if (!NT_STATUS_IS_OK(status)) {
+		goto fail;
+	}
+	status = imessaging_register(msg, NULL, MSG_REQ_RINGBUF_LOG,
+				     ringbuf_log_msg);
+	if (!NT_STATUS_IS_OK(status)) {
+		goto fail;
+	}
+	status = IRPC_REGISTER(msg, irpc, IRPC_UPTIME, irpc_uptime, msg);
+	if (!NT_STATUS_IS_OK(status)) {
+		goto fail;
+	}
 
 	DLIST_ADD(msg_ctxs, msg);
 
diff --git a/source4/lib/messaging/messaging.h b/source4/lib/messaging/messaging.h
index e587fdf..668464d 100644
--- a/source4/lib/messaging/messaging.h
+++ b/source4/lib/messaging/messaging.h
@@ -44,7 +44,7 @@ struct imessaging_context *imessaging_init(TALLOC_CTX *mem_ctx,
 					   struct loadparm_context *lp_ctx,
 					   struct server_id server_id,
 					   struct tevent_context *ev);
-void imessaging_dgm_unref_all(void);
+void imessaging_dgm_unref_ev(struct tevent_context *ev);
 NTSTATUS imessaging_reinit_all(void);
 int imessaging_cleanup(struct imessaging_context *msg);
 struct imessaging_context *imessaging_client_init(TALLOC_CTX *mem_ctx,
diff --git a/source4/smbd/server.c b/source4/smbd/server.c
index b8545b8..fdc36de 100644
--- a/source4/smbd/server.c
+++ b/source4/smbd/server.c
@@ -1,4 +1,4 @@
-/* 
+/*
    Unix SMB/CIFS implementation.
 
    Main SMB server routines
@@ -7,17 +7,17 @@
    Copyright (C) Martin Pool			2002
    Copyright (C) Jelmer Vernooij		2002
    Copyright (C) James J Myers 			2003 <myersjj at samba.org>
-   
+
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 3 of the License, or
    (at your option) any later version.
-   
+
    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.
-   
+
    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
@@ -44,6 +44,11 @@
 #include "nsswitch/winbind_client.h"
 #include "libds/common/roles.h"
 
+struct server_state {
+	struct tevent_context *event_ctx;
+	const char *binary_name;
+};
+
 /*
   recursively delete a directory tree
 */
@@ -75,7 +80,7 @@ static void recursive_delete(const char *path)
 			continue;
 		}
 		if (unlink(fname) != 0) {
-			DEBUG(0,("Unabled to delete '%s' - %s\n", 
+			DEBUG(0,("Unabled to delete '%s' - %s\n",
 				 fname, strerror(errno)));
 			smb_panic("unable to cleanup tmp files");
 		}
@@ -89,7 +94,7 @@ static void recursive_delete(const char *path)
   TDB_CLEAR_IF_FIRST. Unfortunately TDB_CLEAR_IF_FIRST is not
   efficient on unix systems due to the lack of scaling of the byte
   range locking system. So instead of putting the burden on tdb to
-  cleanup tmp files, this function deletes them. 
+  cleanup tmp files, this function deletes them.
 */
 static void cleanup_tmp_files(struct loadparm_context *lp_ctx)
 {
@@ -110,10 +115,12 @@ static void sig_hup(int sig)
 static void sig_term(int sig)
 {
 #if HAVE_GETPGRP
-	static int done_sigterm;
-	if (done_sigterm == 0 && getpgrp() == getpid()) {
+	if (getpgrp() == getpid()) {
+		/*
+		 * We're the process group leader, send
+		 * SIGTERM to our process group.
+		 */
 		DEBUG(0,("SIGTERM: killing children\n"));
-		done_sigterm = 1;
 		kill(-getpgrp(), SIGTERM);
 	}
 #endif
@@ -121,6 +128,19 @@ static void sig_term(int sig)
 	exit(127);
 }
 
+static void sigterm_signal_handler(struct tevent_context *ev,
+				struct tevent_signal *se,
+				int signum, int count, void *siginfo,
+				void *private_data)
+{
+	struct server_state *state = talloc_get_type_abort(
+                private_data, struct server_state);
+
+	DEBUG(10,("Process %s got SIGTERM\n", state->binary_name));
+	TALLOC_FREE(state);
+	sig_term(SIGTERM);
+}
+
 /*
   setup signal masks
 */
@@ -143,7 +163,8 @@ static void setup_signals(void)
 #endif
 
 	/* POSIX demands that signals are inherited. If the invoking process has
-	 * these signals masked, we will have problems, as we won't receive them. */
+	 * these signals masked, we will have problems,
+	 * as we won't receive them. */
 	BlockSignals(false, SIGHUP);
 	BlockSignals(false, SIGTERM);
 
@@ -154,19 +175,25 @@ static void setup_signals(void)
 /*
   handle io on stdin
 */
-static void server_stdin_handler(struct tevent_context *event_ctx, struct tevent_fd *fde, 
-				 uint16_t flags, void *private_data)
+static void server_stdin_handler(struct tevent_context *event_ctx,
+				struct tevent_fd *fde,
+				uint16_t flags,
+				void *private_data)
 {
-	const char *binary_name = (const char *)private_data;
+	struct server_state *state = talloc_get_type_abort(
+		private_data, struct server_state);
 	uint8_t c;
 	if (read(0, &c, 1) == 0) {
-		DEBUG(0,("%s: EOF on stdin - PID %d terminating\n", binary_name, (int)getpid()));
+		DEBUG(0,("%s: EOF on stdin - PID %d terminating\n",
+				state->binary_name, (int)getpid()));
 #if HAVE_GETPGRP
 		if (getpgrp() == getpid()) {
-			DEBUG(0,("Sending SIGTERM from pid %d\n", (int)getpid()));
+			DEBUG(0,("Sending SIGTERM from pid %d\n",
+				(int)getpid()));
 			kill(-getpgrp(), SIGTERM);
 		}
 #endif
+		TALLOC_FREE(state);
 		exit(0);
 	}
 }
@@ -174,13 +201,19 @@ static void server_stdin_handler(struct tevent_context *event_ctx, struct tevent
 /*
   die if the user selected maximum runtime is exceeded
 */
-_NORETURN_ static void max_runtime_handler(struct tevent_context *ev, 
-					   struct tevent_timer *te, 
+_NORETURN_ static void max_runtime_handler(struct tevent_context *ev,
+					   struct tevent_timer *te,
 					   struct timeval t, void *private_data)
 {
-	const char *binary_name = (const char *)private_data;
-	DEBUG(0,("%s: maximum runtime exceeded - terminating PID %d at %llu, current ts: %llu\n",
-		 binary_name, (int)getpid(), (unsigned long long)t.tv_sec, (unsigned long long) time(NULL)));
+	struct server_state *state = talloc_get_type_abort(
+		private_data, struct server_state);
+	DEBUG(0,("%s: maximum runtime exceeded - "
+		"terminating PID %d at %llu, current ts: %llu\n",
+		 state->binary_name,
+		(int)getpid(),
+		(unsigned long long)t.tv_sec,
+		(unsigned long long)time(NULL)));
+	TALLOC_FREE(state);
 	exit(0);
 }
 
@@ -193,7 +226,11 @@ static void prime_ldb_databases(struct tevent_context *event_ctx)
 	TALLOC_CTX *db_context;
 	db_context = talloc_new(event_ctx);
 
-	samdb_connect(db_context, event_ctx, cmdline_lp_ctx, system_session(cmdline_lp_ctx), 0);
+	samdb_connect(db_context,
+			event_ctx,
+			cmdline_lp_ctx,
+			system_session(cmdline_lp_ctx),
+			0);
 	privilege_connect(db_context, cmdline_lp_ctx);
 
 	/* we deliberately leave these open, which allows them to be
@@ -204,26 +241,30 @@ static void prime_ldb_databases(struct tevent_context *event_ctx)
 /*
   called when a fatal condition occurs in a child task
  */
-static NTSTATUS samba_terminate(struct irpc_message *msg, 
+static NTSTATUS samba_terminate(struct irpc_message *msg,
 				struct samba_terminate *r)
 {
-	DEBUG(0,("samba_terminate of %d: %s\n",
-		 (int)getpid(), r->in.reason));
+	struct server_state *state = talloc_get_type(msg->private_data,
+					struct server_state);
+	DBG_ERR("samba_terminate of %s %d: %s\n",
+		state->binary_name, (int)getpid(), r->in.reason);
+	TALLOC_FREE(state);
 	exit(1);
 }
 
 /*
   setup messaging for the top level samba (parent) task
  */
-static NTSTATUS setup_parent_messaging(struct tevent_context *event_ctx, 
+static NTSTATUS setup_parent_messaging(struct server_state *state,
 				       struct loadparm_context *lp_ctx)
 {
 	struct imessaging_context *msg;
 	NTSTATUS status;
 
-	msg = imessaging_init(talloc_autofree_context(),
+	msg = imessaging_init(state->event_ctx,
 			      lp_ctx,
-			      cluster_id(0, SAMBA_PARENT_TASKID), event_ctx);
+			      cluster_id(0, SAMBA_PARENT_TASKID),
+			      state->event_ctx);
 	NT_STATUS_HAVE_NO_MEMORY(msg);
 
 	status = irpc_add_name(msg, "samba");
@@ -232,7 +273,7 @@ static NTSTATUS setup_parent_messaging(struct tevent_context *event_ctx,
 	}
 
 	status = IRPC_REGISTER(msg, irpc, SAMBA_TERMINATE,
-			       samba_terminate, NULL);
+			       samba_terminate, state);
 
 	return status;
 }
@@ -277,7 +318,9 @@ static void show_build(void)
 
 	printf("Paths:\n");
 	for (i=0; config_options[i].name; i++) {
-		printf("   %s: %s\n", config_options[i].name, config_options[i].value);
+		printf("   %s: %s\n",
+			config_options[i].name,
+			config_options[i].value);
 	}
 
 	exit(0);
@@ -285,14 +328,16 @@ static void show_build(void)
 
 static int event_ctx_destructor(struct tevent_context *event_ctx)
 {
-	imessaging_dgm_unref_all();
+	imessaging_dgm_unref_ev(event_ctx);
 	return 0;
 }
 
 /*
  main server.
 */
-static int binary_smbd_main(const char *binary_name, int argc, const char *argv[])
+static int binary_smbd_main(const char *binary_name,
+				int argc,
+				const char *argv[])
 {
 	bool opt_daemon = false;
 	bool opt_interactive = false;
@@ -302,7 +347,6 @@ static int binary_smbd_main(const char *binary_name, int argc, const char *argv[
 	STATIC_service_MODULES_PROTO;
 	init_module_fn static_init[] = { STATIC_service_MODULES };
 	init_module_fn *shared_init;
-	struct tevent_context *event_ctx;
 	uint16_t stdin_event_flags;
 	NTSTATUS status;
 	const char *model = "standard";
@@ -320,15 +364,19 @@ static int binary_smbd_main(const char *binary_name, int argc, const char *argv[
 		 "Become a daemon (default)", NULL },
 		{"interactive",	'i', POPT_ARG_NONE, NULL, OPT_INTERACTIVE,
 		 "Run interactive (not a daemon)", NULL},
-		{"model", 'M', POPT_ARG_STRING,	NULL, OPT_PROCESS_MODEL, 
+		{"model", 'M', POPT_ARG_STRING,	NULL, OPT_PROCESS_MODEL,
 		 "Select process model", "MODEL"},
-		{"maximum-runtime",0, POPT_ARG_INT, &max_runtime, 0, 
-		 "set maximum runtime of the server process, till autotermination", "seconds"},
-		{"show-build", 'b', POPT_ARG_NONE, NULL, OPT_SHOW_BUILD, "show build info", NULL },
+		{"maximum-runtime",0, POPT_ARG_INT, &max_runtime, 0,
+		 "set maximum runtime of the server process, "
+			"till autotermination", "seconds"},
+		{"show-build", 'b', POPT_ARG_NONE, NULL, OPT_SHOW_BUILD,
+			"show build info", NULL },
 		POPT_COMMON_SAMBA
 		POPT_COMMON_VERSION
 		{ NULL }
 	};
+	struct server_state *state = NULL;
+	struct tevent_signal *se = NULL;
 
 	pc = poptGetContext(binary_name, argc, argv, long_options, 0);
 	while((opt = poptGetNextOpt(pc)) != -1) {
@@ -355,7 +403,8 @@ static int binary_smbd_main(const char *binary_name, int argc, const char *argv[
 
 	if (opt_daemon && opt_interactive) {
 		fprintf(stderr,"\nERROR: "
-			  "Option -i|--interactive is not allowed together with -D|--daemon\n\n");
+			"Option -i|--interactive is "
+			"not allowed together with -D|--daemon\n\n");
 		poptPrintUsage(pc, stderr, 0);
 		return 1;
 	} else if (!opt_interactive) {
@@ -374,13 +423,22 @@ static int binary_smbd_main(const char *binary_name, int argc, const char *argv[
 	   so set our umask to 0 */
 	umask(0);
 
-	DEBUG(0,("%s version %s started.\n", binary_name, SAMBA_VERSION_STRING));
-	DEBUGADD(0,("Copyright Andrew Tridgell and the Samba Team 1992-2017\n"));
-
-	if (sizeof(uint16_t) < 2 || sizeof(uint32_t) < 4 || sizeof(uint64_t) < 8) {
-		DEBUG(0,("ERROR: Samba is not configured correctly for the word size on your machine\n"));
-		DEBUGADD(0,("sizeof(uint16_t) = %u, sizeof(uint32_t) %u, sizeof(uint64_t) = %u\n",
-			    (unsigned int)sizeof(uint16_t), (unsigned int)sizeof(uint32_t), (unsigned int)sizeof(uint64_t)));
+	DEBUG(0,("%s version %s started.\n",
+		binary_name,
+		SAMBA_VERSION_STRING));
+	DEBUGADD(0,("Copyright Andrew Tridgell and the Samba Team"
+		" 1992-2017\n"));
+
+	if (sizeof(uint16_t) < 2 ||
+			sizeof(uint32_t) < 4 ||
+			sizeof(uint64_t) < 8) {
+		DEBUG(0,("ERROR: Samba is not configured correctly "
+			"for the word size on your machine\n"));
+		DEBUGADD(0,("sizeof(uint16_t) = %u, sizeof(uint32_t) %u, "
+			"sizeof(uint64_t) = %u\n",
+			(unsigned int)sizeof(uint16_t),
+			(unsigned int)sizeof(uint32_t),
+			(unsigned int)sizeof(uint64_t)));
 		return 1;
 	}
 
@@ -389,6 +447,13 @@ static int binary_smbd_main(const char *binary_name, int argc, const char *argv[
 		become_daemon(true, false, false);
 	}
 
+	/* Create the memory context to hang everything off. */
+	state = talloc_zero(NULL, struct server_state);
+	if (state == NULL) {
+		exit_daemon("Samba cannot create server state", ENOMEM);
+	};
+	state->binary_name = binary_name;
+
 	cleanup_tmp_files(cmdline_lp_ctx);
 
 	if (!directory_exist(lpcfg_lock_directory(cmdline_lp_ctx))) {
@@ -398,19 +463,24 @@ static int binary_smbd_main(const char *binary_name, int argc, const char *argv[
 	pidfile_create(lpcfg_pid_directory(cmdline_lp_ctx), binary_name);
 
 	if (lpcfg_server_role(cmdline_lp_ctx) == ROLE_ACTIVE_DIRECTORY_DC) {
-		if (!open_schannel_session_store(talloc_autofree_context(), cmdline_lp_ctx)) {
-			exit_daemon("Samba cannot open schannel store for secured NETLOGON operations.", EACCES);
+		if (!open_schannel_session_store(state,
+				cmdline_lp_ctx)) {
+			TALLOC_FREE(state);
+			exit_daemon("Samba cannot open schannel store "
+				"for secured NETLOGON operations.", EACCES);
 		}
 	}
 
 	/* make sure we won't go through nss_winbind */
 	if (!winbind_off()) {
-		exit_daemon("Samba failed to disable recusive winbindd calls.", EACCES);
+		TALLOC_FREE(state);
+		exit_daemon("Samba failed to disable recusive "
+			"winbindd calls.", EACCES);
 	}
 
 	gensec_init(); /* FIXME: */
 
-	process_model_init(cmdline_lp_ctx); 
+	process_model_init(cmdline_lp_ctx);
 
 	shared_init = load_samba_modules(NULL, "service");
 
@@ -418,16 +488,17 @@ static int binary_smbd_main(const char *binary_name, int argc, const char *argv[
 	run_init_functions(shared_init);
 
 	talloc_free(shared_init);
-	
+
 	/* the event context is the top level structure in smbd. Everything else
 	   should hang off that */
-	event_ctx = s4_event_context_init(talloc_autofree_context());
+	state->event_ctx = s4_event_context_init(state);
 
-	if (event_ctx == NULL) {
+	if (state->event_ctx == NULL) {
+		TALLOC_FREE(state);
 		exit_daemon("Initializing event context failed", EACCES);
 	}
 
-	talloc_set_destructor(event_ctx, event_ctx_destructor);
+	talloc_set_destructor(state->event_ctx, event_ctx_destructor);
 
 	if (opt_interactive) {
 		/* terminate when stdin goes away */
@@ -443,52 +514,88 @@ static int binary_smbd_main(const char *binary_name, int argc, const char *argv[
 #endif
 
 	if (fstat(0, &st) != 0) {
-		exit_daemon("Samba failed to set standard input handler", ENOTTY);
+		TALLOC_FREE(state);
+		exit_daemon("Samba failed to set standard input handler",
+				ENOTTY);
 	}
 
 	if (S_ISFIFO(st.st_mode) || S_ISSOCK(st.st_mode)) {
-		tevent_add_fd(event_ctx,
-				event_ctx,
+		struct tevent_fd *fde = tevent_add_fd(state->event_ctx,
+				state->event_ctx,
 				0,
 				stdin_event_flags,
 				server_stdin_handler,
-				discard_const(binary_name));
+				state);
+		if (fde == NULL) {
+			TALLOC_FREE(state);
+			exit_daemon("Initializing stdin failed", ENOMEM);
+		}
 	}
 
 	if (max_runtime) {
-		DEBUG(0,("%s PID %d was called with maxruntime %d - current ts %llu\n",


-- 
Samba Shared Repository



More information about the samba-cvs mailing list