From: Andreas Schneider Date: Wed, 13 Jan 2021 12:18:23 +0000 (+0100) Subject: s3:utils: Migrate smbstatus to new cmdline option parser X-Git-Tag: tevent-0.11.0~750 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=ee5e420dc5c56e0ce56763a3cbe52da0ae80c293;p=thirdparty%2Fsamba.git s3:utils: Migrate smbstatus to new cmdline option parser Signed-off-by: Andreas Schneider Reviewed-by: Andrew Bartlett --- diff --git a/source3/utils/status.c b/source3/utils/status.c index fc21d20f766..4b90ade221a 100644 --- a/source3/utils/status.c +++ b/source3/utils/status.c @@ -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 */ diff --git a/source3/utils/wscript_build b/source3/utils/wscript_build index b9a5facb65c..736807ceda6 100644 --- a/source3/utils/wscript_build +++ b/source3/utils/wscript_build @@ -300,7 +300,7 @@ bld.SAMBA3_BINARY('smbstatus', deps=''' talloc smbconf - popt_samba3 + CMDLINE_S3 cmdline_contexts smbd_base LOCKING