s3:smbpasswd: Use cmdline_messaging_context
authorChristof Schmitt <cs@samba.org>
Mon, 20 Aug 2018 22:38:33 +0000 (15:38 -0700)
committerAndreas Schneider <asn@cryptomilk.org>
Fri, 7 Sep 2018 15:26:15 +0000 (17:26 +0200)
smbpasswd does not use POPT_CREDENTIALS. Call cmdline_messaging_context
to initialize a messaging_context with proper error checking before
calling lp_load_global.

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

Signed-off-by: Christof Schmitt <cs@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
source3/utils/smbpasswd.c
source3/utils/wscript_build

index 04f34aa9b695e49eed87476d406a1507be9cf4db..8e2b9d7f80fda7ad9d56df5af5058d25766a883b 100644 (file)
@@ -23,6 +23,7 @@
 #include "../lib/util/util_pw.h"
 #include "libsmb/proto.h"
 #include "passdb.h"
+#include "cmdline_contexts.h"
 
 /*
  * Next two lines needed for SunOS and don't
@@ -196,6 +197,8 @@ static int process_options(int argc, char **argv, int local_flags)
                usage();
        }
 
+       cmdline_messaging_context(configfile);
+
        if (!lp_load_global(configfile)) {
                fprintf(stderr, "Can't load %s - run testparm to debug it\n", 
                        configfile);
@@ -614,7 +617,6 @@ static int process_nonroot(int local_flags)
 int main(int argc, char **argv)
 {      
        TALLOC_CTX *frame = talloc_stackframe();
-       struct messaging_context *msg_ctx = NULL;
        int local_flags = 0;
        int ret;
 
@@ -632,19 +634,6 @@ int main(int argc, char **argv)
 
        setup_logging("smbpasswd", DEBUG_STDERR);
 
-       msg_ctx = server_messaging_context();
-       if (msg_ctx == NULL) {
-               if (geteuid() != 0) {
-                       DBG_NOTICE("Unable to initialize messaging context. "
-                                  "Must be root to do that.\n");
-               } else {
-                       fprintf(stderr,
-                               "smbpasswd is not able to initialize the "
-                               "messaging context!\n");
-                       return 1;
-               }
-       }
-
        /*
         * Set the machine NETBIOS name if not already
         * set from the config file. 
index 67bb87e7a747465de3b62b470d1514a5e9e4c22b..06a986cada4fb887eecd60b1604665256c3707a6 100644 (file)
@@ -37,7 +37,9 @@ bld.SAMBA3_BINARY('smbpasswd',
                  smbconf
                  pdb
                  PASSWD_UTIL
-                 PASSCHANGE''')
+                 PASSCHANGE
+                 cmdline_contexts
+                 ''')
 
 bld.SAMBA3_BINARY('pdbedit',
                  source='pdbedit.c',