param: use a single handle_include function between the two loadparms
[Samba.git] / lib / param / loadparm.c
blobf4ee64973cb7d8ae0be16c9dc7daeeda0db8c783
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_printing NULL
85 #define handle_ldap_debug_level NULL
86 #define handle_idmap_backend NULL
87 #define handle_idmap_uid NULL
88 #define handle_idmap_gid NULL
90 #ifndef N_
91 #define N_(x) x
92 #endif
94 #include "lib/param/param_table.c"
96 /* local variables */
97 struct loadparm_context {
98 const char *szConfigFile;
99 struct loadparm_global *globals;
100 struct loadparm_service **services;
101 struct loadparm_service *sDefault;
102 struct smb_iconv_handle *iconv_handle;
103 int iNumServices;
104 struct loadparm_service *currentService;
105 bool bInGlobalSection;
106 struct file_lists *file_lists;
107 unsigned int flags[NUMPARAMETERS];
108 bool loaded;
109 bool refuse_free;
110 bool global; /* Is this the global context, which may set
111 * global variables such as debug level etc? */
112 const struct loadparm_s3_helpers *s3_fns;
116 struct loadparm_service *lpcfg_default_service(struct loadparm_context *lp_ctx)
118 if (lp_ctx->s3_fns) {
119 return lp_ctx->s3_fns->get_default_loadparm_service();
121 return lp_ctx->sDefault;
125 * Convenience routine to grab string parameters into temporary memory
126 * and run standard_sub_basic on them.
128 * The buffers can be written to by
129 * callers without affecting the source string.
132 static const char *lpcfg_string(const char *s)
134 #if 0 /* until REWRITE done to make thread-safe */
135 size_t len = s ? strlen(s) : 0;
136 char *ret;
137 #endif
139 /* The follow debug is useful for tracking down memory problems
140 especially if you have an inner loop that is calling a lp_*()
141 function that returns a string. Perhaps this debug should be
142 present all the time? */
144 #if 0
145 DEBUG(10, ("lpcfg_string(%s)\n", s));
146 #endif
148 #if 0 /* until REWRITE done to make thread-safe */
149 if (!lp_talloc)
150 lp_talloc = talloc_init("lp_talloc");
152 ret = talloc_array(lp_talloc, char, len + 100); /* leave room for substitution */
154 if (!ret)
155 return NULL;
157 if (!s)
158 *ret = 0;
159 else
160 strlcpy(ret, s, len);
162 if (trim_string(ret, "\"", "\"")) {
163 if (strchr(ret,'"') != NULL)
164 strlcpy(ret, s, len);
167 standard_sub_basic(ret,len+100);
168 return (ret);
169 #endif
170 return s;
174 In this section all the functions that are used to access the
175 parameters from the rest of the program are defined
179 * the creation of separate lpcfg_*() and lp_*() functions is to allow
180 * for code compatibility between existing Samba4 and Samba3 code.
183 /* this global context supports the lp_*() function varients */
184 static struct loadparm_context *global_loadparm_context;
186 #define lpcfg_default_service global_loadparm_context->sDefault
187 #define lpcfg_global_service(i) global_loadparm_context->services[i]
189 #define FN_GLOBAL_STRING(fn_name,var_name) \
190 _PUBLIC_ char *lpcfg_ ## fn_name(struct loadparm_context *lp_ctx, TALLOC_CTX *ctx) {\
191 if (lp_ctx == NULL) return NULL; \
192 if (lp_ctx->s3_fns) { \
193 return lp_ctx->globals->var_name ? lp_ctx->s3_fns->lp_string(ctx, lp_ctx->globals->var_name) : talloc_strdup(ctx, ""); \
195 return lp_ctx->globals->var_name ? talloc_strdup(ctx, lpcfg_string(lp_ctx->globals->var_name)) : talloc_strdup(ctx, ""); \
198 #define FN_GLOBAL_CONST_STRING(fn_name,var_name) \
199 _PUBLIC_ const char *lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) { \
200 if (lp_ctx == NULL) return NULL; \
201 return lp_ctx->globals->var_name ? lpcfg_string(lp_ctx->globals->var_name) : ""; \
204 #define FN_GLOBAL_LIST(fn_name,var_name) \
205 _PUBLIC_ const char **lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) { \
206 if (lp_ctx == NULL) return NULL; \
207 return lp_ctx->globals->var_name; \
210 #define FN_GLOBAL_BOOL(fn_name,var_name) \
211 _PUBLIC_ bool lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) {\
212 if (lp_ctx == NULL) return false; \
213 return lp_ctx->globals->var_name; \
216 #define FN_GLOBAL_INTEGER(fn_name,var_name) \
217 _PUBLIC_ int lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) { \
218 return lp_ctx->globals->var_name; \
221 /* Local parameters don't need the ->s3_fns because the struct
222 * loadparm_service is shared and lpcfg_service() checks the ->s3_fns
223 * hook */
224 #define FN_LOCAL_STRING(fn_name,val) \
225 _PUBLIC_ char *lpcfg_ ## fn_name(struct loadparm_service *service, \
226 struct loadparm_service *sDefault, TALLOC_CTX *ctx) { \
227 return(talloc_strdup(ctx, lpcfg_string((const char *)((service != NULL && service->val != NULL) ? service->val : sDefault->val)))); \
230 #define FN_LOCAL_CONST_STRING(fn_name,val) \
231 _PUBLIC_ const char *lpcfg_ ## fn_name(struct loadparm_service *service, \
232 struct loadparm_service *sDefault) { \
233 return((const char *)((service != NULL && service->val != NULL) ? service->val : sDefault->val)); \
236 #define FN_LOCAL_LIST(fn_name,val) \
237 _PUBLIC_ const char **lpcfg_ ## fn_name(struct loadparm_service *service, \
238 struct loadparm_service *sDefault) {\
239 return(const char **)(service != NULL && service->val != NULL? service->val : sDefault->val); \
242 #define FN_LOCAL_PARM_BOOL(fn_name, val) FN_LOCAL_BOOL(fn_name, val)
244 #define FN_LOCAL_BOOL(fn_name,val) \
245 _PUBLIC_ bool lpcfg_ ## fn_name(struct loadparm_service *service, \
246 struct loadparm_service *sDefault) { \
247 return((service != NULL)? service->val : sDefault->val); \
250 #define FN_LOCAL_INTEGER(fn_name,val) \
251 _PUBLIC_ int lpcfg_ ## fn_name(struct loadparm_service *service, \
252 struct loadparm_service *sDefault) { \
253 return((service != NULL)? service->val : sDefault->val); \
256 #define FN_LOCAL_PARM_INTEGER(fn_name, val) FN_LOCAL_INTEGER(fn_name, val)
258 #define FN_LOCAL_PARM_CHAR(fn_name,val) \
259 _PUBLIC_ char lpcfg_ ## fn_name(struct loadparm_service *service, \
260 struct loadparm_service *sDefault) { \
261 return((service != NULL)? service->val : sDefault->val); \
264 #include "lib/param/param_functions.c"
266 /* These functions cannot be auto-generated */
267 FN_LOCAL_BOOL(autoloaded, autoloaded)
268 FN_GLOBAL_CONST_STRING(dnsdomain, dnsdomain)
270 /* local prototypes */
271 static struct loadparm_service *lpcfg_getservicebyname(struct loadparm_context *lp_ctx,
272 const char *pszServiceName);
273 static bool lpcfg_service_ok(struct loadparm_service *service);
274 static bool do_section(const char *pszSectionName, void *);
276 /* This is a helper function for parametrical options support. */
277 /* It returns a pointer to parametrical option value if it exists or NULL otherwise */
278 /* Actual parametrical functions are quite simple */
279 const char *lpcfg_get_parametric(struct loadparm_context *lp_ctx,
280 struct loadparm_service *service,
281 const char *type, const char *option)
283 char *vfskey_tmp = NULL;
284 char *vfskey = NULL;
285 struct parmlist_entry *data;
287 if (lp_ctx == NULL)
288 return NULL;
290 if (lp_ctx->s3_fns) {
291 return lp_ctx->s3_fns->get_parametric(service, type, option);
294 data = (service == NULL ? lp_ctx->globals->param_opt : service->param_opt);
296 vfskey_tmp = talloc_asprintf(NULL, "%s:%s", type, option);
297 if (vfskey_tmp == NULL) return NULL;
298 vfskey = strlower_talloc(NULL, vfskey_tmp);
299 talloc_free(vfskey_tmp);
301 while (data) {
302 if (strcmp(data->key, vfskey) == 0) {
303 talloc_free(vfskey);
304 return data->value;
306 data = data->next;
309 if (service != NULL) {
310 /* Try to fetch the same option but from globals */
311 /* but only if we are not already working with globals */
312 for (data = lp_ctx->globals->param_opt; data;
313 data = data->next) {
314 if (strcmp(data->key, vfskey) == 0) {
315 talloc_free(vfskey);
316 return data->value;
321 talloc_free(vfskey);
323 return NULL;
328 * convenience routine to return int parameters.
330 static int lp_int(const char *s)
333 if (!s) {
334 DEBUG(0,("lp_int(%s): is called with NULL!\n",s));
335 return -1;
338 return strtol(s, NULL, 0);
342 * convenience routine to return unsigned long parameters.
344 static unsigned long lp_ulong(const char *s)
347 if (!s) {
348 DEBUG(0,("lp_ulong(%s): is called with NULL!\n",s));
349 return -1;
352 return strtoul(s, NULL, 0);
356 * convenience routine to return unsigned long parameters.
358 static long lp_long(const char *s)
361 if (!s) {
362 DEBUG(0,("lp_long(%s): is called with NULL!\n",s));
363 return -1;
366 return strtol(s, NULL, 0);
370 * convenience routine to return unsigned long parameters.
372 static double lp_double(const char *s)
375 if (!s) {
376 DEBUG(0,("lp_double(%s): is called with NULL!\n",s));
377 return -1;
380 return strtod(s, NULL);
384 * convenience routine to return boolean parameters.
386 static bool lp_bool(const char *s)
388 bool ret = false;
390 if (!s) {
391 DEBUG(0,("lp_bool(%s): is called with NULL!\n",s));
392 return false;
395 if (!set_boolean(s, &ret)) {
396 DEBUG(0,("lp_bool(%s): value is not boolean!\n",s));
397 return false;
400 return ret;
405 * Return parametric option from a given service. Type is a part of option before ':'
406 * Parametric option has following syntax: 'Type: option = value'
407 * Returned value is allocated in 'lp_talloc' context
410 const char *lpcfg_parm_string(struct loadparm_context *lp_ctx,
411 struct loadparm_service *service, const char *type,
412 const char *option)
414 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
416 if (value)
417 return lpcfg_string(value);
419 return NULL;
423 * Return parametric option from a given service. Type is a part of option before ':'
424 * Parametric option has following syntax: 'Type: option = value'
425 * Returned value is allocated in 'lp_talloc' context
428 const char **lpcfg_parm_string_list(TALLOC_CTX *mem_ctx,
429 struct loadparm_context *lp_ctx,
430 struct loadparm_service *service,
431 const char *type,
432 const char *option, const char *separator)
434 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
436 if (value != NULL)
437 return (const char **)str_list_make(mem_ctx, value, separator);
439 return NULL;
443 * Return parametric option from a given service. Type is a part of option before ':'
444 * Parametric option has following syntax: 'Type: option = value'
447 int lpcfg_parm_int(struct loadparm_context *lp_ctx,
448 struct loadparm_service *service, const char *type,
449 const char *option, int default_v)
451 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
453 if (value)
454 return lp_int(value);
456 return default_v;
460 * Return parametric option from a given service. Type is a part of
461 * option before ':'.
462 * Parametric option has following syntax: 'Type: option = value'.
465 int lpcfg_parm_bytes(struct loadparm_context *lp_ctx,
466 struct loadparm_service *service, const char *type,
467 const char *option, int default_v)
469 uint64_t bval;
471 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
473 if (value && conv_str_size_error(value, &bval)) {
474 if (bval <= INT_MAX) {
475 return (int)bval;
479 return default_v;
483 * Return parametric option from a given service.
484 * Type is a part of option before ':'
485 * Parametric option has following syntax: 'Type: option = value'
487 unsigned long lpcfg_parm_ulong(struct loadparm_context *lp_ctx,
488 struct loadparm_service *service, const char *type,
489 const char *option, unsigned long default_v)
491 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
493 if (value)
494 return lp_ulong(value);
496 return default_v;
499 long lpcfg_parm_long(struct loadparm_context *lp_ctx,
500 struct loadparm_service *service, const char *type,
501 const char *option, long default_v)
503 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
505 if (value)
506 return lp_long(value);
508 return default_v;
511 double lpcfg_parm_double(struct loadparm_context *lp_ctx,
512 struct loadparm_service *service, const char *type,
513 const char *option, double default_v)
515 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
517 if (value != NULL)
518 return lp_double(value);
520 return default_v;
524 * Return parametric option from a given service. Type is a part of option before ':'
525 * Parametric option has following syntax: 'Type: option = value'
528 bool lpcfg_parm_bool(struct loadparm_context *lp_ctx,
529 struct loadparm_service *service, const char *type,
530 const char *option, bool default_v)
532 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
534 if (value != NULL)
535 return lp_bool(value);
537 return default_v;
542 * Set a string value, deallocating any existing space, and allocing the space
543 * for the string
545 static bool lpcfg_string_set(TALLOC_CTX *mem_ctx, char **dest, const char *src)
547 talloc_free(*dest);
549 if (src == NULL)
550 src = "";
552 *dest = talloc_strdup(mem_ctx, src);
553 if ((*dest) == NULL) {
554 DEBUG(0,("Out of memory in string_set\n"));
555 return false;
558 return true;
562 * Set a string value, deallocating any existing space, and allocing the space
563 * for the string
565 static bool lpcfg_string_set_upper(TALLOC_CTX *mem_ctx, char **dest, const char *src)
567 talloc_free(*dest);
569 if (src == NULL)
570 src = "";
572 *dest = strupper_talloc(mem_ctx, src);
573 if ((*dest) == NULL) {
574 DEBUG(0,("Out of memory in string_set_upper\n"));
575 return false;
578 return true;
584 * Add a new service to the services array initialising it with the given
585 * service.
588 struct loadparm_service *lpcfg_add_service(struct loadparm_context *lp_ctx,
589 const struct loadparm_service *pservice,
590 const char *name)
592 int i;
593 int num_to_alloc = lp_ctx->iNumServices + 1;
594 struct parmlist_entry *data, *pdata;
596 if (pservice == NULL) {
597 pservice = lp_ctx->sDefault;
600 /* it might already exist */
601 if (name) {
602 struct loadparm_service *service = lpcfg_getservicebyname(lp_ctx,
603 name);
604 if (service != NULL) {
605 /* Clean all parametric options for service */
606 /* They will be added during parsing again */
607 data = service->param_opt;
608 while (data) {
609 pdata = data->next;
610 talloc_free(data);
611 data = pdata;
613 service->param_opt = NULL;
614 return service;
618 /* find an invalid one */
619 for (i = 0; i < lp_ctx->iNumServices; i++)
620 if (lp_ctx->services[i] == NULL)
621 break;
623 /* if not, then create one */
624 if (i == lp_ctx->iNumServices) {
625 struct loadparm_service **tsp;
627 tsp = talloc_realloc(lp_ctx, lp_ctx->services, struct loadparm_service *, num_to_alloc);
629 if (!tsp) {
630 DEBUG(0,("lpcfg_add_service: failed to enlarge services!\n"));
631 return NULL;
632 } else {
633 lp_ctx->services = tsp;
634 lp_ctx->services[lp_ctx->iNumServices] = NULL;
637 lp_ctx->iNumServices++;
640 lp_ctx->services[i] = talloc_zero(lp_ctx->services, struct loadparm_service);
641 if (lp_ctx->services[i] == NULL) {
642 DEBUG(0,("lpcfg_add_service: out of memory!\n"));
643 return NULL;
645 copy_service(lp_ctx->services[i], pservice, NULL);
646 if (name != NULL)
647 lpcfg_string_set(lp_ctx->services[i], &lp_ctx->services[i]->szService, name);
648 return lp_ctx->services[i];
652 * Add a new home service, with the specified home directory, defaults coming
653 * from service ifrom.
656 bool lpcfg_add_home(struct loadparm_context *lp_ctx,
657 const char *pszHomename,
658 struct loadparm_service *default_service,
659 const char *user, const char *pszHomedir)
661 struct loadparm_service *service;
663 service = lpcfg_add_service(lp_ctx, default_service, pszHomename);
665 if (service == NULL)
666 return false;
668 if (!(*(default_service->path))
669 || strequal(default_service->path, lp_ctx->sDefault->path)) {
670 service->path = talloc_strdup(service, pszHomedir);
671 } else {
672 service->path = string_sub_talloc(service, lpcfg_path(default_service, lp_ctx->sDefault, service), "%H", pszHomedir);
675 if (!(*(service->comment))) {
676 service->comment = talloc_asprintf(service, "Home directory of %s", user);
678 service->bAvailable = default_service->bAvailable;
679 service->browseable = default_service->browseable;
681 DEBUG(3, ("adding home's share [%s] for user '%s' at '%s'\n",
682 pszHomename, user, service->path));
684 return true;
688 * Add a new printer service, with defaults coming from service iFrom.
691 bool lpcfg_add_printer(struct loadparm_context *lp_ctx,
692 const char *pszPrintername,
693 struct loadparm_service *default_service)
695 const char *comment = "From Printcap";
696 struct loadparm_service *service;
697 service = lpcfg_add_service(lp_ctx, default_service, pszPrintername);
699 if (service == NULL)
700 return false;
702 /* note that we do NOT default the availability flag to True - */
703 /* we take it from the default service passed. This allows all */
704 /* dynamic printers to be disabled by disabling the [printers] */
705 /* entry (if/when the 'available' keyword is implemented!). */
707 /* the printer name is set to the service name. */
708 lpcfg_string_set(service, &service->_printername, pszPrintername);
709 lpcfg_string_set(service, &service->comment, comment);
710 service->browseable = default_service->browseable;
711 /* Printers cannot be read_only. */
712 service->read_only = false;
713 /* Printer services must be printable. */
714 service->printable = true;
716 DEBUG(3, ("adding printer service %s\n", pszPrintername));
718 return true;
722 * Map a parameter's string representation to something we can use.
723 * Returns False if the parameter string is not recognised, else TRUE.
726 int lpcfg_map_parameter(const char *pszParmName)
728 int iIndex;
730 for (iIndex = 0; parm_table[iIndex].label; iIndex++)
731 if (strwicmp(parm_table[iIndex].label, pszParmName) == 0)
732 return iIndex;
734 /* Warn only if it isn't parametric option */
735 if (strchr(pszParmName, ':') == NULL)
736 DEBUG(0, ("Unknown parameter encountered: \"%s\"\n", pszParmName));
737 /* We do return 'fail' for parametric options as well because they are
738 stored in different storage
740 return -1;
745 return the parameter structure for a parameter
747 struct parm_struct *lpcfg_parm_struct(struct loadparm_context *lp_ctx, const char *name)
749 int parmnum;
751 if (lp_ctx->s3_fns) {
752 return lp_ctx->s3_fns->get_parm_struct(name);
755 parmnum = lpcfg_map_parameter(name);
756 if (parmnum == -1) return NULL;
757 return &parm_table[parmnum];
761 return the parameter pointer for a parameter
763 void *lpcfg_parm_ptr(struct loadparm_context *lp_ctx,
764 struct loadparm_service *service, struct parm_struct *parm)
766 if (lp_ctx->s3_fns) {
767 return lp_ctx->s3_fns->get_parm_ptr(service, parm);
770 if (service == NULL) {
771 if (parm->p_class == P_LOCAL)
772 return ((char *)lp_ctx->sDefault)+parm->offset;
773 else if (parm->p_class == P_GLOBAL)
774 return ((char *)lp_ctx->globals)+parm->offset;
775 else return NULL;
776 } else {
777 return ((char *)service) + parm->offset;
782 return the parameter pointer for a parameter
784 bool lpcfg_parm_is_cmdline(struct loadparm_context *lp_ctx, const char *name)
786 int parmnum;
788 if (lp_ctx->s3_fns) {
789 struct parm_struct *parm = lp_ctx->s3_fns->get_parm_struct(name);
790 if (parm) {
791 return parm->flags & FLAG_CMDLINE;
793 return false;
796 parmnum = lpcfg_map_parameter(name);
797 if (parmnum == -1) return false;
799 return lp_ctx->flags[parmnum] & FLAG_CMDLINE;
803 * Find a service by name. Otherwise works like get_service.
806 static struct loadparm_service *lpcfg_getservicebyname(struct loadparm_context *lp_ctx,
807 const char *pszServiceName)
809 int iService;
811 if (lp_ctx->s3_fns) {
812 return lp_ctx->s3_fns->get_service(pszServiceName);
815 for (iService = lp_ctx->iNumServices - 1; iService >= 0; iService--)
816 if (lp_ctx->services[iService] != NULL &&
817 strwicmp(lp_ctx->services[iService]->szService, pszServiceName) == 0) {
818 return lp_ctx->services[iService];
821 return NULL;
825 * Add a parametric option to a parmlist_entry,
826 * replacing old value, if already present.
828 void set_param_opt(TALLOC_CTX *mem_ctx,
829 struct parmlist_entry **opt_list,
830 const char *opt_name,
831 const char *opt_value,
832 unsigned priority)
834 struct parmlist_entry *new_opt, *opt;
835 bool not_added;
837 opt = *opt_list;
838 not_added = true;
840 /* Traverse destination */
841 while (opt) {
842 /* If we already have same option, override it */
843 if (strwicmp(opt->key, opt_name) == 0) {
844 if ((opt->priority & FLAG_CMDLINE) &&
845 !(priority & FLAG_CMDLINE)) {
846 /* it's been marked as not to be
847 overridden */
848 return;
850 TALLOC_FREE(opt->value);
851 TALLOC_FREE(opt->list);
852 opt->value = talloc_strdup(opt, opt_value);
853 opt->priority = priority;
854 not_added = false;
855 break;
857 opt = opt->next;
859 if (not_added) {
860 new_opt = talloc(mem_ctx, struct parmlist_entry);
861 if (new_opt == NULL) {
862 smb_panic("OOM");
865 new_opt->key = talloc_strdup(new_opt, opt_name);
866 if (new_opt->key == NULL) {
867 smb_panic("talloc_strdup failed");
870 new_opt->value = talloc_strdup(new_opt, opt_value);
871 if (new_opt->value == NULL) {
872 smb_panic("talloc_strdup failed");
875 new_opt->list = NULL;
876 new_opt->priority = priority;
877 DLIST_ADD(*opt_list, new_opt);
882 * Copy a service structure to another.
883 * If pcopymapDest is NULL then copy all fields
886 void copy_service(struct loadparm_service *pserviceDest,
887 const struct loadparm_service *pserviceSource,
888 struct bitmap *pcopymapDest)
890 int i;
891 bool bcopyall = (pcopymapDest == NULL);
892 struct parmlist_entry *data;
894 for (i = 0; parm_table[i].label; i++)
895 if (parm_table[i].p_class == P_LOCAL &&
896 (bcopyall || bitmap_query(pcopymapDest, i))) {
897 const void *src_ptr =
898 ((const char *)pserviceSource) + parm_table[i].offset;
899 void *dest_ptr =
900 ((char *)pserviceDest) + parm_table[i].offset;
902 switch (parm_table[i].type) {
903 case P_BOOL:
904 case P_BOOLREV:
905 *(bool *)dest_ptr = *(const bool *)src_ptr;
906 break;
908 case P_INTEGER:
909 case P_BYTES:
910 case P_OCTAL:
911 case P_ENUM:
912 *(int *)dest_ptr = *(const int *)src_ptr;
913 break;
915 case P_CHAR:
916 *(char *)dest_ptr = *(const char *)src_ptr;
917 break;
919 case P_STRING:
920 lpcfg_string_set(pserviceDest,
921 (char **)dest_ptr,
922 *(const char * const *)src_ptr);
923 break;
925 case P_USTRING:
926 lpcfg_string_set_upper(pserviceDest,
927 (char **)dest_ptr,
928 *(const char * const *)src_ptr);
929 break;
930 case P_LIST:
931 TALLOC_FREE(*((char ***)dest_ptr));
932 *(const char * const **)dest_ptr = (const char * const *)str_list_copy(pserviceDest,
933 *(const char * * const *)src_ptr);
934 break;
935 default:
936 break;
940 if (bcopyall) {
941 init_copymap(pserviceDest);
942 if (pserviceSource->copymap)
943 bitmap_copy(pserviceDest->copymap,
944 pserviceSource->copymap);
947 for (data = pserviceSource->param_opt; data != NULL; data = data->next) {
948 set_param_opt(pserviceDest, &pserviceDest->param_opt,
949 data->key, data->value, data->priority);
954 * Check a service for consistency. Return False if the service is in any way
955 * incomplete or faulty, else True.
957 static bool lpcfg_service_ok(struct loadparm_service *service)
959 bool bRetval;
961 bRetval = true;
962 if (service->szService[0] == '\0') {
963 DEBUG(0, ("The following message indicates an internal error:\n"));
964 DEBUG(0, ("No service name in service entry.\n"));
965 bRetval = false;
968 /* The [printers] entry MUST be printable. I'm all for flexibility, but */
969 /* I can't see why you'd want a non-printable printer service... */
970 if (strwicmp(service->szService, PRINTERS_NAME) == 0) {
971 if (!service->printable) {
972 DEBUG(0, ("WARNING: [%s] service MUST be printable!\n",
973 service->szService));
974 service->printable = true;
976 /* [printers] service must also be non-browsable. */
977 if (service->browseable)
978 service->browseable = false;
981 /* If a service is flagged unavailable, log the fact at level 0. */
982 if (!service->bAvailable)
983 DEBUG(1, ("NOTE: Service %s is flagged unavailable.\n",
984 service->szService));
986 return bRetval;
990 /*******************************************************************
991 Keep a linked list of all config files so we know when one has changed
992 it's date and needs to be reloaded.
993 ********************************************************************/
995 void add_to_file_list(TALLOC_CTX *mem_ctx, struct file_lists **list,
996 const char *fname, const char *subfname)
998 struct file_lists *f = *list;
1000 while (f) {
1001 if (f->name && !strcmp(f->name, fname))
1002 break;
1003 f = f->next;
1006 if (!f) {
1007 f = talloc(mem_ctx, struct file_lists);
1008 if (!f)
1009 goto fail;
1010 f->next = *list;
1011 f->name = talloc_strdup(f, fname);
1012 if (!f->name) {
1013 TALLOC_FREE(f);
1014 goto fail;
1016 f->subfname = talloc_strdup(f, subfname);
1017 if (!f->subfname) {
1018 TALLOC_FREE(f);
1019 goto fail;
1021 *list = f;
1022 f->modtime = file_modtime(subfname);
1023 } else {
1024 time_t t = file_modtime(subfname);
1025 if (t)
1026 f->modtime = t;
1028 return;
1030 fail:
1031 DEBUG(0, ("Unable to add file to file list: %s\n", fname));
1035 /*******************************************************************
1036 Check if a config file has changed date.
1037 ********************************************************************/
1038 bool lpcfg_file_list_changed(struct loadparm_context *lp_ctx)
1040 struct file_lists *f;
1041 DEBUG(6, ("lpcfg_file_list_changed()\n"));
1043 for (f = lp_ctx->file_lists; f != NULL; f = f->next) {
1044 char *n2;
1045 time_t mod_time;
1047 n2 = standard_sub_basic(lp_ctx, f->name);
1049 DEBUGADD(6, ("file %s -> %s last mod_time: %s\n",
1050 f->name, n2, ctime(&f->modtime)));
1052 mod_time = file_modtime(n2);
1054 if (mod_time && ((f->modtime != mod_time) || (f->subfname == NULL) || (strcmp(n2, f->subfname) != 0))) {
1055 DEBUGADD(6, ("file %s modified: %s\n", n2,
1056 ctime(&mod_time)));
1057 f->modtime = mod_time;
1058 talloc_free(f->subfname);
1059 f->subfname = talloc_strdup(f, n2);
1060 return true;
1063 return false;
1066 /***************************************************************************
1067 Handle the "realm" parameter
1068 ***************************************************************************/
1070 bool handle_realm(struct loadparm_context *lp_ctx, int unused,
1071 const char *pszParmValue, char **ptr)
1073 char *upper;
1074 char *lower;
1076 upper = strupper_talloc(lp_ctx, pszParmValue);
1077 if (upper == NULL) {
1078 return false;
1081 lower = strlower_talloc(lp_ctx, pszParmValue);
1082 if (lower == NULL) {
1083 TALLOC_FREE(upper);
1084 return false;
1087 if (lp_ctx->s3_fns != NULL) {
1088 lp_ctx->s3_fns->lp_string_set(ptr, pszParmValue);
1089 lp_ctx->s3_fns->lp_string_set(&lp_ctx->globals->realm, upper);
1090 lp_ctx->s3_fns->lp_string_set(&lp_ctx->globals->dnsdomain, lower);
1091 } else {
1092 lpcfg_string_set(lp_ctx, ptr, pszParmValue);
1093 lpcfg_string_set(lp_ctx, &lp_ctx->globals->realm, upper);
1094 lpcfg_string_set(lp_ctx, &lp_ctx->globals->dnsdomain, lower);
1097 return true;
1100 /***************************************************************************
1101 Handle the include operation.
1102 ***************************************************************************/
1104 bool handle_include(struct loadparm_context *lp_ctx, int unused,
1105 const char *pszParmValue, char **ptr)
1107 char *fname;
1109 if (lp_ctx->s3_fns) {
1110 return lp_ctx->s3_fns->lp_include(lp_ctx, unused, pszParmValue, ptr);
1113 fname = standard_sub_basic(lp_ctx, pszParmValue);
1115 add_to_file_list(lp_ctx, &lp_ctx->file_lists, pszParmValue, fname);
1117 lpcfg_string_set(lp_ctx, ptr, fname);
1119 if (file_exist(fname))
1120 return pm_process(fname, do_section, do_parameter, lp_ctx);
1122 DEBUG(2, ("Can't find include file %s\n", fname));
1124 return false;
1127 /***************************************************************************
1128 Handle the interpretation of the copy parameter.
1129 ***************************************************************************/
1131 bool handle_copy(struct loadparm_context *lp_ctx, int snum,
1132 const char *pszParmValue, char **ptr)
1134 bool bRetval;
1135 struct loadparm_service *serviceTemp = NULL;
1136 struct loadparm_service *current = NULL;
1138 bRetval = false;
1140 DEBUG(3, ("Copying service from service %s\n", pszParmValue));
1142 serviceTemp = lpcfg_getservicebyname(lp_ctx, pszParmValue);
1143 if (lp_ctx->s3_fns != NULL) {
1144 current = lp_ctx->s3_fns->get_servicebynum(snum);
1145 } else {
1146 current = lp_ctx->currentService;
1149 if (current == NULL) {
1150 DEBUG(0, ("Unable to copy service - invalid service destination"));
1151 return false;
1154 if (serviceTemp != NULL) {
1155 if (serviceTemp == current) {
1156 DEBUG(0, ("Can't copy service %s - unable to copy self!\n", pszParmValue));
1157 } else {
1158 copy_service(current,
1159 serviceTemp,
1160 current->copymap);
1161 lpcfg_string_set(current, ptr, pszParmValue);
1163 bRetval = true;
1165 } else {
1166 DEBUG(0, ("Unable to copy service - source not found: %s\n",
1167 pszParmValue));
1168 bRetval = false;
1171 return bRetval;
1174 bool handle_debug_list(struct loadparm_context *lp_ctx, int unused,
1175 const char *pszParmValue, char **ptr)
1177 if (lp_ctx->s3_fns != NULL) {
1178 lp_ctx->s3_fns->lp_string_set(ptr, pszParmValue);
1179 } else {
1180 lpcfg_string_set(lp_ctx, ptr, pszParmValue);
1183 return debug_parse_levels(pszParmValue);
1186 bool handle_logfile(struct loadparm_context *lp_ctx, int unused,
1187 const char *pszParmValue, char **ptr)
1189 if (lp_ctx->s3_fns != NULL) {
1190 lp_ctx->s3_fns->lp_string_set(ptr, pszParmValue);
1191 } else {
1192 debug_set_logfile(pszParmValue);
1193 lpcfg_string_set(lp_ctx, ptr, pszParmValue);
1196 return true;
1200 * These special charset handling methods only run in the source3 code.
1203 bool handle_charset(struct loadparm_context *lp_ctx, int snum,
1204 const char *pszParmValue, char **ptr)
1206 if (lp_ctx->s3_fns) {
1207 if (*ptr == NULL || strcmp(*ptr, pszParmValue) != 0) {
1208 lp_ctx->s3_fns->lp_string_set(ptr, pszParmValue);
1209 global_iconv_handle = smb_iconv_handle_reinit(NULL,
1210 lpcfg_dos_charset(lp_ctx),
1211 lpcfg_unix_charset(lp_ctx),
1212 true, global_iconv_handle);
1215 return true;
1217 return lpcfg_string_set(lp_ctx, ptr, pszParmValue);
1221 bool handle_dos_charset(struct loadparm_context *lp_ctx, int snum,
1222 const char *pszParmValue, char **ptr)
1224 bool is_utf8 = false;
1225 size_t len = strlen(pszParmValue);
1227 if (lp_ctx->s3_fns) {
1228 if (len == 4 || len == 5) {
1229 /* Don't use StrCaseCmp here as we don't want to
1230 initialize iconv. */
1231 if ((toupper_m(pszParmValue[0]) == 'U') &&
1232 (toupper_m(pszParmValue[1]) == 'T') &&
1233 (toupper_m(pszParmValue[2]) == 'F')) {
1234 if (len == 4) {
1235 if (pszParmValue[3] == '8') {
1236 is_utf8 = true;
1238 } else {
1239 if (pszParmValue[3] == '-' &&
1240 pszParmValue[4] == '8') {
1241 is_utf8 = true;
1247 if (*ptr == NULL || strcmp(*ptr, pszParmValue) != 0) {
1248 if (is_utf8) {
1249 DEBUG(0,("ERROR: invalid DOS charset: 'dos charset' must not "
1250 "be UTF8, using (default value) %s instead.\n",
1251 DEFAULT_DOS_CHARSET));
1252 pszParmValue = DEFAULT_DOS_CHARSET;
1254 lp_ctx->s3_fns->lp_string_set(ptr, pszParmValue);
1255 global_iconv_handle = smb_iconv_handle_reinit(NULL,
1256 lpcfg_dos_charset(lp_ctx),
1257 lpcfg_unix_charset(lp_ctx),
1258 true, global_iconv_handle);
1260 return true;
1263 return lpcfg_string_set(lp_ctx, ptr, pszParmValue);
1266 /***************************************************************************
1267 Initialise a copymap.
1268 ***************************************************************************/
1270 void init_copymap(struct loadparm_service *pservice)
1272 int i;
1274 TALLOC_FREE(pservice->copymap);
1276 pservice->copymap = bitmap_talloc(NULL, NUMPARAMETERS);
1277 if (!pservice->copymap)
1278 DEBUG(0,
1279 ("Couldn't allocate copymap!! (size %d)\n",
1280 (int)NUMPARAMETERS));
1281 else
1282 for (i = 0; i < NUMPARAMETERS; i++)
1283 bitmap_set(pservice->copymap, i);
1287 * Process a parametric option
1289 static bool lp_do_parameter_parametric(struct loadparm_context *lp_ctx,
1290 struct loadparm_service *service,
1291 const char *pszParmName,
1292 const char *pszParmValue, int flags)
1294 struct parmlist_entry *paramo, *data;
1295 char *name;
1296 TALLOC_CTX *mem_ctx;
1298 while (isspace((unsigned char)*pszParmName)) {
1299 pszParmName++;
1302 name = strlower_talloc(lp_ctx, pszParmName);
1303 if (!name) return false;
1305 if (service == NULL) {
1306 data = lp_ctx->globals->param_opt;
1307 mem_ctx = lp_ctx->globals;
1308 } else {
1309 data = service->param_opt;
1310 mem_ctx = service;
1313 /* Traverse destination */
1314 for (paramo=data; paramo; paramo=paramo->next) {
1315 /* If we already have the option set, override it unless
1316 it was a command line option and the new one isn't */
1317 if (strcmp(paramo->key, name) == 0) {
1318 if ((paramo->priority & FLAG_CMDLINE) &&
1319 !(flags & FLAG_CMDLINE)) {
1320 talloc_free(name);
1321 return true;
1324 talloc_free(paramo->value);
1325 paramo->value = talloc_strdup(paramo, pszParmValue);
1326 paramo->priority = flags;
1327 talloc_free(name);
1328 return true;
1332 paramo = talloc_zero(mem_ctx, struct parmlist_entry);
1333 if (!paramo)
1334 smb_panic("OOM");
1335 paramo->key = talloc_strdup(paramo, name);
1336 paramo->value = talloc_strdup(paramo, pszParmValue);
1337 paramo->priority = flags;
1338 if (service == NULL) {
1339 DLIST_ADD(lp_ctx->globals->param_opt, paramo);
1340 } else {
1341 DLIST_ADD(service->param_opt, paramo);
1344 talloc_free(name);
1346 return true;
1349 static bool set_variable(TALLOC_CTX *mem_ctx, int parmnum, void *parm_ptr,
1350 const char *pszParmName, const char *pszParmValue,
1351 struct loadparm_context *lp_ctx, bool on_globals)
1353 int i;
1354 /* if it is a special case then go ahead */
1355 if (parm_table[parmnum].special) {
1356 bool ret;
1357 ret = parm_table[parmnum].special(lp_ctx, -1, pszParmValue,
1358 (char **)parm_ptr);
1359 if (!ret) {
1360 return false;
1362 goto mark_non_default;
1365 /* now switch on the type of variable it is */
1366 switch (parm_table[parmnum].type)
1368 case P_BOOL: {
1369 bool b;
1370 if (!set_boolean(pszParmValue, &b)) {
1371 DEBUG(0, ("set_variable(%s): value is not "
1372 "boolean!\n", pszParmValue));
1373 return false;
1375 *(bool *)parm_ptr = b;
1377 break;
1379 case P_BOOLREV: {
1380 bool b;
1381 if (!set_boolean(pszParmValue, &b)) {
1382 DEBUG(0, ("set_variable(%s): value is not "
1383 "boolean!\n", pszParmValue));
1384 return false;
1386 *(bool *)parm_ptr = !b;
1388 break;
1390 case P_INTEGER:
1391 *(int *)parm_ptr = atoi(pszParmValue);
1392 break;
1394 case P_CHAR:
1395 *(char *)parm_ptr = *pszParmValue;
1396 break;
1398 case P_OCTAL:
1399 *(int *)parm_ptr = strtol(pszParmValue, NULL, 8);
1400 break;
1402 case P_BYTES:
1404 uint64_t val;
1405 if (conv_str_size_error(pszParmValue, &val)) {
1406 if (val <= INT_MAX) {
1407 *(int *)parm_ptr = (int)val;
1408 break;
1412 DEBUG(0, ("set_variable(%s): value is not "
1413 "a valid size specifier!\n", pszParmValue));
1414 return false;
1417 case P_CMDLIST:
1418 *(const char * const **)parm_ptr
1419 = (const char * const *)str_list_make(mem_ctx,
1420 pszParmValue, NULL);
1421 break;
1422 case P_LIST:
1424 char **new_list = str_list_make(mem_ctx,
1425 pszParmValue, NULL);
1426 for (i=0; new_list[i]; i++) {
1427 if (*(const char ***)parm_ptr != NULL &&
1428 new_list[i][0] == '+' &&
1429 new_list[i][1])
1431 if (!str_list_check(*(const char ***)parm_ptr,
1432 &new_list[i][1])) {
1433 *(const char ***)parm_ptr = str_list_add(*(const char ***)parm_ptr,
1434 &new_list[i][1]);
1436 } else if (*(const char ***)parm_ptr != NULL &&
1437 new_list[i][0] == '-' &&
1438 new_list[i][1])
1440 str_list_remove(*(const char ***)parm_ptr,
1441 &new_list[i][1]);
1442 } else {
1443 if (i != 0) {
1444 DEBUG(0, ("Unsupported list syntax for: %s = %s\n",
1445 pszParmName, pszParmValue));
1446 return false;
1448 *(const char * const **)parm_ptr = (const char * const *) new_list;
1449 break;
1452 break;
1454 case P_STRING:
1455 lpcfg_string_set(mem_ctx, (char **)parm_ptr, pszParmValue);
1456 break;
1458 case P_USTRING:
1459 lpcfg_string_set_upper(mem_ctx, (char **)parm_ptr, pszParmValue);
1460 break;
1462 case P_ENUM:
1463 for (i = 0; parm_table[parmnum].enum_list[i].name; i++) {
1464 if (strequal
1465 (pszParmValue,
1466 parm_table[parmnum].enum_list[i].name)) {
1467 *(int *)parm_ptr =
1468 parm_table[parmnum].
1469 enum_list[i].value;
1470 break;
1473 if (!parm_table[parmnum].enum_list[i].name) {
1474 DEBUG(0,("Unknown enumerated value '%s' for '%s'\n",
1475 pszParmValue, pszParmName));
1476 return false;
1478 break;
1480 case P_SEP:
1481 break;
1484 mark_non_default:
1485 if (on_globals && (lp_ctx->flags[parmnum] & FLAG_DEFAULT)) {
1486 lp_ctx->flags[parmnum] &= ~FLAG_DEFAULT;
1487 /* we have to also unset FLAG_DEFAULT on aliases */
1488 for (i=parmnum-1;i>=0 && parm_table[i].offset == parm_table[parmnum].offset;i--) {
1489 lp_ctx->flags[i] &= ~FLAG_DEFAULT;
1491 for (i=parmnum+1;i<NUMPARAMETERS && parm_table[i].offset == parm_table[parmnum].offset;i++) {
1492 lp_ctx->flags[i] &= ~FLAG_DEFAULT;
1495 return true;
1499 bool lpcfg_do_global_parameter(struct loadparm_context *lp_ctx,
1500 const char *pszParmName, const char *pszParmValue)
1502 int parmnum = lpcfg_map_parameter(pszParmName);
1503 void *parm_ptr;
1505 if (parmnum < 0) {
1506 if (strchr(pszParmName, ':')) {
1507 return lp_do_parameter_parametric(lp_ctx, NULL, pszParmName, pszParmValue, 0);
1509 DEBUG(0, ("Ignoring unknown parameter \"%s\"\n", pszParmName));
1510 return true;
1513 /* if the flag has been set on the command line, then don't allow override,
1514 but don't report an error */
1515 if (lp_ctx->flags[parmnum] & FLAG_CMDLINE) {
1516 return true;
1519 parm_ptr = lpcfg_parm_ptr(lp_ctx, NULL, &parm_table[parmnum]);
1521 return set_variable(lp_ctx->globals, parmnum, parm_ptr,
1522 pszParmName, pszParmValue, lp_ctx, true);
1525 bool lpcfg_do_service_parameter(struct loadparm_context *lp_ctx,
1526 struct loadparm_service *service,
1527 const char *pszParmName, const char *pszParmValue)
1529 void *parm_ptr;
1530 int i;
1531 int parmnum = lpcfg_map_parameter(pszParmName);
1533 if (parmnum < 0) {
1534 if (strchr(pszParmName, ':')) {
1535 return lp_do_parameter_parametric(lp_ctx, service, 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 if (parm_table[parmnum].p_class == P_GLOBAL) {
1548 DEBUG(0,
1549 ("Global parameter %s found in service section!\n",
1550 pszParmName));
1551 return true;
1553 parm_ptr = ((char *)service) + parm_table[parmnum].offset;
1555 if (!service->copymap)
1556 init_copymap(service);
1558 /* this handles the aliases - set the copymap for other
1559 * entries with the same data pointer */
1560 for (i = 0; parm_table[i].label; i++)
1561 if (parm_table[i].offset == parm_table[parmnum].offset &&
1562 parm_table[i].p_class == parm_table[parmnum].p_class)
1563 bitmap_clear(service->copymap, i);
1565 return set_variable(service, parmnum, parm_ptr, pszParmName,
1566 pszParmValue, lp_ctx, false);
1570 * Process a parameter.
1573 static bool do_parameter(const char *pszParmName, const char *pszParmValue,
1574 void *userdata)
1576 struct loadparm_context *lp_ctx = (struct loadparm_context *)userdata;
1578 if (lp_ctx->bInGlobalSection)
1579 return lpcfg_do_global_parameter(lp_ctx, pszParmName,
1580 pszParmValue);
1581 else
1582 return lpcfg_do_service_parameter(lp_ctx, lp_ctx->currentService,
1583 pszParmName, pszParmValue);
1587 variable argument do parameter
1589 bool lpcfg_do_global_parameter_var(struct loadparm_context *lp_ctx, const char *pszParmName, const char *fmt, ...) PRINTF_ATTRIBUTE(3, 4);
1590 bool lpcfg_do_global_parameter_var(struct loadparm_context *lp_ctx,
1591 const char *pszParmName, const char *fmt, ...)
1593 char *s;
1594 bool ret;
1595 va_list ap;
1597 va_start(ap, fmt);
1598 s = talloc_vasprintf(NULL, fmt, ap);
1599 va_end(ap);
1600 ret = lpcfg_do_global_parameter(lp_ctx, pszParmName, s);
1601 talloc_free(s);
1602 return ret;
1607 set a parameter from the commandline - this is called from command line parameter
1608 parsing code. It sets the parameter then marks the parameter as unable to be modified
1609 by smb.conf processing
1611 bool lpcfg_set_cmdline(struct loadparm_context *lp_ctx, const char *pszParmName,
1612 const char *pszParmValue)
1614 int parmnum;
1615 int i;
1617 while (isspace((unsigned char)*pszParmValue)) pszParmValue++;
1619 if (lp_ctx->s3_fns) {
1620 return lp_ctx->s3_fns->set_cmdline(pszParmName, pszParmValue);
1623 parmnum = lpcfg_map_parameter(pszParmName);
1625 if (parmnum < 0 && strchr(pszParmName, ':')) {
1626 /* set a parametric option */
1627 return lp_do_parameter_parametric(lp_ctx, NULL, pszParmName,
1628 pszParmValue, FLAG_CMDLINE);
1631 if (parmnum < 0) {
1632 DEBUG(0,("Unknown option '%s'\n", pszParmName));
1633 return false;
1636 /* reset the CMDLINE flag in case this has been called before */
1637 lp_ctx->flags[parmnum] &= ~FLAG_CMDLINE;
1639 if (!lpcfg_do_global_parameter(lp_ctx, pszParmName, pszParmValue)) {
1640 return false;
1643 lp_ctx->flags[parmnum] |= FLAG_CMDLINE;
1645 /* we have to also set FLAG_CMDLINE on aliases */
1646 for (i=parmnum-1;
1647 i>=0 && 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;
1652 for (i=parmnum+1;
1653 i<NUMPARAMETERS &&
1654 parm_table[i].p_class == parm_table[parmnum].p_class &&
1655 parm_table[i].offset == parm_table[parmnum].offset;
1656 i++) {
1657 lp_ctx->flags[i] |= FLAG_CMDLINE;
1660 return true;
1664 set a option from the commandline in 'a=b' format. Use to support --option
1666 bool lpcfg_set_option(struct loadparm_context *lp_ctx, const char *option)
1668 char *p, *s;
1669 bool ret;
1671 s = talloc_strdup(NULL, option);
1672 if (!s) {
1673 return false;
1676 p = strchr(s, '=');
1677 if (!p) {
1678 talloc_free(s);
1679 return false;
1682 *p = 0;
1684 ret = lpcfg_set_cmdline(lp_ctx, s, p+1);
1685 talloc_free(s);
1686 return ret;
1690 #define BOOLSTR(b) ((b) ? "Yes" : "No")
1693 * Print a parameter of the specified type.
1696 void lpcfg_print_parameter(struct parm_struct *p, void *ptr, FILE * f)
1698 /* For the seperation of lists values that we print below */
1699 const char *list_sep = ", ";
1700 int i;
1701 switch (p->type)
1703 case P_ENUM:
1704 for (i = 0; p->enum_list[i].name; i++) {
1705 if (*(int *)ptr == p->enum_list[i].value) {
1706 fprintf(f, "%s",
1707 p->enum_list[i].name);
1708 break;
1711 break;
1713 case P_BOOL:
1714 fprintf(f, "%s", BOOLSTR(*(bool *)ptr));
1715 break;
1717 case P_BOOLREV:
1718 fprintf(f, "%s", BOOLSTR(!*(bool *)ptr));
1719 break;
1721 case P_INTEGER:
1722 case P_BYTES:
1723 fprintf(f, "%d", *(int *)ptr);
1724 break;
1726 case P_CHAR:
1727 fprintf(f, "%c", *(char *)ptr);
1728 break;
1730 case P_OCTAL: {
1731 int val = *(int *)ptr;
1732 if (val == -1) {
1733 fprintf(f, "-1");
1734 } else {
1735 fprintf(f, "0%03o", val);
1737 break;
1740 case P_CMDLIST:
1741 list_sep = " ";
1742 /* fall through */
1743 case P_LIST:
1744 if ((char ***)ptr && *(char ***)ptr) {
1745 char **list = *(char ***)ptr;
1746 for (; *list; list++) {
1747 /* surround strings with whitespace in double quotes */
1748 if (*(list+1) == NULL) {
1749 /* last item, no extra separator */
1750 list_sep = "";
1752 if ( strchr_m( *list, ' ' ) ) {
1753 fprintf(f, "\"%s\"%s", *list, list_sep);
1754 } else {
1755 fprintf(f, "%s%s", *list, list_sep);
1759 break;
1761 case P_STRING:
1762 case P_USTRING:
1763 if (*(char **)ptr) {
1764 fprintf(f, "%s", *(char **)ptr);
1766 break;
1767 case P_SEP:
1768 break;
1773 * Check if two parameters are equal.
1776 bool lpcfg_equal_parameter(parm_type type, void *ptr1, void *ptr2)
1778 switch (type) {
1779 case P_BOOL:
1780 case P_BOOLREV:
1781 return (*((bool *)ptr1) == *((bool *)ptr2));
1783 case P_INTEGER:
1784 case P_ENUM:
1785 case P_OCTAL:
1786 case P_BYTES:
1787 return (*((int *)ptr1) == *((int *)ptr2));
1789 case P_CHAR:
1790 return (*((char *)ptr1) == *((char *)ptr2));
1792 case P_LIST:
1793 case P_CMDLIST:
1794 return str_list_equal(*(const char ***)ptr1, *(const char ***)ptr2);
1796 case P_STRING:
1797 case P_USTRING:
1799 char *p1 = *(char **)ptr1, *p2 = *(char **)ptr2;
1800 if (p1 && !*p1)
1801 p1 = NULL;
1802 if (p2 && !*p2)
1803 p2 = NULL;
1804 return (p1 == p2 || strequal(p1, p2));
1806 case P_SEP:
1807 break;
1809 return false;
1813 * Process a new section (service).
1815 * At this stage all sections are services.
1816 * Later we'll have special sections that permit server parameters to be set.
1817 * Returns True on success, False on failure.
1820 static bool do_section(const char *pszSectionName, void *userdata)
1822 struct loadparm_context *lp_ctx = (struct loadparm_context *)userdata;
1823 bool bRetval;
1824 bool isglobal = ((strwicmp(pszSectionName, GLOBAL_NAME) == 0) ||
1825 (strwicmp(pszSectionName, GLOBAL_NAME2) == 0));
1826 bRetval = false;
1828 /* if we've just struck a global section, note the fact. */
1829 lp_ctx->bInGlobalSection = isglobal;
1831 /* check for multiple global sections */
1832 if (lp_ctx->bInGlobalSection) {
1833 DEBUG(4, ("Processing section \"[%s]\"\n", pszSectionName));
1834 return true;
1837 /* if we have a current service, tidy it up before moving on */
1838 bRetval = true;
1840 if (lp_ctx->currentService != NULL)
1841 bRetval = lpcfg_service_ok(lp_ctx->currentService);
1843 /* if all is still well, move to the next record in the services array */
1844 if (bRetval) {
1845 /* We put this here to avoid an odd message order if messages are */
1846 /* issued by the post-processing of a previous section. */
1847 DEBUG(4, ("Processing section \"[%s]\"\n", pszSectionName));
1849 if ((lp_ctx->currentService = lpcfg_add_service(lp_ctx, lp_ctx->sDefault,
1850 pszSectionName))
1851 == NULL) {
1852 DEBUG(0, ("Failed to add a new service\n"));
1853 return false;
1857 return bRetval;
1862 * Determine if a particular base parameter is currently set to the default value.
1865 static bool is_default(struct loadparm_service *sDefault, int i)
1867 void *def_ptr = ((char *)sDefault) + parm_table[i].offset;
1868 switch (parm_table[i].type) {
1869 case P_CMDLIST:
1870 case P_LIST:
1871 return str_list_equal((const char * const *)parm_table[i].def.lvalue,
1872 (const char **)def_ptr);
1873 case P_STRING:
1874 case P_USTRING:
1875 return strequal(parm_table[i].def.svalue,
1876 *(char **)def_ptr);
1877 case P_BOOL:
1878 case P_BOOLREV:
1879 return parm_table[i].def.bvalue ==
1880 *(bool *)def_ptr;
1881 case P_INTEGER:
1882 case P_CHAR:
1883 case P_OCTAL:
1884 case P_BYTES:
1885 case P_ENUM:
1886 return parm_table[i].def.ivalue ==
1887 *(int *)def_ptr;
1888 case P_SEP:
1889 break;
1891 return false;
1895 *Display the contents of the global structure.
1898 static void dump_globals(struct loadparm_context *lp_ctx, FILE *f,
1899 bool show_defaults)
1901 int i;
1902 struct parmlist_entry *data;
1904 fprintf(f, "# Global parameters\n[global]\n");
1906 for (i = 0; parm_table[i].label; i++)
1907 if (parm_table[i].p_class == P_GLOBAL &&
1908 (i == 0 || (parm_table[i].offset != parm_table[i - 1].offset))) {
1909 if (!show_defaults && (lp_ctx->flags[i] & FLAG_DEFAULT))
1910 continue;
1911 fprintf(f, "\t%s = ", parm_table[i].label);
1912 lpcfg_print_parameter(&parm_table[i], lpcfg_parm_ptr(lp_ctx, NULL, &parm_table[i]), f);
1913 fprintf(f, "\n");
1915 if (lp_ctx->globals->param_opt != NULL) {
1916 for (data = lp_ctx->globals->param_opt; data;
1917 data = data->next) {
1918 if (!show_defaults && (data->priority & FLAG_DEFAULT)) {
1919 continue;
1921 fprintf(f, "\t%s = %s\n", data->key, data->value);
1928 * Display the contents of a single services record.
1931 static void dump_a_service(struct loadparm_service * pService, struct loadparm_service *sDefault, FILE * f,
1932 unsigned int *flags)
1934 int i;
1935 struct parmlist_entry *data;
1937 if (pService != sDefault)
1938 fprintf(f, "\n[%s]\n", pService->szService);
1940 for (i = 0; parm_table[i].label; i++) {
1941 if (parm_table[i].p_class == P_LOCAL &&
1942 (*parm_table[i].label != '-') &&
1943 (i == 0 || (parm_table[i].offset != parm_table[i - 1].offset)))
1945 if (pService == sDefault) {
1946 if (flags && (flags[i] & FLAG_DEFAULT)) {
1947 continue;
1949 if (defaults_saved) {
1950 if (is_default(sDefault, i)) {
1951 continue;
1954 } else {
1955 if (lpcfg_equal_parameter(parm_table[i].type,
1956 ((char *)pService) +
1957 parm_table[i].offset,
1958 ((char *)sDefault) +
1959 parm_table[i].offset))
1960 continue;
1963 fprintf(f, "\t%s = ", parm_table[i].label);
1964 lpcfg_print_parameter(&parm_table[i],
1965 ((char *)pService) + parm_table[i].offset, f);
1966 fprintf(f, "\n");
1969 if (pService->param_opt != NULL) {
1970 for (data = pService->param_opt; data; data = data->next) {
1971 fprintf(f, "\t%s = %s\n", data->key, data->value);
1976 bool lpcfg_dump_a_parameter(struct loadparm_context *lp_ctx,
1977 struct loadparm_service *service,
1978 const char *parm_name, FILE * f)
1980 struct parm_struct *parm;
1981 void *ptr;
1983 parm = lpcfg_parm_struct(lp_ctx, parm_name);
1984 if (!parm) {
1985 return false;
1988 if (service != NULL && parm->p_class == P_GLOBAL) {
1989 return false;
1992 ptr = lpcfg_parm_ptr(lp_ctx, service,parm);
1994 lpcfg_print_parameter(parm, ptr, f);
1995 fprintf(f, "\n");
1996 return true;
2000 * Auto-load some home services.
2002 static void lpcfg_add_auto_services(struct loadparm_context *lp_ctx,
2003 const char *str)
2005 return;
2010 * Unload unused services.
2013 void lpcfg_killunused(struct loadparm_context *lp_ctx,
2014 struct smbsrv_connection *smb,
2015 bool (*snumused) (struct smbsrv_connection *, int))
2017 int i;
2018 for (i = 0; i < lp_ctx->iNumServices; i++) {
2019 if (lp_ctx->services[i] == NULL)
2020 continue;
2022 if (!snumused || !snumused(smb, i)) {
2023 talloc_free(lp_ctx->services[i]);
2024 lp_ctx->services[i] = NULL;
2030 static int lpcfg_destructor(struct loadparm_context *lp_ctx)
2032 struct parmlist_entry *data;
2034 if (lp_ctx->refuse_free) {
2035 /* someone is trying to free the
2036 global_loadparm_context.
2037 We can't allow that. */
2038 return -1;
2041 if (lp_ctx->globals->param_opt != NULL) {
2042 struct parmlist_entry *next;
2043 for (data = lp_ctx->globals->param_opt; data; data=next) {
2044 next = data->next;
2045 if (data->priority & FLAG_CMDLINE) continue;
2046 DLIST_REMOVE(lp_ctx->globals->param_opt, data);
2047 talloc_free(data);
2051 return 0;
2055 * Initialise the global parameter structure.
2057 * Note that most callers should use loadparm_init_global() instead
2059 struct loadparm_context *loadparm_init(TALLOC_CTX *mem_ctx)
2061 int i;
2062 char *myname;
2063 struct loadparm_context *lp_ctx;
2064 struct parmlist_entry *parm;
2065 char *logfile;
2067 lp_ctx = talloc_zero(mem_ctx, struct loadparm_context);
2068 if (lp_ctx == NULL)
2069 return NULL;
2071 talloc_set_destructor(lp_ctx, lpcfg_destructor);
2072 lp_ctx->bInGlobalSection = true;
2073 lp_ctx->globals = talloc_zero(lp_ctx, struct loadparm_global);
2074 lp_ctx->sDefault = talloc_zero(lp_ctx, struct loadparm_service);
2076 lp_ctx->sDefault->iMaxPrintJobs = 1000;
2077 lp_ctx->sDefault->bAvailable = true;
2078 lp_ctx->sDefault->browseable = true;
2079 lp_ctx->sDefault->read_only = true;
2080 lp_ctx->sDefault->map_archive = true;
2081 lp_ctx->sDefault->strict_locking = true;
2082 lp_ctx->sDefault->oplocks = true;
2083 lp_ctx->sDefault->create_mask = 0744;
2084 lp_ctx->sDefault->force_create_mode = 0000;
2085 lp_ctx->sDefault->directory_mask = 0755;
2086 lp_ctx->sDefault->force_directory_mode = 0000;
2088 DEBUG(3, ("Initialising global parameters\n"));
2090 for (i = 0; parm_table[i].label; i++) {
2091 if ((parm_table[i].type == P_STRING ||
2092 parm_table[i].type == P_USTRING) &&
2093 !(lp_ctx->flags[i] & FLAG_CMDLINE)) {
2094 char **r;
2095 if (parm_table[i].p_class == P_LOCAL) {
2096 r = (char **)(((char *)lp_ctx->sDefault) + parm_table[i].offset);
2097 } else {
2098 r = (char **)(((char *)lp_ctx->globals) + parm_table[i].offset);
2100 *r = talloc_strdup(lp_ctx, "");
2104 logfile = talloc_asprintf(lp_ctx, "%s/log.samba", dyn_LOGFILEBASE);
2105 lpcfg_do_global_parameter(lp_ctx, "log file", logfile);
2106 talloc_free(logfile);
2108 lpcfg_do_global_parameter(lp_ctx, "log level", "0");
2110 lpcfg_do_global_parameter(lp_ctx, "syslog", "1");
2111 lpcfg_do_global_parameter(lp_ctx, "syslog only", "No");
2112 lpcfg_do_global_parameter(lp_ctx, "debug timestamp", "Yes");
2113 lpcfg_do_global_parameter(lp_ctx, "debug prefix timestamp", "No");
2114 lpcfg_do_global_parameter(lp_ctx, "debug hires timestamp", "Yes");
2115 lpcfg_do_global_parameter(lp_ctx, "debug pid", "No");
2116 lpcfg_do_global_parameter(lp_ctx, "debug uid", "No");
2117 lpcfg_do_global_parameter(lp_ctx, "debug class", "No");
2119 lpcfg_do_global_parameter(lp_ctx, "share backend", "classic");
2121 lpcfg_do_global_parameter(lp_ctx, "server role", "auto");
2122 lpcfg_do_global_parameter(lp_ctx, "domain logons", "No");
2123 lpcfg_do_global_parameter(lp_ctx, "domain master", "Auto");
2125 /* options that can be set on the command line must be initialised via
2126 the slower lpcfg_do_global_parameter() to ensure that FLAG_CMDLINE is obeyed */
2127 #ifdef TCP_NODELAY
2128 lpcfg_do_global_parameter(lp_ctx, "socket options", "TCP_NODELAY");
2129 #endif
2130 lpcfg_do_global_parameter(lp_ctx, "workgroup", DEFAULT_WORKGROUP);
2131 myname = get_myname(lp_ctx);
2132 lpcfg_do_global_parameter(lp_ctx, "netbios name", myname);
2133 talloc_free(myname);
2134 lpcfg_do_global_parameter(lp_ctx, "name resolve order", "lmhosts wins host bcast");
2136 lpcfg_do_global_parameter(lp_ctx, "fstype", "NTFS");
2138 lpcfg_do_global_parameter(lp_ctx, "ntvfs handler", "unixuid default");
2139 lpcfg_do_global_parameter(lp_ctx, "max connections", "0");
2141 lpcfg_do_global_parameter(lp_ctx, "dcerpc endpoint servers", "epmapper wkssvc rpcecho samr netlogon lsarpc spoolss drsuapi dssetup unixinfo browser eventlog6 backupkey dnsserver");
2142 lpcfg_do_global_parameter(lp_ctx, "server services", "s3fs rpc nbt wrepl ldap cldap kdc drepl winbind ntp_signd kcc dnsupdate dns");
2143 lpcfg_do_global_parameter(lp_ctx, "kccsrv:samba_kcc", "true");
2144 /* the winbind method for domain controllers is for both RODC
2145 auth forwarding and for trusted domains */
2146 lpcfg_do_global_parameter(lp_ctx, "private dir", dyn_PRIVATE_DIR);
2147 lpcfg_do_global_parameter(lp_ctx, "registry:HKEY_LOCAL_MACHINE", "hklm.ldb");
2149 /* This hive should be dynamically generated by Samba using
2150 data from the sam, but for the moment leave it in a tdb to
2151 keep regedt32 from popping up an annoying dialog. */
2152 lpcfg_do_global_parameter(lp_ctx, "registry:HKEY_USERS", "hku.ldb");
2154 /* using UTF8 by default allows us to support all chars */
2155 lpcfg_do_global_parameter(lp_ctx, "unix charset", "UTF-8");
2157 /* Use codepage 850 as a default for the dos character set */
2158 lpcfg_do_global_parameter(lp_ctx, "dos charset", "CP850");
2161 * Allow the default PASSWD_CHAT to be overridden in local.h.
2163 lpcfg_do_global_parameter(lp_ctx, "passwd chat", DEFAULT_PASSWD_CHAT);
2165 lpcfg_do_global_parameter(lp_ctx, "pid directory", dyn_PIDDIR);
2166 lpcfg_do_global_parameter(lp_ctx, "lock dir", dyn_LOCKDIR);
2167 lpcfg_do_global_parameter(lp_ctx, "state directory", dyn_STATEDIR);
2168 lpcfg_do_global_parameter(lp_ctx, "cache directory", dyn_CACHEDIR);
2169 lpcfg_do_global_parameter(lp_ctx, "ncalrpc dir", dyn_NCALRPCDIR);
2171 lpcfg_do_global_parameter(lp_ctx, "nbt client socket address", "0.0.0.0");
2172 lpcfg_do_global_parameter_var(lp_ctx, "server string",
2173 "Samba %s", SAMBA_VERSION_STRING);
2175 lpcfg_do_global_parameter(lp_ctx, "password server", "*");
2177 lpcfg_do_global_parameter(lp_ctx, "max mux", "50");
2178 lpcfg_do_global_parameter(lp_ctx, "max xmit", "16644");
2179 lpcfg_do_global_parameter(lp_ctx, "host msdfs", "true");
2181 lpcfg_do_global_parameter(lp_ctx, "LargeReadwrite", "True");
2182 lpcfg_do_global_parameter(lp_ctx, "server min protocol", "LANMAN1");
2183 lpcfg_do_global_parameter(lp_ctx, "server max protocol", "SMB3");
2184 lpcfg_do_global_parameter(lp_ctx, "client min protocol", "CORE");
2185 lpcfg_do_global_parameter(lp_ctx, "client max protocol", "NT1");
2186 lpcfg_do_global_parameter(lp_ctx, "security", "AUTO");
2187 lpcfg_do_global_parameter(lp_ctx, "EncryptPasswords", "True");
2188 lpcfg_do_global_parameter(lp_ctx, "ReadRaw", "True");
2189 lpcfg_do_global_parameter(lp_ctx, "WriteRaw", "True");
2190 lpcfg_do_global_parameter(lp_ctx, "NullPasswords", "False");
2191 lpcfg_do_global_parameter(lp_ctx, "old password allowed period", "60");
2192 lpcfg_do_global_parameter(lp_ctx, "ObeyPamRestrictions", "False");
2194 lpcfg_do_global_parameter(lp_ctx, "TimeServer", "False");
2195 lpcfg_do_global_parameter(lp_ctx, "BindInterfacesOnly", "False");
2196 lpcfg_do_global_parameter(lp_ctx, "Unicode", "True");
2197 lpcfg_do_global_parameter(lp_ctx, "ClientLanManAuth", "False");
2198 lpcfg_do_global_parameter(lp_ctx, "ClientNTLMv2Auth", "True");
2199 lpcfg_do_global_parameter(lp_ctx, "LanmanAuth", "False");
2200 lpcfg_do_global_parameter(lp_ctx, "NTLMAuth", "True");
2201 lpcfg_do_global_parameter(lp_ctx, "client use spnego principal", "False");
2203 lpcfg_do_global_parameter(lp_ctx, "UnixExtensions", "True");
2205 lpcfg_do_global_parameter(lp_ctx, "PreferredMaster", "Auto");
2206 lpcfg_do_global_parameter(lp_ctx, "LocalMaster", "True");
2208 lpcfg_do_global_parameter(lp_ctx, "wins support", "False");
2209 lpcfg_do_global_parameter(lp_ctx, "dns proxy", "True");
2211 lpcfg_do_global_parameter(lp_ctx, "winbind separator", "\\");
2212 lpcfg_do_global_parameter(lp_ctx, "winbind sealed pipes", "True");
2213 lpcfg_do_global_parameter(lp_ctx, "require strong key", "True");
2214 lpcfg_do_global_parameter(lp_ctx, "winbindd socket directory", dyn_WINBINDD_SOCKET_DIR);
2215 lpcfg_do_global_parameter(lp_ctx, "winbindd privileged socket directory", dyn_WINBINDD_PRIVILEGED_SOCKET_DIR);
2216 lpcfg_do_global_parameter(lp_ctx, "ntp signd socket directory", dyn_NTP_SIGND_SOCKET_DIR);
2217 lpcfg_do_global_parameter_var(lp_ctx, "dns update command", "%s/samba_dnsupdate", dyn_SCRIPTSBINDIR);
2218 lpcfg_do_global_parameter_var(lp_ctx, "spn update command", "%s/samba_spnupdate", dyn_SCRIPTSBINDIR);
2219 lpcfg_do_global_parameter_var(lp_ctx, "samba kcc command",
2220 "%s/samba_kcc", dyn_SCRIPTSBINDIR);
2221 lpcfg_do_global_parameter(lp_ctx, "template shell", "/bin/false");
2222 lpcfg_do_global_parameter(lp_ctx, "template homedir", "/home/%WORKGROUP%/%ACCOUNTNAME%");
2224 lpcfg_do_global_parameter(lp_ctx, "client signing", "default");
2225 lpcfg_do_global_parameter(lp_ctx, "server signing", "default");
2227 lpcfg_do_global_parameter(lp_ctx, "use spnego", "True");
2229 lpcfg_do_global_parameter(lp_ctx, "use mmap", "True");
2231 lpcfg_do_global_parameter(lp_ctx, "smb ports", "445 139");
2232 lpcfg_do_global_parameter(lp_ctx, "nbt port", "137");
2233 lpcfg_do_global_parameter(lp_ctx, "dgram port", "138");
2234 lpcfg_do_global_parameter(lp_ctx, "cldap port", "389");
2235 lpcfg_do_global_parameter(lp_ctx, "krb5 port", "88");
2236 lpcfg_do_global_parameter(lp_ctx, "kpasswd port", "464");
2237 lpcfg_do_global_parameter(lp_ctx, "web port", "901");
2239 lpcfg_do_global_parameter(lp_ctx, "nt status support", "True");
2241 lpcfg_do_global_parameter(lp_ctx, "max wins ttl", "518400"); /* 6 days */
2242 lpcfg_do_global_parameter(lp_ctx, "min wins ttl", "21600");
2244 lpcfg_do_global_parameter(lp_ctx, "tls enabled", "True");
2245 lpcfg_do_global_parameter(lp_ctx, "tls keyfile", "tls/key.pem");
2246 lpcfg_do_global_parameter(lp_ctx, "tls certfile", "tls/cert.pem");
2247 lpcfg_do_global_parameter(lp_ctx, "tls cafile", "tls/ca.pem");
2248 lpcfg_do_global_parameter(lp_ctx, "prefork children:smb", "4");
2250 lpcfg_do_global_parameter(lp_ctx, "rndc command", "/usr/sbin/rndc");
2251 lpcfg_do_global_parameter(lp_ctx, "nsupdate command", "/usr/bin/nsupdate -g");
2253 lpcfg_do_global_parameter(lp_ctx, "allow dns updates", "secure only");
2254 lpcfg_do_global_parameter(lp_ctx, "dns forwarder", "");
2256 lpcfg_do_global_parameter(lp_ctx, "algorithmic rid base", "1000");
2258 lpcfg_do_global_parameter(lp_ctx, "enhanced browsing", "True");
2260 lpcfg_do_global_parameter(lp_ctx, "winbind nss info", "template");
2262 lpcfg_do_global_parameter(lp_ctx, "server schannel", "Auto");
2264 lpcfg_do_global_parameter(lp_ctx, "short preserve case", "True");
2266 lpcfg_do_global_parameter(lp_ctx, "max open files", "16384");
2268 lpcfg_do_global_parameter(lp_ctx, "cups connection timeout", "30");
2270 lpcfg_do_global_parameter(lp_ctx, "locking", "True");
2272 lpcfg_do_global_parameter(lp_ctx, "block size", "1024");
2274 lpcfg_do_global_parameter(lp_ctx, "client use spnego", "True");
2276 lpcfg_do_global_parameter(lp_ctx, "change notify", "True");
2278 lpcfg_do_global_parameter(lp_ctx, "name cache timeout", "660");
2280 lpcfg_do_global_parameter(lp_ctx, "defer sharing violations", "True");
2282 lpcfg_do_global_parameter(lp_ctx, "ldap replication sleep", "1000");
2284 lpcfg_do_global_parameter(lp_ctx, "idmap backend", "tdb");
2286 lpcfg_do_global_parameter(lp_ctx, "enable privileges", "True");
2288 lpcfg_do_global_parameter_var(lp_ctx, "smb2 max write", "%u", DEFAULT_SMB2_MAX_WRITE);
2290 lpcfg_do_global_parameter(lp_ctx, "passdb backend", "tdbsam");
2292 lpcfg_do_global_parameter(lp_ctx, "getwd cache", "True");
2294 lpcfg_do_global_parameter(lp_ctx, "winbind nested groups", "True");
2296 lpcfg_do_global_parameter(lp_ctx, "mangled names", "True");
2298 lpcfg_do_global_parameter_var(lp_ctx, "smb2 max credits", "%u", DEFAULT_SMB2_MAX_CREDITS);
2300 lpcfg_do_global_parameter(lp_ctx, "ldap ssl", "start tls");
2302 lpcfg_do_global_parameter(lp_ctx, "ldap deref", "auto");
2304 lpcfg_do_global_parameter(lp_ctx, "lm interval", "60");
2306 lpcfg_do_global_parameter(lp_ctx, "mangling method", "hash2");
2308 lpcfg_do_global_parameter(lp_ctx, "hide dot files", "True");
2310 lpcfg_do_global_parameter(lp_ctx, "browse list", "True");
2312 lpcfg_do_global_parameter(lp_ctx, "passwd chat timeout", "2");
2314 lpcfg_do_global_parameter(lp_ctx, "guest account", GUEST_ACCOUNT);
2316 lpcfg_do_global_parameter(lp_ctx, "client schannel", "auto");
2318 lpcfg_do_global_parameter(lp_ctx, "smb encrypt", "default");
2320 lpcfg_do_global_parameter(lp_ctx, "max log size", "5000");
2322 lpcfg_do_global_parameter(lp_ctx, "idmap negative cache time", "120");
2324 lpcfg_do_global_parameter(lp_ctx, "ldap follow referral", "auto");
2326 lpcfg_do_global_parameter(lp_ctx, "multicast dns register", "yes");
2328 lpcfg_do_global_parameter(lp_ctx, "winbind reconnect delay", "30");
2330 lpcfg_do_global_parameter(lp_ctx, "nt acl support", "yes");
2332 lpcfg_do_global_parameter(lp_ctx, "acl check permissions", "yes");
2334 lpcfg_do_global_parameter(lp_ctx, "keepalive", "300");
2336 lpcfg_do_global_parameter(lp_ctx, "winbind cache time", "300");
2338 lpcfg_do_global_parameter(lp_ctx, "level2 oplocks", "yes");
2340 lpcfg_do_global_parameter(lp_ctx, "show add printer wizard", "yes");
2342 lpcfg_do_global_parameter(lp_ctx, "allocation roundup size", "1048576");
2344 lpcfg_do_global_parameter(lp_ctx, "ldap page size", "1024");
2346 lpcfg_do_global_parameter(lp_ctx, "kernel share modes", "yes");
2348 lpcfg_do_global_parameter(lp_ctx, "strict locking", "Auto");
2350 lpcfg_do_global_parameter(lp_ctx, "map readonly", "yes");
2352 lpcfg_do_global_parameter(lp_ctx, "allow trusted domains", "yes");
2354 lpcfg_do_global_parameter(lp_ctx, "default devmode", "yes");
2356 lpcfg_do_global_parameter(lp_ctx, "os level", "20");
2358 lpcfg_do_global_parameter(lp_ctx, "dos filetimes", "yes");
2360 lpcfg_do_global_parameter(lp_ctx, "mangling char", "~");
2362 lpcfg_do_global_parameter(lp_ctx, "printcap cache time", "750");
2364 lpcfg_do_global_parameter(lp_ctx, "create krb5 conf", "yes");
2366 lpcfg_do_global_parameter(lp_ctx, "winbind max clients", "200");
2368 lpcfg_do_global_parameter(lp_ctx, "acl map full control", "yes");
2370 lpcfg_do_global_parameter(lp_ctx, "nt pipe support", "yes");
2372 lpcfg_do_global_parameter(lp_ctx, "ldap debug threshold", "10");
2374 lpcfg_do_global_parameter(lp_ctx, "follow symlinks", "yes");
2376 lpcfg_do_global_parameter(lp_ctx, "machine password timeout", "604800");
2378 lpcfg_do_global_parameter(lp_ctx, "ldap connection timeout", "2");
2380 lpcfg_do_global_parameter(lp_ctx, "winbind expand groups", "1");
2382 lpcfg_do_global_parameter(lp_ctx, "stat cache", "yes");
2384 lpcfg_do_global_parameter(lp_ctx, "lpq cache time", "30");
2386 lpcfg_do_global_parameter_var(lp_ctx, "smb2 max trans", "%u", DEFAULT_SMB2_MAX_TRANSACT);
2388 lpcfg_do_global_parameter_var(lp_ctx, "smb2 max read", "%u", DEFAULT_SMB2_MAX_READ);
2390 lpcfg_do_global_parameter(lp_ctx, "durable handles", "yes");
2392 lpcfg_do_global_parameter(lp_ctx, "max stat cache size", "256");
2394 lpcfg_do_global_parameter(lp_ctx, "ldap passwd sync", "no");
2396 lpcfg_do_global_parameter(lp_ctx, "kernel change notify", "yes");
2398 lpcfg_do_global_parameter(lp_ctx, "max ttl", "259200");
2400 lpcfg_do_global_parameter(lp_ctx, "blocking locks", "yes");
2402 lpcfg_do_global_parameter(lp_ctx, "oplock contention limit", "2");
2404 lpcfg_do_global_parameter(lp_ctx, "load printers", "yes");
2406 lpcfg_do_global_parameter(lp_ctx, "idmap cache time", "604800");
2408 lpcfg_do_global_parameter(lp_ctx, "preserve case", "yes");
2410 lpcfg_do_global_parameter(lp_ctx, "lm announce", "auto");
2412 lpcfg_do_global_parameter(lp_ctx, "afs token lifetime", "604800");
2414 lpcfg_do_global_parameter(lp_ctx, "enable core files", "yes");
2416 lpcfg_do_global_parameter(lp_ctx, "winbind max domain connections", "1");
2418 lpcfg_do_global_parameter(lp_ctx, "case sensitive", "auto");
2420 lpcfg_do_global_parameter(lp_ctx, "ldap timeout", "15");
2422 lpcfg_do_global_parameter(lp_ctx, "mangle prefix", "1");
2424 lpcfg_do_global_parameter(lp_ctx, "posix locking", "yes");
2426 lpcfg_do_global_parameter(lp_ctx, "lock spin time", "200");
2428 lpcfg_do_global_parameter(lp_ctx, "directory name cache size", "100");
2430 lpcfg_do_global_parameter(lp_ctx, "nmbd bind explicit broadcast", "yes");
2432 lpcfg_do_global_parameter(lp_ctx, "init logon delay", "100");
2434 lpcfg_do_global_parameter(lp_ctx, "usershare owner only", "yes");
2436 lpcfg_do_global_parameter(lp_ctx, "-valid", "yes");
2438 lpcfg_do_global_parameter_var(lp_ctx, "usershare path", "%s/usershares", get_dyn_STATEDIR());
2440 #ifdef DEVELOPER
2441 lpcfg_do_global_parameter_var(lp_ctx, "panic action", "/bin/sleep 999999999");
2442 #endif
2444 lpcfg_do_global_parameter(lp_ctx, "smb passwd file", get_dyn_SMB_PASSWD_FILE());
2446 lpcfg_do_global_parameter(lp_ctx, "logon home", "\\\\%N\\%U");
2448 lpcfg_do_global_parameter(lp_ctx, "logon path", "\\\\%N\\%U\\profile");
2450 lpcfg_do_global_parameter(lp_ctx, "printjob username", "%U");
2452 for (i = 0; parm_table[i].label; i++) {
2453 if (!(lp_ctx->flags[i] & FLAG_CMDLINE)) {
2454 lp_ctx->flags[i] |= FLAG_DEFAULT;
2458 for (parm=lp_ctx->globals->param_opt; parm; parm=parm->next) {
2459 if (!(parm->priority & FLAG_CMDLINE)) {
2460 parm->priority |= FLAG_DEFAULT;
2464 return lp_ctx;
2468 * Initialise the global parameter structure.
2470 struct loadparm_context *loadparm_init_global(bool load_default)
2472 if (global_loadparm_context == NULL) {
2473 global_loadparm_context = loadparm_init(NULL);
2475 if (global_loadparm_context == NULL) {
2476 return NULL;
2478 global_loadparm_context->global = true;
2479 if (load_default && !global_loadparm_context->loaded) {
2480 lpcfg_load_default(global_loadparm_context);
2482 global_loadparm_context->refuse_free = true;
2483 return global_loadparm_context;
2487 * Initialise the global parameter structure.
2489 struct loadparm_context *loadparm_init_s3(TALLOC_CTX *mem_ctx,
2490 const struct loadparm_s3_helpers *s3_fns)
2492 struct loadparm_context *loadparm_context = talloc_zero(mem_ctx, struct loadparm_context);
2493 if (!loadparm_context) {
2494 return NULL;
2496 loadparm_context->s3_fns = s3_fns;
2497 loadparm_context->globals = s3_fns->globals;
2498 return loadparm_context;
2501 const char *lpcfg_configfile(struct loadparm_context *lp_ctx)
2503 return lp_ctx->szConfigFile;
2506 const char *lp_default_path(void)
2508 if (getenv("SMB_CONF_PATH"))
2509 return getenv("SMB_CONF_PATH");
2510 else
2511 return dyn_CONFIGFILE;
2515 * Update the internal state of a loadparm context after settings
2516 * have changed.
2518 static bool lpcfg_update(struct loadparm_context *lp_ctx)
2520 struct debug_settings settings;
2521 TALLOC_CTX *tmp_ctx;
2523 tmp_ctx = talloc_new(lp_ctx);
2524 if (tmp_ctx == NULL) {
2525 return false;
2528 lpcfg_add_auto_services(lp_ctx, lpcfg_auto_services(lp_ctx, tmp_ctx));
2530 if (!lp_ctx->globals->wins_server_list && lp_ctx->globals->we_are_a_wins_server) {
2531 lpcfg_do_global_parameter(lp_ctx, "wins server", "127.0.0.1");
2534 if (!lp_ctx->global) {
2535 TALLOC_FREE(tmp_ctx);
2536 return true;
2539 panic_action = lp_ctx->globals->panic_action;
2541 reload_charcnv(lp_ctx);
2543 ZERO_STRUCT(settings);
2544 /* Add any more debug-related smb.conf parameters created in
2545 * future here */
2546 settings.syslog = lp_ctx->globals->syslog;
2547 settings.syslog_only = lp_ctx->globals->syslog_only;
2548 settings.timestamp_logs = lp_ctx->globals->timestamp_logs;
2549 settings.debug_prefix_timestamp = lp_ctx->globals->debug_prefix_timestamp;
2550 settings.debug_hires_timestamp = lp_ctx->globals->debug_hires_timestamp;
2551 settings.debug_pid = lp_ctx->globals->debug_pid;
2552 settings.debug_uid = lp_ctx->globals->debug_uid;
2553 settings.debug_class = lp_ctx->globals->debug_class;
2554 debug_set_settings(&settings);
2556 /* FIXME: This is a bit of a hack, but we can't use a global, since
2557 * not everything that uses lp also uses the socket library */
2558 if (lpcfg_parm_bool(lp_ctx, NULL, "socket", "testnonblock", false)) {
2559 setenv("SOCKET_TESTNONBLOCK", "1", 1);
2560 } else {
2561 unsetenv("SOCKET_TESTNONBLOCK");
2564 TALLOC_FREE(tmp_ctx);
2565 return true;
2568 bool lpcfg_load_default(struct loadparm_context *lp_ctx)
2570 const char *path;
2572 path = lp_default_path();
2574 if (!file_exist(path)) {
2575 /* We allow the default smb.conf file to not exist,
2576 * basically the equivalent of an empty file. */
2577 return lpcfg_update(lp_ctx);
2580 return lpcfg_load(lp_ctx, path);
2584 * Load the services array from the services file.
2586 * Return True on success, False on failure.
2588 bool lpcfg_load(struct loadparm_context *lp_ctx, const char *filename)
2590 char *n2;
2591 bool bRetval;
2593 filename = talloc_strdup(lp_ctx, filename);
2595 lp_ctx->szConfigFile = filename;
2597 if (lp_ctx->s3_fns) {
2598 return lp_ctx->s3_fns->load(filename);
2601 lp_ctx->bInGlobalSection = true;
2602 n2 = standard_sub_basic(lp_ctx, lp_ctx->szConfigFile);
2603 DEBUG(2, ("lpcfg_load: refreshing parameters from %s\n", n2));
2605 add_to_file_list(lp_ctx, &lp_ctx->file_lists, lp_ctx->szConfigFile, n2);
2607 /* We get sections first, so have to start 'behind' to make up */
2608 lp_ctx->currentService = NULL;
2609 bRetval = pm_process(n2, do_section, do_parameter, lp_ctx);
2611 /* finish up the last section */
2612 DEBUG(4, ("pm_process() returned %s\n", BOOLSTR(bRetval)));
2613 if (bRetval)
2614 if (lp_ctx->currentService != NULL)
2615 bRetval = lpcfg_service_ok(lp_ctx->currentService);
2617 bRetval = bRetval && lpcfg_update(lp_ctx);
2619 /* we do this unconditionally, so that it happens even
2620 for a missing smb.conf */
2621 reload_charcnv(lp_ctx);
2623 if (bRetval == true) {
2624 /* set this up so that any child python tasks will
2625 find the right smb.conf */
2626 setenv("SMB_CONF_PATH", filename, 1);
2628 /* set the context used by the lp_*() function
2629 varients */
2630 global_loadparm_context = lp_ctx;
2631 lp_ctx->loaded = true;
2634 return bRetval;
2638 * Return the max number of services.
2641 int lpcfg_numservices(struct loadparm_context *lp_ctx)
2643 if (lp_ctx->s3_fns) {
2644 return lp_ctx->s3_fns->get_numservices();
2647 return lp_ctx->iNumServices;
2651 * Display the contents of the services array in human-readable form.
2654 void lpcfg_dump(struct loadparm_context *lp_ctx, FILE *f, bool show_defaults,
2655 int maxtoprint)
2657 int iService;
2659 if (lp_ctx->s3_fns) {
2660 lp_ctx->s3_fns->dump(f, show_defaults, maxtoprint);
2661 return;
2664 defaults_saved = !show_defaults;
2666 dump_globals(lp_ctx, f, show_defaults);
2668 dump_a_service(lp_ctx->sDefault, lp_ctx->sDefault, f, lp_ctx->flags);
2670 for (iService = 0; iService < maxtoprint; iService++)
2671 lpcfg_dump_one(f, show_defaults, lp_ctx->services[iService], lp_ctx->sDefault);
2675 * Display the contents of one service in human-readable form.
2677 void lpcfg_dump_one(FILE *f, bool show_defaults, struct loadparm_service *service, struct loadparm_service *sDefault)
2679 if (service != NULL) {
2680 if (service->szService[0] == '\0')
2681 return;
2682 dump_a_service(service, sDefault, f, NULL);
2686 struct loadparm_service *lpcfg_servicebynum(struct loadparm_context *lp_ctx,
2687 int snum)
2689 if (lp_ctx->s3_fns) {
2690 return lp_ctx->s3_fns->get_servicebynum(snum);
2693 return lp_ctx->services[snum];
2696 struct loadparm_service *lpcfg_service(struct loadparm_context *lp_ctx,
2697 const char *service_name)
2699 int iService;
2700 char *serviceName;
2702 if (lp_ctx->s3_fns) {
2703 return lp_ctx->s3_fns->get_service(service_name);
2706 for (iService = lp_ctx->iNumServices - 1; iService >= 0; iService--) {
2707 if (lp_ctx->services[iService] &&
2708 lp_ctx->services[iService]->szService) {
2710 * The substitution here is used to support %U is
2711 * service names
2713 serviceName = standard_sub_basic(
2714 lp_ctx->services[iService],
2715 lp_ctx->services[iService]->szService);
2716 if (strequal(serviceName, service_name)) {
2717 talloc_free(serviceName);
2718 return lp_ctx->services[iService];
2720 talloc_free(serviceName);
2724 DEBUG(7,("lpcfg_servicenumber: couldn't find %s\n", service_name));
2725 return NULL;
2728 const char *lpcfg_servicename(const struct loadparm_service *service)
2730 return lpcfg_string((const char *)service->szService);
2734 * A useful volume label function.
2736 const char *lpcfg_volume_label(struct loadparm_service *service, struct loadparm_service *sDefault)
2738 const char *ret;
2739 ret = lpcfg_string((const char *)((service != NULL && service->volume != NULL) ?
2740 service->volume : sDefault->volume));
2741 if (!*ret)
2742 return lpcfg_servicename(service);
2743 return ret;
2747 * Return the correct printer name.
2749 const char *lpcfg_printername(struct loadparm_service *service, struct loadparm_service *sDefault)
2751 const char *ret;
2752 ret = lpcfg_string((const char *)((service != NULL && service->_printername != NULL) ?
2753 service->_printername : sDefault->_printername));
2754 if (ret == NULL || (ret != NULL && *ret == '\0'))
2755 ret = lpcfg_servicename(service);
2757 return ret;
2762 * Return the max print jobs per queue.
2764 int lpcfg_maxprintjobs(struct loadparm_service *service, struct loadparm_service *sDefault)
2766 int maxjobs = (service != NULL) ? service->iMaxPrintJobs : sDefault->iMaxPrintJobs;
2767 if (maxjobs <= 0 || maxjobs >= PRINT_MAX_JOBID)
2768 maxjobs = PRINT_MAX_JOBID - 1;
2770 return maxjobs;
2773 struct smb_iconv_handle *lpcfg_iconv_handle(struct loadparm_context *lp_ctx)
2775 if (lp_ctx == NULL) {
2776 return get_iconv_handle();
2778 return lp_ctx->iconv_handle;
2781 _PUBLIC_ void reload_charcnv(struct loadparm_context *lp_ctx)
2783 struct smb_iconv_handle *old_ic = lp_ctx->iconv_handle;
2784 if (!lp_ctx->global) {
2785 return;
2788 if (old_ic == NULL) {
2789 old_ic = global_iconv_handle;
2791 lp_ctx->iconv_handle = smb_iconv_handle_reinit_lp(lp_ctx, lp_ctx, old_ic);
2792 global_iconv_handle = lp_ctx->iconv_handle;
2795 _PUBLIC_ char *lpcfg_tls_keyfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
2797 return lpcfg_private_path(mem_ctx, lp_ctx, lpcfg__tls_keyfile(lp_ctx));
2800 _PUBLIC_ char *lpcfg_tls_certfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
2802 return lpcfg_private_path(mem_ctx, lp_ctx, lpcfg__tls_certfile(lp_ctx));
2805 _PUBLIC_ char *lpcfg_tls_cafile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
2807 return lpcfg_private_path(mem_ctx, lp_ctx, lpcfg__tls_cafile(lp_ctx));
2810 _PUBLIC_ char *lpcfg_tls_crlfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
2812 return lpcfg_private_path(mem_ctx, lp_ctx, lpcfg__tls_crlfile(lp_ctx));
2815 _PUBLIC_ char *lpcfg_tls_dhpfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
2817 return lpcfg_private_path(mem_ctx, lp_ctx, lpcfg__tls_dhpfile(lp_ctx));
2820 struct gensec_settings *lpcfg_gensec_settings(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
2822 struct gensec_settings *settings = talloc_zero(mem_ctx, struct gensec_settings);
2823 if (settings == NULL)
2824 return NULL;
2825 SMB_ASSERT(lp_ctx != NULL);
2826 settings->lp_ctx = talloc_reference(settings, lp_ctx);
2827 settings->target_hostname = lpcfg_parm_string(lp_ctx, NULL, "gensec", "target_hostname");
2828 return settings;
2831 int lpcfg_server_role(struct loadparm_context *lp_ctx)
2833 int domain_master = lpcfg__domain_master(lp_ctx);
2835 return lp_find_server_role(lpcfg__server_role(lp_ctx),
2836 lpcfg__security(lp_ctx),
2837 lpcfg__domain_logons(lp_ctx),
2838 (domain_master == true) ||
2839 (domain_master == Auto));
2842 int lpcfg_security(struct loadparm_context *lp_ctx)
2844 return lp_find_security(lpcfg__server_role(lp_ctx),
2845 lpcfg__security(lp_ctx));
2848 bool lpcfg_server_signing_allowed(struct loadparm_context *lp_ctx, bool *mandatory)
2850 bool allowed = true;
2851 enum smb_signing_setting signing_setting = lpcfg_server_signing(lp_ctx);
2853 *mandatory = false;
2855 if (signing_setting == SMB_SIGNING_DEFAULT) {
2857 * If we are a domain controller, SMB signing is
2858 * really important, as it can prevent a number of
2859 * attacks on communications between us and the
2860 * clients
2862 * However, it really sucks (no sendfile, CPU
2863 * overhead) performance-wise when used on a
2864 * file server, so disable it by default
2865 * on non-DCs
2868 if (lpcfg_server_role(lp_ctx) >= ROLE_ACTIVE_DIRECTORY_DC) {
2869 signing_setting = SMB_SIGNING_REQUIRED;
2870 } else {
2871 signing_setting = SMB_SIGNING_OFF;
2875 switch (signing_setting) {
2876 case SMB_SIGNING_REQUIRED:
2877 *mandatory = true;
2878 break;
2879 case SMB_SIGNING_IF_REQUIRED:
2880 break;
2881 case SMB_SIGNING_DEFAULT:
2882 case SMB_SIGNING_OFF:
2883 allowed = false;
2884 break;
2887 return allowed;
2890 int lpcfg_tdb_hash_size(struct loadparm_context *lp_ctx, const char *name)
2892 const char *base;
2894 if (name == NULL) {
2895 return 0;
2898 base = strrchr_m(name, '/');
2899 if (base != NULL) {
2900 base += 1;
2901 } else {
2902 base = name;
2904 return lpcfg_parm_int(lp_ctx, NULL, "tdb_hashsize", base, 0);
2908 int lpcfg_tdb_flags(struct loadparm_context *lp_ctx, int tdb_flags)
2910 if (!lpcfg_use_mmap(lp_ctx)) {
2911 tdb_flags |= TDB_NOMMAP;
2913 return tdb_flags;