drsuapi.idl: fix source_dsa spelling
[samba4-gss.git] / lib / param / loadparm.c
blob7d7c7493eb2579b9a78d29e6626a37bf8109d6ea
1 /*
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/>.
31 * Load parameters.
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.
37 * To add a parameter:
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
46 * Notes:
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
52 * careful!
56 #include "includes.h"
57 #include "version.h"
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"
70 #include "tdb.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>
83 #endif
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;
129 char *ret;
130 #endif
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? */
137 #if 0
138 DEBUG(10, ("lpcfg_string(%s)\n", s));
139 #endif
141 #if 0 /* until REWRITE done to make thread-safe */
142 if (!lp_talloc)
143 lp_talloc = talloc_init("lp_talloc");
145 ret = talloc_array(lp_talloc, char, len + 100); /* leave room for substitution */
147 if (!ret)
148 return NULL;
150 if (!s)
151 *ret = 0;
152 else
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);
161 return (ret);
162 #endif
163 return s;
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 variants */
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
213 * hook */
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) {
294 return data;
296 data = data->next;
301 * Fall back to fetching from the globals.
303 data = global_opts;
304 while (data != NULL) {
305 if (strwicmp(data->key, param_key) == 0) {
306 return data;
308 data = data->next;
311 return NULL;
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;
320 if (lp_ctx == NULL)
321 return NULL;
323 data = get_parametric_helper(service,
324 type, option, lp_ctx->globals->param_opt);
326 if (data == NULL) {
327 return NULL;
328 } else {
329 return data->value;
335 * convenience routine to return int parameters.
337 int lp_int(const char *s)
340 if (!s || !*s) {
341 DEBUG(0,("lp_int(%s): is called with NULL!\n",s));
342 return -1;
345 return strtol(s, NULL, 0);
349 * convenience routine to return unsigned long parameters.
351 unsigned long lp_ulong(const char *s)
353 int error = 0;
354 unsigned long int ret;
356 if (!s || !*s) {
357 DBG_DEBUG("lp_ulong(%s): is called with NULL!\n",s);
358 return -1;
361 ret = smb_strtoul(s, NULL, 0, &error, SMB_STR_STANDARD);
362 if (error != 0) {
363 DBG_DEBUG("lp_ulong(%s): conversion failed\n",s);
364 return -1;
367 return ret;
371 * convenience routine to return unsigned long long parameters.
373 unsigned long long lp_ulonglong(const char *s)
375 int error = 0;
376 unsigned long long int ret;
378 if (!s || !*s) {
379 DBG_DEBUG("lp_ulonglong(%s): is called with NULL!\n", s);
380 return -1;
383 ret = smb_strtoull(s, NULL, 0, &error, SMB_STR_STANDARD);
384 if (error != 0) {
385 DBG_DEBUG("lp_ulonglong(%s): conversion failed\n",s);
386 return -1;
389 return ret;
393 * convenience routine to return unsigned long parameters.
395 static long lp_long(const char *s)
398 if (!s) {
399 DEBUG(0,("lp_long(%s): is called with NULL!\n",s));
400 return -1;
403 return strtol(s, NULL, 0);
407 * convenience routine to return unsigned long parameters.
409 static double lp_double(const char *s)
412 if (!s) {
413 DEBUG(0,("lp_double(%s): is called with NULL!\n",s));
414 return -1;
417 return strtod(s, NULL);
421 * convenience routine to return boolean parameters.
423 bool lp_bool(const char *s)
425 bool ret = false;
427 if (!s || !*s) {
428 DEBUG(0,("lp_bool(%s): is called with NULL!\n",s));
429 return false;
432 if (!set_boolean(s, &ret)) {
433 DEBUG(0,("lp_bool(%s): value is not boolean!\n",s));
434 return false;
437 return ret;
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,
448 const char *option)
450 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
452 if (value)
453 return lpcfg_string(value);
455 return NULL;
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,
467 const char *type,
468 const char *option, const char *separator)
470 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
472 if (value != NULL) {
473 char **l = str_list_make(mem_ctx, value, separator);
474 return discard_const_p(const char *, l);
477 return NULL;
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);
491 if (value)
492 return lp_int(value);
494 return default_v;
498 * Return parametric option from a given service. Type is a part of
499 * option before ':'.
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)
507 uint64_t bval;
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) {
513 return (int)bval;
517 return default_v;
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);
531 if (value)
532 return lp_ulong(value);
534 return default_v;
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);
549 if (value) {
550 return lp_ulonglong(value);
553 return default_v;
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);
562 if (value)
563 return lp_long(value);
565 return default_v;
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);
574 if (value != NULL)
575 return lp_double(value);
577 return default_v;
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);
591 if (value != NULL)
592 return lp_bool(value);
594 return default_v;
598 /* this is used to prevent lots of mallocs of size 1 */
599 static const char lpcfg_string_empty[] = "";
602 Free a string value.
604 void lpcfg_string_free(char **s)
606 if (s == NULL) {
607 return;
609 if (*s == lpcfg_string_empty) {
610 *s = NULL;
611 return;
613 TALLOC_FREE(*s);
617 * Set a string value, deallocating any existing space, and allocing the space
618 * for the string
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);
626 return true;
629 *dest = talloc_strdup(mem_ctx, src);
630 if ((*dest) == NULL) {
631 DEBUG(0,("Out of memory in string_set\n"));
632 return false;
635 return true;
639 * Set a string value, deallocating any existing space, and allocing the space
640 * for the string
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);
648 return true;
651 *dest = strupper_talloc(mem_ctx, src);
652 if ((*dest) == NULL) {
653 DEBUG(0,("Out of memory in string_set_upper\n"));
654 return false;
657 return true;
663 * Add a new service to the services array initialising it with the given
664 * service.
667 struct loadparm_service *lpcfg_add_service(struct loadparm_context *lp_ctx,
668 const struct loadparm_service *pservice,
669 const char *name)
671 int i;
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 */
684 if (name) {
685 struct loadparm_service *service = lpcfg_getservicebyname(lp_ctx,
686 name);
687 if (service != NULL) {
688 /* Clean all parametric options for service */
689 /* They will be added during parsing again */
690 data = service->param_opt;
691 while (data) {
692 pdata = data->next;
693 talloc_free(data);
694 data = pdata;
696 service->param_opt = NULL;
697 return service;
701 /* find an invalid one */
702 for (i = 0; i < lp_ctx->iNumServices; i++)
703 if (lp_ctx->services[i] == NULL)
704 break;
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);
712 if (!tsp) {
713 DEBUG(0,("lpcfg_add_service: failed to enlarge services!\n"));
714 return NULL;
715 } else {
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"));
726 return NULL;
728 copy_service(lp_ctx->services[i], pservice, NULL);
729 if (name != 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)
741 int iIndex;
743 for (iIndex = 0; parm_table[iIndex].label; iIndex++)
744 if (strwicmp(parm_table[iIndex].label, pszParmName) == 0)
745 return iIndex;
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
753 return -1;
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);
764 if (num < 0) {
765 return NULL;
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;
786 else return NULL;
787 } else {
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)
797 int parmnum;
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)
807 int parmnum;
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)
822 int iService;
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];
834 return NULL;
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,
845 unsigned priority)
847 struct parmlist_entry *new_opt, *opt;
849 opt = *opt_list;
851 /* Traverse destination */
852 while (opt) {
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
858 overridden */
859 return;
861 TALLOC_FREE(opt->list);
862 lpcfg_string_set(opt, &opt->value, opt_value);
863 opt->priority = priority;
864 return;
866 opt = opt->next;
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) {
873 smb_panic("OOM");
875 new_opt->key = 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)
894 int i;
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;
903 void *dest_ptr =
904 ((char *)pserviceDest) + parm_table[i].offset;
906 switch (parm_table[i].type) {
907 case P_BOOL:
908 case P_BOOLREV:
909 *(bool *)dest_ptr = *(const bool *)src_ptr;
910 break;
912 case P_INTEGER:
913 case P_BYTES:
914 case P_OCTAL:
915 case P_ENUM:
916 *(int *)dest_ptr = *(const int *)src_ptr;
917 break;
919 case P_CHAR:
920 *(char *)dest_ptr = *(const char *)src_ptr;
921 break;
923 case P_STRING:
924 lpcfg_string_set(pserviceDest,
925 (char **)dest_ptr,
926 *(const char * const *)src_ptr);
927 break;
929 case P_USTRING:
930 lpcfg_string_set_upper(pserviceDest,
931 (char **)dest_ptr,
932 *(const char * const *)src_ptr);
933 break;
934 case P_CMDLIST:
935 case P_LIST:
936 TALLOC_FREE(*((char ***)dest_ptr));
937 *(char ***)dest_ptr = str_list_copy(pserviceDest,
938 *discard_const_p(const char **, src_ptr));
939 break;
940 default:
941 break;
945 if (bcopyall) {
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)
964 bool bRetval;
966 bRetval = true;
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"));
970 bRetval = false;
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));
999 return bRetval;
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;
1013 while (f) {
1014 if (f->name && !strcmp(f->name, fname))
1015 break;
1016 f = f->next;
1019 if (!f) {
1020 f = talloc_zero(mem_ctx, struct file_lists);
1021 if (!f)
1022 goto fail;
1023 f->next = *list;
1024 f->name = talloc_strdup(f, fname);
1025 if (!f->name) {
1026 TALLOC_FREE(f);
1027 goto fail;
1029 f->subfname = talloc_strdup(f, subfname);
1030 if (!f->subfname) {
1031 TALLOC_FREE(f);
1032 goto fail;
1034 *list = f;
1037 /* If file_modtime() fails it leaves f->modtime as zero. */
1038 (void)file_modtime(subfname, &f->modtime);
1039 return;
1041 fail:
1042 DEBUG(0, ("Unable to add file to file list: %s\n", fname));
1047 * set the value for a P_ENUM
1049 bool lp_set_enum_parm( struct parm_struct *parm, const char *pszParmValue,
1050 int *ptr )
1052 int i;
1054 for (i = 0; parm->enum_list[i].name; i++) {
1055 if (strwicmp(pszParmValue, parm->enum_list[i].name) == 0) {
1056 *ptr = parm->enum_list[i].value;
1057 return true;
1060 DEBUG(0, ("WARNING: Ignoring invalid value '%s' for parameter '%s'\n",
1061 pszParmValue, parm->label));
1062 return false;
1066 /***************************************************************************
1067 Handle the "realm" parameter
1068 ***************************************************************************/
1070 bool handle_realm(struct loadparm_context *lp_ctx, struct loadparm_service *service,
1071 const char *pszParmValue, char **ptr)
1073 char *upper;
1074 char *lower;
1076 upper = strupper_talloc(lp_ctx, pszParmValue);
1077 if (upper == NULL) {
1078 return false;
1081 lower = strlower_talloc(lp_ctx, pszParmValue);
1082 if (lower == NULL) {
1083 TALLOC_FREE(upper);
1084 return false;
1087 lpcfg_string_set(lp_ctx->globals->ctx, &lp_ctx->globals->realm, upper);
1088 lpcfg_string_set(lp_ctx->globals->ctx, &lp_ctx->globals->dnsdomain, lower);
1090 return true;
1093 /***************************************************************************
1094 Handle the include operation.
1095 ***************************************************************************/
1097 bool handle_include(struct loadparm_context *lp_ctx, struct loadparm_service *service,
1098 const char *pszParmValue, char **ptr)
1100 char *fname;
1101 const char *substitution_variable_substring;
1102 char next_char;
1104 if (lp_ctx->s3_fns) {
1105 return lp_ctx->s3_fns->lp_include(lp_ctx, service, pszParmValue, ptr);
1108 fname = standard_sub_basic(lp_ctx, pszParmValue);
1110 add_to_file_list(lp_ctx, &lp_ctx->file_lists, pszParmValue, fname);
1112 lpcfg_string_set(lp_ctx, ptr, fname);
1114 if (file_exist(fname))
1115 return pm_process(fname, do_section, lpcfg_do_parameter, lp_ctx);
1118 * If the file doesn't exist, we check that it isn't due to variable
1119 * substitution
1121 substitution_variable_substring = strchr(fname, '%');
1123 if (substitution_variable_substring != NULL) {
1124 next_char = substitution_variable_substring[1];
1125 if ((next_char >= 'a' && next_char <= 'z')
1126 || (next_char >= 'A' && next_char <= 'Z')) {
1127 DEBUG(2, ("Tried to load %s but variable substitution in "
1128 "filename, ignoring file.\n", fname));
1129 return true;
1133 DEBUG(2, ("Can't find include file %s\n", fname));
1135 return true;
1138 /***************************************************************************
1139 Handle the interpretation of the copy parameter.
1140 ***************************************************************************/
1142 bool handle_copy(struct loadparm_context *lp_ctx, struct loadparm_service *service,
1143 const char *pszParmValue, char **ptr)
1145 bool bRetval;
1146 struct loadparm_service *serviceTemp = NULL;
1148 bRetval = false;
1150 DEBUG(3, ("Copying service from service %s\n", pszParmValue));
1152 serviceTemp = lpcfg_getservicebyname(lp_ctx, pszParmValue);
1154 if (service == NULL) {
1155 DEBUG(0, ("Unable to copy service - invalid service destination.\n"));
1156 return false;
1159 if (serviceTemp != NULL) {
1160 if (serviceTemp == service) {
1161 DEBUG(0, ("Can't copy service %s - unable to copy self!\n", pszParmValue));
1162 } else {
1163 copy_service(service,
1164 serviceTemp,
1165 service->copymap);
1166 lpcfg_string_set(service, ptr, pszParmValue);
1168 bRetval = true;
1170 } else {
1171 DEBUG(0, ("Unable to copy service - source not found: %s\n",
1172 pszParmValue));
1173 bRetval = false;
1176 return bRetval;
1179 bool handle_debug_list(struct loadparm_context *lp_ctx, struct loadparm_service *service,
1180 const char *pszParmValue, char **ptr)
1182 lpcfg_string_set(lp_ctx->globals->ctx, ptr, pszParmValue);
1184 return debug_parse_levels(pszParmValue);
1187 bool handle_logfile(struct loadparm_context *lp_ctx, struct loadparm_service *service,
1188 const char *pszParmValue, char **ptr)
1190 if (lp_ctx->s3_fns == NULL) {
1191 debug_set_logfile(pszParmValue);
1194 lpcfg_string_set(lp_ctx->globals->ctx, ptr, pszParmValue);
1196 return true;
1200 * These special charset handling methods only run in the source3 code.
1203 bool handle_charset(struct loadparm_context *lp_ctx, struct loadparm_service *service,
1204 const char *pszParmValue, char **ptr)
1206 if (lp_ctx->s3_fns) {
1207 if (*ptr == NULL || strcmp(*ptr, pszParmValue) != 0) {
1208 struct smb_iconv_handle *ret = NULL;
1210 ret = reinit_iconv_handle(NULL,
1211 lpcfg_dos_charset(lp_ctx),
1212 lpcfg_unix_charset(lp_ctx));
1213 if (ret == NULL) {
1214 smb_panic("reinit_iconv_handle failed");
1219 return lpcfg_string_set(lp_ctx->globals->ctx, ptr, pszParmValue);
1223 bool handle_dos_charset(struct loadparm_context *lp_ctx, struct loadparm_service *service,
1224 const char *pszParmValue, char **ptr)
1226 bool is_utf8 = false;
1227 size_t len = strlen(pszParmValue);
1229 if (lp_ctx->s3_fns) {
1230 if (len == 4 || len == 5) {
1231 /* Don't use StrCaseCmp here as we don't want to
1232 initialize iconv. */
1233 if ((toupper_m(pszParmValue[0]) == 'U') &&
1234 (toupper_m(pszParmValue[1]) == 'T') &&
1235 (toupper_m(pszParmValue[2]) == 'F')) {
1236 if (len == 4) {
1237 if (pszParmValue[3] == '8') {
1238 is_utf8 = true;
1240 } else {
1241 if (pszParmValue[3] == '-' &&
1242 pszParmValue[4] == '8') {
1243 is_utf8 = true;
1249 if (*ptr == NULL || strcmp(*ptr, pszParmValue) != 0) {
1250 struct smb_iconv_handle *ret = NULL;
1251 if (is_utf8) {
1252 DEBUG(0,("ERROR: invalid DOS charset: 'dos charset' must not "
1253 "be UTF8, using (default value) %s instead.\n",
1254 DEFAULT_DOS_CHARSET));
1255 pszParmValue = DEFAULT_DOS_CHARSET;
1257 ret = reinit_iconv_handle(NULL,
1258 lpcfg_dos_charset(lp_ctx),
1259 lpcfg_unix_charset(lp_ctx));
1260 if (ret == NULL) {
1261 smb_panic("reinit_iconv_handle failed");
1266 return lpcfg_string_set(lp_ctx->globals->ctx, ptr, pszParmValue);
1269 bool handle_printing(struct loadparm_context *lp_ctx, struct loadparm_service *service,
1270 const char *pszParmValue, char **ptr)
1272 static int parm_num = -1;
1274 if (parm_num == -1) {
1275 parm_num = lpcfg_map_parameter("printing");
1276 if (parm_num == -1) {
1277 return false;
1281 if (!lp_set_enum_parm(&parm_table[parm_num], pszParmValue, (int*)ptr)) {
1282 return false;
1285 if (lp_ctx->s3_fns) {
1286 if (service == NULL) {
1287 init_printer_values(lp_ctx, lp_ctx->globals->ctx, lp_ctx->sDefault);
1288 } else {
1289 init_printer_values(lp_ctx, service, service);
1293 return true;
1296 bool handle_ldap_debug_level(struct loadparm_context *lp_ctx, struct loadparm_service *service,
1297 const char *pszParmValue, char **ptr)
1299 lp_ctx->globals->ldap_debug_level = lp_int(pszParmValue);
1301 if (lp_ctx->s3_fns) {
1302 lp_ctx->s3_fns->init_ldap_debugging();
1304 return true;
1308 * idmap related parameters
1311 bool handle_idmap_backend(struct loadparm_context *lp_ctx, struct loadparm_service *service,
1312 const char *pszParmValue, char **ptr)
1314 if (lp_ctx->s3_fns) {
1315 lp_do_parameter_parametric(lp_ctx, service, "idmap config * : backend",
1316 pszParmValue, 0);
1319 return lpcfg_string_set(lp_ctx->globals->ctx, ptr, pszParmValue);
1322 bool handle_idmap_uid(struct loadparm_context *lp_ctx, struct loadparm_service *service,
1323 const char *pszParmValue, char **ptr)
1325 if (lp_ctx->s3_fns) {
1326 lp_do_parameter_parametric(lp_ctx, service, "idmap config * : range",
1327 pszParmValue, 0);
1330 return lpcfg_string_set(lp_ctx->globals->ctx, ptr, pszParmValue);
1333 bool handle_idmap_gid(struct loadparm_context *lp_ctx, struct loadparm_service *service,
1334 const char *pszParmValue, char **ptr)
1336 if (lp_ctx->s3_fns) {
1337 lp_do_parameter_parametric(lp_ctx, service, "idmap config * : range",
1338 pszParmValue, 0);
1341 return lpcfg_string_set(lp_ctx->globals->ctx, ptr, pszParmValue);
1344 bool handle_smb_ports(struct loadparm_context *lp_ctx, struct loadparm_service *service,
1345 const char *pszParmValue, char **ptr)
1347 static int parm_num = -1;
1348 int i;
1349 const char **list;
1351 if (!pszParmValue || !*pszParmValue) {
1352 return false;
1355 if (parm_num == -1) {
1356 parm_num = lpcfg_map_parameter("smb ports");
1357 if (parm_num == -1) {
1358 return false;
1362 if (!set_variable_helper(lp_ctx->globals->ctx, parm_num, ptr, "smb ports",
1363 pszParmValue)) {
1364 return false;
1367 list = lp_ctx->globals->smb_ports;
1368 if (list == NULL) {
1369 return false;
1372 /* Check that each port is a valid integer and within range */
1373 for (i = 0; list[i] != NULL; i++) {
1374 char *end = NULL;
1375 int port = 0;
1376 port = strtol(list[i], &end, 10);
1377 if (*end != '\0' || port <= 0 || port > 65535) {
1378 TALLOC_FREE(list);
1379 return false;
1383 return true;
1386 bool handle_rpc_server_dynamic_port_range(struct loadparm_context *lp_ctx,
1387 struct loadparm_service *service,
1388 const char *pszParmValue,
1389 char **ptr)
1391 static int parm_num = -1;
1392 int low_port = -1, high_port = -1;
1393 int rc;
1395 if (parm_num == -1) {
1396 parm_num = lpcfg_map_parameter("rpc server dynamic port range");
1397 if (parm_num == -1) {
1398 return false;
1402 if (pszParmValue == NULL || pszParmValue[0] == '\0') {
1403 return false;
1406 rc = sscanf(pszParmValue, "%d - %d", &low_port, &high_port);
1407 if (rc != 2) {
1408 return false;
1411 if (low_port > high_port) {
1412 return false;
1415 if (low_port < SERVER_TCP_PORT_MIN|| high_port > SERVER_TCP_PORT_MAX) {
1416 return false;
1419 if (!set_variable_helper(lp_ctx->globals->ctx, parm_num, ptr,
1420 "rpc server dynamic port range",
1421 pszParmValue)) {
1422 return false;
1425 lp_ctx->globals->rpc_low_port = low_port;
1426 lp_ctx->globals->rpc_high_port = high_port;
1428 return true;
1431 bool handle_smb2_max_credits(struct loadparm_context *lp_ctx,
1432 struct loadparm_service *service,
1433 const char *pszParmValue, char **ptr)
1435 int value = lp_int(pszParmValue);
1437 if (value <= 0) {
1438 value = DEFAULT_SMB2_MAX_CREDITS;
1441 *(int *)ptr = value;
1443 return true;
1446 bool handle_cups_encrypt(struct loadparm_context *lp_ctx,
1447 struct loadparm_service *service,
1448 const char *pszParmValue, char **ptr)
1450 int result = 0;
1451 #ifdef HAVE_HTTPCONNECTENCRYPT
1452 int value = lp_int(pszParmValue);
1454 switch (value) {
1455 case Auto:
1456 result = HTTP_ENCRYPT_REQUIRED;
1457 break;
1458 case true:
1459 result = HTTP_ENCRYPT_ALWAYS;
1460 break;
1461 case false:
1462 result = HTTP_ENCRYPT_NEVER;
1463 break;
1464 default:
1465 result = 0;
1466 break;
1468 #endif
1469 *(int *)ptr = result;
1471 return true;
1474 /***************************************************************************
1475 Initialise a copymap.
1476 ***************************************************************************/
1479 * Initializes service copymap
1480 * Note: pservice *must* be valid TALLOC_CTX
1482 void init_copymap(struct loadparm_service *pservice)
1484 int i;
1486 TALLOC_FREE(pservice->copymap);
1488 pservice->copymap = bitmap_talloc(pservice, num_parameters());
1489 if (!pservice->copymap) {
1490 DEBUG(0,
1491 ("Couldn't allocate copymap!! (size %d)\n",
1492 (int)num_parameters()));
1493 } else {
1494 for (i = 0; i < num_parameters(); i++) {
1495 bitmap_set(pservice->copymap, i);
1501 * Process a parametric option
1503 static bool lp_do_parameter_parametric(struct loadparm_context *lp_ctx,
1504 struct loadparm_service *service,
1505 const char *pszParmName,
1506 const char *pszParmValue, int flags)
1508 struct parmlist_entry **data;
1509 char *name;
1510 TALLOC_CTX *mem_ctx;
1512 while (isspace((unsigned char)*pszParmName)) {
1513 pszParmName++;
1516 name = strlower_talloc(lp_ctx, pszParmName);
1517 if (!name) return false;
1519 if (service == NULL) {
1520 data = &lp_ctx->globals->param_opt;
1522 * s3 code cannot deal with parametric options stored on the globals ctx.
1524 if (lp_ctx->s3_fns != NULL) {
1525 mem_ctx = NULL;
1526 } else {
1527 mem_ctx = lp_ctx->globals->ctx;
1529 } else {
1530 data = &service->param_opt;
1531 mem_ctx = service;
1534 set_param_opt(mem_ctx, data, name, pszParmValue, flags);
1536 talloc_free(name);
1538 return true;
1541 static bool set_variable_helper(TALLOC_CTX *mem_ctx, int parmnum, void *parm_ptr,
1542 const char *pszParmName, const char *pszParmValue)
1544 size_t i;
1546 /* switch on the type of variable it is */
1547 switch (parm_table[parmnum].type)
1549 case P_BOOL: {
1550 bool b;
1551 if (!set_boolean(pszParmValue, &b)) {
1552 DEBUG(0, ("set_variable_helper(%s): value is not "
1553 "boolean!\n", pszParmValue));
1554 return false;
1556 *(bool *)parm_ptr = b;
1558 break;
1560 case P_BOOLREV: {
1561 bool b;
1562 if (!set_boolean(pszParmValue, &b)) {
1563 DEBUG(0, ("set_variable_helper(%s): value is not "
1564 "boolean!\n", pszParmValue));
1565 return false;
1567 *(bool *)parm_ptr = !b;
1569 break;
1571 case P_INTEGER:
1572 *(int *)parm_ptr = lp_int(pszParmValue);
1573 break;
1575 case P_CHAR:
1576 *(char *)parm_ptr = *pszParmValue;
1577 break;
1579 case P_OCTAL:
1580 i = sscanf(pszParmValue, "%o", (int *)parm_ptr);
1581 if ( i != 1 ) {
1582 DEBUG ( 0, ("Invalid octal number %s\n", pszParmName ));
1583 return false;
1585 break;
1587 case P_BYTES:
1589 uint64_t val;
1590 if (conv_str_size_error(pszParmValue, &val)) {
1591 if (val <= INT_MAX) {
1592 *(int *)parm_ptr = (int)val;
1593 break;
1597 DEBUG(0, ("set_variable_helper(%s): value is not "
1598 "a valid size specifier!\n", pszParmValue));
1599 return false;
1602 case P_CMDLIST:
1603 TALLOC_FREE(*(char ***)parm_ptr);
1604 *(char ***)parm_ptr = str_list_make_v3(mem_ctx,
1605 pszParmValue, NULL);
1606 break;
1608 case P_LIST:
1610 char **new_list = str_list_make_v3(mem_ctx,
1611 pszParmValue, NULL);
1612 if (new_list == NULL) {
1613 break;
1616 for (i=0; new_list[i]; i++) {
1617 if (*(const char ***)parm_ptr != NULL &&
1618 new_list[i][0] == '+' &&
1619 new_list[i][1])
1621 if (!str_list_check(*(const char ***)parm_ptr,
1622 &new_list[i][1])) {
1623 *(const char ***)parm_ptr = str_list_add(*(const char ***)parm_ptr,
1624 &new_list[i][1]);
1626 } else if (*(const char ***)parm_ptr != NULL &&
1627 new_list[i][0] == '-' &&
1628 new_list[i][1])
1630 str_list_remove(*(const char ***)parm_ptr,
1631 &new_list[i][1]);
1632 } else {
1633 if (i != 0) {
1634 DEBUG(0, ("Unsupported list syntax for: %s = %s\n",
1635 pszParmName, pszParmValue));
1636 return false;
1638 *(char ***)parm_ptr = new_list;
1639 break;
1642 break;
1645 case P_STRING:
1646 lpcfg_string_set(mem_ctx, (char **)parm_ptr, pszParmValue);
1647 break;
1649 case P_USTRING:
1650 lpcfg_string_set_upper(mem_ctx, (char **)parm_ptr, pszParmValue);
1651 break;
1653 case P_ENUM:
1654 if (!lp_set_enum_parm(&parm_table[parmnum], pszParmValue, (int*)parm_ptr)) {
1655 return false;
1657 break;
1661 return true;
1665 bool handle_name_resolve_order(struct loadparm_context *lp_ctx,
1666 struct loadparm_service *service,
1667 const char *pszParmValue, char **ptr)
1669 const char **valid_values = NULL;
1670 const char **values_to_set = NULL;
1671 int i;
1672 bool value_is_valid = false;
1673 valid_values = str_list_make_v3_const(NULL,
1674 DEFAULT_NAME_RESOLVE_ORDER,
1675 NULL);
1676 if (valid_values == NULL) {
1677 DBG_ERR("OOM: failed to make string list from %s\n",
1678 DEFAULT_NAME_RESOLVE_ORDER);
1679 goto out;
1681 values_to_set = str_list_make_v3_const(lp_ctx->globals->ctx,
1682 pszParmValue,
1683 NULL);
1684 if (values_to_set == NULL) {
1685 DBG_ERR("OOM: failed to make string list from %s\n",
1686 pszParmValue);
1687 goto out;
1689 TALLOC_FREE(lp_ctx->globals->name_resolve_order);
1690 for (i = 0; values_to_set[i] != NULL; i++) {
1691 value_is_valid = str_list_check(valid_values, values_to_set[i]);
1692 if (!value_is_valid) {
1693 DBG_ERR("WARNING: Ignoring invalid list value '%s' "
1694 "for parameter 'name resolve order'\n",
1695 values_to_set[i]);
1696 break;
1699 out:
1700 if (value_is_valid) {
1701 lp_ctx->globals->name_resolve_order = values_to_set;
1702 } else {
1703 TALLOC_FREE(values_to_set);
1705 TALLOC_FREE(valid_values);
1706 return value_is_valid;
1709 bool handle_kdc_default_domain_supported_enctypes(struct loadparm_context *lp_ctx,
1710 struct loadparm_service *service,
1711 const char *pszParmValue, char **ptr)
1713 char **enctype_list = NULL;
1714 char **enctype = NULL;
1715 uint32_t result = 0;
1716 bool ok = true;
1718 enctype_list = str_list_make(NULL, pszParmValue, NULL);
1719 if (enctype_list == NULL) {
1720 DBG_ERR("OOM: failed to make string list from %s\n",
1721 pszParmValue);
1722 ok = false;
1723 goto out;
1726 for (enctype = enctype_list; *enctype != NULL; ++enctype) {
1727 if (strwicmp(*enctype, "arcfour-hmac-md5") == 0 ||
1728 strwicmp(*enctype, "rc4-hmac") == 0)
1730 result |= KERB_ENCTYPE_RC4_HMAC_MD5;
1732 else if (strwicmp(*enctype, "aes128-cts-hmac-sha1-96") == 0 ||
1733 strwicmp(*enctype, "aes128-cts") == 0)
1735 result |= KERB_ENCTYPE_AES128_CTS_HMAC_SHA1_96;
1737 else if (strwicmp(*enctype, "aes256-cts-hmac-sha1-96") == 0 ||
1738 strwicmp(*enctype, "aes256-cts") == 0)
1740 result |= KERB_ENCTYPE_AES256_CTS_HMAC_SHA1_96;
1742 else if (strwicmp(*enctype, "aes256-cts-hmac-sha1-96-sk") == 0 ||
1743 strwicmp(*enctype, "aes256-cts-sk") == 0)
1745 result |= KERB_ENCTYPE_AES256_CTS_HMAC_SHA1_96_SK;
1747 else {
1748 const char *bitstr = *enctype;
1749 int base;
1750 int error;
1751 unsigned long bit;
1753 /* See if the bit's specified in hexadecimal. */
1754 if (bitstr[0] == '0' &&
1755 (bitstr[1] == 'x' || bitstr[2] == 'X'))
1757 base = 16;
1758 bitstr += 2;
1760 else {
1761 base = 10;
1764 bit = smb_strtoul(bitstr, NULL, base, &error, SMB_STR_FULL_STR_CONV);
1765 if (error) {
1766 DBG_ERR("WARNING: Ignoring invalid value '%s' "
1767 "for parameter 'kdc default domain supported enctypes'\n",
1768 *enctype);
1769 ok = false;
1770 } else {
1771 result |= bit;
1776 *(int *)ptr = result;
1777 out:
1778 TALLOC_FREE(enctype_list);
1780 return ok;
1783 bool handle_kdc_supported_enctypes(struct loadparm_context *lp_ctx,
1784 struct loadparm_service *service,
1785 const char *pszParmValue, char **ptr)
1787 char **enctype_list = NULL;
1788 char **enctype = NULL;
1789 uint32_t result = 0;
1790 bool ok = true;
1792 enctype_list = str_list_make(NULL, pszParmValue, NULL);
1793 if (enctype_list == NULL) {
1794 DBG_ERR("OOM: failed to make string list from %s\n",
1795 pszParmValue);
1796 ok = false;
1797 goto out;
1800 for (enctype = enctype_list; *enctype != NULL; ++enctype) {
1801 if (strwicmp(*enctype, "arcfour-hmac-md5") == 0 ||
1802 strwicmp(*enctype, "rc4-hmac") == 0)
1804 result |= KERB_ENCTYPE_RC4_HMAC_MD5;
1806 else if (strwicmp(*enctype, "aes128-cts-hmac-sha1-96") == 0 ||
1807 strwicmp(*enctype, "aes128-cts") == 0)
1809 result |= KERB_ENCTYPE_AES128_CTS_HMAC_SHA1_96;
1811 else if (strwicmp(*enctype, "aes256-cts-hmac-sha1-96") == 0 ||
1812 strwicmp(*enctype, "aes256-cts") == 0)
1814 result |= KERB_ENCTYPE_AES256_CTS_HMAC_SHA1_96;
1816 else {
1817 const char *bitstr = *enctype;
1818 int base;
1819 int error;
1820 unsigned long bit;
1822 /* See if the bit's specified in hexadecimal. */
1823 if (bitstr[0] == '0' &&
1824 (bitstr[1] == 'x' || bitstr[2] == 'X'))
1826 base = 16;
1827 bitstr += 2;
1829 else {
1830 base = 10;
1833 bit = smb_strtoul(bitstr, NULL, base, &error, SMB_STR_FULL_STR_CONV);
1834 if (error) {
1835 DBG_ERR("WARNING: Ignoring invalid value '%s' "
1836 "for parameter 'kdc default domain supported enctypes'\n",
1837 *enctype);
1838 ok = false;
1839 } else {
1840 result |= bit;
1845 *(int *)ptr = result;
1846 out:
1847 TALLOC_FREE(enctype_list);
1849 return ok;
1852 static bool set_variable(TALLOC_CTX *mem_ctx, struct loadparm_service *service,
1853 int parmnum, void *parm_ptr,
1854 const char *pszParmName, const char *pszParmValue,
1855 struct loadparm_context *lp_ctx, bool on_globals)
1857 int i;
1858 bool ok;
1860 /* if it is a special case then go ahead */
1861 if (parm_table[parmnum].special) {
1862 ok = parm_table[parmnum].special(lp_ctx, service, pszParmValue,
1863 (char **)parm_ptr);
1864 } else {
1865 ok = set_variable_helper(mem_ctx, parmnum, parm_ptr,
1866 pszParmName, pszParmValue);
1869 if (!ok) {
1870 return false;
1873 if (on_globals && (lp_ctx->flags[parmnum] & FLAG_DEFAULT)) {
1874 lp_ctx->flags[parmnum] &= ~FLAG_DEFAULT;
1875 /* we have to also unset FLAG_DEFAULT on aliases */
1876 for (i=parmnum-1;i>=0 && parm_table[i].offset == parm_table[parmnum].offset;i--) {
1877 lp_ctx->flags[i] &= ~FLAG_DEFAULT;
1879 for (i=parmnum+1;i<num_parameters() && parm_table[i].offset == parm_table[parmnum].offset;i++) {
1880 lp_ctx->flags[i] &= ~FLAG_DEFAULT;
1883 return true;
1887 bool lpcfg_do_global_parameter(struct loadparm_context *lp_ctx,
1888 const char *pszParmName, const char *pszParmValue)
1890 int parmnum = lpcfg_map_parameter(pszParmName);
1891 void *parm_ptr;
1893 if (parmnum < 0) {
1894 if (strchr(pszParmName, ':')) {
1895 return lp_do_parameter_parametric(lp_ctx, NULL, pszParmName, pszParmValue, 0);
1897 DEBUG(0, ("Ignoring unknown parameter \"%s\"\n", pszParmName));
1898 return true;
1901 /* if the flag has been set on the command line, then don't allow override,
1902 but don't report an error */
1903 if (lp_ctx->flags[parmnum] & FLAG_CMDLINE) {
1904 return true;
1907 if (parm_table[parmnum].flags & FLAG_DEPRECATED) {
1908 char *suppress_env = getenv("SAMBA_DEPRECATED_SUPPRESS");
1909 bool print_warning = (suppress_env == NULL
1910 || suppress_env[0] == '\0');
1911 if (print_warning) {
1912 DBG_WARNING("WARNING: The \"%s\" option "
1913 "is deprecated\n",
1914 pszParmName);
1919 parm_ptr = lpcfg_parm_ptr(lp_ctx, NULL, &parm_table[parmnum]);
1921 return set_variable(lp_ctx->globals->ctx, NULL, parmnum, parm_ptr,
1922 pszParmName, pszParmValue, lp_ctx, true);
1925 bool lpcfg_do_service_parameter(struct loadparm_context *lp_ctx,
1926 struct loadparm_service *service,
1927 const char *pszParmName, const char *pszParmValue)
1929 void *parm_ptr;
1930 int i;
1931 int parmnum = lpcfg_map_parameter(pszParmName);
1933 if (parmnum < 0) {
1934 if (strchr(pszParmName, ':')) {
1935 return lp_do_parameter_parametric(lp_ctx, service, pszParmName, pszParmValue, 0);
1937 DEBUG(0, ("Ignoring unknown parameter \"%s\"\n", pszParmName));
1938 return true;
1941 /* if the flag has been set on the command line, then don't allow override,
1942 but don't report an error */
1943 if (lp_ctx->flags[parmnum] & FLAG_CMDLINE) {
1944 return true;
1947 if (parm_table[parmnum].flags & FLAG_DEPRECATED) {
1948 char *suppress_env = getenv("SAMBA_DEPRECATED_SUPPRESS");
1949 bool print_warning = (suppress_env == NULL
1950 || suppress_env[0] == '\0');
1951 if (print_warning) {
1952 DBG_WARNING("WARNING: The \"%s\" option "
1953 "is deprecated\n",
1954 pszParmName);
1959 if (parm_table[parmnum].p_class == P_GLOBAL) {
1960 DEBUG(0,
1961 ("Global parameter %s found in service section!\n",
1962 pszParmName));
1963 return true;
1965 parm_ptr = ((char *)service) + parm_table[parmnum].offset;
1967 if (!service->copymap)
1968 init_copymap(service);
1970 /* this handles the aliases - set the copymap for other
1971 * entries with the same data pointer */
1972 for (i = 0; parm_table[i].label; i++)
1973 if (parm_table[i].offset == parm_table[parmnum].offset &&
1974 parm_table[i].p_class == parm_table[parmnum].p_class)
1975 bitmap_clear(service->copymap, i);
1977 return set_variable(service, service, parmnum, parm_ptr, pszParmName,
1978 pszParmValue, lp_ctx, false);
1982 * Process a parameter.
1985 bool lpcfg_do_parameter(const char *pszParmName, const char *pszParmValue,
1986 void *userdata)
1988 struct loadparm_context *lp_ctx = (struct loadparm_context *)userdata;
1990 if (lp_ctx->bInGlobalSection)
1991 return lpcfg_do_global_parameter(lp_ctx, pszParmName,
1992 pszParmValue);
1993 else
1994 return lpcfg_do_service_parameter(lp_ctx, lp_ctx->currentService,
1995 pszParmName, pszParmValue);
1999 variable argument do parameter
2001 bool lpcfg_do_global_parameter_var(struct loadparm_context *lp_ctx, const char *pszParmName, const char *fmt, ...) PRINTF_ATTRIBUTE(3, 4);
2002 bool lpcfg_do_global_parameter_var(struct loadparm_context *lp_ctx,
2003 const char *pszParmName, const char *fmt, ...)
2005 char *s;
2006 bool ret;
2007 va_list ap;
2009 va_start(ap, fmt);
2010 s = talloc_vasprintf(NULL, fmt, ap);
2011 va_end(ap);
2012 ret = lpcfg_do_global_parameter(lp_ctx, pszParmName, s);
2013 talloc_free(s);
2014 return ret;
2019 set a parameter from the commandline - this is called from command line parameter
2020 parsing code. It sets the parameter then marks the parameter as unable to be modified
2021 by smb.conf processing
2023 bool lpcfg_set_cmdline(struct loadparm_context *lp_ctx, const char *pszParmName,
2024 const char *pszParmValue)
2026 int parmnum;
2027 int i;
2029 while (isspace((unsigned char)*pszParmValue)) pszParmValue++;
2031 parmnum = lpcfg_map_parameter(pszParmName);
2033 if (parmnum < 0 && strchr(pszParmName, ':')) {
2034 /* set a parametric option */
2035 bool ok;
2036 ok = lp_do_parameter_parametric(lp_ctx, NULL, pszParmName,
2037 pszParmValue, FLAG_CMDLINE);
2038 if (lp_ctx->s3_fns != NULL) {
2039 if (ok) {
2040 lp_ctx->s3_fns->store_cmdline(pszParmName, pszParmValue);
2043 return ok;
2046 if (parmnum < 0) {
2047 DEBUG(0,("Unknown option '%s'\n", pszParmName));
2048 return false;
2051 /* reset the CMDLINE flag in case this has been called before */
2052 lp_ctx->flags[parmnum] &= ~FLAG_CMDLINE;
2054 if (!lpcfg_do_global_parameter(lp_ctx, pszParmName, pszParmValue)) {
2055 return false;
2058 lp_ctx->flags[parmnum] |= FLAG_CMDLINE;
2060 /* we have to also set FLAG_CMDLINE on aliases */
2061 for (i=parmnum-1;
2062 i>=0 && parm_table[i].p_class == parm_table[parmnum].p_class &&
2063 parm_table[i].offset == parm_table[parmnum].offset;
2064 i--) {
2065 lp_ctx->flags[i] |= FLAG_CMDLINE;
2067 for (i=parmnum+1;
2068 i<num_parameters() &&
2069 parm_table[i].p_class == parm_table[parmnum].p_class &&
2070 parm_table[i].offset == parm_table[parmnum].offset;
2071 i++) {
2072 lp_ctx->flags[i] |= FLAG_CMDLINE;
2075 if (lp_ctx->s3_fns != NULL) {
2076 lp_ctx->s3_fns->store_cmdline(pszParmName, pszParmValue);
2079 return true;
2083 set a option from the commandline in 'a=b' format. Use to support --option
2085 bool lpcfg_set_option(struct loadparm_context *lp_ctx, const char *option)
2087 char *p, *s;
2088 bool ret;
2090 s = talloc_strdup(NULL, option);
2091 if (!s) {
2092 return false;
2095 p = strchr(s, '=');
2096 if (!p) {
2097 talloc_free(s);
2098 return false;
2101 *p = 0;
2103 ret = lpcfg_set_cmdline(lp_ctx, s, p+1);
2104 talloc_free(s);
2105 return ret;
2109 #define BOOLSTR(b) ((b) ? "Yes" : "No")
2112 * Print a parameter of the specified type.
2115 void lpcfg_print_parameter(struct parm_struct *p, void *ptr, FILE * f)
2117 /* For the separation of lists values that we print below */
2118 const char *list_sep = ", ";
2119 int i;
2120 switch (p->type)
2122 case P_ENUM:
2123 for (i = 0; p->enum_list[i].name; i++) {
2124 if (*(int *)ptr == p->enum_list[i].value) {
2125 fprintf(f, "%s",
2126 p->enum_list[i].name);
2127 break;
2130 break;
2132 case P_BOOL:
2133 fprintf(f, "%s", BOOLSTR(*(bool *)ptr));
2134 break;
2136 case P_BOOLREV:
2137 fprintf(f, "%s", BOOLSTR(!*(bool *)ptr));
2138 break;
2140 case P_INTEGER:
2141 case P_BYTES:
2142 fprintf(f, "%d", *(int *)ptr);
2143 break;
2145 case P_CHAR:
2146 fprintf(f, "%c", *(char *)ptr);
2147 break;
2149 case P_OCTAL: {
2150 int val = *(int *)ptr;
2151 if (val == -1) {
2152 fprintf(f, "-1");
2153 } else {
2154 fprintf(f, "0%03o", val);
2156 break;
2159 case P_CMDLIST:
2160 list_sep = " ";
2162 FALL_THROUGH;
2163 case P_LIST:
2164 if ((char ***)ptr && *(char ***)ptr) {
2165 char **list = *(char ***)ptr;
2166 for (; *list; list++) {
2167 /* surround strings with whitespace in double quotes */
2168 if (*(list+1) == NULL) {
2169 /* last item, no extra separator */
2170 list_sep = "";
2172 if ( strchr_m( *list, ' ' ) ) {
2173 fprintf(f, "\"%s\"%s", *list, list_sep);
2174 } else {
2175 fprintf(f, "%s%s", *list, list_sep);
2179 break;
2181 case P_STRING:
2182 case P_USTRING:
2183 if (*(char **)ptr) {
2184 fprintf(f, "%s", *(char **)ptr);
2186 break;
2191 * Check if two parameters are equal.
2194 static bool lpcfg_equal_parameter(parm_type type, void *ptr1, void *ptr2)
2196 switch (type) {
2197 case P_BOOL:
2198 case P_BOOLREV:
2199 return (*((bool *)ptr1) == *((bool *)ptr2));
2201 case P_INTEGER:
2202 case P_ENUM:
2203 case P_OCTAL:
2204 case P_BYTES:
2205 return (*((int *)ptr1) == *((int *)ptr2));
2207 case P_CHAR:
2208 return (*((char *)ptr1) == *((char *)ptr2));
2210 case P_LIST:
2211 case P_CMDLIST:
2212 return str_list_equal(*(const char ***)ptr1, *(const char ***)ptr2);
2214 case P_STRING:
2215 case P_USTRING:
2217 char *p1 = *(char **)ptr1, *p2 = *(char **)ptr2;
2218 if (p1 && !*p1)
2219 p1 = NULL;
2220 if (p2 && !*p2)
2221 p2 = NULL;
2222 return (p1 == p2 || strequal(p1, p2));
2225 return false;
2229 * Process a new section (service).
2231 * At this stage all sections are services.
2232 * Later we'll have special sections that permit server parameters to be set.
2233 * Returns True on success, False on failure.
2236 static bool do_section(const char *pszSectionName, void *userdata)
2238 struct loadparm_context *lp_ctx = (struct loadparm_context *)userdata;
2239 bool bRetval;
2240 bool isglobal;
2242 if (lp_ctx->s3_fns != NULL) {
2243 return lp_ctx->s3_fns->do_section(pszSectionName, lp_ctx);
2246 isglobal = ((strwicmp(pszSectionName, GLOBAL_NAME) == 0) ||
2247 (strwicmp(pszSectionName, GLOBAL_NAME2) == 0));
2249 /* if we've just struck a global section, note the fact. */
2250 lp_ctx->bInGlobalSection = isglobal;
2252 /* check for multiple global sections */
2253 if (lp_ctx->bInGlobalSection) {
2254 DEBUG(4, ("Processing section \"[%s]\"\n", pszSectionName));
2255 bRetval = true;
2256 goto out;
2259 /* if we have a current service, tidy it up before moving on */
2260 bRetval = true;
2262 if (lp_ctx->currentService != NULL)
2263 bRetval = lpcfg_service_ok(lp_ctx->currentService);
2265 /* if all is still well, move to the next record in the services array */
2266 if (bRetval) {
2267 /* We put this here to avoid an odd message order if messages are */
2268 /* issued by the post-processing of a previous section. */
2269 DEBUG(4, ("Processing section \"[%s]\"\n", pszSectionName));
2271 if ((lp_ctx->currentService = lpcfg_add_service(lp_ctx, lp_ctx->sDefault,
2272 pszSectionName))
2273 == NULL) {
2274 DEBUG(0, ("Failed to add a new service\n"));
2275 bRetval = false;
2276 goto out;
2279 out:
2280 return bRetval;
2285 * Determine if a particular base parameter is currently set to the default value.
2288 static bool is_default(void *base_structure, int i)
2290 void *def_ptr = ((char *)base_structure) + parm_table[i].offset;
2291 switch (parm_table[i].type) {
2292 case P_CMDLIST:
2293 case P_LIST:
2294 return str_list_equal((const char * const *)parm_table[i].def.lvalue,
2295 *(const char * const **)def_ptr);
2296 case P_STRING:
2297 case P_USTRING:
2298 return strequal(parm_table[i].def.svalue,
2299 *(char **)def_ptr);
2300 case P_BOOL:
2301 case P_BOOLREV:
2302 return parm_table[i].def.bvalue ==
2303 *(bool *)def_ptr;
2304 case P_INTEGER:
2305 case P_CHAR:
2306 case P_OCTAL:
2307 case P_BYTES:
2308 case P_ENUM:
2309 return parm_table[i].def.ivalue ==
2310 *(int *)def_ptr;
2312 return false;
2316 *Display the contents of the global structure.
2319 void lpcfg_dump_globals(struct loadparm_context *lp_ctx, FILE *f,
2320 bool show_defaults)
2322 int i;
2323 struct parmlist_entry *data;
2325 fprintf(f, "# Global parameters\n[global]\n");
2327 for (i = 0; parm_table[i].label; i++) {
2328 if (parm_table[i].p_class != P_GLOBAL) {
2329 continue;
2332 if (parm_table[i].flags & FLAG_SYNONYM) {
2333 continue;
2336 if (!show_defaults) {
2337 if (lp_ctx->flags && (lp_ctx->flags[i] & FLAG_DEFAULT)) {
2338 continue;
2341 if (is_default(lp_ctx->globals, i)) {
2342 continue;
2346 fprintf(f, "\t%s = ", parm_table[i].label);
2347 lpcfg_print_parameter(&parm_table[i], lpcfg_parm_ptr(lp_ctx, NULL, &parm_table[i]), f);
2348 fprintf(f, "\n");
2350 if (lp_ctx->globals->param_opt != NULL) {
2351 for (data = lp_ctx->globals->param_opt; data;
2352 data = data->next) {
2353 if (!show_defaults && (data->priority & FLAG_DEFAULT)) {
2354 continue;
2356 fprintf(f, "\t%s = %s\n", data->key, data->value);
2363 * Display the contents of a single services record.
2366 void lpcfg_dump_a_service(struct loadparm_service * pService, struct loadparm_service *sDefault, FILE * f,
2367 unsigned int *flags, bool show_defaults)
2369 int i;
2370 struct parmlist_entry *data;
2372 if (pService != sDefault)
2373 fprintf(f, "\n[%s]\n", pService->szService);
2375 for (i = 0; parm_table[i].label; i++) {
2376 if (parm_table[i].p_class != P_LOCAL) {
2377 continue;
2380 if (parm_table[i].flags & FLAG_SYNONYM) {
2381 continue;
2384 if (*parm_table[i].label == '-') {
2385 continue;
2388 if (pService == sDefault) {
2389 if (!show_defaults) {
2390 if (flags && (flags[i] & FLAG_DEFAULT)) {
2391 continue;
2394 if (is_default(sDefault, i)) {
2395 continue;
2398 } else {
2399 bool equal;
2401 equal = lpcfg_equal_parameter(parm_table[i].type,
2402 ((char *)pService) +
2403 parm_table[i].offset,
2404 ((char *)sDefault) +
2405 parm_table[i].offset);
2406 if (equal) {
2407 continue;
2411 fprintf(f, "\t%s = ", parm_table[i].label);
2412 lpcfg_print_parameter(&parm_table[i],
2413 ((char *)pService) + parm_table[i].offset, f);
2414 fprintf(f, "\n");
2416 if (pService->param_opt != NULL) {
2417 for (data = pService->param_opt; data; data = data->next) {
2418 if (!show_defaults && (data->priority & FLAG_DEFAULT)) {
2419 continue;
2421 fprintf(f, "\t%s = %s\n", data->key, data->value);
2426 bool lpcfg_dump_a_parameter(struct loadparm_context *lp_ctx,
2427 struct loadparm_service *service,
2428 const char *parm_name, FILE * f)
2430 struct parm_struct *parm;
2431 void *ptr;
2432 char *local_parm_name;
2433 char *parm_opt;
2434 const char *parm_opt_value;
2436 /* check for parametrical option */
2437 local_parm_name = talloc_strdup(lp_ctx, parm_name);
2438 if (local_parm_name == NULL) {
2439 return false;
2442 parm_opt = strchr( local_parm_name, ':');
2444 if (parm_opt) {
2445 *parm_opt = '\0';
2446 parm_opt++;
2447 if (strlen(parm_opt)) {
2448 parm_opt_value = lpcfg_parm_string(lp_ctx, service,
2449 local_parm_name, parm_opt);
2450 if (parm_opt_value) {
2451 fprintf(f, "%s\n", parm_opt_value);
2452 TALLOC_FREE(local_parm_name);
2453 return true;
2456 TALLOC_FREE(local_parm_name);
2457 return false;
2459 TALLOC_FREE(local_parm_name);
2461 /* parameter is not parametric, search the table */
2462 parm = lpcfg_parm_struct(lp_ctx, parm_name);
2463 if (!parm) {
2464 return false;
2467 if (service != NULL && parm->p_class == P_GLOBAL) {
2468 return false;
2471 ptr = lpcfg_parm_ptr(lp_ctx, service,parm);
2473 lpcfg_print_parameter(parm, ptr, f);
2474 fprintf(f, "\n");
2475 return true;
2479 * Auto-load some home services.
2481 static void lpcfg_add_auto_services(struct loadparm_context *lp_ctx,
2482 const char *str)
2484 return;
2487 /***************************************************************************
2488 Initialise the sDefault parameter structure for the printer values.
2489 ***************************************************************************/
2491 void init_printer_values(struct loadparm_context *lp_ctx, TALLOC_CTX *ctx,
2492 struct loadparm_service *pService)
2494 /* choose defaults depending on the type of printing */
2495 switch (pService->printing) {
2496 case PRINT_BSD:
2497 case PRINT_AIX:
2498 case PRINT_LPRNT:
2499 case PRINT_LPROS2:
2500 lpcfg_string_set(ctx, &pService->lpq_command, "lpq -P'%p'");
2501 lpcfg_string_set(ctx, &pService->lprm_command, "lprm -P'%p' %j");
2502 lpcfg_string_set(ctx, &pService->print_command, "lpr -r -P'%p' %s");
2503 break;
2505 case PRINT_LPRNG:
2506 case PRINT_PLP:
2507 lpcfg_string_set(ctx, &pService->lpq_command, "lpq -P'%p'");
2508 lpcfg_string_set(ctx, &pService->lprm_command, "lprm -P'%p' %j");
2509 lpcfg_string_set(ctx, &pService->print_command, "lpr -r -P'%p' %s");
2510 lpcfg_string_set(ctx, &pService->queuepause_command, "lpc stop '%p'");
2511 lpcfg_string_set(ctx, &pService->queueresume_command, "lpc start '%p'");
2512 lpcfg_string_set(ctx, &pService->lppause_command, "lpc hold '%p' %j");
2513 lpcfg_string_set(ctx, &pService->lpresume_command, "lpc release '%p' %j");
2514 break;
2516 case PRINT_CUPS:
2517 case PRINT_IPRINT:
2518 /* set the lpq command to contain the destination printer
2519 name only. This is used by cups_queue_get() */
2520 lpcfg_string_set(ctx, &pService->lpq_command, "%p");
2521 lpcfg_string_set(ctx, &pService->lprm_command, "");
2522 lpcfg_string_set(ctx, &pService->print_command, "");
2523 lpcfg_string_set(ctx, &pService->lppause_command, "");
2524 lpcfg_string_set(ctx, &pService->lpresume_command, "");
2525 lpcfg_string_set(ctx, &pService->queuepause_command, "");
2526 lpcfg_string_set(ctx, &pService->queueresume_command, "");
2527 break;
2529 case PRINT_SYSV:
2530 case PRINT_HPUX:
2531 lpcfg_string_set(ctx, &pService->lpq_command, "lpstat -o%p");
2532 lpcfg_string_set(ctx, &pService->lprm_command, "cancel %p-%j");
2533 lpcfg_string_set(ctx, &pService->print_command, "lp -c -d%p %s; rm %s");
2534 lpcfg_string_set(ctx, &pService->queuepause_command, "disable %p");
2535 lpcfg_string_set(ctx, &pService->queueresume_command, "enable %p");
2536 #ifndef HPUX
2537 lpcfg_string_set(ctx, &pService->lppause_command, "lp -i %p-%j -H hold");
2538 lpcfg_string_set(ctx, &pService->lpresume_command, "lp -i %p-%j -H resume");
2539 #endif /* HPUX */
2540 break;
2542 case PRINT_QNX:
2543 lpcfg_string_set(ctx, &pService->lpq_command, "lpq -P%p");
2544 lpcfg_string_set(ctx, &pService->lprm_command, "lprm -P%p %j");
2545 lpcfg_string_set(ctx, &pService->print_command, "lp -r -P%p %s");
2546 break;
2548 #if defined(DEVELOPER) || defined(ENABLE_SELFTEST)
2550 case PRINT_TEST:
2551 case PRINT_VLP: {
2552 const char *tdbfile;
2553 TALLOC_CTX *tmp_ctx = talloc_new(ctx);
2554 const char *tmp;
2556 tmp = lpcfg_parm_string(lp_ctx, NULL, "vlp", "tdbfile");
2557 if (tmp == NULL) {
2558 tmp = "/tmp/vlp.tdb";
2561 tdbfile = talloc_asprintf(tmp_ctx, "tdbfile=%s", tmp);
2562 if (tdbfile == NULL) {
2563 tdbfile="tdbfile=/tmp/vlp.tdb";
2566 tmp = talloc_asprintf(tmp_ctx, "vlp %s print %%p %%s",
2567 tdbfile);
2568 lpcfg_string_set(ctx, &pService->print_command,
2569 tmp ? tmp : "vlp print %p %s");
2571 tmp = talloc_asprintf(tmp_ctx, "vlp %s lpq %%p",
2572 tdbfile);
2573 lpcfg_string_set(ctx, &pService->lpq_command,
2574 tmp ? tmp : "vlp lpq %p");
2576 tmp = talloc_asprintf(tmp_ctx, "vlp %s lprm %%p %%j",
2577 tdbfile);
2578 lpcfg_string_set(ctx, &pService->lprm_command,
2579 tmp ? tmp : "vlp lprm %p %j");
2581 tmp = talloc_asprintf(tmp_ctx, "vlp %s lppause %%p %%j",
2582 tdbfile);
2583 lpcfg_string_set(ctx, &pService->lppause_command,
2584 tmp ? tmp : "vlp lppause %p %j");
2586 tmp = talloc_asprintf(tmp_ctx, "vlp %s lpresume %%p %%j",
2587 tdbfile);
2588 lpcfg_string_set(ctx, &pService->lpresume_command,
2589 tmp ? tmp : "vlp lpresume %p %j");
2591 tmp = talloc_asprintf(tmp_ctx, "vlp %s queuepause %%p",
2592 tdbfile);
2593 lpcfg_string_set(ctx, &pService->queuepause_command,
2594 tmp ? tmp : "vlp queuepause %p");
2596 tmp = talloc_asprintf(tmp_ctx, "vlp %s queueresume %%p",
2597 tdbfile);
2598 lpcfg_string_set(ctx, &pService->queueresume_command,
2599 tmp ? tmp : "vlp queueresume %p");
2600 TALLOC_FREE(tmp_ctx);
2602 break;
2604 #endif /* DEVELOPER */
2610 static int lpcfg_destructor(struct loadparm_context *lp_ctx)
2612 struct parmlist_entry *data;
2614 if (lp_ctx->refuse_free) {
2615 /* someone is trying to free the
2616 global_loadparm_context.
2617 We can't allow that. */
2618 return -1;
2621 if (lp_ctx->globals->param_opt != NULL) {
2622 struct parmlist_entry *next;
2623 for (data = lp_ctx->globals->param_opt; data; data=next) {
2624 next = data->next;
2625 if (data->priority & FLAG_CMDLINE) continue;
2626 DLIST_REMOVE(lp_ctx->globals->param_opt, data);
2627 talloc_free(data);
2631 return 0;
2635 * Initialise the global parameter structure.
2637 * Note that most callers should use loadparm_init_global() instead
2639 struct loadparm_context *loadparm_init(TALLOC_CTX *mem_ctx)
2641 int i;
2642 char *myname;
2643 struct loadparm_context *lp_ctx;
2644 struct parmlist_entry *parm;
2645 char *logfile;
2647 lp_ctx = talloc_zero(mem_ctx, struct loadparm_context);
2648 if (lp_ctx == NULL)
2649 return NULL;
2651 talloc_set_destructor(lp_ctx, lpcfg_destructor);
2652 lp_ctx->bInGlobalSection = true;
2653 lp_ctx->globals = talloc_zero(lp_ctx, struct loadparm_global);
2654 /* This appears odd, but globals in s3 isn't a pointer */
2655 lp_ctx->globals->ctx = lp_ctx->globals;
2656 lp_ctx->globals->rpc_low_port = SERVER_TCP_LOW_PORT;
2657 lp_ctx->globals->rpc_high_port = SERVER_TCP_HIGH_PORT;
2658 lp_ctx->globals->weak_crypto = SAMBA_WEAK_CRYPTO_UNKNOWN;
2659 lp_ctx->sDefault = talloc_zero(lp_ctx, struct loadparm_service);
2660 lp_ctx->flags = talloc_zero_array(lp_ctx, unsigned int, num_parameters());
2662 lp_ctx->sDefault->max_print_jobs = 1000;
2663 lp_ctx->sDefault->available = true;
2664 lp_ctx->sDefault->browseable = true;
2665 lp_ctx->sDefault->read_only = true;
2666 lp_ctx->sDefault->map_archive = true;
2667 lp_ctx->sDefault->strict_locking = true;
2668 lp_ctx->sDefault->oplocks = true;
2669 lp_ctx->sDefault->create_mask = 0744;
2670 lp_ctx->sDefault->force_create_mode = 0000;
2671 lp_ctx->sDefault->directory_mask = 0755;
2672 lp_ctx->sDefault->force_directory_mode = 0000;
2673 lp_ctx->sDefault->aio_read_size = 1;
2674 lp_ctx->sDefault->aio_write_size = 1;
2675 lp_ctx->sDefault->smbd_search_ask_sharemode = true;
2676 lp_ctx->sDefault->smbd_getinfo_ask_sharemode = true;
2677 lp_ctx->sDefault->volume_serial_number = -1;
2679 DEBUG(3, ("Initialising global parameters\n"));
2681 for (i = 0; parm_table[i].label; i++) {
2682 if ((parm_table[i].type == P_STRING ||
2683 parm_table[i].type == P_USTRING) &&
2684 !(lp_ctx->flags[i] & FLAG_CMDLINE)) {
2685 TALLOC_CTX *parent_mem;
2686 char **r;
2687 if (parm_table[i].p_class == P_LOCAL) {
2688 parent_mem = lp_ctx->sDefault;
2689 r = (char **)(((char *)lp_ctx->sDefault) + parm_table[i].offset);
2690 } else {
2691 parent_mem = lp_ctx->globals;
2692 r = (char **)(((char *)lp_ctx->globals) + parm_table[i].offset);
2694 lpcfg_string_set(parent_mem, r, "");
2698 logfile = talloc_asprintf(lp_ctx, "%s/log.samba", dyn_LOGFILEBASE);
2699 lpcfg_do_global_parameter(lp_ctx, "log file", logfile);
2700 talloc_free(logfile);
2702 lpcfg_do_global_parameter(lp_ctx, "log level", "0");
2704 lpcfg_do_global_parameter(lp_ctx, "syslog", "1");
2705 lpcfg_do_global_parameter(lp_ctx, "syslog only", "No");
2706 lpcfg_do_global_parameter(lp_ctx, "debug timestamp", "Yes");
2707 lpcfg_do_global_parameter(lp_ctx, "debug prefix timestamp", "No");
2708 lpcfg_do_global_parameter(lp_ctx, "debug hires timestamp", "Yes");
2709 lpcfg_do_global_parameter(lp_ctx, "debug syslog format", "No");
2710 lpcfg_do_global_parameter(lp_ctx, "debug pid", "No");
2711 lpcfg_do_global_parameter(lp_ctx, "debug uid", "No");
2712 lpcfg_do_global_parameter(lp_ctx, "debug class", "No");
2713 lpcfg_do_global_parameter(lp_ctx, "winbind debug traceid", "Yes");
2715 lpcfg_do_global_parameter(lp_ctx, "server role", "auto");
2716 lpcfg_do_global_parameter(lp_ctx, "domain logons", "No");
2717 lpcfg_do_global_parameter(lp_ctx, "domain master", "Auto");
2719 /* options that can be set on the command line must be initialised via
2720 the slower lpcfg_do_global_parameter() to ensure that FLAG_CMDLINE is obeyed */
2721 #ifdef TCP_NODELAY
2722 lpcfg_do_global_parameter(lp_ctx, "socket options", "TCP_NODELAY");
2723 #endif
2724 lpcfg_do_global_parameter(lp_ctx, "workgroup", DEFAULT_WORKGROUP);
2725 myname = get_myname(lp_ctx);
2726 lpcfg_do_global_parameter(lp_ctx, "netbios name", myname);
2727 talloc_free(myname);
2728 lpcfg_do_global_parameter(lp_ctx,
2729 "name resolve order",
2730 DEFAULT_NAME_RESOLVE_ORDER);
2732 lpcfg_do_global_parameter(lp_ctx, "fstype", "NTFS");
2734 lpcfg_do_global_parameter(lp_ctx, "ntvfs handler", "unixuid default");
2735 lpcfg_do_global_parameter(lp_ctx, "max connections", "0");
2737 lpcfg_do_global_parameter(lp_ctx, "dcerpc endpoint servers", "epmapper wkssvc samr netlogon lsarpc drsuapi dssetup unixinfo browser eventlog6 backupkey dnsserver");
2738 lpcfg_do_global_parameter(lp_ctx, "server services", "s3fs rpc nbt wrepl ldap cldap kdc drepl winbindd ntp_signd kcc dnsupdate dns");
2739 lpcfg_do_global_parameter(lp_ctx, "kccsrv:samba_kcc", "true");
2740 /* the winbind method for domain controllers is for both RODC
2741 auth forwarding and for trusted domains */
2742 lpcfg_do_global_parameter(lp_ctx, "private dir", dyn_PRIVATE_DIR);
2743 lpcfg_do_global_parameter(lp_ctx, "binddns dir", dyn_BINDDNS_DIR);
2744 lpcfg_do_global_parameter(lp_ctx, "registry:HKEY_LOCAL_MACHINE", "hklm.ldb");
2746 /* This hive should be dynamically generated by Samba using
2747 data from the sam, but for the moment leave it in a tdb to
2748 keep regedt32 from popping up an annoying dialog. */
2749 lpcfg_do_global_parameter(lp_ctx, "registry:HKEY_USERS", "hku.ldb");
2751 /* using UTF8 by default allows us to support all chars */
2752 lpcfg_do_global_parameter(lp_ctx, "unix charset", "UTF-8");
2754 /* Use codepage 850 as a default for the dos character set */
2755 lpcfg_do_global_parameter(lp_ctx, "dos charset", "CP850");
2758 * Allow the default PASSWD_CHAT to be overridden in local.h.
2760 lpcfg_do_global_parameter(lp_ctx, "passwd chat", DEFAULT_PASSWD_CHAT);
2762 lpcfg_do_global_parameter(lp_ctx, "pid directory", dyn_PIDDIR);
2763 lpcfg_do_global_parameter(lp_ctx, "lock dir", dyn_LOCKDIR);
2764 lpcfg_do_global_parameter(lp_ctx, "state directory", dyn_STATEDIR);
2765 lpcfg_do_global_parameter(lp_ctx, "cache directory", dyn_CACHEDIR);
2766 lpcfg_do_global_parameter(lp_ctx, "ncalrpc dir", dyn_NCALRPCDIR);
2768 lpcfg_do_global_parameter(lp_ctx, "nbt client socket address", "0.0.0.0");
2769 lpcfg_do_global_parameter_var(lp_ctx, "server string",
2770 "Samba %s", SAMBA_VERSION_STRING);
2772 lpcfg_do_global_parameter(lp_ctx, "password server", "*");
2774 lpcfg_do_global_parameter(lp_ctx, "max mux", "50");
2775 lpcfg_do_global_parameter(lp_ctx, "max xmit", "16644");
2776 lpcfg_do_global_parameter(lp_ctx, "host msdfs", "true");
2778 lpcfg_do_global_parameter(lp_ctx, "LargeReadwrite", "True");
2779 lpcfg_do_global_parameter(lp_ctx, "server min protocol", "SMB2_02");
2780 lpcfg_do_global_parameter(lp_ctx, "server max protocol", "SMB3");
2781 lpcfg_do_global_parameter(lp_ctx, "client min protocol", "SMB2_02");
2782 lpcfg_do_global_parameter(lp_ctx, "client max protocol", "default");
2783 lpcfg_do_global_parameter(lp_ctx, "client ipc min protocol", "default");
2784 lpcfg_do_global_parameter(lp_ctx, "client ipc max protocol", "default");
2785 lpcfg_do_global_parameter(lp_ctx, "security", "AUTO");
2786 lpcfg_do_global_parameter(lp_ctx, "EncryptPasswords", "True");
2787 lpcfg_do_global_parameter(lp_ctx, "ReadRaw", "True");
2788 lpcfg_do_global_parameter(lp_ctx, "WriteRaw", "True");
2789 lpcfg_do_global_parameter(lp_ctx, "NullPasswords", "False");
2790 lpcfg_do_global_parameter(lp_ctx, "old password allowed period", "60");
2791 lpcfg_do_global_parameter(lp_ctx, "ObeyPamRestrictions", "False");
2793 lpcfg_do_global_parameter(lp_ctx, "TimeServer", "False");
2794 lpcfg_do_global_parameter(lp_ctx, "BindInterfacesOnly", "False");
2795 lpcfg_do_global_parameter(lp_ctx, "Unicode", "True");
2796 lpcfg_do_global_parameter(lp_ctx, "ClientLanManAuth", "False");
2797 lpcfg_do_global_parameter(lp_ctx, "ClientNTLMv2Auth", "True");
2798 lpcfg_do_global_parameter(lp_ctx, "LanmanAuth", "False");
2799 lpcfg_do_global_parameter(lp_ctx, "NTLMAuth", "ntlmv2-only");
2800 lpcfg_do_global_parameter(lp_ctx, "NT hash store", "always");
2801 lpcfg_do_global_parameter(lp_ctx, "RawNTLMv2Auth", "False");
2803 lpcfg_do_global_parameter(lp_ctx, "allow dcerpc auth level connect", "False");
2805 lpcfg_do_global_parameter(lp_ctx, "UnixExtensions", "True");
2807 lpcfg_do_global_parameter(lp_ctx, "PreferredMaster", "Auto");
2808 lpcfg_do_global_parameter(lp_ctx, "LocalMaster", "True");
2810 lpcfg_do_global_parameter(lp_ctx, "wins support", "False");
2811 lpcfg_do_global_parameter(lp_ctx, "dns proxy", "True");
2813 lpcfg_do_global_parameter(lp_ctx, "winbind separator", "\\");
2814 lpcfg_do_global_parameter(lp_ctx, "winbind sealed pipes", "True");
2815 lpcfg_do_global_parameter(lp_ctx, "winbind scan trusted domains", "False");
2816 lpcfg_do_global_parameter(lp_ctx, "require strong key", "True");
2817 lpcfg_do_global_parameter(lp_ctx, "reject md5 servers", "True");
2818 lpcfg_do_global_parameter(lp_ctx, "winbindd socket directory", dyn_WINBINDD_SOCKET_DIR);
2819 lpcfg_do_global_parameter(lp_ctx, "ntp signd socket directory", dyn_NTP_SIGND_SOCKET_DIR);
2820 lpcfg_do_global_parameter_var(lp_ctx, "gpo update command", "%s/samba-gpupdate", dyn_SCRIPTSBINDIR);
2821 lpcfg_do_global_parameter_var(lp_ctx, "apply group policies", "False");
2822 lpcfg_do_global_parameter_var(lp_ctx, "dns update command", "%s/samba_dnsupdate", dyn_SCRIPTSBINDIR);
2823 lpcfg_do_global_parameter_var(lp_ctx, "spn update command", "%s/samba_spnupdate", dyn_SCRIPTSBINDIR);
2824 lpcfg_do_global_parameter_var(lp_ctx, "samba kcc command",
2825 "%s/samba_kcc", dyn_SCRIPTSBINDIR);
2826 #ifdef MIT_KDC_PATH
2827 lpcfg_do_global_parameter_var(lp_ctx,
2828 "mit kdc command",
2829 MIT_KDC_PATH);
2830 #endif
2831 lpcfg_do_global_parameter(lp_ctx, "template shell", "/bin/false");
2832 lpcfg_do_global_parameter(lp_ctx, "template homedir", "/home/%D/%U");
2834 lpcfg_do_global_parameter(lp_ctx, "client signing", "default");
2835 lpcfg_do_global_parameter(lp_ctx, "client ipc signing", "default");
2836 lpcfg_do_global_parameter(lp_ctx, "server signing", "default");
2838 lpcfg_do_global_parameter(lp_ctx, "use mmap", "True");
2840 lpcfg_do_global_parameter(lp_ctx, "smb ports", "445 139");
2841 lpcfg_do_global_parameter_var(lp_ctx, "nbt port", "%d", NBT_NAME_SERVICE_PORT);
2842 lpcfg_do_global_parameter_var(lp_ctx, "dgram port", "%d", NBT_DGRAM_SERVICE_PORT);
2843 lpcfg_do_global_parameter(lp_ctx, "krb5 port", "88");
2844 lpcfg_do_global_parameter(lp_ctx, "kpasswd port", "464");
2845 lpcfg_do_global_parameter_var(lp_ctx, "dns port", "%d", DNS_SERVICE_PORT);
2847 lpcfg_do_global_parameter(lp_ctx, "kdc enable fast", "True");
2849 lpcfg_do_global_parameter(lp_ctx, "nt status support", "True");
2851 lpcfg_do_global_parameter(lp_ctx, "max wins ttl", "518400"); /* 6 days */
2852 lpcfg_do_global_parameter(lp_ctx, "min wins ttl", "21600");
2854 lpcfg_do_global_parameter(lp_ctx, "tls enabled", "True");
2855 lpcfg_do_global_parameter(lp_ctx, "tls verify peer", "as_strict_as_possible");
2856 lpcfg_do_global_parameter(lp_ctx, "tls keyfile", "tls/key.pem");
2857 lpcfg_do_global_parameter(lp_ctx, "tls certfile", "tls/cert.pem");
2858 lpcfg_do_global_parameter(lp_ctx, "tls cafile", "tls/ca.pem");
2859 lpcfg_do_global_parameter(lp_ctx,
2860 "tls priority",
2861 "NORMAL:-VERS-SSL3.0");
2863 lpcfg_do_global_parameter(lp_ctx, "nsupdate command", "/usr/bin/nsupdate -g");
2865 lpcfg_do_global_parameter(lp_ctx, "allow dns updates", "secure only");
2866 lpcfg_do_global_parameter(lp_ctx, "dns zone scavenging", "False");
2867 lpcfg_do_global_parameter(lp_ctx, "dns forwarder", "");
2869 lpcfg_do_global_parameter(lp_ctx, "algorithmic rid base", "1000");
2871 lpcfg_do_global_parameter(lp_ctx, "enhanced browsing", "True");
2873 lpcfg_do_global_parameter(lp_ctx, "winbind nss info", "template");
2875 lpcfg_do_global_parameter(lp_ctx, "server schannel", "True");
2876 lpcfg_do_global_parameter(lp_ctx, "server schannel require seal", "True");
2877 lpcfg_do_global_parameter(lp_ctx, "reject md5 clients", "True");
2879 lpcfg_do_global_parameter(lp_ctx, "short preserve case", "True");
2881 lpcfg_do_global_parameter(lp_ctx, "max open files", "16384");
2883 lpcfg_do_global_parameter(lp_ctx, "cups connection timeout", "30");
2885 lpcfg_do_global_parameter(lp_ctx, "locking", "True");
2887 lpcfg_do_global_parameter(lp_ctx, "block size", "1024");
2889 lpcfg_do_global_parameter(lp_ctx, "client use spnego", "True");
2891 lpcfg_do_global_parameter(lp_ctx, "change notify", "True");
2893 lpcfg_do_global_parameter(lp_ctx, "name cache timeout", "660");
2895 lpcfg_do_global_parameter(lp_ctx, "defer sharing violations", "True");
2897 lpcfg_do_global_parameter(lp_ctx, "ldap replication sleep", "1000");
2899 lpcfg_do_global_parameter(lp_ctx, "idmap backend", "tdb");
2901 lpcfg_do_global_parameter(lp_ctx, "enable privileges", "True");
2903 lpcfg_do_global_parameter_var(lp_ctx, "smb2 max write", "%u", DEFAULT_SMB2_MAX_WRITE);
2905 lpcfg_do_global_parameter(lp_ctx, "passdb backend", "tdbsam");
2907 lpcfg_do_global_parameter(lp_ctx, "deadtime", "10080");
2909 lpcfg_do_global_parameter(lp_ctx, "getwd cache", "True");
2911 lpcfg_do_global_parameter(lp_ctx, "winbind nested groups", "True");
2913 lpcfg_do_global_parameter(lp_ctx, "mangled names", "illegal");
2915 lpcfg_do_global_parameter_var(lp_ctx, "smb2 max credits", "%u", DEFAULT_SMB2_MAX_CREDITS);
2917 lpcfg_do_global_parameter(lp_ctx, "ldap ssl", "start tls");
2919 lpcfg_do_global_parameter(lp_ctx, "ldap deref", "auto");
2921 lpcfg_do_global_parameter(lp_ctx, "lm interval", "60");
2923 lpcfg_do_global_parameter(lp_ctx, "mangling method", "hash2");
2925 lpcfg_do_global_parameter(lp_ctx, "hide dot files", "True");
2927 lpcfg_do_global_parameter(lp_ctx, "browse list", "True");
2929 lpcfg_do_global_parameter(lp_ctx, "passwd chat timeout", "2");
2931 lpcfg_do_global_parameter(lp_ctx, "guest account", GUEST_ACCOUNT);
2933 lpcfg_do_global_parameter(lp_ctx, "client schannel", "True");
2935 lpcfg_do_global_parameter(lp_ctx, "client use krb5 netlogon", "default");
2937 lpcfg_do_global_parameter(lp_ctx, "smb encrypt", "default");
2939 lpcfg_do_global_parameter(lp_ctx, "max log size", "5000");
2941 lpcfg_do_global_parameter(lp_ctx, "idmap negative cache time", "120");
2943 lpcfg_do_global_parameter(lp_ctx, "ldap follow referral", "auto");
2945 lpcfg_do_global_parameter(lp_ctx, "multicast dns register", "yes");
2947 lpcfg_do_global_parameter(lp_ctx, "winbind reconnect delay", "30");
2949 lpcfg_do_global_parameter(lp_ctx, "winbind request timeout", "60");
2951 lpcfg_do_global_parameter(lp_ctx, "nt acl support", "yes");
2953 lpcfg_do_global_parameter(lp_ctx, "acl check permissions", "yes");
2955 lpcfg_do_global_parameter(lp_ctx, "keepalive", "300");
2957 lpcfg_do_global_parameter(lp_ctx, "smbd profiling level", "off");
2959 lpcfg_do_global_parameter(lp_ctx, "winbind cache time", "300");
2961 lpcfg_do_global_parameter(lp_ctx, "level2 oplocks", "yes");
2963 lpcfg_do_global_parameter(lp_ctx, "show add printer wizard", "yes");
2965 lpcfg_do_global_parameter(lp_ctx, "ldap page size", "1000");
2967 lpcfg_do_global_parameter(lp_ctx, "kernel share modes", "no");
2969 lpcfg_do_global_parameter(lp_ctx, "strict locking", "Auto");
2971 lpcfg_do_global_parameter(lp_ctx, "strict sync", "yes");
2973 lpcfg_do_global_parameter(lp_ctx, "map readonly", "no");
2975 lpcfg_do_global_parameter(lp_ctx, "allow trusted domains", "yes");
2977 lpcfg_do_global_parameter(lp_ctx, "default devmode", "yes");
2979 lpcfg_do_global_parameter(lp_ctx, "os level", "20");
2981 lpcfg_do_global_parameter(lp_ctx, "dos filetimes", "yes");
2983 lpcfg_do_global_parameter(lp_ctx, "mangling char", "~");
2985 lpcfg_do_global_parameter(lp_ctx, "printcap cache time", "750");
2987 lpcfg_do_global_parameter(lp_ctx, "create krb5 conf", "yes");
2989 lpcfg_do_global_parameter(lp_ctx, "winbind max clients", "200");
2991 lpcfg_do_global_parameter(lp_ctx, "acl map full control", "yes");
2993 lpcfg_do_global_parameter(lp_ctx, "nt pipe support", "yes");
2995 lpcfg_do_global_parameter(lp_ctx, "ldap debug threshold", "10");
2997 lpcfg_do_global_parameter(lp_ctx, "client ldap sasl wrapping", "seal");
2999 lpcfg_do_global_parameter(lp_ctx, "mdns name", "netbios");
3001 lpcfg_do_global_parameter(lp_ctx, "ldap server require strong auth", "yes");
3003 lpcfg_do_global_parameter(lp_ctx, "follow symlinks", "yes");
3005 lpcfg_do_global_parameter(lp_ctx, "machine password timeout", "604800");
3007 lpcfg_do_global_parameter(lp_ctx, "ldap connection timeout", "2");
3009 lpcfg_do_global_parameter(lp_ctx, "winbind expand groups", "0");
3011 lpcfg_do_global_parameter(lp_ctx, "stat cache", "yes");
3013 lpcfg_do_global_parameter(lp_ctx, "lpq cache time", "30");
3015 lpcfg_do_global_parameter_var(lp_ctx, "smb2 max trans", "%u", DEFAULT_SMB2_MAX_TRANSACT);
3017 lpcfg_do_global_parameter_var(lp_ctx, "smb2 max read", "%u", DEFAULT_SMB2_MAX_READ);
3019 lpcfg_do_global_parameter(lp_ctx, "durable handles", "yes");
3021 lpcfg_do_global_parameter(lp_ctx, "max stat cache size", "512");
3023 lpcfg_do_global_parameter(lp_ctx, "ldap passwd sync", "no");
3025 lpcfg_do_global_parameter(lp_ctx, "kernel change notify", "yes");
3027 lpcfg_do_global_parameter(lp_ctx, "max ttl", "259200");
3029 lpcfg_do_global_parameter(lp_ctx, "blocking locks", "yes");
3031 lpcfg_do_global_parameter(lp_ctx, "load printers", "yes");
3033 lpcfg_do_global_parameter(lp_ctx, "idmap cache time", "604800");
3035 lpcfg_do_global_parameter(lp_ctx, "preserve case", "yes");
3037 lpcfg_do_global_parameter(lp_ctx, "lm announce", "auto");
3039 lpcfg_do_global_parameter(lp_ctx, "afs token lifetime", "604800");
3041 lpcfg_do_global_parameter(lp_ctx, "enable core files", "yes");
3043 lpcfg_do_global_parameter(lp_ctx, "winbind max domain connections", "1");
3045 lpcfg_do_global_parameter(lp_ctx, "case sensitive", "auto");
3047 lpcfg_do_global_parameter(lp_ctx, "ldap timeout", "15");
3049 lpcfg_do_global_parameter(lp_ctx, "mangle prefix", "1");
3051 lpcfg_do_global_parameter(lp_ctx, "posix locking", "yes");
3053 lpcfg_do_global_parameter(lp_ctx, "lock spin time", "200");
3055 lpcfg_do_global_parameter(lp_ctx, "nmbd bind explicit broadcast", "yes");
3057 lpcfg_do_global_parameter(lp_ctx, "init logon delay", "100");
3059 lpcfg_do_global_parameter(lp_ctx, "usershare owner only", "yes");
3061 lpcfg_do_global_parameter(lp_ctx, "-valid", "yes");
3063 lpcfg_do_global_parameter_var(lp_ctx, "usershare path", "%s/usershares", get_dyn_STATEDIR());
3065 #ifdef DEVELOPER
3066 lpcfg_do_global_parameter_var(lp_ctx, "panic action", "/bin/sleep 999999999");
3067 #endif
3069 lpcfg_do_global_parameter(lp_ctx, "smb passwd file", get_dyn_SMB_PASSWD_FILE());
3071 lpcfg_do_global_parameter(lp_ctx, "logon home", "\\\\%N\\%U");
3073 lpcfg_do_global_parameter(lp_ctx, "logon path", "\\\\%N\\%U\\profile");
3075 lpcfg_do_global_parameter(lp_ctx, "printjob username", "%U");
3077 lpcfg_do_global_parameter(lp_ctx, "aio max threads", "100");
3079 lpcfg_do_global_parameter(lp_ctx, "smb2 leases", "yes");
3081 lpcfg_do_global_parameter(lp_ctx, "smb3 directory leases", "Auto");
3083 lpcfg_do_global_parameter(lp_ctx, "server multi channel support", "yes");
3085 lpcfg_do_global_parameter(lp_ctx, "kerberos encryption types", "all");
3087 lpcfg_do_global_parameter(lp_ctx,
3088 "rpc server dynamic port range",
3089 "49152-65535");
3091 lpcfg_do_global_parameter(lp_ctx, "prefork children", "4");
3092 lpcfg_do_global_parameter(lp_ctx, "prefork backoff increment", "10");
3093 lpcfg_do_global_parameter(lp_ctx, "prefork maximum backoff", "120");
3095 lpcfg_do_global_parameter(lp_ctx, "check parent directory delete on close", "no");
3097 lpcfg_do_global_parameter(lp_ctx, "ea support", "yes");
3099 lpcfg_do_global_parameter(lp_ctx, "store dos attributes", "yes");
3101 lpcfg_do_global_parameter(lp_ctx, "vfs mkdir use tmp name", "Auto");
3103 lpcfg_do_global_parameter(lp_ctx, "debug encryption", "no");
3105 lpcfg_do_global_parameter(lp_ctx, "spotlight backend", "noindex");
3107 lpcfg_do_global_parameter(
3108 lp_ctx, "ldap max anonymous request size", "256000");
3109 lpcfg_do_global_parameter(
3110 lp_ctx, "ldap max authenticated request size", "16777216");
3111 lpcfg_do_global_parameter(
3112 lp_ctx, "ldap max search request size", "256000");
3114 /* Async DNS query timeout in seconds. */
3115 lpcfg_do_global_parameter(lp_ctx, "async dns timeout", "10");
3117 lpcfg_do_global_parameter(lp_ctx,
3118 "client smb encrypt",
3119 "default");
3121 lpcfg_do_global_parameter(lp_ctx,
3122 "client use kerberos",
3123 "desired");
3125 lpcfg_do_global_parameter(lp_ctx,
3126 "client protection",
3127 "default");
3129 lpcfg_do_global_parameter(lp_ctx,
3130 "smbd max xattr size",
3131 "65536");
3133 lpcfg_do_global_parameter(lp_ctx,
3134 "acl flag inherited canonicalization",
3135 "yes");
3137 lpcfg_do_global_parameter(lp_ctx,
3138 "winbind use krb5 enterprise principals",
3139 "yes");
3141 lpcfg_do_global_parameter(lp_ctx,
3142 "client smb3 signing algorithms",
3143 DEFAULT_SMB3_SIGNING_ALGORITHMS);
3144 lpcfg_do_global_parameter(lp_ctx,
3145 "server smb3 signing algorithms",
3146 DEFAULT_SMB3_SIGNING_ALGORITHMS);
3148 lpcfg_do_global_parameter(lp_ctx,
3149 "client smb3 encryption algorithms",
3150 DEFAULT_SMB3_ENCRYPTION_ALGORITHMS);
3151 lpcfg_do_global_parameter(lp_ctx,
3152 "server smb3 encryption algorithms",
3153 DEFAULT_SMB3_ENCRYPTION_ALGORITHMS);
3155 lpcfg_do_global_parameter(lp_ctx,
3156 "min domain uid",
3157 "1000");
3159 lpcfg_do_global_parameter(lp_ctx,
3160 "rpc start on demand helpers",
3161 "yes");
3163 lpcfg_do_global_parameter(lp_ctx,
3164 "ad dc functional level",
3165 "2008_R2");
3167 lpcfg_do_global_parameter(lp_ctx,
3168 "acl claims evaluation",
3169 "AD DC only");
3171 /* Set the default Himmelblaud globals */
3172 lpcfg_do_global_parameter(lp_ctx,
3173 "himmelblaud hsm pin path",
3174 get_dyn_HIMMELBLAUD_HSM_PIN_PATH());
3175 lpcfg_do_global_parameter(lp_ctx,
3176 "himmelblaud hello enabled",
3177 "false");
3178 lpcfg_do_global_parameter(lp_ctx,
3179 "himmelblaud sfa fallback",
3180 "false");
3182 for (i = 0; parm_table[i].label; i++) {
3183 if (!(lp_ctx->flags[i] & FLAG_CMDLINE)) {
3184 lp_ctx->flags[i] |= FLAG_DEFAULT;
3188 for (parm=lp_ctx->globals->param_opt; parm; parm=parm->next) {
3189 if (!(parm->priority & FLAG_CMDLINE)) {
3190 parm->priority |= FLAG_DEFAULT;
3194 for (parm=lp_ctx->sDefault->param_opt; parm; parm=parm->next) {
3195 if (!(parm->priority & FLAG_CMDLINE)) {
3196 parm->priority |= FLAG_DEFAULT;
3200 return lp_ctx;
3204 * Initialise the global parameter structure.
3206 struct loadparm_context *loadparm_init_global(bool load_default)
3208 if (global_loadparm_context == NULL) {
3209 global_loadparm_context = loadparm_init(NULL);
3211 if (global_loadparm_context == NULL) {
3212 return NULL;
3214 global_loadparm_context->global = true;
3215 if (load_default && !global_loadparm_context->loaded) {
3216 lpcfg_load_default(global_loadparm_context);
3218 global_loadparm_context->refuse_free = true;
3219 return global_loadparm_context;
3223 * @brief Initialise the global parameter structure.
3225 * This function initialized the globals if needed. Make sure that
3226 * gfree_loadparm() is called before the application exits.
3228 * @param mem_ctx The talloc memory context to allocate lp_ctx on.
3230 * @param s3_fns The loadparm helper functions to use
3232 * @return An initialized lp_ctx pointer or NULL on error.
3234 struct loadparm_context *loadparm_init_s3(TALLOC_CTX *mem_ctx,
3235 const struct loadparm_s3_helpers *s3_fns)
3237 struct loadparm_context *loadparm_context = talloc_zero(mem_ctx, struct loadparm_context);
3238 if (!loadparm_context) {
3239 return NULL;
3241 loadparm_context->s3_fns = s3_fns;
3242 loadparm_context->globals = s3_fns->globals;
3243 loadparm_context->flags = s3_fns->flags;
3245 /* Make sure globals are correctly initialized */
3246 loadparm_context->s3_fns->init_globals(loadparm_context, false);
3248 return loadparm_context;
3251 const char *lpcfg_configfile(struct loadparm_context *lp_ctx)
3253 return lp_ctx->szConfigFile;
3256 const char *lp_default_path(void)
3258 if (getenv("SMB_CONF_PATH"))
3259 return getenv("SMB_CONF_PATH");
3260 else
3261 return dyn_CONFIGFILE;
3265 * Update the internal state of a loadparm context after settings
3266 * have changed.
3268 static bool lpcfg_update(struct loadparm_context *lp_ctx)
3270 struct debug_settings settings;
3271 int max_protocol, min_protocol;
3272 TALLOC_CTX *tmp_ctx;
3273 const struct loadparm_substitution *lp_sub =
3274 lpcfg_noop_substitution();
3276 tmp_ctx = talloc_new(lp_ctx);
3277 if (tmp_ctx == NULL) {
3278 return false;
3281 lpcfg_add_auto_services(lp_ctx, lpcfg_auto_services(lp_ctx, lp_sub, tmp_ctx));
3283 if (!lp_ctx->globals->wins_server_list && lp_ctx->globals->we_are_a_wins_server) {
3284 lpcfg_do_global_parameter(lp_ctx, "wins server", "127.0.0.1");
3287 if (!lp_ctx->global) {
3288 TALLOC_FREE(tmp_ctx);
3289 return true;
3292 panic_action = lp_ctx->globals->panic_action;
3294 reload_charcnv(lp_ctx);
3296 ZERO_STRUCT(settings);
3297 /* Add any more debug-related smb.conf parameters created in
3298 * future here */
3299 settings.timestamp_logs = lp_ctx->globals->timestamp_logs;
3300 settings.debug_prefix_timestamp = lp_ctx->globals->debug_prefix_timestamp;
3301 settings.debug_hires_timestamp = lp_ctx->globals->debug_hires_timestamp;
3302 settings.debug_syslog_format = lp_ctx->globals->debug_syslog_format;
3303 settings.debug_pid = lp_ctx->globals->debug_pid;
3304 settings.debug_uid = lp_ctx->globals->debug_uid;
3305 settings.debug_class = lp_ctx->globals->debug_class;
3306 settings.max_log_size = lp_ctx->globals->max_log_size;
3307 debug_set_settings(&settings, lp_ctx->globals->logging,
3308 lp_ctx->globals->syslog,
3309 lp_ctx->globals->syslog_only);
3311 /* FIXME: This is a bit of a hack, but we can't use a global, since
3312 * not everything that uses lp also uses the socket library */
3313 if (lpcfg_parm_bool(lp_ctx, NULL, "socket", "testnonblock", false)) {
3314 setenv("SOCKET_TESTNONBLOCK", "1", 1);
3315 } else {
3316 unsetenv("SOCKET_TESTNONBLOCK");
3319 /* Check if command line max protocol < min protocol, if so
3320 * report a warning to the user.
3322 max_protocol = lpcfg_client_max_protocol(lp_ctx);
3323 min_protocol = lpcfg_client_min_protocol(lp_ctx);
3324 if (lpcfg_client_max_protocol(lp_ctx) < lpcfg_client_min_protocol(lp_ctx)) {
3325 const char *max_protocolp, *min_protocolp;
3326 max_protocolp = lpcfg_get_smb_protocol(max_protocol);
3327 min_protocolp = lpcfg_get_smb_protocol(min_protocol);
3328 DBG_ERR("Max protocol %s is less than min protocol %s.\n",
3329 max_protocolp, min_protocolp);
3332 TALLOC_FREE(tmp_ctx);
3333 return true;
3336 bool lpcfg_load_default(struct loadparm_context *lp_ctx)
3338 const char *path;
3340 path = lp_default_path();
3342 if (!file_exist(path)) {
3343 /* We allow the default smb.conf file to not exist,
3344 * basically the equivalent of an empty file. */
3345 return lpcfg_update(lp_ctx);
3348 return lpcfg_load(lp_ctx, path);
3352 * Load the services array from the services file.
3354 * Return True on success, False on failure.
3356 static bool lpcfg_load_internal(struct loadparm_context *lp_ctx,
3357 const char *filename, bool set_global)
3359 char *n2;
3360 bool bRetval;
3362 if (lp_ctx->szConfigFile != NULL) {
3363 talloc_free(discard_const_p(char, lp_ctx->szConfigFile));
3364 lp_ctx->szConfigFile = NULL;
3367 lp_ctx->szConfigFile = talloc_strdup(lp_ctx, filename);
3369 if (lp_ctx->s3_fns) {
3370 return lp_ctx->s3_fns->load(filename);
3373 lp_ctx->bInGlobalSection = true;
3374 n2 = standard_sub_basic(lp_ctx, lp_ctx->szConfigFile);
3375 DEBUG(2, ("lpcfg_load: refreshing parameters from %s\n", n2));
3377 add_to_file_list(lp_ctx, &lp_ctx->file_lists, lp_ctx->szConfigFile, n2);
3379 /* We get sections first, so have to start 'behind' to make up */
3380 lp_ctx->currentService = NULL;
3381 bRetval = pm_process(n2, do_section, lpcfg_do_parameter, lp_ctx);
3383 /* finish up the last section */
3384 DEBUG(4, ("pm_process() returned %s\n", BOOLSTR(bRetval)));
3385 if (bRetval)
3386 if (lp_ctx->currentService != NULL)
3387 bRetval = lpcfg_service_ok(lp_ctx->currentService);
3389 bRetval = bRetval && lpcfg_update(lp_ctx);
3391 /* we do this unconditionally, so that it happens even
3392 for a missing smb.conf */
3393 reload_charcnv(lp_ctx);
3395 if (bRetval == true && set_global) {
3396 /* set this up so that any child python tasks will
3397 find the right smb.conf */
3398 setenv("SMB_CONF_PATH", filename, 1);
3400 /* set the context used by the lp_*() function
3401 variants */
3402 global_loadparm_context = lp_ctx;
3403 lp_ctx->loaded = true;
3406 return bRetval;
3409 bool lpcfg_load_no_global(struct loadparm_context *lp_ctx, const char *filename)
3411 return lpcfg_load_internal(lp_ctx, filename, false);
3414 bool lpcfg_load(struct loadparm_context *lp_ctx, const char *filename)
3416 return lpcfg_load_internal(lp_ctx, filename, true);
3420 * Return the max number of services.
3423 int lpcfg_numservices(struct loadparm_context *lp_ctx)
3425 if (lp_ctx->s3_fns) {
3426 return lp_ctx->s3_fns->get_numservices();
3429 return lp_ctx->iNumServices;
3433 * Display the contents of the services array in human-readable form.
3436 void lpcfg_dump(struct loadparm_context *lp_ctx, FILE *f, bool show_defaults,
3437 int maxtoprint)
3439 int iService;
3441 if (lp_ctx->s3_fns) {
3442 lp_ctx->s3_fns->dump(f, show_defaults, maxtoprint);
3443 return;
3446 lpcfg_dump_globals(lp_ctx, f, show_defaults);
3448 lpcfg_dump_a_service(lp_ctx->sDefault, lp_ctx->sDefault, f, lp_ctx->flags, show_defaults);
3450 for (iService = 0; iService < maxtoprint; iService++)
3451 lpcfg_dump_one(f, show_defaults, lp_ctx->services[iService], lp_ctx->sDefault);
3455 * Display the contents of one service in human-readable form.
3457 void lpcfg_dump_one(FILE *f, bool show_defaults, struct loadparm_service *service, struct loadparm_service *sDefault)
3459 if (service != NULL) {
3460 if (service->szService[0] == '\0')
3461 return;
3462 lpcfg_dump_a_service(service, sDefault, f, NULL, show_defaults);
3466 struct loadparm_service *lpcfg_servicebynum(struct loadparm_context *lp_ctx,
3467 int snum)
3469 if (lp_ctx->s3_fns) {
3470 return lp_ctx->s3_fns->get_servicebynum(snum);
3473 return lp_ctx->services[snum];
3476 struct loadparm_service *lpcfg_service(struct loadparm_context *lp_ctx,
3477 const char *service_name)
3479 int iService;
3480 char *serviceName;
3482 if (lp_ctx->s3_fns) {
3483 return lp_ctx->s3_fns->get_service(service_name);
3486 for (iService = lp_ctx->iNumServices - 1; iService >= 0; iService--) {
3487 if (lp_ctx->services[iService] &&
3488 lp_ctx->services[iService]->szService) {
3490 * The substitution here is used to support %U is
3491 * service names
3493 serviceName = standard_sub_basic(
3494 lp_ctx->services[iService],
3495 lp_ctx->services[iService]->szService);
3496 if (strequal(serviceName, service_name)) {
3497 talloc_free(serviceName);
3498 return lp_ctx->services[iService];
3500 talloc_free(serviceName);
3504 DEBUG(7,("lpcfg_servicenumber: couldn't find %s\n", service_name));
3505 return NULL;
3508 const char *lpcfg_servicename(const struct loadparm_service *service)
3510 return service ? lpcfg_string((const char *)service->szService) : NULL;
3513 struct smb_iconv_handle *lpcfg_iconv_handle(struct loadparm_context *lp_ctx)
3515 if (lp_ctx == NULL) {
3516 return get_iconv_handle();
3518 return lp_ctx->iconv_handle;
3521 _PUBLIC_ void reload_charcnv(struct loadparm_context *lp_ctx)
3523 if (!lp_ctx->global) {
3524 return;
3527 lp_ctx->iconv_handle =
3528 reinit_iconv_handle(lp_ctx,
3529 lpcfg_dos_charset(lp_ctx),
3530 lpcfg_unix_charset(lp_ctx));
3531 if (lp_ctx->iconv_handle == NULL) {
3532 smb_panic("reinit_iconv_handle failed");
3536 _PUBLIC_ char *lpcfg_tls_keyfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
3538 return lpcfg_private_path(mem_ctx, lp_ctx, lpcfg__tls_keyfile(lp_ctx));
3541 _PUBLIC_ char *lpcfg_tls_certfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
3543 return lpcfg_private_path(mem_ctx, lp_ctx, lpcfg__tls_certfile(lp_ctx));
3546 _PUBLIC_ char *lpcfg_tls_cafile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
3548 return lpcfg_private_path(mem_ctx, lp_ctx, lpcfg__tls_cafile(lp_ctx));
3551 _PUBLIC_ char *lpcfg_tls_crlfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
3553 return lpcfg_private_path(mem_ctx, lp_ctx, lpcfg__tls_crlfile(lp_ctx));
3556 _PUBLIC_ char *lpcfg_tls_dhpfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
3558 return lpcfg_private_path(mem_ctx, lp_ctx, lpcfg__tls_dhpfile(lp_ctx));
3561 struct gensec_settings *lpcfg_gensec_settings(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
3563 struct gensec_settings *settings = talloc_zero(mem_ctx, struct gensec_settings);
3564 if (settings == NULL)
3565 return NULL;
3566 SMB_ASSERT(lp_ctx != NULL);
3567 settings->lp_ctx = talloc_reference(settings, lp_ctx);
3568 settings->target_hostname = lpcfg_parm_string(lp_ctx, NULL, "gensec", "target_hostname");
3569 return settings;
3572 int lpcfg_server_role(struct loadparm_context *lp_ctx)
3574 int domain_master = lpcfg__domain_master(lp_ctx);
3576 return lp_find_server_role(lpcfg__server_role(lp_ctx),
3577 lpcfg__security(lp_ctx),
3578 lpcfg__domain_logons(lp_ctx),
3579 (domain_master == true) ||
3580 (domain_master == Auto));
3583 int lpcfg_security(struct loadparm_context *lp_ctx)
3585 return lp_find_security(lpcfg__server_role(lp_ctx),
3586 lpcfg__security(lp_ctx));
3589 int lpcfg_client_max_protocol(struct loadparm_context *lp_ctx)
3591 int client_max_protocol = lpcfg__client_max_protocol(lp_ctx);
3592 if (client_max_protocol == PROTOCOL_DEFAULT) {
3593 return PROTOCOL_LATEST;
3595 return client_max_protocol;
3598 int lpcfg_client_ipc_min_protocol(struct loadparm_context *lp_ctx)
3600 int client_ipc_min_protocol = lpcfg__client_ipc_min_protocol(lp_ctx);
3601 if (client_ipc_min_protocol == PROTOCOL_DEFAULT) {
3602 client_ipc_min_protocol = lpcfg_client_min_protocol(lp_ctx);
3604 if (client_ipc_min_protocol < PROTOCOL_NT1) {
3605 return PROTOCOL_NT1;
3607 return client_ipc_min_protocol;
3610 int lpcfg_client_ipc_max_protocol(struct loadparm_context *lp_ctx)
3612 int client_ipc_max_protocol = lpcfg__client_ipc_max_protocol(lp_ctx);
3613 if (client_ipc_max_protocol == PROTOCOL_DEFAULT) {
3614 return PROTOCOL_LATEST;
3616 if (client_ipc_max_protocol < PROTOCOL_NT1) {
3617 return PROTOCOL_NT1;
3619 return client_ipc_max_protocol;
3622 int lpcfg_client_ipc_signing(struct loadparm_context *lp_ctx)
3624 int client_ipc_signing = lpcfg__client_ipc_signing(lp_ctx);
3625 if (client_ipc_signing == SMB_SIGNING_DEFAULT) {
3626 return SMB_SIGNING_REQUIRED;
3628 return client_ipc_signing;
3631 enum credentials_use_kerberos lpcfg_client_use_kerberos(struct loadparm_context *lp_ctx)
3633 if (lpcfg_weak_crypto(lp_ctx) == SAMBA_WEAK_CRYPTO_DISALLOWED) {
3634 return CRED_USE_KERBEROS_REQUIRED;
3637 return lpcfg__client_use_kerberos(lp_ctx);
3640 bool lpcfg_server_signing_allowed(struct loadparm_context *lp_ctx, bool *mandatory)
3642 bool allowed = true;
3643 enum smb_signing_setting signing_setting = lpcfg_server_signing(lp_ctx);
3645 *mandatory = false;
3647 if (signing_setting == SMB_SIGNING_DEFAULT) {
3649 * If we are a domain controller, SMB signing is
3650 * really important, as it can prevent a number of
3651 * attacks on communications between us and the
3652 * clients
3654 * However, it really sucks (no sendfile, CPU
3655 * overhead) performance-wise when used on a
3656 * file server, so disable it by default
3657 * on non-DCs
3660 if (lpcfg_server_role(lp_ctx) >= ROLE_ACTIVE_DIRECTORY_DC) {
3661 signing_setting = SMB_SIGNING_REQUIRED;
3662 } else {
3663 signing_setting = SMB_SIGNING_OFF;
3667 switch (signing_setting) {
3668 case SMB_SIGNING_REQUIRED:
3669 *mandatory = true;
3670 break;
3671 case SMB_SIGNING_DESIRED:
3672 case SMB_SIGNING_IF_REQUIRED:
3673 break;
3674 case SMB_SIGNING_OFF:
3675 allowed = false;
3676 break;
3677 case SMB_SIGNING_DEFAULT:
3678 case SMB_SIGNING_IPC_DEFAULT:
3679 smb_panic(__location__);
3680 break;
3683 return allowed;
3686 int lpcfg_client_use_krb5_netlogon(struct loadparm_context *lp_ctx)
3688 int val = lpcfg__client_use_krb5_netlogon(lp_ctx);
3690 if (val == LP_ENUM_Default) {
3691 val = false;
3694 return val;
3697 int lpcfg_tdb_hash_size(struct loadparm_context *lp_ctx, const char *name)
3699 const char *base;
3701 if (name == NULL) {
3702 return 0;
3705 base = strrchr_m(name, '/');
3706 if (base != NULL) {
3707 base += 1;
3708 } else {
3709 base = name;
3711 return lpcfg_parm_int(lp_ctx, NULL, "tdb_hashsize", base, 0);
3715 int lpcfg_tdb_flags(struct loadparm_context *lp_ctx, int tdb_flags)
3717 if (!lpcfg_use_mmap(lp_ctx)) {
3718 tdb_flags |= TDB_NOMMAP;
3720 return tdb_flags;
3724 * Do not allow LanMan auth if unless NTLMv1 is also allowed
3726 * This also ensures it is disabled if NTLM is totally disabled
3728 bool lpcfg_lanman_auth(struct loadparm_context *lp_ctx)
3730 enum ntlm_auth_level ntlm_auth_level = lpcfg_ntlm_auth(lp_ctx);
3732 if (ntlm_auth_level == NTLM_AUTH_ON) {
3733 return lpcfg__lanman_auth(lp_ctx);
3734 } else {
3735 return false;
3739 static char *lpcfg_noop_substitution_fn(
3740 TALLOC_CTX *mem_ctx,
3741 const struct loadparm_substitution *lp_sub,
3742 const char *raw_value,
3743 void *private_data)
3745 return talloc_strdup(mem_ctx, raw_value);
3748 static const struct loadparm_substitution global_noop_substitution = {
3749 .substituted_string_fn = lpcfg_noop_substitution_fn,
3752 const struct loadparm_substitution *lpcfg_noop_substitution(void)
3754 return &global_noop_substitution;
3757 char *lpcfg_substituted_string(TALLOC_CTX *mem_ctx,
3758 const struct loadparm_substitution *lp_sub,
3759 const char *raw_value)
3761 return lp_sub->substituted_string_fn(mem_ctx,
3762 lp_sub,
3763 raw_value,
3764 lp_sub->private_data);
3768 * @brief Parse a string value of a given parameter to its integer enum value.
3770 * @param[in] param_name The parameter name (e.g. 'client smb encrypt')
3772 * @param[in] param_value The parameter value (e.g. 'required').
3774 * @return The integer value of the enum the param_value matches or INT32_MIN
3775 * on error.
3777 int32_t lpcfg_parse_enum_vals(const char *param_name,
3778 const char *param_value)
3780 struct parm_struct *parm = NULL;
3781 int32_t ret = INT32_MIN;
3782 bool ok;
3784 parm = lpcfg_parm_struct(NULL, param_name);
3785 if (parm == NULL) {
3786 return INT32_MIN;
3789 ok = lp_set_enum_parm(parm, param_value, &ret);
3790 if (!ok) {
3791 return INT32_MIN;
3794 return ret;
3797 const char *lpcfg_dns_hostname(struct loadparm_context *lp_ctx)
3799 const char *dns_hostname = lpcfg__dns_hostname(lp_ctx);
3800 const char *dns_domain = lpcfg_dnsdomain(lp_ctx);
3801 char *netbios_name = NULL;
3802 char *hostname = NULL;
3804 if (dns_hostname != NULL && dns_hostname[0] != '\0') {
3805 return dns_hostname;
3808 netbios_name = strlower_talloc(lp_ctx, lpcfg_netbios_name(lp_ctx));
3809 if (netbios_name == NULL) {
3810 return NULL;
3813 /* If it isn't set, try to initialize with [netbios name].[realm] */
3814 if (dns_domain != NULL && dns_domain[0] != '\0') {
3815 hostname = talloc_asprintf(lp_ctx,
3816 "%s.%s",
3817 netbios_name,
3818 dns_domain);
3819 } else {
3820 hostname = talloc_strdup(lp_ctx, netbios_name);
3822 TALLOC_FREE(netbios_name);
3823 if (hostname == NULL) {
3824 return NULL;
3827 lpcfg_string_set(lp_ctx->globals->ctx,
3828 &lp_ctx->globals->_dns_hostname,
3829 hostname);
3831 return hostname;