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"
70 #define standard_sub_basic talloc_strdup
72 static bool do_parameter(const char *, const char *, void *);
73 static bool defaults_saved
= false;
75 #define LOADPARM_EXTRA_GLOBALS \
76 struct parmlist_entry *param_opt; \
77 char *realm_original; \
79 int iminreceivefile; \
80 char *szPrintcapname; \
82 int iPreferredMaster; \
83 char *szLdapMachineSuffix; \
84 char *szLdapUserSuffix; \
85 char *szLdapIdmapSuffix; \
86 char *szLdapGroupSuffix; \
87 char *szUsershareTemplateShare; \
90 char *szIdmapBackend; \
91 int winbindMaxDomainConnections; \
92 int ismb2_max_credits; \
100 #include "lib/param/param_global.h"
102 #define NUMPARAMETERS (sizeof(parm_table) / sizeof(struct parm_struct))
104 /* we don't need a special handler for "dos charset" and "unix charset" */
105 #define handle_dos_charset NULL
106 #define handle_charset NULL
108 /* these are parameter handlers which are not needed in the
111 #define handle_netbios_aliases NULL
112 #define handle_printing NULL
113 #define handle_ldap_debug_level NULL
114 #define handle_idmap_backend NULL
115 #define handle_idmap_uid NULL
116 #define handle_idmap_gid NULL
122 /* prototypes for the special type handlers */
123 static bool handle_include(struct loadparm_context
*lp_ctx
, int unused
,
124 const char *pszParmValue
, char **ptr
);
125 static bool handle_realm(struct loadparm_context
*lp_ctx
, int unused
,
126 const char *pszParmValue
, char **ptr
);
127 static bool handle_copy(struct loadparm_context
*lp_ctx
, int unused
,
128 const char *pszParmValue
, char **ptr
);
129 static bool handle_debug_list(struct loadparm_context
*lp_ctx
, int unused
,
130 const char *pszParmValue
, char **ptr
);
131 static bool handle_logfile(struct loadparm_context
*lp_ctx
, int unused
,
132 const char *pszParmValue
, char **ptr
);
134 #include "lib/param/param_table.c"
136 /* local variables */
137 struct loadparm_context
{
138 const char *szConfigFile
;
139 struct loadparm_global
*globals
;
140 struct loadparm_service
**services
;
141 struct loadparm_service
*sDefault
;
142 struct smb_iconv_handle
*iconv_handle
;
144 struct loadparm_service
*currentService
;
145 bool bInGlobalSection
;
147 struct file_lists
*next
;
152 unsigned int flags
[NUMPARAMETERS
];
155 bool global
; /* Is this the global context, which may set
156 * global variables such as debug level etc? */
157 const struct loadparm_s3_helpers
*s3_fns
;
161 struct loadparm_service
*lpcfg_default_service(struct loadparm_context
*lp_ctx
)
163 if (lp_ctx
->s3_fns
) {
164 return lp_ctx
->s3_fns
->get_default_loadparm_service();
166 return lp_ctx
->sDefault
;
170 * Convenience routine to grab string parameters into temporary memory
171 * and run standard_sub_basic on them.
173 * The buffers can be written to by
174 * callers without affecting the source string.
177 static const char *lp_string(const char *s
)
179 #if 0 /* until REWRITE done to make thread-safe */
180 size_t len
= s
? strlen(s
) : 0;
184 /* The follow debug is useful for tracking down memory problems
185 especially if you have an inner loop that is calling a lp_*()
186 function that returns a string. Perhaps this debug should be
187 present all the time? */
190 DEBUG(10, ("lp_string(%s)\n", s
));
193 #if 0 /* until REWRITE done to make thread-safe */
195 lp_talloc
= talloc_init("lp_talloc");
197 ret
= talloc_array(lp_talloc
, char, len
+ 100); /* leave room for substitution */
205 strlcpy(ret
, s
, len
);
207 if (trim_string(ret
, "\"", "\"")) {
208 if (strchr(ret
,'"') != NULL
)
209 strlcpy(ret
, s
, len
);
212 standard_sub_basic(ret
,len
+100);
219 In this section all the functions that are used to access the
220 parameters from the rest of the program are defined
224 * the creation of separate lpcfg_*() and lp_*() functions is to allow
225 * for code compatibility between existing Samba4 and Samba3 code.
228 /* this global context supports the lp_*() function varients */
229 static struct loadparm_context
*global_loadparm_context
;
231 #define lpcfg_default_service global_loadparm_context->sDefault
232 #define lpcfg_global_service(i) global_loadparm_context->services[i]
234 #define FN_GLOBAL_STRING(fn_name,var_name) \
235 _PUBLIC_ const char *lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) {\
236 if (lp_ctx == NULL) return NULL; \
237 if (lp_ctx->s3_fns) { \
238 smb_panic( __location__ ": " #fn_name " not implemented because it is an allocated and substiuted string"); \
240 return lp_ctx->globals->var_name ? lp_string(lp_ctx->globals->var_name) : ""; \
243 #define FN_GLOBAL_CONST_STRING(fn_name,var_name) \
244 _PUBLIC_ const char *lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) { \
245 if (lp_ctx == NULL) return NULL; \
246 if (lp_ctx->s3_fns) { \
247 SMB_ASSERT(lp_ctx->s3_fns->fn_name); \
248 return lp_ctx->s3_fns->fn_name(); \
250 return lp_ctx->globals->var_name ? lp_string(lp_ctx->globals->var_name) : ""; \
253 #define FN_GLOBAL_LIST(fn_name,var_name) \
254 _PUBLIC_ const char **lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) { \
255 if (lp_ctx == NULL) return NULL; \
256 if (lp_ctx->s3_fns) { \
257 SMB_ASSERT(lp_ctx->s3_fns->fn_name); \
258 return lp_ctx->s3_fns->fn_name(); \
260 return lp_ctx->globals->var_name; \
263 #define FN_GLOBAL_BOOL(fn_name,var_name) \
264 _PUBLIC_ bool lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) {\
265 if (lp_ctx == NULL) return false; \
266 if (lp_ctx->s3_fns) { \
267 SMB_ASSERT(lp_ctx->s3_fns->fn_name); \
268 return lp_ctx->s3_fns->fn_name(); \
270 return lp_ctx->globals->var_name; \
273 #define FN_GLOBAL_INTEGER(fn_name,var_name) \
274 _PUBLIC_ int lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) { \
275 if (lp_ctx->s3_fns) { \
276 SMB_ASSERT(lp_ctx->s3_fns->fn_name); \
277 return lp_ctx->s3_fns->fn_name(); \
279 return lp_ctx->globals->var_name; \
282 /* Local parameters don't need the ->s3_fns because the struct
283 * loadparm_service is shared and lpcfg_service() checks the ->s3_fns
285 #define FN_LOCAL_STRING(fn_name,val) \
286 _PUBLIC_ const char *lpcfg_ ## fn_name(struct loadparm_service *service, \
287 struct loadparm_service *sDefault) { \
288 return(lp_string((const char *)((service != NULL && service->val != NULL) ? service->val : sDefault->val))); \
291 #define FN_LOCAL_CONST_STRING(fn_name,val) FN_LOCAL_STRING(fn_name, val)
293 #define FN_LOCAL_LIST(fn_name,val) \
294 _PUBLIC_ const char **lpcfg_ ## fn_name(struct loadparm_service *service, \
295 struct loadparm_service *sDefault) {\
296 return(const char **)(service != NULL && service->val != NULL? service->val : sDefault->val); \
299 #define FN_LOCAL_PARM_BOOL(fn_name, val) FN_LOCAL_BOOL(fn_name, val)
301 #define FN_LOCAL_BOOL(fn_name,val) \
302 _PUBLIC_ bool lpcfg_ ## fn_name(struct loadparm_service *service, \
303 struct loadparm_service *sDefault) { \
304 return((service != NULL)? service->val : sDefault->val); \
307 #define FN_LOCAL_INTEGER(fn_name,val) \
308 _PUBLIC_ int lpcfg_ ## fn_name(struct loadparm_service *service, \
309 struct loadparm_service *sDefault) { \
310 return((service != NULL)? service->val : sDefault->val); \
313 #define FN_LOCAL_PARM_INTEGER(fn_name, val) FN_LOCAL_INTEGER(fn_name, val)
315 #define FN_LOCAL_PARM_CHAR(fn_name,val) \
316 _PUBLIC_ char lpcfg_ ## fn_name(struct loadparm_service *service, \
317 struct loadparm_service *sDefault) { \
318 return((service != NULL)? service->val : sDefault->val); \
321 #include "lib/param/param_functions.c"
323 /* These functions remain only in lib/param for now */
324 FN_GLOBAL_BOOL(readraw
, bReadRaw
)
325 FN_GLOBAL_BOOL(writeraw
, bWriteRaw
)
326 FN_GLOBAL_CONST_STRING(cachedir
, szCacheDir
)
327 FN_GLOBAL_CONST_STRING(statedir
, szStateDir
)
329 /* local prototypes */
330 static int map_parameter(const char *pszParmName
);
331 static struct loadparm_service
*getservicebyname(struct loadparm_context
*lp_ctx
,
332 const char *pszServiceName
);
333 static void copy_service(struct loadparm_service
*pserviceDest
,
334 struct loadparm_service
*pserviceSource
,
335 struct bitmap
*pcopymapDest
);
336 static bool lpcfg_service_ok(struct loadparm_service
*service
);
337 static bool do_section(const char *pszSectionName
, void *);
338 static void init_copymap(struct loadparm_service
*pservice
);
340 /* This is a helper function for parametrical options support. */
341 /* It returns a pointer to parametrical option value if it exists or NULL otherwise */
342 /* Actual parametrical functions are quite simple */
343 const char *lpcfg_get_parametric(struct loadparm_context
*lp_ctx
,
344 struct loadparm_service
*service
,
345 const char *type
, const char *option
)
347 char *vfskey_tmp
= NULL
;
349 struct parmlist_entry
*data
;
354 if (lp_ctx
->s3_fns
) {
355 return lp_ctx
->s3_fns
->get_parametric(service
, type
, option
);
358 data
= (service
== NULL
? lp_ctx
->globals
->param_opt
: service
->param_opt
);
360 vfskey_tmp
= talloc_asprintf(NULL
, "%s:%s", type
, option
);
361 if (vfskey_tmp
== NULL
) return NULL
;
362 vfskey
= strlower_talloc(NULL
, vfskey_tmp
);
363 talloc_free(vfskey_tmp
);
366 if (strcmp(data
->key
, vfskey
) == 0) {
373 if (service
!= NULL
) {
374 /* Try to fetch the same option but from globals */
375 /* but only if we are not already working with globals */
376 for (data
= lp_ctx
->globals
->param_opt
; data
;
378 if (strcmp(data
->key
, vfskey
) == 0) {
392 * convenience routine to return int parameters.
394 static int lp_int(const char *s
)
398 DEBUG(0,("lp_int(%s): is called with NULL!\n",s
));
402 return strtol(s
, NULL
, 0);
406 * convenience routine to return unsigned long parameters.
408 static unsigned long lp_ulong(const char *s
)
412 DEBUG(0,("lp_ulong(%s): is called with NULL!\n",s
));
416 return strtoul(s
, NULL
, 0);
420 * convenience routine to return unsigned long parameters.
422 static long lp_long(const char *s
)
426 DEBUG(0,("lp_long(%s): is called with NULL!\n",s
));
430 return strtol(s
, NULL
, 0);
434 * convenience routine to return unsigned long parameters.
436 static double lp_double(const char *s
)
440 DEBUG(0,("lp_double(%s): is called with NULL!\n",s
));
444 return strtod(s
, NULL
);
448 * convenience routine to return boolean parameters.
450 static bool lp_bool(const char *s
)
455 DEBUG(0,("lp_bool(%s): is called with NULL!\n",s
));
459 if (!set_boolean(s
, &ret
)) {
460 DEBUG(0,("lp_bool(%s): value is not boolean!\n",s
));
469 * Return parametric option from a given service. Type is a part of option before ':'
470 * Parametric option has following syntax: 'Type: option = value'
471 * Returned value is allocated in 'lp_talloc' context
474 const char *lpcfg_parm_string(struct loadparm_context
*lp_ctx
,
475 struct loadparm_service
*service
, const char *type
,
478 const char *value
= lpcfg_get_parametric(lp_ctx
, service
, type
, option
);
481 return lp_string(value
);
487 * Return parametric option from a given service. Type is a part of option before ':'
488 * Parametric option has following syntax: 'Type: option = value'
489 * Returned value is allocated in 'lp_talloc' context
492 const char **lpcfg_parm_string_list(TALLOC_CTX
*mem_ctx
,
493 struct loadparm_context
*lp_ctx
,
494 struct loadparm_service
*service
,
496 const char *option
, const char *separator
)
498 const char *value
= lpcfg_get_parametric(lp_ctx
, service
, type
, option
);
501 return (const char **)str_list_make(mem_ctx
, value
, separator
);
507 * Return parametric option from a given service. Type is a part of option before ':'
508 * Parametric option has following syntax: 'Type: option = value'
511 int lpcfg_parm_int(struct loadparm_context
*lp_ctx
,
512 struct loadparm_service
*service
, const char *type
,
513 const char *option
, int default_v
)
515 const char *value
= lpcfg_get_parametric(lp_ctx
, service
, type
, option
);
518 return lp_int(value
);
524 * Return parametric option from a given service. Type is a part of
526 * Parametric option has following syntax: 'Type: option = value'.
529 int lpcfg_parm_bytes(struct loadparm_context
*lp_ctx
,
530 struct loadparm_service
*service
, const char *type
,
531 const char *option
, int default_v
)
535 const char *value
= lpcfg_get_parametric(lp_ctx
, service
, type
, option
);
537 if (value
&& conv_str_size_error(value
, &bval
)) {
538 if (bval
<= INT_MAX
) {
547 * Return parametric option from a given service.
548 * Type is a part of option before ':'
549 * Parametric option has following syntax: 'Type: option = value'
551 unsigned long lpcfg_parm_ulong(struct loadparm_context
*lp_ctx
,
552 struct loadparm_service
*service
, const char *type
,
553 const char *option
, unsigned long default_v
)
555 const char *value
= lpcfg_get_parametric(lp_ctx
, service
, type
, option
);
558 return lp_ulong(value
);
563 long lpcfg_parm_long(struct loadparm_context
*lp_ctx
,
564 struct loadparm_service
*service
, const char *type
,
565 const char *option
, long default_v
)
567 const char *value
= lpcfg_get_parametric(lp_ctx
, service
, type
, option
);
570 return lp_long(value
);
575 double lpcfg_parm_double(struct loadparm_context
*lp_ctx
,
576 struct loadparm_service
*service
, const char *type
,
577 const char *option
, double default_v
)
579 const char *value
= lpcfg_get_parametric(lp_ctx
, service
, type
, option
);
582 return lp_double(value
);
588 * Return parametric option from a given service. Type is a part of option before ':'
589 * Parametric option has following syntax: 'Type: option = value'
592 bool lpcfg_parm_bool(struct loadparm_context
*lp_ctx
,
593 struct loadparm_service
*service
, const char *type
,
594 const char *option
, bool default_v
)
596 const char *value
= lpcfg_get_parametric(lp_ctx
, service
, type
, option
);
599 return lp_bool(value
);
606 * Initialise a service to the defaults.
609 static struct loadparm_service
*init_service(TALLOC_CTX
*mem_ctx
, struct loadparm_service
*sDefault
)
611 struct loadparm_service
*pservice
=
612 talloc_zero(mem_ctx
, struct loadparm_service
);
613 copy_service(pservice
, sDefault
, NULL
);
618 * Set a string value, deallocating any existing space, and allocing the space
621 static bool lpcfg_string_set(TALLOC_CTX
*mem_ctx
, char **dest
, const char *src
)
628 *dest
= talloc_strdup(mem_ctx
, src
);
629 if ((*dest
) == NULL
) {
630 DEBUG(0,("Out of memory in string_set\n"));
638 * Set a string value, deallocating any existing space, and allocing the space
641 static bool lpcfg_string_set_upper(TALLOC_CTX
*mem_ctx
, char **dest
, const char *src
)
648 *dest
= strupper_talloc(mem_ctx
, src
);
649 if ((*dest
) == NULL
) {
650 DEBUG(0,("Out of memory in string_set_upper\n"));
660 * Add a new service to the services array initialising it with the given
664 struct loadparm_service
*lpcfg_add_service(struct loadparm_context
*lp_ctx
,
665 const struct loadparm_service
*pservice
,
669 struct loadparm_service tservice
;
670 int num_to_alloc
= lp_ctx
->iNumServices
+ 1;
671 struct parmlist_entry
*data
, *pdata
;
673 if (pservice
== NULL
) {
674 pservice
= lp_ctx
->sDefault
;
677 tservice
= *pservice
;
679 /* it might already exist */
681 struct loadparm_service
*service
= getservicebyname(lp_ctx
,
683 if (service
!= NULL
) {
684 /* Clean all parametric options for service */
685 /* They will be added during parsing again */
686 data
= service
->param_opt
;
692 service
->param_opt
= NULL
;
697 /* find an invalid one */
698 for (i
= 0; i
< lp_ctx
->iNumServices
; i
++)
699 if (lp_ctx
->services
[i
] == NULL
)
702 /* if not, then create one */
703 if (i
== lp_ctx
->iNumServices
) {
704 struct loadparm_service
**tsp
;
706 tsp
= talloc_realloc(lp_ctx
, lp_ctx
->services
, struct loadparm_service
*, num_to_alloc
);
709 DEBUG(0,("lpcfg_add_service: failed to enlarge services!\n"));
712 lp_ctx
->services
= tsp
;
713 lp_ctx
->services
[lp_ctx
->iNumServices
] = NULL
;
716 lp_ctx
->iNumServices
++;
719 lp_ctx
->services
[i
] = init_service(lp_ctx
->services
, lp_ctx
->sDefault
);
720 if (lp_ctx
->services
[i
] == NULL
) {
721 DEBUG(0,("lpcfg_add_service: out of memory!\n"));
724 copy_service(lp_ctx
->services
[i
], &tservice
, NULL
);
726 lpcfg_string_set(lp_ctx
->services
[i
], &lp_ctx
->services
[i
]->szService
, name
);
727 return lp_ctx
->services
[i
];
731 * Add a new home service, with the specified home directory, defaults coming
732 * from service ifrom.
735 bool lpcfg_add_home(struct loadparm_context
*lp_ctx
,
736 const char *pszHomename
,
737 struct loadparm_service
*default_service
,
738 const char *user
, const char *pszHomedir
)
740 struct loadparm_service
*service
;
742 service
= lpcfg_add_service(lp_ctx
, default_service
, pszHomename
);
747 if (!(*(default_service
->pathname
))
748 || strequal(default_service
->pathname
, lp_ctx
->sDefault
->pathname
)) {
749 service
->pathname
= talloc_strdup(service
, pszHomedir
);
751 service
->pathname
= string_sub_talloc(service
, lpcfg_pathname(default_service
, lp_ctx
->sDefault
), "%H", pszHomedir
);
754 if (!(*(service
->comment
))) {
755 service
->comment
= talloc_asprintf(service
, "Home directory of %s", user
);
757 service
->bAvailable
= default_service
->bAvailable
;
758 service
->browseable
= default_service
->browseable
;
760 DEBUG(3, ("adding home's share [%s] for user '%s' at '%s'\n",
761 pszHomename
, user
, service
->pathname
));
767 * Add a new printer service, with defaults coming from service iFrom.
770 bool lpcfg_add_printer(struct loadparm_context
*lp_ctx
,
771 const char *pszPrintername
,
772 struct loadparm_service
*default_service
)
774 const char *comment
= "From Printcap";
775 struct loadparm_service
*service
;
776 service
= lpcfg_add_service(lp_ctx
, default_service
, pszPrintername
);
781 /* note that we do NOT default the availability flag to True - */
782 /* we take it from the default service passed. This allows all */
783 /* dynamic printers to be disabled by disabling the [printers] */
784 /* entry (if/when the 'available' keyword is implemented!). */
786 /* the printer name is set to the service name. */
787 lpcfg_string_set(service
, &service
->szPrintername
, pszPrintername
);
788 lpcfg_string_set(service
, &service
->comment
, comment
);
789 service
->browseable
= default_service
->browseable
;
790 /* Printers cannot be read_only. */
791 service
->readonly
= false;
792 /* Printer services must be printable. */
793 service
->print_ok
= true;
795 DEBUG(3, ("adding printer service %s\n", pszPrintername
));
801 * Map a parameter's string representation to something we can use.
802 * Returns False if the parameter string is not recognised, else TRUE.
805 static int map_parameter(const char *pszParmName
)
809 if (*pszParmName
== '-')
812 for (iIndex
= 0; parm_table
[iIndex
].label
; iIndex
++)
813 if (strwicmp(parm_table
[iIndex
].label
, pszParmName
) == 0)
816 /* Warn only if it isn't parametric option */
817 if (strchr(pszParmName
, ':') == NULL
)
818 DEBUG(0, ("Unknown parameter encountered: \"%s\"\n", pszParmName
));
819 /* We do return 'fail' for parametric options as well because they are
820 stored in different storage
827 return the parameter structure for a parameter
829 struct parm_struct
*lpcfg_parm_struct(struct loadparm_context
*lp_ctx
, const char *name
)
833 if (lp_ctx
->s3_fns
) {
834 return lp_ctx
->s3_fns
->get_parm_struct(name
);
837 parmnum
= map_parameter(name
);
838 if (parmnum
== -1) return NULL
;
839 return &parm_table
[parmnum
];
843 return the parameter pointer for a parameter
845 void *lpcfg_parm_ptr(struct loadparm_context
*lp_ctx
,
846 struct loadparm_service
*service
, struct parm_struct
*parm
)
848 if (lp_ctx
->s3_fns
) {
849 return lp_ctx
->s3_fns
->get_parm_ptr(service
, parm
);
852 if (service
== NULL
) {
853 if (parm
->p_class
== P_LOCAL
)
854 return ((char *)lp_ctx
->sDefault
)+parm
->offset
;
855 else if (parm
->p_class
== P_GLOBAL
)
856 return ((char *)lp_ctx
->globals
)+parm
->offset
;
859 return ((char *)service
) + parm
->offset
;
864 return the parameter pointer for a parameter
866 bool lpcfg_parm_is_cmdline(struct loadparm_context
*lp_ctx
, const char *name
)
870 if (lp_ctx
->s3_fns
) {
871 struct parm_struct
*parm
= lp_ctx
->s3_fns
->get_parm_struct(name
);
873 return parm
->flags
& FLAG_CMDLINE
;
878 parmnum
= map_parameter(name
);
879 if (parmnum
== -1) return false;
881 return lp_ctx
->flags
[parmnum
] & FLAG_CMDLINE
;
885 * Find a service by name. Otherwise works like get_service.
888 static struct loadparm_service
*getservicebyname(struct loadparm_context
*lp_ctx
,
889 const char *pszServiceName
)
893 if (lp_ctx
->s3_fns
) {
894 return lp_ctx
->s3_fns
->get_service(pszServiceName
);
897 for (iService
= lp_ctx
->iNumServices
- 1; iService
>= 0; iService
--)
898 if (lp_ctx
->services
[iService
] != NULL
&&
899 strwicmp(lp_ctx
->services
[iService
]->szService
, pszServiceName
) == 0) {
900 return lp_ctx
->services
[iService
];
907 * Copy a service structure to another.
908 * If pcopymapDest is NULL then copy all fields
911 static void copy_service(struct loadparm_service
*pserviceDest
,
912 struct loadparm_service
*pserviceSource
,
913 struct bitmap
*pcopymapDest
)
916 bool bcopyall
= (pcopymapDest
== NULL
);
917 struct parmlist_entry
*data
, *pdata
, *paramo
;
920 for (i
= 0; parm_table
[i
].label
; i
++)
921 if (parm_table
[i
].p_class
== P_LOCAL
&&
922 (bcopyall
|| bitmap_query(pcopymapDest
, i
))) {
924 ((char *)pserviceSource
) + parm_table
[i
].offset
;
926 ((char *)pserviceDest
) + parm_table
[i
].offset
;
928 switch (parm_table
[i
].type
) {
930 *(bool *)dest_ptr
= *(bool *)src_ptr
;
937 *(int *)dest_ptr
= *(int *)src_ptr
;
941 *(char *)dest_ptr
= *(char *)src_ptr
;
945 lpcfg_string_set(pserviceDest
,
951 lpcfg_string_set_upper(pserviceDest
,
956 *(const char ***)dest_ptr
= (const char **)str_list_copy(pserviceDest
,
957 *(const char ***)src_ptr
);
965 init_copymap(pserviceDest
);
966 if (pserviceSource
->copymap
)
967 bitmap_copy(pserviceDest
->copymap
,
968 pserviceSource
->copymap
);
971 data
= pserviceSource
->param_opt
;
974 pdata
= pserviceDest
->param_opt
;
975 /* Traverse destination */
977 /* If we already have same option, override it */
978 if (strcmp(pdata
->key
, data
->key
) == 0) {
979 talloc_free(pdata
->value
);
980 pdata
->value
= talloc_strdup(pdata
,
988 paramo
= talloc_zero(pserviceDest
, struct parmlist_entry
);
991 paramo
->key
= talloc_strdup(paramo
, data
->key
);
992 paramo
->value
= talloc_strdup(paramo
, data
->value
);
993 DLIST_ADD(pserviceDest
->param_opt
, paramo
);
1000 * Check a service for consistency. Return False if the service is in any way
1001 * incomplete or faulty, else True.
1003 static bool lpcfg_service_ok(struct loadparm_service
*service
)
1008 if (service
->szService
[0] == '\0') {
1009 DEBUG(0, ("The following message indicates an internal error:\n"));
1010 DEBUG(0, ("No service name in service entry.\n"));
1014 /* The [printers] entry MUST be printable. I'm all for flexibility, but */
1015 /* I can't see why you'd want a non-printable printer service... */
1016 if (strwicmp(service
->szService
, PRINTERS_NAME
) == 0) {
1017 if (!service
->print_ok
) {
1018 DEBUG(0, ("WARNING: [%s] service MUST be printable!\n",
1019 service
->szService
));
1020 service
->print_ok
= true;
1022 /* [printers] service must also be non-browsable. */
1023 if (service
->browseable
)
1024 service
->browseable
= false;
1027 /* If a service is flagged unavailable, log the fact at level 0. */
1028 if (!service
->bAvailable
)
1029 DEBUG(1, ("NOTE: Service %s is flagged unavailable.\n",
1030 service
->szService
));
1036 /*******************************************************************
1037 Keep a linked list of all config files so we know when one has changed
1038 it's date and needs to be reloaded.
1039 ********************************************************************/
1041 static void add_to_file_list(struct loadparm_context
*lp_ctx
,
1042 const char *fname
, const char *subfname
)
1044 struct file_lists
*f
= lp_ctx
->file_lists
;
1047 if (f
->name
&& !strcmp(f
->name
, fname
))
1053 f
= talloc(lp_ctx
, struct file_lists
);
1056 f
->next
= lp_ctx
->file_lists
;
1057 f
->name
= talloc_strdup(f
, fname
);
1062 f
->subfname
= talloc_strdup(f
, subfname
);
1067 lp_ctx
->file_lists
= f
;
1068 f
->modtime
= file_modtime(subfname
);
1070 time_t t
= file_modtime(subfname
);
1076 /*******************************************************************
1077 Check if a config file has changed date.
1078 ********************************************************************/
1079 bool lpcfg_file_list_changed(struct loadparm_context
*lp_ctx
)
1081 struct file_lists
*f
;
1082 DEBUG(6, ("lpcfg_file_list_changed()\n"));
1084 for (f
= lp_ctx
->file_lists
; f
!= NULL
; f
= f
->next
) {
1088 n2
= standard_sub_basic(lp_ctx
, f
->name
);
1090 DEBUGADD(6, ("file %s -> %s last mod_time: %s\n",
1091 f
->name
, n2
, ctime(&f
->modtime
)));
1093 mod_time
= file_modtime(n2
);
1095 if (mod_time
&& ((f
->modtime
!= mod_time
) || (f
->subfname
== NULL
) || (strcmp(n2
, f
->subfname
) != 0))) {
1096 DEBUGADD(6, ("file %s modified: %s\n", n2
,
1098 f
->modtime
= mod_time
;
1099 talloc_free(f
->subfname
);
1100 f
->subfname
= talloc_strdup(f
, n2
);
1107 /***************************************************************************
1108 Handle the "realm" parameter
1109 ***************************************************************************/
1111 static bool handle_realm(struct loadparm_context
*lp_ctx
, int unused
,
1112 const char *pszParmValue
, char **ptr
)
1114 lpcfg_string_set(lp_ctx
, ptr
, pszParmValue
);
1116 talloc_free(lp_ctx
->globals
->realm
);
1117 talloc_free(lp_ctx
->globals
->dnsdomain
);
1119 lp_ctx
->globals
->realm
= strupper_talloc(lp_ctx
, pszParmValue
);
1120 lp_ctx
->globals
->dnsdomain
= strlower_talloc(lp_ctx
, pszParmValue
);
1125 /***************************************************************************
1126 Handle the include operation.
1127 ***************************************************************************/
1129 static bool handle_include(struct loadparm_context
*lp_ctx
, int unused
,
1130 const char *pszParmValue
, char **ptr
)
1132 char *fname
= standard_sub_basic(lp_ctx
, pszParmValue
);
1134 add_to_file_list(lp_ctx
, pszParmValue
, fname
);
1136 lpcfg_string_set(lp_ctx
, ptr
, fname
);
1138 if (file_exist(fname
))
1139 return pm_process(fname
, do_section
, do_parameter
, lp_ctx
);
1141 DEBUG(2, ("Can't find include file %s\n", fname
));
1146 /***************************************************************************
1147 Handle the interpretation of the copy parameter.
1148 ***************************************************************************/
1150 static bool handle_copy(struct loadparm_context
*lp_ctx
, int unused
,
1151 const char *pszParmValue
, char **ptr
)
1154 struct loadparm_service
*serviceTemp
;
1156 lpcfg_string_set(lp_ctx
, ptr
, pszParmValue
);
1160 DEBUG(3, ("Copying service from service %s\n", pszParmValue
));
1162 if ((serviceTemp
= getservicebyname(lp_ctx
, pszParmValue
)) != NULL
) {
1163 if (serviceTemp
== lp_ctx
->currentService
) {
1164 DEBUG(0, ("Can't copy service %s - unable to copy self!\n", pszParmValue
));
1166 copy_service(lp_ctx
->currentService
,
1168 lp_ctx
->currentService
->copymap
);
1172 DEBUG(0, ("Unable to copy service - source not found: %s\n",
1180 static bool handle_debug_list(struct loadparm_context
*lp_ctx
, int unused
,
1181 const char *pszParmValue
, char **ptr
)
1184 lpcfg_string_set(lp_ctx
, ptr
, pszParmValue
);
1185 if (lp_ctx
->global
) {
1186 return debug_parse_levels(pszParmValue
);
1191 static bool handle_logfile(struct loadparm_context
*lp_ctx
, int unused
,
1192 const char *pszParmValue
, char **ptr
)
1194 debug_set_logfile(pszParmValue
);
1195 if (lp_ctx
->global
) {
1196 lpcfg_string_set(lp_ctx
, ptr
, pszParmValue
);
1201 /***************************************************************************
1202 Initialise a copymap.
1203 ***************************************************************************/
1205 static void init_copymap(struct loadparm_service
*pservice
)
1209 TALLOC_FREE(pservice
->copymap
);
1211 pservice
->copymap
= bitmap_talloc(NULL
, NUMPARAMETERS
);
1212 if (!pservice
->copymap
)
1214 ("Couldn't allocate copymap!! (size %d)\n",
1215 (int)NUMPARAMETERS
));
1217 for (i
= 0; i
< NUMPARAMETERS
; i
++)
1218 bitmap_set(pservice
->copymap
, i
);
1222 * Process a parametric option
1224 static bool lp_do_parameter_parametric(struct loadparm_context
*lp_ctx
,
1225 struct loadparm_service
*service
,
1226 const char *pszParmName
,
1227 const char *pszParmValue
, int flags
)
1229 struct parmlist_entry
*paramo
, *data
;
1231 TALLOC_CTX
*mem_ctx
;
1233 while (isspace((unsigned char)*pszParmName
)) {
1237 name
= strlower_talloc(lp_ctx
, pszParmName
);
1238 if (!name
) return false;
1240 if (service
== NULL
) {
1241 data
= lp_ctx
->globals
->param_opt
;
1242 mem_ctx
= lp_ctx
->globals
;
1244 data
= service
->param_opt
;
1248 /* Traverse destination */
1249 for (paramo
=data
; paramo
; paramo
=paramo
->next
) {
1250 /* If we already have the option set, override it unless
1251 it was a command line option and the new one isn't */
1252 if (strcmp(paramo
->key
, name
) == 0) {
1253 if ((paramo
->priority
& FLAG_CMDLINE
) &&
1254 !(flags
& FLAG_CMDLINE
)) {
1259 talloc_free(paramo
->value
);
1260 paramo
->value
= talloc_strdup(paramo
, pszParmValue
);
1261 paramo
->priority
= flags
;
1267 paramo
= talloc_zero(mem_ctx
, struct parmlist_entry
);
1270 paramo
->key
= talloc_strdup(paramo
, name
);
1271 paramo
->value
= talloc_strdup(paramo
, pszParmValue
);
1272 paramo
->priority
= flags
;
1273 if (service
== NULL
) {
1274 DLIST_ADD(lp_ctx
->globals
->param_opt
, paramo
);
1276 DLIST_ADD(service
->param_opt
, paramo
);
1284 static bool set_variable(TALLOC_CTX
*mem_ctx
, int parmnum
, void *parm_ptr
,
1285 const char *pszParmName
, const char *pszParmValue
,
1286 struct loadparm_context
*lp_ctx
, bool on_globals
)
1289 /* if it is a special case then go ahead */
1290 if (parm_table
[parmnum
].special
) {
1292 ret
= parm_table
[parmnum
].special(lp_ctx
, -1, pszParmValue
,
1297 goto mark_non_default
;
1300 /* now switch on the type of variable it is */
1301 switch (parm_table
[parmnum
].type
)
1305 if (!set_boolean(pszParmValue
, &b
)) {
1306 DEBUG(0, ("set_variable(%s): value is not "
1307 "boolean!\n", pszParmValue
));
1310 *(bool *)parm_ptr
= b
;
1316 if (!set_boolean(pszParmValue
, &b
)) {
1317 DEBUG(0, ("set_variable(%s): value is not "
1318 "boolean!\n", pszParmValue
));
1321 *(bool *)parm_ptr
= !b
;
1326 *(int *)parm_ptr
= atoi(pszParmValue
);
1330 *(char *)parm_ptr
= *pszParmValue
;
1334 *(int *)parm_ptr
= strtol(pszParmValue
, NULL
, 8);
1340 if (conv_str_size_error(pszParmValue
, &val
)) {
1341 if (val
<= INT_MAX
) {
1342 *(int *)parm_ptr
= (int)val
;
1347 DEBUG(0, ("set_variable(%s): value is not "
1348 "a valid size specifier!\n", pszParmValue
));
1353 *(const char ***)parm_ptr
= (const char **)str_list_make(mem_ctx
,
1354 pszParmValue
, NULL
);
1358 char **new_list
= str_list_make(mem_ctx
,
1359 pszParmValue
, NULL
);
1360 for (i
=0; new_list
[i
]; i
++) {
1361 if (*(const char ***)parm_ptr
!= NULL
&&
1362 new_list
[i
][0] == '+' &&
1365 if (!str_list_check(*(const char ***)parm_ptr
,
1367 *(const char ***)parm_ptr
= str_list_add(*(const char ***)parm_ptr
,
1370 } else if (*(const char ***)parm_ptr
!= NULL
&&
1371 new_list
[i
][0] == '-' &&
1374 str_list_remove(*(const char ***)parm_ptr
,
1378 DEBUG(0, ("Unsupported list syntax for: %s = %s\n",
1379 pszParmName
, pszParmValue
));
1382 *(const char ***)parm_ptr
= (const char **) new_list
;
1389 lpcfg_string_set(mem_ctx
, (char **)parm_ptr
, pszParmValue
);
1393 lpcfg_string_set_upper(mem_ctx
, (char **)parm_ptr
, pszParmValue
);
1397 for (i
= 0; parm_table
[parmnum
].enum_list
[i
].name
; i
++) {
1400 parm_table
[parmnum
].enum_list
[i
].name
)) {
1402 parm_table
[parmnum
].
1407 if (!parm_table
[parmnum
].enum_list
[i
].name
) {
1408 DEBUG(0,("Unknown enumerated value '%s' for '%s'\n",
1409 pszParmValue
, pszParmName
));
1419 if (on_globals
&& (lp_ctx
->flags
[parmnum
] & FLAG_DEFAULT
)) {
1420 lp_ctx
->flags
[parmnum
] &= ~FLAG_DEFAULT
;
1421 /* we have to also unset FLAG_DEFAULT on aliases */
1422 for (i
=parmnum
-1;i
>=0 && parm_table
[i
].offset
== parm_table
[parmnum
].offset
;i
--) {
1423 lp_ctx
->flags
[i
] &= ~FLAG_DEFAULT
;
1425 for (i
=parmnum
+1;i
<NUMPARAMETERS
&& parm_table
[i
].offset
== parm_table
[parmnum
].offset
;i
++) {
1426 lp_ctx
->flags
[i
] &= ~FLAG_DEFAULT
;
1433 bool lpcfg_do_global_parameter(struct loadparm_context
*lp_ctx
,
1434 const char *pszParmName
, const char *pszParmValue
)
1436 int parmnum
= map_parameter(pszParmName
);
1440 if (strchr(pszParmName
, ':')) {
1441 return lp_do_parameter_parametric(lp_ctx
, NULL
, pszParmName
, pszParmValue
, 0);
1443 DEBUG(0, ("Ignoring unknown parameter \"%s\"\n", pszParmName
));
1447 /* if the flag has been set on the command line, then don't allow override,
1448 but don't report an error */
1449 if (lp_ctx
->flags
[parmnum
] & FLAG_CMDLINE
) {
1453 parm_ptr
= lpcfg_parm_ptr(lp_ctx
, NULL
, &parm_table
[parmnum
]);
1455 return set_variable(lp_ctx
->globals
, parmnum
, parm_ptr
,
1456 pszParmName
, pszParmValue
, lp_ctx
, true);
1459 bool lpcfg_do_service_parameter(struct loadparm_context
*lp_ctx
,
1460 struct loadparm_service
*service
,
1461 const char *pszParmName
, const char *pszParmValue
)
1465 int parmnum
= map_parameter(pszParmName
);
1468 if (strchr(pszParmName
, ':')) {
1469 return lp_do_parameter_parametric(lp_ctx
, service
, pszParmName
, pszParmValue
, 0);
1471 DEBUG(0, ("Ignoring unknown parameter \"%s\"\n", pszParmName
));
1475 /* if the flag has been set on the command line, then don't allow override,
1476 but don't report an error */
1477 if (lp_ctx
->flags
[parmnum
] & FLAG_CMDLINE
) {
1481 if (parm_table
[parmnum
].p_class
== P_GLOBAL
) {
1483 ("Global parameter %s found in service section!\n",
1487 parm_ptr
= ((char *)service
) + parm_table
[parmnum
].offset
;
1489 if (!service
->copymap
)
1490 init_copymap(service
);
1492 /* this handles the aliases - set the copymap for other
1493 * entries with the same data pointer */
1494 for (i
= 0; parm_table
[i
].label
; i
++)
1495 if (parm_table
[i
].offset
== parm_table
[parmnum
].offset
&&
1496 parm_table
[i
].p_class
== parm_table
[parmnum
].p_class
)
1497 bitmap_clear(service
->copymap
, i
);
1499 return set_variable(service
, parmnum
, parm_ptr
, pszParmName
,
1500 pszParmValue
, lp_ctx
, false);
1504 * Process a parameter.
1507 static bool do_parameter(const char *pszParmName
, const char *pszParmValue
,
1510 struct loadparm_context
*lp_ctx
= (struct loadparm_context
*)userdata
;
1512 if (lp_ctx
->bInGlobalSection
)
1513 return lpcfg_do_global_parameter(lp_ctx
, pszParmName
,
1516 return lpcfg_do_service_parameter(lp_ctx
, lp_ctx
->currentService
,
1517 pszParmName
, pszParmValue
);
1521 variable argument do parameter
1523 bool lpcfg_do_global_parameter_var(struct loadparm_context
*lp_ctx
, const char *pszParmName
, const char *fmt
, ...) PRINTF_ATTRIBUTE(3, 4);
1524 bool lpcfg_do_global_parameter_var(struct loadparm_context
*lp_ctx
,
1525 const char *pszParmName
, const char *fmt
, ...)
1532 s
= talloc_vasprintf(NULL
, fmt
, ap
);
1534 ret
= lpcfg_do_global_parameter(lp_ctx
, pszParmName
, s
);
1541 set a parameter from the commandline - this is called from command line parameter
1542 parsing code. It sets the parameter then marks the parameter as unable to be modified
1543 by smb.conf processing
1545 bool lpcfg_set_cmdline(struct loadparm_context
*lp_ctx
, const char *pszParmName
,
1546 const char *pszParmValue
)
1551 if (lp_ctx
->s3_fns
) {
1552 return lp_ctx
->s3_fns
->set_cmdline(pszParmName
, pszParmValue
);
1555 parmnum
= map_parameter(pszParmName
);
1557 while (isspace((unsigned char)*pszParmValue
)) pszParmValue
++;
1560 if (parmnum
< 0 && strchr(pszParmName
, ':')) {
1561 /* set a parametric option */
1562 return lp_do_parameter_parametric(lp_ctx
, NULL
, pszParmName
,
1563 pszParmValue
, FLAG_CMDLINE
);
1567 DEBUG(0,("Unknown option '%s'\n", pszParmName
));
1571 /* reset the CMDLINE flag in case this has been called before */
1572 lp_ctx
->flags
[parmnum
] &= ~FLAG_CMDLINE
;
1574 if (!lpcfg_do_global_parameter(lp_ctx
, pszParmName
, pszParmValue
)) {
1578 lp_ctx
->flags
[parmnum
] |= FLAG_CMDLINE
;
1580 /* we have to also set FLAG_CMDLINE on aliases */
1582 i
>=0 && parm_table
[i
].p_class
== parm_table
[parmnum
].p_class
&&
1583 parm_table
[i
].offset
== parm_table
[parmnum
].offset
;
1585 lp_ctx
->flags
[i
] |= FLAG_CMDLINE
;
1589 parm_table
[i
].p_class
== parm_table
[parmnum
].p_class
&&
1590 parm_table
[i
].offset
== parm_table
[parmnum
].offset
;
1592 lp_ctx
->flags
[i
] |= FLAG_CMDLINE
;
1599 set a option from the commandline in 'a=b' format. Use to support --option
1601 bool lpcfg_set_option(struct loadparm_context
*lp_ctx
, const char *option
)
1606 s
= talloc_strdup(NULL
, option
);
1619 ret
= lpcfg_set_cmdline(lp_ctx
, s
, p
+1);
1625 #define BOOLSTR(b) ((b) ? "Yes" : "No")
1628 * Print a parameter of the specified type.
1631 static void print_parameter(struct parm_struct
*p
, void *ptr
, FILE * f
)
1633 /* For the seperation of lists values that we print below */
1634 const char *list_sep
= ", ";
1639 for (i
= 0; p
->enum_list
[i
].name
; i
++) {
1640 if (*(int *)ptr
== p
->enum_list
[i
].value
) {
1642 p
->enum_list
[i
].name
);
1649 fprintf(f
, "%s", BOOLSTR(*(bool *)ptr
));
1653 fprintf(f
, "%s", BOOLSTR(!*(bool *)ptr
));
1658 fprintf(f
, "%d", *(int *)ptr
);
1662 fprintf(f
, "%c", *(char *)ptr
);
1666 int val
= *(int *)ptr
;
1670 fprintf(f
, "0%o", val
);
1679 if ((char ***)ptr
&& *(char ***)ptr
) {
1680 char **list
= *(char ***)ptr
;
1681 for (; *list
; list
++) {
1682 /* surround strings with whitespace in double quotes */
1683 if (*(list
+1) == NULL
) {
1684 /* last item, no extra separator */
1687 if ( strchr_m( *list
, ' ' ) ) {
1688 fprintf(f
, "\"%s\"%s", *list
, list_sep
);
1690 fprintf(f
, "%s%s", *list
, list_sep
);
1698 if (*(char **)ptr
) {
1699 fprintf(f
, "%s", *(char **)ptr
);
1708 * Check if two parameters are equal.
1711 static bool equal_parameter(parm_type type
, void *ptr1
, void *ptr2
)
1716 return (*((bool *)ptr1
) == *((bool *)ptr2
));
1722 return (*((int *)ptr1
) == *((int *)ptr2
));
1725 return (*((char *)ptr1
) == *((char *)ptr2
));
1729 return str_list_equal(*(const char ***)ptr1
, *(const char ***)ptr2
);
1734 char *p1
= *(char **)ptr1
, *p2
= *(char **)ptr2
;
1739 return (p1
== p2
|| strequal(p1
, p2
));
1748 * Process a new section (service).
1750 * At this stage all sections are services.
1751 * Later we'll have special sections that permit server parameters to be set.
1752 * Returns True on success, False on failure.
1755 static bool do_section(const char *pszSectionName
, void *userdata
)
1757 struct loadparm_context
*lp_ctx
= (struct loadparm_context
*)userdata
;
1759 bool isglobal
= ((strwicmp(pszSectionName
, GLOBAL_NAME
) == 0) ||
1760 (strwicmp(pszSectionName
, GLOBAL_NAME2
) == 0));
1763 /* if we've just struck a global section, note the fact. */
1764 lp_ctx
->bInGlobalSection
= isglobal
;
1766 /* check for multiple global sections */
1767 if (lp_ctx
->bInGlobalSection
) {
1768 DEBUG(4, ("Processing section \"[%s]\"\n", pszSectionName
));
1772 /* if we have a current service, tidy it up before moving on */
1775 if (lp_ctx
->currentService
!= NULL
)
1776 bRetval
= lpcfg_service_ok(lp_ctx
->currentService
);
1778 /* if all is still well, move to the next record in the services array */
1780 /* We put this here to avoid an odd message order if messages are */
1781 /* issued by the post-processing of a previous section. */
1782 DEBUG(4, ("Processing section \"[%s]\"\n", pszSectionName
));
1784 if ((lp_ctx
->currentService
= lpcfg_add_service(lp_ctx
, lp_ctx
->sDefault
,
1787 DEBUG(0, ("Failed to add a new service\n"));
1797 * Determine if a particular base parameter is currently set to the default value.
1800 static bool is_default(struct loadparm_service
*sDefault
, int i
)
1802 void *def_ptr
= ((char *)sDefault
) + parm_table
[i
].offset
;
1803 if (!defaults_saved
)
1805 switch (parm_table
[i
].type
) {
1808 return str_list_equal((const char **)parm_table
[i
].def
.lvalue
,
1809 (const char **)def_ptr
);
1812 return strequal(parm_table
[i
].def
.svalue
,
1816 return parm_table
[i
].def
.bvalue
==
1823 return parm_table
[i
].def
.ivalue
==
1832 *Display the contents of the global structure.
1835 static void dump_globals(struct loadparm_context
*lp_ctx
, FILE *f
,
1839 struct parmlist_entry
*data
;
1841 fprintf(f
, "# Global parameters\n[global]\n");
1843 for (i
= 0; parm_table
[i
].label
; i
++)
1844 if (parm_table
[i
].p_class
== P_GLOBAL
&&
1845 (i
== 0 || (parm_table
[i
].offset
!= parm_table
[i
- 1].offset
))) {
1846 if (!show_defaults
&& (lp_ctx
->flags
[i
] & FLAG_DEFAULT
))
1848 fprintf(f
, "\t%s = ", parm_table
[i
].label
);
1849 print_parameter(&parm_table
[i
], lpcfg_parm_ptr(lp_ctx
, NULL
, &parm_table
[i
]), f
);
1852 if (lp_ctx
->globals
->param_opt
!= NULL
) {
1853 for (data
= lp_ctx
->globals
->param_opt
; data
;
1854 data
= data
->next
) {
1855 if (!show_defaults
&& (data
->priority
& FLAG_DEFAULT
)) {
1858 fprintf(f
, "\t%s = %s\n", data
->key
, data
->value
);
1865 * Display the contents of a single services record.
1868 static void dump_a_service(struct loadparm_service
* pService
, struct loadparm_service
*sDefault
, FILE * f
,
1869 unsigned int *flags
)
1872 struct parmlist_entry
*data
;
1874 if (pService
!= sDefault
)
1875 fprintf(f
, "\n[%s]\n", pService
->szService
);
1877 for (i
= 0; parm_table
[i
].label
; i
++) {
1878 if (parm_table
[i
].p_class
== P_LOCAL
&&
1879 (*parm_table
[i
].label
!= '-') &&
1880 (i
== 0 || (parm_table
[i
].offset
!= parm_table
[i
- 1].offset
)))
1882 if (pService
== sDefault
) {
1883 if (flags
&& (flags
[i
] & FLAG_DEFAULT
)) {
1886 if (defaults_saved
) {
1887 if (is_default(sDefault
, i
)) {
1892 if (equal_parameter(parm_table
[i
].type
,
1893 ((char *)pService
) +
1894 parm_table
[i
].offset
,
1895 ((char *)sDefault
) +
1896 parm_table
[i
].offset
))
1900 fprintf(f
, "\t%s = ", parm_table
[i
].label
);
1901 print_parameter(&parm_table
[i
],
1902 ((char *)pService
) + parm_table
[i
].offset
, f
);
1906 if (pService
->param_opt
!= NULL
) {
1907 for (data
= pService
->param_opt
; data
; data
= data
->next
) {
1908 fprintf(f
, "\t%s = %s\n", data
->key
, data
->value
);
1913 bool lpcfg_dump_a_parameter(struct loadparm_context
*lp_ctx
,
1914 struct loadparm_service
*service
,
1915 const char *parm_name
, FILE * f
)
1917 struct parm_struct
*parm
;
1920 parm
= lpcfg_parm_struct(lp_ctx
, parm_name
);
1925 if (service
!= NULL
&& parm
->p_class
== P_GLOBAL
) {
1929 ptr
= lpcfg_parm_ptr(lp_ctx
, service
,parm
);
1931 print_parameter(parm
, ptr
, f
);
1937 * Return info about the next parameter in a service.
1938 * snum==-1 gives the globals.
1939 * Return NULL when out of parameters.
1943 struct parm_struct
*lpcfg_next_parameter(struct loadparm_context
*lp_ctx
, int snum
, int *i
,
1947 /* do the globals */
1948 for (; parm_table
[*i
].label
; (*i
)++) {
1949 if ((*parm_table
[*i
].label
== '-'))
1953 && (parm_table
[*i
].offset
==
1954 parm_table
[(*i
) - 1].offset
)
1955 && (parm_table
[*i
].p_class
==
1956 parm_table
[(*i
) - 1].p_class
))
1959 return &parm_table
[(*i
)++];
1962 struct loadparm_service
*pService
= lp_ctx
->services
[snum
];
1964 for (; parm_table
[*i
].label
; (*i
)++) {
1965 if (parm_table
[*i
].p_class
== P_LOCAL
&&
1966 (*parm_table
[*i
].label
!= '-') &&
1968 (parm_table
[*i
].offset
!=
1969 parm_table
[(*i
) - 1].offset
)))
1971 if (allparameters
||
1972 !equal_parameter(parm_table
[*i
].type
,
1973 ((char *)pService
) +
1974 parm_table
[*i
].offset
,
1975 ((char *)lp_ctx
->sDefault
) +
1976 parm_table
[*i
].offset
))
1978 return &parm_table
[(*i
)++];
1989 * Auto-load some home services.
1991 static void lpcfg_add_auto_services(struct loadparm_context
*lp_ctx
,
1999 * Unload unused services.
2002 void lpcfg_killunused(struct loadparm_context
*lp_ctx
,
2003 struct smbsrv_connection
*smb
,
2004 bool (*snumused
) (struct smbsrv_connection
*, int))
2007 for (i
= 0; i
< lp_ctx
->iNumServices
; i
++) {
2008 if (lp_ctx
->services
[i
] == NULL
)
2011 if (!snumused
|| !snumused(smb
, i
)) {
2012 talloc_free(lp_ctx
->services
[i
]);
2013 lp_ctx
->services
[i
] = NULL
;
2019 static int lpcfg_destructor(struct loadparm_context
*lp_ctx
)
2021 struct parmlist_entry
*data
;
2023 if (lp_ctx
->refuse_free
) {
2024 /* someone is trying to free the
2025 global_loadparm_context.
2026 We can't allow that. */
2030 if (lp_ctx
->globals
->param_opt
!= NULL
) {
2031 struct parmlist_entry
*next
;
2032 for (data
= lp_ctx
->globals
->param_opt
; data
; data
=next
) {
2034 if (data
->priority
& FLAG_CMDLINE
) continue;
2035 DLIST_REMOVE(lp_ctx
->globals
->param_opt
, data
);
2044 * Initialise the global parameter structure.
2046 * Note that most callers should use loadparm_init_global() instead
2048 struct loadparm_context
*loadparm_init(TALLOC_CTX
*mem_ctx
)
2052 struct loadparm_context
*lp_ctx
;
2053 struct parmlist_entry
*parm
;
2056 lp_ctx
= talloc_zero(mem_ctx
, struct loadparm_context
);
2060 talloc_set_destructor(lp_ctx
, lpcfg_destructor
);
2061 lp_ctx
->bInGlobalSection
= true;
2062 lp_ctx
->globals
= talloc_zero(lp_ctx
, struct loadparm_global
);
2063 lp_ctx
->sDefault
= talloc_zero(lp_ctx
, struct loadparm_service
);
2065 lp_ctx
->sDefault
->iMaxPrintJobs
= 1000;
2066 lp_ctx
->sDefault
->bAvailable
= true;
2067 lp_ctx
->sDefault
->browseable
= true;
2068 lp_ctx
->sDefault
->readonly
= true;
2069 lp_ctx
->sDefault
->map_archive
= true;
2070 lp_ctx
->sDefault
->strict_locking
= true;
2071 lp_ctx
->sDefault
->oplocks
= true;
2072 lp_ctx
->sDefault
->create_mask
= 0744;
2073 lp_ctx
->sDefault
->force_create_mode
= 0000;
2074 lp_ctx
->sDefault
->dir_mask
= 0755;
2075 lp_ctx
->sDefault
->force_dir_mode
= 0000;
2077 DEBUG(3, ("Initialising global parameters\n"));
2079 for (i
= 0; parm_table
[i
].label
; i
++) {
2080 if ((parm_table
[i
].type
== P_STRING
||
2081 parm_table
[i
].type
== P_USTRING
) &&
2082 !(lp_ctx
->flags
[i
] & FLAG_CMDLINE
)) {
2084 if (parm_table
[i
].p_class
== P_LOCAL
) {
2085 r
= (char **)(((char *)lp_ctx
->sDefault
) + parm_table
[i
].offset
);
2087 r
= (char **)(((char *)lp_ctx
->globals
) + parm_table
[i
].offset
);
2089 *r
= talloc_strdup(lp_ctx
, "");
2093 logfile
= talloc_asprintf(lp_ctx
, "%s/log.samba", dyn_LOGFILEBASE
);
2094 lpcfg_do_global_parameter(lp_ctx
, "log file", logfile
);
2095 talloc_free(logfile
);
2097 lpcfg_do_global_parameter(lp_ctx
, "log level", "0");
2099 lpcfg_do_global_parameter(lp_ctx
, "syslog", "1");
2100 lpcfg_do_global_parameter(lp_ctx
, "syslog only", "No");
2101 lpcfg_do_global_parameter(lp_ctx
, "debug timestamp", "Yes");
2102 lpcfg_do_global_parameter(lp_ctx
, "debug prefix timestamp", "No");
2103 lpcfg_do_global_parameter(lp_ctx
, "debug hires timestamp", "Yes");
2104 lpcfg_do_global_parameter(lp_ctx
, "debug pid", "No");
2105 lpcfg_do_global_parameter(lp_ctx
, "debug uid", "No");
2106 lpcfg_do_global_parameter(lp_ctx
, "debug class", "No");
2108 lpcfg_do_global_parameter(lp_ctx
, "share backend", "classic");
2110 lpcfg_do_global_parameter(lp_ctx
, "server role", "auto");
2111 lpcfg_do_global_parameter(lp_ctx
, "domain logons", "No");
2112 lpcfg_do_global_parameter(lp_ctx
, "domain master", "Auto");
2114 /* options that can be set on the command line must be initialised via
2115 the slower lpcfg_do_global_parameter() to ensure that FLAG_CMDLINE is obeyed */
2117 lpcfg_do_global_parameter(lp_ctx
, "socket options", "TCP_NODELAY");
2119 lpcfg_do_global_parameter(lp_ctx
, "workgroup", DEFAULT_WORKGROUP
);
2120 myname
= get_myname(lp_ctx
);
2121 lpcfg_do_global_parameter(lp_ctx
, "netbios name", myname
);
2122 talloc_free(myname
);
2123 lpcfg_do_global_parameter(lp_ctx
, "name resolve order", "wins host bcast");
2125 lpcfg_do_global_parameter(lp_ctx
, "fstype", "NTFS");
2127 lpcfg_do_global_parameter(lp_ctx
, "ntvfs handler", "unixuid default");
2128 lpcfg_do_global_parameter(lp_ctx
, "max connections", "0");
2130 lpcfg_do_global_parameter(lp_ctx
, "dcerpc endpoint servers", "epmapper wkssvc rpcecho samr netlogon lsarpc spoolss drsuapi dssetup unixinfo browser eventlog6 backupkey dnsserver");
2131 lpcfg_do_global_parameter(lp_ctx
, "server services", "s3fs rpc nbt wrepl ldap cldap kdc drepl winbind ntp_signd kcc dnsupdate dns");
2132 lpcfg_do_global_parameter(lp_ctx
, "kccsrv:samba_kcc", "true");
2133 /* the winbind method for domain controllers is for both RODC
2134 auth forwarding and for trusted domains */
2135 lpcfg_do_global_parameter(lp_ctx
, "private dir", dyn_PRIVATE_DIR
);
2136 lpcfg_do_global_parameter(lp_ctx
, "registry:HKEY_LOCAL_MACHINE", "hklm.ldb");
2138 /* This hive should be dynamically generated by Samba using
2139 data from the sam, but for the moment leave it in a tdb to
2140 keep regedt32 from popping up an annoying dialog. */
2141 lpcfg_do_global_parameter(lp_ctx
, "registry:HKEY_USERS", "hku.ldb");
2143 /* using UTF8 by default allows us to support all chars */
2144 lpcfg_do_global_parameter(lp_ctx
, "unix charset", "UTF-8");
2146 /* Use codepage 850 as a default for the dos character set */
2147 lpcfg_do_global_parameter(lp_ctx
, "dos charset", "CP850");
2150 * Allow the default PASSWD_CHAT to be overridden in local.h.
2152 lpcfg_do_global_parameter(lp_ctx
, "passwd chat", DEFAULT_PASSWD_CHAT
);
2154 lpcfg_do_global_parameter(lp_ctx
, "pid directory", dyn_PIDDIR
);
2155 lpcfg_do_global_parameter(lp_ctx
, "lock dir", dyn_LOCKDIR
);
2156 lpcfg_do_global_parameter(lp_ctx
, "state directory", dyn_STATEDIR
);
2157 lpcfg_do_global_parameter(lp_ctx
, "cache directory", dyn_CACHEDIR
);
2158 lpcfg_do_global_parameter(lp_ctx
, "ncalrpc dir", dyn_NCALRPCDIR
);
2160 lpcfg_do_global_parameter(lp_ctx
, "nbt client socket address", "0.0.0.0");
2161 lpcfg_do_global_parameter_var(lp_ctx
, "server string",
2162 "Samba %s", SAMBA_VERSION_STRING
);
2164 lpcfg_do_global_parameter(lp_ctx
, "password server", "*");
2166 lpcfg_do_global_parameter(lp_ctx
, "max mux", "50");
2167 lpcfg_do_global_parameter(lp_ctx
, "max xmit", "16644");
2168 lpcfg_do_global_parameter(lp_ctx
, "host msdfs", "true");
2170 lpcfg_do_global_parameter(lp_ctx
, "LargeReadwrite", "True");
2171 lpcfg_do_global_parameter(lp_ctx
, "server min protocol", "LANMAN1");
2172 lpcfg_do_global_parameter(lp_ctx
, "server max protocol", "NT1");
2173 lpcfg_do_global_parameter(lp_ctx
, "client min protocol", "CORE");
2174 lpcfg_do_global_parameter(lp_ctx
, "client max protocol", "NT1");
2175 lpcfg_do_global_parameter(lp_ctx
, "security", "AUTO");
2176 lpcfg_do_global_parameter(lp_ctx
, "EncryptPasswords", "True");
2177 lpcfg_do_global_parameter(lp_ctx
, "ReadRaw", "True");
2178 lpcfg_do_global_parameter(lp_ctx
, "WriteRaw", "True");
2179 lpcfg_do_global_parameter(lp_ctx
, "NullPasswords", "False");
2180 lpcfg_do_global_parameter(lp_ctx
, "ObeyPamRestrictions", "False");
2182 lpcfg_do_global_parameter(lp_ctx
, "TimeServer", "False");
2183 lpcfg_do_global_parameter(lp_ctx
, "BindInterfacesOnly", "False");
2184 lpcfg_do_global_parameter(lp_ctx
, "Unicode", "True");
2185 lpcfg_do_global_parameter(lp_ctx
, "ClientLanManAuth", "False");
2186 lpcfg_do_global_parameter(lp_ctx
, "ClientNTLMv2Auth", "True");
2187 lpcfg_do_global_parameter(lp_ctx
, "LanmanAuth", "False");
2188 lpcfg_do_global_parameter(lp_ctx
, "NTLMAuth", "True");
2189 lpcfg_do_global_parameter(lp_ctx
, "client use spnego principal", "False");
2191 lpcfg_do_global_parameter(lp_ctx
, "UnixExtensions", "True");
2193 lpcfg_do_global_parameter(lp_ctx
, "PreferredMaster", "Auto");
2194 lpcfg_do_global_parameter(lp_ctx
, "LocalMaster", "True");
2196 lpcfg_do_global_parameter(lp_ctx
, "wins support", "False");
2197 lpcfg_do_global_parameter(lp_ctx
, "dns proxy", "True");
2199 lpcfg_do_global_parameter(lp_ctx
, "winbind separator", "\\");
2200 lpcfg_do_global_parameter(lp_ctx
, "winbind sealed pipes", "True");
2201 lpcfg_do_global_parameter(lp_ctx
, "require strong key", "True");
2202 lpcfg_do_global_parameter(lp_ctx
, "winbindd socket directory", dyn_WINBINDD_SOCKET_DIR
);
2203 lpcfg_do_global_parameter(lp_ctx
, "winbindd privileged socket directory", dyn_WINBINDD_PRIVILEGED_SOCKET_DIR
);
2204 lpcfg_do_global_parameter(lp_ctx
, "ntp signd socket directory", dyn_NTP_SIGND_SOCKET_DIR
);
2205 lpcfg_do_global_parameter_var(lp_ctx
, "dns update command", "%s/samba_dnsupdate", dyn_SCRIPTSBINDIR
);
2206 lpcfg_do_global_parameter_var(lp_ctx
, "spn update command", "%s/samba_spnupdate", dyn_SCRIPTSBINDIR
);
2207 lpcfg_do_global_parameter_var(lp_ctx
, "samba kcc command",
2208 "%s/samba_kcc", dyn_SCRIPTSBINDIR
);
2209 lpcfg_do_global_parameter(lp_ctx
, "template shell", "/bin/false");
2210 lpcfg_do_global_parameter(lp_ctx
, "template homedir", "/home/%WORKGROUP%/%ACCOUNTNAME%");
2212 lpcfg_do_global_parameter(lp_ctx
, "client signing", "default");
2213 lpcfg_do_global_parameter(lp_ctx
, "server signing", "default");
2215 lpcfg_do_global_parameter(lp_ctx
, "use spnego", "True");
2217 lpcfg_do_global_parameter(lp_ctx
, "use mmap", "True");
2219 lpcfg_do_global_parameter(lp_ctx
, "smb ports", "445 139");
2220 lpcfg_do_global_parameter(lp_ctx
, "nbt port", "137");
2221 lpcfg_do_global_parameter(lp_ctx
, "dgram port", "138");
2222 lpcfg_do_global_parameter(lp_ctx
, "cldap port", "389");
2223 lpcfg_do_global_parameter(lp_ctx
, "krb5 port", "88");
2224 lpcfg_do_global_parameter(lp_ctx
, "kpasswd port", "464");
2225 lpcfg_do_global_parameter(lp_ctx
, "web port", "901");
2227 lpcfg_do_global_parameter(lp_ctx
, "nt status support", "True");
2229 lpcfg_do_global_parameter(lp_ctx
, "max wins ttl", "518400"); /* 6 days */
2230 lpcfg_do_global_parameter(lp_ctx
, "min wins ttl", "10");
2232 lpcfg_do_global_parameter(lp_ctx
, "tls enabled", "True");
2233 lpcfg_do_global_parameter(lp_ctx
, "tls keyfile", "tls/key.pem");
2234 lpcfg_do_global_parameter(lp_ctx
, "tls certfile", "tls/cert.pem");
2235 lpcfg_do_global_parameter(lp_ctx
, "tls cafile", "tls/ca.pem");
2236 lpcfg_do_global_parameter(lp_ctx
, "prefork children:smb", "4");
2238 lpcfg_do_global_parameter(lp_ctx
, "rndc command", "/usr/sbin/rndc");
2239 lpcfg_do_global_parameter(lp_ctx
, "nsupdate command", "/usr/bin/nsupdate -g");
2241 lpcfg_do_global_parameter(lp_ctx
, "allow dns updates", "secure only");
2242 lpcfg_do_global_parameter(lp_ctx
, "dns forwarder", "");
2244 lpcfg_do_global_parameter(lp_ctx
, "algorithmic rid base", "1000");
2246 lpcfg_do_global_parameter(lp_ctx
, "enhanced browsing", "True");
2248 lpcfg_do_global_parameter(lp_ctx
, "winbind nss info", "template");
2250 lpcfg_do_global_parameter(lp_ctx
, "server schannel", "Auto");
2252 lpcfg_do_global_parameter(lp_ctx
, "short preserve case", "True");
2254 lpcfg_do_global_parameter(lp_ctx
, "max open files", "16384");
2256 lpcfg_do_global_parameter(lp_ctx
, "cups connection timeout", "30");
2258 lpcfg_do_global_parameter(lp_ctx
, "locking", "True");
2260 lpcfg_do_global_parameter(lp_ctx
, "block size", "1024");
2262 lpcfg_do_global_parameter(lp_ctx
, "client use spnego", "True");
2264 lpcfg_do_global_parameter(lp_ctx
, "change notify", "True");
2266 lpcfg_do_global_parameter(lp_ctx
, "name cache timeout", "660");
2268 lpcfg_do_global_parameter(lp_ctx
, "defer sharing violations", "True");
2270 lpcfg_do_global_parameter(lp_ctx
, "ldap replication sleep", "1000");
2272 lpcfg_do_global_parameter(lp_ctx
, "idmap backend", "tdb");
2274 lpcfg_do_global_parameter(lp_ctx
, "enable privileges", "True");
2276 lpcfg_do_global_parameter(lp_ctx
, "smb2 max write", "1048576");
2278 lpcfg_do_global_parameter(lp_ctx
, "passdb backend", "tdbsam");
2280 lpcfg_do_global_parameter(lp_ctx
, "getwd cache", "True");
2282 lpcfg_do_global_parameter(lp_ctx
, "winbind nested groups", "True");
2284 lpcfg_do_global_parameter(lp_ctx
, "mangled names", "True");
2286 lpcfg_do_global_parameter(lp_ctx
, "smb2 max credits", "8192");
2288 lpcfg_do_global_parameter(lp_ctx
, "ldap ssl", "start tls");
2290 lpcfg_do_global_parameter(lp_ctx
, "ldap deref", "auto");
2292 lpcfg_do_global_parameter(lp_ctx
, "lm interval", "60");
2294 lpcfg_do_global_parameter(lp_ctx
, "mangling method", "hash2");
2296 lpcfg_do_global_parameter(lp_ctx
, "hide dot files", "True");
2298 lpcfg_do_global_parameter(lp_ctx
, "browse list", "True");
2300 lpcfg_do_global_parameter(lp_ctx
, "passwd chat timeout", "2");
2302 lpcfg_do_global_parameter(lp_ctx
, "guest account", GUEST_ACCOUNT
);
2304 lpcfg_do_global_parameter(lp_ctx
, "client schannel", "auto");
2306 lpcfg_do_global_parameter(lp_ctx
, "smb encrypt", "default");
2308 lpcfg_do_global_parameter(lp_ctx
, "max log size", "5000");
2310 lpcfg_do_global_parameter(lp_ctx
, "idmap negative cache time", "120");
2312 lpcfg_do_global_parameter(lp_ctx
, "ldap follow referral", "auto");
2314 lpcfg_do_global_parameter(lp_ctx
, "multicast dns register", "yes");
2316 lpcfg_do_global_parameter(lp_ctx
, "winbind reconnect delay", "30");
2318 lpcfg_do_global_parameter(lp_ctx
, "nt acl support", "yes");
2320 lpcfg_do_global_parameter(lp_ctx
, "acl check permissions", "yes");
2322 lpcfg_do_global_parameter(lp_ctx
, "keepalive", "300");
2324 lpcfg_do_global_parameter(lp_ctx
, "winbind cache time", "300");
2326 lpcfg_do_global_parameter(lp_ctx
, "level2 oplocks", "yes");
2328 lpcfg_do_global_parameter(lp_ctx
, "show add printer wizard", "yes");
2330 lpcfg_do_global_parameter(lp_ctx
, "allocation roundup size", "1048576");
2332 lpcfg_do_global_parameter(lp_ctx
, "ldap page size", "1024");
2334 lpcfg_do_global_parameter(lp_ctx
, "kernel share modes", "yes");
2336 lpcfg_do_global_parameter(lp_ctx
, "strict locking", "Auto");
2338 lpcfg_do_global_parameter(lp_ctx
, "map readonly", "yes");
2340 lpcfg_do_global_parameter(lp_ctx
, "allow trusted domains", "yes");
2342 lpcfg_do_global_parameter(lp_ctx
, "default devmode", "yes");
2344 lpcfg_do_global_parameter(lp_ctx
, "os level", "20");
2346 lpcfg_do_global_parameter(lp_ctx
, "dos filetimes", "yes");
2348 lpcfg_do_global_parameter(lp_ctx
, "mangling char", "~");
2350 lpcfg_do_global_parameter(lp_ctx
, "printcap cache time", "750");
2352 lpcfg_do_global_parameter(lp_ctx
, "create krb5 conf", "yes");
2354 lpcfg_do_global_parameter(lp_ctx
, "winbind max clients", "200");
2356 lpcfg_do_global_parameter(lp_ctx
, "acl map full control", "yes");
2358 lpcfg_do_global_parameter(lp_ctx
, "nt pipe support", "yes");
2360 lpcfg_do_global_parameter(lp_ctx
, "ldap debug threshold", "10");
2362 lpcfg_do_global_parameter(lp_ctx
, "follow symlinks", "yes");
2364 lpcfg_do_global_parameter(lp_ctx
, "machine password timeout", "604800");
2366 lpcfg_do_global_parameter(lp_ctx
, "ldap connection timeout", "2");
2368 lpcfg_do_global_parameter(lp_ctx
, "winbind expand groups", "1");
2370 lpcfg_do_global_parameter(lp_ctx
, "stat cache", "yes");
2372 lpcfg_do_global_parameter(lp_ctx
, "lpq cache time", "30");
2374 lpcfg_do_global_parameter(lp_ctx
, "smb2 max trans", "1048576");
2376 lpcfg_do_global_parameter(lp_ctx
, "smb2 max read", "1048576");
2378 lpcfg_do_global_parameter(lp_ctx
, "durable handles", "yes");
2380 lpcfg_do_global_parameter(lp_ctx
, "max stat cache size", "256");
2382 lpcfg_do_global_parameter(lp_ctx
, "ldap passwd sync", "no");
2384 lpcfg_do_global_parameter(lp_ctx
, "kernel change notify", "yes");
2386 lpcfg_do_global_parameter(lp_ctx
, "max ttl", "259200");
2388 lpcfg_do_global_parameter(lp_ctx
, "blocking locks", "yes");
2390 lpcfg_do_global_parameter(lp_ctx
, "oplock contention limit", "2");
2392 lpcfg_do_global_parameter(lp_ctx
, "load printers", "yes");
2394 lpcfg_do_global_parameter(lp_ctx
, "idmap cache time", "604800");
2396 lpcfg_do_global_parameter(lp_ctx
, "preserve case", "yes");
2398 lpcfg_do_global_parameter(lp_ctx
, "lm announce", "auto");
2400 lpcfg_do_global_parameter(lp_ctx
, "afs token lifetime", "604800");
2402 lpcfg_do_global_parameter(lp_ctx
, "enable core files", "yes");
2404 lpcfg_do_global_parameter(lp_ctx
, "winbind max domain connections", "1");
2406 lpcfg_do_global_parameter(lp_ctx
, "case sensitive", "auto");
2408 lpcfg_do_global_parameter(lp_ctx
, "ldap timeout", "15");
2410 lpcfg_do_global_parameter(lp_ctx
, "mangle prefix", "1");
2412 lpcfg_do_global_parameter(lp_ctx
, "posix locking", "yes");
2414 lpcfg_do_global_parameter(lp_ctx
, "lock spin time", "200");
2416 lpcfg_do_global_parameter(lp_ctx
, "directory name cache size", "100");
2418 lpcfg_do_global_parameter(lp_ctx
, "nmbd bind explicit broadcast", "yes");
2420 lpcfg_do_global_parameter(lp_ctx
, "init logon delay", "100");
2422 lpcfg_do_global_parameter(lp_ctx
, "usershare owner only", "yes");
2424 for (i
= 0; parm_table
[i
].label
; i
++) {
2425 if (!(lp_ctx
->flags
[i
] & FLAG_CMDLINE
)) {
2426 lp_ctx
->flags
[i
] |= FLAG_DEFAULT
;
2430 for (parm
=lp_ctx
->globals
->param_opt
; parm
; parm
=parm
->next
) {
2431 if (!(parm
->priority
& FLAG_CMDLINE
)) {
2432 parm
->priority
|= FLAG_DEFAULT
;
2440 * Initialise the global parameter structure.
2442 struct loadparm_context
*loadparm_init_global(bool load_default
)
2444 if (global_loadparm_context
== NULL
) {
2445 global_loadparm_context
= loadparm_init(NULL
);
2447 if (global_loadparm_context
== NULL
) {
2450 global_loadparm_context
->global
= true;
2451 if (load_default
&& !global_loadparm_context
->loaded
) {
2452 lpcfg_load_default(global_loadparm_context
);
2454 global_loadparm_context
->refuse_free
= true;
2455 return global_loadparm_context
;
2459 * Initialise the global parameter structure.
2461 struct loadparm_context
*loadparm_init_s3(TALLOC_CTX
*mem_ctx
,
2462 const struct loadparm_s3_helpers
*s3_fns
)
2464 struct loadparm_context
*loadparm_context
= talloc_zero(mem_ctx
, struct loadparm_context
);
2465 if (!loadparm_context
) {
2468 loadparm_context
->s3_fns
= s3_fns
;
2469 return loadparm_context
;
2472 const char *lpcfg_configfile(struct loadparm_context
*lp_ctx
)
2474 return lp_ctx
->szConfigFile
;
2477 const char *lp_default_path(void)
2479 if (getenv("SMB_CONF_PATH"))
2480 return getenv("SMB_CONF_PATH");
2482 return dyn_CONFIGFILE
;
2486 * Update the internal state of a loadparm context after settings
2489 static bool lpcfg_update(struct loadparm_context
*lp_ctx
)
2491 struct debug_settings settings
;
2492 lpcfg_add_auto_services(lp_ctx
, lpcfg_auto_services(lp_ctx
));
2494 if (!lp_ctx
->globals
->wins_server_list
&& lp_ctx
->globals
->we_are_a_wins_server
) {
2495 lpcfg_do_global_parameter(lp_ctx
, "wins server", "127.0.0.1");
2498 if (!lp_ctx
->global
) {
2502 panic_action
= lp_ctx
->globals
->panic_action
;
2504 reload_charcnv(lp_ctx
);
2506 ZERO_STRUCT(settings
);
2507 /* Add any more debug-related smb.conf parameters created in
2509 settings
.syslog
= lp_ctx
->globals
->syslog
;
2510 settings
.syslog_only
= lp_ctx
->globals
->syslog_only
;
2511 settings
.timestamp_logs
= lp_ctx
->globals
->timestamp_logs
;
2512 settings
.debug_prefix_timestamp
= lp_ctx
->globals
->debug_prefix_timestamp
;
2513 settings
.debug_hires_timestamp
= lp_ctx
->globals
->debug_hires_timestamp
;
2514 settings
.debug_pid
= lp_ctx
->globals
->debug_pid
;
2515 settings
.debug_uid
= lp_ctx
->globals
->debug_uid
;
2516 settings
.debug_class
= lp_ctx
->globals
->debug_class
;
2517 debug_set_settings(&settings
);
2519 /* FIXME: This is a bit of a hack, but we can't use a global, since
2520 * not everything that uses lp also uses the socket library */
2521 if (lpcfg_parm_bool(lp_ctx
, NULL
, "socket", "testnonblock", false)) {
2522 setenv("SOCKET_TESTNONBLOCK", "1", 1);
2524 unsetenv("SOCKET_TESTNONBLOCK");
2530 bool lpcfg_load_default(struct loadparm_context
*lp_ctx
)
2534 path
= lp_default_path();
2536 if (!file_exist(path
)) {
2537 /* We allow the default smb.conf file to not exist,
2538 * basically the equivalent of an empty file. */
2539 return lpcfg_update(lp_ctx
);
2542 return lpcfg_load(lp_ctx
, path
);
2546 * Load the services array from the services file.
2548 * Return True on success, False on failure.
2550 bool lpcfg_load(struct loadparm_context
*lp_ctx
, const char *filename
)
2555 filename
= talloc_strdup(lp_ctx
, filename
);
2557 lp_ctx
->szConfigFile
= filename
;
2559 if (lp_ctx
->s3_fns
) {
2560 return lp_ctx
->s3_fns
->load(filename
);
2563 lp_ctx
->bInGlobalSection
= true;
2564 n2
= standard_sub_basic(lp_ctx
, lp_ctx
->szConfigFile
);
2565 DEBUG(2, ("lpcfg_load: refreshing parameters from %s\n", n2
));
2567 add_to_file_list(lp_ctx
, lp_ctx
->szConfigFile
, n2
);
2569 /* We get sections first, so have to start 'behind' to make up */
2570 lp_ctx
->currentService
= NULL
;
2571 bRetval
= pm_process(n2
, do_section
, do_parameter
, lp_ctx
);
2573 /* finish up the last section */
2574 DEBUG(4, ("pm_process() returned %s\n", BOOLSTR(bRetval
)));
2576 if (lp_ctx
->currentService
!= NULL
)
2577 bRetval
= lpcfg_service_ok(lp_ctx
->currentService
);
2579 bRetval
= bRetval
&& lpcfg_update(lp_ctx
);
2581 /* we do this unconditionally, so that it happens even
2582 for a missing smb.conf */
2583 reload_charcnv(lp_ctx
);
2585 if (bRetval
== true) {
2586 /* set this up so that any child python tasks will
2587 find the right smb.conf */
2588 setenv("SMB_CONF_PATH", filename
, 1);
2590 /* set the context used by the lp_*() function
2592 global_loadparm_context
= lp_ctx
;
2593 lp_ctx
->loaded
= true;
2600 * Return the max number of services.
2603 int lpcfg_numservices(struct loadparm_context
*lp_ctx
)
2605 if (lp_ctx
->s3_fns
) {
2606 return lp_ctx
->s3_fns
->get_numservices();
2609 return lp_ctx
->iNumServices
;
2613 * Display the contents of the services array in human-readable form.
2616 void lpcfg_dump(struct loadparm_context
*lp_ctx
, FILE *f
, bool show_defaults
,
2621 if (lp_ctx
->s3_fns
) {
2622 lp_ctx
->s3_fns
->dump(f
, show_defaults
, maxtoprint
);
2626 defaults_saved
= !show_defaults
;
2628 dump_globals(lp_ctx
, f
, show_defaults
);
2630 dump_a_service(lp_ctx
->sDefault
, lp_ctx
->sDefault
, f
, lp_ctx
->flags
);
2632 for (iService
= 0; iService
< maxtoprint
; iService
++)
2633 lpcfg_dump_one(f
, show_defaults
, lp_ctx
->services
[iService
], lp_ctx
->sDefault
);
2637 * Display the contents of one service in human-readable form.
2639 void lpcfg_dump_one(FILE *f
, bool show_defaults
, struct loadparm_service
*service
, struct loadparm_service
*sDefault
)
2641 if (service
!= NULL
) {
2642 if (service
->szService
[0] == '\0')
2644 dump_a_service(service
, sDefault
, f
, NULL
);
2648 struct loadparm_service
*lpcfg_servicebynum(struct loadparm_context
*lp_ctx
,
2651 if (lp_ctx
->s3_fns
) {
2652 return lp_ctx
->s3_fns
->get_servicebynum(snum
);
2655 return lp_ctx
->services
[snum
];
2658 struct loadparm_service
*lpcfg_service(struct loadparm_context
*lp_ctx
,
2659 const char *service_name
)
2664 if (lp_ctx
->s3_fns
) {
2665 return lp_ctx
->s3_fns
->get_service(service_name
);
2668 for (iService
= lp_ctx
->iNumServices
- 1; iService
>= 0; iService
--) {
2669 if (lp_ctx
->services
[iService
] &&
2670 lp_ctx
->services
[iService
]->szService
) {
2672 * The substitution here is used to support %U is
2675 serviceName
= standard_sub_basic(
2676 lp_ctx
->services
[iService
],
2677 lp_ctx
->services
[iService
]->szService
);
2678 if (strequal(serviceName
, service_name
)) {
2679 talloc_free(serviceName
);
2680 return lp_ctx
->services
[iService
];
2682 talloc_free(serviceName
);
2686 DEBUG(7,("lpcfg_servicenumber: couldn't find %s\n", service_name
));
2690 const char *lpcfg_servicename(const struct loadparm_service
*service
)
2692 return lp_string((const char *)service
->szService
);
2696 * A useful volume label function.
2698 const char *lpcfg_volume_label(struct loadparm_service
*service
, struct loadparm_service
*sDefault
)
2701 ret
= lp_string((const char *)((service
!= NULL
&& service
->volume
!= NULL
) ?
2702 service
->volume
: sDefault
->volume
));
2704 return lpcfg_servicename(service
);
2709 * If we are PDC then prefer us as DMB
2711 const char *lpcfg_printername(struct loadparm_service
*service
, struct loadparm_service
*sDefault
)
2714 ret
= lp_string((const char *)((service
!= NULL
&& service
->szPrintername
!= NULL
) ?
2715 service
->szPrintername
: sDefault
->szPrintername
));
2716 if (ret
== NULL
|| (ret
!= NULL
&& *ret
== '\0'))
2717 ret
= lpcfg_servicename(service
);
2724 * Return the max print jobs per queue.
2726 int lpcfg_maxprintjobs(struct loadparm_service
*service
, struct loadparm_service
*sDefault
)
2728 int maxjobs
= (service
!= NULL
) ? service
->iMaxPrintJobs
: sDefault
->iMaxPrintJobs
;
2729 if (maxjobs
<= 0 || maxjobs
>= PRINT_MAX_JOBID
)
2730 maxjobs
= PRINT_MAX_JOBID
- 1;
2735 struct smb_iconv_handle
*lpcfg_iconv_handle(struct loadparm_context
*lp_ctx
)
2737 if (lp_ctx
== NULL
) {
2738 return get_iconv_handle();
2740 return lp_ctx
->iconv_handle
;
2743 _PUBLIC_
void reload_charcnv(struct loadparm_context
*lp_ctx
)
2745 struct smb_iconv_handle
*old_ic
= lp_ctx
->iconv_handle
;
2746 if (!lp_ctx
->global
) {
2750 if (old_ic
== NULL
) {
2751 old_ic
= global_iconv_handle
;
2753 lp_ctx
->iconv_handle
= smb_iconv_handle_reinit_lp(lp_ctx
, lp_ctx
, old_ic
);
2754 global_iconv_handle
= lp_ctx
->iconv_handle
;
2757 _PUBLIC_
char *lpcfg_tls_keyfile(TALLOC_CTX
*mem_ctx
, struct loadparm_context
*lp_ctx
)
2759 return lpcfg_private_path(mem_ctx
, lp_ctx
, lp_ctx
->globals
->tls_keyfile
);
2762 _PUBLIC_
char *lpcfg_tls_certfile(TALLOC_CTX
*mem_ctx
, struct loadparm_context
*lp_ctx
)
2764 return lpcfg_private_path(mem_ctx
, lp_ctx
, lp_ctx
->globals
->tls_certfile
);
2767 _PUBLIC_
char *lpcfg_tls_cafile(TALLOC_CTX
*mem_ctx
, struct loadparm_context
*lp_ctx
)
2769 return lpcfg_private_path(mem_ctx
, lp_ctx
, lp_ctx
->globals
->tls_cafile
);
2772 _PUBLIC_
char *lpcfg_tls_crlfile(TALLOC_CTX
*mem_ctx
, struct loadparm_context
*lp_ctx
)
2774 return lpcfg_private_path(mem_ctx
, lp_ctx
, lp_ctx
->globals
->tls_crlfile
);
2777 _PUBLIC_
char *lpcfg_tls_dhpfile(TALLOC_CTX
*mem_ctx
, struct loadparm_context
*lp_ctx
)
2779 return lpcfg_private_path(mem_ctx
, lp_ctx
, lp_ctx
->globals
->tls_dhpfile
);
2782 struct gensec_settings
*lpcfg_gensec_settings(TALLOC_CTX
*mem_ctx
, struct loadparm_context
*lp_ctx
)
2784 struct gensec_settings
*settings
= talloc_zero(mem_ctx
, struct gensec_settings
);
2785 if (settings
== NULL
)
2787 SMB_ASSERT(lp_ctx
!= NULL
);
2788 settings
->lp_ctx
= talloc_reference(settings
, lp_ctx
);
2789 settings
->target_hostname
= lpcfg_parm_string(lp_ctx
, NULL
, "gensec", "target_hostname");
2793 int lpcfg_server_role(struct loadparm_context
*lp_ctx
)
2795 int domain_master
= lpcfg__domain_master(lp_ctx
);
2797 return lp_find_server_role(lpcfg__server_role(lp_ctx
),
2798 lpcfg__security(lp_ctx
),
2799 lpcfg__domain_logons(lp_ctx
),
2800 (domain_master
== true) ||
2801 (domain_master
== Auto
));
2804 int lpcfg_security(struct loadparm_context
*lp_ctx
)
2806 return lp_find_security(lpcfg__server_role(lp_ctx
),
2807 lpcfg__security(lp_ctx
));
2810 bool lpcfg_server_signing_allowed(struct loadparm_context
*lp_ctx
, bool *mandatory
)
2812 bool allowed
= true;
2813 enum smb_signing_setting signing_setting
= lpcfg_server_signing(lp_ctx
);
2817 if (signing_setting
== SMB_SIGNING_DEFAULT
) {
2819 * If we are a domain controller, SMB signing is
2820 * really important, as it can prevent a number of
2821 * attacks on communications between us and the
2824 * However, it really sucks (no sendfile, CPU
2825 * overhead) performance-wise when used on a
2826 * file server, so disable it by default
2830 if (lpcfg_server_role(lp_ctx
) >= ROLE_ACTIVE_DIRECTORY_DC
) {
2831 signing_setting
= SMB_SIGNING_REQUIRED
;
2833 signing_setting
= SMB_SIGNING_OFF
;
2837 switch (signing_setting
) {
2838 case SMB_SIGNING_REQUIRED
:
2841 case SMB_SIGNING_IF_REQUIRED
:
2843 case SMB_SIGNING_DEFAULT
:
2844 case SMB_SIGNING_OFF
: