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 #define LOADPARM_SUBSTITUTION_INTERNALS 1
65 #include "lib/param/loadparm.h"
66 #include "auth/gensec/gensec.h"
67 #include "lib/param/s3_param.h"
68 #include "lib/util/bitmap.h"
69 #include "libcli/smb/smb_constants.h"
71 #include "librpc/gen_ndr/nbt.h"
72 #include "librpc/gen_ndr/dns.h"
73 #include "librpc/gen_ndr/security.h"
74 #include "libds/common/roles.h"
75 #include "lib/util/samba_util.h"
76 #include "libcli/auth/ntlm_check.h"
77 #include "lib/crypto/gnutls_helpers.h"
78 #include "lib/util/smb_strtox.h"
79 #include "auth/credentials/credentials.h"
81 #ifdef HAVE_HTTPCONNECTENCRYPT
82 #include <cups/http.h>
85 #define standard_sub_basic talloc_strdup
87 #include "lib/param/param_global.h"
89 struct loadparm_service *lpcfg_default_service(struct loadparm_context *lp_ctx)
91 return lp_ctx->sDefault;
94 int lpcfg_rpc_low_port(struct loadparm_context *lp_ctx)
96 return lp_ctx->globals->rpc_low_port;
99 int lpcfg_rpc_high_port(struct loadparm_context *lp_ctx)
101 return lp_ctx->globals->rpc_high_port;
104 enum samba_weak_crypto lpcfg_weak_crypto(struct loadparm_context *lp_ctx)
106 if (lp_ctx->globals->weak_crypto == SAMBA_WEAK_CRYPTO_UNKNOWN) {
107 lp_ctx->globals->weak_crypto = SAMBA_WEAK_CRYPTO_DISALLOWED;
109 if (samba_gnutls_weak_crypto_allowed()) {
110 lp_ctx->globals->weak_crypto = SAMBA_WEAK_CRYPTO_ALLOWED;
114 return lp_ctx->globals->weak_crypto;
118 * Convenience routine to grab string parameters into temporary memory
119 * and run standard_sub_basic on them.
121 * The buffers can be written to by
122 * callers without affecting the source string.
125 static const char *lpcfg_string(const char *s)
127 #if 0 /* until REWRITE done to make thread-safe */
128 size_t len = s ? strlen(s) : 0;
132 /* The follow debug is useful for tracking down memory problems
133 especially if you have an inner loop that is calling a lp_*()
134 function that returns a string. Perhaps this debug should be
135 present all the time? */
138 DEBUG(10, ("lpcfg_string(%s)\n", s));
141 #if 0 /* until REWRITE done to make thread-safe */
143 lp_talloc = talloc_init("lp_talloc");
145 ret = talloc_array(lp_talloc, char, len + 100); /* leave room for substitution */
153 strlcpy(ret, s, len);
155 if (trim_string(ret, "\"", "\"")) {
156 if (strchr(ret,'"') != NULL)
157 strlcpy(ret, s, len);
160 standard_sub_basic(ret,len+100);
167 In this section all the functions that are used to access the
168 parameters from the rest of the program are defined
172 * the creation of separate lpcfg_*() and lp_*() functions is to allow
173 * for code compatibility between existing Samba4 and Samba3 code.
176 /* this global context supports the lp_*() function varients */
177 static struct loadparm_context *global_loadparm_context;
179 #define FN_GLOBAL_SUBSTITUTED_STRING(fn_name,var_name) \
180 _PUBLIC_ char *lpcfg_ ## fn_name(struct loadparm_context *lp_ctx, \
181 const struct loadparm_substitution *lp_sub, TALLOC_CTX *mem_ctx) \
183 if (lp_ctx == NULL) return NULL; \
184 return lpcfg_substituted_string(mem_ctx, lp_sub, \
185 lp_ctx->globals->var_name ? lp_ctx->globals->var_name : ""); \
188 #define FN_GLOBAL_CONST_STRING(fn_name,var_name) \
189 _PUBLIC_ const char *lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) { \
190 if (lp_ctx == NULL) return NULL; \
191 return lp_ctx->globals->var_name ? lpcfg_string(lp_ctx->globals->var_name) : ""; \
194 #define FN_GLOBAL_LIST(fn_name,var_name) \
195 _PUBLIC_ const char **lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) { \
196 if (lp_ctx == NULL) return NULL; \
197 return lp_ctx->globals->var_name; \
200 #define FN_GLOBAL_BOOL(fn_name,var_name) \
201 _PUBLIC_ bool lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) {\
202 if (lp_ctx == NULL) return false; \
203 return lp_ctx->globals->var_name; \
206 #define FN_GLOBAL_INTEGER(fn_name,var_name) \
207 _PUBLIC_ int lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) { \
208 return lp_ctx->globals->var_name; \
211 /* Local parameters don't need the ->s3_fns because the struct
212 * loadparm_service is shared and lpcfg_service() checks the ->s3_fns
214 #define FN_LOCAL_SUBSTITUTED_STRING(fn_name,val) \
215 _PUBLIC_ char *lpcfg_ ## fn_name(struct loadparm_service *service, \
216 struct loadparm_service *sDefault, TALLOC_CTX *ctx) { \
217 return(talloc_strdup(ctx, lpcfg_string((const char *)((service != NULL && service->val != NULL) ? service->val : sDefault->val)))); \
220 #define FN_LOCAL_CONST_STRING(fn_name,val) \
221 _PUBLIC_ const char *lpcfg_ ## fn_name(struct loadparm_service *service, \
222 struct loadparm_service *sDefault) { \
223 return((const char *)((service != NULL && service->val != NULL) ? service->val : sDefault->val)); \
226 #define FN_LOCAL_LIST(fn_name,val) \
227 _PUBLIC_ const char **lpcfg_ ## fn_name(struct loadparm_service *service, \
228 struct loadparm_service *sDefault) {\
229 return(const char **)(service != NULL && service->val != NULL? service->val : sDefault->val); \
232 #define FN_LOCAL_PARM_BOOL(fn_name, val) FN_LOCAL_BOOL(fn_name, val)
234 #define FN_LOCAL_BOOL(fn_name,val) \
235 _PUBLIC_ bool lpcfg_ ## fn_name(struct loadparm_service *service, \
236 struct loadparm_service *sDefault) { \
237 return((service != NULL)? service->val : sDefault->val); \
240 #define FN_LOCAL_INTEGER(fn_name,val) \
241 _PUBLIC_ int lpcfg_ ## fn_name(struct loadparm_service *service, \
242 struct loadparm_service *sDefault) { \
243 return((service != NULL)? service->val : sDefault->val); \
246 #define FN_LOCAL_PARM_INTEGER(fn_name, val) FN_LOCAL_INTEGER(fn_name, val)
248 #define FN_LOCAL_CHAR(fn_name,val) \
249 _PUBLIC_ char lpcfg_ ## fn_name(struct loadparm_service *service, \
250 struct loadparm_service *sDefault) { \
251 return((service != NULL)? service->val : sDefault->val); \
254 #define FN_LOCAL_PARM_CHAR(fn_name,val) FN_LOCAL_CHAR(fn_name, val)
256 #include "lib/param/param_functions.c"
258 /* These functions cannot be auto-generated */
259 FN_LOCAL_BOOL(autoloaded, autoloaded)
260 FN_GLOBAL_CONST_STRING(dnsdomain, dnsdomain)
262 /* local prototypes */
263 static struct loadparm_service *lpcfg_getservicebyname(struct loadparm_context *lp_ctx,
264 const char *pszServiceName);
265 static bool do_section(const char *pszSectionName, void *);
266 static bool set_variable_helper(TALLOC_CTX *mem_ctx, int parmnum, void *parm_ptr,
267 const char *pszParmName, const char *pszParmValue);
268 static bool lp_do_parameter_parametric(struct loadparm_context *lp_ctx,
269 struct loadparm_service *service,
270 const char *pszParmName,
271 const char *pszParmValue, int flags);
273 /* The following are helper functions for parametrical options support. */
274 /* It returns a pointer to parametrical option value if it exists or NULL otherwise */
275 /* Actual parametrical functions are quite simple */
276 struct parmlist_entry *get_parametric_helper(struct loadparm_service *service,
277 const char *type, const char *option,
278 struct parmlist_entry *global_opts)
280 size_t type_len = strlen(type);
281 size_t option_len = strlen(option);
282 char param_key[type_len + option_len + 2];
283 struct parmlist_entry *data = NULL;
285 snprintf(param_key, sizeof(param_key), "%s:%s", type, option);
288 * Try to fetch the option from the data.
290 if (service != NULL) {
291 data = service->param_opt;
292 while (data != NULL) {
293 if (strwicmp(data->key, param_key) == 0) {
301 * Fall back to fetching from the globals.
304 while (data != NULL) {
305 if (strwicmp(data->key, param_key) == 0) {
314 const char *lpcfg_get_parametric(struct loadparm_context *lp_ctx,
315 struct loadparm_service *service,
316 const char *type, const char *option)
318 struct parmlist_entry *data;
323 data = get_parametric_helper(service,
324 type, option, lp_ctx->globals->param_opt);
335 * convenience routine to return int parameters.
337 int lp_int(const char *s)
341 DEBUG(0,("lp_int(%s): is called with NULL!\n",s));
345 return strtol(s, NULL, 0);
349 * convenience routine to return unsigned long parameters.
351 unsigned long lp_ulong(const char *s)
354 unsigned long int ret;
357 DBG_DEBUG("lp_ulong(%s): is called with NULL!\n",s);
361 ret = smb_strtoul(s, NULL, 0, &error, SMB_STR_STANDARD);
363 DBG_DEBUG("lp_ulong(%s): conversion failed\n",s);
371 * convenience routine to return unsigned long long parameters.
373 unsigned long long lp_ulonglong(const char *s)
376 unsigned long long int ret;
379 DBG_DEBUG("lp_ulonglong(%s): is called with NULL!\n", s);
383 ret = smb_strtoull(s, NULL, 0, &error, SMB_STR_STANDARD);
385 DBG_DEBUG("lp_ulonglong(%s): conversion failed\n",s);
393 * convenience routine to return unsigned long parameters.
395 static long lp_long(const char *s)
399 DEBUG(0,("lp_long(%s): is called with NULL!\n",s));
403 return strtol(s, NULL, 0);
407 * convenience routine to return unsigned long parameters.
409 static double lp_double(const char *s)
413 DEBUG(0,("lp_double(%s): is called with NULL!\n",s));
417 return strtod(s, NULL);
421 * convenience routine to return boolean parameters.
423 bool lp_bool(const char *s)
428 DEBUG(0,("lp_bool(%s): is called with NULL!\n",s));
432 if (!set_boolean(s, &ret)) {
433 DEBUG(0,("lp_bool(%s): value is not boolean!\n",s));
441 * Return parametric option from a given service. Type is a part of option before ':'
442 * Parametric option has following syntax: 'Type: option = value'
443 * Returned value is allocated in 'lp_talloc' context
446 const char *lpcfg_parm_string(struct loadparm_context *lp_ctx,
447 struct loadparm_service *service, const char *type,
450 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
453 return lpcfg_string(value);
459 * Return parametric option from a given service. Type is a part of option before ':'
460 * Parametric option has following syntax: 'Type: option = value'
461 * Returned value is allocated in 'lp_talloc' context
464 const char **lpcfg_parm_string_list(TALLOC_CTX *mem_ctx,
465 struct loadparm_context *lp_ctx,
466 struct loadparm_service *service,
468 const char *option, const char *separator)
470 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
473 char **l = str_list_make(mem_ctx, value, separator);
474 return discard_const_p(const char *, l);
481 * Return parametric option from a given service. Type is a part of option before ':'
482 * Parametric option has following syntax: 'Type: option = value'
485 int lpcfg_parm_int(struct loadparm_context *lp_ctx,
486 struct loadparm_service *service, const char *type,
487 const char *option, int default_v)
489 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
492 return lp_int(value);
498 * Return parametric option from a given service. Type is a part of
500 * Parametric option has following syntax: 'Type: option = value'.
503 int lpcfg_parm_bytes(struct loadparm_context *lp_ctx,
504 struct loadparm_service *service, const char *type,
505 const char *option, int default_v)
509 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
511 if (value && conv_str_size_error(value, &bval)) {
512 if (bval <= INT_MAX) {
521 * Return parametric option from a given service.
522 * Type is a part of option before ':'
523 * Parametric option has following syntax: 'Type: option = value'
525 unsigned long lpcfg_parm_ulong(struct loadparm_context *lp_ctx,
526 struct loadparm_service *service, const char *type,
527 const char *option, unsigned long default_v)
529 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
532 return lp_ulong(value);
538 * Return parametric option from a given service.
539 * Type is a part of option before ':'
540 * Parametric option has following syntax: 'Type: option = value'
542 unsigned long long lpcfg_parm_ulonglong(struct loadparm_context *lp_ctx,
543 struct loadparm_service *service,
544 const char *type, const char *option,
545 unsigned long long default_v)
547 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
550 return lp_ulonglong(value);
556 long lpcfg_parm_long(struct loadparm_context *lp_ctx,
557 struct loadparm_service *service, const char *type,
558 const char *option, long default_v)
560 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
563 return lp_long(value);
568 double lpcfg_parm_double(struct loadparm_context *lp_ctx,
569 struct loadparm_service *service, const char *type,
570 const char *option, double default_v)
572 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
575 return lp_double(value);
581 * Return parametric option from a given service. Type is a part of option before ':'
582 * Parametric option has following syntax: 'Type: option = value'
585 bool lpcfg_parm_bool(struct loadparm_context *lp_ctx,
586 struct loadparm_service *service, const char *type,
587 const char *option, bool default_v)
589 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
592 return lp_bool(value);
598 /* this is used to prevent lots of mallocs of size 1 */
599 static const char lpcfg_string_empty[] = "";
604 void lpcfg_string_free(char **s)
609 if (*s == lpcfg_string_empty) {
617 * Set a string value, deallocating any existing space, and allocing the space
620 bool lpcfg_string_set(TALLOC_CTX *mem_ctx, char **dest, const char *src)
622 lpcfg_string_free(dest);
624 if ((src == NULL) || (*src == '\0')) {
625 *dest = discard_const_p(char, lpcfg_string_empty);
629 *dest = talloc_strdup(mem_ctx, src);
630 if ((*dest) == NULL) {
631 DEBUG(0,("Out of memory in string_set\n"));
639 * Set a string value, deallocating any existing space, and allocing the space
642 bool lpcfg_string_set_upper(TALLOC_CTX *mem_ctx, char **dest, const char *src)
644 lpcfg_string_free(dest);
646 if ((src == NULL) || (*src == '\0')) {
647 *dest = discard_const_p(char, lpcfg_string_empty);
651 *dest = strupper_talloc(mem_ctx, src);
652 if ((*dest) == NULL) {
653 DEBUG(0,("Out of memory in string_set_upper\n"));
663 * Add a new service to the services array initialising it with the given
667 struct loadparm_service *lpcfg_add_service(struct loadparm_context *lp_ctx,
668 const struct loadparm_service *pservice,
672 int num_to_alloc = lp_ctx->iNumServices + 1;
673 struct parmlist_entry *data, *pdata;
675 if (lp_ctx->s3_fns != NULL) {
676 smb_panic("Add a service should not be called on an s3 loadparm ctx");
679 if (pservice == NULL) {
680 pservice = lp_ctx->sDefault;
683 /* it might already exist */
685 struct loadparm_service *service = lpcfg_getservicebyname(lp_ctx,
687 if (service != NULL) {
688 /* Clean all parametric options for service */
689 /* They will be added during parsing again */
690 data = service->param_opt;
696 service->param_opt = NULL;
701 /* find an invalid one */
702 for (i = 0; i < lp_ctx->iNumServices; i++)
703 if (lp_ctx->services[i] == NULL)
706 /* if not, then create one */
707 if (i == lp_ctx->iNumServices) {
708 struct loadparm_service **tsp;
710 tsp = talloc_realloc(lp_ctx, lp_ctx->services, struct loadparm_service *, num_to_alloc);
713 DEBUG(0,("lpcfg_add_service: failed to enlarge services!\n"));
716 lp_ctx->services = tsp;
717 lp_ctx->services[lp_ctx->iNumServices] = NULL;
720 lp_ctx->iNumServices++;
723 lp_ctx->services[i] = talloc_zero(lp_ctx->services, struct loadparm_service);
724 if (lp_ctx->services[i] == NULL) {
725 DEBUG(0,("lpcfg_add_service: out of memory!\n"));
728 copy_service(lp_ctx->services[i], pservice, NULL);
730 lpcfg_string_set(lp_ctx->services[i], &lp_ctx->services[i]->szService, name);
731 return lp_ctx->services[i];
735 * Map a parameter's string representation to something we can use.
736 * Returns False if the parameter string is not recognised, else TRUE.
739 int lpcfg_map_parameter(const char *pszParmName)
743 for (iIndex = 0; parm_table[iIndex].label; iIndex++)
744 if (strwicmp(parm_table[iIndex].label, pszParmName) == 0)
747 /* Warn only if it isn't parametric option */
748 if (strchr(pszParmName, ':') == NULL)
749 DEBUG(0, ("Unknown parameter encountered: \"%s\"\n", pszParmName));
750 /* We do return 'fail' for parametric options as well because they are
751 stored in different storage
758 return the parameter structure for a parameter
760 struct parm_struct *lpcfg_parm_struct(struct loadparm_context *lp_ctx, const char *name)
762 int num = lpcfg_map_parameter(name);
768 return &parm_table[num];
772 return the parameter pointer for a parameter
774 void *lpcfg_parm_ptr(struct loadparm_context *lp_ctx,
775 struct loadparm_service *service, struct parm_struct *parm)
777 if (lp_ctx->s3_fns) {
778 return lp_ctx->s3_fns->get_parm_ptr(service, parm);
781 if (service == NULL) {
782 if (parm->p_class == P_LOCAL)
783 return ((char *)lp_ctx->sDefault)+parm->offset;
784 else if (parm->p_class == P_GLOBAL)
785 return ((char *)lp_ctx->globals)+parm->offset;
788 return ((char *)service) + parm->offset;
793 return the parameter pointer for a parameter
795 bool lpcfg_parm_is_cmdline(struct loadparm_context *lp_ctx, const char *name)
799 parmnum = lpcfg_map_parameter(name);
800 if (parmnum == -1) return false;
802 return lp_ctx->flags[parmnum] & FLAG_CMDLINE;
805 bool lpcfg_parm_is_unspecified(struct loadparm_context *lp_ctx, const char *name)
809 parmnum = lpcfg_map_parameter(name);
810 if (parmnum == -1) return false;
812 return lp_ctx->flags[parmnum] & FLAG_DEFAULT;
816 * Find a service by name. Otherwise works like get_service.
819 static struct loadparm_service *lpcfg_getservicebyname(struct loadparm_context *lp_ctx,
820 const char *pszServiceName)
824 if (lp_ctx->s3_fns) {
825 return lp_ctx->s3_fns->get_service(pszServiceName);
828 for (iService = lp_ctx->iNumServices - 1; iService >= 0; iService--)
829 if (lp_ctx->services[iService] != NULL &&
830 strwicmp(lp_ctx->services[iService]->szService, pszServiceName) == 0) {
831 return lp_ctx->services[iService];
838 * Add a parametric option to a parmlist_entry,
839 * replacing old value, if already present.
841 void set_param_opt(TALLOC_CTX *mem_ctx,
842 struct parmlist_entry **opt_list,
843 const char *opt_name,
844 const char *opt_value,
847 struct parmlist_entry *new_opt, *opt;
851 /* Traverse destination */
853 /* If we already have same option, override it */
854 if (strwicmp(opt->key, opt_name) == 0) {
855 if ((opt->priority & FLAG_CMDLINE) &&
856 !(priority & FLAG_CMDLINE)) {
857 /* it's been marked as not to be
861 TALLOC_FREE(opt->list);
862 lpcfg_string_set(opt, &opt->value, opt_value);
863 opt->priority = priority;
869 new_opt = talloc_pooled_object(
870 mem_ctx, struct parmlist_entry,
871 2, strlen(opt_name) + 1 + strlen(opt_value) + 1);
872 if (new_opt == NULL) {
876 lpcfg_string_set(new_opt, &new_opt->key, opt_name);
877 new_opt->value = NULL;
878 lpcfg_string_set(new_opt, &new_opt->value, opt_value);
880 new_opt->list = NULL;
881 new_opt->priority = priority;
882 DLIST_ADD(*opt_list, new_opt);
886 * Copy a service structure to another.
887 * If pcopymapDest is NULL then copy all fields
890 void copy_service(struct loadparm_service *pserviceDest,
891 const struct loadparm_service *pserviceSource,
892 struct bitmap *pcopymapDest)
895 bool bcopyall = (pcopymapDest == NULL);
896 struct parmlist_entry *data;
898 for (i = 0; parm_table[i].label; i++)
899 if (parm_table[i].p_class == P_LOCAL &&
900 (bcopyall || bitmap_query(pcopymapDest, i))) {
901 const void *src_ptr =
902 ((const char *)pserviceSource) + parm_table[i].offset;
904 ((char *)pserviceDest) + parm_table[i].offset;
906 switch (parm_table[i].type) {
909 *(bool *)dest_ptr = *(const bool *)src_ptr;
916 *(int *)dest_ptr = *(const int *)src_ptr;
920 *(char *)dest_ptr = *(const char *)src_ptr;
924 lpcfg_string_set(pserviceDest,
926 *(const char * const *)src_ptr);
930 lpcfg_string_set_upper(pserviceDest,
932 *(const char * const *)src_ptr);
936 TALLOC_FREE(*((char ***)dest_ptr));
937 *(char ***)dest_ptr = str_list_copy(pserviceDest,
938 *discard_const_p(const char **, src_ptr));
946 init_copymap(pserviceDest);
947 if (pserviceSource->copymap)
948 bitmap_copy(pserviceDest->copymap,
949 pserviceSource->copymap);
952 for (data = pserviceSource->param_opt; data != NULL; data = data->next) {
953 set_param_opt(pserviceDest, &pserviceDest->param_opt,
954 data->key, data->value, data->priority);
959 * Check a service for consistency. Return False if the service is in any way
960 * incomplete or faulty, else True.
962 bool lpcfg_service_ok(struct loadparm_service *service)
967 if (service->szService[0] == '\0') {
968 DEBUG(0, ("The following message indicates an internal error:\n"));
969 DEBUG(0, ("No service name in service entry.\n"));
973 /* The [printers] entry MUST be printable. I'm all for flexibility, but */
974 /* I can't see why you'd want a non-printable printer service... */
975 if (strwicmp(service->szService, PRINTERS_NAME) == 0) {
976 if (!service->printable) {
977 DEBUG(0, ("WARNING: [%s] service MUST be printable!\n",
978 service->szService));
979 service->printable = true;
981 /* [printers] service must also be non-browsable. */
982 if (service->browseable)
983 service->browseable = false;
986 if (service->path[0] == '\0' &&
987 strwicmp(service->szService, HOMES_NAME) != 0 &&
988 service->msdfs_proxy[0] == '\0')
990 DEBUG(0, ("WARNING: No path in service %s - making it unavailable!\n",
991 service->szService));
992 service->available = false;
995 if (!service->available)
996 DEBUG(1, ("NOTE: Service %s is flagged unavailable.\n",
997 service->szService));
1003 /*******************************************************************
1004 Keep a linked list of all config files so we know when one has changed
1005 it's date and needs to be reloaded.
1006 ********************************************************************/
1008 void add_to_file_list(TALLOC_CTX *mem_ctx, struct file_lists **list,
1009 const char *fname, const char *subfname)
1011 struct file_lists *f = *list;
1014 if (f->name && !strcmp(f->name, fname))
1020 f = talloc(mem_ctx, struct file_lists);
1024 f->name = talloc_strdup(f, fname);
1029 f->subfname = talloc_strdup(f, subfname);
1035 f->modtime = file_modtime(subfname);
1037 time_t t = file_modtime(subfname);
1044 DEBUG(0, ("Unable to add file to file list: %s\n", fname));
1049 * set the value for a P_ENUM
1051 bool lp_set_enum_parm( struct parm_struct *parm, const char *pszParmValue,
1056 for (i = 0; parm->enum_list[i].name; i++) {
1057 if (strwicmp(pszParmValue, parm->enum_list[i].name) == 0) {
1058 *ptr = parm->enum_list[i].value;
1062 DEBUG(0, ("WARNING: Ignoring invalid value '%s' for parameter '%s'\n",
1063 pszParmValue, parm->label));
1068 /***************************************************************************
1069 Handle the "realm" parameter
1070 ***************************************************************************/
1072 bool handle_realm(struct loadparm_context *lp_ctx, struct loadparm_service *service,
1073 const char *pszParmValue, char **ptr)
1078 upper = strupper_talloc(lp_ctx, pszParmValue);
1079 if (upper == NULL) {
1083 lower = strlower_talloc(lp_ctx, pszParmValue);
1084 if (lower == NULL) {
1089 lpcfg_string_set(lp_ctx->globals->ctx, &lp_ctx->globals->realm, upper);
1090 lpcfg_string_set(lp_ctx->globals->ctx, &lp_ctx->globals->dnsdomain, lower);
1095 /***************************************************************************
1096 Handle the include operation.
1097 ***************************************************************************/
1099 bool handle_include(struct loadparm_context *lp_ctx, struct loadparm_service *service,
1100 const char *pszParmValue, char **ptr)
1103 const char *substitution_variable_substring;
1106 if (lp_ctx->s3_fns) {
1107 return lp_ctx->s3_fns->lp_include(lp_ctx, service, pszParmValue, ptr);
1110 fname = standard_sub_basic(lp_ctx, pszParmValue);
1112 add_to_file_list(lp_ctx, &lp_ctx->file_lists, pszParmValue, fname);
1114 lpcfg_string_set(lp_ctx, ptr, fname);
1116 if (file_exist(fname))
1117 return pm_process(fname, do_section, lpcfg_do_parameter, lp_ctx);
1120 * If the file doesn't exist, we check that it isn't due to variable
1123 substitution_variable_substring = strchr(fname, '%');
1125 if (substitution_variable_substring != NULL) {
1126 next_char = substitution_variable_substring[1];
1127 if ((next_char >= 'a' && next_char <= 'z')
1128 || (next_char >= 'A' && next_char <= 'Z')) {
1129 DEBUG(2, ("Tried to load %s but variable substitution in "
1130 "filename, ignoring file.\n", fname));
1135 DEBUG(2, ("Can't find include file %s\n", fname));
1140 /***************************************************************************
1141 Handle the interpretation of the copy parameter.
1142 ***************************************************************************/
1144 bool handle_copy(struct loadparm_context *lp_ctx, struct loadparm_service *service,
1145 const char *pszParmValue, char **ptr)
1148 struct loadparm_service *serviceTemp = NULL;
1152 DEBUG(3, ("Copying service from service %s\n", pszParmValue));
1154 serviceTemp = lpcfg_getservicebyname(lp_ctx, pszParmValue);
1156 if (service == NULL) {
1157 DEBUG(0, ("Unable to copy service - invalid service destination.\n"));
1161 if (serviceTemp != NULL) {
1162 if (serviceTemp == service) {
1163 DEBUG(0, ("Can't copy service %s - unable to copy self!\n", pszParmValue));
1165 copy_service(service,
1168 lpcfg_string_set(service, ptr, pszParmValue);
1173 DEBUG(0, ("Unable to copy service - source not found: %s\n",
1181 bool handle_debug_list(struct loadparm_context *lp_ctx, struct loadparm_service *service,
1182 const char *pszParmValue, char **ptr)
1184 lpcfg_string_set(lp_ctx->globals->ctx, ptr, pszParmValue);
1186 return debug_parse_levels(pszParmValue);
1189 bool handle_logfile(struct loadparm_context *lp_ctx, struct loadparm_service *service,
1190 const char *pszParmValue, char **ptr)
1192 if (lp_ctx->s3_fns == NULL) {
1193 debug_set_logfile(pszParmValue);
1196 lpcfg_string_set(lp_ctx->globals->ctx, ptr, pszParmValue);
1202 * These special charset handling methods only run in the source3 code.
1205 bool handle_charset(struct loadparm_context *lp_ctx, struct loadparm_service *service,
1206 const char *pszParmValue, char **ptr)
1208 if (lp_ctx->s3_fns) {
1209 if (*ptr == NULL || strcmp(*ptr, pszParmValue) != 0) {
1210 struct smb_iconv_handle *ret = NULL;
1212 ret = reinit_iconv_handle(NULL,
1213 lpcfg_dos_charset(lp_ctx),
1214 lpcfg_unix_charset(lp_ctx));
1216 smb_panic("reinit_iconv_handle failed");
1221 return lpcfg_string_set(lp_ctx->globals->ctx, ptr, pszParmValue);
1225 bool handle_dos_charset(struct loadparm_context *lp_ctx, struct loadparm_service *service,
1226 const char *pszParmValue, char **ptr)
1228 bool is_utf8 = false;
1229 size_t len = strlen(pszParmValue);
1231 if (lp_ctx->s3_fns) {
1232 if (len == 4 || len == 5) {
1233 /* Don't use StrCaseCmp here as we don't want to
1234 initialize iconv. */
1235 if ((toupper_m(pszParmValue[0]) == 'U') &&
1236 (toupper_m(pszParmValue[1]) == 'T') &&
1237 (toupper_m(pszParmValue[2]) == 'F')) {
1239 if (pszParmValue[3] == '8') {
1243 if (pszParmValue[3] == '-' &&
1244 pszParmValue[4] == '8') {
1251 if (*ptr == NULL || strcmp(*ptr, pszParmValue) != 0) {
1252 struct smb_iconv_handle *ret = NULL;
1254 DEBUG(0,("ERROR: invalid DOS charset: 'dos charset' must not "
1255 "be UTF8, using (default value) %s instead.\n",
1256 DEFAULT_DOS_CHARSET));
1257 pszParmValue = DEFAULT_DOS_CHARSET;
1259 ret = reinit_iconv_handle(NULL,
1260 lpcfg_dos_charset(lp_ctx),
1261 lpcfg_unix_charset(lp_ctx));
1263 smb_panic("reinit_iconv_handle failed");
1268 return lpcfg_string_set(lp_ctx->globals->ctx, ptr, pszParmValue);
1271 bool handle_printing(struct loadparm_context *lp_ctx, struct loadparm_service *service,
1272 const char *pszParmValue, char **ptr)
1274 static int parm_num = -1;
1276 if (parm_num == -1) {
1277 parm_num = lpcfg_map_parameter("printing");
1280 if (!lp_set_enum_parm(&parm_table[parm_num], pszParmValue, (int*)ptr)) {
1284 if (lp_ctx->s3_fns) {
1285 if (service == NULL) {
1286 init_printer_values(lp_ctx, lp_ctx->globals->ctx, lp_ctx->sDefault);
1288 init_printer_values(lp_ctx, service, service);
1295 bool handle_ldap_debug_level(struct loadparm_context *lp_ctx, struct loadparm_service *service,
1296 const char *pszParmValue, char **ptr)
1298 lp_ctx->globals->ldap_debug_level = lp_int(pszParmValue);
1300 if (lp_ctx->s3_fns) {
1301 lp_ctx->s3_fns->init_ldap_debugging();
1307 * idmap related parameters
1310 bool handle_idmap_backend(struct loadparm_context *lp_ctx, struct loadparm_service *service,
1311 const char *pszParmValue, char **ptr)
1313 if (lp_ctx->s3_fns) {
1314 lp_do_parameter_parametric(lp_ctx, service, "idmap config * : backend",
1318 return lpcfg_string_set(lp_ctx->globals->ctx, ptr, pszParmValue);
1321 bool handle_idmap_uid(struct loadparm_context *lp_ctx, struct loadparm_service *service,
1322 const char *pszParmValue, char **ptr)
1324 if (lp_ctx->s3_fns) {
1325 lp_do_parameter_parametric(lp_ctx, service, "idmap config * : range",
1329 return lpcfg_string_set(lp_ctx->globals->ctx, ptr, pszParmValue);
1332 bool handle_idmap_gid(struct loadparm_context *lp_ctx, struct loadparm_service *service,
1333 const char *pszParmValue, char **ptr)
1335 if (lp_ctx->s3_fns) {
1336 lp_do_parameter_parametric(lp_ctx, service, "idmap config * : range",
1340 return lpcfg_string_set(lp_ctx->globals->ctx, ptr, pszParmValue);
1343 bool handle_smb_ports(struct loadparm_context *lp_ctx, struct loadparm_service *service,
1344 const char *pszParmValue, char **ptr)
1346 static int parm_num = -1;
1350 if (!pszParmValue || !*pszParmValue) {
1354 if (parm_num == -1) {
1355 parm_num = lpcfg_map_parameter("smb ports");
1356 if (parm_num == -1) {
1361 if (!set_variable_helper(lp_ctx->globals->ctx, parm_num, ptr, "smb ports",
1366 list = lp_ctx->globals->smb_ports;
1371 /* Check that each port is a valid integer and within range */
1372 for (i = 0; list[i] != NULL; i++) {
1375 port = strtol(list[i], &end, 10);
1376 if (*end != '\0' || port <= 0 || port > 65535) {
1385 bool handle_rpc_server_dynamic_port_range(struct loadparm_context *lp_ctx,
1386 struct loadparm_service *service,
1387 const char *pszParmValue,
1390 static int parm_num = -1;
1391 int low_port = -1, high_port = -1;
1394 if (parm_num == -1) {
1395 parm_num = lpcfg_map_parameter("rpc server dynamic port range");
1396 if (parm_num == -1) {
1401 if (pszParmValue == NULL || pszParmValue[0] == '\0') {
1405 rc = sscanf(pszParmValue, "%d - %d", &low_port, &high_port);
1410 if (low_port > high_port) {
1414 if (low_port < SERVER_TCP_PORT_MIN|| high_port > SERVER_TCP_PORT_MAX) {
1418 if (!set_variable_helper(lp_ctx->globals->ctx, parm_num, ptr,
1419 "rpc server dynamic port range",
1424 lp_ctx->globals->rpc_low_port = low_port;
1425 lp_ctx->globals->rpc_high_port = high_port;
1430 bool handle_smb2_max_credits(struct loadparm_context *lp_ctx,
1431 struct loadparm_service *service,
1432 const char *pszParmValue, char **ptr)
1434 int value = lp_int(pszParmValue);
1437 value = DEFAULT_SMB2_MAX_CREDITS;
1440 *(int *)ptr = value;
1445 bool handle_cups_encrypt(struct loadparm_context *lp_ctx,
1446 struct loadparm_service *service,
1447 const char *pszParmValue, char **ptr)
1450 #ifdef HAVE_HTTPCONNECTENCRYPT
1451 int value = lp_int(pszParmValue);
1455 result = HTTP_ENCRYPT_REQUIRED;
1458 result = HTTP_ENCRYPT_ALWAYS;
1461 result = HTTP_ENCRYPT_NEVER;
1468 *(int *)ptr = result;
1473 /***************************************************************************
1474 Initialise a copymap.
1475 ***************************************************************************/
1478 * Initializes service copymap
1479 * Note: pservice *must* be valid TALLOC_CTX
1481 void init_copymap(struct loadparm_service *pservice)
1485 TALLOC_FREE(pservice->copymap);
1487 pservice->copymap = bitmap_talloc(pservice, num_parameters());
1488 if (!pservice->copymap) {
1490 ("Couldn't allocate copymap!! (size %d)\n",
1491 (int)num_parameters()));
1493 for (i = 0; i < num_parameters(); i++) {
1494 bitmap_set(pservice->copymap, i);
1500 * Process a parametric option
1502 static bool lp_do_parameter_parametric(struct loadparm_context *lp_ctx,
1503 struct loadparm_service *service,
1504 const char *pszParmName,
1505 const char *pszParmValue, int flags)
1507 struct parmlist_entry **data;
1509 TALLOC_CTX *mem_ctx;
1511 while (isspace((unsigned char)*pszParmName)) {
1515 name = strlower_talloc(lp_ctx, pszParmName);
1516 if (!name) return false;
1518 if (service == NULL) {
1519 data = &lp_ctx->globals->param_opt;
1521 * s3 code cannot deal with parametric options stored on the globals ctx.
1523 if (lp_ctx->s3_fns != NULL) {
1526 mem_ctx = lp_ctx->globals->ctx;
1529 data = &service->param_opt;
1533 set_param_opt(mem_ctx, data, name, pszParmValue, flags);
1540 static bool set_variable_helper(TALLOC_CTX *mem_ctx, int parmnum, void *parm_ptr,
1541 const char *pszParmName, const char *pszParmValue)
1545 /* switch on the type of variable it is */
1546 switch (parm_table[parmnum].type)
1550 if (!set_boolean(pszParmValue, &b)) {
1551 DEBUG(0, ("set_variable_helper(%s): value is not "
1552 "boolean!\n", pszParmValue));
1555 *(bool *)parm_ptr = b;
1561 if (!set_boolean(pszParmValue, &b)) {
1562 DEBUG(0, ("set_variable_helper(%s): value is not "
1563 "boolean!\n", pszParmValue));
1566 *(bool *)parm_ptr = !b;
1571 *(int *)parm_ptr = lp_int(pszParmValue);
1575 *(char *)parm_ptr = *pszParmValue;
1579 i = sscanf(pszParmValue, "%o", (int *)parm_ptr);
1581 DEBUG ( 0, ("Invalid octal number %s\n", pszParmName ));
1589 if (conv_str_size_error(pszParmValue, &val)) {
1590 if (val <= INT_MAX) {
1591 *(int *)parm_ptr = (int)val;
1596 DEBUG(0, ("set_variable_helper(%s): value is not "
1597 "a valid size specifier!\n", pszParmValue));
1602 TALLOC_FREE(*(char ***)parm_ptr);
1603 *(char ***)parm_ptr = str_list_make_v3(mem_ctx,
1604 pszParmValue, NULL);
1609 char **new_list = str_list_make_v3(mem_ctx,
1610 pszParmValue, NULL);
1611 if (new_list == NULL) {
1615 for (i=0; new_list[i]; i++) {
1616 if (*(const char ***)parm_ptr != NULL &&
1617 new_list[i][0] == '+' &&
1620 if (!str_list_check(*(const char ***)parm_ptr,
1622 *(const char ***)parm_ptr = str_list_add(*(const char ***)parm_ptr,
1625 } else if (*(const char ***)parm_ptr != NULL &&
1626 new_list[i][0] == '-' &&
1629 str_list_remove(*(const char ***)parm_ptr,
1633 DEBUG(0, ("Unsupported list syntax for: %s = %s\n",
1634 pszParmName, pszParmValue));
1637 *(char ***)parm_ptr = new_list;
1645 lpcfg_string_set(mem_ctx, (char **)parm_ptr, pszParmValue);
1649 lpcfg_string_set_upper(mem_ctx, (char **)parm_ptr, pszParmValue);
1653 if (!lp_set_enum_parm(&parm_table[parmnum], pszParmValue, (int*)parm_ptr)) {
1664 bool handle_name_resolve_order(struct loadparm_context *lp_ctx,
1665 struct loadparm_service *service,
1666 const char *pszParmValue, char **ptr)
1668 const char **valid_values = NULL;
1669 const char **values_to_set = NULL;
1671 bool value_is_valid = false;
1672 valid_values = str_list_make_v3_const(NULL,
1673 DEFAULT_NAME_RESOLVE_ORDER,
1675 if (valid_values == NULL) {
1676 DBG_ERR("OOM: failed to make string list from %s\n",
1677 DEFAULT_NAME_RESOLVE_ORDER);
1680 values_to_set = str_list_make_v3_const(lp_ctx->globals->ctx,
1683 if (values_to_set == NULL) {
1684 DBG_ERR("OOM: failed to make string list from %s\n",
1688 TALLOC_FREE(lp_ctx->globals->name_resolve_order);
1689 for (i = 0; values_to_set[i] != NULL; i++) {
1690 value_is_valid = str_list_check(valid_values, values_to_set[i]);
1691 if (!value_is_valid) {
1692 DBG_ERR("WARNING: Ignoring invalid list value '%s' "
1693 "for parameter 'name resolve order'\n",
1699 if (value_is_valid) {
1700 lp_ctx->globals->name_resolve_order = values_to_set;
1702 TALLOC_FREE(values_to_set);
1704 TALLOC_FREE(valid_values);
1705 return value_is_valid;
1708 bool handle_kdc_default_domain_supported_enctypes(struct loadparm_context *lp_ctx,
1709 struct loadparm_service *service,
1710 const char *pszParmValue, char **ptr)
1712 char **enctype_list = NULL;
1713 char **enctype = NULL;
1714 uint32_t result = 0;
1717 enctype_list = str_list_make(NULL, pszParmValue, NULL);
1718 if (enctype_list == NULL) {
1719 DBG_ERR("OOM: failed to make string list from %s\n",
1725 for (enctype = enctype_list; *enctype != NULL; ++enctype) {
1726 if (strwicmp(*enctype, "arcfour-hmac-md5") == 0 ||
1727 strwicmp(*enctype, "rc4-hmac") == 0)
1729 result |= KERB_ENCTYPE_RC4_HMAC_MD5;
1731 else if (strwicmp(*enctype, "aes128-cts-hmac-sha1-96") == 0 ||
1732 strwicmp(*enctype, "aes128-cts") == 0)
1734 result |= KERB_ENCTYPE_AES128_CTS_HMAC_SHA1_96;
1736 else if (strwicmp(*enctype, "aes256-cts-hmac-sha1-96") == 0 ||
1737 strwicmp(*enctype, "aes256-cts") == 0)
1739 result |= KERB_ENCTYPE_AES256_CTS_HMAC_SHA1_96;
1741 else if (strwicmp(*enctype, "aes256-cts-hmac-sha1-96-sk") == 0 ||
1742 strwicmp(*enctype, "aes256-cts-sk") == 0)
1744 result |= KERB_ENCTYPE_AES256_CTS_HMAC_SHA1_96_SK;
1747 const char *bitstr = *enctype;
1752 /* See if the bit's specified in hexadecimal. */
1753 if (bitstr[0] == '0' &&
1754 (bitstr[1] == 'x' || bitstr[2] == 'X'))
1763 bit = smb_strtoul(bitstr, NULL, base, &error, SMB_STR_FULL_STR_CONV);
1765 DBG_ERR("WARNING: Ignoring invalid value '%s' "
1766 "for parameter 'kdc default domain supported enctypes'\n",
1775 *(int *)ptr = result;
1777 TALLOC_FREE(enctype_list);
1782 static bool set_variable(TALLOC_CTX *mem_ctx, struct loadparm_service *service,
1783 int parmnum, void *parm_ptr,
1784 const char *pszParmName, const char *pszParmValue,
1785 struct loadparm_context *lp_ctx, bool on_globals)
1790 /* if it is a special case then go ahead */
1791 if (parm_table[parmnum].special) {
1792 ok = parm_table[parmnum].special(lp_ctx, service, pszParmValue,
1795 ok = set_variable_helper(mem_ctx, parmnum, parm_ptr,
1796 pszParmName, pszParmValue);
1803 if (on_globals && (lp_ctx->flags[parmnum] & FLAG_DEFAULT)) {
1804 lp_ctx->flags[parmnum] &= ~FLAG_DEFAULT;
1805 /* we have to also unset FLAG_DEFAULT on aliases */
1806 for (i=parmnum-1;i>=0 && parm_table[i].offset == parm_table[parmnum].offset;i--) {
1807 lp_ctx->flags[i] &= ~FLAG_DEFAULT;
1809 for (i=parmnum+1;i<num_parameters() && parm_table[i].offset == parm_table[parmnum].offset;i++) {
1810 lp_ctx->flags[i] &= ~FLAG_DEFAULT;
1817 bool lpcfg_do_global_parameter(struct loadparm_context *lp_ctx,
1818 const char *pszParmName, const char *pszParmValue)
1820 int parmnum = lpcfg_map_parameter(pszParmName);
1824 if (strchr(pszParmName, ':')) {
1825 return lp_do_parameter_parametric(lp_ctx, NULL, pszParmName, pszParmValue, 0);
1827 DEBUG(0, ("Ignoring unknown parameter \"%s\"\n", pszParmName));
1831 /* if the flag has been set on the command line, then don't allow override,
1832 but don't report an error */
1833 if (lp_ctx->flags[parmnum] & FLAG_CMDLINE) {
1837 if (parm_table[parmnum].flags & FLAG_DEPRECATED) {
1838 char *suppress_env = getenv("SAMBA_DEPRECATED_SUPPRESS");
1839 bool print_warning = (suppress_env == NULL
1840 || suppress_env[0] == '\0');
1841 if (print_warning) {
1842 DBG_WARNING("WARNING: The \"%s\" option "
1849 parm_ptr = lpcfg_parm_ptr(lp_ctx, NULL, &parm_table[parmnum]);
1851 return set_variable(lp_ctx->globals->ctx, NULL, parmnum, parm_ptr,
1852 pszParmName, pszParmValue, lp_ctx, true);
1855 bool lpcfg_do_service_parameter(struct loadparm_context *lp_ctx,
1856 struct loadparm_service *service,
1857 const char *pszParmName, const char *pszParmValue)
1861 int parmnum = lpcfg_map_parameter(pszParmName);
1864 if (strchr(pszParmName, ':')) {
1865 return lp_do_parameter_parametric(lp_ctx, service, pszParmName, pszParmValue, 0);
1867 DEBUG(0, ("Ignoring unknown parameter \"%s\"\n", pszParmName));
1871 /* if the flag has been set on the command line, then don't allow override,
1872 but don't report an error */
1873 if (lp_ctx->flags[parmnum] & FLAG_CMDLINE) {
1877 if (parm_table[parmnum].flags & FLAG_DEPRECATED) {
1878 char *suppress_env = getenv("SAMBA_DEPRECATED_SUPPRESS");
1879 bool print_warning = (suppress_env == NULL
1880 || suppress_env[0] == '\0');
1881 if (print_warning) {
1882 DBG_WARNING("WARNING: The \"%s\" option "
1889 if (parm_table[parmnum].p_class == P_GLOBAL) {
1891 ("Global parameter %s found in service section!\n",
1895 parm_ptr = ((char *)service) + parm_table[parmnum].offset;
1897 if (!service->copymap)
1898 init_copymap(service);
1900 /* this handles the aliases - set the copymap for other
1901 * entries with the same data pointer */
1902 for (i = 0; parm_table[i].label; i++)
1903 if (parm_table[i].offset == parm_table[parmnum].offset &&
1904 parm_table[i].p_class == parm_table[parmnum].p_class)
1905 bitmap_clear(service->copymap, i);
1907 return set_variable(service, service, parmnum, parm_ptr, pszParmName,
1908 pszParmValue, lp_ctx, false);
1912 * Process a parameter.
1915 bool lpcfg_do_parameter(const char *pszParmName, const char *pszParmValue,
1918 struct loadparm_context *lp_ctx = (struct loadparm_context *)userdata;
1920 if (lp_ctx->bInGlobalSection)
1921 return lpcfg_do_global_parameter(lp_ctx, pszParmName,
1924 return lpcfg_do_service_parameter(lp_ctx, lp_ctx->currentService,
1925 pszParmName, pszParmValue);
1929 variable argument do parameter
1931 bool lpcfg_do_global_parameter_var(struct loadparm_context *lp_ctx, const char *pszParmName, const char *fmt, ...) PRINTF_ATTRIBUTE(3, 4);
1932 bool lpcfg_do_global_parameter_var(struct loadparm_context *lp_ctx,
1933 const char *pszParmName, const char *fmt, ...)
1940 s = talloc_vasprintf(NULL, fmt, ap);
1942 ret = lpcfg_do_global_parameter(lp_ctx, pszParmName, s);
1949 set a parameter from the commandline - this is called from command line parameter
1950 parsing code. It sets the parameter then marks the parameter as unable to be modified
1951 by smb.conf processing
1953 bool lpcfg_set_cmdline(struct loadparm_context *lp_ctx, const char *pszParmName,
1954 const char *pszParmValue)
1959 while (isspace((unsigned char)*pszParmValue)) pszParmValue++;
1961 parmnum = lpcfg_map_parameter(pszParmName);
1963 if (parmnum < 0 && strchr(pszParmName, ':')) {
1964 /* set a parametric option */
1966 ok = lp_do_parameter_parametric(lp_ctx, NULL, pszParmName,
1967 pszParmValue, FLAG_CMDLINE);
1968 if (lp_ctx->s3_fns != NULL) {
1970 lp_ctx->s3_fns->store_cmdline(pszParmName, pszParmValue);
1977 DEBUG(0,("Unknown option '%s'\n", pszParmName));
1981 /* reset the CMDLINE flag in case this has been called before */
1982 lp_ctx->flags[parmnum] &= ~FLAG_CMDLINE;
1984 if (!lpcfg_do_global_parameter(lp_ctx, pszParmName, pszParmValue)) {
1988 lp_ctx->flags[parmnum] |= FLAG_CMDLINE;
1990 /* we have to also set FLAG_CMDLINE on aliases */
1992 i>=0 && parm_table[i].p_class == parm_table[parmnum].p_class &&
1993 parm_table[i].offset == parm_table[parmnum].offset;
1995 lp_ctx->flags[i] |= FLAG_CMDLINE;
1998 i<num_parameters() &&
1999 parm_table[i].p_class == parm_table[parmnum].p_class &&
2000 parm_table[i].offset == parm_table[parmnum].offset;
2002 lp_ctx->flags[i] |= FLAG_CMDLINE;
2005 if (lp_ctx->s3_fns != NULL) {
2006 lp_ctx->s3_fns->store_cmdline(pszParmName, pszParmValue);
2013 set a option from the commandline in 'a=b' format. Use to support --option
2015 bool lpcfg_set_option(struct loadparm_context *lp_ctx, const char *option)
2020 s = talloc_strdup(NULL, option);
2033 ret = lpcfg_set_cmdline(lp_ctx, s, p+1);
2039 #define BOOLSTR(b) ((b) ? "Yes" : "No")
2042 * Print a parameter of the specified type.
2045 void lpcfg_print_parameter(struct parm_struct *p, void *ptr, FILE * f)
2047 /* For the seperation of lists values that we print below */
2048 const char *list_sep = ", ";
2053 for (i = 0; p->enum_list[i].name; i++) {
2054 if (*(int *)ptr == p->enum_list[i].value) {
2056 p->enum_list[i].name);
2063 fprintf(f, "%s", BOOLSTR(*(bool *)ptr));
2067 fprintf(f, "%s", BOOLSTR(!*(bool *)ptr));
2072 fprintf(f, "%d", *(int *)ptr);
2076 fprintf(f, "%c", *(char *)ptr);
2080 int val = *(int *)ptr;
2084 fprintf(f, "0%03o", val);
2094 if ((char ***)ptr && *(char ***)ptr) {
2095 char **list = *(char ***)ptr;
2096 for (; *list; list++) {
2097 /* surround strings with whitespace in double quotes */
2098 if (*(list+1) == NULL) {
2099 /* last item, no extra separator */
2102 if ( strchr_m( *list, ' ' ) ) {
2103 fprintf(f, "\"%s\"%s", *list, list_sep);
2105 fprintf(f, "%s%s", *list, list_sep);
2113 if (*(char **)ptr) {
2114 fprintf(f, "%s", *(char **)ptr);
2121 * Check if two parameters are equal.
2124 static bool lpcfg_equal_parameter(parm_type type, void *ptr1, void *ptr2)
2129 return (*((bool *)ptr1) == *((bool *)ptr2));
2135 return (*((int *)ptr1) == *((int *)ptr2));
2138 return (*((char *)ptr1) == *((char *)ptr2));
2142 return str_list_equal(*(const char ***)ptr1, *(const char ***)ptr2);
2147 char *p1 = *(char **)ptr1, *p2 = *(char **)ptr2;
2152 return (p1 == p2 || strequal(p1, p2));
2159 * Process a new section (service).
2161 * At this stage all sections are services.
2162 * Later we'll have special sections that permit server parameters to be set.
2163 * Returns True on success, False on failure.
2166 static bool do_section(const char *pszSectionName, void *userdata)
2168 struct loadparm_context *lp_ctx = (struct loadparm_context *)userdata;
2172 if (lp_ctx->s3_fns != NULL) {
2173 return lp_ctx->s3_fns->do_section(pszSectionName, lp_ctx);
2176 isglobal = ((strwicmp(pszSectionName, GLOBAL_NAME) == 0) ||
2177 (strwicmp(pszSectionName, GLOBAL_NAME2) == 0));
2179 /* if we've just struck a global section, note the fact. */
2180 lp_ctx->bInGlobalSection = isglobal;
2182 /* check for multiple global sections */
2183 if (lp_ctx->bInGlobalSection) {
2184 DEBUG(4, ("Processing section \"[%s]\"\n", pszSectionName));
2189 /* if we have a current service, tidy it up before moving on */
2192 if (lp_ctx->currentService != NULL)
2193 bRetval = lpcfg_service_ok(lp_ctx->currentService);
2195 /* if all is still well, move to the next record in the services array */
2197 /* We put this here to avoid an odd message order if messages are */
2198 /* issued by the post-processing of a previous section. */
2199 DEBUG(4, ("Processing section \"[%s]\"\n", pszSectionName));
2201 if ((lp_ctx->currentService = lpcfg_add_service(lp_ctx, lp_ctx->sDefault,
2204 DEBUG(0, ("Failed to add a new service\n"));
2215 * Determine if a particular base parameter is currently set to the default value.
2218 static bool is_default(void *base_structure, int i)
2220 void *def_ptr = ((char *)base_structure) + parm_table[i].offset;
2221 switch (parm_table[i].type) {
2224 return str_list_equal((const char * const *)parm_table[i].def.lvalue,
2225 *(const char * const **)def_ptr);
2228 return strequal(parm_table[i].def.svalue,
2232 return parm_table[i].def.bvalue ==
2239 return parm_table[i].def.ivalue ==
2246 *Display the contents of the global structure.
2249 void lpcfg_dump_globals(struct loadparm_context *lp_ctx, FILE *f,
2253 struct parmlist_entry *data;
2255 fprintf(f, "# Global parameters\n[global]\n");
2257 for (i = 0; parm_table[i].label; i++) {
2258 if (parm_table[i].p_class != P_GLOBAL) {
2262 if (parm_table[i].flags & FLAG_SYNONYM) {
2266 if (!show_defaults) {
2267 if (lp_ctx->flags && (lp_ctx->flags[i] & FLAG_DEFAULT)) {
2271 if (is_default(lp_ctx->globals, i)) {
2276 fprintf(f, "\t%s = ", parm_table[i].label);
2277 lpcfg_print_parameter(&parm_table[i], lpcfg_parm_ptr(lp_ctx, NULL, &parm_table[i]), f);
2280 if (lp_ctx->globals->param_opt != NULL) {
2281 for (data = lp_ctx->globals->param_opt; data;
2282 data = data->next) {
2283 if (!show_defaults && (data->priority & FLAG_DEFAULT)) {
2286 fprintf(f, "\t%s = %s\n", data->key, data->value);
2293 * Display the contents of a single services record.
2296 void lpcfg_dump_a_service(struct loadparm_service * pService, struct loadparm_service *sDefault, FILE * f,
2297 unsigned int *flags, bool show_defaults)
2300 struct parmlist_entry *data;
2302 if (pService != sDefault)
2303 fprintf(f, "\n[%s]\n", pService->szService);
2305 for (i = 0; parm_table[i].label; i++) {
2306 if (parm_table[i].p_class != P_LOCAL) {
2310 if (parm_table[i].flags & FLAG_SYNONYM) {
2314 if (*parm_table[i].label == '-') {
2318 if (pService == sDefault) {
2319 if (!show_defaults) {
2320 if (flags && (flags[i] & FLAG_DEFAULT)) {
2324 if (is_default(sDefault, i)) {
2331 equal = lpcfg_equal_parameter(parm_table[i].type,
2332 ((char *)pService) +
2333 parm_table[i].offset,
2334 ((char *)sDefault) +
2335 parm_table[i].offset);
2341 fprintf(f, "\t%s = ", parm_table[i].label);
2342 lpcfg_print_parameter(&parm_table[i],
2343 ((char *)pService) + parm_table[i].offset, f);
2346 if (pService->param_opt != NULL) {
2347 for (data = pService->param_opt; data; data = data->next) {
2348 if (!show_defaults && (data->priority & FLAG_DEFAULT)) {
2351 fprintf(f, "\t%s = %s\n", data->key, data->value);
2356 bool lpcfg_dump_a_parameter(struct loadparm_context *lp_ctx,
2357 struct loadparm_service *service,
2358 const char *parm_name, FILE * f)
2360 struct parm_struct *parm;
2362 char *local_parm_name;
2364 const char *parm_opt_value;
2366 /* check for parametrical option */
2367 local_parm_name = talloc_strdup(lp_ctx, parm_name);
2368 if (local_parm_name == NULL) {
2372 parm_opt = strchr( local_parm_name, ':');
2377 if (strlen(parm_opt)) {
2378 parm_opt_value = lpcfg_parm_string(lp_ctx, service,
2379 local_parm_name, parm_opt);
2380 if (parm_opt_value) {
2381 fprintf(f, "%s\n", parm_opt_value);
2382 TALLOC_FREE(local_parm_name);
2386 TALLOC_FREE(local_parm_name);
2389 TALLOC_FREE(local_parm_name);
2391 /* parameter is not parametric, search the table */
2392 parm = lpcfg_parm_struct(lp_ctx, parm_name);
2397 if (service != NULL && parm->p_class == P_GLOBAL) {
2401 ptr = lpcfg_parm_ptr(lp_ctx, service,parm);
2403 lpcfg_print_parameter(parm, ptr, f);
2409 * Auto-load some home services.
2411 static void lpcfg_add_auto_services(struct loadparm_context *lp_ctx,
2417 /***************************************************************************
2418 Initialise the sDefault parameter structure for the printer values.
2419 ***************************************************************************/
2421 void init_printer_values(struct loadparm_context *lp_ctx, TALLOC_CTX *ctx,
2422 struct loadparm_service *pService)
2424 /* choose defaults depending on the type of printing */
2425 switch (pService->printing) {
2430 lpcfg_string_set(ctx, &pService->lpq_command, "lpq -P'%p'");
2431 lpcfg_string_set(ctx, &pService->lprm_command, "lprm -P'%p' %j");
2432 lpcfg_string_set(ctx, &pService->print_command, "lpr -r -P'%p' %s");
2437 lpcfg_string_set(ctx, &pService->lpq_command, "lpq -P'%p'");
2438 lpcfg_string_set(ctx, &pService->lprm_command, "lprm -P'%p' %j");
2439 lpcfg_string_set(ctx, &pService->print_command, "lpr -r -P'%p' %s");
2440 lpcfg_string_set(ctx, &pService->queuepause_command, "lpc stop '%p'");
2441 lpcfg_string_set(ctx, &pService->queueresume_command, "lpc start '%p'");
2442 lpcfg_string_set(ctx, &pService->lppause_command, "lpc hold '%p' %j");
2443 lpcfg_string_set(ctx, &pService->lpresume_command, "lpc release '%p' %j");
2448 /* set the lpq command to contain the destination printer
2449 name only. This is used by cups_queue_get() */
2450 lpcfg_string_set(ctx, &pService->lpq_command, "%p");
2451 lpcfg_string_set(ctx, &pService->lprm_command, "");
2452 lpcfg_string_set(ctx, &pService->print_command, "");
2453 lpcfg_string_set(ctx, &pService->lppause_command, "");
2454 lpcfg_string_set(ctx, &pService->lpresume_command, "");
2455 lpcfg_string_set(ctx, &pService->queuepause_command, "");
2456 lpcfg_string_set(ctx, &pService->queueresume_command, "");
2461 lpcfg_string_set(ctx, &pService->lpq_command, "lpstat -o%p");
2462 lpcfg_string_set(ctx, &pService->lprm_command, "cancel %p-%j");
2463 lpcfg_string_set(ctx, &pService->print_command, "lp -c -d%p %s; rm %s");
2464 lpcfg_string_set(ctx, &pService->queuepause_command, "disable %p");
2465 lpcfg_string_set(ctx, &pService->queueresume_command, "enable %p");
2467 lpcfg_string_set(ctx, &pService->lppause_command, "lp -i %p-%j -H hold");
2468 lpcfg_string_set(ctx, &pService->lpresume_command, "lp -i %p-%j -H resume");
2473 lpcfg_string_set(ctx, &pService->lpq_command, "lpq -P%p");
2474 lpcfg_string_set(ctx, &pService->lprm_command, "lprm -P%p %j");
2475 lpcfg_string_set(ctx, &pService->print_command, "lp -r -P%p %s");
2478 #if defined(DEVELOPER) || defined(ENABLE_SELFTEST)
2482 const char *tdbfile;
2483 TALLOC_CTX *tmp_ctx = talloc_new(ctx);
2486 tmp = lpcfg_parm_string(lp_ctx, NULL, "vlp", "tdbfile");
2488 tmp = "/tmp/vlp.tdb";
2491 tdbfile = talloc_asprintf(tmp_ctx, "tdbfile=%s", tmp);
2492 if (tdbfile == NULL) {
2493 tdbfile="tdbfile=/tmp/vlp.tdb";
2496 tmp = talloc_asprintf(tmp_ctx, "vlp %s print %%p %%s",
2498 lpcfg_string_set(ctx, &pService->print_command,
2499 tmp ? tmp : "vlp print %p %s");
2501 tmp = talloc_asprintf(tmp_ctx, "vlp %s lpq %%p",
2503 lpcfg_string_set(ctx, &pService->lpq_command,
2504 tmp ? tmp : "vlp lpq %p");
2506 tmp = talloc_asprintf(tmp_ctx, "vlp %s lprm %%p %%j",
2508 lpcfg_string_set(ctx, &pService->lprm_command,
2509 tmp ? tmp : "vlp lprm %p %j");
2511 tmp = talloc_asprintf(tmp_ctx, "vlp %s lppause %%p %%j",
2513 lpcfg_string_set(ctx, &pService->lppause_command,
2514 tmp ? tmp : "vlp lppause %p %j");
2516 tmp = talloc_asprintf(tmp_ctx, "vlp %s lpresume %%p %%j",
2518 lpcfg_string_set(ctx, &pService->lpresume_command,
2519 tmp ? tmp : "vlp lpresume %p %j");
2521 tmp = talloc_asprintf(tmp_ctx, "vlp %s queuepause %%p",
2523 lpcfg_string_set(ctx, &pService->queuepause_command,
2524 tmp ? tmp : "vlp queuepause %p");
2526 tmp = talloc_asprintf(tmp_ctx, "vlp %s queueresume %%p",
2528 lpcfg_string_set(ctx, &pService->queueresume_command,
2529 tmp ? tmp : "vlp queueresume %p");
2530 TALLOC_FREE(tmp_ctx);
2534 #endif /* DEVELOPER */
2540 static int lpcfg_destructor(struct loadparm_context *lp_ctx)
2542 struct parmlist_entry *data;
2544 if (lp_ctx->refuse_free) {
2545 /* someone is trying to free the
2546 global_loadparm_context.
2547 We can't allow that. */
2551 if (lp_ctx->globals->param_opt != NULL) {
2552 struct parmlist_entry *next;
2553 for (data = lp_ctx->globals->param_opt; data; data=next) {
2555 if (data->priority & FLAG_CMDLINE) continue;
2556 DLIST_REMOVE(lp_ctx->globals->param_opt, data);
2565 * Initialise the global parameter structure.
2567 * Note that most callers should use loadparm_init_global() instead
2569 struct loadparm_context *loadparm_init(TALLOC_CTX *mem_ctx)
2573 struct loadparm_context *lp_ctx;
2574 struct parmlist_entry *parm;
2577 lp_ctx = talloc_zero(mem_ctx, struct loadparm_context);
2581 talloc_set_destructor(lp_ctx, lpcfg_destructor);
2582 lp_ctx->bInGlobalSection = true;
2583 lp_ctx->globals = talloc_zero(lp_ctx, struct loadparm_global);
2584 /* This appears odd, but globals in s3 isn't a pointer */
2585 lp_ctx->globals->ctx = lp_ctx->globals;
2586 lp_ctx->globals->rpc_low_port = SERVER_TCP_LOW_PORT;
2587 lp_ctx->globals->rpc_high_port = SERVER_TCP_HIGH_PORT;
2588 lp_ctx->globals->weak_crypto = SAMBA_WEAK_CRYPTO_UNKNOWN;
2589 lp_ctx->sDefault = talloc_zero(lp_ctx, struct loadparm_service);
2590 lp_ctx->flags = talloc_zero_array(lp_ctx, unsigned int, num_parameters());
2592 lp_ctx->sDefault->max_print_jobs = 1000;
2593 lp_ctx->sDefault->available = true;
2594 lp_ctx->sDefault->browseable = true;
2595 lp_ctx->sDefault->read_only = true;
2596 lp_ctx->sDefault->map_archive = true;
2597 lp_ctx->sDefault->strict_locking = true;
2598 lp_ctx->sDefault->oplocks = true;
2599 lp_ctx->sDefault->create_mask = 0744;
2600 lp_ctx->sDefault->force_create_mode = 0000;
2601 lp_ctx->sDefault->directory_mask = 0755;
2602 lp_ctx->sDefault->force_directory_mode = 0000;
2603 lp_ctx->sDefault->aio_read_size = 1;
2604 lp_ctx->sDefault->aio_write_size = 1;
2605 lp_ctx->sDefault->smbd_search_ask_sharemode = true;
2606 lp_ctx->sDefault->smbd_getinfo_ask_sharemode = true;
2607 lp_ctx->sDefault->volume_serial_number = -1;
2609 DEBUG(3, ("Initialising global parameters\n"));
2611 for (i = 0; parm_table[i].label; i++) {
2612 if ((parm_table[i].type == P_STRING ||
2613 parm_table[i].type == P_USTRING) &&
2614 !(lp_ctx->flags[i] & FLAG_CMDLINE)) {
2615 TALLOC_CTX *parent_mem;
2617 if (parm_table[i].p_class == P_LOCAL) {
2618 parent_mem = lp_ctx->sDefault;
2619 r = (char **)(((char *)lp_ctx->sDefault) + parm_table[i].offset);
2621 parent_mem = lp_ctx->globals;
2622 r = (char **)(((char *)lp_ctx->globals) + parm_table[i].offset);
2624 lpcfg_string_set(parent_mem, r, "");
2628 logfile = talloc_asprintf(lp_ctx, "%s/log.samba", dyn_LOGFILEBASE);
2629 lpcfg_do_global_parameter(lp_ctx, "log file", logfile);
2630 talloc_free(logfile);
2632 lpcfg_do_global_parameter(lp_ctx, "log level", "0");
2634 lpcfg_do_global_parameter(lp_ctx, "syslog", "1");
2635 lpcfg_do_global_parameter(lp_ctx, "syslog only", "No");
2636 lpcfg_do_global_parameter(lp_ctx, "debug timestamp", "Yes");
2637 lpcfg_do_global_parameter(lp_ctx, "debug prefix timestamp", "No");
2638 lpcfg_do_global_parameter(lp_ctx, "debug hires timestamp", "Yes");
2639 lpcfg_do_global_parameter(lp_ctx, "debug syslog format", "No");
2640 lpcfg_do_global_parameter(lp_ctx, "debug pid", "No");
2641 lpcfg_do_global_parameter(lp_ctx, "debug uid", "No");
2642 lpcfg_do_global_parameter(lp_ctx, "debug class", "No");
2644 lpcfg_do_global_parameter(lp_ctx, "server role", "auto");
2645 lpcfg_do_global_parameter(lp_ctx, "domain logons", "No");
2646 lpcfg_do_global_parameter(lp_ctx, "domain master", "Auto");
2648 /* options that can be set on the command line must be initialised via
2649 the slower lpcfg_do_global_parameter() to ensure that FLAG_CMDLINE is obeyed */
2651 lpcfg_do_global_parameter(lp_ctx, "socket options", "TCP_NODELAY");
2653 lpcfg_do_global_parameter(lp_ctx, "workgroup", DEFAULT_WORKGROUP);
2654 myname = get_myname(lp_ctx);
2655 lpcfg_do_global_parameter(lp_ctx, "netbios name", myname);
2656 talloc_free(myname);
2657 lpcfg_do_global_parameter(lp_ctx,
2658 "name resolve order",
2659 DEFAULT_NAME_RESOLVE_ORDER);
2661 lpcfg_do_global_parameter(lp_ctx, "fstype", "NTFS");
2663 lpcfg_do_global_parameter(lp_ctx, "ntvfs handler", "unixuid default");
2664 lpcfg_do_global_parameter(lp_ctx, "max connections", "0");
2666 lpcfg_do_global_parameter(lp_ctx, "dcerpc endpoint servers", "epmapper wkssvc rpcecho samr netlogon lsarpc drsuapi dssetup unixinfo browser eventlog6 backupkey dnsserver");
2667 lpcfg_do_global_parameter(lp_ctx, "server services", "s3fs rpc nbt wrepl ldap cldap kdc drepl winbindd ntp_signd kcc dnsupdate dns");
2668 lpcfg_do_global_parameter(lp_ctx, "kccsrv:samba_kcc", "true");
2669 /* the winbind method for domain controllers is for both RODC
2670 auth forwarding and for trusted domains */
2671 lpcfg_do_global_parameter(lp_ctx, "private dir", dyn_PRIVATE_DIR);
2672 lpcfg_do_global_parameter(lp_ctx, "binddns dir", dyn_BINDDNS_DIR);
2673 lpcfg_do_global_parameter(lp_ctx, "registry:HKEY_LOCAL_MACHINE", "hklm.ldb");
2675 /* This hive should be dynamically generated by Samba using
2676 data from the sam, but for the moment leave it in a tdb to
2677 keep regedt32 from popping up an annoying dialog. */
2678 lpcfg_do_global_parameter(lp_ctx, "registry:HKEY_USERS", "hku.ldb");
2680 /* using UTF8 by default allows us to support all chars */
2681 lpcfg_do_global_parameter(lp_ctx, "unix charset", "UTF-8");
2683 /* Use codepage 850 as a default for the dos character set */
2684 lpcfg_do_global_parameter(lp_ctx, "dos charset", "CP850");
2687 * Allow the default PASSWD_CHAT to be overridden in local.h.
2689 lpcfg_do_global_parameter(lp_ctx, "passwd chat", DEFAULT_PASSWD_CHAT);
2691 lpcfg_do_global_parameter(lp_ctx, "pid directory", dyn_PIDDIR);
2692 lpcfg_do_global_parameter(lp_ctx, "lock dir", dyn_LOCKDIR);
2693 lpcfg_do_global_parameter(lp_ctx, "state directory", dyn_STATEDIR);
2694 lpcfg_do_global_parameter(lp_ctx, "cache directory", dyn_CACHEDIR);
2695 lpcfg_do_global_parameter(lp_ctx, "ncalrpc dir", dyn_NCALRPCDIR);
2697 lpcfg_do_global_parameter(lp_ctx, "nbt client socket address", "0.0.0.0");
2698 lpcfg_do_global_parameter_var(lp_ctx, "server string",
2699 "Samba %s", SAMBA_VERSION_STRING);
2701 lpcfg_do_global_parameter(lp_ctx, "password server", "*");
2703 lpcfg_do_global_parameter(lp_ctx, "max mux", "50");
2704 lpcfg_do_global_parameter(lp_ctx, "max xmit", "16644");
2705 lpcfg_do_global_parameter(lp_ctx, "host msdfs", "true");
2707 lpcfg_do_global_parameter(lp_ctx, "LargeReadwrite", "True");
2708 lpcfg_do_global_parameter(lp_ctx, "server min protocol", "SMB2_02");
2709 lpcfg_do_global_parameter(lp_ctx, "server max protocol", "SMB3");
2710 lpcfg_do_global_parameter(lp_ctx, "client min protocol", "SMB2_02");
2711 lpcfg_do_global_parameter(lp_ctx, "client max protocol", "default");
2712 lpcfg_do_global_parameter(lp_ctx, "client ipc min protocol", "default");
2713 lpcfg_do_global_parameter(lp_ctx, "client ipc max protocol", "default");
2714 lpcfg_do_global_parameter(lp_ctx, "security", "AUTO");
2715 lpcfg_do_global_parameter(lp_ctx, "EncryptPasswords", "True");
2716 lpcfg_do_global_parameter(lp_ctx, "ReadRaw", "True");
2717 lpcfg_do_global_parameter(lp_ctx, "WriteRaw", "True");
2718 lpcfg_do_global_parameter(lp_ctx, "NullPasswords", "False");
2719 lpcfg_do_global_parameter(lp_ctx, "old password allowed period", "60");
2720 lpcfg_do_global_parameter(lp_ctx, "ObeyPamRestrictions", "False");
2722 lpcfg_do_global_parameter(lp_ctx, "TimeServer", "False");
2723 lpcfg_do_global_parameter(lp_ctx, "BindInterfacesOnly", "False");
2724 lpcfg_do_global_parameter(lp_ctx, "Unicode", "True");
2725 lpcfg_do_global_parameter(lp_ctx, "ClientLanManAuth", "False");
2726 lpcfg_do_global_parameter(lp_ctx, "ClientNTLMv2Auth", "True");
2727 lpcfg_do_global_parameter(lp_ctx, "LanmanAuth", "False");
2728 lpcfg_do_global_parameter(lp_ctx, "NTLMAuth", "ntlmv2-only");
2729 lpcfg_do_global_parameter(lp_ctx, "NT hash store", "always");
2730 lpcfg_do_global_parameter(lp_ctx, "RawNTLMv2Auth", "False");
2731 lpcfg_do_global_parameter(lp_ctx, "client use spnego principal", "False");
2733 lpcfg_do_global_parameter(lp_ctx, "allow dcerpc auth level connect", "False");
2735 lpcfg_do_global_parameter(lp_ctx, "UnixExtensions", "True");
2737 lpcfg_do_global_parameter(lp_ctx, "PreferredMaster", "Auto");
2738 lpcfg_do_global_parameter(lp_ctx, "LocalMaster", "True");
2740 lpcfg_do_global_parameter(lp_ctx, "wins support", "False");
2741 lpcfg_do_global_parameter(lp_ctx, "dns proxy", "True");
2743 lpcfg_do_global_parameter(lp_ctx, "winbind separator", "\\");
2744 lpcfg_do_global_parameter(lp_ctx, "winbind sealed pipes", "True");
2745 lpcfg_do_global_parameter(lp_ctx, "winbind scan trusted domains", "False");
2746 lpcfg_do_global_parameter(lp_ctx, "require strong key", "True");
2747 lpcfg_do_global_parameter(lp_ctx, "reject md5 servers", "True");
2748 lpcfg_do_global_parameter(lp_ctx, "winbindd socket directory", dyn_WINBINDD_SOCKET_DIR);
2749 lpcfg_do_global_parameter(lp_ctx, "ntp signd socket directory", dyn_NTP_SIGND_SOCKET_DIR);
2750 lpcfg_do_global_parameter_var(lp_ctx, "gpo update command", "%s/samba-gpupdate", dyn_SCRIPTSBINDIR);
2751 lpcfg_do_global_parameter_var(lp_ctx, "apply group policies", "False");
2752 lpcfg_do_global_parameter_var(lp_ctx, "dns update command", "%s/samba_dnsupdate", dyn_SCRIPTSBINDIR);
2753 lpcfg_do_global_parameter_var(lp_ctx, "spn update command", "%s/samba_spnupdate", dyn_SCRIPTSBINDIR);
2754 lpcfg_do_global_parameter_var(lp_ctx, "samba kcc command",
2755 "%s/samba_kcc", dyn_SCRIPTSBINDIR);
2757 lpcfg_do_global_parameter_var(lp_ctx,
2761 lpcfg_do_global_parameter(lp_ctx, "template shell", "/bin/false");
2762 lpcfg_do_global_parameter(lp_ctx, "template homedir", "/home/%D/%U");
2764 lpcfg_do_global_parameter(lp_ctx, "client signing", "default");
2765 lpcfg_do_global_parameter(lp_ctx, "client ipc signing", "default");
2766 lpcfg_do_global_parameter(lp_ctx, "server signing", "default");
2768 lpcfg_do_global_parameter(lp_ctx, "use mmap", "True");
2770 lpcfg_do_global_parameter(lp_ctx, "smb ports", "445 139");
2771 lpcfg_do_global_parameter_var(lp_ctx, "nbt port", "%d", NBT_NAME_SERVICE_PORT);
2772 lpcfg_do_global_parameter_var(lp_ctx, "dgram port", "%d", NBT_DGRAM_SERVICE_PORT);
2773 lpcfg_do_global_parameter(lp_ctx, "cldap port", "389");
2774 lpcfg_do_global_parameter(lp_ctx, "krb5 port", "88");
2775 lpcfg_do_global_parameter(lp_ctx, "kpasswd port", "464");
2776 lpcfg_do_global_parameter_var(lp_ctx, "dns port", "%d", DNS_SERVICE_PORT);
2778 lpcfg_do_global_parameter(lp_ctx, "kdc enable fast", "True");
2780 lpcfg_do_global_parameter(lp_ctx, "nt status support", "True");
2782 lpcfg_do_global_parameter(lp_ctx, "max wins ttl", "518400"); /* 6 days */
2783 lpcfg_do_global_parameter(lp_ctx, "min wins ttl", "21600");
2785 lpcfg_do_global_parameter(lp_ctx, "tls enabled", "True");
2786 lpcfg_do_global_parameter(lp_ctx, "tls verify peer", "as_strict_as_possible");
2787 lpcfg_do_global_parameter(lp_ctx, "tls keyfile", "tls/key.pem");
2788 lpcfg_do_global_parameter(lp_ctx, "tls certfile", "tls/cert.pem");
2789 lpcfg_do_global_parameter(lp_ctx, "tls cafile", "tls/ca.pem");
2790 lpcfg_do_global_parameter(lp_ctx,
2792 "NORMAL:-VERS-SSL3.0");
2794 lpcfg_do_global_parameter(lp_ctx, "nsupdate command", "/usr/bin/nsupdate -g");
2796 lpcfg_do_global_parameter(lp_ctx, "allow dns updates", "secure only");
2797 lpcfg_do_global_parameter(lp_ctx, "dns zone scavenging", "False");
2798 lpcfg_do_global_parameter(lp_ctx, "dns forwarder", "");
2800 lpcfg_do_global_parameter(lp_ctx, "algorithmic rid base", "1000");
2802 lpcfg_do_global_parameter(lp_ctx, "enhanced browsing", "True");
2804 lpcfg_do_global_parameter(lp_ctx, "winbind nss info", "template");
2806 lpcfg_do_global_parameter(lp_ctx, "server schannel", "True");
2807 lpcfg_do_global_parameter(lp_ctx, "server schannel require seal", "True");
2808 lpcfg_do_global_parameter(lp_ctx, "reject md5 clients", "True");
2810 lpcfg_do_global_parameter(lp_ctx, "short preserve case", "True");
2812 lpcfg_do_global_parameter(lp_ctx, "max open files", "16384");
2814 lpcfg_do_global_parameter(lp_ctx, "cups connection timeout", "30");
2816 lpcfg_do_global_parameter(lp_ctx, "locking", "True");
2818 lpcfg_do_global_parameter(lp_ctx, "block size", "1024");
2820 lpcfg_do_global_parameter(lp_ctx, "client use spnego", "True");
2822 lpcfg_do_global_parameter(lp_ctx, "change notify", "True");
2824 lpcfg_do_global_parameter(lp_ctx, "name cache timeout", "660");
2826 lpcfg_do_global_parameter(lp_ctx, "defer sharing violations", "True");
2828 lpcfg_do_global_parameter(lp_ctx, "ldap replication sleep", "1000");
2830 lpcfg_do_global_parameter(lp_ctx, "idmap backend", "tdb");
2832 lpcfg_do_global_parameter(lp_ctx, "enable privileges", "True");
2834 lpcfg_do_global_parameter_var(lp_ctx, "smb2 max write", "%u", DEFAULT_SMB2_MAX_WRITE);
2836 lpcfg_do_global_parameter(lp_ctx, "passdb backend", "tdbsam");
2838 lpcfg_do_global_parameter(lp_ctx, "deadtime", "10080");
2840 lpcfg_do_global_parameter(lp_ctx, "getwd cache", "True");
2842 lpcfg_do_global_parameter(lp_ctx, "winbind nested groups", "True");
2844 lpcfg_do_global_parameter(lp_ctx, "mangled names", "illegal");
2846 lpcfg_do_global_parameter_var(lp_ctx, "smb2 max credits", "%u", DEFAULT_SMB2_MAX_CREDITS);
2848 lpcfg_do_global_parameter(lp_ctx, "ldap ssl", "start tls");
2850 lpcfg_do_global_parameter(lp_ctx, "ldap deref", "auto");
2852 lpcfg_do_global_parameter(lp_ctx, "lm interval", "60");
2854 lpcfg_do_global_parameter(lp_ctx, "mangling method", "hash2");
2856 lpcfg_do_global_parameter(lp_ctx, "hide dot files", "True");
2858 lpcfg_do_global_parameter(lp_ctx, "browse list", "True");
2860 lpcfg_do_global_parameter(lp_ctx, "passwd chat timeout", "2");
2862 lpcfg_do_global_parameter(lp_ctx, "guest account", GUEST_ACCOUNT);
2864 lpcfg_do_global_parameter(lp_ctx, "client schannel", "True");
2866 lpcfg_do_global_parameter(lp_ctx, "smb encrypt", "default");
2868 lpcfg_do_global_parameter(lp_ctx, "max log size", "5000");
2870 lpcfg_do_global_parameter(lp_ctx, "idmap negative cache time", "120");
2872 lpcfg_do_global_parameter(lp_ctx, "ldap follow referral", "auto");
2874 lpcfg_do_global_parameter(lp_ctx, "multicast dns register", "yes");
2876 lpcfg_do_global_parameter(lp_ctx, "winbind reconnect delay", "30");
2878 lpcfg_do_global_parameter(lp_ctx, "winbind request timeout", "60");
2880 lpcfg_do_global_parameter(lp_ctx, "nt acl support", "yes");
2882 lpcfg_do_global_parameter(lp_ctx, "acl check permissions", "yes");
2884 lpcfg_do_global_parameter(lp_ctx, "keepalive", "300");
2886 lpcfg_do_global_parameter(lp_ctx, "smbd profiling level", "off");
2888 lpcfg_do_global_parameter(lp_ctx, "winbind cache time", "300");
2890 lpcfg_do_global_parameter(lp_ctx, "level2 oplocks", "yes");
2892 lpcfg_do_global_parameter(lp_ctx, "show add printer wizard", "yes");
2894 lpcfg_do_global_parameter(lp_ctx, "ldap page size", "1000");
2896 lpcfg_do_global_parameter(lp_ctx, "kernel share modes", "no");
2898 lpcfg_do_global_parameter(lp_ctx, "strict locking", "Auto");
2900 lpcfg_do_global_parameter(lp_ctx, "strict sync", "yes");
2902 lpcfg_do_global_parameter(lp_ctx, "map readonly", "no");
2904 lpcfg_do_global_parameter(lp_ctx, "allow trusted domains", "yes");
2906 lpcfg_do_global_parameter(lp_ctx, "default devmode", "yes");
2908 lpcfg_do_global_parameter(lp_ctx, "os level", "20");
2910 lpcfg_do_global_parameter(lp_ctx, "dos filetimes", "yes");
2912 lpcfg_do_global_parameter(lp_ctx, "mangling char", "~");
2914 lpcfg_do_global_parameter(lp_ctx, "printcap cache time", "750");
2916 lpcfg_do_global_parameter(lp_ctx, "create krb5 conf", "yes");
2918 lpcfg_do_global_parameter(lp_ctx, "winbind max clients", "200");
2920 lpcfg_do_global_parameter(lp_ctx, "acl map full control", "yes");
2922 lpcfg_do_global_parameter(lp_ctx, "nt pipe support", "yes");
2924 lpcfg_do_global_parameter(lp_ctx, "ldap debug threshold", "10");
2926 lpcfg_do_global_parameter(lp_ctx, "client ldap sasl wrapping", "sign");
2928 lpcfg_do_global_parameter(lp_ctx, "mdns name", "netbios");
2930 lpcfg_do_global_parameter(lp_ctx, "ldap server require strong auth", "yes");
2932 lpcfg_do_global_parameter(lp_ctx, "follow symlinks", "yes");
2934 lpcfg_do_global_parameter(lp_ctx, "machine password timeout", "604800");
2936 lpcfg_do_global_parameter(lp_ctx, "ldap connection timeout", "2");
2938 lpcfg_do_global_parameter(lp_ctx, "winbind expand groups", "0");
2940 lpcfg_do_global_parameter(lp_ctx, "stat cache", "yes");
2942 lpcfg_do_global_parameter(lp_ctx, "lpq cache time", "30");
2944 lpcfg_do_global_parameter_var(lp_ctx, "smb2 max trans", "%u", DEFAULT_SMB2_MAX_TRANSACT);
2946 lpcfg_do_global_parameter_var(lp_ctx, "smb2 max read", "%u", DEFAULT_SMB2_MAX_READ);
2948 lpcfg_do_global_parameter(lp_ctx, "durable handles", "yes");
2950 lpcfg_do_global_parameter(lp_ctx, "max stat cache size", "512");
2952 lpcfg_do_global_parameter(lp_ctx, "ldap passwd sync", "no");
2954 lpcfg_do_global_parameter(lp_ctx, "kernel change notify", "yes");
2956 lpcfg_do_global_parameter(lp_ctx, "max ttl", "259200");
2958 lpcfg_do_global_parameter(lp_ctx, "blocking locks", "yes");
2960 lpcfg_do_global_parameter(lp_ctx, "load printers", "yes");
2962 lpcfg_do_global_parameter(lp_ctx, "idmap cache time", "604800");
2964 lpcfg_do_global_parameter(lp_ctx, "preserve case", "yes");
2966 lpcfg_do_global_parameter(lp_ctx, "lm announce", "auto");
2968 lpcfg_do_global_parameter(lp_ctx, "afs token lifetime", "604800");
2970 lpcfg_do_global_parameter(lp_ctx, "enable core files", "yes");
2972 lpcfg_do_global_parameter(lp_ctx, "winbind max domain connections", "1");
2974 lpcfg_do_global_parameter(lp_ctx, "case sensitive", "auto");
2976 lpcfg_do_global_parameter(lp_ctx, "ldap timeout", "15");
2978 lpcfg_do_global_parameter(lp_ctx, "mangle prefix", "1");
2980 lpcfg_do_global_parameter(lp_ctx, "posix locking", "yes");
2982 lpcfg_do_global_parameter(lp_ctx, "lock spin time", "200");
2984 lpcfg_do_global_parameter(lp_ctx, "directory name cache size", "100");
2986 lpcfg_do_global_parameter(lp_ctx, "nmbd bind explicit broadcast", "yes");
2988 lpcfg_do_global_parameter(lp_ctx, "init logon delay", "100");
2990 lpcfg_do_global_parameter(lp_ctx, "usershare owner only", "yes");
2992 lpcfg_do_global_parameter(lp_ctx, "-valid", "yes");
2994 lpcfg_do_global_parameter_var(lp_ctx, "usershare path", "%s/usershares", get_dyn_STATEDIR());
2997 lpcfg_do_global_parameter_var(lp_ctx, "panic action", "/bin/sleep 999999999");
3000 lpcfg_do_global_parameter(lp_ctx, "smb passwd file", get_dyn_SMB_PASSWD_FILE());
3002 lpcfg_do_global_parameter(lp_ctx, "logon home", "\\\\%N\\%U");
3004 lpcfg_do_global_parameter(lp_ctx, "logon path", "\\\\%N\\%U\\profile");
3006 lpcfg_do_global_parameter(lp_ctx, "printjob username", "%U");
3008 lpcfg_do_global_parameter(lp_ctx, "aio max threads", "100");
3010 lpcfg_do_global_parameter(lp_ctx, "smb2 leases", "yes");
3012 lpcfg_do_global_parameter(lp_ctx, "server multi channel support", "yes");
3014 lpcfg_do_global_parameter(lp_ctx, "kerberos encryption types", "all");
3016 lpcfg_do_global_parameter(lp_ctx,
3017 "rpc server dynamic port range",
3020 lpcfg_do_global_parameter(lp_ctx, "prefork children", "4");
3021 lpcfg_do_global_parameter(lp_ctx, "prefork backoff increment", "10");
3022 lpcfg_do_global_parameter(lp_ctx, "prefork maximum backoff", "120");
3024 lpcfg_do_global_parameter(lp_ctx, "check parent directory delete on close", "no");
3026 lpcfg_do_global_parameter(lp_ctx, "ea support", "yes");
3028 lpcfg_do_global_parameter(lp_ctx, "store dos attributes", "yes");
3030 lpcfg_do_global_parameter(lp_ctx, "debug encryption", "no");
3032 lpcfg_do_global_parameter(lp_ctx, "spotlight backend", "noindex");
3034 lpcfg_do_global_parameter(
3035 lp_ctx, "ldap max anonymous request size", "256000");
3036 lpcfg_do_global_parameter(
3037 lp_ctx, "ldap max authenticated request size", "16777216");
3038 lpcfg_do_global_parameter(
3039 lp_ctx, "ldap max search request size", "256000");
3041 /* Async DNS query timeout in seconds. */
3042 lpcfg_do_global_parameter(lp_ctx, "async dns timeout", "10");
3044 lpcfg_do_global_parameter(lp_ctx,
3045 "client smb encrypt",
3048 lpcfg_do_global_parameter(lp_ctx,
3049 "client use kerberos",
3052 lpcfg_do_global_parameter(lp_ctx,
3053 "client protection",
3056 lpcfg_do_global_parameter(lp_ctx,
3057 "smbd max xattr size",
3060 lpcfg_do_global_parameter(lp_ctx,
3061 "acl flag inherited canonicalization",
3064 lpcfg_do_global_parameter(lp_ctx,
3065 "winbind use krb5 enterprise principals",
3068 lpcfg_do_global_parameter(lp_ctx,
3069 "client smb3 signing algorithms",
3070 DEFAULT_SMB3_SIGNING_ALGORITHMS);
3071 lpcfg_do_global_parameter(lp_ctx,
3072 "server smb3 signing algorithms",
3073 DEFAULT_SMB3_SIGNING_ALGORITHMS);
3075 lpcfg_do_global_parameter(lp_ctx,
3076 "client smb3 encryption algorithms",
3077 DEFAULT_SMB3_ENCRYPTION_ALGORITHMS);
3078 lpcfg_do_global_parameter(lp_ctx,
3079 "server smb3 encryption algorithms",
3080 DEFAULT_SMB3_ENCRYPTION_ALGORITHMS);
3082 lpcfg_do_global_parameter(lp_ctx,
3086 lpcfg_do_global_parameter(lp_ctx,
3087 "rpc start on demand helpers",
3090 for (i = 0; parm_table[i].label; i++) {
3091 if (!(lp_ctx->flags[i] & FLAG_CMDLINE)) {
3092 lp_ctx->flags[i] |= FLAG_DEFAULT;
3096 for (parm=lp_ctx->globals->param_opt; parm; parm=parm->next) {
3097 if (!(parm->priority & FLAG_CMDLINE)) {
3098 parm->priority |= FLAG_DEFAULT;
3102 for (parm=lp_ctx->sDefault->param_opt; parm; parm=parm->next) {
3103 if (!(parm->priority & FLAG_CMDLINE)) {
3104 parm->priority |= FLAG_DEFAULT;
3112 * Initialise the global parameter structure.
3114 struct loadparm_context *loadparm_init_global(bool load_default)
3116 if (global_loadparm_context == NULL) {
3117 global_loadparm_context = loadparm_init(NULL);
3119 if (global_loadparm_context == NULL) {
3122 global_loadparm_context->global = true;
3123 if (load_default && !global_loadparm_context->loaded) {
3124 lpcfg_load_default(global_loadparm_context);
3126 global_loadparm_context->refuse_free = true;
3127 return global_loadparm_context;
3131 * Initialise the global parameter structure.
3133 struct loadparm_context *loadparm_init_s3(TALLOC_CTX *mem_ctx,
3134 const struct loadparm_s3_helpers *s3_fns)
3136 struct loadparm_context *loadparm_context = talloc_zero(mem_ctx, struct loadparm_context);
3137 if (!loadparm_context) {
3140 loadparm_context->s3_fns = s3_fns;
3141 loadparm_context->globals = s3_fns->globals;
3142 loadparm_context->flags = s3_fns->flags;
3144 return loadparm_context;
3147 const char *lpcfg_configfile(struct loadparm_context *lp_ctx)
3149 return lp_ctx->szConfigFile;
3152 const char *lp_default_path(void)
3154 if (getenv("SMB_CONF_PATH"))
3155 return getenv("SMB_CONF_PATH");
3157 return dyn_CONFIGFILE;
3161 * Update the internal state of a loadparm context after settings
3164 static bool lpcfg_update(struct loadparm_context *lp_ctx)
3166 struct debug_settings settings;
3167 int max_protocol, min_protocol;
3168 TALLOC_CTX *tmp_ctx;
3169 const struct loadparm_substitution *lp_sub =
3170 lpcfg_noop_substitution();
3172 tmp_ctx = talloc_new(lp_ctx);
3173 if (tmp_ctx == NULL) {
3177 lpcfg_add_auto_services(lp_ctx, lpcfg_auto_services(lp_ctx, lp_sub, tmp_ctx));
3179 if (!lp_ctx->globals->wins_server_list && lp_ctx->globals->we_are_a_wins_server) {
3180 lpcfg_do_global_parameter(lp_ctx, "wins server", "127.0.0.1");
3183 if (!lp_ctx->global) {
3184 TALLOC_FREE(tmp_ctx);
3188 panic_action = lp_ctx->globals->panic_action;
3190 reload_charcnv(lp_ctx);
3192 ZERO_STRUCT(settings);
3193 /* Add any more debug-related smb.conf parameters created in
3195 settings.timestamp_logs = lp_ctx->globals->timestamp_logs;
3196 settings.debug_prefix_timestamp = lp_ctx->globals->debug_prefix_timestamp;
3197 settings.debug_hires_timestamp = lp_ctx->globals->debug_hires_timestamp;
3198 settings.debug_syslog_format = lp_ctx->globals->debug_syslog_format;
3199 settings.debug_pid = lp_ctx->globals->debug_pid;
3200 settings.debug_uid = lp_ctx->globals->debug_uid;
3201 settings.debug_class = lp_ctx->globals->debug_class;
3202 settings.max_log_size = lp_ctx->globals->max_log_size;
3203 debug_set_settings(&settings, lp_ctx->globals->logging,
3204 lp_ctx->globals->syslog,
3205 lp_ctx->globals->syslog_only);
3207 /* FIXME: This is a bit of a hack, but we can't use a global, since
3208 * not everything that uses lp also uses the socket library */
3209 if (lpcfg_parm_bool(lp_ctx, NULL, "socket", "testnonblock", false)) {
3210 setenv("SOCKET_TESTNONBLOCK", "1", 1);
3212 unsetenv("SOCKET_TESTNONBLOCK");
3215 /* Check if command line max protocol < min protocol, if so
3216 * report a warning to the user.
3218 max_protocol = lpcfg_client_max_protocol(lp_ctx);
3219 min_protocol = lpcfg_client_min_protocol(lp_ctx);
3220 if (lpcfg_client_max_protocol(lp_ctx) < lpcfg_client_min_protocol(lp_ctx)) {
3221 const char *max_protocolp, *min_protocolp;
3222 max_protocolp = lpcfg_get_smb_protocol(max_protocol);
3223 min_protocolp = lpcfg_get_smb_protocol(min_protocol);
3224 DBG_ERR("Max protocol %s is less than min protocol %s.\n",
3225 max_protocolp, min_protocolp);
3228 TALLOC_FREE(tmp_ctx);
3232 bool lpcfg_load_default(struct loadparm_context *lp_ctx)
3236 path = lp_default_path();
3238 if (!file_exist(path)) {
3239 /* We allow the default smb.conf file to not exist,
3240 * basically the equivalent of an empty file. */
3241 return lpcfg_update(lp_ctx);
3244 return lpcfg_load(lp_ctx, path);
3248 * Load the services array from the services file.
3250 * Return True on success, False on failure.
3252 static bool lpcfg_load_internal(struct loadparm_context *lp_ctx,
3253 const char *filename, bool set_global)
3258 if (lp_ctx->szConfigFile != NULL) {
3259 talloc_free(discard_const_p(char, lp_ctx->szConfigFile));
3260 lp_ctx->szConfigFile = NULL;
3263 lp_ctx->szConfigFile = talloc_strdup(lp_ctx, filename);
3265 if (lp_ctx->s3_fns) {
3266 return lp_ctx->s3_fns->load(filename);
3269 lp_ctx->bInGlobalSection = true;
3270 n2 = standard_sub_basic(lp_ctx, lp_ctx->szConfigFile);
3271 DEBUG(2, ("lpcfg_load: refreshing parameters from %s\n", n2));
3273 add_to_file_list(lp_ctx, &lp_ctx->file_lists, lp_ctx->szConfigFile, n2);
3275 /* We get sections first, so have to start 'behind' to make up */
3276 lp_ctx->currentService = NULL;
3277 bRetval = pm_process(n2, do_section, lpcfg_do_parameter, lp_ctx);
3279 /* finish up the last section */
3280 DEBUG(4, ("pm_process() returned %s\n", BOOLSTR(bRetval)));
3282 if (lp_ctx->currentService != NULL)
3283 bRetval = lpcfg_service_ok(lp_ctx->currentService);
3285 bRetval = bRetval && lpcfg_update(lp_ctx);
3287 /* we do this unconditionally, so that it happens even
3288 for a missing smb.conf */
3289 reload_charcnv(lp_ctx);
3291 if (bRetval == true && set_global) {
3292 /* set this up so that any child python tasks will
3293 find the right smb.conf */
3294 setenv("SMB_CONF_PATH", filename, 1);
3296 /* set the context used by the lp_*() function
3298 global_loadparm_context = lp_ctx;
3299 lp_ctx->loaded = true;
3305 bool lpcfg_load_no_global(struct loadparm_context *lp_ctx, const char *filename)
3307 return lpcfg_load_internal(lp_ctx, filename, false);
3310 bool lpcfg_load(struct loadparm_context *lp_ctx, const char *filename)
3312 return lpcfg_load_internal(lp_ctx, filename, true);
3316 * Return the max number of services.
3319 int lpcfg_numservices(struct loadparm_context *lp_ctx)
3321 if (lp_ctx->s3_fns) {
3322 return lp_ctx->s3_fns->get_numservices();
3325 return lp_ctx->iNumServices;
3329 * Display the contents of the services array in human-readable form.
3332 void lpcfg_dump(struct loadparm_context *lp_ctx, FILE *f, bool show_defaults,
3337 if (lp_ctx->s3_fns) {
3338 lp_ctx->s3_fns->dump(f, show_defaults, maxtoprint);
3342 lpcfg_dump_globals(lp_ctx, f, show_defaults);
3344 lpcfg_dump_a_service(lp_ctx->sDefault, lp_ctx->sDefault, f, lp_ctx->flags, show_defaults);
3346 for (iService = 0; iService < maxtoprint; iService++)
3347 lpcfg_dump_one(f, show_defaults, lp_ctx->services[iService], lp_ctx->sDefault);
3351 * Display the contents of one service in human-readable form.
3353 void lpcfg_dump_one(FILE *f, bool show_defaults, struct loadparm_service *service, struct loadparm_service *sDefault)
3355 if (service != NULL) {
3356 if (service->szService[0] == '\0')
3358 lpcfg_dump_a_service(service, sDefault, f, NULL, show_defaults);
3362 struct loadparm_service *lpcfg_servicebynum(struct loadparm_context *lp_ctx,
3365 if (lp_ctx->s3_fns) {
3366 return lp_ctx->s3_fns->get_servicebynum(snum);
3369 return lp_ctx->services[snum];
3372 struct loadparm_service *lpcfg_service(struct loadparm_context *lp_ctx,
3373 const char *service_name)
3378 if (lp_ctx->s3_fns) {
3379 return lp_ctx->s3_fns->get_service(service_name);
3382 for (iService = lp_ctx->iNumServices - 1; iService >= 0; iService--) {
3383 if (lp_ctx->services[iService] &&
3384 lp_ctx->services[iService]->szService) {
3386 * The substitution here is used to support %U is
3389 serviceName = standard_sub_basic(
3390 lp_ctx->services[iService],
3391 lp_ctx->services[iService]->szService);
3392 if (strequal(serviceName, service_name)) {
3393 talloc_free(serviceName);
3394 return lp_ctx->services[iService];
3396 talloc_free(serviceName);
3400 DEBUG(7,("lpcfg_servicenumber: couldn't find %s\n", service_name));
3404 const char *lpcfg_servicename(const struct loadparm_service *service)
3406 return service ? lpcfg_string((const char *)service->szService) : NULL;
3409 struct smb_iconv_handle *lpcfg_iconv_handle(struct loadparm_context *lp_ctx)
3411 if (lp_ctx == NULL) {
3412 return get_iconv_handle();
3414 return lp_ctx->iconv_handle;
3417 _PUBLIC_ void reload_charcnv(struct loadparm_context *lp_ctx)
3419 if (!lp_ctx->global) {
3423 lp_ctx->iconv_handle =
3424 reinit_iconv_handle(lp_ctx,
3425 lpcfg_dos_charset(lp_ctx),
3426 lpcfg_unix_charset(lp_ctx));
3427 if (lp_ctx->iconv_handle == NULL) {
3428 smb_panic("reinit_iconv_handle failed");
3432 _PUBLIC_ char *lpcfg_tls_keyfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
3434 return lpcfg_private_path(mem_ctx, lp_ctx, lpcfg__tls_keyfile(lp_ctx));
3437 _PUBLIC_ char *lpcfg_tls_certfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
3439 return lpcfg_private_path(mem_ctx, lp_ctx, lpcfg__tls_certfile(lp_ctx));
3442 _PUBLIC_ char *lpcfg_tls_cafile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
3444 return lpcfg_private_path(mem_ctx, lp_ctx, lpcfg__tls_cafile(lp_ctx));
3447 _PUBLIC_ char *lpcfg_tls_crlfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
3449 return lpcfg_private_path(mem_ctx, lp_ctx, lpcfg__tls_crlfile(lp_ctx));
3452 _PUBLIC_ char *lpcfg_tls_dhpfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
3454 return lpcfg_private_path(mem_ctx, lp_ctx, lpcfg__tls_dhpfile(lp_ctx));
3457 struct gensec_settings *lpcfg_gensec_settings(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
3459 struct gensec_settings *settings = talloc_zero(mem_ctx, struct gensec_settings);
3460 if (settings == NULL)
3462 SMB_ASSERT(lp_ctx != NULL);
3463 settings->lp_ctx = talloc_reference(settings, lp_ctx);
3464 settings->target_hostname = lpcfg_parm_string(lp_ctx, NULL, "gensec", "target_hostname");
3468 int lpcfg_server_role(struct loadparm_context *lp_ctx)
3470 int domain_master = lpcfg__domain_master(lp_ctx);
3472 return lp_find_server_role(lpcfg__server_role(lp_ctx),
3473 lpcfg__security(lp_ctx),
3474 lpcfg__domain_logons(lp_ctx),
3475 (domain_master == true) ||
3476 (domain_master == Auto));
3479 int lpcfg_security(struct loadparm_context *lp_ctx)
3481 return lp_find_security(lpcfg__server_role(lp_ctx),
3482 lpcfg__security(lp_ctx));
3485 int lpcfg_client_max_protocol(struct loadparm_context *lp_ctx)
3487 int client_max_protocol = lpcfg__client_max_protocol(lp_ctx);
3488 if (client_max_protocol == PROTOCOL_DEFAULT) {
3489 return PROTOCOL_LATEST;
3491 return client_max_protocol;
3494 int lpcfg_client_ipc_min_protocol(struct loadparm_context *lp_ctx)
3496 int client_ipc_min_protocol = lpcfg__client_ipc_min_protocol(lp_ctx);
3497 if (client_ipc_min_protocol == PROTOCOL_DEFAULT) {
3498 client_ipc_min_protocol = lpcfg_client_min_protocol(lp_ctx);
3500 if (client_ipc_min_protocol < PROTOCOL_NT1) {
3501 return PROTOCOL_NT1;
3503 return client_ipc_min_protocol;
3506 int lpcfg_client_ipc_max_protocol(struct loadparm_context *lp_ctx)
3508 int client_ipc_max_protocol = lpcfg__client_ipc_max_protocol(lp_ctx);
3509 if (client_ipc_max_protocol == PROTOCOL_DEFAULT) {
3510 return PROTOCOL_LATEST;
3512 if (client_ipc_max_protocol < PROTOCOL_NT1) {
3513 return PROTOCOL_NT1;
3515 return client_ipc_max_protocol;
3518 int lpcfg_client_ipc_signing(struct loadparm_context *lp_ctx)
3520 int client_ipc_signing = lpcfg__client_ipc_signing(lp_ctx);
3521 if (client_ipc_signing == SMB_SIGNING_DEFAULT) {
3522 return SMB_SIGNING_REQUIRED;
3524 return client_ipc_signing;
3527 enum credentials_use_kerberos lpcfg_client_use_kerberos(struct loadparm_context *lp_ctx)
3529 if (lpcfg_weak_crypto(lp_ctx) == SAMBA_WEAK_CRYPTO_DISALLOWED) {
3530 return CRED_USE_KERBEROS_REQUIRED;
3533 return lpcfg__client_use_kerberos(lp_ctx);
3536 bool lpcfg_server_signing_allowed(struct loadparm_context *lp_ctx, bool *mandatory)
3538 bool allowed = true;
3539 enum smb_signing_setting signing_setting = lpcfg_server_signing(lp_ctx);
3543 if (signing_setting == SMB_SIGNING_DEFAULT) {
3545 * If we are a domain controller, SMB signing is
3546 * really important, as it can prevent a number of
3547 * attacks on communications between us and the
3550 * However, it really sucks (no sendfile, CPU
3551 * overhead) performance-wise when used on a
3552 * file server, so disable it by default
3556 if (lpcfg_server_role(lp_ctx) >= ROLE_ACTIVE_DIRECTORY_DC) {
3557 signing_setting = SMB_SIGNING_REQUIRED;
3559 signing_setting = SMB_SIGNING_OFF;
3563 switch (signing_setting) {
3564 case SMB_SIGNING_REQUIRED:
3567 case SMB_SIGNING_DESIRED:
3568 case SMB_SIGNING_IF_REQUIRED:
3570 case SMB_SIGNING_OFF:
3573 case SMB_SIGNING_DEFAULT:
3574 case SMB_SIGNING_IPC_DEFAULT:
3575 smb_panic(__location__);
3582 int lpcfg_tdb_hash_size(struct loadparm_context *lp_ctx, const char *name)
3590 base = strrchr_m(name, '/');
3596 return lpcfg_parm_int(lp_ctx, NULL, "tdb_hashsize", base, 0);
3600 int lpcfg_tdb_flags(struct loadparm_context *lp_ctx, int tdb_flags)
3602 if (!lpcfg_use_mmap(lp_ctx)) {
3603 tdb_flags |= TDB_NOMMAP;
3609 * Do not allow LanMan auth if unless NTLMv1 is also allowed
3611 * This also ensures it is disabled if NTLM is totally disabled
3613 bool lpcfg_lanman_auth(struct loadparm_context *lp_ctx)
3615 enum ntlm_auth_level ntlm_auth_level = lpcfg_ntlm_auth(lp_ctx);
3617 if (ntlm_auth_level == NTLM_AUTH_ON) {
3618 return lpcfg__lanman_auth(lp_ctx);
3624 static char *lpcfg_noop_substitution_fn(
3625 TALLOC_CTX *mem_ctx,
3626 const struct loadparm_substitution *lp_sub,
3627 const char *raw_value,
3630 return talloc_strdup(mem_ctx, raw_value);
3633 static const struct loadparm_substitution global_noop_substitution = {
3634 .substituted_string_fn = lpcfg_noop_substitution_fn,
3637 const struct loadparm_substitution *lpcfg_noop_substitution(void)
3639 return &global_noop_substitution;
3642 char *lpcfg_substituted_string(TALLOC_CTX *mem_ctx,
3643 const struct loadparm_substitution *lp_sub,
3644 const char *raw_value)
3646 return lp_sub->substituted_string_fn(mem_ctx,
3649 lp_sub->private_data);
3653 * @brief Parse a string value of a given parameter to its integer enum value.
3655 * @param[in] param_name The parameter name (e.g. 'client smb encrypt')
3657 * @param[in] param_value The parameter value (e.g. 'required').
3659 * @return The integer value of the enum the param_value matches or INT32_MIN
3662 int32_t lpcfg_parse_enum_vals(const char *param_name,
3663 const char *param_value)
3665 struct parm_struct *parm = NULL;
3666 int32_t ret = INT32_MIN;
3669 parm = lpcfg_parm_struct(NULL, param_name);
3674 ok = lp_set_enum_parm(parm, param_value, &ret);