From d8f84205337a8baae7f4057a042e74b3d1c3633a Mon Sep 17 00:00:00 2001 From: Andreas Schneider Date: Tue, 5 Jan 2021 14:35:39 +0100 Subject: [PATCH] s3:smbd: Migrate smbd to new cmdline option parser Signed-off-by: Andreas Schneider Reviewed-by: Andrew Bartlett --- source3/smbd/server.c | 51 ++++++++++++++++++++++++++----------------- source3/wscript_build | 2 +- 2 files changed, 32 insertions(+), 21 deletions(-) diff --git a/source3/smbd/server.c b/source3/smbd/server.c index 468bd21cf75..bb7820399cd 100644 --- a/source3/smbd/server.c +++ b/source3/smbd/server.c @@ -25,7 +25,7 @@ #include "system/filesys.h" #include "lib/util/server_id.h" #include "lib/util/close_low_fd.h" -#include "popt_common.h" +#include "lib/cmdline/cmdline.h" #include "locking/share_mode_lock.h" #include "smbd/smbd.h" #include "smbd/globals.h" @@ -1624,6 +1624,7 @@ extern void build_options(bool screen); .descrip = "Set profiling level","PROFILE_LEVEL", }, POPT_COMMON_SAMBA + POPT_COMMON_VERSION POPT_TABLEEND }; struct smbd_parent_context *parent = NULL; @@ -1654,6 +1655,7 @@ extern void build_options(bool screen); .exit_server = smbd_exit_server, .exit_server_cleanly = smbd_exit_server_cleanly, }; + bool ok; /* * Do this before any other talloc operation @@ -1661,8 +1663,6 @@ extern void build_options(bool screen); talloc_enable_null_tracking(); frame = talloc_stackframe(); - setup_logging(argv[0], DEBUG_DEFAULT_STDOUT); - smb_init_locale(); set_smbd_shim(&smbd_shim_fns); @@ -1675,7 +1675,24 @@ extern void build_options(bool screen); set_auth_parameters(argc,argv); #endif - pc = poptGetContext("smbd", argc, argv, long_options, 0); + ok = samba_cmdline_init(frame, + SAMBA_CMDLINE_CONFIG_SERVER, + true /* require_smbconf */); + if (!ok) { + DBG_ERR("Failed to setup cmdline parser!\n"); + exit(ENOMEM); + } + + pc = samba_popt_get_context(getprogname(), + argc, + argv, + long_options, + 0); + if (pc == NULL) { + DBG_ERR("Failed to get popt context!\n"); + exit(ENOMEM); + } + while((opt = poptGetNextOpt(pc)) != -1) { switch (opt) { case OPT_DAEMON: @@ -1750,7 +1767,6 @@ extern void build_options(bool screen); gain_root_privilege(); gain_root_group_privilege(); - fault_setup(); dump_core_setup("smbd", lp_logfile(talloc_tos(), lp_sub)); /* we are never interested in SIGPIPE */ @@ -1800,11 +1816,6 @@ extern void build_options(bool screen); exit(1); } - if (!lp_load_initial_only(get_dyn_CONFIGFILE())) { - DEBUG(0, ("error opening config file '%s'\n", get_dyn_CONFIGFILE())); - exit(1); - } - /* * This calls unshare(CLONE_FS); on linux * in order to check if the running kernel/container @@ -2132,11 +2143,11 @@ extern void build_options(bool screen); if (serving_printers) { bool bgq = lp_parm_bool(-1, "smbd", "backgroundqueue", true); - bool ok = printing_subsystem_init(ev_ctx, - msg_ctx, - dce_ctx, - true, - bgq); + ok = printing_subsystem_init(ev_ctx, + msg_ctx, + dce_ctx, + true, + bgq); if (!ok) { exit_daemon("Samba failed to init printing subsystem", EACCES); } @@ -2149,11 +2160,11 @@ extern void build_options(bool screen); } #endif } else if (serving_printers) { - bool ok = printing_subsystem_init(ev_ctx, - msg_ctx, - dce_ctx, - false, - false); + ok = printing_subsystem_init(ev_ctx, + msg_ctx, + dce_ctx, + false, + false); if (!ok) { exit(1); } diff --git a/source3/wscript_build b/source3/wscript_build index a1e91d532b1..6eea00acd69 100644 --- a/source3/wscript_build +++ b/source3/wscript_build @@ -1101,7 +1101,7 @@ bld.SAMBA3_SUBSYSTEM('fd_handle', bld.SAMBA3_BINARY('smbd/smbd', source='smbd/server.c smbd/smbd_cleanupd.c', deps=''' - popt_samba3 + CMDLINE_S3 smbd_base EPMD LSASD -- 2.47.3