s3:smbd: rename has_ctdb_public_ip to has_cluster_movable_ip
[Samba.git] / source3 / lib / popt_common.c
blobd5b60c69ef7f9691627065edf1e6965ae60a2850
1 /*
2 Unix SMB/CIFS implementation.
3 Common popt routines
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/>.
23 #include "includes.h"
24 #include "popt_common.h"
25 #include "lib/param/param.h"
27 /* Handle command line options:
28 * -d,--debuglevel
29 * -s,--configfile
30 * -O,--socket-options
31 * -V,--version
32 * -l,--log-base
33 * -n,--netbios-name
34 * -W,--workgroup
35 * -i,--scope
38 enum {OPT_OPTION=1};
40 extern bool override_logfile;
42 static void set_logfile(poptContext con, const char * arg)
45 char lfile[PATH_MAX];
46 const char *pname;
47 int ret;
49 /* Find out basename of current program */
50 pname = strrchr_m(poptGetInvocationName(con), '/');
51 if (pname == NULL) {
52 pname = poptGetInvocationName(con);
53 } else {
54 pname++;
57 ret = snprintf(lfile, sizeof(lfile), "%s/log.%s", arg, pname);
58 if (ret >= sizeof(lfile)) {
59 return;
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) {
78 exit(1);
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);
85 talloc_free(mem_ctx);
86 return;
89 if (reason == POPT_CALLBACK_REASON_POST) {
91 if (PrintSambaVersionString) {
92 printf( "Version %s\n", samba_version_string());
93 talloc_free(mem_ctx);
94 exit(0);
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);
109 exit(1);
111 setup_logging(logfile, DEBUG_FILE);
114 /* Further 'every Samba program must do this' hooks here. */
115 talloc_free(mem_ctx);
116 return;
119 switch(opt->val) {
120 case OPT_OPTION:
122 struct loadparm_context *lp_ctx;
123 bool ok;
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);
129 exit(1);
132 ok = lpcfg_set_option(lp_ctx, arg);
133 if (!ok) {
134 fprintf(stderr, "Error setting option '%s'\n", arg);
135 talloc_free(mem_ctx);
136 exit(1);
138 break;
140 case 'd':
141 if (arg) {
142 lp_set_cmdline("log level", arg);
144 break;
146 case 'V':
147 PrintSambaVersionString = True;
148 break;
150 case 'O':
151 if (arg) {
152 lp_set_cmdline("socket options", arg);
154 break;
156 case 's':
157 if (arg) {
158 set_dyn_CONFIGFILE(arg);
160 break;
162 case 'n':
163 if (arg) {
164 lp_set_cmdline("netbios name", arg);
166 break;
168 case 'l':
169 if (arg) {
170 set_logfile(con, arg);
171 override_logfile = True;
172 set_dyn_LOGFILEBASE(arg);
174 break;
176 case 'i':
177 if (arg) {
178 lp_set_cmdline("netbios scope", arg);
180 break;
182 case 'W':
183 if (arg) {
184 lp_set_cmdline("workgroup", arg);
186 break;
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",
199 .shortName = 'O',
200 .argInfo = POPT_ARG_STRING,
201 .val = 'O',
202 .descrip = "socket options to use",
203 .argDescrip = "SOCKETOPTIONS",
206 .longName = "netbiosname",
207 .shortName = 'n',
208 .argInfo = POPT_ARG_STRING,
209 .val = 'n',
210 .descrip = "Primary netbios name",
211 .argDescrip = "NETBIOSNAME"
214 .longName = "workgroup",
215 .shortName = 'W',
216 .argInfo = POPT_ARG_STRING,
217 .val = 'W',
218 .descrip = "Set the workgroup name",
219 .argDescrip = "WORKGROUP"
222 .longName = "scope",
223 .shortName = 'i',
224 .argInfo = POPT_ARG_STRING,
225 .val = 'i',
226 .descrip = "Use this Netbios scope",
227 .argDescrip = "SCOPE"
229 POPT_TABLEEND
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",
239 .shortName = 'd',
240 .argInfo = POPT_ARG_STRING,
241 .val = 'd',
242 .descrip = "Set debug level",
243 .argDescrip = "DEBUGLEVEL",
246 .longName = "configfile",
247 .shortName = 's',
248 .argInfo = POPT_ARG_STRING,
249 .val = 's',
250 .descrip = "Use alternate configuration file",
251 .argDescrip = "CONFIGFILE",
254 .longName = "log-basename",
255 .shortName = 'l',
256 .argInfo = POPT_ARG_STRING,
257 .val = 'l',
258 .descrip = "Base name for log files",
259 .argDescrip = "LOGFILEBASE",
262 .longName = "version",
263 .shortName = 'V',
264 .argInfo = POPT_ARG_NONE,
265 .val = 'V',
266 .descrip = "Print version",
269 .longName = "option",
270 .argInfo = POPT_ARG_STRING,
271 .val = OPT_OPTION,
272 .descrip = "Set smb.conf option from command line",
273 .argDescrip = "name=value",
275 POPT_TABLEEND
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,
286 .val = 's',
287 .descrip = "Use alternate configuration file",
288 .argDescrip = "CONFIGFILE",
290 POPT_TABLEEND
293 struct poptOption popt_common_version[] = {
295 .argInfo = POPT_ARG_CALLBACK|POPT_CBFLAG_POST,
296 .arg = (void *)popt_common_callback
299 .longName = "version",
300 .shortName = 'V',
301 .argInfo = POPT_ARG_NONE,
302 .val = 'V',
303 .descrip = "Print version",
305 POPT_TABLEEND
308 struct poptOption popt_common_debuglevel[] = {
310 .argInfo = POPT_ARG_CALLBACK,
311 .arg = (void *)popt_common_callback,
314 .longName = "debuglevel",
315 .shortName = 'd',
316 .argInfo = POPT_ARG_STRING,
317 .val = 'd',
318 .descrip = "Set debug level",
319 .argDescrip = "DEBUGLEVEL",
321 POPT_TABLEEND
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,
332 .val = OPT_OPTION,
333 .descrip = "Set smb.conf option from command line",
334 .argDescrip = "name=value",
336 POPT_TABLEEND