2 Unix SMB/CIFS implementation.
3 Parameter loading functions
4 Copyright (C) Karl Auer 1993-1998
6 Largely re-written by Andrew Tridgell, September 1994
8 Copyright (C) Simo Sorce 2001
9 Copyright (C) Alexander Bokovoy 2002
10 Copyright (C) Stefan (metze) Metzmacher 2002
11 Copyright (C) Jim McDonough (jmcd@us.ibm.com) 2003.
12 Copyright (C) James Myers 2003 <myersjj@samba.org>
13 Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2007
14 Copyright (C) Andrew Bartlett 2011-2012
16 This program is free software; you can redistribute it and/or modify
17 it under the terms of the GNU General Public License as published by
18 the Free Software Foundation; either version 3 of the License, or
19 (at your option) any later version.
21 This program is distributed in the hope that it will be useful,
22 but WITHOUT ANY WARRANTY; without even the implied warranty of
23 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 GNU General Public License for more details.
26 You should have received a copy of the GNU General Public License
27 along with this program. If not, see <http://www.gnu.org/licenses/>.
33 * This module provides suitable callback functions for the params
34 * module. It builds the internal table of service details which is
35 * then used by the rest of the server.
39 * 1) add it to the global or service structure definition
40 * 2) add it to the parm_table
41 * 3) add it to the list of available functions (eg: using FN_GLOBAL_STRING())
42 * 4) If it's a global then initialise it in init_globals. If a local
43 * (ie. service) parameter then initialise it in the sDefault structure
47 * The configuration file is processed sequentially for speed. It is NOT
48 * accessed randomly as happens in 'real' Windows. For this reason, there
49 * is a fair bit of sequence-dependent code here - ie., code which assumes
50 * that certain things happen before others. In particular, the code which
51 * happens at the boundary between sections is delicately poised, so be
58 #include "dynconfig/dynconfig.h"
59 #include "system/time.h"
60 #include "system/locale.h"
61 #include "system/network.h" /* needed for TCP_NODELAY */
62 #include "../lib/util/dlinklist.h"
63 #include "lib/param/param.h"
64 #include "lib/param/loadparm.h"
65 #include "auth/gensec/gensec.h"
66 #include "lib/param/s3_param.h"
67 #include "lib/util/bitmap.h"
68 #include "libcli/smb/smb_constants.h"
70 #define standard_sub_basic talloc_strdup
72 static bool do_parameter(const char *, const char *, void *);
73 static bool defaults_saved
= false;
75 #define LOADPARM_EXTRA_GLOBALS \
76 struct parmlist_entry *param_opt; \
79 int iminreceivefile; \
80 char *szPrintcapname; \
82 int iPreferredMaster; \
83 char *szLdapMachineSuffix; \
84 char *szLdapUserSuffix; \
85 char *szLdapIdmapSuffix; \
86 char *szLdapGroupSuffix; \
87 char *szUsershareTemplateShare; \
90 int winbindMaxDomainConnections; \
91 int ismb2_max_credits; \
100 #include "lib/param/param_global.h"
102 #define NUMPARAMETERS (sizeof(parm_table) / sizeof(struct parm_struct))
104 /* we don't need a special handler for "dos charset" and "unix charset" */
105 #define handle_dos_charset NULL
106 #define handle_charset NULL
108 /* these are parameter handlers which are not needed in the
111 #define handle_netbios_aliases NULL
112 #define handle_printing NULL
113 #define handle_ldap_debug_level NULL
114 #define handle_idmap_backend NULL
115 #define handle_idmap_uid NULL
116 #define handle_idmap_gid NULL
122 /* prototypes for the special type handlers */
123 static bool handle_include(struct loadparm_context
*lp_ctx
, int unused
,
124 const char *pszParmValue
, char **ptr
);
125 static bool handle_realm(struct loadparm_context
*lp_ctx
, int unused
,
126 const char *pszParmValue
, char **ptr
);
127 static bool handle_copy(struct loadparm_context
*lp_ctx
, int unused
,
128 const char *pszParmValue
, char **ptr
);
129 static bool handle_debug_list(struct loadparm_context
*lp_ctx
, int unused
,
130 const char *pszParmValue
, char **ptr
);
131 static bool handle_logfile(struct loadparm_context
*lp_ctx
, int unused
,
132 const char *pszParmValue
, char **ptr
);
134 #include "lib/param/param_table.c"
136 /* local variables */
137 struct loadparm_context
{
138 const char *szConfigFile
;
139 struct loadparm_global
*globals
;
140 struct loadparm_service
**services
;
141 struct loadparm_service
*sDefault
;
142 struct smb_iconv_handle
*iconv_handle
;
144 struct loadparm_service
*currentService
;
145 bool bInGlobalSection
;
147 struct file_lists
*next
;
152 unsigned int flags
[NUMPARAMETERS
];
155 bool global
; /* Is this the global context, which may set
156 * global variables such as debug level etc? */
157 const struct loadparm_s3_helpers
*s3_fns
;
161 struct loadparm_service
*lpcfg_default_service(struct loadparm_context
*lp_ctx
)
163 if (lp_ctx
->s3_fns
) {
164 return lp_ctx
->s3_fns
->get_default_loadparm_service();
166 return lp_ctx
->sDefault
;
170 * Convenience routine to grab string parameters into temporary memory
171 * and run standard_sub_basic on them.
173 * The buffers can be written to by
174 * callers without affecting the source string.
177 static const char *lp_string(const char *s
)
179 #if 0 /* until REWRITE done to make thread-safe */
180 size_t len
= s
? strlen(s
) : 0;
184 /* The follow debug is useful for tracking down memory problems
185 especially if you have an inner loop that is calling a lp_*()
186 function that returns a string. Perhaps this debug should be
187 present all the time? */
190 DEBUG(10, ("lp_string(%s)\n", s
));
193 #if 0 /* until REWRITE done to make thread-safe */
195 lp_talloc
= talloc_init("lp_talloc");
197 ret
= talloc_array(lp_talloc
, char, len
+ 100); /* leave room for substitution */
205 strlcpy(ret
, s
, len
);
207 if (trim_string(ret
, "\"", "\"")) {
208 if (strchr(ret
,'"') != NULL
)
209 strlcpy(ret
, s
, len
);
212 standard_sub_basic(ret
,len
+100);
219 In this section all the functions that are used to access the
220 parameters from the rest of the program are defined
224 * the creation of separate lpcfg_*() and lp_*() functions is to allow
225 * for code compatibility between existing Samba4 and Samba3 code.
228 /* this global context supports the lp_*() function varients */
229 static struct loadparm_context
*global_loadparm_context
;
231 #define lpcfg_default_service global_loadparm_context->sDefault
232 #define lpcfg_global_service(i) global_loadparm_context->services[i]
234 #define FN_GLOBAL_STRING(fn_name,var_name) \
235 _PUBLIC_ const char *lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) { \
236 if (lp_ctx == NULL) return NULL; \
237 if (lp_ctx->s3_fns) { \
238 SMB_ASSERT(lp_ctx->s3_fns->fn_name); \
239 return lp_ctx->s3_fns->fn_name(); \
241 return lp_ctx->globals->var_name ? lp_string(lp_ctx->globals->var_name) : ""; \
244 #define FN_GLOBAL_CONST_STRING(fn_name,var_name) \
245 _PUBLIC_ const char *lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) {\
246 if (lp_ctx == NULL) return NULL; \
247 if (lp_ctx->s3_fns) { \
248 SMB_ASSERT(lp_ctx->s3_fns->fn_name); \
249 return lp_ctx->s3_fns->fn_name(); \
251 return lp_ctx->globals->var_name ? lp_string(lp_ctx->globals->var_name) : ""; \
254 #define FN_GLOBAL_LIST(fn_name,var_name) \
255 _PUBLIC_ const char **lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) { \
256 if (lp_ctx == NULL) return NULL; \
257 if (lp_ctx->s3_fns) { \
258 SMB_ASSERT(lp_ctx->s3_fns->fn_name); \
259 return lp_ctx->s3_fns->fn_name(); \
261 return lp_ctx->globals->var_name; \
264 #define FN_GLOBAL_BOOL(fn_name,var_name) \
265 _PUBLIC_ bool lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) {\
266 if (lp_ctx == NULL) return false; \
267 if (lp_ctx->s3_fns) { \
268 SMB_ASSERT(lp_ctx->s3_fns->fn_name); \
269 return lp_ctx->s3_fns->fn_name(); \
271 return lp_ctx->globals->var_name; \
274 #define FN_GLOBAL_INTEGER(fn_name,var_name) \
275 _PUBLIC_ int lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) { \
276 if (lp_ctx->s3_fns) { \
277 SMB_ASSERT(lp_ctx->s3_fns->fn_name); \
278 return lp_ctx->s3_fns->fn_name(); \
280 return lp_ctx->globals->var_name; \
283 /* Local parameters don't need the ->s3_fns because the struct
284 * loadparm_service is shared and lpcfg_service() checks the ->s3_fns
286 #define FN_LOCAL_STRING(fn_name,val) \
287 _PUBLIC_ const char *lpcfg_ ## fn_name(struct loadparm_service *service, \
288 struct loadparm_service *sDefault) { \
289 return(lp_string((const char *)((service != NULL && service->val != NULL) ? service->val : sDefault->val))); \
292 #define FN_LOCAL_CONST_STRING(fn_name,val) FN_LOCAL_STRING(fn_name, val)
294 #define FN_LOCAL_LIST(fn_name,val) \
295 _PUBLIC_ const char **lpcfg_ ## fn_name(struct loadparm_service *service, \
296 struct loadparm_service *sDefault) {\
297 return(const char **)(service != NULL && service->val != NULL? service->val : sDefault->val); \
300 #define FN_LOCAL_PARM_BOOL(fn_name, val) FN_LOCAL_BOOL(fn_name, val)
302 #define FN_LOCAL_BOOL(fn_name,val) \
303 _PUBLIC_ bool lpcfg_ ## fn_name(struct loadparm_service *service, \
304 struct loadparm_service *sDefault) { \
305 return((service != NULL)? service->val : sDefault->val); \
308 #define FN_LOCAL_INTEGER(fn_name,val) \
309 _PUBLIC_ int lpcfg_ ## fn_name(struct loadparm_service *service, \
310 struct loadparm_service *sDefault) { \
311 return((service != NULL)? service->val : sDefault->val); \
314 #define FN_LOCAL_PARM_INTEGER(fn_name, val) FN_LOCAL_INTEGER(fn_name, val)
316 #define FN_LOCAL_PARM_CHAR(fn_name, val) FN_LOCAL_CHAR(fn_name, val)
318 #define FN_LOCAL_CHAR(fn_name,val) \
319 _PUBLIC_ char lpcfg_ ## fn_name(struct loadparm_service *service, \
320 struct loadparm_service *sDefault) { \
321 return((service != NULL)? service->val : sDefault->val); \
324 #include "lib/param/param_functions.c"
326 /* These functions remain only in lib/param for now */
327 FN_GLOBAL_BOOL(readraw
, bReadRaw
)
328 FN_GLOBAL_BOOL(writeraw
, bWriteRaw
)
329 FN_GLOBAL_CONST_STRING(cachedir
, szCacheDir
)
330 FN_GLOBAL_CONST_STRING(statedir
, szStateDir
)
332 /* local prototypes */
333 static int map_parameter(const char *pszParmName
);
334 static struct loadparm_service
*getservicebyname(struct loadparm_context
*lp_ctx
,
335 const char *pszServiceName
);
336 static void copy_service(struct loadparm_service
*pserviceDest
,
337 struct loadparm_service
*pserviceSource
,
338 struct bitmap
*pcopymapDest
);
339 static bool lpcfg_service_ok(struct loadparm_service
*service
);
340 static bool do_section(const char *pszSectionName
, void *);
341 static void init_copymap(struct loadparm_service
*pservice
);
343 /* This is a helper function for parametrical options support. */
344 /* It returns a pointer to parametrical option value if it exists or NULL otherwise */
345 /* Actual parametrical functions are quite simple */
346 const char *lpcfg_get_parametric(struct loadparm_context
*lp_ctx
,
347 struct loadparm_service
*service
,
348 const char *type
, const char *option
)
350 char *vfskey_tmp
= NULL
;
352 struct parmlist_entry
*data
;
357 if (lp_ctx
->s3_fns
) {
358 return lp_ctx
->s3_fns
->get_parametric(service
, type
, option
);
361 data
= (service
== NULL
? lp_ctx
->globals
->param_opt
: service
->param_opt
);
363 vfskey_tmp
= talloc_asprintf(NULL
, "%s:%s", type
, option
);
364 if (vfskey_tmp
== NULL
) return NULL
;
365 vfskey
= strlower_talloc(NULL
, vfskey_tmp
);
366 talloc_free(vfskey_tmp
);
369 if (strcmp(data
->key
, vfskey
) == 0) {
376 if (service
!= NULL
) {
377 /* Try to fetch the same option but from globals */
378 /* but only if we are not already working with globals */
379 for (data
= lp_ctx
->globals
->param_opt
; data
;
381 if (strcmp(data
->key
, vfskey
) == 0) {
395 * convenience routine to return int parameters.
397 static int lp_int(const char *s
)
401 DEBUG(0,("lp_int(%s): is called with NULL!\n",s
));
405 return strtol(s
, NULL
, 0);
409 * convenience routine to return unsigned long parameters.
411 static unsigned long lp_ulong(const char *s
)
415 DEBUG(0,("lp_ulong(%s): is called with NULL!\n",s
));
419 return strtoul(s
, NULL
, 0);
423 * convenience routine to return unsigned long parameters.
425 static long lp_long(const char *s
)
429 DEBUG(0,("lp_long(%s): is called with NULL!\n",s
));
433 return strtol(s
, NULL
, 0);
437 * convenience routine to return unsigned long parameters.
439 static double lp_double(const char *s
)
443 DEBUG(0,("lp_double(%s): is called with NULL!\n",s
));
447 return strtod(s
, NULL
);
451 * convenience routine to return boolean parameters.
453 static bool lp_bool(const char *s
)
458 DEBUG(0,("lp_bool(%s): is called with NULL!\n",s
));
462 if (!set_boolean(s
, &ret
)) {
463 DEBUG(0,("lp_bool(%s): value is not boolean!\n",s
));
472 * Return parametric option from a given service. Type is a part of option before ':'
473 * Parametric option has following syntax: 'Type: option = value'
474 * Returned value is allocated in 'lp_talloc' context
477 const char *lpcfg_parm_string(struct loadparm_context
*lp_ctx
,
478 struct loadparm_service
*service
, const char *type
,
481 const char *value
= lpcfg_get_parametric(lp_ctx
, service
, type
, option
);
484 return lp_string(value
);
490 * Return parametric option from a given service. Type is a part of option before ':'
491 * Parametric option has following syntax: 'Type: option = value'
492 * Returned value is allocated in 'lp_talloc' context
495 const char **lpcfg_parm_string_list(TALLOC_CTX
*mem_ctx
,
496 struct loadparm_context
*lp_ctx
,
497 struct loadparm_service
*service
,
499 const char *option
, const char *separator
)
501 const char *value
= lpcfg_get_parametric(lp_ctx
, service
, type
, option
);
504 return (const char **)str_list_make(mem_ctx
, value
, separator
);
510 * Return parametric option from a given service. Type is a part of option before ':'
511 * Parametric option has following syntax: 'Type: option = value'
514 int lpcfg_parm_int(struct loadparm_context
*lp_ctx
,
515 struct loadparm_service
*service
, const char *type
,
516 const char *option
, int default_v
)
518 const char *value
= lpcfg_get_parametric(lp_ctx
, service
, type
, option
);
521 return lp_int(value
);
527 * Return parametric option from a given service. Type is a part of
529 * Parametric option has following syntax: 'Type: option = value'.
532 int lpcfg_parm_bytes(struct loadparm_context
*lp_ctx
,
533 struct loadparm_service
*service
, const char *type
,
534 const char *option
, int default_v
)
538 const char *value
= lpcfg_get_parametric(lp_ctx
, service
, type
, option
);
540 if (value
&& conv_str_size_error(value
, &bval
)) {
541 if (bval
<= INT_MAX
) {
550 * Return parametric option from a given service.
551 * Type is a part of option before ':'
552 * Parametric option has following syntax: 'Type: option = value'
554 unsigned long lpcfg_parm_ulong(struct loadparm_context
*lp_ctx
,
555 struct loadparm_service
*service
, const char *type
,
556 const char *option
, unsigned long default_v
)
558 const char *value
= lpcfg_get_parametric(lp_ctx
, service
, type
, option
);
561 return lp_ulong(value
);
566 long lpcfg_parm_long(struct loadparm_context
*lp_ctx
,
567 struct loadparm_service
*service
, const char *type
,
568 const char *option
, long default_v
)
570 const char *value
= lpcfg_get_parametric(lp_ctx
, service
, type
, option
);
573 return lp_long(value
);
578 double lpcfg_parm_double(struct loadparm_context
*lp_ctx
,
579 struct loadparm_service
*service
, const char *type
,
580 const char *option
, double default_v
)
582 const char *value
= lpcfg_get_parametric(lp_ctx
, service
, type
, option
);
585 return lp_double(value
);
591 * Return parametric option from a given service. Type is a part of option before ':'
592 * Parametric option has following syntax: 'Type: option = value'
595 bool lpcfg_parm_bool(struct loadparm_context
*lp_ctx
,
596 struct loadparm_service
*service
, const char *type
,
597 const char *option
, bool default_v
)
599 const char *value
= lpcfg_get_parametric(lp_ctx
, service
, type
, option
);
602 return lp_bool(value
);
609 * Initialise a service to the defaults.
612 static struct loadparm_service
*init_service(TALLOC_CTX
*mem_ctx
, struct loadparm_service
*sDefault
)
614 struct loadparm_service
*pservice
=
615 talloc_zero(mem_ctx
, struct loadparm_service
);
616 copy_service(pservice
, sDefault
, NULL
);
621 * Set a string value, deallocating any existing space, and allocing the space
624 static bool lpcfg_string_set(TALLOC_CTX
*mem_ctx
, char **dest
, const char *src
)
631 *dest
= talloc_strdup(mem_ctx
, src
);
632 if ((*dest
) == NULL
) {
633 DEBUG(0,("Out of memory in string_set\n"));
641 * Set a string value, deallocating any existing space, and allocing the space
644 static bool lpcfg_string_set_upper(TALLOC_CTX
*mem_ctx
, char **dest
, const char *src
)
651 *dest
= strupper_talloc(mem_ctx
, src
);
652 if ((*dest
) == NULL
) {
653 DEBUG(0,("Out of memory in string_set_upper\n"));
663 * Add a new service to the services array initialising it with the given
667 struct loadparm_service
*lpcfg_add_service(struct loadparm_context
*lp_ctx
,
668 const struct loadparm_service
*pservice
,
672 struct loadparm_service tservice
;
673 int num_to_alloc
= lp_ctx
->iNumServices
+ 1;
674 struct parmlist_entry
*data
, *pdata
;
676 if (pservice
== NULL
) {
677 pservice
= lp_ctx
->sDefault
;
680 tservice
= *pservice
;
682 /* it might already exist */
684 struct loadparm_service
*service
= getservicebyname(lp_ctx
,
686 if (service
!= NULL
) {
687 /* Clean all parametric options for service */
688 /* They will be added during parsing again */
689 data
= service
->param_opt
;
695 service
->param_opt
= NULL
;
700 /* find an invalid one */
701 for (i
= 0; i
< lp_ctx
->iNumServices
; i
++)
702 if (lp_ctx
->services
[i
] == NULL
)
705 /* if not, then create one */
706 if (i
== lp_ctx
->iNumServices
) {
707 struct loadparm_service
**tsp
;
709 tsp
= talloc_realloc(lp_ctx
, lp_ctx
->services
, struct loadparm_service
*, num_to_alloc
);
712 DEBUG(0,("lpcfg_add_service: failed to enlarge services!\n"));
715 lp_ctx
->services
= tsp
;
716 lp_ctx
->services
[lp_ctx
->iNumServices
] = NULL
;
719 lp_ctx
->iNumServices
++;
722 lp_ctx
->services
[i
] = init_service(lp_ctx
->services
, lp_ctx
->sDefault
);
723 if (lp_ctx
->services
[i
] == NULL
) {
724 DEBUG(0,("lpcfg_add_service: out of memory!\n"));
727 copy_service(lp_ctx
->services
[i
], &tservice
, NULL
);
729 lpcfg_string_set(lp_ctx
->services
[i
], &lp_ctx
->services
[i
]->szService
, name
);
730 return lp_ctx
->services
[i
];
734 * Add a new home service, with the specified home directory, defaults coming
735 * from service ifrom.
738 bool lpcfg_add_home(struct loadparm_context
*lp_ctx
,
739 const char *pszHomename
,
740 struct loadparm_service
*default_service
,
741 const char *user
, const char *pszHomedir
)
743 struct loadparm_service
*service
;
745 service
= lpcfg_add_service(lp_ctx
, default_service
, pszHomename
);
750 if (!(*(default_service
->szPath
))
751 || strequal(default_service
->szPath
, lp_ctx
->sDefault
->szPath
)) {
752 service
->szPath
= talloc_strdup(service
, pszHomedir
);
754 service
->szPath
= string_sub_talloc(service
, lpcfg_pathname(default_service
, lp_ctx
->sDefault
), "%H", pszHomedir
);
757 if (!(*(service
->comment
))) {
758 service
->comment
= talloc_asprintf(service
, "Home directory of %s", user
);
760 service
->bAvailable
= default_service
->bAvailable
;
761 service
->bBrowseable
= default_service
->bBrowseable
;
763 DEBUG(3, ("adding home's share [%s] for user '%s' at '%s'\n",
764 pszHomename
, user
, service
->szPath
));
770 * Add a new printer service, with defaults coming from service iFrom.
773 bool lpcfg_add_printer(struct loadparm_context
*lp_ctx
,
774 const char *pszPrintername
,
775 struct loadparm_service
*default_service
)
777 const char *comment
= "From Printcap";
778 struct loadparm_service
*service
;
779 service
= lpcfg_add_service(lp_ctx
, default_service
, pszPrintername
);
784 /* note that we do NOT default the availability flag to True - */
785 /* we take it from the default service passed. This allows all */
786 /* dynamic printers to be disabled by disabling the [printers] */
787 /* entry (if/when the 'available' keyword is implemented!). */
789 /* the printer name is set to the service name. */
790 lpcfg_string_set(service
, &service
->szPrintername
, pszPrintername
);
791 lpcfg_string_set(service
, &service
->comment
, comment
);
792 service
->bBrowseable
= default_service
->bBrowseable
;
793 /* Printers cannot be read_only. */
794 service
->bRead_only
= false;
795 /* Printer services must be printable. */
796 service
->bPrint_ok
= true;
798 DEBUG(3, ("adding printer service %s\n", pszPrintername
));
804 * Map a parameter's string representation to something we can use.
805 * Returns False if the parameter string is not recognised, else TRUE.
808 static int map_parameter(const char *pszParmName
)
812 if (*pszParmName
== '-')
815 for (iIndex
= 0; parm_table
[iIndex
].label
; iIndex
++)
816 if (strwicmp(parm_table
[iIndex
].label
, pszParmName
) == 0)
819 /* Warn only if it isn't parametric option */
820 if (strchr(pszParmName
, ':') == NULL
)
821 DEBUG(0, ("Unknown parameter encountered: \"%s\"\n", pszParmName
));
822 /* We do return 'fail' for parametric options as well because they are
823 stored in different storage
830 return the parameter structure for a parameter
832 struct parm_struct
*lpcfg_parm_struct(struct loadparm_context
*lp_ctx
, const char *name
)
836 if (lp_ctx
->s3_fns
) {
837 return lp_ctx
->s3_fns
->get_parm_struct(name
);
840 parmnum
= map_parameter(name
);
841 if (parmnum
== -1) return NULL
;
842 return &parm_table
[parmnum
];
846 return the parameter pointer for a parameter
848 void *lpcfg_parm_ptr(struct loadparm_context
*lp_ctx
,
849 struct loadparm_service
*service
, struct parm_struct
*parm
)
851 if (lp_ctx
->s3_fns
) {
852 return lp_ctx
->s3_fns
->get_parm_ptr(service
, parm
);
855 if (service
== NULL
) {
856 if (parm
->p_class
== P_LOCAL
)
857 return ((char *)lp_ctx
->sDefault
)+parm
->offset
;
858 else if (parm
->p_class
== P_GLOBAL
)
859 return ((char *)lp_ctx
->globals
)+parm
->offset
;
862 return ((char *)service
) + parm
->offset
;
867 return the parameter pointer for a parameter
869 bool lpcfg_parm_is_cmdline(struct loadparm_context
*lp_ctx
, const char *name
)
873 if (lp_ctx
->s3_fns
) {
874 struct parm_struct
*parm
= lp_ctx
->s3_fns
->get_parm_struct(name
);
876 return parm
->flags
& FLAG_CMDLINE
;
881 parmnum
= map_parameter(name
);
882 if (parmnum
== -1) return false;
884 return lp_ctx
->flags
[parmnum
] & FLAG_CMDLINE
;
888 * Find a service by name. Otherwise works like get_service.
891 static struct loadparm_service
*getservicebyname(struct loadparm_context
*lp_ctx
,
892 const char *pszServiceName
)
896 if (lp_ctx
->s3_fns
) {
897 return lp_ctx
->s3_fns
->get_service(pszServiceName
);
900 for (iService
= lp_ctx
->iNumServices
- 1; iService
>= 0; iService
--)
901 if (lp_ctx
->services
[iService
] != NULL
&&
902 strwicmp(lp_ctx
->services
[iService
]->szService
, pszServiceName
) == 0) {
903 return lp_ctx
->services
[iService
];
910 * Copy a service structure to another.
911 * If pcopymapDest is NULL then copy all fields
914 static void copy_service(struct loadparm_service
*pserviceDest
,
915 struct loadparm_service
*pserviceSource
,
916 struct bitmap
*pcopymapDest
)
919 bool bcopyall
= (pcopymapDest
== NULL
);
920 struct parmlist_entry
*data
, *pdata
, *paramo
;
923 for (i
= 0; parm_table
[i
].label
; i
++)
924 if (parm_table
[i
].p_class
== P_LOCAL
&&
925 (bcopyall
|| bitmap_query(pcopymapDest
, i
))) {
927 ((char *)pserviceSource
) + parm_table
[i
].offset
;
929 ((char *)pserviceDest
) + parm_table
[i
].offset
;
931 switch (parm_table
[i
].type
) {
933 *(bool *)dest_ptr
= *(bool *)src_ptr
;
940 *(int *)dest_ptr
= *(int *)src_ptr
;
944 lpcfg_string_set(pserviceDest
,
950 lpcfg_string_set_upper(pserviceDest
,
955 *(const char ***)dest_ptr
= (const char **)str_list_copy(pserviceDest
,
956 *(const char ***)src_ptr
);
964 init_copymap(pserviceDest
);
965 if (pserviceSource
->copymap
)
966 bitmap_copy(pserviceDest
->copymap
,
967 pserviceSource
->copymap
);
970 data
= pserviceSource
->param_opt
;
973 pdata
= pserviceDest
->param_opt
;
974 /* Traverse destination */
976 /* If we already have same option, override it */
977 if (strcmp(pdata
->key
, data
->key
) == 0) {
978 talloc_free(pdata
->value
);
979 pdata
->value
= talloc_strdup(pdata
,
987 paramo
= talloc_zero(pserviceDest
, struct parmlist_entry
);
990 paramo
->key
= talloc_strdup(paramo
, data
->key
);
991 paramo
->value
= talloc_strdup(paramo
, data
->value
);
992 DLIST_ADD(pserviceDest
->param_opt
, paramo
);
999 * Check a service for consistency. Return False if the service is in any way
1000 * incomplete or faulty, else True.
1002 static bool lpcfg_service_ok(struct loadparm_service
*service
)
1007 if (service
->szService
[0] == '\0') {
1008 DEBUG(0, ("The following message indicates an internal error:\n"));
1009 DEBUG(0, ("No service name in service entry.\n"));
1013 /* The [printers] entry MUST be printable. I'm all for flexibility, but */
1014 /* I can't see why you'd want a non-printable printer service... */
1015 if (strwicmp(service
->szService
, PRINTERS_NAME
) == 0) {
1016 if (!service
->bPrint_ok
) {
1017 DEBUG(0, ("WARNING: [%s] service MUST be printable!\n",
1018 service
->szService
));
1019 service
->bPrint_ok
= true;
1021 /* [printers] service must also be non-browsable. */
1022 if (service
->bBrowseable
)
1023 service
->bBrowseable
= false;
1026 /* If a service is flagged unavailable, log the fact at level 0. */
1027 if (!service
->bAvailable
)
1028 DEBUG(1, ("NOTE: Service %s is flagged unavailable.\n",
1029 service
->szService
));
1035 /*******************************************************************
1036 Keep a linked list of all config files so we know when one has changed
1037 it's date and needs to be reloaded.
1038 ********************************************************************/
1040 static void add_to_file_list(struct loadparm_context
*lp_ctx
,
1041 const char *fname
, const char *subfname
)
1043 struct file_lists
*f
= lp_ctx
->file_lists
;
1046 if (f
->name
&& !strcmp(f
->name
, fname
))
1052 f
= talloc(lp_ctx
, struct file_lists
);
1055 f
->next
= lp_ctx
->file_lists
;
1056 f
->name
= talloc_strdup(f
, fname
);
1061 f
->subfname
= talloc_strdup(f
, subfname
);
1066 lp_ctx
->file_lists
= f
;
1067 f
->modtime
= file_modtime(subfname
);
1069 time_t t
= file_modtime(subfname
);
1075 /*******************************************************************
1076 Check if a config file has changed date.
1077 ********************************************************************/
1078 bool lpcfg_file_list_changed(struct loadparm_context
*lp_ctx
)
1080 struct file_lists
*f
;
1081 DEBUG(6, ("lp_file_list_changed()\n"));
1083 for (f
= lp_ctx
->file_lists
; f
!= NULL
; f
= f
->next
) {
1087 n2
= standard_sub_basic(lp_ctx
, f
->name
);
1089 DEBUGADD(6, ("file %s -> %s last mod_time: %s\n",
1090 f
->name
, n2
, ctime(&f
->modtime
)));
1092 mod_time
= file_modtime(n2
);
1094 if (mod_time
&& ((f
->modtime
!= mod_time
) || (f
->subfname
== NULL
) || (strcmp(n2
, f
->subfname
) != 0))) {
1095 DEBUGADD(6, ("file %s modified: %s\n", n2
,
1097 f
->modtime
= mod_time
;
1098 talloc_free(f
->subfname
);
1099 f
->subfname
= talloc_strdup(f
, n2
);
1106 /***************************************************************************
1107 Handle the "realm" parameter
1108 ***************************************************************************/
1110 static bool handle_realm(struct loadparm_context
*lp_ctx
, int unused
,
1111 const char *pszParmValue
, char **ptr
)
1113 lpcfg_string_set(lp_ctx
, ptr
, pszParmValue
);
1115 talloc_free(lp_ctx
->globals
->szRealm_upper
);
1116 talloc_free(lp_ctx
->globals
->szRealm_lower
);
1118 lp_ctx
->globals
->szRealm_upper
= strupper_talloc(lp_ctx
, pszParmValue
);
1119 lp_ctx
->globals
->szRealm_lower
= strlower_talloc(lp_ctx
, pszParmValue
);
1124 /***************************************************************************
1125 Handle the include operation.
1126 ***************************************************************************/
1128 static bool handle_include(struct loadparm_context
*lp_ctx
, int unused
,
1129 const char *pszParmValue
, char **ptr
)
1131 char *fname
= standard_sub_basic(lp_ctx
, pszParmValue
);
1133 add_to_file_list(lp_ctx
, pszParmValue
, fname
);
1135 lpcfg_string_set(lp_ctx
, ptr
, fname
);
1137 if (file_exist(fname
))
1138 return pm_process(fname
, do_section
, do_parameter
, lp_ctx
);
1140 DEBUG(2, ("Can't find include file %s\n", fname
));
1145 /***************************************************************************
1146 Handle the interpretation of the copy parameter.
1147 ***************************************************************************/
1149 static bool handle_copy(struct loadparm_context
*lp_ctx
, int unused
,
1150 const char *pszParmValue
, char **ptr
)
1153 struct loadparm_service
*serviceTemp
;
1155 lpcfg_string_set(lp_ctx
, ptr
, pszParmValue
);
1159 DEBUG(3, ("Copying service from service %s\n", pszParmValue
));
1161 if ((serviceTemp
= getservicebyname(lp_ctx
, pszParmValue
)) != NULL
) {
1162 if (serviceTemp
== lp_ctx
->currentService
) {
1163 DEBUG(0, ("Can't copy service %s - unable to copy self!\n", pszParmValue
));
1165 copy_service(lp_ctx
->currentService
,
1167 lp_ctx
->currentService
->copymap
);
1171 DEBUG(0, ("Unable to copy service - source not found: %s\n",
1179 static bool handle_debug_list(struct loadparm_context
*lp_ctx
, int unused
,
1180 const char *pszParmValue
, char **ptr
)
1183 lpcfg_string_set(lp_ctx
, ptr
, pszParmValue
);
1184 if (lp_ctx
->global
) {
1185 return debug_parse_levels(pszParmValue
);
1190 static bool handle_logfile(struct loadparm_context
*lp_ctx
, int unused
,
1191 const char *pszParmValue
, char **ptr
)
1193 debug_set_logfile(pszParmValue
);
1194 if (lp_ctx
->global
) {
1195 lpcfg_string_set(lp_ctx
, ptr
, pszParmValue
);
1200 /***************************************************************************
1201 Initialise a copymap.
1202 ***************************************************************************/
1204 static void init_copymap(struct loadparm_service
*pservice
)
1208 TALLOC_FREE(pservice
->copymap
);
1210 pservice
->copymap
= bitmap_talloc(NULL
, NUMPARAMETERS
);
1211 if (!pservice
->copymap
)
1213 ("Couldn't allocate copymap!! (size %d)\n",
1214 (int)NUMPARAMETERS
));
1216 for (i
= 0; i
< NUMPARAMETERS
; i
++)
1217 bitmap_set(pservice
->copymap
, i
);
1221 * Process a parametric option
1223 static bool lp_do_parameter_parametric(struct loadparm_context
*lp_ctx
,
1224 struct loadparm_service
*service
,
1225 const char *pszParmName
,
1226 const char *pszParmValue
, int flags
)
1228 struct parmlist_entry
*paramo
, *data
;
1230 TALLOC_CTX
*mem_ctx
;
1232 while (isspace((unsigned char)*pszParmName
)) {
1236 name
= strlower_talloc(lp_ctx
, pszParmName
);
1237 if (!name
) return false;
1239 if (service
== NULL
) {
1240 data
= lp_ctx
->globals
->param_opt
;
1241 mem_ctx
= lp_ctx
->globals
;
1243 data
= service
->param_opt
;
1247 /* Traverse destination */
1248 for (paramo
=data
; paramo
; paramo
=paramo
->next
) {
1249 /* If we already have the option set, override it unless
1250 it was a command line option and the new one isn't */
1251 if (strcmp(paramo
->key
, name
) == 0) {
1252 if ((paramo
->priority
& FLAG_CMDLINE
) &&
1253 !(flags
& FLAG_CMDLINE
)) {
1258 talloc_free(paramo
->value
);
1259 paramo
->value
= talloc_strdup(paramo
, pszParmValue
);
1260 paramo
->priority
= flags
;
1266 paramo
= talloc_zero(mem_ctx
, struct parmlist_entry
);
1269 paramo
->key
= talloc_strdup(paramo
, name
);
1270 paramo
->value
= talloc_strdup(paramo
, pszParmValue
);
1271 paramo
->priority
= flags
;
1272 if (service
== NULL
) {
1273 DLIST_ADD(lp_ctx
->globals
->param_opt
, paramo
);
1275 DLIST_ADD(service
->param_opt
, paramo
);
1283 static bool set_variable(TALLOC_CTX
*mem_ctx
, int parmnum
, void *parm_ptr
,
1284 const char *pszParmName
, const char *pszParmValue
,
1285 struct loadparm_context
*lp_ctx
, bool on_globals
)
1288 /* if it is a special case then go ahead */
1289 if (parm_table
[parmnum
].special
) {
1291 ret
= parm_table
[parmnum
].special(lp_ctx
, -1, pszParmValue
,
1296 goto mark_non_default
;
1299 /* now switch on the type of variable it is */
1300 switch (parm_table
[parmnum
].type
)
1304 if (!set_boolean(pszParmValue
, &b
)) {
1305 DEBUG(0,("lp_do_parameter(%s): value is not boolean!\n", pszParmValue
));
1308 *(bool *)parm_ptr
= b
;
1314 if (!set_boolean(pszParmValue
, &b
)) {
1315 DEBUG(0,("lp_do_parameter(%s): value is not boolean!\n", pszParmValue
));
1318 *(bool *)parm_ptr
= !b
;
1323 *(int *)parm_ptr
= atoi(pszParmValue
);
1327 *(char *)parm_ptr
= *pszParmValue
;
1331 *(int *)parm_ptr
= strtol(pszParmValue
, NULL
, 8);
1337 if (conv_str_size_error(pszParmValue
, &val
)) {
1338 if (val
<= INT_MAX
) {
1339 *(int *)parm_ptr
= (int)val
;
1344 DEBUG(0,("lp_do_parameter(%s): value is not "
1345 "a valid size specifier!\n", pszParmValue
));
1350 *(const char ***)parm_ptr
= (const char **)str_list_make(mem_ctx
,
1351 pszParmValue
, NULL
);
1355 char **new_list
= str_list_make(mem_ctx
,
1356 pszParmValue
, NULL
);
1357 for (i
=0; new_list
[i
]; i
++) {
1358 if (new_list
[i
][0] == '+' && new_list
[i
][1]) {
1359 if (!str_list_check(*(const char ***)parm_ptr
,
1361 *(const char ***)parm_ptr
= str_list_add(*(const char ***)parm_ptr
,
1364 } else if (new_list
[i
][0] == '-' && new_list
[i
][1]) {
1365 str_list_remove(*(const char ***)parm_ptr
,
1369 DEBUG(0, ("Unsupported list syntax for: %s = %s\n",
1370 pszParmName
, pszParmValue
));
1373 *(const char ***)parm_ptr
= (const char **) new_list
;
1380 lpcfg_string_set(mem_ctx
, (char **)parm_ptr
, pszParmValue
);
1384 lpcfg_string_set_upper(mem_ctx
, (char **)parm_ptr
, pszParmValue
);
1388 for (i
= 0; parm_table
[parmnum
].enum_list
[i
].name
; i
++) {
1391 parm_table
[parmnum
].enum_list
[i
].name
)) {
1393 parm_table
[parmnum
].
1398 if (!parm_table
[parmnum
].enum_list
[i
].name
) {
1399 DEBUG(0,("Unknown enumerated value '%s' for '%s'\n",
1400 pszParmValue
, pszParmName
));
1410 if (on_globals
&& (lp_ctx
->flags
[parmnum
] & FLAG_DEFAULT
)) {
1411 lp_ctx
->flags
[parmnum
] &= ~FLAG_DEFAULT
;
1412 /* we have to also unset FLAG_DEFAULT on aliases */
1413 for (i
=parmnum
-1;i
>=0 && parm_table
[i
].offset
== parm_table
[parmnum
].offset
;i
--) {
1414 lp_ctx
->flags
[i
] &= ~FLAG_DEFAULT
;
1416 for (i
=parmnum
+1;i
<NUMPARAMETERS
&& parm_table
[i
].offset
== parm_table
[parmnum
].offset
;i
++) {
1417 lp_ctx
->flags
[i
] &= ~FLAG_DEFAULT
;
1424 bool lpcfg_do_global_parameter(struct loadparm_context
*lp_ctx
,
1425 const char *pszParmName
, const char *pszParmValue
)
1427 int parmnum
= map_parameter(pszParmName
);
1431 if (strchr(pszParmName
, ':')) {
1432 return lp_do_parameter_parametric(lp_ctx
, NULL
, pszParmName
, pszParmValue
, 0);
1434 DEBUG(0, ("Ignoring unknown parameter \"%s\"\n", pszParmName
));
1438 /* if the flag has been set on the command line, then don't allow override,
1439 but don't report an error */
1440 if (lp_ctx
->flags
[parmnum
] & FLAG_CMDLINE
) {
1444 parm_ptr
= lpcfg_parm_ptr(lp_ctx
, NULL
, &parm_table
[parmnum
]);
1446 return set_variable(lp_ctx
->globals
, parmnum
, parm_ptr
,
1447 pszParmName
, pszParmValue
, lp_ctx
, true);
1450 bool lpcfg_do_service_parameter(struct loadparm_context
*lp_ctx
,
1451 struct loadparm_service
*service
,
1452 const char *pszParmName
, const char *pszParmValue
)
1456 int parmnum
= map_parameter(pszParmName
);
1459 if (strchr(pszParmName
, ':')) {
1460 return lp_do_parameter_parametric(lp_ctx
, service
, pszParmName
, pszParmValue
, 0);
1462 DEBUG(0, ("Ignoring unknown parameter \"%s\"\n", pszParmName
));
1466 /* if the flag has been set on the command line, then don't allow override,
1467 but don't report an error */
1468 if (lp_ctx
->flags
[parmnum
] & FLAG_CMDLINE
) {
1472 if (parm_table
[parmnum
].p_class
== P_GLOBAL
) {
1474 ("Global parameter %s found in service section!\n",
1478 parm_ptr
= ((char *)service
) + parm_table
[parmnum
].offset
;
1480 if (!service
->copymap
)
1481 init_copymap(service
);
1483 /* this handles the aliases - set the copymap for other
1484 * entries with the same data pointer */
1485 for (i
= 0; parm_table
[i
].label
; i
++)
1486 if (parm_table
[i
].offset
== parm_table
[parmnum
].offset
&&
1487 parm_table
[i
].p_class
== parm_table
[parmnum
].p_class
)
1488 bitmap_clear(service
->copymap
, i
);
1490 return set_variable(service
, parmnum
, parm_ptr
, pszParmName
,
1491 pszParmValue
, lp_ctx
, false);
1495 * Process a parameter.
1498 static bool do_parameter(const char *pszParmName
, const char *pszParmValue
,
1501 struct loadparm_context
*lp_ctx
= (struct loadparm_context
*)userdata
;
1503 if (lp_ctx
->bInGlobalSection
)
1504 return lpcfg_do_global_parameter(lp_ctx
, pszParmName
,
1507 return lpcfg_do_service_parameter(lp_ctx
, lp_ctx
->currentService
,
1508 pszParmName
, pszParmValue
);
1512 variable argument do parameter
1514 bool lpcfg_do_global_parameter_var(struct loadparm_context
*lp_ctx
, const char *pszParmName
, const char *fmt
, ...) PRINTF_ATTRIBUTE(3, 4);
1515 bool lpcfg_do_global_parameter_var(struct loadparm_context
*lp_ctx
,
1516 const char *pszParmName
, const char *fmt
, ...)
1523 s
= talloc_vasprintf(NULL
, fmt
, ap
);
1525 ret
= lpcfg_do_global_parameter(lp_ctx
, pszParmName
, s
);
1532 set a parameter from the commandline - this is called from command line parameter
1533 parsing code. It sets the parameter then marks the parameter as unable to be modified
1534 by smb.conf processing
1536 bool lpcfg_set_cmdline(struct loadparm_context
*lp_ctx
, const char *pszParmName
,
1537 const char *pszParmValue
)
1542 if (lp_ctx
->s3_fns
) {
1543 return lp_ctx
->s3_fns
->set_cmdline(pszParmName
, pszParmValue
);
1546 parmnum
= map_parameter(pszParmName
);
1548 while (isspace((unsigned char)*pszParmValue
)) pszParmValue
++;
1551 if (parmnum
< 0 && strchr(pszParmName
, ':')) {
1552 /* set a parametric option */
1553 return lp_do_parameter_parametric(lp_ctx
, NULL
, pszParmName
,
1554 pszParmValue
, FLAG_CMDLINE
);
1558 DEBUG(0,("Unknown option '%s'\n", pszParmName
));
1562 /* reset the CMDLINE flag in case this has been called before */
1563 lp_ctx
->flags
[parmnum
] &= ~FLAG_CMDLINE
;
1565 if (!lpcfg_do_global_parameter(lp_ctx
, pszParmName
, pszParmValue
)) {
1569 lp_ctx
->flags
[parmnum
] |= FLAG_CMDLINE
;
1571 /* we have to also set FLAG_CMDLINE on aliases */
1572 for (i
=parmnum
-1;i
>=0 && parm_table
[i
].offset
== parm_table
[parmnum
].offset
;i
--) {
1573 lp_ctx
->flags
[i
] |= FLAG_CMDLINE
;
1575 for (i
=parmnum
+1;i
<NUMPARAMETERS
&& parm_table
[i
].offset
== parm_table
[parmnum
].offset
;i
++) {
1576 lp_ctx
->flags
[i
] |= FLAG_CMDLINE
;
1583 set a option from the commandline in 'a=b' format. Use to support --option
1585 bool lpcfg_set_option(struct loadparm_context
*lp_ctx
, const char *option
)
1590 s
= talloc_strdup(NULL
, option
);
1603 ret
= lpcfg_set_cmdline(lp_ctx
, s
, p
+1);
1609 #define BOOLSTR(b) ((b) ? "Yes" : "No")
1612 * Print a parameter of the specified type.
1615 static void print_parameter(struct parm_struct
*p
, void *ptr
, FILE * f
)
1617 /* For the seperation of lists values that we print below */
1618 const char *list_sep
= ", ";
1623 for (i
= 0; p
->enum_list
[i
].name
; i
++) {
1624 if (*(int *)ptr
== p
->enum_list
[i
].value
) {
1626 p
->enum_list
[i
].name
);
1633 fprintf(f
, "%s", BOOLSTR(*(bool *)ptr
));
1637 fprintf(f
, "%s", BOOLSTR(!*(bool *)ptr
));
1642 fprintf(f
, "%d", *(int *)ptr
);
1646 fprintf(f
, "%c", *(char *)ptr
);
1650 int val
= *(int *)ptr
;
1654 fprintf(f
, "0%o", val
);
1663 if ((char ***)ptr
&& *(char ***)ptr
) {
1664 char **list
= *(char ***)ptr
;
1665 for (; *list
; list
++) {
1666 /* surround strings with whitespace in double quotes */
1667 if (*(list
+1) == NULL
) {
1668 /* last item, no extra separator */
1671 if ( strchr_m( *list
, ' ' ) ) {
1672 fprintf(f
, "\"%s\"%s", *list
, list_sep
);
1674 fprintf(f
, "%s%s", *list
, list_sep
);
1682 if (*(char **)ptr
) {
1683 fprintf(f
, "%s", *(char **)ptr
);
1692 * Check if two parameters are equal.
1695 static bool equal_parameter(parm_type type
, void *ptr1
, void *ptr2
)
1700 return (*((bool *)ptr1
) == *((bool *)ptr2
));
1706 return (*((int *)ptr1
) == *((int *)ptr2
));
1709 return (*((char *)ptr1
) == *((char *)ptr2
));
1713 return str_list_equal(*(const char ***)ptr1
, *(const char ***)ptr2
);
1718 char *p1
= *(char **)ptr1
, *p2
= *(char **)ptr2
;
1723 return (p1
== p2
|| strequal(p1
, p2
));
1732 * Process a new section (service).
1734 * At this stage all sections are services.
1735 * Later we'll have special sections that permit server parameters to be set.
1736 * Returns True on success, False on failure.
1739 static bool do_section(const char *pszSectionName
, void *userdata
)
1741 struct loadparm_context
*lp_ctx
= (struct loadparm_context
*)userdata
;
1743 bool isglobal
= ((strwicmp(pszSectionName
, GLOBAL_NAME
) == 0) ||
1744 (strwicmp(pszSectionName
, GLOBAL_NAME2
) == 0));
1747 /* if we've just struck a global section, note the fact. */
1748 lp_ctx
->bInGlobalSection
= isglobal
;
1750 /* check for multiple global sections */
1751 if (lp_ctx
->bInGlobalSection
) {
1752 DEBUG(4, ("Processing section \"[%s]\"\n", pszSectionName
));
1756 /* if we have a current service, tidy it up before moving on */
1759 if (lp_ctx
->currentService
!= NULL
)
1760 bRetval
= lpcfg_service_ok(lp_ctx
->currentService
);
1762 /* if all is still well, move to the next record in the services array */
1764 /* We put this here to avoid an odd message order if messages are */
1765 /* issued by the post-processing of a previous section. */
1766 DEBUG(4, ("Processing section \"[%s]\"\n", pszSectionName
));
1768 if ((lp_ctx
->currentService
= lpcfg_add_service(lp_ctx
, lp_ctx
->sDefault
,
1771 DEBUG(0, ("Failed to add a new service\n"));
1781 * Determine if a particular base parameter is currently set to the default value.
1784 static bool is_default(struct loadparm_service
*sDefault
, int i
)
1786 void *def_ptr
= ((char *)sDefault
) + parm_table
[i
].offset
;
1787 if (!defaults_saved
)
1789 switch (parm_table
[i
].type
) {
1792 return str_list_equal((const char **)parm_table
[i
].def
.lvalue
,
1793 (const char **)def_ptr
);
1796 return strequal(parm_table
[i
].def
.svalue
,
1800 return parm_table
[i
].def
.bvalue
==
1807 return parm_table
[i
].def
.ivalue
==
1816 *Display the contents of the global structure.
1819 static void dump_globals(struct loadparm_context
*lp_ctx
, FILE *f
,
1823 struct parmlist_entry
*data
;
1825 fprintf(f
, "# Global parameters\n[global]\n");
1827 for (i
= 0; parm_table
[i
].label
; i
++)
1828 if (parm_table
[i
].p_class
== P_GLOBAL
&&
1829 (i
== 0 || (parm_table
[i
].offset
!= parm_table
[i
- 1].offset
))) {
1830 if (!show_defaults
&& (lp_ctx
->flags
[i
] & FLAG_DEFAULT
))
1832 fprintf(f
, "\t%s = ", parm_table
[i
].label
);
1833 print_parameter(&parm_table
[i
], lpcfg_parm_ptr(lp_ctx
, NULL
, &parm_table
[i
]), f
);
1836 if (lp_ctx
->globals
->param_opt
!= NULL
) {
1837 for (data
= lp_ctx
->globals
->param_opt
; data
;
1838 data
= data
->next
) {
1839 if (!show_defaults
&& (data
->priority
& FLAG_DEFAULT
)) {
1842 fprintf(f
, "\t%s = %s\n", data
->key
, data
->value
);
1849 * Display the contents of a single services record.
1852 static void dump_a_service(struct loadparm_service
* pService
, struct loadparm_service
*sDefault
, FILE * f
,
1853 unsigned int *flags
)
1856 struct parmlist_entry
*data
;
1858 if (pService
!= sDefault
)
1859 fprintf(f
, "\n[%s]\n", pService
->szService
);
1861 for (i
= 0; parm_table
[i
].label
; i
++) {
1862 if (parm_table
[i
].p_class
== P_LOCAL
&&
1863 (*parm_table
[i
].label
!= '-') &&
1864 (i
== 0 || (parm_table
[i
].offset
!= parm_table
[i
- 1].offset
)))
1866 if (pService
== sDefault
) {
1867 if (flags
&& (flags
[i
] & FLAG_DEFAULT
)) {
1870 if (defaults_saved
) {
1871 if (is_default(sDefault
, i
)) {
1876 if (equal_parameter(parm_table
[i
].type
,
1877 ((char *)pService
) +
1878 parm_table
[i
].offset
,
1879 ((char *)sDefault
) +
1880 parm_table
[i
].offset
))
1884 fprintf(f
, "\t%s = ", parm_table
[i
].label
);
1885 print_parameter(&parm_table
[i
],
1886 ((char *)pService
) + parm_table
[i
].offset
, f
);
1890 if (pService
->param_opt
!= NULL
) {
1891 for (data
= pService
->param_opt
; data
; data
= data
->next
) {
1892 fprintf(f
, "\t%s = %s\n", data
->key
, data
->value
);
1897 bool lpcfg_dump_a_parameter(struct loadparm_context
*lp_ctx
,
1898 struct loadparm_service
*service
,
1899 const char *parm_name
, FILE * f
)
1901 struct parm_struct
*parm
;
1904 parm
= lpcfg_parm_struct(lp_ctx
, parm_name
);
1909 ptr
= lpcfg_parm_ptr(lp_ctx
, service
,parm
);
1911 print_parameter(parm
, ptr
, f
);
1917 * Return info about the next parameter in a service.
1918 * snum==-1 gives the globals.
1919 * Return NULL when out of parameters.
1923 struct parm_struct
*lpcfg_next_parameter(struct loadparm_context
*lp_ctx
, int snum
, int *i
,
1927 /* do the globals */
1928 for (; parm_table
[*i
].label
; (*i
)++) {
1929 if ((*parm_table
[*i
].label
== '-'))
1933 && (parm_table
[*i
].offset
==
1934 parm_table
[(*i
) - 1].offset
)
1935 && (parm_table
[*i
].p_class
==
1936 parm_table
[(*i
) - 1].p_class
))
1939 return &parm_table
[(*i
)++];
1942 struct loadparm_service
*pService
= lp_ctx
->services
[snum
];
1944 for (; parm_table
[*i
].label
; (*i
)++) {
1945 if (parm_table
[*i
].p_class
== P_LOCAL
&&
1946 (*parm_table
[*i
].label
!= '-') &&
1948 (parm_table
[*i
].offset
!=
1949 parm_table
[(*i
) - 1].offset
)))
1951 if (allparameters
||
1952 !equal_parameter(parm_table
[*i
].type
,
1953 ((char *)pService
) +
1954 parm_table
[*i
].offset
,
1955 ((char *)lp_ctx
->sDefault
) +
1956 parm_table
[*i
].offset
))
1958 return &parm_table
[(*i
)++];
1969 * Auto-load some home services.
1971 static void lpcfg_add_auto_services(struct loadparm_context
*lp_ctx
,
1979 * Unload unused services.
1982 void lpcfg_killunused(struct loadparm_context
*lp_ctx
,
1983 struct smbsrv_connection
*smb
,
1984 bool (*snumused
) (struct smbsrv_connection
*, int))
1987 for (i
= 0; i
< lp_ctx
->iNumServices
; i
++) {
1988 if (lp_ctx
->services
[i
] == NULL
)
1991 if (!snumused
|| !snumused(smb
, i
)) {
1992 talloc_free(lp_ctx
->services
[i
]);
1993 lp_ctx
->services
[i
] = NULL
;
1999 static int lpcfg_destructor(struct loadparm_context
*lp_ctx
)
2001 struct parmlist_entry
*data
;
2003 if (lp_ctx
->refuse_free
) {
2004 /* someone is trying to free the
2005 global_loadparm_context.
2006 We can't allow that. */
2010 if (lp_ctx
->globals
->param_opt
!= NULL
) {
2011 struct parmlist_entry
*next
;
2012 for (data
= lp_ctx
->globals
->param_opt
; data
; data
=next
) {
2014 if (data
->priority
& FLAG_CMDLINE
) continue;
2015 DLIST_REMOVE(lp_ctx
->globals
->param_opt
, data
);
2024 * Initialise the global parameter structure.
2026 * Note that most callers should use loadparm_init_global() instead
2028 struct loadparm_context
*loadparm_init(TALLOC_CTX
*mem_ctx
)
2032 struct loadparm_context
*lp_ctx
;
2033 struct parmlist_entry
*parm
;
2036 lp_ctx
= talloc_zero(mem_ctx
, struct loadparm_context
);
2040 talloc_set_destructor(lp_ctx
, lpcfg_destructor
);
2041 lp_ctx
->bInGlobalSection
= true;
2042 lp_ctx
->globals
= talloc_zero(lp_ctx
, struct loadparm_global
);
2043 lp_ctx
->sDefault
= talloc_zero(lp_ctx
, struct loadparm_service
);
2045 lp_ctx
->sDefault
->iMaxPrintJobs
= 1000;
2046 lp_ctx
->sDefault
->bAvailable
= true;
2047 lp_ctx
->sDefault
->bBrowseable
= true;
2048 lp_ctx
->sDefault
->bRead_only
= true;
2049 lp_ctx
->sDefault
->bMap_archive
= true;
2050 lp_ctx
->sDefault
->iStrictLocking
= true;
2051 lp_ctx
->sDefault
->bOpLocks
= true;
2052 lp_ctx
->sDefault
->iCreate_mask
= 0744;
2053 lp_ctx
->sDefault
->iCreate_force_mode
= 0000;
2054 lp_ctx
->sDefault
->iDir_mask
= 0755;
2055 lp_ctx
->sDefault
->iDir_force_mode
= 0000;
2057 DEBUG(3, ("Initialising global parameters\n"));
2059 for (i
= 0; parm_table
[i
].label
; i
++) {
2060 if ((parm_table
[i
].type
== P_STRING
||
2061 parm_table
[i
].type
== P_USTRING
) &&
2062 !(lp_ctx
->flags
[i
] & FLAG_CMDLINE
)) {
2064 if (parm_table
[i
].p_class
== P_LOCAL
) {
2065 r
= (char **)(((char *)lp_ctx
->sDefault
) + parm_table
[i
].offset
);
2067 r
= (char **)(((char *)lp_ctx
->globals
) + parm_table
[i
].offset
);
2069 *r
= talloc_strdup(lp_ctx
, "");
2073 logfile
= talloc_asprintf(lp_ctx
, "%s/log.samba", dyn_LOGFILEBASE
);
2074 lpcfg_do_global_parameter(lp_ctx
, "log file", logfile
);
2075 talloc_free(logfile
);
2077 lpcfg_do_global_parameter(lp_ctx
, "log level", "0");
2079 lpcfg_do_global_parameter(lp_ctx
, "share backend", "classic");
2081 lpcfg_do_global_parameter(lp_ctx
, "server role", "auto");
2082 lpcfg_do_global_parameter(lp_ctx
, "domain logons", "No");
2083 lpcfg_do_global_parameter(lp_ctx
, "domain master", "Auto");
2085 /* options that can be set on the command line must be initialised via
2086 the slower lpcfg_do_global_parameter() to ensure that FLAG_CMDLINE is obeyed */
2088 lpcfg_do_global_parameter(lp_ctx
, "socket options", "TCP_NODELAY");
2090 lpcfg_do_global_parameter(lp_ctx
, "workgroup", DEFAULT_WORKGROUP
);
2091 myname
= get_myname(lp_ctx
);
2092 lpcfg_do_global_parameter(lp_ctx
, "netbios name", myname
);
2093 talloc_free(myname
);
2094 lpcfg_do_global_parameter(lp_ctx
, "name resolve order", "wins host bcast");
2096 lpcfg_do_global_parameter(lp_ctx
, "fstype", "NTFS");
2098 lpcfg_do_global_parameter(lp_ctx
, "ntvfs handler", "unixuid default");
2099 lpcfg_do_global_parameter(lp_ctx
, "max connections", "-1");
2101 lpcfg_do_global_parameter(lp_ctx
, "dcerpc endpoint servers", "epmapper wkssvc rpcecho samr netlogon lsarpc spoolss drsuapi dssetup unixinfo browser eventlog6 backupkey dnsserver");
2102 lpcfg_do_global_parameter(lp_ctx
, "server services", "s3fs rpc nbt wrepl ldap cldap kdc drepl winbind ntp_signd kcc dnsupdate");
2103 /* the winbind method for domain controllers is for both RODC
2104 auth forwarding and for trusted domains */
2105 lpcfg_do_global_parameter(lp_ctx
, "private dir", dyn_PRIVATE_DIR
);
2106 lpcfg_do_global_parameter(lp_ctx
, "registry:HKEY_LOCAL_MACHINE", "hklm.ldb");
2108 /* This hive should be dynamically generated by Samba using
2109 data from the sam, but for the moment leave it in a tdb to
2110 keep regedt32 from popping up an annoying dialog. */
2111 lpcfg_do_global_parameter(lp_ctx
, "registry:HKEY_USERS", "hku.ldb");
2113 /* using UTF8 by default allows us to support all chars */
2114 lpcfg_do_global_parameter(lp_ctx
, "unix charset", "UTF8");
2116 /* Use codepage 850 as a default for the dos character set */
2117 lpcfg_do_global_parameter(lp_ctx
, "dos charset", "CP850");
2120 * Allow the default PASSWD_CHAT to be overridden in local.h.
2122 lpcfg_do_global_parameter(lp_ctx
, "passwd chat", DEFAULT_PASSWD_CHAT
);
2124 lpcfg_do_global_parameter(lp_ctx
, "pid directory", dyn_PIDDIR
);
2125 lpcfg_do_global_parameter(lp_ctx
, "lock dir", dyn_LOCKDIR
);
2126 lpcfg_do_global_parameter(lp_ctx
, "state directory", dyn_STATEDIR
);
2127 lpcfg_do_global_parameter(lp_ctx
, "cache directory", dyn_CACHEDIR
);
2128 lpcfg_do_global_parameter(lp_ctx
, "ncalrpc dir", dyn_NCALRPCDIR
);
2130 lpcfg_do_global_parameter(lp_ctx
, "nbt client socket address", "");
2131 lpcfg_do_global_parameter_var(lp_ctx
, "server string",
2132 "Samba %s", SAMBA_VERSION_STRING
);
2134 lpcfg_do_global_parameter(lp_ctx
, "password server", "*");
2136 lpcfg_do_global_parameter(lp_ctx
, "max mux", "50");
2137 lpcfg_do_global_parameter(lp_ctx
, "max xmit", "12288");
2138 lpcfg_do_global_parameter(lp_ctx
, "host msdfs", "true");
2140 lpcfg_do_global_parameter(lp_ctx
, "password level", "0");
2141 lpcfg_do_global_parameter(lp_ctx
, "LargeReadwrite", "True");
2142 lpcfg_do_global_parameter(lp_ctx
, "server min protocol", "CORE");
2143 lpcfg_do_global_parameter(lp_ctx
, "server max protocol", "NT1");
2144 lpcfg_do_global_parameter(lp_ctx
, "client min protocol", "CORE");
2145 lpcfg_do_global_parameter(lp_ctx
, "client max protocol", "NT1");
2146 lpcfg_do_global_parameter(lp_ctx
, "security", "AUTO");
2147 lpcfg_do_global_parameter(lp_ctx
, "EncryptPasswords", "True");
2148 lpcfg_do_global_parameter(lp_ctx
, "ReadRaw", "True");
2149 lpcfg_do_global_parameter(lp_ctx
, "WriteRaw", "True");
2150 lpcfg_do_global_parameter(lp_ctx
, "NullPasswords", "False");
2151 lpcfg_do_global_parameter(lp_ctx
, "ObeyPamRestrictions", "False");
2153 lpcfg_do_global_parameter(lp_ctx
, "TimeServer", "False");
2154 lpcfg_do_global_parameter(lp_ctx
, "BindInterfacesOnly", "False");
2155 lpcfg_do_global_parameter(lp_ctx
, "Unicode", "True");
2156 lpcfg_do_global_parameter(lp_ctx
, "ClientLanManAuth", "False");
2157 lpcfg_do_global_parameter(lp_ctx
, "ClientNTLMv2Auth", "True");
2158 lpcfg_do_global_parameter(lp_ctx
, "LanmanAuth", "False");
2159 lpcfg_do_global_parameter(lp_ctx
, "NTLMAuth", "True");
2160 lpcfg_do_global_parameter(lp_ctx
, "client use spnego principal", "False");
2162 lpcfg_do_global_parameter(lp_ctx
, "UnixExtensions", "False");
2164 lpcfg_do_global_parameter(lp_ctx
, "PreferredMaster", "Auto");
2165 lpcfg_do_global_parameter(lp_ctx
, "LocalMaster", "True");
2167 lpcfg_do_global_parameter(lp_ctx
, "wins support", "False");
2168 lpcfg_do_global_parameter(lp_ctx
, "dns proxy", "True");
2170 lpcfg_do_global_parameter(lp_ctx
, "winbind separator", "\\");
2171 lpcfg_do_global_parameter(lp_ctx
, "winbind sealed pipes", "True");
2172 lpcfg_do_global_parameter(lp_ctx
, "winbindd socket directory", dyn_WINBINDD_SOCKET_DIR
);
2173 #if _SAMBA_BUILD_ >= 4
2174 lpcfg_do_global_parameter(lp_ctx
, "winbindd privileged socket directory", dyn_WINBINDD_PRIVILEGED_SOCKET_DIR
);
2175 lpcfg_do_global_parameter(lp_ctx
, "ntp signd socket directory", dyn_NTP_SIGND_SOCKET_DIR
);
2176 lpcfg_do_global_parameter_var(lp_ctx
, "dns update command", "%s/samba_dnsupdate", dyn_SCRIPTSBINDIR
);
2177 lpcfg_do_global_parameter_var(lp_ctx
, "spn update command", "%s/samba_spnupdate", dyn_SCRIPTSBINDIR
);
2178 lpcfg_do_global_parameter_var(lp_ctx
, "samba kcc command",
2179 "%s/samba_kcc", dyn_SCRIPTSBINDIR
);
2181 lpcfg_do_global_parameter(lp_ctx
, "template shell", "/bin/false");
2182 lpcfg_do_global_parameter(lp_ctx
, "template homedir", "/home/%WORKGROUP%/%ACCOUNTNAME%");
2184 lpcfg_do_global_parameter(lp_ctx
, "client signing", "default");
2185 lpcfg_do_global_parameter(lp_ctx
, "server signing", "default");
2187 lpcfg_do_global_parameter(lp_ctx
, "use spnego", "True");
2189 lpcfg_do_global_parameter(lp_ctx
, "use mmap", "True");
2191 lpcfg_do_global_parameter(lp_ctx
, "smb ports", "445 139");
2192 lpcfg_do_global_parameter(lp_ctx
, "nbt port", "137");
2193 lpcfg_do_global_parameter(lp_ctx
, "dgram port", "138");
2194 lpcfg_do_global_parameter(lp_ctx
, "cldap port", "389");
2195 lpcfg_do_global_parameter(lp_ctx
, "krb5 port", "88");
2196 lpcfg_do_global_parameter(lp_ctx
, "kpasswd port", "464");
2197 lpcfg_do_global_parameter(lp_ctx
, "web port", "901");
2199 lpcfg_do_global_parameter(lp_ctx
, "nt status support", "True");
2201 lpcfg_do_global_parameter(lp_ctx
, "max wins ttl", "518400"); /* 6 days */
2202 lpcfg_do_global_parameter(lp_ctx
, "min wins ttl", "10");
2204 lpcfg_do_global_parameter(lp_ctx
, "tls enabled", "True");
2205 lpcfg_do_global_parameter(lp_ctx
, "tls keyfile", "tls/key.pem");
2206 lpcfg_do_global_parameter(lp_ctx
, "tls certfile", "tls/cert.pem");
2207 lpcfg_do_global_parameter(lp_ctx
, "tls cafile", "tls/ca.pem");
2208 lpcfg_do_global_parameter(lp_ctx
, "prefork children:smb", "4");
2210 lpcfg_do_global_parameter(lp_ctx
, "rndc command", "/usr/sbin/rndc");
2211 lpcfg_do_global_parameter(lp_ctx
, "nsupdate command", "/usr/bin/nsupdate -g");
2213 lpcfg_do_global_parameter(lp_ctx
, "allow dns updates", "False");
2214 lpcfg_do_global_parameter(lp_ctx
, "dns recursive queries", "False");
2215 lpcfg_do_global_parameter(lp_ctx
, "dns forwarder", "");
2217 for (i
= 0; parm_table
[i
].label
; i
++) {
2218 if (!(lp_ctx
->flags
[i
] & FLAG_CMDLINE
)) {
2219 lp_ctx
->flags
[i
] |= FLAG_DEFAULT
;
2223 for (parm
=lp_ctx
->globals
->param_opt
; parm
; parm
=parm
->next
) {
2224 if (!(parm
->priority
& FLAG_CMDLINE
)) {
2225 parm
->priority
|= FLAG_DEFAULT
;
2233 * Initialise the global parameter structure.
2235 struct loadparm_context
*loadparm_init_global(bool load_default
)
2237 if (global_loadparm_context
== NULL
) {
2238 global_loadparm_context
= loadparm_init(NULL
);
2240 if (global_loadparm_context
== NULL
) {
2243 global_loadparm_context
->global
= true;
2244 if (load_default
&& !global_loadparm_context
->loaded
) {
2245 lpcfg_load_default(global_loadparm_context
);
2247 global_loadparm_context
->refuse_free
= true;
2248 return global_loadparm_context
;
2252 * Initialise the global parameter structure.
2254 struct loadparm_context
*loadparm_init_s3(TALLOC_CTX
*mem_ctx
,
2255 const struct loadparm_s3_helpers
*s3_fns
)
2257 struct loadparm_context
*loadparm_context
= talloc_zero(mem_ctx
, struct loadparm_context
);
2258 if (!loadparm_context
) {
2261 loadparm_context
->s3_fns
= s3_fns
;
2262 return loadparm_context
;
2265 const char *lpcfg_configfile(struct loadparm_context
*lp_ctx
)
2267 return lp_ctx
->szConfigFile
;
2270 const char *lp_default_path(void)
2272 if (getenv("SMB_CONF_PATH"))
2273 return getenv("SMB_CONF_PATH");
2275 return dyn_CONFIGFILE
;
2279 * Update the internal state of a loadparm context after settings
2282 static bool lpcfg_update(struct loadparm_context
*lp_ctx
)
2284 struct debug_settings settings
;
2285 lpcfg_add_auto_services(lp_ctx
, lpcfg_auto_services(lp_ctx
));
2287 if (!lp_ctx
->globals
->szWINSservers
&& lp_ctx
->globals
->bWINSsupport
) {
2288 lpcfg_do_global_parameter(lp_ctx
, "wins server", "127.0.0.1");
2291 if (!lp_ctx
->global
) {
2295 panic_action
= lp_ctx
->globals
->panic_action
;
2297 reload_charcnv(lp_ctx
);
2299 ZERO_STRUCT(settings
);
2300 /* Add any more debug-related smb.conf parameters created in
2302 settings
.timestamp_logs
= true;
2303 debug_set_settings(&settings
);
2305 /* FIXME: This is a bit of a hack, but we can't use a global, since
2306 * not everything that uses lp also uses the socket library */
2307 if (lpcfg_parm_bool(lp_ctx
, NULL
, "socket", "testnonblock", false)) {
2308 setenv("SOCKET_TESTNONBLOCK", "1", 1);
2310 unsetenv("SOCKET_TESTNONBLOCK");
2316 bool lpcfg_load_default(struct loadparm_context
*lp_ctx
)
2320 path
= lp_default_path();
2322 if (!file_exist(path
)) {
2323 /* We allow the default smb.conf file to not exist,
2324 * basically the equivalent of an empty file. */
2325 return lpcfg_update(lp_ctx
);
2328 return lpcfg_load(lp_ctx
, path
);
2332 * Load the services array from the services file.
2334 * Return True on success, False on failure.
2336 bool lpcfg_load(struct loadparm_context
*lp_ctx
, const char *filename
)
2341 filename
= talloc_strdup(lp_ctx
, filename
);
2343 lp_ctx
->szConfigFile
= filename
;
2345 if (lp_ctx
->s3_fns
) {
2346 return lp_ctx
->s3_fns
->load(filename
);
2349 lp_ctx
->bInGlobalSection
= true;
2350 n2
= standard_sub_basic(lp_ctx
, lp_ctx
->szConfigFile
);
2351 DEBUG(2, ("lpcfg_load: refreshing parameters from %s\n", n2
));
2353 add_to_file_list(lp_ctx
, lp_ctx
->szConfigFile
, n2
);
2355 /* We get sections first, so have to start 'behind' to make up */
2356 lp_ctx
->currentService
= NULL
;
2357 bRetval
= pm_process(n2
, do_section
, do_parameter
, lp_ctx
);
2359 /* finish up the last section */
2360 DEBUG(4, ("pm_process() returned %s\n", BOOLSTR(bRetval
)));
2362 if (lp_ctx
->currentService
!= NULL
)
2363 bRetval
= lpcfg_service_ok(lp_ctx
->currentService
);
2365 bRetval
= bRetval
&& lpcfg_update(lp_ctx
);
2367 /* we do this unconditionally, so that it happens even
2368 for a missing smb.conf */
2369 reload_charcnv(lp_ctx
);
2371 if (bRetval
== true) {
2372 /* set this up so that any child python tasks will
2373 find the right smb.conf */
2374 setenv("SMB_CONF_PATH", filename
, 1);
2376 /* set the context used by the lp_*() function
2378 global_loadparm_context
= lp_ctx
;
2379 lp_ctx
->loaded
= true;
2386 * Return the max number of services.
2389 int lpcfg_numservices(struct loadparm_context
*lp_ctx
)
2391 if (lp_ctx
->s3_fns
) {
2392 return lp_ctx
->s3_fns
->get_numservices();
2395 return lp_ctx
->iNumServices
;
2399 * Display the contents of the services array in human-readable form.
2402 void lpcfg_dump(struct loadparm_context
*lp_ctx
, FILE *f
, bool show_defaults
,
2407 if (lp_ctx
->s3_fns
) {
2408 lp_ctx
->s3_fns
->dump(f
, show_defaults
, maxtoprint
);
2412 defaults_saved
= !show_defaults
;
2414 dump_globals(lp_ctx
, f
, show_defaults
);
2416 dump_a_service(lp_ctx
->sDefault
, lp_ctx
->sDefault
, f
, lp_ctx
->flags
);
2418 for (iService
= 0; iService
< maxtoprint
; iService
++)
2419 lpcfg_dump_one(f
, show_defaults
, lp_ctx
->services
[iService
], lp_ctx
->sDefault
);
2423 * Display the contents of one service in human-readable form.
2425 void lpcfg_dump_one(FILE *f
, bool show_defaults
, struct loadparm_service
*service
, struct loadparm_service
*sDefault
)
2427 if (service
!= NULL
) {
2428 if (service
->szService
[0] == '\0')
2430 dump_a_service(service
, sDefault
, f
, NULL
);
2434 struct loadparm_service
*lpcfg_servicebynum(struct loadparm_context
*lp_ctx
,
2437 if (lp_ctx
->s3_fns
) {
2438 return lp_ctx
->s3_fns
->get_servicebynum(snum
);
2441 return lp_ctx
->services
[snum
];
2444 struct loadparm_service
*lpcfg_service(struct loadparm_context
*lp_ctx
,
2445 const char *service_name
)
2450 if (lp_ctx
->s3_fns
) {
2451 return lp_ctx
->s3_fns
->get_service(service_name
);
2454 for (iService
= lp_ctx
->iNumServices
- 1; iService
>= 0; iService
--) {
2455 if (lp_ctx
->services
[iService
] &&
2456 lp_ctx
->services
[iService
]->szService
) {
2458 * The substitution here is used to support %U is
2461 serviceName
= standard_sub_basic(
2462 lp_ctx
->services
[iService
],
2463 lp_ctx
->services
[iService
]->szService
);
2464 if (strequal(serviceName
, service_name
)) {
2465 talloc_free(serviceName
);
2466 return lp_ctx
->services
[iService
];
2468 talloc_free(serviceName
);
2472 DEBUG(7,("lpcfg_servicenumber: couldn't find %s\n", service_name
));
2476 const char *lpcfg_servicename(const struct loadparm_service
*service
)
2478 return lp_string((const char *)service
->szService
);
2482 * A useful volume label function.
2484 const char *lpcfg_volume_label(struct loadparm_service
*service
, struct loadparm_service
*sDefault
)
2487 ret
= lp_string((const char *)((service
!= NULL
&& service
->volume
!= NULL
) ?
2488 service
->volume
: sDefault
->volume
));
2490 return lpcfg_servicename(service
);
2495 * If we are PDC then prefer us as DMB
2497 const char *lpcfg_printername(struct loadparm_service
*service
, struct loadparm_service
*sDefault
)
2500 ret
= lp_string((const char *)((service
!= NULL
&& service
->szPrintername
!= NULL
) ?
2501 service
->szPrintername
: sDefault
->szPrintername
));
2502 if (ret
== NULL
|| (ret
!= NULL
&& *ret
== '\0'))
2503 ret
= lpcfg_servicename(service
);
2510 * Return the max print jobs per queue.
2512 int lpcfg_maxprintjobs(struct loadparm_service
*service
, struct loadparm_service
*sDefault
)
2514 int maxjobs
= (service
!= NULL
) ? service
->iMaxPrintJobs
: sDefault
->iMaxPrintJobs
;
2515 if (maxjobs
<= 0 || maxjobs
>= PRINT_MAX_JOBID
)
2516 maxjobs
= PRINT_MAX_JOBID
- 1;
2521 struct smb_iconv_handle
*lpcfg_iconv_handle(struct loadparm_context
*lp_ctx
)
2523 if (lp_ctx
== NULL
) {
2524 return get_iconv_handle();
2526 return lp_ctx
->iconv_handle
;
2529 _PUBLIC_
void reload_charcnv(struct loadparm_context
*lp_ctx
)
2531 struct smb_iconv_handle
*old_ic
= lp_ctx
->iconv_handle
;
2532 if (!lp_ctx
->global
) {
2536 if (old_ic
== NULL
) {
2537 old_ic
= global_iconv_handle
;
2539 lp_ctx
->iconv_handle
= smb_iconv_handle_reinit_lp(lp_ctx
, lp_ctx
, old_ic
);
2540 global_iconv_handle
= lp_ctx
->iconv_handle
;
2543 _PUBLIC_
char *lpcfg_tls_keyfile(TALLOC_CTX
*mem_ctx
, struct loadparm_context
*lp_ctx
)
2545 return lpcfg_private_path(mem_ctx
, lp_ctx
, lp_ctx
->globals
->tls_keyfile
);
2548 _PUBLIC_
char *lpcfg_tls_certfile(TALLOC_CTX
*mem_ctx
, struct loadparm_context
*lp_ctx
)
2550 return lpcfg_private_path(mem_ctx
, lp_ctx
, lp_ctx
->globals
->tls_certfile
);
2553 _PUBLIC_
char *lpcfg_tls_cafile(TALLOC_CTX
*mem_ctx
, struct loadparm_context
*lp_ctx
)
2555 return lpcfg_private_path(mem_ctx
, lp_ctx
, lp_ctx
->globals
->tls_cafile
);
2558 _PUBLIC_
char *lpcfg_tls_crlfile(TALLOC_CTX
*mem_ctx
, struct loadparm_context
*lp_ctx
)
2560 return lpcfg_private_path(mem_ctx
, lp_ctx
, lp_ctx
->globals
->tls_crlfile
);
2563 _PUBLIC_
char *lpcfg_tls_dhpfile(TALLOC_CTX
*mem_ctx
, struct loadparm_context
*lp_ctx
)
2565 return lpcfg_private_path(mem_ctx
, lp_ctx
, lp_ctx
->globals
->tls_dhpfile
);
2568 struct gensec_settings
*lpcfg_gensec_settings(TALLOC_CTX
*mem_ctx
, struct loadparm_context
*lp_ctx
)
2570 struct gensec_settings
*settings
= talloc_zero(mem_ctx
, struct gensec_settings
);
2571 if (settings
== NULL
)
2573 SMB_ASSERT(lp_ctx
!= NULL
);
2574 settings
->lp_ctx
= talloc_reference(settings
, lp_ctx
);
2575 settings
->target_hostname
= lpcfg_parm_string(lp_ctx
, NULL
, "gensec", "target_hostname");
2579 int lpcfg_server_role(struct loadparm_context
*lp_ctx
)
2581 int domain_master
= lpcfg__domain_master(lp_ctx
);
2583 return lp_find_server_role(lpcfg__server_role(lp_ctx
),
2584 lpcfg__security(lp_ctx
),
2585 lpcfg__domain_logons(lp_ctx
),
2586 (domain_master
== true) ||
2587 (domain_master
== Auto
));
2590 int lpcfg_security(struct loadparm_context
*lp_ctx
)
2592 return lp_find_security(lpcfg__server_role(lp_ctx
),
2593 lpcfg__security(lp_ctx
));