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 (num_parameters())
80 struct loadparm_service *lpcfg_default_service(struct loadparm_context *lp_ctx)
83 return lp_ctx->s3_fns->get_default_loadparm_service();
85 return lp_ctx->sDefault;
89 * Convenience routine to grab string parameters into temporary memory
90 * and run standard_sub_basic on them.
92 * The buffers can be written to by
93 * callers without affecting the source string.
96 static const char *lpcfg_string(const char *s)
98 #if 0 /* until REWRITE done to make thread-safe */
99 size_t len = s ? strlen(s) : 0;
103 /* The follow debug is useful for tracking down memory problems
104 especially if you have an inner loop that is calling a lp_*()
105 function that returns a string. Perhaps this debug should be
106 present all the time? */
109 DEBUG(10, ("lpcfg_string(%s)\n", s));
112 #if 0 /* until REWRITE done to make thread-safe */
114 lp_talloc = talloc_init("lp_talloc");
116 ret = talloc_array(lp_talloc, char, len + 100); /* leave room for substitution */
124 strlcpy(ret, s, len);
126 if (trim_string(ret, "\"", "\"")) {
127 if (strchr(ret,'"') != NULL)
128 strlcpy(ret, s, len);
131 standard_sub_basic(ret,len+100);
138 In this section all the functions that are used to access the
139 parameters from the rest of the program are defined
143 * the creation of separate lpcfg_*() and lp_*() functions is to allow
144 * for code compatibility between existing Samba4 and Samba3 code.
147 /* this global context supports the lp_*() function varients */
148 static struct loadparm_context *global_loadparm_context;
150 #define lpcfg_default_service global_loadparm_context->sDefault
151 #define lpcfg_global_service(i) global_loadparm_context->services[i]
153 #define FN_GLOBAL_STRING(fn_name,var_name) \
154 _PUBLIC_ char *lpcfg_ ## fn_name(struct loadparm_context *lp_ctx, TALLOC_CTX *ctx) {\
155 if (lp_ctx == NULL) return NULL; \
156 if (lp_ctx->s3_fns) { \
157 return lp_ctx->globals->var_name ? lp_ctx->s3_fns->lp_string(ctx, lp_ctx->globals->var_name) : talloc_strdup(ctx, ""); \
159 return lp_ctx->globals->var_name ? talloc_strdup(ctx, lpcfg_string(lp_ctx->globals->var_name)) : talloc_strdup(ctx, ""); \
162 #define FN_GLOBAL_CONST_STRING(fn_name,var_name) \
163 _PUBLIC_ const char *lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) { \
164 if (lp_ctx == NULL) return NULL; \
165 return lp_ctx->globals->var_name ? lpcfg_string(lp_ctx->globals->var_name) : ""; \
168 #define FN_GLOBAL_LIST(fn_name,var_name) \
169 _PUBLIC_ const char **lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) { \
170 if (lp_ctx == NULL) return NULL; \
171 return lp_ctx->globals->var_name; \
174 #define FN_GLOBAL_BOOL(fn_name,var_name) \
175 _PUBLIC_ bool lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) {\
176 if (lp_ctx == NULL) return false; \
177 return lp_ctx->globals->var_name; \
180 #define FN_GLOBAL_INTEGER(fn_name,var_name) \
181 _PUBLIC_ int lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) { \
182 return lp_ctx->globals->var_name; \
185 /* Local parameters don't need the ->s3_fns because the struct
186 * loadparm_service is shared and lpcfg_service() checks the ->s3_fns
188 #define FN_LOCAL_STRING(fn_name,val) \
189 _PUBLIC_ char *lpcfg_ ## fn_name(struct loadparm_service *service, \
190 struct loadparm_service *sDefault, TALLOC_CTX *ctx) { \
191 return(talloc_strdup(ctx, lpcfg_string((const char *)((service != NULL && service->val != NULL) ? service->val : sDefault->val)))); \
194 #define FN_LOCAL_CONST_STRING(fn_name,val) \
195 _PUBLIC_ const char *lpcfg_ ## fn_name(struct loadparm_service *service, \
196 struct loadparm_service *sDefault) { \
197 return((const char *)((service != NULL && service->val != NULL) ? service->val : sDefault->val)); \
200 #define FN_LOCAL_LIST(fn_name,val) \
201 _PUBLIC_ const char **lpcfg_ ## fn_name(struct loadparm_service *service, \
202 struct loadparm_service *sDefault) {\
203 return(const char **)(service != NULL && service->val != NULL? service->val : sDefault->val); \
206 #define FN_LOCAL_PARM_BOOL(fn_name, val) FN_LOCAL_BOOL(fn_name, val)
208 #define FN_LOCAL_BOOL(fn_name,val) \
209 _PUBLIC_ bool lpcfg_ ## fn_name(struct loadparm_service *service, \
210 struct loadparm_service *sDefault) { \
211 return((service != NULL)? service->val : sDefault->val); \
214 #define FN_LOCAL_INTEGER(fn_name,val) \
215 _PUBLIC_ int lpcfg_ ## fn_name(struct loadparm_service *service, \
216 struct loadparm_service *sDefault) { \
217 return((service != NULL)? service->val : sDefault->val); \
220 #define FN_LOCAL_PARM_INTEGER(fn_name, val) FN_LOCAL_INTEGER(fn_name, val)
222 #define FN_LOCAL_PARM_CHAR(fn_name,val) \
223 _PUBLIC_ char lpcfg_ ## fn_name(struct loadparm_service *service, \
224 struct loadparm_service *sDefault) { \
225 return((service != NULL)? service->val : sDefault->val); \
228 #include "lib/param/param_functions.c"
230 /* These functions cannot be auto-generated */
231 FN_LOCAL_BOOL(autoloaded, autoloaded)
232 FN_GLOBAL_CONST_STRING(dnsdomain, dnsdomain)
234 /* local prototypes */
235 static struct loadparm_service *lpcfg_getservicebyname(struct loadparm_context *lp_ctx,
236 const char *pszServiceName);
237 static bool lpcfg_service_ok(struct loadparm_service *service);
238 static bool do_section(const char *pszSectionName, void *);
240 /* This is a helper function for parametrical options support. */
241 /* It returns a pointer to parametrical option value if it exists or NULL otherwise */
242 /* Actual parametrical functions are quite simple */
243 const char *lpcfg_get_parametric(struct loadparm_context *lp_ctx,
244 struct loadparm_service *service,
245 const char *type, const char *option)
247 char *vfskey_tmp = NULL;
249 struct parmlist_entry *data;
254 if (lp_ctx->s3_fns) {
255 return lp_ctx->s3_fns->get_parametric(service, type, option, NULL);
258 data = (service == NULL ? lp_ctx->globals->param_opt : service->param_opt);
260 vfskey_tmp = talloc_asprintf(NULL, "%s:%s", type, option);
261 if (vfskey_tmp == NULL) return NULL;
262 vfskey = strlower_talloc(NULL, vfskey_tmp);
263 talloc_free(vfskey_tmp);
266 if (strcmp(data->key, vfskey) == 0) {
273 if (service != NULL) {
274 /* Try to fetch the same option but from globals */
275 /* but only if we are not already working with globals */
276 for (data = lp_ctx->globals->param_opt; data;
278 if (strcmp(data->key, vfskey) == 0) {
292 * convenience routine to return int parameters.
294 int lp_int(const char *s)
298 DEBUG(0,("lp_int(%s): is called with NULL!\n",s));
302 return strtol(s, NULL, 0);
306 * convenience routine to return unsigned long parameters.
308 unsigned long lp_ulong(const char *s)
312 DEBUG(0,("lp_ulong(%s): is called with NULL!\n",s));
316 return strtoul(s, NULL, 0);
320 * convenience routine to return unsigned long parameters.
322 static long lp_long(const char *s)
326 DEBUG(0,("lp_long(%s): is called with NULL!\n",s));
330 return strtol(s, NULL, 0);
334 * convenience routine to return unsigned long parameters.
336 static double lp_double(const char *s)
340 DEBUG(0,("lp_double(%s): is called with NULL!\n",s));
344 return strtod(s, NULL);
348 * convenience routine to return boolean parameters.
350 bool lp_bool(const char *s)
355 DEBUG(0,("lp_bool(%s): is called with NULL!\n",s));
359 if (!set_boolean(s, &ret)) {
360 DEBUG(0,("lp_bool(%s): value is not boolean!\n",s));
368 * Return parametric option from a given service. Type is a part of option before ':'
369 * Parametric option has following syntax: 'Type: option = value'
370 * Returned value is allocated in 'lp_talloc' context
373 const char *lpcfg_parm_string(struct loadparm_context *lp_ctx,
374 struct loadparm_service *service, const char *type,
377 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
380 return lpcfg_string(value);
386 * Return parametric option from a given service. Type is a part of option before ':'
387 * Parametric option has following syntax: 'Type: option = value'
388 * Returned value is allocated in 'lp_talloc' context
391 const char **lpcfg_parm_string_list(TALLOC_CTX *mem_ctx,
392 struct loadparm_context *lp_ctx,
393 struct loadparm_service *service,
395 const char *option, const char *separator)
397 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
400 return (const char **)str_list_make(mem_ctx, value, separator);
406 * Return parametric option from a given service. Type is a part of option before ':'
407 * Parametric option has following syntax: 'Type: option = value'
410 int lpcfg_parm_int(struct loadparm_context *lp_ctx,
411 struct loadparm_service *service, const char *type,
412 const char *option, int default_v)
414 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
417 return lp_int(value);
423 * Return parametric option from a given service. Type is a part of
425 * Parametric option has following syntax: 'Type: option = value'.
428 int lpcfg_parm_bytes(struct loadparm_context *lp_ctx,
429 struct loadparm_service *service, const char *type,
430 const char *option, int default_v)
434 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
436 if (value && conv_str_size_error(value, &bval)) {
437 if (bval <= INT_MAX) {
446 * Return parametric option from a given service.
447 * Type is a part of option before ':'
448 * Parametric option has following syntax: 'Type: option = value'
450 unsigned long lpcfg_parm_ulong(struct loadparm_context *lp_ctx,
451 struct loadparm_service *service, const char *type,
452 const char *option, unsigned long default_v)
454 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
457 return lp_ulong(value);
462 long lpcfg_parm_long(struct loadparm_context *lp_ctx,
463 struct loadparm_service *service, const char *type,
464 const char *option, long default_v)
466 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
469 return lp_long(value);
474 double lpcfg_parm_double(struct loadparm_context *lp_ctx,
475 struct loadparm_service *service, const char *type,
476 const char *option, double default_v)
478 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
481 return lp_double(value);
487 * Return parametric option from a given service. Type is a part of option before ':'
488 * Parametric option has following syntax: 'Type: option = value'
491 bool lpcfg_parm_bool(struct loadparm_context *lp_ctx,
492 struct loadparm_service *service, const char *type,
493 const char *option, bool default_v)
495 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
498 return lp_bool(value);
505 * Set a string value, deallocating any existing space, and allocing the space
508 bool lpcfg_string_set(TALLOC_CTX *mem_ctx, char **dest, const char *src)
515 *dest = talloc_strdup(mem_ctx, src);
516 if ((*dest) == NULL) {
517 DEBUG(0,("Out of memory in string_set\n"));
525 * Set a string value, deallocating any existing space, and allocing the space
528 static bool lpcfg_string_set_upper(TALLOC_CTX *mem_ctx, char **dest, const char *src)
535 *dest = strupper_talloc(mem_ctx, src);
536 if ((*dest) == NULL) {
537 DEBUG(0,("Out of memory in string_set_upper\n"));
547 * Add a new service to the services array initialising it with the given
551 struct loadparm_service *lpcfg_add_service(struct loadparm_context *lp_ctx,
552 const struct loadparm_service *pservice,
556 int num_to_alloc = lp_ctx->iNumServices + 1;
557 struct parmlist_entry *data, *pdata;
559 if (pservice == NULL) {
560 pservice = lp_ctx->sDefault;
563 /* it might already exist */
565 struct loadparm_service *service = lpcfg_getservicebyname(lp_ctx,
567 if (service != NULL) {
568 /* Clean all parametric options for service */
569 /* They will be added during parsing again */
570 data = service->param_opt;
576 service->param_opt = NULL;
581 /* find an invalid one */
582 for (i = 0; i < lp_ctx->iNumServices; i++)
583 if (lp_ctx->services[i] == NULL)
586 /* if not, then create one */
587 if (i == lp_ctx->iNumServices) {
588 struct loadparm_service **tsp;
590 tsp = talloc_realloc(lp_ctx, lp_ctx->services, struct loadparm_service *, num_to_alloc);
593 DEBUG(0,("lpcfg_add_service: failed to enlarge services!\n"));
596 lp_ctx->services = tsp;
597 lp_ctx->services[lp_ctx->iNumServices] = NULL;
600 lp_ctx->iNumServices++;
603 lp_ctx->services[i] = talloc_zero(lp_ctx->services, struct loadparm_service);
604 if (lp_ctx->services[i] == NULL) {
605 DEBUG(0,("lpcfg_add_service: out of memory!\n"));
608 copy_service(lp_ctx->services[i], pservice, NULL);
610 lpcfg_string_set(lp_ctx->services[i], &lp_ctx->services[i]->szService, name);
611 return lp_ctx->services[i];
615 * Add a new home service, with the specified home directory, defaults coming
616 * from service ifrom.
619 bool lpcfg_add_home(struct loadparm_context *lp_ctx,
620 const char *pszHomename,
621 struct loadparm_service *default_service,
622 const char *user, const char *pszHomedir)
624 struct loadparm_service *service;
626 service = lpcfg_add_service(lp_ctx, default_service, pszHomename);
631 if (!(*(default_service->path))
632 || strequal(default_service->path, lp_ctx->sDefault->path)) {
633 service->path = talloc_strdup(service, pszHomedir);
635 service->path = string_sub_talloc(service, lpcfg_path(default_service, lp_ctx->sDefault, service), "%H", pszHomedir);
638 if (!(*(service->comment))) {
639 service->comment = talloc_asprintf(service, "Home directory of %s", user);
641 service->bAvailable = default_service->bAvailable;
642 service->browseable = default_service->browseable;
644 DEBUG(3, ("adding home's share [%s] for user '%s' at '%s'\n",
645 pszHomename, user, service->path));
651 * Add a new printer service, with defaults coming from service iFrom.
654 bool lpcfg_add_printer(struct loadparm_context *lp_ctx,
655 const char *pszPrintername,
656 struct loadparm_service *default_service)
658 const char *comment = "From Printcap";
659 struct loadparm_service *service;
660 service = lpcfg_add_service(lp_ctx, default_service, pszPrintername);
665 /* note that we do NOT default the availability flag to True - */
666 /* we take it from the default service passed. This allows all */
667 /* dynamic printers to be disabled by disabling the [printers] */
668 /* entry (if/when the 'available' keyword is implemented!). */
670 /* the printer name is set to the service name. */
671 lpcfg_string_set(service, &service->_printername, pszPrintername);
672 lpcfg_string_set(service, &service->comment, comment);
673 service->browseable = default_service->browseable;
674 /* Printers cannot be read_only. */
675 service->read_only = false;
676 /* Printer services must be printable. */
677 service->printable = true;
679 DEBUG(3, ("adding printer service %s\n", pszPrintername));
685 * Map a parameter's string representation to something we can use.
686 * Returns False if the parameter string is not recognised, else TRUE.
689 int lpcfg_map_parameter(const char *pszParmName)
693 for (iIndex = 0; parm_table[iIndex].label; iIndex++)
694 if (strwicmp(parm_table[iIndex].label, pszParmName) == 0)
697 /* Warn only if it isn't parametric option */
698 if (strchr(pszParmName, ':') == NULL)
699 DEBUG(0, ("Unknown parameter encountered: \"%s\"\n", pszParmName));
700 /* We do return 'fail' for parametric options as well because they are
701 stored in different storage
708 return the parameter structure for a parameter
710 struct parm_struct *lpcfg_parm_struct(struct loadparm_context *lp_ctx, const char *name)
714 if (lp_ctx->s3_fns) {
715 return lp_ctx->s3_fns->get_parm_struct(name);
718 parmnum = lpcfg_map_parameter(name);
719 if (parmnum == -1) return NULL;
720 return &parm_table[parmnum];
724 return the parameter pointer for a parameter
726 void *lpcfg_parm_ptr(struct loadparm_context *lp_ctx,
727 struct loadparm_service *service, struct parm_struct *parm)
729 if (lp_ctx->s3_fns) {
730 return lp_ctx->s3_fns->get_parm_ptr(service, parm);
733 if (service == NULL) {
734 if (parm->p_class == P_LOCAL)
735 return ((char *)lp_ctx->sDefault)+parm->offset;
736 else if (parm->p_class == P_GLOBAL)
737 return ((char *)lp_ctx->globals)+parm->offset;
740 return ((char *)service) + parm->offset;
745 return the parameter pointer for a parameter
747 bool lpcfg_parm_is_cmdline(struct loadparm_context *lp_ctx, const char *name)
751 if (lp_ctx->s3_fns) {
752 struct parm_struct *parm = lp_ctx->s3_fns->get_parm_struct(name);
754 return parm->flags & FLAG_CMDLINE;
759 parmnum = lpcfg_map_parameter(name);
760 if (parmnum == -1) return false;
762 return lp_ctx->flags[parmnum] & FLAG_CMDLINE;
766 * Find a service by name. Otherwise works like get_service.
769 static struct loadparm_service *lpcfg_getservicebyname(struct loadparm_context *lp_ctx,
770 const char *pszServiceName)
774 if (lp_ctx->s3_fns) {
775 return lp_ctx->s3_fns->get_service(pszServiceName);
778 for (iService = lp_ctx->iNumServices - 1; iService >= 0; iService--)
779 if (lp_ctx->services[iService] != NULL &&
780 strwicmp(lp_ctx->services[iService]->szService, pszServiceName) == 0) {
781 return lp_ctx->services[iService];
788 * Add a parametric option to a parmlist_entry,
789 * replacing old value, if already present.
791 void set_param_opt(TALLOC_CTX *mem_ctx,
792 struct parmlist_entry **opt_list,
793 const char *opt_name,
794 const char *opt_value,
797 struct parmlist_entry *new_opt, *opt;
803 /* Traverse destination */
805 /* If we already have same option, override it */
806 if (strwicmp(opt->key, opt_name) == 0) {
807 if ((opt->priority & FLAG_CMDLINE) &&
808 !(priority & FLAG_CMDLINE)) {
809 /* it's been marked as not to be
813 TALLOC_FREE(opt->value);
814 TALLOC_FREE(opt->list);
815 opt->value = talloc_strdup(opt, opt_value);
816 opt->priority = priority;
823 new_opt = talloc(mem_ctx, struct parmlist_entry);
824 if (new_opt == NULL) {
828 new_opt->key = talloc_strdup(new_opt, opt_name);
829 if (new_opt->key == NULL) {
830 smb_panic("talloc_strdup failed");
833 new_opt->value = talloc_strdup(new_opt, opt_value);
834 if (new_opt->value == NULL) {
835 smb_panic("talloc_strdup failed");
838 new_opt->list = NULL;
839 new_opt->priority = priority;
840 DLIST_ADD(*opt_list, new_opt);
845 * Copy a service structure to another.
846 * If pcopymapDest is NULL then copy all fields
849 void copy_service(struct loadparm_service *pserviceDest,
850 const struct loadparm_service *pserviceSource,
851 struct bitmap *pcopymapDest)
854 bool bcopyall = (pcopymapDest == NULL);
855 struct parmlist_entry *data;
857 for (i = 0; parm_table[i].label; i++)
858 if (parm_table[i].p_class == P_LOCAL &&
859 (bcopyall || bitmap_query(pcopymapDest, i))) {
860 const void *src_ptr =
861 ((const char *)pserviceSource) + parm_table[i].offset;
863 ((char *)pserviceDest) + parm_table[i].offset;
865 switch (parm_table[i].type) {
868 *(bool *)dest_ptr = *(const bool *)src_ptr;
875 *(int *)dest_ptr = *(const int *)src_ptr;
879 *(char *)dest_ptr = *(const char *)src_ptr;
883 lpcfg_string_set(pserviceDest,
885 *(const char * const *)src_ptr);
889 lpcfg_string_set_upper(pserviceDest,
891 *(const char * const *)src_ptr);
894 TALLOC_FREE(*((char ***)dest_ptr));
895 *(const char * const **)dest_ptr = (const char * const *)str_list_copy(pserviceDest,
896 *(const char * * const *)src_ptr);
904 init_copymap(pserviceDest);
905 if (pserviceSource->copymap)
906 bitmap_copy(pserviceDest->copymap,
907 pserviceSource->copymap);
910 for (data = pserviceSource->param_opt; data != NULL; data = data->next) {
911 set_param_opt(pserviceDest, &pserviceDest->param_opt,
912 data->key, data->value, data->priority);
917 * Check a service for consistency. Return False if the service is in any way
918 * incomplete or faulty, else True.
920 static bool lpcfg_service_ok(struct loadparm_service *service)
925 if (service->szService[0] == '\0') {
926 DEBUG(0, ("The following message indicates an internal error:\n"));
927 DEBUG(0, ("No service name in service entry.\n"));
931 /* The [printers] entry MUST be printable. I'm all for flexibility, but */
932 /* I can't see why you'd want a non-printable printer service... */
933 if (strwicmp(service->szService, PRINTERS_NAME) == 0) {
934 if (!service->printable) {
935 DEBUG(0, ("WARNING: [%s] service MUST be printable!\n",
936 service->szService));
937 service->printable = true;
939 /* [printers] service must also be non-browsable. */
940 if (service->browseable)
941 service->browseable = false;
944 /* If a service is flagged unavailable, log the fact at level 0. */
945 if (!service->bAvailable)
946 DEBUG(1, ("NOTE: Service %s is flagged unavailable.\n",
947 service->szService));
953 /*******************************************************************
954 Keep a linked list of all config files so we know when one has changed
955 it's date and needs to be reloaded.
956 ********************************************************************/
958 void add_to_file_list(TALLOC_CTX *mem_ctx, struct file_lists **list,
959 const char *fname, const char *subfname)
961 struct file_lists *f = *list;
964 if (f->name && !strcmp(f->name, fname))
970 f = talloc(mem_ctx, struct file_lists);
974 f->name = talloc_strdup(f, fname);
979 f->subfname = talloc_strdup(f, subfname);
985 f->modtime = file_modtime(subfname);
987 time_t t = file_modtime(subfname);
994 DEBUG(0, ("Unable to add file to file list: %s\n", fname));
998 /*******************************************************************
999 Check if a config file has changed date.
1000 ********************************************************************/
1001 bool lpcfg_file_list_changed(struct loadparm_context *lp_ctx)
1003 struct file_lists *f;
1004 DEBUG(6, ("lpcfg_file_list_changed()\n"));
1006 for (f = lp_ctx->file_lists; f != NULL; f = f->next) {
1010 n2 = standard_sub_basic(lp_ctx, f->name);
1012 DEBUGADD(6, ("file %s -> %s last mod_time: %s\n",
1013 f->name, n2, ctime(&f->modtime)));
1015 mod_time = file_modtime(n2);
1017 if (mod_time && ((f->modtime != mod_time) || (f->subfname == NULL) || (strcmp(n2, f->subfname) != 0))) {
1018 DEBUGADD(6, ("file %s modified: %s\n", n2,
1020 f->modtime = mod_time;
1021 talloc_free(f->subfname);
1022 f->subfname = talloc_strdup(f, n2);
1030 * set the value for a P_ENUM
1032 bool lp_set_enum_parm( struct parm_struct *parm, const char *pszParmValue,
1037 for (i = 0; parm->enum_list[i].name; i++) {
1038 if ( strequal(pszParmValue, parm->enum_list[i].name)) {
1039 *ptr = parm->enum_list[i].value;
1043 DEBUG(0, ("WARNING: Ignoring invalid value '%s' for parameter '%s'\n",
1044 pszParmValue, parm->label));
1049 /***************************************************************************
1050 Handle the "realm" parameter
1051 ***************************************************************************/
1053 bool handle_realm(struct loadparm_context *lp_ctx, int unused,
1054 const char *pszParmValue, char **ptr)
1059 upper = strupper_talloc(lp_ctx, pszParmValue);
1060 if (upper == NULL) {
1064 lower = strlower_talloc(lp_ctx, pszParmValue);
1065 if (lower == NULL) {
1070 if (lp_ctx->s3_fns != NULL) {
1071 lp_ctx->s3_fns->lp_string_set(ptr, pszParmValue);
1072 lp_ctx->s3_fns->lp_string_set(&lp_ctx->globals->realm, upper);
1073 lp_ctx->s3_fns->lp_string_set(&lp_ctx->globals->dnsdomain, lower);
1075 lpcfg_string_set(lp_ctx, ptr, pszParmValue);
1076 lpcfg_string_set(lp_ctx, &lp_ctx->globals->realm, upper);
1077 lpcfg_string_set(lp_ctx, &lp_ctx->globals->dnsdomain, lower);
1083 /***************************************************************************
1084 Handle the include operation.
1085 ***************************************************************************/
1087 bool handle_include(struct loadparm_context *lp_ctx, int unused,
1088 const char *pszParmValue, char **ptr)
1092 if (lp_ctx->s3_fns) {
1093 return lp_ctx->s3_fns->lp_include(lp_ctx, unused, pszParmValue, ptr);
1096 fname = standard_sub_basic(lp_ctx, pszParmValue);
1098 add_to_file_list(lp_ctx, &lp_ctx->file_lists, pszParmValue, fname);
1100 lpcfg_string_set(lp_ctx, ptr, fname);
1102 if (file_exist(fname))
1103 return pm_process(fname, do_section, do_parameter, lp_ctx);
1105 DEBUG(2, ("Can't find include file %s\n", fname));
1110 /***************************************************************************
1111 Handle the interpretation of the copy parameter.
1112 ***************************************************************************/
1114 bool handle_copy(struct loadparm_context *lp_ctx, int snum,
1115 const char *pszParmValue, char **ptr)
1118 struct loadparm_service *serviceTemp = NULL;
1119 struct loadparm_service *current = NULL;
1123 DEBUG(3, ("Copying service from service %s\n", pszParmValue));
1125 serviceTemp = lpcfg_getservicebyname(lp_ctx, pszParmValue);
1126 if (lp_ctx->s3_fns != NULL) {
1127 current = lp_ctx->s3_fns->get_servicebynum(snum);
1129 current = lp_ctx->currentService;
1132 if (current == NULL) {
1133 DEBUG(0, ("Unable to copy service - invalid service destination"));
1137 if (serviceTemp != NULL) {
1138 if (serviceTemp == current) {
1139 DEBUG(0, ("Can't copy service %s - unable to copy self!\n", pszParmValue));
1141 copy_service(current,
1144 lpcfg_string_set(current, ptr, pszParmValue);
1149 DEBUG(0, ("Unable to copy service - source not found: %s\n",
1157 bool handle_debug_list(struct loadparm_context *lp_ctx, int unused,
1158 const char *pszParmValue, char **ptr)
1160 if (lp_ctx->s3_fns != NULL) {
1161 lp_ctx->s3_fns->lp_string_set(ptr, pszParmValue);
1163 lpcfg_string_set(lp_ctx, ptr, pszParmValue);
1166 return debug_parse_levels(pszParmValue);
1169 bool handle_logfile(struct loadparm_context *lp_ctx, int unused,
1170 const char *pszParmValue, char **ptr)
1172 if (lp_ctx->s3_fns != NULL) {
1173 lp_ctx->s3_fns->lp_string_set(ptr, pszParmValue);
1175 debug_set_logfile(pszParmValue);
1176 lpcfg_string_set(lp_ctx, ptr, pszParmValue);
1183 * These special charset handling methods only run in the source3 code.
1186 bool handle_charset(struct loadparm_context *lp_ctx, int snum,
1187 const char *pszParmValue, char **ptr)
1189 if (lp_ctx->s3_fns) {
1190 if (*ptr == NULL || strcmp(*ptr, pszParmValue) != 0) {
1191 lp_ctx->s3_fns->lp_string_set(ptr, pszParmValue);
1192 global_iconv_handle = smb_iconv_handle_reinit(NULL,
1193 lpcfg_dos_charset(lp_ctx),
1194 lpcfg_unix_charset(lp_ctx),
1195 true, global_iconv_handle);
1200 return lpcfg_string_set(lp_ctx, ptr, pszParmValue);
1204 bool handle_dos_charset(struct loadparm_context *lp_ctx, int snum,
1205 const char *pszParmValue, char **ptr)
1207 bool is_utf8 = false;
1208 size_t len = strlen(pszParmValue);
1210 if (lp_ctx->s3_fns) {
1211 if (len == 4 || len == 5) {
1212 /* Don't use StrCaseCmp here as we don't want to
1213 initialize iconv. */
1214 if ((toupper_m(pszParmValue[0]) == 'U') &&
1215 (toupper_m(pszParmValue[1]) == 'T') &&
1216 (toupper_m(pszParmValue[2]) == 'F')) {
1218 if (pszParmValue[3] == '8') {
1222 if (pszParmValue[3] == '-' &&
1223 pszParmValue[4] == '8') {
1230 if (*ptr == NULL || strcmp(*ptr, pszParmValue) != 0) {
1232 DEBUG(0,("ERROR: invalid DOS charset: 'dos charset' must not "
1233 "be UTF8, using (default value) %s instead.\n",
1234 DEFAULT_DOS_CHARSET));
1235 pszParmValue = DEFAULT_DOS_CHARSET;
1237 lp_ctx->s3_fns->lp_string_set(ptr, pszParmValue);
1238 global_iconv_handle = smb_iconv_handle_reinit(NULL,
1239 lpcfg_dos_charset(lp_ctx),
1240 lpcfg_unix_charset(lp_ctx),
1241 true, global_iconv_handle);
1246 return lpcfg_string_set(lp_ctx, ptr, pszParmValue);
1249 bool handle_printing(struct loadparm_context *lp_ctx, int snum,
1250 const char *pszParmValue, char **ptr)
1252 static int parm_num = -1;
1253 struct loadparm_service *s;
1255 if (parm_num == -1) {
1256 parm_num = lpcfg_map_parameter("printing");
1259 if (!lp_set_enum_parm(&parm_table[parm_num], pszParmValue, (int*)ptr)) {
1263 if (lp_ctx->s3_fns) {
1265 s = lp_ctx->sDefault;
1266 lp_ctx->s3_fns->init_printer_values(lp_ctx->globals->ctx, s);
1268 s = lp_ctx->services[snum];
1269 lp_ctx->s3_fns->init_printer_values(s, s);
1276 bool handle_ldap_debug_level(struct loadparm_context *lp_ctx, int snum, const char *pszParmValue, char **ptr)
1278 lp_ctx->globals->ldap_debug_level = lp_int(pszParmValue);
1280 if (lp_ctx->s3_fns) {
1281 lp_ctx->s3_fns->init_ldap_debugging();
1286 bool handle_netbios_aliases(struct loadparm_context *lp_ctx, int snum, const char *pszParmValue, char **ptr)
1288 TALLOC_FREE(lp_ctx->globals->netbios_aliases);
1289 lp_ctx->globals->netbios_aliases = (const char **)str_list_make_v3(lp_ctx->globals->ctx,
1290 pszParmValue, NULL);
1292 if (lp_ctx->s3_fns) {
1293 return lp_ctx->s3_fns->set_netbios_aliases(lp_ctx->globals->netbios_aliases);
1299 * idmap related parameters
1302 bool handle_idmap_backend(struct loadparm_context *lp_ctx, int snum, const char *pszParmValue, char **ptr)
1304 if (lp_ctx->s3_fns) {
1305 return lp_ctx->s3_fns->lp_do_parameter(snum, "idmap config * : backend", pszParmValue);
1308 return lpcfg_string_set(lp_ctx, ptr, pszParmValue);
1311 bool handle_idmap_uid(struct loadparm_context *lp_ctx, int snum, const char *pszParmValue, char **ptr)
1313 if (lp_ctx->s3_fns) {
1314 return lp_ctx->s3_fns->lp_do_parameter(snum, "idmap config * : range", pszParmValue);
1317 return lpcfg_string_set(lp_ctx, ptr, pszParmValue);
1320 bool handle_idmap_gid(struct loadparm_context *lp_ctx, int snum, const char *pszParmValue, char **ptr)
1322 if (lp_ctx->s3_fns) {
1323 return lp_ctx->s3_fns->lp_do_parameter(snum, "idmap config * : range", pszParmValue);
1326 return lpcfg_string_set(lp_ctx, ptr, pszParmValue);
1329 /***************************************************************************
1330 Initialise a copymap.
1331 ***************************************************************************/
1333 void init_copymap(struct loadparm_service *pservice)
1337 TALLOC_FREE(pservice->copymap);
1339 pservice->copymap = bitmap_talloc(NULL, NUMPARAMETERS);
1340 if (!pservice->copymap)
1342 ("Couldn't allocate copymap!! (size %d)\n",
1343 (int)NUMPARAMETERS));
1345 for (i = 0; i < NUMPARAMETERS; i++)
1346 bitmap_set(pservice->copymap, i);
1350 * Process a parametric option
1352 static bool lp_do_parameter_parametric(struct loadparm_context *lp_ctx,
1353 struct loadparm_service *service,
1354 const char *pszParmName,
1355 const char *pszParmValue, int flags)
1357 struct parmlist_entry **data;
1359 TALLOC_CTX *mem_ctx;
1361 while (isspace((unsigned char)*pszParmName)) {
1365 name = strlower_talloc(lp_ctx, pszParmName);
1366 if (!name) return false;
1368 if (service == NULL) {
1369 data = &lp_ctx->globals->param_opt;
1370 mem_ctx = lp_ctx->globals;
1372 data = &service->param_opt;
1376 set_param_opt(mem_ctx, data, name, pszParmValue, flags);
1383 static bool set_variable(TALLOC_CTX *mem_ctx, int parmnum, void *parm_ptr,
1384 const char *pszParmName, const char *pszParmValue,
1385 struct loadparm_context *lp_ctx, bool on_globals)
1388 /* if it is a special case then go ahead */
1389 if (parm_table[parmnum].special) {
1391 ret = parm_table[parmnum].special(lp_ctx, -1, pszParmValue,
1396 goto mark_non_default;
1399 /* now switch on the type of variable it is */
1400 switch (parm_table[parmnum].type)
1404 if (!set_boolean(pszParmValue, &b)) {
1405 DEBUG(0, ("set_variable(%s): value is not "
1406 "boolean!\n", pszParmValue));
1409 *(bool *)parm_ptr = b;
1415 if (!set_boolean(pszParmValue, &b)) {
1416 DEBUG(0, ("set_variable(%s): value is not "
1417 "boolean!\n", pszParmValue));
1420 *(bool *)parm_ptr = !b;
1425 *(int *)parm_ptr = atoi(pszParmValue);
1429 *(char *)parm_ptr = *pszParmValue;
1433 *(int *)parm_ptr = strtol(pszParmValue, NULL, 8);
1439 if (conv_str_size_error(pszParmValue, &val)) {
1440 if (val <= INT_MAX) {
1441 *(int *)parm_ptr = (int)val;
1446 DEBUG(0, ("set_variable(%s): value is not "
1447 "a valid size specifier!\n", pszParmValue));
1452 *(const char * const **)parm_ptr
1453 = (const char * const *)str_list_make(mem_ctx,
1454 pszParmValue, NULL);
1458 char **new_list = str_list_make(mem_ctx,
1459 pszParmValue, NULL);
1460 for (i=0; new_list[i]; i++) {
1461 if (*(const char ***)parm_ptr != NULL &&
1462 new_list[i][0] == '+' &&
1465 if (!str_list_check(*(const char ***)parm_ptr,
1467 *(const char ***)parm_ptr = str_list_add(*(const char ***)parm_ptr,
1470 } else if (*(const char ***)parm_ptr != NULL &&
1471 new_list[i][0] == '-' &&
1474 str_list_remove(*(const char ***)parm_ptr,
1478 DEBUG(0, ("Unsupported list syntax for: %s = %s\n",
1479 pszParmName, pszParmValue));
1482 *(const char * const **)parm_ptr = (const char * const *) new_list;
1489 lpcfg_string_set(mem_ctx, (char **)parm_ptr, pszParmValue);
1493 lpcfg_string_set_upper(mem_ctx, (char **)parm_ptr, pszParmValue);
1497 if (!lp_set_enum_parm(&parm_table[parmnum], pszParmValue, (int*)parm_ptr)) {
1507 if (on_globals && (lp_ctx->flags[parmnum] & FLAG_DEFAULT)) {
1508 lp_ctx->flags[parmnum] &= ~FLAG_DEFAULT;
1509 /* we have to also unset FLAG_DEFAULT on aliases */
1510 for (i=parmnum-1;i>=0 && parm_table[i].offset == parm_table[parmnum].offset;i--) {
1511 lp_ctx->flags[i] &= ~FLAG_DEFAULT;
1513 for (i=parmnum+1;i<NUMPARAMETERS && parm_table[i].offset == parm_table[parmnum].offset;i++) {
1514 lp_ctx->flags[i] &= ~FLAG_DEFAULT;
1521 bool lpcfg_do_global_parameter(struct loadparm_context *lp_ctx,
1522 const char *pszParmName, const char *pszParmValue)
1524 int parmnum = lpcfg_map_parameter(pszParmName);
1528 if (strchr(pszParmName, ':')) {
1529 return lp_do_parameter_parametric(lp_ctx, NULL, pszParmName, pszParmValue, 0);
1531 DEBUG(0, ("Ignoring unknown parameter \"%s\"\n", pszParmName));
1535 /* if the flag has been set on the command line, then don't allow override,
1536 but don't report an error */
1537 if (lp_ctx->flags[parmnum] & FLAG_CMDLINE) {
1541 parm_ptr = lpcfg_parm_ptr(lp_ctx, NULL, &parm_table[parmnum]);
1543 return set_variable(lp_ctx->globals, parmnum, parm_ptr,
1544 pszParmName, pszParmValue, lp_ctx, true);
1547 bool lpcfg_do_service_parameter(struct loadparm_context *lp_ctx,
1548 struct loadparm_service *service,
1549 const char *pszParmName, const char *pszParmValue)
1553 int parmnum = lpcfg_map_parameter(pszParmName);
1556 if (strchr(pszParmName, ':')) {
1557 return lp_do_parameter_parametric(lp_ctx, service, pszParmName, pszParmValue, 0);
1559 DEBUG(0, ("Ignoring unknown parameter \"%s\"\n", pszParmName));
1563 /* if the flag has been set on the command line, then don't allow override,
1564 but don't report an error */
1565 if (lp_ctx->flags[parmnum] & FLAG_CMDLINE) {
1569 if (parm_table[parmnum].p_class == P_GLOBAL) {
1571 ("Global parameter %s found in service section!\n",
1575 parm_ptr = ((char *)service) + parm_table[parmnum].offset;
1577 if (!service->copymap)
1578 init_copymap(service);
1580 /* this handles the aliases - set the copymap for other
1581 * entries with the same data pointer */
1582 for (i = 0; parm_table[i].label; i++)
1583 if (parm_table[i].offset == parm_table[parmnum].offset &&
1584 parm_table[i].p_class == parm_table[parmnum].p_class)
1585 bitmap_clear(service->copymap, i);
1587 return set_variable(service, parmnum, parm_ptr, pszParmName,
1588 pszParmValue, lp_ctx, false);
1592 * Process a parameter.
1595 static bool do_parameter(const char *pszParmName, const char *pszParmValue,
1598 struct loadparm_context *lp_ctx = (struct loadparm_context *)userdata;
1600 if (lp_ctx->bInGlobalSection)
1601 return lpcfg_do_global_parameter(lp_ctx, pszParmName,
1604 return lpcfg_do_service_parameter(lp_ctx, lp_ctx->currentService,
1605 pszParmName, pszParmValue);
1609 variable argument do parameter
1611 bool lpcfg_do_global_parameter_var(struct loadparm_context *lp_ctx, const char *pszParmName, const char *fmt, ...) PRINTF_ATTRIBUTE(3, 4);
1612 bool lpcfg_do_global_parameter_var(struct loadparm_context *lp_ctx,
1613 const char *pszParmName, const char *fmt, ...)
1620 s = talloc_vasprintf(NULL, fmt, ap);
1622 ret = lpcfg_do_global_parameter(lp_ctx, pszParmName, s);
1629 set a parameter from the commandline - this is called from command line parameter
1630 parsing code. It sets the parameter then marks the parameter as unable to be modified
1631 by smb.conf processing
1633 bool lpcfg_set_cmdline(struct loadparm_context *lp_ctx, const char *pszParmName,
1634 const char *pszParmValue)
1639 while (isspace((unsigned char)*pszParmValue)) pszParmValue++;
1641 if (lp_ctx->s3_fns) {
1642 return lp_ctx->s3_fns->set_cmdline(pszParmName, pszParmValue);
1645 parmnum = lpcfg_map_parameter(pszParmName);
1647 if (parmnum < 0 && strchr(pszParmName, ':')) {
1648 /* set a parametric option */
1649 return lp_do_parameter_parametric(lp_ctx, NULL, pszParmName,
1650 pszParmValue, FLAG_CMDLINE);
1654 DEBUG(0,("Unknown option '%s'\n", pszParmName));
1658 /* reset the CMDLINE flag in case this has been called before */
1659 lp_ctx->flags[parmnum] &= ~FLAG_CMDLINE;
1661 if (!lpcfg_do_global_parameter(lp_ctx, pszParmName, pszParmValue)) {
1665 lp_ctx->flags[parmnum] |= FLAG_CMDLINE;
1667 /* we have to also set FLAG_CMDLINE on aliases */
1669 i>=0 && parm_table[i].p_class == parm_table[parmnum].p_class &&
1670 parm_table[i].offset == parm_table[parmnum].offset;
1672 lp_ctx->flags[i] |= FLAG_CMDLINE;
1676 parm_table[i].p_class == parm_table[parmnum].p_class &&
1677 parm_table[i].offset == parm_table[parmnum].offset;
1679 lp_ctx->flags[i] |= FLAG_CMDLINE;
1686 set a option from the commandline in 'a=b' format. Use to support --option
1688 bool lpcfg_set_option(struct loadparm_context *lp_ctx, const char *option)
1693 s = talloc_strdup(NULL, option);
1706 ret = lpcfg_set_cmdline(lp_ctx, s, p+1);
1712 #define BOOLSTR(b) ((b) ? "Yes" : "No")
1715 * Print a parameter of the specified type.
1718 void lpcfg_print_parameter(struct parm_struct *p, void *ptr, FILE * f)
1720 /* For the seperation of lists values that we print below */
1721 const char *list_sep = ", ";
1726 for (i = 0; p->enum_list[i].name; i++) {
1727 if (*(int *)ptr == p->enum_list[i].value) {
1729 p->enum_list[i].name);
1736 fprintf(f, "%s", BOOLSTR(*(bool *)ptr));
1740 fprintf(f, "%s", BOOLSTR(!*(bool *)ptr));
1745 fprintf(f, "%d", *(int *)ptr);
1749 fprintf(f, "%c", *(char *)ptr);
1753 int val = *(int *)ptr;
1757 fprintf(f, "0%03o", val);
1766 if ((char ***)ptr && *(char ***)ptr) {
1767 char **list = *(char ***)ptr;
1768 for (; *list; list++) {
1769 /* surround strings with whitespace in double quotes */
1770 if (*(list+1) == NULL) {
1771 /* last item, no extra separator */
1774 if ( strchr_m( *list, ' ' ) ) {
1775 fprintf(f, "\"%s\"%s", *list, list_sep);
1777 fprintf(f, "%s%s", *list, list_sep);
1785 if (*(char **)ptr) {
1786 fprintf(f, "%s", *(char **)ptr);
1795 * Check if two parameters are equal.
1798 bool lpcfg_equal_parameter(parm_type type, void *ptr1, void *ptr2)
1803 return (*((bool *)ptr1) == *((bool *)ptr2));
1809 return (*((int *)ptr1) == *((int *)ptr2));
1812 return (*((char *)ptr1) == *((char *)ptr2));
1816 return str_list_equal(*(const char ***)ptr1, *(const char ***)ptr2);
1821 char *p1 = *(char **)ptr1, *p2 = *(char **)ptr2;
1826 return (p1 == p2 || strequal(p1, p2));
1835 * Process a new section (service).
1837 * At this stage all sections are services.
1838 * Later we'll have special sections that permit server parameters to be set.
1839 * Returns True on success, False on failure.
1842 static bool do_section(const char *pszSectionName, void *userdata)
1844 struct loadparm_context *lp_ctx = (struct loadparm_context *)userdata;
1846 bool isglobal = ((strwicmp(pszSectionName, GLOBAL_NAME) == 0) ||
1847 (strwicmp(pszSectionName, GLOBAL_NAME2) == 0));
1850 /* if we've just struck a global section, note the fact. */
1851 lp_ctx->bInGlobalSection = isglobal;
1853 /* check for multiple global sections */
1854 if (lp_ctx->bInGlobalSection) {
1855 DEBUG(4, ("Processing section \"[%s]\"\n", pszSectionName));
1859 /* if we have a current service, tidy it up before moving on */
1862 if (lp_ctx->currentService != NULL)
1863 bRetval = lpcfg_service_ok(lp_ctx->currentService);
1865 /* if all is still well, move to the next record in the services array */
1867 /* We put this here to avoid an odd message order if messages are */
1868 /* issued by the post-processing of a previous section. */
1869 DEBUG(4, ("Processing section \"[%s]\"\n", pszSectionName));
1871 if ((lp_ctx->currentService = lpcfg_add_service(lp_ctx, lp_ctx->sDefault,
1874 DEBUG(0, ("Failed to add a new service\n"));
1884 * Determine if a particular base parameter is currently set to the default value.
1887 static bool is_default(struct loadparm_service *sDefault, int i)
1889 void *def_ptr = ((char *)sDefault) + parm_table[i].offset;
1890 switch (parm_table[i].type) {
1893 return str_list_equal((const char * const *)parm_table[i].def.lvalue,
1894 (const char **)def_ptr);
1897 return strequal(parm_table[i].def.svalue,
1901 return parm_table[i].def.bvalue ==
1908 return parm_table[i].def.ivalue ==
1917 *Display the contents of the global structure.
1920 static void dump_globals(struct loadparm_context *lp_ctx, FILE *f,
1924 struct parmlist_entry *data;
1926 fprintf(f, "# Global parameters\n[global]\n");
1928 for (i = 0; parm_table[i].label; i++)
1929 if (parm_table[i].p_class == P_GLOBAL &&
1930 (i == 0 || (parm_table[i].offset != parm_table[i - 1].offset))) {
1931 if (!show_defaults && (lp_ctx->flags[i] & FLAG_DEFAULT))
1933 fprintf(f, "\t%s = ", parm_table[i].label);
1934 lpcfg_print_parameter(&parm_table[i], lpcfg_parm_ptr(lp_ctx, NULL, &parm_table[i]), f);
1937 if (lp_ctx->globals->param_opt != NULL) {
1938 for (data = lp_ctx->globals->param_opt; data;
1939 data = data->next) {
1940 if (!show_defaults && (data->priority & FLAG_DEFAULT)) {
1943 fprintf(f, "\t%s = %s\n", data->key, data->value);
1950 * Display the contents of a single services record.
1953 static void dump_a_service(struct loadparm_service * pService, struct loadparm_service *sDefault, FILE * f,
1954 unsigned int *flags)
1957 struct parmlist_entry *data;
1959 if (pService != sDefault)
1960 fprintf(f, "\n[%s]\n", pService->szService);
1962 for (i = 0; parm_table[i].label; i++) {
1963 if (parm_table[i].p_class == P_LOCAL &&
1964 (*parm_table[i].label != '-') &&
1965 (i == 0 || (parm_table[i].offset != parm_table[i - 1].offset)))
1967 if (pService == sDefault) {
1968 if (flags && (flags[i] & FLAG_DEFAULT)) {
1971 if (defaults_saved) {
1972 if (is_default(sDefault, i)) {
1977 if (lpcfg_equal_parameter(parm_table[i].type,
1978 ((char *)pService) +
1979 parm_table[i].offset,
1980 ((char *)sDefault) +
1981 parm_table[i].offset))
1985 fprintf(f, "\t%s = ", parm_table[i].label);
1986 lpcfg_print_parameter(&parm_table[i],
1987 ((char *)pService) + parm_table[i].offset, f);
1991 if (pService->param_opt != NULL) {
1992 for (data = pService->param_opt; data; data = data->next) {
1993 fprintf(f, "\t%s = %s\n", data->key, data->value);
1998 bool lpcfg_dump_a_parameter(struct loadparm_context *lp_ctx,
1999 struct loadparm_service *service,
2000 const char *parm_name, FILE * f)
2002 struct parm_struct *parm;
2005 parm = lpcfg_parm_struct(lp_ctx, parm_name);
2010 if (service != NULL && parm->p_class == P_GLOBAL) {
2014 ptr = lpcfg_parm_ptr(lp_ctx, service,parm);
2016 lpcfg_print_parameter(parm, ptr, f);
2022 * Auto-load some home services.
2024 static void lpcfg_add_auto_services(struct loadparm_context *lp_ctx,
2032 * Unload unused services.
2035 void lpcfg_killunused(struct loadparm_context *lp_ctx,
2036 struct smbsrv_connection *smb,
2037 bool (*snumused) (struct smbsrv_connection *, int))
2040 for (i = 0; i < lp_ctx->iNumServices; i++) {
2041 if (lp_ctx->services[i] == NULL)
2044 if (!snumused || !snumused(smb, i)) {
2045 talloc_free(lp_ctx->services[i]);
2046 lp_ctx->services[i] = NULL;
2052 static int lpcfg_destructor(struct loadparm_context *lp_ctx)
2054 struct parmlist_entry *data;
2056 if (lp_ctx->refuse_free) {
2057 /* someone is trying to free the
2058 global_loadparm_context.
2059 We can't allow that. */
2063 if (lp_ctx->globals->param_opt != NULL) {
2064 struct parmlist_entry *next;
2065 for (data = lp_ctx->globals->param_opt; data; data=next) {
2067 if (data->priority & FLAG_CMDLINE) continue;
2068 DLIST_REMOVE(lp_ctx->globals->param_opt, data);
2077 * Initialise the global parameter structure.
2079 * Note that most callers should use loadparm_init_global() instead
2081 struct loadparm_context *loadparm_init(TALLOC_CTX *mem_ctx)
2085 struct loadparm_context *lp_ctx;
2086 struct parmlist_entry *parm;
2089 lp_ctx = talloc_zero(mem_ctx, struct loadparm_context);
2093 talloc_set_destructor(lp_ctx, lpcfg_destructor);
2094 lp_ctx->bInGlobalSection = true;
2095 lp_ctx->globals = talloc_zero(lp_ctx, struct loadparm_global);
2096 /* This appears odd, but globals in s3 isn't a pointer */
2097 lp_ctx->globals->ctx = lp_ctx->globals;
2098 lp_ctx->sDefault = talloc_zero(lp_ctx, struct loadparm_service);
2099 lp_ctx->flags = talloc_zero_array(lp_ctx, unsigned int, NUMPARAMETERS);
2101 lp_ctx->sDefault->iMaxPrintJobs = 1000;
2102 lp_ctx->sDefault->bAvailable = true;
2103 lp_ctx->sDefault->browseable = true;
2104 lp_ctx->sDefault->read_only = true;
2105 lp_ctx->sDefault->map_archive = true;
2106 lp_ctx->sDefault->strict_locking = true;
2107 lp_ctx->sDefault->oplocks = true;
2108 lp_ctx->sDefault->create_mask = 0744;
2109 lp_ctx->sDefault->force_create_mode = 0000;
2110 lp_ctx->sDefault->directory_mask = 0755;
2111 lp_ctx->sDefault->force_directory_mode = 0000;
2113 DEBUG(3, ("Initialising global parameters\n"));
2115 for (i = 0; parm_table[i].label; i++) {
2116 if ((parm_table[i].type == P_STRING ||
2117 parm_table[i].type == P_USTRING) &&
2118 !(lp_ctx->flags[i] & FLAG_CMDLINE)) {
2120 if (parm_table[i].p_class == P_LOCAL) {
2121 r = (char **)(((char *)lp_ctx->sDefault) + parm_table[i].offset);
2123 r = (char **)(((char *)lp_ctx->globals) + parm_table[i].offset);
2125 *r = talloc_strdup(lp_ctx, "");
2129 logfile = talloc_asprintf(lp_ctx, "%s/log.samba", dyn_LOGFILEBASE);
2130 lpcfg_do_global_parameter(lp_ctx, "log file", logfile);
2131 talloc_free(logfile);
2133 lpcfg_do_global_parameter(lp_ctx, "log level", "0");
2135 lpcfg_do_global_parameter(lp_ctx, "syslog", "1");
2136 lpcfg_do_global_parameter(lp_ctx, "syslog only", "No");
2137 lpcfg_do_global_parameter(lp_ctx, "debug timestamp", "Yes");
2138 lpcfg_do_global_parameter(lp_ctx, "debug prefix timestamp", "No");
2139 lpcfg_do_global_parameter(lp_ctx, "debug hires timestamp", "Yes");
2140 lpcfg_do_global_parameter(lp_ctx, "debug pid", "No");
2141 lpcfg_do_global_parameter(lp_ctx, "debug uid", "No");
2142 lpcfg_do_global_parameter(lp_ctx, "debug class", "No");
2144 lpcfg_do_global_parameter(lp_ctx, "share backend", "classic");
2146 lpcfg_do_global_parameter(lp_ctx, "server role", "auto");
2147 lpcfg_do_global_parameter(lp_ctx, "domain logons", "No");
2148 lpcfg_do_global_parameter(lp_ctx, "domain master", "Auto");
2150 /* options that can be set on the command line must be initialised via
2151 the slower lpcfg_do_global_parameter() to ensure that FLAG_CMDLINE is obeyed */
2153 lpcfg_do_global_parameter(lp_ctx, "socket options", "TCP_NODELAY");
2155 lpcfg_do_global_parameter(lp_ctx, "workgroup", DEFAULT_WORKGROUP);
2156 myname = get_myname(lp_ctx);
2157 lpcfg_do_global_parameter(lp_ctx, "netbios name", myname);
2158 talloc_free(myname);
2159 lpcfg_do_global_parameter(lp_ctx, "name resolve order", "lmhosts wins host bcast");
2161 lpcfg_do_global_parameter(lp_ctx, "fstype", "NTFS");
2163 lpcfg_do_global_parameter(lp_ctx, "ntvfs handler", "unixuid default");
2164 lpcfg_do_global_parameter(lp_ctx, "max connections", "0");
2166 lpcfg_do_global_parameter(lp_ctx, "dcerpc endpoint servers", "epmapper wkssvc rpcecho samr netlogon lsarpc spoolss drsuapi dssetup unixinfo browser eventlog6 backupkey dnsserver");
2167 lpcfg_do_global_parameter(lp_ctx, "server services", "s3fs rpc nbt wrepl ldap cldap kdc drepl winbind ntp_signd kcc dnsupdate dns");
2168 lpcfg_do_global_parameter(lp_ctx, "kccsrv:samba_kcc", "true");
2169 /* the winbind method for domain controllers is for both RODC
2170 auth forwarding and for trusted domains */
2171 lpcfg_do_global_parameter(lp_ctx, "private dir", dyn_PRIVATE_DIR);
2172 lpcfg_do_global_parameter(lp_ctx, "registry:HKEY_LOCAL_MACHINE", "hklm.ldb");
2174 /* This hive should be dynamically generated by Samba using
2175 data from the sam, but for the moment leave it in a tdb to
2176 keep regedt32 from popping up an annoying dialog. */
2177 lpcfg_do_global_parameter(lp_ctx, "registry:HKEY_USERS", "hku.ldb");
2179 /* using UTF8 by default allows us to support all chars */
2180 lpcfg_do_global_parameter(lp_ctx, "unix charset", "UTF-8");
2182 /* Use codepage 850 as a default for the dos character set */
2183 lpcfg_do_global_parameter(lp_ctx, "dos charset", "CP850");
2186 * Allow the default PASSWD_CHAT to be overridden in local.h.
2188 lpcfg_do_global_parameter(lp_ctx, "passwd chat", DEFAULT_PASSWD_CHAT);
2190 lpcfg_do_global_parameter(lp_ctx, "pid directory", dyn_PIDDIR);
2191 lpcfg_do_global_parameter(lp_ctx, "lock dir", dyn_LOCKDIR);
2192 lpcfg_do_global_parameter(lp_ctx, "state directory", dyn_STATEDIR);
2193 lpcfg_do_global_parameter(lp_ctx, "cache directory", dyn_CACHEDIR);
2194 lpcfg_do_global_parameter(lp_ctx, "ncalrpc dir", dyn_NCALRPCDIR);
2196 lpcfg_do_global_parameter(lp_ctx, "nbt client socket address", "0.0.0.0");
2197 lpcfg_do_global_parameter_var(lp_ctx, "server string",
2198 "Samba %s", SAMBA_VERSION_STRING);
2200 lpcfg_do_global_parameter(lp_ctx, "password server", "*");
2202 lpcfg_do_global_parameter(lp_ctx, "max mux", "50");
2203 lpcfg_do_global_parameter(lp_ctx, "max xmit", "16644");
2204 lpcfg_do_global_parameter(lp_ctx, "host msdfs", "true");
2206 lpcfg_do_global_parameter(lp_ctx, "LargeReadwrite", "True");
2207 lpcfg_do_global_parameter(lp_ctx, "server min protocol", "LANMAN1");
2208 lpcfg_do_global_parameter(lp_ctx, "server max protocol", "SMB3");
2209 lpcfg_do_global_parameter(lp_ctx, "client min protocol", "CORE");
2210 lpcfg_do_global_parameter(lp_ctx, "client max protocol", "NT1");
2211 lpcfg_do_global_parameter(lp_ctx, "security", "AUTO");
2212 lpcfg_do_global_parameter(lp_ctx, "EncryptPasswords", "True");
2213 lpcfg_do_global_parameter(lp_ctx, "ReadRaw", "True");
2214 lpcfg_do_global_parameter(lp_ctx, "WriteRaw", "True");
2215 lpcfg_do_global_parameter(lp_ctx, "NullPasswords", "False");
2216 lpcfg_do_global_parameter(lp_ctx, "old password allowed period", "60");
2217 lpcfg_do_global_parameter(lp_ctx, "ObeyPamRestrictions", "False");
2219 lpcfg_do_global_parameter(lp_ctx, "TimeServer", "False");
2220 lpcfg_do_global_parameter(lp_ctx, "BindInterfacesOnly", "False");
2221 lpcfg_do_global_parameter(lp_ctx, "Unicode", "True");
2222 lpcfg_do_global_parameter(lp_ctx, "ClientLanManAuth", "False");
2223 lpcfg_do_global_parameter(lp_ctx, "ClientNTLMv2Auth", "True");
2224 lpcfg_do_global_parameter(lp_ctx, "LanmanAuth", "False");
2225 lpcfg_do_global_parameter(lp_ctx, "NTLMAuth", "True");
2226 lpcfg_do_global_parameter(lp_ctx, "client use spnego principal", "False");
2228 lpcfg_do_global_parameter(lp_ctx, "UnixExtensions", "True");
2230 lpcfg_do_global_parameter(lp_ctx, "PreferredMaster", "Auto");
2231 lpcfg_do_global_parameter(lp_ctx, "LocalMaster", "True");
2233 lpcfg_do_global_parameter(lp_ctx, "wins support", "False");
2234 lpcfg_do_global_parameter(lp_ctx, "dns proxy", "True");
2236 lpcfg_do_global_parameter(lp_ctx, "winbind separator", "\\");
2237 lpcfg_do_global_parameter(lp_ctx, "winbind sealed pipes", "True");
2238 lpcfg_do_global_parameter(lp_ctx, "require strong key", "True");
2239 lpcfg_do_global_parameter(lp_ctx, "winbindd socket directory", dyn_WINBINDD_SOCKET_DIR);
2240 lpcfg_do_global_parameter(lp_ctx, "winbindd privileged socket directory", dyn_WINBINDD_PRIVILEGED_SOCKET_DIR);
2241 lpcfg_do_global_parameter(lp_ctx, "ntp signd socket directory", dyn_NTP_SIGND_SOCKET_DIR);
2242 lpcfg_do_global_parameter_var(lp_ctx, "dns update command", "%s/samba_dnsupdate", dyn_SCRIPTSBINDIR);
2243 lpcfg_do_global_parameter_var(lp_ctx, "spn update command", "%s/samba_spnupdate", dyn_SCRIPTSBINDIR);
2244 lpcfg_do_global_parameter_var(lp_ctx, "samba kcc command",
2245 "%s/samba_kcc", dyn_SCRIPTSBINDIR);
2246 lpcfg_do_global_parameter(lp_ctx, "template shell", "/bin/false");
2247 lpcfg_do_global_parameter(lp_ctx, "template homedir", "/home/%WORKGROUP%/%ACCOUNTNAME%");
2249 lpcfg_do_global_parameter(lp_ctx, "client signing", "default");
2250 lpcfg_do_global_parameter(lp_ctx, "server signing", "default");
2252 lpcfg_do_global_parameter(lp_ctx, "use spnego", "True");
2254 lpcfg_do_global_parameter(lp_ctx, "use mmap", "True");
2256 lpcfg_do_global_parameter(lp_ctx, "smb ports", "445 139");
2257 lpcfg_do_global_parameter(lp_ctx, "nbt port", "137");
2258 lpcfg_do_global_parameter(lp_ctx, "dgram port", "138");
2259 lpcfg_do_global_parameter(lp_ctx, "cldap port", "389");
2260 lpcfg_do_global_parameter(lp_ctx, "krb5 port", "88");
2261 lpcfg_do_global_parameter(lp_ctx, "kpasswd port", "464");
2262 lpcfg_do_global_parameter(lp_ctx, "web port", "901");
2264 lpcfg_do_global_parameter(lp_ctx, "nt status support", "True");
2266 lpcfg_do_global_parameter(lp_ctx, "max wins ttl", "518400"); /* 6 days */
2267 lpcfg_do_global_parameter(lp_ctx, "min wins ttl", "21600");
2269 lpcfg_do_global_parameter(lp_ctx, "tls enabled", "True");
2270 lpcfg_do_global_parameter(lp_ctx, "tls keyfile", "tls/key.pem");
2271 lpcfg_do_global_parameter(lp_ctx, "tls certfile", "tls/cert.pem");
2272 lpcfg_do_global_parameter(lp_ctx, "tls cafile", "tls/ca.pem");
2273 lpcfg_do_global_parameter(lp_ctx, "prefork children:smb", "4");
2275 lpcfg_do_global_parameter(lp_ctx, "rndc command", "/usr/sbin/rndc");
2276 lpcfg_do_global_parameter(lp_ctx, "nsupdate command", "/usr/bin/nsupdate -g");
2278 lpcfg_do_global_parameter(lp_ctx, "allow dns updates", "secure only");
2279 lpcfg_do_global_parameter(lp_ctx, "dns forwarder", "");
2281 lpcfg_do_global_parameter(lp_ctx, "algorithmic rid base", "1000");
2283 lpcfg_do_global_parameter(lp_ctx, "enhanced browsing", "True");
2285 lpcfg_do_global_parameter(lp_ctx, "winbind nss info", "template");
2287 lpcfg_do_global_parameter(lp_ctx, "server schannel", "Auto");
2289 lpcfg_do_global_parameter(lp_ctx, "short preserve case", "True");
2291 lpcfg_do_global_parameter(lp_ctx, "max open files", "16384");
2293 lpcfg_do_global_parameter(lp_ctx, "cups connection timeout", "30");
2295 lpcfg_do_global_parameter(lp_ctx, "locking", "True");
2297 lpcfg_do_global_parameter(lp_ctx, "block size", "1024");
2299 lpcfg_do_global_parameter(lp_ctx, "client use spnego", "True");
2301 lpcfg_do_global_parameter(lp_ctx, "change notify", "True");
2303 lpcfg_do_global_parameter(lp_ctx, "name cache timeout", "660");
2305 lpcfg_do_global_parameter(lp_ctx, "defer sharing violations", "True");
2307 lpcfg_do_global_parameter(lp_ctx, "ldap replication sleep", "1000");
2309 lpcfg_do_global_parameter(lp_ctx, "idmap backend", "tdb");
2311 lpcfg_do_global_parameter(lp_ctx, "enable privileges", "True");
2313 lpcfg_do_global_parameter_var(lp_ctx, "smb2 max write", "%u", DEFAULT_SMB2_MAX_WRITE);
2315 lpcfg_do_global_parameter(lp_ctx, "passdb backend", "tdbsam");
2317 lpcfg_do_global_parameter(lp_ctx, "getwd cache", "True");
2319 lpcfg_do_global_parameter(lp_ctx, "winbind nested groups", "True");
2321 lpcfg_do_global_parameter(lp_ctx, "mangled names", "True");
2323 lpcfg_do_global_parameter_var(lp_ctx, "smb2 max credits", "%u", DEFAULT_SMB2_MAX_CREDITS);
2325 lpcfg_do_global_parameter(lp_ctx, "ldap ssl", "start tls");
2327 lpcfg_do_global_parameter(lp_ctx, "ldap deref", "auto");
2329 lpcfg_do_global_parameter(lp_ctx, "lm interval", "60");
2331 lpcfg_do_global_parameter(lp_ctx, "mangling method", "hash2");
2333 lpcfg_do_global_parameter(lp_ctx, "hide dot files", "True");
2335 lpcfg_do_global_parameter(lp_ctx, "browse list", "True");
2337 lpcfg_do_global_parameter(lp_ctx, "passwd chat timeout", "2");
2339 lpcfg_do_global_parameter(lp_ctx, "guest account", GUEST_ACCOUNT);
2341 lpcfg_do_global_parameter(lp_ctx, "client schannel", "auto");
2343 lpcfg_do_global_parameter(lp_ctx, "smb encrypt", "default");
2345 lpcfg_do_global_parameter(lp_ctx, "max log size", "5000");
2347 lpcfg_do_global_parameter(lp_ctx, "idmap negative cache time", "120");
2349 lpcfg_do_global_parameter(lp_ctx, "ldap follow referral", "auto");
2351 lpcfg_do_global_parameter(lp_ctx, "multicast dns register", "yes");
2353 lpcfg_do_global_parameter(lp_ctx, "winbind reconnect delay", "30");
2355 lpcfg_do_global_parameter(lp_ctx, "nt acl support", "yes");
2357 lpcfg_do_global_parameter(lp_ctx, "acl check permissions", "yes");
2359 lpcfg_do_global_parameter(lp_ctx, "keepalive", "300");
2361 lpcfg_do_global_parameter(lp_ctx, "winbind cache time", "300");
2363 lpcfg_do_global_parameter(lp_ctx, "level2 oplocks", "yes");
2365 lpcfg_do_global_parameter(lp_ctx, "show add printer wizard", "yes");
2367 lpcfg_do_global_parameter(lp_ctx, "allocation roundup size", "1048576");
2369 lpcfg_do_global_parameter(lp_ctx, "ldap page size", "1024");
2371 lpcfg_do_global_parameter(lp_ctx, "kernel share modes", "yes");
2373 lpcfg_do_global_parameter(lp_ctx, "strict locking", "Auto");
2375 lpcfg_do_global_parameter(lp_ctx, "map readonly", "yes");
2377 lpcfg_do_global_parameter(lp_ctx, "allow trusted domains", "yes");
2379 lpcfg_do_global_parameter(lp_ctx, "default devmode", "yes");
2381 lpcfg_do_global_parameter(lp_ctx, "os level", "20");
2383 lpcfg_do_global_parameter(lp_ctx, "dos filetimes", "yes");
2385 lpcfg_do_global_parameter(lp_ctx, "mangling char", "~");
2387 lpcfg_do_global_parameter(lp_ctx, "printcap cache time", "750");
2389 lpcfg_do_global_parameter(lp_ctx, "create krb5 conf", "yes");
2391 lpcfg_do_global_parameter(lp_ctx, "winbind max clients", "200");
2393 lpcfg_do_global_parameter(lp_ctx, "acl map full control", "yes");
2395 lpcfg_do_global_parameter(lp_ctx, "nt pipe support", "yes");
2397 lpcfg_do_global_parameter(lp_ctx, "ldap debug threshold", "10");
2399 lpcfg_do_global_parameter(lp_ctx, "follow symlinks", "yes");
2401 lpcfg_do_global_parameter(lp_ctx, "machine password timeout", "604800");
2403 lpcfg_do_global_parameter(lp_ctx, "ldap connection timeout", "2");
2405 lpcfg_do_global_parameter(lp_ctx, "winbind expand groups", "1");
2407 lpcfg_do_global_parameter(lp_ctx, "stat cache", "yes");
2409 lpcfg_do_global_parameter(lp_ctx, "lpq cache time", "30");
2411 lpcfg_do_global_parameter_var(lp_ctx, "smb2 max trans", "%u", DEFAULT_SMB2_MAX_TRANSACT);
2413 lpcfg_do_global_parameter_var(lp_ctx, "smb2 max read", "%u", DEFAULT_SMB2_MAX_READ);
2415 lpcfg_do_global_parameter(lp_ctx, "durable handles", "yes");
2417 lpcfg_do_global_parameter(lp_ctx, "max stat cache size", "256");
2419 lpcfg_do_global_parameter(lp_ctx, "ldap passwd sync", "no");
2421 lpcfg_do_global_parameter(lp_ctx, "kernel change notify", "yes");
2423 lpcfg_do_global_parameter(lp_ctx, "max ttl", "259200");
2425 lpcfg_do_global_parameter(lp_ctx, "blocking locks", "yes");
2427 lpcfg_do_global_parameter(lp_ctx, "oplock contention limit", "2");
2429 lpcfg_do_global_parameter(lp_ctx, "load printers", "yes");
2431 lpcfg_do_global_parameter(lp_ctx, "idmap cache time", "604800");
2433 lpcfg_do_global_parameter(lp_ctx, "preserve case", "yes");
2435 lpcfg_do_global_parameter(lp_ctx, "lm announce", "auto");
2437 lpcfg_do_global_parameter(lp_ctx, "afs token lifetime", "604800");
2439 lpcfg_do_global_parameter(lp_ctx, "enable core files", "yes");
2441 lpcfg_do_global_parameter(lp_ctx, "winbind max domain connections", "1");
2443 lpcfg_do_global_parameter(lp_ctx, "case sensitive", "auto");
2445 lpcfg_do_global_parameter(lp_ctx, "ldap timeout", "15");
2447 lpcfg_do_global_parameter(lp_ctx, "mangle prefix", "1");
2449 lpcfg_do_global_parameter(lp_ctx, "posix locking", "yes");
2451 lpcfg_do_global_parameter(lp_ctx, "lock spin time", "200");
2453 lpcfg_do_global_parameter(lp_ctx, "directory name cache size", "100");
2455 lpcfg_do_global_parameter(lp_ctx, "nmbd bind explicit broadcast", "yes");
2457 lpcfg_do_global_parameter(lp_ctx, "init logon delay", "100");
2459 lpcfg_do_global_parameter(lp_ctx, "usershare owner only", "yes");
2461 lpcfg_do_global_parameter(lp_ctx, "-valid", "yes");
2463 lpcfg_do_global_parameter_var(lp_ctx, "usershare path", "%s/usershares", get_dyn_STATEDIR());
2466 lpcfg_do_global_parameter_var(lp_ctx, "panic action", "/bin/sleep 999999999");
2469 lpcfg_do_global_parameter(lp_ctx, "smb passwd file", get_dyn_SMB_PASSWD_FILE());
2471 lpcfg_do_global_parameter(lp_ctx, "logon home", "\\\\%N\\%U");
2473 lpcfg_do_global_parameter(lp_ctx, "logon path", "\\\\%N\\%U\\profile");
2475 lpcfg_do_global_parameter(lp_ctx, "printjob username", "%U");
2477 for (i = 0; parm_table[i].label; i++) {
2478 if (!(lp_ctx->flags[i] & FLAG_CMDLINE)) {
2479 lp_ctx->flags[i] |= FLAG_DEFAULT;
2483 for (parm=lp_ctx->globals->param_opt; parm; parm=parm->next) {
2484 if (!(parm->priority & FLAG_CMDLINE)) {
2485 parm->priority |= FLAG_DEFAULT;
2493 * Initialise the global parameter structure.
2495 struct loadparm_context *loadparm_init_global(bool load_default)
2497 if (global_loadparm_context == NULL) {
2498 global_loadparm_context = loadparm_init(NULL);
2500 if (global_loadparm_context == NULL) {
2503 global_loadparm_context->global = true;
2504 if (load_default && !global_loadparm_context->loaded) {
2505 lpcfg_load_default(global_loadparm_context);
2507 global_loadparm_context->refuse_free = true;
2508 return global_loadparm_context;
2512 * Initialise the global parameter structure.
2514 struct loadparm_context *loadparm_init_s3(TALLOC_CTX *mem_ctx,
2515 const struct loadparm_s3_helpers *s3_fns)
2517 struct loadparm_context *loadparm_context = talloc_zero(mem_ctx, struct loadparm_context);
2518 if (!loadparm_context) {
2521 loadparm_context->s3_fns = s3_fns;
2522 loadparm_context->globals = s3_fns->globals;
2523 return loadparm_context;
2526 const char *lpcfg_configfile(struct loadparm_context *lp_ctx)
2528 return lp_ctx->szConfigFile;
2531 const char *lp_default_path(void)
2533 if (getenv("SMB_CONF_PATH"))
2534 return getenv("SMB_CONF_PATH");
2536 return dyn_CONFIGFILE;
2540 * Update the internal state of a loadparm context after settings
2543 static bool lpcfg_update(struct loadparm_context *lp_ctx)
2545 struct debug_settings settings;
2546 TALLOC_CTX *tmp_ctx;
2548 tmp_ctx = talloc_new(lp_ctx);
2549 if (tmp_ctx == NULL) {
2553 lpcfg_add_auto_services(lp_ctx, lpcfg_auto_services(lp_ctx, tmp_ctx));
2555 if (!lp_ctx->globals->wins_server_list && lp_ctx->globals->we_are_a_wins_server) {
2556 lpcfg_do_global_parameter(lp_ctx, "wins server", "127.0.0.1");
2559 if (!lp_ctx->global) {
2560 TALLOC_FREE(tmp_ctx);
2564 panic_action = lp_ctx->globals->panic_action;
2566 reload_charcnv(lp_ctx);
2568 ZERO_STRUCT(settings);
2569 /* Add any more debug-related smb.conf parameters created in
2571 settings.syslog = lp_ctx->globals->syslog;
2572 settings.syslog_only = lp_ctx->globals->syslog_only;
2573 settings.timestamp_logs = lp_ctx->globals->timestamp_logs;
2574 settings.debug_prefix_timestamp = lp_ctx->globals->debug_prefix_timestamp;
2575 settings.debug_hires_timestamp = lp_ctx->globals->debug_hires_timestamp;
2576 settings.debug_pid = lp_ctx->globals->debug_pid;
2577 settings.debug_uid = lp_ctx->globals->debug_uid;
2578 settings.debug_class = lp_ctx->globals->debug_class;
2579 debug_set_settings(&settings);
2581 /* FIXME: This is a bit of a hack, but we can't use a global, since
2582 * not everything that uses lp also uses the socket library */
2583 if (lpcfg_parm_bool(lp_ctx, NULL, "socket", "testnonblock", false)) {
2584 setenv("SOCKET_TESTNONBLOCK", "1", 1);
2586 unsetenv("SOCKET_TESTNONBLOCK");
2589 TALLOC_FREE(tmp_ctx);
2593 bool lpcfg_load_default(struct loadparm_context *lp_ctx)
2597 path = lp_default_path();
2599 if (!file_exist(path)) {
2600 /* We allow the default smb.conf file to not exist,
2601 * basically the equivalent of an empty file. */
2602 return lpcfg_update(lp_ctx);
2605 return lpcfg_load(lp_ctx, path);
2609 * Load the services array from the services file.
2611 * Return True on success, False on failure.
2613 bool lpcfg_load(struct loadparm_context *lp_ctx, const char *filename)
2618 filename = talloc_strdup(lp_ctx, filename);
2620 lp_ctx->szConfigFile = filename;
2622 if (lp_ctx->s3_fns) {
2623 return lp_ctx->s3_fns->load(filename);
2626 lp_ctx->bInGlobalSection = true;
2627 n2 = standard_sub_basic(lp_ctx, lp_ctx->szConfigFile);
2628 DEBUG(2, ("lpcfg_load: refreshing parameters from %s\n", n2));
2630 add_to_file_list(lp_ctx, &lp_ctx->file_lists, lp_ctx->szConfigFile, n2);
2632 /* We get sections first, so have to start 'behind' to make up */
2633 lp_ctx->currentService = NULL;
2634 bRetval = pm_process(n2, do_section, do_parameter, lp_ctx);
2636 /* finish up the last section */
2637 DEBUG(4, ("pm_process() returned %s\n", BOOLSTR(bRetval)));
2639 if (lp_ctx->currentService != NULL)
2640 bRetval = lpcfg_service_ok(lp_ctx->currentService);
2642 bRetval = bRetval && lpcfg_update(lp_ctx);
2644 /* we do this unconditionally, so that it happens even
2645 for a missing smb.conf */
2646 reload_charcnv(lp_ctx);
2648 if (bRetval == true) {
2649 /* set this up so that any child python tasks will
2650 find the right smb.conf */
2651 setenv("SMB_CONF_PATH", filename, 1);
2653 /* set the context used by the lp_*() function
2655 global_loadparm_context = lp_ctx;
2656 lp_ctx->loaded = true;
2663 * Return the max number of services.
2666 int lpcfg_numservices(struct loadparm_context *lp_ctx)
2668 if (lp_ctx->s3_fns) {
2669 return lp_ctx->s3_fns->get_numservices();
2672 return lp_ctx->iNumServices;
2676 * Display the contents of the services array in human-readable form.
2679 void lpcfg_dump(struct loadparm_context *lp_ctx, FILE *f, bool show_defaults,
2684 if (lp_ctx->s3_fns) {
2685 lp_ctx->s3_fns->dump(f, show_defaults, maxtoprint);
2689 defaults_saved = !show_defaults;
2691 dump_globals(lp_ctx, f, show_defaults);
2693 dump_a_service(lp_ctx->sDefault, lp_ctx->sDefault, f, lp_ctx->flags);
2695 for (iService = 0; iService < maxtoprint; iService++)
2696 lpcfg_dump_one(f, show_defaults, lp_ctx->services[iService], lp_ctx->sDefault);
2700 * Display the contents of one service in human-readable form.
2702 void lpcfg_dump_one(FILE *f, bool show_defaults, struct loadparm_service *service, struct loadparm_service *sDefault)
2704 if (service != NULL) {
2705 if (service->szService[0] == '\0')
2707 dump_a_service(service, sDefault, f, NULL);
2711 struct loadparm_service *lpcfg_servicebynum(struct loadparm_context *lp_ctx,
2714 if (lp_ctx->s3_fns) {
2715 return lp_ctx->s3_fns->get_servicebynum(snum);
2718 return lp_ctx->services[snum];
2721 struct loadparm_service *lpcfg_service(struct loadparm_context *lp_ctx,
2722 const char *service_name)
2727 if (lp_ctx->s3_fns) {
2728 return lp_ctx->s3_fns->get_service(service_name);
2731 for (iService = lp_ctx->iNumServices - 1; iService >= 0; iService--) {
2732 if (lp_ctx->services[iService] &&
2733 lp_ctx->services[iService]->szService) {
2735 * The substitution here is used to support %U is
2738 serviceName = standard_sub_basic(
2739 lp_ctx->services[iService],
2740 lp_ctx->services[iService]->szService);
2741 if (strequal(serviceName, service_name)) {
2742 talloc_free(serviceName);
2743 return lp_ctx->services[iService];
2745 talloc_free(serviceName);
2749 DEBUG(7,("lpcfg_servicenumber: couldn't find %s\n", service_name));
2753 const char *lpcfg_servicename(const struct loadparm_service *service)
2755 return lpcfg_string((const char *)service->szService);
2759 * A useful volume label function.
2761 const char *lpcfg_volume_label(struct loadparm_service *service, struct loadparm_service *sDefault)
2764 ret = lpcfg_string((const char *)((service != NULL && service->volume != NULL) ?
2765 service->volume : sDefault->volume));
2767 return lpcfg_servicename(service);
2772 * Return the correct printer name.
2774 const char *lpcfg_printername(struct loadparm_service *service, struct loadparm_service *sDefault)
2777 ret = lpcfg_string((const char *)((service != NULL && service->_printername != NULL) ?
2778 service->_printername : sDefault->_printername));
2779 if (ret == NULL || (ret != NULL && *ret == '\0'))
2780 ret = lpcfg_servicename(service);
2787 * Return the max print jobs per queue.
2789 int lpcfg_maxprintjobs(struct loadparm_service *service, struct loadparm_service *sDefault)
2791 int maxjobs = (service != NULL) ? service->iMaxPrintJobs : sDefault->iMaxPrintJobs;
2792 if (maxjobs <= 0 || maxjobs >= PRINT_MAX_JOBID)
2793 maxjobs = PRINT_MAX_JOBID - 1;
2798 struct smb_iconv_handle *lpcfg_iconv_handle(struct loadparm_context *lp_ctx)
2800 if (lp_ctx == NULL) {
2801 return get_iconv_handle();
2803 return lp_ctx->iconv_handle;
2806 _PUBLIC_ void reload_charcnv(struct loadparm_context *lp_ctx)
2808 struct smb_iconv_handle *old_ic = lp_ctx->iconv_handle;
2809 if (!lp_ctx->global) {
2813 if (old_ic == NULL) {
2814 old_ic = global_iconv_handle;
2816 lp_ctx->iconv_handle = smb_iconv_handle_reinit_lp(lp_ctx, lp_ctx, old_ic);
2817 global_iconv_handle = lp_ctx->iconv_handle;
2820 _PUBLIC_ char *lpcfg_tls_keyfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
2822 return lpcfg_private_path(mem_ctx, lp_ctx, lpcfg__tls_keyfile(lp_ctx));
2825 _PUBLIC_ char *lpcfg_tls_certfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
2827 return lpcfg_private_path(mem_ctx, lp_ctx, lpcfg__tls_certfile(lp_ctx));
2830 _PUBLIC_ char *lpcfg_tls_cafile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
2832 return lpcfg_private_path(mem_ctx, lp_ctx, lpcfg__tls_cafile(lp_ctx));
2835 _PUBLIC_ char *lpcfg_tls_crlfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
2837 return lpcfg_private_path(mem_ctx, lp_ctx, lpcfg__tls_crlfile(lp_ctx));
2840 _PUBLIC_ char *lpcfg_tls_dhpfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
2842 return lpcfg_private_path(mem_ctx, lp_ctx, lpcfg__tls_dhpfile(lp_ctx));
2845 struct gensec_settings *lpcfg_gensec_settings(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
2847 struct gensec_settings *settings = talloc_zero(mem_ctx, struct gensec_settings);
2848 if (settings == NULL)
2850 SMB_ASSERT(lp_ctx != NULL);
2851 settings->lp_ctx = talloc_reference(settings, lp_ctx);
2852 settings->target_hostname = lpcfg_parm_string(lp_ctx, NULL, "gensec", "target_hostname");
2856 int lpcfg_server_role(struct loadparm_context *lp_ctx)
2858 int domain_master = lpcfg__domain_master(lp_ctx);
2860 return lp_find_server_role(lpcfg__server_role(lp_ctx),
2861 lpcfg__security(lp_ctx),
2862 lpcfg__domain_logons(lp_ctx),
2863 (domain_master == true) ||
2864 (domain_master == Auto));
2867 int lpcfg_security(struct loadparm_context *lp_ctx)
2869 return lp_find_security(lpcfg__server_role(lp_ctx),
2870 lpcfg__security(lp_ctx));
2873 bool lpcfg_server_signing_allowed(struct loadparm_context *lp_ctx, bool *mandatory)
2875 bool allowed = true;
2876 enum smb_signing_setting signing_setting = lpcfg_server_signing(lp_ctx);
2880 if (signing_setting == SMB_SIGNING_DEFAULT) {
2882 * If we are a domain controller, SMB signing is
2883 * really important, as it can prevent a number of
2884 * attacks on communications between us and the
2887 * However, it really sucks (no sendfile, CPU
2888 * overhead) performance-wise when used on a
2889 * file server, so disable it by default
2893 if (lpcfg_server_role(lp_ctx) >= ROLE_ACTIVE_DIRECTORY_DC) {
2894 signing_setting = SMB_SIGNING_REQUIRED;
2896 signing_setting = SMB_SIGNING_OFF;
2900 switch (signing_setting) {
2901 case SMB_SIGNING_REQUIRED:
2904 case SMB_SIGNING_IF_REQUIRED:
2906 case SMB_SIGNING_DEFAULT:
2907 case SMB_SIGNING_OFF:
2915 int lpcfg_tdb_hash_size(struct loadparm_context *lp_ctx, const char *name)
2923 base = strrchr_m(name, '/');
2929 return lpcfg_parm_int(lp_ctx, NULL, "tdb_hashsize", base, 0);
2933 int lpcfg_tdb_flags(struct loadparm_context *lp_ctx, int tdb_flags)
2935 if (!lpcfg_use_mmap(lp_ctx)) {
2936 tdb_flags |= TDB_NOMMAP;