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"
69 #include "source4/dns_server/dns_update.h"
71 #define standard_sub_basic talloc_strdup
73 static bool do_parameter(const char *, const char *, void *);
74 static bool defaults_saved
= false;
76 #define LOADPARM_EXTRA_GLOBALS \
77 struct parmlist_entry *param_opt; \
80 int iminreceivefile; \
81 char *szPrintcapname; \
83 int iPreferredMaster; \
84 char *szLdapMachineSuffix; \
85 char *szLdapUserSuffix; \
86 char *szLdapIdmapSuffix; \
87 char *szLdapGroupSuffix; \
88 char *szUsershareTemplateShare; \
91 int winbindMaxDomainConnections; \
92 int ismb2_max_credits; \
101 #include "lib/param/param_global.h"
103 #define NUMPARAMETERS (sizeof(parm_table) / sizeof(struct parm_struct))
105 /* we don't need a special handler for "dos charset" and "unix charset" */
106 #define handle_dos_charset NULL
107 #define handle_charset NULL
109 /* these are parameter handlers which are not needed in the
112 #define handle_netbios_aliases NULL
113 #define handle_printing NULL
114 #define handle_ldap_debug_level NULL
115 #define handle_idmap_backend NULL
116 #define handle_idmap_uid NULL
117 #define handle_idmap_gid NULL
123 /* prototypes for the special type handlers */
124 static bool handle_include(struct loadparm_context
*lp_ctx
, int unused
,
125 const char *pszParmValue
, char **ptr
);
126 static bool handle_realm(struct loadparm_context
*lp_ctx
, int unused
,
127 const char *pszParmValue
, char **ptr
);
128 static bool handle_copy(struct loadparm_context
*lp_ctx
, int unused
,
129 const char *pszParmValue
, char **ptr
);
130 static bool handle_debug_list(struct loadparm_context
*lp_ctx
, int unused
,
131 const char *pszParmValue
, char **ptr
);
132 static bool handle_logfile(struct loadparm_context
*lp_ctx
, int unused
,
133 const char *pszParmValue
, char **ptr
);
135 #include "lib/param/param_table.c"
137 /* local variables */
138 struct loadparm_context
{
139 const char *szConfigFile
;
140 struct loadparm_global
*globals
;
141 struct loadparm_service
**services
;
142 struct loadparm_service
*sDefault
;
143 struct smb_iconv_handle
*iconv_handle
;
145 struct loadparm_service
*currentService
;
146 bool bInGlobalSection
;
148 struct file_lists
*next
;
153 unsigned int flags
[NUMPARAMETERS
];
156 bool global
; /* Is this the global context, which may set
157 * global variables such as debug level etc? */
158 const struct loadparm_s3_helpers
*s3_fns
;
162 struct loadparm_service
*lpcfg_default_service(struct loadparm_context
*lp_ctx
)
164 if (lp_ctx
->s3_fns
) {
165 return lp_ctx
->s3_fns
->get_default_loadparm_service();
167 return lp_ctx
->sDefault
;
171 * Convenience routine to grab string parameters into temporary memory
172 * and run standard_sub_basic on them.
174 * The buffers can be written to by
175 * callers without affecting the source string.
178 static const char *lp_string(const char *s
)
180 #if 0 /* until REWRITE done to make thread-safe */
181 size_t len
= s
? strlen(s
) : 0;
185 /* The follow debug is useful for tracking down memory problems
186 especially if you have an inner loop that is calling a lp_*()
187 function that returns a string. Perhaps this debug should be
188 present all the time? */
191 DEBUG(10, ("lp_string(%s)\n", s
));
194 #if 0 /* until REWRITE done to make thread-safe */
196 lp_talloc
= talloc_init("lp_talloc");
198 ret
= talloc_array(lp_talloc
, char, len
+ 100); /* leave room for substitution */
206 strlcpy(ret
, s
, len
);
208 if (trim_string(ret
, "\"", "\"")) {
209 if (strchr(ret
,'"') != NULL
)
210 strlcpy(ret
, s
, len
);
213 standard_sub_basic(ret
,len
+100);
220 In this section all the functions that are used to access the
221 parameters from the rest of the program are defined
225 * the creation of separate lpcfg_*() and lp_*() functions is to allow
226 * for code compatibility between existing Samba4 and Samba3 code.
229 /* this global context supports the lp_*() function varients */
230 static struct loadparm_context
*global_loadparm_context
;
232 #define lpcfg_default_service global_loadparm_context->sDefault
233 #define lpcfg_global_service(i) global_loadparm_context->services[i]
235 #define FN_GLOBAL_STRING(fn_name,var_name) \
236 _PUBLIC_ const char *lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) { \
237 if (lp_ctx == NULL) return NULL; \
238 if (lp_ctx->s3_fns) { \
239 SMB_ASSERT(lp_ctx->s3_fns->fn_name); \
240 return lp_ctx->s3_fns->fn_name(); \
242 return lp_ctx->globals->var_name ? lp_string(lp_ctx->globals->var_name) : ""; \
245 #define FN_GLOBAL_CONST_STRING(fn_name,var_name) \
246 _PUBLIC_ const char *lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) {\
247 if (lp_ctx == NULL) return NULL; \
248 if (lp_ctx->s3_fns) { \
249 SMB_ASSERT(lp_ctx->s3_fns->fn_name); \
250 return lp_ctx->s3_fns->fn_name(); \
252 return lp_ctx->globals->var_name ? lp_string(lp_ctx->globals->var_name) : ""; \
255 #define FN_GLOBAL_LIST(fn_name,var_name) \
256 _PUBLIC_ const char **lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) { \
257 if (lp_ctx == NULL) return NULL; \
258 if (lp_ctx->s3_fns) { \
259 SMB_ASSERT(lp_ctx->s3_fns->fn_name); \
260 return lp_ctx->s3_fns->fn_name(); \
262 return lp_ctx->globals->var_name; \
265 #define FN_GLOBAL_BOOL(fn_name,var_name) \
266 _PUBLIC_ bool lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) {\
267 if (lp_ctx == NULL) return false; \
268 if (lp_ctx->s3_fns) { \
269 SMB_ASSERT(lp_ctx->s3_fns->fn_name); \
270 return lp_ctx->s3_fns->fn_name(); \
272 return lp_ctx->globals->var_name; \
275 #define FN_GLOBAL_INTEGER(fn_name,var_name) \
276 _PUBLIC_ int lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) { \
277 if (lp_ctx->s3_fns) { \
278 SMB_ASSERT(lp_ctx->s3_fns->fn_name); \
279 return lp_ctx->s3_fns->fn_name(); \
281 return lp_ctx->globals->var_name; \
284 /* Local parameters don't need the ->s3_fns because the struct
285 * loadparm_service is shared and lpcfg_service() checks the ->s3_fns
287 #define FN_LOCAL_STRING(fn_name,val) \
288 _PUBLIC_ const char *lpcfg_ ## fn_name(struct loadparm_service *service, \
289 struct loadparm_service *sDefault) { \
290 return(lp_string((const char *)((service != NULL && service->val != NULL) ? service->val : sDefault->val))); \
293 #define FN_LOCAL_CONST_STRING(fn_name,val) FN_LOCAL_STRING(fn_name, val)
295 #define FN_LOCAL_LIST(fn_name,val) \
296 _PUBLIC_ const char **lpcfg_ ## fn_name(struct loadparm_service *service, \
297 struct loadparm_service *sDefault) {\
298 return(const char **)(service != NULL && service->val != NULL? service->val : sDefault->val); \
301 #define FN_LOCAL_PARM_BOOL(fn_name, val) FN_LOCAL_BOOL(fn_name, val)
303 #define FN_LOCAL_BOOL(fn_name,val) \
304 _PUBLIC_ bool lpcfg_ ## fn_name(struct loadparm_service *service, \
305 struct loadparm_service *sDefault) { \
306 return((service != NULL)? service->val : sDefault->val); \
309 #define FN_LOCAL_INTEGER(fn_name,val) \
310 _PUBLIC_ int lpcfg_ ## fn_name(struct loadparm_service *service, \
311 struct loadparm_service *sDefault) { \
312 return((service != NULL)? service->val : sDefault->val); \
315 #define FN_LOCAL_PARM_INTEGER(fn_name, val) FN_LOCAL_INTEGER(fn_name, val)
317 #define FN_LOCAL_PARM_CHAR(fn_name, val) FN_LOCAL_CHAR(fn_name, val)
319 #define FN_LOCAL_CHAR(fn_name,val) \
320 _PUBLIC_ char lpcfg_ ## fn_name(struct loadparm_service *service, \
321 struct loadparm_service *sDefault) { \
322 return((service != NULL)? service->val : sDefault->val); \
325 #include "lib/param/param_functions.c"
327 /* These functions remain only in lib/param for now */
328 FN_GLOBAL_BOOL(readraw
, bReadRaw
)
329 FN_GLOBAL_BOOL(writeraw
, bWriteRaw
)
330 FN_GLOBAL_STRING(cachedir
, szCacheDir
)
331 FN_GLOBAL_STRING(statedir
, szStateDir
)
333 /* local prototypes */
334 static int map_parameter(const char *pszParmName
);
335 static struct loadparm_service
*getservicebyname(struct loadparm_context
*lp_ctx
,
336 const char *pszServiceName
);
337 static void copy_service(struct loadparm_service
*pserviceDest
,
338 struct loadparm_service
*pserviceSource
,
339 struct bitmap
*pcopymapDest
);
340 static bool lpcfg_service_ok(struct loadparm_service
*service
);
341 static bool do_section(const char *pszSectionName
, void *);
342 static void init_copymap(struct loadparm_service
*pservice
);
344 /* This is a helper function for parametrical options support. */
345 /* It returns a pointer to parametrical option value if it exists or NULL otherwise */
346 /* Actual parametrical functions are quite simple */
347 const char *lpcfg_get_parametric(struct loadparm_context
*lp_ctx
,
348 struct loadparm_service
*service
,
349 const char *type
, const char *option
)
351 char *vfskey_tmp
= NULL
;
353 struct parmlist_entry
*data
;
358 if (lp_ctx
->s3_fns
) {
359 return lp_ctx
->s3_fns
->get_parametric(service
, type
, option
);
362 data
= (service
== NULL
? lp_ctx
->globals
->param_opt
: service
->param_opt
);
364 vfskey_tmp
= talloc_asprintf(NULL
, "%s:%s", type
, option
);
365 if (vfskey_tmp
== NULL
) return NULL
;
366 vfskey
= strlower_talloc(NULL
, vfskey_tmp
);
367 talloc_free(vfskey_tmp
);
370 if (strcmp(data
->key
, vfskey
) == 0) {
377 if (service
!= NULL
) {
378 /* Try to fetch the same option but from globals */
379 /* but only if we are not already working with globals */
380 for (data
= lp_ctx
->globals
->param_opt
; data
;
382 if (strcmp(data
->key
, vfskey
) == 0) {
396 * convenience routine to return int parameters.
398 static int lp_int(const char *s
)
402 DEBUG(0,("lp_int(%s): is called with NULL!\n",s
));
406 return strtol(s
, NULL
, 0);
410 * convenience routine to return unsigned long parameters.
412 static unsigned long lp_ulong(const char *s
)
416 DEBUG(0,("lp_ulong(%s): is called with NULL!\n",s
));
420 return strtoul(s
, NULL
, 0);
424 * convenience routine to return unsigned long parameters.
426 static long lp_long(const char *s
)
430 DEBUG(0,("lp_long(%s): is called with NULL!\n",s
));
434 return strtol(s
, NULL
, 0);
438 * convenience routine to return unsigned long parameters.
440 static double lp_double(const char *s
)
444 DEBUG(0,("lp_double(%s): is called with NULL!\n",s
));
448 return strtod(s
, NULL
);
452 * convenience routine to return boolean parameters.
454 static bool lp_bool(const char *s
)
459 DEBUG(0,("lp_bool(%s): is called with NULL!\n",s
));
463 if (!set_boolean(s
, &ret
)) {
464 DEBUG(0,("lp_bool(%s): value is not boolean!\n",s
));
473 * Return parametric option from a given service. Type is a part of option before ':'
474 * Parametric option has following syntax: 'Type: option = value'
475 * Returned value is allocated in 'lp_talloc' context
478 const char *lpcfg_parm_string(struct loadparm_context
*lp_ctx
,
479 struct loadparm_service
*service
, const char *type
,
482 const char *value
= lpcfg_get_parametric(lp_ctx
, service
, type
, option
);
485 return lp_string(value
);
491 * Return parametric option from a given service. Type is a part of option before ':'
492 * Parametric option has following syntax: 'Type: option = value'
493 * Returned value is allocated in 'lp_talloc' context
496 const char **lpcfg_parm_string_list(TALLOC_CTX
*mem_ctx
,
497 struct loadparm_context
*lp_ctx
,
498 struct loadparm_service
*service
,
500 const char *option
, const char *separator
)
502 const char *value
= lpcfg_get_parametric(lp_ctx
, service
, type
, option
);
505 return (const char **)str_list_make(mem_ctx
, value
, separator
);
511 * Return parametric option from a given service. Type is a part of option before ':'
512 * Parametric option has following syntax: 'Type: option = value'
515 int lpcfg_parm_int(struct loadparm_context
*lp_ctx
,
516 struct loadparm_service
*service
, const char *type
,
517 const char *option
, int default_v
)
519 const char *value
= lpcfg_get_parametric(lp_ctx
, service
, type
, option
);
522 return lp_int(value
);
528 * Return parametric option from a given service. Type is a part of
530 * Parametric option has following syntax: 'Type: option = value'.
533 int lpcfg_parm_bytes(struct loadparm_context
*lp_ctx
,
534 struct loadparm_service
*service
, const char *type
,
535 const char *option
, int default_v
)
539 const char *value
= lpcfg_get_parametric(lp_ctx
, service
, type
, option
);
541 if (value
&& conv_str_size_error(value
, &bval
)) {
542 if (bval
<= INT_MAX
) {
551 * Return parametric option from a given service.
552 * Type is a part of option before ':'
553 * Parametric option has following syntax: 'Type: option = value'
555 unsigned long lpcfg_parm_ulong(struct loadparm_context
*lp_ctx
,
556 struct loadparm_service
*service
, const char *type
,
557 const char *option
, unsigned long default_v
)
559 const char *value
= lpcfg_get_parametric(lp_ctx
, service
, type
, option
);
562 return lp_ulong(value
);
567 long lpcfg_parm_long(struct loadparm_context
*lp_ctx
,
568 struct loadparm_service
*service
, const char *type
,
569 const char *option
, long default_v
)
571 const char *value
= lpcfg_get_parametric(lp_ctx
, service
, type
, option
);
574 return lp_long(value
);
579 double lpcfg_parm_double(struct loadparm_context
*lp_ctx
,
580 struct loadparm_service
*service
, const char *type
,
581 const char *option
, double default_v
)
583 const char *value
= lpcfg_get_parametric(lp_ctx
, service
, type
, option
);
586 return lp_double(value
);
592 * Return parametric option from a given service. Type is a part of option before ':'
593 * Parametric option has following syntax: 'Type: option = value'
596 bool lpcfg_parm_bool(struct loadparm_context
*lp_ctx
,
597 struct loadparm_service
*service
, const char *type
,
598 const char *option
, bool default_v
)
600 const char *value
= lpcfg_get_parametric(lp_ctx
, service
, type
, option
);
603 return lp_bool(value
);
610 * Initialise a service to the defaults.
613 static struct loadparm_service
*init_service(TALLOC_CTX
*mem_ctx
, struct loadparm_service
*sDefault
)
615 struct loadparm_service
*pservice
=
616 talloc_zero(mem_ctx
, struct loadparm_service
);
617 copy_service(pservice
, sDefault
, NULL
);
622 * Set a string value, deallocating any existing space, and allocing the space
625 static bool lpcfg_string_set(TALLOC_CTX
*mem_ctx
, char **dest
, const char *src
)
632 *dest
= talloc_strdup(mem_ctx
, src
);
633 if ((*dest
) == NULL
) {
634 DEBUG(0,("Out of memory in string_set\n"));
642 * Set a string value, deallocating any existing space, and allocing the space
645 static bool lpcfg_string_set_upper(TALLOC_CTX
*mem_ctx
, char **dest
, const char *src
)
652 *dest
= strupper_talloc(mem_ctx
, src
);
653 if ((*dest
) == NULL
) {
654 DEBUG(0,("Out of memory in string_set_upper\n"));
664 * Add a new service to the services array initialising it with the given
668 struct loadparm_service
*lpcfg_add_service(struct loadparm_context
*lp_ctx
,
669 const struct loadparm_service
*pservice
,
673 struct loadparm_service tservice
;
674 int num_to_alloc
= lp_ctx
->iNumServices
+ 1;
675 struct parmlist_entry
*data
, *pdata
;
677 if (pservice
== NULL
) {
678 pservice
= lp_ctx
->sDefault
;
681 tservice
= *pservice
;
683 /* it might already exist */
685 struct loadparm_service
*service
= getservicebyname(lp_ctx
,
687 if (service
!= NULL
) {
688 /* Clean all parametric options for service */
689 /* They will be added during parsing again */
690 data
= service
->param_opt
;
696 service
->param_opt
= NULL
;
701 /* find an invalid one */
702 for (i
= 0; i
< lp_ctx
->iNumServices
; i
++)
703 if (lp_ctx
->services
[i
] == NULL
)
706 /* if not, then create one */
707 if (i
== lp_ctx
->iNumServices
) {
708 struct loadparm_service
**tsp
;
710 tsp
= talloc_realloc(lp_ctx
, lp_ctx
->services
, struct loadparm_service
*, num_to_alloc
);
713 DEBUG(0,("lpcfg_add_service: failed to enlarge services!\n"));
716 lp_ctx
->services
= tsp
;
717 lp_ctx
->services
[lp_ctx
->iNumServices
] = NULL
;
720 lp_ctx
->iNumServices
++;
723 lp_ctx
->services
[i
] = init_service(lp_ctx
->services
, lp_ctx
->sDefault
);
724 if (lp_ctx
->services
[i
] == NULL
) {
725 DEBUG(0,("lpcfg_add_service: out of memory!\n"));
728 copy_service(lp_ctx
->services
[i
], &tservice
, NULL
);
730 lpcfg_string_set(lp_ctx
->services
[i
], &lp_ctx
->services
[i
]->szService
, name
);
731 return lp_ctx
->services
[i
];
735 * Add a new home service, with the specified home directory, defaults coming
736 * from service ifrom.
739 bool lpcfg_add_home(struct loadparm_context
*lp_ctx
,
740 const char *pszHomename
,
741 struct loadparm_service
*default_service
,
742 const char *user
, const char *pszHomedir
)
744 struct loadparm_service
*service
;
746 service
= lpcfg_add_service(lp_ctx
, default_service
, pszHomename
);
751 if (!(*(default_service
->szPath
))
752 || strequal(default_service
->szPath
, lp_ctx
->sDefault
->szPath
)) {
753 service
->szPath
= talloc_strdup(service
, pszHomedir
);
755 service
->szPath
= string_sub_talloc(service
, lpcfg_pathname(default_service
, lp_ctx
->sDefault
), "%H", pszHomedir
);
758 if (!(*(service
->comment
))) {
759 service
->comment
= talloc_asprintf(service
, "Home directory of %s", user
);
761 service
->bAvailable
= default_service
->bAvailable
;
762 service
->bBrowseable
= default_service
->bBrowseable
;
764 DEBUG(3, ("adding home's share [%s] for user '%s' at '%s'\n",
765 pszHomename
, user
, service
->szPath
));
771 * Add a new printer service, with defaults coming from service iFrom.
774 bool lpcfg_add_printer(struct loadparm_context
*lp_ctx
,
775 const char *pszPrintername
,
776 struct loadparm_service
*default_service
)
778 const char *comment
= "From Printcap";
779 struct loadparm_service
*service
;
780 service
= lpcfg_add_service(lp_ctx
, default_service
, pszPrintername
);
785 /* note that we do NOT default the availability flag to True - */
786 /* we take it from the default service passed. This allows all */
787 /* dynamic printers to be disabled by disabling the [printers] */
788 /* entry (if/when the 'available' keyword is implemented!). */
790 /* the printer name is set to the service name. */
791 lpcfg_string_set(service
, &service
->szPrintername
, pszPrintername
);
792 lpcfg_string_set(service
, &service
->comment
, comment
);
793 service
->bBrowseable
= default_service
->bBrowseable
;
794 /* Printers cannot be read_only. */
795 service
->bRead_only
= false;
796 /* Printer services must be printable. */
797 service
->bPrint_ok
= true;
799 DEBUG(3, ("adding printer service %s\n", pszPrintername
));
805 * Map a parameter's string representation to something we can use.
806 * Returns False if the parameter string is not recognised, else TRUE.
809 static int map_parameter(const char *pszParmName
)
813 if (*pszParmName
== '-')
816 for (iIndex
= 0; parm_table
[iIndex
].label
; iIndex
++)
817 if (strwicmp(parm_table
[iIndex
].label
, pszParmName
) == 0)
820 /* Warn only if it isn't parametric option */
821 if (strchr(pszParmName
, ':') == NULL
)
822 DEBUG(0, ("Unknown parameter encountered: \"%s\"\n", pszParmName
));
823 /* We do return 'fail' for parametric options as well because they are
824 stored in different storage
831 return the parameter structure for a parameter
833 struct parm_struct
*lpcfg_parm_struct(struct loadparm_context
*lp_ctx
, const char *name
)
837 if (lp_ctx
->s3_fns
) {
838 return lp_ctx
->s3_fns
->get_parm_struct(name
);
841 parmnum
= map_parameter(name
);
842 if (parmnum
== -1) return NULL
;
843 return &parm_table
[parmnum
];
847 return the parameter pointer for a parameter
849 void *lpcfg_parm_ptr(struct loadparm_context
*lp_ctx
,
850 struct loadparm_service
*service
, struct parm_struct
*parm
)
852 if (lp_ctx
->s3_fns
) {
853 return lp_ctx
->s3_fns
->get_parm_ptr(service
, parm
);
856 if (service
== NULL
) {
857 if (parm
->p_class
== P_LOCAL
)
858 return ((char *)lp_ctx
->sDefault
)+parm
->offset
;
859 else if (parm
->p_class
== P_GLOBAL
)
860 return ((char *)lp_ctx
->globals
)+parm
->offset
;
863 return ((char *)service
) + parm
->offset
;
868 return the parameter pointer for a parameter
870 bool lpcfg_parm_is_cmdline(struct loadparm_context
*lp_ctx
, const char *name
)
874 if (lp_ctx
->s3_fns
) {
875 struct parm_struct
*parm
= lp_ctx
->s3_fns
->get_parm_struct(name
);
877 return parm
->flags
& FLAG_CMDLINE
;
882 parmnum
= map_parameter(name
);
883 if (parmnum
== -1) return false;
885 return lp_ctx
->flags
[parmnum
] & FLAG_CMDLINE
;
889 * Find a service by name. Otherwise works like get_service.
892 static struct loadparm_service
*getservicebyname(struct loadparm_context
*lp_ctx
,
893 const char *pszServiceName
)
897 if (lp_ctx
->s3_fns
) {
898 return lp_ctx
->s3_fns
->get_service(pszServiceName
);
901 for (iService
= lp_ctx
->iNumServices
- 1; iService
>= 0; iService
--)
902 if (lp_ctx
->services
[iService
] != NULL
&&
903 strwicmp(lp_ctx
->services
[iService
]->szService
, pszServiceName
) == 0) {
904 return lp_ctx
->services
[iService
];
911 * Copy a service structure to another.
912 * If pcopymapDest is NULL then copy all fields
915 static void copy_service(struct loadparm_service
*pserviceDest
,
916 struct loadparm_service
*pserviceSource
,
917 struct bitmap
*pcopymapDest
)
920 bool bcopyall
= (pcopymapDest
== NULL
);
921 struct parmlist_entry
*data
, *pdata
, *paramo
;
924 for (i
= 0; parm_table
[i
].label
; i
++)
925 if (parm_table
[i
].p_class
== P_LOCAL
&&
926 (bcopyall
|| bitmap_query(pcopymapDest
, i
))) {
928 ((char *)pserviceSource
) + parm_table
[i
].offset
;
930 ((char *)pserviceDest
) + parm_table
[i
].offset
;
932 switch (parm_table
[i
].type
) {
934 *(bool *)dest_ptr
= *(bool *)src_ptr
;
941 *(int *)dest_ptr
= *(int *)src_ptr
;
945 lpcfg_string_set(pserviceDest
,
951 lpcfg_string_set_upper(pserviceDest
,
956 *(const char ***)dest_ptr
= (const char **)str_list_copy(pserviceDest
,
957 *(const char ***)src_ptr
);
965 init_copymap(pserviceDest
);
966 if (pserviceSource
->copymap
)
967 bitmap_copy(pserviceDest
->copymap
,
968 pserviceSource
->copymap
);
971 data
= pserviceSource
->param_opt
;
974 pdata
= pserviceDest
->param_opt
;
975 /* Traverse destination */
977 /* If we already have same option, override it */
978 if (strcmp(pdata
->key
, data
->key
) == 0) {
979 talloc_free(pdata
->value
);
980 pdata
->value
= talloc_strdup(pdata
,
988 paramo
= talloc_zero(pserviceDest
, struct parmlist_entry
);
991 paramo
->key
= talloc_strdup(paramo
, data
->key
);
992 paramo
->value
= talloc_strdup(paramo
, data
->value
);
993 DLIST_ADD(pserviceDest
->param_opt
, paramo
);
1000 * Check a service for consistency. Return False if the service is in any way
1001 * incomplete or faulty, else True.
1003 static bool lpcfg_service_ok(struct loadparm_service
*service
)
1008 if (service
->szService
[0] == '\0') {
1009 DEBUG(0, ("The following message indicates an internal error:\n"));
1010 DEBUG(0, ("No service name in service entry.\n"));
1014 /* The [printers] entry MUST be printable. I'm all for flexibility, but */
1015 /* I can't see why you'd want a non-printable printer service... */
1016 if (strwicmp(service
->szService
, PRINTERS_NAME
) == 0) {
1017 if (!service
->bPrint_ok
) {
1018 DEBUG(0, ("WARNING: [%s] service MUST be printable!\n",
1019 service
->szService
));
1020 service
->bPrint_ok
= true;
1022 /* [printers] service must also be non-browsable. */
1023 if (service
->bBrowseable
)
1024 service
->bBrowseable
= false;
1027 /* If a service is flagged unavailable, log the fact at level 0. */
1028 if (!service
->bAvailable
)
1029 DEBUG(1, ("NOTE: Service %s is flagged unavailable.\n",
1030 service
->szService
));
1036 /*******************************************************************
1037 Keep a linked list of all config files so we know when one has changed
1038 it's date and needs to be reloaded.
1039 ********************************************************************/
1041 static void add_to_file_list(struct loadparm_context
*lp_ctx
,
1042 const char *fname
, const char *subfname
)
1044 struct file_lists
*f
= lp_ctx
->file_lists
;
1047 if (f
->name
&& !strcmp(f
->name
, fname
))
1053 f
= talloc(lp_ctx
, struct file_lists
);
1056 f
->next
= lp_ctx
->file_lists
;
1057 f
->name
= talloc_strdup(f
, fname
);
1062 f
->subfname
= talloc_strdup(f
, subfname
);
1067 lp_ctx
->file_lists
= f
;
1068 f
->modtime
= file_modtime(subfname
);
1070 time_t t
= file_modtime(subfname
);
1076 /*******************************************************************
1077 Check if a config file has changed date.
1078 ********************************************************************/
1079 bool lpcfg_file_list_changed(struct loadparm_context
*lp_ctx
)
1081 struct file_lists
*f
;
1082 DEBUG(6, ("lp_file_list_changed()\n"));
1084 for (f
= lp_ctx
->file_lists
; f
!= NULL
; f
= f
->next
) {
1088 n2
= standard_sub_basic(lp_ctx
, f
->name
);
1090 DEBUGADD(6, ("file %s -> %s last mod_time: %s\n",
1091 f
->name
, n2
, ctime(&f
->modtime
)));
1093 mod_time
= file_modtime(n2
);
1095 if (mod_time
&& ((f
->modtime
!= mod_time
) || (f
->subfname
== NULL
) || (strcmp(n2
, f
->subfname
) != 0))) {
1096 DEBUGADD(6, ("file %s modified: %s\n", n2
,
1098 f
->modtime
= mod_time
;
1099 talloc_free(f
->subfname
);
1100 f
->subfname
= talloc_strdup(f
, n2
);
1107 /***************************************************************************
1108 Handle the "realm" parameter
1109 ***************************************************************************/
1111 static bool handle_realm(struct loadparm_context
*lp_ctx
, int unused
,
1112 const char *pszParmValue
, char **ptr
)
1114 lpcfg_string_set(lp_ctx
, ptr
, pszParmValue
);
1116 talloc_free(lp_ctx
->globals
->szRealm_upper
);
1117 talloc_free(lp_ctx
->globals
->szRealm_lower
);
1119 lp_ctx
->globals
->szRealm_upper
= strupper_talloc(lp_ctx
, pszParmValue
);
1120 lp_ctx
->globals
->szRealm_lower
= strlower_talloc(lp_ctx
, pszParmValue
);
1125 /***************************************************************************
1126 Handle the include operation.
1127 ***************************************************************************/
1129 static bool handle_include(struct loadparm_context
*lp_ctx
, int unused
,
1130 const char *pszParmValue
, char **ptr
)
1132 char *fname
= standard_sub_basic(lp_ctx
, pszParmValue
);
1134 add_to_file_list(lp_ctx
, pszParmValue
, fname
);
1136 lpcfg_string_set(lp_ctx
, ptr
, fname
);
1138 if (file_exist(fname
))
1139 return pm_process(fname
, do_section
, do_parameter
, lp_ctx
);
1141 DEBUG(2, ("Can't find include file %s\n", fname
));
1146 /***************************************************************************
1147 Handle the interpretation of the copy parameter.
1148 ***************************************************************************/
1150 static bool handle_copy(struct loadparm_context
*lp_ctx
, int unused
,
1151 const char *pszParmValue
, char **ptr
)
1154 struct loadparm_service
*serviceTemp
;
1156 lpcfg_string_set(lp_ctx
, ptr
, pszParmValue
);
1160 DEBUG(3, ("Copying service from service %s\n", pszParmValue
));
1162 if ((serviceTemp
= getservicebyname(lp_ctx
, pszParmValue
)) != NULL
) {
1163 if (serviceTemp
== lp_ctx
->currentService
) {
1164 DEBUG(0, ("Can't copy service %s - unable to copy self!\n", pszParmValue
));
1166 copy_service(lp_ctx
->currentService
,
1168 lp_ctx
->currentService
->copymap
);
1172 DEBUG(0, ("Unable to copy service - source not found: %s\n",
1180 static bool handle_debug_list(struct loadparm_context
*lp_ctx
, int unused
,
1181 const char *pszParmValue
, char **ptr
)
1184 lpcfg_string_set(lp_ctx
, ptr
, pszParmValue
);
1185 if (lp_ctx
->global
) {
1186 return debug_parse_levels(pszParmValue
);
1191 static bool handle_logfile(struct loadparm_context
*lp_ctx
, int unused
,
1192 const char *pszParmValue
, char **ptr
)
1194 debug_set_logfile(pszParmValue
);
1195 if (lp_ctx
->global
) {
1196 lpcfg_string_set(lp_ctx
, ptr
, pszParmValue
);
1201 /***************************************************************************
1202 Initialise a copymap.
1203 ***************************************************************************/
1205 static void init_copymap(struct loadparm_service
*pservice
)
1209 TALLOC_FREE(pservice
->copymap
);
1211 pservice
->copymap
= bitmap_talloc(NULL
, NUMPARAMETERS
);
1212 if (!pservice
->copymap
)
1214 ("Couldn't allocate copymap!! (size %d)\n",
1215 (int)NUMPARAMETERS
));
1217 for (i
= 0; i
< NUMPARAMETERS
; i
++)
1218 bitmap_set(pservice
->copymap
, i
);
1222 * Process a parametric option
1224 static bool lp_do_parameter_parametric(struct loadparm_context
*lp_ctx
,
1225 struct loadparm_service
*service
,
1226 const char *pszParmName
,
1227 const char *pszParmValue
, int flags
)
1229 struct parmlist_entry
*paramo
, *data
;
1231 TALLOC_CTX
*mem_ctx
;
1233 while (isspace((unsigned char)*pszParmName
)) {
1237 name
= strlower_talloc(lp_ctx
, pszParmName
);
1238 if (!name
) return false;
1240 if (service
== NULL
) {
1241 data
= lp_ctx
->globals
->param_opt
;
1242 mem_ctx
= lp_ctx
->globals
;
1244 data
= service
->param_opt
;
1248 /* Traverse destination */
1249 for (paramo
=data
; paramo
; paramo
=paramo
->next
) {
1250 /* If we already have the option set, override it unless
1251 it was a command line option and the new one isn't */
1252 if (strcmp(paramo
->key
, name
) == 0) {
1253 if ((paramo
->priority
& FLAG_CMDLINE
) &&
1254 !(flags
& FLAG_CMDLINE
)) {
1259 talloc_free(paramo
->value
);
1260 paramo
->value
= talloc_strdup(paramo
, pszParmValue
);
1261 paramo
->priority
= flags
;
1267 paramo
= talloc_zero(mem_ctx
, struct parmlist_entry
);
1270 paramo
->key
= talloc_strdup(paramo
, name
);
1271 paramo
->value
= talloc_strdup(paramo
, pszParmValue
);
1272 paramo
->priority
= flags
;
1273 if (service
== NULL
) {
1274 DLIST_ADD(lp_ctx
->globals
->param_opt
, paramo
);
1276 DLIST_ADD(service
->param_opt
, paramo
);
1284 static bool set_variable(TALLOC_CTX
*mem_ctx
, int parmnum
, void *parm_ptr
,
1285 const char *pszParmName
, const char *pszParmValue
,
1286 struct loadparm_context
*lp_ctx
, bool on_globals
)
1289 /* if it is a special case then go ahead */
1290 if (parm_table
[parmnum
].special
) {
1292 ret
= parm_table
[parmnum
].special(lp_ctx
, -1, pszParmValue
,
1297 goto mark_non_default
;
1300 /* now switch on the type of variable it is */
1301 switch (parm_table
[parmnum
].type
)
1305 if (!set_boolean(pszParmValue
, &b
)) {
1306 DEBUG(0,("lp_do_parameter(%s): value is not boolean!\n", pszParmValue
));
1309 *(bool *)parm_ptr
= b
;
1315 if (!set_boolean(pszParmValue
, &b
)) {
1316 DEBUG(0,("lp_do_parameter(%s): value is not boolean!\n", pszParmValue
));
1319 *(bool *)parm_ptr
= !b
;
1324 *(int *)parm_ptr
= atoi(pszParmValue
);
1328 *(char *)parm_ptr
= *pszParmValue
;
1332 *(int *)parm_ptr
= strtol(pszParmValue
, NULL
, 8);
1338 if (conv_str_size_error(pszParmValue
, &val
)) {
1339 if (val
<= INT_MAX
) {
1340 *(int *)parm_ptr
= (int)val
;
1345 DEBUG(0,("lp_do_parameter(%s): value is not "
1346 "a valid size specifier!\n", pszParmValue
));
1351 *(const char ***)parm_ptr
= (const char **)str_list_make(mem_ctx
,
1352 pszParmValue
, NULL
);
1356 char **new_list
= str_list_make(mem_ctx
,
1357 pszParmValue
, NULL
);
1358 for (i
=0; new_list
[i
]; i
++) {
1359 if (new_list
[i
][0] == '+' && new_list
[i
][1]) {
1360 if (!str_list_check(*(const char ***)parm_ptr
,
1362 *(const char ***)parm_ptr
= str_list_add(*(const char ***)parm_ptr
,
1365 } else if (new_list
[i
][0] == '-' && new_list
[i
][1]) {
1366 str_list_remove(*(const char ***)parm_ptr
,
1370 DEBUG(0, ("Unsupported list syntax for: %s = %s\n",
1371 pszParmName
, pszParmValue
));
1374 *(const char ***)parm_ptr
= (const char **) new_list
;
1381 lpcfg_string_set(mem_ctx
, (char **)parm_ptr
, pszParmValue
);
1385 lpcfg_string_set_upper(mem_ctx
, (char **)parm_ptr
, pszParmValue
);
1389 for (i
= 0; parm_table
[parmnum
].enum_list
[i
].name
; i
++) {
1392 parm_table
[parmnum
].enum_list
[i
].name
)) {
1394 parm_table
[parmnum
].
1399 if (!parm_table
[parmnum
].enum_list
[i
].name
) {
1400 DEBUG(0,("Unknown enumerated value '%s' for '%s'\n",
1401 pszParmValue
, pszParmName
));
1411 if (on_globals
&& (lp_ctx
->flags
[parmnum
] & FLAG_DEFAULT
)) {
1412 lp_ctx
->flags
[parmnum
] &= ~FLAG_DEFAULT
;
1413 /* we have to also unset FLAG_DEFAULT on aliases */
1414 for (i
=parmnum
-1;i
>=0 && parm_table
[i
].offset
== parm_table
[parmnum
].offset
;i
--) {
1415 lp_ctx
->flags
[i
] &= ~FLAG_DEFAULT
;
1417 for (i
=parmnum
+1;i
<NUMPARAMETERS
&& parm_table
[i
].offset
== parm_table
[parmnum
].offset
;i
++) {
1418 lp_ctx
->flags
[i
] &= ~FLAG_DEFAULT
;
1425 bool lpcfg_do_global_parameter(struct loadparm_context
*lp_ctx
,
1426 const char *pszParmName
, const char *pszParmValue
)
1428 int parmnum
= map_parameter(pszParmName
);
1432 if (strchr(pszParmName
, ':')) {
1433 return lp_do_parameter_parametric(lp_ctx
, NULL
, pszParmName
, pszParmValue
, 0);
1435 DEBUG(0, ("Ignoring unknown parameter \"%s\"\n", pszParmName
));
1439 /* if the flag has been set on the command line, then don't allow override,
1440 but don't report an error */
1441 if (lp_ctx
->flags
[parmnum
] & FLAG_CMDLINE
) {
1445 parm_ptr
= lpcfg_parm_ptr(lp_ctx
, NULL
, &parm_table
[parmnum
]);
1447 return set_variable(lp_ctx
->globals
, parmnum
, parm_ptr
,
1448 pszParmName
, pszParmValue
, lp_ctx
, true);
1451 bool lpcfg_do_service_parameter(struct loadparm_context
*lp_ctx
,
1452 struct loadparm_service
*service
,
1453 const char *pszParmName
, const char *pszParmValue
)
1457 int parmnum
= map_parameter(pszParmName
);
1460 if (strchr(pszParmName
, ':')) {
1461 return lp_do_parameter_parametric(lp_ctx
, service
, pszParmName
, pszParmValue
, 0);
1463 DEBUG(0, ("Ignoring unknown parameter \"%s\"\n", pszParmName
));
1467 /* if the flag has been set on the command line, then don't allow override,
1468 but don't report an error */
1469 if (lp_ctx
->flags
[parmnum
] & FLAG_CMDLINE
) {
1473 if (parm_table
[parmnum
].p_class
== P_GLOBAL
) {
1475 ("Global parameter %s found in service section!\n",
1479 parm_ptr
= ((char *)service
) + parm_table
[parmnum
].offset
;
1481 if (!service
->copymap
)
1482 init_copymap(service
);
1484 /* this handles the aliases - set the copymap for other
1485 * entries with the same data pointer */
1486 for (i
= 0; parm_table
[i
].label
; i
++)
1487 if (parm_table
[i
].offset
== parm_table
[parmnum
].offset
&&
1488 parm_table
[i
].p_class
== parm_table
[parmnum
].p_class
)
1489 bitmap_clear(service
->copymap
, i
);
1491 return set_variable(service
, parmnum
, parm_ptr
, pszParmName
,
1492 pszParmValue
, lp_ctx
, false);
1496 * Process a parameter.
1499 static bool do_parameter(const char *pszParmName
, const char *pszParmValue
,
1502 struct loadparm_context
*lp_ctx
= (struct loadparm_context
*)userdata
;
1504 if (lp_ctx
->bInGlobalSection
)
1505 return lpcfg_do_global_parameter(lp_ctx
, pszParmName
,
1508 return lpcfg_do_service_parameter(lp_ctx
, lp_ctx
->currentService
,
1509 pszParmName
, pszParmValue
);
1513 variable argument do parameter
1515 bool lpcfg_do_global_parameter_var(struct loadparm_context
*lp_ctx
, const char *pszParmName
, const char *fmt
, ...) PRINTF_ATTRIBUTE(3, 4);
1516 bool lpcfg_do_global_parameter_var(struct loadparm_context
*lp_ctx
,
1517 const char *pszParmName
, const char *fmt
, ...)
1524 s
= talloc_vasprintf(NULL
, fmt
, ap
);
1526 ret
= lpcfg_do_global_parameter(lp_ctx
, pszParmName
, s
);
1533 set a parameter from the commandline - this is called from command line parameter
1534 parsing code. It sets the parameter then marks the parameter as unable to be modified
1535 by smb.conf processing
1537 bool lpcfg_set_cmdline(struct loadparm_context
*lp_ctx
, const char *pszParmName
,
1538 const char *pszParmValue
)
1543 if (lp_ctx
->s3_fns
) {
1544 return lp_ctx
->s3_fns
->set_cmdline(pszParmName
, pszParmValue
);
1547 parmnum
= map_parameter(pszParmName
);
1549 while (isspace((unsigned char)*pszParmValue
)) pszParmValue
++;
1552 if (parmnum
< 0 && strchr(pszParmName
, ':')) {
1553 /* set a parametric option */
1554 return lp_do_parameter_parametric(lp_ctx
, NULL
, pszParmName
,
1555 pszParmValue
, FLAG_CMDLINE
);
1559 DEBUG(0,("Unknown option '%s'\n", pszParmName
));
1563 /* reset the CMDLINE flag in case this has been called before */
1564 lp_ctx
->flags
[parmnum
] &= ~FLAG_CMDLINE
;
1566 if (!lpcfg_do_global_parameter(lp_ctx
, pszParmName
, pszParmValue
)) {
1570 lp_ctx
->flags
[parmnum
] |= FLAG_CMDLINE
;
1572 /* we have to also set FLAG_CMDLINE on aliases */
1573 for (i
=parmnum
-1;i
>=0 && parm_table
[i
].offset
== parm_table
[parmnum
].offset
;i
--) {
1574 lp_ctx
->flags
[i
] |= FLAG_CMDLINE
;
1576 for (i
=parmnum
+1;i
<NUMPARAMETERS
&& parm_table
[i
].offset
== parm_table
[parmnum
].offset
;i
++) {
1577 lp_ctx
->flags
[i
] |= FLAG_CMDLINE
;
1584 set a option from the commandline in 'a=b' format. Use to support --option
1586 bool lpcfg_set_option(struct loadparm_context
*lp_ctx
, const char *option
)
1591 s
= talloc_strdup(NULL
, option
);
1604 ret
= lpcfg_set_cmdline(lp_ctx
, s
, p
+1);
1610 #define BOOLSTR(b) ((b) ? "Yes" : "No")
1613 * Print a parameter of the specified type.
1616 static void print_parameter(struct parm_struct
*p
, void *ptr
, FILE * f
)
1618 /* For the seperation of lists values that we print below */
1619 const char *list_sep
= ", ";
1624 for (i
= 0; p
->enum_list
[i
].name
; i
++) {
1625 if (*(int *)ptr
== p
->enum_list
[i
].value
) {
1627 p
->enum_list
[i
].name
);
1634 fprintf(f
, "%s", BOOLSTR(*(bool *)ptr
));
1638 fprintf(f
, "%s", BOOLSTR(!*(bool *)ptr
));
1643 fprintf(f
, "%d", *(int *)ptr
);
1647 fprintf(f
, "%c", *(char *)ptr
);
1651 int val
= *(int *)ptr
;
1655 fprintf(f
, "0%o", val
);
1664 if ((char ***)ptr
&& *(char ***)ptr
) {
1665 char **list
= *(char ***)ptr
;
1666 for (; *list
; list
++) {
1667 /* surround strings with whitespace in double quotes */
1668 if (*(list
+1) == NULL
) {
1669 /* last item, no extra separator */
1672 if ( strchr_m( *list
, ' ' ) ) {
1673 fprintf(f
, "\"%s\"%s", *list
, list_sep
);
1675 fprintf(f
, "%s%s", *list
, list_sep
);
1683 if (*(char **)ptr
) {
1684 fprintf(f
, "%s", *(char **)ptr
);
1693 * Check if two parameters are equal.
1696 static bool equal_parameter(parm_type type
, void *ptr1
, void *ptr2
)
1701 return (*((bool *)ptr1
) == *((bool *)ptr2
));
1707 return (*((int *)ptr1
) == *((int *)ptr2
));
1710 return (*((char *)ptr1
) == *((char *)ptr2
));
1714 return str_list_equal(*(const char ***)ptr1
, *(const char ***)ptr2
);
1719 char *p1
= *(char **)ptr1
, *p2
= *(char **)ptr2
;
1724 return (p1
== p2
|| strequal(p1
, p2
));
1733 * Process a new section (service).
1735 * At this stage all sections are services.
1736 * Later we'll have special sections that permit server parameters to be set.
1737 * Returns True on success, False on failure.
1740 static bool do_section(const char *pszSectionName
, void *userdata
)
1742 struct loadparm_context
*lp_ctx
= (struct loadparm_context
*)userdata
;
1744 bool isglobal
= ((strwicmp(pszSectionName
, GLOBAL_NAME
) == 0) ||
1745 (strwicmp(pszSectionName
, GLOBAL_NAME2
) == 0));
1748 /* if we've just struck a global section, note the fact. */
1749 lp_ctx
->bInGlobalSection
= isglobal
;
1751 /* check for multiple global sections */
1752 if (lp_ctx
->bInGlobalSection
) {
1753 DEBUG(4, ("Processing section \"[%s]\"\n", pszSectionName
));
1757 /* if we have a current service, tidy it up before moving on */
1760 if (lp_ctx
->currentService
!= NULL
)
1761 bRetval
= lpcfg_service_ok(lp_ctx
->currentService
);
1763 /* if all is still well, move to the next record in the services array */
1765 /* We put this here to avoid an odd message order if messages are */
1766 /* issued by the post-processing of a previous section. */
1767 DEBUG(4, ("Processing section \"[%s]\"\n", pszSectionName
));
1769 if ((lp_ctx
->currentService
= lpcfg_add_service(lp_ctx
, lp_ctx
->sDefault
,
1772 DEBUG(0, ("Failed to add a new service\n"));
1782 * Determine if a particular base parameter is currently set to the default value.
1785 static bool is_default(struct loadparm_service
*sDefault
, int i
)
1787 void *def_ptr
= ((char *)sDefault
) + parm_table
[i
].offset
;
1788 if (!defaults_saved
)
1790 switch (parm_table
[i
].type
) {
1793 return str_list_equal((const char **)parm_table
[i
].def
.lvalue
,
1794 (const char **)def_ptr
);
1797 return strequal(parm_table
[i
].def
.svalue
,
1801 return parm_table
[i
].def
.bvalue
==
1808 return parm_table
[i
].def
.ivalue
==
1817 *Display the contents of the global structure.
1820 static void dump_globals(struct loadparm_context
*lp_ctx
, FILE *f
,
1824 struct parmlist_entry
*data
;
1826 fprintf(f
, "# Global parameters\n[global]\n");
1828 for (i
= 0; parm_table
[i
].label
; i
++)
1829 if (parm_table
[i
].p_class
== P_GLOBAL
&&
1830 (i
== 0 || (parm_table
[i
].offset
!= parm_table
[i
- 1].offset
))) {
1831 if (!show_defaults
&& (lp_ctx
->flags
[i
] & FLAG_DEFAULT
))
1833 fprintf(f
, "\t%s = ", parm_table
[i
].label
);
1834 print_parameter(&parm_table
[i
], lpcfg_parm_ptr(lp_ctx
, NULL
, &parm_table
[i
]), f
);
1837 if (lp_ctx
->globals
->param_opt
!= NULL
) {
1838 for (data
= lp_ctx
->globals
->param_opt
; data
;
1839 data
= data
->next
) {
1840 if (!show_defaults
&& (data
->priority
& FLAG_DEFAULT
)) {
1843 fprintf(f
, "\t%s = %s\n", data
->key
, data
->value
);
1850 * Display the contents of a single services record.
1853 static void dump_a_service(struct loadparm_service
* pService
, struct loadparm_service
*sDefault
, FILE * f
,
1854 unsigned int *flags
)
1857 struct parmlist_entry
*data
;
1859 if (pService
!= sDefault
)
1860 fprintf(f
, "\n[%s]\n", pService
->szService
);
1862 for (i
= 0; parm_table
[i
].label
; i
++) {
1863 if (parm_table
[i
].p_class
== P_LOCAL
&&
1864 (*parm_table
[i
].label
!= '-') &&
1865 (i
== 0 || (parm_table
[i
].offset
!= parm_table
[i
- 1].offset
)))
1867 if (pService
== sDefault
) {
1868 if (flags
&& (flags
[i
] & FLAG_DEFAULT
)) {
1871 if (defaults_saved
) {
1872 if (is_default(sDefault
, i
)) {
1877 if (equal_parameter(parm_table
[i
].type
,
1878 ((char *)pService
) +
1879 parm_table
[i
].offset
,
1880 ((char *)sDefault
) +
1881 parm_table
[i
].offset
))
1885 fprintf(f
, "\t%s = ", parm_table
[i
].label
);
1886 print_parameter(&parm_table
[i
],
1887 ((char *)pService
) + parm_table
[i
].offset
, f
);
1891 if (pService
->param_opt
!= NULL
) {
1892 for (data
= pService
->param_opt
; data
; data
= data
->next
) {
1893 fprintf(f
, "\t%s = %s\n", data
->key
, data
->value
);
1898 bool lpcfg_dump_a_parameter(struct loadparm_context
*lp_ctx
,
1899 struct loadparm_service
*service
,
1900 const char *parm_name
, FILE * f
)
1902 struct parm_struct
*parm
;
1905 parm
= lpcfg_parm_struct(lp_ctx
, parm_name
);
1910 ptr
= lpcfg_parm_ptr(lp_ctx
, service
,parm
);
1912 print_parameter(parm
, ptr
, f
);
1918 * Return info about the next parameter in a service.
1919 * snum==-1 gives the globals.
1920 * Return NULL when out of parameters.
1924 struct parm_struct
*lpcfg_next_parameter(struct loadparm_context
*lp_ctx
, int snum
, int *i
,
1928 /* do the globals */
1929 for (; parm_table
[*i
].label
; (*i
)++) {
1930 if ((*parm_table
[*i
].label
== '-'))
1934 && (parm_table
[*i
].offset
==
1935 parm_table
[(*i
) - 1].offset
)
1936 && (parm_table
[*i
].p_class
==
1937 parm_table
[(*i
) - 1].p_class
))
1940 return &parm_table
[(*i
)++];
1943 struct loadparm_service
*pService
= lp_ctx
->services
[snum
];
1945 for (; parm_table
[*i
].label
; (*i
)++) {
1946 if (parm_table
[*i
].p_class
== P_LOCAL
&&
1947 (*parm_table
[*i
].label
!= '-') &&
1949 (parm_table
[*i
].offset
!=
1950 parm_table
[(*i
) - 1].offset
)))
1952 if (allparameters
||
1953 !equal_parameter(parm_table
[*i
].type
,
1954 ((char *)pService
) +
1955 parm_table
[*i
].offset
,
1956 ((char *)lp_ctx
->sDefault
) +
1957 parm_table
[*i
].offset
))
1959 return &parm_table
[(*i
)++];
1970 * Auto-load some home services.
1972 static void lpcfg_add_auto_services(struct loadparm_context
*lp_ctx
,
1980 * Unload unused services.
1983 void lpcfg_killunused(struct loadparm_context
*lp_ctx
,
1984 struct smbsrv_connection
*smb
,
1985 bool (*snumused
) (struct smbsrv_connection
*, int))
1988 for (i
= 0; i
< lp_ctx
->iNumServices
; i
++) {
1989 if (lp_ctx
->services
[i
] == NULL
)
1992 if (!snumused
|| !snumused(smb
, i
)) {
1993 talloc_free(lp_ctx
->services
[i
]);
1994 lp_ctx
->services
[i
] = NULL
;
2000 static int lpcfg_destructor(struct loadparm_context
*lp_ctx
)
2002 struct parmlist_entry
*data
;
2004 if (lp_ctx
->refuse_free
) {
2005 /* someone is trying to free the
2006 global_loadparm_context.
2007 We can't allow that. */
2011 if (lp_ctx
->globals
->param_opt
!= NULL
) {
2012 struct parmlist_entry
*next
;
2013 for (data
= lp_ctx
->globals
->param_opt
; data
; data
=next
) {
2015 if (data
->priority
& FLAG_CMDLINE
) continue;
2016 DLIST_REMOVE(lp_ctx
->globals
->param_opt
, data
);
2025 * Initialise the global parameter structure.
2027 * Note that most callers should use loadparm_init_global() instead
2029 struct loadparm_context
*loadparm_init(TALLOC_CTX
*mem_ctx
)
2033 struct loadparm_context
*lp_ctx
;
2034 struct parmlist_entry
*parm
;
2037 lp_ctx
= talloc_zero(mem_ctx
, struct loadparm_context
);
2041 talloc_set_destructor(lp_ctx
, lpcfg_destructor
);
2042 lp_ctx
->bInGlobalSection
= true;
2043 lp_ctx
->globals
= talloc_zero(lp_ctx
, struct loadparm_global
);
2044 lp_ctx
->sDefault
= talloc_zero(lp_ctx
, struct loadparm_service
);
2046 lp_ctx
->sDefault
->iMaxPrintJobs
= 1000;
2047 lp_ctx
->sDefault
->bAvailable
= true;
2048 lp_ctx
->sDefault
->bBrowseable
= true;
2049 lp_ctx
->sDefault
->bRead_only
= true;
2050 lp_ctx
->sDefault
->bMap_archive
= true;
2051 lp_ctx
->sDefault
->iStrictLocking
= true;
2052 lp_ctx
->sDefault
->bOpLocks
= true;
2053 lp_ctx
->sDefault
->iCreate_mask
= 0744;
2054 lp_ctx
->sDefault
->iCreate_force_mode
= 0000;
2055 lp_ctx
->sDefault
->iDir_mask
= 0755;
2056 lp_ctx
->sDefault
->iDir_force_mode
= 0000;
2058 DEBUG(3, ("Initialising global parameters\n"));
2060 for (i
= 0; parm_table
[i
].label
; i
++) {
2061 if ((parm_table
[i
].type
== P_STRING
||
2062 parm_table
[i
].type
== P_USTRING
) &&
2063 !(lp_ctx
->flags
[i
] & FLAG_CMDLINE
)) {
2065 if (parm_table
[i
].p_class
== P_LOCAL
) {
2066 r
= (char **)(((char *)lp_ctx
->sDefault
) + parm_table
[i
].offset
);
2068 r
= (char **)(((char *)lp_ctx
->globals
) + parm_table
[i
].offset
);
2070 *r
= talloc_strdup(lp_ctx
, "");
2074 logfile
= talloc_asprintf(lp_ctx
, "%s/log.samba", dyn_LOGFILEBASE
);
2075 lpcfg_do_global_parameter(lp_ctx
, "log file", logfile
);
2076 talloc_free(logfile
);
2078 lpcfg_do_global_parameter(lp_ctx
, "log level", "0");
2080 lpcfg_do_global_parameter(lp_ctx
, "share backend", "classic");
2082 lpcfg_do_global_parameter(lp_ctx
, "server role", "auto");
2083 lpcfg_do_global_parameter(lp_ctx
, "domain logons", "No");
2084 lpcfg_do_global_parameter(lp_ctx
, "domain master", "Auto");
2086 /* options that can be set on the command line must be initialised via
2087 the slower lpcfg_do_global_parameter() to ensure that FLAG_CMDLINE is obeyed */
2089 lpcfg_do_global_parameter(lp_ctx
, "socket options", "TCP_NODELAY");
2091 lpcfg_do_global_parameter(lp_ctx
, "workgroup", DEFAULT_WORKGROUP
);
2092 myname
= get_myname(lp_ctx
);
2093 lpcfg_do_global_parameter(lp_ctx
, "netbios name", myname
);
2094 talloc_free(myname
);
2095 lpcfg_do_global_parameter(lp_ctx
, "name resolve order", "wins host bcast");
2097 lpcfg_do_global_parameter(lp_ctx
, "fstype", "NTFS");
2099 lpcfg_do_global_parameter(lp_ctx
, "ntvfs handler", "unixuid default");
2100 lpcfg_do_global_parameter(lp_ctx
, "max connections", "-1");
2102 lpcfg_do_global_parameter(lp_ctx
, "dcerpc endpoint servers", "epmapper wkssvc rpcecho samr netlogon lsarpc spoolss drsuapi dssetup unixinfo browser eventlog6 backupkey dnsserver");
2103 lpcfg_do_global_parameter(lp_ctx
, "server services", "s3fs rpc nbt wrepl ldap cldap kdc drepl winbind ntp_signd kcc dnsupdate");
2104 /* the winbind method for domain controllers is for both RODC
2105 auth forwarding and for trusted domains */
2106 lpcfg_do_global_parameter(lp_ctx
, "private dir", dyn_PRIVATE_DIR
);
2107 lpcfg_do_global_parameter(lp_ctx
, "registry:HKEY_LOCAL_MACHINE", "hklm.ldb");
2109 /* This hive should be dynamically generated by Samba using
2110 data from the sam, but for the moment leave it in a tdb to
2111 keep regedt32 from popping up an annoying dialog. */
2112 lpcfg_do_global_parameter(lp_ctx
, "registry:HKEY_USERS", "hku.ldb");
2114 /* using UTF8 by default allows us to support all chars */
2115 lpcfg_do_global_parameter(lp_ctx
, "unix charset", "UTF8");
2117 /* Use codepage 850 as a default for the dos character set */
2118 lpcfg_do_global_parameter(lp_ctx
, "dos charset", "CP850");
2121 * Allow the default PASSWD_CHAT to be overridden in local.h.
2123 lpcfg_do_global_parameter(lp_ctx
, "passwd chat", DEFAULT_PASSWD_CHAT
);
2125 lpcfg_do_global_parameter(lp_ctx
, "pid directory", dyn_PIDDIR
);
2126 lpcfg_do_global_parameter(lp_ctx
, "lock dir", dyn_LOCKDIR
);
2127 lpcfg_do_global_parameter(lp_ctx
, "state directory", dyn_STATEDIR
);
2128 lpcfg_do_global_parameter(lp_ctx
, "cache directory", dyn_CACHEDIR
);
2129 lpcfg_do_global_parameter(lp_ctx
, "ncalrpc dir", dyn_NCALRPCDIR
);
2131 lpcfg_do_global_parameter(lp_ctx
, "socket address", "");
2132 lpcfg_do_global_parameter_var(lp_ctx
, "server string",
2133 "Samba %s", SAMBA_VERSION_STRING
);
2135 lpcfg_do_global_parameter(lp_ctx
, "password server", "*");
2137 lpcfg_do_global_parameter(lp_ctx
, "max mux", "50");
2138 lpcfg_do_global_parameter(lp_ctx
, "max xmit", "12288");
2139 lpcfg_do_global_parameter(lp_ctx
, "host msdfs", "true");
2141 lpcfg_do_global_parameter(lp_ctx
, "password level", "0");
2142 lpcfg_do_global_parameter(lp_ctx
, "LargeReadwrite", "True");
2143 lpcfg_do_global_parameter(lp_ctx
, "server min protocol", "CORE");
2144 lpcfg_do_global_parameter(lp_ctx
, "server max protocol", "NT1");
2145 lpcfg_do_global_parameter(lp_ctx
, "client min protocol", "CORE");
2146 lpcfg_do_global_parameter(lp_ctx
, "client max protocol", "NT1");
2147 lpcfg_do_global_parameter(lp_ctx
, "security", "AUTO");
2148 lpcfg_do_global_parameter(lp_ctx
, "EncryptPasswords", "True");
2149 lpcfg_do_global_parameter(lp_ctx
, "ReadRaw", "True");
2150 lpcfg_do_global_parameter(lp_ctx
, "WriteRaw", "True");
2151 lpcfg_do_global_parameter(lp_ctx
, "NullPasswords", "False");
2152 lpcfg_do_global_parameter(lp_ctx
, "ObeyPamRestrictions", "False");
2154 lpcfg_do_global_parameter(lp_ctx
, "TimeServer", "False");
2155 lpcfg_do_global_parameter(lp_ctx
, "BindInterfacesOnly", "False");
2156 lpcfg_do_global_parameter(lp_ctx
, "Unicode", "True");
2157 lpcfg_do_global_parameter(lp_ctx
, "ClientLanManAuth", "False");
2158 lpcfg_do_global_parameter(lp_ctx
, "ClientNTLMv2Auth", "True");
2159 lpcfg_do_global_parameter(lp_ctx
, "LanmanAuth", "False");
2160 lpcfg_do_global_parameter(lp_ctx
, "NTLMAuth", "True");
2161 lpcfg_do_global_parameter(lp_ctx
, "client use spnego principal", "False");
2163 lpcfg_do_global_parameter(lp_ctx
, "UnixExtensions", "False");
2165 lpcfg_do_global_parameter(lp_ctx
, "PreferredMaster", "Auto");
2166 lpcfg_do_global_parameter(lp_ctx
, "LocalMaster", "True");
2168 lpcfg_do_global_parameter(lp_ctx
, "wins support", "False");
2169 lpcfg_do_global_parameter(lp_ctx
, "dns proxy", "True");
2171 lpcfg_do_global_parameter(lp_ctx
, "winbind separator", "\\");
2172 lpcfg_do_global_parameter(lp_ctx
, "winbind sealed pipes", "True");
2173 lpcfg_do_global_parameter(lp_ctx
, "winbindd socket directory", dyn_WINBINDD_SOCKET_DIR
);
2174 #if _SAMBA_BUILD_ >= 4
2175 lpcfg_do_global_parameter(lp_ctx
, "winbindd privileged socket directory", dyn_WINBINDD_PRIVILEGED_SOCKET_DIR
);
2176 lpcfg_do_global_parameter(lp_ctx
, "ntp signd socket directory", dyn_NTP_SIGND_SOCKET_DIR
);
2177 lpcfg_do_global_parameter_var(lp_ctx
, "dns update command", "%s/samba_dnsupdate", dyn_SCRIPTSBINDIR
);
2178 lpcfg_do_global_parameter_var(lp_ctx
, "spn update command", "%s/samba_spnupdate", dyn_SCRIPTSBINDIR
);
2179 lpcfg_do_global_parameter_var(lp_ctx
, "samba kcc command",
2180 "%s/samba_kcc", dyn_SCRIPTSBINDIR
);
2182 lpcfg_do_global_parameter(lp_ctx
, "template shell", "/bin/false");
2183 lpcfg_do_global_parameter(lp_ctx
, "template homedir", "/home/%WORKGROUP%/%ACCOUNTNAME%");
2185 lpcfg_do_global_parameter(lp_ctx
, "client signing", "default");
2186 lpcfg_do_global_parameter(lp_ctx
, "server signing", "default");
2188 lpcfg_do_global_parameter(lp_ctx
, "use spnego", "True");
2190 lpcfg_do_global_parameter(lp_ctx
, "use mmap", "True");
2192 lpcfg_do_global_parameter(lp_ctx
, "smb ports", "445 139");
2193 lpcfg_do_global_parameter(lp_ctx
, "nbt port", "137");
2194 lpcfg_do_global_parameter(lp_ctx
, "dgram port", "138");
2195 lpcfg_do_global_parameter(lp_ctx
, "cldap port", "389");
2196 lpcfg_do_global_parameter(lp_ctx
, "krb5 port", "88");
2197 lpcfg_do_global_parameter(lp_ctx
, "kpasswd port", "464");
2198 lpcfg_do_global_parameter(lp_ctx
, "web port", "901");
2200 lpcfg_do_global_parameter(lp_ctx
, "nt status support", "True");
2202 lpcfg_do_global_parameter(lp_ctx
, "max wins ttl", "518400"); /* 6 days */
2203 lpcfg_do_global_parameter(lp_ctx
, "min wins ttl", "10");
2205 lpcfg_do_global_parameter(lp_ctx
, "tls enabled", "True");
2206 lpcfg_do_global_parameter(lp_ctx
, "tls keyfile", "tls/key.pem");
2207 lpcfg_do_global_parameter(lp_ctx
, "tls certfile", "tls/cert.pem");
2208 lpcfg_do_global_parameter(lp_ctx
, "tls cafile", "tls/ca.pem");
2209 lpcfg_do_global_parameter(lp_ctx
, "prefork children:smb", "4");
2211 lpcfg_do_global_parameter(lp_ctx
, "rndc command", "/usr/sbin/rndc");
2212 lpcfg_do_global_parameter(lp_ctx
, "nsupdate command", "/usr/bin/nsupdate -g");
2214 lpcfg_do_global_parameter(lp_ctx
, "allow dns updates", "False");
2215 lpcfg_do_global_parameter(lp_ctx
, "dns recursive queries", "False");
2216 lpcfg_do_global_parameter(lp_ctx
, "dns forwarder", "");
2218 for (i
= 0; parm_table
[i
].label
; i
++) {
2219 if (!(lp_ctx
->flags
[i
] & FLAG_CMDLINE
)) {
2220 lp_ctx
->flags
[i
] |= FLAG_DEFAULT
;
2224 for (parm
=lp_ctx
->globals
->param_opt
; parm
; parm
=parm
->next
) {
2225 if (!(parm
->priority
& FLAG_CMDLINE
)) {
2226 parm
->priority
|= FLAG_DEFAULT
;
2234 * Initialise the global parameter structure.
2236 struct loadparm_context
*loadparm_init_global(bool load_default
)
2238 if (global_loadparm_context
== NULL
) {
2239 global_loadparm_context
= loadparm_init(NULL
);
2241 if (global_loadparm_context
== NULL
) {
2244 global_loadparm_context
->global
= true;
2245 if (load_default
&& !global_loadparm_context
->loaded
) {
2246 lpcfg_load_default(global_loadparm_context
);
2248 global_loadparm_context
->refuse_free
= true;
2249 return global_loadparm_context
;
2253 * Initialise the global parameter structure.
2255 struct loadparm_context
*loadparm_init_s3(TALLOC_CTX
*mem_ctx
,
2256 const struct loadparm_s3_helpers
*s3_fns
)
2258 struct loadparm_context
*loadparm_context
= talloc_zero(mem_ctx
, struct loadparm_context
);
2259 if (!loadparm_context
) {
2262 loadparm_context
->s3_fns
= s3_fns
;
2263 return loadparm_context
;
2266 const char *lpcfg_configfile(struct loadparm_context
*lp_ctx
)
2268 return lp_ctx
->szConfigFile
;
2271 const char *lp_default_path(void)
2273 if (getenv("SMB_CONF_PATH"))
2274 return getenv("SMB_CONF_PATH");
2276 return dyn_CONFIGFILE
;
2280 * Update the internal state of a loadparm context after settings
2283 static bool lpcfg_update(struct loadparm_context
*lp_ctx
)
2285 struct debug_settings settings
;
2286 lpcfg_add_auto_services(lp_ctx
, lpcfg_auto_services(lp_ctx
));
2288 if (!lp_ctx
->globals
->szWINSservers
&& lp_ctx
->globals
->bWINSsupport
) {
2289 lpcfg_do_global_parameter(lp_ctx
, "wins server", "127.0.0.1");
2292 if (!lp_ctx
->global
) {
2296 panic_action
= lp_ctx
->globals
->panic_action
;
2298 reload_charcnv(lp_ctx
);
2300 ZERO_STRUCT(settings
);
2301 /* Add any more debug-related smb.conf parameters created in
2303 settings
.timestamp_logs
= true;
2304 debug_set_settings(&settings
);
2306 /* FIXME: This is a bit of a hack, but we can't use a global, since
2307 * not everything that uses lp also uses the socket library */
2308 if (lpcfg_parm_bool(lp_ctx
, NULL
, "socket", "testnonblock", false)) {
2309 setenv("SOCKET_TESTNONBLOCK", "1", 1);
2311 unsetenv("SOCKET_TESTNONBLOCK");
2317 bool lpcfg_load_default(struct loadparm_context
*lp_ctx
)
2321 path
= lp_default_path();
2323 if (!file_exist(path
)) {
2324 /* We allow the default smb.conf file to not exist,
2325 * basically the equivalent of an empty file. */
2326 return lpcfg_update(lp_ctx
);
2329 return lpcfg_load(lp_ctx
, path
);
2333 * Load the services array from the services file.
2335 * Return True on success, False on failure.
2337 bool lpcfg_load(struct loadparm_context
*lp_ctx
, const char *filename
)
2342 filename
= talloc_strdup(lp_ctx
, filename
);
2344 lp_ctx
->szConfigFile
= filename
;
2346 if (lp_ctx
->s3_fns
) {
2347 return lp_ctx
->s3_fns
->load(filename
);
2350 lp_ctx
->bInGlobalSection
= true;
2351 n2
= standard_sub_basic(lp_ctx
, lp_ctx
->szConfigFile
);
2352 DEBUG(2, ("lpcfg_load: refreshing parameters from %s\n", n2
));
2354 add_to_file_list(lp_ctx
, lp_ctx
->szConfigFile
, n2
);
2356 /* We get sections first, so have to start 'behind' to make up */
2357 lp_ctx
->currentService
= NULL
;
2358 bRetval
= pm_process(n2
, do_section
, do_parameter
, lp_ctx
);
2360 /* finish up the last section */
2361 DEBUG(4, ("pm_process() returned %s\n", BOOLSTR(bRetval
)));
2363 if (lp_ctx
->currentService
!= NULL
)
2364 bRetval
= lpcfg_service_ok(lp_ctx
->currentService
);
2366 bRetval
= bRetval
&& lpcfg_update(lp_ctx
);
2368 /* we do this unconditionally, so that it happens even
2369 for a missing smb.conf */
2370 reload_charcnv(lp_ctx
);
2372 if (bRetval
== true) {
2373 /* set this up so that any child python tasks will
2374 find the right smb.conf */
2375 setenv("SMB_CONF_PATH", filename
, 1);
2377 /* set the context used by the lp_*() function
2379 global_loadparm_context
= lp_ctx
;
2380 lp_ctx
->loaded
= true;
2387 * Return the max number of services.
2390 int lpcfg_numservices(struct loadparm_context
*lp_ctx
)
2392 if (lp_ctx
->s3_fns
) {
2393 return lp_ctx
->s3_fns
->get_numservices();
2396 return lp_ctx
->iNumServices
;
2400 * Display the contents of the services array in human-readable form.
2403 void lpcfg_dump(struct loadparm_context
*lp_ctx
, FILE *f
, bool show_defaults
,
2408 if (lp_ctx
->s3_fns
) {
2409 lp_ctx
->s3_fns
->dump(f
, show_defaults
, maxtoprint
);
2413 defaults_saved
= !show_defaults
;
2415 dump_globals(lp_ctx
, f
, show_defaults
);
2417 dump_a_service(lp_ctx
->sDefault
, lp_ctx
->sDefault
, f
, lp_ctx
->flags
);
2419 for (iService
= 0; iService
< maxtoprint
; iService
++)
2420 lpcfg_dump_one(f
, show_defaults
, lp_ctx
->services
[iService
], lp_ctx
->sDefault
);
2424 * Display the contents of one service in human-readable form.
2426 void lpcfg_dump_one(FILE *f
, bool show_defaults
, struct loadparm_service
*service
, struct loadparm_service
*sDefault
)
2428 if (service
!= NULL
) {
2429 if (service
->szService
[0] == '\0')
2431 dump_a_service(service
, sDefault
, f
, NULL
);
2435 struct loadparm_service
*lpcfg_servicebynum(struct loadparm_context
*lp_ctx
,
2438 if (lp_ctx
->s3_fns
) {
2439 return lp_ctx
->s3_fns
->get_servicebynum(snum
);
2442 return lp_ctx
->services
[snum
];
2445 struct loadparm_service
*lpcfg_service(struct loadparm_context
*lp_ctx
,
2446 const char *service_name
)
2451 if (lp_ctx
->s3_fns
) {
2452 return lp_ctx
->s3_fns
->get_service(service_name
);
2455 for (iService
= lp_ctx
->iNumServices
- 1; iService
>= 0; iService
--) {
2456 if (lp_ctx
->services
[iService
] &&
2457 lp_ctx
->services
[iService
]->szService
) {
2459 * The substitution here is used to support %U is
2462 serviceName
= standard_sub_basic(
2463 lp_ctx
->services
[iService
],
2464 lp_ctx
->services
[iService
]->szService
);
2465 if (strequal(serviceName
, service_name
)) {
2466 talloc_free(serviceName
);
2467 return lp_ctx
->services
[iService
];
2469 talloc_free(serviceName
);
2473 DEBUG(7,("lpcfg_servicenumber: couldn't find %s\n", service_name
));
2477 const char *lpcfg_servicename(const struct loadparm_service
*service
)
2479 return lp_string((const char *)service
->szService
);
2483 * A useful volume label function.
2485 const char *lpcfg_volume_label(struct loadparm_service
*service
, struct loadparm_service
*sDefault
)
2488 ret
= lp_string((const char *)((service
!= NULL
&& service
->volume
!= NULL
) ?
2489 service
->volume
: sDefault
->volume
));
2491 return lpcfg_servicename(service
);
2496 * If we are PDC then prefer us as DMB
2498 const char *lpcfg_printername(struct loadparm_service
*service
, struct loadparm_service
*sDefault
)
2501 ret
= lp_string((const char *)((service
!= NULL
&& service
->szPrintername
!= NULL
) ?
2502 service
->szPrintername
: sDefault
->szPrintername
));
2503 if (ret
== NULL
|| (ret
!= NULL
&& *ret
== '\0'))
2504 ret
= lpcfg_servicename(service
);
2511 * Return the max print jobs per queue.
2513 int lpcfg_maxprintjobs(struct loadparm_service
*service
, struct loadparm_service
*sDefault
)
2515 int maxjobs
= (service
!= NULL
) ? service
->iMaxPrintJobs
: sDefault
->iMaxPrintJobs
;
2516 if (maxjobs
<= 0 || maxjobs
>= PRINT_MAX_JOBID
)
2517 maxjobs
= PRINT_MAX_JOBID
- 1;
2522 struct smb_iconv_handle
*lpcfg_iconv_handle(struct loadparm_context
*lp_ctx
)
2524 if (lp_ctx
== NULL
) {
2525 return get_iconv_handle();
2527 return lp_ctx
->iconv_handle
;
2530 _PUBLIC_
void reload_charcnv(struct loadparm_context
*lp_ctx
)
2532 struct smb_iconv_handle
*old_ic
= lp_ctx
->iconv_handle
;
2533 if (!lp_ctx
->global
) {
2537 if (old_ic
== NULL
) {
2538 old_ic
= global_iconv_handle
;
2540 lp_ctx
->iconv_handle
= smb_iconv_handle_reinit_lp(lp_ctx
, lp_ctx
, old_ic
);
2541 global_iconv_handle
= lp_ctx
->iconv_handle
;
2544 _PUBLIC_
char *lpcfg_tls_keyfile(TALLOC_CTX
*mem_ctx
, struct loadparm_context
*lp_ctx
)
2546 return lpcfg_private_path(mem_ctx
, lp_ctx
, lp_ctx
->globals
->tls_keyfile
);
2549 _PUBLIC_
char *lpcfg_tls_certfile(TALLOC_CTX
*mem_ctx
, struct loadparm_context
*lp_ctx
)
2551 return lpcfg_private_path(mem_ctx
, lp_ctx
, lp_ctx
->globals
->tls_certfile
);
2554 _PUBLIC_
char *lpcfg_tls_cafile(TALLOC_CTX
*mem_ctx
, struct loadparm_context
*lp_ctx
)
2556 return lpcfg_private_path(mem_ctx
, lp_ctx
, lp_ctx
->globals
->tls_cafile
);
2559 _PUBLIC_
char *lpcfg_tls_crlfile(TALLOC_CTX
*mem_ctx
, struct loadparm_context
*lp_ctx
)
2561 return lpcfg_private_path(mem_ctx
, lp_ctx
, lp_ctx
->globals
->tls_crlfile
);
2564 _PUBLIC_
char *lpcfg_tls_dhpfile(TALLOC_CTX
*mem_ctx
, struct loadparm_context
*lp_ctx
)
2566 return lpcfg_private_path(mem_ctx
, lp_ctx
, lp_ctx
->globals
->tls_dhpfile
);
2569 struct gensec_settings
*lpcfg_gensec_settings(TALLOC_CTX
*mem_ctx
, struct loadparm_context
*lp_ctx
)
2571 struct gensec_settings
*settings
= talloc_zero(mem_ctx
, struct gensec_settings
);
2572 if (settings
== NULL
)
2574 SMB_ASSERT(lp_ctx
!= NULL
);
2575 settings
->lp_ctx
= talloc_reference(settings
, lp_ctx
);
2576 settings
->target_hostname
= lpcfg_parm_string(lp_ctx
, NULL
, "gensec", "target_hostname");
2580 int lpcfg_server_role(struct loadparm_context
*lp_ctx
)
2582 int domain_master
= lpcfg__domain_master(lp_ctx
);
2584 return lp_find_server_role(lpcfg__server_role(lp_ctx
),
2585 lpcfg__security(lp_ctx
),
2586 lpcfg__domain_logons(lp_ctx
),
2587 (domain_master
== true) ||
2588 (domain_master
== Auto
));
2591 int lpcfg_security(struct loadparm_context
*lp_ctx
)
2593 return lp_find_security(lpcfg__server_role(lp_ctx
),
2594 lpcfg__security(lp_ctx
));