lib/param: use strwicmp instead of strlower_talloc
[Samba.git] / lib / param / loadparm.c
blobb6f1f85a6ec85f36e64d43b77b8c44e74387017d
1 /*
2 Unix SMB/CIFS implementation.
3 Parameter loading functions
4 Copyright (C) Karl Auer 1993-1998
6 Largely re-written by Andrew Tridgell, September 1994
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
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.
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.
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/>.
31 * Load parameters.
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.
37 * To add a parameter:
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
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!
56 #include "includes.h"
57 #include "version.h"
58 #include "dynconfig/dynconfig.h"
59 #include "system/time.h"
60 #include "system/locale.h"
61 #include "system/network.h" /* needed for TCP_NODELAY */
62 #include "../lib/util/dlinklist.h"
63 #include "lib/param/param.h"
64 #include "lib/param/loadparm.h"
65 #include "auth/gensec/gensec.h"
66 #include "lib/param/s3_param.h"
67 #include "lib/util/bitmap.h"
68 #include "libcli/smb/smb_constants.h"
69 #include "tdb.h"
71 #define standard_sub_basic talloc_strdup
73 static bool do_parameter(const char *, const char *, void *);
74 static bool defaults_saved = false;
76 #include "lib/param/param_global.h"
78 #define NUMPARAMETERS (num_parameters())
80 struct loadparm_service *lpcfg_default_service(struct loadparm_context *lp_ctx)
82 if (lp_ctx->s3_fns) {
83 return lp_ctx->s3_fns->get_default_loadparm_service();
85 return lp_ctx->sDefault;
88 /**
89 * Convenience routine to grab string parameters into temporary memory
90 * and run standard_sub_basic on them.
92 * The buffers can be written to by
93 * callers without affecting the source string.
96 static const char *lpcfg_string(const char *s)
98 #if 0 /* until REWRITE done to make thread-safe */
99 size_t len = s ? strlen(s) : 0;
100 char *ret;
101 #endif
103 /* The follow debug is useful for tracking down memory problems
104 especially if you have an inner loop that is calling a lp_*()
105 function that returns a string. Perhaps this debug should be
106 present all the time? */
108 #if 0
109 DEBUG(10, ("lpcfg_string(%s)\n", s));
110 #endif
112 #if 0 /* until REWRITE done to make thread-safe */
113 if (!lp_talloc)
114 lp_talloc = talloc_init("lp_talloc");
116 ret = talloc_array(lp_talloc, char, len + 100); /* leave room for substitution */
118 if (!ret)
119 return NULL;
121 if (!s)
122 *ret = 0;
123 else
124 strlcpy(ret, s, len);
126 if (trim_string(ret, "\"", "\"")) {
127 if (strchr(ret,'"') != NULL)
128 strlcpy(ret, s, len);
131 standard_sub_basic(ret,len+100);
132 return (ret);
133 #endif
134 return s;
138 In this section all the functions that are used to access the
139 parameters from the rest of the program are defined
143 * the creation of separate lpcfg_*() and lp_*() functions is to allow
144 * for code compatibility between existing Samba4 and Samba3 code.
147 /* this global context supports the lp_*() function varients */
148 static struct loadparm_context *global_loadparm_context;
150 #define lpcfg_default_service global_loadparm_context->sDefault
151 #define lpcfg_global_service(i) global_loadparm_context->services[i]
153 #define FN_GLOBAL_STRING(fn_name,var_name) \
154 _PUBLIC_ char *lpcfg_ ## fn_name(struct loadparm_context *lp_ctx, TALLOC_CTX *ctx) {\
155 if (lp_ctx == NULL) return NULL; \
156 if (lp_ctx->s3_fns) { \
157 return lp_ctx->globals->var_name ? lp_ctx->s3_fns->lp_string(ctx, lp_ctx->globals->var_name) : talloc_strdup(ctx, ""); \
159 return lp_ctx->globals->var_name ? talloc_strdup(ctx, lpcfg_string(lp_ctx->globals->var_name)) : talloc_strdup(ctx, ""); \
162 #define FN_GLOBAL_CONST_STRING(fn_name,var_name) \
163 _PUBLIC_ const char *lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) { \
164 if (lp_ctx == NULL) return NULL; \
165 return lp_ctx->globals->var_name ? lpcfg_string(lp_ctx->globals->var_name) : ""; \
168 #define FN_GLOBAL_LIST(fn_name,var_name) \
169 _PUBLIC_ const char **lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) { \
170 if (lp_ctx == NULL) return NULL; \
171 return lp_ctx->globals->var_name; \
174 #define FN_GLOBAL_BOOL(fn_name,var_name) \
175 _PUBLIC_ bool lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) {\
176 if (lp_ctx == NULL) return false; \
177 return lp_ctx->globals->var_name; \
180 #define FN_GLOBAL_INTEGER(fn_name,var_name) \
181 _PUBLIC_ int lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) { \
182 return lp_ctx->globals->var_name; \
185 /* Local parameters don't need the ->s3_fns because the struct
186 * loadparm_service is shared and lpcfg_service() checks the ->s3_fns
187 * hook */
188 #define FN_LOCAL_STRING(fn_name,val) \
189 _PUBLIC_ char *lpcfg_ ## fn_name(struct loadparm_service *service, \
190 struct loadparm_service *sDefault, TALLOC_CTX *ctx) { \
191 return(talloc_strdup(ctx, lpcfg_string((const char *)((service != NULL && service->val != NULL) ? service->val : sDefault->val)))); \
194 #define FN_LOCAL_CONST_STRING(fn_name,val) \
195 _PUBLIC_ const char *lpcfg_ ## fn_name(struct loadparm_service *service, \
196 struct loadparm_service *sDefault) { \
197 return((const char *)((service != NULL && service->val != NULL) ? service->val : sDefault->val)); \
200 #define FN_LOCAL_LIST(fn_name,val) \
201 _PUBLIC_ const char **lpcfg_ ## fn_name(struct loadparm_service *service, \
202 struct loadparm_service *sDefault) {\
203 return(const char **)(service != NULL && service->val != NULL? service->val : sDefault->val); \
206 #define FN_LOCAL_PARM_BOOL(fn_name, val) FN_LOCAL_BOOL(fn_name, val)
208 #define FN_LOCAL_BOOL(fn_name,val) \
209 _PUBLIC_ bool lpcfg_ ## fn_name(struct loadparm_service *service, \
210 struct loadparm_service *sDefault) { \
211 return((service != NULL)? service->val : sDefault->val); \
214 #define FN_LOCAL_INTEGER(fn_name,val) \
215 _PUBLIC_ int lpcfg_ ## fn_name(struct loadparm_service *service, \
216 struct loadparm_service *sDefault) { \
217 return((service != NULL)? service->val : sDefault->val); \
220 #define FN_LOCAL_PARM_INTEGER(fn_name, val) FN_LOCAL_INTEGER(fn_name, val)
222 #define FN_LOCAL_PARM_CHAR(fn_name,val) \
223 _PUBLIC_ char lpcfg_ ## fn_name(struct loadparm_service *service, \
224 struct loadparm_service *sDefault) { \
225 return((service != NULL)? service->val : sDefault->val); \
228 #include "lib/param/param_functions.c"
230 /* These functions cannot be auto-generated */
231 FN_LOCAL_BOOL(autoloaded, autoloaded)
232 FN_GLOBAL_CONST_STRING(dnsdomain, dnsdomain)
234 /* local prototypes */
235 static struct loadparm_service *lpcfg_getservicebyname(struct loadparm_context *lp_ctx,
236 const char *pszServiceName);
237 static bool lpcfg_service_ok(struct loadparm_service *service);
238 static bool do_section(const char *pszSectionName, void *);
240 /* This is a helper function for parametrical options support. */
241 /* It returns a pointer to parametrical option value if it exists or NULL otherwise */
242 /* Actual parametrical functions are quite simple */
243 const char *lpcfg_get_parametric(struct loadparm_context *lp_ctx,
244 struct loadparm_service *service,
245 const char *type, const char *option)
247 char *vfskey = NULL;
248 struct parmlist_entry *data;
250 if (lp_ctx == NULL)
251 return NULL;
253 if (lp_ctx->s3_fns) {
254 return lp_ctx->s3_fns->get_parametric(service, type, option, NULL);
257 data = (service == NULL ? lp_ctx->globals->param_opt : service->param_opt);
259 vfskey = talloc_asprintf(NULL, "%s:%s", type, option);
260 if (vfskey == NULL) {
261 DEBUG(0,("asprintf failed!\n"));
262 return NULL;
265 while (data) {
266 if (strwicmp(data->key, vfskey) == 0) {
267 talloc_free(vfskey);
268 return data->value;
270 data = data->next;
273 if (service != NULL) {
274 /* Try to fetch the same option but from globals */
275 /* but only if we are not already working with globals */
276 for (data = lp_ctx->globals->param_opt; data;
277 data = data->next) {
278 if (strwicmp(data->key, vfskey) == 0) {
279 talloc_free(vfskey);
280 return data->value;
285 talloc_free(vfskey);
287 return NULL;
292 * convenience routine to return int parameters.
294 int lp_int(const char *s)
297 if (!s || !*s) {
298 DEBUG(0,("lp_int(%s): is called with NULL!\n",s));
299 return -1;
302 return strtol(s, NULL, 0);
306 * convenience routine to return unsigned long parameters.
308 unsigned long lp_ulong(const char *s)
311 if (!s || !*s) {
312 DEBUG(0,("lp_ulong(%s): is called with NULL!\n",s));
313 return -1;
316 return strtoul(s, NULL, 0);
320 * convenience routine to return unsigned long parameters.
322 static long lp_long(const char *s)
325 if (!s) {
326 DEBUG(0,("lp_long(%s): is called with NULL!\n",s));
327 return -1;
330 return strtol(s, NULL, 0);
334 * convenience routine to return unsigned long parameters.
336 static double lp_double(const char *s)
339 if (!s) {
340 DEBUG(0,("lp_double(%s): is called with NULL!\n",s));
341 return -1;
344 return strtod(s, NULL);
348 * convenience routine to return boolean parameters.
350 bool lp_bool(const char *s)
352 bool ret = false;
354 if (!s || !*s) {
355 DEBUG(0,("lp_bool(%s): is called with NULL!\n",s));
356 return false;
359 if (!set_boolean(s, &ret)) {
360 DEBUG(0,("lp_bool(%s): value is not boolean!\n",s));
361 return false;
364 return ret;
368 * Return parametric option from a given service. Type is a part of option before ':'
369 * Parametric option has following syntax: 'Type: option = value'
370 * Returned value is allocated in 'lp_talloc' context
373 const char *lpcfg_parm_string(struct loadparm_context *lp_ctx,
374 struct loadparm_service *service, const char *type,
375 const char *option)
377 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
379 if (value)
380 return lpcfg_string(value);
382 return NULL;
386 * Return parametric option from a given service. Type is a part of option before ':'
387 * Parametric option has following syntax: 'Type: option = value'
388 * Returned value is allocated in 'lp_talloc' context
391 const char **lpcfg_parm_string_list(TALLOC_CTX *mem_ctx,
392 struct loadparm_context *lp_ctx,
393 struct loadparm_service *service,
394 const char *type,
395 const char *option, const char *separator)
397 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
399 if (value != NULL)
400 return (const char **)str_list_make(mem_ctx, value, separator);
402 return NULL;
406 * Return parametric option from a given service. Type is a part of option before ':'
407 * Parametric option has following syntax: 'Type: option = value'
410 int lpcfg_parm_int(struct loadparm_context *lp_ctx,
411 struct loadparm_service *service, const char *type,
412 const char *option, int default_v)
414 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
416 if (value)
417 return lp_int(value);
419 return default_v;
423 * Return parametric option from a given service. Type is a part of
424 * option before ':'.
425 * Parametric option has following syntax: 'Type: option = value'.
428 int lpcfg_parm_bytes(struct loadparm_context *lp_ctx,
429 struct loadparm_service *service, const char *type,
430 const char *option, int default_v)
432 uint64_t bval;
434 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
436 if (value && conv_str_size_error(value, &bval)) {
437 if (bval <= INT_MAX) {
438 return (int)bval;
442 return default_v;
446 * Return parametric option from a given service.
447 * Type is a part of option before ':'
448 * Parametric option has following syntax: 'Type: option = value'
450 unsigned long lpcfg_parm_ulong(struct loadparm_context *lp_ctx,
451 struct loadparm_service *service, const char *type,
452 const char *option, unsigned long default_v)
454 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
456 if (value)
457 return lp_ulong(value);
459 return default_v;
462 long lpcfg_parm_long(struct loadparm_context *lp_ctx,
463 struct loadparm_service *service, const char *type,
464 const char *option, long default_v)
466 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
468 if (value)
469 return lp_long(value);
471 return default_v;
474 double lpcfg_parm_double(struct loadparm_context *lp_ctx,
475 struct loadparm_service *service, const char *type,
476 const char *option, double default_v)
478 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
480 if (value != NULL)
481 return lp_double(value);
483 return default_v;
487 * Return parametric option from a given service. Type is a part of option before ':'
488 * Parametric option has following syntax: 'Type: option = value'
491 bool lpcfg_parm_bool(struct loadparm_context *lp_ctx,
492 struct loadparm_service *service, const char *type,
493 const char *option, bool default_v)
495 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
497 if (value != NULL)
498 return lp_bool(value);
500 return default_v;
505 * Set a string value, deallocating any existing space, and allocing the space
506 * for the string
508 bool lpcfg_string_set(TALLOC_CTX *mem_ctx, char **dest, const char *src)
510 talloc_free(*dest);
512 if (src == NULL)
513 src = "";
515 *dest = talloc_strdup(mem_ctx, src);
516 if ((*dest) == NULL) {
517 DEBUG(0,("Out of memory in string_set\n"));
518 return false;
521 return true;
525 * Set a string value, deallocating any existing space, and allocing the space
526 * for the string
528 static bool lpcfg_string_set_upper(TALLOC_CTX *mem_ctx, char **dest, const char *src)
530 talloc_free(*dest);
532 if (src == NULL)
533 src = "";
535 *dest = strupper_talloc(mem_ctx, src);
536 if ((*dest) == NULL) {
537 DEBUG(0,("Out of memory in string_set_upper\n"));
538 return false;
541 return true;
547 * Add a new service to the services array initialising it with the given
548 * service.
551 struct loadparm_service *lpcfg_add_service(struct loadparm_context *lp_ctx,
552 const struct loadparm_service *pservice,
553 const char *name)
555 int i;
556 int num_to_alloc = lp_ctx->iNumServices + 1;
557 struct parmlist_entry *data, *pdata;
559 if (pservice == NULL) {
560 pservice = lp_ctx->sDefault;
563 /* it might already exist */
564 if (name) {
565 struct loadparm_service *service = lpcfg_getservicebyname(lp_ctx,
566 name);
567 if (service != NULL) {
568 /* Clean all parametric options for service */
569 /* They will be added during parsing again */
570 data = service->param_opt;
571 while (data) {
572 pdata = data->next;
573 talloc_free(data);
574 data = pdata;
576 service->param_opt = NULL;
577 return service;
581 /* find an invalid one */
582 for (i = 0; i < lp_ctx->iNumServices; i++)
583 if (lp_ctx->services[i] == NULL)
584 break;
586 /* if not, then create one */
587 if (i == lp_ctx->iNumServices) {
588 struct loadparm_service **tsp;
590 tsp = talloc_realloc(lp_ctx, lp_ctx->services, struct loadparm_service *, num_to_alloc);
592 if (!tsp) {
593 DEBUG(0,("lpcfg_add_service: failed to enlarge services!\n"));
594 return NULL;
595 } else {
596 lp_ctx->services = tsp;
597 lp_ctx->services[lp_ctx->iNumServices] = NULL;
600 lp_ctx->iNumServices++;
603 lp_ctx->services[i] = talloc_zero(lp_ctx->services, struct loadparm_service);
604 if (lp_ctx->services[i] == NULL) {
605 DEBUG(0,("lpcfg_add_service: out of memory!\n"));
606 return NULL;
608 copy_service(lp_ctx->services[i], pservice, NULL);
609 if (name != NULL)
610 lpcfg_string_set(lp_ctx->services[i], &lp_ctx->services[i]->szService, name);
611 return lp_ctx->services[i];
615 * Add a new home service, with the specified home directory, defaults coming
616 * from service ifrom.
619 bool lpcfg_add_home(struct loadparm_context *lp_ctx,
620 const char *pszHomename,
621 struct loadparm_service *default_service,
622 const char *user, const char *pszHomedir)
624 struct loadparm_service *service;
626 service = lpcfg_add_service(lp_ctx, default_service, pszHomename);
628 if (service == NULL)
629 return false;
631 if (!(*(default_service->path))
632 || strequal(default_service->path, lp_ctx->sDefault->path)) {
633 service->path = talloc_strdup(service, pszHomedir);
634 } else {
635 service->path = string_sub_talloc(service, lpcfg_path(default_service, lp_ctx->sDefault, service), "%H", pszHomedir);
638 if (!(*(service->comment))) {
639 service->comment = talloc_asprintf(service, "Home directory of %s", user);
641 service->bAvailable = default_service->bAvailable;
642 service->browseable = default_service->browseable;
644 DEBUG(3, ("adding home's share [%s] for user '%s' at '%s'\n",
645 pszHomename, user, service->path));
647 return true;
651 * Add a new printer service, with defaults coming from service iFrom.
654 bool lpcfg_add_printer(struct loadparm_context *lp_ctx,
655 const char *pszPrintername,
656 struct loadparm_service *default_service)
658 const char *comment = "From Printcap";
659 struct loadparm_service *service;
660 service = lpcfg_add_service(lp_ctx, default_service, pszPrintername);
662 if (service == NULL)
663 return false;
665 /* note that we do NOT default the availability flag to True - */
666 /* we take it from the default service passed. This allows all */
667 /* dynamic printers to be disabled by disabling the [printers] */
668 /* entry (if/when the 'available' keyword is implemented!). */
670 /* the printer name is set to the service name. */
671 lpcfg_string_set(service, &service->_printername, pszPrintername);
672 lpcfg_string_set(service, &service->comment, comment);
673 service->browseable = default_service->browseable;
674 /* Printers cannot be read_only. */
675 service->read_only = false;
676 /* Printer services must be printable. */
677 service->printable = true;
679 DEBUG(3, ("adding printer service %s\n", pszPrintername));
681 return true;
685 * Map a parameter's string representation to something we can use.
686 * Returns False if the parameter string is not recognised, else TRUE.
689 int lpcfg_map_parameter(const char *pszParmName)
691 int iIndex;
693 for (iIndex = 0; parm_table[iIndex].label; iIndex++)
694 if (strwicmp(parm_table[iIndex].label, pszParmName) == 0)
695 return iIndex;
697 /* Warn only if it isn't parametric option */
698 if (strchr(pszParmName, ':') == NULL)
699 DEBUG(0, ("Unknown parameter encountered: \"%s\"\n", pszParmName));
700 /* We do return 'fail' for parametric options as well because they are
701 stored in different storage
703 return -1;
708 return the parameter structure for a parameter
710 struct parm_struct *lpcfg_parm_struct(struct loadparm_context *lp_ctx, const char *name)
712 int parmnum;
714 if (lp_ctx->s3_fns) {
715 return lp_ctx->s3_fns->get_parm_struct(name);
718 parmnum = lpcfg_map_parameter(name);
719 if (parmnum == -1) return NULL;
720 return &parm_table[parmnum];
724 return the parameter pointer for a parameter
726 void *lpcfg_parm_ptr(struct loadparm_context *lp_ctx,
727 struct loadparm_service *service, struct parm_struct *parm)
729 if (lp_ctx->s3_fns) {
730 return lp_ctx->s3_fns->get_parm_ptr(service, parm);
733 if (service == NULL) {
734 if (parm->p_class == P_LOCAL)
735 return ((char *)lp_ctx->sDefault)+parm->offset;
736 else if (parm->p_class == P_GLOBAL)
737 return ((char *)lp_ctx->globals)+parm->offset;
738 else return NULL;
739 } else {
740 return ((char *)service) + parm->offset;
745 return the parameter pointer for a parameter
747 bool lpcfg_parm_is_cmdline(struct loadparm_context *lp_ctx, const char *name)
749 int parmnum;
751 if (lp_ctx->s3_fns) {
752 struct parm_struct *parm = lp_ctx->s3_fns->get_parm_struct(name);
753 if (parm) {
754 return parm->flags & FLAG_CMDLINE;
756 return false;
759 parmnum = lpcfg_map_parameter(name);
760 if (parmnum == -1) return false;
762 return lp_ctx->flags[parmnum] & FLAG_CMDLINE;
766 * Find a service by name. Otherwise works like get_service.
769 static struct loadparm_service *lpcfg_getservicebyname(struct loadparm_context *lp_ctx,
770 const char *pszServiceName)
772 int iService;
774 if (lp_ctx->s3_fns) {
775 return lp_ctx->s3_fns->get_service(pszServiceName);
778 for (iService = lp_ctx->iNumServices - 1; iService >= 0; iService--)
779 if (lp_ctx->services[iService] != NULL &&
780 strwicmp(lp_ctx->services[iService]->szService, pszServiceName) == 0) {
781 return lp_ctx->services[iService];
784 return NULL;
788 * Add a parametric option to a parmlist_entry,
789 * replacing old value, if already present.
791 void set_param_opt(TALLOC_CTX *mem_ctx,
792 struct parmlist_entry **opt_list,
793 const char *opt_name,
794 const char *opt_value,
795 unsigned priority)
797 struct parmlist_entry *new_opt, *opt;
798 bool not_added;
800 opt = *opt_list;
801 not_added = true;
803 /* Traverse destination */
804 while (opt) {
805 /* If we already have same option, override it */
806 if (strwicmp(opt->key, opt_name) == 0) {
807 if ((opt->priority & FLAG_CMDLINE) &&
808 !(priority & FLAG_CMDLINE)) {
809 /* it's been marked as not to be
810 overridden */
811 return;
813 TALLOC_FREE(opt->value);
814 TALLOC_FREE(opt->list);
815 opt->value = talloc_strdup(opt, opt_value);
816 opt->priority = priority;
817 not_added = false;
818 break;
820 opt = opt->next;
822 if (not_added) {
823 new_opt = talloc(mem_ctx, struct parmlist_entry);
824 if (new_opt == NULL) {
825 smb_panic("OOM");
828 new_opt->key = talloc_strdup(new_opt, opt_name);
829 if (new_opt->key == NULL) {
830 smb_panic("talloc_strdup failed");
833 new_opt->value = talloc_strdup(new_opt, opt_value);
834 if (new_opt->value == NULL) {
835 smb_panic("talloc_strdup failed");
838 new_opt->list = NULL;
839 new_opt->priority = priority;
840 DLIST_ADD(*opt_list, new_opt);
845 * Copy a service structure to another.
846 * If pcopymapDest is NULL then copy all fields
849 void copy_service(struct loadparm_service *pserviceDest,
850 const struct loadparm_service *pserviceSource,
851 struct bitmap *pcopymapDest)
853 int i;
854 bool bcopyall = (pcopymapDest == NULL);
855 struct parmlist_entry *data;
857 for (i = 0; parm_table[i].label; i++)
858 if (parm_table[i].p_class == P_LOCAL &&
859 (bcopyall || bitmap_query(pcopymapDest, i))) {
860 const void *src_ptr =
861 ((const char *)pserviceSource) + parm_table[i].offset;
862 void *dest_ptr =
863 ((char *)pserviceDest) + parm_table[i].offset;
865 switch (parm_table[i].type) {
866 case P_BOOL:
867 case P_BOOLREV:
868 *(bool *)dest_ptr = *(const bool *)src_ptr;
869 break;
871 case P_INTEGER:
872 case P_BYTES:
873 case P_OCTAL:
874 case P_ENUM:
875 *(int *)dest_ptr = *(const int *)src_ptr;
876 break;
878 case P_CHAR:
879 *(char *)dest_ptr = *(const char *)src_ptr;
880 break;
882 case P_STRING:
883 lpcfg_string_set(pserviceDest,
884 (char **)dest_ptr,
885 *(const char * const *)src_ptr);
886 break;
888 case P_USTRING:
889 lpcfg_string_set_upper(pserviceDest,
890 (char **)dest_ptr,
891 *(const char * const *)src_ptr);
892 break;
893 case P_CMDLIST:
894 case P_LIST:
895 TALLOC_FREE(*((char ***)dest_ptr));
896 *(const char * const **)dest_ptr = (const char * const *)str_list_copy(pserviceDest,
897 *(const char * * const *)src_ptr);
898 break;
899 default:
900 break;
904 if (bcopyall) {
905 init_copymap(pserviceDest);
906 if (pserviceSource->copymap)
907 bitmap_copy(pserviceDest->copymap,
908 pserviceSource->copymap);
911 for (data = pserviceSource->param_opt; data != NULL; data = data->next) {
912 set_param_opt(pserviceDest, &pserviceDest->param_opt,
913 data->key, data->value, data->priority);
918 * Check a service for consistency. Return False if the service is in any way
919 * incomplete or faulty, else True.
921 static bool lpcfg_service_ok(struct loadparm_service *service)
923 bool bRetval;
925 bRetval = true;
926 if (service->szService[0] == '\0') {
927 DEBUG(0, ("The following message indicates an internal error:\n"));
928 DEBUG(0, ("No service name in service entry.\n"));
929 bRetval = false;
932 /* The [printers] entry MUST be printable. I'm all for flexibility, but */
933 /* I can't see why you'd want a non-printable printer service... */
934 if (strwicmp(service->szService, PRINTERS_NAME) == 0) {
935 if (!service->printable) {
936 DEBUG(0, ("WARNING: [%s] service MUST be printable!\n",
937 service->szService));
938 service->printable = true;
940 /* [printers] service must also be non-browsable. */
941 if (service->browseable)
942 service->browseable = false;
945 /* If a service is flagged unavailable, log the fact at level 0. */
946 if (!service->bAvailable)
947 DEBUG(1, ("NOTE: Service %s is flagged unavailable.\n",
948 service->szService));
950 return bRetval;
954 /*******************************************************************
955 Keep a linked list of all config files so we know when one has changed
956 it's date and needs to be reloaded.
957 ********************************************************************/
959 void add_to_file_list(TALLOC_CTX *mem_ctx, struct file_lists **list,
960 const char *fname, const char *subfname)
962 struct file_lists *f = *list;
964 while (f) {
965 if (f->name && !strcmp(f->name, fname))
966 break;
967 f = f->next;
970 if (!f) {
971 f = talloc(mem_ctx, struct file_lists);
972 if (!f)
973 goto fail;
974 f->next = *list;
975 f->name = talloc_strdup(f, fname);
976 if (!f->name) {
977 TALLOC_FREE(f);
978 goto fail;
980 f->subfname = talloc_strdup(f, subfname);
981 if (!f->subfname) {
982 TALLOC_FREE(f);
983 goto fail;
985 *list = f;
986 f->modtime = file_modtime(subfname);
987 } else {
988 time_t t = file_modtime(subfname);
989 if (t)
990 f->modtime = t;
992 return;
994 fail:
995 DEBUG(0, ("Unable to add file to file list: %s\n", fname));
999 /*******************************************************************
1000 Check if a config file has changed date.
1001 ********************************************************************/
1002 bool lpcfg_file_list_changed(struct loadparm_context *lp_ctx)
1004 struct file_lists *f;
1005 DEBUG(6, ("lpcfg_file_list_changed()\n"));
1007 for (f = lp_ctx->file_lists; f != NULL; f = f->next) {
1008 char *n2;
1009 time_t mod_time;
1011 n2 = standard_sub_basic(lp_ctx, f->name);
1013 DEBUGADD(6, ("file %s -> %s last mod_time: %s\n",
1014 f->name, n2, ctime(&f->modtime)));
1016 mod_time = file_modtime(n2);
1018 if (mod_time && ((f->modtime != mod_time) || (f->subfname == NULL) || (strcmp(n2, f->subfname) != 0))) {
1019 DEBUGADD(6, ("file %s modified: %s\n", n2,
1020 ctime(&mod_time)));
1021 f->modtime = mod_time;
1022 talloc_free(f->subfname);
1023 f->subfname = talloc_strdup(f, n2);
1024 return true;
1027 return false;
1031 * set the value for a P_ENUM
1033 bool lp_set_enum_parm( struct parm_struct *parm, const char *pszParmValue,
1034 int *ptr )
1036 int i;
1038 for (i = 0; parm->enum_list[i].name; i++) {
1039 if ( strequal(pszParmValue, parm->enum_list[i].name)) {
1040 *ptr = parm->enum_list[i].value;
1041 return true;
1044 DEBUG(0, ("WARNING: Ignoring invalid value '%s' for parameter '%s'\n",
1045 pszParmValue, parm->label));
1046 return false;
1050 /***************************************************************************
1051 Handle the "realm" parameter
1052 ***************************************************************************/
1054 bool handle_realm(struct loadparm_context *lp_ctx, int unused,
1055 const char *pszParmValue, char **ptr)
1057 char *upper;
1058 char *lower;
1060 upper = strupper_talloc(lp_ctx, pszParmValue);
1061 if (upper == NULL) {
1062 return false;
1065 lower = strlower_talloc(lp_ctx, pszParmValue);
1066 if (lower == NULL) {
1067 TALLOC_FREE(upper);
1068 return false;
1071 if (lp_ctx->s3_fns != NULL) {
1072 lp_ctx->s3_fns->lp_string_set(ptr, pszParmValue);
1073 lp_ctx->s3_fns->lp_string_set(&lp_ctx->globals->realm, upper);
1074 lp_ctx->s3_fns->lp_string_set(&lp_ctx->globals->dnsdomain, lower);
1075 } else {
1076 lpcfg_string_set(lp_ctx, ptr, pszParmValue);
1077 lpcfg_string_set(lp_ctx, &lp_ctx->globals->realm, upper);
1078 lpcfg_string_set(lp_ctx, &lp_ctx->globals->dnsdomain, lower);
1081 return true;
1084 /***************************************************************************
1085 Handle the include operation.
1086 ***************************************************************************/
1088 bool handle_include(struct loadparm_context *lp_ctx, int unused,
1089 const char *pszParmValue, char **ptr)
1091 char *fname;
1093 if (lp_ctx->s3_fns) {
1094 return lp_ctx->s3_fns->lp_include(lp_ctx, unused, pszParmValue, ptr);
1097 fname = standard_sub_basic(lp_ctx, pszParmValue);
1099 add_to_file_list(lp_ctx, &lp_ctx->file_lists, pszParmValue, fname);
1101 lpcfg_string_set(lp_ctx, ptr, fname);
1103 if (file_exist(fname))
1104 return pm_process(fname, do_section, do_parameter, lp_ctx);
1106 DEBUG(2, ("Can't find include file %s\n", fname));
1108 return false;
1111 /***************************************************************************
1112 Handle the interpretation of the copy parameter.
1113 ***************************************************************************/
1115 bool handle_copy(struct loadparm_context *lp_ctx, int snum,
1116 const char *pszParmValue, char **ptr)
1118 bool bRetval;
1119 struct loadparm_service *serviceTemp = NULL;
1120 struct loadparm_service *current = NULL;
1122 bRetval = false;
1124 DEBUG(3, ("Copying service from service %s\n", pszParmValue));
1126 serviceTemp = lpcfg_getservicebyname(lp_ctx, pszParmValue);
1127 if (lp_ctx->s3_fns != NULL) {
1128 current = lp_ctx->s3_fns->get_servicebynum(snum);
1129 } else {
1130 current = lp_ctx->currentService;
1133 if (current == NULL) {
1134 DEBUG(0, ("Unable to copy service - invalid service destination"));
1135 return false;
1138 if (serviceTemp != NULL) {
1139 if (serviceTemp == current) {
1140 DEBUG(0, ("Can't copy service %s - unable to copy self!\n", pszParmValue));
1141 } else {
1142 copy_service(current,
1143 serviceTemp,
1144 current->copymap);
1145 lpcfg_string_set(current, ptr, pszParmValue);
1147 bRetval = true;
1149 } else {
1150 DEBUG(0, ("Unable to copy service - source not found: %s\n",
1151 pszParmValue));
1152 bRetval = false;
1155 return bRetval;
1158 bool handle_debug_list(struct loadparm_context *lp_ctx, int unused,
1159 const char *pszParmValue, char **ptr)
1161 if (lp_ctx->s3_fns != NULL) {
1162 lp_ctx->s3_fns->lp_string_set(ptr, pszParmValue);
1163 } else {
1164 lpcfg_string_set(lp_ctx, ptr, pszParmValue);
1167 return debug_parse_levels(pszParmValue);
1170 bool handle_logfile(struct loadparm_context *lp_ctx, int unused,
1171 const char *pszParmValue, char **ptr)
1173 if (lp_ctx->s3_fns != NULL) {
1174 lp_ctx->s3_fns->lp_string_set(ptr, pszParmValue);
1175 } else {
1176 debug_set_logfile(pszParmValue);
1177 lpcfg_string_set(lp_ctx, ptr, pszParmValue);
1180 return true;
1184 * These special charset handling methods only run in the source3 code.
1187 bool handle_charset(struct loadparm_context *lp_ctx, int snum,
1188 const char *pszParmValue, char **ptr)
1190 if (lp_ctx->s3_fns) {
1191 if (*ptr == NULL || strcmp(*ptr, pszParmValue) != 0) {
1192 lp_ctx->s3_fns->lp_string_set(ptr, pszParmValue);
1193 global_iconv_handle = smb_iconv_handle_reinit(NULL,
1194 lpcfg_dos_charset(lp_ctx),
1195 lpcfg_unix_charset(lp_ctx),
1196 true, global_iconv_handle);
1199 return true;
1201 return lpcfg_string_set(lp_ctx, ptr, pszParmValue);
1205 bool handle_dos_charset(struct loadparm_context *lp_ctx, int snum,
1206 const char *pszParmValue, char **ptr)
1208 bool is_utf8 = false;
1209 size_t len = strlen(pszParmValue);
1211 if (lp_ctx->s3_fns) {
1212 if (len == 4 || len == 5) {
1213 /* Don't use StrCaseCmp here as we don't want to
1214 initialize iconv. */
1215 if ((toupper_m(pszParmValue[0]) == 'U') &&
1216 (toupper_m(pszParmValue[1]) == 'T') &&
1217 (toupper_m(pszParmValue[2]) == 'F')) {
1218 if (len == 4) {
1219 if (pszParmValue[3] == '8') {
1220 is_utf8 = true;
1222 } else {
1223 if (pszParmValue[3] == '-' &&
1224 pszParmValue[4] == '8') {
1225 is_utf8 = true;
1231 if (*ptr == NULL || strcmp(*ptr, pszParmValue) != 0) {
1232 if (is_utf8) {
1233 DEBUG(0,("ERROR: invalid DOS charset: 'dos charset' must not "
1234 "be UTF8, using (default value) %s instead.\n",
1235 DEFAULT_DOS_CHARSET));
1236 pszParmValue = DEFAULT_DOS_CHARSET;
1238 lp_ctx->s3_fns->lp_string_set(ptr, pszParmValue);
1239 global_iconv_handle = smb_iconv_handle_reinit(NULL,
1240 lpcfg_dos_charset(lp_ctx),
1241 lpcfg_unix_charset(lp_ctx),
1242 true, global_iconv_handle);
1244 return true;
1247 return lpcfg_string_set(lp_ctx, ptr, pszParmValue);
1250 bool handle_printing(struct loadparm_context *lp_ctx, int snum,
1251 const char *pszParmValue, char **ptr)
1253 static int parm_num = -1;
1254 struct loadparm_service *s;
1256 if (parm_num == -1) {
1257 parm_num = lpcfg_map_parameter("printing");
1260 if (!lp_set_enum_parm(&parm_table[parm_num], pszParmValue, (int*)ptr)) {
1261 return false;
1264 if (lp_ctx->s3_fns) {
1265 if ( snum < 0 ) {
1266 s = lp_ctx->sDefault;
1267 lp_ctx->s3_fns->init_printer_values(lp_ctx->globals->ctx, s);
1268 } else {
1269 s = lp_ctx->services[snum];
1270 lp_ctx->s3_fns->init_printer_values(s, s);
1274 return true;
1277 bool handle_ldap_debug_level(struct loadparm_context *lp_ctx, int snum, const char *pszParmValue, char **ptr)
1279 lp_ctx->globals->ldap_debug_level = lp_int(pszParmValue);
1281 if (lp_ctx->s3_fns) {
1282 lp_ctx->s3_fns->init_ldap_debugging();
1284 return true;
1287 bool handle_netbios_aliases(struct loadparm_context *lp_ctx, int snum, const char *pszParmValue, char **ptr)
1289 TALLOC_FREE(lp_ctx->globals->netbios_aliases);
1290 lp_ctx->globals->netbios_aliases = (const char **)str_list_make_v3(lp_ctx->globals->ctx,
1291 pszParmValue, NULL);
1293 if (lp_ctx->s3_fns) {
1294 return lp_ctx->s3_fns->set_netbios_aliases(lp_ctx->globals->netbios_aliases);
1296 return true;
1300 * idmap related parameters
1303 bool handle_idmap_backend(struct loadparm_context *lp_ctx, int snum, const char *pszParmValue, char **ptr)
1305 if (lp_ctx->s3_fns) {
1306 return lp_ctx->s3_fns->lp_do_parameter(snum, "idmap config * : backend", pszParmValue);
1309 return lpcfg_string_set(lp_ctx, ptr, pszParmValue);
1312 bool handle_idmap_uid(struct loadparm_context *lp_ctx, int snum, const char *pszParmValue, char **ptr)
1314 if (lp_ctx->s3_fns) {
1315 return lp_ctx->s3_fns->lp_do_parameter(snum, "idmap config * : range", pszParmValue);
1318 return lpcfg_string_set(lp_ctx, ptr, pszParmValue);
1321 bool handle_idmap_gid(struct loadparm_context *lp_ctx, int snum, const char *pszParmValue, char **ptr)
1323 if (lp_ctx->s3_fns) {
1324 return lp_ctx->s3_fns->lp_do_parameter(snum, "idmap config * : range", pszParmValue);
1327 return lpcfg_string_set(lp_ctx, ptr, pszParmValue);
1330 /***************************************************************************
1331 Initialise a copymap.
1332 ***************************************************************************/
1334 void init_copymap(struct loadparm_service *pservice)
1336 int i;
1338 TALLOC_FREE(pservice->copymap);
1340 pservice->copymap = bitmap_talloc(NULL, NUMPARAMETERS);
1341 if (!pservice->copymap)
1342 DEBUG(0,
1343 ("Couldn't allocate copymap!! (size %d)\n",
1344 (int)NUMPARAMETERS));
1345 else
1346 for (i = 0; i < NUMPARAMETERS; i++)
1347 bitmap_set(pservice->copymap, i);
1351 * Process a parametric option
1353 static bool lp_do_parameter_parametric(struct loadparm_context *lp_ctx,
1354 struct loadparm_service *service,
1355 const char *pszParmName,
1356 const char *pszParmValue, int flags)
1358 struct parmlist_entry **data;
1359 char *name;
1360 TALLOC_CTX *mem_ctx;
1362 while (isspace((unsigned char)*pszParmName)) {
1363 pszParmName++;
1366 name = strlower_talloc(lp_ctx, pszParmName);
1367 if (!name) return false;
1369 if (service == NULL) {
1370 data = &lp_ctx->globals->param_opt;
1371 mem_ctx = lp_ctx->globals;
1372 } else {
1373 data = &service->param_opt;
1374 mem_ctx = service;
1377 set_param_opt(mem_ctx, data, name, pszParmValue, flags);
1379 talloc_free(name);
1381 return true;
1384 static bool set_variable(TALLOC_CTX *mem_ctx, int parmnum, void *parm_ptr,
1385 const char *pszParmName, const char *pszParmValue,
1386 struct loadparm_context *lp_ctx, bool on_globals)
1388 int i;
1389 /* if it is a special case then go ahead */
1390 if (parm_table[parmnum].special) {
1391 bool ret;
1392 ret = parm_table[parmnum].special(lp_ctx, -1, pszParmValue,
1393 (char **)parm_ptr);
1394 if (!ret) {
1395 return false;
1397 goto mark_non_default;
1400 /* now switch on the type of variable it is */
1401 switch (parm_table[parmnum].type)
1403 case P_BOOL: {
1404 bool b;
1405 if (!set_boolean(pszParmValue, &b)) {
1406 DEBUG(0, ("set_variable(%s): value is not "
1407 "boolean!\n", pszParmValue));
1408 return false;
1410 *(bool *)parm_ptr = b;
1412 break;
1414 case P_BOOLREV: {
1415 bool b;
1416 if (!set_boolean(pszParmValue, &b)) {
1417 DEBUG(0, ("set_variable(%s): value is not "
1418 "boolean!\n", pszParmValue));
1419 return false;
1421 *(bool *)parm_ptr = !b;
1423 break;
1425 case P_INTEGER:
1426 *(int *)parm_ptr = atoi(pszParmValue);
1427 break;
1429 case P_CHAR:
1430 *(char *)parm_ptr = *pszParmValue;
1431 break;
1433 case P_OCTAL:
1434 *(int *)parm_ptr = strtol(pszParmValue, NULL, 8);
1435 break;
1437 case P_BYTES:
1439 uint64_t val;
1440 if (conv_str_size_error(pszParmValue, &val)) {
1441 if (val <= INT_MAX) {
1442 *(int *)parm_ptr = (int)val;
1443 break;
1447 DEBUG(0, ("set_variable(%s): value is not "
1448 "a valid size specifier!\n", pszParmValue));
1449 return false;
1452 case P_CMDLIST:
1453 *(const char * const **)parm_ptr
1454 = (const char * const *)str_list_make(mem_ctx,
1455 pszParmValue, NULL);
1456 break;
1457 case P_LIST:
1459 char **new_list = str_list_make(mem_ctx,
1460 pszParmValue, NULL);
1461 for (i=0; new_list[i]; i++) {
1462 if (*(const char ***)parm_ptr != NULL &&
1463 new_list[i][0] == '+' &&
1464 new_list[i][1])
1466 if (!str_list_check(*(const char ***)parm_ptr,
1467 &new_list[i][1])) {
1468 *(const char ***)parm_ptr = str_list_add(*(const char ***)parm_ptr,
1469 &new_list[i][1]);
1471 } else if (*(const char ***)parm_ptr != NULL &&
1472 new_list[i][0] == '-' &&
1473 new_list[i][1])
1475 str_list_remove(*(const char ***)parm_ptr,
1476 &new_list[i][1]);
1477 } else {
1478 if (i != 0) {
1479 DEBUG(0, ("Unsupported list syntax for: %s = %s\n",
1480 pszParmName, pszParmValue));
1481 return false;
1483 *(const char * const **)parm_ptr = (const char * const *) new_list;
1484 break;
1487 break;
1489 case P_STRING:
1490 lpcfg_string_set(mem_ctx, (char **)parm_ptr, pszParmValue);
1491 break;
1493 case P_USTRING:
1494 lpcfg_string_set_upper(mem_ctx, (char **)parm_ptr, pszParmValue);
1495 break;
1497 case P_ENUM:
1498 if (!lp_set_enum_parm(&parm_table[parmnum], pszParmValue, (int*)parm_ptr)) {
1499 return false;
1501 break;
1503 case P_SEP:
1504 break;
1507 mark_non_default:
1508 if (on_globals && (lp_ctx->flags[parmnum] & FLAG_DEFAULT)) {
1509 lp_ctx->flags[parmnum] &= ~FLAG_DEFAULT;
1510 /* we have to also unset FLAG_DEFAULT on aliases */
1511 for (i=parmnum-1;i>=0 && parm_table[i].offset == parm_table[parmnum].offset;i--) {
1512 lp_ctx->flags[i] &= ~FLAG_DEFAULT;
1514 for (i=parmnum+1;i<NUMPARAMETERS && parm_table[i].offset == parm_table[parmnum].offset;i++) {
1515 lp_ctx->flags[i] &= ~FLAG_DEFAULT;
1518 return true;
1522 bool lpcfg_do_global_parameter(struct loadparm_context *lp_ctx,
1523 const char *pszParmName, const char *pszParmValue)
1525 int parmnum = lpcfg_map_parameter(pszParmName);
1526 void *parm_ptr;
1528 if (parmnum < 0) {
1529 if (strchr(pszParmName, ':')) {
1530 return lp_do_parameter_parametric(lp_ctx, NULL, pszParmName, pszParmValue, 0);
1532 DEBUG(0, ("Ignoring unknown parameter \"%s\"\n", pszParmName));
1533 return true;
1536 /* if the flag has been set on the command line, then don't allow override,
1537 but don't report an error */
1538 if (lp_ctx->flags[parmnum] & FLAG_CMDLINE) {
1539 return true;
1542 parm_ptr = lpcfg_parm_ptr(lp_ctx, NULL, &parm_table[parmnum]);
1544 return set_variable(lp_ctx->globals, parmnum, parm_ptr,
1545 pszParmName, pszParmValue, lp_ctx, true);
1548 bool lpcfg_do_service_parameter(struct loadparm_context *lp_ctx,
1549 struct loadparm_service *service,
1550 const char *pszParmName, const char *pszParmValue)
1552 void *parm_ptr;
1553 int i;
1554 int parmnum = lpcfg_map_parameter(pszParmName);
1556 if (parmnum < 0) {
1557 if (strchr(pszParmName, ':')) {
1558 return lp_do_parameter_parametric(lp_ctx, service, pszParmName, pszParmValue, 0);
1560 DEBUG(0, ("Ignoring unknown parameter \"%s\"\n", pszParmName));
1561 return true;
1564 /* if the flag has been set on the command line, then don't allow override,
1565 but don't report an error */
1566 if (lp_ctx->flags[parmnum] & FLAG_CMDLINE) {
1567 return true;
1570 if (parm_table[parmnum].p_class == P_GLOBAL) {
1571 DEBUG(0,
1572 ("Global parameter %s found in service section!\n",
1573 pszParmName));
1574 return true;
1576 parm_ptr = ((char *)service) + parm_table[parmnum].offset;
1578 if (!service->copymap)
1579 init_copymap(service);
1581 /* this handles the aliases - set the copymap for other
1582 * entries with the same data pointer */
1583 for (i = 0; parm_table[i].label; i++)
1584 if (parm_table[i].offset == parm_table[parmnum].offset &&
1585 parm_table[i].p_class == parm_table[parmnum].p_class)
1586 bitmap_clear(service->copymap, i);
1588 return set_variable(service, parmnum, parm_ptr, pszParmName,
1589 pszParmValue, lp_ctx, false);
1593 * Process a parameter.
1596 static bool do_parameter(const char *pszParmName, const char *pszParmValue,
1597 void *userdata)
1599 struct loadparm_context *lp_ctx = (struct loadparm_context *)userdata;
1601 if (lp_ctx->bInGlobalSection)
1602 return lpcfg_do_global_parameter(lp_ctx, pszParmName,
1603 pszParmValue);
1604 else
1605 return lpcfg_do_service_parameter(lp_ctx, lp_ctx->currentService,
1606 pszParmName, pszParmValue);
1610 variable argument do parameter
1612 bool lpcfg_do_global_parameter_var(struct loadparm_context *lp_ctx, const char *pszParmName, const char *fmt, ...) PRINTF_ATTRIBUTE(3, 4);
1613 bool lpcfg_do_global_parameter_var(struct loadparm_context *lp_ctx,
1614 const char *pszParmName, const char *fmt, ...)
1616 char *s;
1617 bool ret;
1618 va_list ap;
1620 va_start(ap, fmt);
1621 s = talloc_vasprintf(NULL, fmt, ap);
1622 va_end(ap);
1623 ret = lpcfg_do_global_parameter(lp_ctx, pszParmName, s);
1624 talloc_free(s);
1625 return ret;
1630 set a parameter from the commandline - this is called from command line parameter
1631 parsing code. It sets the parameter then marks the parameter as unable to be modified
1632 by smb.conf processing
1634 bool lpcfg_set_cmdline(struct loadparm_context *lp_ctx, const char *pszParmName,
1635 const char *pszParmValue)
1637 int parmnum;
1638 int i;
1640 while (isspace((unsigned char)*pszParmValue)) pszParmValue++;
1642 if (lp_ctx->s3_fns) {
1643 return lp_ctx->s3_fns->set_cmdline(pszParmName, pszParmValue);
1646 parmnum = lpcfg_map_parameter(pszParmName);
1648 if (parmnum < 0 && strchr(pszParmName, ':')) {
1649 /* set a parametric option */
1650 return lp_do_parameter_parametric(lp_ctx, NULL, pszParmName,
1651 pszParmValue, FLAG_CMDLINE);
1654 if (parmnum < 0) {
1655 DEBUG(0,("Unknown option '%s'\n", pszParmName));
1656 return false;
1659 /* reset the CMDLINE flag in case this has been called before */
1660 lp_ctx->flags[parmnum] &= ~FLAG_CMDLINE;
1662 if (!lpcfg_do_global_parameter(lp_ctx, pszParmName, pszParmValue)) {
1663 return false;
1666 lp_ctx->flags[parmnum] |= FLAG_CMDLINE;
1668 /* we have to also set FLAG_CMDLINE on aliases */
1669 for (i=parmnum-1;
1670 i>=0 && parm_table[i].p_class == parm_table[parmnum].p_class &&
1671 parm_table[i].offset == parm_table[parmnum].offset;
1672 i--) {
1673 lp_ctx->flags[i] |= FLAG_CMDLINE;
1675 for (i=parmnum+1;
1676 i<NUMPARAMETERS &&
1677 parm_table[i].p_class == parm_table[parmnum].p_class &&
1678 parm_table[i].offset == parm_table[parmnum].offset;
1679 i++) {
1680 lp_ctx->flags[i] |= FLAG_CMDLINE;
1683 return true;
1687 set a option from the commandline in 'a=b' format. Use to support --option
1689 bool lpcfg_set_option(struct loadparm_context *lp_ctx, const char *option)
1691 char *p, *s;
1692 bool ret;
1694 s = talloc_strdup(NULL, option);
1695 if (!s) {
1696 return false;
1699 p = strchr(s, '=');
1700 if (!p) {
1701 talloc_free(s);
1702 return false;
1705 *p = 0;
1707 ret = lpcfg_set_cmdline(lp_ctx, s, p+1);
1708 talloc_free(s);
1709 return ret;
1713 #define BOOLSTR(b) ((b) ? "Yes" : "No")
1716 * Print a parameter of the specified type.
1719 void lpcfg_print_parameter(struct parm_struct *p, void *ptr, FILE * f)
1721 /* For the seperation of lists values that we print below */
1722 const char *list_sep = ", ";
1723 int i;
1724 switch (p->type)
1726 case P_ENUM:
1727 for (i = 0; p->enum_list[i].name; i++) {
1728 if (*(int *)ptr == p->enum_list[i].value) {
1729 fprintf(f, "%s",
1730 p->enum_list[i].name);
1731 break;
1734 break;
1736 case P_BOOL:
1737 fprintf(f, "%s", BOOLSTR(*(bool *)ptr));
1738 break;
1740 case P_BOOLREV:
1741 fprintf(f, "%s", BOOLSTR(!*(bool *)ptr));
1742 break;
1744 case P_INTEGER:
1745 case P_BYTES:
1746 fprintf(f, "%d", *(int *)ptr);
1747 break;
1749 case P_CHAR:
1750 fprintf(f, "%c", *(char *)ptr);
1751 break;
1753 case P_OCTAL: {
1754 int val = *(int *)ptr;
1755 if (val == -1) {
1756 fprintf(f, "-1");
1757 } else {
1758 fprintf(f, "0%03o", val);
1760 break;
1763 case P_CMDLIST:
1764 list_sep = " ";
1765 /* fall through */
1766 case P_LIST:
1767 if ((char ***)ptr && *(char ***)ptr) {
1768 char **list = *(char ***)ptr;
1769 for (; *list; list++) {
1770 /* surround strings with whitespace in double quotes */
1771 if (*(list+1) == NULL) {
1772 /* last item, no extra separator */
1773 list_sep = "";
1775 if ( strchr_m( *list, ' ' ) ) {
1776 fprintf(f, "\"%s\"%s", *list, list_sep);
1777 } else {
1778 fprintf(f, "%s%s", *list, list_sep);
1782 break;
1784 case P_STRING:
1785 case P_USTRING:
1786 if (*(char **)ptr) {
1787 fprintf(f, "%s", *(char **)ptr);
1789 break;
1790 case P_SEP:
1791 break;
1796 * Check if two parameters are equal.
1799 bool lpcfg_equal_parameter(parm_type type, void *ptr1, void *ptr2)
1801 switch (type) {
1802 case P_BOOL:
1803 case P_BOOLREV:
1804 return (*((bool *)ptr1) == *((bool *)ptr2));
1806 case P_INTEGER:
1807 case P_ENUM:
1808 case P_OCTAL:
1809 case P_BYTES:
1810 return (*((int *)ptr1) == *((int *)ptr2));
1812 case P_CHAR:
1813 return (*((char *)ptr1) == *((char *)ptr2));
1815 case P_LIST:
1816 case P_CMDLIST:
1817 return str_list_equal(*(const char ***)ptr1, *(const char ***)ptr2);
1819 case P_STRING:
1820 case P_USTRING:
1822 char *p1 = *(char **)ptr1, *p2 = *(char **)ptr2;
1823 if (p1 && !*p1)
1824 p1 = NULL;
1825 if (p2 && !*p2)
1826 p2 = NULL;
1827 return (p1 == p2 || strequal(p1, p2));
1829 case P_SEP:
1830 break;
1832 return false;
1836 * Process a new section (service).
1838 * At this stage all sections are services.
1839 * Later we'll have special sections that permit server parameters to be set.
1840 * Returns True on success, False on failure.
1843 static bool do_section(const char *pszSectionName, void *userdata)
1845 struct loadparm_context *lp_ctx = (struct loadparm_context *)userdata;
1846 bool bRetval;
1847 bool isglobal = ((strwicmp(pszSectionName, GLOBAL_NAME) == 0) ||
1848 (strwicmp(pszSectionName, GLOBAL_NAME2) == 0));
1849 bRetval = false;
1851 /* if we've just struck a global section, note the fact. */
1852 lp_ctx->bInGlobalSection = isglobal;
1854 /* check for multiple global sections */
1855 if (lp_ctx->bInGlobalSection) {
1856 DEBUG(4, ("Processing section \"[%s]\"\n", pszSectionName));
1857 return true;
1860 /* if we have a current service, tidy it up before moving on */
1861 bRetval = true;
1863 if (lp_ctx->currentService != NULL)
1864 bRetval = lpcfg_service_ok(lp_ctx->currentService);
1866 /* if all is still well, move to the next record in the services array */
1867 if (bRetval) {
1868 /* We put this here to avoid an odd message order if messages are */
1869 /* issued by the post-processing of a previous section. */
1870 DEBUG(4, ("Processing section \"[%s]\"\n", pszSectionName));
1872 if ((lp_ctx->currentService = lpcfg_add_service(lp_ctx, lp_ctx->sDefault,
1873 pszSectionName))
1874 == NULL) {
1875 DEBUG(0, ("Failed to add a new service\n"));
1876 return false;
1880 return bRetval;
1885 * Determine if a particular base parameter is currently set to the default value.
1888 static bool is_default(struct loadparm_service *sDefault, int i)
1890 void *def_ptr = ((char *)sDefault) + parm_table[i].offset;
1891 switch (parm_table[i].type) {
1892 case P_CMDLIST:
1893 case P_LIST:
1894 return str_list_equal((const char * const *)parm_table[i].def.lvalue,
1895 *(const char ***)def_ptr);
1896 case P_STRING:
1897 case P_USTRING:
1898 return strequal(parm_table[i].def.svalue,
1899 *(char **)def_ptr);
1900 case P_BOOL:
1901 case P_BOOLREV:
1902 return parm_table[i].def.bvalue ==
1903 *(bool *)def_ptr;
1904 case P_INTEGER:
1905 case P_CHAR:
1906 case P_OCTAL:
1907 case P_BYTES:
1908 case P_ENUM:
1909 return parm_table[i].def.ivalue ==
1910 *(int *)def_ptr;
1911 case P_SEP:
1912 break;
1914 return false;
1918 *Display the contents of the global structure.
1921 static void dump_globals(struct loadparm_context *lp_ctx, FILE *f,
1922 bool show_defaults)
1924 int i;
1925 struct parmlist_entry *data;
1927 fprintf(f, "# Global parameters\n[global]\n");
1929 for (i = 0; parm_table[i].label; i++)
1930 if (parm_table[i].p_class == P_GLOBAL &&
1931 (i == 0 || (parm_table[i].offset != parm_table[i - 1].offset))) {
1932 if (!show_defaults && (lp_ctx->flags[i] & FLAG_DEFAULT))
1933 continue;
1934 fprintf(f, "\t%s = ", parm_table[i].label);
1935 lpcfg_print_parameter(&parm_table[i], lpcfg_parm_ptr(lp_ctx, NULL, &parm_table[i]), f);
1936 fprintf(f, "\n");
1938 if (lp_ctx->globals->param_opt != NULL) {
1939 for (data = lp_ctx->globals->param_opt; data;
1940 data = data->next) {
1941 if (!show_defaults && (data->priority & FLAG_DEFAULT)) {
1942 continue;
1944 fprintf(f, "\t%s = %s\n", data->key, data->value);
1951 * Display the contents of a single services record.
1954 static void dump_a_service(struct loadparm_service * pService, struct loadparm_service *sDefault, FILE * f,
1955 unsigned int *flags)
1957 int i;
1958 struct parmlist_entry *data;
1960 if (pService != sDefault)
1961 fprintf(f, "\n[%s]\n", pService->szService);
1963 for (i = 0; parm_table[i].label; i++) {
1964 if (parm_table[i].p_class == P_LOCAL &&
1965 (*parm_table[i].label != '-') &&
1966 (i == 0 || (parm_table[i].offset != parm_table[i - 1].offset)))
1968 if (pService == sDefault) {
1969 if (flags && (flags[i] & FLAG_DEFAULT)) {
1970 continue;
1972 if (defaults_saved) {
1973 if (is_default(sDefault, i)) {
1974 continue;
1977 } else {
1978 if (lpcfg_equal_parameter(parm_table[i].type,
1979 ((char *)pService) +
1980 parm_table[i].offset,
1981 ((char *)sDefault) +
1982 parm_table[i].offset))
1983 continue;
1986 fprintf(f, "\t%s = ", parm_table[i].label);
1987 lpcfg_print_parameter(&parm_table[i],
1988 ((char *)pService) + parm_table[i].offset, f);
1989 fprintf(f, "\n");
1992 if (pService->param_opt != NULL) {
1993 for (data = pService->param_opt; data; data = data->next) {
1994 fprintf(f, "\t%s = %s\n", data->key, data->value);
1999 bool lpcfg_dump_a_parameter(struct loadparm_context *lp_ctx,
2000 struct loadparm_service *service,
2001 const char *parm_name, FILE * f)
2003 struct parm_struct *parm;
2004 void *ptr;
2005 char *local_parm_name;
2006 char *parm_opt;
2007 const char *parm_opt_value;
2009 /* check for parametrical option */
2010 local_parm_name = talloc_strdup(lp_ctx, parm_name);
2011 if (local_parm_name == NULL) {
2012 return false;
2015 parm_opt = strchr( local_parm_name, ':');
2017 if (parm_opt) {
2018 *parm_opt = '\0';
2019 parm_opt++;
2020 if (strlen(parm_opt)) {
2021 parm_opt_value = lpcfg_parm_string(lp_ctx, service,
2022 local_parm_name, parm_opt);
2023 if (parm_opt_value) {
2024 fprintf(f, "%s\n", parm_opt_value);
2025 return true;
2028 return false;
2031 /* parameter is not parametric, search the table */
2032 parm = lpcfg_parm_struct(lp_ctx, parm_name);
2033 if (!parm) {
2034 return false;
2037 if (service != NULL && parm->p_class == P_GLOBAL) {
2038 return false;
2041 ptr = lpcfg_parm_ptr(lp_ctx, service,parm);
2043 lpcfg_print_parameter(parm, ptr, f);
2044 fprintf(f, "\n");
2045 return true;
2049 * Auto-load some home services.
2051 static void lpcfg_add_auto_services(struct loadparm_context *lp_ctx,
2052 const char *str)
2054 return;
2059 * Unload unused services.
2062 void lpcfg_killunused(struct loadparm_context *lp_ctx,
2063 struct smbsrv_connection *smb,
2064 bool (*snumused) (struct smbsrv_connection *, int))
2066 int i;
2067 for (i = 0; i < lp_ctx->iNumServices; i++) {
2068 if (lp_ctx->services[i] == NULL)
2069 continue;
2071 if (!snumused || !snumused(smb, i)) {
2072 talloc_free(lp_ctx->services[i]);
2073 lp_ctx->services[i] = NULL;
2079 static int lpcfg_destructor(struct loadparm_context *lp_ctx)
2081 struct parmlist_entry *data;
2083 if (lp_ctx->refuse_free) {
2084 /* someone is trying to free the
2085 global_loadparm_context.
2086 We can't allow that. */
2087 return -1;
2090 if (lp_ctx->globals->param_opt != NULL) {
2091 struct parmlist_entry *next;
2092 for (data = lp_ctx->globals->param_opt; data; data=next) {
2093 next = data->next;
2094 if (data->priority & FLAG_CMDLINE) continue;
2095 DLIST_REMOVE(lp_ctx->globals->param_opt, data);
2096 talloc_free(data);
2100 return 0;
2104 * Initialise the global parameter structure.
2106 * Note that most callers should use loadparm_init_global() instead
2108 struct loadparm_context *loadparm_init(TALLOC_CTX *mem_ctx)
2110 int i;
2111 char *myname;
2112 struct loadparm_context *lp_ctx;
2113 struct parmlist_entry *parm;
2114 char *logfile;
2116 lp_ctx = talloc_zero(mem_ctx, struct loadparm_context);
2117 if (lp_ctx == NULL)
2118 return NULL;
2120 talloc_set_destructor(lp_ctx, lpcfg_destructor);
2121 lp_ctx->bInGlobalSection = true;
2122 lp_ctx->globals = talloc_zero(lp_ctx, struct loadparm_global);
2123 /* This appears odd, but globals in s3 isn't a pointer */
2124 lp_ctx->globals->ctx = lp_ctx->globals;
2125 lp_ctx->sDefault = talloc_zero(lp_ctx, struct loadparm_service);
2126 lp_ctx->flags = talloc_zero_array(lp_ctx, unsigned int, NUMPARAMETERS);
2128 lp_ctx->sDefault->iMaxPrintJobs = 1000;
2129 lp_ctx->sDefault->bAvailable = true;
2130 lp_ctx->sDefault->browseable = true;
2131 lp_ctx->sDefault->read_only = true;
2132 lp_ctx->sDefault->map_archive = true;
2133 lp_ctx->sDefault->strict_locking = true;
2134 lp_ctx->sDefault->oplocks = true;
2135 lp_ctx->sDefault->create_mask = 0744;
2136 lp_ctx->sDefault->force_create_mode = 0000;
2137 lp_ctx->sDefault->directory_mask = 0755;
2138 lp_ctx->sDefault->force_directory_mode = 0000;
2140 DEBUG(3, ("Initialising global parameters\n"));
2142 for (i = 0; parm_table[i].label; i++) {
2143 if ((parm_table[i].type == P_STRING ||
2144 parm_table[i].type == P_USTRING) &&
2145 !(lp_ctx->flags[i] & FLAG_CMDLINE)) {
2146 char **r;
2147 if (parm_table[i].p_class == P_LOCAL) {
2148 r = (char **)(((char *)lp_ctx->sDefault) + parm_table[i].offset);
2149 } else {
2150 r = (char **)(((char *)lp_ctx->globals) + parm_table[i].offset);
2152 *r = talloc_strdup(lp_ctx, "");
2156 logfile = talloc_asprintf(lp_ctx, "%s/log.samba", dyn_LOGFILEBASE);
2157 lpcfg_do_global_parameter(lp_ctx, "log file", logfile);
2158 talloc_free(logfile);
2160 lpcfg_do_global_parameter(lp_ctx, "log level", "0");
2162 lpcfg_do_global_parameter(lp_ctx, "syslog", "1");
2163 lpcfg_do_global_parameter(lp_ctx, "syslog only", "No");
2164 lpcfg_do_global_parameter(lp_ctx, "debug timestamp", "Yes");
2165 lpcfg_do_global_parameter(lp_ctx, "debug prefix timestamp", "No");
2166 lpcfg_do_global_parameter(lp_ctx, "debug hires timestamp", "Yes");
2167 lpcfg_do_global_parameter(lp_ctx, "debug pid", "No");
2168 lpcfg_do_global_parameter(lp_ctx, "debug uid", "No");
2169 lpcfg_do_global_parameter(lp_ctx, "debug class", "No");
2171 lpcfg_do_global_parameter(lp_ctx, "share backend", "classic");
2173 lpcfg_do_global_parameter(lp_ctx, "server role", "auto");
2174 lpcfg_do_global_parameter(lp_ctx, "domain logons", "No");
2175 lpcfg_do_global_parameter(lp_ctx, "domain master", "Auto");
2177 /* options that can be set on the command line must be initialised via
2178 the slower lpcfg_do_global_parameter() to ensure that FLAG_CMDLINE is obeyed */
2179 #ifdef TCP_NODELAY
2180 lpcfg_do_global_parameter(lp_ctx, "socket options", "TCP_NODELAY");
2181 #endif
2182 lpcfg_do_global_parameter(lp_ctx, "workgroup", DEFAULT_WORKGROUP);
2183 myname = get_myname(lp_ctx);
2184 lpcfg_do_global_parameter(lp_ctx, "netbios name", myname);
2185 talloc_free(myname);
2186 lpcfg_do_global_parameter(lp_ctx, "name resolve order", "lmhosts wins host bcast");
2188 lpcfg_do_global_parameter(lp_ctx, "fstype", "NTFS");
2190 lpcfg_do_global_parameter(lp_ctx, "ntvfs handler", "unixuid default");
2191 lpcfg_do_global_parameter(lp_ctx, "max connections", "0");
2193 lpcfg_do_global_parameter(lp_ctx, "dcerpc endpoint servers", "epmapper wkssvc rpcecho samr netlogon lsarpc spoolss drsuapi dssetup unixinfo browser eventlog6 backupkey dnsserver");
2194 lpcfg_do_global_parameter(lp_ctx, "server services", "s3fs rpc nbt wrepl ldap cldap kdc drepl winbind ntp_signd kcc dnsupdate dns");
2195 lpcfg_do_global_parameter(lp_ctx, "kccsrv:samba_kcc", "true");
2196 /* the winbind method for domain controllers is for both RODC
2197 auth forwarding and for trusted domains */
2198 lpcfg_do_global_parameter(lp_ctx, "private dir", dyn_PRIVATE_DIR);
2199 lpcfg_do_global_parameter(lp_ctx, "registry:HKEY_LOCAL_MACHINE", "hklm.ldb");
2201 /* This hive should be dynamically generated by Samba using
2202 data from the sam, but for the moment leave it in a tdb to
2203 keep regedt32 from popping up an annoying dialog. */
2204 lpcfg_do_global_parameter(lp_ctx, "registry:HKEY_USERS", "hku.ldb");
2206 /* using UTF8 by default allows us to support all chars */
2207 lpcfg_do_global_parameter(lp_ctx, "unix charset", "UTF-8");
2209 /* Use codepage 850 as a default for the dos character set */
2210 lpcfg_do_global_parameter(lp_ctx, "dos charset", "CP850");
2213 * Allow the default PASSWD_CHAT to be overridden in local.h.
2215 lpcfg_do_global_parameter(lp_ctx, "passwd chat", DEFAULT_PASSWD_CHAT);
2217 lpcfg_do_global_parameter(lp_ctx, "pid directory", dyn_PIDDIR);
2218 lpcfg_do_global_parameter(lp_ctx, "lock dir", dyn_LOCKDIR);
2219 lpcfg_do_global_parameter(lp_ctx, "state directory", dyn_STATEDIR);
2220 lpcfg_do_global_parameter(lp_ctx, "cache directory", dyn_CACHEDIR);
2221 lpcfg_do_global_parameter(lp_ctx, "ncalrpc dir", dyn_NCALRPCDIR);
2223 lpcfg_do_global_parameter(lp_ctx, "nbt client socket address", "0.0.0.0");
2224 lpcfg_do_global_parameter_var(lp_ctx, "server string",
2225 "Samba %s", SAMBA_VERSION_STRING);
2227 lpcfg_do_global_parameter(lp_ctx, "password server", "*");
2229 lpcfg_do_global_parameter(lp_ctx, "max mux", "50");
2230 lpcfg_do_global_parameter(lp_ctx, "max xmit", "16644");
2231 lpcfg_do_global_parameter(lp_ctx, "host msdfs", "true");
2233 lpcfg_do_global_parameter(lp_ctx, "LargeReadwrite", "True");
2234 lpcfg_do_global_parameter(lp_ctx, "server min protocol", "LANMAN1");
2235 lpcfg_do_global_parameter(lp_ctx, "server max protocol", "SMB3");
2236 lpcfg_do_global_parameter(lp_ctx, "client min protocol", "CORE");
2237 lpcfg_do_global_parameter(lp_ctx, "client max protocol", "NT1");
2238 lpcfg_do_global_parameter(lp_ctx, "security", "AUTO");
2239 lpcfg_do_global_parameter(lp_ctx, "EncryptPasswords", "True");
2240 lpcfg_do_global_parameter(lp_ctx, "ReadRaw", "True");
2241 lpcfg_do_global_parameter(lp_ctx, "WriteRaw", "True");
2242 lpcfg_do_global_parameter(lp_ctx, "NullPasswords", "False");
2243 lpcfg_do_global_parameter(lp_ctx, "old password allowed period", "60");
2244 lpcfg_do_global_parameter(lp_ctx, "ObeyPamRestrictions", "False");
2246 lpcfg_do_global_parameter(lp_ctx, "TimeServer", "False");
2247 lpcfg_do_global_parameter(lp_ctx, "BindInterfacesOnly", "False");
2248 lpcfg_do_global_parameter(lp_ctx, "Unicode", "True");
2249 lpcfg_do_global_parameter(lp_ctx, "ClientLanManAuth", "False");
2250 lpcfg_do_global_parameter(lp_ctx, "ClientNTLMv2Auth", "True");
2251 lpcfg_do_global_parameter(lp_ctx, "LanmanAuth", "False");
2252 lpcfg_do_global_parameter(lp_ctx, "NTLMAuth", "True");
2253 lpcfg_do_global_parameter(lp_ctx, "client use spnego principal", "False");
2255 lpcfg_do_global_parameter(lp_ctx, "UnixExtensions", "True");
2257 lpcfg_do_global_parameter(lp_ctx, "PreferredMaster", "Auto");
2258 lpcfg_do_global_parameter(lp_ctx, "LocalMaster", "True");
2260 lpcfg_do_global_parameter(lp_ctx, "wins support", "False");
2261 lpcfg_do_global_parameter(lp_ctx, "dns proxy", "True");
2263 lpcfg_do_global_parameter(lp_ctx, "winbind separator", "\\");
2264 lpcfg_do_global_parameter(lp_ctx, "winbind sealed pipes", "True");
2265 lpcfg_do_global_parameter(lp_ctx, "require strong key", "True");
2266 lpcfg_do_global_parameter(lp_ctx, "winbindd socket directory", dyn_WINBINDD_SOCKET_DIR);
2267 lpcfg_do_global_parameter(lp_ctx, "winbindd privileged socket directory", dyn_WINBINDD_PRIVILEGED_SOCKET_DIR);
2268 lpcfg_do_global_parameter(lp_ctx, "ntp signd socket directory", dyn_NTP_SIGND_SOCKET_DIR);
2269 lpcfg_do_global_parameter_var(lp_ctx, "dns update command", "%s/samba_dnsupdate", dyn_SCRIPTSBINDIR);
2270 lpcfg_do_global_parameter_var(lp_ctx, "spn update command", "%s/samba_spnupdate", dyn_SCRIPTSBINDIR);
2271 lpcfg_do_global_parameter_var(lp_ctx, "samba kcc command",
2272 "%s/samba_kcc", dyn_SCRIPTSBINDIR);
2273 lpcfg_do_global_parameter(lp_ctx, "template shell", "/bin/false");
2274 lpcfg_do_global_parameter(lp_ctx, "template homedir", "/home/%WORKGROUP%/%ACCOUNTNAME%");
2276 lpcfg_do_global_parameter(lp_ctx, "client signing", "default");
2277 lpcfg_do_global_parameter(lp_ctx, "server signing", "default");
2279 lpcfg_do_global_parameter(lp_ctx, "use spnego", "True");
2281 lpcfg_do_global_parameter(lp_ctx, "use mmap", "True");
2283 lpcfg_do_global_parameter(lp_ctx, "smb ports", "445 139");
2284 lpcfg_do_global_parameter(lp_ctx, "nbt port", "137");
2285 lpcfg_do_global_parameter(lp_ctx, "dgram port", "138");
2286 lpcfg_do_global_parameter(lp_ctx, "cldap port", "389");
2287 lpcfg_do_global_parameter(lp_ctx, "krb5 port", "88");
2288 lpcfg_do_global_parameter(lp_ctx, "kpasswd port", "464");
2289 lpcfg_do_global_parameter(lp_ctx, "web port", "901");
2291 lpcfg_do_global_parameter(lp_ctx, "nt status support", "True");
2293 lpcfg_do_global_parameter(lp_ctx, "max wins ttl", "518400"); /* 6 days */
2294 lpcfg_do_global_parameter(lp_ctx, "min wins ttl", "21600");
2296 lpcfg_do_global_parameter(lp_ctx, "tls enabled", "True");
2297 lpcfg_do_global_parameter(lp_ctx, "tls keyfile", "tls/key.pem");
2298 lpcfg_do_global_parameter(lp_ctx, "tls certfile", "tls/cert.pem");
2299 lpcfg_do_global_parameter(lp_ctx, "tls cafile", "tls/ca.pem");
2300 lpcfg_do_global_parameter(lp_ctx, "prefork children:smb", "4");
2302 lpcfg_do_global_parameter(lp_ctx, "rndc command", "/usr/sbin/rndc");
2303 lpcfg_do_global_parameter(lp_ctx, "nsupdate command", "/usr/bin/nsupdate -g");
2305 lpcfg_do_global_parameter(lp_ctx, "allow dns updates", "secure only");
2306 lpcfg_do_global_parameter(lp_ctx, "dns forwarder", "");
2308 lpcfg_do_global_parameter(lp_ctx, "algorithmic rid base", "1000");
2310 lpcfg_do_global_parameter(lp_ctx, "enhanced browsing", "True");
2312 lpcfg_do_global_parameter(lp_ctx, "winbind nss info", "template");
2314 lpcfg_do_global_parameter(lp_ctx, "server schannel", "Auto");
2316 lpcfg_do_global_parameter(lp_ctx, "short preserve case", "True");
2318 lpcfg_do_global_parameter(lp_ctx, "max open files", "16384");
2320 lpcfg_do_global_parameter(lp_ctx, "cups connection timeout", "30");
2322 lpcfg_do_global_parameter(lp_ctx, "locking", "True");
2324 lpcfg_do_global_parameter(lp_ctx, "block size", "1024");
2326 lpcfg_do_global_parameter(lp_ctx, "client use spnego", "True");
2328 lpcfg_do_global_parameter(lp_ctx, "change notify", "True");
2330 lpcfg_do_global_parameter(lp_ctx, "name cache timeout", "660");
2332 lpcfg_do_global_parameter(lp_ctx, "defer sharing violations", "True");
2334 lpcfg_do_global_parameter(lp_ctx, "ldap replication sleep", "1000");
2336 lpcfg_do_global_parameter(lp_ctx, "idmap backend", "tdb");
2338 lpcfg_do_global_parameter(lp_ctx, "enable privileges", "True");
2340 lpcfg_do_global_parameter_var(lp_ctx, "smb2 max write", "%u", DEFAULT_SMB2_MAX_WRITE);
2342 lpcfg_do_global_parameter(lp_ctx, "passdb backend", "tdbsam");
2344 lpcfg_do_global_parameter(lp_ctx, "getwd cache", "True");
2346 lpcfg_do_global_parameter(lp_ctx, "winbind nested groups", "True");
2348 lpcfg_do_global_parameter(lp_ctx, "mangled names", "True");
2350 lpcfg_do_global_parameter_var(lp_ctx, "smb2 max credits", "%u", DEFAULT_SMB2_MAX_CREDITS);
2352 lpcfg_do_global_parameter(lp_ctx, "ldap ssl", "start tls");
2354 lpcfg_do_global_parameter(lp_ctx, "ldap deref", "auto");
2356 lpcfg_do_global_parameter(lp_ctx, "lm interval", "60");
2358 lpcfg_do_global_parameter(lp_ctx, "mangling method", "hash2");
2360 lpcfg_do_global_parameter(lp_ctx, "hide dot files", "True");
2362 lpcfg_do_global_parameter(lp_ctx, "browse list", "True");
2364 lpcfg_do_global_parameter(lp_ctx, "passwd chat timeout", "2");
2366 lpcfg_do_global_parameter(lp_ctx, "guest account", GUEST_ACCOUNT);
2368 lpcfg_do_global_parameter(lp_ctx, "client schannel", "auto");
2370 lpcfg_do_global_parameter(lp_ctx, "smb encrypt", "default");
2372 lpcfg_do_global_parameter(lp_ctx, "max log size", "5000");
2374 lpcfg_do_global_parameter(lp_ctx, "idmap negative cache time", "120");
2376 lpcfg_do_global_parameter(lp_ctx, "ldap follow referral", "auto");
2378 lpcfg_do_global_parameter(lp_ctx, "multicast dns register", "yes");
2380 lpcfg_do_global_parameter(lp_ctx, "winbind reconnect delay", "30");
2382 lpcfg_do_global_parameter(lp_ctx, "nt acl support", "yes");
2384 lpcfg_do_global_parameter(lp_ctx, "acl check permissions", "yes");
2386 lpcfg_do_global_parameter(lp_ctx, "keepalive", "300");
2388 lpcfg_do_global_parameter(lp_ctx, "winbind cache time", "300");
2390 lpcfg_do_global_parameter(lp_ctx, "level2 oplocks", "yes");
2392 lpcfg_do_global_parameter(lp_ctx, "show add printer wizard", "yes");
2394 lpcfg_do_global_parameter(lp_ctx, "allocation roundup size", "1048576");
2396 lpcfg_do_global_parameter(lp_ctx, "ldap page size", "1024");
2398 lpcfg_do_global_parameter(lp_ctx, "kernel share modes", "yes");
2400 lpcfg_do_global_parameter(lp_ctx, "strict locking", "Auto");
2402 lpcfg_do_global_parameter(lp_ctx, "map readonly", "yes");
2404 lpcfg_do_global_parameter(lp_ctx, "allow trusted domains", "yes");
2406 lpcfg_do_global_parameter(lp_ctx, "default devmode", "yes");
2408 lpcfg_do_global_parameter(lp_ctx, "os level", "20");
2410 lpcfg_do_global_parameter(lp_ctx, "dos filetimes", "yes");
2412 lpcfg_do_global_parameter(lp_ctx, "mangling char", "~");
2414 lpcfg_do_global_parameter(lp_ctx, "printcap cache time", "750");
2416 lpcfg_do_global_parameter(lp_ctx, "create krb5 conf", "yes");
2418 lpcfg_do_global_parameter(lp_ctx, "winbind max clients", "200");
2420 lpcfg_do_global_parameter(lp_ctx, "acl map full control", "yes");
2422 lpcfg_do_global_parameter(lp_ctx, "nt pipe support", "yes");
2424 lpcfg_do_global_parameter(lp_ctx, "ldap debug threshold", "10");
2426 lpcfg_do_global_parameter(lp_ctx, "follow symlinks", "yes");
2428 lpcfg_do_global_parameter(lp_ctx, "machine password timeout", "604800");
2430 lpcfg_do_global_parameter(lp_ctx, "ldap connection timeout", "2");
2432 lpcfg_do_global_parameter(lp_ctx, "winbind expand groups", "1");
2434 lpcfg_do_global_parameter(lp_ctx, "stat cache", "yes");
2436 lpcfg_do_global_parameter(lp_ctx, "lpq cache time", "30");
2438 lpcfg_do_global_parameter_var(lp_ctx, "smb2 max trans", "%u", DEFAULT_SMB2_MAX_TRANSACT);
2440 lpcfg_do_global_parameter_var(lp_ctx, "smb2 max read", "%u", DEFAULT_SMB2_MAX_READ);
2442 lpcfg_do_global_parameter(lp_ctx, "durable handles", "yes");
2444 lpcfg_do_global_parameter(lp_ctx, "max stat cache size", "256");
2446 lpcfg_do_global_parameter(lp_ctx, "ldap passwd sync", "no");
2448 lpcfg_do_global_parameter(lp_ctx, "kernel change notify", "yes");
2450 lpcfg_do_global_parameter(lp_ctx, "max ttl", "259200");
2452 lpcfg_do_global_parameter(lp_ctx, "blocking locks", "yes");
2454 lpcfg_do_global_parameter(lp_ctx, "oplock contention limit", "2");
2456 lpcfg_do_global_parameter(lp_ctx, "load printers", "yes");
2458 lpcfg_do_global_parameter(lp_ctx, "idmap cache time", "604800");
2460 lpcfg_do_global_parameter(lp_ctx, "preserve case", "yes");
2462 lpcfg_do_global_parameter(lp_ctx, "lm announce", "auto");
2464 lpcfg_do_global_parameter(lp_ctx, "afs token lifetime", "604800");
2466 lpcfg_do_global_parameter(lp_ctx, "enable core files", "yes");
2468 lpcfg_do_global_parameter(lp_ctx, "winbind max domain connections", "1");
2470 lpcfg_do_global_parameter(lp_ctx, "case sensitive", "auto");
2472 lpcfg_do_global_parameter(lp_ctx, "ldap timeout", "15");
2474 lpcfg_do_global_parameter(lp_ctx, "mangle prefix", "1");
2476 lpcfg_do_global_parameter(lp_ctx, "posix locking", "yes");
2478 lpcfg_do_global_parameter(lp_ctx, "lock spin time", "200");
2480 lpcfg_do_global_parameter(lp_ctx, "directory name cache size", "100");
2482 lpcfg_do_global_parameter(lp_ctx, "nmbd bind explicit broadcast", "yes");
2484 lpcfg_do_global_parameter(lp_ctx, "init logon delay", "100");
2486 lpcfg_do_global_parameter(lp_ctx, "usershare owner only", "yes");
2488 lpcfg_do_global_parameter(lp_ctx, "-valid", "yes");
2490 lpcfg_do_global_parameter_var(lp_ctx, "usershare path", "%s/usershares", get_dyn_STATEDIR());
2492 #ifdef DEVELOPER
2493 lpcfg_do_global_parameter_var(lp_ctx, "panic action", "/bin/sleep 999999999");
2494 #endif
2496 lpcfg_do_global_parameter(lp_ctx, "smb passwd file", get_dyn_SMB_PASSWD_FILE());
2498 lpcfg_do_global_parameter(lp_ctx, "logon home", "\\\\%N\\%U");
2500 lpcfg_do_global_parameter(lp_ctx, "logon path", "\\\\%N\\%U\\profile");
2502 lpcfg_do_global_parameter(lp_ctx, "printjob username", "%U");
2504 for (i = 0; parm_table[i].label; i++) {
2505 if (!(lp_ctx->flags[i] & FLAG_CMDLINE)) {
2506 lp_ctx->flags[i] |= FLAG_DEFAULT;
2510 for (parm=lp_ctx->globals->param_opt; parm; parm=parm->next) {
2511 if (!(parm->priority & FLAG_CMDLINE)) {
2512 parm->priority |= FLAG_DEFAULT;
2516 return lp_ctx;
2520 * Initialise the global parameter structure.
2522 struct loadparm_context *loadparm_init_global(bool load_default)
2524 if (global_loadparm_context == NULL) {
2525 global_loadparm_context = loadparm_init(NULL);
2527 if (global_loadparm_context == NULL) {
2528 return NULL;
2530 global_loadparm_context->global = true;
2531 if (load_default && !global_loadparm_context->loaded) {
2532 lpcfg_load_default(global_loadparm_context);
2534 global_loadparm_context->refuse_free = true;
2535 return global_loadparm_context;
2539 * Initialise the global parameter structure.
2541 struct loadparm_context *loadparm_init_s3(TALLOC_CTX *mem_ctx,
2542 const struct loadparm_s3_helpers *s3_fns)
2544 struct loadparm_context *loadparm_context = talloc_zero(mem_ctx, struct loadparm_context);
2545 if (!loadparm_context) {
2546 return NULL;
2548 loadparm_context->s3_fns = s3_fns;
2549 loadparm_context->globals = s3_fns->globals;
2550 return loadparm_context;
2553 const char *lpcfg_configfile(struct loadparm_context *lp_ctx)
2555 return lp_ctx->szConfigFile;
2558 const char *lp_default_path(void)
2560 if (getenv("SMB_CONF_PATH"))
2561 return getenv("SMB_CONF_PATH");
2562 else
2563 return dyn_CONFIGFILE;
2567 * Update the internal state of a loadparm context after settings
2568 * have changed.
2570 static bool lpcfg_update(struct loadparm_context *lp_ctx)
2572 struct debug_settings settings;
2573 TALLOC_CTX *tmp_ctx;
2575 tmp_ctx = talloc_new(lp_ctx);
2576 if (tmp_ctx == NULL) {
2577 return false;
2580 lpcfg_add_auto_services(lp_ctx, lpcfg_auto_services(lp_ctx, tmp_ctx));
2582 if (!lp_ctx->globals->wins_server_list && lp_ctx->globals->we_are_a_wins_server) {
2583 lpcfg_do_global_parameter(lp_ctx, "wins server", "127.0.0.1");
2586 if (!lp_ctx->global) {
2587 TALLOC_FREE(tmp_ctx);
2588 return true;
2591 panic_action = lp_ctx->globals->panic_action;
2593 reload_charcnv(lp_ctx);
2595 ZERO_STRUCT(settings);
2596 /* Add any more debug-related smb.conf parameters created in
2597 * future here */
2598 settings.syslog = lp_ctx->globals->syslog;
2599 settings.syslog_only = lp_ctx->globals->syslog_only;
2600 settings.timestamp_logs = lp_ctx->globals->timestamp_logs;
2601 settings.debug_prefix_timestamp = lp_ctx->globals->debug_prefix_timestamp;
2602 settings.debug_hires_timestamp = lp_ctx->globals->debug_hires_timestamp;
2603 settings.debug_pid = lp_ctx->globals->debug_pid;
2604 settings.debug_uid = lp_ctx->globals->debug_uid;
2605 settings.debug_class = lp_ctx->globals->debug_class;
2606 debug_set_settings(&settings);
2608 /* FIXME: This is a bit of a hack, but we can't use a global, since
2609 * not everything that uses lp also uses the socket library */
2610 if (lpcfg_parm_bool(lp_ctx, NULL, "socket", "testnonblock", false)) {
2611 setenv("SOCKET_TESTNONBLOCK", "1", 1);
2612 } else {
2613 unsetenv("SOCKET_TESTNONBLOCK");
2616 TALLOC_FREE(tmp_ctx);
2617 return true;
2620 bool lpcfg_load_default(struct loadparm_context *lp_ctx)
2622 const char *path;
2624 path = lp_default_path();
2626 if (!file_exist(path)) {
2627 /* We allow the default smb.conf file to not exist,
2628 * basically the equivalent of an empty file. */
2629 return lpcfg_update(lp_ctx);
2632 return lpcfg_load(lp_ctx, path);
2636 * Load the services array from the services file.
2638 * Return True on success, False on failure.
2640 bool lpcfg_load(struct loadparm_context *lp_ctx, const char *filename)
2642 char *n2;
2643 bool bRetval;
2645 filename = talloc_strdup(lp_ctx, filename);
2647 lp_ctx->szConfigFile = filename;
2649 if (lp_ctx->s3_fns) {
2650 return lp_ctx->s3_fns->load(filename);
2653 lp_ctx->bInGlobalSection = true;
2654 n2 = standard_sub_basic(lp_ctx, lp_ctx->szConfigFile);
2655 DEBUG(2, ("lpcfg_load: refreshing parameters from %s\n", n2));
2657 add_to_file_list(lp_ctx, &lp_ctx->file_lists, lp_ctx->szConfigFile, n2);
2659 /* We get sections first, so have to start 'behind' to make up */
2660 lp_ctx->currentService = NULL;
2661 bRetval = pm_process(n2, do_section, do_parameter, lp_ctx);
2663 /* finish up the last section */
2664 DEBUG(4, ("pm_process() returned %s\n", BOOLSTR(bRetval)));
2665 if (bRetval)
2666 if (lp_ctx->currentService != NULL)
2667 bRetval = lpcfg_service_ok(lp_ctx->currentService);
2669 bRetval = bRetval && lpcfg_update(lp_ctx);
2671 /* we do this unconditionally, so that it happens even
2672 for a missing smb.conf */
2673 reload_charcnv(lp_ctx);
2675 if (bRetval == true) {
2676 /* set this up so that any child python tasks will
2677 find the right smb.conf */
2678 setenv("SMB_CONF_PATH", filename, 1);
2680 /* set the context used by the lp_*() function
2681 varients */
2682 global_loadparm_context = lp_ctx;
2683 lp_ctx->loaded = true;
2686 return bRetval;
2690 * Return the max number of services.
2693 int lpcfg_numservices(struct loadparm_context *lp_ctx)
2695 if (lp_ctx->s3_fns) {
2696 return lp_ctx->s3_fns->get_numservices();
2699 return lp_ctx->iNumServices;
2703 * Display the contents of the services array in human-readable form.
2706 void lpcfg_dump(struct loadparm_context *lp_ctx, FILE *f, bool show_defaults,
2707 int maxtoprint)
2709 int iService;
2711 if (lp_ctx->s3_fns) {
2712 lp_ctx->s3_fns->dump(f, show_defaults, maxtoprint);
2713 return;
2716 defaults_saved = !show_defaults;
2718 dump_globals(lp_ctx, f, show_defaults);
2720 dump_a_service(lp_ctx->sDefault, lp_ctx->sDefault, f, lp_ctx->flags);
2722 for (iService = 0; iService < maxtoprint; iService++)
2723 lpcfg_dump_one(f, show_defaults, lp_ctx->services[iService], lp_ctx->sDefault);
2727 * Display the contents of one service in human-readable form.
2729 void lpcfg_dump_one(FILE *f, bool show_defaults, struct loadparm_service *service, struct loadparm_service *sDefault)
2731 if (service != NULL) {
2732 if (service->szService[0] == '\0')
2733 return;
2734 dump_a_service(service, sDefault, f, NULL);
2738 struct loadparm_service *lpcfg_servicebynum(struct loadparm_context *lp_ctx,
2739 int snum)
2741 if (lp_ctx->s3_fns) {
2742 return lp_ctx->s3_fns->get_servicebynum(snum);
2745 return lp_ctx->services[snum];
2748 struct loadparm_service *lpcfg_service(struct loadparm_context *lp_ctx,
2749 const char *service_name)
2751 int iService;
2752 char *serviceName;
2754 if (lp_ctx->s3_fns) {
2755 return lp_ctx->s3_fns->get_service(service_name);
2758 for (iService = lp_ctx->iNumServices - 1; iService >= 0; iService--) {
2759 if (lp_ctx->services[iService] &&
2760 lp_ctx->services[iService]->szService) {
2762 * The substitution here is used to support %U is
2763 * service names
2765 serviceName = standard_sub_basic(
2766 lp_ctx->services[iService],
2767 lp_ctx->services[iService]->szService);
2768 if (strequal(serviceName, service_name)) {
2769 talloc_free(serviceName);
2770 return lp_ctx->services[iService];
2772 talloc_free(serviceName);
2776 DEBUG(7,("lpcfg_servicenumber: couldn't find %s\n", service_name));
2777 return NULL;
2780 const char *lpcfg_servicename(const struct loadparm_service *service)
2782 return lpcfg_string((const char *)service->szService);
2786 * A useful volume label function.
2788 const char *lpcfg_volume_label(struct loadparm_service *service, struct loadparm_service *sDefault)
2790 const char *ret;
2791 ret = lpcfg_string((const char *)((service != NULL && service->volume != NULL) ?
2792 service->volume : sDefault->volume));
2793 if (!*ret)
2794 return lpcfg_servicename(service);
2795 return ret;
2799 * Return the correct printer name.
2801 const char *lpcfg_printername(struct loadparm_service *service, struct loadparm_service *sDefault)
2803 const char *ret;
2804 ret = lpcfg_string((const char *)((service != NULL && service->_printername != NULL) ?
2805 service->_printername : sDefault->_printername));
2806 if (ret == NULL || (ret != NULL && *ret == '\0'))
2807 ret = lpcfg_servicename(service);
2809 return ret;
2814 * Return the max print jobs per queue.
2816 int lpcfg_maxprintjobs(struct loadparm_service *service, struct loadparm_service *sDefault)
2818 int maxjobs = (service != NULL) ? service->iMaxPrintJobs : sDefault->iMaxPrintJobs;
2819 if (maxjobs <= 0 || maxjobs >= PRINT_MAX_JOBID)
2820 maxjobs = PRINT_MAX_JOBID - 1;
2822 return maxjobs;
2825 struct smb_iconv_handle *lpcfg_iconv_handle(struct loadparm_context *lp_ctx)
2827 if (lp_ctx == NULL) {
2828 return get_iconv_handle();
2830 return lp_ctx->iconv_handle;
2833 _PUBLIC_ void reload_charcnv(struct loadparm_context *lp_ctx)
2835 struct smb_iconv_handle *old_ic = lp_ctx->iconv_handle;
2836 if (!lp_ctx->global) {
2837 return;
2840 if (old_ic == NULL) {
2841 old_ic = global_iconv_handle;
2843 lp_ctx->iconv_handle = smb_iconv_handle_reinit_lp(lp_ctx, lp_ctx, old_ic);
2844 global_iconv_handle = lp_ctx->iconv_handle;
2847 _PUBLIC_ char *lpcfg_tls_keyfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
2849 return lpcfg_private_path(mem_ctx, lp_ctx, lpcfg__tls_keyfile(lp_ctx));
2852 _PUBLIC_ char *lpcfg_tls_certfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
2854 return lpcfg_private_path(mem_ctx, lp_ctx, lpcfg__tls_certfile(lp_ctx));
2857 _PUBLIC_ char *lpcfg_tls_cafile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
2859 return lpcfg_private_path(mem_ctx, lp_ctx, lpcfg__tls_cafile(lp_ctx));
2862 _PUBLIC_ char *lpcfg_tls_crlfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
2864 return lpcfg_private_path(mem_ctx, lp_ctx, lpcfg__tls_crlfile(lp_ctx));
2867 _PUBLIC_ char *lpcfg_tls_dhpfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
2869 return lpcfg_private_path(mem_ctx, lp_ctx, lpcfg__tls_dhpfile(lp_ctx));
2872 struct gensec_settings *lpcfg_gensec_settings(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
2874 struct gensec_settings *settings = talloc_zero(mem_ctx, struct gensec_settings);
2875 if (settings == NULL)
2876 return NULL;
2877 SMB_ASSERT(lp_ctx != NULL);
2878 settings->lp_ctx = talloc_reference(settings, lp_ctx);
2879 settings->target_hostname = lpcfg_parm_string(lp_ctx, NULL, "gensec", "target_hostname");
2880 return settings;
2883 int lpcfg_server_role(struct loadparm_context *lp_ctx)
2885 int domain_master = lpcfg__domain_master(lp_ctx);
2887 return lp_find_server_role(lpcfg__server_role(lp_ctx),
2888 lpcfg__security(lp_ctx),
2889 lpcfg__domain_logons(lp_ctx),
2890 (domain_master == true) ||
2891 (domain_master == Auto));
2894 int lpcfg_security(struct loadparm_context *lp_ctx)
2896 return lp_find_security(lpcfg__server_role(lp_ctx),
2897 lpcfg__security(lp_ctx));
2900 bool lpcfg_server_signing_allowed(struct loadparm_context *lp_ctx, bool *mandatory)
2902 bool allowed = true;
2903 enum smb_signing_setting signing_setting = lpcfg_server_signing(lp_ctx);
2905 *mandatory = false;
2907 if (signing_setting == SMB_SIGNING_DEFAULT) {
2909 * If we are a domain controller, SMB signing is
2910 * really important, as it can prevent a number of
2911 * attacks on communications between us and the
2912 * clients
2914 * However, it really sucks (no sendfile, CPU
2915 * overhead) performance-wise when used on a
2916 * file server, so disable it by default
2917 * on non-DCs
2920 if (lpcfg_server_role(lp_ctx) >= ROLE_ACTIVE_DIRECTORY_DC) {
2921 signing_setting = SMB_SIGNING_REQUIRED;
2922 } else {
2923 signing_setting = SMB_SIGNING_OFF;
2927 switch (signing_setting) {
2928 case SMB_SIGNING_REQUIRED:
2929 *mandatory = true;
2930 break;
2931 case SMB_SIGNING_IF_REQUIRED:
2932 break;
2933 case SMB_SIGNING_DEFAULT:
2934 case SMB_SIGNING_OFF:
2935 allowed = false;
2936 break;
2939 return allowed;
2942 int lpcfg_tdb_hash_size(struct loadparm_context *lp_ctx, const char *name)
2944 const char *base;
2946 if (name == NULL) {
2947 return 0;
2950 base = strrchr_m(name, '/');
2951 if (base != NULL) {
2952 base += 1;
2953 } else {
2954 base = name;
2956 return lpcfg_parm_int(lp_ctx, NULL, "tdb_hashsize", base, 0);
2960 int lpcfg_tdb_flags(struct loadparm_context *lp_ctx, int tdb_flags)
2962 if (!lpcfg_use_mmap(lp_ctx)) {
2963 tdb_flags |= TDB_NOMMAP;
2965 return tdb_flags;