s3: lib/server_contexts: add client event and messaging context
authorRalph Boehme <slow@samba.org>
Mon, 9 Jul 2018 15:13:28 +0000 (17:13 +0200)
committerRalph Boehme <slow@samba.org>
Tue, 10 Jul 2018 15:49:15 +0000 (17:49 +0200)
This is similar to the existing server_contexts, but for clients like
smbpasswd, testparm asf.

client_messaging_context() calls lp_load_initial_only() which is needed
to initialize messaging when checking and creating the directories used
for the messaging sockets and lockfiles.

Note that internally client and server event and messaging context must
be the same, as low level in db_open() we call
server_messaging_context().

Bug: https://bugzilla.samba.org/show_bug.cgi?id=13465

Signed-off-by: Ralph Boehme <slow@samba.org>
source3/include/proto.h
source3/lib/server_contexts.c

index fea4ba51be5a0c4846275e424478c68dc598098d..d5f8c7130fa9822095e96de52e12f031a4a61c64 100644 (file)
@@ -893,6 +893,11 @@ void server_event_context_free(void);
 struct messaging_context *server_messaging_context(void);
 void server_messaging_context_free(void);
 
+struct tevent_context *client_event_context(void);
+void client_event_context_free(void);
+struct messaging_context *client_messaging_context(const char *config_file);
+void client_messaging_context_free(void);
+
 /* The following definitions come from lib/sessionid_tdb.c  */
 struct sessionid;
 NTSTATUS sessionid_traverse_read(int (*fn)(const char *key,
index ce9b0ed1b88c75e1e8af8677c394dabb268d7a1a..1586a6535b68cbfcb2b676eea7120ceb27f53fbb 100644 (file)
@@ -63,3 +63,51 @@ void server_messaging_context_free(void)
 {
        TALLOC_FREE(msg_ctx);
 }
+
+struct tevent_context *client_event_context(void)
+{
+       if (ev != NULL) {
+               return ev;
+       }
+
+       /*
+        * Note we MUST use the NULL context here, not the
+        * autofree context, to avoid side effects in forked
+        * children exiting.
+        */
+       ev = samba_tevent_context_init(NULL);
+       if (ev == NULL) {
+               smb_panic("Could not init client's event context");
+       }
+       return ev;
+}
+
+void client_event_context_free(void)
+{
+       TALLOC_FREE(ev);
+}
+
+struct messaging_context *client_messaging_context(const char *config_file)
+{
+       if (msg_ctx != NULL) {
+               return msg_ctx;
+       }
+
+       if (!lp_load_initial_only(config_file)) {
+               return NULL;
+       }
+
+       /*
+        * Note we MUST use the NULL context here, not the
+        * autofree context, to avoid side effects in forked
+        * children exiting.
+        */
+       msg_ctx = messaging_init(NULL, client_event_context());
+
+       return msg_ctx;
+}
+
+void client_messaging_context_free(void)
+{
+       TALLOC_FREE(msg_ctx);
+}