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 #include "lib/param/param_global.h"
75 struct loadparm_service *lpcfg_default_service(struct loadparm_context *lp_ctx)
77 return lp_ctx->sDefault;
81 * Convenience routine to grab string parameters into temporary memory
82 * and run standard_sub_basic on them.
84 * The buffers can be written to by
85 * callers without affecting the source string.
88 static const char *lpcfg_string(const char *s)
90 #if 0 /* until REWRITE done to make thread-safe */
91 size_t len = s ? strlen(s) : 0;
95 /* The follow debug is useful for tracking down memory problems
96 especially if you have an inner loop that is calling a lp_*()
97 function that returns a string. Perhaps this debug should be
98 present all the time? */
101 DEBUG(10, ("lpcfg_string(%s)\n", s));
104 #if 0 /* until REWRITE done to make thread-safe */
106 lp_talloc = talloc_init("lp_talloc");
108 ret = talloc_array(lp_talloc, char, len + 100); /* leave room for substitution */
116 strlcpy(ret, s, len);
118 if (trim_string(ret, "\"", "\"")) {
119 if (strchr(ret,'"') != NULL)
120 strlcpy(ret, s, len);
123 standard_sub_basic(ret,len+100);
130 In this section all the functions that are used to access the
131 parameters from the rest of the program are defined
135 * the creation of separate lpcfg_*() and lp_*() functions is to allow
136 * for code compatibility between existing Samba4 and Samba3 code.
139 /* this global context supports the lp_*() function varients */
140 static struct loadparm_context *global_loadparm_context;
142 #define lpcfg_default_service global_loadparm_context->sDefault
143 #define lpcfg_global_service(i) global_loadparm_context->services[i]
145 #define FN_GLOBAL_STRING(fn_name,var_name) \
146 _PUBLIC_ char *lpcfg_ ## fn_name(struct loadparm_context *lp_ctx, TALLOC_CTX *ctx) {\
147 if (lp_ctx == NULL) return NULL; \
148 if (lp_ctx->s3_fns) { \
149 return lp_ctx->globals->var_name ? lp_ctx->s3_fns->lp_string(ctx, lp_ctx->globals->var_name) : talloc_strdup(ctx, ""); \
151 return lp_ctx->globals->var_name ? talloc_strdup(ctx, lpcfg_string(lp_ctx->globals->var_name)) : talloc_strdup(ctx, ""); \
154 #define FN_GLOBAL_CONST_STRING(fn_name,var_name) \
155 _PUBLIC_ const char *lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) { \
156 if (lp_ctx == NULL) return NULL; \
157 return lp_ctx->globals->var_name ? lpcfg_string(lp_ctx->globals->var_name) : ""; \
160 #define FN_GLOBAL_LIST(fn_name,var_name) \
161 _PUBLIC_ const char **lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) { \
162 if (lp_ctx == NULL) return NULL; \
163 return lp_ctx->globals->var_name; \
166 #define FN_GLOBAL_BOOL(fn_name,var_name) \
167 _PUBLIC_ bool lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) {\
168 if (lp_ctx == NULL) return false; \
169 return lp_ctx->globals->var_name; \
172 #define FN_GLOBAL_INTEGER(fn_name,var_name) \
173 _PUBLIC_ int lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) { \
174 return lp_ctx->globals->var_name; \
177 /* Local parameters don't need the ->s3_fns because the struct
178 * loadparm_service is shared and lpcfg_service() checks the ->s3_fns
180 #define FN_LOCAL_STRING(fn_name,val) \
181 _PUBLIC_ char *lpcfg_ ## fn_name(struct loadparm_service *service, \
182 struct loadparm_service *sDefault, TALLOC_CTX *ctx) { \
183 return(talloc_strdup(ctx, lpcfg_string((const char *)((service != NULL && service->val != NULL) ? service->val : sDefault->val)))); \
186 #define FN_LOCAL_CONST_STRING(fn_name,val) \
187 _PUBLIC_ const char *lpcfg_ ## fn_name(struct loadparm_service *service, \
188 struct loadparm_service *sDefault) { \
189 return((const char *)((service != NULL && service->val != NULL) ? service->val : sDefault->val)); \
192 #define FN_LOCAL_LIST(fn_name,val) \
193 _PUBLIC_ const char **lpcfg_ ## fn_name(struct loadparm_service *service, \
194 struct loadparm_service *sDefault) {\
195 return(const char **)(service != NULL && service->val != NULL? service->val : sDefault->val); \
198 #define FN_LOCAL_PARM_BOOL(fn_name, val) FN_LOCAL_BOOL(fn_name, val)
200 #define FN_LOCAL_BOOL(fn_name,val) \
201 _PUBLIC_ bool lpcfg_ ## fn_name(struct loadparm_service *service, \
202 struct loadparm_service *sDefault) { \
203 return((service != NULL)? service->val : sDefault->val); \
206 #define FN_LOCAL_INTEGER(fn_name,val) \
207 _PUBLIC_ int lpcfg_ ## fn_name(struct loadparm_service *service, \
208 struct loadparm_service *sDefault) { \
209 return((service != NULL)? service->val : sDefault->val); \
212 #define FN_LOCAL_PARM_INTEGER(fn_name, val) FN_LOCAL_INTEGER(fn_name, val)
214 #define FN_LOCAL_PARM_CHAR(fn_name,val) \
215 _PUBLIC_ char lpcfg_ ## fn_name(struct loadparm_service *service, \
216 struct loadparm_service *sDefault) { \
217 return((service != NULL)? service->val : sDefault->val); \
220 #include "lib/param/param_functions.c"
222 /* These functions cannot be auto-generated */
223 FN_LOCAL_BOOL(autoloaded, autoloaded)
224 FN_GLOBAL_CONST_STRING(dnsdomain, dnsdomain)
226 /* local prototypes */
227 static struct loadparm_service *lpcfg_getservicebyname(struct loadparm_context *lp_ctx,
228 const char *pszServiceName);
229 static bool do_section(const char *pszSectionName, void *);
230 static bool set_variable_helper(TALLOC_CTX *mem_ctx, int parmnum, void *parm_ptr,
231 const char *pszParmName, const char *pszParmValue);
232 static bool lp_do_parameter_parametric(struct loadparm_context *lp_ctx,
233 struct loadparm_service *service,
234 const char *pszParmName,
235 const char *pszParmValue, int flags);
237 /* The following are helper functions 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 struct parmlist_entry *get_parametric_helper(struct loadparm_service *service,
241 const char *type, const char *option,
242 struct parmlist_entry *global_opts)
245 struct parmlist_entry *data = NULL;
246 TALLOC_CTX *mem_ctx = talloc_stackframe();
248 param_key = talloc_asprintf(mem_ctx, "%s:%s", type, option);
249 if (param_key == NULL) {
250 DEBUG(0,("asprintf failed!\n"));
251 TALLOC_FREE(mem_ctx);
256 * Try to fetch the option from the data.
258 if (service != NULL) {
259 data = service->param_opt;
260 while (data != NULL) {
261 if (strwicmp(data->key, param_key) == 0) {
262 TALLOC_FREE(mem_ctx);
270 * Fall back to fetching from the globals.
273 while (data != NULL) {
274 if (strwicmp(data->key, param_key) == 0) {
275 TALLOC_FREE(mem_ctx);
282 TALLOC_FREE(mem_ctx);
289 const char *lpcfg_get_parametric(struct loadparm_context *lp_ctx,
290 struct loadparm_service *service,
291 const char *type, const char *option)
293 struct parmlist_entry *data;
298 data = get_parametric_helper(service,
299 type, option, lp_ctx->globals->param_opt);
310 * convenience routine to return int parameters.
312 int lp_int(const char *s)
316 DEBUG(0,("lp_int(%s): is called with NULL!\n",s));
320 return strtol(s, NULL, 0);
324 * convenience routine to return unsigned long parameters.
326 unsigned long lp_ulong(const char *s)
330 DEBUG(0,("lp_ulong(%s): is called with NULL!\n",s));
334 return strtoul(s, NULL, 0);
338 * convenience routine to return unsigned long parameters.
340 static long lp_long(const char *s)
344 DEBUG(0,("lp_long(%s): is called with NULL!\n",s));
348 return strtol(s, NULL, 0);
352 * convenience routine to return unsigned long parameters.
354 static double lp_double(const char *s)
358 DEBUG(0,("lp_double(%s): is called with NULL!\n",s));
362 return strtod(s, NULL);
366 * convenience routine to return boolean parameters.
368 bool lp_bool(const char *s)
373 DEBUG(0,("lp_bool(%s): is called with NULL!\n",s));
377 if (!set_boolean(s, &ret)) {
378 DEBUG(0,("lp_bool(%s): value is not boolean!\n",s));
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(struct loadparm_context *lp_ctx,
392 struct loadparm_service *service, const char *type,
395 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
398 return lpcfg_string(value);
404 * Return parametric option from a given service. Type is a part of option before ':'
405 * Parametric option has following syntax: 'Type: option = value'
406 * Returned value is allocated in 'lp_talloc' context
409 const char **lpcfg_parm_string_list(TALLOC_CTX *mem_ctx,
410 struct loadparm_context *lp_ctx,
411 struct loadparm_service *service,
413 const char *option, const char *separator)
415 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
418 return (const char **)str_list_make(mem_ctx, value, separator);
424 * Return parametric option from a given service. Type is a part of option before ':'
425 * Parametric option has following syntax: 'Type: option = value'
428 int lpcfg_parm_int(struct loadparm_context *lp_ctx,
429 struct loadparm_service *service, const char *type,
430 const char *option, int default_v)
432 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
435 return lp_int(value);
441 * Return parametric option from a given service. Type is a part of
443 * Parametric option has following syntax: 'Type: option = value'.
446 int lpcfg_parm_bytes(struct loadparm_context *lp_ctx,
447 struct loadparm_service *service, const char *type,
448 const char *option, int default_v)
452 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
454 if (value && conv_str_size_error(value, &bval)) {
455 if (bval <= INT_MAX) {
464 * Return parametric option from a given service.
465 * Type is a part of option before ':'
466 * Parametric option has following syntax: 'Type: option = value'
468 unsigned long lpcfg_parm_ulong(struct loadparm_context *lp_ctx,
469 struct loadparm_service *service, const char *type,
470 const char *option, unsigned long default_v)
472 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
475 return lp_ulong(value);
480 long lpcfg_parm_long(struct loadparm_context *lp_ctx,
481 struct loadparm_service *service, const char *type,
482 const char *option, long default_v)
484 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
487 return lp_long(value);
492 double lpcfg_parm_double(struct loadparm_context *lp_ctx,
493 struct loadparm_service *service, const char *type,
494 const char *option, double default_v)
496 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
499 return lp_double(value);
505 * Return parametric option from a given service. Type is a part of option before ':'
506 * Parametric option has following syntax: 'Type: option = value'
509 bool lpcfg_parm_bool(struct loadparm_context *lp_ctx,
510 struct loadparm_service *service, const char *type,
511 const char *option, bool default_v)
513 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
516 return lp_bool(value);
523 * Set a string value, deallocating any existing space, and allocing the space
526 bool lpcfg_string_set(TALLOC_CTX *mem_ctx, char **dest, const char *src)
533 *dest = talloc_strdup(mem_ctx, src);
534 if ((*dest) == NULL) {
535 DEBUG(0,("Out of memory in string_set\n"));
543 * Set a string value, deallocating any existing space, and allocing the space
546 bool lpcfg_string_set_upper(TALLOC_CTX *mem_ctx, char **dest, const char *src)
553 *dest = strupper_talloc(mem_ctx, src);
554 if ((*dest) == NULL) {
555 DEBUG(0,("Out of memory in string_set_upper\n"));
565 * Add a new service to the services array initialising it with the given
569 struct loadparm_service *lpcfg_add_service(struct loadparm_context *lp_ctx,
570 const struct loadparm_service *pservice,
574 int num_to_alloc = lp_ctx->iNumServices + 1;
575 struct parmlist_entry *data, *pdata;
577 if (lp_ctx->s3_fns != NULL) {
578 smb_panic("Add a service should not be called on an s3 loadparm ctx");
581 if (pservice == NULL) {
582 pservice = lp_ctx->sDefault;
585 /* it might already exist */
587 struct loadparm_service *service = lpcfg_getservicebyname(lp_ctx,
589 if (service != NULL) {
590 /* Clean all parametric options for service */
591 /* They will be added during parsing again */
592 data = service->param_opt;
598 service->param_opt = NULL;
603 /* find an invalid one */
604 for (i = 0; i < lp_ctx->iNumServices; i++)
605 if (lp_ctx->services[i] == NULL)
608 /* if not, then create one */
609 if (i == lp_ctx->iNumServices) {
610 struct loadparm_service **tsp;
612 tsp = talloc_realloc(lp_ctx, lp_ctx->services, struct loadparm_service *, num_to_alloc);
615 DEBUG(0,("lpcfg_add_service: failed to enlarge services!\n"));
618 lp_ctx->services = tsp;
619 lp_ctx->services[lp_ctx->iNumServices] = NULL;
622 lp_ctx->iNumServices++;
625 lp_ctx->services[i] = talloc_zero(lp_ctx->services, struct loadparm_service);
626 if (lp_ctx->services[i] == NULL) {
627 DEBUG(0,("lpcfg_add_service: out of memory!\n"));
630 copy_service(lp_ctx->services[i], pservice, NULL);
632 lpcfg_string_set(lp_ctx->services[i], &lp_ctx->services[i]->szService, name);
633 return lp_ctx->services[i];
637 * Add a new home service, with the specified home directory, defaults coming
638 * from service ifrom.
641 bool lpcfg_add_home(struct loadparm_context *lp_ctx,
642 const char *pszHomename,
643 struct loadparm_service *default_service,
644 const char *user, const char *pszHomedir)
646 struct loadparm_service *service;
648 service = lpcfg_add_service(lp_ctx, default_service, pszHomename);
653 if (!(*(default_service->path))
654 || strequal(default_service->path, lp_ctx->sDefault->path)) {
655 service->path = talloc_strdup(service, pszHomedir);
657 service->path = string_sub_talloc(service, lpcfg_path(default_service, lp_ctx->sDefault, service), "%H", pszHomedir);
660 if (!(*(service->comment))) {
661 service->comment = talloc_asprintf(service, "Home directory of %s", user);
663 service->bAvailable = default_service->bAvailable;
664 service->browseable = default_service->browseable;
666 DEBUG(3, ("adding home's share [%s] for user '%s' at '%s'\n",
667 pszHomename, user, service->path));
673 * Add a new printer service, with defaults coming from service iFrom.
676 bool lpcfg_add_printer(struct loadparm_context *lp_ctx,
677 const char *pszPrintername,
678 struct loadparm_service *default_service)
680 const char *comment = "From Printcap";
681 struct loadparm_service *service;
682 service = lpcfg_add_service(lp_ctx, default_service, pszPrintername);
687 /* note that we do NOT default the availability flag to True - */
688 /* we take it from the default service passed. This allows all */
689 /* dynamic printers to be disabled by disabling the [printers] */
690 /* entry (if/when the 'available' keyword is implemented!). */
692 /* the printer name is set to the service name. */
693 lpcfg_string_set(service, &service->_printername, pszPrintername);
694 lpcfg_string_set(service, &service->comment, comment);
695 service->browseable = default_service->browseable;
696 /* Printers cannot be read_only. */
697 service->read_only = false;
698 /* Printer services must be printable. */
699 service->printable = true;
701 DEBUG(3, ("adding printer service %s\n", pszPrintername));
707 * Map a parameter's string representation to something we can use.
708 * Returns False if the parameter string is not recognised, else TRUE.
711 int lpcfg_map_parameter(const char *pszParmName)
715 for (iIndex = 0; parm_table[iIndex].label; iIndex++)
716 if (strwicmp(parm_table[iIndex].label, pszParmName) == 0)
719 /* Warn only if it isn't parametric option */
720 if (strchr(pszParmName, ':') == NULL)
721 DEBUG(0, ("Unknown parameter encountered: \"%s\"\n", pszParmName));
722 /* We do return 'fail' for parametric options as well because they are
723 stored in different storage
730 return the parameter structure for a parameter
732 struct parm_struct *lpcfg_parm_struct(struct loadparm_context *lp_ctx, const char *name)
734 int num = lpcfg_map_parameter(name);
740 return &parm_table[num];
744 return the parameter pointer for a parameter
746 void *lpcfg_parm_ptr(struct loadparm_context *lp_ctx,
747 struct loadparm_service *service, struct parm_struct *parm)
749 if (lp_ctx->s3_fns) {
750 return lp_ctx->s3_fns->get_parm_ptr(service, parm);
753 if (service == NULL) {
754 if (parm->p_class == P_LOCAL)
755 return ((char *)lp_ctx->sDefault)+parm->offset;
756 else if (parm->p_class == P_GLOBAL)
757 return ((char *)lp_ctx->globals)+parm->offset;
760 return ((char *)service) + parm->offset;
765 return the parameter pointer for a parameter
767 bool lpcfg_parm_is_cmdline(struct loadparm_context *lp_ctx, const char *name)
771 parmnum = lpcfg_map_parameter(name);
772 if (parmnum == -1) return false;
774 return lp_ctx->flags[parmnum] & FLAG_CMDLINE;
778 * Find a service by name. Otherwise works like get_service.
781 static struct loadparm_service *lpcfg_getservicebyname(struct loadparm_context *lp_ctx,
782 const char *pszServiceName)
786 if (lp_ctx->s3_fns) {
787 return lp_ctx->s3_fns->get_service(pszServiceName);
790 for (iService = lp_ctx->iNumServices - 1; iService >= 0; iService--)
791 if (lp_ctx->services[iService] != NULL &&
792 strwicmp(lp_ctx->services[iService]->szService, pszServiceName) == 0) {
793 return lp_ctx->services[iService];
800 * Add a parametric option to a parmlist_entry,
801 * replacing old value, if already present.
803 void set_param_opt(TALLOC_CTX *mem_ctx,
804 struct parmlist_entry **opt_list,
805 const char *opt_name,
806 const char *opt_value,
809 struct parmlist_entry *new_opt, *opt;
815 /* Traverse destination */
817 /* If we already have same option, override it */
818 if (strwicmp(opt->key, opt_name) == 0) {
819 if ((opt->priority & FLAG_CMDLINE) &&
820 !(priority & FLAG_CMDLINE)) {
821 /* it's been marked as not to be
825 TALLOC_FREE(opt->value);
826 TALLOC_FREE(opt->list);
827 opt->value = talloc_strdup(opt, opt_value);
828 opt->priority = priority;
835 new_opt = talloc(mem_ctx, struct parmlist_entry);
836 if (new_opt == NULL) {
840 new_opt->key = talloc_strdup(new_opt, opt_name);
841 if (new_opt->key == NULL) {
842 smb_panic("talloc_strdup failed");
845 new_opt->value = talloc_strdup(new_opt, opt_value);
846 if (new_opt->value == NULL) {
847 smb_panic("talloc_strdup failed");
850 new_opt->list = NULL;
851 new_opt->priority = priority;
852 DLIST_ADD(*opt_list, new_opt);
857 * Copy a service structure to another.
858 * If pcopymapDest is NULL then copy all fields
861 void copy_service(struct loadparm_service *pserviceDest,
862 const struct loadparm_service *pserviceSource,
863 struct bitmap *pcopymapDest)
866 bool bcopyall = (pcopymapDest == NULL);
867 struct parmlist_entry *data;
869 for (i = 0; parm_table[i].label; i++)
870 if (parm_table[i].p_class == P_LOCAL &&
871 (bcopyall || bitmap_query(pcopymapDest, i))) {
872 const void *src_ptr =
873 ((const char *)pserviceSource) + parm_table[i].offset;
875 ((char *)pserviceDest) + parm_table[i].offset;
877 switch (parm_table[i].type) {
880 *(bool *)dest_ptr = *(const bool *)src_ptr;
887 *(int *)dest_ptr = *(const int *)src_ptr;
891 *(char *)dest_ptr = *(const char *)src_ptr;
895 lpcfg_string_set(pserviceDest,
897 *(const char * const *)src_ptr);
901 lpcfg_string_set_upper(pserviceDest,
903 *(const char * const *)src_ptr);
907 TALLOC_FREE(*((char ***)dest_ptr));
908 *(const char * const **)dest_ptr = (const char * const *)str_list_copy(pserviceDest,
909 *(const char * * const *)src_ptr);
917 init_copymap(pserviceDest);
918 if (pserviceSource->copymap)
919 bitmap_copy(pserviceDest->copymap,
920 pserviceSource->copymap);
923 for (data = pserviceSource->param_opt; data != NULL; data = data->next) {
924 set_param_opt(pserviceDest, &pserviceDest->param_opt,
925 data->key, data->value, data->priority);
930 * Check a service for consistency. Return False if the service is in any way
931 * incomplete or faulty, else True.
933 bool lpcfg_service_ok(struct loadparm_service *service)
938 if (service->szService[0] == '\0') {
939 DEBUG(0, ("The following message indicates an internal error:\n"));
940 DEBUG(0, ("No service name in service entry.\n"));
944 /* The [printers] entry MUST be printable. I'm all for flexibility, but */
945 /* I can't see why you'd want a non-printable printer service... */
946 if (strwicmp(service->szService, PRINTERS_NAME) == 0) {
947 if (!service->printable) {
948 DEBUG(0, ("WARNING: [%s] service MUST be printable!\n",
949 service->szService));
950 service->printable = true;
952 /* [printers] service must also be non-browsable. */
953 if (service->browseable)
954 service->browseable = false;
957 if (service->path[0] == '\0' &&
958 strwicmp(service->szService, HOMES_NAME) != 0 &&
959 service->msdfs_proxy[0] == '\0')
961 DEBUG(0, ("WARNING: No path in service %s - making it unavailable!\n",
962 service->szService));
963 service->bAvailable = false;
966 /* If a service is flagged unavailable, log the fact at level 0. */
967 if (!service->bAvailable)
968 DEBUG(1, ("NOTE: Service %s is flagged unavailable.\n",
969 service->szService));
975 /*******************************************************************
976 Keep a linked list of all config files so we know when one has changed
977 it's date and needs to be reloaded.
978 ********************************************************************/
980 void add_to_file_list(TALLOC_CTX *mem_ctx, struct file_lists **list,
981 const char *fname, const char *subfname)
983 struct file_lists *f = *list;
986 if (f->name && !strcmp(f->name, fname))
992 f = talloc(mem_ctx, struct file_lists);
996 f->name = talloc_strdup(f, fname);
1001 f->subfname = talloc_strdup(f, subfname);
1007 f->modtime = file_modtime(subfname);
1009 time_t t = file_modtime(subfname);
1016 DEBUG(0, ("Unable to add file to file list: %s\n", fname));
1020 /*******************************************************************
1021 Check if a config file has changed date.
1022 ********************************************************************/
1023 bool lpcfg_file_list_changed(struct loadparm_context *lp_ctx)
1025 struct file_lists *f;
1026 DEBUG(6, ("lpcfg_file_list_changed()\n"));
1028 for (f = lp_ctx->file_lists; f != NULL; f = f->next) {
1032 n2 = standard_sub_basic(lp_ctx, f->name);
1034 DEBUGADD(6, ("file %s -> %s last mod_time: %s\n",
1035 f->name, n2, ctime(&f->modtime)));
1037 mod_time = file_modtime(n2);
1039 if (mod_time && ((f->modtime != mod_time) || (f->subfname == NULL) || (strcmp(n2, f->subfname) != 0))) {
1040 DEBUGADD(6, ("file %s modified: %s\n", n2,
1042 f->modtime = mod_time;
1043 talloc_free(f->subfname);
1044 f->subfname = talloc_strdup(f, n2);
1054 * set the value for a P_ENUM
1056 bool lp_set_enum_parm( struct parm_struct *parm, const char *pszParmValue,
1061 for (i = 0; parm->enum_list[i].name; i++) {
1062 if ( strequal(pszParmValue, parm->enum_list[i].name)) {
1063 *ptr = parm->enum_list[i].value;
1067 DEBUG(0, ("WARNING: Ignoring invalid value '%s' for parameter '%s'\n",
1068 pszParmValue, parm->label));
1073 /***************************************************************************
1074 Handle the "realm" parameter
1075 ***************************************************************************/
1077 bool handle_realm(struct loadparm_context *lp_ctx, struct loadparm_service *service,
1078 const char *pszParmValue, char **ptr)
1083 upper = strupper_talloc(lp_ctx, pszParmValue);
1084 if (upper == NULL) {
1088 lower = strlower_talloc(lp_ctx, pszParmValue);
1089 if (lower == NULL) {
1094 lpcfg_string_set(lp_ctx->globals->ctx, ptr, pszParmValue);
1095 lpcfg_string_set(lp_ctx->globals->ctx, &lp_ctx->globals->realm, upper);
1096 lpcfg_string_set(lp_ctx->globals->ctx, &lp_ctx->globals->dnsdomain, lower);
1101 /***************************************************************************
1102 Handle the include operation.
1103 ***************************************************************************/
1105 bool handle_include(struct loadparm_context *lp_ctx, struct loadparm_service *service,
1106 const char *pszParmValue, char **ptr)
1110 if (lp_ctx->s3_fns) {
1111 return lp_ctx->s3_fns->lp_include(lp_ctx, service, pszParmValue, ptr);
1114 fname = standard_sub_basic(lp_ctx, pszParmValue);
1116 add_to_file_list(lp_ctx, &lp_ctx->file_lists, pszParmValue, fname);
1118 lpcfg_string_set(lp_ctx, ptr, fname);
1120 if (file_exist(fname))
1121 return pm_process(fname, do_section, lpcfg_do_parameter, lp_ctx);
1123 DEBUG(2, ("Can't find include file %s\n", fname));
1128 /***************************************************************************
1129 Handle the interpretation of the copy parameter.
1130 ***************************************************************************/
1132 bool handle_copy(struct loadparm_context *lp_ctx, struct loadparm_service *service,
1133 const char *pszParmValue, char **ptr)
1136 struct loadparm_service *serviceTemp = NULL;
1140 DEBUG(3, ("Copying service from service %s\n", pszParmValue));
1142 serviceTemp = lpcfg_getservicebyname(lp_ctx, pszParmValue);
1144 if (service == NULL) {
1145 DEBUG(0, ("Unable to copy service - invalid service destination.\n"));
1149 if (serviceTemp != NULL) {
1150 if (serviceTemp == service) {
1151 DEBUG(0, ("Can't copy service %s - unable to copy self!\n", pszParmValue));
1153 copy_service(service,
1156 lpcfg_string_set(service, ptr, pszParmValue);
1161 DEBUG(0, ("Unable to copy service - source not found: %s\n",
1169 bool handle_debug_list(struct loadparm_context *lp_ctx, struct loadparm_service *service,
1170 const char *pszParmValue, char **ptr)
1172 lpcfg_string_set(lp_ctx->globals->ctx, ptr, pszParmValue);
1174 return debug_parse_levels(pszParmValue);
1177 bool handle_logfile(struct loadparm_context *lp_ctx, struct loadparm_service *service,
1178 const char *pszParmValue, char **ptr)
1180 if (lp_ctx->s3_fns == NULL) {
1181 debug_set_logfile(pszParmValue);
1184 lpcfg_string_set(lp_ctx->globals->ctx, ptr, pszParmValue);
1190 * These special charset handling methods only run in the source3 code.
1193 bool handle_charset(struct loadparm_context *lp_ctx, struct loadparm_service *service,
1194 const char *pszParmValue, char **ptr)
1196 if (lp_ctx->s3_fns) {
1197 if (*ptr == NULL || strcmp(*ptr, pszParmValue) != 0) {
1198 global_iconv_handle = smb_iconv_handle_reinit(NULL,
1199 lpcfg_dos_charset(lp_ctx),
1200 lpcfg_unix_charset(lp_ctx),
1201 true, global_iconv_handle);
1205 return lpcfg_string_set(lp_ctx->globals->ctx, ptr, pszParmValue);
1209 bool handle_dos_charset(struct loadparm_context *lp_ctx, struct loadparm_service *service,
1210 const char *pszParmValue, char **ptr)
1212 bool is_utf8 = false;
1213 size_t len = strlen(pszParmValue);
1215 if (lp_ctx->s3_fns) {
1216 if (len == 4 || len == 5) {
1217 /* Don't use StrCaseCmp here as we don't want to
1218 initialize iconv. */
1219 if ((toupper_m(pszParmValue[0]) == 'U') &&
1220 (toupper_m(pszParmValue[1]) == 'T') &&
1221 (toupper_m(pszParmValue[2]) == 'F')) {
1223 if (pszParmValue[3] == '8') {
1227 if (pszParmValue[3] == '-' &&
1228 pszParmValue[4] == '8') {
1235 if (*ptr == NULL || strcmp(*ptr, pszParmValue) != 0) {
1237 DEBUG(0,("ERROR: invalid DOS charset: 'dos charset' must not "
1238 "be UTF8, using (default value) %s instead.\n",
1239 DEFAULT_DOS_CHARSET));
1240 pszParmValue = DEFAULT_DOS_CHARSET;
1242 global_iconv_handle = smb_iconv_handle_reinit(NULL,
1243 lpcfg_dos_charset(lp_ctx),
1244 lpcfg_unix_charset(lp_ctx),
1245 true, global_iconv_handle);
1249 return lpcfg_string_set(lp_ctx->globals->ctx, ptr, pszParmValue);
1252 bool handle_printing(struct loadparm_context *lp_ctx, struct loadparm_service *service,
1253 const char *pszParmValue, char **ptr)
1255 static int parm_num = -1;
1257 if (parm_num == -1) {
1258 parm_num = lpcfg_map_parameter("printing");
1261 if (!lp_set_enum_parm(&parm_table[parm_num], pszParmValue, (int*)ptr)) {
1265 if (lp_ctx->s3_fns) {
1266 if (service == NULL) {
1267 init_printer_values(lp_ctx, lp_ctx->globals->ctx, lp_ctx->sDefault);
1269 init_printer_values(lp_ctx, service, service);
1276 bool handle_ldap_debug_level(struct loadparm_context *lp_ctx, struct loadparm_service *service,
1277 const char *pszParmValue, char **ptr)
1279 lp_ctx->globals->ldap_debug_level = lp_int(pszParmValue);
1281 if (lp_ctx->s3_fns) {
1282 lp_ctx->s3_fns->init_ldap_debugging();
1287 bool handle_netbios_aliases(struct loadparm_context *lp_ctx, struct loadparm_service *service,
1288 const char *pszParmValue, char **ptr)
1290 TALLOC_FREE(lp_ctx->globals->netbios_aliases);
1291 lp_ctx->globals->netbios_aliases = (const char **)str_list_make_v3(lp_ctx->globals->ctx,
1292 pszParmValue, NULL);
1294 if (lp_ctx->s3_fns) {
1295 return lp_ctx->s3_fns->set_netbios_aliases(lp_ctx->globals->netbios_aliases);
1301 * idmap related parameters
1304 bool handle_idmap_backend(struct loadparm_context *lp_ctx, struct loadparm_service *service,
1305 const char *pszParmValue, char **ptr)
1307 if (lp_ctx->s3_fns) {
1308 lp_do_parameter_parametric(lp_ctx, service, "idmap config * : backend",
1312 return lpcfg_string_set(lp_ctx->globals->ctx, ptr, pszParmValue);
1315 bool handle_idmap_uid(struct loadparm_context *lp_ctx, struct loadparm_service *service,
1316 const char *pszParmValue, char **ptr)
1318 if (lp_ctx->s3_fns) {
1319 lp_do_parameter_parametric(lp_ctx, service, "idmap config * : range",
1323 return lpcfg_string_set(lp_ctx->globals->ctx, ptr, pszParmValue);
1326 bool handle_idmap_gid(struct loadparm_context *lp_ctx, struct loadparm_service *service,
1327 const char *pszParmValue, char **ptr)
1329 if (lp_ctx->s3_fns) {
1330 lp_do_parameter_parametric(lp_ctx, service, "idmap config * : range",
1334 return lpcfg_string_set(lp_ctx->globals->ctx, ptr, pszParmValue);
1337 bool handle_smb_ports(struct loadparm_context *lp_ctx, struct loadparm_service *service,
1338 const char *pszParmValue, char **ptr)
1340 static int parm_num = -1;
1344 if (!pszParmValue || !*pszParmValue) {
1348 if (parm_num == -1) {
1349 parm_num = lpcfg_map_parameter("smb ports");
1352 if(!set_variable_helper(lp_ctx->globals->ctx, parm_num, ptr, "smb ports",
1357 list = lp_ctx->globals->smb_ports;
1362 /* Check that each port is a valid integer and within range */
1363 for (i = 0; list[i] != NULL; i++) {
1366 port = strtol(list[i], &end, 10);
1367 if (*end != '\0' || port <= 0 || port > 65535) {
1376 /***************************************************************************
1377 Initialise a copymap.
1378 ***************************************************************************/
1380 void init_copymap(struct loadparm_service *pservice)
1384 TALLOC_FREE(pservice->copymap);
1386 pservice->copymap = bitmap_talloc(NULL, num_parameters());
1387 if (!pservice->copymap)
1389 ("Couldn't allocate copymap!! (size %d)\n",
1390 (int)num_parameters()));
1392 for (i = 0; i < num_parameters(); i++)
1393 bitmap_set(pservice->copymap, i);
1397 * Process a parametric option
1399 static bool lp_do_parameter_parametric(struct loadparm_context *lp_ctx,
1400 struct loadparm_service *service,
1401 const char *pszParmName,
1402 const char *pszParmValue, int flags)
1404 struct parmlist_entry **data;
1406 TALLOC_CTX *mem_ctx;
1408 while (isspace((unsigned char)*pszParmName)) {
1412 name = strlower_talloc(lp_ctx, pszParmName);
1413 if (!name) return false;
1415 if (service == NULL) {
1416 data = &lp_ctx->globals->param_opt;
1418 * s3 code cannot deal with parametric options stored on the globals ctx.
1420 if (lp_ctx->s3_fns != NULL) {
1423 mem_ctx = lp_ctx->globals->ctx;
1426 data = &service->param_opt;
1430 set_param_opt(mem_ctx, data, name, pszParmValue, flags);
1437 static bool set_variable_helper(TALLOC_CTX *mem_ctx, int parmnum, void *parm_ptr,
1438 const char *pszParmName, const char *pszParmValue)
1442 /* switch on the type of variable it is */
1443 switch (parm_table[parmnum].type)
1447 if (!set_boolean(pszParmValue, &b)) {
1448 DEBUG(0, ("set_variable_helper(%s): value is not "
1449 "boolean!\n", pszParmValue));
1452 *(bool *)parm_ptr = b;
1458 if (!set_boolean(pszParmValue, &b)) {
1459 DEBUG(0, ("set_variable_helper(%s): value is not "
1460 "boolean!\n", pszParmValue));
1463 *(bool *)parm_ptr = !b;
1468 *(int *)parm_ptr = lp_int(pszParmValue);
1472 *(char *)parm_ptr = *pszParmValue;
1476 i = sscanf(pszParmValue, "%o", (int *)parm_ptr);
1478 DEBUG ( 0, ("Invalid octal number %s\n", pszParmName ));
1486 if (conv_str_size_error(pszParmValue, &val)) {
1487 if (val <= INT_MAX) {
1488 *(int *)parm_ptr = (int)val;
1493 DEBUG(0, ("set_variable_helper(%s): value is not "
1494 "a valid size specifier!\n", pszParmValue));
1499 TALLOC_FREE(*(char ***)parm_ptr);
1500 *(const char * const **)parm_ptr
1501 = (const char * const *)str_list_make_v3(mem_ctx,
1502 pszParmValue, NULL);
1507 char **new_list = str_list_make_v3(mem_ctx,
1508 pszParmValue, NULL);
1509 if (new_list == NULL) {
1513 for (i=0; new_list[i]; i++) {
1514 if (*(const char ***)parm_ptr != NULL &&
1515 new_list[i][0] == '+' &&
1518 if (!str_list_check(*(const char ***)parm_ptr,
1520 *(const char ***)parm_ptr = str_list_add(*(const char ***)parm_ptr,
1523 } else if (*(const char ***)parm_ptr != NULL &&
1524 new_list[i][0] == '-' &&
1527 str_list_remove(*(const char ***)parm_ptr,
1531 DEBUG(0, ("Unsupported list syntax for: %s = %s\n",
1532 pszParmName, pszParmValue));
1535 *(const char * const **)parm_ptr = (const char * const *) new_list;
1543 lpcfg_string_set(mem_ctx, (char **)parm_ptr, pszParmValue);
1547 lpcfg_string_set_upper(mem_ctx, (char **)parm_ptr, pszParmValue);
1551 if (!lp_set_enum_parm(&parm_table[parmnum], pszParmValue, (int*)parm_ptr)) {
1564 bool set_variable(TALLOC_CTX *mem_ctx, struct loadparm_service *service, int parmnum, void *parm_ptr,
1565 const char *pszParmName, const char *pszParmValue,
1566 struct loadparm_context *lp_ctx, bool on_globals)
1571 /* if it is a special case then go ahead */
1572 if (parm_table[parmnum].special) {
1573 ok = parm_table[parmnum].special(lp_ctx, service, pszParmValue,
1578 goto mark_non_default;
1581 ok = set_variable_helper(mem_ctx, parmnum, parm_ptr, pszParmName, pszParmValue);
1588 if (on_globals && (lp_ctx->flags[parmnum] & FLAG_DEFAULT)) {
1589 lp_ctx->flags[parmnum] &= ~FLAG_DEFAULT;
1590 /* we have to also unset FLAG_DEFAULT on aliases */
1591 for (i=parmnum-1;i>=0 && parm_table[i].offset == parm_table[parmnum].offset;i--) {
1592 lp_ctx->flags[i] &= ~FLAG_DEFAULT;
1594 for (i=parmnum+1;i<num_parameters() && parm_table[i].offset == parm_table[parmnum].offset;i++) {
1595 lp_ctx->flags[i] &= ~FLAG_DEFAULT;
1602 bool lpcfg_do_global_parameter(struct loadparm_context *lp_ctx,
1603 const char *pszParmName, const char *pszParmValue)
1605 int parmnum = lpcfg_map_parameter(pszParmName);
1609 if (strchr(pszParmName, ':')) {
1610 return lp_do_parameter_parametric(lp_ctx, NULL, pszParmName, pszParmValue, 0);
1612 DEBUG(0, ("Ignoring unknown parameter \"%s\"\n", pszParmName));
1616 /* if the flag has been set on the command line, then don't allow override,
1617 but don't report an error */
1618 if (lp_ctx->flags[parmnum] & FLAG_CMDLINE) {
1622 if (parm_table[parmnum].flags & FLAG_DEPRECATED) {
1623 DEBUG(1, ("WARNING: The \"%s\" option is deprecated\n",
1627 parm_ptr = lpcfg_parm_ptr(lp_ctx, NULL, &parm_table[parmnum]);
1629 return set_variable(lp_ctx->globals->ctx, NULL, parmnum, parm_ptr,
1630 pszParmName, pszParmValue, lp_ctx, true);
1633 bool lpcfg_do_service_parameter(struct loadparm_context *lp_ctx,
1634 struct loadparm_service *service,
1635 const char *pszParmName, const char *pszParmValue)
1639 int parmnum = lpcfg_map_parameter(pszParmName);
1642 if (strchr(pszParmName, ':')) {
1643 return lp_do_parameter_parametric(lp_ctx, service, pszParmName, pszParmValue, 0);
1645 DEBUG(0, ("Ignoring unknown parameter \"%s\"\n", pszParmName));
1649 /* if the flag has been set on the command line, then don't allow override,
1650 but don't report an error */
1651 if (lp_ctx->flags[parmnum] & FLAG_CMDLINE) {
1655 if (parm_table[parmnum].flags & FLAG_DEPRECATED) {
1656 DEBUG(1, ("WARNING: The \"%s\" option is deprecated\n",
1660 if (parm_table[parmnum].p_class == P_GLOBAL) {
1662 ("Global parameter %s found in service section!\n",
1666 parm_ptr = ((char *)service) + parm_table[parmnum].offset;
1668 if (!service->copymap)
1669 init_copymap(service);
1671 /* this handles the aliases - set the copymap for other
1672 * entries with the same data pointer */
1673 for (i = 0; parm_table[i].label; i++)
1674 if (parm_table[i].offset == parm_table[parmnum].offset &&
1675 parm_table[i].p_class == parm_table[parmnum].p_class)
1676 bitmap_clear(service->copymap, i);
1678 return set_variable(service, service, parmnum, parm_ptr, pszParmName,
1679 pszParmValue, lp_ctx, false);
1683 * Process a parameter.
1686 bool lpcfg_do_parameter(const char *pszParmName, const char *pszParmValue,
1689 struct loadparm_context *lp_ctx = (struct loadparm_context *)userdata;
1691 if (lp_ctx->bInGlobalSection)
1692 return lpcfg_do_global_parameter(lp_ctx, pszParmName,
1695 return lpcfg_do_service_parameter(lp_ctx, lp_ctx->currentService,
1696 pszParmName, pszParmValue);
1700 variable argument do parameter
1702 bool lpcfg_do_global_parameter_var(struct loadparm_context *lp_ctx, const char *pszParmName, const char *fmt, ...) PRINTF_ATTRIBUTE(3, 4);
1703 bool lpcfg_do_global_parameter_var(struct loadparm_context *lp_ctx,
1704 const char *pszParmName, const char *fmt, ...)
1711 s = talloc_vasprintf(NULL, fmt, ap);
1713 ret = lpcfg_do_global_parameter(lp_ctx, pszParmName, s);
1720 set a parameter from the commandline - this is called from command line parameter
1721 parsing code. It sets the parameter then marks the parameter as unable to be modified
1722 by smb.conf processing
1724 bool lpcfg_set_cmdline(struct loadparm_context *lp_ctx, const char *pszParmName,
1725 const char *pszParmValue)
1730 while (isspace((unsigned char)*pszParmValue)) pszParmValue++;
1732 parmnum = lpcfg_map_parameter(pszParmName);
1734 if (parmnum < 0 && strchr(pszParmName, ':')) {
1735 /* set a parametric option */
1737 ok = lp_do_parameter_parametric(lp_ctx, NULL, pszParmName,
1738 pszParmValue, FLAG_CMDLINE);
1739 if (lp_ctx->s3_fns != NULL) {
1741 lp_ctx->s3_fns->store_cmdline(pszParmName, pszParmValue);
1748 DEBUG(0,("Unknown option '%s'\n", pszParmName));
1752 /* reset the CMDLINE flag in case this has been called before */
1753 lp_ctx->flags[parmnum] &= ~FLAG_CMDLINE;
1755 if (!lpcfg_do_global_parameter(lp_ctx, pszParmName, pszParmValue)) {
1759 lp_ctx->flags[parmnum] |= FLAG_CMDLINE;
1761 /* we have to also set FLAG_CMDLINE on aliases */
1763 i>=0 && parm_table[i].p_class == parm_table[parmnum].p_class &&
1764 parm_table[i].offset == parm_table[parmnum].offset;
1766 lp_ctx->flags[i] |= FLAG_CMDLINE;
1769 i<num_parameters() &&
1770 parm_table[i].p_class == parm_table[parmnum].p_class &&
1771 parm_table[i].offset == parm_table[parmnum].offset;
1773 lp_ctx->flags[i] |= FLAG_CMDLINE;
1776 if (lp_ctx->s3_fns != NULL) {
1777 lp_ctx->s3_fns->store_cmdline(pszParmName, pszParmValue);
1784 set a option from the commandline in 'a=b' format. Use to support --option
1786 bool lpcfg_set_option(struct loadparm_context *lp_ctx, const char *option)
1791 s = talloc_strdup(NULL, option);
1804 ret = lpcfg_set_cmdline(lp_ctx, s, p+1);
1810 #define BOOLSTR(b) ((b) ? "Yes" : "No")
1813 * Print a parameter of the specified type.
1816 void lpcfg_print_parameter(struct parm_struct *p, void *ptr, FILE * f)
1818 /* For the seperation of lists values that we print below */
1819 const char *list_sep = ", ";
1824 for (i = 0; p->enum_list[i].name; i++) {
1825 if (*(int *)ptr == p->enum_list[i].value) {
1827 p->enum_list[i].name);
1834 fprintf(f, "%s", BOOLSTR(*(bool *)ptr));
1838 fprintf(f, "%s", BOOLSTR(!*(bool *)ptr));
1843 fprintf(f, "%d", *(int *)ptr);
1847 fprintf(f, "%c", *(char *)ptr);
1851 int val = *(int *)ptr;
1855 fprintf(f, "0%03o", val);
1864 if ((char ***)ptr && *(char ***)ptr) {
1865 char **list = *(char ***)ptr;
1866 for (; *list; list++) {
1867 /* surround strings with whitespace in double quotes */
1868 if (*(list+1) == NULL) {
1869 /* last item, no extra separator */
1872 if ( strchr_m( *list, ' ' ) ) {
1873 fprintf(f, "\"%s\"%s", *list, list_sep);
1875 fprintf(f, "%s%s", *list, list_sep);
1883 if (*(char **)ptr) {
1884 fprintf(f, "%s", *(char **)ptr);
1893 * Check if two parameters are equal.
1896 static bool lpcfg_equal_parameter(parm_type type, void *ptr1, void *ptr2)
1901 return (*((bool *)ptr1) == *((bool *)ptr2));
1907 return (*((int *)ptr1) == *((int *)ptr2));
1910 return (*((char *)ptr1) == *((char *)ptr2));
1914 return str_list_equal(*(const char ***)ptr1, *(const char ***)ptr2);
1919 char *p1 = *(char **)ptr1, *p2 = *(char **)ptr2;
1924 return (p1 == p2 || strequal(p1, p2));
1933 * Process a new section (service).
1935 * At this stage all sections are services.
1936 * Later we'll have special sections that permit server parameters to be set.
1937 * Returns True on success, False on failure.
1940 static bool do_section(const char *pszSectionName, void *userdata)
1942 struct loadparm_context *lp_ctx = (struct loadparm_context *)userdata;
1946 if (lp_ctx->s3_fns != NULL) {
1947 return lp_ctx->s3_fns->do_section(pszSectionName, lp_ctx);
1950 isglobal = ((strwicmp(pszSectionName, GLOBAL_NAME) == 0) ||
1951 (strwicmp(pszSectionName, GLOBAL_NAME2) == 0));
1955 /* if we've just struck a global section, note the fact. */
1956 lp_ctx->bInGlobalSection = isglobal;
1958 /* check for multiple global sections */
1959 if (lp_ctx->bInGlobalSection) {
1960 DEBUG(4, ("Processing section \"[%s]\"\n", pszSectionName));
1964 /* if we have a current service, tidy it up before moving on */
1967 if (lp_ctx->currentService != NULL)
1968 bRetval = lpcfg_service_ok(lp_ctx->currentService);
1970 /* if all is still well, move to the next record in the services array */
1972 /* We put this here to avoid an odd message order if messages are */
1973 /* issued by the post-processing of a previous section. */
1974 DEBUG(4, ("Processing section \"[%s]\"\n", pszSectionName));
1976 if ((lp_ctx->currentService = lpcfg_add_service(lp_ctx, lp_ctx->sDefault,
1979 DEBUG(0, ("Failed to add a new service\n"));
1989 * Determine if a particular base parameter is currently set to the default value.
1992 static bool is_default(void *base_structure, int i)
1994 void *def_ptr = ((char *)base_structure) + parm_table[i].offset;
1995 switch (parm_table[i].type) {
1998 return str_list_equal((const char * const *)parm_table[i].def.lvalue,
1999 *(const char ***)def_ptr);
2002 return strequal(parm_table[i].def.svalue,
2006 return parm_table[i].def.bvalue ==
2013 return parm_table[i].def.ivalue ==
2022 *Display the contents of the global structure.
2025 void lpcfg_dump_globals(struct loadparm_context *lp_ctx, FILE *f,
2029 struct parmlist_entry *data;
2031 fprintf(f, "# Global parameters\n[global]\n");
2033 for (i = 0; parm_table[i].label; i++)
2034 if (parm_table[i].p_class == P_GLOBAL &&
2035 (i == 0 || (parm_table[i].offset != parm_table[i - 1].offset))) {
2036 if (!show_defaults) {
2037 if (lp_ctx->flags && (lp_ctx->flags[i] & FLAG_DEFAULT)) {
2041 if (is_default(lp_ctx->globals, i)) {
2046 fprintf(f, "\t%s = ", parm_table[i].label);
2047 lpcfg_print_parameter(&parm_table[i], lpcfg_parm_ptr(lp_ctx, NULL, &parm_table[i]), f);
2050 if (lp_ctx->globals->param_opt != NULL) {
2051 for (data = lp_ctx->globals->param_opt; data;
2052 data = data->next) {
2053 if (!show_defaults && (data->priority & FLAG_DEFAULT)) {
2056 fprintf(f, "\t%s = %s\n", data->key, data->value);
2063 * Display the contents of a single services record.
2066 void lpcfg_dump_a_service(struct loadparm_service * pService, struct loadparm_service *sDefault, FILE * f,
2067 unsigned int *flags, bool show_defaults)
2070 struct parmlist_entry *data;
2072 if (pService != sDefault)
2073 fprintf(f, "\n[%s]\n", pService->szService);
2075 for (i = 0; parm_table[i].label; i++) {
2076 if (parm_table[i].p_class == P_LOCAL &&
2077 (*parm_table[i].label != '-') &&
2078 (i == 0 || (parm_table[i].offset != parm_table[i - 1].offset)))
2080 if (pService == sDefault) {
2081 if (flags && (flags[i] & FLAG_DEFAULT)) {
2084 if (!show_defaults) {
2085 if (is_default(sDefault, i)) {
2090 if (lpcfg_equal_parameter(parm_table[i].type,
2091 ((char *)pService) +
2092 parm_table[i].offset,
2093 ((char *)sDefault) +
2094 parm_table[i].offset))
2098 fprintf(f, "\t%s = ", parm_table[i].label);
2099 lpcfg_print_parameter(&parm_table[i],
2100 ((char *)pService) + parm_table[i].offset, f);
2104 if (pService->param_opt != NULL) {
2105 for (data = pService->param_opt; data; data = data->next) {
2106 if (!show_defaults && (data->priority & FLAG_DEFAULT)) {
2109 fprintf(f, "\t%s = %s\n", data->key, data->value);
2114 bool lpcfg_dump_a_parameter(struct loadparm_context *lp_ctx,
2115 struct loadparm_service *service,
2116 const char *parm_name, FILE * f)
2118 struct parm_struct *parm;
2120 char *local_parm_name;
2122 const char *parm_opt_value;
2124 /* check for parametrical option */
2125 local_parm_name = talloc_strdup(lp_ctx, parm_name);
2126 if (local_parm_name == NULL) {
2130 parm_opt = strchr( local_parm_name, ':');
2135 if (strlen(parm_opt)) {
2136 parm_opt_value = lpcfg_parm_string(lp_ctx, service,
2137 local_parm_name, parm_opt);
2138 if (parm_opt_value) {
2139 fprintf(f, "%s\n", parm_opt_value);
2146 /* parameter is not parametric, search the table */
2147 parm = lpcfg_parm_struct(lp_ctx, parm_name);
2152 if (service != NULL && parm->p_class == P_GLOBAL) {
2156 ptr = lpcfg_parm_ptr(lp_ctx, service,parm);
2158 lpcfg_print_parameter(parm, ptr, f);
2164 * Auto-load some home services.
2166 static void lpcfg_add_auto_services(struct loadparm_context *lp_ctx,
2172 /***************************************************************************
2173 Initialise the sDefault parameter structure for the printer values.
2174 ***************************************************************************/
2176 void init_printer_values(struct loadparm_context *lp_ctx, TALLOC_CTX *ctx,
2177 struct loadparm_service *pService)
2179 /* choose defaults depending on the type of printing */
2180 switch (pService->printing) {
2185 lpcfg_string_set(ctx, &pService->lpq_command, "lpq -P'%p'");
2186 lpcfg_string_set(ctx, &pService->lprm_command, "lprm -P'%p' %j");
2187 lpcfg_string_set(ctx, &pService->print_command, "lpr -r -P'%p' %s");
2192 lpcfg_string_set(ctx, &pService->lpq_command, "lpq -P'%p'");
2193 lpcfg_string_set(ctx, &pService->lprm_command, "lprm -P'%p' %j");
2194 lpcfg_string_set(ctx, &pService->print_command, "lpr -r -P'%p' %s");
2195 lpcfg_string_set(ctx, &pService->queuepause_command, "lpc stop '%p'");
2196 lpcfg_string_set(ctx, &pService->queueresume_command, "lpc start '%p'");
2197 lpcfg_string_set(ctx, &pService->lppause_command, "lpc hold '%p' %j");
2198 lpcfg_string_set(ctx, &pService->lpresume_command, "lpc release '%p' %j");
2203 /* set the lpq command to contain the destination printer
2204 name only. This is used by cups_queue_get() */
2205 lpcfg_string_set(ctx, &pService->lpq_command, "%p");
2206 lpcfg_string_set(ctx, &pService->lprm_command, "");
2207 lpcfg_string_set(ctx, &pService->print_command, "");
2208 lpcfg_string_set(ctx, &pService->lppause_command, "");
2209 lpcfg_string_set(ctx, &pService->lpresume_command, "");
2210 lpcfg_string_set(ctx, &pService->queuepause_command, "");
2211 lpcfg_string_set(ctx, &pService->queueresume_command, "");
2216 lpcfg_string_set(ctx, &pService->lpq_command, "lpstat -o%p");
2217 lpcfg_string_set(ctx, &pService->lprm_command, "cancel %p-%j");
2218 lpcfg_string_set(ctx, &pService->print_command, "lp -c -d%p %s; rm %s");
2219 lpcfg_string_set(ctx, &pService->queuepause_command, "disable %p");
2220 lpcfg_string_set(ctx, &pService->queueresume_command, "enable %p");
2222 lpcfg_string_set(ctx, &pService->lppause_command, "lp -i %p-%j -H hold");
2223 lpcfg_string_set(ctx, &pService->lpresume_command, "lp -i %p-%j -H resume");
2228 lpcfg_string_set(ctx, &pService->lpq_command, "lpq -P%p");
2229 lpcfg_string_set(ctx, &pService->lprm_command, "lprm -P%p %j");
2230 lpcfg_string_set(ctx, &pService->print_command, "lp -r -P%p %s");
2233 #if defined(DEVELOPER) || defined(ENABLE_SELFTEST)
2237 const char *tdbfile;
2238 TALLOC_CTX *tmp_ctx = talloc_new(ctx);
2241 tmp = lpcfg_parm_string(lp_ctx, NULL, "vlp", "tdbfile");
2243 tmp = "/tmp/vlp.tdb";
2246 tdbfile = talloc_asprintf(tmp_ctx, "tdbfile=%s", tmp);
2247 if (tdbfile == NULL) {
2248 tdbfile="tdbfile=/tmp/vlp.tdb";
2251 tmp = talloc_asprintf(tmp_ctx, "vlp %s print %%p %%s",
2253 lpcfg_string_set(ctx, &pService->print_command,
2254 tmp ? tmp : "vlp print %p %s");
2256 tmp = talloc_asprintf(tmp_ctx, "vlp %s lpq %%p",
2258 lpcfg_string_set(ctx, &pService->lpq_command,
2259 tmp ? tmp : "vlp lpq %p");
2261 tmp = talloc_asprintf(tmp_ctx, "vlp %s lprm %%p %%j",
2263 lpcfg_string_set(ctx, &pService->lprm_command,
2264 tmp ? tmp : "vlp lprm %p %j");
2266 tmp = talloc_asprintf(tmp_ctx, "vlp %s lppause %%p %%j",
2268 lpcfg_string_set(ctx, &pService->lppause_command,
2269 tmp ? tmp : "vlp lppause %p %j");
2271 tmp = talloc_asprintf(tmp_ctx, "vlp %s lpresume %%p %%j",
2273 lpcfg_string_set(ctx, &pService->lpresume_command,
2274 tmp ? tmp : "vlp lpresume %p %j");
2276 tmp = talloc_asprintf(tmp_ctx, "vlp %s queuepause %%p",
2278 lpcfg_string_set(ctx, &pService->queuepause_command,
2279 tmp ? tmp : "vlp queuepause %p");
2281 tmp = talloc_asprintf(tmp_ctx, "vlp %s queueresume %%p",
2283 lpcfg_string_set(ctx, &pService->queueresume_command,
2284 tmp ? tmp : "vlp queueresume %p");
2285 TALLOC_FREE(tmp_ctx);
2289 #endif /* DEVELOPER */
2295 * Unload unused services.
2298 void lpcfg_killunused(struct loadparm_context *lp_ctx,
2299 struct smbsrv_connection *smb,
2300 bool (*snumused) (struct smbsrv_connection *, int))
2304 if (lp_ctx->s3_fns != NULL) {
2305 smb_panic("Cannot be used from an s3 loadparm ctx");
2308 for (i = 0; i < lp_ctx->iNumServices; i++) {
2309 if (lp_ctx->services[i] == NULL)
2312 if (!snumused || !snumused(smb, i)) {
2313 talloc_free(lp_ctx->services[i]);
2314 lp_ctx->services[i] = NULL;
2320 static int lpcfg_destructor(struct loadparm_context *lp_ctx)
2322 struct parmlist_entry *data;
2324 if (lp_ctx->refuse_free) {
2325 /* someone is trying to free the
2326 global_loadparm_context.
2327 We can't allow that. */
2331 if (lp_ctx->globals->param_opt != NULL) {
2332 struct parmlist_entry *next;
2333 for (data = lp_ctx->globals->param_opt; data; data=next) {
2335 if (data->priority & FLAG_CMDLINE) continue;
2336 DLIST_REMOVE(lp_ctx->globals->param_opt, data);
2345 * Initialise the global parameter structure.
2347 * Note that most callers should use loadparm_init_global() instead
2349 struct loadparm_context *loadparm_init(TALLOC_CTX *mem_ctx)
2353 struct loadparm_context *lp_ctx;
2354 struct parmlist_entry *parm;
2357 lp_ctx = talloc_zero(mem_ctx, struct loadparm_context);
2361 talloc_set_destructor(lp_ctx, lpcfg_destructor);
2362 lp_ctx->bInGlobalSection = true;
2363 lp_ctx->globals = talloc_zero(lp_ctx, struct loadparm_global);
2364 /* This appears odd, but globals in s3 isn't a pointer */
2365 lp_ctx->globals->ctx = lp_ctx->globals;
2366 lp_ctx->sDefault = talloc_zero(lp_ctx, struct loadparm_service);
2367 lp_ctx->flags = talloc_zero_array(lp_ctx, unsigned int, num_parameters());
2369 lp_ctx->sDefault->iMaxPrintJobs = 1000;
2370 lp_ctx->sDefault->bAvailable = true;
2371 lp_ctx->sDefault->browseable = true;
2372 lp_ctx->sDefault->read_only = true;
2373 lp_ctx->sDefault->map_archive = true;
2374 lp_ctx->sDefault->strict_locking = true;
2375 lp_ctx->sDefault->oplocks = true;
2376 lp_ctx->sDefault->create_mask = 0744;
2377 lp_ctx->sDefault->force_create_mode = 0000;
2378 lp_ctx->sDefault->directory_mask = 0755;
2379 lp_ctx->sDefault->force_directory_mode = 0000;
2381 DEBUG(3, ("Initialising global parameters\n"));
2383 for (i = 0; parm_table[i].label; i++) {
2384 if ((parm_table[i].type == P_STRING ||
2385 parm_table[i].type == P_USTRING) &&
2386 !(lp_ctx->flags[i] & FLAG_CMDLINE)) {
2388 if (parm_table[i].p_class == P_LOCAL) {
2389 r = (char **)(((char *)lp_ctx->sDefault) + parm_table[i].offset);
2391 r = (char **)(((char *)lp_ctx->globals) + parm_table[i].offset);
2393 *r = talloc_strdup(lp_ctx, "");
2397 logfile = talloc_asprintf(lp_ctx, "%s/log.samba", dyn_LOGFILEBASE);
2398 lpcfg_do_global_parameter(lp_ctx, "log file", logfile);
2399 talloc_free(logfile);
2401 lpcfg_do_global_parameter(lp_ctx, "log level", "0");
2403 lpcfg_do_global_parameter(lp_ctx, "syslog", "1");
2404 lpcfg_do_global_parameter(lp_ctx, "syslog only", "No");
2405 lpcfg_do_global_parameter(lp_ctx, "debug timestamp", "Yes");
2406 lpcfg_do_global_parameter(lp_ctx, "debug prefix timestamp", "No");
2407 lpcfg_do_global_parameter(lp_ctx, "debug hires timestamp", "Yes");
2408 lpcfg_do_global_parameter(lp_ctx, "debug pid", "No");
2409 lpcfg_do_global_parameter(lp_ctx, "debug uid", "No");
2410 lpcfg_do_global_parameter(lp_ctx, "debug class", "No");
2412 lpcfg_do_global_parameter(lp_ctx, "share backend", "classic");
2414 lpcfg_do_global_parameter(lp_ctx, "server role", "auto");
2415 lpcfg_do_global_parameter(lp_ctx, "domain logons", "No");
2416 lpcfg_do_global_parameter(lp_ctx, "domain master", "Auto");
2418 /* options that can be set on the command line must be initialised via
2419 the slower lpcfg_do_global_parameter() to ensure that FLAG_CMDLINE is obeyed */
2421 lpcfg_do_global_parameter(lp_ctx, "socket options", "TCP_NODELAY");
2423 lpcfg_do_global_parameter(lp_ctx, "workgroup", DEFAULT_WORKGROUP);
2424 myname = get_myname(lp_ctx);
2425 lpcfg_do_global_parameter(lp_ctx, "netbios name", myname);
2426 talloc_free(myname);
2427 lpcfg_do_global_parameter(lp_ctx, "name resolve order", "lmhosts wins host bcast");
2429 lpcfg_do_global_parameter(lp_ctx, "fstype", "NTFS");
2431 lpcfg_do_global_parameter(lp_ctx, "ntvfs handler", "unixuid default");
2432 lpcfg_do_global_parameter(lp_ctx, "max connections", "0");
2434 lpcfg_do_global_parameter(lp_ctx, "dcerpc endpoint servers", "epmapper wkssvc rpcecho samr netlogon lsarpc spoolss drsuapi dssetup unixinfo browser eventlog6 backupkey dnsserver");
2435 lpcfg_do_global_parameter(lp_ctx, "server services", "s3fs rpc nbt wrepl ldap cldap kdc drepl winbindd ntp_signd kcc dnsupdate dns");
2436 lpcfg_do_global_parameter(lp_ctx, "kccsrv:samba_kcc", "true");
2437 /* the winbind method for domain controllers is for both RODC
2438 auth forwarding and for trusted domains */
2439 lpcfg_do_global_parameter(lp_ctx, "private dir", dyn_PRIVATE_DIR);
2440 lpcfg_do_global_parameter(lp_ctx, "registry:HKEY_LOCAL_MACHINE", "hklm.ldb");
2442 /* This hive should be dynamically generated by Samba using
2443 data from the sam, but for the moment leave it in a tdb to
2444 keep regedt32 from popping up an annoying dialog. */
2445 lpcfg_do_global_parameter(lp_ctx, "registry:HKEY_USERS", "hku.ldb");
2447 /* using UTF8 by default allows us to support all chars */
2448 lpcfg_do_global_parameter(lp_ctx, "unix charset", "UTF-8");
2450 /* Use codepage 850 as a default for the dos character set */
2451 lpcfg_do_global_parameter(lp_ctx, "dos charset", "CP850");
2454 * Allow the default PASSWD_CHAT to be overridden in local.h.
2456 lpcfg_do_global_parameter(lp_ctx, "passwd chat", DEFAULT_PASSWD_CHAT);
2458 lpcfg_do_global_parameter(lp_ctx, "pid directory", dyn_PIDDIR);
2459 lpcfg_do_global_parameter(lp_ctx, "lock dir", dyn_LOCKDIR);
2460 lpcfg_do_global_parameter(lp_ctx, "state directory", dyn_STATEDIR);
2461 lpcfg_do_global_parameter(lp_ctx, "cache directory", dyn_CACHEDIR);
2462 lpcfg_do_global_parameter(lp_ctx, "ncalrpc dir", dyn_NCALRPCDIR);
2464 lpcfg_do_global_parameter(lp_ctx, "nbt client socket address", "0.0.0.0");
2465 lpcfg_do_global_parameter_var(lp_ctx, "server string",
2466 "Samba %s", SAMBA_VERSION_STRING);
2468 lpcfg_do_global_parameter(lp_ctx, "password server", "*");
2470 lpcfg_do_global_parameter(lp_ctx, "max mux", "50");
2471 lpcfg_do_global_parameter(lp_ctx, "max xmit", "16644");
2472 lpcfg_do_global_parameter(lp_ctx, "host msdfs", "true");
2474 lpcfg_do_global_parameter(lp_ctx, "LargeReadwrite", "True");
2475 lpcfg_do_global_parameter(lp_ctx, "server min protocol", "LANMAN1");
2476 lpcfg_do_global_parameter(lp_ctx, "server max protocol", "SMB3");
2477 lpcfg_do_global_parameter(lp_ctx, "client min protocol", "CORE");
2478 lpcfg_do_global_parameter(lp_ctx, "client max protocol", "NT1");
2479 lpcfg_do_global_parameter(lp_ctx, "security", "AUTO");
2480 lpcfg_do_global_parameter(lp_ctx, "EncryptPasswords", "True");
2481 lpcfg_do_global_parameter(lp_ctx, "ReadRaw", "True");
2482 lpcfg_do_global_parameter(lp_ctx, "WriteRaw", "True");
2483 lpcfg_do_global_parameter(lp_ctx, "NullPasswords", "False");
2484 lpcfg_do_global_parameter(lp_ctx, "old password allowed period", "60");
2485 lpcfg_do_global_parameter(lp_ctx, "ObeyPamRestrictions", "False");
2487 lpcfg_do_global_parameter(lp_ctx, "TimeServer", "False");
2488 lpcfg_do_global_parameter(lp_ctx, "BindInterfacesOnly", "False");
2489 lpcfg_do_global_parameter(lp_ctx, "Unicode", "True");
2490 lpcfg_do_global_parameter(lp_ctx, "ClientLanManAuth", "False");
2491 lpcfg_do_global_parameter(lp_ctx, "ClientNTLMv2Auth", "True");
2492 lpcfg_do_global_parameter(lp_ctx, "LanmanAuth", "False");
2493 lpcfg_do_global_parameter(lp_ctx, "NTLMAuth", "True");
2494 lpcfg_do_global_parameter(lp_ctx, "client use spnego principal", "False");
2496 lpcfg_do_global_parameter(lp_ctx, "UnixExtensions", "True");
2498 lpcfg_do_global_parameter(lp_ctx, "PreferredMaster", "Auto");
2499 lpcfg_do_global_parameter(lp_ctx, "LocalMaster", "True");
2501 lpcfg_do_global_parameter(lp_ctx, "wins support", "False");
2502 lpcfg_do_global_parameter(lp_ctx, "dns proxy", "True");
2504 lpcfg_do_global_parameter(lp_ctx, "winbind separator", "\\");
2505 lpcfg_do_global_parameter(lp_ctx, "winbind sealed pipes", "True");
2506 lpcfg_do_global_parameter(lp_ctx, "require strong key", "True");
2507 lpcfg_do_global_parameter(lp_ctx, "winbindd socket directory", dyn_WINBINDD_SOCKET_DIR);
2508 lpcfg_do_global_parameter(lp_ctx, "winbindd privileged socket directory", dyn_WINBINDD_PRIVILEGED_SOCKET_DIR);
2509 lpcfg_do_global_parameter(lp_ctx, "ntp signd socket directory", dyn_NTP_SIGND_SOCKET_DIR);
2510 lpcfg_do_global_parameter_var(lp_ctx, "dns update command", "%s/samba_dnsupdate", dyn_SCRIPTSBINDIR);
2511 lpcfg_do_global_parameter_var(lp_ctx, "spn update command", "%s/samba_spnupdate", dyn_SCRIPTSBINDIR);
2512 lpcfg_do_global_parameter_var(lp_ctx, "samba kcc command",
2513 "%s/samba_kcc", dyn_SCRIPTSBINDIR);
2514 lpcfg_do_global_parameter(lp_ctx, "template shell", "/bin/false");
2515 lpcfg_do_global_parameter(lp_ctx, "template homedir", "/home/%D/%U");
2517 lpcfg_do_global_parameter(lp_ctx, "client signing", "default");
2518 lpcfg_do_global_parameter(lp_ctx, "server signing", "default");
2520 lpcfg_do_global_parameter(lp_ctx, "use spnego", "True");
2522 lpcfg_do_global_parameter(lp_ctx, "use mmap", "True");
2524 lpcfg_do_global_parameter(lp_ctx, "smb ports", "445 139");
2525 lpcfg_do_global_parameter(lp_ctx, "nbt port", "137");
2526 lpcfg_do_global_parameter(lp_ctx, "dgram port", "138");
2527 lpcfg_do_global_parameter(lp_ctx, "cldap port", "389");
2528 lpcfg_do_global_parameter(lp_ctx, "krb5 port", "88");
2529 lpcfg_do_global_parameter(lp_ctx, "kpasswd port", "464");
2530 lpcfg_do_global_parameter(lp_ctx, "web port", "901");
2532 lpcfg_do_global_parameter(lp_ctx, "nt status support", "True");
2534 lpcfg_do_global_parameter(lp_ctx, "max wins ttl", "518400"); /* 6 days */
2535 lpcfg_do_global_parameter(lp_ctx, "min wins ttl", "21600");
2537 lpcfg_do_global_parameter(lp_ctx, "tls enabled", "True");
2538 lpcfg_do_global_parameter(lp_ctx, "tls keyfile", "tls/key.pem");
2539 lpcfg_do_global_parameter(lp_ctx, "tls certfile", "tls/cert.pem");
2540 lpcfg_do_global_parameter(lp_ctx, "tls cafile", "tls/ca.pem");
2541 lpcfg_do_global_parameter(lp_ctx, "prefork children:smb", "4");
2543 lpcfg_do_global_parameter(lp_ctx, "rndc command", "/usr/sbin/rndc");
2544 lpcfg_do_global_parameter(lp_ctx, "nsupdate command", "/usr/bin/nsupdate -g");
2546 lpcfg_do_global_parameter(lp_ctx, "allow dns updates", "secure only");
2547 lpcfg_do_global_parameter(lp_ctx, "dns forwarder", "");
2549 lpcfg_do_global_parameter(lp_ctx, "algorithmic rid base", "1000");
2551 lpcfg_do_global_parameter(lp_ctx, "enhanced browsing", "True");
2553 lpcfg_do_global_parameter(lp_ctx, "winbind nss info", "template");
2555 lpcfg_do_global_parameter(lp_ctx, "server schannel", "Auto");
2557 lpcfg_do_global_parameter(lp_ctx, "short preserve case", "True");
2559 lpcfg_do_global_parameter(lp_ctx, "max open files", "16384");
2561 lpcfg_do_global_parameter(lp_ctx, "cups connection timeout", "30");
2563 lpcfg_do_global_parameter(lp_ctx, "locking", "True");
2565 lpcfg_do_global_parameter(lp_ctx, "block size", "1024");
2567 lpcfg_do_global_parameter(lp_ctx, "client use spnego", "True");
2569 lpcfg_do_global_parameter(lp_ctx, "change notify", "True");
2571 lpcfg_do_global_parameter(lp_ctx, "name cache timeout", "660");
2573 lpcfg_do_global_parameter(lp_ctx, "defer sharing violations", "True");
2575 lpcfg_do_global_parameter(lp_ctx, "ldap replication sleep", "1000");
2577 lpcfg_do_global_parameter(lp_ctx, "idmap backend", "tdb");
2579 lpcfg_do_global_parameter(lp_ctx, "enable privileges", "True");
2581 lpcfg_do_global_parameter_var(lp_ctx, "smb2 max write", "%u", DEFAULT_SMB2_MAX_WRITE);
2583 lpcfg_do_global_parameter(lp_ctx, "passdb backend", "tdbsam");
2585 lpcfg_do_global_parameter(lp_ctx, "getwd cache", "True");
2587 lpcfg_do_global_parameter(lp_ctx, "winbind nested groups", "True");
2589 lpcfg_do_global_parameter(lp_ctx, "mangled names", "True");
2591 lpcfg_do_global_parameter_var(lp_ctx, "smb2 max credits", "%u", DEFAULT_SMB2_MAX_CREDITS);
2593 lpcfg_do_global_parameter(lp_ctx, "ldap ssl", "start tls");
2595 lpcfg_do_global_parameter(lp_ctx, "ldap deref", "auto");
2597 lpcfg_do_global_parameter(lp_ctx, "lm interval", "60");
2599 lpcfg_do_global_parameter(lp_ctx, "mangling method", "hash2");
2601 lpcfg_do_global_parameter(lp_ctx, "hide dot files", "True");
2603 lpcfg_do_global_parameter(lp_ctx, "browse list", "True");
2605 lpcfg_do_global_parameter(lp_ctx, "passwd chat timeout", "2");
2607 lpcfg_do_global_parameter(lp_ctx, "guest account", GUEST_ACCOUNT);
2609 lpcfg_do_global_parameter(lp_ctx, "client schannel", "auto");
2611 lpcfg_do_global_parameter(lp_ctx, "smb encrypt", "default");
2613 lpcfg_do_global_parameter(lp_ctx, "max log size", "5000");
2615 lpcfg_do_global_parameter(lp_ctx, "idmap negative cache time", "120");
2617 lpcfg_do_global_parameter(lp_ctx, "ldap follow referral", "auto");
2619 lpcfg_do_global_parameter(lp_ctx, "multicast dns register", "yes");
2621 lpcfg_do_global_parameter(lp_ctx, "winbind reconnect delay", "30");
2623 lpcfg_do_global_parameter(lp_ctx, "winbind request timeout", "60");
2625 lpcfg_do_global_parameter(lp_ctx, "nt acl support", "yes");
2627 lpcfg_do_global_parameter(lp_ctx, "acl check permissions", "yes");
2629 lpcfg_do_global_parameter(lp_ctx, "keepalive", "300");
2631 lpcfg_do_global_parameter(lp_ctx, "winbind cache time", "300");
2633 lpcfg_do_global_parameter(lp_ctx, "level2 oplocks", "yes");
2635 lpcfg_do_global_parameter(lp_ctx, "show add printer wizard", "yes");
2637 lpcfg_do_global_parameter(lp_ctx, "allocation roundup size", "1048576");
2639 lpcfg_do_global_parameter(lp_ctx, "ldap page size", "1024");
2641 lpcfg_do_global_parameter(lp_ctx, "kernel share modes", "yes");
2643 lpcfg_do_global_parameter(lp_ctx, "strict locking", "Auto");
2645 lpcfg_do_global_parameter(lp_ctx, "map readonly", "yes");
2647 lpcfg_do_global_parameter(lp_ctx, "allow trusted domains", "yes");
2649 lpcfg_do_global_parameter(lp_ctx, "default devmode", "yes");
2651 lpcfg_do_global_parameter(lp_ctx, "os level", "20");
2653 lpcfg_do_global_parameter(lp_ctx, "dos filetimes", "yes");
2655 lpcfg_do_global_parameter(lp_ctx, "mangling char", "~");
2657 lpcfg_do_global_parameter(lp_ctx, "printcap cache time", "750");
2659 lpcfg_do_global_parameter(lp_ctx, "create krb5 conf", "yes");
2661 lpcfg_do_global_parameter(lp_ctx, "winbind max clients", "200");
2663 lpcfg_do_global_parameter(lp_ctx, "acl map full control", "yes");
2665 lpcfg_do_global_parameter(lp_ctx, "nt pipe support", "yes");
2667 lpcfg_do_global_parameter(lp_ctx, "ldap debug threshold", "10");
2669 lpcfg_do_global_parameter(lp_ctx, "follow symlinks", "yes");
2671 lpcfg_do_global_parameter(lp_ctx, "machine password timeout", "604800");
2673 lpcfg_do_global_parameter(lp_ctx, "ldap connection timeout", "2");
2675 lpcfg_do_global_parameter(lp_ctx, "winbind expand groups", "0");
2677 lpcfg_do_global_parameter(lp_ctx, "stat cache", "yes");
2679 lpcfg_do_global_parameter(lp_ctx, "lpq cache time", "30");
2681 lpcfg_do_global_parameter_var(lp_ctx, "smb2 max trans", "%u", DEFAULT_SMB2_MAX_TRANSACT);
2683 lpcfg_do_global_parameter_var(lp_ctx, "smb2 max read", "%u", DEFAULT_SMB2_MAX_READ);
2685 lpcfg_do_global_parameter(lp_ctx, "durable handles", "yes");
2687 lpcfg_do_global_parameter(lp_ctx, "max stat cache size", "256");
2689 lpcfg_do_global_parameter(lp_ctx, "ldap passwd sync", "no");
2691 lpcfg_do_global_parameter(lp_ctx, "kernel change notify", "yes");
2693 lpcfg_do_global_parameter(lp_ctx, "max ttl", "259200");
2695 lpcfg_do_global_parameter(lp_ctx, "blocking locks", "yes");
2697 lpcfg_do_global_parameter(lp_ctx, "oplock contention limit", "2");
2699 lpcfg_do_global_parameter(lp_ctx, "load printers", "yes");
2701 lpcfg_do_global_parameter(lp_ctx, "idmap cache time", "604800");
2703 lpcfg_do_global_parameter(lp_ctx, "preserve case", "yes");
2705 lpcfg_do_global_parameter(lp_ctx, "lm announce", "auto");
2707 lpcfg_do_global_parameter(lp_ctx, "afs token lifetime", "604800");
2709 lpcfg_do_global_parameter(lp_ctx, "enable core files", "yes");
2711 lpcfg_do_global_parameter(lp_ctx, "winbind max domain connections", "1");
2713 lpcfg_do_global_parameter(lp_ctx, "case sensitive", "auto");
2715 lpcfg_do_global_parameter(lp_ctx, "ldap timeout", "15");
2717 lpcfg_do_global_parameter(lp_ctx, "mangle prefix", "1");
2719 lpcfg_do_global_parameter(lp_ctx, "posix locking", "yes");
2721 lpcfg_do_global_parameter(lp_ctx, "lock spin time", "200");
2723 lpcfg_do_global_parameter(lp_ctx, "directory name cache size", "100");
2725 lpcfg_do_global_parameter(lp_ctx, "nmbd bind explicit broadcast", "yes");
2727 lpcfg_do_global_parameter(lp_ctx, "init logon delay", "100");
2729 lpcfg_do_global_parameter(lp_ctx, "usershare owner only", "yes");
2731 lpcfg_do_global_parameter(lp_ctx, "-valid", "yes");
2733 lpcfg_do_global_parameter_var(lp_ctx, "usershare path", "%s/usershares", get_dyn_STATEDIR());
2736 lpcfg_do_global_parameter_var(lp_ctx, "panic action", "/bin/sleep 999999999");
2739 lpcfg_do_global_parameter(lp_ctx, "smb passwd file", get_dyn_SMB_PASSWD_FILE());
2741 lpcfg_do_global_parameter(lp_ctx, "logon home", "\\\\%N\\%U");
2743 lpcfg_do_global_parameter(lp_ctx, "logon path", "\\\\%N\\%U\\profile");
2745 lpcfg_do_global_parameter(lp_ctx, "printjob username", "%U");
2747 for (i = 0; parm_table[i].label; i++) {
2748 if (!(lp_ctx->flags[i] & FLAG_CMDLINE)) {
2749 lp_ctx->flags[i] |= FLAG_DEFAULT;
2753 for (parm=lp_ctx->globals->param_opt; parm; parm=parm->next) {
2754 if (!(parm->priority & FLAG_CMDLINE)) {
2755 parm->priority |= FLAG_DEFAULT;
2759 for (parm=lp_ctx->sDefault->param_opt; parm; parm=parm->next) {
2760 if (!(parm->priority & FLAG_CMDLINE)) {
2761 parm->priority |= FLAG_DEFAULT;
2770 * Initialise the global parameter structure.
2772 struct loadparm_context *loadparm_init_global(bool load_default)
2774 if (global_loadparm_context == NULL) {
2775 global_loadparm_context = loadparm_init(NULL);
2777 if (global_loadparm_context == NULL) {
2780 global_loadparm_context->global = true;
2781 if (load_default && !global_loadparm_context->loaded) {
2782 lpcfg_load_default(global_loadparm_context);
2784 global_loadparm_context->refuse_free = true;
2785 return global_loadparm_context;
2789 * Initialise the global parameter structure.
2791 struct loadparm_context *loadparm_init_s3(TALLOC_CTX *mem_ctx,
2792 const struct loadparm_s3_helpers *s3_fns)
2794 struct loadparm_context *loadparm_context = talloc_zero(mem_ctx, struct loadparm_context);
2795 if (!loadparm_context) {
2798 loadparm_context->s3_fns = s3_fns;
2799 loadparm_context->globals = s3_fns->globals;
2800 loadparm_context->flags = s3_fns->flags;
2802 return loadparm_context;
2805 const char *lpcfg_configfile(struct loadparm_context *lp_ctx)
2807 return lp_ctx->szConfigFile;
2810 const char *lp_default_path(void)
2812 if (getenv("SMB_CONF_PATH"))
2813 return getenv("SMB_CONF_PATH");
2815 return dyn_CONFIGFILE;
2819 * Update the internal state of a loadparm context after settings
2822 static bool lpcfg_update(struct loadparm_context *lp_ctx)
2824 struct debug_settings settings;
2825 TALLOC_CTX *tmp_ctx;
2827 tmp_ctx = talloc_new(lp_ctx);
2828 if (tmp_ctx == NULL) {
2832 lpcfg_add_auto_services(lp_ctx, lpcfg_auto_services(lp_ctx, tmp_ctx));
2834 if (!lp_ctx->globals->wins_server_list && lp_ctx->globals->we_are_a_wins_server) {
2835 lpcfg_do_global_parameter(lp_ctx, "wins server", "127.0.0.1");
2838 if (!lp_ctx->global) {
2839 TALLOC_FREE(tmp_ctx);
2843 panic_action = lp_ctx->globals->panic_action;
2845 reload_charcnv(lp_ctx);
2847 ZERO_STRUCT(settings);
2848 /* Add any more debug-related smb.conf parameters created in
2850 settings.syslog = lp_ctx->globals->syslog;
2851 settings.syslog_only = lp_ctx->globals->syslog_only;
2852 settings.timestamp_logs = lp_ctx->globals->timestamp_logs;
2853 settings.debug_prefix_timestamp = lp_ctx->globals->debug_prefix_timestamp;
2854 settings.debug_hires_timestamp = lp_ctx->globals->debug_hires_timestamp;
2855 settings.debug_pid = lp_ctx->globals->debug_pid;
2856 settings.debug_uid = lp_ctx->globals->debug_uid;
2857 settings.debug_class = lp_ctx->globals->debug_class;
2858 debug_set_settings(&settings);
2860 /* FIXME: This is a bit of a hack, but we can't use a global, since
2861 * not everything that uses lp also uses the socket library */
2862 if (lpcfg_parm_bool(lp_ctx, NULL, "socket", "testnonblock", false)) {
2863 setenv("SOCKET_TESTNONBLOCK", "1", 1);
2865 unsetenv("SOCKET_TESTNONBLOCK");
2868 TALLOC_FREE(tmp_ctx);
2872 bool lpcfg_load_default(struct loadparm_context *lp_ctx)
2876 path = lp_default_path();
2878 if (!file_exist(path)) {
2879 /* We allow the default smb.conf file to not exist,
2880 * basically the equivalent of an empty file. */
2881 return lpcfg_update(lp_ctx);
2884 return lpcfg_load(lp_ctx, path);
2888 * Load the services array from the services file.
2890 * Return True on success, False on failure.
2892 bool lpcfg_load(struct loadparm_context *lp_ctx, const char *filename)
2897 filename = talloc_strdup(lp_ctx, filename);
2899 lp_ctx->szConfigFile = filename;
2901 if (lp_ctx->s3_fns) {
2902 return lp_ctx->s3_fns->load(filename);
2905 lp_ctx->bInGlobalSection = true;
2906 n2 = standard_sub_basic(lp_ctx, lp_ctx->szConfigFile);
2907 DEBUG(2, ("lpcfg_load: refreshing parameters from %s\n", n2));
2909 add_to_file_list(lp_ctx, &lp_ctx->file_lists, lp_ctx->szConfigFile, n2);
2911 /* We get sections first, so have to start 'behind' to make up */
2912 lp_ctx->currentService = NULL;
2913 bRetval = pm_process(n2, do_section, lpcfg_do_parameter, lp_ctx);
2915 /* finish up the last section */
2916 DEBUG(4, ("pm_process() returned %s\n", BOOLSTR(bRetval)));
2918 if (lp_ctx->currentService != NULL)
2919 bRetval = lpcfg_service_ok(lp_ctx->currentService);
2921 bRetval = bRetval && lpcfg_update(lp_ctx);
2923 /* we do this unconditionally, so that it happens even
2924 for a missing smb.conf */
2925 reload_charcnv(lp_ctx);
2927 if (bRetval == true) {
2928 /* set this up so that any child python tasks will
2929 find the right smb.conf */
2930 setenv("SMB_CONF_PATH", filename, 1);
2932 /* set the context used by the lp_*() function
2934 global_loadparm_context = lp_ctx;
2935 lp_ctx->loaded = true;
2942 * Return the max number of services.
2945 int lpcfg_numservices(struct loadparm_context *lp_ctx)
2947 if (lp_ctx->s3_fns) {
2948 return lp_ctx->s3_fns->get_numservices();
2951 return lp_ctx->iNumServices;
2955 * Display the contents of the services array in human-readable form.
2958 void lpcfg_dump(struct loadparm_context *lp_ctx, FILE *f, bool show_defaults,
2963 if (lp_ctx->s3_fns) {
2964 lp_ctx->s3_fns->dump(f, show_defaults, maxtoprint);
2968 lpcfg_dump_globals(lp_ctx, f, show_defaults);
2970 lpcfg_dump_a_service(lp_ctx->sDefault, lp_ctx->sDefault, f, lp_ctx->flags, show_defaults);
2972 for (iService = 0; iService < maxtoprint; iService++)
2973 lpcfg_dump_one(f, show_defaults, lp_ctx->services[iService], lp_ctx->sDefault);
2977 * Display the contents of one service in human-readable form.
2979 void lpcfg_dump_one(FILE *f, bool show_defaults, struct loadparm_service *service, struct loadparm_service *sDefault)
2981 if (service != NULL) {
2982 if (service->szService[0] == '\0')
2984 lpcfg_dump_a_service(service, sDefault, f, NULL, show_defaults);
2988 struct loadparm_service *lpcfg_servicebynum(struct loadparm_context *lp_ctx,
2991 if (lp_ctx->s3_fns) {
2992 return lp_ctx->s3_fns->get_servicebynum(snum);
2995 return lp_ctx->services[snum];
2998 struct loadparm_service *lpcfg_service(struct loadparm_context *lp_ctx,
2999 const char *service_name)
3004 if (lp_ctx->s3_fns) {
3005 return lp_ctx->s3_fns->get_service(service_name);
3008 for (iService = lp_ctx->iNumServices - 1; iService >= 0; iService--) {
3009 if (lp_ctx->services[iService] &&
3010 lp_ctx->services[iService]->szService) {
3012 * The substitution here is used to support %U is
3015 serviceName = standard_sub_basic(
3016 lp_ctx->services[iService],
3017 lp_ctx->services[iService]->szService);
3018 if (strequal(serviceName, service_name)) {
3019 talloc_free(serviceName);
3020 return lp_ctx->services[iService];
3022 talloc_free(serviceName);
3026 DEBUG(7,("lpcfg_servicenumber: couldn't find %s\n", service_name));
3030 const char *lpcfg_servicename(const struct loadparm_service *service)
3032 return lpcfg_string((const char *)service->szService);
3036 * A useful volume label function.
3038 const char *lpcfg_volume_label(struct loadparm_service *service, struct loadparm_service *sDefault)
3041 ret = lpcfg_string((const char *)((service != NULL && service->volume != NULL) ?
3042 service->volume : sDefault->volume));
3044 return lpcfg_servicename(service);
3049 * Return the correct printer name.
3051 const char *lpcfg_printername(struct loadparm_service *service, struct loadparm_service *sDefault)
3054 ret = lpcfg_string((const char *)((service != NULL && service->_printername != NULL) ?
3055 service->_printername : sDefault->_printername));
3056 if (ret == NULL || (ret != NULL && *ret == '\0'))
3057 ret = lpcfg_servicename(service);
3064 * Return the max print jobs per queue.
3066 int lpcfg_maxprintjobs(struct loadparm_service *service, struct loadparm_service *sDefault)
3068 int maxjobs = (service != NULL) ? service->iMaxPrintJobs : sDefault->iMaxPrintJobs;
3069 if (maxjobs <= 0 || maxjobs >= PRINT_MAX_JOBID)
3070 maxjobs = PRINT_MAX_JOBID - 1;
3075 struct smb_iconv_handle *lpcfg_iconv_handle(struct loadparm_context *lp_ctx)
3077 if (lp_ctx == NULL) {
3078 return get_iconv_handle();
3080 return lp_ctx->iconv_handle;
3083 _PUBLIC_ void reload_charcnv(struct loadparm_context *lp_ctx)
3085 struct smb_iconv_handle *old_ic = lp_ctx->iconv_handle;
3086 if (!lp_ctx->global) {
3090 if (old_ic == NULL) {
3091 old_ic = global_iconv_handle;
3093 lp_ctx->iconv_handle = smb_iconv_handle_reinit_lp(lp_ctx, lp_ctx, old_ic);
3094 global_iconv_handle = lp_ctx->iconv_handle;
3097 _PUBLIC_ char *lpcfg_tls_keyfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
3099 return lpcfg_private_path(mem_ctx, lp_ctx, lpcfg__tls_keyfile(lp_ctx));
3102 _PUBLIC_ char *lpcfg_tls_certfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
3104 return lpcfg_private_path(mem_ctx, lp_ctx, lpcfg__tls_certfile(lp_ctx));
3107 _PUBLIC_ char *lpcfg_tls_cafile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
3109 return lpcfg_private_path(mem_ctx, lp_ctx, lpcfg__tls_cafile(lp_ctx));
3112 _PUBLIC_ char *lpcfg_tls_crlfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
3114 return lpcfg_private_path(mem_ctx, lp_ctx, lpcfg__tls_crlfile(lp_ctx));
3117 _PUBLIC_ char *lpcfg_tls_dhpfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
3119 return lpcfg_private_path(mem_ctx, lp_ctx, lpcfg__tls_dhpfile(lp_ctx));
3122 struct gensec_settings *lpcfg_gensec_settings(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
3124 struct gensec_settings *settings = talloc_zero(mem_ctx, struct gensec_settings);
3125 if (settings == NULL)
3127 SMB_ASSERT(lp_ctx != NULL);
3128 settings->lp_ctx = talloc_reference(settings, lp_ctx);
3129 settings->target_hostname = lpcfg_parm_string(lp_ctx, NULL, "gensec", "target_hostname");
3133 int lpcfg_server_role(struct loadparm_context *lp_ctx)
3135 int domain_master = lpcfg__domain_master(lp_ctx);
3137 return lp_find_server_role(lpcfg__server_role(lp_ctx),
3138 lpcfg__security(lp_ctx),
3139 lpcfg__domain_logons(lp_ctx),
3140 (domain_master == true) ||
3141 (domain_master == Auto));
3144 int lpcfg_security(struct loadparm_context *lp_ctx)
3146 return lp_find_security(lpcfg__server_role(lp_ctx),
3147 lpcfg__security(lp_ctx));
3150 bool lpcfg_server_signing_allowed(struct loadparm_context *lp_ctx, bool *mandatory)
3152 bool allowed = true;
3153 enum smb_signing_setting signing_setting = lpcfg_server_signing(lp_ctx);
3157 if (signing_setting == SMB_SIGNING_DEFAULT) {
3159 * If we are a domain controller, SMB signing is
3160 * really important, as it can prevent a number of
3161 * attacks on communications between us and the
3164 * However, it really sucks (no sendfile, CPU
3165 * overhead) performance-wise when used on a
3166 * file server, so disable it by default
3170 if (lpcfg_server_role(lp_ctx) >= ROLE_ACTIVE_DIRECTORY_DC) {
3171 signing_setting = SMB_SIGNING_REQUIRED;
3173 signing_setting = SMB_SIGNING_OFF;
3177 switch (signing_setting) {
3178 case SMB_SIGNING_REQUIRED:
3181 case SMB_SIGNING_IF_REQUIRED:
3183 case SMB_SIGNING_DEFAULT:
3184 case SMB_SIGNING_OFF:
3192 int lpcfg_tdb_hash_size(struct loadparm_context *lp_ctx, const char *name)
3200 base = strrchr_m(name, '/');
3206 return lpcfg_parm_int(lp_ctx, NULL, "tdb_hashsize", base, 0);
3210 int lpcfg_tdb_flags(struct loadparm_context *lp_ctx, int tdb_flags)
3212 if (!lpcfg_use_mmap(lp_ctx)) {
3213 tdb_flags |= TDB_NOMMAP;