param: move handle printing into lib/param
[Samba.git] / lib / param / loadparm.c
blob5b89a4f1dba21bea0781efd1e376b75906611971
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_ldap_debug_level NULL
85 #define handle_idmap_backend NULL
86 #define handle_idmap_uid NULL
87 #define handle_idmap_gid NULL
89 #ifndef N_
90 #define N_(x) x
91 #endif
93 #include "lib/param/param_table.c"
95 struct loadparm_service *lpcfg_default_service(struct loadparm_context *lp_ctx)
97 if (lp_ctx->s3_fns) {
98 return lp_ctx->s3_fns->get_default_loadparm_service();
100 return lp_ctx->sDefault;
104 * Convenience routine to grab string parameters into temporary memory
105 * and run standard_sub_basic on them.
107 * The buffers can be written to by
108 * callers without affecting the source string.
111 static const char *lpcfg_string(const char *s)
113 #if 0 /* until REWRITE done to make thread-safe */
114 size_t len = s ? strlen(s) : 0;
115 char *ret;
116 #endif
118 /* The follow debug is useful for tracking down memory problems
119 especially if you have an inner loop that is calling a lp_*()
120 function that returns a string. Perhaps this debug should be
121 present all the time? */
123 #if 0
124 DEBUG(10, ("lpcfg_string(%s)\n", s));
125 #endif
127 #if 0 /* until REWRITE done to make thread-safe */
128 if (!lp_talloc)
129 lp_talloc = talloc_init("lp_talloc");
131 ret = talloc_array(lp_talloc, char, len + 100); /* leave room for substitution */
133 if (!ret)
134 return NULL;
136 if (!s)
137 *ret = 0;
138 else
139 strlcpy(ret, s, len);
141 if (trim_string(ret, "\"", "\"")) {
142 if (strchr(ret,'"') != NULL)
143 strlcpy(ret, s, len);
146 standard_sub_basic(ret,len+100);
147 return (ret);
148 #endif
149 return s;
153 In this section all the functions that are used to access the
154 parameters from the rest of the program are defined
158 * the creation of separate lpcfg_*() and lp_*() functions is to allow
159 * for code compatibility between existing Samba4 and Samba3 code.
162 /* this global context supports the lp_*() function varients */
163 static struct loadparm_context *global_loadparm_context;
165 #define lpcfg_default_service global_loadparm_context->sDefault
166 #define lpcfg_global_service(i) global_loadparm_context->services[i]
168 #define FN_GLOBAL_STRING(fn_name,var_name) \
169 _PUBLIC_ char *lpcfg_ ## fn_name(struct loadparm_context *lp_ctx, TALLOC_CTX *ctx) {\
170 if (lp_ctx == NULL) return NULL; \
171 if (lp_ctx->s3_fns) { \
172 return lp_ctx->globals->var_name ? lp_ctx->s3_fns->lp_string(ctx, lp_ctx->globals->var_name) : talloc_strdup(ctx, ""); \
174 return lp_ctx->globals->var_name ? talloc_strdup(ctx, lpcfg_string(lp_ctx->globals->var_name)) : talloc_strdup(ctx, ""); \
177 #define FN_GLOBAL_CONST_STRING(fn_name,var_name) \
178 _PUBLIC_ const char *lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) { \
179 if (lp_ctx == NULL) return NULL; \
180 return lp_ctx->globals->var_name ? lpcfg_string(lp_ctx->globals->var_name) : ""; \
183 #define FN_GLOBAL_LIST(fn_name,var_name) \
184 _PUBLIC_ const char **lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) { \
185 if (lp_ctx == NULL) return NULL; \
186 return lp_ctx->globals->var_name; \
189 #define FN_GLOBAL_BOOL(fn_name,var_name) \
190 _PUBLIC_ bool lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) {\
191 if (lp_ctx == NULL) return false; \
192 return lp_ctx->globals->var_name; \
195 #define FN_GLOBAL_INTEGER(fn_name,var_name) \
196 _PUBLIC_ int lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) { \
197 return lp_ctx->globals->var_name; \
200 /* Local parameters don't need the ->s3_fns because the struct
201 * loadparm_service is shared and lpcfg_service() checks the ->s3_fns
202 * hook */
203 #define FN_LOCAL_STRING(fn_name,val) \
204 _PUBLIC_ char *lpcfg_ ## fn_name(struct loadparm_service *service, \
205 struct loadparm_service *sDefault, TALLOC_CTX *ctx) { \
206 return(talloc_strdup(ctx, lpcfg_string((const char *)((service != NULL && service->val != NULL) ? service->val : sDefault->val)))); \
209 #define FN_LOCAL_CONST_STRING(fn_name,val) \
210 _PUBLIC_ const char *lpcfg_ ## fn_name(struct loadparm_service *service, \
211 struct loadparm_service *sDefault) { \
212 return((const char *)((service != NULL && service->val != NULL) ? service->val : sDefault->val)); \
215 #define FN_LOCAL_LIST(fn_name,val) \
216 _PUBLIC_ const char **lpcfg_ ## fn_name(struct loadparm_service *service, \
217 struct loadparm_service *sDefault) {\
218 return(const char **)(service != NULL && service->val != NULL? service->val : sDefault->val); \
221 #define FN_LOCAL_PARM_BOOL(fn_name, val) FN_LOCAL_BOOL(fn_name, val)
223 #define FN_LOCAL_BOOL(fn_name,val) \
224 _PUBLIC_ bool lpcfg_ ## fn_name(struct loadparm_service *service, \
225 struct loadparm_service *sDefault) { \
226 return((service != NULL)? service->val : sDefault->val); \
229 #define FN_LOCAL_INTEGER(fn_name,val) \
230 _PUBLIC_ int lpcfg_ ## fn_name(struct loadparm_service *service, \
231 struct loadparm_service *sDefault) { \
232 return((service != NULL)? service->val : sDefault->val); \
235 #define FN_LOCAL_PARM_INTEGER(fn_name, val) FN_LOCAL_INTEGER(fn_name, val)
237 #define FN_LOCAL_PARM_CHAR(fn_name,val) \
238 _PUBLIC_ char lpcfg_ ## fn_name(struct loadparm_service *service, \
239 struct loadparm_service *sDefault) { \
240 return((service != NULL)? service->val : sDefault->val); \
243 #include "lib/param/param_functions.c"
245 /* These functions cannot be auto-generated */
246 FN_LOCAL_BOOL(autoloaded, autoloaded)
247 FN_GLOBAL_CONST_STRING(dnsdomain, dnsdomain)
249 /* local prototypes */
250 static struct loadparm_service *lpcfg_getservicebyname(struct loadparm_context *lp_ctx,
251 const char *pszServiceName);
252 static bool lpcfg_service_ok(struct loadparm_service *service);
253 static bool do_section(const char *pszSectionName, void *);
255 /* This is a helper function for parametrical options support. */
256 /* It returns a pointer to parametrical option value if it exists or NULL otherwise */
257 /* Actual parametrical functions are quite simple */
258 const char *lpcfg_get_parametric(struct loadparm_context *lp_ctx,
259 struct loadparm_service *service,
260 const char *type, const char *option)
262 char *vfskey_tmp = NULL;
263 char *vfskey = NULL;
264 struct parmlist_entry *data;
266 if (lp_ctx == NULL)
267 return NULL;
269 if (lp_ctx->s3_fns) {
270 return lp_ctx->s3_fns->get_parametric(service, type, option, NULL);
273 data = (service == NULL ? lp_ctx->globals->param_opt : service->param_opt);
275 vfskey_tmp = talloc_asprintf(NULL, "%s:%s", type, option);
276 if (vfskey_tmp == NULL) return NULL;
277 vfskey = strlower_talloc(NULL, vfskey_tmp);
278 talloc_free(vfskey_tmp);
280 while (data) {
281 if (strcmp(data->key, vfskey) == 0) {
282 talloc_free(vfskey);
283 return data->value;
285 data = data->next;
288 if (service != NULL) {
289 /* Try to fetch the same option but from globals */
290 /* but only if we are not already working with globals */
291 for (data = lp_ctx->globals->param_opt; data;
292 data = data->next) {
293 if (strcmp(data->key, vfskey) == 0) {
294 talloc_free(vfskey);
295 return data->value;
300 talloc_free(vfskey);
302 return NULL;
307 * convenience routine to return int parameters.
309 int lp_int(const char *s)
312 if (!s || !*s) {
313 DEBUG(0,("lp_int(%s): is called with NULL!\n",s));
314 return -1;
317 return strtol(s, NULL, 0);
321 * convenience routine to return unsigned long parameters.
323 unsigned long lp_ulong(const char *s)
326 if (!s || !*s) {
327 DEBUG(0,("lp_ulong(%s): is called with NULL!\n",s));
328 return -1;
331 return strtoul(s, NULL, 0);
335 * convenience routine to return unsigned long parameters.
337 static long lp_long(const char *s)
340 if (!s) {
341 DEBUG(0,("lp_long(%s): is called with NULL!\n",s));
342 return -1;
345 return strtol(s, NULL, 0);
349 * convenience routine to return unsigned long parameters.
351 static double lp_double(const char *s)
354 if (!s) {
355 DEBUG(0,("lp_double(%s): is called with NULL!\n",s));
356 return -1;
359 return strtod(s, NULL);
363 * convenience routine to return boolean parameters.
365 bool lp_bool(const char *s)
367 bool ret = false;
369 if (!s || !*s) {
370 DEBUG(0,("lp_bool(%s): is called with NULL!\n",s));
371 return false;
374 if (!set_boolean(s, &ret)) {
375 DEBUG(0,("lp_bool(%s): value is not boolean!\n",s));
376 return false;
379 return ret;
383 * Return parametric option from a given service. Type is a part of option before ':'
384 * Parametric option has following syntax: 'Type: option = value'
385 * Returned value is allocated in 'lp_talloc' context
388 const char *lpcfg_parm_string(struct loadparm_context *lp_ctx,
389 struct loadparm_service *service, const char *type,
390 const char *option)
392 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
394 if (value)
395 return lpcfg_string(value);
397 return NULL;
401 * Return parametric option from a given service. Type is a part of option before ':'
402 * Parametric option has following syntax: 'Type: option = value'
403 * Returned value is allocated in 'lp_talloc' context
406 const char **lpcfg_parm_string_list(TALLOC_CTX *mem_ctx,
407 struct loadparm_context *lp_ctx,
408 struct loadparm_service *service,
409 const char *type,
410 const char *option, const char *separator)
412 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
414 if (value != NULL)
415 return (const char **)str_list_make(mem_ctx, value, separator);
417 return NULL;
421 * Return parametric option from a given service. Type is a part of option before ':'
422 * Parametric option has following syntax: 'Type: option = value'
425 int lpcfg_parm_int(struct loadparm_context *lp_ctx,
426 struct loadparm_service *service, const char *type,
427 const char *option, int default_v)
429 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
431 if (value)
432 return lp_int(value);
434 return default_v;
438 * Return parametric option from a given service. Type is a part of
439 * option before ':'.
440 * Parametric option has following syntax: 'Type: option = value'.
443 int lpcfg_parm_bytes(struct loadparm_context *lp_ctx,
444 struct loadparm_service *service, const char *type,
445 const char *option, int default_v)
447 uint64_t bval;
449 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
451 if (value && conv_str_size_error(value, &bval)) {
452 if (bval <= INT_MAX) {
453 return (int)bval;
457 return default_v;
461 * Return parametric option from a given service.
462 * Type is a part of option before ':'
463 * Parametric option has following syntax: 'Type: option = value'
465 unsigned long lpcfg_parm_ulong(struct loadparm_context *lp_ctx,
466 struct loadparm_service *service, const char *type,
467 const char *option, unsigned long default_v)
469 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
471 if (value)
472 return lp_ulong(value);
474 return default_v;
477 long lpcfg_parm_long(struct loadparm_context *lp_ctx,
478 struct loadparm_service *service, const char *type,
479 const char *option, long default_v)
481 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
483 if (value)
484 return lp_long(value);
486 return default_v;
489 double lpcfg_parm_double(struct loadparm_context *lp_ctx,
490 struct loadparm_service *service, const char *type,
491 const char *option, double default_v)
493 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
495 if (value != NULL)
496 return lp_double(value);
498 return default_v;
502 * Return parametric option from a given service. Type is a part of option before ':'
503 * Parametric option has following syntax: 'Type: option = value'
506 bool lpcfg_parm_bool(struct loadparm_context *lp_ctx,
507 struct loadparm_service *service, const char *type,
508 const char *option, bool default_v)
510 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
512 if (value != NULL)
513 return lp_bool(value);
515 return default_v;
520 * Set a string value, deallocating any existing space, and allocing the space
521 * for the string
523 bool lpcfg_string_set(TALLOC_CTX *mem_ctx, char **dest, const char *src)
525 talloc_free(*dest);
527 if (src == NULL)
528 src = "";
530 *dest = talloc_strdup(mem_ctx, src);
531 if ((*dest) == NULL) {
532 DEBUG(0,("Out of memory in string_set\n"));
533 return false;
536 return true;
540 * Set a string value, deallocating any existing space, and allocing the space
541 * for the string
543 static bool lpcfg_string_set_upper(TALLOC_CTX *mem_ctx, char **dest, const char *src)
545 talloc_free(*dest);
547 if (src == NULL)
548 src = "";
550 *dest = strupper_talloc(mem_ctx, src);
551 if ((*dest) == NULL) {
552 DEBUG(0,("Out of memory in string_set_upper\n"));
553 return false;
556 return true;
562 * Add a new service to the services array initialising it with the given
563 * service.
566 struct loadparm_service *lpcfg_add_service(struct loadparm_context *lp_ctx,
567 const struct loadparm_service *pservice,
568 const char *name)
570 int i;
571 int num_to_alloc = lp_ctx->iNumServices + 1;
572 struct parmlist_entry *data, *pdata;
574 if (pservice == NULL) {
575 pservice = lp_ctx->sDefault;
578 /* it might already exist */
579 if (name) {
580 struct loadparm_service *service = lpcfg_getservicebyname(lp_ctx,
581 name);
582 if (service != NULL) {
583 /* Clean all parametric options for service */
584 /* They will be added during parsing again */
585 data = service->param_opt;
586 while (data) {
587 pdata = data->next;
588 talloc_free(data);
589 data = pdata;
591 service->param_opt = NULL;
592 return service;
596 /* find an invalid one */
597 for (i = 0; i < lp_ctx->iNumServices; i++)
598 if (lp_ctx->services[i] == NULL)
599 break;
601 /* if not, then create one */
602 if (i == lp_ctx->iNumServices) {
603 struct loadparm_service **tsp;
605 tsp = talloc_realloc(lp_ctx, lp_ctx->services, struct loadparm_service *, num_to_alloc);
607 if (!tsp) {
608 DEBUG(0,("lpcfg_add_service: failed to enlarge services!\n"));
609 return NULL;
610 } else {
611 lp_ctx->services = tsp;
612 lp_ctx->services[lp_ctx->iNumServices] = NULL;
615 lp_ctx->iNumServices++;
618 lp_ctx->services[i] = talloc_zero(lp_ctx->services, struct loadparm_service);
619 if (lp_ctx->services[i] == NULL) {
620 DEBUG(0,("lpcfg_add_service: out of memory!\n"));
621 return NULL;
623 copy_service(lp_ctx->services[i], pservice, NULL);
624 if (name != NULL)
625 lpcfg_string_set(lp_ctx->services[i], &lp_ctx->services[i]->szService, name);
626 return lp_ctx->services[i];
630 * Add a new home service, with the specified home directory, defaults coming
631 * from service ifrom.
634 bool lpcfg_add_home(struct loadparm_context *lp_ctx,
635 const char *pszHomename,
636 struct loadparm_service *default_service,
637 const char *user, const char *pszHomedir)
639 struct loadparm_service *service;
641 service = lpcfg_add_service(lp_ctx, default_service, pszHomename);
643 if (service == NULL)
644 return false;
646 if (!(*(default_service->path))
647 || strequal(default_service->path, lp_ctx->sDefault->path)) {
648 service->path = talloc_strdup(service, pszHomedir);
649 } else {
650 service->path = string_sub_talloc(service, lpcfg_path(default_service, lp_ctx->sDefault, service), "%H", pszHomedir);
653 if (!(*(service->comment))) {
654 service->comment = talloc_asprintf(service, "Home directory of %s", user);
656 service->bAvailable = default_service->bAvailable;
657 service->browseable = default_service->browseable;
659 DEBUG(3, ("adding home's share [%s] for user '%s' at '%s'\n",
660 pszHomename, user, service->path));
662 return true;
666 * Add a new printer service, with defaults coming from service iFrom.
669 bool lpcfg_add_printer(struct loadparm_context *lp_ctx,
670 const char *pszPrintername,
671 struct loadparm_service *default_service)
673 const char *comment = "From Printcap";
674 struct loadparm_service *service;
675 service = lpcfg_add_service(lp_ctx, default_service, pszPrintername);
677 if (service == NULL)
678 return false;
680 /* note that we do NOT default the availability flag to True - */
681 /* we take it from the default service passed. This allows all */
682 /* dynamic printers to be disabled by disabling the [printers] */
683 /* entry (if/when the 'available' keyword is implemented!). */
685 /* the printer name is set to the service name. */
686 lpcfg_string_set(service, &service->_printername, pszPrintername);
687 lpcfg_string_set(service, &service->comment, comment);
688 service->browseable = default_service->browseable;
689 /* Printers cannot be read_only. */
690 service->read_only = false;
691 /* Printer services must be printable. */
692 service->printable = true;
694 DEBUG(3, ("adding printer service %s\n", pszPrintername));
696 return true;
700 * Map a parameter's string representation to something we can use.
701 * Returns False if the parameter string is not recognised, else TRUE.
704 int lpcfg_map_parameter(const char *pszParmName)
706 int iIndex;
708 for (iIndex = 0; parm_table[iIndex].label; iIndex++)
709 if (strwicmp(parm_table[iIndex].label, pszParmName) == 0)
710 return iIndex;
712 /* Warn only if it isn't parametric option */
713 if (strchr(pszParmName, ':') == NULL)
714 DEBUG(0, ("Unknown parameter encountered: \"%s\"\n", pszParmName));
715 /* We do return 'fail' for parametric options as well because they are
716 stored in different storage
718 return -1;
723 return the parameter structure for a parameter
725 struct parm_struct *lpcfg_parm_struct(struct loadparm_context *lp_ctx, const char *name)
727 int parmnum;
729 if (lp_ctx->s3_fns) {
730 return lp_ctx->s3_fns->get_parm_struct(name);
733 parmnum = lpcfg_map_parameter(name);
734 if (parmnum == -1) return NULL;
735 return &parm_table[parmnum];
739 return the parameter pointer for a parameter
741 void *lpcfg_parm_ptr(struct loadparm_context *lp_ctx,
742 struct loadparm_service *service, struct parm_struct *parm)
744 if (lp_ctx->s3_fns) {
745 return lp_ctx->s3_fns->get_parm_ptr(service, parm);
748 if (service == NULL) {
749 if (parm->p_class == P_LOCAL)
750 return ((char *)lp_ctx->sDefault)+parm->offset;
751 else if (parm->p_class == P_GLOBAL)
752 return ((char *)lp_ctx->globals)+parm->offset;
753 else return NULL;
754 } else {
755 return ((char *)service) + parm->offset;
760 return the parameter pointer for a parameter
762 bool lpcfg_parm_is_cmdline(struct loadparm_context *lp_ctx, const char *name)
764 int parmnum;
766 if (lp_ctx->s3_fns) {
767 struct parm_struct *parm = lp_ctx->s3_fns->get_parm_struct(name);
768 if (parm) {
769 return parm->flags & FLAG_CMDLINE;
771 return false;
774 parmnum = lpcfg_map_parameter(name);
775 if (parmnum == -1) return false;
777 return lp_ctx->flags[parmnum] & FLAG_CMDLINE;
781 * Find a service by name. Otherwise works like get_service.
784 static struct loadparm_service *lpcfg_getservicebyname(struct loadparm_context *lp_ctx,
785 const char *pszServiceName)
787 int iService;
789 if (lp_ctx->s3_fns) {
790 return lp_ctx->s3_fns->get_service(pszServiceName);
793 for (iService = lp_ctx->iNumServices - 1; iService >= 0; iService--)
794 if (lp_ctx->services[iService] != NULL &&
795 strwicmp(lp_ctx->services[iService]->szService, pszServiceName) == 0) {
796 return lp_ctx->services[iService];
799 return NULL;
803 * Add a parametric option to a parmlist_entry,
804 * replacing old value, if already present.
806 void set_param_opt(TALLOC_CTX *mem_ctx,
807 struct parmlist_entry **opt_list,
808 const char *opt_name,
809 const char *opt_value,
810 unsigned priority)
812 struct parmlist_entry *new_opt, *opt;
813 bool not_added;
815 opt = *opt_list;
816 not_added = true;
818 /* Traverse destination */
819 while (opt) {
820 /* If we already have same option, override it */
821 if (strwicmp(opt->key, opt_name) == 0) {
822 if ((opt->priority & FLAG_CMDLINE) &&
823 !(priority & FLAG_CMDLINE)) {
824 /* it's been marked as not to be
825 overridden */
826 return;
828 TALLOC_FREE(opt->value);
829 TALLOC_FREE(opt->list);
830 opt->value = talloc_strdup(opt, opt_value);
831 opt->priority = priority;
832 not_added = false;
833 break;
835 opt = opt->next;
837 if (not_added) {
838 new_opt = talloc(mem_ctx, struct parmlist_entry);
839 if (new_opt == NULL) {
840 smb_panic("OOM");
843 new_opt->key = talloc_strdup(new_opt, opt_name);
844 if (new_opt->key == NULL) {
845 smb_panic("talloc_strdup failed");
848 new_opt->value = talloc_strdup(new_opt, opt_value);
849 if (new_opt->value == NULL) {
850 smb_panic("talloc_strdup failed");
853 new_opt->list = NULL;
854 new_opt->priority = priority;
855 DLIST_ADD(*opt_list, new_opt);
860 * Copy a service structure to another.
861 * If pcopymapDest is NULL then copy all fields
864 void copy_service(struct loadparm_service *pserviceDest,
865 const struct loadparm_service *pserviceSource,
866 struct bitmap *pcopymapDest)
868 int i;
869 bool bcopyall = (pcopymapDest == NULL);
870 struct parmlist_entry *data;
872 for (i = 0; parm_table[i].label; i++)
873 if (parm_table[i].p_class == P_LOCAL &&
874 (bcopyall || bitmap_query(pcopymapDest, i))) {
875 const void *src_ptr =
876 ((const char *)pserviceSource) + parm_table[i].offset;
877 void *dest_ptr =
878 ((char *)pserviceDest) + parm_table[i].offset;
880 switch (parm_table[i].type) {
881 case P_BOOL:
882 case P_BOOLREV:
883 *(bool *)dest_ptr = *(const bool *)src_ptr;
884 break;
886 case P_INTEGER:
887 case P_BYTES:
888 case P_OCTAL:
889 case P_ENUM:
890 *(int *)dest_ptr = *(const int *)src_ptr;
891 break;
893 case P_CHAR:
894 *(char *)dest_ptr = *(const char *)src_ptr;
895 break;
897 case P_STRING:
898 lpcfg_string_set(pserviceDest,
899 (char **)dest_ptr,
900 *(const char * const *)src_ptr);
901 break;
903 case P_USTRING:
904 lpcfg_string_set_upper(pserviceDest,
905 (char **)dest_ptr,
906 *(const char * const *)src_ptr);
907 break;
908 case P_LIST:
909 TALLOC_FREE(*((char ***)dest_ptr));
910 *(const char * const **)dest_ptr = (const char * const *)str_list_copy(pserviceDest,
911 *(const char * * const *)src_ptr);
912 break;
913 default:
914 break;
918 if (bcopyall) {
919 init_copymap(pserviceDest);
920 if (pserviceSource->copymap)
921 bitmap_copy(pserviceDest->copymap,
922 pserviceSource->copymap);
925 for (data = pserviceSource->param_opt; data != NULL; data = data->next) {
926 set_param_opt(pserviceDest, &pserviceDest->param_opt,
927 data->key, data->value, data->priority);
932 * Check a service for consistency. Return False if the service is in any way
933 * incomplete or faulty, else True.
935 static bool lpcfg_service_ok(struct loadparm_service *service)
937 bool bRetval;
939 bRetval = true;
940 if (service->szService[0] == '\0') {
941 DEBUG(0, ("The following message indicates an internal error:\n"));
942 DEBUG(0, ("No service name in service entry.\n"));
943 bRetval = false;
946 /* The [printers] entry MUST be printable. I'm all for flexibility, but */
947 /* I can't see why you'd want a non-printable printer service... */
948 if (strwicmp(service->szService, PRINTERS_NAME) == 0) {
949 if (!service->printable) {
950 DEBUG(0, ("WARNING: [%s] service MUST be printable!\n",
951 service->szService));
952 service->printable = true;
954 /* [printers] service must also be non-browsable. */
955 if (service->browseable)
956 service->browseable = false;
959 /* If a service is flagged unavailable, log the fact at level 0. */
960 if (!service->bAvailable)
961 DEBUG(1, ("NOTE: Service %s is flagged unavailable.\n",
962 service->szService));
964 return bRetval;
968 /*******************************************************************
969 Keep a linked list of all config files so we know when one has changed
970 it's date and needs to be reloaded.
971 ********************************************************************/
973 void add_to_file_list(TALLOC_CTX *mem_ctx, struct file_lists **list,
974 const char *fname, const char *subfname)
976 struct file_lists *f = *list;
978 while (f) {
979 if (f->name && !strcmp(f->name, fname))
980 break;
981 f = f->next;
984 if (!f) {
985 f = talloc(mem_ctx, struct file_lists);
986 if (!f)
987 goto fail;
988 f->next = *list;
989 f->name = talloc_strdup(f, fname);
990 if (!f->name) {
991 TALLOC_FREE(f);
992 goto fail;
994 f->subfname = talloc_strdup(f, subfname);
995 if (!f->subfname) {
996 TALLOC_FREE(f);
997 goto fail;
999 *list = f;
1000 f->modtime = file_modtime(subfname);
1001 } else {
1002 time_t t = file_modtime(subfname);
1003 if (t)
1004 f->modtime = t;
1006 return;
1008 fail:
1009 DEBUG(0, ("Unable to add file to file list: %s\n", fname));
1013 /*******************************************************************
1014 Check if a config file has changed date.
1015 ********************************************************************/
1016 bool lpcfg_file_list_changed(struct loadparm_context *lp_ctx)
1018 struct file_lists *f;
1019 DEBUG(6, ("lpcfg_file_list_changed()\n"));
1021 for (f = lp_ctx->file_lists; f != NULL; f = f->next) {
1022 char *n2;
1023 time_t mod_time;
1025 n2 = standard_sub_basic(lp_ctx, f->name);
1027 DEBUGADD(6, ("file %s -> %s last mod_time: %s\n",
1028 f->name, n2, ctime(&f->modtime)));
1030 mod_time = file_modtime(n2);
1032 if (mod_time && ((f->modtime != mod_time) || (f->subfname == NULL) || (strcmp(n2, f->subfname) != 0))) {
1033 DEBUGADD(6, ("file %s modified: %s\n", n2,
1034 ctime(&mod_time)));
1035 f->modtime = mod_time;
1036 talloc_free(f->subfname);
1037 f->subfname = talloc_strdup(f, n2);
1038 return true;
1041 return false;
1045 * set the value for a P_ENUM
1047 bool lp_set_enum_parm( struct parm_struct *parm, const char *pszParmValue,
1048 int *ptr )
1050 int i;
1052 for (i = 0; parm->enum_list[i].name; i++) {
1053 if ( strequal(pszParmValue, parm->enum_list[i].name)) {
1054 *ptr = parm->enum_list[i].value;
1055 return true;
1058 DEBUG(0, ("WARNING: Ignoring invalid value '%s' for parameter '%s'\n",
1059 pszParmValue, parm->label));
1060 return false;
1064 /***************************************************************************
1065 Handle the "realm" parameter
1066 ***************************************************************************/
1068 bool handle_realm(struct loadparm_context *lp_ctx, int unused,
1069 const char *pszParmValue, char **ptr)
1071 char *upper;
1072 char *lower;
1074 upper = strupper_talloc(lp_ctx, pszParmValue);
1075 if (upper == NULL) {
1076 return false;
1079 lower = strlower_talloc(lp_ctx, pszParmValue);
1080 if (lower == NULL) {
1081 TALLOC_FREE(upper);
1082 return false;
1085 if (lp_ctx->s3_fns != NULL) {
1086 lp_ctx->s3_fns->lp_string_set(ptr, pszParmValue);
1087 lp_ctx->s3_fns->lp_string_set(&lp_ctx->globals->realm, upper);
1088 lp_ctx->s3_fns->lp_string_set(&lp_ctx->globals->dnsdomain, lower);
1089 } else {
1090 lpcfg_string_set(lp_ctx, ptr, pszParmValue);
1091 lpcfg_string_set(lp_ctx, &lp_ctx->globals->realm, upper);
1092 lpcfg_string_set(lp_ctx, &lp_ctx->globals->dnsdomain, lower);
1095 return true;
1098 /***************************************************************************
1099 Handle the include operation.
1100 ***************************************************************************/
1102 bool handle_include(struct loadparm_context *lp_ctx, int unused,
1103 const char *pszParmValue, char **ptr)
1105 char *fname;
1107 if (lp_ctx->s3_fns) {
1108 return lp_ctx->s3_fns->lp_include(lp_ctx, unused, pszParmValue, ptr);
1111 fname = standard_sub_basic(lp_ctx, pszParmValue);
1113 add_to_file_list(lp_ctx, &lp_ctx->file_lists, pszParmValue, fname);
1115 lpcfg_string_set(lp_ctx, ptr, fname);
1117 if (file_exist(fname))
1118 return pm_process(fname, do_section, do_parameter, lp_ctx);
1120 DEBUG(2, ("Can't find include file %s\n", fname));
1122 return false;
1125 /***************************************************************************
1126 Handle the interpretation of the copy parameter.
1127 ***************************************************************************/
1129 bool handle_copy(struct loadparm_context *lp_ctx, int snum,
1130 const char *pszParmValue, char **ptr)
1132 bool bRetval;
1133 struct loadparm_service *serviceTemp = NULL;
1134 struct loadparm_service *current = NULL;
1136 bRetval = false;
1138 DEBUG(3, ("Copying service from service %s\n", pszParmValue));
1140 serviceTemp = lpcfg_getservicebyname(lp_ctx, pszParmValue);
1141 if (lp_ctx->s3_fns != NULL) {
1142 current = lp_ctx->s3_fns->get_servicebynum(snum);
1143 } else {
1144 current = lp_ctx->currentService;
1147 if (current == NULL) {
1148 DEBUG(0, ("Unable to copy service - invalid service destination"));
1149 return false;
1152 if (serviceTemp != NULL) {
1153 if (serviceTemp == current) {
1154 DEBUG(0, ("Can't copy service %s - unable to copy self!\n", pszParmValue));
1155 } else {
1156 copy_service(current,
1157 serviceTemp,
1158 current->copymap);
1159 lpcfg_string_set(current, ptr, pszParmValue);
1161 bRetval = true;
1163 } else {
1164 DEBUG(0, ("Unable to copy service - source not found: %s\n",
1165 pszParmValue));
1166 bRetval = false;
1169 return bRetval;
1172 bool handle_debug_list(struct loadparm_context *lp_ctx, int unused,
1173 const char *pszParmValue, char **ptr)
1175 if (lp_ctx->s3_fns != NULL) {
1176 lp_ctx->s3_fns->lp_string_set(ptr, pszParmValue);
1177 } else {
1178 lpcfg_string_set(lp_ctx, ptr, pszParmValue);
1181 return debug_parse_levels(pszParmValue);
1184 bool handle_logfile(struct loadparm_context *lp_ctx, int unused,
1185 const char *pszParmValue, char **ptr)
1187 if (lp_ctx->s3_fns != NULL) {
1188 lp_ctx->s3_fns->lp_string_set(ptr, pszParmValue);
1189 } else {
1190 debug_set_logfile(pszParmValue);
1191 lpcfg_string_set(lp_ctx, ptr, pszParmValue);
1194 return true;
1198 * These special charset handling methods only run in the source3 code.
1201 bool handle_charset(struct loadparm_context *lp_ctx, int snum,
1202 const char *pszParmValue, char **ptr)
1204 if (lp_ctx->s3_fns) {
1205 if (*ptr == NULL || strcmp(*ptr, pszParmValue) != 0) {
1206 lp_ctx->s3_fns->lp_string_set(ptr, pszParmValue);
1207 global_iconv_handle = smb_iconv_handle_reinit(NULL,
1208 lpcfg_dos_charset(lp_ctx),
1209 lpcfg_unix_charset(lp_ctx),
1210 true, global_iconv_handle);
1213 return true;
1215 return lpcfg_string_set(lp_ctx, ptr, pszParmValue);
1219 bool handle_dos_charset(struct loadparm_context *lp_ctx, int snum,
1220 const char *pszParmValue, char **ptr)
1222 bool is_utf8 = false;
1223 size_t len = strlen(pszParmValue);
1225 if (lp_ctx->s3_fns) {
1226 if (len == 4 || len == 5) {
1227 /* Don't use StrCaseCmp here as we don't want to
1228 initialize iconv. */
1229 if ((toupper_m(pszParmValue[0]) == 'U') &&
1230 (toupper_m(pszParmValue[1]) == 'T') &&
1231 (toupper_m(pszParmValue[2]) == 'F')) {
1232 if (len == 4) {
1233 if (pszParmValue[3] == '8') {
1234 is_utf8 = true;
1236 } else {
1237 if (pszParmValue[3] == '-' &&
1238 pszParmValue[4] == '8') {
1239 is_utf8 = true;
1245 if (*ptr == NULL || strcmp(*ptr, pszParmValue) != 0) {
1246 if (is_utf8) {
1247 DEBUG(0,("ERROR: invalid DOS charset: 'dos charset' must not "
1248 "be UTF8, using (default value) %s instead.\n",
1249 DEFAULT_DOS_CHARSET));
1250 pszParmValue = DEFAULT_DOS_CHARSET;
1252 lp_ctx->s3_fns->lp_string_set(ptr, pszParmValue);
1253 global_iconv_handle = smb_iconv_handle_reinit(NULL,
1254 lpcfg_dos_charset(lp_ctx),
1255 lpcfg_unix_charset(lp_ctx),
1256 true, global_iconv_handle);
1258 return true;
1261 return lpcfg_string_set(lp_ctx, ptr, pszParmValue);
1264 bool handle_printing(struct loadparm_context *lp_ctx, int snum,
1265 const char *pszParmValue, char **ptr)
1267 static int parm_num = -1;
1268 struct loadparm_service *s;
1270 if (parm_num == -1) {
1271 parm_num = lpcfg_map_parameter("printing");
1274 if (!lp_set_enum_parm(&parm_table[parm_num], pszParmValue, (int*)ptr)) {
1275 return false;
1278 if (lp_ctx->s3_fns) {
1279 if ( snum < 0 ) {
1280 s = lp_ctx->sDefault;
1281 lp_ctx->s3_fns->init_printer_values(lp_ctx->globals->ctx, s);
1282 } else {
1283 s = lp_ctx->services[snum];
1284 lp_ctx->s3_fns->init_printer_values(s, s);
1288 return true;
1292 /***************************************************************************
1293 Initialise a copymap.
1294 ***************************************************************************/
1296 void init_copymap(struct loadparm_service *pservice)
1298 int i;
1300 TALLOC_FREE(pservice->copymap);
1302 pservice->copymap = bitmap_talloc(NULL, NUMPARAMETERS);
1303 if (!pservice->copymap)
1304 DEBUG(0,
1305 ("Couldn't allocate copymap!! (size %d)\n",
1306 (int)NUMPARAMETERS));
1307 else
1308 for (i = 0; i < NUMPARAMETERS; i++)
1309 bitmap_set(pservice->copymap, i);
1313 * Process a parametric option
1315 static bool lp_do_parameter_parametric(struct loadparm_context *lp_ctx,
1316 struct loadparm_service *service,
1317 const char *pszParmName,
1318 const char *pszParmValue, int flags)
1320 struct parmlist_entry *paramo, *data;
1321 char *name;
1322 TALLOC_CTX *mem_ctx;
1324 while (isspace((unsigned char)*pszParmName)) {
1325 pszParmName++;
1328 name = strlower_talloc(lp_ctx, pszParmName);
1329 if (!name) return false;
1331 if (service == NULL) {
1332 data = lp_ctx->globals->param_opt;
1333 mem_ctx = lp_ctx->globals;
1334 } else {
1335 data = service->param_opt;
1336 mem_ctx = service;
1339 /* Traverse destination */
1340 for (paramo=data; paramo; paramo=paramo->next) {
1341 /* If we already have the option set, override it unless
1342 it was a command line option and the new one isn't */
1343 if (strcmp(paramo->key, name) == 0) {
1344 if ((paramo->priority & FLAG_CMDLINE) &&
1345 !(flags & FLAG_CMDLINE)) {
1346 talloc_free(name);
1347 return true;
1350 talloc_free(paramo->value);
1351 paramo->value = talloc_strdup(paramo, pszParmValue);
1352 paramo->priority = flags;
1353 talloc_free(name);
1354 return true;
1358 paramo = talloc_zero(mem_ctx, struct parmlist_entry);
1359 if (!paramo)
1360 smb_panic("OOM");
1361 paramo->key = talloc_strdup(paramo, name);
1362 paramo->value = talloc_strdup(paramo, pszParmValue);
1363 paramo->priority = flags;
1364 if (service == NULL) {
1365 DLIST_ADD(lp_ctx->globals->param_opt, paramo);
1366 } else {
1367 DLIST_ADD(service->param_opt, paramo);
1370 talloc_free(name);
1372 return true;
1375 static bool set_variable(TALLOC_CTX *mem_ctx, int parmnum, void *parm_ptr,
1376 const char *pszParmName, const char *pszParmValue,
1377 struct loadparm_context *lp_ctx, bool on_globals)
1379 int i;
1380 /* if it is a special case then go ahead */
1381 if (parm_table[parmnum].special) {
1382 bool ret;
1383 ret = parm_table[parmnum].special(lp_ctx, -1, pszParmValue,
1384 (char **)parm_ptr);
1385 if (!ret) {
1386 return false;
1388 goto mark_non_default;
1391 /* now switch on the type of variable it is */
1392 switch (parm_table[parmnum].type)
1394 case P_BOOL: {
1395 bool b;
1396 if (!set_boolean(pszParmValue, &b)) {
1397 DEBUG(0, ("set_variable(%s): value is not "
1398 "boolean!\n", pszParmValue));
1399 return false;
1401 *(bool *)parm_ptr = b;
1403 break;
1405 case P_BOOLREV: {
1406 bool b;
1407 if (!set_boolean(pszParmValue, &b)) {
1408 DEBUG(0, ("set_variable(%s): value is not "
1409 "boolean!\n", pszParmValue));
1410 return false;
1412 *(bool *)parm_ptr = !b;
1414 break;
1416 case P_INTEGER:
1417 *(int *)parm_ptr = atoi(pszParmValue);
1418 break;
1420 case P_CHAR:
1421 *(char *)parm_ptr = *pszParmValue;
1422 break;
1424 case P_OCTAL:
1425 *(int *)parm_ptr = strtol(pszParmValue, NULL, 8);
1426 break;
1428 case P_BYTES:
1430 uint64_t val;
1431 if (conv_str_size_error(pszParmValue, &val)) {
1432 if (val <= INT_MAX) {
1433 *(int *)parm_ptr = (int)val;
1434 break;
1438 DEBUG(0, ("set_variable(%s): value is not "
1439 "a valid size specifier!\n", pszParmValue));
1440 return false;
1443 case P_CMDLIST:
1444 *(const char * const **)parm_ptr
1445 = (const char * const *)str_list_make(mem_ctx,
1446 pszParmValue, NULL);
1447 break;
1448 case P_LIST:
1450 char **new_list = str_list_make(mem_ctx,
1451 pszParmValue, NULL);
1452 for (i=0; new_list[i]; i++) {
1453 if (*(const char ***)parm_ptr != NULL &&
1454 new_list[i][0] == '+' &&
1455 new_list[i][1])
1457 if (!str_list_check(*(const char ***)parm_ptr,
1458 &new_list[i][1])) {
1459 *(const char ***)parm_ptr = str_list_add(*(const char ***)parm_ptr,
1460 &new_list[i][1]);
1462 } else if (*(const char ***)parm_ptr != NULL &&
1463 new_list[i][0] == '-' &&
1464 new_list[i][1])
1466 str_list_remove(*(const char ***)parm_ptr,
1467 &new_list[i][1]);
1468 } else {
1469 if (i != 0) {
1470 DEBUG(0, ("Unsupported list syntax for: %s = %s\n",
1471 pszParmName, pszParmValue));
1472 return false;
1474 *(const char * const **)parm_ptr = (const char * const *) new_list;
1475 break;
1478 break;
1480 case P_STRING:
1481 lpcfg_string_set(mem_ctx, (char **)parm_ptr, pszParmValue);
1482 break;
1484 case P_USTRING:
1485 lpcfg_string_set_upper(mem_ctx, (char **)parm_ptr, pszParmValue);
1486 break;
1488 case P_ENUM:
1489 if (!lp_set_enum_parm(&parm_table[parmnum], pszParmValue, (int*)parm_ptr)) {
1490 return false;
1492 break;
1494 case P_SEP:
1495 break;
1498 mark_non_default:
1499 if (on_globals && (lp_ctx->flags[parmnum] & FLAG_DEFAULT)) {
1500 lp_ctx->flags[parmnum] &= ~FLAG_DEFAULT;
1501 /* we have to also unset FLAG_DEFAULT on aliases */
1502 for (i=parmnum-1;i>=0 && parm_table[i].offset == parm_table[parmnum].offset;i--) {
1503 lp_ctx->flags[i] &= ~FLAG_DEFAULT;
1505 for (i=parmnum+1;i<NUMPARAMETERS && parm_table[i].offset == parm_table[parmnum].offset;i++) {
1506 lp_ctx->flags[i] &= ~FLAG_DEFAULT;
1509 return true;
1513 bool lpcfg_do_global_parameter(struct loadparm_context *lp_ctx,
1514 const char *pszParmName, const char *pszParmValue)
1516 int parmnum = lpcfg_map_parameter(pszParmName);
1517 void *parm_ptr;
1519 if (parmnum < 0) {
1520 if (strchr(pszParmName, ':')) {
1521 return lp_do_parameter_parametric(lp_ctx, NULL, pszParmName, pszParmValue, 0);
1523 DEBUG(0, ("Ignoring unknown parameter \"%s\"\n", pszParmName));
1524 return true;
1527 /* if the flag has been set on the command line, then don't allow override,
1528 but don't report an error */
1529 if (lp_ctx->flags[parmnum] & FLAG_CMDLINE) {
1530 return true;
1533 parm_ptr = lpcfg_parm_ptr(lp_ctx, NULL, &parm_table[parmnum]);
1535 return set_variable(lp_ctx->globals, parmnum, parm_ptr,
1536 pszParmName, pszParmValue, lp_ctx, true);
1539 bool lpcfg_do_service_parameter(struct loadparm_context *lp_ctx,
1540 struct loadparm_service *service,
1541 const char *pszParmName, const char *pszParmValue)
1543 void *parm_ptr;
1544 int i;
1545 int parmnum = lpcfg_map_parameter(pszParmName);
1547 if (parmnum < 0) {
1548 if (strchr(pszParmName, ':')) {
1549 return lp_do_parameter_parametric(lp_ctx, service, pszParmName, pszParmValue, 0);
1551 DEBUG(0, ("Ignoring unknown parameter \"%s\"\n", pszParmName));
1552 return true;
1555 /* if the flag has been set on the command line, then don't allow override,
1556 but don't report an error */
1557 if (lp_ctx->flags[parmnum] & FLAG_CMDLINE) {
1558 return true;
1561 if (parm_table[parmnum].p_class == P_GLOBAL) {
1562 DEBUG(0,
1563 ("Global parameter %s found in service section!\n",
1564 pszParmName));
1565 return true;
1567 parm_ptr = ((char *)service) + parm_table[parmnum].offset;
1569 if (!service->copymap)
1570 init_copymap(service);
1572 /* this handles the aliases - set the copymap for other
1573 * entries with the same data pointer */
1574 for (i = 0; parm_table[i].label; i++)
1575 if (parm_table[i].offset == parm_table[parmnum].offset &&
1576 parm_table[i].p_class == parm_table[parmnum].p_class)
1577 bitmap_clear(service->copymap, i);
1579 return set_variable(service, parmnum, parm_ptr, pszParmName,
1580 pszParmValue, lp_ctx, false);
1584 * Process a parameter.
1587 static bool do_parameter(const char *pszParmName, const char *pszParmValue,
1588 void *userdata)
1590 struct loadparm_context *lp_ctx = (struct loadparm_context *)userdata;
1592 if (lp_ctx->bInGlobalSection)
1593 return lpcfg_do_global_parameter(lp_ctx, pszParmName,
1594 pszParmValue);
1595 else
1596 return lpcfg_do_service_parameter(lp_ctx, lp_ctx->currentService,
1597 pszParmName, pszParmValue);
1601 variable argument do parameter
1603 bool lpcfg_do_global_parameter_var(struct loadparm_context *lp_ctx, const char *pszParmName, const char *fmt, ...) PRINTF_ATTRIBUTE(3, 4);
1604 bool lpcfg_do_global_parameter_var(struct loadparm_context *lp_ctx,
1605 const char *pszParmName, const char *fmt, ...)
1607 char *s;
1608 bool ret;
1609 va_list ap;
1611 va_start(ap, fmt);
1612 s = talloc_vasprintf(NULL, fmt, ap);
1613 va_end(ap);
1614 ret = lpcfg_do_global_parameter(lp_ctx, pszParmName, s);
1615 talloc_free(s);
1616 return ret;
1621 set a parameter from the commandline - this is called from command line parameter
1622 parsing code. It sets the parameter then marks the parameter as unable to be modified
1623 by smb.conf processing
1625 bool lpcfg_set_cmdline(struct loadparm_context *lp_ctx, const char *pszParmName,
1626 const char *pszParmValue)
1628 int parmnum;
1629 int i;
1631 while (isspace((unsigned char)*pszParmValue)) pszParmValue++;
1633 if (lp_ctx->s3_fns) {
1634 return lp_ctx->s3_fns->set_cmdline(pszParmName, pszParmValue);
1637 parmnum = lpcfg_map_parameter(pszParmName);
1639 if (parmnum < 0 && strchr(pszParmName, ':')) {
1640 /* set a parametric option */
1641 return lp_do_parameter_parametric(lp_ctx, NULL, pszParmName,
1642 pszParmValue, FLAG_CMDLINE);
1645 if (parmnum < 0) {
1646 DEBUG(0,("Unknown option '%s'\n", pszParmName));
1647 return false;
1650 /* reset the CMDLINE flag in case this has been called before */
1651 lp_ctx->flags[parmnum] &= ~FLAG_CMDLINE;
1653 if (!lpcfg_do_global_parameter(lp_ctx, pszParmName, pszParmValue)) {
1654 return false;
1657 lp_ctx->flags[parmnum] |= FLAG_CMDLINE;
1659 /* we have to also set FLAG_CMDLINE on aliases */
1660 for (i=parmnum-1;
1661 i>=0 && parm_table[i].p_class == parm_table[parmnum].p_class &&
1662 parm_table[i].offset == parm_table[parmnum].offset;
1663 i--) {
1664 lp_ctx->flags[i] |= FLAG_CMDLINE;
1666 for (i=parmnum+1;
1667 i<NUMPARAMETERS &&
1668 parm_table[i].p_class == parm_table[parmnum].p_class &&
1669 parm_table[i].offset == parm_table[parmnum].offset;
1670 i++) {
1671 lp_ctx->flags[i] |= FLAG_CMDLINE;
1674 return true;
1678 set a option from the commandline in 'a=b' format. Use to support --option
1680 bool lpcfg_set_option(struct loadparm_context *lp_ctx, const char *option)
1682 char *p, *s;
1683 bool ret;
1685 s = talloc_strdup(NULL, option);
1686 if (!s) {
1687 return false;
1690 p = strchr(s, '=');
1691 if (!p) {
1692 talloc_free(s);
1693 return false;
1696 *p = 0;
1698 ret = lpcfg_set_cmdline(lp_ctx, s, p+1);
1699 talloc_free(s);
1700 return ret;
1704 #define BOOLSTR(b) ((b) ? "Yes" : "No")
1707 * Print a parameter of the specified type.
1710 void lpcfg_print_parameter(struct parm_struct *p, void *ptr, FILE * f)
1712 /* For the seperation of lists values that we print below */
1713 const char *list_sep = ", ";
1714 int i;
1715 switch (p->type)
1717 case P_ENUM:
1718 for (i = 0; p->enum_list[i].name; i++) {
1719 if (*(int *)ptr == p->enum_list[i].value) {
1720 fprintf(f, "%s",
1721 p->enum_list[i].name);
1722 break;
1725 break;
1727 case P_BOOL:
1728 fprintf(f, "%s", BOOLSTR(*(bool *)ptr));
1729 break;
1731 case P_BOOLREV:
1732 fprintf(f, "%s", BOOLSTR(!*(bool *)ptr));
1733 break;
1735 case P_INTEGER:
1736 case P_BYTES:
1737 fprintf(f, "%d", *(int *)ptr);
1738 break;
1740 case P_CHAR:
1741 fprintf(f, "%c", *(char *)ptr);
1742 break;
1744 case P_OCTAL: {
1745 int val = *(int *)ptr;
1746 if (val == -1) {
1747 fprintf(f, "-1");
1748 } else {
1749 fprintf(f, "0%03o", val);
1751 break;
1754 case P_CMDLIST:
1755 list_sep = " ";
1756 /* fall through */
1757 case P_LIST:
1758 if ((char ***)ptr && *(char ***)ptr) {
1759 char **list = *(char ***)ptr;
1760 for (; *list; list++) {
1761 /* surround strings with whitespace in double quotes */
1762 if (*(list+1) == NULL) {
1763 /* last item, no extra separator */
1764 list_sep = "";
1766 if ( strchr_m( *list, ' ' ) ) {
1767 fprintf(f, "\"%s\"%s", *list, list_sep);
1768 } else {
1769 fprintf(f, "%s%s", *list, list_sep);
1773 break;
1775 case P_STRING:
1776 case P_USTRING:
1777 if (*(char **)ptr) {
1778 fprintf(f, "%s", *(char **)ptr);
1780 break;
1781 case P_SEP:
1782 break;
1787 * Check if two parameters are equal.
1790 bool lpcfg_equal_parameter(parm_type type, void *ptr1, void *ptr2)
1792 switch (type) {
1793 case P_BOOL:
1794 case P_BOOLREV:
1795 return (*((bool *)ptr1) == *((bool *)ptr2));
1797 case P_INTEGER:
1798 case P_ENUM:
1799 case P_OCTAL:
1800 case P_BYTES:
1801 return (*((int *)ptr1) == *((int *)ptr2));
1803 case P_CHAR:
1804 return (*((char *)ptr1) == *((char *)ptr2));
1806 case P_LIST:
1807 case P_CMDLIST:
1808 return str_list_equal(*(const char ***)ptr1, *(const char ***)ptr2);
1810 case P_STRING:
1811 case P_USTRING:
1813 char *p1 = *(char **)ptr1, *p2 = *(char **)ptr2;
1814 if (p1 && !*p1)
1815 p1 = NULL;
1816 if (p2 && !*p2)
1817 p2 = NULL;
1818 return (p1 == p2 || strequal(p1, p2));
1820 case P_SEP:
1821 break;
1823 return false;
1827 * Process a new section (service).
1829 * At this stage all sections are services.
1830 * Later we'll have special sections that permit server parameters to be set.
1831 * Returns True on success, False on failure.
1834 static bool do_section(const char *pszSectionName, void *userdata)
1836 struct loadparm_context *lp_ctx = (struct loadparm_context *)userdata;
1837 bool bRetval;
1838 bool isglobal = ((strwicmp(pszSectionName, GLOBAL_NAME) == 0) ||
1839 (strwicmp(pszSectionName, GLOBAL_NAME2) == 0));
1840 bRetval = false;
1842 /* if we've just struck a global section, note the fact. */
1843 lp_ctx->bInGlobalSection = isglobal;
1845 /* check for multiple global sections */
1846 if (lp_ctx->bInGlobalSection) {
1847 DEBUG(4, ("Processing section \"[%s]\"\n", pszSectionName));
1848 return true;
1851 /* if we have a current service, tidy it up before moving on */
1852 bRetval = true;
1854 if (lp_ctx->currentService != NULL)
1855 bRetval = lpcfg_service_ok(lp_ctx->currentService);
1857 /* if all is still well, move to the next record in the services array */
1858 if (bRetval) {
1859 /* We put this here to avoid an odd message order if messages are */
1860 /* issued by the post-processing of a previous section. */
1861 DEBUG(4, ("Processing section \"[%s]\"\n", pszSectionName));
1863 if ((lp_ctx->currentService = lpcfg_add_service(lp_ctx, lp_ctx->sDefault,
1864 pszSectionName))
1865 == NULL) {
1866 DEBUG(0, ("Failed to add a new service\n"));
1867 return false;
1871 return bRetval;
1876 * Determine if a particular base parameter is currently set to the default value.
1879 static bool is_default(struct loadparm_service *sDefault, int i)
1881 void *def_ptr = ((char *)sDefault) + parm_table[i].offset;
1882 switch (parm_table[i].type) {
1883 case P_CMDLIST:
1884 case P_LIST:
1885 return str_list_equal((const char * const *)parm_table[i].def.lvalue,
1886 (const char **)def_ptr);
1887 case P_STRING:
1888 case P_USTRING:
1889 return strequal(parm_table[i].def.svalue,
1890 *(char **)def_ptr);
1891 case P_BOOL:
1892 case P_BOOLREV:
1893 return parm_table[i].def.bvalue ==
1894 *(bool *)def_ptr;
1895 case P_INTEGER:
1896 case P_CHAR:
1897 case P_OCTAL:
1898 case P_BYTES:
1899 case P_ENUM:
1900 return parm_table[i].def.ivalue ==
1901 *(int *)def_ptr;
1902 case P_SEP:
1903 break;
1905 return false;
1909 *Display the contents of the global structure.
1912 static void dump_globals(struct loadparm_context *lp_ctx, FILE *f,
1913 bool show_defaults)
1915 int i;
1916 struct parmlist_entry *data;
1918 fprintf(f, "# Global parameters\n[global]\n");
1920 for (i = 0; parm_table[i].label; i++)
1921 if (parm_table[i].p_class == P_GLOBAL &&
1922 (i == 0 || (parm_table[i].offset != parm_table[i - 1].offset))) {
1923 if (!show_defaults && (lp_ctx->flags[i] & FLAG_DEFAULT))
1924 continue;
1925 fprintf(f, "\t%s = ", parm_table[i].label);
1926 lpcfg_print_parameter(&parm_table[i], lpcfg_parm_ptr(lp_ctx, NULL, &parm_table[i]), f);
1927 fprintf(f, "\n");
1929 if (lp_ctx->globals->param_opt != NULL) {
1930 for (data = lp_ctx->globals->param_opt; data;
1931 data = data->next) {
1932 if (!show_defaults && (data->priority & FLAG_DEFAULT)) {
1933 continue;
1935 fprintf(f, "\t%s = %s\n", data->key, data->value);
1942 * Display the contents of a single services record.
1945 static void dump_a_service(struct loadparm_service * pService, struct loadparm_service *sDefault, FILE * f,
1946 unsigned int *flags)
1948 int i;
1949 struct parmlist_entry *data;
1951 if (pService != sDefault)
1952 fprintf(f, "\n[%s]\n", pService->szService);
1954 for (i = 0; parm_table[i].label; i++) {
1955 if (parm_table[i].p_class == P_LOCAL &&
1956 (*parm_table[i].label != '-') &&
1957 (i == 0 || (parm_table[i].offset != parm_table[i - 1].offset)))
1959 if (pService == sDefault) {
1960 if (flags && (flags[i] & FLAG_DEFAULT)) {
1961 continue;
1963 if (defaults_saved) {
1964 if (is_default(sDefault, i)) {
1965 continue;
1968 } else {
1969 if (lpcfg_equal_parameter(parm_table[i].type,
1970 ((char *)pService) +
1971 parm_table[i].offset,
1972 ((char *)sDefault) +
1973 parm_table[i].offset))
1974 continue;
1977 fprintf(f, "\t%s = ", parm_table[i].label);
1978 lpcfg_print_parameter(&parm_table[i],
1979 ((char *)pService) + parm_table[i].offset, f);
1980 fprintf(f, "\n");
1983 if (pService->param_opt != NULL) {
1984 for (data = pService->param_opt; data; data = data->next) {
1985 fprintf(f, "\t%s = %s\n", data->key, data->value);
1990 bool lpcfg_dump_a_parameter(struct loadparm_context *lp_ctx,
1991 struct loadparm_service *service,
1992 const char *parm_name, FILE * f)
1994 struct parm_struct *parm;
1995 void *ptr;
1997 parm = lpcfg_parm_struct(lp_ctx, parm_name);
1998 if (!parm) {
1999 return false;
2002 if (service != NULL && parm->p_class == P_GLOBAL) {
2003 return false;
2006 ptr = lpcfg_parm_ptr(lp_ctx, service,parm);
2008 lpcfg_print_parameter(parm, ptr, f);
2009 fprintf(f, "\n");
2010 return true;
2014 * Auto-load some home services.
2016 static void lpcfg_add_auto_services(struct loadparm_context *lp_ctx,
2017 const char *str)
2019 return;
2024 * Unload unused services.
2027 void lpcfg_killunused(struct loadparm_context *lp_ctx,
2028 struct smbsrv_connection *smb,
2029 bool (*snumused) (struct smbsrv_connection *, int))
2031 int i;
2032 for (i = 0; i < lp_ctx->iNumServices; i++) {
2033 if (lp_ctx->services[i] == NULL)
2034 continue;
2036 if (!snumused || !snumused(smb, i)) {
2037 talloc_free(lp_ctx->services[i]);
2038 lp_ctx->services[i] = NULL;
2044 static int lpcfg_destructor(struct loadparm_context *lp_ctx)
2046 struct parmlist_entry *data;
2048 if (lp_ctx->refuse_free) {
2049 /* someone is trying to free the
2050 global_loadparm_context.
2051 We can't allow that. */
2052 return -1;
2055 if (lp_ctx->globals->param_opt != NULL) {
2056 struct parmlist_entry *next;
2057 for (data = lp_ctx->globals->param_opt; data; data=next) {
2058 next = data->next;
2059 if (data->priority & FLAG_CMDLINE) continue;
2060 DLIST_REMOVE(lp_ctx->globals->param_opt, data);
2061 talloc_free(data);
2065 return 0;
2069 * Initialise the global parameter structure.
2071 * Note that most callers should use loadparm_init_global() instead
2073 struct loadparm_context *loadparm_init(TALLOC_CTX *mem_ctx)
2075 int i;
2076 char *myname;
2077 struct loadparm_context *lp_ctx;
2078 struct parmlist_entry *parm;
2079 char *logfile;
2081 lp_ctx = talloc_zero(mem_ctx, struct loadparm_context);
2082 if (lp_ctx == NULL)
2083 return NULL;
2085 talloc_set_destructor(lp_ctx, lpcfg_destructor);
2086 lp_ctx->bInGlobalSection = true;
2087 lp_ctx->globals = talloc_zero(lp_ctx, struct loadparm_global);
2088 lp_ctx->sDefault = talloc_zero(lp_ctx, struct loadparm_service);
2089 lp_ctx->flags = talloc_zero_array(lp_ctx, unsigned int, NUMPARAMETERS);
2091 lp_ctx->sDefault->iMaxPrintJobs = 1000;
2092 lp_ctx->sDefault->bAvailable = true;
2093 lp_ctx->sDefault->browseable = true;
2094 lp_ctx->sDefault->read_only = true;
2095 lp_ctx->sDefault->map_archive = true;
2096 lp_ctx->sDefault->strict_locking = true;
2097 lp_ctx->sDefault->oplocks = true;
2098 lp_ctx->sDefault->create_mask = 0744;
2099 lp_ctx->sDefault->force_create_mode = 0000;
2100 lp_ctx->sDefault->directory_mask = 0755;
2101 lp_ctx->sDefault->force_directory_mode = 0000;
2103 DEBUG(3, ("Initialising global parameters\n"));
2105 for (i = 0; parm_table[i].label; i++) {
2106 if ((parm_table[i].type == P_STRING ||
2107 parm_table[i].type == P_USTRING) &&
2108 !(lp_ctx->flags[i] & FLAG_CMDLINE)) {
2109 char **r;
2110 if (parm_table[i].p_class == P_LOCAL) {
2111 r = (char **)(((char *)lp_ctx->sDefault) + parm_table[i].offset);
2112 } else {
2113 r = (char **)(((char *)lp_ctx->globals) + parm_table[i].offset);
2115 *r = talloc_strdup(lp_ctx, "");
2119 logfile = talloc_asprintf(lp_ctx, "%s/log.samba", dyn_LOGFILEBASE);
2120 lpcfg_do_global_parameter(lp_ctx, "log file", logfile);
2121 talloc_free(logfile);
2123 lpcfg_do_global_parameter(lp_ctx, "log level", "0");
2125 lpcfg_do_global_parameter(lp_ctx, "syslog", "1");
2126 lpcfg_do_global_parameter(lp_ctx, "syslog only", "No");
2127 lpcfg_do_global_parameter(lp_ctx, "debug timestamp", "Yes");
2128 lpcfg_do_global_parameter(lp_ctx, "debug prefix timestamp", "No");
2129 lpcfg_do_global_parameter(lp_ctx, "debug hires timestamp", "Yes");
2130 lpcfg_do_global_parameter(lp_ctx, "debug pid", "No");
2131 lpcfg_do_global_parameter(lp_ctx, "debug uid", "No");
2132 lpcfg_do_global_parameter(lp_ctx, "debug class", "No");
2134 lpcfg_do_global_parameter(lp_ctx, "share backend", "classic");
2136 lpcfg_do_global_parameter(lp_ctx, "server role", "auto");
2137 lpcfg_do_global_parameter(lp_ctx, "domain logons", "No");
2138 lpcfg_do_global_parameter(lp_ctx, "domain master", "Auto");
2140 /* options that can be set on the command line must be initialised via
2141 the slower lpcfg_do_global_parameter() to ensure that FLAG_CMDLINE is obeyed */
2142 #ifdef TCP_NODELAY
2143 lpcfg_do_global_parameter(lp_ctx, "socket options", "TCP_NODELAY");
2144 #endif
2145 lpcfg_do_global_parameter(lp_ctx, "workgroup", DEFAULT_WORKGROUP);
2146 myname = get_myname(lp_ctx);
2147 lpcfg_do_global_parameter(lp_ctx, "netbios name", myname);
2148 talloc_free(myname);
2149 lpcfg_do_global_parameter(lp_ctx, "name resolve order", "lmhosts wins host bcast");
2151 lpcfg_do_global_parameter(lp_ctx, "fstype", "NTFS");
2153 lpcfg_do_global_parameter(lp_ctx, "ntvfs handler", "unixuid default");
2154 lpcfg_do_global_parameter(lp_ctx, "max connections", "0");
2156 lpcfg_do_global_parameter(lp_ctx, "dcerpc endpoint servers", "epmapper wkssvc rpcecho samr netlogon lsarpc spoolss drsuapi dssetup unixinfo browser eventlog6 backupkey dnsserver");
2157 lpcfg_do_global_parameter(lp_ctx, "server services", "s3fs rpc nbt wrepl ldap cldap kdc drepl winbind ntp_signd kcc dnsupdate dns");
2158 lpcfg_do_global_parameter(lp_ctx, "kccsrv:samba_kcc", "true");
2159 /* the winbind method for domain controllers is for both RODC
2160 auth forwarding and for trusted domains */
2161 lpcfg_do_global_parameter(lp_ctx, "private dir", dyn_PRIVATE_DIR);
2162 lpcfg_do_global_parameter(lp_ctx, "registry:HKEY_LOCAL_MACHINE", "hklm.ldb");
2164 /* This hive should be dynamically generated by Samba using
2165 data from the sam, but for the moment leave it in a tdb to
2166 keep regedt32 from popping up an annoying dialog. */
2167 lpcfg_do_global_parameter(lp_ctx, "registry:HKEY_USERS", "hku.ldb");
2169 /* using UTF8 by default allows us to support all chars */
2170 lpcfg_do_global_parameter(lp_ctx, "unix charset", "UTF-8");
2172 /* Use codepage 850 as a default for the dos character set */
2173 lpcfg_do_global_parameter(lp_ctx, "dos charset", "CP850");
2176 * Allow the default PASSWD_CHAT to be overridden in local.h.
2178 lpcfg_do_global_parameter(lp_ctx, "passwd chat", DEFAULT_PASSWD_CHAT);
2180 lpcfg_do_global_parameter(lp_ctx, "pid directory", dyn_PIDDIR);
2181 lpcfg_do_global_parameter(lp_ctx, "lock dir", dyn_LOCKDIR);
2182 lpcfg_do_global_parameter(lp_ctx, "state directory", dyn_STATEDIR);
2183 lpcfg_do_global_parameter(lp_ctx, "cache directory", dyn_CACHEDIR);
2184 lpcfg_do_global_parameter(lp_ctx, "ncalrpc dir", dyn_NCALRPCDIR);
2186 lpcfg_do_global_parameter(lp_ctx, "nbt client socket address", "0.0.0.0");
2187 lpcfg_do_global_parameter_var(lp_ctx, "server string",
2188 "Samba %s", SAMBA_VERSION_STRING);
2190 lpcfg_do_global_parameter(lp_ctx, "password server", "*");
2192 lpcfg_do_global_parameter(lp_ctx, "max mux", "50");
2193 lpcfg_do_global_parameter(lp_ctx, "max xmit", "16644");
2194 lpcfg_do_global_parameter(lp_ctx, "host msdfs", "true");
2196 lpcfg_do_global_parameter(lp_ctx, "LargeReadwrite", "True");
2197 lpcfg_do_global_parameter(lp_ctx, "server min protocol", "LANMAN1");
2198 lpcfg_do_global_parameter(lp_ctx, "server max protocol", "SMB3");
2199 lpcfg_do_global_parameter(lp_ctx, "client min protocol", "CORE");
2200 lpcfg_do_global_parameter(lp_ctx, "client max protocol", "NT1");
2201 lpcfg_do_global_parameter(lp_ctx, "security", "AUTO");
2202 lpcfg_do_global_parameter(lp_ctx, "EncryptPasswords", "True");
2203 lpcfg_do_global_parameter(lp_ctx, "ReadRaw", "True");
2204 lpcfg_do_global_parameter(lp_ctx, "WriteRaw", "True");
2205 lpcfg_do_global_parameter(lp_ctx, "NullPasswords", "False");
2206 lpcfg_do_global_parameter(lp_ctx, "old password allowed period", "60");
2207 lpcfg_do_global_parameter(lp_ctx, "ObeyPamRestrictions", "False");
2209 lpcfg_do_global_parameter(lp_ctx, "TimeServer", "False");
2210 lpcfg_do_global_parameter(lp_ctx, "BindInterfacesOnly", "False");
2211 lpcfg_do_global_parameter(lp_ctx, "Unicode", "True");
2212 lpcfg_do_global_parameter(lp_ctx, "ClientLanManAuth", "False");
2213 lpcfg_do_global_parameter(lp_ctx, "ClientNTLMv2Auth", "True");
2214 lpcfg_do_global_parameter(lp_ctx, "LanmanAuth", "False");
2215 lpcfg_do_global_parameter(lp_ctx, "NTLMAuth", "True");
2216 lpcfg_do_global_parameter(lp_ctx, "client use spnego principal", "False");
2218 lpcfg_do_global_parameter(lp_ctx, "UnixExtensions", "True");
2220 lpcfg_do_global_parameter(lp_ctx, "PreferredMaster", "Auto");
2221 lpcfg_do_global_parameter(lp_ctx, "LocalMaster", "True");
2223 lpcfg_do_global_parameter(lp_ctx, "wins support", "False");
2224 lpcfg_do_global_parameter(lp_ctx, "dns proxy", "True");
2226 lpcfg_do_global_parameter(lp_ctx, "winbind separator", "\\");
2227 lpcfg_do_global_parameter(lp_ctx, "winbind sealed pipes", "True");
2228 lpcfg_do_global_parameter(lp_ctx, "require strong key", "True");
2229 lpcfg_do_global_parameter(lp_ctx, "winbindd socket directory", dyn_WINBINDD_SOCKET_DIR);
2230 lpcfg_do_global_parameter(lp_ctx, "winbindd privileged socket directory", dyn_WINBINDD_PRIVILEGED_SOCKET_DIR);
2231 lpcfg_do_global_parameter(lp_ctx, "ntp signd socket directory", dyn_NTP_SIGND_SOCKET_DIR);
2232 lpcfg_do_global_parameter_var(lp_ctx, "dns update command", "%s/samba_dnsupdate", dyn_SCRIPTSBINDIR);
2233 lpcfg_do_global_parameter_var(lp_ctx, "spn update command", "%s/samba_spnupdate", dyn_SCRIPTSBINDIR);
2234 lpcfg_do_global_parameter_var(lp_ctx, "samba kcc command",
2235 "%s/samba_kcc", dyn_SCRIPTSBINDIR);
2236 lpcfg_do_global_parameter(lp_ctx, "template shell", "/bin/false");
2237 lpcfg_do_global_parameter(lp_ctx, "template homedir", "/home/%WORKGROUP%/%ACCOUNTNAME%");
2239 lpcfg_do_global_parameter(lp_ctx, "client signing", "default");
2240 lpcfg_do_global_parameter(lp_ctx, "server signing", "default");
2242 lpcfg_do_global_parameter(lp_ctx, "use spnego", "True");
2244 lpcfg_do_global_parameter(lp_ctx, "use mmap", "True");
2246 lpcfg_do_global_parameter(lp_ctx, "smb ports", "445 139");
2247 lpcfg_do_global_parameter(lp_ctx, "nbt port", "137");
2248 lpcfg_do_global_parameter(lp_ctx, "dgram port", "138");
2249 lpcfg_do_global_parameter(lp_ctx, "cldap port", "389");
2250 lpcfg_do_global_parameter(lp_ctx, "krb5 port", "88");
2251 lpcfg_do_global_parameter(lp_ctx, "kpasswd port", "464");
2252 lpcfg_do_global_parameter(lp_ctx, "web port", "901");
2254 lpcfg_do_global_parameter(lp_ctx, "nt status support", "True");
2256 lpcfg_do_global_parameter(lp_ctx, "max wins ttl", "518400"); /* 6 days */
2257 lpcfg_do_global_parameter(lp_ctx, "min wins ttl", "21600");
2259 lpcfg_do_global_parameter(lp_ctx, "tls enabled", "True");
2260 lpcfg_do_global_parameter(lp_ctx, "tls keyfile", "tls/key.pem");
2261 lpcfg_do_global_parameter(lp_ctx, "tls certfile", "tls/cert.pem");
2262 lpcfg_do_global_parameter(lp_ctx, "tls cafile", "tls/ca.pem");
2263 lpcfg_do_global_parameter(lp_ctx, "prefork children:smb", "4");
2265 lpcfg_do_global_parameter(lp_ctx, "rndc command", "/usr/sbin/rndc");
2266 lpcfg_do_global_parameter(lp_ctx, "nsupdate command", "/usr/bin/nsupdate -g");
2268 lpcfg_do_global_parameter(lp_ctx, "allow dns updates", "secure only");
2269 lpcfg_do_global_parameter(lp_ctx, "dns forwarder", "");
2271 lpcfg_do_global_parameter(lp_ctx, "algorithmic rid base", "1000");
2273 lpcfg_do_global_parameter(lp_ctx, "enhanced browsing", "True");
2275 lpcfg_do_global_parameter(lp_ctx, "winbind nss info", "template");
2277 lpcfg_do_global_parameter(lp_ctx, "server schannel", "Auto");
2279 lpcfg_do_global_parameter(lp_ctx, "short preserve case", "True");
2281 lpcfg_do_global_parameter(lp_ctx, "max open files", "16384");
2283 lpcfg_do_global_parameter(lp_ctx, "cups connection timeout", "30");
2285 lpcfg_do_global_parameter(lp_ctx, "locking", "True");
2287 lpcfg_do_global_parameter(lp_ctx, "block size", "1024");
2289 lpcfg_do_global_parameter(lp_ctx, "client use spnego", "True");
2291 lpcfg_do_global_parameter(lp_ctx, "change notify", "True");
2293 lpcfg_do_global_parameter(lp_ctx, "name cache timeout", "660");
2295 lpcfg_do_global_parameter(lp_ctx, "defer sharing violations", "True");
2297 lpcfg_do_global_parameter(lp_ctx, "ldap replication sleep", "1000");
2299 lpcfg_do_global_parameter(lp_ctx, "idmap backend", "tdb");
2301 lpcfg_do_global_parameter(lp_ctx, "enable privileges", "True");
2303 lpcfg_do_global_parameter_var(lp_ctx, "smb2 max write", "%u", DEFAULT_SMB2_MAX_WRITE);
2305 lpcfg_do_global_parameter(lp_ctx, "passdb backend", "tdbsam");
2307 lpcfg_do_global_parameter(lp_ctx, "getwd cache", "True");
2309 lpcfg_do_global_parameter(lp_ctx, "winbind nested groups", "True");
2311 lpcfg_do_global_parameter(lp_ctx, "mangled names", "True");
2313 lpcfg_do_global_parameter_var(lp_ctx, "smb2 max credits", "%u", DEFAULT_SMB2_MAX_CREDITS);
2315 lpcfg_do_global_parameter(lp_ctx, "ldap ssl", "start tls");
2317 lpcfg_do_global_parameter(lp_ctx, "ldap deref", "auto");
2319 lpcfg_do_global_parameter(lp_ctx, "lm interval", "60");
2321 lpcfg_do_global_parameter(lp_ctx, "mangling method", "hash2");
2323 lpcfg_do_global_parameter(lp_ctx, "hide dot files", "True");
2325 lpcfg_do_global_parameter(lp_ctx, "browse list", "True");
2327 lpcfg_do_global_parameter(lp_ctx, "passwd chat timeout", "2");
2329 lpcfg_do_global_parameter(lp_ctx, "guest account", GUEST_ACCOUNT);
2331 lpcfg_do_global_parameter(lp_ctx, "client schannel", "auto");
2333 lpcfg_do_global_parameter(lp_ctx, "smb encrypt", "default");
2335 lpcfg_do_global_parameter(lp_ctx, "max log size", "5000");
2337 lpcfg_do_global_parameter(lp_ctx, "idmap negative cache time", "120");
2339 lpcfg_do_global_parameter(lp_ctx, "ldap follow referral", "auto");
2341 lpcfg_do_global_parameter(lp_ctx, "multicast dns register", "yes");
2343 lpcfg_do_global_parameter(lp_ctx, "winbind reconnect delay", "30");
2345 lpcfg_do_global_parameter(lp_ctx, "nt acl support", "yes");
2347 lpcfg_do_global_parameter(lp_ctx, "acl check permissions", "yes");
2349 lpcfg_do_global_parameter(lp_ctx, "keepalive", "300");
2351 lpcfg_do_global_parameter(lp_ctx, "winbind cache time", "300");
2353 lpcfg_do_global_parameter(lp_ctx, "level2 oplocks", "yes");
2355 lpcfg_do_global_parameter(lp_ctx, "show add printer wizard", "yes");
2357 lpcfg_do_global_parameter(lp_ctx, "allocation roundup size", "1048576");
2359 lpcfg_do_global_parameter(lp_ctx, "ldap page size", "1024");
2361 lpcfg_do_global_parameter(lp_ctx, "kernel share modes", "yes");
2363 lpcfg_do_global_parameter(lp_ctx, "strict locking", "Auto");
2365 lpcfg_do_global_parameter(lp_ctx, "map readonly", "yes");
2367 lpcfg_do_global_parameter(lp_ctx, "allow trusted domains", "yes");
2369 lpcfg_do_global_parameter(lp_ctx, "default devmode", "yes");
2371 lpcfg_do_global_parameter(lp_ctx, "os level", "20");
2373 lpcfg_do_global_parameter(lp_ctx, "dos filetimes", "yes");
2375 lpcfg_do_global_parameter(lp_ctx, "mangling char", "~");
2377 lpcfg_do_global_parameter(lp_ctx, "printcap cache time", "750");
2379 lpcfg_do_global_parameter(lp_ctx, "create krb5 conf", "yes");
2381 lpcfg_do_global_parameter(lp_ctx, "winbind max clients", "200");
2383 lpcfg_do_global_parameter(lp_ctx, "acl map full control", "yes");
2385 lpcfg_do_global_parameter(lp_ctx, "nt pipe support", "yes");
2387 lpcfg_do_global_parameter(lp_ctx, "ldap debug threshold", "10");
2389 lpcfg_do_global_parameter(lp_ctx, "follow symlinks", "yes");
2391 lpcfg_do_global_parameter(lp_ctx, "machine password timeout", "604800");
2393 lpcfg_do_global_parameter(lp_ctx, "ldap connection timeout", "2");
2395 lpcfg_do_global_parameter(lp_ctx, "winbind expand groups", "1");
2397 lpcfg_do_global_parameter(lp_ctx, "stat cache", "yes");
2399 lpcfg_do_global_parameter(lp_ctx, "lpq cache time", "30");
2401 lpcfg_do_global_parameter_var(lp_ctx, "smb2 max trans", "%u", DEFAULT_SMB2_MAX_TRANSACT);
2403 lpcfg_do_global_parameter_var(lp_ctx, "smb2 max read", "%u", DEFAULT_SMB2_MAX_READ);
2405 lpcfg_do_global_parameter(lp_ctx, "durable handles", "yes");
2407 lpcfg_do_global_parameter(lp_ctx, "max stat cache size", "256");
2409 lpcfg_do_global_parameter(lp_ctx, "ldap passwd sync", "no");
2411 lpcfg_do_global_parameter(lp_ctx, "kernel change notify", "yes");
2413 lpcfg_do_global_parameter(lp_ctx, "max ttl", "259200");
2415 lpcfg_do_global_parameter(lp_ctx, "blocking locks", "yes");
2417 lpcfg_do_global_parameter(lp_ctx, "oplock contention limit", "2");
2419 lpcfg_do_global_parameter(lp_ctx, "load printers", "yes");
2421 lpcfg_do_global_parameter(lp_ctx, "idmap cache time", "604800");
2423 lpcfg_do_global_parameter(lp_ctx, "preserve case", "yes");
2425 lpcfg_do_global_parameter(lp_ctx, "lm announce", "auto");
2427 lpcfg_do_global_parameter(lp_ctx, "afs token lifetime", "604800");
2429 lpcfg_do_global_parameter(lp_ctx, "enable core files", "yes");
2431 lpcfg_do_global_parameter(lp_ctx, "winbind max domain connections", "1");
2433 lpcfg_do_global_parameter(lp_ctx, "case sensitive", "auto");
2435 lpcfg_do_global_parameter(lp_ctx, "ldap timeout", "15");
2437 lpcfg_do_global_parameter(lp_ctx, "mangle prefix", "1");
2439 lpcfg_do_global_parameter(lp_ctx, "posix locking", "yes");
2441 lpcfg_do_global_parameter(lp_ctx, "lock spin time", "200");
2443 lpcfg_do_global_parameter(lp_ctx, "directory name cache size", "100");
2445 lpcfg_do_global_parameter(lp_ctx, "nmbd bind explicit broadcast", "yes");
2447 lpcfg_do_global_parameter(lp_ctx, "init logon delay", "100");
2449 lpcfg_do_global_parameter(lp_ctx, "usershare owner only", "yes");
2451 lpcfg_do_global_parameter(lp_ctx, "-valid", "yes");
2453 lpcfg_do_global_parameter_var(lp_ctx, "usershare path", "%s/usershares", get_dyn_STATEDIR());
2455 #ifdef DEVELOPER
2456 lpcfg_do_global_parameter_var(lp_ctx, "panic action", "/bin/sleep 999999999");
2457 #endif
2459 lpcfg_do_global_parameter(lp_ctx, "smb passwd file", get_dyn_SMB_PASSWD_FILE());
2461 lpcfg_do_global_parameter(lp_ctx, "logon home", "\\\\%N\\%U");
2463 lpcfg_do_global_parameter(lp_ctx, "logon path", "\\\\%N\\%U\\profile");
2465 lpcfg_do_global_parameter(lp_ctx, "printjob username", "%U");
2467 for (i = 0; parm_table[i].label; i++) {
2468 if (!(lp_ctx->flags[i] & FLAG_CMDLINE)) {
2469 lp_ctx->flags[i] |= FLAG_DEFAULT;
2473 for (parm=lp_ctx->globals->param_opt; parm; parm=parm->next) {
2474 if (!(parm->priority & FLAG_CMDLINE)) {
2475 parm->priority |= FLAG_DEFAULT;
2479 return lp_ctx;
2483 * Initialise the global parameter structure.
2485 struct loadparm_context *loadparm_init_global(bool load_default)
2487 if (global_loadparm_context == NULL) {
2488 global_loadparm_context = loadparm_init(NULL);
2490 if (global_loadparm_context == NULL) {
2491 return NULL;
2493 global_loadparm_context->global = true;
2494 if (load_default && !global_loadparm_context->loaded) {
2495 lpcfg_load_default(global_loadparm_context);
2497 global_loadparm_context->refuse_free = true;
2498 return global_loadparm_context;
2502 * Initialise the global parameter structure.
2504 struct loadparm_context *loadparm_init_s3(TALLOC_CTX *mem_ctx,
2505 const struct loadparm_s3_helpers *s3_fns)
2507 struct loadparm_context *loadparm_context = talloc_zero(mem_ctx, struct loadparm_context);
2508 if (!loadparm_context) {
2509 return NULL;
2511 loadparm_context->s3_fns = s3_fns;
2512 loadparm_context->globals = s3_fns->globals;
2513 return loadparm_context;
2516 const char *lpcfg_configfile(struct loadparm_context *lp_ctx)
2518 return lp_ctx->szConfigFile;
2521 const char *lp_default_path(void)
2523 if (getenv("SMB_CONF_PATH"))
2524 return getenv("SMB_CONF_PATH");
2525 else
2526 return dyn_CONFIGFILE;
2530 * Update the internal state of a loadparm context after settings
2531 * have changed.
2533 static bool lpcfg_update(struct loadparm_context *lp_ctx)
2535 struct debug_settings settings;
2536 TALLOC_CTX *tmp_ctx;
2538 tmp_ctx = talloc_new(lp_ctx);
2539 if (tmp_ctx == NULL) {
2540 return false;
2543 lpcfg_add_auto_services(lp_ctx, lpcfg_auto_services(lp_ctx, tmp_ctx));
2545 if (!lp_ctx->globals->wins_server_list && lp_ctx->globals->we_are_a_wins_server) {
2546 lpcfg_do_global_parameter(lp_ctx, "wins server", "127.0.0.1");
2549 if (!lp_ctx->global) {
2550 TALLOC_FREE(tmp_ctx);
2551 return true;
2554 panic_action = lp_ctx->globals->panic_action;
2556 reload_charcnv(lp_ctx);
2558 ZERO_STRUCT(settings);
2559 /* Add any more debug-related smb.conf parameters created in
2560 * future here */
2561 settings.syslog = lp_ctx->globals->syslog;
2562 settings.syslog_only = lp_ctx->globals->syslog_only;
2563 settings.timestamp_logs = lp_ctx->globals->timestamp_logs;
2564 settings.debug_prefix_timestamp = lp_ctx->globals->debug_prefix_timestamp;
2565 settings.debug_hires_timestamp = lp_ctx->globals->debug_hires_timestamp;
2566 settings.debug_pid = lp_ctx->globals->debug_pid;
2567 settings.debug_uid = lp_ctx->globals->debug_uid;
2568 settings.debug_class = lp_ctx->globals->debug_class;
2569 debug_set_settings(&settings);
2571 /* FIXME: This is a bit of a hack, but we can't use a global, since
2572 * not everything that uses lp also uses the socket library */
2573 if (lpcfg_parm_bool(lp_ctx, NULL, "socket", "testnonblock", false)) {
2574 setenv("SOCKET_TESTNONBLOCK", "1", 1);
2575 } else {
2576 unsetenv("SOCKET_TESTNONBLOCK");
2579 TALLOC_FREE(tmp_ctx);
2580 return true;
2583 bool lpcfg_load_default(struct loadparm_context *lp_ctx)
2585 const char *path;
2587 path = lp_default_path();
2589 if (!file_exist(path)) {
2590 /* We allow the default smb.conf file to not exist,
2591 * basically the equivalent of an empty file. */
2592 return lpcfg_update(lp_ctx);
2595 return lpcfg_load(lp_ctx, path);
2599 * Load the services array from the services file.
2601 * Return True on success, False on failure.
2603 bool lpcfg_load(struct loadparm_context *lp_ctx, const char *filename)
2605 char *n2;
2606 bool bRetval;
2608 filename = talloc_strdup(lp_ctx, filename);
2610 lp_ctx->szConfigFile = filename;
2612 if (lp_ctx->s3_fns) {
2613 return lp_ctx->s3_fns->load(filename);
2616 lp_ctx->bInGlobalSection = true;
2617 n2 = standard_sub_basic(lp_ctx, lp_ctx->szConfigFile);
2618 DEBUG(2, ("lpcfg_load: refreshing parameters from %s\n", n2));
2620 add_to_file_list(lp_ctx, &lp_ctx->file_lists, lp_ctx->szConfigFile, n2);
2622 /* We get sections first, so have to start 'behind' to make up */
2623 lp_ctx->currentService = NULL;
2624 bRetval = pm_process(n2, do_section, do_parameter, lp_ctx);
2626 /* finish up the last section */
2627 DEBUG(4, ("pm_process() returned %s\n", BOOLSTR(bRetval)));
2628 if (bRetval)
2629 if (lp_ctx->currentService != NULL)
2630 bRetval = lpcfg_service_ok(lp_ctx->currentService);
2632 bRetval = bRetval && lpcfg_update(lp_ctx);
2634 /* we do this unconditionally, so that it happens even
2635 for a missing smb.conf */
2636 reload_charcnv(lp_ctx);
2638 if (bRetval == true) {
2639 /* set this up so that any child python tasks will
2640 find the right smb.conf */
2641 setenv("SMB_CONF_PATH", filename, 1);
2643 /* set the context used by the lp_*() function
2644 varients */
2645 global_loadparm_context = lp_ctx;
2646 lp_ctx->loaded = true;
2649 return bRetval;
2653 * Return the max number of services.
2656 int lpcfg_numservices(struct loadparm_context *lp_ctx)
2658 if (lp_ctx->s3_fns) {
2659 return lp_ctx->s3_fns->get_numservices();
2662 return lp_ctx->iNumServices;
2666 * Display the contents of the services array in human-readable form.
2669 void lpcfg_dump(struct loadparm_context *lp_ctx, FILE *f, bool show_defaults,
2670 int maxtoprint)
2672 int iService;
2674 if (lp_ctx->s3_fns) {
2675 lp_ctx->s3_fns->dump(f, show_defaults, maxtoprint);
2676 return;
2679 defaults_saved = !show_defaults;
2681 dump_globals(lp_ctx, f, show_defaults);
2683 dump_a_service(lp_ctx->sDefault, lp_ctx->sDefault, f, lp_ctx->flags);
2685 for (iService = 0; iService < maxtoprint; iService++)
2686 lpcfg_dump_one(f, show_defaults, lp_ctx->services[iService], lp_ctx->sDefault);
2690 * Display the contents of one service in human-readable form.
2692 void lpcfg_dump_one(FILE *f, bool show_defaults, struct loadparm_service *service, struct loadparm_service *sDefault)
2694 if (service != NULL) {
2695 if (service->szService[0] == '\0')
2696 return;
2697 dump_a_service(service, sDefault, f, NULL);
2701 struct loadparm_service *lpcfg_servicebynum(struct loadparm_context *lp_ctx,
2702 int snum)
2704 if (lp_ctx->s3_fns) {
2705 return lp_ctx->s3_fns->get_servicebynum(snum);
2708 return lp_ctx->services[snum];
2711 struct loadparm_service *lpcfg_service(struct loadparm_context *lp_ctx,
2712 const char *service_name)
2714 int iService;
2715 char *serviceName;
2717 if (lp_ctx->s3_fns) {
2718 return lp_ctx->s3_fns->get_service(service_name);
2721 for (iService = lp_ctx->iNumServices - 1; iService >= 0; iService--) {
2722 if (lp_ctx->services[iService] &&
2723 lp_ctx->services[iService]->szService) {
2725 * The substitution here is used to support %U is
2726 * service names
2728 serviceName = standard_sub_basic(
2729 lp_ctx->services[iService],
2730 lp_ctx->services[iService]->szService);
2731 if (strequal(serviceName, service_name)) {
2732 talloc_free(serviceName);
2733 return lp_ctx->services[iService];
2735 talloc_free(serviceName);
2739 DEBUG(7,("lpcfg_servicenumber: couldn't find %s\n", service_name));
2740 return NULL;
2743 const char *lpcfg_servicename(const struct loadparm_service *service)
2745 return lpcfg_string((const char *)service->szService);
2749 * A useful volume label function.
2751 const char *lpcfg_volume_label(struct loadparm_service *service, struct loadparm_service *sDefault)
2753 const char *ret;
2754 ret = lpcfg_string((const char *)((service != NULL && service->volume != NULL) ?
2755 service->volume : sDefault->volume));
2756 if (!*ret)
2757 return lpcfg_servicename(service);
2758 return ret;
2762 * Return the correct printer name.
2764 const char *lpcfg_printername(struct loadparm_service *service, struct loadparm_service *sDefault)
2766 const char *ret;
2767 ret = lpcfg_string((const char *)((service != NULL && service->_printername != NULL) ?
2768 service->_printername : sDefault->_printername));
2769 if (ret == NULL || (ret != NULL && *ret == '\0'))
2770 ret = lpcfg_servicename(service);
2772 return ret;
2777 * Return the max print jobs per queue.
2779 int lpcfg_maxprintjobs(struct loadparm_service *service, struct loadparm_service *sDefault)
2781 int maxjobs = (service != NULL) ? service->iMaxPrintJobs : sDefault->iMaxPrintJobs;
2782 if (maxjobs <= 0 || maxjobs >= PRINT_MAX_JOBID)
2783 maxjobs = PRINT_MAX_JOBID - 1;
2785 return maxjobs;
2788 struct smb_iconv_handle *lpcfg_iconv_handle(struct loadparm_context *lp_ctx)
2790 if (lp_ctx == NULL) {
2791 return get_iconv_handle();
2793 return lp_ctx->iconv_handle;
2796 _PUBLIC_ void reload_charcnv(struct loadparm_context *lp_ctx)
2798 struct smb_iconv_handle *old_ic = lp_ctx->iconv_handle;
2799 if (!lp_ctx->global) {
2800 return;
2803 if (old_ic == NULL) {
2804 old_ic = global_iconv_handle;
2806 lp_ctx->iconv_handle = smb_iconv_handle_reinit_lp(lp_ctx, lp_ctx, old_ic);
2807 global_iconv_handle = lp_ctx->iconv_handle;
2810 _PUBLIC_ char *lpcfg_tls_keyfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
2812 return lpcfg_private_path(mem_ctx, lp_ctx, lpcfg__tls_keyfile(lp_ctx));
2815 _PUBLIC_ char *lpcfg_tls_certfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
2817 return lpcfg_private_path(mem_ctx, lp_ctx, lpcfg__tls_certfile(lp_ctx));
2820 _PUBLIC_ char *lpcfg_tls_cafile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
2822 return lpcfg_private_path(mem_ctx, lp_ctx, lpcfg__tls_cafile(lp_ctx));
2825 _PUBLIC_ char *lpcfg_tls_crlfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
2827 return lpcfg_private_path(mem_ctx, lp_ctx, lpcfg__tls_crlfile(lp_ctx));
2830 _PUBLIC_ char *lpcfg_tls_dhpfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
2832 return lpcfg_private_path(mem_ctx, lp_ctx, lpcfg__tls_dhpfile(lp_ctx));
2835 struct gensec_settings *lpcfg_gensec_settings(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
2837 struct gensec_settings *settings = talloc_zero(mem_ctx, struct gensec_settings);
2838 if (settings == NULL)
2839 return NULL;
2840 SMB_ASSERT(lp_ctx != NULL);
2841 settings->lp_ctx = talloc_reference(settings, lp_ctx);
2842 settings->target_hostname = lpcfg_parm_string(lp_ctx, NULL, "gensec", "target_hostname");
2843 return settings;
2846 int lpcfg_server_role(struct loadparm_context *lp_ctx)
2848 int domain_master = lpcfg__domain_master(lp_ctx);
2850 return lp_find_server_role(lpcfg__server_role(lp_ctx),
2851 lpcfg__security(lp_ctx),
2852 lpcfg__domain_logons(lp_ctx),
2853 (domain_master == true) ||
2854 (domain_master == Auto));
2857 int lpcfg_security(struct loadparm_context *lp_ctx)
2859 return lp_find_security(lpcfg__server_role(lp_ctx),
2860 lpcfg__security(lp_ctx));
2863 bool lpcfg_server_signing_allowed(struct loadparm_context *lp_ctx, bool *mandatory)
2865 bool allowed = true;
2866 enum smb_signing_setting signing_setting = lpcfg_server_signing(lp_ctx);
2868 *mandatory = false;
2870 if (signing_setting == SMB_SIGNING_DEFAULT) {
2872 * If we are a domain controller, SMB signing is
2873 * really important, as it can prevent a number of
2874 * attacks on communications between us and the
2875 * clients
2877 * However, it really sucks (no sendfile, CPU
2878 * overhead) performance-wise when used on a
2879 * file server, so disable it by default
2880 * on non-DCs
2883 if (lpcfg_server_role(lp_ctx) >= ROLE_ACTIVE_DIRECTORY_DC) {
2884 signing_setting = SMB_SIGNING_REQUIRED;
2885 } else {
2886 signing_setting = SMB_SIGNING_OFF;
2890 switch (signing_setting) {
2891 case SMB_SIGNING_REQUIRED:
2892 *mandatory = true;
2893 break;
2894 case SMB_SIGNING_IF_REQUIRED:
2895 break;
2896 case SMB_SIGNING_DEFAULT:
2897 case SMB_SIGNING_OFF:
2898 allowed = false;
2899 break;
2902 return allowed;
2905 int lpcfg_tdb_hash_size(struct loadparm_context *lp_ctx, const char *name)
2907 const char *base;
2909 if (name == NULL) {
2910 return 0;
2913 base = strrchr_m(name, '/');
2914 if (base != NULL) {
2915 base += 1;
2916 } else {
2917 base = name;
2919 return lpcfg_parm_int(lp_ctx, NULL, "tdb_hashsize", base, 0);
2923 int lpcfg_tdb_flags(struct loadparm_context *lp_ctx, int tdb_flags)
2925 if (!lpcfg_use_mmap(lp_ctx)) {
2926 tdb_flags |= TDB_NOMMAP;
2928 return tdb_flags;