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
)
48 /* Find out basename of current program */
49 pname
= strrchr_m(poptGetInvocationName(con
),'/');
52 pname
= poptGetInvocationName(con
);
56 if (asprintf(&lfile
, "%s/log.%s", arg
, pname
) < 0) {
59 lp_set_logfile(lfile
);
63 static bool PrintSambaVersionString
;
65 static void popt_s3_talloc_log_fn(const char *message
)
67 DEBUG(0,("%s", message
));
70 static void popt_common_callback(poptContext con
,
71 enum poptCallbackReason reason
,
72 const struct poptOption
*opt
,
73 const char *arg
, const void *data
)
76 if (reason
== POPT_CALLBACK_REASON_PRE
) {
77 set_logfile(con
, get_dyn_LOGFILEBASE());
78 talloc_set_log_fn(popt_s3_talloc_log_fn
);
79 talloc_set_abort_fn(smb_panic
);
83 if (reason
== POPT_CALLBACK_REASON_POST
) {
85 if (PrintSambaVersionString
) {
86 printf( "Version %s\n", samba_version_string());
90 if (is_default_dyn_CONFIGFILE()) {
91 if(getenv("SMB_CONF_PATH")) {
92 set_dyn_CONFIGFILE(getenv("SMB_CONF_PATH"));
96 if (override_logfile
) {
97 setup_logging(lp_logfile(talloc_tos()), DEBUG_FILE
);
100 /* Further 'every Samba program must do this' hooks here. */
107 struct loadparm_context
*lp_ctx
;
109 lp_ctx
= loadparm_init_s3(talloc_tos(), loadparm_s3_helpers());
110 if (lp_ctx
== NULL
) {
111 fprintf(stderr
, "loadparm_init_s3() failed!\n");
115 if (!lpcfg_set_option(lp_ctx
, arg
)) {
116 fprintf(stderr
, "Error setting option '%s'\n", arg
);
124 lp_set_cmdline("log level", arg
);
129 PrintSambaVersionString
= True
;
134 lp_set_cmdline("socket options", arg
);
140 set_dyn_CONFIGFILE(arg
);
146 lp_set_cmdline("netbios name", arg
);
152 set_logfile(con
, arg
);
153 override_logfile
= True
;
154 set_dyn_LOGFILEBASE(arg
);
160 lp_set_cmdline("netbios scope", arg
);
166 lp_set_cmdline("workgroup", arg
);
172 struct poptOption popt_common_connection
[] = {
173 { NULL
, 0, POPT_ARG_CALLBACK
, (void *)popt_common_callback
},
174 { "socket-options", 'O', POPT_ARG_STRING
, NULL
, 'O', "socket options to use",
176 { "netbiosname", 'n', POPT_ARG_STRING
, NULL
, 'n', "Primary netbios name", "NETBIOSNAME" },
177 { "workgroup", 'W', POPT_ARG_STRING
, NULL
, 'W', "Set the workgroup name", "WORKGROUP" },
178 { "scope", 'i', POPT_ARG_STRING
, NULL
, 'i', "Use this Netbios scope", "SCOPE" },
183 struct poptOption popt_common_samba
[] = {
184 { NULL
, 0, POPT_ARG_CALLBACK
|POPT_CBFLAG_PRE
|POPT_CBFLAG_POST
, (void *)popt_common_callback
},
185 { "debuglevel", 'd', POPT_ARG_STRING
, NULL
, 'd', "Set debug level", "DEBUGLEVEL" },
186 { "configfile", 's', POPT_ARG_STRING
, NULL
, 's', "Use alternate configuration file", "CONFIGFILE" },
187 { "log-basename", 'l', POPT_ARG_STRING
, NULL
, 'l', "Base name for log files", "LOGFILEBASE" },
188 { "version", 'V', POPT_ARG_NONE
, NULL
, 'V', "Print version" },
189 { "option", 0, POPT_ARG_STRING
, NULL
, OPT_OPTION
, "Set smb.conf option from command line", "name=value" },
193 struct poptOption popt_common_configfile
[] = {
194 { NULL
, 0, POPT_ARG_CALLBACK
|POPT_CBFLAG_PRE
|POPT_CBFLAG_POST
, (void *)popt_common_callback
},
195 { "configfile", 0, POPT_ARG_STRING
, NULL
, 's', "Use alternate configuration file", "CONFIGFILE" },
199 struct poptOption popt_common_version
[] = {
200 { NULL
, 0, POPT_ARG_CALLBACK
|POPT_CBFLAG_POST
, (void *)popt_common_callback
},
201 { "version", 'V', POPT_ARG_NONE
, NULL
, 'V', "Print version" },
205 struct poptOption popt_common_debuglevel
[] = {
206 { NULL
, 0, POPT_ARG_CALLBACK
, (void *)popt_common_callback
},
207 { "debuglevel", 'd', POPT_ARG_STRING
, NULL
, 'd', "Set debug level", "DEBUGLEVEL" },
211 struct poptOption popt_common_option
[] = {
212 { NULL
, 0, POPT_ARG_CALLBACK
|POPT_CBFLAG_POST
, (void *)popt_common_callback
},
213 { "option", 0, POPT_ARG_STRING
, NULL
, OPT_OPTION
, "Set smb.conf option from command line", "name=value" },