s3: popt_common: use client_messaging_context()
authorRalph Boehme <slow@samba.org>
Tue, 10 Jul 2018 13:26:40 +0000 (15:26 +0200)
committerRalph Boehme <slow@samba.org>
Tue, 10 Jul 2018 15:53:58 +0000 (17:53 +0200)
This adds calls to client_messaging_context() to the popt hooks and
ensure any client tool that uses POPT_COMMON_SAMBA or
POPT_COMMON_CREDENTIALS gets an implicit messaging context, ensuring it
doesn't crash in lp_load_*() which, with include=registry in smb.conf on
a cluster, in most lp_load_*() cases ends up loading the registry
config.

It crashes in the registry config initialisation because
messaging_ctdb_connection() panics with a missing ctdb messaging
connection.

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

Signed-off-by: Ralph Boehme <slow@samba.org>
source3/lib/popt_common.c

index cc93a756c3ba529aa5fbaf2443ad3a109d6c039c..1a1b0f3b3641884f5c6559ea2847a08cb148092b 100644 (file)
@@ -81,6 +81,7 @@ static void popt_common_callback(poptContext con,
        }
 
        if (reason == POPT_CALLBACK_REASON_POST) {
+               struct messaging_context *msg_ctx = NULL;
 
                if (PrintSambaVersionString) {
                        printf( "Version %s\n", samba_version_string());
@@ -93,6 +94,14 @@ static void popt_common_callback(poptContext con,
                        }
                }
 
+               msg_ctx = client_messaging_context(get_dyn_CONFIGFILE());
+               if (msg_ctx == NULL) {
+                       fprintf(stderr, "Unable to initialize messaging context.");
+                       if (geteuid() == 0) {
+                               exit(1);
+                       }
+               }
+
                /* Further 'every Samba program must do this' hooks here. */
                return;
        }
@@ -287,11 +296,20 @@ static void popt_common_credentials_callback(poptContext con,
 
        if (reason == POPT_CALLBACK_REASON_POST) {
                bool ok;
+               struct messaging_context *msg_ctx = NULL;
 
                if (override_logfile) {
                        setup_logging(lp_logfile(talloc_tos()), DEBUG_FILE );
                }
 
+               msg_ctx = client_messaging_context(get_dyn_CONFIGFILE());
+               if (msg_ctx == NULL) {
+                       fprintf(stderr, "Unable to initialize messaging context.");
+                       if (geteuid() == 0) {
+                               exit(1);
+                       }
+               }
+
                ok = lp_load_client(get_dyn_CONFIGFILE());
                if (!ok) {
                        const char *pname = poptGetInvocationName(con);