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"
72 #include "lib/util/samba_util.h"
74 #ifdef HAVE_HTTPCONNECTENCRYPT
75 #include <cups/http.h>
78 #define standard_sub_basic talloc_strdup
80 #include "lib/param/param_global.h"
82 struct loadparm_service
*lpcfg_default_service(struct loadparm_context
*lp_ctx
)
84 return lp_ctx
->sDefault
;
87 int lpcfg_rpc_low_port(struct loadparm_context
*lp_ctx
)
89 return lp_ctx
->globals
->rpc_low_port
;
92 int lpcfg_rpc_high_port(struct loadparm_context
*lp_ctx
)
94 return lp_ctx
->globals
->rpc_high_port
;
98 * Convenience routine to grab string parameters into temporary memory
99 * and run standard_sub_basic on them.
101 * The buffers can be written to by
102 * callers without affecting the source string.
105 static const char *lpcfg_string(const char *s
)
107 #if 0 /* until REWRITE done to make thread-safe */
108 size_t len
= s
? strlen(s
) : 0;
112 /* The follow debug is useful for tracking down memory problems
113 especially if you have an inner loop that is calling a lp_*()
114 function that returns a string. Perhaps this debug should be
115 present all the time? */
118 DEBUG(10, ("lpcfg_string(%s)\n", s
));
121 #if 0 /* until REWRITE done to make thread-safe */
123 lp_talloc
= talloc_init("lp_talloc");
125 ret
= talloc_array(lp_talloc
, char, len
+ 100); /* leave room for substitution */
133 strlcpy(ret
, s
, len
);
135 if (trim_string(ret
, "\"", "\"")) {
136 if (strchr(ret
,'"') != NULL
)
137 strlcpy(ret
, s
, len
);
140 standard_sub_basic(ret
,len
+100);
147 In this section all the functions that are used to access the
148 parameters from the rest of the program are defined
152 * the creation of separate lpcfg_*() and lp_*() functions is to allow
153 * for code compatibility between existing Samba4 and Samba3 code.
156 /* this global context supports the lp_*() function varients */
157 static struct loadparm_context
*global_loadparm_context
;
159 #define FN_GLOBAL_STRING(fn_name,var_name) \
160 _PUBLIC_ char *lpcfg_ ## fn_name(struct loadparm_context *lp_ctx, TALLOC_CTX *ctx) {\
161 if (lp_ctx == NULL) return NULL; \
162 if (lp_ctx->s3_fns) { \
163 return lp_ctx->globals->var_name ? lp_ctx->s3_fns->lp_string(ctx, lp_ctx->globals->var_name) : talloc_strdup(ctx, ""); \
165 return lp_ctx->globals->var_name ? talloc_strdup(ctx, lpcfg_string(lp_ctx->globals->var_name)) : talloc_strdup(ctx, ""); \
168 #define FN_GLOBAL_CONST_STRING(fn_name,var_name) \
169 _PUBLIC_ const char *lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) { \
170 if (lp_ctx == NULL) return NULL; \
171 return lp_ctx->globals->var_name ? lpcfg_string(lp_ctx->globals->var_name) : ""; \
174 #define FN_GLOBAL_LIST(fn_name,var_name) \
175 _PUBLIC_ const char **lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) { \
176 if (lp_ctx == NULL) return NULL; \
177 return lp_ctx->globals->var_name; \
180 #define FN_GLOBAL_BOOL(fn_name,var_name) \
181 _PUBLIC_ bool lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) {\
182 if (lp_ctx == NULL) return false; \
183 return lp_ctx->globals->var_name; \
186 #define FN_GLOBAL_INTEGER(fn_name,var_name) \
187 _PUBLIC_ int lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) { \
188 return lp_ctx->globals->var_name; \
191 /* Local parameters don't need the ->s3_fns because the struct
192 * loadparm_service is shared and lpcfg_service() checks the ->s3_fns
194 #define FN_LOCAL_STRING(fn_name,val) \
195 _PUBLIC_ char *lpcfg_ ## fn_name(struct loadparm_service *service, \
196 struct loadparm_service *sDefault, TALLOC_CTX *ctx) { \
197 return(talloc_strdup(ctx, lpcfg_string((const char *)((service != NULL && service->val != NULL) ? service->val : sDefault->val)))); \
200 #define FN_LOCAL_CONST_STRING(fn_name,val) \
201 _PUBLIC_ const char *lpcfg_ ## fn_name(struct loadparm_service *service, \
202 struct loadparm_service *sDefault) { \
203 return((const char *)((service != NULL && service->val != NULL) ? service->val : sDefault->val)); \
206 #define FN_LOCAL_LIST(fn_name,val) \
207 _PUBLIC_ const char **lpcfg_ ## fn_name(struct loadparm_service *service, \
208 struct loadparm_service *sDefault) {\
209 return(const char **)(service != NULL && service->val != NULL? service->val : sDefault->val); \
212 #define FN_LOCAL_PARM_BOOL(fn_name, val) FN_LOCAL_BOOL(fn_name, val)
214 #define FN_LOCAL_BOOL(fn_name,val) \
215 _PUBLIC_ bool lpcfg_ ## fn_name(struct loadparm_service *service, \
216 struct loadparm_service *sDefault) { \
217 return((service != NULL)? service->val : sDefault->val); \
220 #define FN_LOCAL_INTEGER(fn_name,val) \
221 _PUBLIC_ int lpcfg_ ## fn_name(struct loadparm_service *service, \
222 struct loadparm_service *sDefault) { \
223 return((service != NULL)? service->val : sDefault->val); \
226 #define FN_LOCAL_PARM_INTEGER(fn_name, val) FN_LOCAL_INTEGER(fn_name, val)
228 #define FN_LOCAL_CHAR(fn_name,val) \
229 _PUBLIC_ char lpcfg_ ## fn_name(struct loadparm_service *service, \
230 struct loadparm_service *sDefault) { \
231 return((service != NULL)? service->val : sDefault->val); \
234 #define FN_LOCAL_PARM_CHAR(fn_name,val) FN_LOCAL_CHAR(fn_name, val)
236 #include "lib/param/param_functions.c"
238 /* These functions cannot be auto-generated */
239 FN_LOCAL_BOOL(autoloaded
, autoloaded
)
240 FN_GLOBAL_CONST_STRING(dnsdomain
, dnsdomain
)
242 /* local prototypes */
243 static struct loadparm_service
*lpcfg_getservicebyname(struct loadparm_context
*lp_ctx
,
244 const char *pszServiceName
);
245 static bool do_section(const char *pszSectionName
, void *);
246 static bool set_variable_helper(TALLOC_CTX
*mem_ctx
, int parmnum
, void *parm_ptr
,
247 const char *pszParmName
, const char *pszParmValue
);
248 static bool lp_do_parameter_parametric(struct loadparm_context
*lp_ctx
,
249 struct loadparm_service
*service
,
250 const char *pszParmName
,
251 const char *pszParmValue
, int flags
);
253 /* The following are helper functions for parametrical options support. */
254 /* It returns a pointer to parametrical option value if it exists or NULL otherwise */
255 /* Actual parametrical functions are quite simple */
256 struct parmlist_entry
*get_parametric_helper(struct loadparm_service
*service
,
257 const char *type
, const char *option
,
258 struct parmlist_entry
*global_opts
)
260 size_t type_len
= strlen(type
);
261 size_t option_len
= strlen(option
);
262 char param_key
[type_len
+ option_len
+ 2];
263 struct parmlist_entry
*data
= NULL
;
265 snprintf(param_key
, sizeof(param_key
), "%s:%s", type
, option
);
268 * Try to fetch the option from the data.
270 if (service
!= NULL
) {
271 data
= service
->param_opt
;
272 while (data
!= NULL
) {
273 if (strwicmp(data
->key
, param_key
) == 0) {
281 * Fall back to fetching from the globals.
284 while (data
!= NULL
) {
285 if (strwicmp(data
->key
, param_key
) == 0) {
294 const char *lpcfg_get_parametric(struct loadparm_context
*lp_ctx
,
295 struct loadparm_service
*service
,
296 const char *type
, const char *option
)
298 struct parmlist_entry
*data
;
303 data
= get_parametric_helper(service
,
304 type
, option
, lp_ctx
->globals
->param_opt
);
315 * convenience routine to return int parameters.
317 int lp_int(const char *s
)
321 DEBUG(0,("lp_int(%s): is called with NULL!\n",s
));
325 return strtol(s
, NULL
, 0);
329 * convenience routine to return unsigned long parameters.
331 unsigned long lp_ulong(const char *s
)
335 DEBUG(0,("lp_ulong(%s): is called with NULL!\n",s
));
339 return strtoul(s
, NULL
, 0);
343 * convenience routine to return unsigned long long parameters.
345 unsigned long long lp_ulonglong(const char *s
)
349 DEBUG(0, ("lp_ulonglong(%s): is called with NULL!\n", s
));
353 return strtoull(s
, NULL
, 0);
357 * convenience routine to return unsigned long parameters.
359 static long lp_long(const char *s
)
363 DEBUG(0,("lp_long(%s): is called with NULL!\n",s
));
367 return strtol(s
, NULL
, 0);
371 * convenience routine to return unsigned long parameters.
373 static double lp_double(const char *s
)
377 DEBUG(0,("lp_double(%s): is called with NULL!\n",s
));
381 return strtod(s
, NULL
);
385 * convenience routine to return boolean parameters.
387 bool lp_bool(const char *s
)
392 DEBUG(0,("lp_bool(%s): is called with NULL!\n",s
));
396 if (!set_boolean(s
, &ret
)) {
397 DEBUG(0,("lp_bool(%s): value is not boolean!\n",s
));
405 * Return parametric option from a given service. Type is a part of option before ':'
406 * Parametric option has following syntax: 'Type: option = value'
407 * Returned value is allocated in 'lp_talloc' context
410 const char *lpcfg_parm_string(struct loadparm_context
*lp_ctx
,
411 struct loadparm_service
*service
, const char *type
,
414 const char *value
= lpcfg_get_parametric(lp_ctx
, service
, type
, option
);
417 return lpcfg_string(value
);
423 * Return parametric option from a given service. Type is a part of option before ':'
424 * Parametric option has following syntax: 'Type: option = value'
425 * Returned value is allocated in 'lp_talloc' context
428 const char **lpcfg_parm_string_list(TALLOC_CTX
*mem_ctx
,
429 struct loadparm_context
*lp_ctx
,
430 struct loadparm_service
*service
,
432 const char *option
, const char *separator
)
434 const char *value
= lpcfg_get_parametric(lp_ctx
, service
, type
, option
);
437 char **l
= str_list_make(mem_ctx
, value
, separator
);
438 return discard_const_p(const char *, l
);
445 * Return parametric option from a given service. Type is a part of option before ':'
446 * Parametric option has following syntax: 'Type: option = value'
449 int lpcfg_parm_int(struct loadparm_context
*lp_ctx
,
450 struct loadparm_service
*service
, const char *type
,
451 const char *option
, int default_v
)
453 const char *value
= lpcfg_get_parametric(lp_ctx
, service
, type
, option
);
456 return lp_int(value
);
462 * Return parametric option from a given service. Type is a part of
464 * Parametric option has following syntax: 'Type: option = value'.
467 int lpcfg_parm_bytes(struct loadparm_context
*lp_ctx
,
468 struct loadparm_service
*service
, const char *type
,
469 const char *option
, int default_v
)
473 const char *value
= lpcfg_get_parametric(lp_ctx
, service
, type
, option
);
475 if (value
&& conv_str_size_error(value
, &bval
)) {
476 if (bval
<= INT_MAX
) {
485 * Return parametric option from a given service.
486 * Type is a part of option before ':'
487 * Parametric option has following syntax: 'Type: option = value'
489 unsigned long lpcfg_parm_ulong(struct loadparm_context
*lp_ctx
,
490 struct loadparm_service
*service
, const char *type
,
491 const char *option
, unsigned long default_v
)
493 const char *value
= lpcfg_get_parametric(lp_ctx
, service
, type
, option
);
496 return lp_ulong(value
);
502 * Return parametric option from a given service.
503 * Type is a part of option before ':'
504 * Parametric option has following syntax: 'Type: option = value'
506 unsigned long long lpcfg_parm_ulonglong(struct loadparm_context
*lp_ctx
,
507 struct loadparm_service
*service
,
508 const char *type
, const char *option
,
509 unsigned long long default_v
)
511 const char *value
= lpcfg_get_parametric(lp_ctx
, service
, type
, option
);
514 return lp_ulonglong(value
);
520 long lpcfg_parm_long(struct loadparm_context
*lp_ctx
,
521 struct loadparm_service
*service
, const char *type
,
522 const char *option
, long default_v
)
524 const char *value
= lpcfg_get_parametric(lp_ctx
, service
, type
, option
);
527 return lp_long(value
);
532 double lpcfg_parm_double(struct loadparm_context
*lp_ctx
,
533 struct loadparm_service
*service
, const char *type
,
534 const char *option
, double default_v
)
536 const char *value
= lpcfg_get_parametric(lp_ctx
, service
, type
, option
);
539 return lp_double(value
);
545 * Return parametric option from a given service. Type is a part of option before ':'
546 * Parametric option has following syntax: 'Type: option = value'
549 bool lpcfg_parm_bool(struct loadparm_context
*lp_ctx
,
550 struct loadparm_service
*service
, const char *type
,
551 const char *option
, bool default_v
)
553 const char *value
= lpcfg_get_parametric(lp_ctx
, service
, type
, option
);
556 return lp_bool(value
);
562 /* this is used to prevent lots of mallocs of size 1 */
563 static const char lpcfg_string_empty
[] = "";
568 void lpcfg_string_free(char **s
)
573 if (*s
== lpcfg_string_empty
) {
581 * Set a string value, deallocating any existing space, and allocing the space
584 bool lpcfg_string_set(TALLOC_CTX
*mem_ctx
, char **dest
, const char *src
)
586 lpcfg_string_free(dest
);
588 if ((src
== NULL
) || (*src
== '\0')) {
589 *dest
= discard_const_p(char, lpcfg_string_empty
);
593 *dest
= talloc_strdup(mem_ctx
, src
);
594 if ((*dest
) == NULL
) {
595 DEBUG(0,("Out of memory in string_set\n"));
603 * Set a string value, deallocating any existing space, and allocing the space
606 bool lpcfg_string_set_upper(TALLOC_CTX
*mem_ctx
, char **dest
, const char *src
)
608 lpcfg_string_free(dest
);
610 if ((src
== NULL
) || (*src
== '\0')) {
611 *dest
= discard_const_p(char, lpcfg_string_empty
);
615 *dest
= strupper_talloc(mem_ctx
, src
);
616 if ((*dest
) == NULL
) {
617 DEBUG(0,("Out of memory in string_set_upper\n"));
627 * Add a new service to the services array initialising it with the given
631 struct loadparm_service
*lpcfg_add_service(struct loadparm_context
*lp_ctx
,
632 const struct loadparm_service
*pservice
,
636 int num_to_alloc
= lp_ctx
->iNumServices
+ 1;
637 struct parmlist_entry
*data
, *pdata
;
639 if (lp_ctx
->s3_fns
!= NULL
) {
640 smb_panic("Add a service should not be called on an s3 loadparm ctx");
643 if (pservice
== NULL
) {
644 pservice
= lp_ctx
->sDefault
;
647 /* it might already exist */
649 struct loadparm_service
*service
= lpcfg_getservicebyname(lp_ctx
,
651 if (service
!= NULL
) {
652 /* Clean all parametric options for service */
653 /* They will be added during parsing again */
654 data
= service
->param_opt
;
660 service
->param_opt
= NULL
;
665 /* find an invalid one */
666 for (i
= 0; i
< lp_ctx
->iNumServices
; i
++)
667 if (lp_ctx
->services
[i
] == NULL
)
670 /* if not, then create one */
671 if (i
== lp_ctx
->iNumServices
) {
672 struct loadparm_service
**tsp
;
674 tsp
= talloc_realloc(lp_ctx
, lp_ctx
->services
, struct loadparm_service
*, num_to_alloc
);
677 DEBUG(0,("lpcfg_add_service: failed to enlarge services!\n"));
680 lp_ctx
->services
= tsp
;
681 lp_ctx
->services
[lp_ctx
->iNumServices
] = NULL
;
684 lp_ctx
->iNumServices
++;
687 lp_ctx
->services
[i
] = talloc_zero(lp_ctx
->services
, struct loadparm_service
);
688 if (lp_ctx
->services
[i
] == NULL
) {
689 DEBUG(0,("lpcfg_add_service: out of memory!\n"));
692 copy_service(lp_ctx
->services
[i
], pservice
, NULL
);
694 lpcfg_string_set(lp_ctx
->services
[i
], &lp_ctx
->services
[i
]->szService
, name
);
695 return lp_ctx
->services
[i
];
699 * Add a new home service, with the specified home directory, defaults coming
700 * from service ifrom.
703 bool lpcfg_add_home(struct loadparm_context
*lp_ctx
,
704 const char *pszHomename
,
705 struct loadparm_service
*default_service
,
706 const char *user
, const char *pszHomedir
)
708 struct loadparm_service
*service
;
710 service
= lpcfg_add_service(lp_ctx
, default_service
, pszHomename
);
715 if (!(*(default_service
->path
))
716 || strequal(default_service
->path
, lp_ctx
->sDefault
->path
)) {
717 service
->path
= talloc_strdup(service
, pszHomedir
);
719 service
->path
= string_sub_talloc(service
, lpcfg_path(default_service
, lp_ctx
->sDefault
, service
), "%H", pszHomedir
);
722 if (!(*(service
->comment
))) {
723 service
->comment
= talloc_asprintf(service
, "Home directory of %s", user
);
725 service
->available
= default_service
->available
;
726 service
->browseable
= default_service
->browseable
;
728 DEBUG(3, ("adding home's share [%s] for user '%s' at '%s'\n",
729 pszHomename
, user
, service
->path
));
735 * Add a new printer service, with defaults coming from service iFrom.
738 bool lpcfg_add_printer(struct loadparm_context
*lp_ctx
,
739 const char *pszPrintername
,
740 struct loadparm_service
*default_service
)
742 const char *comment
= "From Printcap";
743 struct loadparm_service
*service
;
744 service
= lpcfg_add_service(lp_ctx
, default_service
, pszPrintername
);
749 /* note that we do NOT default the availability flag to True - */
750 /* we take it from the default service passed. This allows all */
751 /* dynamic printers to be disabled by disabling the [printers] */
752 /* entry (if/when the 'available' keyword is implemented!). */
754 /* the printer name is set to the service name. */
755 lpcfg_string_set(service
, &service
->_printername
, pszPrintername
);
756 lpcfg_string_set(service
, &service
->comment
, comment
);
757 service
->browseable
= default_service
->browseable
;
758 /* Printers cannot be read_only. */
759 service
->read_only
= false;
760 /* Printer services must be printable. */
761 service
->printable
= true;
763 DEBUG(3, ("adding printer service %s\n", pszPrintername
));
769 * Map a parameter's string representation to something we can use.
770 * Returns False if the parameter string is not recognised, else TRUE.
773 int lpcfg_map_parameter(const char *pszParmName
)
777 for (iIndex
= 0; parm_table
[iIndex
].label
; iIndex
++)
778 if (strwicmp(parm_table
[iIndex
].label
, pszParmName
) == 0)
781 /* Warn only if it isn't parametric option */
782 if (strchr(pszParmName
, ':') == NULL
)
783 DEBUG(0, ("Unknown parameter encountered: \"%s\"\n", pszParmName
));
784 /* We do return 'fail' for parametric options as well because they are
785 stored in different storage
792 return the parameter structure for a parameter
794 struct parm_struct
*lpcfg_parm_struct(struct loadparm_context
*lp_ctx
, const char *name
)
796 int num
= lpcfg_map_parameter(name
);
802 return &parm_table
[num
];
806 return the parameter pointer for a parameter
808 void *lpcfg_parm_ptr(struct loadparm_context
*lp_ctx
,
809 struct loadparm_service
*service
, struct parm_struct
*parm
)
811 if (lp_ctx
->s3_fns
) {
812 return lp_ctx
->s3_fns
->get_parm_ptr(service
, parm
);
815 if (service
== NULL
) {
816 if (parm
->p_class
== P_LOCAL
)
817 return ((char *)lp_ctx
->sDefault
)+parm
->offset
;
818 else if (parm
->p_class
== P_GLOBAL
)
819 return ((char *)lp_ctx
->globals
)+parm
->offset
;
822 return ((char *)service
) + parm
->offset
;
827 return the parameter pointer for a parameter
829 bool lpcfg_parm_is_cmdline(struct loadparm_context
*lp_ctx
, const char *name
)
833 parmnum
= lpcfg_map_parameter(name
);
834 if (parmnum
== -1) return false;
836 return lp_ctx
->flags
[parmnum
] & FLAG_CMDLINE
;
840 * Find a service by name. Otherwise works like get_service.
843 static struct loadparm_service
*lpcfg_getservicebyname(struct loadparm_context
*lp_ctx
,
844 const char *pszServiceName
)
848 if (lp_ctx
->s3_fns
) {
849 return lp_ctx
->s3_fns
->get_service(pszServiceName
);
852 for (iService
= lp_ctx
->iNumServices
- 1; iService
>= 0; iService
--)
853 if (lp_ctx
->services
[iService
] != NULL
&&
854 strwicmp(lp_ctx
->services
[iService
]->szService
, pszServiceName
) == 0) {
855 return lp_ctx
->services
[iService
];
862 * Add a parametric option to a parmlist_entry,
863 * replacing old value, if already present.
865 void set_param_opt(TALLOC_CTX
*mem_ctx
,
866 struct parmlist_entry
**opt_list
,
867 const char *opt_name
,
868 const char *opt_value
,
871 struct parmlist_entry
*new_opt
, *opt
;
875 /* Traverse destination */
877 /* If we already have same option, override it */
878 if (strwicmp(opt
->key
, opt_name
) == 0) {
879 if ((opt
->priority
& FLAG_CMDLINE
) &&
880 !(priority
& FLAG_CMDLINE
)) {
881 /* it's been marked as not to be
885 TALLOC_FREE(opt
->list
);
886 lpcfg_string_set(opt
, &opt
->value
, opt_value
);
887 opt
->priority
= priority
;
893 new_opt
= talloc_pooled_object(
894 mem_ctx
, struct parmlist_entry
,
895 2, strlen(opt_name
) + 1 + strlen(opt_value
) + 1);
896 if (new_opt
== NULL
) {
900 lpcfg_string_set(new_opt
, &new_opt
->key
, opt_name
);
901 new_opt
->value
= NULL
;
902 lpcfg_string_set(new_opt
, &new_opt
->value
, opt_value
);
904 new_opt
->list
= NULL
;
905 new_opt
->priority
= priority
;
906 DLIST_ADD(*opt_list
, new_opt
);
910 * Copy a service structure to another.
911 * If pcopymapDest is NULL then copy all fields
914 void copy_service(struct loadparm_service
*pserviceDest
,
915 const struct loadparm_service
*pserviceSource
,
916 struct bitmap
*pcopymapDest
)
919 bool bcopyall
= (pcopymapDest
== NULL
);
920 struct parmlist_entry
*data
;
922 for (i
= 0; parm_table
[i
].label
; i
++)
923 if (parm_table
[i
].p_class
== P_LOCAL
&&
924 (bcopyall
|| bitmap_query(pcopymapDest
, i
))) {
925 const void *src_ptr
=
926 ((const char *)pserviceSource
) + parm_table
[i
].offset
;
928 ((char *)pserviceDest
) + parm_table
[i
].offset
;
930 switch (parm_table
[i
].type
) {
933 *(bool *)dest_ptr
= *(const bool *)src_ptr
;
940 *(int *)dest_ptr
= *(const int *)src_ptr
;
944 *(char *)dest_ptr
= *(const char *)src_ptr
;
948 lpcfg_string_set(pserviceDest
,
950 *(const char * const *)src_ptr
);
954 lpcfg_string_set_upper(pserviceDest
,
956 *(const char * const *)src_ptr
);
960 TALLOC_FREE(*((char ***)dest_ptr
));
961 *(char ***)dest_ptr
= str_list_copy(pserviceDest
,
962 *discard_const_p(const char **, src_ptr
));
970 init_copymap(pserviceDest
);
971 if (pserviceSource
->copymap
)
972 bitmap_copy(pserviceDest
->copymap
,
973 pserviceSource
->copymap
);
976 for (data
= pserviceSource
->param_opt
; data
!= NULL
; data
= data
->next
) {
977 set_param_opt(pserviceDest
, &pserviceDest
->param_opt
,
978 data
->key
, data
->value
, data
->priority
);
983 * Check a service for consistency. Return False if the service is in any way
984 * incomplete or faulty, else True.
986 bool lpcfg_service_ok(struct loadparm_service
*service
)
991 if (service
->szService
[0] == '\0') {
992 DEBUG(0, ("The following message indicates an internal error:\n"));
993 DEBUG(0, ("No service name in service entry.\n"));
997 /* The [printers] entry MUST be printable. I'm all for flexibility, but */
998 /* I can't see why you'd want a non-printable printer service... */
999 if (strwicmp(service
->szService
, PRINTERS_NAME
) == 0) {
1000 if (!service
->printable
) {
1001 DEBUG(0, ("WARNING: [%s] service MUST be printable!\n",
1002 service
->szService
));
1003 service
->printable
= true;
1005 /* [printers] service must also be non-browsable. */
1006 if (service
->browseable
)
1007 service
->browseable
= false;
1010 if (service
->path
[0] == '\0' &&
1011 strwicmp(service
->szService
, HOMES_NAME
) != 0 &&
1012 service
->msdfs_proxy
[0] == '\0')
1014 DEBUG(0, ("WARNING: No path in service %s - making it unavailable!\n",
1015 service
->szService
));
1016 service
->available
= false;
1019 if (!service
->available
)
1020 DEBUG(1, ("NOTE: Service %s is flagged unavailable.\n",
1021 service
->szService
));
1027 /*******************************************************************
1028 Keep a linked list of all config files so we know when one has changed
1029 it's date and needs to be reloaded.
1030 ********************************************************************/
1032 void add_to_file_list(TALLOC_CTX
*mem_ctx
, struct file_lists
**list
,
1033 const char *fname
, const char *subfname
)
1035 struct file_lists
*f
= *list
;
1038 if (f
->name
&& !strcmp(f
->name
, fname
))
1044 f
= talloc(mem_ctx
, struct file_lists
);
1048 f
->name
= talloc_strdup(f
, fname
);
1053 f
->subfname
= talloc_strdup(f
, subfname
);
1059 f
->modtime
= file_modtime(subfname
);
1061 time_t t
= file_modtime(subfname
);
1068 DEBUG(0, ("Unable to add file to file list: %s\n", fname
));
1072 /*******************************************************************
1073 Check if a config file has changed date.
1074 ********************************************************************/
1075 bool lpcfg_file_list_changed(struct loadparm_context
*lp_ctx
)
1077 struct file_lists
*f
;
1078 DEBUG(6, ("lpcfg_file_list_changed()\n"));
1080 for (f
= lp_ctx
->file_lists
; f
!= NULL
; f
= f
->next
) {
1084 n2
= standard_sub_basic(lp_ctx
, f
->name
);
1086 DEBUGADD(6, ("file %s -> %s last mod_time: %s\n",
1087 f
->name
, n2
, ctime(&f
->modtime
)));
1089 mod_time
= file_modtime(n2
);
1091 if (mod_time
&& ((f
->modtime
!= mod_time
) || (f
->subfname
== NULL
) || (strcmp(n2
, f
->subfname
) != 0))) {
1092 DEBUGADD(6, ("file %s modified: %s\n", n2
,
1094 f
->modtime
= mod_time
;
1095 talloc_free(f
->subfname
);
1096 f
->subfname
= talloc_strdup(f
, n2
);
1106 * set the value for a P_ENUM
1108 bool lp_set_enum_parm( struct parm_struct
*parm
, const char *pszParmValue
,
1113 for (i
= 0; parm
->enum_list
[i
].name
; i
++) {
1114 if (strwicmp(pszParmValue
, parm
->enum_list
[i
].name
) == 0) {
1115 *ptr
= parm
->enum_list
[i
].value
;
1119 DEBUG(0, ("WARNING: Ignoring invalid value '%s' for parameter '%s'\n",
1120 pszParmValue
, parm
->label
));
1125 /***************************************************************************
1126 Handle the "realm" parameter
1127 ***************************************************************************/
1129 bool handle_realm(struct loadparm_context
*lp_ctx
, struct loadparm_service
*service
,
1130 const char *pszParmValue
, char **ptr
)
1135 upper
= strupper_talloc(lp_ctx
, pszParmValue
);
1136 if (upper
== NULL
) {
1140 lower
= strlower_talloc(lp_ctx
, pszParmValue
);
1141 if (lower
== NULL
) {
1146 lpcfg_string_set(lp_ctx
->globals
->ctx
, &lp_ctx
->globals
->realm_original
, pszParmValue
);
1147 lpcfg_string_set(lp_ctx
->globals
->ctx
, &lp_ctx
->globals
->realm
, upper
);
1148 lpcfg_string_set(lp_ctx
->globals
->ctx
, &lp_ctx
->globals
->dnsdomain
, lower
);
1153 /***************************************************************************
1154 Handle the include operation.
1155 ***************************************************************************/
1157 bool handle_include(struct loadparm_context
*lp_ctx
, struct loadparm_service
*service
,
1158 const char *pszParmValue
, char **ptr
)
1161 const char *substitution_variable_substring
;
1164 if (lp_ctx
->s3_fns
) {
1165 return lp_ctx
->s3_fns
->lp_include(lp_ctx
, service
, pszParmValue
, ptr
);
1168 fname
= standard_sub_basic(lp_ctx
, pszParmValue
);
1170 add_to_file_list(lp_ctx
, &lp_ctx
->file_lists
, pszParmValue
, fname
);
1172 lpcfg_string_set(lp_ctx
, ptr
, fname
);
1174 if (file_exist(fname
))
1175 return pm_process(fname
, do_section
, lpcfg_do_parameter
, lp_ctx
);
1178 * If the file doesn't exist, we check that it isn't due to variable
1181 substitution_variable_substring
= strchr(fname
, '%');
1183 if (substitution_variable_substring
!= NULL
) {
1184 next_char
= substitution_variable_substring
[1];
1185 if ((next_char
>= 'a' && next_char
<= 'z')
1186 || (next_char
>= 'A' && next_char
<= 'Z')) {
1187 DEBUG(2, ("Tried to load %s but variable substitution in "
1188 "filename, ignoring file.\n", fname
));
1193 DEBUG(2, ("Can't find include file %s\n", fname
));
1198 /***************************************************************************
1199 Handle the interpretation of the copy parameter.
1200 ***************************************************************************/
1202 bool handle_copy(struct loadparm_context
*lp_ctx
, struct loadparm_service
*service
,
1203 const char *pszParmValue
, char **ptr
)
1206 struct loadparm_service
*serviceTemp
= NULL
;
1210 DEBUG(3, ("Copying service from service %s\n", pszParmValue
));
1212 serviceTemp
= lpcfg_getservicebyname(lp_ctx
, pszParmValue
);
1214 if (service
== NULL
) {
1215 DEBUG(0, ("Unable to copy service - invalid service destination.\n"));
1219 if (serviceTemp
!= NULL
) {
1220 if (serviceTemp
== service
) {
1221 DEBUG(0, ("Can't copy service %s - unable to copy self!\n", pszParmValue
));
1223 copy_service(service
,
1226 lpcfg_string_set(service
, ptr
, pszParmValue
);
1231 DEBUG(0, ("Unable to copy service - source not found: %s\n",
1239 bool handle_debug_list(struct loadparm_context
*lp_ctx
, struct loadparm_service
*service
,
1240 const char *pszParmValue
, char **ptr
)
1242 lpcfg_string_set(lp_ctx
->globals
->ctx
, ptr
, pszParmValue
);
1244 return debug_parse_levels(pszParmValue
);
1247 bool handle_logfile(struct loadparm_context
*lp_ctx
, struct loadparm_service
*service
,
1248 const char *pszParmValue
, char **ptr
)
1250 if (lp_ctx
->s3_fns
== NULL
) {
1251 debug_set_logfile(pszParmValue
);
1254 lpcfg_string_set(lp_ctx
->globals
->ctx
, ptr
, pszParmValue
);
1260 * These special charset handling methods only run in the source3 code.
1263 bool handle_charset(struct loadparm_context
*lp_ctx
, struct loadparm_service
*service
,
1264 const char *pszParmValue
, char **ptr
)
1266 if (lp_ctx
->s3_fns
) {
1267 if (*ptr
== NULL
|| strcmp(*ptr
, pszParmValue
) != 0) {
1268 struct smb_iconv_handle
*ret
= NULL
;
1270 ret
= reinit_iconv_handle(NULL
,
1271 lpcfg_dos_charset(lp_ctx
),
1272 lpcfg_unix_charset(lp_ctx
));
1274 smb_panic("reinit_iconv_handle failed");
1279 return lpcfg_string_set(lp_ctx
->globals
->ctx
, ptr
, pszParmValue
);
1283 bool handle_dos_charset(struct loadparm_context
*lp_ctx
, struct loadparm_service
*service
,
1284 const char *pszParmValue
, char **ptr
)
1286 bool is_utf8
= false;
1287 size_t len
= strlen(pszParmValue
);
1289 if (lp_ctx
->s3_fns
) {
1290 if (len
== 4 || len
== 5) {
1291 /* Don't use StrCaseCmp here as we don't want to
1292 initialize iconv. */
1293 if ((toupper_m(pszParmValue
[0]) == 'U') &&
1294 (toupper_m(pszParmValue
[1]) == 'T') &&
1295 (toupper_m(pszParmValue
[2]) == 'F')) {
1297 if (pszParmValue
[3] == '8') {
1301 if (pszParmValue
[3] == '-' &&
1302 pszParmValue
[4] == '8') {
1309 if (*ptr
== NULL
|| strcmp(*ptr
, pszParmValue
) != 0) {
1310 struct smb_iconv_handle
*ret
= NULL
;
1312 DEBUG(0,("ERROR: invalid DOS charset: 'dos charset' must not "
1313 "be UTF8, using (default value) %s instead.\n",
1314 DEFAULT_DOS_CHARSET
));
1315 pszParmValue
= DEFAULT_DOS_CHARSET
;
1317 ret
= reinit_iconv_handle(NULL
,
1318 lpcfg_dos_charset(lp_ctx
),
1319 lpcfg_unix_charset(lp_ctx
));
1321 smb_panic("reinit_iconv_handle failed");
1326 return lpcfg_string_set(lp_ctx
->globals
->ctx
, ptr
, pszParmValue
);
1329 bool handle_printing(struct loadparm_context
*lp_ctx
, struct loadparm_service
*service
,
1330 const char *pszParmValue
, char **ptr
)
1332 static int parm_num
= -1;
1334 if (parm_num
== -1) {
1335 parm_num
= lpcfg_map_parameter("printing");
1338 if (!lp_set_enum_parm(&parm_table
[parm_num
], pszParmValue
, (int*)ptr
)) {
1342 if (lp_ctx
->s3_fns
) {
1343 if (service
== NULL
) {
1344 init_printer_values(lp_ctx
, lp_ctx
->globals
->ctx
, lp_ctx
->sDefault
);
1346 init_printer_values(lp_ctx
, service
, service
);
1353 bool handle_ldap_debug_level(struct loadparm_context
*lp_ctx
, struct loadparm_service
*service
,
1354 const char *pszParmValue
, char **ptr
)
1356 lp_ctx
->globals
->ldap_debug_level
= lp_int(pszParmValue
);
1358 if (lp_ctx
->s3_fns
) {
1359 lp_ctx
->s3_fns
->init_ldap_debugging();
1364 bool handle_netbios_aliases(struct loadparm_context
*lp_ctx
, struct loadparm_service
*service
,
1365 const char *pszParmValue
, char **ptr
)
1367 TALLOC_FREE(lp_ctx
->globals
->netbios_aliases
);
1368 lp_ctx
->globals
->netbios_aliases
= str_list_make_v3_const(lp_ctx
->globals
->ctx
,
1369 pszParmValue
, NULL
);
1371 if (lp_ctx
->s3_fns
) {
1372 return lp_ctx
->s3_fns
->set_netbios_aliases(lp_ctx
->globals
->netbios_aliases
);
1378 * idmap related parameters
1381 bool handle_idmap_backend(struct loadparm_context
*lp_ctx
, struct loadparm_service
*service
,
1382 const char *pszParmValue
, char **ptr
)
1384 if (lp_ctx
->s3_fns
) {
1385 lp_do_parameter_parametric(lp_ctx
, service
, "idmap config * : backend",
1389 return lpcfg_string_set(lp_ctx
->globals
->ctx
, ptr
, pszParmValue
);
1392 bool handle_idmap_uid(struct loadparm_context
*lp_ctx
, struct loadparm_service
*service
,
1393 const char *pszParmValue
, char **ptr
)
1395 if (lp_ctx
->s3_fns
) {
1396 lp_do_parameter_parametric(lp_ctx
, service
, "idmap config * : range",
1400 return lpcfg_string_set(lp_ctx
->globals
->ctx
, ptr
, pszParmValue
);
1403 bool handle_idmap_gid(struct loadparm_context
*lp_ctx
, struct loadparm_service
*service
,
1404 const char *pszParmValue
, char **ptr
)
1406 if (lp_ctx
->s3_fns
) {
1407 lp_do_parameter_parametric(lp_ctx
, service
, "idmap config * : range",
1411 return lpcfg_string_set(lp_ctx
->globals
->ctx
, ptr
, pszParmValue
);
1414 bool handle_smb_ports(struct loadparm_context
*lp_ctx
, struct loadparm_service
*service
,
1415 const char *pszParmValue
, char **ptr
)
1417 static int parm_num
= -1;
1421 if (!pszParmValue
|| !*pszParmValue
) {
1425 if (parm_num
== -1) {
1426 parm_num
= lpcfg_map_parameter("smb ports");
1427 if (parm_num
== -1) {
1432 if(!set_variable_helper(lp_ctx
->globals
->ctx
, parm_num
, ptr
, "smb ports",
1437 list
= lp_ctx
->globals
->smb_ports
;
1442 /* Check that each port is a valid integer and within range */
1443 for (i
= 0; list
[i
] != NULL
; i
++) {
1446 port
= strtol(list
[i
], &end
, 10);
1447 if (*end
!= '\0' || port
<= 0 || port
> 65535) {
1456 bool handle_rpc_server_dynamic_port_range(struct loadparm_context
*lp_ctx
,
1457 struct loadparm_service
*service
,
1458 const char *pszParmValue
,
1461 int low_port
= -1, high_port
= -1;
1464 if (pszParmValue
== NULL
|| pszParmValue
[0] == '\0') {
1468 rc
= sscanf(pszParmValue
, "%d - %d", &low_port
, &high_port
);
1473 if (low_port
> high_port
) {
1477 if (low_port
< SERVER_TCP_PORT_MIN
|| high_port
> SERVER_TCP_PORT_MAX
) {
1481 lp_ctx
->globals
->rpc_low_port
= low_port
;
1482 lp_ctx
->globals
->rpc_high_port
= high_port
;
1487 bool handle_smb2_max_credits(struct loadparm_context
*lp_ctx
,
1488 struct loadparm_service
*service
,
1489 const char *pszParmValue
, char **ptr
)
1491 int value
= lp_int(pszParmValue
);
1494 value
= DEFAULT_SMB2_MAX_CREDITS
;
1497 *(int *)ptr
= value
;
1502 bool handle_cups_encrypt(struct loadparm_context
*lp_ctx
,
1503 struct loadparm_service
*service
,
1504 const char *pszParmValue
, char **ptr
)
1507 #ifdef HAVE_HTTPCONNECTENCRYPT
1508 int value
= lp_int(pszParmValue
);
1512 result
= HTTP_ENCRYPT_REQUIRED
;
1515 result
= HTTP_ENCRYPT_ALWAYS
;
1518 result
= HTTP_ENCRYPT_NEVER
;
1525 *(int *)ptr
= result
;
1530 /***************************************************************************
1531 Initialise a copymap.
1532 ***************************************************************************/
1535 * Initializes service copymap
1536 * Note: pservice *must* be valid TALLOC_CTX
1538 void init_copymap(struct loadparm_service
*pservice
)
1542 TALLOC_FREE(pservice
->copymap
);
1544 pservice
->copymap
= bitmap_talloc(pservice
, num_parameters());
1545 if (!pservice
->copymap
) {
1547 ("Couldn't allocate copymap!! (size %d)\n",
1548 (int)num_parameters()));
1550 for (i
= 0; i
< num_parameters(); i
++) {
1551 bitmap_set(pservice
->copymap
, i
);
1557 * Process a parametric option
1559 static bool lp_do_parameter_parametric(struct loadparm_context
*lp_ctx
,
1560 struct loadparm_service
*service
,
1561 const char *pszParmName
,
1562 const char *pszParmValue
, int flags
)
1564 struct parmlist_entry
**data
;
1566 TALLOC_CTX
*mem_ctx
;
1568 while (isspace((unsigned char)*pszParmName
)) {
1572 name
= strlower_talloc(lp_ctx
, pszParmName
);
1573 if (!name
) return false;
1575 if (service
== NULL
) {
1576 data
= &lp_ctx
->globals
->param_opt
;
1578 * s3 code cannot deal with parametric options stored on the globals ctx.
1580 if (lp_ctx
->s3_fns
!= NULL
) {
1583 mem_ctx
= lp_ctx
->globals
->ctx
;
1586 data
= &service
->param_opt
;
1590 set_param_opt(mem_ctx
, data
, name
, pszParmValue
, flags
);
1597 static bool set_variable_helper(TALLOC_CTX
*mem_ctx
, int parmnum
, void *parm_ptr
,
1598 const char *pszParmName
, const char *pszParmValue
)
1602 /* switch on the type of variable it is */
1603 switch (parm_table
[parmnum
].type
)
1607 if (!set_boolean(pszParmValue
, &b
)) {
1608 DEBUG(0, ("set_variable_helper(%s): value is not "
1609 "boolean!\n", pszParmValue
));
1612 *(bool *)parm_ptr
= b
;
1618 if (!set_boolean(pszParmValue
, &b
)) {
1619 DEBUG(0, ("set_variable_helper(%s): value is not "
1620 "boolean!\n", pszParmValue
));
1623 *(bool *)parm_ptr
= !b
;
1628 *(int *)parm_ptr
= lp_int(pszParmValue
);
1632 *(char *)parm_ptr
= *pszParmValue
;
1636 i
= sscanf(pszParmValue
, "%o", (int *)parm_ptr
);
1638 DEBUG ( 0, ("Invalid octal number %s\n", pszParmName
));
1646 if (conv_str_size_error(pszParmValue
, &val
)) {
1647 if (val
<= INT_MAX
) {
1648 *(int *)parm_ptr
= (int)val
;
1653 DEBUG(0, ("set_variable_helper(%s): value is not "
1654 "a valid size specifier!\n", pszParmValue
));
1659 TALLOC_FREE(*(char ***)parm_ptr
);
1660 *(char ***)parm_ptr
= str_list_make_v3(mem_ctx
,
1661 pszParmValue
, NULL
);
1666 char **new_list
= str_list_make_v3(mem_ctx
,
1667 pszParmValue
, NULL
);
1668 if (new_list
== NULL
) {
1672 for (i
=0; new_list
[i
]; i
++) {
1673 if (*(const char ***)parm_ptr
!= NULL
&&
1674 new_list
[i
][0] == '+' &&
1677 if (!str_list_check(*(const char ***)parm_ptr
,
1679 *(const char ***)parm_ptr
= str_list_add(*(const char ***)parm_ptr
,
1682 } else if (*(const char ***)parm_ptr
!= NULL
&&
1683 new_list
[i
][0] == '-' &&
1686 str_list_remove(*(const char ***)parm_ptr
,
1690 DEBUG(0, ("Unsupported list syntax for: %s = %s\n",
1691 pszParmName
, pszParmValue
));
1694 *(char ***)parm_ptr
= new_list
;
1702 lpcfg_string_set(mem_ctx
, (char **)parm_ptr
, pszParmValue
);
1706 lpcfg_string_set_upper(mem_ctx
, (char **)parm_ptr
, pszParmValue
);
1710 if (!lp_set_enum_parm(&parm_table
[parmnum
], pszParmValue
, (int*)parm_ptr
)) {
1721 bool handle_name_resolve_order(struct loadparm_context
*lp_ctx
,
1722 struct loadparm_service
*service
,
1723 const char *pszParmValue
, char **ptr
)
1725 const char **valid_values
= NULL
;
1726 const char **values_to_set
= NULL
;
1728 bool value_is_valid
= false;
1729 valid_values
= str_list_make_v3_const(NULL
,
1730 DEFAULT_NAME_RESOLVE_ORDER
,
1732 if (valid_values
== NULL
) {
1733 DBG_ERR("OOM: failed to make string list from %s\n",
1734 DEFAULT_NAME_RESOLVE_ORDER
);
1737 values_to_set
= str_list_make_v3_const(lp_ctx
->globals
->ctx
,
1740 if (values_to_set
== NULL
) {
1741 DBG_ERR("OOM: failed to make string list from %s\n",
1745 TALLOC_FREE(lp_ctx
->globals
->name_resolve_order
);
1746 for (i
= 0; values_to_set
[i
] != NULL
; i
++) {
1747 value_is_valid
= str_list_check(valid_values
, values_to_set
[i
]);
1748 if (!value_is_valid
) {
1749 DBG_ERR("WARNING: Ignoring invalid list value '%s' "
1750 "for parameter 'name resolve order'\n",
1756 if (value_is_valid
) {
1757 lp_ctx
->globals
->name_resolve_order
= values_to_set
;
1759 TALLOC_FREE(values_to_set
);
1761 TALLOC_FREE(valid_values
);
1762 return value_is_valid
;
1765 static bool set_variable(TALLOC_CTX
*mem_ctx
, struct loadparm_service
*service
,
1766 int parmnum
, void *parm_ptr
,
1767 const char *pszParmName
, const char *pszParmValue
,
1768 struct loadparm_context
*lp_ctx
, bool on_globals
)
1773 /* if it is a special case then go ahead */
1774 if (parm_table
[parmnum
].special
) {
1775 ok
= parm_table
[parmnum
].special(lp_ctx
, service
, pszParmValue
,
1778 ok
= set_variable_helper(mem_ctx
, parmnum
, parm_ptr
,
1779 pszParmName
, pszParmValue
);
1786 if (on_globals
&& (lp_ctx
->flags
[parmnum
] & FLAG_DEFAULT
)) {
1787 lp_ctx
->flags
[parmnum
] &= ~FLAG_DEFAULT
;
1788 /* we have to also unset FLAG_DEFAULT on aliases */
1789 for (i
=parmnum
-1;i
>=0 && parm_table
[i
].offset
== parm_table
[parmnum
].offset
;i
--) {
1790 lp_ctx
->flags
[i
] &= ~FLAG_DEFAULT
;
1792 for (i
=parmnum
+1;i
<num_parameters() && parm_table
[i
].offset
== parm_table
[parmnum
].offset
;i
++) {
1793 lp_ctx
->flags
[i
] &= ~FLAG_DEFAULT
;
1800 bool lpcfg_do_global_parameter(struct loadparm_context
*lp_ctx
,
1801 const char *pszParmName
, const char *pszParmValue
)
1803 int parmnum
= lpcfg_map_parameter(pszParmName
);
1807 if (strchr(pszParmName
, ':')) {
1808 return lp_do_parameter_parametric(lp_ctx
, NULL
, pszParmName
, pszParmValue
, 0);
1810 DEBUG(0, ("Ignoring unknown parameter \"%s\"\n", pszParmName
));
1814 /* if the flag has been set on the command line, then don't allow override,
1815 but don't report an error */
1816 if (lp_ctx
->flags
[parmnum
] & FLAG_CMDLINE
) {
1820 if (parm_table
[parmnum
].flags
& FLAG_DEPRECATED
) {
1821 DEBUG(1, ("WARNING: The \"%s\" option is deprecated\n",
1825 parm_ptr
= lpcfg_parm_ptr(lp_ctx
, NULL
, &parm_table
[parmnum
]);
1827 return set_variable(lp_ctx
->globals
->ctx
, NULL
, parmnum
, parm_ptr
,
1828 pszParmName
, pszParmValue
, lp_ctx
, true);
1831 bool lpcfg_do_service_parameter(struct loadparm_context
*lp_ctx
,
1832 struct loadparm_service
*service
,
1833 const char *pszParmName
, const char *pszParmValue
)
1837 int parmnum
= lpcfg_map_parameter(pszParmName
);
1840 if (strchr(pszParmName
, ':')) {
1841 return lp_do_parameter_parametric(lp_ctx
, service
, pszParmName
, pszParmValue
, 0);
1843 DEBUG(0, ("Ignoring unknown parameter \"%s\"\n", pszParmName
));
1847 /* if the flag has been set on the command line, then don't allow override,
1848 but don't report an error */
1849 if (lp_ctx
->flags
[parmnum
] & FLAG_CMDLINE
) {
1853 if (parm_table
[parmnum
].flags
& FLAG_DEPRECATED
) {
1854 DEBUG(1, ("WARNING: The \"%s\" option is deprecated\n",
1858 if (parm_table
[parmnum
].p_class
== P_GLOBAL
) {
1860 ("Global parameter %s found in service section!\n",
1864 parm_ptr
= ((char *)service
) + parm_table
[parmnum
].offset
;
1866 if (!service
->copymap
)
1867 init_copymap(service
);
1869 /* this handles the aliases - set the copymap for other
1870 * entries with the same data pointer */
1871 for (i
= 0; parm_table
[i
].label
; i
++)
1872 if (parm_table
[i
].offset
== parm_table
[parmnum
].offset
&&
1873 parm_table
[i
].p_class
== parm_table
[parmnum
].p_class
)
1874 bitmap_clear(service
->copymap
, i
);
1876 return set_variable(service
, service
, parmnum
, parm_ptr
, pszParmName
,
1877 pszParmValue
, lp_ctx
, false);
1881 * Process a parameter.
1884 bool lpcfg_do_parameter(const char *pszParmName
, const char *pszParmValue
,
1887 struct loadparm_context
*lp_ctx
= (struct loadparm_context
*)userdata
;
1889 if (lp_ctx
->bInGlobalSection
)
1890 return lpcfg_do_global_parameter(lp_ctx
, pszParmName
,
1893 return lpcfg_do_service_parameter(lp_ctx
, lp_ctx
->currentService
,
1894 pszParmName
, pszParmValue
);
1898 variable argument do parameter
1900 bool lpcfg_do_global_parameter_var(struct loadparm_context
*lp_ctx
, const char *pszParmName
, const char *fmt
, ...) PRINTF_ATTRIBUTE(3, 4);
1901 bool lpcfg_do_global_parameter_var(struct loadparm_context
*lp_ctx
,
1902 const char *pszParmName
, const char *fmt
, ...)
1909 s
= talloc_vasprintf(NULL
, fmt
, ap
);
1911 ret
= lpcfg_do_global_parameter(lp_ctx
, pszParmName
, s
);
1918 set a parameter from the commandline - this is called from command line parameter
1919 parsing code. It sets the parameter then marks the parameter as unable to be modified
1920 by smb.conf processing
1922 bool lpcfg_set_cmdline(struct loadparm_context
*lp_ctx
, const char *pszParmName
,
1923 const char *pszParmValue
)
1928 while (isspace((unsigned char)*pszParmValue
)) pszParmValue
++;
1930 parmnum
= lpcfg_map_parameter(pszParmName
);
1932 if (parmnum
< 0 && strchr(pszParmName
, ':')) {
1933 /* set a parametric option */
1935 ok
= lp_do_parameter_parametric(lp_ctx
, NULL
, pszParmName
,
1936 pszParmValue
, FLAG_CMDLINE
);
1937 if (lp_ctx
->s3_fns
!= NULL
) {
1939 lp_ctx
->s3_fns
->store_cmdline(pszParmName
, pszParmValue
);
1946 DEBUG(0,("Unknown option '%s'\n", pszParmName
));
1950 /* reset the CMDLINE flag in case this has been called before */
1951 lp_ctx
->flags
[parmnum
] &= ~FLAG_CMDLINE
;
1953 if (!lpcfg_do_global_parameter(lp_ctx
, pszParmName
, pszParmValue
)) {
1957 lp_ctx
->flags
[parmnum
] |= FLAG_CMDLINE
;
1959 /* we have to also set FLAG_CMDLINE on aliases */
1961 i
>=0 && parm_table
[i
].p_class
== parm_table
[parmnum
].p_class
&&
1962 parm_table
[i
].offset
== parm_table
[parmnum
].offset
;
1964 lp_ctx
->flags
[i
] |= FLAG_CMDLINE
;
1967 i
<num_parameters() &&
1968 parm_table
[i
].p_class
== parm_table
[parmnum
].p_class
&&
1969 parm_table
[i
].offset
== parm_table
[parmnum
].offset
;
1971 lp_ctx
->flags
[i
] |= FLAG_CMDLINE
;
1974 if (lp_ctx
->s3_fns
!= NULL
) {
1975 lp_ctx
->s3_fns
->store_cmdline(pszParmName
, pszParmValue
);
1982 set a option from the commandline in 'a=b' format. Use to support --option
1984 bool lpcfg_set_option(struct loadparm_context
*lp_ctx
, const char *option
)
1989 s
= talloc_strdup(NULL
, option
);
2002 ret
= lpcfg_set_cmdline(lp_ctx
, s
, p
+1);
2008 #define BOOLSTR(b) ((b) ? "Yes" : "No")
2011 * Print a parameter of the specified type.
2014 void lpcfg_print_parameter(struct parm_struct
*p
, void *ptr
, FILE * f
)
2016 /* For the seperation of lists values that we print below */
2017 const char *list_sep
= ", ";
2022 for (i
= 0; p
->enum_list
[i
].name
; i
++) {
2023 if (*(int *)ptr
== p
->enum_list
[i
].value
) {
2025 p
->enum_list
[i
].name
);
2032 fprintf(f
, "%s", BOOLSTR(*(bool *)ptr
));
2036 fprintf(f
, "%s", BOOLSTR(!*(bool *)ptr
));
2041 fprintf(f
, "%d", *(int *)ptr
);
2045 fprintf(f
, "%c", *(char *)ptr
);
2049 int val
= *(int *)ptr
;
2053 fprintf(f
, "0%03o", val
);
2062 if ((char ***)ptr
&& *(char ***)ptr
) {
2063 char **list
= *(char ***)ptr
;
2064 for (; *list
; list
++) {
2065 /* surround strings with whitespace in double quotes */
2066 if (*(list
+1) == NULL
) {
2067 /* last item, no extra separator */
2070 if ( strchr_m( *list
, ' ' ) ) {
2071 fprintf(f
, "\"%s\"%s", *list
, list_sep
);
2073 fprintf(f
, "%s%s", *list
, list_sep
);
2081 if (*(char **)ptr
) {
2082 fprintf(f
, "%s", *(char **)ptr
);
2089 * Check if two parameters are equal.
2092 static bool lpcfg_equal_parameter(parm_type type
, void *ptr1
, void *ptr2
)
2097 return (*((bool *)ptr1
) == *((bool *)ptr2
));
2103 return (*((int *)ptr1
) == *((int *)ptr2
));
2106 return (*((char *)ptr1
) == *((char *)ptr2
));
2110 return str_list_equal(*(const char ***)ptr1
, *(const char ***)ptr2
);
2115 char *p1
= *(char **)ptr1
, *p2
= *(char **)ptr2
;
2120 return (p1
== p2
|| strequal(p1
, p2
));
2127 * Process a new section (service).
2129 * At this stage all sections are services.
2130 * Later we'll have special sections that permit server parameters to be set.
2131 * Returns True on success, False on failure.
2134 static bool do_section(const char *pszSectionName
, void *userdata
)
2136 struct loadparm_context
*lp_ctx
= (struct loadparm_context
*)userdata
;
2140 if (lp_ctx
->s3_fns
!= NULL
) {
2141 return lp_ctx
->s3_fns
->do_section(pszSectionName
, lp_ctx
);
2144 isglobal
= ((strwicmp(pszSectionName
, GLOBAL_NAME
) == 0) ||
2145 (strwicmp(pszSectionName
, GLOBAL_NAME2
) == 0));
2149 /* if we've just struck a global section, note the fact. */
2150 lp_ctx
->bInGlobalSection
= isglobal
;
2152 /* check for multiple global sections */
2153 if (lp_ctx
->bInGlobalSection
) {
2154 DEBUG(4, ("Processing section \"[%s]\"\n", pszSectionName
));
2158 /* if we have a current service, tidy it up before moving on */
2161 if (lp_ctx
->currentService
!= NULL
)
2162 bRetval
= lpcfg_service_ok(lp_ctx
->currentService
);
2164 /* if all is still well, move to the next record in the services array */
2166 /* We put this here to avoid an odd message order if messages are */
2167 /* issued by the post-processing of a previous section. */
2168 DEBUG(4, ("Processing section \"[%s]\"\n", pszSectionName
));
2170 if ((lp_ctx
->currentService
= lpcfg_add_service(lp_ctx
, lp_ctx
->sDefault
,
2173 DEBUG(0, ("Failed to add a new service\n"));
2183 * Determine if a particular base parameter is currently set to the default value.
2186 static bool is_default(void *base_structure
, int i
)
2188 void *def_ptr
= ((char *)base_structure
) + parm_table
[i
].offset
;
2189 switch (parm_table
[i
].type
) {
2192 return str_list_equal((const char * const *)parm_table
[i
].def
.lvalue
,
2193 *(const char * const **)def_ptr
);
2196 return strequal(parm_table
[i
].def
.svalue
,
2200 return parm_table
[i
].def
.bvalue
==
2207 return parm_table
[i
].def
.ivalue
==
2214 *Display the contents of the global structure.
2217 void lpcfg_dump_globals(struct loadparm_context
*lp_ctx
, FILE *f
,
2221 struct parmlist_entry
*data
;
2223 fprintf(f
, "# Global parameters\n[global]\n");
2225 for (i
= 0; parm_table
[i
].label
; i
++) {
2226 if (parm_table
[i
].p_class
!= P_GLOBAL
) {
2230 if (parm_table
[i
].flags
& FLAG_SYNONYM
) {
2234 if (!show_defaults
) {
2235 if (lp_ctx
->flags
&& (lp_ctx
->flags
[i
] & FLAG_DEFAULT
)) {
2239 if (is_default(lp_ctx
->globals
, i
)) {
2244 fprintf(f
, "\t%s = ", parm_table
[i
].label
);
2245 lpcfg_print_parameter(&parm_table
[i
], lpcfg_parm_ptr(lp_ctx
, NULL
, &parm_table
[i
]), f
);
2248 if (lp_ctx
->globals
->param_opt
!= NULL
) {
2249 for (data
= lp_ctx
->globals
->param_opt
; data
;
2250 data
= data
->next
) {
2251 if (!show_defaults
&& (data
->priority
& FLAG_DEFAULT
)) {
2254 fprintf(f
, "\t%s = %s\n", data
->key
, data
->value
);
2261 * Display the contents of a single services record.
2264 void lpcfg_dump_a_service(struct loadparm_service
* pService
, struct loadparm_service
*sDefault
, FILE * f
,
2265 unsigned int *flags
, bool show_defaults
)
2268 struct parmlist_entry
*data
;
2270 if (pService
!= sDefault
)
2271 fprintf(f
, "\n[%s]\n", pService
->szService
);
2273 for (i
= 0; parm_table
[i
].label
; i
++) {
2274 if (parm_table
[i
].p_class
!= P_LOCAL
) {
2278 if (parm_table
[i
].flags
& FLAG_SYNONYM
) {
2282 if (*parm_table
[i
].label
== '-') {
2286 if (pService
== sDefault
) {
2287 if (!show_defaults
) {
2288 if (flags
&& (flags
[i
] & FLAG_DEFAULT
)) {
2292 if (is_default(sDefault
, i
)) {
2299 equal
= lpcfg_equal_parameter(parm_table
[i
].type
,
2300 ((char *)pService
) +
2301 parm_table
[i
].offset
,
2302 ((char *)sDefault
) +
2303 parm_table
[i
].offset
);
2309 fprintf(f
, "\t%s = ", parm_table
[i
].label
);
2310 lpcfg_print_parameter(&parm_table
[i
],
2311 ((char *)pService
) + parm_table
[i
].offset
, f
);
2314 if (pService
->param_opt
!= NULL
) {
2315 for (data
= pService
->param_opt
; data
; data
= data
->next
) {
2316 if (!show_defaults
&& (data
->priority
& FLAG_DEFAULT
)) {
2319 fprintf(f
, "\t%s = %s\n", data
->key
, data
->value
);
2324 bool lpcfg_dump_a_parameter(struct loadparm_context
*lp_ctx
,
2325 struct loadparm_service
*service
,
2326 const char *parm_name
, FILE * f
)
2328 struct parm_struct
*parm
;
2330 char *local_parm_name
;
2332 const char *parm_opt_value
;
2334 /* check for parametrical option */
2335 local_parm_name
= talloc_strdup(lp_ctx
, parm_name
);
2336 if (local_parm_name
== NULL
) {
2340 parm_opt
= strchr( local_parm_name
, ':');
2345 if (strlen(parm_opt
)) {
2346 parm_opt_value
= lpcfg_parm_string(lp_ctx
, service
,
2347 local_parm_name
, parm_opt
);
2348 if (parm_opt_value
) {
2349 fprintf(f
, "%s\n", parm_opt_value
);
2356 /* parameter is not parametric, search the table */
2357 parm
= lpcfg_parm_struct(lp_ctx
, parm_name
);
2362 if (service
!= NULL
&& parm
->p_class
== P_GLOBAL
) {
2366 ptr
= lpcfg_parm_ptr(lp_ctx
, service
,parm
);
2368 lpcfg_print_parameter(parm
, ptr
, f
);
2374 * Auto-load some home services.
2376 static void lpcfg_add_auto_services(struct loadparm_context
*lp_ctx
,
2382 /***************************************************************************
2383 Initialise the sDefault parameter structure for the printer values.
2384 ***************************************************************************/
2386 void init_printer_values(struct loadparm_context
*lp_ctx
, TALLOC_CTX
*ctx
,
2387 struct loadparm_service
*pService
)
2389 /* choose defaults depending on the type of printing */
2390 switch (pService
->printing
) {
2395 lpcfg_string_set(ctx
, &pService
->lpq_command
, "lpq -P'%p'");
2396 lpcfg_string_set(ctx
, &pService
->lprm_command
, "lprm -P'%p' %j");
2397 lpcfg_string_set(ctx
, &pService
->print_command
, "lpr -r -P'%p' %s");
2402 lpcfg_string_set(ctx
, &pService
->lpq_command
, "lpq -P'%p'");
2403 lpcfg_string_set(ctx
, &pService
->lprm_command
, "lprm -P'%p' %j");
2404 lpcfg_string_set(ctx
, &pService
->print_command
, "lpr -r -P'%p' %s");
2405 lpcfg_string_set(ctx
, &pService
->queuepause_command
, "lpc stop '%p'");
2406 lpcfg_string_set(ctx
, &pService
->queueresume_command
, "lpc start '%p'");
2407 lpcfg_string_set(ctx
, &pService
->lppause_command
, "lpc hold '%p' %j");
2408 lpcfg_string_set(ctx
, &pService
->lpresume_command
, "lpc release '%p' %j");
2413 /* set the lpq command to contain the destination printer
2414 name only. This is used by cups_queue_get() */
2415 lpcfg_string_set(ctx
, &pService
->lpq_command
, "%p");
2416 lpcfg_string_set(ctx
, &pService
->lprm_command
, "");
2417 lpcfg_string_set(ctx
, &pService
->print_command
, "");
2418 lpcfg_string_set(ctx
, &pService
->lppause_command
, "");
2419 lpcfg_string_set(ctx
, &pService
->lpresume_command
, "");
2420 lpcfg_string_set(ctx
, &pService
->queuepause_command
, "");
2421 lpcfg_string_set(ctx
, &pService
->queueresume_command
, "");
2426 lpcfg_string_set(ctx
, &pService
->lpq_command
, "lpstat -o%p");
2427 lpcfg_string_set(ctx
, &pService
->lprm_command
, "cancel %p-%j");
2428 lpcfg_string_set(ctx
, &pService
->print_command
, "lp -c -d%p %s; rm %s");
2429 lpcfg_string_set(ctx
, &pService
->queuepause_command
, "disable %p");
2430 lpcfg_string_set(ctx
, &pService
->queueresume_command
, "enable %p");
2432 lpcfg_string_set(ctx
, &pService
->lppause_command
, "lp -i %p-%j -H hold");
2433 lpcfg_string_set(ctx
, &pService
->lpresume_command
, "lp -i %p-%j -H resume");
2438 lpcfg_string_set(ctx
, &pService
->lpq_command
, "lpq -P%p");
2439 lpcfg_string_set(ctx
, &pService
->lprm_command
, "lprm -P%p %j");
2440 lpcfg_string_set(ctx
, &pService
->print_command
, "lp -r -P%p %s");
2443 #if defined(DEVELOPER) || defined(ENABLE_SELFTEST)
2447 const char *tdbfile
;
2448 TALLOC_CTX
*tmp_ctx
= talloc_new(ctx
);
2451 tmp
= lpcfg_parm_string(lp_ctx
, NULL
, "vlp", "tdbfile");
2453 tmp
= "/tmp/vlp.tdb";
2456 tdbfile
= talloc_asprintf(tmp_ctx
, "tdbfile=%s", tmp
);
2457 if (tdbfile
== NULL
) {
2458 tdbfile
="tdbfile=/tmp/vlp.tdb";
2461 tmp
= talloc_asprintf(tmp_ctx
, "vlp %s print %%p %%s",
2463 lpcfg_string_set(ctx
, &pService
->print_command
,
2464 tmp
? tmp
: "vlp print %p %s");
2466 tmp
= talloc_asprintf(tmp_ctx
, "vlp %s lpq %%p",
2468 lpcfg_string_set(ctx
, &pService
->lpq_command
,
2469 tmp
? tmp
: "vlp lpq %p");
2471 tmp
= talloc_asprintf(tmp_ctx
, "vlp %s lprm %%p %%j",
2473 lpcfg_string_set(ctx
, &pService
->lprm_command
,
2474 tmp
? tmp
: "vlp lprm %p %j");
2476 tmp
= talloc_asprintf(tmp_ctx
, "vlp %s lppause %%p %%j",
2478 lpcfg_string_set(ctx
, &pService
->lppause_command
,
2479 tmp
? tmp
: "vlp lppause %p %j");
2481 tmp
= talloc_asprintf(tmp_ctx
, "vlp %s lpresume %%p %%j",
2483 lpcfg_string_set(ctx
, &pService
->lpresume_command
,
2484 tmp
? tmp
: "vlp lpresume %p %j");
2486 tmp
= talloc_asprintf(tmp_ctx
, "vlp %s queuepause %%p",
2488 lpcfg_string_set(ctx
, &pService
->queuepause_command
,
2489 tmp
? tmp
: "vlp queuepause %p");
2491 tmp
= talloc_asprintf(tmp_ctx
, "vlp %s queueresume %%p",
2493 lpcfg_string_set(ctx
, &pService
->queueresume_command
,
2494 tmp
? tmp
: "vlp queueresume %p");
2495 TALLOC_FREE(tmp_ctx
);
2499 #endif /* DEVELOPER */
2505 * Unload unused services.
2508 void lpcfg_killunused(struct loadparm_context
*lp_ctx
,
2509 struct smbsrv_connection
*smb
,
2510 bool (*snumused
) (struct smbsrv_connection
*, int))
2514 if (lp_ctx
->s3_fns
!= NULL
) {
2515 smb_panic("Cannot be used from an s3 loadparm ctx");
2518 for (i
= 0; i
< lp_ctx
->iNumServices
; i
++) {
2519 if (lp_ctx
->services
[i
] == NULL
)
2522 if (!snumused
|| !snumused(smb
, i
)) {
2523 talloc_free(lp_ctx
->services
[i
]);
2524 lp_ctx
->services
[i
] = NULL
;
2530 static int lpcfg_destructor(struct loadparm_context
*lp_ctx
)
2532 struct parmlist_entry
*data
;
2534 if (lp_ctx
->refuse_free
) {
2535 /* someone is trying to free the
2536 global_loadparm_context.
2537 We can't allow that. */
2541 if (lp_ctx
->globals
->param_opt
!= NULL
) {
2542 struct parmlist_entry
*next
;
2543 for (data
= lp_ctx
->globals
->param_opt
; data
; data
=next
) {
2545 if (data
->priority
& FLAG_CMDLINE
) continue;
2546 DLIST_REMOVE(lp_ctx
->globals
->param_opt
, data
);
2555 * Initialise the global parameter structure.
2557 * Note that most callers should use loadparm_init_global() instead
2559 struct loadparm_context
*loadparm_init(TALLOC_CTX
*mem_ctx
)
2563 struct loadparm_context
*lp_ctx
;
2564 struct parmlist_entry
*parm
;
2567 lp_ctx
= talloc_zero(mem_ctx
, struct loadparm_context
);
2571 talloc_set_destructor(lp_ctx
, lpcfg_destructor
);
2572 lp_ctx
->bInGlobalSection
= true;
2573 lp_ctx
->globals
= talloc_zero(lp_ctx
, struct loadparm_global
);
2574 /* This appears odd, but globals in s3 isn't a pointer */
2575 lp_ctx
->globals
->ctx
= lp_ctx
->globals
;
2576 lp_ctx
->globals
->rpc_low_port
= SERVER_TCP_LOW_PORT
;
2577 lp_ctx
->globals
->rpc_high_port
= SERVER_TCP_HIGH_PORT
;
2578 lp_ctx
->sDefault
= talloc_zero(lp_ctx
, struct loadparm_service
);
2579 lp_ctx
->flags
= talloc_zero_array(lp_ctx
, unsigned int, num_parameters());
2581 lp_ctx
->sDefault
->max_print_jobs
= 1000;
2582 lp_ctx
->sDefault
->available
= true;
2583 lp_ctx
->sDefault
->browseable
= true;
2584 lp_ctx
->sDefault
->read_only
= true;
2585 lp_ctx
->sDefault
->map_archive
= true;
2586 lp_ctx
->sDefault
->strict_locking
= true;
2587 lp_ctx
->sDefault
->oplocks
= true;
2588 lp_ctx
->sDefault
->create_mask
= 0744;
2589 lp_ctx
->sDefault
->force_create_mode
= 0000;
2590 lp_ctx
->sDefault
->directory_mask
= 0755;
2591 lp_ctx
->sDefault
->force_directory_mode
= 0000;
2593 DEBUG(3, ("Initialising global parameters\n"));
2595 for (i
= 0; parm_table
[i
].label
; i
++) {
2596 if ((parm_table
[i
].type
== P_STRING
||
2597 parm_table
[i
].type
== P_USTRING
) &&
2598 !(lp_ctx
->flags
[i
] & FLAG_CMDLINE
)) {
2599 TALLOC_CTX
*parent_mem
;
2601 if (parm_table
[i
].p_class
== P_LOCAL
) {
2602 parent_mem
= lp_ctx
->sDefault
;
2603 r
= (char **)(((char *)lp_ctx
->sDefault
) + parm_table
[i
].offset
);
2605 parent_mem
= lp_ctx
->globals
;
2606 r
= (char **)(((char *)lp_ctx
->globals
) + parm_table
[i
].offset
);
2608 lpcfg_string_set(parent_mem
, r
, "");
2612 logfile
= talloc_asprintf(lp_ctx
, "%s/log.samba", dyn_LOGFILEBASE
);
2613 lpcfg_do_global_parameter(lp_ctx
, "log file", logfile
);
2614 talloc_free(logfile
);
2616 lpcfg_do_global_parameter(lp_ctx
, "log level", "0");
2618 lpcfg_do_global_parameter(lp_ctx
, "syslog", "1");
2619 lpcfg_do_global_parameter(lp_ctx
, "syslog only", "No");
2620 lpcfg_do_global_parameter(lp_ctx
, "debug timestamp", "Yes");
2621 lpcfg_do_global_parameter(lp_ctx
, "debug prefix timestamp", "No");
2622 lpcfg_do_global_parameter(lp_ctx
, "debug hires timestamp", "Yes");
2623 lpcfg_do_global_parameter(lp_ctx
, "debug pid", "No");
2624 lpcfg_do_global_parameter(lp_ctx
, "debug uid", "No");
2625 lpcfg_do_global_parameter(lp_ctx
, "debug class", "No");
2627 lpcfg_do_global_parameter(lp_ctx
, "share backend", "classic");
2629 lpcfg_do_global_parameter(lp_ctx
, "server role", "auto");
2630 lpcfg_do_global_parameter(lp_ctx
, "domain logons", "No");
2631 lpcfg_do_global_parameter(lp_ctx
, "domain master", "Auto");
2633 /* options that can be set on the command line must be initialised via
2634 the slower lpcfg_do_global_parameter() to ensure that FLAG_CMDLINE is obeyed */
2636 lpcfg_do_global_parameter(lp_ctx
, "socket options", "TCP_NODELAY");
2638 lpcfg_do_global_parameter(lp_ctx
, "workgroup", DEFAULT_WORKGROUP
);
2639 myname
= get_myname(lp_ctx
);
2640 lpcfg_do_global_parameter(lp_ctx
, "netbios name", myname
);
2641 talloc_free(myname
);
2642 lpcfg_do_global_parameter(lp_ctx
,
2643 "name resolve order",
2644 DEFAULT_NAME_RESOLVE_ORDER
);
2646 lpcfg_do_global_parameter(lp_ctx
, "fstype", "NTFS");
2648 lpcfg_do_global_parameter(lp_ctx
, "ntvfs handler", "unixuid default");
2649 lpcfg_do_global_parameter(lp_ctx
, "max connections", "0");
2651 lpcfg_do_global_parameter(lp_ctx
, "dcerpc endpoint servers", "epmapper wkssvc rpcecho samr netlogon lsarpc drsuapi dssetup unixinfo browser eventlog6 backupkey dnsserver");
2652 lpcfg_do_global_parameter(lp_ctx
, "server services", "s3fs rpc nbt wrepl ldap cldap kdc drepl winbindd ntp_signd kcc dnsupdate dns");
2653 lpcfg_do_global_parameter(lp_ctx
, "kccsrv:samba_kcc", "true");
2654 /* the winbind method for domain controllers is for both RODC
2655 auth forwarding and for trusted domains */
2656 lpcfg_do_global_parameter(lp_ctx
, "private dir", dyn_PRIVATE_DIR
);
2657 lpcfg_do_global_parameter(lp_ctx
, "registry:HKEY_LOCAL_MACHINE", "hklm.ldb");
2659 /* This hive should be dynamically generated by Samba using
2660 data from the sam, but for the moment leave it in a tdb to
2661 keep regedt32 from popping up an annoying dialog. */
2662 lpcfg_do_global_parameter(lp_ctx
, "registry:HKEY_USERS", "hku.ldb");
2664 /* using UTF8 by default allows us to support all chars */
2665 lpcfg_do_global_parameter(lp_ctx
, "unix charset", "UTF-8");
2667 /* Use codepage 850 as a default for the dos character set */
2668 lpcfg_do_global_parameter(lp_ctx
, "dos charset", "CP850");
2671 * Allow the default PASSWD_CHAT to be overridden in local.h.
2673 lpcfg_do_global_parameter(lp_ctx
, "passwd chat", DEFAULT_PASSWD_CHAT
);
2675 lpcfg_do_global_parameter(lp_ctx
, "pid directory", dyn_PIDDIR
);
2676 lpcfg_do_global_parameter(lp_ctx
, "lock dir", dyn_LOCKDIR
);
2677 lpcfg_do_global_parameter(lp_ctx
, "state directory", dyn_STATEDIR
);
2678 lpcfg_do_global_parameter(lp_ctx
, "cache directory", dyn_CACHEDIR
);
2679 lpcfg_do_global_parameter(lp_ctx
, "ncalrpc dir", dyn_NCALRPCDIR
);
2681 lpcfg_do_global_parameter(lp_ctx
, "nbt client socket address", "0.0.0.0");
2682 lpcfg_do_global_parameter_var(lp_ctx
, "server string",
2683 "Samba %s", SAMBA_VERSION_STRING
);
2685 lpcfg_do_global_parameter(lp_ctx
, "password server", "*");
2687 lpcfg_do_global_parameter(lp_ctx
, "max mux", "50");
2688 lpcfg_do_global_parameter(lp_ctx
, "max xmit", "16644");
2689 lpcfg_do_global_parameter(lp_ctx
, "host msdfs", "true");
2691 lpcfg_do_global_parameter(lp_ctx
, "LargeReadwrite", "True");
2692 lpcfg_do_global_parameter(lp_ctx
, "server min protocol", "LANMAN1");
2693 lpcfg_do_global_parameter(lp_ctx
, "server max protocol", "SMB3");
2694 lpcfg_do_global_parameter(lp_ctx
, "client min protocol", "CORE");
2695 lpcfg_do_global_parameter(lp_ctx
, "client max protocol", "default");
2696 lpcfg_do_global_parameter(lp_ctx
, "client ipc min protocol", "default");
2697 lpcfg_do_global_parameter(lp_ctx
, "client ipc max protocol", "default");
2698 lpcfg_do_global_parameter(lp_ctx
, "security", "AUTO");
2699 lpcfg_do_global_parameter(lp_ctx
, "EncryptPasswords", "True");
2700 lpcfg_do_global_parameter(lp_ctx
, "ReadRaw", "True");
2701 lpcfg_do_global_parameter(lp_ctx
, "WriteRaw", "True");
2702 lpcfg_do_global_parameter(lp_ctx
, "NullPasswords", "False");
2703 lpcfg_do_global_parameter(lp_ctx
, "old password allowed period", "60");
2704 lpcfg_do_global_parameter(lp_ctx
, "ObeyPamRestrictions", "False");
2706 lpcfg_do_global_parameter(lp_ctx
, "TimeServer", "False");
2707 lpcfg_do_global_parameter(lp_ctx
, "BindInterfacesOnly", "False");
2708 lpcfg_do_global_parameter(lp_ctx
, "Unicode", "True");
2709 lpcfg_do_global_parameter(lp_ctx
, "ClientLanManAuth", "False");
2710 lpcfg_do_global_parameter(lp_ctx
, "ClientNTLMv2Auth", "True");
2711 lpcfg_do_global_parameter(lp_ctx
, "LanmanAuth", "False");
2712 lpcfg_do_global_parameter(lp_ctx
, "NTLMAuth", "False");
2713 lpcfg_do_global_parameter(lp_ctx
, "RawNTLMv2Auth", "False");
2714 lpcfg_do_global_parameter(lp_ctx
, "client use spnego principal", "False");
2716 lpcfg_do_global_parameter(lp_ctx
, "allow dcerpc auth level connect", "False");
2718 lpcfg_do_global_parameter(lp_ctx
, "UnixExtensions", "True");
2720 lpcfg_do_global_parameter(lp_ctx
, "PreferredMaster", "Auto");
2721 lpcfg_do_global_parameter(lp_ctx
, "LocalMaster", "True");
2723 lpcfg_do_global_parameter(lp_ctx
, "wins support", "False");
2724 lpcfg_do_global_parameter(lp_ctx
, "dns proxy", "True");
2726 lpcfg_do_global_parameter(lp_ctx
, "winbind separator", "\\");
2727 lpcfg_do_global_parameter(lp_ctx
, "winbind sealed pipes", "True");
2728 lpcfg_do_global_parameter(lp_ctx
, "require strong key", "True");
2729 lpcfg_do_global_parameter(lp_ctx
, "winbindd socket directory", dyn_WINBINDD_SOCKET_DIR
);
2730 lpcfg_do_global_parameter(lp_ctx
, "ntp signd socket directory", dyn_NTP_SIGND_SOCKET_DIR
);
2731 lpcfg_do_global_parameter_var(lp_ctx
, "dns update command", "%s/samba_dnsupdate", dyn_SCRIPTSBINDIR
);
2732 lpcfg_do_global_parameter_var(lp_ctx
, "spn update command", "%s/samba_spnupdate", dyn_SCRIPTSBINDIR
);
2733 lpcfg_do_global_parameter_var(lp_ctx
, "samba kcc command",
2734 "%s/samba_kcc", dyn_SCRIPTSBINDIR
);
2736 lpcfg_do_global_parameter_var(lp_ctx
,
2740 lpcfg_do_global_parameter(lp_ctx
, "template shell", "/bin/false");
2741 lpcfg_do_global_parameter(lp_ctx
, "template homedir", "/home/%D/%U");
2743 lpcfg_do_global_parameter(lp_ctx
, "client signing", "default");
2744 lpcfg_do_global_parameter(lp_ctx
, "client ipc signing", "default");
2745 lpcfg_do_global_parameter(lp_ctx
, "server signing", "default");
2747 lpcfg_do_global_parameter(lp_ctx
, "use spnego", "True");
2749 lpcfg_do_global_parameter(lp_ctx
, "use mmap", "True");
2751 lpcfg_do_global_parameter(lp_ctx
, "smb ports", "445 139");
2752 lpcfg_do_global_parameter_var(lp_ctx
, "nbt port", "%d", NBT_NAME_SERVICE_PORT
);
2753 lpcfg_do_global_parameter_var(lp_ctx
, "dgram port", "%d", NBT_DGRAM_SERVICE_PORT
);
2754 lpcfg_do_global_parameter(lp_ctx
, "cldap port", "389");
2755 lpcfg_do_global_parameter(lp_ctx
, "krb5 port", "88");
2756 lpcfg_do_global_parameter(lp_ctx
, "kpasswd port", "464");
2757 lpcfg_do_global_parameter(lp_ctx
, "web port", "901");
2759 lpcfg_do_global_parameter(lp_ctx
, "nt status support", "True");
2761 lpcfg_do_global_parameter(lp_ctx
, "max wins ttl", "518400"); /* 6 days */
2762 lpcfg_do_global_parameter(lp_ctx
, "min wins ttl", "21600");
2764 lpcfg_do_global_parameter(lp_ctx
, "tls enabled", "True");
2765 lpcfg_do_global_parameter(lp_ctx
, "tls verify peer", "as_strict_as_possible");
2766 lpcfg_do_global_parameter(lp_ctx
, "tls keyfile", "tls/key.pem");
2767 lpcfg_do_global_parameter(lp_ctx
, "tls certfile", "tls/cert.pem");
2768 lpcfg_do_global_parameter(lp_ctx
, "tls cafile", "tls/ca.pem");
2769 lpcfg_do_global_parameter(lp_ctx
, "tls priority", "NORMAL:-VERS-SSL3.0");
2770 lpcfg_do_global_parameter(lp_ctx
, "prefork children:smb", "4");
2772 lpcfg_do_global_parameter(lp_ctx
, "rndc command", "/usr/sbin/rndc");
2773 lpcfg_do_global_parameter(lp_ctx
, "nsupdate command", "/usr/bin/nsupdate -g");
2775 lpcfg_do_global_parameter(lp_ctx
, "allow dns updates", "secure only");
2776 lpcfg_do_global_parameter(lp_ctx
, "dns forwarder", "");
2778 lpcfg_do_global_parameter(lp_ctx
, "algorithmic rid base", "1000");
2780 lpcfg_do_global_parameter(lp_ctx
, "enhanced browsing", "True");
2782 lpcfg_do_global_parameter(lp_ctx
, "winbind nss info", "template");
2784 lpcfg_do_global_parameter(lp_ctx
, "server schannel", "Auto");
2786 lpcfg_do_global_parameter(lp_ctx
, "short preserve case", "True");
2788 lpcfg_do_global_parameter(lp_ctx
, "max open files", "16384");
2790 lpcfg_do_global_parameter(lp_ctx
, "cups connection timeout", "30");
2792 lpcfg_do_global_parameter(lp_ctx
, "locking", "True");
2794 lpcfg_do_global_parameter(lp_ctx
, "block size", "1024");
2796 lpcfg_do_global_parameter(lp_ctx
, "client use spnego", "True");
2798 lpcfg_do_global_parameter(lp_ctx
, "change notify", "True");
2800 lpcfg_do_global_parameter(lp_ctx
, "name cache timeout", "660");
2802 lpcfg_do_global_parameter(lp_ctx
, "defer sharing violations", "True");
2804 lpcfg_do_global_parameter(lp_ctx
, "ldap replication sleep", "1000");
2806 lpcfg_do_global_parameter(lp_ctx
, "idmap backend", "tdb");
2808 lpcfg_do_global_parameter(lp_ctx
, "enable privileges", "True");
2810 lpcfg_do_global_parameter_var(lp_ctx
, "smb2 max write", "%u", DEFAULT_SMB2_MAX_WRITE
);
2812 lpcfg_do_global_parameter(lp_ctx
, "passdb backend", "tdbsam");
2814 lpcfg_do_global_parameter(lp_ctx
, "getwd cache", "True");
2816 lpcfg_do_global_parameter(lp_ctx
, "winbind nested groups", "True");
2818 lpcfg_do_global_parameter(lp_ctx
, "mangled names", "True");
2820 lpcfg_do_global_parameter_var(lp_ctx
, "smb2 max credits", "%u", DEFAULT_SMB2_MAX_CREDITS
);
2822 lpcfg_do_global_parameter(lp_ctx
, "ldap ssl", "start tls");
2824 lpcfg_do_global_parameter(lp_ctx
, "ldap deref", "auto");
2826 lpcfg_do_global_parameter(lp_ctx
, "lm interval", "60");
2828 lpcfg_do_global_parameter(lp_ctx
, "mangling method", "hash2");
2830 lpcfg_do_global_parameter(lp_ctx
, "hide dot files", "True");
2832 lpcfg_do_global_parameter(lp_ctx
, "browse list", "True");
2834 lpcfg_do_global_parameter(lp_ctx
, "passwd chat timeout", "2");
2836 lpcfg_do_global_parameter(lp_ctx
, "guest account", GUEST_ACCOUNT
);
2838 lpcfg_do_global_parameter(lp_ctx
, "map untrusted to domain", "auto");
2840 lpcfg_do_global_parameter(lp_ctx
, "client schannel", "auto");
2842 lpcfg_do_global_parameter(lp_ctx
, "smb encrypt", "default");
2844 lpcfg_do_global_parameter(lp_ctx
, "max log size", "5000");
2846 lpcfg_do_global_parameter(lp_ctx
, "idmap negative cache time", "120");
2848 lpcfg_do_global_parameter(lp_ctx
, "ldap follow referral", "auto");
2850 lpcfg_do_global_parameter(lp_ctx
, "multicast dns register", "yes");
2852 lpcfg_do_global_parameter(lp_ctx
, "winbind reconnect delay", "30");
2854 lpcfg_do_global_parameter(lp_ctx
, "winbind request timeout", "60");
2856 lpcfg_do_global_parameter(lp_ctx
, "nt acl support", "yes");
2858 lpcfg_do_global_parameter(lp_ctx
, "acl check permissions", "yes");
2860 lpcfg_do_global_parameter(lp_ctx
, "keepalive", "300");
2862 lpcfg_do_global_parameter(lp_ctx
, "smbd profiling level", "off");
2864 lpcfg_do_global_parameter(lp_ctx
, "winbind cache time", "300");
2866 lpcfg_do_global_parameter(lp_ctx
, "level2 oplocks", "yes");
2868 lpcfg_do_global_parameter(lp_ctx
, "show add printer wizard", "yes");
2870 lpcfg_do_global_parameter(lp_ctx
, "allocation roundup size", "1048576");
2872 lpcfg_do_global_parameter(lp_ctx
, "ldap page size", "1000");
2874 lpcfg_do_global_parameter(lp_ctx
, "kernel share modes", "yes");
2876 lpcfg_do_global_parameter(lp_ctx
, "strict locking", "Auto");
2878 lpcfg_do_global_parameter(lp_ctx
, "strict sync", "yes");
2880 lpcfg_do_global_parameter(lp_ctx
, "map readonly", "yes");
2882 lpcfg_do_global_parameter(lp_ctx
, "allow trusted domains", "yes");
2884 lpcfg_do_global_parameter(lp_ctx
, "default devmode", "yes");
2886 lpcfg_do_global_parameter(lp_ctx
, "os level", "20");
2888 lpcfg_do_global_parameter(lp_ctx
, "dos filetimes", "yes");
2890 lpcfg_do_global_parameter(lp_ctx
, "mangling char", "~");
2892 lpcfg_do_global_parameter(lp_ctx
, "printcap cache time", "750");
2894 lpcfg_do_global_parameter(lp_ctx
, "create krb5 conf", "yes");
2896 lpcfg_do_global_parameter(lp_ctx
, "winbind max clients", "200");
2898 lpcfg_do_global_parameter(lp_ctx
, "acl map full control", "yes");
2900 lpcfg_do_global_parameter(lp_ctx
, "nt pipe support", "yes");
2902 lpcfg_do_global_parameter(lp_ctx
, "ldap debug threshold", "10");
2904 lpcfg_do_global_parameter(lp_ctx
, "client ldap sasl wrapping", "sign");
2906 lpcfg_do_global_parameter(lp_ctx
, "ldap server require strong auth", "yes");
2908 lpcfg_do_global_parameter(lp_ctx
, "follow symlinks", "yes");
2910 lpcfg_do_global_parameter(lp_ctx
, "machine password timeout", "604800");
2912 lpcfg_do_global_parameter(lp_ctx
, "ldap connection timeout", "2");
2914 lpcfg_do_global_parameter(lp_ctx
, "winbind expand groups", "0");
2916 lpcfg_do_global_parameter(lp_ctx
, "stat cache", "yes");
2918 lpcfg_do_global_parameter(lp_ctx
, "lpq cache time", "30");
2920 lpcfg_do_global_parameter_var(lp_ctx
, "smb2 max trans", "%u", DEFAULT_SMB2_MAX_TRANSACT
);
2922 lpcfg_do_global_parameter_var(lp_ctx
, "smb2 max read", "%u", DEFAULT_SMB2_MAX_READ
);
2924 lpcfg_do_global_parameter(lp_ctx
, "durable handles", "yes");
2926 lpcfg_do_global_parameter(lp_ctx
, "max stat cache size", "256");
2928 lpcfg_do_global_parameter(lp_ctx
, "ldap passwd sync", "no");
2930 lpcfg_do_global_parameter(lp_ctx
, "kernel change notify", "yes");
2932 lpcfg_do_global_parameter(lp_ctx
, "max ttl", "259200");
2934 lpcfg_do_global_parameter(lp_ctx
, "blocking locks", "yes");
2936 lpcfg_do_global_parameter(lp_ctx
, "oplock contention limit", "2");
2938 lpcfg_do_global_parameter(lp_ctx
, "load printers", "yes");
2940 lpcfg_do_global_parameter(lp_ctx
, "idmap cache time", "604800");
2942 lpcfg_do_global_parameter(lp_ctx
, "preserve case", "yes");
2944 lpcfg_do_global_parameter(lp_ctx
, "lm announce", "auto");
2946 lpcfg_do_global_parameter(lp_ctx
, "afs token lifetime", "604800");
2948 lpcfg_do_global_parameter(lp_ctx
, "enable core files", "yes");
2950 lpcfg_do_global_parameter(lp_ctx
, "winbind max domain connections", "1");
2952 lpcfg_do_global_parameter(lp_ctx
, "case sensitive", "auto");
2954 lpcfg_do_global_parameter(lp_ctx
, "ldap timeout", "15");
2956 lpcfg_do_global_parameter(lp_ctx
, "mangle prefix", "1");
2958 lpcfg_do_global_parameter(lp_ctx
, "posix locking", "yes");
2960 lpcfg_do_global_parameter(lp_ctx
, "lock spin time", "200");
2962 lpcfg_do_global_parameter(lp_ctx
, "directory name cache size", "100");
2964 lpcfg_do_global_parameter(lp_ctx
, "nmbd bind explicit broadcast", "yes");
2966 lpcfg_do_global_parameter(lp_ctx
, "init logon delay", "100");
2968 lpcfg_do_global_parameter(lp_ctx
, "usershare owner only", "yes");
2970 lpcfg_do_global_parameter(lp_ctx
, "-valid", "yes");
2972 lpcfg_do_global_parameter_var(lp_ctx
, "usershare path", "%s/usershares", get_dyn_STATEDIR());
2975 lpcfg_do_global_parameter_var(lp_ctx
, "panic action", "/bin/sleep 999999999");
2978 lpcfg_do_global_parameter(lp_ctx
, "smb passwd file", get_dyn_SMB_PASSWD_FILE());
2980 lpcfg_do_global_parameter(lp_ctx
, "logon home", "\\\\%N\\%U");
2982 lpcfg_do_global_parameter(lp_ctx
, "logon path", "\\\\%N\\%U\\profile");
2984 lpcfg_do_global_parameter(lp_ctx
, "printjob username", "%U");
2986 lpcfg_do_global_parameter(lp_ctx
, "aio max threads", "100");
2988 lpcfg_do_global_parameter(lp_ctx
, "smb2 leases", "yes");
2990 lpcfg_do_global_parameter(lp_ctx
, "kerberos encryption types", "all");
2992 lpcfg_do_global_parameter(lp_ctx
,
2993 "rpc server dynamic port range",
2996 for (i
= 0; parm_table
[i
].label
; i
++) {
2997 if (!(lp_ctx
->flags
[i
] & FLAG_CMDLINE
)) {
2998 lp_ctx
->flags
[i
] |= FLAG_DEFAULT
;
3002 for (parm
=lp_ctx
->globals
->param_opt
; parm
; parm
=parm
->next
) {
3003 if (!(parm
->priority
& FLAG_CMDLINE
)) {
3004 parm
->priority
|= FLAG_DEFAULT
;
3008 for (parm
=lp_ctx
->sDefault
->param_opt
; parm
; parm
=parm
->next
) {
3009 if (!(parm
->priority
& FLAG_CMDLINE
)) {
3010 parm
->priority
|= FLAG_DEFAULT
;
3018 * Initialise the global parameter structure.
3020 struct loadparm_context
*loadparm_init_global(bool load_default
)
3022 if (global_loadparm_context
== NULL
) {
3023 global_loadparm_context
= loadparm_init(NULL
);
3025 if (global_loadparm_context
== NULL
) {
3028 global_loadparm_context
->global
= true;
3029 if (load_default
&& !global_loadparm_context
->loaded
) {
3030 lpcfg_load_default(global_loadparm_context
);
3032 global_loadparm_context
->refuse_free
= true;
3033 return global_loadparm_context
;
3037 * Initialise the global parameter structure.
3039 struct loadparm_context
*loadparm_init_s3(TALLOC_CTX
*mem_ctx
,
3040 const struct loadparm_s3_helpers
*s3_fns
)
3042 struct loadparm_context
*loadparm_context
= talloc_zero(mem_ctx
, struct loadparm_context
);
3043 if (!loadparm_context
) {
3046 loadparm_context
->s3_fns
= s3_fns
;
3047 loadparm_context
->globals
= s3_fns
->globals
;
3048 loadparm_context
->flags
= s3_fns
->flags
;
3050 return loadparm_context
;
3053 const char *lpcfg_configfile(struct loadparm_context
*lp_ctx
)
3055 return lp_ctx
->szConfigFile
;
3058 const char *lp_default_path(void)
3060 if (getenv("SMB_CONF_PATH"))
3061 return getenv("SMB_CONF_PATH");
3063 return dyn_CONFIGFILE
;
3067 * Update the internal state of a loadparm context after settings
3070 static bool lpcfg_update(struct loadparm_context
*lp_ctx
)
3072 struct debug_settings settings
;
3073 TALLOC_CTX
*tmp_ctx
;
3075 tmp_ctx
= talloc_new(lp_ctx
);
3076 if (tmp_ctx
== NULL
) {
3080 lpcfg_add_auto_services(lp_ctx
, lpcfg_auto_services(lp_ctx
, tmp_ctx
));
3082 if (!lp_ctx
->globals
->wins_server_list
&& lp_ctx
->globals
->we_are_a_wins_server
) {
3083 lpcfg_do_global_parameter(lp_ctx
, "wins server", "127.0.0.1");
3086 if (!lp_ctx
->global
) {
3087 TALLOC_FREE(tmp_ctx
);
3091 panic_action
= lp_ctx
->globals
->panic_action
;
3093 reload_charcnv(lp_ctx
);
3095 ZERO_STRUCT(settings
);
3096 /* Add any more debug-related smb.conf parameters created in
3098 settings
.timestamp_logs
= lp_ctx
->globals
->timestamp_logs
;
3099 settings
.debug_prefix_timestamp
= lp_ctx
->globals
->debug_prefix_timestamp
;
3100 settings
.debug_hires_timestamp
= lp_ctx
->globals
->debug_hires_timestamp
;
3101 settings
.debug_pid
= lp_ctx
->globals
->debug_pid
;
3102 settings
.debug_uid
= lp_ctx
->globals
->debug_uid
;
3103 settings
.debug_class
= lp_ctx
->globals
->debug_class
;
3104 debug_set_settings(&settings
, lp_ctx
->globals
->logging
,
3105 lp_ctx
->globals
->syslog
,
3106 lp_ctx
->globals
->syslog_only
);
3108 /* FIXME: This is a bit of a hack, but we can't use a global, since
3109 * not everything that uses lp also uses the socket library */
3110 if (lpcfg_parm_bool(lp_ctx
, NULL
, "socket", "testnonblock", false)) {
3111 setenv("SOCKET_TESTNONBLOCK", "1", 1);
3113 unsetenv("SOCKET_TESTNONBLOCK");
3116 TALLOC_FREE(tmp_ctx
);
3120 bool lpcfg_load_default(struct loadparm_context
*lp_ctx
)
3124 path
= lp_default_path();
3126 if (!file_exist(path
)) {
3127 /* We allow the default smb.conf file to not exist,
3128 * basically the equivalent of an empty file. */
3129 return lpcfg_update(lp_ctx
);
3132 return lpcfg_load(lp_ctx
, path
);
3136 * Load the services array from the services file.
3138 * Return True on success, False on failure.
3140 bool lpcfg_load(struct loadparm_context
*lp_ctx
, const char *filename
)
3145 filename
= talloc_strdup(lp_ctx
, filename
);
3147 lp_ctx
->szConfigFile
= filename
;
3149 if (lp_ctx
->s3_fns
) {
3150 return lp_ctx
->s3_fns
->load(filename
);
3153 lp_ctx
->bInGlobalSection
= true;
3154 n2
= standard_sub_basic(lp_ctx
, lp_ctx
->szConfigFile
);
3155 DEBUG(2, ("lpcfg_load: refreshing parameters from %s\n", n2
));
3157 add_to_file_list(lp_ctx
, &lp_ctx
->file_lists
, lp_ctx
->szConfigFile
, n2
);
3159 /* We get sections first, so have to start 'behind' to make up */
3160 lp_ctx
->currentService
= NULL
;
3161 bRetval
= pm_process(n2
, do_section
, lpcfg_do_parameter
, lp_ctx
);
3163 /* finish up the last section */
3164 DEBUG(4, ("pm_process() returned %s\n", BOOLSTR(bRetval
)));
3166 if (lp_ctx
->currentService
!= NULL
)
3167 bRetval
= lpcfg_service_ok(lp_ctx
->currentService
);
3169 bRetval
= bRetval
&& lpcfg_update(lp_ctx
);
3171 /* we do this unconditionally, so that it happens even
3172 for a missing smb.conf */
3173 reload_charcnv(lp_ctx
);
3175 if (bRetval
== true) {
3176 /* set this up so that any child python tasks will
3177 find the right smb.conf */
3178 setenv("SMB_CONF_PATH", filename
, 1);
3180 /* set the context used by the lp_*() function
3182 global_loadparm_context
= lp_ctx
;
3183 lp_ctx
->loaded
= true;
3190 * Return the max number of services.
3193 int lpcfg_numservices(struct loadparm_context
*lp_ctx
)
3195 if (lp_ctx
->s3_fns
) {
3196 return lp_ctx
->s3_fns
->get_numservices();
3199 return lp_ctx
->iNumServices
;
3203 * Display the contents of the services array in human-readable form.
3206 void lpcfg_dump(struct loadparm_context
*lp_ctx
, FILE *f
, bool show_defaults
,
3211 if (lp_ctx
->s3_fns
) {
3212 lp_ctx
->s3_fns
->dump(f
, show_defaults
, maxtoprint
);
3216 lpcfg_dump_globals(lp_ctx
, f
, show_defaults
);
3218 lpcfg_dump_a_service(lp_ctx
->sDefault
, lp_ctx
->sDefault
, f
, lp_ctx
->flags
, show_defaults
);
3220 for (iService
= 0; iService
< maxtoprint
; iService
++)
3221 lpcfg_dump_one(f
, show_defaults
, lp_ctx
->services
[iService
], lp_ctx
->sDefault
);
3225 * Display the contents of one service in human-readable form.
3227 void lpcfg_dump_one(FILE *f
, bool show_defaults
, struct loadparm_service
*service
, struct loadparm_service
*sDefault
)
3229 if (service
!= NULL
) {
3230 if (service
->szService
[0] == '\0')
3232 lpcfg_dump_a_service(service
, sDefault
, f
, NULL
, show_defaults
);
3236 struct loadparm_service
*lpcfg_servicebynum(struct loadparm_context
*lp_ctx
,
3239 if (lp_ctx
->s3_fns
) {
3240 return lp_ctx
->s3_fns
->get_servicebynum(snum
);
3243 return lp_ctx
->services
[snum
];
3246 struct loadparm_service
*lpcfg_service(struct loadparm_context
*lp_ctx
,
3247 const char *service_name
)
3252 if (lp_ctx
->s3_fns
) {
3253 return lp_ctx
->s3_fns
->get_service(service_name
);
3256 for (iService
= lp_ctx
->iNumServices
- 1; iService
>= 0; iService
--) {
3257 if (lp_ctx
->services
[iService
] &&
3258 lp_ctx
->services
[iService
]->szService
) {
3260 * The substitution here is used to support %U is
3263 serviceName
= standard_sub_basic(
3264 lp_ctx
->services
[iService
],
3265 lp_ctx
->services
[iService
]->szService
);
3266 if (strequal(serviceName
, service_name
)) {
3267 talloc_free(serviceName
);
3268 return lp_ctx
->services
[iService
];
3270 talloc_free(serviceName
);
3274 DEBUG(7,("lpcfg_servicenumber: couldn't find %s\n", service_name
));
3278 const char *lpcfg_servicename(const struct loadparm_service
*service
)
3280 return lpcfg_string((const char *)service
->szService
);
3284 * A useful volume label function.
3286 const char *lpcfg_volume_label(struct loadparm_service
*service
, struct loadparm_service
*sDefault
)
3289 ret
= lpcfg_string((const char *)((service
!= NULL
&& service
->volume
!= NULL
) ?
3290 service
->volume
: sDefault
->volume
));
3292 return lpcfg_servicename(service
);
3297 * Return the correct printer name.
3299 const char *lpcfg_printername(struct loadparm_service
*service
, struct loadparm_service
*sDefault
)
3302 ret
= lpcfg_string((const char *)((service
!= NULL
&& service
->_printername
!= NULL
) ?
3303 service
->_printername
: sDefault
->_printername
));
3304 if (ret
== NULL
|| (ret
!= NULL
&& *ret
== '\0'))
3305 ret
= lpcfg_servicename(service
);
3312 * Return the max print jobs per queue.
3314 int lpcfg_maxprintjobs(struct loadparm_service
*service
, struct loadparm_service
*sDefault
)
3316 int maxjobs
= lpcfg_max_print_jobs(service
, sDefault
);
3318 if (maxjobs
<= 0 || maxjobs
>= PRINT_MAX_JOBID
)
3319 maxjobs
= PRINT_MAX_JOBID
- 1;
3324 struct smb_iconv_handle
*lpcfg_iconv_handle(struct loadparm_context
*lp_ctx
)
3326 if (lp_ctx
== NULL
) {
3327 return get_iconv_handle();
3329 return lp_ctx
->iconv_handle
;
3332 _PUBLIC_
void reload_charcnv(struct loadparm_context
*lp_ctx
)
3334 if (!lp_ctx
->global
) {
3338 lp_ctx
->iconv_handle
=
3339 reinit_iconv_handle(lp_ctx
,
3340 lpcfg_dos_charset(lp_ctx
),
3341 lpcfg_unix_charset(lp_ctx
));
3342 if (lp_ctx
->iconv_handle
== NULL
) {
3343 smb_panic("reinit_iconv_handle failed");
3347 _PUBLIC_
char *lpcfg_tls_keyfile(TALLOC_CTX
*mem_ctx
, struct loadparm_context
*lp_ctx
)
3349 return lpcfg_private_path(mem_ctx
, lp_ctx
, lpcfg__tls_keyfile(lp_ctx
));
3352 _PUBLIC_
char *lpcfg_tls_certfile(TALLOC_CTX
*mem_ctx
, struct loadparm_context
*lp_ctx
)
3354 return lpcfg_private_path(mem_ctx
, lp_ctx
, lpcfg__tls_certfile(lp_ctx
));
3357 _PUBLIC_
char *lpcfg_tls_cafile(TALLOC_CTX
*mem_ctx
, struct loadparm_context
*lp_ctx
)
3359 return lpcfg_private_path(mem_ctx
, lp_ctx
, lpcfg__tls_cafile(lp_ctx
));
3362 _PUBLIC_
char *lpcfg_tls_crlfile(TALLOC_CTX
*mem_ctx
, struct loadparm_context
*lp_ctx
)
3364 return lpcfg_private_path(mem_ctx
, lp_ctx
, lpcfg__tls_crlfile(lp_ctx
));
3367 _PUBLIC_
char *lpcfg_tls_dhpfile(TALLOC_CTX
*mem_ctx
, struct loadparm_context
*lp_ctx
)
3369 return lpcfg_private_path(mem_ctx
, lp_ctx
, lpcfg__tls_dhpfile(lp_ctx
));
3372 struct gensec_settings
*lpcfg_gensec_settings(TALLOC_CTX
*mem_ctx
, struct loadparm_context
*lp_ctx
)
3374 struct gensec_settings
*settings
= talloc_zero(mem_ctx
, struct gensec_settings
);
3375 if (settings
== NULL
)
3377 SMB_ASSERT(lp_ctx
!= NULL
);
3378 settings
->lp_ctx
= talloc_reference(settings
, lp_ctx
);
3379 settings
->target_hostname
= lpcfg_parm_string(lp_ctx
, NULL
, "gensec", "target_hostname");
3383 int lpcfg_server_role(struct loadparm_context
*lp_ctx
)
3385 int domain_master
= lpcfg__domain_master(lp_ctx
);
3387 return lp_find_server_role(lpcfg__server_role(lp_ctx
),
3388 lpcfg__security(lp_ctx
),
3389 lpcfg__domain_logons(lp_ctx
),
3390 (domain_master
== true) ||
3391 (domain_master
== Auto
));
3394 int lpcfg_security(struct loadparm_context
*lp_ctx
)
3396 return lp_find_security(lpcfg__server_role(lp_ctx
),
3397 lpcfg__security(lp_ctx
));
3400 int lpcfg_client_max_protocol(struct loadparm_context
*lp_ctx
)
3402 int client_max_protocol
= lpcfg__client_max_protocol(lp_ctx
);
3403 if (client_max_protocol
== PROTOCOL_DEFAULT
) {
3404 return PROTOCOL_NT1
;
3406 return client_max_protocol
;
3409 int lpcfg_client_ipc_min_protocol(struct loadparm_context
*lp_ctx
)
3411 int client_ipc_min_protocol
= lpcfg__client_ipc_min_protocol(lp_ctx
);
3412 if (client_ipc_min_protocol
== PROTOCOL_DEFAULT
) {
3413 client_ipc_min_protocol
= lpcfg_client_min_protocol(lp_ctx
);
3415 if (client_ipc_min_protocol
< PROTOCOL_NT1
) {
3416 return PROTOCOL_NT1
;
3418 return client_ipc_min_protocol
;
3421 int lpcfg_client_ipc_max_protocol(struct loadparm_context
*lp_ctx
)
3423 int client_ipc_max_protocol
= lpcfg__client_ipc_max_protocol(lp_ctx
);
3424 if (client_ipc_max_protocol
== PROTOCOL_DEFAULT
) {
3425 return PROTOCOL_LATEST
;
3427 if (client_ipc_max_protocol
< PROTOCOL_NT1
) {
3428 return PROTOCOL_NT1
;
3430 return client_ipc_max_protocol
;
3433 int lpcfg_client_ipc_signing(struct loadparm_context
*lp_ctx
)
3435 int client_ipc_signing
= lpcfg__client_ipc_signing(lp_ctx
);
3436 if (client_ipc_signing
== SMB_SIGNING_DEFAULT
) {
3437 return SMB_SIGNING_REQUIRED
;
3439 return client_ipc_signing
;
3442 bool lpcfg_server_signing_allowed(struct loadparm_context
*lp_ctx
, bool *mandatory
)
3444 bool allowed
= true;
3445 enum smb_signing_setting signing_setting
= lpcfg_server_signing(lp_ctx
);
3449 if (signing_setting
== SMB_SIGNING_DEFAULT
) {
3451 * If we are a domain controller, SMB signing is
3452 * really important, as it can prevent a number of
3453 * attacks on communications between us and the
3456 * However, it really sucks (no sendfile, CPU
3457 * overhead) performance-wise when used on a
3458 * file server, so disable it by default
3462 if (lpcfg_server_role(lp_ctx
) >= ROLE_ACTIVE_DIRECTORY_DC
) {
3463 signing_setting
= SMB_SIGNING_REQUIRED
;
3465 signing_setting
= SMB_SIGNING_OFF
;
3469 switch (signing_setting
) {
3470 case SMB_SIGNING_REQUIRED
:
3473 case SMB_SIGNING_DESIRED
:
3474 case SMB_SIGNING_IF_REQUIRED
:
3476 case SMB_SIGNING_OFF
:
3479 case SMB_SIGNING_DEFAULT
:
3480 case SMB_SIGNING_IPC_DEFAULT
:
3481 smb_panic(__location__
);
3488 int lpcfg_tdb_hash_size(struct loadparm_context
*lp_ctx
, const char *name
)
3496 base
= strrchr_m(name
, '/');
3502 return lpcfg_parm_int(lp_ctx
, NULL
, "tdb_hashsize", base
, 0);
3506 int lpcfg_tdb_flags(struct loadparm_context
*lp_ctx
, int tdb_flags
)
3508 if (!lpcfg_use_mmap(lp_ctx
)) {
3509 tdb_flags
|= TDB_NOMMAP
;