2 Unix SMB/CIFS implementation.
3 Parameter loading functions
4 Copyright (C) Karl Auer 1993-1998
6 Largely re-written by Andrew Tridgell, September 1994
8 Copyright (C) Simo Sorce 2001
9 Copyright (C) Alexander Bokovoy 2002
10 Copyright (C) Stefan (metze) Metzmacher 2002
11 Copyright (C) Jim McDonough (jmcd@us.ibm.com) 2003.
12 Copyright (C) James Myers 2003 <myersjj@samba.org>
13 Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2007
14 Copyright (C) Andrew Bartlett 2011-2012
16 This program is free software; you can redistribute it and/or modify
17 it under the terms of the GNU General Public License as published by
18 the Free Software Foundation; either version 3 of the License, or
19 (at your option) any later version.
21 This program is distributed in the hope that it will be useful,
22 but WITHOUT ANY WARRANTY; without even the implied warranty of
23 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 GNU General Public License for more details.
26 You should have received a copy of the GNU General Public License
27 along with this program. If not, see <http://www.gnu.org/licenses/>.
33 * This module provides suitable callback functions for the params
34 * module. It builds the internal table of service details which is
35 * then used by the rest of the server.
39 * 1) add it to the global or service structure definition
40 * 2) add it to the parm_table
41 * 3) add it to the list of available functions (eg: using FN_GLOBAL_STRING())
42 * 4) If it's a global then initialise it in init_globals. If a local
43 * (ie. service) parameter then initialise it in the sDefault structure
47 * The configuration file is processed sequentially for speed. It is NOT
48 * accessed randomly as happens in 'real' Windows. For this reason, there
49 * is a fair bit of sequence-dependent code here - ie., code which assumes
50 * that certain things happen before others. In particular, the code which
51 * happens at the boundary between sections is delicately poised, so be
58 #include "dynconfig/dynconfig.h"
59 #include "system/time.h"
60 #include "system/locale.h"
61 #include "system/network.h" /* needed for TCP_NODELAY */
62 #include "../lib/util/dlinklist.h"
63 #include "lib/param/param.h"
64 #include "lib/param/loadparm.h"
65 #include "auth/gensec/gensec.h"
66 #include "lib/param/s3_param.h"
67 #include "lib/util/bitmap.h"
68 #include "libcli/smb/smb_constants.h"
70 #define standard_sub_basic talloc_strdup
72 static bool do_parameter(const char *, const char *, void *);
73 static bool defaults_saved
= false;
75 #define LOADPARM_EXTRA_GLOBALS \
76 struct parmlist_entry *param_opt; \
79 int iminreceivefile; \
80 char *szPrintcapname; \
82 int iPreferredMaster; \
83 char *szLdapMachineSuffix; \
84 char *szLdapUserSuffix; \
85 char *szLdapIdmapSuffix; \
86 char *szLdapGroupSuffix; \
87 char *szUsershareTemplateShare; \
90 char *szIdmapBackend; \
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_CHAR(fn_name,val) \
318 _PUBLIC_ char lpcfg_ ## fn_name(struct loadparm_service *service, \
319 struct loadparm_service *sDefault) { \
320 return((service != NULL)? service->val : sDefault->val); \
323 #include "lib/param/param_functions.c"
325 /* These functions remain only in lib/param for now */
326 FN_GLOBAL_BOOL(readraw
, bReadRaw
)
327 FN_GLOBAL_BOOL(writeraw
, bWriteRaw
)
328 FN_GLOBAL_CONST_STRING(cachedir
, szCacheDir
)
329 FN_GLOBAL_CONST_STRING(statedir
, szStateDir
)
331 /* local prototypes */
332 static int map_parameter(const char *pszParmName
);
333 static struct loadparm_service
*getservicebyname(struct loadparm_context
*lp_ctx
,
334 const char *pszServiceName
);
335 static void copy_service(struct loadparm_service
*pserviceDest
,
336 struct loadparm_service
*pserviceSource
,
337 struct bitmap
*pcopymapDest
);
338 static bool lpcfg_service_ok(struct loadparm_service
*service
);
339 static bool do_section(const char *pszSectionName
, void *);
340 static void init_copymap(struct loadparm_service
*pservice
);
342 /* This is a helper function for parametrical options support. */
343 /* It returns a pointer to parametrical option value if it exists or NULL otherwise */
344 /* Actual parametrical functions are quite simple */
345 const char *lpcfg_get_parametric(struct loadparm_context
*lp_ctx
,
346 struct loadparm_service
*service
,
347 const char *type
, const char *option
)
349 char *vfskey_tmp
= NULL
;
351 struct parmlist_entry
*data
;
356 if (lp_ctx
->s3_fns
) {
357 return lp_ctx
->s3_fns
->get_parametric(service
, type
, option
);
360 data
= (service
== NULL
? lp_ctx
->globals
->param_opt
: service
->param_opt
);
362 vfskey_tmp
= talloc_asprintf(NULL
, "%s:%s", type
, option
);
363 if (vfskey_tmp
== NULL
) return NULL
;
364 vfskey
= strlower_talloc(NULL
, vfskey_tmp
);
365 talloc_free(vfskey_tmp
);
368 if (strcmp(data
->key
, vfskey
) == 0) {
375 if (service
!= NULL
) {
376 /* Try to fetch the same option but from globals */
377 /* but only if we are not already working with globals */
378 for (data
= lp_ctx
->globals
->param_opt
; data
;
380 if (strcmp(data
->key
, vfskey
) == 0) {
394 * convenience routine to return int parameters.
396 static int lp_int(const char *s
)
400 DEBUG(0,("lp_int(%s): is called with NULL!\n",s
));
404 return strtol(s
, NULL
, 0);
408 * convenience routine to return unsigned long parameters.
410 static unsigned long lp_ulong(const char *s
)
414 DEBUG(0,("lp_ulong(%s): is called with NULL!\n",s
));
418 return strtoul(s
, NULL
, 0);
422 * convenience routine to return unsigned long parameters.
424 static long lp_long(const char *s
)
428 DEBUG(0,("lp_long(%s): is called with NULL!\n",s
));
432 return strtol(s
, NULL
, 0);
436 * convenience routine to return unsigned long parameters.
438 static double lp_double(const char *s
)
442 DEBUG(0,("lp_double(%s): is called with NULL!\n",s
));
446 return strtod(s
, NULL
);
450 * convenience routine to return boolean parameters.
452 static bool lp_bool(const char *s
)
457 DEBUG(0,("lp_bool(%s): is called with NULL!\n",s
));
461 if (!set_boolean(s
, &ret
)) {
462 DEBUG(0,("lp_bool(%s): value is not boolean!\n",s
));
471 * Return parametric option from a given service. Type is a part of option before ':'
472 * Parametric option has following syntax: 'Type: option = value'
473 * Returned value is allocated in 'lp_talloc' context
476 const char *lpcfg_parm_string(struct loadparm_context
*lp_ctx
,
477 struct loadparm_service
*service
, const char *type
,
480 const char *value
= lpcfg_get_parametric(lp_ctx
, service
, type
, option
);
483 return lp_string(value
);
489 * Return parametric option from a given service. Type is a part of option before ':'
490 * Parametric option has following syntax: 'Type: option = value'
491 * Returned value is allocated in 'lp_talloc' context
494 const char **lpcfg_parm_string_list(TALLOC_CTX
*mem_ctx
,
495 struct loadparm_context
*lp_ctx
,
496 struct loadparm_service
*service
,
498 const char *option
, const char *separator
)
500 const char *value
= lpcfg_get_parametric(lp_ctx
, service
, type
, option
);
503 return (const char **)str_list_make(mem_ctx
, value
, separator
);
509 * Return parametric option from a given service. Type is a part of option before ':'
510 * Parametric option has following syntax: 'Type: option = value'
513 int lpcfg_parm_int(struct loadparm_context
*lp_ctx
,
514 struct loadparm_service
*service
, const char *type
,
515 const char *option
, int default_v
)
517 const char *value
= lpcfg_get_parametric(lp_ctx
, service
, type
, option
);
520 return lp_int(value
);
526 * Return parametric option from a given service. Type is a part of
528 * Parametric option has following syntax: 'Type: option = value'.
531 int lpcfg_parm_bytes(struct loadparm_context
*lp_ctx
,
532 struct loadparm_service
*service
, const char *type
,
533 const char *option
, int default_v
)
537 const char *value
= lpcfg_get_parametric(lp_ctx
, service
, type
, option
);
539 if (value
&& conv_str_size_error(value
, &bval
)) {
540 if (bval
<= INT_MAX
) {
549 * Return parametric option from a given service.
550 * Type is a part of option before ':'
551 * Parametric option has following syntax: 'Type: option = value'
553 unsigned long lpcfg_parm_ulong(struct loadparm_context
*lp_ctx
,
554 struct loadparm_service
*service
, const char *type
,
555 const char *option
, unsigned long default_v
)
557 const char *value
= lpcfg_get_parametric(lp_ctx
, service
, type
, option
);
560 return lp_ulong(value
);
565 long lpcfg_parm_long(struct loadparm_context
*lp_ctx
,
566 struct loadparm_service
*service
, const char *type
,
567 const char *option
, long default_v
)
569 const char *value
= lpcfg_get_parametric(lp_ctx
, service
, type
, option
);
572 return lp_long(value
);
577 double lpcfg_parm_double(struct loadparm_context
*lp_ctx
,
578 struct loadparm_service
*service
, const char *type
,
579 const char *option
, double default_v
)
581 const char *value
= lpcfg_get_parametric(lp_ctx
, service
, type
, option
);
584 return lp_double(value
);
590 * Return parametric option from a given service. Type is a part of option before ':'
591 * Parametric option has following syntax: 'Type: option = value'
594 bool lpcfg_parm_bool(struct loadparm_context
*lp_ctx
,
595 struct loadparm_service
*service
, const char *type
,
596 const char *option
, bool default_v
)
598 const char *value
= lpcfg_get_parametric(lp_ctx
, service
, type
, option
);
601 return lp_bool(value
);
608 * Initialise a service to the defaults.
611 static struct loadparm_service
*init_service(TALLOC_CTX
*mem_ctx
, struct loadparm_service
*sDefault
)
613 struct loadparm_service
*pservice
=
614 talloc_zero(mem_ctx
, struct loadparm_service
);
615 copy_service(pservice
, sDefault
, NULL
);
620 * Set a string value, deallocating any existing space, and allocing the space
623 static bool lpcfg_string_set(TALLOC_CTX
*mem_ctx
, char **dest
, const char *src
)
630 *dest
= talloc_strdup(mem_ctx
, src
);
631 if ((*dest
) == NULL
) {
632 DEBUG(0,("Out of memory in string_set\n"));
640 * Set a string value, deallocating any existing space, and allocing the space
643 static bool lpcfg_string_set_upper(TALLOC_CTX
*mem_ctx
, char **dest
, const char *src
)
650 *dest
= strupper_talloc(mem_ctx
, src
);
651 if ((*dest
) == NULL
) {
652 DEBUG(0,("Out of memory in string_set_upper\n"));
662 * Add a new service to the services array initialising it with the given
666 struct loadparm_service
*lpcfg_add_service(struct loadparm_context
*lp_ctx
,
667 const struct loadparm_service
*pservice
,
671 struct loadparm_service tservice
;
672 int num_to_alloc
= lp_ctx
->iNumServices
+ 1;
673 struct parmlist_entry
*data
, *pdata
;
675 if (pservice
== NULL
) {
676 pservice
= lp_ctx
->sDefault
;
679 tservice
= *pservice
;
681 /* it might already exist */
683 struct loadparm_service
*service
= getservicebyname(lp_ctx
,
685 if (service
!= NULL
) {
686 /* Clean all parametric options for service */
687 /* They will be added during parsing again */
688 data
= service
->param_opt
;
694 service
->param_opt
= NULL
;
699 /* find an invalid one */
700 for (i
= 0; i
< lp_ctx
->iNumServices
; i
++)
701 if (lp_ctx
->services
[i
] == NULL
)
704 /* if not, then create one */
705 if (i
== lp_ctx
->iNumServices
) {
706 struct loadparm_service
**tsp
;
708 tsp
= talloc_realloc(lp_ctx
, lp_ctx
->services
, struct loadparm_service
*, num_to_alloc
);
711 DEBUG(0,("lpcfg_add_service: failed to enlarge services!\n"));
714 lp_ctx
->services
= tsp
;
715 lp_ctx
->services
[lp_ctx
->iNumServices
] = NULL
;
718 lp_ctx
->iNumServices
++;
721 lp_ctx
->services
[i
] = init_service(lp_ctx
->services
, lp_ctx
->sDefault
);
722 if (lp_ctx
->services
[i
] == NULL
) {
723 DEBUG(0,("lpcfg_add_service: out of memory!\n"));
726 copy_service(lp_ctx
->services
[i
], &tservice
, NULL
);
728 lpcfg_string_set(lp_ctx
->services
[i
], &lp_ctx
->services
[i
]->szService
, name
);
729 return lp_ctx
->services
[i
];
733 * Add a new home service, with the specified home directory, defaults coming
734 * from service ifrom.
737 bool lpcfg_add_home(struct loadparm_context
*lp_ctx
,
738 const char *pszHomename
,
739 struct loadparm_service
*default_service
,
740 const char *user
, const char *pszHomedir
)
742 struct loadparm_service
*service
;
744 service
= lpcfg_add_service(lp_ctx
, default_service
, pszHomename
);
749 if (!(*(default_service
->szPath
))
750 || strequal(default_service
->szPath
, lp_ctx
->sDefault
->szPath
)) {
751 service
->szPath
= talloc_strdup(service
, pszHomedir
);
753 service
->szPath
= string_sub_talloc(service
, lpcfg_pathname(default_service
, lp_ctx
->sDefault
), "%H", pszHomedir
);
756 if (!(*(service
->comment
))) {
757 service
->comment
= talloc_asprintf(service
, "Home directory of %s", user
);
759 service
->bAvailable
= default_service
->bAvailable
;
760 service
->bBrowseable
= default_service
->bBrowseable
;
762 DEBUG(3, ("adding home's share [%s] for user '%s' at '%s'\n",
763 pszHomename
, user
, service
->szPath
));
769 * Add a new printer service, with defaults coming from service iFrom.
772 bool lpcfg_add_printer(struct loadparm_context
*lp_ctx
,
773 const char *pszPrintername
,
774 struct loadparm_service
*default_service
)
776 const char *comment
= "From Printcap";
777 struct loadparm_service
*service
;
778 service
= lpcfg_add_service(lp_ctx
, default_service
, pszPrintername
);
783 /* note that we do NOT default the availability flag to True - */
784 /* we take it from the default service passed. This allows all */
785 /* dynamic printers to be disabled by disabling the [printers] */
786 /* entry (if/when the 'available' keyword is implemented!). */
788 /* the printer name is set to the service name. */
789 lpcfg_string_set(service
, &service
->szPrintername
, pszPrintername
);
790 lpcfg_string_set(service
, &service
->comment
, comment
);
791 service
->bBrowseable
= default_service
->bBrowseable
;
792 /* Printers cannot be read_only. */
793 service
->bRead_only
= false;
794 /* Printer services must be printable. */
795 service
->bPrint_ok
= true;
797 DEBUG(3, ("adding printer service %s\n", pszPrintername
));
803 * Map a parameter's string representation to something we can use.
804 * Returns False if the parameter string is not recognised, else TRUE.
807 static int map_parameter(const char *pszParmName
)
811 if (*pszParmName
== '-')
814 for (iIndex
= 0; parm_table
[iIndex
].label
; iIndex
++)
815 if (strwicmp(parm_table
[iIndex
].label
, pszParmName
) == 0)
818 /* Warn only if it isn't parametric option */
819 if (strchr(pszParmName
, ':') == NULL
)
820 DEBUG(0, ("Unknown parameter encountered: \"%s\"\n", pszParmName
));
821 /* We do return 'fail' for parametric options as well because they are
822 stored in different storage
829 return the parameter structure for a parameter
831 struct parm_struct
*lpcfg_parm_struct(struct loadparm_context
*lp_ctx
, const char *name
)
835 if (lp_ctx
->s3_fns
) {
836 return lp_ctx
->s3_fns
->get_parm_struct(name
);
839 parmnum
= map_parameter(name
);
840 if (parmnum
== -1) return NULL
;
841 return &parm_table
[parmnum
];
845 return the parameter pointer for a parameter
847 void *lpcfg_parm_ptr(struct loadparm_context
*lp_ctx
,
848 struct loadparm_service
*service
, struct parm_struct
*parm
)
850 if (lp_ctx
->s3_fns
) {
851 return lp_ctx
->s3_fns
->get_parm_ptr(service
, parm
);
854 if (service
== NULL
) {
855 if (parm
->p_class
== P_LOCAL
)
856 return ((char *)lp_ctx
->sDefault
)+parm
->offset
;
857 else if (parm
->p_class
== P_GLOBAL
)
858 return ((char *)lp_ctx
->globals
)+parm
->offset
;
861 return ((char *)service
) + parm
->offset
;
866 return the parameter pointer for a parameter
868 bool lpcfg_parm_is_cmdline(struct loadparm_context
*lp_ctx
, const char *name
)
872 if (lp_ctx
->s3_fns
) {
873 struct parm_struct
*parm
= lp_ctx
->s3_fns
->get_parm_struct(name
);
875 return parm
->flags
& FLAG_CMDLINE
;
880 parmnum
= map_parameter(name
);
881 if (parmnum
== -1) return false;
883 return lp_ctx
->flags
[parmnum
] & FLAG_CMDLINE
;
887 * Find a service by name. Otherwise works like get_service.
890 static struct loadparm_service
*getservicebyname(struct loadparm_context
*lp_ctx
,
891 const char *pszServiceName
)
895 if (lp_ctx
->s3_fns
) {
896 return lp_ctx
->s3_fns
->get_service(pszServiceName
);
899 for (iService
= lp_ctx
->iNumServices
- 1; iService
>= 0; iService
--)
900 if (lp_ctx
->services
[iService
] != NULL
&&
901 strwicmp(lp_ctx
->services
[iService
]->szService
, pszServiceName
) == 0) {
902 return lp_ctx
->services
[iService
];
909 * Copy a service structure to another.
910 * If pcopymapDest is NULL then copy all fields
913 static void copy_service(struct loadparm_service
*pserviceDest
,
914 struct loadparm_service
*pserviceSource
,
915 struct bitmap
*pcopymapDest
)
918 bool bcopyall
= (pcopymapDest
== NULL
);
919 struct parmlist_entry
*data
, *pdata
, *paramo
;
922 for (i
= 0; parm_table
[i
].label
; i
++)
923 if (parm_table
[i
].p_class
== P_LOCAL
&&
924 (bcopyall
|| bitmap_query(pcopymapDest
, i
))) {
926 ((char *)pserviceSource
) + parm_table
[i
].offset
;
928 ((char *)pserviceDest
) + parm_table
[i
].offset
;
930 switch (parm_table
[i
].type
) {
932 *(bool *)dest_ptr
= *(bool *)src_ptr
;
939 *(int *)dest_ptr
= *(int *)src_ptr
;
943 lpcfg_string_set(pserviceDest
,
949 lpcfg_string_set_upper(pserviceDest
,
954 *(const char ***)dest_ptr
= (const char **)str_list_copy(pserviceDest
,
955 *(const char ***)src_ptr
);
963 init_copymap(pserviceDest
);
964 if (pserviceSource
->copymap
)
965 bitmap_copy(pserviceDest
->copymap
,
966 pserviceSource
->copymap
);
969 data
= pserviceSource
->param_opt
;
972 pdata
= pserviceDest
->param_opt
;
973 /* Traverse destination */
975 /* If we already have same option, override it */
976 if (strcmp(pdata
->key
, data
->key
) == 0) {
977 talloc_free(pdata
->value
);
978 pdata
->value
= talloc_strdup(pdata
,
986 paramo
= talloc_zero(pserviceDest
, struct parmlist_entry
);
989 paramo
->key
= talloc_strdup(paramo
, data
->key
);
990 paramo
->value
= talloc_strdup(paramo
, data
->value
);
991 DLIST_ADD(pserviceDest
->param_opt
, paramo
);
998 * Check a service for consistency. Return False if the service is in any way
999 * incomplete or faulty, else True.
1001 static bool lpcfg_service_ok(struct loadparm_service
*service
)
1006 if (service
->szService
[0] == '\0') {
1007 DEBUG(0, ("The following message indicates an internal error:\n"));
1008 DEBUG(0, ("No service name in service entry.\n"));
1012 /* The [printers] entry MUST be printable. I'm all for flexibility, but */
1013 /* I can't see why you'd want a non-printable printer service... */
1014 if (strwicmp(service
->szService
, PRINTERS_NAME
) == 0) {
1015 if (!service
->bPrint_ok
) {
1016 DEBUG(0, ("WARNING: [%s] service MUST be printable!\n",
1017 service
->szService
));
1018 service
->bPrint_ok
= true;
1020 /* [printers] service must also be non-browsable. */
1021 if (service
->bBrowseable
)
1022 service
->bBrowseable
= false;
1025 /* If a service is flagged unavailable, log the fact at level 0. */
1026 if (!service
->bAvailable
)
1027 DEBUG(1, ("NOTE: Service %s is flagged unavailable.\n",
1028 service
->szService
));
1034 /*******************************************************************
1035 Keep a linked list of all config files so we know when one has changed
1036 it's date and needs to be reloaded.
1037 ********************************************************************/
1039 static void add_to_file_list(struct loadparm_context
*lp_ctx
,
1040 const char *fname
, const char *subfname
)
1042 struct file_lists
*f
= lp_ctx
->file_lists
;
1045 if (f
->name
&& !strcmp(f
->name
, fname
))
1051 f
= talloc(lp_ctx
, struct file_lists
);
1054 f
->next
= lp_ctx
->file_lists
;
1055 f
->name
= talloc_strdup(f
, fname
);
1060 f
->subfname
= talloc_strdup(f
, subfname
);
1065 lp_ctx
->file_lists
= f
;
1066 f
->modtime
= file_modtime(subfname
);
1068 time_t t
= file_modtime(subfname
);
1074 /*******************************************************************
1075 Check if a config file has changed date.
1076 ********************************************************************/
1077 bool lpcfg_file_list_changed(struct loadparm_context
*lp_ctx
)
1079 struct file_lists
*f
;
1080 DEBUG(6, ("lpcfg_file_list_changed()\n"));
1082 for (f
= lp_ctx
->file_lists
; f
!= NULL
; f
= f
->next
) {
1086 n2
= standard_sub_basic(lp_ctx
, f
->name
);
1088 DEBUGADD(6, ("file %s -> %s last mod_time: %s\n",
1089 f
->name
, n2
, ctime(&f
->modtime
)));
1091 mod_time
= file_modtime(n2
);
1093 if (mod_time
&& ((f
->modtime
!= mod_time
) || (f
->subfname
== NULL
) || (strcmp(n2
, f
->subfname
) != 0))) {
1094 DEBUGADD(6, ("file %s modified: %s\n", n2
,
1096 f
->modtime
= mod_time
;
1097 talloc_free(f
->subfname
);
1098 f
->subfname
= talloc_strdup(f
, n2
);
1105 /***************************************************************************
1106 Handle the "realm" parameter
1107 ***************************************************************************/
1109 static bool handle_realm(struct loadparm_context
*lp_ctx
, int unused
,
1110 const char *pszParmValue
, char **ptr
)
1112 lpcfg_string_set(lp_ctx
, ptr
, pszParmValue
);
1114 talloc_free(lp_ctx
->globals
->szRealm_upper
);
1115 talloc_free(lp_ctx
->globals
->szRealm_lower
);
1117 lp_ctx
->globals
->szRealm_upper
= strupper_talloc(lp_ctx
, pszParmValue
);
1118 lp_ctx
->globals
->szRealm_lower
= strlower_talloc(lp_ctx
, pszParmValue
);
1123 /***************************************************************************
1124 Handle the include operation.
1125 ***************************************************************************/
1127 static bool handle_include(struct loadparm_context
*lp_ctx
, int unused
,
1128 const char *pszParmValue
, char **ptr
)
1130 char *fname
= standard_sub_basic(lp_ctx
, pszParmValue
);
1132 add_to_file_list(lp_ctx
, pszParmValue
, fname
);
1134 lpcfg_string_set(lp_ctx
, ptr
, fname
);
1136 if (file_exist(fname
))
1137 return pm_process(fname
, do_section
, do_parameter
, lp_ctx
);
1139 DEBUG(2, ("Can't find include file %s\n", fname
));
1144 /***************************************************************************
1145 Handle the interpretation of the copy parameter.
1146 ***************************************************************************/
1148 static bool handle_copy(struct loadparm_context
*lp_ctx
, int unused
,
1149 const char *pszParmValue
, char **ptr
)
1152 struct loadparm_service
*serviceTemp
;
1154 lpcfg_string_set(lp_ctx
, ptr
, pszParmValue
);
1158 DEBUG(3, ("Copying service from service %s\n", pszParmValue
));
1160 if ((serviceTemp
= getservicebyname(lp_ctx
, pszParmValue
)) != NULL
) {
1161 if (serviceTemp
== lp_ctx
->currentService
) {
1162 DEBUG(0, ("Can't copy service %s - unable to copy self!\n", pszParmValue
));
1164 copy_service(lp_ctx
->currentService
,
1166 lp_ctx
->currentService
->copymap
);
1170 DEBUG(0, ("Unable to copy service - source not found: %s\n",
1178 static bool handle_debug_list(struct loadparm_context
*lp_ctx
, int unused
,
1179 const char *pszParmValue
, char **ptr
)
1182 lpcfg_string_set(lp_ctx
, ptr
, pszParmValue
);
1183 if (lp_ctx
->global
) {
1184 return debug_parse_levels(pszParmValue
);
1189 static bool handle_logfile(struct loadparm_context
*lp_ctx
, int unused
,
1190 const char *pszParmValue
, char **ptr
)
1192 debug_set_logfile(pszParmValue
);
1193 if (lp_ctx
->global
) {
1194 lpcfg_string_set(lp_ctx
, ptr
, pszParmValue
);
1199 /***************************************************************************
1200 Initialise a copymap.
1201 ***************************************************************************/
1203 static void init_copymap(struct loadparm_service
*pservice
)
1207 TALLOC_FREE(pservice
->copymap
);
1209 pservice
->copymap
= bitmap_talloc(NULL
, NUMPARAMETERS
);
1210 if (!pservice
->copymap
)
1212 ("Couldn't allocate copymap!! (size %d)\n",
1213 (int)NUMPARAMETERS
));
1215 for (i
= 0; i
< NUMPARAMETERS
; i
++)
1216 bitmap_set(pservice
->copymap
, i
);
1220 * Process a parametric option
1222 static bool lp_do_parameter_parametric(struct loadparm_context
*lp_ctx
,
1223 struct loadparm_service
*service
,
1224 const char *pszParmName
,
1225 const char *pszParmValue
, int flags
)
1227 struct parmlist_entry
*paramo
, *data
;
1229 TALLOC_CTX
*mem_ctx
;
1231 while (isspace((unsigned char)*pszParmName
)) {
1235 name
= strlower_talloc(lp_ctx
, pszParmName
);
1236 if (!name
) return false;
1238 if (service
== NULL
) {
1239 data
= lp_ctx
->globals
->param_opt
;
1240 mem_ctx
= lp_ctx
->globals
;
1242 data
= service
->param_opt
;
1246 /* Traverse destination */
1247 for (paramo
=data
; paramo
; paramo
=paramo
->next
) {
1248 /* If we already have the option set, override it unless
1249 it was a command line option and the new one isn't */
1250 if (strcmp(paramo
->key
, name
) == 0) {
1251 if ((paramo
->priority
& FLAG_CMDLINE
) &&
1252 !(flags
& FLAG_CMDLINE
)) {
1257 talloc_free(paramo
->value
);
1258 paramo
->value
= talloc_strdup(paramo
, pszParmValue
);
1259 paramo
->priority
= flags
;
1265 paramo
= talloc_zero(mem_ctx
, struct parmlist_entry
);
1268 paramo
->key
= talloc_strdup(paramo
, name
);
1269 paramo
->value
= talloc_strdup(paramo
, pszParmValue
);
1270 paramo
->priority
= flags
;
1271 if (service
== NULL
) {
1272 DLIST_ADD(lp_ctx
->globals
->param_opt
, paramo
);
1274 DLIST_ADD(service
->param_opt
, paramo
);
1282 static bool set_variable(TALLOC_CTX
*mem_ctx
, int parmnum
, void *parm_ptr
,
1283 const char *pszParmName
, const char *pszParmValue
,
1284 struct loadparm_context
*lp_ctx
, bool on_globals
)
1287 /* if it is a special case then go ahead */
1288 if (parm_table
[parmnum
].special
) {
1290 ret
= parm_table
[parmnum
].special(lp_ctx
, -1, pszParmValue
,
1295 goto mark_non_default
;
1298 /* now switch on the type of variable it is */
1299 switch (parm_table
[parmnum
].type
)
1303 if (!set_boolean(pszParmValue
, &b
)) {
1304 DEBUG(0, ("set_variable(%s): value is not "
1305 "boolean!\n", pszParmValue
));
1308 *(bool *)parm_ptr
= b
;
1314 if (!set_boolean(pszParmValue
, &b
)) {
1315 DEBUG(0, ("set_variable(%s): value is not "
1316 "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, ("set_variable(%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 (*(const char ***)parm_ptr
!= NULL
&&
1360 new_list
[i
][0] == '+' &&
1363 if (!str_list_check(*(const char ***)parm_ptr
,
1365 *(const char ***)parm_ptr
= str_list_add(*(const char ***)parm_ptr
,
1368 } else if (*(const char ***)parm_ptr
!= NULL
&&
1369 new_list
[i
][0] == '-' &&
1372 str_list_remove(*(const char ***)parm_ptr
,
1376 DEBUG(0, ("Unsupported list syntax for: %s = %s\n",
1377 pszParmName
, pszParmValue
));
1380 *(const char ***)parm_ptr
= (const char **) new_list
;
1387 lpcfg_string_set(mem_ctx
, (char **)parm_ptr
, pszParmValue
);
1391 lpcfg_string_set_upper(mem_ctx
, (char **)parm_ptr
, pszParmValue
);
1395 for (i
= 0; parm_table
[parmnum
].enum_list
[i
].name
; i
++) {
1398 parm_table
[parmnum
].enum_list
[i
].name
)) {
1400 parm_table
[parmnum
].
1405 if (!parm_table
[parmnum
].enum_list
[i
].name
) {
1406 DEBUG(0,("Unknown enumerated value '%s' for '%s'\n",
1407 pszParmValue
, pszParmName
));
1417 if (on_globals
&& (lp_ctx
->flags
[parmnum
] & FLAG_DEFAULT
)) {
1418 lp_ctx
->flags
[parmnum
] &= ~FLAG_DEFAULT
;
1419 /* we have to also unset FLAG_DEFAULT on aliases */
1420 for (i
=parmnum
-1;i
>=0 && parm_table
[i
].offset
== parm_table
[parmnum
].offset
;i
--) {
1421 lp_ctx
->flags
[i
] &= ~FLAG_DEFAULT
;
1423 for (i
=parmnum
+1;i
<NUMPARAMETERS
&& parm_table
[i
].offset
== parm_table
[parmnum
].offset
;i
++) {
1424 lp_ctx
->flags
[i
] &= ~FLAG_DEFAULT
;
1431 bool lpcfg_do_global_parameter(struct loadparm_context
*lp_ctx
,
1432 const char *pszParmName
, const char *pszParmValue
)
1434 int parmnum
= map_parameter(pszParmName
);
1438 if (strchr(pszParmName
, ':')) {
1439 return lp_do_parameter_parametric(lp_ctx
, NULL
, pszParmName
, pszParmValue
, 0);
1441 DEBUG(0, ("Ignoring unknown parameter \"%s\"\n", pszParmName
));
1445 /* if the flag has been set on the command line, then don't allow override,
1446 but don't report an error */
1447 if (lp_ctx
->flags
[parmnum
] & FLAG_CMDLINE
) {
1451 parm_ptr
= lpcfg_parm_ptr(lp_ctx
, NULL
, &parm_table
[parmnum
]);
1453 return set_variable(lp_ctx
->globals
, parmnum
, parm_ptr
,
1454 pszParmName
, pszParmValue
, lp_ctx
, true);
1457 bool lpcfg_do_service_parameter(struct loadparm_context
*lp_ctx
,
1458 struct loadparm_service
*service
,
1459 const char *pszParmName
, const char *pszParmValue
)
1463 int parmnum
= map_parameter(pszParmName
);
1466 if (strchr(pszParmName
, ':')) {
1467 return lp_do_parameter_parametric(lp_ctx
, service
, pszParmName
, pszParmValue
, 0);
1469 DEBUG(0, ("Ignoring unknown parameter \"%s\"\n", pszParmName
));
1473 /* if the flag has been set on the command line, then don't allow override,
1474 but don't report an error */
1475 if (lp_ctx
->flags
[parmnum
] & FLAG_CMDLINE
) {
1479 if (parm_table
[parmnum
].p_class
== P_GLOBAL
) {
1481 ("Global parameter %s found in service section!\n",
1485 parm_ptr
= ((char *)service
) + parm_table
[parmnum
].offset
;
1487 if (!service
->copymap
)
1488 init_copymap(service
);
1490 /* this handles the aliases - set the copymap for other
1491 * entries with the same data pointer */
1492 for (i
= 0; parm_table
[i
].label
; i
++)
1493 if (parm_table
[i
].offset
== parm_table
[parmnum
].offset
&&
1494 parm_table
[i
].p_class
== parm_table
[parmnum
].p_class
)
1495 bitmap_clear(service
->copymap
, i
);
1497 return set_variable(service
, parmnum
, parm_ptr
, pszParmName
,
1498 pszParmValue
, lp_ctx
, false);
1502 * Process a parameter.
1505 static bool do_parameter(const char *pszParmName
, const char *pszParmValue
,
1508 struct loadparm_context
*lp_ctx
= (struct loadparm_context
*)userdata
;
1510 if (lp_ctx
->bInGlobalSection
)
1511 return lpcfg_do_global_parameter(lp_ctx
, pszParmName
,
1514 return lpcfg_do_service_parameter(lp_ctx
, lp_ctx
->currentService
,
1515 pszParmName
, pszParmValue
);
1519 variable argument do parameter
1521 bool lpcfg_do_global_parameter_var(struct loadparm_context
*lp_ctx
, const char *pszParmName
, const char *fmt
, ...) PRINTF_ATTRIBUTE(3, 4);
1522 bool lpcfg_do_global_parameter_var(struct loadparm_context
*lp_ctx
,
1523 const char *pszParmName
, const char *fmt
, ...)
1530 s
= talloc_vasprintf(NULL
, fmt
, ap
);
1532 ret
= lpcfg_do_global_parameter(lp_ctx
, pszParmName
, s
);
1539 set a parameter from the commandline - this is called from command line parameter
1540 parsing code. It sets the parameter then marks the parameter as unable to be modified
1541 by smb.conf processing
1543 bool lpcfg_set_cmdline(struct loadparm_context
*lp_ctx
, const char *pszParmName
,
1544 const char *pszParmValue
)
1549 if (lp_ctx
->s3_fns
) {
1550 return lp_ctx
->s3_fns
->set_cmdline(pszParmName
, pszParmValue
);
1553 parmnum
= map_parameter(pszParmName
);
1555 while (isspace((unsigned char)*pszParmValue
)) pszParmValue
++;
1558 if (parmnum
< 0 && strchr(pszParmName
, ':')) {
1559 /* set a parametric option */
1560 return lp_do_parameter_parametric(lp_ctx
, NULL
, pszParmName
,
1561 pszParmValue
, FLAG_CMDLINE
);
1565 DEBUG(0,("Unknown option '%s'\n", pszParmName
));
1569 /* reset the CMDLINE flag in case this has been called before */
1570 lp_ctx
->flags
[parmnum
] &= ~FLAG_CMDLINE
;
1572 if (!lpcfg_do_global_parameter(lp_ctx
, pszParmName
, pszParmValue
)) {
1576 lp_ctx
->flags
[parmnum
] |= FLAG_CMDLINE
;
1578 /* we have to also set FLAG_CMDLINE on aliases */
1579 for (i
=parmnum
-1;i
>=0 && parm_table
[i
].offset
== parm_table
[parmnum
].offset
;i
--) {
1580 lp_ctx
->flags
[i
] |= FLAG_CMDLINE
;
1582 for (i
=parmnum
+1;i
<NUMPARAMETERS
&& parm_table
[i
].offset
== parm_table
[parmnum
].offset
;i
++) {
1583 lp_ctx
->flags
[i
] |= FLAG_CMDLINE
;
1590 set a option from the commandline in 'a=b' format. Use to support --option
1592 bool lpcfg_set_option(struct loadparm_context
*lp_ctx
, const char *option
)
1597 s
= talloc_strdup(NULL
, option
);
1610 ret
= lpcfg_set_cmdline(lp_ctx
, s
, p
+1);
1616 #define BOOLSTR(b) ((b) ? "Yes" : "No")
1619 * Print a parameter of the specified type.
1622 static void print_parameter(struct parm_struct
*p
, void *ptr
, FILE * f
)
1624 /* For the seperation of lists values that we print below */
1625 const char *list_sep
= ", ";
1630 for (i
= 0; p
->enum_list
[i
].name
; i
++) {
1631 if (*(int *)ptr
== p
->enum_list
[i
].value
) {
1633 p
->enum_list
[i
].name
);
1640 fprintf(f
, "%s", BOOLSTR(*(bool *)ptr
));
1644 fprintf(f
, "%s", BOOLSTR(!*(bool *)ptr
));
1649 fprintf(f
, "%d", *(int *)ptr
);
1653 fprintf(f
, "%c", *(char *)ptr
);
1657 int val
= *(int *)ptr
;
1661 fprintf(f
, "0%o", val
);
1670 if ((char ***)ptr
&& *(char ***)ptr
) {
1671 char **list
= *(char ***)ptr
;
1672 for (; *list
; list
++) {
1673 /* surround strings with whitespace in double quotes */
1674 if (*(list
+1) == NULL
) {
1675 /* last item, no extra separator */
1678 if ( strchr_m( *list
, ' ' ) ) {
1679 fprintf(f
, "\"%s\"%s", *list
, list_sep
);
1681 fprintf(f
, "%s%s", *list
, list_sep
);
1689 if (*(char **)ptr
) {
1690 fprintf(f
, "%s", *(char **)ptr
);
1699 * Check if two parameters are equal.
1702 static bool equal_parameter(parm_type type
, void *ptr1
, void *ptr2
)
1707 return (*((bool *)ptr1
) == *((bool *)ptr2
));
1713 return (*((int *)ptr1
) == *((int *)ptr2
));
1716 return (*((char *)ptr1
) == *((char *)ptr2
));
1720 return str_list_equal(*(const char ***)ptr1
, *(const char ***)ptr2
);
1725 char *p1
= *(char **)ptr1
, *p2
= *(char **)ptr2
;
1730 return (p1
== p2
|| strequal(p1
, p2
));
1739 * Process a new section (service).
1741 * At this stage all sections are services.
1742 * Later we'll have special sections that permit server parameters to be set.
1743 * Returns True on success, False on failure.
1746 static bool do_section(const char *pszSectionName
, void *userdata
)
1748 struct loadparm_context
*lp_ctx
= (struct loadparm_context
*)userdata
;
1750 bool isglobal
= ((strwicmp(pszSectionName
, GLOBAL_NAME
) == 0) ||
1751 (strwicmp(pszSectionName
, GLOBAL_NAME2
) == 0));
1754 /* if we've just struck a global section, note the fact. */
1755 lp_ctx
->bInGlobalSection
= isglobal
;
1757 /* check for multiple global sections */
1758 if (lp_ctx
->bInGlobalSection
) {
1759 DEBUG(4, ("Processing section \"[%s]\"\n", pszSectionName
));
1763 /* if we have a current service, tidy it up before moving on */
1766 if (lp_ctx
->currentService
!= NULL
)
1767 bRetval
= lpcfg_service_ok(lp_ctx
->currentService
);
1769 /* if all is still well, move to the next record in the services array */
1771 /* We put this here to avoid an odd message order if messages are */
1772 /* issued by the post-processing of a previous section. */
1773 DEBUG(4, ("Processing section \"[%s]\"\n", pszSectionName
));
1775 if ((lp_ctx
->currentService
= lpcfg_add_service(lp_ctx
, lp_ctx
->sDefault
,
1778 DEBUG(0, ("Failed to add a new service\n"));
1788 * Determine if a particular base parameter is currently set to the default value.
1791 static bool is_default(struct loadparm_service
*sDefault
, int i
)
1793 void *def_ptr
= ((char *)sDefault
) + parm_table
[i
].offset
;
1794 if (!defaults_saved
)
1796 switch (parm_table
[i
].type
) {
1799 return str_list_equal((const char **)parm_table
[i
].def
.lvalue
,
1800 (const char **)def_ptr
);
1803 return strequal(parm_table
[i
].def
.svalue
,
1807 return parm_table
[i
].def
.bvalue
==
1814 return parm_table
[i
].def
.ivalue
==
1823 *Display the contents of the global structure.
1826 static void dump_globals(struct loadparm_context
*lp_ctx
, FILE *f
,
1830 struct parmlist_entry
*data
;
1832 fprintf(f
, "# Global parameters\n[global]\n");
1834 for (i
= 0; parm_table
[i
].label
; i
++)
1835 if (parm_table
[i
].p_class
== P_GLOBAL
&&
1836 (i
== 0 || (parm_table
[i
].offset
!= parm_table
[i
- 1].offset
))) {
1837 if (!show_defaults
&& (lp_ctx
->flags
[i
] & FLAG_DEFAULT
))
1839 fprintf(f
, "\t%s = ", parm_table
[i
].label
);
1840 print_parameter(&parm_table
[i
], lpcfg_parm_ptr(lp_ctx
, NULL
, &parm_table
[i
]), f
);
1843 if (lp_ctx
->globals
->param_opt
!= NULL
) {
1844 for (data
= lp_ctx
->globals
->param_opt
; data
;
1845 data
= data
->next
) {
1846 if (!show_defaults
&& (data
->priority
& FLAG_DEFAULT
)) {
1849 fprintf(f
, "\t%s = %s\n", data
->key
, data
->value
);
1856 * Display the contents of a single services record.
1859 static void dump_a_service(struct loadparm_service
* pService
, struct loadparm_service
*sDefault
, FILE * f
,
1860 unsigned int *flags
)
1863 struct parmlist_entry
*data
;
1865 if (pService
!= sDefault
)
1866 fprintf(f
, "\n[%s]\n", pService
->szService
);
1868 for (i
= 0; parm_table
[i
].label
; i
++) {
1869 if (parm_table
[i
].p_class
== P_LOCAL
&&
1870 (*parm_table
[i
].label
!= '-') &&
1871 (i
== 0 || (parm_table
[i
].offset
!= parm_table
[i
- 1].offset
)))
1873 if (pService
== sDefault
) {
1874 if (flags
&& (flags
[i
] & FLAG_DEFAULT
)) {
1877 if (defaults_saved
) {
1878 if (is_default(sDefault
, i
)) {
1883 if (equal_parameter(parm_table
[i
].type
,
1884 ((char *)pService
) +
1885 parm_table
[i
].offset
,
1886 ((char *)sDefault
) +
1887 parm_table
[i
].offset
))
1891 fprintf(f
, "\t%s = ", parm_table
[i
].label
);
1892 print_parameter(&parm_table
[i
],
1893 ((char *)pService
) + parm_table
[i
].offset
, f
);
1897 if (pService
->param_opt
!= NULL
) {
1898 for (data
= pService
->param_opt
; data
; data
= data
->next
) {
1899 fprintf(f
, "\t%s = %s\n", data
->key
, data
->value
);
1904 bool lpcfg_dump_a_parameter(struct loadparm_context
*lp_ctx
,
1905 struct loadparm_service
*service
,
1906 const char *parm_name
, FILE * f
)
1908 struct parm_struct
*parm
;
1911 parm
= lpcfg_parm_struct(lp_ctx
, parm_name
);
1916 ptr
= lpcfg_parm_ptr(lp_ctx
, service
,parm
);
1918 print_parameter(parm
, ptr
, f
);
1924 * Return info about the next parameter in a service.
1925 * snum==-1 gives the globals.
1926 * Return NULL when out of parameters.
1930 struct parm_struct
*lpcfg_next_parameter(struct loadparm_context
*lp_ctx
, int snum
, int *i
,
1934 /* do the globals */
1935 for (; parm_table
[*i
].label
; (*i
)++) {
1936 if ((*parm_table
[*i
].label
== '-'))
1940 && (parm_table
[*i
].offset
==
1941 parm_table
[(*i
) - 1].offset
)
1942 && (parm_table
[*i
].p_class
==
1943 parm_table
[(*i
) - 1].p_class
))
1946 return &parm_table
[(*i
)++];
1949 struct loadparm_service
*pService
= lp_ctx
->services
[snum
];
1951 for (; parm_table
[*i
].label
; (*i
)++) {
1952 if (parm_table
[*i
].p_class
== P_LOCAL
&&
1953 (*parm_table
[*i
].label
!= '-') &&
1955 (parm_table
[*i
].offset
!=
1956 parm_table
[(*i
) - 1].offset
)))
1958 if (allparameters
||
1959 !equal_parameter(parm_table
[*i
].type
,
1960 ((char *)pService
) +
1961 parm_table
[*i
].offset
,
1962 ((char *)lp_ctx
->sDefault
) +
1963 parm_table
[*i
].offset
))
1965 return &parm_table
[(*i
)++];
1976 * Auto-load some home services.
1978 static void lpcfg_add_auto_services(struct loadparm_context
*lp_ctx
,
1986 * Unload unused services.
1989 void lpcfg_killunused(struct loadparm_context
*lp_ctx
,
1990 struct smbsrv_connection
*smb
,
1991 bool (*snumused
) (struct smbsrv_connection
*, int))
1994 for (i
= 0; i
< lp_ctx
->iNumServices
; i
++) {
1995 if (lp_ctx
->services
[i
] == NULL
)
1998 if (!snumused
|| !snumused(smb
, i
)) {
1999 talloc_free(lp_ctx
->services
[i
]);
2000 lp_ctx
->services
[i
] = NULL
;
2006 static int lpcfg_destructor(struct loadparm_context
*lp_ctx
)
2008 struct parmlist_entry
*data
;
2010 if (lp_ctx
->refuse_free
) {
2011 /* someone is trying to free the
2012 global_loadparm_context.
2013 We can't allow that. */
2017 if (lp_ctx
->globals
->param_opt
!= NULL
) {
2018 struct parmlist_entry
*next
;
2019 for (data
= lp_ctx
->globals
->param_opt
; data
; data
=next
) {
2021 if (data
->priority
& FLAG_CMDLINE
) continue;
2022 DLIST_REMOVE(lp_ctx
->globals
->param_opt
, data
);
2031 * Initialise the global parameter structure.
2033 * Note that most callers should use loadparm_init_global() instead
2035 struct loadparm_context
*loadparm_init(TALLOC_CTX
*mem_ctx
)
2039 struct loadparm_context
*lp_ctx
;
2040 struct parmlist_entry
*parm
;
2043 lp_ctx
= talloc_zero(mem_ctx
, struct loadparm_context
);
2047 talloc_set_destructor(lp_ctx
, lpcfg_destructor
);
2048 lp_ctx
->bInGlobalSection
= true;
2049 lp_ctx
->globals
= talloc_zero(lp_ctx
, struct loadparm_global
);
2050 lp_ctx
->sDefault
= talloc_zero(lp_ctx
, struct loadparm_service
);
2052 lp_ctx
->sDefault
->iMaxPrintJobs
= 1000;
2053 lp_ctx
->sDefault
->bAvailable
= true;
2054 lp_ctx
->sDefault
->bBrowseable
= true;
2055 lp_ctx
->sDefault
->bRead_only
= true;
2056 lp_ctx
->sDefault
->bMap_archive
= true;
2057 lp_ctx
->sDefault
->iStrictLocking
= true;
2058 lp_ctx
->sDefault
->bOpLocks
= true;
2059 lp_ctx
->sDefault
->iCreate_mask
= 0744;
2060 lp_ctx
->sDefault
->iCreate_force_mode
= 0000;
2061 lp_ctx
->sDefault
->iDir_mask
= 0755;
2062 lp_ctx
->sDefault
->iDir_force_mode
= 0000;
2064 DEBUG(3, ("Initialising global parameters\n"));
2066 for (i
= 0; parm_table
[i
].label
; i
++) {
2067 if ((parm_table
[i
].type
== P_STRING
||
2068 parm_table
[i
].type
== P_USTRING
) &&
2069 !(lp_ctx
->flags
[i
] & FLAG_CMDLINE
)) {
2071 if (parm_table
[i
].p_class
== P_LOCAL
) {
2072 r
= (char **)(((char *)lp_ctx
->sDefault
) + parm_table
[i
].offset
);
2074 r
= (char **)(((char *)lp_ctx
->globals
) + parm_table
[i
].offset
);
2076 *r
= talloc_strdup(lp_ctx
, "");
2080 logfile
= talloc_asprintf(lp_ctx
, "%s/log.samba", dyn_LOGFILEBASE
);
2081 lpcfg_do_global_parameter(lp_ctx
, "log file", logfile
);
2082 talloc_free(logfile
);
2084 lpcfg_do_global_parameter(lp_ctx
, "log level", "0");
2086 lpcfg_do_global_parameter(lp_ctx
, "share backend", "classic");
2088 lpcfg_do_global_parameter(lp_ctx
, "server role", "auto");
2089 lpcfg_do_global_parameter(lp_ctx
, "domain logons", "No");
2090 lpcfg_do_global_parameter(lp_ctx
, "domain master", "Auto");
2092 /* options that can be set on the command line must be initialised via
2093 the slower lpcfg_do_global_parameter() to ensure that FLAG_CMDLINE is obeyed */
2095 lpcfg_do_global_parameter(lp_ctx
, "socket options", "TCP_NODELAY");
2097 lpcfg_do_global_parameter(lp_ctx
, "workgroup", DEFAULT_WORKGROUP
);
2098 myname
= get_myname(lp_ctx
);
2099 lpcfg_do_global_parameter(lp_ctx
, "netbios name", myname
);
2100 talloc_free(myname
);
2101 lpcfg_do_global_parameter(lp_ctx
, "name resolve order", "wins host bcast");
2103 lpcfg_do_global_parameter(lp_ctx
, "fstype", "NTFS");
2105 lpcfg_do_global_parameter(lp_ctx
, "ntvfs handler", "unixuid default");
2106 lpcfg_do_global_parameter(lp_ctx
, "max connections", "-1");
2108 lpcfg_do_global_parameter(lp_ctx
, "dcerpc endpoint servers", "epmapper wkssvc rpcecho samr netlogon lsarpc spoolss drsuapi dssetup unixinfo browser eventlog6 backupkey dnsserver");
2109 lpcfg_do_global_parameter(lp_ctx
, "server services", "s3fs rpc nbt wrepl ldap cldap kdc drepl winbind ntp_signd kcc dnsupdate dns");
2110 /* the winbind method for domain controllers is for both RODC
2111 auth forwarding and for trusted domains */
2112 lpcfg_do_global_parameter(lp_ctx
, "private dir", dyn_PRIVATE_DIR
);
2113 lpcfg_do_global_parameter(lp_ctx
, "registry:HKEY_LOCAL_MACHINE", "hklm.ldb");
2115 /* This hive should be dynamically generated by Samba using
2116 data from the sam, but for the moment leave it in a tdb to
2117 keep regedt32 from popping up an annoying dialog. */
2118 lpcfg_do_global_parameter(lp_ctx
, "registry:HKEY_USERS", "hku.ldb");
2120 /* using UTF8 by default allows us to support all chars */
2121 lpcfg_do_global_parameter(lp_ctx
, "unix charset", "UTF8");
2123 /* Use codepage 850 as a default for the dos character set */
2124 lpcfg_do_global_parameter(lp_ctx
, "dos charset", "CP850");
2127 * Allow the default PASSWD_CHAT to be overridden in local.h.
2129 lpcfg_do_global_parameter(lp_ctx
, "passwd chat", DEFAULT_PASSWD_CHAT
);
2131 lpcfg_do_global_parameter(lp_ctx
, "pid directory", dyn_PIDDIR
);
2132 lpcfg_do_global_parameter(lp_ctx
, "lock dir", dyn_LOCKDIR
);
2133 lpcfg_do_global_parameter(lp_ctx
, "state directory", dyn_STATEDIR
);
2134 lpcfg_do_global_parameter(lp_ctx
, "cache directory", dyn_CACHEDIR
);
2135 lpcfg_do_global_parameter(lp_ctx
, "ncalrpc dir", dyn_NCALRPCDIR
);
2137 lpcfg_do_global_parameter(lp_ctx
, "nbt client socket address", "");
2138 lpcfg_do_global_parameter_var(lp_ctx
, "server string",
2139 "Samba %s", SAMBA_VERSION_STRING
);
2141 lpcfg_do_global_parameter(lp_ctx
, "password server", "*");
2143 lpcfg_do_global_parameter(lp_ctx
, "max mux", "50");
2144 lpcfg_do_global_parameter(lp_ctx
, "max xmit", "12288");
2145 lpcfg_do_global_parameter(lp_ctx
, "host msdfs", "true");
2147 lpcfg_do_global_parameter(lp_ctx
, "password level", "0");
2148 lpcfg_do_global_parameter(lp_ctx
, "LargeReadwrite", "True");
2149 lpcfg_do_global_parameter(lp_ctx
, "server min protocol", "CORE");
2150 lpcfg_do_global_parameter(lp_ctx
, "server max protocol", "NT1");
2151 lpcfg_do_global_parameter(lp_ctx
, "client min protocol", "CORE");
2152 lpcfg_do_global_parameter(lp_ctx
, "client max protocol", "NT1");
2153 lpcfg_do_global_parameter(lp_ctx
, "security", "AUTO");
2154 lpcfg_do_global_parameter(lp_ctx
, "EncryptPasswords", "True");
2155 lpcfg_do_global_parameter(lp_ctx
, "ReadRaw", "True");
2156 lpcfg_do_global_parameter(lp_ctx
, "WriteRaw", "True");
2157 lpcfg_do_global_parameter(lp_ctx
, "NullPasswords", "False");
2158 lpcfg_do_global_parameter(lp_ctx
, "ObeyPamRestrictions", "False");
2160 lpcfg_do_global_parameter(lp_ctx
, "TimeServer", "False");
2161 lpcfg_do_global_parameter(lp_ctx
, "BindInterfacesOnly", "False");
2162 lpcfg_do_global_parameter(lp_ctx
, "Unicode", "True");
2163 lpcfg_do_global_parameter(lp_ctx
, "ClientLanManAuth", "False");
2164 lpcfg_do_global_parameter(lp_ctx
, "ClientNTLMv2Auth", "True");
2165 lpcfg_do_global_parameter(lp_ctx
, "LanmanAuth", "False");
2166 lpcfg_do_global_parameter(lp_ctx
, "NTLMAuth", "True");
2167 lpcfg_do_global_parameter(lp_ctx
, "client use spnego principal", "False");
2169 lpcfg_do_global_parameter(lp_ctx
, "UnixExtensions", "False");
2171 lpcfg_do_global_parameter(lp_ctx
, "PreferredMaster", "Auto");
2172 lpcfg_do_global_parameter(lp_ctx
, "LocalMaster", "True");
2174 lpcfg_do_global_parameter(lp_ctx
, "wins support", "False");
2175 lpcfg_do_global_parameter(lp_ctx
, "dns proxy", "True");
2177 lpcfg_do_global_parameter(lp_ctx
, "winbind separator", "\\");
2178 lpcfg_do_global_parameter(lp_ctx
, "winbind sealed pipes", "True");
2179 lpcfg_do_global_parameter(lp_ctx
, "winbindd socket directory", dyn_WINBINDD_SOCKET_DIR
);
2180 #if _SAMBA_BUILD_ >= 4
2181 lpcfg_do_global_parameter(lp_ctx
, "winbindd privileged socket directory", dyn_WINBINDD_PRIVILEGED_SOCKET_DIR
);
2182 lpcfg_do_global_parameter(lp_ctx
, "ntp signd socket directory", dyn_NTP_SIGND_SOCKET_DIR
);
2183 lpcfg_do_global_parameter_var(lp_ctx
, "dns update command", "%s/samba_dnsupdate", dyn_SCRIPTSBINDIR
);
2184 lpcfg_do_global_parameter_var(lp_ctx
, "spn update command", "%s/samba_spnupdate", dyn_SCRIPTSBINDIR
);
2185 lpcfg_do_global_parameter_var(lp_ctx
, "samba kcc command",
2186 "%s/samba_kcc", dyn_SCRIPTSBINDIR
);
2188 lpcfg_do_global_parameter(lp_ctx
, "template shell", "/bin/false");
2189 lpcfg_do_global_parameter(lp_ctx
, "template homedir", "/home/%WORKGROUP%/%ACCOUNTNAME%");
2191 lpcfg_do_global_parameter(lp_ctx
, "client signing", "default");
2192 lpcfg_do_global_parameter(lp_ctx
, "server signing", "default");
2194 lpcfg_do_global_parameter(lp_ctx
, "use spnego", "True");
2196 lpcfg_do_global_parameter(lp_ctx
, "use mmap", "True");
2198 lpcfg_do_global_parameter(lp_ctx
, "smb ports", "445 139");
2199 lpcfg_do_global_parameter(lp_ctx
, "nbt port", "137");
2200 lpcfg_do_global_parameter(lp_ctx
, "dgram port", "138");
2201 lpcfg_do_global_parameter(lp_ctx
, "cldap port", "389");
2202 lpcfg_do_global_parameter(lp_ctx
, "krb5 port", "88");
2203 lpcfg_do_global_parameter(lp_ctx
, "kpasswd port", "464");
2204 lpcfg_do_global_parameter(lp_ctx
, "web port", "901");
2206 lpcfg_do_global_parameter(lp_ctx
, "nt status support", "True");
2208 lpcfg_do_global_parameter(lp_ctx
, "max wins ttl", "518400"); /* 6 days */
2209 lpcfg_do_global_parameter(lp_ctx
, "min wins ttl", "10");
2211 lpcfg_do_global_parameter(lp_ctx
, "tls enabled", "True");
2212 lpcfg_do_global_parameter(lp_ctx
, "tls keyfile", "tls/key.pem");
2213 lpcfg_do_global_parameter(lp_ctx
, "tls certfile", "tls/cert.pem");
2214 lpcfg_do_global_parameter(lp_ctx
, "tls cafile", "tls/ca.pem");
2215 lpcfg_do_global_parameter(lp_ctx
, "prefork children:smb", "4");
2217 lpcfg_do_global_parameter(lp_ctx
, "rndc command", "/usr/sbin/rndc");
2218 lpcfg_do_global_parameter(lp_ctx
, "nsupdate command", "/usr/bin/nsupdate -g");
2220 lpcfg_do_global_parameter(lp_ctx
, "allow dns updates", "secure only");
2221 lpcfg_do_global_parameter(lp_ctx
, "dns forwarder", "");
2223 for (i
= 0; parm_table
[i
].label
; i
++) {
2224 if (!(lp_ctx
->flags
[i
] & FLAG_CMDLINE
)) {
2225 lp_ctx
->flags
[i
] |= FLAG_DEFAULT
;
2229 for (parm
=lp_ctx
->globals
->param_opt
; parm
; parm
=parm
->next
) {
2230 if (!(parm
->priority
& FLAG_CMDLINE
)) {
2231 parm
->priority
|= FLAG_DEFAULT
;
2239 * Initialise the global parameter structure.
2241 struct loadparm_context
*loadparm_init_global(bool load_default
)
2243 if (global_loadparm_context
== NULL
) {
2244 global_loadparm_context
= loadparm_init(NULL
);
2246 if (global_loadparm_context
== NULL
) {
2249 global_loadparm_context
->global
= true;
2250 if (load_default
&& !global_loadparm_context
->loaded
) {
2251 lpcfg_load_default(global_loadparm_context
);
2253 global_loadparm_context
->refuse_free
= true;
2254 return global_loadparm_context
;
2258 * Initialise the global parameter structure.
2260 struct loadparm_context
*loadparm_init_s3(TALLOC_CTX
*mem_ctx
,
2261 const struct loadparm_s3_helpers
*s3_fns
)
2263 struct loadparm_context
*loadparm_context
= talloc_zero(mem_ctx
, struct loadparm_context
);
2264 if (!loadparm_context
) {
2267 loadparm_context
->s3_fns
= s3_fns
;
2268 return loadparm_context
;
2271 const char *lpcfg_configfile(struct loadparm_context
*lp_ctx
)
2273 return lp_ctx
->szConfigFile
;
2276 const char *lp_default_path(void)
2278 if (getenv("SMB_CONF_PATH"))
2279 return getenv("SMB_CONF_PATH");
2281 return dyn_CONFIGFILE
;
2285 * Update the internal state of a loadparm context after settings
2288 static bool lpcfg_update(struct loadparm_context
*lp_ctx
)
2290 struct debug_settings settings
;
2291 lpcfg_add_auto_services(lp_ctx
, lpcfg_auto_services(lp_ctx
));
2293 if (!lp_ctx
->globals
->szWINSservers
&& lp_ctx
->globals
->bWINSsupport
) {
2294 lpcfg_do_global_parameter(lp_ctx
, "wins server", "127.0.0.1");
2297 if (!lp_ctx
->global
) {
2301 panic_action
= lp_ctx
->globals
->szPanicAction
;
2303 reload_charcnv(lp_ctx
);
2305 ZERO_STRUCT(settings
);
2306 /* Add any more debug-related smb.conf parameters created in
2308 settings
.timestamp_logs
= true;
2309 debug_set_settings(&settings
);
2311 /* FIXME: This is a bit of a hack, but we can't use a global, since
2312 * not everything that uses lp also uses the socket library */
2313 if (lpcfg_parm_bool(lp_ctx
, NULL
, "socket", "testnonblock", false)) {
2314 setenv("SOCKET_TESTNONBLOCK", "1", 1);
2316 unsetenv("SOCKET_TESTNONBLOCK");
2322 bool lpcfg_load_default(struct loadparm_context
*lp_ctx
)
2326 path
= lp_default_path();
2328 if (!file_exist(path
)) {
2329 /* We allow the default smb.conf file to not exist,
2330 * basically the equivalent of an empty file. */
2331 return lpcfg_update(lp_ctx
);
2334 return lpcfg_load(lp_ctx
, path
);
2338 * Load the services array from the services file.
2340 * Return True on success, False on failure.
2342 bool lpcfg_load(struct loadparm_context
*lp_ctx
, const char *filename
)
2347 filename
= talloc_strdup(lp_ctx
, filename
);
2349 lp_ctx
->szConfigFile
= filename
;
2351 if (lp_ctx
->s3_fns
) {
2352 return lp_ctx
->s3_fns
->load(filename
);
2355 lp_ctx
->bInGlobalSection
= true;
2356 n2
= standard_sub_basic(lp_ctx
, lp_ctx
->szConfigFile
);
2357 DEBUG(2, ("lpcfg_load: refreshing parameters from %s\n", n2
));
2359 add_to_file_list(lp_ctx
, lp_ctx
->szConfigFile
, n2
);
2361 /* We get sections first, so have to start 'behind' to make up */
2362 lp_ctx
->currentService
= NULL
;
2363 bRetval
= pm_process(n2
, do_section
, do_parameter
, lp_ctx
);
2365 /* finish up the last section */
2366 DEBUG(4, ("pm_process() returned %s\n", BOOLSTR(bRetval
)));
2368 if (lp_ctx
->currentService
!= NULL
)
2369 bRetval
= lpcfg_service_ok(lp_ctx
->currentService
);
2371 bRetval
= bRetval
&& lpcfg_update(lp_ctx
);
2373 /* we do this unconditionally, so that it happens even
2374 for a missing smb.conf */
2375 reload_charcnv(lp_ctx
);
2377 if (bRetval
== true) {
2378 /* set this up so that any child python tasks will
2379 find the right smb.conf */
2380 setenv("SMB_CONF_PATH", filename
, 1);
2382 /* set the context used by the lp_*() function
2384 global_loadparm_context
= lp_ctx
;
2385 lp_ctx
->loaded
= true;
2392 * Return the max number of services.
2395 int lpcfg_numservices(struct loadparm_context
*lp_ctx
)
2397 if (lp_ctx
->s3_fns
) {
2398 return lp_ctx
->s3_fns
->get_numservices();
2401 return lp_ctx
->iNumServices
;
2405 * Display the contents of the services array in human-readable form.
2408 void lpcfg_dump(struct loadparm_context
*lp_ctx
, FILE *f
, bool show_defaults
,
2413 if (lp_ctx
->s3_fns
) {
2414 lp_ctx
->s3_fns
->dump(f
, show_defaults
, maxtoprint
);
2418 defaults_saved
= !show_defaults
;
2420 dump_globals(lp_ctx
, f
, show_defaults
);
2422 dump_a_service(lp_ctx
->sDefault
, lp_ctx
->sDefault
, f
, lp_ctx
->flags
);
2424 for (iService
= 0; iService
< maxtoprint
; iService
++)
2425 lpcfg_dump_one(f
, show_defaults
, lp_ctx
->services
[iService
], lp_ctx
->sDefault
);
2429 * Display the contents of one service in human-readable form.
2431 void lpcfg_dump_one(FILE *f
, bool show_defaults
, struct loadparm_service
*service
, struct loadparm_service
*sDefault
)
2433 if (service
!= NULL
) {
2434 if (service
->szService
[0] == '\0')
2436 dump_a_service(service
, sDefault
, f
, NULL
);
2440 struct loadparm_service
*lpcfg_servicebynum(struct loadparm_context
*lp_ctx
,
2443 if (lp_ctx
->s3_fns
) {
2444 return lp_ctx
->s3_fns
->get_servicebynum(snum
);
2447 return lp_ctx
->services
[snum
];
2450 struct loadparm_service
*lpcfg_service(struct loadparm_context
*lp_ctx
,
2451 const char *service_name
)
2456 if (lp_ctx
->s3_fns
) {
2457 return lp_ctx
->s3_fns
->get_service(service_name
);
2460 for (iService
= lp_ctx
->iNumServices
- 1; iService
>= 0; iService
--) {
2461 if (lp_ctx
->services
[iService
] &&
2462 lp_ctx
->services
[iService
]->szService
) {
2464 * The substitution here is used to support %U is
2467 serviceName
= standard_sub_basic(
2468 lp_ctx
->services
[iService
],
2469 lp_ctx
->services
[iService
]->szService
);
2470 if (strequal(serviceName
, service_name
)) {
2471 talloc_free(serviceName
);
2472 return lp_ctx
->services
[iService
];
2474 talloc_free(serviceName
);
2478 DEBUG(7,("lpcfg_servicenumber: couldn't find %s\n", service_name
));
2482 const char *lpcfg_servicename(const struct loadparm_service
*service
)
2484 return lp_string((const char *)service
->szService
);
2488 * A useful volume label function.
2490 const char *lpcfg_volume_label(struct loadparm_service
*service
, struct loadparm_service
*sDefault
)
2493 ret
= lp_string((const char *)((service
!= NULL
&& service
->volume
!= NULL
) ?
2494 service
->volume
: sDefault
->volume
));
2496 return lpcfg_servicename(service
);
2501 * If we are PDC then prefer us as DMB
2503 const char *lpcfg_printername(struct loadparm_service
*service
, struct loadparm_service
*sDefault
)
2506 ret
= lp_string((const char *)((service
!= NULL
&& service
->szPrintername
!= NULL
) ?
2507 service
->szPrintername
: sDefault
->szPrintername
));
2508 if (ret
== NULL
|| (ret
!= NULL
&& *ret
== '\0'))
2509 ret
= lpcfg_servicename(service
);
2516 * Return the max print jobs per queue.
2518 int lpcfg_maxprintjobs(struct loadparm_service
*service
, struct loadparm_service
*sDefault
)
2520 int maxjobs
= (service
!= NULL
) ? service
->iMaxPrintJobs
: sDefault
->iMaxPrintJobs
;
2521 if (maxjobs
<= 0 || maxjobs
>= PRINT_MAX_JOBID
)
2522 maxjobs
= PRINT_MAX_JOBID
- 1;
2527 struct smb_iconv_handle
*lpcfg_iconv_handle(struct loadparm_context
*lp_ctx
)
2529 if (lp_ctx
== NULL
) {
2530 return get_iconv_handle();
2532 return lp_ctx
->iconv_handle
;
2535 _PUBLIC_
void reload_charcnv(struct loadparm_context
*lp_ctx
)
2537 struct smb_iconv_handle
*old_ic
= lp_ctx
->iconv_handle
;
2538 if (!lp_ctx
->global
) {
2542 if (old_ic
== NULL
) {
2543 old_ic
= global_iconv_handle
;
2545 lp_ctx
->iconv_handle
= smb_iconv_handle_reinit_lp(lp_ctx
, lp_ctx
, old_ic
);
2546 global_iconv_handle
= lp_ctx
->iconv_handle
;
2549 _PUBLIC_
char *lpcfg_tls_keyfile(TALLOC_CTX
*mem_ctx
, struct loadparm_context
*lp_ctx
)
2551 return lpcfg_private_path(mem_ctx
, lp_ctx
, lp_ctx
->globals
->tls_keyfile
);
2554 _PUBLIC_
char *lpcfg_tls_certfile(TALLOC_CTX
*mem_ctx
, struct loadparm_context
*lp_ctx
)
2556 return lpcfg_private_path(mem_ctx
, lp_ctx
, lp_ctx
->globals
->tls_certfile
);
2559 _PUBLIC_
char *lpcfg_tls_cafile(TALLOC_CTX
*mem_ctx
, struct loadparm_context
*lp_ctx
)
2561 return lpcfg_private_path(mem_ctx
, lp_ctx
, lp_ctx
->globals
->tls_cafile
);
2564 _PUBLIC_
char *lpcfg_tls_crlfile(TALLOC_CTX
*mem_ctx
, struct loadparm_context
*lp_ctx
)
2566 return lpcfg_private_path(mem_ctx
, lp_ctx
, lp_ctx
->globals
->tls_crlfile
);
2569 _PUBLIC_
char *lpcfg_tls_dhpfile(TALLOC_CTX
*mem_ctx
, struct loadparm_context
*lp_ctx
)
2571 return lpcfg_private_path(mem_ctx
, lp_ctx
, lp_ctx
->globals
->tls_dhpfile
);
2574 struct gensec_settings
*lpcfg_gensec_settings(TALLOC_CTX
*mem_ctx
, struct loadparm_context
*lp_ctx
)
2576 struct gensec_settings
*settings
= talloc_zero(mem_ctx
, struct gensec_settings
);
2577 if (settings
== NULL
)
2579 SMB_ASSERT(lp_ctx
!= NULL
);
2580 settings
->lp_ctx
= talloc_reference(settings
, lp_ctx
);
2581 settings
->target_hostname
= lpcfg_parm_string(lp_ctx
, NULL
, "gensec", "target_hostname");
2585 int lpcfg_server_role(struct loadparm_context
*lp_ctx
)
2587 int domain_master
= lpcfg__domain_master(lp_ctx
);
2589 return lp_find_server_role(lpcfg__server_role(lp_ctx
),
2590 lpcfg__security(lp_ctx
),
2591 lpcfg__domain_logons(lp_ctx
),
2592 (domain_master
== true) ||
2593 (domain_master
== Auto
));
2596 int lpcfg_security(struct loadparm_context
*lp_ctx
)
2598 return lp_find_security(lpcfg__server_role(lp_ctx
),
2599 lpcfg__security(lp_ctx
));