smbdotconf: add client ldap sasl wrapping = {starttls,ldaps}
[Samba.git] / lib / param / loadparm.c
blob0984ca7195b349a30c328dc3ef0bcc1a1dd1a434
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 false;
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");
1278 if (!lp_set_enum_parm(&parm_table[parm_num], pszParmValue, (int*)ptr)) {
1279 return false;
1282 if (lp_ctx->s3_fns) {
1283 if (service == NULL) {
1284 init_printer_values(lp_ctx, lp_ctx->globals->ctx, lp_ctx->sDefault);
1285 } else {
1286 init_printer_values(lp_ctx, service, service);
1290 return true;
1293 bool handle_ldap_debug_level(struct loadparm_context *lp_ctx, struct loadparm_service *service,
1294 const char *pszParmValue, char **ptr)
1296 lp_ctx->globals->ldap_debug_level = lp_int(pszParmValue);
1298 if (lp_ctx->s3_fns) {
1299 lp_ctx->s3_fns->init_ldap_debugging();
1301 return true;
1305 * idmap related parameters
1308 bool handle_idmap_backend(struct loadparm_context *lp_ctx, struct loadparm_service *service,
1309 const char *pszParmValue, char **ptr)
1311 if (lp_ctx->s3_fns) {
1312 lp_do_parameter_parametric(lp_ctx, service, "idmap config * : backend",
1313 pszParmValue, 0);
1316 return lpcfg_string_set(lp_ctx->globals->ctx, ptr, pszParmValue);
1319 bool handle_idmap_uid(struct loadparm_context *lp_ctx, struct loadparm_service *service,
1320 const char *pszParmValue, char **ptr)
1322 if (lp_ctx->s3_fns) {
1323 lp_do_parameter_parametric(lp_ctx, service, "idmap config * : range",
1324 pszParmValue, 0);
1327 return lpcfg_string_set(lp_ctx->globals->ctx, ptr, pszParmValue);
1330 bool handle_idmap_gid(struct loadparm_context *lp_ctx, struct loadparm_service *service,
1331 const char *pszParmValue, char **ptr)
1333 if (lp_ctx->s3_fns) {
1334 lp_do_parameter_parametric(lp_ctx, service, "idmap config * : range",
1335 pszParmValue, 0);
1338 return lpcfg_string_set(lp_ctx->globals->ctx, ptr, pszParmValue);
1341 bool handle_smb_ports(struct loadparm_context *lp_ctx, struct loadparm_service *service,
1342 const char *pszParmValue, char **ptr)
1344 static int parm_num = -1;
1345 int i;
1346 const char **list;
1348 if (!pszParmValue || !*pszParmValue) {
1349 return false;
1352 if (parm_num == -1) {
1353 parm_num = lpcfg_map_parameter("smb ports");
1354 if (parm_num == -1) {
1355 return false;
1359 if (!set_variable_helper(lp_ctx->globals->ctx, parm_num, ptr, "smb ports",
1360 pszParmValue)) {
1361 return false;
1364 list = lp_ctx->globals->smb_ports;
1365 if (list == NULL) {
1366 return false;
1369 /* Check that each port is a valid integer and within range */
1370 for (i = 0; list[i] != NULL; i++) {
1371 char *end = NULL;
1372 int port = 0;
1373 port = strtol(list[i], &end, 10);
1374 if (*end != '\0' || port <= 0 || port > 65535) {
1375 TALLOC_FREE(list);
1376 return false;
1380 return true;
1383 bool handle_rpc_server_dynamic_port_range(struct loadparm_context *lp_ctx,
1384 struct loadparm_service *service,
1385 const char *pszParmValue,
1386 char **ptr)
1388 static int parm_num = -1;
1389 int low_port = -1, high_port = -1;
1390 int rc;
1392 if (parm_num == -1) {
1393 parm_num = lpcfg_map_parameter("rpc server dynamic port range");
1394 if (parm_num == -1) {
1395 return false;
1399 if (pszParmValue == NULL || pszParmValue[0] == '\0') {
1400 return false;
1403 rc = sscanf(pszParmValue, "%d - %d", &low_port, &high_port);
1404 if (rc != 2) {
1405 return false;
1408 if (low_port > high_port) {
1409 return false;
1412 if (low_port < SERVER_TCP_PORT_MIN|| high_port > SERVER_TCP_PORT_MAX) {
1413 return false;
1416 if (!set_variable_helper(lp_ctx->globals->ctx, parm_num, ptr,
1417 "rpc server dynamic port range",
1418 pszParmValue)) {
1419 return false;
1422 lp_ctx->globals->rpc_low_port = low_port;
1423 lp_ctx->globals->rpc_high_port = high_port;
1425 return true;
1428 bool handle_smb2_max_credits(struct loadparm_context *lp_ctx,
1429 struct loadparm_service *service,
1430 const char *pszParmValue, char **ptr)
1432 int value = lp_int(pszParmValue);
1434 if (value <= 0) {
1435 value = DEFAULT_SMB2_MAX_CREDITS;
1438 *(int *)ptr = value;
1440 return true;
1443 bool handle_cups_encrypt(struct loadparm_context *lp_ctx,
1444 struct loadparm_service *service,
1445 const char *pszParmValue, char **ptr)
1447 int result = 0;
1448 #ifdef HAVE_HTTPCONNECTENCRYPT
1449 int value = lp_int(pszParmValue);
1451 switch (value) {
1452 case Auto:
1453 result = HTTP_ENCRYPT_REQUIRED;
1454 break;
1455 case true:
1456 result = HTTP_ENCRYPT_ALWAYS;
1457 break;
1458 case false:
1459 result = HTTP_ENCRYPT_NEVER;
1460 break;
1461 default:
1462 result = 0;
1463 break;
1465 #endif
1466 *(int *)ptr = result;
1468 return true;
1471 /***************************************************************************
1472 Initialise a copymap.
1473 ***************************************************************************/
1476 * Initializes service copymap
1477 * Note: pservice *must* be valid TALLOC_CTX
1479 void init_copymap(struct loadparm_service *pservice)
1481 int i;
1483 TALLOC_FREE(pservice->copymap);
1485 pservice->copymap = bitmap_talloc(pservice, num_parameters());
1486 if (!pservice->copymap) {
1487 DEBUG(0,
1488 ("Couldn't allocate copymap!! (size %d)\n",
1489 (int)num_parameters()));
1490 } else {
1491 for (i = 0; i < num_parameters(); i++) {
1492 bitmap_set(pservice->copymap, i);
1498 * Process a parametric option
1500 static bool lp_do_parameter_parametric(struct loadparm_context *lp_ctx,
1501 struct loadparm_service *service,
1502 const char *pszParmName,
1503 const char *pszParmValue, int flags)
1505 struct parmlist_entry **data;
1506 char *name;
1507 TALLOC_CTX *mem_ctx;
1509 while (isspace((unsigned char)*pszParmName)) {
1510 pszParmName++;
1513 name = strlower_talloc(lp_ctx, pszParmName);
1514 if (!name) return false;
1516 if (service == NULL) {
1517 data = &lp_ctx->globals->param_opt;
1519 * s3 code cannot deal with parametric options stored on the globals ctx.
1521 if (lp_ctx->s3_fns != NULL) {
1522 mem_ctx = NULL;
1523 } else {
1524 mem_ctx = lp_ctx->globals->ctx;
1526 } else {
1527 data = &service->param_opt;
1528 mem_ctx = service;
1531 set_param_opt(mem_ctx, data, name, pszParmValue, flags);
1533 talloc_free(name);
1535 return true;
1538 static bool set_variable_helper(TALLOC_CTX *mem_ctx, int parmnum, void *parm_ptr,
1539 const char *pszParmName, const char *pszParmValue)
1541 size_t i;
1543 /* switch on the type of variable it is */
1544 switch (parm_table[parmnum].type)
1546 case P_BOOL: {
1547 bool b;
1548 if (!set_boolean(pszParmValue, &b)) {
1549 DEBUG(0, ("set_variable_helper(%s): value is not "
1550 "boolean!\n", pszParmValue));
1551 return false;
1553 *(bool *)parm_ptr = b;
1555 break;
1557 case P_BOOLREV: {
1558 bool b;
1559 if (!set_boolean(pszParmValue, &b)) {
1560 DEBUG(0, ("set_variable_helper(%s): value is not "
1561 "boolean!\n", pszParmValue));
1562 return false;
1564 *(bool *)parm_ptr = !b;
1566 break;
1568 case P_INTEGER:
1569 *(int *)parm_ptr = lp_int(pszParmValue);
1570 break;
1572 case P_CHAR:
1573 *(char *)parm_ptr = *pszParmValue;
1574 break;
1576 case P_OCTAL:
1577 i = sscanf(pszParmValue, "%o", (int *)parm_ptr);
1578 if ( i != 1 ) {
1579 DEBUG ( 0, ("Invalid octal number %s\n", pszParmName ));
1580 return false;
1582 break;
1584 case P_BYTES:
1586 uint64_t val;
1587 if (conv_str_size_error(pszParmValue, &val)) {
1588 if (val <= INT_MAX) {
1589 *(int *)parm_ptr = (int)val;
1590 break;
1594 DEBUG(0, ("set_variable_helper(%s): value is not "
1595 "a valid size specifier!\n", pszParmValue));
1596 return false;
1599 case P_CMDLIST:
1600 TALLOC_FREE(*(char ***)parm_ptr);
1601 *(char ***)parm_ptr = str_list_make_v3(mem_ctx,
1602 pszParmValue, NULL);
1603 break;
1605 case P_LIST:
1607 char **new_list = str_list_make_v3(mem_ctx,
1608 pszParmValue, NULL);
1609 if (new_list == NULL) {
1610 break;
1613 for (i=0; new_list[i]; i++) {
1614 if (*(const char ***)parm_ptr != NULL &&
1615 new_list[i][0] == '+' &&
1616 new_list[i][1])
1618 if (!str_list_check(*(const char ***)parm_ptr,
1619 &new_list[i][1])) {
1620 *(const char ***)parm_ptr = str_list_add(*(const char ***)parm_ptr,
1621 &new_list[i][1]);
1623 } else if (*(const char ***)parm_ptr != NULL &&
1624 new_list[i][0] == '-' &&
1625 new_list[i][1])
1627 str_list_remove(*(const char ***)parm_ptr,
1628 &new_list[i][1]);
1629 } else {
1630 if (i != 0) {
1631 DEBUG(0, ("Unsupported list syntax for: %s = %s\n",
1632 pszParmName, pszParmValue));
1633 return false;
1635 *(char ***)parm_ptr = new_list;
1636 break;
1639 break;
1642 case P_STRING:
1643 lpcfg_string_set(mem_ctx, (char **)parm_ptr, pszParmValue);
1644 break;
1646 case P_USTRING:
1647 lpcfg_string_set_upper(mem_ctx, (char **)parm_ptr, pszParmValue);
1648 break;
1650 case P_ENUM:
1651 if (!lp_set_enum_parm(&parm_table[parmnum], pszParmValue, (int*)parm_ptr)) {
1652 return false;
1654 break;
1658 return true;
1662 bool handle_name_resolve_order(struct loadparm_context *lp_ctx,
1663 struct loadparm_service *service,
1664 const char *pszParmValue, char **ptr)
1666 const char **valid_values = NULL;
1667 const char **values_to_set = NULL;
1668 int i;
1669 bool value_is_valid = false;
1670 valid_values = str_list_make_v3_const(NULL,
1671 DEFAULT_NAME_RESOLVE_ORDER,
1672 NULL);
1673 if (valid_values == NULL) {
1674 DBG_ERR("OOM: failed to make string list from %s\n",
1675 DEFAULT_NAME_RESOLVE_ORDER);
1676 goto out;
1678 values_to_set = str_list_make_v3_const(lp_ctx->globals->ctx,
1679 pszParmValue,
1680 NULL);
1681 if (values_to_set == NULL) {
1682 DBG_ERR("OOM: failed to make string list from %s\n",
1683 pszParmValue);
1684 goto out;
1686 TALLOC_FREE(lp_ctx->globals->name_resolve_order);
1687 for (i = 0; values_to_set[i] != NULL; i++) {
1688 value_is_valid = str_list_check(valid_values, values_to_set[i]);
1689 if (!value_is_valid) {
1690 DBG_ERR("WARNING: Ignoring invalid list value '%s' "
1691 "for parameter 'name resolve order'\n",
1692 values_to_set[i]);
1693 break;
1696 out:
1697 if (value_is_valid) {
1698 lp_ctx->globals->name_resolve_order = values_to_set;
1699 } else {
1700 TALLOC_FREE(values_to_set);
1702 TALLOC_FREE(valid_values);
1703 return value_is_valid;
1706 bool handle_kdc_default_domain_supported_enctypes(struct loadparm_context *lp_ctx,
1707 struct loadparm_service *service,
1708 const char *pszParmValue, char **ptr)
1710 char **enctype_list = NULL;
1711 char **enctype = NULL;
1712 uint32_t result = 0;
1713 bool ok = true;
1715 enctype_list = str_list_make(NULL, pszParmValue, NULL);
1716 if (enctype_list == NULL) {
1717 DBG_ERR("OOM: failed to make string list from %s\n",
1718 pszParmValue);
1719 ok = false;
1720 goto out;
1723 for (enctype = enctype_list; *enctype != NULL; ++enctype) {
1724 if (strwicmp(*enctype, "arcfour-hmac-md5") == 0 ||
1725 strwicmp(*enctype, "rc4-hmac") == 0)
1727 result |= KERB_ENCTYPE_RC4_HMAC_MD5;
1729 else if (strwicmp(*enctype, "aes128-cts-hmac-sha1-96") == 0 ||
1730 strwicmp(*enctype, "aes128-cts") == 0)
1732 result |= KERB_ENCTYPE_AES128_CTS_HMAC_SHA1_96;
1734 else if (strwicmp(*enctype, "aes256-cts-hmac-sha1-96") == 0 ||
1735 strwicmp(*enctype, "aes256-cts") == 0)
1737 result |= KERB_ENCTYPE_AES256_CTS_HMAC_SHA1_96;
1739 else if (strwicmp(*enctype, "aes256-cts-hmac-sha1-96-sk") == 0 ||
1740 strwicmp(*enctype, "aes256-cts-sk") == 0)
1742 result |= KERB_ENCTYPE_AES256_CTS_HMAC_SHA1_96_SK;
1744 else {
1745 const char *bitstr = *enctype;
1746 int base;
1747 int error;
1748 unsigned long bit;
1750 /* See if the bit's specified in hexadecimal. */
1751 if (bitstr[0] == '0' &&
1752 (bitstr[1] == 'x' || bitstr[2] == 'X'))
1754 base = 16;
1755 bitstr += 2;
1757 else {
1758 base = 10;
1761 bit = smb_strtoul(bitstr, NULL, base, &error, SMB_STR_FULL_STR_CONV);
1762 if (error) {
1763 DBG_ERR("WARNING: Ignoring invalid value '%s' "
1764 "for parameter 'kdc default domain supported enctypes'\n",
1765 *enctype);
1766 ok = false;
1767 } else {
1768 result |= bit;
1773 *(int *)ptr = result;
1774 out:
1775 TALLOC_FREE(enctype_list);
1777 return ok;
1780 bool handle_kdc_supported_enctypes(struct loadparm_context *lp_ctx,
1781 struct loadparm_service *service,
1782 const char *pszParmValue, char **ptr)
1784 char **enctype_list = NULL;
1785 char **enctype = NULL;
1786 uint32_t result = 0;
1787 bool ok = true;
1789 enctype_list = str_list_make(NULL, pszParmValue, NULL);
1790 if (enctype_list == NULL) {
1791 DBG_ERR("OOM: failed to make string list from %s\n",
1792 pszParmValue);
1793 ok = false;
1794 goto out;
1797 for (enctype = enctype_list; *enctype != NULL; ++enctype) {
1798 if (strwicmp(*enctype, "arcfour-hmac-md5") == 0 ||
1799 strwicmp(*enctype, "rc4-hmac") == 0)
1801 result |= KERB_ENCTYPE_RC4_HMAC_MD5;
1803 else if (strwicmp(*enctype, "aes128-cts-hmac-sha1-96") == 0 ||
1804 strwicmp(*enctype, "aes128-cts") == 0)
1806 result |= KERB_ENCTYPE_AES128_CTS_HMAC_SHA1_96;
1808 else if (strwicmp(*enctype, "aes256-cts-hmac-sha1-96") == 0 ||
1809 strwicmp(*enctype, "aes256-cts") == 0)
1811 result |= KERB_ENCTYPE_AES256_CTS_HMAC_SHA1_96;
1813 else {
1814 const char *bitstr = *enctype;
1815 int base;
1816 int error;
1817 unsigned long bit;
1819 /* See if the bit's specified in hexadecimal. */
1820 if (bitstr[0] == '0' &&
1821 (bitstr[1] == 'x' || bitstr[2] == 'X'))
1823 base = 16;
1824 bitstr += 2;
1826 else {
1827 base = 10;
1830 bit = smb_strtoul(bitstr, NULL, base, &error, SMB_STR_FULL_STR_CONV);
1831 if (error) {
1832 DBG_ERR("WARNING: Ignoring invalid value '%s' "
1833 "for parameter 'kdc default domain supported enctypes'\n",
1834 *enctype);
1835 ok = false;
1836 } else {
1837 result |= bit;
1842 *(int *)ptr = result;
1843 out:
1844 TALLOC_FREE(enctype_list);
1846 return ok;
1849 static bool set_variable(TALLOC_CTX *mem_ctx, struct loadparm_service *service,
1850 int parmnum, void *parm_ptr,
1851 const char *pszParmName, const char *pszParmValue,
1852 struct loadparm_context *lp_ctx, bool on_globals)
1854 int i;
1855 bool ok;
1857 /* if it is a special case then go ahead */
1858 if (parm_table[parmnum].special) {
1859 ok = parm_table[parmnum].special(lp_ctx, service, pszParmValue,
1860 (char **)parm_ptr);
1861 } else {
1862 ok = set_variable_helper(mem_ctx, parmnum, parm_ptr,
1863 pszParmName, pszParmValue);
1866 if (!ok) {
1867 return false;
1870 if (on_globals && (lp_ctx->flags[parmnum] & FLAG_DEFAULT)) {
1871 lp_ctx->flags[parmnum] &= ~FLAG_DEFAULT;
1872 /* we have to also unset FLAG_DEFAULT on aliases */
1873 for (i=parmnum-1;i>=0 && parm_table[i].offset == parm_table[parmnum].offset;i--) {
1874 lp_ctx->flags[i] &= ~FLAG_DEFAULT;
1876 for (i=parmnum+1;i<num_parameters() && parm_table[i].offset == parm_table[parmnum].offset;i++) {
1877 lp_ctx->flags[i] &= ~FLAG_DEFAULT;
1880 return true;
1884 bool lpcfg_do_global_parameter(struct loadparm_context *lp_ctx,
1885 const char *pszParmName, const char *pszParmValue)
1887 int parmnum = lpcfg_map_parameter(pszParmName);
1888 void *parm_ptr;
1890 if (parmnum < 0) {
1891 if (strchr(pszParmName, ':')) {
1892 return lp_do_parameter_parametric(lp_ctx, NULL, pszParmName, pszParmValue, 0);
1894 DEBUG(0, ("Ignoring unknown parameter \"%s\"\n", pszParmName));
1895 return true;
1898 /* if the flag has been set on the command line, then don't allow override,
1899 but don't report an error */
1900 if (lp_ctx->flags[parmnum] & FLAG_CMDLINE) {
1901 return true;
1904 if (parm_table[parmnum].flags & FLAG_DEPRECATED) {
1905 char *suppress_env = getenv("SAMBA_DEPRECATED_SUPPRESS");
1906 bool print_warning = (suppress_env == NULL
1907 || suppress_env[0] == '\0');
1908 if (print_warning) {
1909 DBG_WARNING("WARNING: The \"%s\" option "
1910 "is deprecated\n",
1911 pszParmName);
1916 parm_ptr = lpcfg_parm_ptr(lp_ctx, NULL, &parm_table[parmnum]);
1918 return set_variable(lp_ctx->globals->ctx, NULL, parmnum, parm_ptr,
1919 pszParmName, pszParmValue, lp_ctx, true);
1922 bool lpcfg_do_service_parameter(struct loadparm_context *lp_ctx,
1923 struct loadparm_service *service,
1924 const char *pszParmName, const char *pszParmValue)
1926 void *parm_ptr;
1927 int i;
1928 int parmnum = lpcfg_map_parameter(pszParmName);
1930 if (parmnum < 0) {
1931 if (strchr(pszParmName, ':')) {
1932 return lp_do_parameter_parametric(lp_ctx, service, pszParmName, pszParmValue, 0);
1934 DEBUG(0, ("Ignoring unknown parameter \"%s\"\n", pszParmName));
1935 return true;
1938 /* if the flag has been set on the command line, then don't allow override,
1939 but don't report an error */
1940 if (lp_ctx->flags[parmnum] & FLAG_CMDLINE) {
1941 return true;
1944 if (parm_table[parmnum].flags & FLAG_DEPRECATED) {
1945 char *suppress_env = getenv("SAMBA_DEPRECATED_SUPPRESS");
1946 bool print_warning = (suppress_env == NULL
1947 || suppress_env[0] == '\0');
1948 if (print_warning) {
1949 DBG_WARNING("WARNING: The \"%s\" option "
1950 "is deprecated\n",
1951 pszParmName);
1956 if (parm_table[parmnum].p_class == P_GLOBAL) {
1957 DEBUG(0,
1958 ("Global parameter %s found in service section!\n",
1959 pszParmName));
1960 return true;
1962 parm_ptr = ((char *)service) + parm_table[parmnum].offset;
1964 if (!service->copymap)
1965 init_copymap(service);
1967 /* this handles the aliases - set the copymap for other
1968 * entries with the same data pointer */
1969 for (i = 0; parm_table[i].label; i++)
1970 if (parm_table[i].offset == parm_table[parmnum].offset &&
1971 parm_table[i].p_class == parm_table[parmnum].p_class)
1972 bitmap_clear(service->copymap, i);
1974 return set_variable(service, service, parmnum, parm_ptr, pszParmName,
1975 pszParmValue, lp_ctx, false);
1979 * Process a parameter.
1982 bool lpcfg_do_parameter(const char *pszParmName, const char *pszParmValue,
1983 void *userdata)
1985 struct loadparm_context *lp_ctx = (struct loadparm_context *)userdata;
1987 if (lp_ctx->bInGlobalSection)
1988 return lpcfg_do_global_parameter(lp_ctx, pszParmName,
1989 pszParmValue);
1990 else
1991 return lpcfg_do_service_parameter(lp_ctx, lp_ctx->currentService,
1992 pszParmName, pszParmValue);
1996 variable argument do parameter
1998 bool lpcfg_do_global_parameter_var(struct loadparm_context *lp_ctx, const char *pszParmName, const char *fmt, ...) PRINTF_ATTRIBUTE(3, 4);
1999 bool lpcfg_do_global_parameter_var(struct loadparm_context *lp_ctx,
2000 const char *pszParmName, const char *fmt, ...)
2002 char *s;
2003 bool ret;
2004 va_list ap;
2006 va_start(ap, fmt);
2007 s = talloc_vasprintf(NULL, fmt, ap);
2008 va_end(ap);
2009 ret = lpcfg_do_global_parameter(lp_ctx, pszParmName, s);
2010 talloc_free(s);
2011 return ret;
2016 set a parameter from the commandline - this is called from command line parameter
2017 parsing code. It sets the parameter then marks the parameter as unable to be modified
2018 by smb.conf processing
2020 bool lpcfg_set_cmdline(struct loadparm_context *lp_ctx, const char *pszParmName,
2021 const char *pszParmValue)
2023 int parmnum;
2024 int i;
2026 while (isspace((unsigned char)*pszParmValue)) pszParmValue++;
2028 parmnum = lpcfg_map_parameter(pszParmName);
2030 if (parmnum < 0 && strchr(pszParmName, ':')) {
2031 /* set a parametric option */
2032 bool ok;
2033 ok = lp_do_parameter_parametric(lp_ctx, NULL, pszParmName,
2034 pszParmValue, FLAG_CMDLINE);
2035 if (lp_ctx->s3_fns != NULL) {
2036 if (ok) {
2037 lp_ctx->s3_fns->store_cmdline(pszParmName, pszParmValue);
2040 return ok;
2043 if (parmnum < 0) {
2044 DEBUG(0,("Unknown option '%s'\n", pszParmName));
2045 return false;
2048 /* reset the CMDLINE flag in case this has been called before */
2049 lp_ctx->flags[parmnum] &= ~FLAG_CMDLINE;
2051 if (!lpcfg_do_global_parameter(lp_ctx, pszParmName, pszParmValue)) {
2052 return false;
2055 lp_ctx->flags[parmnum] |= FLAG_CMDLINE;
2057 /* we have to also set FLAG_CMDLINE on aliases */
2058 for (i=parmnum-1;
2059 i>=0 && parm_table[i].p_class == parm_table[parmnum].p_class &&
2060 parm_table[i].offset == parm_table[parmnum].offset;
2061 i--) {
2062 lp_ctx->flags[i] |= FLAG_CMDLINE;
2064 for (i=parmnum+1;
2065 i<num_parameters() &&
2066 parm_table[i].p_class == parm_table[parmnum].p_class &&
2067 parm_table[i].offset == parm_table[parmnum].offset;
2068 i++) {
2069 lp_ctx->flags[i] |= FLAG_CMDLINE;
2072 if (lp_ctx->s3_fns != NULL) {
2073 lp_ctx->s3_fns->store_cmdline(pszParmName, pszParmValue);
2076 return true;
2080 set a option from the commandline in 'a=b' format. Use to support --option
2082 bool lpcfg_set_option(struct loadparm_context *lp_ctx, const char *option)
2084 char *p, *s;
2085 bool ret;
2087 s = talloc_strdup(NULL, option);
2088 if (!s) {
2089 return false;
2092 p = strchr(s, '=');
2093 if (!p) {
2094 talloc_free(s);
2095 return false;
2098 *p = 0;
2100 ret = lpcfg_set_cmdline(lp_ctx, s, p+1);
2101 talloc_free(s);
2102 return ret;
2106 #define BOOLSTR(b) ((b) ? "Yes" : "No")
2109 * Print a parameter of the specified type.
2112 void lpcfg_print_parameter(struct parm_struct *p, void *ptr, FILE * f)
2114 /* For the separation of lists values that we print below */
2115 const char *list_sep = ", ";
2116 int i;
2117 switch (p->type)
2119 case P_ENUM:
2120 for (i = 0; p->enum_list[i].name; i++) {
2121 if (*(int *)ptr == p->enum_list[i].value) {
2122 fprintf(f, "%s",
2123 p->enum_list[i].name);
2124 break;
2127 break;
2129 case P_BOOL:
2130 fprintf(f, "%s", BOOLSTR(*(bool *)ptr));
2131 break;
2133 case P_BOOLREV:
2134 fprintf(f, "%s", BOOLSTR(!*(bool *)ptr));
2135 break;
2137 case P_INTEGER:
2138 case P_BYTES:
2139 fprintf(f, "%d", *(int *)ptr);
2140 break;
2142 case P_CHAR:
2143 fprintf(f, "%c", *(char *)ptr);
2144 break;
2146 case P_OCTAL: {
2147 int val = *(int *)ptr;
2148 if (val == -1) {
2149 fprintf(f, "-1");
2150 } else {
2151 fprintf(f, "0%03o", val);
2153 break;
2156 case P_CMDLIST:
2157 list_sep = " ";
2159 FALL_THROUGH;
2160 case P_LIST:
2161 if ((char ***)ptr && *(char ***)ptr) {
2162 char **list = *(char ***)ptr;
2163 for (; *list; list++) {
2164 /* surround strings with whitespace in double quotes */
2165 if (*(list+1) == NULL) {
2166 /* last item, no extra separator */
2167 list_sep = "";
2169 if ( strchr_m( *list, ' ' ) ) {
2170 fprintf(f, "\"%s\"%s", *list, list_sep);
2171 } else {
2172 fprintf(f, "%s%s", *list, list_sep);
2176 break;
2178 case P_STRING:
2179 case P_USTRING:
2180 if (*(char **)ptr) {
2181 fprintf(f, "%s", *(char **)ptr);
2183 break;
2188 * Check if two parameters are equal.
2191 static bool lpcfg_equal_parameter(parm_type type, void *ptr1, void *ptr2)
2193 switch (type) {
2194 case P_BOOL:
2195 case P_BOOLREV:
2196 return (*((bool *)ptr1) == *((bool *)ptr2));
2198 case P_INTEGER:
2199 case P_ENUM:
2200 case P_OCTAL:
2201 case P_BYTES:
2202 return (*((int *)ptr1) == *((int *)ptr2));
2204 case P_CHAR:
2205 return (*((char *)ptr1) == *((char *)ptr2));
2207 case P_LIST:
2208 case P_CMDLIST:
2209 return str_list_equal(*(const char ***)ptr1, *(const char ***)ptr2);
2211 case P_STRING:
2212 case P_USTRING:
2214 char *p1 = *(char **)ptr1, *p2 = *(char **)ptr2;
2215 if (p1 && !*p1)
2216 p1 = NULL;
2217 if (p2 && !*p2)
2218 p2 = NULL;
2219 return (p1 == p2 || strequal(p1, p2));
2222 return false;
2226 * Process a new section (service).
2228 * At this stage all sections are services.
2229 * Later we'll have special sections that permit server parameters to be set.
2230 * Returns True on success, False on failure.
2233 static bool do_section(const char *pszSectionName, void *userdata)
2235 struct loadparm_context *lp_ctx = (struct loadparm_context *)userdata;
2236 bool bRetval;
2237 bool isglobal;
2239 if (lp_ctx->s3_fns != NULL) {
2240 return lp_ctx->s3_fns->do_section(pszSectionName, lp_ctx);
2243 isglobal = ((strwicmp(pszSectionName, GLOBAL_NAME) == 0) ||
2244 (strwicmp(pszSectionName, GLOBAL_NAME2) == 0));
2246 /* if we've just struck a global section, note the fact. */
2247 lp_ctx->bInGlobalSection = isglobal;
2249 /* check for multiple global sections */
2250 if (lp_ctx->bInGlobalSection) {
2251 DEBUG(4, ("Processing section \"[%s]\"\n", pszSectionName));
2252 bRetval = true;
2253 goto out;
2256 /* if we have a current service, tidy it up before moving on */
2257 bRetval = true;
2259 if (lp_ctx->currentService != NULL)
2260 bRetval = lpcfg_service_ok(lp_ctx->currentService);
2262 /* if all is still well, move to the next record in the services array */
2263 if (bRetval) {
2264 /* We put this here to avoid an odd message order if messages are */
2265 /* issued by the post-processing of a previous section. */
2266 DEBUG(4, ("Processing section \"[%s]\"\n", pszSectionName));
2268 if ((lp_ctx->currentService = lpcfg_add_service(lp_ctx, lp_ctx->sDefault,
2269 pszSectionName))
2270 == NULL) {
2271 DEBUG(0, ("Failed to add a new service\n"));
2272 bRetval = false;
2273 goto out;
2276 out:
2277 return bRetval;
2282 * Determine if a particular base parameter is currently set to the default value.
2285 static bool is_default(void *base_structure, int i)
2287 void *def_ptr = ((char *)base_structure) + parm_table[i].offset;
2288 switch (parm_table[i].type) {
2289 case P_CMDLIST:
2290 case P_LIST:
2291 return str_list_equal((const char * const *)parm_table[i].def.lvalue,
2292 *(const char * const **)def_ptr);
2293 case P_STRING:
2294 case P_USTRING:
2295 return strequal(parm_table[i].def.svalue,
2296 *(char **)def_ptr);
2297 case P_BOOL:
2298 case P_BOOLREV:
2299 return parm_table[i].def.bvalue ==
2300 *(bool *)def_ptr;
2301 case P_INTEGER:
2302 case P_CHAR:
2303 case P_OCTAL:
2304 case P_BYTES:
2305 case P_ENUM:
2306 return parm_table[i].def.ivalue ==
2307 *(int *)def_ptr;
2309 return false;
2313 *Display the contents of the global structure.
2316 void lpcfg_dump_globals(struct loadparm_context *lp_ctx, FILE *f,
2317 bool show_defaults)
2319 int i;
2320 struct parmlist_entry *data;
2322 fprintf(f, "# Global parameters\n[global]\n");
2324 for (i = 0; parm_table[i].label; i++) {
2325 if (parm_table[i].p_class != P_GLOBAL) {
2326 continue;
2329 if (parm_table[i].flags & FLAG_SYNONYM) {
2330 continue;
2333 if (!show_defaults) {
2334 if (lp_ctx->flags && (lp_ctx->flags[i] & FLAG_DEFAULT)) {
2335 continue;
2338 if (is_default(lp_ctx->globals, i)) {
2339 continue;
2343 fprintf(f, "\t%s = ", parm_table[i].label);
2344 lpcfg_print_parameter(&parm_table[i], lpcfg_parm_ptr(lp_ctx, NULL, &parm_table[i]), f);
2345 fprintf(f, "\n");
2347 if (lp_ctx->globals->param_opt != NULL) {
2348 for (data = lp_ctx->globals->param_opt; data;
2349 data = data->next) {
2350 if (!show_defaults && (data->priority & FLAG_DEFAULT)) {
2351 continue;
2353 fprintf(f, "\t%s = %s\n", data->key, data->value);
2360 * Display the contents of a single services record.
2363 void lpcfg_dump_a_service(struct loadparm_service * pService, struct loadparm_service *sDefault, FILE * f,
2364 unsigned int *flags, bool show_defaults)
2366 int i;
2367 struct parmlist_entry *data;
2369 if (pService != sDefault)
2370 fprintf(f, "\n[%s]\n", pService->szService);
2372 for (i = 0; parm_table[i].label; i++) {
2373 if (parm_table[i].p_class != P_LOCAL) {
2374 continue;
2377 if (parm_table[i].flags & FLAG_SYNONYM) {
2378 continue;
2381 if (*parm_table[i].label == '-') {
2382 continue;
2385 if (pService == sDefault) {
2386 if (!show_defaults) {
2387 if (flags && (flags[i] & FLAG_DEFAULT)) {
2388 continue;
2391 if (is_default(sDefault, i)) {
2392 continue;
2395 } else {
2396 bool equal;
2398 equal = lpcfg_equal_parameter(parm_table[i].type,
2399 ((char *)pService) +
2400 parm_table[i].offset,
2401 ((char *)sDefault) +
2402 parm_table[i].offset);
2403 if (equal) {
2404 continue;
2408 fprintf(f, "\t%s = ", parm_table[i].label);
2409 lpcfg_print_parameter(&parm_table[i],
2410 ((char *)pService) + parm_table[i].offset, f);
2411 fprintf(f, "\n");
2413 if (pService->param_opt != NULL) {
2414 for (data = pService->param_opt; data; data = data->next) {
2415 if (!show_defaults && (data->priority & FLAG_DEFAULT)) {
2416 continue;
2418 fprintf(f, "\t%s = %s\n", data->key, data->value);
2423 bool lpcfg_dump_a_parameter(struct loadparm_context *lp_ctx,
2424 struct loadparm_service *service,
2425 const char *parm_name, FILE * f)
2427 struct parm_struct *parm;
2428 void *ptr;
2429 char *local_parm_name;
2430 char *parm_opt;
2431 const char *parm_opt_value;
2433 /* check for parametrical option */
2434 local_parm_name = talloc_strdup(lp_ctx, parm_name);
2435 if (local_parm_name == NULL) {
2436 return false;
2439 parm_opt = strchr( local_parm_name, ':');
2441 if (parm_opt) {
2442 *parm_opt = '\0';
2443 parm_opt++;
2444 if (strlen(parm_opt)) {
2445 parm_opt_value = lpcfg_parm_string(lp_ctx, service,
2446 local_parm_name, parm_opt);
2447 if (parm_opt_value) {
2448 fprintf(f, "%s\n", parm_opt_value);
2449 TALLOC_FREE(local_parm_name);
2450 return true;
2453 TALLOC_FREE(local_parm_name);
2454 return false;
2456 TALLOC_FREE(local_parm_name);
2458 /* parameter is not parametric, search the table */
2459 parm = lpcfg_parm_struct(lp_ctx, parm_name);
2460 if (!parm) {
2461 return false;
2464 if (service != NULL && parm->p_class == P_GLOBAL) {
2465 return false;
2468 ptr = lpcfg_parm_ptr(lp_ctx, service,parm);
2470 lpcfg_print_parameter(parm, ptr, f);
2471 fprintf(f, "\n");
2472 return true;
2476 * Auto-load some home services.
2478 static void lpcfg_add_auto_services(struct loadparm_context *lp_ctx,
2479 const char *str)
2481 return;
2484 /***************************************************************************
2485 Initialise the sDefault parameter structure for the printer values.
2486 ***************************************************************************/
2488 void init_printer_values(struct loadparm_context *lp_ctx, TALLOC_CTX *ctx,
2489 struct loadparm_service *pService)
2491 /* choose defaults depending on the type of printing */
2492 switch (pService->printing) {
2493 case PRINT_BSD:
2494 case PRINT_AIX:
2495 case PRINT_LPRNT:
2496 case PRINT_LPROS2:
2497 lpcfg_string_set(ctx, &pService->lpq_command, "lpq -P'%p'");
2498 lpcfg_string_set(ctx, &pService->lprm_command, "lprm -P'%p' %j");
2499 lpcfg_string_set(ctx, &pService->print_command, "lpr -r -P'%p' %s");
2500 break;
2502 case PRINT_LPRNG:
2503 case PRINT_PLP:
2504 lpcfg_string_set(ctx, &pService->lpq_command, "lpq -P'%p'");
2505 lpcfg_string_set(ctx, &pService->lprm_command, "lprm -P'%p' %j");
2506 lpcfg_string_set(ctx, &pService->print_command, "lpr -r -P'%p' %s");
2507 lpcfg_string_set(ctx, &pService->queuepause_command, "lpc stop '%p'");
2508 lpcfg_string_set(ctx, &pService->queueresume_command, "lpc start '%p'");
2509 lpcfg_string_set(ctx, &pService->lppause_command, "lpc hold '%p' %j");
2510 lpcfg_string_set(ctx, &pService->lpresume_command, "lpc release '%p' %j");
2511 break;
2513 case PRINT_CUPS:
2514 case PRINT_IPRINT:
2515 /* set the lpq command to contain the destination printer
2516 name only. This is used by cups_queue_get() */
2517 lpcfg_string_set(ctx, &pService->lpq_command, "%p");
2518 lpcfg_string_set(ctx, &pService->lprm_command, "");
2519 lpcfg_string_set(ctx, &pService->print_command, "");
2520 lpcfg_string_set(ctx, &pService->lppause_command, "");
2521 lpcfg_string_set(ctx, &pService->lpresume_command, "");
2522 lpcfg_string_set(ctx, &pService->queuepause_command, "");
2523 lpcfg_string_set(ctx, &pService->queueresume_command, "");
2524 break;
2526 case PRINT_SYSV:
2527 case PRINT_HPUX:
2528 lpcfg_string_set(ctx, &pService->lpq_command, "lpstat -o%p");
2529 lpcfg_string_set(ctx, &pService->lprm_command, "cancel %p-%j");
2530 lpcfg_string_set(ctx, &pService->print_command, "lp -c -d%p %s; rm %s");
2531 lpcfg_string_set(ctx, &pService->queuepause_command, "disable %p");
2532 lpcfg_string_set(ctx, &pService->queueresume_command, "enable %p");
2533 #ifndef HPUX
2534 lpcfg_string_set(ctx, &pService->lppause_command, "lp -i %p-%j -H hold");
2535 lpcfg_string_set(ctx, &pService->lpresume_command, "lp -i %p-%j -H resume");
2536 #endif /* HPUX */
2537 break;
2539 case PRINT_QNX:
2540 lpcfg_string_set(ctx, &pService->lpq_command, "lpq -P%p");
2541 lpcfg_string_set(ctx, &pService->lprm_command, "lprm -P%p %j");
2542 lpcfg_string_set(ctx, &pService->print_command, "lp -r -P%p %s");
2543 break;
2545 #if defined(DEVELOPER) || defined(ENABLE_SELFTEST)
2547 case PRINT_TEST:
2548 case PRINT_VLP: {
2549 const char *tdbfile;
2550 TALLOC_CTX *tmp_ctx = talloc_new(ctx);
2551 const char *tmp;
2553 tmp = lpcfg_parm_string(lp_ctx, NULL, "vlp", "tdbfile");
2554 if (tmp == NULL) {
2555 tmp = "/tmp/vlp.tdb";
2558 tdbfile = talloc_asprintf(tmp_ctx, "tdbfile=%s", tmp);
2559 if (tdbfile == NULL) {
2560 tdbfile="tdbfile=/tmp/vlp.tdb";
2563 tmp = talloc_asprintf(tmp_ctx, "vlp %s print %%p %%s",
2564 tdbfile);
2565 lpcfg_string_set(ctx, &pService->print_command,
2566 tmp ? tmp : "vlp print %p %s");
2568 tmp = talloc_asprintf(tmp_ctx, "vlp %s lpq %%p",
2569 tdbfile);
2570 lpcfg_string_set(ctx, &pService->lpq_command,
2571 tmp ? tmp : "vlp lpq %p");
2573 tmp = talloc_asprintf(tmp_ctx, "vlp %s lprm %%p %%j",
2574 tdbfile);
2575 lpcfg_string_set(ctx, &pService->lprm_command,
2576 tmp ? tmp : "vlp lprm %p %j");
2578 tmp = talloc_asprintf(tmp_ctx, "vlp %s lppause %%p %%j",
2579 tdbfile);
2580 lpcfg_string_set(ctx, &pService->lppause_command,
2581 tmp ? tmp : "vlp lppause %p %j");
2583 tmp = talloc_asprintf(tmp_ctx, "vlp %s lpresume %%p %%j",
2584 tdbfile);
2585 lpcfg_string_set(ctx, &pService->lpresume_command,
2586 tmp ? tmp : "vlp lpresume %p %j");
2588 tmp = talloc_asprintf(tmp_ctx, "vlp %s queuepause %%p",
2589 tdbfile);
2590 lpcfg_string_set(ctx, &pService->queuepause_command,
2591 tmp ? tmp : "vlp queuepause %p");
2593 tmp = talloc_asprintf(tmp_ctx, "vlp %s queueresume %%p",
2594 tdbfile);
2595 lpcfg_string_set(ctx, &pService->queueresume_command,
2596 tmp ? tmp : "vlp queueresume %p");
2597 TALLOC_FREE(tmp_ctx);
2599 break;
2601 #endif /* DEVELOPER */
2607 static int lpcfg_destructor(struct loadparm_context *lp_ctx)
2609 struct parmlist_entry *data;
2611 if (lp_ctx->refuse_free) {
2612 /* someone is trying to free the
2613 global_loadparm_context.
2614 We can't allow that. */
2615 return -1;
2618 if (lp_ctx->globals->param_opt != NULL) {
2619 struct parmlist_entry *next;
2620 for (data = lp_ctx->globals->param_opt; data; data=next) {
2621 next = data->next;
2622 if (data->priority & FLAG_CMDLINE) continue;
2623 DLIST_REMOVE(lp_ctx->globals->param_opt, data);
2624 talloc_free(data);
2628 return 0;
2632 * Initialise the global parameter structure.
2634 * Note that most callers should use loadparm_init_global() instead
2636 struct loadparm_context *loadparm_init(TALLOC_CTX *mem_ctx)
2638 int i;
2639 char *myname;
2640 struct loadparm_context *lp_ctx;
2641 struct parmlist_entry *parm;
2642 char *logfile;
2644 lp_ctx = talloc_zero(mem_ctx, struct loadparm_context);
2645 if (lp_ctx == NULL)
2646 return NULL;
2648 talloc_set_destructor(lp_ctx, lpcfg_destructor);
2649 lp_ctx->bInGlobalSection = true;
2650 lp_ctx->globals = talloc_zero(lp_ctx, struct loadparm_global);
2651 /* This appears odd, but globals in s3 isn't a pointer */
2652 lp_ctx->globals->ctx = lp_ctx->globals;
2653 lp_ctx->globals->rpc_low_port = SERVER_TCP_LOW_PORT;
2654 lp_ctx->globals->rpc_high_port = SERVER_TCP_HIGH_PORT;
2655 lp_ctx->globals->weak_crypto = SAMBA_WEAK_CRYPTO_UNKNOWN;
2656 lp_ctx->sDefault = talloc_zero(lp_ctx, struct loadparm_service);
2657 lp_ctx->flags = talloc_zero_array(lp_ctx, unsigned int, num_parameters());
2659 lp_ctx->sDefault->max_print_jobs = 1000;
2660 lp_ctx->sDefault->available = true;
2661 lp_ctx->sDefault->browseable = true;
2662 lp_ctx->sDefault->read_only = true;
2663 lp_ctx->sDefault->map_archive = true;
2664 lp_ctx->sDefault->strict_locking = true;
2665 lp_ctx->sDefault->oplocks = true;
2666 lp_ctx->sDefault->create_mask = 0744;
2667 lp_ctx->sDefault->force_create_mode = 0000;
2668 lp_ctx->sDefault->directory_mask = 0755;
2669 lp_ctx->sDefault->force_directory_mode = 0000;
2670 lp_ctx->sDefault->aio_read_size = 1;
2671 lp_ctx->sDefault->aio_write_size = 1;
2672 lp_ctx->sDefault->smbd_search_ask_sharemode = true;
2673 lp_ctx->sDefault->smbd_getinfo_ask_sharemode = true;
2674 lp_ctx->sDefault->volume_serial_number = -1;
2676 DEBUG(3, ("Initialising global parameters\n"));
2678 for (i = 0; parm_table[i].label; i++) {
2679 if ((parm_table[i].type == P_STRING ||
2680 parm_table[i].type == P_USTRING) &&
2681 !(lp_ctx->flags[i] & FLAG_CMDLINE)) {
2682 TALLOC_CTX *parent_mem;
2683 char **r;
2684 if (parm_table[i].p_class == P_LOCAL) {
2685 parent_mem = lp_ctx->sDefault;
2686 r = (char **)(((char *)lp_ctx->sDefault) + parm_table[i].offset);
2687 } else {
2688 parent_mem = lp_ctx->globals;
2689 r = (char **)(((char *)lp_ctx->globals) + parm_table[i].offset);
2691 lpcfg_string_set(parent_mem, r, "");
2695 logfile = talloc_asprintf(lp_ctx, "%s/log.samba", dyn_LOGFILEBASE);
2696 lpcfg_do_global_parameter(lp_ctx, "log file", logfile);
2697 talloc_free(logfile);
2699 lpcfg_do_global_parameter(lp_ctx, "log level", "0");
2701 lpcfg_do_global_parameter(lp_ctx, "syslog", "1");
2702 lpcfg_do_global_parameter(lp_ctx, "syslog only", "No");
2703 lpcfg_do_global_parameter(lp_ctx, "debug timestamp", "Yes");
2704 lpcfg_do_global_parameter(lp_ctx, "debug prefix timestamp", "No");
2705 lpcfg_do_global_parameter(lp_ctx, "debug hires timestamp", "Yes");
2706 lpcfg_do_global_parameter(lp_ctx, "debug syslog format", "No");
2707 lpcfg_do_global_parameter(lp_ctx, "debug pid", "No");
2708 lpcfg_do_global_parameter(lp_ctx, "debug uid", "No");
2709 lpcfg_do_global_parameter(lp_ctx, "debug class", "No");
2710 lpcfg_do_global_parameter(lp_ctx, "winbind debug traceid", "Yes");
2712 lpcfg_do_global_parameter(lp_ctx, "server role", "auto");
2713 lpcfg_do_global_parameter(lp_ctx, "domain logons", "No");
2714 lpcfg_do_global_parameter(lp_ctx, "domain master", "Auto");
2716 /* options that can be set on the command line must be initialised via
2717 the slower lpcfg_do_global_parameter() to ensure that FLAG_CMDLINE is obeyed */
2718 #ifdef TCP_NODELAY
2719 lpcfg_do_global_parameter(lp_ctx, "socket options", "TCP_NODELAY");
2720 #endif
2721 lpcfg_do_global_parameter(lp_ctx, "workgroup", DEFAULT_WORKGROUP);
2722 myname = get_myname(lp_ctx);
2723 lpcfg_do_global_parameter(lp_ctx, "netbios name", myname);
2724 talloc_free(myname);
2725 lpcfg_do_global_parameter(lp_ctx,
2726 "name resolve order",
2727 DEFAULT_NAME_RESOLVE_ORDER);
2729 lpcfg_do_global_parameter(lp_ctx, "fstype", "NTFS");
2731 lpcfg_do_global_parameter(lp_ctx, "ntvfs handler", "unixuid default");
2732 lpcfg_do_global_parameter(lp_ctx, "max connections", "0");
2734 lpcfg_do_global_parameter(lp_ctx, "dcerpc endpoint servers", "epmapper wkssvc samr netlogon lsarpc drsuapi dssetup unixinfo browser eventlog6 backupkey dnsserver");
2735 lpcfg_do_global_parameter(lp_ctx, "server services", "s3fs rpc nbt wrepl ldap cldap kdc drepl winbindd ntp_signd kcc dnsupdate dns");
2736 lpcfg_do_global_parameter(lp_ctx, "kccsrv:samba_kcc", "true");
2737 /* the winbind method for domain controllers is for both RODC
2738 auth forwarding and for trusted domains */
2739 lpcfg_do_global_parameter(lp_ctx, "private dir", dyn_PRIVATE_DIR);
2740 lpcfg_do_global_parameter(lp_ctx, "binddns dir", dyn_BINDDNS_DIR);
2741 lpcfg_do_global_parameter(lp_ctx, "registry:HKEY_LOCAL_MACHINE", "hklm.ldb");
2743 /* This hive should be dynamically generated by Samba using
2744 data from the sam, but for the moment leave it in a tdb to
2745 keep regedt32 from popping up an annoying dialog. */
2746 lpcfg_do_global_parameter(lp_ctx, "registry:HKEY_USERS", "hku.ldb");
2748 /* using UTF8 by default allows us to support all chars */
2749 lpcfg_do_global_parameter(lp_ctx, "unix charset", "UTF-8");
2751 /* Use codepage 850 as a default for the dos character set */
2752 lpcfg_do_global_parameter(lp_ctx, "dos charset", "CP850");
2755 * Allow the default PASSWD_CHAT to be overridden in local.h.
2757 lpcfg_do_global_parameter(lp_ctx, "passwd chat", DEFAULT_PASSWD_CHAT);
2759 lpcfg_do_global_parameter(lp_ctx, "pid directory", dyn_PIDDIR);
2760 lpcfg_do_global_parameter(lp_ctx, "lock dir", dyn_LOCKDIR);
2761 lpcfg_do_global_parameter(lp_ctx, "state directory", dyn_STATEDIR);
2762 lpcfg_do_global_parameter(lp_ctx, "cache directory", dyn_CACHEDIR);
2763 lpcfg_do_global_parameter(lp_ctx, "ncalrpc dir", dyn_NCALRPCDIR);
2765 lpcfg_do_global_parameter(lp_ctx, "nbt client socket address", "0.0.0.0");
2766 lpcfg_do_global_parameter_var(lp_ctx, "server string",
2767 "Samba %s", SAMBA_VERSION_STRING);
2769 lpcfg_do_global_parameter(lp_ctx, "password server", "*");
2771 lpcfg_do_global_parameter(lp_ctx, "max mux", "50");
2772 lpcfg_do_global_parameter(lp_ctx, "max xmit", "16644");
2773 lpcfg_do_global_parameter(lp_ctx, "host msdfs", "true");
2775 lpcfg_do_global_parameter(lp_ctx, "LargeReadwrite", "True");
2776 lpcfg_do_global_parameter(lp_ctx, "server min protocol", "SMB2_02");
2777 lpcfg_do_global_parameter(lp_ctx, "server max protocol", "SMB3");
2778 lpcfg_do_global_parameter(lp_ctx, "client min protocol", "SMB2_02");
2779 lpcfg_do_global_parameter(lp_ctx, "client max protocol", "default");
2780 lpcfg_do_global_parameter(lp_ctx, "client ipc min protocol", "default");
2781 lpcfg_do_global_parameter(lp_ctx, "client ipc max protocol", "default");
2782 lpcfg_do_global_parameter(lp_ctx, "security", "AUTO");
2783 lpcfg_do_global_parameter(lp_ctx, "EncryptPasswords", "True");
2784 lpcfg_do_global_parameter(lp_ctx, "ReadRaw", "True");
2785 lpcfg_do_global_parameter(lp_ctx, "WriteRaw", "True");
2786 lpcfg_do_global_parameter(lp_ctx, "NullPasswords", "False");
2787 lpcfg_do_global_parameter(lp_ctx, "old password allowed period", "60");
2788 lpcfg_do_global_parameter(lp_ctx, "ObeyPamRestrictions", "False");
2790 lpcfg_do_global_parameter(lp_ctx, "TimeServer", "False");
2791 lpcfg_do_global_parameter(lp_ctx, "BindInterfacesOnly", "False");
2792 lpcfg_do_global_parameter(lp_ctx, "Unicode", "True");
2793 lpcfg_do_global_parameter(lp_ctx, "ClientLanManAuth", "False");
2794 lpcfg_do_global_parameter(lp_ctx, "ClientNTLMv2Auth", "True");
2795 lpcfg_do_global_parameter(lp_ctx, "LanmanAuth", "False");
2796 lpcfg_do_global_parameter(lp_ctx, "NTLMAuth", "ntlmv2-only");
2797 lpcfg_do_global_parameter(lp_ctx, "NT hash store", "always");
2798 lpcfg_do_global_parameter(lp_ctx, "RawNTLMv2Auth", "False");
2799 lpcfg_do_global_parameter(lp_ctx, "client use spnego principal", "False");
2801 lpcfg_do_global_parameter(lp_ctx, "allow dcerpc auth level connect", "False");
2803 lpcfg_do_global_parameter(lp_ctx, "UnixExtensions", "True");
2805 lpcfg_do_global_parameter(lp_ctx, "PreferredMaster", "Auto");
2806 lpcfg_do_global_parameter(lp_ctx, "LocalMaster", "True");
2808 lpcfg_do_global_parameter(lp_ctx, "wins support", "False");
2809 lpcfg_do_global_parameter(lp_ctx, "dns proxy", "True");
2811 lpcfg_do_global_parameter(lp_ctx, "winbind separator", "\\");
2812 lpcfg_do_global_parameter(lp_ctx, "winbind sealed pipes", "True");
2813 lpcfg_do_global_parameter(lp_ctx, "winbind scan trusted domains", "False");
2814 lpcfg_do_global_parameter(lp_ctx, "require strong key", "True");
2815 lpcfg_do_global_parameter(lp_ctx, "reject md5 servers", "True");
2816 lpcfg_do_global_parameter(lp_ctx, "winbindd socket directory", dyn_WINBINDD_SOCKET_DIR);
2817 lpcfg_do_global_parameter(lp_ctx, "ntp signd socket directory", dyn_NTP_SIGND_SOCKET_DIR);
2818 lpcfg_do_global_parameter_var(lp_ctx, "gpo update command", "%s/samba-gpupdate", dyn_SCRIPTSBINDIR);
2819 lpcfg_do_global_parameter_var(lp_ctx, "apply group policies", "False");
2820 lpcfg_do_global_parameter_var(lp_ctx, "dns update command", "%s/samba_dnsupdate", dyn_SCRIPTSBINDIR);
2821 lpcfg_do_global_parameter_var(lp_ctx, "spn update command", "%s/samba_spnupdate", dyn_SCRIPTSBINDIR);
2822 lpcfg_do_global_parameter_var(lp_ctx, "samba kcc command",
2823 "%s/samba_kcc", dyn_SCRIPTSBINDIR);
2824 #ifdef MIT_KDC_PATH
2825 lpcfg_do_global_parameter_var(lp_ctx,
2826 "mit kdc command",
2827 MIT_KDC_PATH);
2828 #endif
2829 lpcfg_do_global_parameter(lp_ctx, "template shell", "/bin/false");
2830 lpcfg_do_global_parameter(lp_ctx, "template homedir", "/home/%D/%U");
2832 lpcfg_do_global_parameter(lp_ctx, "client signing", "default");
2833 lpcfg_do_global_parameter(lp_ctx, "client ipc signing", "default");
2834 lpcfg_do_global_parameter(lp_ctx, "server signing", "default");
2836 lpcfg_do_global_parameter(lp_ctx, "use mmap", "True");
2838 lpcfg_do_global_parameter(lp_ctx, "smb ports", "445 139");
2839 lpcfg_do_global_parameter_var(lp_ctx, "nbt port", "%d", NBT_NAME_SERVICE_PORT);
2840 lpcfg_do_global_parameter_var(lp_ctx, "dgram port", "%d", NBT_DGRAM_SERVICE_PORT);
2841 lpcfg_do_global_parameter(lp_ctx, "cldap port", "389");
2842 lpcfg_do_global_parameter(lp_ctx, "krb5 port", "88");
2843 lpcfg_do_global_parameter(lp_ctx, "kpasswd port", "464");
2844 lpcfg_do_global_parameter_var(lp_ctx, "dns port", "%d", DNS_SERVICE_PORT);
2846 lpcfg_do_global_parameter(lp_ctx, "kdc enable fast", "True");
2848 lpcfg_do_global_parameter(lp_ctx, "nt status support", "True");
2850 lpcfg_do_global_parameter(lp_ctx, "max wins ttl", "518400"); /* 6 days */
2851 lpcfg_do_global_parameter(lp_ctx, "min wins ttl", "21600");
2853 lpcfg_do_global_parameter(lp_ctx, "tls enabled", "True");
2854 lpcfg_do_global_parameter(lp_ctx, "tls verify peer", "as_strict_as_possible");
2855 lpcfg_do_global_parameter(lp_ctx, "tls keyfile", "tls/key.pem");
2856 lpcfg_do_global_parameter(lp_ctx, "tls certfile", "tls/cert.pem");
2857 lpcfg_do_global_parameter(lp_ctx, "tls cafile", "tls/ca.pem");
2858 lpcfg_do_global_parameter(lp_ctx,
2859 "tls priority",
2860 "NORMAL:-VERS-SSL3.0");
2862 lpcfg_do_global_parameter(lp_ctx, "nsupdate command", "/usr/bin/nsupdate -g");
2864 lpcfg_do_global_parameter(lp_ctx, "allow dns updates", "secure only");
2865 lpcfg_do_global_parameter(lp_ctx, "dns zone scavenging", "False");
2866 lpcfg_do_global_parameter(lp_ctx, "dns forwarder", "");
2868 lpcfg_do_global_parameter(lp_ctx, "algorithmic rid base", "1000");
2870 lpcfg_do_global_parameter(lp_ctx, "enhanced browsing", "True");
2872 lpcfg_do_global_parameter(lp_ctx, "winbind nss info", "template");
2874 lpcfg_do_global_parameter(lp_ctx, "server schannel", "True");
2875 lpcfg_do_global_parameter(lp_ctx, "server schannel require seal", "True");
2876 lpcfg_do_global_parameter(lp_ctx, "reject md5 clients", "True");
2878 lpcfg_do_global_parameter(lp_ctx, "short preserve case", "True");
2880 lpcfg_do_global_parameter(lp_ctx, "max open files", "16384");
2882 lpcfg_do_global_parameter(lp_ctx, "cups connection timeout", "30");
2884 lpcfg_do_global_parameter(lp_ctx, "locking", "True");
2886 lpcfg_do_global_parameter(lp_ctx, "block size", "1024");
2888 lpcfg_do_global_parameter(lp_ctx, "client use spnego", "True");
2890 lpcfg_do_global_parameter(lp_ctx, "change notify", "True");
2892 lpcfg_do_global_parameter(lp_ctx, "name cache timeout", "660");
2894 lpcfg_do_global_parameter(lp_ctx, "defer sharing violations", "True");
2896 lpcfg_do_global_parameter(lp_ctx, "ldap replication sleep", "1000");
2898 lpcfg_do_global_parameter(lp_ctx, "idmap backend", "tdb");
2900 lpcfg_do_global_parameter(lp_ctx, "enable privileges", "True");
2902 lpcfg_do_global_parameter_var(lp_ctx, "smb2 max write", "%u", DEFAULT_SMB2_MAX_WRITE);
2904 lpcfg_do_global_parameter(lp_ctx, "passdb backend", "tdbsam");
2906 lpcfg_do_global_parameter(lp_ctx, "deadtime", "10080");
2908 lpcfg_do_global_parameter(lp_ctx, "getwd cache", "True");
2910 lpcfg_do_global_parameter(lp_ctx, "winbind nested groups", "True");
2912 lpcfg_do_global_parameter(lp_ctx, "mangled names", "illegal");
2914 lpcfg_do_global_parameter_var(lp_ctx, "smb2 max credits", "%u", DEFAULT_SMB2_MAX_CREDITS);
2916 lpcfg_do_global_parameter(lp_ctx, "ldap ssl", "start tls");
2918 lpcfg_do_global_parameter(lp_ctx, "ldap deref", "auto");
2920 lpcfg_do_global_parameter(lp_ctx, "lm interval", "60");
2922 lpcfg_do_global_parameter(lp_ctx, "mangling method", "hash2");
2924 lpcfg_do_global_parameter(lp_ctx, "hide dot files", "True");
2926 lpcfg_do_global_parameter(lp_ctx, "browse list", "True");
2928 lpcfg_do_global_parameter(lp_ctx, "passwd chat timeout", "2");
2930 lpcfg_do_global_parameter(lp_ctx, "guest account", GUEST_ACCOUNT);
2932 lpcfg_do_global_parameter(lp_ctx, "client schannel", "True");
2934 lpcfg_do_global_parameter(lp_ctx, "smb encrypt", "default");
2936 lpcfg_do_global_parameter(lp_ctx, "max log size", "5000");
2938 lpcfg_do_global_parameter(lp_ctx, "idmap negative cache time", "120");
2940 lpcfg_do_global_parameter(lp_ctx, "ldap follow referral", "auto");
2942 lpcfg_do_global_parameter(lp_ctx, "multicast dns register", "yes");
2944 lpcfg_do_global_parameter(lp_ctx, "winbind reconnect delay", "30");
2946 lpcfg_do_global_parameter(lp_ctx, "winbind request timeout", "60");
2948 lpcfg_do_global_parameter(lp_ctx, "nt acl support", "yes");
2950 lpcfg_do_global_parameter(lp_ctx, "acl check permissions", "yes");
2952 lpcfg_do_global_parameter(lp_ctx, "keepalive", "300");
2954 lpcfg_do_global_parameter(lp_ctx, "smbd profiling level", "off");
2956 lpcfg_do_global_parameter(lp_ctx, "winbind cache time", "300");
2958 lpcfg_do_global_parameter(lp_ctx, "level2 oplocks", "yes");
2960 lpcfg_do_global_parameter(lp_ctx, "show add printer wizard", "yes");
2962 lpcfg_do_global_parameter(lp_ctx, "ldap page size", "1000");
2964 lpcfg_do_global_parameter(lp_ctx, "kernel share modes", "no");
2966 lpcfg_do_global_parameter(lp_ctx, "strict locking", "Auto");
2968 lpcfg_do_global_parameter(lp_ctx, "strict sync", "yes");
2970 lpcfg_do_global_parameter(lp_ctx, "map readonly", "no");
2972 lpcfg_do_global_parameter(lp_ctx, "allow trusted domains", "yes");
2974 lpcfg_do_global_parameter(lp_ctx, "default devmode", "yes");
2976 lpcfg_do_global_parameter(lp_ctx, "os level", "20");
2978 lpcfg_do_global_parameter(lp_ctx, "dos filetimes", "yes");
2980 lpcfg_do_global_parameter(lp_ctx, "mangling char", "~");
2982 lpcfg_do_global_parameter(lp_ctx, "printcap cache time", "750");
2984 lpcfg_do_global_parameter(lp_ctx, "create krb5 conf", "yes");
2986 lpcfg_do_global_parameter(lp_ctx, "winbind max clients", "200");
2988 lpcfg_do_global_parameter(lp_ctx, "acl map full control", "yes");
2990 lpcfg_do_global_parameter(lp_ctx, "nt pipe support", "yes");
2992 lpcfg_do_global_parameter(lp_ctx, "ldap debug threshold", "10");
2994 lpcfg_do_global_parameter(lp_ctx, "client ldap sasl wrapping", "seal");
2996 lpcfg_do_global_parameter(lp_ctx, "mdns name", "netbios");
2998 lpcfg_do_global_parameter(lp_ctx, "ldap server require strong auth", "yes");
3000 lpcfg_do_global_parameter(lp_ctx, "follow symlinks", "yes");
3002 lpcfg_do_global_parameter(lp_ctx, "machine password timeout", "604800");
3004 lpcfg_do_global_parameter(lp_ctx, "ldap connection timeout", "2");
3006 lpcfg_do_global_parameter(lp_ctx, "winbind expand groups", "0");
3008 lpcfg_do_global_parameter(lp_ctx, "stat cache", "yes");
3010 lpcfg_do_global_parameter(lp_ctx, "lpq cache time", "30");
3012 lpcfg_do_global_parameter_var(lp_ctx, "smb2 max trans", "%u", DEFAULT_SMB2_MAX_TRANSACT);
3014 lpcfg_do_global_parameter_var(lp_ctx, "smb2 max read", "%u", DEFAULT_SMB2_MAX_READ);
3016 lpcfg_do_global_parameter(lp_ctx, "durable handles", "yes");
3018 lpcfg_do_global_parameter(lp_ctx, "max stat cache size", "512");
3020 lpcfg_do_global_parameter(lp_ctx, "ldap passwd sync", "no");
3022 lpcfg_do_global_parameter(lp_ctx, "kernel change notify", "yes");
3024 lpcfg_do_global_parameter(lp_ctx, "max ttl", "259200");
3026 lpcfg_do_global_parameter(lp_ctx, "blocking locks", "yes");
3028 lpcfg_do_global_parameter(lp_ctx, "load printers", "yes");
3030 lpcfg_do_global_parameter(lp_ctx, "idmap cache time", "604800");
3032 lpcfg_do_global_parameter(lp_ctx, "preserve case", "yes");
3034 lpcfg_do_global_parameter(lp_ctx, "lm announce", "auto");
3036 lpcfg_do_global_parameter(lp_ctx, "afs token lifetime", "604800");
3038 lpcfg_do_global_parameter(lp_ctx, "enable core files", "yes");
3040 lpcfg_do_global_parameter(lp_ctx, "winbind max domain connections", "1");
3042 lpcfg_do_global_parameter(lp_ctx, "case sensitive", "auto");
3044 lpcfg_do_global_parameter(lp_ctx, "ldap timeout", "15");
3046 lpcfg_do_global_parameter(lp_ctx, "mangle prefix", "1");
3048 lpcfg_do_global_parameter(lp_ctx, "posix locking", "yes");
3050 lpcfg_do_global_parameter(lp_ctx, "lock spin time", "200");
3052 lpcfg_do_global_parameter(lp_ctx, "nmbd bind explicit broadcast", "yes");
3054 lpcfg_do_global_parameter(lp_ctx, "init logon delay", "100");
3056 lpcfg_do_global_parameter(lp_ctx, "usershare owner only", "yes");
3058 lpcfg_do_global_parameter(lp_ctx, "-valid", "yes");
3060 lpcfg_do_global_parameter_var(lp_ctx, "usershare path", "%s/usershares", get_dyn_STATEDIR());
3062 #ifdef DEVELOPER
3063 lpcfg_do_global_parameter_var(lp_ctx, "panic action", "/bin/sleep 999999999");
3064 #endif
3066 lpcfg_do_global_parameter(lp_ctx, "smb passwd file", get_dyn_SMB_PASSWD_FILE());
3068 lpcfg_do_global_parameter(lp_ctx, "logon home", "\\\\%N\\%U");
3070 lpcfg_do_global_parameter(lp_ctx, "logon path", "\\\\%N\\%U\\profile");
3072 lpcfg_do_global_parameter(lp_ctx, "printjob username", "%U");
3074 lpcfg_do_global_parameter(lp_ctx, "aio max threads", "100");
3076 lpcfg_do_global_parameter(lp_ctx, "smb2 leases", "yes");
3078 lpcfg_do_global_parameter(lp_ctx, "server multi channel support", "yes");
3080 lpcfg_do_global_parameter(lp_ctx, "kerberos encryption types", "all");
3082 lpcfg_do_global_parameter(lp_ctx,
3083 "rpc server dynamic port range",
3084 "49152-65535");
3086 lpcfg_do_global_parameter(lp_ctx, "prefork children", "4");
3087 lpcfg_do_global_parameter(lp_ctx, "prefork backoff increment", "10");
3088 lpcfg_do_global_parameter(lp_ctx, "prefork maximum backoff", "120");
3090 lpcfg_do_global_parameter(lp_ctx, "check parent directory delete on close", "no");
3092 lpcfg_do_global_parameter(lp_ctx, "ea support", "yes");
3094 lpcfg_do_global_parameter(lp_ctx, "store dos attributes", "yes");
3096 lpcfg_do_global_parameter(lp_ctx, "debug encryption", "no");
3098 lpcfg_do_global_parameter(lp_ctx, "spotlight backend", "noindex");
3100 lpcfg_do_global_parameter(
3101 lp_ctx, "ldap max anonymous request size", "256000");
3102 lpcfg_do_global_parameter(
3103 lp_ctx, "ldap max authenticated request size", "16777216");
3104 lpcfg_do_global_parameter(
3105 lp_ctx, "ldap max search request size", "256000");
3107 /* Async DNS query timeout in seconds. */
3108 lpcfg_do_global_parameter(lp_ctx, "async dns timeout", "10");
3110 lpcfg_do_global_parameter(lp_ctx,
3111 "client smb encrypt",
3112 "default");
3114 lpcfg_do_global_parameter(lp_ctx,
3115 "client use kerberos",
3116 "desired");
3118 lpcfg_do_global_parameter(lp_ctx,
3119 "client protection",
3120 "default");
3122 lpcfg_do_global_parameter(lp_ctx,
3123 "smbd max xattr size",
3124 "65536");
3126 lpcfg_do_global_parameter(lp_ctx,
3127 "acl flag inherited canonicalization",
3128 "yes");
3130 lpcfg_do_global_parameter(lp_ctx,
3131 "winbind use krb5 enterprise principals",
3132 "yes");
3134 lpcfg_do_global_parameter(lp_ctx,
3135 "client smb3 signing algorithms",
3136 DEFAULT_SMB3_SIGNING_ALGORITHMS);
3137 lpcfg_do_global_parameter(lp_ctx,
3138 "server smb3 signing algorithms",
3139 DEFAULT_SMB3_SIGNING_ALGORITHMS);
3141 lpcfg_do_global_parameter(lp_ctx,
3142 "client smb3 encryption algorithms",
3143 DEFAULT_SMB3_ENCRYPTION_ALGORITHMS);
3144 lpcfg_do_global_parameter(lp_ctx,
3145 "server smb3 encryption algorithms",
3146 DEFAULT_SMB3_ENCRYPTION_ALGORITHMS);
3148 lpcfg_do_global_parameter(lp_ctx,
3149 "min domain uid",
3150 "1000");
3152 lpcfg_do_global_parameter(lp_ctx,
3153 "rpc start on demand helpers",
3154 "yes");
3156 lpcfg_do_global_parameter(lp_ctx,
3157 "ad dc functional level",
3158 "2008_R2");
3160 lpcfg_do_global_parameter(lp_ctx,
3161 "acl claims evaluation",
3162 "AD DC only");
3164 for (i = 0; parm_table[i].label; i++) {
3165 if (!(lp_ctx->flags[i] & FLAG_CMDLINE)) {
3166 lp_ctx->flags[i] |= FLAG_DEFAULT;
3170 for (parm=lp_ctx->globals->param_opt; parm; parm=parm->next) {
3171 if (!(parm->priority & FLAG_CMDLINE)) {
3172 parm->priority |= FLAG_DEFAULT;
3176 for (parm=lp_ctx->sDefault->param_opt; parm; parm=parm->next) {
3177 if (!(parm->priority & FLAG_CMDLINE)) {
3178 parm->priority |= FLAG_DEFAULT;
3182 return lp_ctx;
3186 * Initialise the global parameter structure.
3188 struct loadparm_context *loadparm_init_global(bool load_default)
3190 if (global_loadparm_context == NULL) {
3191 global_loadparm_context = loadparm_init(NULL);
3193 if (global_loadparm_context == NULL) {
3194 return NULL;
3196 global_loadparm_context->global = true;
3197 if (load_default && !global_loadparm_context->loaded) {
3198 lpcfg_load_default(global_loadparm_context);
3200 global_loadparm_context->refuse_free = true;
3201 return global_loadparm_context;
3205 * @brief Initialise the global parameter structure.
3207 * This function initialized the globals if needed. Make sure that
3208 * gfree_loadparm() is called before the application exits.
3210 * @param mem_ctx The talloc memory context to allocate lp_ctx on.
3212 * @param s3_fns The loadparm helper functions to use
3214 * @return An initialized lp_ctx pointer or NULL on error.
3216 struct loadparm_context *loadparm_init_s3(TALLOC_CTX *mem_ctx,
3217 const struct loadparm_s3_helpers *s3_fns)
3219 struct loadparm_context *loadparm_context = talloc_zero(mem_ctx, struct loadparm_context);
3220 if (!loadparm_context) {
3221 return NULL;
3223 loadparm_context->s3_fns = s3_fns;
3224 loadparm_context->globals = s3_fns->globals;
3225 loadparm_context->flags = s3_fns->flags;
3227 /* Make sure globals are correctly initialized */
3228 loadparm_context->s3_fns->init_globals(loadparm_context, false);
3230 return loadparm_context;
3233 const char *lpcfg_configfile(struct loadparm_context *lp_ctx)
3235 return lp_ctx->szConfigFile;
3238 const char *lp_default_path(void)
3240 if (getenv("SMB_CONF_PATH"))
3241 return getenv("SMB_CONF_PATH");
3242 else
3243 return dyn_CONFIGFILE;
3247 * Update the internal state of a loadparm context after settings
3248 * have changed.
3250 static bool lpcfg_update(struct loadparm_context *lp_ctx)
3252 struct debug_settings settings;
3253 int max_protocol, min_protocol;
3254 TALLOC_CTX *tmp_ctx;
3255 const struct loadparm_substitution *lp_sub =
3256 lpcfg_noop_substitution();
3258 tmp_ctx = talloc_new(lp_ctx);
3259 if (tmp_ctx == NULL) {
3260 return false;
3263 lpcfg_add_auto_services(lp_ctx, lpcfg_auto_services(lp_ctx, lp_sub, tmp_ctx));
3265 if (!lp_ctx->globals->wins_server_list && lp_ctx->globals->we_are_a_wins_server) {
3266 lpcfg_do_global_parameter(lp_ctx, "wins server", "127.0.0.1");
3269 if (!lp_ctx->global) {
3270 TALLOC_FREE(tmp_ctx);
3271 return true;
3274 panic_action = lp_ctx->globals->panic_action;
3276 reload_charcnv(lp_ctx);
3278 ZERO_STRUCT(settings);
3279 /* Add any more debug-related smb.conf parameters created in
3280 * future here */
3281 settings.timestamp_logs = lp_ctx->globals->timestamp_logs;
3282 settings.debug_prefix_timestamp = lp_ctx->globals->debug_prefix_timestamp;
3283 settings.debug_hires_timestamp = lp_ctx->globals->debug_hires_timestamp;
3284 settings.debug_syslog_format = lp_ctx->globals->debug_syslog_format;
3285 settings.debug_pid = lp_ctx->globals->debug_pid;
3286 settings.debug_uid = lp_ctx->globals->debug_uid;
3287 settings.debug_class = lp_ctx->globals->debug_class;
3288 settings.max_log_size = lp_ctx->globals->max_log_size;
3289 debug_set_settings(&settings, lp_ctx->globals->logging,
3290 lp_ctx->globals->syslog,
3291 lp_ctx->globals->syslog_only);
3293 /* FIXME: This is a bit of a hack, but we can't use a global, since
3294 * not everything that uses lp also uses the socket library */
3295 if (lpcfg_parm_bool(lp_ctx, NULL, "socket", "testnonblock", false)) {
3296 setenv("SOCKET_TESTNONBLOCK", "1", 1);
3297 } else {
3298 unsetenv("SOCKET_TESTNONBLOCK");
3301 /* Check if command line max protocol < min protocol, if so
3302 * report a warning to the user.
3304 max_protocol = lpcfg_client_max_protocol(lp_ctx);
3305 min_protocol = lpcfg_client_min_protocol(lp_ctx);
3306 if (lpcfg_client_max_protocol(lp_ctx) < lpcfg_client_min_protocol(lp_ctx)) {
3307 const char *max_protocolp, *min_protocolp;
3308 max_protocolp = lpcfg_get_smb_protocol(max_protocol);
3309 min_protocolp = lpcfg_get_smb_protocol(min_protocol);
3310 DBG_ERR("Max protocol %s is less than min protocol %s.\n",
3311 max_protocolp, min_protocolp);
3314 TALLOC_FREE(tmp_ctx);
3315 return true;
3318 bool lpcfg_load_default(struct loadparm_context *lp_ctx)
3320 const char *path;
3322 path = lp_default_path();
3324 if (!file_exist(path)) {
3325 /* We allow the default smb.conf file to not exist,
3326 * basically the equivalent of an empty file. */
3327 return lpcfg_update(lp_ctx);
3330 return lpcfg_load(lp_ctx, path);
3334 * Load the services array from the services file.
3336 * Return True on success, False on failure.
3338 static bool lpcfg_load_internal(struct loadparm_context *lp_ctx,
3339 const char *filename, bool set_global)
3341 char *n2;
3342 bool bRetval;
3344 if (lp_ctx->szConfigFile != NULL) {
3345 talloc_free(discard_const_p(char, lp_ctx->szConfigFile));
3346 lp_ctx->szConfigFile = NULL;
3349 lp_ctx->szConfigFile = talloc_strdup(lp_ctx, filename);
3351 if (lp_ctx->s3_fns) {
3352 return lp_ctx->s3_fns->load(filename);
3355 lp_ctx->bInGlobalSection = true;
3356 n2 = standard_sub_basic(lp_ctx, lp_ctx->szConfigFile);
3357 DEBUG(2, ("lpcfg_load: refreshing parameters from %s\n", n2));
3359 add_to_file_list(lp_ctx, &lp_ctx->file_lists, lp_ctx->szConfigFile, n2);
3361 /* We get sections first, so have to start 'behind' to make up */
3362 lp_ctx->currentService = NULL;
3363 bRetval = pm_process(n2, do_section, lpcfg_do_parameter, lp_ctx);
3365 /* finish up the last section */
3366 DEBUG(4, ("pm_process() returned %s\n", BOOLSTR(bRetval)));
3367 if (bRetval)
3368 if (lp_ctx->currentService != NULL)
3369 bRetval = lpcfg_service_ok(lp_ctx->currentService);
3371 bRetval = bRetval && lpcfg_update(lp_ctx);
3373 /* we do this unconditionally, so that it happens even
3374 for a missing smb.conf */
3375 reload_charcnv(lp_ctx);
3377 if (bRetval == true && set_global) {
3378 /* set this up so that any child python tasks will
3379 find the right smb.conf */
3380 setenv("SMB_CONF_PATH", filename, 1);
3382 /* set the context used by the lp_*() function
3383 variants */
3384 global_loadparm_context = lp_ctx;
3385 lp_ctx->loaded = true;
3388 return bRetval;
3391 bool lpcfg_load_no_global(struct loadparm_context *lp_ctx, const char *filename)
3393 return lpcfg_load_internal(lp_ctx, filename, false);
3396 bool lpcfg_load(struct loadparm_context *lp_ctx, const char *filename)
3398 return lpcfg_load_internal(lp_ctx, filename, true);
3402 * Return the max number of services.
3405 int lpcfg_numservices(struct loadparm_context *lp_ctx)
3407 if (lp_ctx->s3_fns) {
3408 return lp_ctx->s3_fns->get_numservices();
3411 return lp_ctx->iNumServices;
3415 * Display the contents of the services array in human-readable form.
3418 void lpcfg_dump(struct loadparm_context *lp_ctx, FILE *f, bool show_defaults,
3419 int maxtoprint)
3421 int iService;
3423 if (lp_ctx->s3_fns) {
3424 lp_ctx->s3_fns->dump(f, show_defaults, maxtoprint);
3425 return;
3428 lpcfg_dump_globals(lp_ctx, f, show_defaults);
3430 lpcfg_dump_a_service(lp_ctx->sDefault, lp_ctx->sDefault, f, lp_ctx->flags, show_defaults);
3432 for (iService = 0; iService < maxtoprint; iService++)
3433 lpcfg_dump_one(f, show_defaults, lp_ctx->services[iService], lp_ctx->sDefault);
3437 * Display the contents of one service in human-readable form.
3439 void lpcfg_dump_one(FILE *f, bool show_defaults, struct loadparm_service *service, struct loadparm_service *sDefault)
3441 if (service != NULL) {
3442 if (service->szService[0] == '\0')
3443 return;
3444 lpcfg_dump_a_service(service, sDefault, f, NULL, show_defaults);
3448 struct loadparm_service *lpcfg_servicebynum(struct loadparm_context *lp_ctx,
3449 int snum)
3451 if (lp_ctx->s3_fns) {
3452 return lp_ctx->s3_fns->get_servicebynum(snum);
3455 return lp_ctx->services[snum];
3458 struct loadparm_service *lpcfg_service(struct loadparm_context *lp_ctx,
3459 const char *service_name)
3461 int iService;
3462 char *serviceName;
3464 if (lp_ctx->s3_fns) {
3465 return lp_ctx->s3_fns->get_service(service_name);
3468 for (iService = lp_ctx->iNumServices - 1; iService >= 0; iService--) {
3469 if (lp_ctx->services[iService] &&
3470 lp_ctx->services[iService]->szService) {
3472 * The substitution here is used to support %U is
3473 * service names
3475 serviceName = standard_sub_basic(
3476 lp_ctx->services[iService],
3477 lp_ctx->services[iService]->szService);
3478 if (strequal(serviceName, service_name)) {
3479 talloc_free(serviceName);
3480 return lp_ctx->services[iService];
3482 talloc_free(serviceName);
3486 DEBUG(7,("lpcfg_servicenumber: couldn't find %s\n", service_name));
3487 return NULL;
3490 const char *lpcfg_servicename(const struct loadparm_service *service)
3492 return service ? lpcfg_string((const char *)service->szService) : NULL;
3495 struct smb_iconv_handle *lpcfg_iconv_handle(struct loadparm_context *lp_ctx)
3497 if (lp_ctx == NULL) {
3498 return get_iconv_handle();
3500 return lp_ctx->iconv_handle;
3503 _PUBLIC_ void reload_charcnv(struct loadparm_context *lp_ctx)
3505 if (!lp_ctx->global) {
3506 return;
3509 lp_ctx->iconv_handle =
3510 reinit_iconv_handle(lp_ctx,
3511 lpcfg_dos_charset(lp_ctx),
3512 lpcfg_unix_charset(lp_ctx));
3513 if (lp_ctx->iconv_handle == NULL) {
3514 smb_panic("reinit_iconv_handle failed");
3518 _PUBLIC_ char *lpcfg_tls_keyfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
3520 return lpcfg_private_path(mem_ctx, lp_ctx, lpcfg__tls_keyfile(lp_ctx));
3523 _PUBLIC_ char *lpcfg_tls_certfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
3525 return lpcfg_private_path(mem_ctx, lp_ctx, lpcfg__tls_certfile(lp_ctx));
3528 _PUBLIC_ char *lpcfg_tls_cafile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
3530 return lpcfg_private_path(mem_ctx, lp_ctx, lpcfg__tls_cafile(lp_ctx));
3533 _PUBLIC_ char *lpcfg_tls_crlfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
3535 return lpcfg_private_path(mem_ctx, lp_ctx, lpcfg__tls_crlfile(lp_ctx));
3538 _PUBLIC_ char *lpcfg_tls_dhpfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
3540 return lpcfg_private_path(mem_ctx, lp_ctx, lpcfg__tls_dhpfile(lp_ctx));
3543 struct gensec_settings *lpcfg_gensec_settings(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
3545 struct gensec_settings *settings = talloc_zero(mem_ctx, struct gensec_settings);
3546 if (settings == NULL)
3547 return NULL;
3548 SMB_ASSERT(lp_ctx != NULL);
3549 settings->lp_ctx = talloc_reference(settings, lp_ctx);
3550 settings->target_hostname = lpcfg_parm_string(lp_ctx, NULL, "gensec", "target_hostname");
3551 return settings;
3554 int lpcfg_server_role(struct loadparm_context *lp_ctx)
3556 int domain_master = lpcfg__domain_master(lp_ctx);
3558 return lp_find_server_role(lpcfg__server_role(lp_ctx),
3559 lpcfg__security(lp_ctx),
3560 lpcfg__domain_logons(lp_ctx),
3561 (domain_master == true) ||
3562 (domain_master == Auto));
3565 int lpcfg_security(struct loadparm_context *lp_ctx)
3567 return lp_find_security(lpcfg__server_role(lp_ctx),
3568 lpcfg__security(lp_ctx));
3571 int lpcfg_client_max_protocol(struct loadparm_context *lp_ctx)
3573 int client_max_protocol = lpcfg__client_max_protocol(lp_ctx);
3574 if (client_max_protocol == PROTOCOL_DEFAULT) {
3575 return PROTOCOL_LATEST;
3577 return client_max_protocol;
3580 int lpcfg_client_ipc_min_protocol(struct loadparm_context *lp_ctx)
3582 int client_ipc_min_protocol = lpcfg__client_ipc_min_protocol(lp_ctx);
3583 if (client_ipc_min_protocol == PROTOCOL_DEFAULT) {
3584 client_ipc_min_protocol = lpcfg_client_min_protocol(lp_ctx);
3586 if (client_ipc_min_protocol < PROTOCOL_NT1) {
3587 return PROTOCOL_NT1;
3589 return client_ipc_min_protocol;
3592 int lpcfg_client_ipc_max_protocol(struct loadparm_context *lp_ctx)
3594 int client_ipc_max_protocol = lpcfg__client_ipc_max_protocol(lp_ctx);
3595 if (client_ipc_max_protocol == PROTOCOL_DEFAULT) {
3596 return PROTOCOL_LATEST;
3598 if (client_ipc_max_protocol < PROTOCOL_NT1) {
3599 return PROTOCOL_NT1;
3601 return client_ipc_max_protocol;
3604 int lpcfg_client_ipc_signing(struct loadparm_context *lp_ctx)
3606 int client_ipc_signing = lpcfg__client_ipc_signing(lp_ctx);
3607 if (client_ipc_signing == SMB_SIGNING_DEFAULT) {
3608 return SMB_SIGNING_REQUIRED;
3610 return client_ipc_signing;
3613 enum credentials_use_kerberos lpcfg_client_use_kerberos(struct loadparm_context *lp_ctx)
3615 if (lpcfg_weak_crypto(lp_ctx) == SAMBA_WEAK_CRYPTO_DISALLOWED) {
3616 return CRED_USE_KERBEROS_REQUIRED;
3619 return lpcfg__client_use_kerberos(lp_ctx);
3622 bool lpcfg_server_signing_allowed(struct loadparm_context *lp_ctx, bool *mandatory)
3624 bool allowed = true;
3625 enum smb_signing_setting signing_setting = lpcfg_server_signing(lp_ctx);
3627 *mandatory = false;
3629 if (signing_setting == SMB_SIGNING_DEFAULT) {
3631 * If we are a domain controller, SMB signing is
3632 * really important, as it can prevent a number of
3633 * attacks on communications between us and the
3634 * clients
3636 * However, it really sucks (no sendfile, CPU
3637 * overhead) performance-wise when used on a
3638 * file server, so disable it by default
3639 * on non-DCs
3642 if (lpcfg_server_role(lp_ctx) >= ROLE_ACTIVE_DIRECTORY_DC) {
3643 signing_setting = SMB_SIGNING_REQUIRED;
3644 } else {
3645 signing_setting = SMB_SIGNING_OFF;
3649 switch (signing_setting) {
3650 case SMB_SIGNING_REQUIRED:
3651 *mandatory = true;
3652 break;
3653 case SMB_SIGNING_DESIRED:
3654 case SMB_SIGNING_IF_REQUIRED:
3655 break;
3656 case SMB_SIGNING_OFF:
3657 allowed = false;
3658 break;
3659 case SMB_SIGNING_DEFAULT:
3660 case SMB_SIGNING_IPC_DEFAULT:
3661 smb_panic(__location__);
3662 break;
3665 return allowed;
3668 int lpcfg_tdb_hash_size(struct loadparm_context *lp_ctx, const char *name)
3670 const char *base;
3672 if (name == NULL) {
3673 return 0;
3676 base = strrchr_m(name, '/');
3677 if (base != NULL) {
3678 base += 1;
3679 } else {
3680 base = name;
3682 return lpcfg_parm_int(lp_ctx, NULL, "tdb_hashsize", base, 0);
3686 int lpcfg_tdb_flags(struct loadparm_context *lp_ctx, int tdb_flags)
3688 if (!lpcfg_use_mmap(lp_ctx)) {
3689 tdb_flags |= TDB_NOMMAP;
3691 return tdb_flags;
3695 * Do not allow LanMan auth if unless NTLMv1 is also allowed
3697 * This also ensures it is disabled if NTLM is totally disabled
3699 bool lpcfg_lanman_auth(struct loadparm_context *lp_ctx)
3701 enum ntlm_auth_level ntlm_auth_level = lpcfg_ntlm_auth(lp_ctx);
3703 if (ntlm_auth_level == NTLM_AUTH_ON) {
3704 return lpcfg__lanman_auth(lp_ctx);
3705 } else {
3706 return false;
3710 static char *lpcfg_noop_substitution_fn(
3711 TALLOC_CTX *mem_ctx,
3712 const struct loadparm_substitution *lp_sub,
3713 const char *raw_value,
3714 void *private_data)
3716 return talloc_strdup(mem_ctx, raw_value);
3719 static const struct loadparm_substitution global_noop_substitution = {
3720 .substituted_string_fn = lpcfg_noop_substitution_fn,
3723 const struct loadparm_substitution *lpcfg_noop_substitution(void)
3725 return &global_noop_substitution;
3728 char *lpcfg_substituted_string(TALLOC_CTX *mem_ctx,
3729 const struct loadparm_substitution *lp_sub,
3730 const char *raw_value)
3732 return lp_sub->substituted_string_fn(mem_ctx,
3733 lp_sub,
3734 raw_value,
3735 lp_sub->private_data);
3739 * @brief Parse a string value of a given parameter to its integer enum value.
3741 * @param[in] param_name The parameter name (e.g. 'client smb encrypt')
3743 * @param[in] param_value The parameter value (e.g. 'required').
3745 * @return The integer value of the enum the param_value matches or INT32_MIN
3746 * on error.
3748 int32_t lpcfg_parse_enum_vals(const char *param_name,
3749 const char *param_value)
3751 struct parm_struct *parm = NULL;
3752 int32_t ret = INT32_MIN;
3753 bool ok;
3755 parm = lpcfg_parm_struct(NULL, param_name);
3756 if (parm == NULL) {
3757 return INT32_MIN;
3760 ok = lp_set_enum_parm(parm, param_value, &ret);
3761 if (!ok) {
3762 return INT32_MIN;
3765 return ret;