]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
s3:utils: Migrate smbstatus to new cmdline option parser
authorAndreas Schneider <asn@samba.org>
Wed, 13 Jan 2021 12:18:23 +0000 (13:18 +0100)
committerAndrew Bartlett <abartlet@samba.org>
Tue, 25 May 2021 00:23:37 +0000 (00:23 +0000)
Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
source3/utils/status.c
source3/utils/wscript_build

index fc21d20f766dd105dfc7fd183028bece3ae431b7..4b90ade221a1796c42713a6b72bc21ac04c44244 100644 (file)
@@ -34,7 +34,7 @@
 #include "lib/util/server_id.h"
 #include "smbd/globals.h"
 #include "system/filesys.h"
-#include "popt_common.h"
+#include "lib/cmdline/cmdline.h"
 #include "dbwrap/dbwrap.h"
 #include "dbwrap/dbwrap_open.h"
 #include "../libcli/security/security.h"
@@ -638,6 +638,7 @@ int main(int argc, const char *argv[])
                        .descrip    = "Try to resolve UIDs to usernames"
                },
                POPT_COMMON_SAMBA
+               POPT_COMMON_VERSION
                POPT_TABLEEND
        };
        TALLOC_CTX *frame = talloc_stackframe();
@@ -646,28 +647,29 @@ int main(int argc, const char *argv[])
        char *db_path;
        bool ok;
 
-       sec_init();
        smb_init_locale();
 
-       setup_logging(argv[0], DEBUG_STDERR);
-       lp_set_cmdline("log level", "0");
-
-       if (getuid() != geteuid()) {
-               d_printf("smbstatus should not be run setuid\n");
-               ret = 1;
-               goto done;
+       ok = samba_cmdline_init(frame,
+                               SAMBA_CMDLINE_CONFIG_CLIENT,
+                               false /* require_smbconf */);
+       if (!ok) {
+               DBG_ERR("Failed to init cmdline parser!\n");
+               TALLOC_FREE(frame);
+               exit(1);
        }
+       lp_set_cmdline("log level", "0");
 
-       if (getuid() != 0) {
-               d_printf("smbstatus only works as root!\n");
-               ret = 1;
-               goto done;
+       pc = samba_popt_get_context(getprogname(),
+                                   argc,
+                                   argv,
+                                   long_options,
+                                   POPT_CONTEXT_KEEP_FIRST);
+       if (pc == NULL) {
+               DBG_ERR("Failed to setup popt context!\n");
+               TALLOC_FREE(frame);
+               exit(1);
        }
 
-
-       pc = poptGetContext(NULL, argc, argv, long_options,
-                           POPT_CONTEXT_KEEP_FIRST);
-
        while ((c = poptGetNextOpt(pc)) != -1) {
                switch (c) {
                case 'p':
@@ -710,6 +712,20 @@ int main(int argc, const char *argv[])
                }
        }
 
+       sec_init();
+
+       if (getuid() != geteuid()) {
+               d_printf("smbstatus should not be run setuid\n");
+               ret = 1;
+               goto done;
+       }
+
+       if (getuid() != 0) {
+               d_printf("smbstatus only works as root!\n");
+               ret = 1;
+               goto done;
+       }
+
        /* setup the flags based on the possible combincations */
 
        show_processes = !(shares_only || locks_only || profile_only) || processes_only;
@@ -730,13 +746,6 @@ int main(int argc, const char *argv[])
                goto done;
        }
 
-       if (!lp_load_global(get_dyn_CONFIGFILE())) {
-               fprintf(stderr, "Can't load %s - run testparm to debug it\n",
-                       get_dyn_CONFIGFILE());
-               ret = -1;
-               goto done;
-       }
-
        switch (profile_only) {
                case 'P':
                        /* Dump profile data */
index b9a5facb65c241438e4df7b75c7cf6e0fda655e3..736807ceda6366d21d3ad182933a79b1d86f2784 100644 (file)
@@ -300,7 +300,7 @@ bld.SAMBA3_BINARY('smbstatus',
                  deps='''
                       talloc
                       smbconf
-                      popt_samba3
+                      CMDLINE_S3
                       cmdline_contexts
                       smbd_base
                       LOCKING