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 *);
75 #include "lib/param/param_global.h"
77 struct loadparm_service *lpcfg_default_service(struct loadparm_context *lp_ctx)
80 return lp_ctx->s3_fns->get_default_loadparm_service();
82 return lp_ctx->sDefault;
86 * Convenience routine to grab string parameters into temporary memory
87 * and run standard_sub_basic on them.
89 * The buffers can be written to by
90 * callers without affecting the source string.
93 static const char *lpcfg_string(const char *s)
95 #if 0 /* until REWRITE done to make thread-safe */
96 size_t len = s ? strlen(s) : 0;
100 /* The follow debug is useful for tracking down memory problems
101 especially if you have an inner loop that is calling a lp_*()
102 function that returns a string. Perhaps this debug should be
103 present all the time? */
106 DEBUG(10, ("lpcfg_string(%s)\n", s));
109 #if 0 /* until REWRITE done to make thread-safe */
111 lp_talloc = talloc_init("lp_talloc");
113 ret = talloc_array(lp_talloc, char, len + 100); /* leave room for substitution */
121 strlcpy(ret, s, len);
123 if (trim_string(ret, "\"", "\"")) {
124 if (strchr(ret,'"') != NULL)
125 strlcpy(ret, s, len);
128 standard_sub_basic(ret,len+100);
135 In this section all the functions that are used to access the
136 parameters from the rest of the program are defined
140 * the creation of separate lpcfg_*() and lp_*() functions is to allow
141 * for code compatibility between existing Samba4 and Samba3 code.
144 /* this global context supports the lp_*() function varients */
145 static struct loadparm_context *global_loadparm_context;
147 #define lpcfg_default_service global_loadparm_context->sDefault
148 #define lpcfg_global_service(i) global_loadparm_context->services[i]
150 #define FN_GLOBAL_STRING(fn_name,var_name) \
151 _PUBLIC_ char *lpcfg_ ## fn_name(struct loadparm_context *lp_ctx, TALLOC_CTX *ctx) {\
152 if (lp_ctx == NULL) return NULL; \
153 if (lp_ctx->s3_fns) { \
154 return lp_ctx->globals->var_name ? lp_ctx->s3_fns->lp_string(ctx, lp_ctx->globals->var_name) : talloc_strdup(ctx, ""); \
156 return lp_ctx->globals->var_name ? talloc_strdup(ctx, lpcfg_string(lp_ctx->globals->var_name)) : talloc_strdup(ctx, ""); \
159 #define FN_GLOBAL_CONST_STRING(fn_name,var_name) \
160 _PUBLIC_ const char *lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) { \
161 if (lp_ctx == NULL) return NULL; \
162 return lp_ctx->globals->var_name ? lpcfg_string(lp_ctx->globals->var_name) : ""; \
165 #define FN_GLOBAL_LIST(fn_name,var_name) \
166 _PUBLIC_ const char **lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) { \
167 if (lp_ctx == NULL) return NULL; \
168 return lp_ctx->globals->var_name; \
171 #define FN_GLOBAL_BOOL(fn_name,var_name) \
172 _PUBLIC_ bool lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) {\
173 if (lp_ctx == NULL) return false; \
174 return lp_ctx->globals->var_name; \
177 #define FN_GLOBAL_INTEGER(fn_name,var_name) \
178 _PUBLIC_ int lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) { \
179 return lp_ctx->globals->var_name; \
182 /* Local parameters don't need the ->s3_fns because the struct
183 * loadparm_service is shared and lpcfg_service() checks the ->s3_fns
185 #define FN_LOCAL_STRING(fn_name,val) \
186 _PUBLIC_ char *lpcfg_ ## fn_name(struct loadparm_service *service, \
187 struct loadparm_service *sDefault, TALLOC_CTX *ctx) { \
188 return(talloc_strdup(ctx, lpcfg_string((const char *)((service != NULL && service->val != NULL) ? service->val : sDefault->val)))); \
191 #define FN_LOCAL_CONST_STRING(fn_name,val) \
192 _PUBLIC_ const char *lpcfg_ ## fn_name(struct loadparm_service *service, \
193 struct loadparm_service *sDefault) { \
194 return((const char *)((service != NULL && service->val != NULL) ? service->val : sDefault->val)); \
197 #define FN_LOCAL_LIST(fn_name,val) \
198 _PUBLIC_ const char **lpcfg_ ## fn_name(struct loadparm_service *service, \
199 struct loadparm_service *sDefault) {\
200 return(const char **)(service != NULL && service->val != NULL? service->val : sDefault->val); \
203 #define FN_LOCAL_PARM_BOOL(fn_name, val) FN_LOCAL_BOOL(fn_name, val)
205 #define FN_LOCAL_BOOL(fn_name,val) \
206 _PUBLIC_ bool lpcfg_ ## fn_name(struct loadparm_service *service, \
207 struct loadparm_service *sDefault) { \
208 return((service != NULL)? service->val : sDefault->val); \
211 #define FN_LOCAL_INTEGER(fn_name,val) \
212 _PUBLIC_ int lpcfg_ ## fn_name(struct loadparm_service *service, \
213 struct loadparm_service *sDefault) { \
214 return((service != NULL)? service->val : sDefault->val); \
217 #define FN_LOCAL_PARM_INTEGER(fn_name, val) FN_LOCAL_INTEGER(fn_name, val)
219 #define FN_LOCAL_PARM_CHAR(fn_name,val) \
220 _PUBLIC_ char lpcfg_ ## fn_name(struct loadparm_service *service, \
221 struct loadparm_service *sDefault) { \
222 return((service != NULL)? service->val : sDefault->val); \
225 #include "lib/param/param_functions.c"
227 /* These functions cannot be auto-generated */
228 FN_LOCAL_BOOL(autoloaded, autoloaded)
229 FN_GLOBAL_CONST_STRING(dnsdomain, dnsdomain)
231 /* local prototypes */
232 static struct loadparm_service *lpcfg_getservicebyname(struct loadparm_context *lp_ctx,
233 const char *pszServiceName);
234 static bool lpcfg_service_ok(struct loadparm_service *service);
235 static bool do_section(const char *pszSectionName, void *);
237 /* This is a helper function for parametrical options support. */
238 /* It returns a pointer to parametrical option value if it exists or NULL otherwise */
239 /* Actual parametrical functions are quite simple */
240 const char *lpcfg_get_parametric(struct loadparm_context *lp_ctx,
241 struct loadparm_service *service,
242 const char *type, const char *option)
245 struct parmlist_entry *data;
250 if (lp_ctx->s3_fns) {
251 return lp_ctx->s3_fns->get_parametric(service, type, option, NULL);
254 data = (service == NULL ? lp_ctx->globals->param_opt : service->param_opt);
256 vfskey = talloc_asprintf(NULL, "%s:%s", type, option);
257 if (vfskey == NULL) {
258 DEBUG(0,("asprintf failed!\n"));
263 if (strwicmp(data->key, vfskey) == 0) {
270 if (service != NULL) {
271 /* Try to fetch the same option but from globals */
272 /* but only if we are not already working with globals */
273 for (data = lp_ctx->globals->param_opt; data;
275 if (strwicmp(data->key, vfskey) == 0) {
289 * convenience routine to return int parameters.
291 int lp_int(const char *s)
295 DEBUG(0,("lp_int(%s): is called with NULL!\n",s));
299 return strtol(s, NULL, 0);
303 * convenience routine to return unsigned long parameters.
305 unsigned long lp_ulong(const char *s)
309 DEBUG(0,("lp_ulong(%s): is called with NULL!\n",s));
313 return strtoul(s, NULL, 0);
317 * convenience routine to return unsigned long parameters.
319 static long lp_long(const char *s)
323 DEBUG(0,("lp_long(%s): is called with NULL!\n",s));
327 return strtol(s, NULL, 0);
331 * convenience routine to return unsigned long parameters.
333 static double lp_double(const char *s)
337 DEBUG(0,("lp_double(%s): is called with NULL!\n",s));
341 return strtod(s, NULL);
345 * convenience routine to return boolean parameters.
347 bool lp_bool(const char *s)
352 DEBUG(0,("lp_bool(%s): is called with NULL!\n",s));
356 if (!set_boolean(s, &ret)) {
357 DEBUG(0,("lp_bool(%s): value is not boolean!\n",s));
365 * Return parametric option from a given service. Type is a part of option before ':'
366 * Parametric option has following syntax: 'Type: option = value'
367 * Returned value is allocated in 'lp_talloc' context
370 const char *lpcfg_parm_string(struct loadparm_context *lp_ctx,
371 struct loadparm_service *service, const char *type,
374 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
377 return lpcfg_string(value);
383 * Return parametric option from a given service. Type is a part of option before ':'
384 * Parametric option has following syntax: 'Type: option = value'
385 * Returned value is allocated in 'lp_talloc' context
388 const char **lpcfg_parm_string_list(TALLOC_CTX *mem_ctx,
389 struct loadparm_context *lp_ctx,
390 struct loadparm_service *service,
392 const char *option, const char *separator)
394 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
397 return (const char **)str_list_make(mem_ctx, value, separator);
403 * Return parametric option from a given service. Type is a part of option before ':'
404 * Parametric option has following syntax: 'Type: option = value'
407 int lpcfg_parm_int(struct loadparm_context *lp_ctx,
408 struct loadparm_service *service, const char *type,
409 const char *option, int default_v)
411 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
414 return lp_int(value);
420 * Return parametric option from a given service. Type is a part of
422 * Parametric option has following syntax: 'Type: option = value'.
425 int lpcfg_parm_bytes(struct loadparm_context *lp_ctx,
426 struct loadparm_service *service, const char *type,
427 const char *option, int default_v)
431 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
433 if (value && conv_str_size_error(value, &bval)) {
434 if (bval <= INT_MAX) {
443 * Return parametric option from a given service.
444 * Type is a part of option before ':'
445 * Parametric option has following syntax: 'Type: option = value'
447 unsigned long lpcfg_parm_ulong(struct loadparm_context *lp_ctx,
448 struct loadparm_service *service, const char *type,
449 const char *option, unsigned long default_v)
451 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
454 return lp_ulong(value);
459 long lpcfg_parm_long(struct loadparm_context *lp_ctx,
460 struct loadparm_service *service, const char *type,
461 const char *option, long default_v)
463 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
466 return lp_long(value);
471 double lpcfg_parm_double(struct loadparm_context *lp_ctx,
472 struct loadparm_service *service, const char *type,
473 const char *option, double default_v)
475 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
478 return lp_double(value);
484 * Return parametric option from a given service. Type is a part of option before ':'
485 * Parametric option has following syntax: 'Type: option = value'
488 bool lpcfg_parm_bool(struct loadparm_context *lp_ctx,
489 struct loadparm_service *service, const char *type,
490 const char *option, bool default_v)
492 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
495 return lp_bool(value);
502 * Set a string value, deallocating any existing space, and allocing the space
505 bool lpcfg_string_set(TALLOC_CTX *mem_ctx, char **dest, const char *src)
512 *dest = talloc_strdup(mem_ctx, src);
513 if ((*dest) == NULL) {
514 DEBUG(0,("Out of memory in string_set\n"));
522 * Set a string value, deallocating any existing space, and allocing the space
525 static bool lpcfg_string_set_upper(TALLOC_CTX *mem_ctx, char **dest, const char *src)
532 *dest = strupper_talloc(mem_ctx, src);
533 if ((*dest) == NULL) {
534 DEBUG(0,("Out of memory in string_set_upper\n"));
544 * Add a new service to the services array initialising it with the given
548 struct loadparm_service *lpcfg_add_service(struct loadparm_context *lp_ctx,
549 const struct loadparm_service *pservice,
553 int num_to_alloc = lp_ctx->iNumServices + 1;
554 struct parmlist_entry *data, *pdata;
556 if (pservice == NULL) {
557 pservice = lp_ctx->sDefault;
560 /* it might already exist */
562 struct loadparm_service *service = lpcfg_getservicebyname(lp_ctx,
564 if (service != NULL) {
565 /* Clean all parametric options for service */
566 /* They will be added during parsing again */
567 data = service->param_opt;
573 service->param_opt = NULL;
578 /* find an invalid one */
579 for (i = 0; i < lp_ctx->iNumServices; i++)
580 if (lp_ctx->services[i] == NULL)
583 /* if not, then create one */
584 if (i == lp_ctx->iNumServices) {
585 struct loadparm_service **tsp;
587 tsp = talloc_realloc(lp_ctx, lp_ctx->services, struct loadparm_service *, num_to_alloc);
590 DEBUG(0,("lpcfg_add_service: failed to enlarge services!\n"));
593 lp_ctx->services = tsp;
594 lp_ctx->services[lp_ctx->iNumServices] = NULL;
597 lp_ctx->iNumServices++;
600 lp_ctx->services[i] = talloc_zero(lp_ctx->services, struct loadparm_service);
601 if (lp_ctx->services[i] == NULL) {
602 DEBUG(0,("lpcfg_add_service: out of memory!\n"));
605 copy_service(lp_ctx->services[i], pservice, NULL);
607 lpcfg_string_set(lp_ctx->services[i], &lp_ctx->services[i]->szService, name);
608 return lp_ctx->services[i];
612 * Add a new home service, with the specified home directory, defaults coming
613 * from service ifrom.
616 bool lpcfg_add_home(struct loadparm_context *lp_ctx,
617 const char *pszHomename,
618 struct loadparm_service *default_service,
619 const char *user, const char *pszHomedir)
621 struct loadparm_service *service;
623 service = lpcfg_add_service(lp_ctx, default_service, pszHomename);
628 if (!(*(default_service->path))
629 || strequal(default_service->path, lp_ctx->sDefault->path)) {
630 service->path = talloc_strdup(service, pszHomedir);
632 service->path = string_sub_talloc(service, lpcfg_path(default_service, lp_ctx->sDefault, service), "%H", pszHomedir);
635 if (!(*(service->comment))) {
636 service->comment = talloc_asprintf(service, "Home directory of %s", user);
638 service->bAvailable = default_service->bAvailable;
639 service->browseable = default_service->browseable;
641 DEBUG(3, ("adding home's share [%s] for user '%s' at '%s'\n",
642 pszHomename, user, service->path));
648 * Add a new printer service, with defaults coming from service iFrom.
651 bool lpcfg_add_printer(struct loadparm_context *lp_ctx,
652 const char *pszPrintername,
653 struct loadparm_service *default_service)
655 const char *comment = "From Printcap";
656 struct loadparm_service *service;
657 service = lpcfg_add_service(lp_ctx, default_service, pszPrintername);
662 /* note that we do NOT default the availability flag to True - */
663 /* we take it from the default service passed. This allows all */
664 /* dynamic printers to be disabled by disabling the [printers] */
665 /* entry (if/when the 'available' keyword is implemented!). */
667 /* the printer name is set to the service name. */
668 lpcfg_string_set(service, &service->_printername, pszPrintername);
669 lpcfg_string_set(service, &service->comment, comment);
670 service->browseable = default_service->browseable;
671 /* Printers cannot be read_only. */
672 service->read_only = false;
673 /* Printer services must be printable. */
674 service->printable = true;
676 DEBUG(3, ("adding printer service %s\n", pszPrintername));
682 * Map a parameter's string representation to something we can use.
683 * Returns False if the parameter string is not recognised, else TRUE.
686 int lpcfg_map_parameter(const char *pszParmName)
690 for (iIndex = 0; parm_table[iIndex].label; iIndex++)
691 if (strwicmp(parm_table[iIndex].label, pszParmName) == 0)
694 /* Warn only if it isn't parametric option */
695 if (strchr(pszParmName, ':') == NULL)
696 DEBUG(0, ("Unknown parameter encountered: \"%s\"\n", pszParmName));
697 /* We do return 'fail' for parametric options as well because they are
698 stored in different storage
705 return the parameter structure for a parameter
707 struct parm_struct *lpcfg_parm_struct(struct loadparm_context *lp_ctx, const char *name)
711 if (lp_ctx->s3_fns) {
712 return lp_ctx->s3_fns->get_parm_struct(name);
715 parmnum = lpcfg_map_parameter(name);
716 if (parmnum == -1) return NULL;
717 return &parm_table[parmnum];
721 return the parameter pointer for a parameter
723 void *lpcfg_parm_ptr(struct loadparm_context *lp_ctx,
724 struct loadparm_service *service, struct parm_struct *parm)
726 if (lp_ctx->s3_fns) {
727 return lp_ctx->s3_fns->get_parm_ptr(service, parm);
730 if (service == NULL) {
731 if (parm->p_class == P_LOCAL)
732 return ((char *)lp_ctx->sDefault)+parm->offset;
733 else if (parm->p_class == P_GLOBAL)
734 return ((char *)lp_ctx->globals)+parm->offset;
737 return ((char *)service) + parm->offset;
742 return the parameter pointer for a parameter
744 bool lpcfg_parm_is_cmdline(struct loadparm_context *lp_ctx, const char *name)
748 if (lp_ctx->s3_fns) {
749 struct parm_struct *parm = lp_ctx->s3_fns->get_parm_struct(name);
751 return parm->flags & FLAG_CMDLINE;
756 parmnum = lpcfg_map_parameter(name);
757 if (parmnum == -1) return false;
759 return lp_ctx->flags[parmnum] & FLAG_CMDLINE;
763 * Find a service by name. Otherwise works like get_service.
766 static struct loadparm_service *lpcfg_getservicebyname(struct loadparm_context *lp_ctx,
767 const char *pszServiceName)
771 if (lp_ctx->s3_fns) {
772 return lp_ctx->s3_fns->get_service(pszServiceName);
775 for (iService = lp_ctx->iNumServices - 1; iService >= 0; iService--)
776 if (lp_ctx->services[iService] != NULL &&
777 strwicmp(lp_ctx->services[iService]->szService, pszServiceName) == 0) {
778 return lp_ctx->services[iService];
785 * Add a parametric option to a parmlist_entry,
786 * replacing old value, if already present.
788 void set_param_opt(TALLOC_CTX *mem_ctx,
789 struct parmlist_entry **opt_list,
790 const char *opt_name,
791 const char *opt_value,
794 struct parmlist_entry *new_opt, *opt;
800 /* Traverse destination */
802 /* If we already have same option, override it */
803 if (strwicmp(opt->key, opt_name) == 0) {
804 if ((opt->priority & FLAG_CMDLINE) &&
805 !(priority & FLAG_CMDLINE)) {
806 /* it's been marked as not to be
810 TALLOC_FREE(opt->value);
811 TALLOC_FREE(opt->list);
812 opt->value = talloc_strdup(opt, opt_value);
813 opt->priority = priority;
820 new_opt = talloc(mem_ctx, struct parmlist_entry);
821 if (new_opt == NULL) {
825 new_opt->key = talloc_strdup(new_opt, opt_name);
826 if (new_opt->key == NULL) {
827 smb_panic("talloc_strdup failed");
830 new_opt->value = talloc_strdup(new_opt, opt_value);
831 if (new_opt->value == NULL) {
832 smb_panic("talloc_strdup failed");
835 new_opt->list = NULL;
836 new_opt->priority = priority;
837 DLIST_ADD(*opt_list, new_opt);
842 * Copy a service structure to another.
843 * If pcopymapDest is NULL then copy all fields
846 void copy_service(struct loadparm_service *pserviceDest,
847 const struct loadparm_service *pserviceSource,
848 struct bitmap *pcopymapDest)
851 bool bcopyall = (pcopymapDest == NULL);
852 struct parmlist_entry *data;
854 for (i = 0; parm_table[i].label; i++)
855 if (parm_table[i].p_class == P_LOCAL &&
856 (bcopyall || bitmap_query(pcopymapDest, i))) {
857 const void *src_ptr =
858 ((const char *)pserviceSource) + parm_table[i].offset;
860 ((char *)pserviceDest) + parm_table[i].offset;
862 switch (parm_table[i].type) {
865 *(bool *)dest_ptr = *(const bool *)src_ptr;
872 *(int *)dest_ptr = *(const int *)src_ptr;
876 *(char *)dest_ptr = *(const char *)src_ptr;
880 lpcfg_string_set(pserviceDest,
882 *(const char * const *)src_ptr);
886 lpcfg_string_set_upper(pserviceDest,
888 *(const char * const *)src_ptr);
892 TALLOC_FREE(*((char ***)dest_ptr));
893 *(const char * const **)dest_ptr = (const char * const *)str_list_copy(pserviceDest,
894 *(const char * * const *)src_ptr);
902 init_copymap(pserviceDest);
903 if (pserviceSource->copymap)
904 bitmap_copy(pserviceDest->copymap,
905 pserviceSource->copymap);
908 for (data = pserviceSource->param_opt; data != NULL; data = data->next) {
909 set_param_opt(pserviceDest, &pserviceDest->param_opt,
910 data->key, data->value, data->priority);
915 * Check a service for consistency. Return False if the service is in any way
916 * incomplete or faulty, else True.
918 static bool lpcfg_service_ok(struct loadparm_service *service)
923 if (service->szService[0] == '\0') {
924 DEBUG(0, ("The following message indicates an internal error:\n"));
925 DEBUG(0, ("No service name in service entry.\n"));
929 /* The [printers] entry MUST be printable. I'm all for flexibility, but */
930 /* I can't see why you'd want a non-printable printer service... */
931 if (strwicmp(service->szService, PRINTERS_NAME) == 0) {
932 if (!service->printable) {
933 DEBUG(0, ("WARNING: [%s] service MUST be printable!\n",
934 service->szService));
935 service->printable = true;
937 /* [printers] service must also be non-browsable. */
938 if (service->browseable)
939 service->browseable = false;
942 /* If a service is flagged unavailable, log the fact at level 0. */
943 if (!service->bAvailable)
944 DEBUG(1, ("NOTE: Service %s is flagged unavailable.\n",
945 service->szService));
951 /*******************************************************************
952 Keep a linked list of all config files so we know when one has changed
953 it's date and needs to be reloaded.
954 ********************************************************************/
956 void add_to_file_list(TALLOC_CTX *mem_ctx, struct file_lists **list,
957 const char *fname, const char *subfname)
959 struct file_lists *f = *list;
962 if (f->name && !strcmp(f->name, fname))
968 f = talloc(mem_ctx, struct file_lists);
972 f->name = talloc_strdup(f, fname);
977 f->subfname = talloc_strdup(f, subfname);
983 f->modtime = file_modtime(subfname);
985 time_t t = file_modtime(subfname);
992 DEBUG(0, ("Unable to add file to file list: %s\n", fname));
996 /*******************************************************************
997 Check if a config file has changed date.
998 ********************************************************************/
999 bool lpcfg_file_list_changed(struct loadparm_context *lp_ctx)
1001 struct file_lists *f;
1002 DEBUG(6, ("lpcfg_file_list_changed()\n"));
1004 for (f = lp_ctx->file_lists; f != NULL; f = f->next) {
1008 n2 = standard_sub_basic(lp_ctx, f->name);
1010 DEBUGADD(6, ("file %s -> %s last mod_time: %s\n",
1011 f->name, n2, ctime(&f->modtime)));
1013 mod_time = file_modtime(n2);
1015 if (mod_time && ((f->modtime != mod_time) || (f->subfname == NULL) || (strcmp(n2, f->subfname) != 0))) {
1016 DEBUGADD(6, ("file %s modified: %s\n", n2,
1018 f->modtime = mod_time;
1019 talloc_free(f->subfname);
1020 f->subfname = talloc_strdup(f, n2);
1028 * set the value for a P_ENUM
1030 bool lp_set_enum_parm( struct parm_struct *parm, const char *pszParmValue,
1035 for (i = 0; parm->enum_list[i].name; i++) {
1036 if ( strequal(pszParmValue, parm->enum_list[i].name)) {
1037 *ptr = parm->enum_list[i].value;
1041 DEBUG(0, ("WARNING: Ignoring invalid value '%s' for parameter '%s'\n",
1042 pszParmValue, parm->label));
1047 /***************************************************************************
1048 Handle the "realm" parameter
1049 ***************************************************************************/
1051 bool handle_realm(struct loadparm_context *lp_ctx, int unused,
1052 const char *pszParmValue, char **ptr)
1057 upper = strupper_talloc(lp_ctx, pszParmValue);
1058 if (upper == NULL) {
1062 lower = strlower_talloc(lp_ctx, pszParmValue);
1063 if (lower == NULL) {
1068 if (lp_ctx->s3_fns != NULL) {
1069 lp_ctx->s3_fns->lp_string_set(ptr, pszParmValue);
1070 lp_ctx->s3_fns->lp_string_set(&lp_ctx->globals->realm, upper);
1071 lp_ctx->s3_fns->lp_string_set(&lp_ctx->globals->dnsdomain, lower);
1073 lpcfg_string_set(lp_ctx, ptr, pszParmValue);
1074 lpcfg_string_set(lp_ctx, &lp_ctx->globals->realm, upper);
1075 lpcfg_string_set(lp_ctx, &lp_ctx->globals->dnsdomain, lower);
1081 /***************************************************************************
1082 Handle the include operation.
1083 ***************************************************************************/
1085 bool handle_include(struct loadparm_context *lp_ctx, int unused,
1086 const char *pszParmValue, char **ptr)
1090 if (lp_ctx->s3_fns) {
1091 return lp_ctx->s3_fns->lp_include(lp_ctx, unused, pszParmValue, ptr);
1094 fname = standard_sub_basic(lp_ctx, pszParmValue);
1096 add_to_file_list(lp_ctx, &lp_ctx->file_lists, pszParmValue, fname);
1098 lpcfg_string_set(lp_ctx, ptr, fname);
1100 if (file_exist(fname))
1101 return pm_process(fname, do_section, do_parameter, lp_ctx);
1103 DEBUG(2, ("Can't find include file %s\n", fname));
1108 /***************************************************************************
1109 Handle the interpretation of the copy parameter.
1110 ***************************************************************************/
1112 bool handle_copy(struct loadparm_context *lp_ctx, int snum,
1113 const char *pszParmValue, char **ptr)
1116 struct loadparm_service *serviceTemp = NULL;
1117 struct loadparm_service *current = NULL;
1121 DEBUG(3, ("Copying service from service %s\n", pszParmValue));
1123 serviceTemp = lpcfg_getservicebyname(lp_ctx, pszParmValue);
1124 if (lp_ctx->s3_fns != NULL) {
1125 current = lp_ctx->s3_fns->get_servicebynum(snum);
1127 current = lp_ctx->currentService;
1130 if (current == NULL) {
1131 DEBUG(0, ("Unable to copy service - invalid service destination"));
1135 if (serviceTemp != NULL) {
1136 if (serviceTemp == current) {
1137 DEBUG(0, ("Can't copy service %s - unable to copy self!\n", pszParmValue));
1139 copy_service(current,
1142 lpcfg_string_set(current, ptr, pszParmValue);
1147 DEBUG(0, ("Unable to copy service - source not found: %s\n",
1155 bool handle_debug_list(struct loadparm_context *lp_ctx, int unused,
1156 const char *pszParmValue, char **ptr)
1158 if (lp_ctx->s3_fns != NULL) {
1159 lp_ctx->s3_fns->lp_string_set(ptr, pszParmValue);
1161 lpcfg_string_set(lp_ctx, ptr, pszParmValue);
1164 return debug_parse_levels(pszParmValue);
1167 bool handle_logfile(struct loadparm_context *lp_ctx, int unused,
1168 const char *pszParmValue, char **ptr)
1170 if (lp_ctx->s3_fns != NULL) {
1171 lp_ctx->s3_fns->lp_string_set(ptr, pszParmValue);
1173 debug_set_logfile(pszParmValue);
1174 lpcfg_string_set(lp_ctx, ptr, pszParmValue);
1181 * These special charset handling methods only run in the source3 code.
1184 bool handle_charset(struct loadparm_context *lp_ctx, int snum,
1185 const char *pszParmValue, char **ptr)
1187 if (lp_ctx->s3_fns) {
1188 if (*ptr == NULL || strcmp(*ptr, pszParmValue) != 0) {
1189 lp_ctx->s3_fns->lp_string_set(ptr, pszParmValue);
1190 global_iconv_handle = smb_iconv_handle_reinit(NULL,
1191 lpcfg_dos_charset(lp_ctx),
1192 lpcfg_unix_charset(lp_ctx),
1193 true, global_iconv_handle);
1198 return lpcfg_string_set(lp_ctx, ptr, pszParmValue);
1202 bool handle_dos_charset(struct loadparm_context *lp_ctx, int snum,
1203 const char *pszParmValue, char **ptr)
1205 bool is_utf8 = false;
1206 size_t len = strlen(pszParmValue);
1208 if (lp_ctx->s3_fns) {
1209 if (len == 4 || len == 5) {
1210 /* Don't use StrCaseCmp here as we don't want to
1211 initialize iconv. */
1212 if ((toupper_m(pszParmValue[0]) == 'U') &&
1213 (toupper_m(pszParmValue[1]) == 'T') &&
1214 (toupper_m(pszParmValue[2]) == 'F')) {
1216 if (pszParmValue[3] == '8') {
1220 if (pszParmValue[3] == '-' &&
1221 pszParmValue[4] == '8') {
1228 if (*ptr == NULL || strcmp(*ptr, pszParmValue) != 0) {
1230 DEBUG(0,("ERROR: invalid DOS charset: 'dos charset' must not "
1231 "be UTF8, using (default value) %s instead.\n",
1232 DEFAULT_DOS_CHARSET));
1233 pszParmValue = DEFAULT_DOS_CHARSET;
1235 lp_ctx->s3_fns->lp_string_set(ptr, pszParmValue);
1236 global_iconv_handle = smb_iconv_handle_reinit(NULL,
1237 lpcfg_dos_charset(lp_ctx),
1238 lpcfg_unix_charset(lp_ctx),
1239 true, global_iconv_handle);
1244 return lpcfg_string_set(lp_ctx, ptr, pszParmValue);
1247 bool handle_printing(struct loadparm_context *lp_ctx, int snum,
1248 const char *pszParmValue, char **ptr)
1250 static int parm_num = -1;
1251 struct loadparm_service *s;
1253 if (parm_num == -1) {
1254 parm_num = lpcfg_map_parameter("printing");
1257 if (!lp_set_enum_parm(&parm_table[parm_num], pszParmValue, (int*)ptr)) {
1261 if (lp_ctx->s3_fns) {
1263 s = lp_ctx->sDefault;
1264 lp_ctx->s3_fns->init_printer_values(lp_ctx->globals->ctx, s);
1266 s = lp_ctx->services[snum];
1267 lp_ctx->s3_fns->init_printer_values(s, s);
1274 bool handle_ldap_debug_level(struct loadparm_context *lp_ctx, int snum, const char *pszParmValue, char **ptr)
1276 lp_ctx->globals->ldap_debug_level = lp_int(pszParmValue);
1278 if (lp_ctx->s3_fns) {
1279 lp_ctx->s3_fns->init_ldap_debugging();
1284 bool handle_netbios_aliases(struct loadparm_context *lp_ctx, int snum, const char *pszParmValue, char **ptr)
1286 TALLOC_FREE(lp_ctx->globals->netbios_aliases);
1287 lp_ctx->globals->netbios_aliases = (const char **)str_list_make_v3(lp_ctx->globals->ctx,
1288 pszParmValue, NULL);
1290 if (lp_ctx->s3_fns) {
1291 return lp_ctx->s3_fns->set_netbios_aliases(lp_ctx->globals->netbios_aliases);
1297 * idmap related parameters
1300 bool handle_idmap_backend(struct loadparm_context *lp_ctx, int snum, const char *pszParmValue, char **ptr)
1302 if (lp_ctx->s3_fns) {
1303 return lp_ctx->s3_fns->lp_do_parameter(snum, "idmap config * : backend", pszParmValue);
1306 return lpcfg_string_set(lp_ctx, ptr, pszParmValue);
1309 bool handle_idmap_uid(struct loadparm_context *lp_ctx, int snum, const char *pszParmValue, char **ptr)
1311 if (lp_ctx->s3_fns) {
1312 return lp_ctx->s3_fns->lp_do_parameter(snum, "idmap config * : range", pszParmValue);
1315 return lpcfg_string_set(lp_ctx, ptr, pszParmValue);
1318 bool handle_idmap_gid(struct loadparm_context *lp_ctx, int snum, const char *pszParmValue, char **ptr)
1320 if (lp_ctx->s3_fns) {
1321 return lp_ctx->s3_fns->lp_do_parameter(snum, "idmap config * : range", pszParmValue);
1324 return lpcfg_string_set(lp_ctx, ptr, pszParmValue);
1327 /***************************************************************************
1328 Initialise a copymap.
1329 ***************************************************************************/
1331 void init_copymap(struct loadparm_service *pservice)
1335 TALLOC_FREE(pservice->copymap);
1337 pservice->copymap = bitmap_talloc(NULL, num_parameters());
1338 if (!pservice->copymap)
1340 ("Couldn't allocate copymap!! (size %d)\n",
1341 (int)num_parameters()));
1343 for (i = 0; i < num_parameters(); i++)
1344 bitmap_set(pservice->copymap, i);
1348 * Process a parametric option
1350 static bool lp_do_parameter_parametric(struct loadparm_context *lp_ctx,
1351 struct loadparm_service *service,
1352 const char *pszParmName,
1353 const char *pszParmValue, int flags)
1355 struct parmlist_entry **data;
1357 TALLOC_CTX *mem_ctx;
1359 while (isspace((unsigned char)*pszParmName)) {
1363 name = strlower_talloc(lp_ctx, pszParmName);
1364 if (!name) return false;
1366 if (service == NULL) {
1367 data = &lp_ctx->globals->param_opt;
1368 mem_ctx = lp_ctx->globals;
1370 data = &service->param_opt;
1374 set_param_opt(mem_ctx, data, name, pszParmValue, flags);
1381 static bool set_variable(TALLOC_CTX *mem_ctx, int parmnum, void *parm_ptr,
1382 const char *pszParmName, const char *pszParmValue,
1383 struct loadparm_context *lp_ctx, bool on_globals)
1386 /* if it is a special case then go ahead */
1387 if (parm_table[parmnum].special) {
1389 ret = parm_table[parmnum].special(lp_ctx, -1, pszParmValue,
1394 goto mark_non_default;
1397 /* now switch on the type of variable it is */
1398 switch (parm_table[parmnum].type)
1402 if (!set_boolean(pszParmValue, &b)) {
1403 DEBUG(0, ("set_variable(%s): value is not "
1404 "boolean!\n", pszParmValue));
1407 *(bool *)parm_ptr = b;
1413 if (!set_boolean(pszParmValue, &b)) {
1414 DEBUG(0, ("set_variable(%s): value is not "
1415 "boolean!\n", pszParmValue));
1418 *(bool *)parm_ptr = !b;
1423 *(int *)parm_ptr = atoi(pszParmValue);
1427 *(char *)parm_ptr = *pszParmValue;
1431 *(int *)parm_ptr = strtol(pszParmValue, NULL, 8);
1437 if (conv_str_size_error(pszParmValue, &val)) {
1438 if (val <= INT_MAX) {
1439 *(int *)parm_ptr = (int)val;
1444 DEBUG(0, ("set_variable(%s): value is not "
1445 "a valid size specifier!\n", pszParmValue));
1450 *(const char * const **)parm_ptr
1451 = (const char * const *)str_list_make(mem_ctx,
1452 pszParmValue, NULL);
1456 char **new_list = str_list_make(mem_ctx,
1457 pszParmValue, NULL);
1458 for (i=0; new_list[i]; i++) {
1459 if (*(const char ***)parm_ptr != NULL &&
1460 new_list[i][0] == '+' &&
1463 if (!str_list_check(*(const char ***)parm_ptr,
1465 *(const char ***)parm_ptr = str_list_add(*(const char ***)parm_ptr,
1468 } else if (*(const char ***)parm_ptr != NULL &&
1469 new_list[i][0] == '-' &&
1472 str_list_remove(*(const char ***)parm_ptr,
1476 DEBUG(0, ("Unsupported list syntax for: %s = %s\n",
1477 pszParmName, pszParmValue));
1480 *(const char * const **)parm_ptr = (const char * const *) new_list;
1487 lpcfg_string_set(mem_ctx, (char **)parm_ptr, pszParmValue);
1491 lpcfg_string_set_upper(mem_ctx, (char **)parm_ptr, pszParmValue);
1495 if (!lp_set_enum_parm(&parm_table[parmnum], pszParmValue, (int*)parm_ptr)) {
1505 if (on_globals && (lp_ctx->flags[parmnum] & FLAG_DEFAULT)) {
1506 lp_ctx->flags[parmnum] &= ~FLAG_DEFAULT;
1507 /* we have to also unset FLAG_DEFAULT on aliases */
1508 for (i=parmnum-1;i>=0 && parm_table[i].offset == parm_table[parmnum].offset;i--) {
1509 lp_ctx->flags[i] &= ~FLAG_DEFAULT;
1511 for (i=parmnum+1;i<num_parameters() && parm_table[i].offset == parm_table[parmnum].offset;i++) {
1512 lp_ctx->flags[i] &= ~FLAG_DEFAULT;
1519 bool lpcfg_do_global_parameter(struct loadparm_context *lp_ctx,
1520 const char *pszParmName, const char *pszParmValue)
1522 int parmnum = lpcfg_map_parameter(pszParmName);
1526 if (strchr(pszParmName, ':')) {
1527 return lp_do_parameter_parametric(lp_ctx, NULL, pszParmName, pszParmValue, 0);
1529 DEBUG(0, ("Ignoring unknown parameter \"%s\"\n", pszParmName));
1533 /* if the flag has been set on the command line, then don't allow override,
1534 but don't report an error */
1535 if (lp_ctx->flags[parmnum] & FLAG_CMDLINE) {
1539 parm_ptr = lpcfg_parm_ptr(lp_ctx, NULL, &parm_table[parmnum]);
1541 return set_variable(lp_ctx->globals, parmnum, parm_ptr,
1542 pszParmName, pszParmValue, lp_ctx, true);
1545 bool lpcfg_do_service_parameter(struct loadparm_context *lp_ctx,
1546 struct loadparm_service *service,
1547 const char *pszParmName, const char *pszParmValue)
1551 int parmnum = lpcfg_map_parameter(pszParmName);
1554 if (strchr(pszParmName, ':')) {
1555 return lp_do_parameter_parametric(lp_ctx, service, pszParmName, pszParmValue, 0);
1557 DEBUG(0, ("Ignoring unknown parameter \"%s\"\n", pszParmName));
1561 /* if the flag has been set on the command line, then don't allow override,
1562 but don't report an error */
1563 if (lp_ctx->flags[parmnum] & FLAG_CMDLINE) {
1567 if (parm_table[parmnum].p_class == P_GLOBAL) {
1569 ("Global parameter %s found in service section!\n",
1573 parm_ptr = ((char *)service) + parm_table[parmnum].offset;
1575 if (!service->copymap)
1576 init_copymap(service);
1578 /* this handles the aliases - set the copymap for other
1579 * entries with the same data pointer */
1580 for (i = 0; parm_table[i].label; i++)
1581 if (parm_table[i].offset == parm_table[parmnum].offset &&
1582 parm_table[i].p_class == parm_table[parmnum].p_class)
1583 bitmap_clear(service->copymap, i);
1585 return set_variable(service, parmnum, parm_ptr, pszParmName,
1586 pszParmValue, lp_ctx, false);
1590 * Process a parameter.
1593 static bool do_parameter(const char *pszParmName, const char *pszParmValue,
1596 struct loadparm_context *lp_ctx = (struct loadparm_context *)userdata;
1598 if (lp_ctx->bInGlobalSection)
1599 return lpcfg_do_global_parameter(lp_ctx, pszParmName,
1602 return lpcfg_do_service_parameter(lp_ctx, lp_ctx->currentService,
1603 pszParmName, pszParmValue);
1607 variable argument do parameter
1609 bool lpcfg_do_global_parameter_var(struct loadparm_context *lp_ctx, const char *pszParmName, const char *fmt, ...) PRINTF_ATTRIBUTE(3, 4);
1610 bool lpcfg_do_global_parameter_var(struct loadparm_context *lp_ctx,
1611 const char *pszParmName, const char *fmt, ...)
1618 s = talloc_vasprintf(NULL, fmt, ap);
1620 ret = lpcfg_do_global_parameter(lp_ctx, pszParmName, s);
1627 set a parameter from the commandline - this is called from command line parameter
1628 parsing code. It sets the parameter then marks the parameter as unable to be modified
1629 by smb.conf processing
1631 bool lpcfg_set_cmdline(struct loadparm_context *lp_ctx, const char *pszParmName,
1632 const char *pszParmValue)
1637 while (isspace((unsigned char)*pszParmValue)) pszParmValue++;
1639 if (lp_ctx->s3_fns) {
1640 return lp_ctx->s3_fns->set_cmdline(pszParmName, pszParmValue);
1643 parmnum = lpcfg_map_parameter(pszParmName);
1645 if (parmnum < 0 && strchr(pszParmName, ':')) {
1646 /* set a parametric option */
1647 return lp_do_parameter_parametric(lp_ctx, NULL, pszParmName,
1648 pszParmValue, FLAG_CMDLINE);
1652 DEBUG(0,("Unknown option '%s'\n", pszParmName));
1656 /* reset the CMDLINE flag in case this has been called before */
1657 lp_ctx->flags[parmnum] &= ~FLAG_CMDLINE;
1659 if (!lpcfg_do_global_parameter(lp_ctx, pszParmName, pszParmValue)) {
1663 lp_ctx->flags[parmnum] |= FLAG_CMDLINE;
1665 /* we have to also set FLAG_CMDLINE on aliases */
1667 i>=0 && parm_table[i].p_class == parm_table[parmnum].p_class &&
1668 parm_table[i].offset == parm_table[parmnum].offset;
1670 lp_ctx->flags[i] |= FLAG_CMDLINE;
1673 i<num_parameters() &&
1674 parm_table[i].p_class == parm_table[parmnum].p_class &&
1675 parm_table[i].offset == parm_table[parmnum].offset;
1677 lp_ctx->flags[i] |= FLAG_CMDLINE;
1684 set a option from the commandline in 'a=b' format. Use to support --option
1686 bool lpcfg_set_option(struct loadparm_context *lp_ctx, const char *option)
1691 s = talloc_strdup(NULL, option);
1704 ret = lpcfg_set_cmdline(lp_ctx, s, p+1);
1710 #define BOOLSTR(b) ((b) ? "Yes" : "No")
1713 * Print a parameter of the specified type.
1716 void lpcfg_print_parameter(struct parm_struct *p, void *ptr, FILE * f)
1718 /* For the seperation of lists values that we print below */
1719 const char *list_sep = ", ";
1724 for (i = 0; p->enum_list[i].name; i++) {
1725 if (*(int *)ptr == p->enum_list[i].value) {
1727 p->enum_list[i].name);
1734 fprintf(f, "%s", BOOLSTR(*(bool *)ptr));
1738 fprintf(f, "%s", BOOLSTR(!*(bool *)ptr));
1743 fprintf(f, "%d", *(int *)ptr);
1747 fprintf(f, "%c", *(char *)ptr);
1751 int val = *(int *)ptr;
1755 fprintf(f, "0%03o", val);
1764 if ((char ***)ptr && *(char ***)ptr) {
1765 char **list = *(char ***)ptr;
1766 for (; *list; list++) {
1767 /* surround strings with whitespace in double quotes */
1768 if (*(list+1) == NULL) {
1769 /* last item, no extra separator */
1772 if ( strchr_m( *list, ' ' ) ) {
1773 fprintf(f, "\"%s\"%s", *list, list_sep);
1775 fprintf(f, "%s%s", *list, list_sep);
1783 if (*(char **)ptr) {
1784 fprintf(f, "%s", *(char **)ptr);
1793 * Check if two parameters are equal.
1796 static bool lpcfg_equal_parameter(parm_type type, void *ptr1, void *ptr2)
1801 return (*((bool *)ptr1) == *((bool *)ptr2));
1807 return (*((int *)ptr1) == *((int *)ptr2));
1810 return (*((char *)ptr1) == *((char *)ptr2));
1814 return str_list_equal(*(const char ***)ptr1, *(const char ***)ptr2);
1819 char *p1 = *(char **)ptr1, *p2 = *(char **)ptr2;
1824 return (p1 == p2 || strequal(p1, p2));
1833 * Process a new section (service).
1835 * At this stage all sections are services.
1836 * Later we'll have special sections that permit server parameters to be set.
1837 * Returns True on success, False on failure.
1840 static bool do_section(const char *pszSectionName, void *userdata)
1842 struct loadparm_context *lp_ctx = (struct loadparm_context *)userdata;
1844 bool isglobal = ((strwicmp(pszSectionName, GLOBAL_NAME) == 0) ||
1845 (strwicmp(pszSectionName, GLOBAL_NAME2) == 0));
1848 /* if we've just struck a global section, note the fact. */
1849 lp_ctx->bInGlobalSection = isglobal;
1851 /* check for multiple global sections */
1852 if (lp_ctx->bInGlobalSection) {
1853 DEBUG(4, ("Processing section \"[%s]\"\n", pszSectionName));
1857 /* if we have a current service, tidy it up before moving on */
1860 if (lp_ctx->currentService != NULL)
1861 bRetval = lpcfg_service_ok(lp_ctx->currentService);
1863 /* if all is still well, move to the next record in the services array */
1865 /* We put this here to avoid an odd message order if messages are */
1866 /* issued by the post-processing of a previous section. */
1867 DEBUG(4, ("Processing section \"[%s]\"\n", pszSectionName));
1869 if ((lp_ctx->currentService = lpcfg_add_service(lp_ctx, lp_ctx->sDefault,
1872 DEBUG(0, ("Failed to add a new service\n"));
1882 * Determine if a particular base parameter is currently set to the default value.
1885 static bool is_default(struct loadparm_service *sDefault, int i)
1887 void *def_ptr = ((char *)sDefault) + parm_table[i].offset;
1888 switch (parm_table[i].type) {
1891 return str_list_equal((const char * const *)parm_table[i].def.lvalue,
1892 *(const char ***)def_ptr);
1895 return strequal(parm_table[i].def.svalue,
1899 return parm_table[i].def.bvalue ==
1906 return parm_table[i].def.ivalue ==
1915 *Display the contents of the global structure.
1918 static void dump_globals(struct loadparm_context *lp_ctx, FILE *f,
1922 struct parmlist_entry *data;
1924 fprintf(f, "# Global parameters\n[global]\n");
1926 for (i = 0; parm_table[i].label; i++)
1927 if (parm_table[i].p_class == P_GLOBAL &&
1928 (i == 0 || (parm_table[i].offset != parm_table[i - 1].offset))) {
1929 if (!show_defaults && (lp_ctx->flags[i] & FLAG_DEFAULT))
1931 fprintf(f, "\t%s = ", parm_table[i].label);
1932 lpcfg_print_parameter(&parm_table[i], lpcfg_parm_ptr(lp_ctx, NULL, &parm_table[i]), f);
1935 if (lp_ctx->globals->param_opt != NULL) {
1936 for (data = lp_ctx->globals->param_opt; data;
1937 data = data->next) {
1938 if (!show_defaults && (data->priority & FLAG_DEFAULT)) {
1941 fprintf(f, "\t%s = %s\n", data->key, data->value);
1948 * Display the contents of a single services record.
1951 void lpcfg_dump_a_service(struct loadparm_service * pService, struct loadparm_service *sDefault, FILE * f,
1952 unsigned int *flags, bool show_defaults)
1955 struct parmlist_entry *data;
1957 if (pService != sDefault)
1958 fprintf(f, "\n[%s]\n", pService->szService);
1960 for (i = 0; parm_table[i].label; i++) {
1961 if (parm_table[i].p_class == P_LOCAL &&
1962 (*parm_table[i].label != '-') &&
1963 (i == 0 || (parm_table[i].offset != parm_table[i - 1].offset)))
1965 if (pService == sDefault) {
1966 if (flags && (flags[i] & FLAG_DEFAULT)) {
1969 if (!show_defaults) {
1970 if (is_default(sDefault, i)) {
1975 if (lpcfg_equal_parameter(parm_table[i].type,
1976 ((char *)pService) +
1977 parm_table[i].offset,
1978 ((char *)sDefault) +
1979 parm_table[i].offset))
1983 fprintf(f, "\t%s = ", parm_table[i].label);
1984 lpcfg_print_parameter(&parm_table[i],
1985 ((char *)pService) + parm_table[i].offset, f);
1989 if (pService->param_opt != NULL) {
1990 for (data = pService->param_opt; data; data = data->next) {
1991 fprintf(f, "\t%s = %s\n", data->key, data->value);
1996 bool lpcfg_dump_a_parameter(struct loadparm_context *lp_ctx,
1997 struct loadparm_service *service,
1998 const char *parm_name, FILE * f)
2000 struct parm_struct *parm;
2002 char *local_parm_name;
2004 const char *parm_opt_value;
2006 /* check for parametrical option */
2007 local_parm_name = talloc_strdup(lp_ctx, parm_name);
2008 if (local_parm_name == NULL) {
2012 parm_opt = strchr( local_parm_name, ':');
2017 if (strlen(parm_opt)) {
2018 parm_opt_value = lpcfg_parm_string(lp_ctx, service,
2019 local_parm_name, parm_opt);
2020 if (parm_opt_value) {
2021 fprintf(f, "%s\n", parm_opt_value);
2028 /* parameter is not parametric, search the table */
2029 parm = lpcfg_parm_struct(lp_ctx, parm_name);
2034 if (service != NULL && parm->p_class == P_GLOBAL) {
2038 ptr = lpcfg_parm_ptr(lp_ctx, service,parm);
2040 lpcfg_print_parameter(parm, ptr, f);
2046 * Auto-load some home services.
2048 static void lpcfg_add_auto_services(struct loadparm_context *lp_ctx,
2056 * Unload unused services.
2059 void lpcfg_killunused(struct loadparm_context *lp_ctx,
2060 struct smbsrv_connection *smb,
2061 bool (*snumused) (struct smbsrv_connection *, int))
2064 for (i = 0; i < lp_ctx->iNumServices; i++) {
2065 if (lp_ctx->services[i] == NULL)
2068 if (!snumused || !snumused(smb, i)) {
2069 talloc_free(lp_ctx->services[i]);
2070 lp_ctx->services[i] = NULL;
2076 static int lpcfg_destructor(struct loadparm_context *lp_ctx)
2078 struct parmlist_entry *data;
2080 if (lp_ctx->refuse_free) {
2081 /* someone is trying to free the
2082 global_loadparm_context.
2083 We can't allow that. */
2087 if (lp_ctx->globals->param_opt != NULL) {
2088 struct parmlist_entry *next;
2089 for (data = lp_ctx->globals->param_opt; data; data=next) {
2091 if (data->priority & FLAG_CMDLINE) continue;
2092 DLIST_REMOVE(lp_ctx->globals->param_opt, data);
2101 * Initialise the global parameter structure.
2103 * Note that most callers should use loadparm_init_global() instead
2105 struct loadparm_context *loadparm_init(TALLOC_CTX *mem_ctx)
2109 struct loadparm_context *lp_ctx;
2110 struct parmlist_entry *parm;
2113 lp_ctx = talloc_zero(mem_ctx, struct loadparm_context);
2117 talloc_set_destructor(lp_ctx, lpcfg_destructor);
2118 lp_ctx->bInGlobalSection = true;
2119 lp_ctx->globals = talloc_zero(lp_ctx, struct loadparm_global);
2120 /* This appears odd, but globals in s3 isn't a pointer */
2121 lp_ctx->globals->ctx = lp_ctx->globals;
2122 lp_ctx->sDefault = talloc_zero(lp_ctx, struct loadparm_service);
2123 lp_ctx->flags = talloc_zero_array(lp_ctx, unsigned int, num_parameters());
2125 lp_ctx->sDefault->iMaxPrintJobs = 1000;
2126 lp_ctx->sDefault->bAvailable = true;
2127 lp_ctx->sDefault->browseable = true;
2128 lp_ctx->sDefault->read_only = true;
2129 lp_ctx->sDefault->map_archive = true;
2130 lp_ctx->sDefault->strict_locking = true;
2131 lp_ctx->sDefault->oplocks = true;
2132 lp_ctx->sDefault->create_mask = 0744;
2133 lp_ctx->sDefault->force_create_mode = 0000;
2134 lp_ctx->sDefault->directory_mask = 0755;
2135 lp_ctx->sDefault->force_directory_mode = 0000;
2137 DEBUG(3, ("Initialising global parameters\n"));
2139 for (i = 0; parm_table[i].label; i++) {
2140 if ((parm_table[i].type == P_STRING ||
2141 parm_table[i].type == P_USTRING) &&
2142 !(lp_ctx->flags[i] & FLAG_CMDLINE)) {
2144 if (parm_table[i].p_class == P_LOCAL) {
2145 r = (char **)(((char *)lp_ctx->sDefault) + parm_table[i].offset);
2147 r = (char **)(((char *)lp_ctx->globals) + parm_table[i].offset);
2149 *r = talloc_strdup(lp_ctx, "");
2153 logfile = talloc_asprintf(lp_ctx, "%s/log.samba", dyn_LOGFILEBASE);
2154 lpcfg_do_global_parameter(lp_ctx, "log file", logfile);
2155 talloc_free(logfile);
2157 lpcfg_do_global_parameter(lp_ctx, "log level", "0");
2159 lpcfg_do_global_parameter(lp_ctx, "syslog", "1");
2160 lpcfg_do_global_parameter(lp_ctx, "syslog only", "No");
2161 lpcfg_do_global_parameter(lp_ctx, "debug timestamp", "Yes");
2162 lpcfg_do_global_parameter(lp_ctx, "debug prefix timestamp", "No");
2163 lpcfg_do_global_parameter(lp_ctx, "debug hires timestamp", "Yes");
2164 lpcfg_do_global_parameter(lp_ctx, "debug pid", "No");
2165 lpcfg_do_global_parameter(lp_ctx, "debug uid", "No");
2166 lpcfg_do_global_parameter(lp_ctx, "debug class", "No");
2168 lpcfg_do_global_parameter(lp_ctx, "share backend", "classic");
2170 lpcfg_do_global_parameter(lp_ctx, "server role", "auto");
2171 lpcfg_do_global_parameter(lp_ctx, "domain logons", "No");
2172 lpcfg_do_global_parameter(lp_ctx, "domain master", "Auto");
2174 /* options that can be set on the command line must be initialised via
2175 the slower lpcfg_do_global_parameter() to ensure that FLAG_CMDLINE is obeyed */
2177 lpcfg_do_global_parameter(lp_ctx, "socket options", "TCP_NODELAY");
2179 lpcfg_do_global_parameter(lp_ctx, "workgroup", DEFAULT_WORKGROUP);
2180 myname = get_myname(lp_ctx);
2181 lpcfg_do_global_parameter(lp_ctx, "netbios name", myname);
2182 talloc_free(myname);
2183 lpcfg_do_global_parameter(lp_ctx, "name resolve order", "lmhosts wins host bcast");
2185 lpcfg_do_global_parameter(lp_ctx, "fstype", "NTFS");
2187 lpcfg_do_global_parameter(lp_ctx, "ntvfs handler", "unixuid default");
2188 lpcfg_do_global_parameter(lp_ctx, "max connections", "0");
2190 lpcfg_do_global_parameter(lp_ctx, "dcerpc endpoint servers", "epmapper wkssvc rpcecho samr netlogon lsarpc spoolss drsuapi dssetup unixinfo browser eventlog6 backupkey dnsserver");
2191 lpcfg_do_global_parameter(lp_ctx, "server services", "s3fs rpc nbt wrepl ldap cldap kdc drepl winbind ntp_signd kcc dnsupdate dns");
2192 lpcfg_do_global_parameter(lp_ctx, "kccsrv:samba_kcc", "true");
2193 /* the winbind method for domain controllers is for both RODC
2194 auth forwarding and for trusted domains */
2195 lpcfg_do_global_parameter(lp_ctx, "private dir", dyn_PRIVATE_DIR);
2196 lpcfg_do_global_parameter(lp_ctx, "registry:HKEY_LOCAL_MACHINE", "hklm.ldb");
2198 /* This hive should be dynamically generated by Samba using
2199 data from the sam, but for the moment leave it in a tdb to
2200 keep regedt32 from popping up an annoying dialog. */
2201 lpcfg_do_global_parameter(lp_ctx, "registry:HKEY_USERS", "hku.ldb");
2203 /* using UTF8 by default allows us to support all chars */
2204 lpcfg_do_global_parameter(lp_ctx, "unix charset", "UTF-8");
2206 /* Use codepage 850 as a default for the dos character set */
2207 lpcfg_do_global_parameter(lp_ctx, "dos charset", "CP850");
2210 * Allow the default PASSWD_CHAT to be overridden in local.h.
2212 lpcfg_do_global_parameter(lp_ctx, "passwd chat", DEFAULT_PASSWD_CHAT);
2214 lpcfg_do_global_parameter(lp_ctx, "pid directory", dyn_PIDDIR);
2215 lpcfg_do_global_parameter(lp_ctx, "lock dir", dyn_LOCKDIR);
2216 lpcfg_do_global_parameter(lp_ctx, "state directory", dyn_STATEDIR);
2217 lpcfg_do_global_parameter(lp_ctx, "cache directory", dyn_CACHEDIR);
2218 lpcfg_do_global_parameter(lp_ctx, "ncalrpc dir", dyn_NCALRPCDIR);
2220 lpcfg_do_global_parameter(lp_ctx, "nbt client socket address", "0.0.0.0");
2221 lpcfg_do_global_parameter_var(lp_ctx, "server string",
2222 "Samba %s", SAMBA_VERSION_STRING);
2224 lpcfg_do_global_parameter(lp_ctx, "password server", "*");
2226 lpcfg_do_global_parameter(lp_ctx, "max mux", "50");
2227 lpcfg_do_global_parameter(lp_ctx, "max xmit", "16644");
2228 lpcfg_do_global_parameter(lp_ctx, "host msdfs", "true");
2230 lpcfg_do_global_parameter(lp_ctx, "LargeReadwrite", "True");
2231 lpcfg_do_global_parameter(lp_ctx, "server min protocol", "LANMAN1");
2232 lpcfg_do_global_parameter(lp_ctx, "server max protocol", "SMB3");
2233 lpcfg_do_global_parameter(lp_ctx, "client min protocol", "CORE");
2234 lpcfg_do_global_parameter(lp_ctx, "client max protocol", "NT1");
2235 lpcfg_do_global_parameter(lp_ctx, "security", "AUTO");
2236 lpcfg_do_global_parameter(lp_ctx, "EncryptPasswords", "True");
2237 lpcfg_do_global_parameter(lp_ctx, "ReadRaw", "True");
2238 lpcfg_do_global_parameter(lp_ctx, "WriteRaw", "True");
2239 lpcfg_do_global_parameter(lp_ctx, "NullPasswords", "False");
2240 lpcfg_do_global_parameter(lp_ctx, "old password allowed period", "60");
2241 lpcfg_do_global_parameter(lp_ctx, "ObeyPamRestrictions", "False");
2243 lpcfg_do_global_parameter(lp_ctx, "TimeServer", "False");
2244 lpcfg_do_global_parameter(lp_ctx, "BindInterfacesOnly", "False");
2245 lpcfg_do_global_parameter(lp_ctx, "Unicode", "True");
2246 lpcfg_do_global_parameter(lp_ctx, "ClientLanManAuth", "False");
2247 lpcfg_do_global_parameter(lp_ctx, "ClientNTLMv2Auth", "True");
2248 lpcfg_do_global_parameter(lp_ctx, "LanmanAuth", "False");
2249 lpcfg_do_global_parameter(lp_ctx, "NTLMAuth", "True");
2250 lpcfg_do_global_parameter(lp_ctx, "client use spnego principal", "False");
2252 lpcfg_do_global_parameter(lp_ctx, "UnixExtensions", "True");
2254 lpcfg_do_global_parameter(lp_ctx, "PreferredMaster", "Auto");
2255 lpcfg_do_global_parameter(lp_ctx, "LocalMaster", "True");
2257 lpcfg_do_global_parameter(lp_ctx, "wins support", "False");
2258 lpcfg_do_global_parameter(lp_ctx, "dns proxy", "True");
2260 lpcfg_do_global_parameter(lp_ctx, "winbind separator", "\\");
2261 lpcfg_do_global_parameter(lp_ctx, "winbind sealed pipes", "True");
2262 lpcfg_do_global_parameter(lp_ctx, "require strong key", "True");
2263 lpcfg_do_global_parameter(lp_ctx, "winbindd socket directory", dyn_WINBINDD_SOCKET_DIR);
2264 lpcfg_do_global_parameter(lp_ctx, "winbindd privileged socket directory", dyn_WINBINDD_PRIVILEGED_SOCKET_DIR);
2265 lpcfg_do_global_parameter(lp_ctx, "ntp signd socket directory", dyn_NTP_SIGND_SOCKET_DIR);
2266 lpcfg_do_global_parameter_var(lp_ctx, "dns update command", "%s/samba_dnsupdate", dyn_SCRIPTSBINDIR);
2267 lpcfg_do_global_parameter_var(lp_ctx, "spn update command", "%s/samba_spnupdate", dyn_SCRIPTSBINDIR);
2268 lpcfg_do_global_parameter_var(lp_ctx, "samba kcc command",
2269 "%s/samba_kcc", dyn_SCRIPTSBINDIR);
2270 lpcfg_do_global_parameter(lp_ctx, "template shell", "/bin/false");
2271 lpcfg_do_global_parameter(lp_ctx, "template homedir", "/home/%WORKGROUP%/%ACCOUNTNAME%");
2273 lpcfg_do_global_parameter(lp_ctx, "client signing", "default");
2274 lpcfg_do_global_parameter(lp_ctx, "server signing", "default");
2276 lpcfg_do_global_parameter(lp_ctx, "use spnego", "True");
2278 lpcfg_do_global_parameter(lp_ctx, "use mmap", "True");
2280 lpcfg_do_global_parameter(lp_ctx, "smb ports", "445 139");
2281 lpcfg_do_global_parameter(lp_ctx, "nbt port", "137");
2282 lpcfg_do_global_parameter(lp_ctx, "dgram port", "138");
2283 lpcfg_do_global_parameter(lp_ctx, "cldap port", "389");
2284 lpcfg_do_global_parameter(lp_ctx, "krb5 port", "88");
2285 lpcfg_do_global_parameter(lp_ctx, "kpasswd port", "464");
2286 lpcfg_do_global_parameter(lp_ctx, "web port", "901");
2288 lpcfg_do_global_parameter(lp_ctx, "nt status support", "True");
2290 lpcfg_do_global_parameter(lp_ctx, "max wins ttl", "518400"); /* 6 days */
2291 lpcfg_do_global_parameter(lp_ctx, "min wins ttl", "21600");
2293 lpcfg_do_global_parameter(lp_ctx, "tls enabled", "True");
2294 lpcfg_do_global_parameter(lp_ctx, "tls keyfile", "tls/key.pem");
2295 lpcfg_do_global_parameter(lp_ctx, "tls certfile", "tls/cert.pem");
2296 lpcfg_do_global_parameter(lp_ctx, "tls cafile", "tls/ca.pem");
2297 lpcfg_do_global_parameter(lp_ctx, "prefork children:smb", "4");
2299 lpcfg_do_global_parameter(lp_ctx, "rndc command", "/usr/sbin/rndc");
2300 lpcfg_do_global_parameter(lp_ctx, "nsupdate command", "/usr/bin/nsupdate -g");
2302 lpcfg_do_global_parameter(lp_ctx, "allow dns updates", "secure only");
2303 lpcfg_do_global_parameter(lp_ctx, "dns forwarder", "");
2305 lpcfg_do_global_parameter(lp_ctx, "algorithmic rid base", "1000");
2307 lpcfg_do_global_parameter(lp_ctx, "enhanced browsing", "True");
2309 lpcfg_do_global_parameter(lp_ctx, "winbind nss info", "template");
2311 lpcfg_do_global_parameter(lp_ctx, "server schannel", "Auto");
2313 lpcfg_do_global_parameter(lp_ctx, "short preserve case", "True");
2315 lpcfg_do_global_parameter(lp_ctx, "max open files", "16384");
2317 lpcfg_do_global_parameter(lp_ctx, "cups connection timeout", "30");
2319 lpcfg_do_global_parameter(lp_ctx, "locking", "True");
2321 lpcfg_do_global_parameter(lp_ctx, "block size", "1024");
2323 lpcfg_do_global_parameter(lp_ctx, "client use spnego", "True");
2325 lpcfg_do_global_parameter(lp_ctx, "change notify", "True");
2327 lpcfg_do_global_parameter(lp_ctx, "name cache timeout", "660");
2329 lpcfg_do_global_parameter(lp_ctx, "defer sharing violations", "True");
2331 lpcfg_do_global_parameter(lp_ctx, "ldap replication sleep", "1000");
2333 lpcfg_do_global_parameter(lp_ctx, "idmap backend", "tdb");
2335 lpcfg_do_global_parameter(lp_ctx, "enable privileges", "True");
2337 lpcfg_do_global_parameter_var(lp_ctx, "smb2 max write", "%u", DEFAULT_SMB2_MAX_WRITE);
2339 lpcfg_do_global_parameter(lp_ctx, "passdb backend", "tdbsam");
2341 lpcfg_do_global_parameter(lp_ctx, "getwd cache", "True");
2343 lpcfg_do_global_parameter(lp_ctx, "winbind nested groups", "True");
2345 lpcfg_do_global_parameter(lp_ctx, "mangled names", "True");
2347 lpcfg_do_global_parameter_var(lp_ctx, "smb2 max credits", "%u", DEFAULT_SMB2_MAX_CREDITS);
2349 lpcfg_do_global_parameter(lp_ctx, "ldap ssl", "start tls");
2351 lpcfg_do_global_parameter(lp_ctx, "ldap deref", "auto");
2353 lpcfg_do_global_parameter(lp_ctx, "lm interval", "60");
2355 lpcfg_do_global_parameter(lp_ctx, "mangling method", "hash2");
2357 lpcfg_do_global_parameter(lp_ctx, "hide dot files", "True");
2359 lpcfg_do_global_parameter(lp_ctx, "browse list", "True");
2361 lpcfg_do_global_parameter(lp_ctx, "passwd chat timeout", "2");
2363 lpcfg_do_global_parameter(lp_ctx, "guest account", GUEST_ACCOUNT);
2365 lpcfg_do_global_parameter(lp_ctx, "client schannel", "auto");
2367 lpcfg_do_global_parameter(lp_ctx, "smb encrypt", "default");
2369 lpcfg_do_global_parameter(lp_ctx, "max log size", "5000");
2371 lpcfg_do_global_parameter(lp_ctx, "idmap negative cache time", "120");
2373 lpcfg_do_global_parameter(lp_ctx, "ldap follow referral", "auto");
2375 lpcfg_do_global_parameter(lp_ctx, "multicast dns register", "yes");
2377 lpcfg_do_global_parameter(lp_ctx, "winbind reconnect delay", "30");
2379 lpcfg_do_global_parameter(lp_ctx, "nt acl support", "yes");
2381 lpcfg_do_global_parameter(lp_ctx, "acl check permissions", "yes");
2383 lpcfg_do_global_parameter(lp_ctx, "keepalive", "300");
2385 lpcfg_do_global_parameter(lp_ctx, "winbind cache time", "300");
2387 lpcfg_do_global_parameter(lp_ctx, "level2 oplocks", "yes");
2389 lpcfg_do_global_parameter(lp_ctx, "show add printer wizard", "yes");
2391 lpcfg_do_global_parameter(lp_ctx, "allocation roundup size", "1048576");
2393 lpcfg_do_global_parameter(lp_ctx, "ldap page size", "1024");
2395 lpcfg_do_global_parameter(lp_ctx, "kernel share modes", "yes");
2397 lpcfg_do_global_parameter(lp_ctx, "strict locking", "Auto");
2399 lpcfg_do_global_parameter(lp_ctx, "map readonly", "yes");
2401 lpcfg_do_global_parameter(lp_ctx, "allow trusted domains", "yes");
2403 lpcfg_do_global_parameter(lp_ctx, "default devmode", "yes");
2405 lpcfg_do_global_parameter(lp_ctx, "os level", "20");
2407 lpcfg_do_global_parameter(lp_ctx, "dos filetimes", "yes");
2409 lpcfg_do_global_parameter(lp_ctx, "mangling char", "~");
2411 lpcfg_do_global_parameter(lp_ctx, "printcap cache time", "750");
2413 lpcfg_do_global_parameter(lp_ctx, "create krb5 conf", "yes");
2415 lpcfg_do_global_parameter(lp_ctx, "winbind max clients", "200");
2417 lpcfg_do_global_parameter(lp_ctx, "acl map full control", "yes");
2419 lpcfg_do_global_parameter(lp_ctx, "nt pipe support", "yes");
2421 lpcfg_do_global_parameter(lp_ctx, "ldap debug threshold", "10");
2423 lpcfg_do_global_parameter(lp_ctx, "follow symlinks", "yes");
2425 lpcfg_do_global_parameter(lp_ctx, "machine password timeout", "604800");
2427 lpcfg_do_global_parameter(lp_ctx, "ldap connection timeout", "2");
2429 lpcfg_do_global_parameter(lp_ctx, "winbind expand groups", "1");
2431 lpcfg_do_global_parameter(lp_ctx, "stat cache", "yes");
2433 lpcfg_do_global_parameter(lp_ctx, "lpq cache time", "30");
2435 lpcfg_do_global_parameter_var(lp_ctx, "smb2 max trans", "%u", DEFAULT_SMB2_MAX_TRANSACT);
2437 lpcfg_do_global_parameter_var(lp_ctx, "smb2 max read", "%u", DEFAULT_SMB2_MAX_READ);
2439 lpcfg_do_global_parameter(lp_ctx, "durable handles", "yes");
2441 lpcfg_do_global_parameter(lp_ctx, "max stat cache size", "256");
2443 lpcfg_do_global_parameter(lp_ctx, "ldap passwd sync", "no");
2445 lpcfg_do_global_parameter(lp_ctx, "kernel change notify", "yes");
2447 lpcfg_do_global_parameter(lp_ctx, "max ttl", "259200");
2449 lpcfg_do_global_parameter(lp_ctx, "blocking locks", "yes");
2451 lpcfg_do_global_parameter(lp_ctx, "oplock contention limit", "2");
2453 lpcfg_do_global_parameter(lp_ctx, "load printers", "yes");
2455 lpcfg_do_global_parameter(lp_ctx, "idmap cache time", "604800");
2457 lpcfg_do_global_parameter(lp_ctx, "preserve case", "yes");
2459 lpcfg_do_global_parameter(lp_ctx, "lm announce", "auto");
2461 lpcfg_do_global_parameter(lp_ctx, "afs token lifetime", "604800");
2463 lpcfg_do_global_parameter(lp_ctx, "enable core files", "yes");
2465 lpcfg_do_global_parameter(lp_ctx, "winbind max domain connections", "1");
2467 lpcfg_do_global_parameter(lp_ctx, "case sensitive", "auto");
2469 lpcfg_do_global_parameter(lp_ctx, "ldap timeout", "15");
2471 lpcfg_do_global_parameter(lp_ctx, "mangle prefix", "1");
2473 lpcfg_do_global_parameter(lp_ctx, "posix locking", "yes");
2475 lpcfg_do_global_parameter(lp_ctx, "lock spin time", "200");
2477 lpcfg_do_global_parameter(lp_ctx, "directory name cache size", "100");
2479 lpcfg_do_global_parameter(lp_ctx, "nmbd bind explicit broadcast", "yes");
2481 lpcfg_do_global_parameter(lp_ctx, "init logon delay", "100");
2483 lpcfg_do_global_parameter(lp_ctx, "usershare owner only", "yes");
2485 lpcfg_do_global_parameter(lp_ctx, "-valid", "yes");
2487 lpcfg_do_global_parameter_var(lp_ctx, "usershare path", "%s/usershares", get_dyn_STATEDIR());
2490 lpcfg_do_global_parameter_var(lp_ctx, "panic action", "/bin/sleep 999999999");
2493 lpcfg_do_global_parameter(lp_ctx, "smb passwd file", get_dyn_SMB_PASSWD_FILE());
2495 lpcfg_do_global_parameter(lp_ctx, "logon home", "\\\\%N\\%U");
2497 lpcfg_do_global_parameter(lp_ctx, "logon path", "\\\\%N\\%U\\profile");
2499 lpcfg_do_global_parameter(lp_ctx, "printjob username", "%U");
2501 for (i = 0; parm_table[i].label; i++) {
2502 if (!(lp_ctx->flags[i] & FLAG_CMDLINE)) {
2503 lp_ctx->flags[i] |= FLAG_DEFAULT;
2507 for (parm=lp_ctx->globals->param_opt; parm; parm=parm->next) {
2508 if (!(parm->priority & FLAG_CMDLINE)) {
2509 parm->priority |= FLAG_DEFAULT;
2517 * Initialise the global parameter structure.
2519 struct loadparm_context *loadparm_init_global(bool load_default)
2521 if (global_loadparm_context == NULL) {
2522 global_loadparm_context = loadparm_init(NULL);
2524 if (global_loadparm_context == NULL) {
2527 global_loadparm_context->global = true;
2528 if (load_default && !global_loadparm_context->loaded) {
2529 lpcfg_load_default(global_loadparm_context);
2531 global_loadparm_context->refuse_free = true;
2532 return global_loadparm_context;
2536 * Initialise the global parameter structure.
2538 struct loadparm_context *loadparm_init_s3(TALLOC_CTX *mem_ctx,
2539 const struct loadparm_s3_helpers *s3_fns)
2541 struct loadparm_context *loadparm_context = talloc_zero(mem_ctx, struct loadparm_context);
2542 if (!loadparm_context) {
2545 loadparm_context->s3_fns = s3_fns;
2546 loadparm_context->globals = s3_fns->globals;
2547 return loadparm_context;
2550 const char *lpcfg_configfile(struct loadparm_context *lp_ctx)
2552 return lp_ctx->szConfigFile;
2555 const char *lp_default_path(void)
2557 if (getenv("SMB_CONF_PATH"))
2558 return getenv("SMB_CONF_PATH");
2560 return dyn_CONFIGFILE;
2564 * Update the internal state of a loadparm context after settings
2567 static bool lpcfg_update(struct loadparm_context *lp_ctx)
2569 struct debug_settings settings;
2570 TALLOC_CTX *tmp_ctx;
2572 tmp_ctx = talloc_new(lp_ctx);
2573 if (tmp_ctx == NULL) {
2577 lpcfg_add_auto_services(lp_ctx, lpcfg_auto_services(lp_ctx, tmp_ctx));
2579 if (!lp_ctx->globals->wins_server_list && lp_ctx->globals->we_are_a_wins_server) {
2580 lpcfg_do_global_parameter(lp_ctx, "wins server", "127.0.0.1");
2583 if (!lp_ctx->global) {
2584 TALLOC_FREE(tmp_ctx);
2588 panic_action = lp_ctx->globals->panic_action;
2590 reload_charcnv(lp_ctx);
2592 ZERO_STRUCT(settings);
2593 /* Add any more debug-related smb.conf parameters created in
2595 settings.syslog = lp_ctx->globals->syslog;
2596 settings.syslog_only = lp_ctx->globals->syslog_only;
2597 settings.timestamp_logs = lp_ctx->globals->timestamp_logs;
2598 settings.debug_prefix_timestamp = lp_ctx->globals->debug_prefix_timestamp;
2599 settings.debug_hires_timestamp = lp_ctx->globals->debug_hires_timestamp;
2600 settings.debug_pid = lp_ctx->globals->debug_pid;
2601 settings.debug_uid = lp_ctx->globals->debug_uid;
2602 settings.debug_class = lp_ctx->globals->debug_class;
2603 debug_set_settings(&settings);
2605 /* FIXME: This is a bit of a hack, but we can't use a global, since
2606 * not everything that uses lp also uses the socket library */
2607 if (lpcfg_parm_bool(lp_ctx, NULL, "socket", "testnonblock", false)) {
2608 setenv("SOCKET_TESTNONBLOCK", "1", 1);
2610 unsetenv("SOCKET_TESTNONBLOCK");
2613 TALLOC_FREE(tmp_ctx);
2617 bool lpcfg_load_default(struct loadparm_context *lp_ctx)
2621 path = lp_default_path();
2623 if (!file_exist(path)) {
2624 /* We allow the default smb.conf file to not exist,
2625 * basically the equivalent of an empty file. */
2626 return lpcfg_update(lp_ctx);
2629 return lpcfg_load(lp_ctx, path);
2633 * Load the services array from the services file.
2635 * Return True on success, False on failure.
2637 bool lpcfg_load(struct loadparm_context *lp_ctx, const char *filename)
2642 filename = talloc_strdup(lp_ctx, filename);
2644 lp_ctx->szConfigFile = filename;
2646 if (lp_ctx->s3_fns) {
2647 return lp_ctx->s3_fns->load(filename);
2650 lp_ctx->bInGlobalSection = true;
2651 n2 = standard_sub_basic(lp_ctx, lp_ctx->szConfigFile);
2652 DEBUG(2, ("lpcfg_load: refreshing parameters from %s\n", n2));
2654 add_to_file_list(lp_ctx, &lp_ctx->file_lists, lp_ctx->szConfigFile, n2);
2656 /* We get sections first, so have to start 'behind' to make up */
2657 lp_ctx->currentService = NULL;
2658 bRetval = pm_process(n2, do_section, do_parameter, lp_ctx);
2660 /* finish up the last section */
2661 DEBUG(4, ("pm_process() returned %s\n", BOOLSTR(bRetval)));
2663 if (lp_ctx->currentService != NULL)
2664 bRetval = lpcfg_service_ok(lp_ctx->currentService);
2666 bRetval = bRetval && lpcfg_update(lp_ctx);
2668 /* we do this unconditionally, so that it happens even
2669 for a missing smb.conf */
2670 reload_charcnv(lp_ctx);
2672 if (bRetval == true) {
2673 /* set this up so that any child python tasks will
2674 find the right smb.conf */
2675 setenv("SMB_CONF_PATH", filename, 1);
2677 /* set the context used by the lp_*() function
2679 global_loadparm_context = lp_ctx;
2680 lp_ctx->loaded = true;
2687 * Return the max number of services.
2690 int lpcfg_numservices(struct loadparm_context *lp_ctx)
2692 if (lp_ctx->s3_fns) {
2693 return lp_ctx->s3_fns->get_numservices();
2696 return lp_ctx->iNumServices;
2700 * Display the contents of the services array in human-readable form.
2703 void lpcfg_dump(struct loadparm_context *lp_ctx, FILE *f, bool show_defaults,
2708 if (lp_ctx->s3_fns) {
2709 lp_ctx->s3_fns->dump(f, show_defaults, maxtoprint);
2713 dump_globals(lp_ctx, f, show_defaults);
2715 lpcfg_dump_a_service(lp_ctx->sDefault, lp_ctx->sDefault, f, lp_ctx->flags, show_defaults);
2717 for (iService = 0; iService < maxtoprint; iService++)
2718 lpcfg_dump_one(f, show_defaults, lp_ctx->services[iService], lp_ctx->sDefault);
2722 * Display the contents of one service in human-readable form.
2724 void lpcfg_dump_one(FILE *f, bool show_defaults, struct loadparm_service *service, struct loadparm_service *sDefault)
2726 if (service != NULL) {
2727 if (service->szService[0] == '\0')
2729 lpcfg_dump_a_service(service, sDefault, f, NULL, show_defaults);
2733 struct loadparm_service *lpcfg_servicebynum(struct loadparm_context *lp_ctx,
2736 if (lp_ctx->s3_fns) {
2737 return lp_ctx->s3_fns->get_servicebynum(snum);
2740 return lp_ctx->services[snum];
2743 struct loadparm_service *lpcfg_service(struct loadparm_context *lp_ctx,
2744 const char *service_name)
2749 if (lp_ctx->s3_fns) {
2750 return lp_ctx->s3_fns->get_service(service_name);
2753 for (iService = lp_ctx->iNumServices - 1; iService >= 0; iService--) {
2754 if (lp_ctx->services[iService] &&
2755 lp_ctx->services[iService]->szService) {
2757 * The substitution here is used to support %U is
2760 serviceName = standard_sub_basic(
2761 lp_ctx->services[iService],
2762 lp_ctx->services[iService]->szService);
2763 if (strequal(serviceName, service_name)) {
2764 talloc_free(serviceName);
2765 return lp_ctx->services[iService];
2767 talloc_free(serviceName);
2771 DEBUG(7,("lpcfg_servicenumber: couldn't find %s\n", service_name));
2775 const char *lpcfg_servicename(const struct loadparm_service *service)
2777 return lpcfg_string((const char *)service->szService);
2781 * A useful volume label function.
2783 const char *lpcfg_volume_label(struct loadparm_service *service, struct loadparm_service *sDefault)
2786 ret = lpcfg_string((const char *)((service != NULL && service->volume != NULL) ?
2787 service->volume : sDefault->volume));
2789 return lpcfg_servicename(service);
2794 * Return the correct printer name.
2796 const char *lpcfg_printername(struct loadparm_service *service, struct loadparm_service *sDefault)
2799 ret = lpcfg_string((const char *)((service != NULL && service->_printername != NULL) ?
2800 service->_printername : sDefault->_printername));
2801 if (ret == NULL || (ret != NULL && *ret == '\0'))
2802 ret = lpcfg_servicename(service);
2809 * Return the max print jobs per queue.
2811 int lpcfg_maxprintjobs(struct loadparm_service *service, struct loadparm_service *sDefault)
2813 int maxjobs = (service != NULL) ? service->iMaxPrintJobs : sDefault->iMaxPrintJobs;
2814 if (maxjobs <= 0 || maxjobs >= PRINT_MAX_JOBID)
2815 maxjobs = PRINT_MAX_JOBID - 1;
2820 struct smb_iconv_handle *lpcfg_iconv_handle(struct loadparm_context *lp_ctx)
2822 if (lp_ctx == NULL) {
2823 return get_iconv_handle();
2825 return lp_ctx->iconv_handle;
2828 _PUBLIC_ void reload_charcnv(struct loadparm_context *lp_ctx)
2830 struct smb_iconv_handle *old_ic = lp_ctx->iconv_handle;
2831 if (!lp_ctx->global) {
2835 if (old_ic == NULL) {
2836 old_ic = global_iconv_handle;
2838 lp_ctx->iconv_handle = smb_iconv_handle_reinit_lp(lp_ctx, lp_ctx, old_ic);
2839 global_iconv_handle = lp_ctx->iconv_handle;
2842 _PUBLIC_ char *lpcfg_tls_keyfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
2844 return lpcfg_private_path(mem_ctx, lp_ctx, lpcfg__tls_keyfile(lp_ctx));
2847 _PUBLIC_ char *lpcfg_tls_certfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
2849 return lpcfg_private_path(mem_ctx, lp_ctx, lpcfg__tls_certfile(lp_ctx));
2852 _PUBLIC_ char *lpcfg_tls_cafile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
2854 return lpcfg_private_path(mem_ctx, lp_ctx, lpcfg__tls_cafile(lp_ctx));
2857 _PUBLIC_ char *lpcfg_tls_crlfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
2859 return lpcfg_private_path(mem_ctx, lp_ctx, lpcfg__tls_crlfile(lp_ctx));
2862 _PUBLIC_ char *lpcfg_tls_dhpfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
2864 return lpcfg_private_path(mem_ctx, lp_ctx, lpcfg__tls_dhpfile(lp_ctx));
2867 struct gensec_settings *lpcfg_gensec_settings(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
2869 struct gensec_settings *settings = talloc_zero(mem_ctx, struct gensec_settings);
2870 if (settings == NULL)
2872 SMB_ASSERT(lp_ctx != NULL);
2873 settings->lp_ctx = talloc_reference(settings, lp_ctx);
2874 settings->target_hostname = lpcfg_parm_string(lp_ctx, NULL, "gensec", "target_hostname");
2878 int lpcfg_server_role(struct loadparm_context *lp_ctx)
2880 int domain_master = lpcfg__domain_master(lp_ctx);
2882 return lp_find_server_role(lpcfg__server_role(lp_ctx),
2883 lpcfg__security(lp_ctx),
2884 lpcfg__domain_logons(lp_ctx),
2885 (domain_master == true) ||
2886 (domain_master == Auto));
2889 int lpcfg_security(struct loadparm_context *lp_ctx)
2891 return lp_find_security(lpcfg__server_role(lp_ctx),
2892 lpcfg__security(lp_ctx));
2895 bool lpcfg_server_signing_allowed(struct loadparm_context *lp_ctx, bool *mandatory)
2897 bool allowed = true;
2898 enum smb_signing_setting signing_setting = lpcfg_server_signing(lp_ctx);
2902 if (signing_setting == SMB_SIGNING_DEFAULT) {
2904 * If we are a domain controller, SMB signing is
2905 * really important, as it can prevent a number of
2906 * attacks on communications between us and the
2909 * However, it really sucks (no sendfile, CPU
2910 * overhead) performance-wise when used on a
2911 * file server, so disable it by default
2915 if (lpcfg_server_role(lp_ctx) >= ROLE_ACTIVE_DIRECTORY_DC) {
2916 signing_setting = SMB_SIGNING_REQUIRED;
2918 signing_setting = SMB_SIGNING_OFF;
2922 switch (signing_setting) {
2923 case SMB_SIGNING_REQUIRED:
2926 case SMB_SIGNING_IF_REQUIRED:
2928 case SMB_SIGNING_DEFAULT:
2929 case SMB_SIGNING_OFF:
2937 int lpcfg_tdb_hash_size(struct loadparm_context *lp_ctx, const char *name)
2945 base = strrchr_m(name, '/');
2951 return lpcfg_parm_int(lp_ctx, NULL, "tdb_hashsize", base, 0);
2955 int lpcfg_tdb_flags(struct loadparm_context *lp_ctx, int tdb_flags)
2957 if (!lpcfg_use_mmap(lp_ctx)) {
2958 tdb_flags |= TDB_NOMMAP;