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(socket_address, szSocketAddress)
332 FN_GLOBAL_STRING(statedir, szStateDir)
334 /* local prototypes */
335 static int map_parameter(const char *pszParmName);
336 static struct loadparm_service *getservicebyname(struct loadparm_context *lp_ctx,
337 const char *pszServiceName);
338 static void copy_service(struct loadparm_service *pserviceDest,
339 struct loadparm_service *pserviceSource,
340 struct bitmap *pcopymapDest);
341 static bool lpcfg_service_ok(struct loadparm_service *service);
342 static bool do_section(const char *pszSectionName, void *);
343 static void init_copymap(struct loadparm_service *pservice);
345 /* This is a helper function for parametrical options support. */
346 /* It returns a pointer to parametrical option value if it exists or NULL otherwise */
347 /* Actual parametrical functions are quite simple */
348 const char *lpcfg_get_parametric(struct loadparm_context *lp_ctx,
349 struct loadparm_service *service,
350 const char *type, const char *option)
352 char *vfskey_tmp = NULL;
354 struct parmlist_entry *data;
359 if (lp_ctx->s3_fns) {
360 return lp_ctx->s3_fns->get_parametric(service, type, option);
363 data = (service == NULL ? lp_ctx->globals->param_opt : service->param_opt);
365 vfskey_tmp = talloc_asprintf(NULL, "%s:%s", type, option);
366 if (vfskey_tmp == NULL) return NULL;
367 vfskey = strlower_talloc(NULL, vfskey_tmp);
368 talloc_free(vfskey_tmp);
371 if (strcmp(data->key, vfskey) == 0) {
378 if (service != NULL) {
379 /* Try to fetch the same option but from globals */
380 /* but only if we are not already working with globals */
381 for (data = lp_ctx->globals->param_opt; data;
383 if (strcmp(data->key, vfskey) == 0) {
397 * convenience routine to return int parameters.
399 static int lp_int(const char *s)
403 DEBUG(0,("lp_int(%s): is called with NULL!\n",s));
407 return strtol(s, NULL, 0);
411 * convenience routine to return unsigned long parameters.
413 static unsigned long lp_ulong(const char *s)
417 DEBUG(0,("lp_ulong(%s): is called with NULL!\n",s));
421 return strtoul(s, NULL, 0);
425 * convenience routine to return unsigned long parameters.
427 static long lp_long(const char *s)
431 DEBUG(0,("lp_long(%s): is called with NULL!\n",s));
435 return strtol(s, NULL, 0);
439 * convenience routine to return unsigned long parameters.
441 static double lp_double(const char *s)
445 DEBUG(0,("lp_double(%s): is called with NULL!\n",s));
449 return strtod(s, NULL);
453 * convenience routine to return boolean parameters.
455 static bool lp_bool(const char *s)
460 DEBUG(0,("lp_bool(%s): is called with NULL!\n",s));
464 if (!set_boolean(s, &ret)) {
465 DEBUG(0,("lp_bool(%s): value is not boolean!\n",s));
474 * Return parametric option from a given service. Type is a part of option before ':'
475 * Parametric option has following syntax: 'Type: option = value'
476 * Returned value is allocated in 'lp_talloc' context
479 const char *lpcfg_parm_string(struct loadparm_context *lp_ctx,
480 struct loadparm_service *service, const char *type,
483 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
486 return lp_string(value);
492 * Return parametric option from a given service. Type is a part of option before ':'
493 * Parametric option has following syntax: 'Type: option = value'
494 * Returned value is allocated in 'lp_talloc' context
497 const char **lpcfg_parm_string_list(TALLOC_CTX *mem_ctx,
498 struct loadparm_context *lp_ctx,
499 struct loadparm_service *service,
501 const char *option, const char *separator)
503 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
506 return (const char **)str_list_make(mem_ctx, value, separator);
512 * Return parametric option from a given service. Type is a part of option before ':'
513 * Parametric option has following syntax: 'Type: option = value'
516 int lpcfg_parm_int(struct loadparm_context *lp_ctx,
517 struct loadparm_service *service, const char *type,
518 const char *option, int default_v)
520 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
523 return lp_int(value);
529 * Return parametric option from a given service. Type is a part of
531 * Parametric option has following syntax: 'Type: option = value'.
534 int lpcfg_parm_bytes(struct loadparm_context *lp_ctx,
535 struct loadparm_service *service, const char *type,
536 const char *option, int default_v)
540 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
542 if (value && conv_str_size_error(value, &bval)) {
543 if (bval <= INT_MAX) {
552 * Return parametric option from a given service.
553 * Type is a part of option before ':'
554 * Parametric option has following syntax: 'Type: option = value'
556 unsigned long lpcfg_parm_ulong(struct loadparm_context *lp_ctx,
557 struct loadparm_service *service, const char *type,
558 const char *option, unsigned long default_v)
560 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
563 return lp_ulong(value);
568 long lpcfg_parm_long(struct loadparm_context *lp_ctx,
569 struct loadparm_service *service, const char *type,
570 const char *option, long default_v)
572 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
575 return lp_long(value);
580 double lpcfg_parm_double(struct loadparm_context *lp_ctx,
581 struct loadparm_service *service, const char *type,
582 const char *option, double default_v)
584 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
587 return lp_double(value);
593 * Return parametric option from a given service. Type is a part of option before ':'
594 * Parametric option has following syntax: 'Type: option = value'
597 bool lpcfg_parm_bool(struct loadparm_context *lp_ctx,
598 struct loadparm_service *service, const char *type,
599 const char *option, bool default_v)
601 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
604 return lp_bool(value);
611 * Initialise a service to the defaults.
614 static struct loadparm_service *init_service(TALLOC_CTX *mem_ctx, struct loadparm_service *sDefault)
616 struct loadparm_service *pservice =
617 talloc_zero(mem_ctx, struct loadparm_service);
618 copy_service(pservice, sDefault, NULL);
623 * Set a string value, deallocating any existing space, and allocing the space
626 static bool lpcfg_string_set(TALLOC_CTX *mem_ctx, char **dest, const char *src)
633 *dest = talloc_strdup(mem_ctx, src);
634 if ((*dest) == NULL) {
635 DEBUG(0,("Out of memory in string_set\n"));
643 * Set a string value, deallocating any existing space, and allocing the space
646 static bool lpcfg_string_set_upper(TALLOC_CTX *mem_ctx, char **dest, const char *src)
653 *dest = strupper_talloc(mem_ctx, src);
654 if ((*dest) == NULL) {
655 DEBUG(0,("Out of memory in string_set_upper\n"));
665 * Add a new service to the services array initialising it with the given
669 struct loadparm_service *lpcfg_add_service(struct loadparm_context *lp_ctx,
670 const struct loadparm_service *pservice,
674 struct loadparm_service tservice;
675 int num_to_alloc = lp_ctx->iNumServices + 1;
676 struct parmlist_entry *data, *pdata;
678 if (pservice == NULL) {
679 pservice = lp_ctx->sDefault;
682 tservice = *pservice;
684 /* it might already exist */
686 struct loadparm_service *service = getservicebyname(lp_ctx,
688 if (service != NULL) {
689 /* Clean all parametric options for service */
690 /* They will be added during parsing again */
691 data = service->param_opt;
697 service->param_opt = NULL;
702 /* find an invalid one */
703 for (i = 0; i < lp_ctx->iNumServices; i++)
704 if (lp_ctx->services[i] == NULL)
707 /* if not, then create one */
708 if (i == lp_ctx->iNumServices) {
709 struct loadparm_service **tsp;
711 tsp = talloc_realloc(lp_ctx, lp_ctx->services, struct loadparm_service *, num_to_alloc);
714 DEBUG(0,("lpcfg_add_service: failed to enlarge services!\n"));
717 lp_ctx->services = tsp;
718 lp_ctx->services[lp_ctx->iNumServices] = NULL;
721 lp_ctx->iNumServices++;
724 lp_ctx->services[i] = init_service(lp_ctx->services, lp_ctx->sDefault);
725 if (lp_ctx->services[i] == NULL) {
726 DEBUG(0,("lpcfg_add_service: out of memory!\n"));
729 copy_service(lp_ctx->services[i], &tservice, NULL);
731 lpcfg_string_set(lp_ctx->services[i], &lp_ctx->services[i]->szService, name);
732 return lp_ctx->services[i];
736 * Add a new home service, with the specified home directory, defaults coming
737 * from service ifrom.
740 bool lpcfg_add_home(struct loadparm_context *lp_ctx,
741 const char *pszHomename,
742 struct loadparm_service *default_service,
743 const char *user, const char *pszHomedir)
745 struct loadparm_service *service;
747 service = lpcfg_add_service(lp_ctx, default_service, pszHomename);
752 if (!(*(default_service->szPath))
753 || strequal(default_service->szPath, lp_ctx->sDefault->szPath)) {
754 service->szPath = talloc_strdup(service, pszHomedir);
756 service->szPath = string_sub_talloc(service, lpcfg_pathname(default_service, lp_ctx->sDefault), "%H", pszHomedir);
759 if (!(*(service->comment))) {
760 service->comment = talloc_asprintf(service, "Home directory of %s", user);
762 service->bAvailable = default_service->bAvailable;
763 service->bBrowseable = default_service->bBrowseable;
765 DEBUG(3, ("adding home's share [%s] for user '%s' at '%s'\n",
766 pszHomename, user, service->szPath));
772 * Add a new printer service, with defaults coming from service iFrom.
775 bool lpcfg_add_printer(struct loadparm_context *lp_ctx,
776 const char *pszPrintername,
777 struct loadparm_service *default_service)
779 const char *comment = "From Printcap";
780 struct loadparm_service *service;
781 service = lpcfg_add_service(lp_ctx, default_service, pszPrintername);
786 /* note that we do NOT default the availability flag to True - */
787 /* we take it from the default service passed. This allows all */
788 /* dynamic printers to be disabled by disabling the [printers] */
789 /* entry (if/when the 'available' keyword is implemented!). */
791 /* the printer name is set to the service name. */
792 lpcfg_string_set(service, &service->szPrintername, pszPrintername);
793 lpcfg_string_set(service, &service->comment, comment);
794 service->bBrowseable = default_service->bBrowseable;
795 /* Printers cannot be read_only. */
796 service->bRead_only = false;
797 /* Printer services must be printable. */
798 service->bPrint_ok = true;
800 DEBUG(3, ("adding printer service %s\n", pszPrintername));
806 * Map a parameter's string representation to something we can use.
807 * Returns False if the parameter string is not recognised, else TRUE.
810 static int map_parameter(const char *pszParmName)
814 if (*pszParmName == '-')
817 for (iIndex = 0; parm_table[iIndex].label; iIndex++)
818 if (strwicmp(parm_table[iIndex].label, pszParmName) == 0)
821 /* Warn only if it isn't parametric option */
822 if (strchr(pszParmName, ':') == NULL)
823 DEBUG(0, ("Unknown parameter encountered: \"%s\"\n", pszParmName));
824 /* We do return 'fail' for parametric options as well because they are
825 stored in different storage
832 return the parameter structure for a parameter
834 struct parm_struct *lpcfg_parm_struct(struct loadparm_context *lp_ctx, const char *name)
838 if (lp_ctx->s3_fns) {
839 return lp_ctx->s3_fns->get_parm_struct(name);
842 parmnum = map_parameter(name);
843 if (parmnum == -1) return NULL;
844 return &parm_table[parmnum];
848 return the parameter pointer for a parameter
850 void *lpcfg_parm_ptr(struct loadparm_context *lp_ctx,
851 struct loadparm_service *service, struct parm_struct *parm)
853 if (lp_ctx->s3_fns) {
854 return lp_ctx->s3_fns->get_parm_ptr(service, parm);
857 if (service == NULL) {
858 if (parm->p_class == P_LOCAL)
859 return ((char *)lp_ctx->sDefault)+parm->offset;
860 else if (parm->p_class == P_GLOBAL)
861 return ((char *)lp_ctx->globals)+parm->offset;
864 return ((char *)service) + parm->offset;
869 return the parameter pointer for a parameter
871 bool lpcfg_parm_is_cmdline(struct loadparm_context *lp_ctx, const char *name)
875 if (lp_ctx->s3_fns) {
876 struct parm_struct *parm = lp_ctx->s3_fns->get_parm_struct(name);
878 return parm->flags & FLAG_CMDLINE;
883 parmnum = map_parameter(name);
884 if (parmnum == -1) return false;
886 return lp_ctx->flags[parmnum] & FLAG_CMDLINE;
890 * Find a service by name. Otherwise works like get_service.
893 static struct loadparm_service *getservicebyname(struct loadparm_context *lp_ctx,
894 const char *pszServiceName)
898 if (lp_ctx->s3_fns) {
899 return lp_ctx->s3_fns->get_service(pszServiceName);
902 for (iService = lp_ctx->iNumServices - 1; iService >= 0; iService--)
903 if (lp_ctx->services[iService] != NULL &&
904 strwicmp(lp_ctx->services[iService]->szService, pszServiceName) == 0) {
905 return lp_ctx->services[iService];
912 * Copy a service structure to another.
913 * If pcopymapDest is NULL then copy all fields
916 static void copy_service(struct loadparm_service *pserviceDest,
917 struct loadparm_service *pserviceSource,
918 struct bitmap *pcopymapDest)
921 bool bcopyall = (pcopymapDest == NULL);
922 struct parmlist_entry *data, *pdata, *paramo;
925 for (i = 0; parm_table[i].label; i++)
926 if (parm_table[i].p_class == P_LOCAL &&
927 (bcopyall || bitmap_query(pcopymapDest, i))) {
929 ((char *)pserviceSource) + parm_table[i].offset;
931 ((char *)pserviceDest) + parm_table[i].offset;
933 switch (parm_table[i].type) {
935 *(bool *)dest_ptr = *(bool *)src_ptr;
942 *(int *)dest_ptr = *(int *)src_ptr;
946 lpcfg_string_set(pserviceDest,
952 lpcfg_string_set_upper(pserviceDest,
957 *(const char ***)dest_ptr = (const char **)str_list_copy(pserviceDest,
958 *(const char ***)src_ptr);
966 init_copymap(pserviceDest);
967 if (pserviceSource->copymap)
968 bitmap_copy(pserviceDest->copymap,
969 pserviceSource->copymap);
972 data = pserviceSource->param_opt;
975 pdata = pserviceDest->param_opt;
976 /* Traverse destination */
978 /* If we already have same option, override it */
979 if (strcmp(pdata->key, data->key) == 0) {
980 talloc_free(pdata->value);
981 pdata->value = talloc_strdup(pdata,
989 paramo = talloc_zero(pserviceDest, struct parmlist_entry);
992 paramo->key = talloc_strdup(paramo, data->key);
993 paramo->value = talloc_strdup(paramo, data->value);
994 DLIST_ADD(pserviceDest->param_opt, paramo);
1001 * Check a service for consistency. Return False if the service is in any way
1002 * incomplete or faulty, else True.
1004 static bool lpcfg_service_ok(struct loadparm_service *service)
1009 if (service->szService[0] == '\0') {
1010 DEBUG(0, ("The following message indicates an internal error:\n"));
1011 DEBUG(0, ("No service name in service entry.\n"));
1015 /* The [printers] entry MUST be printable. I'm all for flexibility, but */
1016 /* I can't see why you'd want a non-printable printer service... */
1017 if (strwicmp(service->szService, PRINTERS_NAME) == 0) {
1018 if (!service->bPrint_ok) {
1019 DEBUG(0, ("WARNING: [%s] service MUST be printable!\n",
1020 service->szService));
1021 service->bPrint_ok = true;
1023 /* [printers] service must also be non-browsable. */
1024 if (service->bBrowseable)
1025 service->bBrowseable = false;
1028 /* If a service is flagged unavailable, log the fact at level 0. */
1029 if (!service->bAvailable)
1030 DEBUG(1, ("NOTE: Service %s is flagged unavailable.\n",
1031 service->szService));
1037 /*******************************************************************
1038 Keep a linked list of all config files so we know when one has changed
1039 it's date and needs to be reloaded.
1040 ********************************************************************/
1042 static void add_to_file_list(struct loadparm_context *lp_ctx,
1043 const char *fname, const char *subfname)
1045 struct file_lists *f = lp_ctx->file_lists;
1048 if (f->name && !strcmp(f->name, fname))
1054 f = talloc(lp_ctx, struct file_lists);
1057 f->next = lp_ctx->file_lists;
1058 f->name = talloc_strdup(f, fname);
1063 f->subfname = talloc_strdup(f, subfname);
1068 lp_ctx->file_lists = f;
1069 f->modtime = file_modtime(subfname);
1071 time_t t = file_modtime(subfname);
1077 /*******************************************************************
1078 Check if a config file has changed date.
1079 ********************************************************************/
1080 bool lpcfg_file_list_changed(struct loadparm_context *lp_ctx)
1082 struct file_lists *f;
1083 DEBUG(6, ("lp_file_list_changed()\n"));
1085 for (f = lp_ctx->file_lists; f != NULL; f = f->next) {
1089 n2 = standard_sub_basic(lp_ctx, f->name);
1091 DEBUGADD(6, ("file %s -> %s last mod_time: %s\n",
1092 f->name, n2, ctime(&f->modtime)));
1094 mod_time = file_modtime(n2);
1096 if (mod_time && ((f->modtime != mod_time) || (f->subfname == NULL) || (strcmp(n2, f->subfname) != 0))) {
1097 DEBUGADD(6, ("file %s modified: %s\n", n2,
1099 f->modtime = mod_time;
1100 talloc_free(f->subfname);
1101 f->subfname = talloc_strdup(f, n2);
1108 /***************************************************************************
1109 Handle the "realm" parameter
1110 ***************************************************************************/
1112 static bool handle_realm(struct loadparm_context *lp_ctx, int unused,
1113 const char *pszParmValue, char **ptr)
1115 lpcfg_string_set(lp_ctx, ptr, pszParmValue);
1117 talloc_free(lp_ctx->globals->szRealm_upper);
1118 talloc_free(lp_ctx->globals->szRealm_lower);
1120 lp_ctx->globals->szRealm_upper = strupper_talloc(lp_ctx, pszParmValue);
1121 lp_ctx->globals->szRealm_lower = strlower_talloc(lp_ctx, pszParmValue);
1126 /***************************************************************************
1127 Handle the include operation.
1128 ***************************************************************************/
1130 static bool handle_include(struct loadparm_context *lp_ctx, int unused,
1131 const char *pszParmValue, char **ptr)
1133 char *fname = standard_sub_basic(lp_ctx, pszParmValue);
1135 add_to_file_list(lp_ctx, pszParmValue, fname);
1137 lpcfg_string_set(lp_ctx, ptr, fname);
1139 if (file_exist(fname))
1140 return pm_process(fname, do_section, do_parameter, lp_ctx);
1142 DEBUG(2, ("Can't find include file %s\n", fname));
1147 /***************************************************************************
1148 Handle the interpretation of the copy parameter.
1149 ***************************************************************************/
1151 static bool handle_copy(struct loadparm_context *lp_ctx, int unused,
1152 const char *pszParmValue, char **ptr)
1155 struct loadparm_service *serviceTemp;
1157 lpcfg_string_set(lp_ctx, ptr, pszParmValue);
1161 DEBUG(3, ("Copying service from service %s\n", pszParmValue));
1163 if ((serviceTemp = getservicebyname(lp_ctx, pszParmValue)) != NULL) {
1164 if (serviceTemp == lp_ctx->currentService) {
1165 DEBUG(0, ("Can't copy service %s - unable to copy self!\n", pszParmValue));
1167 copy_service(lp_ctx->currentService,
1169 lp_ctx->currentService->copymap);
1173 DEBUG(0, ("Unable to copy service - source not found: %s\n",
1181 static bool handle_debug_list(struct loadparm_context *lp_ctx, int unused,
1182 const char *pszParmValue, char **ptr)
1185 lpcfg_string_set(lp_ctx, ptr, pszParmValue);
1186 if (lp_ctx->global) {
1187 return debug_parse_levels(pszParmValue);
1192 static bool handle_logfile(struct loadparm_context *lp_ctx, int unused,
1193 const char *pszParmValue, char **ptr)
1195 debug_set_logfile(pszParmValue);
1196 if (lp_ctx->global) {
1197 lpcfg_string_set(lp_ctx, ptr, pszParmValue);
1202 /***************************************************************************
1203 Initialise a copymap.
1204 ***************************************************************************/
1206 static void init_copymap(struct loadparm_service *pservice)
1210 TALLOC_FREE(pservice->copymap);
1212 pservice->copymap = bitmap_talloc(NULL, NUMPARAMETERS);
1213 if (!pservice->copymap)
1215 ("Couldn't allocate copymap!! (size %d)\n",
1216 (int)NUMPARAMETERS));
1218 for (i = 0; i < NUMPARAMETERS; i++)
1219 bitmap_set(pservice->copymap, i);
1223 * Process a parametric option
1225 static bool lp_do_parameter_parametric(struct loadparm_context *lp_ctx,
1226 struct loadparm_service *service,
1227 const char *pszParmName,
1228 const char *pszParmValue, int flags)
1230 struct parmlist_entry *paramo, *data;
1232 TALLOC_CTX *mem_ctx;
1234 while (isspace((unsigned char)*pszParmName)) {
1238 name = strlower_talloc(lp_ctx, pszParmName);
1239 if (!name) return false;
1241 if (service == NULL) {
1242 data = lp_ctx->globals->param_opt;
1243 mem_ctx = lp_ctx->globals;
1245 data = service->param_opt;
1249 /* Traverse destination */
1250 for (paramo=data; paramo; paramo=paramo->next) {
1251 /* If we already have the option set, override it unless
1252 it was a command line option and the new one isn't */
1253 if (strcmp(paramo->key, name) == 0) {
1254 if ((paramo->priority & FLAG_CMDLINE) &&
1255 !(flags & FLAG_CMDLINE)) {
1260 talloc_free(paramo->value);
1261 paramo->value = talloc_strdup(paramo, pszParmValue);
1262 paramo->priority = flags;
1268 paramo = talloc_zero(mem_ctx, struct parmlist_entry);
1271 paramo->key = talloc_strdup(paramo, name);
1272 paramo->value = talloc_strdup(paramo, pszParmValue);
1273 paramo->priority = flags;
1274 if (service == NULL) {
1275 DLIST_ADD(lp_ctx->globals->param_opt, paramo);
1277 DLIST_ADD(service->param_opt, paramo);
1285 static bool set_variable(TALLOC_CTX *mem_ctx, int parmnum, void *parm_ptr,
1286 const char *pszParmName, const char *pszParmValue,
1287 struct loadparm_context *lp_ctx, bool on_globals)
1290 /* if it is a special case then go ahead */
1291 if (parm_table[parmnum].special) {
1293 ret = parm_table[parmnum].special(lp_ctx, -1, pszParmValue,
1298 goto mark_non_default;
1301 /* now switch on the type of variable it is */
1302 switch (parm_table[parmnum].type)
1306 if (!set_boolean(pszParmValue, &b)) {
1307 DEBUG(0,("lp_do_parameter(%s): value is not boolean!\n", pszParmValue));
1310 *(bool *)parm_ptr = b;
1316 if (!set_boolean(pszParmValue, &b)) {
1317 DEBUG(0,("lp_do_parameter(%s): value is not boolean!\n", pszParmValue));
1320 *(bool *)parm_ptr = !b;
1325 *(int *)parm_ptr = atoi(pszParmValue);
1329 *(char *)parm_ptr = *pszParmValue;
1333 *(int *)parm_ptr = strtol(pszParmValue, NULL, 8);
1339 if (conv_str_size_error(pszParmValue, &val)) {
1340 if (val <= INT_MAX) {
1341 *(int *)parm_ptr = (int)val;
1346 DEBUG(0,("lp_do_parameter(%s): value is not "
1347 "a valid size specifier!\n", pszParmValue));
1352 *(const char ***)parm_ptr = (const char **)str_list_make(mem_ctx,
1353 pszParmValue, NULL);
1357 char **new_list = str_list_make(mem_ctx,
1358 pszParmValue, NULL);
1359 for (i=0; new_list[i]; i++) {
1360 if (new_list[i][0] == '+' && new_list[i][1]) {
1361 if (!str_list_check(*(const char ***)parm_ptr,
1363 *(const char ***)parm_ptr = str_list_add(*(const char ***)parm_ptr,
1366 } else if (new_list[i][0] == '-' && new_list[i][1]) {
1367 str_list_remove(*(const char ***)parm_ptr,
1371 DEBUG(0, ("Unsupported list syntax for: %s = %s\n",
1372 pszParmName, pszParmValue));
1375 *(const char ***)parm_ptr = (const char **) new_list;
1382 lpcfg_string_set(mem_ctx, (char **)parm_ptr, pszParmValue);
1386 lpcfg_string_set_upper(mem_ctx, (char **)parm_ptr, pszParmValue);
1390 for (i = 0; parm_table[parmnum].enum_list[i].name; i++) {
1393 parm_table[parmnum].enum_list[i].name)) {
1395 parm_table[parmnum].
1400 if (!parm_table[parmnum].enum_list[i].name) {
1401 DEBUG(0,("Unknown enumerated value '%s' for '%s'\n",
1402 pszParmValue, pszParmName));
1412 if (on_globals && (lp_ctx->flags[parmnum] & FLAG_DEFAULT)) {
1413 lp_ctx->flags[parmnum] &= ~FLAG_DEFAULT;
1414 /* we have to also unset FLAG_DEFAULT on aliases */
1415 for (i=parmnum-1;i>=0 && parm_table[i].offset == parm_table[parmnum].offset;i--) {
1416 lp_ctx->flags[i] &= ~FLAG_DEFAULT;
1418 for (i=parmnum+1;i<NUMPARAMETERS && parm_table[i].offset == parm_table[parmnum].offset;i++) {
1419 lp_ctx->flags[i] &= ~FLAG_DEFAULT;
1426 bool lpcfg_do_global_parameter(struct loadparm_context *lp_ctx,
1427 const char *pszParmName, const char *pszParmValue)
1429 int parmnum = map_parameter(pszParmName);
1433 if (strchr(pszParmName, ':')) {
1434 return lp_do_parameter_parametric(lp_ctx, NULL, pszParmName, pszParmValue, 0);
1436 DEBUG(0, ("Ignoring unknown parameter \"%s\"\n", pszParmName));
1440 /* if the flag has been set on the command line, then don't allow override,
1441 but don't report an error */
1442 if (lp_ctx->flags[parmnum] & FLAG_CMDLINE) {
1446 parm_ptr = lpcfg_parm_ptr(lp_ctx, NULL, &parm_table[parmnum]);
1448 return set_variable(lp_ctx->globals, parmnum, parm_ptr,
1449 pszParmName, pszParmValue, lp_ctx, true);
1452 bool lpcfg_do_service_parameter(struct loadparm_context *lp_ctx,
1453 struct loadparm_service *service,
1454 const char *pszParmName, const char *pszParmValue)
1458 int parmnum = map_parameter(pszParmName);
1461 if (strchr(pszParmName, ':')) {
1462 return lp_do_parameter_parametric(lp_ctx, service, pszParmName, pszParmValue, 0);
1464 DEBUG(0, ("Ignoring unknown parameter \"%s\"\n", pszParmName));
1468 /* if the flag has been set on the command line, then don't allow override,
1469 but don't report an error */
1470 if (lp_ctx->flags[parmnum] & FLAG_CMDLINE) {
1474 if (parm_table[parmnum].p_class == P_GLOBAL) {
1476 ("Global parameter %s found in service section!\n",
1480 parm_ptr = ((char *)service) + parm_table[parmnum].offset;
1482 if (!service->copymap)
1483 init_copymap(service);
1485 /* this handles the aliases - set the copymap for other
1486 * entries with the same data pointer */
1487 for (i = 0; parm_table[i].label; i++)
1488 if (parm_table[i].offset == parm_table[parmnum].offset &&
1489 parm_table[i].p_class == parm_table[parmnum].p_class)
1490 bitmap_clear(service->copymap, i);
1492 return set_variable(service, parmnum, parm_ptr, pszParmName,
1493 pszParmValue, lp_ctx, false);
1497 * Process a parameter.
1500 static bool do_parameter(const char *pszParmName, const char *pszParmValue,
1503 struct loadparm_context *lp_ctx = (struct loadparm_context *)userdata;
1505 if (lp_ctx->bInGlobalSection)
1506 return lpcfg_do_global_parameter(lp_ctx, pszParmName,
1509 return lpcfg_do_service_parameter(lp_ctx, lp_ctx->currentService,
1510 pszParmName, pszParmValue);
1514 variable argument do parameter
1516 bool lpcfg_do_global_parameter_var(struct loadparm_context *lp_ctx, const char *pszParmName, const char *fmt, ...) PRINTF_ATTRIBUTE(3, 4);
1517 bool lpcfg_do_global_parameter_var(struct loadparm_context *lp_ctx,
1518 const char *pszParmName, const char *fmt, ...)
1525 s = talloc_vasprintf(NULL, fmt, ap);
1527 ret = lpcfg_do_global_parameter(lp_ctx, pszParmName, s);
1534 set a parameter from the commandline - this is called from command line parameter
1535 parsing code. It sets the parameter then marks the parameter as unable to be modified
1536 by smb.conf processing
1538 bool lpcfg_set_cmdline(struct loadparm_context *lp_ctx, const char *pszParmName,
1539 const char *pszParmValue)
1544 if (lp_ctx->s3_fns) {
1545 return lp_ctx->s3_fns->set_cmdline(pszParmName, pszParmValue);
1548 parmnum = map_parameter(pszParmName);
1550 while (isspace((unsigned char)*pszParmValue)) pszParmValue++;
1553 if (parmnum < 0 && strchr(pszParmName, ':')) {
1554 /* set a parametric option */
1555 return lp_do_parameter_parametric(lp_ctx, NULL, pszParmName,
1556 pszParmValue, FLAG_CMDLINE);
1560 DEBUG(0,("Unknown option '%s'\n", pszParmName));
1564 /* reset the CMDLINE flag in case this has been called before */
1565 lp_ctx->flags[parmnum] &= ~FLAG_CMDLINE;
1567 if (!lpcfg_do_global_parameter(lp_ctx, pszParmName, pszParmValue)) {
1571 lp_ctx->flags[parmnum] |= FLAG_CMDLINE;
1573 /* we have to also set FLAG_CMDLINE on aliases */
1574 for (i=parmnum-1;i>=0 && parm_table[i].offset == parm_table[parmnum].offset;i--) {
1575 lp_ctx->flags[i] |= FLAG_CMDLINE;
1577 for (i=parmnum+1;i<NUMPARAMETERS && parm_table[i].offset == parm_table[parmnum].offset;i++) {
1578 lp_ctx->flags[i] |= FLAG_CMDLINE;
1585 set a option from the commandline in 'a=b' format. Use to support --option
1587 bool lpcfg_set_option(struct loadparm_context *lp_ctx, const char *option)
1592 s = talloc_strdup(NULL, option);
1605 ret = lpcfg_set_cmdline(lp_ctx, s, p+1);
1611 #define BOOLSTR(b) ((b) ? "Yes" : "No")
1614 * Print a parameter of the specified type.
1617 static void print_parameter(struct parm_struct *p, void *ptr, FILE * f)
1619 /* For the seperation of lists values that we print below */
1620 const char *list_sep = ", ";
1625 for (i = 0; p->enum_list[i].name; i++) {
1626 if (*(int *)ptr == p->enum_list[i].value) {
1628 p->enum_list[i].name);
1635 fprintf(f, "%s", BOOLSTR(*(bool *)ptr));
1639 fprintf(f, "%s", BOOLSTR(!*(bool *)ptr));
1644 fprintf(f, "%d", *(int *)ptr);
1648 fprintf(f, "%c", *(char *)ptr);
1652 int val = *(int *)ptr;
1656 fprintf(f, "0%o", val);
1665 if ((char ***)ptr && *(char ***)ptr) {
1666 char **list = *(char ***)ptr;
1667 for (; *list; list++) {
1668 /* surround strings with whitespace in double quotes */
1669 if (*(list+1) == NULL) {
1670 /* last item, no extra separator */
1673 if ( strchr_m( *list, ' ' ) ) {
1674 fprintf(f, "\"%s\"%s", *list, list_sep);
1676 fprintf(f, "%s%s", *list, list_sep);
1684 if (*(char **)ptr) {
1685 fprintf(f, "%s", *(char **)ptr);
1694 * Check if two parameters are equal.
1697 static bool equal_parameter(parm_type type, void *ptr1, void *ptr2)
1702 return (*((bool *)ptr1) == *((bool *)ptr2));
1708 return (*((int *)ptr1) == *((int *)ptr2));
1711 return (*((char *)ptr1) == *((char *)ptr2));
1715 return str_list_equal(*(const char ***)ptr1, *(const char ***)ptr2);
1720 char *p1 = *(char **)ptr1, *p2 = *(char **)ptr2;
1725 return (p1 == p2 || strequal(p1, p2));
1734 * Process a new section (service).
1736 * At this stage all sections are services.
1737 * Later we'll have special sections that permit server parameters to be set.
1738 * Returns True on success, False on failure.
1741 static bool do_section(const char *pszSectionName, void *userdata)
1743 struct loadparm_context *lp_ctx = (struct loadparm_context *)userdata;
1745 bool isglobal = ((strwicmp(pszSectionName, GLOBAL_NAME) == 0) ||
1746 (strwicmp(pszSectionName, GLOBAL_NAME2) == 0));
1749 /* if we've just struck a global section, note the fact. */
1750 lp_ctx->bInGlobalSection = isglobal;
1752 /* check for multiple global sections */
1753 if (lp_ctx->bInGlobalSection) {
1754 DEBUG(4, ("Processing section \"[%s]\"\n", pszSectionName));
1758 /* if we have a current service, tidy it up before moving on */
1761 if (lp_ctx->currentService != NULL)
1762 bRetval = lpcfg_service_ok(lp_ctx->currentService);
1764 /* if all is still well, move to the next record in the services array */
1766 /* We put this here to avoid an odd message order if messages are */
1767 /* issued by the post-processing of a previous section. */
1768 DEBUG(4, ("Processing section \"[%s]\"\n", pszSectionName));
1770 if ((lp_ctx->currentService = lpcfg_add_service(lp_ctx, lp_ctx->sDefault,
1773 DEBUG(0, ("Failed to add a new service\n"));
1783 * Determine if a particular base parameter is currently set to the default value.
1786 static bool is_default(struct loadparm_service *sDefault, int i)
1788 void *def_ptr = ((char *)sDefault) + parm_table[i].offset;
1789 if (!defaults_saved)
1791 switch (parm_table[i].type) {
1794 return str_list_equal((const char **)parm_table[i].def.lvalue,
1795 (const char **)def_ptr);
1798 return strequal(parm_table[i].def.svalue,
1802 return parm_table[i].def.bvalue ==
1809 return parm_table[i].def.ivalue ==
1818 *Display the contents of the global structure.
1821 static void dump_globals(struct loadparm_context *lp_ctx, FILE *f,
1825 struct parmlist_entry *data;
1827 fprintf(f, "# Global parameters\n[global]\n");
1829 for (i = 0; parm_table[i].label; i++)
1830 if (parm_table[i].p_class == P_GLOBAL &&
1831 (i == 0 || (parm_table[i].offset != parm_table[i - 1].offset))) {
1832 if (!show_defaults && (lp_ctx->flags[i] & FLAG_DEFAULT))
1834 fprintf(f, "\t%s = ", parm_table[i].label);
1835 print_parameter(&parm_table[i], lpcfg_parm_ptr(lp_ctx, NULL, &parm_table[i]), f);
1838 if (lp_ctx->globals->param_opt != NULL) {
1839 for (data = lp_ctx->globals->param_opt; data;
1840 data = data->next) {
1841 if (!show_defaults && (data->priority & FLAG_DEFAULT)) {
1844 fprintf(f, "\t%s = %s\n", data->key, data->value);
1851 * Display the contents of a single services record.
1854 static void dump_a_service(struct loadparm_service * pService, struct loadparm_service *sDefault, FILE * f,
1855 unsigned int *flags)
1858 struct parmlist_entry *data;
1860 if (pService != sDefault)
1861 fprintf(f, "\n[%s]\n", pService->szService);
1863 for (i = 0; parm_table[i].label; i++) {
1864 if (parm_table[i].p_class == P_LOCAL &&
1865 (*parm_table[i].label != '-') &&
1866 (i == 0 || (parm_table[i].offset != parm_table[i - 1].offset)))
1868 if (pService == sDefault) {
1869 if (flags && (flags[i] & FLAG_DEFAULT)) {
1872 if (defaults_saved) {
1873 if (is_default(sDefault, i)) {
1878 if (equal_parameter(parm_table[i].type,
1879 ((char *)pService) +
1880 parm_table[i].offset,
1881 ((char *)sDefault) +
1882 parm_table[i].offset))
1886 fprintf(f, "\t%s = ", parm_table[i].label);
1887 print_parameter(&parm_table[i],
1888 ((char *)pService) + parm_table[i].offset, f);
1892 if (pService->param_opt != NULL) {
1893 for (data = pService->param_opt; data; data = data->next) {
1894 fprintf(f, "\t%s = %s\n", data->key, data->value);
1899 bool lpcfg_dump_a_parameter(struct loadparm_context *lp_ctx,
1900 struct loadparm_service *service,
1901 const char *parm_name, FILE * f)
1903 struct parm_struct *parm;
1906 parm = lpcfg_parm_struct(lp_ctx, parm_name);
1911 ptr = lpcfg_parm_ptr(lp_ctx, service,parm);
1913 print_parameter(parm, ptr, f);
1919 * Return info about the next parameter in a service.
1920 * snum==-1 gives the globals.
1921 * Return NULL when out of parameters.
1925 struct parm_struct *lpcfg_next_parameter(struct loadparm_context *lp_ctx, int snum, int *i,
1929 /* do the globals */
1930 for (; parm_table[*i].label; (*i)++) {
1931 if ((*parm_table[*i].label == '-'))
1935 && (parm_table[*i].offset ==
1936 parm_table[(*i) - 1].offset)
1937 && (parm_table[*i].p_class ==
1938 parm_table[(*i) - 1].p_class))
1941 return &parm_table[(*i)++];
1944 struct loadparm_service *pService = lp_ctx->services[snum];
1946 for (; parm_table[*i].label; (*i)++) {
1947 if (parm_table[*i].p_class == P_LOCAL &&
1948 (*parm_table[*i].label != '-') &&
1950 (parm_table[*i].offset !=
1951 parm_table[(*i) - 1].offset)))
1953 if (allparameters ||
1954 !equal_parameter(parm_table[*i].type,
1955 ((char *)pService) +
1956 parm_table[*i].offset,
1957 ((char *)lp_ctx->sDefault) +
1958 parm_table[*i].offset))
1960 return &parm_table[(*i)++];
1971 * Auto-load some home services.
1973 static void lpcfg_add_auto_services(struct loadparm_context *lp_ctx,
1981 * Unload unused services.
1984 void lpcfg_killunused(struct loadparm_context *lp_ctx,
1985 struct smbsrv_connection *smb,
1986 bool (*snumused) (struct smbsrv_connection *, int))
1989 for (i = 0; i < lp_ctx->iNumServices; i++) {
1990 if (lp_ctx->services[i] == NULL)
1993 if (!snumused || !snumused(smb, i)) {
1994 talloc_free(lp_ctx->services[i]);
1995 lp_ctx->services[i] = NULL;
2001 static int lpcfg_destructor(struct loadparm_context *lp_ctx)
2003 struct parmlist_entry *data;
2005 if (lp_ctx->refuse_free) {
2006 /* someone is trying to free the
2007 global_loadparm_context.
2008 We can't allow that. */
2012 if (lp_ctx->globals->param_opt != NULL) {
2013 struct parmlist_entry *next;
2014 for (data = lp_ctx->globals->param_opt; data; data=next) {
2016 if (data->priority & FLAG_CMDLINE) continue;
2017 DLIST_REMOVE(lp_ctx->globals->param_opt, data);
2026 * Initialise the global parameter structure.
2028 * Note that most callers should use loadparm_init_global() instead
2030 struct loadparm_context *loadparm_init(TALLOC_CTX *mem_ctx)
2034 struct loadparm_context *lp_ctx;
2035 struct parmlist_entry *parm;
2038 lp_ctx = talloc_zero(mem_ctx, struct loadparm_context);
2042 talloc_set_destructor(lp_ctx, lpcfg_destructor);
2043 lp_ctx->bInGlobalSection = true;
2044 lp_ctx->globals = talloc_zero(lp_ctx, struct loadparm_global);
2045 lp_ctx->sDefault = talloc_zero(lp_ctx, struct loadparm_service);
2047 lp_ctx->sDefault->iMaxPrintJobs = 1000;
2048 lp_ctx->sDefault->bAvailable = true;
2049 lp_ctx->sDefault->bBrowseable = true;
2050 lp_ctx->sDefault->bRead_only = true;
2051 lp_ctx->sDefault->bMap_archive = true;
2052 lp_ctx->sDefault->iStrictLocking = true;
2053 lp_ctx->sDefault->bOpLocks = true;
2054 lp_ctx->sDefault->iCreate_mask = 0744;
2055 lp_ctx->sDefault->iCreate_force_mode = 0000;
2056 lp_ctx->sDefault->iDir_mask = 0755;
2057 lp_ctx->sDefault->iDir_force_mode = 0000;
2059 DEBUG(3, ("Initialising global parameters\n"));
2061 for (i = 0; parm_table[i].label; i++) {
2062 if ((parm_table[i].type == P_STRING ||
2063 parm_table[i].type == P_USTRING) &&
2064 !(lp_ctx->flags[i] & FLAG_CMDLINE)) {
2066 if (parm_table[i].p_class == P_LOCAL) {
2067 r = (char **)(((char *)lp_ctx->sDefault) + parm_table[i].offset);
2069 r = (char **)(((char *)lp_ctx->globals) + parm_table[i].offset);
2071 *r = talloc_strdup(lp_ctx, "");
2075 logfile = talloc_asprintf(lp_ctx, "%s/log.samba", dyn_LOGFILEBASE);
2076 lpcfg_do_global_parameter(lp_ctx, "log file", logfile);
2077 talloc_free(logfile);
2079 lpcfg_do_global_parameter(lp_ctx, "log level", "0");
2081 lpcfg_do_global_parameter(lp_ctx, "share backend", "classic");
2083 lpcfg_do_global_parameter(lp_ctx, "server role", "auto");
2084 lpcfg_do_global_parameter(lp_ctx, "domain logons", "No");
2085 lpcfg_do_global_parameter(lp_ctx, "domain master", "Auto");
2087 /* options that can be set on the command line must be initialised via
2088 the slower lpcfg_do_global_parameter() to ensure that FLAG_CMDLINE is obeyed */
2090 lpcfg_do_global_parameter(lp_ctx, "socket options", "TCP_NODELAY");
2092 lpcfg_do_global_parameter(lp_ctx, "workgroup", DEFAULT_WORKGROUP);
2093 myname = get_myname(lp_ctx);
2094 lpcfg_do_global_parameter(lp_ctx, "netbios name", myname);
2095 talloc_free(myname);
2096 lpcfg_do_global_parameter(lp_ctx, "name resolve order", "wins host bcast");
2098 lpcfg_do_global_parameter(lp_ctx, "fstype", "NTFS");
2100 lpcfg_do_global_parameter(lp_ctx, "ntvfs handler", "unixuid default");
2101 lpcfg_do_global_parameter(lp_ctx, "max connections", "-1");
2103 lpcfg_do_global_parameter(lp_ctx, "dcerpc endpoint servers", "epmapper wkssvc rpcecho samr netlogon lsarpc spoolss drsuapi dssetup unixinfo browser eventlog6 backupkey dnsserver");
2104 lpcfg_do_global_parameter(lp_ctx, "server services", "s3fs rpc nbt wrepl ldap cldap kdc drepl winbind ntp_signd kcc dnsupdate");
2105 /* the winbind method for domain controllers is for both RODC
2106 auth forwarding and for trusted domains */
2107 lpcfg_do_global_parameter(lp_ctx, "private dir", dyn_PRIVATE_DIR);
2108 lpcfg_do_global_parameter(lp_ctx, "registry:HKEY_LOCAL_MACHINE", "hklm.ldb");
2110 /* This hive should be dynamically generated by Samba using
2111 data from the sam, but for the moment leave it in a tdb to
2112 keep regedt32 from popping up an annoying dialog. */
2113 lpcfg_do_global_parameter(lp_ctx, "registry:HKEY_USERS", "hku.ldb");
2115 /* using UTF8 by default allows us to support all chars */
2116 lpcfg_do_global_parameter(lp_ctx, "unix charset", "UTF8");
2118 /* Use codepage 850 as a default for the dos character set */
2119 lpcfg_do_global_parameter(lp_ctx, "dos charset", "CP850");
2122 * Allow the default PASSWD_CHAT to be overridden in local.h.
2124 lpcfg_do_global_parameter(lp_ctx, "passwd chat", DEFAULT_PASSWD_CHAT);
2126 lpcfg_do_global_parameter(lp_ctx, "pid directory", dyn_PIDDIR);
2127 lpcfg_do_global_parameter(lp_ctx, "lock dir", dyn_LOCKDIR);
2128 lpcfg_do_global_parameter(lp_ctx, "state directory", dyn_STATEDIR);
2129 lpcfg_do_global_parameter(lp_ctx, "cache directory", dyn_CACHEDIR);
2130 lpcfg_do_global_parameter(lp_ctx, "ncalrpc dir", dyn_NCALRPCDIR);
2132 lpcfg_do_global_parameter(lp_ctx, "socket address", "");
2133 lpcfg_do_global_parameter_var(lp_ctx, "server string",
2134 "Samba %s", SAMBA_VERSION_STRING);
2136 lpcfg_do_global_parameter(lp_ctx, "password server", "*");
2138 lpcfg_do_global_parameter(lp_ctx, "max mux", "50");
2139 lpcfg_do_global_parameter(lp_ctx, "max xmit", "12288");
2140 lpcfg_do_global_parameter(lp_ctx, "host msdfs", "true");
2142 lpcfg_do_global_parameter(lp_ctx, "password level", "0");
2143 lpcfg_do_global_parameter(lp_ctx, "LargeReadwrite", "True");
2144 lpcfg_do_global_parameter(lp_ctx, "server min protocol", "CORE");
2145 lpcfg_do_global_parameter(lp_ctx, "server max protocol", "NT1");
2146 lpcfg_do_global_parameter(lp_ctx, "client min protocol", "CORE");
2147 lpcfg_do_global_parameter(lp_ctx, "client max protocol", "NT1");
2148 lpcfg_do_global_parameter(lp_ctx, "security", "AUTO");
2149 lpcfg_do_global_parameter(lp_ctx, "paranoid server security", "True");
2150 lpcfg_do_global_parameter(lp_ctx, "EncryptPasswords", "True");
2151 lpcfg_do_global_parameter(lp_ctx, "ReadRaw", "True");
2152 lpcfg_do_global_parameter(lp_ctx, "WriteRaw", "True");
2153 lpcfg_do_global_parameter(lp_ctx, "NullPasswords", "False");
2154 lpcfg_do_global_parameter(lp_ctx, "ObeyPamRestrictions", "False");
2156 lpcfg_do_global_parameter(lp_ctx, "TimeServer", "False");
2157 lpcfg_do_global_parameter(lp_ctx, "BindInterfacesOnly", "False");
2158 lpcfg_do_global_parameter(lp_ctx, "Unicode", "True");
2159 lpcfg_do_global_parameter(lp_ctx, "ClientLanManAuth", "False");
2160 lpcfg_do_global_parameter(lp_ctx, "ClientNTLMv2Auth", "True");
2161 lpcfg_do_global_parameter(lp_ctx, "LanmanAuth", "False");
2162 lpcfg_do_global_parameter(lp_ctx, "NTLMAuth", "True");
2163 lpcfg_do_global_parameter(lp_ctx, "client use spnego principal", "False");
2165 lpcfg_do_global_parameter(lp_ctx, "UnixExtensions", "False");
2167 lpcfg_do_global_parameter(lp_ctx, "PreferredMaster", "Auto");
2168 lpcfg_do_global_parameter(lp_ctx, "LocalMaster", "True");
2170 lpcfg_do_global_parameter(lp_ctx, "wins support", "False");
2171 lpcfg_do_global_parameter(lp_ctx, "dns proxy", "True");
2173 lpcfg_do_global_parameter(lp_ctx, "winbind separator", "\\");
2174 lpcfg_do_global_parameter(lp_ctx, "winbind sealed pipes", "True");
2175 lpcfg_do_global_parameter(lp_ctx, "winbindd socket directory", dyn_WINBINDD_SOCKET_DIR);
2176 #if _SAMBA_BUILD_ >= 4
2177 lpcfg_do_global_parameter(lp_ctx, "winbindd privileged socket directory", dyn_WINBINDD_PRIVILEGED_SOCKET_DIR);
2178 lpcfg_do_global_parameter(lp_ctx, "ntp signd socket directory", dyn_NTP_SIGND_SOCKET_DIR);
2179 lpcfg_do_global_parameter_var(lp_ctx, "dns update command", "%s/samba_dnsupdate", dyn_SCRIPTSBINDIR);
2180 lpcfg_do_global_parameter_var(lp_ctx, "spn update command", "%s/samba_spnupdate", dyn_SCRIPTSBINDIR);
2181 lpcfg_do_global_parameter_var(lp_ctx, "samba kcc command",
2182 "%s/samba_kcc", dyn_SCRIPTSBINDIR);
2184 lpcfg_do_global_parameter(lp_ctx, "template shell", "/bin/false");
2185 lpcfg_do_global_parameter(lp_ctx, "template homedir", "/home/%WORKGROUP%/%ACCOUNTNAME%");
2187 lpcfg_do_global_parameter(lp_ctx, "client signing", "default");
2188 lpcfg_do_global_parameter(lp_ctx, "server signing", "default");
2190 lpcfg_do_global_parameter(lp_ctx, "use spnego", "True");
2192 lpcfg_do_global_parameter(lp_ctx, "use mmap", "True");
2194 lpcfg_do_global_parameter(lp_ctx, "smb ports", "445 139");
2195 lpcfg_do_global_parameter(lp_ctx, "nbt port", "137");
2196 lpcfg_do_global_parameter(lp_ctx, "dgram port", "138");
2197 lpcfg_do_global_parameter(lp_ctx, "cldap port", "389");
2198 lpcfg_do_global_parameter(lp_ctx, "krb5 port", "88");
2199 lpcfg_do_global_parameter(lp_ctx, "kpasswd port", "464");
2200 lpcfg_do_global_parameter(lp_ctx, "web port", "901");
2202 lpcfg_do_global_parameter(lp_ctx, "nt status support", "True");
2204 lpcfg_do_global_parameter(lp_ctx, "max wins ttl", "518400"); /* 6 days */
2205 lpcfg_do_global_parameter(lp_ctx, "min wins ttl", "10");
2207 lpcfg_do_global_parameter(lp_ctx, "tls enabled", "True");
2208 lpcfg_do_global_parameter(lp_ctx, "tls keyfile", "tls/key.pem");
2209 lpcfg_do_global_parameter(lp_ctx, "tls certfile", "tls/cert.pem");
2210 lpcfg_do_global_parameter(lp_ctx, "tls cafile", "tls/ca.pem");
2211 lpcfg_do_global_parameter(lp_ctx, "prefork children:smb", "4");
2213 lpcfg_do_global_parameter(lp_ctx, "rndc command", "/usr/sbin/rndc");
2214 lpcfg_do_global_parameter(lp_ctx, "nsupdate command", "/usr/bin/nsupdate -g");
2216 lpcfg_do_global_parameter(lp_ctx, "allow dns updates", "False");
2217 lpcfg_do_global_parameter(lp_ctx, "dns recursive queries", "False");
2218 lpcfg_do_global_parameter(lp_ctx, "dns forwarder", "");
2220 for (i = 0; parm_table[i].label; i++) {
2221 if (!(lp_ctx->flags[i] & FLAG_CMDLINE)) {
2222 lp_ctx->flags[i] |= FLAG_DEFAULT;
2226 for (parm=lp_ctx->globals->param_opt; parm; parm=parm->next) {
2227 if (!(parm->priority & FLAG_CMDLINE)) {
2228 parm->priority |= FLAG_DEFAULT;
2236 * Initialise the global parameter structure.
2238 struct loadparm_context *loadparm_init_global(bool load_default)
2240 if (global_loadparm_context == NULL) {
2241 global_loadparm_context = loadparm_init(NULL);
2243 if (global_loadparm_context == NULL) {
2246 global_loadparm_context->global = true;
2247 if (load_default && !global_loadparm_context->loaded) {
2248 lpcfg_load_default(global_loadparm_context);
2250 global_loadparm_context->refuse_free = true;
2251 return global_loadparm_context;
2255 * Initialise the global parameter structure.
2257 struct loadparm_context *loadparm_init_s3(TALLOC_CTX *mem_ctx,
2258 const struct loadparm_s3_helpers *s3_fns)
2260 struct loadparm_context *loadparm_context = talloc_zero(mem_ctx, struct loadparm_context);
2261 if (!loadparm_context) {
2264 loadparm_context->s3_fns = s3_fns;
2265 return loadparm_context;
2268 const char *lpcfg_configfile(struct loadparm_context *lp_ctx)
2270 return lp_ctx->szConfigFile;
2273 const char *lp_default_path(void)
2275 if (getenv("SMB_CONF_PATH"))
2276 return getenv("SMB_CONF_PATH");
2278 return dyn_CONFIGFILE;
2282 * Update the internal state of a loadparm context after settings
2285 static bool lpcfg_update(struct loadparm_context *lp_ctx)
2287 struct debug_settings settings;
2288 lpcfg_add_auto_services(lp_ctx, lpcfg_auto_services(lp_ctx));
2290 if (!lp_ctx->globals->szWINSservers && lp_ctx->globals->bWINSsupport) {
2291 lpcfg_do_global_parameter(lp_ctx, "wins server", "127.0.0.1");
2294 if (!lp_ctx->global) {
2298 panic_action = lp_ctx->globals->panic_action;
2300 reload_charcnv(lp_ctx);
2302 ZERO_STRUCT(settings);
2303 /* Add any more debug-related smb.conf parameters created in
2305 settings.timestamp_logs = true;
2306 debug_set_settings(&settings);
2308 /* FIXME: This is a bit of a hack, but we can't use a global, since
2309 * not everything that uses lp also uses the socket library */
2310 if (lpcfg_parm_bool(lp_ctx, NULL, "socket", "testnonblock", false)) {
2311 setenv("SOCKET_TESTNONBLOCK", "1", 1);
2313 unsetenv("SOCKET_TESTNONBLOCK");
2319 bool lpcfg_load_default(struct loadparm_context *lp_ctx)
2323 path = lp_default_path();
2325 if (!file_exist(path)) {
2326 /* We allow the default smb.conf file to not exist,
2327 * basically the equivalent of an empty file. */
2328 return lpcfg_update(lp_ctx);
2331 return lpcfg_load(lp_ctx, path);
2335 * Load the services array from the services file.
2337 * Return True on success, False on failure.
2339 bool lpcfg_load(struct loadparm_context *lp_ctx, const char *filename)
2344 filename = talloc_strdup(lp_ctx, filename);
2346 lp_ctx->szConfigFile = filename;
2348 if (lp_ctx->s3_fns) {
2349 return lp_ctx->s3_fns->load(filename);
2352 lp_ctx->bInGlobalSection = true;
2353 n2 = standard_sub_basic(lp_ctx, lp_ctx->szConfigFile);
2354 DEBUG(2, ("lpcfg_load: refreshing parameters from %s\n", n2));
2356 add_to_file_list(lp_ctx, lp_ctx->szConfigFile, n2);
2358 /* We get sections first, so have to start 'behind' to make up */
2359 lp_ctx->currentService = NULL;
2360 bRetval = pm_process(n2, do_section, do_parameter, lp_ctx);
2362 /* finish up the last section */
2363 DEBUG(4, ("pm_process() returned %s\n", BOOLSTR(bRetval)));
2365 if (lp_ctx->currentService != NULL)
2366 bRetval = lpcfg_service_ok(lp_ctx->currentService);
2368 bRetval = bRetval && lpcfg_update(lp_ctx);
2370 /* we do this unconditionally, so that it happens even
2371 for a missing smb.conf */
2372 reload_charcnv(lp_ctx);
2374 if (bRetval == true) {
2375 /* set this up so that any child python tasks will
2376 find the right smb.conf */
2377 setenv("SMB_CONF_PATH", filename, 1);
2379 /* set the context used by the lp_*() function
2381 global_loadparm_context = lp_ctx;
2382 lp_ctx->loaded = true;
2389 * Return the max number of services.
2392 int lpcfg_numservices(struct loadparm_context *lp_ctx)
2394 if (lp_ctx->s3_fns) {
2395 return lp_ctx->s3_fns->get_numservices();
2398 return lp_ctx->iNumServices;
2402 * Display the contents of the services array in human-readable form.
2405 void lpcfg_dump(struct loadparm_context *lp_ctx, FILE *f, bool show_defaults,
2410 if (lp_ctx->s3_fns) {
2411 lp_ctx->s3_fns->dump(f, show_defaults, maxtoprint);
2415 defaults_saved = !show_defaults;
2417 dump_globals(lp_ctx, f, show_defaults);
2419 dump_a_service(lp_ctx->sDefault, lp_ctx->sDefault, f, lp_ctx->flags);
2421 for (iService = 0; iService < maxtoprint; iService++)
2422 lpcfg_dump_one(f, show_defaults, lp_ctx->services[iService], lp_ctx->sDefault);
2426 * Display the contents of one service in human-readable form.
2428 void lpcfg_dump_one(FILE *f, bool show_defaults, struct loadparm_service *service, struct loadparm_service *sDefault)
2430 if (service != NULL) {
2431 if (service->szService[0] == '\0')
2433 dump_a_service(service, sDefault, f, NULL);
2437 struct loadparm_service *lpcfg_servicebynum(struct loadparm_context *lp_ctx,
2440 if (lp_ctx->s3_fns) {
2441 return lp_ctx->s3_fns->get_servicebynum(snum);
2444 return lp_ctx->services[snum];
2447 struct loadparm_service *lpcfg_service(struct loadparm_context *lp_ctx,
2448 const char *service_name)
2453 if (lp_ctx->s3_fns) {
2454 return lp_ctx->s3_fns->get_service(service_name);
2457 for (iService = lp_ctx->iNumServices - 1; iService >= 0; iService--) {
2458 if (lp_ctx->services[iService] &&
2459 lp_ctx->services[iService]->szService) {
2461 * The substitution here is used to support %U is
2464 serviceName = standard_sub_basic(
2465 lp_ctx->services[iService],
2466 lp_ctx->services[iService]->szService);
2467 if (strequal(serviceName, service_name)) {
2468 talloc_free(serviceName);
2469 return lp_ctx->services[iService];
2471 talloc_free(serviceName);
2475 DEBUG(7,("lpcfg_servicenumber: couldn't find %s\n", service_name));
2479 const char *lpcfg_servicename(const struct loadparm_service *service)
2481 return lp_string((const char *)service->szService);
2485 * A useful volume label function.
2487 const char *lpcfg_volume_label(struct loadparm_service *service, struct loadparm_service *sDefault)
2490 ret = lp_string((const char *)((service != NULL && service->volume != NULL) ?
2491 service->volume : sDefault->volume));
2493 return lpcfg_servicename(service);
2498 * If we are PDC then prefer us as DMB
2500 const char *lpcfg_printername(struct loadparm_service *service, struct loadparm_service *sDefault)
2503 ret = lp_string((const char *)((service != NULL && service->szPrintername != NULL) ?
2504 service->szPrintername : sDefault->szPrintername));
2505 if (ret == NULL || (ret != NULL && *ret == '\0'))
2506 ret = lpcfg_servicename(service);
2513 * Return the max print jobs per queue.
2515 int lpcfg_maxprintjobs(struct loadparm_service *service, struct loadparm_service *sDefault)
2517 int maxjobs = (service != NULL) ? service->iMaxPrintJobs : sDefault->iMaxPrintJobs;
2518 if (maxjobs <= 0 || maxjobs >= PRINT_MAX_JOBID)
2519 maxjobs = PRINT_MAX_JOBID - 1;
2524 struct smb_iconv_handle *lpcfg_iconv_handle(struct loadparm_context *lp_ctx)
2526 if (lp_ctx == NULL) {
2527 return get_iconv_handle();
2529 return lp_ctx->iconv_handle;
2532 _PUBLIC_ void reload_charcnv(struct loadparm_context *lp_ctx)
2534 struct smb_iconv_handle *old_ic = lp_ctx->iconv_handle;
2535 if (!lp_ctx->global) {
2539 if (old_ic == NULL) {
2540 old_ic = global_iconv_handle;
2542 lp_ctx->iconv_handle = smb_iconv_handle_reinit_lp(lp_ctx, lp_ctx, old_ic);
2543 global_iconv_handle = lp_ctx->iconv_handle;
2546 _PUBLIC_ char *lpcfg_tls_keyfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
2548 return lpcfg_private_path(mem_ctx, lp_ctx, lp_ctx->globals->tls_keyfile);
2551 _PUBLIC_ char *lpcfg_tls_certfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
2553 return lpcfg_private_path(mem_ctx, lp_ctx, lp_ctx->globals->tls_certfile);
2556 _PUBLIC_ char *lpcfg_tls_cafile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
2558 return lpcfg_private_path(mem_ctx, lp_ctx, lp_ctx->globals->tls_cafile);
2561 _PUBLIC_ char *lpcfg_tls_crlfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
2563 return lpcfg_private_path(mem_ctx, lp_ctx, lp_ctx->globals->tls_crlfile);
2566 _PUBLIC_ char *lpcfg_tls_dhpfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
2568 return lpcfg_private_path(mem_ctx, lp_ctx, lp_ctx->globals->tls_dhpfile);
2571 struct gensec_settings *lpcfg_gensec_settings(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
2573 struct gensec_settings *settings = talloc_zero(mem_ctx, struct gensec_settings);
2574 if (settings == NULL)
2576 SMB_ASSERT(lp_ctx != NULL);
2577 settings->lp_ctx = talloc_reference(settings, lp_ctx);
2578 settings->target_hostname = lpcfg_parm_string(lp_ctx, NULL, "gensec", "target_hostname");
2582 int lpcfg_server_role(struct loadparm_context *lp_ctx)
2584 int domain_master = lpcfg__domain_master(lp_ctx);
2586 return lp_find_server_role(lpcfg__server_role(lp_ctx),
2587 lpcfg__security(lp_ctx),
2588 lpcfg__domain_logons(lp_ctx),
2589 (domain_master == true) ||
2590 (domain_master == Auto));
2593 int lpcfg_security(struct loadparm_context *lp_ctx)
2595 return lp_find_security(lpcfg__server_role(lp_ctx),
2596 lpcfg__security(lp_ctx));