Line data Source code
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 : #define LOADPARM_SUBSTITUTION_INTERNALS 1
65 : #include "lib/param/loadparm.h"
66 : #include "auth/gensec/gensec.h"
67 : #include "lib/param/s3_param.h"
68 : #include "lib/util/bitmap.h"
69 : #include "libcli/smb/smb_constants.h"
70 : #include "tdb.h"
71 : #include "librpc/gen_ndr/nbt.h"
72 : #include "librpc/gen_ndr/dns.h"
73 : #include "librpc/gen_ndr/security.h"
74 : #include "libds/common/roles.h"
75 : #include "lib/util/samba_util.h"
76 : #include "libcli/auth/ntlm_check.h"
77 : #include "lib/crypto/gnutls_helpers.h"
78 : #include "lib/util/smb_strtox.h"
79 : #include "auth/credentials/credentials.h"
80 :
81 : #ifdef HAVE_HTTPCONNECTENCRYPT
82 : #include <cups/http.h>
83 : #endif
84 :
85 : #define standard_sub_basic talloc_strdup
86 :
87 : #include "lib/param/param_global.h"
88 :
89 295087 : struct loadparm_service *lpcfg_default_service(struct loadparm_context *lp_ctx)
90 : {
91 295087 : return lp_ctx->sDefault;
92 : }
93 :
94 68 : int lpcfg_rpc_low_port(struct loadparm_context *lp_ctx)
95 : {
96 68 : return lp_ctx->globals->rpc_low_port;
97 : }
98 :
99 68 : int lpcfg_rpc_high_port(struct loadparm_context *lp_ctx)
100 : {
101 68 : return lp_ctx->globals->rpc_high_port;
102 : }
103 :
104 905480 : enum samba_weak_crypto lpcfg_weak_crypto(struct loadparm_context *lp_ctx)
105 : {
106 905480 : if (lp_ctx->globals->weak_crypto == SAMBA_WEAK_CRYPTO_UNKNOWN) {
107 52214 : lp_ctx->globals->weak_crypto = SAMBA_WEAK_CRYPTO_DISALLOWED;
108 :
109 52214 : if (samba_gnutls_weak_crypto_allowed()) {
110 52212 : lp_ctx->globals->weak_crypto = SAMBA_WEAK_CRYPTO_ALLOWED;
111 : }
112 : }
113 :
114 905480 : return lp_ctx->globals->weak_crypto;
115 : }
116 :
117 : /**
118 : * Convenience routine to grab string parameters into temporary memory
119 : * and run standard_sub_basic on them.
120 : *
121 : * The buffers can be written to by
122 : * callers without affecting the source string.
123 : */
124 :
125 12349949 : static const char *lpcfg_string(const char *s)
126 : {
127 : #if 0 /* until REWRITE done to make thread-safe */
128 : size_t len = s ? strlen(s) : 0;
129 : char *ret;
130 : #endif
131 :
132 : /* The follow debug is useful for tracking down memory problems
133 : especially if you have an inner loop that is calling a lp_*()
134 : function that returns a string. Perhaps this debug should be
135 : present all the time? */
136 :
137 : #if 0
138 : DEBUG(10, ("lpcfg_string(%s)\n", s));
139 : #endif
140 :
141 : #if 0 /* until REWRITE done to make thread-safe */
142 : if (!lp_talloc)
143 : lp_talloc = talloc_init("lp_talloc");
144 :
145 : ret = talloc_array(lp_talloc, char, len + 100); /* leave room for substitution */
146 :
147 : if (!ret)
148 : return NULL;
149 :
150 : if (!s)
151 : *ret = 0;
152 : else
153 : strlcpy(ret, s, len);
154 :
155 : if (trim_string(ret, "\"", "\"")) {
156 : if (strchr(ret,'"') != NULL)
157 : strlcpy(ret, s, len);
158 : }
159 :
160 : standard_sub_basic(ret,len+100);
161 : return (ret);
162 : #endif
163 12349949 : return s;
164 : }
165 :
166 : /*
167 : In this section all the functions that are used to access the
168 : parameters from the rest of the program are defined
169 : */
170 :
171 : /*
172 : * the creation of separate lpcfg_*() and lp_*() functions is to allow
173 : * for code compatibility between existing Samba4 and Samba3 code.
174 : */
175 :
176 : /* this global context supports the lp_*() function variants */
177 : static struct loadparm_context *global_loadparm_context;
178 :
179 : #define FN_GLOBAL_SUBSTITUTED_STRING(fn_name,var_name) \
180 : _PUBLIC_ char *lpcfg_ ## fn_name(struct loadparm_context *lp_ctx, \
181 : const struct loadparm_substitution *lp_sub, TALLOC_CTX *mem_ctx) \
182 : { \
183 : if (lp_ctx == NULL) return NULL; \
184 : return lpcfg_substituted_string(mem_ctx, lp_sub, \
185 : lp_ctx->globals->var_name ? lp_ctx->globals->var_name : ""); \
186 : }
187 :
188 : #define FN_GLOBAL_CONST_STRING(fn_name,var_name) \
189 : _PUBLIC_ const char *lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) { \
190 : if (lp_ctx == NULL) return NULL; \
191 : return lp_ctx->globals->var_name ? lpcfg_string(lp_ctx->globals->var_name) : ""; \
192 : }
193 :
194 : #define FN_GLOBAL_LIST(fn_name,var_name) \
195 : _PUBLIC_ const char **lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) { \
196 : if (lp_ctx == NULL) return NULL; \
197 : return lp_ctx->globals->var_name; \
198 : }
199 :
200 : #define FN_GLOBAL_BOOL(fn_name,var_name) \
201 : _PUBLIC_ bool lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) {\
202 : if (lp_ctx == NULL) return false; \
203 : return lp_ctx->globals->var_name; \
204 : }
205 :
206 : #define FN_GLOBAL_INTEGER(fn_name,var_name) \
207 : _PUBLIC_ int lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) { \
208 : return lp_ctx->globals->var_name; \
209 : }
210 :
211 : /* Local parameters don't need the ->s3_fns because the struct
212 : * loadparm_service is shared and lpcfg_service() checks the ->s3_fns
213 : * hook */
214 : #define FN_LOCAL_SUBSTITUTED_STRING(fn_name,val) \
215 : _PUBLIC_ char *lpcfg_ ## fn_name(struct loadparm_service *service, \
216 : struct loadparm_service *sDefault, TALLOC_CTX *ctx) { \
217 : return(talloc_strdup(ctx, lpcfg_string((const char *)((service != NULL && service->val != NULL) ? service->val : sDefault->val)))); \
218 : }
219 :
220 : #define FN_LOCAL_CONST_STRING(fn_name,val) \
221 : _PUBLIC_ const char *lpcfg_ ## fn_name(struct loadparm_service *service, \
222 : struct loadparm_service *sDefault) { \
223 : return((const char *)((service != NULL && service->val != NULL) ? service->val : sDefault->val)); \
224 : }
225 :
226 : #define FN_LOCAL_LIST(fn_name,val) \
227 : _PUBLIC_ const char **lpcfg_ ## fn_name(struct loadparm_service *service, \
228 : struct loadparm_service *sDefault) {\
229 : return(const char **)(service != NULL && service->val != NULL? service->val : sDefault->val); \
230 : }
231 :
232 : #define FN_LOCAL_PARM_BOOL(fn_name, val) FN_LOCAL_BOOL(fn_name, val)
233 :
234 : #define FN_LOCAL_BOOL(fn_name,val) \
235 : _PUBLIC_ bool lpcfg_ ## fn_name(struct loadparm_service *service, \
236 : struct loadparm_service *sDefault) { \
237 : return((service != NULL)? service->val : sDefault->val); \
238 : }
239 :
240 : #define FN_LOCAL_INTEGER(fn_name,val) \
241 : _PUBLIC_ int lpcfg_ ## fn_name(struct loadparm_service *service, \
242 : struct loadparm_service *sDefault) { \
243 : return((service != NULL)? service->val : sDefault->val); \
244 : }
245 :
246 : #define FN_LOCAL_PARM_INTEGER(fn_name, val) FN_LOCAL_INTEGER(fn_name, val)
247 :
248 : #define FN_LOCAL_CHAR(fn_name,val) \
249 : _PUBLIC_ char lpcfg_ ## fn_name(struct loadparm_service *service, \
250 : struct loadparm_service *sDefault) { \
251 : return((service != NULL)? service->val : sDefault->val); \
252 : }
253 :
254 : #define FN_LOCAL_PARM_CHAR(fn_name,val) FN_LOCAL_CHAR(fn_name, val)
255 :
256 : #include "lib/param/param_functions.c"
257 :
258 : /* These functions cannot be auto-generated */
259 0 : FN_LOCAL_BOOL(autoloaded, autoloaded)
260 5858598 : FN_GLOBAL_CONST_STRING(dnsdomain, dnsdomain)
261 :
262 : /* local prototypes */
263 : static struct loadparm_service *lpcfg_getservicebyname(struct loadparm_context *lp_ctx,
264 : const char *pszServiceName);
265 : static bool do_section(const char *pszSectionName, void *);
266 : static bool set_variable_helper(TALLOC_CTX *mem_ctx, int parmnum, void *parm_ptr,
267 : const char *pszParmName, const char *pszParmValue);
268 : static bool lp_do_parameter_parametric(struct loadparm_context *lp_ctx,
269 : struct loadparm_service *service,
270 : const char *pszParmName,
271 : const char *pszParmValue, int flags);
272 :
273 : /* The following are helper functions for parametrical options support. */
274 : /* It returns a pointer to parametrical option value if it exists or NULL otherwise */
275 : /* Actual parametrical functions are quite simple */
276 16814080 : struct parmlist_entry *get_parametric_helper(struct loadparm_service *service,
277 : const char *type, const char *option,
278 : struct parmlist_entry *global_opts)
279 16814080 : {
280 16814080 : size_t type_len = strlen(type);
281 16814080 : size_t option_len = strlen(option);
282 16814080 : char param_key[type_len + option_len + 2];
283 16814080 : struct parmlist_entry *data = NULL;
284 :
285 16814080 : snprintf(param_key, sizeof(param_key), "%s:%s", type, option);
286 :
287 : /*
288 : * Try to fetch the option from the data.
289 : */
290 16814080 : if (service != NULL) {
291 2076543 : data = service->param_opt;
292 3867229 : while (data != NULL) {
293 2027879 : if (strwicmp(data->key, param_key) == 0) {
294 237193 : return data;
295 : }
296 1790686 : data = data->next;
297 : }
298 : }
299 :
300 : /*
301 : * Fall back to fetching from the globals.
302 : */
303 12249064 : data = global_opts;
304 531052031 : while (data != NULL) {
305 516379043 : if (strwicmp(data->key, param_key) == 0) {
306 1903899 : return data;
307 : }
308 514475144 : data = data->next;
309 : }
310 :
311 10367717 : return NULL;
312 : }
313 :
314 13925320 : const char *lpcfg_get_parametric(struct loadparm_context *lp_ctx,
315 : struct loadparm_service *service,
316 : const char *type, const char *option)
317 : {
318 4316742 : struct parmlist_entry *data;
319 :
320 13925320 : if (lp_ctx == NULL)
321 0 : return NULL;
322 :
323 18242062 : data = get_parametric_helper(service,
324 13925320 : type, option, lp_ctx->globals->param_opt);
325 :
326 13925320 : if (data == NULL) {
327 8335450 : return NULL;
328 : } else {
329 1293687 : return data->value;
330 : }
331 : }
332 :
333 :
334 : /**
335 : * convenience routine to return int parameters.
336 : */
337 849350 : int lp_int(const char *s)
338 : {
339 :
340 849350 : if (!s || !*s) {
341 0 : DEBUG(0,("lp_int(%s): is called with NULL!\n",s));
342 0 : return -1;
343 : }
344 :
345 849350 : return strtol(s, NULL, 0);
346 : }
347 :
348 : /**
349 : * convenience routine to return unsigned long parameters.
350 : */
351 3906 : unsigned long lp_ulong(const char *s)
352 : {
353 3906 : int error = 0;
354 0 : unsigned long int ret;
355 :
356 3906 : if (!s || !*s) {
357 0 : DBG_DEBUG("lp_ulong(%s): is called with NULL!\n",s);
358 0 : return -1;
359 : }
360 :
361 3906 : ret = smb_strtoul(s, NULL, 0, &error, SMB_STR_STANDARD);
362 3906 : if (error != 0) {
363 0 : DBG_DEBUG("lp_ulong(%s): conversion failed\n",s);
364 0 : return -1;
365 : }
366 :
367 3906 : return ret;
368 : }
369 :
370 : /**
371 : * convenience routine to return unsigned long long parameters.
372 : */
373 411 : unsigned long long lp_ulonglong(const char *s)
374 : {
375 411 : int error = 0;
376 0 : unsigned long long int ret;
377 :
378 411 : if (!s || !*s) {
379 0 : DBG_DEBUG("lp_ulonglong(%s): is called with NULL!\n", s);
380 0 : return -1;
381 : }
382 :
383 411 : ret = smb_strtoull(s, NULL, 0, &error, SMB_STR_STANDARD);
384 411 : if (error != 0) {
385 0 : DBG_DEBUG("lp_ulonglong(%s): conversion failed\n",s);
386 0 : return -1;
387 : }
388 :
389 411 : return ret;
390 : }
391 :
392 : /**
393 : * convenience routine to return unsigned long parameters.
394 : */
395 0 : static long lp_long(const char *s)
396 : {
397 :
398 0 : if (!s) {
399 0 : DEBUG(0,("lp_long(%s): is called with NULL!\n",s));
400 0 : return -1;
401 : }
402 :
403 0 : return strtol(s, NULL, 0);
404 : }
405 :
406 : /**
407 : * convenience routine to return unsigned long parameters.
408 : */
409 1 : static double lp_double(const char *s)
410 : {
411 :
412 1 : if (!s) {
413 0 : DEBUG(0,("lp_double(%s): is called with NULL!\n",s));
414 0 : return -1;
415 : }
416 :
417 1 : return strtod(s, NULL);
418 : }
419 :
420 : /**
421 : * convenience routine to return boolean parameters.
422 : */
423 1157368 : bool lp_bool(const char *s)
424 : {
425 1157368 : bool ret = false;
426 :
427 1157368 : if (!s || !*s) {
428 28 : DEBUG(0,("lp_bool(%s): is called with NULL!\n",s));
429 28 : return false;
430 : }
431 :
432 1157340 : if (!set_boolean(s, &ret)) {
433 0 : DEBUG(0,("lp_bool(%s): value is not boolean!\n",s));
434 0 : return false;
435 : }
436 :
437 1157340 : return ret;
438 : }
439 :
440 : /**
441 : * Return parametric option from a given service. Type is a part of option before ':'
442 : * Parametric option has following syntax: 'Type: option = value'
443 : * Returned value is allocated in 'lp_talloc' context
444 : */
445 :
446 2110753 : const char *lpcfg_parm_string(struct loadparm_context *lp_ctx,
447 : struct loadparm_service *service, const char *type,
448 : const char *option)
449 : {
450 2110753 : const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
451 :
452 2110753 : if (value)
453 757037 : return lpcfg_string(value);
454 :
455 1333293 : return NULL;
456 : }
457 :
458 : /**
459 : * Return parametric option from a given service. Type is a part of option before ':'
460 : * Parametric option has following syntax: 'Type: option = value'
461 : * Returned value is allocated in 'lp_talloc' context
462 : */
463 :
464 0 : const char **lpcfg_parm_string_list(TALLOC_CTX *mem_ctx,
465 : struct loadparm_context *lp_ctx,
466 : struct loadparm_service *service,
467 : const char *type,
468 : const char *option, const char *separator)
469 : {
470 0 : const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
471 :
472 0 : if (value != NULL) {
473 0 : char **l = str_list_make(mem_ctx, value, separator);
474 0 : return discard_const_p(const char *, l);
475 : }
476 :
477 0 : return NULL;
478 : }
479 :
480 : /**
481 : * Return parametric option from a given service. Type is a part of option before ':'
482 : * Parametric option has following syntax: 'Type: option = value'
483 : */
484 :
485 773846 : int lpcfg_parm_int(struct loadparm_context *lp_ctx,
486 : struct loadparm_service *service, const char *type,
487 : const char *option, int default_v)
488 : {
489 773846 : const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
490 :
491 773846 : if (value)
492 59510 : return lp_int(value);
493 :
494 692349 : return default_v;
495 : }
496 :
497 : /**
498 : * Return parametric option from a given service. Type is a part of
499 : * option before ':'.
500 : * Parametric option has following syntax: 'Type: option = value'.
501 : */
502 :
503 2 : int lpcfg_parm_bytes(struct loadparm_context *lp_ctx,
504 : struct loadparm_service *service, const char *type,
505 : const char *option, int default_v)
506 : {
507 2 : uint64_t bval;
508 :
509 2 : const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
510 :
511 2 : if (value && conv_str_size_error(value, &bval)) {
512 1 : if (bval <= INT_MAX) {
513 1 : return (int)bval;
514 : }
515 : }
516 :
517 0 : return default_v;
518 : }
519 :
520 : /**
521 : * Return parametric option from a given service.
522 : * Type is a part of option before ':'
523 : * Parametric option has following syntax: 'Type: option = value'
524 : */
525 59754 : unsigned long lpcfg_parm_ulong(struct loadparm_context *lp_ctx,
526 : struct loadparm_service *service, const char *type,
527 : const char *option, unsigned long default_v)
528 : {
529 59754 : const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
530 :
531 59754 : if (value)
532 3880 : return lp_ulong(value);
533 :
534 54994 : return default_v;
535 : }
536 :
537 : /**
538 : * Return parametric option from a given service.
539 : * Type is a part of option before ':'
540 : * Parametric option has following syntax: 'Type: option = value'
541 : */
542 0 : unsigned long long lpcfg_parm_ulonglong(struct loadparm_context *lp_ctx,
543 : struct loadparm_service *service,
544 : const char *type, const char *option,
545 : unsigned long long default_v)
546 : {
547 0 : const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
548 :
549 0 : if (value) {
550 0 : return lp_ulonglong(value);
551 : }
552 :
553 0 : return default_v;
554 : }
555 :
556 889 : long lpcfg_parm_long(struct loadparm_context *lp_ctx,
557 : struct loadparm_service *service, const char *type,
558 : const char *option, long default_v)
559 : {
560 889 : const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
561 :
562 889 : if (value)
563 0 : return lp_long(value);
564 :
565 865 : return default_v;
566 : }
567 :
568 2 : double lpcfg_parm_double(struct loadparm_context *lp_ctx,
569 : struct loadparm_service *service, const char *type,
570 : const char *option, double default_v)
571 : {
572 2 : const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
573 :
574 2 : if (value != NULL)
575 1 : return lp_double(value);
576 :
577 0 : return default_v;
578 : }
579 :
580 : /**
581 : * Return parametric option from a given service. Type is a part of option before ':'
582 : * Parametric option has following syntax: 'Type: option = value'
583 : */
584 :
585 10933396 : bool lpcfg_parm_bool(struct loadparm_context *lp_ctx,
586 : struct loadparm_service *service, const char *type,
587 : const char *option, bool default_v)
588 : {
589 10933396 : const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
590 :
591 10933396 : if (value != NULL)
592 432524 : return lp_bool(value);
593 :
594 6248938 : return default_v;
595 : }
596 :
597 :
598 : /* this is used to prevent lots of mallocs of size 1 */
599 : static const char lpcfg_string_empty[] = "";
600 :
601 : /**
602 : Free a string value.
603 : **/
604 106042810 : void lpcfg_string_free(char **s)
605 : {
606 106042810 : if (s == NULL) {
607 0 : return;
608 : }
609 106042810 : if (*s == lpcfg_string_empty) {
610 37756964 : *s = NULL;
611 37756964 : return;
612 : }
613 68285846 : TALLOC_FREE(*s);
614 : }
615 :
616 : /**
617 : * Set a string value, deallocating any existing space, and allocing the space
618 : * for the string
619 : */
620 82842379 : bool lpcfg_string_set(TALLOC_CTX *mem_ctx, char **dest, const char *src)
621 : {
622 82842379 : lpcfg_string_free(dest);
623 :
624 82842379 : if ((src == NULL) || (*src == '\0')) {
625 45538963 : *dest = discard_const_p(char, lpcfg_string_empty);
626 45538963 : return true;
627 : }
628 :
629 37303416 : *dest = talloc_strdup(mem_ctx, src);
630 37303416 : if ((*dest) == NULL) {
631 0 : DEBUG(0,("Out of memory in string_set\n"));
632 0 : return false;
633 : }
634 :
635 37183706 : return true;
636 : }
637 :
638 : /**
639 : * Set a string value, deallocating any existing space, and allocing the space
640 : * for the string
641 : */
642 181015 : bool lpcfg_string_set_upper(TALLOC_CTX *mem_ctx, char **dest, const char *src)
643 : {
644 181015 : lpcfg_string_free(dest);
645 :
646 181015 : if ((src == NULL) || (*src == '\0')) {
647 6 : *dest = discard_const_p(char, lpcfg_string_empty);
648 6 : return true;
649 : }
650 :
651 181009 : *dest = strupper_talloc(mem_ctx, src);
652 181009 : if ((*dest) == NULL) {
653 0 : DEBUG(0,("Out of memory in string_set_upper\n"));
654 0 : return false;
655 : }
656 :
657 178699 : return true;
658 : }
659 :
660 :
661 :
662 : /**
663 : * Add a new service to the services array initialising it with the given
664 : * service.
665 : */
666 :
667 306573 : struct loadparm_service *lpcfg_add_service(struct loadparm_context *lp_ctx,
668 : const struct loadparm_service *pservice,
669 : const char *name)
670 : {
671 2892 : int i;
672 306573 : int num_to_alloc = lp_ctx->iNumServices + 1;
673 2892 : struct parmlist_entry *data, *pdata;
674 :
675 306573 : if (lp_ctx->s3_fns != NULL) {
676 0 : smb_panic("Add a service should not be called on an s3 loadparm ctx");
677 : }
678 :
679 306573 : if (pservice == NULL) {
680 68 : pservice = lp_ctx->sDefault;
681 : }
682 :
683 : /* it might already exist */
684 306573 : if (name) {
685 306573 : struct loadparm_service *service = lpcfg_getservicebyname(lp_ctx,
686 : name);
687 306573 : if (service != NULL) {
688 : /* Clean all parametric options for service */
689 : /* They will be added during parsing again */
690 215542 : data = service->param_opt;
691 662416 : while (data) {
692 446874 : pdata = data->next;
693 446874 : talloc_free(data);
694 446874 : data = pdata;
695 : }
696 215542 : service->param_opt = NULL;
697 215542 : return service;
698 : }
699 : }
700 :
701 : /* find an invalid one */
702 1691566 : for (i = 0; i < lp_ctx->iNumServices; i++)
703 1600535 : if (lp_ctx->services[i] == NULL)
704 0 : break;
705 :
706 : /* if not, then create one */
707 91031 : if (i == lp_ctx->iNumServices) {
708 1965 : struct loadparm_service **tsp;
709 :
710 91031 : tsp = talloc_realloc(lp_ctx, lp_ctx->services, struct loadparm_service *, num_to_alloc);
711 :
712 91031 : if (!tsp) {
713 0 : DEBUG(0,("lpcfg_add_service: failed to enlarge services!\n"));
714 0 : return NULL;
715 : } else {
716 91031 : lp_ctx->services = tsp;
717 91031 : lp_ctx->services[lp_ctx->iNumServices] = NULL;
718 : }
719 :
720 91031 : lp_ctx->iNumServices++;
721 : }
722 :
723 91031 : lp_ctx->services[i] = talloc_zero(lp_ctx->services, struct loadparm_service);
724 91031 : if (lp_ctx->services[i] == NULL) {
725 0 : DEBUG(0,("lpcfg_add_service: out of memory!\n"));
726 0 : return NULL;
727 : }
728 91031 : copy_service(lp_ctx->services[i], pservice, NULL);
729 91031 : if (name != NULL)
730 91031 : lpcfg_string_set(lp_ctx->services[i], &lp_ctx->services[i]->szService, name);
731 91031 : return lp_ctx->services[i];
732 : }
733 :
734 : /**
735 : * Map a parameter's string representation to something we can use.
736 : * Returns False if the parameter string is not recognised, else TRUE.
737 : */
738 :
739 23431176 : int lpcfg_map_parameter(const char *pszParmName)
740 : {
741 212231 : int iIndex;
742 :
743 7737452672 : for (iIndex = 0; parm_table[iIndex].label; iIndex++)
744 7731994598 : if (strwicmp(parm_table[iIndex].label, pszParmName) == 0)
745 17973102 : return iIndex;
746 :
747 : /* Warn only if it isn't parametric option */
748 5458074 : if (strchr(pszParmName, ':') == NULL)
749 5 : DEBUG(0, ("Unknown parameter encountered: \"%s\"\n", pszParmName));
750 : /* We do return 'fail' for parametric options as well because they are
751 : stored in different storage
752 : */
753 5441971 : return -1;
754 : }
755 :
756 :
757 : /**
758 : return the parameter structure for a parameter
759 : */
760 41130 : struct parm_struct *lpcfg_parm_struct(struct loadparm_context *lp_ctx, const char *name)
761 : {
762 41130 : int num = lpcfg_map_parameter(name);
763 :
764 41130 : if (num < 0) {
765 0 : return NULL;
766 : }
767 :
768 41129 : return &parm_table[num];
769 : }
770 :
771 : /**
772 : return the parameter pointer for a parameter
773 : */
774 7458940 : void *lpcfg_parm_ptr(struct loadparm_context *lp_ctx,
775 : struct loadparm_service *service, struct parm_struct *parm)
776 : {
777 7458940 : if (lp_ctx->s3_fns) {
778 3033736 : return lp_ctx->s3_fns->get_parm_ptr(service, parm);
779 : }
780 :
781 4425204 : if (service == NULL) {
782 4419916 : if (parm->p_class == P_LOCAL)
783 603820 : return ((char *)lp_ctx->sDefault)+parm->offset;
784 3816096 : else if (parm->p_class == P_GLOBAL)
785 3816096 : return ((char *)lp_ctx->globals)+parm->offset;
786 0 : else return NULL;
787 : } else {
788 5288 : return ((char *)service) + parm->offset;
789 : }
790 : }
791 :
792 : /**
793 : return the parameter pointer for a parameter
794 : */
795 721962 : bool lpcfg_parm_is_cmdline(struct loadparm_context *lp_ctx, const char *name)
796 : {
797 11253 : int parmnum;
798 :
799 721962 : parmnum = lpcfg_map_parameter(name);
800 721962 : if (parmnum == -1) return false;
801 :
802 721962 : return lp_ctx->flags[parmnum] & FLAG_CMDLINE;
803 : }
804 :
805 0 : bool lpcfg_parm_is_unspecified(struct loadparm_context *lp_ctx, const char *name)
806 : {
807 0 : int parmnum;
808 :
809 0 : parmnum = lpcfg_map_parameter(name);
810 0 : if (parmnum == -1) return false;
811 :
812 0 : return lp_ctx->flags[parmnum] & FLAG_DEFAULT;
813 : }
814 :
815 : /**
816 : * Find a service by name. Otherwise works like get_service.
817 : */
818 :
819 1308913 : static struct loadparm_service *lpcfg_getservicebyname(struct loadparm_context *lp_ctx,
820 : const char *pszServiceName)
821 : {
822 4368 : int iService;
823 :
824 1308913 : if (lp_ctx->s3_fns) {
825 878190 : return lp_ctx->s3_fns->get_service(pszServiceName);
826 : }
827 :
828 6984295 : for (iService = lp_ctx->iNumServices - 1; iService >= 0; iService--)
829 13786526 : if (lp_ctx->services[iService] != NULL &&
830 6893263 : strwicmp(lp_ctx->services[iService]->szService, pszServiceName) == 0) {
831 339691 : return lp_ctx->services[iService];
832 : }
833 :
834 89067 : return NULL;
835 : }
836 :
837 : /**
838 : * Add a parametric option to a parmlist_entry,
839 : * replacing old value, if already present.
840 : */
841 5811224 : void set_param_opt(TALLOC_CTX *mem_ctx,
842 : struct parmlist_entry **opt_list,
843 : const char *opt_name,
844 : const char *opt_value,
845 : unsigned priority)
846 : {
847 20156 : struct parmlist_entry *new_opt, *opt;
848 :
849 5811224 : opt = *opt_list;
850 :
851 : /* Traverse destination */
852 48351357 : while (opt) {
853 : /* If we already have same option, override it */
854 43125021 : if (strwicmp(opt->key, opt_name) == 0) {
855 584888 : if ((opt->priority & FLAG_CMDLINE) &&
856 6957 : !(priority & FLAG_CMDLINE)) {
857 : /* it's been marked as not to be
858 : overridden */
859 416 : return;
860 : }
861 584466 : TALLOC_FREE(opt->list);
862 584466 : lpcfg_string_set(opt, &opt->value, opt_value);
863 584466 : opt->priority = priority;
864 584466 : return;
865 : }
866 42540133 : opt = opt->next;
867 : }
868 :
869 5226336 : new_opt = talloc_pooled_object(
870 : mem_ctx, struct parmlist_entry,
871 : 2, strlen(opt_name) + 1 + strlen(opt_value) + 1);
872 5226336 : if (new_opt == NULL) {
873 0 : smb_panic("OOM");
874 : }
875 5226336 : new_opt->key = NULL;
876 5226336 : lpcfg_string_set(new_opt, &new_opt->key, opt_name);
877 5226336 : new_opt->value = NULL;
878 5226336 : lpcfg_string_set(new_opt, &new_opt->value, opt_value);
879 :
880 5226336 : new_opt->list = NULL;
881 5226336 : new_opt->priority = priority;
882 5226336 : DLIST_ADD(*opt_list, new_opt);
883 : }
884 :
885 : /**
886 : * Copy a service structure to another.
887 : * If pcopymapDest is NULL then copy all fields
888 : */
889 :
890 1290224 : void copy_service(struct loadparm_service *pserviceDest,
891 : const struct loadparm_service *pserviceSource,
892 : struct bitmap *pcopymapDest)
893 : {
894 3509 : int i;
895 1290224 : bool bcopyall = (pcopymapDest == NULL);
896 3509 : struct parmlist_entry *data;
897 :
898 673496928 : for (i = 0; parm_table[i].label; i++)
899 672206704 : if (parm_table[i].p_class == P_LOCAL &&
900 157367066 : (bcopyall || bitmap_query(pcopymapDest, i))) {
901 200059582 : const void *src_ptr =
902 200059582 : ((const char *)pserviceSource) + parm_table[i].offset;
903 200059582 : void *dest_ptr =
904 199510745 : ((char *)pserviceDest) + parm_table[i].offset;
905 :
906 200059582 : switch (parm_table[i].type) {
907 98835139 : case P_BOOL:
908 : case P_BOOLREV:
909 98835139 : *(bool *)dest_ptr = *(const bool *)src_ptr;
910 98835139 : break;
911 :
912 39850937 : case P_INTEGER:
913 : case P_BYTES:
914 : case P_OCTAL:
915 : case P_ENUM:
916 39850937 : *(int *)dest_ptr = *(const int *)src_ptr;
917 39850937 : break;
918 :
919 1290224 : case P_CHAR:
920 1290224 : *(char *)dest_ptr = *(const char *)src_ptr;
921 1290224 : break;
922 :
923 43839416 : case P_STRING:
924 43839416 : lpcfg_string_set(pserviceDest,
925 : (char **)dest_ptr,
926 : *(const char * const *)src_ptr);
927 43839416 : break;
928 :
929 0 : case P_USTRING:
930 0 : lpcfg_string_set_upper(pserviceDest,
931 : (char **)dest_ptr,
932 : *(const char * const *)src_ptr);
933 0 : break;
934 16243866 : case P_CMDLIST:
935 : case P_LIST:
936 16243866 : TALLOC_FREE(*((char ***)dest_ptr));
937 16243866 : *(char ***)dest_ptr = str_list_copy(pserviceDest,
938 : *discard_const_p(const char **, src_ptr));
939 16243866 : break;
940 0 : default:
941 0 : break;
942 : }
943 : }
944 :
945 1290224 : if (bcopyall) {
946 287886 : init_copymap(pserviceDest);
947 287886 : if (pserviceSource->copymap)
948 11529 : bitmap_copy(pserviceDest->copymap,
949 11529 : pserviceSource->copymap);
950 : }
951 :
952 1646162 : for (data = pserviceSource->param_opt; data != NULL; data = data->next) {
953 355938 : set_param_opt(pserviceDest, &pserviceDest->param_opt,
954 355938 : data->key, data->value, data->priority);
955 : }
956 1290224 : }
957 :
958 : /**
959 : * Check a service for consistency. Return False if the service is in any way
960 : * incomplete or faulty, else True.
961 : */
962 3310996 : bool lpcfg_service_ok(struct loadparm_service *service)
963 : {
964 3035 : bool bRetval;
965 :
966 3310996 : bRetval = true;
967 3310996 : if (service->szService[0] == '\0') {
968 0 : DEBUG(0, ("The following message indicates an internal error:\n"));
969 0 : DEBUG(0, ("No service name in service entry.\n"));
970 0 : bRetval = false;
971 : }
972 :
973 : /* The [printers] entry MUST be printable. I'm all for flexibility, but */
974 : /* I can't see why you'd want a non-printable printer service... */
975 3310996 : if (strwicmp(service->szService, PRINTERS_NAME) == 0) {
976 0 : if (!service->printable) {
977 0 : DEBUG(0, ("WARNING: [%s] service MUST be printable!\n",
978 : service->szService));
979 0 : service->printable = true;
980 : }
981 : /* [printers] service must also be non-browsable. */
982 0 : if (service->browseable)
983 0 : service->browseable = false;
984 : }
985 :
986 3322592 : if (service->path[0] == '\0' &&
987 11596 : strwicmp(service->szService, HOMES_NAME) != 0 &&
988 2 : service->msdfs_proxy[0] == '\0')
989 : {
990 2 : DEBUG(0, ("WARNING: No path in service %s - making it unavailable!\n",
991 : service->szService));
992 2 : service->available = false;
993 : }
994 :
995 3310996 : if (!service->available)
996 2 : DEBUG(1, ("NOTE: Service %s is flagged unavailable.\n",
997 : service->szService));
998 :
999 3310996 : return bRetval;
1000 : }
1001 :
1002 :
1003 : /*******************************************************************
1004 : Keep a linked list of all config files so we know when one has changed
1005 : it's date and needs to be reloaded.
1006 : ********************************************************************/
1007 :
1008 255148 : void add_to_file_list(TALLOC_CTX *mem_ctx, struct file_lists **list,
1009 : const char *fname, const char *subfname)
1010 : {
1011 255148 : struct file_lists *f = *list;
1012 :
1013 623339 : while (f) {
1014 435343 : if (f->name && !strcmp(f->name, fname))
1015 67035 : break;
1016 368191 : f = f->next;
1017 : }
1018 :
1019 255148 : if (!f) {
1020 187996 : f = talloc_zero(mem_ctx, struct file_lists);
1021 187996 : if (!f)
1022 0 : goto fail;
1023 187996 : f->next = *list;
1024 187996 : f->name = talloc_strdup(f, fname);
1025 187996 : if (!f->name) {
1026 0 : TALLOC_FREE(f);
1027 0 : goto fail;
1028 : }
1029 187996 : f->subfname = talloc_strdup(f, subfname);
1030 187996 : if (!f->subfname) {
1031 0 : TALLOC_FREE(f);
1032 0 : goto fail;
1033 : }
1034 187996 : *list = f;
1035 : }
1036 :
1037 : /* If file_modtime() fails it leaves f->modtime as zero. */
1038 255148 : (void)file_modtime(subfname, &f->modtime);
1039 255148 : return;
1040 :
1041 0 : fail:
1042 0 : DEBUG(0, ("Unable to add file to file list: %s\n", fname));
1043 :
1044 : }
1045 :
1046 : /*
1047 : * set the value for a P_ENUM
1048 : */
1049 1893337 : bool lp_set_enum_parm( struct parm_struct *parm, const char *pszParmValue,
1050 : int *ptr )
1051 : {
1052 41388 : int i;
1053 :
1054 8137035 : for (i = 0; parm->enum_list[i].name; i++) {
1055 8137031 : if (strwicmp(pszParmValue, parm->enum_list[i].name) == 0) {
1056 1893333 : *ptr = parm->enum_list[i].value;
1057 1893333 : return true;
1058 : }
1059 : }
1060 4 : DEBUG(0, ("WARNING: Ignoring invalid value '%s' for parameter '%s'\n",
1061 : pszParmValue, parm->label));
1062 2 : return false;
1063 : }
1064 :
1065 :
1066 : /***************************************************************************
1067 : Handle the "realm" parameter
1068 : ***************************************************************************/
1069 :
1070 35432 : bool handle_realm(struct loadparm_context *lp_ctx, struct loadparm_service *service,
1071 : const char *pszParmValue, char **ptr)
1072 : {
1073 265 : char *upper;
1074 265 : char *lower;
1075 :
1076 35432 : upper = strupper_talloc(lp_ctx, pszParmValue);
1077 35432 : if (upper == NULL) {
1078 0 : return false;
1079 : }
1080 :
1081 35432 : lower = strlower_talloc(lp_ctx, pszParmValue);
1082 35432 : if (lower == NULL) {
1083 0 : TALLOC_FREE(upper);
1084 0 : return false;
1085 : }
1086 :
1087 35432 : lpcfg_string_set(lp_ctx->globals->ctx, &lp_ctx->globals->realm, upper);
1088 35432 : lpcfg_string_set(lp_ctx->globals->ctx, &lp_ctx->globals->dnsdomain, lower);
1089 :
1090 35432 : return true;
1091 : }
1092 :
1093 : /***************************************************************************
1094 : Handle the include operation.
1095 : ***************************************************************************/
1096 :
1097 174307 : bool handle_include(struct loadparm_context *lp_ctx, struct loadparm_service *service,
1098 : const char *pszParmValue, char **ptr)
1099 : {
1100 0 : char *fname;
1101 0 : const char *substitution_variable_substring;
1102 0 : char next_char;
1103 :
1104 174307 : if (lp_ctx->s3_fns) {
1105 172613 : return lp_ctx->s3_fns->lp_include(lp_ctx, service, pszParmValue, ptr);
1106 : }
1107 :
1108 1694 : fname = standard_sub_basic(lp_ctx, pszParmValue);
1109 :
1110 1694 : add_to_file_list(lp_ctx, &lp_ctx->file_lists, pszParmValue, fname);
1111 :
1112 1694 : lpcfg_string_set(lp_ctx, ptr, fname);
1113 :
1114 1694 : if (file_exist(fname))
1115 1450 : return pm_process(fname, do_section, lpcfg_do_parameter, lp_ctx);
1116 :
1117 : /*
1118 : * If the file doesn't exist, we check that it isn't due to variable
1119 : * substitution
1120 : */
1121 244 : substitution_variable_substring = strchr(fname, '%');
1122 :
1123 244 : if (substitution_variable_substring != NULL) {
1124 239 : next_char = substitution_variable_substring[1];
1125 239 : if ((next_char >= 'a' && next_char <= 'z')
1126 239 : || (next_char >= 'A' && next_char <= 'Z')) {
1127 239 : DEBUG(2, ("Tried to load %s but variable substitution in "
1128 : "filename, ignoring file.\n", fname));
1129 239 : return true;
1130 : }
1131 : }
1132 :
1133 5 : DEBUG(2, ("Can't find include file %s\n", fname));
1134 :
1135 5 : return false;
1136 : }
1137 :
1138 : /***************************************************************************
1139 : Handle the interpretation of the copy parameter.
1140 : ***************************************************************************/
1141 :
1142 1002340 : bool handle_copy(struct loadparm_context *lp_ctx, struct loadparm_service *service,
1143 : const char *pszParmValue, char **ptr)
1144 : {
1145 1476 : bool bRetval;
1146 1002340 : struct loadparm_service *serviceTemp = NULL;
1147 :
1148 1002340 : bRetval = false;
1149 :
1150 1002340 : DEBUG(3, ("Copying service from service %s\n", pszParmValue));
1151 :
1152 1002340 : serviceTemp = lpcfg_getservicebyname(lp_ctx, pszParmValue);
1153 :
1154 1002340 : if (service == NULL) {
1155 2 : DEBUG(0, ("Unable to copy service - invalid service destination.\n"));
1156 2 : return false;
1157 : }
1158 :
1159 1002338 : if (serviceTemp != NULL) {
1160 1002338 : if (serviceTemp == service) {
1161 0 : DEBUG(0, ("Can't copy service %s - unable to copy self!\n", pszParmValue));
1162 : } else {
1163 1002338 : copy_service(service,
1164 : serviceTemp,
1165 : service->copymap);
1166 1002338 : lpcfg_string_set(service, ptr, pszParmValue);
1167 :
1168 1002338 : bRetval = true;
1169 : }
1170 : } else {
1171 0 : DEBUG(0, ("Unable to copy service - source not found: %s\n",
1172 : pszParmValue));
1173 0 : bRetval = false;
1174 : }
1175 :
1176 1000862 : return bRetval;
1177 : }
1178 :
1179 111870 : bool handle_debug_list(struct loadparm_context *lp_ctx, struct loadparm_service *service,
1180 : const char *pszParmValue, char **ptr)
1181 : {
1182 111870 : lpcfg_string_set(lp_ctx->globals->ctx, ptr, pszParmValue);
1183 :
1184 111870 : return debug_parse_levels(pszParmValue);
1185 : }
1186 :
1187 93050 : bool handle_logfile(struct loadparm_context *lp_ctx, struct loadparm_service *service,
1188 : const char *pszParmValue, char **ptr)
1189 : {
1190 93050 : if (lp_ctx->s3_fns == NULL) {
1191 34210 : debug_set_logfile(pszParmValue);
1192 : }
1193 :
1194 93050 : lpcfg_string_set(lp_ctx->globals->ctx, ptr, pszParmValue);
1195 :
1196 93050 : return true;
1197 : }
1198 :
1199 : /*
1200 : * These special charset handling methods only run in the source3 code.
1201 : */
1202 :
1203 12573 : bool handle_charset(struct loadparm_context *lp_ctx, struct loadparm_service *service,
1204 : const char *pszParmValue, char **ptr)
1205 : {
1206 12573 : if (lp_ctx->s3_fns) {
1207 12 : if (*ptr == NULL || strcmp(*ptr, pszParmValue) != 0) {
1208 10 : struct smb_iconv_handle *ret = NULL;
1209 :
1210 10 : ret = reinit_iconv_handle(NULL,
1211 : lpcfg_dos_charset(lp_ctx),
1212 : lpcfg_unix_charset(lp_ctx));
1213 10 : if (ret == NULL) {
1214 0 : smb_panic("reinit_iconv_handle failed");
1215 : }
1216 : }
1217 :
1218 : }
1219 12573 : return lpcfg_string_set(lp_ctx->globals->ctx, ptr, pszParmValue);
1220 :
1221 : }
1222 :
1223 12576 : bool handle_dos_charset(struct loadparm_context *lp_ctx, struct loadparm_service *service,
1224 : const char *pszParmValue, char **ptr)
1225 : {
1226 12576 : bool is_utf8 = false;
1227 12576 : size_t len = strlen(pszParmValue);
1228 :
1229 12576 : if (lp_ctx->s3_fns) {
1230 4 : if (len == 4 || len == 5) {
1231 : /* Don't use StrCaseCmp here as we don't want to
1232 : initialize iconv. */
1233 0 : if ((toupper_m(pszParmValue[0]) == 'U') &&
1234 0 : (toupper_m(pszParmValue[1]) == 'T') &&
1235 0 : (toupper_m(pszParmValue[2]) == 'F')) {
1236 0 : if (len == 4) {
1237 0 : if (pszParmValue[3] == '8') {
1238 0 : is_utf8 = true;
1239 : }
1240 : } else {
1241 0 : if (pszParmValue[3] == '-' &&
1242 0 : pszParmValue[4] == '8') {
1243 0 : is_utf8 = true;
1244 : }
1245 : }
1246 : }
1247 : }
1248 :
1249 4 : if (*ptr == NULL || strcmp(*ptr, pszParmValue) != 0) {
1250 4 : struct smb_iconv_handle *ret = NULL;
1251 4 : if (is_utf8) {
1252 0 : DEBUG(0,("ERROR: invalid DOS charset: 'dos charset' must not "
1253 : "be UTF8, using (default value) %s instead.\n",
1254 : DEFAULT_DOS_CHARSET));
1255 0 : pszParmValue = DEFAULT_DOS_CHARSET;
1256 : }
1257 4 : ret = reinit_iconv_handle(NULL,
1258 : lpcfg_dos_charset(lp_ctx),
1259 : lpcfg_unix_charset(lp_ctx));
1260 4 : if (ret == NULL) {
1261 0 : smb_panic("reinit_iconv_handle failed");
1262 : }
1263 : }
1264 : }
1265 :
1266 12576 : return lpcfg_string_set(lp_ctx->globals->ctx, ptr, pszParmValue);
1267 : }
1268 :
1269 82280 : bool handle_printing(struct loadparm_context *lp_ctx, struct loadparm_service *service,
1270 : const char *pszParmValue, char **ptr)
1271 : {
1272 246 : static int parm_num = -1;
1273 :
1274 82280 : if (parm_num == -1) {
1275 7640 : parm_num = lpcfg_map_parameter("printing");
1276 : }
1277 :
1278 82280 : if (!lp_set_enum_parm(&parm_table[parm_num], pszParmValue, (int*)ptr)) {
1279 0 : return false;
1280 : }
1281 :
1282 82280 : if (lp_ctx->s3_fns) {
1283 63440 : if (service == NULL) {
1284 63440 : init_printer_values(lp_ctx, lp_ctx->globals->ctx, lp_ctx->sDefault);
1285 : } else {
1286 0 : init_printer_values(lp_ctx, service, service);
1287 : }
1288 : }
1289 :
1290 82034 : return true;
1291 : }
1292 :
1293 11 : bool handle_ldap_debug_level(struct loadparm_context *lp_ctx, struct loadparm_service *service,
1294 : const char *pszParmValue, char **ptr)
1295 : {
1296 11 : lp_ctx->globals->ldap_debug_level = lp_int(pszParmValue);
1297 :
1298 11 : if (lp_ctx->s3_fns) {
1299 8 : lp_ctx->s3_fns->init_ldap_debugging();
1300 : }
1301 11 : return true;
1302 : }
1303 :
1304 : /*
1305 : * idmap related parameters
1306 : */
1307 :
1308 12567 : bool handle_idmap_backend(struct loadparm_context *lp_ctx, struct loadparm_service *service,
1309 : const char *pszParmValue, char **ptr)
1310 : {
1311 12567 : if (lp_ctx->s3_fns) {
1312 6 : lp_do_parameter_parametric(lp_ctx, service, "idmap config * : backend",
1313 : pszParmValue, 0);
1314 : }
1315 :
1316 12567 : return lpcfg_string_set(lp_ctx->globals->ctx, ptr, pszParmValue);
1317 : }
1318 :
1319 9 : bool handle_idmap_uid(struct loadparm_context *lp_ctx, struct loadparm_service *service,
1320 : const char *pszParmValue, char **ptr)
1321 : {
1322 9 : if (lp_ctx->s3_fns) {
1323 6 : lp_do_parameter_parametric(lp_ctx, service, "idmap config * : range",
1324 : pszParmValue, 0);
1325 : }
1326 :
1327 9 : return lpcfg_string_set(lp_ctx->globals->ctx, ptr, pszParmValue);
1328 : }
1329 :
1330 9 : bool handle_idmap_gid(struct loadparm_context *lp_ctx, struct loadparm_service *service,
1331 : const char *pszParmValue, char **ptr)
1332 : {
1333 9 : if (lp_ctx->s3_fns) {
1334 6 : lp_do_parameter_parametric(lp_ctx, service, "idmap config * : range",
1335 : pszParmValue, 0);
1336 : }
1337 :
1338 9 : return lpcfg_string_set(lp_ctx->globals->ctx, ptr, pszParmValue);
1339 : }
1340 :
1341 12561 : bool handle_smb_ports(struct loadparm_context *lp_ctx, struct loadparm_service *service,
1342 : const char *pszParmValue, char **ptr)
1343 : {
1344 616 : static int parm_num = -1;
1345 616 : int i;
1346 616 : const char **list;
1347 :
1348 12561 : if (!pszParmValue || !*pszParmValue) {
1349 0 : return false;
1350 : }
1351 :
1352 12561 : if (parm_num == -1) {
1353 12389 : parm_num = lpcfg_map_parameter("smb ports");
1354 12389 : if (parm_num == -1) {
1355 0 : return false;
1356 : }
1357 : }
1358 :
1359 12561 : if (!set_variable_helper(lp_ctx->globals->ctx, parm_num, ptr, "smb ports",
1360 : pszParmValue)) {
1361 0 : return false;
1362 : }
1363 :
1364 12561 : list = lp_ctx->globals->smb_ports;
1365 12561 : if (list == NULL) {
1366 0 : return false;
1367 : }
1368 :
1369 : /* Check that each port is a valid integer and within range */
1370 37683 : for (i = 0; list[i] != NULL; i++) {
1371 25122 : char *end = NULL;
1372 25122 : int port = 0;
1373 25122 : port = strtol(list[i], &end, 10);
1374 25122 : if (*end != '\0' || port <= 0 || port > 65535) {
1375 0 : TALLOC_FREE(list);
1376 0 : return false;
1377 : }
1378 : }
1379 :
1380 11945 : return true;
1381 : }
1382 :
1383 12561 : bool handle_rpc_server_dynamic_port_range(struct loadparm_context *lp_ctx,
1384 : struct loadparm_service *service,
1385 : const char *pszParmValue,
1386 : char **ptr)
1387 : {
1388 616 : static int parm_num = -1;
1389 12561 : int low_port = -1, high_port = -1;
1390 616 : int rc;
1391 :
1392 12561 : if (parm_num == -1) {
1393 12389 : parm_num = lpcfg_map_parameter("rpc server dynamic port range");
1394 12389 : if (parm_num == -1) {
1395 0 : return false;
1396 : }
1397 : }
1398 :
1399 12561 : if (pszParmValue == NULL || pszParmValue[0] == '\0') {
1400 0 : return false;
1401 : }
1402 :
1403 12561 : rc = sscanf(pszParmValue, "%d - %d", &low_port, &high_port);
1404 12561 : if (rc != 2) {
1405 0 : return false;
1406 : }
1407 :
1408 12561 : if (low_port > high_port) {
1409 0 : return false;
1410 : }
1411 :
1412 12561 : if (low_port < SERVER_TCP_PORT_MIN|| high_port > SERVER_TCP_PORT_MAX) {
1413 0 : return false;
1414 : }
1415 :
1416 12561 : if (!set_variable_helper(lp_ctx->globals->ctx, parm_num, ptr,
1417 : "rpc server dynamic port range",
1418 : pszParmValue)) {
1419 0 : return false;
1420 : }
1421 :
1422 12561 : lp_ctx->globals->rpc_low_port = low_port;
1423 12561 : lp_ctx->globals->rpc_high_port = high_port;
1424 :
1425 12561 : return true;
1426 : }
1427 :
1428 12567 : bool handle_smb2_max_credits(struct loadparm_context *lp_ctx,
1429 : struct loadparm_service *service,
1430 : const char *pszParmValue, char **ptr)
1431 : {
1432 12567 : int value = lp_int(pszParmValue);
1433 :
1434 12567 : if (value <= 0) {
1435 0 : value = DEFAULT_SMB2_MAX_CREDITS;
1436 : }
1437 :
1438 12567 : *(int *)ptr = value;
1439 :
1440 12567 : return true;
1441 : }
1442 :
1443 0 : bool handle_cups_encrypt(struct loadparm_context *lp_ctx,
1444 : struct loadparm_service *service,
1445 : const char *pszParmValue, char **ptr)
1446 : {
1447 0 : int result = 0;
1448 : #ifdef HAVE_HTTPCONNECTENCRYPT
1449 0 : int value = lp_int(pszParmValue);
1450 :
1451 0 : switch (value) {
1452 0 : case Auto:
1453 0 : result = HTTP_ENCRYPT_REQUIRED;
1454 0 : break;
1455 0 : case true:
1456 0 : result = HTTP_ENCRYPT_ALWAYS;
1457 0 : break;
1458 0 : case false:
1459 0 : result = HTTP_ENCRYPT_NEVER;
1460 0 : break;
1461 0 : default:
1462 0 : result = 0;
1463 0 : break;
1464 : }
1465 : #endif
1466 0 : *(int *)ptr = result;
1467 :
1468 0 : return true;
1469 : }
1470 :
1471 : /***************************************************************************
1472 : Initialise a copymap.
1473 : ***************************************************************************/
1474 :
1475 : /**
1476 : * Initializes service copymap
1477 : * Note: pservice *must* be valid TALLOC_CTX
1478 : */
1479 287886 : void init_copymap(struct loadparm_service *pservice)
1480 : {
1481 2033 : int i;
1482 :
1483 287886 : TALLOC_FREE(pservice->copymap);
1484 :
1485 287886 : pservice->copymap = bitmap_talloc(pservice, num_parameters());
1486 287886 : if (!pservice->copymap) {
1487 0 : DEBUG(0,
1488 : ("Couldn't allocate copymap!! (size %d)\n",
1489 : (int)num_parameters()));
1490 : } else {
1491 150564378 : for (i = 0; i < num_parameters(); i++) {
1492 150276492 : bitmap_set(pservice->copymap, i);
1493 : }
1494 : }
1495 287886 : }
1496 :
1497 : /**
1498 : * Process a parametric option
1499 : */
1500 5454647 : static bool lp_do_parameter_parametric(struct loadparm_context *lp_ctx,
1501 : struct loadparm_service *service,
1502 : const char *pszParmName,
1503 : const char *pszParmValue, int flags)
1504 : {
1505 16091 : struct parmlist_entry **data;
1506 16091 : char *name;
1507 16091 : TALLOC_CTX *mem_ctx;
1508 :
1509 5454647 : while (isspace((unsigned char)*pszParmName)) {
1510 0 : pszParmName++;
1511 : }
1512 :
1513 5454647 : name = strlower_talloc(lp_ctx, pszParmName);
1514 5454647 : if (!name) return false;
1515 :
1516 5454647 : if (service == NULL) {
1517 1923101 : data = &lp_ctx->globals->param_opt;
1518 : /**
1519 : * s3 code cannot deal with parametric options stored on the globals ctx.
1520 : */
1521 1923101 : if (lp_ctx->s3_fns != NULL) {
1522 1079083 : mem_ctx = NULL;
1523 : } else {
1524 842977 : mem_ctx = lp_ctx->globals->ctx;
1525 : }
1526 : } else {
1527 3531546 : data = &service->param_opt;
1528 3531546 : mem_ctx = service;
1529 : }
1530 :
1531 5454647 : set_param_opt(mem_ctx, data, name, pszParmValue, flags);
1532 :
1533 5454647 : talloc_free(name);
1534 :
1535 5454647 : return true;
1536 : }
1537 :
1538 15441686 : static bool set_variable_helper(TALLOC_CTX *mem_ctx, int parmnum, void *parm_ptr,
1539 : const char *pszParmName, const char *pszParmValue)
1540 : {
1541 174524 : size_t i;
1542 :
1543 : /* switch on the type of variable it is */
1544 15441686 : switch (parm_table[parmnum].type)
1545 : {
1546 4562428 : case P_BOOL: {
1547 61968 : bool b;
1548 4562428 : if (!set_boolean(pszParmValue, &b)) {
1549 0 : DEBUG(0, ("set_variable_helper(%s): value is not "
1550 : "boolean!\n", pszParmValue));
1551 0 : return false;
1552 : }
1553 4562428 : *(bool *)parm_ptr = b;
1554 : }
1555 4562428 : break;
1556 :
1557 15326 : case P_BOOLREV: {
1558 0 : bool b;
1559 15326 : if (!set_boolean(pszParmValue, &b)) {
1560 0 : DEBUG(0, ("set_variable_helper(%s): value is not "
1561 : "boolean!\n", pszParmValue));
1562 0 : return false;
1563 : }
1564 15326 : *(bool *)parm_ptr = !b;
1565 : }
1566 15326 : break;
1567 :
1568 763403 : case P_INTEGER:
1569 763403 : *(int *)parm_ptr = lp_int(pszParmValue);
1570 763403 : break;
1571 :
1572 12567 : case P_CHAR:
1573 12567 : *(char *)parm_ptr = *pszParmValue;
1574 12567 : break;
1575 :
1576 352101 : case P_OCTAL:
1577 352101 : i = sscanf(pszParmValue, "%o", (int *)parm_ptr);
1578 352101 : if ( i != 1 ) {
1579 0 : DEBUG ( 0, ("Invalid octal number %s\n", pszParmName ));
1580 0 : return false;
1581 : }
1582 351240 : break;
1583 :
1584 200022 : case P_BYTES:
1585 : {
1586 4420 : uint64_t val;
1587 200022 : if (conv_str_size_error(pszParmValue, &val)) {
1588 200022 : if (val <= INT_MAX) {
1589 200022 : *(int *)parm_ptr = (int)val;
1590 200022 : break;
1591 : }
1592 : }
1593 :
1594 0 : DEBUG(0, ("set_variable_helper(%s): value is not "
1595 : "a valid size specifier!\n", pszParmValue));
1596 0 : return false;
1597 : }
1598 :
1599 2021936 : case P_CMDLIST:
1600 2021936 : TALLOC_FREE(*(char ***)parm_ptr);
1601 2021936 : *(char ***)parm_ptr = str_list_make_v3(mem_ctx,
1602 : pszParmValue, NULL);
1603 2021936 : break;
1604 :
1605 225325 : case P_LIST:
1606 : {
1607 225325 : char **new_list = str_list_make_v3(mem_ctx,
1608 : pszParmValue, NULL);
1609 225325 : if (new_list == NULL) {
1610 3 : break;
1611 : }
1612 :
1613 364710 : for (i=0; new_list[i]; i++) {
1614 313613 : if (*(const char ***)parm_ptr != NULL &&
1615 210397 : new_list[i][0] == '+' &&
1616 95391 : new_list[i][1])
1617 : {
1618 112056 : if (!str_list_check(*(const char ***)parm_ptr,
1619 95391 : &new_list[i][1])) {
1620 45351 : *(const char ***)parm_ptr = str_list_add(*(const char ***)parm_ptr,
1621 45351 : &new_list[i][1]);
1622 : }
1623 218222 : } else if (*(const char ***)parm_ptr != NULL &&
1624 115006 : new_list[i][0] == '-' &&
1625 43997 : new_list[i][1])
1626 : {
1627 43997 : str_list_remove(*(const char ***)parm_ptr,
1628 43997 : &new_list[i][1]);
1629 : } else {
1630 174225 : if (i != 0) {
1631 0 : DEBUG(0, ("Unsupported list syntax for: %s = %s\n",
1632 : pszParmName, pszParmValue));
1633 0 : return false;
1634 : }
1635 174225 : *(char ***)parm_ptr = new_list;
1636 174225 : break;
1637 : }
1638 : }
1639 219378 : break;
1640 : }
1641 :
1642 5822471 : case P_STRING:
1643 5822471 : lpcfg_string_set(mem_ctx, (char **)parm_ptr, pszParmValue);
1644 5822471 : break;
1645 :
1646 181015 : case P_USTRING:
1647 181015 : lpcfg_string_set_upper(mem_ctx, (char **)parm_ptr, pszParmValue);
1648 181015 : break;
1649 :
1650 1285092 : case P_ENUM:
1651 1285092 : if (!lp_set_enum_parm(&parm_table[parmnum], pszParmValue, (int*)parm_ptr)) {
1652 2 : return false;
1653 : }
1654 1256745 : break;
1655 :
1656 : }
1657 :
1658 15267160 : return true;
1659 :
1660 : }
1661 :
1662 12571 : bool handle_name_resolve_order(struct loadparm_context *lp_ctx,
1663 : struct loadparm_service *service,
1664 : const char *pszParmValue, char **ptr)
1665 : {
1666 12571 : const char **valid_values = NULL;
1667 12571 : const char **values_to_set = NULL;
1668 616 : int i;
1669 12571 : bool value_is_valid = false;
1670 12571 : valid_values = str_list_make_v3_const(NULL,
1671 : DEFAULT_NAME_RESOLVE_ORDER,
1672 : NULL);
1673 12571 : if (valid_values == NULL) {
1674 0 : DBG_ERR("OOM: failed to make string list from %s\n",
1675 : DEFAULT_NAME_RESOLVE_ORDER);
1676 0 : goto out;
1677 : }
1678 12571 : values_to_set = str_list_make_v3_const(lp_ctx->globals->ctx,
1679 : pszParmValue,
1680 : NULL);
1681 12571 : if (values_to_set == NULL) {
1682 0 : DBG_ERR("OOM: failed to make string list from %s\n",
1683 : pszParmValue);
1684 0 : goto out;
1685 : }
1686 12571 : TALLOC_FREE(lp_ctx->globals->name_resolve_order);
1687 62835 : for (i = 0; values_to_set[i] != NULL; i++) {
1688 50272 : value_is_valid = str_list_check(valid_values, values_to_set[i]);
1689 50272 : if (!value_is_valid) {
1690 8 : DBG_ERR("WARNING: Ignoring invalid list value '%s' "
1691 : "for parameter 'name resolve order'\n",
1692 : values_to_set[i]);
1693 8 : break;
1694 : }
1695 : }
1696 12563 : out:
1697 12571 : if (value_is_valid) {
1698 12563 : lp_ctx->globals->name_resolve_order = values_to_set;
1699 : } else {
1700 8 : TALLOC_FREE(values_to_set);
1701 : }
1702 12571 : TALLOC_FREE(valid_values);
1703 12571 : return value_is_valid;
1704 : }
1705 :
1706 9 : bool handle_kdc_default_domain_supported_enctypes(struct loadparm_context *lp_ctx,
1707 : struct loadparm_service *service,
1708 : const char *pszParmValue, char **ptr)
1709 : {
1710 9 : char **enctype_list = NULL;
1711 9 : char **enctype = NULL;
1712 9 : uint32_t result = 0;
1713 9 : bool ok = true;
1714 :
1715 9 : enctype_list = str_list_make(NULL, pszParmValue, NULL);
1716 9 : if (enctype_list == NULL) {
1717 0 : DBG_ERR("OOM: failed to make string list from %s\n",
1718 : pszParmValue);
1719 0 : ok = false;
1720 0 : goto out;
1721 : }
1722 :
1723 18 : for (enctype = enctype_list; *enctype != NULL; ++enctype) {
1724 18 : if (strwicmp(*enctype, "arcfour-hmac-md5") == 0 ||
1725 9 : strwicmp(*enctype, "rc4-hmac") == 0)
1726 : {
1727 0 : result |= KERB_ENCTYPE_RC4_HMAC_MD5;
1728 : }
1729 18 : else if (strwicmp(*enctype, "aes128-cts-hmac-sha1-96") == 0 ||
1730 9 : strwicmp(*enctype, "aes128-cts") == 0)
1731 : {
1732 0 : result |= KERB_ENCTYPE_AES128_CTS_HMAC_SHA1_96;
1733 : }
1734 18 : else if (strwicmp(*enctype, "aes256-cts-hmac-sha1-96") == 0 ||
1735 9 : strwicmp(*enctype, "aes256-cts") == 0)
1736 : {
1737 0 : result |= KERB_ENCTYPE_AES256_CTS_HMAC_SHA1_96;
1738 : }
1739 18 : else if (strwicmp(*enctype, "aes256-cts-hmac-sha1-96-sk") == 0 ||
1740 9 : strwicmp(*enctype, "aes256-cts-sk") == 0)
1741 : {
1742 0 : result |= KERB_ENCTYPE_AES256_CTS_HMAC_SHA1_96_SK;
1743 : }
1744 : else {
1745 9 : const char *bitstr = *enctype;
1746 0 : int base;
1747 0 : int error;
1748 0 : unsigned long bit;
1749 :
1750 : /* See if the bit's specified in hexadecimal. */
1751 9 : if (bitstr[0] == '0' &&
1752 3 : (bitstr[1] == 'x' || bitstr[2] == 'X'))
1753 : {
1754 0 : base = 16;
1755 0 : bitstr += 2;
1756 : }
1757 : else {
1758 9 : base = 10;
1759 : }
1760 :
1761 9 : bit = smb_strtoul(bitstr, NULL, base, &error, SMB_STR_FULL_STR_CONV);
1762 9 : if (error) {
1763 0 : DBG_ERR("WARNING: Ignoring invalid value '%s' "
1764 : "for parameter 'kdc default domain supported enctypes'\n",
1765 : *enctype);
1766 0 : ok = false;
1767 : } else {
1768 9 : result |= bit;
1769 : }
1770 : }
1771 : }
1772 :
1773 9 : *(int *)ptr = result;
1774 9 : out:
1775 9 : TALLOC_FREE(enctype_list);
1776 :
1777 9 : return ok;
1778 : }
1779 :
1780 9 : bool handle_kdc_supported_enctypes(struct loadparm_context *lp_ctx,
1781 : struct loadparm_service *service,
1782 : const char *pszParmValue, char **ptr)
1783 : {
1784 9 : char **enctype_list = NULL;
1785 9 : char **enctype = NULL;
1786 9 : uint32_t result = 0;
1787 9 : bool ok = true;
1788 :
1789 9 : enctype_list = str_list_make(NULL, pszParmValue, NULL);
1790 9 : if (enctype_list == NULL) {
1791 0 : DBG_ERR("OOM: failed to make string list from %s\n",
1792 : pszParmValue);
1793 0 : ok = false;
1794 0 : goto out;
1795 : }
1796 :
1797 18 : for (enctype = enctype_list; *enctype != NULL; ++enctype) {
1798 18 : if (strwicmp(*enctype, "arcfour-hmac-md5") == 0 ||
1799 9 : strwicmp(*enctype, "rc4-hmac") == 0)
1800 : {
1801 0 : result |= KERB_ENCTYPE_RC4_HMAC_MD5;
1802 : }
1803 18 : else if (strwicmp(*enctype, "aes128-cts-hmac-sha1-96") == 0 ||
1804 9 : strwicmp(*enctype, "aes128-cts") == 0)
1805 : {
1806 0 : result |= KERB_ENCTYPE_AES128_CTS_HMAC_SHA1_96;
1807 : }
1808 18 : else if (strwicmp(*enctype, "aes256-cts-hmac-sha1-96") == 0 ||
1809 9 : strwicmp(*enctype, "aes256-cts") == 0)
1810 : {
1811 0 : result |= KERB_ENCTYPE_AES256_CTS_HMAC_SHA1_96;
1812 : }
1813 : else {
1814 9 : const char *bitstr = *enctype;
1815 0 : int base;
1816 0 : int error;
1817 0 : unsigned long bit;
1818 :
1819 : /* See if the bit's specified in hexadecimal. */
1820 9 : if (bitstr[0] == '0' &&
1821 3 : (bitstr[1] == 'x' || bitstr[2] == 'X'))
1822 : {
1823 0 : base = 16;
1824 0 : bitstr += 2;
1825 : }
1826 : else {
1827 9 : base = 10;
1828 : }
1829 :
1830 9 : bit = smb_strtoul(bitstr, NULL, base, &error, SMB_STR_FULL_STR_CONV);
1831 9 : if (error) {
1832 0 : DBG_ERR("WARNING: Ignoring invalid value '%s' "
1833 : "for parameter 'kdc default domain supported enctypes'\n",
1834 : *enctype);
1835 0 : ok = false;
1836 : } else {
1837 9 : result |= bit;
1838 : }
1839 : }
1840 : }
1841 :
1842 9 : *(int *)ptr = result;
1843 9 : out:
1844 9 : TALLOC_FREE(enctype_list);
1845 :
1846 9 : return ok;
1847 : }
1848 :
1849 17003866 : static bool set_variable(TALLOC_CTX *mem_ctx, struct loadparm_service *service,
1850 : int parmnum, void *parm_ptr,
1851 : const char *pszParmName, const char *pszParmValue,
1852 : struct loadparm_context *lp_ctx, bool on_globals)
1853 : {
1854 182202 : int i;
1855 182202 : bool ok;
1856 :
1857 : /* if it is a special case then go ahead */
1858 17003866 : if (parm_table[parmnum].special) {
1859 1587302 : ok = parm_table[parmnum].special(lp_ctx, service, pszParmValue,
1860 : (char **)parm_ptr);
1861 : } else {
1862 15416564 : ok = set_variable_helper(mem_ctx, parmnum, parm_ptr,
1863 : pszParmName, pszParmValue);
1864 : }
1865 :
1866 17003866 : if (!ok) {
1867 17 : return false;
1868 : }
1869 :
1870 17003849 : if (on_globals && (lp_ctx->flags[parmnum] & FLAG_DEFAULT)) {
1871 387563 : lp_ctx->flags[parmnum] &= ~FLAG_DEFAULT;
1872 : /* we have to also unset FLAG_DEFAULT on aliases */
1873 396399 : for (i=parmnum-1;i>=0 && parm_table[i].offset == parm_table[parmnum].offset;i--) {
1874 8836 : lp_ctx->flags[i] &= ~FLAG_DEFAULT;
1875 : }
1876 440541 : for (i=parmnum+1;i<num_parameters() && parm_table[i].offset == parm_table[parmnum].offset;i++) {
1877 52978 : lp_ctx->flags[i] &= ~FLAG_DEFAULT;
1878 : }
1879 : }
1880 16821647 : return true;
1881 : }
1882 :
1883 :
1884 9334305 : bool lpcfg_do_global_parameter(struct loadparm_context *lp_ctx,
1885 : const char *pszParmName, const char *pszParmValue)
1886 : {
1887 9334305 : int parmnum = lpcfg_map_parameter(pszParmName);
1888 184933 : void *parm_ptr;
1889 :
1890 9334305 : if (parmnum < 0) {
1891 1897508 : if (strchr(pszParmName, ':')) {
1892 1897506 : return lp_do_parameter_parametric(lp_ctx, NULL, pszParmName, pszParmValue, 0);
1893 : }
1894 2 : DEBUG(0, ("Ignoring unknown parameter \"%s\"\n", pszParmName));
1895 2 : return true;
1896 : }
1897 :
1898 : /* if the flag has been set on the command line, then don't allow override,
1899 : but don't report an error */
1900 7436797 : if (lp_ctx->flags[parmnum] & FLAG_CMDLINE) {
1901 48788 : return true;
1902 : }
1903 :
1904 7387703 : if (parm_table[parmnum].flags & FLAG_DEPRECATED) {
1905 356218 : char *suppress_env = getenv("SAMBA_DEPRECATED_SUPPRESS");
1906 369397 : bool print_warning = (suppress_env == NULL
1907 356218 : || suppress_env[0] == '\0');
1908 356218 : if (print_warning) {
1909 4 : DBG_WARNING("WARNING: The \"%s\" option "
1910 : "is deprecated\n",
1911 : pszParmName);
1912 :
1913 : }
1914 : }
1915 :
1916 7387703 : parm_ptr = lpcfg_parm_ptr(lp_ctx, NULL, &parm_table[parmnum]);
1917 :
1918 7387703 : return set_variable(lp_ctx->globals->ctx, NULL, parmnum, parm_ptr,
1919 : pszParmName, pszParmValue, lp_ctx, true);
1920 : }
1921 :
1922 13147937 : bool lpcfg_do_service_parameter(struct loadparm_context *lp_ctx,
1923 : struct loadparm_service *service,
1924 : const char *pszParmName, const char *pszParmValue)
1925 : {
1926 12771 : void *parm_ptr;
1927 12771 : int i;
1928 13147937 : int parmnum = lpcfg_map_parameter(pszParmName);
1929 :
1930 13147937 : if (parmnum < 0) {
1931 3531546 : if (strchr(pszParmName, ':')) {
1932 3531546 : return lp_do_parameter_parametric(lp_ctx, service, pszParmName, pszParmValue, 0);
1933 : }
1934 0 : DEBUG(0, ("Ignoring unknown parameter \"%s\"\n", pszParmName));
1935 0 : return true;
1936 : }
1937 :
1938 : /* if the flag has been set on the command line, then don't allow override,
1939 : but don't report an error */
1940 9616391 : if (lp_ctx->flags[parmnum] & FLAG_CMDLINE) {
1941 228 : return true;
1942 : }
1943 :
1944 9616163 : if (parm_table[parmnum].flags & FLAG_DEPRECATED) {
1945 0 : char *suppress_env = getenv("SAMBA_DEPRECATED_SUPPRESS");
1946 0 : bool print_warning = (suppress_env == NULL
1947 0 : || suppress_env[0] == '\0');
1948 0 : if (print_warning) {
1949 0 : DBG_WARNING("WARNING: The \"%s\" option "
1950 : "is deprecated\n",
1951 : pszParmName);
1952 :
1953 : }
1954 : }
1955 :
1956 9616163 : if (parm_table[parmnum].p_class == P_GLOBAL) {
1957 0 : DEBUG(0,
1958 : ("Global parameter %s found in service section!\n",
1959 : pszParmName));
1960 0 : return true;
1961 : }
1962 9616163 : parm_ptr = ((char *)service) + parm_table[parmnum].offset;
1963 :
1964 9616163 : if (!service->copymap)
1965 0 : init_copymap(service);
1966 :
1967 : /* this handles the aliases - set the copymap for other
1968 : * entries with the same data pointer */
1969 5019637086 : for (i = 0; parm_table[i].label; i++)
1970 5010020923 : if (parm_table[i].offset == parm_table[parmnum].offset &&
1971 26136742 : parm_table[i].p_class == parm_table[parmnum].p_class)
1972 15975947 : bitmap_clear(service->copymap, i);
1973 :
1974 9616163 : return set_variable(service, service, parmnum, parm_ptr, pszParmName,
1975 : pszParmValue, lp_ctx, false);
1976 : }
1977 :
1978 : /**
1979 : * Process a parameter.
1980 : */
1981 :
1982 3133778 : bool lpcfg_do_parameter(const char *pszParmName, const char *pszParmValue,
1983 : void *userdata)
1984 : {
1985 3133778 : struct loadparm_context *lp_ctx = (struct loadparm_context *)userdata;
1986 :
1987 3133778 : if (lp_ctx->bInGlobalSection)
1988 2085399 : return lpcfg_do_global_parameter(lp_ctx, pszParmName,
1989 : pszParmValue);
1990 : else
1991 1048379 : return lpcfg_do_service_parameter(lp_ctx, lp_ctx->currentService,
1992 : pszParmName, pszParmValue);
1993 : }
1994 :
1995 : /*
1996 : variable argument do parameter
1997 : */
1998 : bool lpcfg_do_global_parameter_var(struct loadparm_context *lp_ctx, const char *pszParmName, const char *fmt, ...) PRINTF_ATTRIBUTE(3, 4);
1999 190729 : bool lpcfg_do_global_parameter_var(struct loadparm_context *lp_ctx,
2000 : const char *pszParmName, const char *fmt, ...)
2001 : {
2002 9241 : char *s;
2003 9241 : bool ret;
2004 9241 : va_list ap;
2005 :
2006 190729 : va_start(ap, fmt);
2007 190729 : s = talloc_vasprintf(NULL, fmt, ap);
2008 190729 : va_end(ap);
2009 190729 : ret = lpcfg_do_global_parameter(lp_ctx, pszParmName, s);
2010 190729 : talloc_free(s);
2011 190729 : return ret;
2012 : }
2013 :
2014 :
2015 : /*
2016 : set a parameter from the commandline - this is called from command line parameter
2017 : parsing code. It sets the parameter then marks the parameter as unable to be modified
2018 : by smb.conf processing
2019 : */
2020 62071 : bool lpcfg_set_cmdline(struct loadparm_context *lp_ctx, const char *pszParmName,
2021 : const char *pszParmValue)
2022 : {
2023 1177 : int parmnum;
2024 1177 : int i;
2025 :
2026 64983 : while (isspace((unsigned char)*pszParmValue)) pszParmValue++;
2027 :
2028 62071 : parmnum = lpcfg_map_parameter(pszParmName);
2029 :
2030 62071 : if (parmnum < 0 && strchr(pszParmName, ':')) {
2031 : /* set a parametric option */
2032 895 : bool ok;
2033 25577 : ok = lp_do_parameter_parametric(lp_ctx, NULL, pszParmName,
2034 : pszParmValue, FLAG_CMDLINE);
2035 25577 : if (lp_ctx->s3_fns != NULL) {
2036 411 : if (ok) {
2037 411 : lp_ctx->s3_fns->store_cmdline(pszParmName, pszParmValue);
2038 : }
2039 : }
2040 25577 : return ok;
2041 : }
2042 :
2043 36494 : if (parmnum < 0) {
2044 0 : DEBUG(0,("Unknown option '%s'\n", pszParmName));
2045 0 : return false;
2046 : }
2047 :
2048 : /* reset the CMDLINE flag in case this has been called before */
2049 36494 : lp_ctx->flags[parmnum] &= ~FLAG_CMDLINE;
2050 :
2051 36494 : if (!lpcfg_do_global_parameter(lp_ctx, pszParmName, pszParmValue)) {
2052 5 : return false;
2053 : }
2054 :
2055 36489 : lp_ctx->flags[parmnum] |= FLAG_CMDLINE;
2056 :
2057 : /* we have to also set FLAG_CMDLINE on aliases */
2058 36489 : for (i=parmnum-1;
2059 36770 : i>=0 && parm_table[i].p_class == parm_table[parmnum].p_class &&
2060 35757 : parm_table[i].offset == parm_table[parmnum].offset;
2061 281 : i--) {
2062 281 : lp_ctx->flags[i] |= FLAG_CMDLINE;
2063 : }
2064 36489 : for (i=parmnum+1;
2065 58356 : i<num_parameters() &&
2066 57993 : parm_table[i].p_class == parm_table[parmnum].p_class &&
2067 54966 : parm_table[i].offset == parm_table[parmnum].offset;
2068 21504 : i++) {
2069 21504 : lp_ctx->flags[i] |= FLAG_CMDLINE;
2070 : }
2071 :
2072 36489 : if (lp_ctx->s3_fns != NULL) {
2073 31559 : lp_ctx->s3_fns->store_cmdline(pszParmName, pszParmValue);
2074 : }
2075 :
2076 36207 : return true;
2077 : }
2078 :
2079 : /*
2080 : set a option from the commandline in 'a=b' format. Use to support --option
2081 : */
2082 11817 : bool lpcfg_set_option(struct loadparm_context *lp_ctx, const char *option)
2083 : {
2084 375 : char *p, *s;
2085 375 : bool ret;
2086 :
2087 11817 : s = talloc_strdup(NULL, option);
2088 11817 : if (!s) {
2089 0 : return false;
2090 : }
2091 :
2092 11817 : p = strchr(s, '=');
2093 11817 : if (!p) {
2094 1 : talloc_free(s);
2095 1 : return false;
2096 : }
2097 :
2098 11816 : *p = 0;
2099 :
2100 11816 : ret = lpcfg_set_cmdline(lp_ctx, s, p+1);
2101 11816 : talloc_free(s);
2102 11816 : return ret;
2103 : }
2104 :
2105 :
2106 : #define BOOLSTR(b) ((b) ? "Yes" : "No")
2107 :
2108 : /**
2109 : * Print a parameter of the specified type.
2110 : */
2111 :
2112 51814 : void lpcfg_print_parameter(struct parm_struct *p, void *ptr, FILE * f)
2113 : {
2114 : /* For the separation of lists values that we print below */
2115 51814 : const char *list_sep = ", ";
2116 1652 : int i;
2117 51814 : switch (p->type)
2118 : {
2119 4648 : case P_ENUM:
2120 21159 : for (i = 0; p->enum_list[i].name; i++) {
2121 21159 : if (*(int *)ptr == p->enum_list[i].value) {
2122 6443 : fprintf(f, "%s",
2123 4791 : p->enum_list[i].name);
2124 4648 : break;
2125 : }
2126 : }
2127 4648 : break;
2128 :
2129 15618 : case P_BOOL:
2130 15618 : fprintf(f, "%s", BOOLSTR(*(bool *)ptr));
2131 15193 : break;
2132 :
2133 12 : case P_BOOLREV:
2134 12 : fprintf(f, "%s", BOOLSTR(!*(bool *)ptr));
2135 12 : break;
2136 :
2137 6355 : case P_INTEGER:
2138 : case P_BYTES:
2139 6355 : fprintf(f, "%d", *(int *)ptr);
2140 6166 : break;
2141 :
2142 73 : case P_CHAR:
2143 73 : fprintf(f, "%c", *(char *)ptr);
2144 71 : break;
2145 :
2146 851 : case P_OCTAL: {
2147 851 : int val = *(int *)ptr;
2148 851 : if (val == -1) {
2149 0 : fprintf(f, "-1");
2150 : } else {
2151 851 : fprintf(f, "0%03o", val);
2152 : }
2153 835 : break;
2154 : }
2155 :
2156 3761 : case P_CMDLIST:
2157 3761 : list_sep = " ";
2158 :
2159 173 : FALL_THROUGH;
2160 5263 : case P_LIST:
2161 5263 : if ((char ***)ptr && *(char ***)ptr) {
2162 3524 : char **list = *(char ***)ptr;
2163 19079 : for (; *list; list++) {
2164 : /* surround strings with whitespace in double quotes */
2165 15428 : if (*(list+1) == NULL) {
2166 : /* last item, no extra separator */
2167 3651 : list_sep = "";
2168 : }
2169 15428 : if ( strchr_m( *list, ' ' ) ) {
2170 24 : fprintf(f, "\"%s\"%s", *list, list_sep);
2171 : } else {
2172 15404 : fprintf(f, "%s%s", *list, list_sep);
2173 : }
2174 : }
2175 : }
2176 5090 : break;
2177 :
2178 18851 : case P_STRING:
2179 : case P_USTRING:
2180 18851 : if (*(char **)ptr) {
2181 18851 : fprintf(f, "%s", *(char **)ptr);
2182 : }
2183 18147 : break;
2184 : }
2185 51814 : }
2186 :
2187 : /**
2188 : * Check if two parameters are equal.
2189 : */
2190 :
2191 460092 : static bool lpcfg_equal_parameter(parm_type type, void *ptr1, void *ptr2)
2192 : {
2193 460092 : switch (type) {
2194 230046 : case P_BOOL:
2195 : case P_BOOLREV:
2196 230046 : return (*((bool *)ptr1) == *((bool *)ptr2));
2197 :
2198 90018 : case P_INTEGER:
2199 : case P_ENUM:
2200 : case P_OCTAL:
2201 : case P_BYTES:
2202 90018 : return (*((int *)ptr1) == *((int *)ptr2));
2203 :
2204 3334 : case P_CHAR:
2205 3334 : return (*((char *)ptr1) == *((char *)ptr2));
2206 :
2207 33340 : case P_LIST:
2208 : case P_CMDLIST:
2209 33340 : return str_list_equal(*(const char ***)ptr1, *(const char ***)ptr2);
2210 :
2211 103354 : case P_STRING:
2212 : case P_USTRING:
2213 : {
2214 103354 : char *p1 = *(char **)ptr1, *p2 = *(char **)ptr2;
2215 103354 : if (p1 && !*p1)
2216 73416 : p1 = NULL;
2217 103354 : if (p2 && !*p2)
2218 78312 : p2 = NULL;
2219 103850 : return (p1 == p2 || strequal(p1, p2));
2220 : }
2221 : }
2222 0 : return false;
2223 : }
2224 :
2225 : /**
2226 : * Process a new section (service).
2227 : *
2228 : * At this stage all sections are services.
2229 : * Later we'll have special sections that permit server parameters to be set.
2230 : * Returns True on success, False on failure.
2231 : */
2232 :
2233 343734 : static bool do_section(const char *pszSectionName, void *userdata)
2234 : {
2235 343734 : struct loadparm_context *lp_ctx = (struct loadparm_context *)userdata;
2236 3724 : bool bRetval;
2237 3724 : bool isglobal;
2238 :
2239 343734 : if (lp_ctx->s3_fns != NULL) {
2240 0 : return lp_ctx->s3_fns->do_section(pszSectionName, lp_ctx);
2241 : }
2242 :
2243 650430 : isglobal = ((strwicmp(pszSectionName, GLOBAL_NAME) == 0) ||
2244 306696 : (strwicmp(pszSectionName, GLOBAL_NAME2) == 0));
2245 :
2246 : /* if we've just struck a global section, note the fact. */
2247 343734 : lp_ctx->bInGlobalSection = isglobal;
2248 :
2249 : /* check for multiple global sections */
2250 343734 : if (lp_ctx->bInGlobalSection) {
2251 37231 : DEBUG(4, ("Processing section \"[%s]\"\n", pszSectionName));
2252 37231 : bRetval = true;
2253 37231 : goto out;
2254 : }
2255 :
2256 : /* if we have a current service, tidy it up before moving on */
2257 306503 : bRetval = true;
2258 :
2259 306503 : if (lp_ctx->currentService != NULL)
2260 288097 : bRetval = lpcfg_service_ok(lp_ctx->currentService);
2261 :
2262 : /* if all is still well, move to the next record in the services array */
2263 306306 : if (bRetval) {
2264 : /* We put this here to avoid an odd message order if messages are */
2265 : /* issued by the post-processing of a previous section. */
2266 306503 : DEBUG(4, ("Processing section \"[%s]\"\n", pszSectionName));
2267 :
2268 306503 : if ((lp_ctx->currentService = lpcfg_add_service(lp_ctx, lp_ctx->sDefault,
2269 : pszSectionName))
2270 : == NULL) {
2271 0 : DEBUG(0, ("Failed to add a new service\n"));
2272 0 : bRetval = false;
2273 0 : goto out;
2274 : }
2275 : }
2276 306503 : out:
2277 340010 : return bRetval;
2278 : }
2279 :
2280 :
2281 : /**
2282 : * Determine if a particular base parameter is currently set to the default value.
2283 : */
2284 :
2285 10998 : static bool is_default(void *base_structure, int i)
2286 : {
2287 10998 : void *def_ptr = ((char *)base_structure) + parm_table[i].offset;
2288 10998 : switch (parm_table[i].type) {
2289 1441 : case P_CMDLIST:
2290 : case P_LIST:
2291 1441 : return str_list_equal((const char * const *)parm_table[i].def.lvalue,
2292 : *(const char * const **)def_ptr);
2293 5462 : case P_STRING:
2294 : case P_USTRING:
2295 5462 : return strequal(parm_table[i].def.svalue,
2296 : *(char **)def_ptr);
2297 2076 : case P_BOOL:
2298 : case P_BOOLREV:
2299 2076 : return parm_table[i].def.bvalue ==
2300 2076 : *(bool *)def_ptr;
2301 2019 : case P_INTEGER:
2302 : case P_CHAR:
2303 : case P_OCTAL:
2304 : case P_BYTES:
2305 : case P_ENUM:
2306 2019 : return parm_table[i].def.ivalue ==
2307 2019 : *(int *)def_ptr;
2308 : }
2309 0 : return false;
2310 : }
2311 :
2312 : /**
2313 : *Display the contents of the global structure.
2314 : */
2315 :
2316 1300 : void lpcfg_dump_globals(struct loadparm_context *lp_ctx, FILE *f,
2317 : bool show_defaults)
2318 : {
2319 27 : int i;
2320 27 : struct parmlist_entry *data;
2321 :
2322 1300 : fprintf(f, "# Global parameters\n[global]\n");
2323 :
2324 678627 : for (i = 0; parm_table[i].label; i++) {
2325 677300 : if (parm_table[i].p_class != P_GLOBAL) {
2326 204100 : continue;
2327 : }
2328 :
2329 473200 : if (parm_table[i].flags & FLAG_SYNONYM) {
2330 26000 : continue;
2331 : }
2332 :
2333 447200 : if (!show_defaults) {
2334 424840 : if (lp_ctx->flags && (lp_ctx->flags[i] & FLAG_DEFAULT)) {
2335 415305 : continue;
2336 : }
2337 :
2338 9535 : if (is_default(lp_ctx->globals, i)) {
2339 1389 : continue;
2340 : }
2341 : }
2342 :
2343 30506 : fprintf(f, "\t%s = ", parm_table[i].label);
2344 30506 : lpcfg_print_parameter(&parm_table[i], lpcfg_parm_ptr(lp_ctx, NULL, &parm_table[i]), f);
2345 43399 : fprintf(f, "\n");
2346 : }
2347 1300 : if (lp_ctx->globals->param_opt != NULL) {
2348 11642 : for (data = lp_ctx->globals->param_opt; data;
2349 10342 : data = data->next) {
2350 10342 : if (!show_defaults && (data->priority & FLAG_DEFAULT)) {
2351 2126 : continue;
2352 : }
2353 8291 : fprintf(f, "\t%s = %s\n", data->key, data->value);
2354 : }
2355 : }
2356 :
2357 1300 : }
2358 :
2359 : /**
2360 : * Display the contents of a single services record.
2361 : */
2362 :
2363 4632 : void lpcfg_dump_a_service(struct loadparm_service * pService, struct loadparm_service *sDefault, FILE * f,
2364 : unsigned int *flags, bool show_defaults)
2365 : {
2366 112 : int i;
2367 112 : struct parmlist_entry *data;
2368 :
2369 4632 : if (pService != sDefault)
2370 3334 : fprintf(f, "\n[%s]\n", pService->szService);
2371 :
2372 2417904 : for (i = 0; parm_table[i].label; i++) {
2373 2413272 : if (parm_table[i].p_class != P_LOCAL) {
2374 1686048 : continue;
2375 : }
2376 :
2377 727224 : if (parm_table[i].flags & FLAG_SYNONYM) {
2378 83376 : continue;
2379 : }
2380 :
2381 643848 : if (*parm_table[i].label == '-') {
2382 4632 : continue;
2383 : }
2384 :
2385 639216 : if (pService == sDefault) {
2386 179124 : if (!show_defaults) {
2387 170154 : if (flags && (flags[i] & FLAG_DEFAULT)) {
2388 168691 : continue;
2389 : }
2390 :
2391 1463 : if (is_default(sDefault, i)) {
2392 215 : continue;
2393 : }
2394 : }
2395 : } else {
2396 12006 : bool equal;
2397 :
2398 472098 : equal = lpcfg_equal_parameter(parm_table[i].type,
2399 : ((char *)pService) +
2400 448086 : parm_table[i].offset,
2401 : ((char *)sDefault) +
2402 460092 : parm_table[i].offset);
2403 460092 : if (equal) {
2404 451782 : continue;
2405 : }
2406 : }
2407 :
2408 18528 : fprintf(f, "\t%s = ", parm_table[i].label);
2409 18528 : lpcfg_print_parameter(&parm_table[i],
2410 18528 : ((char *)pService) + parm_table[i].offset, f);
2411 76410 : fprintf(f, "\n");
2412 : }
2413 4632 : if (pService->param_opt != NULL) {
2414 7962 : for (data = pService->param_opt; data; data = data->next) {
2415 5995 : if (!show_defaults && (data->priority & FLAG_DEFAULT)) {
2416 0 : continue;
2417 : }
2418 5995 : fprintf(f, "\t%s = %s\n", data->key, data->value);
2419 : }
2420 : }
2421 4632 : }
2422 :
2423 2927 : bool lpcfg_dump_a_parameter(struct loadparm_context *lp_ctx,
2424 : struct loadparm_service *service,
2425 : const char *parm_name, FILE * f)
2426 : {
2427 9 : struct parm_struct *parm;
2428 9 : void *ptr;
2429 9 : char *local_parm_name;
2430 9 : char *parm_opt;
2431 9 : const char *parm_opt_value;
2432 :
2433 : /* check for parametrical option */
2434 2927 : local_parm_name = talloc_strdup(lp_ctx, parm_name);
2435 2927 : if (local_parm_name == NULL) {
2436 0 : return false;
2437 : }
2438 :
2439 2927 : parm_opt = strchr( local_parm_name, ':');
2440 :
2441 2927 : if (parm_opt) {
2442 146 : *parm_opt = '\0';
2443 146 : parm_opt++;
2444 146 : if (strlen(parm_opt)) {
2445 146 : parm_opt_value = lpcfg_parm_string(lp_ctx, service,
2446 : local_parm_name, parm_opt);
2447 146 : if (parm_opt_value) {
2448 146 : fprintf(f, "%s\n", parm_opt_value);
2449 146 : TALLOC_FREE(local_parm_name);
2450 146 : return true;
2451 : }
2452 : }
2453 0 : TALLOC_FREE(local_parm_name);
2454 0 : return false;
2455 : }
2456 2781 : TALLOC_FREE(local_parm_name);
2457 :
2458 : /* parameter is not parametric, search the table */
2459 2781 : parm = lpcfg_parm_struct(lp_ctx, parm_name);
2460 2781 : if (!parm) {
2461 0 : return false;
2462 : }
2463 :
2464 2780 : if (service != NULL && parm->p_class == P_GLOBAL) {
2465 0 : return false;
2466 : }
2467 :
2468 2780 : ptr = lpcfg_parm_ptr(lp_ctx, service,parm);
2469 :
2470 2780 : lpcfg_print_parameter(parm, ptr, f);
2471 2780 : fprintf(f, "\n");
2472 2780 : return true;
2473 : }
2474 :
2475 : /**
2476 : * Auto-load some home services.
2477 : */
2478 29145 : static void lpcfg_add_auto_services(struct loadparm_context *lp_ctx,
2479 : const char *str)
2480 : {
2481 29145 : return;
2482 : }
2483 :
2484 : /***************************************************************************
2485 : Initialise the sDefault parameter structure for the printer values.
2486 : ***************************************************************************/
2487 :
2488 152068 : void init_printer_values(struct loadparm_context *lp_ctx, TALLOC_CTX *ctx,
2489 : struct loadparm_service *pService)
2490 : {
2491 : /* choose defaults depending on the type of printing */
2492 152068 : switch (pService->printing) {
2493 40099 : case PRINT_BSD:
2494 : case PRINT_AIX:
2495 : case PRINT_LPRNT:
2496 : case PRINT_LPROS2:
2497 40099 : lpcfg_string_set(ctx, &pService->lpq_command, "lpq -P'%p'");
2498 40099 : lpcfg_string_set(ctx, &pService->lprm_command, "lprm -P'%p' %j");
2499 40099 : lpcfg_string_set(ctx, &pService->print_command, "lpr -r -P'%p' %s");
2500 40099 : break;
2501 :
2502 0 : case PRINT_LPRNG:
2503 : case PRINT_PLP:
2504 0 : lpcfg_string_set(ctx, &pService->lpq_command, "lpq -P'%p'");
2505 0 : lpcfg_string_set(ctx, &pService->lprm_command, "lprm -P'%p' %j");
2506 0 : lpcfg_string_set(ctx, &pService->print_command, "lpr -r -P'%p' %s");
2507 0 : lpcfg_string_set(ctx, &pService->queuepause_command, "lpc stop '%p'");
2508 0 : lpcfg_string_set(ctx, &pService->queueresume_command, "lpc start '%p'");
2509 0 : lpcfg_string_set(ctx, &pService->lppause_command, "lpc hold '%p' %j");
2510 0 : lpcfg_string_set(ctx, &pService->lpresume_command, "lpc release '%p' %j");
2511 0 : break;
2512 :
2513 111969 : case PRINT_CUPS:
2514 : case PRINT_IPRINT:
2515 : /* set the lpq command to contain the destination printer
2516 : name only. This is used by cups_queue_get() */
2517 111969 : lpcfg_string_set(ctx, &pService->lpq_command, "%p");
2518 111969 : lpcfg_string_set(ctx, &pService->lprm_command, "");
2519 111969 : lpcfg_string_set(ctx, &pService->print_command, "");
2520 111969 : lpcfg_string_set(ctx, &pService->lppause_command, "");
2521 111969 : lpcfg_string_set(ctx, &pService->lpresume_command, "");
2522 111969 : lpcfg_string_set(ctx, &pService->queuepause_command, "");
2523 111969 : lpcfg_string_set(ctx, &pService->queueresume_command, "");
2524 111969 : break;
2525 :
2526 0 : case PRINT_SYSV:
2527 : case PRINT_HPUX:
2528 0 : lpcfg_string_set(ctx, &pService->lpq_command, "lpstat -o%p");
2529 0 : lpcfg_string_set(ctx, &pService->lprm_command, "cancel %p-%j");
2530 0 : lpcfg_string_set(ctx, &pService->print_command, "lp -c -d%p %s; rm %s");
2531 0 : lpcfg_string_set(ctx, &pService->queuepause_command, "disable %p");
2532 0 : lpcfg_string_set(ctx, &pService->queueresume_command, "enable %p");
2533 : #ifndef HPUX
2534 0 : lpcfg_string_set(ctx, &pService->lppause_command, "lp -i %p-%j -H hold");
2535 0 : lpcfg_string_set(ctx, &pService->lpresume_command, "lp -i %p-%j -H resume");
2536 : #endif /* HPUX */
2537 0 : break;
2538 :
2539 0 : case PRINT_QNX:
2540 0 : lpcfg_string_set(ctx, &pService->lpq_command, "lpq -P%p");
2541 0 : lpcfg_string_set(ctx, &pService->lprm_command, "lprm -P%p %j");
2542 0 : lpcfg_string_set(ctx, &pService->print_command, "lp -r -P%p %s");
2543 0 : break;
2544 :
2545 : #if defined(DEVELOPER) || defined(ENABLE_SELFTEST)
2546 :
2547 0 : case PRINT_TEST:
2548 : case PRINT_VLP: {
2549 0 : const char *tdbfile;
2550 0 : TALLOC_CTX *tmp_ctx = talloc_new(ctx);
2551 0 : const char *tmp;
2552 :
2553 0 : tmp = lpcfg_parm_string(lp_ctx, NULL, "vlp", "tdbfile");
2554 0 : if (tmp == NULL) {
2555 0 : tmp = "/tmp/vlp.tdb";
2556 : }
2557 :
2558 0 : tdbfile = talloc_asprintf(tmp_ctx, "tdbfile=%s", tmp);
2559 0 : if (tdbfile == NULL) {
2560 0 : tdbfile="tdbfile=/tmp/vlp.tdb";
2561 : }
2562 :
2563 0 : tmp = talloc_asprintf(tmp_ctx, "vlp %s print %%p %%s",
2564 : tdbfile);
2565 0 : lpcfg_string_set(ctx, &pService->print_command,
2566 : tmp ? tmp : "vlp print %p %s");
2567 :
2568 0 : tmp = talloc_asprintf(tmp_ctx, "vlp %s lpq %%p",
2569 : tdbfile);
2570 0 : lpcfg_string_set(ctx, &pService->lpq_command,
2571 : tmp ? tmp : "vlp lpq %p");
2572 :
2573 0 : tmp = talloc_asprintf(tmp_ctx, "vlp %s lprm %%p %%j",
2574 : tdbfile);
2575 0 : lpcfg_string_set(ctx, &pService->lprm_command,
2576 : tmp ? tmp : "vlp lprm %p %j");
2577 :
2578 0 : tmp = talloc_asprintf(tmp_ctx, "vlp %s lppause %%p %%j",
2579 : tdbfile);
2580 0 : lpcfg_string_set(ctx, &pService->lppause_command,
2581 : tmp ? tmp : "vlp lppause %p %j");
2582 :
2583 0 : tmp = talloc_asprintf(tmp_ctx, "vlp %s lpresume %%p %%j",
2584 : tdbfile);
2585 0 : lpcfg_string_set(ctx, &pService->lpresume_command,
2586 : tmp ? tmp : "vlp lpresume %p %j");
2587 :
2588 0 : tmp = talloc_asprintf(tmp_ctx, "vlp %s queuepause %%p",
2589 : tdbfile);
2590 0 : lpcfg_string_set(ctx, &pService->queuepause_command,
2591 : tmp ? tmp : "vlp queuepause %p");
2592 :
2593 0 : tmp = talloc_asprintf(tmp_ctx, "vlp %s queueresume %%p",
2594 : tdbfile);
2595 0 : lpcfg_string_set(ctx, &pService->queueresume_command,
2596 : tmp ? tmp : "vlp queueresume %p");
2597 0 : TALLOC_FREE(tmp_ctx);
2598 :
2599 0 : break;
2600 : }
2601 : #endif /* DEVELOPER */
2602 :
2603 : }
2604 152068 : }
2605 :
2606 :
2607 63 : static int lpcfg_destructor(struct loadparm_context *lp_ctx)
2608 : {
2609 63 : struct parmlist_entry *data;
2610 :
2611 63 : if (lp_ctx->refuse_free) {
2612 : /* someone is trying to free the
2613 : global_loadparm_context.
2614 : We can't allow that. */
2615 0 : return -1;
2616 : }
2617 :
2618 63 : if (lp_ctx->globals->param_opt != NULL) {
2619 : struct parmlist_entry *next;
2620 257 : for (data = lp_ctx->globals->param_opt; data; data=next) {
2621 194 : next = data->next;
2622 194 : if (data->priority & FLAG_CMDLINE) continue;
2623 189 : DLIST_REMOVE(lp_ctx->globals->param_opt, data);
2624 189 : talloc_free(data);
2625 : }
2626 : }
2627 :
2628 0 : return 0;
2629 : }
2630 :
2631 : /**
2632 : * Initialise the global parameter structure.
2633 : *
2634 : * Note that most callers should use loadparm_init_global() instead
2635 : */
2636 12558 : struct loadparm_context *loadparm_init(TALLOC_CTX *mem_ctx)
2637 : {
2638 616 : int i;
2639 616 : char *myname;
2640 616 : struct loadparm_context *lp_ctx;
2641 616 : struct parmlist_entry *parm;
2642 616 : char *logfile;
2643 :
2644 12558 : lp_ctx = talloc_zero(mem_ctx, struct loadparm_context);
2645 12558 : if (lp_ctx == NULL)
2646 0 : return NULL;
2647 :
2648 12558 : talloc_set_destructor(lp_ctx, lpcfg_destructor);
2649 12558 : lp_ctx->bInGlobalSection = true;
2650 12558 : lp_ctx->globals = talloc_zero(lp_ctx, struct loadparm_global);
2651 : /* This appears odd, but globals in s3 isn't a pointer */
2652 12558 : lp_ctx->globals->ctx = lp_ctx->globals;
2653 12558 : lp_ctx->globals->rpc_low_port = SERVER_TCP_LOW_PORT;
2654 12558 : lp_ctx->globals->rpc_high_port = SERVER_TCP_HIGH_PORT;
2655 12558 : lp_ctx->globals->weak_crypto = SAMBA_WEAK_CRYPTO_UNKNOWN;
2656 12558 : lp_ctx->sDefault = talloc_zero(lp_ctx, struct loadparm_service);
2657 12558 : lp_ctx->flags = talloc_zero_array(lp_ctx, unsigned int, num_parameters());
2658 :
2659 12558 : lp_ctx->sDefault->max_print_jobs = 1000;
2660 12558 : lp_ctx->sDefault->available = true;
2661 12558 : lp_ctx->sDefault->browseable = true;
2662 12558 : lp_ctx->sDefault->read_only = true;
2663 12558 : lp_ctx->sDefault->map_archive = true;
2664 12558 : lp_ctx->sDefault->strict_locking = true;
2665 12558 : lp_ctx->sDefault->oplocks = true;
2666 12558 : lp_ctx->sDefault->create_mask = 0744;
2667 12558 : lp_ctx->sDefault->force_create_mode = 0000;
2668 12558 : lp_ctx->sDefault->directory_mask = 0755;
2669 12558 : lp_ctx->sDefault->force_directory_mode = 0000;
2670 12558 : lp_ctx->sDefault->aio_read_size = 1;
2671 12558 : lp_ctx->sDefault->aio_write_size = 1;
2672 12558 : lp_ctx->sDefault->smbd_search_ask_sharemode = true;
2673 12558 : lp_ctx->sDefault->smbd_getinfo_ask_sharemode = true;
2674 12558 : lp_ctx->sDefault->volume_serial_number = -1;
2675 :
2676 12558 : DEBUG(3, ("Initialising global parameters\n"));
2677 :
2678 6555276 : for (i = 0; parm_table[i].label; i++) {
2679 6542718 : if ((parm_table[i].type == P_STRING ||
2680 4615338 : parm_table[i].type == P_USTRING) &&
2681 1820910 : !(lp_ctx->flags[i] & FLAG_CMDLINE)) {
2682 89320 : TALLOC_CTX *parent_mem;
2683 89320 : char **r;
2684 1820910 : if (parm_table[i].p_class == P_LOCAL) {
2685 439530 : parent_mem = lp_ctx->sDefault;
2686 439530 : r = (char **)(((char *)lp_ctx->sDefault) + parm_table[i].offset);
2687 : } else {
2688 1381380 : parent_mem = lp_ctx->globals;
2689 1381380 : r = (char **)(((char *)lp_ctx->globals) + parm_table[i].offset);
2690 : }
2691 1820910 : lpcfg_string_set(parent_mem, r, "");
2692 : }
2693 : }
2694 :
2695 12558 : logfile = talloc_asprintf(lp_ctx, "%s/log.samba", dyn_LOGFILEBASE);
2696 12558 : lpcfg_do_global_parameter(lp_ctx, "log file", logfile);
2697 12558 : talloc_free(logfile);
2698 :
2699 12558 : lpcfg_do_global_parameter(lp_ctx, "log level", "0");
2700 :
2701 12558 : lpcfg_do_global_parameter(lp_ctx, "syslog", "1");
2702 12558 : lpcfg_do_global_parameter(lp_ctx, "syslog only", "No");
2703 12558 : lpcfg_do_global_parameter(lp_ctx, "debug timestamp", "Yes");
2704 12558 : lpcfg_do_global_parameter(lp_ctx, "debug prefix timestamp", "No");
2705 12558 : lpcfg_do_global_parameter(lp_ctx, "debug hires timestamp", "Yes");
2706 12558 : lpcfg_do_global_parameter(lp_ctx, "debug syslog format", "No");
2707 12558 : lpcfg_do_global_parameter(lp_ctx, "debug pid", "No");
2708 12558 : lpcfg_do_global_parameter(lp_ctx, "debug uid", "No");
2709 12558 : lpcfg_do_global_parameter(lp_ctx, "debug class", "No");
2710 12558 : lpcfg_do_global_parameter(lp_ctx, "winbind debug traceid", "Yes");
2711 :
2712 12558 : lpcfg_do_global_parameter(lp_ctx, "server role", "auto");
2713 12558 : lpcfg_do_global_parameter(lp_ctx, "domain logons", "No");
2714 12558 : lpcfg_do_global_parameter(lp_ctx, "domain master", "Auto");
2715 :
2716 : /* options that can be set on the command line must be initialised via
2717 : the slower lpcfg_do_global_parameter() to ensure that FLAG_CMDLINE is obeyed */
2718 : #ifdef TCP_NODELAY
2719 12558 : lpcfg_do_global_parameter(lp_ctx, "socket options", "TCP_NODELAY");
2720 : #endif
2721 12558 : lpcfg_do_global_parameter(lp_ctx, "workgroup", DEFAULT_WORKGROUP);
2722 12558 : myname = get_myname(lp_ctx);
2723 12558 : lpcfg_do_global_parameter(lp_ctx, "netbios name", myname);
2724 12558 : talloc_free(myname);
2725 12558 : lpcfg_do_global_parameter(lp_ctx,
2726 : "name resolve order",
2727 : DEFAULT_NAME_RESOLVE_ORDER);
2728 :
2729 12558 : lpcfg_do_global_parameter(lp_ctx, "fstype", "NTFS");
2730 :
2731 12558 : lpcfg_do_global_parameter(lp_ctx, "ntvfs handler", "unixuid default");
2732 12558 : lpcfg_do_global_parameter(lp_ctx, "max connections", "0");
2733 :
2734 12558 : lpcfg_do_global_parameter(lp_ctx, "dcerpc endpoint servers", "epmapper wkssvc samr netlogon lsarpc drsuapi dssetup unixinfo browser eventlog6 backupkey dnsserver");
2735 12558 : lpcfg_do_global_parameter(lp_ctx, "server services", "s3fs rpc nbt wrepl ldap cldap kdc drepl winbindd ntp_signd kcc dnsupdate dns");
2736 12558 : lpcfg_do_global_parameter(lp_ctx, "kccsrv:samba_kcc", "true");
2737 : /* the winbind method for domain controllers is for both RODC
2738 : auth forwarding and for trusted domains */
2739 12558 : lpcfg_do_global_parameter(lp_ctx, "private dir", dyn_PRIVATE_DIR);
2740 12558 : lpcfg_do_global_parameter(lp_ctx, "binddns dir", dyn_BINDDNS_DIR);
2741 12558 : lpcfg_do_global_parameter(lp_ctx, "registry:HKEY_LOCAL_MACHINE", "hklm.ldb");
2742 :
2743 : /* This hive should be dynamically generated by Samba using
2744 : data from the sam, but for the moment leave it in a tdb to
2745 : keep regedt32 from popping up an annoying dialog. */
2746 12558 : lpcfg_do_global_parameter(lp_ctx, "registry:HKEY_USERS", "hku.ldb");
2747 :
2748 : /* using UTF8 by default allows us to support all chars */
2749 12558 : lpcfg_do_global_parameter(lp_ctx, "unix charset", "UTF-8");
2750 :
2751 : /* Use codepage 850 as a default for the dos character set */
2752 12558 : lpcfg_do_global_parameter(lp_ctx, "dos charset", "CP850");
2753 :
2754 : /*
2755 : * Allow the default PASSWD_CHAT to be overridden in local.h.
2756 : */
2757 12558 : lpcfg_do_global_parameter(lp_ctx, "passwd chat", DEFAULT_PASSWD_CHAT);
2758 :
2759 12558 : lpcfg_do_global_parameter(lp_ctx, "pid directory", dyn_PIDDIR);
2760 12558 : lpcfg_do_global_parameter(lp_ctx, "lock dir", dyn_LOCKDIR);
2761 12558 : lpcfg_do_global_parameter(lp_ctx, "state directory", dyn_STATEDIR);
2762 12558 : lpcfg_do_global_parameter(lp_ctx, "cache directory", dyn_CACHEDIR);
2763 12558 : lpcfg_do_global_parameter(lp_ctx, "ncalrpc dir", dyn_NCALRPCDIR);
2764 :
2765 12558 : lpcfg_do_global_parameter(lp_ctx, "nbt client socket address", "0.0.0.0");
2766 12558 : lpcfg_do_global_parameter_var(lp_ctx, "server string",
2767 : "Samba %s", SAMBA_VERSION_STRING);
2768 :
2769 12558 : lpcfg_do_global_parameter(lp_ctx, "password server", "*");
2770 :
2771 12558 : lpcfg_do_global_parameter(lp_ctx, "max mux", "50");
2772 12558 : lpcfg_do_global_parameter(lp_ctx, "max xmit", "16644");
2773 12558 : lpcfg_do_global_parameter(lp_ctx, "host msdfs", "true");
2774 :
2775 12558 : lpcfg_do_global_parameter(lp_ctx, "LargeReadwrite", "True");
2776 12558 : lpcfg_do_global_parameter(lp_ctx, "server min protocol", "SMB2_02");
2777 12558 : lpcfg_do_global_parameter(lp_ctx, "server max protocol", "SMB3");
2778 12558 : lpcfg_do_global_parameter(lp_ctx, "client min protocol", "SMB2_02");
2779 12558 : lpcfg_do_global_parameter(lp_ctx, "client max protocol", "default");
2780 12558 : lpcfg_do_global_parameter(lp_ctx, "client ipc min protocol", "default");
2781 12558 : lpcfg_do_global_parameter(lp_ctx, "client ipc max protocol", "default");
2782 12558 : lpcfg_do_global_parameter(lp_ctx, "security", "AUTO");
2783 12558 : lpcfg_do_global_parameter(lp_ctx, "EncryptPasswords", "True");
2784 12558 : lpcfg_do_global_parameter(lp_ctx, "ReadRaw", "True");
2785 12558 : lpcfg_do_global_parameter(lp_ctx, "WriteRaw", "True");
2786 12558 : lpcfg_do_global_parameter(lp_ctx, "NullPasswords", "False");
2787 12558 : lpcfg_do_global_parameter(lp_ctx, "old password allowed period", "60");
2788 12558 : lpcfg_do_global_parameter(lp_ctx, "ObeyPamRestrictions", "False");
2789 :
2790 12558 : lpcfg_do_global_parameter(lp_ctx, "TimeServer", "False");
2791 12558 : lpcfg_do_global_parameter(lp_ctx, "BindInterfacesOnly", "False");
2792 12558 : lpcfg_do_global_parameter(lp_ctx, "Unicode", "True");
2793 12558 : lpcfg_do_global_parameter(lp_ctx, "ClientLanManAuth", "False");
2794 12558 : lpcfg_do_global_parameter(lp_ctx, "ClientNTLMv2Auth", "True");
2795 12558 : lpcfg_do_global_parameter(lp_ctx, "LanmanAuth", "False");
2796 12558 : lpcfg_do_global_parameter(lp_ctx, "NTLMAuth", "ntlmv2-only");
2797 12558 : lpcfg_do_global_parameter(lp_ctx, "NT hash store", "always");
2798 12558 : lpcfg_do_global_parameter(lp_ctx, "RawNTLMv2Auth", "False");
2799 :
2800 12558 : lpcfg_do_global_parameter(lp_ctx, "allow dcerpc auth level connect", "False");
2801 :
2802 12558 : lpcfg_do_global_parameter(lp_ctx, "UnixExtensions", "True");
2803 :
2804 12558 : lpcfg_do_global_parameter(lp_ctx, "PreferredMaster", "Auto");
2805 12558 : lpcfg_do_global_parameter(lp_ctx, "LocalMaster", "True");
2806 :
2807 12558 : lpcfg_do_global_parameter(lp_ctx, "wins support", "False");
2808 12558 : lpcfg_do_global_parameter(lp_ctx, "dns proxy", "True");
2809 :
2810 12558 : lpcfg_do_global_parameter(lp_ctx, "winbind separator", "\\");
2811 12558 : lpcfg_do_global_parameter(lp_ctx, "winbind sealed pipes", "True");
2812 12558 : lpcfg_do_global_parameter(lp_ctx, "winbind scan trusted domains", "False");
2813 12558 : lpcfg_do_global_parameter(lp_ctx, "require strong key", "True");
2814 12558 : lpcfg_do_global_parameter(lp_ctx, "reject md5 servers", "True");
2815 12558 : lpcfg_do_global_parameter(lp_ctx, "winbindd socket directory", dyn_WINBINDD_SOCKET_DIR);
2816 12558 : lpcfg_do_global_parameter(lp_ctx, "ntp signd socket directory", dyn_NTP_SIGND_SOCKET_DIR);
2817 12558 : lpcfg_do_global_parameter_var(lp_ctx, "gpo update command", "%s/samba-gpupdate", dyn_SCRIPTSBINDIR);
2818 12558 : lpcfg_do_global_parameter_var(lp_ctx, "apply group policies", "False");
2819 12558 : lpcfg_do_global_parameter_var(lp_ctx, "dns update command", "%s/samba_dnsupdate", dyn_SCRIPTSBINDIR);
2820 12558 : lpcfg_do_global_parameter_var(lp_ctx, "spn update command", "%s/samba_spnupdate", dyn_SCRIPTSBINDIR);
2821 12558 : lpcfg_do_global_parameter_var(lp_ctx, "samba kcc command",
2822 : "%s/samba_kcc", dyn_SCRIPTSBINDIR);
2823 : #ifdef MIT_KDC_PATH
2824 2358 : lpcfg_do_global_parameter_var(lp_ctx,
2825 : "mit kdc command",
2826 : MIT_KDC_PATH);
2827 : #endif
2828 12558 : lpcfg_do_global_parameter(lp_ctx, "template shell", "/bin/false");
2829 12558 : lpcfg_do_global_parameter(lp_ctx, "template homedir", "/home/%D/%U");
2830 :
2831 12558 : lpcfg_do_global_parameter(lp_ctx, "client signing", "default");
2832 12558 : lpcfg_do_global_parameter(lp_ctx, "client ipc signing", "default");
2833 12558 : lpcfg_do_global_parameter(lp_ctx, "server signing", "default");
2834 :
2835 12558 : lpcfg_do_global_parameter(lp_ctx, "use mmap", "True");
2836 :
2837 12558 : lpcfg_do_global_parameter(lp_ctx, "smb ports", "445 139");
2838 12558 : lpcfg_do_global_parameter_var(lp_ctx, "nbt port", "%d", NBT_NAME_SERVICE_PORT);
2839 12558 : lpcfg_do_global_parameter_var(lp_ctx, "dgram port", "%d", NBT_DGRAM_SERVICE_PORT);
2840 12558 : lpcfg_do_global_parameter(lp_ctx, "cldap port", "389");
2841 12558 : lpcfg_do_global_parameter(lp_ctx, "krb5 port", "88");
2842 12558 : lpcfg_do_global_parameter(lp_ctx, "kpasswd port", "464");
2843 12558 : lpcfg_do_global_parameter_var(lp_ctx, "dns port", "%d", DNS_SERVICE_PORT);
2844 :
2845 12558 : lpcfg_do_global_parameter(lp_ctx, "kdc enable fast", "True");
2846 :
2847 12558 : lpcfg_do_global_parameter(lp_ctx, "nt status support", "True");
2848 :
2849 12558 : lpcfg_do_global_parameter(lp_ctx, "max wins ttl", "518400"); /* 6 days */
2850 12558 : lpcfg_do_global_parameter(lp_ctx, "min wins ttl", "21600");
2851 :
2852 12558 : lpcfg_do_global_parameter(lp_ctx, "tls enabled", "True");
2853 12558 : lpcfg_do_global_parameter(lp_ctx, "tls verify peer", "as_strict_as_possible");
2854 12558 : lpcfg_do_global_parameter(lp_ctx, "tls keyfile", "tls/key.pem");
2855 12558 : lpcfg_do_global_parameter(lp_ctx, "tls certfile", "tls/cert.pem");
2856 12558 : lpcfg_do_global_parameter(lp_ctx, "tls cafile", "tls/ca.pem");
2857 12558 : lpcfg_do_global_parameter(lp_ctx,
2858 : "tls priority",
2859 : "NORMAL:-VERS-SSL3.0");
2860 :
2861 12558 : lpcfg_do_global_parameter(lp_ctx, "nsupdate command", "/usr/bin/nsupdate -g");
2862 :
2863 12558 : lpcfg_do_global_parameter(lp_ctx, "allow dns updates", "secure only");
2864 12558 : lpcfg_do_global_parameter(lp_ctx, "dns zone scavenging", "False");
2865 12558 : lpcfg_do_global_parameter(lp_ctx, "dns forwarder", "");
2866 :
2867 12558 : lpcfg_do_global_parameter(lp_ctx, "algorithmic rid base", "1000");
2868 :
2869 12558 : lpcfg_do_global_parameter(lp_ctx, "enhanced browsing", "True");
2870 :
2871 12558 : lpcfg_do_global_parameter(lp_ctx, "winbind nss info", "template");
2872 :
2873 12558 : lpcfg_do_global_parameter(lp_ctx, "server schannel", "True");
2874 12558 : lpcfg_do_global_parameter(lp_ctx, "server schannel require seal", "True");
2875 12558 : lpcfg_do_global_parameter(lp_ctx, "reject md5 clients", "True");
2876 :
2877 12558 : lpcfg_do_global_parameter(lp_ctx, "short preserve case", "True");
2878 :
2879 12558 : lpcfg_do_global_parameter(lp_ctx, "max open files", "16384");
2880 :
2881 12558 : lpcfg_do_global_parameter(lp_ctx, "cups connection timeout", "30");
2882 :
2883 12558 : lpcfg_do_global_parameter(lp_ctx, "locking", "True");
2884 :
2885 12558 : lpcfg_do_global_parameter(lp_ctx, "block size", "1024");
2886 :
2887 12558 : lpcfg_do_global_parameter(lp_ctx, "client use spnego", "True");
2888 :
2889 12558 : lpcfg_do_global_parameter(lp_ctx, "change notify", "True");
2890 :
2891 12558 : lpcfg_do_global_parameter(lp_ctx, "name cache timeout", "660");
2892 :
2893 12558 : lpcfg_do_global_parameter(lp_ctx, "defer sharing violations", "True");
2894 :
2895 12558 : lpcfg_do_global_parameter(lp_ctx, "ldap replication sleep", "1000");
2896 :
2897 12558 : lpcfg_do_global_parameter(lp_ctx, "idmap backend", "tdb");
2898 :
2899 12558 : lpcfg_do_global_parameter(lp_ctx, "enable privileges", "True");
2900 :
2901 12558 : lpcfg_do_global_parameter_var(lp_ctx, "smb2 max write", "%u", DEFAULT_SMB2_MAX_WRITE);
2902 :
2903 12558 : lpcfg_do_global_parameter(lp_ctx, "passdb backend", "tdbsam");
2904 :
2905 12558 : lpcfg_do_global_parameter(lp_ctx, "deadtime", "10080");
2906 :
2907 12558 : lpcfg_do_global_parameter(lp_ctx, "getwd cache", "True");
2908 :
2909 12558 : lpcfg_do_global_parameter(lp_ctx, "winbind nested groups", "True");
2910 :
2911 12558 : lpcfg_do_global_parameter(lp_ctx, "mangled names", "illegal");
2912 :
2913 12558 : lpcfg_do_global_parameter_var(lp_ctx, "smb2 max credits", "%u", DEFAULT_SMB2_MAX_CREDITS);
2914 :
2915 12558 : lpcfg_do_global_parameter(lp_ctx, "ldap ssl", "start tls");
2916 :
2917 12558 : lpcfg_do_global_parameter(lp_ctx, "ldap deref", "auto");
2918 :
2919 12558 : lpcfg_do_global_parameter(lp_ctx, "lm interval", "60");
2920 :
2921 12558 : lpcfg_do_global_parameter(lp_ctx, "mangling method", "hash2");
2922 :
2923 12558 : lpcfg_do_global_parameter(lp_ctx, "hide dot files", "True");
2924 :
2925 12558 : lpcfg_do_global_parameter(lp_ctx, "browse list", "True");
2926 :
2927 12558 : lpcfg_do_global_parameter(lp_ctx, "passwd chat timeout", "2");
2928 :
2929 12558 : lpcfg_do_global_parameter(lp_ctx, "guest account", GUEST_ACCOUNT);
2930 :
2931 12558 : lpcfg_do_global_parameter(lp_ctx, "client schannel", "True");
2932 :
2933 12558 : lpcfg_do_global_parameter(lp_ctx, "smb encrypt", "default");
2934 :
2935 12558 : lpcfg_do_global_parameter(lp_ctx, "max log size", "5000");
2936 :
2937 12558 : lpcfg_do_global_parameter(lp_ctx, "idmap negative cache time", "120");
2938 :
2939 12558 : lpcfg_do_global_parameter(lp_ctx, "ldap follow referral", "auto");
2940 :
2941 12558 : lpcfg_do_global_parameter(lp_ctx, "multicast dns register", "yes");
2942 :
2943 12558 : lpcfg_do_global_parameter(lp_ctx, "winbind reconnect delay", "30");
2944 :
2945 12558 : lpcfg_do_global_parameter(lp_ctx, "winbind request timeout", "60");
2946 :
2947 12558 : lpcfg_do_global_parameter(lp_ctx, "nt acl support", "yes");
2948 :
2949 12558 : lpcfg_do_global_parameter(lp_ctx, "acl check permissions", "yes");
2950 :
2951 12558 : lpcfg_do_global_parameter(lp_ctx, "keepalive", "300");
2952 :
2953 12558 : lpcfg_do_global_parameter(lp_ctx, "smbd profiling level", "off");
2954 :
2955 12558 : lpcfg_do_global_parameter(lp_ctx, "winbind cache time", "300");
2956 :
2957 12558 : lpcfg_do_global_parameter(lp_ctx, "level2 oplocks", "yes");
2958 :
2959 12558 : lpcfg_do_global_parameter(lp_ctx, "show add printer wizard", "yes");
2960 :
2961 12558 : lpcfg_do_global_parameter(lp_ctx, "ldap page size", "1000");
2962 :
2963 12558 : lpcfg_do_global_parameter(lp_ctx, "kernel share modes", "no");
2964 :
2965 12558 : lpcfg_do_global_parameter(lp_ctx, "strict locking", "Auto");
2966 :
2967 12558 : lpcfg_do_global_parameter(lp_ctx, "strict sync", "yes");
2968 :
2969 12558 : lpcfg_do_global_parameter(lp_ctx, "map readonly", "no");
2970 :
2971 12558 : lpcfg_do_global_parameter(lp_ctx, "allow trusted domains", "yes");
2972 :
2973 12558 : lpcfg_do_global_parameter(lp_ctx, "default devmode", "yes");
2974 :
2975 12558 : lpcfg_do_global_parameter(lp_ctx, "os level", "20");
2976 :
2977 12558 : lpcfg_do_global_parameter(lp_ctx, "dos filetimes", "yes");
2978 :
2979 12558 : lpcfg_do_global_parameter(lp_ctx, "mangling char", "~");
2980 :
2981 12558 : lpcfg_do_global_parameter(lp_ctx, "printcap cache time", "750");
2982 :
2983 12558 : lpcfg_do_global_parameter(lp_ctx, "create krb5 conf", "yes");
2984 :
2985 12558 : lpcfg_do_global_parameter(lp_ctx, "winbind max clients", "200");
2986 :
2987 12558 : lpcfg_do_global_parameter(lp_ctx, "acl map full control", "yes");
2988 :
2989 12558 : lpcfg_do_global_parameter(lp_ctx, "nt pipe support", "yes");
2990 :
2991 12558 : lpcfg_do_global_parameter(lp_ctx, "ldap debug threshold", "10");
2992 :
2993 12558 : lpcfg_do_global_parameter(lp_ctx, "client ldap sasl wrapping", "seal");
2994 :
2995 12558 : lpcfg_do_global_parameter(lp_ctx, "mdns name", "netbios");
2996 :
2997 12558 : lpcfg_do_global_parameter(lp_ctx, "ldap server require strong auth", "yes");
2998 :
2999 12558 : lpcfg_do_global_parameter(lp_ctx, "follow symlinks", "yes");
3000 :
3001 12558 : lpcfg_do_global_parameter(lp_ctx, "machine password timeout", "604800");
3002 :
3003 12558 : lpcfg_do_global_parameter(lp_ctx, "ldap connection timeout", "2");
3004 :
3005 12558 : lpcfg_do_global_parameter(lp_ctx, "winbind expand groups", "0");
3006 :
3007 12558 : lpcfg_do_global_parameter(lp_ctx, "stat cache", "yes");
3008 :
3009 12558 : lpcfg_do_global_parameter(lp_ctx, "lpq cache time", "30");
3010 :
3011 12558 : lpcfg_do_global_parameter_var(lp_ctx, "smb2 max trans", "%u", DEFAULT_SMB2_MAX_TRANSACT);
3012 :
3013 12558 : lpcfg_do_global_parameter_var(lp_ctx, "smb2 max read", "%u", DEFAULT_SMB2_MAX_READ);
3014 :
3015 12558 : lpcfg_do_global_parameter(lp_ctx, "durable handles", "yes");
3016 :
3017 12558 : lpcfg_do_global_parameter(lp_ctx, "max stat cache size", "512");
3018 :
3019 12558 : lpcfg_do_global_parameter(lp_ctx, "ldap passwd sync", "no");
3020 :
3021 12558 : lpcfg_do_global_parameter(lp_ctx, "kernel change notify", "yes");
3022 :
3023 12558 : lpcfg_do_global_parameter(lp_ctx, "max ttl", "259200");
3024 :
3025 12558 : lpcfg_do_global_parameter(lp_ctx, "blocking locks", "yes");
3026 :
3027 12558 : lpcfg_do_global_parameter(lp_ctx, "load printers", "yes");
3028 :
3029 12558 : lpcfg_do_global_parameter(lp_ctx, "idmap cache time", "604800");
3030 :
3031 12558 : lpcfg_do_global_parameter(lp_ctx, "preserve case", "yes");
3032 :
3033 12558 : lpcfg_do_global_parameter(lp_ctx, "lm announce", "auto");
3034 :
3035 12558 : lpcfg_do_global_parameter(lp_ctx, "afs token lifetime", "604800");
3036 :
3037 12558 : lpcfg_do_global_parameter(lp_ctx, "enable core files", "yes");
3038 :
3039 12558 : lpcfg_do_global_parameter(lp_ctx, "winbind max domain connections", "1");
3040 :
3041 12558 : lpcfg_do_global_parameter(lp_ctx, "case sensitive", "auto");
3042 :
3043 12558 : lpcfg_do_global_parameter(lp_ctx, "ldap timeout", "15");
3044 :
3045 12558 : lpcfg_do_global_parameter(lp_ctx, "mangle prefix", "1");
3046 :
3047 12558 : lpcfg_do_global_parameter(lp_ctx, "posix locking", "yes");
3048 :
3049 12558 : lpcfg_do_global_parameter(lp_ctx, "lock spin time", "200");
3050 :
3051 12558 : lpcfg_do_global_parameter(lp_ctx, "nmbd bind explicit broadcast", "yes");
3052 :
3053 12558 : lpcfg_do_global_parameter(lp_ctx, "init logon delay", "100");
3054 :
3055 12558 : lpcfg_do_global_parameter(lp_ctx, "usershare owner only", "yes");
3056 :
3057 12558 : lpcfg_do_global_parameter(lp_ctx, "-valid", "yes");
3058 :
3059 12558 : lpcfg_do_global_parameter_var(lp_ctx, "usershare path", "%s/usershares", get_dyn_STATEDIR());
3060 :
3061 : #ifdef DEVELOPER
3062 12558 : lpcfg_do_global_parameter_var(lp_ctx, "panic action", "/bin/sleep 999999999");
3063 : #endif
3064 :
3065 12558 : lpcfg_do_global_parameter(lp_ctx, "smb passwd file", get_dyn_SMB_PASSWD_FILE());
3066 :
3067 12558 : lpcfg_do_global_parameter(lp_ctx, "logon home", "\\\\%N\\%U");
3068 :
3069 12558 : lpcfg_do_global_parameter(lp_ctx, "logon path", "\\\\%N\\%U\\profile");
3070 :
3071 12558 : lpcfg_do_global_parameter(lp_ctx, "printjob username", "%U");
3072 :
3073 12558 : lpcfg_do_global_parameter(lp_ctx, "aio max threads", "100");
3074 :
3075 12558 : lpcfg_do_global_parameter(lp_ctx, "smb2 leases", "yes");
3076 :
3077 12558 : lpcfg_do_global_parameter(lp_ctx, "server multi channel support", "yes");
3078 :
3079 12558 : lpcfg_do_global_parameter(lp_ctx, "kerberos encryption types", "all");
3080 :
3081 12558 : lpcfg_do_global_parameter(lp_ctx,
3082 : "rpc server dynamic port range",
3083 : "49152-65535");
3084 :
3085 12558 : lpcfg_do_global_parameter(lp_ctx, "prefork children", "4");
3086 12558 : lpcfg_do_global_parameter(lp_ctx, "prefork backoff increment", "10");
3087 12558 : lpcfg_do_global_parameter(lp_ctx, "prefork maximum backoff", "120");
3088 :
3089 12558 : lpcfg_do_global_parameter(lp_ctx, "check parent directory delete on close", "no");
3090 :
3091 12558 : lpcfg_do_global_parameter(lp_ctx, "ea support", "yes");
3092 :
3093 12558 : lpcfg_do_global_parameter(lp_ctx, "store dos attributes", "yes");
3094 :
3095 12558 : lpcfg_do_global_parameter(lp_ctx, "debug encryption", "no");
3096 :
3097 12558 : lpcfg_do_global_parameter(lp_ctx, "spotlight backend", "noindex");
3098 :
3099 12558 : lpcfg_do_global_parameter(
3100 : lp_ctx, "ldap max anonymous request size", "256000");
3101 12558 : lpcfg_do_global_parameter(
3102 : lp_ctx, "ldap max authenticated request size", "16777216");
3103 12558 : lpcfg_do_global_parameter(
3104 : lp_ctx, "ldap max search request size", "256000");
3105 :
3106 : /* Async DNS query timeout in seconds. */
3107 12558 : lpcfg_do_global_parameter(lp_ctx, "async dns timeout", "10");
3108 :
3109 12558 : lpcfg_do_global_parameter(lp_ctx,
3110 : "client smb encrypt",
3111 : "default");
3112 :
3113 12558 : lpcfg_do_global_parameter(lp_ctx,
3114 : "client use kerberos",
3115 : "desired");
3116 :
3117 12558 : lpcfg_do_global_parameter(lp_ctx,
3118 : "client protection",
3119 : "default");
3120 :
3121 12558 : lpcfg_do_global_parameter(lp_ctx,
3122 : "smbd max xattr size",
3123 : "65536");
3124 :
3125 12558 : lpcfg_do_global_parameter(lp_ctx,
3126 : "acl flag inherited canonicalization",
3127 : "yes");
3128 :
3129 12558 : lpcfg_do_global_parameter(lp_ctx,
3130 : "winbind use krb5 enterprise principals",
3131 : "yes");
3132 :
3133 12558 : lpcfg_do_global_parameter(lp_ctx,
3134 : "client smb3 signing algorithms",
3135 : DEFAULT_SMB3_SIGNING_ALGORITHMS);
3136 12558 : lpcfg_do_global_parameter(lp_ctx,
3137 : "server smb3 signing algorithms",
3138 : DEFAULT_SMB3_SIGNING_ALGORITHMS);
3139 :
3140 12558 : lpcfg_do_global_parameter(lp_ctx,
3141 : "client smb3 encryption algorithms",
3142 : DEFAULT_SMB3_ENCRYPTION_ALGORITHMS);
3143 12558 : lpcfg_do_global_parameter(lp_ctx,
3144 : "server smb3 encryption algorithms",
3145 : DEFAULT_SMB3_ENCRYPTION_ALGORITHMS);
3146 :
3147 12558 : lpcfg_do_global_parameter(lp_ctx,
3148 : "min domain uid",
3149 : "1000");
3150 :
3151 12558 : lpcfg_do_global_parameter(lp_ctx,
3152 : "rpc start on demand helpers",
3153 : "yes");
3154 :
3155 12558 : lpcfg_do_global_parameter(lp_ctx,
3156 : "ad dc functional level",
3157 : "2008_R2");
3158 :
3159 12558 : lpcfg_do_global_parameter(lp_ctx,
3160 : "acl claims evaluation",
3161 : "AD DC only");
3162 :
3163 6555892 : for (i = 0; parm_table[i].label; i++) {
3164 6542718 : if (!(lp_ctx->flags[i] & FLAG_CMDLINE)) {
3165 6542718 : lp_ctx->flags[i] |= FLAG_DEFAULT;
3166 : }
3167 : }
3168 :
3169 50232 : for (parm=lp_ctx->globals->param_opt; parm; parm=parm->next) {
3170 37674 : if (!(parm->priority & FLAG_CMDLINE)) {
3171 37674 : parm->priority |= FLAG_DEFAULT;
3172 : }
3173 : }
3174 :
3175 12558 : for (parm=lp_ctx->sDefault->param_opt; parm; parm=parm->next) {
3176 0 : if (!(parm->priority & FLAG_CMDLINE)) {
3177 0 : parm->priority |= FLAG_DEFAULT;
3178 : }
3179 : }
3180 :
3181 11942 : return lp_ctx;
3182 : }
3183 :
3184 : /**
3185 : * Initialise the global parameter structure.
3186 : */
3187 80473 : struct loadparm_context *loadparm_init_global(bool load_default)
3188 : {
3189 80473 : if (global_loadparm_context == NULL) {
3190 12387 : global_loadparm_context = loadparm_init(NULL);
3191 : }
3192 80473 : if (global_loadparm_context == NULL) {
3193 0 : return NULL;
3194 : }
3195 80473 : global_loadparm_context->global = true;
3196 80473 : if (load_default && !global_loadparm_context->loaded) {
3197 170 : lpcfg_load_default(global_loadparm_context);
3198 : }
3199 80473 : global_loadparm_context->refuse_free = true;
3200 80473 : return global_loadparm_context;
3201 : }
3202 :
3203 : /**
3204 : * @brief Initialise the global parameter structure.
3205 : *
3206 : * This function initialized the globals if needed. Make sure that
3207 : * gfree_loadparm() is called before the application exits.
3208 : *
3209 : * @param mem_ctx The talloc memory context to allocate lp_ctx on.
3210 : *
3211 : * @param s3_fns The loadparm helper functions to use
3212 : *
3213 : * @return An initialized lp_ctx pointer or NULL on error.
3214 : */
3215 836047 : struct loadparm_context *loadparm_init_s3(TALLOC_CTX *mem_ctx,
3216 : const struct loadparm_s3_helpers *s3_fns)
3217 : {
3218 836047 : struct loadparm_context *loadparm_context = talloc_zero(mem_ctx, struct loadparm_context);
3219 836047 : if (!loadparm_context) {
3220 0 : return NULL;
3221 : }
3222 836047 : loadparm_context->s3_fns = s3_fns;
3223 836047 : loadparm_context->globals = s3_fns->globals;
3224 836047 : loadparm_context->flags = s3_fns->flags;
3225 :
3226 : /* Make sure globals are correctly initialized */
3227 836047 : loadparm_context->s3_fns->init_globals(loadparm_context, false);
3228 :
3229 836047 : return loadparm_context;
3230 : }
3231 :
3232 430559 : const char *lpcfg_configfile(struct loadparm_context *lp_ctx)
3233 : {
3234 430559 : return lp_ctx->szConfigFile;
3235 : }
3236 :
3237 102585 : const char *lp_default_path(void)
3238 : {
3239 102585 : if (getenv("SMB_CONF_PATH"))
3240 86712 : return getenv("SMB_CONF_PATH");
3241 : else
3242 15873 : return dyn_CONFIGFILE;
3243 : }
3244 :
3245 : /**
3246 : * Update the internal state of a loadparm context after settings
3247 : * have changed.
3248 : */
3249 29826 : static bool lpcfg_update(struct loadparm_context *lp_ctx)
3250 : {
3251 681 : struct debug_settings settings;
3252 681 : int max_protocol, min_protocol;
3253 681 : TALLOC_CTX *tmp_ctx;
3254 681 : const struct loadparm_substitution *lp_sub =
3255 29826 : lpcfg_noop_substitution();
3256 :
3257 29826 : tmp_ctx = talloc_new(lp_ctx);
3258 29826 : if (tmp_ctx == NULL) {
3259 0 : return false;
3260 : }
3261 :
3262 29826 : lpcfg_add_auto_services(lp_ctx, lpcfg_auto_services(lp_ctx, lp_sub, tmp_ctx));
3263 :
3264 29826 : if (!lp_ctx->globals->wins_server_list && lp_ctx->globals->we_are_a_wins_server) {
3265 4553 : lpcfg_do_global_parameter(lp_ctx, "wins server", "127.0.0.1");
3266 : }
3267 :
3268 29826 : if (!lp_ctx->global) {
3269 134 : TALLOC_FREE(tmp_ctx);
3270 134 : return true;
3271 : }
3272 :
3273 29692 : panic_action = lp_ctx->globals->panic_action;
3274 :
3275 29692 : reload_charcnv(lp_ctx);
3276 :
3277 29692 : ZERO_STRUCT(settings);
3278 : /* Add any more debug-related smb.conf parameters created in
3279 : * future here */
3280 29692 : settings.timestamp_logs = lp_ctx->globals->timestamp_logs;
3281 29692 : settings.debug_prefix_timestamp = lp_ctx->globals->debug_prefix_timestamp;
3282 29692 : settings.debug_hires_timestamp = lp_ctx->globals->debug_hires_timestamp;
3283 29692 : settings.debug_syslog_format = lp_ctx->globals->debug_syslog_format;
3284 29692 : settings.debug_pid = lp_ctx->globals->debug_pid;
3285 29692 : settings.debug_uid = lp_ctx->globals->debug_uid;
3286 29692 : settings.debug_class = lp_ctx->globals->debug_class;
3287 29692 : settings.max_log_size = lp_ctx->globals->max_log_size;
3288 29692 : debug_set_settings(&settings, lp_ctx->globals->logging,
3289 29019 : lp_ctx->globals->syslog,
3290 29692 : lp_ctx->globals->syslog_only);
3291 :
3292 : /* FIXME: This is a bit of a hack, but we can't use a global, since
3293 : * not everything that uses lp also uses the socket library */
3294 29692 : if (lpcfg_parm_bool(lp_ctx, NULL, "socket", "testnonblock", false)) {
3295 176 : setenv("SOCKET_TESTNONBLOCK", "1", 1);
3296 : } else {
3297 29516 : unsetenv("SOCKET_TESTNONBLOCK");
3298 : }
3299 :
3300 : /* Check if command line max protocol < min protocol, if so
3301 : * report a warning to the user.
3302 : */
3303 29692 : max_protocol = lpcfg_client_max_protocol(lp_ctx);
3304 29692 : min_protocol = lpcfg_client_min_protocol(lp_ctx);
3305 29692 : if (lpcfg_client_max_protocol(lp_ctx) < lpcfg_client_min_protocol(lp_ctx)) {
3306 0 : const char *max_protocolp, *min_protocolp;
3307 0 : max_protocolp = lpcfg_get_smb_protocol(max_protocol);
3308 0 : min_protocolp = lpcfg_get_smb_protocol(min_protocol);
3309 0 : DBG_ERR("Max protocol %s is less than min protocol %s.\n",
3310 : max_protocolp, min_protocolp);
3311 : }
3312 :
3313 29692 : TALLOC_FREE(tmp_ctx);
3314 29692 : return true;
3315 : }
3316 :
3317 279 : bool lpcfg_load_default(struct loadparm_context *lp_ctx)
3318 : {
3319 11 : const char *path;
3320 :
3321 279 : path = lp_default_path();
3322 :
3323 279 : if (!file_exist(path)) {
3324 : /* We allow the default smb.conf file to not exist,
3325 : * basically the equivalent of an empty file. */
3326 2 : return lpcfg_update(lp_ctx);
3327 : }
3328 :
3329 277 : return lpcfg_load(lp_ctx, path);
3330 : }
3331 :
3332 : /**
3333 : * Load the services array from the services file.
3334 : *
3335 : * Return True on success, False on failure.
3336 : */
3337 32239 : static bool lpcfg_load_internal(struct loadparm_context *lp_ctx,
3338 : const char *filename, bool set_global)
3339 : {
3340 739 : char *n2;
3341 739 : bool bRetval;
3342 :
3343 32239 : if (lp_ctx->szConfigFile != NULL) {
3344 18532 : talloc_free(discard_const_p(char, lp_ctx->szConfigFile));
3345 18532 : lp_ctx->szConfigFile = NULL;
3346 : }
3347 :
3348 32239 : lp_ctx->szConfigFile = talloc_strdup(lp_ctx, filename);
3349 :
3350 32239 : if (lp_ctx->s3_fns) {
3351 2288 : return lp_ctx->s3_fns->load(filename);
3352 : }
3353 :
3354 29951 : lp_ctx->bInGlobalSection = true;
3355 29951 : n2 = standard_sub_basic(lp_ctx, lp_ctx->szConfigFile);
3356 29951 : DEBUG(2, ("lpcfg_load: refreshing parameters from %s\n", n2));
3357 :
3358 29951 : add_to_file_list(lp_ctx, &lp_ctx->file_lists, lp_ctx->szConfigFile, n2);
3359 :
3360 : /* We get sections first, so have to start 'behind' to make up */
3361 29951 : lp_ctx->currentService = NULL;
3362 29951 : bRetval = pm_process(n2, do_section, lpcfg_do_parameter, lp_ctx);
3363 :
3364 : /* finish up the last section */
3365 29951 : DEBUG(4, ("pm_process() returned %s\n", BOOLSTR(bRetval)));
3366 29951 : if (bRetval)
3367 29824 : if (lp_ctx->currentService != NULL)
3368 18402 : bRetval = lpcfg_service_ok(lp_ctx->currentService);
3369 :
3370 29951 : bRetval = bRetval && lpcfg_update(lp_ctx);
3371 :
3372 : /* we do this unconditionally, so that it happens even
3373 : for a missing smb.conf */
3374 29951 : reload_charcnv(lp_ctx);
3375 :
3376 29951 : if (bRetval == true && set_global) {
3377 : /* set this up so that any child python tasks will
3378 : find the right smb.conf */
3379 29718 : setenv("SMB_CONF_PATH", filename, 1);
3380 :
3381 : /* set the context used by the lp_*() function
3382 : variants */
3383 29718 : global_loadparm_context = lp_ctx;
3384 29718 : lp_ctx->loaded = true;
3385 : }
3386 :
3387 29263 : return bRetval;
3388 : }
3389 :
3390 108 : bool lpcfg_load_no_global(struct loadparm_context *lp_ctx, const char *filename)
3391 : {
3392 108 : return lpcfg_load_internal(lp_ctx, filename, false);
3393 : }
3394 :
3395 32131 : bool lpcfg_load(struct loadparm_context *lp_ctx, const char *filename)
3396 : {
3397 32131 : return lpcfg_load_internal(lp_ctx, filename, true);
3398 : }
3399 :
3400 : /**
3401 : * Return the max number of services.
3402 : */
3403 :
3404 5353 : int lpcfg_numservices(struct loadparm_context *lp_ctx)
3405 : {
3406 5353 : if (lp_ctx->s3_fns) {
3407 6 : return lp_ctx->s3_fns->get_numservices();
3408 : }
3409 :
3410 5347 : return lp_ctx->iNumServices;
3411 : }
3412 :
3413 : /**
3414 : * Display the contents of the services array in human-readable form.
3415 : */
3416 :
3417 771 : void lpcfg_dump(struct loadparm_context *lp_ctx, FILE *f, bool show_defaults,
3418 : int maxtoprint)
3419 : {
3420 25 : int iService;
3421 :
3422 771 : if (lp_ctx->s3_fns) {
3423 0 : lp_ctx->s3_fns->dump(f, show_defaults, maxtoprint);
3424 0 : return;
3425 : }
3426 :
3427 771 : lpcfg_dump_globals(lp_ctx, f, show_defaults);
3428 :
3429 771 : lpcfg_dump_a_service(lp_ctx->sDefault, lp_ctx->sDefault, f, lp_ctx->flags, show_defaults);
3430 :
3431 3875 : for (iService = 0; iService < maxtoprint; iService++)
3432 3079 : lpcfg_dump_one(f, show_defaults, lp_ctx->services[iService], lp_ctx->sDefault);
3433 : }
3434 :
3435 : /**
3436 : * Display the contents of one service in human-readable form.
3437 : */
3438 3080 : void lpcfg_dump_one(FILE *f, bool show_defaults, struct loadparm_service *service, struct loadparm_service *sDefault)
3439 : {
3440 3080 : if (service != NULL) {
3441 3080 : if (service->szService[0] == '\0')
3442 0 : return;
3443 3080 : lpcfg_dump_a_service(service, sDefault, f, NULL, show_defaults);
3444 : }
3445 : }
3446 :
3447 5206 : struct loadparm_service *lpcfg_servicebynum(struct loadparm_context *lp_ctx,
3448 : int snum)
3449 : {
3450 5206 : if (lp_ctx->s3_fns) {
3451 0 : return lp_ctx->s3_fns->get_servicebynum(snum);
3452 : }
3453 :
3454 5206 : return lp_ctx->services[snum];
3455 : }
3456 :
3457 8840 : struct loadparm_service *lpcfg_service(struct loadparm_context *lp_ctx,
3458 : const char *service_name)
3459 : {
3460 260 : int iService;
3461 260 : char *serviceName;
3462 :
3463 8840 : if (lp_ctx->s3_fns) {
3464 3 : return lp_ctx->s3_fns->get_service(service_name);
3465 : }
3466 :
3467 71508 : for (iService = lp_ctx->iNumServices - 1; iService >= 0; iService--) {
3468 71409 : if (lp_ctx->services[iService] &&
3469 71409 : lp_ctx->services[iService]->szService) {
3470 : /*
3471 : * The substitution here is used to support %U is
3472 : * service names
3473 : */
3474 71409 : serviceName = standard_sub_basic(
3475 69003 : lp_ctx->services[iService],
3476 69003 : lp_ctx->services[iService]->szService);
3477 71409 : if (strequal(serviceName, service_name)) {
3478 8738 : talloc_free(serviceName);
3479 8738 : return lp_ctx->services[iService];
3480 : }
3481 62671 : talloc_free(serviceName);
3482 : }
3483 : }
3484 :
3485 99 : DEBUG(7,("lpcfg_servicenumber: couldn't find %s\n", service_name));
3486 89 : return NULL;
3487 : }
3488 :
3489 8637 : const char *lpcfg_servicename(const struct loadparm_service *service)
3490 : {
3491 8637 : return service ? lpcfg_string((const char *)service->szService) : NULL;
3492 : }
3493 :
3494 2095240 : struct smb_iconv_handle *lpcfg_iconv_handle(struct loadparm_context *lp_ctx)
3495 : {
3496 2095240 : if (lp_ctx == NULL) {
3497 0 : return get_iconv_handle();
3498 : }
3499 2095240 : return lp_ctx->iconv_handle;
3500 : }
3501 :
3502 77615 : _PUBLIC_ void reload_charcnv(struct loadparm_context *lp_ctx)
3503 : {
3504 77615 : if (!lp_ctx->global) {
3505 126 : return;
3506 : }
3507 :
3508 78959 : lp_ctx->iconv_handle =
3509 77479 : reinit_iconv_handle(lp_ctx,
3510 : lpcfg_dos_charset(lp_ctx),
3511 : lpcfg_unix_charset(lp_ctx));
3512 77479 : if (lp_ctx->iconv_handle == NULL) {
3513 0 : smb_panic("reinit_iconv_handle failed");
3514 : }
3515 : }
3516 :
3517 62 : _PUBLIC_ char *lpcfg_tls_keyfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
3518 : {
3519 62 : return lpcfg_private_path(mem_ctx, lp_ctx, lpcfg__tls_keyfile(lp_ctx));
3520 : }
3521 :
3522 62 : _PUBLIC_ char *lpcfg_tls_certfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
3523 : {
3524 62 : return lpcfg_private_path(mem_ctx, lp_ctx, lpcfg__tls_certfile(lp_ctx));
3525 : }
3526 :
3527 684 : _PUBLIC_ char *lpcfg_tls_cafile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
3528 : {
3529 684 : return lpcfg_private_path(mem_ctx, lp_ctx, lpcfg__tls_cafile(lp_ctx));
3530 : }
3531 :
3532 684 : _PUBLIC_ char *lpcfg_tls_crlfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
3533 : {
3534 684 : return lpcfg_private_path(mem_ctx, lp_ctx, lpcfg__tls_crlfile(lp_ctx));
3535 : }
3536 :
3537 62 : _PUBLIC_ char *lpcfg_tls_dhpfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
3538 : {
3539 62 : return lpcfg_private_path(mem_ctx, lp_ctx, lpcfg__tls_dhpfile(lp_ctx));
3540 : }
3541 :
3542 297589 : struct gensec_settings *lpcfg_gensec_settings(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
3543 : {
3544 297589 : struct gensec_settings *settings = talloc_zero(mem_ctx, struct gensec_settings);
3545 297589 : if (settings == NULL)
3546 0 : return NULL;
3547 297589 : SMB_ASSERT(lp_ctx != NULL);
3548 297589 : settings->lp_ctx = talloc_reference(settings, lp_ctx);
3549 297589 : settings->target_hostname = lpcfg_parm_string(lp_ctx, NULL, "gensec", "target_hostname");
3550 297589 : return settings;
3551 : }
3552 :
3553 686153 : int lpcfg_server_role(struct loadparm_context *lp_ctx)
3554 : {
3555 686153 : int domain_master = lpcfg__domain_master(lp_ctx);
3556 :
3557 1351914 : return lp_find_server_role(lpcfg__server_role(lp_ctx),
3558 : lpcfg__security(lp_ctx),
3559 686153 : lpcfg__domain_logons(lp_ctx),
3560 20392 : (domain_master == true) ||
3561 : (domain_master == Auto));
3562 : }
3563 :
3564 68209 : int lpcfg_security(struct loadparm_context *lp_ctx)
3565 : {
3566 68209 : return lp_find_security(lpcfg__server_role(lp_ctx),
3567 : lpcfg__security(lp_ctx));
3568 : }
3569 :
3570 59384 : int lpcfg_client_max_protocol(struct loadparm_context *lp_ctx)
3571 : {
3572 59384 : int client_max_protocol = lpcfg__client_max_protocol(lp_ctx);
3573 59384 : if (client_max_protocol == PROTOCOL_DEFAULT) {
3574 59364 : return PROTOCOL_LATEST;
3575 : }
3576 20 : return client_max_protocol;
3577 : }
3578 :
3579 6431 : int lpcfg_client_ipc_min_protocol(struct loadparm_context *lp_ctx)
3580 : {
3581 6431 : int client_ipc_min_protocol = lpcfg__client_ipc_min_protocol(lp_ctx);
3582 6431 : if (client_ipc_min_protocol == PROTOCOL_DEFAULT) {
3583 6423 : client_ipc_min_protocol = lpcfg_client_min_protocol(lp_ctx);
3584 : }
3585 6431 : if (client_ipc_min_protocol < PROTOCOL_NT1) {
3586 5686 : return PROTOCOL_NT1;
3587 : }
3588 355 : return client_ipc_min_protocol;
3589 : }
3590 :
3591 6431 : int lpcfg_client_ipc_max_protocol(struct loadparm_context *lp_ctx)
3592 : {
3593 6431 : int client_ipc_max_protocol = lpcfg__client_ipc_max_protocol(lp_ctx);
3594 6431 : if (client_ipc_max_protocol == PROTOCOL_DEFAULT) {
3595 6029 : return PROTOCOL_LATEST;
3596 : }
3597 12 : if (client_ipc_max_protocol < PROTOCOL_NT1) {
3598 0 : return PROTOCOL_NT1;
3599 : }
3600 12 : return client_ipc_max_protocol;
3601 : }
3602 :
3603 286711 : int lpcfg_client_ipc_signing(struct loadparm_context *lp_ctx)
3604 : {
3605 286711 : int client_ipc_signing = lpcfg__client_ipc_signing(lp_ctx);
3606 286711 : if (client_ipc_signing == SMB_SIGNING_DEFAULT) {
3607 286711 : return SMB_SIGNING_REQUIRED;
3608 : }
3609 0 : return client_ipc_signing;
3610 : }
3611 :
3612 215809 : enum credentials_use_kerberos lpcfg_client_use_kerberos(struct loadparm_context *lp_ctx)
3613 : {
3614 215809 : if (lpcfg_weak_crypto(lp_ctx) == SAMBA_WEAK_CRYPTO_DISALLOWED) {
3615 7 : return CRED_USE_KERBEROS_REQUIRED;
3616 : }
3617 :
3618 215802 : return lpcfg__client_use_kerberos(lp_ctx);
3619 : }
3620 :
3621 68175 : bool lpcfg_server_signing_allowed(struct loadparm_context *lp_ctx, bool *mandatory)
3622 : {
3623 68175 : bool allowed = true;
3624 68175 : enum smb_signing_setting signing_setting = lpcfg_server_signing(lp_ctx);
3625 :
3626 68175 : *mandatory = false;
3627 :
3628 68175 : if (signing_setting == SMB_SIGNING_DEFAULT) {
3629 : /*
3630 : * If we are a domain controller, SMB signing is
3631 : * really important, as it can prevent a number of
3632 : * attacks on communications between us and the
3633 : * clients
3634 : *
3635 : * However, it really sucks (no sendfile, CPU
3636 : * overhead) performance-wise when used on a
3637 : * file server, so disable it by default
3638 : * on non-DCs
3639 : */
3640 :
3641 67069 : if (lpcfg_server_role(lp_ctx) >= ROLE_ACTIVE_DIRECTORY_DC) {
3642 20241 : signing_setting = SMB_SIGNING_REQUIRED;
3643 : } else {
3644 45000 : signing_setting = SMB_SIGNING_OFF;
3645 : }
3646 : }
3647 :
3648 66347 : switch (signing_setting) {
3649 23041 : case SMB_SIGNING_REQUIRED:
3650 23041 : *mandatory = true;
3651 23041 : break;
3652 134 : case SMB_SIGNING_DESIRED:
3653 : case SMB_SIGNING_IF_REQUIRED:
3654 134 : break;
3655 45000 : case SMB_SIGNING_OFF:
3656 45000 : allowed = false;
3657 45000 : break;
3658 0 : case SMB_SIGNING_DEFAULT:
3659 : case SMB_SIGNING_IPC_DEFAULT:
3660 0 : smb_panic(__location__);
3661 1828 : break;
3662 : }
3663 :
3664 68175 : return allowed;
3665 : }
3666 :
3667 329430 : int lpcfg_tdb_hash_size(struct loadparm_context *lp_ctx, const char *name)
3668 : {
3669 11984 : const char *base;
3670 :
3671 329430 : if (name == NULL) {
3672 0 : return 0;
3673 : }
3674 :
3675 329430 : base = strrchr_m(name, '/');
3676 329430 : if (base != NULL) {
3677 329424 : base += 1;
3678 : } else {
3679 0 : base = name;
3680 : }
3681 329430 : return lpcfg_parm_int(lp_ctx, NULL, "tdb_hashsize", base, 0);
3682 :
3683 : }
3684 :
3685 1108359 : int lpcfg_tdb_flags(struct loadparm_context *lp_ctx, int tdb_flags)
3686 : {
3687 1108359 : if (!lpcfg_use_mmap(lp_ctx)) {
3688 0 : tdb_flags |= TDB_NOMMAP;
3689 : }
3690 1108359 : return tdb_flags;
3691 : }
3692 :
3693 : /*
3694 : * Do not allow LanMan auth if unless NTLMv1 is also allowed
3695 : *
3696 : * This also ensures it is disabled if NTLM is totally disabled
3697 : */
3698 70410 : bool lpcfg_lanman_auth(struct loadparm_context *lp_ctx)
3699 : {
3700 70410 : enum ntlm_auth_level ntlm_auth_level = lpcfg_ntlm_auth(lp_ctx);
3701 :
3702 70410 : if (ntlm_auth_level == NTLM_AUTH_ON) {
3703 36062 : return lpcfg__lanman_auth(lp_ctx);
3704 : } else {
3705 34348 : return false;
3706 : }
3707 : }
3708 :
3709 47761 : static char *lpcfg_noop_substitution_fn(
3710 : TALLOC_CTX *mem_ctx,
3711 : const struct loadparm_substitution *lp_sub,
3712 : const char *raw_value,
3713 : void *private_data)
3714 : {
3715 47761 : return talloc_strdup(mem_ctx, raw_value);
3716 : }
3717 :
3718 : static const struct loadparm_substitution global_noop_substitution = {
3719 : .substituted_string_fn = lpcfg_noop_substitution_fn,
3720 : };
3721 :
3722 48044 : const struct loadparm_substitution *lpcfg_noop_substitution(void)
3723 : {
3724 48044 : return &global_noop_substitution;
3725 : }
3726 :
3727 2569362 : char *lpcfg_substituted_string(TALLOC_CTX *mem_ctx,
3728 : const struct loadparm_substitution *lp_sub,
3729 : const char *raw_value)
3730 : {
3731 5138724 : return lp_sub->substituted_string_fn(mem_ctx,
3732 : lp_sub,
3733 : raw_value,
3734 2569362 : lp_sub->private_data);
3735 : }
3736 :
3737 : /**
3738 : * @brief Parse a string value of a given parameter to its integer enum value.
3739 : *
3740 : * @param[in] param_name The parameter name (e.g. 'client smb encrypt')
3741 : *
3742 : * @param[in] param_value The parameter value (e.g. 'required').
3743 : *
3744 : * @return The integer value of the enum the param_value matches or INT32_MIN
3745 : * on error.
3746 : */
3747 398 : int32_t lpcfg_parse_enum_vals(const char *param_name,
3748 : const char *param_value)
3749 : {
3750 398 : struct parm_struct *parm = NULL;
3751 398 : int32_t ret = INT32_MIN;
3752 8 : bool ok;
3753 :
3754 398 : parm = lpcfg_parm_struct(NULL, param_name);
3755 398 : if (parm == NULL) {
3756 0 : return INT32_MIN;
3757 : }
3758 :
3759 398 : ok = lp_set_enum_parm(parm, param_value, &ret);
3760 398 : if (!ok) {
3761 0 : return INT32_MIN;
3762 : }
3763 :
3764 396 : return ret;
3765 : }
3766 :
3767 16117 : const char *lpcfg_dns_hostname(struct loadparm_context *lp_ctx)
3768 : {
3769 16117 : const char *dns_hostname = lpcfg__dns_hostname(lp_ctx);
3770 16117 : const char *dns_domain = lpcfg_dnsdomain(lp_ctx);
3771 16117 : char *netbios_name = NULL;
3772 16117 : char *hostname = NULL;
3773 :
3774 16117 : if (dns_hostname != NULL && dns_hostname[0] != '\0') {
3775 7305 : return dns_hostname;
3776 : }
3777 :
3778 8776 : netbios_name = strlower_talloc(lp_ctx, lpcfg_netbios_name(lp_ctx));
3779 8776 : if (netbios_name == NULL) {
3780 0 : return NULL;
3781 : }
3782 :
3783 : /* If it isn't set, try to initialize with [netbios name].[realm] */
3784 8776 : if (dns_domain != NULL && dns_domain[0] != '\0') {
3785 8774 : hostname = talloc_asprintf(lp_ctx,
3786 : "%s.%s",
3787 : netbios_name,
3788 : dns_domain);
3789 : } else {
3790 2 : hostname = talloc_strdup(lp_ctx, netbios_name);
3791 : }
3792 8776 : TALLOC_FREE(netbios_name);
3793 8776 : if (hostname == NULL) {
3794 0 : return NULL;
3795 : }
3796 :
3797 8776 : lpcfg_string_set(lp_ctx->globals->ctx,
3798 8776 : &lp_ctx->globals->_dns_hostname,
3799 : hostname);
3800 :
3801 8776 : return hostname;
3802 : }
|