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"
72 #ifdef HAVE_HTTPCONNECTENCRYPT
73 #include <cups/http.h>
76 #define standard_sub_basic talloc_strdup
78 #include "lib/param/param_global.h"
80 struct loadparm_service
*lpcfg_default_service(struct loadparm_context
*lp_ctx
)
82 return lp_ctx
->sDefault
;
86 * Convenience routine to grab string parameters into temporary memory
87 * and run standard_sub_basic on them.
89 * The buffers can be written to by
90 * callers without affecting the source string.
93 static const char *lpcfg_string(const char *s
)
95 #if 0 /* until REWRITE done to make thread-safe */
96 size_t len
= s
? strlen(s
) : 0;
100 /* The follow debug is useful for tracking down memory problems
101 especially if you have an inner loop that is calling a lp_*()
102 function that returns a string. Perhaps this debug should be
103 present all the time? */
106 DEBUG(10, ("lpcfg_string(%s)\n", s
));
109 #if 0 /* until REWRITE done to make thread-safe */
111 lp_talloc
= talloc_init("lp_talloc");
113 ret
= talloc_array(lp_talloc
, char, len
+ 100); /* leave room for substitution */
121 strlcpy(ret
, s
, len
);
123 if (trim_string(ret
, "\"", "\"")) {
124 if (strchr(ret
,'"') != NULL
)
125 strlcpy(ret
, s
, len
);
128 standard_sub_basic(ret
,len
+100);
135 In this section all the functions that are used to access the
136 parameters from the rest of the program are defined
140 * the creation of separate lpcfg_*() and lp_*() functions is to allow
141 * for code compatibility between existing Samba4 and Samba3 code.
144 /* this global context supports the lp_*() function varients */
145 static struct loadparm_context
*global_loadparm_context
;
147 #define FN_GLOBAL_STRING(fn_name,var_name) \
148 _PUBLIC_ char *lpcfg_ ## fn_name(struct loadparm_context *lp_ctx, TALLOC_CTX *ctx) {\
149 if (lp_ctx == NULL) return NULL; \
150 if (lp_ctx->s3_fns) { \
151 return lp_ctx->globals->var_name ? lp_ctx->s3_fns->lp_string(ctx, lp_ctx->globals->var_name) : talloc_strdup(ctx, ""); \
153 return lp_ctx->globals->var_name ? talloc_strdup(ctx, lpcfg_string(lp_ctx->globals->var_name)) : talloc_strdup(ctx, ""); \
156 #define FN_GLOBAL_CONST_STRING(fn_name,var_name) \
157 _PUBLIC_ const char *lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) { \
158 if (lp_ctx == NULL) return NULL; \
159 return lp_ctx->globals->var_name ? lpcfg_string(lp_ctx->globals->var_name) : ""; \
162 #define FN_GLOBAL_LIST(fn_name,var_name) \
163 _PUBLIC_ const char **lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) { \
164 if (lp_ctx == NULL) return NULL; \
165 return lp_ctx->globals->var_name; \
168 #define FN_GLOBAL_BOOL(fn_name,var_name) \
169 _PUBLIC_ bool lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) {\
170 if (lp_ctx == NULL) return false; \
171 return lp_ctx->globals->var_name; \
174 #define FN_GLOBAL_INTEGER(fn_name,var_name) \
175 _PUBLIC_ int lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) { \
176 return lp_ctx->globals->var_name; \
179 /* Local parameters don't need the ->s3_fns because the struct
180 * loadparm_service is shared and lpcfg_service() checks the ->s3_fns
182 #define FN_LOCAL_STRING(fn_name,val) \
183 _PUBLIC_ char *lpcfg_ ## fn_name(struct loadparm_service *service, \
184 struct loadparm_service *sDefault, TALLOC_CTX *ctx) { \
185 return(talloc_strdup(ctx, lpcfg_string((const char *)((service != NULL && service->val != NULL) ? service->val : sDefault->val)))); \
188 #define FN_LOCAL_CONST_STRING(fn_name,val) \
189 _PUBLIC_ const char *lpcfg_ ## fn_name(struct loadparm_service *service, \
190 struct loadparm_service *sDefault) { \
191 return((const char *)((service != NULL && service->val != NULL) ? service->val : sDefault->val)); \
194 #define FN_LOCAL_LIST(fn_name,val) \
195 _PUBLIC_ const char **lpcfg_ ## fn_name(struct loadparm_service *service, \
196 struct loadparm_service *sDefault) {\
197 return(const char **)(service != NULL && service->val != NULL? service->val : sDefault->val); \
200 #define FN_LOCAL_PARM_BOOL(fn_name, val) FN_LOCAL_BOOL(fn_name, val)
202 #define FN_LOCAL_BOOL(fn_name,val) \
203 _PUBLIC_ bool lpcfg_ ## fn_name(struct loadparm_service *service, \
204 struct loadparm_service *sDefault) { \
205 return((service != NULL)? service->val : sDefault->val); \
208 #define FN_LOCAL_INTEGER(fn_name,val) \
209 _PUBLIC_ int lpcfg_ ## fn_name(struct loadparm_service *service, \
210 struct loadparm_service *sDefault) { \
211 return((service != NULL)? service->val : sDefault->val); \
214 #define FN_LOCAL_PARM_INTEGER(fn_name, val) FN_LOCAL_INTEGER(fn_name, val)
216 #define FN_LOCAL_CHAR(fn_name,val) \
217 _PUBLIC_ char lpcfg_ ## fn_name(struct loadparm_service *service, \
218 struct loadparm_service *sDefault) { \
219 return((service != NULL)? service->val : sDefault->val); \
222 #define FN_LOCAL_PARM_CHAR(fn_name,val) FN_LOCAL_CHAR(fn_name, val)
224 #include "lib/param/param_functions.c"
226 /* These functions cannot be auto-generated */
227 FN_LOCAL_BOOL(autoloaded
, autoloaded
)
228 FN_GLOBAL_CONST_STRING(dnsdomain
, dnsdomain
)
230 /* local prototypes */
231 static struct loadparm_service
*lpcfg_getservicebyname(struct loadparm_context
*lp_ctx
,
232 const char *pszServiceName
);
233 static bool do_section(const char *pszSectionName
, void *);
234 static bool set_variable_helper(TALLOC_CTX
*mem_ctx
, int parmnum
, void *parm_ptr
,
235 const char *pszParmName
, const char *pszParmValue
);
236 static bool lp_do_parameter_parametric(struct loadparm_context
*lp_ctx
,
237 struct loadparm_service
*service
,
238 const char *pszParmName
,
239 const char *pszParmValue
, int flags
);
241 /* The following are helper functions for parametrical options support. */
242 /* It returns a pointer to parametrical option value if it exists or NULL otherwise */
243 /* Actual parametrical functions are quite simple */
244 struct parmlist_entry
*get_parametric_helper(struct loadparm_service
*service
,
245 const char *type
, const char *option
,
246 struct parmlist_entry
*global_opts
)
248 size_t type_len
= strlen(type
);
249 size_t option_len
= strlen(option
);
250 char param_key
[type_len
+ option_len
+ 2];
251 struct parmlist_entry
*data
= NULL
;
253 snprintf(param_key
, sizeof(param_key
), "%s:%s", type
, option
);
256 * Try to fetch the option from the data.
258 if (service
!= NULL
) {
259 data
= service
->param_opt
;
260 while (data
!= NULL
) {
261 if (strwicmp(data
->key
, param_key
) == 0) {
269 * Fall back to fetching from the globals.
272 while (data
!= NULL
) {
273 if (strwicmp(data
->key
, param_key
) == 0) {
282 const char *lpcfg_get_parametric(struct loadparm_context
*lp_ctx
,
283 struct loadparm_service
*service
,
284 const char *type
, const char *option
)
286 struct parmlist_entry
*data
;
291 data
= get_parametric_helper(service
,
292 type
, option
, lp_ctx
->globals
->param_opt
);
303 * convenience routine to return int parameters.
305 int lp_int(const char *s
)
309 DEBUG(0,("lp_int(%s): is called with NULL!\n",s
));
313 return strtol(s
, NULL
, 0);
317 * convenience routine to return unsigned long parameters.
319 unsigned long lp_ulong(const char *s
)
323 DEBUG(0,("lp_ulong(%s): is called with NULL!\n",s
));
327 return strtoul(s
, NULL
, 0);
331 * convenience routine to return unsigned long parameters.
333 static long lp_long(const char *s
)
337 DEBUG(0,("lp_long(%s): is called with NULL!\n",s
));
341 return strtol(s
, NULL
, 0);
345 * convenience routine to return unsigned long parameters.
347 static double lp_double(const char *s
)
351 DEBUG(0,("lp_double(%s): is called with NULL!\n",s
));
355 return strtod(s
, NULL
);
359 * convenience routine to return boolean parameters.
361 bool lp_bool(const char *s
)
366 DEBUG(0,("lp_bool(%s): is called with NULL!\n",s
));
370 if (!set_boolean(s
, &ret
)) {
371 DEBUG(0,("lp_bool(%s): value is not boolean!\n",s
));
379 * Return parametric option from a given service. Type is a part of option before ':'
380 * Parametric option has following syntax: 'Type: option = value'
381 * Returned value is allocated in 'lp_talloc' context
384 const char *lpcfg_parm_string(struct loadparm_context
*lp_ctx
,
385 struct loadparm_service
*service
, const char *type
,
388 const char *value
= lpcfg_get_parametric(lp_ctx
, service
, type
, option
);
391 return lpcfg_string(value
);
397 * Return parametric option from a given service. Type is a part of option before ':'
398 * Parametric option has following syntax: 'Type: option = value'
399 * Returned value is allocated in 'lp_talloc' context
402 const char **lpcfg_parm_string_list(TALLOC_CTX
*mem_ctx
,
403 struct loadparm_context
*lp_ctx
,
404 struct loadparm_service
*service
,
406 const char *option
, const char *separator
)
408 const char *value
= lpcfg_get_parametric(lp_ctx
, service
, type
, option
);
411 char **l
= str_list_make(mem_ctx
, value
, separator
);
412 return discard_const_p(const char *, l
);
419 * Return parametric option from a given service. Type is a part of option before ':'
420 * Parametric option has following syntax: 'Type: option = value'
423 int lpcfg_parm_int(struct loadparm_context
*lp_ctx
,
424 struct loadparm_service
*service
, const char *type
,
425 const char *option
, int default_v
)
427 const char *value
= lpcfg_get_parametric(lp_ctx
, service
, type
, option
);
430 return lp_int(value
);
436 * Return parametric option from a given service. Type is a part of
438 * Parametric option has following syntax: 'Type: option = value'.
441 int lpcfg_parm_bytes(struct loadparm_context
*lp_ctx
,
442 struct loadparm_service
*service
, const char *type
,
443 const char *option
, int default_v
)
447 const char *value
= lpcfg_get_parametric(lp_ctx
, service
, type
, option
);
449 if (value
&& conv_str_size_error(value
, &bval
)) {
450 if (bval
<= INT_MAX
) {
459 * Return parametric option from a given service.
460 * Type is a part of option before ':'
461 * Parametric option has following syntax: 'Type: option = value'
463 unsigned long lpcfg_parm_ulong(struct loadparm_context
*lp_ctx
,
464 struct loadparm_service
*service
, const char *type
,
465 const char *option
, unsigned long default_v
)
467 const char *value
= lpcfg_get_parametric(lp_ctx
, service
, type
, option
);
470 return lp_ulong(value
);
475 long lpcfg_parm_long(struct loadparm_context
*lp_ctx
,
476 struct loadparm_service
*service
, const char *type
,
477 const char *option
, long default_v
)
479 const char *value
= lpcfg_get_parametric(lp_ctx
, service
, type
, option
);
482 return lp_long(value
);
487 double lpcfg_parm_double(struct loadparm_context
*lp_ctx
,
488 struct loadparm_service
*service
, const char *type
,
489 const char *option
, double default_v
)
491 const char *value
= lpcfg_get_parametric(lp_ctx
, service
, type
, option
);
494 return lp_double(value
);
500 * Return parametric option from a given service. Type is a part of option before ':'
501 * Parametric option has following syntax: 'Type: option = value'
504 bool lpcfg_parm_bool(struct loadparm_context
*lp_ctx
,
505 struct loadparm_service
*service
, const char *type
,
506 const char *option
, bool default_v
)
508 const char *value
= lpcfg_get_parametric(lp_ctx
, service
, type
, option
);
511 return lp_bool(value
);
518 * Set a string value, deallocating any existing space, and allocing the space
521 bool lpcfg_string_set(TALLOC_CTX
*mem_ctx
, char **dest
, const char *src
)
528 *dest
= talloc_strdup(mem_ctx
, src
);
529 if ((*dest
) == NULL
) {
530 DEBUG(0,("Out of memory in string_set\n"));
538 * Set a string value, deallocating any existing space, and allocing the space
541 bool lpcfg_string_set_upper(TALLOC_CTX
*mem_ctx
, char **dest
, const char *src
)
548 *dest
= strupper_talloc(mem_ctx
, src
);
549 if ((*dest
) == NULL
) {
550 DEBUG(0,("Out of memory in string_set_upper\n"));
560 * Add a new service to the services array initialising it with the given
564 struct loadparm_service
*lpcfg_add_service(struct loadparm_context
*lp_ctx
,
565 const struct loadparm_service
*pservice
,
569 int num_to_alloc
= lp_ctx
->iNumServices
+ 1;
570 struct parmlist_entry
*data
, *pdata
;
572 if (lp_ctx
->s3_fns
!= NULL
) {
573 smb_panic("Add a service should not be called on an s3 loadparm ctx");
576 if (pservice
== NULL
) {
577 pservice
= lp_ctx
->sDefault
;
580 /* it might already exist */
582 struct loadparm_service
*service
= lpcfg_getservicebyname(lp_ctx
,
584 if (service
!= NULL
) {
585 /* Clean all parametric options for service */
586 /* They will be added during parsing again */
587 data
= service
->param_opt
;
593 service
->param_opt
= NULL
;
598 /* find an invalid one */
599 for (i
= 0; i
< lp_ctx
->iNumServices
; i
++)
600 if (lp_ctx
->services
[i
] == NULL
)
603 /* if not, then create one */
604 if (i
== lp_ctx
->iNumServices
) {
605 struct loadparm_service
**tsp
;
607 tsp
= talloc_realloc(lp_ctx
, lp_ctx
->services
, struct loadparm_service
*, num_to_alloc
);
610 DEBUG(0,("lpcfg_add_service: failed to enlarge services!\n"));
613 lp_ctx
->services
= tsp
;
614 lp_ctx
->services
[lp_ctx
->iNumServices
] = NULL
;
617 lp_ctx
->iNumServices
++;
620 lp_ctx
->services
[i
] = talloc_zero(lp_ctx
->services
, struct loadparm_service
);
621 if (lp_ctx
->services
[i
] == NULL
) {
622 DEBUG(0,("lpcfg_add_service: out of memory!\n"));
625 copy_service(lp_ctx
->services
[i
], pservice
, NULL
);
627 lpcfg_string_set(lp_ctx
->services
[i
], &lp_ctx
->services
[i
]->szService
, name
);
628 return lp_ctx
->services
[i
];
632 * Add a new home service, with the specified home directory, defaults coming
633 * from service ifrom.
636 bool lpcfg_add_home(struct loadparm_context
*lp_ctx
,
637 const char *pszHomename
,
638 struct loadparm_service
*default_service
,
639 const char *user
, const char *pszHomedir
)
641 struct loadparm_service
*service
;
643 service
= lpcfg_add_service(lp_ctx
, default_service
, pszHomename
);
648 if (!(*(default_service
->path
))
649 || strequal(default_service
->path
, lp_ctx
->sDefault
->path
)) {
650 service
->path
= talloc_strdup(service
, pszHomedir
);
652 service
->path
= string_sub_talloc(service
, lpcfg_path(default_service
, lp_ctx
->sDefault
, service
), "%H", pszHomedir
);
655 if (!(*(service
->comment
))) {
656 service
->comment
= talloc_asprintf(service
, "Home directory of %s", user
);
658 service
->available
= default_service
->available
;
659 service
->browseable
= default_service
->browseable
;
661 DEBUG(3, ("adding home's share [%s] for user '%s' at '%s'\n",
662 pszHomename
, user
, service
->path
));
668 * Add a new printer service, with defaults coming from service iFrom.
671 bool lpcfg_add_printer(struct loadparm_context
*lp_ctx
,
672 const char *pszPrintername
,
673 struct loadparm_service
*default_service
)
675 const char *comment
= "From Printcap";
676 struct loadparm_service
*service
;
677 service
= lpcfg_add_service(lp_ctx
, default_service
, pszPrintername
);
682 /* note that we do NOT default the availability flag to True - */
683 /* we take it from the default service passed. This allows all */
684 /* dynamic printers to be disabled by disabling the [printers] */
685 /* entry (if/when the 'available' keyword is implemented!). */
687 /* the printer name is set to the service name. */
688 lpcfg_string_set(service
, &service
->_printername
, pszPrintername
);
689 lpcfg_string_set(service
, &service
->comment
, comment
);
690 service
->browseable
= default_service
->browseable
;
691 /* Printers cannot be read_only. */
692 service
->read_only
= false;
693 /* Printer services must be printable. */
694 service
->printable
= true;
696 DEBUG(3, ("adding printer service %s\n", pszPrintername
));
702 * Map a parameter's string representation to something we can use.
703 * Returns False if the parameter string is not recognised, else TRUE.
706 int lpcfg_map_parameter(const char *pszParmName
)
710 for (iIndex
= 0; parm_table
[iIndex
].label
; iIndex
++)
711 if (strwicmp(parm_table
[iIndex
].label
, pszParmName
) == 0)
714 /* Warn only if it isn't parametric option */
715 if (strchr(pszParmName
, ':') == NULL
)
716 DEBUG(0, ("Unknown parameter encountered: \"%s\"\n", pszParmName
));
717 /* We do return 'fail' for parametric options as well because they are
718 stored in different storage
725 return the parameter structure for a parameter
727 struct parm_struct
*lpcfg_parm_struct(struct loadparm_context
*lp_ctx
, const char *name
)
729 int num
= lpcfg_map_parameter(name
);
735 return &parm_table
[num
];
739 return the parameter pointer for a parameter
741 void *lpcfg_parm_ptr(struct loadparm_context
*lp_ctx
,
742 struct loadparm_service
*service
, struct parm_struct
*parm
)
744 if (lp_ctx
->s3_fns
) {
745 return lp_ctx
->s3_fns
->get_parm_ptr(service
, parm
);
748 if (service
== NULL
) {
749 if (parm
->p_class
== P_LOCAL
)
750 return ((char *)lp_ctx
->sDefault
)+parm
->offset
;
751 else if (parm
->p_class
== P_GLOBAL
)
752 return ((char *)lp_ctx
->globals
)+parm
->offset
;
755 return ((char *)service
) + parm
->offset
;
760 return the parameter pointer for a parameter
762 bool lpcfg_parm_is_cmdline(struct loadparm_context
*lp_ctx
, const char *name
)
766 parmnum
= lpcfg_map_parameter(name
);
767 if (parmnum
== -1) return false;
769 return lp_ctx
->flags
[parmnum
] & FLAG_CMDLINE
;
773 * Find a service by name. Otherwise works like get_service.
776 static struct loadparm_service
*lpcfg_getservicebyname(struct loadparm_context
*lp_ctx
,
777 const char *pszServiceName
)
781 if (lp_ctx
->s3_fns
) {
782 return lp_ctx
->s3_fns
->get_service(pszServiceName
);
785 for (iService
= lp_ctx
->iNumServices
- 1; iService
>= 0; iService
--)
786 if (lp_ctx
->services
[iService
] != NULL
&&
787 strwicmp(lp_ctx
->services
[iService
]->szService
, pszServiceName
) == 0) {
788 return lp_ctx
->services
[iService
];
795 * Add a parametric option to a parmlist_entry,
796 * replacing old value, if already present.
798 void set_param_opt(TALLOC_CTX
*mem_ctx
,
799 struct parmlist_entry
**opt_list
,
800 const char *opt_name
,
801 const char *opt_value
,
804 struct parmlist_entry
*new_opt
, *opt
;
810 /* Traverse destination */
812 /* If we already have same option, override it */
813 if (strwicmp(opt
->key
, opt_name
) == 0) {
814 if ((opt
->priority
& FLAG_CMDLINE
) &&
815 !(priority
& FLAG_CMDLINE
)) {
816 /* it's been marked as not to be
820 TALLOC_FREE(opt
->value
);
821 TALLOC_FREE(opt
->list
);
822 opt
->value
= talloc_strdup(opt
, opt_value
);
823 opt
->priority
= priority
;
830 new_opt
= talloc(mem_ctx
, struct parmlist_entry
);
831 if (new_opt
== NULL
) {
835 new_opt
->key
= talloc_strdup(new_opt
, opt_name
);
836 if (new_opt
->key
== NULL
) {
837 smb_panic("talloc_strdup failed");
840 new_opt
->value
= talloc_strdup(new_opt
, opt_value
);
841 if (new_opt
->value
== NULL
) {
842 smb_panic("talloc_strdup failed");
845 new_opt
->list
= NULL
;
846 new_opt
->priority
= priority
;
847 DLIST_ADD(*opt_list
, new_opt
);
852 * Copy a service structure to another.
853 * If pcopymapDest is NULL then copy all fields
856 void copy_service(struct loadparm_service
*pserviceDest
,
857 const struct loadparm_service
*pserviceSource
,
858 struct bitmap
*pcopymapDest
)
861 bool bcopyall
= (pcopymapDest
== NULL
);
862 struct parmlist_entry
*data
;
864 for (i
= 0; parm_table
[i
].label
; i
++)
865 if (parm_table
[i
].p_class
== P_LOCAL
&&
866 (bcopyall
|| bitmap_query(pcopymapDest
, i
))) {
867 const void *src_ptr
=
868 ((const char *)pserviceSource
) + parm_table
[i
].offset
;
870 ((char *)pserviceDest
) + parm_table
[i
].offset
;
872 switch (parm_table
[i
].type
) {
875 *(bool *)dest_ptr
= *(const bool *)src_ptr
;
882 *(int *)dest_ptr
= *(const int *)src_ptr
;
886 *(char *)dest_ptr
= *(const char *)src_ptr
;
890 lpcfg_string_set(pserviceDest
,
892 *(const char * const *)src_ptr
);
896 lpcfg_string_set_upper(pserviceDest
,
898 *(const char * const *)src_ptr
);
902 TALLOC_FREE(*((char ***)dest_ptr
));
903 *(char ***)dest_ptr
= str_list_copy(pserviceDest
,
904 *discard_const_p(const char **, src_ptr
));
912 init_copymap(pserviceDest
);
913 if (pserviceSource
->copymap
)
914 bitmap_copy(pserviceDest
->copymap
,
915 pserviceSource
->copymap
);
918 for (data
= pserviceSource
->param_opt
; data
!= NULL
; data
= data
->next
) {
919 set_param_opt(pserviceDest
, &pserviceDest
->param_opt
,
920 data
->key
, data
->value
, data
->priority
);
925 * Check a service for consistency. Return False if the service is in any way
926 * incomplete or faulty, else True.
928 bool lpcfg_service_ok(struct loadparm_service
*service
)
933 if (service
->szService
[0] == '\0') {
934 DEBUG(0, ("The following message indicates an internal error:\n"));
935 DEBUG(0, ("No service name in service entry.\n"));
939 /* The [printers] entry MUST be printable. I'm all for flexibility, but */
940 /* I can't see why you'd want a non-printable printer service... */
941 if (strwicmp(service
->szService
, PRINTERS_NAME
) == 0) {
942 if (!service
->printable
) {
943 DEBUG(0, ("WARNING: [%s] service MUST be printable!\n",
944 service
->szService
));
945 service
->printable
= true;
947 /* [printers] service must also be non-browsable. */
948 if (service
->browseable
)
949 service
->browseable
= false;
952 if (service
->path
[0] == '\0' &&
953 strwicmp(service
->szService
, HOMES_NAME
) != 0 &&
954 service
->msdfs_proxy
[0] == '\0')
956 DEBUG(0, ("WARNING: No path in service %s - making it unavailable!\n",
957 service
->szService
));
958 service
->available
= false;
961 if (!service
->available
)
962 DEBUG(1, ("NOTE: Service %s is flagged unavailable.\n",
963 service
->szService
));
969 /*******************************************************************
970 Keep a linked list of all config files so we know when one has changed
971 it's date and needs to be reloaded.
972 ********************************************************************/
974 void add_to_file_list(TALLOC_CTX
*mem_ctx
, struct file_lists
**list
,
975 const char *fname
, const char *subfname
)
977 struct file_lists
*f
= *list
;
980 if (f
->name
&& !strcmp(f
->name
, fname
))
986 f
= talloc(mem_ctx
, struct file_lists
);
990 f
->name
= talloc_strdup(f
, fname
);
995 f
->subfname
= talloc_strdup(f
, subfname
);
1001 f
->modtime
= file_modtime(subfname
);
1003 time_t t
= file_modtime(subfname
);
1010 DEBUG(0, ("Unable to add file to file list: %s\n", fname
));
1014 /*******************************************************************
1015 Check if a config file has changed date.
1016 ********************************************************************/
1017 bool lpcfg_file_list_changed(struct loadparm_context
*lp_ctx
)
1019 struct file_lists
*f
;
1020 DEBUG(6, ("lpcfg_file_list_changed()\n"));
1022 for (f
= lp_ctx
->file_lists
; f
!= NULL
; f
= f
->next
) {
1026 n2
= standard_sub_basic(lp_ctx
, f
->name
);
1028 DEBUGADD(6, ("file %s -> %s last mod_time: %s\n",
1029 f
->name
, n2
, ctime(&f
->modtime
)));
1031 mod_time
= file_modtime(n2
);
1033 if (mod_time
&& ((f
->modtime
!= mod_time
) || (f
->subfname
== NULL
) || (strcmp(n2
, f
->subfname
) != 0))) {
1034 DEBUGADD(6, ("file %s modified: %s\n", n2
,
1036 f
->modtime
= mod_time
;
1037 talloc_free(f
->subfname
);
1038 f
->subfname
= talloc_strdup(f
, n2
);
1048 * set the value for a P_ENUM
1050 bool lp_set_enum_parm( struct parm_struct
*parm
, const char *pszParmValue
,
1055 for (i
= 0; parm
->enum_list
[i
].name
; i
++) {
1056 if (strwicmp(pszParmValue
, parm
->enum_list
[i
].name
) == 0) {
1057 *ptr
= parm
->enum_list
[i
].value
;
1061 DEBUG(0, ("WARNING: Ignoring invalid value '%s' for parameter '%s'\n",
1062 pszParmValue
, parm
->label
));
1067 /***************************************************************************
1068 Handle the "realm" parameter
1069 ***************************************************************************/
1071 bool handle_realm(struct loadparm_context
*lp_ctx
, struct loadparm_service
*service
,
1072 const char *pszParmValue
, char **ptr
)
1077 upper
= strupper_talloc(lp_ctx
, pszParmValue
);
1078 if (upper
== NULL
) {
1082 lower
= strlower_talloc(lp_ctx
, pszParmValue
);
1083 if (lower
== NULL
) {
1088 lpcfg_string_set(lp_ctx
->globals
->ctx
, &lp_ctx
->globals
->realm_original
, pszParmValue
);
1089 lpcfg_string_set(lp_ctx
->globals
->ctx
, &lp_ctx
->globals
->realm
, upper
);
1090 lpcfg_string_set(lp_ctx
->globals
->ctx
, &lp_ctx
->globals
->dnsdomain
, lower
);
1095 /***************************************************************************
1096 Handle the include operation.
1097 ***************************************************************************/
1099 bool handle_include(struct loadparm_context
*lp_ctx
, struct loadparm_service
*service
,
1100 const char *pszParmValue
, char **ptr
)
1104 if (lp_ctx
->s3_fns
) {
1105 return lp_ctx
->s3_fns
->lp_include(lp_ctx
, service
, pszParmValue
, ptr
);
1108 fname
= standard_sub_basic(lp_ctx
, pszParmValue
);
1110 add_to_file_list(lp_ctx
, &lp_ctx
->file_lists
, pszParmValue
, fname
);
1112 lpcfg_string_set(lp_ctx
, ptr
, fname
);
1114 if (file_exist(fname
))
1115 return pm_process(fname
, do_section
, lpcfg_do_parameter
, lp_ctx
);
1117 DEBUG(2, ("Can't find include file %s\n", fname
));
1122 /***************************************************************************
1123 Handle the interpretation of the copy parameter.
1124 ***************************************************************************/
1126 bool handle_copy(struct loadparm_context
*lp_ctx
, struct loadparm_service
*service
,
1127 const char *pszParmValue
, char **ptr
)
1130 struct loadparm_service
*serviceTemp
= NULL
;
1134 DEBUG(3, ("Copying service from service %s\n", pszParmValue
));
1136 serviceTemp
= lpcfg_getservicebyname(lp_ctx
, pszParmValue
);
1138 if (service
== NULL
) {
1139 DEBUG(0, ("Unable to copy service - invalid service destination.\n"));
1143 if (serviceTemp
!= NULL
) {
1144 if (serviceTemp
== service
) {
1145 DEBUG(0, ("Can't copy service %s - unable to copy self!\n", pszParmValue
));
1147 copy_service(service
,
1150 lpcfg_string_set(service
, ptr
, pszParmValue
);
1155 DEBUG(0, ("Unable to copy service - source not found: %s\n",
1163 bool handle_debug_list(struct loadparm_context
*lp_ctx
, struct loadparm_service
*service
,
1164 const char *pszParmValue
, char **ptr
)
1166 lpcfg_string_set(lp_ctx
->globals
->ctx
, ptr
, pszParmValue
);
1168 return debug_parse_levels(pszParmValue
);
1171 bool handle_logfile(struct loadparm_context
*lp_ctx
, struct loadparm_service
*service
,
1172 const char *pszParmValue
, char **ptr
)
1174 if (lp_ctx
->s3_fns
== NULL
) {
1175 debug_set_logfile(pszParmValue
);
1178 lpcfg_string_set(lp_ctx
->globals
->ctx
, ptr
, pszParmValue
);
1184 * These special charset handling methods only run in the source3 code.
1187 bool handle_charset(struct loadparm_context
*lp_ctx
, struct loadparm_service
*service
,
1188 const char *pszParmValue
, char **ptr
)
1190 if (lp_ctx
->s3_fns
) {
1191 if (*ptr
== NULL
|| strcmp(*ptr
, pszParmValue
) != 0) {
1192 global_iconv_handle
= smb_iconv_handle_reinit(NULL
,
1193 lpcfg_dos_charset(lp_ctx
),
1194 lpcfg_unix_charset(lp_ctx
),
1195 true, global_iconv_handle
);
1199 return lpcfg_string_set(lp_ctx
->globals
->ctx
, ptr
, pszParmValue
);
1203 bool handle_dos_charset(struct loadparm_context
*lp_ctx
, struct loadparm_service
*service
,
1204 const char *pszParmValue
, char **ptr
)
1206 bool is_utf8
= false;
1207 size_t len
= strlen(pszParmValue
);
1209 if (lp_ctx
->s3_fns
) {
1210 if (len
== 4 || len
== 5) {
1211 /* Don't use StrCaseCmp here as we don't want to
1212 initialize iconv. */
1213 if ((toupper_m(pszParmValue
[0]) == 'U') &&
1214 (toupper_m(pszParmValue
[1]) == 'T') &&
1215 (toupper_m(pszParmValue
[2]) == 'F')) {
1217 if (pszParmValue
[3] == '8') {
1221 if (pszParmValue
[3] == '-' &&
1222 pszParmValue
[4] == '8') {
1229 if (*ptr
== NULL
|| strcmp(*ptr
, pszParmValue
) != 0) {
1231 DEBUG(0,("ERROR: invalid DOS charset: 'dos charset' must not "
1232 "be UTF8, using (default value) %s instead.\n",
1233 DEFAULT_DOS_CHARSET
));
1234 pszParmValue
= DEFAULT_DOS_CHARSET
;
1236 global_iconv_handle
= smb_iconv_handle_reinit(NULL
,
1237 lpcfg_dos_charset(lp_ctx
),
1238 lpcfg_unix_charset(lp_ctx
),
1239 true, global_iconv_handle
);
1243 return lpcfg_string_set(lp_ctx
->globals
->ctx
, ptr
, pszParmValue
);
1246 bool handle_printing(struct loadparm_context
*lp_ctx
, struct loadparm_service
*service
,
1247 const char *pszParmValue
, char **ptr
)
1249 static int parm_num
= -1;
1251 if (parm_num
== -1) {
1252 parm_num
= lpcfg_map_parameter("printing");
1255 if (!lp_set_enum_parm(&parm_table
[parm_num
], pszParmValue
, (int*)ptr
)) {
1259 if (lp_ctx
->s3_fns
) {
1260 if (service
== NULL
) {
1261 init_printer_values(lp_ctx
, lp_ctx
->globals
->ctx
, lp_ctx
->sDefault
);
1263 init_printer_values(lp_ctx
, service
, service
);
1270 bool handle_ldap_debug_level(struct loadparm_context
*lp_ctx
, struct loadparm_service
*service
,
1271 const char *pszParmValue
, char **ptr
)
1273 lp_ctx
->globals
->ldap_debug_level
= lp_int(pszParmValue
);
1275 if (lp_ctx
->s3_fns
) {
1276 lp_ctx
->s3_fns
->init_ldap_debugging();
1281 bool handle_netbios_aliases(struct loadparm_context
*lp_ctx
, struct loadparm_service
*service
,
1282 const char *pszParmValue
, char **ptr
)
1284 TALLOC_FREE(lp_ctx
->globals
->netbios_aliases
);
1285 lp_ctx
->globals
->netbios_aliases
= str_list_make_v3_const(lp_ctx
->globals
->ctx
,
1286 pszParmValue
, NULL
);
1288 if (lp_ctx
->s3_fns
) {
1289 return lp_ctx
->s3_fns
->set_netbios_aliases(lp_ctx
->globals
->netbios_aliases
);
1295 * idmap related parameters
1298 bool handle_idmap_backend(struct loadparm_context
*lp_ctx
, struct loadparm_service
*service
,
1299 const char *pszParmValue
, char **ptr
)
1301 if (lp_ctx
->s3_fns
) {
1302 lp_do_parameter_parametric(lp_ctx
, service
, "idmap config * : backend",
1306 return lpcfg_string_set(lp_ctx
->globals
->ctx
, ptr
, pszParmValue
);
1309 bool handle_idmap_uid(struct loadparm_context
*lp_ctx
, struct loadparm_service
*service
,
1310 const char *pszParmValue
, char **ptr
)
1312 if (lp_ctx
->s3_fns
) {
1313 lp_do_parameter_parametric(lp_ctx
, service
, "idmap config * : range",
1317 return lpcfg_string_set(lp_ctx
->globals
->ctx
, ptr
, pszParmValue
);
1320 bool handle_idmap_gid(struct loadparm_context
*lp_ctx
, struct loadparm_service
*service
,
1321 const char *pszParmValue
, char **ptr
)
1323 if (lp_ctx
->s3_fns
) {
1324 lp_do_parameter_parametric(lp_ctx
, service
, "idmap config * : range",
1328 return lpcfg_string_set(lp_ctx
->globals
->ctx
, ptr
, pszParmValue
);
1331 bool handle_smb_ports(struct loadparm_context
*lp_ctx
, struct loadparm_service
*service
,
1332 const char *pszParmValue
, char **ptr
)
1334 static int parm_num
= -1;
1338 if (!pszParmValue
|| !*pszParmValue
) {
1342 if (parm_num
== -1) {
1343 parm_num
= lpcfg_map_parameter("smb ports");
1344 if (parm_num
== -1) {
1349 if(!set_variable_helper(lp_ctx
->globals
->ctx
, parm_num
, ptr
, "smb ports",
1354 list
= lp_ctx
->globals
->smb_ports
;
1359 /* Check that each port is a valid integer and within range */
1360 for (i
= 0; list
[i
] != NULL
; i
++) {
1363 port
= strtol(list
[i
], &end
, 10);
1364 if (*end
!= '\0' || port
<= 0 || port
> 65535) {
1373 bool handle_smb2_max_credits(struct loadparm_context
*lp_ctx
,
1374 struct loadparm_service
*service
,
1375 const char *pszParmValue
, char **ptr
)
1377 int value
= lp_int(pszParmValue
);
1380 value
= DEFAULT_SMB2_MAX_CREDITS
;
1383 *(int *)ptr
= value
;
1388 bool handle_cups_encrypt(struct loadparm_context
*lp_ctx
,
1389 struct loadparm_service
*service
,
1390 const char *pszParmValue
, char **ptr
)
1393 #ifdef HAVE_HTTPCONNECTENCRYPT
1394 int value
= lp_int(pszParmValue
);
1398 result
= HTTP_ENCRYPT_REQUIRED
;
1401 result
= HTTP_ENCRYPT_ALWAYS
;
1404 result
= HTTP_ENCRYPT_NEVER
;
1411 *(int *)ptr
= result
;
1416 /***************************************************************************
1417 Initialise a copymap.
1418 ***************************************************************************/
1421 * Initializes service copymap
1422 * Note: pservice *must* be valid TALLOC_CTX
1424 void init_copymap(struct loadparm_service
*pservice
)
1428 TALLOC_FREE(pservice
->copymap
);
1430 pservice
->copymap
= bitmap_talloc(pservice
, num_parameters());
1431 if (!pservice
->copymap
) {
1433 ("Couldn't allocate copymap!! (size %d)\n",
1434 (int)num_parameters()));
1436 for (i
= 0; i
< num_parameters(); i
++) {
1437 bitmap_set(pservice
->copymap
, i
);
1443 * Process a parametric option
1445 static bool lp_do_parameter_parametric(struct loadparm_context
*lp_ctx
,
1446 struct loadparm_service
*service
,
1447 const char *pszParmName
,
1448 const char *pszParmValue
, int flags
)
1450 struct parmlist_entry
**data
;
1452 TALLOC_CTX
*mem_ctx
;
1454 while (isspace((unsigned char)*pszParmName
)) {
1458 name
= strlower_talloc(lp_ctx
, pszParmName
);
1459 if (!name
) return false;
1461 if (service
== NULL
) {
1462 data
= &lp_ctx
->globals
->param_opt
;
1464 * s3 code cannot deal with parametric options stored on the globals ctx.
1466 if (lp_ctx
->s3_fns
!= NULL
) {
1469 mem_ctx
= lp_ctx
->globals
->ctx
;
1472 data
= &service
->param_opt
;
1476 set_param_opt(mem_ctx
, data
, name
, pszParmValue
, flags
);
1483 static bool set_variable_helper(TALLOC_CTX
*mem_ctx
, int parmnum
, void *parm_ptr
,
1484 const char *pszParmName
, const char *pszParmValue
)
1488 /* switch on the type of variable it is */
1489 switch (parm_table
[parmnum
].type
)
1493 if (!set_boolean(pszParmValue
, &b
)) {
1494 DEBUG(0, ("set_variable_helper(%s): value is not "
1495 "boolean!\n", pszParmValue
));
1498 *(bool *)parm_ptr
= b
;
1504 if (!set_boolean(pszParmValue
, &b
)) {
1505 DEBUG(0, ("set_variable_helper(%s): value is not "
1506 "boolean!\n", pszParmValue
));
1509 *(bool *)parm_ptr
= !b
;
1514 *(int *)parm_ptr
= lp_int(pszParmValue
);
1518 *(char *)parm_ptr
= *pszParmValue
;
1522 i
= sscanf(pszParmValue
, "%o", (int *)parm_ptr
);
1524 DEBUG ( 0, ("Invalid octal number %s\n", pszParmName
));
1532 if (conv_str_size_error(pszParmValue
, &val
)) {
1533 if (val
<= INT_MAX
) {
1534 *(int *)parm_ptr
= (int)val
;
1539 DEBUG(0, ("set_variable_helper(%s): value is not "
1540 "a valid size specifier!\n", pszParmValue
));
1545 TALLOC_FREE(*(char ***)parm_ptr
);
1546 *(char ***)parm_ptr
= str_list_make_v3(mem_ctx
,
1547 pszParmValue
, NULL
);
1552 char **new_list
= str_list_make_v3(mem_ctx
,
1553 pszParmValue
, NULL
);
1554 if (new_list
== NULL
) {
1558 for (i
=0; new_list
[i
]; i
++) {
1559 if (*(const char ***)parm_ptr
!= NULL
&&
1560 new_list
[i
][0] == '+' &&
1563 if (!str_list_check(*(const char ***)parm_ptr
,
1565 *(const char ***)parm_ptr
= str_list_add(*(const char ***)parm_ptr
,
1568 } else if (*(const char ***)parm_ptr
!= NULL
&&
1569 new_list
[i
][0] == '-' &&
1572 str_list_remove(*(const char ***)parm_ptr
,
1576 DEBUG(0, ("Unsupported list syntax for: %s = %s\n",
1577 pszParmName
, pszParmValue
));
1580 *(char ***)parm_ptr
= new_list
;
1588 lpcfg_string_set(mem_ctx
, (char **)parm_ptr
, pszParmValue
);
1592 lpcfg_string_set_upper(mem_ctx
, (char **)parm_ptr
, pszParmValue
);
1596 if (!lp_set_enum_parm(&parm_table
[parmnum
], pszParmValue
, (int*)parm_ptr
)) {
1607 static bool set_variable(TALLOC_CTX
*mem_ctx
, struct loadparm_service
*service
,
1608 int parmnum
, void *parm_ptr
,
1609 const char *pszParmName
, const char *pszParmValue
,
1610 struct loadparm_context
*lp_ctx
, bool on_globals
)
1615 /* if it is a special case then go ahead */
1616 if (parm_table
[parmnum
].special
) {
1617 ok
= parm_table
[parmnum
].special(lp_ctx
, service
, pszParmValue
,
1620 ok
= set_variable_helper(mem_ctx
, parmnum
, parm_ptr
,
1621 pszParmName
, pszParmValue
);
1628 if (on_globals
&& (lp_ctx
->flags
[parmnum
] & FLAG_DEFAULT
)) {
1629 lp_ctx
->flags
[parmnum
] &= ~FLAG_DEFAULT
;
1630 /* we have to also unset FLAG_DEFAULT on aliases */
1631 for (i
=parmnum
-1;i
>=0 && parm_table
[i
].offset
== parm_table
[parmnum
].offset
;i
--) {
1632 lp_ctx
->flags
[i
] &= ~FLAG_DEFAULT
;
1634 for (i
=parmnum
+1;i
<num_parameters() && parm_table
[i
].offset
== parm_table
[parmnum
].offset
;i
++) {
1635 lp_ctx
->flags
[i
] &= ~FLAG_DEFAULT
;
1642 bool lpcfg_do_global_parameter(struct loadparm_context
*lp_ctx
,
1643 const char *pszParmName
, const char *pszParmValue
)
1645 int parmnum
= lpcfg_map_parameter(pszParmName
);
1649 if (strchr(pszParmName
, ':')) {
1650 return lp_do_parameter_parametric(lp_ctx
, NULL
, pszParmName
, pszParmValue
, 0);
1652 DEBUG(0, ("Ignoring unknown parameter \"%s\"\n", pszParmName
));
1656 /* if the flag has been set on the command line, then don't allow override,
1657 but don't report an error */
1658 if (lp_ctx
->flags
[parmnum
] & FLAG_CMDLINE
) {
1662 if (parm_table
[parmnum
].flags
& FLAG_DEPRECATED
) {
1663 DEBUG(1, ("WARNING: The \"%s\" option is deprecated\n",
1667 parm_ptr
= lpcfg_parm_ptr(lp_ctx
, NULL
, &parm_table
[parmnum
]);
1669 return set_variable(lp_ctx
->globals
->ctx
, NULL
, parmnum
, parm_ptr
,
1670 pszParmName
, pszParmValue
, lp_ctx
, true);
1673 bool lpcfg_do_service_parameter(struct loadparm_context
*lp_ctx
,
1674 struct loadparm_service
*service
,
1675 const char *pszParmName
, const char *pszParmValue
)
1679 int parmnum
= lpcfg_map_parameter(pszParmName
);
1682 if (strchr(pszParmName
, ':')) {
1683 return lp_do_parameter_parametric(lp_ctx
, service
, pszParmName
, pszParmValue
, 0);
1685 DEBUG(0, ("Ignoring unknown parameter \"%s\"\n", pszParmName
));
1689 /* if the flag has been set on the command line, then don't allow override,
1690 but don't report an error */
1691 if (lp_ctx
->flags
[parmnum
] & FLAG_CMDLINE
) {
1695 if (parm_table
[parmnum
].flags
& FLAG_DEPRECATED
) {
1696 DEBUG(1, ("WARNING: The \"%s\" option is deprecated\n",
1700 if (parm_table
[parmnum
].p_class
== P_GLOBAL
) {
1702 ("Global parameter %s found in service section!\n",
1706 parm_ptr
= ((char *)service
) + parm_table
[parmnum
].offset
;
1708 if (!service
->copymap
)
1709 init_copymap(service
);
1711 /* this handles the aliases - set the copymap for other
1712 * entries with the same data pointer */
1713 for (i
= 0; parm_table
[i
].label
; i
++)
1714 if (parm_table
[i
].offset
== parm_table
[parmnum
].offset
&&
1715 parm_table
[i
].p_class
== parm_table
[parmnum
].p_class
)
1716 bitmap_clear(service
->copymap
, i
);
1718 return set_variable(service
, service
, parmnum
, parm_ptr
, pszParmName
,
1719 pszParmValue
, lp_ctx
, false);
1723 * Process a parameter.
1726 bool lpcfg_do_parameter(const char *pszParmName
, const char *pszParmValue
,
1729 struct loadparm_context
*lp_ctx
= (struct loadparm_context
*)userdata
;
1731 if (lp_ctx
->bInGlobalSection
)
1732 return lpcfg_do_global_parameter(lp_ctx
, pszParmName
,
1735 return lpcfg_do_service_parameter(lp_ctx
, lp_ctx
->currentService
,
1736 pszParmName
, pszParmValue
);
1740 variable argument do parameter
1742 bool lpcfg_do_global_parameter_var(struct loadparm_context
*lp_ctx
, const char *pszParmName
, const char *fmt
, ...) PRINTF_ATTRIBUTE(3, 4);
1743 bool lpcfg_do_global_parameter_var(struct loadparm_context
*lp_ctx
,
1744 const char *pszParmName
, const char *fmt
, ...)
1751 s
= talloc_vasprintf(NULL
, fmt
, ap
);
1753 ret
= lpcfg_do_global_parameter(lp_ctx
, pszParmName
, s
);
1760 set a parameter from the commandline - this is called from command line parameter
1761 parsing code. It sets the parameter then marks the parameter as unable to be modified
1762 by smb.conf processing
1764 bool lpcfg_set_cmdline(struct loadparm_context
*lp_ctx
, const char *pszParmName
,
1765 const char *pszParmValue
)
1770 while (isspace((unsigned char)*pszParmValue
)) pszParmValue
++;
1772 parmnum
= lpcfg_map_parameter(pszParmName
);
1774 if (parmnum
< 0 && strchr(pszParmName
, ':')) {
1775 /* set a parametric option */
1777 ok
= lp_do_parameter_parametric(lp_ctx
, NULL
, pszParmName
,
1778 pszParmValue
, FLAG_CMDLINE
);
1779 if (lp_ctx
->s3_fns
!= NULL
) {
1781 lp_ctx
->s3_fns
->store_cmdline(pszParmName
, pszParmValue
);
1788 DEBUG(0,("Unknown option '%s'\n", pszParmName
));
1792 /* reset the CMDLINE flag in case this has been called before */
1793 lp_ctx
->flags
[parmnum
] &= ~FLAG_CMDLINE
;
1795 if (!lpcfg_do_global_parameter(lp_ctx
, pszParmName
, pszParmValue
)) {
1799 lp_ctx
->flags
[parmnum
] |= FLAG_CMDLINE
;
1801 /* we have to also set FLAG_CMDLINE on aliases */
1803 i
>=0 && parm_table
[i
].p_class
== parm_table
[parmnum
].p_class
&&
1804 parm_table
[i
].offset
== parm_table
[parmnum
].offset
;
1806 lp_ctx
->flags
[i
] |= FLAG_CMDLINE
;
1809 i
<num_parameters() &&
1810 parm_table
[i
].p_class
== parm_table
[parmnum
].p_class
&&
1811 parm_table
[i
].offset
== parm_table
[parmnum
].offset
;
1813 lp_ctx
->flags
[i
] |= FLAG_CMDLINE
;
1816 if (lp_ctx
->s3_fns
!= NULL
) {
1817 lp_ctx
->s3_fns
->store_cmdline(pszParmName
, pszParmValue
);
1824 set a option from the commandline in 'a=b' format. Use to support --option
1826 bool lpcfg_set_option(struct loadparm_context
*lp_ctx
, const char *option
)
1831 s
= talloc_strdup(NULL
, option
);
1844 ret
= lpcfg_set_cmdline(lp_ctx
, s
, p
+1);
1850 #define BOOLSTR(b) ((b) ? "Yes" : "No")
1853 * Print a parameter of the specified type.
1856 void lpcfg_print_parameter(struct parm_struct
*p
, void *ptr
, FILE * f
)
1858 /* For the seperation of lists values that we print below */
1859 const char *list_sep
= ", ";
1864 for (i
= 0; p
->enum_list
[i
].name
; i
++) {
1865 if (*(int *)ptr
== p
->enum_list
[i
].value
) {
1867 p
->enum_list
[i
].name
);
1874 fprintf(f
, "%s", BOOLSTR(*(bool *)ptr
));
1878 fprintf(f
, "%s", BOOLSTR(!*(bool *)ptr
));
1883 fprintf(f
, "%d", *(int *)ptr
);
1887 fprintf(f
, "%c", *(char *)ptr
);
1891 int val
= *(int *)ptr
;
1895 fprintf(f
, "0%03o", val
);
1904 if ((char ***)ptr
&& *(char ***)ptr
) {
1905 char **list
= *(char ***)ptr
;
1906 for (; *list
; list
++) {
1907 /* surround strings with whitespace in double quotes */
1908 if (*(list
+1) == NULL
) {
1909 /* last item, no extra separator */
1912 if ( strchr_m( *list
, ' ' ) ) {
1913 fprintf(f
, "\"%s\"%s", *list
, list_sep
);
1915 fprintf(f
, "%s%s", *list
, list_sep
);
1923 if (*(char **)ptr
) {
1924 fprintf(f
, "%s", *(char **)ptr
);
1931 * Check if two parameters are equal.
1934 static bool lpcfg_equal_parameter(parm_type type
, void *ptr1
, void *ptr2
)
1939 return (*((bool *)ptr1
) == *((bool *)ptr2
));
1945 return (*((int *)ptr1
) == *((int *)ptr2
));
1948 return (*((char *)ptr1
) == *((char *)ptr2
));
1952 return str_list_equal(*(const char ***)ptr1
, *(const char ***)ptr2
);
1957 char *p1
= *(char **)ptr1
, *p2
= *(char **)ptr2
;
1962 return (p1
== p2
|| strequal(p1
, p2
));
1969 * Process a new section (service).
1971 * At this stage all sections are services.
1972 * Later we'll have special sections that permit server parameters to be set.
1973 * Returns True on success, False on failure.
1976 static bool do_section(const char *pszSectionName
, void *userdata
)
1978 struct loadparm_context
*lp_ctx
= (struct loadparm_context
*)userdata
;
1982 if (lp_ctx
->s3_fns
!= NULL
) {
1983 return lp_ctx
->s3_fns
->do_section(pszSectionName
, lp_ctx
);
1986 isglobal
= ((strwicmp(pszSectionName
, GLOBAL_NAME
) == 0) ||
1987 (strwicmp(pszSectionName
, GLOBAL_NAME2
) == 0));
1991 /* if we've just struck a global section, note the fact. */
1992 lp_ctx
->bInGlobalSection
= isglobal
;
1994 /* check for multiple global sections */
1995 if (lp_ctx
->bInGlobalSection
) {
1996 DEBUG(4, ("Processing section \"[%s]\"\n", pszSectionName
));
2000 /* if we have a current service, tidy it up before moving on */
2003 if (lp_ctx
->currentService
!= NULL
)
2004 bRetval
= lpcfg_service_ok(lp_ctx
->currentService
);
2006 /* if all is still well, move to the next record in the services array */
2008 /* We put this here to avoid an odd message order if messages are */
2009 /* issued by the post-processing of a previous section. */
2010 DEBUG(4, ("Processing section \"[%s]\"\n", pszSectionName
));
2012 if ((lp_ctx
->currentService
= lpcfg_add_service(lp_ctx
, lp_ctx
->sDefault
,
2015 DEBUG(0, ("Failed to add a new service\n"));
2025 * Determine if a particular base parameter is currently set to the default value.
2028 static bool is_default(void *base_structure
, int i
)
2030 void *def_ptr
= ((char *)base_structure
) + parm_table
[i
].offset
;
2031 switch (parm_table
[i
].type
) {
2034 return str_list_equal((const char * const *)parm_table
[i
].def
.lvalue
,
2035 *(const char * const **)def_ptr
);
2038 return strequal(parm_table
[i
].def
.svalue
,
2042 return parm_table
[i
].def
.bvalue
==
2049 return parm_table
[i
].def
.ivalue
==
2056 *Display the contents of the global structure.
2059 void lpcfg_dump_globals(struct loadparm_context
*lp_ctx
, FILE *f
,
2063 struct parmlist_entry
*data
;
2065 fprintf(f
, "# Global parameters\n[global]\n");
2067 for (i
= 0; parm_table
[i
].label
; i
++)
2068 if (parm_table
[i
].p_class
== P_GLOBAL
&&
2069 (i
== 0 || (parm_table
[i
].offset
!= parm_table
[i
- 1].offset
))) {
2070 if (!show_defaults
) {
2071 if (lp_ctx
->flags
&& (lp_ctx
->flags
[i
] & FLAG_DEFAULT
)) {
2075 if (is_default(lp_ctx
->globals
, i
)) {
2080 fprintf(f
, "\t%s = ", parm_table
[i
].label
);
2081 lpcfg_print_parameter(&parm_table
[i
], lpcfg_parm_ptr(lp_ctx
, NULL
, &parm_table
[i
]), f
);
2084 if (lp_ctx
->globals
->param_opt
!= NULL
) {
2085 for (data
= lp_ctx
->globals
->param_opt
; data
;
2086 data
= data
->next
) {
2087 if (!show_defaults
&& (data
->priority
& FLAG_DEFAULT
)) {
2090 fprintf(f
, "\t%s = %s\n", data
->key
, data
->value
);
2097 * Display the contents of a single services record.
2100 void lpcfg_dump_a_service(struct loadparm_service
* pService
, struct loadparm_service
*sDefault
, FILE * f
,
2101 unsigned int *flags
, bool show_defaults
)
2104 struct parmlist_entry
*data
;
2106 if (pService
!= sDefault
)
2107 fprintf(f
, "\n[%s]\n", pService
->szService
);
2109 for (i
= 0; parm_table
[i
].label
; i
++) {
2110 if (parm_table
[i
].p_class
== P_LOCAL
&&
2111 (*parm_table
[i
].label
!= '-') &&
2112 (i
== 0 || (parm_table
[i
].offset
!= parm_table
[i
- 1].offset
)))
2114 if (pService
== sDefault
) {
2115 if (!show_defaults
) {
2116 if (flags
&& (flags
[i
] & FLAG_DEFAULT
)) {
2120 if (is_default(sDefault
, i
)) {
2125 if (lpcfg_equal_parameter(parm_table
[i
].type
,
2126 ((char *)pService
) +
2127 parm_table
[i
].offset
,
2128 ((char *)sDefault
) +
2129 parm_table
[i
].offset
))
2133 fprintf(f
, "\t%s = ", parm_table
[i
].label
);
2134 lpcfg_print_parameter(&parm_table
[i
],
2135 ((char *)pService
) + parm_table
[i
].offset
, f
);
2139 if (pService
->param_opt
!= NULL
) {
2140 for (data
= pService
->param_opt
; data
; data
= data
->next
) {
2141 if (!show_defaults
&& (data
->priority
& FLAG_DEFAULT
)) {
2144 fprintf(f
, "\t%s = %s\n", data
->key
, data
->value
);
2149 bool lpcfg_dump_a_parameter(struct loadparm_context
*lp_ctx
,
2150 struct loadparm_service
*service
,
2151 const char *parm_name
, FILE * f
)
2153 struct parm_struct
*parm
;
2155 char *local_parm_name
;
2157 const char *parm_opt_value
;
2159 /* check for parametrical option */
2160 local_parm_name
= talloc_strdup(lp_ctx
, parm_name
);
2161 if (local_parm_name
== NULL
) {
2165 parm_opt
= strchr( local_parm_name
, ':');
2170 if (strlen(parm_opt
)) {
2171 parm_opt_value
= lpcfg_parm_string(lp_ctx
, service
,
2172 local_parm_name
, parm_opt
);
2173 if (parm_opt_value
) {
2174 fprintf(f
, "%s\n", parm_opt_value
);
2181 /* parameter is not parametric, search the table */
2182 parm
= lpcfg_parm_struct(lp_ctx
, parm_name
);
2187 if (service
!= NULL
&& parm
->p_class
== P_GLOBAL
) {
2191 ptr
= lpcfg_parm_ptr(lp_ctx
, service
,parm
);
2193 lpcfg_print_parameter(parm
, ptr
, f
);
2199 * Auto-load some home services.
2201 static void lpcfg_add_auto_services(struct loadparm_context
*lp_ctx
,
2207 /***************************************************************************
2208 Initialise the sDefault parameter structure for the printer values.
2209 ***************************************************************************/
2211 void init_printer_values(struct loadparm_context
*lp_ctx
, TALLOC_CTX
*ctx
,
2212 struct loadparm_service
*pService
)
2214 /* choose defaults depending on the type of printing */
2215 switch (pService
->printing
) {
2220 lpcfg_string_set(ctx
, &pService
->lpq_command
, "lpq -P'%p'");
2221 lpcfg_string_set(ctx
, &pService
->lprm_command
, "lprm -P'%p' %j");
2222 lpcfg_string_set(ctx
, &pService
->print_command
, "lpr -r -P'%p' %s");
2227 lpcfg_string_set(ctx
, &pService
->lpq_command
, "lpq -P'%p'");
2228 lpcfg_string_set(ctx
, &pService
->lprm_command
, "lprm -P'%p' %j");
2229 lpcfg_string_set(ctx
, &pService
->print_command
, "lpr -r -P'%p' %s");
2230 lpcfg_string_set(ctx
, &pService
->queuepause_command
, "lpc stop '%p'");
2231 lpcfg_string_set(ctx
, &pService
->queueresume_command
, "lpc start '%p'");
2232 lpcfg_string_set(ctx
, &pService
->lppause_command
, "lpc hold '%p' %j");
2233 lpcfg_string_set(ctx
, &pService
->lpresume_command
, "lpc release '%p' %j");
2238 /* set the lpq command to contain the destination printer
2239 name only. This is used by cups_queue_get() */
2240 lpcfg_string_set(ctx
, &pService
->lpq_command
, "%p");
2241 lpcfg_string_set(ctx
, &pService
->lprm_command
, "");
2242 lpcfg_string_set(ctx
, &pService
->print_command
, "");
2243 lpcfg_string_set(ctx
, &pService
->lppause_command
, "");
2244 lpcfg_string_set(ctx
, &pService
->lpresume_command
, "");
2245 lpcfg_string_set(ctx
, &pService
->queuepause_command
, "");
2246 lpcfg_string_set(ctx
, &pService
->queueresume_command
, "");
2251 lpcfg_string_set(ctx
, &pService
->lpq_command
, "lpstat -o%p");
2252 lpcfg_string_set(ctx
, &pService
->lprm_command
, "cancel %p-%j");
2253 lpcfg_string_set(ctx
, &pService
->print_command
, "lp -c -d%p %s; rm %s");
2254 lpcfg_string_set(ctx
, &pService
->queuepause_command
, "disable %p");
2255 lpcfg_string_set(ctx
, &pService
->queueresume_command
, "enable %p");
2257 lpcfg_string_set(ctx
, &pService
->lppause_command
, "lp -i %p-%j -H hold");
2258 lpcfg_string_set(ctx
, &pService
->lpresume_command
, "lp -i %p-%j -H resume");
2263 lpcfg_string_set(ctx
, &pService
->lpq_command
, "lpq -P%p");
2264 lpcfg_string_set(ctx
, &pService
->lprm_command
, "lprm -P%p %j");
2265 lpcfg_string_set(ctx
, &pService
->print_command
, "lp -r -P%p %s");
2268 #if defined(DEVELOPER) || defined(ENABLE_SELFTEST)
2272 const char *tdbfile
;
2273 TALLOC_CTX
*tmp_ctx
= talloc_new(ctx
);
2276 tmp
= lpcfg_parm_string(lp_ctx
, NULL
, "vlp", "tdbfile");
2278 tmp
= "/tmp/vlp.tdb";
2281 tdbfile
= talloc_asprintf(tmp_ctx
, "tdbfile=%s", tmp
);
2282 if (tdbfile
== NULL
) {
2283 tdbfile
="tdbfile=/tmp/vlp.tdb";
2286 tmp
= talloc_asprintf(tmp_ctx
, "vlp %s print %%p %%s",
2288 lpcfg_string_set(ctx
, &pService
->print_command
,
2289 tmp
? tmp
: "vlp print %p %s");
2291 tmp
= talloc_asprintf(tmp_ctx
, "vlp %s lpq %%p",
2293 lpcfg_string_set(ctx
, &pService
->lpq_command
,
2294 tmp
? tmp
: "vlp lpq %p");
2296 tmp
= talloc_asprintf(tmp_ctx
, "vlp %s lprm %%p %%j",
2298 lpcfg_string_set(ctx
, &pService
->lprm_command
,
2299 tmp
? tmp
: "vlp lprm %p %j");
2301 tmp
= talloc_asprintf(tmp_ctx
, "vlp %s lppause %%p %%j",
2303 lpcfg_string_set(ctx
, &pService
->lppause_command
,
2304 tmp
? tmp
: "vlp lppause %p %j");
2306 tmp
= talloc_asprintf(tmp_ctx
, "vlp %s lpresume %%p %%j",
2308 lpcfg_string_set(ctx
, &pService
->lpresume_command
,
2309 tmp
? tmp
: "vlp lpresume %p %j");
2311 tmp
= talloc_asprintf(tmp_ctx
, "vlp %s queuepause %%p",
2313 lpcfg_string_set(ctx
, &pService
->queuepause_command
,
2314 tmp
? tmp
: "vlp queuepause %p");
2316 tmp
= talloc_asprintf(tmp_ctx
, "vlp %s queueresume %%p",
2318 lpcfg_string_set(ctx
, &pService
->queueresume_command
,
2319 tmp
? tmp
: "vlp queueresume %p");
2320 TALLOC_FREE(tmp_ctx
);
2324 #endif /* DEVELOPER */
2330 * Unload unused services.
2333 void lpcfg_killunused(struct loadparm_context
*lp_ctx
,
2334 struct smbsrv_connection
*smb
,
2335 bool (*snumused
) (struct smbsrv_connection
*, int))
2339 if (lp_ctx
->s3_fns
!= NULL
) {
2340 smb_panic("Cannot be used from an s3 loadparm ctx");
2343 for (i
= 0; i
< lp_ctx
->iNumServices
; i
++) {
2344 if (lp_ctx
->services
[i
] == NULL
)
2347 if (!snumused
|| !snumused(smb
, i
)) {
2348 talloc_free(lp_ctx
->services
[i
]);
2349 lp_ctx
->services
[i
] = NULL
;
2355 static int lpcfg_destructor(struct loadparm_context
*lp_ctx
)
2357 struct parmlist_entry
*data
;
2359 if (lp_ctx
->refuse_free
) {
2360 /* someone is trying to free the
2361 global_loadparm_context.
2362 We can't allow that. */
2366 if (lp_ctx
->globals
->param_opt
!= NULL
) {
2367 struct parmlist_entry
*next
;
2368 for (data
= lp_ctx
->globals
->param_opt
; data
; data
=next
) {
2370 if (data
->priority
& FLAG_CMDLINE
) continue;
2371 DLIST_REMOVE(lp_ctx
->globals
->param_opt
, data
);
2379 struct defaults_hook_data
{
2381 lpcfg_defaults_hook hook
;
2382 struct defaults_hook_data
*prev
, *next
;
2383 } *defaults_hooks
= NULL
;
2386 bool lpcfg_register_defaults_hook(const char *name
, lpcfg_defaults_hook hook
)
2388 struct defaults_hook_data
*hook_data
= talloc(talloc_autofree_context(),
2389 struct defaults_hook_data
);
2390 hook_data
->name
= talloc_strdup(hook_data
, name
);
2391 hook_data
->hook
= hook
;
2392 DLIST_ADD(defaults_hooks
, hook_data
);
2397 * Initialise the global parameter structure.
2399 * Note that most callers should use loadparm_init_global() instead
2401 struct loadparm_context
*loadparm_init(TALLOC_CTX
*mem_ctx
)
2405 struct loadparm_context
*lp_ctx
;
2406 struct parmlist_entry
*parm
;
2408 struct defaults_hook_data
*defaults_hook
;
2410 lp_ctx
= talloc_zero(mem_ctx
, struct loadparm_context
);
2414 talloc_set_destructor(lp_ctx
, lpcfg_destructor
);
2415 lp_ctx
->bInGlobalSection
= true;
2416 lp_ctx
->globals
= talloc_zero(lp_ctx
, struct loadparm_global
);
2417 /* This appears odd, but globals in s3 isn't a pointer */
2418 lp_ctx
->globals
->ctx
= lp_ctx
->globals
;
2419 lp_ctx
->sDefault
= talloc_zero(lp_ctx
, struct loadparm_service
);
2420 lp_ctx
->flags
= talloc_zero_array(lp_ctx
, unsigned int, num_parameters());
2422 lp_ctx
->sDefault
->max_print_jobs
= 1000;
2423 lp_ctx
->sDefault
->available
= true;
2424 lp_ctx
->sDefault
->browseable
= true;
2425 lp_ctx
->sDefault
->read_only
= true;
2426 lp_ctx
->sDefault
->map_archive
= true;
2427 lp_ctx
->sDefault
->strict_locking
= true;
2428 lp_ctx
->sDefault
->oplocks
= true;
2429 lp_ctx
->sDefault
->create_mask
= 0744;
2430 lp_ctx
->sDefault
->force_create_mode
= 0000;
2431 lp_ctx
->sDefault
->directory_mask
= 0755;
2432 lp_ctx
->sDefault
->force_directory_mode
= 0000;
2434 DEBUG(3, ("Initialising global parameters\n"));
2436 for (i
= 0; parm_table
[i
].label
; i
++) {
2437 if ((parm_table
[i
].type
== P_STRING
||
2438 parm_table
[i
].type
== P_USTRING
) &&
2439 !(lp_ctx
->flags
[i
] & FLAG_CMDLINE
)) {
2441 if (parm_table
[i
].p_class
== P_LOCAL
) {
2442 r
= (char **)(((char *)lp_ctx
->sDefault
) + parm_table
[i
].offset
);
2444 r
= (char **)(((char *)lp_ctx
->globals
) + parm_table
[i
].offset
);
2446 *r
= talloc_strdup(lp_ctx
, "");
2450 logfile
= talloc_asprintf(lp_ctx
, "%s/log.samba", dyn_LOGFILEBASE
);
2451 lpcfg_do_global_parameter(lp_ctx
, "log file", logfile
);
2452 talloc_free(logfile
);
2454 lpcfg_do_global_parameter(lp_ctx
, "log level", "0");
2456 lpcfg_do_global_parameter(lp_ctx
, "syslog", "1");
2457 lpcfg_do_global_parameter(lp_ctx
, "syslog only", "No");
2458 lpcfg_do_global_parameter(lp_ctx
, "debug timestamp", "Yes");
2459 lpcfg_do_global_parameter(lp_ctx
, "debug prefix timestamp", "No");
2460 lpcfg_do_global_parameter(lp_ctx
, "debug hires timestamp", "Yes");
2461 lpcfg_do_global_parameter(lp_ctx
, "debug pid", "No");
2462 lpcfg_do_global_parameter(lp_ctx
, "debug uid", "No");
2463 lpcfg_do_global_parameter(lp_ctx
, "debug class", "No");
2465 lpcfg_do_global_parameter(lp_ctx
, "share backend", "classic");
2467 lpcfg_do_global_parameter(lp_ctx
, "server role", "auto");
2468 lpcfg_do_global_parameter(lp_ctx
, "domain logons", "No");
2469 lpcfg_do_global_parameter(lp_ctx
, "domain master", "Auto");
2471 /* options that can be set on the command line must be initialised via
2472 the slower lpcfg_do_global_parameter() to ensure that FLAG_CMDLINE is obeyed */
2474 lpcfg_do_global_parameter(lp_ctx
, "socket options", "TCP_NODELAY");
2476 lpcfg_do_global_parameter(lp_ctx
, "workgroup", DEFAULT_WORKGROUP
);
2477 myname
= get_myname(lp_ctx
);
2478 lpcfg_do_global_parameter(lp_ctx
, "netbios name", myname
);
2479 talloc_free(myname
);
2480 lpcfg_do_global_parameter(lp_ctx
, "name resolve order", "lmhosts wins host bcast");
2482 lpcfg_do_global_parameter(lp_ctx
, "fstype", "NTFS");
2484 lpcfg_do_global_parameter(lp_ctx
, "ntvfs handler", "unixuid default");
2485 lpcfg_do_global_parameter(lp_ctx
, "max connections", "0");
2487 lpcfg_do_global_parameter(lp_ctx
, "dcerpc endpoint servers", "epmapper wkssvc rpcecho samr netlogon lsarpc spoolss drsuapi dssetup unixinfo browser eventlog6 backupkey dnsserver");
2488 lpcfg_do_global_parameter(lp_ctx
, "server services", "s3fs rpc nbt wrepl ldap cldap kdc drepl winbindd ntp_signd kcc dnsupdate dns");
2489 lpcfg_do_global_parameter(lp_ctx
, "kccsrv:samba_kcc", "false");
2490 /* the winbind method for domain controllers is for both RODC
2491 auth forwarding and for trusted domains */
2492 lpcfg_do_global_parameter(lp_ctx
, "private dir", dyn_PRIVATE_DIR
);
2493 lpcfg_do_global_parameter(lp_ctx
, "registry:HKEY_LOCAL_MACHINE", "hklm.ldb");
2495 /* This hive should be dynamically generated by Samba using
2496 data from the sam, but for the moment leave it in a tdb to
2497 keep regedt32 from popping up an annoying dialog. */
2498 lpcfg_do_global_parameter(lp_ctx
, "registry:HKEY_USERS", "hku.ldb");
2500 /* using UTF8 by default allows us to support all chars */
2501 lpcfg_do_global_parameter(lp_ctx
, "unix charset", "UTF-8");
2503 /* Use codepage 850 as a default for the dos character set */
2504 lpcfg_do_global_parameter(lp_ctx
, "dos charset", "CP850");
2507 * Allow the default PASSWD_CHAT to be overridden in local.h.
2509 lpcfg_do_global_parameter(lp_ctx
, "passwd chat", DEFAULT_PASSWD_CHAT
);
2511 lpcfg_do_global_parameter(lp_ctx
, "pid directory", dyn_PIDDIR
);
2512 lpcfg_do_global_parameter(lp_ctx
, "lock dir", dyn_LOCKDIR
);
2513 lpcfg_do_global_parameter(lp_ctx
, "state directory", dyn_STATEDIR
);
2514 lpcfg_do_global_parameter(lp_ctx
, "cache directory", dyn_CACHEDIR
);
2515 lpcfg_do_global_parameter(lp_ctx
, "ncalrpc dir", dyn_NCALRPCDIR
);
2517 lpcfg_do_global_parameter(lp_ctx
, "nbt client socket address", "0.0.0.0");
2518 lpcfg_do_global_parameter_var(lp_ctx
, "server string",
2519 "Samba %s", SAMBA_VERSION_STRING
);
2521 lpcfg_do_global_parameter(lp_ctx
, "password server", "*");
2523 lpcfg_do_global_parameter(lp_ctx
, "max mux", "50");
2524 lpcfg_do_global_parameter(lp_ctx
, "max xmit", "16644");
2525 lpcfg_do_global_parameter(lp_ctx
, "host msdfs", "true");
2527 lpcfg_do_global_parameter(lp_ctx
, "LargeReadwrite", "True");
2528 lpcfg_do_global_parameter(lp_ctx
, "server min protocol", "LANMAN1");
2529 lpcfg_do_global_parameter(lp_ctx
, "server max protocol", "SMB3");
2530 lpcfg_do_global_parameter(lp_ctx
, "client min protocol", "CORE");
2531 lpcfg_do_global_parameter(lp_ctx
, "client max protocol", "default");
2532 lpcfg_do_global_parameter(lp_ctx
, "security", "AUTO");
2533 lpcfg_do_global_parameter(lp_ctx
, "EncryptPasswords", "True");
2534 lpcfg_do_global_parameter(lp_ctx
, "ReadRaw", "True");
2535 lpcfg_do_global_parameter(lp_ctx
, "WriteRaw", "True");
2536 lpcfg_do_global_parameter(lp_ctx
, "NullPasswords", "False");
2537 lpcfg_do_global_parameter(lp_ctx
, "old password allowed period", "60");
2538 lpcfg_do_global_parameter(lp_ctx
, "ObeyPamRestrictions", "False");
2540 lpcfg_do_global_parameter(lp_ctx
, "TimeServer", "False");
2541 lpcfg_do_global_parameter(lp_ctx
, "BindInterfacesOnly", "False");
2542 lpcfg_do_global_parameter(lp_ctx
, "Unicode", "True");
2543 lpcfg_do_global_parameter(lp_ctx
, "ClientLanManAuth", "False");
2544 lpcfg_do_global_parameter(lp_ctx
, "ClientNTLMv2Auth", "True");
2545 lpcfg_do_global_parameter(lp_ctx
, "LanmanAuth", "False");
2546 lpcfg_do_global_parameter(lp_ctx
, "NTLMAuth", "True");
2547 lpcfg_do_global_parameter(lp_ctx
, "client use spnego principal", "False");
2549 lpcfg_do_global_parameter(lp_ctx
, "UnixExtensions", "True");
2551 lpcfg_do_global_parameter(lp_ctx
, "PreferredMaster", "Auto");
2552 lpcfg_do_global_parameter(lp_ctx
, "LocalMaster", "True");
2554 lpcfg_do_global_parameter(lp_ctx
, "wins support", "False");
2555 lpcfg_do_global_parameter(lp_ctx
, "dns proxy", "True");
2557 lpcfg_do_global_parameter(lp_ctx
, "winbind separator", "\\");
2558 lpcfg_do_global_parameter(lp_ctx
, "winbind sealed pipes", "True");
2559 lpcfg_do_global_parameter(lp_ctx
, "require strong key", "True");
2560 lpcfg_do_global_parameter(lp_ctx
, "winbindd socket directory", dyn_WINBINDD_SOCKET_DIR
);
2561 lpcfg_do_global_parameter(lp_ctx
, "winbindd privileged socket directory", dyn_WINBINDD_PRIVILEGED_SOCKET_DIR
);
2562 lpcfg_do_global_parameter(lp_ctx
, "ntp signd socket directory", dyn_NTP_SIGND_SOCKET_DIR
);
2563 lpcfg_do_global_parameter_var(lp_ctx
, "dns update command", "%s/samba_dnsupdate", dyn_SCRIPTSBINDIR
);
2564 lpcfg_do_global_parameter_var(lp_ctx
, "spn update command", "%s/samba_spnupdate", dyn_SCRIPTSBINDIR
);
2565 lpcfg_do_global_parameter_var(lp_ctx
, "samba kcc command",
2566 "%s/samba_kcc", dyn_SCRIPTSBINDIR
);
2567 lpcfg_do_global_parameter(lp_ctx
, "template shell", "/bin/false");
2568 lpcfg_do_global_parameter(lp_ctx
, "template homedir", "/home/%D/%U");
2570 lpcfg_do_global_parameter(lp_ctx
, "client signing", "default");
2571 lpcfg_do_global_parameter(lp_ctx
, "server signing", "default");
2573 lpcfg_do_global_parameter(lp_ctx
, "use spnego", "True");
2575 lpcfg_do_global_parameter(lp_ctx
, "use mmap", "True");
2577 lpcfg_do_global_parameter(lp_ctx
, "smb ports", "445 139");
2578 lpcfg_do_global_parameter_var(lp_ctx
, "nbt port", "%d", NBT_NAME_SERVICE_PORT
);
2579 lpcfg_do_global_parameter_var(lp_ctx
, "dgram port", "%d", NBT_DGRAM_SERVICE_PORT
);
2580 lpcfg_do_global_parameter(lp_ctx
, "cldap port", "389");
2581 lpcfg_do_global_parameter(lp_ctx
, "krb5 port", "88");
2582 lpcfg_do_global_parameter(lp_ctx
, "kpasswd port", "464");
2583 lpcfg_do_global_parameter(lp_ctx
, "web port", "901");
2585 lpcfg_do_global_parameter(lp_ctx
, "nt status support", "True");
2587 lpcfg_do_global_parameter(lp_ctx
, "max wins ttl", "518400"); /* 6 days */
2588 lpcfg_do_global_parameter(lp_ctx
, "min wins ttl", "21600");
2590 lpcfg_do_global_parameter(lp_ctx
, "tls enabled", "True");
2591 lpcfg_do_global_parameter(lp_ctx
, "tls keyfile", "tls/key.pem");
2592 lpcfg_do_global_parameter(lp_ctx
, "tls certfile", "tls/cert.pem");
2593 lpcfg_do_global_parameter(lp_ctx
, "tls cafile", "tls/ca.pem");
2594 lpcfg_do_global_parameter(lp_ctx
, "tls priority", "NORMAL:-VERS-SSL3.0");
2595 lpcfg_do_global_parameter(lp_ctx
, "prefork children:smb", "4");
2597 lpcfg_do_global_parameter(lp_ctx
, "rndc command", "/usr/sbin/rndc");
2598 lpcfg_do_global_parameter(lp_ctx
, "nsupdate command", "/usr/bin/nsupdate -g");
2600 lpcfg_do_global_parameter(lp_ctx
, "allow dns updates", "secure only");
2601 lpcfg_do_global_parameter(lp_ctx
, "dns forwarder", "");
2603 lpcfg_do_global_parameter(lp_ctx
, "algorithmic rid base", "1000");
2605 lpcfg_do_global_parameter(lp_ctx
, "enhanced browsing", "True");
2607 lpcfg_do_global_parameter(lp_ctx
, "winbind nss info", "template");
2609 lpcfg_do_global_parameter(lp_ctx
, "server schannel", "Auto");
2611 lpcfg_do_global_parameter(lp_ctx
, "short preserve case", "True");
2613 lpcfg_do_global_parameter(lp_ctx
, "max open files", "16384");
2615 lpcfg_do_global_parameter(lp_ctx
, "cups connection timeout", "30");
2617 lpcfg_do_global_parameter(lp_ctx
, "locking", "True");
2619 lpcfg_do_global_parameter(lp_ctx
, "block size", "1024");
2621 lpcfg_do_global_parameter(lp_ctx
, "client use spnego", "True");
2623 lpcfg_do_global_parameter(lp_ctx
, "change notify", "True");
2625 lpcfg_do_global_parameter(lp_ctx
, "name cache timeout", "660");
2627 lpcfg_do_global_parameter(lp_ctx
, "defer sharing violations", "True");
2629 lpcfg_do_global_parameter(lp_ctx
, "ldap replication sleep", "1000");
2631 lpcfg_do_global_parameter(lp_ctx
, "idmap backend", "tdb");
2633 lpcfg_do_global_parameter(lp_ctx
, "enable privileges", "True");
2635 lpcfg_do_global_parameter_var(lp_ctx
, "smb2 max write", "%u", DEFAULT_SMB2_MAX_WRITE
);
2637 lpcfg_do_global_parameter(lp_ctx
, "passdb backend", "tdbsam");
2639 lpcfg_do_global_parameter(lp_ctx
, "getwd cache", "True");
2641 lpcfg_do_global_parameter(lp_ctx
, "winbind nested groups", "True");
2643 lpcfg_do_global_parameter(lp_ctx
, "mangled names", "True");
2645 lpcfg_do_global_parameter_var(lp_ctx
, "smb2 max credits", "%u", DEFAULT_SMB2_MAX_CREDITS
);
2647 lpcfg_do_global_parameter(lp_ctx
, "ldap ssl", "start tls");
2649 lpcfg_do_global_parameter(lp_ctx
, "ldap deref", "auto");
2651 lpcfg_do_global_parameter(lp_ctx
, "lm interval", "60");
2653 lpcfg_do_global_parameter(lp_ctx
, "mangling method", "hash2");
2655 lpcfg_do_global_parameter(lp_ctx
, "hide dot files", "True");
2657 lpcfg_do_global_parameter(lp_ctx
, "browse list", "True");
2659 lpcfg_do_global_parameter(lp_ctx
, "passwd chat timeout", "2");
2661 lpcfg_do_global_parameter(lp_ctx
, "guest account", GUEST_ACCOUNT
);
2663 lpcfg_do_global_parameter(lp_ctx
, "client schannel", "auto");
2665 lpcfg_do_global_parameter(lp_ctx
, "smb encrypt", "default");
2667 lpcfg_do_global_parameter(lp_ctx
, "max log size", "5000");
2669 lpcfg_do_global_parameter(lp_ctx
, "idmap negative cache time", "120");
2671 lpcfg_do_global_parameter(lp_ctx
, "ldap follow referral", "auto");
2673 lpcfg_do_global_parameter(lp_ctx
, "multicast dns register", "yes");
2675 lpcfg_do_global_parameter(lp_ctx
, "winbind reconnect delay", "30");
2677 lpcfg_do_global_parameter(lp_ctx
, "winbind request timeout", "60");
2679 lpcfg_do_global_parameter(lp_ctx
, "nt acl support", "yes");
2681 lpcfg_do_global_parameter(lp_ctx
, "acl check permissions", "yes");
2683 lpcfg_do_global_parameter(lp_ctx
, "keepalive", "300");
2685 lpcfg_do_global_parameter(lp_ctx
, "smbd profiling level", "off");
2687 lpcfg_do_global_parameter(lp_ctx
, "winbind cache time", "300");
2689 lpcfg_do_global_parameter(lp_ctx
, "level2 oplocks", "yes");
2691 lpcfg_do_global_parameter(lp_ctx
, "show add printer wizard", "yes");
2693 lpcfg_do_global_parameter(lp_ctx
, "allocation roundup size", "1048576");
2695 lpcfg_do_global_parameter(lp_ctx
, "ldap page size", "1024");
2697 lpcfg_do_global_parameter(lp_ctx
, "kernel share modes", "yes");
2699 lpcfg_do_global_parameter(lp_ctx
, "strict locking", "Auto");
2701 lpcfg_do_global_parameter(lp_ctx
, "map readonly", "yes");
2703 lpcfg_do_global_parameter(lp_ctx
, "allow trusted domains", "yes");
2705 lpcfg_do_global_parameter(lp_ctx
, "default devmode", "yes");
2707 lpcfg_do_global_parameter(lp_ctx
, "os level", "20");
2709 lpcfg_do_global_parameter(lp_ctx
, "dos filetimes", "yes");
2711 lpcfg_do_global_parameter(lp_ctx
, "mangling char", "~");
2713 lpcfg_do_global_parameter(lp_ctx
, "printcap cache time", "750");
2715 lpcfg_do_global_parameter(lp_ctx
, "create krb5 conf", "yes");
2717 lpcfg_do_global_parameter(lp_ctx
, "winbind max clients", "200");
2719 lpcfg_do_global_parameter(lp_ctx
, "acl map full control", "yes");
2721 lpcfg_do_global_parameter(lp_ctx
, "nt pipe support", "yes");
2723 lpcfg_do_global_parameter(lp_ctx
, "ldap debug threshold", "10");
2725 lpcfg_do_global_parameter(lp_ctx
, "client ldap sasl wrapping", "sign");
2727 lpcfg_do_global_parameter(lp_ctx
, "follow symlinks", "yes");
2729 lpcfg_do_global_parameter(lp_ctx
, "machine password timeout", "604800");
2731 lpcfg_do_global_parameter(lp_ctx
, "ldap connection timeout", "2");
2733 lpcfg_do_global_parameter(lp_ctx
, "winbind expand groups", "0");
2735 lpcfg_do_global_parameter(lp_ctx
, "stat cache", "yes");
2737 lpcfg_do_global_parameter(lp_ctx
, "lpq cache time", "30");
2739 lpcfg_do_global_parameter_var(lp_ctx
, "smb2 max trans", "%u", DEFAULT_SMB2_MAX_TRANSACT
);
2741 lpcfg_do_global_parameter_var(lp_ctx
, "smb2 max read", "%u", DEFAULT_SMB2_MAX_READ
);
2743 lpcfg_do_global_parameter(lp_ctx
, "durable handles", "yes");
2745 lpcfg_do_global_parameter(lp_ctx
, "max stat cache size", "256");
2747 lpcfg_do_global_parameter(lp_ctx
, "ldap passwd sync", "no");
2749 lpcfg_do_global_parameter(lp_ctx
, "kernel change notify", "yes");
2751 lpcfg_do_global_parameter(lp_ctx
, "max ttl", "259200");
2753 lpcfg_do_global_parameter(lp_ctx
, "blocking locks", "yes");
2755 lpcfg_do_global_parameter(lp_ctx
, "oplock contention limit", "2");
2757 lpcfg_do_global_parameter(lp_ctx
, "load printers", "yes");
2759 lpcfg_do_global_parameter(lp_ctx
, "idmap cache time", "604800");
2761 lpcfg_do_global_parameter(lp_ctx
, "preserve case", "yes");
2763 lpcfg_do_global_parameter(lp_ctx
, "lm announce", "auto");
2765 lpcfg_do_global_parameter(lp_ctx
, "afs token lifetime", "604800");
2767 lpcfg_do_global_parameter(lp_ctx
, "enable core files", "yes");
2769 lpcfg_do_global_parameter(lp_ctx
, "winbind max domain connections", "1");
2771 lpcfg_do_global_parameter(lp_ctx
, "case sensitive", "auto");
2773 lpcfg_do_global_parameter(lp_ctx
, "ldap timeout", "15");
2775 lpcfg_do_global_parameter(lp_ctx
, "mangle prefix", "1");
2777 lpcfg_do_global_parameter(lp_ctx
, "posix locking", "yes");
2779 lpcfg_do_global_parameter(lp_ctx
, "lock spin time", "200");
2781 lpcfg_do_global_parameter(lp_ctx
, "directory name cache size", "100");
2783 lpcfg_do_global_parameter(lp_ctx
, "nmbd bind explicit broadcast", "yes");
2785 lpcfg_do_global_parameter(lp_ctx
, "init logon delay", "100");
2787 lpcfg_do_global_parameter(lp_ctx
, "usershare owner only", "yes");
2789 lpcfg_do_global_parameter(lp_ctx
, "-valid", "yes");
2791 lpcfg_do_global_parameter_var(lp_ctx
, "usershare path", "%s/usershares", get_dyn_STATEDIR());
2794 lpcfg_do_global_parameter_var(lp_ctx
, "panic action", "/bin/sleep 999999999");
2797 lpcfg_do_global_parameter(lp_ctx
, "smb passwd file", get_dyn_SMB_PASSWD_FILE());
2799 lpcfg_do_global_parameter(lp_ctx
, "logon home", "\\\\%N\\%U");
2801 lpcfg_do_global_parameter(lp_ctx
, "logon path", "\\\\%N\\%U\\profile");
2803 lpcfg_do_global_parameter(lp_ctx
, "printjob username", "%U");
2805 /* Allow modules to adjust defaults */
2806 for (defaults_hook
= defaults_hooks
; defaults_hook
;
2807 defaults_hook
= defaults_hook
->next
) {
2810 ret
= defaults_hook
->hook(lp_ctx
);
2812 DEBUG(1, ("Defaults hook %s failed to run.",
2813 defaults_hook
->name
));
2814 talloc_free(lp_ctx
);
2819 for (i
= 0; parm_table
[i
].label
; i
++) {
2820 if (!(lp_ctx
->flags
[i
] & FLAG_CMDLINE
)) {
2821 lp_ctx
->flags
[i
] |= FLAG_DEFAULT
;
2825 for (parm
=lp_ctx
->globals
->param_opt
; parm
; parm
=parm
->next
) {
2826 if (!(parm
->priority
& FLAG_CMDLINE
)) {
2827 parm
->priority
|= FLAG_DEFAULT
;
2831 for (parm
=lp_ctx
->sDefault
->param_opt
; parm
; parm
=parm
->next
) {
2832 if (!(parm
->priority
& FLAG_CMDLINE
)) {
2833 parm
->priority
|= FLAG_DEFAULT
;
2841 * Initialise the global parameter structure.
2843 struct loadparm_context
*loadparm_init_global(bool load_default
)
2845 if (global_loadparm_context
== NULL
) {
2846 global_loadparm_context
= loadparm_init(NULL
);
2848 if (global_loadparm_context
== NULL
) {
2851 global_loadparm_context
->global
= true;
2852 if (load_default
&& !global_loadparm_context
->loaded
) {
2853 lpcfg_load_default(global_loadparm_context
);
2855 global_loadparm_context
->refuse_free
= true;
2856 return global_loadparm_context
;
2860 * Initialise the global parameter structure.
2862 struct loadparm_context
*loadparm_init_s3(TALLOC_CTX
*mem_ctx
,
2863 const struct loadparm_s3_helpers
*s3_fns
)
2865 struct loadparm_context
*loadparm_context
= talloc_zero(mem_ctx
, struct loadparm_context
);
2866 if (!loadparm_context
) {
2869 loadparm_context
->s3_fns
= s3_fns
;
2870 loadparm_context
->globals
= s3_fns
->globals
;
2871 loadparm_context
->flags
= s3_fns
->flags
;
2873 return loadparm_context
;
2876 const char *lpcfg_configfile(struct loadparm_context
*lp_ctx
)
2878 return lp_ctx
->szConfigFile
;
2881 const char *lp_default_path(void)
2883 if (getenv("SMB_CONF_PATH"))
2884 return getenv("SMB_CONF_PATH");
2886 return dyn_CONFIGFILE
;
2890 * Update the internal state of a loadparm context after settings
2893 static bool lpcfg_update(struct loadparm_context
*lp_ctx
)
2895 struct debug_settings settings
;
2896 TALLOC_CTX
*tmp_ctx
;
2898 tmp_ctx
= talloc_new(lp_ctx
);
2899 if (tmp_ctx
== NULL
) {
2903 lpcfg_add_auto_services(lp_ctx
, lpcfg_auto_services(lp_ctx
, tmp_ctx
));
2905 if (!lp_ctx
->globals
->wins_server_list
&& lp_ctx
->globals
->we_are_a_wins_server
) {
2906 lpcfg_do_global_parameter(lp_ctx
, "wins server", "127.0.0.1");
2909 if (!lp_ctx
->global
) {
2910 TALLOC_FREE(tmp_ctx
);
2914 panic_action
= lp_ctx
->globals
->panic_action
;
2916 reload_charcnv(lp_ctx
);
2918 ZERO_STRUCT(settings
);
2919 /* Add any more debug-related smb.conf parameters created in
2921 settings
.timestamp_logs
= lp_ctx
->globals
->timestamp_logs
;
2922 settings
.debug_prefix_timestamp
= lp_ctx
->globals
->debug_prefix_timestamp
;
2923 settings
.debug_hires_timestamp
= lp_ctx
->globals
->debug_hires_timestamp
;
2924 settings
.debug_pid
= lp_ctx
->globals
->debug_pid
;
2925 settings
.debug_uid
= lp_ctx
->globals
->debug_uid
;
2926 settings
.debug_class
= lp_ctx
->globals
->debug_class
;
2927 debug_set_settings(&settings
, lp_ctx
->globals
->logging
,
2928 lp_ctx
->globals
->syslog
,
2929 lp_ctx
->globals
->syslog_only
);
2931 /* FIXME: This is a bit of a hack, but we can't use a global, since
2932 * not everything that uses lp also uses the socket library */
2933 if (lpcfg_parm_bool(lp_ctx
, NULL
, "socket", "testnonblock", false)) {
2934 setenv("SOCKET_TESTNONBLOCK", "1", 1);
2936 unsetenv("SOCKET_TESTNONBLOCK");
2939 TALLOC_FREE(tmp_ctx
);
2943 bool lpcfg_load_default(struct loadparm_context
*lp_ctx
)
2947 path
= lp_default_path();
2949 if (!file_exist(path
)) {
2950 /* We allow the default smb.conf file to not exist,
2951 * basically the equivalent of an empty file. */
2952 return lpcfg_update(lp_ctx
);
2955 return lpcfg_load(lp_ctx
, path
);
2959 * Load the services array from the services file.
2961 * Return True on success, False on failure.
2963 bool lpcfg_load(struct loadparm_context
*lp_ctx
, const char *filename
)
2968 filename
= talloc_strdup(lp_ctx
, filename
);
2970 lp_ctx
->szConfigFile
= filename
;
2972 if (lp_ctx
->s3_fns
) {
2973 return lp_ctx
->s3_fns
->load(filename
);
2976 lp_ctx
->bInGlobalSection
= true;
2977 n2
= standard_sub_basic(lp_ctx
, lp_ctx
->szConfigFile
);
2978 DEBUG(2, ("lpcfg_load: refreshing parameters from %s\n", n2
));
2980 add_to_file_list(lp_ctx
, &lp_ctx
->file_lists
, lp_ctx
->szConfigFile
, n2
);
2982 /* We get sections first, so have to start 'behind' to make up */
2983 lp_ctx
->currentService
= NULL
;
2984 bRetval
= pm_process(n2
, do_section
, lpcfg_do_parameter
, lp_ctx
);
2986 /* finish up the last section */
2987 DEBUG(4, ("pm_process() returned %s\n", BOOLSTR(bRetval
)));
2989 if (lp_ctx
->currentService
!= NULL
)
2990 bRetval
= lpcfg_service_ok(lp_ctx
->currentService
);
2992 bRetval
= bRetval
&& lpcfg_update(lp_ctx
);
2994 /* we do this unconditionally, so that it happens even
2995 for a missing smb.conf */
2996 reload_charcnv(lp_ctx
);
2998 if (bRetval
== true) {
2999 /* set this up so that any child python tasks will
3000 find the right smb.conf */
3001 setenv("SMB_CONF_PATH", filename
, 1);
3003 /* set the context used by the lp_*() function
3005 global_loadparm_context
= lp_ctx
;
3006 lp_ctx
->loaded
= true;
3013 * Return the max number of services.
3016 int lpcfg_numservices(struct loadparm_context
*lp_ctx
)
3018 if (lp_ctx
->s3_fns
) {
3019 return lp_ctx
->s3_fns
->get_numservices();
3022 return lp_ctx
->iNumServices
;
3026 * Display the contents of the services array in human-readable form.
3029 void lpcfg_dump(struct loadparm_context
*lp_ctx
, FILE *f
, bool show_defaults
,
3034 if (lp_ctx
->s3_fns
) {
3035 lp_ctx
->s3_fns
->dump(f
, show_defaults
, maxtoprint
);
3039 lpcfg_dump_globals(lp_ctx
, f
, show_defaults
);
3041 lpcfg_dump_a_service(lp_ctx
->sDefault
, lp_ctx
->sDefault
, f
, lp_ctx
->flags
, show_defaults
);
3043 for (iService
= 0; iService
< maxtoprint
; iService
++)
3044 lpcfg_dump_one(f
, show_defaults
, lp_ctx
->services
[iService
], lp_ctx
->sDefault
);
3048 * Display the contents of one service in human-readable form.
3050 void lpcfg_dump_one(FILE *f
, bool show_defaults
, struct loadparm_service
*service
, struct loadparm_service
*sDefault
)
3052 if (service
!= NULL
) {
3053 if (service
->szService
[0] == '\0')
3055 lpcfg_dump_a_service(service
, sDefault
, f
, NULL
, show_defaults
);
3059 struct loadparm_service
*lpcfg_servicebynum(struct loadparm_context
*lp_ctx
,
3062 if (lp_ctx
->s3_fns
) {
3063 return lp_ctx
->s3_fns
->get_servicebynum(snum
);
3066 return lp_ctx
->services
[snum
];
3069 struct loadparm_service
*lpcfg_service(struct loadparm_context
*lp_ctx
,
3070 const char *service_name
)
3075 if (lp_ctx
->s3_fns
) {
3076 return lp_ctx
->s3_fns
->get_service(service_name
);
3079 for (iService
= lp_ctx
->iNumServices
- 1; iService
>= 0; iService
--) {
3080 if (lp_ctx
->services
[iService
] &&
3081 lp_ctx
->services
[iService
]->szService
) {
3083 * The substitution here is used to support %U is
3086 serviceName
= standard_sub_basic(
3087 lp_ctx
->services
[iService
],
3088 lp_ctx
->services
[iService
]->szService
);
3089 if (strequal(serviceName
, service_name
)) {
3090 talloc_free(serviceName
);
3091 return lp_ctx
->services
[iService
];
3093 talloc_free(serviceName
);
3097 DEBUG(7,("lpcfg_servicenumber: couldn't find %s\n", service_name
));
3101 const char *lpcfg_servicename(const struct loadparm_service
*service
)
3103 return lpcfg_string((const char *)service
->szService
);
3107 * A useful volume label function.
3109 const char *lpcfg_volume_label(struct loadparm_service
*service
, struct loadparm_service
*sDefault
)
3112 ret
= lpcfg_string((const char *)((service
!= NULL
&& service
->volume
!= NULL
) ?
3113 service
->volume
: sDefault
->volume
));
3115 return lpcfg_servicename(service
);
3120 * Return the correct printer name.
3122 const char *lpcfg_printername(struct loadparm_service
*service
, struct loadparm_service
*sDefault
)
3125 ret
= lpcfg_string((const char *)((service
!= NULL
&& service
->_printername
!= NULL
) ?
3126 service
->_printername
: sDefault
->_printername
));
3127 if (ret
== NULL
|| (ret
!= NULL
&& *ret
== '\0'))
3128 ret
= lpcfg_servicename(service
);
3135 * Return the max print jobs per queue.
3137 int lpcfg_maxprintjobs(struct loadparm_service
*service
, struct loadparm_service
*sDefault
)
3139 int maxjobs
= lpcfg_max_print_jobs(service
, sDefault
);
3141 if (maxjobs
<= 0 || maxjobs
>= PRINT_MAX_JOBID
)
3142 maxjobs
= PRINT_MAX_JOBID
- 1;
3147 struct smb_iconv_handle
*lpcfg_iconv_handle(struct loadparm_context
*lp_ctx
)
3149 if (lp_ctx
== NULL
) {
3150 return get_iconv_handle();
3152 return lp_ctx
->iconv_handle
;
3155 _PUBLIC_
void reload_charcnv(struct loadparm_context
*lp_ctx
)
3157 struct smb_iconv_handle
*old_ic
= lp_ctx
->iconv_handle
;
3158 if (!lp_ctx
->global
) {
3162 if (old_ic
== NULL
) {
3163 old_ic
= global_iconv_handle
;
3165 lp_ctx
->iconv_handle
= smb_iconv_handle_reinit_lp(lp_ctx
, lp_ctx
, old_ic
);
3166 global_iconv_handle
= lp_ctx
->iconv_handle
;
3169 _PUBLIC_
char *lpcfg_tls_keyfile(TALLOC_CTX
*mem_ctx
, struct loadparm_context
*lp_ctx
)
3171 return lpcfg_private_path(mem_ctx
, lp_ctx
, lpcfg__tls_keyfile(lp_ctx
));
3174 _PUBLIC_
char *lpcfg_tls_certfile(TALLOC_CTX
*mem_ctx
, struct loadparm_context
*lp_ctx
)
3176 return lpcfg_private_path(mem_ctx
, lp_ctx
, lpcfg__tls_certfile(lp_ctx
));
3179 _PUBLIC_
char *lpcfg_tls_cafile(TALLOC_CTX
*mem_ctx
, struct loadparm_context
*lp_ctx
)
3181 return lpcfg_private_path(mem_ctx
, lp_ctx
, lpcfg__tls_cafile(lp_ctx
));
3184 _PUBLIC_
char *lpcfg_tls_crlfile(TALLOC_CTX
*mem_ctx
, struct loadparm_context
*lp_ctx
)
3186 return lpcfg_private_path(mem_ctx
, lp_ctx
, lpcfg__tls_crlfile(lp_ctx
));
3189 _PUBLIC_
char *lpcfg_tls_dhpfile(TALLOC_CTX
*mem_ctx
, struct loadparm_context
*lp_ctx
)
3191 return lpcfg_private_path(mem_ctx
, lp_ctx
, lpcfg__tls_dhpfile(lp_ctx
));
3194 struct gensec_settings
*lpcfg_gensec_settings(TALLOC_CTX
*mem_ctx
, struct loadparm_context
*lp_ctx
)
3196 struct gensec_settings
*settings
= talloc_zero(mem_ctx
, struct gensec_settings
);
3197 if (settings
== NULL
)
3199 SMB_ASSERT(lp_ctx
!= NULL
);
3200 settings
->lp_ctx
= talloc_reference(settings
, lp_ctx
);
3201 settings
->target_hostname
= lpcfg_parm_string(lp_ctx
, NULL
, "gensec", "target_hostname");
3205 int lpcfg_server_role(struct loadparm_context
*lp_ctx
)
3207 int domain_master
= lpcfg__domain_master(lp_ctx
);
3209 return lp_find_server_role(lpcfg__server_role(lp_ctx
),
3210 lpcfg__security(lp_ctx
),
3211 lpcfg__domain_logons(lp_ctx
),
3212 (domain_master
== true) ||
3213 (domain_master
== Auto
));
3216 int lpcfg_security(struct loadparm_context
*lp_ctx
)
3218 return lp_find_security(lpcfg__server_role(lp_ctx
),
3219 lpcfg__security(lp_ctx
));
3222 int lpcfg_client_max_protocol(struct loadparm_context
*lp_ctx
)
3224 int client_max_protocol
= lpcfg__client_max_protocol(lp_ctx
);
3225 if (client_max_protocol
== PROTOCOL_DEFAULT
) {
3226 return PROTOCOL_NT1
;
3228 return client_max_protocol
;
3231 bool lpcfg_server_signing_allowed(struct loadparm_context
*lp_ctx
, bool *mandatory
)
3233 bool allowed
= true;
3234 enum smb_signing_setting signing_setting
= lpcfg_server_signing(lp_ctx
);
3238 if (signing_setting
== SMB_SIGNING_DEFAULT
) {
3240 * If we are a domain controller, SMB signing is
3241 * really important, as it can prevent a number of
3242 * attacks on communications between us and the
3245 * However, it really sucks (no sendfile, CPU
3246 * overhead) performance-wise when used on a
3247 * file server, so disable it by default
3251 if (lpcfg_server_role(lp_ctx
) >= ROLE_ACTIVE_DIRECTORY_DC
) {
3252 signing_setting
= SMB_SIGNING_REQUIRED
;
3254 signing_setting
= SMB_SIGNING_OFF
;
3258 switch (signing_setting
) {
3259 case SMB_SIGNING_REQUIRED
:
3262 case SMB_SIGNING_DESIRED
:
3263 case SMB_SIGNING_IF_REQUIRED
:
3265 case SMB_SIGNING_DEFAULT
:
3266 case SMB_SIGNING_OFF
:
3274 int lpcfg_tdb_hash_size(struct loadparm_context
*lp_ctx
, const char *name
)
3282 base
= strrchr_m(name
, '/');
3288 return lpcfg_parm_int(lp_ctx
, NULL
, "tdb_hashsize", base
, 0);
3292 int lpcfg_tdb_flags(struct loadparm_context
*lp_ctx
, int tdb_flags
)
3294 if (!lpcfg_use_mmap(lp_ctx
)) {
3295 tdb_flags
|= TDB_NOMMAP
;