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; \
78 int iminreceivefile; \
79 char *szPrintcapname; \
81 int iPreferredMaster; \
82 char *szLdapMachineSuffix; \
83 char *szLdapUserSuffix; \
84 char *szLdapIdmapSuffix; \
85 char *szLdapGroupSuffix; \
88 char *szIdmapBackend; \
89 int winbindMaxDomainConnections; \
90 int ismb2_max_credits;
92 #include "lib/param/param_global.h"
94 #define NUMPARAMETERS (sizeof(parm_table) / sizeof(struct parm_struct))
96 /* we don't need a special handler for "dos charset" and "unix charset" */
97 #define handle_dos_charset NULL
98 #define handle_charset NULL
100 /* these are parameter handlers which are not needed in the
103 #define handle_netbios_aliases NULL
104 #define handle_printing NULL
105 #define handle_ldap_debug_level NULL
106 #define handle_idmap_backend NULL
107 #define handle_idmap_uid NULL
108 #define handle_idmap_gid NULL
114 /* prototypes for the special type handlers */
115 static bool handle_include(struct loadparm_context *lp_ctx, int unused,
116 const char *pszParmValue, char **ptr);
117 static bool handle_realm(struct loadparm_context *lp_ctx, int unused,
118 const char *pszParmValue, char **ptr);
119 static bool handle_copy(struct loadparm_context *lp_ctx, int unused,
120 const char *pszParmValue, char **ptr);
121 static bool handle_debug_list(struct loadparm_context *lp_ctx, int unused,
122 const char *pszParmValue, char **ptr);
123 static bool handle_logfile(struct loadparm_context *lp_ctx, int unused,
124 const char *pszParmValue, char **ptr);
126 #include "lib/param/param_table.c"
128 /* local variables */
129 struct loadparm_context {
130 const char *szConfigFile;
131 struct loadparm_global *globals;
132 struct loadparm_service **services;
133 struct loadparm_service *sDefault;
134 struct smb_iconv_handle *iconv_handle;
136 struct loadparm_service *currentService;
137 bool bInGlobalSection;
139 struct file_lists *next;
144 unsigned int flags[NUMPARAMETERS];
147 bool global; /* Is this the global context, which may set
148 * global variables such as debug level etc? */
149 const struct loadparm_s3_helpers *s3_fns;
153 struct loadparm_service *lpcfg_default_service(struct loadparm_context *lp_ctx)
155 if (lp_ctx->s3_fns) {
156 return lp_ctx->s3_fns->get_default_loadparm_service();
158 return lp_ctx->sDefault;
162 * Convenience routine to grab string parameters into temporary memory
163 * and run standard_sub_basic on them.
165 * The buffers can be written to by
166 * callers without affecting the source string.
169 static const char *lp_string(const char *s)
171 #if 0 /* until REWRITE done to make thread-safe */
172 size_t len = s ? strlen(s) : 0;
176 /* The follow debug is useful for tracking down memory problems
177 especially if you have an inner loop that is calling a lp_*()
178 function that returns a string. Perhaps this debug should be
179 present all the time? */
182 DEBUG(10, ("lp_string(%s)\n", s));
185 #if 0 /* until REWRITE done to make thread-safe */
187 lp_talloc = talloc_init("lp_talloc");
189 ret = talloc_array(lp_talloc, char, len + 100); /* leave room for substitution */
197 strlcpy(ret, s, len);
199 if (trim_string(ret, "\"", "\"")) {
200 if (strchr(ret,'"') != NULL)
201 strlcpy(ret, s, len);
204 standard_sub_basic(ret,len+100);
211 In this section all the functions that are used to access the
212 parameters from the rest of the program are defined
216 * the creation of separate lpcfg_*() and lp_*() functions is to allow
217 * for code compatibility between existing Samba4 and Samba3 code.
220 /* this global context supports the lp_*() function varients */
221 static struct loadparm_context *global_loadparm_context;
223 #define lpcfg_default_service global_loadparm_context->sDefault
224 #define lpcfg_global_service(i) global_loadparm_context->services[i]
226 #define FN_GLOBAL_STRING(fn_name,var_name) \
227 _PUBLIC_ const char *lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) {\
228 if (lp_ctx == NULL) return NULL; \
229 if (lp_ctx->s3_fns) { \
230 smb_panic( __location__ ": " #fn_name " not implemented because it is an allocated and substiuted string"); \
232 return lp_ctx->globals->var_name ? lp_string(lp_ctx->globals->var_name) : ""; \
235 #define FN_GLOBAL_CONST_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_LIST(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; \
255 #define FN_GLOBAL_BOOL(fn_name,var_name) \
256 _PUBLIC_ bool lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) {\
257 if (lp_ctx == NULL) return false; \
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_INTEGER(fn_name,var_name) \
266 _PUBLIC_ int lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) { \
267 if (lp_ctx->s3_fns) { \
268 SMB_ASSERT(lp_ctx->s3_fns->fn_name); \
269 return lp_ctx->s3_fns->fn_name(); \
271 return lp_ctx->globals->var_name; \
274 /* Local parameters don't need the ->s3_fns because the struct
275 * loadparm_service is shared and lpcfg_service() checks the ->s3_fns
277 #define FN_LOCAL_STRING(fn_name,val) \
278 _PUBLIC_ const char *lpcfg_ ## fn_name(struct loadparm_service *service, \
279 struct loadparm_service *sDefault) { \
280 return(lp_string((const char *)((service != NULL && service->val != NULL) ? service->val : sDefault->val))); \
283 #define FN_LOCAL_CONST_STRING(fn_name,val) FN_LOCAL_STRING(fn_name, val)
285 #define FN_LOCAL_LIST(fn_name,val) \
286 _PUBLIC_ const char **lpcfg_ ## fn_name(struct loadparm_service *service, \
287 struct loadparm_service *sDefault) {\
288 return(const char **)(service != NULL && service->val != NULL? service->val : sDefault->val); \
291 #define FN_LOCAL_PARM_BOOL(fn_name, val) FN_LOCAL_BOOL(fn_name, val)
293 #define FN_LOCAL_BOOL(fn_name,val) \
294 _PUBLIC_ bool lpcfg_ ## fn_name(struct loadparm_service *service, \
295 struct loadparm_service *sDefault) { \
296 return((service != NULL)? service->val : sDefault->val); \
299 #define FN_LOCAL_INTEGER(fn_name,val) \
300 _PUBLIC_ int lpcfg_ ## fn_name(struct loadparm_service *service, \
301 struct loadparm_service *sDefault) { \
302 return((service != NULL)? service->val : sDefault->val); \
305 #define FN_LOCAL_PARM_INTEGER(fn_name, val) FN_LOCAL_INTEGER(fn_name, val)
307 #define FN_LOCAL_PARM_CHAR(fn_name,val) \
308 _PUBLIC_ char lpcfg_ ## fn_name(struct loadparm_service *service, \
309 struct loadparm_service *sDefault) { \
310 return((service != NULL)? service->val : sDefault->val); \
313 #include "lib/param/param_functions.c"
315 /* These functions cannot be auto-generated */
316 FN_LOCAL_BOOL(autoloaded, autoloaded)
317 FN_GLOBAL_CONST_STRING(dnsdomain, dnsdomain)
319 /* local prototypes */
320 static struct loadparm_service *getservicebyname(struct loadparm_context *lp_ctx,
321 const char *pszServiceName);
322 static void copy_service(struct loadparm_service *pserviceDest,
323 struct loadparm_service *pserviceSource,
324 struct bitmap *pcopymapDest);
325 static bool lpcfg_service_ok(struct loadparm_service *service);
326 static bool do_section(const char *pszSectionName, void *);
327 static void init_copymap(struct loadparm_service *pservice);
329 /* This is a helper function for parametrical options support. */
330 /* It returns a pointer to parametrical option value if it exists or NULL otherwise */
331 /* Actual parametrical functions are quite simple */
332 const char *lpcfg_get_parametric(struct loadparm_context *lp_ctx,
333 struct loadparm_service *service,
334 const char *type, const char *option)
336 char *vfskey_tmp = NULL;
338 struct parmlist_entry *data;
343 if (lp_ctx->s3_fns) {
344 return lp_ctx->s3_fns->get_parametric(service, type, option);
347 data = (service == NULL ? lp_ctx->globals->param_opt : service->param_opt);
349 vfskey_tmp = talloc_asprintf(NULL, "%s:%s", type, option);
350 if (vfskey_tmp == NULL) return NULL;
351 vfskey = strlower_talloc(NULL, vfskey_tmp);
352 talloc_free(vfskey_tmp);
355 if (strcmp(data->key, vfskey) == 0) {
362 if (service != NULL) {
363 /* Try to fetch the same option but from globals */
364 /* but only if we are not already working with globals */
365 for (data = lp_ctx->globals->param_opt; data;
367 if (strcmp(data->key, vfskey) == 0) {
381 * convenience routine to return int parameters.
383 static int lp_int(const char *s)
387 DEBUG(0,("lp_int(%s): is called with NULL!\n",s));
391 return strtol(s, NULL, 0);
395 * convenience routine to return unsigned long parameters.
397 static unsigned long lp_ulong(const char *s)
401 DEBUG(0,("lp_ulong(%s): is called with NULL!\n",s));
405 return strtoul(s, NULL, 0);
409 * convenience routine to return unsigned long parameters.
411 static long lp_long(const char *s)
415 DEBUG(0,("lp_long(%s): is called with NULL!\n",s));
419 return strtol(s, NULL, 0);
423 * convenience routine to return unsigned long parameters.
425 static double lp_double(const char *s)
429 DEBUG(0,("lp_double(%s): is called with NULL!\n",s));
433 return strtod(s, NULL);
437 * convenience routine to return boolean parameters.
439 static bool lp_bool(const char *s)
444 DEBUG(0,("lp_bool(%s): is called with NULL!\n",s));
448 if (!set_boolean(s, &ret)) {
449 DEBUG(0,("lp_bool(%s): value is not boolean!\n",s));
458 * Return parametric option from a given service. Type is a part of option before ':'
459 * Parametric option has following syntax: 'Type: option = value'
460 * Returned value is allocated in 'lp_talloc' context
463 const char *lpcfg_parm_string(struct loadparm_context *lp_ctx,
464 struct loadparm_service *service, const char *type,
467 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
470 return lp_string(value);
476 * Return parametric option from a given service. Type is a part of option before ':'
477 * Parametric option has following syntax: 'Type: option = value'
478 * Returned value is allocated in 'lp_talloc' context
481 const char **lpcfg_parm_string_list(TALLOC_CTX *mem_ctx,
482 struct loadparm_context *lp_ctx,
483 struct loadparm_service *service,
485 const char *option, const char *separator)
487 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
490 return (const char **)str_list_make(mem_ctx, value, separator);
496 * Return parametric option from a given service. Type is a part of option before ':'
497 * Parametric option has following syntax: 'Type: option = value'
500 int lpcfg_parm_int(struct loadparm_context *lp_ctx,
501 struct loadparm_service *service, const char *type,
502 const char *option, int default_v)
504 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
507 return lp_int(value);
513 * Return parametric option from a given service. Type is a part of
515 * Parametric option has following syntax: 'Type: option = value'.
518 int lpcfg_parm_bytes(struct loadparm_context *lp_ctx,
519 struct loadparm_service *service, const char *type,
520 const char *option, int default_v)
524 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
526 if (value && conv_str_size_error(value, &bval)) {
527 if (bval <= INT_MAX) {
536 * Return parametric option from a given service.
537 * Type is a part of option before ':'
538 * Parametric option has following syntax: 'Type: option = value'
540 unsigned long lpcfg_parm_ulong(struct loadparm_context *lp_ctx,
541 struct loadparm_service *service, const char *type,
542 const char *option, unsigned long default_v)
544 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
547 return lp_ulong(value);
552 long lpcfg_parm_long(struct loadparm_context *lp_ctx,
553 struct loadparm_service *service, const char *type,
554 const char *option, long default_v)
556 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
559 return lp_long(value);
564 double lpcfg_parm_double(struct loadparm_context *lp_ctx,
565 struct loadparm_service *service, const char *type,
566 const char *option, double default_v)
568 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
571 return lp_double(value);
577 * Return parametric option from a given service. Type is a part of option before ':'
578 * Parametric option has following syntax: 'Type: option = value'
581 bool lpcfg_parm_bool(struct loadparm_context *lp_ctx,
582 struct loadparm_service *service, const char *type,
583 const char *option, bool default_v)
585 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
588 return lp_bool(value);
595 * Initialise a service to the defaults.
598 static struct loadparm_service *init_service(TALLOC_CTX *mem_ctx, struct loadparm_service *sDefault)
600 struct loadparm_service *pservice =
601 talloc_zero(mem_ctx, struct loadparm_service);
602 copy_service(pservice, sDefault, NULL);
607 * Set a string value, deallocating any existing space, and allocing the space
610 static bool lpcfg_string_set(TALLOC_CTX *mem_ctx, char **dest, const char *src)
617 *dest = talloc_strdup(mem_ctx, src);
618 if ((*dest) == NULL) {
619 DEBUG(0,("Out of memory in string_set\n"));
627 * Set a string value, deallocating any existing space, and allocing the space
630 static bool lpcfg_string_set_upper(TALLOC_CTX *mem_ctx, char **dest, const char *src)
637 *dest = strupper_talloc(mem_ctx, src);
638 if ((*dest) == NULL) {
639 DEBUG(0,("Out of memory in string_set_upper\n"));
649 * Add a new service to the services array initialising it with the given
653 struct loadparm_service *lpcfg_add_service(struct loadparm_context *lp_ctx,
654 const struct loadparm_service *pservice,
658 struct loadparm_service tservice;
659 int num_to_alloc = lp_ctx->iNumServices + 1;
660 struct parmlist_entry *data, *pdata;
662 if (pservice == NULL) {
663 pservice = lp_ctx->sDefault;
666 tservice = *pservice;
668 /* it might already exist */
670 struct loadparm_service *service = getservicebyname(lp_ctx,
672 if (service != NULL) {
673 /* Clean all parametric options for service */
674 /* They will be added during parsing again */
675 data = service->param_opt;
681 service->param_opt = NULL;
686 /* find an invalid one */
687 for (i = 0; i < lp_ctx->iNumServices; i++)
688 if (lp_ctx->services[i] == NULL)
691 /* if not, then create one */
692 if (i == lp_ctx->iNumServices) {
693 struct loadparm_service **tsp;
695 tsp = talloc_realloc(lp_ctx, lp_ctx->services, struct loadparm_service *, num_to_alloc);
698 DEBUG(0,("lpcfg_add_service: failed to enlarge services!\n"));
701 lp_ctx->services = tsp;
702 lp_ctx->services[lp_ctx->iNumServices] = NULL;
705 lp_ctx->iNumServices++;
708 lp_ctx->services[i] = init_service(lp_ctx->services, lp_ctx->sDefault);
709 if (lp_ctx->services[i] == NULL) {
710 DEBUG(0,("lpcfg_add_service: out of memory!\n"));
713 copy_service(lp_ctx->services[i], &tservice, NULL);
715 lpcfg_string_set(lp_ctx->services[i], &lp_ctx->services[i]->szService, name);
716 return lp_ctx->services[i];
720 * Add a new home service, with the specified home directory, defaults coming
721 * from service ifrom.
724 bool lpcfg_add_home(struct loadparm_context *lp_ctx,
725 const char *pszHomename,
726 struct loadparm_service *default_service,
727 const char *user, const char *pszHomedir)
729 struct loadparm_service *service;
731 service = lpcfg_add_service(lp_ctx, default_service, pszHomename);
736 if (!(*(default_service->path))
737 || strequal(default_service->path, lp_ctx->sDefault->path)) {
738 service->path = talloc_strdup(service, pszHomedir);
740 service->path = string_sub_talloc(service, lpcfg_path(default_service, lp_ctx->sDefault), "%H", pszHomedir);
743 if (!(*(service->comment))) {
744 service->comment = talloc_asprintf(service, "Home directory of %s", user);
746 service->bAvailable = default_service->bAvailable;
747 service->browseable = default_service->browseable;
749 DEBUG(3, ("adding home's share [%s] for user '%s' at '%s'\n",
750 pszHomename, user, service->path));
756 * Add a new printer service, with defaults coming from service iFrom.
759 bool lpcfg_add_printer(struct loadparm_context *lp_ctx,
760 const char *pszPrintername,
761 struct loadparm_service *default_service)
763 const char *comment = "From Printcap";
764 struct loadparm_service *service;
765 service = lpcfg_add_service(lp_ctx, default_service, pszPrintername);
770 /* note that we do NOT default the availability flag to True - */
771 /* we take it from the default service passed. This allows all */
772 /* dynamic printers to be disabled by disabling the [printers] */
773 /* entry (if/when the 'available' keyword is implemented!). */
775 /* the printer name is set to the service name. */
776 lpcfg_string_set(service, &service->_printername, pszPrintername);
777 lpcfg_string_set(service, &service->comment, comment);
778 service->browseable = default_service->browseable;
779 /* Printers cannot be read_only. */
780 service->read_only = false;
781 /* Printer services must be printable. */
782 service->printable = true;
784 DEBUG(3, ("adding printer service %s\n", pszPrintername));
790 * Map a parameter's string representation to something we can use.
791 * Returns False if the parameter string is not recognised, else TRUE.
794 int lpcfg_map_parameter(const char *pszParmName)
798 for (iIndex = 0; parm_table[iIndex].label; iIndex++)
799 if (strwicmp(parm_table[iIndex].label, pszParmName) == 0)
802 /* Warn only if it isn't parametric option */
803 if (strchr(pszParmName, ':') == NULL)
804 DEBUG(0, ("Unknown parameter encountered: \"%s\"\n", pszParmName));
805 /* We do return 'fail' for parametric options as well because they are
806 stored in different storage
813 return the parameter structure for a parameter
815 struct parm_struct *lpcfg_parm_struct(struct loadparm_context *lp_ctx, const char *name)
819 if (lp_ctx->s3_fns) {
820 return lp_ctx->s3_fns->get_parm_struct(name);
823 parmnum = lpcfg_map_parameter(name);
824 if (parmnum == -1) return NULL;
825 return &parm_table[parmnum];
829 return the parameter pointer for a parameter
831 void *lpcfg_parm_ptr(struct loadparm_context *lp_ctx,
832 struct loadparm_service *service, struct parm_struct *parm)
834 if (lp_ctx->s3_fns) {
835 return lp_ctx->s3_fns->get_parm_ptr(service, parm);
838 if (service == NULL) {
839 if (parm->p_class == P_LOCAL)
840 return ((char *)lp_ctx->sDefault)+parm->offset;
841 else if (parm->p_class == P_GLOBAL)
842 return ((char *)lp_ctx->globals)+parm->offset;
845 return ((char *)service) + parm->offset;
850 return the parameter pointer for a parameter
852 bool lpcfg_parm_is_cmdline(struct loadparm_context *lp_ctx, const char *name)
856 if (lp_ctx->s3_fns) {
857 struct parm_struct *parm = lp_ctx->s3_fns->get_parm_struct(name);
859 return parm->flags & FLAG_CMDLINE;
864 parmnum = lpcfg_map_parameter(name);
865 if (parmnum == -1) return false;
867 return lp_ctx->flags[parmnum] & FLAG_CMDLINE;
871 * Find a service by name. Otherwise works like get_service.
874 static struct loadparm_service *getservicebyname(struct loadparm_context *lp_ctx,
875 const char *pszServiceName)
879 if (lp_ctx->s3_fns) {
880 return lp_ctx->s3_fns->get_service(pszServiceName);
883 for (iService = lp_ctx->iNumServices - 1; iService >= 0; iService--)
884 if (lp_ctx->services[iService] != NULL &&
885 strwicmp(lp_ctx->services[iService]->szService, pszServiceName) == 0) {
886 return lp_ctx->services[iService];
893 * Copy a service structure to another.
894 * If pcopymapDest is NULL then copy all fields
897 static void copy_service(struct loadparm_service *pserviceDest,
898 struct loadparm_service *pserviceSource,
899 struct bitmap *pcopymapDest)
902 bool bcopyall = (pcopymapDest == NULL);
903 struct parmlist_entry *data, *pdata, *paramo;
906 for (i = 0; parm_table[i].label; i++)
907 if (parm_table[i].p_class == P_LOCAL &&
908 (bcopyall || bitmap_query(pcopymapDest, i))) {
910 ((char *)pserviceSource) + parm_table[i].offset;
912 ((char *)pserviceDest) + parm_table[i].offset;
914 switch (parm_table[i].type) {
917 *(bool *)dest_ptr = *(bool *)src_ptr;
924 *(int *)dest_ptr = *(int *)src_ptr;
928 *(char *)dest_ptr = *(char *)src_ptr;
932 lpcfg_string_set(pserviceDest,
938 lpcfg_string_set_upper(pserviceDest,
943 *(const char ***)dest_ptr = (const char **)str_list_copy(pserviceDest,
944 *(const char ***)src_ptr);
952 init_copymap(pserviceDest);
953 if (pserviceSource->copymap)
954 bitmap_copy(pserviceDest->copymap,
955 pserviceSource->copymap);
958 data = pserviceSource->param_opt;
961 pdata = pserviceDest->param_opt;
962 /* Traverse destination */
964 /* If we already have same option, override it */
965 if (strcmp(pdata->key, data->key) == 0) {
966 talloc_free(pdata->value);
967 pdata->value = talloc_strdup(pdata,
975 paramo = talloc_zero(pserviceDest, struct parmlist_entry);
978 paramo->key = talloc_strdup(paramo, data->key);
979 paramo->value = talloc_strdup(paramo, data->value);
980 DLIST_ADD(pserviceDest->param_opt, paramo);
987 * Check a service for consistency. Return False if the service is in any way
988 * incomplete or faulty, else True.
990 static bool lpcfg_service_ok(struct loadparm_service *service)
995 if (service->szService[0] == '\0') {
996 DEBUG(0, ("The following message indicates an internal error:\n"));
997 DEBUG(0, ("No service name in service entry.\n"));
1001 /* The [printers] entry MUST be printable. I'm all for flexibility, but */
1002 /* I can't see why you'd want a non-printable printer service... */
1003 if (strwicmp(service->szService, PRINTERS_NAME) == 0) {
1004 if (!service->printable) {
1005 DEBUG(0, ("WARNING: [%s] service MUST be printable!\n",
1006 service->szService));
1007 service->printable = true;
1009 /* [printers] service must also be non-browsable. */
1010 if (service->browseable)
1011 service->browseable = false;
1014 /* If a service is flagged unavailable, log the fact at level 0. */
1015 if (!service->bAvailable)
1016 DEBUG(1, ("NOTE: Service %s is flagged unavailable.\n",
1017 service->szService));
1023 /*******************************************************************
1024 Keep a linked list of all config files so we know when one has changed
1025 it's date and needs to be reloaded.
1026 ********************************************************************/
1028 static void add_to_file_list(struct loadparm_context *lp_ctx,
1029 const char *fname, const char *subfname)
1031 struct file_lists *f = lp_ctx->file_lists;
1034 if (f->name && !strcmp(f->name, fname))
1040 f = talloc(lp_ctx, struct file_lists);
1043 f->next = lp_ctx->file_lists;
1044 f->name = talloc_strdup(f, fname);
1049 f->subfname = talloc_strdup(f, subfname);
1054 lp_ctx->file_lists = f;
1055 f->modtime = file_modtime(subfname);
1057 time_t t = file_modtime(subfname);
1063 /*******************************************************************
1064 Check if a config file has changed date.
1065 ********************************************************************/
1066 bool lpcfg_file_list_changed(struct loadparm_context *lp_ctx)
1068 struct file_lists *f;
1069 DEBUG(6, ("lpcfg_file_list_changed()\n"));
1071 for (f = lp_ctx->file_lists; f != NULL; f = f->next) {
1075 n2 = standard_sub_basic(lp_ctx, f->name);
1077 DEBUGADD(6, ("file %s -> %s last mod_time: %s\n",
1078 f->name, n2, ctime(&f->modtime)));
1080 mod_time = file_modtime(n2);
1082 if (mod_time && ((f->modtime != mod_time) || (f->subfname == NULL) || (strcmp(n2, f->subfname) != 0))) {
1083 DEBUGADD(6, ("file %s modified: %s\n", n2,
1085 f->modtime = mod_time;
1086 talloc_free(f->subfname);
1087 f->subfname = talloc_strdup(f, n2);
1094 /***************************************************************************
1095 Handle the "realm" parameter
1096 ***************************************************************************/
1098 static bool handle_realm(struct loadparm_context *lp_ctx, int unused,
1099 const char *pszParmValue, char **ptr)
1101 lpcfg_string_set(lp_ctx, ptr, pszParmValue);
1103 talloc_free(lp_ctx->globals->realm);
1104 talloc_free(lp_ctx->globals->dnsdomain);
1106 lp_ctx->globals->realm = strupper_talloc(lp_ctx, pszParmValue);
1107 lp_ctx->globals->dnsdomain = strlower_talloc(lp_ctx, pszParmValue);
1112 /***************************************************************************
1113 Handle the include operation.
1114 ***************************************************************************/
1116 static bool handle_include(struct loadparm_context *lp_ctx, int unused,
1117 const char *pszParmValue, char **ptr)
1119 char *fname = standard_sub_basic(lp_ctx, pszParmValue);
1121 add_to_file_list(lp_ctx, pszParmValue, fname);
1123 lpcfg_string_set(lp_ctx, ptr, fname);
1125 if (file_exist(fname))
1126 return pm_process(fname, do_section, do_parameter, lp_ctx);
1128 DEBUG(2, ("Can't find include file %s\n", fname));
1133 /***************************************************************************
1134 Handle the interpretation of the copy parameter.
1135 ***************************************************************************/
1137 static bool handle_copy(struct loadparm_context *lp_ctx, int unused,
1138 const char *pszParmValue, char **ptr)
1141 struct loadparm_service *serviceTemp;
1143 lpcfg_string_set(lp_ctx, ptr, pszParmValue);
1147 DEBUG(3, ("Copying service from service %s\n", pszParmValue));
1149 if ((serviceTemp = getservicebyname(lp_ctx, pszParmValue)) != NULL) {
1150 if (serviceTemp == lp_ctx->currentService) {
1151 DEBUG(0, ("Can't copy service %s - unable to copy self!\n", pszParmValue));
1153 copy_service(lp_ctx->currentService,
1155 lp_ctx->currentService->copymap);
1159 DEBUG(0, ("Unable to copy service - source not found: %s\n",
1167 static bool handle_debug_list(struct loadparm_context *lp_ctx, int unused,
1168 const char *pszParmValue, char **ptr)
1171 lpcfg_string_set(lp_ctx, ptr, pszParmValue);
1172 if (lp_ctx->global) {
1173 return debug_parse_levels(pszParmValue);
1178 static bool handle_logfile(struct loadparm_context *lp_ctx, int unused,
1179 const char *pszParmValue, char **ptr)
1181 debug_set_logfile(pszParmValue);
1182 if (lp_ctx->global) {
1183 lpcfg_string_set(lp_ctx, ptr, pszParmValue);
1188 /***************************************************************************
1189 Initialise a copymap.
1190 ***************************************************************************/
1192 static void init_copymap(struct loadparm_service *pservice)
1196 TALLOC_FREE(pservice->copymap);
1198 pservice->copymap = bitmap_talloc(NULL, NUMPARAMETERS);
1199 if (!pservice->copymap)
1201 ("Couldn't allocate copymap!! (size %d)\n",
1202 (int)NUMPARAMETERS));
1204 for (i = 0; i < NUMPARAMETERS; i++)
1205 bitmap_set(pservice->copymap, i);
1209 * Process a parametric option
1211 static bool lp_do_parameter_parametric(struct loadparm_context *lp_ctx,
1212 struct loadparm_service *service,
1213 const char *pszParmName,
1214 const char *pszParmValue, int flags)
1216 struct parmlist_entry *paramo, *data;
1218 TALLOC_CTX *mem_ctx;
1220 while (isspace((unsigned char)*pszParmName)) {
1224 name = strlower_talloc(lp_ctx, pszParmName);
1225 if (!name) return false;
1227 if (service == NULL) {
1228 data = lp_ctx->globals->param_opt;
1229 mem_ctx = lp_ctx->globals;
1231 data = service->param_opt;
1235 /* Traverse destination */
1236 for (paramo=data; paramo; paramo=paramo->next) {
1237 /* If we already have the option set, override it unless
1238 it was a command line option and the new one isn't */
1239 if (strcmp(paramo->key, name) == 0) {
1240 if ((paramo->priority & FLAG_CMDLINE) &&
1241 !(flags & FLAG_CMDLINE)) {
1246 talloc_free(paramo->value);
1247 paramo->value = talloc_strdup(paramo, pszParmValue);
1248 paramo->priority = flags;
1254 paramo = talloc_zero(mem_ctx, struct parmlist_entry);
1257 paramo->key = talloc_strdup(paramo, name);
1258 paramo->value = talloc_strdup(paramo, pszParmValue);
1259 paramo->priority = flags;
1260 if (service == NULL) {
1261 DLIST_ADD(lp_ctx->globals->param_opt, paramo);
1263 DLIST_ADD(service->param_opt, paramo);
1271 static bool set_variable(TALLOC_CTX *mem_ctx, int parmnum, void *parm_ptr,
1272 const char *pszParmName, const char *pszParmValue,
1273 struct loadparm_context *lp_ctx, bool on_globals)
1276 /* if it is a special case then go ahead */
1277 if (parm_table[parmnum].special) {
1279 ret = parm_table[parmnum].special(lp_ctx, -1, pszParmValue,
1284 goto mark_non_default;
1287 /* now switch on the type of variable it is */
1288 switch (parm_table[parmnum].type)
1292 if (!set_boolean(pszParmValue, &b)) {
1293 DEBUG(0, ("set_variable(%s): value is not "
1294 "boolean!\n", pszParmValue));
1297 *(bool *)parm_ptr = b;
1303 if (!set_boolean(pszParmValue, &b)) {
1304 DEBUG(0, ("set_variable(%s): value is not "
1305 "boolean!\n", pszParmValue));
1308 *(bool *)parm_ptr = !b;
1313 *(int *)parm_ptr = atoi(pszParmValue);
1317 *(char *)parm_ptr = *pszParmValue;
1321 *(int *)parm_ptr = strtol(pszParmValue, NULL, 8);
1327 if (conv_str_size_error(pszParmValue, &val)) {
1328 if (val <= INT_MAX) {
1329 *(int *)parm_ptr = (int)val;
1334 DEBUG(0, ("set_variable(%s): value is not "
1335 "a valid size specifier!\n", pszParmValue));
1340 *(const char ***)parm_ptr = (const char **)str_list_make(mem_ctx,
1341 pszParmValue, NULL);
1345 char **new_list = str_list_make(mem_ctx,
1346 pszParmValue, NULL);
1347 for (i=0; new_list[i]; i++) {
1348 if (*(const char ***)parm_ptr != NULL &&
1349 new_list[i][0] == '+' &&
1352 if (!str_list_check(*(const char ***)parm_ptr,
1354 *(const char ***)parm_ptr = str_list_add(*(const char ***)parm_ptr,
1357 } else if (*(const char ***)parm_ptr != NULL &&
1358 new_list[i][0] == '-' &&
1361 str_list_remove(*(const char ***)parm_ptr,
1365 DEBUG(0, ("Unsupported list syntax for: %s = %s\n",
1366 pszParmName, pszParmValue));
1369 *(const char ***)parm_ptr = (const char **) new_list;
1376 lpcfg_string_set(mem_ctx, (char **)parm_ptr, pszParmValue);
1380 lpcfg_string_set_upper(mem_ctx, (char **)parm_ptr, pszParmValue);
1384 for (i = 0; parm_table[parmnum].enum_list[i].name; i++) {
1387 parm_table[parmnum].enum_list[i].name)) {
1389 parm_table[parmnum].
1394 if (!parm_table[parmnum].enum_list[i].name) {
1395 DEBUG(0,("Unknown enumerated value '%s' for '%s'\n",
1396 pszParmValue, pszParmName));
1406 if (on_globals && (lp_ctx->flags[parmnum] & FLAG_DEFAULT)) {
1407 lp_ctx->flags[parmnum] &= ~FLAG_DEFAULT;
1408 /* we have to also unset FLAG_DEFAULT on aliases */
1409 for (i=parmnum-1;i>=0 && parm_table[i].offset == parm_table[parmnum].offset;i--) {
1410 lp_ctx->flags[i] &= ~FLAG_DEFAULT;
1412 for (i=parmnum+1;i<NUMPARAMETERS && parm_table[i].offset == parm_table[parmnum].offset;i++) {
1413 lp_ctx->flags[i] &= ~FLAG_DEFAULT;
1420 bool lpcfg_do_global_parameter(struct loadparm_context *lp_ctx,
1421 const char *pszParmName, const char *pszParmValue)
1423 int parmnum = lpcfg_map_parameter(pszParmName);
1427 if (strchr(pszParmName, ':')) {
1428 return lp_do_parameter_parametric(lp_ctx, NULL, pszParmName, pszParmValue, 0);
1430 DEBUG(0, ("Ignoring unknown parameter \"%s\"\n", pszParmName));
1434 /* if the flag has been set on the command line, then don't allow override,
1435 but don't report an error */
1436 if (lp_ctx->flags[parmnum] & FLAG_CMDLINE) {
1440 parm_ptr = lpcfg_parm_ptr(lp_ctx, NULL, &parm_table[parmnum]);
1442 return set_variable(lp_ctx->globals, parmnum, parm_ptr,
1443 pszParmName, pszParmValue, lp_ctx, true);
1446 bool lpcfg_do_service_parameter(struct loadparm_context *lp_ctx,
1447 struct loadparm_service *service,
1448 const char *pszParmName, const char *pszParmValue)
1452 int parmnum = lpcfg_map_parameter(pszParmName);
1455 if (strchr(pszParmName, ':')) {
1456 return lp_do_parameter_parametric(lp_ctx, service, pszParmName, pszParmValue, 0);
1458 DEBUG(0, ("Ignoring unknown parameter \"%s\"\n", pszParmName));
1462 /* if the flag has been set on the command line, then don't allow override,
1463 but don't report an error */
1464 if (lp_ctx->flags[parmnum] & FLAG_CMDLINE) {
1468 if (parm_table[parmnum].p_class == P_GLOBAL) {
1470 ("Global parameter %s found in service section!\n",
1474 parm_ptr = ((char *)service) + parm_table[parmnum].offset;
1476 if (!service->copymap)
1477 init_copymap(service);
1479 /* this handles the aliases - set the copymap for other
1480 * entries with the same data pointer */
1481 for (i = 0; parm_table[i].label; i++)
1482 if (parm_table[i].offset == parm_table[parmnum].offset &&
1483 parm_table[i].p_class == parm_table[parmnum].p_class)
1484 bitmap_clear(service->copymap, i);
1486 return set_variable(service, parmnum, parm_ptr, pszParmName,
1487 pszParmValue, lp_ctx, false);
1491 * Process a parameter.
1494 static bool do_parameter(const char *pszParmName, const char *pszParmValue,
1497 struct loadparm_context *lp_ctx = (struct loadparm_context *)userdata;
1499 if (lp_ctx->bInGlobalSection)
1500 return lpcfg_do_global_parameter(lp_ctx, pszParmName,
1503 return lpcfg_do_service_parameter(lp_ctx, lp_ctx->currentService,
1504 pszParmName, pszParmValue);
1508 variable argument do parameter
1510 bool lpcfg_do_global_parameter_var(struct loadparm_context *lp_ctx, const char *pszParmName, const char *fmt, ...) PRINTF_ATTRIBUTE(3, 4);
1511 bool lpcfg_do_global_parameter_var(struct loadparm_context *lp_ctx,
1512 const char *pszParmName, const char *fmt, ...)
1519 s = talloc_vasprintf(NULL, fmt, ap);
1521 ret = lpcfg_do_global_parameter(lp_ctx, pszParmName, s);
1528 set a parameter from the commandline - this is called from command line parameter
1529 parsing code. It sets the parameter then marks the parameter as unable to be modified
1530 by smb.conf processing
1532 bool lpcfg_set_cmdline(struct loadparm_context *lp_ctx, const char *pszParmName,
1533 const char *pszParmValue)
1538 if (lp_ctx->s3_fns) {
1539 return lp_ctx->s3_fns->set_cmdline(pszParmName, pszParmValue);
1542 parmnum = lpcfg_map_parameter(pszParmName);
1544 while (isspace((unsigned char)*pszParmValue)) pszParmValue++;
1547 if (parmnum < 0 && strchr(pszParmName, ':')) {
1548 /* set a parametric option */
1549 return lp_do_parameter_parametric(lp_ctx, NULL, pszParmName,
1550 pszParmValue, FLAG_CMDLINE);
1554 DEBUG(0,("Unknown option '%s'\n", pszParmName));
1558 /* reset the CMDLINE flag in case this has been called before */
1559 lp_ctx->flags[parmnum] &= ~FLAG_CMDLINE;
1561 if (!lpcfg_do_global_parameter(lp_ctx, pszParmName, pszParmValue)) {
1565 lp_ctx->flags[parmnum] |= FLAG_CMDLINE;
1567 /* we have to also set FLAG_CMDLINE on aliases */
1569 i>=0 && parm_table[i].p_class == parm_table[parmnum].p_class &&
1570 parm_table[i].offset == parm_table[parmnum].offset;
1572 lp_ctx->flags[i] |= FLAG_CMDLINE;
1576 parm_table[i].p_class == parm_table[parmnum].p_class &&
1577 parm_table[i].offset == parm_table[parmnum].offset;
1579 lp_ctx->flags[i] |= FLAG_CMDLINE;
1586 set a option from the commandline in 'a=b' format. Use to support --option
1588 bool lpcfg_set_option(struct loadparm_context *lp_ctx, const char *option)
1593 s = talloc_strdup(NULL, option);
1606 ret = lpcfg_set_cmdline(lp_ctx, s, p+1);
1612 #define BOOLSTR(b) ((b) ? "Yes" : "No")
1615 * Print a parameter of the specified type.
1618 void lpcfg_print_parameter(struct parm_struct *p, void *ptr, FILE * f)
1620 /* For the seperation of lists values that we print below */
1621 const char *list_sep = ", ";
1626 for (i = 0; p->enum_list[i].name; i++) {
1627 if (*(int *)ptr == p->enum_list[i].value) {
1629 p->enum_list[i].name);
1636 fprintf(f, "%s", BOOLSTR(*(bool *)ptr));
1640 fprintf(f, "%s", BOOLSTR(!*(bool *)ptr));
1645 fprintf(f, "%d", *(int *)ptr);
1649 fprintf(f, "%c", *(char *)ptr);
1653 int val = *(int *)ptr;
1657 fprintf(f, "0%03o", val);
1666 if ((char ***)ptr && *(char ***)ptr) {
1667 char **list = *(char ***)ptr;
1668 for (; *list; list++) {
1669 /* surround strings with whitespace in double quotes */
1670 if (*(list+1) == NULL) {
1671 /* last item, no extra separator */
1674 if ( strchr_m( *list, ' ' ) ) {
1675 fprintf(f, "\"%s\"%s", *list, list_sep);
1677 fprintf(f, "%s%s", *list, list_sep);
1685 if (*(char **)ptr) {
1686 fprintf(f, "%s", *(char **)ptr);
1695 * Check if two parameters are equal.
1698 bool lpcfg_equal_parameter(parm_type type, void *ptr1, void *ptr2)
1703 return (*((bool *)ptr1) == *((bool *)ptr2));
1709 return (*((int *)ptr1) == *((int *)ptr2));
1712 return (*((char *)ptr1) == *((char *)ptr2));
1716 return str_list_equal(*(const char ***)ptr1, *(const char ***)ptr2);
1721 char *p1 = *(char **)ptr1, *p2 = *(char **)ptr2;
1726 return (p1 == p2 || strequal(p1, p2));
1735 * Process a new section (service).
1737 * At this stage all sections are services.
1738 * Later we'll have special sections that permit server parameters to be set.
1739 * Returns True on success, False on failure.
1742 static bool do_section(const char *pszSectionName, void *userdata)
1744 struct loadparm_context *lp_ctx = (struct loadparm_context *)userdata;
1746 bool isglobal = ((strwicmp(pszSectionName, GLOBAL_NAME) == 0) ||
1747 (strwicmp(pszSectionName, GLOBAL_NAME2) == 0));
1750 /* if we've just struck a global section, note the fact. */
1751 lp_ctx->bInGlobalSection = isglobal;
1753 /* check for multiple global sections */
1754 if (lp_ctx->bInGlobalSection) {
1755 DEBUG(4, ("Processing section \"[%s]\"\n", pszSectionName));
1759 /* if we have a current service, tidy it up before moving on */
1762 if (lp_ctx->currentService != NULL)
1763 bRetval = lpcfg_service_ok(lp_ctx->currentService);
1765 /* if all is still well, move to the next record in the services array */
1767 /* We put this here to avoid an odd message order if messages are */
1768 /* issued by the post-processing of a previous section. */
1769 DEBUG(4, ("Processing section \"[%s]\"\n", pszSectionName));
1771 if ((lp_ctx->currentService = lpcfg_add_service(lp_ctx, lp_ctx->sDefault,
1774 DEBUG(0, ("Failed to add a new service\n"));
1784 * Determine if a particular base parameter is currently set to the default value.
1787 static bool is_default(struct loadparm_service *sDefault, int i)
1789 void *def_ptr = ((char *)sDefault) + parm_table[i].offset;
1790 switch (parm_table[i].type) {
1793 return str_list_equal((const char **)parm_table[i].def.lvalue,
1794 (const char **)def_ptr);
1797 return strequal(parm_table[i].def.svalue,
1801 return parm_table[i].def.bvalue ==
1808 return parm_table[i].def.ivalue ==
1817 *Display the contents of the global structure.
1820 static void dump_globals(struct loadparm_context *lp_ctx, FILE *f,
1824 struct parmlist_entry *data;
1826 fprintf(f, "# Global parameters\n[global]\n");
1828 for (i = 0; parm_table[i].label; i++)
1829 if (parm_table[i].p_class == P_GLOBAL &&
1830 (i == 0 || (parm_table[i].offset != parm_table[i - 1].offset))) {
1831 if (!show_defaults && (lp_ctx->flags[i] & FLAG_DEFAULT))
1833 fprintf(f, "\t%s = ", parm_table[i].label);
1834 lpcfg_print_parameter(&parm_table[i], lpcfg_parm_ptr(lp_ctx, NULL, &parm_table[i]), f);
1837 if (lp_ctx->globals->param_opt != NULL) {
1838 for (data = lp_ctx->globals->param_opt; data;
1839 data = data->next) {
1840 if (!show_defaults && (data->priority & FLAG_DEFAULT)) {
1843 fprintf(f, "\t%s = %s\n", data->key, data->value);
1850 * Display the contents of a single services record.
1853 static void dump_a_service(struct loadparm_service * pService, struct loadparm_service *sDefault, FILE * f,
1854 unsigned int *flags)
1857 struct parmlist_entry *data;
1859 if (pService != sDefault)
1860 fprintf(f, "\n[%s]\n", pService->szService);
1862 for (i = 0; parm_table[i].label; i++) {
1863 if (parm_table[i].p_class == P_LOCAL &&
1864 (*parm_table[i].label != '-') &&
1865 (i == 0 || (parm_table[i].offset != parm_table[i - 1].offset)))
1867 if (pService == sDefault) {
1868 if (flags && (flags[i] & FLAG_DEFAULT)) {
1871 if (defaults_saved) {
1872 if (is_default(sDefault, i)) {
1877 if (lpcfg_equal_parameter(parm_table[i].type,
1878 ((char *)pService) +
1879 parm_table[i].offset,
1880 ((char *)sDefault) +
1881 parm_table[i].offset))
1885 fprintf(f, "\t%s = ", parm_table[i].label);
1886 lpcfg_print_parameter(&parm_table[i],
1887 ((char *)pService) + parm_table[i].offset, f);
1891 if (pService->param_opt != NULL) {
1892 for (data = pService->param_opt; data; data = data->next) {
1893 fprintf(f, "\t%s = %s\n", data->key, data->value);
1898 bool lpcfg_dump_a_parameter(struct loadparm_context *lp_ctx,
1899 struct loadparm_service *service,
1900 const char *parm_name, FILE * f)
1902 struct parm_struct *parm;
1905 parm = lpcfg_parm_struct(lp_ctx, parm_name);
1910 if (service != NULL && parm->p_class == P_GLOBAL) {
1914 ptr = lpcfg_parm_ptr(lp_ctx, service,parm);
1916 lpcfg_print_parameter(parm, ptr, f);
1922 * Auto-load some home services.
1924 static void lpcfg_add_auto_services(struct loadparm_context *lp_ctx,
1932 * Unload unused services.
1935 void lpcfg_killunused(struct loadparm_context *lp_ctx,
1936 struct smbsrv_connection *smb,
1937 bool (*snumused) (struct smbsrv_connection *, int))
1940 for (i = 0; i < lp_ctx->iNumServices; i++) {
1941 if (lp_ctx->services[i] == NULL)
1944 if (!snumused || !snumused(smb, i)) {
1945 talloc_free(lp_ctx->services[i]);
1946 lp_ctx->services[i] = NULL;
1952 static int lpcfg_destructor(struct loadparm_context *lp_ctx)
1954 struct parmlist_entry *data;
1956 if (lp_ctx->refuse_free) {
1957 /* someone is trying to free the
1958 global_loadparm_context.
1959 We can't allow that. */
1963 if (lp_ctx->globals->param_opt != NULL) {
1964 struct parmlist_entry *next;
1965 for (data = lp_ctx->globals->param_opt; data; data=next) {
1967 if (data->priority & FLAG_CMDLINE) continue;
1968 DLIST_REMOVE(lp_ctx->globals->param_opt, data);
1977 * Initialise the global parameter structure.
1979 * Note that most callers should use loadparm_init_global() instead
1981 struct loadparm_context *loadparm_init(TALLOC_CTX *mem_ctx)
1985 struct loadparm_context *lp_ctx;
1986 struct parmlist_entry *parm;
1989 lp_ctx = talloc_zero(mem_ctx, struct loadparm_context);
1993 talloc_set_destructor(lp_ctx, lpcfg_destructor);
1994 lp_ctx->bInGlobalSection = true;
1995 lp_ctx->globals = talloc_zero(lp_ctx, struct loadparm_global);
1996 lp_ctx->sDefault = talloc_zero(lp_ctx, struct loadparm_service);
1998 lp_ctx->sDefault->iMaxPrintJobs = 1000;
1999 lp_ctx->sDefault->bAvailable = true;
2000 lp_ctx->sDefault->browseable = true;
2001 lp_ctx->sDefault->read_only = true;
2002 lp_ctx->sDefault->map_archive = true;
2003 lp_ctx->sDefault->strict_locking = true;
2004 lp_ctx->sDefault->oplocks = true;
2005 lp_ctx->sDefault->create_mask = 0744;
2006 lp_ctx->sDefault->force_create_mode = 0000;
2007 lp_ctx->sDefault->directory_mask = 0755;
2008 lp_ctx->sDefault->force_directory_mode = 0000;
2010 DEBUG(3, ("Initialising global parameters\n"));
2012 for (i = 0; parm_table[i].label; i++) {
2013 if ((parm_table[i].type == P_STRING ||
2014 parm_table[i].type == P_USTRING) &&
2015 !(lp_ctx->flags[i] & FLAG_CMDLINE)) {
2017 if (parm_table[i].p_class == P_LOCAL) {
2018 r = (char **)(((char *)lp_ctx->sDefault) + parm_table[i].offset);
2020 r = (char **)(((char *)lp_ctx->globals) + parm_table[i].offset);
2022 *r = talloc_strdup(lp_ctx, "");
2026 logfile = talloc_asprintf(lp_ctx, "%s/log.samba", dyn_LOGFILEBASE);
2027 lpcfg_do_global_parameter(lp_ctx, "log file", logfile);
2028 talloc_free(logfile);
2030 lpcfg_do_global_parameter(lp_ctx, "log level", "0");
2032 lpcfg_do_global_parameter(lp_ctx, "syslog", "1");
2033 lpcfg_do_global_parameter(lp_ctx, "syslog only", "No");
2034 lpcfg_do_global_parameter(lp_ctx, "debug timestamp", "Yes");
2035 lpcfg_do_global_parameter(lp_ctx, "debug prefix timestamp", "No");
2036 lpcfg_do_global_parameter(lp_ctx, "debug hires timestamp", "Yes");
2037 lpcfg_do_global_parameter(lp_ctx, "debug pid", "No");
2038 lpcfg_do_global_parameter(lp_ctx, "debug uid", "No");
2039 lpcfg_do_global_parameter(lp_ctx, "debug class", "No");
2041 lpcfg_do_global_parameter(lp_ctx, "share backend", "classic");
2043 lpcfg_do_global_parameter(lp_ctx, "server role", "auto");
2044 lpcfg_do_global_parameter(lp_ctx, "domain logons", "No");
2045 lpcfg_do_global_parameter(lp_ctx, "domain master", "Auto");
2047 /* options that can be set on the command line must be initialised via
2048 the slower lpcfg_do_global_parameter() to ensure that FLAG_CMDLINE is obeyed */
2050 lpcfg_do_global_parameter(lp_ctx, "socket options", "TCP_NODELAY");
2052 lpcfg_do_global_parameter(lp_ctx, "workgroup", DEFAULT_WORKGROUP);
2053 myname = get_myname(lp_ctx);
2054 lpcfg_do_global_parameter(lp_ctx, "netbios name", myname);
2055 talloc_free(myname);
2056 lpcfg_do_global_parameter(lp_ctx, "name resolve order", "lmhosts wins host bcast");
2058 lpcfg_do_global_parameter(lp_ctx, "fstype", "NTFS");
2060 lpcfg_do_global_parameter(lp_ctx, "ntvfs handler", "unixuid default");
2061 lpcfg_do_global_parameter(lp_ctx, "max connections", "0");
2063 lpcfg_do_global_parameter(lp_ctx, "dcerpc endpoint servers", "epmapper wkssvc rpcecho samr netlogon lsarpc spoolss drsuapi dssetup unixinfo browser eventlog6 backupkey dnsserver");
2064 lpcfg_do_global_parameter(lp_ctx, "server services", "s3fs rpc nbt wrepl ldap cldap kdc drepl winbind ntp_signd kcc dnsupdate dns");
2065 lpcfg_do_global_parameter(lp_ctx, "kccsrv:samba_kcc", "true");
2066 /* the winbind method for domain controllers is for both RODC
2067 auth forwarding and for trusted domains */
2068 lpcfg_do_global_parameter(lp_ctx, "private dir", dyn_PRIVATE_DIR);
2069 lpcfg_do_global_parameter(lp_ctx, "registry:HKEY_LOCAL_MACHINE", "hklm.ldb");
2071 /* This hive should be dynamically generated by Samba using
2072 data from the sam, but for the moment leave it in a tdb to
2073 keep regedt32 from popping up an annoying dialog. */
2074 lpcfg_do_global_parameter(lp_ctx, "registry:HKEY_USERS", "hku.ldb");
2076 /* using UTF8 by default allows us to support all chars */
2077 lpcfg_do_global_parameter(lp_ctx, "unix charset", "UTF-8");
2079 /* Use codepage 850 as a default for the dos character set */
2080 lpcfg_do_global_parameter(lp_ctx, "dos charset", "CP850");
2083 * Allow the default PASSWD_CHAT to be overridden in local.h.
2085 lpcfg_do_global_parameter(lp_ctx, "passwd chat", DEFAULT_PASSWD_CHAT);
2087 lpcfg_do_global_parameter(lp_ctx, "pid directory", dyn_PIDDIR);
2088 lpcfg_do_global_parameter(lp_ctx, "lock dir", dyn_LOCKDIR);
2089 lpcfg_do_global_parameter(lp_ctx, "state directory", dyn_STATEDIR);
2090 lpcfg_do_global_parameter(lp_ctx, "cache directory", dyn_CACHEDIR);
2091 lpcfg_do_global_parameter(lp_ctx, "ncalrpc dir", dyn_NCALRPCDIR);
2093 lpcfg_do_global_parameter(lp_ctx, "nbt client socket address", "0.0.0.0");
2094 lpcfg_do_global_parameter_var(lp_ctx, "server string",
2095 "Samba %s", SAMBA_VERSION_STRING);
2097 lpcfg_do_global_parameter(lp_ctx, "password server", "*");
2099 lpcfg_do_global_parameter(lp_ctx, "max mux", "50");
2100 lpcfg_do_global_parameter(lp_ctx, "max xmit", "16644");
2101 lpcfg_do_global_parameter(lp_ctx, "host msdfs", "true");
2103 lpcfg_do_global_parameter(lp_ctx, "LargeReadwrite", "True");
2104 lpcfg_do_global_parameter(lp_ctx, "server min protocol", "LANMAN1");
2105 lpcfg_do_global_parameter(lp_ctx, "server max protocol", "SMB3");
2106 lpcfg_do_global_parameter(lp_ctx, "client min protocol", "CORE");
2107 lpcfg_do_global_parameter(lp_ctx, "client max protocol", "NT1");
2108 lpcfg_do_global_parameter(lp_ctx, "security", "AUTO");
2109 lpcfg_do_global_parameter(lp_ctx, "EncryptPasswords", "True");
2110 lpcfg_do_global_parameter(lp_ctx, "ReadRaw", "True");
2111 lpcfg_do_global_parameter(lp_ctx, "WriteRaw", "True");
2112 lpcfg_do_global_parameter(lp_ctx, "NullPasswords", "False");
2113 lpcfg_do_global_parameter(lp_ctx, "ObeyPamRestrictions", "False");
2115 lpcfg_do_global_parameter(lp_ctx, "TimeServer", "False");
2116 lpcfg_do_global_parameter(lp_ctx, "BindInterfacesOnly", "False");
2117 lpcfg_do_global_parameter(lp_ctx, "Unicode", "True");
2118 lpcfg_do_global_parameter(lp_ctx, "ClientLanManAuth", "False");
2119 lpcfg_do_global_parameter(lp_ctx, "ClientNTLMv2Auth", "True");
2120 lpcfg_do_global_parameter(lp_ctx, "LanmanAuth", "False");
2121 lpcfg_do_global_parameter(lp_ctx, "NTLMAuth", "True");
2122 lpcfg_do_global_parameter(lp_ctx, "client use spnego principal", "False");
2124 lpcfg_do_global_parameter(lp_ctx, "UnixExtensions", "True");
2126 lpcfg_do_global_parameter(lp_ctx, "PreferredMaster", "Auto");
2127 lpcfg_do_global_parameter(lp_ctx, "LocalMaster", "True");
2129 lpcfg_do_global_parameter(lp_ctx, "wins support", "False");
2130 lpcfg_do_global_parameter(lp_ctx, "dns proxy", "True");
2132 lpcfg_do_global_parameter(lp_ctx, "winbind separator", "\\");
2133 lpcfg_do_global_parameter(lp_ctx, "winbind sealed pipes", "True");
2134 lpcfg_do_global_parameter(lp_ctx, "require strong key", "True");
2135 lpcfg_do_global_parameter(lp_ctx, "winbindd socket directory", dyn_WINBINDD_SOCKET_DIR);
2136 lpcfg_do_global_parameter(lp_ctx, "winbindd privileged socket directory", dyn_WINBINDD_PRIVILEGED_SOCKET_DIR);
2137 lpcfg_do_global_parameter(lp_ctx, "ntp signd socket directory", dyn_NTP_SIGND_SOCKET_DIR);
2138 lpcfg_do_global_parameter_var(lp_ctx, "dns update command", "%s/samba_dnsupdate", dyn_SCRIPTSBINDIR);
2139 lpcfg_do_global_parameter_var(lp_ctx, "spn update command", "%s/samba_spnupdate", dyn_SCRIPTSBINDIR);
2140 lpcfg_do_global_parameter_var(lp_ctx, "samba kcc command",
2141 "%s/samba_kcc", dyn_SCRIPTSBINDIR);
2142 lpcfg_do_global_parameter(lp_ctx, "template shell", "/bin/false");
2143 lpcfg_do_global_parameter(lp_ctx, "template homedir", "/home/%WORKGROUP%/%ACCOUNTNAME%");
2145 lpcfg_do_global_parameter(lp_ctx, "client signing", "default");
2146 lpcfg_do_global_parameter(lp_ctx, "server signing", "default");
2148 lpcfg_do_global_parameter(lp_ctx, "use spnego", "True");
2150 lpcfg_do_global_parameter(lp_ctx, "use mmap", "True");
2152 lpcfg_do_global_parameter(lp_ctx, "smb ports", "445 139");
2153 lpcfg_do_global_parameter(lp_ctx, "nbt port", "137");
2154 lpcfg_do_global_parameter(lp_ctx, "dgram port", "138");
2155 lpcfg_do_global_parameter(lp_ctx, "cldap port", "389");
2156 lpcfg_do_global_parameter(lp_ctx, "krb5 port", "88");
2157 lpcfg_do_global_parameter(lp_ctx, "kpasswd port", "464");
2158 lpcfg_do_global_parameter(lp_ctx, "web port", "901");
2160 lpcfg_do_global_parameter(lp_ctx, "nt status support", "True");
2162 lpcfg_do_global_parameter(lp_ctx, "max wins ttl", "518400"); /* 6 days */
2163 lpcfg_do_global_parameter(lp_ctx, "min wins ttl", "21600");
2165 lpcfg_do_global_parameter(lp_ctx, "tls enabled", "True");
2166 lpcfg_do_global_parameter(lp_ctx, "tls keyfile", "tls/key.pem");
2167 lpcfg_do_global_parameter(lp_ctx, "tls certfile", "tls/cert.pem");
2168 lpcfg_do_global_parameter(lp_ctx, "tls cafile", "tls/ca.pem");
2169 lpcfg_do_global_parameter(lp_ctx, "prefork children:smb", "4");
2171 lpcfg_do_global_parameter(lp_ctx, "rndc command", "/usr/sbin/rndc");
2172 lpcfg_do_global_parameter(lp_ctx, "nsupdate command", "/usr/bin/nsupdate -g");
2174 lpcfg_do_global_parameter(lp_ctx, "allow dns updates", "secure only");
2175 lpcfg_do_global_parameter(lp_ctx, "dns forwarder", "");
2177 lpcfg_do_global_parameter(lp_ctx, "algorithmic rid base", "1000");
2179 lpcfg_do_global_parameter(lp_ctx, "enhanced browsing", "True");
2181 lpcfg_do_global_parameter(lp_ctx, "winbind nss info", "template");
2183 lpcfg_do_global_parameter(lp_ctx, "server schannel", "Auto");
2185 lpcfg_do_global_parameter(lp_ctx, "short preserve case", "True");
2187 lpcfg_do_global_parameter(lp_ctx, "max open files", "16384");
2189 lpcfg_do_global_parameter(lp_ctx, "cups connection timeout", "30");
2191 lpcfg_do_global_parameter(lp_ctx, "locking", "True");
2193 lpcfg_do_global_parameter(lp_ctx, "block size", "1024");
2195 lpcfg_do_global_parameter(lp_ctx, "client use spnego", "True");
2197 lpcfg_do_global_parameter(lp_ctx, "change notify", "True");
2199 lpcfg_do_global_parameter(lp_ctx, "name cache timeout", "660");
2201 lpcfg_do_global_parameter(lp_ctx, "defer sharing violations", "True");
2203 lpcfg_do_global_parameter(lp_ctx, "ldap replication sleep", "1000");
2205 lpcfg_do_global_parameter(lp_ctx, "idmap backend", "tdb");
2207 lpcfg_do_global_parameter(lp_ctx, "enable privileges", "True");
2209 lpcfg_do_global_parameter_var(lp_ctx, "smb2 max write", "%u", DEFAULT_SMB2_MAX_WRITE);
2211 lpcfg_do_global_parameter(lp_ctx, "passdb backend", "tdbsam");
2213 lpcfg_do_global_parameter(lp_ctx, "getwd cache", "True");
2215 lpcfg_do_global_parameter(lp_ctx, "winbind nested groups", "True");
2217 lpcfg_do_global_parameter(lp_ctx, "mangled names", "True");
2219 lpcfg_do_global_parameter_var(lp_ctx, "smb2 max credits", "%u", DEFAULT_SMB2_MAX_CREDITS);
2221 lpcfg_do_global_parameter(lp_ctx, "ldap ssl", "start tls");
2223 lpcfg_do_global_parameter(lp_ctx, "ldap deref", "auto");
2225 lpcfg_do_global_parameter(lp_ctx, "lm interval", "60");
2227 lpcfg_do_global_parameter(lp_ctx, "mangling method", "hash2");
2229 lpcfg_do_global_parameter(lp_ctx, "hide dot files", "True");
2231 lpcfg_do_global_parameter(lp_ctx, "browse list", "True");
2233 lpcfg_do_global_parameter(lp_ctx, "passwd chat timeout", "2");
2235 lpcfg_do_global_parameter(lp_ctx, "guest account", GUEST_ACCOUNT);
2237 lpcfg_do_global_parameter(lp_ctx, "client schannel", "auto");
2239 lpcfg_do_global_parameter(lp_ctx, "smb encrypt", "default");
2241 lpcfg_do_global_parameter(lp_ctx, "max log size", "5000");
2243 lpcfg_do_global_parameter(lp_ctx, "idmap negative cache time", "120");
2245 lpcfg_do_global_parameter(lp_ctx, "ldap follow referral", "auto");
2247 lpcfg_do_global_parameter(lp_ctx, "multicast dns register", "yes");
2249 lpcfg_do_global_parameter(lp_ctx, "winbind reconnect delay", "30");
2251 lpcfg_do_global_parameter(lp_ctx, "nt acl support", "yes");
2253 lpcfg_do_global_parameter(lp_ctx, "acl check permissions", "yes");
2255 lpcfg_do_global_parameter(lp_ctx, "keepalive", "300");
2257 lpcfg_do_global_parameter(lp_ctx, "winbind cache time", "300");
2259 lpcfg_do_global_parameter(lp_ctx, "level2 oplocks", "yes");
2261 lpcfg_do_global_parameter(lp_ctx, "show add printer wizard", "yes");
2263 lpcfg_do_global_parameter(lp_ctx, "allocation roundup size", "1048576");
2265 lpcfg_do_global_parameter(lp_ctx, "ldap page size", "1024");
2267 lpcfg_do_global_parameter(lp_ctx, "kernel share modes", "yes");
2269 lpcfg_do_global_parameter(lp_ctx, "strict locking", "Auto");
2271 lpcfg_do_global_parameter(lp_ctx, "map readonly", "yes");
2273 lpcfg_do_global_parameter(lp_ctx, "allow trusted domains", "yes");
2275 lpcfg_do_global_parameter(lp_ctx, "default devmode", "yes");
2277 lpcfg_do_global_parameter(lp_ctx, "os level", "20");
2279 lpcfg_do_global_parameter(lp_ctx, "dos filetimes", "yes");
2281 lpcfg_do_global_parameter(lp_ctx, "mangling char", "~");
2283 lpcfg_do_global_parameter(lp_ctx, "printcap cache time", "750");
2285 lpcfg_do_global_parameter(lp_ctx, "create krb5 conf", "yes");
2287 lpcfg_do_global_parameter(lp_ctx, "winbind max clients", "200");
2289 lpcfg_do_global_parameter(lp_ctx, "acl map full control", "yes");
2291 lpcfg_do_global_parameter(lp_ctx, "nt pipe support", "yes");
2293 lpcfg_do_global_parameter(lp_ctx, "ldap debug threshold", "10");
2295 lpcfg_do_global_parameter(lp_ctx, "follow symlinks", "yes");
2297 lpcfg_do_global_parameter(lp_ctx, "machine password timeout", "604800");
2299 lpcfg_do_global_parameter(lp_ctx, "ldap connection timeout", "2");
2301 lpcfg_do_global_parameter(lp_ctx, "winbind expand groups", "1");
2303 lpcfg_do_global_parameter(lp_ctx, "stat cache", "yes");
2305 lpcfg_do_global_parameter(lp_ctx, "lpq cache time", "30");
2307 lpcfg_do_global_parameter_var(lp_ctx, "smb2 max trans", "%u", DEFAULT_SMB2_MAX_TRANSACT);
2309 lpcfg_do_global_parameter_var(lp_ctx, "smb2 max read", "%u", DEFAULT_SMB2_MAX_READ);
2311 lpcfg_do_global_parameter(lp_ctx, "durable handles", "yes");
2313 lpcfg_do_global_parameter(lp_ctx, "max stat cache size", "256");
2315 lpcfg_do_global_parameter(lp_ctx, "ldap passwd sync", "no");
2317 lpcfg_do_global_parameter(lp_ctx, "kernel change notify", "yes");
2319 lpcfg_do_global_parameter(lp_ctx, "max ttl", "259200");
2321 lpcfg_do_global_parameter(lp_ctx, "blocking locks", "yes");
2323 lpcfg_do_global_parameter(lp_ctx, "oplock contention limit", "2");
2325 lpcfg_do_global_parameter(lp_ctx, "load printers", "yes");
2327 lpcfg_do_global_parameter(lp_ctx, "idmap cache time", "604800");
2329 lpcfg_do_global_parameter(lp_ctx, "preserve case", "yes");
2331 lpcfg_do_global_parameter(lp_ctx, "lm announce", "auto");
2333 lpcfg_do_global_parameter(lp_ctx, "afs token lifetime", "604800");
2335 lpcfg_do_global_parameter(lp_ctx, "enable core files", "yes");
2337 lpcfg_do_global_parameter(lp_ctx, "winbind max domain connections", "1");
2339 lpcfg_do_global_parameter(lp_ctx, "case sensitive", "auto");
2341 lpcfg_do_global_parameter(lp_ctx, "ldap timeout", "15");
2343 lpcfg_do_global_parameter(lp_ctx, "mangle prefix", "1");
2345 lpcfg_do_global_parameter(lp_ctx, "posix locking", "yes");
2347 lpcfg_do_global_parameter(lp_ctx, "lock spin time", "200");
2349 lpcfg_do_global_parameter(lp_ctx, "directory name cache size", "100");
2351 lpcfg_do_global_parameter(lp_ctx, "nmbd bind explicit broadcast", "yes");
2353 lpcfg_do_global_parameter(lp_ctx, "init logon delay", "100");
2355 lpcfg_do_global_parameter(lp_ctx, "usershare owner only", "yes");
2357 lpcfg_do_global_parameter(lp_ctx, "-valid", "yes");
2359 lpcfg_do_global_parameter_var(lp_ctx, "usershare path", "%s/usershares", get_dyn_STATEDIR());
2362 lpcfg_do_global_parameter_var(lp_ctx, "panic action", "/bin/sleep 999999999");
2365 lpcfg_do_global_parameter(lp_ctx, "smb passwd file", get_dyn_SMB_PASSWD_FILE());
2367 lpcfg_do_global_parameter(lp_ctx, "logon home", "\\\\%N\\%U");
2369 lpcfg_do_global_parameter(lp_ctx, "logon path", "\\\\%N\\%U\\profile");
2371 lpcfg_do_global_parameter(lp_ctx, "printjob username", "%U");
2373 for (i = 0; parm_table[i].label; i++) {
2374 if (!(lp_ctx->flags[i] & FLAG_CMDLINE)) {
2375 lp_ctx->flags[i] |= FLAG_DEFAULT;
2379 for (parm=lp_ctx->globals->param_opt; parm; parm=parm->next) {
2380 if (!(parm->priority & FLAG_CMDLINE)) {
2381 parm->priority |= FLAG_DEFAULT;
2389 * Initialise the global parameter structure.
2391 struct loadparm_context *loadparm_init_global(bool load_default)
2393 if (global_loadparm_context == NULL) {
2394 global_loadparm_context = loadparm_init(NULL);
2396 if (global_loadparm_context == NULL) {
2399 global_loadparm_context->global = true;
2400 if (load_default && !global_loadparm_context->loaded) {
2401 lpcfg_load_default(global_loadparm_context);
2403 global_loadparm_context->refuse_free = true;
2404 return global_loadparm_context;
2408 * Initialise the global parameter structure.
2410 struct loadparm_context *loadparm_init_s3(TALLOC_CTX *mem_ctx,
2411 const struct loadparm_s3_helpers *s3_fns)
2413 struct loadparm_context *loadparm_context = talloc_zero(mem_ctx, struct loadparm_context);
2414 if (!loadparm_context) {
2417 loadparm_context->s3_fns = s3_fns;
2418 return loadparm_context;
2421 const char *lpcfg_configfile(struct loadparm_context *lp_ctx)
2423 return lp_ctx->szConfigFile;
2426 const char *lp_default_path(void)
2428 if (getenv("SMB_CONF_PATH"))
2429 return getenv("SMB_CONF_PATH");
2431 return dyn_CONFIGFILE;
2435 * Update the internal state of a loadparm context after settings
2438 static bool lpcfg_update(struct loadparm_context *lp_ctx)
2440 struct debug_settings settings;
2441 lpcfg_add_auto_services(lp_ctx, lpcfg_auto_services(lp_ctx));
2443 if (!lp_ctx->globals->wins_server_list && lp_ctx->globals->we_are_a_wins_server) {
2444 lpcfg_do_global_parameter(lp_ctx, "wins server", "127.0.0.1");
2447 if (!lp_ctx->global) {
2451 panic_action = lp_ctx->globals->panic_action;
2453 reload_charcnv(lp_ctx);
2455 ZERO_STRUCT(settings);
2456 /* Add any more debug-related smb.conf parameters created in
2458 settings.syslog = lp_ctx->globals->syslog;
2459 settings.syslog_only = lp_ctx->globals->syslog_only;
2460 settings.timestamp_logs = lp_ctx->globals->timestamp_logs;
2461 settings.debug_prefix_timestamp = lp_ctx->globals->debug_prefix_timestamp;
2462 settings.debug_hires_timestamp = lp_ctx->globals->debug_hires_timestamp;
2463 settings.debug_pid = lp_ctx->globals->debug_pid;
2464 settings.debug_uid = lp_ctx->globals->debug_uid;
2465 settings.debug_class = lp_ctx->globals->debug_class;
2466 debug_set_settings(&settings);
2468 /* FIXME: This is a bit of a hack, but we can't use a global, since
2469 * not everything that uses lp also uses the socket library */
2470 if (lpcfg_parm_bool(lp_ctx, NULL, "socket", "testnonblock", false)) {
2471 setenv("SOCKET_TESTNONBLOCK", "1", 1);
2473 unsetenv("SOCKET_TESTNONBLOCK");
2479 bool lpcfg_load_default(struct loadparm_context *lp_ctx)
2483 path = lp_default_path();
2485 if (!file_exist(path)) {
2486 /* We allow the default smb.conf file to not exist,
2487 * basically the equivalent of an empty file. */
2488 return lpcfg_update(lp_ctx);
2491 return lpcfg_load(lp_ctx, path);
2495 * Load the services array from the services file.
2497 * Return True on success, False on failure.
2499 bool lpcfg_load(struct loadparm_context *lp_ctx, const char *filename)
2504 filename = talloc_strdup(lp_ctx, filename);
2506 lp_ctx->szConfigFile = filename;
2508 if (lp_ctx->s3_fns) {
2509 return lp_ctx->s3_fns->load(filename);
2512 lp_ctx->bInGlobalSection = true;
2513 n2 = standard_sub_basic(lp_ctx, lp_ctx->szConfigFile);
2514 DEBUG(2, ("lpcfg_load: refreshing parameters from %s\n", n2));
2516 add_to_file_list(lp_ctx, lp_ctx->szConfigFile, n2);
2518 /* We get sections first, so have to start 'behind' to make up */
2519 lp_ctx->currentService = NULL;
2520 bRetval = pm_process(n2, do_section, do_parameter, lp_ctx);
2522 /* finish up the last section */
2523 DEBUG(4, ("pm_process() returned %s\n", BOOLSTR(bRetval)));
2525 if (lp_ctx->currentService != NULL)
2526 bRetval = lpcfg_service_ok(lp_ctx->currentService);
2528 bRetval = bRetval && lpcfg_update(lp_ctx);
2530 /* we do this unconditionally, so that it happens even
2531 for a missing smb.conf */
2532 reload_charcnv(lp_ctx);
2534 if (bRetval == true) {
2535 /* set this up so that any child python tasks will
2536 find the right smb.conf */
2537 setenv("SMB_CONF_PATH", filename, 1);
2539 /* set the context used by the lp_*() function
2541 global_loadparm_context = lp_ctx;
2542 lp_ctx->loaded = true;
2549 * Return the max number of services.
2552 int lpcfg_numservices(struct loadparm_context *lp_ctx)
2554 if (lp_ctx->s3_fns) {
2555 return lp_ctx->s3_fns->get_numservices();
2558 return lp_ctx->iNumServices;
2562 * Display the contents of the services array in human-readable form.
2565 void lpcfg_dump(struct loadparm_context *lp_ctx, FILE *f, bool show_defaults,
2570 if (lp_ctx->s3_fns) {
2571 lp_ctx->s3_fns->dump(f, show_defaults, maxtoprint);
2575 defaults_saved = !show_defaults;
2577 dump_globals(lp_ctx, f, show_defaults);
2579 dump_a_service(lp_ctx->sDefault, lp_ctx->sDefault, f, lp_ctx->flags);
2581 for (iService = 0; iService < maxtoprint; iService++)
2582 lpcfg_dump_one(f, show_defaults, lp_ctx->services[iService], lp_ctx->sDefault);
2586 * Display the contents of one service in human-readable form.
2588 void lpcfg_dump_one(FILE *f, bool show_defaults, struct loadparm_service *service, struct loadparm_service *sDefault)
2590 if (service != NULL) {
2591 if (service->szService[0] == '\0')
2593 dump_a_service(service, sDefault, f, NULL);
2597 struct loadparm_service *lpcfg_servicebynum(struct loadparm_context *lp_ctx,
2600 if (lp_ctx->s3_fns) {
2601 return lp_ctx->s3_fns->get_servicebynum(snum);
2604 return lp_ctx->services[snum];
2607 struct loadparm_service *lpcfg_service(struct loadparm_context *lp_ctx,
2608 const char *service_name)
2613 if (lp_ctx->s3_fns) {
2614 return lp_ctx->s3_fns->get_service(service_name);
2617 for (iService = lp_ctx->iNumServices - 1; iService >= 0; iService--) {
2618 if (lp_ctx->services[iService] &&
2619 lp_ctx->services[iService]->szService) {
2621 * The substitution here is used to support %U is
2624 serviceName = standard_sub_basic(
2625 lp_ctx->services[iService],
2626 lp_ctx->services[iService]->szService);
2627 if (strequal(serviceName, service_name)) {
2628 talloc_free(serviceName);
2629 return lp_ctx->services[iService];
2631 talloc_free(serviceName);
2635 DEBUG(7,("lpcfg_servicenumber: couldn't find %s\n", service_name));
2639 const char *lpcfg_servicename(const struct loadparm_service *service)
2641 return lp_string((const char *)service->szService);
2645 * A useful volume label function.
2647 const char *lpcfg_volume_label(struct loadparm_service *service, struct loadparm_service *sDefault)
2650 ret = lp_string((const char *)((service != NULL && service->volume != NULL) ?
2651 service->volume : sDefault->volume));
2653 return lpcfg_servicename(service);
2658 * Return the correct printer name.
2660 const char *lpcfg_printername(struct loadparm_service *service, struct loadparm_service *sDefault)
2663 ret = lp_string((const char *)((service != NULL && service->_printername != NULL) ?
2664 service->_printername : sDefault->_printername));
2665 if (ret == NULL || (ret != NULL && *ret == '\0'))
2666 ret = lpcfg_servicename(service);
2673 * Return the max print jobs per queue.
2675 int lpcfg_maxprintjobs(struct loadparm_service *service, struct loadparm_service *sDefault)
2677 int maxjobs = (service != NULL) ? service->iMaxPrintJobs : sDefault->iMaxPrintJobs;
2678 if (maxjobs <= 0 || maxjobs >= PRINT_MAX_JOBID)
2679 maxjobs = PRINT_MAX_JOBID - 1;
2684 struct smb_iconv_handle *lpcfg_iconv_handle(struct loadparm_context *lp_ctx)
2686 if (lp_ctx == NULL) {
2687 return get_iconv_handle();
2689 return lp_ctx->iconv_handle;
2692 _PUBLIC_ void reload_charcnv(struct loadparm_context *lp_ctx)
2694 struct smb_iconv_handle *old_ic = lp_ctx->iconv_handle;
2695 if (!lp_ctx->global) {
2699 if (old_ic == NULL) {
2700 old_ic = global_iconv_handle;
2702 lp_ctx->iconv_handle = smb_iconv_handle_reinit_lp(lp_ctx, lp_ctx, old_ic);
2703 global_iconv_handle = lp_ctx->iconv_handle;
2706 _PUBLIC_ char *lpcfg_tls_keyfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
2708 return lpcfg_private_path(mem_ctx, lp_ctx, lpcfg__tls_keyfile(lp_ctx));
2711 _PUBLIC_ char *lpcfg_tls_certfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
2713 return lpcfg_private_path(mem_ctx, lp_ctx, lpcfg__tls_certfile(lp_ctx));
2716 _PUBLIC_ char *lpcfg_tls_cafile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
2718 return lpcfg_private_path(mem_ctx, lp_ctx, lpcfg__tls_cafile(lp_ctx));
2721 _PUBLIC_ char *lpcfg_tls_crlfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
2723 return lpcfg_private_path(mem_ctx, lp_ctx, lpcfg__tls_crlfile(lp_ctx));
2726 _PUBLIC_ char *lpcfg_tls_dhpfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
2728 return lpcfg_private_path(mem_ctx, lp_ctx, lpcfg__tls_dhpfile(lp_ctx));
2731 struct gensec_settings *lpcfg_gensec_settings(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
2733 struct gensec_settings *settings = talloc_zero(mem_ctx, struct gensec_settings);
2734 if (settings == NULL)
2736 SMB_ASSERT(lp_ctx != NULL);
2737 settings->lp_ctx = talloc_reference(settings, lp_ctx);
2738 settings->target_hostname = lpcfg_parm_string(lp_ctx, NULL, "gensec", "target_hostname");
2742 int lpcfg_server_role(struct loadparm_context *lp_ctx)
2744 int domain_master = lpcfg__domain_master(lp_ctx);
2746 return lp_find_server_role(lpcfg__server_role(lp_ctx),
2747 lpcfg__security(lp_ctx),
2748 lpcfg__domain_logons(lp_ctx),
2749 (domain_master == true) ||
2750 (domain_master == Auto));
2753 int lpcfg_security(struct loadparm_context *lp_ctx)
2755 return lp_find_security(lpcfg__server_role(lp_ctx),
2756 lpcfg__security(lp_ctx));
2759 bool lpcfg_server_signing_allowed(struct loadparm_context *lp_ctx, bool *mandatory)
2761 bool allowed = true;
2762 enum smb_signing_setting signing_setting = lpcfg_server_signing(lp_ctx);
2766 if (signing_setting == SMB_SIGNING_DEFAULT) {
2768 * If we are a domain controller, SMB signing is
2769 * really important, as it can prevent a number of
2770 * attacks on communications between us and the
2773 * However, it really sucks (no sendfile, CPU
2774 * overhead) performance-wise when used on a
2775 * file server, so disable it by default
2779 if (lpcfg_server_role(lp_ctx) >= ROLE_ACTIVE_DIRECTORY_DC) {
2780 signing_setting = SMB_SIGNING_REQUIRED;
2782 signing_setting = SMB_SIGNING_OFF;
2786 switch (signing_setting) {
2787 case SMB_SIGNING_REQUIRED:
2790 case SMB_SIGNING_IF_REQUIRED:
2792 case SMB_SIGNING_DEFAULT:
2793 case SMB_SIGNING_OFF: