[PATCH 2/6] s3-printing: create printer snums before print_backend_init()

David Disseldorp ddiss at suse.de
Fri Jun 17 05:39:17 MDT 2011


Both print_backend_init() and migrate_printer() walk the list of snums
when checking for valid printer shares. This must be done after the
services have been created following printcap update.
---
 source3/printing/spoolssd.c       |   30 +++++++++++++++++++++++++++++-
 source3/rpc_server/rpc_ep_setup.c |   33 ++++++++++++++++++++++++++-------
 source3/smbd/server.c             |    8 +-------
 3 files changed, 56 insertions(+), 15 deletions(-)

diff --git a/source3/printing/spoolssd.c b/source3/printing/spoolssd.c
index 896aee0..028d357 100644
--- a/source3/printing/spoolssd.c
+++ b/source3/printing/spoolssd.c
@@ -29,6 +29,8 @@
 #include "rpc_server/rpc_server.h"
 #include "rpc_server/rpc_ep_setup.h"
 #include "rpc_server/spoolss/srv_spoolss_nt.h"
+#include "printing/pcap.h"
+#include "printing/load.h"
 
 #define SPOOLSS_PIPE_NAME "spoolss"
 #define DAEMON_NAME "spoolssd"
@@ -130,12 +132,38 @@ static void spoolss_setup_sig_hup_handler(struct tevent_context *ev_ctx,
 	}
 }
 
+static void spoolss_init_pcap_cb(struct tevent_context *ev,
+				 struct messaging_context *msg_ctx)
+{
+	bool ok;
+
+	load_printers(ev, msg_ctx);
+
+	ok = print_backend_init(msg_ctx);
+	if (!ok) {
+		smb_panic("failed to initialise printing backend");
+	}
+
+	ok = nt_printing_tdb_migrate(msg_ctx);
+	if (!ok) {
+		smb_panic("failed to migrate printing tdbs");
+	}
+}
+
+
 static bool spoolss_init_cb(void *ptr)
 {
 	struct messaging_context *msg_ctx = talloc_get_type_abort(
 		ptr, struct messaging_context);
 
-	return nt_printing_tdb_migrate(msg_ctx);
+	/*
+	 * TODO pcap_cache_reload must be changed to call it's callback
+	 * unconditionally.
+	 */
+	pcap_cache_reload(server_event_context(), msg_ctx,
+			  &spoolss_init_pcap_cb);
+
+	return true;
 }
 
 static bool spoolss_shutdown_cb(void *ptr)
diff --git a/source3/rpc_server/rpc_ep_setup.c b/source3/rpc_server/rpc_ep_setup.c
index 2d4c7e9..bf8134a 100644
--- a/source3/rpc_server/rpc_ep_setup.c
+++ b/source3/rpc_server/rpc_ep_setup.c
@@ -51,6 +51,10 @@
 #include "rpc_server/rpc_server.h"
 #include "rpc_server/epmapper/srv_epmapper.h"
 
+#include "include/printing.h"
+#include "printing/pcap.h"
+#include "printing/load.h"
+
 struct dcesrv_ep_context {
 	struct tevent_context *ev_ctx;
 	struct messaging_context *msg_ctx;
@@ -653,25 +657,40 @@ static bool netlogon_init_cb(void *ptr)
 	return true;
 }
 
+static void spoolss_init_pcap_cb(struct tevent_context *ev,
+				 struct messaging_context *msg_ctx)
+{
+	bool ok;
+
+	load_printers(ev, msg_ctx);
+
+	ok = print_backend_init(msg_ctx);
+	if (!ok) {
+		smb_panic("failed to initialise printing backend");
+	}
+
+	ok = nt_printing_tdb_migrate(msg_ctx);
+	if (!ok) {
+		smb_panic("failed to migrate printing tdbs");
+	}
+}
+
 static bool spoolss_init_cb(void *ptr)
 {
 	struct dcesrv_ep_context *ep_ctx =
 		talloc_get_type_abort(ptr, struct dcesrv_ep_context);
 	const char *rpcsrv_type;
-	bool ok;
 
 	rpcsrv_type = lp_parm_const_string(GLOBAL_SECTION_SNUM,
 					   "rpc_server",
 					   "epmapper",
 					   "none");
-
 	/*
-	 * Migrate the printers first.
+	 * TODO pcap_cache_reload must be changed to call it's callback
+	 * unconditionally.
 	 */
-	ok = nt_printing_tdb_migrate(ep_ctx->msg_ctx);
-	if (!ok) {
-		return false;
-	}
+	pcap_cache_reload(ep_ctx->ev_ctx, ep_ctx->msg_ctx,
+			  &spoolss_init_pcap_cb);
 
 	if (StrCaseCmp(rpcsrv_type, "embedded") == 0 ||
 	    StrCaseCmp(rpcsrv_type, "daemon") == 0) {
diff --git a/source3/smbd/server.c b/source3/smbd/server.c
index f1aac81..15d488b 100644
--- a/source3/smbd/server.c
+++ b/source3/smbd/server.c
@@ -1196,9 +1196,6 @@ extern void build_options(bool screen);
 	if (!W_ERROR_IS_OK(registry_init_full()))
 		exit(1);
 
-	if (!print_backend_init(smbd_messaging_context()))
-		exit(1);
-
 	/* Open the share_info.tdb here, so we don't have to open
 	   after the fork on every single connection.  This is a small
 	   performance improvment and reduces the total number of system
@@ -1237,14 +1234,11 @@ extern void build_options(bool screen);
 		}
 	}
 
+	/* spoolss initialisation publishes nt printer services */
 	if (!dcesrv_ep_setup(smbd_event_context(), smbd_server_conn->msg_ctx)) {
 		exit(1);
 	}
 
-	/* Publish nt printers, this requires a working winreg pipe */
-	pcap_cache_reload(server_event_context(), smbd_messaging_context(),
-			  &reload_printers);
-
 	/* only start the background queue daemon if we are 
 	   running as a daemon -- bad things will happen if
 	   smbd is launched via inetd and we fork a copy of 
-- 
1.7.1



More information about the samba-technical mailing list