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 struct loadparm_service
*lpcfg_default_service(struct loadparm_context
*lp_ctx
)
81 return lp_ctx
->s3_fns
->get_default_loadparm_service();
83 return lp_ctx
->sDefault
;
87 * Convenience routine to grab string parameters into temporary memory
88 * and run standard_sub_basic on them.
90 * The buffers can be written to by
91 * callers without affecting the source string.
94 static const char *lpcfg_string(const char *s
)
96 #if 0 /* until REWRITE done to make thread-safe */
97 size_t len
= s
? strlen(s
) : 0;
101 /* The follow debug is useful for tracking down memory problems
102 especially if you have an inner loop that is calling a lp_*()
103 function that returns a string. Perhaps this debug should be
104 present all the time? */
107 DEBUG(10, ("lpcfg_string(%s)\n", s
));
110 #if 0 /* until REWRITE done to make thread-safe */
112 lp_talloc
= talloc_init("lp_talloc");
114 ret
= talloc_array(lp_talloc
, char, len
+ 100); /* leave room for substitution */
122 strlcpy(ret
, s
, len
);
124 if (trim_string(ret
, "\"", "\"")) {
125 if (strchr(ret
,'"') != NULL
)
126 strlcpy(ret
, s
, len
);
129 standard_sub_basic(ret
,len
+100);
136 In this section all the functions that are used to access the
137 parameters from the rest of the program are defined
141 * the creation of separate lpcfg_*() and lp_*() functions is to allow
142 * for code compatibility between existing Samba4 and Samba3 code.
145 /* this global context supports the lp_*() function varients */
146 static struct loadparm_context
*global_loadparm_context
;
148 #define lpcfg_default_service global_loadparm_context->sDefault
149 #define lpcfg_global_service(i) global_loadparm_context->services[i]
151 #define FN_GLOBAL_STRING(fn_name,var_name) \
152 _PUBLIC_ char *lpcfg_ ## fn_name(struct loadparm_context *lp_ctx, TALLOC_CTX *ctx) {\
153 if (lp_ctx == NULL) return NULL; \
154 if (lp_ctx->s3_fns) { \
155 return lp_ctx->globals->var_name ? lp_ctx->s3_fns->lp_string(ctx, lp_ctx->globals->var_name) : talloc_strdup(ctx, ""); \
157 return lp_ctx->globals->var_name ? talloc_strdup(ctx, lpcfg_string(lp_ctx->globals->var_name)) : talloc_strdup(ctx, ""); \
160 #define FN_GLOBAL_CONST_STRING(fn_name,var_name) \
161 _PUBLIC_ const char *lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) { \
162 if (lp_ctx == NULL) return NULL; \
163 return lp_ctx->globals->var_name ? lpcfg_string(lp_ctx->globals->var_name) : ""; \
166 #define FN_GLOBAL_LIST(fn_name,var_name) \
167 _PUBLIC_ const char **lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) { \
168 if (lp_ctx == NULL) return NULL; \
169 return lp_ctx->globals->var_name; \
172 #define FN_GLOBAL_BOOL(fn_name,var_name) \
173 _PUBLIC_ bool lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) {\
174 if (lp_ctx == NULL) return false; \
175 return lp_ctx->globals->var_name; \
178 #define FN_GLOBAL_INTEGER(fn_name,var_name) \
179 _PUBLIC_ int lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) { \
180 return lp_ctx->globals->var_name; \
183 /* Local parameters don't need the ->s3_fns because the struct
184 * loadparm_service is shared and lpcfg_service() checks the ->s3_fns
186 #define FN_LOCAL_STRING(fn_name,val) \
187 _PUBLIC_ char *lpcfg_ ## fn_name(struct loadparm_service *service, \
188 struct loadparm_service *sDefault, TALLOC_CTX *ctx) { \
189 return(talloc_strdup(ctx, lpcfg_string((const char *)((service != NULL && service->val != NULL) ? service->val : sDefault->val)))); \
192 #define FN_LOCAL_CONST_STRING(fn_name,val) \
193 _PUBLIC_ const char *lpcfg_ ## fn_name(struct loadparm_service *service, \
194 struct loadparm_service *sDefault) { \
195 return((const char *)((service != NULL && service->val != NULL) ? service->val : sDefault->val)); \
198 #define FN_LOCAL_LIST(fn_name,val) \
199 _PUBLIC_ const char **lpcfg_ ## fn_name(struct loadparm_service *service, \
200 struct loadparm_service *sDefault) {\
201 return(const char **)(service != NULL && service->val != NULL? service->val : sDefault->val); \
204 #define FN_LOCAL_PARM_BOOL(fn_name, val) FN_LOCAL_BOOL(fn_name, val)
206 #define FN_LOCAL_BOOL(fn_name,val) \
207 _PUBLIC_ bool lpcfg_ ## fn_name(struct loadparm_service *service, \
208 struct loadparm_service *sDefault) { \
209 return((service != NULL)? service->val : sDefault->val); \
212 #define FN_LOCAL_INTEGER(fn_name,val) \
213 _PUBLIC_ int lpcfg_ ## fn_name(struct loadparm_service *service, \
214 struct loadparm_service *sDefault) { \
215 return((service != NULL)? service->val : sDefault->val); \
218 #define FN_LOCAL_PARM_INTEGER(fn_name, val) FN_LOCAL_INTEGER(fn_name, val)
220 #define FN_LOCAL_PARM_CHAR(fn_name,val) \
221 _PUBLIC_ char lpcfg_ ## fn_name(struct loadparm_service *service, \
222 struct loadparm_service *sDefault) { \
223 return((service != NULL)? service->val : sDefault->val); \
226 #include "lib/param/param_functions.c"
228 /* These functions cannot be auto-generated */
229 FN_LOCAL_BOOL(autoloaded
, autoloaded
)
230 FN_GLOBAL_CONST_STRING(dnsdomain
, dnsdomain
)
232 /* local prototypes */
233 static struct loadparm_service
*lpcfg_getservicebyname(struct loadparm_context
*lp_ctx
,
234 const char *pszServiceName
);
235 static bool lpcfg_service_ok(struct loadparm_service
*service
);
236 static bool do_section(const char *pszSectionName
, void *);
238 /* This is a helper function for parametrical options support. */
239 /* It returns a pointer to parametrical option value if it exists or NULL otherwise */
240 /* Actual parametrical functions are quite simple */
241 const char *lpcfg_get_parametric(struct loadparm_context
*lp_ctx
,
242 struct loadparm_service
*service
,
243 const char *type
, const char *option
)
246 struct parmlist_entry
*data
;
251 if (lp_ctx
->s3_fns
) {
252 return lp_ctx
->s3_fns
->get_parametric(service
, type
, option
, NULL
);
255 data
= (service
== NULL
? lp_ctx
->globals
->param_opt
: service
->param_opt
);
257 vfskey
= talloc_asprintf(NULL
, "%s:%s", type
, option
);
258 if (vfskey
== NULL
) {
259 DEBUG(0,("asprintf failed!\n"));
264 if (strwicmp(data
->key
, vfskey
) == 0) {
271 if (service
!= NULL
) {
272 /* Try to fetch the same option but from globals */
273 /* but only if we are not already working with globals */
274 for (data
= lp_ctx
->globals
->param_opt
; data
;
276 if (strwicmp(data
->key
, vfskey
) == 0) {
290 * convenience routine to return int parameters.
292 int lp_int(const char *s
)
296 DEBUG(0,("lp_int(%s): is called with NULL!\n",s
));
300 return strtol(s
, NULL
, 0);
304 * convenience routine to return unsigned long parameters.
306 unsigned long lp_ulong(const char *s
)
310 DEBUG(0,("lp_ulong(%s): is called with NULL!\n",s
));
314 return strtoul(s
, NULL
, 0);
318 * convenience routine to return unsigned long parameters.
320 static long lp_long(const char *s
)
324 DEBUG(0,("lp_long(%s): is called with NULL!\n",s
));
328 return strtol(s
, NULL
, 0);
332 * convenience routine to return unsigned long parameters.
334 static double lp_double(const char *s
)
338 DEBUG(0,("lp_double(%s): is called with NULL!\n",s
));
342 return strtod(s
, NULL
);
346 * convenience routine to return boolean parameters.
348 bool lp_bool(const char *s
)
353 DEBUG(0,("lp_bool(%s): is called with NULL!\n",s
));
357 if (!set_boolean(s
, &ret
)) {
358 DEBUG(0,("lp_bool(%s): value is not boolean!\n",s
));
366 * Return parametric option from a given service. Type is a part of option before ':'
367 * Parametric option has following syntax: 'Type: option = value'
368 * Returned value is allocated in 'lp_talloc' context
371 const char *lpcfg_parm_string(struct loadparm_context
*lp_ctx
,
372 struct loadparm_service
*service
, const char *type
,
375 const char *value
= lpcfg_get_parametric(lp_ctx
, service
, type
, option
);
378 return lpcfg_string(value
);
384 * Return parametric option from a given service. Type is a part of option before ':'
385 * Parametric option has following syntax: 'Type: option = value'
386 * Returned value is allocated in 'lp_talloc' context
389 const char **lpcfg_parm_string_list(TALLOC_CTX
*mem_ctx
,
390 struct loadparm_context
*lp_ctx
,
391 struct loadparm_service
*service
,
393 const char *option
, const char *separator
)
395 const char *value
= lpcfg_get_parametric(lp_ctx
, service
, type
, option
);
398 return (const char **)str_list_make(mem_ctx
, value
, separator
);
404 * Return parametric option from a given service. Type is a part of option before ':'
405 * Parametric option has following syntax: 'Type: option = value'
408 int lpcfg_parm_int(struct loadparm_context
*lp_ctx
,
409 struct loadparm_service
*service
, const char *type
,
410 const char *option
, int default_v
)
412 const char *value
= lpcfg_get_parametric(lp_ctx
, service
, type
, option
);
415 return lp_int(value
);
421 * Return parametric option from a given service. Type is a part of
423 * Parametric option has following syntax: 'Type: option = value'.
426 int lpcfg_parm_bytes(struct loadparm_context
*lp_ctx
,
427 struct loadparm_service
*service
, const char *type
,
428 const char *option
, int default_v
)
432 const char *value
= lpcfg_get_parametric(lp_ctx
, service
, type
, option
);
434 if (value
&& conv_str_size_error(value
, &bval
)) {
435 if (bval
<= INT_MAX
) {
444 * Return parametric option from a given service.
445 * Type is a part of option before ':'
446 * Parametric option has following syntax: 'Type: option = value'
448 unsigned long lpcfg_parm_ulong(struct loadparm_context
*lp_ctx
,
449 struct loadparm_service
*service
, const char *type
,
450 const char *option
, unsigned long default_v
)
452 const char *value
= lpcfg_get_parametric(lp_ctx
, service
, type
, option
);
455 return lp_ulong(value
);
460 long lpcfg_parm_long(struct loadparm_context
*lp_ctx
,
461 struct loadparm_service
*service
, const char *type
,
462 const char *option
, long default_v
)
464 const char *value
= lpcfg_get_parametric(lp_ctx
, service
, type
, option
);
467 return lp_long(value
);
472 double lpcfg_parm_double(struct loadparm_context
*lp_ctx
,
473 struct loadparm_service
*service
, const char *type
,
474 const char *option
, double default_v
)
476 const char *value
= lpcfg_get_parametric(lp_ctx
, service
, type
, option
);
479 return lp_double(value
);
485 * Return parametric option from a given service. Type is a part of option before ':'
486 * Parametric option has following syntax: 'Type: option = value'
489 bool lpcfg_parm_bool(struct loadparm_context
*lp_ctx
,
490 struct loadparm_service
*service
, const char *type
,
491 const char *option
, bool default_v
)
493 const char *value
= lpcfg_get_parametric(lp_ctx
, service
, type
, option
);
496 return lp_bool(value
);
503 * Set a string value, deallocating any existing space, and allocing the space
506 bool lpcfg_string_set(TALLOC_CTX
*mem_ctx
, char **dest
, const char *src
)
513 *dest
= talloc_strdup(mem_ctx
, src
);
514 if ((*dest
) == NULL
) {
515 DEBUG(0,("Out of memory in string_set\n"));
523 * Set a string value, deallocating any existing space, and allocing the space
526 static bool lpcfg_string_set_upper(TALLOC_CTX
*mem_ctx
, char **dest
, const char *src
)
533 *dest
= strupper_talloc(mem_ctx
, src
);
534 if ((*dest
) == NULL
) {
535 DEBUG(0,("Out of memory in string_set_upper\n"));
545 * Add a new service to the services array initialising it with the given
549 struct loadparm_service
*lpcfg_add_service(struct loadparm_context
*lp_ctx
,
550 const struct loadparm_service
*pservice
,
554 int num_to_alloc
= lp_ctx
->iNumServices
+ 1;
555 struct parmlist_entry
*data
, *pdata
;
557 if (pservice
== NULL
) {
558 pservice
= lp_ctx
->sDefault
;
561 /* it might already exist */
563 struct loadparm_service
*service
= lpcfg_getservicebyname(lp_ctx
,
565 if (service
!= NULL
) {
566 /* Clean all parametric options for service */
567 /* They will be added during parsing again */
568 data
= service
->param_opt
;
574 service
->param_opt
= NULL
;
579 /* find an invalid one */
580 for (i
= 0; i
< lp_ctx
->iNumServices
; i
++)
581 if (lp_ctx
->services
[i
] == NULL
)
584 /* if not, then create one */
585 if (i
== lp_ctx
->iNumServices
) {
586 struct loadparm_service
**tsp
;
588 tsp
= talloc_realloc(lp_ctx
, lp_ctx
->services
, struct loadparm_service
*, num_to_alloc
);
591 DEBUG(0,("lpcfg_add_service: failed to enlarge services!\n"));
594 lp_ctx
->services
= tsp
;
595 lp_ctx
->services
[lp_ctx
->iNumServices
] = NULL
;
598 lp_ctx
->iNumServices
++;
601 lp_ctx
->services
[i
] = talloc_zero(lp_ctx
->services
, struct loadparm_service
);
602 if (lp_ctx
->services
[i
] == NULL
) {
603 DEBUG(0,("lpcfg_add_service: out of memory!\n"));
606 copy_service(lp_ctx
->services
[i
], pservice
, NULL
);
608 lpcfg_string_set(lp_ctx
->services
[i
], &lp_ctx
->services
[i
]->szService
, name
);
609 return lp_ctx
->services
[i
];
613 * Add a new home service, with the specified home directory, defaults coming
614 * from service ifrom.
617 bool lpcfg_add_home(struct loadparm_context
*lp_ctx
,
618 const char *pszHomename
,
619 struct loadparm_service
*default_service
,
620 const char *user
, const char *pszHomedir
)
622 struct loadparm_service
*service
;
624 service
= lpcfg_add_service(lp_ctx
, default_service
, pszHomename
);
629 if (!(*(default_service
->path
))
630 || strequal(default_service
->path
, lp_ctx
->sDefault
->path
)) {
631 service
->path
= talloc_strdup(service
, pszHomedir
);
633 service
->path
= string_sub_talloc(service
, lpcfg_path(default_service
, lp_ctx
->sDefault
, service
), "%H", pszHomedir
);
636 if (!(*(service
->comment
))) {
637 service
->comment
= talloc_asprintf(service
, "Home directory of %s", user
);
639 service
->bAvailable
= default_service
->bAvailable
;
640 service
->browseable
= default_service
->browseable
;
642 DEBUG(3, ("adding home's share [%s] for user '%s' at '%s'\n",
643 pszHomename
, user
, service
->path
));
649 * Add a new printer service, with defaults coming from service iFrom.
652 bool lpcfg_add_printer(struct loadparm_context
*lp_ctx
,
653 const char *pszPrintername
,
654 struct loadparm_service
*default_service
)
656 const char *comment
= "From Printcap";
657 struct loadparm_service
*service
;
658 service
= lpcfg_add_service(lp_ctx
, default_service
, pszPrintername
);
663 /* note that we do NOT default the availability flag to True - */
664 /* we take it from the default service passed. This allows all */
665 /* dynamic printers to be disabled by disabling the [printers] */
666 /* entry (if/when the 'available' keyword is implemented!). */
668 /* the printer name is set to the service name. */
669 lpcfg_string_set(service
, &service
->_printername
, pszPrintername
);
670 lpcfg_string_set(service
, &service
->comment
, comment
);
671 service
->browseable
= default_service
->browseable
;
672 /* Printers cannot be read_only. */
673 service
->read_only
= false;
674 /* Printer services must be printable. */
675 service
->printable
= true;
677 DEBUG(3, ("adding printer service %s\n", pszPrintername
));
683 * Map a parameter's string representation to something we can use.
684 * Returns False if the parameter string is not recognised, else TRUE.
687 int lpcfg_map_parameter(const char *pszParmName
)
691 for (iIndex
= 0; parm_table
[iIndex
].label
; iIndex
++)
692 if (strwicmp(parm_table
[iIndex
].label
, pszParmName
) == 0)
695 /* Warn only if it isn't parametric option */
696 if (strchr(pszParmName
, ':') == NULL
)
697 DEBUG(0, ("Unknown parameter encountered: \"%s\"\n", pszParmName
));
698 /* We do return 'fail' for parametric options as well because they are
699 stored in different storage
706 return the parameter structure for a parameter
708 struct parm_struct
*lpcfg_parm_struct(struct loadparm_context
*lp_ctx
, const char *name
)
712 if (lp_ctx
->s3_fns
) {
713 return lp_ctx
->s3_fns
->get_parm_struct(name
);
716 parmnum
= lpcfg_map_parameter(name
);
717 if (parmnum
== -1) return NULL
;
718 return &parm_table
[parmnum
];
722 return the parameter pointer for a parameter
724 void *lpcfg_parm_ptr(struct loadparm_context
*lp_ctx
,
725 struct loadparm_service
*service
, struct parm_struct
*parm
)
727 if (lp_ctx
->s3_fns
) {
728 return lp_ctx
->s3_fns
->get_parm_ptr(service
, parm
);
731 if (service
== NULL
) {
732 if (parm
->p_class
== P_LOCAL
)
733 return ((char *)lp_ctx
->sDefault
)+parm
->offset
;
734 else if (parm
->p_class
== P_GLOBAL
)
735 return ((char *)lp_ctx
->globals
)+parm
->offset
;
738 return ((char *)service
) + parm
->offset
;
743 return the parameter pointer for a parameter
745 bool lpcfg_parm_is_cmdline(struct loadparm_context
*lp_ctx
, const char *name
)
749 if (lp_ctx
->s3_fns
) {
750 struct parm_struct
*parm
= lp_ctx
->s3_fns
->get_parm_struct(name
);
752 return parm
->flags
& FLAG_CMDLINE
;
757 parmnum
= lpcfg_map_parameter(name
);
758 if (parmnum
== -1) return false;
760 return lp_ctx
->flags
[parmnum
] & FLAG_CMDLINE
;
764 * Find a service by name. Otherwise works like get_service.
767 static struct loadparm_service
*lpcfg_getservicebyname(struct loadparm_context
*lp_ctx
,
768 const char *pszServiceName
)
772 if (lp_ctx
->s3_fns
) {
773 return lp_ctx
->s3_fns
->get_service(pszServiceName
);
776 for (iService
= lp_ctx
->iNumServices
- 1; iService
>= 0; iService
--)
777 if (lp_ctx
->services
[iService
] != NULL
&&
778 strwicmp(lp_ctx
->services
[iService
]->szService
, pszServiceName
) == 0) {
779 return lp_ctx
->services
[iService
];
786 * Add a parametric option to a parmlist_entry,
787 * replacing old value, if already present.
789 void set_param_opt(TALLOC_CTX
*mem_ctx
,
790 struct parmlist_entry
**opt_list
,
791 const char *opt_name
,
792 const char *opt_value
,
795 struct parmlist_entry
*new_opt
, *opt
;
801 /* Traverse destination */
803 /* If we already have same option, override it */
804 if (strwicmp(opt
->key
, opt_name
) == 0) {
805 if ((opt
->priority
& FLAG_CMDLINE
) &&
806 !(priority
& FLAG_CMDLINE
)) {
807 /* it's been marked as not to be
811 TALLOC_FREE(opt
->value
);
812 TALLOC_FREE(opt
->list
);
813 opt
->value
= talloc_strdup(opt
, opt_value
);
814 opt
->priority
= priority
;
821 new_opt
= talloc(mem_ctx
, struct parmlist_entry
);
822 if (new_opt
== NULL
) {
826 new_opt
->key
= talloc_strdup(new_opt
, opt_name
);
827 if (new_opt
->key
== NULL
) {
828 smb_panic("talloc_strdup failed");
831 new_opt
->value
= talloc_strdup(new_opt
, opt_value
);
832 if (new_opt
->value
== NULL
) {
833 smb_panic("talloc_strdup failed");
836 new_opt
->list
= NULL
;
837 new_opt
->priority
= priority
;
838 DLIST_ADD(*opt_list
, new_opt
);
843 * Copy a service structure to another.
844 * If pcopymapDest is NULL then copy all fields
847 void copy_service(struct loadparm_service
*pserviceDest
,
848 const struct loadparm_service
*pserviceSource
,
849 struct bitmap
*pcopymapDest
)
852 bool bcopyall
= (pcopymapDest
== NULL
);
853 struct parmlist_entry
*data
;
855 for (i
= 0; parm_table
[i
].label
; i
++)
856 if (parm_table
[i
].p_class
== P_LOCAL
&&
857 (bcopyall
|| bitmap_query(pcopymapDest
, i
))) {
858 const void *src_ptr
=
859 ((const char *)pserviceSource
) + parm_table
[i
].offset
;
861 ((char *)pserviceDest
) + parm_table
[i
].offset
;
863 switch (parm_table
[i
].type
) {
866 *(bool *)dest_ptr
= *(const bool *)src_ptr
;
873 *(int *)dest_ptr
= *(const int *)src_ptr
;
877 *(char *)dest_ptr
= *(const char *)src_ptr
;
881 lpcfg_string_set(pserviceDest
,
883 *(const char * const *)src_ptr
);
887 lpcfg_string_set_upper(pserviceDest
,
889 *(const char * const *)src_ptr
);
893 TALLOC_FREE(*((char ***)dest_ptr
));
894 *(const char * const **)dest_ptr
= (const char * const *)str_list_copy(pserviceDest
,
895 *(const char * * const *)src_ptr
);
903 init_copymap(pserviceDest
);
904 if (pserviceSource
->copymap
)
905 bitmap_copy(pserviceDest
->copymap
,
906 pserviceSource
->copymap
);
909 for (data
= pserviceSource
->param_opt
; data
!= NULL
; data
= data
->next
) {
910 set_param_opt(pserviceDest
, &pserviceDest
->param_opt
,
911 data
->key
, data
->value
, data
->priority
);
916 * Check a service for consistency. Return False if the service is in any way
917 * incomplete or faulty, else True.
919 static bool lpcfg_service_ok(struct loadparm_service
*service
)
924 if (service
->szService
[0] == '\0') {
925 DEBUG(0, ("The following message indicates an internal error:\n"));
926 DEBUG(0, ("No service name in service entry.\n"));
930 /* The [printers] entry MUST be printable. I'm all for flexibility, but */
931 /* I can't see why you'd want a non-printable printer service... */
932 if (strwicmp(service
->szService
, PRINTERS_NAME
) == 0) {
933 if (!service
->printable
) {
934 DEBUG(0, ("WARNING: [%s] service MUST be printable!\n",
935 service
->szService
));
936 service
->printable
= true;
938 /* [printers] service must also be non-browsable. */
939 if (service
->browseable
)
940 service
->browseable
= false;
943 /* If a service is flagged unavailable, log the fact at level 0. */
944 if (!service
->bAvailable
)
945 DEBUG(1, ("NOTE: Service %s is flagged unavailable.\n",
946 service
->szService
));
952 /*******************************************************************
953 Keep a linked list of all config files so we know when one has changed
954 it's date and needs to be reloaded.
955 ********************************************************************/
957 void add_to_file_list(TALLOC_CTX
*mem_ctx
, struct file_lists
**list
,
958 const char *fname
, const char *subfname
)
960 struct file_lists
*f
= *list
;
963 if (f
->name
&& !strcmp(f
->name
, fname
))
969 f
= talloc(mem_ctx
, struct file_lists
);
973 f
->name
= talloc_strdup(f
, fname
);
978 f
->subfname
= talloc_strdup(f
, subfname
);
984 f
->modtime
= file_modtime(subfname
);
986 time_t t
= file_modtime(subfname
);
993 DEBUG(0, ("Unable to add file to file list: %s\n", fname
));
997 /*******************************************************************
998 Check if a config file has changed date.
999 ********************************************************************/
1000 bool lpcfg_file_list_changed(struct loadparm_context
*lp_ctx
)
1002 struct file_lists
*f
;
1003 DEBUG(6, ("lpcfg_file_list_changed()\n"));
1005 for (f
= lp_ctx
->file_lists
; f
!= NULL
; f
= f
->next
) {
1009 n2
= standard_sub_basic(lp_ctx
, f
->name
);
1011 DEBUGADD(6, ("file %s -> %s last mod_time: %s\n",
1012 f
->name
, n2
, ctime(&f
->modtime
)));
1014 mod_time
= file_modtime(n2
);
1016 if (mod_time
&& ((f
->modtime
!= mod_time
) || (f
->subfname
== NULL
) || (strcmp(n2
, f
->subfname
) != 0))) {
1017 DEBUGADD(6, ("file %s modified: %s\n", n2
,
1019 f
->modtime
= mod_time
;
1020 talloc_free(f
->subfname
);
1021 f
->subfname
= talloc_strdup(f
, n2
);
1029 * set the value for a P_ENUM
1031 bool lp_set_enum_parm( struct parm_struct
*parm
, const char *pszParmValue
,
1036 for (i
= 0; parm
->enum_list
[i
].name
; i
++) {
1037 if ( strequal(pszParmValue
, parm
->enum_list
[i
].name
)) {
1038 *ptr
= parm
->enum_list
[i
].value
;
1042 DEBUG(0, ("WARNING: Ignoring invalid value '%s' for parameter '%s'\n",
1043 pszParmValue
, parm
->label
));
1048 /***************************************************************************
1049 Handle the "realm" parameter
1050 ***************************************************************************/
1052 bool handle_realm(struct loadparm_context
*lp_ctx
, int unused
,
1053 const char *pszParmValue
, char **ptr
)
1058 upper
= strupper_talloc(lp_ctx
, pszParmValue
);
1059 if (upper
== NULL
) {
1063 lower
= strlower_talloc(lp_ctx
, pszParmValue
);
1064 if (lower
== NULL
) {
1069 if (lp_ctx
->s3_fns
!= NULL
) {
1070 lp_ctx
->s3_fns
->lp_string_set(ptr
, pszParmValue
);
1071 lp_ctx
->s3_fns
->lp_string_set(&lp_ctx
->globals
->realm
, upper
);
1072 lp_ctx
->s3_fns
->lp_string_set(&lp_ctx
->globals
->dnsdomain
, lower
);
1074 lpcfg_string_set(lp_ctx
, ptr
, pszParmValue
);
1075 lpcfg_string_set(lp_ctx
, &lp_ctx
->globals
->realm
, upper
);
1076 lpcfg_string_set(lp_ctx
, &lp_ctx
->globals
->dnsdomain
, lower
);
1082 /***************************************************************************
1083 Handle the include operation.
1084 ***************************************************************************/
1086 bool handle_include(struct loadparm_context
*lp_ctx
, int unused
,
1087 const char *pszParmValue
, char **ptr
)
1091 if (lp_ctx
->s3_fns
) {
1092 return lp_ctx
->s3_fns
->lp_include(lp_ctx
, unused
, pszParmValue
, ptr
);
1095 fname
= standard_sub_basic(lp_ctx
, pszParmValue
);
1097 add_to_file_list(lp_ctx
, &lp_ctx
->file_lists
, pszParmValue
, fname
);
1099 lpcfg_string_set(lp_ctx
, ptr
, fname
);
1101 if (file_exist(fname
))
1102 return pm_process(fname
, do_section
, do_parameter
, lp_ctx
);
1104 DEBUG(2, ("Can't find include file %s\n", fname
));
1109 /***************************************************************************
1110 Handle the interpretation of the copy parameter.
1111 ***************************************************************************/
1113 bool handle_copy(struct loadparm_context
*lp_ctx
, int snum
,
1114 const char *pszParmValue
, char **ptr
)
1117 struct loadparm_service
*serviceTemp
= NULL
;
1118 struct loadparm_service
*current
= NULL
;
1122 DEBUG(3, ("Copying service from service %s\n", pszParmValue
));
1124 serviceTemp
= lpcfg_getservicebyname(lp_ctx
, pszParmValue
);
1125 if (lp_ctx
->s3_fns
!= NULL
) {
1126 current
= lp_ctx
->s3_fns
->get_servicebynum(snum
);
1128 current
= lp_ctx
->currentService
;
1131 if (current
== NULL
) {
1132 DEBUG(0, ("Unable to copy service - invalid service destination"));
1136 if (serviceTemp
!= NULL
) {
1137 if (serviceTemp
== current
) {
1138 DEBUG(0, ("Can't copy service %s - unable to copy self!\n", pszParmValue
));
1140 copy_service(current
,
1143 lpcfg_string_set(current
, ptr
, pszParmValue
);
1148 DEBUG(0, ("Unable to copy service - source not found: %s\n",
1156 bool handle_debug_list(struct loadparm_context
*lp_ctx
, int unused
,
1157 const char *pszParmValue
, char **ptr
)
1159 if (lp_ctx
->s3_fns
!= NULL
) {
1160 lp_ctx
->s3_fns
->lp_string_set(ptr
, pszParmValue
);
1162 lpcfg_string_set(lp_ctx
, ptr
, pszParmValue
);
1165 return debug_parse_levels(pszParmValue
);
1168 bool handle_logfile(struct loadparm_context
*lp_ctx
, int unused
,
1169 const char *pszParmValue
, char **ptr
)
1171 if (lp_ctx
->s3_fns
!= NULL
) {
1172 lp_ctx
->s3_fns
->lp_string_set(ptr
, pszParmValue
);
1174 debug_set_logfile(pszParmValue
);
1175 lpcfg_string_set(lp_ctx
, ptr
, pszParmValue
);
1182 * These special charset handling methods only run in the source3 code.
1185 bool handle_charset(struct loadparm_context
*lp_ctx
, int snum
,
1186 const char *pszParmValue
, char **ptr
)
1188 if (lp_ctx
->s3_fns
) {
1189 if (*ptr
== NULL
|| strcmp(*ptr
, pszParmValue
) != 0) {
1190 lp_ctx
->s3_fns
->lp_string_set(ptr
, pszParmValue
);
1191 global_iconv_handle
= smb_iconv_handle_reinit(NULL
,
1192 lpcfg_dos_charset(lp_ctx
),
1193 lpcfg_unix_charset(lp_ctx
),
1194 true, global_iconv_handle
);
1199 return lpcfg_string_set(lp_ctx
, ptr
, pszParmValue
);
1203 bool handle_dos_charset(struct loadparm_context
*lp_ctx
, int snum
,
1204 const char *pszParmValue
, char **ptr
)
1206 bool is_utf8
= false;
1207 size_t len
= strlen(pszParmValue
);
1209 if (lp_ctx
->s3_fns
) {
1210 if (len
== 4 || len
== 5) {
1211 /* Don't use StrCaseCmp here as we don't want to
1212 initialize iconv. */
1213 if ((toupper_m(pszParmValue
[0]) == 'U') &&
1214 (toupper_m(pszParmValue
[1]) == 'T') &&
1215 (toupper_m(pszParmValue
[2]) == 'F')) {
1217 if (pszParmValue
[3] == '8') {
1221 if (pszParmValue
[3] == '-' &&
1222 pszParmValue
[4] == '8') {
1229 if (*ptr
== NULL
|| strcmp(*ptr
, pszParmValue
) != 0) {
1231 DEBUG(0,("ERROR: invalid DOS charset: 'dos charset' must not "
1232 "be UTF8, using (default value) %s instead.\n",
1233 DEFAULT_DOS_CHARSET
));
1234 pszParmValue
= DEFAULT_DOS_CHARSET
;
1236 lp_ctx
->s3_fns
->lp_string_set(ptr
, pszParmValue
);
1237 global_iconv_handle
= smb_iconv_handle_reinit(NULL
,
1238 lpcfg_dos_charset(lp_ctx
),
1239 lpcfg_unix_charset(lp_ctx
),
1240 true, global_iconv_handle
);
1245 return lpcfg_string_set(lp_ctx
, ptr
, pszParmValue
);
1248 bool handle_printing(struct loadparm_context
*lp_ctx
, int snum
,
1249 const char *pszParmValue
, char **ptr
)
1251 static int parm_num
= -1;
1252 struct loadparm_service
*s
;
1254 if (parm_num
== -1) {
1255 parm_num
= lpcfg_map_parameter("printing");
1258 if (!lp_set_enum_parm(&parm_table
[parm_num
], pszParmValue
, (int*)ptr
)) {
1262 if (lp_ctx
->s3_fns
) {
1264 s
= lp_ctx
->sDefault
;
1265 lp_ctx
->s3_fns
->init_printer_values(lp_ctx
->globals
->ctx
, s
);
1267 s
= lp_ctx
->services
[snum
];
1268 lp_ctx
->s3_fns
->init_printer_values(s
, s
);
1275 bool handle_ldap_debug_level(struct loadparm_context
*lp_ctx
, int snum
, const char *pszParmValue
, char **ptr
)
1277 lp_ctx
->globals
->ldap_debug_level
= lp_int(pszParmValue
);
1279 if (lp_ctx
->s3_fns
) {
1280 lp_ctx
->s3_fns
->init_ldap_debugging();
1285 bool handle_netbios_aliases(struct loadparm_context
*lp_ctx
, int snum
, const char *pszParmValue
, char **ptr
)
1287 TALLOC_FREE(lp_ctx
->globals
->netbios_aliases
);
1288 lp_ctx
->globals
->netbios_aliases
= (const char **)str_list_make_v3(lp_ctx
->globals
->ctx
,
1289 pszParmValue
, NULL
);
1291 if (lp_ctx
->s3_fns
) {
1292 return lp_ctx
->s3_fns
->set_netbios_aliases(lp_ctx
->globals
->netbios_aliases
);
1298 * idmap related parameters
1301 bool handle_idmap_backend(struct loadparm_context
*lp_ctx
, int snum
, const char *pszParmValue
, char **ptr
)
1303 if (lp_ctx
->s3_fns
) {
1304 return lp_ctx
->s3_fns
->lp_do_parameter(snum
, "idmap config * : backend", pszParmValue
);
1307 return lpcfg_string_set(lp_ctx
, ptr
, pszParmValue
);
1310 bool handle_idmap_uid(struct loadparm_context
*lp_ctx
, int snum
, const char *pszParmValue
, char **ptr
)
1312 if (lp_ctx
->s3_fns
) {
1313 return lp_ctx
->s3_fns
->lp_do_parameter(snum
, "idmap config * : range", pszParmValue
);
1316 return lpcfg_string_set(lp_ctx
, ptr
, pszParmValue
);
1319 bool handle_idmap_gid(struct loadparm_context
*lp_ctx
, int snum
, const char *pszParmValue
, char **ptr
)
1321 if (lp_ctx
->s3_fns
) {
1322 return lp_ctx
->s3_fns
->lp_do_parameter(snum
, "idmap config * : range", pszParmValue
);
1325 return lpcfg_string_set(lp_ctx
, ptr
, pszParmValue
);
1328 /***************************************************************************
1329 Initialise a copymap.
1330 ***************************************************************************/
1332 void init_copymap(struct loadparm_service
*pservice
)
1336 TALLOC_FREE(pservice
->copymap
);
1338 pservice
->copymap
= bitmap_talloc(NULL
, num_parameters());
1339 if (!pservice
->copymap
)
1341 ("Couldn't allocate copymap!! (size %d)\n",
1342 (int)num_parameters()));
1344 for (i
= 0; i
< num_parameters(); i
++)
1345 bitmap_set(pservice
->copymap
, i
);
1349 * Process a parametric option
1351 static bool lp_do_parameter_parametric(struct loadparm_context
*lp_ctx
,
1352 struct loadparm_service
*service
,
1353 const char *pszParmName
,
1354 const char *pszParmValue
, int flags
)
1356 struct parmlist_entry
**data
;
1358 TALLOC_CTX
*mem_ctx
;
1360 while (isspace((unsigned char)*pszParmName
)) {
1364 name
= strlower_talloc(lp_ctx
, pszParmName
);
1365 if (!name
) return false;
1367 if (service
== NULL
) {
1368 data
= &lp_ctx
->globals
->param_opt
;
1369 mem_ctx
= lp_ctx
->globals
;
1371 data
= &service
->param_opt
;
1375 set_param_opt(mem_ctx
, data
, name
, pszParmValue
, flags
);
1382 static bool set_variable(TALLOC_CTX
*mem_ctx
, int parmnum
, void *parm_ptr
,
1383 const char *pszParmName
, const char *pszParmValue
,
1384 struct loadparm_context
*lp_ctx
, bool on_globals
)
1387 /* if it is a special case then go ahead */
1388 if (parm_table
[parmnum
].special
) {
1390 ret
= parm_table
[parmnum
].special(lp_ctx
, -1, pszParmValue
,
1395 goto mark_non_default
;
1398 /* now switch on the type of variable it is */
1399 switch (parm_table
[parmnum
].type
)
1403 if (!set_boolean(pszParmValue
, &b
)) {
1404 DEBUG(0, ("set_variable(%s): value is not "
1405 "boolean!\n", pszParmValue
));
1408 *(bool *)parm_ptr
= b
;
1414 if (!set_boolean(pszParmValue
, &b
)) {
1415 DEBUG(0, ("set_variable(%s): value is not "
1416 "boolean!\n", pszParmValue
));
1419 *(bool *)parm_ptr
= !b
;
1424 *(int *)parm_ptr
= atoi(pszParmValue
);
1428 *(char *)parm_ptr
= *pszParmValue
;
1432 *(int *)parm_ptr
= strtol(pszParmValue
, NULL
, 8);
1438 if (conv_str_size_error(pszParmValue
, &val
)) {
1439 if (val
<= INT_MAX
) {
1440 *(int *)parm_ptr
= (int)val
;
1445 DEBUG(0, ("set_variable(%s): value is not "
1446 "a valid size specifier!\n", pszParmValue
));
1451 *(const char * const **)parm_ptr
1452 = (const char * const *)str_list_make(mem_ctx
,
1453 pszParmValue
, NULL
);
1457 char **new_list
= str_list_make(mem_ctx
,
1458 pszParmValue
, NULL
);
1459 for (i
=0; new_list
[i
]; i
++) {
1460 if (*(const char ***)parm_ptr
!= NULL
&&
1461 new_list
[i
][0] == '+' &&
1464 if (!str_list_check(*(const char ***)parm_ptr
,
1466 *(const char ***)parm_ptr
= str_list_add(*(const char ***)parm_ptr
,
1469 } else if (*(const char ***)parm_ptr
!= NULL
&&
1470 new_list
[i
][0] == '-' &&
1473 str_list_remove(*(const char ***)parm_ptr
,
1477 DEBUG(0, ("Unsupported list syntax for: %s = %s\n",
1478 pszParmName
, pszParmValue
));
1481 *(const char * const **)parm_ptr
= (const char * const *) new_list
;
1488 lpcfg_string_set(mem_ctx
, (char **)parm_ptr
, pszParmValue
);
1492 lpcfg_string_set_upper(mem_ctx
, (char **)parm_ptr
, pszParmValue
);
1496 if (!lp_set_enum_parm(&parm_table
[parmnum
], pszParmValue
, (int*)parm_ptr
)) {
1506 if (on_globals
&& (lp_ctx
->flags
[parmnum
] & FLAG_DEFAULT
)) {
1507 lp_ctx
->flags
[parmnum
] &= ~FLAG_DEFAULT
;
1508 /* we have to also unset FLAG_DEFAULT on aliases */
1509 for (i
=parmnum
-1;i
>=0 && parm_table
[i
].offset
== parm_table
[parmnum
].offset
;i
--) {
1510 lp_ctx
->flags
[i
] &= ~FLAG_DEFAULT
;
1512 for (i
=parmnum
+1;i
<num_parameters() && parm_table
[i
].offset
== parm_table
[parmnum
].offset
;i
++) {
1513 lp_ctx
->flags
[i
] &= ~FLAG_DEFAULT
;
1520 bool lpcfg_do_global_parameter(struct loadparm_context
*lp_ctx
,
1521 const char *pszParmName
, const char *pszParmValue
)
1523 int parmnum
= lpcfg_map_parameter(pszParmName
);
1527 if (strchr(pszParmName
, ':')) {
1528 return lp_do_parameter_parametric(lp_ctx
, NULL
, pszParmName
, pszParmValue
, 0);
1530 DEBUG(0, ("Ignoring unknown parameter \"%s\"\n", pszParmName
));
1534 /* if the flag has been set on the command line, then don't allow override,
1535 but don't report an error */
1536 if (lp_ctx
->flags
[parmnum
] & FLAG_CMDLINE
) {
1540 parm_ptr
= lpcfg_parm_ptr(lp_ctx
, NULL
, &parm_table
[parmnum
]);
1542 return set_variable(lp_ctx
->globals
, parmnum
, parm_ptr
,
1543 pszParmName
, pszParmValue
, lp_ctx
, true);
1546 bool lpcfg_do_service_parameter(struct loadparm_context
*lp_ctx
,
1547 struct loadparm_service
*service
,
1548 const char *pszParmName
, const char *pszParmValue
)
1552 int parmnum
= lpcfg_map_parameter(pszParmName
);
1555 if (strchr(pszParmName
, ':')) {
1556 return lp_do_parameter_parametric(lp_ctx
, service
, pszParmName
, pszParmValue
, 0);
1558 DEBUG(0, ("Ignoring unknown parameter \"%s\"\n", pszParmName
));
1562 /* if the flag has been set on the command line, then don't allow override,
1563 but don't report an error */
1564 if (lp_ctx
->flags
[parmnum
] & FLAG_CMDLINE
) {
1568 if (parm_table
[parmnum
].p_class
== P_GLOBAL
) {
1570 ("Global parameter %s found in service section!\n",
1574 parm_ptr
= ((char *)service
) + parm_table
[parmnum
].offset
;
1576 if (!service
->copymap
)
1577 init_copymap(service
);
1579 /* this handles the aliases - set the copymap for other
1580 * entries with the same data pointer */
1581 for (i
= 0; parm_table
[i
].label
; i
++)
1582 if (parm_table
[i
].offset
== parm_table
[parmnum
].offset
&&
1583 parm_table
[i
].p_class
== parm_table
[parmnum
].p_class
)
1584 bitmap_clear(service
->copymap
, i
);
1586 return set_variable(service
, parmnum
, parm_ptr
, pszParmName
,
1587 pszParmValue
, lp_ctx
, false);
1591 * Process a parameter.
1594 static bool do_parameter(const char *pszParmName
, const char *pszParmValue
,
1597 struct loadparm_context
*lp_ctx
= (struct loadparm_context
*)userdata
;
1599 if (lp_ctx
->bInGlobalSection
)
1600 return lpcfg_do_global_parameter(lp_ctx
, pszParmName
,
1603 return lpcfg_do_service_parameter(lp_ctx
, lp_ctx
->currentService
,
1604 pszParmName
, pszParmValue
);
1608 variable argument do parameter
1610 bool lpcfg_do_global_parameter_var(struct loadparm_context
*lp_ctx
, const char *pszParmName
, const char *fmt
, ...) PRINTF_ATTRIBUTE(3, 4);
1611 bool lpcfg_do_global_parameter_var(struct loadparm_context
*lp_ctx
,
1612 const char *pszParmName
, const char *fmt
, ...)
1619 s
= talloc_vasprintf(NULL
, fmt
, ap
);
1621 ret
= lpcfg_do_global_parameter(lp_ctx
, pszParmName
, s
);
1628 set a parameter from the commandline - this is called from command line parameter
1629 parsing code. It sets the parameter then marks the parameter as unable to be modified
1630 by smb.conf processing
1632 bool lpcfg_set_cmdline(struct loadparm_context
*lp_ctx
, const char *pszParmName
,
1633 const char *pszParmValue
)
1638 while (isspace((unsigned char)*pszParmValue
)) pszParmValue
++;
1640 if (lp_ctx
->s3_fns
) {
1641 return lp_ctx
->s3_fns
->set_cmdline(pszParmName
, pszParmValue
);
1644 parmnum
= lpcfg_map_parameter(pszParmName
);
1646 if (parmnum
< 0 && strchr(pszParmName
, ':')) {
1647 /* set a parametric option */
1648 return lp_do_parameter_parametric(lp_ctx
, NULL
, pszParmName
,
1649 pszParmValue
, FLAG_CMDLINE
);
1653 DEBUG(0,("Unknown option '%s'\n", pszParmName
));
1657 /* reset the CMDLINE flag in case this has been called before */
1658 lp_ctx
->flags
[parmnum
] &= ~FLAG_CMDLINE
;
1660 if (!lpcfg_do_global_parameter(lp_ctx
, pszParmName
, pszParmValue
)) {
1664 lp_ctx
->flags
[parmnum
] |= FLAG_CMDLINE
;
1666 /* we have to also set FLAG_CMDLINE on aliases */
1668 i
>=0 && 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
;
1674 i
<num_parameters() &&
1675 parm_table
[i
].p_class
== parm_table
[parmnum
].p_class
&&
1676 parm_table
[i
].offset
== parm_table
[parmnum
].offset
;
1678 lp_ctx
->flags
[i
] |= FLAG_CMDLINE
;
1685 set a option from the commandline in 'a=b' format. Use to support --option
1687 bool lpcfg_set_option(struct loadparm_context
*lp_ctx
, const char *option
)
1692 s
= talloc_strdup(NULL
, option
);
1705 ret
= lpcfg_set_cmdline(lp_ctx
, s
, p
+1);
1711 #define BOOLSTR(b) ((b) ? "Yes" : "No")
1714 * Print a parameter of the specified type.
1717 void lpcfg_print_parameter(struct parm_struct
*p
, void *ptr
, FILE * f
)
1719 /* For the seperation of lists values that we print below */
1720 const char *list_sep
= ", ";
1725 for (i
= 0; p
->enum_list
[i
].name
; i
++) {
1726 if (*(int *)ptr
== p
->enum_list
[i
].value
) {
1728 p
->enum_list
[i
].name
);
1735 fprintf(f
, "%s", BOOLSTR(*(bool *)ptr
));
1739 fprintf(f
, "%s", BOOLSTR(!*(bool *)ptr
));
1744 fprintf(f
, "%d", *(int *)ptr
);
1748 fprintf(f
, "%c", *(char *)ptr
);
1752 int val
= *(int *)ptr
;
1756 fprintf(f
, "0%03o", val
);
1765 if ((char ***)ptr
&& *(char ***)ptr
) {
1766 char **list
= *(char ***)ptr
;
1767 for (; *list
; list
++) {
1768 /* surround strings with whitespace in double quotes */
1769 if (*(list
+1) == NULL
) {
1770 /* last item, no extra separator */
1773 if ( strchr_m( *list
, ' ' ) ) {
1774 fprintf(f
, "\"%s\"%s", *list
, list_sep
);
1776 fprintf(f
, "%s%s", *list
, list_sep
);
1784 if (*(char **)ptr
) {
1785 fprintf(f
, "%s", *(char **)ptr
);
1794 * Check if two parameters are equal.
1797 bool lpcfg_equal_parameter(parm_type type
, void *ptr1
, void *ptr2
)
1802 return (*((bool *)ptr1
) == *((bool *)ptr2
));
1808 return (*((int *)ptr1
) == *((int *)ptr2
));
1811 return (*((char *)ptr1
) == *((char *)ptr2
));
1815 return str_list_equal(*(const char ***)ptr1
, *(const char ***)ptr2
);
1820 char *p1
= *(char **)ptr1
, *p2
= *(char **)ptr2
;
1825 return (p1
== p2
|| strequal(p1
, p2
));
1834 * Process a new section (service).
1836 * At this stage all sections are services.
1837 * Later we'll have special sections that permit server parameters to be set.
1838 * Returns True on success, False on failure.
1841 static bool do_section(const char *pszSectionName
, void *userdata
)
1843 struct loadparm_context
*lp_ctx
= (struct loadparm_context
*)userdata
;
1845 bool isglobal
= ((strwicmp(pszSectionName
, GLOBAL_NAME
) == 0) ||
1846 (strwicmp(pszSectionName
, GLOBAL_NAME2
) == 0));
1849 /* if we've just struck a global section, note the fact. */
1850 lp_ctx
->bInGlobalSection
= isglobal
;
1852 /* check for multiple global sections */
1853 if (lp_ctx
->bInGlobalSection
) {
1854 DEBUG(4, ("Processing section \"[%s]\"\n", pszSectionName
));
1858 /* if we have a current service, tidy it up before moving on */
1861 if (lp_ctx
->currentService
!= NULL
)
1862 bRetval
= lpcfg_service_ok(lp_ctx
->currentService
);
1864 /* if all is still well, move to the next record in the services array */
1866 /* We put this here to avoid an odd message order if messages are */
1867 /* issued by the post-processing of a previous section. */
1868 DEBUG(4, ("Processing section \"[%s]\"\n", pszSectionName
));
1870 if ((lp_ctx
->currentService
= lpcfg_add_service(lp_ctx
, lp_ctx
->sDefault
,
1873 DEBUG(0, ("Failed to add a new service\n"));
1883 * Determine if a particular base parameter is currently set to the default value.
1886 static bool is_default(struct loadparm_service
*sDefault
, int i
)
1888 void *def_ptr
= ((char *)sDefault
) + parm_table
[i
].offset
;
1889 switch (parm_table
[i
].type
) {
1892 return str_list_equal((const char * const *)parm_table
[i
].def
.lvalue
,
1893 *(const char ***)def_ptr
);
1896 return strequal(parm_table
[i
].def
.svalue
,
1900 return parm_table
[i
].def
.bvalue
==
1907 return parm_table
[i
].def
.ivalue
==
1916 *Display the contents of the global structure.
1919 static void dump_globals(struct loadparm_context
*lp_ctx
, FILE *f
,
1923 struct parmlist_entry
*data
;
1925 fprintf(f
, "# Global parameters\n[global]\n");
1927 for (i
= 0; parm_table
[i
].label
; i
++)
1928 if (parm_table
[i
].p_class
== P_GLOBAL
&&
1929 (i
== 0 || (parm_table
[i
].offset
!= parm_table
[i
- 1].offset
))) {
1930 if (!show_defaults
&& (lp_ctx
->flags
[i
] & FLAG_DEFAULT
))
1932 fprintf(f
, "\t%s = ", parm_table
[i
].label
);
1933 lpcfg_print_parameter(&parm_table
[i
], lpcfg_parm_ptr(lp_ctx
, NULL
, &parm_table
[i
]), f
);
1936 if (lp_ctx
->globals
->param_opt
!= NULL
) {
1937 for (data
= lp_ctx
->globals
->param_opt
; data
;
1938 data
= data
->next
) {
1939 if (!show_defaults
&& (data
->priority
& FLAG_DEFAULT
)) {
1942 fprintf(f
, "\t%s = %s\n", data
->key
, data
->value
);
1949 * Display the contents of a single services record.
1952 void lpcfg_dump_a_service(struct loadparm_service
* pService
, struct loadparm_service
*sDefault
, FILE * f
,
1953 unsigned int *flags
, bool show_defaults
)
1956 struct parmlist_entry
*data
;
1958 if (pService
!= sDefault
)
1959 fprintf(f
, "\n[%s]\n", pService
->szService
);
1961 for (i
= 0; parm_table
[i
].label
; i
++) {
1962 if (parm_table
[i
].p_class
== P_LOCAL
&&
1963 (*parm_table
[i
].label
!= '-') &&
1964 (i
== 0 || (parm_table
[i
].offset
!= parm_table
[i
- 1].offset
)))
1966 if (pService
== sDefault
) {
1967 if (flags
&& (flags
[i
] & FLAG_DEFAULT
)) {
1970 if (!show_defaults
) {
1971 if (is_default(sDefault
, i
)) {
1976 if (lpcfg_equal_parameter(parm_table
[i
].type
,
1977 ((char *)pService
) +
1978 parm_table
[i
].offset
,
1979 ((char *)sDefault
) +
1980 parm_table
[i
].offset
))
1984 fprintf(f
, "\t%s = ", parm_table
[i
].label
);
1985 lpcfg_print_parameter(&parm_table
[i
],
1986 ((char *)pService
) + parm_table
[i
].offset
, f
);
1990 if (pService
->param_opt
!= NULL
) {
1991 for (data
= pService
->param_opt
; data
; data
= data
->next
) {
1992 fprintf(f
, "\t%s = %s\n", data
->key
, data
->value
);
1997 bool lpcfg_dump_a_parameter(struct loadparm_context
*lp_ctx
,
1998 struct loadparm_service
*service
,
1999 const char *parm_name
, FILE * f
)
2001 struct parm_struct
*parm
;
2003 char *local_parm_name
;
2005 const char *parm_opt_value
;
2007 /* check for parametrical option */
2008 local_parm_name
= talloc_strdup(lp_ctx
, parm_name
);
2009 if (local_parm_name
== NULL
) {
2013 parm_opt
= strchr( local_parm_name
, ':');
2018 if (strlen(parm_opt
)) {
2019 parm_opt_value
= lpcfg_parm_string(lp_ctx
, service
,
2020 local_parm_name
, parm_opt
);
2021 if (parm_opt_value
) {
2022 fprintf(f
, "%s\n", parm_opt_value
);
2029 /* parameter is not parametric, search the table */
2030 parm
= lpcfg_parm_struct(lp_ctx
, parm_name
);
2035 if (service
!= NULL
&& parm
->p_class
== P_GLOBAL
) {
2039 ptr
= lpcfg_parm_ptr(lp_ctx
, service
,parm
);
2041 lpcfg_print_parameter(parm
, ptr
, f
);
2047 * Auto-load some home services.
2049 static void lpcfg_add_auto_services(struct loadparm_context
*lp_ctx
,
2057 * Unload unused services.
2060 void lpcfg_killunused(struct loadparm_context
*lp_ctx
,
2061 struct smbsrv_connection
*smb
,
2062 bool (*snumused
) (struct smbsrv_connection
*, int))
2065 for (i
= 0; i
< lp_ctx
->iNumServices
; i
++) {
2066 if (lp_ctx
->services
[i
] == NULL
)
2069 if (!snumused
|| !snumused(smb
, i
)) {
2070 talloc_free(lp_ctx
->services
[i
]);
2071 lp_ctx
->services
[i
] = NULL
;
2077 static int lpcfg_destructor(struct loadparm_context
*lp_ctx
)
2079 struct parmlist_entry
*data
;
2081 if (lp_ctx
->refuse_free
) {
2082 /* someone is trying to free the
2083 global_loadparm_context.
2084 We can't allow that. */
2088 if (lp_ctx
->globals
->param_opt
!= NULL
) {
2089 struct parmlist_entry
*next
;
2090 for (data
= lp_ctx
->globals
->param_opt
; data
; data
=next
) {
2092 if (data
->priority
& FLAG_CMDLINE
) continue;
2093 DLIST_REMOVE(lp_ctx
->globals
->param_opt
, data
);
2102 * Initialise the global parameter structure.
2104 * Note that most callers should use loadparm_init_global() instead
2106 struct loadparm_context
*loadparm_init(TALLOC_CTX
*mem_ctx
)
2110 struct loadparm_context
*lp_ctx
;
2111 struct parmlist_entry
*parm
;
2114 lp_ctx
= talloc_zero(mem_ctx
, struct loadparm_context
);
2118 talloc_set_destructor(lp_ctx
, lpcfg_destructor
);
2119 lp_ctx
->bInGlobalSection
= true;
2120 lp_ctx
->globals
= talloc_zero(lp_ctx
, struct loadparm_global
);
2121 /* This appears odd, but globals in s3 isn't a pointer */
2122 lp_ctx
->globals
->ctx
= lp_ctx
->globals
;
2123 lp_ctx
->sDefault
= talloc_zero(lp_ctx
, struct loadparm_service
);
2124 lp_ctx
->flags
= talloc_zero_array(lp_ctx
, unsigned int, num_parameters());
2126 lp_ctx
->sDefault
->iMaxPrintJobs
= 1000;
2127 lp_ctx
->sDefault
->bAvailable
= true;
2128 lp_ctx
->sDefault
->browseable
= true;
2129 lp_ctx
->sDefault
->read_only
= true;
2130 lp_ctx
->sDefault
->map_archive
= true;
2131 lp_ctx
->sDefault
->strict_locking
= true;
2132 lp_ctx
->sDefault
->oplocks
= true;
2133 lp_ctx
->sDefault
->create_mask
= 0744;
2134 lp_ctx
->sDefault
->force_create_mode
= 0000;
2135 lp_ctx
->sDefault
->directory_mask
= 0755;
2136 lp_ctx
->sDefault
->force_directory_mode
= 0000;
2138 DEBUG(3, ("Initialising global parameters\n"));
2140 for (i
= 0; parm_table
[i
].label
; i
++) {
2141 if ((parm_table
[i
].type
== P_STRING
||
2142 parm_table
[i
].type
== P_USTRING
) &&
2143 !(lp_ctx
->flags
[i
] & FLAG_CMDLINE
)) {
2145 if (parm_table
[i
].p_class
== P_LOCAL
) {
2146 r
= (char **)(((char *)lp_ctx
->sDefault
) + parm_table
[i
].offset
);
2148 r
= (char **)(((char *)lp_ctx
->globals
) + parm_table
[i
].offset
);
2150 *r
= talloc_strdup(lp_ctx
, "");
2154 logfile
= talloc_asprintf(lp_ctx
, "%s/log.samba", dyn_LOGFILEBASE
);
2155 lpcfg_do_global_parameter(lp_ctx
, "log file", logfile
);
2156 talloc_free(logfile
);
2158 lpcfg_do_global_parameter(lp_ctx
, "log level", "0");
2160 lpcfg_do_global_parameter(lp_ctx
, "syslog", "1");
2161 lpcfg_do_global_parameter(lp_ctx
, "syslog only", "No");
2162 lpcfg_do_global_parameter(lp_ctx
, "debug timestamp", "Yes");
2163 lpcfg_do_global_parameter(lp_ctx
, "debug prefix timestamp", "No");
2164 lpcfg_do_global_parameter(lp_ctx
, "debug hires timestamp", "Yes");
2165 lpcfg_do_global_parameter(lp_ctx
, "debug pid", "No");
2166 lpcfg_do_global_parameter(lp_ctx
, "debug uid", "No");
2167 lpcfg_do_global_parameter(lp_ctx
, "debug class", "No");
2169 lpcfg_do_global_parameter(lp_ctx
, "share backend", "classic");
2171 lpcfg_do_global_parameter(lp_ctx
, "server role", "auto");
2172 lpcfg_do_global_parameter(lp_ctx
, "domain logons", "No");
2173 lpcfg_do_global_parameter(lp_ctx
, "domain master", "Auto");
2175 /* options that can be set on the command line must be initialised via
2176 the slower lpcfg_do_global_parameter() to ensure that FLAG_CMDLINE is obeyed */
2178 lpcfg_do_global_parameter(lp_ctx
, "socket options", "TCP_NODELAY");
2180 lpcfg_do_global_parameter(lp_ctx
, "workgroup", DEFAULT_WORKGROUP
);
2181 myname
= get_myname(lp_ctx
);
2182 lpcfg_do_global_parameter(lp_ctx
, "netbios name", myname
);
2183 talloc_free(myname
);
2184 lpcfg_do_global_parameter(lp_ctx
, "name resolve order", "lmhosts wins host bcast");
2186 lpcfg_do_global_parameter(lp_ctx
, "fstype", "NTFS");
2188 lpcfg_do_global_parameter(lp_ctx
, "ntvfs handler", "unixuid default");
2189 lpcfg_do_global_parameter(lp_ctx
, "max connections", "0");
2191 lpcfg_do_global_parameter(lp_ctx
, "dcerpc endpoint servers", "epmapper wkssvc rpcecho samr netlogon lsarpc spoolss drsuapi dssetup unixinfo browser eventlog6 backupkey dnsserver");
2192 lpcfg_do_global_parameter(lp_ctx
, "server services", "s3fs rpc nbt wrepl ldap cldap kdc drepl winbind ntp_signd kcc dnsupdate dns");
2193 lpcfg_do_global_parameter(lp_ctx
, "kccsrv:samba_kcc", "true");
2194 /* the winbind method for domain controllers is for both RODC
2195 auth forwarding and for trusted domains */
2196 lpcfg_do_global_parameter(lp_ctx
, "private dir", dyn_PRIVATE_DIR
);
2197 lpcfg_do_global_parameter(lp_ctx
, "registry:HKEY_LOCAL_MACHINE", "hklm.ldb");
2199 /* This hive should be dynamically generated by Samba using
2200 data from the sam, but for the moment leave it in a tdb to
2201 keep regedt32 from popping up an annoying dialog. */
2202 lpcfg_do_global_parameter(lp_ctx
, "registry:HKEY_USERS", "hku.ldb");
2204 /* using UTF8 by default allows us to support all chars */
2205 lpcfg_do_global_parameter(lp_ctx
, "unix charset", "UTF-8");
2207 /* Use codepage 850 as a default for the dos character set */
2208 lpcfg_do_global_parameter(lp_ctx
, "dos charset", "CP850");
2211 * Allow the default PASSWD_CHAT to be overridden in local.h.
2213 lpcfg_do_global_parameter(lp_ctx
, "passwd chat", DEFAULT_PASSWD_CHAT
);
2215 lpcfg_do_global_parameter(lp_ctx
, "pid directory", dyn_PIDDIR
);
2216 lpcfg_do_global_parameter(lp_ctx
, "lock dir", dyn_LOCKDIR
);
2217 lpcfg_do_global_parameter(lp_ctx
, "state directory", dyn_STATEDIR
);
2218 lpcfg_do_global_parameter(lp_ctx
, "cache directory", dyn_CACHEDIR
);
2219 lpcfg_do_global_parameter(lp_ctx
, "ncalrpc dir", dyn_NCALRPCDIR
);
2221 lpcfg_do_global_parameter(lp_ctx
, "nbt client socket address", "0.0.0.0");
2222 lpcfg_do_global_parameter_var(lp_ctx
, "server string",
2223 "Samba %s", SAMBA_VERSION_STRING
);
2225 lpcfg_do_global_parameter(lp_ctx
, "password server", "*");
2227 lpcfg_do_global_parameter(lp_ctx
, "max mux", "50");
2228 lpcfg_do_global_parameter(lp_ctx
, "max xmit", "16644");
2229 lpcfg_do_global_parameter(lp_ctx
, "host msdfs", "true");
2231 lpcfg_do_global_parameter(lp_ctx
, "LargeReadwrite", "True");
2232 lpcfg_do_global_parameter(lp_ctx
, "server min protocol", "LANMAN1");
2233 lpcfg_do_global_parameter(lp_ctx
, "server max protocol", "SMB3");
2234 lpcfg_do_global_parameter(lp_ctx
, "client min protocol", "CORE");
2235 lpcfg_do_global_parameter(lp_ctx
, "client max protocol", "NT1");
2236 lpcfg_do_global_parameter(lp_ctx
, "security", "AUTO");
2237 lpcfg_do_global_parameter(lp_ctx
, "EncryptPasswords", "True");
2238 lpcfg_do_global_parameter(lp_ctx
, "ReadRaw", "True");
2239 lpcfg_do_global_parameter(lp_ctx
, "WriteRaw", "True");
2240 lpcfg_do_global_parameter(lp_ctx
, "NullPasswords", "False");
2241 lpcfg_do_global_parameter(lp_ctx
, "old password allowed period", "60");
2242 lpcfg_do_global_parameter(lp_ctx
, "ObeyPamRestrictions", "False");
2244 lpcfg_do_global_parameter(lp_ctx
, "TimeServer", "False");
2245 lpcfg_do_global_parameter(lp_ctx
, "BindInterfacesOnly", "False");
2246 lpcfg_do_global_parameter(lp_ctx
, "Unicode", "True");
2247 lpcfg_do_global_parameter(lp_ctx
, "ClientLanManAuth", "False");
2248 lpcfg_do_global_parameter(lp_ctx
, "ClientNTLMv2Auth", "True");
2249 lpcfg_do_global_parameter(lp_ctx
, "LanmanAuth", "False");
2250 lpcfg_do_global_parameter(lp_ctx
, "NTLMAuth", "True");
2251 lpcfg_do_global_parameter(lp_ctx
, "client use spnego principal", "False");
2253 lpcfg_do_global_parameter(lp_ctx
, "UnixExtensions", "True");
2255 lpcfg_do_global_parameter(lp_ctx
, "PreferredMaster", "Auto");
2256 lpcfg_do_global_parameter(lp_ctx
, "LocalMaster", "True");
2258 lpcfg_do_global_parameter(lp_ctx
, "wins support", "False");
2259 lpcfg_do_global_parameter(lp_ctx
, "dns proxy", "True");
2261 lpcfg_do_global_parameter(lp_ctx
, "winbind separator", "\\");
2262 lpcfg_do_global_parameter(lp_ctx
, "winbind sealed pipes", "True");
2263 lpcfg_do_global_parameter(lp_ctx
, "require strong key", "True");
2264 lpcfg_do_global_parameter(lp_ctx
, "winbindd socket directory", dyn_WINBINDD_SOCKET_DIR
);
2265 lpcfg_do_global_parameter(lp_ctx
, "winbindd privileged socket directory", dyn_WINBINDD_PRIVILEGED_SOCKET_DIR
);
2266 lpcfg_do_global_parameter(lp_ctx
, "ntp signd socket directory", dyn_NTP_SIGND_SOCKET_DIR
);
2267 lpcfg_do_global_parameter_var(lp_ctx
, "dns update command", "%s/samba_dnsupdate", dyn_SCRIPTSBINDIR
);
2268 lpcfg_do_global_parameter_var(lp_ctx
, "spn update command", "%s/samba_spnupdate", dyn_SCRIPTSBINDIR
);
2269 lpcfg_do_global_parameter_var(lp_ctx
, "samba kcc command",
2270 "%s/samba_kcc", dyn_SCRIPTSBINDIR
);
2271 lpcfg_do_global_parameter(lp_ctx
, "template shell", "/bin/false");
2272 lpcfg_do_global_parameter(lp_ctx
, "template homedir", "/home/%WORKGROUP%/%ACCOUNTNAME%");
2274 lpcfg_do_global_parameter(lp_ctx
, "client signing", "default");
2275 lpcfg_do_global_parameter(lp_ctx
, "server signing", "default");
2277 lpcfg_do_global_parameter(lp_ctx
, "use spnego", "True");
2279 lpcfg_do_global_parameter(lp_ctx
, "use mmap", "True");
2281 lpcfg_do_global_parameter(lp_ctx
, "smb ports", "445 139");
2282 lpcfg_do_global_parameter(lp_ctx
, "nbt port", "137");
2283 lpcfg_do_global_parameter(lp_ctx
, "dgram port", "138");
2284 lpcfg_do_global_parameter(lp_ctx
, "cldap port", "389");
2285 lpcfg_do_global_parameter(lp_ctx
, "krb5 port", "88");
2286 lpcfg_do_global_parameter(lp_ctx
, "kpasswd port", "464");
2287 lpcfg_do_global_parameter(lp_ctx
, "web port", "901");
2289 lpcfg_do_global_parameter(lp_ctx
, "nt status support", "True");
2291 lpcfg_do_global_parameter(lp_ctx
, "max wins ttl", "518400"); /* 6 days */
2292 lpcfg_do_global_parameter(lp_ctx
, "min wins ttl", "21600");
2294 lpcfg_do_global_parameter(lp_ctx
, "tls enabled", "True");
2295 lpcfg_do_global_parameter(lp_ctx
, "tls keyfile", "tls/key.pem");
2296 lpcfg_do_global_parameter(lp_ctx
, "tls certfile", "tls/cert.pem");
2297 lpcfg_do_global_parameter(lp_ctx
, "tls cafile", "tls/ca.pem");
2298 lpcfg_do_global_parameter(lp_ctx
, "prefork children:smb", "4");
2300 lpcfg_do_global_parameter(lp_ctx
, "rndc command", "/usr/sbin/rndc");
2301 lpcfg_do_global_parameter(lp_ctx
, "nsupdate command", "/usr/bin/nsupdate -g");
2303 lpcfg_do_global_parameter(lp_ctx
, "allow dns updates", "secure only");
2304 lpcfg_do_global_parameter(lp_ctx
, "dns forwarder", "");
2306 lpcfg_do_global_parameter(lp_ctx
, "algorithmic rid base", "1000");
2308 lpcfg_do_global_parameter(lp_ctx
, "enhanced browsing", "True");
2310 lpcfg_do_global_parameter(lp_ctx
, "winbind nss info", "template");
2312 lpcfg_do_global_parameter(lp_ctx
, "server schannel", "Auto");
2314 lpcfg_do_global_parameter(lp_ctx
, "short preserve case", "True");
2316 lpcfg_do_global_parameter(lp_ctx
, "max open files", "16384");
2318 lpcfg_do_global_parameter(lp_ctx
, "cups connection timeout", "30");
2320 lpcfg_do_global_parameter(lp_ctx
, "locking", "True");
2322 lpcfg_do_global_parameter(lp_ctx
, "block size", "1024");
2324 lpcfg_do_global_parameter(lp_ctx
, "client use spnego", "True");
2326 lpcfg_do_global_parameter(lp_ctx
, "change notify", "True");
2328 lpcfg_do_global_parameter(lp_ctx
, "name cache timeout", "660");
2330 lpcfg_do_global_parameter(lp_ctx
, "defer sharing violations", "True");
2332 lpcfg_do_global_parameter(lp_ctx
, "ldap replication sleep", "1000");
2334 lpcfg_do_global_parameter(lp_ctx
, "idmap backend", "tdb");
2336 lpcfg_do_global_parameter(lp_ctx
, "enable privileges", "True");
2338 lpcfg_do_global_parameter_var(lp_ctx
, "smb2 max write", "%u", DEFAULT_SMB2_MAX_WRITE
);
2340 lpcfg_do_global_parameter(lp_ctx
, "passdb backend", "tdbsam");
2342 lpcfg_do_global_parameter(lp_ctx
, "getwd cache", "True");
2344 lpcfg_do_global_parameter(lp_ctx
, "winbind nested groups", "True");
2346 lpcfg_do_global_parameter(lp_ctx
, "mangled names", "True");
2348 lpcfg_do_global_parameter_var(lp_ctx
, "smb2 max credits", "%u", DEFAULT_SMB2_MAX_CREDITS
);
2350 lpcfg_do_global_parameter(lp_ctx
, "ldap ssl", "start tls");
2352 lpcfg_do_global_parameter(lp_ctx
, "ldap deref", "auto");
2354 lpcfg_do_global_parameter(lp_ctx
, "lm interval", "60");
2356 lpcfg_do_global_parameter(lp_ctx
, "mangling method", "hash2");
2358 lpcfg_do_global_parameter(lp_ctx
, "hide dot files", "True");
2360 lpcfg_do_global_parameter(lp_ctx
, "browse list", "True");
2362 lpcfg_do_global_parameter(lp_ctx
, "passwd chat timeout", "2");
2364 lpcfg_do_global_parameter(lp_ctx
, "guest account", GUEST_ACCOUNT
);
2366 lpcfg_do_global_parameter(lp_ctx
, "client schannel", "auto");
2368 lpcfg_do_global_parameter(lp_ctx
, "smb encrypt", "default");
2370 lpcfg_do_global_parameter(lp_ctx
, "max log size", "5000");
2372 lpcfg_do_global_parameter(lp_ctx
, "idmap negative cache time", "120");
2374 lpcfg_do_global_parameter(lp_ctx
, "ldap follow referral", "auto");
2376 lpcfg_do_global_parameter(lp_ctx
, "multicast dns register", "yes");
2378 lpcfg_do_global_parameter(lp_ctx
, "winbind reconnect delay", "30");
2380 lpcfg_do_global_parameter(lp_ctx
, "nt acl support", "yes");
2382 lpcfg_do_global_parameter(lp_ctx
, "acl check permissions", "yes");
2384 lpcfg_do_global_parameter(lp_ctx
, "keepalive", "300");
2386 lpcfg_do_global_parameter(lp_ctx
, "winbind cache time", "300");
2388 lpcfg_do_global_parameter(lp_ctx
, "level2 oplocks", "yes");
2390 lpcfg_do_global_parameter(lp_ctx
, "show add printer wizard", "yes");
2392 lpcfg_do_global_parameter(lp_ctx
, "allocation roundup size", "1048576");
2394 lpcfg_do_global_parameter(lp_ctx
, "ldap page size", "1024");
2396 lpcfg_do_global_parameter(lp_ctx
, "kernel share modes", "yes");
2398 lpcfg_do_global_parameter(lp_ctx
, "strict locking", "Auto");
2400 lpcfg_do_global_parameter(lp_ctx
, "map readonly", "yes");
2402 lpcfg_do_global_parameter(lp_ctx
, "allow trusted domains", "yes");
2404 lpcfg_do_global_parameter(lp_ctx
, "default devmode", "yes");
2406 lpcfg_do_global_parameter(lp_ctx
, "os level", "20");
2408 lpcfg_do_global_parameter(lp_ctx
, "dos filetimes", "yes");
2410 lpcfg_do_global_parameter(lp_ctx
, "mangling char", "~");
2412 lpcfg_do_global_parameter(lp_ctx
, "printcap cache time", "750");
2414 lpcfg_do_global_parameter(lp_ctx
, "create krb5 conf", "yes");
2416 lpcfg_do_global_parameter(lp_ctx
, "winbind max clients", "200");
2418 lpcfg_do_global_parameter(lp_ctx
, "acl map full control", "yes");
2420 lpcfg_do_global_parameter(lp_ctx
, "nt pipe support", "yes");
2422 lpcfg_do_global_parameter(lp_ctx
, "ldap debug threshold", "10");
2424 lpcfg_do_global_parameter(lp_ctx
, "follow symlinks", "yes");
2426 lpcfg_do_global_parameter(lp_ctx
, "machine password timeout", "604800");
2428 lpcfg_do_global_parameter(lp_ctx
, "ldap connection timeout", "2");
2430 lpcfg_do_global_parameter(lp_ctx
, "winbind expand groups", "1");
2432 lpcfg_do_global_parameter(lp_ctx
, "stat cache", "yes");
2434 lpcfg_do_global_parameter(lp_ctx
, "lpq cache time", "30");
2436 lpcfg_do_global_parameter_var(lp_ctx
, "smb2 max trans", "%u", DEFAULT_SMB2_MAX_TRANSACT
);
2438 lpcfg_do_global_parameter_var(lp_ctx
, "smb2 max read", "%u", DEFAULT_SMB2_MAX_READ
);
2440 lpcfg_do_global_parameter(lp_ctx
, "durable handles", "yes");
2442 lpcfg_do_global_parameter(lp_ctx
, "max stat cache size", "256");
2444 lpcfg_do_global_parameter(lp_ctx
, "ldap passwd sync", "no");
2446 lpcfg_do_global_parameter(lp_ctx
, "kernel change notify", "yes");
2448 lpcfg_do_global_parameter(lp_ctx
, "max ttl", "259200");
2450 lpcfg_do_global_parameter(lp_ctx
, "blocking locks", "yes");
2452 lpcfg_do_global_parameter(lp_ctx
, "oplock contention limit", "2");
2454 lpcfg_do_global_parameter(lp_ctx
, "load printers", "yes");
2456 lpcfg_do_global_parameter(lp_ctx
, "idmap cache time", "604800");
2458 lpcfg_do_global_parameter(lp_ctx
, "preserve case", "yes");
2460 lpcfg_do_global_parameter(lp_ctx
, "lm announce", "auto");
2462 lpcfg_do_global_parameter(lp_ctx
, "afs token lifetime", "604800");
2464 lpcfg_do_global_parameter(lp_ctx
, "enable core files", "yes");
2466 lpcfg_do_global_parameter(lp_ctx
, "winbind max domain connections", "1");
2468 lpcfg_do_global_parameter(lp_ctx
, "case sensitive", "auto");
2470 lpcfg_do_global_parameter(lp_ctx
, "ldap timeout", "15");
2472 lpcfg_do_global_parameter(lp_ctx
, "mangle prefix", "1");
2474 lpcfg_do_global_parameter(lp_ctx
, "posix locking", "yes");
2476 lpcfg_do_global_parameter(lp_ctx
, "lock spin time", "200");
2478 lpcfg_do_global_parameter(lp_ctx
, "directory name cache size", "100");
2480 lpcfg_do_global_parameter(lp_ctx
, "nmbd bind explicit broadcast", "yes");
2482 lpcfg_do_global_parameter(lp_ctx
, "init logon delay", "100");
2484 lpcfg_do_global_parameter(lp_ctx
, "usershare owner only", "yes");
2486 lpcfg_do_global_parameter(lp_ctx
, "-valid", "yes");
2488 lpcfg_do_global_parameter_var(lp_ctx
, "usershare path", "%s/usershares", get_dyn_STATEDIR());
2491 lpcfg_do_global_parameter_var(lp_ctx
, "panic action", "/bin/sleep 999999999");
2494 lpcfg_do_global_parameter(lp_ctx
, "smb passwd file", get_dyn_SMB_PASSWD_FILE());
2496 lpcfg_do_global_parameter(lp_ctx
, "logon home", "\\\\%N\\%U");
2498 lpcfg_do_global_parameter(lp_ctx
, "logon path", "\\\\%N\\%U\\profile");
2500 lpcfg_do_global_parameter(lp_ctx
, "printjob username", "%U");
2502 for (i
= 0; parm_table
[i
].label
; i
++) {
2503 if (!(lp_ctx
->flags
[i
] & FLAG_CMDLINE
)) {
2504 lp_ctx
->flags
[i
] |= FLAG_DEFAULT
;
2508 for (parm
=lp_ctx
->globals
->param_opt
; parm
; parm
=parm
->next
) {
2509 if (!(parm
->priority
& FLAG_CMDLINE
)) {
2510 parm
->priority
|= FLAG_DEFAULT
;
2518 * Initialise the global parameter structure.
2520 struct loadparm_context
*loadparm_init_global(bool load_default
)
2522 if (global_loadparm_context
== NULL
) {
2523 global_loadparm_context
= loadparm_init(NULL
);
2525 if (global_loadparm_context
== NULL
) {
2528 global_loadparm_context
->global
= true;
2529 if (load_default
&& !global_loadparm_context
->loaded
) {
2530 lpcfg_load_default(global_loadparm_context
);
2532 global_loadparm_context
->refuse_free
= true;
2533 return global_loadparm_context
;
2537 * Initialise the global parameter structure.
2539 struct loadparm_context
*loadparm_init_s3(TALLOC_CTX
*mem_ctx
,
2540 const struct loadparm_s3_helpers
*s3_fns
)
2542 struct loadparm_context
*loadparm_context
= talloc_zero(mem_ctx
, struct loadparm_context
);
2543 if (!loadparm_context
) {
2546 loadparm_context
->s3_fns
= s3_fns
;
2547 loadparm_context
->globals
= s3_fns
->globals
;
2548 return loadparm_context
;
2551 const char *lpcfg_configfile(struct loadparm_context
*lp_ctx
)
2553 return lp_ctx
->szConfigFile
;
2556 const char *lp_default_path(void)
2558 if (getenv("SMB_CONF_PATH"))
2559 return getenv("SMB_CONF_PATH");
2561 return dyn_CONFIGFILE
;
2565 * Update the internal state of a loadparm context after settings
2568 static bool lpcfg_update(struct loadparm_context
*lp_ctx
)
2570 struct debug_settings settings
;
2571 TALLOC_CTX
*tmp_ctx
;
2573 tmp_ctx
= talloc_new(lp_ctx
);
2574 if (tmp_ctx
== NULL
) {
2578 lpcfg_add_auto_services(lp_ctx
, lpcfg_auto_services(lp_ctx
, tmp_ctx
));
2580 if (!lp_ctx
->globals
->wins_server_list
&& lp_ctx
->globals
->we_are_a_wins_server
) {
2581 lpcfg_do_global_parameter(lp_ctx
, "wins server", "127.0.0.1");
2584 if (!lp_ctx
->global
) {
2585 TALLOC_FREE(tmp_ctx
);
2589 panic_action
= lp_ctx
->globals
->panic_action
;
2591 reload_charcnv(lp_ctx
);
2593 ZERO_STRUCT(settings
);
2594 /* Add any more debug-related smb.conf parameters created in
2596 settings
.syslog
= lp_ctx
->globals
->syslog
;
2597 settings
.syslog_only
= lp_ctx
->globals
->syslog_only
;
2598 settings
.timestamp_logs
= lp_ctx
->globals
->timestamp_logs
;
2599 settings
.debug_prefix_timestamp
= lp_ctx
->globals
->debug_prefix_timestamp
;
2600 settings
.debug_hires_timestamp
= lp_ctx
->globals
->debug_hires_timestamp
;
2601 settings
.debug_pid
= lp_ctx
->globals
->debug_pid
;
2602 settings
.debug_uid
= lp_ctx
->globals
->debug_uid
;
2603 settings
.debug_class
= lp_ctx
->globals
->debug_class
;
2604 debug_set_settings(&settings
);
2606 /* FIXME: This is a bit of a hack, but we can't use a global, since
2607 * not everything that uses lp also uses the socket library */
2608 if (lpcfg_parm_bool(lp_ctx
, NULL
, "socket", "testnonblock", false)) {
2609 setenv("SOCKET_TESTNONBLOCK", "1", 1);
2611 unsetenv("SOCKET_TESTNONBLOCK");
2614 TALLOC_FREE(tmp_ctx
);
2618 bool lpcfg_load_default(struct loadparm_context
*lp_ctx
)
2622 path
= lp_default_path();
2624 if (!file_exist(path
)) {
2625 /* We allow the default smb.conf file to not exist,
2626 * basically the equivalent of an empty file. */
2627 return lpcfg_update(lp_ctx
);
2630 return lpcfg_load(lp_ctx
, path
);
2634 * Load the services array from the services file.
2636 * Return True on success, False on failure.
2638 bool lpcfg_load(struct loadparm_context
*lp_ctx
, const char *filename
)
2643 filename
= talloc_strdup(lp_ctx
, filename
);
2645 lp_ctx
->szConfigFile
= filename
;
2647 if (lp_ctx
->s3_fns
) {
2648 return lp_ctx
->s3_fns
->load(filename
);
2651 lp_ctx
->bInGlobalSection
= true;
2652 n2
= standard_sub_basic(lp_ctx
, lp_ctx
->szConfigFile
);
2653 DEBUG(2, ("lpcfg_load: refreshing parameters from %s\n", n2
));
2655 add_to_file_list(lp_ctx
, &lp_ctx
->file_lists
, lp_ctx
->szConfigFile
, n2
);
2657 /* We get sections first, so have to start 'behind' to make up */
2658 lp_ctx
->currentService
= NULL
;
2659 bRetval
= pm_process(n2
, do_section
, do_parameter
, lp_ctx
);
2661 /* finish up the last section */
2662 DEBUG(4, ("pm_process() returned %s\n", BOOLSTR(bRetval
)));
2664 if (lp_ctx
->currentService
!= NULL
)
2665 bRetval
= lpcfg_service_ok(lp_ctx
->currentService
);
2667 bRetval
= bRetval
&& lpcfg_update(lp_ctx
);
2669 /* we do this unconditionally, so that it happens even
2670 for a missing smb.conf */
2671 reload_charcnv(lp_ctx
);
2673 if (bRetval
== true) {
2674 /* set this up so that any child python tasks will
2675 find the right smb.conf */
2676 setenv("SMB_CONF_PATH", filename
, 1);
2678 /* set the context used by the lp_*() function
2680 global_loadparm_context
= lp_ctx
;
2681 lp_ctx
->loaded
= true;
2688 * Return the max number of services.
2691 int lpcfg_numservices(struct loadparm_context
*lp_ctx
)
2693 if (lp_ctx
->s3_fns
) {
2694 return lp_ctx
->s3_fns
->get_numservices();
2697 return lp_ctx
->iNumServices
;
2701 * Display the contents of the services array in human-readable form.
2704 void lpcfg_dump(struct loadparm_context
*lp_ctx
, FILE *f
, bool show_defaults
,
2709 if (lp_ctx
->s3_fns
) {
2710 lp_ctx
->s3_fns
->dump(f
, show_defaults
, maxtoprint
);
2714 dump_globals(lp_ctx
, f
, show_defaults
);
2716 lpcfg_dump_a_service(lp_ctx
->sDefault
, lp_ctx
->sDefault
, f
, lp_ctx
->flags
, show_defaults
);
2718 for (iService
= 0; iService
< maxtoprint
; iService
++)
2719 lpcfg_dump_one(f
, show_defaults
, lp_ctx
->services
[iService
], lp_ctx
->sDefault
);
2723 * Display the contents of one service in human-readable form.
2725 void lpcfg_dump_one(FILE *f
, bool show_defaults
, struct loadparm_service
*service
, struct loadparm_service
*sDefault
)
2727 if (service
!= NULL
) {
2728 if (service
->szService
[0] == '\0')
2730 lpcfg_dump_a_service(service
, sDefault
, f
, NULL
, show_defaults
);
2734 struct loadparm_service
*lpcfg_servicebynum(struct loadparm_context
*lp_ctx
,
2737 if (lp_ctx
->s3_fns
) {
2738 return lp_ctx
->s3_fns
->get_servicebynum(snum
);
2741 return lp_ctx
->services
[snum
];
2744 struct loadparm_service
*lpcfg_service(struct loadparm_context
*lp_ctx
,
2745 const char *service_name
)
2750 if (lp_ctx
->s3_fns
) {
2751 return lp_ctx
->s3_fns
->get_service(service_name
);
2754 for (iService
= lp_ctx
->iNumServices
- 1; iService
>= 0; iService
--) {
2755 if (lp_ctx
->services
[iService
] &&
2756 lp_ctx
->services
[iService
]->szService
) {
2758 * The substitution here is used to support %U is
2761 serviceName
= standard_sub_basic(
2762 lp_ctx
->services
[iService
],
2763 lp_ctx
->services
[iService
]->szService
);
2764 if (strequal(serviceName
, service_name
)) {
2765 talloc_free(serviceName
);
2766 return lp_ctx
->services
[iService
];
2768 talloc_free(serviceName
);
2772 DEBUG(7,("lpcfg_servicenumber: couldn't find %s\n", service_name
));
2776 const char *lpcfg_servicename(const struct loadparm_service
*service
)
2778 return lpcfg_string((const char *)service
->szService
);
2782 * A useful volume label function.
2784 const char *lpcfg_volume_label(struct loadparm_service
*service
, struct loadparm_service
*sDefault
)
2787 ret
= lpcfg_string((const char *)((service
!= NULL
&& service
->volume
!= NULL
) ?
2788 service
->volume
: sDefault
->volume
));
2790 return lpcfg_servicename(service
);
2795 * Return the correct printer name.
2797 const char *lpcfg_printername(struct loadparm_service
*service
, struct loadparm_service
*sDefault
)
2800 ret
= lpcfg_string((const char *)((service
!= NULL
&& service
->_printername
!= NULL
) ?
2801 service
->_printername
: sDefault
->_printername
));
2802 if (ret
== NULL
|| (ret
!= NULL
&& *ret
== '\0'))
2803 ret
= lpcfg_servicename(service
);
2810 * Return the max print jobs per queue.
2812 int lpcfg_maxprintjobs(struct loadparm_service
*service
, struct loadparm_service
*sDefault
)
2814 int maxjobs
= (service
!= NULL
) ? service
->iMaxPrintJobs
: sDefault
->iMaxPrintJobs
;
2815 if (maxjobs
<= 0 || maxjobs
>= PRINT_MAX_JOBID
)
2816 maxjobs
= PRINT_MAX_JOBID
- 1;
2821 struct smb_iconv_handle
*lpcfg_iconv_handle(struct loadparm_context
*lp_ctx
)
2823 if (lp_ctx
== NULL
) {
2824 return get_iconv_handle();
2826 return lp_ctx
->iconv_handle
;
2829 _PUBLIC_
void reload_charcnv(struct loadparm_context
*lp_ctx
)
2831 struct smb_iconv_handle
*old_ic
= lp_ctx
->iconv_handle
;
2832 if (!lp_ctx
->global
) {
2836 if (old_ic
== NULL
) {
2837 old_ic
= global_iconv_handle
;
2839 lp_ctx
->iconv_handle
= smb_iconv_handle_reinit_lp(lp_ctx
, lp_ctx
, old_ic
);
2840 global_iconv_handle
= lp_ctx
->iconv_handle
;
2843 _PUBLIC_
char *lpcfg_tls_keyfile(TALLOC_CTX
*mem_ctx
, struct loadparm_context
*lp_ctx
)
2845 return lpcfg_private_path(mem_ctx
, lp_ctx
, lpcfg__tls_keyfile(lp_ctx
));
2848 _PUBLIC_
char *lpcfg_tls_certfile(TALLOC_CTX
*mem_ctx
, struct loadparm_context
*lp_ctx
)
2850 return lpcfg_private_path(mem_ctx
, lp_ctx
, lpcfg__tls_certfile(lp_ctx
));
2853 _PUBLIC_
char *lpcfg_tls_cafile(TALLOC_CTX
*mem_ctx
, struct loadparm_context
*lp_ctx
)
2855 return lpcfg_private_path(mem_ctx
, lp_ctx
, lpcfg__tls_cafile(lp_ctx
));
2858 _PUBLIC_
char *lpcfg_tls_crlfile(TALLOC_CTX
*mem_ctx
, struct loadparm_context
*lp_ctx
)
2860 return lpcfg_private_path(mem_ctx
, lp_ctx
, lpcfg__tls_crlfile(lp_ctx
));
2863 _PUBLIC_
char *lpcfg_tls_dhpfile(TALLOC_CTX
*mem_ctx
, struct loadparm_context
*lp_ctx
)
2865 return lpcfg_private_path(mem_ctx
, lp_ctx
, lpcfg__tls_dhpfile(lp_ctx
));
2868 struct gensec_settings
*lpcfg_gensec_settings(TALLOC_CTX
*mem_ctx
, struct loadparm_context
*lp_ctx
)
2870 struct gensec_settings
*settings
= talloc_zero(mem_ctx
, struct gensec_settings
);
2871 if (settings
== NULL
)
2873 SMB_ASSERT(lp_ctx
!= NULL
);
2874 settings
->lp_ctx
= talloc_reference(settings
, lp_ctx
);
2875 settings
->target_hostname
= lpcfg_parm_string(lp_ctx
, NULL
, "gensec", "target_hostname");
2879 int lpcfg_server_role(struct loadparm_context
*lp_ctx
)
2881 int domain_master
= lpcfg__domain_master(lp_ctx
);
2883 return lp_find_server_role(lpcfg__server_role(lp_ctx
),
2884 lpcfg__security(lp_ctx
),
2885 lpcfg__domain_logons(lp_ctx
),
2886 (domain_master
== true) ||
2887 (domain_master
== Auto
));
2890 int lpcfg_security(struct loadparm_context
*lp_ctx
)
2892 return lp_find_security(lpcfg__server_role(lp_ctx
),
2893 lpcfg__security(lp_ctx
));
2896 bool lpcfg_server_signing_allowed(struct loadparm_context
*lp_ctx
, bool *mandatory
)
2898 bool allowed
= true;
2899 enum smb_signing_setting signing_setting
= lpcfg_server_signing(lp_ctx
);
2903 if (signing_setting
== SMB_SIGNING_DEFAULT
) {
2905 * If we are a domain controller, SMB signing is
2906 * really important, as it can prevent a number of
2907 * attacks on communications between us and the
2910 * However, it really sucks (no sendfile, CPU
2911 * overhead) performance-wise when used on a
2912 * file server, so disable it by default
2916 if (lpcfg_server_role(lp_ctx
) >= ROLE_ACTIVE_DIRECTORY_DC
) {
2917 signing_setting
= SMB_SIGNING_REQUIRED
;
2919 signing_setting
= SMB_SIGNING_OFF
;
2923 switch (signing_setting
) {
2924 case SMB_SIGNING_REQUIRED
:
2927 case SMB_SIGNING_IF_REQUIRED
:
2929 case SMB_SIGNING_DEFAULT
:
2930 case SMB_SIGNING_OFF
:
2938 int lpcfg_tdb_hash_size(struct loadparm_context
*lp_ctx
, const char *name
)
2946 base
= strrchr_m(name
, '/');
2952 return lpcfg_parm_int(lp_ctx
, NULL
, "tdb_hashsize", base
, 0);
2956 int lpcfg_tdb_flags(struct loadparm_context
*lp_ctx
, int tdb_flags
)
2958 if (!lpcfg_use_mmap(lp_ctx
)) {
2959 tdb_flags
|= TDB_NOMMAP
;