2 Unix SMB/CIFS implementation.
3 Parameter loading functions
4 Copyright (C) Karl Auer 1993-1998
6 Largely re-written by Andrew Tridgell, September 1994
8 Copyright (C) Simo Sorce 2001
9 Copyright (C) Alexander Bokovoy 2002
10 Copyright (C) Stefan (metze) Metzmacher 2002
11 Copyright (C) Jim McDonough (jmcd@us.ibm.com) 2003.
12 Copyright (C) James Myers 2003 <myersjj@samba.org>
13 Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2007
14 Copyright (C) Andrew Bartlett 2011-2012
16 This program is free software; you can redistribute it and/or modify
17 it under the terms of the GNU General Public License as published by
18 the Free Software Foundation; either version 3 of the License, or
19 (at your option) any later version.
21 This program is distributed in the hope that it will be useful,
22 but WITHOUT ANY WARRANTY; without even the implied warranty of
23 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 GNU General Public License for more details.
26 You should have received a copy of the GNU General Public License
27 along with this program. If not, see <http://www.gnu.org/licenses/>.
33 * This module provides suitable callback functions for the params
34 * module. It builds the internal table of service details which is
35 * then used by the rest of the server.
39 * 1) add it to the global or service structure definition
40 * 2) add it to the parm_table
41 * 3) add it to the list of available functions (eg: using FN_GLOBAL_STRING())
42 * 4) If it's a global then initialise it in init_globals. If a local
43 * (ie. service) parameter then initialise it in the sDefault structure
47 * The configuration file is processed sequentially for speed. It is NOT
48 * accessed randomly as happens in 'real' Windows. For this reason, there
49 * is a fair bit of sequence-dependent code here - ie., code which assumes
50 * that certain things happen before others. In particular, the code which
51 * happens at the boundary between sections is delicately poised, so be
58 #include "dynconfig/dynconfig.h"
59 #include "system/time.h"
60 #include "system/locale.h"
61 #include "system/network.h" /* needed for TCP_NODELAY */
62 #include "../lib/util/dlinklist.h"
63 #include "lib/param/param.h"
64 #include "lib/param/loadparm.h"
65 #include "auth/gensec/gensec.h"
66 #include "lib/param/s3_param.h"
67 #include "lib/util/bitmap.h"
68 #include "libcli/smb/smb_constants.h"
71 #define standard_sub_basic talloc_strdup
73 static bool do_parameter(const char *, const char *, void *);
74 static bool defaults_saved
= false;
76 #include "lib/param/param_global.h"
78 #define NUMPARAMETERS (sizeof(parm_table) / sizeof(struct parm_struct))
80 /* these are parameter handlers which are not needed in the
83 #define handle_netbios_aliases NULL
84 #define handle_printing NULL
85 #define handle_ldap_debug_level NULL
86 #define handle_idmap_backend NULL
87 #define handle_idmap_uid NULL
88 #define handle_idmap_gid NULL
94 #include "lib/param/param_table.c"
97 struct loadparm_context
{
98 const char *szConfigFile
;
99 struct loadparm_global
*globals
;
100 struct loadparm_service
**services
;
101 struct loadparm_service
*sDefault
;
102 struct smb_iconv_handle
*iconv_handle
;
104 struct loadparm_service
*currentService
;
105 bool bInGlobalSection
;
106 struct file_lists
*file_lists
;
107 unsigned int flags
[NUMPARAMETERS
];
110 bool global
; /* Is this the global context, which may set
111 * global variables such as debug level etc? */
112 const struct loadparm_s3_helpers
*s3_fns
;
116 struct loadparm_service
*lpcfg_default_service(struct loadparm_context
*lp_ctx
)
118 if (lp_ctx
->s3_fns
) {
119 return lp_ctx
->s3_fns
->get_default_loadparm_service();
121 return lp_ctx
->sDefault
;
125 * Convenience routine to grab string parameters into temporary memory
126 * and run standard_sub_basic on them.
128 * The buffers can be written to by
129 * callers without affecting the source string.
132 static const char *lpcfg_string(const char *s
)
134 #if 0 /* until REWRITE done to make thread-safe */
135 size_t len
= s
? strlen(s
) : 0;
139 /* The follow debug is useful for tracking down memory problems
140 especially if you have an inner loop that is calling a lp_*()
141 function that returns a string. Perhaps this debug should be
142 present all the time? */
145 DEBUG(10, ("lpcfg_string(%s)\n", s
));
148 #if 0 /* until REWRITE done to make thread-safe */
150 lp_talloc
= talloc_init("lp_talloc");
152 ret
= talloc_array(lp_talloc
, char, len
+ 100); /* leave room for substitution */
160 strlcpy(ret
, s
, len
);
162 if (trim_string(ret
, "\"", "\"")) {
163 if (strchr(ret
,'"') != NULL
)
164 strlcpy(ret
, s
, len
);
167 standard_sub_basic(ret
,len
+100);
174 In this section all the functions that are used to access the
175 parameters from the rest of the program are defined
179 * the creation of separate lpcfg_*() and lp_*() functions is to allow
180 * for code compatibility between existing Samba4 and Samba3 code.
183 /* this global context supports the lp_*() function varients */
184 static struct loadparm_context
*global_loadparm_context
;
186 #define lpcfg_default_service global_loadparm_context->sDefault
187 #define lpcfg_global_service(i) global_loadparm_context->services[i]
189 #define FN_GLOBAL_STRING(fn_name,var_name) \
190 _PUBLIC_ char *lpcfg_ ## fn_name(struct loadparm_context *lp_ctx, TALLOC_CTX *ctx) {\
191 if (lp_ctx == NULL) return NULL; \
192 if (lp_ctx->s3_fns) { \
193 return lp_ctx->globals->var_name ? lp_ctx->s3_fns->lp_string(ctx, lp_ctx->globals->var_name) : talloc_strdup(ctx, ""); \
195 return lp_ctx->globals->var_name ? talloc_strdup(ctx, lpcfg_string(lp_ctx->globals->var_name)) : talloc_strdup(ctx, ""); \
198 #define FN_GLOBAL_CONST_STRING(fn_name,var_name) \
199 _PUBLIC_ const char *lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) { \
200 if (lp_ctx == NULL) return NULL; \
201 return lp_ctx->globals->var_name ? lpcfg_string(lp_ctx->globals->var_name) : ""; \
204 #define FN_GLOBAL_LIST(fn_name,var_name) \
205 _PUBLIC_ const char **lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) { \
206 if (lp_ctx == NULL) return NULL; \
207 return lp_ctx->globals->var_name; \
210 #define FN_GLOBAL_BOOL(fn_name,var_name) \
211 _PUBLIC_ bool lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) {\
212 if (lp_ctx == NULL) return false; \
213 return lp_ctx->globals->var_name; \
216 #define FN_GLOBAL_INTEGER(fn_name,var_name) \
217 _PUBLIC_ int lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) { \
218 return lp_ctx->globals->var_name; \
221 /* Local parameters don't need the ->s3_fns because the struct
222 * loadparm_service is shared and lpcfg_service() checks the ->s3_fns
224 #define FN_LOCAL_STRING(fn_name,val) \
225 _PUBLIC_ char *lpcfg_ ## fn_name(struct loadparm_service *service, \
226 struct loadparm_service *sDefault, TALLOC_CTX *ctx) { \
227 return(talloc_strdup(ctx, lpcfg_string((const char *)((service != NULL && service->val != NULL) ? service->val : sDefault->val)))); \
230 #define FN_LOCAL_CONST_STRING(fn_name,val) \
231 _PUBLIC_ const char *lpcfg_ ## fn_name(struct loadparm_service *service, \
232 struct loadparm_service *sDefault) { \
233 return((const char *)((service != NULL && service->val != NULL) ? service->val : sDefault->val)); \
236 #define FN_LOCAL_LIST(fn_name,val) \
237 _PUBLIC_ const char **lpcfg_ ## fn_name(struct loadparm_service *service, \
238 struct loadparm_service *sDefault) {\
239 return(const char **)(service != NULL && service->val != NULL? service->val : sDefault->val); \
242 #define FN_LOCAL_PARM_BOOL(fn_name, val) FN_LOCAL_BOOL(fn_name, val)
244 #define FN_LOCAL_BOOL(fn_name,val) \
245 _PUBLIC_ bool lpcfg_ ## fn_name(struct loadparm_service *service, \
246 struct loadparm_service *sDefault) { \
247 return((service != NULL)? service->val : sDefault->val); \
250 #define FN_LOCAL_INTEGER(fn_name,val) \
251 _PUBLIC_ int lpcfg_ ## fn_name(struct loadparm_service *service, \
252 struct loadparm_service *sDefault) { \
253 return((service != NULL)? service->val : sDefault->val); \
256 #define FN_LOCAL_PARM_INTEGER(fn_name, val) FN_LOCAL_INTEGER(fn_name, val)
258 #define FN_LOCAL_PARM_CHAR(fn_name,val) \
259 _PUBLIC_ char lpcfg_ ## fn_name(struct loadparm_service *service, \
260 struct loadparm_service *sDefault) { \
261 return((service != NULL)? service->val : sDefault->val); \
264 #include "lib/param/param_functions.c"
266 /* These functions cannot be auto-generated */
267 FN_LOCAL_BOOL(autoloaded
, autoloaded
)
268 FN_GLOBAL_CONST_STRING(dnsdomain
, dnsdomain
)
270 /* local prototypes */
271 static struct loadparm_service
*lpcfg_getservicebyname(struct loadparm_context
*lp_ctx
,
272 const char *pszServiceName
);
273 static bool lpcfg_service_ok(struct loadparm_service
*service
);
274 static bool do_section(const char *pszSectionName
, void *);
276 /* This is a helper function for parametrical options support. */
277 /* It returns a pointer to parametrical option value if it exists or NULL otherwise */
278 /* Actual parametrical functions are quite simple */
279 const char *lpcfg_get_parametric(struct loadparm_context
*lp_ctx
,
280 struct loadparm_service
*service
,
281 const char *type
, const char *option
)
283 char *vfskey_tmp
= NULL
;
285 struct parmlist_entry
*data
;
290 if (lp_ctx
->s3_fns
) {
291 return lp_ctx
->s3_fns
->get_parametric(service
, type
, option
);
294 data
= (service
== NULL
? lp_ctx
->globals
->param_opt
: service
->param_opt
);
296 vfskey_tmp
= talloc_asprintf(NULL
, "%s:%s", type
, option
);
297 if (vfskey_tmp
== NULL
) return NULL
;
298 vfskey
= strlower_talloc(NULL
, vfskey_tmp
);
299 talloc_free(vfskey_tmp
);
302 if (strcmp(data
->key
, vfskey
) == 0) {
309 if (service
!= NULL
) {
310 /* Try to fetch the same option but from globals */
311 /* but only if we are not already working with globals */
312 for (data
= lp_ctx
->globals
->param_opt
; data
;
314 if (strcmp(data
->key
, vfskey
) == 0) {
328 * convenience routine to return int parameters.
330 static int lp_int(const char *s
)
334 DEBUG(0,("lp_int(%s): is called with NULL!\n",s
));
338 return strtol(s
, NULL
, 0);
342 * convenience routine to return unsigned long parameters.
344 static unsigned long lp_ulong(const char *s
)
348 DEBUG(0,("lp_ulong(%s): is called with NULL!\n",s
));
352 return strtoul(s
, NULL
, 0);
356 * convenience routine to return unsigned long parameters.
358 static long lp_long(const char *s
)
362 DEBUG(0,("lp_long(%s): is called with NULL!\n",s
));
366 return strtol(s
, NULL
, 0);
370 * convenience routine to return unsigned long parameters.
372 static double lp_double(const char *s
)
376 DEBUG(0,("lp_double(%s): is called with NULL!\n",s
));
380 return strtod(s
, NULL
);
384 * convenience routine to return boolean parameters.
386 static bool lp_bool(const char *s
)
391 DEBUG(0,("lp_bool(%s): is called with NULL!\n",s
));
395 if (!set_boolean(s
, &ret
)) {
396 DEBUG(0,("lp_bool(%s): value is not boolean!\n",s
));
405 * Return parametric option from a given service. Type is a part of option before ':'
406 * Parametric option has following syntax: 'Type: option = value'
407 * Returned value is allocated in 'lp_talloc' context
410 const char *lpcfg_parm_string(struct loadparm_context
*lp_ctx
,
411 struct loadparm_service
*service
, const char *type
,
414 const char *value
= lpcfg_get_parametric(lp_ctx
, service
, type
, option
);
417 return lpcfg_string(value
);
423 * Return parametric option from a given service. Type is a part of option before ':'
424 * Parametric option has following syntax: 'Type: option = value'
425 * Returned value is allocated in 'lp_talloc' context
428 const char **lpcfg_parm_string_list(TALLOC_CTX
*mem_ctx
,
429 struct loadparm_context
*lp_ctx
,
430 struct loadparm_service
*service
,
432 const char *option
, const char *separator
)
434 const char *value
= lpcfg_get_parametric(lp_ctx
, service
, type
, option
);
437 return (const char **)str_list_make(mem_ctx
, value
, separator
);
443 * Return parametric option from a given service. Type is a part of option before ':'
444 * Parametric option has following syntax: 'Type: option = value'
447 int lpcfg_parm_int(struct loadparm_context
*lp_ctx
,
448 struct loadparm_service
*service
, const char *type
,
449 const char *option
, int default_v
)
451 const char *value
= lpcfg_get_parametric(lp_ctx
, service
, type
, option
);
454 return lp_int(value
);
460 * Return parametric option from a given service. Type is a part of
462 * Parametric option has following syntax: 'Type: option = value'.
465 int lpcfg_parm_bytes(struct loadparm_context
*lp_ctx
,
466 struct loadparm_service
*service
, const char *type
,
467 const char *option
, int default_v
)
471 const char *value
= lpcfg_get_parametric(lp_ctx
, service
, type
, option
);
473 if (value
&& conv_str_size_error(value
, &bval
)) {
474 if (bval
<= INT_MAX
) {
483 * Return parametric option from a given service.
484 * Type is a part of option before ':'
485 * Parametric option has following syntax: 'Type: option = value'
487 unsigned long lpcfg_parm_ulong(struct loadparm_context
*lp_ctx
,
488 struct loadparm_service
*service
, const char *type
,
489 const char *option
, unsigned long default_v
)
491 const char *value
= lpcfg_get_parametric(lp_ctx
, service
, type
, option
);
494 return lp_ulong(value
);
499 long lpcfg_parm_long(struct loadparm_context
*lp_ctx
,
500 struct loadparm_service
*service
, const char *type
,
501 const char *option
, long default_v
)
503 const char *value
= lpcfg_get_parametric(lp_ctx
, service
, type
, option
);
506 return lp_long(value
);
511 double lpcfg_parm_double(struct loadparm_context
*lp_ctx
,
512 struct loadparm_service
*service
, const char *type
,
513 const char *option
, double default_v
)
515 const char *value
= lpcfg_get_parametric(lp_ctx
, service
, type
, option
);
518 return lp_double(value
);
524 * Return parametric option from a given service. Type is a part of option before ':'
525 * Parametric option has following syntax: 'Type: option = value'
528 bool lpcfg_parm_bool(struct loadparm_context
*lp_ctx
,
529 struct loadparm_service
*service
, const char *type
,
530 const char *option
, bool default_v
)
532 const char *value
= lpcfg_get_parametric(lp_ctx
, service
, type
, option
);
535 return lp_bool(value
);
542 * Set a string value, deallocating any existing space, and allocing the space
545 static bool lpcfg_string_set(TALLOC_CTX
*mem_ctx
, char **dest
, const char *src
)
552 *dest
= talloc_strdup(mem_ctx
, src
);
553 if ((*dest
) == NULL
) {
554 DEBUG(0,("Out of memory in string_set\n"));
562 * Set a string value, deallocating any existing space, and allocing the space
565 static bool lpcfg_string_set_upper(TALLOC_CTX
*mem_ctx
, char **dest
, const char *src
)
572 *dest
= strupper_talloc(mem_ctx
, src
);
573 if ((*dest
) == NULL
) {
574 DEBUG(0,("Out of memory in string_set_upper\n"));
584 * Add a new service to the services array initialising it with the given
588 struct loadparm_service
*lpcfg_add_service(struct loadparm_context
*lp_ctx
,
589 const struct loadparm_service
*pservice
,
593 int num_to_alloc
= lp_ctx
->iNumServices
+ 1;
594 struct parmlist_entry
*data
, *pdata
;
596 if (pservice
== NULL
) {
597 pservice
= lp_ctx
->sDefault
;
600 /* it might already exist */
602 struct loadparm_service
*service
= lpcfg_getservicebyname(lp_ctx
,
604 if (service
!= NULL
) {
605 /* Clean all parametric options for service */
606 /* They will be added during parsing again */
607 data
= service
->param_opt
;
613 service
->param_opt
= NULL
;
618 /* find an invalid one */
619 for (i
= 0; i
< lp_ctx
->iNumServices
; i
++)
620 if (lp_ctx
->services
[i
] == NULL
)
623 /* if not, then create one */
624 if (i
== lp_ctx
->iNumServices
) {
625 struct loadparm_service
**tsp
;
627 tsp
= talloc_realloc(lp_ctx
, lp_ctx
->services
, struct loadparm_service
*, num_to_alloc
);
630 DEBUG(0,("lpcfg_add_service: failed to enlarge services!\n"));
633 lp_ctx
->services
= tsp
;
634 lp_ctx
->services
[lp_ctx
->iNumServices
] = NULL
;
637 lp_ctx
->iNumServices
++;
640 lp_ctx
->services
[i
] = talloc_zero(lp_ctx
->services
, struct loadparm_service
);
641 if (lp_ctx
->services
[i
] == NULL
) {
642 DEBUG(0,("lpcfg_add_service: out of memory!\n"));
645 copy_service(lp_ctx
->services
[i
], pservice
, NULL
);
647 lpcfg_string_set(lp_ctx
->services
[i
], &lp_ctx
->services
[i
]->szService
, name
);
648 return lp_ctx
->services
[i
];
652 * Add a new home service, with the specified home directory, defaults coming
653 * from service ifrom.
656 bool lpcfg_add_home(struct loadparm_context
*lp_ctx
,
657 const char *pszHomename
,
658 struct loadparm_service
*default_service
,
659 const char *user
, const char *pszHomedir
)
661 struct loadparm_service
*service
;
663 service
= lpcfg_add_service(lp_ctx
, default_service
, pszHomename
);
668 if (!(*(default_service
->path
))
669 || strequal(default_service
->path
, lp_ctx
->sDefault
->path
)) {
670 service
->path
= talloc_strdup(service
, pszHomedir
);
672 service
->path
= string_sub_talloc(service
, lpcfg_path(default_service
, lp_ctx
->sDefault
, service
), "%H", pszHomedir
);
675 if (!(*(service
->comment
))) {
676 service
->comment
= talloc_asprintf(service
, "Home directory of %s", user
);
678 service
->bAvailable
= default_service
->bAvailable
;
679 service
->browseable
= default_service
->browseable
;
681 DEBUG(3, ("adding home's share [%s] for user '%s' at '%s'\n",
682 pszHomename
, user
, service
->path
));
688 * Add a new printer service, with defaults coming from service iFrom.
691 bool lpcfg_add_printer(struct loadparm_context
*lp_ctx
,
692 const char *pszPrintername
,
693 struct loadparm_service
*default_service
)
695 const char *comment
= "From Printcap";
696 struct loadparm_service
*service
;
697 service
= lpcfg_add_service(lp_ctx
, default_service
, pszPrintername
);
702 /* note that we do NOT default the availability flag to True - */
703 /* we take it from the default service passed. This allows all */
704 /* dynamic printers to be disabled by disabling the [printers] */
705 /* entry (if/when the 'available' keyword is implemented!). */
707 /* the printer name is set to the service name. */
708 lpcfg_string_set(service
, &service
->_printername
, pszPrintername
);
709 lpcfg_string_set(service
, &service
->comment
, comment
);
710 service
->browseable
= default_service
->browseable
;
711 /* Printers cannot be read_only. */
712 service
->read_only
= false;
713 /* Printer services must be printable. */
714 service
->printable
= true;
716 DEBUG(3, ("adding printer service %s\n", pszPrintername
));
722 * Map a parameter's string representation to something we can use.
723 * Returns False if the parameter string is not recognised, else TRUE.
726 int lpcfg_map_parameter(const char *pszParmName
)
730 for (iIndex
= 0; parm_table
[iIndex
].label
; iIndex
++)
731 if (strwicmp(parm_table
[iIndex
].label
, pszParmName
) == 0)
734 /* Warn only if it isn't parametric option */
735 if (strchr(pszParmName
, ':') == NULL
)
736 DEBUG(0, ("Unknown parameter encountered: \"%s\"\n", pszParmName
));
737 /* We do return 'fail' for parametric options as well because they are
738 stored in different storage
745 return the parameter structure for a parameter
747 struct parm_struct
*lpcfg_parm_struct(struct loadparm_context
*lp_ctx
, const char *name
)
751 if (lp_ctx
->s3_fns
) {
752 return lp_ctx
->s3_fns
->get_parm_struct(name
);
755 parmnum
= lpcfg_map_parameter(name
);
756 if (parmnum
== -1) return NULL
;
757 return &parm_table
[parmnum
];
761 return the parameter pointer for a parameter
763 void *lpcfg_parm_ptr(struct loadparm_context
*lp_ctx
,
764 struct loadparm_service
*service
, struct parm_struct
*parm
)
766 if (lp_ctx
->s3_fns
) {
767 return lp_ctx
->s3_fns
->get_parm_ptr(service
, parm
);
770 if (service
== NULL
) {
771 if (parm
->p_class
== P_LOCAL
)
772 return ((char *)lp_ctx
->sDefault
)+parm
->offset
;
773 else if (parm
->p_class
== P_GLOBAL
)
774 return ((char *)lp_ctx
->globals
)+parm
->offset
;
777 return ((char *)service
) + parm
->offset
;
782 return the parameter pointer for a parameter
784 bool lpcfg_parm_is_cmdline(struct loadparm_context
*lp_ctx
, const char *name
)
788 if (lp_ctx
->s3_fns
) {
789 struct parm_struct
*parm
= lp_ctx
->s3_fns
->get_parm_struct(name
);
791 return parm
->flags
& FLAG_CMDLINE
;
796 parmnum
= lpcfg_map_parameter(name
);
797 if (parmnum
== -1) return false;
799 return lp_ctx
->flags
[parmnum
] & FLAG_CMDLINE
;
803 * Find a service by name. Otherwise works like get_service.
806 static struct loadparm_service
*lpcfg_getservicebyname(struct loadparm_context
*lp_ctx
,
807 const char *pszServiceName
)
811 if (lp_ctx
->s3_fns
) {
812 return lp_ctx
->s3_fns
->get_service(pszServiceName
);
815 for (iService
= lp_ctx
->iNumServices
- 1; iService
>= 0; iService
--)
816 if (lp_ctx
->services
[iService
] != NULL
&&
817 strwicmp(lp_ctx
->services
[iService
]->szService
, pszServiceName
) == 0) {
818 return lp_ctx
->services
[iService
];
825 * Add a parametric option to a parmlist_entry,
826 * replacing old value, if already present.
828 void set_param_opt(TALLOC_CTX
*mem_ctx
,
829 struct parmlist_entry
**opt_list
,
830 const char *opt_name
,
831 const char *opt_value
,
834 struct parmlist_entry
*new_opt
, *opt
;
840 /* Traverse destination */
842 /* If we already have same option, override it */
843 if (strwicmp(opt
->key
, opt_name
) == 0) {
844 if ((opt
->priority
& FLAG_CMDLINE
) &&
845 !(priority
& FLAG_CMDLINE
)) {
846 /* it's been marked as not to be
850 TALLOC_FREE(opt
->value
);
851 TALLOC_FREE(opt
->list
);
852 opt
->value
= talloc_strdup(opt
, opt_value
);
853 opt
->priority
= priority
;
860 new_opt
= talloc(mem_ctx
, struct parmlist_entry
);
861 if (new_opt
== NULL
) {
865 new_opt
->key
= talloc_strdup(new_opt
, opt_name
);
866 if (new_opt
->key
== NULL
) {
867 smb_panic("talloc_strdup failed");
870 new_opt
->value
= talloc_strdup(new_opt
, opt_value
);
871 if (new_opt
->value
== NULL
) {
872 smb_panic("talloc_strdup failed");
875 new_opt
->list
= NULL
;
876 new_opt
->priority
= priority
;
877 DLIST_ADD(*opt_list
, new_opt
);
882 * Copy a service structure to another.
883 * If pcopymapDest is NULL then copy all fields
886 void copy_service(struct loadparm_service
*pserviceDest
,
887 const struct loadparm_service
*pserviceSource
,
888 struct bitmap
*pcopymapDest
)
891 bool bcopyall
= (pcopymapDest
== NULL
);
892 struct parmlist_entry
*data
;
894 for (i
= 0; parm_table
[i
].label
; i
++)
895 if (parm_table
[i
].p_class
== P_LOCAL
&&
896 (bcopyall
|| bitmap_query(pcopymapDest
, i
))) {
897 const void *src_ptr
=
898 ((const char *)pserviceSource
) + parm_table
[i
].offset
;
900 ((char *)pserviceDest
) + parm_table
[i
].offset
;
902 switch (parm_table
[i
].type
) {
905 *(bool *)dest_ptr
= *(const bool *)src_ptr
;
912 *(int *)dest_ptr
= *(const int *)src_ptr
;
916 *(char *)dest_ptr
= *(const char *)src_ptr
;
920 lpcfg_string_set(pserviceDest
,
922 *(const char * const *)src_ptr
);
926 lpcfg_string_set_upper(pserviceDest
,
928 *(const char * const *)src_ptr
);
931 TALLOC_FREE(*((char ***)dest_ptr
));
932 *(const char * const **)dest_ptr
= (const char * const *)str_list_copy(pserviceDest
,
933 *(const char * * const *)src_ptr
);
941 init_copymap(pserviceDest
);
942 if (pserviceSource
->copymap
)
943 bitmap_copy(pserviceDest
->copymap
,
944 pserviceSource
->copymap
);
947 for (data
= pserviceSource
->param_opt
; data
!= NULL
; data
= data
->next
) {
948 set_param_opt(pserviceDest
, &pserviceDest
->param_opt
,
949 data
->key
, data
->value
, data
->priority
);
954 * Check a service for consistency. Return False if the service is in any way
955 * incomplete or faulty, else True.
957 static bool lpcfg_service_ok(struct loadparm_service
*service
)
962 if (service
->szService
[0] == '\0') {
963 DEBUG(0, ("The following message indicates an internal error:\n"));
964 DEBUG(0, ("No service name in service entry.\n"));
968 /* The [printers] entry MUST be printable. I'm all for flexibility, but */
969 /* I can't see why you'd want a non-printable printer service... */
970 if (strwicmp(service
->szService
, PRINTERS_NAME
) == 0) {
971 if (!service
->printable
) {
972 DEBUG(0, ("WARNING: [%s] service MUST be printable!\n",
973 service
->szService
));
974 service
->printable
= true;
976 /* [printers] service must also be non-browsable. */
977 if (service
->browseable
)
978 service
->browseable
= false;
981 /* If a service is flagged unavailable, log the fact at level 0. */
982 if (!service
->bAvailable
)
983 DEBUG(1, ("NOTE: Service %s is flagged unavailable.\n",
984 service
->szService
));
990 /*******************************************************************
991 Keep a linked list of all config files so we know when one has changed
992 it's date and needs to be reloaded.
993 ********************************************************************/
995 void add_to_file_list(TALLOC_CTX
*mem_ctx
, struct file_lists
**list
,
996 const char *fname
, const char *subfname
)
998 struct file_lists
*f
= *list
;
1001 if (f
->name
&& !strcmp(f
->name
, fname
))
1007 f
= talloc(mem_ctx
, struct file_lists
);
1011 f
->name
= talloc_strdup(f
, fname
);
1016 f
->subfname
= talloc_strdup(f
, subfname
);
1022 f
->modtime
= file_modtime(subfname
);
1024 time_t t
= file_modtime(subfname
);
1031 DEBUG(0, ("Unable to add file to file list: %s\n", fname
));
1035 /*******************************************************************
1036 Check if a config file has changed date.
1037 ********************************************************************/
1038 bool lpcfg_file_list_changed(struct loadparm_context
*lp_ctx
)
1040 struct file_lists
*f
;
1041 DEBUG(6, ("lpcfg_file_list_changed()\n"));
1043 for (f
= lp_ctx
->file_lists
; f
!= NULL
; f
= f
->next
) {
1047 n2
= standard_sub_basic(lp_ctx
, f
->name
);
1049 DEBUGADD(6, ("file %s -> %s last mod_time: %s\n",
1050 f
->name
, n2
, ctime(&f
->modtime
)));
1052 mod_time
= file_modtime(n2
);
1054 if (mod_time
&& ((f
->modtime
!= mod_time
) || (f
->subfname
== NULL
) || (strcmp(n2
, f
->subfname
) != 0))) {
1055 DEBUGADD(6, ("file %s modified: %s\n", n2
,
1057 f
->modtime
= mod_time
;
1058 talloc_free(f
->subfname
);
1059 f
->subfname
= talloc_strdup(f
, n2
);
1066 /***************************************************************************
1067 Handle the "realm" parameter
1068 ***************************************************************************/
1070 bool handle_realm(struct loadparm_context
*lp_ctx
, int unused
,
1071 const char *pszParmValue
, char **ptr
)
1076 upper
= strupper_talloc(lp_ctx
, pszParmValue
);
1077 if (upper
== NULL
) {
1081 lower
= strlower_talloc(lp_ctx
, pszParmValue
);
1082 if (lower
== NULL
) {
1087 if (lp_ctx
->s3_fns
!= NULL
) {
1088 lp_ctx
->s3_fns
->lp_string_set(ptr
, pszParmValue
);
1089 lp_ctx
->s3_fns
->lp_string_set(&lp_ctx
->globals
->realm
, upper
);
1090 lp_ctx
->s3_fns
->lp_string_set(&lp_ctx
->globals
->dnsdomain
, lower
);
1092 lpcfg_string_set(lp_ctx
, ptr
, pszParmValue
);
1093 lpcfg_string_set(lp_ctx
, &lp_ctx
->globals
->realm
, upper
);
1094 lpcfg_string_set(lp_ctx
, &lp_ctx
->globals
->dnsdomain
, lower
);
1100 /***************************************************************************
1101 Handle the include operation.
1102 ***************************************************************************/
1104 bool handle_include(struct loadparm_context
*lp_ctx
, int unused
,
1105 const char *pszParmValue
, char **ptr
)
1109 if (lp_ctx
->s3_fns
) {
1110 return lp_ctx
->s3_fns
->lp_include(lp_ctx
, unused
, pszParmValue
, ptr
);
1113 fname
= standard_sub_basic(lp_ctx
, pszParmValue
);
1115 add_to_file_list(lp_ctx
, &lp_ctx
->file_lists
, pszParmValue
, fname
);
1117 lpcfg_string_set(lp_ctx
, ptr
, fname
);
1119 if (file_exist(fname
))
1120 return pm_process(fname
, do_section
, do_parameter
, lp_ctx
);
1122 DEBUG(2, ("Can't find include file %s\n", fname
));
1127 /***************************************************************************
1128 Handle the interpretation of the copy parameter.
1129 ***************************************************************************/
1131 bool handle_copy(struct loadparm_context
*lp_ctx
, int snum
,
1132 const char *pszParmValue
, char **ptr
)
1135 struct loadparm_service
*serviceTemp
= NULL
;
1136 struct loadparm_service
*current
= NULL
;
1140 DEBUG(3, ("Copying service from service %s\n", pszParmValue
));
1142 serviceTemp
= lpcfg_getservicebyname(lp_ctx
, pszParmValue
);
1143 if (lp_ctx
->s3_fns
!= NULL
) {
1144 current
= lp_ctx
->s3_fns
->get_servicebynum(snum
);
1146 current
= lp_ctx
->currentService
;
1149 if (current
== NULL
) {
1150 DEBUG(0, ("Unable to copy service - invalid service destination"));
1154 if (serviceTemp
!= NULL
) {
1155 if (serviceTemp
== current
) {
1156 DEBUG(0, ("Can't copy service %s - unable to copy self!\n", pszParmValue
));
1158 copy_service(current
,
1161 lpcfg_string_set(current
, ptr
, pszParmValue
);
1166 DEBUG(0, ("Unable to copy service - source not found: %s\n",
1174 bool handle_debug_list(struct loadparm_context
*lp_ctx
, int unused
,
1175 const char *pszParmValue
, char **ptr
)
1177 if (lp_ctx
->s3_fns
!= NULL
) {
1178 lp_ctx
->s3_fns
->lp_string_set(ptr
, pszParmValue
);
1180 lpcfg_string_set(lp_ctx
, ptr
, pszParmValue
);
1183 return debug_parse_levels(pszParmValue
);
1186 bool handle_logfile(struct loadparm_context
*lp_ctx
, int unused
,
1187 const char *pszParmValue
, char **ptr
)
1189 if (lp_ctx
->s3_fns
!= NULL
) {
1190 lp_ctx
->s3_fns
->lp_string_set(ptr
, pszParmValue
);
1192 debug_set_logfile(pszParmValue
);
1193 lpcfg_string_set(lp_ctx
, ptr
, pszParmValue
);
1200 * These special charset handling methods only run in the source3 code.
1203 bool handle_charset(struct loadparm_context
*lp_ctx
, int snum
,
1204 const char *pszParmValue
, char **ptr
)
1206 if (lp_ctx
->s3_fns
) {
1207 if (*ptr
== NULL
|| strcmp(*ptr
, pszParmValue
) != 0) {
1208 lp_ctx
->s3_fns
->lp_string_set(ptr
, pszParmValue
);
1209 global_iconv_handle
= smb_iconv_handle_reinit(NULL
,
1210 lpcfg_dos_charset(lp_ctx
),
1211 lpcfg_unix_charset(lp_ctx
),
1212 true, global_iconv_handle
);
1217 return lpcfg_string_set(lp_ctx
, ptr
, pszParmValue
);
1221 bool handle_dos_charset(struct loadparm_context
*lp_ctx
, int snum
,
1222 const char *pszParmValue
, char **ptr
)
1224 bool is_utf8
= false;
1225 size_t len
= strlen(pszParmValue
);
1227 if (lp_ctx
->s3_fns
) {
1228 if (len
== 4 || len
== 5) {
1229 /* Don't use StrCaseCmp here as we don't want to
1230 initialize iconv. */
1231 if ((toupper_m(pszParmValue
[0]) == 'U') &&
1232 (toupper_m(pszParmValue
[1]) == 'T') &&
1233 (toupper_m(pszParmValue
[2]) == 'F')) {
1235 if (pszParmValue
[3] == '8') {
1239 if (pszParmValue
[3] == '-' &&
1240 pszParmValue
[4] == '8') {
1247 if (*ptr
== NULL
|| strcmp(*ptr
, pszParmValue
) != 0) {
1249 DEBUG(0,("ERROR: invalid DOS charset: 'dos charset' must not "
1250 "be UTF8, using (default value) %s instead.\n",
1251 DEFAULT_DOS_CHARSET
));
1252 pszParmValue
= DEFAULT_DOS_CHARSET
;
1254 lp_ctx
->s3_fns
->lp_string_set(ptr
, pszParmValue
);
1255 global_iconv_handle
= smb_iconv_handle_reinit(NULL
,
1256 lpcfg_dos_charset(lp_ctx
),
1257 lpcfg_unix_charset(lp_ctx
),
1258 true, global_iconv_handle
);
1263 return lpcfg_string_set(lp_ctx
, ptr
, pszParmValue
);
1266 /***************************************************************************
1267 Initialise a copymap.
1268 ***************************************************************************/
1270 void init_copymap(struct loadparm_service
*pservice
)
1274 TALLOC_FREE(pservice
->copymap
);
1276 pservice
->copymap
= bitmap_talloc(NULL
, NUMPARAMETERS
);
1277 if (!pservice
->copymap
)
1279 ("Couldn't allocate copymap!! (size %d)\n",
1280 (int)NUMPARAMETERS
));
1282 for (i
= 0; i
< NUMPARAMETERS
; i
++)
1283 bitmap_set(pservice
->copymap
, i
);
1287 * Process a parametric option
1289 static bool lp_do_parameter_parametric(struct loadparm_context
*lp_ctx
,
1290 struct loadparm_service
*service
,
1291 const char *pszParmName
,
1292 const char *pszParmValue
, int flags
)
1294 struct parmlist_entry
*paramo
, *data
;
1296 TALLOC_CTX
*mem_ctx
;
1298 while (isspace((unsigned char)*pszParmName
)) {
1302 name
= strlower_talloc(lp_ctx
, pszParmName
);
1303 if (!name
) return false;
1305 if (service
== NULL
) {
1306 data
= lp_ctx
->globals
->param_opt
;
1307 mem_ctx
= lp_ctx
->globals
;
1309 data
= service
->param_opt
;
1313 /* Traverse destination */
1314 for (paramo
=data
; paramo
; paramo
=paramo
->next
) {
1315 /* If we already have the option set, override it unless
1316 it was a command line option and the new one isn't */
1317 if (strcmp(paramo
->key
, name
) == 0) {
1318 if ((paramo
->priority
& FLAG_CMDLINE
) &&
1319 !(flags
& FLAG_CMDLINE
)) {
1324 talloc_free(paramo
->value
);
1325 paramo
->value
= talloc_strdup(paramo
, pszParmValue
);
1326 paramo
->priority
= flags
;
1332 paramo
= talloc_zero(mem_ctx
, struct parmlist_entry
);
1335 paramo
->key
= talloc_strdup(paramo
, name
);
1336 paramo
->value
= talloc_strdup(paramo
, pszParmValue
);
1337 paramo
->priority
= flags
;
1338 if (service
== NULL
) {
1339 DLIST_ADD(lp_ctx
->globals
->param_opt
, paramo
);
1341 DLIST_ADD(service
->param_opt
, paramo
);
1349 static bool set_variable(TALLOC_CTX
*mem_ctx
, int parmnum
, void *parm_ptr
,
1350 const char *pszParmName
, const char *pszParmValue
,
1351 struct loadparm_context
*lp_ctx
, bool on_globals
)
1354 /* if it is a special case then go ahead */
1355 if (parm_table
[parmnum
].special
) {
1357 ret
= parm_table
[parmnum
].special(lp_ctx
, -1, pszParmValue
,
1362 goto mark_non_default
;
1365 /* now switch on the type of variable it is */
1366 switch (parm_table
[parmnum
].type
)
1370 if (!set_boolean(pszParmValue
, &b
)) {
1371 DEBUG(0, ("set_variable(%s): value is not "
1372 "boolean!\n", pszParmValue
));
1375 *(bool *)parm_ptr
= b
;
1381 if (!set_boolean(pszParmValue
, &b
)) {
1382 DEBUG(0, ("set_variable(%s): value is not "
1383 "boolean!\n", pszParmValue
));
1386 *(bool *)parm_ptr
= !b
;
1391 *(int *)parm_ptr
= atoi(pszParmValue
);
1395 *(char *)parm_ptr
= *pszParmValue
;
1399 *(int *)parm_ptr
= strtol(pszParmValue
, NULL
, 8);
1405 if (conv_str_size_error(pszParmValue
, &val
)) {
1406 if (val
<= INT_MAX
) {
1407 *(int *)parm_ptr
= (int)val
;
1412 DEBUG(0, ("set_variable(%s): value is not "
1413 "a valid size specifier!\n", pszParmValue
));
1418 *(const char * const **)parm_ptr
1419 = (const char * const *)str_list_make(mem_ctx
,
1420 pszParmValue
, NULL
);
1424 char **new_list
= str_list_make(mem_ctx
,
1425 pszParmValue
, NULL
);
1426 for (i
=0; new_list
[i
]; i
++) {
1427 if (*(const char ***)parm_ptr
!= NULL
&&
1428 new_list
[i
][0] == '+' &&
1431 if (!str_list_check(*(const char ***)parm_ptr
,
1433 *(const char ***)parm_ptr
= str_list_add(*(const char ***)parm_ptr
,
1436 } else if (*(const char ***)parm_ptr
!= NULL
&&
1437 new_list
[i
][0] == '-' &&
1440 str_list_remove(*(const char ***)parm_ptr
,
1444 DEBUG(0, ("Unsupported list syntax for: %s = %s\n",
1445 pszParmName
, pszParmValue
));
1448 *(const char * const **)parm_ptr
= (const char * const *) new_list
;
1455 lpcfg_string_set(mem_ctx
, (char **)parm_ptr
, pszParmValue
);
1459 lpcfg_string_set_upper(mem_ctx
, (char **)parm_ptr
, pszParmValue
);
1463 for (i
= 0; parm_table
[parmnum
].enum_list
[i
].name
; i
++) {
1466 parm_table
[parmnum
].enum_list
[i
].name
)) {
1468 parm_table
[parmnum
].
1473 if (!parm_table
[parmnum
].enum_list
[i
].name
) {
1474 DEBUG(0,("Unknown enumerated value '%s' for '%s'\n",
1475 pszParmValue
, pszParmName
));
1485 if (on_globals
&& (lp_ctx
->flags
[parmnum
] & FLAG_DEFAULT
)) {
1486 lp_ctx
->flags
[parmnum
] &= ~FLAG_DEFAULT
;
1487 /* we have to also unset FLAG_DEFAULT on aliases */
1488 for (i
=parmnum
-1;i
>=0 && parm_table
[i
].offset
== parm_table
[parmnum
].offset
;i
--) {
1489 lp_ctx
->flags
[i
] &= ~FLAG_DEFAULT
;
1491 for (i
=parmnum
+1;i
<NUMPARAMETERS
&& parm_table
[i
].offset
== parm_table
[parmnum
].offset
;i
++) {
1492 lp_ctx
->flags
[i
] &= ~FLAG_DEFAULT
;
1499 bool lpcfg_do_global_parameter(struct loadparm_context
*lp_ctx
,
1500 const char *pszParmName
, const char *pszParmValue
)
1502 int parmnum
= lpcfg_map_parameter(pszParmName
);
1506 if (strchr(pszParmName
, ':')) {
1507 return lp_do_parameter_parametric(lp_ctx
, NULL
, pszParmName
, pszParmValue
, 0);
1509 DEBUG(0, ("Ignoring unknown parameter \"%s\"\n", pszParmName
));
1513 /* if the flag has been set on the command line, then don't allow override,
1514 but don't report an error */
1515 if (lp_ctx
->flags
[parmnum
] & FLAG_CMDLINE
) {
1519 parm_ptr
= lpcfg_parm_ptr(lp_ctx
, NULL
, &parm_table
[parmnum
]);
1521 return set_variable(lp_ctx
->globals
, parmnum
, parm_ptr
,
1522 pszParmName
, pszParmValue
, lp_ctx
, true);
1525 bool lpcfg_do_service_parameter(struct loadparm_context
*lp_ctx
,
1526 struct loadparm_service
*service
,
1527 const char *pszParmName
, const char *pszParmValue
)
1531 int parmnum
= lpcfg_map_parameter(pszParmName
);
1534 if (strchr(pszParmName
, ':')) {
1535 return lp_do_parameter_parametric(lp_ctx
, service
, pszParmName
, pszParmValue
, 0);
1537 DEBUG(0, ("Ignoring unknown parameter \"%s\"\n", pszParmName
));
1541 /* if the flag has been set on the command line, then don't allow override,
1542 but don't report an error */
1543 if (lp_ctx
->flags
[parmnum
] & FLAG_CMDLINE
) {
1547 if (parm_table
[parmnum
].p_class
== P_GLOBAL
) {
1549 ("Global parameter %s found in service section!\n",
1553 parm_ptr
= ((char *)service
) + parm_table
[parmnum
].offset
;
1555 if (!service
->copymap
)
1556 init_copymap(service
);
1558 /* this handles the aliases - set the copymap for other
1559 * entries with the same data pointer */
1560 for (i
= 0; parm_table
[i
].label
; i
++)
1561 if (parm_table
[i
].offset
== parm_table
[parmnum
].offset
&&
1562 parm_table
[i
].p_class
== parm_table
[parmnum
].p_class
)
1563 bitmap_clear(service
->copymap
, i
);
1565 return set_variable(service
, parmnum
, parm_ptr
, pszParmName
,
1566 pszParmValue
, lp_ctx
, false);
1570 * Process a parameter.
1573 static bool do_parameter(const char *pszParmName
, const char *pszParmValue
,
1576 struct loadparm_context
*lp_ctx
= (struct loadparm_context
*)userdata
;
1578 if (lp_ctx
->bInGlobalSection
)
1579 return lpcfg_do_global_parameter(lp_ctx
, pszParmName
,
1582 return lpcfg_do_service_parameter(lp_ctx
, lp_ctx
->currentService
,
1583 pszParmName
, pszParmValue
);
1587 variable argument do parameter
1589 bool lpcfg_do_global_parameter_var(struct loadparm_context
*lp_ctx
, const char *pszParmName
, const char *fmt
, ...) PRINTF_ATTRIBUTE(3, 4);
1590 bool lpcfg_do_global_parameter_var(struct loadparm_context
*lp_ctx
,
1591 const char *pszParmName
, const char *fmt
, ...)
1598 s
= talloc_vasprintf(NULL
, fmt
, ap
);
1600 ret
= lpcfg_do_global_parameter(lp_ctx
, pszParmName
, s
);
1607 set a parameter from the commandline - this is called from command line parameter
1608 parsing code. It sets the parameter then marks the parameter as unable to be modified
1609 by smb.conf processing
1611 bool lpcfg_set_cmdline(struct loadparm_context
*lp_ctx
, const char *pszParmName
,
1612 const char *pszParmValue
)
1617 while (isspace((unsigned char)*pszParmValue
)) pszParmValue
++;
1619 if (lp_ctx
->s3_fns
) {
1620 return lp_ctx
->s3_fns
->set_cmdline(pszParmName
, pszParmValue
);
1623 parmnum
= lpcfg_map_parameter(pszParmName
);
1625 if (parmnum
< 0 && strchr(pszParmName
, ':')) {
1626 /* set a parametric option */
1627 return lp_do_parameter_parametric(lp_ctx
, NULL
, pszParmName
,
1628 pszParmValue
, FLAG_CMDLINE
);
1632 DEBUG(0,("Unknown option '%s'\n", pszParmName
));
1636 /* reset the CMDLINE flag in case this has been called before */
1637 lp_ctx
->flags
[parmnum
] &= ~FLAG_CMDLINE
;
1639 if (!lpcfg_do_global_parameter(lp_ctx
, pszParmName
, pszParmValue
)) {
1643 lp_ctx
->flags
[parmnum
] |= FLAG_CMDLINE
;
1645 /* we have to also set FLAG_CMDLINE on aliases */
1647 i
>=0 && parm_table
[i
].p_class
== parm_table
[parmnum
].p_class
&&
1648 parm_table
[i
].offset
== parm_table
[parmnum
].offset
;
1650 lp_ctx
->flags
[i
] |= FLAG_CMDLINE
;
1654 parm_table
[i
].p_class
== parm_table
[parmnum
].p_class
&&
1655 parm_table
[i
].offset
== parm_table
[parmnum
].offset
;
1657 lp_ctx
->flags
[i
] |= FLAG_CMDLINE
;
1664 set a option from the commandline in 'a=b' format. Use to support --option
1666 bool lpcfg_set_option(struct loadparm_context
*lp_ctx
, const char *option
)
1671 s
= talloc_strdup(NULL
, option
);
1684 ret
= lpcfg_set_cmdline(lp_ctx
, s
, p
+1);
1690 #define BOOLSTR(b) ((b) ? "Yes" : "No")
1693 * Print a parameter of the specified type.
1696 void lpcfg_print_parameter(struct parm_struct
*p
, void *ptr
, FILE * f
)
1698 /* For the seperation of lists values that we print below */
1699 const char *list_sep
= ", ";
1704 for (i
= 0; p
->enum_list
[i
].name
; i
++) {
1705 if (*(int *)ptr
== p
->enum_list
[i
].value
) {
1707 p
->enum_list
[i
].name
);
1714 fprintf(f
, "%s", BOOLSTR(*(bool *)ptr
));
1718 fprintf(f
, "%s", BOOLSTR(!*(bool *)ptr
));
1723 fprintf(f
, "%d", *(int *)ptr
);
1727 fprintf(f
, "%c", *(char *)ptr
);
1731 int val
= *(int *)ptr
;
1735 fprintf(f
, "0%03o", val
);
1744 if ((char ***)ptr
&& *(char ***)ptr
) {
1745 char **list
= *(char ***)ptr
;
1746 for (; *list
; list
++) {
1747 /* surround strings with whitespace in double quotes */
1748 if (*(list
+1) == NULL
) {
1749 /* last item, no extra separator */
1752 if ( strchr_m( *list
, ' ' ) ) {
1753 fprintf(f
, "\"%s\"%s", *list
, list_sep
);
1755 fprintf(f
, "%s%s", *list
, list_sep
);
1763 if (*(char **)ptr
) {
1764 fprintf(f
, "%s", *(char **)ptr
);
1773 * Check if two parameters are equal.
1776 bool lpcfg_equal_parameter(parm_type type
, void *ptr1
, void *ptr2
)
1781 return (*((bool *)ptr1
) == *((bool *)ptr2
));
1787 return (*((int *)ptr1
) == *((int *)ptr2
));
1790 return (*((char *)ptr1
) == *((char *)ptr2
));
1794 return str_list_equal(*(const char ***)ptr1
, *(const char ***)ptr2
);
1799 char *p1
= *(char **)ptr1
, *p2
= *(char **)ptr2
;
1804 return (p1
== p2
|| strequal(p1
, p2
));
1813 * Process a new section (service).
1815 * At this stage all sections are services.
1816 * Later we'll have special sections that permit server parameters to be set.
1817 * Returns True on success, False on failure.
1820 static bool do_section(const char *pszSectionName
, void *userdata
)
1822 struct loadparm_context
*lp_ctx
= (struct loadparm_context
*)userdata
;
1824 bool isglobal
= ((strwicmp(pszSectionName
, GLOBAL_NAME
) == 0) ||
1825 (strwicmp(pszSectionName
, GLOBAL_NAME2
) == 0));
1828 /* if we've just struck a global section, note the fact. */
1829 lp_ctx
->bInGlobalSection
= isglobal
;
1831 /* check for multiple global sections */
1832 if (lp_ctx
->bInGlobalSection
) {
1833 DEBUG(4, ("Processing section \"[%s]\"\n", pszSectionName
));
1837 /* if we have a current service, tidy it up before moving on */
1840 if (lp_ctx
->currentService
!= NULL
)
1841 bRetval
= lpcfg_service_ok(lp_ctx
->currentService
);
1843 /* if all is still well, move to the next record in the services array */
1845 /* We put this here to avoid an odd message order if messages are */
1846 /* issued by the post-processing of a previous section. */
1847 DEBUG(4, ("Processing section \"[%s]\"\n", pszSectionName
));
1849 if ((lp_ctx
->currentService
= lpcfg_add_service(lp_ctx
, lp_ctx
->sDefault
,
1852 DEBUG(0, ("Failed to add a new service\n"));
1862 * Determine if a particular base parameter is currently set to the default value.
1865 static bool is_default(struct loadparm_service
*sDefault
, int i
)
1867 void *def_ptr
= ((char *)sDefault
) + parm_table
[i
].offset
;
1868 switch (parm_table
[i
].type
) {
1871 return str_list_equal((const char * const *)parm_table
[i
].def
.lvalue
,
1872 (const char **)def_ptr
);
1875 return strequal(parm_table
[i
].def
.svalue
,
1879 return parm_table
[i
].def
.bvalue
==
1886 return parm_table
[i
].def
.ivalue
==
1895 *Display the contents of the global structure.
1898 static void dump_globals(struct loadparm_context
*lp_ctx
, FILE *f
,
1902 struct parmlist_entry
*data
;
1904 fprintf(f
, "# Global parameters\n[global]\n");
1906 for (i
= 0; parm_table
[i
].label
; i
++)
1907 if (parm_table
[i
].p_class
== P_GLOBAL
&&
1908 (i
== 0 || (parm_table
[i
].offset
!= parm_table
[i
- 1].offset
))) {
1909 if (!show_defaults
&& (lp_ctx
->flags
[i
] & FLAG_DEFAULT
))
1911 fprintf(f
, "\t%s = ", parm_table
[i
].label
);
1912 lpcfg_print_parameter(&parm_table
[i
], lpcfg_parm_ptr(lp_ctx
, NULL
, &parm_table
[i
]), f
);
1915 if (lp_ctx
->globals
->param_opt
!= NULL
) {
1916 for (data
= lp_ctx
->globals
->param_opt
; data
;
1917 data
= data
->next
) {
1918 if (!show_defaults
&& (data
->priority
& FLAG_DEFAULT
)) {
1921 fprintf(f
, "\t%s = %s\n", data
->key
, data
->value
);
1928 * Display the contents of a single services record.
1931 static void dump_a_service(struct loadparm_service
* pService
, struct loadparm_service
*sDefault
, FILE * f
,
1932 unsigned int *flags
)
1935 struct parmlist_entry
*data
;
1937 if (pService
!= sDefault
)
1938 fprintf(f
, "\n[%s]\n", pService
->szService
);
1940 for (i
= 0; parm_table
[i
].label
; i
++) {
1941 if (parm_table
[i
].p_class
== P_LOCAL
&&
1942 (*parm_table
[i
].label
!= '-') &&
1943 (i
== 0 || (parm_table
[i
].offset
!= parm_table
[i
- 1].offset
)))
1945 if (pService
== sDefault
) {
1946 if (flags
&& (flags
[i
] & FLAG_DEFAULT
)) {
1949 if (defaults_saved
) {
1950 if (is_default(sDefault
, i
)) {
1955 if (lpcfg_equal_parameter(parm_table
[i
].type
,
1956 ((char *)pService
) +
1957 parm_table
[i
].offset
,
1958 ((char *)sDefault
) +
1959 parm_table
[i
].offset
))
1963 fprintf(f
, "\t%s = ", parm_table
[i
].label
);
1964 lpcfg_print_parameter(&parm_table
[i
],
1965 ((char *)pService
) + parm_table
[i
].offset
, f
);
1969 if (pService
->param_opt
!= NULL
) {
1970 for (data
= pService
->param_opt
; data
; data
= data
->next
) {
1971 fprintf(f
, "\t%s = %s\n", data
->key
, data
->value
);
1976 bool lpcfg_dump_a_parameter(struct loadparm_context
*lp_ctx
,
1977 struct loadparm_service
*service
,
1978 const char *parm_name
, FILE * f
)
1980 struct parm_struct
*parm
;
1983 parm
= lpcfg_parm_struct(lp_ctx
, parm_name
);
1988 if (service
!= NULL
&& parm
->p_class
== P_GLOBAL
) {
1992 ptr
= lpcfg_parm_ptr(lp_ctx
, service
,parm
);
1994 lpcfg_print_parameter(parm
, ptr
, f
);
2000 * Auto-load some home services.
2002 static void lpcfg_add_auto_services(struct loadparm_context
*lp_ctx
,
2010 * Unload unused services.
2013 void lpcfg_killunused(struct loadparm_context
*lp_ctx
,
2014 struct smbsrv_connection
*smb
,
2015 bool (*snumused
) (struct smbsrv_connection
*, int))
2018 for (i
= 0; i
< lp_ctx
->iNumServices
; i
++) {
2019 if (lp_ctx
->services
[i
] == NULL
)
2022 if (!snumused
|| !snumused(smb
, i
)) {
2023 talloc_free(lp_ctx
->services
[i
]);
2024 lp_ctx
->services
[i
] = NULL
;
2030 static int lpcfg_destructor(struct loadparm_context
*lp_ctx
)
2032 struct parmlist_entry
*data
;
2034 if (lp_ctx
->refuse_free
) {
2035 /* someone is trying to free the
2036 global_loadparm_context.
2037 We can't allow that. */
2041 if (lp_ctx
->globals
->param_opt
!= NULL
) {
2042 struct parmlist_entry
*next
;
2043 for (data
= lp_ctx
->globals
->param_opt
; data
; data
=next
) {
2045 if (data
->priority
& FLAG_CMDLINE
) continue;
2046 DLIST_REMOVE(lp_ctx
->globals
->param_opt
, data
);
2055 * Initialise the global parameter structure.
2057 * Note that most callers should use loadparm_init_global() instead
2059 struct loadparm_context
*loadparm_init(TALLOC_CTX
*mem_ctx
)
2063 struct loadparm_context
*lp_ctx
;
2064 struct parmlist_entry
*parm
;
2067 lp_ctx
= talloc_zero(mem_ctx
, struct loadparm_context
);
2071 talloc_set_destructor(lp_ctx
, lpcfg_destructor
);
2072 lp_ctx
->bInGlobalSection
= true;
2073 lp_ctx
->globals
= talloc_zero(lp_ctx
, struct loadparm_global
);
2074 lp_ctx
->sDefault
= talloc_zero(lp_ctx
, struct loadparm_service
);
2076 lp_ctx
->sDefault
->iMaxPrintJobs
= 1000;
2077 lp_ctx
->sDefault
->bAvailable
= true;
2078 lp_ctx
->sDefault
->browseable
= true;
2079 lp_ctx
->sDefault
->read_only
= true;
2080 lp_ctx
->sDefault
->map_archive
= true;
2081 lp_ctx
->sDefault
->strict_locking
= true;
2082 lp_ctx
->sDefault
->oplocks
= true;
2083 lp_ctx
->sDefault
->create_mask
= 0744;
2084 lp_ctx
->sDefault
->force_create_mode
= 0000;
2085 lp_ctx
->sDefault
->directory_mask
= 0755;
2086 lp_ctx
->sDefault
->force_directory_mode
= 0000;
2088 DEBUG(3, ("Initialising global parameters\n"));
2090 for (i
= 0; parm_table
[i
].label
; i
++) {
2091 if ((parm_table
[i
].type
== P_STRING
||
2092 parm_table
[i
].type
== P_USTRING
) &&
2093 !(lp_ctx
->flags
[i
] & FLAG_CMDLINE
)) {
2095 if (parm_table
[i
].p_class
== P_LOCAL
) {
2096 r
= (char **)(((char *)lp_ctx
->sDefault
) + parm_table
[i
].offset
);
2098 r
= (char **)(((char *)lp_ctx
->globals
) + parm_table
[i
].offset
);
2100 *r
= talloc_strdup(lp_ctx
, "");
2104 logfile
= talloc_asprintf(lp_ctx
, "%s/log.samba", dyn_LOGFILEBASE
);
2105 lpcfg_do_global_parameter(lp_ctx
, "log file", logfile
);
2106 talloc_free(logfile
);
2108 lpcfg_do_global_parameter(lp_ctx
, "log level", "0");
2110 lpcfg_do_global_parameter(lp_ctx
, "syslog", "1");
2111 lpcfg_do_global_parameter(lp_ctx
, "syslog only", "No");
2112 lpcfg_do_global_parameter(lp_ctx
, "debug timestamp", "Yes");
2113 lpcfg_do_global_parameter(lp_ctx
, "debug prefix timestamp", "No");
2114 lpcfg_do_global_parameter(lp_ctx
, "debug hires timestamp", "Yes");
2115 lpcfg_do_global_parameter(lp_ctx
, "debug pid", "No");
2116 lpcfg_do_global_parameter(lp_ctx
, "debug uid", "No");
2117 lpcfg_do_global_parameter(lp_ctx
, "debug class", "No");
2119 lpcfg_do_global_parameter(lp_ctx
, "share backend", "classic");
2121 lpcfg_do_global_parameter(lp_ctx
, "server role", "auto");
2122 lpcfg_do_global_parameter(lp_ctx
, "domain logons", "No");
2123 lpcfg_do_global_parameter(lp_ctx
, "domain master", "Auto");
2125 /* options that can be set on the command line must be initialised via
2126 the slower lpcfg_do_global_parameter() to ensure that FLAG_CMDLINE is obeyed */
2128 lpcfg_do_global_parameter(lp_ctx
, "socket options", "TCP_NODELAY");
2130 lpcfg_do_global_parameter(lp_ctx
, "workgroup", DEFAULT_WORKGROUP
);
2131 myname
= get_myname(lp_ctx
);
2132 lpcfg_do_global_parameter(lp_ctx
, "netbios name", myname
);
2133 talloc_free(myname
);
2134 lpcfg_do_global_parameter(lp_ctx
, "name resolve order", "lmhosts wins host bcast");
2136 lpcfg_do_global_parameter(lp_ctx
, "fstype", "NTFS");
2138 lpcfg_do_global_parameter(lp_ctx
, "ntvfs handler", "unixuid default");
2139 lpcfg_do_global_parameter(lp_ctx
, "max connections", "0");
2141 lpcfg_do_global_parameter(lp_ctx
, "dcerpc endpoint servers", "epmapper wkssvc rpcecho samr netlogon lsarpc spoolss drsuapi dssetup unixinfo browser eventlog6 backupkey dnsserver");
2142 lpcfg_do_global_parameter(lp_ctx
, "server services", "s3fs rpc nbt wrepl ldap cldap kdc drepl winbind ntp_signd kcc dnsupdate dns");
2143 lpcfg_do_global_parameter(lp_ctx
, "kccsrv:samba_kcc", "true");
2144 /* the winbind method for domain controllers is for both RODC
2145 auth forwarding and for trusted domains */
2146 lpcfg_do_global_parameter(lp_ctx
, "private dir", dyn_PRIVATE_DIR
);
2147 lpcfg_do_global_parameter(lp_ctx
, "registry:HKEY_LOCAL_MACHINE", "hklm.ldb");
2149 /* This hive should be dynamically generated by Samba using
2150 data from the sam, but for the moment leave it in a tdb to
2151 keep regedt32 from popping up an annoying dialog. */
2152 lpcfg_do_global_parameter(lp_ctx
, "registry:HKEY_USERS", "hku.ldb");
2154 /* using UTF8 by default allows us to support all chars */
2155 lpcfg_do_global_parameter(lp_ctx
, "unix charset", "UTF-8");
2157 /* Use codepage 850 as a default for the dos character set */
2158 lpcfg_do_global_parameter(lp_ctx
, "dos charset", "CP850");
2161 * Allow the default PASSWD_CHAT to be overridden in local.h.
2163 lpcfg_do_global_parameter(lp_ctx
, "passwd chat", DEFAULT_PASSWD_CHAT
);
2165 lpcfg_do_global_parameter(lp_ctx
, "pid directory", dyn_PIDDIR
);
2166 lpcfg_do_global_parameter(lp_ctx
, "lock dir", dyn_LOCKDIR
);
2167 lpcfg_do_global_parameter(lp_ctx
, "state directory", dyn_STATEDIR
);
2168 lpcfg_do_global_parameter(lp_ctx
, "cache directory", dyn_CACHEDIR
);
2169 lpcfg_do_global_parameter(lp_ctx
, "ncalrpc dir", dyn_NCALRPCDIR
);
2171 lpcfg_do_global_parameter(lp_ctx
, "nbt client socket address", "0.0.0.0");
2172 lpcfg_do_global_parameter_var(lp_ctx
, "server string",
2173 "Samba %s", SAMBA_VERSION_STRING
);
2175 lpcfg_do_global_parameter(lp_ctx
, "password server", "*");
2177 lpcfg_do_global_parameter(lp_ctx
, "max mux", "50");
2178 lpcfg_do_global_parameter(lp_ctx
, "max xmit", "16644");
2179 lpcfg_do_global_parameter(lp_ctx
, "host msdfs", "true");
2181 lpcfg_do_global_parameter(lp_ctx
, "LargeReadwrite", "True");
2182 lpcfg_do_global_parameter(lp_ctx
, "server min protocol", "LANMAN1");
2183 lpcfg_do_global_parameter(lp_ctx
, "server max protocol", "SMB3");
2184 lpcfg_do_global_parameter(lp_ctx
, "client min protocol", "CORE");
2185 lpcfg_do_global_parameter(lp_ctx
, "client max protocol", "NT1");
2186 lpcfg_do_global_parameter(lp_ctx
, "security", "AUTO");
2187 lpcfg_do_global_parameter(lp_ctx
, "EncryptPasswords", "True");
2188 lpcfg_do_global_parameter(lp_ctx
, "ReadRaw", "True");
2189 lpcfg_do_global_parameter(lp_ctx
, "WriteRaw", "True");
2190 lpcfg_do_global_parameter(lp_ctx
, "NullPasswords", "False");
2191 lpcfg_do_global_parameter(lp_ctx
, "old password allowed period", "60");
2192 lpcfg_do_global_parameter(lp_ctx
, "ObeyPamRestrictions", "False");
2194 lpcfg_do_global_parameter(lp_ctx
, "TimeServer", "False");
2195 lpcfg_do_global_parameter(lp_ctx
, "BindInterfacesOnly", "False");
2196 lpcfg_do_global_parameter(lp_ctx
, "Unicode", "True");
2197 lpcfg_do_global_parameter(lp_ctx
, "ClientLanManAuth", "False");
2198 lpcfg_do_global_parameter(lp_ctx
, "ClientNTLMv2Auth", "True");
2199 lpcfg_do_global_parameter(lp_ctx
, "LanmanAuth", "False");
2200 lpcfg_do_global_parameter(lp_ctx
, "NTLMAuth", "True");
2201 lpcfg_do_global_parameter(lp_ctx
, "client use spnego principal", "False");
2203 lpcfg_do_global_parameter(lp_ctx
, "UnixExtensions", "True");
2205 lpcfg_do_global_parameter(lp_ctx
, "PreferredMaster", "Auto");
2206 lpcfg_do_global_parameter(lp_ctx
, "LocalMaster", "True");
2208 lpcfg_do_global_parameter(lp_ctx
, "wins support", "False");
2209 lpcfg_do_global_parameter(lp_ctx
, "dns proxy", "True");
2211 lpcfg_do_global_parameter(lp_ctx
, "winbind separator", "\\");
2212 lpcfg_do_global_parameter(lp_ctx
, "winbind sealed pipes", "True");
2213 lpcfg_do_global_parameter(lp_ctx
, "require strong key", "True");
2214 lpcfg_do_global_parameter(lp_ctx
, "winbindd socket directory", dyn_WINBINDD_SOCKET_DIR
);
2215 lpcfg_do_global_parameter(lp_ctx
, "winbindd privileged socket directory", dyn_WINBINDD_PRIVILEGED_SOCKET_DIR
);
2216 lpcfg_do_global_parameter(lp_ctx
, "ntp signd socket directory", dyn_NTP_SIGND_SOCKET_DIR
);
2217 lpcfg_do_global_parameter_var(lp_ctx
, "dns update command", "%s/samba_dnsupdate", dyn_SCRIPTSBINDIR
);
2218 lpcfg_do_global_parameter_var(lp_ctx
, "spn update command", "%s/samba_spnupdate", dyn_SCRIPTSBINDIR
);
2219 lpcfg_do_global_parameter_var(lp_ctx
, "samba kcc command",
2220 "%s/samba_kcc", dyn_SCRIPTSBINDIR
);
2221 lpcfg_do_global_parameter(lp_ctx
, "template shell", "/bin/false");
2222 lpcfg_do_global_parameter(lp_ctx
, "template homedir", "/home/%WORKGROUP%/%ACCOUNTNAME%");
2224 lpcfg_do_global_parameter(lp_ctx
, "client signing", "default");
2225 lpcfg_do_global_parameter(lp_ctx
, "server signing", "default");
2227 lpcfg_do_global_parameter(lp_ctx
, "use spnego", "True");
2229 lpcfg_do_global_parameter(lp_ctx
, "use mmap", "True");
2231 lpcfg_do_global_parameter(lp_ctx
, "smb ports", "445 139");
2232 lpcfg_do_global_parameter(lp_ctx
, "nbt port", "137");
2233 lpcfg_do_global_parameter(lp_ctx
, "dgram port", "138");
2234 lpcfg_do_global_parameter(lp_ctx
, "cldap port", "389");
2235 lpcfg_do_global_parameter(lp_ctx
, "krb5 port", "88");
2236 lpcfg_do_global_parameter(lp_ctx
, "kpasswd port", "464");
2237 lpcfg_do_global_parameter(lp_ctx
, "web port", "901");
2239 lpcfg_do_global_parameter(lp_ctx
, "nt status support", "True");
2241 lpcfg_do_global_parameter(lp_ctx
, "max wins ttl", "518400"); /* 6 days */
2242 lpcfg_do_global_parameter(lp_ctx
, "min wins ttl", "21600");
2244 lpcfg_do_global_parameter(lp_ctx
, "tls enabled", "True");
2245 lpcfg_do_global_parameter(lp_ctx
, "tls keyfile", "tls/key.pem");
2246 lpcfg_do_global_parameter(lp_ctx
, "tls certfile", "tls/cert.pem");
2247 lpcfg_do_global_parameter(lp_ctx
, "tls cafile", "tls/ca.pem");
2248 lpcfg_do_global_parameter(lp_ctx
, "prefork children:smb", "4");
2250 lpcfg_do_global_parameter(lp_ctx
, "rndc command", "/usr/sbin/rndc");
2251 lpcfg_do_global_parameter(lp_ctx
, "nsupdate command", "/usr/bin/nsupdate -g");
2253 lpcfg_do_global_parameter(lp_ctx
, "allow dns updates", "secure only");
2254 lpcfg_do_global_parameter(lp_ctx
, "dns forwarder", "");
2256 lpcfg_do_global_parameter(lp_ctx
, "algorithmic rid base", "1000");
2258 lpcfg_do_global_parameter(lp_ctx
, "enhanced browsing", "True");
2260 lpcfg_do_global_parameter(lp_ctx
, "winbind nss info", "template");
2262 lpcfg_do_global_parameter(lp_ctx
, "server schannel", "Auto");
2264 lpcfg_do_global_parameter(lp_ctx
, "short preserve case", "True");
2266 lpcfg_do_global_parameter(lp_ctx
, "max open files", "16384");
2268 lpcfg_do_global_parameter(lp_ctx
, "cups connection timeout", "30");
2270 lpcfg_do_global_parameter(lp_ctx
, "locking", "True");
2272 lpcfg_do_global_parameter(lp_ctx
, "block size", "1024");
2274 lpcfg_do_global_parameter(lp_ctx
, "client use spnego", "True");
2276 lpcfg_do_global_parameter(lp_ctx
, "change notify", "True");
2278 lpcfg_do_global_parameter(lp_ctx
, "name cache timeout", "660");
2280 lpcfg_do_global_parameter(lp_ctx
, "defer sharing violations", "True");
2282 lpcfg_do_global_parameter(lp_ctx
, "ldap replication sleep", "1000");
2284 lpcfg_do_global_parameter(lp_ctx
, "idmap backend", "tdb");
2286 lpcfg_do_global_parameter(lp_ctx
, "enable privileges", "True");
2288 lpcfg_do_global_parameter_var(lp_ctx
, "smb2 max write", "%u", DEFAULT_SMB2_MAX_WRITE
);
2290 lpcfg_do_global_parameter(lp_ctx
, "passdb backend", "tdbsam");
2292 lpcfg_do_global_parameter(lp_ctx
, "getwd cache", "True");
2294 lpcfg_do_global_parameter(lp_ctx
, "winbind nested groups", "True");
2296 lpcfg_do_global_parameter(lp_ctx
, "mangled names", "True");
2298 lpcfg_do_global_parameter_var(lp_ctx
, "smb2 max credits", "%u", DEFAULT_SMB2_MAX_CREDITS
);
2300 lpcfg_do_global_parameter(lp_ctx
, "ldap ssl", "start tls");
2302 lpcfg_do_global_parameter(lp_ctx
, "ldap deref", "auto");
2304 lpcfg_do_global_parameter(lp_ctx
, "lm interval", "60");
2306 lpcfg_do_global_parameter(lp_ctx
, "mangling method", "hash2");
2308 lpcfg_do_global_parameter(lp_ctx
, "hide dot files", "True");
2310 lpcfg_do_global_parameter(lp_ctx
, "browse list", "True");
2312 lpcfg_do_global_parameter(lp_ctx
, "passwd chat timeout", "2");
2314 lpcfg_do_global_parameter(lp_ctx
, "guest account", GUEST_ACCOUNT
);
2316 lpcfg_do_global_parameter(lp_ctx
, "client schannel", "auto");
2318 lpcfg_do_global_parameter(lp_ctx
, "smb encrypt", "default");
2320 lpcfg_do_global_parameter(lp_ctx
, "max log size", "5000");
2322 lpcfg_do_global_parameter(lp_ctx
, "idmap negative cache time", "120");
2324 lpcfg_do_global_parameter(lp_ctx
, "ldap follow referral", "auto");
2326 lpcfg_do_global_parameter(lp_ctx
, "multicast dns register", "yes");
2328 lpcfg_do_global_parameter(lp_ctx
, "winbind reconnect delay", "30");
2330 lpcfg_do_global_parameter(lp_ctx
, "nt acl support", "yes");
2332 lpcfg_do_global_parameter(lp_ctx
, "acl check permissions", "yes");
2334 lpcfg_do_global_parameter(lp_ctx
, "keepalive", "300");
2336 lpcfg_do_global_parameter(lp_ctx
, "winbind cache time", "300");
2338 lpcfg_do_global_parameter(lp_ctx
, "level2 oplocks", "yes");
2340 lpcfg_do_global_parameter(lp_ctx
, "show add printer wizard", "yes");
2342 lpcfg_do_global_parameter(lp_ctx
, "allocation roundup size", "1048576");
2344 lpcfg_do_global_parameter(lp_ctx
, "ldap page size", "1024");
2346 lpcfg_do_global_parameter(lp_ctx
, "kernel share modes", "yes");
2348 lpcfg_do_global_parameter(lp_ctx
, "strict locking", "Auto");
2350 lpcfg_do_global_parameter(lp_ctx
, "map readonly", "yes");
2352 lpcfg_do_global_parameter(lp_ctx
, "allow trusted domains", "yes");
2354 lpcfg_do_global_parameter(lp_ctx
, "default devmode", "yes");
2356 lpcfg_do_global_parameter(lp_ctx
, "os level", "20");
2358 lpcfg_do_global_parameter(lp_ctx
, "dos filetimes", "yes");
2360 lpcfg_do_global_parameter(lp_ctx
, "mangling char", "~");
2362 lpcfg_do_global_parameter(lp_ctx
, "printcap cache time", "750");
2364 lpcfg_do_global_parameter(lp_ctx
, "create krb5 conf", "yes");
2366 lpcfg_do_global_parameter(lp_ctx
, "winbind max clients", "200");
2368 lpcfg_do_global_parameter(lp_ctx
, "acl map full control", "yes");
2370 lpcfg_do_global_parameter(lp_ctx
, "nt pipe support", "yes");
2372 lpcfg_do_global_parameter(lp_ctx
, "ldap debug threshold", "10");
2374 lpcfg_do_global_parameter(lp_ctx
, "follow symlinks", "yes");
2376 lpcfg_do_global_parameter(lp_ctx
, "machine password timeout", "604800");
2378 lpcfg_do_global_parameter(lp_ctx
, "ldap connection timeout", "2");
2380 lpcfg_do_global_parameter(lp_ctx
, "winbind expand groups", "1");
2382 lpcfg_do_global_parameter(lp_ctx
, "stat cache", "yes");
2384 lpcfg_do_global_parameter(lp_ctx
, "lpq cache time", "30");
2386 lpcfg_do_global_parameter_var(lp_ctx
, "smb2 max trans", "%u", DEFAULT_SMB2_MAX_TRANSACT
);
2388 lpcfg_do_global_parameter_var(lp_ctx
, "smb2 max read", "%u", DEFAULT_SMB2_MAX_READ
);
2390 lpcfg_do_global_parameter(lp_ctx
, "durable handles", "yes");
2392 lpcfg_do_global_parameter(lp_ctx
, "max stat cache size", "256");
2394 lpcfg_do_global_parameter(lp_ctx
, "ldap passwd sync", "no");
2396 lpcfg_do_global_parameter(lp_ctx
, "kernel change notify", "yes");
2398 lpcfg_do_global_parameter(lp_ctx
, "max ttl", "259200");
2400 lpcfg_do_global_parameter(lp_ctx
, "blocking locks", "yes");
2402 lpcfg_do_global_parameter(lp_ctx
, "oplock contention limit", "2");
2404 lpcfg_do_global_parameter(lp_ctx
, "load printers", "yes");
2406 lpcfg_do_global_parameter(lp_ctx
, "idmap cache time", "604800");
2408 lpcfg_do_global_parameter(lp_ctx
, "preserve case", "yes");
2410 lpcfg_do_global_parameter(lp_ctx
, "lm announce", "auto");
2412 lpcfg_do_global_parameter(lp_ctx
, "afs token lifetime", "604800");
2414 lpcfg_do_global_parameter(lp_ctx
, "enable core files", "yes");
2416 lpcfg_do_global_parameter(lp_ctx
, "winbind max domain connections", "1");
2418 lpcfg_do_global_parameter(lp_ctx
, "case sensitive", "auto");
2420 lpcfg_do_global_parameter(lp_ctx
, "ldap timeout", "15");
2422 lpcfg_do_global_parameter(lp_ctx
, "mangle prefix", "1");
2424 lpcfg_do_global_parameter(lp_ctx
, "posix locking", "yes");
2426 lpcfg_do_global_parameter(lp_ctx
, "lock spin time", "200");
2428 lpcfg_do_global_parameter(lp_ctx
, "directory name cache size", "100");
2430 lpcfg_do_global_parameter(lp_ctx
, "nmbd bind explicit broadcast", "yes");
2432 lpcfg_do_global_parameter(lp_ctx
, "init logon delay", "100");
2434 lpcfg_do_global_parameter(lp_ctx
, "usershare owner only", "yes");
2436 lpcfg_do_global_parameter(lp_ctx
, "-valid", "yes");
2438 lpcfg_do_global_parameter_var(lp_ctx
, "usershare path", "%s/usershares", get_dyn_STATEDIR());
2441 lpcfg_do_global_parameter_var(lp_ctx
, "panic action", "/bin/sleep 999999999");
2444 lpcfg_do_global_parameter(lp_ctx
, "smb passwd file", get_dyn_SMB_PASSWD_FILE());
2446 lpcfg_do_global_parameter(lp_ctx
, "logon home", "\\\\%N\\%U");
2448 lpcfg_do_global_parameter(lp_ctx
, "logon path", "\\\\%N\\%U\\profile");
2450 lpcfg_do_global_parameter(lp_ctx
, "printjob username", "%U");
2452 for (i
= 0; parm_table
[i
].label
; i
++) {
2453 if (!(lp_ctx
->flags
[i
] & FLAG_CMDLINE
)) {
2454 lp_ctx
->flags
[i
] |= FLAG_DEFAULT
;
2458 for (parm
=lp_ctx
->globals
->param_opt
; parm
; parm
=parm
->next
) {
2459 if (!(parm
->priority
& FLAG_CMDLINE
)) {
2460 parm
->priority
|= FLAG_DEFAULT
;
2468 * Initialise the global parameter structure.
2470 struct loadparm_context
*loadparm_init_global(bool load_default
)
2472 if (global_loadparm_context
== NULL
) {
2473 global_loadparm_context
= loadparm_init(NULL
);
2475 if (global_loadparm_context
== NULL
) {
2478 global_loadparm_context
->global
= true;
2479 if (load_default
&& !global_loadparm_context
->loaded
) {
2480 lpcfg_load_default(global_loadparm_context
);
2482 global_loadparm_context
->refuse_free
= true;
2483 return global_loadparm_context
;
2487 * Initialise the global parameter structure.
2489 struct loadparm_context
*loadparm_init_s3(TALLOC_CTX
*mem_ctx
,
2490 const struct loadparm_s3_helpers
*s3_fns
)
2492 struct loadparm_context
*loadparm_context
= talloc_zero(mem_ctx
, struct loadparm_context
);
2493 if (!loadparm_context
) {
2496 loadparm_context
->s3_fns
= s3_fns
;
2497 loadparm_context
->globals
= s3_fns
->globals
;
2498 return loadparm_context
;
2501 const char *lpcfg_configfile(struct loadparm_context
*lp_ctx
)
2503 return lp_ctx
->szConfigFile
;
2506 const char *lp_default_path(void)
2508 if (getenv("SMB_CONF_PATH"))
2509 return getenv("SMB_CONF_PATH");
2511 return dyn_CONFIGFILE
;
2515 * Update the internal state of a loadparm context after settings
2518 static bool lpcfg_update(struct loadparm_context
*lp_ctx
)
2520 struct debug_settings settings
;
2521 TALLOC_CTX
*tmp_ctx
;
2523 tmp_ctx
= talloc_new(lp_ctx
);
2524 if (tmp_ctx
== NULL
) {
2528 lpcfg_add_auto_services(lp_ctx
, lpcfg_auto_services(lp_ctx
, tmp_ctx
));
2530 if (!lp_ctx
->globals
->wins_server_list
&& lp_ctx
->globals
->we_are_a_wins_server
) {
2531 lpcfg_do_global_parameter(lp_ctx
, "wins server", "127.0.0.1");
2534 if (!lp_ctx
->global
) {
2535 TALLOC_FREE(tmp_ctx
);
2539 panic_action
= lp_ctx
->globals
->panic_action
;
2541 reload_charcnv(lp_ctx
);
2543 ZERO_STRUCT(settings
);
2544 /* Add any more debug-related smb.conf parameters created in
2546 settings
.syslog
= lp_ctx
->globals
->syslog
;
2547 settings
.syslog_only
= lp_ctx
->globals
->syslog_only
;
2548 settings
.timestamp_logs
= lp_ctx
->globals
->timestamp_logs
;
2549 settings
.debug_prefix_timestamp
= lp_ctx
->globals
->debug_prefix_timestamp
;
2550 settings
.debug_hires_timestamp
= lp_ctx
->globals
->debug_hires_timestamp
;
2551 settings
.debug_pid
= lp_ctx
->globals
->debug_pid
;
2552 settings
.debug_uid
= lp_ctx
->globals
->debug_uid
;
2553 settings
.debug_class
= lp_ctx
->globals
->debug_class
;
2554 debug_set_settings(&settings
);
2556 /* FIXME: This is a bit of a hack, but we can't use a global, since
2557 * not everything that uses lp also uses the socket library */
2558 if (lpcfg_parm_bool(lp_ctx
, NULL
, "socket", "testnonblock", false)) {
2559 setenv("SOCKET_TESTNONBLOCK", "1", 1);
2561 unsetenv("SOCKET_TESTNONBLOCK");
2564 TALLOC_FREE(tmp_ctx
);
2568 bool lpcfg_load_default(struct loadparm_context
*lp_ctx
)
2572 path
= lp_default_path();
2574 if (!file_exist(path
)) {
2575 /* We allow the default smb.conf file to not exist,
2576 * basically the equivalent of an empty file. */
2577 return lpcfg_update(lp_ctx
);
2580 return lpcfg_load(lp_ctx
, path
);
2584 * Load the services array from the services file.
2586 * Return True on success, False on failure.
2588 bool lpcfg_load(struct loadparm_context
*lp_ctx
, const char *filename
)
2593 filename
= talloc_strdup(lp_ctx
, filename
);
2595 lp_ctx
->szConfigFile
= filename
;
2597 if (lp_ctx
->s3_fns
) {
2598 return lp_ctx
->s3_fns
->load(filename
);
2601 lp_ctx
->bInGlobalSection
= true;
2602 n2
= standard_sub_basic(lp_ctx
, lp_ctx
->szConfigFile
);
2603 DEBUG(2, ("lpcfg_load: refreshing parameters from %s\n", n2
));
2605 add_to_file_list(lp_ctx
, &lp_ctx
->file_lists
, lp_ctx
->szConfigFile
, n2
);
2607 /* We get sections first, so have to start 'behind' to make up */
2608 lp_ctx
->currentService
= NULL
;
2609 bRetval
= pm_process(n2
, do_section
, do_parameter
, lp_ctx
);
2611 /* finish up the last section */
2612 DEBUG(4, ("pm_process() returned %s\n", BOOLSTR(bRetval
)));
2614 if (lp_ctx
->currentService
!= NULL
)
2615 bRetval
= lpcfg_service_ok(lp_ctx
->currentService
);
2617 bRetval
= bRetval
&& lpcfg_update(lp_ctx
);
2619 /* we do this unconditionally, so that it happens even
2620 for a missing smb.conf */
2621 reload_charcnv(lp_ctx
);
2623 if (bRetval
== true) {
2624 /* set this up so that any child python tasks will
2625 find the right smb.conf */
2626 setenv("SMB_CONF_PATH", filename
, 1);
2628 /* set the context used by the lp_*() function
2630 global_loadparm_context
= lp_ctx
;
2631 lp_ctx
->loaded
= true;
2638 * Return the max number of services.
2641 int lpcfg_numservices(struct loadparm_context
*lp_ctx
)
2643 if (lp_ctx
->s3_fns
) {
2644 return lp_ctx
->s3_fns
->get_numservices();
2647 return lp_ctx
->iNumServices
;
2651 * Display the contents of the services array in human-readable form.
2654 void lpcfg_dump(struct loadparm_context
*lp_ctx
, FILE *f
, bool show_defaults
,
2659 if (lp_ctx
->s3_fns
) {
2660 lp_ctx
->s3_fns
->dump(f
, show_defaults
, maxtoprint
);
2664 defaults_saved
= !show_defaults
;
2666 dump_globals(lp_ctx
, f
, show_defaults
);
2668 dump_a_service(lp_ctx
->sDefault
, lp_ctx
->sDefault
, f
, lp_ctx
->flags
);
2670 for (iService
= 0; iService
< maxtoprint
; iService
++)
2671 lpcfg_dump_one(f
, show_defaults
, lp_ctx
->services
[iService
], lp_ctx
->sDefault
);
2675 * Display the contents of one service in human-readable form.
2677 void lpcfg_dump_one(FILE *f
, bool show_defaults
, struct loadparm_service
*service
, struct loadparm_service
*sDefault
)
2679 if (service
!= NULL
) {
2680 if (service
->szService
[0] == '\0')
2682 dump_a_service(service
, sDefault
, f
, NULL
);
2686 struct loadparm_service
*lpcfg_servicebynum(struct loadparm_context
*lp_ctx
,
2689 if (lp_ctx
->s3_fns
) {
2690 return lp_ctx
->s3_fns
->get_servicebynum(snum
);
2693 return lp_ctx
->services
[snum
];
2696 struct loadparm_service
*lpcfg_service(struct loadparm_context
*lp_ctx
,
2697 const char *service_name
)
2702 if (lp_ctx
->s3_fns
) {
2703 return lp_ctx
->s3_fns
->get_service(service_name
);
2706 for (iService
= lp_ctx
->iNumServices
- 1; iService
>= 0; iService
--) {
2707 if (lp_ctx
->services
[iService
] &&
2708 lp_ctx
->services
[iService
]->szService
) {
2710 * The substitution here is used to support %U is
2713 serviceName
= standard_sub_basic(
2714 lp_ctx
->services
[iService
],
2715 lp_ctx
->services
[iService
]->szService
);
2716 if (strequal(serviceName
, service_name
)) {
2717 talloc_free(serviceName
);
2718 return lp_ctx
->services
[iService
];
2720 talloc_free(serviceName
);
2724 DEBUG(7,("lpcfg_servicenumber: couldn't find %s\n", service_name
));
2728 const char *lpcfg_servicename(const struct loadparm_service
*service
)
2730 return lpcfg_string((const char *)service
->szService
);
2734 * A useful volume label function.
2736 const char *lpcfg_volume_label(struct loadparm_service
*service
, struct loadparm_service
*sDefault
)
2739 ret
= lpcfg_string((const char *)((service
!= NULL
&& service
->volume
!= NULL
) ?
2740 service
->volume
: sDefault
->volume
));
2742 return lpcfg_servicename(service
);
2747 * Return the correct printer name.
2749 const char *lpcfg_printername(struct loadparm_service
*service
, struct loadparm_service
*sDefault
)
2752 ret
= lpcfg_string((const char *)((service
!= NULL
&& service
->_printername
!= NULL
) ?
2753 service
->_printername
: sDefault
->_printername
));
2754 if (ret
== NULL
|| (ret
!= NULL
&& *ret
== '\0'))
2755 ret
= lpcfg_servicename(service
);
2762 * Return the max print jobs per queue.
2764 int lpcfg_maxprintjobs(struct loadparm_service
*service
, struct loadparm_service
*sDefault
)
2766 int maxjobs
= (service
!= NULL
) ? service
->iMaxPrintJobs
: sDefault
->iMaxPrintJobs
;
2767 if (maxjobs
<= 0 || maxjobs
>= PRINT_MAX_JOBID
)
2768 maxjobs
= PRINT_MAX_JOBID
- 1;
2773 struct smb_iconv_handle
*lpcfg_iconv_handle(struct loadparm_context
*lp_ctx
)
2775 if (lp_ctx
== NULL
) {
2776 return get_iconv_handle();
2778 return lp_ctx
->iconv_handle
;
2781 _PUBLIC_
void reload_charcnv(struct loadparm_context
*lp_ctx
)
2783 struct smb_iconv_handle
*old_ic
= lp_ctx
->iconv_handle
;
2784 if (!lp_ctx
->global
) {
2788 if (old_ic
== NULL
) {
2789 old_ic
= global_iconv_handle
;
2791 lp_ctx
->iconv_handle
= smb_iconv_handle_reinit_lp(lp_ctx
, lp_ctx
, old_ic
);
2792 global_iconv_handle
= lp_ctx
->iconv_handle
;
2795 _PUBLIC_
char *lpcfg_tls_keyfile(TALLOC_CTX
*mem_ctx
, struct loadparm_context
*lp_ctx
)
2797 return lpcfg_private_path(mem_ctx
, lp_ctx
, lpcfg__tls_keyfile(lp_ctx
));
2800 _PUBLIC_
char *lpcfg_tls_certfile(TALLOC_CTX
*mem_ctx
, struct loadparm_context
*lp_ctx
)
2802 return lpcfg_private_path(mem_ctx
, lp_ctx
, lpcfg__tls_certfile(lp_ctx
));
2805 _PUBLIC_
char *lpcfg_tls_cafile(TALLOC_CTX
*mem_ctx
, struct loadparm_context
*lp_ctx
)
2807 return lpcfg_private_path(mem_ctx
, lp_ctx
, lpcfg__tls_cafile(lp_ctx
));
2810 _PUBLIC_
char *lpcfg_tls_crlfile(TALLOC_CTX
*mem_ctx
, struct loadparm_context
*lp_ctx
)
2812 return lpcfg_private_path(mem_ctx
, lp_ctx
, lpcfg__tls_crlfile(lp_ctx
));
2815 _PUBLIC_
char *lpcfg_tls_dhpfile(TALLOC_CTX
*mem_ctx
, struct loadparm_context
*lp_ctx
)
2817 return lpcfg_private_path(mem_ctx
, lp_ctx
, lpcfg__tls_dhpfile(lp_ctx
));
2820 struct gensec_settings
*lpcfg_gensec_settings(TALLOC_CTX
*mem_ctx
, struct loadparm_context
*lp_ctx
)
2822 struct gensec_settings
*settings
= talloc_zero(mem_ctx
, struct gensec_settings
);
2823 if (settings
== NULL
)
2825 SMB_ASSERT(lp_ctx
!= NULL
);
2826 settings
->lp_ctx
= talloc_reference(settings
, lp_ctx
);
2827 settings
->target_hostname
= lpcfg_parm_string(lp_ctx
, NULL
, "gensec", "target_hostname");
2831 int lpcfg_server_role(struct loadparm_context
*lp_ctx
)
2833 int domain_master
= lpcfg__domain_master(lp_ctx
);
2835 return lp_find_server_role(lpcfg__server_role(lp_ctx
),
2836 lpcfg__security(lp_ctx
),
2837 lpcfg__domain_logons(lp_ctx
),
2838 (domain_master
== true) ||
2839 (domain_master
== Auto
));
2842 int lpcfg_security(struct loadparm_context
*lp_ctx
)
2844 return lp_find_security(lpcfg__server_role(lp_ctx
),
2845 lpcfg__security(lp_ctx
));
2848 bool lpcfg_server_signing_allowed(struct loadparm_context
*lp_ctx
, bool *mandatory
)
2850 bool allowed
= true;
2851 enum smb_signing_setting signing_setting
= lpcfg_server_signing(lp_ctx
);
2855 if (signing_setting
== SMB_SIGNING_DEFAULT
) {
2857 * If we are a domain controller, SMB signing is
2858 * really important, as it can prevent a number of
2859 * attacks on communications between us and the
2862 * However, it really sucks (no sendfile, CPU
2863 * overhead) performance-wise when used on a
2864 * file server, so disable it by default
2868 if (lpcfg_server_role(lp_ctx
) >= ROLE_ACTIVE_DIRECTORY_DC
) {
2869 signing_setting
= SMB_SIGNING_REQUIRED
;
2871 signing_setting
= SMB_SIGNING_OFF
;
2875 switch (signing_setting
) {
2876 case SMB_SIGNING_REQUIRED
:
2879 case SMB_SIGNING_IF_REQUIRED
:
2881 case SMB_SIGNING_DEFAULT
:
2882 case SMB_SIGNING_OFF
:
2890 int lpcfg_tdb_hash_size(struct loadparm_context
*lp_ctx
, const char *name
)
2898 base
= strrchr_m(name
, '/');
2904 return lpcfg_parm_int(lp_ctx
, NULL
, "tdb_hashsize", base
, 0);
2908 int lpcfg_tdb_flags(struct loadparm_context
*lp_ctx
, int tdb_flags
)
2910 if (!lpcfg_use_mmap(lp_ctx
)) {
2911 tdb_flags
|= TDB_NOMMAP
;