param: setup ctx variable in loadparm globals
[Samba.git] / lib / param / loadparm.c
blob71aab15a93ae10aa90d721b34f0ef6289ddbaec3
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 /* these are parameter handlers which are not needed in the
81 * non-source3 code
83 #define handle_netbios_aliases NULL
84 #define handle_idmap_backend NULL
85 #define handle_idmap_uid NULL
86 #define handle_idmap_gid NULL
88 #ifndef N_
89 #define N_(x) x
90 #endif
92 #include "lib/param/param_table.c"
94 struct loadparm_service *lpcfg_default_service(struct loadparm_context *lp_ctx)
96 if (lp_ctx->s3_fns) {
97 return lp_ctx->s3_fns->get_default_loadparm_service();
99 return lp_ctx->sDefault;
103 * Convenience routine to grab string parameters into temporary memory
104 * and run standard_sub_basic on them.
106 * The buffers can be written to by
107 * callers without affecting the source string.
110 static const char *lpcfg_string(const char *s)
112 #if 0 /* until REWRITE done to make thread-safe */
113 size_t len = s ? strlen(s) : 0;
114 char *ret;
115 #endif
117 /* The follow debug is useful for tracking down memory problems
118 especially if you have an inner loop that is calling a lp_*()
119 function that returns a string. Perhaps this debug should be
120 present all the time? */
122 #if 0
123 DEBUG(10, ("lpcfg_string(%s)\n", s));
124 #endif
126 #if 0 /* until REWRITE done to make thread-safe */
127 if (!lp_talloc)
128 lp_talloc = talloc_init("lp_talloc");
130 ret = talloc_array(lp_talloc, char, len + 100); /* leave room for substitution */
132 if (!ret)
133 return NULL;
135 if (!s)
136 *ret = 0;
137 else
138 strlcpy(ret, s, len);
140 if (trim_string(ret, "\"", "\"")) {
141 if (strchr(ret,'"') != NULL)
142 strlcpy(ret, s, len);
145 standard_sub_basic(ret,len+100);
146 return (ret);
147 #endif
148 return s;
152 In this section all the functions that are used to access the
153 parameters from the rest of the program are defined
157 * the creation of separate lpcfg_*() and lp_*() functions is to allow
158 * for code compatibility between existing Samba4 and Samba3 code.
161 /* this global context supports the lp_*() function varients */
162 static struct loadparm_context *global_loadparm_context;
164 #define lpcfg_default_service global_loadparm_context->sDefault
165 #define lpcfg_global_service(i) global_loadparm_context->services[i]
167 #define FN_GLOBAL_STRING(fn_name,var_name) \
168 _PUBLIC_ char *lpcfg_ ## fn_name(struct loadparm_context *lp_ctx, TALLOC_CTX *ctx) {\
169 if (lp_ctx == NULL) return NULL; \
170 if (lp_ctx->s3_fns) { \
171 return lp_ctx->globals->var_name ? lp_ctx->s3_fns->lp_string(ctx, lp_ctx->globals->var_name) : talloc_strdup(ctx, ""); \
173 return lp_ctx->globals->var_name ? talloc_strdup(ctx, lpcfg_string(lp_ctx->globals->var_name)) : talloc_strdup(ctx, ""); \
176 #define FN_GLOBAL_CONST_STRING(fn_name,var_name) \
177 _PUBLIC_ const char *lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) { \
178 if (lp_ctx == NULL) return NULL; \
179 return lp_ctx->globals->var_name ? lpcfg_string(lp_ctx->globals->var_name) : ""; \
182 #define FN_GLOBAL_LIST(fn_name,var_name) \
183 _PUBLIC_ const char **lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) { \
184 if (lp_ctx == NULL) return NULL; \
185 return lp_ctx->globals->var_name; \
188 #define FN_GLOBAL_BOOL(fn_name,var_name) \
189 _PUBLIC_ bool lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) {\
190 if (lp_ctx == NULL) return false; \
191 return lp_ctx->globals->var_name; \
194 #define FN_GLOBAL_INTEGER(fn_name,var_name) \
195 _PUBLIC_ int lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) { \
196 return lp_ctx->globals->var_name; \
199 /* Local parameters don't need the ->s3_fns because the struct
200 * loadparm_service is shared and lpcfg_service() checks the ->s3_fns
201 * hook */
202 #define FN_LOCAL_STRING(fn_name,val) \
203 _PUBLIC_ char *lpcfg_ ## fn_name(struct loadparm_service *service, \
204 struct loadparm_service *sDefault, TALLOC_CTX *ctx) { \
205 return(talloc_strdup(ctx, lpcfg_string((const char *)((service != NULL && service->val != NULL) ? service->val : sDefault->val)))); \
208 #define FN_LOCAL_CONST_STRING(fn_name,val) \
209 _PUBLIC_ const char *lpcfg_ ## fn_name(struct loadparm_service *service, \
210 struct loadparm_service *sDefault) { \
211 return((const char *)((service != NULL && service->val != NULL) ? service->val : sDefault->val)); \
214 #define FN_LOCAL_LIST(fn_name,val) \
215 _PUBLIC_ const char **lpcfg_ ## fn_name(struct loadparm_service *service, \
216 struct loadparm_service *sDefault) {\
217 return(const char **)(service != NULL && service->val != NULL? service->val : sDefault->val); \
220 #define FN_LOCAL_PARM_BOOL(fn_name, val) FN_LOCAL_BOOL(fn_name, val)
222 #define FN_LOCAL_BOOL(fn_name,val) \
223 _PUBLIC_ bool lpcfg_ ## fn_name(struct loadparm_service *service, \
224 struct loadparm_service *sDefault) { \
225 return((service != NULL)? service->val : sDefault->val); \
228 #define FN_LOCAL_INTEGER(fn_name,val) \
229 _PUBLIC_ int lpcfg_ ## fn_name(struct loadparm_service *service, \
230 struct loadparm_service *sDefault) { \
231 return((service != NULL)? service->val : sDefault->val); \
234 #define FN_LOCAL_PARM_INTEGER(fn_name, val) FN_LOCAL_INTEGER(fn_name, val)
236 #define FN_LOCAL_PARM_CHAR(fn_name,val) \
237 _PUBLIC_ char lpcfg_ ## fn_name(struct loadparm_service *service, \
238 struct loadparm_service *sDefault) { \
239 return((service != NULL)? service->val : sDefault->val); \
242 #include "lib/param/param_functions.c"
244 /* These functions cannot be auto-generated */
245 FN_LOCAL_BOOL(autoloaded, autoloaded)
246 FN_GLOBAL_CONST_STRING(dnsdomain, dnsdomain)
248 /* local prototypes */
249 static struct loadparm_service *lpcfg_getservicebyname(struct loadparm_context *lp_ctx,
250 const char *pszServiceName);
251 static bool lpcfg_service_ok(struct loadparm_service *service);
252 static bool do_section(const char *pszSectionName, void *);
254 /* This is a helper function for parametrical options support. */
255 /* It returns a pointer to parametrical option value if it exists or NULL otherwise */
256 /* Actual parametrical functions are quite simple */
257 const char *lpcfg_get_parametric(struct loadparm_context *lp_ctx,
258 struct loadparm_service *service,
259 const char *type, const char *option)
261 char *vfskey_tmp = NULL;
262 char *vfskey = NULL;
263 struct parmlist_entry *data;
265 if (lp_ctx == NULL)
266 return NULL;
268 if (lp_ctx->s3_fns) {
269 return lp_ctx->s3_fns->get_parametric(service, type, option, NULL);
272 data = (service == NULL ? lp_ctx->globals->param_opt : service->param_opt);
274 vfskey_tmp = talloc_asprintf(NULL, "%s:%s", type, option);
275 if (vfskey_tmp == NULL) return NULL;
276 vfskey = strlower_talloc(NULL, vfskey_tmp);
277 talloc_free(vfskey_tmp);
279 while (data) {
280 if (strcmp(data->key, vfskey) == 0) {
281 talloc_free(vfskey);
282 return data->value;
284 data = data->next;
287 if (service != NULL) {
288 /* Try to fetch the same option but from globals */
289 /* but only if we are not already working with globals */
290 for (data = lp_ctx->globals->param_opt; data;
291 data = data->next) {
292 if (strcmp(data->key, vfskey) == 0) {
293 talloc_free(vfskey);
294 return data->value;
299 talloc_free(vfskey);
301 return NULL;
306 * convenience routine to return int parameters.
308 int lp_int(const char *s)
311 if (!s || !*s) {
312 DEBUG(0,("lp_int(%s): is called with NULL!\n",s));
313 return -1;
316 return strtol(s, NULL, 0);
320 * convenience routine to return unsigned long parameters.
322 unsigned long lp_ulong(const char *s)
325 if (!s || !*s) {
326 DEBUG(0,("lp_ulong(%s): is called with NULL!\n",s));
327 return -1;
330 return strtoul(s, NULL, 0);
334 * convenience routine to return unsigned long parameters.
336 static long lp_long(const char *s)
339 if (!s) {
340 DEBUG(0,("lp_long(%s): is called with NULL!\n",s));
341 return -1;
344 return strtol(s, NULL, 0);
348 * convenience routine to return unsigned long parameters.
350 static double lp_double(const char *s)
353 if (!s) {
354 DEBUG(0,("lp_double(%s): is called with NULL!\n",s));
355 return -1;
358 return strtod(s, NULL);
362 * convenience routine to return boolean parameters.
364 bool lp_bool(const char *s)
366 bool ret = false;
368 if (!s || !*s) {
369 DEBUG(0,("lp_bool(%s): is called with NULL!\n",s));
370 return false;
373 if (!set_boolean(s, &ret)) {
374 DEBUG(0,("lp_bool(%s): value is not boolean!\n",s));
375 return false;
378 return ret;
382 * Return parametric option from a given service. Type is a part of option before ':'
383 * Parametric option has following syntax: 'Type: option = value'
384 * Returned value is allocated in 'lp_talloc' context
387 const char *lpcfg_parm_string(struct loadparm_context *lp_ctx,
388 struct loadparm_service *service, const char *type,
389 const char *option)
391 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
393 if (value)
394 return lpcfg_string(value);
396 return NULL;
400 * Return parametric option from a given service. Type is a part of option before ':'
401 * Parametric option has following syntax: 'Type: option = value'
402 * Returned value is allocated in 'lp_talloc' context
405 const char **lpcfg_parm_string_list(TALLOC_CTX *mem_ctx,
406 struct loadparm_context *lp_ctx,
407 struct loadparm_service *service,
408 const char *type,
409 const char *option, const char *separator)
411 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
413 if (value != NULL)
414 return (const char **)str_list_make(mem_ctx, value, separator);
416 return NULL;
420 * Return parametric option from a given service. Type is a part of option before ':'
421 * Parametric option has following syntax: 'Type: option = value'
424 int lpcfg_parm_int(struct loadparm_context *lp_ctx,
425 struct loadparm_service *service, const char *type,
426 const char *option, int default_v)
428 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
430 if (value)
431 return lp_int(value);
433 return default_v;
437 * Return parametric option from a given service. Type is a part of
438 * option before ':'.
439 * Parametric option has following syntax: 'Type: option = value'.
442 int lpcfg_parm_bytes(struct loadparm_context *lp_ctx,
443 struct loadparm_service *service, const char *type,
444 const char *option, int default_v)
446 uint64_t bval;
448 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
450 if (value && conv_str_size_error(value, &bval)) {
451 if (bval <= INT_MAX) {
452 return (int)bval;
456 return default_v;
460 * Return parametric option from a given service.
461 * Type is a part of option before ':'
462 * Parametric option has following syntax: 'Type: option = value'
464 unsigned long lpcfg_parm_ulong(struct loadparm_context *lp_ctx,
465 struct loadparm_service *service, const char *type,
466 const char *option, unsigned long default_v)
468 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
470 if (value)
471 return lp_ulong(value);
473 return default_v;
476 long lpcfg_parm_long(struct loadparm_context *lp_ctx,
477 struct loadparm_service *service, const char *type,
478 const char *option, long default_v)
480 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
482 if (value)
483 return lp_long(value);
485 return default_v;
488 double lpcfg_parm_double(struct loadparm_context *lp_ctx,
489 struct loadparm_service *service, const char *type,
490 const char *option, double default_v)
492 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
494 if (value != NULL)
495 return lp_double(value);
497 return default_v;
501 * Return parametric option from a given service. Type is a part of option before ':'
502 * Parametric option has following syntax: 'Type: option = value'
505 bool lpcfg_parm_bool(struct loadparm_context *lp_ctx,
506 struct loadparm_service *service, const char *type,
507 const char *option, bool default_v)
509 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
511 if (value != NULL)
512 return lp_bool(value);
514 return default_v;
519 * Set a string value, deallocating any existing space, and allocing the space
520 * for the string
522 bool lpcfg_string_set(TALLOC_CTX *mem_ctx, char **dest, const char *src)
524 talloc_free(*dest);
526 if (src == NULL)
527 src = "";
529 *dest = talloc_strdup(mem_ctx, src);
530 if ((*dest) == NULL) {
531 DEBUG(0,("Out of memory in string_set\n"));
532 return false;
535 return true;
539 * Set a string value, deallocating any existing space, and allocing the space
540 * for the string
542 static bool lpcfg_string_set_upper(TALLOC_CTX *mem_ctx, char **dest, const char *src)
544 talloc_free(*dest);
546 if (src == NULL)
547 src = "";
549 *dest = strupper_talloc(mem_ctx, src);
550 if ((*dest) == NULL) {
551 DEBUG(0,("Out of memory in string_set_upper\n"));
552 return false;
555 return true;
561 * Add a new service to the services array initialising it with the given
562 * service.
565 struct loadparm_service *lpcfg_add_service(struct loadparm_context *lp_ctx,
566 const struct loadparm_service *pservice,
567 const char *name)
569 int i;
570 int num_to_alloc = lp_ctx->iNumServices + 1;
571 struct parmlist_entry *data, *pdata;
573 if (pservice == NULL) {
574 pservice = lp_ctx->sDefault;
577 /* it might already exist */
578 if (name) {
579 struct loadparm_service *service = lpcfg_getservicebyname(lp_ctx,
580 name);
581 if (service != NULL) {
582 /* Clean all parametric options for service */
583 /* They will be added during parsing again */
584 data = service->param_opt;
585 while (data) {
586 pdata = data->next;
587 talloc_free(data);
588 data = pdata;
590 service->param_opt = NULL;
591 return service;
595 /* find an invalid one */
596 for (i = 0; i < lp_ctx->iNumServices; i++)
597 if (lp_ctx->services[i] == NULL)
598 break;
600 /* if not, then create one */
601 if (i == lp_ctx->iNumServices) {
602 struct loadparm_service **tsp;
604 tsp = talloc_realloc(lp_ctx, lp_ctx->services, struct loadparm_service *, num_to_alloc);
606 if (!tsp) {
607 DEBUG(0,("lpcfg_add_service: failed to enlarge services!\n"));
608 return NULL;
609 } else {
610 lp_ctx->services = tsp;
611 lp_ctx->services[lp_ctx->iNumServices] = NULL;
614 lp_ctx->iNumServices++;
617 lp_ctx->services[i] = talloc_zero(lp_ctx->services, struct loadparm_service);
618 if (lp_ctx->services[i] == NULL) {
619 DEBUG(0,("lpcfg_add_service: out of memory!\n"));
620 return NULL;
622 copy_service(lp_ctx->services[i], pservice, NULL);
623 if (name != NULL)
624 lpcfg_string_set(lp_ctx->services[i], &lp_ctx->services[i]->szService, name);
625 return lp_ctx->services[i];
629 * Add a new home service, with the specified home directory, defaults coming
630 * from service ifrom.
633 bool lpcfg_add_home(struct loadparm_context *lp_ctx,
634 const char *pszHomename,
635 struct loadparm_service *default_service,
636 const char *user, const char *pszHomedir)
638 struct loadparm_service *service;
640 service = lpcfg_add_service(lp_ctx, default_service, pszHomename);
642 if (service == NULL)
643 return false;
645 if (!(*(default_service->path))
646 || strequal(default_service->path, lp_ctx->sDefault->path)) {
647 service->path = talloc_strdup(service, pszHomedir);
648 } else {
649 service->path = string_sub_talloc(service, lpcfg_path(default_service, lp_ctx->sDefault, service), "%H", pszHomedir);
652 if (!(*(service->comment))) {
653 service->comment = talloc_asprintf(service, "Home directory of %s", user);
655 service->bAvailable = default_service->bAvailable;
656 service->browseable = default_service->browseable;
658 DEBUG(3, ("adding home's share [%s] for user '%s' at '%s'\n",
659 pszHomename, user, service->path));
661 return true;
665 * Add a new printer service, with defaults coming from service iFrom.
668 bool lpcfg_add_printer(struct loadparm_context *lp_ctx,
669 const char *pszPrintername,
670 struct loadparm_service *default_service)
672 const char *comment = "From Printcap";
673 struct loadparm_service *service;
674 service = lpcfg_add_service(lp_ctx, default_service, pszPrintername);
676 if (service == NULL)
677 return false;
679 /* note that we do NOT default the availability flag to True - */
680 /* we take it from the default service passed. This allows all */
681 /* dynamic printers to be disabled by disabling the [printers] */
682 /* entry (if/when the 'available' keyword is implemented!). */
684 /* the printer name is set to the service name. */
685 lpcfg_string_set(service, &service->_printername, pszPrintername);
686 lpcfg_string_set(service, &service->comment, comment);
687 service->browseable = default_service->browseable;
688 /* Printers cannot be read_only. */
689 service->read_only = false;
690 /* Printer services must be printable. */
691 service->printable = true;
693 DEBUG(3, ("adding printer service %s\n", pszPrintername));
695 return true;
699 * Map a parameter's string representation to something we can use.
700 * Returns False if the parameter string is not recognised, else TRUE.
703 int lpcfg_map_parameter(const char *pszParmName)
705 int iIndex;
707 for (iIndex = 0; parm_table[iIndex].label; iIndex++)
708 if (strwicmp(parm_table[iIndex].label, pszParmName) == 0)
709 return iIndex;
711 /* Warn only if it isn't parametric option */
712 if (strchr(pszParmName, ':') == NULL)
713 DEBUG(0, ("Unknown parameter encountered: \"%s\"\n", pszParmName));
714 /* We do return 'fail' for parametric options as well because they are
715 stored in different storage
717 return -1;
722 return the parameter structure for a parameter
724 struct parm_struct *lpcfg_parm_struct(struct loadparm_context *lp_ctx, const char *name)
726 int parmnum;
728 if (lp_ctx->s3_fns) {
729 return lp_ctx->s3_fns->get_parm_struct(name);
732 parmnum = lpcfg_map_parameter(name);
733 if (parmnum == -1) return NULL;
734 return &parm_table[parmnum];
738 return the parameter pointer for a parameter
740 void *lpcfg_parm_ptr(struct loadparm_context *lp_ctx,
741 struct loadparm_service *service, struct parm_struct *parm)
743 if (lp_ctx->s3_fns) {
744 return lp_ctx->s3_fns->get_parm_ptr(service, parm);
747 if (service == NULL) {
748 if (parm->p_class == P_LOCAL)
749 return ((char *)lp_ctx->sDefault)+parm->offset;
750 else if (parm->p_class == P_GLOBAL)
751 return ((char *)lp_ctx->globals)+parm->offset;
752 else return NULL;
753 } else {
754 return ((char *)service) + parm->offset;
759 return the parameter pointer for a parameter
761 bool lpcfg_parm_is_cmdline(struct loadparm_context *lp_ctx, const char *name)
763 int parmnum;
765 if (lp_ctx->s3_fns) {
766 struct parm_struct *parm = lp_ctx->s3_fns->get_parm_struct(name);
767 if (parm) {
768 return parm->flags & FLAG_CMDLINE;
770 return false;
773 parmnum = lpcfg_map_parameter(name);
774 if (parmnum == -1) return false;
776 return lp_ctx->flags[parmnum] & FLAG_CMDLINE;
780 * Find a service by name. Otherwise works like get_service.
783 static struct loadparm_service *lpcfg_getservicebyname(struct loadparm_context *lp_ctx,
784 const char *pszServiceName)
786 int iService;
788 if (lp_ctx->s3_fns) {
789 return lp_ctx->s3_fns->get_service(pszServiceName);
792 for (iService = lp_ctx->iNumServices - 1; iService >= 0; iService--)
793 if (lp_ctx->services[iService] != NULL &&
794 strwicmp(lp_ctx->services[iService]->szService, pszServiceName) == 0) {
795 return lp_ctx->services[iService];
798 return NULL;
802 * Add a parametric option to a parmlist_entry,
803 * replacing old value, if already present.
805 void set_param_opt(TALLOC_CTX *mem_ctx,
806 struct parmlist_entry **opt_list,
807 const char *opt_name,
808 const char *opt_value,
809 unsigned priority)
811 struct parmlist_entry *new_opt, *opt;
812 bool not_added;
814 opt = *opt_list;
815 not_added = true;
817 /* Traverse destination */
818 while (opt) {
819 /* If we already have same option, override it */
820 if (strwicmp(opt->key, opt_name) == 0) {
821 if ((opt->priority & FLAG_CMDLINE) &&
822 !(priority & FLAG_CMDLINE)) {
823 /* it's been marked as not to be
824 overridden */
825 return;
827 TALLOC_FREE(opt->value);
828 TALLOC_FREE(opt->list);
829 opt->value = talloc_strdup(opt, opt_value);
830 opt->priority = priority;
831 not_added = false;
832 break;
834 opt = opt->next;
836 if (not_added) {
837 new_opt = talloc(mem_ctx, struct parmlist_entry);
838 if (new_opt == NULL) {
839 smb_panic("OOM");
842 new_opt->key = talloc_strdup(new_opt, opt_name);
843 if (new_opt->key == NULL) {
844 smb_panic("talloc_strdup failed");
847 new_opt->value = talloc_strdup(new_opt, opt_value);
848 if (new_opt->value == NULL) {
849 smb_panic("talloc_strdup failed");
852 new_opt->list = NULL;
853 new_opt->priority = priority;
854 DLIST_ADD(*opt_list, new_opt);
859 * Copy a service structure to another.
860 * If pcopymapDest is NULL then copy all fields
863 void copy_service(struct loadparm_service *pserviceDest,
864 const struct loadparm_service *pserviceSource,
865 struct bitmap *pcopymapDest)
867 int i;
868 bool bcopyall = (pcopymapDest == NULL);
869 struct parmlist_entry *data;
871 for (i = 0; parm_table[i].label; i++)
872 if (parm_table[i].p_class == P_LOCAL &&
873 (bcopyall || bitmap_query(pcopymapDest, i))) {
874 const void *src_ptr =
875 ((const char *)pserviceSource) + parm_table[i].offset;
876 void *dest_ptr =
877 ((char *)pserviceDest) + parm_table[i].offset;
879 switch (parm_table[i].type) {
880 case P_BOOL:
881 case P_BOOLREV:
882 *(bool *)dest_ptr = *(const bool *)src_ptr;
883 break;
885 case P_INTEGER:
886 case P_BYTES:
887 case P_OCTAL:
888 case P_ENUM:
889 *(int *)dest_ptr = *(const int *)src_ptr;
890 break;
892 case P_CHAR:
893 *(char *)dest_ptr = *(const char *)src_ptr;
894 break;
896 case P_STRING:
897 lpcfg_string_set(pserviceDest,
898 (char **)dest_ptr,
899 *(const char * const *)src_ptr);
900 break;
902 case P_USTRING:
903 lpcfg_string_set_upper(pserviceDest,
904 (char **)dest_ptr,
905 *(const char * const *)src_ptr);
906 break;
907 case P_LIST:
908 TALLOC_FREE(*((char ***)dest_ptr));
909 *(const char * const **)dest_ptr = (const char * const *)str_list_copy(pserviceDest,
910 *(const char * * const *)src_ptr);
911 break;
912 default:
913 break;
917 if (bcopyall) {
918 init_copymap(pserviceDest);
919 if (pserviceSource->copymap)
920 bitmap_copy(pserviceDest->copymap,
921 pserviceSource->copymap);
924 for (data = pserviceSource->param_opt; data != NULL; data = data->next) {
925 set_param_opt(pserviceDest, &pserviceDest->param_opt,
926 data->key, data->value, data->priority);
931 * Check a service for consistency. Return False if the service is in any way
932 * incomplete or faulty, else True.
934 static bool lpcfg_service_ok(struct loadparm_service *service)
936 bool bRetval;
938 bRetval = true;
939 if (service->szService[0] == '\0') {
940 DEBUG(0, ("The following message indicates an internal error:\n"));
941 DEBUG(0, ("No service name in service entry.\n"));
942 bRetval = false;
945 /* The [printers] entry MUST be printable. I'm all for flexibility, but */
946 /* I can't see why you'd want a non-printable printer service... */
947 if (strwicmp(service->szService, PRINTERS_NAME) == 0) {
948 if (!service->printable) {
949 DEBUG(0, ("WARNING: [%s] service MUST be printable!\n",
950 service->szService));
951 service->printable = true;
953 /* [printers] service must also be non-browsable. */
954 if (service->browseable)
955 service->browseable = false;
958 /* If a service is flagged unavailable, log the fact at level 0. */
959 if (!service->bAvailable)
960 DEBUG(1, ("NOTE: Service %s is flagged unavailable.\n",
961 service->szService));
963 return bRetval;
967 /*******************************************************************
968 Keep a linked list of all config files so we know when one has changed
969 it's date and needs to be reloaded.
970 ********************************************************************/
972 void add_to_file_list(TALLOC_CTX *mem_ctx, struct file_lists **list,
973 const char *fname, const char *subfname)
975 struct file_lists *f = *list;
977 while (f) {
978 if (f->name && !strcmp(f->name, fname))
979 break;
980 f = f->next;
983 if (!f) {
984 f = talloc(mem_ctx, struct file_lists);
985 if (!f)
986 goto fail;
987 f->next = *list;
988 f->name = talloc_strdup(f, fname);
989 if (!f->name) {
990 TALLOC_FREE(f);
991 goto fail;
993 f->subfname = talloc_strdup(f, subfname);
994 if (!f->subfname) {
995 TALLOC_FREE(f);
996 goto fail;
998 *list = f;
999 f->modtime = file_modtime(subfname);
1000 } else {
1001 time_t t = file_modtime(subfname);
1002 if (t)
1003 f->modtime = t;
1005 return;
1007 fail:
1008 DEBUG(0, ("Unable to add file to file list: %s\n", fname));
1012 /*******************************************************************
1013 Check if a config file has changed date.
1014 ********************************************************************/
1015 bool lpcfg_file_list_changed(struct loadparm_context *lp_ctx)
1017 struct file_lists *f;
1018 DEBUG(6, ("lpcfg_file_list_changed()\n"));
1020 for (f = lp_ctx->file_lists; f != NULL; f = f->next) {
1021 char *n2;
1022 time_t mod_time;
1024 n2 = standard_sub_basic(lp_ctx, f->name);
1026 DEBUGADD(6, ("file %s -> %s last mod_time: %s\n",
1027 f->name, n2, ctime(&f->modtime)));
1029 mod_time = file_modtime(n2);
1031 if (mod_time && ((f->modtime != mod_time) || (f->subfname == NULL) || (strcmp(n2, f->subfname) != 0))) {
1032 DEBUGADD(6, ("file %s modified: %s\n", n2,
1033 ctime(&mod_time)));
1034 f->modtime = mod_time;
1035 talloc_free(f->subfname);
1036 f->subfname = talloc_strdup(f, n2);
1037 return true;
1040 return false;
1044 * set the value for a P_ENUM
1046 bool lp_set_enum_parm( struct parm_struct *parm, const char *pszParmValue,
1047 int *ptr )
1049 int i;
1051 for (i = 0; parm->enum_list[i].name; i++) {
1052 if ( strequal(pszParmValue, parm->enum_list[i].name)) {
1053 *ptr = parm->enum_list[i].value;
1054 return true;
1057 DEBUG(0, ("WARNING: Ignoring invalid value '%s' for parameter '%s'\n",
1058 pszParmValue, parm->label));
1059 return false;
1063 /***************************************************************************
1064 Handle the "realm" parameter
1065 ***************************************************************************/
1067 bool handle_realm(struct loadparm_context *lp_ctx, int unused,
1068 const char *pszParmValue, char **ptr)
1070 char *upper;
1071 char *lower;
1073 upper = strupper_talloc(lp_ctx, pszParmValue);
1074 if (upper == NULL) {
1075 return false;
1078 lower = strlower_talloc(lp_ctx, pszParmValue);
1079 if (lower == NULL) {
1080 TALLOC_FREE(upper);
1081 return false;
1084 if (lp_ctx->s3_fns != NULL) {
1085 lp_ctx->s3_fns->lp_string_set(ptr, pszParmValue);
1086 lp_ctx->s3_fns->lp_string_set(&lp_ctx->globals->realm, upper);
1087 lp_ctx->s3_fns->lp_string_set(&lp_ctx->globals->dnsdomain, lower);
1088 } else {
1089 lpcfg_string_set(lp_ctx, ptr, pszParmValue);
1090 lpcfg_string_set(lp_ctx, &lp_ctx->globals->realm, upper);
1091 lpcfg_string_set(lp_ctx, &lp_ctx->globals->dnsdomain, lower);
1094 return true;
1097 /***************************************************************************
1098 Handle the include operation.
1099 ***************************************************************************/
1101 bool handle_include(struct loadparm_context *lp_ctx, int unused,
1102 const char *pszParmValue, char **ptr)
1104 char *fname;
1106 if (lp_ctx->s3_fns) {
1107 return lp_ctx->s3_fns->lp_include(lp_ctx, unused, pszParmValue, ptr);
1110 fname = standard_sub_basic(lp_ctx, pszParmValue);
1112 add_to_file_list(lp_ctx, &lp_ctx->file_lists, pszParmValue, fname);
1114 lpcfg_string_set(lp_ctx, ptr, fname);
1116 if (file_exist(fname))
1117 return pm_process(fname, do_section, do_parameter, lp_ctx);
1119 DEBUG(2, ("Can't find include file %s\n", fname));
1121 return false;
1124 /***************************************************************************
1125 Handle the interpretation of the copy parameter.
1126 ***************************************************************************/
1128 bool handle_copy(struct loadparm_context *lp_ctx, int snum,
1129 const char *pszParmValue, char **ptr)
1131 bool bRetval;
1132 struct loadparm_service *serviceTemp = NULL;
1133 struct loadparm_service *current = NULL;
1135 bRetval = false;
1137 DEBUG(3, ("Copying service from service %s\n", pszParmValue));
1139 serviceTemp = lpcfg_getservicebyname(lp_ctx, pszParmValue);
1140 if (lp_ctx->s3_fns != NULL) {
1141 current = lp_ctx->s3_fns->get_servicebynum(snum);
1142 } else {
1143 current = lp_ctx->currentService;
1146 if (current == NULL) {
1147 DEBUG(0, ("Unable to copy service - invalid service destination"));
1148 return false;
1151 if (serviceTemp != NULL) {
1152 if (serviceTemp == current) {
1153 DEBUG(0, ("Can't copy service %s - unable to copy self!\n", pszParmValue));
1154 } else {
1155 copy_service(current,
1156 serviceTemp,
1157 current->copymap);
1158 lpcfg_string_set(current, ptr, pszParmValue);
1160 bRetval = true;
1162 } else {
1163 DEBUG(0, ("Unable to copy service - source not found: %s\n",
1164 pszParmValue));
1165 bRetval = false;
1168 return bRetval;
1171 bool handle_debug_list(struct loadparm_context *lp_ctx, int unused,
1172 const char *pszParmValue, char **ptr)
1174 if (lp_ctx->s3_fns != NULL) {
1175 lp_ctx->s3_fns->lp_string_set(ptr, pszParmValue);
1176 } else {
1177 lpcfg_string_set(lp_ctx, ptr, pszParmValue);
1180 return debug_parse_levels(pszParmValue);
1183 bool handle_logfile(struct loadparm_context *lp_ctx, int unused,
1184 const char *pszParmValue, char **ptr)
1186 if (lp_ctx->s3_fns != NULL) {
1187 lp_ctx->s3_fns->lp_string_set(ptr, pszParmValue);
1188 } else {
1189 debug_set_logfile(pszParmValue);
1190 lpcfg_string_set(lp_ctx, ptr, pszParmValue);
1193 return true;
1197 * These special charset handling methods only run in the source3 code.
1200 bool handle_charset(struct loadparm_context *lp_ctx, int snum,
1201 const char *pszParmValue, char **ptr)
1203 if (lp_ctx->s3_fns) {
1204 if (*ptr == NULL || strcmp(*ptr, pszParmValue) != 0) {
1205 lp_ctx->s3_fns->lp_string_set(ptr, pszParmValue);
1206 global_iconv_handle = smb_iconv_handle_reinit(NULL,
1207 lpcfg_dos_charset(lp_ctx),
1208 lpcfg_unix_charset(lp_ctx),
1209 true, global_iconv_handle);
1212 return true;
1214 return lpcfg_string_set(lp_ctx, ptr, pszParmValue);
1218 bool handle_dos_charset(struct loadparm_context *lp_ctx, int snum,
1219 const char *pszParmValue, char **ptr)
1221 bool is_utf8 = false;
1222 size_t len = strlen(pszParmValue);
1224 if (lp_ctx->s3_fns) {
1225 if (len == 4 || len == 5) {
1226 /* Don't use StrCaseCmp here as we don't want to
1227 initialize iconv. */
1228 if ((toupper_m(pszParmValue[0]) == 'U') &&
1229 (toupper_m(pszParmValue[1]) == 'T') &&
1230 (toupper_m(pszParmValue[2]) == 'F')) {
1231 if (len == 4) {
1232 if (pszParmValue[3] == '8') {
1233 is_utf8 = true;
1235 } else {
1236 if (pszParmValue[3] == '-' &&
1237 pszParmValue[4] == '8') {
1238 is_utf8 = true;
1244 if (*ptr == NULL || strcmp(*ptr, pszParmValue) != 0) {
1245 if (is_utf8) {
1246 DEBUG(0,("ERROR: invalid DOS charset: 'dos charset' must not "
1247 "be UTF8, using (default value) %s instead.\n",
1248 DEFAULT_DOS_CHARSET));
1249 pszParmValue = DEFAULT_DOS_CHARSET;
1251 lp_ctx->s3_fns->lp_string_set(ptr, pszParmValue);
1252 global_iconv_handle = smb_iconv_handle_reinit(NULL,
1253 lpcfg_dos_charset(lp_ctx),
1254 lpcfg_unix_charset(lp_ctx),
1255 true, global_iconv_handle);
1257 return true;
1260 return lpcfg_string_set(lp_ctx, ptr, pszParmValue);
1263 bool handle_printing(struct loadparm_context *lp_ctx, int snum,
1264 const char *pszParmValue, char **ptr)
1266 static int parm_num = -1;
1267 struct loadparm_service *s;
1269 if (parm_num == -1) {
1270 parm_num = lpcfg_map_parameter("printing");
1273 if (!lp_set_enum_parm(&parm_table[parm_num], pszParmValue, (int*)ptr)) {
1274 return false;
1277 if (lp_ctx->s3_fns) {
1278 if ( snum < 0 ) {
1279 s = lp_ctx->sDefault;
1280 lp_ctx->s3_fns->init_printer_values(lp_ctx->globals->ctx, s);
1281 } else {
1282 s = lp_ctx->services[snum];
1283 lp_ctx->s3_fns->init_printer_values(s, s);
1287 return true;
1290 bool handle_ldap_debug_level(struct loadparm_context *lp_ctx, int snum, const char *pszParmValue, char **ptr)
1292 lp_ctx->globals->ldap_debug_level = lp_int(pszParmValue);
1294 if (lp_ctx->s3_fns) {
1295 lp_ctx->s3_fns->init_ldap_debugging();
1297 return true;
1300 /***************************************************************************
1301 Initialise a copymap.
1302 ***************************************************************************/
1304 void init_copymap(struct loadparm_service *pservice)
1306 int i;
1308 TALLOC_FREE(pservice->copymap);
1310 pservice->copymap = bitmap_talloc(NULL, NUMPARAMETERS);
1311 if (!pservice->copymap)
1312 DEBUG(0,
1313 ("Couldn't allocate copymap!! (size %d)\n",
1314 (int)NUMPARAMETERS));
1315 else
1316 for (i = 0; i < NUMPARAMETERS; i++)
1317 bitmap_set(pservice->copymap, i);
1321 * Process a parametric option
1323 static bool lp_do_parameter_parametric(struct loadparm_context *lp_ctx,
1324 struct loadparm_service *service,
1325 const char *pszParmName,
1326 const char *pszParmValue, int flags)
1328 struct parmlist_entry **data;
1329 char *name;
1330 TALLOC_CTX *mem_ctx;
1332 while (isspace((unsigned char)*pszParmName)) {
1333 pszParmName++;
1336 name = strlower_talloc(lp_ctx, pszParmName);
1337 if (!name) return false;
1339 if (service == NULL) {
1340 data = &lp_ctx->globals->param_opt;
1341 mem_ctx = lp_ctx->globals;
1342 } else {
1343 data = &service->param_opt;
1344 mem_ctx = service;
1347 set_param_opt(mem_ctx, data, name, pszParmValue, flags);
1349 talloc_free(name);
1351 return true;
1354 static bool set_variable(TALLOC_CTX *mem_ctx, int parmnum, void *parm_ptr,
1355 const char *pszParmName, const char *pszParmValue,
1356 struct loadparm_context *lp_ctx, bool on_globals)
1358 int i;
1359 /* if it is a special case then go ahead */
1360 if (parm_table[parmnum].special) {
1361 bool ret;
1362 ret = parm_table[parmnum].special(lp_ctx, -1, pszParmValue,
1363 (char **)parm_ptr);
1364 if (!ret) {
1365 return false;
1367 goto mark_non_default;
1370 /* now switch on the type of variable it is */
1371 switch (parm_table[parmnum].type)
1373 case P_BOOL: {
1374 bool b;
1375 if (!set_boolean(pszParmValue, &b)) {
1376 DEBUG(0, ("set_variable(%s): value is not "
1377 "boolean!\n", pszParmValue));
1378 return false;
1380 *(bool *)parm_ptr = b;
1382 break;
1384 case P_BOOLREV: {
1385 bool b;
1386 if (!set_boolean(pszParmValue, &b)) {
1387 DEBUG(0, ("set_variable(%s): value is not "
1388 "boolean!\n", pszParmValue));
1389 return false;
1391 *(bool *)parm_ptr = !b;
1393 break;
1395 case P_INTEGER:
1396 *(int *)parm_ptr = atoi(pszParmValue);
1397 break;
1399 case P_CHAR:
1400 *(char *)parm_ptr = *pszParmValue;
1401 break;
1403 case P_OCTAL:
1404 *(int *)parm_ptr = strtol(pszParmValue, NULL, 8);
1405 break;
1407 case P_BYTES:
1409 uint64_t val;
1410 if (conv_str_size_error(pszParmValue, &val)) {
1411 if (val <= INT_MAX) {
1412 *(int *)parm_ptr = (int)val;
1413 break;
1417 DEBUG(0, ("set_variable(%s): value is not "
1418 "a valid size specifier!\n", pszParmValue));
1419 return false;
1422 case P_CMDLIST:
1423 *(const char * const **)parm_ptr
1424 = (const char * const *)str_list_make(mem_ctx,
1425 pszParmValue, NULL);
1426 break;
1427 case P_LIST:
1429 char **new_list = str_list_make(mem_ctx,
1430 pszParmValue, NULL);
1431 for (i=0; new_list[i]; i++) {
1432 if (*(const char ***)parm_ptr != NULL &&
1433 new_list[i][0] == '+' &&
1434 new_list[i][1])
1436 if (!str_list_check(*(const char ***)parm_ptr,
1437 &new_list[i][1])) {
1438 *(const char ***)parm_ptr = str_list_add(*(const char ***)parm_ptr,
1439 &new_list[i][1]);
1441 } else if (*(const char ***)parm_ptr != NULL &&
1442 new_list[i][0] == '-' &&
1443 new_list[i][1])
1445 str_list_remove(*(const char ***)parm_ptr,
1446 &new_list[i][1]);
1447 } else {
1448 if (i != 0) {
1449 DEBUG(0, ("Unsupported list syntax for: %s = %s\n",
1450 pszParmName, pszParmValue));
1451 return false;
1453 *(const char * const **)parm_ptr = (const char * const *) new_list;
1454 break;
1457 break;
1459 case P_STRING:
1460 lpcfg_string_set(mem_ctx, (char **)parm_ptr, pszParmValue);
1461 break;
1463 case P_USTRING:
1464 lpcfg_string_set_upper(mem_ctx, (char **)parm_ptr, pszParmValue);
1465 break;
1467 case P_ENUM:
1468 if (!lp_set_enum_parm(&parm_table[parmnum], pszParmValue, (int*)parm_ptr)) {
1469 return false;
1471 break;
1473 case P_SEP:
1474 break;
1477 mark_non_default:
1478 if (on_globals && (lp_ctx->flags[parmnum] & FLAG_DEFAULT)) {
1479 lp_ctx->flags[parmnum] &= ~FLAG_DEFAULT;
1480 /* we have to also unset FLAG_DEFAULT on aliases */
1481 for (i=parmnum-1;i>=0 && parm_table[i].offset == parm_table[parmnum].offset;i--) {
1482 lp_ctx->flags[i] &= ~FLAG_DEFAULT;
1484 for (i=parmnum+1;i<NUMPARAMETERS && parm_table[i].offset == parm_table[parmnum].offset;i++) {
1485 lp_ctx->flags[i] &= ~FLAG_DEFAULT;
1488 return true;
1492 bool lpcfg_do_global_parameter(struct loadparm_context *lp_ctx,
1493 const char *pszParmName, const char *pszParmValue)
1495 int parmnum = lpcfg_map_parameter(pszParmName);
1496 void *parm_ptr;
1498 if (parmnum < 0) {
1499 if (strchr(pszParmName, ':')) {
1500 return lp_do_parameter_parametric(lp_ctx, NULL, pszParmName, pszParmValue, 0);
1502 DEBUG(0, ("Ignoring unknown parameter \"%s\"\n", pszParmName));
1503 return true;
1506 /* if the flag has been set on the command line, then don't allow override,
1507 but don't report an error */
1508 if (lp_ctx->flags[parmnum] & FLAG_CMDLINE) {
1509 return true;
1512 parm_ptr = lpcfg_parm_ptr(lp_ctx, NULL, &parm_table[parmnum]);
1514 return set_variable(lp_ctx->globals, parmnum, parm_ptr,
1515 pszParmName, pszParmValue, lp_ctx, true);
1518 bool lpcfg_do_service_parameter(struct loadparm_context *lp_ctx,
1519 struct loadparm_service *service,
1520 const char *pszParmName, const char *pszParmValue)
1522 void *parm_ptr;
1523 int i;
1524 int parmnum = lpcfg_map_parameter(pszParmName);
1526 if (parmnum < 0) {
1527 if (strchr(pszParmName, ':')) {
1528 return lp_do_parameter_parametric(lp_ctx, service, pszParmName, pszParmValue, 0);
1530 DEBUG(0, ("Ignoring unknown parameter \"%s\"\n", pszParmName));
1531 return true;
1534 /* if the flag has been set on the command line, then don't allow override,
1535 but don't report an error */
1536 if (lp_ctx->flags[parmnum] & FLAG_CMDLINE) {
1537 return true;
1540 if (parm_table[parmnum].p_class == P_GLOBAL) {
1541 DEBUG(0,
1542 ("Global parameter %s found in service section!\n",
1543 pszParmName));
1544 return true;
1546 parm_ptr = ((char *)service) + parm_table[parmnum].offset;
1548 if (!service->copymap)
1549 init_copymap(service);
1551 /* this handles the aliases - set the copymap for other
1552 * entries with the same data pointer */
1553 for (i = 0; parm_table[i].label; i++)
1554 if (parm_table[i].offset == parm_table[parmnum].offset &&
1555 parm_table[i].p_class == parm_table[parmnum].p_class)
1556 bitmap_clear(service->copymap, i);
1558 return set_variable(service, parmnum, parm_ptr, pszParmName,
1559 pszParmValue, lp_ctx, false);
1563 * Process a parameter.
1566 static bool do_parameter(const char *pszParmName, const char *pszParmValue,
1567 void *userdata)
1569 struct loadparm_context *lp_ctx = (struct loadparm_context *)userdata;
1571 if (lp_ctx->bInGlobalSection)
1572 return lpcfg_do_global_parameter(lp_ctx, pszParmName,
1573 pszParmValue);
1574 else
1575 return lpcfg_do_service_parameter(lp_ctx, lp_ctx->currentService,
1576 pszParmName, pszParmValue);
1580 variable argument do parameter
1582 bool lpcfg_do_global_parameter_var(struct loadparm_context *lp_ctx, const char *pszParmName, const char *fmt, ...) PRINTF_ATTRIBUTE(3, 4);
1583 bool lpcfg_do_global_parameter_var(struct loadparm_context *lp_ctx,
1584 const char *pszParmName, const char *fmt, ...)
1586 char *s;
1587 bool ret;
1588 va_list ap;
1590 va_start(ap, fmt);
1591 s = talloc_vasprintf(NULL, fmt, ap);
1592 va_end(ap);
1593 ret = lpcfg_do_global_parameter(lp_ctx, pszParmName, s);
1594 talloc_free(s);
1595 return ret;
1600 set a parameter from the commandline - this is called from command line parameter
1601 parsing code. It sets the parameter then marks the parameter as unable to be modified
1602 by smb.conf processing
1604 bool lpcfg_set_cmdline(struct loadparm_context *lp_ctx, const char *pszParmName,
1605 const char *pszParmValue)
1607 int parmnum;
1608 int i;
1610 while (isspace((unsigned char)*pszParmValue)) pszParmValue++;
1612 if (lp_ctx->s3_fns) {
1613 return lp_ctx->s3_fns->set_cmdline(pszParmName, pszParmValue);
1616 parmnum = lpcfg_map_parameter(pszParmName);
1618 if (parmnum < 0 && strchr(pszParmName, ':')) {
1619 /* set a parametric option */
1620 return lp_do_parameter_parametric(lp_ctx, NULL, pszParmName,
1621 pszParmValue, FLAG_CMDLINE);
1624 if (parmnum < 0) {
1625 DEBUG(0,("Unknown option '%s'\n", pszParmName));
1626 return false;
1629 /* reset the CMDLINE flag in case this has been called before */
1630 lp_ctx->flags[parmnum] &= ~FLAG_CMDLINE;
1632 if (!lpcfg_do_global_parameter(lp_ctx, pszParmName, pszParmValue)) {
1633 return false;
1636 lp_ctx->flags[parmnum] |= FLAG_CMDLINE;
1638 /* we have to also set FLAG_CMDLINE on aliases */
1639 for (i=parmnum-1;
1640 i>=0 && parm_table[i].p_class == parm_table[parmnum].p_class &&
1641 parm_table[i].offset == parm_table[parmnum].offset;
1642 i--) {
1643 lp_ctx->flags[i] |= FLAG_CMDLINE;
1645 for (i=parmnum+1;
1646 i<NUMPARAMETERS &&
1647 parm_table[i].p_class == parm_table[parmnum].p_class &&
1648 parm_table[i].offset == parm_table[parmnum].offset;
1649 i++) {
1650 lp_ctx->flags[i] |= FLAG_CMDLINE;
1653 return true;
1657 set a option from the commandline in 'a=b' format. Use to support --option
1659 bool lpcfg_set_option(struct loadparm_context *lp_ctx, const char *option)
1661 char *p, *s;
1662 bool ret;
1664 s = talloc_strdup(NULL, option);
1665 if (!s) {
1666 return false;
1669 p = strchr(s, '=');
1670 if (!p) {
1671 talloc_free(s);
1672 return false;
1675 *p = 0;
1677 ret = lpcfg_set_cmdline(lp_ctx, s, p+1);
1678 talloc_free(s);
1679 return ret;
1683 #define BOOLSTR(b) ((b) ? "Yes" : "No")
1686 * Print a parameter of the specified type.
1689 void lpcfg_print_parameter(struct parm_struct *p, void *ptr, FILE * f)
1691 /* For the seperation of lists values that we print below */
1692 const char *list_sep = ", ";
1693 int i;
1694 switch (p->type)
1696 case P_ENUM:
1697 for (i = 0; p->enum_list[i].name; i++) {
1698 if (*(int *)ptr == p->enum_list[i].value) {
1699 fprintf(f, "%s",
1700 p->enum_list[i].name);
1701 break;
1704 break;
1706 case P_BOOL:
1707 fprintf(f, "%s", BOOLSTR(*(bool *)ptr));
1708 break;
1710 case P_BOOLREV:
1711 fprintf(f, "%s", BOOLSTR(!*(bool *)ptr));
1712 break;
1714 case P_INTEGER:
1715 case P_BYTES:
1716 fprintf(f, "%d", *(int *)ptr);
1717 break;
1719 case P_CHAR:
1720 fprintf(f, "%c", *(char *)ptr);
1721 break;
1723 case P_OCTAL: {
1724 int val = *(int *)ptr;
1725 if (val == -1) {
1726 fprintf(f, "-1");
1727 } else {
1728 fprintf(f, "0%03o", val);
1730 break;
1733 case P_CMDLIST:
1734 list_sep = " ";
1735 /* fall through */
1736 case P_LIST:
1737 if ((char ***)ptr && *(char ***)ptr) {
1738 char **list = *(char ***)ptr;
1739 for (; *list; list++) {
1740 /* surround strings with whitespace in double quotes */
1741 if (*(list+1) == NULL) {
1742 /* last item, no extra separator */
1743 list_sep = "";
1745 if ( strchr_m( *list, ' ' ) ) {
1746 fprintf(f, "\"%s\"%s", *list, list_sep);
1747 } else {
1748 fprintf(f, "%s%s", *list, list_sep);
1752 break;
1754 case P_STRING:
1755 case P_USTRING:
1756 if (*(char **)ptr) {
1757 fprintf(f, "%s", *(char **)ptr);
1759 break;
1760 case P_SEP:
1761 break;
1766 * Check if two parameters are equal.
1769 bool lpcfg_equal_parameter(parm_type type, void *ptr1, void *ptr2)
1771 switch (type) {
1772 case P_BOOL:
1773 case P_BOOLREV:
1774 return (*((bool *)ptr1) == *((bool *)ptr2));
1776 case P_INTEGER:
1777 case P_ENUM:
1778 case P_OCTAL:
1779 case P_BYTES:
1780 return (*((int *)ptr1) == *((int *)ptr2));
1782 case P_CHAR:
1783 return (*((char *)ptr1) == *((char *)ptr2));
1785 case P_LIST:
1786 case P_CMDLIST:
1787 return str_list_equal(*(const char ***)ptr1, *(const char ***)ptr2);
1789 case P_STRING:
1790 case P_USTRING:
1792 char *p1 = *(char **)ptr1, *p2 = *(char **)ptr2;
1793 if (p1 && !*p1)
1794 p1 = NULL;
1795 if (p2 && !*p2)
1796 p2 = NULL;
1797 return (p1 == p2 || strequal(p1, p2));
1799 case P_SEP:
1800 break;
1802 return false;
1806 * Process a new section (service).
1808 * At this stage all sections are services.
1809 * Later we'll have special sections that permit server parameters to be set.
1810 * Returns True on success, False on failure.
1813 static bool do_section(const char *pszSectionName, void *userdata)
1815 struct loadparm_context *lp_ctx = (struct loadparm_context *)userdata;
1816 bool bRetval;
1817 bool isglobal = ((strwicmp(pszSectionName, GLOBAL_NAME) == 0) ||
1818 (strwicmp(pszSectionName, GLOBAL_NAME2) == 0));
1819 bRetval = false;
1821 /* if we've just struck a global section, note the fact. */
1822 lp_ctx->bInGlobalSection = isglobal;
1824 /* check for multiple global sections */
1825 if (lp_ctx->bInGlobalSection) {
1826 DEBUG(4, ("Processing section \"[%s]\"\n", pszSectionName));
1827 return true;
1830 /* if we have a current service, tidy it up before moving on */
1831 bRetval = true;
1833 if (lp_ctx->currentService != NULL)
1834 bRetval = lpcfg_service_ok(lp_ctx->currentService);
1836 /* if all is still well, move to the next record in the services array */
1837 if (bRetval) {
1838 /* We put this here to avoid an odd message order if messages are */
1839 /* issued by the post-processing of a previous section. */
1840 DEBUG(4, ("Processing section \"[%s]\"\n", pszSectionName));
1842 if ((lp_ctx->currentService = lpcfg_add_service(lp_ctx, lp_ctx->sDefault,
1843 pszSectionName))
1844 == NULL) {
1845 DEBUG(0, ("Failed to add a new service\n"));
1846 return false;
1850 return bRetval;
1855 * Determine if a particular base parameter is currently set to the default value.
1858 static bool is_default(struct loadparm_service *sDefault, int i)
1860 void *def_ptr = ((char *)sDefault) + parm_table[i].offset;
1861 switch (parm_table[i].type) {
1862 case P_CMDLIST:
1863 case P_LIST:
1864 return str_list_equal((const char * const *)parm_table[i].def.lvalue,
1865 (const char **)def_ptr);
1866 case P_STRING:
1867 case P_USTRING:
1868 return strequal(parm_table[i].def.svalue,
1869 *(char **)def_ptr);
1870 case P_BOOL:
1871 case P_BOOLREV:
1872 return parm_table[i].def.bvalue ==
1873 *(bool *)def_ptr;
1874 case P_INTEGER:
1875 case P_CHAR:
1876 case P_OCTAL:
1877 case P_BYTES:
1878 case P_ENUM:
1879 return parm_table[i].def.ivalue ==
1880 *(int *)def_ptr;
1881 case P_SEP:
1882 break;
1884 return false;
1888 *Display the contents of the global structure.
1891 static void dump_globals(struct loadparm_context *lp_ctx, FILE *f,
1892 bool show_defaults)
1894 int i;
1895 struct parmlist_entry *data;
1897 fprintf(f, "# Global parameters\n[global]\n");
1899 for (i = 0; parm_table[i].label; i++)
1900 if (parm_table[i].p_class == P_GLOBAL &&
1901 (i == 0 || (parm_table[i].offset != parm_table[i - 1].offset))) {
1902 if (!show_defaults && (lp_ctx->flags[i] & FLAG_DEFAULT))
1903 continue;
1904 fprintf(f, "\t%s = ", parm_table[i].label);
1905 lpcfg_print_parameter(&parm_table[i], lpcfg_parm_ptr(lp_ctx, NULL, &parm_table[i]), f);
1906 fprintf(f, "\n");
1908 if (lp_ctx->globals->param_opt != NULL) {
1909 for (data = lp_ctx->globals->param_opt; data;
1910 data = data->next) {
1911 if (!show_defaults && (data->priority & FLAG_DEFAULT)) {
1912 continue;
1914 fprintf(f, "\t%s = %s\n", data->key, data->value);
1921 * Display the contents of a single services record.
1924 static void dump_a_service(struct loadparm_service * pService, struct loadparm_service *sDefault, FILE * f,
1925 unsigned int *flags)
1927 int i;
1928 struct parmlist_entry *data;
1930 if (pService != sDefault)
1931 fprintf(f, "\n[%s]\n", pService->szService);
1933 for (i = 0; parm_table[i].label; i++) {
1934 if (parm_table[i].p_class == P_LOCAL &&
1935 (*parm_table[i].label != '-') &&
1936 (i == 0 || (parm_table[i].offset != parm_table[i - 1].offset)))
1938 if (pService == sDefault) {
1939 if (flags && (flags[i] & FLAG_DEFAULT)) {
1940 continue;
1942 if (defaults_saved) {
1943 if (is_default(sDefault, i)) {
1944 continue;
1947 } else {
1948 if (lpcfg_equal_parameter(parm_table[i].type,
1949 ((char *)pService) +
1950 parm_table[i].offset,
1951 ((char *)sDefault) +
1952 parm_table[i].offset))
1953 continue;
1956 fprintf(f, "\t%s = ", parm_table[i].label);
1957 lpcfg_print_parameter(&parm_table[i],
1958 ((char *)pService) + parm_table[i].offset, f);
1959 fprintf(f, "\n");
1962 if (pService->param_opt != NULL) {
1963 for (data = pService->param_opt; data; data = data->next) {
1964 fprintf(f, "\t%s = %s\n", data->key, data->value);
1969 bool lpcfg_dump_a_parameter(struct loadparm_context *lp_ctx,
1970 struct loadparm_service *service,
1971 const char *parm_name, FILE * f)
1973 struct parm_struct *parm;
1974 void *ptr;
1976 parm = lpcfg_parm_struct(lp_ctx, parm_name);
1977 if (!parm) {
1978 return false;
1981 if (service != NULL && parm->p_class == P_GLOBAL) {
1982 return false;
1985 ptr = lpcfg_parm_ptr(lp_ctx, service,parm);
1987 lpcfg_print_parameter(parm, ptr, f);
1988 fprintf(f, "\n");
1989 return true;
1993 * Auto-load some home services.
1995 static void lpcfg_add_auto_services(struct loadparm_context *lp_ctx,
1996 const char *str)
1998 return;
2003 * Unload unused services.
2006 void lpcfg_killunused(struct loadparm_context *lp_ctx,
2007 struct smbsrv_connection *smb,
2008 bool (*snumused) (struct smbsrv_connection *, int))
2010 int i;
2011 for (i = 0; i < lp_ctx->iNumServices; i++) {
2012 if (lp_ctx->services[i] == NULL)
2013 continue;
2015 if (!snumused || !snumused(smb, i)) {
2016 talloc_free(lp_ctx->services[i]);
2017 lp_ctx->services[i] = NULL;
2023 static int lpcfg_destructor(struct loadparm_context *lp_ctx)
2025 struct parmlist_entry *data;
2027 if (lp_ctx->refuse_free) {
2028 /* someone is trying to free the
2029 global_loadparm_context.
2030 We can't allow that. */
2031 return -1;
2034 if (lp_ctx->globals->param_opt != NULL) {
2035 struct parmlist_entry *next;
2036 for (data = lp_ctx->globals->param_opt; data; data=next) {
2037 next = data->next;
2038 if (data->priority & FLAG_CMDLINE) continue;
2039 DLIST_REMOVE(lp_ctx->globals->param_opt, data);
2040 talloc_free(data);
2044 return 0;
2048 * Initialise the global parameter structure.
2050 * Note that most callers should use loadparm_init_global() instead
2052 struct loadparm_context *loadparm_init(TALLOC_CTX *mem_ctx)
2054 int i;
2055 char *myname;
2056 struct loadparm_context *lp_ctx;
2057 struct parmlist_entry *parm;
2058 char *logfile;
2060 lp_ctx = talloc_zero(mem_ctx, struct loadparm_context);
2061 if (lp_ctx == NULL)
2062 return NULL;
2064 talloc_set_destructor(lp_ctx, lpcfg_destructor);
2065 lp_ctx->bInGlobalSection = true;
2066 lp_ctx->globals = talloc_zero(lp_ctx, struct loadparm_global);
2067 /* This appears odd, but globals in s3 isn't a pointer */
2068 lp_ctx->globals->ctx = lp_ctx->globals;
2069 lp_ctx->sDefault = talloc_zero(lp_ctx, struct loadparm_service);
2070 lp_ctx->flags = talloc_zero_array(lp_ctx, unsigned int, NUMPARAMETERS);
2072 lp_ctx->sDefault->iMaxPrintJobs = 1000;
2073 lp_ctx->sDefault->bAvailable = true;
2074 lp_ctx->sDefault->browseable = true;
2075 lp_ctx->sDefault->read_only = true;
2076 lp_ctx->sDefault->map_archive = true;
2077 lp_ctx->sDefault->strict_locking = true;
2078 lp_ctx->sDefault->oplocks = true;
2079 lp_ctx->sDefault->create_mask = 0744;
2080 lp_ctx->sDefault->force_create_mode = 0000;
2081 lp_ctx->sDefault->directory_mask = 0755;
2082 lp_ctx->sDefault->force_directory_mode = 0000;
2084 DEBUG(3, ("Initialising global parameters\n"));
2086 for (i = 0; parm_table[i].label; i++) {
2087 if ((parm_table[i].type == P_STRING ||
2088 parm_table[i].type == P_USTRING) &&
2089 !(lp_ctx->flags[i] & FLAG_CMDLINE)) {
2090 char **r;
2091 if (parm_table[i].p_class == P_LOCAL) {
2092 r = (char **)(((char *)lp_ctx->sDefault) + parm_table[i].offset);
2093 } else {
2094 r = (char **)(((char *)lp_ctx->globals) + parm_table[i].offset);
2096 *r = talloc_strdup(lp_ctx, "");
2100 logfile = talloc_asprintf(lp_ctx, "%s/log.samba", dyn_LOGFILEBASE);
2101 lpcfg_do_global_parameter(lp_ctx, "log file", logfile);
2102 talloc_free(logfile);
2104 lpcfg_do_global_parameter(lp_ctx, "log level", "0");
2106 lpcfg_do_global_parameter(lp_ctx, "syslog", "1");
2107 lpcfg_do_global_parameter(lp_ctx, "syslog only", "No");
2108 lpcfg_do_global_parameter(lp_ctx, "debug timestamp", "Yes");
2109 lpcfg_do_global_parameter(lp_ctx, "debug prefix timestamp", "No");
2110 lpcfg_do_global_parameter(lp_ctx, "debug hires timestamp", "Yes");
2111 lpcfg_do_global_parameter(lp_ctx, "debug pid", "No");
2112 lpcfg_do_global_parameter(lp_ctx, "debug uid", "No");
2113 lpcfg_do_global_parameter(lp_ctx, "debug class", "No");
2115 lpcfg_do_global_parameter(lp_ctx, "share backend", "classic");
2117 lpcfg_do_global_parameter(lp_ctx, "server role", "auto");
2118 lpcfg_do_global_parameter(lp_ctx, "domain logons", "No");
2119 lpcfg_do_global_parameter(lp_ctx, "domain master", "Auto");
2121 /* options that can be set on the command line must be initialised via
2122 the slower lpcfg_do_global_parameter() to ensure that FLAG_CMDLINE is obeyed */
2123 #ifdef TCP_NODELAY
2124 lpcfg_do_global_parameter(lp_ctx, "socket options", "TCP_NODELAY");
2125 #endif
2126 lpcfg_do_global_parameter(lp_ctx, "workgroup", DEFAULT_WORKGROUP);
2127 myname = get_myname(lp_ctx);
2128 lpcfg_do_global_parameter(lp_ctx, "netbios name", myname);
2129 talloc_free(myname);
2130 lpcfg_do_global_parameter(lp_ctx, "name resolve order", "lmhosts wins host bcast");
2132 lpcfg_do_global_parameter(lp_ctx, "fstype", "NTFS");
2134 lpcfg_do_global_parameter(lp_ctx, "ntvfs handler", "unixuid default");
2135 lpcfg_do_global_parameter(lp_ctx, "max connections", "0");
2137 lpcfg_do_global_parameter(lp_ctx, "dcerpc endpoint servers", "epmapper wkssvc rpcecho samr netlogon lsarpc spoolss drsuapi dssetup unixinfo browser eventlog6 backupkey dnsserver");
2138 lpcfg_do_global_parameter(lp_ctx, "server services", "s3fs rpc nbt wrepl ldap cldap kdc drepl winbind ntp_signd kcc dnsupdate dns");
2139 lpcfg_do_global_parameter(lp_ctx, "kccsrv:samba_kcc", "true");
2140 /* the winbind method for domain controllers is for both RODC
2141 auth forwarding and for trusted domains */
2142 lpcfg_do_global_parameter(lp_ctx, "private dir", dyn_PRIVATE_DIR);
2143 lpcfg_do_global_parameter(lp_ctx, "registry:HKEY_LOCAL_MACHINE", "hklm.ldb");
2145 /* This hive should be dynamically generated by Samba using
2146 data from the sam, but for the moment leave it in a tdb to
2147 keep regedt32 from popping up an annoying dialog. */
2148 lpcfg_do_global_parameter(lp_ctx, "registry:HKEY_USERS", "hku.ldb");
2150 /* using UTF8 by default allows us to support all chars */
2151 lpcfg_do_global_parameter(lp_ctx, "unix charset", "UTF-8");
2153 /* Use codepage 850 as a default for the dos character set */
2154 lpcfg_do_global_parameter(lp_ctx, "dos charset", "CP850");
2157 * Allow the default PASSWD_CHAT to be overridden in local.h.
2159 lpcfg_do_global_parameter(lp_ctx, "passwd chat", DEFAULT_PASSWD_CHAT);
2161 lpcfg_do_global_parameter(lp_ctx, "pid directory", dyn_PIDDIR);
2162 lpcfg_do_global_parameter(lp_ctx, "lock dir", dyn_LOCKDIR);
2163 lpcfg_do_global_parameter(lp_ctx, "state directory", dyn_STATEDIR);
2164 lpcfg_do_global_parameter(lp_ctx, "cache directory", dyn_CACHEDIR);
2165 lpcfg_do_global_parameter(lp_ctx, "ncalrpc dir", dyn_NCALRPCDIR);
2167 lpcfg_do_global_parameter(lp_ctx, "nbt client socket address", "0.0.0.0");
2168 lpcfg_do_global_parameter_var(lp_ctx, "server string",
2169 "Samba %s", SAMBA_VERSION_STRING);
2171 lpcfg_do_global_parameter(lp_ctx, "password server", "*");
2173 lpcfg_do_global_parameter(lp_ctx, "max mux", "50");
2174 lpcfg_do_global_parameter(lp_ctx, "max xmit", "16644");
2175 lpcfg_do_global_parameter(lp_ctx, "host msdfs", "true");
2177 lpcfg_do_global_parameter(lp_ctx, "LargeReadwrite", "True");
2178 lpcfg_do_global_parameter(lp_ctx, "server min protocol", "LANMAN1");
2179 lpcfg_do_global_parameter(lp_ctx, "server max protocol", "SMB3");
2180 lpcfg_do_global_parameter(lp_ctx, "client min protocol", "CORE");
2181 lpcfg_do_global_parameter(lp_ctx, "client max protocol", "NT1");
2182 lpcfg_do_global_parameter(lp_ctx, "security", "AUTO");
2183 lpcfg_do_global_parameter(lp_ctx, "EncryptPasswords", "True");
2184 lpcfg_do_global_parameter(lp_ctx, "ReadRaw", "True");
2185 lpcfg_do_global_parameter(lp_ctx, "WriteRaw", "True");
2186 lpcfg_do_global_parameter(lp_ctx, "NullPasswords", "False");
2187 lpcfg_do_global_parameter(lp_ctx, "old password allowed period", "60");
2188 lpcfg_do_global_parameter(lp_ctx, "ObeyPamRestrictions", "False");
2190 lpcfg_do_global_parameter(lp_ctx, "TimeServer", "False");
2191 lpcfg_do_global_parameter(lp_ctx, "BindInterfacesOnly", "False");
2192 lpcfg_do_global_parameter(lp_ctx, "Unicode", "True");
2193 lpcfg_do_global_parameter(lp_ctx, "ClientLanManAuth", "False");
2194 lpcfg_do_global_parameter(lp_ctx, "ClientNTLMv2Auth", "True");
2195 lpcfg_do_global_parameter(lp_ctx, "LanmanAuth", "False");
2196 lpcfg_do_global_parameter(lp_ctx, "NTLMAuth", "True");
2197 lpcfg_do_global_parameter(lp_ctx, "client use spnego principal", "False");
2199 lpcfg_do_global_parameter(lp_ctx, "UnixExtensions", "True");
2201 lpcfg_do_global_parameter(lp_ctx, "PreferredMaster", "Auto");
2202 lpcfg_do_global_parameter(lp_ctx, "LocalMaster", "True");
2204 lpcfg_do_global_parameter(lp_ctx, "wins support", "False");
2205 lpcfg_do_global_parameter(lp_ctx, "dns proxy", "True");
2207 lpcfg_do_global_parameter(lp_ctx, "winbind separator", "\\");
2208 lpcfg_do_global_parameter(lp_ctx, "winbind sealed pipes", "True");
2209 lpcfg_do_global_parameter(lp_ctx, "require strong key", "True");
2210 lpcfg_do_global_parameter(lp_ctx, "winbindd socket directory", dyn_WINBINDD_SOCKET_DIR);
2211 lpcfg_do_global_parameter(lp_ctx, "winbindd privileged socket directory", dyn_WINBINDD_PRIVILEGED_SOCKET_DIR);
2212 lpcfg_do_global_parameter(lp_ctx, "ntp signd socket directory", dyn_NTP_SIGND_SOCKET_DIR);
2213 lpcfg_do_global_parameter_var(lp_ctx, "dns update command", "%s/samba_dnsupdate", dyn_SCRIPTSBINDIR);
2214 lpcfg_do_global_parameter_var(lp_ctx, "spn update command", "%s/samba_spnupdate", dyn_SCRIPTSBINDIR);
2215 lpcfg_do_global_parameter_var(lp_ctx, "samba kcc command",
2216 "%s/samba_kcc", dyn_SCRIPTSBINDIR);
2217 lpcfg_do_global_parameter(lp_ctx, "template shell", "/bin/false");
2218 lpcfg_do_global_parameter(lp_ctx, "template homedir", "/home/%WORKGROUP%/%ACCOUNTNAME%");
2220 lpcfg_do_global_parameter(lp_ctx, "client signing", "default");
2221 lpcfg_do_global_parameter(lp_ctx, "server signing", "default");
2223 lpcfg_do_global_parameter(lp_ctx, "use spnego", "True");
2225 lpcfg_do_global_parameter(lp_ctx, "use mmap", "True");
2227 lpcfg_do_global_parameter(lp_ctx, "smb ports", "445 139");
2228 lpcfg_do_global_parameter(lp_ctx, "nbt port", "137");
2229 lpcfg_do_global_parameter(lp_ctx, "dgram port", "138");
2230 lpcfg_do_global_parameter(lp_ctx, "cldap port", "389");
2231 lpcfg_do_global_parameter(lp_ctx, "krb5 port", "88");
2232 lpcfg_do_global_parameter(lp_ctx, "kpasswd port", "464");
2233 lpcfg_do_global_parameter(lp_ctx, "web port", "901");
2235 lpcfg_do_global_parameter(lp_ctx, "nt status support", "True");
2237 lpcfg_do_global_parameter(lp_ctx, "max wins ttl", "518400"); /* 6 days */
2238 lpcfg_do_global_parameter(lp_ctx, "min wins ttl", "21600");
2240 lpcfg_do_global_parameter(lp_ctx, "tls enabled", "True");
2241 lpcfg_do_global_parameter(lp_ctx, "tls keyfile", "tls/key.pem");
2242 lpcfg_do_global_parameter(lp_ctx, "tls certfile", "tls/cert.pem");
2243 lpcfg_do_global_parameter(lp_ctx, "tls cafile", "tls/ca.pem");
2244 lpcfg_do_global_parameter(lp_ctx, "prefork children:smb", "4");
2246 lpcfg_do_global_parameter(lp_ctx, "rndc command", "/usr/sbin/rndc");
2247 lpcfg_do_global_parameter(lp_ctx, "nsupdate command", "/usr/bin/nsupdate -g");
2249 lpcfg_do_global_parameter(lp_ctx, "allow dns updates", "secure only");
2250 lpcfg_do_global_parameter(lp_ctx, "dns forwarder", "");
2252 lpcfg_do_global_parameter(lp_ctx, "algorithmic rid base", "1000");
2254 lpcfg_do_global_parameter(lp_ctx, "enhanced browsing", "True");
2256 lpcfg_do_global_parameter(lp_ctx, "winbind nss info", "template");
2258 lpcfg_do_global_parameter(lp_ctx, "server schannel", "Auto");
2260 lpcfg_do_global_parameter(lp_ctx, "short preserve case", "True");
2262 lpcfg_do_global_parameter(lp_ctx, "max open files", "16384");
2264 lpcfg_do_global_parameter(lp_ctx, "cups connection timeout", "30");
2266 lpcfg_do_global_parameter(lp_ctx, "locking", "True");
2268 lpcfg_do_global_parameter(lp_ctx, "block size", "1024");
2270 lpcfg_do_global_parameter(lp_ctx, "client use spnego", "True");
2272 lpcfg_do_global_parameter(lp_ctx, "change notify", "True");
2274 lpcfg_do_global_parameter(lp_ctx, "name cache timeout", "660");
2276 lpcfg_do_global_parameter(lp_ctx, "defer sharing violations", "True");
2278 lpcfg_do_global_parameter(lp_ctx, "ldap replication sleep", "1000");
2280 lpcfg_do_global_parameter(lp_ctx, "idmap backend", "tdb");
2282 lpcfg_do_global_parameter(lp_ctx, "enable privileges", "True");
2284 lpcfg_do_global_parameter_var(lp_ctx, "smb2 max write", "%u", DEFAULT_SMB2_MAX_WRITE);
2286 lpcfg_do_global_parameter(lp_ctx, "passdb backend", "tdbsam");
2288 lpcfg_do_global_parameter(lp_ctx, "getwd cache", "True");
2290 lpcfg_do_global_parameter(lp_ctx, "winbind nested groups", "True");
2292 lpcfg_do_global_parameter(lp_ctx, "mangled names", "True");
2294 lpcfg_do_global_parameter_var(lp_ctx, "smb2 max credits", "%u", DEFAULT_SMB2_MAX_CREDITS);
2296 lpcfg_do_global_parameter(lp_ctx, "ldap ssl", "start tls");
2298 lpcfg_do_global_parameter(lp_ctx, "ldap deref", "auto");
2300 lpcfg_do_global_parameter(lp_ctx, "lm interval", "60");
2302 lpcfg_do_global_parameter(lp_ctx, "mangling method", "hash2");
2304 lpcfg_do_global_parameter(lp_ctx, "hide dot files", "True");
2306 lpcfg_do_global_parameter(lp_ctx, "browse list", "True");
2308 lpcfg_do_global_parameter(lp_ctx, "passwd chat timeout", "2");
2310 lpcfg_do_global_parameter(lp_ctx, "guest account", GUEST_ACCOUNT);
2312 lpcfg_do_global_parameter(lp_ctx, "client schannel", "auto");
2314 lpcfg_do_global_parameter(lp_ctx, "smb encrypt", "default");
2316 lpcfg_do_global_parameter(lp_ctx, "max log size", "5000");
2318 lpcfg_do_global_parameter(lp_ctx, "idmap negative cache time", "120");
2320 lpcfg_do_global_parameter(lp_ctx, "ldap follow referral", "auto");
2322 lpcfg_do_global_parameter(lp_ctx, "multicast dns register", "yes");
2324 lpcfg_do_global_parameter(lp_ctx, "winbind reconnect delay", "30");
2326 lpcfg_do_global_parameter(lp_ctx, "nt acl support", "yes");
2328 lpcfg_do_global_parameter(lp_ctx, "acl check permissions", "yes");
2330 lpcfg_do_global_parameter(lp_ctx, "keepalive", "300");
2332 lpcfg_do_global_parameter(lp_ctx, "winbind cache time", "300");
2334 lpcfg_do_global_parameter(lp_ctx, "level2 oplocks", "yes");
2336 lpcfg_do_global_parameter(lp_ctx, "show add printer wizard", "yes");
2338 lpcfg_do_global_parameter(lp_ctx, "allocation roundup size", "1048576");
2340 lpcfg_do_global_parameter(lp_ctx, "ldap page size", "1024");
2342 lpcfg_do_global_parameter(lp_ctx, "kernel share modes", "yes");
2344 lpcfg_do_global_parameter(lp_ctx, "strict locking", "Auto");
2346 lpcfg_do_global_parameter(lp_ctx, "map readonly", "yes");
2348 lpcfg_do_global_parameter(lp_ctx, "allow trusted domains", "yes");
2350 lpcfg_do_global_parameter(lp_ctx, "default devmode", "yes");
2352 lpcfg_do_global_parameter(lp_ctx, "os level", "20");
2354 lpcfg_do_global_parameter(lp_ctx, "dos filetimes", "yes");
2356 lpcfg_do_global_parameter(lp_ctx, "mangling char", "~");
2358 lpcfg_do_global_parameter(lp_ctx, "printcap cache time", "750");
2360 lpcfg_do_global_parameter(lp_ctx, "create krb5 conf", "yes");
2362 lpcfg_do_global_parameter(lp_ctx, "winbind max clients", "200");
2364 lpcfg_do_global_parameter(lp_ctx, "acl map full control", "yes");
2366 lpcfg_do_global_parameter(lp_ctx, "nt pipe support", "yes");
2368 lpcfg_do_global_parameter(lp_ctx, "ldap debug threshold", "10");
2370 lpcfg_do_global_parameter(lp_ctx, "follow symlinks", "yes");
2372 lpcfg_do_global_parameter(lp_ctx, "machine password timeout", "604800");
2374 lpcfg_do_global_parameter(lp_ctx, "ldap connection timeout", "2");
2376 lpcfg_do_global_parameter(lp_ctx, "winbind expand groups", "1");
2378 lpcfg_do_global_parameter(lp_ctx, "stat cache", "yes");
2380 lpcfg_do_global_parameter(lp_ctx, "lpq cache time", "30");
2382 lpcfg_do_global_parameter_var(lp_ctx, "smb2 max trans", "%u", DEFAULT_SMB2_MAX_TRANSACT);
2384 lpcfg_do_global_parameter_var(lp_ctx, "smb2 max read", "%u", DEFAULT_SMB2_MAX_READ);
2386 lpcfg_do_global_parameter(lp_ctx, "durable handles", "yes");
2388 lpcfg_do_global_parameter(lp_ctx, "max stat cache size", "256");
2390 lpcfg_do_global_parameter(lp_ctx, "ldap passwd sync", "no");
2392 lpcfg_do_global_parameter(lp_ctx, "kernel change notify", "yes");
2394 lpcfg_do_global_parameter(lp_ctx, "max ttl", "259200");
2396 lpcfg_do_global_parameter(lp_ctx, "blocking locks", "yes");
2398 lpcfg_do_global_parameter(lp_ctx, "oplock contention limit", "2");
2400 lpcfg_do_global_parameter(lp_ctx, "load printers", "yes");
2402 lpcfg_do_global_parameter(lp_ctx, "idmap cache time", "604800");
2404 lpcfg_do_global_parameter(lp_ctx, "preserve case", "yes");
2406 lpcfg_do_global_parameter(lp_ctx, "lm announce", "auto");
2408 lpcfg_do_global_parameter(lp_ctx, "afs token lifetime", "604800");
2410 lpcfg_do_global_parameter(lp_ctx, "enable core files", "yes");
2412 lpcfg_do_global_parameter(lp_ctx, "winbind max domain connections", "1");
2414 lpcfg_do_global_parameter(lp_ctx, "case sensitive", "auto");
2416 lpcfg_do_global_parameter(lp_ctx, "ldap timeout", "15");
2418 lpcfg_do_global_parameter(lp_ctx, "mangle prefix", "1");
2420 lpcfg_do_global_parameter(lp_ctx, "posix locking", "yes");
2422 lpcfg_do_global_parameter(lp_ctx, "lock spin time", "200");
2424 lpcfg_do_global_parameter(lp_ctx, "directory name cache size", "100");
2426 lpcfg_do_global_parameter(lp_ctx, "nmbd bind explicit broadcast", "yes");
2428 lpcfg_do_global_parameter(lp_ctx, "init logon delay", "100");
2430 lpcfg_do_global_parameter(lp_ctx, "usershare owner only", "yes");
2432 lpcfg_do_global_parameter(lp_ctx, "-valid", "yes");
2434 lpcfg_do_global_parameter_var(lp_ctx, "usershare path", "%s/usershares", get_dyn_STATEDIR());
2436 #ifdef DEVELOPER
2437 lpcfg_do_global_parameter_var(lp_ctx, "panic action", "/bin/sleep 999999999");
2438 #endif
2440 lpcfg_do_global_parameter(lp_ctx, "smb passwd file", get_dyn_SMB_PASSWD_FILE());
2442 lpcfg_do_global_parameter(lp_ctx, "logon home", "\\\\%N\\%U");
2444 lpcfg_do_global_parameter(lp_ctx, "logon path", "\\\\%N\\%U\\profile");
2446 lpcfg_do_global_parameter(lp_ctx, "printjob username", "%U");
2448 for (i = 0; parm_table[i].label; i++) {
2449 if (!(lp_ctx->flags[i] & FLAG_CMDLINE)) {
2450 lp_ctx->flags[i] |= FLAG_DEFAULT;
2454 for (parm=lp_ctx->globals->param_opt; parm; parm=parm->next) {
2455 if (!(parm->priority & FLAG_CMDLINE)) {
2456 parm->priority |= FLAG_DEFAULT;
2460 return lp_ctx;
2464 * Initialise the global parameter structure.
2466 struct loadparm_context *loadparm_init_global(bool load_default)
2468 if (global_loadparm_context == NULL) {
2469 global_loadparm_context = loadparm_init(NULL);
2471 if (global_loadparm_context == NULL) {
2472 return NULL;
2474 global_loadparm_context->global = true;
2475 if (load_default && !global_loadparm_context->loaded) {
2476 lpcfg_load_default(global_loadparm_context);
2478 global_loadparm_context->refuse_free = true;
2479 return global_loadparm_context;
2483 * Initialise the global parameter structure.
2485 struct loadparm_context *loadparm_init_s3(TALLOC_CTX *mem_ctx,
2486 const struct loadparm_s3_helpers *s3_fns)
2488 struct loadparm_context *loadparm_context = talloc_zero(mem_ctx, struct loadparm_context);
2489 if (!loadparm_context) {
2490 return NULL;
2492 loadparm_context->s3_fns = s3_fns;
2493 loadparm_context->globals = s3_fns->globals;
2494 return loadparm_context;
2497 const char *lpcfg_configfile(struct loadparm_context *lp_ctx)
2499 return lp_ctx->szConfigFile;
2502 const char *lp_default_path(void)
2504 if (getenv("SMB_CONF_PATH"))
2505 return getenv("SMB_CONF_PATH");
2506 else
2507 return dyn_CONFIGFILE;
2511 * Update the internal state of a loadparm context after settings
2512 * have changed.
2514 static bool lpcfg_update(struct loadparm_context *lp_ctx)
2516 struct debug_settings settings;
2517 TALLOC_CTX *tmp_ctx;
2519 tmp_ctx = talloc_new(lp_ctx);
2520 if (tmp_ctx == NULL) {
2521 return false;
2524 lpcfg_add_auto_services(lp_ctx, lpcfg_auto_services(lp_ctx, tmp_ctx));
2526 if (!lp_ctx->globals->wins_server_list && lp_ctx->globals->we_are_a_wins_server) {
2527 lpcfg_do_global_parameter(lp_ctx, "wins server", "127.0.0.1");
2530 if (!lp_ctx->global) {
2531 TALLOC_FREE(tmp_ctx);
2532 return true;
2535 panic_action = lp_ctx->globals->panic_action;
2537 reload_charcnv(lp_ctx);
2539 ZERO_STRUCT(settings);
2540 /* Add any more debug-related smb.conf parameters created in
2541 * future here */
2542 settings.syslog = lp_ctx->globals->syslog;
2543 settings.syslog_only = lp_ctx->globals->syslog_only;
2544 settings.timestamp_logs = lp_ctx->globals->timestamp_logs;
2545 settings.debug_prefix_timestamp = lp_ctx->globals->debug_prefix_timestamp;
2546 settings.debug_hires_timestamp = lp_ctx->globals->debug_hires_timestamp;
2547 settings.debug_pid = lp_ctx->globals->debug_pid;
2548 settings.debug_uid = lp_ctx->globals->debug_uid;
2549 settings.debug_class = lp_ctx->globals->debug_class;
2550 debug_set_settings(&settings);
2552 /* FIXME: This is a bit of a hack, but we can't use a global, since
2553 * not everything that uses lp also uses the socket library */
2554 if (lpcfg_parm_bool(lp_ctx, NULL, "socket", "testnonblock", false)) {
2555 setenv("SOCKET_TESTNONBLOCK", "1", 1);
2556 } else {
2557 unsetenv("SOCKET_TESTNONBLOCK");
2560 TALLOC_FREE(tmp_ctx);
2561 return true;
2564 bool lpcfg_load_default(struct loadparm_context *lp_ctx)
2566 const char *path;
2568 path = lp_default_path();
2570 if (!file_exist(path)) {
2571 /* We allow the default smb.conf file to not exist,
2572 * basically the equivalent of an empty file. */
2573 return lpcfg_update(lp_ctx);
2576 return lpcfg_load(lp_ctx, path);
2580 * Load the services array from the services file.
2582 * Return True on success, False on failure.
2584 bool lpcfg_load(struct loadparm_context *lp_ctx, const char *filename)
2586 char *n2;
2587 bool bRetval;
2589 filename = talloc_strdup(lp_ctx, filename);
2591 lp_ctx->szConfigFile = filename;
2593 if (lp_ctx->s3_fns) {
2594 return lp_ctx->s3_fns->load(filename);
2597 lp_ctx->bInGlobalSection = true;
2598 n2 = standard_sub_basic(lp_ctx, lp_ctx->szConfigFile);
2599 DEBUG(2, ("lpcfg_load: refreshing parameters from %s\n", n2));
2601 add_to_file_list(lp_ctx, &lp_ctx->file_lists, lp_ctx->szConfigFile, n2);
2603 /* We get sections first, so have to start 'behind' to make up */
2604 lp_ctx->currentService = NULL;
2605 bRetval = pm_process(n2, do_section, do_parameter, lp_ctx);
2607 /* finish up the last section */
2608 DEBUG(4, ("pm_process() returned %s\n", BOOLSTR(bRetval)));
2609 if (bRetval)
2610 if (lp_ctx->currentService != NULL)
2611 bRetval = lpcfg_service_ok(lp_ctx->currentService);
2613 bRetval = bRetval && lpcfg_update(lp_ctx);
2615 /* we do this unconditionally, so that it happens even
2616 for a missing smb.conf */
2617 reload_charcnv(lp_ctx);
2619 if (bRetval == true) {
2620 /* set this up so that any child python tasks will
2621 find the right smb.conf */
2622 setenv("SMB_CONF_PATH", filename, 1);
2624 /* set the context used by the lp_*() function
2625 varients */
2626 global_loadparm_context = lp_ctx;
2627 lp_ctx->loaded = true;
2630 return bRetval;
2634 * Return the max number of services.
2637 int lpcfg_numservices(struct loadparm_context *lp_ctx)
2639 if (lp_ctx->s3_fns) {
2640 return lp_ctx->s3_fns->get_numservices();
2643 return lp_ctx->iNumServices;
2647 * Display the contents of the services array in human-readable form.
2650 void lpcfg_dump(struct loadparm_context *lp_ctx, FILE *f, bool show_defaults,
2651 int maxtoprint)
2653 int iService;
2655 if (lp_ctx->s3_fns) {
2656 lp_ctx->s3_fns->dump(f, show_defaults, maxtoprint);
2657 return;
2660 defaults_saved = !show_defaults;
2662 dump_globals(lp_ctx, f, show_defaults);
2664 dump_a_service(lp_ctx->sDefault, lp_ctx->sDefault, f, lp_ctx->flags);
2666 for (iService = 0; iService < maxtoprint; iService++)
2667 lpcfg_dump_one(f, show_defaults, lp_ctx->services[iService], lp_ctx->sDefault);
2671 * Display the contents of one service in human-readable form.
2673 void lpcfg_dump_one(FILE *f, bool show_defaults, struct loadparm_service *service, struct loadparm_service *sDefault)
2675 if (service != NULL) {
2676 if (service->szService[0] == '\0')
2677 return;
2678 dump_a_service(service, sDefault, f, NULL);
2682 struct loadparm_service *lpcfg_servicebynum(struct loadparm_context *lp_ctx,
2683 int snum)
2685 if (lp_ctx->s3_fns) {
2686 return lp_ctx->s3_fns->get_servicebynum(snum);
2689 return lp_ctx->services[snum];
2692 struct loadparm_service *lpcfg_service(struct loadparm_context *lp_ctx,
2693 const char *service_name)
2695 int iService;
2696 char *serviceName;
2698 if (lp_ctx->s3_fns) {
2699 return lp_ctx->s3_fns->get_service(service_name);
2702 for (iService = lp_ctx->iNumServices - 1; iService >= 0; iService--) {
2703 if (lp_ctx->services[iService] &&
2704 lp_ctx->services[iService]->szService) {
2706 * The substitution here is used to support %U is
2707 * service names
2709 serviceName = standard_sub_basic(
2710 lp_ctx->services[iService],
2711 lp_ctx->services[iService]->szService);
2712 if (strequal(serviceName, service_name)) {
2713 talloc_free(serviceName);
2714 return lp_ctx->services[iService];
2716 talloc_free(serviceName);
2720 DEBUG(7,("lpcfg_servicenumber: couldn't find %s\n", service_name));
2721 return NULL;
2724 const char *lpcfg_servicename(const struct loadparm_service *service)
2726 return lpcfg_string((const char *)service->szService);
2730 * A useful volume label function.
2732 const char *lpcfg_volume_label(struct loadparm_service *service, struct loadparm_service *sDefault)
2734 const char *ret;
2735 ret = lpcfg_string((const char *)((service != NULL && service->volume != NULL) ?
2736 service->volume : sDefault->volume));
2737 if (!*ret)
2738 return lpcfg_servicename(service);
2739 return ret;
2743 * Return the correct printer name.
2745 const char *lpcfg_printername(struct loadparm_service *service, struct loadparm_service *sDefault)
2747 const char *ret;
2748 ret = lpcfg_string((const char *)((service != NULL && service->_printername != NULL) ?
2749 service->_printername : sDefault->_printername));
2750 if (ret == NULL || (ret != NULL && *ret == '\0'))
2751 ret = lpcfg_servicename(service);
2753 return ret;
2758 * Return the max print jobs per queue.
2760 int lpcfg_maxprintjobs(struct loadparm_service *service, struct loadparm_service *sDefault)
2762 int maxjobs = (service != NULL) ? service->iMaxPrintJobs : sDefault->iMaxPrintJobs;
2763 if (maxjobs <= 0 || maxjobs >= PRINT_MAX_JOBID)
2764 maxjobs = PRINT_MAX_JOBID - 1;
2766 return maxjobs;
2769 struct smb_iconv_handle *lpcfg_iconv_handle(struct loadparm_context *lp_ctx)
2771 if (lp_ctx == NULL) {
2772 return get_iconv_handle();
2774 return lp_ctx->iconv_handle;
2777 _PUBLIC_ void reload_charcnv(struct loadparm_context *lp_ctx)
2779 struct smb_iconv_handle *old_ic = lp_ctx->iconv_handle;
2780 if (!lp_ctx->global) {
2781 return;
2784 if (old_ic == NULL) {
2785 old_ic = global_iconv_handle;
2787 lp_ctx->iconv_handle = smb_iconv_handle_reinit_lp(lp_ctx, lp_ctx, old_ic);
2788 global_iconv_handle = lp_ctx->iconv_handle;
2791 _PUBLIC_ char *lpcfg_tls_keyfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
2793 return lpcfg_private_path(mem_ctx, lp_ctx, lpcfg__tls_keyfile(lp_ctx));
2796 _PUBLIC_ char *lpcfg_tls_certfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
2798 return lpcfg_private_path(mem_ctx, lp_ctx, lpcfg__tls_certfile(lp_ctx));
2801 _PUBLIC_ char *lpcfg_tls_cafile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
2803 return lpcfg_private_path(mem_ctx, lp_ctx, lpcfg__tls_cafile(lp_ctx));
2806 _PUBLIC_ char *lpcfg_tls_crlfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
2808 return lpcfg_private_path(mem_ctx, lp_ctx, lpcfg__tls_crlfile(lp_ctx));
2811 _PUBLIC_ char *lpcfg_tls_dhpfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
2813 return lpcfg_private_path(mem_ctx, lp_ctx, lpcfg__tls_dhpfile(lp_ctx));
2816 struct gensec_settings *lpcfg_gensec_settings(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
2818 struct gensec_settings *settings = talloc_zero(mem_ctx, struct gensec_settings);
2819 if (settings == NULL)
2820 return NULL;
2821 SMB_ASSERT(lp_ctx != NULL);
2822 settings->lp_ctx = talloc_reference(settings, lp_ctx);
2823 settings->target_hostname = lpcfg_parm_string(lp_ctx, NULL, "gensec", "target_hostname");
2824 return settings;
2827 int lpcfg_server_role(struct loadparm_context *lp_ctx)
2829 int domain_master = lpcfg__domain_master(lp_ctx);
2831 return lp_find_server_role(lpcfg__server_role(lp_ctx),
2832 lpcfg__security(lp_ctx),
2833 lpcfg__domain_logons(lp_ctx),
2834 (domain_master == true) ||
2835 (domain_master == Auto));
2838 int lpcfg_security(struct loadparm_context *lp_ctx)
2840 return lp_find_security(lpcfg__server_role(lp_ctx),
2841 lpcfg__security(lp_ctx));
2844 bool lpcfg_server_signing_allowed(struct loadparm_context *lp_ctx, bool *mandatory)
2846 bool allowed = true;
2847 enum smb_signing_setting signing_setting = lpcfg_server_signing(lp_ctx);
2849 *mandatory = false;
2851 if (signing_setting == SMB_SIGNING_DEFAULT) {
2853 * If we are a domain controller, SMB signing is
2854 * really important, as it can prevent a number of
2855 * attacks on communications between us and the
2856 * clients
2858 * However, it really sucks (no sendfile, CPU
2859 * overhead) performance-wise when used on a
2860 * file server, so disable it by default
2861 * on non-DCs
2864 if (lpcfg_server_role(lp_ctx) >= ROLE_ACTIVE_DIRECTORY_DC) {
2865 signing_setting = SMB_SIGNING_REQUIRED;
2866 } else {
2867 signing_setting = SMB_SIGNING_OFF;
2871 switch (signing_setting) {
2872 case SMB_SIGNING_REQUIRED:
2873 *mandatory = true;
2874 break;
2875 case SMB_SIGNING_IF_REQUIRED:
2876 break;
2877 case SMB_SIGNING_DEFAULT:
2878 case SMB_SIGNING_OFF:
2879 allowed = false;
2880 break;
2883 return allowed;
2886 int lpcfg_tdb_hash_size(struct loadparm_context *lp_ctx, const char *name)
2888 const char *base;
2890 if (name == NULL) {
2891 return 0;
2894 base = strrchr_m(name, '/');
2895 if (base != NULL) {
2896 base += 1;
2897 } else {
2898 base = name;
2900 return lpcfg_parm_int(lp_ctx, NULL, "tdb_hashsize", base, 0);
2904 int lpcfg_tdb_flags(struct loadparm_context *lp_ctx, int tdb_flags)
2906 if (!lpcfg_use_mmap(lp_ctx)) {
2907 tdb_flags |= TDB_NOMMAP;
2909 return tdb_flags;