2 Unix SMB/CIFS implementation.
5 Copyright (C) Tim Potter 2001,2002
6 Copyright (C) Jelmer Vernooij 2002,2003
7 Copyright (C) James Peach 2006
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>.
24 #include "popt_common.h"
25 #include "lib/param/param.h"
27 /* Handle command line options:
40 extern bool override_logfile;
42 static void set_logfile(poptContext con, const char * arg)
49 /* Find out basename of current program */
50 pname = strrchr_m(poptGetInvocationName(con), '/');
52 pname = poptGetInvocationName(con);
57 ret = snprintf(lfile, sizeof(lfile), "%s/log.%s", arg, pname);
58 if (ret >= sizeof(lfile)) {
61 lp_set_logfile(lfile);
64 static bool PrintSambaVersionString;
66 static void popt_s3_talloc_log_fn(const char *message)
68 DEBUG(0,("%s", message));
71 static void popt_common_callback(poptContext con,
72 enum poptCallbackReason reason,
73 const struct poptOption *opt,
74 const char *arg, const void *data)
76 TALLOC_CTX *mem_ctx = talloc_new(NULL);
77 if (mem_ctx == NULL) {
81 if (reason == POPT_CALLBACK_REASON_PRE) {
82 set_logfile(con, get_dyn_LOGFILEBASE());
83 talloc_set_log_fn(popt_s3_talloc_log_fn);
84 talloc_set_abort_fn(smb_panic);
89 if (reason == POPT_CALLBACK_REASON_POST) {
91 if (PrintSambaVersionString) {
92 printf( "Version %s\n", samba_version_string());
97 if (is_default_dyn_CONFIGFILE()) {
98 if (getenv("SMB_CONF_PATH")) {
99 set_dyn_CONFIGFILE(getenv("SMB_CONF_PATH"));
103 if (override_logfile) {
104 char *logfile = lp_logfile(mem_ctx);
105 if (logfile == NULL) {
106 talloc_free(mem_ctx);
109 setup_logging(logfile, DEBUG_FILE);
112 /* Further 'every Samba program must do this' hooks here. */
113 talloc_free(mem_ctx);
120 struct loadparm_context *lp_ctx;
123 lp_ctx = loadparm_init_s3(mem_ctx, loadparm_s3_helpers());
124 if (lp_ctx == NULL) {
125 fprintf(stderr, "loadparm_init_s3() failed!\n");
126 talloc_free(mem_ctx);
130 ok = lpcfg_set_option(lp_ctx, arg);
132 fprintf(stderr, "Error setting option '%s'\n", arg);
133 talloc_free(mem_ctx);
140 lp_set_cmdline("log level", arg);
145 PrintSambaVersionString = True;
150 lp_set_cmdline("socket options", arg);
156 set_dyn_CONFIGFILE(arg);
162 lp_set_cmdline("netbios name", arg);
168 set_logfile(con, arg);
169 override_logfile = True;
170 set_dyn_LOGFILEBASE(arg);
176 lp_set_cmdline("netbios scope", arg);
182 lp_set_cmdline("workgroup", arg);
187 talloc_free(mem_ctx);
190 struct poptOption popt_common_connection[] = {
192 .argInfo = POPT_ARG_CALLBACK,
193 .arg = (void *)popt_common_callback,
196 .longName = "socket-options",
198 .argInfo = POPT_ARG_STRING,
200 .descrip = "socket options to use",
201 .argDescrip = "SOCKETOPTIONS",
204 .longName = "netbiosname",
206 .argInfo = POPT_ARG_STRING,
208 .descrip = "Primary netbios name",
209 .argDescrip = "NETBIOSNAME"
212 .longName = "workgroup",
214 .argInfo = POPT_ARG_STRING,
216 .descrip = "Set the workgroup name",
217 .argDescrip = "WORKGROUP"
222 .argInfo = POPT_ARG_STRING,
224 .descrip = "Use this Netbios scope",
225 .argDescrip = "SCOPE"
230 struct poptOption popt_common_samba[] = {
232 .argInfo = POPT_ARG_CALLBACK|POPT_CBFLAG_PRE|POPT_CBFLAG_POST,
233 .arg = (void *)popt_common_callback,
236 .longName = "debuglevel",
238 .argInfo = POPT_ARG_STRING,
240 .descrip = "Set debug level",
241 .argDescrip = "DEBUGLEVEL",
244 .longName = "configfile",
246 .argInfo = POPT_ARG_STRING,
248 .descrip = "Use alternate configuration file",
249 .argDescrip = "CONFIGFILE",
252 .longName = "log-basename",
254 .argInfo = POPT_ARG_STRING,
256 .descrip = "Base name for log files",
257 .argDescrip = "LOGFILEBASE",
260 .longName = "version",
262 .argInfo = POPT_ARG_NONE,
264 .descrip = "Print version",
267 .longName = "option",
268 .argInfo = POPT_ARG_STRING,
270 .descrip = "Set smb.conf option from command line",
271 .argDescrip = "name=value",
276 struct poptOption popt_common_configfile[] = {
278 .argInfo = POPT_ARG_CALLBACK|POPT_CBFLAG_PRE|POPT_CBFLAG_POST,
279 .arg = (void *)popt_common_callback,
282 .longName = "configfile",
283 .argInfo = POPT_ARG_STRING,
285 .descrip = "Use alternate configuration file",
286 .argDescrip = "CONFIGFILE",
291 struct poptOption popt_common_version[] = {
293 .argInfo = POPT_ARG_CALLBACK|POPT_CBFLAG_POST,
294 .arg = (void *)popt_common_callback
297 .longName = "version",
299 .argInfo = POPT_ARG_NONE,
301 .descrip = "Print version",
306 struct poptOption popt_common_debuglevel[] = {
308 .argInfo = POPT_ARG_CALLBACK,
309 .arg = (void *)popt_common_callback,
312 .longName = "debuglevel",
314 .argInfo = POPT_ARG_STRING,
316 .descrip = "Set debug level",
317 .argDescrip = "DEBUGLEVEL",
322 struct poptOption popt_common_option[] = {
324 .argInfo = POPT_ARG_CALLBACK|POPT_CBFLAG_POST,
325 .arg = (void *)popt_common_callback,
328 .longName = "option",
329 .argInfo = POPT_ARG_STRING,
331 .descrip = "Set smb.conf option from command line",
332 .argDescrip = "name=value",