param: use a single special handler for idmap parameters
[Samba.git] / lib / param / loadparm.c
blob811d802779da5a01800ae41516f9c5246bbb9eff
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 (sizeof(parm_table) / sizeof(struct parm_struct))
80 #ifndef N_
81 #define N_(x) x
82 #endif
84 #include "lib/param/param_table.c"
86 struct loadparm_service *lpcfg_default_service(struct loadparm_context *lp_ctx)
88 if (lp_ctx->s3_fns) {
89 return lp_ctx->s3_fns->get_default_loadparm_service();
91 return lp_ctx->sDefault;
94 /**
95 * Convenience routine to grab string parameters into temporary memory
96 * and run standard_sub_basic on them.
98 * The buffers can be written to by
99 * callers without affecting the source string.
102 static const char *lpcfg_string(const char *s)
104 #if 0 /* until REWRITE done to make thread-safe */
105 size_t len = s ? strlen(s) : 0;
106 char *ret;
107 #endif
109 /* The follow debug is useful for tracking down memory problems
110 especially if you have an inner loop that is calling a lp_*()
111 function that returns a string. Perhaps this debug should be
112 present all the time? */
114 #if 0
115 DEBUG(10, ("lpcfg_string(%s)\n", s));
116 #endif
118 #if 0 /* until REWRITE done to make thread-safe */
119 if (!lp_talloc)
120 lp_talloc = talloc_init("lp_talloc");
122 ret = talloc_array(lp_talloc, char, len + 100); /* leave room for substitution */
124 if (!ret)
125 return NULL;
127 if (!s)
128 *ret = 0;
129 else
130 strlcpy(ret, s, len);
132 if (trim_string(ret, "\"", "\"")) {
133 if (strchr(ret,'"') != NULL)
134 strlcpy(ret, s, len);
137 standard_sub_basic(ret,len+100);
138 return (ret);
139 #endif
140 return s;
144 In this section all the functions that are used to access the
145 parameters from the rest of the program are defined
149 * the creation of separate lpcfg_*() and lp_*() functions is to allow
150 * for code compatibility between existing Samba4 and Samba3 code.
153 /* this global context supports the lp_*() function varients */
154 static struct loadparm_context *global_loadparm_context;
156 #define lpcfg_default_service global_loadparm_context->sDefault
157 #define lpcfg_global_service(i) global_loadparm_context->services[i]
159 #define FN_GLOBAL_STRING(fn_name,var_name) \
160 _PUBLIC_ char *lpcfg_ ## fn_name(struct loadparm_context *lp_ctx, TALLOC_CTX *ctx) {\
161 if (lp_ctx == NULL) return NULL; \
162 if (lp_ctx->s3_fns) { \
163 return lp_ctx->globals->var_name ? lp_ctx->s3_fns->lp_string(ctx, lp_ctx->globals->var_name) : talloc_strdup(ctx, ""); \
165 return lp_ctx->globals->var_name ? talloc_strdup(ctx, lpcfg_string(lp_ctx->globals->var_name)) : talloc_strdup(ctx, ""); \
168 #define FN_GLOBAL_CONST_STRING(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 ? lpcfg_string(lp_ctx->globals->var_name) : ""; \
174 #define FN_GLOBAL_LIST(fn_name,var_name) \
175 _PUBLIC_ const char **lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) { \
176 if (lp_ctx == NULL) return NULL; \
177 return lp_ctx->globals->var_name; \
180 #define FN_GLOBAL_BOOL(fn_name,var_name) \
181 _PUBLIC_ bool lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) {\
182 if (lp_ctx == NULL) return false; \
183 return lp_ctx->globals->var_name; \
186 #define FN_GLOBAL_INTEGER(fn_name,var_name) \
187 _PUBLIC_ int lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) { \
188 return lp_ctx->globals->var_name; \
191 /* Local parameters don't need the ->s3_fns because the struct
192 * loadparm_service is shared and lpcfg_service() checks the ->s3_fns
193 * hook */
194 #define FN_LOCAL_STRING(fn_name,val) \
195 _PUBLIC_ char *lpcfg_ ## fn_name(struct loadparm_service *service, \
196 struct loadparm_service *sDefault, TALLOC_CTX *ctx) { \
197 return(talloc_strdup(ctx, lpcfg_string((const char *)((service != NULL && service->val != NULL) ? service->val : sDefault->val)))); \
200 #define FN_LOCAL_CONST_STRING(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_LIST(fn_name,val) \
207 _PUBLIC_ const char **lpcfg_ ## fn_name(struct loadparm_service *service, \
208 struct loadparm_service *sDefault) {\
209 return(const char **)(service != NULL && service->val != NULL? service->val : sDefault->val); \
212 #define FN_LOCAL_PARM_BOOL(fn_name, val) FN_LOCAL_BOOL(fn_name, val)
214 #define FN_LOCAL_BOOL(fn_name,val) \
215 _PUBLIC_ bool lpcfg_ ## fn_name(struct loadparm_service *service, \
216 struct loadparm_service *sDefault) { \
217 return((service != NULL)? service->val : sDefault->val); \
220 #define FN_LOCAL_INTEGER(fn_name,val) \
221 _PUBLIC_ int lpcfg_ ## fn_name(struct loadparm_service *service, \
222 struct loadparm_service *sDefault) { \
223 return((service != NULL)? service->val : sDefault->val); \
226 #define FN_LOCAL_PARM_INTEGER(fn_name, val) FN_LOCAL_INTEGER(fn_name, val)
228 #define FN_LOCAL_PARM_CHAR(fn_name,val) \
229 _PUBLIC_ char lpcfg_ ## fn_name(struct loadparm_service *service, \
230 struct loadparm_service *sDefault) { \
231 return((service != NULL)? service->val : sDefault->val); \
234 #include "lib/param/param_functions.c"
236 /* These functions cannot be auto-generated */
237 FN_LOCAL_BOOL(autoloaded, autoloaded)
238 FN_GLOBAL_CONST_STRING(dnsdomain, dnsdomain)
240 /* local prototypes */
241 static struct loadparm_service *lpcfg_getservicebyname(struct loadparm_context *lp_ctx,
242 const char *pszServiceName);
243 static bool lpcfg_service_ok(struct loadparm_service *service);
244 static bool do_section(const char *pszSectionName, void *);
246 /* This is a helper function for parametrical options support. */
247 /* It returns a pointer to parametrical option value if it exists or NULL otherwise */
248 /* Actual parametrical functions are quite simple */
249 const char *lpcfg_get_parametric(struct loadparm_context *lp_ctx,
250 struct loadparm_service *service,
251 const char *type, const char *option)
253 char *vfskey_tmp = NULL;
254 char *vfskey = NULL;
255 struct parmlist_entry *data;
257 if (lp_ctx == NULL)
258 return NULL;
260 if (lp_ctx->s3_fns) {
261 return lp_ctx->s3_fns->get_parametric(service, type, option, NULL);
264 data = (service == NULL ? lp_ctx->globals->param_opt : service->param_opt);
266 vfskey_tmp = talloc_asprintf(NULL, "%s:%s", type, option);
267 if (vfskey_tmp == NULL) return NULL;
268 vfskey = strlower_talloc(NULL, vfskey_tmp);
269 talloc_free(vfskey_tmp);
271 while (data) {
272 if (strcmp(data->key, vfskey) == 0) {
273 talloc_free(vfskey);
274 return data->value;
276 data = data->next;
279 if (service != NULL) {
280 /* Try to fetch the same option but from globals */
281 /* but only if we are not already working with globals */
282 for (data = lp_ctx->globals->param_opt; data;
283 data = data->next) {
284 if (strcmp(data->key, vfskey) == 0) {
285 talloc_free(vfskey);
286 return data->value;
291 talloc_free(vfskey);
293 return NULL;
298 * convenience routine to return int parameters.
300 int lp_int(const char *s)
303 if (!s || !*s) {
304 DEBUG(0,("lp_int(%s): is called with NULL!\n",s));
305 return -1;
308 return strtol(s, NULL, 0);
312 * convenience routine to return unsigned long parameters.
314 unsigned long lp_ulong(const char *s)
317 if (!s || !*s) {
318 DEBUG(0,("lp_ulong(%s): is called with NULL!\n",s));
319 return -1;
322 return strtoul(s, NULL, 0);
326 * convenience routine to return unsigned long parameters.
328 static long lp_long(const char *s)
331 if (!s) {
332 DEBUG(0,("lp_long(%s): is called with NULL!\n",s));
333 return -1;
336 return strtol(s, NULL, 0);
340 * convenience routine to return unsigned long parameters.
342 static double lp_double(const char *s)
345 if (!s) {
346 DEBUG(0,("lp_double(%s): is called with NULL!\n",s));
347 return -1;
350 return strtod(s, NULL);
354 * convenience routine to return boolean parameters.
356 bool lp_bool(const char *s)
358 bool ret = false;
360 if (!s || !*s) {
361 DEBUG(0,("lp_bool(%s): is called with NULL!\n",s));
362 return false;
365 if (!set_boolean(s, &ret)) {
366 DEBUG(0,("lp_bool(%s): value is not boolean!\n",s));
367 return false;
370 return ret;
374 * Return parametric option from a given service. Type is a part of option before ':'
375 * Parametric option has following syntax: 'Type: option = value'
376 * Returned value is allocated in 'lp_talloc' context
379 const char *lpcfg_parm_string(struct loadparm_context *lp_ctx,
380 struct loadparm_service *service, const char *type,
381 const char *option)
383 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
385 if (value)
386 return lpcfg_string(value);
388 return NULL;
392 * Return parametric option from a given service. Type is a part of option before ':'
393 * Parametric option has following syntax: 'Type: option = value'
394 * Returned value is allocated in 'lp_talloc' context
397 const char **lpcfg_parm_string_list(TALLOC_CTX *mem_ctx,
398 struct loadparm_context *lp_ctx,
399 struct loadparm_service *service,
400 const char *type,
401 const char *option, const char *separator)
403 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
405 if (value != NULL)
406 return (const char **)str_list_make(mem_ctx, value, separator);
408 return NULL;
412 * Return parametric option from a given service. Type is a part of option before ':'
413 * Parametric option has following syntax: 'Type: option = value'
416 int lpcfg_parm_int(struct loadparm_context *lp_ctx,
417 struct loadparm_service *service, const char *type,
418 const char *option, int default_v)
420 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
422 if (value)
423 return lp_int(value);
425 return default_v;
429 * Return parametric option from a given service. Type is a part of
430 * option before ':'.
431 * Parametric option has following syntax: 'Type: option = value'.
434 int lpcfg_parm_bytes(struct loadparm_context *lp_ctx,
435 struct loadparm_service *service, const char *type,
436 const char *option, int default_v)
438 uint64_t bval;
440 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
442 if (value && conv_str_size_error(value, &bval)) {
443 if (bval <= INT_MAX) {
444 return (int)bval;
448 return default_v;
452 * Return parametric option from a given service.
453 * Type is a part of option before ':'
454 * Parametric option has following syntax: 'Type: option = value'
456 unsigned long lpcfg_parm_ulong(struct loadparm_context *lp_ctx,
457 struct loadparm_service *service, const char *type,
458 const char *option, unsigned long default_v)
460 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
462 if (value)
463 return lp_ulong(value);
465 return default_v;
468 long lpcfg_parm_long(struct loadparm_context *lp_ctx,
469 struct loadparm_service *service, const char *type,
470 const char *option, long default_v)
472 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
474 if (value)
475 return lp_long(value);
477 return default_v;
480 double lpcfg_parm_double(struct loadparm_context *lp_ctx,
481 struct loadparm_service *service, const char *type,
482 const char *option, double default_v)
484 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
486 if (value != NULL)
487 return lp_double(value);
489 return default_v;
493 * Return parametric option from a given service. Type is a part of option before ':'
494 * Parametric option has following syntax: 'Type: option = value'
497 bool lpcfg_parm_bool(struct loadparm_context *lp_ctx,
498 struct loadparm_service *service, const char *type,
499 const char *option, bool default_v)
501 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
503 if (value != NULL)
504 return lp_bool(value);
506 return default_v;
511 * Set a string value, deallocating any existing space, and allocing the space
512 * for the string
514 bool lpcfg_string_set(TALLOC_CTX *mem_ctx, char **dest, const char *src)
516 talloc_free(*dest);
518 if (src == NULL)
519 src = "";
521 *dest = talloc_strdup(mem_ctx, src);
522 if ((*dest) == NULL) {
523 DEBUG(0,("Out of memory in string_set\n"));
524 return false;
527 return true;
531 * Set a string value, deallocating any existing space, and allocing the space
532 * for the string
534 static bool lpcfg_string_set_upper(TALLOC_CTX *mem_ctx, char **dest, const char *src)
536 talloc_free(*dest);
538 if (src == NULL)
539 src = "";
541 *dest = strupper_talloc(mem_ctx, src);
542 if ((*dest) == NULL) {
543 DEBUG(0,("Out of memory in string_set_upper\n"));
544 return false;
547 return true;
553 * Add a new service to the services array initialising it with the given
554 * service.
557 struct loadparm_service *lpcfg_add_service(struct loadparm_context *lp_ctx,
558 const struct loadparm_service *pservice,
559 const char *name)
561 int i;
562 int num_to_alloc = lp_ctx->iNumServices + 1;
563 struct parmlist_entry *data, *pdata;
565 if (pservice == NULL) {
566 pservice = lp_ctx->sDefault;
569 /* it might already exist */
570 if (name) {
571 struct loadparm_service *service = lpcfg_getservicebyname(lp_ctx,
572 name);
573 if (service != NULL) {
574 /* Clean all parametric options for service */
575 /* They will be added during parsing again */
576 data = service->param_opt;
577 while (data) {
578 pdata = data->next;
579 talloc_free(data);
580 data = pdata;
582 service->param_opt = NULL;
583 return service;
587 /* find an invalid one */
588 for (i = 0; i < lp_ctx->iNumServices; i++)
589 if (lp_ctx->services[i] == NULL)
590 break;
592 /* if not, then create one */
593 if (i == lp_ctx->iNumServices) {
594 struct loadparm_service **tsp;
596 tsp = talloc_realloc(lp_ctx, lp_ctx->services, struct loadparm_service *, num_to_alloc);
598 if (!tsp) {
599 DEBUG(0,("lpcfg_add_service: failed to enlarge services!\n"));
600 return NULL;
601 } else {
602 lp_ctx->services = tsp;
603 lp_ctx->services[lp_ctx->iNumServices] = NULL;
606 lp_ctx->iNumServices++;
609 lp_ctx->services[i] = talloc_zero(lp_ctx->services, struct loadparm_service);
610 if (lp_ctx->services[i] == NULL) {
611 DEBUG(0,("lpcfg_add_service: out of memory!\n"));
612 return NULL;
614 copy_service(lp_ctx->services[i], pservice, NULL);
615 if (name != NULL)
616 lpcfg_string_set(lp_ctx->services[i], &lp_ctx->services[i]->szService, name);
617 return lp_ctx->services[i];
621 * Add a new home service, with the specified home directory, defaults coming
622 * from service ifrom.
625 bool lpcfg_add_home(struct loadparm_context *lp_ctx,
626 const char *pszHomename,
627 struct loadparm_service *default_service,
628 const char *user, const char *pszHomedir)
630 struct loadparm_service *service;
632 service = lpcfg_add_service(lp_ctx, default_service, pszHomename);
634 if (service == NULL)
635 return false;
637 if (!(*(default_service->path))
638 || strequal(default_service->path, lp_ctx->sDefault->path)) {
639 service->path = talloc_strdup(service, pszHomedir);
640 } else {
641 service->path = string_sub_talloc(service, lpcfg_path(default_service, lp_ctx->sDefault, service), "%H", pszHomedir);
644 if (!(*(service->comment))) {
645 service->comment = talloc_asprintf(service, "Home directory of %s", user);
647 service->bAvailable = default_service->bAvailable;
648 service->browseable = default_service->browseable;
650 DEBUG(3, ("adding home's share [%s] for user '%s' at '%s'\n",
651 pszHomename, user, service->path));
653 return true;
657 * Add a new printer service, with defaults coming from service iFrom.
660 bool lpcfg_add_printer(struct loadparm_context *lp_ctx,
661 const char *pszPrintername,
662 struct loadparm_service *default_service)
664 const char *comment = "From Printcap";
665 struct loadparm_service *service;
666 service = lpcfg_add_service(lp_ctx, default_service, pszPrintername);
668 if (service == NULL)
669 return false;
671 /* note that we do NOT default the availability flag to True - */
672 /* we take it from the default service passed. This allows all */
673 /* dynamic printers to be disabled by disabling the [printers] */
674 /* entry (if/when the 'available' keyword is implemented!). */
676 /* the printer name is set to the service name. */
677 lpcfg_string_set(service, &service->_printername, pszPrintername);
678 lpcfg_string_set(service, &service->comment, comment);
679 service->browseable = default_service->browseable;
680 /* Printers cannot be read_only. */
681 service->read_only = false;
682 /* Printer services must be printable. */
683 service->printable = true;
685 DEBUG(3, ("adding printer service %s\n", pszPrintername));
687 return true;
691 * Map a parameter's string representation to something we can use.
692 * Returns False if the parameter string is not recognised, else TRUE.
695 int lpcfg_map_parameter(const char *pszParmName)
697 int iIndex;
699 for (iIndex = 0; parm_table[iIndex].label; iIndex++)
700 if (strwicmp(parm_table[iIndex].label, pszParmName) == 0)
701 return iIndex;
703 /* Warn only if it isn't parametric option */
704 if (strchr(pszParmName, ':') == NULL)
705 DEBUG(0, ("Unknown parameter encountered: \"%s\"\n", pszParmName));
706 /* We do return 'fail' for parametric options as well because they are
707 stored in different storage
709 return -1;
714 return the parameter structure for a parameter
716 struct parm_struct *lpcfg_parm_struct(struct loadparm_context *lp_ctx, const char *name)
718 int parmnum;
720 if (lp_ctx->s3_fns) {
721 return lp_ctx->s3_fns->get_parm_struct(name);
724 parmnum = lpcfg_map_parameter(name);
725 if (parmnum == -1) return NULL;
726 return &parm_table[parmnum];
730 return the parameter pointer for a parameter
732 void *lpcfg_parm_ptr(struct loadparm_context *lp_ctx,
733 struct loadparm_service *service, struct parm_struct *parm)
735 if (lp_ctx->s3_fns) {
736 return lp_ctx->s3_fns->get_parm_ptr(service, parm);
739 if (service == NULL) {
740 if (parm->p_class == P_LOCAL)
741 return ((char *)lp_ctx->sDefault)+parm->offset;
742 else if (parm->p_class == P_GLOBAL)
743 return ((char *)lp_ctx->globals)+parm->offset;
744 else return NULL;
745 } else {
746 return ((char *)service) + parm->offset;
751 return the parameter pointer for a parameter
753 bool lpcfg_parm_is_cmdline(struct loadparm_context *lp_ctx, const char *name)
755 int parmnum;
757 if (lp_ctx->s3_fns) {
758 struct parm_struct *parm = lp_ctx->s3_fns->get_parm_struct(name);
759 if (parm) {
760 return parm->flags & FLAG_CMDLINE;
762 return false;
765 parmnum = lpcfg_map_parameter(name);
766 if (parmnum == -1) return false;
768 return lp_ctx->flags[parmnum] & FLAG_CMDLINE;
772 * Find a service by name. Otherwise works like get_service.
775 static struct loadparm_service *lpcfg_getservicebyname(struct loadparm_context *lp_ctx,
776 const char *pszServiceName)
778 int iService;
780 if (lp_ctx->s3_fns) {
781 return lp_ctx->s3_fns->get_service(pszServiceName);
784 for (iService = lp_ctx->iNumServices - 1; iService >= 0; iService--)
785 if (lp_ctx->services[iService] != NULL &&
786 strwicmp(lp_ctx->services[iService]->szService, pszServiceName) == 0) {
787 return lp_ctx->services[iService];
790 return NULL;
794 * Add a parametric option to a parmlist_entry,
795 * replacing old value, if already present.
797 void set_param_opt(TALLOC_CTX *mem_ctx,
798 struct parmlist_entry **opt_list,
799 const char *opt_name,
800 const char *opt_value,
801 unsigned priority)
803 struct parmlist_entry *new_opt, *opt;
804 bool not_added;
806 opt = *opt_list;
807 not_added = true;
809 /* Traverse destination */
810 while (opt) {
811 /* If we already have same option, override it */
812 if (strwicmp(opt->key, opt_name) == 0) {
813 if ((opt->priority & FLAG_CMDLINE) &&
814 !(priority & FLAG_CMDLINE)) {
815 /* it's been marked as not to be
816 overridden */
817 return;
819 TALLOC_FREE(opt->value);
820 TALLOC_FREE(opt->list);
821 opt->value = talloc_strdup(opt, opt_value);
822 opt->priority = priority;
823 not_added = false;
824 break;
826 opt = opt->next;
828 if (not_added) {
829 new_opt = talloc(mem_ctx, struct parmlist_entry);
830 if (new_opt == NULL) {
831 smb_panic("OOM");
834 new_opt->key = talloc_strdup(new_opt, opt_name);
835 if (new_opt->key == NULL) {
836 smb_panic("talloc_strdup failed");
839 new_opt->value = talloc_strdup(new_opt, opt_value);
840 if (new_opt->value == NULL) {
841 smb_panic("talloc_strdup failed");
844 new_opt->list = NULL;
845 new_opt->priority = priority;
846 DLIST_ADD(*opt_list, new_opt);
851 * Copy a service structure to another.
852 * If pcopymapDest is NULL then copy all fields
855 void copy_service(struct loadparm_service *pserviceDest,
856 const struct loadparm_service *pserviceSource,
857 struct bitmap *pcopymapDest)
859 int i;
860 bool bcopyall = (pcopymapDest == NULL);
861 struct parmlist_entry *data;
863 for (i = 0; parm_table[i].label; i++)
864 if (parm_table[i].p_class == P_LOCAL &&
865 (bcopyall || bitmap_query(pcopymapDest, i))) {
866 const void *src_ptr =
867 ((const char *)pserviceSource) + parm_table[i].offset;
868 void *dest_ptr =
869 ((char *)pserviceDest) + parm_table[i].offset;
871 switch (parm_table[i].type) {
872 case P_BOOL:
873 case P_BOOLREV:
874 *(bool *)dest_ptr = *(const bool *)src_ptr;
875 break;
877 case P_INTEGER:
878 case P_BYTES:
879 case P_OCTAL:
880 case P_ENUM:
881 *(int *)dest_ptr = *(const int *)src_ptr;
882 break;
884 case P_CHAR:
885 *(char *)dest_ptr = *(const char *)src_ptr;
886 break;
888 case P_STRING:
889 lpcfg_string_set(pserviceDest,
890 (char **)dest_ptr,
891 *(const char * const *)src_ptr);
892 break;
894 case P_USTRING:
895 lpcfg_string_set_upper(pserviceDest,
896 (char **)dest_ptr,
897 *(const char * const *)src_ptr);
898 break;
899 case P_LIST:
900 TALLOC_FREE(*((char ***)dest_ptr));
901 *(const char * const **)dest_ptr = (const char * const *)str_list_copy(pserviceDest,
902 *(const char * * const *)src_ptr);
903 break;
904 default:
905 break;
909 if (bcopyall) {
910 init_copymap(pserviceDest);
911 if (pserviceSource->copymap)
912 bitmap_copy(pserviceDest->copymap,
913 pserviceSource->copymap);
916 for (data = pserviceSource->param_opt; data != NULL; data = data->next) {
917 set_param_opt(pserviceDest, &pserviceDest->param_opt,
918 data->key, data->value, data->priority);
923 * Check a service for consistency. Return False if the service is in any way
924 * incomplete or faulty, else True.
926 static bool lpcfg_service_ok(struct loadparm_service *service)
928 bool bRetval;
930 bRetval = true;
931 if (service->szService[0] == '\0') {
932 DEBUG(0, ("The following message indicates an internal error:\n"));
933 DEBUG(0, ("No service name in service entry.\n"));
934 bRetval = false;
937 /* The [printers] entry MUST be printable. I'm all for flexibility, but */
938 /* I can't see why you'd want a non-printable printer service... */
939 if (strwicmp(service->szService, PRINTERS_NAME) == 0) {
940 if (!service->printable) {
941 DEBUG(0, ("WARNING: [%s] service MUST be printable!\n",
942 service->szService));
943 service->printable = true;
945 /* [printers] service must also be non-browsable. */
946 if (service->browseable)
947 service->browseable = false;
950 /* If a service is flagged unavailable, log the fact at level 0. */
951 if (!service->bAvailable)
952 DEBUG(1, ("NOTE: Service %s is flagged unavailable.\n",
953 service->szService));
955 return bRetval;
959 /*******************************************************************
960 Keep a linked list of all config files so we know when one has changed
961 it's date and needs to be reloaded.
962 ********************************************************************/
964 void add_to_file_list(TALLOC_CTX *mem_ctx, struct file_lists **list,
965 const char *fname, const char *subfname)
967 struct file_lists *f = *list;
969 while (f) {
970 if (f->name && !strcmp(f->name, fname))
971 break;
972 f = f->next;
975 if (!f) {
976 f = talloc(mem_ctx, struct file_lists);
977 if (!f)
978 goto fail;
979 f->next = *list;
980 f->name = talloc_strdup(f, fname);
981 if (!f->name) {
982 TALLOC_FREE(f);
983 goto fail;
985 f->subfname = talloc_strdup(f, subfname);
986 if (!f->subfname) {
987 TALLOC_FREE(f);
988 goto fail;
990 *list = f;
991 f->modtime = file_modtime(subfname);
992 } else {
993 time_t t = file_modtime(subfname);
994 if (t)
995 f->modtime = t;
997 return;
999 fail:
1000 DEBUG(0, ("Unable to add file to file list: %s\n", fname));
1004 /*******************************************************************
1005 Check if a config file has changed date.
1006 ********************************************************************/
1007 bool lpcfg_file_list_changed(struct loadparm_context *lp_ctx)
1009 struct file_lists *f;
1010 DEBUG(6, ("lpcfg_file_list_changed()\n"));
1012 for (f = lp_ctx->file_lists; f != NULL; f = f->next) {
1013 char *n2;
1014 time_t mod_time;
1016 n2 = standard_sub_basic(lp_ctx, f->name);
1018 DEBUGADD(6, ("file %s -> %s last mod_time: %s\n",
1019 f->name, n2, ctime(&f->modtime)));
1021 mod_time = file_modtime(n2);
1023 if (mod_time && ((f->modtime != mod_time) || (f->subfname == NULL) || (strcmp(n2, f->subfname) != 0))) {
1024 DEBUGADD(6, ("file %s modified: %s\n", n2,
1025 ctime(&mod_time)));
1026 f->modtime = mod_time;
1027 talloc_free(f->subfname);
1028 f->subfname = talloc_strdup(f, n2);
1029 return true;
1032 return false;
1036 * set the value for a P_ENUM
1038 bool lp_set_enum_parm( struct parm_struct *parm, const char *pszParmValue,
1039 int *ptr )
1041 int i;
1043 for (i = 0; parm->enum_list[i].name; i++) {
1044 if ( strequal(pszParmValue, parm->enum_list[i].name)) {
1045 *ptr = parm->enum_list[i].value;
1046 return true;
1049 DEBUG(0, ("WARNING: Ignoring invalid value '%s' for parameter '%s'\n",
1050 pszParmValue, parm->label));
1051 return false;
1055 /***************************************************************************
1056 Handle the "realm" parameter
1057 ***************************************************************************/
1059 bool handle_realm(struct loadparm_context *lp_ctx, int unused,
1060 const char *pszParmValue, char **ptr)
1062 char *upper;
1063 char *lower;
1065 upper = strupper_talloc(lp_ctx, pszParmValue);
1066 if (upper == NULL) {
1067 return false;
1070 lower = strlower_talloc(lp_ctx, pszParmValue);
1071 if (lower == NULL) {
1072 TALLOC_FREE(upper);
1073 return false;
1076 if (lp_ctx->s3_fns != NULL) {
1077 lp_ctx->s3_fns->lp_string_set(ptr, pszParmValue);
1078 lp_ctx->s3_fns->lp_string_set(&lp_ctx->globals->realm, upper);
1079 lp_ctx->s3_fns->lp_string_set(&lp_ctx->globals->dnsdomain, lower);
1080 } else {
1081 lpcfg_string_set(lp_ctx, ptr, pszParmValue);
1082 lpcfg_string_set(lp_ctx, &lp_ctx->globals->realm, upper);
1083 lpcfg_string_set(lp_ctx, &lp_ctx->globals->dnsdomain, lower);
1086 return true;
1089 /***************************************************************************
1090 Handle the include operation.
1091 ***************************************************************************/
1093 bool handle_include(struct loadparm_context *lp_ctx, int unused,
1094 const char *pszParmValue, char **ptr)
1096 char *fname;
1098 if (lp_ctx->s3_fns) {
1099 return lp_ctx->s3_fns->lp_include(lp_ctx, unused, pszParmValue, ptr);
1102 fname = standard_sub_basic(lp_ctx, pszParmValue);
1104 add_to_file_list(lp_ctx, &lp_ctx->file_lists, pszParmValue, fname);
1106 lpcfg_string_set(lp_ctx, ptr, fname);
1108 if (file_exist(fname))
1109 return pm_process(fname, do_section, do_parameter, lp_ctx);
1111 DEBUG(2, ("Can't find include file %s\n", fname));
1113 return false;
1116 /***************************************************************************
1117 Handle the interpretation of the copy parameter.
1118 ***************************************************************************/
1120 bool handle_copy(struct loadparm_context *lp_ctx, int snum,
1121 const char *pszParmValue, char **ptr)
1123 bool bRetval;
1124 struct loadparm_service *serviceTemp = NULL;
1125 struct loadparm_service *current = NULL;
1127 bRetval = false;
1129 DEBUG(3, ("Copying service from service %s\n", pszParmValue));
1131 serviceTemp = lpcfg_getservicebyname(lp_ctx, pszParmValue);
1132 if (lp_ctx->s3_fns != NULL) {
1133 current = lp_ctx->s3_fns->get_servicebynum(snum);
1134 } else {
1135 current = lp_ctx->currentService;
1138 if (current == NULL) {
1139 DEBUG(0, ("Unable to copy service - invalid service destination"));
1140 return false;
1143 if (serviceTemp != NULL) {
1144 if (serviceTemp == current) {
1145 DEBUG(0, ("Can't copy service %s - unable to copy self!\n", pszParmValue));
1146 } else {
1147 copy_service(current,
1148 serviceTemp,
1149 current->copymap);
1150 lpcfg_string_set(current, ptr, pszParmValue);
1152 bRetval = true;
1154 } else {
1155 DEBUG(0, ("Unable to copy service - source not found: %s\n",
1156 pszParmValue));
1157 bRetval = false;
1160 return bRetval;
1163 bool handle_debug_list(struct loadparm_context *lp_ctx, int unused,
1164 const char *pszParmValue, char **ptr)
1166 if (lp_ctx->s3_fns != NULL) {
1167 lp_ctx->s3_fns->lp_string_set(ptr, pszParmValue);
1168 } else {
1169 lpcfg_string_set(lp_ctx, ptr, pszParmValue);
1172 return debug_parse_levels(pszParmValue);
1175 bool handle_logfile(struct loadparm_context *lp_ctx, int unused,
1176 const char *pszParmValue, char **ptr)
1178 if (lp_ctx->s3_fns != NULL) {
1179 lp_ctx->s3_fns->lp_string_set(ptr, pszParmValue);
1180 } else {
1181 debug_set_logfile(pszParmValue);
1182 lpcfg_string_set(lp_ctx, ptr, pszParmValue);
1185 return true;
1189 * These special charset handling methods only run in the source3 code.
1192 bool handle_charset(struct loadparm_context *lp_ctx, int snum,
1193 const char *pszParmValue, char **ptr)
1195 if (lp_ctx->s3_fns) {
1196 if (*ptr == NULL || strcmp(*ptr, pszParmValue) != 0) {
1197 lp_ctx->s3_fns->lp_string_set(ptr, pszParmValue);
1198 global_iconv_handle = smb_iconv_handle_reinit(NULL,
1199 lpcfg_dos_charset(lp_ctx),
1200 lpcfg_unix_charset(lp_ctx),
1201 true, global_iconv_handle);
1204 return true;
1206 return lpcfg_string_set(lp_ctx, ptr, pszParmValue);
1210 bool handle_dos_charset(struct loadparm_context *lp_ctx, int snum,
1211 const char *pszParmValue, char **ptr)
1213 bool is_utf8 = false;
1214 size_t len = strlen(pszParmValue);
1216 if (lp_ctx->s3_fns) {
1217 if (len == 4 || len == 5) {
1218 /* Don't use StrCaseCmp here as we don't want to
1219 initialize iconv. */
1220 if ((toupper_m(pszParmValue[0]) == 'U') &&
1221 (toupper_m(pszParmValue[1]) == 'T') &&
1222 (toupper_m(pszParmValue[2]) == 'F')) {
1223 if (len == 4) {
1224 if (pszParmValue[3] == '8') {
1225 is_utf8 = true;
1227 } else {
1228 if (pszParmValue[3] == '-' &&
1229 pszParmValue[4] == '8') {
1230 is_utf8 = true;
1236 if (*ptr == NULL || strcmp(*ptr, pszParmValue) != 0) {
1237 if (is_utf8) {
1238 DEBUG(0,("ERROR: invalid DOS charset: 'dos charset' must not "
1239 "be UTF8, using (default value) %s instead.\n",
1240 DEFAULT_DOS_CHARSET));
1241 pszParmValue = DEFAULT_DOS_CHARSET;
1243 lp_ctx->s3_fns->lp_string_set(ptr, pszParmValue);
1244 global_iconv_handle = smb_iconv_handle_reinit(NULL,
1245 lpcfg_dos_charset(lp_ctx),
1246 lpcfg_unix_charset(lp_ctx),
1247 true, global_iconv_handle);
1249 return true;
1252 return lpcfg_string_set(lp_ctx, ptr, pszParmValue);
1255 bool handle_printing(struct loadparm_context *lp_ctx, int snum,
1256 const char *pszParmValue, char **ptr)
1258 static int parm_num = -1;
1259 struct loadparm_service *s;
1261 if (parm_num == -1) {
1262 parm_num = lpcfg_map_parameter("printing");
1265 if (!lp_set_enum_parm(&parm_table[parm_num], pszParmValue, (int*)ptr)) {
1266 return false;
1269 if (lp_ctx->s3_fns) {
1270 if ( snum < 0 ) {
1271 s = lp_ctx->sDefault;
1272 lp_ctx->s3_fns->init_printer_values(lp_ctx->globals->ctx, s);
1273 } else {
1274 s = lp_ctx->services[snum];
1275 lp_ctx->s3_fns->init_printer_values(s, s);
1279 return true;
1282 bool handle_ldap_debug_level(struct loadparm_context *lp_ctx, int snum, const char *pszParmValue, char **ptr)
1284 lp_ctx->globals->ldap_debug_level = lp_int(pszParmValue);
1286 if (lp_ctx->s3_fns) {
1287 lp_ctx->s3_fns->init_ldap_debugging();
1289 return true;
1292 bool handle_netbios_aliases(struct loadparm_context *lp_ctx, int snum, const char *pszParmValue, char **ptr)
1294 TALLOC_FREE(lp_ctx->globals->netbios_aliases);
1295 lp_ctx->globals->netbios_aliases = (const char **)str_list_make_v3(lp_ctx->globals->ctx,
1296 pszParmValue, NULL);
1298 if (lp_ctx->s3_fns) {
1299 return lp_ctx->s3_fns->set_netbios_aliases(lp_ctx->globals->netbios_aliases);
1301 return true;
1305 * idmap related parameters
1308 bool handle_idmap_backend(struct loadparm_context *lp_ctx, int snum, const char *pszParmValue, char **ptr)
1310 if (lp_ctx->s3_fns) {
1311 return lp_ctx->s3_fns->lp_do_parameter(snum, "idmap config * : backend", pszParmValue);
1314 return lpcfg_string_set(lp_ctx, ptr, pszParmValue);
1317 bool handle_idmap_uid(struct loadparm_context *lp_ctx, int snum, const char *pszParmValue, char **ptr)
1319 if (lp_ctx->s3_fns) {
1320 return lp_ctx->s3_fns->lp_do_parameter(snum, "idmap config * : range", pszParmValue);
1323 return lpcfg_string_set(lp_ctx, ptr, pszParmValue);
1326 bool handle_idmap_gid(struct loadparm_context *lp_ctx, int snum, const char *pszParmValue, char **ptr)
1328 if (lp_ctx->s3_fns) {
1329 return lp_ctx->s3_fns->lp_do_parameter(snum, "idmap config * : range", pszParmValue);
1332 return lpcfg_string_set(lp_ctx, ptr, pszParmValue);
1335 /***************************************************************************
1336 Initialise a copymap.
1337 ***************************************************************************/
1339 void init_copymap(struct loadparm_service *pservice)
1341 int i;
1343 TALLOC_FREE(pservice->copymap);
1345 pservice->copymap = bitmap_talloc(NULL, NUMPARAMETERS);
1346 if (!pservice->copymap)
1347 DEBUG(0,
1348 ("Couldn't allocate copymap!! (size %d)\n",
1349 (int)NUMPARAMETERS));
1350 else
1351 for (i = 0; i < NUMPARAMETERS; i++)
1352 bitmap_set(pservice->copymap, i);
1356 * Process a parametric option
1358 static bool lp_do_parameter_parametric(struct loadparm_context *lp_ctx,
1359 struct loadparm_service *service,
1360 const char *pszParmName,
1361 const char *pszParmValue, int flags)
1363 struct parmlist_entry **data;
1364 char *name;
1365 TALLOC_CTX *mem_ctx;
1367 while (isspace((unsigned char)*pszParmName)) {
1368 pszParmName++;
1371 name = strlower_talloc(lp_ctx, pszParmName);
1372 if (!name) return false;
1374 if (service == NULL) {
1375 data = &lp_ctx->globals->param_opt;
1376 mem_ctx = lp_ctx->globals;
1377 } else {
1378 data = &service->param_opt;
1379 mem_ctx = service;
1382 set_param_opt(mem_ctx, data, name, pszParmValue, flags);
1384 talloc_free(name);
1386 return true;
1389 static bool set_variable(TALLOC_CTX *mem_ctx, int parmnum, void *parm_ptr,
1390 const char *pszParmName, const char *pszParmValue,
1391 struct loadparm_context *lp_ctx, bool on_globals)
1393 int i;
1394 /* if it is a special case then go ahead */
1395 if (parm_table[parmnum].special) {
1396 bool ret;
1397 ret = parm_table[parmnum].special(lp_ctx, -1, pszParmValue,
1398 (char **)parm_ptr);
1399 if (!ret) {
1400 return false;
1402 goto mark_non_default;
1405 /* now switch on the type of variable it is */
1406 switch (parm_table[parmnum].type)
1408 case P_BOOL: {
1409 bool b;
1410 if (!set_boolean(pszParmValue, &b)) {
1411 DEBUG(0, ("set_variable(%s): value is not "
1412 "boolean!\n", pszParmValue));
1413 return false;
1415 *(bool *)parm_ptr = b;
1417 break;
1419 case P_BOOLREV: {
1420 bool b;
1421 if (!set_boolean(pszParmValue, &b)) {
1422 DEBUG(0, ("set_variable(%s): value is not "
1423 "boolean!\n", pszParmValue));
1424 return false;
1426 *(bool *)parm_ptr = !b;
1428 break;
1430 case P_INTEGER:
1431 *(int *)parm_ptr = atoi(pszParmValue);
1432 break;
1434 case P_CHAR:
1435 *(char *)parm_ptr = *pszParmValue;
1436 break;
1438 case P_OCTAL:
1439 *(int *)parm_ptr = strtol(pszParmValue, NULL, 8);
1440 break;
1442 case P_BYTES:
1444 uint64_t val;
1445 if (conv_str_size_error(pszParmValue, &val)) {
1446 if (val <= INT_MAX) {
1447 *(int *)parm_ptr = (int)val;
1448 break;
1452 DEBUG(0, ("set_variable(%s): value is not "
1453 "a valid size specifier!\n", pszParmValue));
1454 return false;
1457 case P_CMDLIST:
1458 *(const char * const **)parm_ptr
1459 = (const char * const *)str_list_make(mem_ctx,
1460 pszParmValue, NULL);
1461 break;
1462 case P_LIST:
1464 char **new_list = str_list_make(mem_ctx,
1465 pszParmValue, NULL);
1466 for (i=0; new_list[i]; i++) {
1467 if (*(const char ***)parm_ptr != NULL &&
1468 new_list[i][0] == '+' &&
1469 new_list[i][1])
1471 if (!str_list_check(*(const char ***)parm_ptr,
1472 &new_list[i][1])) {
1473 *(const char ***)parm_ptr = str_list_add(*(const char ***)parm_ptr,
1474 &new_list[i][1]);
1476 } else if (*(const char ***)parm_ptr != NULL &&
1477 new_list[i][0] == '-' &&
1478 new_list[i][1])
1480 str_list_remove(*(const char ***)parm_ptr,
1481 &new_list[i][1]);
1482 } else {
1483 if (i != 0) {
1484 DEBUG(0, ("Unsupported list syntax for: %s = %s\n",
1485 pszParmName, pszParmValue));
1486 return false;
1488 *(const char * const **)parm_ptr = (const char * const *) new_list;
1489 break;
1492 break;
1494 case P_STRING:
1495 lpcfg_string_set(mem_ctx, (char **)parm_ptr, pszParmValue);
1496 break;
1498 case P_USTRING:
1499 lpcfg_string_set_upper(mem_ctx, (char **)parm_ptr, pszParmValue);
1500 break;
1502 case P_ENUM:
1503 if (!lp_set_enum_parm(&parm_table[parmnum], pszParmValue, (int*)parm_ptr)) {
1504 return false;
1506 break;
1508 case P_SEP:
1509 break;
1512 mark_non_default:
1513 if (on_globals && (lp_ctx->flags[parmnum] & FLAG_DEFAULT)) {
1514 lp_ctx->flags[parmnum] &= ~FLAG_DEFAULT;
1515 /* we have to also unset FLAG_DEFAULT on aliases */
1516 for (i=parmnum-1;i>=0 && parm_table[i].offset == parm_table[parmnum].offset;i--) {
1517 lp_ctx->flags[i] &= ~FLAG_DEFAULT;
1519 for (i=parmnum+1;i<NUMPARAMETERS && parm_table[i].offset == parm_table[parmnum].offset;i++) {
1520 lp_ctx->flags[i] &= ~FLAG_DEFAULT;
1523 return true;
1527 bool lpcfg_do_global_parameter(struct loadparm_context *lp_ctx,
1528 const char *pszParmName, const char *pszParmValue)
1530 int parmnum = lpcfg_map_parameter(pszParmName);
1531 void *parm_ptr;
1533 if (parmnum < 0) {
1534 if (strchr(pszParmName, ':')) {
1535 return lp_do_parameter_parametric(lp_ctx, NULL, pszParmName, pszParmValue, 0);
1537 DEBUG(0, ("Ignoring unknown parameter \"%s\"\n", pszParmName));
1538 return true;
1541 /* if the flag has been set on the command line, then don't allow override,
1542 but don't report an error */
1543 if (lp_ctx->flags[parmnum] & FLAG_CMDLINE) {
1544 return true;
1547 parm_ptr = lpcfg_parm_ptr(lp_ctx, NULL, &parm_table[parmnum]);
1549 return set_variable(lp_ctx->globals, parmnum, parm_ptr,
1550 pszParmName, pszParmValue, lp_ctx, true);
1553 bool lpcfg_do_service_parameter(struct loadparm_context *lp_ctx,
1554 struct loadparm_service *service,
1555 const char *pszParmName, const char *pszParmValue)
1557 void *parm_ptr;
1558 int i;
1559 int parmnum = lpcfg_map_parameter(pszParmName);
1561 if (parmnum < 0) {
1562 if (strchr(pszParmName, ':')) {
1563 return lp_do_parameter_parametric(lp_ctx, service, pszParmName, pszParmValue, 0);
1565 DEBUG(0, ("Ignoring unknown parameter \"%s\"\n", pszParmName));
1566 return true;
1569 /* if the flag has been set on the command line, then don't allow override,
1570 but don't report an error */
1571 if (lp_ctx->flags[parmnum] & FLAG_CMDLINE) {
1572 return true;
1575 if (parm_table[parmnum].p_class == P_GLOBAL) {
1576 DEBUG(0,
1577 ("Global parameter %s found in service section!\n",
1578 pszParmName));
1579 return true;
1581 parm_ptr = ((char *)service) + parm_table[parmnum].offset;
1583 if (!service->copymap)
1584 init_copymap(service);
1586 /* this handles the aliases - set the copymap for other
1587 * entries with the same data pointer */
1588 for (i = 0; parm_table[i].label; i++)
1589 if (parm_table[i].offset == parm_table[parmnum].offset &&
1590 parm_table[i].p_class == parm_table[parmnum].p_class)
1591 bitmap_clear(service->copymap, i);
1593 return set_variable(service, parmnum, parm_ptr, pszParmName,
1594 pszParmValue, lp_ctx, false);
1598 * Process a parameter.
1601 static bool do_parameter(const char *pszParmName, const char *pszParmValue,
1602 void *userdata)
1604 struct loadparm_context *lp_ctx = (struct loadparm_context *)userdata;
1606 if (lp_ctx->bInGlobalSection)
1607 return lpcfg_do_global_parameter(lp_ctx, pszParmName,
1608 pszParmValue);
1609 else
1610 return lpcfg_do_service_parameter(lp_ctx, lp_ctx->currentService,
1611 pszParmName, pszParmValue);
1615 variable argument do parameter
1617 bool lpcfg_do_global_parameter_var(struct loadparm_context *lp_ctx, const char *pszParmName, const char *fmt, ...) PRINTF_ATTRIBUTE(3, 4);
1618 bool lpcfg_do_global_parameter_var(struct loadparm_context *lp_ctx,
1619 const char *pszParmName, const char *fmt, ...)
1621 char *s;
1622 bool ret;
1623 va_list ap;
1625 va_start(ap, fmt);
1626 s = talloc_vasprintf(NULL, fmt, ap);
1627 va_end(ap);
1628 ret = lpcfg_do_global_parameter(lp_ctx, pszParmName, s);
1629 talloc_free(s);
1630 return ret;
1635 set a parameter from the commandline - this is called from command line parameter
1636 parsing code. It sets the parameter then marks the parameter as unable to be modified
1637 by smb.conf processing
1639 bool lpcfg_set_cmdline(struct loadparm_context *lp_ctx, const char *pszParmName,
1640 const char *pszParmValue)
1642 int parmnum;
1643 int i;
1645 while (isspace((unsigned char)*pszParmValue)) pszParmValue++;
1647 if (lp_ctx->s3_fns) {
1648 return lp_ctx->s3_fns->set_cmdline(pszParmName, pszParmValue);
1651 parmnum = lpcfg_map_parameter(pszParmName);
1653 if (parmnum < 0 && strchr(pszParmName, ':')) {
1654 /* set a parametric option */
1655 return lp_do_parameter_parametric(lp_ctx, NULL, pszParmName,
1656 pszParmValue, FLAG_CMDLINE);
1659 if (parmnum < 0) {
1660 DEBUG(0,("Unknown option '%s'\n", pszParmName));
1661 return false;
1664 /* reset the CMDLINE flag in case this has been called before */
1665 lp_ctx->flags[parmnum] &= ~FLAG_CMDLINE;
1667 if (!lpcfg_do_global_parameter(lp_ctx, pszParmName, pszParmValue)) {
1668 return false;
1671 lp_ctx->flags[parmnum] |= FLAG_CMDLINE;
1673 /* we have to also set FLAG_CMDLINE on aliases */
1674 for (i=parmnum-1;
1675 i>=0 && parm_table[i].p_class == parm_table[parmnum].p_class &&
1676 parm_table[i].offset == parm_table[parmnum].offset;
1677 i--) {
1678 lp_ctx->flags[i] |= FLAG_CMDLINE;
1680 for (i=parmnum+1;
1681 i<NUMPARAMETERS &&
1682 parm_table[i].p_class == parm_table[parmnum].p_class &&
1683 parm_table[i].offset == parm_table[parmnum].offset;
1684 i++) {
1685 lp_ctx->flags[i] |= FLAG_CMDLINE;
1688 return true;
1692 set a option from the commandline in 'a=b' format. Use to support --option
1694 bool lpcfg_set_option(struct loadparm_context *lp_ctx, const char *option)
1696 char *p, *s;
1697 bool ret;
1699 s = talloc_strdup(NULL, option);
1700 if (!s) {
1701 return false;
1704 p = strchr(s, '=');
1705 if (!p) {
1706 talloc_free(s);
1707 return false;
1710 *p = 0;
1712 ret = lpcfg_set_cmdline(lp_ctx, s, p+1);
1713 talloc_free(s);
1714 return ret;
1718 #define BOOLSTR(b) ((b) ? "Yes" : "No")
1721 * Print a parameter of the specified type.
1724 void lpcfg_print_parameter(struct parm_struct *p, void *ptr, FILE * f)
1726 /* For the seperation of lists values that we print below */
1727 const char *list_sep = ", ";
1728 int i;
1729 switch (p->type)
1731 case P_ENUM:
1732 for (i = 0; p->enum_list[i].name; i++) {
1733 if (*(int *)ptr == p->enum_list[i].value) {
1734 fprintf(f, "%s",
1735 p->enum_list[i].name);
1736 break;
1739 break;
1741 case P_BOOL:
1742 fprintf(f, "%s", BOOLSTR(*(bool *)ptr));
1743 break;
1745 case P_BOOLREV:
1746 fprintf(f, "%s", BOOLSTR(!*(bool *)ptr));
1747 break;
1749 case P_INTEGER:
1750 case P_BYTES:
1751 fprintf(f, "%d", *(int *)ptr);
1752 break;
1754 case P_CHAR:
1755 fprintf(f, "%c", *(char *)ptr);
1756 break;
1758 case P_OCTAL: {
1759 int val = *(int *)ptr;
1760 if (val == -1) {
1761 fprintf(f, "-1");
1762 } else {
1763 fprintf(f, "0%03o", val);
1765 break;
1768 case P_CMDLIST:
1769 list_sep = " ";
1770 /* fall through */
1771 case P_LIST:
1772 if ((char ***)ptr && *(char ***)ptr) {
1773 char **list = *(char ***)ptr;
1774 for (; *list; list++) {
1775 /* surround strings with whitespace in double quotes */
1776 if (*(list+1) == NULL) {
1777 /* last item, no extra separator */
1778 list_sep = "";
1780 if ( strchr_m( *list, ' ' ) ) {
1781 fprintf(f, "\"%s\"%s", *list, list_sep);
1782 } else {
1783 fprintf(f, "%s%s", *list, list_sep);
1787 break;
1789 case P_STRING:
1790 case P_USTRING:
1791 if (*(char **)ptr) {
1792 fprintf(f, "%s", *(char **)ptr);
1794 break;
1795 case P_SEP:
1796 break;
1801 * Check if two parameters are equal.
1804 bool lpcfg_equal_parameter(parm_type type, void *ptr1, void *ptr2)
1806 switch (type) {
1807 case P_BOOL:
1808 case P_BOOLREV:
1809 return (*((bool *)ptr1) == *((bool *)ptr2));
1811 case P_INTEGER:
1812 case P_ENUM:
1813 case P_OCTAL:
1814 case P_BYTES:
1815 return (*((int *)ptr1) == *((int *)ptr2));
1817 case P_CHAR:
1818 return (*((char *)ptr1) == *((char *)ptr2));
1820 case P_LIST:
1821 case P_CMDLIST:
1822 return str_list_equal(*(const char ***)ptr1, *(const char ***)ptr2);
1824 case P_STRING:
1825 case P_USTRING:
1827 char *p1 = *(char **)ptr1, *p2 = *(char **)ptr2;
1828 if (p1 && !*p1)
1829 p1 = NULL;
1830 if (p2 && !*p2)
1831 p2 = NULL;
1832 return (p1 == p2 || strequal(p1, p2));
1834 case P_SEP:
1835 break;
1837 return false;
1841 * Process a new section (service).
1843 * At this stage all sections are services.
1844 * Later we'll have special sections that permit server parameters to be set.
1845 * Returns True on success, False on failure.
1848 static bool do_section(const char *pszSectionName, void *userdata)
1850 struct loadparm_context *lp_ctx = (struct loadparm_context *)userdata;
1851 bool bRetval;
1852 bool isglobal = ((strwicmp(pszSectionName, GLOBAL_NAME) == 0) ||
1853 (strwicmp(pszSectionName, GLOBAL_NAME2) == 0));
1854 bRetval = false;
1856 /* if we've just struck a global section, note the fact. */
1857 lp_ctx->bInGlobalSection = isglobal;
1859 /* check for multiple global sections */
1860 if (lp_ctx->bInGlobalSection) {
1861 DEBUG(4, ("Processing section \"[%s]\"\n", pszSectionName));
1862 return true;
1865 /* if we have a current service, tidy it up before moving on */
1866 bRetval = true;
1868 if (lp_ctx->currentService != NULL)
1869 bRetval = lpcfg_service_ok(lp_ctx->currentService);
1871 /* if all is still well, move to the next record in the services array */
1872 if (bRetval) {
1873 /* We put this here to avoid an odd message order if messages are */
1874 /* issued by the post-processing of a previous section. */
1875 DEBUG(4, ("Processing section \"[%s]\"\n", pszSectionName));
1877 if ((lp_ctx->currentService = lpcfg_add_service(lp_ctx, lp_ctx->sDefault,
1878 pszSectionName))
1879 == NULL) {
1880 DEBUG(0, ("Failed to add a new service\n"));
1881 return false;
1885 return bRetval;
1890 * Determine if a particular base parameter is currently set to the default value.
1893 static bool is_default(struct loadparm_service *sDefault, int i)
1895 void *def_ptr = ((char *)sDefault) + parm_table[i].offset;
1896 switch (parm_table[i].type) {
1897 case P_CMDLIST:
1898 case P_LIST:
1899 return str_list_equal((const char * const *)parm_table[i].def.lvalue,
1900 (const char **)def_ptr);
1901 case P_STRING:
1902 case P_USTRING:
1903 return strequal(parm_table[i].def.svalue,
1904 *(char **)def_ptr);
1905 case P_BOOL:
1906 case P_BOOLREV:
1907 return parm_table[i].def.bvalue ==
1908 *(bool *)def_ptr;
1909 case P_INTEGER:
1910 case P_CHAR:
1911 case P_OCTAL:
1912 case P_BYTES:
1913 case P_ENUM:
1914 return parm_table[i].def.ivalue ==
1915 *(int *)def_ptr;
1916 case P_SEP:
1917 break;
1919 return false;
1923 *Display the contents of the global structure.
1926 static void dump_globals(struct loadparm_context *lp_ctx, FILE *f,
1927 bool show_defaults)
1929 int i;
1930 struct parmlist_entry *data;
1932 fprintf(f, "# Global parameters\n[global]\n");
1934 for (i = 0; parm_table[i].label; i++)
1935 if (parm_table[i].p_class == P_GLOBAL &&
1936 (i == 0 || (parm_table[i].offset != parm_table[i - 1].offset))) {
1937 if (!show_defaults && (lp_ctx->flags[i] & FLAG_DEFAULT))
1938 continue;
1939 fprintf(f, "\t%s = ", parm_table[i].label);
1940 lpcfg_print_parameter(&parm_table[i], lpcfg_parm_ptr(lp_ctx, NULL, &parm_table[i]), f);
1941 fprintf(f, "\n");
1943 if (lp_ctx->globals->param_opt != NULL) {
1944 for (data = lp_ctx->globals->param_opt; data;
1945 data = data->next) {
1946 if (!show_defaults && (data->priority & FLAG_DEFAULT)) {
1947 continue;
1949 fprintf(f, "\t%s = %s\n", data->key, data->value);
1956 * Display the contents of a single services record.
1959 static void dump_a_service(struct loadparm_service * pService, struct loadparm_service *sDefault, FILE * f,
1960 unsigned int *flags)
1962 int i;
1963 struct parmlist_entry *data;
1965 if (pService != sDefault)
1966 fprintf(f, "\n[%s]\n", pService->szService);
1968 for (i = 0; parm_table[i].label; i++) {
1969 if (parm_table[i].p_class == P_LOCAL &&
1970 (*parm_table[i].label != '-') &&
1971 (i == 0 || (parm_table[i].offset != parm_table[i - 1].offset)))
1973 if (pService == sDefault) {
1974 if (flags && (flags[i] & FLAG_DEFAULT)) {
1975 continue;
1977 if (defaults_saved) {
1978 if (is_default(sDefault, i)) {
1979 continue;
1982 } else {
1983 if (lpcfg_equal_parameter(parm_table[i].type,
1984 ((char *)pService) +
1985 parm_table[i].offset,
1986 ((char *)sDefault) +
1987 parm_table[i].offset))
1988 continue;
1991 fprintf(f, "\t%s = ", parm_table[i].label);
1992 lpcfg_print_parameter(&parm_table[i],
1993 ((char *)pService) + parm_table[i].offset, f);
1994 fprintf(f, "\n");
1997 if (pService->param_opt != NULL) {
1998 for (data = pService->param_opt; data; data = data->next) {
1999 fprintf(f, "\t%s = %s\n", data->key, data->value);
2004 bool lpcfg_dump_a_parameter(struct loadparm_context *lp_ctx,
2005 struct loadparm_service *service,
2006 const char *parm_name, FILE * f)
2008 struct parm_struct *parm;
2009 void *ptr;
2011 parm = lpcfg_parm_struct(lp_ctx, parm_name);
2012 if (!parm) {
2013 return false;
2016 if (service != NULL && parm->p_class == P_GLOBAL) {
2017 return false;
2020 ptr = lpcfg_parm_ptr(lp_ctx, service,parm);
2022 lpcfg_print_parameter(parm, ptr, f);
2023 fprintf(f, "\n");
2024 return true;
2028 * Auto-load some home services.
2030 static void lpcfg_add_auto_services(struct loadparm_context *lp_ctx,
2031 const char *str)
2033 return;
2038 * Unload unused services.
2041 void lpcfg_killunused(struct loadparm_context *lp_ctx,
2042 struct smbsrv_connection *smb,
2043 bool (*snumused) (struct smbsrv_connection *, int))
2045 int i;
2046 for (i = 0; i < lp_ctx->iNumServices; i++) {
2047 if (lp_ctx->services[i] == NULL)
2048 continue;
2050 if (!snumused || !snumused(smb, i)) {
2051 talloc_free(lp_ctx->services[i]);
2052 lp_ctx->services[i] = NULL;
2058 static int lpcfg_destructor(struct loadparm_context *lp_ctx)
2060 struct parmlist_entry *data;
2062 if (lp_ctx->refuse_free) {
2063 /* someone is trying to free the
2064 global_loadparm_context.
2065 We can't allow that. */
2066 return -1;
2069 if (lp_ctx->globals->param_opt != NULL) {
2070 struct parmlist_entry *next;
2071 for (data = lp_ctx->globals->param_opt; data; data=next) {
2072 next = data->next;
2073 if (data->priority & FLAG_CMDLINE) continue;
2074 DLIST_REMOVE(lp_ctx->globals->param_opt, data);
2075 talloc_free(data);
2079 return 0;
2083 * Initialise the global parameter structure.
2085 * Note that most callers should use loadparm_init_global() instead
2087 struct loadparm_context *loadparm_init(TALLOC_CTX *mem_ctx)
2089 int i;
2090 char *myname;
2091 struct loadparm_context *lp_ctx;
2092 struct parmlist_entry *parm;
2093 char *logfile;
2095 lp_ctx = talloc_zero(mem_ctx, struct loadparm_context);
2096 if (lp_ctx == NULL)
2097 return NULL;
2099 talloc_set_destructor(lp_ctx, lpcfg_destructor);
2100 lp_ctx->bInGlobalSection = true;
2101 lp_ctx->globals = talloc_zero(lp_ctx, struct loadparm_global);
2102 /* This appears odd, but globals in s3 isn't a pointer */
2103 lp_ctx->globals->ctx = lp_ctx->globals;
2104 lp_ctx->sDefault = talloc_zero(lp_ctx, struct loadparm_service);
2105 lp_ctx->flags = talloc_zero_array(lp_ctx, unsigned int, NUMPARAMETERS);
2107 lp_ctx->sDefault->iMaxPrintJobs = 1000;
2108 lp_ctx->sDefault->bAvailable = true;
2109 lp_ctx->sDefault->browseable = true;
2110 lp_ctx->sDefault->read_only = true;
2111 lp_ctx->sDefault->map_archive = true;
2112 lp_ctx->sDefault->strict_locking = true;
2113 lp_ctx->sDefault->oplocks = true;
2114 lp_ctx->sDefault->create_mask = 0744;
2115 lp_ctx->sDefault->force_create_mode = 0000;
2116 lp_ctx->sDefault->directory_mask = 0755;
2117 lp_ctx->sDefault->force_directory_mode = 0000;
2119 DEBUG(3, ("Initialising global parameters\n"));
2121 for (i = 0; parm_table[i].label; i++) {
2122 if ((parm_table[i].type == P_STRING ||
2123 parm_table[i].type == P_USTRING) &&
2124 !(lp_ctx->flags[i] & FLAG_CMDLINE)) {
2125 char **r;
2126 if (parm_table[i].p_class == P_LOCAL) {
2127 r = (char **)(((char *)lp_ctx->sDefault) + parm_table[i].offset);
2128 } else {
2129 r = (char **)(((char *)lp_ctx->globals) + parm_table[i].offset);
2131 *r = talloc_strdup(lp_ctx, "");
2135 logfile = talloc_asprintf(lp_ctx, "%s/log.samba", dyn_LOGFILEBASE);
2136 lpcfg_do_global_parameter(lp_ctx, "log file", logfile);
2137 talloc_free(logfile);
2139 lpcfg_do_global_parameter(lp_ctx, "log level", "0");
2141 lpcfg_do_global_parameter(lp_ctx, "syslog", "1");
2142 lpcfg_do_global_parameter(lp_ctx, "syslog only", "No");
2143 lpcfg_do_global_parameter(lp_ctx, "debug timestamp", "Yes");
2144 lpcfg_do_global_parameter(lp_ctx, "debug prefix timestamp", "No");
2145 lpcfg_do_global_parameter(lp_ctx, "debug hires timestamp", "Yes");
2146 lpcfg_do_global_parameter(lp_ctx, "debug pid", "No");
2147 lpcfg_do_global_parameter(lp_ctx, "debug uid", "No");
2148 lpcfg_do_global_parameter(lp_ctx, "debug class", "No");
2150 lpcfg_do_global_parameter(lp_ctx, "share backend", "classic");
2152 lpcfg_do_global_parameter(lp_ctx, "server role", "auto");
2153 lpcfg_do_global_parameter(lp_ctx, "domain logons", "No");
2154 lpcfg_do_global_parameter(lp_ctx, "domain master", "Auto");
2156 /* options that can be set on the command line must be initialised via
2157 the slower lpcfg_do_global_parameter() to ensure that FLAG_CMDLINE is obeyed */
2158 #ifdef TCP_NODELAY
2159 lpcfg_do_global_parameter(lp_ctx, "socket options", "TCP_NODELAY");
2160 #endif
2161 lpcfg_do_global_parameter(lp_ctx, "workgroup", DEFAULT_WORKGROUP);
2162 myname = get_myname(lp_ctx);
2163 lpcfg_do_global_parameter(lp_ctx, "netbios name", myname);
2164 talloc_free(myname);
2165 lpcfg_do_global_parameter(lp_ctx, "name resolve order", "lmhosts wins host bcast");
2167 lpcfg_do_global_parameter(lp_ctx, "fstype", "NTFS");
2169 lpcfg_do_global_parameter(lp_ctx, "ntvfs handler", "unixuid default");
2170 lpcfg_do_global_parameter(lp_ctx, "max connections", "0");
2172 lpcfg_do_global_parameter(lp_ctx, "dcerpc endpoint servers", "epmapper wkssvc rpcecho samr netlogon lsarpc spoolss drsuapi dssetup unixinfo browser eventlog6 backupkey dnsserver");
2173 lpcfg_do_global_parameter(lp_ctx, "server services", "s3fs rpc nbt wrepl ldap cldap kdc drepl winbind ntp_signd kcc dnsupdate dns");
2174 lpcfg_do_global_parameter(lp_ctx, "kccsrv:samba_kcc", "true");
2175 /* the winbind method for domain controllers is for both RODC
2176 auth forwarding and for trusted domains */
2177 lpcfg_do_global_parameter(lp_ctx, "private dir", dyn_PRIVATE_DIR);
2178 lpcfg_do_global_parameter(lp_ctx, "registry:HKEY_LOCAL_MACHINE", "hklm.ldb");
2180 /* This hive should be dynamically generated by Samba using
2181 data from the sam, but for the moment leave it in a tdb to
2182 keep regedt32 from popping up an annoying dialog. */
2183 lpcfg_do_global_parameter(lp_ctx, "registry:HKEY_USERS", "hku.ldb");
2185 /* using UTF8 by default allows us to support all chars */
2186 lpcfg_do_global_parameter(lp_ctx, "unix charset", "UTF-8");
2188 /* Use codepage 850 as a default for the dos character set */
2189 lpcfg_do_global_parameter(lp_ctx, "dos charset", "CP850");
2192 * Allow the default PASSWD_CHAT to be overridden in local.h.
2194 lpcfg_do_global_parameter(lp_ctx, "passwd chat", DEFAULT_PASSWD_CHAT);
2196 lpcfg_do_global_parameter(lp_ctx, "pid directory", dyn_PIDDIR);
2197 lpcfg_do_global_parameter(lp_ctx, "lock dir", dyn_LOCKDIR);
2198 lpcfg_do_global_parameter(lp_ctx, "state directory", dyn_STATEDIR);
2199 lpcfg_do_global_parameter(lp_ctx, "cache directory", dyn_CACHEDIR);
2200 lpcfg_do_global_parameter(lp_ctx, "ncalrpc dir", dyn_NCALRPCDIR);
2202 lpcfg_do_global_parameter(lp_ctx, "nbt client socket address", "0.0.0.0");
2203 lpcfg_do_global_parameter_var(lp_ctx, "server string",
2204 "Samba %s", SAMBA_VERSION_STRING);
2206 lpcfg_do_global_parameter(lp_ctx, "password server", "*");
2208 lpcfg_do_global_parameter(lp_ctx, "max mux", "50");
2209 lpcfg_do_global_parameter(lp_ctx, "max xmit", "16644");
2210 lpcfg_do_global_parameter(lp_ctx, "host msdfs", "true");
2212 lpcfg_do_global_parameter(lp_ctx, "LargeReadwrite", "True");
2213 lpcfg_do_global_parameter(lp_ctx, "server min protocol", "LANMAN1");
2214 lpcfg_do_global_parameter(lp_ctx, "server max protocol", "SMB3");
2215 lpcfg_do_global_parameter(lp_ctx, "client min protocol", "CORE");
2216 lpcfg_do_global_parameter(lp_ctx, "client max protocol", "NT1");
2217 lpcfg_do_global_parameter(lp_ctx, "security", "AUTO");
2218 lpcfg_do_global_parameter(lp_ctx, "EncryptPasswords", "True");
2219 lpcfg_do_global_parameter(lp_ctx, "ReadRaw", "True");
2220 lpcfg_do_global_parameter(lp_ctx, "WriteRaw", "True");
2221 lpcfg_do_global_parameter(lp_ctx, "NullPasswords", "False");
2222 lpcfg_do_global_parameter(lp_ctx, "old password allowed period", "60");
2223 lpcfg_do_global_parameter(lp_ctx, "ObeyPamRestrictions", "False");
2225 lpcfg_do_global_parameter(lp_ctx, "TimeServer", "False");
2226 lpcfg_do_global_parameter(lp_ctx, "BindInterfacesOnly", "False");
2227 lpcfg_do_global_parameter(lp_ctx, "Unicode", "True");
2228 lpcfg_do_global_parameter(lp_ctx, "ClientLanManAuth", "False");
2229 lpcfg_do_global_parameter(lp_ctx, "ClientNTLMv2Auth", "True");
2230 lpcfg_do_global_parameter(lp_ctx, "LanmanAuth", "False");
2231 lpcfg_do_global_parameter(lp_ctx, "NTLMAuth", "True");
2232 lpcfg_do_global_parameter(lp_ctx, "client use spnego principal", "False");
2234 lpcfg_do_global_parameter(lp_ctx, "UnixExtensions", "True");
2236 lpcfg_do_global_parameter(lp_ctx, "PreferredMaster", "Auto");
2237 lpcfg_do_global_parameter(lp_ctx, "LocalMaster", "True");
2239 lpcfg_do_global_parameter(lp_ctx, "wins support", "False");
2240 lpcfg_do_global_parameter(lp_ctx, "dns proxy", "True");
2242 lpcfg_do_global_parameter(lp_ctx, "winbind separator", "\\");
2243 lpcfg_do_global_parameter(lp_ctx, "winbind sealed pipes", "True");
2244 lpcfg_do_global_parameter(lp_ctx, "require strong key", "True");
2245 lpcfg_do_global_parameter(lp_ctx, "winbindd socket directory", dyn_WINBINDD_SOCKET_DIR);
2246 lpcfg_do_global_parameter(lp_ctx, "winbindd privileged socket directory", dyn_WINBINDD_PRIVILEGED_SOCKET_DIR);
2247 lpcfg_do_global_parameter(lp_ctx, "ntp signd socket directory", dyn_NTP_SIGND_SOCKET_DIR);
2248 lpcfg_do_global_parameter_var(lp_ctx, "dns update command", "%s/samba_dnsupdate", dyn_SCRIPTSBINDIR);
2249 lpcfg_do_global_parameter_var(lp_ctx, "spn update command", "%s/samba_spnupdate", dyn_SCRIPTSBINDIR);
2250 lpcfg_do_global_parameter_var(lp_ctx, "samba kcc command",
2251 "%s/samba_kcc", dyn_SCRIPTSBINDIR);
2252 lpcfg_do_global_parameter(lp_ctx, "template shell", "/bin/false");
2253 lpcfg_do_global_parameter(lp_ctx, "template homedir", "/home/%WORKGROUP%/%ACCOUNTNAME%");
2255 lpcfg_do_global_parameter(lp_ctx, "client signing", "default");
2256 lpcfg_do_global_parameter(lp_ctx, "server signing", "default");
2258 lpcfg_do_global_parameter(lp_ctx, "use spnego", "True");
2260 lpcfg_do_global_parameter(lp_ctx, "use mmap", "True");
2262 lpcfg_do_global_parameter(lp_ctx, "smb ports", "445 139");
2263 lpcfg_do_global_parameter(lp_ctx, "nbt port", "137");
2264 lpcfg_do_global_parameter(lp_ctx, "dgram port", "138");
2265 lpcfg_do_global_parameter(lp_ctx, "cldap port", "389");
2266 lpcfg_do_global_parameter(lp_ctx, "krb5 port", "88");
2267 lpcfg_do_global_parameter(lp_ctx, "kpasswd port", "464");
2268 lpcfg_do_global_parameter(lp_ctx, "web port", "901");
2270 lpcfg_do_global_parameter(lp_ctx, "nt status support", "True");
2272 lpcfg_do_global_parameter(lp_ctx, "max wins ttl", "518400"); /* 6 days */
2273 lpcfg_do_global_parameter(lp_ctx, "min wins ttl", "21600");
2275 lpcfg_do_global_parameter(lp_ctx, "tls enabled", "True");
2276 lpcfg_do_global_parameter(lp_ctx, "tls keyfile", "tls/key.pem");
2277 lpcfg_do_global_parameter(lp_ctx, "tls certfile", "tls/cert.pem");
2278 lpcfg_do_global_parameter(lp_ctx, "tls cafile", "tls/ca.pem");
2279 lpcfg_do_global_parameter(lp_ctx, "prefork children:smb", "4");
2281 lpcfg_do_global_parameter(lp_ctx, "rndc command", "/usr/sbin/rndc");
2282 lpcfg_do_global_parameter(lp_ctx, "nsupdate command", "/usr/bin/nsupdate -g");
2284 lpcfg_do_global_parameter(lp_ctx, "allow dns updates", "secure only");
2285 lpcfg_do_global_parameter(lp_ctx, "dns forwarder", "");
2287 lpcfg_do_global_parameter(lp_ctx, "algorithmic rid base", "1000");
2289 lpcfg_do_global_parameter(lp_ctx, "enhanced browsing", "True");
2291 lpcfg_do_global_parameter(lp_ctx, "winbind nss info", "template");
2293 lpcfg_do_global_parameter(lp_ctx, "server schannel", "Auto");
2295 lpcfg_do_global_parameter(lp_ctx, "short preserve case", "True");
2297 lpcfg_do_global_parameter(lp_ctx, "max open files", "16384");
2299 lpcfg_do_global_parameter(lp_ctx, "cups connection timeout", "30");
2301 lpcfg_do_global_parameter(lp_ctx, "locking", "True");
2303 lpcfg_do_global_parameter(lp_ctx, "block size", "1024");
2305 lpcfg_do_global_parameter(lp_ctx, "client use spnego", "True");
2307 lpcfg_do_global_parameter(lp_ctx, "change notify", "True");
2309 lpcfg_do_global_parameter(lp_ctx, "name cache timeout", "660");
2311 lpcfg_do_global_parameter(lp_ctx, "defer sharing violations", "True");
2313 lpcfg_do_global_parameter(lp_ctx, "ldap replication sleep", "1000");
2315 lpcfg_do_global_parameter(lp_ctx, "idmap backend", "tdb");
2317 lpcfg_do_global_parameter(lp_ctx, "enable privileges", "True");
2319 lpcfg_do_global_parameter_var(lp_ctx, "smb2 max write", "%u", DEFAULT_SMB2_MAX_WRITE);
2321 lpcfg_do_global_parameter(lp_ctx, "passdb backend", "tdbsam");
2323 lpcfg_do_global_parameter(lp_ctx, "getwd cache", "True");
2325 lpcfg_do_global_parameter(lp_ctx, "winbind nested groups", "True");
2327 lpcfg_do_global_parameter(lp_ctx, "mangled names", "True");
2329 lpcfg_do_global_parameter_var(lp_ctx, "smb2 max credits", "%u", DEFAULT_SMB2_MAX_CREDITS);
2331 lpcfg_do_global_parameter(lp_ctx, "ldap ssl", "start tls");
2333 lpcfg_do_global_parameter(lp_ctx, "ldap deref", "auto");
2335 lpcfg_do_global_parameter(lp_ctx, "lm interval", "60");
2337 lpcfg_do_global_parameter(lp_ctx, "mangling method", "hash2");
2339 lpcfg_do_global_parameter(lp_ctx, "hide dot files", "True");
2341 lpcfg_do_global_parameter(lp_ctx, "browse list", "True");
2343 lpcfg_do_global_parameter(lp_ctx, "passwd chat timeout", "2");
2345 lpcfg_do_global_parameter(lp_ctx, "guest account", GUEST_ACCOUNT);
2347 lpcfg_do_global_parameter(lp_ctx, "client schannel", "auto");
2349 lpcfg_do_global_parameter(lp_ctx, "smb encrypt", "default");
2351 lpcfg_do_global_parameter(lp_ctx, "max log size", "5000");
2353 lpcfg_do_global_parameter(lp_ctx, "idmap negative cache time", "120");
2355 lpcfg_do_global_parameter(lp_ctx, "ldap follow referral", "auto");
2357 lpcfg_do_global_parameter(lp_ctx, "multicast dns register", "yes");
2359 lpcfg_do_global_parameter(lp_ctx, "winbind reconnect delay", "30");
2361 lpcfg_do_global_parameter(lp_ctx, "nt acl support", "yes");
2363 lpcfg_do_global_parameter(lp_ctx, "acl check permissions", "yes");
2365 lpcfg_do_global_parameter(lp_ctx, "keepalive", "300");
2367 lpcfg_do_global_parameter(lp_ctx, "winbind cache time", "300");
2369 lpcfg_do_global_parameter(lp_ctx, "level2 oplocks", "yes");
2371 lpcfg_do_global_parameter(lp_ctx, "show add printer wizard", "yes");
2373 lpcfg_do_global_parameter(lp_ctx, "allocation roundup size", "1048576");
2375 lpcfg_do_global_parameter(lp_ctx, "ldap page size", "1024");
2377 lpcfg_do_global_parameter(lp_ctx, "kernel share modes", "yes");
2379 lpcfg_do_global_parameter(lp_ctx, "strict locking", "Auto");
2381 lpcfg_do_global_parameter(lp_ctx, "map readonly", "yes");
2383 lpcfg_do_global_parameter(lp_ctx, "allow trusted domains", "yes");
2385 lpcfg_do_global_parameter(lp_ctx, "default devmode", "yes");
2387 lpcfg_do_global_parameter(lp_ctx, "os level", "20");
2389 lpcfg_do_global_parameter(lp_ctx, "dos filetimes", "yes");
2391 lpcfg_do_global_parameter(lp_ctx, "mangling char", "~");
2393 lpcfg_do_global_parameter(lp_ctx, "printcap cache time", "750");
2395 lpcfg_do_global_parameter(lp_ctx, "create krb5 conf", "yes");
2397 lpcfg_do_global_parameter(lp_ctx, "winbind max clients", "200");
2399 lpcfg_do_global_parameter(lp_ctx, "acl map full control", "yes");
2401 lpcfg_do_global_parameter(lp_ctx, "nt pipe support", "yes");
2403 lpcfg_do_global_parameter(lp_ctx, "ldap debug threshold", "10");
2405 lpcfg_do_global_parameter(lp_ctx, "follow symlinks", "yes");
2407 lpcfg_do_global_parameter(lp_ctx, "machine password timeout", "604800");
2409 lpcfg_do_global_parameter(lp_ctx, "ldap connection timeout", "2");
2411 lpcfg_do_global_parameter(lp_ctx, "winbind expand groups", "1");
2413 lpcfg_do_global_parameter(lp_ctx, "stat cache", "yes");
2415 lpcfg_do_global_parameter(lp_ctx, "lpq cache time", "30");
2417 lpcfg_do_global_parameter_var(lp_ctx, "smb2 max trans", "%u", DEFAULT_SMB2_MAX_TRANSACT);
2419 lpcfg_do_global_parameter_var(lp_ctx, "smb2 max read", "%u", DEFAULT_SMB2_MAX_READ);
2421 lpcfg_do_global_parameter(lp_ctx, "durable handles", "yes");
2423 lpcfg_do_global_parameter(lp_ctx, "max stat cache size", "256");
2425 lpcfg_do_global_parameter(lp_ctx, "ldap passwd sync", "no");
2427 lpcfg_do_global_parameter(lp_ctx, "kernel change notify", "yes");
2429 lpcfg_do_global_parameter(lp_ctx, "max ttl", "259200");
2431 lpcfg_do_global_parameter(lp_ctx, "blocking locks", "yes");
2433 lpcfg_do_global_parameter(lp_ctx, "oplock contention limit", "2");
2435 lpcfg_do_global_parameter(lp_ctx, "load printers", "yes");
2437 lpcfg_do_global_parameter(lp_ctx, "idmap cache time", "604800");
2439 lpcfg_do_global_parameter(lp_ctx, "preserve case", "yes");
2441 lpcfg_do_global_parameter(lp_ctx, "lm announce", "auto");
2443 lpcfg_do_global_parameter(lp_ctx, "afs token lifetime", "604800");
2445 lpcfg_do_global_parameter(lp_ctx, "enable core files", "yes");
2447 lpcfg_do_global_parameter(lp_ctx, "winbind max domain connections", "1");
2449 lpcfg_do_global_parameter(lp_ctx, "case sensitive", "auto");
2451 lpcfg_do_global_parameter(lp_ctx, "ldap timeout", "15");
2453 lpcfg_do_global_parameter(lp_ctx, "mangle prefix", "1");
2455 lpcfg_do_global_parameter(lp_ctx, "posix locking", "yes");
2457 lpcfg_do_global_parameter(lp_ctx, "lock spin time", "200");
2459 lpcfg_do_global_parameter(lp_ctx, "directory name cache size", "100");
2461 lpcfg_do_global_parameter(lp_ctx, "nmbd bind explicit broadcast", "yes");
2463 lpcfg_do_global_parameter(lp_ctx, "init logon delay", "100");
2465 lpcfg_do_global_parameter(lp_ctx, "usershare owner only", "yes");
2467 lpcfg_do_global_parameter(lp_ctx, "-valid", "yes");
2469 lpcfg_do_global_parameter_var(lp_ctx, "usershare path", "%s/usershares", get_dyn_STATEDIR());
2471 #ifdef DEVELOPER
2472 lpcfg_do_global_parameter_var(lp_ctx, "panic action", "/bin/sleep 999999999");
2473 #endif
2475 lpcfg_do_global_parameter(lp_ctx, "smb passwd file", get_dyn_SMB_PASSWD_FILE());
2477 lpcfg_do_global_parameter(lp_ctx, "logon home", "\\\\%N\\%U");
2479 lpcfg_do_global_parameter(lp_ctx, "logon path", "\\\\%N\\%U\\profile");
2481 lpcfg_do_global_parameter(lp_ctx, "printjob username", "%U");
2483 for (i = 0; parm_table[i].label; i++) {
2484 if (!(lp_ctx->flags[i] & FLAG_CMDLINE)) {
2485 lp_ctx->flags[i] |= FLAG_DEFAULT;
2489 for (parm=lp_ctx->globals->param_opt; parm; parm=parm->next) {
2490 if (!(parm->priority & FLAG_CMDLINE)) {
2491 parm->priority |= FLAG_DEFAULT;
2495 return lp_ctx;
2499 * Initialise the global parameter structure.
2501 struct loadparm_context *loadparm_init_global(bool load_default)
2503 if (global_loadparm_context == NULL) {
2504 global_loadparm_context = loadparm_init(NULL);
2506 if (global_loadparm_context == NULL) {
2507 return NULL;
2509 global_loadparm_context->global = true;
2510 if (load_default && !global_loadparm_context->loaded) {
2511 lpcfg_load_default(global_loadparm_context);
2513 global_loadparm_context->refuse_free = true;
2514 return global_loadparm_context;
2518 * Initialise the global parameter structure.
2520 struct loadparm_context *loadparm_init_s3(TALLOC_CTX *mem_ctx,
2521 const struct loadparm_s3_helpers *s3_fns)
2523 struct loadparm_context *loadparm_context = talloc_zero(mem_ctx, struct loadparm_context);
2524 if (!loadparm_context) {
2525 return NULL;
2527 loadparm_context->s3_fns = s3_fns;
2528 loadparm_context->globals = s3_fns->globals;
2529 return loadparm_context;
2532 const char *lpcfg_configfile(struct loadparm_context *lp_ctx)
2534 return lp_ctx->szConfigFile;
2537 const char *lp_default_path(void)
2539 if (getenv("SMB_CONF_PATH"))
2540 return getenv("SMB_CONF_PATH");
2541 else
2542 return dyn_CONFIGFILE;
2546 * Update the internal state of a loadparm context after settings
2547 * have changed.
2549 static bool lpcfg_update(struct loadparm_context *lp_ctx)
2551 struct debug_settings settings;
2552 TALLOC_CTX *tmp_ctx;
2554 tmp_ctx = talloc_new(lp_ctx);
2555 if (tmp_ctx == NULL) {
2556 return false;
2559 lpcfg_add_auto_services(lp_ctx, lpcfg_auto_services(lp_ctx, tmp_ctx));
2561 if (!lp_ctx->globals->wins_server_list && lp_ctx->globals->we_are_a_wins_server) {
2562 lpcfg_do_global_parameter(lp_ctx, "wins server", "127.0.0.1");
2565 if (!lp_ctx->global) {
2566 TALLOC_FREE(tmp_ctx);
2567 return true;
2570 panic_action = lp_ctx->globals->panic_action;
2572 reload_charcnv(lp_ctx);
2574 ZERO_STRUCT(settings);
2575 /* Add any more debug-related smb.conf parameters created in
2576 * future here */
2577 settings.syslog = lp_ctx->globals->syslog;
2578 settings.syslog_only = lp_ctx->globals->syslog_only;
2579 settings.timestamp_logs = lp_ctx->globals->timestamp_logs;
2580 settings.debug_prefix_timestamp = lp_ctx->globals->debug_prefix_timestamp;
2581 settings.debug_hires_timestamp = lp_ctx->globals->debug_hires_timestamp;
2582 settings.debug_pid = lp_ctx->globals->debug_pid;
2583 settings.debug_uid = lp_ctx->globals->debug_uid;
2584 settings.debug_class = lp_ctx->globals->debug_class;
2585 debug_set_settings(&settings);
2587 /* FIXME: This is a bit of a hack, but we can't use a global, since
2588 * not everything that uses lp also uses the socket library */
2589 if (lpcfg_parm_bool(lp_ctx, NULL, "socket", "testnonblock", false)) {
2590 setenv("SOCKET_TESTNONBLOCK", "1", 1);
2591 } else {
2592 unsetenv("SOCKET_TESTNONBLOCK");
2595 TALLOC_FREE(tmp_ctx);
2596 return true;
2599 bool lpcfg_load_default(struct loadparm_context *lp_ctx)
2601 const char *path;
2603 path = lp_default_path();
2605 if (!file_exist(path)) {
2606 /* We allow the default smb.conf file to not exist,
2607 * basically the equivalent of an empty file. */
2608 return lpcfg_update(lp_ctx);
2611 return lpcfg_load(lp_ctx, path);
2615 * Load the services array from the services file.
2617 * Return True on success, False on failure.
2619 bool lpcfg_load(struct loadparm_context *lp_ctx, const char *filename)
2621 char *n2;
2622 bool bRetval;
2624 filename = talloc_strdup(lp_ctx, filename);
2626 lp_ctx->szConfigFile = filename;
2628 if (lp_ctx->s3_fns) {
2629 return lp_ctx->s3_fns->load(filename);
2632 lp_ctx->bInGlobalSection = true;
2633 n2 = standard_sub_basic(lp_ctx, lp_ctx->szConfigFile);
2634 DEBUG(2, ("lpcfg_load: refreshing parameters from %s\n", n2));
2636 add_to_file_list(lp_ctx, &lp_ctx->file_lists, lp_ctx->szConfigFile, n2);
2638 /* We get sections first, so have to start 'behind' to make up */
2639 lp_ctx->currentService = NULL;
2640 bRetval = pm_process(n2, do_section, do_parameter, lp_ctx);
2642 /* finish up the last section */
2643 DEBUG(4, ("pm_process() returned %s\n", BOOLSTR(bRetval)));
2644 if (bRetval)
2645 if (lp_ctx->currentService != NULL)
2646 bRetval = lpcfg_service_ok(lp_ctx->currentService);
2648 bRetval = bRetval && lpcfg_update(lp_ctx);
2650 /* we do this unconditionally, so that it happens even
2651 for a missing smb.conf */
2652 reload_charcnv(lp_ctx);
2654 if (bRetval == true) {
2655 /* set this up so that any child python tasks will
2656 find the right smb.conf */
2657 setenv("SMB_CONF_PATH", filename, 1);
2659 /* set the context used by the lp_*() function
2660 varients */
2661 global_loadparm_context = lp_ctx;
2662 lp_ctx->loaded = true;
2665 return bRetval;
2669 * Return the max number of services.
2672 int lpcfg_numservices(struct loadparm_context *lp_ctx)
2674 if (lp_ctx->s3_fns) {
2675 return lp_ctx->s3_fns->get_numservices();
2678 return lp_ctx->iNumServices;
2682 * Display the contents of the services array in human-readable form.
2685 void lpcfg_dump(struct loadparm_context *lp_ctx, FILE *f, bool show_defaults,
2686 int maxtoprint)
2688 int iService;
2690 if (lp_ctx->s3_fns) {
2691 lp_ctx->s3_fns->dump(f, show_defaults, maxtoprint);
2692 return;
2695 defaults_saved = !show_defaults;
2697 dump_globals(lp_ctx, f, show_defaults);
2699 dump_a_service(lp_ctx->sDefault, lp_ctx->sDefault, f, lp_ctx->flags);
2701 for (iService = 0; iService < maxtoprint; iService++)
2702 lpcfg_dump_one(f, show_defaults, lp_ctx->services[iService], lp_ctx->sDefault);
2706 * Display the contents of one service in human-readable form.
2708 void lpcfg_dump_one(FILE *f, bool show_defaults, struct loadparm_service *service, struct loadparm_service *sDefault)
2710 if (service != NULL) {
2711 if (service->szService[0] == '\0')
2712 return;
2713 dump_a_service(service, sDefault, f, NULL);
2717 struct loadparm_service *lpcfg_servicebynum(struct loadparm_context *lp_ctx,
2718 int snum)
2720 if (lp_ctx->s3_fns) {
2721 return lp_ctx->s3_fns->get_servicebynum(snum);
2724 return lp_ctx->services[snum];
2727 struct loadparm_service *lpcfg_service(struct loadparm_context *lp_ctx,
2728 const char *service_name)
2730 int iService;
2731 char *serviceName;
2733 if (lp_ctx->s3_fns) {
2734 return lp_ctx->s3_fns->get_service(service_name);
2737 for (iService = lp_ctx->iNumServices - 1; iService >= 0; iService--) {
2738 if (lp_ctx->services[iService] &&
2739 lp_ctx->services[iService]->szService) {
2741 * The substitution here is used to support %U is
2742 * service names
2744 serviceName = standard_sub_basic(
2745 lp_ctx->services[iService],
2746 lp_ctx->services[iService]->szService);
2747 if (strequal(serviceName, service_name)) {
2748 talloc_free(serviceName);
2749 return lp_ctx->services[iService];
2751 talloc_free(serviceName);
2755 DEBUG(7,("lpcfg_servicenumber: couldn't find %s\n", service_name));
2756 return NULL;
2759 const char *lpcfg_servicename(const struct loadparm_service *service)
2761 return lpcfg_string((const char *)service->szService);
2765 * A useful volume label function.
2767 const char *lpcfg_volume_label(struct loadparm_service *service, struct loadparm_service *sDefault)
2769 const char *ret;
2770 ret = lpcfg_string((const char *)((service != NULL && service->volume != NULL) ?
2771 service->volume : sDefault->volume));
2772 if (!*ret)
2773 return lpcfg_servicename(service);
2774 return ret;
2778 * Return the correct printer name.
2780 const char *lpcfg_printername(struct loadparm_service *service, struct loadparm_service *sDefault)
2782 const char *ret;
2783 ret = lpcfg_string((const char *)((service != NULL && service->_printername != NULL) ?
2784 service->_printername : sDefault->_printername));
2785 if (ret == NULL || (ret != NULL && *ret == '\0'))
2786 ret = lpcfg_servicename(service);
2788 return ret;
2793 * Return the max print jobs per queue.
2795 int lpcfg_maxprintjobs(struct loadparm_service *service, struct loadparm_service *sDefault)
2797 int maxjobs = (service != NULL) ? service->iMaxPrintJobs : sDefault->iMaxPrintJobs;
2798 if (maxjobs <= 0 || maxjobs >= PRINT_MAX_JOBID)
2799 maxjobs = PRINT_MAX_JOBID - 1;
2801 return maxjobs;
2804 struct smb_iconv_handle *lpcfg_iconv_handle(struct loadparm_context *lp_ctx)
2806 if (lp_ctx == NULL) {
2807 return get_iconv_handle();
2809 return lp_ctx->iconv_handle;
2812 _PUBLIC_ void reload_charcnv(struct loadparm_context *lp_ctx)
2814 struct smb_iconv_handle *old_ic = lp_ctx->iconv_handle;
2815 if (!lp_ctx->global) {
2816 return;
2819 if (old_ic == NULL) {
2820 old_ic = global_iconv_handle;
2822 lp_ctx->iconv_handle = smb_iconv_handle_reinit_lp(lp_ctx, lp_ctx, old_ic);
2823 global_iconv_handle = lp_ctx->iconv_handle;
2826 _PUBLIC_ char *lpcfg_tls_keyfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
2828 return lpcfg_private_path(mem_ctx, lp_ctx, lpcfg__tls_keyfile(lp_ctx));
2831 _PUBLIC_ char *lpcfg_tls_certfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
2833 return lpcfg_private_path(mem_ctx, lp_ctx, lpcfg__tls_certfile(lp_ctx));
2836 _PUBLIC_ char *lpcfg_tls_cafile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
2838 return lpcfg_private_path(mem_ctx, lp_ctx, lpcfg__tls_cafile(lp_ctx));
2841 _PUBLIC_ char *lpcfg_tls_crlfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
2843 return lpcfg_private_path(mem_ctx, lp_ctx, lpcfg__tls_crlfile(lp_ctx));
2846 _PUBLIC_ char *lpcfg_tls_dhpfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
2848 return lpcfg_private_path(mem_ctx, lp_ctx, lpcfg__tls_dhpfile(lp_ctx));
2851 struct gensec_settings *lpcfg_gensec_settings(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
2853 struct gensec_settings *settings = talloc_zero(mem_ctx, struct gensec_settings);
2854 if (settings == NULL)
2855 return NULL;
2856 SMB_ASSERT(lp_ctx != NULL);
2857 settings->lp_ctx = talloc_reference(settings, lp_ctx);
2858 settings->target_hostname = lpcfg_parm_string(lp_ctx, NULL, "gensec", "target_hostname");
2859 return settings;
2862 int lpcfg_server_role(struct loadparm_context *lp_ctx)
2864 int domain_master = lpcfg__domain_master(lp_ctx);
2866 return lp_find_server_role(lpcfg__server_role(lp_ctx),
2867 lpcfg__security(lp_ctx),
2868 lpcfg__domain_logons(lp_ctx),
2869 (domain_master == true) ||
2870 (domain_master == Auto));
2873 int lpcfg_security(struct loadparm_context *lp_ctx)
2875 return lp_find_security(lpcfg__server_role(lp_ctx),
2876 lpcfg__security(lp_ctx));
2879 bool lpcfg_server_signing_allowed(struct loadparm_context *lp_ctx, bool *mandatory)
2881 bool allowed = true;
2882 enum smb_signing_setting signing_setting = lpcfg_server_signing(lp_ctx);
2884 *mandatory = false;
2886 if (signing_setting == SMB_SIGNING_DEFAULT) {
2888 * If we are a domain controller, SMB signing is
2889 * really important, as it can prevent a number of
2890 * attacks on communications between us and the
2891 * clients
2893 * However, it really sucks (no sendfile, CPU
2894 * overhead) performance-wise when used on a
2895 * file server, so disable it by default
2896 * on non-DCs
2899 if (lpcfg_server_role(lp_ctx) >= ROLE_ACTIVE_DIRECTORY_DC) {
2900 signing_setting = SMB_SIGNING_REQUIRED;
2901 } else {
2902 signing_setting = SMB_SIGNING_OFF;
2906 switch (signing_setting) {
2907 case SMB_SIGNING_REQUIRED:
2908 *mandatory = true;
2909 break;
2910 case SMB_SIGNING_IF_REQUIRED:
2911 break;
2912 case SMB_SIGNING_DEFAULT:
2913 case SMB_SIGNING_OFF:
2914 allowed = false;
2915 break;
2918 return allowed;
2921 int lpcfg_tdb_hash_size(struct loadparm_context *lp_ctx, const char *name)
2923 const char *base;
2925 if (name == NULL) {
2926 return 0;
2929 base = strrchr_m(name, '/');
2930 if (base != NULL) {
2931 base += 1;
2932 } else {
2933 base = name;
2935 return lpcfg_parm_int(lp_ctx, NULL, "tdb_hashsize", base, 0);
2939 int lpcfg_tdb_flags(struct loadparm_context *lp_ctx, int tdb_flags)
2941 if (!lpcfg_use_mmap(lp_ctx)) {
2942 tdb_flags |= TDB_NOMMAP;
2944 return tdb_flags;