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; \
77 char *realm_original; \
79 int iminreceivefile; \
80 char *szPrintcapname; \
82 int iPreferredMaster; \
83 char *szLdapMachineSuffix; \
84 char *szLdapUserSuffix; \
85 char *szLdapIdmapSuffix; \
86 char *szLdapGroupSuffix; \
89 char *szIdmapBackend; \
90 int winbindMaxDomainConnections; \
91 int ismb2_max_credits; \
99 #include "lib/param/param_global.h"
101 #define NUMPARAMETERS (sizeof(parm_table) / sizeof(struct parm_struct))
103 /* we don't need a special handler for "dos charset" and "unix charset" */
104 #define handle_dos_charset NULL
105 #define handle_charset NULL
107 /* these are parameter handlers which are not needed in the
110 #define handle_netbios_aliases NULL
111 #define handle_printing NULL
112 #define handle_ldap_debug_level NULL
113 #define handle_idmap_backend NULL
114 #define handle_idmap_uid NULL
115 #define handle_idmap_gid NULL
121 /* prototypes for the special type handlers */
122 static bool handle_include(struct loadparm_context *lp_ctx, int unused,
123 const char *pszParmValue, char **ptr);
124 static bool handle_realm(struct loadparm_context *lp_ctx, int unused,
125 const char *pszParmValue, char **ptr);
126 static bool handle_copy(struct loadparm_context *lp_ctx, int unused,
127 const char *pszParmValue, char **ptr);
128 static bool handle_debug_list(struct loadparm_context *lp_ctx, int unused,
129 const char *pszParmValue, char **ptr);
130 static bool handle_logfile(struct loadparm_context *lp_ctx, int unused,
131 const char *pszParmValue, char **ptr);
133 #include "lib/param/param_table.c"
135 /* local variables */
136 struct loadparm_context {
137 const char *szConfigFile;
138 struct loadparm_global *globals;
139 struct loadparm_service **services;
140 struct loadparm_service *sDefault;
141 struct smb_iconv_handle *iconv_handle;
143 struct loadparm_service *currentService;
144 bool bInGlobalSection;
146 struct file_lists *next;
151 unsigned int flags[NUMPARAMETERS];
154 bool global; /* Is this the global context, which may set
155 * global variables such as debug level etc? */
156 const struct loadparm_s3_helpers *s3_fns;
160 struct loadparm_service *lpcfg_default_service(struct loadparm_context *lp_ctx)
162 if (lp_ctx->s3_fns) {
163 return lp_ctx->s3_fns->get_default_loadparm_service();
165 return lp_ctx->sDefault;
169 * Convenience routine to grab string parameters into temporary memory
170 * and run standard_sub_basic on them.
172 * The buffers can be written to by
173 * callers without affecting the source string.
176 static const char *lp_string(const char *s)
178 #if 0 /* until REWRITE done to make thread-safe */
179 size_t len = s ? strlen(s) : 0;
183 /* The follow debug is useful for tracking down memory problems
184 especially if you have an inner loop that is calling a lp_*()
185 function that returns a string. Perhaps this debug should be
186 present all the time? */
189 DEBUG(10, ("lp_string(%s)\n", s));
192 #if 0 /* until REWRITE done to make thread-safe */
194 lp_talloc = talloc_init("lp_talloc");
196 ret = talloc_array(lp_talloc, char, len + 100); /* leave room for substitution */
204 strlcpy(ret, s, len);
206 if (trim_string(ret, "\"", "\"")) {
207 if (strchr(ret,'"') != NULL)
208 strlcpy(ret, s, len);
211 standard_sub_basic(ret,len+100);
218 In this section all the functions that are used to access the
219 parameters from the rest of the program are defined
223 * the creation of separate lpcfg_*() and lp_*() functions is to allow
224 * for code compatibility between existing Samba4 and Samba3 code.
227 /* this global context supports the lp_*() function varients */
228 static struct loadparm_context *global_loadparm_context;
230 #define lpcfg_default_service global_loadparm_context->sDefault
231 #define lpcfg_global_service(i) global_loadparm_context->services[i]
233 #define FN_GLOBAL_STRING(fn_name,var_name) \
234 _PUBLIC_ const char *lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) {\
235 if (lp_ctx == NULL) return NULL; \
236 if (lp_ctx->s3_fns) { \
237 smb_panic( __location__ ": " #fn_name " not implemented because it is an allocated and substiuted string"); \
239 return lp_ctx->globals->var_name ? lp_string(lp_ctx->globals->var_name) : ""; \
242 #define FN_GLOBAL_CONST_STRING(fn_name,var_name) \
243 _PUBLIC_ const char *lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) { \
244 if (lp_ctx == NULL) return NULL; \
245 if (lp_ctx->s3_fns) { \
246 SMB_ASSERT(lp_ctx->s3_fns->fn_name); \
247 return lp_ctx->s3_fns->fn_name(); \
249 return lp_ctx->globals->var_name ? lp_string(lp_ctx->globals->var_name) : ""; \
252 #define FN_GLOBAL_LIST(fn_name,var_name) \
253 _PUBLIC_ const char **lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) { \
254 if (lp_ctx == NULL) return NULL; \
255 if (lp_ctx->s3_fns) { \
256 SMB_ASSERT(lp_ctx->s3_fns->fn_name); \
257 return lp_ctx->s3_fns->fn_name(); \
259 return lp_ctx->globals->var_name; \
262 #define FN_GLOBAL_BOOL(fn_name,var_name) \
263 _PUBLIC_ bool lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) {\
264 if (lp_ctx == NULL) return false; \
265 if (lp_ctx->s3_fns) { \
266 SMB_ASSERT(lp_ctx->s3_fns->fn_name); \
267 return lp_ctx->s3_fns->fn_name(); \
269 return lp_ctx->globals->var_name; \
272 #define FN_GLOBAL_INTEGER(fn_name,var_name) \
273 _PUBLIC_ int lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) { \
274 if (lp_ctx->s3_fns) { \
275 SMB_ASSERT(lp_ctx->s3_fns->fn_name); \
276 return lp_ctx->s3_fns->fn_name(); \
278 return lp_ctx->globals->var_name; \
281 /* Local parameters don't need the ->s3_fns because the struct
282 * loadparm_service is shared and lpcfg_service() checks the ->s3_fns
284 #define FN_LOCAL_STRING(fn_name,val) \
285 _PUBLIC_ const char *lpcfg_ ## fn_name(struct loadparm_service *service, \
286 struct loadparm_service *sDefault) { \
287 return(lp_string((const char *)((service != NULL && service->val != NULL) ? service->val : sDefault->val))); \
290 #define FN_LOCAL_CONST_STRING(fn_name,val) FN_LOCAL_STRING(fn_name, val)
292 #define FN_LOCAL_LIST(fn_name,val) \
293 _PUBLIC_ const char **lpcfg_ ## fn_name(struct loadparm_service *service, \
294 struct loadparm_service *sDefault) {\
295 return(const char **)(service != NULL && service->val != NULL? service->val : sDefault->val); \
298 #define FN_LOCAL_PARM_BOOL(fn_name, val) FN_LOCAL_BOOL(fn_name, val)
300 #define FN_LOCAL_BOOL(fn_name,val) \
301 _PUBLIC_ bool lpcfg_ ## fn_name(struct loadparm_service *service, \
302 struct loadparm_service *sDefault) { \
303 return((service != NULL)? service->val : sDefault->val); \
306 #define FN_LOCAL_INTEGER(fn_name,val) \
307 _PUBLIC_ int lpcfg_ ## fn_name(struct loadparm_service *service, \
308 struct loadparm_service *sDefault) { \
309 return((service != NULL)? service->val : sDefault->val); \
312 #define FN_LOCAL_PARM_INTEGER(fn_name, val) FN_LOCAL_INTEGER(fn_name, val)
314 #define FN_LOCAL_PARM_CHAR(fn_name,val) \
315 _PUBLIC_ char lpcfg_ ## fn_name(struct loadparm_service *service, \
316 struct loadparm_service *sDefault) { \
317 return((service != NULL)? service->val : sDefault->val); \
320 #include "lib/param/param_functions.c"
322 /* These functions remain only in lib/param for now */
323 FN_GLOBAL_BOOL(readraw, bReadRaw)
324 FN_GLOBAL_BOOL(writeraw, bWriteRaw)
325 FN_GLOBAL_CONST_STRING(cachedir, szCacheDir)
326 FN_GLOBAL_CONST_STRING(statedir, szStateDir)
328 /* local prototypes */
329 static struct loadparm_service *getservicebyname(struct loadparm_context *lp_ctx,
330 const char *pszServiceName);
331 static void copy_service(struct loadparm_service *pserviceDest,
332 struct loadparm_service *pserviceSource,
333 struct bitmap *pcopymapDest);
334 static bool lpcfg_service_ok(struct loadparm_service *service);
335 static bool do_section(const char *pszSectionName, void *);
336 static void init_copymap(struct loadparm_service *pservice);
338 /* This is a helper function for parametrical options support. */
339 /* It returns a pointer to parametrical option value if it exists or NULL otherwise */
340 /* Actual parametrical functions are quite simple */
341 const char *lpcfg_get_parametric(struct loadparm_context *lp_ctx,
342 struct loadparm_service *service,
343 const char *type, const char *option)
345 char *vfskey_tmp = NULL;
347 struct parmlist_entry *data;
352 if (lp_ctx->s3_fns) {
353 return lp_ctx->s3_fns->get_parametric(service, type, option);
356 data = (service == NULL ? lp_ctx->globals->param_opt : service->param_opt);
358 vfskey_tmp = talloc_asprintf(NULL, "%s:%s", type, option);
359 if (vfskey_tmp == NULL) return NULL;
360 vfskey = strlower_talloc(NULL, vfskey_tmp);
361 talloc_free(vfskey_tmp);
364 if (strcmp(data->key, vfskey) == 0) {
371 if (service != NULL) {
372 /* Try to fetch the same option but from globals */
373 /* but only if we are not already working with globals */
374 for (data = lp_ctx->globals->param_opt; data;
376 if (strcmp(data->key, vfskey) == 0) {
390 * convenience routine to return int parameters.
392 static int lp_int(const char *s)
396 DEBUG(0,("lp_int(%s): is called with NULL!\n",s));
400 return strtol(s, NULL, 0);
404 * convenience routine to return unsigned long parameters.
406 static unsigned long lp_ulong(const char *s)
410 DEBUG(0,("lp_ulong(%s): is called with NULL!\n",s));
414 return strtoul(s, NULL, 0);
418 * convenience routine to return unsigned long parameters.
420 static long lp_long(const char *s)
424 DEBUG(0,("lp_long(%s): is called with NULL!\n",s));
428 return strtol(s, NULL, 0);
432 * convenience routine to return unsigned long parameters.
434 static double lp_double(const char *s)
438 DEBUG(0,("lp_double(%s): is called with NULL!\n",s));
442 return strtod(s, NULL);
446 * convenience routine to return boolean parameters.
448 static bool lp_bool(const char *s)
453 DEBUG(0,("lp_bool(%s): is called with NULL!\n",s));
457 if (!set_boolean(s, &ret)) {
458 DEBUG(0,("lp_bool(%s): value is not boolean!\n",s));
467 * Return parametric option from a given service. Type is a part of option before ':'
468 * Parametric option has following syntax: 'Type: option = value'
469 * Returned value is allocated in 'lp_talloc' context
472 const char *lpcfg_parm_string(struct loadparm_context *lp_ctx,
473 struct loadparm_service *service, const char *type,
476 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
479 return lp_string(value);
485 * Return parametric option from a given service. Type is a part of option before ':'
486 * Parametric option has following syntax: 'Type: option = value'
487 * Returned value is allocated in 'lp_talloc' context
490 const char **lpcfg_parm_string_list(TALLOC_CTX *mem_ctx,
491 struct loadparm_context *lp_ctx,
492 struct loadparm_service *service,
494 const char *option, const char *separator)
496 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
499 return (const char **)str_list_make(mem_ctx, value, separator);
505 * Return parametric option from a given service. Type is a part of option before ':'
506 * Parametric option has following syntax: 'Type: option = value'
509 int lpcfg_parm_int(struct loadparm_context *lp_ctx,
510 struct loadparm_service *service, const char *type,
511 const char *option, int default_v)
513 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
516 return lp_int(value);
522 * Return parametric option from a given service. Type is a part of
524 * Parametric option has following syntax: 'Type: option = value'.
527 int lpcfg_parm_bytes(struct loadparm_context *lp_ctx,
528 struct loadparm_service *service, const char *type,
529 const char *option, int default_v)
533 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
535 if (value && conv_str_size_error(value, &bval)) {
536 if (bval <= INT_MAX) {
545 * Return parametric option from a given service.
546 * Type is a part of option before ':'
547 * Parametric option has following syntax: 'Type: option = value'
549 unsigned long lpcfg_parm_ulong(struct loadparm_context *lp_ctx,
550 struct loadparm_service *service, const char *type,
551 const char *option, unsigned long default_v)
553 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
556 return lp_ulong(value);
561 long lpcfg_parm_long(struct loadparm_context *lp_ctx,
562 struct loadparm_service *service, const char *type,
563 const char *option, long default_v)
565 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
568 return lp_long(value);
573 double lpcfg_parm_double(struct loadparm_context *lp_ctx,
574 struct loadparm_service *service, const char *type,
575 const char *option, double default_v)
577 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
580 return lp_double(value);
586 * Return parametric option from a given service. Type is a part of option before ':'
587 * Parametric option has following syntax: 'Type: option = value'
590 bool lpcfg_parm_bool(struct loadparm_context *lp_ctx,
591 struct loadparm_service *service, const char *type,
592 const char *option, bool default_v)
594 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
597 return lp_bool(value);
604 * Initialise a service to the defaults.
607 static struct loadparm_service *init_service(TALLOC_CTX *mem_ctx, struct loadparm_service *sDefault)
609 struct loadparm_service *pservice =
610 talloc_zero(mem_ctx, struct loadparm_service);
611 copy_service(pservice, sDefault, NULL);
616 * Set a string value, deallocating any existing space, and allocing the space
619 static bool lpcfg_string_set(TALLOC_CTX *mem_ctx, char **dest, const char *src)
626 *dest = talloc_strdup(mem_ctx, src);
627 if ((*dest) == NULL) {
628 DEBUG(0,("Out of memory in string_set\n"));
636 * Set a string value, deallocating any existing space, and allocing the space
639 static bool lpcfg_string_set_upper(TALLOC_CTX *mem_ctx, char **dest, const char *src)
646 *dest = strupper_talloc(mem_ctx, src);
647 if ((*dest) == NULL) {
648 DEBUG(0,("Out of memory in string_set_upper\n"));
658 * Add a new service to the services array initialising it with the given
662 struct loadparm_service *lpcfg_add_service(struct loadparm_context *lp_ctx,
663 const struct loadparm_service *pservice,
667 struct loadparm_service tservice;
668 int num_to_alloc = lp_ctx->iNumServices + 1;
669 struct parmlist_entry *data, *pdata;
671 if (pservice == NULL) {
672 pservice = lp_ctx->sDefault;
675 tservice = *pservice;
677 /* it might already exist */
679 struct loadparm_service *service = getservicebyname(lp_ctx,
681 if (service != NULL) {
682 /* Clean all parametric options for service */
683 /* They will be added during parsing again */
684 data = service->param_opt;
690 service->param_opt = NULL;
695 /* find an invalid one */
696 for (i = 0; i < lp_ctx->iNumServices; i++)
697 if (lp_ctx->services[i] == NULL)
700 /* if not, then create one */
701 if (i == lp_ctx->iNumServices) {
702 struct loadparm_service **tsp;
704 tsp = talloc_realloc(lp_ctx, lp_ctx->services, struct loadparm_service *, num_to_alloc);
707 DEBUG(0,("lpcfg_add_service: failed to enlarge services!\n"));
710 lp_ctx->services = tsp;
711 lp_ctx->services[lp_ctx->iNumServices] = NULL;
714 lp_ctx->iNumServices++;
717 lp_ctx->services[i] = init_service(lp_ctx->services, lp_ctx->sDefault);
718 if (lp_ctx->services[i] == NULL) {
719 DEBUG(0,("lpcfg_add_service: out of memory!\n"));
722 copy_service(lp_ctx->services[i], &tservice, NULL);
724 lpcfg_string_set(lp_ctx->services[i], &lp_ctx->services[i]->szService, name);
725 return lp_ctx->services[i];
729 * Add a new home service, with the specified home directory, defaults coming
730 * from service ifrom.
733 bool lpcfg_add_home(struct loadparm_context *lp_ctx,
734 const char *pszHomename,
735 struct loadparm_service *default_service,
736 const char *user, const char *pszHomedir)
738 struct loadparm_service *service;
740 service = lpcfg_add_service(lp_ctx, default_service, pszHomename);
745 if (!(*(default_service->path))
746 || strequal(default_service->path, lp_ctx->sDefault->path)) {
747 service->path = talloc_strdup(service, pszHomedir);
749 service->path = string_sub_talloc(service, lpcfg_path(default_service, lp_ctx->sDefault), "%H", pszHomedir);
752 if (!(*(service->comment))) {
753 service->comment = talloc_asprintf(service, "Home directory of %s", user);
755 service->bAvailable = default_service->bAvailable;
756 service->browseable = default_service->browseable;
758 DEBUG(3, ("adding home's share [%s] for user '%s' at '%s'\n",
759 pszHomename, user, service->path));
765 * Add a new printer service, with defaults coming from service iFrom.
768 bool lpcfg_add_printer(struct loadparm_context *lp_ctx,
769 const char *pszPrintername,
770 struct loadparm_service *default_service)
772 const char *comment = "From Printcap";
773 struct loadparm_service *service;
774 service = lpcfg_add_service(lp_ctx, default_service, pszPrintername);
779 /* note that we do NOT default the availability flag to True - */
780 /* we take it from the default service passed. This allows all */
781 /* dynamic printers to be disabled by disabling the [printers] */
782 /* entry (if/when the 'available' keyword is implemented!). */
784 /* the printer name is set to the service name. */
785 lpcfg_string_set(service, &service->_printername, pszPrintername);
786 lpcfg_string_set(service, &service->comment, comment);
787 service->browseable = default_service->browseable;
788 /* Printers cannot be read_only. */
789 service->read_only = false;
790 /* Printer services must be printable. */
791 service->printable = true;
793 DEBUG(3, ("adding printer service %s\n", pszPrintername));
799 * Map a parameter's string representation to something we can use.
800 * Returns False if the parameter string is not recognised, else TRUE.
803 int lpcfg_map_parameter(const char *pszParmName)
807 for (iIndex = 0; parm_table[iIndex].label; iIndex++)
808 if (strwicmp(parm_table[iIndex].label, pszParmName) == 0)
811 /* Warn only if it isn't parametric option */
812 if (strchr(pszParmName, ':') == NULL)
813 DEBUG(0, ("Unknown parameter encountered: \"%s\"\n", pszParmName));
814 /* We do return 'fail' for parametric options as well because they are
815 stored in different storage
822 return the parameter structure for a parameter
824 struct parm_struct *lpcfg_parm_struct(struct loadparm_context *lp_ctx, const char *name)
828 if (lp_ctx->s3_fns) {
829 return lp_ctx->s3_fns->get_parm_struct(name);
832 parmnum = lpcfg_map_parameter(name);
833 if (parmnum == -1) return NULL;
834 return &parm_table[parmnum];
838 return the parameter pointer for a parameter
840 void *lpcfg_parm_ptr(struct loadparm_context *lp_ctx,
841 struct loadparm_service *service, struct parm_struct *parm)
843 if (lp_ctx->s3_fns) {
844 return lp_ctx->s3_fns->get_parm_ptr(service, parm);
847 if (service == NULL) {
848 if (parm->p_class == P_LOCAL)
849 return ((char *)lp_ctx->sDefault)+parm->offset;
850 else if (parm->p_class == P_GLOBAL)
851 return ((char *)lp_ctx->globals)+parm->offset;
854 return ((char *)service) + parm->offset;
859 return the parameter pointer for a parameter
861 bool lpcfg_parm_is_cmdline(struct loadparm_context *lp_ctx, const char *name)
865 if (lp_ctx->s3_fns) {
866 struct parm_struct *parm = lp_ctx->s3_fns->get_parm_struct(name);
868 return parm->flags & FLAG_CMDLINE;
873 parmnum = lpcfg_map_parameter(name);
874 if (parmnum == -1) return false;
876 return lp_ctx->flags[parmnum] & FLAG_CMDLINE;
880 * Find a service by name. Otherwise works like get_service.
883 static struct loadparm_service *getservicebyname(struct loadparm_context *lp_ctx,
884 const char *pszServiceName)
888 if (lp_ctx->s3_fns) {
889 return lp_ctx->s3_fns->get_service(pszServiceName);
892 for (iService = lp_ctx->iNumServices - 1; iService >= 0; iService--)
893 if (lp_ctx->services[iService] != NULL &&
894 strwicmp(lp_ctx->services[iService]->szService, pszServiceName) == 0) {
895 return lp_ctx->services[iService];
902 * Copy a service structure to another.
903 * If pcopymapDest is NULL then copy all fields
906 static void copy_service(struct loadparm_service *pserviceDest,
907 struct loadparm_service *pserviceSource,
908 struct bitmap *pcopymapDest)
911 bool bcopyall = (pcopymapDest == NULL);
912 struct parmlist_entry *data, *pdata, *paramo;
915 for (i = 0; parm_table[i].label; i++)
916 if (parm_table[i].p_class == P_LOCAL &&
917 (bcopyall || bitmap_query(pcopymapDest, i))) {
919 ((char *)pserviceSource) + parm_table[i].offset;
921 ((char *)pserviceDest) + parm_table[i].offset;
923 switch (parm_table[i].type) {
926 *(bool *)dest_ptr = *(bool *)src_ptr;
933 *(int *)dest_ptr = *(int *)src_ptr;
937 *(char *)dest_ptr = *(char *)src_ptr;
941 lpcfg_string_set(pserviceDest,
947 lpcfg_string_set_upper(pserviceDest,
952 *(const char ***)dest_ptr = (const char **)str_list_copy(pserviceDest,
953 *(const char ***)src_ptr);
961 init_copymap(pserviceDest);
962 if (pserviceSource->copymap)
963 bitmap_copy(pserviceDest->copymap,
964 pserviceSource->copymap);
967 data = pserviceSource->param_opt;
970 pdata = pserviceDest->param_opt;
971 /* Traverse destination */
973 /* If we already have same option, override it */
974 if (strcmp(pdata->key, data->key) == 0) {
975 talloc_free(pdata->value);
976 pdata->value = talloc_strdup(pdata,
984 paramo = talloc_zero(pserviceDest, struct parmlist_entry);
987 paramo->key = talloc_strdup(paramo, data->key);
988 paramo->value = talloc_strdup(paramo, data->value);
989 DLIST_ADD(pserviceDest->param_opt, paramo);
996 * Check a service for consistency. Return False if the service is in any way
997 * incomplete or faulty, else True.
999 static bool lpcfg_service_ok(struct loadparm_service *service)
1004 if (service->szService[0] == '\0') {
1005 DEBUG(0, ("The following message indicates an internal error:\n"));
1006 DEBUG(0, ("No service name in service entry.\n"));
1010 /* The [printers] entry MUST be printable. I'm all for flexibility, but */
1011 /* I can't see why you'd want a non-printable printer service... */
1012 if (strwicmp(service->szService, PRINTERS_NAME) == 0) {
1013 if (!service->printable) {
1014 DEBUG(0, ("WARNING: [%s] service MUST be printable!\n",
1015 service->szService));
1016 service->printable = true;
1018 /* [printers] service must also be non-browsable. */
1019 if (service->browseable)
1020 service->browseable = false;
1023 /* If a service is flagged unavailable, log the fact at level 0. */
1024 if (!service->bAvailable)
1025 DEBUG(1, ("NOTE: Service %s is flagged unavailable.\n",
1026 service->szService));
1032 /*******************************************************************
1033 Keep a linked list of all config files so we know when one has changed
1034 it's date and needs to be reloaded.
1035 ********************************************************************/
1037 static void add_to_file_list(struct loadparm_context *lp_ctx,
1038 const char *fname, const char *subfname)
1040 struct file_lists *f = lp_ctx->file_lists;
1043 if (f->name && !strcmp(f->name, fname))
1049 f = talloc(lp_ctx, struct file_lists);
1052 f->next = lp_ctx->file_lists;
1053 f->name = talloc_strdup(f, fname);
1058 f->subfname = talloc_strdup(f, subfname);
1063 lp_ctx->file_lists = f;
1064 f->modtime = file_modtime(subfname);
1066 time_t t = file_modtime(subfname);
1072 /*******************************************************************
1073 Check if a config file has changed date.
1074 ********************************************************************/
1075 bool lpcfg_file_list_changed(struct loadparm_context *lp_ctx)
1077 struct file_lists *f;
1078 DEBUG(6, ("lpcfg_file_list_changed()\n"));
1080 for (f = lp_ctx->file_lists; f != NULL; f = f->next) {
1084 n2 = standard_sub_basic(lp_ctx, f->name);
1086 DEBUGADD(6, ("file %s -> %s last mod_time: %s\n",
1087 f->name, n2, ctime(&f->modtime)));
1089 mod_time = file_modtime(n2);
1091 if (mod_time && ((f->modtime != mod_time) || (f->subfname == NULL) || (strcmp(n2, f->subfname) != 0))) {
1092 DEBUGADD(6, ("file %s modified: %s\n", n2,
1094 f->modtime = mod_time;
1095 talloc_free(f->subfname);
1096 f->subfname = talloc_strdup(f, n2);
1103 /***************************************************************************
1104 Handle the "realm" parameter
1105 ***************************************************************************/
1107 static bool handle_realm(struct loadparm_context *lp_ctx, int unused,
1108 const char *pszParmValue, char **ptr)
1110 lpcfg_string_set(lp_ctx, ptr, pszParmValue);
1112 talloc_free(lp_ctx->globals->realm);
1113 talloc_free(lp_ctx->globals->dnsdomain);
1115 lp_ctx->globals->realm = strupper_talloc(lp_ctx, pszParmValue);
1116 lp_ctx->globals->dnsdomain = strlower_talloc(lp_ctx, pszParmValue);
1121 /***************************************************************************
1122 Handle the include operation.
1123 ***************************************************************************/
1125 static bool handle_include(struct loadparm_context *lp_ctx, int unused,
1126 const char *pszParmValue, char **ptr)
1128 char *fname = standard_sub_basic(lp_ctx, pszParmValue);
1130 add_to_file_list(lp_ctx, pszParmValue, fname);
1132 lpcfg_string_set(lp_ctx, ptr, fname);
1134 if (file_exist(fname))
1135 return pm_process(fname, do_section, do_parameter, lp_ctx);
1137 DEBUG(2, ("Can't find include file %s\n", fname));
1142 /***************************************************************************
1143 Handle the interpretation of the copy parameter.
1144 ***************************************************************************/
1146 static bool handle_copy(struct loadparm_context *lp_ctx, int unused,
1147 const char *pszParmValue, char **ptr)
1150 struct loadparm_service *serviceTemp;
1152 lpcfg_string_set(lp_ctx, ptr, pszParmValue);
1156 DEBUG(3, ("Copying service from service %s\n", pszParmValue));
1158 if ((serviceTemp = getservicebyname(lp_ctx, pszParmValue)) != NULL) {
1159 if (serviceTemp == lp_ctx->currentService) {
1160 DEBUG(0, ("Can't copy service %s - unable to copy self!\n", pszParmValue));
1162 copy_service(lp_ctx->currentService,
1164 lp_ctx->currentService->copymap);
1168 DEBUG(0, ("Unable to copy service - source not found: %s\n",
1176 static bool handle_debug_list(struct loadparm_context *lp_ctx, int unused,
1177 const char *pszParmValue, char **ptr)
1180 lpcfg_string_set(lp_ctx, ptr, pszParmValue);
1181 if (lp_ctx->global) {
1182 return debug_parse_levels(pszParmValue);
1187 static bool handle_logfile(struct loadparm_context *lp_ctx, int unused,
1188 const char *pszParmValue, char **ptr)
1190 debug_set_logfile(pszParmValue);
1191 if (lp_ctx->global) {
1192 lpcfg_string_set(lp_ctx, ptr, pszParmValue);
1197 /***************************************************************************
1198 Initialise a copymap.
1199 ***************************************************************************/
1201 static void init_copymap(struct loadparm_service *pservice)
1205 TALLOC_FREE(pservice->copymap);
1207 pservice->copymap = bitmap_talloc(NULL, NUMPARAMETERS);
1208 if (!pservice->copymap)
1210 ("Couldn't allocate copymap!! (size %d)\n",
1211 (int)NUMPARAMETERS));
1213 for (i = 0; i < NUMPARAMETERS; i++)
1214 bitmap_set(pservice->copymap, i);
1218 * Process a parametric option
1220 static bool lp_do_parameter_parametric(struct loadparm_context *lp_ctx,
1221 struct loadparm_service *service,
1222 const char *pszParmName,
1223 const char *pszParmValue, int flags)
1225 struct parmlist_entry *paramo, *data;
1227 TALLOC_CTX *mem_ctx;
1229 while (isspace((unsigned char)*pszParmName)) {
1233 name = strlower_talloc(lp_ctx, pszParmName);
1234 if (!name) return false;
1236 if (service == NULL) {
1237 data = lp_ctx->globals->param_opt;
1238 mem_ctx = lp_ctx->globals;
1240 data = service->param_opt;
1244 /* Traverse destination */
1245 for (paramo=data; paramo; paramo=paramo->next) {
1246 /* If we already have the option set, override it unless
1247 it was a command line option and the new one isn't */
1248 if (strcmp(paramo->key, name) == 0) {
1249 if ((paramo->priority & FLAG_CMDLINE) &&
1250 !(flags & FLAG_CMDLINE)) {
1255 talloc_free(paramo->value);
1256 paramo->value = talloc_strdup(paramo, pszParmValue);
1257 paramo->priority = flags;
1263 paramo = talloc_zero(mem_ctx, struct parmlist_entry);
1266 paramo->key = talloc_strdup(paramo, name);
1267 paramo->value = talloc_strdup(paramo, pszParmValue);
1268 paramo->priority = flags;
1269 if (service == NULL) {
1270 DLIST_ADD(lp_ctx->globals->param_opt, paramo);
1272 DLIST_ADD(service->param_opt, paramo);
1280 static bool set_variable(TALLOC_CTX *mem_ctx, int parmnum, void *parm_ptr,
1281 const char *pszParmName, const char *pszParmValue,
1282 struct loadparm_context *lp_ctx, bool on_globals)
1285 /* if it is a special case then go ahead */
1286 if (parm_table[parmnum].special) {
1288 ret = parm_table[parmnum].special(lp_ctx, -1, pszParmValue,
1293 goto mark_non_default;
1296 /* now switch on the type of variable it is */
1297 switch (parm_table[parmnum].type)
1301 if (!set_boolean(pszParmValue, &b)) {
1302 DEBUG(0, ("set_variable(%s): value is not "
1303 "boolean!\n", pszParmValue));
1306 *(bool *)parm_ptr = b;
1312 if (!set_boolean(pszParmValue, &b)) {
1313 DEBUG(0, ("set_variable(%s): value is not "
1314 "boolean!\n", pszParmValue));
1317 *(bool *)parm_ptr = !b;
1322 *(int *)parm_ptr = atoi(pszParmValue);
1326 *(char *)parm_ptr = *pszParmValue;
1330 *(int *)parm_ptr = strtol(pszParmValue, NULL, 8);
1336 if (conv_str_size_error(pszParmValue, &val)) {
1337 if (val <= INT_MAX) {
1338 *(int *)parm_ptr = (int)val;
1343 DEBUG(0, ("set_variable(%s): value is not "
1344 "a valid size specifier!\n", pszParmValue));
1349 *(const char ***)parm_ptr = (const char **)str_list_make(mem_ctx,
1350 pszParmValue, NULL);
1354 char **new_list = str_list_make(mem_ctx,
1355 pszParmValue, NULL);
1356 for (i=0; new_list[i]; i++) {
1357 if (*(const char ***)parm_ptr != NULL &&
1358 new_list[i][0] == '+' &&
1361 if (!str_list_check(*(const char ***)parm_ptr,
1363 *(const char ***)parm_ptr = str_list_add(*(const char ***)parm_ptr,
1366 } else if (*(const char ***)parm_ptr != NULL &&
1367 new_list[i][0] == '-' &&
1370 str_list_remove(*(const char ***)parm_ptr,
1374 DEBUG(0, ("Unsupported list syntax for: %s = %s\n",
1375 pszParmName, pszParmValue));
1378 *(const char ***)parm_ptr = (const char **) new_list;
1385 lpcfg_string_set(mem_ctx, (char **)parm_ptr, pszParmValue);
1389 lpcfg_string_set_upper(mem_ctx, (char **)parm_ptr, pszParmValue);
1393 for (i = 0; parm_table[parmnum].enum_list[i].name; i++) {
1396 parm_table[parmnum].enum_list[i].name)) {
1398 parm_table[parmnum].
1403 if (!parm_table[parmnum].enum_list[i].name) {
1404 DEBUG(0,("Unknown enumerated value '%s' for '%s'\n",
1405 pszParmValue, pszParmName));
1415 if (on_globals && (lp_ctx->flags[parmnum] & FLAG_DEFAULT)) {
1416 lp_ctx->flags[parmnum] &= ~FLAG_DEFAULT;
1417 /* we have to also unset FLAG_DEFAULT on aliases */
1418 for (i=parmnum-1;i>=0 && parm_table[i].offset == parm_table[parmnum].offset;i--) {
1419 lp_ctx->flags[i] &= ~FLAG_DEFAULT;
1421 for (i=parmnum+1;i<NUMPARAMETERS && parm_table[i].offset == parm_table[parmnum].offset;i++) {
1422 lp_ctx->flags[i] &= ~FLAG_DEFAULT;
1429 bool lpcfg_do_global_parameter(struct loadparm_context *lp_ctx,
1430 const char *pszParmName, const char *pszParmValue)
1432 int parmnum = lpcfg_map_parameter(pszParmName);
1436 if (strchr(pszParmName, ':')) {
1437 return lp_do_parameter_parametric(lp_ctx, NULL, pszParmName, pszParmValue, 0);
1439 DEBUG(0, ("Ignoring unknown parameter \"%s\"\n", pszParmName));
1443 /* if the flag has been set on the command line, then don't allow override,
1444 but don't report an error */
1445 if (lp_ctx->flags[parmnum] & FLAG_CMDLINE) {
1449 parm_ptr = lpcfg_parm_ptr(lp_ctx, NULL, &parm_table[parmnum]);
1451 return set_variable(lp_ctx->globals, parmnum, parm_ptr,
1452 pszParmName, pszParmValue, lp_ctx, true);
1455 bool lpcfg_do_service_parameter(struct loadparm_context *lp_ctx,
1456 struct loadparm_service *service,
1457 const char *pszParmName, const char *pszParmValue)
1461 int parmnum = lpcfg_map_parameter(pszParmName);
1464 if (strchr(pszParmName, ':')) {
1465 return lp_do_parameter_parametric(lp_ctx, service, pszParmName, pszParmValue, 0);
1467 DEBUG(0, ("Ignoring unknown parameter \"%s\"\n", pszParmName));
1471 /* if the flag has been set on the command line, then don't allow override,
1472 but don't report an error */
1473 if (lp_ctx->flags[parmnum] & FLAG_CMDLINE) {
1477 if (parm_table[parmnum].p_class == P_GLOBAL) {
1479 ("Global parameter %s found in service section!\n",
1483 parm_ptr = ((char *)service) + parm_table[parmnum].offset;
1485 if (!service->copymap)
1486 init_copymap(service);
1488 /* this handles the aliases - set the copymap for other
1489 * entries with the same data pointer */
1490 for (i = 0; parm_table[i].label; i++)
1491 if (parm_table[i].offset == parm_table[parmnum].offset &&
1492 parm_table[i].p_class == parm_table[parmnum].p_class)
1493 bitmap_clear(service->copymap, i);
1495 return set_variable(service, parmnum, parm_ptr, pszParmName,
1496 pszParmValue, lp_ctx, false);
1500 * Process a parameter.
1503 static bool do_parameter(const char *pszParmName, const char *pszParmValue,
1506 struct loadparm_context *lp_ctx = (struct loadparm_context *)userdata;
1508 if (lp_ctx->bInGlobalSection)
1509 return lpcfg_do_global_parameter(lp_ctx, pszParmName,
1512 return lpcfg_do_service_parameter(lp_ctx, lp_ctx->currentService,
1513 pszParmName, pszParmValue);
1517 variable argument do parameter
1519 bool lpcfg_do_global_parameter_var(struct loadparm_context *lp_ctx, const char *pszParmName, const char *fmt, ...) PRINTF_ATTRIBUTE(3, 4);
1520 bool lpcfg_do_global_parameter_var(struct loadparm_context *lp_ctx,
1521 const char *pszParmName, const char *fmt, ...)
1528 s = talloc_vasprintf(NULL, fmt, ap);
1530 ret = lpcfg_do_global_parameter(lp_ctx, pszParmName, s);
1537 set a parameter from the commandline - this is called from command line parameter
1538 parsing code. It sets the parameter then marks the parameter as unable to be modified
1539 by smb.conf processing
1541 bool lpcfg_set_cmdline(struct loadparm_context *lp_ctx, const char *pszParmName,
1542 const char *pszParmValue)
1547 if (lp_ctx->s3_fns) {
1548 return lp_ctx->s3_fns->set_cmdline(pszParmName, pszParmValue);
1551 parmnum = lpcfg_map_parameter(pszParmName);
1553 while (isspace((unsigned char)*pszParmValue)) pszParmValue++;
1556 if (parmnum < 0 && strchr(pszParmName, ':')) {
1557 /* set a parametric option */
1558 return lp_do_parameter_parametric(lp_ctx, NULL, pszParmName,
1559 pszParmValue, FLAG_CMDLINE);
1563 DEBUG(0,("Unknown option '%s'\n", pszParmName));
1567 /* reset the CMDLINE flag in case this has been called before */
1568 lp_ctx->flags[parmnum] &= ~FLAG_CMDLINE;
1570 if (!lpcfg_do_global_parameter(lp_ctx, pszParmName, pszParmValue)) {
1574 lp_ctx->flags[parmnum] |= FLAG_CMDLINE;
1576 /* we have to also set FLAG_CMDLINE on aliases */
1578 i>=0 && parm_table[i].p_class == parm_table[parmnum].p_class &&
1579 parm_table[i].offset == parm_table[parmnum].offset;
1581 lp_ctx->flags[i] |= FLAG_CMDLINE;
1585 parm_table[i].p_class == parm_table[parmnum].p_class &&
1586 parm_table[i].offset == parm_table[parmnum].offset;
1588 lp_ctx->flags[i] |= FLAG_CMDLINE;
1595 set a option from the commandline in 'a=b' format. Use to support --option
1597 bool lpcfg_set_option(struct loadparm_context *lp_ctx, const char *option)
1602 s = talloc_strdup(NULL, option);
1615 ret = lpcfg_set_cmdline(lp_ctx, s, p+1);
1621 #define BOOLSTR(b) ((b) ? "Yes" : "No")
1624 * Print a parameter of the specified type.
1627 void lpcfg_print_parameter(struct parm_struct *p, void *ptr, FILE * f)
1629 /* For the seperation of lists values that we print below */
1630 const char *list_sep = ", ";
1635 for (i = 0; p->enum_list[i].name; i++) {
1636 if (*(int *)ptr == p->enum_list[i].value) {
1638 p->enum_list[i].name);
1645 fprintf(f, "%s", BOOLSTR(*(bool *)ptr));
1649 fprintf(f, "%s", BOOLSTR(!*(bool *)ptr));
1654 fprintf(f, "%d", *(int *)ptr);
1658 fprintf(f, "%c", *(char *)ptr);
1662 int val = *(int *)ptr;
1666 fprintf(f, "0%03o", val);
1675 if ((char ***)ptr && *(char ***)ptr) {
1676 char **list = *(char ***)ptr;
1677 for (; *list; list++) {
1678 /* surround strings with whitespace in double quotes */
1679 if (*(list+1) == NULL) {
1680 /* last item, no extra separator */
1683 if ( strchr_m( *list, ' ' ) ) {
1684 fprintf(f, "\"%s\"%s", *list, list_sep);
1686 fprintf(f, "%s%s", *list, list_sep);
1694 if (*(char **)ptr) {
1695 fprintf(f, "%s", *(char **)ptr);
1704 * Check if two parameters are equal.
1707 bool lpcfg_equal_parameter(parm_type type, void *ptr1, void *ptr2)
1712 return (*((bool *)ptr1) == *((bool *)ptr2));
1718 return (*((int *)ptr1) == *((int *)ptr2));
1721 return (*((char *)ptr1) == *((char *)ptr2));
1725 return str_list_equal(*(const char ***)ptr1, *(const char ***)ptr2);
1730 char *p1 = *(char **)ptr1, *p2 = *(char **)ptr2;
1735 return (p1 == p2 || strequal(p1, p2));
1744 * Process a new section (service).
1746 * At this stage all sections are services.
1747 * Later we'll have special sections that permit server parameters to be set.
1748 * Returns True on success, False on failure.
1751 static bool do_section(const char *pszSectionName, void *userdata)
1753 struct loadparm_context *lp_ctx = (struct loadparm_context *)userdata;
1755 bool isglobal = ((strwicmp(pszSectionName, GLOBAL_NAME) == 0) ||
1756 (strwicmp(pszSectionName, GLOBAL_NAME2) == 0));
1759 /* if we've just struck a global section, note the fact. */
1760 lp_ctx->bInGlobalSection = isglobal;
1762 /* check for multiple global sections */
1763 if (lp_ctx->bInGlobalSection) {
1764 DEBUG(4, ("Processing section \"[%s]\"\n", pszSectionName));
1768 /* if we have a current service, tidy it up before moving on */
1771 if (lp_ctx->currentService != NULL)
1772 bRetval = lpcfg_service_ok(lp_ctx->currentService);
1774 /* if all is still well, move to the next record in the services array */
1776 /* We put this here to avoid an odd message order if messages are */
1777 /* issued by the post-processing of a previous section. */
1778 DEBUG(4, ("Processing section \"[%s]\"\n", pszSectionName));
1780 if ((lp_ctx->currentService = lpcfg_add_service(lp_ctx, lp_ctx->sDefault,
1783 DEBUG(0, ("Failed to add a new service\n"));
1793 * Determine if a particular base parameter is currently set to the default value.
1796 static bool is_default(struct loadparm_service *sDefault, int i)
1798 void *def_ptr = ((char *)sDefault) + parm_table[i].offset;
1799 switch (parm_table[i].type) {
1802 return str_list_equal((const char **)parm_table[i].def.lvalue,
1803 (const char **)def_ptr);
1806 return strequal(parm_table[i].def.svalue,
1810 return parm_table[i].def.bvalue ==
1817 return parm_table[i].def.ivalue ==
1826 *Display the contents of the global structure.
1829 static void dump_globals(struct loadparm_context *lp_ctx, FILE *f,
1833 struct parmlist_entry *data;
1835 fprintf(f, "# Global parameters\n[global]\n");
1837 for (i = 0; parm_table[i].label; i++)
1838 if (parm_table[i].p_class == P_GLOBAL &&
1839 (i == 0 || (parm_table[i].offset != parm_table[i - 1].offset))) {
1840 if (!show_defaults && (lp_ctx->flags[i] & FLAG_DEFAULT))
1842 fprintf(f, "\t%s = ", parm_table[i].label);
1843 lpcfg_print_parameter(&parm_table[i], lpcfg_parm_ptr(lp_ctx, NULL, &parm_table[i]), f);
1846 if (lp_ctx->globals->param_opt != NULL) {
1847 for (data = lp_ctx->globals->param_opt; data;
1848 data = data->next) {
1849 if (!show_defaults && (data->priority & FLAG_DEFAULT)) {
1852 fprintf(f, "\t%s = %s\n", data->key, data->value);
1859 * Display the contents of a single services record.
1862 static void dump_a_service(struct loadparm_service * pService, struct loadparm_service *sDefault, FILE * f,
1863 unsigned int *flags)
1866 struct parmlist_entry *data;
1868 if (pService != sDefault)
1869 fprintf(f, "\n[%s]\n", pService->szService);
1871 for (i = 0; parm_table[i].label; i++) {
1872 if (parm_table[i].p_class == P_LOCAL &&
1873 (*parm_table[i].label != '-') &&
1874 (i == 0 || (parm_table[i].offset != parm_table[i - 1].offset)))
1876 if (pService == sDefault) {
1877 if (flags && (flags[i] & FLAG_DEFAULT)) {
1880 if (defaults_saved) {
1881 if (is_default(sDefault, i)) {
1886 if (lpcfg_equal_parameter(parm_table[i].type,
1887 ((char *)pService) +
1888 parm_table[i].offset,
1889 ((char *)sDefault) +
1890 parm_table[i].offset))
1894 fprintf(f, "\t%s = ", parm_table[i].label);
1895 lpcfg_print_parameter(&parm_table[i],
1896 ((char *)pService) + parm_table[i].offset, f);
1900 if (pService->param_opt != NULL) {
1901 for (data = pService->param_opt; data; data = data->next) {
1902 fprintf(f, "\t%s = %s\n", data->key, data->value);
1907 bool lpcfg_dump_a_parameter(struct loadparm_context *lp_ctx,
1908 struct loadparm_service *service,
1909 const char *parm_name, FILE * f)
1911 struct parm_struct *parm;
1914 parm = lpcfg_parm_struct(lp_ctx, parm_name);
1919 if (service != NULL && parm->p_class == P_GLOBAL) {
1923 ptr = lpcfg_parm_ptr(lp_ctx, service,parm);
1925 lpcfg_print_parameter(parm, ptr, f);
1931 * Auto-load some home services.
1933 static void lpcfg_add_auto_services(struct loadparm_context *lp_ctx,
1941 * Unload unused services.
1944 void lpcfg_killunused(struct loadparm_context *lp_ctx,
1945 struct smbsrv_connection *smb,
1946 bool (*snumused) (struct smbsrv_connection *, int))
1949 for (i = 0; i < lp_ctx->iNumServices; i++) {
1950 if (lp_ctx->services[i] == NULL)
1953 if (!snumused || !snumused(smb, i)) {
1954 talloc_free(lp_ctx->services[i]);
1955 lp_ctx->services[i] = NULL;
1961 static int lpcfg_destructor(struct loadparm_context *lp_ctx)
1963 struct parmlist_entry *data;
1965 if (lp_ctx->refuse_free) {
1966 /* someone is trying to free the
1967 global_loadparm_context.
1968 We can't allow that. */
1972 if (lp_ctx->globals->param_opt != NULL) {
1973 struct parmlist_entry *next;
1974 for (data = lp_ctx->globals->param_opt; data; data=next) {
1976 if (data->priority & FLAG_CMDLINE) continue;
1977 DLIST_REMOVE(lp_ctx->globals->param_opt, data);
1986 * Initialise the global parameter structure.
1988 * Note that most callers should use loadparm_init_global() instead
1990 struct loadparm_context *loadparm_init(TALLOC_CTX *mem_ctx)
1994 struct loadparm_context *lp_ctx;
1995 struct parmlist_entry *parm;
1998 lp_ctx = talloc_zero(mem_ctx, struct loadparm_context);
2002 talloc_set_destructor(lp_ctx, lpcfg_destructor);
2003 lp_ctx->bInGlobalSection = true;
2004 lp_ctx->globals = talloc_zero(lp_ctx, struct loadparm_global);
2005 lp_ctx->sDefault = talloc_zero(lp_ctx, struct loadparm_service);
2007 lp_ctx->sDefault->iMaxPrintJobs = 1000;
2008 lp_ctx->sDefault->bAvailable = true;
2009 lp_ctx->sDefault->browseable = true;
2010 lp_ctx->sDefault->read_only = true;
2011 lp_ctx->sDefault->map_archive = true;
2012 lp_ctx->sDefault->strict_locking = true;
2013 lp_ctx->sDefault->oplocks = true;
2014 lp_ctx->sDefault->create_mask = 0744;
2015 lp_ctx->sDefault->force_create_mode = 0000;
2016 lp_ctx->sDefault->directory_mask = 0755;
2017 lp_ctx->sDefault->force_directory_mode = 0000;
2019 DEBUG(3, ("Initialising global parameters\n"));
2021 for (i = 0; parm_table[i].label; i++) {
2022 if ((parm_table[i].type == P_STRING ||
2023 parm_table[i].type == P_USTRING) &&
2024 !(lp_ctx->flags[i] & FLAG_CMDLINE)) {
2026 if (parm_table[i].p_class == P_LOCAL) {
2027 r = (char **)(((char *)lp_ctx->sDefault) + parm_table[i].offset);
2029 r = (char **)(((char *)lp_ctx->globals) + parm_table[i].offset);
2031 *r = talloc_strdup(lp_ctx, "");
2035 logfile = talloc_asprintf(lp_ctx, "%s/log.samba", dyn_LOGFILEBASE);
2036 lpcfg_do_global_parameter(lp_ctx, "log file", logfile);
2037 talloc_free(logfile);
2039 lpcfg_do_global_parameter(lp_ctx, "log level", "0");
2041 lpcfg_do_global_parameter(lp_ctx, "syslog", "1");
2042 lpcfg_do_global_parameter(lp_ctx, "syslog only", "No");
2043 lpcfg_do_global_parameter(lp_ctx, "debug timestamp", "Yes");
2044 lpcfg_do_global_parameter(lp_ctx, "debug prefix timestamp", "No");
2045 lpcfg_do_global_parameter(lp_ctx, "debug hires timestamp", "Yes");
2046 lpcfg_do_global_parameter(lp_ctx, "debug pid", "No");
2047 lpcfg_do_global_parameter(lp_ctx, "debug uid", "No");
2048 lpcfg_do_global_parameter(lp_ctx, "debug class", "No");
2050 lpcfg_do_global_parameter(lp_ctx, "share backend", "classic");
2052 lpcfg_do_global_parameter(lp_ctx, "server role", "auto");
2053 lpcfg_do_global_parameter(lp_ctx, "domain logons", "No");
2054 lpcfg_do_global_parameter(lp_ctx, "domain master", "Auto");
2056 /* options that can be set on the command line must be initialised via
2057 the slower lpcfg_do_global_parameter() to ensure that FLAG_CMDLINE is obeyed */
2059 lpcfg_do_global_parameter(lp_ctx, "socket options", "TCP_NODELAY");
2061 lpcfg_do_global_parameter(lp_ctx, "workgroup", DEFAULT_WORKGROUP);
2062 myname = get_myname(lp_ctx);
2063 lpcfg_do_global_parameter(lp_ctx, "netbios name", myname);
2064 talloc_free(myname);
2065 lpcfg_do_global_parameter(lp_ctx, "name resolve order", "lmhosts wins host bcast");
2067 lpcfg_do_global_parameter(lp_ctx, "fstype", "NTFS");
2069 lpcfg_do_global_parameter(lp_ctx, "ntvfs handler", "unixuid default");
2070 lpcfg_do_global_parameter(lp_ctx, "max connections", "0");
2072 lpcfg_do_global_parameter(lp_ctx, "dcerpc endpoint servers", "epmapper wkssvc rpcecho samr netlogon lsarpc spoolss drsuapi dssetup unixinfo browser eventlog6 backupkey dnsserver");
2073 lpcfg_do_global_parameter(lp_ctx, "server services", "s3fs rpc nbt wrepl ldap cldap kdc drepl winbind ntp_signd kcc dnsupdate dns");
2074 lpcfg_do_global_parameter(lp_ctx, "kccsrv:samba_kcc", "true");
2075 /* the winbind method for domain controllers is for both RODC
2076 auth forwarding and for trusted domains */
2077 lpcfg_do_global_parameter(lp_ctx, "private dir", dyn_PRIVATE_DIR);
2078 lpcfg_do_global_parameter(lp_ctx, "registry:HKEY_LOCAL_MACHINE", "hklm.ldb");
2080 /* This hive should be dynamically generated by Samba using
2081 data from the sam, but for the moment leave it in a tdb to
2082 keep regedt32 from popping up an annoying dialog. */
2083 lpcfg_do_global_parameter(lp_ctx, "registry:HKEY_USERS", "hku.ldb");
2085 /* using UTF8 by default allows us to support all chars */
2086 lpcfg_do_global_parameter(lp_ctx, "unix charset", "UTF-8");
2088 /* Use codepage 850 as a default for the dos character set */
2089 lpcfg_do_global_parameter(lp_ctx, "dos charset", "CP850");
2092 * Allow the default PASSWD_CHAT to be overridden in local.h.
2094 lpcfg_do_global_parameter(lp_ctx, "passwd chat", DEFAULT_PASSWD_CHAT);
2096 lpcfg_do_global_parameter(lp_ctx, "pid directory", dyn_PIDDIR);
2097 lpcfg_do_global_parameter(lp_ctx, "lock dir", dyn_LOCKDIR);
2098 lpcfg_do_global_parameter(lp_ctx, "state directory", dyn_STATEDIR);
2099 lpcfg_do_global_parameter(lp_ctx, "cache directory", dyn_CACHEDIR);
2100 lpcfg_do_global_parameter(lp_ctx, "ncalrpc dir", dyn_NCALRPCDIR);
2102 lpcfg_do_global_parameter(lp_ctx, "nbt client socket address", "0.0.0.0");
2103 lpcfg_do_global_parameter_var(lp_ctx, "server string",
2104 "Samba %s", SAMBA_VERSION_STRING);
2106 lpcfg_do_global_parameter(lp_ctx, "password server", "*");
2108 lpcfg_do_global_parameter(lp_ctx, "max mux", "50");
2109 lpcfg_do_global_parameter(lp_ctx, "max xmit", "16644");
2110 lpcfg_do_global_parameter(lp_ctx, "host msdfs", "true");
2112 lpcfg_do_global_parameter(lp_ctx, "LargeReadwrite", "True");
2113 lpcfg_do_global_parameter(lp_ctx, "server min protocol", "LANMAN1");
2114 lpcfg_do_global_parameter(lp_ctx, "server max protocol", "SMB3");
2115 lpcfg_do_global_parameter(lp_ctx, "client min protocol", "CORE");
2116 lpcfg_do_global_parameter(lp_ctx, "client max protocol", "NT1");
2117 lpcfg_do_global_parameter(lp_ctx, "security", "AUTO");
2118 lpcfg_do_global_parameter(lp_ctx, "EncryptPasswords", "True");
2119 lpcfg_do_global_parameter(lp_ctx, "ReadRaw", "True");
2120 lpcfg_do_global_parameter(lp_ctx, "WriteRaw", "True");
2121 lpcfg_do_global_parameter(lp_ctx, "NullPasswords", "False");
2122 lpcfg_do_global_parameter(lp_ctx, "ObeyPamRestrictions", "False");
2124 lpcfg_do_global_parameter(lp_ctx, "TimeServer", "False");
2125 lpcfg_do_global_parameter(lp_ctx, "BindInterfacesOnly", "False");
2126 lpcfg_do_global_parameter(lp_ctx, "Unicode", "True");
2127 lpcfg_do_global_parameter(lp_ctx, "ClientLanManAuth", "False");
2128 lpcfg_do_global_parameter(lp_ctx, "ClientNTLMv2Auth", "True");
2129 lpcfg_do_global_parameter(lp_ctx, "LanmanAuth", "False");
2130 lpcfg_do_global_parameter(lp_ctx, "NTLMAuth", "True");
2131 lpcfg_do_global_parameter(lp_ctx, "client use spnego principal", "False");
2133 lpcfg_do_global_parameter(lp_ctx, "UnixExtensions", "True");
2135 lpcfg_do_global_parameter(lp_ctx, "PreferredMaster", "Auto");
2136 lpcfg_do_global_parameter(lp_ctx, "LocalMaster", "True");
2138 lpcfg_do_global_parameter(lp_ctx, "wins support", "False");
2139 lpcfg_do_global_parameter(lp_ctx, "dns proxy", "True");
2141 lpcfg_do_global_parameter(lp_ctx, "winbind separator", "\\");
2142 lpcfg_do_global_parameter(lp_ctx, "winbind sealed pipes", "True");
2143 lpcfg_do_global_parameter(lp_ctx, "require strong key", "True");
2144 lpcfg_do_global_parameter(lp_ctx, "winbindd socket directory", dyn_WINBINDD_SOCKET_DIR);
2145 lpcfg_do_global_parameter(lp_ctx, "winbindd privileged socket directory", dyn_WINBINDD_PRIVILEGED_SOCKET_DIR);
2146 lpcfg_do_global_parameter(lp_ctx, "ntp signd socket directory", dyn_NTP_SIGND_SOCKET_DIR);
2147 lpcfg_do_global_parameter_var(lp_ctx, "dns update command", "%s/samba_dnsupdate", dyn_SCRIPTSBINDIR);
2148 lpcfg_do_global_parameter_var(lp_ctx, "spn update command", "%s/samba_spnupdate", dyn_SCRIPTSBINDIR);
2149 lpcfg_do_global_parameter_var(lp_ctx, "samba kcc command",
2150 "%s/samba_kcc", dyn_SCRIPTSBINDIR);
2151 lpcfg_do_global_parameter(lp_ctx, "template shell", "/bin/false");
2152 lpcfg_do_global_parameter(lp_ctx, "template homedir", "/home/%WORKGROUP%/%ACCOUNTNAME%");
2154 lpcfg_do_global_parameter(lp_ctx, "client signing", "default");
2155 lpcfg_do_global_parameter(lp_ctx, "server signing", "default");
2157 lpcfg_do_global_parameter(lp_ctx, "use spnego", "True");
2159 lpcfg_do_global_parameter(lp_ctx, "use mmap", "True");
2161 lpcfg_do_global_parameter(lp_ctx, "smb ports", "445 139");
2162 lpcfg_do_global_parameter(lp_ctx, "nbt port", "137");
2163 lpcfg_do_global_parameter(lp_ctx, "dgram port", "138");
2164 lpcfg_do_global_parameter(lp_ctx, "cldap port", "389");
2165 lpcfg_do_global_parameter(lp_ctx, "krb5 port", "88");
2166 lpcfg_do_global_parameter(lp_ctx, "kpasswd port", "464");
2167 lpcfg_do_global_parameter(lp_ctx, "web port", "901");
2169 lpcfg_do_global_parameter(lp_ctx, "nt status support", "True");
2171 lpcfg_do_global_parameter(lp_ctx, "max wins ttl", "518400"); /* 6 days */
2172 lpcfg_do_global_parameter(lp_ctx, "min wins ttl", "21600");
2174 lpcfg_do_global_parameter(lp_ctx, "tls enabled", "True");
2175 lpcfg_do_global_parameter(lp_ctx, "tls keyfile", "tls/key.pem");
2176 lpcfg_do_global_parameter(lp_ctx, "tls certfile", "tls/cert.pem");
2177 lpcfg_do_global_parameter(lp_ctx, "tls cafile", "tls/ca.pem");
2178 lpcfg_do_global_parameter(lp_ctx, "prefork children:smb", "4");
2180 lpcfg_do_global_parameter(lp_ctx, "rndc command", "/usr/sbin/rndc");
2181 lpcfg_do_global_parameter(lp_ctx, "nsupdate command", "/usr/bin/nsupdate -g");
2183 lpcfg_do_global_parameter(lp_ctx, "allow dns updates", "secure only");
2184 lpcfg_do_global_parameter(lp_ctx, "dns forwarder", "");
2186 lpcfg_do_global_parameter(lp_ctx, "algorithmic rid base", "1000");
2188 lpcfg_do_global_parameter(lp_ctx, "enhanced browsing", "True");
2190 lpcfg_do_global_parameter(lp_ctx, "winbind nss info", "template");
2192 lpcfg_do_global_parameter(lp_ctx, "server schannel", "Auto");
2194 lpcfg_do_global_parameter(lp_ctx, "short preserve case", "True");
2196 lpcfg_do_global_parameter(lp_ctx, "max open files", "16384");
2198 lpcfg_do_global_parameter(lp_ctx, "cups connection timeout", "30");
2200 lpcfg_do_global_parameter(lp_ctx, "locking", "True");
2202 lpcfg_do_global_parameter(lp_ctx, "block size", "1024");
2204 lpcfg_do_global_parameter(lp_ctx, "client use spnego", "True");
2206 lpcfg_do_global_parameter(lp_ctx, "change notify", "True");
2208 lpcfg_do_global_parameter(lp_ctx, "name cache timeout", "660");
2210 lpcfg_do_global_parameter(lp_ctx, "defer sharing violations", "True");
2212 lpcfg_do_global_parameter(lp_ctx, "ldap replication sleep", "1000");
2214 lpcfg_do_global_parameter(lp_ctx, "idmap backend", "tdb");
2216 lpcfg_do_global_parameter(lp_ctx, "enable privileges", "True");
2218 lpcfg_do_global_parameter(lp_ctx, "smb2 max write", "1048576");
2220 lpcfg_do_global_parameter(lp_ctx, "passdb backend", "tdbsam");
2222 lpcfg_do_global_parameter(lp_ctx, "getwd cache", "True");
2224 lpcfg_do_global_parameter(lp_ctx, "winbind nested groups", "True");
2226 lpcfg_do_global_parameter(lp_ctx, "mangled names", "True");
2228 lpcfg_do_global_parameter(lp_ctx, "smb2 max credits", "8192");
2230 lpcfg_do_global_parameter(lp_ctx, "ldap ssl", "start tls");
2232 lpcfg_do_global_parameter(lp_ctx, "ldap deref", "auto");
2234 lpcfg_do_global_parameter(lp_ctx, "lm interval", "60");
2236 lpcfg_do_global_parameter(lp_ctx, "mangling method", "hash2");
2238 lpcfg_do_global_parameter(lp_ctx, "hide dot files", "True");
2240 lpcfg_do_global_parameter(lp_ctx, "browse list", "True");
2242 lpcfg_do_global_parameter(lp_ctx, "passwd chat timeout", "2");
2244 lpcfg_do_global_parameter(lp_ctx, "guest account", GUEST_ACCOUNT);
2246 lpcfg_do_global_parameter(lp_ctx, "client schannel", "auto");
2248 lpcfg_do_global_parameter(lp_ctx, "smb encrypt", "default");
2250 lpcfg_do_global_parameter(lp_ctx, "max log size", "5000");
2252 lpcfg_do_global_parameter(lp_ctx, "idmap negative cache time", "120");
2254 lpcfg_do_global_parameter(lp_ctx, "ldap follow referral", "auto");
2256 lpcfg_do_global_parameter(lp_ctx, "multicast dns register", "yes");
2258 lpcfg_do_global_parameter(lp_ctx, "winbind reconnect delay", "30");
2260 lpcfg_do_global_parameter(lp_ctx, "nt acl support", "yes");
2262 lpcfg_do_global_parameter(lp_ctx, "acl check permissions", "yes");
2264 lpcfg_do_global_parameter(lp_ctx, "keepalive", "300");
2266 lpcfg_do_global_parameter(lp_ctx, "winbind cache time", "300");
2268 lpcfg_do_global_parameter(lp_ctx, "level2 oplocks", "yes");
2270 lpcfg_do_global_parameter(lp_ctx, "show add printer wizard", "yes");
2272 lpcfg_do_global_parameter(lp_ctx, "allocation roundup size", "1048576");
2274 lpcfg_do_global_parameter(lp_ctx, "ldap page size", "1024");
2276 lpcfg_do_global_parameter(lp_ctx, "kernel share modes", "yes");
2278 lpcfg_do_global_parameter(lp_ctx, "strict locking", "Auto");
2280 lpcfg_do_global_parameter(lp_ctx, "map readonly", "yes");
2282 lpcfg_do_global_parameter(lp_ctx, "allow trusted domains", "yes");
2284 lpcfg_do_global_parameter(lp_ctx, "default devmode", "yes");
2286 lpcfg_do_global_parameter(lp_ctx, "os level", "20");
2288 lpcfg_do_global_parameter(lp_ctx, "dos filetimes", "yes");
2290 lpcfg_do_global_parameter(lp_ctx, "mangling char", "~");
2292 lpcfg_do_global_parameter(lp_ctx, "printcap cache time", "750");
2294 lpcfg_do_global_parameter(lp_ctx, "create krb5 conf", "yes");
2296 lpcfg_do_global_parameter(lp_ctx, "winbind max clients", "200");
2298 lpcfg_do_global_parameter(lp_ctx, "acl map full control", "yes");
2300 lpcfg_do_global_parameter(lp_ctx, "nt pipe support", "yes");
2302 lpcfg_do_global_parameter(lp_ctx, "ldap debug threshold", "10");
2304 lpcfg_do_global_parameter(lp_ctx, "follow symlinks", "yes");
2306 lpcfg_do_global_parameter(lp_ctx, "machine password timeout", "604800");
2308 lpcfg_do_global_parameter(lp_ctx, "ldap connection timeout", "2");
2310 lpcfg_do_global_parameter(lp_ctx, "winbind expand groups", "1");
2312 lpcfg_do_global_parameter(lp_ctx, "stat cache", "yes");
2314 lpcfg_do_global_parameter(lp_ctx, "lpq cache time", "30");
2316 lpcfg_do_global_parameter(lp_ctx, "smb2 max trans", "1048576");
2318 lpcfg_do_global_parameter(lp_ctx, "smb2 max read", "1048576");
2320 lpcfg_do_global_parameter(lp_ctx, "durable handles", "yes");
2322 lpcfg_do_global_parameter(lp_ctx, "max stat cache size", "256");
2324 lpcfg_do_global_parameter(lp_ctx, "ldap passwd sync", "no");
2326 lpcfg_do_global_parameter(lp_ctx, "kernel change notify", "yes");
2328 lpcfg_do_global_parameter(lp_ctx, "max ttl", "259200");
2330 lpcfg_do_global_parameter(lp_ctx, "blocking locks", "yes");
2332 lpcfg_do_global_parameter(lp_ctx, "oplock contention limit", "2");
2334 lpcfg_do_global_parameter(lp_ctx, "load printers", "yes");
2336 lpcfg_do_global_parameter(lp_ctx, "idmap cache time", "604800");
2338 lpcfg_do_global_parameter(lp_ctx, "preserve case", "yes");
2340 lpcfg_do_global_parameter(lp_ctx, "lm announce", "auto");
2342 lpcfg_do_global_parameter(lp_ctx, "afs token lifetime", "604800");
2344 lpcfg_do_global_parameter(lp_ctx, "enable core files", "yes");
2346 lpcfg_do_global_parameter(lp_ctx, "winbind max domain connections", "1");
2348 lpcfg_do_global_parameter(lp_ctx, "case sensitive", "auto");
2350 lpcfg_do_global_parameter(lp_ctx, "ldap timeout", "15");
2352 lpcfg_do_global_parameter(lp_ctx, "mangle prefix", "1");
2354 lpcfg_do_global_parameter(lp_ctx, "posix locking", "yes");
2356 lpcfg_do_global_parameter(lp_ctx, "lock spin time", "200");
2358 lpcfg_do_global_parameter(lp_ctx, "directory name cache size", "100");
2360 lpcfg_do_global_parameter(lp_ctx, "nmbd bind explicit broadcast", "yes");
2362 lpcfg_do_global_parameter(lp_ctx, "init logon delay", "100");
2364 lpcfg_do_global_parameter(lp_ctx, "usershare owner only", "yes");
2366 lpcfg_do_global_parameter(lp_ctx, "-valid", "yes");
2368 lpcfg_do_global_parameter_var(lp_ctx, "usershare path", "%s/usershares", get_dyn_STATEDIR());
2371 lpcfg_do_global_parameter_var(lp_ctx, "panic action", "/bin/sleep 999999999");
2374 lpcfg_do_global_parameter(lp_ctx, "smb passwd file", get_dyn_SMB_PASSWD_FILE());
2376 lpcfg_do_global_parameter(lp_ctx, "logon home", "\\\\%N\\%U");
2378 lpcfg_do_global_parameter(lp_ctx, "logon path", "\\\\%N\\%U\\profile");
2380 lpcfg_do_global_parameter(lp_ctx, "printjob username", "%U");
2382 for (i = 0; parm_table[i].label; i++) {
2383 if (!(lp_ctx->flags[i] & FLAG_CMDLINE)) {
2384 lp_ctx->flags[i] |= FLAG_DEFAULT;
2388 for (parm=lp_ctx->globals->param_opt; parm; parm=parm->next) {
2389 if (!(parm->priority & FLAG_CMDLINE)) {
2390 parm->priority |= FLAG_DEFAULT;
2398 * Initialise the global parameter structure.
2400 struct loadparm_context *loadparm_init_global(bool load_default)
2402 if (global_loadparm_context == NULL) {
2403 global_loadparm_context = loadparm_init(NULL);
2405 if (global_loadparm_context == NULL) {
2408 global_loadparm_context->global = true;
2409 if (load_default && !global_loadparm_context->loaded) {
2410 lpcfg_load_default(global_loadparm_context);
2412 global_loadparm_context->refuse_free = true;
2413 return global_loadparm_context;
2417 * Initialise the global parameter structure.
2419 struct loadparm_context *loadparm_init_s3(TALLOC_CTX *mem_ctx,
2420 const struct loadparm_s3_helpers *s3_fns)
2422 struct loadparm_context *loadparm_context = talloc_zero(mem_ctx, struct loadparm_context);
2423 if (!loadparm_context) {
2426 loadparm_context->s3_fns = s3_fns;
2427 return loadparm_context;
2430 const char *lpcfg_configfile(struct loadparm_context *lp_ctx)
2432 return lp_ctx->szConfigFile;
2435 const char *lp_default_path(void)
2437 if (getenv("SMB_CONF_PATH"))
2438 return getenv("SMB_CONF_PATH");
2440 return dyn_CONFIGFILE;
2444 * Update the internal state of a loadparm context after settings
2447 static bool lpcfg_update(struct loadparm_context *lp_ctx)
2449 struct debug_settings settings;
2450 lpcfg_add_auto_services(lp_ctx, lpcfg_auto_services(lp_ctx));
2452 if (!lp_ctx->globals->wins_server_list && lp_ctx->globals->we_are_a_wins_server) {
2453 lpcfg_do_global_parameter(lp_ctx, "wins server", "127.0.0.1");
2456 if (!lp_ctx->global) {
2460 panic_action = lp_ctx->globals->panic_action;
2462 reload_charcnv(lp_ctx);
2464 ZERO_STRUCT(settings);
2465 /* Add any more debug-related smb.conf parameters created in
2467 settings.syslog = lp_ctx->globals->syslog;
2468 settings.syslog_only = lp_ctx->globals->syslog_only;
2469 settings.timestamp_logs = lp_ctx->globals->timestamp_logs;
2470 settings.debug_prefix_timestamp = lp_ctx->globals->debug_prefix_timestamp;
2471 settings.debug_hires_timestamp = lp_ctx->globals->debug_hires_timestamp;
2472 settings.debug_pid = lp_ctx->globals->debug_pid;
2473 settings.debug_uid = lp_ctx->globals->debug_uid;
2474 settings.debug_class = lp_ctx->globals->debug_class;
2475 debug_set_settings(&settings);
2477 /* FIXME: This is a bit of a hack, but we can't use a global, since
2478 * not everything that uses lp also uses the socket library */
2479 if (lpcfg_parm_bool(lp_ctx, NULL, "socket", "testnonblock", false)) {
2480 setenv("SOCKET_TESTNONBLOCK", "1", 1);
2482 unsetenv("SOCKET_TESTNONBLOCK");
2488 bool lpcfg_load_default(struct loadparm_context *lp_ctx)
2492 path = lp_default_path();
2494 if (!file_exist(path)) {
2495 /* We allow the default smb.conf file to not exist,
2496 * basically the equivalent of an empty file. */
2497 return lpcfg_update(lp_ctx);
2500 return lpcfg_load(lp_ctx, path);
2504 * Load the services array from the services file.
2506 * Return True on success, False on failure.
2508 bool lpcfg_load(struct loadparm_context *lp_ctx, const char *filename)
2513 filename = talloc_strdup(lp_ctx, filename);
2515 lp_ctx->szConfigFile = filename;
2517 if (lp_ctx->s3_fns) {
2518 return lp_ctx->s3_fns->load(filename);
2521 lp_ctx->bInGlobalSection = true;
2522 n2 = standard_sub_basic(lp_ctx, lp_ctx->szConfigFile);
2523 DEBUG(2, ("lpcfg_load: refreshing parameters from %s\n", n2));
2525 add_to_file_list(lp_ctx, lp_ctx->szConfigFile, n2);
2527 /* We get sections first, so have to start 'behind' to make up */
2528 lp_ctx->currentService = NULL;
2529 bRetval = pm_process(n2, do_section, do_parameter, lp_ctx);
2531 /* finish up the last section */
2532 DEBUG(4, ("pm_process() returned %s\n", BOOLSTR(bRetval)));
2534 if (lp_ctx->currentService != NULL)
2535 bRetval = lpcfg_service_ok(lp_ctx->currentService);
2537 bRetval = bRetval && lpcfg_update(lp_ctx);
2539 /* we do this unconditionally, so that it happens even
2540 for a missing smb.conf */
2541 reload_charcnv(lp_ctx);
2543 if (bRetval == true) {
2544 /* set this up so that any child python tasks will
2545 find the right smb.conf */
2546 setenv("SMB_CONF_PATH", filename, 1);
2548 /* set the context used by the lp_*() function
2550 global_loadparm_context = lp_ctx;
2551 lp_ctx->loaded = true;
2558 * Return the max number of services.
2561 int lpcfg_numservices(struct loadparm_context *lp_ctx)
2563 if (lp_ctx->s3_fns) {
2564 return lp_ctx->s3_fns->get_numservices();
2567 return lp_ctx->iNumServices;
2571 * Display the contents of the services array in human-readable form.
2574 void lpcfg_dump(struct loadparm_context *lp_ctx, FILE *f, bool show_defaults,
2579 if (lp_ctx->s3_fns) {
2580 lp_ctx->s3_fns->dump(f, show_defaults, maxtoprint);
2584 defaults_saved = !show_defaults;
2586 dump_globals(lp_ctx, f, show_defaults);
2588 dump_a_service(lp_ctx->sDefault, lp_ctx->sDefault, f, lp_ctx->flags);
2590 for (iService = 0; iService < maxtoprint; iService++)
2591 lpcfg_dump_one(f, show_defaults, lp_ctx->services[iService], lp_ctx->sDefault);
2595 * Display the contents of one service in human-readable form.
2597 void lpcfg_dump_one(FILE *f, bool show_defaults, struct loadparm_service *service, struct loadparm_service *sDefault)
2599 if (service != NULL) {
2600 if (service->szService[0] == '\0')
2602 dump_a_service(service, sDefault, f, NULL);
2606 struct loadparm_service *lpcfg_servicebynum(struct loadparm_context *lp_ctx,
2609 if (lp_ctx->s3_fns) {
2610 return lp_ctx->s3_fns->get_servicebynum(snum);
2613 return lp_ctx->services[snum];
2616 struct loadparm_service *lpcfg_service(struct loadparm_context *lp_ctx,
2617 const char *service_name)
2622 if (lp_ctx->s3_fns) {
2623 return lp_ctx->s3_fns->get_service(service_name);
2626 for (iService = lp_ctx->iNumServices - 1; iService >= 0; iService--) {
2627 if (lp_ctx->services[iService] &&
2628 lp_ctx->services[iService]->szService) {
2630 * The substitution here is used to support %U is
2633 serviceName = standard_sub_basic(
2634 lp_ctx->services[iService],
2635 lp_ctx->services[iService]->szService);
2636 if (strequal(serviceName, service_name)) {
2637 talloc_free(serviceName);
2638 return lp_ctx->services[iService];
2640 talloc_free(serviceName);
2644 DEBUG(7,("lpcfg_servicenumber: couldn't find %s\n", service_name));
2648 const char *lpcfg_servicename(const struct loadparm_service *service)
2650 return lp_string((const char *)service->szService);
2654 * A useful volume label function.
2656 const char *lpcfg_volume_label(struct loadparm_service *service, struct loadparm_service *sDefault)
2659 ret = lp_string((const char *)((service != NULL && service->volume != NULL) ?
2660 service->volume : sDefault->volume));
2662 return lpcfg_servicename(service);
2667 * Return the correct printer name.
2669 const char *lpcfg_printername(struct loadparm_service *service, struct loadparm_service *sDefault)
2672 ret = lp_string((const char *)((service != NULL && service->_printername != NULL) ?
2673 service->_printername : sDefault->_printername));
2674 if (ret == NULL || (ret != NULL && *ret == '\0'))
2675 ret = lpcfg_servicename(service);
2682 * Return the max print jobs per queue.
2684 int lpcfg_maxprintjobs(struct loadparm_service *service, struct loadparm_service *sDefault)
2686 int maxjobs = (service != NULL) ? service->iMaxPrintJobs : sDefault->iMaxPrintJobs;
2687 if (maxjobs <= 0 || maxjobs >= PRINT_MAX_JOBID)
2688 maxjobs = PRINT_MAX_JOBID - 1;
2693 struct smb_iconv_handle *lpcfg_iconv_handle(struct loadparm_context *lp_ctx)
2695 if (lp_ctx == NULL) {
2696 return get_iconv_handle();
2698 return lp_ctx->iconv_handle;
2701 _PUBLIC_ void reload_charcnv(struct loadparm_context *lp_ctx)
2703 struct smb_iconv_handle *old_ic = lp_ctx->iconv_handle;
2704 if (!lp_ctx->global) {
2708 if (old_ic == NULL) {
2709 old_ic = global_iconv_handle;
2711 lp_ctx->iconv_handle = smb_iconv_handle_reinit_lp(lp_ctx, lp_ctx, old_ic);
2712 global_iconv_handle = lp_ctx->iconv_handle;
2715 _PUBLIC_ char *lpcfg_tls_keyfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
2717 return lpcfg_private_path(mem_ctx, lp_ctx, lp_ctx->globals->tls_keyfile);
2720 _PUBLIC_ char *lpcfg_tls_certfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
2722 return lpcfg_private_path(mem_ctx, lp_ctx, lp_ctx->globals->tls_certfile);
2725 _PUBLIC_ char *lpcfg_tls_cafile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
2727 return lpcfg_private_path(mem_ctx, lp_ctx, lp_ctx->globals->tls_cafile);
2730 _PUBLIC_ char *lpcfg_tls_crlfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
2732 return lpcfg_private_path(mem_ctx, lp_ctx, lp_ctx->globals->tls_crlfile);
2735 _PUBLIC_ char *lpcfg_tls_dhpfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
2737 return lpcfg_private_path(mem_ctx, lp_ctx, lp_ctx->globals->tls_dhpfile);
2740 struct gensec_settings *lpcfg_gensec_settings(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
2742 struct gensec_settings *settings = talloc_zero(mem_ctx, struct gensec_settings);
2743 if (settings == NULL)
2745 SMB_ASSERT(lp_ctx != NULL);
2746 settings->lp_ctx = talloc_reference(settings, lp_ctx);
2747 settings->target_hostname = lpcfg_parm_string(lp_ctx, NULL, "gensec", "target_hostname");
2751 int lpcfg_server_role(struct loadparm_context *lp_ctx)
2753 int domain_master = lpcfg__domain_master(lp_ctx);
2755 return lp_find_server_role(lpcfg__server_role(lp_ctx),
2756 lpcfg__security(lp_ctx),
2757 lpcfg__domain_logons(lp_ctx),
2758 (domain_master == true) ||
2759 (domain_master == Auto));
2762 int lpcfg_security(struct loadparm_context *lp_ctx)
2764 return lp_find_security(lpcfg__server_role(lp_ctx),
2765 lpcfg__security(lp_ctx));
2768 bool lpcfg_server_signing_allowed(struct loadparm_context *lp_ctx, bool *mandatory)
2770 bool allowed = true;
2771 enum smb_signing_setting signing_setting = lpcfg_server_signing(lp_ctx);
2775 if (signing_setting == SMB_SIGNING_DEFAULT) {
2777 * If we are a domain controller, SMB signing is
2778 * really important, as it can prevent a number of
2779 * attacks on communications between us and the
2782 * However, it really sucks (no sendfile, CPU
2783 * overhead) performance-wise when used on a
2784 * file server, so disable it by default
2788 if (lpcfg_server_role(lp_ctx) >= ROLE_ACTIVE_DIRECTORY_DC) {
2789 signing_setting = SMB_SIGNING_REQUIRED;
2791 signing_setting = SMB_SIGNING_OFF;
2795 switch (signing_setting) {
2796 case SMB_SIGNING_REQUIRED:
2799 case SMB_SIGNING_IF_REQUIRED:
2801 case SMB_SIGNING_DEFAULT:
2802 case SMB_SIGNING_OFF: