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 2 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, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 #include "system/filesys.h"
26 #include "system/passwd.h"
27 #include "lib/cmdline/popt_common.h"
29 /* Handle command line options:
40 enum {OPT_OPTION=1,OPT_LEAK_REPORT,OPT_LEAK_REPORT_FULL, OPT_DEBUG_STDERR};
42 struct cli_credentials *cmdline_credentials = NULL;
44 static void popt_common_callback(poptContext con,
45 enum poptCallbackReason reason,
46 const struct poptOption *opt,
47 const char *arg, const void *data)
51 if (reason == POPT_CALLBACK_REASON_POST) {
52 /* Hook any 'every Samba program must do this, after
53 * the smb.conf is setup' functions here */
59 /* Find out basename of current program */
60 pname = strrchr_m(poptGetInvocationName(con),'/');
63 pname = poptGetInvocationName(con);
67 if (reason == POPT_CALLBACK_REASON_PRE) {
68 /* setup for panics */
69 fault_setup(poptGetInvocationName(con));
72 setup_logging(pname, DEBUG_STDOUT);
78 lp_set_cmdline("log level", arg);
81 case OPT_DEBUG_STDERR:
82 setup_logging(pname, DEBUG_STDERR);
86 printf( "Version %s\n", SAMBA_VERSION_STRING );
92 lp_set_cmdline("socket options", arg);
98 lp_set_cmdline("config file", arg);
104 char *logfile = talloc_asprintf(NULL, "%s/log.%s", arg, pname);
105 lp_set_cmdline("log file", logfile);
106 talloc_free(logfile);
111 lp_set_cmdline("workgroup", arg);
115 lp_set_cmdline("netbios name", arg);
119 lp_set_cmdline("netbios scope", arg);
123 lp_set_cmdline("max protocol", arg);
127 lp_set_cmdline("name resolve order", arg);
131 if (!lp_set_option(arg)) {
132 fprintf(stderr, "Error setting option '%s'\n", arg);
137 case OPT_LEAK_REPORT:
138 talloc_enable_leak_report();
141 case OPT_LEAK_REPORT_FULL:
142 talloc_enable_leak_report_full();
148 struct poptOption popt_common_connection[] = {
149 { NULL, 0, POPT_ARG_CALLBACK, popt_common_callback },
150 { "name-resolve", 'R', POPT_ARG_STRING, NULL, 'R', "Use these name resolution services only", "NAME-RESOLVE-ORDER" },
151 { "socket-options", 'O', POPT_ARG_STRING, NULL, 'O', "socket options to use", "SOCKETOPTIONS" },
152 { "netbiosname", 'n', POPT_ARG_STRING, NULL, 'n', "Primary netbios name", "NETBIOSNAME" },
153 { "workgroup", 'W', POPT_ARG_STRING, NULL, 'W', "Set the workgroup name", "WORKGROUP" },
154 { "scope", 'i', POPT_ARG_STRING, NULL, 'i', "Use this Netbios scope", "SCOPE" },
155 { "maxprotocol", 'm', POPT_ARG_STRING, NULL, 'm', "Set max protocol level", "MAXPROTOCOL" },
159 struct poptOption popt_common_samba[] = {
160 { NULL, 0, POPT_ARG_CALLBACK|POPT_CBFLAG_PRE|POPT_CBFLAG_POST, popt_common_callback },
161 { "debuglevel", 'd', POPT_ARG_STRING, NULL, 'd', "Set debug level", "DEBUGLEVEL" },
162 { "debug-stderr", 0, POPT_ARG_NONE, NULL, OPT_DEBUG_STDERR, "Send debug output to STDERR", NULL },
163 { "configfile", 's', POPT_ARG_STRING, NULL, 's', "Use alternative configuration file", "CONFIGFILE" },
164 { "option", 0, POPT_ARG_STRING, NULL, OPT_OPTION, "Set smb.conf option from command line", "name=value" },
165 { "log-basename", 'l', POPT_ARG_STRING, NULL, 'l', "Basename for log/debug files", "LOGFILEBASE" },
166 { "leak-report", 0, POPT_ARG_NONE, NULL, OPT_LEAK_REPORT, "enable talloc leak reporting on exit", NULL },
167 { "leak-report-full",0, POPT_ARG_NONE, NULL, OPT_LEAK_REPORT_FULL, "enable full talloc leak reporting on exit", NULL },
171 struct poptOption popt_common_version[] = {
172 { NULL, 0, POPT_ARG_CALLBACK, popt_common_callback },
173 { "version", 'V', POPT_ARG_NONE, NULL, 'V', "Print version" },
177 /* Handle command line options:
179 * -A,--authentication-file
187 static BOOL dont_ask;
190 disable asking for a password
192 void popt_common_dont_ask(void)
197 static void popt_common_credentials_callback(poptContext con,
198 enum poptCallbackReason reason,
199 const struct poptOption *opt,
200 const char *arg, const void *data)
202 if (reason == POPT_CALLBACK_REASON_PRE) {
203 cmdline_credentials = cli_credentials_init(talloc_autofree_context());
207 if (reason == POPT_CALLBACK_REASON_POST) {
208 cli_credentials_guess(cmdline_credentials);
211 cli_credentials_set_cmdline_callbacks(cmdline_credentials);
221 cli_credentials_parse_string(cmdline_credentials, arg, CRED_SPECIFIED);
222 /* This breaks the abstraction, including the const above */
223 if ((lp=strchr_m(arg,'%'))) {
226 memset(lp,0,strlen(lp));
232 cli_credentials_parse_file(cmdline_credentials, arg, CRED_SPECIFIED);
236 lp_set_cmdline("client signing", arg);
240 /* Later, after this is all over, get the machine account details from the secrets.ldb */
241 cli_credentials_set_machine_account_pending(cmdline_credentials);
243 /* machine accounts only work with kerberos (fall though)*/
250 struct poptOption popt_common_credentials[] = {
251 { NULL, 0, POPT_ARG_CALLBACK|POPT_CBFLAG_PRE|POPT_CBFLAG_POST, popt_common_credentials_callback },
252 { "user", 'U', POPT_ARG_STRING, NULL, 'U', "Set the network username", "[DOMAIN\\]USERNAME[%PASSWORD]" },
253 { "no-pass", 'N', POPT_ARG_NONE, &dont_ask, True, "Don't ask for a password" },
254 { "authentication-file", 'A', POPT_ARG_STRING, NULL, 'A', "Get the credentials from a file", "FILE" },
255 { "signing", 'S', POPT_ARG_STRING, NULL, 'S', "Set the client signing state", "on|off|required" },
256 { "machine-pass", 'P', POPT_ARG_NONE, NULL, 'P', "Use stored machine account password (implies -k)" },