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