torture3: Reproducer for bug 10593
[Samba.git] / lib / param / loadparm.c
blob5a0ef8824a1bd4442024a5e55ea654e5f43101dd
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 *);
75 #include "lib/param/param_global.h"
77 struct loadparm_service *lpcfg_default_service(struct loadparm_context *lp_ctx)
79 if (lp_ctx->s3_fns) {
80 return lp_ctx->s3_fns->get_default_loadparm_service();
82 return lp_ctx->sDefault;
85 /**
86 * Convenience routine to grab string parameters into temporary memory
87 * and run standard_sub_basic on them.
89 * The buffers can be written to by
90 * callers without affecting the source string.
93 static const char *lpcfg_string(const char *s)
95 #if 0 /* until REWRITE done to make thread-safe */
96 size_t len = s ? strlen(s) : 0;
97 char *ret;
98 #endif
100 /* The follow debug is useful for tracking down memory problems
101 especially if you have an inner loop that is calling a lp_*()
102 function that returns a string. Perhaps this debug should be
103 present all the time? */
105 #if 0
106 DEBUG(10, ("lpcfg_string(%s)\n", s));
107 #endif
109 #if 0 /* until REWRITE done to make thread-safe */
110 if (!lp_talloc)
111 lp_talloc = talloc_init("lp_talloc");
113 ret = talloc_array(lp_talloc, char, len + 100); /* leave room for substitution */
115 if (!ret)
116 return NULL;
118 if (!s)
119 *ret = 0;
120 else
121 strlcpy(ret, s, len);
123 if (trim_string(ret, "\"", "\"")) {
124 if (strchr(ret,'"') != NULL)
125 strlcpy(ret, s, len);
128 standard_sub_basic(ret,len+100);
129 return (ret);
130 #endif
131 return s;
135 In this section all the functions that are used to access the
136 parameters from the rest of the program are defined
140 * the creation of separate lpcfg_*() and lp_*() functions is to allow
141 * for code compatibility between existing Samba4 and Samba3 code.
144 /* this global context supports the lp_*() function varients */
145 static struct loadparm_context *global_loadparm_context;
147 #define lpcfg_default_service global_loadparm_context->sDefault
148 #define lpcfg_global_service(i) global_loadparm_context->services[i]
150 #define FN_GLOBAL_STRING(fn_name,var_name) \
151 _PUBLIC_ char *lpcfg_ ## fn_name(struct loadparm_context *lp_ctx, TALLOC_CTX *ctx) {\
152 if (lp_ctx == NULL) return NULL; \
153 if (lp_ctx->s3_fns) { \
154 return lp_ctx->globals->var_name ? lp_ctx->s3_fns->lp_string(ctx, lp_ctx->globals->var_name) : talloc_strdup(ctx, ""); \
156 return lp_ctx->globals->var_name ? talloc_strdup(ctx, lpcfg_string(lp_ctx->globals->var_name)) : talloc_strdup(ctx, ""); \
159 #define FN_GLOBAL_CONST_STRING(fn_name,var_name) \
160 _PUBLIC_ const char *lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) { \
161 if (lp_ctx == NULL) return NULL; \
162 return lp_ctx->globals->var_name ? lpcfg_string(lp_ctx->globals->var_name) : ""; \
165 #define FN_GLOBAL_LIST(fn_name,var_name) \
166 _PUBLIC_ const char **lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) { \
167 if (lp_ctx == NULL) return NULL; \
168 return lp_ctx->globals->var_name; \
171 #define FN_GLOBAL_BOOL(fn_name,var_name) \
172 _PUBLIC_ bool lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) {\
173 if (lp_ctx == NULL) return false; \
174 return lp_ctx->globals->var_name; \
177 #define FN_GLOBAL_INTEGER(fn_name,var_name) \
178 _PUBLIC_ int lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) { \
179 return lp_ctx->globals->var_name; \
182 /* Local parameters don't need the ->s3_fns because the struct
183 * loadparm_service is shared and lpcfg_service() checks the ->s3_fns
184 * hook */
185 #define FN_LOCAL_STRING(fn_name,val) \
186 _PUBLIC_ char *lpcfg_ ## fn_name(struct loadparm_service *service, \
187 struct loadparm_service *sDefault, TALLOC_CTX *ctx) { \
188 return(talloc_strdup(ctx, lpcfg_string((const char *)((service != NULL && service->val != NULL) ? service->val : sDefault->val)))); \
191 #define FN_LOCAL_CONST_STRING(fn_name,val) \
192 _PUBLIC_ const char *lpcfg_ ## fn_name(struct loadparm_service *service, \
193 struct loadparm_service *sDefault) { \
194 return((const char *)((service != NULL && service->val != NULL) ? service->val : sDefault->val)); \
197 #define FN_LOCAL_LIST(fn_name,val) \
198 _PUBLIC_ const char **lpcfg_ ## fn_name(struct loadparm_service *service, \
199 struct loadparm_service *sDefault) {\
200 return(const char **)(service != NULL && service->val != NULL? service->val : sDefault->val); \
203 #define FN_LOCAL_PARM_BOOL(fn_name, val) FN_LOCAL_BOOL(fn_name, val)
205 #define FN_LOCAL_BOOL(fn_name,val) \
206 _PUBLIC_ bool lpcfg_ ## fn_name(struct loadparm_service *service, \
207 struct loadparm_service *sDefault) { \
208 return((service != NULL)? service->val : sDefault->val); \
211 #define FN_LOCAL_INTEGER(fn_name,val) \
212 _PUBLIC_ int lpcfg_ ## fn_name(struct loadparm_service *service, \
213 struct loadparm_service *sDefault) { \
214 return((service != NULL)? service->val : sDefault->val); \
217 #define FN_LOCAL_PARM_INTEGER(fn_name, val) FN_LOCAL_INTEGER(fn_name, val)
219 #define FN_LOCAL_PARM_CHAR(fn_name,val) \
220 _PUBLIC_ char lpcfg_ ## fn_name(struct loadparm_service *service, \
221 struct loadparm_service *sDefault) { \
222 return((service != NULL)? service->val : sDefault->val); \
225 #include "lib/param/param_functions.c"
227 /* These functions cannot be auto-generated */
228 FN_LOCAL_BOOL(autoloaded, autoloaded)
229 FN_GLOBAL_CONST_STRING(dnsdomain, dnsdomain)
231 /* local prototypes */
232 static struct loadparm_service *lpcfg_getservicebyname(struct loadparm_context *lp_ctx,
233 const char *pszServiceName);
234 static bool lpcfg_service_ok(struct loadparm_service *service);
235 static bool do_section(const char *pszSectionName, void *);
237 /* The following are helper functions for parametrical options support. */
238 /* It returns a pointer to parametrical option value if it exists or NULL otherwise */
239 /* Actual parametrical functions are quite simple */
240 struct parmlist_entry *get_parametric_helper(struct loadparm_service *service,
241 const char *type, const char *option,
242 struct parmlist_entry *global_opts)
244 char* param_key;
245 struct parmlist_entry *data = NULL;
246 TALLOC_CTX *mem_ctx = talloc_stackframe();
248 param_key = talloc_asprintf(mem_ctx, "%s:%s", type, option);
249 if (param_key == NULL) {
250 DEBUG(0,("asprintf failed!\n"));
251 TALLOC_FREE(mem_ctx);
252 return NULL;
256 * Try to fetch the option from the data.
258 if (service != NULL) {
259 data = service->param_opt;
260 while (data != NULL) {
261 if (strwicmp(data->key, param_key) == 0) {
262 TALLOC_FREE(mem_ctx);
263 return data;
265 data = data->next;
270 * Fall back to fetching from the globals.
272 data = global_opts;
273 while (data != NULL) {
274 if (strwicmp(data->key, param_key) == 0) {
275 TALLOC_FREE(mem_ctx);
276 return data;
278 data = data->next;
282 TALLOC_FREE(mem_ctx);
284 return NULL;
289 const char *lpcfg_get_parametric(struct loadparm_context *lp_ctx,
290 struct loadparm_service *service,
291 const char *type, const char *option)
293 struct parmlist_entry *data;
295 if (lp_ctx == NULL)
296 return NULL;
298 data = get_parametric_helper(service,
299 type, option, lp_ctx->globals->param_opt);
301 if (data == NULL) {
302 return NULL;
303 } else {
304 return data->value;
310 * convenience routine to return int parameters.
312 int lp_int(const char *s)
315 if (!s || !*s) {
316 DEBUG(0,("lp_int(%s): is called with NULL!\n",s));
317 return -1;
320 return strtol(s, NULL, 0);
324 * convenience routine to return unsigned long parameters.
326 unsigned long lp_ulong(const char *s)
329 if (!s || !*s) {
330 DEBUG(0,("lp_ulong(%s): is called with NULL!\n",s));
331 return -1;
334 return strtoul(s, NULL, 0);
338 * convenience routine to return unsigned long parameters.
340 static long lp_long(const char *s)
343 if (!s) {
344 DEBUG(0,("lp_long(%s): is called with NULL!\n",s));
345 return -1;
348 return strtol(s, NULL, 0);
352 * convenience routine to return unsigned long parameters.
354 static double lp_double(const char *s)
357 if (!s) {
358 DEBUG(0,("lp_double(%s): is called with NULL!\n",s));
359 return -1;
362 return strtod(s, NULL);
366 * convenience routine to return boolean parameters.
368 bool lp_bool(const char *s)
370 bool ret = false;
372 if (!s || !*s) {
373 DEBUG(0,("lp_bool(%s): is called with NULL!\n",s));
374 return false;
377 if (!set_boolean(s, &ret)) {
378 DEBUG(0,("lp_bool(%s): value is not boolean!\n",s));
379 return false;
382 return ret;
386 * Return parametric option from a given service. Type is a part of option before ':'
387 * Parametric option has following syntax: 'Type: option = value'
388 * Returned value is allocated in 'lp_talloc' context
391 const char *lpcfg_parm_string(struct loadparm_context *lp_ctx,
392 struct loadparm_service *service, const char *type,
393 const char *option)
395 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
397 if (value)
398 return lpcfg_string(value);
400 return NULL;
404 * Return parametric option from a given service. Type is a part of option before ':'
405 * Parametric option has following syntax: 'Type: option = value'
406 * Returned value is allocated in 'lp_talloc' context
409 const char **lpcfg_parm_string_list(TALLOC_CTX *mem_ctx,
410 struct loadparm_context *lp_ctx,
411 struct loadparm_service *service,
412 const char *type,
413 const char *option, const char *separator)
415 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
417 if (value != NULL)
418 return (const char **)str_list_make(mem_ctx, value, separator);
420 return NULL;
424 * Return parametric option from a given service. Type is a part of option before ':'
425 * Parametric option has following syntax: 'Type: option = value'
428 int lpcfg_parm_int(struct loadparm_context *lp_ctx,
429 struct loadparm_service *service, const char *type,
430 const char *option, int default_v)
432 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
434 if (value)
435 return lp_int(value);
437 return default_v;
441 * Return parametric option from a given service. Type is a part of
442 * option before ':'.
443 * Parametric option has following syntax: 'Type: option = value'.
446 int lpcfg_parm_bytes(struct loadparm_context *lp_ctx,
447 struct loadparm_service *service, const char *type,
448 const char *option, int default_v)
450 uint64_t bval;
452 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
454 if (value && conv_str_size_error(value, &bval)) {
455 if (bval <= INT_MAX) {
456 return (int)bval;
460 return default_v;
464 * Return parametric option from a given service.
465 * Type is a part of option before ':'
466 * Parametric option has following syntax: 'Type: option = value'
468 unsigned long lpcfg_parm_ulong(struct loadparm_context *lp_ctx,
469 struct loadparm_service *service, const char *type,
470 const char *option, unsigned long default_v)
472 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
474 if (value)
475 return lp_ulong(value);
477 return default_v;
480 long lpcfg_parm_long(struct loadparm_context *lp_ctx,
481 struct loadparm_service *service, const char *type,
482 const char *option, long default_v)
484 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
486 if (value)
487 return lp_long(value);
489 return default_v;
492 double lpcfg_parm_double(struct loadparm_context *lp_ctx,
493 struct loadparm_service *service, const char *type,
494 const char *option, double default_v)
496 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
498 if (value != NULL)
499 return lp_double(value);
501 return default_v;
505 * Return parametric option from a given service. Type is a part of option before ':'
506 * Parametric option has following syntax: 'Type: option = value'
509 bool lpcfg_parm_bool(struct loadparm_context *lp_ctx,
510 struct loadparm_service *service, const char *type,
511 const char *option, bool default_v)
513 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
515 if (value != NULL)
516 return lp_bool(value);
518 return default_v;
523 * Set a string value, deallocating any existing space, and allocing the space
524 * for the string
526 bool lpcfg_string_set(TALLOC_CTX *mem_ctx, char **dest, const char *src)
528 talloc_free(*dest);
530 if (src == NULL)
531 src = "";
533 *dest = talloc_strdup(mem_ctx, src);
534 if ((*dest) == NULL) {
535 DEBUG(0,("Out of memory in string_set\n"));
536 return false;
539 return true;
543 * Set a string value, deallocating any existing space, and allocing the space
544 * for the string
546 static bool lpcfg_string_set_upper(TALLOC_CTX *mem_ctx, char **dest, const char *src)
548 talloc_free(*dest);
550 if (src == NULL)
551 src = "";
553 *dest = strupper_talloc(mem_ctx, src);
554 if ((*dest) == NULL) {
555 DEBUG(0,("Out of memory in string_set_upper\n"));
556 return false;
559 return true;
565 * Add a new service to the services array initialising it with the given
566 * service.
569 struct loadparm_service *lpcfg_add_service(struct loadparm_context *lp_ctx,
570 const struct loadparm_service *pservice,
571 const char *name)
573 int i;
574 int num_to_alloc = lp_ctx->iNumServices + 1;
575 struct parmlist_entry *data, *pdata;
577 if (pservice == NULL) {
578 pservice = lp_ctx->sDefault;
581 /* it might already exist */
582 if (name) {
583 struct loadparm_service *service = lpcfg_getservicebyname(lp_ctx,
584 name);
585 if (service != NULL) {
586 /* Clean all parametric options for service */
587 /* They will be added during parsing again */
588 data = service->param_opt;
589 while (data) {
590 pdata = data->next;
591 talloc_free(data);
592 data = pdata;
594 service->param_opt = NULL;
595 return service;
599 /* find an invalid one */
600 for (i = 0; i < lp_ctx->iNumServices; i++)
601 if (lp_ctx->services[i] == NULL)
602 break;
604 /* if not, then create one */
605 if (i == lp_ctx->iNumServices) {
606 struct loadparm_service **tsp;
608 tsp = talloc_realloc(lp_ctx, lp_ctx->services, struct loadparm_service *, num_to_alloc);
610 if (!tsp) {
611 DEBUG(0,("lpcfg_add_service: failed to enlarge services!\n"));
612 return NULL;
613 } else {
614 lp_ctx->services = tsp;
615 lp_ctx->services[lp_ctx->iNumServices] = NULL;
618 lp_ctx->iNumServices++;
621 lp_ctx->services[i] = talloc_zero(lp_ctx->services, struct loadparm_service);
622 if (lp_ctx->services[i] == NULL) {
623 DEBUG(0,("lpcfg_add_service: out of memory!\n"));
624 return NULL;
626 copy_service(lp_ctx->services[i], pservice, NULL);
627 if (name != NULL)
628 lpcfg_string_set(lp_ctx->services[i], &lp_ctx->services[i]->szService, name);
629 return lp_ctx->services[i];
633 * Add a new home service, with the specified home directory, defaults coming
634 * from service ifrom.
637 bool lpcfg_add_home(struct loadparm_context *lp_ctx,
638 const char *pszHomename,
639 struct loadparm_service *default_service,
640 const char *user, const char *pszHomedir)
642 struct loadparm_service *service;
644 service = lpcfg_add_service(lp_ctx, default_service, pszHomename);
646 if (service == NULL)
647 return false;
649 if (!(*(default_service->path))
650 || strequal(default_service->path, lp_ctx->sDefault->path)) {
651 service->path = talloc_strdup(service, pszHomedir);
652 } else {
653 service->path = string_sub_talloc(service, lpcfg_path(default_service, lp_ctx->sDefault, service), "%H", pszHomedir);
656 if (!(*(service->comment))) {
657 service->comment = talloc_asprintf(service, "Home directory of %s", user);
659 service->bAvailable = default_service->bAvailable;
660 service->browseable = default_service->browseable;
662 DEBUG(3, ("adding home's share [%s] for user '%s' at '%s'\n",
663 pszHomename, user, service->path));
665 return true;
669 * Add a new printer service, with defaults coming from service iFrom.
672 bool lpcfg_add_printer(struct loadparm_context *lp_ctx,
673 const char *pszPrintername,
674 struct loadparm_service *default_service)
676 const char *comment = "From Printcap";
677 struct loadparm_service *service;
678 service = lpcfg_add_service(lp_ctx, default_service, pszPrintername);
680 if (service == NULL)
681 return false;
683 /* note that we do NOT default the availability flag to True - */
684 /* we take it from the default service passed. This allows all */
685 /* dynamic printers to be disabled by disabling the [printers] */
686 /* entry (if/when the 'available' keyword is implemented!). */
688 /* the printer name is set to the service name. */
689 lpcfg_string_set(service, &service->_printername, pszPrintername);
690 lpcfg_string_set(service, &service->comment, comment);
691 service->browseable = default_service->browseable;
692 /* Printers cannot be read_only. */
693 service->read_only = false;
694 /* Printer services must be printable. */
695 service->printable = true;
697 DEBUG(3, ("adding printer service %s\n", pszPrintername));
699 return true;
703 * Map a parameter's string representation to something we can use.
704 * Returns False if the parameter string is not recognised, else TRUE.
707 int lpcfg_map_parameter(const char *pszParmName)
709 int iIndex;
711 for (iIndex = 0; parm_table[iIndex].label; iIndex++)
712 if (strwicmp(parm_table[iIndex].label, pszParmName) == 0)
713 return iIndex;
715 /* Warn only if it isn't parametric option */
716 if (strchr(pszParmName, ':') == NULL)
717 DEBUG(0, ("Unknown parameter encountered: \"%s\"\n", pszParmName));
718 /* We do return 'fail' for parametric options as well because they are
719 stored in different storage
721 return -1;
726 return the parameter structure for a parameter
728 struct parm_struct *lpcfg_parm_struct(struct loadparm_context *lp_ctx, const char *name)
730 int parmnum;
732 if (lp_ctx->s3_fns) {
733 return lp_ctx->s3_fns->get_parm_struct(name);
736 parmnum = lpcfg_map_parameter(name);
737 if (parmnum == -1) return NULL;
738 return &parm_table[parmnum];
742 return the parameter pointer for a parameter
744 void *lpcfg_parm_ptr(struct loadparm_context *lp_ctx,
745 struct loadparm_service *service, struct parm_struct *parm)
747 if (lp_ctx->s3_fns) {
748 return lp_ctx->s3_fns->get_parm_ptr(service, parm);
751 if (service == NULL) {
752 if (parm->p_class == P_LOCAL)
753 return ((char *)lp_ctx->sDefault)+parm->offset;
754 else if (parm->p_class == P_GLOBAL)
755 return ((char *)lp_ctx->globals)+parm->offset;
756 else return NULL;
757 } else {
758 return ((char *)service) + parm->offset;
763 return the parameter pointer for a parameter
765 bool lpcfg_parm_is_cmdline(struct loadparm_context *lp_ctx, const char *name)
767 int parmnum;
769 if (lp_ctx->s3_fns) {
770 struct parm_struct *parm = lp_ctx->s3_fns->get_parm_struct(name);
771 if (parm) {
772 return parm->flags & FLAG_CMDLINE;
774 return false;
777 parmnum = lpcfg_map_parameter(name);
778 if (parmnum == -1) return false;
780 return lp_ctx->flags[parmnum] & FLAG_CMDLINE;
784 * Find a service by name. Otherwise works like get_service.
787 static struct loadparm_service *lpcfg_getservicebyname(struct loadparm_context *lp_ctx,
788 const char *pszServiceName)
790 int iService;
792 if (lp_ctx->s3_fns) {
793 return lp_ctx->s3_fns->get_service(pszServiceName);
796 for (iService = lp_ctx->iNumServices - 1; iService >= 0; iService--)
797 if (lp_ctx->services[iService] != NULL &&
798 strwicmp(lp_ctx->services[iService]->szService, pszServiceName) == 0) {
799 return lp_ctx->services[iService];
802 return NULL;
806 * Add a parametric option to a parmlist_entry,
807 * replacing old value, if already present.
809 void set_param_opt(TALLOC_CTX *mem_ctx,
810 struct parmlist_entry **opt_list,
811 const char *opt_name,
812 const char *opt_value,
813 unsigned priority)
815 struct parmlist_entry *new_opt, *opt;
816 bool not_added;
818 opt = *opt_list;
819 not_added = true;
821 /* Traverse destination */
822 while (opt) {
823 /* If we already have same option, override it */
824 if (strwicmp(opt->key, opt_name) == 0) {
825 if ((opt->priority & FLAG_CMDLINE) &&
826 !(priority & FLAG_CMDLINE)) {
827 /* it's been marked as not to be
828 overridden */
829 return;
831 TALLOC_FREE(opt->value);
832 TALLOC_FREE(opt->list);
833 opt->value = talloc_strdup(opt, opt_value);
834 opt->priority = priority;
835 not_added = false;
836 break;
838 opt = opt->next;
840 if (not_added) {
841 new_opt = talloc(mem_ctx, struct parmlist_entry);
842 if (new_opt == NULL) {
843 smb_panic("OOM");
846 new_opt->key = talloc_strdup(new_opt, opt_name);
847 if (new_opt->key == NULL) {
848 smb_panic("talloc_strdup failed");
851 new_opt->value = talloc_strdup(new_opt, opt_value);
852 if (new_opt->value == NULL) {
853 smb_panic("talloc_strdup failed");
856 new_opt->list = NULL;
857 new_opt->priority = priority;
858 DLIST_ADD(*opt_list, new_opt);
863 * Copy a service structure to another.
864 * If pcopymapDest is NULL then copy all fields
867 void copy_service(struct loadparm_service *pserviceDest,
868 const struct loadparm_service *pserviceSource,
869 struct bitmap *pcopymapDest)
871 int i;
872 bool bcopyall = (pcopymapDest == NULL);
873 struct parmlist_entry *data;
875 for (i = 0; parm_table[i].label; i++)
876 if (parm_table[i].p_class == P_LOCAL &&
877 (bcopyall || bitmap_query(pcopymapDest, i))) {
878 const void *src_ptr =
879 ((const char *)pserviceSource) + parm_table[i].offset;
880 void *dest_ptr =
881 ((char *)pserviceDest) + parm_table[i].offset;
883 switch (parm_table[i].type) {
884 case P_BOOL:
885 case P_BOOLREV:
886 *(bool *)dest_ptr = *(const bool *)src_ptr;
887 break;
889 case P_INTEGER:
890 case P_BYTES:
891 case P_OCTAL:
892 case P_ENUM:
893 *(int *)dest_ptr = *(const int *)src_ptr;
894 break;
896 case P_CHAR:
897 *(char *)dest_ptr = *(const char *)src_ptr;
898 break;
900 case P_STRING:
901 lpcfg_string_set(pserviceDest,
902 (char **)dest_ptr,
903 *(const char * const *)src_ptr);
904 break;
906 case P_USTRING:
907 lpcfg_string_set_upper(pserviceDest,
908 (char **)dest_ptr,
909 *(const char * const *)src_ptr);
910 break;
911 case P_CMDLIST:
912 case P_LIST:
913 TALLOC_FREE(*((char ***)dest_ptr));
914 *(const char * const **)dest_ptr = (const char * const *)str_list_copy(pserviceDest,
915 *(const char * * const *)src_ptr);
916 break;
917 default:
918 break;
922 if (bcopyall) {
923 init_copymap(pserviceDest);
924 if (pserviceSource->copymap)
925 bitmap_copy(pserviceDest->copymap,
926 pserviceSource->copymap);
929 for (data = pserviceSource->param_opt; data != NULL; data = data->next) {
930 set_param_opt(pserviceDest, &pserviceDest->param_opt,
931 data->key, data->value, data->priority);
936 * Check a service for consistency. Return False if the service is in any way
937 * incomplete or faulty, else True.
939 static bool lpcfg_service_ok(struct loadparm_service *service)
941 bool bRetval;
943 bRetval = true;
944 if (service->szService[0] == '\0') {
945 DEBUG(0, ("The following message indicates an internal error:\n"));
946 DEBUG(0, ("No service name in service entry.\n"));
947 bRetval = false;
950 /* The [printers] entry MUST be printable. I'm all for flexibility, but */
951 /* I can't see why you'd want a non-printable printer service... */
952 if (strwicmp(service->szService, PRINTERS_NAME) == 0) {
953 if (!service->printable) {
954 DEBUG(0, ("WARNING: [%s] service MUST be printable!\n",
955 service->szService));
956 service->printable = true;
958 /* [printers] service must also be non-browsable. */
959 if (service->browseable)
960 service->browseable = false;
963 /* If a service is flagged unavailable, log the fact at level 0. */
964 if (!service->bAvailable)
965 DEBUG(1, ("NOTE: Service %s is flagged unavailable.\n",
966 service->szService));
968 return bRetval;
972 /*******************************************************************
973 Keep a linked list of all config files so we know when one has changed
974 it's date and needs to be reloaded.
975 ********************************************************************/
977 void add_to_file_list(TALLOC_CTX *mem_ctx, struct file_lists **list,
978 const char *fname, const char *subfname)
980 struct file_lists *f = *list;
982 while (f) {
983 if (f->name && !strcmp(f->name, fname))
984 break;
985 f = f->next;
988 if (!f) {
989 f = talloc(mem_ctx, struct file_lists);
990 if (!f)
991 goto fail;
992 f->next = *list;
993 f->name = talloc_strdup(f, fname);
994 if (!f->name) {
995 TALLOC_FREE(f);
996 goto fail;
998 f->subfname = talloc_strdup(f, subfname);
999 if (!f->subfname) {
1000 TALLOC_FREE(f);
1001 goto fail;
1003 *list = f;
1004 f->modtime = file_modtime(subfname);
1005 } else {
1006 time_t t = file_modtime(subfname);
1007 if (t)
1008 f->modtime = t;
1010 return;
1012 fail:
1013 DEBUG(0, ("Unable to add file to file list: %s\n", fname));
1017 /*******************************************************************
1018 Check if a config file has changed date.
1019 ********************************************************************/
1020 bool lpcfg_file_list_changed(struct loadparm_context *lp_ctx)
1022 struct file_lists *f;
1023 DEBUG(6, ("lpcfg_file_list_changed()\n"));
1025 for (f = lp_ctx->file_lists; f != NULL; f = f->next) {
1026 char *n2;
1027 time_t mod_time;
1029 n2 = standard_sub_basic(lp_ctx, f->name);
1031 DEBUGADD(6, ("file %s -> %s last mod_time: %s\n",
1032 f->name, n2, ctime(&f->modtime)));
1034 mod_time = file_modtime(n2);
1036 if (mod_time && ((f->modtime != mod_time) || (f->subfname == NULL) || (strcmp(n2, f->subfname) != 0))) {
1037 DEBUGADD(6, ("file %s modified: %s\n", n2,
1038 ctime(&mod_time)));
1039 f->modtime = mod_time;
1040 talloc_free(f->subfname);
1041 f->subfname = talloc_strdup(f, n2);
1042 return true;
1045 return false;
1049 * set the value for a P_ENUM
1051 bool lp_set_enum_parm( struct parm_struct *parm, const char *pszParmValue,
1052 int *ptr )
1054 int i;
1056 for (i = 0; parm->enum_list[i].name; i++) {
1057 if ( strequal(pszParmValue, parm->enum_list[i].name)) {
1058 *ptr = parm->enum_list[i].value;
1059 return true;
1062 DEBUG(0, ("WARNING: Ignoring invalid value '%s' for parameter '%s'\n",
1063 pszParmValue, parm->label));
1064 return false;
1068 /***************************************************************************
1069 Handle the "realm" parameter
1070 ***************************************************************************/
1072 bool handle_realm(struct loadparm_context *lp_ctx, int unused,
1073 const char *pszParmValue, char **ptr)
1075 char *upper;
1076 char *lower;
1078 upper = strupper_talloc(lp_ctx, pszParmValue);
1079 if (upper == NULL) {
1080 return false;
1083 lower = strlower_talloc(lp_ctx, pszParmValue);
1084 if (lower == NULL) {
1085 TALLOC_FREE(upper);
1086 return false;
1089 if (lp_ctx->s3_fns != NULL) {
1090 lp_ctx->s3_fns->lp_string_set(ptr, pszParmValue);
1091 lp_ctx->s3_fns->lp_string_set(&lp_ctx->globals->realm, upper);
1092 lp_ctx->s3_fns->lp_string_set(&lp_ctx->globals->dnsdomain, lower);
1093 } else {
1094 lpcfg_string_set(lp_ctx, ptr, pszParmValue);
1095 lpcfg_string_set(lp_ctx, &lp_ctx->globals->realm, upper);
1096 lpcfg_string_set(lp_ctx, &lp_ctx->globals->dnsdomain, lower);
1099 return true;
1102 /***************************************************************************
1103 Handle the include operation.
1104 ***************************************************************************/
1106 bool handle_include(struct loadparm_context *lp_ctx, int unused,
1107 const char *pszParmValue, char **ptr)
1109 char *fname;
1111 if (lp_ctx->s3_fns) {
1112 return lp_ctx->s3_fns->lp_include(lp_ctx, unused, pszParmValue, ptr);
1115 fname = standard_sub_basic(lp_ctx, pszParmValue);
1117 add_to_file_list(lp_ctx, &lp_ctx->file_lists, pszParmValue, fname);
1119 lpcfg_string_set(lp_ctx, ptr, fname);
1121 if (file_exist(fname))
1122 return pm_process(fname, do_section, do_parameter, lp_ctx);
1124 DEBUG(2, ("Can't find include file %s\n", fname));
1126 return false;
1129 /***************************************************************************
1130 Handle the interpretation of the copy parameter.
1131 ***************************************************************************/
1133 bool handle_copy(struct loadparm_context *lp_ctx, int snum,
1134 const char *pszParmValue, char **ptr)
1136 bool bRetval;
1137 struct loadparm_service *serviceTemp = NULL;
1138 struct loadparm_service *current = NULL;
1140 bRetval = false;
1142 DEBUG(3, ("Copying service from service %s\n", pszParmValue));
1144 serviceTemp = lpcfg_getservicebyname(lp_ctx, pszParmValue);
1145 if (lp_ctx->s3_fns != NULL) {
1146 current = lp_ctx->s3_fns->get_servicebynum(snum);
1147 } else {
1148 current = lp_ctx->currentService;
1151 if (current == NULL) {
1152 DEBUG(0, ("Unable to copy service - invalid service destination"));
1153 return false;
1156 if (serviceTemp != NULL) {
1157 if (serviceTemp == current) {
1158 DEBUG(0, ("Can't copy service %s - unable to copy self!\n", pszParmValue));
1159 } else {
1160 copy_service(current,
1161 serviceTemp,
1162 current->copymap);
1163 lpcfg_string_set(current, ptr, pszParmValue);
1165 bRetval = true;
1167 } else {
1168 DEBUG(0, ("Unable to copy service - source not found: %s\n",
1169 pszParmValue));
1170 bRetval = false;
1173 return bRetval;
1176 bool handle_debug_list(struct loadparm_context *lp_ctx, int unused,
1177 const char *pszParmValue, char **ptr)
1179 if (lp_ctx->s3_fns != NULL) {
1180 lp_ctx->s3_fns->lp_string_set(ptr, pszParmValue);
1181 } else {
1182 lpcfg_string_set(lp_ctx, ptr, pszParmValue);
1185 return debug_parse_levels(pszParmValue);
1188 bool handle_logfile(struct loadparm_context *lp_ctx, int unused,
1189 const char *pszParmValue, char **ptr)
1191 if (lp_ctx->s3_fns != NULL) {
1192 lp_ctx->s3_fns->lp_string_set(ptr, pszParmValue);
1193 } else {
1194 debug_set_logfile(pszParmValue);
1195 lpcfg_string_set(lp_ctx, ptr, pszParmValue);
1198 return true;
1202 * These special charset handling methods only run in the source3 code.
1205 bool handle_charset(struct loadparm_context *lp_ctx, int snum,
1206 const char *pszParmValue, char **ptr)
1208 if (lp_ctx->s3_fns) {
1209 if (*ptr == NULL || strcmp(*ptr, pszParmValue) != 0) {
1210 lp_ctx->s3_fns->lp_string_set(ptr, pszParmValue);
1211 global_iconv_handle = smb_iconv_handle_reinit(NULL,
1212 lpcfg_dos_charset(lp_ctx),
1213 lpcfg_unix_charset(lp_ctx),
1214 true, global_iconv_handle);
1217 return true;
1219 return lpcfg_string_set(lp_ctx, ptr, pszParmValue);
1223 bool handle_dos_charset(struct loadparm_context *lp_ctx, int snum,
1224 const char *pszParmValue, char **ptr)
1226 bool is_utf8 = false;
1227 size_t len = strlen(pszParmValue);
1229 if (lp_ctx->s3_fns) {
1230 if (len == 4 || len == 5) {
1231 /* Don't use StrCaseCmp here as we don't want to
1232 initialize iconv. */
1233 if ((toupper_m(pszParmValue[0]) == 'U') &&
1234 (toupper_m(pszParmValue[1]) == 'T') &&
1235 (toupper_m(pszParmValue[2]) == 'F')) {
1236 if (len == 4) {
1237 if (pszParmValue[3] == '8') {
1238 is_utf8 = true;
1240 } else {
1241 if (pszParmValue[3] == '-' &&
1242 pszParmValue[4] == '8') {
1243 is_utf8 = true;
1249 if (*ptr == NULL || strcmp(*ptr, pszParmValue) != 0) {
1250 if (is_utf8) {
1251 DEBUG(0,("ERROR: invalid DOS charset: 'dos charset' must not "
1252 "be UTF8, using (default value) %s instead.\n",
1253 DEFAULT_DOS_CHARSET));
1254 pszParmValue = DEFAULT_DOS_CHARSET;
1256 lp_ctx->s3_fns->lp_string_set(ptr, pszParmValue);
1257 global_iconv_handle = smb_iconv_handle_reinit(NULL,
1258 lpcfg_dos_charset(lp_ctx),
1259 lpcfg_unix_charset(lp_ctx),
1260 true, global_iconv_handle);
1262 return true;
1265 return lpcfg_string_set(lp_ctx, ptr, pszParmValue);
1268 bool handle_printing(struct loadparm_context *lp_ctx, int snum,
1269 const char *pszParmValue, char **ptr)
1271 static int parm_num = -1;
1272 struct loadparm_service *s;
1274 if (parm_num == -1) {
1275 parm_num = lpcfg_map_parameter("printing");
1278 if (!lp_set_enum_parm(&parm_table[parm_num], pszParmValue, (int*)ptr)) {
1279 return false;
1282 if (lp_ctx->s3_fns) {
1283 if ( snum < 0 ) {
1284 s = lp_ctx->sDefault;
1285 lp_ctx->s3_fns->init_printer_values(lp_ctx->globals->ctx, s);
1286 } else {
1287 s = lp_ctx->services[snum];
1288 lp_ctx->s3_fns->init_printer_values(s, s);
1292 return true;
1295 bool handle_ldap_debug_level(struct loadparm_context *lp_ctx, int snum, const char *pszParmValue, char **ptr)
1297 lp_ctx->globals->ldap_debug_level = lp_int(pszParmValue);
1299 if (lp_ctx->s3_fns) {
1300 lp_ctx->s3_fns->init_ldap_debugging();
1302 return true;
1305 bool handle_netbios_aliases(struct loadparm_context *lp_ctx, int snum, const char *pszParmValue, char **ptr)
1307 TALLOC_FREE(lp_ctx->globals->netbios_aliases);
1308 lp_ctx->globals->netbios_aliases = (const char **)str_list_make_v3(lp_ctx->globals->ctx,
1309 pszParmValue, NULL);
1311 if (lp_ctx->s3_fns) {
1312 return lp_ctx->s3_fns->set_netbios_aliases(lp_ctx->globals->netbios_aliases);
1314 return true;
1318 * idmap related parameters
1321 bool handle_idmap_backend(struct loadparm_context *lp_ctx, int snum, const char *pszParmValue, char **ptr)
1323 if (lp_ctx->s3_fns) {
1324 return lp_ctx->s3_fns->lp_do_parameter(snum, "idmap config * : backend", pszParmValue);
1327 return lpcfg_string_set(lp_ctx, ptr, pszParmValue);
1330 bool handle_idmap_uid(struct loadparm_context *lp_ctx, int snum, const char *pszParmValue, char **ptr)
1332 if (lp_ctx->s3_fns) {
1333 return lp_ctx->s3_fns->lp_do_parameter(snum, "idmap config * : range", pszParmValue);
1336 return lpcfg_string_set(lp_ctx, ptr, pszParmValue);
1339 bool handle_idmap_gid(struct loadparm_context *lp_ctx, int snum, const char *pszParmValue, char **ptr)
1341 if (lp_ctx->s3_fns) {
1342 return lp_ctx->s3_fns->lp_do_parameter(snum, "idmap config * : range", pszParmValue);
1345 return lpcfg_string_set(lp_ctx, ptr, pszParmValue);
1348 /***************************************************************************
1349 Initialise a copymap.
1350 ***************************************************************************/
1352 void init_copymap(struct loadparm_service *pservice)
1354 int i;
1356 TALLOC_FREE(pservice->copymap);
1358 pservice->copymap = bitmap_talloc(NULL, num_parameters());
1359 if (!pservice->copymap)
1360 DEBUG(0,
1361 ("Couldn't allocate copymap!! (size %d)\n",
1362 (int)num_parameters()));
1363 else
1364 for (i = 0; i < num_parameters(); i++)
1365 bitmap_set(pservice->copymap, i);
1369 * Process a parametric option
1371 static bool lp_do_parameter_parametric(struct loadparm_context *lp_ctx,
1372 struct loadparm_service *service,
1373 const char *pszParmName,
1374 const char *pszParmValue, int flags)
1376 struct parmlist_entry **data;
1377 char *name;
1378 TALLOC_CTX *mem_ctx;
1380 while (isspace((unsigned char)*pszParmName)) {
1381 pszParmName++;
1384 name = strlower_talloc(lp_ctx, pszParmName);
1385 if (!name) return false;
1387 if (service == NULL) {
1388 data = &lp_ctx->globals->param_opt;
1389 mem_ctx = lp_ctx->globals;
1390 } else {
1391 data = &service->param_opt;
1392 mem_ctx = service;
1395 set_param_opt(mem_ctx, data, name, pszParmValue, flags);
1397 talloc_free(name);
1399 return true;
1402 static bool set_variable(TALLOC_CTX *mem_ctx, int parmnum, void *parm_ptr,
1403 const char *pszParmName, const char *pszParmValue,
1404 struct loadparm_context *lp_ctx, bool on_globals)
1406 int i;
1407 /* if it is a special case then go ahead */
1408 if (parm_table[parmnum].special) {
1409 bool ret;
1410 ret = parm_table[parmnum].special(lp_ctx, -1, pszParmValue,
1411 (char **)parm_ptr);
1412 if (!ret) {
1413 return false;
1415 goto mark_non_default;
1418 /* now switch on the type of variable it is */
1419 switch (parm_table[parmnum].type)
1421 case P_BOOL: {
1422 bool b;
1423 if (!set_boolean(pszParmValue, &b)) {
1424 DEBUG(0, ("set_variable(%s): value is not "
1425 "boolean!\n", pszParmValue));
1426 return false;
1428 *(bool *)parm_ptr = b;
1430 break;
1432 case P_BOOLREV: {
1433 bool b;
1434 if (!set_boolean(pszParmValue, &b)) {
1435 DEBUG(0, ("set_variable(%s): value is not "
1436 "boolean!\n", pszParmValue));
1437 return false;
1439 *(bool *)parm_ptr = !b;
1441 break;
1443 case P_INTEGER:
1444 *(int *)parm_ptr = lp_int(pszParmValue);
1445 break;
1447 case P_CHAR:
1448 *(char *)parm_ptr = *pszParmValue;
1449 break;
1451 case P_OCTAL:
1452 i = sscanf(pszParmValue, "%o", (int *)parm_ptr);
1453 if ( i != 1 ) {
1454 DEBUG ( 0, ("Invalid octal number %s\n", pszParmName ));
1455 return false;
1457 break;
1459 case P_BYTES:
1461 uint64_t val;
1462 if (conv_str_size_error(pszParmValue, &val)) {
1463 if (val <= INT_MAX) {
1464 *(int *)parm_ptr = (int)val;
1465 break;
1469 DEBUG(0, ("set_variable(%s): value is not "
1470 "a valid size specifier!\n", pszParmValue));
1471 return false;
1474 case P_CMDLIST:
1475 TALLOC_FREE(*(char ***)parm_ptr);
1476 *(const char * const **)parm_ptr
1477 = (const char * const *)str_list_make(mem_ctx,
1478 pszParmValue, NULL);
1479 break;
1480 case P_LIST:
1482 char **new_list = str_list_make(mem_ctx,
1483 pszParmValue, NULL);
1484 for (i=0; new_list[i]; i++) {
1485 if (*(const char ***)parm_ptr != NULL &&
1486 new_list[i][0] == '+' &&
1487 new_list[i][1])
1489 if (!str_list_check(*(const char ***)parm_ptr,
1490 &new_list[i][1])) {
1491 *(const char ***)parm_ptr = str_list_add(*(const char ***)parm_ptr,
1492 &new_list[i][1]);
1494 } else if (*(const char ***)parm_ptr != NULL &&
1495 new_list[i][0] == '-' &&
1496 new_list[i][1])
1498 str_list_remove(*(const char ***)parm_ptr,
1499 &new_list[i][1]);
1500 } else {
1501 if (i != 0) {
1502 DEBUG(0, ("Unsupported list syntax for: %s = %s\n",
1503 pszParmName, pszParmValue));
1504 return false;
1506 *(const char * const **)parm_ptr = (const char * const *) new_list;
1507 break;
1510 break;
1512 case P_STRING:
1513 lpcfg_string_set(mem_ctx, (char **)parm_ptr, pszParmValue);
1514 break;
1516 case P_USTRING:
1517 lpcfg_string_set_upper(mem_ctx, (char **)parm_ptr, pszParmValue);
1518 break;
1520 case P_ENUM:
1521 if (!lp_set_enum_parm(&parm_table[parmnum], pszParmValue, (int*)parm_ptr)) {
1522 return false;
1524 break;
1526 case P_SEP:
1527 break;
1530 mark_non_default:
1531 if (on_globals && (lp_ctx->flags[parmnum] & FLAG_DEFAULT)) {
1532 lp_ctx->flags[parmnum] &= ~FLAG_DEFAULT;
1533 /* we have to also unset FLAG_DEFAULT on aliases */
1534 for (i=parmnum-1;i>=0 && parm_table[i].offset == parm_table[parmnum].offset;i--) {
1535 lp_ctx->flags[i] &= ~FLAG_DEFAULT;
1537 for (i=parmnum+1;i<num_parameters() && parm_table[i].offset == parm_table[parmnum].offset;i++) {
1538 lp_ctx->flags[i] &= ~FLAG_DEFAULT;
1541 return true;
1545 bool lpcfg_do_global_parameter(struct loadparm_context *lp_ctx,
1546 const char *pszParmName, const char *pszParmValue)
1548 int parmnum = lpcfg_map_parameter(pszParmName);
1549 void *parm_ptr;
1551 if (parmnum < 0) {
1552 if (strchr(pszParmName, ':')) {
1553 return lp_do_parameter_parametric(lp_ctx, NULL, pszParmName, pszParmValue, 0);
1555 DEBUG(0, ("Ignoring unknown parameter \"%s\"\n", pszParmName));
1556 return true;
1559 /* if the flag has been set on the command line, then don't allow override,
1560 but don't report an error */
1561 if (lp_ctx->flags[parmnum] & FLAG_CMDLINE) {
1562 return true;
1565 parm_ptr = lpcfg_parm_ptr(lp_ctx, NULL, &parm_table[parmnum]);
1567 return set_variable(lp_ctx->globals, parmnum, parm_ptr,
1568 pszParmName, pszParmValue, lp_ctx, true);
1571 bool lpcfg_do_service_parameter(struct loadparm_context *lp_ctx,
1572 struct loadparm_service *service,
1573 const char *pszParmName, const char *pszParmValue)
1575 void *parm_ptr;
1576 int i;
1577 int parmnum = lpcfg_map_parameter(pszParmName);
1579 if (parmnum < 0) {
1580 if (strchr(pszParmName, ':')) {
1581 return lp_do_parameter_parametric(lp_ctx, service, pszParmName, pszParmValue, 0);
1583 DEBUG(0, ("Ignoring unknown parameter \"%s\"\n", pszParmName));
1584 return true;
1587 /* if the flag has been set on the command line, then don't allow override,
1588 but don't report an error */
1589 if (lp_ctx->flags[parmnum] & FLAG_CMDLINE) {
1590 return true;
1593 if (parm_table[parmnum].p_class == P_GLOBAL) {
1594 DEBUG(0,
1595 ("Global parameter %s found in service section!\n",
1596 pszParmName));
1597 return true;
1599 parm_ptr = ((char *)service) + parm_table[parmnum].offset;
1601 if (!service->copymap)
1602 init_copymap(service);
1604 /* this handles the aliases - set the copymap for other
1605 * entries with the same data pointer */
1606 for (i = 0; parm_table[i].label; i++)
1607 if (parm_table[i].offset == parm_table[parmnum].offset &&
1608 parm_table[i].p_class == parm_table[parmnum].p_class)
1609 bitmap_clear(service->copymap, i);
1611 return set_variable(service, parmnum, parm_ptr, pszParmName,
1612 pszParmValue, lp_ctx, false);
1616 * Process a parameter.
1619 static bool do_parameter(const char *pszParmName, const char *pszParmValue,
1620 void *userdata)
1622 struct loadparm_context *lp_ctx = (struct loadparm_context *)userdata;
1624 if (lp_ctx->bInGlobalSection)
1625 return lpcfg_do_global_parameter(lp_ctx, pszParmName,
1626 pszParmValue);
1627 else
1628 return lpcfg_do_service_parameter(lp_ctx, lp_ctx->currentService,
1629 pszParmName, pszParmValue);
1633 variable argument do parameter
1635 bool lpcfg_do_global_parameter_var(struct loadparm_context *lp_ctx, const char *pszParmName, const char *fmt, ...) PRINTF_ATTRIBUTE(3, 4);
1636 bool lpcfg_do_global_parameter_var(struct loadparm_context *lp_ctx,
1637 const char *pszParmName, const char *fmt, ...)
1639 char *s;
1640 bool ret;
1641 va_list ap;
1643 va_start(ap, fmt);
1644 s = talloc_vasprintf(NULL, fmt, ap);
1645 va_end(ap);
1646 ret = lpcfg_do_global_parameter(lp_ctx, pszParmName, s);
1647 talloc_free(s);
1648 return ret;
1653 set a parameter from the commandline - this is called from command line parameter
1654 parsing code. It sets the parameter then marks the parameter as unable to be modified
1655 by smb.conf processing
1657 bool lpcfg_set_cmdline(struct loadparm_context *lp_ctx, const char *pszParmName,
1658 const char *pszParmValue)
1660 int parmnum;
1661 int i;
1663 while (isspace((unsigned char)*pszParmValue)) pszParmValue++;
1665 if (lp_ctx->s3_fns) {
1666 return lp_ctx->s3_fns->set_cmdline(pszParmName, pszParmValue);
1669 parmnum = lpcfg_map_parameter(pszParmName);
1671 if (parmnum < 0 && strchr(pszParmName, ':')) {
1672 /* set a parametric option */
1673 return lp_do_parameter_parametric(lp_ctx, NULL, pszParmName,
1674 pszParmValue, FLAG_CMDLINE);
1677 if (parmnum < 0) {
1678 DEBUG(0,("Unknown option '%s'\n", pszParmName));
1679 return false;
1682 /* reset the CMDLINE flag in case this has been called before */
1683 lp_ctx->flags[parmnum] &= ~FLAG_CMDLINE;
1685 if (!lpcfg_do_global_parameter(lp_ctx, pszParmName, pszParmValue)) {
1686 return false;
1689 lp_ctx->flags[parmnum] |= FLAG_CMDLINE;
1691 /* we have to also set FLAG_CMDLINE on aliases */
1692 for (i=parmnum-1;
1693 i>=0 && parm_table[i].p_class == parm_table[parmnum].p_class &&
1694 parm_table[i].offset == parm_table[parmnum].offset;
1695 i--) {
1696 lp_ctx->flags[i] |= FLAG_CMDLINE;
1698 for (i=parmnum+1;
1699 i<num_parameters() &&
1700 parm_table[i].p_class == parm_table[parmnum].p_class &&
1701 parm_table[i].offset == parm_table[parmnum].offset;
1702 i++) {
1703 lp_ctx->flags[i] |= FLAG_CMDLINE;
1706 return true;
1710 set a option from the commandline in 'a=b' format. Use to support --option
1712 bool lpcfg_set_option(struct loadparm_context *lp_ctx, const char *option)
1714 char *p, *s;
1715 bool ret;
1717 s = talloc_strdup(NULL, option);
1718 if (!s) {
1719 return false;
1722 p = strchr(s, '=');
1723 if (!p) {
1724 talloc_free(s);
1725 return false;
1728 *p = 0;
1730 ret = lpcfg_set_cmdline(lp_ctx, s, p+1);
1731 talloc_free(s);
1732 return ret;
1736 #define BOOLSTR(b) ((b) ? "Yes" : "No")
1739 * Print a parameter of the specified type.
1742 void lpcfg_print_parameter(struct parm_struct *p, void *ptr, FILE * f)
1744 /* For the seperation of lists values that we print below */
1745 const char *list_sep = ", ";
1746 int i;
1747 switch (p->type)
1749 case P_ENUM:
1750 for (i = 0; p->enum_list[i].name; i++) {
1751 if (*(int *)ptr == p->enum_list[i].value) {
1752 fprintf(f, "%s",
1753 p->enum_list[i].name);
1754 break;
1757 break;
1759 case P_BOOL:
1760 fprintf(f, "%s", BOOLSTR(*(bool *)ptr));
1761 break;
1763 case P_BOOLREV:
1764 fprintf(f, "%s", BOOLSTR(!*(bool *)ptr));
1765 break;
1767 case P_INTEGER:
1768 case P_BYTES:
1769 fprintf(f, "%d", *(int *)ptr);
1770 break;
1772 case P_CHAR:
1773 fprintf(f, "%c", *(char *)ptr);
1774 break;
1776 case P_OCTAL: {
1777 int val = *(int *)ptr;
1778 if (val == -1) {
1779 fprintf(f, "-1");
1780 } else {
1781 fprintf(f, "0%03o", val);
1783 break;
1786 case P_CMDLIST:
1787 list_sep = " ";
1788 /* fall through */
1789 case P_LIST:
1790 if ((char ***)ptr && *(char ***)ptr) {
1791 char **list = *(char ***)ptr;
1792 for (; *list; list++) {
1793 /* surround strings with whitespace in double quotes */
1794 if (*(list+1) == NULL) {
1795 /* last item, no extra separator */
1796 list_sep = "";
1798 if ( strchr_m( *list, ' ' ) ) {
1799 fprintf(f, "\"%s\"%s", *list, list_sep);
1800 } else {
1801 fprintf(f, "%s%s", *list, list_sep);
1805 break;
1807 case P_STRING:
1808 case P_USTRING:
1809 if (*(char **)ptr) {
1810 fprintf(f, "%s", *(char **)ptr);
1812 break;
1813 case P_SEP:
1814 break;
1819 * Check if two parameters are equal.
1822 static bool lpcfg_equal_parameter(parm_type type, void *ptr1, void *ptr2)
1824 switch (type) {
1825 case P_BOOL:
1826 case P_BOOLREV:
1827 return (*((bool *)ptr1) == *((bool *)ptr2));
1829 case P_INTEGER:
1830 case P_ENUM:
1831 case P_OCTAL:
1832 case P_BYTES:
1833 return (*((int *)ptr1) == *((int *)ptr2));
1835 case P_CHAR:
1836 return (*((char *)ptr1) == *((char *)ptr2));
1838 case P_LIST:
1839 case P_CMDLIST:
1840 return str_list_equal(*(const char ***)ptr1, *(const char ***)ptr2);
1842 case P_STRING:
1843 case P_USTRING:
1845 char *p1 = *(char **)ptr1, *p2 = *(char **)ptr2;
1846 if (p1 && !*p1)
1847 p1 = NULL;
1848 if (p2 && !*p2)
1849 p2 = NULL;
1850 return (p1 == p2 || strequal(p1, p2));
1852 case P_SEP:
1853 break;
1855 return false;
1859 * Process a new section (service).
1861 * At this stage all sections are services.
1862 * Later we'll have special sections that permit server parameters to be set.
1863 * Returns True on success, False on failure.
1866 static bool do_section(const char *pszSectionName, void *userdata)
1868 struct loadparm_context *lp_ctx = (struct loadparm_context *)userdata;
1869 bool bRetval;
1870 bool isglobal = ((strwicmp(pszSectionName, GLOBAL_NAME) == 0) ||
1871 (strwicmp(pszSectionName, GLOBAL_NAME2) == 0));
1872 bRetval = false;
1874 /* if we've just struck a global section, note the fact. */
1875 lp_ctx->bInGlobalSection = isglobal;
1877 /* check for multiple global sections */
1878 if (lp_ctx->bInGlobalSection) {
1879 DEBUG(4, ("Processing section \"[%s]\"\n", pszSectionName));
1880 return true;
1883 /* if we have a current service, tidy it up before moving on */
1884 bRetval = true;
1886 if (lp_ctx->currentService != NULL)
1887 bRetval = lpcfg_service_ok(lp_ctx->currentService);
1889 /* if all is still well, move to the next record in the services array */
1890 if (bRetval) {
1891 /* We put this here to avoid an odd message order if messages are */
1892 /* issued by the post-processing of a previous section. */
1893 DEBUG(4, ("Processing section \"[%s]\"\n", pszSectionName));
1895 if ((lp_ctx->currentService = lpcfg_add_service(lp_ctx, lp_ctx->sDefault,
1896 pszSectionName))
1897 == NULL) {
1898 DEBUG(0, ("Failed to add a new service\n"));
1899 return false;
1903 return bRetval;
1908 * Determine if a particular base parameter is currently set to the default value.
1911 static bool is_default(struct loadparm_service *sDefault, int i)
1913 void *def_ptr = ((char *)sDefault) + parm_table[i].offset;
1914 switch (parm_table[i].type) {
1915 case P_CMDLIST:
1916 case P_LIST:
1917 return str_list_equal((const char * const *)parm_table[i].def.lvalue,
1918 *(const char ***)def_ptr);
1919 case P_STRING:
1920 case P_USTRING:
1921 return strequal(parm_table[i].def.svalue,
1922 *(char **)def_ptr);
1923 case P_BOOL:
1924 case P_BOOLREV:
1925 return parm_table[i].def.bvalue ==
1926 *(bool *)def_ptr;
1927 case P_INTEGER:
1928 case P_CHAR:
1929 case P_OCTAL:
1930 case P_BYTES:
1931 case P_ENUM:
1932 return parm_table[i].def.ivalue ==
1933 *(int *)def_ptr;
1934 case P_SEP:
1935 break;
1937 return false;
1941 *Display the contents of the global structure.
1944 static void dump_globals(struct loadparm_context *lp_ctx, FILE *f,
1945 bool show_defaults)
1947 int i;
1948 struct parmlist_entry *data;
1950 fprintf(f, "# Global parameters\n[global]\n");
1952 for (i = 0; parm_table[i].label; i++)
1953 if (parm_table[i].p_class == P_GLOBAL &&
1954 (i == 0 || (parm_table[i].offset != parm_table[i - 1].offset))) {
1955 if (!show_defaults && (lp_ctx->flags[i] & FLAG_DEFAULT))
1956 continue;
1957 fprintf(f, "\t%s = ", parm_table[i].label);
1958 lpcfg_print_parameter(&parm_table[i], lpcfg_parm_ptr(lp_ctx, NULL, &parm_table[i]), f);
1959 fprintf(f, "\n");
1961 if (lp_ctx->globals->param_opt != NULL) {
1962 for (data = lp_ctx->globals->param_opt; data;
1963 data = data->next) {
1964 if (!show_defaults && (data->priority & FLAG_DEFAULT)) {
1965 continue;
1967 fprintf(f, "\t%s = %s\n", data->key, data->value);
1974 * Display the contents of a single services record.
1977 void lpcfg_dump_a_service(struct loadparm_service * pService, struct loadparm_service *sDefault, FILE * f,
1978 unsigned int *flags, bool show_defaults)
1980 int i;
1981 struct parmlist_entry *data;
1983 if (pService != sDefault)
1984 fprintf(f, "\n[%s]\n", pService->szService);
1986 for (i = 0; parm_table[i].label; i++) {
1987 if (parm_table[i].p_class == P_LOCAL &&
1988 (*parm_table[i].label != '-') &&
1989 (i == 0 || (parm_table[i].offset != parm_table[i - 1].offset)))
1991 if (pService == sDefault) {
1992 if (flags && (flags[i] & FLAG_DEFAULT)) {
1993 continue;
1995 if (!show_defaults) {
1996 if (is_default(sDefault, i)) {
1997 continue;
2000 } else {
2001 if (lpcfg_equal_parameter(parm_table[i].type,
2002 ((char *)pService) +
2003 parm_table[i].offset,
2004 ((char *)sDefault) +
2005 parm_table[i].offset))
2006 continue;
2009 fprintf(f, "\t%s = ", parm_table[i].label);
2010 lpcfg_print_parameter(&parm_table[i],
2011 ((char *)pService) + parm_table[i].offset, f);
2012 fprintf(f, "\n");
2015 if (pService->param_opt != NULL) {
2016 for (data = pService->param_opt; data; data = data->next) {
2017 fprintf(f, "\t%s = %s\n", data->key, data->value);
2022 bool lpcfg_dump_a_parameter(struct loadparm_context *lp_ctx,
2023 struct loadparm_service *service,
2024 const char *parm_name, FILE * f)
2026 struct parm_struct *parm;
2027 void *ptr;
2028 char *local_parm_name;
2029 char *parm_opt;
2030 const char *parm_opt_value;
2032 /* check for parametrical option */
2033 local_parm_name = talloc_strdup(lp_ctx, parm_name);
2034 if (local_parm_name == NULL) {
2035 return false;
2038 parm_opt = strchr( local_parm_name, ':');
2040 if (parm_opt) {
2041 *parm_opt = '\0';
2042 parm_opt++;
2043 if (strlen(parm_opt)) {
2044 parm_opt_value = lpcfg_parm_string(lp_ctx, service,
2045 local_parm_name, parm_opt);
2046 if (parm_opt_value) {
2047 fprintf(f, "%s\n", parm_opt_value);
2048 return true;
2051 return false;
2054 /* parameter is not parametric, search the table */
2055 parm = lpcfg_parm_struct(lp_ctx, parm_name);
2056 if (!parm) {
2057 return false;
2060 if (service != NULL && parm->p_class == P_GLOBAL) {
2061 return false;
2064 ptr = lpcfg_parm_ptr(lp_ctx, service,parm);
2066 lpcfg_print_parameter(parm, ptr, f);
2067 fprintf(f, "\n");
2068 return true;
2072 * Auto-load some home services.
2074 static void lpcfg_add_auto_services(struct loadparm_context *lp_ctx,
2075 const char *str)
2077 return;
2082 * Unload unused services.
2085 void lpcfg_killunused(struct loadparm_context *lp_ctx,
2086 struct smbsrv_connection *smb,
2087 bool (*snumused) (struct smbsrv_connection *, int))
2089 int i;
2090 for (i = 0; i < lp_ctx->iNumServices; i++) {
2091 if (lp_ctx->services[i] == NULL)
2092 continue;
2094 if (!snumused || !snumused(smb, i)) {
2095 talloc_free(lp_ctx->services[i]);
2096 lp_ctx->services[i] = NULL;
2102 static int lpcfg_destructor(struct loadparm_context *lp_ctx)
2104 struct parmlist_entry *data;
2106 if (lp_ctx->refuse_free) {
2107 /* someone is trying to free the
2108 global_loadparm_context.
2109 We can't allow that. */
2110 return -1;
2113 if (lp_ctx->globals->param_opt != NULL) {
2114 struct parmlist_entry *next;
2115 for (data = lp_ctx->globals->param_opt; data; data=next) {
2116 next = data->next;
2117 if (data->priority & FLAG_CMDLINE) continue;
2118 DLIST_REMOVE(lp_ctx->globals->param_opt, data);
2119 talloc_free(data);
2123 return 0;
2127 * Initialise the global parameter structure.
2129 * Note that most callers should use loadparm_init_global() instead
2131 struct loadparm_context *loadparm_init(TALLOC_CTX *mem_ctx)
2133 int i;
2134 char *myname;
2135 struct loadparm_context *lp_ctx;
2136 struct parmlist_entry *parm;
2137 char *logfile;
2139 lp_ctx = talloc_zero(mem_ctx, struct loadparm_context);
2140 if (lp_ctx == NULL)
2141 return NULL;
2143 talloc_set_destructor(lp_ctx, lpcfg_destructor);
2144 lp_ctx->bInGlobalSection = true;
2145 lp_ctx->globals = talloc_zero(lp_ctx, struct loadparm_global);
2146 /* This appears odd, but globals in s3 isn't a pointer */
2147 lp_ctx->globals->ctx = lp_ctx->globals;
2148 lp_ctx->sDefault = talloc_zero(lp_ctx, struct loadparm_service);
2149 lp_ctx->flags = talloc_zero_array(lp_ctx, unsigned int, num_parameters());
2151 lp_ctx->sDefault->iMaxPrintJobs = 1000;
2152 lp_ctx->sDefault->bAvailable = true;
2153 lp_ctx->sDefault->browseable = true;
2154 lp_ctx->sDefault->read_only = true;
2155 lp_ctx->sDefault->map_archive = true;
2156 lp_ctx->sDefault->strict_locking = true;
2157 lp_ctx->sDefault->oplocks = true;
2158 lp_ctx->sDefault->create_mask = 0744;
2159 lp_ctx->sDefault->force_create_mode = 0000;
2160 lp_ctx->sDefault->directory_mask = 0755;
2161 lp_ctx->sDefault->force_directory_mode = 0000;
2163 DEBUG(3, ("Initialising global parameters\n"));
2165 for (i = 0; parm_table[i].label; i++) {
2166 if ((parm_table[i].type == P_STRING ||
2167 parm_table[i].type == P_USTRING) &&
2168 !(lp_ctx->flags[i] & FLAG_CMDLINE)) {
2169 char **r;
2170 if (parm_table[i].p_class == P_LOCAL) {
2171 r = (char **)(((char *)lp_ctx->sDefault) + parm_table[i].offset);
2172 } else {
2173 r = (char **)(((char *)lp_ctx->globals) + parm_table[i].offset);
2175 *r = talloc_strdup(lp_ctx, "");
2179 logfile = talloc_asprintf(lp_ctx, "%s/log.samba", dyn_LOGFILEBASE);
2180 lpcfg_do_global_parameter(lp_ctx, "log file", logfile);
2181 talloc_free(logfile);
2183 lpcfg_do_global_parameter(lp_ctx, "log level", "0");
2185 lpcfg_do_global_parameter(lp_ctx, "syslog", "1");
2186 lpcfg_do_global_parameter(lp_ctx, "syslog only", "No");
2187 lpcfg_do_global_parameter(lp_ctx, "debug timestamp", "Yes");
2188 lpcfg_do_global_parameter(lp_ctx, "debug prefix timestamp", "No");
2189 lpcfg_do_global_parameter(lp_ctx, "debug hires timestamp", "Yes");
2190 lpcfg_do_global_parameter(lp_ctx, "debug pid", "No");
2191 lpcfg_do_global_parameter(lp_ctx, "debug uid", "No");
2192 lpcfg_do_global_parameter(lp_ctx, "debug class", "No");
2194 lpcfg_do_global_parameter(lp_ctx, "share backend", "classic");
2196 lpcfg_do_global_parameter(lp_ctx, "server role", "auto");
2197 lpcfg_do_global_parameter(lp_ctx, "domain logons", "No");
2198 lpcfg_do_global_parameter(lp_ctx, "domain master", "Auto");
2200 /* options that can be set on the command line must be initialised via
2201 the slower lpcfg_do_global_parameter() to ensure that FLAG_CMDLINE is obeyed */
2202 #ifdef TCP_NODELAY
2203 lpcfg_do_global_parameter(lp_ctx, "socket options", "TCP_NODELAY");
2204 #endif
2205 lpcfg_do_global_parameter(lp_ctx, "workgroup", DEFAULT_WORKGROUP);
2206 myname = get_myname(lp_ctx);
2207 lpcfg_do_global_parameter(lp_ctx, "netbios name", myname);
2208 talloc_free(myname);
2209 lpcfg_do_global_parameter(lp_ctx, "name resolve order", "lmhosts wins host bcast");
2211 lpcfg_do_global_parameter(lp_ctx, "fstype", "NTFS");
2213 lpcfg_do_global_parameter(lp_ctx, "ntvfs handler", "unixuid default");
2214 lpcfg_do_global_parameter(lp_ctx, "max connections", "0");
2216 lpcfg_do_global_parameter(lp_ctx, "dcerpc endpoint servers", "epmapper wkssvc rpcecho samr netlogon lsarpc spoolss drsuapi dssetup unixinfo browser eventlog6 backupkey dnsserver");
2217 lpcfg_do_global_parameter(lp_ctx, "server services", "s3fs rpc nbt wrepl ldap cldap kdc drepl winbind ntp_signd kcc dnsupdate dns");
2218 lpcfg_do_global_parameter(lp_ctx, "kccsrv:samba_kcc", "true");
2219 /* the winbind method for domain controllers is for both RODC
2220 auth forwarding and for trusted domains */
2221 lpcfg_do_global_parameter(lp_ctx, "private dir", dyn_PRIVATE_DIR);
2222 lpcfg_do_global_parameter(lp_ctx, "registry:HKEY_LOCAL_MACHINE", "hklm.ldb");
2224 /* This hive should be dynamically generated by Samba using
2225 data from the sam, but for the moment leave it in a tdb to
2226 keep regedt32 from popping up an annoying dialog. */
2227 lpcfg_do_global_parameter(lp_ctx, "registry:HKEY_USERS", "hku.ldb");
2229 /* using UTF8 by default allows us to support all chars */
2230 lpcfg_do_global_parameter(lp_ctx, "unix charset", "UTF-8");
2232 /* Use codepage 850 as a default for the dos character set */
2233 lpcfg_do_global_parameter(lp_ctx, "dos charset", "CP850");
2236 * Allow the default PASSWD_CHAT to be overridden in local.h.
2238 lpcfg_do_global_parameter(lp_ctx, "passwd chat", DEFAULT_PASSWD_CHAT);
2240 lpcfg_do_global_parameter(lp_ctx, "pid directory", dyn_PIDDIR);
2241 lpcfg_do_global_parameter(lp_ctx, "lock dir", dyn_LOCKDIR);
2242 lpcfg_do_global_parameter(lp_ctx, "state directory", dyn_STATEDIR);
2243 lpcfg_do_global_parameter(lp_ctx, "cache directory", dyn_CACHEDIR);
2244 lpcfg_do_global_parameter(lp_ctx, "ncalrpc dir", dyn_NCALRPCDIR);
2246 lpcfg_do_global_parameter(lp_ctx, "nbt client socket address", "0.0.0.0");
2247 lpcfg_do_global_parameter_var(lp_ctx, "server string",
2248 "Samba %s", SAMBA_VERSION_STRING);
2250 lpcfg_do_global_parameter(lp_ctx, "password server", "*");
2252 lpcfg_do_global_parameter(lp_ctx, "max mux", "50");
2253 lpcfg_do_global_parameter(lp_ctx, "max xmit", "16644");
2254 lpcfg_do_global_parameter(lp_ctx, "host msdfs", "true");
2256 lpcfg_do_global_parameter(lp_ctx, "LargeReadwrite", "True");
2257 lpcfg_do_global_parameter(lp_ctx, "server min protocol", "LANMAN1");
2258 lpcfg_do_global_parameter(lp_ctx, "server max protocol", "SMB3");
2259 lpcfg_do_global_parameter(lp_ctx, "client min protocol", "CORE");
2260 lpcfg_do_global_parameter(lp_ctx, "client max protocol", "NT1");
2261 lpcfg_do_global_parameter(lp_ctx, "security", "AUTO");
2262 lpcfg_do_global_parameter(lp_ctx, "EncryptPasswords", "True");
2263 lpcfg_do_global_parameter(lp_ctx, "ReadRaw", "True");
2264 lpcfg_do_global_parameter(lp_ctx, "WriteRaw", "True");
2265 lpcfg_do_global_parameter(lp_ctx, "NullPasswords", "False");
2266 lpcfg_do_global_parameter(lp_ctx, "old password allowed period", "60");
2267 lpcfg_do_global_parameter(lp_ctx, "ObeyPamRestrictions", "False");
2269 lpcfg_do_global_parameter(lp_ctx, "TimeServer", "False");
2270 lpcfg_do_global_parameter(lp_ctx, "BindInterfacesOnly", "False");
2271 lpcfg_do_global_parameter(lp_ctx, "Unicode", "True");
2272 lpcfg_do_global_parameter(lp_ctx, "ClientLanManAuth", "False");
2273 lpcfg_do_global_parameter(lp_ctx, "ClientNTLMv2Auth", "True");
2274 lpcfg_do_global_parameter(lp_ctx, "LanmanAuth", "False");
2275 lpcfg_do_global_parameter(lp_ctx, "NTLMAuth", "True");
2276 lpcfg_do_global_parameter(lp_ctx, "client use spnego principal", "False");
2278 lpcfg_do_global_parameter(lp_ctx, "UnixExtensions", "True");
2280 lpcfg_do_global_parameter(lp_ctx, "PreferredMaster", "Auto");
2281 lpcfg_do_global_parameter(lp_ctx, "LocalMaster", "True");
2283 lpcfg_do_global_parameter(lp_ctx, "wins support", "False");
2284 lpcfg_do_global_parameter(lp_ctx, "dns proxy", "True");
2286 lpcfg_do_global_parameter(lp_ctx, "winbind separator", "\\");
2287 lpcfg_do_global_parameter(lp_ctx, "winbind sealed pipes", "True");
2288 lpcfg_do_global_parameter(lp_ctx, "require strong key", "True");
2289 lpcfg_do_global_parameter(lp_ctx, "winbindd socket directory", dyn_WINBINDD_SOCKET_DIR);
2290 lpcfg_do_global_parameter(lp_ctx, "winbindd privileged socket directory", dyn_WINBINDD_PRIVILEGED_SOCKET_DIR);
2291 lpcfg_do_global_parameter(lp_ctx, "ntp signd socket directory", dyn_NTP_SIGND_SOCKET_DIR);
2292 lpcfg_do_global_parameter_var(lp_ctx, "dns update command", "%s/samba_dnsupdate", dyn_SCRIPTSBINDIR);
2293 lpcfg_do_global_parameter_var(lp_ctx, "spn update command", "%s/samba_spnupdate", dyn_SCRIPTSBINDIR);
2294 lpcfg_do_global_parameter_var(lp_ctx, "samba kcc command",
2295 "%s/samba_kcc", dyn_SCRIPTSBINDIR);
2296 lpcfg_do_global_parameter(lp_ctx, "template shell", "/bin/false");
2297 lpcfg_do_global_parameter(lp_ctx, "template homedir", "/home/%D/%U");
2299 lpcfg_do_global_parameter(lp_ctx, "client signing", "default");
2300 lpcfg_do_global_parameter(lp_ctx, "server signing", "default");
2302 lpcfg_do_global_parameter(lp_ctx, "use spnego", "True");
2304 lpcfg_do_global_parameter(lp_ctx, "use mmap", "True");
2306 lpcfg_do_global_parameter(lp_ctx, "smb ports", "445 139");
2307 lpcfg_do_global_parameter(lp_ctx, "nbt port", "137");
2308 lpcfg_do_global_parameter(lp_ctx, "dgram port", "138");
2309 lpcfg_do_global_parameter(lp_ctx, "cldap port", "389");
2310 lpcfg_do_global_parameter(lp_ctx, "krb5 port", "88");
2311 lpcfg_do_global_parameter(lp_ctx, "kpasswd port", "464");
2312 lpcfg_do_global_parameter(lp_ctx, "web port", "901");
2314 lpcfg_do_global_parameter(lp_ctx, "nt status support", "True");
2316 lpcfg_do_global_parameter(lp_ctx, "max wins ttl", "518400"); /* 6 days */
2317 lpcfg_do_global_parameter(lp_ctx, "min wins ttl", "21600");
2319 lpcfg_do_global_parameter(lp_ctx, "tls enabled", "True");
2320 lpcfg_do_global_parameter(lp_ctx, "tls keyfile", "tls/key.pem");
2321 lpcfg_do_global_parameter(lp_ctx, "tls certfile", "tls/cert.pem");
2322 lpcfg_do_global_parameter(lp_ctx, "tls cafile", "tls/ca.pem");
2323 lpcfg_do_global_parameter(lp_ctx, "prefork children:smb", "4");
2325 lpcfg_do_global_parameter(lp_ctx, "rndc command", "/usr/sbin/rndc");
2326 lpcfg_do_global_parameter(lp_ctx, "nsupdate command", "/usr/bin/nsupdate -g");
2328 lpcfg_do_global_parameter(lp_ctx, "allow dns updates", "secure only");
2329 lpcfg_do_global_parameter(lp_ctx, "dns forwarder", "");
2331 lpcfg_do_global_parameter(lp_ctx, "algorithmic rid base", "1000");
2333 lpcfg_do_global_parameter(lp_ctx, "enhanced browsing", "True");
2335 lpcfg_do_global_parameter(lp_ctx, "winbind nss info", "template");
2337 lpcfg_do_global_parameter(lp_ctx, "server schannel", "Auto");
2339 lpcfg_do_global_parameter(lp_ctx, "short preserve case", "True");
2341 lpcfg_do_global_parameter(lp_ctx, "max open files", "16384");
2343 lpcfg_do_global_parameter(lp_ctx, "cups connection timeout", "30");
2345 lpcfg_do_global_parameter(lp_ctx, "locking", "True");
2347 lpcfg_do_global_parameter(lp_ctx, "block size", "1024");
2349 lpcfg_do_global_parameter(lp_ctx, "client use spnego", "True");
2351 lpcfg_do_global_parameter(lp_ctx, "change notify", "True");
2353 lpcfg_do_global_parameter(lp_ctx, "name cache timeout", "660");
2355 lpcfg_do_global_parameter(lp_ctx, "defer sharing violations", "True");
2357 lpcfg_do_global_parameter(lp_ctx, "ldap replication sleep", "1000");
2359 lpcfg_do_global_parameter(lp_ctx, "idmap backend", "tdb");
2361 lpcfg_do_global_parameter(lp_ctx, "enable privileges", "True");
2363 lpcfg_do_global_parameter_var(lp_ctx, "smb2 max write", "%u", DEFAULT_SMB2_MAX_WRITE);
2365 lpcfg_do_global_parameter(lp_ctx, "passdb backend", "tdbsam");
2367 lpcfg_do_global_parameter(lp_ctx, "getwd cache", "True");
2369 lpcfg_do_global_parameter(lp_ctx, "winbind nested groups", "True");
2371 lpcfg_do_global_parameter(lp_ctx, "mangled names", "True");
2373 lpcfg_do_global_parameter_var(lp_ctx, "smb2 max credits", "%u", DEFAULT_SMB2_MAX_CREDITS);
2375 lpcfg_do_global_parameter(lp_ctx, "ldap ssl", "start tls");
2377 lpcfg_do_global_parameter(lp_ctx, "ldap deref", "auto");
2379 lpcfg_do_global_parameter(lp_ctx, "lm interval", "60");
2381 lpcfg_do_global_parameter(lp_ctx, "mangling method", "hash2");
2383 lpcfg_do_global_parameter(lp_ctx, "hide dot files", "True");
2385 lpcfg_do_global_parameter(lp_ctx, "browse list", "True");
2387 lpcfg_do_global_parameter(lp_ctx, "passwd chat timeout", "2");
2389 lpcfg_do_global_parameter(lp_ctx, "guest account", GUEST_ACCOUNT);
2391 lpcfg_do_global_parameter(lp_ctx, "client schannel", "auto");
2393 lpcfg_do_global_parameter(lp_ctx, "smb encrypt", "default");
2395 lpcfg_do_global_parameter(lp_ctx, "max log size", "5000");
2397 lpcfg_do_global_parameter(lp_ctx, "idmap negative cache time", "120");
2399 lpcfg_do_global_parameter(lp_ctx, "ldap follow referral", "auto");
2401 lpcfg_do_global_parameter(lp_ctx, "multicast dns register", "yes");
2403 lpcfg_do_global_parameter(lp_ctx, "winbind reconnect delay", "30");
2405 lpcfg_do_global_parameter(lp_ctx, "nt acl support", "yes");
2407 lpcfg_do_global_parameter(lp_ctx, "acl check permissions", "yes");
2409 lpcfg_do_global_parameter(lp_ctx, "keepalive", "300");
2411 lpcfg_do_global_parameter(lp_ctx, "winbind cache time", "300");
2413 lpcfg_do_global_parameter(lp_ctx, "level2 oplocks", "yes");
2415 lpcfg_do_global_parameter(lp_ctx, "show add printer wizard", "yes");
2417 lpcfg_do_global_parameter(lp_ctx, "allocation roundup size", "1048576");
2419 lpcfg_do_global_parameter(lp_ctx, "ldap page size", "1024");
2421 lpcfg_do_global_parameter(lp_ctx, "kernel share modes", "yes");
2423 lpcfg_do_global_parameter(lp_ctx, "strict locking", "Auto");
2425 lpcfg_do_global_parameter(lp_ctx, "map readonly", "yes");
2427 lpcfg_do_global_parameter(lp_ctx, "allow trusted domains", "yes");
2429 lpcfg_do_global_parameter(lp_ctx, "default devmode", "yes");
2431 lpcfg_do_global_parameter(lp_ctx, "os level", "20");
2433 lpcfg_do_global_parameter(lp_ctx, "dos filetimes", "yes");
2435 lpcfg_do_global_parameter(lp_ctx, "mangling char", "~");
2437 lpcfg_do_global_parameter(lp_ctx, "printcap cache time", "750");
2439 lpcfg_do_global_parameter(lp_ctx, "create krb5 conf", "yes");
2441 lpcfg_do_global_parameter(lp_ctx, "winbind max clients", "200");
2443 lpcfg_do_global_parameter(lp_ctx, "acl map full control", "yes");
2445 lpcfg_do_global_parameter(lp_ctx, "nt pipe support", "yes");
2447 lpcfg_do_global_parameter(lp_ctx, "ldap debug threshold", "10");
2449 lpcfg_do_global_parameter(lp_ctx, "follow symlinks", "yes");
2451 lpcfg_do_global_parameter(lp_ctx, "machine password timeout", "604800");
2453 lpcfg_do_global_parameter(lp_ctx, "ldap connection timeout", "2");
2455 lpcfg_do_global_parameter(lp_ctx, "winbind expand groups", "1");
2457 lpcfg_do_global_parameter(lp_ctx, "stat cache", "yes");
2459 lpcfg_do_global_parameter(lp_ctx, "lpq cache time", "30");
2461 lpcfg_do_global_parameter_var(lp_ctx, "smb2 max trans", "%u", DEFAULT_SMB2_MAX_TRANSACT);
2463 lpcfg_do_global_parameter_var(lp_ctx, "smb2 max read", "%u", DEFAULT_SMB2_MAX_READ);
2465 lpcfg_do_global_parameter(lp_ctx, "durable handles", "yes");
2467 lpcfg_do_global_parameter(lp_ctx, "max stat cache size", "256");
2469 lpcfg_do_global_parameter(lp_ctx, "ldap passwd sync", "no");
2471 lpcfg_do_global_parameter(lp_ctx, "kernel change notify", "yes");
2473 lpcfg_do_global_parameter(lp_ctx, "max ttl", "259200");
2475 lpcfg_do_global_parameter(lp_ctx, "blocking locks", "yes");
2477 lpcfg_do_global_parameter(lp_ctx, "oplock contention limit", "2");
2479 lpcfg_do_global_parameter(lp_ctx, "load printers", "yes");
2481 lpcfg_do_global_parameter(lp_ctx, "idmap cache time", "604800");
2483 lpcfg_do_global_parameter(lp_ctx, "preserve case", "yes");
2485 lpcfg_do_global_parameter(lp_ctx, "lm announce", "auto");
2487 lpcfg_do_global_parameter(lp_ctx, "afs token lifetime", "604800");
2489 lpcfg_do_global_parameter(lp_ctx, "enable core files", "yes");
2491 lpcfg_do_global_parameter(lp_ctx, "winbind max domain connections", "1");
2493 lpcfg_do_global_parameter(lp_ctx, "case sensitive", "auto");
2495 lpcfg_do_global_parameter(lp_ctx, "ldap timeout", "15");
2497 lpcfg_do_global_parameter(lp_ctx, "mangle prefix", "1");
2499 lpcfg_do_global_parameter(lp_ctx, "posix locking", "yes");
2501 lpcfg_do_global_parameter(lp_ctx, "lock spin time", "200");
2503 lpcfg_do_global_parameter(lp_ctx, "directory name cache size", "100");
2505 lpcfg_do_global_parameter(lp_ctx, "nmbd bind explicit broadcast", "yes");
2507 lpcfg_do_global_parameter(lp_ctx, "init logon delay", "100");
2509 lpcfg_do_global_parameter(lp_ctx, "usershare owner only", "yes");
2511 lpcfg_do_global_parameter(lp_ctx, "-valid", "yes");
2513 lpcfg_do_global_parameter_var(lp_ctx, "usershare path", "%s/usershares", get_dyn_STATEDIR());
2515 #ifdef DEVELOPER
2516 lpcfg_do_global_parameter_var(lp_ctx, "panic action", "/bin/sleep 999999999");
2517 #endif
2519 lpcfg_do_global_parameter(lp_ctx, "smb passwd file", get_dyn_SMB_PASSWD_FILE());
2521 lpcfg_do_global_parameter(lp_ctx, "logon home", "\\\\%N\\%U");
2523 lpcfg_do_global_parameter(lp_ctx, "logon path", "\\\\%N\\%U\\profile");
2525 lpcfg_do_global_parameter(lp_ctx, "printjob username", "%U");
2527 for (i = 0; parm_table[i].label; i++) {
2528 if (!(lp_ctx->flags[i] & FLAG_CMDLINE)) {
2529 lp_ctx->flags[i] |= FLAG_DEFAULT;
2533 for (parm=lp_ctx->globals->param_opt; parm; parm=parm->next) {
2534 if (!(parm->priority & FLAG_CMDLINE)) {
2535 parm->priority |= FLAG_DEFAULT;
2539 return lp_ctx;
2543 * Initialise the global parameter structure.
2545 struct loadparm_context *loadparm_init_global(bool load_default)
2547 if (global_loadparm_context == NULL) {
2548 global_loadparm_context = loadparm_init(NULL);
2550 if (global_loadparm_context == NULL) {
2551 return NULL;
2553 global_loadparm_context->global = true;
2554 if (load_default && !global_loadparm_context->loaded) {
2555 lpcfg_load_default(global_loadparm_context);
2557 global_loadparm_context->refuse_free = true;
2558 return global_loadparm_context;
2562 * Initialise the global parameter structure.
2564 struct loadparm_context *loadparm_init_s3(TALLOC_CTX *mem_ctx,
2565 const struct loadparm_s3_helpers *s3_fns)
2567 struct loadparm_context *loadparm_context = talloc_zero(mem_ctx, struct loadparm_context);
2568 if (!loadparm_context) {
2569 return NULL;
2571 loadparm_context->s3_fns = s3_fns;
2572 loadparm_context->globals = s3_fns->globals;
2573 return loadparm_context;
2576 const char *lpcfg_configfile(struct loadparm_context *lp_ctx)
2578 return lp_ctx->szConfigFile;
2581 const char *lp_default_path(void)
2583 if (getenv("SMB_CONF_PATH"))
2584 return getenv("SMB_CONF_PATH");
2585 else
2586 return dyn_CONFIGFILE;
2590 * Update the internal state of a loadparm context after settings
2591 * have changed.
2593 static bool lpcfg_update(struct loadparm_context *lp_ctx)
2595 struct debug_settings settings;
2596 TALLOC_CTX *tmp_ctx;
2598 tmp_ctx = talloc_new(lp_ctx);
2599 if (tmp_ctx == NULL) {
2600 return false;
2603 lpcfg_add_auto_services(lp_ctx, lpcfg_auto_services(lp_ctx, tmp_ctx));
2605 if (!lp_ctx->globals->wins_server_list && lp_ctx->globals->we_are_a_wins_server) {
2606 lpcfg_do_global_parameter(lp_ctx, "wins server", "127.0.0.1");
2609 if (!lp_ctx->global) {
2610 TALLOC_FREE(tmp_ctx);
2611 return true;
2614 panic_action = lp_ctx->globals->panic_action;
2616 reload_charcnv(lp_ctx);
2618 ZERO_STRUCT(settings);
2619 /* Add any more debug-related smb.conf parameters created in
2620 * future here */
2621 settings.syslog = lp_ctx->globals->syslog;
2622 settings.syslog_only = lp_ctx->globals->syslog_only;
2623 settings.timestamp_logs = lp_ctx->globals->timestamp_logs;
2624 settings.debug_prefix_timestamp = lp_ctx->globals->debug_prefix_timestamp;
2625 settings.debug_hires_timestamp = lp_ctx->globals->debug_hires_timestamp;
2626 settings.debug_pid = lp_ctx->globals->debug_pid;
2627 settings.debug_uid = lp_ctx->globals->debug_uid;
2628 settings.debug_class = lp_ctx->globals->debug_class;
2629 debug_set_settings(&settings);
2631 /* FIXME: This is a bit of a hack, but we can't use a global, since
2632 * not everything that uses lp also uses the socket library */
2633 if (lpcfg_parm_bool(lp_ctx, NULL, "socket", "testnonblock", false)) {
2634 setenv("SOCKET_TESTNONBLOCK", "1", 1);
2635 } else {
2636 unsetenv("SOCKET_TESTNONBLOCK");
2639 TALLOC_FREE(tmp_ctx);
2640 return true;
2643 bool lpcfg_load_default(struct loadparm_context *lp_ctx)
2645 const char *path;
2647 path = lp_default_path();
2649 if (!file_exist(path)) {
2650 /* We allow the default smb.conf file to not exist,
2651 * basically the equivalent of an empty file. */
2652 return lpcfg_update(lp_ctx);
2655 return lpcfg_load(lp_ctx, path);
2659 * Load the services array from the services file.
2661 * Return True on success, False on failure.
2663 bool lpcfg_load(struct loadparm_context *lp_ctx, const char *filename)
2665 char *n2;
2666 bool bRetval;
2668 filename = talloc_strdup(lp_ctx, filename);
2670 lp_ctx->szConfigFile = filename;
2672 if (lp_ctx->s3_fns) {
2673 return lp_ctx->s3_fns->load(filename);
2676 lp_ctx->bInGlobalSection = true;
2677 n2 = standard_sub_basic(lp_ctx, lp_ctx->szConfigFile);
2678 DEBUG(2, ("lpcfg_load: refreshing parameters from %s\n", n2));
2680 add_to_file_list(lp_ctx, &lp_ctx->file_lists, lp_ctx->szConfigFile, n2);
2682 /* We get sections first, so have to start 'behind' to make up */
2683 lp_ctx->currentService = NULL;
2684 bRetval = pm_process(n2, do_section, do_parameter, lp_ctx);
2686 /* finish up the last section */
2687 DEBUG(4, ("pm_process() returned %s\n", BOOLSTR(bRetval)));
2688 if (bRetval)
2689 if (lp_ctx->currentService != NULL)
2690 bRetval = lpcfg_service_ok(lp_ctx->currentService);
2692 bRetval = bRetval && lpcfg_update(lp_ctx);
2694 /* we do this unconditionally, so that it happens even
2695 for a missing smb.conf */
2696 reload_charcnv(lp_ctx);
2698 if (bRetval == true) {
2699 /* set this up so that any child python tasks will
2700 find the right smb.conf */
2701 setenv("SMB_CONF_PATH", filename, 1);
2703 /* set the context used by the lp_*() function
2704 varients */
2705 global_loadparm_context = lp_ctx;
2706 lp_ctx->loaded = true;
2709 return bRetval;
2713 * Return the max number of services.
2716 int lpcfg_numservices(struct loadparm_context *lp_ctx)
2718 if (lp_ctx->s3_fns) {
2719 return lp_ctx->s3_fns->get_numservices();
2722 return lp_ctx->iNumServices;
2726 * Display the contents of the services array in human-readable form.
2729 void lpcfg_dump(struct loadparm_context *lp_ctx, FILE *f, bool show_defaults,
2730 int maxtoprint)
2732 int iService;
2734 if (lp_ctx->s3_fns) {
2735 lp_ctx->s3_fns->dump(f, show_defaults, maxtoprint);
2736 return;
2739 dump_globals(lp_ctx, f, show_defaults);
2741 lpcfg_dump_a_service(lp_ctx->sDefault, lp_ctx->sDefault, f, lp_ctx->flags, show_defaults);
2743 for (iService = 0; iService < maxtoprint; iService++)
2744 lpcfg_dump_one(f, show_defaults, lp_ctx->services[iService], lp_ctx->sDefault);
2748 * Display the contents of one service in human-readable form.
2750 void lpcfg_dump_one(FILE *f, bool show_defaults, struct loadparm_service *service, struct loadparm_service *sDefault)
2752 if (service != NULL) {
2753 if (service->szService[0] == '\0')
2754 return;
2755 lpcfg_dump_a_service(service, sDefault, f, NULL, show_defaults);
2759 struct loadparm_service *lpcfg_servicebynum(struct loadparm_context *lp_ctx,
2760 int snum)
2762 if (lp_ctx->s3_fns) {
2763 return lp_ctx->s3_fns->get_servicebynum(snum);
2766 return lp_ctx->services[snum];
2769 struct loadparm_service *lpcfg_service(struct loadparm_context *lp_ctx,
2770 const char *service_name)
2772 int iService;
2773 char *serviceName;
2775 if (lp_ctx->s3_fns) {
2776 return lp_ctx->s3_fns->get_service(service_name);
2779 for (iService = lp_ctx->iNumServices - 1; iService >= 0; iService--) {
2780 if (lp_ctx->services[iService] &&
2781 lp_ctx->services[iService]->szService) {
2783 * The substitution here is used to support %U is
2784 * service names
2786 serviceName = standard_sub_basic(
2787 lp_ctx->services[iService],
2788 lp_ctx->services[iService]->szService);
2789 if (strequal(serviceName, service_name)) {
2790 talloc_free(serviceName);
2791 return lp_ctx->services[iService];
2793 talloc_free(serviceName);
2797 DEBUG(7,("lpcfg_servicenumber: couldn't find %s\n", service_name));
2798 return NULL;
2801 const char *lpcfg_servicename(const struct loadparm_service *service)
2803 return lpcfg_string((const char *)service->szService);
2807 * A useful volume label function.
2809 const char *lpcfg_volume_label(struct loadparm_service *service, struct loadparm_service *sDefault)
2811 const char *ret;
2812 ret = lpcfg_string((const char *)((service != NULL && service->volume != NULL) ?
2813 service->volume : sDefault->volume));
2814 if (!*ret)
2815 return lpcfg_servicename(service);
2816 return ret;
2820 * Return the correct printer name.
2822 const char *lpcfg_printername(struct loadparm_service *service, struct loadparm_service *sDefault)
2824 const char *ret;
2825 ret = lpcfg_string((const char *)((service != NULL && service->_printername != NULL) ?
2826 service->_printername : sDefault->_printername));
2827 if (ret == NULL || (ret != NULL && *ret == '\0'))
2828 ret = lpcfg_servicename(service);
2830 return ret;
2835 * Return the max print jobs per queue.
2837 int lpcfg_maxprintjobs(struct loadparm_service *service, struct loadparm_service *sDefault)
2839 int maxjobs = (service != NULL) ? service->iMaxPrintJobs : sDefault->iMaxPrintJobs;
2840 if (maxjobs <= 0 || maxjobs >= PRINT_MAX_JOBID)
2841 maxjobs = PRINT_MAX_JOBID - 1;
2843 return maxjobs;
2846 struct smb_iconv_handle *lpcfg_iconv_handle(struct loadparm_context *lp_ctx)
2848 if (lp_ctx == NULL) {
2849 return get_iconv_handle();
2851 return lp_ctx->iconv_handle;
2854 _PUBLIC_ void reload_charcnv(struct loadparm_context *lp_ctx)
2856 struct smb_iconv_handle *old_ic = lp_ctx->iconv_handle;
2857 if (!lp_ctx->global) {
2858 return;
2861 if (old_ic == NULL) {
2862 old_ic = global_iconv_handle;
2864 lp_ctx->iconv_handle = smb_iconv_handle_reinit_lp(lp_ctx, lp_ctx, old_ic);
2865 global_iconv_handle = lp_ctx->iconv_handle;
2868 _PUBLIC_ char *lpcfg_tls_keyfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
2870 return lpcfg_private_path(mem_ctx, lp_ctx, lpcfg__tls_keyfile(lp_ctx));
2873 _PUBLIC_ char *lpcfg_tls_certfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
2875 return lpcfg_private_path(mem_ctx, lp_ctx, lpcfg__tls_certfile(lp_ctx));
2878 _PUBLIC_ char *lpcfg_tls_cafile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
2880 return lpcfg_private_path(mem_ctx, lp_ctx, lpcfg__tls_cafile(lp_ctx));
2883 _PUBLIC_ char *lpcfg_tls_crlfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
2885 return lpcfg_private_path(mem_ctx, lp_ctx, lpcfg__tls_crlfile(lp_ctx));
2888 _PUBLIC_ char *lpcfg_tls_dhpfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
2890 return lpcfg_private_path(mem_ctx, lp_ctx, lpcfg__tls_dhpfile(lp_ctx));
2893 struct gensec_settings *lpcfg_gensec_settings(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
2895 struct gensec_settings *settings = talloc_zero(mem_ctx, struct gensec_settings);
2896 if (settings == NULL)
2897 return NULL;
2898 SMB_ASSERT(lp_ctx != NULL);
2899 settings->lp_ctx = talloc_reference(settings, lp_ctx);
2900 settings->target_hostname = lpcfg_parm_string(lp_ctx, NULL, "gensec", "target_hostname");
2901 return settings;
2904 int lpcfg_server_role(struct loadparm_context *lp_ctx)
2906 int domain_master = lpcfg__domain_master(lp_ctx);
2908 return lp_find_server_role(lpcfg__server_role(lp_ctx),
2909 lpcfg__security(lp_ctx),
2910 lpcfg__domain_logons(lp_ctx),
2911 (domain_master == true) ||
2912 (domain_master == Auto));
2915 int lpcfg_security(struct loadparm_context *lp_ctx)
2917 return lp_find_security(lpcfg__server_role(lp_ctx),
2918 lpcfg__security(lp_ctx));
2921 bool lpcfg_server_signing_allowed(struct loadparm_context *lp_ctx, bool *mandatory)
2923 bool allowed = true;
2924 enum smb_signing_setting signing_setting = lpcfg_server_signing(lp_ctx);
2926 *mandatory = false;
2928 if (signing_setting == SMB_SIGNING_DEFAULT) {
2930 * If we are a domain controller, SMB signing is
2931 * really important, as it can prevent a number of
2932 * attacks on communications between us and the
2933 * clients
2935 * However, it really sucks (no sendfile, CPU
2936 * overhead) performance-wise when used on a
2937 * file server, so disable it by default
2938 * on non-DCs
2941 if (lpcfg_server_role(lp_ctx) >= ROLE_ACTIVE_DIRECTORY_DC) {
2942 signing_setting = SMB_SIGNING_REQUIRED;
2943 } else {
2944 signing_setting = SMB_SIGNING_OFF;
2948 switch (signing_setting) {
2949 case SMB_SIGNING_REQUIRED:
2950 *mandatory = true;
2951 break;
2952 case SMB_SIGNING_IF_REQUIRED:
2953 break;
2954 case SMB_SIGNING_DEFAULT:
2955 case SMB_SIGNING_OFF:
2956 allowed = false;
2957 break;
2960 return allowed;
2963 int lpcfg_tdb_hash_size(struct loadparm_context *lp_ctx, const char *name)
2965 const char *base;
2967 if (name == NULL) {
2968 return 0;
2971 base = strrchr_m(name, '/');
2972 if (base != NULL) {
2973 base += 1;
2974 } else {
2975 base = name;
2977 return lpcfg_parm_int(lp_ctx, NULL, "tdb_hashsize", base, 0);
2981 int lpcfg_tdb_flags(struct loadparm_context *lp_ctx, int tdb_flags)
2983 if (!lpcfg_use_mmap(lp_ctx)) {
2984 tdb_flags |= TDB_NOMMAP;
2986 return tdb_flags;