1 | /*
|
---|
2 | Unix SMB/CIFS implementation.
|
---|
3 | Parameter loading functions
|
---|
4 | Copyright (C) Karl Auer 1993-1998
|
---|
5 |
|
---|
6 | Largely re-written by Andrew Tridgell, September 1994
|
---|
7 |
|
---|
8 | Copyright (C) Simo Sorce 2001
|
---|
9 | Copyright (C) Alexander Bokovoy 2002
|
---|
10 | Copyright (C) Stefan (metze) Metzmacher 2002
|
---|
11 | Copyright (C) Jim McDonough (jmcd@us.ibm.com) 2003.
|
---|
12 | Copyright (C) James Myers 2003 <myersjj@samba.org>
|
---|
13 | Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2007
|
---|
14 | Copyright (C) Andrew Bartlett 2011-2012
|
---|
15 |
|
---|
16 | This program is free software; you can redistribute it and/or modify
|
---|
17 | it under the terms of the GNU General Public License as published by
|
---|
18 | the Free Software Foundation; either version 3 of the License, or
|
---|
19 | (at your option) any later version.
|
---|
20 |
|
---|
21 | This program is distributed in the hope that it will be useful,
|
---|
22 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
23 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
24 | GNU General Public License for more details.
|
---|
25 |
|
---|
26 | You should have received a copy of the GNU General Public License
|
---|
27 | along with this program. If not, see <http://www.gnu.org/licenses/>.
|
---|
28 | */
|
---|
29 |
|
---|
30 | /*
|
---|
31 | * Load parameters.
|
---|
32 | *
|
---|
33 | * This module provides suitable callback functions for the params
|
---|
34 | * module. It builds the internal table of service details which is
|
---|
35 | * then used by the rest of the server.
|
---|
36 | *
|
---|
37 | * To add a parameter:
|
---|
38 | *
|
---|
39 | * 1) add it to the global or service structure definition
|
---|
40 | * 2) add it to the parm_table
|
---|
41 | * 3) add it to the list of available functions (eg: using FN_GLOBAL_STRING())
|
---|
42 | * 4) If it's a global then initialise it in init_globals. If a local
|
---|
43 | * (ie. service) parameter then initialise it in the sDefault structure
|
---|
44 | *
|
---|
45 | *
|
---|
46 | * Notes:
|
---|
47 | * The configuration file is processed sequentially for speed. It is NOT
|
---|
48 | * accessed randomly as happens in 'real' Windows. For this reason, there
|
---|
49 | * is a fair bit of sequence-dependent code here - ie., code which assumes
|
---|
50 | * that certain things happen before others. In particular, the code which
|
---|
51 | * happens at the boundary between sections is delicately poised, so be
|
---|
52 | * careful!
|
---|
53 | *
|
---|
54 | */
|
---|
55 |
|
---|
56 | #include "includes.h"
|
---|
57 | #include "version.h"
|
---|
58 | #include "dynconfig/dynconfig.h"
|
---|
59 | #include "system/time.h"
|
---|
60 | #include "system/locale.h"
|
---|
61 | #include "system/network.h" /* needed for TCP_NODELAY */
|
---|
62 | #include "../lib/util/dlinklist.h"
|
---|
63 | #include "lib/param/param.h"
|
---|
64 | #include "lib/param/loadparm.h"
|
---|
65 | #include "auth/gensec/gensec.h"
|
---|
66 | #include "lib/param/s3_param.h"
|
---|
67 | #include "lib/util/bitmap.h"
|
---|
68 | #include "libcli/smb/smb_constants.h"
|
---|
69 | #include "tdb.h"
|
---|
70 | #include "librpc/gen_ndr/nbt.h"
|
---|
71 | #include "libds/common/roles.h"
|
---|
72 |
|
---|
73 | #ifdef HAVE_HTTPCONNECTENCRYPT
|
---|
74 | #include <cups/http.h>
|
---|
75 | #endif
|
---|
76 |
|
---|
77 | #define standard_sub_basic talloc_strdup
|
---|
78 |
|
---|
79 | #include "lib/param/param_global.h"
|
---|
80 |
|
---|
81 | struct loadparm_service *lpcfg_default_service(struct loadparm_context *lp_ctx)
|
---|
82 | {
|
---|
83 | return lp_ctx->sDefault;
|
---|
84 | }
|
---|
85 |
|
---|
86 | /**
|
---|
87 | * Convenience routine to grab string parameters into temporary memory
|
---|
88 | * and run standard_sub_basic on them.
|
---|
89 | *
|
---|
90 | * The buffers can be written to by
|
---|
91 | * callers without affecting the source string.
|
---|
92 | */
|
---|
93 |
|
---|
94 | static const char *lpcfg_string(const char *s)
|
---|
95 | {
|
---|
96 | #if 0 /* until REWRITE done to make thread-safe */
|
---|
97 | size_t len = s ? strlen(s) : 0;
|
---|
98 | char *ret;
|
---|
99 | #endif
|
---|
100 |
|
---|
101 | /* The follow debug is useful for tracking down memory problems
|
---|
102 | especially if you have an inner loop that is calling a lp_*()
|
---|
103 | function that returns a string. Perhaps this debug should be
|
---|
104 | present all the time? */
|
---|
105 |
|
---|
106 | #if 0
|
---|
107 | DEBUG(10, ("lpcfg_string(%s)\n", s));
|
---|
108 | #endif
|
---|
109 |
|
---|
110 | #if 0 /* until REWRITE done to make thread-safe */
|
---|
111 | if (!lp_talloc)
|
---|
112 | lp_talloc = talloc_init("lp_talloc");
|
---|
113 |
|
---|
114 | ret = talloc_array(lp_talloc, char, len + 100); /* leave room for substitution */
|
---|
115 |
|
---|
116 | if (!ret)
|
---|
117 | return NULL;
|
---|
118 |
|
---|
119 | if (!s)
|
---|
120 | *ret = 0;
|
---|
121 | else
|
---|
122 | strlcpy(ret, s, len);
|
---|
123 |
|
---|
124 | if (trim_string(ret, "\"", "\"")) {
|
---|
125 | if (strchr(ret,'"') != NULL)
|
---|
126 | strlcpy(ret, s, len);
|
---|
127 | }
|
---|
128 |
|
---|
129 | standard_sub_basic(ret,len+100);
|
---|
130 | return (ret);
|
---|
131 | #endif
|
---|
132 | return s;
|
---|
133 | }
|
---|
134 |
|
---|
135 | /*
|
---|
136 | In this section all the functions that are used to access the
|
---|
137 | parameters from the rest of the program are defined
|
---|
138 | */
|
---|
139 |
|
---|
140 | /*
|
---|
141 | * the creation of separate lpcfg_*() and lp_*() functions is to allow
|
---|
142 | * for code compatibility between existing Samba4 and Samba3 code.
|
---|
143 | */
|
---|
144 |
|
---|
145 | /* this global context supports the lp_*() function varients */
|
---|
146 | static struct loadparm_context *global_loadparm_context;
|
---|
147 |
|
---|
148 | #define FN_GLOBAL_STRING(fn_name,var_name) \
|
---|
149 | _PUBLIC_ char *lpcfg_ ## fn_name(struct loadparm_context *lp_ctx, TALLOC_CTX *ctx) {\
|
---|
150 | if (lp_ctx == NULL) return NULL; \
|
---|
151 | if (lp_ctx->s3_fns) { \
|
---|
152 | return lp_ctx->globals->var_name ? lp_ctx->s3_fns->lp_string(ctx, lp_ctx->globals->var_name) : talloc_strdup(ctx, ""); \
|
---|
153 | } \
|
---|
154 | return lp_ctx->globals->var_name ? talloc_strdup(ctx, lpcfg_string(lp_ctx->globals->var_name)) : talloc_strdup(ctx, ""); \
|
---|
155 | }
|
---|
156 |
|
---|
157 | #define FN_GLOBAL_CONST_STRING(fn_name,var_name) \
|
---|
158 | _PUBLIC_ const char *lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) { \
|
---|
159 | if (lp_ctx == NULL) return NULL; \
|
---|
160 | return lp_ctx->globals->var_name ? lpcfg_string(lp_ctx->globals->var_name) : ""; \
|
---|
161 | }
|
---|
162 |
|
---|
163 | #define FN_GLOBAL_LIST(fn_name,var_name) \
|
---|
164 | _PUBLIC_ const char **lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) { \
|
---|
165 | if (lp_ctx == NULL) return NULL; \
|
---|
166 | return lp_ctx->globals->var_name; \
|
---|
167 | }
|
---|
168 |
|
---|
169 | #define FN_GLOBAL_BOOL(fn_name,var_name) \
|
---|
170 | _PUBLIC_ bool lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) {\
|
---|
171 | if (lp_ctx == NULL) return false; \
|
---|
172 | return lp_ctx->globals->var_name; \
|
---|
173 | }
|
---|
174 |
|
---|
175 | #define FN_GLOBAL_INTEGER(fn_name,var_name) \
|
---|
176 | _PUBLIC_ int lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) { \
|
---|
177 | return lp_ctx->globals->var_name; \
|
---|
178 | }
|
---|
179 |
|
---|
180 | /* Local parameters don't need the ->s3_fns because the struct
|
---|
181 | * loadparm_service is shared and lpcfg_service() checks the ->s3_fns
|
---|
182 | * hook */
|
---|
183 | #define FN_LOCAL_STRING(fn_name,val) \
|
---|
184 | _PUBLIC_ char *lpcfg_ ## fn_name(struct loadparm_service *service, \
|
---|
185 | struct loadparm_service *sDefault, TALLOC_CTX *ctx) { \
|
---|
186 | return(talloc_strdup(ctx, lpcfg_string((const char *)((service != NULL && service->val != NULL) ? service->val : sDefault->val)))); \
|
---|
187 | }
|
---|
188 |
|
---|
189 | #define FN_LOCAL_CONST_STRING(fn_name,val) \
|
---|
190 | _PUBLIC_ const char *lpcfg_ ## fn_name(struct loadparm_service *service, \
|
---|
191 | struct loadparm_service *sDefault) { \
|
---|
192 | return((const char *)((service != NULL && service->val != NULL) ? service->val : sDefault->val)); \
|
---|
193 | }
|
---|
194 |
|
---|
195 | #define FN_LOCAL_LIST(fn_name,val) \
|
---|
196 | _PUBLIC_ const char **lpcfg_ ## fn_name(struct loadparm_service *service, \
|
---|
197 | struct loadparm_service *sDefault) {\
|
---|
198 | return(const char **)(service != NULL && service->val != NULL? service->val : sDefault->val); \
|
---|
199 | }
|
---|
200 |
|
---|
201 | #define FN_LOCAL_PARM_BOOL(fn_name, val) FN_LOCAL_BOOL(fn_name, val)
|
---|
202 |
|
---|
203 | #define FN_LOCAL_BOOL(fn_name,val) \
|
---|
204 | _PUBLIC_ bool lpcfg_ ## fn_name(struct loadparm_service *service, \
|
---|
205 | struct loadparm_service *sDefault) { \
|
---|
206 | return((service != NULL)? service->val : sDefault->val); \
|
---|
207 | }
|
---|
208 |
|
---|
209 | #define FN_LOCAL_INTEGER(fn_name,val) \
|
---|
210 | _PUBLIC_ int lpcfg_ ## fn_name(struct loadparm_service *service, \
|
---|
211 | struct loadparm_service *sDefault) { \
|
---|
212 | return((service != NULL)? service->val : sDefault->val); \
|
---|
213 | }
|
---|
214 |
|
---|
215 | #define FN_LOCAL_PARM_INTEGER(fn_name, val) FN_LOCAL_INTEGER(fn_name, val)
|
---|
216 |
|
---|
217 | #define FN_LOCAL_CHAR(fn_name,val) \
|
---|
218 | _PUBLIC_ char lpcfg_ ## fn_name(struct loadparm_service *service, \
|
---|
219 | struct loadparm_service *sDefault) { \
|
---|
220 | return((service != NULL)? service->val : sDefault->val); \
|
---|
221 | }
|
---|
222 |
|
---|
223 | #define FN_LOCAL_PARM_CHAR(fn_name,val) FN_LOCAL_CHAR(fn_name, val)
|
---|
224 |
|
---|
225 | #include "lib/param/param_functions.c"
|
---|
226 |
|
---|
227 | /* These functions cannot be auto-generated */
|
---|
228 | FN_LOCAL_BOOL(autoloaded, autoloaded)
|
---|
229 | FN_GLOBAL_CONST_STRING(dnsdomain, dnsdomain)
|
---|
230 |
|
---|
231 | /* local prototypes */
|
---|
232 | static struct loadparm_service *lpcfg_getservicebyname(struct loadparm_context *lp_ctx,
|
---|
233 | const char *pszServiceName);
|
---|
234 | static bool do_section(const char *pszSectionName, void *);
|
---|
235 | static bool set_variable_helper(TALLOC_CTX *mem_ctx, int parmnum, void *parm_ptr,
|
---|
236 | const char *pszParmName, const char *pszParmValue);
|
---|
237 | static bool lp_do_parameter_parametric(struct loadparm_context *lp_ctx,
|
---|
238 | struct loadparm_service *service,
|
---|
239 | const char *pszParmName,
|
---|
240 | const char *pszParmValue, int flags);
|
---|
241 |
|
---|
242 | /* The following are helper functions for parametrical options support. */
|
---|
243 | /* It returns a pointer to parametrical option value if it exists or NULL otherwise */
|
---|
244 | /* Actual parametrical functions are quite simple */
|
---|
245 | struct parmlist_entry *get_parametric_helper(struct loadparm_service *service,
|
---|
246 | const char *type, const char *option,
|
---|
247 | struct parmlist_entry *global_opts)
|
---|
248 | {
|
---|
249 | size_t type_len = strlen(type);
|
---|
250 | size_t option_len = strlen(option);
|
---|
251 | char param_key[type_len + option_len + 2];
|
---|
252 | struct parmlist_entry *data = NULL;
|
---|
253 |
|
---|
254 | snprintf(param_key, sizeof(param_key), "%s:%s", type, option);
|
---|
255 |
|
---|
256 | /*
|
---|
257 | * Try to fetch the option from the data.
|
---|
258 | */
|
---|
259 | if (service != NULL) {
|
---|
260 | data = service->param_opt;
|
---|
261 | while (data != NULL) {
|
---|
262 | if (strwicmp(data->key, param_key) == 0) {
|
---|
263 | return data;
|
---|
264 | }
|
---|
265 | data = data->next;
|
---|
266 | }
|
---|
267 | }
|
---|
268 |
|
---|
269 | /*
|
---|
270 | * Fall back to fetching from the globals.
|
---|
271 | */
|
---|
272 | data = global_opts;
|
---|
273 | while (data != NULL) {
|
---|
274 | if (strwicmp(data->key, param_key) == 0) {
|
---|
275 | return data;
|
---|
276 | }
|
---|
277 | data = data->next;
|
---|
278 | }
|
---|
279 |
|
---|
280 | return NULL;
|
---|
281 | }
|
---|
282 |
|
---|
283 | const char *lpcfg_get_parametric(struct loadparm_context *lp_ctx,
|
---|
284 | struct loadparm_service *service,
|
---|
285 | const char *type, const char *option)
|
---|
286 | {
|
---|
287 | struct parmlist_entry *data;
|
---|
288 |
|
---|
289 | if (lp_ctx == NULL)
|
---|
290 | return NULL;
|
---|
291 |
|
---|
292 | data = get_parametric_helper(service,
|
---|
293 | type, option, lp_ctx->globals->param_opt);
|
---|
294 |
|
---|
295 | if (data == NULL) {
|
---|
296 | return NULL;
|
---|
297 | } else {
|
---|
298 | return data->value;
|
---|
299 | }
|
---|
300 | }
|
---|
301 |
|
---|
302 |
|
---|
303 | /**
|
---|
304 | * convenience routine to return int parameters.
|
---|
305 | */
|
---|
306 | int lp_int(const char *s)
|
---|
307 | {
|
---|
308 |
|
---|
309 | if (!s || !*s) {
|
---|
310 | DEBUG(0,("lp_int(%s): is called with NULL!\n",s));
|
---|
311 | return -1;
|
---|
312 | }
|
---|
313 |
|
---|
314 | return strtol(s, NULL, 0);
|
---|
315 | }
|
---|
316 |
|
---|
317 | /**
|
---|
318 | * convenience routine to return unsigned long parameters.
|
---|
319 | */
|
---|
320 | unsigned long lp_ulong(const char *s)
|
---|
321 | {
|
---|
322 |
|
---|
323 | if (!s || !*s) {
|
---|
324 | DEBUG(0,("lp_ulong(%s): is called with NULL!\n",s));
|
---|
325 | return -1;
|
---|
326 | }
|
---|
327 |
|
---|
328 | return strtoul(s, NULL, 0);
|
---|
329 | }
|
---|
330 |
|
---|
331 | /**
|
---|
332 | * convenience routine to return unsigned long long parameters.
|
---|
333 | */
|
---|
334 | unsigned long long lp_ulonglong(const char *s)
|
---|
335 | {
|
---|
336 |
|
---|
337 | if (!s || !*s) {
|
---|
338 | DEBUG(0, ("lp_ulonglong(%s): is called with NULL!\n", s));
|
---|
339 | return -1;
|
---|
340 | }
|
---|
341 |
|
---|
342 | return strtoull(s, NULL, 0);
|
---|
343 | }
|
---|
344 |
|
---|
345 | /**
|
---|
346 | * convenience routine to return unsigned long parameters.
|
---|
347 | */
|
---|
348 | static long lp_long(const char *s)
|
---|
349 | {
|
---|
350 |
|
---|
351 | if (!s) {
|
---|
352 | DEBUG(0,("lp_long(%s): is called with NULL!\n",s));
|
---|
353 | return -1;
|
---|
354 | }
|
---|
355 |
|
---|
356 | return strtol(s, NULL, 0);
|
---|
357 | }
|
---|
358 |
|
---|
359 | /**
|
---|
360 | * convenience routine to return unsigned long parameters.
|
---|
361 | */
|
---|
362 | static double lp_double(const char *s)
|
---|
363 | {
|
---|
364 |
|
---|
365 | if (!s) {
|
---|
366 | DEBUG(0,("lp_double(%s): is called with NULL!\n",s));
|
---|
367 | return -1;
|
---|
368 | }
|
---|
369 |
|
---|
370 | return strtod(s, NULL);
|
---|
371 | }
|
---|
372 |
|
---|
373 | /**
|
---|
374 | * convenience routine to return boolean parameters.
|
---|
375 | */
|
---|
376 | bool lp_bool(const char *s)
|
---|
377 | {
|
---|
378 | bool ret = false;
|
---|
379 |
|
---|
380 | if (!s || !*s) {
|
---|
381 | DEBUG(0,("lp_bool(%s): is called with NULL!\n",s));
|
---|
382 | return false;
|
---|
383 | }
|
---|
384 |
|
---|
385 | if (!set_boolean(s, &ret)) {
|
---|
386 | DEBUG(0,("lp_bool(%s): value is not boolean!\n",s));
|
---|
387 | return false;
|
---|
388 | }
|
---|
389 |
|
---|
390 | return ret;
|
---|
391 | }
|
---|
392 |
|
---|
393 | /**
|
---|
394 | * Return parametric option from a given service. Type is a part of option before ':'
|
---|
395 | * Parametric option has following syntax: 'Type: option = value'
|
---|
396 | * Returned value is allocated in 'lp_talloc' context
|
---|
397 | */
|
---|
398 |
|
---|
399 | const char *lpcfg_parm_string(struct loadparm_context *lp_ctx,
|
---|
400 | struct loadparm_service *service, const char *type,
|
---|
401 | const char *option)
|
---|
402 | {
|
---|
403 | const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
|
---|
404 |
|
---|
405 | if (value)
|
---|
406 | return lpcfg_string(value);
|
---|
407 |
|
---|
408 | return NULL;
|
---|
409 | }
|
---|
410 |
|
---|
411 | /**
|
---|
412 | * Return parametric option from a given service. Type is a part of option before ':'
|
---|
413 | * Parametric option has following syntax: 'Type: option = value'
|
---|
414 | * Returned value is allocated in 'lp_talloc' context
|
---|
415 | */
|
---|
416 |
|
---|
417 | const char **lpcfg_parm_string_list(TALLOC_CTX *mem_ctx,
|
---|
418 | struct loadparm_context *lp_ctx,
|
---|
419 | struct loadparm_service *service,
|
---|
420 | const char *type,
|
---|
421 | const char *option, const char *separator)
|
---|
422 | {
|
---|
423 | const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
|
---|
424 |
|
---|
425 | if (value != NULL) {
|
---|
426 | char **l = str_list_make(mem_ctx, value, separator);
|
---|
427 | return discard_const_p(const char *, l);
|
---|
428 | }
|
---|
429 |
|
---|
430 | return NULL;
|
---|
431 | }
|
---|
432 |
|
---|
433 | /**
|
---|
434 | * Return parametric option from a given service. Type is a part of option before ':'
|
---|
435 | * Parametric option has following syntax: 'Type: option = value'
|
---|
436 | */
|
---|
437 |
|
---|
438 | int lpcfg_parm_int(struct loadparm_context *lp_ctx,
|
---|
439 | struct loadparm_service *service, const char *type,
|
---|
440 | const char *option, int default_v)
|
---|
441 | {
|
---|
442 | const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
|
---|
443 |
|
---|
444 | if (value)
|
---|
445 | return lp_int(value);
|
---|
446 |
|
---|
447 | return default_v;
|
---|
448 | }
|
---|
449 |
|
---|
450 | /**
|
---|
451 | * Return parametric option from a given service. Type is a part of
|
---|
452 | * option before ':'.
|
---|
453 | * Parametric option has following syntax: 'Type: option = value'.
|
---|
454 | */
|
---|
455 |
|
---|
456 | int lpcfg_parm_bytes(struct loadparm_context *lp_ctx,
|
---|
457 | struct loadparm_service *service, const char *type,
|
---|
458 | const char *option, int default_v)
|
---|
459 | {
|
---|
460 | uint64_t bval;
|
---|
461 |
|
---|
462 | const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
|
---|
463 |
|
---|
464 | if (value && conv_str_size_error(value, &bval)) {
|
---|
465 | if (bval <= INT_MAX) {
|
---|
466 | return (int)bval;
|
---|
467 | }
|
---|
468 | }
|
---|
469 |
|
---|
470 | return default_v;
|
---|
471 | }
|
---|
472 |
|
---|
473 | /**
|
---|
474 | * Return parametric option from a given service.
|
---|
475 | * Type is a part of option before ':'
|
---|
476 | * Parametric option has following syntax: 'Type: option = value'
|
---|
477 | */
|
---|
478 | unsigned long lpcfg_parm_ulong(struct loadparm_context *lp_ctx,
|
---|
479 | struct loadparm_service *service, const char *type,
|
---|
480 | const char *option, unsigned long default_v)
|
---|
481 | {
|
---|
482 | const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
|
---|
483 |
|
---|
484 | if (value)
|
---|
485 | return lp_ulong(value);
|
---|
486 |
|
---|
487 | return default_v;
|
---|
488 | }
|
---|
489 |
|
---|
490 | /**
|
---|
491 | * Return parametric option from a given service.
|
---|
492 | * Type is a part of option before ':'
|
---|
493 | * Parametric option has following syntax: 'Type: option = value'
|
---|
494 | */
|
---|
495 | unsigned long long lpcfg_parm_ulonglong(struct loadparm_context *lp_ctx,
|
---|
496 | struct loadparm_service *service,
|
---|
497 | const char *type, const char *option,
|
---|
498 | unsigned long long default_v)
|
---|
499 | {
|
---|
500 | const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
|
---|
501 |
|
---|
502 | if (value) {
|
---|
503 | return lp_ulonglong(value);
|
---|
504 | }
|
---|
505 |
|
---|
506 | return default_v;
|
---|
507 | }
|
---|
508 |
|
---|
509 | long lpcfg_parm_long(struct loadparm_context *lp_ctx,
|
---|
510 | struct loadparm_service *service, const char *type,
|
---|
511 | const char *option, long default_v)
|
---|
512 | {
|
---|
513 | const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
|
---|
514 |
|
---|
515 | if (value)
|
---|
516 | return lp_long(value);
|
---|
517 |
|
---|
518 | return default_v;
|
---|
519 | }
|
---|
520 |
|
---|
521 | double lpcfg_parm_double(struct loadparm_context *lp_ctx,
|
---|
522 | struct loadparm_service *service, const char *type,
|
---|
523 | const char *option, double default_v)
|
---|
524 | {
|
---|
525 | const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
|
---|
526 |
|
---|
527 | if (value != NULL)
|
---|
528 | return lp_double(value);
|
---|
529 |
|
---|
530 | return default_v;
|
---|
531 | }
|
---|
532 |
|
---|
533 | /**
|
---|
534 | * Return parametric option from a given service. Type is a part of option before ':'
|
---|
535 | * Parametric option has following syntax: 'Type: option = value'
|
---|
536 | */
|
---|
537 |
|
---|
538 | bool lpcfg_parm_bool(struct loadparm_context *lp_ctx,
|
---|
539 | struct loadparm_service *service, const char *type,
|
---|
540 | const char *option, bool default_v)
|
---|
541 | {
|
---|
542 | const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
|
---|
543 |
|
---|
544 | if (value != NULL)
|
---|
545 | return lp_bool(value);
|
---|
546 |
|
---|
547 | return default_v;
|
---|
548 | }
|
---|
549 |
|
---|
550 |
|
---|
551 | /* this is used to prevent lots of mallocs of size 1 */
|
---|
552 | static const char lpcfg_string_emtpy[] = "";
|
---|
553 |
|
---|
554 | /**
|
---|
555 | Free a string value.
|
---|
556 | **/
|
---|
557 | void lpcfg_string_free(char **s)
|
---|
558 | {
|
---|
559 | if (s == NULL) {
|
---|
560 | return;
|
---|
561 | }
|
---|
562 | if (*s == lpcfg_string_emtpy) {
|
---|
563 | *s = NULL;
|
---|
564 | return;
|
---|
565 | }
|
---|
566 | TALLOC_FREE(*s);
|
---|
567 | }
|
---|
568 |
|
---|
569 | /**
|
---|
570 | * Set a string value, deallocating any existing space, and allocing the space
|
---|
571 | * for the string
|
---|
572 | */
|
---|
573 | bool lpcfg_string_set(TALLOC_CTX *mem_ctx, char **dest, const char *src)
|
---|
574 | {
|
---|
575 | lpcfg_string_free(dest);
|
---|
576 |
|
---|
577 | if ((src == NULL) || (*src == '\0')) {
|
---|
578 | *dest = discard_const_p(char, lpcfg_string_emtpy);
|
---|
579 | return true;
|
---|
580 | }
|
---|
581 |
|
---|
582 | *dest = talloc_strdup(mem_ctx, src);
|
---|
583 | if ((*dest) == NULL) {
|
---|
584 | DEBUG(0,("Out of memory in string_set\n"));
|
---|
585 | return false;
|
---|
586 | }
|
---|
587 |
|
---|
588 | return true;
|
---|
589 | }
|
---|
590 |
|
---|
591 | /**
|
---|
592 | * Set a string value, deallocating any existing space, and allocing the space
|
---|
593 | * for the string
|
---|
594 | */
|
---|
595 | bool lpcfg_string_set_upper(TALLOC_CTX *mem_ctx, char **dest, const char *src)
|
---|
596 | {
|
---|
597 | lpcfg_string_free(dest);
|
---|
598 |
|
---|
599 | if ((src == NULL) || (*src == '\0')) {
|
---|
600 | *dest = discard_const_p(char, lpcfg_string_emtpy);
|
---|
601 | return true;
|
---|
602 | }
|
---|
603 |
|
---|
604 | *dest = strupper_talloc(mem_ctx, src);
|
---|
605 | if ((*dest) == NULL) {
|
---|
606 | DEBUG(0,("Out of memory in string_set_upper\n"));
|
---|
607 | return false;
|
---|
608 | }
|
---|
609 |
|
---|
610 | return true;
|
---|
611 | }
|
---|
612 |
|
---|
613 |
|
---|
614 |
|
---|
615 | /**
|
---|
616 | * Add a new service to the services array initialising it with the given
|
---|
617 | * service.
|
---|
618 | */
|
---|
619 |
|
---|
620 | struct loadparm_service *lpcfg_add_service(struct loadparm_context *lp_ctx,
|
---|
621 | const struct loadparm_service *pservice,
|
---|
622 | const char *name)
|
---|
623 | {
|
---|
624 | int i;
|
---|
625 | int num_to_alloc = lp_ctx->iNumServices + 1;
|
---|
626 | struct parmlist_entry *data, *pdata;
|
---|
627 |
|
---|
628 | if (lp_ctx->s3_fns != NULL) {
|
---|
629 | smb_panic("Add a service should not be called on an s3 loadparm ctx");
|
---|
630 | }
|
---|
631 |
|
---|
632 | if (pservice == NULL) {
|
---|
633 | pservice = lp_ctx->sDefault;
|
---|
634 | }
|
---|
635 |
|
---|
636 | /* it might already exist */
|
---|
637 | if (name) {
|
---|
638 | struct loadparm_service *service = lpcfg_getservicebyname(lp_ctx,
|
---|
639 | name);
|
---|
640 | if (service != NULL) {
|
---|
641 | /* Clean all parametric options for service */
|
---|
642 | /* They will be added during parsing again */
|
---|
643 | data = service->param_opt;
|
---|
644 | while (data) {
|
---|
645 | pdata = data->next;
|
---|
646 | talloc_free(data);
|
---|
647 | data = pdata;
|
---|
648 | }
|
---|
649 | service->param_opt = NULL;
|
---|
650 | return service;
|
---|
651 | }
|
---|
652 | }
|
---|
653 |
|
---|
654 | /* find an invalid one */
|
---|
655 | for (i = 0; i < lp_ctx->iNumServices; i++)
|
---|
656 | if (lp_ctx->services[i] == NULL)
|
---|
657 | break;
|
---|
658 |
|
---|
659 | /* if not, then create one */
|
---|
660 | if (i == lp_ctx->iNumServices) {
|
---|
661 | struct loadparm_service **tsp;
|
---|
662 |
|
---|
663 | tsp = talloc_realloc(lp_ctx, lp_ctx->services, struct loadparm_service *, num_to_alloc);
|
---|
664 |
|
---|
665 | if (!tsp) {
|
---|
666 | DEBUG(0,("lpcfg_add_service: failed to enlarge services!\n"));
|
---|
667 | return NULL;
|
---|
668 | } else {
|
---|
669 | lp_ctx->services = tsp;
|
---|
670 | lp_ctx->services[lp_ctx->iNumServices] = NULL;
|
---|
671 | }
|
---|
672 |
|
---|
673 | lp_ctx->iNumServices++;
|
---|
674 | }
|
---|
675 |
|
---|
676 | lp_ctx->services[i] = talloc_zero(lp_ctx->services, struct loadparm_service);
|
---|
677 | if (lp_ctx->services[i] == NULL) {
|
---|
678 | DEBUG(0,("lpcfg_add_service: out of memory!\n"));
|
---|
679 | return NULL;
|
---|
680 | }
|
---|
681 | copy_service(lp_ctx->services[i], pservice, NULL);
|
---|
682 | if (name != NULL)
|
---|
683 | lpcfg_string_set(lp_ctx->services[i], &lp_ctx->services[i]->szService, name);
|
---|
684 | return lp_ctx->services[i];
|
---|
685 | }
|
---|
686 |
|
---|
687 | /**
|
---|
688 | * Add a new home service, with the specified home directory, defaults coming
|
---|
689 | * from service ifrom.
|
---|
690 | */
|
---|
691 |
|
---|
692 | bool lpcfg_add_home(struct loadparm_context *lp_ctx,
|
---|
693 | const char *pszHomename,
|
---|
694 | struct loadparm_service *default_service,
|
---|
695 | const char *user, const char *pszHomedir)
|
---|
696 | {
|
---|
697 | struct loadparm_service *service;
|
---|
698 |
|
---|
699 | service = lpcfg_add_service(lp_ctx, default_service, pszHomename);
|
---|
700 |
|
---|
701 | if (service == NULL)
|
---|
702 | return false;
|
---|
703 |
|
---|
704 | if (!(*(default_service->path))
|
---|
705 | || strequal(default_service->path, lp_ctx->sDefault->path)) {
|
---|
706 | service->path = talloc_strdup(service, pszHomedir);
|
---|
707 | } else {
|
---|
708 | service->path = string_sub_talloc(service, lpcfg_path(default_service, lp_ctx->sDefault, service), "%H", pszHomedir);
|
---|
709 | }
|
---|
710 |
|
---|
711 | if (!(*(service->comment))) {
|
---|
712 | service->comment = talloc_asprintf(service, "Home directory of %s", user);
|
---|
713 | }
|
---|
714 | service->available = default_service->available;
|
---|
715 | service->browseable = default_service->browseable;
|
---|
716 |
|
---|
717 | DEBUG(3, ("adding home's share [%s] for user '%s' at '%s'\n",
|
---|
718 | pszHomename, user, service->path));
|
---|
719 |
|
---|
720 | return true;
|
---|
721 | }
|
---|
722 |
|
---|
723 | /**
|
---|
724 | * Add a new printer service, with defaults coming from service iFrom.
|
---|
725 | */
|
---|
726 |
|
---|
727 | bool lpcfg_add_printer(struct loadparm_context *lp_ctx,
|
---|
728 | const char *pszPrintername,
|
---|
729 | struct loadparm_service *default_service)
|
---|
730 | {
|
---|
731 | const char *comment = "From Printcap";
|
---|
732 | struct loadparm_service *service;
|
---|
733 | service = lpcfg_add_service(lp_ctx, default_service, pszPrintername);
|
---|
734 |
|
---|
735 | if (service == NULL)
|
---|
736 | return false;
|
---|
737 |
|
---|
738 | /* note that we do NOT default the availability flag to True - */
|
---|
739 | /* we take it from the default service passed. This allows all */
|
---|
740 | /* dynamic printers to be disabled by disabling the [printers] */
|
---|
741 | /* entry (if/when the 'available' keyword is implemented!). */
|
---|
742 |
|
---|
743 | /* the printer name is set to the service name. */
|
---|
744 | lpcfg_string_set(service, &service->_printername, pszPrintername);
|
---|
745 | lpcfg_string_set(service, &service->comment, comment);
|
---|
746 | service->browseable = default_service->browseable;
|
---|
747 | /* Printers cannot be read_only. */
|
---|
748 | service->read_only = false;
|
---|
749 | /* Printer services must be printable. */
|
---|
750 | service->printable = true;
|
---|
751 |
|
---|
752 | DEBUG(3, ("adding printer service %s\n", pszPrintername));
|
---|
753 |
|
---|
754 | return true;
|
---|
755 | }
|
---|
756 |
|
---|
757 | /**
|
---|
758 | * Map a parameter's string representation to something we can use.
|
---|
759 | * Returns False if the parameter string is not recognised, else TRUE.
|
---|
760 | */
|
---|
761 |
|
---|
762 | int lpcfg_map_parameter(const char *pszParmName)
|
---|
763 | {
|
---|
764 | int iIndex;
|
---|
765 |
|
---|
766 | for (iIndex = 0; parm_table[iIndex].label; iIndex++)
|
---|
767 | if (strwicmp(parm_table[iIndex].label, pszParmName) == 0)
|
---|
768 | return iIndex;
|
---|
769 |
|
---|
770 | /* Warn only if it isn't parametric option */
|
---|
771 | if (strchr(pszParmName, ':') == NULL)
|
---|
772 | DEBUG(0, ("Unknown parameter encountered: \"%s\"\n", pszParmName));
|
---|
773 | /* We do return 'fail' for parametric options as well because they are
|
---|
774 | stored in different storage
|
---|
775 | */
|
---|
776 | return -1;
|
---|
777 | }
|
---|
778 |
|
---|
779 |
|
---|
780 | /**
|
---|
781 | return the parameter structure for a parameter
|
---|
782 | */
|
---|
783 | struct parm_struct *lpcfg_parm_struct(struct loadparm_context *lp_ctx, const char *name)
|
---|
784 | {
|
---|
785 | int num = lpcfg_map_parameter(name);
|
---|
786 |
|
---|
787 | if (num < 0) {
|
---|
788 | return NULL;
|
---|
789 | }
|
---|
790 |
|
---|
791 | return &parm_table[num];
|
---|
792 | }
|
---|
793 |
|
---|
794 | /**
|
---|
795 | return the parameter pointer for a parameter
|
---|
796 | */
|
---|
797 | void *lpcfg_parm_ptr(struct loadparm_context *lp_ctx,
|
---|
798 | struct loadparm_service *service, struct parm_struct *parm)
|
---|
799 | {
|
---|
800 | if (lp_ctx->s3_fns) {
|
---|
801 | return lp_ctx->s3_fns->get_parm_ptr(service, parm);
|
---|
802 | }
|
---|
803 |
|
---|
804 | if (service == NULL) {
|
---|
805 | if (parm->p_class == P_LOCAL)
|
---|
806 | return ((char *)lp_ctx->sDefault)+parm->offset;
|
---|
807 | else if (parm->p_class == P_GLOBAL)
|
---|
808 | return ((char *)lp_ctx->globals)+parm->offset;
|
---|
809 | else return NULL;
|
---|
810 | } else {
|
---|
811 | return ((char *)service) + parm->offset;
|
---|
812 | }
|
---|
813 | }
|
---|
814 |
|
---|
815 | /**
|
---|
816 | return the parameter pointer for a parameter
|
---|
817 | */
|
---|
818 | bool lpcfg_parm_is_cmdline(struct loadparm_context *lp_ctx, const char *name)
|
---|
819 | {
|
---|
820 | int parmnum;
|
---|
821 |
|
---|
822 | parmnum = lpcfg_map_parameter(name);
|
---|
823 | if (parmnum == -1) return false;
|
---|
824 |
|
---|
825 | return lp_ctx->flags[parmnum] & FLAG_CMDLINE;
|
---|
826 | }
|
---|
827 |
|
---|
828 | /**
|
---|
829 | * Find a service by name. Otherwise works like get_service.
|
---|
830 | */
|
---|
831 |
|
---|
832 | static struct loadparm_service *lpcfg_getservicebyname(struct loadparm_context *lp_ctx,
|
---|
833 | const char *pszServiceName)
|
---|
834 | {
|
---|
835 | int iService;
|
---|
836 |
|
---|
837 | if (lp_ctx->s3_fns) {
|
---|
838 | return lp_ctx->s3_fns->get_service(pszServiceName);
|
---|
839 | }
|
---|
840 |
|
---|
841 | for (iService = lp_ctx->iNumServices - 1; iService >= 0; iService--)
|
---|
842 | if (lp_ctx->services[iService] != NULL &&
|
---|
843 | strwicmp(lp_ctx->services[iService]->szService, pszServiceName) == 0) {
|
---|
844 | return lp_ctx->services[iService];
|
---|
845 | }
|
---|
846 |
|
---|
847 | return NULL;
|
---|
848 | }
|
---|
849 |
|
---|
850 | /**
|
---|
851 | * Add a parametric option to a parmlist_entry,
|
---|
852 | * replacing old value, if already present.
|
---|
853 | */
|
---|
854 | void set_param_opt(TALLOC_CTX *mem_ctx,
|
---|
855 | struct parmlist_entry **opt_list,
|
---|
856 | const char *opt_name,
|
---|
857 | const char *opt_value,
|
---|
858 | unsigned priority)
|
---|
859 | {
|
---|
860 | struct parmlist_entry *new_opt, *opt;
|
---|
861 |
|
---|
862 | opt = *opt_list;
|
---|
863 |
|
---|
864 | /* Traverse destination */
|
---|
865 | while (opt) {
|
---|
866 | /* If we already have same option, override it */
|
---|
867 | if (strwicmp(opt->key, opt_name) == 0) {
|
---|
868 | if ((opt->priority & FLAG_CMDLINE) &&
|
---|
869 | !(priority & FLAG_CMDLINE)) {
|
---|
870 | /* it's been marked as not to be
|
---|
871 | overridden */
|
---|
872 | return;
|
---|
873 | }
|
---|
874 | TALLOC_FREE(opt->list);
|
---|
875 | lpcfg_string_set(opt, &opt->value, opt_value);
|
---|
876 | opt->priority = priority;
|
---|
877 | return;
|
---|
878 | }
|
---|
879 | opt = opt->next;
|
---|
880 | }
|
---|
881 |
|
---|
882 | new_opt = talloc_pooled_object(
|
---|
883 | mem_ctx, struct parmlist_entry,
|
---|
884 | 2, strlen(opt_name) + 1 + strlen(opt_value) + 1);
|
---|
885 | if (new_opt == NULL) {
|
---|
886 | smb_panic("OOM");
|
---|
887 | }
|
---|
888 | new_opt->key = NULL;
|
---|
889 | lpcfg_string_set(new_opt, &new_opt->key, opt_name);
|
---|
890 | new_opt->value = NULL;
|
---|
891 | lpcfg_string_set(new_opt, &new_opt->value, opt_value);
|
---|
892 |
|
---|
893 | new_opt->list = NULL;
|
---|
894 | new_opt->priority = priority;
|
---|
895 | DLIST_ADD(*opt_list, new_opt);
|
---|
896 | }
|
---|
897 |
|
---|
898 | /**
|
---|
899 | * Copy a service structure to another.
|
---|
900 | * If pcopymapDest is NULL then copy all fields
|
---|
901 | */
|
---|
902 |
|
---|
903 | void copy_service(struct loadparm_service *pserviceDest,
|
---|
904 | const struct loadparm_service *pserviceSource,
|
---|
905 | struct bitmap *pcopymapDest)
|
---|
906 | {
|
---|
907 | int i;
|
---|
908 | bool bcopyall = (pcopymapDest == NULL);
|
---|
909 | struct parmlist_entry *data;
|
---|
910 |
|
---|
911 | for (i = 0; parm_table[i].label; i++)
|
---|
912 | if (parm_table[i].p_class == P_LOCAL &&
|
---|
913 | (bcopyall || bitmap_query(pcopymapDest, i))) {
|
---|
914 | const void *src_ptr =
|
---|
915 | ((const char *)pserviceSource) + parm_table[i].offset;
|
---|
916 | void *dest_ptr =
|
---|
917 | ((char *)pserviceDest) + parm_table[i].offset;
|
---|
918 |
|
---|
919 | switch (parm_table[i].type) {
|
---|
920 | case P_BOOL:
|
---|
921 | case P_BOOLREV:
|
---|
922 | *(bool *)dest_ptr = *(const bool *)src_ptr;
|
---|
923 | break;
|
---|
924 |
|
---|
925 | case P_INTEGER:
|
---|
926 | case P_BYTES:
|
---|
927 | case P_OCTAL:
|
---|
928 | case P_ENUM:
|
---|
929 | *(int *)dest_ptr = *(const int *)src_ptr;
|
---|
930 | break;
|
---|
931 |
|
---|
932 | case P_CHAR:
|
---|
933 | *(char *)dest_ptr = *(const char *)src_ptr;
|
---|
934 | break;
|
---|
935 |
|
---|
936 | case P_STRING:
|
---|
937 | lpcfg_string_set(pserviceDest,
|
---|
938 | (char **)dest_ptr,
|
---|
939 | *(const char * const *)src_ptr);
|
---|
940 | break;
|
---|
941 |
|
---|
942 | case P_USTRING:
|
---|
943 | lpcfg_string_set_upper(pserviceDest,
|
---|
944 | (char **)dest_ptr,
|
---|
945 | *(const char * const *)src_ptr);
|
---|
946 | break;
|
---|
947 | case P_CMDLIST:
|
---|
948 | case P_LIST:
|
---|
949 | TALLOC_FREE(*((char ***)dest_ptr));
|
---|
950 | *(char ***)dest_ptr = str_list_copy(pserviceDest,
|
---|
951 | *discard_const_p(const char **, src_ptr));
|
---|
952 | break;
|
---|
953 | default:
|
---|
954 | break;
|
---|
955 | }
|
---|
956 | }
|
---|
957 |
|
---|
958 | if (bcopyall) {
|
---|
959 | init_copymap(pserviceDest);
|
---|
960 | if (pserviceSource->copymap)
|
---|
961 | bitmap_copy(pserviceDest->copymap,
|
---|
962 | pserviceSource->copymap);
|
---|
963 | }
|
---|
964 |
|
---|
965 | for (data = pserviceSource->param_opt; data != NULL; data = data->next) {
|
---|
966 | set_param_opt(pserviceDest, &pserviceDest->param_opt,
|
---|
967 | data->key, data->value, data->priority);
|
---|
968 | }
|
---|
969 | }
|
---|
970 |
|
---|
971 | /**
|
---|
972 | * Check a service for consistency. Return False if the service is in any way
|
---|
973 | * incomplete or faulty, else True.
|
---|
974 | */
|
---|
975 | bool lpcfg_service_ok(struct loadparm_service *service)
|
---|
976 | {
|
---|
977 | bool bRetval;
|
---|
978 |
|
---|
979 | bRetval = true;
|
---|
980 | if (service->szService[0] == '\0') {
|
---|
981 | DEBUG(0, ("The following message indicates an internal error:\n"));
|
---|
982 | DEBUG(0, ("No service name in service entry.\n"));
|
---|
983 | bRetval = false;
|
---|
984 | }
|
---|
985 |
|
---|
986 | /* The [printers] entry MUST be printable. I'm all for flexibility, but */
|
---|
987 | /* I can't see why you'd want a non-printable printer service... */
|
---|
988 | if (strwicmp(service->szService, PRINTERS_NAME) == 0) {
|
---|
989 | if (!service->printable) {
|
---|
990 | DEBUG(0, ("WARNING: [%s] service MUST be printable!\n",
|
---|
991 | service->szService));
|
---|
992 | service->printable = true;
|
---|
993 | }
|
---|
994 | /* [printers] service must also be non-browsable. */
|
---|
995 | if (service->browseable)
|
---|
996 | service->browseable = false;
|
---|
997 | }
|
---|
998 |
|
---|
999 | if (service->path[0] == '\0' &&
|
---|
1000 | strwicmp(service->szService, HOMES_NAME) != 0 &&
|
---|
1001 | service->msdfs_proxy[0] == '\0')
|
---|
1002 | {
|
---|
1003 | DEBUG(0, ("WARNING: No path in service %s - making it unavailable!\n",
|
---|
1004 | service->szService));
|
---|
1005 | service->available = false;
|
---|
1006 | }
|
---|
1007 |
|
---|
1008 | if (!service->available)
|
---|
1009 | DEBUG(1, ("NOTE: Service %s is flagged unavailable.\n",
|
---|
1010 | service->szService));
|
---|
1011 |
|
---|
1012 | return bRetval;
|
---|
1013 | }
|
---|
1014 |
|
---|
1015 |
|
---|
1016 | /*******************************************************************
|
---|
1017 | Keep a linked list of all config files so we know when one has changed
|
---|
1018 | it's date and needs to be reloaded.
|
---|
1019 | ********************************************************************/
|
---|
1020 |
|
---|
1021 | void add_to_file_list(TALLOC_CTX *mem_ctx, struct file_lists **list,
|
---|
1022 | const char *fname, const char *subfname)
|
---|
1023 | {
|
---|
1024 | struct file_lists *f = *list;
|
---|
1025 |
|
---|
1026 | while (f) {
|
---|
1027 | if (f->name && !strcmp(f->name, fname))
|
---|
1028 | break;
|
---|
1029 | f = f->next;
|
---|
1030 | }
|
---|
1031 |
|
---|
1032 | if (!f) {
|
---|
1033 | f = talloc(mem_ctx, struct file_lists);
|
---|
1034 | if (!f)
|
---|
1035 | goto fail;
|
---|
1036 | f->next = *list;
|
---|
1037 | f->name = talloc_strdup(f, fname);
|
---|
1038 | if (!f->name) {
|
---|
1039 | TALLOC_FREE(f);
|
---|
1040 | goto fail;
|
---|
1041 | }
|
---|
1042 | f->subfname = talloc_strdup(f, subfname);
|
---|
1043 | if (!f->subfname) {
|
---|
1044 | TALLOC_FREE(f);
|
---|
1045 | goto fail;
|
---|
1046 | }
|
---|
1047 | *list = f;
|
---|
1048 | f->modtime = file_modtime(subfname);
|
---|
1049 | } else {
|
---|
1050 | time_t t = file_modtime(subfname);
|
---|
1051 | if (t)
|
---|
1052 | f->modtime = t;
|
---|
1053 | }
|
---|
1054 | return;
|
---|
1055 |
|
---|
1056 | fail:
|
---|
1057 | DEBUG(0, ("Unable to add file to file list: %s\n", fname));
|
---|
1058 |
|
---|
1059 | }
|
---|
1060 |
|
---|
1061 | /*******************************************************************
|
---|
1062 | Check if a config file has changed date.
|
---|
1063 | ********************************************************************/
|
---|
1064 | bool lpcfg_file_list_changed(struct loadparm_context *lp_ctx)
|
---|
1065 | {
|
---|
1066 | struct file_lists *f;
|
---|
1067 | DEBUG(6, ("lpcfg_file_list_changed()\n"));
|
---|
1068 |
|
---|
1069 | for (f = lp_ctx->file_lists; f != NULL; f = f->next) {
|
---|
1070 | char *n2;
|
---|
1071 | time_t mod_time;
|
---|
1072 |
|
---|
1073 | n2 = standard_sub_basic(lp_ctx, f->name);
|
---|
1074 |
|
---|
1075 | DEBUGADD(6, ("file %s -> %s last mod_time: %s\n",
|
---|
1076 | f->name, n2, ctime(&f->modtime)));
|
---|
1077 |
|
---|
1078 | mod_time = file_modtime(n2);
|
---|
1079 |
|
---|
1080 | if (mod_time && ((f->modtime != mod_time) || (f->subfname == NULL) || (strcmp(n2, f->subfname) != 0))) {
|
---|
1081 | DEBUGADD(6, ("file %s modified: %s\n", n2,
|
---|
1082 | ctime(&mod_time)));
|
---|
1083 | f->modtime = mod_time;
|
---|
1084 | talloc_free(f->subfname);
|
---|
1085 | f->subfname = talloc_strdup(f, n2);
|
---|
1086 | TALLOC_FREE(n2);
|
---|
1087 | return true;
|
---|
1088 | }
|
---|
1089 | TALLOC_FREE(n2);
|
---|
1090 | }
|
---|
1091 | return false;
|
---|
1092 | }
|
---|
1093 |
|
---|
1094 | /*
|
---|
1095 | * set the value for a P_ENUM
|
---|
1096 | */
|
---|
1097 | bool lp_set_enum_parm( struct parm_struct *parm, const char *pszParmValue,
|
---|
1098 | int *ptr )
|
---|
1099 | {
|
---|
1100 | int i;
|
---|
1101 |
|
---|
1102 | for (i = 0; parm->enum_list[i].name; i++) {
|
---|
1103 | if (strwicmp(pszParmValue, parm->enum_list[i].name) == 0) {
|
---|
1104 | *ptr = parm->enum_list[i].value;
|
---|
1105 | return true;
|
---|
1106 | }
|
---|
1107 | }
|
---|
1108 | DEBUG(0, ("WARNING: Ignoring invalid value '%s' for parameter '%s'\n",
|
---|
1109 | pszParmValue, parm->label));
|
---|
1110 | return false;
|
---|
1111 | }
|
---|
1112 |
|
---|
1113 |
|
---|
1114 | /***************************************************************************
|
---|
1115 | Handle the "realm" parameter
|
---|
1116 | ***************************************************************************/
|
---|
1117 |
|
---|
1118 | bool handle_realm(struct loadparm_context *lp_ctx, struct loadparm_service *service,
|
---|
1119 | const char *pszParmValue, char **ptr)
|
---|
1120 | {
|
---|
1121 | char *upper;
|
---|
1122 | char *lower;
|
---|
1123 |
|
---|
1124 | upper = strupper_talloc(lp_ctx, pszParmValue);
|
---|
1125 | if (upper == NULL) {
|
---|
1126 | return false;
|
---|
1127 | }
|
---|
1128 |
|
---|
1129 | lower = strlower_talloc(lp_ctx, pszParmValue);
|
---|
1130 | if (lower == NULL) {
|
---|
1131 | TALLOC_FREE(upper);
|
---|
1132 | return false;
|
---|
1133 | }
|
---|
1134 |
|
---|
1135 | lpcfg_string_set(lp_ctx->globals->ctx, &lp_ctx->globals->realm_original, pszParmValue);
|
---|
1136 | lpcfg_string_set(lp_ctx->globals->ctx, &lp_ctx->globals->realm, upper);
|
---|
1137 | lpcfg_string_set(lp_ctx->globals->ctx, &lp_ctx->globals->dnsdomain, lower);
|
---|
1138 |
|
---|
1139 | return true;
|
---|
1140 | }
|
---|
1141 |
|
---|
1142 | /***************************************************************************
|
---|
1143 | Handle the include operation.
|
---|
1144 | ***************************************************************************/
|
---|
1145 |
|
---|
1146 | bool handle_include(struct loadparm_context *lp_ctx, struct loadparm_service *service,
|
---|
1147 | const char *pszParmValue, char **ptr)
|
---|
1148 | {
|
---|
1149 | char *fname;
|
---|
1150 | const char *substitution_variable_substring;
|
---|
1151 | char next_char;
|
---|
1152 |
|
---|
1153 | if (lp_ctx->s3_fns) {
|
---|
1154 | return lp_ctx->s3_fns->lp_include(lp_ctx, service, pszParmValue, ptr);
|
---|
1155 | }
|
---|
1156 |
|
---|
1157 | fname = standard_sub_basic(lp_ctx, pszParmValue);
|
---|
1158 |
|
---|
1159 | add_to_file_list(lp_ctx, &lp_ctx->file_lists, pszParmValue, fname);
|
---|
1160 |
|
---|
1161 | lpcfg_string_set(lp_ctx, ptr, fname);
|
---|
1162 |
|
---|
1163 | if (file_exist(fname))
|
---|
1164 | return pm_process(fname, do_section, lpcfg_do_parameter, lp_ctx);
|
---|
1165 |
|
---|
1166 | /*
|
---|
1167 | * If the file doesn't exist, we check that it isn't due to variable
|
---|
1168 | * substitution
|
---|
1169 | */
|
---|
1170 | substitution_variable_substring = strchr(fname, '%');
|
---|
1171 |
|
---|
1172 | if (substitution_variable_substring != NULL) {
|
---|
1173 | next_char = substitution_variable_substring[1];
|
---|
1174 | if ((next_char >= 'a' && next_char <= 'z')
|
---|
1175 | || (next_char >= 'A' && next_char <= 'Z')) {
|
---|
1176 | DEBUG(2, ("Tried to load %s but variable substitution in "
|
---|
1177 | "filename, ignoring file.\n", fname));
|
---|
1178 | return true;
|
---|
1179 | }
|
---|
1180 | }
|
---|
1181 |
|
---|
1182 | DEBUG(2, ("Can't find include file %s\n", fname));
|
---|
1183 |
|
---|
1184 | return false;
|
---|
1185 | }
|
---|
1186 |
|
---|
1187 | /***************************************************************************
|
---|
1188 | Handle the interpretation of the copy parameter.
|
---|
1189 | ***************************************************************************/
|
---|
1190 |
|
---|
1191 | bool handle_copy(struct loadparm_context *lp_ctx, struct loadparm_service *service,
|
---|
1192 | const char *pszParmValue, char **ptr)
|
---|
1193 | {
|
---|
1194 | bool bRetval;
|
---|
1195 | struct loadparm_service *serviceTemp = NULL;
|
---|
1196 |
|
---|
1197 | bRetval = false;
|
---|
1198 |
|
---|
1199 | DEBUG(3, ("Copying service from service %s\n", pszParmValue));
|
---|
1200 |
|
---|
1201 | serviceTemp = lpcfg_getservicebyname(lp_ctx, pszParmValue);
|
---|
1202 |
|
---|
1203 | if (service == NULL) {
|
---|
1204 | DEBUG(0, ("Unable to copy service - invalid service destination.\n"));
|
---|
1205 | return false;
|
---|
1206 | }
|
---|
1207 |
|
---|
1208 | if (serviceTemp != NULL) {
|
---|
1209 | if (serviceTemp == service) {
|
---|
1210 | DEBUG(0, ("Can't copy service %s - unable to copy self!\n", pszParmValue));
|
---|
1211 | } else {
|
---|
1212 | copy_service(service,
|
---|
1213 | serviceTemp,
|
---|
1214 | service->copymap);
|
---|
1215 | lpcfg_string_set(service, ptr, pszParmValue);
|
---|
1216 |
|
---|
1217 | bRetval = true;
|
---|
1218 | }
|
---|
1219 | } else {
|
---|
1220 | DEBUG(0, ("Unable to copy service - source not found: %s\n",
|
---|
1221 | pszParmValue));
|
---|
1222 | bRetval = false;
|
---|
1223 | }
|
---|
1224 |
|
---|
1225 | return bRetval;
|
---|
1226 | }
|
---|
1227 |
|
---|
1228 | bool handle_debug_list(struct loadparm_context *lp_ctx, struct loadparm_service *service,
|
---|
1229 | const char *pszParmValue, char **ptr)
|
---|
1230 | {
|
---|
1231 | lpcfg_string_set(lp_ctx->globals->ctx, ptr, pszParmValue);
|
---|
1232 |
|
---|
1233 | return debug_parse_levels(pszParmValue);
|
---|
1234 | }
|
---|
1235 |
|
---|
1236 | bool handle_logfile(struct loadparm_context *lp_ctx, struct loadparm_service *service,
|
---|
1237 | const char *pszParmValue, char **ptr)
|
---|
1238 | {
|
---|
1239 | if (lp_ctx->s3_fns == NULL) {
|
---|
1240 | debug_set_logfile(pszParmValue);
|
---|
1241 | }
|
---|
1242 |
|
---|
1243 | lpcfg_string_set(lp_ctx->globals->ctx, ptr, pszParmValue);
|
---|
1244 |
|
---|
1245 | return true;
|
---|
1246 | }
|
---|
1247 |
|
---|
1248 | /*
|
---|
1249 | * These special charset handling methods only run in the source3 code.
|
---|
1250 | */
|
---|
1251 |
|
---|
1252 | bool handle_charset(struct loadparm_context *lp_ctx, struct loadparm_service *service,
|
---|
1253 | const char *pszParmValue, char **ptr)
|
---|
1254 | {
|
---|
1255 | if (lp_ctx->s3_fns) {
|
---|
1256 | if (*ptr == NULL || strcmp(*ptr, pszParmValue) != 0) {
|
---|
1257 | global_iconv_handle = smb_iconv_handle_reinit(NULL,
|
---|
1258 | lpcfg_dos_charset(lp_ctx),
|
---|
1259 | lpcfg_unix_charset(lp_ctx),
|
---|
1260 | true, global_iconv_handle);
|
---|
1261 | }
|
---|
1262 |
|
---|
1263 | }
|
---|
1264 | return lpcfg_string_set(lp_ctx->globals->ctx, ptr, pszParmValue);
|
---|
1265 |
|
---|
1266 | }
|
---|
1267 |
|
---|
1268 | bool handle_dos_charset(struct loadparm_context *lp_ctx, struct loadparm_service *service,
|
---|
1269 | const char *pszParmValue, char **ptr)
|
---|
1270 | {
|
---|
1271 | bool is_utf8 = false;
|
---|
1272 | size_t len = strlen(pszParmValue);
|
---|
1273 |
|
---|
1274 | if (lp_ctx->s3_fns) {
|
---|
1275 | if (len == 4 || len == 5) {
|
---|
1276 | /* Don't use StrCaseCmp here as we don't want to
|
---|
1277 | initialize iconv. */
|
---|
1278 | if ((toupper_m(pszParmValue[0]) == 'U') &&
|
---|
1279 | (toupper_m(pszParmValue[1]) == 'T') &&
|
---|
1280 | (toupper_m(pszParmValue[2]) == 'F')) {
|
---|
1281 | if (len == 4) {
|
---|
1282 | if (pszParmValue[3] == '8') {
|
---|
1283 | is_utf8 = true;
|
---|
1284 | }
|
---|
1285 | } else {
|
---|
1286 | if (pszParmValue[3] == '-' &&
|
---|
1287 | pszParmValue[4] == '8') {
|
---|
1288 | is_utf8 = true;
|
---|
1289 | }
|
---|
1290 | }
|
---|
1291 | }
|
---|
1292 | }
|
---|
1293 |
|
---|
1294 | if (*ptr == NULL || strcmp(*ptr, pszParmValue) != 0) {
|
---|
1295 | if (is_utf8) {
|
---|
1296 | DEBUG(0,("ERROR: invalid DOS charset: 'dos charset' must not "
|
---|
1297 | "be UTF8, using (default value) %s instead.\n",
|
---|
1298 | DEFAULT_DOS_CHARSET));
|
---|
1299 | pszParmValue = DEFAULT_DOS_CHARSET;
|
---|
1300 | }
|
---|
1301 | global_iconv_handle = smb_iconv_handle_reinit(NULL,
|
---|
1302 | lpcfg_dos_charset(lp_ctx),
|
---|
1303 | lpcfg_unix_charset(lp_ctx),
|
---|
1304 | true, global_iconv_handle);
|
---|
1305 | }
|
---|
1306 | }
|
---|
1307 |
|
---|
1308 | return lpcfg_string_set(lp_ctx->globals->ctx, ptr, pszParmValue);
|
---|
1309 | }
|
---|
1310 |
|
---|
1311 | bool handle_printing(struct loadparm_context *lp_ctx, struct loadparm_service *service,
|
---|
1312 | const char *pszParmValue, char **ptr)
|
---|
1313 | {
|
---|
1314 | static int parm_num = -1;
|
---|
1315 |
|
---|
1316 | if (parm_num == -1) {
|
---|
1317 | parm_num = lpcfg_map_parameter("printing");
|
---|
1318 | }
|
---|
1319 |
|
---|
1320 | if (!lp_set_enum_parm(&parm_table[parm_num], pszParmValue, (int*)ptr)) {
|
---|
1321 | return false;
|
---|
1322 | }
|
---|
1323 |
|
---|
1324 | if (lp_ctx->s3_fns) {
|
---|
1325 | if (service == NULL) {
|
---|
1326 | init_printer_values(lp_ctx, lp_ctx->globals->ctx, lp_ctx->sDefault);
|
---|
1327 | } else {
|
---|
1328 | init_printer_values(lp_ctx, service, service);
|
---|
1329 | }
|
---|
1330 | }
|
---|
1331 |
|
---|
1332 | return true;
|
---|
1333 | }
|
---|
1334 |
|
---|
1335 | bool handle_ldap_debug_level(struct loadparm_context *lp_ctx, struct loadparm_service *service,
|
---|
1336 | const char *pszParmValue, char **ptr)
|
---|
1337 | {
|
---|
1338 | lp_ctx->globals->ldap_debug_level = lp_int(pszParmValue);
|
---|
1339 |
|
---|
1340 | if (lp_ctx->s3_fns) {
|
---|
1341 | lp_ctx->s3_fns->init_ldap_debugging();
|
---|
1342 | }
|
---|
1343 | return true;
|
---|
1344 | }
|
---|
1345 |
|
---|
1346 | bool handle_netbios_aliases(struct loadparm_context *lp_ctx, struct loadparm_service *service,
|
---|
1347 | const char *pszParmValue, char **ptr)
|
---|
1348 | {
|
---|
1349 | TALLOC_FREE(lp_ctx->globals->netbios_aliases);
|
---|
1350 | lp_ctx->globals->netbios_aliases = str_list_make_v3_const(lp_ctx->globals->ctx,
|
---|
1351 | pszParmValue, NULL);
|
---|
1352 |
|
---|
1353 | if (lp_ctx->s3_fns) {
|
---|
1354 | return lp_ctx->s3_fns->set_netbios_aliases(lp_ctx->globals->netbios_aliases);
|
---|
1355 | }
|
---|
1356 | return true;
|
---|
1357 | }
|
---|
1358 |
|
---|
1359 | /*
|
---|
1360 | * idmap related parameters
|
---|
1361 | */
|
---|
1362 |
|
---|
1363 | bool handle_idmap_backend(struct loadparm_context *lp_ctx, struct loadparm_service *service,
|
---|
1364 | const char *pszParmValue, char **ptr)
|
---|
1365 | {
|
---|
1366 | if (lp_ctx->s3_fns) {
|
---|
1367 | lp_do_parameter_parametric(lp_ctx, service, "idmap config * : backend",
|
---|
1368 | pszParmValue, 0);
|
---|
1369 | }
|
---|
1370 |
|
---|
1371 | return lpcfg_string_set(lp_ctx->globals->ctx, ptr, pszParmValue);
|
---|
1372 | }
|
---|
1373 |
|
---|
1374 | bool handle_idmap_uid(struct loadparm_context *lp_ctx, struct loadparm_service *service,
|
---|
1375 | const char *pszParmValue, char **ptr)
|
---|
1376 | {
|
---|
1377 | if (lp_ctx->s3_fns) {
|
---|
1378 | lp_do_parameter_parametric(lp_ctx, service, "idmap config * : range",
|
---|
1379 | pszParmValue, 0);
|
---|
1380 | }
|
---|
1381 |
|
---|
1382 | return lpcfg_string_set(lp_ctx->globals->ctx, ptr, pszParmValue);
|
---|
1383 | }
|
---|
1384 |
|
---|
1385 | bool handle_idmap_gid(struct loadparm_context *lp_ctx, struct loadparm_service *service,
|
---|
1386 | const char *pszParmValue, char **ptr)
|
---|
1387 | {
|
---|
1388 | if (lp_ctx->s3_fns) {
|
---|
1389 | lp_do_parameter_parametric(lp_ctx, service, "idmap config * : range",
|
---|
1390 | pszParmValue, 0);
|
---|
1391 | }
|
---|
1392 |
|
---|
1393 | return lpcfg_string_set(lp_ctx->globals->ctx, ptr, pszParmValue);
|
---|
1394 | }
|
---|
1395 |
|
---|
1396 | bool handle_smb_ports(struct loadparm_context *lp_ctx, struct loadparm_service *service,
|
---|
1397 | const char *pszParmValue, char **ptr)
|
---|
1398 | {
|
---|
1399 | static int parm_num = -1;
|
---|
1400 | int i;
|
---|
1401 | const char **list;
|
---|
1402 |
|
---|
1403 | if (!pszParmValue || !*pszParmValue) {
|
---|
1404 | return false;
|
---|
1405 | }
|
---|
1406 |
|
---|
1407 | if (parm_num == -1) {
|
---|
1408 | parm_num = lpcfg_map_parameter("smb ports");
|
---|
1409 | if (parm_num == -1) {
|
---|
1410 | return false;
|
---|
1411 | }
|
---|
1412 | }
|
---|
1413 |
|
---|
1414 | if(!set_variable_helper(lp_ctx->globals->ctx, parm_num, ptr, "smb ports",
|
---|
1415 | pszParmValue)) {
|
---|
1416 | return false;
|
---|
1417 | }
|
---|
1418 |
|
---|
1419 | list = lp_ctx->globals->smb_ports;
|
---|
1420 | if (list == NULL) {
|
---|
1421 | return false;
|
---|
1422 | }
|
---|
1423 |
|
---|
1424 | /* Check that each port is a valid integer and within range */
|
---|
1425 | for (i = 0; list[i] != NULL; i++) {
|
---|
1426 | char *end = NULL;
|
---|
1427 | int port = 0;
|
---|
1428 | port = strtol(list[i], &end, 10);
|
---|
1429 | if (*end != '\0' || port <= 0 || port > 65535) {
|
---|
1430 | TALLOC_FREE(list);
|
---|
1431 | return false;
|
---|
1432 | }
|
---|
1433 | }
|
---|
1434 |
|
---|
1435 | return true;
|
---|
1436 | }
|
---|
1437 |
|
---|
1438 | bool handle_smb2_max_credits(struct loadparm_context *lp_ctx,
|
---|
1439 | struct loadparm_service *service,
|
---|
1440 | const char *pszParmValue, char **ptr)
|
---|
1441 | {
|
---|
1442 | int value = lp_int(pszParmValue);
|
---|
1443 |
|
---|
1444 | if (value <= 0) {
|
---|
1445 | value = DEFAULT_SMB2_MAX_CREDITS;
|
---|
1446 | }
|
---|
1447 |
|
---|
1448 | *(int *)ptr = value;
|
---|
1449 |
|
---|
1450 | return true;
|
---|
1451 | }
|
---|
1452 |
|
---|
1453 | bool handle_cups_encrypt(struct loadparm_context *lp_ctx,
|
---|
1454 | struct loadparm_service *service,
|
---|
1455 | const char *pszParmValue, char **ptr)
|
---|
1456 | {
|
---|
1457 | int result = 0;
|
---|
1458 | #ifdef HAVE_HTTPCONNECTENCRYPT
|
---|
1459 | int value = lp_int(pszParmValue);
|
---|
1460 |
|
---|
1461 | switch (value) {
|
---|
1462 | case Auto:
|
---|
1463 | result = HTTP_ENCRYPT_REQUIRED;
|
---|
1464 | break;
|
---|
1465 | case true:
|
---|
1466 | result = HTTP_ENCRYPT_ALWAYS;
|
---|
1467 | break;
|
---|
1468 | case false:
|
---|
1469 | result = HTTP_ENCRYPT_NEVER;
|
---|
1470 | break;
|
---|
1471 | default:
|
---|
1472 | result = 0;
|
---|
1473 | break;
|
---|
1474 | }
|
---|
1475 | #endif
|
---|
1476 | *(int *)ptr = result;
|
---|
1477 |
|
---|
1478 | return true;
|
---|
1479 | }
|
---|
1480 |
|
---|
1481 | /***************************************************************************
|
---|
1482 | Initialise a copymap.
|
---|
1483 | ***************************************************************************/
|
---|
1484 |
|
---|
1485 | /**
|
---|
1486 | * Initializes service copymap
|
---|
1487 | * Note: pservice *must* be valid TALLOC_CTX
|
---|
1488 | */
|
---|
1489 | void init_copymap(struct loadparm_service *pservice)
|
---|
1490 | {
|
---|
1491 | int i;
|
---|
1492 |
|
---|
1493 | TALLOC_FREE(pservice->copymap);
|
---|
1494 |
|
---|
1495 | pservice->copymap = bitmap_talloc(pservice, num_parameters());
|
---|
1496 | if (!pservice->copymap) {
|
---|
1497 | DEBUG(0,
|
---|
1498 | ("Couldn't allocate copymap!! (size %d)\n",
|
---|
1499 | (int)num_parameters()));
|
---|
1500 | } else {
|
---|
1501 | for (i = 0; i < num_parameters(); i++) {
|
---|
1502 | bitmap_set(pservice->copymap, i);
|
---|
1503 | }
|
---|
1504 | }
|
---|
1505 | }
|
---|
1506 |
|
---|
1507 | /**
|
---|
1508 | * Process a parametric option
|
---|
1509 | */
|
---|
1510 | static bool lp_do_parameter_parametric(struct loadparm_context *lp_ctx,
|
---|
1511 | struct loadparm_service *service,
|
---|
1512 | const char *pszParmName,
|
---|
1513 | const char *pszParmValue, int flags)
|
---|
1514 | {
|
---|
1515 | struct parmlist_entry **data;
|
---|
1516 | char *name;
|
---|
1517 | TALLOC_CTX *mem_ctx;
|
---|
1518 |
|
---|
1519 | while (isspace((unsigned char)*pszParmName)) {
|
---|
1520 | pszParmName++;
|
---|
1521 | }
|
---|
1522 |
|
---|
1523 | name = strlower_talloc(lp_ctx, pszParmName);
|
---|
1524 | if (!name) return false;
|
---|
1525 |
|
---|
1526 | if (service == NULL) {
|
---|
1527 | data = &lp_ctx->globals->param_opt;
|
---|
1528 | /**
|
---|
1529 | * s3 code cannot deal with parametric options stored on the globals ctx.
|
---|
1530 | */
|
---|
1531 | if (lp_ctx->s3_fns != NULL) {
|
---|
1532 | mem_ctx = NULL;
|
---|
1533 | } else {
|
---|
1534 | mem_ctx = lp_ctx->globals->ctx;
|
---|
1535 | }
|
---|
1536 | } else {
|
---|
1537 | data = &service->param_opt;
|
---|
1538 | mem_ctx = service;
|
---|
1539 | }
|
---|
1540 |
|
---|
1541 | set_param_opt(mem_ctx, data, name, pszParmValue, flags);
|
---|
1542 |
|
---|
1543 | talloc_free(name);
|
---|
1544 |
|
---|
1545 | return true;
|
---|
1546 | }
|
---|
1547 |
|
---|
1548 | static bool set_variable_helper(TALLOC_CTX *mem_ctx, int parmnum, void *parm_ptr,
|
---|
1549 | const char *pszParmName, const char *pszParmValue)
|
---|
1550 | {
|
---|
1551 | int i;
|
---|
1552 |
|
---|
1553 | /* switch on the type of variable it is */
|
---|
1554 | switch (parm_table[parmnum].type)
|
---|
1555 | {
|
---|
1556 | case P_BOOL: {
|
---|
1557 | bool b;
|
---|
1558 | if (!set_boolean(pszParmValue, &b)) {
|
---|
1559 | DEBUG(0, ("set_variable_helper(%s): value is not "
|
---|
1560 | "boolean!\n", pszParmValue));
|
---|
1561 | return false;
|
---|
1562 | }
|
---|
1563 | *(bool *)parm_ptr = b;
|
---|
1564 | }
|
---|
1565 | break;
|
---|
1566 |
|
---|
1567 | case P_BOOLREV: {
|
---|
1568 | bool b;
|
---|
1569 | if (!set_boolean(pszParmValue, &b)) {
|
---|
1570 | DEBUG(0, ("set_variable_helper(%s): value is not "
|
---|
1571 | "boolean!\n", pszParmValue));
|
---|
1572 | return false;
|
---|
1573 | }
|
---|
1574 | *(bool *)parm_ptr = !b;
|
---|
1575 | }
|
---|
1576 | break;
|
---|
1577 |
|
---|
1578 | case P_INTEGER:
|
---|
1579 | *(int *)parm_ptr = lp_int(pszParmValue);
|
---|
1580 | break;
|
---|
1581 |
|
---|
1582 | case P_CHAR:
|
---|
1583 | *(char *)parm_ptr = *pszParmValue;
|
---|
1584 | break;
|
---|
1585 |
|
---|
1586 | case P_OCTAL:
|
---|
1587 | i = sscanf(pszParmValue, "%o", (int *)parm_ptr);
|
---|
1588 | if ( i != 1 ) {
|
---|
1589 | DEBUG ( 0, ("Invalid octal number %s\n", pszParmName ));
|
---|
1590 | return false;
|
---|
1591 | }
|
---|
1592 | break;
|
---|
1593 |
|
---|
1594 | case P_BYTES:
|
---|
1595 | {
|
---|
1596 | uint64_t val;
|
---|
1597 | if (conv_str_size_error(pszParmValue, &val)) {
|
---|
1598 | if (val <= INT_MAX) {
|
---|
1599 | *(int *)parm_ptr = (int)val;
|
---|
1600 | break;
|
---|
1601 | }
|
---|
1602 | }
|
---|
1603 |
|
---|
1604 | DEBUG(0, ("set_variable_helper(%s): value is not "
|
---|
1605 | "a valid size specifier!\n", pszParmValue));
|
---|
1606 | return false;
|
---|
1607 | }
|
---|
1608 |
|
---|
1609 | case P_CMDLIST:
|
---|
1610 | TALLOC_FREE(*(char ***)parm_ptr);
|
---|
1611 | *(char ***)parm_ptr = str_list_make_v3(mem_ctx,
|
---|
1612 | pszParmValue, NULL);
|
---|
1613 | break;
|
---|
1614 |
|
---|
1615 | case P_LIST:
|
---|
1616 | {
|
---|
1617 | char **new_list = str_list_make_v3(mem_ctx,
|
---|
1618 | pszParmValue, NULL);
|
---|
1619 | if (new_list == NULL) {
|
---|
1620 | break;
|
---|
1621 | }
|
---|
1622 |
|
---|
1623 | for (i=0; new_list[i]; i++) {
|
---|
1624 | if (*(const char ***)parm_ptr != NULL &&
|
---|
1625 | new_list[i][0] == '+' &&
|
---|
1626 | new_list[i][1])
|
---|
1627 | {
|
---|
1628 | if (!str_list_check(*(const char ***)parm_ptr,
|
---|
1629 | &new_list[i][1])) {
|
---|
1630 | *(const char ***)parm_ptr = str_list_add(*(const char ***)parm_ptr,
|
---|
1631 | &new_list[i][1]);
|
---|
1632 | }
|
---|
1633 | } else if (*(const char ***)parm_ptr != NULL &&
|
---|
1634 | new_list[i][0] == '-' &&
|
---|
1635 | new_list[i][1])
|
---|
1636 | {
|
---|
1637 | str_list_remove(*(const char ***)parm_ptr,
|
---|
1638 | &new_list[i][1]);
|
---|
1639 | } else {
|
---|
1640 | if (i != 0) {
|
---|
1641 | DEBUG(0, ("Unsupported list syntax for: %s = %s\n",
|
---|
1642 | pszParmName, pszParmValue));
|
---|
1643 | return false;
|
---|
1644 | }
|
---|
1645 | *(char ***)parm_ptr = new_list;
|
---|
1646 | break;
|
---|
1647 | }
|
---|
1648 | }
|
---|
1649 | break;
|
---|
1650 | }
|
---|
1651 |
|
---|
1652 | case P_STRING:
|
---|
1653 | lpcfg_string_set(mem_ctx, (char **)parm_ptr, pszParmValue);
|
---|
1654 | break;
|
---|
1655 |
|
---|
1656 | case P_USTRING:
|
---|
1657 | lpcfg_string_set_upper(mem_ctx, (char **)parm_ptr, pszParmValue);
|
---|
1658 | break;
|
---|
1659 |
|
---|
1660 | case P_ENUM:
|
---|
1661 | if (!lp_set_enum_parm(&parm_table[parmnum], pszParmValue, (int*)parm_ptr)) {
|
---|
1662 | return false;
|
---|
1663 | }
|
---|
1664 | break;
|
---|
1665 |
|
---|
1666 | }
|
---|
1667 |
|
---|
1668 | return true;
|
---|
1669 |
|
---|
1670 | }
|
---|
1671 |
|
---|
1672 | static bool set_variable(TALLOC_CTX *mem_ctx, struct loadparm_service *service,
|
---|
1673 | int parmnum, void *parm_ptr,
|
---|
1674 | const char *pszParmName, const char *pszParmValue,
|
---|
1675 | struct loadparm_context *lp_ctx, bool on_globals)
|
---|
1676 | {
|
---|
1677 | int i;
|
---|
1678 | bool ok;
|
---|
1679 |
|
---|
1680 | /* if it is a special case then go ahead */
|
---|
1681 | if (parm_table[parmnum].special) {
|
---|
1682 | ok = parm_table[parmnum].special(lp_ctx, service, pszParmValue,
|
---|
1683 | (char **)parm_ptr);
|
---|
1684 | } else {
|
---|
1685 | ok = set_variable_helper(mem_ctx, parmnum, parm_ptr,
|
---|
1686 | pszParmName, pszParmValue);
|
---|
1687 | }
|
---|
1688 |
|
---|
1689 | if (!ok) {
|
---|
1690 | return false;
|
---|
1691 | }
|
---|
1692 |
|
---|
1693 | if (on_globals && (lp_ctx->flags[parmnum] & FLAG_DEFAULT)) {
|
---|
1694 | lp_ctx->flags[parmnum] &= ~FLAG_DEFAULT;
|
---|
1695 | /* we have to also unset FLAG_DEFAULT on aliases */
|
---|
1696 | for (i=parmnum-1;i>=0 && parm_table[i].offset == parm_table[parmnum].offset;i--) {
|
---|
1697 | lp_ctx->flags[i] &= ~FLAG_DEFAULT;
|
---|
1698 | }
|
---|
1699 | for (i=parmnum+1;i<num_parameters() && parm_table[i].offset == parm_table[parmnum].offset;i++) {
|
---|
1700 | lp_ctx->flags[i] &= ~FLAG_DEFAULT;
|
---|
1701 | }
|
---|
1702 | }
|
---|
1703 | return true;
|
---|
1704 | }
|
---|
1705 |
|
---|
1706 |
|
---|
1707 | bool lpcfg_do_global_parameter(struct loadparm_context *lp_ctx,
|
---|
1708 | const char *pszParmName, const char *pszParmValue)
|
---|
1709 | {
|
---|
1710 | int parmnum = lpcfg_map_parameter(pszParmName);
|
---|
1711 | void *parm_ptr;
|
---|
1712 |
|
---|
1713 | if (parmnum < 0) {
|
---|
1714 | if (strchr(pszParmName, ':')) {
|
---|
1715 | return lp_do_parameter_parametric(lp_ctx, NULL, pszParmName, pszParmValue, 0);
|
---|
1716 | }
|
---|
1717 | DEBUG(0, ("Ignoring unknown parameter \"%s\"\n", pszParmName));
|
---|
1718 | return true;
|
---|
1719 | }
|
---|
1720 |
|
---|
1721 | /* if the flag has been set on the command line, then don't allow override,
|
---|
1722 | but don't report an error */
|
---|
1723 | if (lp_ctx->flags[parmnum] & FLAG_CMDLINE) {
|
---|
1724 | return true;
|
---|
1725 | }
|
---|
1726 |
|
---|
1727 | if (parm_table[parmnum].flags & FLAG_DEPRECATED) {
|
---|
1728 | DEBUG(1, ("WARNING: The \"%s\" option is deprecated\n",
|
---|
1729 | pszParmName));
|
---|
1730 | }
|
---|
1731 |
|
---|
1732 | parm_ptr = lpcfg_parm_ptr(lp_ctx, NULL, &parm_table[parmnum]);
|
---|
1733 |
|
---|
1734 | return set_variable(lp_ctx->globals->ctx, NULL, parmnum, parm_ptr,
|
---|
1735 | pszParmName, pszParmValue, lp_ctx, true);
|
---|
1736 | }
|
---|
1737 |
|
---|
1738 | bool lpcfg_do_service_parameter(struct loadparm_context *lp_ctx,
|
---|
1739 | struct loadparm_service *service,
|
---|
1740 | const char *pszParmName, const char *pszParmValue)
|
---|
1741 | {
|
---|
1742 | void *parm_ptr;
|
---|
1743 | int i;
|
---|
1744 | int parmnum = lpcfg_map_parameter(pszParmName);
|
---|
1745 |
|
---|
1746 | if (parmnum < 0) {
|
---|
1747 | if (strchr(pszParmName, ':')) {
|
---|
1748 | return lp_do_parameter_parametric(lp_ctx, service, pszParmName, pszParmValue, 0);
|
---|
1749 | }
|
---|
1750 | DEBUG(0, ("Ignoring unknown parameter \"%s\"\n", pszParmName));
|
---|
1751 | return true;
|
---|
1752 | }
|
---|
1753 |
|
---|
1754 | /* if the flag has been set on the command line, then don't allow override,
|
---|
1755 | but don't report an error */
|
---|
1756 | if (lp_ctx->flags[parmnum] & FLAG_CMDLINE) {
|
---|
1757 | return true;
|
---|
1758 | }
|
---|
1759 |
|
---|
1760 | if (parm_table[parmnum].flags & FLAG_DEPRECATED) {
|
---|
1761 | DEBUG(1, ("WARNING: The \"%s\" option is deprecated\n",
|
---|
1762 | pszParmName));
|
---|
1763 | }
|
---|
1764 |
|
---|
1765 | if (parm_table[parmnum].p_class == P_GLOBAL) {
|
---|
1766 | DEBUG(0,
|
---|
1767 | ("Global parameter %s found in service section!\n",
|
---|
1768 | pszParmName));
|
---|
1769 | return true;
|
---|
1770 | }
|
---|
1771 | parm_ptr = ((char *)service) + parm_table[parmnum].offset;
|
---|
1772 |
|
---|
1773 | if (!service->copymap)
|
---|
1774 | init_copymap(service);
|
---|
1775 |
|
---|
1776 | /* this handles the aliases - set the copymap for other
|
---|
1777 | * entries with the same data pointer */
|
---|
1778 | for (i = 0; parm_table[i].label; i++)
|
---|
1779 | if (parm_table[i].offset == parm_table[parmnum].offset &&
|
---|
1780 | parm_table[i].p_class == parm_table[parmnum].p_class)
|
---|
1781 | bitmap_clear(service->copymap, i);
|
---|
1782 |
|
---|
1783 | return set_variable(service, service, parmnum, parm_ptr, pszParmName,
|
---|
1784 | pszParmValue, lp_ctx, false);
|
---|
1785 | }
|
---|
1786 |
|
---|
1787 | /**
|
---|
1788 | * Process a parameter.
|
---|
1789 | */
|
---|
1790 |
|
---|
1791 | bool lpcfg_do_parameter(const char *pszParmName, const char *pszParmValue,
|
---|
1792 | void *userdata)
|
---|
1793 | {
|
---|
1794 | struct loadparm_context *lp_ctx = (struct loadparm_context *)userdata;
|
---|
1795 |
|
---|
1796 | if (lp_ctx->bInGlobalSection)
|
---|
1797 | return lpcfg_do_global_parameter(lp_ctx, pszParmName,
|
---|
1798 | pszParmValue);
|
---|
1799 | else
|
---|
1800 | return lpcfg_do_service_parameter(lp_ctx, lp_ctx->currentService,
|
---|
1801 | pszParmName, pszParmValue);
|
---|
1802 | }
|
---|
1803 |
|
---|
1804 | /*
|
---|
1805 | variable argument do parameter
|
---|
1806 | */
|
---|
1807 | bool lpcfg_do_global_parameter_var(struct loadparm_context *lp_ctx, const char *pszParmName, const char *fmt, ...) PRINTF_ATTRIBUTE(3, 4);
|
---|
1808 | bool lpcfg_do_global_parameter_var(struct loadparm_context *lp_ctx,
|
---|
1809 | const char *pszParmName, const char *fmt, ...)
|
---|
1810 | {
|
---|
1811 | char *s;
|
---|
1812 | bool ret;
|
---|
1813 | va_list ap;
|
---|
1814 |
|
---|
1815 | va_start(ap, fmt);
|
---|
1816 | s = talloc_vasprintf(NULL, fmt, ap);
|
---|
1817 | va_end(ap);
|
---|
1818 | ret = lpcfg_do_global_parameter(lp_ctx, pszParmName, s);
|
---|
1819 | talloc_free(s);
|
---|
1820 | return ret;
|
---|
1821 | }
|
---|
1822 |
|
---|
1823 |
|
---|
1824 | /*
|
---|
1825 | set a parameter from the commandline - this is called from command line parameter
|
---|
1826 | parsing code. It sets the parameter then marks the parameter as unable to be modified
|
---|
1827 | by smb.conf processing
|
---|
1828 | */
|
---|
1829 | bool lpcfg_set_cmdline(struct loadparm_context *lp_ctx, const char *pszParmName,
|
---|
1830 | const char *pszParmValue)
|
---|
1831 | {
|
---|
1832 | int parmnum;
|
---|
1833 | int i;
|
---|
1834 |
|
---|
1835 | while (isspace((unsigned char)*pszParmValue)) pszParmValue++;
|
---|
1836 |
|
---|
1837 | parmnum = lpcfg_map_parameter(pszParmName);
|
---|
1838 |
|
---|
1839 | if (parmnum < 0 && strchr(pszParmName, ':')) {
|
---|
1840 | /* set a parametric option */
|
---|
1841 | bool ok;
|
---|
1842 | ok = lp_do_parameter_parametric(lp_ctx, NULL, pszParmName,
|
---|
1843 | pszParmValue, FLAG_CMDLINE);
|
---|
1844 | if (lp_ctx->s3_fns != NULL) {
|
---|
1845 | if (ok) {
|
---|
1846 | lp_ctx->s3_fns->store_cmdline(pszParmName, pszParmValue);
|
---|
1847 | }
|
---|
1848 | }
|
---|
1849 | return ok;
|
---|
1850 | }
|
---|
1851 |
|
---|
1852 | if (parmnum < 0) {
|
---|
1853 | DEBUG(0,("Unknown option '%s'\n", pszParmName));
|
---|
1854 | return false;
|
---|
1855 | }
|
---|
1856 |
|
---|
1857 | /* reset the CMDLINE flag in case this has been called before */
|
---|
1858 | lp_ctx->flags[parmnum] &= ~FLAG_CMDLINE;
|
---|
1859 |
|
---|
1860 | if (!lpcfg_do_global_parameter(lp_ctx, pszParmName, pszParmValue)) {
|
---|
1861 | return false;
|
---|
1862 | }
|
---|
1863 |
|
---|
1864 | lp_ctx->flags[parmnum] |= FLAG_CMDLINE;
|
---|
1865 |
|
---|
1866 | /* we have to also set FLAG_CMDLINE on aliases */
|
---|
1867 | for (i=parmnum-1;
|
---|
1868 | i>=0 && parm_table[i].p_class == parm_table[parmnum].p_class &&
|
---|
1869 | parm_table[i].offset == parm_table[parmnum].offset;
|
---|
1870 | i--) {
|
---|
1871 | lp_ctx->flags[i] |= FLAG_CMDLINE;
|
---|
1872 | }
|
---|
1873 | for (i=parmnum+1;
|
---|
1874 | i<num_parameters() &&
|
---|
1875 | parm_table[i].p_class == parm_table[parmnum].p_class &&
|
---|
1876 | parm_table[i].offset == parm_table[parmnum].offset;
|
---|
1877 | i++) {
|
---|
1878 | lp_ctx->flags[i] |= FLAG_CMDLINE;
|
---|
1879 | }
|
---|
1880 |
|
---|
1881 | if (lp_ctx->s3_fns != NULL) {
|
---|
1882 | lp_ctx->s3_fns->store_cmdline(pszParmName, pszParmValue);
|
---|
1883 | }
|
---|
1884 |
|
---|
1885 | return true;
|
---|
1886 | }
|
---|
1887 |
|
---|
1888 | /*
|
---|
1889 | set a option from the commandline in 'a=b' format. Use to support --option
|
---|
1890 | */
|
---|
1891 | bool lpcfg_set_option(struct loadparm_context *lp_ctx, const char *option)
|
---|
1892 | {
|
---|
1893 | char *p, *s;
|
---|
1894 | bool ret;
|
---|
1895 |
|
---|
1896 | s = talloc_strdup(NULL, option);
|
---|
1897 | if (!s) {
|
---|
1898 | return false;
|
---|
1899 | }
|
---|
1900 |
|
---|
1901 | p = strchr(s, '=');
|
---|
1902 | if (!p) {
|
---|
1903 | talloc_free(s);
|
---|
1904 | return false;
|
---|
1905 | }
|
---|
1906 |
|
---|
1907 | *p = 0;
|
---|
1908 |
|
---|
1909 | ret = lpcfg_set_cmdline(lp_ctx, s, p+1);
|
---|
1910 | talloc_free(s);
|
---|
1911 | return ret;
|
---|
1912 | }
|
---|
1913 |
|
---|
1914 |
|
---|
1915 | #define BOOLSTR(b) ((b) ? "Yes" : "No")
|
---|
1916 |
|
---|
1917 | /**
|
---|
1918 | * Print a parameter of the specified type.
|
---|
1919 | */
|
---|
1920 |
|
---|
1921 | void lpcfg_print_parameter(struct parm_struct *p, void *ptr, FILE * f)
|
---|
1922 | {
|
---|
1923 | /* For the seperation of lists values that we print below */
|
---|
1924 | const char *list_sep = ", ";
|
---|
1925 | int i;
|
---|
1926 | switch (p->type)
|
---|
1927 | {
|
---|
1928 | case P_ENUM:
|
---|
1929 | for (i = 0; p->enum_list[i].name; i++) {
|
---|
1930 | if (*(int *)ptr == p->enum_list[i].value) {
|
---|
1931 | fprintf(f, "%s",
|
---|
1932 | p->enum_list[i].name);
|
---|
1933 | break;
|
---|
1934 | }
|
---|
1935 | }
|
---|
1936 | break;
|
---|
1937 |
|
---|
1938 | case P_BOOL:
|
---|
1939 | fprintf(f, "%s", BOOLSTR(*(bool *)ptr));
|
---|
1940 | break;
|
---|
1941 |
|
---|
1942 | case P_BOOLREV:
|
---|
1943 | fprintf(f, "%s", BOOLSTR(!*(bool *)ptr));
|
---|
1944 | break;
|
---|
1945 |
|
---|
1946 | case P_INTEGER:
|
---|
1947 | case P_BYTES:
|
---|
1948 | fprintf(f, "%d", *(int *)ptr);
|
---|
1949 | break;
|
---|
1950 |
|
---|
1951 | case P_CHAR:
|
---|
1952 | fprintf(f, "%c", *(char *)ptr);
|
---|
1953 | break;
|
---|
1954 |
|
---|
1955 | case P_OCTAL: {
|
---|
1956 | int val = *(int *)ptr;
|
---|
1957 | if (val == -1) {
|
---|
1958 | fprintf(f, "-1");
|
---|
1959 | } else {
|
---|
1960 | fprintf(f, "0%03o", val);
|
---|
1961 | }
|
---|
1962 | break;
|
---|
1963 | }
|
---|
1964 |
|
---|
1965 | case P_CMDLIST:
|
---|
1966 | list_sep = " ";
|
---|
1967 | /* fall through */
|
---|
1968 | case P_LIST:
|
---|
1969 | if ((char ***)ptr && *(char ***)ptr) {
|
---|
1970 | char **list = *(char ***)ptr;
|
---|
1971 | for (; *list; list++) {
|
---|
1972 | /* surround strings with whitespace in double quotes */
|
---|
1973 | if (*(list+1) == NULL) {
|
---|
1974 | /* last item, no extra separator */
|
---|
1975 | list_sep = "";
|
---|
1976 | }
|
---|
1977 | if ( strchr_m( *list, ' ' ) ) {
|
---|
1978 | fprintf(f, "\"%s\"%s", *list, list_sep);
|
---|
1979 | } else {
|
---|
1980 | fprintf(f, "%s%s", *list, list_sep);
|
---|
1981 | }
|
---|
1982 | }
|
---|
1983 | }
|
---|
1984 | break;
|
---|
1985 |
|
---|
1986 | case P_STRING:
|
---|
1987 | case P_USTRING:
|
---|
1988 | if (*(char **)ptr) {
|
---|
1989 | fprintf(f, "%s", *(char **)ptr);
|
---|
1990 | }
|
---|
1991 | break;
|
---|
1992 | }
|
---|
1993 | }
|
---|
1994 |
|
---|
1995 | /**
|
---|
1996 | * Check if two parameters are equal.
|
---|
1997 | */
|
---|
1998 |
|
---|
1999 | static bool lpcfg_equal_parameter(parm_type type, void *ptr1, void *ptr2)
|
---|
2000 | {
|
---|
2001 | switch (type) {
|
---|
2002 | case P_BOOL:
|
---|
2003 | case P_BOOLREV:
|
---|
2004 | return (*((bool *)ptr1) == *((bool *)ptr2));
|
---|
2005 |
|
---|
2006 | case P_INTEGER:
|
---|
2007 | case P_ENUM:
|
---|
2008 | case P_OCTAL:
|
---|
2009 | case P_BYTES:
|
---|
2010 | return (*((int *)ptr1) == *((int *)ptr2));
|
---|
2011 |
|
---|
2012 | case P_CHAR:
|
---|
2013 | return (*((char *)ptr1) == *((char *)ptr2));
|
---|
2014 |
|
---|
2015 | case P_LIST:
|
---|
2016 | case P_CMDLIST:
|
---|
2017 | return str_list_equal(*(const char ***)ptr1, *(const char ***)ptr2);
|
---|
2018 |
|
---|
2019 | case P_STRING:
|
---|
2020 | case P_USTRING:
|
---|
2021 | {
|
---|
2022 | char *p1 = *(char **)ptr1, *p2 = *(char **)ptr2;
|
---|
2023 | if (p1 && !*p1)
|
---|
2024 | p1 = NULL;
|
---|
2025 | if (p2 && !*p2)
|
---|
2026 | p2 = NULL;
|
---|
2027 | return (p1 == p2 || strequal(p1, p2));
|
---|
2028 | }
|
---|
2029 | }
|
---|
2030 | return false;
|
---|
2031 | }
|
---|
2032 |
|
---|
2033 | /**
|
---|
2034 | * Process a new section (service).
|
---|
2035 | *
|
---|
2036 | * At this stage all sections are services.
|
---|
2037 | * Later we'll have special sections that permit server parameters to be set.
|
---|
2038 | * Returns True on success, False on failure.
|
---|
2039 | */
|
---|
2040 |
|
---|
2041 | static bool do_section(const char *pszSectionName, void *userdata)
|
---|
2042 | {
|
---|
2043 | struct loadparm_context *lp_ctx = (struct loadparm_context *)userdata;
|
---|
2044 | bool bRetval;
|
---|
2045 | bool isglobal;
|
---|
2046 |
|
---|
2047 | if (lp_ctx->s3_fns != NULL) {
|
---|
2048 | return lp_ctx->s3_fns->do_section(pszSectionName, lp_ctx);
|
---|
2049 | }
|
---|
2050 |
|
---|
2051 | isglobal = ((strwicmp(pszSectionName, GLOBAL_NAME) == 0) ||
|
---|
2052 | (strwicmp(pszSectionName, GLOBAL_NAME2) == 0));
|
---|
2053 |
|
---|
2054 | bRetval = false;
|
---|
2055 |
|
---|
2056 | /* if we've just struck a global section, note the fact. */
|
---|
2057 | lp_ctx->bInGlobalSection = isglobal;
|
---|
2058 |
|
---|
2059 | /* check for multiple global sections */
|
---|
2060 | if (lp_ctx->bInGlobalSection) {
|
---|
2061 | DEBUG(4, ("Processing section \"[%s]\"\n", pszSectionName));
|
---|
2062 | return true;
|
---|
2063 | }
|
---|
2064 |
|
---|
2065 | /* if we have a current service, tidy it up before moving on */
|
---|
2066 | bRetval = true;
|
---|
2067 |
|
---|
2068 | if (lp_ctx->currentService != NULL)
|
---|
2069 | bRetval = lpcfg_service_ok(lp_ctx->currentService);
|
---|
2070 |
|
---|
2071 | /* if all is still well, move to the next record in the services array */
|
---|
2072 | if (bRetval) {
|
---|
2073 | /* We put this here to avoid an odd message order if messages are */
|
---|
2074 | /* issued by the post-processing of a previous section. */
|
---|
2075 | DEBUG(4, ("Processing section \"[%s]\"\n", pszSectionName));
|
---|
2076 |
|
---|
2077 | if ((lp_ctx->currentService = lpcfg_add_service(lp_ctx, lp_ctx->sDefault,
|
---|
2078 | pszSectionName))
|
---|
2079 | == NULL) {
|
---|
2080 | DEBUG(0, ("Failed to add a new service\n"));
|
---|
2081 | return false;
|
---|
2082 | }
|
---|
2083 | }
|
---|
2084 |
|
---|
2085 | return bRetval;
|
---|
2086 | }
|
---|
2087 |
|
---|
2088 |
|
---|
2089 | /**
|
---|
2090 | * Determine if a particular base parameter is currently set to the default value.
|
---|
2091 | */
|
---|
2092 |
|
---|
2093 | static bool is_default(void *base_structure, int i)
|
---|
2094 | {
|
---|
2095 | void *def_ptr = ((char *)base_structure) + parm_table[i].offset;
|
---|
2096 | switch (parm_table[i].type) {
|
---|
2097 | case P_CMDLIST:
|
---|
2098 | case P_LIST:
|
---|
2099 | return str_list_equal((const char * const *)parm_table[i].def.lvalue,
|
---|
2100 | *(const char * const **)def_ptr);
|
---|
2101 | case P_STRING:
|
---|
2102 | case P_USTRING:
|
---|
2103 | return strequal(parm_table[i].def.svalue,
|
---|
2104 | *(char **)def_ptr);
|
---|
2105 | case P_BOOL:
|
---|
2106 | case P_BOOLREV:
|
---|
2107 | return parm_table[i].def.bvalue ==
|
---|
2108 | *(bool *)def_ptr;
|
---|
2109 | case P_INTEGER:
|
---|
2110 | case P_CHAR:
|
---|
2111 | case P_OCTAL:
|
---|
2112 | case P_BYTES:
|
---|
2113 | case P_ENUM:
|
---|
2114 | return parm_table[i].def.ivalue ==
|
---|
2115 | *(int *)def_ptr;
|
---|
2116 | }
|
---|
2117 | return false;
|
---|
2118 | }
|
---|
2119 |
|
---|
2120 | /**
|
---|
2121 | *Display the contents of the global structure.
|
---|
2122 | */
|
---|
2123 |
|
---|
2124 | void lpcfg_dump_globals(struct loadparm_context *lp_ctx, FILE *f,
|
---|
2125 | bool show_defaults)
|
---|
2126 | {
|
---|
2127 | int i;
|
---|
2128 | struct parmlist_entry *data;
|
---|
2129 |
|
---|
2130 | fprintf(f, "# Global parameters\n[global]\n");
|
---|
2131 |
|
---|
2132 | for (i = 0; parm_table[i].label; i++) {
|
---|
2133 | if (parm_table[i].p_class != P_GLOBAL) {
|
---|
2134 | continue;
|
---|
2135 | }
|
---|
2136 |
|
---|
2137 | if (parm_table[i].flags & FLAG_SYNONYM) {
|
---|
2138 | continue;
|
---|
2139 | }
|
---|
2140 |
|
---|
2141 | if (!show_defaults) {
|
---|
2142 | if (lp_ctx->flags && (lp_ctx->flags[i] & FLAG_DEFAULT)) {
|
---|
2143 | continue;
|
---|
2144 | }
|
---|
2145 |
|
---|
2146 | if (is_default(lp_ctx->globals, i)) {
|
---|
2147 | continue;
|
---|
2148 | }
|
---|
2149 | }
|
---|
2150 |
|
---|
2151 | fprintf(f, "\t%s = ", parm_table[i].label);
|
---|
2152 | lpcfg_print_parameter(&parm_table[i], lpcfg_parm_ptr(lp_ctx, NULL, &parm_table[i]), f);
|
---|
2153 | fprintf(f, "\n");
|
---|
2154 | }
|
---|
2155 | if (lp_ctx->globals->param_opt != NULL) {
|
---|
2156 | for (data = lp_ctx->globals->param_opt; data;
|
---|
2157 | data = data->next) {
|
---|
2158 | if (!show_defaults && (data->priority & FLAG_DEFAULT)) {
|
---|
2159 | continue;
|
---|
2160 | }
|
---|
2161 | fprintf(f, "\t%s = %s\n", data->key, data->value);
|
---|
2162 | }
|
---|
2163 | }
|
---|
2164 |
|
---|
2165 | }
|
---|
2166 |
|
---|
2167 | /**
|
---|
2168 | * Display the contents of a single services record.
|
---|
2169 | */
|
---|
2170 |
|
---|
2171 | void lpcfg_dump_a_service(struct loadparm_service * pService, struct loadparm_service *sDefault, FILE * f,
|
---|
2172 | unsigned int *flags, bool show_defaults)
|
---|
2173 | {
|
---|
2174 | int i;
|
---|
2175 | struct parmlist_entry *data;
|
---|
2176 |
|
---|
2177 | if (pService != sDefault)
|
---|
2178 | fprintf(f, "\n[%s]\n", pService->szService);
|
---|
2179 |
|
---|
2180 | for (i = 0; parm_table[i].label; i++) {
|
---|
2181 | if (parm_table[i].p_class != P_LOCAL) {
|
---|
2182 | continue;
|
---|
2183 | }
|
---|
2184 |
|
---|
2185 | if (parm_table[i].flags & FLAG_SYNONYM) {
|
---|
2186 | continue;
|
---|
2187 | }
|
---|
2188 |
|
---|
2189 | if (*parm_table[i].label == '-') {
|
---|
2190 | continue;
|
---|
2191 | }
|
---|
2192 |
|
---|
2193 | if (pService == sDefault) {
|
---|
2194 | if (!show_defaults) {
|
---|
2195 | if (flags && (flags[i] & FLAG_DEFAULT)) {
|
---|
2196 | continue;
|
---|
2197 | }
|
---|
2198 |
|
---|
2199 | if (is_default(sDefault, i)) {
|
---|
2200 | continue;
|
---|
2201 | }
|
---|
2202 | }
|
---|
2203 | } else {
|
---|
2204 | bool equal;
|
---|
2205 |
|
---|
2206 | equal = lpcfg_equal_parameter(parm_table[i].type,
|
---|
2207 | ((char *)pService) +
|
---|
2208 | parm_table[i].offset,
|
---|
2209 | ((char *)sDefault) +
|
---|
2210 | parm_table[i].offset);
|
---|
2211 | if (equal) {
|
---|
2212 | continue;
|
---|
2213 | }
|
---|
2214 | }
|
---|
2215 |
|
---|
2216 | fprintf(f, "\t%s = ", parm_table[i].label);
|
---|
2217 | lpcfg_print_parameter(&parm_table[i],
|
---|
2218 | ((char *)pService) + parm_table[i].offset, f);
|
---|
2219 | fprintf(f, "\n");
|
---|
2220 | }
|
---|
2221 | if (pService->param_opt != NULL) {
|
---|
2222 | for (data = pService->param_opt; data; data = data->next) {
|
---|
2223 | if (!show_defaults && (data->priority & FLAG_DEFAULT)) {
|
---|
2224 | continue;
|
---|
2225 | }
|
---|
2226 | fprintf(f, "\t%s = %s\n", data->key, data->value);
|
---|
2227 | }
|
---|
2228 | }
|
---|
2229 | }
|
---|
2230 |
|
---|
2231 | bool lpcfg_dump_a_parameter(struct loadparm_context *lp_ctx,
|
---|
2232 | struct loadparm_service *service,
|
---|
2233 | const char *parm_name, FILE * f)
|
---|
2234 | {
|
---|
2235 | struct parm_struct *parm;
|
---|
2236 | void *ptr;
|
---|
2237 | char *local_parm_name;
|
---|
2238 | char *parm_opt;
|
---|
2239 | const char *parm_opt_value;
|
---|
2240 |
|
---|
2241 | /* check for parametrical option */
|
---|
2242 | local_parm_name = talloc_strdup(lp_ctx, parm_name);
|
---|
2243 | if (local_parm_name == NULL) {
|
---|
2244 | return false;
|
---|
2245 | }
|
---|
2246 |
|
---|
2247 | parm_opt = strchr( local_parm_name, ':');
|
---|
2248 |
|
---|
2249 | if (parm_opt) {
|
---|
2250 | *parm_opt = '\0';
|
---|
2251 | parm_opt++;
|
---|
2252 | if (strlen(parm_opt)) {
|
---|
2253 | parm_opt_value = lpcfg_parm_string(lp_ctx, service,
|
---|
2254 | local_parm_name, parm_opt);
|
---|
2255 | if (parm_opt_value) {
|
---|
2256 | fprintf(f, "%s\n", parm_opt_value);
|
---|
2257 | return true;
|
---|
2258 | }
|
---|
2259 | }
|
---|
2260 | return false;
|
---|
2261 | }
|
---|
2262 |
|
---|
2263 | /* parameter is not parametric, search the table */
|
---|
2264 | parm = lpcfg_parm_struct(lp_ctx, parm_name);
|
---|
2265 | if (!parm) {
|
---|
2266 | return false;
|
---|
2267 | }
|
---|
2268 |
|
---|
2269 | if (service != NULL && parm->p_class == P_GLOBAL) {
|
---|
2270 | return false;
|
---|
2271 | }
|
---|
2272 |
|
---|
2273 | ptr = lpcfg_parm_ptr(lp_ctx, service,parm);
|
---|
2274 |
|
---|
2275 | lpcfg_print_parameter(parm, ptr, f);
|
---|
2276 | fprintf(f, "\n");
|
---|
2277 | return true;
|
---|
2278 | }
|
---|
2279 |
|
---|
2280 | /**
|
---|
2281 | * Auto-load some home services.
|
---|
2282 | */
|
---|
2283 | static void lpcfg_add_auto_services(struct loadparm_context *lp_ctx,
|
---|
2284 | const char *str)
|
---|
2285 | {
|
---|
2286 | return;
|
---|
2287 | }
|
---|
2288 |
|
---|
2289 | /***************************************************************************
|
---|
2290 | Initialise the sDefault parameter structure for the printer values.
|
---|
2291 | ***************************************************************************/
|
---|
2292 |
|
---|
2293 | void init_printer_values(struct loadparm_context *lp_ctx, TALLOC_CTX *ctx,
|
---|
2294 | struct loadparm_service *pService)
|
---|
2295 | {
|
---|
2296 | /* choose defaults depending on the type of printing */
|
---|
2297 | switch (pService->printing) {
|
---|
2298 | case PRINT_BSD:
|
---|
2299 | case PRINT_AIX:
|
---|
2300 | case PRINT_LPRNT:
|
---|
2301 | case PRINT_LPROS2:
|
---|
2302 | lpcfg_string_set(ctx, &pService->lpq_command, "lpq -P'%p'");
|
---|
2303 | lpcfg_string_set(ctx, &pService->lprm_command, "lprm -P'%p' %j");
|
---|
2304 | lpcfg_string_set(ctx, &pService->print_command, "lpr -r -P'%p' %s");
|
---|
2305 | break;
|
---|
2306 |
|
---|
2307 | case PRINT_LPRNG:
|
---|
2308 | case PRINT_PLP:
|
---|
2309 | lpcfg_string_set(ctx, &pService->lpq_command, "lpq -P'%p'");
|
---|
2310 | lpcfg_string_set(ctx, &pService->lprm_command, "lprm -P'%p' %j");
|
---|
2311 | lpcfg_string_set(ctx, &pService->print_command, "lpr -r -P'%p' %s");
|
---|
2312 | lpcfg_string_set(ctx, &pService->queuepause_command, "lpc stop '%p'");
|
---|
2313 | lpcfg_string_set(ctx, &pService->queueresume_command, "lpc start '%p'");
|
---|
2314 | lpcfg_string_set(ctx, &pService->lppause_command, "lpc hold '%p' %j");
|
---|
2315 | lpcfg_string_set(ctx, &pService->lpresume_command, "lpc release '%p' %j");
|
---|
2316 | break;
|
---|
2317 |
|
---|
2318 | case PRINT_CUPS:
|
---|
2319 | case PRINT_IPRINT:
|
---|
2320 | /* set the lpq command to contain the destination printer
|
---|
2321 | name only. This is used by cups_queue_get() */
|
---|
2322 | lpcfg_string_set(ctx, &pService->lpq_command, "%p");
|
---|
2323 | lpcfg_string_set(ctx, &pService->lprm_command, "");
|
---|
2324 | lpcfg_string_set(ctx, &pService->print_command, "");
|
---|
2325 | lpcfg_string_set(ctx, &pService->lppause_command, "");
|
---|
2326 | lpcfg_string_set(ctx, &pService->lpresume_command, "");
|
---|
2327 | lpcfg_string_set(ctx, &pService->queuepause_command, "");
|
---|
2328 | lpcfg_string_set(ctx, &pService->queueresume_command, "");
|
---|
2329 | break;
|
---|
2330 |
|
---|
2331 | case PRINT_SYSV:
|
---|
2332 | case PRINT_HPUX:
|
---|
2333 | lpcfg_string_set(ctx, &pService->lpq_command, "lpstat -o%p");
|
---|
2334 | lpcfg_string_set(ctx, &pService->lprm_command, "cancel %p-%j");
|
---|
2335 | lpcfg_string_set(ctx, &pService->print_command, "lp -c -d%p %s; rm %s");
|
---|
2336 | lpcfg_string_set(ctx, &pService->queuepause_command, "disable %p");
|
---|
2337 | lpcfg_string_set(ctx, &pService->queueresume_command, "enable %p");
|
---|
2338 | #ifndef HPUX
|
---|
2339 | lpcfg_string_set(ctx, &pService->lppause_command, "lp -i %p-%j -H hold");
|
---|
2340 | lpcfg_string_set(ctx, &pService->lpresume_command, "lp -i %p-%j -H resume");
|
---|
2341 | #endif /* HPUX */
|
---|
2342 | break;
|
---|
2343 |
|
---|
2344 | case PRINT_QNX:
|
---|
2345 | lpcfg_string_set(ctx, &pService->lpq_command, "lpq -P%p");
|
---|
2346 | lpcfg_string_set(ctx, &pService->lprm_command, "lprm -P%p %j");
|
---|
2347 | lpcfg_string_set(ctx, &pService->print_command, "lp -r -P%p %s");
|
---|
2348 | break;
|
---|
2349 |
|
---|
2350 | #if defined(DEVELOPER) || defined(ENABLE_SELFTEST)
|
---|
2351 |
|
---|
2352 | case PRINT_TEST:
|
---|
2353 | case PRINT_VLP: {
|
---|
2354 | const char *tdbfile;
|
---|
2355 | TALLOC_CTX *tmp_ctx = talloc_new(ctx);
|
---|
2356 | const char *tmp;
|
---|
2357 |
|
---|
2358 | tmp = lpcfg_parm_string(lp_ctx, NULL, "vlp", "tdbfile");
|
---|
2359 | if (tmp == NULL) {
|
---|
2360 | tmp = "/tmp/vlp.tdb";
|
---|
2361 | }
|
---|
2362 |
|
---|
2363 | tdbfile = talloc_asprintf(tmp_ctx, "tdbfile=%s", tmp);
|
---|
2364 | if (tdbfile == NULL) {
|
---|
2365 | tdbfile="tdbfile=/tmp/vlp.tdb";
|
---|
2366 | }
|
---|
2367 |
|
---|
2368 | tmp = talloc_asprintf(tmp_ctx, "vlp %s print %%p %%s",
|
---|
2369 | tdbfile);
|
---|
2370 | lpcfg_string_set(ctx, &pService->print_command,
|
---|
2371 | tmp ? tmp : "vlp print %p %s");
|
---|
2372 |
|
---|
2373 | tmp = talloc_asprintf(tmp_ctx, "vlp %s lpq %%p",
|
---|
2374 | tdbfile);
|
---|
2375 | lpcfg_string_set(ctx, &pService->lpq_command,
|
---|
2376 | tmp ? tmp : "vlp lpq %p");
|
---|
2377 |
|
---|
2378 | tmp = talloc_asprintf(tmp_ctx, "vlp %s lprm %%p %%j",
|
---|
2379 | tdbfile);
|
---|
2380 | lpcfg_string_set(ctx, &pService->lprm_command,
|
---|
2381 | tmp ? tmp : "vlp lprm %p %j");
|
---|
2382 |
|
---|
2383 | tmp = talloc_asprintf(tmp_ctx, "vlp %s lppause %%p %%j",
|
---|
2384 | tdbfile);
|
---|
2385 | lpcfg_string_set(ctx, &pService->lppause_command,
|
---|
2386 | tmp ? tmp : "vlp lppause %p %j");
|
---|
2387 |
|
---|
2388 | tmp = talloc_asprintf(tmp_ctx, "vlp %s lpresume %%p %%j",
|
---|
2389 | tdbfile);
|
---|
2390 | lpcfg_string_set(ctx, &pService->lpresume_command,
|
---|
2391 | tmp ? tmp : "vlp lpresume %p %j");
|
---|
2392 |
|
---|
2393 | tmp = talloc_asprintf(tmp_ctx, "vlp %s queuepause %%p",
|
---|
2394 | tdbfile);
|
---|
2395 | lpcfg_string_set(ctx, &pService->queuepause_command,
|
---|
2396 | tmp ? tmp : "vlp queuepause %p");
|
---|
2397 |
|
---|
2398 | tmp = talloc_asprintf(tmp_ctx, "vlp %s queueresume %%p",
|
---|
2399 | tdbfile);
|
---|
2400 | lpcfg_string_set(ctx, &pService->queueresume_command,
|
---|
2401 | tmp ? tmp : "vlp queueresume %p");
|
---|
2402 | TALLOC_FREE(tmp_ctx);
|
---|
2403 |
|
---|
2404 | break;
|
---|
2405 | }
|
---|
2406 | #endif /* DEVELOPER */
|
---|
2407 |
|
---|
2408 | }
|
---|
2409 | }
|
---|
2410 |
|
---|
2411 | /**
|
---|
2412 | * Unload unused services.
|
---|
2413 | */
|
---|
2414 |
|
---|
2415 | void lpcfg_killunused(struct loadparm_context *lp_ctx,
|
---|
2416 | struct smbsrv_connection *smb,
|
---|
2417 | bool (*snumused) (struct smbsrv_connection *, int))
|
---|
2418 | {
|
---|
2419 | int i;
|
---|
2420 |
|
---|
2421 | if (lp_ctx->s3_fns != NULL) {
|
---|
2422 | smb_panic("Cannot be used from an s3 loadparm ctx");
|
---|
2423 | }
|
---|
2424 |
|
---|
2425 | for (i = 0; i < lp_ctx->iNumServices; i++) {
|
---|
2426 | if (lp_ctx->services[i] == NULL)
|
---|
2427 | continue;
|
---|
2428 |
|
---|
2429 | if (!snumused || !snumused(smb, i)) {
|
---|
2430 | talloc_free(lp_ctx->services[i]);
|
---|
2431 | lp_ctx->services[i] = NULL;
|
---|
2432 | }
|
---|
2433 | }
|
---|
2434 | }
|
---|
2435 |
|
---|
2436 |
|
---|
2437 | static int lpcfg_destructor(struct loadparm_context *lp_ctx)
|
---|
2438 | {
|
---|
2439 | struct parmlist_entry *data;
|
---|
2440 |
|
---|
2441 | if (lp_ctx->refuse_free) {
|
---|
2442 | /* someone is trying to free the
|
---|
2443 | global_loadparm_context.
|
---|
2444 | We can't allow that. */
|
---|
2445 | return -1;
|
---|
2446 | }
|
---|
2447 |
|
---|
2448 | if (lp_ctx->globals->param_opt != NULL) {
|
---|
2449 | struct parmlist_entry *next;
|
---|
2450 | for (data = lp_ctx->globals->param_opt; data; data=next) {
|
---|
2451 | next = data->next;
|
---|
2452 | if (data->priority & FLAG_CMDLINE) continue;
|
---|
2453 | DLIST_REMOVE(lp_ctx->globals->param_opt, data);
|
---|
2454 | talloc_free(data);
|
---|
2455 | }
|
---|
2456 | }
|
---|
2457 |
|
---|
2458 | return 0;
|
---|
2459 | }
|
---|
2460 |
|
---|
2461 | struct defaults_hook_data {
|
---|
2462 | const char *name;
|
---|
2463 | lpcfg_defaults_hook hook;
|
---|
2464 | struct defaults_hook_data *prev, *next;
|
---|
2465 | } *defaults_hooks = NULL;
|
---|
2466 |
|
---|
2467 |
|
---|
2468 | bool lpcfg_register_defaults_hook(const char *name, lpcfg_defaults_hook hook)
|
---|
2469 | {
|
---|
2470 | struct defaults_hook_data *hook_data = talloc(talloc_autofree_context(),
|
---|
2471 | struct defaults_hook_data);
|
---|
2472 | hook_data->name = talloc_strdup(hook_data, name);
|
---|
2473 | hook_data->hook = hook;
|
---|
2474 | DLIST_ADD(defaults_hooks, hook_data);
|
---|
2475 | return false;
|
---|
2476 | }
|
---|
2477 |
|
---|
2478 | /**
|
---|
2479 | * Initialise the global parameter structure.
|
---|
2480 | *
|
---|
2481 | * Note that most callers should use loadparm_init_global() instead
|
---|
2482 | */
|
---|
2483 | struct loadparm_context *loadparm_init(TALLOC_CTX *mem_ctx)
|
---|
2484 | {
|
---|
2485 | int i;
|
---|
2486 | char *myname;
|
---|
2487 | struct loadparm_context *lp_ctx;
|
---|
2488 | struct parmlist_entry *parm;
|
---|
2489 | char *logfile;
|
---|
2490 | struct defaults_hook_data *defaults_hook;
|
---|
2491 |
|
---|
2492 | lp_ctx = talloc_zero(mem_ctx, struct loadparm_context);
|
---|
2493 | if (lp_ctx == NULL)
|
---|
2494 | return NULL;
|
---|
2495 |
|
---|
2496 | talloc_set_destructor(lp_ctx, lpcfg_destructor);
|
---|
2497 | lp_ctx->bInGlobalSection = true;
|
---|
2498 | lp_ctx->globals = talloc_zero(lp_ctx, struct loadparm_global);
|
---|
2499 | /* This appears odd, but globals in s3 isn't a pointer */
|
---|
2500 | lp_ctx->globals->ctx = lp_ctx->globals;
|
---|
2501 | lp_ctx->sDefault = talloc_zero(lp_ctx, struct loadparm_service);
|
---|
2502 | lp_ctx->flags = talloc_zero_array(lp_ctx, unsigned int, num_parameters());
|
---|
2503 |
|
---|
2504 | lp_ctx->sDefault->max_print_jobs = 1000;
|
---|
2505 | lp_ctx->sDefault->available = true;
|
---|
2506 | lp_ctx->sDefault->browseable = true;
|
---|
2507 | lp_ctx->sDefault->read_only = true;
|
---|
2508 | lp_ctx->sDefault->map_archive = true;
|
---|
2509 | lp_ctx->sDefault->strict_locking = true;
|
---|
2510 | lp_ctx->sDefault->oplocks = true;
|
---|
2511 | lp_ctx->sDefault->create_mask = 0744;
|
---|
2512 | lp_ctx->sDefault->force_create_mode = 0000;
|
---|
2513 | lp_ctx->sDefault->directory_mask = 0755;
|
---|
2514 | lp_ctx->sDefault->force_directory_mode = 0000;
|
---|
2515 |
|
---|
2516 | DEBUG(3, ("Initialising global parameters\n"));
|
---|
2517 |
|
---|
2518 | for (i = 0; parm_table[i].label; i++) {
|
---|
2519 | if ((parm_table[i].type == P_STRING ||
|
---|
2520 | parm_table[i].type == P_USTRING) &&
|
---|
2521 | !(lp_ctx->flags[i] & FLAG_CMDLINE)) {
|
---|
2522 | TALLOC_CTX *parent_mem;
|
---|
2523 | char **r;
|
---|
2524 | if (parm_table[i].p_class == P_LOCAL) {
|
---|
2525 | parent_mem = lp_ctx->sDefault;
|
---|
2526 | r = (char **)(((char *)lp_ctx->sDefault) + parm_table[i].offset);
|
---|
2527 | } else {
|
---|
2528 | parent_mem = lp_ctx->globals;
|
---|
2529 | r = (char **)(((char *)lp_ctx->globals) + parm_table[i].offset);
|
---|
2530 | }
|
---|
2531 | lpcfg_string_set(parent_mem, r, "");
|
---|
2532 | }
|
---|
2533 | }
|
---|
2534 |
|
---|
2535 | logfile = talloc_asprintf(lp_ctx, "%s/log.samba", dyn_LOGFILEBASE);
|
---|
2536 | lpcfg_do_global_parameter(lp_ctx, "log file", logfile);
|
---|
2537 | talloc_free(logfile);
|
---|
2538 |
|
---|
2539 | lpcfg_do_global_parameter(lp_ctx, "log level", "0");
|
---|
2540 |
|
---|
2541 | lpcfg_do_global_parameter(lp_ctx, "syslog", "1");
|
---|
2542 | lpcfg_do_global_parameter(lp_ctx, "syslog only", "No");
|
---|
2543 | lpcfg_do_global_parameter(lp_ctx, "debug timestamp", "Yes");
|
---|
2544 | lpcfg_do_global_parameter(lp_ctx, "debug prefix timestamp", "No");
|
---|
2545 | lpcfg_do_global_parameter(lp_ctx, "debug hires timestamp", "Yes");
|
---|
2546 | lpcfg_do_global_parameter(lp_ctx, "debug pid", "No");
|
---|
2547 | lpcfg_do_global_parameter(lp_ctx, "debug uid", "No");
|
---|
2548 | lpcfg_do_global_parameter(lp_ctx, "debug class", "No");
|
---|
2549 |
|
---|
2550 | lpcfg_do_global_parameter(lp_ctx, "share backend", "classic");
|
---|
2551 |
|
---|
2552 | lpcfg_do_global_parameter(lp_ctx, "server role", "auto");
|
---|
2553 | lpcfg_do_global_parameter(lp_ctx, "domain logons", "No");
|
---|
2554 | lpcfg_do_global_parameter(lp_ctx, "domain master", "Auto");
|
---|
2555 |
|
---|
2556 | /* options that can be set on the command line must be initialised via
|
---|
2557 | the slower lpcfg_do_global_parameter() to ensure that FLAG_CMDLINE is obeyed */
|
---|
2558 | #ifdef TCP_NODELAY
|
---|
2559 | lpcfg_do_global_parameter(lp_ctx, "socket options", "TCP_NODELAY");
|
---|
2560 | #endif
|
---|
2561 | lpcfg_do_global_parameter(lp_ctx, "workgroup", DEFAULT_WORKGROUP);
|
---|
2562 | myname = get_myname(lp_ctx);
|
---|
2563 | lpcfg_do_global_parameter(lp_ctx, "netbios name", myname);
|
---|
2564 | talloc_free(myname);
|
---|
2565 | lpcfg_do_global_parameter(lp_ctx, "name resolve order", "lmhosts wins host bcast");
|
---|
2566 |
|
---|
2567 | lpcfg_do_global_parameter(lp_ctx, "fstype", "NTFS");
|
---|
2568 |
|
---|
2569 | lpcfg_do_global_parameter(lp_ctx, "ntvfs handler", "unixuid default");
|
---|
2570 | lpcfg_do_global_parameter(lp_ctx, "max connections", "0");
|
---|
2571 |
|
---|
2572 | lpcfg_do_global_parameter(lp_ctx, "dcerpc endpoint servers", "epmapper wkssvc rpcecho samr netlogon lsarpc drsuapi dssetup unixinfo browser eventlog6 backupkey dnsserver");
|
---|
2573 | lpcfg_do_global_parameter(lp_ctx, "server services", "s3fs rpc nbt wrepl ldap cldap kdc drepl winbindd ntp_signd kcc dnsupdate dns");
|
---|
2574 | lpcfg_do_global_parameter(lp_ctx, "kccsrv:samba_kcc", "false");
|
---|
2575 | /* the winbind method for domain controllers is for both RODC
|
---|
2576 | auth forwarding and for trusted domains */
|
---|
2577 | lpcfg_do_global_parameter(lp_ctx, "private dir", dyn_PRIVATE_DIR);
|
---|
2578 | lpcfg_do_global_parameter(lp_ctx, "registry:HKEY_LOCAL_MACHINE", "hklm.ldb");
|
---|
2579 |
|
---|
2580 | /* This hive should be dynamically generated by Samba using
|
---|
2581 | data from the sam, but for the moment leave it in a tdb to
|
---|
2582 | keep regedt32 from popping up an annoying dialog. */
|
---|
2583 | lpcfg_do_global_parameter(lp_ctx, "registry:HKEY_USERS", "hku.ldb");
|
---|
2584 |
|
---|
2585 | /* using UTF8 by default allows us to support all chars */
|
---|
2586 | lpcfg_do_global_parameter(lp_ctx, "unix charset", "UTF-8");
|
---|
2587 |
|
---|
2588 | /* Use codepage 850 as a default for the dos character set */
|
---|
2589 | lpcfg_do_global_parameter(lp_ctx, "dos charset", "CP850");
|
---|
2590 |
|
---|
2591 | /*
|
---|
2592 | * Allow the default PASSWD_CHAT to be overridden in local.h.
|
---|
2593 | */
|
---|
2594 | lpcfg_do_global_parameter(lp_ctx, "passwd chat", DEFAULT_PASSWD_CHAT);
|
---|
2595 |
|
---|
2596 | lpcfg_do_global_parameter(lp_ctx, "pid directory", dyn_PIDDIR);
|
---|
2597 | lpcfg_do_global_parameter(lp_ctx, "lock dir", dyn_LOCKDIR);
|
---|
2598 | lpcfg_do_global_parameter(lp_ctx, "state directory", dyn_STATEDIR);
|
---|
2599 | lpcfg_do_global_parameter(lp_ctx, "cache directory", dyn_CACHEDIR);
|
---|
2600 | lpcfg_do_global_parameter(lp_ctx, "ncalrpc dir", dyn_NCALRPCDIR);
|
---|
2601 |
|
---|
2602 | lpcfg_do_global_parameter(lp_ctx, "nbt client socket address", "0.0.0.0");
|
---|
2603 | lpcfg_do_global_parameter_var(lp_ctx, "server string",
|
---|
2604 | "Samba %s", SAMBA_VERSION_STRING);
|
---|
2605 |
|
---|
2606 | lpcfg_do_global_parameter(lp_ctx, "password server", "*");
|
---|
2607 |
|
---|
2608 | lpcfg_do_global_parameter(lp_ctx, "max mux", "50");
|
---|
2609 | lpcfg_do_global_parameter(lp_ctx, "max xmit", "16644");
|
---|
2610 | lpcfg_do_global_parameter(lp_ctx, "host msdfs", "true");
|
---|
2611 |
|
---|
2612 | lpcfg_do_global_parameter(lp_ctx, "LargeReadwrite", "True");
|
---|
2613 | lpcfg_do_global_parameter(lp_ctx, "server min protocol", "LANMAN1");
|
---|
2614 | lpcfg_do_global_parameter(lp_ctx, "server max protocol", "SMB3");
|
---|
2615 | lpcfg_do_global_parameter(lp_ctx, "client min protocol", "CORE");
|
---|
2616 | lpcfg_do_global_parameter(lp_ctx, "client max protocol", "default");
|
---|
2617 | lpcfg_do_global_parameter(lp_ctx, "client ipc min protocol", "default");
|
---|
2618 | lpcfg_do_global_parameter(lp_ctx, "client ipc max protocol", "default");
|
---|
2619 | lpcfg_do_global_parameter(lp_ctx, "security", "AUTO");
|
---|
2620 | lpcfg_do_global_parameter(lp_ctx, "EncryptPasswords", "True");
|
---|
2621 | lpcfg_do_global_parameter(lp_ctx, "ReadRaw", "True");
|
---|
2622 | lpcfg_do_global_parameter(lp_ctx, "WriteRaw", "True");
|
---|
2623 | lpcfg_do_global_parameter(lp_ctx, "NullPasswords", "False");
|
---|
2624 | lpcfg_do_global_parameter(lp_ctx, "old password allowed period", "60");
|
---|
2625 | lpcfg_do_global_parameter(lp_ctx, "ObeyPamRestrictions", "False");
|
---|
2626 |
|
---|
2627 | lpcfg_do_global_parameter(lp_ctx, "TimeServer", "False");
|
---|
2628 | lpcfg_do_global_parameter(lp_ctx, "BindInterfacesOnly", "False");
|
---|
2629 | lpcfg_do_global_parameter(lp_ctx, "Unicode", "True");
|
---|
2630 | lpcfg_do_global_parameter(lp_ctx, "ClientLanManAuth", "False");
|
---|
2631 | lpcfg_do_global_parameter(lp_ctx, "ClientNTLMv2Auth", "True");
|
---|
2632 | lpcfg_do_global_parameter(lp_ctx, "LanmanAuth", "False");
|
---|
2633 | lpcfg_do_global_parameter(lp_ctx, "NTLMAuth", "True");
|
---|
2634 | lpcfg_do_global_parameter(lp_ctx, "RawNTLMv2Auth", "False");
|
---|
2635 | lpcfg_do_global_parameter(lp_ctx, "client use spnego principal", "False");
|
---|
2636 |
|
---|
2637 | lpcfg_do_global_parameter(lp_ctx, "allow dcerpc auth level connect", "False");
|
---|
2638 |
|
---|
2639 | lpcfg_do_global_parameter(lp_ctx, "UnixExtensions", "True");
|
---|
2640 |
|
---|
2641 | lpcfg_do_global_parameter(lp_ctx, "PreferredMaster", "Auto");
|
---|
2642 | lpcfg_do_global_parameter(lp_ctx, "LocalMaster", "True");
|
---|
2643 |
|
---|
2644 | lpcfg_do_global_parameter(lp_ctx, "wins support", "False");
|
---|
2645 | lpcfg_do_global_parameter(lp_ctx, "dns proxy", "True");
|
---|
2646 |
|
---|
2647 | lpcfg_do_global_parameter(lp_ctx, "winbind separator", "\\");
|
---|
2648 | lpcfg_do_global_parameter(lp_ctx, "winbind sealed pipes", "True");
|
---|
2649 | lpcfg_do_global_parameter(lp_ctx, "require strong key", "True");
|
---|
2650 | lpcfg_do_global_parameter(lp_ctx, "winbindd socket directory", dyn_WINBINDD_SOCKET_DIR);
|
---|
2651 | lpcfg_do_global_parameter(lp_ctx, "winbindd privileged socket directory", dyn_WINBINDD_PRIVILEGED_SOCKET_DIR);
|
---|
2652 | lpcfg_do_global_parameter(lp_ctx, "ntp signd socket directory", dyn_NTP_SIGND_SOCKET_DIR);
|
---|
2653 | lpcfg_do_global_parameter_var(lp_ctx, "dns update command", "%s/samba_dnsupdate", dyn_SCRIPTSBINDIR);
|
---|
2654 | lpcfg_do_global_parameter_var(lp_ctx, "spn update command", "%s/samba_spnupdate", dyn_SCRIPTSBINDIR);
|
---|
2655 | lpcfg_do_global_parameter_var(lp_ctx, "samba kcc command",
|
---|
2656 | "%s/samba_kcc", dyn_SCRIPTSBINDIR);
|
---|
2657 | lpcfg_do_global_parameter(lp_ctx, "template shell", "/bin/false");
|
---|
2658 | lpcfg_do_global_parameter(lp_ctx, "template homedir", "/home/%D/%U");
|
---|
2659 |
|
---|
2660 | lpcfg_do_global_parameter(lp_ctx, "client signing", "default");
|
---|
2661 | lpcfg_do_global_parameter(lp_ctx, "client ipc signing", "default");
|
---|
2662 | lpcfg_do_global_parameter(lp_ctx, "server signing", "default");
|
---|
2663 |
|
---|
2664 | lpcfg_do_global_parameter(lp_ctx, "use spnego", "True");
|
---|
2665 |
|
---|
2666 | lpcfg_do_global_parameter(lp_ctx, "use mmap", "True");
|
---|
2667 |
|
---|
2668 | lpcfg_do_global_parameter(lp_ctx, "smb ports", "445 139");
|
---|
2669 | lpcfg_do_global_parameter_var(lp_ctx, "nbt port", "%d", NBT_NAME_SERVICE_PORT);
|
---|
2670 | lpcfg_do_global_parameter_var(lp_ctx, "dgram port", "%d", NBT_DGRAM_SERVICE_PORT);
|
---|
2671 | lpcfg_do_global_parameter(lp_ctx, "cldap port", "389");
|
---|
2672 | lpcfg_do_global_parameter(lp_ctx, "krb5 port", "88");
|
---|
2673 | lpcfg_do_global_parameter(lp_ctx, "kpasswd port", "464");
|
---|
2674 | lpcfg_do_global_parameter(lp_ctx, "web port", "901");
|
---|
2675 |
|
---|
2676 | lpcfg_do_global_parameter(lp_ctx, "nt status support", "True");
|
---|
2677 |
|
---|
2678 | lpcfg_do_global_parameter(lp_ctx, "max wins ttl", "518400"); /* 6 days */
|
---|
2679 | lpcfg_do_global_parameter(lp_ctx, "min wins ttl", "21600");
|
---|
2680 |
|
---|
2681 | lpcfg_do_global_parameter(lp_ctx, "tls enabled", "True");
|
---|
2682 | lpcfg_do_global_parameter(lp_ctx, "tls verify peer", "as_strict_as_possible");
|
---|
2683 | lpcfg_do_global_parameter(lp_ctx, "tls keyfile", "tls/key.pem");
|
---|
2684 | lpcfg_do_global_parameter(lp_ctx, "tls certfile", "tls/cert.pem");
|
---|
2685 | lpcfg_do_global_parameter(lp_ctx, "tls cafile", "tls/ca.pem");
|
---|
2686 | lpcfg_do_global_parameter(lp_ctx, "tls priority", "NORMAL:-VERS-SSL3.0");
|
---|
2687 | lpcfg_do_global_parameter(lp_ctx, "prefork children:smb", "4");
|
---|
2688 |
|
---|
2689 | lpcfg_do_global_parameter(lp_ctx, "rndc command", "/usr/sbin/rndc");
|
---|
2690 | lpcfg_do_global_parameter(lp_ctx, "nsupdate command", "/usr/bin/nsupdate -g");
|
---|
2691 |
|
---|
2692 | lpcfg_do_global_parameter(lp_ctx, "allow dns updates", "secure only");
|
---|
2693 | lpcfg_do_global_parameter(lp_ctx, "dns forwarder", "");
|
---|
2694 |
|
---|
2695 | lpcfg_do_global_parameter(lp_ctx, "algorithmic rid base", "1000");
|
---|
2696 |
|
---|
2697 | lpcfg_do_global_parameter(lp_ctx, "enhanced browsing", "True");
|
---|
2698 |
|
---|
2699 | lpcfg_do_global_parameter(lp_ctx, "winbind nss info", "template");
|
---|
2700 |
|
---|
2701 | lpcfg_do_global_parameter(lp_ctx, "server schannel", "Auto");
|
---|
2702 |
|
---|
2703 | lpcfg_do_global_parameter(lp_ctx, "short preserve case", "True");
|
---|
2704 |
|
---|
2705 | lpcfg_do_global_parameter(lp_ctx, "max open files", "16384");
|
---|
2706 |
|
---|
2707 | lpcfg_do_global_parameter(lp_ctx, "cups connection timeout", "30");
|
---|
2708 |
|
---|
2709 | lpcfg_do_global_parameter(lp_ctx, "locking", "True");
|
---|
2710 |
|
---|
2711 | lpcfg_do_global_parameter(lp_ctx, "block size", "1024");
|
---|
2712 |
|
---|
2713 | lpcfg_do_global_parameter(lp_ctx, "client use spnego", "True");
|
---|
2714 |
|
---|
2715 | lpcfg_do_global_parameter(lp_ctx, "change notify", "True");
|
---|
2716 |
|
---|
2717 | lpcfg_do_global_parameter(lp_ctx, "name cache timeout", "660");
|
---|
2718 |
|
---|
2719 | lpcfg_do_global_parameter(lp_ctx, "defer sharing violations", "True");
|
---|
2720 |
|
---|
2721 | lpcfg_do_global_parameter(lp_ctx, "ldap replication sleep", "1000");
|
---|
2722 |
|
---|
2723 | lpcfg_do_global_parameter(lp_ctx, "idmap backend", "tdb");
|
---|
2724 |
|
---|
2725 | lpcfg_do_global_parameter(lp_ctx, "enable privileges", "True");
|
---|
2726 |
|
---|
2727 | lpcfg_do_global_parameter_var(lp_ctx, "smb2 max write", "%u", DEFAULT_SMB2_MAX_WRITE);
|
---|
2728 |
|
---|
2729 | lpcfg_do_global_parameter(lp_ctx, "passdb backend", "tdbsam");
|
---|
2730 |
|
---|
2731 | lpcfg_do_global_parameter(lp_ctx, "getwd cache", "True");
|
---|
2732 |
|
---|
2733 | lpcfg_do_global_parameter(lp_ctx, "winbind nested groups", "True");
|
---|
2734 |
|
---|
2735 | lpcfg_do_global_parameter(lp_ctx, "mangled names", "True");
|
---|
2736 |
|
---|
2737 | lpcfg_do_global_parameter_var(lp_ctx, "smb2 max credits", "%u", DEFAULT_SMB2_MAX_CREDITS);
|
---|
2738 |
|
---|
2739 | lpcfg_do_global_parameter(lp_ctx, "ldap ssl", "start tls");
|
---|
2740 |
|
---|
2741 | lpcfg_do_global_parameter(lp_ctx, "ldap deref", "auto");
|
---|
2742 |
|
---|
2743 | lpcfg_do_global_parameter(lp_ctx, "lm interval", "60");
|
---|
2744 |
|
---|
2745 | lpcfg_do_global_parameter(lp_ctx, "mangling method", "hash2");
|
---|
2746 |
|
---|
2747 | lpcfg_do_global_parameter(lp_ctx, "hide dot files", "True");
|
---|
2748 |
|
---|
2749 | lpcfg_do_global_parameter(lp_ctx, "browse list", "True");
|
---|
2750 |
|
---|
2751 | lpcfg_do_global_parameter(lp_ctx, "passwd chat timeout", "2");
|
---|
2752 |
|
---|
2753 | lpcfg_do_global_parameter(lp_ctx, "guest account", GUEST_ACCOUNT);
|
---|
2754 |
|
---|
2755 | lpcfg_do_global_parameter(lp_ctx, "client schannel", "auto");
|
---|
2756 |
|
---|
2757 | lpcfg_do_global_parameter(lp_ctx, "smb encrypt", "default");
|
---|
2758 |
|
---|
2759 | lpcfg_do_global_parameter(lp_ctx, "max log size", "5000");
|
---|
2760 |
|
---|
2761 | lpcfg_do_global_parameter(lp_ctx, "idmap negative cache time", "120");
|
---|
2762 |
|
---|
2763 | lpcfg_do_global_parameter(lp_ctx, "ldap follow referral", "auto");
|
---|
2764 |
|
---|
2765 | lpcfg_do_global_parameter(lp_ctx, "multicast dns register", "yes");
|
---|
2766 |
|
---|
2767 | lpcfg_do_global_parameter(lp_ctx, "winbind reconnect delay", "30");
|
---|
2768 |
|
---|
2769 | lpcfg_do_global_parameter(lp_ctx, "winbind request timeout", "60");
|
---|
2770 |
|
---|
2771 | lpcfg_do_global_parameter(lp_ctx, "nt acl support", "yes");
|
---|
2772 |
|
---|
2773 | lpcfg_do_global_parameter(lp_ctx, "acl check permissions", "yes");
|
---|
2774 |
|
---|
2775 | lpcfg_do_global_parameter(lp_ctx, "keepalive", "300");
|
---|
2776 |
|
---|
2777 | lpcfg_do_global_parameter(lp_ctx, "smbd profiling level", "off");
|
---|
2778 |
|
---|
2779 | lpcfg_do_global_parameter(lp_ctx, "winbind cache time", "300");
|
---|
2780 |
|
---|
2781 | lpcfg_do_global_parameter(lp_ctx, "level2 oplocks", "yes");
|
---|
2782 |
|
---|
2783 | lpcfg_do_global_parameter(lp_ctx, "show add printer wizard", "yes");
|
---|
2784 |
|
---|
2785 | lpcfg_do_global_parameter(lp_ctx, "allocation roundup size", "1048576");
|
---|
2786 |
|
---|
2787 | lpcfg_do_global_parameter(lp_ctx, "ldap page size", "1000");
|
---|
2788 |
|
---|
2789 | lpcfg_do_global_parameter(lp_ctx, "kernel share modes", "yes");
|
---|
2790 |
|
---|
2791 | lpcfg_do_global_parameter(lp_ctx, "strict locking", "Auto");
|
---|
2792 |
|
---|
2793 | lpcfg_do_global_parameter(lp_ctx, "map readonly", "yes");
|
---|
2794 |
|
---|
2795 | lpcfg_do_global_parameter(lp_ctx, "allow trusted domains", "yes");
|
---|
2796 |
|
---|
2797 | lpcfg_do_global_parameter(lp_ctx, "default devmode", "yes");
|
---|
2798 |
|
---|
2799 | lpcfg_do_global_parameter(lp_ctx, "os level", "20");
|
---|
2800 |
|
---|
2801 | lpcfg_do_global_parameter(lp_ctx, "dos filetimes", "yes");
|
---|
2802 |
|
---|
2803 | lpcfg_do_global_parameter(lp_ctx, "mangling char", "~");
|
---|
2804 |
|
---|
2805 | lpcfg_do_global_parameter(lp_ctx, "printcap cache time", "750");
|
---|
2806 |
|
---|
2807 | lpcfg_do_global_parameter(lp_ctx, "create krb5 conf", "yes");
|
---|
2808 |
|
---|
2809 | lpcfg_do_global_parameter(lp_ctx, "winbind max clients", "200");
|
---|
2810 |
|
---|
2811 | lpcfg_do_global_parameter(lp_ctx, "acl map full control", "yes");
|
---|
2812 |
|
---|
2813 | lpcfg_do_global_parameter(lp_ctx, "nt pipe support", "yes");
|
---|
2814 |
|
---|
2815 | lpcfg_do_global_parameter(lp_ctx, "ldap debug threshold", "10");
|
---|
2816 |
|
---|
2817 | lpcfg_do_global_parameter(lp_ctx, "client ldap sasl wrapping", "sign");
|
---|
2818 |
|
---|
2819 | lpcfg_do_global_parameter(lp_ctx, "ldap server require strong auth", "yes");
|
---|
2820 |
|
---|
2821 | lpcfg_do_global_parameter(lp_ctx, "follow symlinks", "yes");
|
---|
2822 |
|
---|
2823 | lpcfg_do_global_parameter(lp_ctx, "machine password timeout", "604800");
|
---|
2824 |
|
---|
2825 | lpcfg_do_global_parameter(lp_ctx, "ldap connection timeout", "2");
|
---|
2826 |
|
---|
2827 | lpcfg_do_global_parameter(lp_ctx, "winbind expand groups", "0");
|
---|
2828 |
|
---|
2829 | lpcfg_do_global_parameter(lp_ctx, "stat cache", "yes");
|
---|
2830 |
|
---|
2831 | lpcfg_do_global_parameter(lp_ctx, "lpq cache time", "30");
|
---|
2832 |
|
---|
2833 | lpcfg_do_global_parameter_var(lp_ctx, "smb2 max trans", "%u", DEFAULT_SMB2_MAX_TRANSACT);
|
---|
2834 |
|
---|
2835 | lpcfg_do_global_parameter_var(lp_ctx, "smb2 max read", "%u", DEFAULT_SMB2_MAX_READ);
|
---|
2836 |
|
---|
2837 | lpcfg_do_global_parameter(lp_ctx, "durable handles", "yes");
|
---|
2838 |
|
---|
2839 | lpcfg_do_global_parameter(lp_ctx, "max stat cache size", "256");
|
---|
2840 |
|
---|
2841 | lpcfg_do_global_parameter(lp_ctx, "ldap passwd sync", "no");
|
---|
2842 |
|
---|
2843 | lpcfg_do_global_parameter(lp_ctx, "kernel change notify", "yes");
|
---|
2844 |
|
---|
2845 | lpcfg_do_global_parameter(lp_ctx, "max ttl", "259200");
|
---|
2846 |
|
---|
2847 | lpcfg_do_global_parameter(lp_ctx, "blocking locks", "yes");
|
---|
2848 |
|
---|
2849 | lpcfg_do_global_parameter(lp_ctx, "oplock contention limit", "2");
|
---|
2850 |
|
---|
2851 | lpcfg_do_global_parameter(lp_ctx, "load printers", "yes");
|
---|
2852 |
|
---|
2853 | lpcfg_do_global_parameter(lp_ctx, "idmap cache time", "604800");
|
---|
2854 |
|
---|
2855 | lpcfg_do_global_parameter(lp_ctx, "preserve case", "yes");
|
---|
2856 |
|
---|
2857 | lpcfg_do_global_parameter(lp_ctx, "lm announce", "auto");
|
---|
2858 |
|
---|
2859 | lpcfg_do_global_parameter(lp_ctx, "afs token lifetime", "604800");
|
---|
2860 |
|
---|
2861 | lpcfg_do_global_parameter(lp_ctx, "enable core files", "yes");
|
---|
2862 |
|
---|
2863 | lpcfg_do_global_parameter(lp_ctx, "winbind max domain connections", "1");
|
---|
2864 |
|
---|
2865 | lpcfg_do_global_parameter(lp_ctx, "case sensitive", "auto");
|
---|
2866 |
|
---|
2867 | lpcfg_do_global_parameter(lp_ctx, "ldap timeout", "15");
|
---|
2868 |
|
---|
2869 | lpcfg_do_global_parameter(lp_ctx, "mangle prefix", "1");
|
---|
2870 |
|
---|
2871 | lpcfg_do_global_parameter(lp_ctx, "posix locking", "yes");
|
---|
2872 |
|
---|
2873 | lpcfg_do_global_parameter(lp_ctx, "lock spin time", "200");
|
---|
2874 |
|
---|
2875 | lpcfg_do_global_parameter(lp_ctx, "directory name cache size", "100");
|
---|
2876 |
|
---|
2877 | lpcfg_do_global_parameter(lp_ctx, "nmbd bind explicit broadcast", "yes");
|
---|
2878 |
|
---|
2879 | lpcfg_do_global_parameter(lp_ctx, "init logon delay", "100");
|
---|
2880 |
|
---|
2881 | lpcfg_do_global_parameter(lp_ctx, "usershare owner only", "yes");
|
---|
2882 |
|
---|
2883 | lpcfg_do_global_parameter(lp_ctx, "-valid", "yes");
|
---|
2884 |
|
---|
2885 | lpcfg_do_global_parameter_var(lp_ctx, "usershare path", "%s/usershares", get_dyn_STATEDIR());
|
---|
2886 |
|
---|
2887 | #ifdef DEVELOPER
|
---|
2888 | lpcfg_do_global_parameter_var(lp_ctx, "panic action", "/bin/sleep 999999999");
|
---|
2889 | #endif
|
---|
2890 |
|
---|
2891 | lpcfg_do_global_parameter(lp_ctx, "smb passwd file", get_dyn_SMB_PASSWD_FILE());
|
---|
2892 |
|
---|
2893 | lpcfg_do_global_parameter(lp_ctx, "logon home", "\\\\%N\\%U");
|
---|
2894 |
|
---|
2895 | lpcfg_do_global_parameter(lp_ctx, "logon path", "\\\\%N\\%U\\profile");
|
---|
2896 |
|
---|
2897 | lpcfg_do_global_parameter(lp_ctx, "printjob username", "%U");
|
---|
2898 |
|
---|
2899 | lpcfg_do_global_parameter(lp_ctx, "aio max threads", "100");
|
---|
2900 |
|
---|
2901 | /* Allow modules to adjust defaults */
|
---|
2902 | for (defaults_hook = defaults_hooks; defaults_hook;
|
---|
2903 | defaults_hook = defaults_hook->next) {
|
---|
2904 | bool ret;
|
---|
2905 |
|
---|
2906 | ret = defaults_hook->hook(lp_ctx);
|
---|
2907 | if (!ret) {
|
---|
2908 | DEBUG(1, ("Defaults hook %s failed to run.",
|
---|
2909 | defaults_hook->name));
|
---|
2910 | talloc_free(lp_ctx);
|
---|
2911 | return NULL;
|
---|
2912 | }
|
---|
2913 | }
|
---|
2914 |
|
---|
2915 | for (i = 0; parm_table[i].label; i++) {
|
---|
2916 | if (!(lp_ctx->flags[i] & FLAG_CMDLINE)) {
|
---|
2917 | lp_ctx->flags[i] |= FLAG_DEFAULT;
|
---|
2918 | }
|
---|
2919 | }
|
---|
2920 |
|
---|
2921 | for (parm=lp_ctx->globals->param_opt; parm; parm=parm->next) {
|
---|
2922 | if (!(parm->priority & FLAG_CMDLINE)) {
|
---|
2923 | parm->priority |= FLAG_DEFAULT;
|
---|
2924 | }
|
---|
2925 | }
|
---|
2926 |
|
---|
2927 | for (parm=lp_ctx->sDefault->param_opt; parm; parm=parm->next) {
|
---|
2928 | if (!(parm->priority & FLAG_CMDLINE)) {
|
---|
2929 | parm->priority |= FLAG_DEFAULT;
|
---|
2930 | }
|
---|
2931 | }
|
---|
2932 |
|
---|
2933 | return lp_ctx;
|
---|
2934 | }
|
---|
2935 |
|
---|
2936 | /**
|
---|
2937 | * Initialise the global parameter structure.
|
---|
2938 | */
|
---|
2939 | struct loadparm_context *loadparm_init_global(bool load_default)
|
---|
2940 | {
|
---|
2941 | if (global_loadparm_context == NULL) {
|
---|
2942 | global_loadparm_context = loadparm_init(NULL);
|
---|
2943 | }
|
---|
2944 | if (global_loadparm_context == NULL) {
|
---|
2945 | return NULL;
|
---|
2946 | }
|
---|
2947 | global_loadparm_context->global = true;
|
---|
2948 | if (load_default && !global_loadparm_context->loaded) {
|
---|
2949 | lpcfg_load_default(global_loadparm_context);
|
---|
2950 | }
|
---|
2951 | global_loadparm_context->refuse_free = true;
|
---|
2952 | return global_loadparm_context;
|
---|
2953 | }
|
---|
2954 |
|
---|
2955 | /**
|
---|
2956 | * Initialise the global parameter structure.
|
---|
2957 | */
|
---|
2958 | struct loadparm_context *loadparm_init_s3(TALLOC_CTX *mem_ctx,
|
---|
2959 | const struct loadparm_s3_helpers *s3_fns)
|
---|
2960 | {
|
---|
2961 | struct loadparm_context *loadparm_context = talloc_zero(mem_ctx, struct loadparm_context);
|
---|
2962 | if (!loadparm_context) {
|
---|
2963 | return NULL;
|
---|
2964 | }
|
---|
2965 | loadparm_context->s3_fns = s3_fns;
|
---|
2966 | loadparm_context->globals = s3_fns->globals;
|
---|
2967 | loadparm_context->flags = s3_fns->flags;
|
---|
2968 |
|
---|
2969 | return loadparm_context;
|
---|
2970 | }
|
---|
2971 |
|
---|
2972 | const char *lpcfg_configfile(struct loadparm_context *lp_ctx)
|
---|
2973 | {
|
---|
2974 | return lp_ctx->szConfigFile;
|
---|
2975 | }
|
---|
2976 |
|
---|
2977 | const char *lp_default_path(void)
|
---|
2978 | {
|
---|
2979 | if (getenv("SMB_CONF_PATH"))
|
---|
2980 | return getenv("SMB_CONF_PATH");
|
---|
2981 | else
|
---|
2982 | return dyn_CONFIGFILE;
|
---|
2983 | }
|
---|
2984 |
|
---|
2985 | /**
|
---|
2986 | * Update the internal state of a loadparm context after settings
|
---|
2987 | * have changed.
|
---|
2988 | */
|
---|
2989 | static bool lpcfg_update(struct loadparm_context *lp_ctx)
|
---|
2990 | {
|
---|
2991 | struct debug_settings settings;
|
---|
2992 | TALLOC_CTX *tmp_ctx;
|
---|
2993 |
|
---|
2994 | tmp_ctx = talloc_new(lp_ctx);
|
---|
2995 | if (tmp_ctx == NULL) {
|
---|
2996 | return false;
|
---|
2997 | }
|
---|
2998 |
|
---|
2999 | lpcfg_add_auto_services(lp_ctx, lpcfg_auto_services(lp_ctx, tmp_ctx));
|
---|
3000 |
|
---|
3001 | if (!lp_ctx->globals->wins_server_list && lp_ctx->globals->we_are_a_wins_server) {
|
---|
3002 | lpcfg_do_global_parameter(lp_ctx, "wins server", "127.0.0.1");
|
---|
3003 | }
|
---|
3004 |
|
---|
3005 | if (!lp_ctx->global) {
|
---|
3006 | TALLOC_FREE(tmp_ctx);
|
---|
3007 | return true;
|
---|
3008 | }
|
---|
3009 |
|
---|
3010 | panic_action = lp_ctx->globals->panic_action;
|
---|
3011 |
|
---|
3012 | reload_charcnv(lp_ctx);
|
---|
3013 |
|
---|
3014 | ZERO_STRUCT(settings);
|
---|
3015 | /* Add any more debug-related smb.conf parameters created in
|
---|
3016 | * future here */
|
---|
3017 | settings.timestamp_logs = lp_ctx->globals->timestamp_logs;
|
---|
3018 | settings.debug_prefix_timestamp = lp_ctx->globals->debug_prefix_timestamp;
|
---|
3019 | settings.debug_hires_timestamp = lp_ctx->globals->debug_hires_timestamp;
|
---|
3020 | settings.debug_pid = lp_ctx->globals->debug_pid;
|
---|
3021 | settings.debug_uid = lp_ctx->globals->debug_uid;
|
---|
3022 | settings.debug_class = lp_ctx->globals->debug_class;
|
---|
3023 | debug_set_settings(&settings, lp_ctx->globals->logging,
|
---|
3024 | lp_ctx->globals->syslog,
|
---|
3025 | lp_ctx->globals->syslog_only);
|
---|
3026 |
|
---|
3027 | /* FIXME: This is a bit of a hack, but we can't use a global, since
|
---|
3028 | * not everything that uses lp also uses the socket library */
|
---|
3029 | if (lpcfg_parm_bool(lp_ctx, NULL, "socket", "testnonblock", false)) {
|
---|
3030 | setenv("SOCKET_TESTNONBLOCK", "1", 1);
|
---|
3031 | } else {
|
---|
3032 | unsetenv("SOCKET_TESTNONBLOCK");
|
---|
3033 | }
|
---|
3034 |
|
---|
3035 | TALLOC_FREE(tmp_ctx);
|
---|
3036 | return true;
|
---|
3037 | }
|
---|
3038 |
|
---|
3039 | bool lpcfg_load_default(struct loadparm_context *lp_ctx)
|
---|
3040 | {
|
---|
3041 | const char *path;
|
---|
3042 |
|
---|
3043 | path = lp_default_path();
|
---|
3044 |
|
---|
3045 | if (!file_exist(path)) {
|
---|
3046 | /* We allow the default smb.conf file to not exist,
|
---|
3047 | * basically the equivalent of an empty file. */
|
---|
3048 | return lpcfg_update(lp_ctx);
|
---|
3049 | }
|
---|
3050 |
|
---|
3051 | return lpcfg_load(lp_ctx, path);
|
---|
3052 | }
|
---|
3053 |
|
---|
3054 | /**
|
---|
3055 | * Load the services array from the services file.
|
---|
3056 | *
|
---|
3057 | * Return True on success, False on failure.
|
---|
3058 | */
|
---|
3059 | bool lpcfg_load(struct loadparm_context *lp_ctx, const char *filename)
|
---|
3060 | {
|
---|
3061 | char *n2;
|
---|
3062 | bool bRetval;
|
---|
3063 |
|
---|
3064 | filename = talloc_strdup(lp_ctx, filename);
|
---|
3065 |
|
---|
3066 | lp_ctx->szConfigFile = filename;
|
---|
3067 |
|
---|
3068 | if (lp_ctx->s3_fns) {
|
---|
3069 | return lp_ctx->s3_fns->load(filename);
|
---|
3070 | }
|
---|
3071 |
|
---|
3072 | lp_ctx->bInGlobalSection = true;
|
---|
3073 | n2 = standard_sub_basic(lp_ctx, lp_ctx->szConfigFile);
|
---|
3074 | DEBUG(2, ("lpcfg_load: refreshing parameters from %s\n", n2));
|
---|
3075 |
|
---|
3076 | add_to_file_list(lp_ctx, &lp_ctx->file_lists, lp_ctx->szConfigFile, n2);
|
---|
3077 |
|
---|
3078 | /* We get sections first, so have to start 'behind' to make up */
|
---|
3079 | lp_ctx->currentService = NULL;
|
---|
3080 | bRetval = pm_process(n2, do_section, lpcfg_do_parameter, lp_ctx);
|
---|
3081 |
|
---|
3082 | /* finish up the last section */
|
---|
3083 | DEBUG(4, ("pm_process() returned %s\n", BOOLSTR(bRetval)));
|
---|
3084 | if (bRetval)
|
---|
3085 | if (lp_ctx->currentService != NULL)
|
---|
3086 | bRetval = lpcfg_service_ok(lp_ctx->currentService);
|
---|
3087 |
|
---|
3088 | bRetval = bRetval && lpcfg_update(lp_ctx);
|
---|
3089 |
|
---|
3090 | /* we do this unconditionally, so that it happens even
|
---|
3091 | for a missing smb.conf */
|
---|
3092 | reload_charcnv(lp_ctx);
|
---|
3093 |
|
---|
3094 | if (bRetval == true) {
|
---|
3095 | /* set this up so that any child python tasks will
|
---|
3096 | find the right smb.conf */
|
---|
3097 | setenv("SMB_CONF_PATH", filename, 1);
|
---|
3098 |
|
---|
3099 | /* set the context used by the lp_*() function
|
---|
3100 | varients */
|
---|
3101 | global_loadparm_context = lp_ctx;
|
---|
3102 | lp_ctx->loaded = true;
|
---|
3103 | }
|
---|
3104 |
|
---|
3105 | return bRetval;
|
---|
3106 | }
|
---|
3107 |
|
---|
3108 | /**
|
---|
3109 | * Return the max number of services.
|
---|
3110 | */
|
---|
3111 |
|
---|
3112 | int lpcfg_numservices(struct loadparm_context *lp_ctx)
|
---|
3113 | {
|
---|
3114 | if (lp_ctx->s3_fns) {
|
---|
3115 | return lp_ctx->s3_fns->get_numservices();
|
---|
3116 | }
|
---|
3117 |
|
---|
3118 | return lp_ctx->iNumServices;
|
---|
3119 | }
|
---|
3120 |
|
---|
3121 | /**
|
---|
3122 | * Display the contents of the services array in human-readable form.
|
---|
3123 | */
|
---|
3124 |
|
---|
3125 | void lpcfg_dump(struct loadparm_context *lp_ctx, FILE *f, bool show_defaults,
|
---|
3126 | int maxtoprint)
|
---|
3127 | {
|
---|
3128 | int iService;
|
---|
3129 |
|
---|
3130 | if (lp_ctx->s3_fns) {
|
---|
3131 | lp_ctx->s3_fns->dump(f, show_defaults, maxtoprint);
|
---|
3132 | return;
|
---|
3133 | }
|
---|
3134 |
|
---|
3135 | lpcfg_dump_globals(lp_ctx, f, show_defaults);
|
---|
3136 |
|
---|
3137 | lpcfg_dump_a_service(lp_ctx->sDefault, lp_ctx->sDefault, f, lp_ctx->flags, show_defaults);
|
---|
3138 |
|
---|
3139 | for (iService = 0; iService < maxtoprint; iService++)
|
---|
3140 | lpcfg_dump_one(f, show_defaults, lp_ctx->services[iService], lp_ctx->sDefault);
|
---|
3141 | }
|
---|
3142 |
|
---|
3143 | /**
|
---|
3144 | * Display the contents of one service in human-readable form.
|
---|
3145 | */
|
---|
3146 | void lpcfg_dump_one(FILE *f, bool show_defaults, struct loadparm_service *service, struct loadparm_service *sDefault)
|
---|
3147 | {
|
---|
3148 | if (service != NULL) {
|
---|
3149 | if (service->szService[0] == '\0')
|
---|
3150 | return;
|
---|
3151 | lpcfg_dump_a_service(service, sDefault, f, NULL, show_defaults);
|
---|
3152 | }
|
---|
3153 | }
|
---|
3154 |
|
---|
3155 | struct loadparm_service *lpcfg_servicebynum(struct loadparm_context *lp_ctx,
|
---|
3156 | int snum)
|
---|
3157 | {
|
---|
3158 | if (lp_ctx->s3_fns) {
|
---|
3159 | return lp_ctx->s3_fns->get_servicebynum(snum);
|
---|
3160 | }
|
---|
3161 |
|
---|
3162 | return lp_ctx->services[snum];
|
---|
3163 | }
|
---|
3164 |
|
---|
3165 | struct loadparm_service *lpcfg_service(struct loadparm_context *lp_ctx,
|
---|
3166 | const char *service_name)
|
---|
3167 | {
|
---|
3168 | int iService;
|
---|
3169 | char *serviceName;
|
---|
3170 |
|
---|
3171 | if (lp_ctx->s3_fns) {
|
---|
3172 | return lp_ctx->s3_fns->get_service(service_name);
|
---|
3173 | }
|
---|
3174 |
|
---|
3175 | for (iService = lp_ctx->iNumServices - 1; iService >= 0; iService--) {
|
---|
3176 | if (lp_ctx->services[iService] &&
|
---|
3177 | lp_ctx->services[iService]->szService) {
|
---|
3178 | /*
|
---|
3179 | * The substitution here is used to support %U is
|
---|
3180 | * service names
|
---|
3181 | */
|
---|
3182 | serviceName = standard_sub_basic(
|
---|
3183 | lp_ctx->services[iService],
|
---|
3184 | lp_ctx->services[iService]->szService);
|
---|
3185 | if (strequal(serviceName, service_name)) {
|
---|
3186 | talloc_free(serviceName);
|
---|
3187 | return lp_ctx->services[iService];
|
---|
3188 | }
|
---|
3189 | talloc_free(serviceName);
|
---|
3190 | }
|
---|
3191 | }
|
---|
3192 |
|
---|
3193 | DEBUG(7,("lpcfg_servicenumber: couldn't find %s\n", service_name));
|
---|
3194 | return NULL;
|
---|
3195 | }
|
---|
3196 |
|
---|
3197 | const char *lpcfg_servicename(const struct loadparm_service *service)
|
---|
3198 | {
|
---|
3199 | return lpcfg_string((const char *)service->szService);
|
---|
3200 | }
|
---|
3201 |
|
---|
3202 | /**
|
---|
3203 | * A useful volume label function.
|
---|
3204 | */
|
---|
3205 | const char *lpcfg_volume_label(struct loadparm_service *service, struct loadparm_service *sDefault)
|
---|
3206 | {
|
---|
3207 | const char *ret;
|
---|
3208 | ret = lpcfg_string((const char *)((service != NULL && service->volume != NULL) ?
|
---|
3209 | service->volume : sDefault->volume));
|
---|
3210 | if (!*ret)
|
---|
3211 | return lpcfg_servicename(service);
|
---|
3212 | return ret;
|
---|
3213 | }
|
---|
3214 |
|
---|
3215 | /**
|
---|
3216 | * Return the correct printer name.
|
---|
3217 | */
|
---|
3218 | const char *lpcfg_printername(struct loadparm_service *service, struct loadparm_service *sDefault)
|
---|
3219 | {
|
---|
3220 | const char *ret;
|
---|
3221 | ret = lpcfg_string((const char *)((service != NULL && service->_printername != NULL) ?
|
---|
3222 | service->_printername : sDefault->_printername));
|
---|
3223 | if (ret == NULL || (ret != NULL && *ret == '\0'))
|
---|
3224 | ret = lpcfg_servicename(service);
|
---|
3225 |
|
---|
3226 | return ret;
|
---|
3227 | }
|
---|
3228 |
|
---|
3229 |
|
---|
3230 | /**
|
---|
3231 | * Return the max print jobs per queue.
|
---|
3232 | */
|
---|
3233 | int lpcfg_maxprintjobs(struct loadparm_service *service, struct loadparm_service *sDefault)
|
---|
3234 | {
|
---|
3235 | int maxjobs = lpcfg_max_print_jobs(service, sDefault);
|
---|
3236 |
|
---|
3237 | if (maxjobs <= 0 || maxjobs >= PRINT_MAX_JOBID)
|
---|
3238 | maxjobs = PRINT_MAX_JOBID - 1;
|
---|
3239 |
|
---|
3240 | return maxjobs;
|
---|
3241 | }
|
---|
3242 |
|
---|
3243 | struct smb_iconv_handle *lpcfg_iconv_handle(struct loadparm_context *lp_ctx)
|
---|
3244 | {
|
---|
3245 | if (lp_ctx == NULL) {
|
---|
3246 | return get_iconv_handle();
|
---|
3247 | }
|
---|
3248 | return lp_ctx->iconv_handle;
|
---|
3249 | }
|
---|
3250 |
|
---|
3251 | _PUBLIC_ void reload_charcnv(struct loadparm_context *lp_ctx)
|
---|
3252 | {
|
---|
3253 | struct smb_iconv_handle *old_ic = lp_ctx->iconv_handle;
|
---|
3254 | if (!lp_ctx->global) {
|
---|
3255 | return;
|
---|
3256 | }
|
---|
3257 |
|
---|
3258 | if (old_ic == NULL) {
|
---|
3259 | old_ic = global_iconv_handle;
|
---|
3260 | }
|
---|
3261 | lp_ctx->iconv_handle = smb_iconv_handle_reinit_lp(lp_ctx, lp_ctx, old_ic);
|
---|
3262 | global_iconv_handle = lp_ctx->iconv_handle;
|
---|
3263 | }
|
---|
3264 |
|
---|
3265 | _PUBLIC_ char *lpcfg_tls_keyfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
|
---|
3266 | {
|
---|
3267 | return lpcfg_private_path(mem_ctx, lp_ctx, lpcfg__tls_keyfile(lp_ctx));
|
---|
3268 | }
|
---|
3269 |
|
---|
3270 | _PUBLIC_ char *lpcfg_tls_certfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
|
---|
3271 | {
|
---|
3272 | return lpcfg_private_path(mem_ctx, lp_ctx, lpcfg__tls_certfile(lp_ctx));
|
---|
3273 | }
|
---|
3274 |
|
---|
3275 | _PUBLIC_ char *lpcfg_tls_cafile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
|
---|
3276 | {
|
---|
3277 | return lpcfg_private_path(mem_ctx, lp_ctx, lpcfg__tls_cafile(lp_ctx));
|
---|
3278 | }
|
---|
3279 |
|
---|
3280 | _PUBLIC_ char *lpcfg_tls_crlfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
|
---|
3281 | {
|
---|
3282 | return lpcfg_private_path(mem_ctx, lp_ctx, lpcfg__tls_crlfile(lp_ctx));
|
---|
3283 | }
|
---|
3284 |
|
---|
3285 | _PUBLIC_ char *lpcfg_tls_dhpfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
|
---|
3286 | {
|
---|
3287 | return lpcfg_private_path(mem_ctx, lp_ctx, lpcfg__tls_dhpfile(lp_ctx));
|
---|
3288 | }
|
---|
3289 |
|
---|
3290 | struct gensec_settings *lpcfg_gensec_settings(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
|
---|
3291 | {
|
---|
3292 | struct gensec_settings *settings = talloc_zero(mem_ctx, struct gensec_settings);
|
---|
3293 | if (settings == NULL)
|
---|
3294 | return NULL;
|
---|
3295 | SMB_ASSERT(lp_ctx != NULL);
|
---|
3296 | settings->lp_ctx = talloc_reference(settings, lp_ctx);
|
---|
3297 | settings->target_hostname = lpcfg_parm_string(lp_ctx, NULL, "gensec", "target_hostname");
|
---|
3298 | return settings;
|
---|
3299 | }
|
---|
3300 |
|
---|
3301 | int lpcfg_server_role(struct loadparm_context *lp_ctx)
|
---|
3302 | {
|
---|
3303 | int domain_master = lpcfg__domain_master(lp_ctx);
|
---|
3304 |
|
---|
3305 | return lp_find_server_role(lpcfg__server_role(lp_ctx),
|
---|
3306 | lpcfg__security(lp_ctx),
|
---|
3307 | lpcfg__domain_logons(lp_ctx),
|
---|
3308 | (domain_master == true) ||
|
---|
3309 | (domain_master == Auto));
|
---|
3310 | }
|
---|
3311 |
|
---|
3312 | int lpcfg_security(struct loadparm_context *lp_ctx)
|
---|
3313 | {
|
---|
3314 | return lp_find_security(lpcfg__server_role(lp_ctx),
|
---|
3315 | lpcfg__security(lp_ctx));
|
---|
3316 | }
|
---|
3317 |
|
---|
3318 | int lpcfg_client_max_protocol(struct loadparm_context *lp_ctx)
|
---|
3319 | {
|
---|
3320 | int client_max_protocol = lpcfg__client_max_protocol(lp_ctx);
|
---|
3321 | if (client_max_protocol == PROTOCOL_DEFAULT) {
|
---|
3322 | return PROTOCOL_NT1;
|
---|
3323 | }
|
---|
3324 | return client_max_protocol;
|
---|
3325 | }
|
---|
3326 |
|
---|
3327 | int lpcfg_client_ipc_min_protocol(struct loadparm_context *lp_ctx)
|
---|
3328 | {
|
---|
3329 | int client_ipc_min_protocol = lpcfg__client_ipc_min_protocol(lp_ctx);
|
---|
3330 | if (client_ipc_min_protocol == PROTOCOL_DEFAULT) {
|
---|
3331 | client_ipc_min_protocol = lpcfg_client_min_protocol(lp_ctx);
|
---|
3332 | }
|
---|
3333 | if (client_ipc_min_protocol < PROTOCOL_NT1) {
|
---|
3334 | return PROTOCOL_NT1;
|
---|
3335 | }
|
---|
3336 | return client_ipc_min_protocol;
|
---|
3337 | }
|
---|
3338 |
|
---|
3339 | int lpcfg_client_ipc_max_protocol(struct loadparm_context *lp_ctx)
|
---|
3340 | {
|
---|
3341 | int client_ipc_max_protocol = lpcfg__client_ipc_max_protocol(lp_ctx);
|
---|
3342 | if (client_ipc_max_protocol == PROTOCOL_DEFAULT) {
|
---|
3343 | return PROTOCOL_LATEST;
|
---|
3344 | }
|
---|
3345 | if (client_ipc_max_protocol < PROTOCOL_NT1) {
|
---|
3346 | return PROTOCOL_NT1;
|
---|
3347 | }
|
---|
3348 | return client_ipc_max_protocol;
|
---|
3349 | }
|
---|
3350 |
|
---|
3351 | int lpcfg_client_ipc_signing(struct loadparm_context *lp_ctx)
|
---|
3352 | {
|
---|
3353 | int client_ipc_signing = lpcfg__client_ipc_signing(lp_ctx);
|
---|
3354 | if (client_ipc_signing == SMB_SIGNING_DEFAULT) {
|
---|
3355 | return SMB_SIGNING_REQUIRED;
|
---|
3356 | }
|
---|
3357 | return client_ipc_signing;
|
---|
3358 | }
|
---|
3359 |
|
---|
3360 | bool lpcfg_server_signing_allowed(struct loadparm_context *lp_ctx, bool *mandatory)
|
---|
3361 | {
|
---|
3362 | bool allowed = true;
|
---|
3363 | enum smb_signing_setting signing_setting = lpcfg_server_signing(lp_ctx);
|
---|
3364 |
|
---|
3365 | *mandatory = false;
|
---|
3366 |
|
---|
3367 | if (signing_setting == SMB_SIGNING_DEFAULT) {
|
---|
3368 | /*
|
---|
3369 | * If we are a domain controller, SMB signing is
|
---|
3370 | * really important, as it can prevent a number of
|
---|
3371 | * attacks on communications between us and the
|
---|
3372 | * clients
|
---|
3373 | *
|
---|
3374 | * However, it really sucks (no sendfile, CPU
|
---|
3375 | * overhead) performance-wise when used on a
|
---|
3376 | * file server, so disable it by default
|
---|
3377 | * on non-DCs
|
---|
3378 | */
|
---|
3379 |
|
---|
3380 | if (lpcfg_server_role(lp_ctx) >= ROLE_ACTIVE_DIRECTORY_DC) {
|
---|
3381 | signing_setting = SMB_SIGNING_REQUIRED;
|
---|
3382 | } else {
|
---|
3383 | signing_setting = SMB_SIGNING_OFF;
|
---|
3384 | }
|
---|
3385 | }
|
---|
3386 |
|
---|
3387 | switch (signing_setting) {
|
---|
3388 | case SMB_SIGNING_REQUIRED:
|
---|
3389 | *mandatory = true;
|
---|
3390 | break;
|
---|
3391 | case SMB_SIGNING_DESIRED:
|
---|
3392 | case SMB_SIGNING_IF_REQUIRED:
|
---|
3393 | break;
|
---|
3394 | case SMB_SIGNING_OFF:
|
---|
3395 | allowed = false;
|
---|
3396 | break;
|
---|
3397 | case SMB_SIGNING_DEFAULT:
|
---|
3398 | case SMB_SIGNING_IPC_DEFAULT:
|
---|
3399 | smb_panic(__location__);
|
---|
3400 | break;
|
---|
3401 | }
|
---|
3402 |
|
---|
3403 | return allowed;
|
---|
3404 | }
|
---|
3405 |
|
---|
3406 | int lpcfg_tdb_hash_size(struct loadparm_context *lp_ctx, const char *name)
|
---|
3407 | {
|
---|
3408 | const char *base;
|
---|
3409 |
|
---|
3410 | if (name == NULL) {
|
---|
3411 | return 0;
|
---|
3412 | }
|
---|
3413 |
|
---|
3414 | base = strrchr_m(name, '/');
|
---|
3415 | if (base != NULL) {
|
---|
3416 | base += 1;
|
---|
3417 | } else {
|
---|
3418 | base = name;
|
---|
3419 | }
|
---|
3420 | return lpcfg_parm_int(lp_ctx, NULL, "tdb_hashsize", base, 0);
|
---|
3421 |
|
---|
3422 | }
|
---|
3423 |
|
---|
3424 | int lpcfg_tdb_flags(struct loadparm_context *lp_ctx, int tdb_flags)
|
---|
3425 | {
|
---|
3426 | if (!lpcfg_use_mmap(lp_ctx)) {
|
---|
3427 | tdb_flags |= TDB_NOMMAP;
|
---|
3428 | }
|
---|
3429 | return tdb_flags;
|
---|
3430 | }
|
---|