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 #include "librpc/gen_ndr/nbt.h"
71 #include "libds/common/roles.h"
73 #ifdef HAVE_HTTPCONNECTENCRYPT
74 #include <cups/http.h>
77 #define standard_sub_basic talloc_strdup
79 #include "lib/param/param_global.h"
81 struct loadparm_service
*lpcfg_default_service(struct loadparm_context
*lp_ctx
)
83 return lp_ctx
->sDefault
;
87 * Convenience routine to grab string parameters into temporary memory
88 * and run standard_sub_basic on them.
90 * The buffers can be written to by
91 * callers without affecting the source string.
94 static const char *lpcfg_string(const char *s
)
96 #if 0 /* until REWRITE done to make thread-safe */
97 size_t len
= s
? strlen(s
) : 0;
101 /* The follow debug is useful for tracking down memory problems
102 especially if you have an inner loop that is calling a lp_*()
103 function that returns a string. Perhaps this debug should be
104 present all the time? */
107 DEBUG(10, ("lpcfg_string(%s)\n", s
));
110 #if 0 /* until REWRITE done to make thread-safe */
112 lp_talloc
= talloc_init("lp_talloc");
114 ret
= talloc_array(lp_talloc
, char, len
+ 100); /* leave room for substitution */
122 strlcpy(ret
, s
, len
);
124 if (trim_string(ret
, "\"", "\"")) {
125 if (strchr(ret
,'"') != NULL
)
126 strlcpy(ret
, s
, len
);
129 standard_sub_basic(ret
,len
+100);
136 In this section all the functions that are used to access the
137 parameters from the rest of the program are defined
141 * the creation of separate lpcfg_*() and lp_*() functions is to allow
142 * for code compatibility between existing Samba4 and Samba3 code.
145 /* this global context supports the lp_*() function varients */
146 static struct loadparm_context
*global_loadparm_context
;
148 #define FN_GLOBAL_STRING(fn_name,var_name) \
149 _PUBLIC_ char *lpcfg_ ## fn_name(struct loadparm_context *lp_ctx, TALLOC_CTX *ctx) {\
150 if (lp_ctx == NULL) return NULL; \
151 if (lp_ctx->s3_fns) { \
152 return lp_ctx->globals->var_name ? lp_ctx->s3_fns->lp_string(ctx, lp_ctx->globals->var_name) : talloc_strdup(ctx, ""); \
154 return lp_ctx->globals->var_name ? talloc_strdup(ctx, lpcfg_string(lp_ctx->globals->var_name)) : talloc_strdup(ctx, ""); \
157 #define FN_GLOBAL_CONST_STRING(fn_name,var_name) \
158 _PUBLIC_ const char *lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) { \
159 if (lp_ctx == NULL) return NULL; \
160 return lp_ctx->globals->var_name ? lpcfg_string(lp_ctx->globals->var_name) : ""; \
163 #define FN_GLOBAL_LIST(fn_name,var_name) \
164 _PUBLIC_ const char **lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) { \
165 if (lp_ctx == NULL) return NULL; \
166 return lp_ctx->globals->var_name; \
169 #define FN_GLOBAL_BOOL(fn_name,var_name) \
170 _PUBLIC_ bool lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) {\
171 if (lp_ctx == NULL) return false; \
172 return lp_ctx->globals->var_name; \
175 #define FN_GLOBAL_INTEGER(fn_name,var_name) \
176 _PUBLIC_ int lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) { \
177 return lp_ctx->globals->var_name; \
180 /* Local parameters don't need the ->s3_fns because the struct
181 * loadparm_service is shared and lpcfg_service() checks the ->s3_fns
183 #define FN_LOCAL_STRING(fn_name,val) \
184 _PUBLIC_ char *lpcfg_ ## fn_name(struct loadparm_service *service, \
185 struct loadparm_service *sDefault, TALLOC_CTX *ctx) { \
186 return(talloc_strdup(ctx, lpcfg_string((const char *)((service != NULL && service->val != NULL) ? service->val : sDefault->val)))); \
189 #define FN_LOCAL_CONST_STRING(fn_name,val) \
190 _PUBLIC_ const char *lpcfg_ ## fn_name(struct loadparm_service *service, \
191 struct loadparm_service *sDefault) { \
192 return((const char *)((service != NULL && service->val != NULL) ? service->val : sDefault->val)); \
195 #define FN_LOCAL_LIST(fn_name,val) \
196 _PUBLIC_ const char **lpcfg_ ## fn_name(struct loadparm_service *service, \
197 struct loadparm_service *sDefault) {\
198 return(const char **)(service != NULL && service->val != NULL? service->val : sDefault->val); \
201 #define FN_LOCAL_PARM_BOOL(fn_name, val) FN_LOCAL_BOOL(fn_name, val)
203 #define FN_LOCAL_BOOL(fn_name,val) \
204 _PUBLIC_ bool lpcfg_ ## fn_name(struct loadparm_service *service, \
205 struct loadparm_service *sDefault) { \
206 return((service != NULL)? service->val : sDefault->val); \
209 #define FN_LOCAL_INTEGER(fn_name,val) \
210 _PUBLIC_ int lpcfg_ ## fn_name(struct loadparm_service *service, \
211 struct loadparm_service *sDefault) { \
212 return((service != NULL)? service->val : sDefault->val); \
215 #define FN_LOCAL_PARM_INTEGER(fn_name, val) FN_LOCAL_INTEGER(fn_name, val)
217 #define FN_LOCAL_CHAR(fn_name,val) \
218 _PUBLIC_ char lpcfg_ ## fn_name(struct loadparm_service *service, \
219 struct loadparm_service *sDefault) { \
220 return((service != NULL)? service->val : sDefault->val); \
223 #define FN_LOCAL_PARM_CHAR(fn_name,val) FN_LOCAL_CHAR(fn_name, val)
225 #include "lib/param/param_functions.c"
227 /* These functions cannot be auto-generated */
228 FN_LOCAL_BOOL(autoloaded
, autoloaded
)
229 FN_GLOBAL_CONST_STRING(dnsdomain
, dnsdomain
)
231 /* local prototypes */
232 static struct loadparm_service
*lpcfg_getservicebyname(struct loadparm_context
*lp_ctx
,
233 const char *pszServiceName
);
234 static bool do_section(const char *pszSectionName
, void *);
235 static bool set_variable_helper(TALLOC_CTX
*mem_ctx
, int parmnum
, void *parm_ptr
,
236 const char *pszParmName
, const char *pszParmValue
);
237 static bool lp_do_parameter_parametric(struct loadparm_context
*lp_ctx
,
238 struct loadparm_service
*service
,
239 const char *pszParmName
,
240 const char *pszParmValue
, int flags
);
242 /* The following are helper functions for parametrical options support. */
243 /* It returns a pointer to parametrical option value if it exists or NULL otherwise */
244 /* Actual parametrical functions are quite simple */
245 struct parmlist_entry
*get_parametric_helper(struct loadparm_service
*service
,
246 const char *type
, const char *option
,
247 struct parmlist_entry
*global_opts
)
249 size_t type_len
= strlen(type
);
250 size_t option_len
= strlen(option
);
251 char param_key
[type_len
+ option_len
+ 2];
252 struct parmlist_entry
*data
= NULL
;
254 snprintf(param_key
, sizeof(param_key
), "%s:%s", type
, option
);
257 * Try to fetch the option from the data.
259 if (service
!= NULL
) {
260 data
= service
->param_opt
;
261 while (data
!= NULL
) {
262 if (strwicmp(data
->key
, param_key
) == 0) {
270 * Fall back to fetching from the globals.
273 while (data
!= NULL
) {
274 if (strwicmp(data
->key
, param_key
) == 0) {
283 const char *lpcfg_get_parametric(struct loadparm_context
*lp_ctx
,
284 struct loadparm_service
*service
,
285 const char *type
, const char *option
)
287 struct parmlist_entry
*data
;
292 data
= get_parametric_helper(service
,
293 type
, option
, lp_ctx
->globals
->param_opt
);
304 * convenience routine to return int parameters.
306 int lp_int(const char *s
)
310 DEBUG(0,("lp_int(%s): is called with NULL!\n",s
));
314 return strtol(s
, NULL
, 0);
318 * convenience routine to return unsigned long parameters.
320 unsigned long lp_ulong(const char *s
)
324 DEBUG(0,("lp_ulong(%s): is called with NULL!\n",s
));
328 return strtoul(s
, NULL
, 0);
332 * convenience routine to return unsigned long long parameters.
334 unsigned long long lp_ulonglong(const char *s
)
338 DEBUG(0, ("lp_ulonglong(%s): is called with NULL!\n", s
));
342 return strtoull(s
, NULL
, 0);
346 * convenience routine to return unsigned long parameters.
348 static long lp_long(const char *s
)
352 DEBUG(0,("lp_long(%s): is called with NULL!\n",s
));
356 return strtol(s
, NULL
, 0);
360 * convenience routine to return unsigned long parameters.
362 static double lp_double(const char *s
)
366 DEBUG(0,("lp_double(%s): is called with NULL!\n",s
));
370 return strtod(s
, NULL
);
374 * convenience routine to return boolean parameters.
376 bool lp_bool(const char *s
)
381 DEBUG(0,("lp_bool(%s): is called with NULL!\n",s
));
385 if (!set_boolean(s
, &ret
)) {
386 DEBUG(0,("lp_bool(%s): value is not boolean!\n",s
));
394 * Return parametric option from a given service. Type is a part of option before ':'
395 * Parametric option has following syntax: 'Type: option = value'
396 * Returned value is allocated in 'lp_talloc' context
399 const char *lpcfg_parm_string(struct loadparm_context
*lp_ctx
,
400 struct loadparm_service
*service
, const char *type
,
403 const char *value
= lpcfg_get_parametric(lp_ctx
, service
, type
, option
);
406 return lpcfg_string(value
);
412 * Return parametric option from a given service. Type is a part of option before ':'
413 * Parametric option has following syntax: 'Type: option = value'
414 * Returned value is allocated in 'lp_talloc' context
417 const char **lpcfg_parm_string_list(TALLOC_CTX
*mem_ctx
,
418 struct loadparm_context
*lp_ctx
,
419 struct loadparm_service
*service
,
421 const char *option
, const char *separator
)
423 const char *value
= lpcfg_get_parametric(lp_ctx
, service
, type
, option
);
426 char **l
= str_list_make(mem_ctx
, value
, separator
);
427 return discard_const_p(const char *, l
);
434 * Return parametric option from a given service. Type is a part of option before ':'
435 * Parametric option has following syntax: 'Type: option = value'
438 int lpcfg_parm_int(struct loadparm_context
*lp_ctx
,
439 struct loadparm_service
*service
, const char *type
,
440 const char *option
, int default_v
)
442 const char *value
= lpcfg_get_parametric(lp_ctx
, service
, type
, option
);
445 return lp_int(value
);
451 * Return parametric option from a given service. Type is a part of
453 * Parametric option has following syntax: 'Type: option = value'.
456 int lpcfg_parm_bytes(struct loadparm_context
*lp_ctx
,
457 struct loadparm_service
*service
, const char *type
,
458 const char *option
, int default_v
)
462 const char *value
= lpcfg_get_parametric(lp_ctx
, service
, type
, option
);
464 if (value
&& conv_str_size_error(value
, &bval
)) {
465 if (bval
<= INT_MAX
) {
474 * Return parametric option from a given service.
475 * Type is a part of option before ':'
476 * Parametric option has following syntax: 'Type: option = value'
478 unsigned long lpcfg_parm_ulong(struct loadparm_context
*lp_ctx
,
479 struct loadparm_service
*service
, const char *type
,
480 const char *option
, unsigned long default_v
)
482 const char *value
= lpcfg_get_parametric(lp_ctx
, service
, type
, option
);
485 return lp_ulong(value
);
491 * Return parametric option from a given service.
492 * Type is a part of option before ':'
493 * Parametric option has following syntax: 'Type: option = value'
495 unsigned long long lpcfg_parm_ulonglong(struct loadparm_context
*lp_ctx
,
496 struct loadparm_service
*service
,
497 const char *type
, const char *option
,
498 unsigned long long default_v
)
500 const char *value
= lpcfg_get_parametric(lp_ctx
, service
, type
, option
);
503 return lp_ulonglong(value
);
509 long lpcfg_parm_long(struct loadparm_context
*lp_ctx
,
510 struct loadparm_service
*service
, const char *type
,
511 const char *option
, long default_v
)
513 const char *value
= lpcfg_get_parametric(lp_ctx
, service
, type
, option
);
516 return lp_long(value
);
521 double lpcfg_parm_double(struct loadparm_context
*lp_ctx
,
522 struct loadparm_service
*service
, const char *type
,
523 const char *option
, double default_v
)
525 const char *value
= lpcfg_get_parametric(lp_ctx
, service
, type
, option
);
528 return lp_double(value
);
534 * Return parametric option from a given service. Type is a part of option before ':'
535 * Parametric option has following syntax: 'Type: option = value'
538 bool lpcfg_parm_bool(struct loadparm_context
*lp_ctx
,
539 struct loadparm_service
*service
, const char *type
,
540 const char *option
, bool default_v
)
542 const char *value
= lpcfg_get_parametric(lp_ctx
, service
, type
, option
);
545 return lp_bool(value
);
551 /* this is used to prevent lots of mallocs of size 1 */
552 static const char lpcfg_string_empty
[] = "";
557 void lpcfg_string_free(char **s
)
562 if (*s
== lpcfg_string_empty
) {
570 * Set a string value, deallocating any existing space, and allocing the space
573 bool lpcfg_string_set(TALLOC_CTX
*mem_ctx
, char **dest
, const char *src
)
575 lpcfg_string_free(dest
);
577 if ((src
== NULL
) || (*src
== '\0')) {
578 *dest
= discard_const_p(char, lpcfg_string_empty
);
582 *dest
= talloc_strdup(mem_ctx
, src
);
583 if ((*dest
) == NULL
) {
584 DEBUG(0,("Out of memory in string_set\n"));
592 * Set a string value, deallocating any existing space, and allocing the space
595 bool lpcfg_string_set_upper(TALLOC_CTX
*mem_ctx
, char **dest
, const char *src
)
597 lpcfg_string_free(dest
);
599 if ((src
== NULL
) || (*src
== '\0')) {
600 *dest
= discard_const_p(char, lpcfg_string_empty
);
604 *dest
= strupper_talloc(mem_ctx
, src
);
605 if ((*dest
) == NULL
) {
606 DEBUG(0,("Out of memory in string_set_upper\n"));
616 * Add a new service to the services array initialising it with the given
620 struct loadparm_service
*lpcfg_add_service(struct loadparm_context
*lp_ctx
,
621 const struct loadparm_service
*pservice
,
625 int num_to_alloc
= lp_ctx
->iNumServices
+ 1;
626 struct parmlist_entry
*data
, *pdata
;
628 if (lp_ctx
->s3_fns
!= NULL
) {
629 smb_panic("Add a service should not be called on an s3 loadparm ctx");
632 if (pservice
== NULL
) {
633 pservice
= lp_ctx
->sDefault
;
636 /* it might already exist */
638 struct loadparm_service
*service
= lpcfg_getservicebyname(lp_ctx
,
640 if (service
!= NULL
) {
641 /* Clean all parametric options for service */
642 /* They will be added during parsing again */
643 data
= service
->param_opt
;
649 service
->param_opt
= NULL
;
654 /* find an invalid one */
655 for (i
= 0; i
< lp_ctx
->iNumServices
; i
++)
656 if (lp_ctx
->services
[i
] == NULL
)
659 /* if not, then create one */
660 if (i
== lp_ctx
->iNumServices
) {
661 struct loadparm_service
**tsp
;
663 tsp
= talloc_realloc(lp_ctx
, lp_ctx
->services
, struct loadparm_service
*, num_to_alloc
);
666 DEBUG(0,("lpcfg_add_service: failed to enlarge services!\n"));
669 lp_ctx
->services
= tsp
;
670 lp_ctx
->services
[lp_ctx
->iNumServices
] = NULL
;
673 lp_ctx
->iNumServices
++;
676 lp_ctx
->services
[i
] = talloc_zero(lp_ctx
->services
, struct loadparm_service
);
677 if (lp_ctx
->services
[i
] == NULL
) {
678 DEBUG(0,("lpcfg_add_service: out of memory!\n"));
681 copy_service(lp_ctx
->services
[i
], pservice
, NULL
);
683 lpcfg_string_set(lp_ctx
->services
[i
], &lp_ctx
->services
[i
]->szService
, name
);
684 return lp_ctx
->services
[i
];
688 * Add a new home service, with the specified home directory, defaults coming
689 * from service ifrom.
692 bool lpcfg_add_home(struct loadparm_context
*lp_ctx
,
693 const char *pszHomename
,
694 struct loadparm_service
*default_service
,
695 const char *user
, const char *pszHomedir
)
697 struct loadparm_service
*service
;
699 service
= lpcfg_add_service(lp_ctx
, default_service
, pszHomename
);
704 if (!(*(default_service
->path
))
705 || strequal(default_service
->path
, lp_ctx
->sDefault
->path
)) {
706 service
->path
= talloc_strdup(service
, pszHomedir
);
708 service
->path
= string_sub_talloc(service
, lpcfg_path(default_service
, lp_ctx
->sDefault
, service
), "%H", pszHomedir
);
711 if (!(*(service
->comment
))) {
712 service
->comment
= talloc_asprintf(service
, "Home directory of %s", user
);
714 service
->available
= default_service
->available
;
715 service
->browseable
= default_service
->browseable
;
717 DEBUG(3, ("adding home's share [%s] for user '%s' at '%s'\n",
718 pszHomename
, user
, service
->path
));
724 * Add a new printer service, with defaults coming from service iFrom.
727 bool lpcfg_add_printer(struct loadparm_context
*lp_ctx
,
728 const char *pszPrintername
,
729 struct loadparm_service
*default_service
)
731 const char *comment
= "From Printcap";
732 struct loadparm_service
*service
;
733 service
= lpcfg_add_service(lp_ctx
, default_service
, pszPrintername
);
738 /* note that we do NOT default the availability flag to True - */
739 /* we take it from the default service passed. This allows all */
740 /* dynamic printers to be disabled by disabling the [printers] */
741 /* entry (if/when the 'available' keyword is implemented!). */
743 /* the printer name is set to the service name. */
744 lpcfg_string_set(service
, &service
->_printername
, pszPrintername
);
745 lpcfg_string_set(service
, &service
->comment
, comment
);
746 service
->browseable
= default_service
->browseable
;
747 /* Printers cannot be read_only. */
748 service
->read_only
= false;
749 /* Printer services must be printable. */
750 service
->printable
= true;
752 DEBUG(3, ("adding printer service %s\n", pszPrintername
));
758 * Map a parameter's string representation to something we can use.
759 * Returns False if the parameter string is not recognised, else TRUE.
762 int lpcfg_map_parameter(const char *pszParmName
)
766 for (iIndex
= 0; parm_table
[iIndex
].label
; iIndex
++)
767 if (strwicmp(parm_table
[iIndex
].label
, pszParmName
) == 0)
770 /* Warn only if it isn't parametric option */
771 if (strchr(pszParmName
, ':') == NULL
)
772 DEBUG(0, ("Unknown parameter encountered: \"%s\"\n", pszParmName
));
773 /* We do return 'fail' for parametric options as well because they are
774 stored in different storage
781 return the parameter structure for a parameter
783 struct parm_struct
*lpcfg_parm_struct(struct loadparm_context
*lp_ctx
, const char *name
)
785 int num
= lpcfg_map_parameter(name
);
791 return &parm_table
[num
];
795 return the parameter pointer for a parameter
797 void *lpcfg_parm_ptr(struct loadparm_context
*lp_ctx
,
798 struct loadparm_service
*service
, struct parm_struct
*parm
)
800 if (lp_ctx
->s3_fns
) {
801 return lp_ctx
->s3_fns
->get_parm_ptr(service
, parm
);
804 if (service
== NULL
) {
805 if (parm
->p_class
== P_LOCAL
)
806 return ((char *)lp_ctx
->sDefault
)+parm
->offset
;
807 else if (parm
->p_class
== P_GLOBAL
)
808 return ((char *)lp_ctx
->globals
)+parm
->offset
;
811 return ((char *)service
) + parm
->offset
;
816 return the parameter pointer for a parameter
818 bool lpcfg_parm_is_cmdline(struct loadparm_context
*lp_ctx
, const char *name
)
822 parmnum
= lpcfg_map_parameter(name
);
823 if (parmnum
== -1) return false;
825 return lp_ctx
->flags
[parmnum
] & FLAG_CMDLINE
;
829 * Find a service by name. Otherwise works like get_service.
832 static struct loadparm_service
*lpcfg_getservicebyname(struct loadparm_context
*lp_ctx
,
833 const char *pszServiceName
)
837 if (lp_ctx
->s3_fns
) {
838 return lp_ctx
->s3_fns
->get_service(pszServiceName
);
841 for (iService
= lp_ctx
->iNumServices
- 1; iService
>= 0; iService
--)
842 if (lp_ctx
->services
[iService
] != NULL
&&
843 strwicmp(lp_ctx
->services
[iService
]->szService
, pszServiceName
) == 0) {
844 return lp_ctx
->services
[iService
];
851 * Add a parametric option to a parmlist_entry,
852 * replacing old value, if already present.
854 void set_param_opt(TALLOC_CTX
*mem_ctx
,
855 struct parmlist_entry
**opt_list
,
856 const char *opt_name
,
857 const char *opt_value
,
860 struct parmlist_entry
*new_opt
, *opt
;
864 /* Traverse destination */
866 /* If we already have same option, override it */
867 if (strwicmp(opt
->key
, opt_name
) == 0) {
868 if ((opt
->priority
& FLAG_CMDLINE
) &&
869 !(priority
& FLAG_CMDLINE
)) {
870 /* it's been marked as not to be
874 TALLOC_FREE(opt
->list
);
875 lpcfg_string_set(opt
, &opt
->value
, opt_value
);
876 opt
->priority
= priority
;
882 new_opt
= talloc_pooled_object(
883 mem_ctx
, struct parmlist_entry
,
884 2, strlen(opt_name
) + 1 + strlen(opt_value
) + 1);
885 if (new_opt
== NULL
) {
889 lpcfg_string_set(new_opt
, &new_opt
->key
, opt_name
);
890 new_opt
->value
= NULL
;
891 lpcfg_string_set(new_opt
, &new_opt
->value
, opt_value
);
893 new_opt
->list
= NULL
;
894 new_opt
->priority
= priority
;
895 DLIST_ADD(*opt_list
, new_opt
);
899 * Copy a service structure to another.
900 * If pcopymapDest is NULL then copy all fields
903 void copy_service(struct loadparm_service
*pserviceDest
,
904 const struct loadparm_service
*pserviceSource
,
905 struct bitmap
*pcopymapDest
)
908 bool bcopyall
= (pcopymapDest
== NULL
);
909 struct parmlist_entry
*data
;
911 for (i
= 0; parm_table
[i
].label
; i
++)
912 if (parm_table
[i
].p_class
== P_LOCAL
&&
913 (bcopyall
|| bitmap_query(pcopymapDest
, i
))) {
914 const void *src_ptr
=
915 ((const char *)pserviceSource
) + parm_table
[i
].offset
;
917 ((char *)pserviceDest
) + parm_table
[i
].offset
;
919 switch (parm_table
[i
].type
) {
922 *(bool *)dest_ptr
= *(const bool *)src_ptr
;
929 *(int *)dest_ptr
= *(const int *)src_ptr
;
933 *(char *)dest_ptr
= *(const char *)src_ptr
;
937 lpcfg_string_set(pserviceDest
,
939 *(const char * const *)src_ptr
);
943 lpcfg_string_set_upper(pserviceDest
,
945 *(const char * const *)src_ptr
);
949 TALLOC_FREE(*((char ***)dest_ptr
));
950 *(char ***)dest_ptr
= str_list_copy(pserviceDest
,
951 *discard_const_p(const char **, src_ptr
));
959 init_copymap(pserviceDest
);
960 if (pserviceSource
->copymap
)
961 bitmap_copy(pserviceDest
->copymap
,
962 pserviceSource
->copymap
);
965 for (data
= pserviceSource
->param_opt
; data
!= NULL
; data
= data
->next
) {
966 set_param_opt(pserviceDest
, &pserviceDest
->param_opt
,
967 data
->key
, data
->value
, data
->priority
);
972 * Check a service for consistency. Return False if the service is in any way
973 * incomplete or faulty, else True.
975 bool lpcfg_service_ok(struct loadparm_service
*service
)
980 if (service
->szService
[0] == '\0') {
981 DEBUG(0, ("The following message indicates an internal error:\n"));
982 DEBUG(0, ("No service name in service entry.\n"));
986 /* The [printers] entry MUST be printable. I'm all for flexibility, but */
987 /* I can't see why you'd want a non-printable printer service... */
988 if (strwicmp(service
->szService
, PRINTERS_NAME
) == 0) {
989 if (!service
->printable
) {
990 DEBUG(0, ("WARNING: [%s] service MUST be printable!\n",
991 service
->szService
));
992 service
->printable
= true;
994 /* [printers] service must also be non-browsable. */
995 if (service
->browseable
)
996 service
->browseable
= false;
999 if (service
->path
[0] == '\0' &&
1000 strwicmp(service
->szService
, HOMES_NAME
) != 0 &&
1001 service
->msdfs_proxy
[0] == '\0')
1003 DEBUG(0, ("WARNING: No path in service %s - making it unavailable!\n",
1004 service
->szService
));
1005 service
->available
= false;
1008 if (!service
->available
)
1009 DEBUG(1, ("NOTE: Service %s is flagged unavailable.\n",
1010 service
->szService
));
1016 /*******************************************************************
1017 Keep a linked list of all config files so we know when one has changed
1018 it's date and needs to be reloaded.
1019 ********************************************************************/
1021 void add_to_file_list(TALLOC_CTX
*mem_ctx
, struct file_lists
**list
,
1022 const char *fname
, const char *subfname
)
1024 struct file_lists
*f
= *list
;
1027 if (f
->name
&& !strcmp(f
->name
, fname
))
1033 f
= talloc(mem_ctx
, struct file_lists
);
1037 f
->name
= talloc_strdup(f
, fname
);
1042 f
->subfname
= talloc_strdup(f
, subfname
);
1048 f
->modtime
= file_modtime(subfname
);
1050 time_t t
= file_modtime(subfname
);
1057 DEBUG(0, ("Unable to add file to file list: %s\n", fname
));
1061 /*******************************************************************
1062 Check if a config file has changed date.
1063 ********************************************************************/
1064 bool lpcfg_file_list_changed(struct loadparm_context
*lp_ctx
)
1066 struct file_lists
*f
;
1067 DEBUG(6, ("lpcfg_file_list_changed()\n"));
1069 for (f
= lp_ctx
->file_lists
; f
!= NULL
; f
= f
->next
) {
1073 n2
= standard_sub_basic(lp_ctx
, f
->name
);
1075 DEBUGADD(6, ("file %s -> %s last mod_time: %s\n",
1076 f
->name
, n2
, ctime(&f
->modtime
)));
1078 mod_time
= file_modtime(n2
);
1080 if (mod_time
&& ((f
->modtime
!= mod_time
) || (f
->subfname
== NULL
) || (strcmp(n2
, f
->subfname
) != 0))) {
1081 DEBUGADD(6, ("file %s modified: %s\n", n2
,
1083 f
->modtime
= mod_time
;
1084 talloc_free(f
->subfname
);
1085 f
->subfname
= talloc_strdup(f
, n2
);
1095 * set the value for a P_ENUM
1097 bool lp_set_enum_parm( struct parm_struct
*parm
, const char *pszParmValue
,
1102 for (i
= 0; parm
->enum_list
[i
].name
; i
++) {
1103 if (strwicmp(pszParmValue
, parm
->enum_list
[i
].name
) == 0) {
1104 *ptr
= parm
->enum_list
[i
].value
;
1108 DEBUG(0, ("WARNING: Ignoring invalid value '%s' for parameter '%s'\n",
1109 pszParmValue
, parm
->label
));
1114 /***************************************************************************
1115 Handle the "realm" parameter
1116 ***************************************************************************/
1118 bool handle_realm(struct loadparm_context
*lp_ctx
, struct loadparm_service
*service
,
1119 const char *pszParmValue
, char **ptr
)
1124 upper
= strupper_talloc(lp_ctx
, pszParmValue
);
1125 if (upper
== NULL
) {
1129 lower
= strlower_talloc(lp_ctx
, pszParmValue
);
1130 if (lower
== NULL
) {
1135 lpcfg_string_set(lp_ctx
->globals
->ctx
, &lp_ctx
->globals
->realm_original
, pszParmValue
);
1136 lpcfg_string_set(lp_ctx
->globals
->ctx
, &lp_ctx
->globals
->realm
, upper
);
1137 lpcfg_string_set(lp_ctx
->globals
->ctx
, &lp_ctx
->globals
->dnsdomain
, lower
);
1142 /***************************************************************************
1143 Handle the include operation.
1144 ***************************************************************************/
1146 bool handle_include(struct loadparm_context
*lp_ctx
, struct loadparm_service
*service
,
1147 const char *pszParmValue
, char **ptr
)
1150 const char *substitution_variable_substring
;
1153 if (lp_ctx
->s3_fns
) {
1154 return lp_ctx
->s3_fns
->lp_include(lp_ctx
, service
, pszParmValue
, ptr
);
1157 fname
= standard_sub_basic(lp_ctx
, pszParmValue
);
1159 add_to_file_list(lp_ctx
, &lp_ctx
->file_lists
, pszParmValue
, fname
);
1161 lpcfg_string_set(lp_ctx
, ptr
, fname
);
1163 if (file_exist(fname
))
1164 return pm_process(fname
, do_section
, lpcfg_do_parameter
, lp_ctx
);
1167 * If the file doesn't exist, we check that it isn't due to variable
1170 substitution_variable_substring
= strchr(fname
, '%');
1172 if (substitution_variable_substring
!= NULL
) {
1173 next_char
= substitution_variable_substring
[1];
1174 if ((next_char
>= 'a' && next_char
<= 'z')
1175 || (next_char
>= 'A' && next_char
<= 'Z')) {
1176 DEBUG(2, ("Tried to load %s but variable substitution in "
1177 "filename, ignoring file.\n", fname
));
1182 DEBUG(2, ("Can't find include file %s\n", fname
));
1187 /***************************************************************************
1188 Handle the interpretation of the copy parameter.
1189 ***************************************************************************/
1191 bool handle_copy(struct loadparm_context
*lp_ctx
, struct loadparm_service
*service
,
1192 const char *pszParmValue
, char **ptr
)
1195 struct loadparm_service
*serviceTemp
= NULL
;
1199 DEBUG(3, ("Copying service from service %s\n", pszParmValue
));
1201 serviceTemp
= lpcfg_getservicebyname(lp_ctx
, pszParmValue
);
1203 if (service
== NULL
) {
1204 DEBUG(0, ("Unable to copy service - invalid service destination.\n"));
1208 if (serviceTemp
!= NULL
) {
1209 if (serviceTemp
== service
) {
1210 DEBUG(0, ("Can't copy service %s - unable to copy self!\n", pszParmValue
));
1212 copy_service(service
,
1215 lpcfg_string_set(service
, ptr
, pszParmValue
);
1220 DEBUG(0, ("Unable to copy service - source not found: %s\n",
1228 bool handle_debug_list(struct loadparm_context
*lp_ctx
, struct loadparm_service
*service
,
1229 const char *pszParmValue
, char **ptr
)
1231 lpcfg_string_set(lp_ctx
->globals
->ctx
, ptr
, pszParmValue
);
1233 return debug_parse_levels(pszParmValue
);
1236 bool handle_logfile(struct loadparm_context
*lp_ctx
, struct loadparm_service
*service
,
1237 const char *pszParmValue
, char **ptr
)
1239 if (lp_ctx
->s3_fns
== NULL
) {
1240 debug_set_logfile(pszParmValue
);
1243 lpcfg_string_set(lp_ctx
->globals
->ctx
, ptr
, pszParmValue
);
1249 * These special charset handling methods only run in the source3 code.
1252 bool handle_charset(struct loadparm_context
*lp_ctx
, struct loadparm_service
*service
,
1253 const char *pszParmValue
, char **ptr
)
1255 if (lp_ctx
->s3_fns
) {
1256 if (*ptr
== NULL
|| strcmp(*ptr
, pszParmValue
) != 0) {
1257 global_iconv_handle
= smb_iconv_handle_reinit(NULL
,
1258 lpcfg_dos_charset(lp_ctx
),
1259 lpcfg_unix_charset(lp_ctx
),
1260 true, global_iconv_handle
);
1264 return lpcfg_string_set(lp_ctx
->globals
->ctx
, ptr
, pszParmValue
);
1268 bool handle_dos_charset(struct loadparm_context
*lp_ctx
, struct loadparm_service
*service
,
1269 const char *pszParmValue
, char **ptr
)
1271 bool is_utf8
= false;
1272 size_t len
= strlen(pszParmValue
);
1274 if (lp_ctx
->s3_fns
) {
1275 if (len
== 4 || len
== 5) {
1276 /* Don't use StrCaseCmp here as we don't want to
1277 initialize iconv. */
1278 if ((toupper_m(pszParmValue
[0]) == 'U') &&
1279 (toupper_m(pszParmValue
[1]) == 'T') &&
1280 (toupper_m(pszParmValue
[2]) == 'F')) {
1282 if (pszParmValue
[3] == '8') {
1286 if (pszParmValue
[3] == '-' &&
1287 pszParmValue
[4] == '8') {
1294 if (*ptr
== NULL
|| strcmp(*ptr
, pszParmValue
) != 0) {
1296 DEBUG(0,("ERROR: invalid DOS charset: 'dos charset' must not "
1297 "be UTF8, using (default value) %s instead.\n",
1298 DEFAULT_DOS_CHARSET
));
1299 pszParmValue
= DEFAULT_DOS_CHARSET
;
1301 global_iconv_handle
= smb_iconv_handle_reinit(NULL
,
1302 lpcfg_dos_charset(lp_ctx
),
1303 lpcfg_unix_charset(lp_ctx
),
1304 true, global_iconv_handle
);
1308 return lpcfg_string_set(lp_ctx
->globals
->ctx
, ptr
, pszParmValue
);
1311 bool handle_printing(struct loadparm_context
*lp_ctx
, struct loadparm_service
*service
,
1312 const char *pszParmValue
, char **ptr
)
1314 static int parm_num
= -1;
1316 if (parm_num
== -1) {
1317 parm_num
= lpcfg_map_parameter("printing");
1320 if (!lp_set_enum_parm(&parm_table
[parm_num
], pszParmValue
, (int*)ptr
)) {
1324 if (lp_ctx
->s3_fns
) {
1325 if (service
== NULL
) {
1326 init_printer_values(lp_ctx
, lp_ctx
->globals
->ctx
, lp_ctx
->sDefault
);
1328 init_printer_values(lp_ctx
, service
, service
);
1335 bool handle_ldap_debug_level(struct loadparm_context
*lp_ctx
, struct loadparm_service
*service
,
1336 const char *pszParmValue
, char **ptr
)
1338 lp_ctx
->globals
->ldap_debug_level
= lp_int(pszParmValue
);
1340 if (lp_ctx
->s3_fns
) {
1341 lp_ctx
->s3_fns
->init_ldap_debugging();
1346 bool handle_netbios_aliases(struct loadparm_context
*lp_ctx
, struct loadparm_service
*service
,
1347 const char *pszParmValue
, char **ptr
)
1349 TALLOC_FREE(lp_ctx
->globals
->netbios_aliases
);
1350 lp_ctx
->globals
->netbios_aliases
= str_list_make_v3_const(lp_ctx
->globals
->ctx
,
1351 pszParmValue
, NULL
);
1353 if (lp_ctx
->s3_fns
) {
1354 return lp_ctx
->s3_fns
->set_netbios_aliases(lp_ctx
->globals
->netbios_aliases
);
1360 * idmap related parameters
1363 bool handle_idmap_backend(struct loadparm_context
*lp_ctx
, struct loadparm_service
*service
,
1364 const char *pszParmValue
, char **ptr
)
1366 if (lp_ctx
->s3_fns
) {
1367 lp_do_parameter_parametric(lp_ctx
, service
, "idmap config * : backend",
1371 return lpcfg_string_set(lp_ctx
->globals
->ctx
, ptr
, pszParmValue
);
1374 bool handle_idmap_uid(struct loadparm_context
*lp_ctx
, struct loadparm_service
*service
,
1375 const char *pszParmValue
, char **ptr
)
1377 if (lp_ctx
->s3_fns
) {
1378 lp_do_parameter_parametric(lp_ctx
, service
, "idmap config * : range",
1382 return lpcfg_string_set(lp_ctx
->globals
->ctx
, ptr
, pszParmValue
);
1385 bool handle_idmap_gid(struct loadparm_context
*lp_ctx
, struct loadparm_service
*service
,
1386 const char *pszParmValue
, char **ptr
)
1388 if (lp_ctx
->s3_fns
) {
1389 lp_do_parameter_parametric(lp_ctx
, service
, "idmap config * : range",
1393 return lpcfg_string_set(lp_ctx
->globals
->ctx
, ptr
, pszParmValue
);
1396 bool handle_smb_ports(struct loadparm_context
*lp_ctx
, struct loadparm_service
*service
,
1397 const char *pszParmValue
, char **ptr
)
1399 static int parm_num
= -1;
1403 if (!pszParmValue
|| !*pszParmValue
) {
1407 if (parm_num
== -1) {
1408 parm_num
= lpcfg_map_parameter("smb ports");
1409 if (parm_num
== -1) {
1414 if(!set_variable_helper(lp_ctx
->globals
->ctx
, parm_num
, ptr
, "smb ports",
1419 list
= lp_ctx
->globals
->smb_ports
;
1424 /* Check that each port is a valid integer and within range */
1425 for (i
= 0; list
[i
] != NULL
; i
++) {
1428 port
= strtol(list
[i
], &end
, 10);
1429 if (*end
!= '\0' || port
<= 0 || port
> 65535) {
1438 bool handle_smb2_max_credits(struct loadparm_context
*lp_ctx
,
1439 struct loadparm_service
*service
,
1440 const char *pszParmValue
, char **ptr
)
1442 int value
= lp_int(pszParmValue
);
1445 value
= DEFAULT_SMB2_MAX_CREDITS
;
1448 *(int *)ptr
= value
;
1453 bool handle_cups_encrypt(struct loadparm_context
*lp_ctx
,
1454 struct loadparm_service
*service
,
1455 const char *pszParmValue
, char **ptr
)
1458 #ifdef HAVE_HTTPCONNECTENCRYPT
1459 int value
= lp_int(pszParmValue
);
1463 result
= HTTP_ENCRYPT_REQUIRED
;
1466 result
= HTTP_ENCRYPT_ALWAYS
;
1469 result
= HTTP_ENCRYPT_NEVER
;
1476 *(int *)ptr
= result
;
1481 /***************************************************************************
1482 Initialise a copymap.
1483 ***************************************************************************/
1486 * Initializes service copymap
1487 * Note: pservice *must* be valid TALLOC_CTX
1489 void init_copymap(struct loadparm_service
*pservice
)
1493 TALLOC_FREE(pservice
->copymap
);
1495 pservice
->copymap
= bitmap_talloc(pservice
, num_parameters());
1496 if (!pservice
->copymap
) {
1498 ("Couldn't allocate copymap!! (size %d)\n",
1499 (int)num_parameters()));
1501 for (i
= 0; i
< num_parameters(); i
++) {
1502 bitmap_set(pservice
->copymap
, i
);
1508 * Process a parametric option
1510 static bool lp_do_parameter_parametric(struct loadparm_context
*lp_ctx
,
1511 struct loadparm_service
*service
,
1512 const char *pszParmName
,
1513 const char *pszParmValue
, int flags
)
1515 struct parmlist_entry
**data
;
1517 TALLOC_CTX
*mem_ctx
;
1519 while (isspace((unsigned char)*pszParmName
)) {
1523 name
= strlower_talloc(lp_ctx
, pszParmName
);
1524 if (!name
) return false;
1526 if (service
== NULL
) {
1527 data
= &lp_ctx
->globals
->param_opt
;
1529 * s3 code cannot deal with parametric options stored on the globals ctx.
1531 if (lp_ctx
->s3_fns
!= NULL
) {
1534 mem_ctx
= lp_ctx
->globals
->ctx
;
1537 data
= &service
->param_opt
;
1541 set_param_opt(mem_ctx
, data
, name
, pszParmValue
, flags
);
1548 static bool set_variable_helper(TALLOC_CTX
*mem_ctx
, int parmnum
, void *parm_ptr
,
1549 const char *pszParmName
, const char *pszParmValue
)
1553 /* switch on the type of variable it is */
1554 switch (parm_table
[parmnum
].type
)
1558 if (!set_boolean(pszParmValue
, &b
)) {
1559 DEBUG(0, ("set_variable_helper(%s): value is not "
1560 "boolean!\n", pszParmValue
));
1563 *(bool *)parm_ptr
= b
;
1569 if (!set_boolean(pszParmValue
, &b
)) {
1570 DEBUG(0, ("set_variable_helper(%s): value is not "
1571 "boolean!\n", pszParmValue
));
1574 *(bool *)parm_ptr
= !b
;
1579 *(int *)parm_ptr
= lp_int(pszParmValue
);
1583 *(char *)parm_ptr
= *pszParmValue
;
1587 i
= sscanf(pszParmValue
, "%o", (int *)parm_ptr
);
1589 DEBUG ( 0, ("Invalid octal number %s\n", pszParmName
));
1597 if (conv_str_size_error(pszParmValue
, &val
)) {
1598 if (val
<= INT_MAX
) {
1599 *(int *)parm_ptr
= (int)val
;
1604 DEBUG(0, ("set_variable_helper(%s): value is not "
1605 "a valid size specifier!\n", pszParmValue
));
1610 TALLOC_FREE(*(char ***)parm_ptr
);
1611 *(char ***)parm_ptr
= str_list_make_v3(mem_ctx
,
1612 pszParmValue
, NULL
);
1617 char **new_list
= str_list_make_v3(mem_ctx
,
1618 pszParmValue
, NULL
);
1619 if (new_list
== NULL
) {
1623 for (i
=0; new_list
[i
]; i
++) {
1624 if (*(const char ***)parm_ptr
!= NULL
&&
1625 new_list
[i
][0] == '+' &&
1628 if (!str_list_check(*(const char ***)parm_ptr
,
1630 *(const char ***)parm_ptr
= str_list_add(*(const char ***)parm_ptr
,
1633 } else if (*(const char ***)parm_ptr
!= NULL
&&
1634 new_list
[i
][0] == '-' &&
1637 str_list_remove(*(const char ***)parm_ptr
,
1641 DEBUG(0, ("Unsupported list syntax for: %s = %s\n",
1642 pszParmName
, pszParmValue
));
1645 *(char ***)parm_ptr
= new_list
;
1653 lpcfg_string_set(mem_ctx
, (char **)parm_ptr
, pszParmValue
);
1657 lpcfg_string_set_upper(mem_ctx
, (char **)parm_ptr
, pszParmValue
);
1661 if (!lp_set_enum_parm(&parm_table
[parmnum
], pszParmValue
, (int*)parm_ptr
)) {
1672 static bool set_variable(TALLOC_CTX
*mem_ctx
, struct loadparm_service
*service
,
1673 int parmnum
, void *parm_ptr
,
1674 const char *pszParmName
, const char *pszParmValue
,
1675 struct loadparm_context
*lp_ctx
, bool on_globals
)
1680 /* if it is a special case then go ahead */
1681 if (parm_table
[parmnum
].special
) {
1682 ok
= parm_table
[parmnum
].special(lp_ctx
, service
, pszParmValue
,
1685 ok
= set_variable_helper(mem_ctx
, parmnum
, parm_ptr
,
1686 pszParmName
, pszParmValue
);
1693 if (on_globals
&& (lp_ctx
->flags
[parmnum
] & FLAG_DEFAULT
)) {
1694 lp_ctx
->flags
[parmnum
] &= ~FLAG_DEFAULT
;
1695 /* we have to also unset FLAG_DEFAULT on aliases */
1696 for (i
=parmnum
-1;i
>=0 && parm_table
[i
].offset
== parm_table
[parmnum
].offset
;i
--) {
1697 lp_ctx
->flags
[i
] &= ~FLAG_DEFAULT
;
1699 for (i
=parmnum
+1;i
<num_parameters() && parm_table
[i
].offset
== parm_table
[parmnum
].offset
;i
++) {
1700 lp_ctx
->flags
[i
] &= ~FLAG_DEFAULT
;
1707 bool lpcfg_do_global_parameter(struct loadparm_context
*lp_ctx
,
1708 const char *pszParmName
, const char *pszParmValue
)
1710 int parmnum
= lpcfg_map_parameter(pszParmName
);
1714 if (strchr(pszParmName
, ':')) {
1715 return lp_do_parameter_parametric(lp_ctx
, NULL
, pszParmName
, pszParmValue
, 0);
1717 DEBUG(0, ("Ignoring unknown parameter \"%s\"\n", pszParmName
));
1721 /* if the flag has been set on the command line, then don't allow override,
1722 but don't report an error */
1723 if (lp_ctx
->flags
[parmnum
] & FLAG_CMDLINE
) {
1727 if (parm_table
[parmnum
].flags
& FLAG_DEPRECATED
) {
1728 DEBUG(1, ("WARNING: The \"%s\" option is deprecated\n",
1732 parm_ptr
= lpcfg_parm_ptr(lp_ctx
, NULL
, &parm_table
[parmnum
]);
1734 return set_variable(lp_ctx
->globals
->ctx
, NULL
, parmnum
, parm_ptr
,
1735 pszParmName
, pszParmValue
, lp_ctx
, true);
1738 bool lpcfg_do_service_parameter(struct loadparm_context
*lp_ctx
,
1739 struct loadparm_service
*service
,
1740 const char *pszParmName
, const char *pszParmValue
)
1744 int parmnum
= lpcfg_map_parameter(pszParmName
);
1747 if (strchr(pszParmName
, ':')) {
1748 return lp_do_parameter_parametric(lp_ctx
, service
, pszParmName
, pszParmValue
, 0);
1750 DEBUG(0, ("Ignoring unknown parameter \"%s\"\n", pszParmName
));
1754 /* if the flag has been set on the command line, then don't allow override,
1755 but don't report an error */
1756 if (lp_ctx
->flags
[parmnum
] & FLAG_CMDLINE
) {
1760 if (parm_table
[parmnum
].flags
& FLAG_DEPRECATED
) {
1761 DEBUG(1, ("WARNING: The \"%s\" option is deprecated\n",
1765 if (parm_table
[parmnum
].p_class
== P_GLOBAL
) {
1767 ("Global parameter %s found in service section!\n",
1771 parm_ptr
= ((char *)service
) + parm_table
[parmnum
].offset
;
1773 if (!service
->copymap
)
1774 init_copymap(service
);
1776 /* this handles the aliases - set the copymap for other
1777 * entries with the same data pointer */
1778 for (i
= 0; parm_table
[i
].label
; i
++)
1779 if (parm_table
[i
].offset
== parm_table
[parmnum
].offset
&&
1780 parm_table
[i
].p_class
== parm_table
[parmnum
].p_class
)
1781 bitmap_clear(service
->copymap
, i
);
1783 return set_variable(service
, service
, parmnum
, parm_ptr
, pszParmName
,
1784 pszParmValue
, lp_ctx
, false);
1788 * Process a parameter.
1791 bool lpcfg_do_parameter(const char *pszParmName
, const char *pszParmValue
,
1794 struct loadparm_context
*lp_ctx
= (struct loadparm_context
*)userdata
;
1796 if (lp_ctx
->bInGlobalSection
)
1797 return lpcfg_do_global_parameter(lp_ctx
, pszParmName
,
1800 return lpcfg_do_service_parameter(lp_ctx
, lp_ctx
->currentService
,
1801 pszParmName
, pszParmValue
);
1805 variable argument do parameter
1807 bool lpcfg_do_global_parameter_var(struct loadparm_context
*lp_ctx
, const char *pszParmName
, const char *fmt
, ...) PRINTF_ATTRIBUTE(3, 4);
1808 bool lpcfg_do_global_parameter_var(struct loadparm_context
*lp_ctx
,
1809 const char *pszParmName
, const char *fmt
, ...)
1816 s
= talloc_vasprintf(NULL
, fmt
, ap
);
1818 ret
= lpcfg_do_global_parameter(lp_ctx
, pszParmName
, s
);
1825 set a parameter from the commandline - this is called from command line parameter
1826 parsing code. It sets the parameter then marks the parameter as unable to be modified
1827 by smb.conf processing
1829 bool lpcfg_set_cmdline(struct loadparm_context
*lp_ctx
, const char *pszParmName
,
1830 const char *pszParmValue
)
1835 while (isspace((unsigned char)*pszParmValue
)) pszParmValue
++;
1837 parmnum
= lpcfg_map_parameter(pszParmName
);
1839 if (parmnum
< 0 && strchr(pszParmName
, ':')) {
1840 /* set a parametric option */
1842 ok
= lp_do_parameter_parametric(lp_ctx
, NULL
, pszParmName
,
1843 pszParmValue
, FLAG_CMDLINE
);
1844 if (lp_ctx
->s3_fns
!= NULL
) {
1846 lp_ctx
->s3_fns
->store_cmdline(pszParmName
, pszParmValue
);
1853 DEBUG(0,("Unknown option '%s'\n", pszParmName
));
1857 /* reset the CMDLINE flag in case this has been called before */
1858 lp_ctx
->flags
[parmnum
] &= ~FLAG_CMDLINE
;
1860 if (!lpcfg_do_global_parameter(lp_ctx
, pszParmName
, pszParmValue
)) {
1864 lp_ctx
->flags
[parmnum
] |= FLAG_CMDLINE
;
1866 /* we have to also set FLAG_CMDLINE on aliases */
1868 i
>=0 && parm_table
[i
].p_class
== parm_table
[parmnum
].p_class
&&
1869 parm_table
[i
].offset
== parm_table
[parmnum
].offset
;
1871 lp_ctx
->flags
[i
] |= FLAG_CMDLINE
;
1874 i
<num_parameters() &&
1875 parm_table
[i
].p_class
== parm_table
[parmnum
].p_class
&&
1876 parm_table
[i
].offset
== parm_table
[parmnum
].offset
;
1878 lp_ctx
->flags
[i
] |= FLAG_CMDLINE
;
1881 if (lp_ctx
->s3_fns
!= NULL
) {
1882 lp_ctx
->s3_fns
->store_cmdline(pszParmName
, pszParmValue
);
1889 set a option from the commandline in 'a=b' format. Use to support --option
1891 bool lpcfg_set_option(struct loadparm_context
*lp_ctx
, const char *option
)
1896 s
= talloc_strdup(NULL
, option
);
1909 ret
= lpcfg_set_cmdline(lp_ctx
, s
, p
+1);
1915 #define BOOLSTR(b) ((b) ? "Yes" : "No")
1918 * Print a parameter of the specified type.
1921 void lpcfg_print_parameter(struct parm_struct
*p
, void *ptr
, FILE * f
)
1923 /* For the seperation of lists values that we print below */
1924 const char *list_sep
= ", ";
1929 for (i
= 0; p
->enum_list
[i
].name
; i
++) {
1930 if (*(int *)ptr
== p
->enum_list
[i
].value
) {
1932 p
->enum_list
[i
].name
);
1939 fprintf(f
, "%s", BOOLSTR(*(bool *)ptr
));
1943 fprintf(f
, "%s", BOOLSTR(!*(bool *)ptr
));
1948 fprintf(f
, "%d", *(int *)ptr
);
1952 fprintf(f
, "%c", *(char *)ptr
);
1956 int val
= *(int *)ptr
;
1960 fprintf(f
, "0%03o", val
);
1969 if ((char ***)ptr
&& *(char ***)ptr
) {
1970 char **list
= *(char ***)ptr
;
1971 for (; *list
; list
++) {
1972 /* surround strings with whitespace in double quotes */
1973 if (*(list
+1) == NULL
) {
1974 /* last item, no extra separator */
1977 if ( strchr_m( *list
, ' ' ) ) {
1978 fprintf(f
, "\"%s\"%s", *list
, list_sep
);
1980 fprintf(f
, "%s%s", *list
, list_sep
);
1988 if (*(char **)ptr
) {
1989 fprintf(f
, "%s", *(char **)ptr
);
1996 * Check if two parameters are equal.
1999 static bool lpcfg_equal_parameter(parm_type type
, void *ptr1
, void *ptr2
)
2004 return (*((bool *)ptr1
) == *((bool *)ptr2
));
2010 return (*((int *)ptr1
) == *((int *)ptr2
));
2013 return (*((char *)ptr1
) == *((char *)ptr2
));
2017 return str_list_equal(*(const char ***)ptr1
, *(const char ***)ptr2
);
2022 char *p1
= *(char **)ptr1
, *p2
= *(char **)ptr2
;
2027 return (p1
== p2
|| strequal(p1
, p2
));
2034 * Process a new section (service).
2036 * At this stage all sections are services.
2037 * Later we'll have special sections that permit server parameters to be set.
2038 * Returns True on success, False on failure.
2041 static bool do_section(const char *pszSectionName
, void *userdata
)
2043 struct loadparm_context
*lp_ctx
= (struct loadparm_context
*)userdata
;
2047 if (lp_ctx
->s3_fns
!= NULL
) {
2048 return lp_ctx
->s3_fns
->do_section(pszSectionName
, lp_ctx
);
2051 isglobal
= ((strwicmp(pszSectionName
, GLOBAL_NAME
) == 0) ||
2052 (strwicmp(pszSectionName
, GLOBAL_NAME2
) == 0));
2056 /* if we've just struck a global section, note the fact. */
2057 lp_ctx
->bInGlobalSection
= isglobal
;
2059 /* check for multiple global sections */
2060 if (lp_ctx
->bInGlobalSection
) {
2061 DEBUG(4, ("Processing section \"[%s]\"\n", pszSectionName
));
2065 /* if we have a current service, tidy it up before moving on */
2068 if (lp_ctx
->currentService
!= NULL
)
2069 bRetval
= lpcfg_service_ok(lp_ctx
->currentService
);
2071 /* if all is still well, move to the next record in the services array */
2073 /* We put this here to avoid an odd message order if messages are */
2074 /* issued by the post-processing of a previous section. */
2075 DEBUG(4, ("Processing section \"[%s]\"\n", pszSectionName
));
2077 if ((lp_ctx
->currentService
= lpcfg_add_service(lp_ctx
, lp_ctx
->sDefault
,
2080 DEBUG(0, ("Failed to add a new service\n"));
2090 * Determine if a particular base parameter is currently set to the default value.
2093 static bool is_default(void *base_structure
, int i
)
2095 void *def_ptr
= ((char *)base_structure
) + parm_table
[i
].offset
;
2096 switch (parm_table
[i
].type
) {
2099 return str_list_equal((const char * const *)parm_table
[i
].def
.lvalue
,
2100 *(const char * const **)def_ptr
);
2103 return strequal(parm_table
[i
].def
.svalue
,
2107 return parm_table
[i
].def
.bvalue
==
2114 return parm_table
[i
].def
.ivalue
==
2121 *Display the contents of the global structure.
2124 void lpcfg_dump_globals(struct loadparm_context
*lp_ctx
, FILE *f
,
2128 struct parmlist_entry
*data
;
2130 fprintf(f
, "# Global parameters\n[global]\n");
2132 for (i
= 0; parm_table
[i
].label
; i
++) {
2133 if (parm_table
[i
].p_class
!= P_GLOBAL
) {
2137 if (parm_table
[i
].flags
& FLAG_SYNONYM
) {
2141 if (!show_defaults
) {
2142 if (lp_ctx
->flags
&& (lp_ctx
->flags
[i
] & FLAG_DEFAULT
)) {
2146 if (is_default(lp_ctx
->globals
, i
)) {
2151 fprintf(f
, "\t%s = ", parm_table
[i
].label
);
2152 lpcfg_print_parameter(&parm_table
[i
], lpcfg_parm_ptr(lp_ctx
, NULL
, &parm_table
[i
]), f
);
2155 if (lp_ctx
->globals
->param_opt
!= NULL
) {
2156 for (data
= lp_ctx
->globals
->param_opt
; data
;
2157 data
= data
->next
) {
2158 if (!show_defaults
&& (data
->priority
& FLAG_DEFAULT
)) {
2161 fprintf(f
, "\t%s = %s\n", data
->key
, data
->value
);
2168 * Display the contents of a single services record.
2171 void lpcfg_dump_a_service(struct loadparm_service
* pService
, struct loadparm_service
*sDefault
, FILE * f
,
2172 unsigned int *flags
, bool show_defaults
)
2175 struct parmlist_entry
*data
;
2177 if (pService
!= sDefault
)
2178 fprintf(f
, "\n[%s]\n", pService
->szService
);
2180 for (i
= 0; parm_table
[i
].label
; i
++) {
2181 if (parm_table
[i
].p_class
!= P_LOCAL
) {
2185 if (parm_table
[i
].flags
& FLAG_SYNONYM
) {
2189 if (*parm_table
[i
].label
== '-') {
2193 if (pService
== sDefault
) {
2194 if (!show_defaults
) {
2195 if (flags
&& (flags
[i
] & FLAG_DEFAULT
)) {
2199 if (is_default(sDefault
, i
)) {
2206 equal
= lpcfg_equal_parameter(parm_table
[i
].type
,
2207 ((char *)pService
) +
2208 parm_table
[i
].offset
,
2209 ((char *)sDefault
) +
2210 parm_table
[i
].offset
);
2216 fprintf(f
, "\t%s = ", parm_table
[i
].label
);
2217 lpcfg_print_parameter(&parm_table
[i
],
2218 ((char *)pService
) + parm_table
[i
].offset
, f
);
2221 if (pService
->param_opt
!= NULL
) {
2222 for (data
= pService
->param_opt
; data
; data
= data
->next
) {
2223 if (!show_defaults
&& (data
->priority
& FLAG_DEFAULT
)) {
2226 fprintf(f
, "\t%s = %s\n", data
->key
, data
->value
);
2231 bool lpcfg_dump_a_parameter(struct loadparm_context
*lp_ctx
,
2232 struct loadparm_service
*service
,
2233 const char *parm_name
, FILE * f
)
2235 struct parm_struct
*parm
;
2237 char *local_parm_name
;
2239 const char *parm_opt_value
;
2241 /* check for parametrical option */
2242 local_parm_name
= talloc_strdup(lp_ctx
, parm_name
);
2243 if (local_parm_name
== NULL
) {
2247 parm_opt
= strchr( local_parm_name
, ':');
2252 if (strlen(parm_opt
)) {
2253 parm_opt_value
= lpcfg_parm_string(lp_ctx
, service
,
2254 local_parm_name
, parm_opt
);
2255 if (parm_opt_value
) {
2256 fprintf(f
, "%s\n", parm_opt_value
);
2263 /* parameter is not parametric, search the table */
2264 parm
= lpcfg_parm_struct(lp_ctx
, parm_name
);
2269 if (service
!= NULL
&& parm
->p_class
== P_GLOBAL
) {
2273 ptr
= lpcfg_parm_ptr(lp_ctx
, service
,parm
);
2275 lpcfg_print_parameter(parm
, ptr
, f
);
2281 * Auto-load some home services.
2283 static void lpcfg_add_auto_services(struct loadparm_context
*lp_ctx
,
2289 /***************************************************************************
2290 Initialise the sDefault parameter structure for the printer values.
2291 ***************************************************************************/
2293 void init_printer_values(struct loadparm_context
*lp_ctx
, TALLOC_CTX
*ctx
,
2294 struct loadparm_service
*pService
)
2296 /* choose defaults depending on the type of printing */
2297 switch (pService
->printing
) {
2302 lpcfg_string_set(ctx
, &pService
->lpq_command
, "lpq -P'%p'");
2303 lpcfg_string_set(ctx
, &pService
->lprm_command
, "lprm -P'%p' %j");
2304 lpcfg_string_set(ctx
, &pService
->print_command
, "lpr -r -P'%p' %s");
2309 lpcfg_string_set(ctx
, &pService
->lpq_command
, "lpq -P'%p'");
2310 lpcfg_string_set(ctx
, &pService
->lprm_command
, "lprm -P'%p' %j");
2311 lpcfg_string_set(ctx
, &pService
->print_command
, "lpr -r -P'%p' %s");
2312 lpcfg_string_set(ctx
, &pService
->queuepause_command
, "lpc stop '%p'");
2313 lpcfg_string_set(ctx
, &pService
->queueresume_command
, "lpc start '%p'");
2314 lpcfg_string_set(ctx
, &pService
->lppause_command
, "lpc hold '%p' %j");
2315 lpcfg_string_set(ctx
, &pService
->lpresume_command
, "lpc release '%p' %j");
2320 /* set the lpq command to contain the destination printer
2321 name only. This is used by cups_queue_get() */
2322 lpcfg_string_set(ctx
, &pService
->lpq_command
, "%p");
2323 lpcfg_string_set(ctx
, &pService
->lprm_command
, "");
2324 lpcfg_string_set(ctx
, &pService
->print_command
, "");
2325 lpcfg_string_set(ctx
, &pService
->lppause_command
, "");
2326 lpcfg_string_set(ctx
, &pService
->lpresume_command
, "");
2327 lpcfg_string_set(ctx
, &pService
->queuepause_command
, "");
2328 lpcfg_string_set(ctx
, &pService
->queueresume_command
, "");
2333 lpcfg_string_set(ctx
, &pService
->lpq_command
, "lpstat -o%p");
2334 lpcfg_string_set(ctx
, &pService
->lprm_command
, "cancel %p-%j");
2335 lpcfg_string_set(ctx
, &pService
->print_command
, "lp -c -d%p %s; rm %s");
2336 lpcfg_string_set(ctx
, &pService
->queuepause_command
, "disable %p");
2337 lpcfg_string_set(ctx
, &pService
->queueresume_command
, "enable %p");
2339 lpcfg_string_set(ctx
, &pService
->lppause_command
, "lp -i %p-%j -H hold");
2340 lpcfg_string_set(ctx
, &pService
->lpresume_command
, "lp -i %p-%j -H resume");
2345 lpcfg_string_set(ctx
, &pService
->lpq_command
, "lpq -P%p");
2346 lpcfg_string_set(ctx
, &pService
->lprm_command
, "lprm -P%p %j");
2347 lpcfg_string_set(ctx
, &pService
->print_command
, "lp -r -P%p %s");
2350 #if defined(DEVELOPER) || defined(ENABLE_SELFTEST)
2354 const char *tdbfile
;
2355 TALLOC_CTX
*tmp_ctx
= talloc_new(ctx
);
2358 tmp
= lpcfg_parm_string(lp_ctx
, NULL
, "vlp", "tdbfile");
2360 tmp
= "/tmp/vlp.tdb";
2363 tdbfile
= talloc_asprintf(tmp_ctx
, "tdbfile=%s", tmp
);
2364 if (tdbfile
== NULL
) {
2365 tdbfile
="tdbfile=/tmp/vlp.tdb";
2368 tmp
= talloc_asprintf(tmp_ctx
, "vlp %s print %%p %%s",
2370 lpcfg_string_set(ctx
, &pService
->print_command
,
2371 tmp
? tmp
: "vlp print %p %s");
2373 tmp
= talloc_asprintf(tmp_ctx
, "vlp %s lpq %%p",
2375 lpcfg_string_set(ctx
, &pService
->lpq_command
,
2376 tmp
? tmp
: "vlp lpq %p");
2378 tmp
= talloc_asprintf(tmp_ctx
, "vlp %s lprm %%p %%j",
2380 lpcfg_string_set(ctx
, &pService
->lprm_command
,
2381 tmp
? tmp
: "vlp lprm %p %j");
2383 tmp
= talloc_asprintf(tmp_ctx
, "vlp %s lppause %%p %%j",
2385 lpcfg_string_set(ctx
, &pService
->lppause_command
,
2386 tmp
? tmp
: "vlp lppause %p %j");
2388 tmp
= talloc_asprintf(tmp_ctx
, "vlp %s lpresume %%p %%j",
2390 lpcfg_string_set(ctx
, &pService
->lpresume_command
,
2391 tmp
? tmp
: "vlp lpresume %p %j");
2393 tmp
= talloc_asprintf(tmp_ctx
, "vlp %s queuepause %%p",
2395 lpcfg_string_set(ctx
, &pService
->queuepause_command
,
2396 tmp
? tmp
: "vlp queuepause %p");
2398 tmp
= talloc_asprintf(tmp_ctx
, "vlp %s queueresume %%p",
2400 lpcfg_string_set(ctx
, &pService
->queueresume_command
,
2401 tmp
? tmp
: "vlp queueresume %p");
2402 TALLOC_FREE(tmp_ctx
);
2406 #endif /* DEVELOPER */
2412 * Unload unused services.
2415 void lpcfg_killunused(struct loadparm_context
*lp_ctx
,
2416 struct smbsrv_connection
*smb
,
2417 bool (*snumused
) (struct smbsrv_connection
*, int))
2421 if (lp_ctx
->s3_fns
!= NULL
) {
2422 smb_panic("Cannot be used from an s3 loadparm ctx");
2425 for (i
= 0; i
< lp_ctx
->iNumServices
; i
++) {
2426 if (lp_ctx
->services
[i
] == NULL
)
2429 if (!snumused
|| !snumused(smb
, i
)) {
2430 talloc_free(lp_ctx
->services
[i
]);
2431 lp_ctx
->services
[i
] = NULL
;
2437 static int lpcfg_destructor(struct loadparm_context
*lp_ctx
)
2439 struct parmlist_entry
*data
;
2441 if (lp_ctx
->refuse_free
) {
2442 /* someone is trying to free the
2443 global_loadparm_context.
2444 We can't allow that. */
2448 if (lp_ctx
->globals
->param_opt
!= NULL
) {
2449 struct parmlist_entry
*next
;
2450 for (data
= lp_ctx
->globals
->param_opt
; data
; data
=next
) {
2452 if (data
->priority
& FLAG_CMDLINE
) continue;
2453 DLIST_REMOVE(lp_ctx
->globals
->param_opt
, data
);
2461 struct defaults_hook_data
{
2463 lpcfg_defaults_hook hook
;
2464 struct defaults_hook_data
*prev
, *next
;
2465 } *defaults_hooks
= NULL
;
2468 bool lpcfg_register_defaults_hook(const char *name
, lpcfg_defaults_hook hook
)
2470 struct defaults_hook_data
*hook_data
= talloc(talloc_autofree_context(),
2471 struct defaults_hook_data
);
2472 hook_data
->name
= talloc_strdup(hook_data
, name
);
2473 hook_data
->hook
= hook
;
2474 DLIST_ADD(defaults_hooks
, hook_data
);
2479 * Initialise the global parameter structure.
2481 * Note that most callers should use loadparm_init_global() instead
2483 struct loadparm_context
*loadparm_init(TALLOC_CTX
*mem_ctx
)
2487 struct loadparm_context
*lp_ctx
;
2488 struct parmlist_entry
*parm
;
2490 struct defaults_hook_data
*defaults_hook
;
2492 lp_ctx
= talloc_zero(mem_ctx
, struct loadparm_context
);
2496 talloc_set_destructor(lp_ctx
, lpcfg_destructor
);
2497 lp_ctx
->bInGlobalSection
= true;
2498 lp_ctx
->globals
= talloc_zero(lp_ctx
, struct loadparm_global
);
2499 /* This appears odd, but globals in s3 isn't a pointer */
2500 lp_ctx
->globals
->ctx
= lp_ctx
->globals
;
2501 lp_ctx
->sDefault
= talloc_zero(lp_ctx
, struct loadparm_service
);
2502 lp_ctx
->flags
= talloc_zero_array(lp_ctx
, unsigned int, num_parameters());
2504 lp_ctx
->sDefault
->max_print_jobs
= 1000;
2505 lp_ctx
->sDefault
->available
= true;
2506 lp_ctx
->sDefault
->browseable
= true;
2507 lp_ctx
->sDefault
->read_only
= true;
2508 lp_ctx
->sDefault
->map_archive
= true;
2509 lp_ctx
->sDefault
->strict_locking
= true;
2510 lp_ctx
->sDefault
->oplocks
= true;
2511 lp_ctx
->sDefault
->create_mask
= 0744;
2512 lp_ctx
->sDefault
->force_create_mode
= 0000;
2513 lp_ctx
->sDefault
->directory_mask
= 0755;
2514 lp_ctx
->sDefault
->force_directory_mode
= 0000;
2516 DEBUG(3, ("Initialising global parameters\n"));
2518 for (i
= 0; parm_table
[i
].label
; i
++) {
2519 if ((parm_table
[i
].type
== P_STRING
||
2520 parm_table
[i
].type
== P_USTRING
) &&
2521 !(lp_ctx
->flags
[i
] & FLAG_CMDLINE
)) {
2522 TALLOC_CTX
*parent_mem
;
2524 if (parm_table
[i
].p_class
== P_LOCAL
) {
2525 parent_mem
= lp_ctx
->sDefault
;
2526 r
= (char **)(((char *)lp_ctx
->sDefault
) + parm_table
[i
].offset
);
2528 parent_mem
= lp_ctx
->globals
;
2529 r
= (char **)(((char *)lp_ctx
->globals
) + parm_table
[i
].offset
);
2531 lpcfg_string_set(parent_mem
, r
, "");
2535 logfile
= talloc_asprintf(lp_ctx
, "%s/log.samba", dyn_LOGFILEBASE
);
2536 lpcfg_do_global_parameter(lp_ctx
, "log file", logfile
);
2537 talloc_free(logfile
);
2539 lpcfg_do_global_parameter(lp_ctx
, "log level", "0");
2541 lpcfg_do_global_parameter(lp_ctx
, "syslog", "1");
2542 lpcfg_do_global_parameter(lp_ctx
, "syslog only", "No");
2543 lpcfg_do_global_parameter(lp_ctx
, "debug timestamp", "Yes");
2544 lpcfg_do_global_parameter(lp_ctx
, "debug prefix timestamp", "No");
2545 lpcfg_do_global_parameter(lp_ctx
, "debug hires timestamp", "Yes");
2546 lpcfg_do_global_parameter(lp_ctx
, "debug pid", "No");
2547 lpcfg_do_global_parameter(lp_ctx
, "debug uid", "No");
2548 lpcfg_do_global_parameter(lp_ctx
, "debug class", "No");
2550 lpcfg_do_global_parameter(lp_ctx
, "share backend", "classic");
2552 lpcfg_do_global_parameter(lp_ctx
, "server role", "auto");
2553 lpcfg_do_global_parameter(lp_ctx
, "domain logons", "No");
2554 lpcfg_do_global_parameter(lp_ctx
, "domain master", "Auto");
2556 /* options that can be set on the command line must be initialised via
2557 the slower lpcfg_do_global_parameter() to ensure that FLAG_CMDLINE is obeyed */
2559 lpcfg_do_global_parameter(lp_ctx
, "socket options", "TCP_NODELAY");
2561 lpcfg_do_global_parameter(lp_ctx
, "workgroup", DEFAULT_WORKGROUP
);
2562 myname
= get_myname(lp_ctx
);
2563 lpcfg_do_global_parameter(lp_ctx
, "netbios name", myname
);
2564 talloc_free(myname
);
2565 lpcfg_do_global_parameter(lp_ctx
, "name resolve order", "lmhosts wins host bcast");
2567 lpcfg_do_global_parameter(lp_ctx
, "fstype", "NTFS");
2569 lpcfg_do_global_parameter(lp_ctx
, "ntvfs handler", "unixuid default");
2570 lpcfg_do_global_parameter(lp_ctx
, "max connections", "0");
2572 lpcfg_do_global_parameter(lp_ctx
, "dcerpc endpoint servers", "epmapper wkssvc rpcecho samr netlogon lsarpc drsuapi dssetup unixinfo browser eventlog6 backupkey dnsserver");
2573 lpcfg_do_global_parameter(lp_ctx
, "server services", "s3fs rpc nbt wrepl ldap cldap kdc drepl winbindd ntp_signd kcc dnsupdate dns");
2574 lpcfg_do_global_parameter(lp_ctx
, "kccsrv:samba_kcc", "true");
2575 /* the winbind method for domain controllers is for both RODC
2576 auth forwarding and for trusted domains */
2577 lpcfg_do_global_parameter(lp_ctx
, "private dir", dyn_PRIVATE_DIR
);
2578 lpcfg_do_global_parameter(lp_ctx
, "registry:HKEY_LOCAL_MACHINE", "hklm.ldb");
2580 /* This hive should be dynamically generated by Samba using
2581 data from the sam, but for the moment leave it in a tdb to
2582 keep regedt32 from popping up an annoying dialog. */
2583 lpcfg_do_global_parameter(lp_ctx
, "registry:HKEY_USERS", "hku.ldb");
2585 /* using UTF8 by default allows us to support all chars */
2586 lpcfg_do_global_parameter(lp_ctx
, "unix charset", "UTF-8");
2588 /* Use codepage 850 as a default for the dos character set */
2589 lpcfg_do_global_parameter(lp_ctx
, "dos charset", "CP850");
2592 * Allow the default PASSWD_CHAT to be overridden in local.h.
2594 lpcfg_do_global_parameter(lp_ctx
, "passwd chat", DEFAULT_PASSWD_CHAT
);
2596 lpcfg_do_global_parameter(lp_ctx
, "pid directory", dyn_PIDDIR
);
2597 lpcfg_do_global_parameter(lp_ctx
, "lock dir", dyn_LOCKDIR
);
2598 lpcfg_do_global_parameter(lp_ctx
, "state directory", dyn_STATEDIR
);
2599 lpcfg_do_global_parameter(lp_ctx
, "cache directory", dyn_CACHEDIR
);
2600 lpcfg_do_global_parameter(lp_ctx
, "ncalrpc dir", dyn_NCALRPCDIR
);
2602 lpcfg_do_global_parameter(lp_ctx
, "nbt client socket address", "0.0.0.0");
2603 lpcfg_do_global_parameter_var(lp_ctx
, "server string",
2604 "Samba %s", SAMBA_VERSION_STRING
);
2606 lpcfg_do_global_parameter(lp_ctx
, "password server", "*");
2608 lpcfg_do_global_parameter(lp_ctx
, "max mux", "50");
2609 lpcfg_do_global_parameter(lp_ctx
, "max xmit", "16644");
2610 lpcfg_do_global_parameter(lp_ctx
, "host msdfs", "true");
2612 lpcfg_do_global_parameter(lp_ctx
, "LargeReadwrite", "True");
2613 lpcfg_do_global_parameter(lp_ctx
, "server min protocol", "LANMAN1");
2614 lpcfg_do_global_parameter(lp_ctx
, "server max protocol", "SMB3");
2615 lpcfg_do_global_parameter(lp_ctx
, "client min protocol", "CORE");
2616 lpcfg_do_global_parameter(lp_ctx
, "client max protocol", "default");
2617 lpcfg_do_global_parameter(lp_ctx
, "client ipc min protocol", "default");
2618 lpcfg_do_global_parameter(lp_ctx
, "client ipc max protocol", "default");
2619 lpcfg_do_global_parameter(lp_ctx
, "security", "AUTO");
2620 lpcfg_do_global_parameter(lp_ctx
, "EncryptPasswords", "True");
2621 lpcfg_do_global_parameter(lp_ctx
, "ReadRaw", "True");
2622 lpcfg_do_global_parameter(lp_ctx
, "WriteRaw", "True");
2623 lpcfg_do_global_parameter(lp_ctx
, "NullPasswords", "False");
2624 lpcfg_do_global_parameter(lp_ctx
, "old password allowed period", "60");
2625 lpcfg_do_global_parameter(lp_ctx
, "ObeyPamRestrictions", "False");
2627 lpcfg_do_global_parameter(lp_ctx
, "TimeServer", "False");
2628 lpcfg_do_global_parameter(lp_ctx
, "BindInterfacesOnly", "False");
2629 lpcfg_do_global_parameter(lp_ctx
, "Unicode", "True");
2630 lpcfg_do_global_parameter(lp_ctx
, "ClientLanManAuth", "False");
2631 lpcfg_do_global_parameter(lp_ctx
, "ClientNTLMv2Auth", "True");
2632 lpcfg_do_global_parameter(lp_ctx
, "LanmanAuth", "False");
2633 lpcfg_do_global_parameter(lp_ctx
, "NTLMAuth", "False");
2634 lpcfg_do_global_parameter(lp_ctx
, "RawNTLMv2Auth", "False");
2635 lpcfg_do_global_parameter(lp_ctx
, "client use spnego principal", "False");
2637 lpcfg_do_global_parameter(lp_ctx
, "allow dcerpc auth level connect", "False");
2639 lpcfg_do_global_parameter(lp_ctx
, "UnixExtensions", "True");
2641 lpcfg_do_global_parameter(lp_ctx
, "PreferredMaster", "Auto");
2642 lpcfg_do_global_parameter(lp_ctx
, "LocalMaster", "True");
2644 lpcfg_do_global_parameter(lp_ctx
, "wins support", "False");
2645 lpcfg_do_global_parameter(lp_ctx
, "dns proxy", "True");
2647 lpcfg_do_global_parameter(lp_ctx
, "winbind separator", "\\");
2648 lpcfg_do_global_parameter(lp_ctx
, "winbind sealed pipes", "True");
2649 lpcfg_do_global_parameter(lp_ctx
, "require strong key", "True");
2650 lpcfg_do_global_parameter(lp_ctx
, "winbindd socket directory", dyn_WINBINDD_SOCKET_DIR
);
2651 lpcfg_do_global_parameter(lp_ctx
, "ntp signd socket directory", dyn_NTP_SIGND_SOCKET_DIR
);
2652 lpcfg_do_global_parameter_var(lp_ctx
, "dns update command", "%s/samba_dnsupdate", dyn_SCRIPTSBINDIR
);
2653 lpcfg_do_global_parameter_var(lp_ctx
, "spn update command", "%s/samba_spnupdate", dyn_SCRIPTSBINDIR
);
2654 lpcfg_do_global_parameter_var(lp_ctx
, "samba kcc command",
2655 "%s/samba_kcc", dyn_SCRIPTSBINDIR
);
2656 lpcfg_do_global_parameter(lp_ctx
, "template shell", "/bin/false");
2657 lpcfg_do_global_parameter(lp_ctx
, "template homedir", "/home/%D/%U");
2659 lpcfg_do_global_parameter(lp_ctx
, "client signing", "default");
2660 lpcfg_do_global_parameter(lp_ctx
, "client ipc signing", "default");
2661 lpcfg_do_global_parameter(lp_ctx
, "server signing", "default");
2663 lpcfg_do_global_parameter(lp_ctx
, "use spnego", "True");
2665 lpcfg_do_global_parameter(lp_ctx
, "use mmap", "True");
2667 lpcfg_do_global_parameter(lp_ctx
, "smb ports", "445 139");
2668 lpcfg_do_global_parameter_var(lp_ctx
, "nbt port", "%d", NBT_NAME_SERVICE_PORT
);
2669 lpcfg_do_global_parameter_var(lp_ctx
, "dgram port", "%d", NBT_DGRAM_SERVICE_PORT
);
2670 lpcfg_do_global_parameter(lp_ctx
, "cldap port", "389");
2671 lpcfg_do_global_parameter(lp_ctx
, "krb5 port", "88");
2672 lpcfg_do_global_parameter(lp_ctx
, "kpasswd port", "464");
2673 lpcfg_do_global_parameter(lp_ctx
, "web port", "901");
2675 lpcfg_do_global_parameter(lp_ctx
, "nt status support", "True");
2677 lpcfg_do_global_parameter(lp_ctx
, "max wins ttl", "518400"); /* 6 days */
2678 lpcfg_do_global_parameter(lp_ctx
, "min wins ttl", "21600");
2680 lpcfg_do_global_parameter(lp_ctx
, "tls enabled", "True");
2681 lpcfg_do_global_parameter(lp_ctx
, "tls verify peer", "as_strict_as_possible");
2682 lpcfg_do_global_parameter(lp_ctx
, "tls keyfile", "tls/key.pem");
2683 lpcfg_do_global_parameter(lp_ctx
, "tls certfile", "tls/cert.pem");
2684 lpcfg_do_global_parameter(lp_ctx
, "tls cafile", "tls/ca.pem");
2685 lpcfg_do_global_parameter(lp_ctx
, "tls priority", "NORMAL:-VERS-SSL3.0");
2686 lpcfg_do_global_parameter(lp_ctx
, "prefork children:smb", "4");
2688 lpcfg_do_global_parameter(lp_ctx
, "rndc command", "/usr/sbin/rndc");
2689 lpcfg_do_global_parameter(lp_ctx
, "nsupdate command", "/usr/bin/nsupdate -g");
2691 lpcfg_do_global_parameter(lp_ctx
, "allow dns updates", "secure only");
2692 lpcfg_do_global_parameter(lp_ctx
, "dns forwarder", "");
2694 lpcfg_do_global_parameter(lp_ctx
, "algorithmic rid base", "1000");
2696 lpcfg_do_global_parameter(lp_ctx
, "enhanced browsing", "True");
2698 lpcfg_do_global_parameter(lp_ctx
, "winbind nss info", "template");
2700 lpcfg_do_global_parameter(lp_ctx
, "server schannel", "Auto");
2702 lpcfg_do_global_parameter(lp_ctx
, "short preserve case", "True");
2704 lpcfg_do_global_parameter(lp_ctx
, "max open files", "16384");
2706 lpcfg_do_global_parameter(lp_ctx
, "cups connection timeout", "30");
2708 lpcfg_do_global_parameter(lp_ctx
, "locking", "True");
2710 lpcfg_do_global_parameter(lp_ctx
, "block size", "1024");
2712 lpcfg_do_global_parameter(lp_ctx
, "client use spnego", "True");
2714 lpcfg_do_global_parameter(lp_ctx
, "change notify", "True");
2716 lpcfg_do_global_parameter(lp_ctx
, "name cache timeout", "660");
2718 lpcfg_do_global_parameter(lp_ctx
, "defer sharing violations", "True");
2720 lpcfg_do_global_parameter(lp_ctx
, "ldap replication sleep", "1000");
2722 lpcfg_do_global_parameter(lp_ctx
, "idmap backend", "tdb");
2724 lpcfg_do_global_parameter(lp_ctx
, "enable privileges", "True");
2726 lpcfg_do_global_parameter_var(lp_ctx
, "smb2 max write", "%u", DEFAULT_SMB2_MAX_WRITE
);
2728 lpcfg_do_global_parameter(lp_ctx
, "passdb backend", "tdbsam");
2730 lpcfg_do_global_parameter(lp_ctx
, "getwd cache", "True");
2732 lpcfg_do_global_parameter(lp_ctx
, "winbind nested groups", "True");
2734 lpcfg_do_global_parameter(lp_ctx
, "mangled names", "True");
2736 lpcfg_do_global_parameter_var(lp_ctx
, "smb2 max credits", "%u", DEFAULT_SMB2_MAX_CREDITS
);
2738 lpcfg_do_global_parameter(lp_ctx
, "ldap ssl", "start tls");
2740 lpcfg_do_global_parameter(lp_ctx
, "ldap deref", "auto");
2742 lpcfg_do_global_parameter(lp_ctx
, "lm interval", "60");
2744 lpcfg_do_global_parameter(lp_ctx
, "mangling method", "hash2");
2746 lpcfg_do_global_parameter(lp_ctx
, "hide dot files", "True");
2748 lpcfg_do_global_parameter(lp_ctx
, "browse list", "True");
2750 lpcfg_do_global_parameter(lp_ctx
, "passwd chat timeout", "2");
2752 lpcfg_do_global_parameter(lp_ctx
, "guest account", GUEST_ACCOUNT
);
2754 lpcfg_do_global_parameter(lp_ctx
, "client schannel", "auto");
2756 lpcfg_do_global_parameter(lp_ctx
, "smb encrypt", "default");
2758 lpcfg_do_global_parameter(lp_ctx
, "max log size", "5000");
2760 lpcfg_do_global_parameter(lp_ctx
, "idmap negative cache time", "120");
2762 lpcfg_do_global_parameter(lp_ctx
, "ldap follow referral", "auto");
2764 lpcfg_do_global_parameter(lp_ctx
, "multicast dns register", "yes");
2766 lpcfg_do_global_parameter(lp_ctx
, "winbind reconnect delay", "30");
2768 lpcfg_do_global_parameter(lp_ctx
, "winbind request timeout", "60");
2770 lpcfg_do_global_parameter(lp_ctx
, "nt acl support", "yes");
2772 lpcfg_do_global_parameter(lp_ctx
, "acl check permissions", "yes");
2774 lpcfg_do_global_parameter(lp_ctx
, "keepalive", "300");
2776 lpcfg_do_global_parameter(lp_ctx
, "smbd profiling level", "off");
2778 lpcfg_do_global_parameter(lp_ctx
, "winbind cache time", "300");
2780 lpcfg_do_global_parameter(lp_ctx
, "level2 oplocks", "yes");
2782 lpcfg_do_global_parameter(lp_ctx
, "show add printer wizard", "yes");
2784 lpcfg_do_global_parameter(lp_ctx
, "allocation roundup size", "1048576");
2786 lpcfg_do_global_parameter(lp_ctx
, "ldap page size", "1000");
2788 lpcfg_do_global_parameter(lp_ctx
, "kernel share modes", "yes");
2790 lpcfg_do_global_parameter(lp_ctx
, "strict locking", "Auto");
2792 lpcfg_do_global_parameter(lp_ctx
, "map readonly", "yes");
2794 lpcfg_do_global_parameter(lp_ctx
, "allow trusted domains", "yes");
2796 lpcfg_do_global_parameter(lp_ctx
, "default devmode", "yes");
2798 lpcfg_do_global_parameter(lp_ctx
, "os level", "20");
2800 lpcfg_do_global_parameter(lp_ctx
, "dos filetimes", "yes");
2802 lpcfg_do_global_parameter(lp_ctx
, "mangling char", "~");
2804 lpcfg_do_global_parameter(lp_ctx
, "printcap cache time", "750");
2806 lpcfg_do_global_parameter(lp_ctx
, "create krb5 conf", "yes");
2808 lpcfg_do_global_parameter(lp_ctx
, "winbind max clients", "200");
2810 lpcfg_do_global_parameter(lp_ctx
, "acl map full control", "yes");
2812 lpcfg_do_global_parameter(lp_ctx
, "nt pipe support", "yes");
2814 lpcfg_do_global_parameter(lp_ctx
, "ldap debug threshold", "10");
2816 lpcfg_do_global_parameter(lp_ctx
, "client ldap sasl wrapping", "sign");
2818 lpcfg_do_global_parameter(lp_ctx
, "ldap server require strong auth", "yes");
2820 lpcfg_do_global_parameter(lp_ctx
, "follow symlinks", "yes");
2822 lpcfg_do_global_parameter(lp_ctx
, "machine password timeout", "604800");
2824 lpcfg_do_global_parameter(lp_ctx
, "ldap connection timeout", "2");
2826 lpcfg_do_global_parameter(lp_ctx
, "winbind expand groups", "0");
2828 lpcfg_do_global_parameter(lp_ctx
, "stat cache", "yes");
2830 lpcfg_do_global_parameter(lp_ctx
, "lpq cache time", "30");
2832 lpcfg_do_global_parameter_var(lp_ctx
, "smb2 max trans", "%u", DEFAULT_SMB2_MAX_TRANSACT
);
2834 lpcfg_do_global_parameter_var(lp_ctx
, "smb2 max read", "%u", DEFAULT_SMB2_MAX_READ
);
2836 lpcfg_do_global_parameter(lp_ctx
, "durable handles", "yes");
2838 lpcfg_do_global_parameter(lp_ctx
, "max stat cache size", "256");
2840 lpcfg_do_global_parameter(lp_ctx
, "ldap passwd sync", "no");
2842 lpcfg_do_global_parameter(lp_ctx
, "kernel change notify", "yes");
2844 lpcfg_do_global_parameter(lp_ctx
, "max ttl", "259200");
2846 lpcfg_do_global_parameter(lp_ctx
, "blocking locks", "yes");
2848 lpcfg_do_global_parameter(lp_ctx
, "oplock contention limit", "2");
2850 lpcfg_do_global_parameter(lp_ctx
, "load printers", "yes");
2852 lpcfg_do_global_parameter(lp_ctx
, "idmap cache time", "604800");
2854 lpcfg_do_global_parameter(lp_ctx
, "preserve case", "yes");
2856 lpcfg_do_global_parameter(lp_ctx
, "lm announce", "auto");
2858 lpcfg_do_global_parameter(lp_ctx
, "afs token lifetime", "604800");
2860 lpcfg_do_global_parameter(lp_ctx
, "enable core files", "yes");
2862 lpcfg_do_global_parameter(lp_ctx
, "winbind max domain connections", "1");
2864 lpcfg_do_global_parameter(lp_ctx
, "case sensitive", "auto");
2866 lpcfg_do_global_parameter(lp_ctx
, "ldap timeout", "15");
2868 lpcfg_do_global_parameter(lp_ctx
, "mangle prefix", "1");
2870 lpcfg_do_global_parameter(lp_ctx
, "posix locking", "yes");
2872 lpcfg_do_global_parameter(lp_ctx
, "lock spin time", "200");
2874 lpcfg_do_global_parameter(lp_ctx
, "directory name cache size", "100");
2876 lpcfg_do_global_parameter(lp_ctx
, "nmbd bind explicit broadcast", "yes");
2878 lpcfg_do_global_parameter(lp_ctx
, "init logon delay", "100");
2880 lpcfg_do_global_parameter(lp_ctx
, "usershare owner only", "yes");
2882 lpcfg_do_global_parameter(lp_ctx
, "-valid", "yes");
2884 lpcfg_do_global_parameter_var(lp_ctx
, "usershare path", "%s/usershares", get_dyn_STATEDIR());
2887 lpcfg_do_global_parameter_var(lp_ctx
, "panic action", "/bin/sleep 999999999");
2890 lpcfg_do_global_parameter(lp_ctx
, "smb passwd file", get_dyn_SMB_PASSWD_FILE());
2892 lpcfg_do_global_parameter(lp_ctx
, "logon home", "\\\\%N\\%U");
2894 lpcfg_do_global_parameter(lp_ctx
, "logon path", "\\\\%N\\%U\\profile");
2896 lpcfg_do_global_parameter(lp_ctx
, "printjob username", "%U");
2898 lpcfg_do_global_parameter(lp_ctx
, "aio max threads", "100");
2900 lpcfg_do_global_parameter(lp_ctx
, "smb2 leases", "yes");
2902 lpcfg_do_global_parameter(lp_ctx
, "kerberos encryption types", "all");
2904 /* Allow modules to adjust defaults */
2905 for (defaults_hook
= defaults_hooks
; defaults_hook
;
2906 defaults_hook
= defaults_hook
->next
) {
2909 ret
= defaults_hook
->hook(lp_ctx
);
2911 DEBUG(1, ("Defaults hook %s failed to run.",
2912 defaults_hook
->name
));
2913 talloc_free(lp_ctx
);
2918 for (i
= 0; parm_table
[i
].label
; i
++) {
2919 if (!(lp_ctx
->flags
[i
] & FLAG_CMDLINE
)) {
2920 lp_ctx
->flags
[i
] |= FLAG_DEFAULT
;
2924 for (parm
=lp_ctx
->globals
->param_opt
; parm
; parm
=parm
->next
) {
2925 if (!(parm
->priority
& FLAG_CMDLINE
)) {
2926 parm
->priority
|= FLAG_DEFAULT
;
2930 for (parm
=lp_ctx
->sDefault
->param_opt
; parm
; parm
=parm
->next
) {
2931 if (!(parm
->priority
& FLAG_CMDLINE
)) {
2932 parm
->priority
|= FLAG_DEFAULT
;
2940 * Initialise the global parameter structure.
2942 struct loadparm_context
*loadparm_init_global(bool load_default
)
2944 if (global_loadparm_context
== NULL
) {
2945 global_loadparm_context
= loadparm_init(NULL
);
2947 if (global_loadparm_context
== NULL
) {
2950 global_loadparm_context
->global
= true;
2951 if (load_default
&& !global_loadparm_context
->loaded
) {
2952 lpcfg_load_default(global_loadparm_context
);
2954 global_loadparm_context
->refuse_free
= true;
2955 return global_loadparm_context
;
2959 * Initialise the global parameter structure.
2961 struct loadparm_context
*loadparm_init_s3(TALLOC_CTX
*mem_ctx
,
2962 const struct loadparm_s3_helpers
*s3_fns
)
2964 struct loadparm_context
*loadparm_context
= talloc_zero(mem_ctx
, struct loadparm_context
);
2965 if (!loadparm_context
) {
2968 loadparm_context
->s3_fns
= s3_fns
;
2969 loadparm_context
->globals
= s3_fns
->globals
;
2970 loadparm_context
->flags
= s3_fns
->flags
;
2972 return loadparm_context
;
2975 const char *lpcfg_configfile(struct loadparm_context
*lp_ctx
)
2977 return lp_ctx
->szConfigFile
;
2980 const char *lp_default_path(void)
2982 if (getenv("SMB_CONF_PATH"))
2983 return getenv("SMB_CONF_PATH");
2985 return dyn_CONFIGFILE
;
2989 * Update the internal state of a loadparm context after settings
2992 static bool lpcfg_update(struct loadparm_context
*lp_ctx
)
2994 struct debug_settings settings
;
2995 TALLOC_CTX
*tmp_ctx
;
2997 tmp_ctx
= talloc_new(lp_ctx
);
2998 if (tmp_ctx
== NULL
) {
3002 lpcfg_add_auto_services(lp_ctx
, lpcfg_auto_services(lp_ctx
, tmp_ctx
));
3004 if (!lp_ctx
->globals
->wins_server_list
&& lp_ctx
->globals
->we_are_a_wins_server
) {
3005 lpcfg_do_global_parameter(lp_ctx
, "wins server", "127.0.0.1");
3008 if (!lp_ctx
->global
) {
3009 TALLOC_FREE(tmp_ctx
);
3013 panic_action
= lp_ctx
->globals
->panic_action
;
3015 reload_charcnv(lp_ctx
);
3017 ZERO_STRUCT(settings
);
3018 /* Add any more debug-related smb.conf parameters created in
3020 settings
.timestamp_logs
= lp_ctx
->globals
->timestamp_logs
;
3021 settings
.debug_prefix_timestamp
= lp_ctx
->globals
->debug_prefix_timestamp
;
3022 settings
.debug_hires_timestamp
= lp_ctx
->globals
->debug_hires_timestamp
;
3023 settings
.debug_pid
= lp_ctx
->globals
->debug_pid
;
3024 settings
.debug_uid
= lp_ctx
->globals
->debug_uid
;
3025 settings
.debug_class
= lp_ctx
->globals
->debug_class
;
3026 debug_set_settings(&settings
, lp_ctx
->globals
->logging
,
3027 lp_ctx
->globals
->syslog
,
3028 lp_ctx
->globals
->syslog_only
);
3030 /* FIXME: This is a bit of a hack, but we can't use a global, since
3031 * not everything that uses lp also uses the socket library */
3032 if (lpcfg_parm_bool(lp_ctx
, NULL
, "socket", "testnonblock", false)) {
3033 setenv("SOCKET_TESTNONBLOCK", "1", 1);
3035 unsetenv("SOCKET_TESTNONBLOCK");
3038 TALLOC_FREE(tmp_ctx
);
3042 bool lpcfg_load_default(struct loadparm_context
*lp_ctx
)
3046 path
= lp_default_path();
3048 if (!file_exist(path
)) {
3049 /* We allow the default smb.conf file to not exist,
3050 * basically the equivalent of an empty file. */
3051 return lpcfg_update(lp_ctx
);
3054 return lpcfg_load(lp_ctx
, path
);
3058 * Load the services array from the services file.
3060 * Return True on success, False on failure.
3062 bool lpcfg_load(struct loadparm_context
*lp_ctx
, const char *filename
)
3067 filename
= talloc_strdup(lp_ctx
, filename
);
3069 lp_ctx
->szConfigFile
= filename
;
3071 if (lp_ctx
->s3_fns
) {
3072 return lp_ctx
->s3_fns
->load(filename
);
3075 lp_ctx
->bInGlobalSection
= true;
3076 n2
= standard_sub_basic(lp_ctx
, lp_ctx
->szConfigFile
);
3077 DEBUG(2, ("lpcfg_load: refreshing parameters from %s\n", n2
));
3079 add_to_file_list(lp_ctx
, &lp_ctx
->file_lists
, lp_ctx
->szConfigFile
, n2
);
3081 /* We get sections first, so have to start 'behind' to make up */
3082 lp_ctx
->currentService
= NULL
;
3083 bRetval
= pm_process(n2
, do_section
, lpcfg_do_parameter
, lp_ctx
);
3085 /* finish up the last section */
3086 DEBUG(4, ("pm_process() returned %s\n", BOOLSTR(bRetval
)));
3088 if (lp_ctx
->currentService
!= NULL
)
3089 bRetval
= lpcfg_service_ok(lp_ctx
->currentService
);
3091 bRetval
= bRetval
&& lpcfg_update(lp_ctx
);
3093 /* we do this unconditionally, so that it happens even
3094 for a missing smb.conf */
3095 reload_charcnv(lp_ctx
);
3097 if (bRetval
== true) {
3098 /* set this up so that any child python tasks will
3099 find the right smb.conf */
3100 setenv("SMB_CONF_PATH", filename
, 1);
3102 /* set the context used by the lp_*() function
3104 global_loadparm_context
= lp_ctx
;
3105 lp_ctx
->loaded
= true;
3112 * Return the max number of services.
3115 int lpcfg_numservices(struct loadparm_context
*lp_ctx
)
3117 if (lp_ctx
->s3_fns
) {
3118 return lp_ctx
->s3_fns
->get_numservices();
3121 return lp_ctx
->iNumServices
;
3125 * Display the contents of the services array in human-readable form.
3128 void lpcfg_dump(struct loadparm_context
*lp_ctx
, FILE *f
, bool show_defaults
,
3133 if (lp_ctx
->s3_fns
) {
3134 lp_ctx
->s3_fns
->dump(f
, show_defaults
, maxtoprint
);
3138 lpcfg_dump_globals(lp_ctx
, f
, show_defaults
);
3140 lpcfg_dump_a_service(lp_ctx
->sDefault
, lp_ctx
->sDefault
, f
, lp_ctx
->flags
, show_defaults
);
3142 for (iService
= 0; iService
< maxtoprint
; iService
++)
3143 lpcfg_dump_one(f
, show_defaults
, lp_ctx
->services
[iService
], lp_ctx
->sDefault
);
3147 * Display the contents of one service in human-readable form.
3149 void lpcfg_dump_one(FILE *f
, bool show_defaults
, struct loadparm_service
*service
, struct loadparm_service
*sDefault
)
3151 if (service
!= NULL
) {
3152 if (service
->szService
[0] == '\0')
3154 lpcfg_dump_a_service(service
, sDefault
, f
, NULL
, show_defaults
);
3158 struct loadparm_service
*lpcfg_servicebynum(struct loadparm_context
*lp_ctx
,
3161 if (lp_ctx
->s3_fns
) {
3162 return lp_ctx
->s3_fns
->get_servicebynum(snum
);
3165 return lp_ctx
->services
[snum
];
3168 struct loadparm_service
*lpcfg_service(struct loadparm_context
*lp_ctx
,
3169 const char *service_name
)
3174 if (lp_ctx
->s3_fns
) {
3175 return lp_ctx
->s3_fns
->get_service(service_name
);
3178 for (iService
= lp_ctx
->iNumServices
- 1; iService
>= 0; iService
--) {
3179 if (lp_ctx
->services
[iService
] &&
3180 lp_ctx
->services
[iService
]->szService
) {
3182 * The substitution here is used to support %U is
3185 serviceName
= standard_sub_basic(
3186 lp_ctx
->services
[iService
],
3187 lp_ctx
->services
[iService
]->szService
);
3188 if (strequal(serviceName
, service_name
)) {
3189 talloc_free(serviceName
);
3190 return lp_ctx
->services
[iService
];
3192 talloc_free(serviceName
);
3196 DEBUG(7,("lpcfg_servicenumber: couldn't find %s\n", service_name
));
3200 const char *lpcfg_servicename(const struct loadparm_service
*service
)
3202 return lpcfg_string((const char *)service
->szService
);
3206 * A useful volume label function.
3208 const char *lpcfg_volume_label(struct loadparm_service
*service
, struct loadparm_service
*sDefault
)
3211 ret
= lpcfg_string((const char *)((service
!= NULL
&& service
->volume
!= NULL
) ?
3212 service
->volume
: sDefault
->volume
));
3214 return lpcfg_servicename(service
);
3219 * Return the correct printer name.
3221 const char *lpcfg_printername(struct loadparm_service
*service
, struct loadparm_service
*sDefault
)
3224 ret
= lpcfg_string((const char *)((service
!= NULL
&& service
->_printername
!= NULL
) ?
3225 service
->_printername
: sDefault
->_printername
));
3226 if (ret
== NULL
|| (ret
!= NULL
&& *ret
== '\0'))
3227 ret
= lpcfg_servicename(service
);
3234 * Return the max print jobs per queue.
3236 int lpcfg_maxprintjobs(struct loadparm_service
*service
, struct loadparm_service
*sDefault
)
3238 int maxjobs
= lpcfg_max_print_jobs(service
, sDefault
);
3240 if (maxjobs
<= 0 || maxjobs
>= PRINT_MAX_JOBID
)
3241 maxjobs
= PRINT_MAX_JOBID
- 1;
3246 struct smb_iconv_handle
*lpcfg_iconv_handle(struct loadparm_context
*lp_ctx
)
3248 if (lp_ctx
== NULL
) {
3249 return get_iconv_handle();
3251 return lp_ctx
->iconv_handle
;
3254 _PUBLIC_
void reload_charcnv(struct loadparm_context
*lp_ctx
)
3256 struct smb_iconv_handle
*old_ic
= lp_ctx
->iconv_handle
;
3257 if (!lp_ctx
->global
) {
3261 if (old_ic
== NULL
) {
3262 old_ic
= global_iconv_handle
;
3264 lp_ctx
->iconv_handle
= smb_iconv_handle_reinit_lp(lp_ctx
, lp_ctx
, old_ic
);
3265 global_iconv_handle
= lp_ctx
->iconv_handle
;
3268 _PUBLIC_
char *lpcfg_tls_keyfile(TALLOC_CTX
*mem_ctx
, struct loadparm_context
*lp_ctx
)
3270 return lpcfg_private_path(mem_ctx
, lp_ctx
, lpcfg__tls_keyfile(lp_ctx
));
3273 _PUBLIC_
char *lpcfg_tls_certfile(TALLOC_CTX
*mem_ctx
, struct loadparm_context
*lp_ctx
)
3275 return lpcfg_private_path(mem_ctx
, lp_ctx
, lpcfg__tls_certfile(lp_ctx
));
3278 _PUBLIC_
char *lpcfg_tls_cafile(TALLOC_CTX
*mem_ctx
, struct loadparm_context
*lp_ctx
)
3280 return lpcfg_private_path(mem_ctx
, lp_ctx
, lpcfg__tls_cafile(lp_ctx
));
3283 _PUBLIC_
char *lpcfg_tls_crlfile(TALLOC_CTX
*mem_ctx
, struct loadparm_context
*lp_ctx
)
3285 return lpcfg_private_path(mem_ctx
, lp_ctx
, lpcfg__tls_crlfile(lp_ctx
));
3288 _PUBLIC_
char *lpcfg_tls_dhpfile(TALLOC_CTX
*mem_ctx
, struct loadparm_context
*lp_ctx
)
3290 return lpcfg_private_path(mem_ctx
, lp_ctx
, lpcfg__tls_dhpfile(lp_ctx
));
3293 struct gensec_settings
*lpcfg_gensec_settings(TALLOC_CTX
*mem_ctx
, struct loadparm_context
*lp_ctx
)
3295 struct gensec_settings
*settings
= talloc_zero(mem_ctx
, struct gensec_settings
);
3296 if (settings
== NULL
)
3298 SMB_ASSERT(lp_ctx
!= NULL
);
3299 settings
->lp_ctx
= talloc_reference(settings
, lp_ctx
);
3300 settings
->target_hostname
= lpcfg_parm_string(lp_ctx
, NULL
, "gensec", "target_hostname");
3304 int lpcfg_server_role(struct loadparm_context
*lp_ctx
)
3306 int domain_master
= lpcfg__domain_master(lp_ctx
);
3308 return lp_find_server_role(lpcfg__server_role(lp_ctx
),
3309 lpcfg__security(lp_ctx
),
3310 lpcfg__domain_logons(lp_ctx
),
3311 (domain_master
== true) ||
3312 (domain_master
== Auto
));
3315 int lpcfg_security(struct loadparm_context
*lp_ctx
)
3317 return lp_find_security(lpcfg__server_role(lp_ctx
),
3318 lpcfg__security(lp_ctx
));
3321 int lpcfg_client_max_protocol(struct loadparm_context
*lp_ctx
)
3323 int client_max_protocol
= lpcfg__client_max_protocol(lp_ctx
);
3324 if (client_max_protocol
== PROTOCOL_DEFAULT
) {
3325 return PROTOCOL_NT1
;
3327 return client_max_protocol
;
3330 int lpcfg_client_ipc_min_protocol(struct loadparm_context
*lp_ctx
)
3332 int client_ipc_min_protocol
= lpcfg__client_ipc_min_protocol(lp_ctx
);
3333 if (client_ipc_min_protocol
== PROTOCOL_DEFAULT
) {
3334 client_ipc_min_protocol
= lpcfg_client_min_protocol(lp_ctx
);
3336 if (client_ipc_min_protocol
< PROTOCOL_NT1
) {
3337 return PROTOCOL_NT1
;
3339 return client_ipc_min_protocol
;
3342 int lpcfg_client_ipc_max_protocol(struct loadparm_context
*lp_ctx
)
3344 int client_ipc_max_protocol
= lpcfg__client_ipc_max_protocol(lp_ctx
);
3345 if (client_ipc_max_protocol
== PROTOCOL_DEFAULT
) {
3346 return PROTOCOL_LATEST
;
3348 if (client_ipc_max_protocol
< PROTOCOL_NT1
) {
3349 return PROTOCOL_NT1
;
3351 return client_ipc_max_protocol
;
3354 int lpcfg_client_ipc_signing(struct loadparm_context
*lp_ctx
)
3356 int client_ipc_signing
= lpcfg__client_ipc_signing(lp_ctx
);
3357 if (client_ipc_signing
== SMB_SIGNING_DEFAULT
) {
3358 return SMB_SIGNING_REQUIRED
;
3360 return client_ipc_signing
;
3363 bool lpcfg_server_signing_allowed(struct loadparm_context
*lp_ctx
, bool *mandatory
)
3365 bool allowed
= true;
3366 enum smb_signing_setting signing_setting
= lpcfg_server_signing(lp_ctx
);
3370 if (signing_setting
== SMB_SIGNING_DEFAULT
) {
3372 * If we are a domain controller, SMB signing is
3373 * really important, as it can prevent a number of
3374 * attacks on communications between us and the
3377 * However, it really sucks (no sendfile, CPU
3378 * overhead) performance-wise when used on a
3379 * file server, so disable it by default
3383 if (lpcfg_server_role(lp_ctx
) >= ROLE_ACTIVE_DIRECTORY_DC
) {
3384 signing_setting
= SMB_SIGNING_REQUIRED
;
3386 signing_setting
= SMB_SIGNING_OFF
;
3390 switch (signing_setting
) {
3391 case SMB_SIGNING_REQUIRED
:
3394 case SMB_SIGNING_DESIRED
:
3395 case SMB_SIGNING_IF_REQUIRED
:
3397 case SMB_SIGNING_OFF
:
3400 case SMB_SIGNING_DEFAULT
:
3401 case SMB_SIGNING_IPC_DEFAULT
:
3402 smb_panic(__location__
);
3409 int lpcfg_tdb_hash_size(struct loadparm_context
*lp_ctx
, const char *name
)
3417 base
= strrchr_m(name
, '/');
3423 return lpcfg_parm_int(lp_ctx
, NULL
, "tdb_hashsize", base
, 0);
3427 int lpcfg_tdb_flags(struct loadparm_context
*lp_ctx
, int tdb_flags
)
3429 if (!lpcfg_use_mmap(lp_ctx
)) {
3430 tdb_flags
|= TDB_NOMMAP
;