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 const struct loadparm_substitution
*lp_sub
=
105 loadparm_s3_global_substitution();
106 char *logfile
= lp_logfile(mem_ctx
, lp_sub
);
107 if (logfile
== NULL
) {
108 talloc_free(mem_ctx
);
111 setup_logging(logfile
, DEBUG_FILE
);
114 /* Further 'every Samba program must do this' hooks here. */
115 talloc_free(mem_ctx
);
122 struct loadparm_context
*lp_ctx
;
125 lp_ctx
= loadparm_init_s3(mem_ctx
, loadparm_s3_helpers());
126 if (lp_ctx
== NULL
) {
127 fprintf(stderr
, "loadparm_init_s3() failed!\n");
128 talloc_free(mem_ctx
);
132 ok
= lpcfg_set_option(lp_ctx
, arg
);
134 fprintf(stderr
, "Error setting option '%s'\n", arg
);
135 talloc_free(mem_ctx
);
142 lp_set_cmdline("log level", arg
);
147 PrintSambaVersionString
= True
;
152 lp_set_cmdline("socket options", arg
);
158 set_dyn_CONFIGFILE(arg
);
164 lp_set_cmdline("netbios name", arg
);
170 set_logfile(con
, arg
);
171 override_logfile
= True
;
172 set_dyn_LOGFILEBASE(arg
);
178 lp_set_cmdline("netbios scope", arg
);
184 lp_set_cmdline("workgroup", arg
);
189 talloc_free(mem_ctx
);
192 struct poptOption popt_common_connection
[] = {
194 .argInfo
= POPT_ARG_CALLBACK
,
195 .arg
= (void *)popt_common_callback
,
198 .longName
= "socket-options",
200 .argInfo
= POPT_ARG_STRING
,
202 .descrip
= "socket options to use",
203 .argDescrip
= "SOCKETOPTIONS",
206 .longName
= "netbiosname",
208 .argInfo
= POPT_ARG_STRING
,
210 .descrip
= "Primary netbios name",
211 .argDescrip
= "NETBIOSNAME"
214 .longName
= "workgroup",
216 .argInfo
= POPT_ARG_STRING
,
218 .descrip
= "Set the workgroup name",
219 .argDescrip
= "WORKGROUP"
224 .argInfo
= POPT_ARG_STRING
,
226 .descrip
= "Use this Netbios scope",
227 .argDescrip
= "SCOPE"
232 struct poptOption popt_common_samba
[] = {
234 .argInfo
= POPT_ARG_CALLBACK
|POPT_CBFLAG_PRE
|POPT_CBFLAG_POST
,
235 .arg
= (void *)popt_common_callback
,
238 .longName
= "debuglevel",
240 .argInfo
= POPT_ARG_STRING
,
242 .descrip
= "Set debug level",
243 .argDescrip
= "DEBUGLEVEL",
246 .longName
= "configfile",
248 .argInfo
= POPT_ARG_STRING
,
250 .descrip
= "Use alternate configuration file",
251 .argDescrip
= "CONFIGFILE",
254 .longName
= "log-basename",
256 .argInfo
= POPT_ARG_STRING
,
258 .descrip
= "Base name for log files",
259 .argDescrip
= "LOGFILEBASE",
262 .longName
= "version",
264 .argInfo
= POPT_ARG_NONE
,
266 .descrip
= "Print version",
269 .longName
= "option",
270 .argInfo
= POPT_ARG_STRING
,
272 .descrip
= "Set smb.conf option from command line",
273 .argDescrip
= "name=value",
278 struct poptOption popt_common_configfile
[] = {
280 .argInfo
= POPT_ARG_CALLBACK
|POPT_CBFLAG_PRE
|POPT_CBFLAG_POST
,
281 .arg
= (void *)popt_common_callback
,
284 .longName
= "configfile",
285 .argInfo
= POPT_ARG_STRING
,
287 .descrip
= "Use alternate configuration file",
288 .argDescrip
= "CONFIGFILE",
293 struct poptOption popt_common_version
[] = {
295 .argInfo
= POPT_ARG_CALLBACK
|POPT_CBFLAG_POST
,
296 .arg
= (void *)popt_common_callback
299 .longName
= "version",
301 .argInfo
= POPT_ARG_NONE
,
303 .descrip
= "Print version",
308 struct poptOption popt_common_debuglevel
[] = {
310 .argInfo
= POPT_ARG_CALLBACK
,
311 .arg
= (void *)popt_common_callback
,
314 .longName
= "debuglevel",
316 .argInfo
= POPT_ARG_STRING
,
318 .descrip
= "Set debug level",
319 .argDescrip
= "DEBUGLEVEL",
324 struct poptOption popt_common_option
[] = {
326 .argInfo
= POPT_ARG_CALLBACK
|POPT_CBFLAG_POST
,
327 .arg
= (void *)popt_common_callback
,
330 .longName
= "option",
331 .argInfo
= POPT_ARG_STRING
,
333 .descrip
= "Set smb.conf option from command line",
334 .argDescrip
= "name=value",