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"
71 #define standard_sub_basic talloc_strdup
73 static bool do_parameter(const char *, const char *, void *);
74 static bool defaults_saved = false;
76 #include "lib/param/param_global.h"
78 #define NUMPARAMETERS (sizeof(parm_table) / sizeof(struct parm_struct))
80 /* these are parameter handlers which are not needed in the
83 #define handle_netbios_aliases NULL
84 #define handle_printing NULL
85 #define handle_ldap_debug_level NULL
86 #define handle_idmap_backend NULL
87 #define handle_idmap_uid NULL
88 #define handle_idmap_gid NULL
94 #include "lib/param/param_table.c"
96 struct loadparm_service *lpcfg_default_service(struct loadparm_context *lp_ctx)
99 return lp_ctx->s3_fns->get_default_loadparm_service();
101 return lp_ctx->sDefault;
105 * Convenience routine to grab string parameters into temporary memory
106 * and run standard_sub_basic on them.
108 * The buffers can be written to by
109 * callers without affecting the source string.
112 static const char *lpcfg_string(const char *s)
114 #if 0 /* until REWRITE done to make thread-safe */
115 size_t len = s ? strlen(s) : 0;
119 /* The follow debug is useful for tracking down memory problems
120 especially if you have an inner loop that is calling a lp_*()
121 function that returns a string. Perhaps this debug should be
122 present all the time? */
125 DEBUG(10, ("lpcfg_string(%s)\n", s));
128 #if 0 /* until REWRITE done to make thread-safe */
130 lp_talloc = talloc_init("lp_talloc");
132 ret = talloc_array(lp_talloc, char, len + 100); /* leave room for substitution */
140 strlcpy(ret, s, len);
142 if (trim_string(ret, "\"", "\"")) {
143 if (strchr(ret,'"') != NULL)
144 strlcpy(ret, s, len);
147 standard_sub_basic(ret,len+100);
154 In this section all the functions that are used to access the
155 parameters from the rest of the program are defined
159 * the creation of separate lpcfg_*() and lp_*() functions is to allow
160 * for code compatibility between existing Samba4 and Samba3 code.
163 /* this global context supports the lp_*() function varients */
164 static struct loadparm_context *global_loadparm_context;
166 #define lpcfg_default_service global_loadparm_context->sDefault
167 #define lpcfg_global_service(i) global_loadparm_context->services[i]
169 #define FN_GLOBAL_STRING(fn_name,var_name) \
170 _PUBLIC_ char *lpcfg_ ## fn_name(struct loadparm_context *lp_ctx, TALLOC_CTX *ctx) {\
171 if (lp_ctx == NULL) return NULL; \
172 if (lp_ctx->s3_fns) { \
173 return lp_ctx->globals->var_name ? lp_ctx->s3_fns->lp_string(ctx, lp_ctx->globals->var_name) : talloc_strdup(ctx, ""); \
175 return lp_ctx->globals->var_name ? talloc_strdup(ctx, lpcfg_string(lp_ctx->globals->var_name)) : talloc_strdup(ctx, ""); \
178 #define FN_GLOBAL_CONST_STRING(fn_name,var_name) \
179 _PUBLIC_ const char *lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) { \
180 if (lp_ctx == NULL) return NULL; \
181 return lp_ctx->globals->var_name ? lpcfg_string(lp_ctx->globals->var_name) : ""; \
184 #define FN_GLOBAL_LIST(fn_name,var_name) \
185 _PUBLIC_ const char **lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) { \
186 if (lp_ctx == NULL) return NULL; \
187 return lp_ctx->globals->var_name; \
190 #define FN_GLOBAL_BOOL(fn_name,var_name) \
191 _PUBLIC_ bool lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) {\
192 if (lp_ctx == NULL) return false; \
193 return lp_ctx->globals->var_name; \
196 #define FN_GLOBAL_INTEGER(fn_name,var_name) \
197 _PUBLIC_ int lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) { \
198 return lp_ctx->globals->var_name; \
201 /* Local parameters don't need the ->s3_fns because the struct
202 * loadparm_service is shared and lpcfg_service() checks the ->s3_fns
204 #define FN_LOCAL_STRING(fn_name,val) \
205 _PUBLIC_ char *lpcfg_ ## fn_name(struct loadparm_service *service, \
206 struct loadparm_service *sDefault, TALLOC_CTX *ctx) { \
207 return(talloc_strdup(ctx, lpcfg_string((const char *)((service != NULL && service->val != NULL) ? service->val : sDefault->val)))); \
210 #define FN_LOCAL_CONST_STRING(fn_name,val) \
211 _PUBLIC_ const char *lpcfg_ ## fn_name(struct loadparm_service *service, \
212 struct loadparm_service *sDefault) { \
213 return((const char *)((service != NULL && service->val != NULL) ? service->val : sDefault->val)); \
216 #define FN_LOCAL_LIST(fn_name,val) \
217 _PUBLIC_ const char **lpcfg_ ## fn_name(struct loadparm_service *service, \
218 struct loadparm_service *sDefault) {\
219 return(const char **)(service != NULL && service->val != NULL? service->val : sDefault->val); \
222 #define FN_LOCAL_PARM_BOOL(fn_name, val) FN_LOCAL_BOOL(fn_name, val)
224 #define FN_LOCAL_BOOL(fn_name,val) \
225 _PUBLIC_ bool lpcfg_ ## fn_name(struct loadparm_service *service, \
226 struct loadparm_service *sDefault) { \
227 return((service != NULL)? service->val : sDefault->val); \
230 #define FN_LOCAL_INTEGER(fn_name,val) \
231 _PUBLIC_ int lpcfg_ ## fn_name(struct loadparm_service *service, \
232 struct loadparm_service *sDefault) { \
233 return((service != NULL)? service->val : sDefault->val); \
236 #define FN_LOCAL_PARM_INTEGER(fn_name, val) FN_LOCAL_INTEGER(fn_name, val)
238 #define FN_LOCAL_PARM_CHAR(fn_name,val) \
239 _PUBLIC_ char lpcfg_ ## fn_name(struct loadparm_service *service, \
240 struct loadparm_service *sDefault) { \
241 return((service != NULL)? service->val : sDefault->val); \
244 #include "lib/param/param_functions.c"
246 /* These functions cannot be auto-generated */
247 FN_LOCAL_BOOL(autoloaded, autoloaded)
248 FN_GLOBAL_CONST_STRING(dnsdomain, dnsdomain)
250 /* local prototypes */
251 static struct loadparm_service *lpcfg_getservicebyname(struct loadparm_context *lp_ctx,
252 const char *pszServiceName);
253 static bool lpcfg_service_ok(struct loadparm_service *service);
254 static bool do_section(const char *pszSectionName, void *);
256 /* This is a helper function for parametrical options support. */
257 /* It returns a pointer to parametrical option value if it exists or NULL otherwise */
258 /* Actual parametrical functions are quite simple */
259 const char *lpcfg_get_parametric(struct loadparm_context *lp_ctx,
260 struct loadparm_service *service,
261 const char *type, const char *option)
263 char *vfskey_tmp = NULL;
265 struct parmlist_entry *data;
270 if (lp_ctx->s3_fns) {
271 return lp_ctx->s3_fns->get_parametric(service, type, option, NULL);
274 data = (service == NULL ? lp_ctx->globals->param_opt : service->param_opt);
276 vfskey_tmp = talloc_asprintf(NULL, "%s:%s", type, option);
277 if (vfskey_tmp == NULL) return NULL;
278 vfskey = strlower_talloc(NULL, vfskey_tmp);
279 talloc_free(vfskey_tmp);
282 if (strcmp(data->key, vfskey) == 0) {
289 if (service != NULL) {
290 /* Try to fetch the same option but from globals */
291 /* but only if we are not already working with globals */
292 for (data = lp_ctx->globals->param_opt; data;
294 if (strcmp(data->key, vfskey) == 0) {
308 * convenience routine to return int parameters.
310 int lp_int(const char *s)
314 DEBUG(0,("lp_int(%s): is called with NULL!\n",s));
318 return strtol(s, NULL, 0);
322 * convenience routine to return unsigned long parameters.
324 unsigned long lp_ulong(const char *s)
328 DEBUG(0,("lp_ulong(%s): is called with NULL!\n",s));
332 return strtoul(s, NULL, 0);
336 * convenience routine to return unsigned long parameters.
338 static long lp_long(const char *s)
342 DEBUG(0,("lp_long(%s): is called with NULL!\n",s));
346 return strtol(s, NULL, 0);
350 * convenience routine to return unsigned long parameters.
352 static double lp_double(const char *s)
356 DEBUG(0,("lp_double(%s): is called with NULL!\n",s));
360 return strtod(s, NULL);
364 * convenience routine to return boolean parameters.
366 bool lp_bool(const char *s)
371 DEBUG(0,("lp_bool(%s): is called with NULL!\n",s));
375 if (!set_boolean(s, &ret)) {
376 DEBUG(0,("lp_bool(%s): value is not boolean!\n",s));
384 * Return parametric option from a given service. Type is a part of option before ':'
385 * Parametric option has following syntax: 'Type: option = value'
386 * Returned value is allocated in 'lp_talloc' context
389 const char *lpcfg_parm_string(struct loadparm_context *lp_ctx,
390 struct loadparm_service *service, const char *type,
393 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
396 return lpcfg_string(value);
402 * Return parametric option from a given service. Type is a part of option before ':'
403 * Parametric option has following syntax: 'Type: option = value'
404 * Returned value is allocated in 'lp_talloc' context
407 const char **lpcfg_parm_string_list(TALLOC_CTX *mem_ctx,
408 struct loadparm_context *lp_ctx,
409 struct loadparm_service *service,
411 const char *option, const char *separator)
413 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
416 return (const char **)str_list_make(mem_ctx, value, separator);
422 * Return parametric option from a given service. Type is a part of option before ':'
423 * Parametric option has following syntax: 'Type: option = value'
426 int lpcfg_parm_int(struct loadparm_context *lp_ctx,
427 struct loadparm_service *service, const char *type,
428 const char *option, int default_v)
430 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
433 return lp_int(value);
439 * Return parametric option from a given service. Type is a part of
441 * Parametric option has following syntax: 'Type: option = value'.
444 int lpcfg_parm_bytes(struct loadparm_context *lp_ctx,
445 struct loadparm_service *service, const char *type,
446 const char *option, int default_v)
450 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
452 if (value && conv_str_size_error(value, &bval)) {
453 if (bval <= INT_MAX) {
462 * Return parametric option from a given service.
463 * Type is a part of option before ':'
464 * Parametric option has following syntax: 'Type: option = value'
466 unsigned long lpcfg_parm_ulong(struct loadparm_context *lp_ctx,
467 struct loadparm_service *service, const char *type,
468 const char *option, unsigned long default_v)
470 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
473 return lp_ulong(value);
478 long lpcfg_parm_long(struct loadparm_context *lp_ctx,
479 struct loadparm_service *service, const char *type,
480 const char *option, long default_v)
482 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
485 return lp_long(value);
490 double lpcfg_parm_double(struct loadparm_context *lp_ctx,
491 struct loadparm_service *service, const char *type,
492 const char *option, double default_v)
494 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
497 return lp_double(value);
503 * Return parametric option from a given service. Type is a part of option before ':'
504 * Parametric option has following syntax: 'Type: option = value'
507 bool lpcfg_parm_bool(struct loadparm_context *lp_ctx,
508 struct loadparm_service *service, const char *type,
509 const char *option, bool default_v)
511 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
514 return lp_bool(value);
521 * Set a string value, deallocating any existing space, and allocing the space
524 bool lpcfg_string_set(TALLOC_CTX *mem_ctx, char **dest, const char *src)
531 *dest = talloc_strdup(mem_ctx, src);
532 if ((*dest) == NULL) {
533 DEBUG(0,("Out of memory in string_set\n"));
541 * Set a string value, deallocating any existing space, and allocing the space
544 static bool lpcfg_string_set_upper(TALLOC_CTX *mem_ctx, char **dest, const char *src)
551 *dest = strupper_talloc(mem_ctx, src);
552 if ((*dest) == NULL) {
553 DEBUG(0,("Out of memory in string_set_upper\n"));
563 * Add a new service to the services array initialising it with the given
567 struct loadparm_service *lpcfg_add_service(struct loadparm_context *lp_ctx,
568 const struct loadparm_service *pservice,
572 int num_to_alloc = lp_ctx->iNumServices + 1;
573 struct parmlist_entry *data, *pdata;
575 if (pservice == NULL) {
576 pservice = lp_ctx->sDefault;
579 /* it might already exist */
581 struct loadparm_service *service = lpcfg_getservicebyname(lp_ctx,
583 if (service != NULL) {
584 /* Clean all parametric options for service */
585 /* They will be added during parsing again */
586 data = service->param_opt;
592 service->param_opt = NULL;
597 /* find an invalid one */
598 for (i = 0; i < lp_ctx->iNumServices; i++)
599 if (lp_ctx->services[i] == NULL)
602 /* if not, then create one */
603 if (i == lp_ctx->iNumServices) {
604 struct loadparm_service **tsp;
606 tsp = talloc_realloc(lp_ctx, lp_ctx->services, struct loadparm_service *, num_to_alloc);
609 DEBUG(0,("lpcfg_add_service: failed to enlarge services!\n"));
612 lp_ctx->services = tsp;
613 lp_ctx->services[lp_ctx->iNumServices] = NULL;
616 lp_ctx->iNumServices++;
619 lp_ctx->services[i] = talloc_zero(lp_ctx->services, struct loadparm_service);
620 if (lp_ctx->services[i] == NULL) {
621 DEBUG(0,("lpcfg_add_service: out of memory!\n"));
624 copy_service(lp_ctx->services[i], pservice, NULL);
626 lpcfg_string_set(lp_ctx->services[i], &lp_ctx->services[i]->szService, name);
627 return lp_ctx->services[i];
631 * Add a new home service, with the specified home directory, defaults coming
632 * from service ifrom.
635 bool lpcfg_add_home(struct loadparm_context *lp_ctx,
636 const char *pszHomename,
637 struct loadparm_service *default_service,
638 const char *user, const char *pszHomedir)
640 struct loadparm_service *service;
642 service = lpcfg_add_service(lp_ctx, default_service, pszHomename);
647 if (!(*(default_service->path))
648 || strequal(default_service->path, lp_ctx->sDefault->path)) {
649 service->path = talloc_strdup(service, pszHomedir);
651 service->path = string_sub_talloc(service, lpcfg_path(default_service, lp_ctx->sDefault, service), "%H", pszHomedir);
654 if (!(*(service->comment))) {
655 service->comment = talloc_asprintf(service, "Home directory of %s", user);
657 service->bAvailable = default_service->bAvailable;
658 service->browseable = default_service->browseable;
660 DEBUG(3, ("adding home's share [%s] for user '%s' at '%s'\n",
661 pszHomename, user, service->path));
667 * Add a new printer service, with defaults coming from service iFrom.
670 bool lpcfg_add_printer(struct loadparm_context *lp_ctx,
671 const char *pszPrintername,
672 struct loadparm_service *default_service)
674 const char *comment = "From Printcap";
675 struct loadparm_service *service;
676 service = lpcfg_add_service(lp_ctx, default_service, pszPrintername);
681 /* note that we do NOT default the availability flag to True - */
682 /* we take it from the default service passed. This allows all */
683 /* dynamic printers to be disabled by disabling the [printers] */
684 /* entry (if/when the 'available' keyword is implemented!). */
686 /* the printer name is set to the service name. */
687 lpcfg_string_set(service, &service->_printername, pszPrintername);
688 lpcfg_string_set(service, &service->comment, comment);
689 service->browseable = default_service->browseable;
690 /* Printers cannot be read_only. */
691 service->read_only = false;
692 /* Printer services must be printable. */
693 service->printable = true;
695 DEBUG(3, ("adding printer service %s\n", pszPrintername));
701 * Map a parameter's string representation to something we can use.
702 * Returns False if the parameter string is not recognised, else TRUE.
705 int lpcfg_map_parameter(const char *pszParmName)
709 for (iIndex = 0; parm_table[iIndex].label; iIndex++)
710 if (strwicmp(parm_table[iIndex].label, pszParmName) == 0)
713 /* Warn only if it isn't parametric option */
714 if (strchr(pszParmName, ':') == NULL)
715 DEBUG(0, ("Unknown parameter encountered: \"%s\"\n", pszParmName));
716 /* We do return 'fail' for parametric options as well because they are
717 stored in different storage
724 return the parameter structure for a parameter
726 struct parm_struct *lpcfg_parm_struct(struct loadparm_context *lp_ctx, const char *name)
730 if (lp_ctx->s3_fns) {
731 return lp_ctx->s3_fns->get_parm_struct(name);
734 parmnum = lpcfg_map_parameter(name);
735 if (parmnum == -1) return NULL;
736 return &parm_table[parmnum];
740 return the parameter pointer for a parameter
742 void *lpcfg_parm_ptr(struct loadparm_context *lp_ctx,
743 struct loadparm_service *service, struct parm_struct *parm)
745 if (lp_ctx->s3_fns) {
746 return lp_ctx->s3_fns->get_parm_ptr(service, parm);
749 if (service == NULL) {
750 if (parm->p_class == P_LOCAL)
751 return ((char *)lp_ctx->sDefault)+parm->offset;
752 else if (parm->p_class == P_GLOBAL)
753 return ((char *)lp_ctx->globals)+parm->offset;
756 return ((char *)service) + parm->offset;
761 return the parameter pointer for a parameter
763 bool lpcfg_parm_is_cmdline(struct loadparm_context *lp_ctx, const char *name)
767 if (lp_ctx->s3_fns) {
768 struct parm_struct *parm = lp_ctx->s3_fns->get_parm_struct(name);
770 return parm->flags & FLAG_CMDLINE;
775 parmnum = lpcfg_map_parameter(name);
776 if (parmnum == -1) return false;
778 return lp_ctx->flags[parmnum] & FLAG_CMDLINE;
782 * Find a service by name. Otherwise works like get_service.
785 static struct loadparm_service *lpcfg_getservicebyname(struct loadparm_context *lp_ctx,
786 const char *pszServiceName)
790 if (lp_ctx->s3_fns) {
791 return lp_ctx->s3_fns->get_service(pszServiceName);
794 for (iService = lp_ctx->iNumServices - 1; iService >= 0; iService--)
795 if (lp_ctx->services[iService] != NULL &&
796 strwicmp(lp_ctx->services[iService]->szService, pszServiceName) == 0) {
797 return lp_ctx->services[iService];
804 * Add a parametric option to a parmlist_entry,
805 * replacing old value, if already present.
807 void set_param_opt(TALLOC_CTX *mem_ctx,
808 struct parmlist_entry **opt_list,
809 const char *opt_name,
810 const char *opt_value,
813 struct parmlist_entry *new_opt, *opt;
819 /* Traverse destination */
821 /* If we already have same option, override it */
822 if (strwicmp(opt->key, opt_name) == 0) {
823 if ((opt->priority & FLAG_CMDLINE) &&
824 !(priority & FLAG_CMDLINE)) {
825 /* it's been marked as not to be
829 TALLOC_FREE(opt->value);
830 TALLOC_FREE(opt->list);
831 opt->value = talloc_strdup(opt, opt_value);
832 opt->priority = priority;
839 new_opt = talloc(mem_ctx, struct parmlist_entry);
840 if (new_opt == NULL) {
844 new_opt->key = talloc_strdup(new_opt, opt_name);
845 if (new_opt->key == NULL) {
846 smb_panic("talloc_strdup failed");
849 new_opt->value = talloc_strdup(new_opt, opt_value);
850 if (new_opt->value == NULL) {
851 smb_panic("talloc_strdup failed");
854 new_opt->list = NULL;
855 new_opt->priority = priority;
856 DLIST_ADD(*opt_list, new_opt);
861 * Copy a service structure to another.
862 * If pcopymapDest is NULL then copy all fields
865 void copy_service(struct loadparm_service *pserviceDest,
866 const struct loadparm_service *pserviceSource,
867 struct bitmap *pcopymapDest)
870 bool bcopyall = (pcopymapDest == NULL);
871 struct parmlist_entry *data;
873 for (i = 0; parm_table[i].label; i++)
874 if (parm_table[i].p_class == P_LOCAL &&
875 (bcopyall || bitmap_query(pcopymapDest, i))) {
876 const void *src_ptr =
877 ((const char *)pserviceSource) + parm_table[i].offset;
879 ((char *)pserviceDest) + parm_table[i].offset;
881 switch (parm_table[i].type) {
884 *(bool *)dest_ptr = *(const bool *)src_ptr;
891 *(int *)dest_ptr = *(const int *)src_ptr;
895 *(char *)dest_ptr = *(const char *)src_ptr;
899 lpcfg_string_set(pserviceDest,
901 *(const char * const *)src_ptr);
905 lpcfg_string_set_upper(pserviceDest,
907 *(const char * const *)src_ptr);
910 TALLOC_FREE(*((char ***)dest_ptr));
911 *(const char * const **)dest_ptr = (const char * const *)str_list_copy(pserviceDest,
912 *(const char * * const *)src_ptr);
920 init_copymap(pserviceDest);
921 if (pserviceSource->copymap)
922 bitmap_copy(pserviceDest->copymap,
923 pserviceSource->copymap);
926 for (data = pserviceSource->param_opt; data != NULL; data = data->next) {
927 set_param_opt(pserviceDest, &pserviceDest->param_opt,
928 data->key, data->value, data->priority);
933 * Check a service for consistency. Return False if the service is in any way
934 * incomplete or faulty, else True.
936 static bool lpcfg_service_ok(struct loadparm_service *service)
941 if (service->szService[0] == '\0') {
942 DEBUG(0, ("The following message indicates an internal error:\n"));
943 DEBUG(0, ("No service name in service entry.\n"));
947 /* The [printers] entry MUST be printable. I'm all for flexibility, but */
948 /* I can't see why you'd want a non-printable printer service... */
949 if (strwicmp(service->szService, PRINTERS_NAME) == 0) {
950 if (!service->printable) {
951 DEBUG(0, ("WARNING: [%s] service MUST be printable!\n",
952 service->szService));
953 service->printable = true;
955 /* [printers] service must also be non-browsable. */
956 if (service->browseable)
957 service->browseable = false;
960 /* If a service is flagged unavailable, log the fact at level 0. */
961 if (!service->bAvailable)
962 DEBUG(1, ("NOTE: Service %s is flagged unavailable.\n",
963 service->szService));
969 /*******************************************************************
970 Keep a linked list of all config files so we know when one has changed
971 it's date and needs to be reloaded.
972 ********************************************************************/
974 void add_to_file_list(TALLOC_CTX *mem_ctx, struct file_lists **list,
975 const char *fname, const char *subfname)
977 struct file_lists *f = *list;
980 if (f->name && !strcmp(f->name, fname))
986 f = talloc(mem_ctx, struct file_lists);
990 f->name = talloc_strdup(f, fname);
995 f->subfname = talloc_strdup(f, subfname);
1001 f->modtime = file_modtime(subfname);
1003 time_t t = file_modtime(subfname);
1010 DEBUG(0, ("Unable to add file to file list: %s\n", fname));
1014 /*******************************************************************
1015 Check if a config file has changed date.
1016 ********************************************************************/
1017 bool lpcfg_file_list_changed(struct loadparm_context *lp_ctx)
1019 struct file_lists *f;
1020 DEBUG(6, ("lpcfg_file_list_changed()\n"));
1022 for (f = lp_ctx->file_lists; f != NULL; f = f->next) {
1026 n2 = standard_sub_basic(lp_ctx, f->name);
1028 DEBUGADD(6, ("file %s -> %s last mod_time: %s\n",
1029 f->name, n2, ctime(&f->modtime)));
1031 mod_time = file_modtime(n2);
1033 if (mod_time && ((f->modtime != mod_time) || (f->subfname == NULL) || (strcmp(n2, f->subfname) != 0))) {
1034 DEBUGADD(6, ("file %s modified: %s\n", n2,
1036 f->modtime = mod_time;
1037 talloc_free(f->subfname);
1038 f->subfname = talloc_strdup(f, n2);
1046 * set the value for a P_ENUM
1048 bool lp_set_enum_parm( struct parm_struct *parm, const char *pszParmValue,
1053 for (i = 0; parm->enum_list[i].name; i++) {
1054 if ( strequal(pszParmValue, parm->enum_list[i].name)) {
1055 *ptr = parm->enum_list[i].value;
1059 DEBUG(0, ("WARNING: Ignoring invalid value '%s' for parameter '%s'\n",
1060 pszParmValue, parm->label));
1065 /***************************************************************************
1066 Handle the "realm" parameter
1067 ***************************************************************************/
1069 bool handle_realm(struct loadparm_context *lp_ctx, int unused,
1070 const char *pszParmValue, char **ptr)
1075 upper = strupper_talloc(lp_ctx, pszParmValue);
1076 if (upper == NULL) {
1080 lower = strlower_talloc(lp_ctx, pszParmValue);
1081 if (lower == NULL) {
1086 if (lp_ctx->s3_fns != NULL) {
1087 lp_ctx->s3_fns->lp_string_set(ptr, pszParmValue);
1088 lp_ctx->s3_fns->lp_string_set(&lp_ctx->globals->realm, upper);
1089 lp_ctx->s3_fns->lp_string_set(&lp_ctx->globals->dnsdomain, lower);
1091 lpcfg_string_set(lp_ctx, ptr, pszParmValue);
1092 lpcfg_string_set(lp_ctx, &lp_ctx->globals->realm, upper);
1093 lpcfg_string_set(lp_ctx, &lp_ctx->globals->dnsdomain, lower);
1099 /***************************************************************************
1100 Handle the include operation.
1101 ***************************************************************************/
1103 bool handle_include(struct loadparm_context *lp_ctx, int unused,
1104 const char *pszParmValue, char **ptr)
1108 if (lp_ctx->s3_fns) {
1109 return lp_ctx->s3_fns->lp_include(lp_ctx, unused, pszParmValue, ptr);
1112 fname = standard_sub_basic(lp_ctx, pszParmValue);
1114 add_to_file_list(lp_ctx, &lp_ctx->file_lists, pszParmValue, fname);
1116 lpcfg_string_set(lp_ctx, ptr, fname);
1118 if (file_exist(fname))
1119 return pm_process(fname, do_section, do_parameter, lp_ctx);
1121 DEBUG(2, ("Can't find include file %s\n", fname));
1126 /***************************************************************************
1127 Handle the interpretation of the copy parameter.
1128 ***************************************************************************/
1130 bool handle_copy(struct loadparm_context *lp_ctx, int snum,
1131 const char *pszParmValue, char **ptr)
1134 struct loadparm_service *serviceTemp = NULL;
1135 struct loadparm_service *current = NULL;
1139 DEBUG(3, ("Copying service from service %s\n", pszParmValue));
1141 serviceTemp = lpcfg_getservicebyname(lp_ctx, pszParmValue);
1142 if (lp_ctx->s3_fns != NULL) {
1143 current = lp_ctx->s3_fns->get_servicebynum(snum);
1145 current = lp_ctx->currentService;
1148 if (current == NULL) {
1149 DEBUG(0, ("Unable to copy service - invalid service destination"));
1153 if (serviceTemp != NULL) {
1154 if (serviceTemp == current) {
1155 DEBUG(0, ("Can't copy service %s - unable to copy self!\n", pszParmValue));
1157 copy_service(current,
1160 lpcfg_string_set(current, ptr, pszParmValue);
1165 DEBUG(0, ("Unable to copy service - source not found: %s\n",
1173 bool handle_debug_list(struct loadparm_context *lp_ctx, int unused,
1174 const char *pszParmValue, char **ptr)
1176 if (lp_ctx->s3_fns != NULL) {
1177 lp_ctx->s3_fns->lp_string_set(ptr, pszParmValue);
1179 lpcfg_string_set(lp_ctx, ptr, pszParmValue);
1182 return debug_parse_levels(pszParmValue);
1185 bool handle_logfile(struct loadparm_context *lp_ctx, int unused,
1186 const char *pszParmValue, char **ptr)
1188 if (lp_ctx->s3_fns != NULL) {
1189 lp_ctx->s3_fns->lp_string_set(ptr, pszParmValue);
1191 debug_set_logfile(pszParmValue);
1192 lpcfg_string_set(lp_ctx, ptr, pszParmValue);
1199 * These special charset handling methods only run in the source3 code.
1202 bool handle_charset(struct loadparm_context *lp_ctx, int snum,
1203 const char *pszParmValue, char **ptr)
1205 if (lp_ctx->s3_fns) {
1206 if (*ptr == NULL || strcmp(*ptr, pszParmValue) != 0) {
1207 lp_ctx->s3_fns->lp_string_set(ptr, pszParmValue);
1208 global_iconv_handle = smb_iconv_handle_reinit(NULL,
1209 lpcfg_dos_charset(lp_ctx),
1210 lpcfg_unix_charset(lp_ctx),
1211 true, global_iconv_handle);
1216 return lpcfg_string_set(lp_ctx, ptr, pszParmValue);
1220 bool handle_dos_charset(struct loadparm_context *lp_ctx, int snum,
1221 const char *pszParmValue, char **ptr)
1223 bool is_utf8 = false;
1224 size_t len = strlen(pszParmValue);
1226 if (lp_ctx->s3_fns) {
1227 if (len == 4 || len == 5) {
1228 /* Don't use StrCaseCmp here as we don't want to
1229 initialize iconv. */
1230 if ((toupper_m(pszParmValue[0]) == 'U') &&
1231 (toupper_m(pszParmValue[1]) == 'T') &&
1232 (toupper_m(pszParmValue[2]) == 'F')) {
1234 if (pszParmValue[3] == '8') {
1238 if (pszParmValue[3] == '-' &&
1239 pszParmValue[4] == '8') {
1246 if (*ptr == NULL || strcmp(*ptr, pszParmValue) != 0) {
1248 DEBUG(0,("ERROR: invalid DOS charset: 'dos charset' must not "
1249 "be UTF8, using (default value) %s instead.\n",
1250 DEFAULT_DOS_CHARSET));
1251 pszParmValue = DEFAULT_DOS_CHARSET;
1253 lp_ctx->s3_fns->lp_string_set(ptr, pszParmValue);
1254 global_iconv_handle = smb_iconv_handle_reinit(NULL,
1255 lpcfg_dos_charset(lp_ctx),
1256 lpcfg_unix_charset(lp_ctx),
1257 true, global_iconv_handle);
1262 return lpcfg_string_set(lp_ctx, ptr, pszParmValue);
1265 /***************************************************************************
1266 Initialise a copymap.
1267 ***************************************************************************/
1269 void init_copymap(struct loadparm_service *pservice)
1273 TALLOC_FREE(pservice->copymap);
1275 pservice->copymap = bitmap_talloc(NULL, NUMPARAMETERS);
1276 if (!pservice->copymap)
1278 ("Couldn't allocate copymap!! (size %d)\n",
1279 (int)NUMPARAMETERS));
1281 for (i = 0; i < NUMPARAMETERS; i++)
1282 bitmap_set(pservice->copymap, i);
1286 * Process a parametric option
1288 static bool lp_do_parameter_parametric(struct loadparm_context *lp_ctx,
1289 struct loadparm_service *service,
1290 const char *pszParmName,
1291 const char *pszParmValue, int flags)
1293 struct parmlist_entry *paramo, *data;
1295 TALLOC_CTX *mem_ctx;
1297 while (isspace((unsigned char)*pszParmName)) {
1301 name = strlower_talloc(lp_ctx, pszParmName);
1302 if (!name) return false;
1304 if (service == NULL) {
1305 data = lp_ctx->globals->param_opt;
1306 mem_ctx = lp_ctx->globals;
1308 data = service->param_opt;
1312 /* Traverse destination */
1313 for (paramo=data; paramo; paramo=paramo->next) {
1314 /* If we already have the option set, override it unless
1315 it was a command line option and the new one isn't */
1316 if (strcmp(paramo->key, name) == 0) {
1317 if ((paramo->priority & FLAG_CMDLINE) &&
1318 !(flags & FLAG_CMDLINE)) {
1323 talloc_free(paramo->value);
1324 paramo->value = talloc_strdup(paramo, pszParmValue);
1325 paramo->priority = flags;
1331 paramo = talloc_zero(mem_ctx, struct parmlist_entry);
1334 paramo->key = talloc_strdup(paramo, name);
1335 paramo->value = talloc_strdup(paramo, pszParmValue);
1336 paramo->priority = flags;
1337 if (service == NULL) {
1338 DLIST_ADD(lp_ctx->globals->param_opt, paramo);
1340 DLIST_ADD(service->param_opt, paramo);
1348 static bool set_variable(TALLOC_CTX *mem_ctx, int parmnum, void *parm_ptr,
1349 const char *pszParmName, const char *pszParmValue,
1350 struct loadparm_context *lp_ctx, bool on_globals)
1353 /* if it is a special case then go ahead */
1354 if (parm_table[parmnum].special) {
1356 ret = parm_table[parmnum].special(lp_ctx, -1, pszParmValue,
1361 goto mark_non_default;
1364 /* now switch on the type of variable it is */
1365 switch (parm_table[parmnum].type)
1369 if (!set_boolean(pszParmValue, &b)) {
1370 DEBUG(0, ("set_variable(%s): value is not "
1371 "boolean!\n", pszParmValue));
1374 *(bool *)parm_ptr = b;
1380 if (!set_boolean(pszParmValue, &b)) {
1381 DEBUG(0, ("set_variable(%s): value is not "
1382 "boolean!\n", pszParmValue));
1385 *(bool *)parm_ptr = !b;
1390 *(int *)parm_ptr = atoi(pszParmValue);
1394 *(char *)parm_ptr = *pszParmValue;
1398 *(int *)parm_ptr = strtol(pszParmValue, NULL, 8);
1404 if (conv_str_size_error(pszParmValue, &val)) {
1405 if (val <= INT_MAX) {
1406 *(int *)parm_ptr = (int)val;
1411 DEBUG(0, ("set_variable(%s): value is not "
1412 "a valid size specifier!\n", pszParmValue));
1417 *(const char * const **)parm_ptr
1418 = (const char * const *)str_list_make(mem_ctx,
1419 pszParmValue, NULL);
1423 char **new_list = str_list_make(mem_ctx,
1424 pszParmValue, NULL);
1425 for (i=0; new_list[i]; i++) {
1426 if (*(const char ***)parm_ptr != NULL &&
1427 new_list[i][0] == '+' &&
1430 if (!str_list_check(*(const char ***)parm_ptr,
1432 *(const char ***)parm_ptr = str_list_add(*(const char ***)parm_ptr,
1435 } else if (*(const char ***)parm_ptr != NULL &&
1436 new_list[i][0] == '-' &&
1439 str_list_remove(*(const char ***)parm_ptr,
1443 DEBUG(0, ("Unsupported list syntax for: %s = %s\n",
1444 pszParmName, pszParmValue));
1447 *(const char * const **)parm_ptr = (const char * const *) new_list;
1454 lpcfg_string_set(mem_ctx, (char **)parm_ptr, pszParmValue);
1458 lpcfg_string_set_upper(mem_ctx, (char **)parm_ptr, pszParmValue);
1462 if (!lp_set_enum_parm(&parm_table[parmnum], pszParmValue, (int*)parm_ptr)) {
1472 if (on_globals && (lp_ctx->flags[parmnum] & FLAG_DEFAULT)) {
1473 lp_ctx->flags[parmnum] &= ~FLAG_DEFAULT;
1474 /* we have to also unset FLAG_DEFAULT on aliases */
1475 for (i=parmnum-1;i>=0 && parm_table[i].offset == parm_table[parmnum].offset;i--) {
1476 lp_ctx->flags[i] &= ~FLAG_DEFAULT;
1478 for (i=parmnum+1;i<NUMPARAMETERS && parm_table[i].offset == parm_table[parmnum].offset;i++) {
1479 lp_ctx->flags[i] &= ~FLAG_DEFAULT;
1486 bool lpcfg_do_global_parameter(struct loadparm_context *lp_ctx,
1487 const char *pszParmName, const char *pszParmValue)
1489 int parmnum = lpcfg_map_parameter(pszParmName);
1493 if (strchr(pszParmName, ':')) {
1494 return lp_do_parameter_parametric(lp_ctx, NULL, pszParmName, pszParmValue, 0);
1496 DEBUG(0, ("Ignoring unknown parameter \"%s\"\n", pszParmName));
1500 /* if the flag has been set on the command line, then don't allow override,
1501 but don't report an error */
1502 if (lp_ctx->flags[parmnum] & FLAG_CMDLINE) {
1506 parm_ptr = lpcfg_parm_ptr(lp_ctx, NULL, &parm_table[parmnum]);
1508 return set_variable(lp_ctx->globals, parmnum, parm_ptr,
1509 pszParmName, pszParmValue, lp_ctx, true);
1512 bool lpcfg_do_service_parameter(struct loadparm_context *lp_ctx,
1513 struct loadparm_service *service,
1514 const char *pszParmName, const char *pszParmValue)
1518 int parmnum = lpcfg_map_parameter(pszParmName);
1521 if (strchr(pszParmName, ':')) {
1522 return lp_do_parameter_parametric(lp_ctx, service, pszParmName, pszParmValue, 0);
1524 DEBUG(0, ("Ignoring unknown parameter \"%s\"\n", pszParmName));
1528 /* if the flag has been set on the command line, then don't allow override,
1529 but don't report an error */
1530 if (lp_ctx->flags[parmnum] & FLAG_CMDLINE) {
1534 if (parm_table[parmnum].p_class == P_GLOBAL) {
1536 ("Global parameter %s found in service section!\n",
1540 parm_ptr = ((char *)service) + parm_table[parmnum].offset;
1542 if (!service->copymap)
1543 init_copymap(service);
1545 /* this handles the aliases - set the copymap for other
1546 * entries with the same data pointer */
1547 for (i = 0; parm_table[i].label; i++)
1548 if (parm_table[i].offset == parm_table[parmnum].offset &&
1549 parm_table[i].p_class == parm_table[parmnum].p_class)
1550 bitmap_clear(service->copymap, i);
1552 return set_variable(service, parmnum, parm_ptr, pszParmName,
1553 pszParmValue, lp_ctx, false);
1557 * Process a parameter.
1560 static bool do_parameter(const char *pszParmName, const char *pszParmValue,
1563 struct loadparm_context *lp_ctx = (struct loadparm_context *)userdata;
1565 if (lp_ctx->bInGlobalSection)
1566 return lpcfg_do_global_parameter(lp_ctx, pszParmName,
1569 return lpcfg_do_service_parameter(lp_ctx, lp_ctx->currentService,
1570 pszParmName, pszParmValue);
1574 variable argument do parameter
1576 bool lpcfg_do_global_parameter_var(struct loadparm_context *lp_ctx, const char *pszParmName, const char *fmt, ...) PRINTF_ATTRIBUTE(3, 4);
1577 bool lpcfg_do_global_parameter_var(struct loadparm_context *lp_ctx,
1578 const char *pszParmName, const char *fmt, ...)
1585 s = talloc_vasprintf(NULL, fmt, ap);
1587 ret = lpcfg_do_global_parameter(lp_ctx, pszParmName, s);
1594 set a parameter from the commandline - this is called from command line parameter
1595 parsing code. It sets the parameter then marks the parameter as unable to be modified
1596 by smb.conf processing
1598 bool lpcfg_set_cmdline(struct loadparm_context *lp_ctx, const char *pszParmName,
1599 const char *pszParmValue)
1604 while (isspace((unsigned char)*pszParmValue)) pszParmValue++;
1606 if (lp_ctx->s3_fns) {
1607 return lp_ctx->s3_fns->set_cmdline(pszParmName, pszParmValue);
1610 parmnum = lpcfg_map_parameter(pszParmName);
1612 if (parmnum < 0 && strchr(pszParmName, ':')) {
1613 /* set a parametric option */
1614 return lp_do_parameter_parametric(lp_ctx, NULL, pszParmName,
1615 pszParmValue, FLAG_CMDLINE);
1619 DEBUG(0,("Unknown option '%s'\n", pszParmName));
1623 /* reset the CMDLINE flag in case this has been called before */
1624 lp_ctx->flags[parmnum] &= ~FLAG_CMDLINE;
1626 if (!lpcfg_do_global_parameter(lp_ctx, pszParmName, pszParmValue)) {
1630 lp_ctx->flags[parmnum] |= FLAG_CMDLINE;
1632 /* we have to also set FLAG_CMDLINE on aliases */
1634 i>=0 && parm_table[i].p_class == parm_table[parmnum].p_class &&
1635 parm_table[i].offset == parm_table[parmnum].offset;
1637 lp_ctx->flags[i] |= FLAG_CMDLINE;
1641 parm_table[i].p_class == parm_table[parmnum].p_class &&
1642 parm_table[i].offset == parm_table[parmnum].offset;
1644 lp_ctx->flags[i] |= FLAG_CMDLINE;
1651 set a option from the commandline in 'a=b' format. Use to support --option
1653 bool lpcfg_set_option(struct loadparm_context *lp_ctx, const char *option)
1658 s = talloc_strdup(NULL, option);
1671 ret = lpcfg_set_cmdline(lp_ctx, s, p+1);
1677 #define BOOLSTR(b) ((b) ? "Yes" : "No")
1680 * Print a parameter of the specified type.
1683 void lpcfg_print_parameter(struct parm_struct *p, void *ptr, FILE * f)
1685 /* For the seperation of lists values that we print below */
1686 const char *list_sep = ", ";
1691 for (i = 0; p->enum_list[i].name; i++) {
1692 if (*(int *)ptr == p->enum_list[i].value) {
1694 p->enum_list[i].name);
1701 fprintf(f, "%s", BOOLSTR(*(bool *)ptr));
1705 fprintf(f, "%s", BOOLSTR(!*(bool *)ptr));
1710 fprintf(f, "%d", *(int *)ptr);
1714 fprintf(f, "%c", *(char *)ptr);
1718 int val = *(int *)ptr;
1722 fprintf(f, "0%03o", val);
1731 if ((char ***)ptr && *(char ***)ptr) {
1732 char **list = *(char ***)ptr;
1733 for (; *list; list++) {
1734 /* surround strings with whitespace in double quotes */
1735 if (*(list+1) == NULL) {
1736 /* last item, no extra separator */
1739 if ( strchr_m( *list, ' ' ) ) {
1740 fprintf(f, "\"%s\"%s", *list, list_sep);
1742 fprintf(f, "%s%s", *list, list_sep);
1750 if (*(char **)ptr) {
1751 fprintf(f, "%s", *(char **)ptr);
1760 * Check if two parameters are equal.
1763 bool lpcfg_equal_parameter(parm_type type, void *ptr1, void *ptr2)
1768 return (*((bool *)ptr1) == *((bool *)ptr2));
1774 return (*((int *)ptr1) == *((int *)ptr2));
1777 return (*((char *)ptr1) == *((char *)ptr2));
1781 return str_list_equal(*(const char ***)ptr1, *(const char ***)ptr2);
1786 char *p1 = *(char **)ptr1, *p2 = *(char **)ptr2;
1791 return (p1 == p2 || strequal(p1, p2));
1800 * Process a new section (service).
1802 * At this stage all sections are services.
1803 * Later we'll have special sections that permit server parameters to be set.
1804 * Returns True on success, False on failure.
1807 static bool do_section(const char *pszSectionName, void *userdata)
1809 struct loadparm_context *lp_ctx = (struct loadparm_context *)userdata;
1811 bool isglobal = ((strwicmp(pszSectionName, GLOBAL_NAME) == 0) ||
1812 (strwicmp(pszSectionName, GLOBAL_NAME2) == 0));
1815 /* if we've just struck a global section, note the fact. */
1816 lp_ctx->bInGlobalSection = isglobal;
1818 /* check for multiple global sections */
1819 if (lp_ctx->bInGlobalSection) {
1820 DEBUG(4, ("Processing section \"[%s]\"\n", pszSectionName));
1824 /* if we have a current service, tidy it up before moving on */
1827 if (lp_ctx->currentService != NULL)
1828 bRetval = lpcfg_service_ok(lp_ctx->currentService);
1830 /* if all is still well, move to the next record in the services array */
1832 /* We put this here to avoid an odd message order if messages are */
1833 /* issued by the post-processing of a previous section. */
1834 DEBUG(4, ("Processing section \"[%s]\"\n", pszSectionName));
1836 if ((lp_ctx->currentService = lpcfg_add_service(lp_ctx, lp_ctx->sDefault,
1839 DEBUG(0, ("Failed to add a new service\n"));
1849 * Determine if a particular base parameter is currently set to the default value.
1852 static bool is_default(struct loadparm_service *sDefault, int i)
1854 void *def_ptr = ((char *)sDefault) + parm_table[i].offset;
1855 switch (parm_table[i].type) {
1858 return str_list_equal((const char * const *)parm_table[i].def.lvalue,
1859 (const char **)def_ptr);
1862 return strequal(parm_table[i].def.svalue,
1866 return parm_table[i].def.bvalue ==
1873 return parm_table[i].def.ivalue ==
1882 *Display the contents of the global structure.
1885 static void dump_globals(struct loadparm_context *lp_ctx, FILE *f,
1889 struct parmlist_entry *data;
1891 fprintf(f, "# Global parameters\n[global]\n");
1893 for (i = 0; parm_table[i].label; i++)
1894 if (parm_table[i].p_class == P_GLOBAL &&
1895 (i == 0 || (parm_table[i].offset != parm_table[i - 1].offset))) {
1896 if (!show_defaults && (lp_ctx->flags[i] & FLAG_DEFAULT))
1898 fprintf(f, "\t%s = ", parm_table[i].label);
1899 lpcfg_print_parameter(&parm_table[i], lpcfg_parm_ptr(lp_ctx, NULL, &parm_table[i]), f);
1902 if (lp_ctx->globals->param_opt != NULL) {
1903 for (data = lp_ctx->globals->param_opt; data;
1904 data = data->next) {
1905 if (!show_defaults && (data->priority & FLAG_DEFAULT)) {
1908 fprintf(f, "\t%s = %s\n", data->key, data->value);
1915 * Display the contents of a single services record.
1918 static void dump_a_service(struct loadparm_service * pService, struct loadparm_service *sDefault, FILE * f,
1919 unsigned int *flags)
1922 struct parmlist_entry *data;
1924 if (pService != sDefault)
1925 fprintf(f, "\n[%s]\n", pService->szService);
1927 for (i = 0; parm_table[i].label; i++) {
1928 if (parm_table[i].p_class == P_LOCAL &&
1929 (*parm_table[i].label != '-') &&
1930 (i == 0 || (parm_table[i].offset != parm_table[i - 1].offset)))
1932 if (pService == sDefault) {
1933 if (flags && (flags[i] & FLAG_DEFAULT)) {
1936 if (defaults_saved) {
1937 if (is_default(sDefault, i)) {
1942 if (lpcfg_equal_parameter(parm_table[i].type,
1943 ((char *)pService) +
1944 parm_table[i].offset,
1945 ((char *)sDefault) +
1946 parm_table[i].offset))
1950 fprintf(f, "\t%s = ", parm_table[i].label);
1951 lpcfg_print_parameter(&parm_table[i],
1952 ((char *)pService) + parm_table[i].offset, f);
1956 if (pService->param_opt != NULL) {
1957 for (data = pService->param_opt; data; data = data->next) {
1958 fprintf(f, "\t%s = %s\n", data->key, data->value);
1963 bool lpcfg_dump_a_parameter(struct loadparm_context *lp_ctx,
1964 struct loadparm_service *service,
1965 const char *parm_name, FILE * f)
1967 struct parm_struct *parm;
1970 parm = lpcfg_parm_struct(lp_ctx, parm_name);
1975 if (service != NULL && parm->p_class == P_GLOBAL) {
1979 ptr = lpcfg_parm_ptr(lp_ctx, service,parm);
1981 lpcfg_print_parameter(parm, ptr, f);
1987 * Auto-load some home services.
1989 static void lpcfg_add_auto_services(struct loadparm_context *lp_ctx,
1997 * Unload unused services.
2000 void lpcfg_killunused(struct loadparm_context *lp_ctx,
2001 struct smbsrv_connection *smb,
2002 bool (*snumused) (struct smbsrv_connection *, int))
2005 for (i = 0; i < lp_ctx->iNumServices; i++) {
2006 if (lp_ctx->services[i] == NULL)
2009 if (!snumused || !snumused(smb, i)) {
2010 talloc_free(lp_ctx->services[i]);
2011 lp_ctx->services[i] = NULL;
2017 static int lpcfg_destructor(struct loadparm_context *lp_ctx)
2019 struct parmlist_entry *data;
2021 if (lp_ctx->refuse_free) {
2022 /* someone is trying to free the
2023 global_loadparm_context.
2024 We can't allow that. */
2028 if (lp_ctx->globals->param_opt != NULL) {
2029 struct parmlist_entry *next;
2030 for (data = lp_ctx->globals->param_opt; data; data=next) {
2032 if (data->priority & FLAG_CMDLINE) continue;
2033 DLIST_REMOVE(lp_ctx->globals->param_opt, data);
2042 * Initialise the global parameter structure.
2044 * Note that most callers should use loadparm_init_global() instead
2046 struct loadparm_context *loadparm_init(TALLOC_CTX *mem_ctx)
2050 struct loadparm_context *lp_ctx;
2051 struct parmlist_entry *parm;
2054 lp_ctx = talloc_zero(mem_ctx, struct loadparm_context);
2058 talloc_set_destructor(lp_ctx, lpcfg_destructor);
2059 lp_ctx->bInGlobalSection = true;
2060 lp_ctx->globals = talloc_zero(lp_ctx, struct loadparm_global);
2061 lp_ctx->sDefault = talloc_zero(lp_ctx, struct loadparm_service);
2062 lp_ctx->flags = talloc_zero_array(lp_ctx, unsigned int, NUMPARAMETERS);
2064 lp_ctx->sDefault->iMaxPrintJobs = 1000;
2065 lp_ctx->sDefault->bAvailable = true;
2066 lp_ctx->sDefault->browseable = true;
2067 lp_ctx->sDefault->read_only = true;
2068 lp_ctx->sDefault->map_archive = true;
2069 lp_ctx->sDefault->strict_locking = true;
2070 lp_ctx->sDefault->oplocks = true;
2071 lp_ctx->sDefault->create_mask = 0744;
2072 lp_ctx->sDefault->force_create_mode = 0000;
2073 lp_ctx->sDefault->directory_mask = 0755;
2074 lp_ctx->sDefault->force_directory_mode = 0000;
2076 DEBUG(3, ("Initialising global parameters\n"));
2078 for (i = 0; parm_table[i].label; i++) {
2079 if ((parm_table[i].type == P_STRING ||
2080 parm_table[i].type == P_USTRING) &&
2081 !(lp_ctx->flags[i] & FLAG_CMDLINE)) {
2083 if (parm_table[i].p_class == P_LOCAL) {
2084 r = (char **)(((char *)lp_ctx->sDefault) + parm_table[i].offset);
2086 r = (char **)(((char *)lp_ctx->globals) + parm_table[i].offset);
2088 *r = talloc_strdup(lp_ctx, "");
2092 logfile = talloc_asprintf(lp_ctx, "%s/log.samba", dyn_LOGFILEBASE);
2093 lpcfg_do_global_parameter(lp_ctx, "log file", logfile);
2094 talloc_free(logfile);
2096 lpcfg_do_global_parameter(lp_ctx, "log level", "0");
2098 lpcfg_do_global_parameter(lp_ctx, "syslog", "1");
2099 lpcfg_do_global_parameter(lp_ctx, "syslog only", "No");
2100 lpcfg_do_global_parameter(lp_ctx, "debug timestamp", "Yes");
2101 lpcfg_do_global_parameter(lp_ctx, "debug prefix timestamp", "No");
2102 lpcfg_do_global_parameter(lp_ctx, "debug hires timestamp", "Yes");
2103 lpcfg_do_global_parameter(lp_ctx, "debug pid", "No");
2104 lpcfg_do_global_parameter(lp_ctx, "debug uid", "No");
2105 lpcfg_do_global_parameter(lp_ctx, "debug class", "No");
2107 lpcfg_do_global_parameter(lp_ctx, "share backend", "classic");
2109 lpcfg_do_global_parameter(lp_ctx, "server role", "auto");
2110 lpcfg_do_global_parameter(lp_ctx, "domain logons", "No");
2111 lpcfg_do_global_parameter(lp_ctx, "domain master", "Auto");
2113 /* options that can be set on the command line must be initialised via
2114 the slower lpcfg_do_global_parameter() to ensure that FLAG_CMDLINE is obeyed */
2116 lpcfg_do_global_parameter(lp_ctx, "socket options", "TCP_NODELAY");
2118 lpcfg_do_global_parameter(lp_ctx, "workgroup", DEFAULT_WORKGROUP);
2119 myname = get_myname(lp_ctx);
2120 lpcfg_do_global_parameter(lp_ctx, "netbios name", myname);
2121 talloc_free(myname);
2122 lpcfg_do_global_parameter(lp_ctx, "name resolve order", "lmhosts wins host bcast");
2124 lpcfg_do_global_parameter(lp_ctx, "fstype", "NTFS");
2126 lpcfg_do_global_parameter(lp_ctx, "ntvfs handler", "unixuid default");
2127 lpcfg_do_global_parameter(lp_ctx, "max connections", "0");
2129 lpcfg_do_global_parameter(lp_ctx, "dcerpc endpoint servers", "epmapper wkssvc rpcecho samr netlogon lsarpc spoolss drsuapi dssetup unixinfo browser eventlog6 backupkey dnsserver");
2130 lpcfg_do_global_parameter(lp_ctx, "server services", "s3fs rpc nbt wrepl ldap cldap kdc drepl winbind ntp_signd kcc dnsupdate dns");
2131 lpcfg_do_global_parameter(lp_ctx, "kccsrv:samba_kcc", "true");
2132 /* the winbind method for domain controllers is for both RODC
2133 auth forwarding and for trusted domains */
2134 lpcfg_do_global_parameter(lp_ctx, "private dir", dyn_PRIVATE_DIR);
2135 lpcfg_do_global_parameter(lp_ctx, "registry:HKEY_LOCAL_MACHINE", "hklm.ldb");
2137 /* This hive should be dynamically generated by Samba using
2138 data from the sam, but for the moment leave it in a tdb to
2139 keep regedt32 from popping up an annoying dialog. */
2140 lpcfg_do_global_parameter(lp_ctx, "registry:HKEY_USERS", "hku.ldb");
2142 /* using UTF8 by default allows us to support all chars */
2143 lpcfg_do_global_parameter(lp_ctx, "unix charset", "UTF-8");
2145 /* Use codepage 850 as a default for the dos character set */
2146 lpcfg_do_global_parameter(lp_ctx, "dos charset", "CP850");
2149 * Allow the default PASSWD_CHAT to be overridden in local.h.
2151 lpcfg_do_global_parameter(lp_ctx, "passwd chat", DEFAULT_PASSWD_CHAT);
2153 lpcfg_do_global_parameter(lp_ctx, "pid directory", dyn_PIDDIR);
2154 lpcfg_do_global_parameter(lp_ctx, "lock dir", dyn_LOCKDIR);
2155 lpcfg_do_global_parameter(lp_ctx, "state directory", dyn_STATEDIR);
2156 lpcfg_do_global_parameter(lp_ctx, "cache directory", dyn_CACHEDIR);
2157 lpcfg_do_global_parameter(lp_ctx, "ncalrpc dir", dyn_NCALRPCDIR);
2159 lpcfg_do_global_parameter(lp_ctx, "nbt client socket address", "0.0.0.0");
2160 lpcfg_do_global_parameter_var(lp_ctx, "server string",
2161 "Samba %s", SAMBA_VERSION_STRING);
2163 lpcfg_do_global_parameter(lp_ctx, "password server", "*");
2165 lpcfg_do_global_parameter(lp_ctx, "max mux", "50");
2166 lpcfg_do_global_parameter(lp_ctx, "max xmit", "16644");
2167 lpcfg_do_global_parameter(lp_ctx, "host msdfs", "true");
2169 lpcfg_do_global_parameter(lp_ctx, "LargeReadwrite", "True");
2170 lpcfg_do_global_parameter(lp_ctx, "server min protocol", "LANMAN1");
2171 lpcfg_do_global_parameter(lp_ctx, "server max protocol", "SMB3");
2172 lpcfg_do_global_parameter(lp_ctx, "client min protocol", "CORE");
2173 lpcfg_do_global_parameter(lp_ctx, "client max protocol", "NT1");
2174 lpcfg_do_global_parameter(lp_ctx, "security", "AUTO");
2175 lpcfg_do_global_parameter(lp_ctx, "EncryptPasswords", "True");
2176 lpcfg_do_global_parameter(lp_ctx, "ReadRaw", "True");
2177 lpcfg_do_global_parameter(lp_ctx, "WriteRaw", "True");
2178 lpcfg_do_global_parameter(lp_ctx, "NullPasswords", "False");
2179 lpcfg_do_global_parameter(lp_ctx, "old password allowed period", "60");
2180 lpcfg_do_global_parameter(lp_ctx, "ObeyPamRestrictions", "False");
2182 lpcfg_do_global_parameter(lp_ctx, "TimeServer", "False");
2183 lpcfg_do_global_parameter(lp_ctx, "BindInterfacesOnly", "False");
2184 lpcfg_do_global_parameter(lp_ctx, "Unicode", "True");
2185 lpcfg_do_global_parameter(lp_ctx, "ClientLanManAuth", "False");
2186 lpcfg_do_global_parameter(lp_ctx, "ClientNTLMv2Auth", "True");
2187 lpcfg_do_global_parameter(lp_ctx, "LanmanAuth", "False");
2188 lpcfg_do_global_parameter(lp_ctx, "NTLMAuth", "True");
2189 lpcfg_do_global_parameter(lp_ctx, "client use spnego principal", "False");
2191 lpcfg_do_global_parameter(lp_ctx, "UnixExtensions", "True");
2193 lpcfg_do_global_parameter(lp_ctx, "PreferredMaster", "Auto");
2194 lpcfg_do_global_parameter(lp_ctx, "LocalMaster", "True");
2196 lpcfg_do_global_parameter(lp_ctx, "wins support", "False");
2197 lpcfg_do_global_parameter(lp_ctx, "dns proxy", "True");
2199 lpcfg_do_global_parameter(lp_ctx, "winbind separator", "\\");
2200 lpcfg_do_global_parameter(lp_ctx, "winbind sealed pipes", "True");
2201 lpcfg_do_global_parameter(lp_ctx, "require strong key", "True");
2202 lpcfg_do_global_parameter(lp_ctx, "winbindd socket directory", dyn_WINBINDD_SOCKET_DIR);
2203 lpcfg_do_global_parameter(lp_ctx, "winbindd privileged socket directory", dyn_WINBINDD_PRIVILEGED_SOCKET_DIR);
2204 lpcfg_do_global_parameter(lp_ctx, "ntp signd socket directory", dyn_NTP_SIGND_SOCKET_DIR);
2205 lpcfg_do_global_parameter_var(lp_ctx, "dns update command", "%s/samba_dnsupdate", dyn_SCRIPTSBINDIR);
2206 lpcfg_do_global_parameter_var(lp_ctx, "spn update command", "%s/samba_spnupdate", dyn_SCRIPTSBINDIR);
2207 lpcfg_do_global_parameter_var(lp_ctx, "samba kcc command",
2208 "%s/samba_kcc", dyn_SCRIPTSBINDIR);
2209 lpcfg_do_global_parameter(lp_ctx, "template shell", "/bin/false");
2210 lpcfg_do_global_parameter(lp_ctx, "template homedir", "/home/%WORKGROUP%/%ACCOUNTNAME%");
2212 lpcfg_do_global_parameter(lp_ctx, "client signing", "default");
2213 lpcfg_do_global_parameter(lp_ctx, "server signing", "default");
2215 lpcfg_do_global_parameter(lp_ctx, "use spnego", "True");
2217 lpcfg_do_global_parameter(lp_ctx, "use mmap", "True");
2219 lpcfg_do_global_parameter(lp_ctx, "smb ports", "445 139");
2220 lpcfg_do_global_parameter(lp_ctx, "nbt port", "137");
2221 lpcfg_do_global_parameter(lp_ctx, "dgram port", "138");
2222 lpcfg_do_global_parameter(lp_ctx, "cldap port", "389");
2223 lpcfg_do_global_parameter(lp_ctx, "krb5 port", "88");
2224 lpcfg_do_global_parameter(lp_ctx, "kpasswd port", "464");
2225 lpcfg_do_global_parameter(lp_ctx, "web port", "901");
2227 lpcfg_do_global_parameter(lp_ctx, "nt status support", "True");
2229 lpcfg_do_global_parameter(lp_ctx, "max wins ttl", "518400"); /* 6 days */
2230 lpcfg_do_global_parameter(lp_ctx, "min wins ttl", "21600");
2232 lpcfg_do_global_parameter(lp_ctx, "tls enabled", "True");
2233 lpcfg_do_global_parameter(lp_ctx, "tls keyfile", "tls/key.pem");
2234 lpcfg_do_global_parameter(lp_ctx, "tls certfile", "tls/cert.pem");
2235 lpcfg_do_global_parameter(lp_ctx, "tls cafile", "tls/ca.pem");
2236 lpcfg_do_global_parameter(lp_ctx, "prefork children:smb", "4");
2238 lpcfg_do_global_parameter(lp_ctx, "rndc command", "/usr/sbin/rndc");
2239 lpcfg_do_global_parameter(lp_ctx, "nsupdate command", "/usr/bin/nsupdate -g");
2241 lpcfg_do_global_parameter(lp_ctx, "allow dns updates", "secure only");
2242 lpcfg_do_global_parameter(lp_ctx, "dns forwarder", "");
2244 lpcfg_do_global_parameter(lp_ctx, "algorithmic rid base", "1000");
2246 lpcfg_do_global_parameter(lp_ctx, "enhanced browsing", "True");
2248 lpcfg_do_global_parameter(lp_ctx, "winbind nss info", "template");
2250 lpcfg_do_global_parameter(lp_ctx, "server schannel", "Auto");
2252 lpcfg_do_global_parameter(lp_ctx, "short preserve case", "True");
2254 lpcfg_do_global_parameter(lp_ctx, "max open files", "16384");
2256 lpcfg_do_global_parameter(lp_ctx, "cups connection timeout", "30");
2258 lpcfg_do_global_parameter(lp_ctx, "locking", "True");
2260 lpcfg_do_global_parameter(lp_ctx, "block size", "1024");
2262 lpcfg_do_global_parameter(lp_ctx, "client use spnego", "True");
2264 lpcfg_do_global_parameter(lp_ctx, "change notify", "True");
2266 lpcfg_do_global_parameter(lp_ctx, "name cache timeout", "660");
2268 lpcfg_do_global_parameter(lp_ctx, "defer sharing violations", "True");
2270 lpcfg_do_global_parameter(lp_ctx, "ldap replication sleep", "1000");
2272 lpcfg_do_global_parameter(lp_ctx, "idmap backend", "tdb");
2274 lpcfg_do_global_parameter(lp_ctx, "enable privileges", "True");
2276 lpcfg_do_global_parameter_var(lp_ctx, "smb2 max write", "%u", DEFAULT_SMB2_MAX_WRITE);
2278 lpcfg_do_global_parameter(lp_ctx, "passdb backend", "tdbsam");
2280 lpcfg_do_global_parameter(lp_ctx, "getwd cache", "True");
2282 lpcfg_do_global_parameter(lp_ctx, "winbind nested groups", "True");
2284 lpcfg_do_global_parameter(lp_ctx, "mangled names", "True");
2286 lpcfg_do_global_parameter_var(lp_ctx, "smb2 max credits", "%u", DEFAULT_SMB2_MAX_CREDITS);
2288 lpcfg_do_global_parameter(lp_ctx, "ldap ssl", "start tls");
2290 lpcfg_do_global_parameter(lp_ctx, "ldap deref", "auto");
2292 lpcfg_do_global_parameter(lp_ctx, "lm interval", "60");
2294 lpcfg_do_global_parameter(lp_ctx, "mangling method", "hash2");
2296 lpcfg_do_global_parameter(lp_ctx, "hide dot files", "True");
2298 lpcfg_do_global_parameter(lp_ctx, "browse list", "True");
2300 lpcfg_do_global_parameter(lp_ctx, "passwd chat timeout", "2");
2302 lpcfg_do_global_parameter(lp_ctx, "guest account", GUEST_ACCOUNT);
2304 lpcfg_do_global_parameter(lp_ctx, "client schannel", "auto");
2306 lpcfg_do_global_parameter(lp_ctx, "smb encrypt", "default");
2308 lpcfg_do_global_parameter(lp_ctx, "max log size", "5000");
2310 lpcfg_do_global_parameter(lp_ctx, "idmap negative cache time", "120");
2312 lpcfg_do_global_parameter(lp_ctx, "ldap follow referral", "auto");
2314 lpcfg_do_global_parameter(lp_ctx, "multicast dns register", "yes");
2316 lpcfg_do_global_parameter(lp_ctx, "winbind reconnect delay", "30");
2318 lpcfg_do_global_parameter(lp_ctx, "nt acl support", "yes");
2320 lpcfg_do_global_parameter(lp_ctx, "acl check permissions", "yes");
2322 lpcfg_do_global_parameter(lp_ctx, "keepalive", "300");
2324 lpcfg_do_global_parameter(lp_ctx, "winbind cache time", "300");
2326 lpcfg_do_global_parameter(lp_ctx, "level2 oplocks", "yes");
2328 lpcfg_do_global_parameter(lp_ctx, "show add printer wizard", "yes");
2330 lpcfg_do_global_parameter(lp_ctx, "allocation roundup size", "1048576");
2332 lpcfg_do_global_parameter(lp_ctx, "ldap page size", "1024");
2334 lpcfg_do_global_parameter(lp_ctx, "kernel share modes", "yes");
2336 lpcfg_do_global_parameter(lp_ctx, "strict locking", "Auto");
2338 lpcfg_do_global_parameter(lp_ctx, "map readonly", "yes");
2340 lpcfg_do_global_parameter(lp_ctx, "allow trusted domains", "yes");
2342 lpcfg_do_global_parameter(lp_ctx, "default devmode", "yes");
2344 lpcfg_do_global_parameter(lp_ctx, "os level", "20");
2346 lpcfg_do_global_parameter(lp_ctx, "dos filetimes", "yes");
2348 lpcfg_do_global_parameter(lp_ctx, "mangling char", "~");
2350 lpcfg_do_global_parameter(lp_ctx, "printcap cache time", "750");
2352 lpcfg_do_global_parameter(lp_ctx, "create krb5 conf", "yes");
2354 lpcfg_do_global_parameter(lp_ctx, "winbind max clients", "200");
2356 lpcfg_do_global_parameter(lp_ctx, "acl map full control", "yes");
2358 lpcfg_do_global_parameter(lp_ctx, "nt pipe support", "yes");
2360 lpcfg_do_global_parameter(lp_ctx, "ldap debug threshold", "10");
2362 lpcfg_do_global_parameter(lp_ctx, "follow symlinks", "yes");
2364 lpcfg_do_global_parameter(lp_ctx, "machine password timeout", "604800");
2366 lpcfg_do_global_parameter(lp_ctx, "ldap connection timeout", "2");
2368 lpcfg_do_global_parameter(lp_ctx, "winbind expand groups", "1");
2370 lpcfg_do_global_parameter(lp_ctx, "stat cache", "yes");
2372 lpcfg_do_global_parameter(lp_ctx, "lpq cache time", "30");
2374 lpcfg_do_global_parameter_var(lp_ctx, "smb2 max trans", "%u", DEFAULT_SMB2_MAX_TRANSACT);
2376 lpcfg_do_global_parameter_var(lp_ctx, "smb2 max read", "%u", DEFAULT_SMB2_MAX_READ);
2378 lpcfg_do_global_parameter(lp_ctx, "durable handles", "yes");
2380 lpcfg_do_global_parameter(lp_ctx, "max stat cache size", "256");
2382 lpcfg_do_global_parameter(lp_ctx, "ldap passwd sync", "no");
2384 lpcfg_do_global_parameter(lp_ctx, "kernel change notify", "yes");
2386 lpcfg_do_global_parameter(lp_ctx, "max ttl", "259200");
2388 lpcfg_do_global_parameter(lp_ctx, "blocking locks", "yes");
2390 lpcfg_do_global_parameter(lp_ctx, "oplock contention limit", "2");
2392 lpcfg_do_global_parameter(lp_ctx, "load printers", "yes");
2394 lpcfg_do_global_parameter(lp_ctx, "idmap cache time", "604800");
2396 lpcfg_do_global_parameter(lp_ctx, "preserve case", "yes");
2398 lpcfg_do_global_parameter(lp_ctx, "lm announce", "auto");
2400 lpcfg_do_global_parameter(lp_ctx, "afs token lifetime", "604800");
2402 lpcfg_do_global_parameter(lp_ctx, "enable core files", "yes");
2404 lpcfg_do_global_parameter(lp_ctx, "winbind max domain connections", "1");
2406 lpcfg_do_global_parameter(lp_ctx, "case sensitive", "auto");
2408 lpcfg_do_global_parameter(lp_ctx, "ldap timeout", "15");
2410 lpcfg_do_global_parameter(lp_ctx, "mangle prefix", "1");
2412 lpcfg_do_global_parameter(lp_ctx, "posix locking", "yes");
2414 lpcfg_do_global_parameter(lp_ctx, "lock spin time", "200");
2416 lpcfg_do_global_parameter(lp_ctx, "directory name cache size", "100");
2418 lpcfg_do_global_parameter(lp_ctx, "nmbd bind explicit broadcast", "yes");
2420 lpcfg_do_global_parameter(lp_ctx, "init logon delay", "100");
2422 lpcfg_do_global_parameter(lp_ctx, "usershare owner only", "yes");
2424 lpcfg_do_global_parameter(lp_ctx, "-valid", "yes");
2426 lpcfg_do_global_parameter_var(lp_ctx, "usershare path", "%s/usershares", get_dyn_STATEDIR());
2429 lpcfg_do_global_parameter_var(lp_ctx, "panic action", "/bin/sleep 999999999");
2432 lpcfg_do_global_parameter(lp_ctx, "smb passwd file", get_dyn_SMB_PASSWD_FILE());
2434 lpcfg_do_global_parameter(lp_ctx, "logon home", "\\\\%N\\%U");
2436 lpcfg_do_global_parameter(lp_ctx, "logon path", "\\\\%N\\%U\\profile");
2438 lpcfg_do_global_parameter(lp_ctx, "printjob username", "%U");
2440 for (i = 0; parm_table[i].label; i++) {
2441 if (!(lp_ctx->flags[i] & FLAG_CMDLINE)) {
2442 lp_ctx->flags[i] |= FLAG_DEFAULT;
2446 for (parm=lp_ctx->globals->param_opt; parm; parm=parm->next) {
2447 if (!(parm->priority & FLAG_CMDLINE)) {
2448 parm->priority |= FLAG_DEFAULT;
2456 * Initialise the global parameter structure.
2458 struct loadparm_context *loadparm_init_global(bool load_default)
2460 if (global_loadparm_context == NULL) {
2461 global_loadparm_context = loadparm_init(NULL);
2463 if (global_loadparm_context == NULL) {
2466 global_loadparm_context->global = true;
2467 if (load_default && !global_loadparm_context->loaded) {
2468 lpcfg_load_default(global_loadparm_context);
2470 global_loadparm_context->refuse_free = true;
2471 return global_loadparm_context;
2475 * Initialise the global parameter structure.
2477 struct loadparm_context *loadparm_init_s3(TALLOC_CTX *mem_ctx,
2478 const struct loadparm_s3_helpers *s3_fns)
2480 struct loadparm_context *loadparm_context = talloc_zero(mem_ctx, struct loadparm_context);
2481 if (!loadparm_context) {
2484 loadparm_context->s3_fns = s3_fns;
2485 loadparm_context->globals = s3_fns->globals;
2486 return loadparm_context;
2489 const char *lpcfg_configfile(struct loadparm_context *lp_ctx)
2491 return lp_ctx->szConfigFile;
2494 const char *lp_default_path(void)
2496 if (getenv("SMB_CONF_PATH"))
2497 return getenv("SMB_CONF_PATH");
2499 return dyn_CONFIGFILE;
2503 * Update the internal state of a loadparm context after settings
2506 static bool lpcfg_update(struct loadparm_context *lp_ctx)
2508 struct debug_settings settings;
2509 TALLOC_CTX *tmp_ctx;
2511 tmp_ctx = talloc_new(lp_ctx);
2512 if (tmp_ctx == NULL) {
2516 lpcfg_add_auto_services(lp_ctx, lpcfg_auto_services(lp_ctx, tmp_ctx));
2518 if (!lp_ctx->globals->wins_server_list && lp_ctx->globals->we_are_a_wins_server) {
2519 lpcfg_do_global_parameter(lp_ctx, "wins server", "127.0.0.1");
2522 if (!lp_ctx->global) {
2523 TALLOC_FREE(tmp_ctx);
2527 panic_action = lp_ctx->globals->panic_action;
2529 reload_charcnv(lp_ctx);
2531 ZERO_STRUCT(settings);
2532 /* Add any more debug-related smb.conf parameters created in
2534 settings.syslog = lp_ctx->globals->syslog;
2535 settings.syslog_only = lp_ctx->globals->syslog_only;
2536 settings.timestamp_logs = lp_ctx->globals->timestamp_logs;
2537 settings.debug_prefix_timestamp = lp_ctx->globals->debug_prefix_timestamp;
2538 settings.debug_hires_timestamp = lp_ctx->globals->debug_hires_timestamp;
2539 settings.debug_pid = lp_ctx->globals->debug_pid;
2540 settings.debug_uid = lp_ctx->globals->debug_uid;
2541 settings.debug_class = lp_ctx->globals->debug_class;
2542 debug_set_settings(&settings);
2544 /* FIXME: This is a bit of a hack, but we can't use a global, since
2545 * not everything that uses lp also uses the socket library */
2546 if (lpcfg_parm_bool(lp_ctx, NULL, "socket", "testnonblock", false)) {
2547 setenv("SOCKET_TESTNONBLOCK", "1", 1);
2549 unsetenv("SOCKET_TESTNONBLOCK");
2552 TALLOC_FREE(tmp_ctx);
2556 bool lpcfg_load_default(struct loadparm_context *lp_ctx)
2560 path = lp_default_path();
2562 if (!file_exist(path)) {
2563 /* We allow the default smb.conf file to not exist,
2564 * basically the equivalent of an empty file. */
2565 return lpcfg_update(lp_ctx);
2568 return lpcfg_load(lp_ctx, path);
2572 * Load the services array from the services file.
2574 * Return True on success, False on failure.
2576 bool lpcfg_load(struct loadparm_context *lp_ctx, const char *filename)
2581 filename = talloc_strdup(lp_ctx, filename);
2583 lp_ctx->szConfigFile = filename;
2585 if (lp_ctx->s3_fns) {
2586 return lp_ctx->s3_fns->load(filename);
2589 lp_ctx->bInGlobalSection = true;
2590 n2 = standard_sub_basic(lp_ctx, lp_ctx->szConfigFile);
2591 DEBUG(2, ("lpcfg_load: refreshing parameters from %s\n", n2));
2593 add_to_file_list(lp_ctx, &lp_ctx->file_lists, lp_ctx->szConfigFile, n2);
2595 /* We get sections first, so have to start 'behind' to make up */
2596 lp_ctx->currentService = NULL;
2597 bRetval = pm_process(n2, do_section, do_parameter, lp_ctx);
2599 /* finish up the last section */
2600 DEBUG(4, ("pm_process() returned %s\n", BOOLSTR(bRetval)));
2602 if (lp_ctx->currentService != NULL)
2603 bRetval = lpcfg_service_ok(lp_ctx->currentService);
2605 bRetval = bRetval && lpcfg_update(lp_ctx);
2607 /* we do this unconditionally, so that it happens even
2608 for a missing smb.conf */
2609 reload_charcnv(lp_ctx);
2611 if (bRetval == true) {
2612 /* set this up so that any child python tasks will
2613 find the right smb.conf */
2614 setenv("SMB_CONF_PATH", filename, 1);
2616 /* set the context used by the lp_*() function
2618 global_loadparm_context = lp_ctx;
2619 lp_ctx->loaded = true;
2626 * Return the max number of services.
2629 int lpcfg_numservices(struct loadparm_context *lp_ctx)
2631 if (lp_ctx->s3_fns) {
2632 return lp_ctx->s3_fns->get_numservices();
2635 return lp_ctx->iNumServices;
2639 * Display the contents of the services array in human-readable form.
2642 void lpcfg_dump(struct loadparm_context *lp_ctx, FILE *f, bool show_defaults,
2647 if (lp_ctx->s3_fns) {
2648 lp_ctx->s3_fns->dump(f, show_defaults, maxtoprint);
2652 defaults_saved = !show_defaults;
2654 dump_globals(lp_ctx, f, show_defaults);
2656 dump_a_service(lp_ctx->sDefault, lp_ctx->sDefault, f, lp_ctx->flags);
2658 for (iService = 0; iService < maxtoprint; iService++)
2659 lpcfg_dump_one(f, show_defaults, lp_ctx->services[iService], lp_ctx->sDefault);
2663 * Display the contents of one service in human-readable form.
2665 void lpcfg_dump_one(FILE *f, bool show_defaults, struct loadparm_service *service, struct loadparm_service *sDefault)
2667 if (service != NULL) {
2668 if (service->szService[0] == '\0')
2670 dump_a_service(service, sDefault, f, NULL);
2674 struct loadparm_service *lpcfg_servicebynum(struct loadparm_context *lp_ctx,
2677 if (lp_ctx->s3_fns) {
2678 return lp_ctx->s3_fns->get_servicebynum(snum);
2681 return lp_ctx->services[snum];
2684 struct loadparm_service *lpcfg_service(struct loadparm_context *lp_ctx,
2685 const char *service_name)
2690 if (lp_ctx->s3_fns) {
2691 return lp_ctx->s3_fns->get_service(service_name);
2694 for (iService = lp_ctx->iNumServices - 1; iService >= 0; iService--) {
2695 if (lp_ctx->services[iService] &&
2696 lp_ctx->services[iService]->szService) {
2698 * The substitution here is used to support %U is
2701 serviceName = standard_sub_basic(
2702 lp_ctx->services[iService],
2703 lp_ctx->services[iService]->szService);
2704 if (strequal(serviceName, service_name)) {
2705 talloc_free(serviceName);
2706 return lp_ctx->services[iService];
2708 talloc_free(serviceName);
2712 DEBUG(7,("lpcfg_servicenumber: couldn't find %s\n", service_name));
2716 const char *lpcfg_servicename(const struct loadparm_service *service)
2718 return lpcfg_string((const char *)service->szService);
2722 * A useful volume label function.
2724 const char *lpcfg_volume_label(struct loadparm_service *service, struct loadparm_service *sDefault)
2727 ret = lpcfg_string((const char *)((service != NULL && service->volume != NULL) ?
2728 service->volume : sDefault->volume));
2730 return lpcfg_servicename(service);
2735 * Return the correct printer name.
2737 const char *lpcfg_printername(struct loadparm_service *service, struct loadparm_service *sDefault)
2740 ret = lpcfg_string((const char *)((service != NULL && service->_printername != NULL) ?
2741 service->_printername : sDefault->_printername));
2742 if (ret == NULL || (ret != NULL && *ret == '\0'))
2743 ret = lpcfg_servicename(service);
2750 * Return the max print jobs per queue.
2752 int lpcfg_maxprintjobs(struct loadparm_service *service, struct loadparm_service *sDefault)
2754 int maxjobs = (service != NULL) ? service->iMaxPrintJobs : sDefault->iMaxPrintJobs;
2755 if (maxjobs <= 0 || maxjobs >= PRINT_MAX_JOBID)
2756 maxjobs = PRINT_MAX_JOBID - 1;
2761 struct smb_iconv_handle *lpcfg_iconv_handle(struct loadparm_context *lp_ctx)
2763 if (lp_ctx == NULL) {
2764 return get_iconv_handle();
2766 return lp_ctx->iconv_handle;
2769 _PUBLIC_ void reload_charcnv(struct loadparm_context *lp_ctx)
2771 struct smb_iconv_handle *old_ic = lp_ctx->iconv_handle;
2772 if (!lp_ctx->global) {
2776 if (old_ic == NULL) {
2777 old_ic = global_iconv_handle;
2779 lp_ctx->iconv_handle = smb_iconv_handle_reinit_lp(lp_ctx, lp_ctx, old_ic);
2780 global_iconv_handle = lp_ctx->iconv_handle;
2783 _PUBLIC_ char *lpcfg_tls_keyfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
2785 return lpcfg_private_path(mem_ctx, lp_ctx, lpcfg__tls_keyfile(lp_ctx));
2788 _PUBLIC_ char *lpcfg_tls_certfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
2790 return lpcfg_private_path(mem_ctx, lp_ctx, lpcfg__tls_certfile(lp_ctx));
2793 _PUBLIC_ char *lpcfg_tls_cafile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
2795 return lpcfg_private_path(mem_ctx, lp_ctx, lpcfg__tls_cafile(lp_ctx));
2798 _PUBLIC_ char *lpcfg_tls_crlfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
2800 return lpcfg_private_path(mem_ctx, lp_ctx, lpcfg__tls_crlfile(lp_ctx));
2803 _PUBLIC_ char *lpcfg_tls_dhpfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
2805 return lpcfg_private_path(mem_ctx, lp_ctx, lpcfg__tls_dhpfile(lp_ctx));
2808 struct gensec_settings *lpcfg_gensec_settings(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
2810 struct gensec_settings *settings = talloc_zero(mem_ctx, struct gensec_settings);
2811 if (settings == NULL)
2813 SMB_ASSERT(lp_ctx != NULL);
2814 settings->lp_ctx = talloc_reference(settings, lp_ctx);
2815 settings->target_hostname = lpcfg_parm_string(lp_ctx, NULL, "gensec", "target_hostname");
2819 int lpcfg_server_role(struct loadparm_context *lp_ctx)
2821 int domain_master = lpcfg__domain_master(lp_ctx);
2823 return lp_find_server_role(lpcfg__server_role(lp_ctx),
2824 lpcfg__security(lp_ctx),
2825 lpcfg__domain_logons(lp_ctx),
2826 (domain_master == true) ||
2827 (domain_master == Auto));
2830 int lpcfg_security(struct loadparm_context *lp_ctx)
2832 return lp_find_security(lpcfg__server_role(lp_ctx),
2833 lpcfg__security(lp_ctx));
2836 bool lpcfg_server_signing_allowed(struct loadparm_context *lp_ctx, bool *mandatory)
2838 bool allowed = true;
2839 enum smb_signing_setting signing_setting = lpcfg_server_signing(lp_ctx);
2843 if (signing_setting == SMB_SIGNING_DEFAULT) {
2845 * If we are a domain controller, SMB signing is
2846 * really important, as it can prevent a number of
2847 * attacks on communications between us and the
2850 * However, it really sucks (no sendfile, CPU
2851 * overhead) performance-wise when used on a
2852 * file server, so disable it by default
2856 if (lpcfg_server_role(lp_ctx) >= ROLE_ACTIVE_DIRECTORY_DC) {
2857 signing_setting = SMB_SIGNING_REQUIRED;
2859 signing_setting = SMB_SIGNING_OFF;
2863 switch (signing_setting) {
2864 case SMB_SIGNING_REQUIRED:
2867 case SMB_SIGNING_IF_REQUIRED:
2869 case SMB_SIGNING_DEFAULT:
2870 case SMB_SIGNING_OFF:
2878 int lpcfg_tdb_hash_size(struct loadparm_context *lp_ctx, const char *name)
2886 base = strrchr_m(name, '/');
2892 return lpcfg_parm_int(lp_ctx, NULL, "tdb_hashsize", base, 0);
2896 int lpcfg_tdb_flags(struct loadparm_context *lp_ctx, int tdb_flags)
2898 if (!lpcfg_use_mmap(lp_ctx)) {
2899 tdb_flags |= TDB_NOMMAP;