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/>.
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.
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
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
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"
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
83 #define handle_netbios_aliases NULL
84 #define handle_printing NULL
85 #define handle_ldap_debug_level NULL
86 #define handle_idmap_backend NULL
87 #define handle_idmap_uid NULL
88 #define handle_idmap_gid NULL
94 #include "lib/param/param_table.c"
97 struct loadparm_context {
98 const char *szConfigFile;
99 struct loadparm_global *globals;
100 struct loadparm_service **services;
101 struct loadparm_service *sDefault;
102 struct smb_iconv_handle *iconv_handle;
104 struct loadparm_service *currentService;
105 bool bInGlobalSection;
106 struct file_lists *file_lists;
107 unsigned int flags[NUMPARAMETERS];
110 bool global; /* Is this the global context, which may set
111 * global variables such as debug level etc? */
112 const struct loadparm_s3_helpers *s3_fns;
116 struct loadparm_service *lpcfg_default_service(struct loadparm_context *lp_ctx)
118 if (lp_ctx->s3_fns) {
119 return lp_ctx->s3_fns->get_default_loadparm_service();
121 return lp_ctx->sDefault;
125 * Convenience routine to grab string parameters into temporary memory
126 * and run standard_sub_basic on them.
128 * The buffers can be written to by
129 * callers without affecting the source string.
132 static const char *lpcfg_string(const char *s)
134 #if 0 /* until REWRITE done to make thread-safe */
135 size_t len = s ? strlen(s) : 0;
139 /* The follow debug is useful for tracking down memory problems
140 especially if you have an inner loop that is calling a lp_*()
141 function that returns a string. Perhaps this debug should be
142 present all the time? */
145 DEBUG(10, ("lpcfg_string(%s)\n", s));
148 #if 0 /* until REWRITE done to make thread-safe */
150 lp_talloc = talloc_init("lp_talloc");
152 ret = talloc_array(lp_talloc, char, len + 100); /* leave room for substitution */
160 strlcpy(ret, s, len);
162 if (trim_string(ret, "\"", "\"")) {
163 if (strchr(ret,'"') != NULL)
164 strlcpy(ret, s, len);
167 standard_sub_basic(ret,len+100);
174 In this section all the functions that are used to access the
175 parameters from the rest of the program are defined
179 * the creation of separate lpcfg_*() and lp_*() functions is to allow
180 * for code compatibility between existing Samba4 and Samba3 code.
183 /* this global context supports the lp_*() function varients */
184 static struct loadparm_context *global_loadparm_context;
186 #define lpcfg_default_service global_loadparm_context->sDefault
187 #define lpcfg_global_service(i) global_loadparm_context->services[i]
189 #define FN_GLOBAL_STRING(fn_name,var_name) \
190 _PUBLIC_ char *lpcfg_ ## fn_name(struct loadparm_context *lp_ctx, TALLOC_CTX *ctx) {\
191 if (lp_ctx == NULL) return NULL; \
192 if (lp_ctx->s3_fns) { \
193 return lp_ctx->globals->var_name ? lp_ctx->s3_fns->lp_string(ctx, lp_ctx->globals->var_name) : talloc_strdup(ctx, ""); \
195 return lp_ctx->globals->var_name ? talloc_strdup(ctx, lpcfg_string(lp_ctx->globals->var_name)) : talloc_strdup(ctx, ""); \
198 #define FN_GLOBAL_CONST_STRING(fn_name,var_name) \
199 _PUBLIC_ const char *lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) { \
200 if (lp_ctx == NULL) return NULL; \
201 return lp_ctx->globals->var_name ? lpcfg_string(lp_ctx->globals->var_name) : ""; \
204 #define FN_GLOBAL_LIST(fn_name,var_name) \
205 _PUBLIC_ const char **lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) { \
206 if (lp_ctx == NULL) return NULL; \
207 return lp_ctx->globals->var_name; \
210 #define FN_GLOBAL_BOOL(fn_name,var_name) \
211 _PUBLIC_ bool lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) {\
212 if (lp_ctx == NULL) return false; \
213 return lp_ctx->globals->var_name; \
216 #define FN_GLOBAL_INTEGER(fn_name,var_name) \
217 _PUBLIC_ int lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) { \
218 return lp_ctx->globals->var_name; \
221 /* Local parameters don't need the ->s3_fns because the struct
222 * loadparm_service is shared and lpcfg_service() checks the ->s3_fns
224 #define FN_LOCAL_STRING(fn_name,val) \
225 _PUBLIC_ char *lpcfg_ ## fn_name(struct loadparm_service *service, \
226 struct loadparm_service *sDefault, TALLOC_CTX *ctx) { \
227 return(talloc_strdup(ctx, lpcfg_string((const char *)((service != NULL && service->val != NULL) ? service->val : sDefault->val)))); \
230 #define FN_LOCAL_CONST_STRING(fn_name,val) \
231 _PUBLIC_ const char *lpcfg_ ## fn_name(struct loadparm_service *service, \
232 struct loadparm_service *sDefault) { \
233 return((const char *)((service != NULL && service->val != NULL) ? service->val : sDefault->val)); \
236 #define FN_LOCAL_LIST(fn_name,val) \
237 _PUBLIC_ const char **lpcfg_ ## fn_name(struct loadparm_service *service, \
238 struct loadparm_service *sDefault) {\
239 return(const char **)(service != NULL && service->val != NULL? service->val : sDefault->val); \
242 #define FN_LOCAL_PARM_BOOL(fn_name, val) FN_LOCAL_BOOL(fn_name, val)
244 #define FN_LOCAL_BOOL(fn_name,val) \
245 _PUBLIC_ bool lpcfg_ ## fn_name(struct loadparm_service *service, \
246 struct loadparm_service *sDefault) { \
247 return((service != NULL)? service->val : sDefault->val); \
250 #define FN_LOCAL_INTEGER(fn_name,val) \
251 _PUBLIC_ int lpcfg_ ## fn_name(struct loadparm_service *service, \
252 struct loadparm_service *sDefault) { \
253 return((service != NULL)? service->val : sDefault->val); \
256 #define FN_LOCAL_PARM_INTEGER(fn_name, val) FN_LOCAL_INTEGER(fn_name, val)
258 #define FN_LOCAL_PARM_CHAR(fn_name,val) \
259 _PUBLIC_ char lpcfg_ ## fn_name(struct loadparm_service *service, \
260 struct loadparm_service *sDefault) { \
261 return((service != NULL)? service->val : sDefault->val); \
264 #include "lib/param/param_functions.c"
266 /* These functions cannot be auto-generated */
267 FN_LOCAL_BOOL(autoloaded, autoloaded)
268 FN_GLOBAL_CONST_STRING(dnsdomain, dnsdomain)
270 /* local prototypes */
271 static struct loadparm_service *lpcfg_getservicebyname(struct loadparm_context *lp_ctx,
272 const char *pszServiceName);
273 static bool lpcfg_service_ok(struct loadparm_service *service);
274 static bool do_section(const char *pszSectionName, void *);
276 /* This is a helper function for parametrical options support. */
277 /* It returns a pointer to parametrical option value if it exists or NULL otherwise */
278 /* Actual parametrical functions are quite simple */
279 const char *lpcfg_get_parametric(struct loadparm_context *lp_ctx,
280 struct loadparm_service *service,
281 const char *type, const char *option)
283 char *vfskey_tmp = NULL;
285 struct parmlist_entry *data;
290 if (lp_ctx->s3_fns) {
291 return lp_ctx->s3_fns->get_parametric(service, type, option);
294 data = (service == NULL ? lp_ctx->globals->param_opt : service->param_opt);
296 vfskey_tmp = talloc_asprintf(NULL, "%s:%s", type, option);
297 if (vfskey_tmp == NULL) return NULL;
298 vfskey = strlower_talloc(NULL, vfskey_tmp);
299 talloc_free(vfskey_tmp);
302 if (strcmp(data->key, vfskey) == 0) {
309 if (service != NULL) {
310 /* Try to fetch the same option but from globals */
311 /* but only if we are not already working with globals */
312 for (data = lp_ctx->globals->param_opt; data;
314 if (strcmp(data->key, vfskey) == 0) {
328 * convenience routine to return int parameters.
330 int lp_int(const char *s)
334 DEBUG(0,("lp_int(%s): is called with NULL!\n",s));
338 return strtol(s, NULL, 0);
342 * convenience routine to return unsigned long parameters.
344 unsigned long lp_ulong(const char *s)
348 DEBUG(0,("lp_ulong(%s): is called with NULL!\n",s));
352 return strtoul(s, NULL, 0);
356 * convenience routine to return unsigned long parameters.
358 static long lp_long(const char *s)
362 DEBUG(0,("lp_long(%s): is called with NULL!\n",s));
366 return strtol(s, NULL, 0);
370 * convenience routine to return unsigned long parameters.
372 static double lp_double(const char *s)
376 DEBUG(0,("lp_double(%s): is called with NULL!\n",s));
380 return strtod(s, NULL);
384 * convenience routine to return boolean parameters.
386 bool lp_bool(const char *s)
391 DEBUG(0,("lp_bool(%s): is called with NULL!\n",s));
395 if (!set_boolean(s, &ret)) {
396 DEBUG(0,("lp_bool(%s): value is not boolean!\n",s));
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(struct loadparm_context *lp_ctx,
410 struct loadparm_service *service, const char *type,
413 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
416 return lpcfg_string(value);
422 * Return parametric option from a given service. Type is a part of option before ':'
423 * Parametric option has following syntax: 'Type: option = value'
424 * Returned value is allocated in 'lp_talloc' context
427 const char **lpcfg_parm_string_list(TALLOC_CTX *mem_ctx,
428 struct loadparm_context *lp_ctx,
429 struct loadparm_service *service,
431 const char *option, const char *separator)
433 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
436 return (const char **)str_list_make(mem_ctx, value, separator);
442 * Return parametric option from a given service. Type is a part of option before ':'
443 * Parametric option has following syntax: 'Type: option = value'
446 int lpcfg_parm_int(struct loadparm_context *lp_ctx,
447 struct loadparm_service *service, const char *type,
448 const char *option, int default_v)
450 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
453 return lp_int(value);
459 * Return parametric option from a given service. Type is a part of
461 * Parametric option has following syntax: 'Type: option = value'.
464 int lpcfg_parm_bytes(struct loadparm_context *lp_ctx,
465 struct loadparm_service *service, const char *type,
466 const char *option, int default_v)
470 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
472 if (value && conv_str_size_error(value, &bval)) {
473 if (bval <= INT_MAX) {
482 * Return parametric option from a given service.
483 * Type is a part of option before ':'
484 * Parametric option has following syntax: 'Type: option = value'
486 unsigned long lpcfg_parm_ulong(struct loadparm_context *lp_ctx,
487 struct loadparm_service *service, const char *type,
488 const char *option, unsigned long default_v)
490 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
493 return lp_ulong(value);
498 long lpcfg_parm_long(struct loadparm_context *lp_ctx,
499 struct loadparm_service *service, const char *type,
500 const char *option, long default_v)
502 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
505 return lp_long(value);
510 double lpcfg_parm_double(struct loadparm_context *lp_ctx,
511 struct loadparm_service *service, const char *type,
512 const char *option, double default_v)
514 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
517 return lp_double(value);
523 * Return parametric option from a given service. Type is a part of option before ':'
524 * Parametric option has following syntax: 'Type: option = value'
527 bool lpcfg_parm_bool(struct loadparm_context *lp_ctx,
528 struct loadparm_service *service, const char *type,
529 const char *option, bool default_v)
531 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
534 return lp_bool(value);
541 * Set a string value, deallocating any existing space, and allocing the space
544 bool lpcfg_string_set(TALLOC_CTX *mem_ctx, char **dest, const char *src)
551 *dest = talloc_strdup(mem_ctx, src);
552 if ((*dest) == NULL) {
553 DEBUG(0,("Out of memory in string_set\n"));
561 * Set a string value, deallocating any existing space, and allocing the space
564 static bool lpcfg_string_set_upper(TALLOC_CTX *mem_ctx, char **dest, const char *src)
571 *dest = strupper_talloc(mem_ctx, src);
572 if ((*dest) == NULL) {
573 DEBUG(0,("Out of memory in string_set_upper\n"));
583 * Add a new service to the services array initialising it with the given
587 struct loadparm_service *lpcfg_add_service(struct loadparm_context *lp_ctx,
588 const struct loadparm_service *pservice,
592 int num_to_alloc = lp_ctx->iNumServices + 1;
593 struct parmlist_entry *data, *pdata;
595 if (pservice == NULL) {
596 pservice = lp_ctx->sDefault;
599 /* it might already exist */
601 struct loadparm_service *service = lpcfg_getservicebyname(lp_ctx,
603 if (service != NULL) {
604 /* Clean all parametric options for service */
605 /* They will be added during parsing again */
606 data = service->param_opt;
612 service->param_opt = NULL;
617 /* find an invalid one */
618 for (i = 0; i < lp_ctx->iNumServices; i++)
619 if (lp_ctx->services[i] == NULL)
622 /* if not, then create one */
623 if (i == lp_ctx->iNumServices) {
624 struct loadparm_service **tsp;
626 tsp = talloc_realloc(lp_ctx, lp_ctx->services, struct loadparm_service *, num_to_alloc);
629 DEBUG(0,("lpcfg_add_service: failed to enlarge services!\n"));
632 lp_ctx->services = tsp;
633 lp_ctx->services[lp_ctx->iNumServices] = NULL;
636 lp_ctx->iNumServices++;
639 lp_ctx->services[i] = talloc_zero(lp_ctx->services, struct loadparm_service);
640 if (lp_ctx->services[i] == NULL) {
641 DEBUG(0,("lpcfg_add_service: out of memory!\n"));
644 copy_service(lp_ctx->services[i], pservice, NULL);
646 lpcfg_string_set(lp_ctx->services[i], &lp_ctx->services[i]->szService, name);
647 return lp_ctx->services[i];
651 * Add a new home service, with the specified home directory, defaults coming
652 * from service ifrom.
655 bool lpcfg_add_home(struct loadparm_context *lp_ctx,
656 const char *pszHomename,
657 struct loadparm_service *default_service,
658 const char *user, const char *pszHomedir)
660 struct loadparm_service *service;
662 service = lpcfg_add_service(lp_ctx, default_service, pszHomename);
667 if (!(*(default_service->path))
668 || strequal(default_service->path, lp_ctx->sDefault->path)) {
669 service->path = talloc_strdup(service, pszHomedir);
671 service->path = string_sub_talloc(service, lpcfg_path(default_service, lp_ctx->sDefault, service), "%H", pszHomedir);
674 if (!(*(service->comment))) {
675 service->comment = talloc_asprintf(service, "Home directory of %s", user);
677 service->bAvailable = default_service->bAvailable;
678 service->browseable = default_service->browseable;
680 DEBUG(3, ("adding home's share [%s] for user '%s' at '%s'\n",
681 pszHomename, user, service->path));
687 * Add a new printer service, with defaults coming from service iFrom.
690 bool lpcfg_add_printer(struct loadparm_context *lp_ctx,
691 const char *pszPrintername,
692 struct loadparm_service *default_service)
694 const char *comment = "From Printcap";
695 struct loadparm_service *service;
696 service = lpcfg_add_service(lp_ctx, default_service, pszPrintername);
701 /* note that we do NOT default the availability flag to True - */
702 /* we take it from the default service passed. This allows all */
703 /* dynamic printers to be disabled by disabling the [printers] */
704 /* entry (if/when the 'available' keyword is implemented!). */
706 /* the printer name is set to the service name. */
707 lpcfg_string_set(service, &service->_printername, pszPrintername);
708 lpcfg_string_set(service, &service->comment, comment);
709 service->browseable = default_service->browseable;
710 /* Printers cannot be read_only. */
711 service->read_only = false;
712 /* Printer services must be printable. */
713 service->printable = true;
715 DEBUG(3, ("adding printer service %s\n", pszPrintername));
721 * Map a parameter's string representation to something we can use.
722 * Returns False if the parameter string is not recognised, else TRUE.
725 int lpcfg_map_parameter(const char *pszParmName)
729 for (iIndex = 0; parm_table[iIndex].label; iIndex++)
730 if (strwicmp(parm_table[iIndex].label, pszParmName) == 0)
733 /* Warn only if it isn't parametric option */
734 if (strchr(pszParmName, ':') == NULL)
735 DEBUG(0, ("Unknown parameter encountered: \"%s\"\n", pszParmName));
736 /* We do return 'fail' for parametric options as well because they are
737 stored in different storage
744 return the parameter structure for a parameter
746 struct parm_struct *lpcfg_parm_struct(struct loadparm_context *lp_ctx, const char *name)
750 if (lp_ctx->s3_fns) {
751 return lp_ctx->s3_fns->get_parm_struct(name);
754 parmnum = lpcfg_map_parameter(name);
755 if (parmnum == -1) return NULL;
756 return &parm_table[parmnum];
760 return the parameter pointer for a parameter
762 void *lpcfg_parm_ptr(struct loadparm_context *lp_ctx,
763 struct loadparm_service *service, struct parm_struct *parm)
765 if (lp_ctx->s3_fns) {
766 return lp_ctx->s3_fns->get_parm_ptr(service, parm);
769 if (service == NULL) {
770 if (parm->p_class == P_LOCAL)
771 return ((char *)lp_ctx->sDefault)+parm->offset;
772 else if (parm->p_class == P_GLOBAL)
773 return ((char *)lp_ctx->globals)+parm->offset;
776 return ((char *)service) + parm->offset;
781 return the parameter pointer for a parameter
783 bool lpcfg_parm_is_cmdline(struct loadparm_context *lp_ctx, const char *name)
787 if (lp_ctx->s3_fns) {
788 struct parm_struct *parm = lp_ctx->s3_fns->get_parm_struct(name);
790 return parm->flags & FLAG_CMDLINE;
795 parmnum = lpcfg_map_parameter(name);
796 if (parmnum == -1) return false;
798 return lp_ctx->flags[parmnum] & FLAG_CMDLINE;
802 * Find a service by name. Otherwise works like get_service.
805 static struct loadparm_service *lpcfg_getservicebyname(struct loadparm_context *lp_ctx,
806 const char *pszServiceName)
810 if (lp_ctx->s3_fns) {
811 return lp_ctx->s3_fns->get_service(pszServiceName);
814 for (iService = lp_ctx->iNumServices - 1; iService >= 0; iService--)
815 if (lp_ctx->services[iService] != NULL &&
816 strwicmp(lp_ctx->services[iService]->szService, pszServiceName) == 0) {
817 return lp_ctx->services[iService];
824 * Add a parametric option to a parmlist_entry,
825 * replacing old value, if already present.
827 void set_param_opt(TALLOC_CTX *mem_ctx,
828 struct parmlist_entry **opt_list,
829 const char *opt_name,
830 const char *opt_value,
833 struct parmlist_entry *new_opt, *opt;
839 /* Traverse destination */
841 /* If we already have same option, override it */
842 if (strwicmp(opt->key, opt_name) == 0) {
843 if ((opt->priority & FLAG_CMDLINE) &&
844 !(priority & FLAG_CMDLINE)) {
845 /* it's been marked as not to be
849 TALLOC_FREE(opt->value);
850 TALLOC_FREE(opt->list);
851 opt->value = talloc_strdup(opt, opt_value);
852 opt->priority = priority;
859 new_opt = talloc(mem_ctx, struct parmlist_entry);
860 if (new_opt == NULL) {
864 new_opt->key = talloc_strdup(new_opt, opt_name);
865 if (new_opt->key == NULL) {
866 smb_panic("talloc_strdup failed");
869 new_opt->value = talloc_strdup(new_opt, opt_value);
870 if (new_opt->value == NULL) {
871 smb_panic("talloc_strdup failed");
874 new_opt->list = NULL;
875 new_opt->priority = priority;
876 DLIST_ADD(*opt_list, new_opt);
881 * Copy a service structure to another.
882 * If pcopymapDest is NULL then copy all fields
885 void copy_service(struct loadparm_service *pserviceDest,
886 const struct loadparm_service *pserviceSource,
887 struct bitmap *pcopymapDest)
890 bool bcopyall = (pcopymapDest == NULL);
891 struct parmlist_entry *data;
893 for (i = 0; parm_table[i].label; i++)
894 if (parm_table[i].p_class == P_LOCAL &&
895 (bcopyall || bitmap_query(pcopymapDest, i))) {
896 const void *src_ptr =
897 ((const char *)pserviceSource) + parm_table[i].offset;
899 ((char *)pserviceDest) + parm_table[i].offset;
901 switch (parm_table[i].type) {
904 *(bool *)dest_ptr = *(const bool *)src_ptr;
911 *(int *)dest_ptr = *(const int *)src_ptr;
915 *(char *)dest_ptr = *(const char *)src_ptr;
919 lpcfg_string_set(pserviceDest,
921 *(const char * const *)src_ptr);
925 lpcfg_string_set_upper(pserviceDest,
927 *(const char * const *)src_ptr);
930 TALLOC_FREE(*((char ***)dest_ptr));
931 *(const char * const **)dest_ptr = (const char * const *)str_list_copy(pserviceDest,
932 *(const char * * const *)src_ptr);
940 init_copymap(pserviceDest);
941 if (pserviceSource->copymap)
942 bitmap_copy(pserviceDest->copymap,
943 pserviceSource->copymap);
946 for (data = pserviceSource->param_opt; data != NULL; data = data->next) {
947 set_param_opt(pserviceDest, &pserviceDest->param_opt,
948 data->key, data->value, data->priority);
953 * Check a service for consistency. Return False if the service is in any way
954 * incomplete or faulty, else True.
956 static bool lpcfg_service_ok(struct loadparm_service *service)
961 if (service->szService[0] == '\0') {
962 DEBUG(0, ("The following message indicates an internal error:\n"));
963 DEBUG(0, ("No service name in service entry.\n"));
967 /* The [printers] entry MUST be printable. I'm all for flexibility, but */
968 /* I can't see why you'd want a non-printable printer service... */
969 if (strwicmp(service->szService, PRINTERS_NAME) == 0) {
970 if (!service->printable) {
971 DEBUG(0, ("WARNING: [%s] service MUST be printable!\n",
972 service->szService));
973 service->printable = true;
975 /* [printers] service must also be non-browsable. */
976 if (service->browseable)
977 service->browseable = false;
980 /* If a service is flagged unavailable, log the fact at level 0. */
981 if (!service->bAvailable)
982 DEBUG(1, ("NOTE: Service %s is flagged unavailable.\n",
983 service->szService));
989 /*******************************************************************
990 Keep a linked list of all config files so we know when one has changed
991 it's date and needs to be reloaded.
992 ********************************************************************/
994 void add_to_file_list(TALLOC_CTX *mem_ctx, struct file_lists **list,
995 const char *fname, const char *subfname)
997 struct file_lists *f = *list;
1000 if (f->name && !strcmp(f->name, fname))
1006 f = talloc(mem_ctx, struct file_lists);
1010 f->name = talloc_strdup(f, fname);
1015 f->subfname = talloc_strdup(f, subfname);
1021 f->modtime = file_modtime(subfname);
1023 time_t t = file_modtime(subfname);
1030 DEBUG(0, ("Unable to add file to file list: %s\n", fname));
1034 /*******************************************************************
1035 Check if a config file has changed date.
1036 ********************************************************************/
1037 bool lpcfg_file_list_changed(struct loadparm_context *lp_ctx)
1039 struct file_lists *f;
1040 DEBUG(6, ("lpcfg_file_list_changed()\n"));
1042 for (f = lp_ctx->file_lists; f != NULL; f = f->next) {
1046 n2 = standard_sub_basic(lp_ctx, f->name);
1048 DEBUGADD(6, ("file %s -> %s last mod_time: %s\n",
1049 f->name, n2, ctime(&f->modtime)));
1051 mod_time = file_modtime(n2);
1053 if (mod_time && ((f->modtime != mod_time) || (f->subfname == NULL) || (strcmp(n2, f->subfname) != 0))) {
1054 DEBUGADD(6, ("file %s modified: %s\n", n2,
1056 f->modtime = mod_time;
1057 talloc_free(f->subfname);
1058 f->subfname = talloc_strdup(f, n2);
1066 * set the value for a P_ENUM
1068 bool lp_set_enum_parm( struct parm_struct *parm, const char *pszParmValue,
1073 for (i = 0; parm->enum_list[i].name; i++) {
1074 if ( strequal(pszParmValue, parm->enum_list[i].name)) {
1075 *ptr = parm->enum_list[i].value;
1079 DEBUG(0, ("WARNING: Ignoring invalid value '%s' for parameter '%s'\n",
1080 pszParmValue, parm->label));
1085 /***************************************************************************
1086 Handle the "realm" parameter
1087 ***************************************************************************/
1089 bool handle_realm(struct loadparm_context *lp_ctx, int unused,
1090 const char *pszParmValue, char **ptr)
1095 upper = strupper_talloc(lp_ctx, pszParmValue);
1096 if (upper == NULL) {
1100 lower = strlower_talloc(lp_ctx, pszParmValue);
1101 if (lower == NULL) {
1106 if (lp_ctx->s3_fns != NULL) {
1107 lp_ctx->s3_fns->lp_string_set(ptr, pszParmValue);
1108 lp_ctx->s3_fns->lp_string_set(&lp_ctx->globals->realm, upper);
1109 lp_ctx->s3_fns->lp_string_set(&lp_ctx->globals->dnsdomain, lower);
1111 lpcfg_string_set(lp_ctx, ptr, pszParmValue);
1112 lpcfg_string_set(lp_ctx, &lp_ctx->globals->realm, upper);
1113 lpcfg_string_set(lp_ctx, &lp_ctx->globals->dnsdomain, lower);
1119 /***************************************************************************
1120 Handle the include operation.
1121 ***************************************************************************/
1123 bool handle_include(struct loadparm_context *lp_ctx, int unused,
1124 const char *pszParmValue, char **ptr)
1128 if (lp_ctx->s3_fns) {
1129 return lp_ctx->s3_fns->lp_include(lp_ctx, unused, pszParmValue, ptr);
1132 fname = standard_sub_basic(lp_ctx, pszParmValue);
1134 add_to_file_list(lp_ctx, &lp_ctx->file_lists, pszParmValue, fname);
1136 lpcfg_string_set(lp_ctx, ptr, fname);
1138 if (file_exist(fname))
1139 return pm_process(fname, do_section, do_parameter, lp_ctx);
1141 DEBUG(2, ("Can't find include file %s\n", fname));
1146 /***************************************************************************
1147 Handle the interpretation of the copy parameter.
1148 ***************************************************************************/
1150 bool handle_copy(struct loadparm_context *lp_ctx, int snum,
1151 const char *pszParmValue, char **ptr)
1154 struct loadparm_service *serviceTemp = NULL;
1155 struct loadparm_service *current = NULL;
1159 DEBUG(3, ("Copying service from service %s\n", pszParmValue));
1161 serviceTemp = lpcfg_getservicebyname(lp_ctx, pszParmValue);
1162 if (lp_ctx->s3_fns != NULL) {
1163 current = lp_ctx->s3_fns->get_servicebynum(snum);
1165 current = lp_ctx->currentService;
1168 if (current == NULL) {
1169 DEBUG(0, ("Unable to copy service - invalid service destination"));
1173 if (serviceTemp != NULL) {
1174 if (serviceTemp == current) {
1175 DEBUG(0, ("Can't copy service %s - unable to copy self!\n", pszParmValue));
1177 copy_service(current,
1180 lpcfg_string_set(current, ptr, pszParmValue);
1185 DEBUG(0, ("Unable to copy service - source not found: %s\n",
1193 bool handle_debug_list(struct loadparm_context *lp_ctx, int unused,
1194 const char *pszParmValue, char **ptr)
1196 if (lp_ctx->s3_fns != NULL) {
1197 lp_ctx->s3_fns->lp_string_set(ptr, pszParmValue);
1199 lpcfg_string_set(lp_ctx, ptr, pszParmValue);
1202 return debug_parse_levels(pszParmValue);
1205 bool handle_logfile(struct loadparm_context *lp_ctx, int unused,
1206 const char *pszParmValue, char **ptr)
1208 if (lp_ctx->s3_fns != NULL) {
1209 lp_ctx->s3_fns->lp_string_set(ptr, pszParmValue);
1211 debug_set_logfile(pszParmValue);
1212 lpcfg_string_set(lp_ctx, ptr, pszParmValue);
1219 * These special charset handling methods only run in the source3 code.
1222 bool handle_charset(struct loadparm_context *lp_ctx, int snum,
1223 const char *pszParmValue, char **ptr)
1225 if (lp_ctx->s3_fns) {
1226 if (*ptr == NULL || strcmp(*ptr, pszParmValue) != 0) {
1227 lp_ctx->s3_fns->lp_string_set(ptr, pszParmValue);
1228 global_iconv_handle = smb_iconv_handle_reinit(NULL,
1229 lpcfg_dos_charset(lp_ctx),
1230 lpcfg_unix_charset(lp_ctx),
1231 true, global_iconv_handle);
1236 return lpcfg_string_set(lp_ctx, ptr, pszParmValue);
1240 bool handle_dos_charset(struct loadparm_context *lp_ctx, int snum,
1241 const char *pszParmValue, char **ptr)
1243 bool is_utf8 = false;
1244 size_t len = strlen(pszParmValue);
1246 if (lp_ctx->s3_fns) {
1247 if (len == 4 || len == 5) {
1248 /* Don't use StrCaseCmp here as we don't want to
1249 initialize iconv. */
1250 if ((toupper_m(pszParmValue[0]) == 'U') &&
1251 (toupper_m(pszParmValue[1]) == 'T') &&
1252 (toupper_m(pszParmValue[2]) == 'F')) {
1254 if (pszParmValue[3] == '8') {
1258 if (pszParmValue[3] == '-' &&
1259 pszParmValue[4] == '8') {
1266 if (*ptr == NULL || strcmp(*ptr, pszParmValue) != 0) {
1268 DEBUG(0,("ERROR: invalid DOS charset: 'dos charset' must not "
1269 "be UTF8, using (default value) %s instead.\n",
1270 DEFAULT_DOS_CHARSET));
1271 pszParmValue = DEFAULT_DOS_CHARSET;
1273 lp_ctx->s3_fns->lp_string_set(ptr, pszParmValue);
1274 global_iconv_handle = smb_iconv_handle_reinit(NULL,
1275 lpcfg_dos_charset(lp_ctx),
1276 lpcfg_unix_charset(lp_ctx),
1277 true, global_iconv_handle);
1282 return lpcfg_string_set(lp_ctx, ptr, pszParmValue);
1285 /***************************************************************************
1286 Initialise a copymap.
1287 ***************************************************************************/
1289 void init_copymap(struct loadparm_service *pservice)
1293 TALLOC_FREE(pservice->copymap);
1295 pservice->copymap = bitmap_talloc(NULL, NUMPARAMETERS);
1296 if (!pservice->copymap)
1298 ("Couldn't allocate copymap!! (size %d)\n",
1299 (int)NUMPARAMETERS));
1301 for (i = 0; i < NUMPARAMETERS; i++)
1302 bitmap_set(pservice->copymap, i);
1306 * Process a parametric option
1308 static bool lp_do_parameter_parametric(struct loadparm_context *lp_ctx,
1309 struct loadparm_service *service,
1310 const char *pszParmName,
1311 const char *pszParmValue, int flags)
1313 struct parmlist_entry *paramo, *data;
1315 TALLOC_CTX *mem_ctx;
1317 while (isspace((unsigned char)*pszParmName)) {
1321 name = strlower_talloc(lp_ctx, pszParmName);
1322 if (!name) return false;
1324 if (service == NULL) {
1325 data = lp_ctx->globals->param_opt;
1326 mem_ctx = lp_ctx->globals;
1328 data = service->param_opt;
1332 /* Traverse destination */
1333 for (paramo=data; paramo; paramo=paramo->next) {
1334 /* If we already have the option set, override it unless
1335 it was a command line option and the new one isn't */
1336 if (strcmp(paramo->key, name) == 0) {
1337 if ((paramo->priority & FLAG_CMDLINE) &&
1338 !(flags & FLAG_CMDLINE)) {
1343 talloc_free(paramo->value);
1344 paramo->value = talloc_strdup(paramo, pszParmValue);
1345 paramo->priority = flags;
1351 paramo = talloc_zero(mem_ctx, struct parmlist_entry);
1354 paramo->key = talloc_strdup(paramo, name);
1355 paramo->value = talloc_strdup(paramo, pszParmValue);
1356 paramo->priority = flags;
1357 if (service == NULL) {
1358 DLIST_ADD(lp_ctx->globals->param_opt, paramo);
1360 DLIST_ADD(service->param_opt, paramo);
1368 static bool set_variable(TALLOC_CTX *mem_ctx, int parmnum, void *parm_ptr,
1369 const char *pszParmName, const char *pszParmValue,
1370 struct loadparm_context *lp_ctx, bool on_globals)
1373 /* if it is a special case then go ahead */
1374 if (parm_table[parmnum].special) {
1376 ret = parm_table[parmnum].special(lp_ctx, -1, pszParmValue,
1381 goto mark_non_default;
1384 /* now switch on the type of variable it is */
1385 switch (parm_table[parmnum].type)
1389 if (!set_boolean(pszParmValue, &b)) {
1390 DEBUG(0, ("set_variable(%s): value is not "
1391 "boolean!\n", pszParmValue));
1394 *(bool *)parm_ptr = b;
1400 if (!set_boolean(pszParmValue, &b)) {
1401 DEBUG(0, ("set_variable(%s): value is not "
1402 "boolean!\n", pszParmValue));
1405 *(bool *)parm_ptr = !b;
1410 *(int *)parm_ptr = atoi(pszParmValue);
1414 *(char *)parm_ptr = *pszParmValue;
1418 *(int *)parm_ptr = strtol(pszParmValue, NULL, 8);
1424 if (conv_str_size_error(pszParmValue, &val)) {
1425 if (val <= INT_MAX) {
1426 *(int *)parm_ptr = (int)val;
1431 DEBUG(0, ("set_variable(%s): value is not "
1432 "a valid size specifier!\n", pszParmValue));
1437 *(const char * const **)parm_ptr
1438 = (const char * const *)str_list_make(mem_ctx,
1439 pszParmValue, NULL);
1443 char **new_list = str_list_make(mem_ctx,
1444 pszParmValue, NULL);
1445 for (i=0; new_list[i]; i++) {
1446 if (*(const char ***)parm_ptr != NULL &&
1447 new_list[i][0] == '+' &&
1450 if (!str_list_check(*(const char ***)parm_ptr,
1452 *(const char ***)parm_ptr = str_list_add(*(const char ***)parm_ptr,
1455 } else if (*(const char ***)parm_ptr != NULL &&
1456 new_list[i][0] == '-' &&
1459 str_list_remove(*(const char ***)parm_ptr,
1463 DEBUG(0, ("Unsupported list syntax for: %s = %s\n",
1464 pszParmName, pszParmValue));
1467 *(const char * const **)parm_ptr = (const char * const *) new_list;
1474 lpcfg_string_set(mem_ctx, (char **)parm_ptr, pszParmValue);
1478 lpcfg_string_set_upper(mem_ctx, (char **)parm_ptr, pszParmValue);
1482 if (!lp_set_enum_parm(&parm_table[parmnum], pszParmValue, (int*)parm_ptr)) {
1492 if (on_globals && (lp_ctx->flags[parmnum] & FLAG_DEFAULT)) {
1493 lp_ctx->flags[parmnum] &= ~FLAG_DEFAULT;
1494 /* we have to also unset FLAG_DEFAULT on aliases */
1495 for (i=parmnum-1;i>=0 && parm_table[i].offset == parm_table[parmnum].offset;i--) {
1496 lp_ctx->flags[i] &= ~FLAG_DEFAULT;
1498 for (i=parmnum+1;i<NUMPARAMETERS && parm_table[i].offset == parm_table[parmnum].offset;i++) {
1499 lp_ctx->flags[i] &= ~FLAG_DEFAULT;
1506 bool lpcfg_do_global_parameter(struct loadparm_context *lp_ctx,
1507 const char *pszParmName, const char *pszParmValue)
1509 int parmnum = lpcfg_map_parameter(pszParmName);
1513 if (strchr(pszParmName, ':')) {
1514 return lp_do_parameter_parametric(lp_ctx, NULL, pszParmName, pszParmValue, 0);
1516 DEBUG(0, ("Ignoring unknown parameter \"%s\"\n", pszParmName));
1520 /* if the flag has been set on the command line, then don't allow override,
1521 but don't report an error */
1522 if (lp_ctx->flags[parmnum] & FLAG_CMDLINE) {
1526 parm_ptr = lpcfg_parm_ptr(lp_ctx, NULL, &parm_table[parmnum]);
1528 return set_variable(lp_ctx->globals, parmnum, parm_ptr,
1529 pszParmName, pszParmValue, lp_ctx, true);
1532 bool lpcfg_do_service_parameter(struct loadparm_context *lp_ctx,
1533 struct loadparm_service *service,
1534 const char *pszParmName, const char *pszParmValue)
1538 int parmnum = lpcfg_map_parameter(pszParmName);
1541 if (strchr(pszParmName, ':')) {
1542 return lp_do_parameter_parametric(lp_ctx, service, pszParmName, pszParmValue, 0);
1544 DEBUG(0, ("Ignoring unknown parameter \"%s\"\n", pszParmName));
1548 /* if the flag has been set on the command line, then don't allow override,
1549 but don't report an error */
1550 if (lp_ctx->flags[parmnum] & FLAG_CMDLINE) {
1554 if (parm_table[parmnum].p_class == P_GLOBAL) {
1556 ("Global parameter %s found in service section!\n",
1560 parm_ptr = ((char *)service) + parm_table[parmnum].offset;
1562 if (!service->copymap)
1563 init_copymap(service);
1565 /* this handles the aliases - set the copymap for other
1566 * entries with the same data pointer */
1567 for (i = 0; parm_table[i].label; i++)
1568 if (parm_table[i].offset == parm_table[parmnum].offset &&
1569 parm_table[i].p_class == parm_table[parmnum].p_class)
1570 bitmap_clear(service->copymap, i);
1572 return set_variable(service, parmnum, parm_ptr, pszParmName,
1573 pszParmValue, lp_ctx, false);
1577 * Process a parameter.
1580 static bool do_parameter(const char *pszParmName, const char *pszParmValue,
1583 struct loadparm_context *lp_ctx = (struct loadparm_context *)userdata;
1585 if (lp_ctx->bInGlobalSection)
1586 return lpcfg_do_global_parameter(lp_ctx, pszParmName,
1589 return lpcfg_do_service_parameter(lp_ctx, lp_ctx->currentService,
1590 pszParmName, pszParmValue);
1594 variable argument do parameter
1596 bool lpcfg_do_global_parameter_var(struct loadparm_context *lp_ctx, const char *pszParmName, const char *fmt, ...) PRINTF_ATTRIBUTE(3, 4);
1597 bool lpcfg_do_global_parameter_var(struct loadparm_context *lp_ctx,
1598 const char *pszParmName, const char *fmt, ...)
1605 s = talloc_vasprintf(NULL, fmt, ap);
1607 ret = lpcfg_do_global_parameter(lp_ctx, pszParmName, s);
1614 set a parameter from the commandline - this is called from command line parameter
1615 parsing code. It sets the parameter then marks the parameter as unable to be modified
1616 by smb.conf processing
1618 bool lpcfg_set_cmdline(struct loadparm_context *lp_ctx, const char *pszParmName,
1619 const char *pszParmValue)
1624 while (isspace((unsigned char)*pszParmValue)) pszParmValue++;
1626 if (lp_ctx->s3_fns) {
1627 return lp_ctx->s3_fns->set_cmdline(pszParmName, pszParmValue);
1630 parmnum = lpcfg_map_parameter(pszParmName);
1632 if (parmnum < 0 && strchr(pszParmName, ':')) {
1633 /* set a parametric option */
1634 return lp_do_parameter_parametric(lp_ctx, NULL, pszParmName,
1635 pszParmValue, FLAG_CMDLINE);
1639 DEBUG(0,("Unknown option '%s'\n", pszParmName));
1643 /* reset the CMDLINE flag in case this has been called before */
1644 lp_ctx->flags[parmnum] &= ~FLAG_CMDLINE;
1646 if (!lpcfg_do_global_parameter(lp_ctx, pszParmName, pszParmValue)) {
1650 lp_ctx->flags[parmnum] |= FLAG_CMDLINE;
1652 /* we have to also set FLAG_CMDLINE on aliases */
1654 i>=0 && parm_table[i].p_class == parm_table[parmnum].p_class &&
1655 parm_table[i].offset == parm_table[parmnum].offset;
1657 lp_ctx->flags[i] |= FLAG_CMDLINE;
1661 parm_table[i].p_class == parm_table[parmnum].p_class &&
1662 parm_table[i].offset == parm_table[parmnum].offset;
1664 lp_ctx->flags[i] |= FLAG_CMDLINE;
1671 set a option from the commandline in 'a=b' format. Use to support --option
1673 bool lpcfg_set_option(struct loadparm_context *lp_ctx, const char *option)
1678 s = talloc_strdup(NULL, option);
1691 ret = lpcfg_set_cmdline(lp_ctx, s, p+1);
1697 #define BOOLSTR(b) ((b) ? "Yes" : "No")
1700 * Print a parameter of the specified type.
1703 void lpcfg_print_parameter(struct parm_struct *p, void *ptr, FILE * f)
1705 /* For the seperation of lists values that we print below */
1706 const char *list_sep = ", ";
1711 for (i = 0; p->enum_list[i].name; i++) {
1712 if (*(int *)ptr == p->enum_list[i].value) {
1714 p->enum_list[i].name);
1721 fprintf(f, "%s", BOOLSTR(*(bool *)ptr));
1725 fprintf(f, "%s", BOOLSTR(!*(bool *)ptr));
1730 fprintf(f, "%d", *(int *)ptr);
1734 fprintf(f, "%c", *(char *)ptr);
1738 int val = *(int *)ptr;
1742 fprintf(f, "0%03o", val);
1751 if ((char ***)ptr && *(char ***)ptr) {
1752 char **list = *(char ***)ptr;
1753 for (; *list; list++) {
1754 /* surround strings with whitespace in double quotes */
1755 if (*(list+1) == NULL) {
1756 /* last item, no extra separator */
1759 if ( strchr_m( *list, ' ' ) ) {
1760 fprintf(f, "\"%s\"%s", *list, list_sep);
1762 fprintf(f, "%s%s", *list, list_sep);
1770 if (*(char **)ptr) {
1771 fprintf(f, "%s", *(char **)ptr);
1780 * Check if two parameters are equal.
1783 bool lpcfg_equal_parameter(parm_type type, void *ptr1, void *ptr2)
1788 return (*((bool *)ptr1) == *((bool *)ptr2));
1794 return (*((int *)ptr1) == *((int *)ptr2));
1797 return (*((char *)ptr1) == *((char *)ptr2));
1801 return str_list_equal(*(const char ***)ptr1, *(const char ***)ptr2);
1806 char *p1 = *(char **)ptr1, *p2 = *(char **)ptr2;
1811 return (p1 == p2 || strequal(p1, p2));
1820 * Process a new section (service).
1822 * At this stage all sections are services.
1823 * Later we'll have special sections that permit server parameters to be set.
1824 * Returns True on success, False on failure.
1827 static bool do_section(const char *pszSectionName, void *userdata)
1829 struct loadparm_context *lp_ctx = (struct loadparm_context *)userdata;
1831 bool isglobal = ((strwicmp(pszSectionName, GLOBAL_NAME) == 0) ||
1832 (strwicmp(pszSectionName, GLOBAL_NAME2) == 0));
1835 /* if we've just struck a global section, note the fact. */
1836 lp_ctx->bInGlobalSection = isglobal;
1838 /* check for multiple global sections */
1839 if (lp_ctx->bInGlobalSection) {
1840 DEBUG(4, ("Processing section \"[%s]\"\n", pszSectionName));
1844 /* if we have a current service, tidy it up before moving on */
1847 if (lp_ctx->currentService != NULL)
1848 bRetval = lpcfg_service_ok(lp_ctx->currentService);
1850 /* if all is still well, move to the next record in the services array */
1852 /* We put this here to avoid an odd message order if messages are */
1853 /* issued by the post-processing of a previous section. */
1854 DEBUG(4, ("Processing section \"[%s]\"\n", pszSectionName));
1856 if ((lp_ctx->currentService = lpcfg_add_service(lp_ctx, lp_ctx->sDefault,
1859 DEBUG(0, ("Failed to add a new service\n"));
1869 * Determine if a particular base parameter is currently set to the default value.
1872 static bool is_default(struct loadparm_service *sDefault, int i)
1874 void *def_ptr = ((char *)sDefault) + parm_table[i].offset;
1875 switch (parm_table[i].type) {
1878 return str_list_equal((const char * const *)parm_table[i].def.lvalue,
1879 (const char **)def_ptr);
1882 return strequal(parm_table[i].def.svalue,
1886 return parm_table[i].def.bvalue ==
1893 return parm_table[i].def.ivalue ==
1902 *Display the contents of the global structure.
1905 static void dump_globals(struct loadparm_context *lp_ctx, FILE *f,
1909 struct parmlist_entry *data;
1911 fprintf(f, "# Global parameters\n[global]\n");
1913 for (i = 0; parm_table[i].label; i++)
1914 if (parm_table[i].p_class == P_GLOBAL &&
1915 (i == 0 || (parm_table[i].offset != parm_table[i - 1].offset))) {
1916 if (!show_defaults && (lp_ctx->flags[i] & FLAG_DEFAULT))
1918 fprintf(f, "\t%s = ", parm_table[i].label);
1919 lpcfg_print_parameter(&parm_table[i], lpcfg_parm_ptr(lp_ctx, NULL, &parm_table[i]), f);
1922 if (lp_ctx->globals->param_opt != NULL) {
1923 for (data = lp_ctx->globals->param_opt; data;
1924 data = data->next) {
1925 if (!show_defaults && (data->priority & FLAG_DEFAULT)) {
1928 fprintf(f, "\t%s = %s\n", data->key, data->value);
1935 * Display the contents of a single services record.
1938 static void dump_a_service(struct loadparm_service * pService, struct loadparm_service *sDefault, FILE * f,
1939 unsigned int *flags)
1942 struct parmlist_entry *data;
1944 if (pService != sDefault)
1945 fprintf(f, "\n[%s]\n", pService->szService);
1947 for (i = 0; parm_table[i].label; i++) {
1948 if (parm_table[i].p_class == P_LOCAL &&
1949 (*parm_table[i].label != '-') &&
1950 (i == 0 || (parm_table[i].offset != parm_table[i - 1].offset)))
1952 if (pService == sDefault) {
1953 if (flags && (flags[i] & FLAG_DEFAULT)) {
1956 if (defaults_saved) {
1957 if (is_default(sDefault, i)) {
1962 if (lpcfg_equal_parameter(parm_table[i].type,
1963 ((char *)pService) +
1964 parm_table[i].offset,
1965 ((char *)sDefault) +
1966 parm_table[i].offset))
1970 fprintf(f, "\t%s = ", parm_table[i].label);
1971 lpcfg_print_parameter(&parm_table[i],
1972 ((char *)pService) + parm_table[i].offset, f);
1976 if (pService->param_opt != NULL) {
1977 for (data = pService->param_opt; data; data = data->next) {
1978 fprintf(f, "\t%s = %s\n", data->key, data->value);
1983 bool lpcfg_dump_a_parameter(struct loadparm_context *lp_ctx,
1984 struct loadparm_service *service,
1985 const char *parm_name, FILE * f)
1987 struct parm_struct *parm;
1990 parm = lpcfg_parm_struct(lp_ctx, parm_name);
1995 if (service != NULL && parm->p_class == P_GLOBAL) {
1999 ptr = lpcfg_parm_ptr(lp_ctx, service,parm);
2001 lpcfg_print_parameter(parm, ptr, f);
2007 * Auto-load some home services.
2009 static void lpcfg_add_auto_services(struct loadparm_context *lp_ctx,
2017 * Unload unused services.
2020 void lpcfg_killunused(struct loadparm_context *lp_ctx,
2021 struct smbsrv_connection *smb,
2022 bool (*snumused) (struct smbsrv_connection *, int))
2025 for (i = 0; i < lp_ctx->iNumServices; i++) {
2026 if (lp_ctx->services[i] == NULL)
2029 if (!snumused || !snumused(smb, i)) {
2030 talloc_free(lp_ctx->services[i]);
2031 lp_ctx->services[i] = NULL;
2037 static int lpcfg_destructor(struct loadparm_context *lp_ctx)
2039 struct parmlist_entry *data;
2041 if (lp_ctx->refuse_free) {
2042 /* someone is trying to free the
2043 global_loadparm_context.
2044 We can't allow that. */
2048 if (lp_ctx->globals->param_opt != NULL) {
2049 struct parmlist_entry *next;
2050 for (data = lp_ctx->globals->param_opt; data; data=next) {
2052 if (data->priority & FLAG_CMDLINE) continue;
2053 DLIST_REMOVE(lp_ctx->globals->param_opt, data);
2062 * Initialise the global parameter structure.
2064 * Note that most callers should use loadparm_init_global() instead
2066 struct loadparm_context *loadparm_init(TALLOC_CTX *mem_ctx)
2070 struct loadparm_context *lp_ctx;
2071 struct parmlist_entry *parm;
2074 lp_ctx = talloc_zero(mem_ctx, struct loadparm_context);
2078 talloc_set_destructor(lp_ctx, lpcfg_destructor);
2079 lp_ctx->bInGlobalSection = true;
2080 lp_ctx->globals = talloc_zero(lp_ctx, struct loadparm_global);
2081 lp_ctx->sDefault = talloc_zero(lp_ctx, struct loadparm_service);
2083 lp_ctx->sDefault->iMaxPrintJobs = 1000;
2084 lp_ctx->sDefault->bAvailable = true;
2085 lp_ctx->sDefault->browseable = true;
2086 lp_ctx->sDefault->read_only = true;
2087 lp_ctx->sDefault->map_archive = true;
2088 lp_ctx->sDefault->strict_locking = true;
2089 lp_ctx->sDefault->oplocks = true;
2090 lp_ctx->sDefault->create_mask = 0744;
2091 lp_ctx->sDefault->force_create_mode = 0000;
2092 lp_ctx->sDefault->directory_mask = 0755;
2093 lp_ctx->sDefault->force_directory_mode = 0000;
2095 DEBUG(3, ("Initialising global parameters\n"));
2097 for (i = 0; parm_table[i].label; i++) {
2098 if ((parm_table[i].type == P_STRING ||
2099 parm_table[i].type == P_USTRING) &&
2100 !(lp_ctx->flags[i] & FLAG_CMDLINE)) {
2102 if (parm_table[i].p_class == P_LOCAL) {
2103 r = (char **)(((char *)lp_ctx->sDefault) + parm_table[i].offset);
2105 r = (char **)(((char *)lp_ctx->globals) + parm_table[i].offset);
2107 *r = talloc_strdup(lp_ctx, "");
2111 logfile = talloc_asprintf(lp_ctx, "%s/log.samba", dyn_LOGFILEBASE);
2112 lpcfg_do_global_parameter(lp_ctx, "log file", logfile);
2113 talloc_free(logfile);
2115 lpcfg_do_global_parameter(lp_ctx, "log level", "0");
2117 lpcfg_do_global_parameter(lp_ctx, "syslog", "1");
2118 lpcfg_do_global_parameter(lp_ctx, "syslog only", "No");
2119 lpcfg_do_global_parameter(lp_ctx, "debug timestamp", "Yes");
2120 lpcfg_do_global_parameter(lp_ctx, "debug prefix timestamp", "No");
2121 lpcfg_do_global_parameter(lp_ctx, "debug hires timestamp", "Yes");
2122 lpcfg_do_global_parameter(lp_ctx, "debug pid", "No");
2123 lpcfg_do_global_parameter(lp_ctx, "debug uid", "No");
2124 lpcfg_do_global_parameter(lp_ctx, "debug class", "No");
2126 lpcfg_do_global_parameter(lp_ctx, "share backend", "classic");
2128 lpcfg_do_global_parameter(lp_ctx, "server role", "auto");
2129 lpcfg_do_global_parameter(lp_ctx, "domain logons", "No");
2130 lpcfg_do_global_parameter(lp_ctx, "domain master", "Auto");
2132 /* options that can be set on the command line must be initialised via
2133 the slower lpcfg_do_global_parameter() to ensure that FLAG_CMDLINE is obeyed */
2135 lpcfg_do_global_parameter(lp_ctx, "socket options", "TCP_NODELAY");
2137 lpcfg_do_global_parameter(lp_ctx, "workgroup", DEFAULT_WORKGROUP);
2138 myname = get_myname(lp_ctx);
2139 lpcfg_do_global_parameter(lp_ctx, "netbios name", myname);
2140 talloc_free(myname);
2141 lpcfg_do_global_parameter(lp_ctx, "name resolve order", "lmhosts wins host bcast");
2143 lpcfg_do_global_parameter(lp_ctx, "fstype", "NTFS");
2145 lpcfg_do_global_parameter(lp_ctx, "ntvfs handler", "unixuid default");
2146 lpcfg_do_global_parameter(lp_ctx, "max connections", "0");
2148 lpcfg_do_global_parameter(lp_ctx, "dcerpc endpoint servers", "epmapper wkssvc rpcecho samr netlogon lsarpc spoolss drsuapi dssetup unixinfo browser eventlog6 backupkey dnsserver");
2149 lpcfg_do_global_parameter(lp_ctx, "server services", "s3fs rpc nbt wrepl ldap cldap kdc drepl winbind ntp_signd kcc dnsupdate dns");
2150 lpcfg_do_global_parameter(lp_ctx, "kccsrv:samba_kcc", "true");
2151 /* the winbind method for domain controllers is for both RODC
2152 auth forwarding and for trusted domains */
2153 lpcfg_do_global_parameter(lp_ctx, "private dir", dyn_PRIVATE_DIR);
2154 lpcfg_do_global_parameter(lp_ctx, "registry:HKEY_LOCAL_MACHINE", "hklm.ldb");
2156 /* This hive should be dynamically generated by Samba using
2157 data from the sam, but for the moment leave it in a tdb to
2158 keep regedt32 from popping up an annoying dialog. */
2159 lpcfg_do_global_parameter(lp_ctx, "registry:HKEY_USERS", "hku.ldb");
2161 /* using UTF8 by default allows us to support all chars */
2162 lpcfg_do_global_parameter(lp_ctx, "unix charset", "UTF-8");
2164 /* Use codepage 850 as a default for the dos character set */
2165 lpcfg_do_global_parameter(lp_ctx, "dos charset", "CP850");
2168 * Allow the default PASSWD_CHAT to be overridden in local.h.
2170 lpcfg_do_global_parameter(lp_ctx, "passwd chat", DEFAULT_PASSWD_CHAT);
2172 lpcfg_do_global_parameter(lp_ctx, "pid directory", dyn_PIDDIR);
2173 lpcfg_do_global_parameter(lp_ctx, "lock dir", dyn_LOCKDIR);
2174 lpcfg_do_global_parameter(lp_ctx, "state directory", dyn_STATEDIR);
2175 lpcfg_do_global_parameter(lp_ctx, "cache directory", dyn_CACHEDIR);
2176 lpcfg_do_global_parameter(lp_ctx, "ncalrpc dir", dyn_NCALRPCDIR);
2178 lpcfg_do_global_parameter(lp_ctx, "nbt client socket address", "0.0.0.0");
2179 lpcfg_do_global_parameter_var(lp_ctx, "server string",
2180 "Samba %s", SAMBA_VERSION_STRING);
2182 lpcfg_do_global_parameter(lp_ctx, "password server", "*");
2184 lpcfg_do_global_parameter(lp_ctx, "max mux", "50");
2185 lpcfg_do_global_parameter(lp_ctx, "max xmit", "16644");
2186 lpcfg_do_global_parameter(lp_ctx, "host msdfs", "true");
2188 lpcfg_do_global_parameter(lp_ctx, "LargeReadwrite", "True");
2189 lpcfg_do_global_parameter(lp_ctx, "server min protocol", "LANMAN1");
2190 lpcfg_do_global_parameter(lp_ctx, "server max protocol", "SMB3");
2191 lpcfg_do_global_parameter(lp_ctx, "client min protocol", "CORE");
2192 lpcfg_do_global_parameter(lp_ctx, "client max protocol", "NT1");
2193 lpcfg_do_global_parameter(lp_ctx, "security", "AUTO");
2194 lpcfg_do_global_parameter(lp_ctx, "EncryptPasswords", "True");
2195 lpcfg_do_global_parameter(lp_ctx, "ReadRaw", "True");
2196 lpcfg_do_global_parameter(lp_ctx, "WriteRaw", "True");
2197 lpcfg_do_global_parameter(lp_ctx, "NullPasswords", "False");
2198 lpcfg_do_global_parameter(lp_ctx, "old password allowed period", "60");
2199 lpcfg_do_global_parameter(lp_ctx, "ObeyPamRestrictions", "False");
2201 lpcfg_do_global_parameter(lp_ctx, "TimeServer", "False");
2202 lpcfg_do_global_parameter(lp_ctx, "BindInterfacesOnly", "False");
2203 lpcfg_do_global_parameter(lp_ctx, "Unicode", "True");
2204 lpcfg_do_global_parameter(lp_ctx, "ClientLanManAuth", "False");
2205 lpcfg_do_global_parameter(lp_ctx, "ClientNTLMv2Auth", "True");
2206 lpcfg_do_global_parameter(lp_ctx, "LanmanAuth", "False");
2207 lpcfg_do_global_parameter(lp_ctx, "NTLMAuth", "True");
2208 lpcfg_do_global_parameter(lp_ctx, "client use spnego principal", "False");
2210 lpcfg_do_global_parameter(lp_ctx, "UnixExtensions", "True");
2212 lpcfg_do_global_parameter(lp_ctx, "PreferredMaster", "Auto");
2213 lpcfg_do_global_parameter(lp_ctx, "LocalMaster", "True");
2215 lpcfg_do_global_parameter(lp_ctx, "wins support", "False");
2216 lpcfg_do_global_parameter(lp_ctx, "dns proxy", "True");
2218 lpcfg_do_global_parameter(lp_ctx, "winbind separator", "\\");
2219 lpcfg_do_global_parameter(lp_ctx, "winbind sealed pipes", "True");
2220 lpcfg_do_global_parameter(lp_ctx, "require strong key", "True");
2221 lpcfg_do_global_parameter(lp_ctx, "winbindd socket directory", dyn_WINBINDD_SOCKET_DIR);
2222 lpcfg_do_global_parameter(lp_ctx, "winbindd privileged socket directory", dyn_WINBINDD_PRIVILEGED_SOCKET_DIR);
2223 lpcfg_do_global_parameter(lp_ctx, "ntp signd socket directory", dyn_NTP_SIGND_SOCKET_DIR);
2224 lpcfg_do_global_parameter_var(lp_ctx, "dns update command", "%s/samba_dnsupdate", dyn_SCRIPTSBINDIR);
2225 lpcfg_do_global_parameter_var(lp_ctx, "spn update command", "%s/samba_spnupdate", dyn_SCRIPTSBINDIR);
2226 lpcfg_do_global_parameter_var(lp_ctx, "samba kcc command",
2227 "%s/samba_kcc", dyn_SCRIPTSBINDIR);
2228 lpcfg_do_global_parameter(lp_ctx, "template shell", "/bin/false");
2229 lpcfg_do_global_parameter(lp_ctx, "template homedir", "/home/%WORKGROUP%/%ACCOUNTNAME%");
2231 lpcfg_do_global_parameter(lp_ctx, "client signing", "default");
2232 lpcfg_do_global_parameter(lp_ctx, "server signing", "default");
2234 lpcfg_do_global_parameter(lp_ctx, "use spnego", "True");
2236 lpcfg_do_global_parameter(lp_ctx, "use mmap", "True");
2238 lpcfg_do_global_parameter(lp_ctx, "smb ports", "445 139");
2239 lpcfg_do_global_parameter(lp_ctx, "nbt port", "137");
2240 lpcfg_do_global_parameter(lp_ctx, "dgram port", "138");
2241 lpcfg_do_global_parameter(lp_ctx, "cldap port", "389");
2242 lpcfg_do_global_parameter(lp_ctx, "krb5 port", "88");
2243 lpcfg_do_global_parameter(lp_ctx, "kpasswd port", "464");
2244 lpcfg_do_global_parameter(lp_ctx, "web port", "901");
2246 lpcfg_do_global_parameter(lp_ctx, "nt status support", "True");
2248 lpcfg_do_global_parameter(lp_ctx, "max wins ttl", "518400"); /* 6 days */
2249 lpcfg_do_global_parameter(lp_ctx, "min wins ttl", "21600");
2251 lpcfg_do_global_parameter(lp_ctx, "tls enabled", "True");
2252 lpcfg_do_global_parameter(lp_ctx, "tls keyfile", "tls/key.pem");
2253 lpcfg_do_global_parameter(lp_ctx, "tls certfile", "tls/cert.pem");
2254 lpcfg_do_global_parameter(lp_ctx, "tls cafile", "tls/ca.pem");
2255 lpcfg_do_global_parameter(lp_ctx, "prefork children:smb", "4");
2257 lpcfg_do_global_parameter(lp_ctx, "rndc command", "/usr/sbin/rndc");
2258 lpcfg_do_global_parameter(lp_ctx, "nsupdate command", "/usr/bin/nsupdate -g");
2260 lpcfg_do_global_parameter(lp_ctx, "allow dns updates", "secure only");
2261 lpcfg_do_global_parameter(lp_ctx, "dns forwarder", "");
2263 lpcfg_do_global_parameter(lp_ctx, "algorithmic rid base", "1000");
2265 lpcfg_do_global_parameter(lp_ctx, "enhanced browsing", "True");
2267 lpcfg_do_global_parameter(lp_ctx, "winbind nss info", "template");
2269 lpcfg_do_global_parameter(lp_ctx, "server schannel", "Auto");
2271 lpcfg_do_global_parameter(lp_ctx, "short preserve case", "True");
2273 lpcfg_do_global_parameter(lp_ctx, "max open files", "16384");
2275 lpcfg_do_global_parameter(lp_ctx, "cups connection timeout", "30");
2277 lpcfg_do_global_parameter(lp_ctx, "locking", "True");
2279 lpcfg_do_global_parameter(lp_ctx, "block size", "1024");
2281 lpcfg_do_global_parameter(lp_ctx, "client use spnego", "True");
2283 lpcfg_do_global_parameter(lp_ctx, "change notify", "True");
2285 lpcfg_do_global_parameter(lp_ctx, "name cache timeout", "660");
2287 lpcfg_do_global_parameter(lp_ctx, "defer sharing violations", "True");
2289 lpcfg_do_global_parameter(lp_ctx, "ldap replication sleep", "1000");
2291 lpcfg_do_global_parameter(lp_ctx, "idmap backend", "tdb");
2293 lpcfg_do_global_parameter(lp_ctx, "enable privileges", "True");
2295 lpcfg_do_global_parameter_var(lp_ctx, "smb2 max write", "%u", DEFAULT_SMB2_MAX_WRITE);
2297 lpcfg_do_global_parameter(lp_ctx, "passdb backend", "tdbsam");
2299 lpcfg_do_global_parameter(lp_ctx, "getwd cache", "True");
2301 lpcfg_do_global_parameter(lp_ctx, "winbind nested groups", "True");
2303 lpcfg_do_global_parameter(lp_ctx, "mangled names", "True");
2305 lpcfg_do_global_parameter_var(lp_ctx, "smb2 max credits", "%u", DEFAULT_SMB2_MAX_CREDITS);
2307 lpcfg_do_global_parameter(lp_ctx, "ldap ssl", "start tls");
2309 lpcfg_do_global_parameter(lp_ctx, "ldap deref", "auto");
2311 lpcfg_do_global_parameter(lp_ctx, "lm interval", "60");
2313 lpcfg_do_global_parameter(lp_ctx, "mangling method", "hash2");
2315 lpcfg_do_global_parameter(lp_ctx, "hide dot files", "True");
2317 lpcfg_do_global_parameter(lp_ctx, "browse list", "True");
2319 lpcfg_do_global_parameter(lp_ctx, "passwd chat timeout", "2");
2321 lpcfg_do_global_parameter(lp_ctx, "guest account", GUEST_ACCOUNT);
2323 lpcfg_do_global_parameter(lp_ctx, "client schannel", "auto");
2325 lpcfg_do_global_parameter(lp_ctx, "smb encrypt", "default");
2327 lpcfg_do_global_parameter(lp_ctx, "max log size", "5000");
2329 lpcfg_do_global_parameter(lp_ctx, "idmap negative cache time", "120");
2331 lpcfg_do_global_parameter(lp_ctx, "ldap follow referral", "auto");
2333 lpcfg_do_global_parameter(lp_ctx, "multicast dns register", "yes");
2335 lpcfg_do_global_parameter(lp_ctx, "winbind reconnect delay", "30");
2337 lpcfg_do_global_parameter(lp_ctx, "nt acl support", "yes");
2339 lpcfg_do_global_parameter(lp_ctx, "acl check permissions", "yes");
2341 lpcfg_do_global_parameter(lp_ctx, "keepalive", "300");
2343 lpcfg_do_global_parameter(lp_ctx, "winbind cache time", "300");
2345 lpcfg_do_global_parameter(lp_ctx, "level2 oplocks", "yes");
2347 lpcfg_do_global_parameter(lp_ctx, "show add printer wizard", "yes");
2349 lpcfg_do_global_parameter(lp_ctx, "allocation roundup size", "1048576");
2351 lpcfg_do_global_parameter(lp_ctx, "ldap page size", "1024");
2353 lpcfg_do_global_parameter(lp_ctx, "kernel share modes", "yes");
2355 lpcfg_do_global_parameter(lp_ctx, "strict locking", "Auto");
2357 lpcfg_do_global_parameter(lp_ctx, "map readonly", "yes");
2359 lpcfg_do_global_parameter(lp_ctx, "allow trusted domains", "yes");
2361 lpcfg_do_global_parameter(lp_ctx, "default devmode", "yes");
2363 lpcfg_do_global_parameter(lp_ctx, "os level", "20");
2365 lpcfg_do_global_parameter(lp_ctx, "dos filetimes", "yes");
2367 lpcfg_do_global_parameter(lp_ctx, "mangling char", "~");
2369 lpcfg_do_global_parameter(lp_ctx, "printcap cache time", "750");
2371 lpcfg_do_global_parameter(lp_ctx, "create krb5 conf", "yes");
2373 lpcfg_do_global_parameter(lp_ctx, "winbind max clients", "200");
2375 lpcfg_do_global_parameter(lp_ctx, "acl map full control", "yes");
2377 lpcfg_do_global_parameter(lp_ctx, "nt pipe support", "yes");
2379 lpcfg_do_global_parameter(lp_ctx, "ldap debug threshold", "10");
2381 lpcfg_do_global_parameter(lp_ctx, "follow symlinks", "yes");
2383 lpcfg_do_global_parameter(lp_ctx, "machine password timeout", "604800");
2385 lpcfg_do_global_parameter(lp_ctx, "ldap connection timeout", "2");
2387 lpcfg_do_global_parameter(lp_ctx, "winbind expand groups", "1");
2389 lpcfg_do_global_parameter(lp_ctx, "stat cache", "yes");
2391 lpcfg_do_global_parameter(lp_ctx, "lpq cache time", "30");
2393 lpcfg_do_global_parameter_var(lp_ctx, "smb2 max trans", "%u", DEFAULT_SMB2_MAX_TRANSACT);
2395 lpcfg_do_global_parameter_var(lp_ctx, "smb2 max read", "%u", DEFAULT_SMB2_MAX_READ);
2397 lpcfg_do_global_parameter(lp_ctx, "durable handles", "yes");
2399 lpcfg_do_global_parameter(lp_ctx, "max stat cache size", "256");
2401 lpcfg_do_global_parameter(lp_ctx, "ldap passwd sync", "no");
2403 lpcfg_do_global_parameter(lp_ctx, "kernel change notify", "yes");
2405 lpcfg_do_global_parameter(lp_ctx, "max ttl", "259200");
2407 lpcfg_do_global_parameter(lp_ctx, "blocking locks", "yes");
2409 lpcfg_do_global_parameter(lp_ctx, "oplock contention limit", "2");
2411 lpcfg_do_global_parameter(lp_ctx, "load printers", "yes");
2413 lpcfg_do_global_parameter(lp_ctx, "idmap cache time", "604800");
2415 lpcfg_do_global_parameter(lp_ctx, "preserve case", "yes");
2417 lpcfg_do_global_parameter(lp_ctx, "lm announce", "auto");
2419 lpcfg_do_global_parameter(lp_ctx, "afs token lifetime", "604800");
2421 lpcfg_do_global_parameter(lp_ctx, "enable core files", "yes");
2423 lpcfg_do_global_parameter(lp_ctx, "winbind max domain connections", "1");
2425 lpcfg_do_global_parameter(lp_ctx, "case sensitive", "auto");
2427 lpcfg_do_global_parameter(lp_ctx, "ldap timeout", "15");
2429 lpcfg_do_global_parameter(lp_ctx, "mangle prefix", "1");
2431 lpcfg_do_global_parameter(lp_ctx, "posix locking", "yes");
2433 lpcfg_do_global_parameter(lp_ctx, "lock spin time", "200");
2435 lpcfg_do_global_parameter(lp_ctx, "directory name cache size", "100");
2437 lpcfg_do_global_parameter(lp_ctx, "nmbd bind explicit broadcast", "yes");
2439 lpcfg_do_global_parameter(lp_ctx, "init logon delay", "100");
2441 lpcfg_do_global_parameter(lp_ctx, "usershare owner only", "yes");
2443 lpcfg_do_global_parameter(lp_ctx, "-valid", "yes");
2445 lpcfg_do_global_parameter_var(lp_ctx, "usershare path", "%s/usershares", get_dyn_STATEDIR());
2448 lpcfg_do_global_parameter_var(lp_ctx, "panic action", "/bin/sleep 999999999");
2451 lpcfg_do_global_parameter(lp_ctx, "smb passwd file", get_dyn_SMB_PASSWD_FILE());
2453 lpcfg_do_global_parameter(lp_ctx, "logon home", "\\\\%N\\%U");
2455 lpcfg_do_global_parameter(lp_ctx, "logon path", "\\\\%N\\%U\\profile");
2457 lpcfg_do_global_parameter(lp_ctx, "printjob username", "%U");
2459 for (i = 0; parm_table[i].label; i++) {
2460 if (!(lp_ctx->flags[i] & FLAG_CMDLINE)) {
2461 lp_ctx->flags[i] |= FLAG_DEFAULT;
2465 for (parm=lp_ctx->globals->param_opt; parm; parm=parm->next) {
2466 if (!(parm->priority & FLAG_CMDLINE)) {
2467 parm->priority |= FLAG_DEFAULT;
2475 * Initialise the global parameter structure.
2477 struct loadparm_context *loadparm_init_global(bool load_default)
2479 if (global_loadparm_context == NULL) {
2480 global_loadparm_context = loadparm_init(NULL);
2482 if (global_loadparm_context == NULL) {
2485 global_loadparm_context->global = true;
2486 if (load_default && !global_loadparm_context->loaded) {
2487 lpcfg_load_default(global_loadparm_context);
2489 global_loadparm_context->refuse_free = true;
2490 return global_loadparm_context;
2494 * Initialise the global parameter structure.
2496 struct loadparm_context *loadparm_init_s3(TALLOC_CTX *mem_ctx,
2497 const struct loadparm_s3_helpers *s3_fns)
2499 struct loadparm_context *loadparm_context = talloc_zero(mem_ctx, struct loadparm_context);
2500 if (!loadparm_context) {
2503 loadparm_context->s3_fns = s3_fns;
2504 loadparm_context->globals = s3_fns->globals;
2505 return loadparm_context;
2508 const char *lpcfg_configfile(struct loadparm_context *lp_ctx)
2510 return lp_ctx->szConfigFile;
2513 const char *lp_default_path(void)
2515 if (getenv("SMB_CONF_PATH"))
2516 return getenv("SMB_CONF_PATH");
2518 return dyn_CONFIGFILE;
2522 * Update the internal state of a loadparm context after settings
2525 static bool lpcfg_update(struct loadparm_context *lp_ctx)
2527 struct debug_settings settings;
2528 TALLOC_CTX *tmp_ctx;
2530 tmp_ctx = talloc_new(lp_ctx);
2531 if (tmp_ctx == NULL) {
2535 lpcfg_add_auto_services(lp_ctx, lpcfg_auto_services(lp_ctx, tmp_ctx));
2537 if (!lp_ctx->globals->wins_server_list && lp_ctx->globals->we_are_a_wins_server) {
2538 lpcfg_do_global_parameter(lp_ctx, "wins server", "127.0.0.1");
2541 if (!lp_ctx->global) {
2542 TALLOC_FREE(tmp_ctx);
2546 panic_action = lp_ctx->globals->panic_action;
2548 reload_charcnv(lp_ctx);
2550 ZERO_STRUCT(settings);
2551 /* Add any more debug-related smb.conf parameters created in
2553 settings.syslog = lp_ctx->globals->syslog;
2554 settings.syslog_only = lp_ctx->globals->syslog_only;
2555 settings.timestamp_logs = lp_ctx->globals->timestamp_logs;
2556 settings.debug_prefix_timestamp = lp_ctx->globals->debug_prefix_timestamp;
2557 settings.debug_hires_timestamp = lp_ctx->globals->debug_hires_timestamp;
2558 settings.debug_pid = lp_ctx->globals->debug_pid;
2559 settings.debug_uid = lp_ctx->globals->debug_uid;
2560 settings.debug_class = lp_ctx->globals->debug_class;
2561 debug_set_settings(&settings);
2563 /* FIXME: This is a bit of a hack, but we can't use a global, since
2564 * not everything that uses lp also uses the socket library */
2565 if (lpcfg_parm_bool(lp_ctx, NULL, "socket", "testnonblock", false)) {
2566 setenv("SOCKET_TESTNONBLOCK", "1", 1);
2568 unsetenv("SOCKET_TESTNONBLOCK");
2571 TALLOC_FREE(tmp_ctx);
2575 bool lpcfg_load_default(struct loadparm_context *lp_ctx)
2579 path = lp_default_path();
2581 if (!file_exist(path)) {
2582 /* We allow the default smb.conf file to not exist,
2583 * basically the equivalent of an empty file. */
2584 return lpcfg_update(lp_ctx);
2587 return lpcfg_load(lp_ctx, path);
2591 * Load the services array from the services file.
2593 * Return True on success, False on failure.
2595 bool lpcfg_load(struct loadparm_context *lp_ctx, const char *filename)
2600 filename = talloc_strdup(lp_ctx, filename);
2602 lp_ctx->szConfigFile = filename;
2604 if (lp_ctx->s3_fns) {
2605 return lp_ctx->s3_fns->load(filename);
2608 lp_ctx->bInGlobalSection = true;
2609 n2 = standard_sub_basic(lp_ctx, lp_ctx->szConfigFile);
2610 DEBUG(2, ("lpcfg_load: refreshing parameters from %s\n", n2));
2612 add_to_file_list(lp_ctx, &lp_ctx->file_lists, lp_ctx->szConfigFile, n2);
2614 /* We get sections first, so have to start 'behind' to make up */
2615 lp_ctx->currentService = NULL;
2616 bRetval = pm_process(n2, do_section, do_parameter, lp_ctx);
2618 /* finish up the last section */
2619 DEBUG(4, ("pm_process() returned %s\n", BOOLSTR(bRetval)));
2621 if (lp_ctx->currentService != NULL)
2622 bRetval = lpcfg_service_ok(lp_ctx->currentService);
2624 bRetval = bRetval && lpcfg_update(lp_ctx);
2626 /* we do this unconditionally, so that it happens even
2627 for a missing smb.conf */
2628 reload_charcnv(lp_ctx);
2630 if (bRetval == true) {
2631 /* set this up so that any child python tasks will
2632 find the right smb.conf */
2633 setenv("SMB_CONF_PATH", filename, 1);
2635 /* set the context used by the lp_*() function
2637 global_loadparm_context = lp_ctx;
2638 lp_ctx->loaded = true;
2645 * Return the max number of services.
2648 int lpcfg_numservices(struct loadparm_context *lp_ctx)
2650 if (lp_ctx->s3_fns) {
2651 return lp_ctx->s3_fns->get_numservices();
2654 return lp_ctx->iNumServices;
2658 * Display the contents of the services array in human-readable form.
2661 void lpcfg_dump(struct loadparm_context *lp_ctx, FILE *f, bool show_defaults,
2666 if (lp_ctx->s3_fns) {
2667 lp_ctx->s3_fns->dump(f, show_defaults, maxtoprint);
2671 defaults_saved = !show_defaults;
2673 dump_globals(lp_ctx, f, show_defaults);
2675 dump_a_service(lp_ctx->sDefault, lp_ctx->sDefault, f, lp_ctx->flags);
2677 for (iService = 0; iService < maxtoprint; iService++)
2678 lpcfg_dump_one(f, show_defaults, lp_ctx->services[iService], lp_ctx->sDefault);
2682 * Display the contents of one service in human-readable form.
2684 void lpcfg_dump_one(FILE *f, bool show_defaults, struct loadparm_service *service, struct loadparm_service *sDefault)
2686 if (service != NULL) {
2687 if (service->szService[0] == '\0')
2689 dump_a_service(service, sDefault, f, NULL);
2693 struct loadparm_service *lpcfg_servicebynum(struct loadparm_context *lp_ctx,
2696 if (lp_ctx->s3_fns) {
2697 return lp_ctx->s3_fns->get_servicebynum(snum);
2700 return lp_ctx->services[snum];
2703 struct loadparm_service *lpcfg_service(struct loadparm_context *lp_ctx,
2704 const char *service_name)
2709 if (lp_ctx->s3_fns) {
2710 return lp_ctx->s3_fns->get_service(service_name);
2713 for (iService = lp_ctx->iNumServices - 1; iService >= 0; iService--) {
2714 if (lp_ctx->services[iService] &&
2715 lp_ctx->services[iService]->szService) {
2717 * The substitution here is used to support %U is
2720 serviceName = standard_sub_basic(
2721 lp_ctx->services[iService],
2722 lp_ctx->services[iService]->szService);
2723 if (strequal(serviceName, service_name)) {
2724 talloc_free(serviceName);
2725 return lp_ctx->services[iService];
2727 talloc_free(serviceName);
2731 DEBUG(7,("lpcfg_servicenumber: couldn't find %s\n", service_name));
2735 const char *lpcfg_servicename(const struct loadparm_service *service)
2737 return lpcfg_string((const char *)service->szService);
2741 * A useful volume label function.
2743 const char *lpcfg_volume_label(struct loadparm_service *service, struct loadparm_service *sDefault)
2746 ret = lpcfg_string((const char *)((service != NULL && service->volume != NULL) ?
2747 service->volume : sDefault->volume));
2749 return lpcfg_servicename(service);
2754 * Return the correct printer name.
2756 const char *lpcfg_printername(struct loadparm_service *service, struct loadparm_service *sDefault)
2759 ret = lpcfg_string((const char *)((service != NULL && service->_printername != NULL) ?
2760 service->_printername : sDefault->_printername));
2761 if (ret == NULL || (ret != NULL && *ret == '\0'))
2762 ret = lpcfg_servicename(service);
2769 * Return the max print jobs per queue.
2771 int lpcfg_maxprintjobs(struct loadparm_service *service, struct loadparm_service *sDefault)
2773 int maxjobs = (service != NULL) ? service->iMaxPrintJobs : sDefault->iMaxPrintJobs;
2774 if (maxjobs <= 0 || maxjobs >= PRINT_MAX_JOBID)
2775 maxjobs = PRINT_MAX_JOBID - 1;
2780 struct smb_iconv_handle *lpcfg_iconv_handle(struct loadparm_context *lp_ctx)
2782 if (lp_ctx == NULL) {
2783 return get_iconv_handle();
2785 return lp_ctx->iconv_handle;
2788 _PUBLIC_ void reload_charcnv(struct loadparm_context *lp_ctx)
2790 struct smb_iconv_handle *old_ic = lp_ctx->iconv_handle;
2791 if (!lp_ctx->global) {
2795 if (old_ic == NULL) {
2796 old_ic = global_iconv_handle;
2798 lp_ctx->iconv_handle = smb_iconv_handle_reinit_lp(lp_ctx, lp_ctx, old_ic);
2799 global_iconv_handle = lp_ctx->iconv_handle;
2802 _PUBLIC_ char *lpcfg_tls_keyfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
2804 return lpcfg_private_path(mem_ctx, lp_ctx, lpcfg__tls_keyfile(lp_ctx));
2807 _PUBLIC_ char *lpcfg_tls_certfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
2809 return lpcfg_private_path(mem_ctx, lp_ctx, lpcfg__tls_certfile(lp_ctx));
2812 _PUBLIC_ char *lpcfg_tls_cafile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
2814 return lpcfg_private_path(mem_ctx, lp_ctx, lpcfg__tls_cafile(lp_ctx));
2817 _PUBLIC_ char *lpcfg_tls_crlfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
2819 return lpcfg_private_path(mem_ctx, lp_ctx, lpcfg__tls_crlfile(lp_ctx));
2822 _PUBLIC_ char *lpcfg_tls_dhpfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
2824 return lpcfg_private_path(mem_ctx, lp_ctx, lpcfg__tls_dhpfile(lp_ctx));
2827 struct gensec_settings *lpcfg_gensec_settings(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
2829 struct gensec_settings *settings = talloc_zero(mem_ctx, struct gensec_settings);
2830 if (settings == NULL)
2832 SMB_ASSERT(lp_ctx != NULL);
2833 settings->lp_ctx = talloc_reference(settings, lp_ctx);
2834 settings->target_hostname = lpcfg_parm_string(lp_ctx, NULL, "gensec", "target_hostname");
2838 int lpcfg_server_role(struct loadparm_context *lp_ctx)
2840 int domain_master = lpcfg__domain_master(lp_ctx);
2842 return lp_find_server_role(lpcfg__server_role(lp_ctx),
2843 lpcfg__security(lp_ctx),
2844 lpcfg__domain_logons(lp_ctx),
2845 (domain_master == true) ||
2846 (domain_master == Auto));
2849 int lpcfg_security(struct loadparm_context *lp_ctx)
2851 return lp_find_security(lpcfg__server_role(lp_ctx),
2852 lpcfg__security(lp_ctx));
2855 bool lpcfg_server_signing_allowed(struct loadparm_context *lp_ctx, bool *mandatory)
2857 bool allowed = true;
2858 enum smb_signing_setting signing_setting = lpcfg_server_signing(lp_ctx);
2862 if (signing_setting == SMB_SIGNING_DEFAULT) {
2864 * If we are a domain controller, SMB signing is
2865 * really important, as it can prevent a number of
2866 * attacks on communications between us and the
2869 * However, it really sucks (no sendfile, CPU
2870 * overhead) performance-wise when used on a
2871 * file server, so disable it by default
2875 if (lpcfg_server_role(lp_ctx) >= ROLE_ACTIVE_DIRECTORY_DC) {
2876 signing_setting = SMB_SIGNING_REQUIRED;
2878 signing_setting = SMB_SIGNING_OFF;
2882 switch (signing_setting) {
2883 case SMB_SIGNING_REQUIRED:
2886 case SMB_SIGNING_IF_REQUIRED:
2888 case SMB_SIGNING_DEFAULT:
2889 case SMB_SIGNING_OFF:
2897 int lpcfg_tdb_hash_size(struct loadparm_context *lp_ctx, const char *name)
2905 base = strrchr_m(name, '/');
2911 return lpcfg_parm_int(lp_ctx, NULL, "tdb_hashsize", base, 0);
2915 int lpcfg_tdb_flags(struct loadparm_context *lp_ctx, int tdb_flags)
2917 if (!lpcfg_use_mmap(lp_ctx)) {
2918 tdb_flags |= TDB_NOMMAP;