2 Unix SMB/CIFS implementation.
5 Copyright (C) Tim Potter 2001,2002
6 Copyright (C) Jelmer Vernooij 2002,2003,2005
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
24 #include "lib/cmdline/popt_common.h"
25 #include "param/param.h"
27 /* Handle command line options:
39 enum {OPT_OPTION=1,OPT_LEAK_REPORT,OPT_LEAK_REPORT_FULL,OPT_DEBUG_STDERR};
41 static struct cli_credentials *cmdline_credentials = NULL;
43 void popt_set_cmdline_credentials(struct cli_credentials *creds)
45 cmdline_credentials = creds;
48 struct cli_credentials *popt_get_cmdline_credentials(void)
50 return cmdline_credentials;
53 void popt_free_cmdline_credentials(void)
55 TALLOC_FREE(cmdline_credentials);
58 struct loadparm_context *cmdline_lp_ctx = NULL;
60 static void popt_version_callback(poptContext con,
61 enum poptCallbackReason reason,
62 const struct poptOption *opt,
63 const char *arg, const void *data)
67 printf("Version %s\n", SAMBA_VERSION_STRING );
72 static void popt_s4_talloc_log_fn(const char *message)
74 DEBUG(0,("%s", message));
77 static void popt_samba_callback(poptContext con,
78 enum poptCallbackReason reason,
79 const struct poptOption *opt,
80 const char *arg, const void *data)
84 if (reason == POPT_CALLBACK_REASON_POST) {
85 if (lpcfg_configfile(cmdline_lp_ctx) == NULL) {
86 lpcfg_load_default(cmdline_lp_ctx);
88 /* Hook any 'every Samba program must do this, after
89 * the smb.conf is setup' functions here */
93 /* Find out basename of current program */
94 pname = strrchr_m(poptGetInvocationName(con),'/');
97 pname = poptGetInvocationName(con);
101 if (reason == POPT_CALLBACK_REASON_PRE) {
102 /* Hook for 'almost the first thing to do in a samba program' here */
103 /* setup for panics */
107 setup_logging(pname, DEBUG_DEFAULT_STDOUT);
108 talloc_set_log_fn(popt_s4_talloc_log_fn);
109 talloc_set_abort_fn(smb_panic);
111 cmdline_lp_ctx = loadparm_init_global(false);
117 case OPT_LEAK_REPORT:
118 talloc_enable_leak_report();
121 case OPT_LEAK_REPORT_FULL:
122 talloc_enable_leak_report_full();
126 if (!lpcfg_set_option(cmdline_lp_ctx, arg)) {
127 fprintf(stderr, "Error setting option '%s'\n", arg);
133 lpcfg_set_cmdline(cmdline_lp_ctx, "log level", arg);
136 case OPT_DEBUG_STDERR:
137 setup_logging(pname, DEBUG_STDERR);
142 lpcfg_load(cmdline_lp_ctx, arg);
148 char *new_logfile = talloc_asprintf(NULL, "%s/log.%s", arg, pname);
149 lpcfg_set_cmdline(cmdline_lp_ctx, "log file", new_logfile);
150 talloc_free(new_logfile);
160 static void popt_common_callback(poptContext con,
161 enum poptCallbackReason reason,
162 const struct poptOption *opt,
163 const char *arg, const void *data)
165 struct loadparm_context *lp_ctx = cmdline_lp_ctx;
170 lpcfg_set_cmdline(lp_ctx, "socket options", arg);
175 lpcfg_set_cmdline(lp_ctx, "workgroup", arg);
179 lpcfg_set_cmdline(lp_ctx, "realm", arg);
183 lpcfg_set_cmdline(lp_ctx, "netbios name", arg);
187 lpcfg_set_cmdline(lp_ctx, "netbios scope", arg);
191 lpcfg_set_cmdline(lp_ctx, "client max protocol", arg);
195 lpcfg_set_cmdline(lp_ctx, "name resolve order", arg);
199 lpcfg_set_cmdline(lp_ctx, "client signing", arg);
205 struct poptOption popt_common_connection4[] = {
207 .argInfo = POPT_ARG_CALLBACK,
208 .arg = (void *)popt_common_callback,
211 .longName = "name-resolve",
213 .argInfo = POPT_ARG_STRING,
215 .descrip = "Use these name resolution services only",
216 .argDescrip = "NAME-RESOLVE-ORDER",
219 .longName = "socket-options",
221 .argInfo = POPT_ARG_STRING,
223 .descrip = "socket options to use",
224 .argDescrip = "SOCKETOPTIONS",
227 .longName = "netbiosname",
229 .argInfo = POPT_ARG_STRING,
231 .descrip = "Primary netbios name",
232 .argDescrip = "NETBIOSNAME",
235 .longName = "signing",
237 .argInfo = POPT_ARG_STRING,
239 .descrip = "Set the client signing state",
240 .argDescrip = "on|off|required",
243 .longName = "workgroup",
245 .argInfo = POPT_ARG_STRING,
247 .descrip = "Set the workgroup name",
248 .argDescrip = "WORKGROUP",
252 .argInfo = POPT_ARG_STRING,
254 .descrip = "Set the realm name",
255 .argDescrip = "REALM",
260 .argInfo = POPT_ARG_STRING,
262 .descrip = "Use this Netbios scope",
263 .argDescrip = "SCOPE",
266 .longName = "maxprotocol",
268 .argInfo = POPT_ARG_STRING,
270 .descrip = "Set max protocol level",
271 .argDescrip = "MAXPROTOCOL",
276 struct poptOption popt_common_samba4[] = {
278 .argInfo = POPT_ARG_CALLBACK|POPT_CBFLAG_PRE|POPT_CBFLAG_POST,
279 .arg = (void *)popt_samba_callback,
282 .longName = "debuglevel",
284 .argInfo = POPT_ARG_STRING,
286 .descrip = "Set debug level",
287 .argDescrip = "DEBUGLEVEL",
290 .longName = "debug-stderr",
291 .argInfo = POPT_ARG_NONE,
292 .val = OPT_DEBUG_STDERR,
293 .descrip = "Send debug output to STDERR",
296 .longName = "configfile",
298 .argInfo = POPT_ARG_STRING,
300 .descrip = "Use alternative configuration file",
301 .argDescrip = "CONFIGFILE",
304 .longName = "option",
305 .argInfo = POPT_ARG_STRING,
307 .descrip = "Set smb.conf option from command line",
308 .argDescrip = "name=value",
311 .longName = "log-basename",
313 .argInfo = POPT_ARG_STRING,
315 .descrip = "Basename for log/debug files",
316 .argDescrip = "LOGFILEBASE",
319 .longName = "leak-report",
320 .argInfo = POPT_ARG_NONE,
321 .val = OPT_LEAK_REPORT,
322 .descrip = "enable talloc leak reporting on exit",
325 .longName = "leak-report-full",
326 .argInfo = POPT_ARG_NONE,
327 .val = OPT_LEAK_REPORT_FULL,
328 .descrip = "enable full talloc leak reporting on exit",
333 struct poptOption popt_common_version4[] = {
335 .argInfo = POPT_ARG_CALLBACK,
336 .arg = (void *)popt_version_callback,
339 .longName = "version",
341 .argInfo = POPT_ARG_NONE,
343 .descrip = "Print version",