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 /* we don't need a special handler for "dos charset" and "unix charset" */
81 #define handle_dos_charset NULL
82 #define handle_charset NULL
84 /* these are parameter handlers which are not needed in the
87 #define handle_netbios_aliases NULL
88 #define handle_printing NULL
89 #define handle_ldap_debug_level NULL
90 #define handle_idmap_backend NULL
91 #define handle_idmap_uid NULL
92 #define handle_idmap_gid NULL
98 /* prototypes for the special type handlers */
99 static bool handle_include(struct loadparm_context
*lp_ctx
, int unused
,
100 const char *pszParmValue
, char **ptr
);
101 static bool handle_copy(struct loadparm_context
*lp_ctx
, int unused
,
102 const char *pszParmValue
, char **ptr
);
104 #include "lib/param/param_table.c"
106 /* local variables */
107 struct loadparm_context
{
108 const char *szConfigFile
;
109 struct loadparm_global
*globals
;
110 struct loadparm_service
**services
;
111 struct loadparm_service
*sDefault
;
112 struct smb_iconv_handle
*iconv_handle
;
114 struct loadparm_service
*currentService
;
115 bool bInGlobalSection
;
117 struct file_lists
*next
;
122 unsigned int flags
[NUMPARAMETERS
];
125 bool global
; /* Is this the global context, which may set
126 * global variables such as debug level etc? */
127 const struct loadparm_s3_helpers
*s3_fns
;
131 struct loadparm_service
*lpcfg_default_service(struct loadparm_context
*lp_ctx
)
133 if (lp_ctx
->s3_fns
) {
134 return lp_ctx
->s3_fns
->get_default_loadparm_service();
136 return lp_ctx
->sDefault
;
140 * Convenience routine to grab string parameters into temporary memory
141 * and run standard_sub_basic on them.
143 * The buffers can be written to by
144 * callers without affecting the source string.
147 static const char *lpcfg_string(const char *s
)
149 #if 0 /* until REWRITE done to make thread-safe */
150 size_t len
= s
? strlen(s
) : 0;
154 /* The follow debug is useful for tracking down memory problems
155 especially if you have an inner loop that is calling a lp_*()
156 function that returns a string. Perhaps this debug should be
157 present all the time? */
160 DEBUG(10, ("lpcfg_string(%s)\n", s
));
163 #if 0 /* until REWRITE done to make thread-safe */
165 lp_talloc
= talloc_init("lp_talloc");
167 ret
= talloc_array(lp_talloc
, char, len
+ 100); /* leave room for substitution */
175 strlcpy(ret
, s
, len
);
177 if (trim_string(ret
, "\"", "\"")) {
178 if (strchr(ret
,'"') != NULL
)
179 strlcpy(ret
, s
, len
);
182 standard_sub_basic(ret
,len
+100);
189 In this section all the functions that are used to access the
190 parameters from the rest of the program are defined
194 * the creation of separate lpcfg_*() and lp_*() functions is to allow
195 * for code compatibility between existing Samba4 and Samba3 code.
198 /* this global context supports the lp_*() function varients */
199 static struct loadparm_context
*global_loadparm_context
;
201 #define lpcfg_default_service global_loadparm_context->sDefault
202 #define lpcfg_global_service(i) global_loadparm_context->services[i]
204 #define FN_GLOBAL_STRING(fn_name,var_name) \
205 _PUBLIC_ char *lpcfg_ ## fn_name(struct loadparm_context *lp_ctx, TALLOC_CTX *ctx) {\
206 if (lp_ctx == NULL) return NULL; \
207 if (lp_ctx->s3_fns) { \
208 return lp_ctx->globals->var_name ? lp_ctx->s3_fns->lp_string(ctx, lp_ctx->globals->var_name) : talloc_strdup(ctx, ""); \
210 return lp_ctx->globals->var_name ? talloc_strdup(ctx, lpcfg_string(lp_ctx->globals->var_name)) : talloc_strdup(ctx, ""); \
213 #define FN_GLOBAL_CONST_STRING(fn_name,var_name) \
214 _PUBLIC_ const char *lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) { \
215 if (lp_ctx == NULL) return NULL; \
216 return lp_ctx->globals->var_name ? lpcfg_string(lp_ctx->globals->var_name) : ""; \
219 #define FN_GLOBAL_LIST(fn_name,var_name) \
220 _PUBLIC_ const char **lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) { \
221 if (lp_ctx == NULL) return NULL; \
222 return lp_ctx->globals->var_name; \
225 #define FN_GLOBAL_BOOL(fn_name,var_name) \
226 _PUBLIC_ bool lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) {\
227 if (lp_ctx == NULL) return false; \
228 return lp_ctx->globals->var_name; \
231 #define FN_GLOBAL_INTEGER(fn_name,var_name) \
232 _PUBLIC_ int lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) { \
233 return lp_ctx->globals->var_name; \
236 /* Local parameters don't need the ->s3_fns because the struct
237 * loadparm_service is shared and lpcfg_service() checks the ->s3_fns
239 #define FN_LOCAL_STRING(fn_name,val) \
240 _PUBLIC_ char *lpcfg_ ## fn_name(struct loadparm_service *service, \
241 struct loadparm_service *sDefault, TALLOC_CTX *ctx) { \
242 return(talloc_strdup(ctx, lpcfg_string((const char *)((service != NULL && service->val != NULL) ? service->val : sDefault->val)))); \
245 #define FN_LOCAL_CONST_STRING(fn_name,val) \
246 _PUBLIC_ const char *lpcfg_ ## fn_name(struct loadparm_service *service, \
247 struct loadparm_service *sDefault) { \
248 return((const char *)((service != NULL && service->val != NULL) ? service->val : sDefault->val)); \
251 #define FN_LOCAL_LIST(fn_name,val) \
252 _PUBLIC_ const char **lpcfg_ ## fn_name(struct loadparm_service *service, \
253 struct loadparm_service *sDefault) {\
254 return(const char **)(service != NULL && service->val != NULL? service->val : sDefault->val); \
257 #define FN_LOCAL_PARM_BOOL(fn_name, val) FN_LOCAL_BOOL(fn_name, val)
259 #define FN_LOCAL_BOOL(fn_name,val) \
260 _PUBLIC_ bool lpcfg_ ## fn_name(struct loadparm_service *service, \
261 struct loadparm_service *sDefault) { \
262 return((service != NULL)? service->val : sDefault->val); \
265 #define FN_LOCAL_INTEGER(fn_name,val) \
266 _PUBLIC_ int lpcfg_ ## fn_name(struct loadparm_service *service, \
267 struct loadparm_service *sDefault) { \
268 return((service != NULL)? service->val : sDefault->val); \
271 #define FN_LOCAL_PARM_INTEGER(fn_name, val) FN_LOCAL_INTEGER(fn_name, val)
273 #define FN_LOCAL_PARM_CHAR(fn_name,val) \
274 _PUBLIC_ char lpcfg_ ## fn_name(struct loadparm_service *service, \
275 struct loadparm_service *sDefault) { \
276 return((service != NULL)? service->val : sDefault->val); \
279 #include "lib/param/param_functions.c"
281 /* These functions cannot be auto-generated */
282 FN_LOCAL_BOOL(autoloaded
, autoloaded
)
283 FN_GLOBAL_CONST_STRING(dnsdomain
, dnsdomain
)
285 /* local prototypes */
286 static struct loadparm_service
*getservicebyname(struct loadparm_context
*lp_ctx
,
287 const char *pszServiceName
);
288 static bool lpcfg_service_ok(struct loadparm_service
*service
);
289 static bool do_section(const char *pszSectionName
, void *);
290 static void init_copymap(struct loadparm_service
*pservice
);
292 /* This is a helper function for parametrical options support. */
293 /* It returns a pointer to parametrical option value if it exists or NULL otherwise */
294 /* Actual parametrical functions are quite simple */
295 const char *lpcfg_get_parametric(struct loadparm_context
*lp_ctx
,
296 struct loadparm_service
*service
,
297 const char *type
, const char *option
)
299 char *vfskey_tmp
= NULL
;
301 struct parmlist_entry
*data
;
306 if (lp_ctx
->s3_fns
) {
307 return lp_ctx
->s3_fns
->get_parametric(service
, type
, option
);
310 data
= (service
== NULL
? lp_ctx
->globals
->param_opt
: service
->param_opt
);
312 vfskey_tmp
= talloc_asprintf(NULL
, "%s:%s", type
, option
);
313 if (vfskey_tmp
== NULL
) return NULL
;
314 vfskey
= strlower_talloc(NULL
, vfskey_tmp
);
315 talloc_free(vfskey_tmp
);
318 if (strcmp(data
->key
, vfskey
) == 0) {
325 if (service
!= NULL
) {
326 /* Try to fetch the same option but from globals */
327 /* but only if we are not already working with globals */
328 for (data
= lp_ctx
->globals
->param_opt
; data
;
330 if (strcmp(data
->key
, vfskey
) == 0) {
344 * convenience routine to return int parameters.
346 static int lp_int(const char *s
)
350 DEBUG(0,("lp_int(%s): is called with NULL!\n",s
));
354 return strtol(s
, NULL
, 0);
358 * convenience routine to return unsigned long parameters.
360 static unsigned long lp_ulong(const char *s
)
364 DEBUG(0,("lp_ulong(%s): is called with NULL!\n",s
));
368 return strtoul(s
, NULL
, 0);
372 * convenience routine to return unsigned long parameters.
374 static long lp_long(const char *s
)
378 DEBUG(0,("lp_long(%s): is called with NULL!\n",s
));
382 return strtol(s
, NULL
, 0);
386 * convenience routine to return unsigned long parameters.
388 static double lp_double(const char *s
)
392 DEBUG(0,("lp_double(%s): is called with NULL!\n",s
));
396 return strtod(s
, NULL
);
400 * convenience routine to return boolean parameters.
402 static bool lp_bool(const char *s
)
407 DEBUG(0,("lp_bool(%s): is called with NULL!\n",s
));
411 if (!set_boolean(s
, &ret
)) {
412 DEBUG(0,("lp_bool(%s): value is not boolean!\n",s
));
421 * Return parametric option from a given service. Type is a part of option before ':'
422 * Parametric option has following syntax: 'Type: option = value'
423 * Returned value is allocated in 'lp_talloc' context
426 const char *lpcfg_parm_string(struct loadparm_context
*lp_ctx
,
427 struct loadparm_service
*service
, const char *type
,
430 const char *value
= lpcfg_get_parametric(lp_ctx
, service
, type
, option
);
433 return lpcfg_string(value
);
439 * Return parametric option from a given service. Type is a part of option before ':'
440 * Parametric option has following syntax: 'Type: option = value'
441 * Returned value is allocated in 'lp_talloc' context
444 const char **lpcfg_parm_string_list(TALLOC_CTX
*mem_ctx
,
445 struct loadparm_context
*lp_ctx
,
446 struct loadparm_service
*service
,
448 const char *option
, const char *separator
)
450 const char *value
= lpcfg_get_parametric(lp_ctx
, service
, type
, option
);
453 return (const char **)str_list_make(mem_ctx
, value
, separator
);
459 * Return parametric option from a given service. Type is a part of option before ':'
460 * Parametric option has following syntax: 'Type: option = value'
463 int lpcfg_parm_int(struct loadparm_context
*lp_ctx
,
464 struct loadparm_service
*service
, const char *type
,
465 const char *option
, int default_v
)
467 const char *value
= lpcfg_get_parametric(lp_ctx
, service
, type
, option
);
470 return lp_int(value
);
476 * Return parametric option from a given service. Type is a part of
478 * Parametric option has following syntax: 'Type: option = value'.
481 int lpcfg_parm_bytes(struct loadparm_context
*lp_ctx
,
482 struct loadparm_service
*service
, const char *type
,
483 const char *option
, int default_v
)
487 const char *value
= lpcfg_get_parametric(lp_ctx
, service
, type
, option
);
489 if (value
&& conv_str_size_error(value
, &bval
)) {
490 if (bval
<= INT_MAX
) {
499 * Return parametric option from a given service.
500 * Type is a part of option before ':'
501 * Parametric option has following syntax: 'Type: option = value'
503 unsigned long lpcfg_parm_ulong(struct loadparm_context
*lp_ctx
,
504 struct loadparm_service
*service
, const char *type
,
505 const char *option
, unsigned long default_v
)
507 const char *value
= lpcfg_get_parametric(lp_ctx
, service
, type
, option
);
510 return lp_ulong(value
);
515 long lpcfg_parm_long(struct loadparm_context
*lp_ctx
,
516 struct loadparm_service
*service
, const char *type
,
517 const char *option
, long default_v
)
519 const char *value
= lpcfg_get_parametric(lp_ctx
, service
, type
, option
);
522 return lp_long(value
);
527 double lpcfg_parm_double(struct loadparm_context
*lp_ctx
,
528 struct loadparm_service
*service
, const char *type
,
529 const char *option
, double default_v
)
531 const char *value
= lpcfg_get_parametric(lp_ctx
, service
, type
, option
);
534 return lp_double(value
);
540 * Return parametric option from a given service. Type is a part of option before ':'
541 * Parametric option has following syntax: 'Type: option = value'
544 bool lpcfg_parm_bool(struct loadparm_context
*lp_ctx
,
545 struct loadparm_service
*service
, const char *type
,
546 const char *option
, bool default_v
)
548 const char *value
= lpcfg_get_parametric(lp_ctx
, service
, type
, option
);
551 return lp_bool(value
);
558 * Set a string value, deallocating any existing space, and allocing the space
561 static bool lpcfg_string_set(TALLOC_CTX
*mem_ctx
, char **dest
, const char *src
)
568 *dest
= talloc_strdup(mem_ctx
, src
);
569 if ((*dest
) == NULL
) {
570 DEBUG(0,("Out of memory in string_set\n"));
578 * Set a string value, deallocating any existing space, and allocing the space
581 static bool lpcfg_string_set_upper(TALLOC_CTX
*mem_ctx
, char **dest
, const char *src
)
588 *dest
= strupper_talloc(mem_ctx
, src
);
589 if ((*dest
) == NULL
) {
590 DEBUG(0,("Out of memory in string_set_upper\n"));
600 * Add a new service to the services array initialising it with the given
604 struct loadparm_service
*lpcfg_add_service(struct loadparm_context
*lp_ctx
,
605 const struct loadparm_service
*pservice
,
609 int num_to_alloc
= lp_ctx
->iNumServices
+ 1;
610 struct parmlist_entry
*data
, *pdata
;
612 if (pservice
== NULL
) {
613 pservice
= lp_ctx
->sDefault
;
616 /* it might already exist */
618 struct loadparm_service
*service
= getservicebyname(lp_ctx
,
620 if (service
!= NULL
) {
621 /* Clean all parametric options for service */
622 /* They will be added during parsing again */
623 data
= service
->param_opt
;
629 service
->param_opt
= NULL
;
634 /* find an invalid one */
635 for (i
= 0; i
< lp_ctx
->iNumServices
; i
++)
636 if (lp_ctx
->services
[i
] == NULL
)
639 /* if not, then create one */
640 if (i
== lp_ctx
->iNumServices
) {
641 struct loadparm_service
**tsp
;
643 tsp
= talloc_realloc(lp_ctx
, lp_ctx
->services
, struct loadparm_service
*, num_to_alloc
);
646 DEBUG(0,("lpcfg_add_service: failed to enlarge services!\n"));
649 lp_ctx
->services
= tsp
;
650 lp_ctx
->services
[lp_ctx
->iNumServices
] = NULL
;
653 lp_ctx
->iNumServices
++;
656 lp_ctx
->services
[i
] = talloc_zero(lp_ctx
->services
, struct loadparm_service
);
657 if (lp_ctx
->services
[i
] == NULL
) {
658 DEBUG(0,("lpcfg_add_service: out of memory!\n"));
661 copy_service(lp_ctx
->services
[i
], pservice
, NULL
);
663 lpcfg_string_set(lp_ctx
->services
[i
], &lp_ctx
->services
[i
]->szService
, name
);
664 return lp_ctx
->services
[i
];
668 * Add a new home service, with the specified home directory, defaults coming
669 * from service ifrom.
672 bool lpcfg_add_home(struct loadparm_context
*lp_ctx
,
673 const char *pszHomename
,
674 struct loadparm_service
*default_service
,
675 const char *user
, const char *pszHomedir
)
677 struct loadparm_service
*service
;
679 service
= lpcfg_add_service(lp_ctx
, default_service
, pszHomename
);
684 if (!(*(default_service
->path
))
685 || strequal(default_service
->path
, lp_ctx
->sDefault
->path
)) {
686 service
->path
= talloc_strdup(service
, pszHomedir
);
688 service
->path
= string_sub_talloc(service
, lpcfg_path(default_service
, lp_ctx
->sDefault
, service
), "%H", pszHomedir
);
691 if (!(*(service
->comment
))) {
692 service
->comment
= talloc_asprintf(service
, "Home directory of %s", user
);
694 service
->bAvailable
= default_service
->bAvailable
;
695 service
->browseable
= default_service
->browseable
;
697 DEBUG(3, ("adding home's share [%s] for user '%s' at '%s'\n",
698 pszHomename
, user
, service
->path
));
704 * Add a new printer service, with defaults coming from service iFrom.
707 bool lpcfg_add_printer(struct loadparm_context
*lp_ctx
,
708 const char *pszPrintername
,
709 struct loadparm_service
*default_service
)
711 const char *comment
= "From Printcap";
712 struct loadparm_service
*service
;
713 service
= lpcfg_add_service(lp_ctx
, default_service
, pszPrintername
);
718 /* note that we do NOT default the availability flag to True - */
719 /* we take it from the default service passed. This allows all */
720 /* dynamic printers to be disabled by disabling the [printers] */
721 /* entry (if/when the 'available' keyword is implemented!). */
723 /* the printer name is set to the service name. */
724 lpcfg_string_set(service
, &service
->_printername
, pszPrintername
);
725 lpcfg_string_set(service
, &service
->comment
, comment
);
726 service
->browseable
= default_service
->browseable
;
727 /* Printers cannot be read_only. */
728 service
->read_only
= false;
729 /* Printer services must be printable. */
730 service
->printable
= true;
732 DEBUG(3, ("adding printer service %s\n", pszPrintername
));
738 * Map a parameter's string representation to something we can use.
739 * Returns False if the parameter string is not recognised, else TRUE.
742 int lpcfg_map_parameter(const char *pszParmName
)
746 for (iIndex
= 0; parm_table
[iIndex
].label
; iIndex
++)
747 if (strwicmp(parm_table
[iIndex
].label
, pszParmName
) == 0)
750 /* Warn only if it isn't parametric option */
751 if (strchr(pszParmName
, ':') == NULL
)
752 DEBUG(0, ("Unknown parameter encountered: \"%s\"\n", pszParmName
));
753 /* We do return 'fail' for parametric options as well because they are
754 stored in different storage
761 return the parameter structure for a parameter
763 struct parm_struct
*lpcfg_parm_struct(struct loadparm_context
*lp_ctx
, const char *name
)
767 if (lp_ctx
->s3_fns
) {
768 return lp_ctx
->s3_fns
->get_parm_struct(name
);
771 parmnum
= lpcfg_map_parameter(name
);
772 if (parmnum
== -1) return NULL
;
773 return &parm_table
[parmnum
];
777 return the parameter pointer for a parameter
779 void *lpcfg_parm_ptr(struct loadparm_context
*lp_ctx
,
780 struct loadparm_service
*service
, struct parm_struct
*parm
)
782 if (lp_ctx
->s3_fns
) {
783 return lp_ctx
->s3_fns
->get_parm_ptr(service
, parm
);
786 if (service
== NULL
) {
787 if (parm
->p_class
== P_LOCAL
)
788 return ((char *)lp_ctx
->sDefault
)+parm
->offset
;
789 else if (parm
->p_class
== P_GLOBAL
)
790 return ((char *)lp_ctx
->globals
)+parm
->offset
;
793 return ((char *)service
) + parm
->offset
;
798 return the parameter pointer for a parameter
800 bool lpcfg_parm_is_cmdline(struct loadparm_context
*lp_ctx
, const char *name
)
804 if (lp_ctx
->s3_fns
) {
805 struct parm_struct
*parm
= lp_ctx
->s3_fns
->get_parm_struct(name
);
807 return parm
->flags
& FLAG_CMDLINE
;
812 parmnum
= lpcfg_map_parameter(name
);
813 if (parmnum
== -1) return false;
815 return lp_ctx
->flags
[parmnum
] & FLAG_CMDLINE
;
819 * Find a service by name. Otherwise works like get_service.
822 static struct loadparm_service
*getservicebyname(struct loadparm_context
*lp_ctx
,
823 const char *pszServiceName
)
827 if (lp_ctx
->s3_fns
) {
828 return lp_ctx
->s3_fns
->get_service(pszServiceName
);
831 for (iService
= lp_ctx
->iNumServices
- 1; iService
>= 0; iService
--)
832 if (lp_ctx
->services
[iService
] != NULL
&&
833 strwicmp(lp_ctx
->services
[iService
]->szService
, pszServiceName
) == 0) {
834 return lp_ctx
->services
[iService
];
841 * Add a parametric option to a parmlist_entry,
842 * replacing old value, if already present.
844 void set_param_opt(TALLOC_CTX
*mem_ctx
,
845 struct parmlist_entry
**opt_list
,
846 const char *opt_name
,
847 const char *opt_value
,
850 struct parmlist_entry
*new_opt
, *opt
;
856 /* Traverse destination */
858 /* If we already have same option, override it */
859 if (strwicmp(opt
->key
, opt_name
) == 0) {
860 if ((opt
->priority
& FLAG_CMDLINE
) &&
861 !(priority
& FLAG_CMDLINE
)) {
862 /* it's been marked as not to be
866 TALLOC_FREE(opt
->value
);
867 TALLOC_FREE(opt
->list
);
868 opt
->value
= talloc_strdup(opt
, opt_value
);
869 opt
->priority
= priority
;
876 new_opt
= talloc(mem_ctx
, struct parmlist_entry
);
877 if (new_opt
== NULL
) {
881 new_opt
->key
= talloc_strdup(new_opt
, opt_name
);
882 if (new_opt
->key
== NULL
) {
883 smb_panic("talloc_strdup failed");
886 new_opt
->value
= talloc_strdup(new_opt
, opt_value
);
887 if (new_opt
->value
== NULL
) {
888 smb_panic("talloc_strdup failed");
891 new_opt
->list
= NULL
;
892 new_opt
->priority
= priority
;
893 DLIST_ADD(*opt_list
, new_opt
);
898 * Copy a service structure to another.
899 * If pcopymapDest is NULL then copy all fields
902 void copy_service(struct loadparm_service
*pserviceDest
,
903 const struct loadparm_service
*pserviceSource
,
904 struct bitmap
*pcopymapDest
)
907 bool bcopyall
= (pcopymapDest
== NULL
);
908 struct parmlist_entry
*data
;
910 for (i
= 0; parm_table
[i
].label
; i
++)
911 if (parm_table
[i
].p_class
== P_LOCAL
&&
912 (bcopyall
|| bitmap_query(pcopymapDest
, i
))) {
913 const void *src_ptr
=
914 ((const char *)pserviceSource
) + parm_table
[i
].offset
;
916 ((char *)pserviceDest
) + parm_table
[i
].offset
;
918 switch (parm_table
[i
].type
) {
921 *(bool *)dest_ptr
= *(const bool *)src_ptr
;
928 *(int *)dest_ptr
= *(const int *)src_ptr
;
932 *(char *)dest_ptr
= *(const char *)src_ptr
;
936 lpcfg_string_set(pserviceDest
,
938 *(const char * const *)src_ptr
);
942 lpcfg_string_set_upper(pserviceDest
,
944 *(const char * const *)src_ptr
);
947 TALLOC_FREE(*((char ***)dest_ptr
));
948 *(const char * const **)dest_ptr
= (const char * const *)str_list_copy(pserviceDest
,
949 *(const char * * const *)src_ptr
);
957 init_copymap(pserviceDest
);
958 if (pserviceSource
->copymap
)
959 bitmap_copy(pserviceDest
->copymap
,
960 pserviceSource
->copymap
);
963 for (data
= pserviceSource
->param_opt
; data
!= NULL
; data
= data
->next
) {
964 set_param_opt(pserviceDest
, &pserviceDest
->param_opt
,
965 data
->key
, data
->value
, data
->priority
);
970 * Check a service for consistency. Return False if the service is in any way
971 * incomplete or faulty, else True.
973 static bool lpcfg_service_ok(struct loadparm_service
*service
)
978 if (service
->szService
[0] == '\0') {
979 DEBUG(0, ("The following message indicates an internal error:\n"));
980 DEBUG(0, ("No service name in service entry.\n"));
984 /* The [printers] entry MUST be printable. I'm all for flexibility, but */
985 /* I can't see why you'd want a non-printable printer service... */
986 if (strwicmp(service
->szService
, PRINTERS_NAME
) == 0) {
987 if (!service
->printable
) {
988 DEBUG(0, ("WARNING: [%s] service MUST be printable!\n",
989 service
->szService
));
990 service
->printable
= true;
992 /* [printers] service must also be non-browsable. */
993 if (service
->browseable
)
994 service
->browseable
= false;
997 /* If a service is flagged unavailable, log the fact at level 0. */
998 if (!service
->bAvailable
)
999 DEBUG(1, ("NOTE: Service %s is flagged unavailable.\n",
1000 service
->szService
));
1006 /*******************************************************************
1007 Keep a linked list of all config files so we know when one has changed
1008 it's date and needs to be reloaded.
1009 ********************************************************************/
1011 static void add_to_file_list(struct loadparm_context
*lp_ctx
,
1012 const char *fname
, const char *subfname
)
1014 struct file_lists
*f
= lp_ctx
->file_lists
;
1017 if (f
->name
&& !strcmp(f
->name
, fname
))
1023 f
= talloc(lp_ctx
, struct file_lists
);
1026 f
->next
= lp_ctx
->file_lists
;
1027 f
->name
= talloc_strdup(f
, fname
);
1032 f
->subfname
= talloc_strdup(f
, subfname
);
1037 lp_ctx
->file_lists
= f
;
1038 f
->modtime
= file_modtime(subfname
);
1040 time_t t
= file_modtime(subfname
);
1046 /*******************************************************************
1047 Check if a config file has changed date.
1048 ********************************************************************/
1049 bool lpcfg_file_list_changed(struct loadparm_context
*lp_ctx
)
1051 struct file_lists
*f
;
1052 DEBUG(6, ("lpcfg_file_list_changed()\n"));
1054 for (f
= lp_ctx
->file_lists
; f
!= NULL
; f
= f
->next
) {
1058 n2
= standard_sub_basic(lp_ctx
, f
->name
);
1060 DEBUGADD(6, ("file %s -> %s last mod_time: %s\n",
1061 f
->name
, n2
, ctime(&f
->modtime
)));
1063 mod_time
= file_modtime(n2
);
1065 if (mod_time
&& ((f
->modtime
!= mod_time
) || (f
->subfname
== NULL
) || (strcmp(n2
, f
->subfname
) != 0))) {
1066 DEBUGADD(6, ("file %s modified: %s\n", n2
,
1068 f
->modtime
= mod_time
;
1069 talloc_free(f
->subfname
);
1070 f
->subfname
= talloc_strdup(f
, n2
);
1077 /***************************************************************************
1078 Handle the "realm" parameter
1079 ***************************************************************************/
1081 bool handle_realm(struct loadparm_context
*lp_ctx
, int unused
,
1082 const char *pszParmValue
, char **ptr
)
1087 upper
= strupper_talloc(lp_ctx
, pszParmValue
);
1088 if (upper
== NULL
) {
1092 lower
= strlower_talloc(lp_ctx
, pszParmValue
);
1093 if (lower
== NULL
) {
1098 if (lp_ctx
->s3_fns
!= NULL
) {
1099 lp_ctx
->s3_fns
->lp_string_set(ptr
, pszParmValue
);
1100 lp_ctx
->s3_fns
->lp_string_set(&lp_ctx
->globals
->realm
, upper
);
1101 lp_ctx
->s3_fns
->lp_string_set(&lp_ctx
->globals
->dnsdomain
, lower
);
1103 lpcfg_string_set(lp_ctx
, ptr
, pszParmValue
);
1104 lpcfg_string_set(lp_ctx
, &lp_ctx
->globals
->realm
, upper
);
1105 lpcfg_string_set(lp_ctx
, &lp_ctx
->globals
->dnsdomain
, lower
);
1111 /***************************************************************************
1112 Handle the include operation.
1113 ***************************************************************************/
1115 static bool handle_include(struct loadparm_context
*lp_ctx
, int unused
,
1116 const char *pszParmValue
, char **ptr
)
1118 char *fname
= standard_sub_basic(lp_ctx
, pszParmValue
);
1120 add_to_file_list(lp_ctx
, pszParmValue
, fname
);
1122 lpcfg_string_set(lp_ctx
, ptr
, fname
);
1124 if (file_exist(fname
))
1125 return pm_process(fname
, do_section
, do_parameter
, lp_ctx
);
1127 DEBUG(2, ("Can't find include file %s\n", fname
));
1132 /***************************************************************************
1133 Handle the interpretation of the copy parameter.
1134 ***************************************************************************/
1136 static bool handle_copy(struct loadparm_context
*lp_ctx
, int unused
,
1137 const char *pszParmValue
, char **ptr
)
1140 struct loadparm_service
*serviceTemp
;
1142 lpcfg_string_set(lp_ctx
, ptr
, pszParmValue
);
1146 DEBUG(3, ("Copying service from service %s\n", pszParmValue
));
1148 if ((serviceTemp
= getservicebyname(lp_ctx
, pszParmValue
)) != NULL
) {
1149 if (serviceTemp
== lp_ctx
->currentService
) {
1150 DEBUG(0, ("Can't copy service %s - unable to copy self!\n", pszParmValue
));
1152 copy_service(lp_ctx
->currentService
,
1154 lp_ctx
->currentService
->copymap
);
1158 DEBUG(0, ("Unable to copy service - source not found: %s\n",
1166 bool handle_debug_list(struct loadparm_context
*lp_ctx
, int unused
,
1167 const char *pszParmValue
, char **ptr
)
1169 if (lp_ctx
->s3_fns
!= NULL
) {
1170 lp_ctx
->s3_fns
->lp_string_set(ptr
, pszParmValue
);
1172 lpcfg_string_set(lp_ctx
, ptr
, pszParmValue
);
1175 return debug_parse_levels(pszParmValue
);
1178 bool handle_logfile(struct loadparm_context
*lp_ctx
, int unused
,
1179 const char *pszParmValue
, char **ptr
)
1181 if (lp_ctx
->s3_fns
!= NULL
) {
1182 lp_ctx
->s3_fns
->lp_string_set(ptr
, pszParmValue
);
1184 debug_set_logfile(pszParmValue
);
1185 lpcfg_string_set(lp_ctx
, ptr
, pszParmValue
);
1191 /***************************************************************************
1192 Initialise a copymap.
1193 ***************************************************************************/
1195 static void init_copymap(struct loadparm_service
*pservice
)
1199 TALLOC_FREE(pservice
->copymap
);
1201 pservice
->copymap
= bitmap_talloc(NULL
, NUMPARAMETERS
);
1202 if (!pservice
->copymap
)
1204 ("Couldn't allocate copymap!! (size %d)\n",
1205 (int)NUMPARAMETERS
));
1207 for (i
= 0; i
< NUMPARAMETERS
; i
++)
1208 bitmap_set(pservice
->copymap
, i
);
1212 * Process a parametric option
1214 static bool lp_do_parameter_parametric(struct loadparm_context
*lp_ctx
,
1215 struct loadparm_service
*service
,
1216 const char *pszParmName
,
1217 const char *pszParmValue
, int flags
)
1219 struct parmlist_entry
*paramo
, *data
;
1221 TALLOC_CTX
*mem_ctx
;
1223 while (isspace((unsigned char)*pszParmName
)) {
1227 name
= strlower_talloc(lp_ctx
, pszParmName
);
1228 if (!name
) return false;
1230 if (service
== NULL
) {
1231 data
= lp_ctx
->globals
->param_opt
;
1232 mem_ctx
= lp_ctx
->globals
;
1234 data
= service
->param_opt
;
1238 /* Traverse destination */
1239 for (paramo
=data
; paramo
; paramo
=paramo
->next
) {
1240 /* If we already have the option set, override it unless
1241 it was a command line option and the new one isn't */
1242 if (strcmp(paramo
->key
, name
) == 0) {
1243 if ((paramo
->priority
& FLAG_CMDLINE
) &&
1244 !(flags
& FLAG_CMDLINE
)) {
1249 talloc_free(paramo
->value
);
1250 paramo
->value
= talloc_strdup(paramo
, pszParmValue
);
1251 paramo
->priority
= flags
;
1257 paramo
= talloc_zero(mem_ctx
, struct parmlist_entry
);
1260 paramo
->key
= talloc_strdup(paramo
, name
);
1261 paramo
->value
= talloc_strdup(paramo
, pszParmValue
);
1262 paramo
->priority
= flags
;
1263 if (service
== NULL
) {
1264 DLIST_ADD(lp_ctx
->globals
->param_opt
, paramo
);
1266 DLIST_ADD(service
->param_opt
, paramo
);
1274 static bool set_variable(TALLOC_CTX
*mem_ctx
, int parmnum
, void *parm_ptr
,
1275 const char *pszParmName
, const char *pszParmValue
,
1276 struct loadparm_context
*lp_ctx
, bool on_globals
)
1279 /* if it is a special case then go ahead */
1280 if (parm_table
[parmnum
].special
) {
1282 ret
= parm_table
[parmnum
].special(lp_ctx
, -1, pszParmValue
,
1287 goto mark_non_default
;
1290 /* now switch on the type of variable it is */
1291 switch (parm_table
[parmnum
].type
)
1295 if (!set_boolean(pszParmValue
, &b
)) {
1296 DEBUG(0, ("set_variable(%s): value is not "
1297 "boolean!\n", pszParmValue
));
1300 *(bool *)parm_ptr
= b
;
1306 if (!set_boolean(pszParmValue
, &b
)) {
1307 DEBUG(0, ("set_variable(%s): value is not "
1308 "boolean!\n", pszParmValue
));
1311 *(bool *)parm_ptr
= !b
;
1316 *(int *)parm_ptr
= atoi(pszParmValue
);
1320 *(char *)parm_ptr
= *pszParmValue
;
1324 *(int *)parm_ptr
= strtol(pszParmValue
, NULL
, 8);
1330 if (conv_str_size_error(pszParmValue
, &val
)) {
1331 if (val
<= INT_MAX
) {
1332 *(int *)parm_ptr
= (int)val
;
1337 DEBUG(0, ("set_variable(%s): value is not "
1338 "a valid size specifier!\n", pszParmValue
));
1343 *(const char * const **)parm_ptr
1344 = (const char * const *)str_list_make(mem_ctx
,
1345 pszParmValue
, NULL
);
1349 char **new_list
= str_list_make(mem_ctx
,
1350 pszParmValue
, NULL
);
1351 for (i
=0; new_list
[i
]; i
++) {
1352 if (*(const char ***)parm_ptr
!= NULL
&&
1353 new_list
[i
][0] == '+' &&
1356 if (!str_list_check(*(const char ***)parm_ptr
,
1358 *(const char ***)parm_ptr
= str_list_add(*(const char ***)parm_ptr
,
1361 } else if (*(const char ***)parm_ptr
!= NULL
&&
1362 new_list
[i
][0] == '-' &&
1365 str_list_remove(*(const char ***)parm_ptr
,
1369 DEBUG(0, ("Unsupported list syntax for: %s = %s\n",
1370 pszParmName
, pszParmValue
));
1373 *(const char * const **)parm_ptr
= (const char * const *) new_list
;
1380 lpcfg_string_set(mem_ctx
, (char **)parm_ptr
, pszParmValue
);
1384 lpcfg_string_set_upper(mem_ctx
, (char **)parm_ptr
, pszParmValue
);
1388 for (i
= 0; parm_table
[parmnum
].enum_list
[i
].name
; i
++) {
1391 parm_table
[parmnum
].enum_list
[i
].name
)) {
1393 parm_table
[parmnum
].
1398 if (!parm_table
[parmnum
].enum_list
[i
].name
) {
1399 DEBUG(0,("Unknown enumerated value '%s' for '%s'\n",
1400 pszParmValue
, pszParmName
));
1410 if (on_globals
&& (lp_ctx
->flags
[parmnum
] & FLAG_DEFAULT
)) {
1411 lp_ctx
->flags
[parmnum
] &= ~FLAG_DEFAULT
;
1412 /* we have to also unset FLAG_DEFAULT on aliases */
1413 for (i
=parmnum
-1;i
>=0 && parm_table
[i
].offset
== parm_table
[parmnum
].offset
;i
--) {
1414 lp_ctx
->flags
[i
] &= ~FLAG_DEFAULT
;
1416 for (i
=parmnum
+1;i
<NUMPARAMETERS
&& parm_table
[i
].offset
== parm_table
[parmnum
].offset
;i
++) {
1417 lp_ctx
->flags
[i
] &= ~FLAG_DEFAULT
;
1424 bool lpcfg_do_global_parameter(struct loadparm_context
*lp_ctx
,
1425 const char *pszParmName
, const char *pszParmValue
)
1427 int parmnum
= lpcfg_map_parameter(pszParmName
);
1431 if (strchr(pszParmName
, ':')) {
1432 return lp_do_parameter_parametric(lp_ctx
, NULL
, pszParmName
, pszParmValue
, 0);
1434 DEBUG(0, ("Ignoring unknown parameter \"%s\"\n", pszParmName
));
1438 /* if the flag has been set on the command line, then don't allow override,
1439 but don't report an error */
1440 if (lp_ctx
->flags
[parmnum
] & FLAG_CMDLINE
) {
1444 parm_ptr
= lpcfg_parm_ptr(lp_ctx
, NULL
, &parm_table
[parmnum
]);
1446 return set_variable(lp_ctx
->globals
, parmnum
, parm_ptr
,
1447 pszParmName
, pszParmValue
, lp_ctx
, true);
1450 bool lpcfg_do_service_parameter(struct loadparm_context
*lp_ctx
,
1451 struct loadparm_service
*service
,
1452 const char *pszParmName
, const char *pszParmValue
)
1456 int parmnum
= lpcfg_map_parameter(pszParmName
);
1459 if (strchr(pszParmName
, ':')) {
1460 return lp_do_parameter_parametric(lp_ctx
, service
, pszParmName
, pszParmValue
, 0);
1462 DEBUG(0, ("Ignoring unknown parameter \"%s\"\n", pszParmName
));
1466 /* if the flag has been set on the command line, then don't allow override,
1467 but don't report an error */
1468 if (lp_ctx
->flags
[parmnum
] & FLAG_CMDLINE
) {
1472 if (parm_table
[parmnum
].p_class
== P_GLOBAL
) {
1474 ("Global parameter %s found in service section!\n",
1478 parm_ptr
= ((char *)service
) + parm_table
[parmnum
].offset
;
1480 if (!service
->copymap
)
1481 init_copymap(service
);
1483 /* this handles the aliases - set the copymap for other
1484 * entries with the same data pointer */
1485 for (i
= 0; parm_table
[i
].label
; i
++)
1486 if (parm_table
[i
].offset
== parm_table
[parmnum
].offset
&&
1487 parm_table
[i
].p_class
== parm_table
[parmnum
].p_class
)
1488 bitmap_clear(service
->copymap
, i
);
1490 return set_variable(service
, parmnum
, parm_ptr
, pszParmName
,
1491 pszParmValue
, lp_ctx
, false);
1495 * Process a parameter.
1498 static bool do_parameter(const char *pszParmName
, const char *pszParmValue
,
1501 struct loadparm_context
*lp_ctx
= (struct loadparm_context
*)userdata
;
1503 if (lp_ctx
->bInGlobalSection
)
1504 return lpcfg_do_global_parameter(lp_ctx
, pszParmName
,
1507 return lpcfg_do_service_parameter(lp_ctx
, lp_ctx
->currentService
,
1508 pszParmName
, pszParmValue
);
1512 variable argument do parameter
1514 bool lpcfg_do_global_parameter_var(struct loadparm_context
*lp_ctx
, const char *pszParmName
, const char *fmt
, ...) PRINTF_ATTRIBUTE(3, 4);
1515 bool lpcfg_do_global_parameter_var(struct loadparm_context
*lp_ctx
,
1516 const char *pszParmName
, const char *fmt
, ...)
1523 s
= talloc_vasprintf(NULL
, fmt
, ap
);
1525 ret
= lpcfg_do_global_parameter(lp_ctx
, pszParmName
, s
);
1532 set a parameter from the commandline - this is called from command line parameter
1533 parsing code. It sets the parameter then marks the parameter as unable to be modified
1534 by smb.conf processing
1536 bool lpcfg_set_cmdline(struct loadparm_context
*lp_ctx
, const char *pszParmName
,
1537 const char *pszParmValue
)
1542 if (lp_ctx
->s3_fns
) {
1543 return lp_ctx
->s3_fns
->set_cmdline(pszParmName
, pszParmValue
);
1546 parmnum
= lpcfg_map_parameter(pszParmName
);
1548 while (isspace((unsigned char)*pszParmValue
)) pszParmValue
++;
1551 if (parmnum
< 0 && strchr(pszParmName
, ':')) {
1552 /* set a parametric option */
1553 return lp_do_parameter_parametric(lp_ctx
, NULL
, pszParmName
,
1554 pszParmValue
, FLAG_CMDLINE
);
1558 DEBUG(0,("Unknown option '%s'\n", pszParmName
));
1562 /* reset the CMDLINE flag in case this has been called before */
1563 lp_ctx
->flags
[parmnum
] &= ~FLAG_CMDLINE
;
1565 if (!lpcfg_do_global_parameter(lp_ctx
, pszParmName
, pszParmValue
)) {
1569 lp_ctx
->flags
[parmnum
] |= FLAG_CMDLINE
;
1571 /* we have to also set FLAG_CMDLINE on aliases */
1573 i
>=0 && parm_table
[i
].p_class
== parm_table
[parmnum
].p_class
&&
1574 parm_table
[i
].offset
== parm_table
[parmnum
].offset
;
1576 lp_ctx
->flags
[i
] |= FLAG_CMDLINE
;
1580 parm_table
[i
].p_class
== parm_table
[parmnum
].p_class
&&
1581 parm_table
[i
].offset
== parm_table
[parmnum
].offset
;
1583 lp_ctx
->flags
[i
] |= FLAG_CMDLINE
;
1590 set a option from the commandline in 'a=b' format. Use to support --option
1592 bool lpcfg_set_option(struct loadparm_context
*lp_ctx
, const char *option
)
1597 s
= talloc_strdup(NULL
, option
);
1610 ret
= lpcfg_set_cmdline(lp_ctx
, s
, p
+1);
1616 #define BOOLSTR(b) ((b) ? "Yes" : "No")
1619 * Print a parameter of the specified type.
1622 void lpcfg_print_parameter(struct parm_struct
*p
, void *ptr
, FILE * f
)
1624 /* For the seperation of lists values that we print below */
1625 const char *list_sep
= ", ";
1630 for (i
= 0; p
->enum_list
[i
].name
; i
++) {
1631 if (*(int *)ptr
== p
->enum_list
[i
].value
) {
1633 p
->enum_list
[i
].name
);
1640 fprintf(f
, "%s", BOOLSTR(*(bool *)ptr
));
1644 fprintf(f
, "%s", BOOLSTR(!*(bool *)ptr
));
1649 fprintf(f
, "%d", *(int *)ptr
);
1653 fprintf(f
, "%c", *(char *)ptr
);
1657 int val
= *(int *)ptr
;
1661 fprintf(f
, "0%03o", val
);
1670 if ((char ***)ptr
&& *(char ***)ptr
) {
1671 char **list
= *(char ***)ptr
;
1672 for (; *list
; list
++) {
1673 /* surround strings with whitespace in double quotes */
1674 if (*(list
+1) == NULL
) {
1675 /* last item, no extra separator */
1678 if ( strchr_m( *list
, ' ' ) ) {
1679 fprintf(f
, "\"%s\"%s", *list
, list_sep
);
1681 fprintf(f
, "%s%s", *list
, list_sep
);
1689 if (*(char **)ptr
) {
1690 fprintf(f
, "%s", *(char **)ptr
);
1699 * Check if two parameters are equal.
1702 bool lpcfg_equal_parameter(parm_type type
, void *ptr1
, void *ptr2
)
1707 return (*((bool *)ptr1
) == *((bool *)ptr2
));
1713 return (*((int *)ptr1
) == *((int *)ptr2
));
1716 return (*((char *)ptr1
) == *((char *)ptr2
));
1720 return str_list_equal(*(const char ***)ptr1
, *(const char ***)ptr2
);
1725 char *p1
= *(char **)ptr1
, *p2
= *(char **)ptr2
;
1730 return (p1
== p2
|| strequal(p1
, p2
));
1739 * Process a new section (service).
1741 * At this stage all sections are services.
1742 * Later we'll have special sections that permit server parameters to be set.
1743 * Returns True on success, False on failure.
1746 static bool do_section(const char *pszSectionName
, void *userdata
)
1748 struct loadparm_context
*lp_ctx
= (struct loadparm_context
*)userdata
;
1750 bool isglobal
= ((strwicmp(pszSectionName
, GLOBAL_NAME
) == 0) ||
1751 (strwicmp(pszSectionName
, GLOBAL_NAME2
) == 0));
1754 /* if we've just struck a global section, note the fact. */
1755 lp_ctx
->bInGlobalSection
= isglobal
;
1757 /* check for multiple global sections */
1758 if (lp_ctx
->bInGlobalSection
) {
1759 DEBUG(4, ("Processing section \"[%s]\"\n", pszSectionName
));
1763 /* if we have a current service, tidy it up before moving on */
1766 if (lp_ctx
->currentService
!= NULL
)
1767 bRetval
= lpcfg_service_ok(lp_ctx
->currentService
);
1769 /* if all is still well, move to the next record in the services array */
1771 /* We put this here to avoid an odd message order if messages are */
1772 /* issued by the post-processing of a previous section. */
1773 DEBUG(4, ("Processing section \"[%s]\"\n", pszSectionName
));
1775 if ((lp_ctx
->currentService
= lpcfg_add_service(lp_ctx
, lp_ctx
->sDefault
,
1778 DEBUG(0, ("Failed to add a new service\n"));
1788 * Determine if a particular base parameter is currently set to the default value.
1791 static bool is_default(struct loadparm_service
*sDefault
, int i
)
1793 void *def_ptr
= ((char *)sDefault
) + parm_table
[i
].offset
;
1794 switch (parm_table
[i
].type
) {
1797 return str_list_equal((const char * const *)parm_table
[i
].def
.lvalue
,
1798 (const char **)def_ptr
);
1801 return strequal(parm_table
[i
].def
.svalue
,
1805 return parm_table
[i
].def
.bvalue
==
1812 return parm_table
[i
].def
.ivalue
==
1821 *Display the contents of the global structure.
1824 static void dump_globals(struct loadparm_context
*lp_ctx
, FILE *f
,
1828 struct parmlist_entry
*data
;
1830 fprintf(f
, "# Global parameters\n[global]\n");
1832 for (i
= 0; parm_table
[i
].label
; i
++)
1833 if (parm_table
[i
].p_class
== P_GLOBAL
&&
1834 (i
== 0 || (parm_table
[i
].offset
!= parm_table
[i
- 1].offset
))) {
1835 if (!show_defaults
&& (lp_ctx
->flags
[i
] & FLAG_DEFAULT
))
1837 fprintf(f
, "\t%s = ", parm_table
[i
].label
);
1838 lpcfg_print_parameter(&parm_table
[i
], lpcfg_parm_ptr(lp_ctx
, NULL
, &parm_table
[i
]), f
);
1841 if (lp_ctx
->globals
->param_opt
!= NULL
) {
1842 for (data
= lp_ctx
->globals
->param_opt
; data
;
1843 data
= data
->next
) {
1844 if (!show_defaults
&& (data
->priority
& FLAG_DEFAULT
)) {
1847 fprintf(f
, "\t%s = %s\n", data
->key
, data
->value
);
1854 * Display the contents of a single services record.
1857 static void dump_a_service(struct loadparm_service
* pService
, struct loadparm_service
*sDefault
, FILE * f
,
1858 unsigned int *flags
)
1861 struct parmlist_entry
*data
;
1863 if (pService
!= sDefault
)
1864 fprintf(f
, "\n[%s]\n", pService
->szService
);
1866 for (i
= 0; parm_table
[i
].label
; i
++) {
1867 if (parm_table
[i
].p_class
== P_LOCAL
&&
1868 (*parm_table
[i
].label
!= '-') &&
1869 (i
== 0 || (parm_table
[i
].offset
!= parm_table
[i
- 1].offset
)))
1871 if (pService
== sDefault
) {
1872 if (flags
&& (flags
[i
] & FLAG_DEFAULT
)) {
1875 if (defaults_saved
) {
1876 if (is_default(sDefault
, i
)) {
1881 if (lpcfg_equal_parameter(parm_table
[i
].type
,
1882 ((char *)pService
) +
1883 parm_table
[i
].offset
,
1884 ((char *)sDefault
) +
1885 parm_table
[i
].offset
))
1889 fprintf(f
, "\t%s = ", parm_table
[i
].label
);
1890 lpcfg_print_parameter(&parm_table
[i
],
1891 ((char *)pService
) + parm_table
[i
].offset
, f
);
1895 if (pService
->param_opt
!= NULL
) {
1896 for (data
= pService
->param_opt
; data
; data
= data
->next
) {
1897 fprintf(f
, "\t%s = %s\n", data
->key
, data
->value
);
1902 bool lpcfg_dump_a_parameter(struct loadparm_context
*lp_ctx
,
1903 struct loadparm_service
*service
,
1904 const char *parm_name
, FILE * f
)
1906 struct parm_struct
*parm
;
1909 parm
= lpcfg_parm_struct(lp_ctx
, parm_name
);
1914 if (service
!= NULL
&& parm
->p_class
== P_GLOBAL
) {
1918 ptr
= lpcfg_parm_ptr(lp_ctx
, service
,parm
);
1920 lpcfg_print_parameter(parm
, ptr
, f
);
1926 * Auto-load some home services.
1928 static void lpcfg_add_auto_services(struct loadparm_context
*lp_ctx
,
1936 * Unload unused services.
1939 void lpcfg_killunused(struct loadparm_context
*lp_ctx
,
1940 struct smbsrv_connection
*smb
,
1941 bool (*snumused
) (struct smbsrv_connection
*, int))
1944 for (i
= 0; i
< lp_ctx
->iNumServices
; i
++) {
1945 if (lp_ctx
->services
[i
] == NULL
)
1948 if (!snumused
|| !snumused(smb
, i
)) {
1949 talloc_free(lp_ctx
->services
[i
]);
1950 lp_ctx
->services
[i
] = NULL
;
1956 static int lpcfg_destructor(struct loadparm_context
*lp_ctx
)
1958 struct parmlist_entry
*data
;
1960 if (lp_ctx
->refuse_free
) {
1961 /* someone is trying to free the
1962 global_loadparm_context.
1963 We can't allow that. */
1967 if (lp_ctx
->globals
->param_opt
!= NULL
) {
1968 struct parmlist_entry
*next
;
1969 for (data
= lp_ctx
->globals
->param_opt
; data
; data
=next
) {
1971 if (data
->priority
& FLAG_CMDLINE
) continue;
1972 DLIST_REMOVE(lp_ctx
->globals
->param_opt
, data
);
1981 * Initialise the global parameter structure.
1983 * Note that most callers should use loadparm_init_global() instead
1985 struct loadparm_context
*loadparm_init(TALLOC_CTX
*mem_ctx
)
1989 struct loadparm_context
*lp_ctx
;
1990 struct parmlist_entry
*parm
;
1993 lp_ctx
= talloc_zero(mem_ctx
, struct loadparm_context
);
1997 talloc_set_destructor(lp_ctx
, lpcfg_destructor
);
1998 lp_ctx
->bInGlobalSection
= true;
1999 lp_ctx
->globals
= talloc_zero(lp_ctx
, struct loadparm_global
);
2000 lp_ctx
->sDefault
= talloc_zero(lp_ctx
, struct loadparm_service
);
2002 lp_ctx
->sDefault
->iMaxPrintJobs
= 1000;
2003 lp_ctx
->sDefault
->bAvailable
= true;
2004 lp_ctx
->sDefault
->browseable
= true;
2005 lp_ctx
->sDefault
->read_only
= true;
2006 lp_ctx
->sDefault
->map_archive
= true;
2007 lp_ctx
->sDefault
->strict_locking
= true;
2008 lp_ctx
->sDefault
->oplocks
= true;
2009 lp_ctx
->sDefault
->create_mask
= 0744;
2010 lp_ctx
->sDefault
->force_create_mode
= 0000;
2011 lp_ctx
->sDefault
->directory_mask
= 0755;
2012 lp_ctx
->sDefault
->force_directory_mode
= 0000;
2014 DEBUG(3, ("Initialising global parameters\n"));
2016 for (i
= 0; parm_table
[i
].label
; i
++) {
2017 if ((parm_table
[i
].type
== P_STRING
||
2018 parm_table
[i
].type
== P_USTRING
) &&
2019 !(lp_ctx
->flags
[i
] & FLAG_CMDLINE
)) {
2021 if (parm_table
[i
].p_class
== P_LOCAL
) {
2022 r
= (char **)(((char *)lp_ctx
->sDefault
) + parm_table
[i
].offset
);
2024 r
= (char **)(((char *)lp_ctx
->globals
) + parm_table
[i
].offset
);
2026 *r
= talloc_strdup(lp_ctx
, "");
2030 logfile
= talloc_asprintf(lp_ctx
, "%s/log.samba", dyn_LOGFILEBASE
);
2031 lpcfg_do_global_parameter(lp_ctx
, "log file", logfile
);
2032 talloc_free(logfile
);
2034 lpcfg_do_global_parameter(lp_ctx
, "log level", "0");
2036 lpcfg_do_global_parameter(lp_ctx
, "syslog", "1");
2037 lpcfg_do_global_parameter(lp_ctx
, "syslog only", "No");
2038 lpcfg_do_global_parameter(lp_ctx
, "debug timestamp", "Yes");
2039 lpcfg_do_global_parameter(lp_ctx
, "debug prefix timestamp", "No");
2040 lpcfg_do_global_parameter(lp_ctx
, "debug hires timestamp", "Yes");
2041 lpcfg_do_global_parameter(lp_ctx
, "debug pid", "No");
2042 lpcfg_do_global_parameter(lp_ctx
, "debug uid", "No");
2043 lpcfg_do_global_parameter(lp_ctx
, "debug class", "No");
2045 lpcfg_do_global_parameter(lp_ctx
, "share backend", "classic");
2047 lpcfg_do_global_parameter(lp_ctx
, "server role", "auto");
2048 lpcfg_do_global_parameter(lp_ctx
, "domain logons", "No");
2049 lpcfg_do_global_parameter(lp_ctx
, "domain master", "Auto");
2051 /* options that can be set on the command line must be initialised via
2052 the slower lpcfg_do_global_parameter() to ensure that FLAG_CMDLINE is obeyed */
2054 lpcfg_do_global_parameter(lp_ctx
, "socket options", "TCP_NODELAY");
2056 lpcfg_do_global_parameter(lp_ctx
, "workgroup", DEFAULT_WORKGROUP
);
2057 myname
= get_myname(lp_ctx
);
2058 lpcfg_do_global_parameter(lp_ctx
, "netbios name", myname
);
2059 talloc_free(myname
);
2060 lpcfg_do_global_parameter(lp_ctx
, "name resolve order", "lmhosts wins host bcast");
2062 lpcfg_do_global_parameter(lp_ctx
, "fstype", "NTFS");
2064 lpcfg_do_global_parameter(lp_ctx
, "ntvfs handler", "unixuid default");
2065 lpcfg_do_global_parameter(lp_ctx
, "max connections", "0");
2067 lpcfg_do_global_parameter(lp_ctx
, "dcerpc endpoint servers", "epmapper wkssvc rpcecho samr netlogon lsarpc spoolss drsuapi dssetup unixinfo browser eventlog6 backupkey dnsserver");
2068 lpcfg_do_global_parameter(lp_ctx
, "server services", "s3fs rpc nbt wrepl ldap cldap kdc drepl winbind ntp_signd kcc dnsupdate dns");
2069 lpcfg_do_global_parameter(lp_ctx
, "kccsrv:samba_kcc", "true");
2070 /* the winbind method for domain controllers is for both RODC
2071 auth forwarding and for trusted domains */
2072 lpcfg_do_global_parameter(lp_ctx
, "private dir", dyn_PRIVATE_DIR
);
2073 lpcfg_do_global_parameter(lp_ctx
, "registry:HKEY_LOCAL_MACHINE", "hklm.ldb");
2075 /* This hive should be dynamically generated by Samba using
2076 data from the sam, but for the moment leave it in a tdb to
2077 keep regedt32 from popping up an annoying dialog. */
2078 lpcfg_do_global_parameter(lp_ctx
, "registry:HKEY_USERS", "hku.ldb");
2080 /* using UTF8 by default allows us to support all chars */
2081 lpcfg_do_global_parameter(lp_ctx
, "unix charset", "UTF-8");
2083 /* Use codepage 850 as a default for the dos character set */
2084 lpcfg_do_global_parameter(lp_ctx
, "dos charset", "CP850");
2087 * Allow the default PASSWD_CHAT to be overridden in local.h.
2089 lpcfg_do_global_parameter(lp_ctx
, "passwd chat", DEFAULT_PASSWD_CHAT
);
2091 lpcfg_do_global_parameter(lp_ctx
, "pid directory", dyn_PIDDIR
);
2092 lpcfg_do_global_parameter(lp_ctx
, "lock dir", dyn_LOCKDIR
);
2093 lpcfg_do_global_parameter(lp_ctx
, "state directory", dyn_STATEDIR
);
2094 lpcfg_do_global_parameter(lp_ctx
, "cache directory", dyn_CACHEDIR
);
2095 lpcfg_do_global_parameter(lp_ctx
, "ncalrpc dir", dyn_NCALRPCDIR
);
2097 lpcfg_do_global_parameter(lp_ctx
, "nbt client socket address", "0.0.0.0");
2098 lpcfg_do_global_parameter_var(lp_ctx
, "server string",
2099 "Samba %s", SAMBA_VERSION_STRING
);
2101 lpcfg_do_global_parameter(lp_ctx
, "password server", "*");
2103 lpcfg_do_global_parameter(lp_ctx
, "max mux", "50");
2104 lpcfg_do_global_parameter(lp_ctx
, "max xmit", "16644");
2105 lpcfg_do_global_parameter(lp_ctx
, "host msdfs", "true");
2107 lpcfg_do_global_parameter(lp_ctx
, "LargeReadwrite", "True");
2108 lpcfg_do_global_parameter(lp_ctx
, "server min protocol", "LANMAN1");
2109 lpcfg_do_global_parameter(lp_ctx
, "server max protocol", "SMB3");
2110 lpcfg_do_global_parameter(lp_ctx
, "client min protocol", "CORE");
2111 lpcfg_do_global_parameter(lp_ctx
, "client max protocol", "NT1");
2112 lpcfg_do_global_parameter(lp_ctx
, "security", "AUTO");
2113 lpcfg_do_global_parameter(lp_ctx
, "EncryptPasswords", "True");
2114 lpcfg_do_global_parameter(lp_ctx
, "ReadRaw", "True");
2115 lpcfg_do_global_parameter(lp_ctx
, "WriteRaw", "True");
2116 lpcfg_do_global_parameter(lp_ctx
, "NullPasswords", "False");
2117 lpcfg_do_global_parameter(lp_ctx
, "old password allowed period", "60");
2118 lpcfg_do_global_parameter(lp_ctx
, "ObeyPamRestrictions", "False");
2120 lpcfg_do_global_parameter(lp_ctx
, "TimeServer", "False");
2121 lpcfg_do_global_parameter(lp_ctx
, "BindInterfacesOnly", "False");
2122 lpcfg_do_global_parameter(lp_ctx
, "Unicode", "True");
2123 lpcfg_do_global_parameter(lp_ctx
, "ClientLanManAuth", "False");
2124 lpcfg_do_global_parameter(lp_ctx
, "ClientNTLMv2Auth", "True");
2125 lpcfg_do_global_parameter(lp_ctx
, "LanmanAuth", "False");
2126 lpcfg_do_global_parameter(lp_ctx
, "NTLMAuth", "True");
2127 lpcfg_do_global_parameter(lp_ctx
, "client use spnego principal", "False");
2129 lpcfg_do_global_parameter(lp_ctx
, "UnixExtensions", "True");
2131 lpcfg_do_global_parameter(lp_ctx
, "PreferredMaster", "Auto");
2132 lpcfg_do_global_parameter(lp_ctx
, "LocalMaster", "True");
2134 lpcfg_do_global_parameter(lp_ctx
, "wins support", "False");
2135 lpcfg_do_global_parameter(lp_ctx
, "dns proxy", "True");
2137 lpcfg_do_global_parameter(lp_ctx
, "winbind separator", "\\");
2138 lpcfg_do_global_parameter(lp_ctx
, "winbind sealed pipes", "True");
2139 lpcfg_do_global_parameter(lp_ctx
, "require strong key", "True");
2140 lpcfg_do_global_parameter(lp_ctx
, "winbindd socket directory", dyn_WINBINDD_SOCKET_DIR
);
2141 lpcfg_do_global_parameter(lp_ctx
, "winbindd privileged socket directory", dyn_WINBINDD_PRIVILEGED_SOCKET_DIR
);
2142 lpcfg_do_global_parameter(lp_ctx
, "ntp signd socket directory", dyn_NTP_SIGND_SOCKET_DIR
);
2143 lpcfg_do_global_parameter_var(lp_ctx
, "dns update command", "%s/samba_dnsupdate", dyn_SCRIPTSBINDIR
);
2144 lpcfg_do_global_parameter_var(lp_ctx
, "spn update command", "%s/samba_spnupdate", dyn_SCRIPTSBINDIR
);
2145 lpcfg_do_global_parameter_var(lp_ctx
, "samba kcc command",
2146 "%s/samba_kcc", dyn_SCRIPTSBINDIR
);
2147 lpcfg_do_global_parameter(lp_ctx
, "template shell", "/bin/false");
2148 lpcfg_do_global_parameter(lp_ctx
, "template homedir", "/home/%WORKGROUP%/%ACCOUNTNAME%");
2150 lpcfg_do_global_parameter(lp_ctx
, "client signing", "default");
2151 lpcfg_do_global_parameter(lp_ctx
, "server signing", "default");
2153 lpcfg_do_global_parameter(lp_ctx
, "use spnego", "True");
2155 lpcfg_do_global_parameter(lp_ctx
, "use mmap", "True");
2157 lpcfg_do_global_parameter(lp_ctx
, "smb ports", "445 139");
2158 lpcfg_do_global_parameter(lp_ctx
, "nbt port", "137");
2159 lpcfg_do_global_parameter(lp_ctx
, "dgram port", "138");
2160 lpcfg_do_global_parameter(lp_ctx
, "cldap port", "389");
2161 lpcfg_do_global_parameter(lp_ctx
, "krb5 port", "88");
2162 lpcfg_do_global_parameter(lp_ctx
, "kpasswd port", "464");
2163 lpcfg_do_global_parameter(lp_ctx
, "web port", "901");
2165 lpcfg_do_global_parameter(lp_ctx
, "nt status support", "True");
2167 lpcfg_do_global_parameter(lp_ctx
, "max wins ttl", "518400"); /* 6 days */
2168 lpcfg_do_global_parameter(lp_ctx
, "min wins ttl", "21600");
2170 lpcfg_do_global_parameter(lp_ctx
, "tls enabled", "True");
2171 lpcfg_do_global_parameter(lp_ctx
, "tls keyfile", "tls/key.pem");
2172 lpcfg_do_global_parameter(lp_ctx
, "tls certfile", "tls/cert.pem");
2173 lpcfg_do_global_parameter(lp_ctx
, "tls cafile", "tls/ca.pem");
2174 lpcfg_do_global_parameter(lp_ctx
, "prefork children:smb", "4");
2176 lpcfg_do_global_parameter(lp_ctx
, "rndc command", "/usr/sbin/rndc");
2177 lpcfg_do_global_parameter(lp_ctx
, "nsupdate command", "/usr/bin/nsupdate -g");
2179 lpcfg_do_global_parameter(lp_ctx
, "allow dns updates", "secure only");
2180 lpcfg_do_global_parameter(lp_ctx
, "dns forwarder", "");
2182 lpcfg_do_global_parameter(lp_ctx
, "algorithmic rid base", "1000");
2184 lpcfg_do_global_parameter(lp_ctx
, "enhanced browsing", "True");
2186 lpcfg_do_global_parameter(lp_ctx
, "winbind nss info", "template");
2188 lpcfg_do_global_parameter(lp_ctx
, "server schannel", "Auto");
2190 lpcfg_do_global_parameter(lp_ctx
, "short preserve case", "True");
2192 lpcfg_do_global_parameter(lp_ctx
, "max open files", "16384");
2194 lpcfg_do_global_parameter(lp_ctx
, "cups connection timeout", "30");
2196 lpcfg_do_global_parameter(lp_ctx
, "locking", "True");
2198 lpcfg_do_global_parameter(lp_ctx
, "block size", "1024");
2200 lpcfg_do_global_parameter(lp_ctx
, "client use spnego", "True");
2202 lpcfg_do_global_parameter(lp_ctx
, "change notify", "True");
2204 lpcfg_do_global_parameter(lp_ctx
, "name cache timeout", "660");
2206 lpcfg_do_global_parameter(lp_ctx
, "defer sharing violations", "True");
2208 lpcfg_do_global_parameter(lp_ctx
, "ldap replication sleep", "1000");
2210 lpcfg_do_global_parameter(lp_ctx
, "idmap backend", "tdb");
2212 lpcfg_do_global_parameter(lp_ctx
, "enable privileges", "True");
2214 lpcfg_do_global_parameter_var(lp_ctx
, "smb2 max write", "%u", DEFAULT_SMB2_MAX_WRITE
);
2216 lpcfg_do_global_parameter(lp_ctx
, "passdb backend", "tdbsam");
2218 lpcfg_do_global_parameter(lp_ctx
, "getwd cache", "True");
2220 lpcfg_do_global_parameter(lp_ctx
, "winbind nested groups", "True");
2222 lpcfg_do_global_parameter(lp_ctx
, "mangled names", "True");
2224 lpcfg_do_global_parameter_var(lp_ctx
, "smb2 max credits", "%u", DEFAULT_SMB2_MAX_CREDITS
);
2226 lpcfg_do_global_parameter(lp_ctx
, "ldap ssl", "start tls");
2228 lpcfg_do_global_parameter(lp_ctx
, "ldap deref", "auto");
2230 lpcfg_do_global_parameter(lp_ctx
, "lm interval", "60");
2232 lpcfg_do_global_parameter(lp_ctx
, "mangling method", "hash2");
2234 lpcfg_do_global_parameter(lp_ctx
, "hide dot files", "True");
2236 lpcfg_do_global_parameter(lp_ctx
, "browse list", "True");
2238 lpcfg_do_global_parameter(lp_ctx
, "passwd chat timeout", "2");
2240 lpcfg_do_global_parameter(lp_ctx
, "guest account", GUEST_ACCOUNT
);
2242 lpcfg_do_global_parameter(lp_ctx
, "client schannel", "auto");
2244 lpcfg_do_global_parameter(lp_ctx
, "smb encrypt", "default");
2246 lpcfg_do_global_parameter(lp_ctx
, "max log size", "5000");
2248 lpcfg_do_global_parameter(lp_ctx
, "idmap negative cache time", "120");
2250 lpcfg_do_global_parameter(lp_ctx
, "ldap follow referral", "auto");
2252 lpcfg_do_global_parameter(lp_ctx
, "multicast dns register", "yes");
2254 lpcfg_do_global_parameter(lp_ctx
, "winbind reconnect delay", "30");
2256 lpcfg_do_global_parameter(lp_ctx
, "nt acl support", "yes");
2258 lpcfg_do_global_parameter(lp_ctx
, "acl check permissions", "yes");
2260 lpcfg_do_global_parameter(lp_ctx
, "keepalive", "300");
2262 lpcfg_do_global_parameter(lp_ctx
, "winbind cache time", "300");
2264 lpcfg_do_global_parameter(lp_ctx
, "level2 oplocks", "yes");
2266 lpcfg_do_global_parameter(lp_ctx
, "show add printer wizard", "yes");
2268 lpcfg_do_global_parameter(lp_ctx
, "allocation roundup size", "1048576");
2270 lpcfg_do_global_parameter(lp_ctx
, "ldap page size", "1024");
2272 lpcfg_do_global_parameter(lp_ctx
, "kernel share modes", "yes");
2274 lpcfg_do_global_parameter(lp_ctx
, "strict locking", "Auto");
2276 lpcfg_do_global_parameter(lp_ctx
, "map readonly", "yes");
2278 lpcfg_do_global_parameter(lp_ctx
, "allow trusted domains", "yes");
2280 lpcfg_do_global_parameter(lp_ctx
, "default devmode", "yes");
2282 lpcfg_do_global_parameter(lp_ctx
, "os level", "20");
2284 lpcfg_do_global_parameter(lp_ctx
, "dos filetimes", "yes");
2286 lpcfg_do_global_parameter(lp_ctx
, "mangling char", "~");
2288 lpcfg_do_global_parameter(lp_ctx
, "printcap cache time", "750");
2290 lpcfg_do_global_parameter(lp_ctx
, "create krb5 conf", "yes");
2292 lpcfg_do_global_parameter(lp_ctx
, "winbind max clients", "200");
2294 lpcfg_do_global_parameter(lp_ctx
, "acl map full control", "yes");
2296 lpcfg_do_global_parameter(lp_ctx
, "nt pipe support", "yes");
2298 lpcfg_do_global_parameter(lp_ctx
, "ldap debug threshold", "10");
2300 lpcfg_do_global_parameter(lp_ctx
, "follow symlinks", "yes");
2302 lpcfg_do_global_parameter(lp_ctx
, "machine password timeout", "604800");
2304 lpcfg_do_global_parameter(lp_ctx
, "ldap connection timeout", "2");
2306 lpcfg_do_global_parameter(lp_ctx
, "winbind expand groups", "1");
2308 lpcfg_do_global_parameter(lp_ctx
, "stat cache", "yes");
2310 lpcfg_do_global_parameter(lp_ctx
, "lpq cache time", "30");
2312 lpcfg_do_global_parameter_var(lp_ctx
, "smb2 max trans", "%u", DEFAULT_SMB2_MAX_TRANSACT
);
2314 lpcfg_do_global_parameter_var(lp_ctx
, "smb2 max read", "%u", DEFAULT_SMB2_MAX_READ
);
2316 lpcfg_do_global_parameter(lp_ctx
, "durable handles", "yes");
2318 lpcfg_do_global_parameter(lp_ctx
, "max stat cache size", "256");
2320 lpcfg_do_global_parameter(lp_ctx
, "ldap passwd sync", "no");
2322 lpcfg_do_global_parameter(lp_ctx
, "kernel change notify", "yes");
2324 lpcfg_do_global_parameter(lp_ctx
, "max ttl", "259200");
2326 lpcfg_do_global_parameter(lp_ctx
, "blocking locks", "yes");
2328 lpcfg_do_global_parameter(lp_ctx
, "oplock contention limit", "2");
2330 lpcfg_do_global_parameter(lp_ctx
, "load printers", "yes");
2332 lpcfg_do_global_parameter(lp_ctx
, "idmap cache time", "604800");
2334 lpcfg_do_global_parameter(lp_ctx
, "preserve case", "yes");
2336 lpcfg_do_global_parameter(lp_ctx
, "lm announce", "auto");
2338 lpcfg_do_global_parameter(lp_ctx
, "afs token lifetime", "604800");
2340 lpcfg_do_global_parameter(lp_ctx
, "enable core files", "yes");
2342 lpcfg_do_global_parameter(lp_ctx
, "winbind max domain connections", "1");
2344 lpcfg_do_global_parameter(lp_ctx
, "case sensitive", "auto");
2346 lpcfg_do_global_parameter(lp_ctx
, "ldap timeout", "15");
2348 lpcfg_do_global_parameter(lp_ctx
, "mangle prefix", "1");
2350 lpcfg_do_global_parameter(lp_ctx
, "posix locking", "yes");
2352 lpcfg_do_global_parameter(lp_ctx
, "lock spin time", "200");
2354 lpcfg_do_global_parameter(lp_ctx
, "directory name cache size", "100");
2356 lpcfg_do_global_parameter(lp_ctx
, "nmbd bind explicit broadcast", "yes");
2358 lpcfg_do_global_parameter(lp_ctx
, "init logon delay", "100");
2360 lpcfg_do_global_parameter(lp_ctx
, "usershare owner only", "yes");
2362 lpcfg_do_global_parameter(lp_ctx
, "-valid", "yes");
2364 lpcfg_do_global_parameter_var(lp_ctx
, "usershare path", "%s/usershares", get_dyn_STATEDIR());
2367 lpcfg_do_global_parameter_var(lp_ctx
, "panic action", "/bin/sleep 999999999");
2370 lpcfg_do_global_parameter(lp_ctx
, "smb passwd file", get_dyn_SMB_PASSWD_FILE());
2372 lpcfg_do_global_parameter(lp_ctx
, "logon home", "\\\\%N\\%U");
2374 lpcfg_do_global_parameter(lp_ctx
, "logon path", "\\\\%N\\%U\\profile");
2376 lpcfg_do_global_parameter(lp_ctx
, "printjob username", "%U");
2378 for (i
= 0; parm_table
[i
].label
; i
++) {
2379 if (!(lp_ctx
->flags
[i
] & FLAG_CMDLINE
)) {
2380 lp_ctx
->flags
[i
] |= FLAG_DEFAULT
;
2384 for (parm
=lp_ctx
->globals
->param_opt
; parm
; parm
=parm
->next
) {
2385 if (!(parm
->priority
& FLAG_CMDLINE
)) {
2386 parm
->priority
|= FLAG_DEFAULT
;
2394 * Initialise the global parameter structure.
2396 struct loadparm_context
*loadparm_init_global(bool load_default
)
2398 if (global_loadparm_context
== NULL
) {
2399 global_loadparm_context
= loadparm_init(NULL
);
2401 if (global_loadparm_context
== NULL
) {
2404 global_loadparm_context
->global
= true;
2405 if (load_default
&& !global_loadparm_context
->loaded
) {
2406 lpcfg_load_default(global_loadparm_context
);
2408 global_loadparm_context
->refuse_free
= true;
2409 return global_loadparm_context
;
2413 * Initialise the global parameter structure.
2415 struct loadparm_context
*loadparm_init_s3(TALLOC_CTX
*mem_ctx
,
2416 const struct loadparm_s3_helpers
*s3_fns
)
2418 struct loadparm_context
*loadparm_context
= talloc_zero(mem_ctx
, struct loadparm_context
);
2419 if (!loadparm_context
) {
2422 loadparm_context
->s3_fns
= s3_fns
;
2423 loadparm_context
->globals
= s3_fns
->globals
;
2424 return loadparm_context
;
2427 const char *lpcfg_configfile(struct loadparm_context
*lp_ctx
)
2429 return lp_ctx
->szConfigFile
;
2432 const char *lp_default_path(void)
2434 if (getenv("SMB_CONF_PATH"))
2435 return getenv("SMB_CONF_PATH");
2437 return dyn_CONFIGFILE
;
2441 * Update the internal state of a loadparm context after settings
2444 static bool lpcfg_update(struct loadparm_context
*lp_ctx
)
2446 struct debug_settings settings
;
2447 TALLOC_CTX
*tmp_ctx
;
2449 tmp_ctx
= talloc_new(lp_ctx
);
2450 if (tmp_ctx
== NULL
) {
2454 lpcfg_add_auto_services(lp_ctx
, lpcfg_auto_services(lp_ctx
, tmp_ctx
));
2456 if (!lp_ctx
->globals
->wins_server_list
&& lp_ctx
->globals
->we_are_a_wins_server
) {
2457 lpcfg_do_global_parameter(lp_ctx
, "wins server", "127.0.0.1");
2460 if (!lp_ctx
->global
) {
2461 TALLOC_FREE(tmp_ctx
);
2465 panic_action
= lp_ctx
->globals
->panic_action
;
2467 reload_charcnv(lp_ctx
);
2469 ZERO_STRUCT(settings
);
2470 /* Add any more debug-related smb.conf parameters created in
2472 settings
.syslog
= lp_ctx
->globals
->syslog
;
2473 settings
.syslog_only
= lp_ctx
->globals
->syslog_only
;
2474 settings
.timestamp_logs
= lp_ctx
->globals
->timestamp_logs
;
2475 settings
.debug_prefix_timestamp
= lp_ctx
->globals
->debug_prefix_timestamp
;
2476 settings
.debug_hires_timestamp
= lp_ctx
->globals
->debug_hires_timestamp
;
2477 settings
.debug_pid
= lp_ctx
->globals
->debug_pid
;
2478 settings
.debug_uid
= lp_ctx
->globals
->debug_uid
;
2479 settings
.debug_class
= lp_ctx
->globals
->debug_class
;
2480 debug_set_settings(&settings
);
2482 /* FIXME: This is a bit of a hack, but we can't use a global, since
2483 * not everything that uses lp also uses the socket library */
2484 if (lpcfg_parm_bool(lp_ctx
, NULL
, "socket", "testnonblock", false)) {
2485 setenv("SOCKET_TESTNONBLOCK", "1", 1);
2487 unsetenv("SOCKET_TESTNONBLOCK");
2490 TALLOC_FREE(tmp_ctx
);
2494 bool lpcfg_load_default(struct loadparm_context
*lp_ctx
)
2498 path
= lp_default_path();
2500 if (!file_exist(path
)) {
2501 /* We allow the default smb.conf file to not exist,
2502 * basically the equivalent of an empty file. */
2503 return lpcfg_update(lp_ctx
);
2506 return lpcfg_load(lp_ctx
, path
);
2510 * Load the services array from the services file.
2512 * Return True on success, False on failure.
2514 bool lpcfg_load(struct loadparm_context
*lp_ctx
, const char *filename
)
2519 filename
= talloc_strdup(lp_ctx
, filename
);
2521 lp_ctx
->szConfigFile
= filename
;
2523 if (lp_ctx
->s3_fns
) {
2524 return lp_ctx
->s3_fns
->load(filename
);
2527 lp_ctx
->bInGlobalSection
= true;
2528 n2
= standard_sub_basic(lp_ctx
, lp_ctx
->szConfigFile
);
2529 DEBUG(2, ("lpcfg_load: refreshing parameters from %s\n", n2
));
2531 add_to_file_list(lp_ctx
, lp_ctx
->szConfigFile
, n2
);
2533 /* We get sections first, so have to start 'behind' to make up */
2534 lp_ctx
->currentService
= NULL
;
2535 bRetval
= pm_process(n2
, do_section
, do_parameter
, lp_ctx
);
2537 /* finish up the last section */
2538 DEBUG(4, ("pm_process() returned %s\n", BOOLSTR(bRetval
)));
2540 if (lp_ctx
->currentService
!= NULL
)
2541 bRetval
= lpcfg_service_ok(lp_ctx
->currentService
);
2543 bRetval
= bRetval
&& lpcfg_update(lp_ctx
);
2545 /* we do this unconditionally, so that it happens even
2546 for a missing smb.conf */
2547 reload_charcnv(lp_ctx
);
2549 if (bRetval
== true) {
2550 /* set this up so that any child python tasks will
2551 find the right smb.conf */
2552 setenv("SMB_CONF_PATH", filename
, 1);
2554 /* set the context used by the lp_*() function
2556 global_loadparm_context
= lp_ctx
;
2557 lp_ctx
->loaded
= true;
2564 * Return the max number of services.
2567 int lpcfg_numservices(struct loadparm_context
*lp_ctx
)
2569 if (lp_ctx
->s3_fns
) {
2570 return lp_ctx
->s3_fns
->get_numservices();
2573 return lp_ctx
->iNumServices
;
2577 * Display the contents of the services array in human-readable form.
2580 void lpcfg_dump(struct loadparm_context
*lp_ctx
, FILE *f
, bool show_defaults
,
2585 if (lp_ctx
->s3_fns
) {
2586 lp_ctx
->s3_fns
->dump(f
, show_defaults
, maxtoprint
);
2590 defaults_saved
= !show_defaults
;
2592 dump_globals(lp_ctx
, f
, show_defaults
);
2594 dump_a_service(lp_ctx
->sDefault
, lp_ctx
->sDefault
, f
, lp_ctx
->flags
);
2596 for (iService
= 0; iService
< maxtoprint
; iService
++)
2597 lpcfg_dump_one(f
, show_defaults
, lp_ctx
->services
[iService
], lp_ctx
->sDefault
);
2601 * Display the contents of one service in human-readable form.
2603 void lpcfg_dump_one(FILE *f
, bool show_defaults
, struct loadparm_service
*service
, struct loadparm_service
*sDefault
)
2605 if (service
!= NULL
) {
2606 if (service
->szService
[0] == '\0')
2608 dump_a_service(service
, sDefault
, f
, NULL
);
2612 struct loadparm_service
*lpcfg_servicebynum(struct loadparm_context
*lp_ctx
,
2615 if (lp_ctx
->s3_fns
) {
2616 return lp_ctx
->s3_fns
->get_servicebynum(snum
);
2619 return lp_ctx
->services
[snum
];
2622 struct loadparm_service
*lpcfg_service(struct loadparm_context
*lp_ctx
,
2623 const char *service_name
)
2628 if (lp_ctx
->s3_fns
) {
2629 return lp_ctx
->s3_fns
->get_service(service_name
);
2632 for (iService
= lp_ctx
->iNumServices
- 1; iService
>= 0; iService
--) {
2633 if (lp_ctx
->services
[iService
] &&
2634 lp_ctx
->services
[iService
]->szService
) {
2636 * The substitution here is used to support %U is
2639 serviceName
= standard_sub_basic(
2640 lp_ctx
->services
[iService
],
2641 lp_ctx
->services
[iService
]->szService
);
2642 if (strequal(serviceName
, service_name
)) {
2643 talloc_free(serviceName
);
2644 return lp_ctx
->services
[iService
];
2646 talloc_free(serviceName
);
2650 DEBUG(7,("lpcfg_servicenumber: couldn't find %s\n", service_name
));
2654 const char *lpcfg_servicename(const struct loadparm_service
*service
)
2656 return lpcfg_string((const char *)service
->szService
);
2660 * A useful volume label function.
2662 const char *lpcfg_volume_label(struct loadparm_service
*service
, struct loadparm_service
*sDefault
)
2665 ret
= lpcfg_string((const char *)((service
!= NULL
&& service
->volume
!= NULL
) ?
2666 service
->volume
: sDefault
->volume
));
2668 return lpcfg_servicename(service
);
2673 * Return the correct printer name.
2675 const char *lpcfg_printername(struct loadparm_service
*service
, struct loadparm_service
*sDefault
)
2678 ret
= lpcfg_string((const char *)((service
!= NULL
&& service
->_printername
!= NULL
) ?
2679 service
->_printername
: sDefault
->_printername
));
2680 if (ret
== NULL
|| (ret
!= NULL
&& *ret
== '\0'))
2681 ret
= lpcfg_servicename(service
);
2688 * Return the max print jobs per queue.
2690 int lpcfg_maxprintjobs(struct loadparm_service
*service
, struct loadparm_service
*sDefault
)
2692 int maxjobs
= (service
!= NULL
) ? service
->iMaxPrintJobs
: sDefault
->iMaxPrintJobs
;
2693 if (maxjobs
<= 0 || maxjobs
>= PRINT_MAX_JOBID
)
2694 maxjobs
= PRINT_MAX_JOBID
- 1;
2699 struct smb_iconv_handle
*lpcfg_iconv_handle(struct loadparm_context
*lp_ctx
)
2701 if (lp_ctx
== NULL
) {
2702 return get_iconv_handle();
2704 return lp_ctx
->iconv_handle
;
2707 _PUBLIC_
void reload_charcnv(struct loadparm_context
*lp_ctx
)
2709 struct smb_iconv_handle
*old_ic
= lp_ctx
->iconv_handle
;
2710 if (!lp_ctx
->global
) {
2714 if (old_ic
== NULL
) {
2715 old_ic
= global_iconv_handle
;
2717 lp_ctx
->iconv_handle
= smb_iconv_handle_reinit_lp(lp_ctx
, lp_ctx
, old_ic
);
2718 global_iconv_handle
= lp_ctx
->iconv_handle
;
2721 _PUBLIC_
char *lpcfg_tls_keyfile(TALLOC_CTX
*mem_ctx
, struct loadparm_context
*lp_ctx
)
2723 return lpcfg_private_path(mem_ctx
, lp_ctx
, lpcfg__tls_keyfile(lp_ctx
));
2726 _PUBLIC_
char *lpcfg_tls_certfile(TALLOC_CTX
*mem_ctx
, struct loadparm_context
*lp_ctx
)
2728 return lpcfg_private_path(mem_ctx
, lp_ctx
, lpcfg__tls_certfile(lp_ctx
));
2731 _PUBLIC_
char *lpcfg_tls_cafile(TALLOC_CTX
*mem_ctx
, struct loadparm_context
*lp_ctx
)
2733 return lpcfg_private_path(mem_ctx
, lp_ctx
, lpcfg__tls_cafile(lp_ctx
));
2736 _PUBLIC_
char *lpcfg_tls_crlfile(TALLOC_CTX
*mem_ctx
, struct loadparm_context
*lp_ctx
)
2738 return lpcfg_private_path(mem_ctx
, lp_ctx
, lpcfg__tls_crlfile(lp_ctx
));
2741 _PUBLIC_
char *lpcfg_tls_dhpfile(TALLOC_CTX
*mem_ctx
, struct loadparm_context
*lp_ctx
)
2743 return lpcfg_private_path(mem_ctx
, lp_ctx
, lpcfg__tls_dhpfile(lp_ctx
));
2746 struct gensec_settings
*lpcfg_gensec_settings(TALLOC_CTX
*mem_ctx
, struct loadparm_context
*lp_ctx
)
2748 struct gensec_settings
*settings
= talloc_zero(mem_ctx
, struct gensec_settings
);
2749 if (settings
== NULL
)
2751 SMB_ASSERT(lp_ctx
!= NULL
);
2752 settings
->lp_ctx
= talloc_reference(settings
, lp_ctx
);
2753 settings
->target_hostname
= lpcfg_parm_string(lp_ctx
, NULL
, "gensec", "target_hostname");
2757 int lpcfg_server_role(struct loadparm_context
*lp_ctx
)
2759 int domain_master
= lpcfg__domain_master(lp_ctx
);
2761 return lp_find_server_role(lpcfg__server_role(lp_ctx
),
2762 lpcfg__security(lp_ctx
),
2763 lpcfg__domain_logons(lp_ctx
),
2764 (domain_master
== true) ||
2765 (domain_master
== Auto
));
2768 int lpcfg_security(struct loadparm_context
*lp_ctx
)
2770 return lp_find_security(lpcfg__server_role(lp_ctx
),
2771 lpcfg__security(lp_ctx
));
2774 bool lpcfg_server_signing_allowed(struct loadparm_context
*lp_ctx
, bool *mandatory
)
2776 bool allowed
= true;
2777 enum smb_signing_setting signing_setting
= lpcfg_server_signing(lp_ctx
);
2781 if (signing_setting
== SMB_SIGNING_DEFAULT
) {
2783 * If we are a domain controller, SMB signing is
2784 * really important, as it can prevent a number of
2785 * attacks on communications between us and the
2788 * However, it really sucks (no sendfile, CPU
2789 * overhead) performance-wise when used on a
2790 * file server, so disable it by default
2794 if (lpcfg_server_role(lp_ctx
) >= ROLE_ACTIVE_DIRECTORY_DC
) {
2795 signing_setting
= SMB_SIGNING_REQUIRED
;
2797 signing_setting
= SMB_SIGNING_OFF
;
2801 switch (signing_setting
) {
2802 case SMB_SIGNING_REQUIRED
:
2805 case SMB_SIGNING_IF_REQUIRED
:
2807 case SMB_SIGNING_DEFAULT
:
2808 case SMB_SIGNING_OFF
:
2816 int lpcfg_tdb_hash_size(struct loadparm_context
*lp_ctx
, const char *name
)
2824 base
= strrchr_m(name
, '/');
2830 return lpcfg_parm_int(lp_ctx
, NULL
, "tdb_hashsize", base
, 0);
2834 int lpcfg_tdb_flags(struct loadparm_context
*lp_ctx
, int tdb_flags
)
2836 if (!lpcfg_use_mmap(lp_ctx
)) {
2837 tdb_flags
|= TDB_NOMMAP
;