2 Unix SMB/CIFS implementation.
3 Parameter loading functions
4 Copyright (C) Karl Auer 1993-1998
6 Largely re-written by Andrew Tridgell, September 1994
8 Copyright (C) Simo Sorce 2001
9 Copyright (C) Alexander Bokovoy 2002
10 Copyright (C) Stefan (metze) Metzmacher 2002
11 Copyright (C) Jim McDonough (jmcd@us.ibm.com) 2003.
12 Copyright (C) James Myers 2003 <myersjj@samba.org>
13 Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2007
14 Copyright (C) Andrew Bartlett 2011-2012
16 This program is free software; you can redistribute it and/or modify
17 it under the terms of the GNU General Public License as published by
18 the Free Software Foundation; either version 3 of the License, or
19 (at your option) any later version.
21 This program is distributed in the hope that it will be useful,
22 but WITHOUT ANY WARRANTY; without even the implied warranty of
23 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 GNU General Public License for more details.
26 You should have received a copy of the GNU General Public License
27 along with this program. If not, see <http://www.gnu.org/licenses/>.
33 * This module provides suitable callback functions for the params
34 * module. It builds the internal table of service details which is
35 * then used by the rest of the server.
39 * 1) add it to the global or service structure definition
40 * 2) add it to the parm_table
41 * 3) add it to the list of available functions (eg: using FN_GLOBAL_STRING())
42 * 4) If it's a global then initialise it in init_globals. If a local
43 * (ie. service) parameter then initialise it in the sDefault structure
47 * The configuration file is processed sequentially for speed. It is NOT
48 * accessed randomly as happens in 'real' Windows. For this reason, there
49 * is a fair bit of sequence-dependent code here - ie., code which assumes
50 * that certain things happen before others. In particular, the code which
51 * happens at the boundary between sections is delicately poised, so be
58 #include "dynconfig/dynconfig.h"
59 #include "system/time.h"
60 #include "system/locale.h"
61 #include "system/network.h" /* needed for TCP_NODELAY */
62 #include "../lib/util/dlinklist.h"
63 #include "lib/param/param.h"
64 #define LOADPARM_SUBSTITUTION_INTERNALS 1
65 #include "lib/param/loadparm.h"
66 #include "auth/gensec/gensec.h"
67 #include "lib/param/s3_param.h"
68 #include "lib/util/bitmap.h"
69 #include "libcli/smb/smb_constants.h"
71 #include "librpc/gen_ndr/nbt.h"
72 #include "librpc/gen_ndr/dns.h"
73 #include "libds/common/roles.h"
74 #include "lib/util/samba_util.h"
75 #include "libcli/auth/ntlm_check.h"
76 #include "lib/crypto/gnutls_helpers.h"
77 #include "lib/util/smb_strtox.h"
78 #include "auth/credentials/credentials.h"
80 #ifdef HAVE_HTTPCONNECTENCRYPT
81 #include <cups/http.h>
84 #define standard_sub_basic talloc_strdup
86 #include "lib/param/param_global.h"
88 struct loadparm_service *lpcfg_default_service(struct loadparm_context *lp_ctx)
90 return lp_ctx->sDefault;
93 int lpcfg_rpc_low_port(struct loadparm_context *lp_ctx)
95 return lp_ctx->globals->rpc_low_port;
98 int lpcfg_rpc_high_port(struct loadparm_context *lp_ctx)
100 return lp_ctx->globals->rpc_high_port;
103 enum samba_weak_crypto lpcfg_weak_crypto(struct loadparm_context *lp_ctx)
105 if (lp_ctx->globals->weak_crypto == SAMBA_WEAK_CRYPTO_UNKNOWN) {
106 lp_ctx->globals->weak_crypto = SAMBA_WEAK_CRYPTO_DISALLOWED;
108 if (samba_gnutls_weak_crypto_allowed()) {
109 lp_ctx->globals->weak_crypto = SAMBA_WEAK_CRYPTO_ALLOWED;
113 return lp_ctx->globals->weak_crypto;
117 * Convenience routine to grab string parameters into temporary memory
118 * and run standard_sub_basic on them.
120 * The buffers can be written to by
121 * callers without affecting the source string.
124 static const char *lpcfg_string(const char *s)
126 #if 0 /* until REWRITE done to make thread-safe */
127 size_t len = s ? strlen(s) : 0;
131 /* The follow debug is useful for tracking down memory problems
132 especially if you have an inner loop that is calling a lp_*()
133 function that returns a string. Perhaps this debug should be
134 present all the time? */
137 DEBUG(10, ("lpcfg_string(%s)\n", s));
140 #if 0 /* until REWRITE done to make thread-safe */
142 lp_talloc = talloc_init("lp_talloc");
144 ret = talloc_array(lp_talloc, char, len + 100); /* leave room for substitution */
152 strlcpy(ret, s, len);
154 if (trim_string(ret, "\"", "\"")) {
155 if (strchr(ret,'"') != NULL)
156 strlcpy(ret, s, len);
159 standard_sub_basic(ret,len+100);
166 In this section all the functions that are used to access the
167 parameters from the rest of the program are defined
171 * the creation of separate lpcfg_*() and lp_*() functions is to allow
172 * for code compatibility between existing Samba4 and Samba3 code.
175 /* this global context supports the lp_*() function varients */
176 static struct loadparm_context *global_loadparm_context;
178 #define FN_GLOBAL_SUBSTITUTED_STRING(fn_name,var_name) \
179 _PUBLIC_ char *lpcfg_ ## fn_name(struct loadparm_context *lp_ctx, \
180 const struct loadparm_substitution *lp_sub, TALLOC_CTX *mem_ctx) \
182 if (lp_ctx == NULL) return NULL; \
183 return lpcfg_substituted_string(mem_ctx, lp_sub, \
184 lp_ctx->globals->var_name ? lp_ctx->globals->var_name : ""); \
187 #define FN_GLOBAL_CONST_STRING(fn_name,var_name) \
188 _PUBLIC_ const char *lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) { \
189 if (lp_ctx == NULL) return NULL; \
190 return lp_ctx->globals->var_name ? lpcfg_string(lp_ctx->globals->var_name) : ""; \
193 #define FN_GLOBAL_LIST(fn_name,var_name) \
194 _PUBLIC_ const char **lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) { \
195 if (lp_ctx == NULL) return NULL; \
196 return lp_ctx->globals->var_name; \
199 #define FN_GLOBAL_BOOL(fn_name,var_name) \
200 _PUBLIC_ bool lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) {\
201 if (lp_ctx == NULL) return false; \
202 return lp_ctx->globals->var_name; \
205 #define FN_GLOBAL_INTEGER(fn_name,var_name) \
206 _PUBLIC_ int lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) { \
207 return lp_ctx->globals->var_name; \
210 /* Local parameters don't need the ->s3_fns because the struct
211 * loadparm_service is shared and lpcfg_service() checks the ->s3_fns
213 #define FN_LOCAL_SUBSTITUTED_STRING(fn_name,val) \
214 _PUBLIC_ char *lpcfg_ ## fn_name(struct loadparm_service *service, \
215 struct loadparm_service *sDefault, TALLOC_CTX *ctx) { \
216 return(talloc_strdup(ctx, lpcfg_string((const char *)((service != NULL && service->val != NULL) ? service->val : sDefault->val)))); \
219 #define FN_LOCAL_CONST_STRING(fn_name,val) \
220 _PUBLIC_ const char *lpcfg_ ## fn_name(struct loadparm_service *service, \
221 struct loadparm_service *sDefault) { \
222 return((const char *)((service != NULL && service->val != NULL) ? service->val : sDefault->val)); \
225 #define FN_LOCAL_LIST(fn_name,val) \
226 _PUBLIC_ const char **lpcfg_ ## fn_name(struct loadparm_service *service, \
227 struct loadparm_service *sDefault) {\
228 return(const char **)(service != NULL && service->val != NULL? service->val : sDefault->val); \
231 #define FN_LOCAL_PARM_BOOL(fn_name, val) FN_LOCAL_BOOL(fn_name, val)
233 #define FN_LOCAL_BOOL(fn_name,val) \
234 _PUBLIC_ bool lpcfg_ ## fn_name(struct loadparm_service *service, \
235 struct loadparm_service *sDefault) { \
236 return((service != NULL)? service->val : sDefault->val); \
239 #define FN_LOCAL_INTEGER(fn_name,val) \
240 _PUBLIC_ int lpcfg_ ## fn_name(struct loadparm_service *service, \
241 struct loadparm_service *sDefault) { \
242 return((service != NULL)? service->val : sDefault->val); \
245 #define FN_LOCAL_PARM_INTEGER(fn_name, val) FN_LOCAL_INTEGER(fn_name, val)
247 #define FN_LOCAL_CHAR(fn_name,val) \
248 _PUBLIC_ char lpcfg_ ## fn_name(struct loadparm_service *service, \
249 struct loadparm_service *sDefault) { \
250 return((service != NULL)? service->val : sDefault->val); \
253 #define FN_LOCAL_PARM_CHAR(fn_name,val) FN_LOCAL_CHAR(fn_name, val)
255 #include "lib/param/param_functions.c"
257 /* These functions cannot be auto-generated */
258 FN_LOCAL_BOOL(autoloaded, autoloaded)
259 FN_GLOBAL_CONST_STRING(dnsdomain, dnsdomain)
261 /* local prototypes */
262 static struct loadparm_service *lpcfg_getservicebyname(struct loadparm_context *lp_ctx,
263 const char *pszServiceName);
264 static bool do_section(const char *pszSectionName, void *);
265 static bool set_variable_helper(TALLOC_CTX *mem_ctx, int parmnum, void *parm_ptr,
266 const char *pszParmName, const char *pszParmValue);
267 static bool lp_do_parameter_parametric(struct loadparm_context *lp_ctx,
268 struct loadparm_service *service,
269 const char *pszParmName,
270 const char *pszParmValue, int flags);
272 /* The following are helper functions for parametrical options support. */
273 /* It returns a pointer to parametrical option value if it exists or NULL otherwise */
274 /* Actual parametrical functions are quite simple */
275 struct parmlist_entry *get_parametric_helper(struct loadparm_service *service,
276 const char *type, const char *option,
277 struct parmlist_entry *global_opts)
279 size_t type_len = strlen(type);
280 size_t option_len = strlen(option);
281 char param_key[type_len + option_len + 2];
282 struct parmlist_entry *data = NULL;
284 snprintf(param_key, sizeof(param_key), "%s:%s", type, option);
287 * Try to fetch the option from the data.
289 if (service != NULL) {
290 data = service->param_opt;
291 while (data != NULL) {
292 if (strwicmp(data->key, param_key) == 0) {
300 * Fall back to fetching from the globals.
303 while (data != NULL) {
304 if (strwicmp(data->key, param_key) == 0) {
313 const char *lpcfg_get_parametric(struct loadparm_context *lp_ctx,
314 struct loadparm_service *service,
315 const char *type, const char *option)
317 struct parmlist_entry *data;
322 data = get_parametric_helper(service,
323 type, option, lp_ctx->globals->param_opt);
334 * convenience routine to return int parameters.
336 int lp_int(const char *s)
340 DEBUG(0,("lp_int(%s): is called with NULL!\n",s));
344 return strtol(s, NULL, 0);
348 * convenience routine to return unsigned long parameters.
350 unsigned long lp_ulong(const char *s)
353 unsigned long int ret;
356 DBG_DEBUG("lp_ulong(%s): is called with NULL!\n",s);
360 ret = smb_strtoul(s, NULL, 0, &error, SMB_STR_STANDARD);
362 DBG_DEBUG("lp_ulong(%s): conversion failed\n",s);
370 * convenience routine to return unsigned long long parameters.
372 unsigned long long lp_ulonglong(const char *s)
375 unsigned long long int ret;
378 DBG_DEBUG("lp_ulonglong(%s): is called with NULL!\n", s);
382 ret = smb_strtoull(s, NULL, 0, &error, SMB_STR_STANDARD);
384 DBG_DEBUG("lp_ulonglong(%s): conversion failed\n",s);
392 * convenience routine to return unsigned long parameters.
394 static long lp_long(const char *s)
398 DEBUG(0,("lp_long(%s): is called with NULL!\n",s));
402 return strtol(s, NULL, 0);
406 * convenience routine to return unsigned long parameters.
408 static double lp_double(const char *s)
412 DEBUG(0,("lp_double(%s): is called with NULL!\n",s));
416 return strtod(s, NULL);
420 * convenience routine to return boolean parameters.
422 bool lp_bool(const char *s)
427 DEBUG(0,("lp_bool(%s): is called with NULL!\n",s));
431 if (!set_boolean(s, &ret)) {
432 DEBUG(0,("lp_bool(%s): value is not boolean!\n",s));
440 * Return parametric option from a given service. Type is a part of option before ':'
441 * Parametric option has following syntax: 'Type: option = value'
442 * Returned value is allocated in 'lp_talloc' context
445 const char *lpcfg_parm_string(struct loadparm_context *lp_ctx,
446 struct loadparm_service *service, const char *type,
449 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
452 return lpcfg_string(value);
458 * Return parametric option from a given service. Type is a part of option before ':'
459 * Parametric option has following syntax: 'Type: option = value'
460 * Returned value is allocated in 'lp_talloc' context
463 const char **lpcfg_parm_string_list(TALLOC_CTX *mem_ctx,
464 struct loadparm_context *lp_ctx,
465 struct loadparm_service *service,
467 const char *option, const char *separator)
469 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
472 char **l = str_list_make(mem_ctx, value, separator);
473 return discard_const_p(const char *, l);
480 * Return parametric option from a given service. Type is a part of option before ':'
481 * Parametric option has following syntax: 'Type: option = value'
484 int lpcfg_parm_int(struct loadparm_context *lp_ctx,
485 struct loadparm_service *service, const char *type,
486 const char *option, int default_v)
488 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
491 return lp_int(value);
497 * Return parametric option from a given service. Type is a part of
499 * Parametric option has following syntax: 'Type: option = value'.
502 int lpcfg_parm_bytes(struct loadparm_context *lp_ctx,
503 struct loadparm_service *service, const char *type,
504 const char *option, int default_v)
508 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
510 if (value && conv_str_size_error(value, &bval)) {
511 if (bval <= INT_MAX) {
520 * Return parametric option from a given service.
521 * Type is a part of option before ':'
522 * Parametric option has following syntax: 'Type: option = value'
524 unsigned long lpcfg_parm_ulong(struct loadparm_context *lp_ctx,
525 struct loadparm_service *service, const char *type,
526 const char *option, unsigned long default_v)
528 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
531 return lp_ulong(value);
537 * Return parametric option from a given service.
538 * Type is a part of option before ':'
539 * Parametric option has following syntax: 'Type: option = value'
541 unsigned long long lpcfg_parm_ulonglong(struct loadparm_context *lp_ctx,
542 struct loadparm_service *service,
543 const char *type, const char *option,
544 unsigned long long default_v)
546 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
549 return lp_ulonglong(value);
555 long lpcfg_parm_long(struct loadparm_context *lp_ctx,
556 struct loadparm_service *service, const char *type,
557 const char *option, long default_v)
559 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
562 return lp_long(value);
567 double lpcfg_parm_double(struct loadparm_context *lp_ctx,
568 struct loadparm_service *service, const char *type,
569 const char *option, double default_v)
571 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
574 return lp_double(value);
580 * Return parametric option from a given service. Type is a part of option before ':'
581 * Parametric option has following syntax: 'Type: option = value'
584 bool lpcfg_parm_bool(struct loadparm_context *lp_ctx,
585 struct loadparm_service *service, const char *type,
586 const char *option, bool default_v)
588 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
591 return lp_bool(value);
597 /* this is used to prevent lots of mallocs of size 1 */
598 static const char lpcfg_string_empty[] = "";
603 void lpcfg_string_free(char **s)
608 if (*s == lpcfg_string_empty) {
616 * Set a string value, deallocating any existing space, and allocing the space
619 bool lpcfg_string_set(TALLOC_CTX *mem_ctx, char **dest, const char *src)
621 lpcfg_string_free(dest);
623 if ((src == NULL) || (*src == '\0')) {
624 *dest = discard_const_p(char, lpcfg_string_empty);
628 *dest = talloc_strdup(mem_ctx, src);
629 if ((*dest) == NULL) {
630 DEBUG(0,("Out of memory in string_set\n"));
638 * Set a string value, deallocating any existing space, and allocing the space
641 bool lpcfg_string_set_upper(TALLOC_CTX *mem_ctx, char **dest, const char *src)
643 lpcfg_string_free(dest);
645 if ((src == NULL) || (*src == '\0')) {
646 *dest = discard_const_p(char, lpcfg_string_empty);
650 *dest = strupper_talloc(mem_ctx, src);
651 if ((*dest) == NULL) {
652 DEBUG(0,("Out of memory in string_set_upper\n"));
662 * Add a new service to the services array initialising it with the given
666 struct loadparm_service *lpcfg_add_service(struct loadparm_context *lp_ctx,
667 const struct loadparm_service *pservice,
671 int num_to_alloc = lp_ctx->iNumServices + 1;
672 struct parmlist_entry *data, *pdata;
674 if (lp_ctx->s3_fns != NULL) {
675 smb_panic("Add a service should not be called on an s3 loadparm ctx");
678 if (pservice == NULL) {
679 pservice = lp_ctx->sDefault;
682 /* it might already exist */
684 struct loadparm_service *service = lpcfg_getservicebyname(lp_ctx,
686 if (service != NULL) {
687 /* Clean all parametric options for service */
688 /* They will be added during parsing again */
689 data = service->param_opt;
695 service->param_opt = NULL;
700 /* find an invalid one */
701 for (i = 0; i < lp_ctx->iNumServices; i++)
702 if (lp_ctx->services[i] == NULL)
705 /* if not, then create one */
706 if (i == lp_ctx->iNumServices) {
707 struct loadparm_service **tsp;
709 tsp = talloc_realloc(lp_ctx, lp_ctx->services, struct loadparm_service *, num_to_alloc);
712 DEBUG(0,("lpcfg_add_service: failed to enlarge services!\n"));
715 lp_ctx->services = tsp;
716 lp_ctx->services[lp_ctx->iNumServices] = NULL;
719 lp_ctx->iNumServices++;
722 lp_ctx->services[i] = talloc_zero(lp_ctx->services, struct loadparm_service);
723 if (lp_ctx->services[i] == NULL) {
724 DEBUG(0,("lpcfg_add_service: out of memory!\n"));
727 copy_service(lp_ctx->services[i], pservice, NULL);
729 lpcfg_string_set(lp_ctx->services[i], &lp_ctx->services[i]->szService, name);
730 return lp_ctx->services[i];
734 * Map a parameter's string representation to something we can use.
735 * Returns False if the parameter string is not recognised, else TRUE.
738 int lpcfg_map_parameter(const char *pszParmName)
742 for (iIndex = 0; parm_table[iIndex].label; iIndex++)
743 if (strwicmp(parm_table[iIndex].label, pszParmName) == 0)
746 /* Warn only if it isn't parametric option */
747 if (strchr(pszParmName, ':') == NULL)
748 DEBUG(0, ("Unknown parameter encountered: \"%s\"\n", pszParmName));
749 /* We do return 'fail' for parametric options as well because they are
750 stored in different storage
757 return the parameter structure for a parameter
759 struct parm_struct *lpcfg_parm_struct(struct loadparm_context *lp_ctx, const char *name)
761 int num = lpcfg_map_parameter(name);
767 return &parm_table[num];
771 return the parameter pointer for a parameter
773 void *lpcfg_parm_ptr(struct loadparm_context *lp_ctx,
774 struct loadparm_service *service, struct parm_struct *parm)
776 if (lp_ctx->s3_fns) {
777 return lp_ctx->s3_fns->get_parm_ptr(service, parm);
780 if (service == NULL) {
781 if (parm->p_class == P_LOCAL)
782 return ((char *)lp_ctx->sDefault)+parm->offset;
783 else if (parm->p_class == P_GLOBAL)
784 return ((char *)lp_ctx->globals)+parm->offset;
787 return ((char *)service) + parm->offset;
792 return the parameter pointer for a parameter
794 bool lpcfg_parm_is_cmdline(struct loadparm_context *lp_ctx, const char *name)
798 parmnum = lpcfg_map_parameter(name);
799 if (parmnum == -1) return false;
801 return lp_ctx->flags[parmnum] & FLAG_CMDLINE;
804 bool lpcfg_parm_is_unspecified(struct loadparm_context *lp_ctx, const char *name)
808 parmnum = lpcfg_map_parameter(name);
809 if (parmnum == -1) return false;
811 return lp_ctx->flags[parmnum] & FLAG_DEFAULT;
815 * Find a service by name. Otherwise works like get_service.
818 static struct loadparm_service *lpcfg_getservicebyname(struct loadparm_context *lp_ctx,
819 const char *pszServiceName)
823 if (lp_ctx->s3_fns) {
824 return lp_ctx->s3_fns->get_service(pszServiceName);
827 for (iService = lp_ctx->iNumServices - 1; iService >= 0; iService--)
828 if (lp_ctx->services[iService] != NULL &&
829 strwicmp(lp_ctx->services[iService]->szService, pszServiceName) == 0) {
830 return lp_ctx->services[iService];
837 * Add a parametric option to a parmlist_entry,
838 * replacing old value, if already present.
840 void set_param_opt(TALLOC_CTX *mem_ctx,
841 struct parmlist_entry **opt_list,
842 const char *opt_name,
843 const char *opt_value,
846 struct parmlist_entry *new_opt, *opt;
850 /* Traverse destination */
852 /* If we already have same option, override it */
853 if (strwicmp(opt->key, opt_name) == 0) {
854 if ((opt->priority & FLAG_CMDLINE) &&
855 !(priority & FLAG_CMDLINE)) {
856 /* it's been marked as not to be
860 TALLOC_FREE(opt->list);
861 lpcfg_string_set(opt, &opt->value, opt_value);
862 opt->priority = priority;
868 new_opt = talloc_pooled_object(
869 mem_ctx, struct parmlist_entry,
870 2, strlen(opt_name) + 1 + strlen(opt_value) + 1);
871 if (new_opt == NULL) {
875 lpcfg_string_set(new_opt, &new_opt->key, opt_name);
876 new_opt->value = NULL;
877 lpcfg_string_set(new_opt, &new_opt->value, opt_value);
879 new_opt->list = NULL;
880 new_opt->priority = priority;
881 DLIST_ADD(*opt_list, new_opt);
885 * Copy a service structure to another.
886 * If pcopymapDest is NULL then copy all fields
889 void copy_service(struct loadparm_service *pserviceDest,
890 const struct loadparm_service *pserviceSource,
891 struct bitmap *pcopymapDest)
894 bool bcopyall = (pcopymapDest == NULL);
895 struct parmlist_entry *data;
897 for (i = 0; parm_table[i].label; i++)
898 if (parm_table[i].p_class == P_LOCAL &&
899 (bcopyall || bitmap_query(pcopymapDest, i))) {
900 const void *src_ptr =
901 ((const char *)pserviceSource) + parm_table[i].offset;
903 ((char *)pserviceDest) + parm_table[i].offset;
905 switch (parm_table[i].type) {
908 *(bool *)dest_ptr = *(const bool *)src_ptr;
915 *(int *)dest_ptr = *(const int *)src_ptr;
919 *(char *)dest_ptr = *(const char *)src_ptr;
923 lpcfg_string_set(pserviceDest,
925 *(const char * const *)src_ptr);
929 lpcfg_string_set_upper(pserviceDest,
931 *(const char * const *)src_ptr);
935 TALLOC_FREE(*((char ***)dest_ptr));
936 *(char ***)dest_ptr = str_list_copy(pserviceDest,
937 *discard_const_p(const char **, src_ptr));
945 init_copymap(pserviceDest);
946 if (pserviceSource->copymap)
947 bitmap_copy(pserviceDest->copymap,
948 pserviceSource->copymap);
951 for (data = pserviceSource->param_opt; data != NULL; data = data->next) {
952 set_param_opt(pserviceDest, &pserviceDest->param_opt,
953 data->key, data->value, data->priority);
958 * Check a service for consistency. Return False if the service is in any way
959 * incomplete or faulty, else True.
961 bool lpcfg_service_ok(struct loadparm_service *service)
966 if (service->szService[0] == '\0') {
967 DEBUG(0, ("The following message indicates an internal error:\n"));
968 DEBUG(0, ("No service name in service entry.\n"));
972 /* The [printers] entry MUST be printable. I'm all for flexibility, but */
973 /* I can't see why you'd want a non-printable printer service... */
974 if (strwicmp(service->szService, PRINTERS_NAME) == 0) {
975 if (!service->printable) {
976 DEBUG(0, ("WARNING: [%s] service MUST be printable!\n",
977 service->szService));
978 service->printable = true;
980 /* [printers] service must also be non-browsable. */
981 if (service->browseable)
982 service->browseable = false;
985 if (service->path[0] == '\0' &&
986 strwicmp(service->szService, HOMES_NAME) != 0 &&
987 service->msdfs_proxy[0] == '\0')
989 DEBUG(0, ("WARNING: No path in service %s - making it unavailable!\n",
990 service->szService));
991 service->available = false;
994 if (!service->available)
995 DEBUG(1, ("NOTE: Service %s is flagged unavailable.\n",
996 service->szService));
1002 /*******************************************************************
1003 Keep a linked list of all config files so we know when one has changed
1004 it's date and needs to be reloaded.
1005 ********************************************************************/
1007 void add_to_file_list(TALLOC_CTX *mem_ctx, struct file_lists **list,
1008 const char *fname, const char *subfname)
1010 struct file_lists *f = *list;
1013 if (f->name && !strcmp(f->name, fname))
1019 f = talloc(mem_ctx, struct file_lists);
1023 f->name = talloc_strdup(f, fname);
1028 f->subfname = talloc_strdup(f, subfname);
1034 f->modtime = file_modtime(subfname);
1036 time_t t = file_modtime(subfname);
1043 DEBUG(0, ("Unable to add file to file list: %s\n", fname));
1048 * set the value for a P_ENUM
1050 bool lp_set_enum_parm( struct parm_struct *parm, const char *pszParmValue,
1055 for (i = 0; parm->enum_list[i].name; i++) {
1056 if (strwicmp(pszParmValue, parm->enum_list[i].name) == 0) {
1057 *ptr = parm->enum_list[i].value;
1061 DEBUG(0, ("WARNING: Ignoring invalid value '%s' for parameter '%s'\n",
1062 pszParmValue, parm->label));
1067 /***************************************************************************
1068 Handle the "realm" parameter
1069 ***************************************************************************/
1071 bool handle_realm(struct loadparm_context *lp_ctx, struct loadparm_service *service,
1072 const char *pszParmValue, char **ptr)
1077 upper = strupper_talloc(lp_ctx, pszParmValue);
1078 if (upper == NULL) {
1082 lower = strlower_talloc(lp_ctx, pszParmValue);
1083 if (lower == NULL) {
1088 lpcfg_string_set(lp_ctx->globals->ctx, &lp_ctx->globals->realm, upper);
1089 lpcfg_string_set(lp_ctx->globals->ctx, &lp_ctx->globals->dnsdomain, lower);
1094 /***************************************************************************
1095 Handle the include operation.
1096 ***************************************************************************/
1098 bool handle_include(struct loadparm_context *lp_ctx, struct loadparm_service *service,
1099 const char *pszParmValue, char **ptr)
1102 const char *substitution_variable_substring;
1105 if (lp_ctx->s3_fns) {
1106 return lp_ctx->s3_fns->lp_include(lp_ctx, service, pszParmValue, ptr);
1109 fname = standard_sub_basic(lp_ctx, pszParmValue);
1111 add_to_file_list(lp_ctx, &lp_ctx->file_lists, pszParmValue, fname);
1113 lpcfg_string_set(lp_ctx, ptr, fname);
1115 if (file_exist(fname))
1116 return pm_process(fname, do_section, lpcfg_do_parameter, lp_ctx);
1119 * If the file doesn't exist, we check that it isn't due to variable
1122 substitution_variable_substring = strchr(fname, '%');
1124 if (substitution_variable_substring != NULL) {
1125 next_char = substitution_variable_substring[1];
1126 if ((next_char >= 'a' && next_char <= 'z')
1127 || (next_char >= 'A' && next_char <= 'Z')) {
1128 DEBUG(2, ("Tried to load %s but variable substitution in "
1129 "filename, ignoring file.\n", fname));
1134 DEBUG(2, ("Can't find include file %s\n", fname));
1139 /***************************************************************************
1140 Handle the interpretation of the copy parameter.
1141 ***************************************************************************/
1143 bool handle_copy(struct loadparm_context *lp_ctx, struct loadparm_service *service,
1144 const char *pszParmValue, char **ptr)
1147 struct loadparm_service *serviceTemp = NULL;
1151 DEBUG(3, ("Copying service from service %s\n", pszParmValue));
1153 serviceTemp = lpcfg_getservicebyname(lp_ctx, pszParmValue);
1155 if (service == NULL) {
1156 DEBUG(0, ("Unable to copy service - invalid service destination.\n"));
1160 if (serviceTemp != NULL) {
1161 if (serviceTemp == service) {
1162 DEBUG(0, ("Can't copy service %s - unable to copy self!\n", pszParmValue));
1164 copy_service(service,
1167 lpcfg_string_set(service, ptr, pszParmValue);
1172 DEBUG(0, ("Unable to copy service - source not found: %s\n",
1180 bool handle_debug_list(struct loadparm_context *lp_ctx, struct loadparm_service *service,
1181 const char *pszParmValue, char **ptr)
1183 lpcfg_string_set(lp_ctx->globals->ctx, ptr, pszParmValue);
1185 return debug_parse_levels(pszParmValue);
1188 bool handle_logfile(struct loadparm_context *lp_ctx, struct loadparm_service *service,
1189 const char *pszParmValue, char **ptr)
1191 if (lp_ctx->s3_fns == NULL) {
1192 debug_set_logfile(pszParmValue);
1195 lpcfg_string_set(lp_ctx->globals->ctx, ptr, pszParmValue);
1201 * These special charset handling methods only run in the source3 code.
1204 bool handle_charset(struct loadparm_context *lp_ctx, struct loadparm_service *service,
1205 const char *pszParmValue, char **ptr)
1207 if (lp_ctx->s3_fns) {
1208 if (*ptr == NULL || strcmp(*ptr, pszParmValue) != 0) {
1209 struct smb_iconv_handle *ret = NULL;
1211 ret = reinit_iconv_handle(NULL,
1212 lpcfg_dos_charset(lp_ctx),
1213 lpcfg_unix_charset(lp_ctx));
1215 smb_panic("reinit_iconv_handle failed");
1220 return lpcfg_string_set(lp_ctx->globals->ctx, ptr, pszParmValue);
1224 bool handle_dos_charset(struct loadparm_context *lp_ctx, struct loadparm_service *service,
1225 const char *pszParmValue, char **ptr)
1227 bool is_utf8 = false;
1228 size_t len = strlen(pszParmValue);
1230 if (lp_ctx->s3_fns) {
1231 if (len == 4 || len == 5) {
1232 /* Don't use StrCaseCmp here as we don't want to
1233 initialize iconv. */
1234 if ((toupper_m(pszParmValue[0]) == 'U') &&
1235 (toupper_m(pszParmValue[1]) == 'T') &&
1236 (toupper_m(pszParmValue[2]) == 'F')) {
1238 if (pszParmValue[3] == '8') {
1242 if (pszParmValue[3] == '-' &&
1243 pszParmValue[4] == '8') {
1250 if (*ptr == NULL || strcmp(*ptr, pszParmValue) != 0) {
1251 struct smb_iconv_handle *ret = NULL;
1253 DEBUG(0,("ERROR: invalid DOS charset: 'dos charset' must not "
1254 "be UTF8, using (default value) %s instead.\n",
1255 DEFAULT_DOS_CHARSET));
1256 pszParmValue = DEFAULT_DOS_CHARSET;
1258 ret = reinit_iconv_handle(NULL,
1259 lpcfg_dos_charset(lp_ctx),
1260 lpcfg_unix_charset(lp_ctx));
1262 smb_panic("reinit_iconv_handle failed");
1267 return lpcfg_string_set(lp_ctx->globals->ctx, ptr, pszParmValue);
1270 bool handle_printing(struct loadparm_context *lp_ctx, struct loadparm_service *service,
1271 const char *pszParmValue, char **ptr)
1273 static int parm_num = -1;
1275 if (parm_num == -1) {
1276 parm_num = lpcfg_map_parameter("printing");
1279 if (!lp_set_enum_parm(&parm_table[parm_num], pszParmValue, (int*)ptr)) {
1283 if (lp_ctx->s3_fns) {
1284 if (service == NULL) {
1285 init_printer_values(lp_ctx, lp_ctx->globals->ctx, lp_ctx->sDefault);
1287 init_printer_values(lp_ctx, service, service);
1294 bool handle_ldap_debug_level(struct loadparm_context *lp_ctx, struct loadparm_service *service,
1295 const char *pszParmValue, char **ptr)
1297 lp_ctx->globals->ldap_debug_level = lp_int(pszParmValue);
1299 if (lp_ctx->s3_fns) {
1300 lp_ctx->s3_fns->init_ldap_debugging();
1306 * idmap related parameters
1309 bool handle_idmap_backend(struct loadparm_context *lp_ctx, struct loadparm_service *service,
1310 const char *pszParmValue, char **ptr)
1312 if (lp_ctx->s3_fns) {
1313 lp_do_parameter_parametric(lp_ctx, service, "idmap config * : backend",
1317 return lpcfg_string_set(lp_ctx->globals->ctx, ptr, pszParmValue);
1320 bool handle_idmap_uid(struct loadparm_context *lp_ctx, struct loadparm_service *service,
1321 const char *pszParmValue, char **ptr)
1323 if (lp_ctx->s3_fns) {
1324 lp_do_parameter_parametric(lp_ctx, service, "idmap config * : range",
1328 return lpcfg_string_set(lp_ctx->globals->ctx, ptr, pszParmValue);
1331 bool handle_idmap_gid(struct loadparm_context *lp_ctx, struct loadparm_service *service,
1332 const char *pszParmValue, char **ptr)
1334 if (lp_ctx->s3_fns) {
1335 lp_do_parameter_parametric(lp_ctx, service, "idmap config * : range",
1339 return lpcfg_string_set(lp_ctx->globals->ctx, ptr, pszParmValue);
1342 bool handle_smb_ports(struct loadparm_context *lp_ctx, struct loadparm_service *service,
1343 const char *pszParmValue, char **ptr)
1345 static int parm_num = -1;
1349 if (!pszParmValue || !*pszParmValue) {
1353 if (parm_num == -1) {
1354 parm_num = lpcfg_map_parameter("smb ports");
1355 if (parm_num == -1) {
1360 if (!set_variable_helper(lp_ctx->globals->ctx, parm_num, ptr, "smb ports",
1365 list = lp_ctx->globals->smb_ports;
1370 /* Check that each port is a valid integer and within range */
1371 for (i = 0; list[i] != NULL; i++) {
1374 port = strtol(list[i], &end, 10);
1375 if (*end != '\0' || port <= 0 || port > 65535) {
1384 bool handle_rpc_server_dynamic_port_range(struct loadparm_context *lp_ctx,
1385 struct loadparm_service *service,
1386 const char *pszParmValue,
1389 static int parm_num = -1;
1390 int low_port = -1, high_port = -1;
1393 if (parm_num == -1) {
1394 parm_num = lpcfg_map_parameter("rpc server dynamic port range");
1395 if (parm_num == -1) {
1400 if (pszParmValue == NULL || pszParmValue[0] == '\0') {
1404 rc = sscanf(pszParmValue, "%d - %d", &low_port, &high_port);
1409 if (low_port > high_port) {
1413 if (low_port < SERVER_TCP_PORT_MIN|| high_port > SERVER_TCP_PORT_MAX) {
1417 if (!set_variable_helper(lp_ctx->globals->ctx, parm_num, ptr,
1418 "rpc server dynamic port range",
1423 lp_ctx->globals->rpc_low_port = low_port;
1424 lp_ctx->globals->rpc_high_port = high_port;
1429 bool handle_smb2_max_credits(struct loadparm_context *lp_ctx,
1430 struct loadparm_service *service,
1431 const char *pszParmValue, char **ptr)
1433 int value = lp_int(pszParmValue);
1436 value = DEFAULT_SMB2_MAX_CREDITS;
1439 *(int *)ptr = value;
1444 bool handle_cups_encrypt(struct loadparm_context *lp_ctx,
1445 struct loadparm_service *service,
1446 const char *pszParmValue, char **ptr)
1449 #ifdef HAVE_HTTPCONNECTENCRYPT
1450 int value = lp_int(pszParmValue);
1454 result = HTTP_ENCRYPT_REQUIRED;
1457 result = HTTP_ENCRYPT_ALWAYS;
1460 result = HTTP_ENCRYPT_NEVER;
1467 *(int *)ptr = result;
1472 /***************************************************************************
1473 Initialise a copymap.
1474 ***************************************************************************/
1477 * Initializes service copymap
1478 * Note: pservice *must* be valid TALLOC_CTX
1480 void init_copymap(struct loadparm_service *pservice)
1484 TALLOC_FREE(pservice->copymap);
1486 pservice->copymap = bitmap_talloc(pservice, num_parameters());
1487 if (!pservice->copymap) {
1489 ("Couldn't allocate copymap!! (size %d)\n",
1490 (int)num_parameters()));
1492 for (i = 0; i < num_parameters(); i++) {
1493 bitmap_set(pservice->copymap, i);
1499 * Process a parametric option
1501 static bool lp_do_parameter_parametric(struct loadparm_context *lp_ctx,
1502 struct loadparm_service *service,
1503 const char *pszParmName,
1504 const char *pszParmValue, int flags)
1506 struct parmlist_entry **data;
1508 TALLOC_CTX *mem_ctx;
1510 while (isspace((unsigned char)*pszParmName)) {
1514 name = strlower_talloc(lp_ctx, pszParmName);
1515 if (!name) return false;
1517 if (service == NULL) {
1518 data = &lp_ctx->globals->param_opt;
1520 * s3 code cannot deal with parametric options stored on the globals ctx.
1522 if (lp_ctx->s3_fns != NULL) {
1525 mem_ctx = lp_ctx->globals->ctx;
1528 data = &service->param_opt;
1532 set_param_opt(mem_ctx, data, name, pszParmValue, flags);
1539 static bool set_variable_helper(TALLOC_CTX *mem_ctx, int parmnum, void *parm_ptr,
1540 const char *pszParmName, const char *pszParmValue)
1544 /* switch on the type of variable it is */
1545 switch (parm_table[parmnum].type)
1549 if (!set_boolean(pszParmValue, &b)) {
1550 DEBUG(0, ("set_variable_helper(%s): value is not "
1551 "boolean!\n", pszParmValue));
1554 *(bool *)parm_ptr = b;
1560 if (!set_boolean(pszParmValue, &b)) {
1561 DEBUG(0, ("set_variable_helper(%s): value is not "
1562 "boolean!\n", pszParmValue));
1565 *(bool *)parm_ptr = !b;
1570 *(int *)parm_ptr = lp_int(pszParmValue);
1574 *(char *)parm_ptr = *pszParmValue;
1578 i = sscanf(pszParmValue, "%o", (int *)parm_ptr);
1580 DEBUG ( 0, ("Invalid octal number %s\n", pszParmName ));
1588 if (conv_str_size_error(pszParmValue, &val)) {
1589 if (val <= INT_MAX) {
1590 *(int *)parm_ptr = (int)val;
1595 DEBUG(0, ("set_variable_helper(%s): value is not "
1596 "a valid size specifier!\n", pszParmValue));
1601 TALLOC_FREE(*(char ***)parm_ptr);
1602 *(char ***)parm_ptr = str_list_make_v3(mem_ctx,
1603 pszParmValue, NULL);
1608 char **new_list = str_list_make_v3(mem_ctx,
1609 pszParmValue, NULL);
1610 if (new_list == NULL) {
1614 for (i=0; new_list[i]; i++) {
1615 if (*(const char ***)parm_ptr != NULL &&
1616 new_list[i][0] == '+' &&
1619 if (!str_list_check(*(const char ***)parm_ptr,
1621 *(const char ***)parm_ptr = str_list_add(*(const char ***)parm_ptr,
1624 } else if (*(const char ***)parm_ptr != NULL &&
1625 new_list[i][0] == '-' &&
1628 str_list_remove(*(const char ***)parm_ptr,
1632 DEBUG(0, ("Unsupported list syntax for: %s = %s\n",
1633 pszParmName, pszParmValue));
1636 *(char ***)parm_ptr = new_list;
1644 lpcfg_string_set(mem_ctx, (char **)parm_ptr, pszParmValue);
1648 lpcfg_string_set_upper(mem_ctx, (char **)parm_ptr, pszParmValue);
1652 if (!lp_set_enum_parm(&parm_table[parmnum], pszParmValue, (int*)parm_ptr)) {
1663 bool handle_name_resolve_order(struct loadparm_context *lp_ctx,
1664 struct loadparm_service *service,
1665 const char *pszParmValue, char **ptr)
1667 const char **valid_values = NULL;
1668 const char **values_to_set = NULL;
1670 bool value_is_valid = false;
1671 valid_values = str_list_make_v3_const(NULL,
1672 DEFAULT_NAME_RESOLVE_ORDER,
1674 if (valid_values == NULL) {
1675 DBG_ERR("OOM: failed to make string list from %s\n",
1676 DEFAULT_NAME_RESOLVE_ORDER);
1679 values_to_set = str_list_make_v3_const(lp_ctx->globals->ctx,
1682 if (values_to_set == NULL) {
1683 DBG_ERR("OOM: failed to make string list from %s\n",
1687 TALLOC_FREE(lp_ctx->globals->name_resolve_order);
1688 for (i = 0; values_to_set[i] != NULL; i++) {
1689 value_is_valid = str_list_check(valid_values, values_to_set[i]);
1690 if (!value_is_valid) {
1691 DBG_ERR("WARNING: Ignoring invalid list value '%s' "
1692 "for parameter 'name resolve order'\n",
1698 if (value_is_valid) {
1699 lp_ctx->globals->name_resolve_order = values_to_set;
1701 TALLOC_FREE(values_to_set);
1703 TALLOC_FREE(valid_values);
1704 return value_is_valid;
1707 static bool set_variable(TALLOC_CTX *mem_ctx, struct loadparm_service *service,
1708 int parmnum, void *parm_ptr,
1709 const char *pszParmName, const char *pszParmValue,
1710 struct loadparm_context *lp_ctx, bool on_globals)
1715 /* if it is a special case then go ahead */
1716 if (parm_table[parmnum].special) {
1717 ok = parm_table[parmnum].special(lp_ctx, service, pszParmValue,
1720 ok = set_variable_helper(mem_ctx, parmnum, parm_ptr,
1721 pszParmName, pszParmValue);
1728 if (on_globals && (lp_ctx->flags[parmnum] & FLAG_DEFAULT)) {
1729 lp_ctx->flags[parmnum] &= ~FLAG_DEFAULT;
1730 /* we have to also unset FLAG_DEFAULT on aliases */
1731 for (i=parmnum-1;i>=0 && parm_table[i].offset == parm_table[parmnum].offset;i--) {
1732 lp_ctx->flags[i] &= ~FLAG_DEFAULT;
1734 for (i=parmnum+1;i<num_parameters() && parm_table[i].offset == parm_table[parmnum].offset;i++) {
1735 lp_ctx->flags[i] &= ~FLAG_DEFAULT;
1742 bool lpcfg_do_global_parameter(struct loadparm_context *lp_ctx,
1743 const char *pszParmName, const char *pszParmValue)
1745 int parmnum = lpcfg_map_parameter(pszParmName);
1749 if (strchr(pszParmName, ':')) {
1750 return lp_do_parameter_parametric(lp_ctx, NULL, pszParmName, pszParmValue, 0);
1752 DEBUG(0, ("Ignoring unknown parameter \"%s\"\n", pszParmName));
1756 /* if the flag has been set on the command line, then don't allow override,
1757 but don't report an error */
1758 if (lp_ctx->flags[parmnum] & FLAG_CMDLINE) {
1762 if (parm_table[parmnum].flags & FLAG_DEPRECATED) {
1763 char *suppress_env = getenv("SAMBA_DEPRECATED_SUPPRESS");
1764 bool print_warning = (suppress_env == NULL
1765 || suppress_env[0] == '\0');
1766 if (print_warning) {
1767 DBG_WARNING("WARNING: The \"%s\" option "
1774 parm_ptr = lpcfg_parm_ptr(lp_ctx, NULL, &parm_table[parmnum]);
1776 return set_variable(lp_ctx->globals->ctx, NULL, parmnum, parm_ptr,
1777 pszParmName, pszParmValue, lp_ctx, true);
1780 bool lpcfg_do_service_parameter(struct loadparm_context *lp_ctx,
1781 struct loadparm_service *service,
1782 const char *pszParmName, const char *pszParmValue)
1786 int parmnum = lpcfg_map_parameter(pszParmName);
1789 if (strchr(pszParmName, ':')) {
1790 return lp_do_parameter_parametric(lp_ctx, service, pszParmName, pszParmValue, 0);
1792 DEBUG(0, ("Ignoring unknown parameter \"%s\"\n", pszParmName));
1796 /* if the flag has been set on the command line, then don't allow override,
1797 but don't report an error */
1798 if (lp_ctx->flags[parmnum] & FLAG_CMDLINE) {
1802 if (parm_table[parmnum].flags & FLAG_DEPRECATED) {
1803 char *suppress_env = getenv("SAMBA_DEPRECATED_SUPPRESS");
1804 bool print_warning = (suppress_env == NULL
1805 || suppress_env[0] == '\0');
1806 if (print_warning) {
1807 DBG_WARNING("WARNING: The \"%s\" option "
1814 if (parm_table[parmnum].p_class == P_GLOBAL) {
1816 ("Global parameter %s found in service section!\n",
1820 parm_ptr = ((char *)service) + parm_table[parmnum].offset;
1822 if (!service->copymap)
1823 init_copymap(service);
1825 /* this handles the aliases - set the copymap for other
1826 * entries with the same data pointer */
1827 for (i = 0; parm_table[i].label; i++)
1828 if (parm_table[i].offset == parm_table[parmnum].offset &&
1829 parm_table[i].p_class == parm_table[parmnum].p_class)
1830 bitmap_clear(service->copymap, i);
1832 return set_variable(service, service, parmnum, parm_ptr, pszParmName,
1833 pszParmValue, lp_ctx, false);
1837 * Process a parameter.
1840 bool lpcfg_do_parameter(const char *pszParmName, const char *pszParmValue,
1843 struct loadparm_context *lp_ctx = (struct loadparm_context *)userdata;
1845 if (lp_ctx->bInGlobalSection)
1846 return lpcfg_do_global_parameter(lp_ctx, pszParmName,
1849 return lpcfg_do_service_parameter(lp_ctx, lp_ctx->currentService,
1850 pszParmName, pszParmValue);
1854 variable argument do parameter
1856 bool lpcfg_do_global_parameter_var(struct loadparm_context *lp_ctx, const char *pszParmName, const char *fmt, ...) PRINTF_ATTRIBUTE(3, 4);
1857 bool lpcfg_do_global_parameter_var(struct loadparm_context *lp_ctx,
1858 const char *pszParmName, const char *fmt, ...)
1865 s = talloc_vasprintf(NULL, fmt, ap);
1867 ret = lpcfg_do_global_parameter(lp_ctx, pszParmName, s);
1874 set a parameter from the commandline - this is called from command line parameter
1875 parsing code. It sets the parameter then marks the parameter as unable to be modified
1876 by smb.conf processing
1878 bool lpcfg_set_cmdline(struct loadparm_context *lp_ctx, const char *pszParmName,
1879 const char *pszParmValue)
1884 while (isspace((unsigned char)*pszParmValue)) pszParmValue++;
1886 parmnum = lpcfg_map_parameter(pszParmName);
1888 if (parmnum < 0 && strchr(pszParmName, ':')) {
1889 /* set a parametric option */
1891 ok = lp_do_parameter_parametric(lp_ctx, NULL, pszParmName,
1892 pszParmValue, FLAG_CMDLINE);
1893 if (lp_ctx->s3_fns != NULL) {
1895 lp_ctx->s3_fns->store_cmdline(pszParmName, pszParmValue);
1902 DEBUG(0,("Unknown option '%s'\n", pszParmName));
1906 /* reset the CMDLINE flag in case this has been called before */
1907 lp_ctx->flags[parmnum] &= ~FLAG_CMDLINE;
1909 if (!lpcfg_do_global_parameter(lp_ctx, pszParmName, pszParmValue)) {
1913 lp_ctx->flags[parmnum] |= FLAG_CMDLINE;
1915 /* we have to also set FLAG_CMDLINE on aliases */
1917 i>=0 && parm_table[i].p_class == parm_table[parmnum].p_class &&
1918 parm_table[i].offset == parm_table[parmnum].offset;
1920 lp_ctx->flags[i] |= FLAG_CMDLINE;
1923 i<num_parameters() &&
1924 parm_table[i].p_class == parm_table[parmnum].p_class &&
1925 parm_table[i].offset == parm_table[parmnum].offset;
1927 lp_ctx->flags[i] |= FLAG_CMDLINE;
1930 if (lp_ctx->s3_fns != NULL) {
1931 lp_ctx->s3_fns->store_cmdline(pszParmName, pszParmValue);
1938 set a option from the commandline in 'a=b' format. Use to support --option
1940 bool lpcfg_set_option(struct loadparm_context *lp_ctx, const char *option)
1945 s = talloc_strdup(NULL, option);
1958 ret = lpcfg_set_cmdline(lp_ctx, s, p+1);
1964 #define BOOLSTR(b) ((b) ? "Yes" : "No")
1967 * Print a parameter of the specified type.
1970 void lpcfg_print_parameter(struct parm_struct *p, void *ptr, FILE * f)
1972 /* For the seperation of lists values that we print below */
1973 const char *list_sep = ", ";
1978 for (i = 0; p->enum_list[i].name; i++) {
1979 if (*(int *)ptr == p->enum_list[i].value) {
1981 p->enum_list[i].name);
1988 fprintf(f, "%s", BOOLSTR(*(bool *)ptr));
1992 fprintf(f, "%s", BOOLSTR(!*(bool *)ptr));
1997 fprintf(f, "%d", *(int *)ptr);
2001 fprintf(f, "%c", *(char *)ptr);
2005 int val = *(int *)ptr;
2009 fprintf(f, "0%03o", val);
2019 if ((char ***)ptr && *(char ***)ptr) {
2020 char **list = *(char ***)ptr;
2021 for (; *list; list++) {
2022 /* surround strings with whitespace in double quotes */
2023 if (*(list+1) == NULL) {
2024 /* last item, no extra separator */
2027 if ( strchr_m( *list, ' ' ) ) {
2028 fprintf(f, "\"%s\"%s", *list, list_sep);
2030 fprintf(f, "%s%s", *list, list_sep);
2038 if (*(char **)ptr) {
2039 fprintf(f, "%s", *(char **)ptr);
2046 * Check if two parameters are equal.
2049 static bool lpcfg_equal_parameter(parm_type type, void *ptr1, void *ptr2)
2054 return (*((bool *)ptr1) == *((bool *)ptr2));
2060 return (*((int *)ptr1) == *((int *)ptr2));
2063 return (*((char *)ptr1) == *((char *)ptr2));
2067 return str_list_equal(*(const char ***)ptr1, *(const char ***)ptr2);
2072 char *p1 = *(char **)ptr1, *p2 = *(char **)ptr2;
2077 return (p1 == p2 || strequal(p1, p2));
2084 * Process a new section (service).
2086 * At this stage all sections are services.
2087 * Later we'll have special sections that permit server parameters to be set.
2088 * Returns True on success, False on failure.
2091 static bool do_section(const char *pszSectionName, void *userdata)
2093 struct loadparm_context *lp_ctx = (struct loadparm_context *)userdata;
2097 if (lp_ctx->s3_fns != NULL) {
2098 return lp_ctx->s3_fns->do_section(pszSectionName, lp_ctx);
2101 isglobal = ((strwicmp(pszSectionName, GLOBAL_NAME) == 0) ||
2102 (strwicmp(pszSectionName, GLOBAL_NAME2) == 0));
2104 /* if we've just struck a global section, note the fact. */
2105 lp_ctx->bInGlobalSection = isglobal;
2107 /* check for multiple global sections */
2108 if (lp_ctx->bInGlobalSection) {
2109 DEBUG(4, ("Processing section \"[%s]\"\n", pszSectionName));
2114 /* if we have a current service, tidy it up before moving on */
2117 if (lp_ctx->currentService != NULL)
2118 bRetval = lpcfg_service_ok(lp_ctx->currentService);
2120 /* if all is still well, move to the next record in the services array */
2122 /* We put this here to avoid an odd message order if messages are */
2123 /* issued by the post-processing of a previous section. */
2124 DEBUG(4, ("Processing section \"[%s]\"\n", pszSectionName));
2126 if ((lp_ctx->currentService = lpcfg_add_service(lp_ctx, lp_ctx->sDefault,
2129 DEBUG(0, ("Failed to add a new service\n"));
2140 * Determine if a particular base parameter is currently set to the default value.
2143 static bool is_default(void *base_structure, int i)
2145 void *def_ptr = ((char *)base_structure) + parm_table[i].offset;
2146 switch (parm_table[i].type) {
2149 return str_list_equal((const char * const *)parm_table[i].def.lvalue,
2150 *(const char * const **)def_ptr);
2153 return strequal(parm_table[i].def.svalue,
2157 return parm_table[i].def.bvalue ==
2164 return parm_table[i].def.ivalue ==
2171 *Display the contents of the global structure.
2174 void lpcfg_dump_globals(struct loadparm_context *lp_ctx, FILE *f,
2178 struct parmlist_entry *data;
2180 fprintf(f, "# Global parameters\n[global]\n");
2182 for (i = 0; parm_table[i].label; i++) {
2183 if (parm_table[i].p_class != P_GLOBAL) {
2187 if (parm_table[i].flags & FLAG_SYNONYM) {
2191 if (!show_defaults) {
2192 if (lp_ctx->flags && (lp_ctx->flags[i] & FLAG_DEFAULT)) {
2196 if (is_default(lp_ctx->globals, i)) {
2201 fprintf(f, "\t%s = ", parm_table[i].label);
2202 lpcfg_print_parameter(&parm_table[i], lpcfg_parm_ptr(lp_ctx, NULL, &parm_table[i]), f);
2205 if (lp_ctx->globals->param_opt != NULL) {
2206 for (data = lp_ctx->globals->param_opt; data;
2207 data = data->next) {
2208 if (!show_defaults && (data->priority & FLAG_DEFAULT)) {
2211 fprintf(f, "\t%s = %s\n", data->key, data->value);
2218 * Display the contents of a single services record.
2221 void lpcfg_dump_a_service(struct loadparm_service * pService, struct loadparm_service *sDefault, FILE * f,
2222 unsigned int *flags, bool show_defaults)
2225 struct parmlist_entry *data;
2227 if (pService != sDefault)
2228 fprintf(f, "\n[%s]\n", pService->szService);
2230 for (i = 0; parm_table[i].label; i++) {
2231 if (parm_table[i].p_class != P_LOCAL) {
2235 if (parm_table[i].flags & FLAG_SYNONYM) {
2239 if (*parm_table[i].label == '-') {
2243 if (pService == sDefault) {
2244 if (!show_defaults) {
2245 if (flags && (flags[i] & FLAG_DEFAULT)) {
2249 if (is_default(sDefault, i)) {
2256 equal = lpcfg_equal_parameter(parm_table[i].type,
2257 ((char *)pService) +
2258 parm_table[i].offset,
2259 ((char *)sDefault) +
2260 parm_table[i].offset);
2266 fprintf(f, "\t%s = ", parm_table[i].label);
2267 lpcfg_print_parameter(&parm_table[i],
2268 ((char *)pService) + parm_table[i].offset, f);
2271 if (pService->param_opt != NULL) {
2272 for (data = pService->param_opt; data; data = data->next) {
2273 if (!show_defaults && (data->priority & FLAG_DEFAULT)) {
2276 fprintf(f, "\t%s = %s\n", data->key, data->value);
2281 bool lpcfg_dump_a_parameter(struct loadparm_context *lp_ctx,
2282 struct loadparm_service *service,
2283 const char *parm_name, FILE * f)
2285 struct parm_struct *parm;
2287 char *local_parm_name;
2289 const char *parm_opt_value;
2291 /* check for parametrical option */
2292 local_parm_name = talloc_strdup(lp_ctx, parm_name);
2293 if (local_parm_name == NULL) {
2297 parm_opt = strchr( local_parm_name, ':');
2302 if (strlen(parm_opt)) {
2303 parm_opt_value = lpcfg_parm_string(lp_ctx, service,
2304 local_parm_name, parm_opt);
2305 if (parm_opt_value) {
2306 fprintf(f, "%s\n", parm_opt_value);
2307 TALLOC_FREE(local_parm_name);
2311 TALLOC_FREE(local_parm_name);
2314 TALLOC_FREE(local_parm_name);
2316 /* parameter is not parametric, search the table */
2317 parm = lpcfg_parm_struct(lp_ctx, parm_name);
2322 if (service != NULL && parm->p_class == P_GLOBAL) {
2326 ptr = lpcfg_parm_ptr(lp_ctx, service,parm);
2328 lpcfg_print_parameter(parm, ptr, f);
2334 * Auto-load some home services.
2336 static void lpcfg_add_auto_services(struct loadparm_context *lp_ctx,
2342 /***************************************************************************
2343 Initialise the sDefault parameter structure for the printer values.
2344 ***************************************************************************/
2346 void init_printer_values(struct loadparm_context *lp_ctx, TALLOC_CTX *ctx,
2347 struct loadparm_service *pService)
2349 /* choose defaults depending on the type of printing */
2350 switch (pService->printing) {
2355 lpcfg_string_set(ctx, &pService->lpq_command, "lpq -P'%p'");
2356 lpcfg_string_set(ctx, &pService->lprm_command, "lprm -P'%p' %j");
2357 lpcfg_string_set(ctx, &pService->print_command, "lpr -r -P'%p' %s");
2362 lpcfg_string_set(ctx, &pService->lpq_command, "lpq -P'%p'");
2363 lpcfg_string_set(ctx, &pService->lprm_command, "lprm -P'%p' %j");
2364 lpcfg_string_set(ctx, &pService->print_command, "lpr -r -P'%p' %s");
2365 lpcfg_string_set(ctx, &pService->queuepause_command, "lpc stop '%p'");
2366 lpcfg_string_set(ctx, &pService->queueresume_command, "lpc start '%p'");
2367 lpcfg_string_set(ctx, &pService->lppause_command, "lpc hold '%p' %j");
2368 lpcfg_string_set(ctx, &pService->lpresume_command, "lpc release '%p' %j");
2373 /* set the lpq command to contain the destination printer
2374 name only. This is used by cups_queue_get() */
2375 lpcfg_string_set(ctx, &pService->lpq_command, "%p");
2376 lpcfg_string_set(ctx, &pService->lprm_command, "");
2377 lpcfg_string_set(ctx, &pService->print_command, "");
2378 lpcfg_string_set(ctx, &pService->lppause_command, "");
2379 lpcfg_string_set(ctx, &pService->lpresume_command, "");
2380 lpcfg_string_set(ctx, &pService->queuepause_command, "");
2381 lpcfg_string_set(ctx, &pService->queueresume_command, "");
2386 lpcfg_string_set(ctx, &pService->lpq_command, "lpstat -o%p");
2387 lpcfg_string_set(ctx, &pService->lprm_command, "cancel %p-%j");
2388 lpcfg_string_set(ctx, &pService->print_command, "lp -c -d%p %s; rm %s");
2389 lpcfg_string_set(ctx, &pService->queuepause_command, "disable %p");
2390 lpcfg_string_set(ctx, &pService->queueresume_command, "enable %p");
2392 lpcfg_string_set(ctx, &pService->lppause_command, "lp -i %p-%j -H hold");
2393 lpcfg_string_set(ctx, &pService->lpresume_command, "lp -i %p-%j -H resume");
2398 lpcfg_string_set(ctx, &pService->lpq_command, "lpq -P%p");
2399 lpcfg_string_set(ctx, &pService->lprm_command, "lprm -P%p %j");
2400 lpcfg_string_set(ctx, &pService->print_command, "lp -r -P%p %s");
2403 #if defined(DEVELOPER) || defined(ENABLE_SELFTEST)
2407 const char *tdbfile;
2408 TALLOC_CTX *tmp_ctx = talloc_new(ctx);
2411 tmp = lpcfg_parm_string(lp_ctx, NULL, "vlp", "tdbfile");
2413 tmp = "/tmp/vlp.tdb";
2416 tdbfile = talloc_asprintf(tmp_ctx, "tdbfile=%s", tmp);
2417 if (tdbfile == NULL) {
2418 tdbfile="tdbfile=/tmp/vlp.tdb";
2421 tmp = talloc_asprintf(tmp_ctx, "vlp %s print %%p %%s",
2423 lpcfg_string_set(ctx, &pService->print_command,
2424 tmp ? tmp : "vlp print %p %s");
2426 tmp = talloc_asprintf(tmp_ctx, "vlp %s lpq %%p",
2428 lpcfg_string_set(ctx, &pService->lpq_command,
2429 tmp ? tmp : "vlp lpq %p");
2431 tmp = talloc_asprintf(tmp_ctx, "vlp %s lprm %%p %%j",
2433 lpcfg_string_set(ctx, &pService->lprm_command,
2434 tmp ? tmp : "vlp lprm %p %j");
2436 tmp = talloc_asprintf(tmp_ctx, "vlp %s lppause %%p %%j",
2438 lpcfg_string_set(ctx, &pService->lppause_command,
2439 tmp ? tmp : "vlp lppause %p %j");
2441 tmp = talloc_asprintf(tmp_ctx, "vlp %s lpresume %%p %%j",
2443 lpcfg_string_set(ctx, &pService->lpresume_command,
2444 tmp ? tmp : "vlp lpresume %p %j");
2446 tmp = talloc_asprintf(tmp_ctx, "vlp %s queuepause %%p",
2448 lpcfg_string_set(ctx, &pService->queuepause_command,
2449 tmp ? tmp : "vlp queuepause %p");
2451 tmp = talloc_asprintf(tmp_ctx, "vlp %s queueresume %%p",
2453 lpcfg_string_set(ctx, &pService->queueresume_command,
2454 tmp ? tmp : "vlp queueresume %p");
2455 TALLOC_FREE(tmp_ctx);
2459 #endif /* DEVELOPER */
2465 static int lpcfg_destructor(struct loadparm_context *lp_ctx)
2467 struct parmlist_entry *data;
2469 if (lp_ctx->refuse_free) {
2470 /* someone is trying to free the
2471 global_loadparm_context.
2472 We can't allow that. */
2476 if (lp_ctx->globals->param_opt != NULL) {
2477 struct parmlist_entry *next;
2478 for (data = lp_ctx->globals->param_opt; data; data=next) {
2480 if (data->priority & FLAG_CMDLINE) continue;
2481 DLIST_REMOVE(lp_ctx->globals->param_opt, data);
2490 * Initialise the global parameter structure.
2492 * Note that most callers should use loadparm_init_global() instead
2494 struct loadparm_context *loadparm_init(TALLOC_CTX *mem_ctx)
2498 struct loadparm_context *lp_ctx;
2499 struct parmlist_entry *parm;
2502 lp_ctx = talloc_zero(mem_ctx, struct loadparm_context);
2506 talloc_set_destructor(lp_ctx, lpcfg_destructor);
2507 lp_ctx->bInGlobalSection = true;
2508 lp_ctx->globals = talloc_zero(lp_ctx, struct loadparm_global);
2509 /* This appears odd, but globals in s3 isn't a pointer */
2510 lp_ctx->globals->ctx = lp_ctx->globals;
2511 lp_ctx->globals->rpc_low_port = SERVER_TCP_LOW_PORT;
2512 lp_ctx->globals->rpc_high_port = SERVER_TCP_HIGH_PORT;
2513 lp_ctx->globals->weak_crypto = SAMBA_WEAK_CRYPTO_UNKNOWN;
2514 lp_ctx->sDefault = talloc_zero(lp_ctx, struct loadparm_service);
2515 lp_ctx->flags = talloc_zero_array(lp_ctx, unsigned int, num_parameters());
2517 lp_ctx->sDefault->max_print_jobs = 1000;
2518 lp_ctx->sDefault->available = true;
2519 lp_ctx->sDefault->browseable = true;
2520 lp_ctx->sDefault->read_only = true;
2521 lp_ctx->sDefault->map_archive = true;
2522 lp_ctx->sDefault->strict_locking = true;
2523 lp_ctx->sDefault->oplocks = true;
2524 lp_ctx->sDefault->create_mask = 0744;
2525 lp_ctx->sDefault->force_create_mode = 0000;
2526 lp_ctx->sDefault->directory_mask = 0755;
2527 lp_ctx->sDefault->force_directory_mode = 0000;
2528 lp_ctx->sDefault->aio_read_size = 1;
2529 lp_ctx->sDefault->aio_write_size = 1;
2530 lp_ctx->sDefault->smbd_search_ask_sharemode = true;
2531 lp_ctx->sDefault->smbd_getinfo_ask_sharemode = true;
2532 lp_ctx->sDefault->volume_serial_number = -1;
2534 DEBUG(3, ("Initialising global parameters\n"));
2536 for (i = 0; parm_table[i].label; i++) {
2537 if ((parm_table[i].type == P_STRING ||
2538 parm_table[i].type == P_USTRING) &&
2539 !(lp_ctx->flags[i] & FLAG_CMDLINE)) {
2540 TALLOC_CTX *parent_mem;
2542 if (parm_table[i].p_class == P_LOCAL) {
2543 parent_mem = lp_ctx->sDefault;
2544 r = (char **)(((char *)lp_ctx->sDefault) + parm_table[i].offset);
2546 parent_mem = lp_ctx->globals;
2547 r = (char **)(((char *)lp_ctx->globals) + parm_table[i].offset);
2549 lpcfg_string_set(parent_mem, r, "");
2553 logfile = talloc_asprintf(lp_ctx, "%s/log.samba", dyn_LOGFILEBASE);
2554 lpcfg_do_global_parameter(lp_ctx, "log file", logfile);
2555 talloc_free(logfile);
2557 lpcfg_do_global_parameter(lp_ctx, "log level", "0");
2559 lpcfg_do_global_parameter(lp_ctx, "syslog", "1");
2560 lpcfg_do_global_parameter(lp_ctx, "syslog only", "No");
2561 lpcfg_do_global_parameter(lp_ctx, "debug timestamp", "Yes");
2562 lpcfg_do_global_parameter(lp_ctx, "debug prefix timestamp", "No");
2563 lpcfg_do_global_parameter(lp_ctx, "debug hires timestamp", "Yes");
2564 lpcfg_do_global_parameter(lp_ctx, "debug syslog format", "No");
2565 lpcfg_do_global_parameter(lp_ctx, "debug pid", "No");
2566 lpcfg_do_global_parameter(lp_ctx, "debug uid", "No");
2567 lpcfg_do_global_parameter(lp_ctx, "debug class", "No");
2569 lpcfg_do_global_parameter(lp_ctx, "server role", "auto");
2570 lpcfg_do_global_parameter(lp_ctx, "domain logons", "No");
2571 lpcfg_do_global_parameter(lp_ctx, "domain master", "Auto");
2573 /* options that can be set on the command line must be initialised via
2574 the slower lpcfg_do_global_parameter() to ensure that FLAG_CMDLINE is obeyed */
2576 lpcfg_do_global_parameter(lp_ctx, "socket options", "TCP_NODELAY");
2578 lpcfg_do_global_parameter(lp_ctx, "workgroup", DEFAULT_WORKGROUP);
2579 myname = get_myname(lp_ctx);
2580 lpcfg_do_global_parameter(lp_ctx, "netbios name", myname);
2581 talloc_free(myname);
2582 lpcfg_do_global_parameter(lp_ctx,
2583 "name resolve order",
2584 DEFAULT_NAME_RESOLVE_ORDER);
2586 lpcfg_do_global_parameter(lp_ctx, "fstype", "NTFS");
2588 lpcfg_do_global_parameter(lp_ctx, "ntvfs handler", "unixuid default");
2589 lpcfg_do_global_parameter(lp_ctx, "max connections", "0");
2591 lpcfg_do_global_parameter(lp_ctx, "dcerpc endpoint servers", "epmapper wkssvc rpcecho samr netlogon lsarpc drsuapi dssetup unixinfo browser eventlog6 backupkey dnsserver");
2592 lpcfg_do_global_parameter(lp_ctx, "server services", "s3fs rpc nbt wrepl ldap cldap kdc drepl winbindd ntp_signd kcc dnsupdate dns");
2593 lpcfg_do_global_parameter(lp_ctx, "kccsrv:samba_kcc", "true");
2594 /* the winbind method for domain controllers is for both RODC
2595 auth forwarding and for trusted domains */
2596 lpcfg_do_global_parameter(lp_ctx, "private dir", dyn_PRIVATE_DIR);
2597 lpcfg_do_global_parameter(lp_ctx, "binddns dir", dyn_BINDDNS_DIR);
2598 lpcfg_do_global_parameter(lp_ctx, "registry:HKEY_LOCAL_MACHINE", "hklm.ldb");
2600 /* This hive should be dynamically generated by Samba using
2601 data from the sam, but for the moment leave it in a tdb to
2602 keep regedt32 from popping up an annoying dialog. */
2603 lpcfg_do_global_parameter(lp_ctx, "registry:HKEY_USERS", "hku.ldb");
2605 /* using UTF8 by default allows us to support all chars */
2606 lpcfg_do_global_parameter(lp_ctx, "unix charset", "UTF-8");
2608 /* Use codepage 850 as a default for the dos character set */
2609 lpcfg_do_global_parameter(lp_ctx, "dos charset", "CP850");
2612 * Allow the default PASSWD_CHAT to be overridden in local.h.
2614 lpcfg_do_global_parameter(lp_ctx, "passwd chat", DEFAULT_PASSWD_CHAT);
2616 lpcfg_do_global_parameter(lp_ctx, "pid directory", dyn_PIDDIR);
2617 lpcfg_do_global_parameter(lp_ctx, "lock dir", dyn_LOCKDIR);
2618 lpcfg_do_global_parameter(lp_ctx, "state directory", dyn_STATEDIR);
2619 lpcfg_do_global_parameter(lp_ctx, "cache directory", dyn_CACHEDIR);
2620 lpcfg_do_global_parameter(lp_ctx, "ncalrpc dir", dyn_NCALRPCDIR);
2622 lpcfg_do_global_parameter(lp_ctx, "nbt client socket address", "0.0.0.0");
2623 lpcfg_do_global_parameter_var(lp_ctx, "server string",
2624 "Samba %s", SAMBA_VERSION_STRING);
2626 lpcfg_do_global_parameter(lp_ctx, "password server", "*");
2628 lpcfg_do_global_parameter(lp_ctx, "max mux", "50");
2629 lpcfg_do_global_parameter(lp_ctx, "max xmit", "16644");
2630 lpcfg_do_global_parameter(lp_ctx, "host msdfs", "true");
2632 lpcfg_do_global_parameter(lp_ctx, "LargeReadwrite", "True");
2633 lpcfg_do_global_parameter(lp_ctx, "server min protocol", "SMB2_02");
2634 lpcfg_do_global_parameter(lp_ctx, "server max protocol", "SMB3");
2635 lpcfg_do_global_parameter(lp_ctx, "client min protocol", "SMB2_02");
2636 lpcfg_do_global_parameter(lp_ctx, "client max protocol", "default");
2637 lpcfg_do_global_parameter(lp_ctx, "client ipc min protocol", "default");
2638 lpcfg_do_global_parameter(lp_ctx, "client ipc max protocol", "default");
2639 lpcfg_do_global_parameter(lp_ctx, "security", "AUTO");
2640 lpcfg_do_global_parameter(lp_ctx, "EncryptPasswords", "True");
2641 lpcfg_do_global_parameter(lp_ctx, "ReadRaw", "True");
2642 lpcfg_do_global_parameter(lp_ctx, "WriteRaw", "True");
2643 lpcfg_do_global_parameter(lp_ctx, "NullPasswords", "False");
2644 lpcfg_do_global_parameter(lp_ctx, "old password allowed period", "60");
2645 lpcfg_do_global_parameter(lp_ctx, "ObeyPamRestrictions", "False");
2647 lpcfg_do_global_parameter(lp_ctx, "TimeServer", "False");
2648 lpcfg_do_global_parameter(lp_ctx, "BindInterfacesOnly", "False");
2649 lpcfg_do_global_parameter(lp_ctx, "Unicode", "True");
2650 lpcfg_do_global_parameter(lp_ctx, "ClientLanManAuth", "False");
2651 lpcfg_do_global_parameter(lp_ctx, "ClientNTLMv2Auth", "True");
2652 lpcfg_do_global_parameter(lp_ctx, "LanmanAuth", "False");
2653 lpcfg_do_global_parameter(lp_ctx, "NTLMAuth", "ntlmv2-only");
2654 lpcfg_do_global_parameter(lp_ctx, "NT hash store", "always");
2655 lpcfg_do_global_parameter(lp_ctx, "RawNTLMv2Auth", "False");
2656 lpcfg_do_global_parameter(lp_ctx, "client use spnego principal", "False");
2658 lpcfg_do_global_parameter(lp_ctx, "allow dcerpc auth level connect", "False");
2660 lpcfg_do_global_parameter(lp_ctx, "UnixExtensions", "True");
2662 lpcfg_do_global_parameter(lp_ctx, "PreferredMaster", "Auto");
2663 lpcfg_do_global_parameter(lp_ctx, "LocalMaster", "True");
2665 lpcfg_do_global_parameter(lp_ctx, "wins support", "False");
2666 lpcfg_do_global_parameter(lp_ctx, "dns proxy", "True");
2668 lpcfg_do_global_parameter(lp_ctx, "winbind separator", "\\");
2669 lpcfg_do_global_parameter(lp_ctx, "winbind sealed pipes", "True");
2670 lpcfg_do_global_parameter(lp_ctx, "winbind scan trusted domains", "False");
2671 lpcfg_do_global_parameter(lp_ctx, "require strong key", "True");
2672 lpcfg_do_global_parameter(lp_ctx, "reject md5 servers", "True");
2673 lpcfg_do_global_parameter(lp_ctx, "winbindd socket directory", dyn_WINBINDD_SOCKET_DIR);
2674 lpcfg_do_global_parameter(lp_ctx, "ntp signd socket directory", dyn_NTP_SIGND_SOCKET_DIR);
2675 lpcfg_do_global_parameter_var(lp_ctx, "gpo update command", "%s/samba-gpupdate", dyn_SCRIPTSBINDIR);
2676 lpcfg_do_global_parameter_var(lp_ctx, "apply group policies", "False");
2677 lpcfg_do_global_parameter_var(lp_ctx, "dns update command", "%s/samba_dnsupdate", dyn_SCRIPTSBINDIR);
2678 lpcfg_do_global_parameter_var(lp_ctx, "spn update command", "%s/samba_spnupdate", dyn_SCRIPTSBINDIR);
2679 lpcfg_do_global_parameter_var(lp_ctx, "samba kcc command",
2680 "%s/samba_kcc", dyn_SCRIPTSBINDIR);
2682 lpcfg_do_global_parameter_var(lp_ctx,
2686 lpcfg_do_global_parameter(lp_ctx, "template shell", "/bin/false");
2687 lpcfg_do_global_parameter(lp_ctx, "template homedir", "/home/%D/%U");
2689 lpcfg_do_global_parameter(lp_ctx, "client signing", "default");
2690 lpcfg_do_global_parameter(lp_ctx, "client ipc signing", "default");
2691 lpcfg_do_global_parameter(lp_ctx, "server signing", "default");
2693 lpcfg_do_global_parameter(lp_ctx, "use mmap", "True");
2695 lpcfg_do_global_parameter(lp_ctx, "smb ports", "445 139");
2696 lpcfg_do_global_parameter_var(lp_ctx, "nbt port", "%d", NBT_NAME_SERVICE_PORT);
2697 lpcfg_do_global_parameter_var(lp_ctx, "dgram port", "%d", NBT_DGRAM_SERVICE_PORT);
2698 lpcfg_do_global_parameter(lp_ctx, "cldap port", "389");
2699 lpcfg_do_global_parameter(lp_ctx, "krb5 port", "88");
2700 lpcfg_do_global_parameter(lp_ctx, "kpasswd port", "464");
2701 lpcfg_do_global_parameter_var(lp_ctx, "dns port", "%d", DNS_SERVICE_PORT);
2703 lpcfg_do_global_parameter(lp_ctx, "kdc enable fast", "True");
2705 lpcfg_do_global_parameter(lp_ctx, "nt status support", "True");
2707 lpcfg_do_global_parameter(lp_ctx, "max wins ttl", "518400"); /* 6 days */
2708 lpcfg_do_global_parameter(lp_ctx, "min wins ttl", "21600");
2710 lpcfg_do_global_parameter(lp_ctx, "tls enabled", "True");
2711 lpcfg_do_global_parameter(lp_ctx, "tls verify peer", "as_strict_as_possible");
2712 lpcfg_do_global_parameter(lp_ctx, "tls keyfile", "tls/key.pem");
2713 lpcfg_do_global_parameter(lp_ctx, "tls certfile", "tls/cert.pem");
2714 lpcfg_do_global_parameter(lp_ctx, "tls cafile", "tls/ca.pem");
2715 lpcfg_do_global_parameter(lp_ctx,
2717 "NORMAL:-VERS-SSL3.0");
2719 lpcfg_do_global_parameter(lp_ctx, "nsupdate command", "/usr/bin/nsupdate -g");
2721 lpcfg_do_global_parameter(lp_ctx, "allow dns updates", "secure only");
2722 lpcfg_do_global_parameter(lp_ctx, "dns zone scavenging", "False");
2723 lpcfg_do_global_parameter(lp_ctx, "dns forwarder", "");
2725 lpcfg_do_global_parameter(lp_ctx, "algorithmic rid base", "1000");
2727 lpcfg_do_global_parameter(lp_ctx, "enhanced browsing", "True");
2729 lpcfg_do_global_parameter(lp_ctx, "winbind nss info", "template");
2731 lpcfg_do_global_parameter(lp_ctx, "server schannel", "True");
2733 lpcfg_do_global_parameter(lp_ctx, "short preserve case", "True");
2735 lpcfg_do_global_parameter(lp_ctx, "max open files", "16384");
2737 lpcfg_do_global_parameter(lp_ctx, "cups connection timeout", "30");
2739 lpcfg_do_global_parameter(lp_ctx, "locking", "True");
2741 lpcfg_do_global_parameter(lp_ctx, "block size", "1024");
2743 lpcfg_do_global_parameter(lp_ctx, "client use spnego", "True");
2745 lpcfg_do_global_parameter(lp_ctx, "change notify", "True");
2747 lpcfg_do_global_parameter(lp_ctx, "name cache timeout", "660");
2749 lpcfg_do_global_parameter(lp_ctx, "defer sharing violations", "True");
2751 lpcfg_do_global_parameter(lp_ctx, "ldap replication sleep", "1000");
2753 lpcfg_do_global_parameter(lp_ctx, "idmap backend", "tdb");
2755 lpcfg_do_global_parameter(lp_ctx, "enable privileges", "True");
2757 lpcfg_do_global_parameter_var(lp_ctx, "smb2 max write", "%u", DEFAULT_SMB2_MAX_WRITE);
2759 lpcfg_do_global_parameter(lp_ctx, "passdb backend", "tdbsam");
2761 lpcfg_do_global_parameter(lp_ctx, "deadtime", "10080");
2763 lpcfg_do_global_parameter(lp_ctx, "getwd cache", "True");
2765 lpcfg_do_global_parameter(lp_ctx, "winbind nested groups", "True");
2767 lpcfg_do_global_parameter(lp_ctx, "mangled names", "illegal");
2769 lpcfg_do_global_parameter_var(lp_ctx, "smb2 max credits", "%u", DEFAULT_SMB2_MAX_CREDITS);
2771 lpcfg_do_global_parameter(lp_ctx, "ldap ssl", "start tls");
2773 lpcfg_do_global_parameter(lp_ctx, "ldap deref", "auto");
2775 lpcfg_do_global_parameter(lp_ctx, "lm interval", "60");
2777 lpcfg_do_global_parameter(lp_ctx, "mangling method", "hash2");
2779 lpcfg_do_global_parameter(lp_ctx, "hide dot files", "True");
2781 lpcfg_do_global_parameter(lp_ctx, "browse list", "True");
2783 lpcfg_do_global_parameter(lp_ctx, "passwd chat timeout", "2");
2785 lpcfg_do_global_parameter(lp_ctx, "guest account", GUEST_ACCOUNT);
2787 lpcfg_do_global_parameter(lp_ctx, "client schannel", "True");
2789 lpcfg_do_global_parameter(lp_ctx, "smb encrypt", "default");
2791 lpcfg_do_global_parameter(lp_ctx, "max log size", "5000");
2793 lpcfg_do_global_parameter(lp_ctx, "idmap negative cache time", "120");
2795 lpcfg_do_global_parameter(lp_ctx, "ldap follow referral", "auto");
2797 lpcfg_do_global_parameter(lp_ctx, "multicast dns register", "yes");
2799 lpcfg_do_global_parameter(lp_ctx, "winbind reconnect delay", "30");
2801 lpcfg_do_global_parameter(lp_ctx, "winbind request timeout", "60");
2803 lpcfg_do_global_parameter(lp_ctx, "nt acl support", "yes");
2805 lpcfg_do_global_parameter(lp_ctx, "acl check permissions", "yes");
2807 lpcfg_do_global_parameter(lp_ctx, "keepalive", "300");
2809 lpcfg_do_global_parameter(lp_ctx, "smbd profiling level", "off");
2811 lpcfg_do_global_parameter(lp_ctx, "winbind cache time", "300");
2813 lpcfg_do_global_parameter(lp_ctx, "level2 oplocks", "yes");
2815 lpcfg_do_global_parameter(lp_ctx, "show add printer wizard", "yes");
2817 lpcfg_do_global_parameter(lp_ctx, "ldap page size", "1000");
2819 lpcfg_do_global_parameter(lp_ctx, "kernel share modes", "no");
2821 lpcfg_do_global_parameter(lp_ctx, "strict locking", "Auto");
2823 lpcfg_do_global_parameter(lp_ctx, "strict sync", "yes");
2825 lpcfg_do_global_parameter(lp_ctx, "map readonly", "no");
2827 lpcfg_do_global_parameter(lp_ctx, "allow trusted domains", "yes");
2829 lpcfg_do_global_parameter(lp_ctx, "default devmode", "yes");
2831 lpcfg_do_global_parameter(lp_ctx, "os level", "20");
2833 lpcfg_do_global_parameter(lp_ctx, "dos filetimes", "yes");
2835 lpcfg_do_global_parameter(lp_ctx, "mangling char", "~");
2837 lpcfg_do_global_parameter(lp_ctx, "printcap cache time", "750");
2839 lpcfg_do_global_parameter(lp_ctx, "create krb5 conf", "yes");
2841 lpcfg_do_global_parameter(lp_ctx, "winbind max clients", "200");
2843 lpcfg_do_global_parameter(lp_ctx, "acl map full control", "yes");
2845 lpcfg_do_global_parameter(lp_ctx, "nt pipe support", "yes");
2847 lpcfg_do_global_parameter(lp_ctx, "ldap debug threshold", "10");
2849 lpcfg_do_global_parameter(lp_ctx, "client ldap sasl wrapping", "sign");
2851 lpcfg_do_global_parameter(lp_ctx, "mdns name", "netbios");
2853 lpcfg_do_global_parameter(lp_ctx, "ldap server require strong auth", "yes");
2855 lpcfg_do_global_parameter(lp_ctx, "follow symlinks", "yes");
2857 lpcfg_do_global_parameter(lp_ctx, "machine password timeout", "604800");
2859 lpcfg_do_global_parameter(lp_ctx, "ldap connection timeout", "2");
2861 lpcfg_do_global_parameter(lp_ctx, "winbind expand groups", "0");
2863 lpcfg_do_global_parameter(lp_ctx, "stat cache", "yes");
2865 lpcfg_do_global_parameter(lp_ctx, "lpq cache time", "30");
2867 lpcfg_do_global_parameter_var(lp_ctx, "smb2 max trans", "%u", DEFAULT_SMB2_MAX_TRANSACT);
2869 lpcfg_do_global_parameter_var(lp_ctx, "smb2 max read", "%u", DEFAULT_SMB2_MAX_READ);
2871 lpcfg_do_global_parameter(lp_ctx, "durable handles", "yes");
2873 lpcfg_do_global_parameter(lp_ctx, "max stat cache size", "512");
2875 lpcfg_do_global_parameter(lp_ctx, "ldap passwd sync", "no");
2877 lpcfg_do_global_parameter(lp_ctx, "kernel change notify", "yes");
2879 lpcfg_do_global_parameter(lp_ctx, "max ttl", "259200");
2881 lpcfg_do_global_parameter(lp_ctx, "blocking locks", "yes");
2883 lpcfg_do_global_parameter(lp_ctx, "load printers", "yes");
2885 lpcfg_do_global_parameter(lp_ctx, "idmap cache time", "604800");
2887 lpcfg_do_global_parameter(lp_ctx, "preserve case", "yes");
2889 lpcfg_do_global_parameter(lp_ctx, "lm announce", "auto");
2891 lpcfg_do_global_parameter(lp_ctx, "afs token lifetime", "604800");
2893 lpcfg_do_global_parameter(lp_ctx, "enable core files", "yes");
2895 lpcfg_do_global_parameter(lp_ctx, "winbind max domain connections", "1");
2897 lpcfg_do_global_parameter(lp_ctx, "case sensitive", "auto");
2899 lpcfg_do_global_parameter(lp_ctx, "ldap timeout", "15");
2901 lpcfg_do_global_parameter(lp_ctx, "mangle prefix", "1");
2903 lpcfg_do_global_parameter(lp_ctx, "posix locking", "yes");
2905 lpcfg_do_global_parameter(lp_ctx, "lock spin time", "200");
2907 lpcfg_do_global_parameter(lp_ctx, "directory name cache size", "100");
2909 lpcfg_do_global_parameter(lp_ctx, "nmbd bind explicit broadcast", "yes");
2911 lpcfg_do_global_parameter(lp_ctx, "init logon delay", "100");
2913 lpcfg_do_global_parameter(lp_ctx, "usershare owner only", "yes");
2915 lpcfg_do_global_parameter(lp_ctx, "-valid", "yes");
2917 lpcfg_do_global_parameter_var(lp_ctx, "usershare path", "%s/usershares", get_dyn_STATEDIR());
2920 lpcfg_do_global_parameter_var(lp_ctx, "panic action", "/bin/sleep 999999999");
2923 lpcfg_do_global_parameter(lp_ctx, "smb passwd file", get_dyn_SMB_PASSWD_FILE());
2925 lpcfg_do_global_parameter(lp_ctx, "logon home", "\\\\%N\\%U");
2927 lpcfg_do_global_parameter(lp_ctx, "logon path", "\\\\%N\\%U\\profile");
2929 lpcfg_do_global_parameter(lp_ctx, "printjob username", "%U");
2931 lpcfg_do_global_parameter(lp_ctx, "aio max threads", "100");
2933 lpcfg_do_global_parameter(lp_ctx, "smb2 leases", "yes");
2935 lpcfg_do_global_parameter(lp_ctx, "server multi channel support", "yes");
2937 lpcfg_do_global_parameter(lp_ctx, "kerberos encryption types", "all");
2939 lpcfg_do_global_parameter(lp_ctx,
2940 "rpc server dynamic port range",
2943 lpcfg_do_global_parameter(lp_ctx, "prefork children", "4");
2944 lpcfg_do_global_parameter(lp_ctx, "prefork backoff increment", "10");
2945 lpcfg_do_global_parameter(lp_ctx, "prefork maximum backoff", "120");
2947 lpcfg_do_global_parameter(lp_ctx, "check parent directory delete on close", "no");
2949 lpcfg_do_global_parameter(lp_ctx, "ea support", "yes");
2951 lpcfg_do_global_parameter(lp_ctx, "store dos attributes", "yes");
2953 lpcfg_do_global_parameter(lp_ctx, "debug encryption", "no");
2955 lpcfg_do_global_parameter(lp_ctx, "spotlight backend", "noindex");
2957 lpcfg_do_global_parameter(
2958 lp_ctx, "ldap max anonymous request size", "256000");
2959 lpcfg_do_global_parameter(
2960 lp_ctx, "ldap max authenticated request size", "16777216");
2961 lpcfg_do_global_parameter(
2962 lp_ctx, "ldap max search request size", "256000");
2964 /* Async DNS query timeout in seconds. */
2965 lpcfg_do_global_parameter(lp_ctx, "async dns timeout", "10");
2967 lpcfg_do_global_parameter(lp_ctx,
2968 "client smb encrypt",
2971 lpcfg_do_global_parameter(lp_ctx,
2972 "client use kerberos",
2975 lpcfg_do_global_parameter(lp_ctx,
2976 "client protection",
2979 lpcfg_do_global_parameter(lp_ctx,
2980 "smbd max xattr size",
2983 lpcfg_do_global_parameter(lp_ctx,
2984 "acl flag inherited canonicalization",
2987 lpcfg_do_global_parameter(lp_ctx,
2988 "winbind use krb5 enterprise principals",
2991 lpcfg_do_global_parameter(lp_ctx,
2992 "client smb3 signing algorithms",
2993 DEFAULT_SMB3_SIGNING_ALGORITHMS);
2994 lpcfg_do_global_parameter(lp_ctx,
2995 "server smb3 signing algorithms",
2996 DEFAULT_SMB3_SIGNING_ALGORITHMS);
2998 lpcfg_do_global_parameter(lp_ctx,
2999 "client smb3 encryption algorithms",
3000 DEFAULT_SMB3_ENCRYPTION_ALGORITHMS);
3001 lpcfg_do_global_parameter(lp_ctx,
3002 "server smb3 encryption algorithms",
3003 DEFAULT_SMB3_ENCRYPTION_ALGORITHMS);
3005 lpcfg_do_global_parameter(lp_ctx,
3009 lpcfg_do_global_parameter(lp_ctx,
3010 "rpc start on demand helpers",
3013 for (i = 0; parm_table[i].label; i++) {
3014 if (!(lp_ctx->flags[i] & FLAG_CMDLINE)) {
3015 lp_ctx->flags[i] |= FLAG_DEFAULT;
3019 for (parm=lp_ctx->globals->param_opt; parm; parm=parm->next) {
3020 if (!(parm->priority & FLAG_CMDLINE)) {
3021 parm->priority |= FLAG_DEFAULT;
3025 for (parm=lp_ctx->sDefault->param_opt; parm; parm=parm->next) {
3026 if (!(parm->priority & FLAG_CMDLINE)) {
3027 parm->priority |= FLAG_DEFAULT;
3035 * Initialise the global parameter structure.
3037 struct loadparm_context *loadparm_init_global(bool load_default)
3039 if (global_loadparm_context == NULL) {
3040 global_loadparm_context = loadparm_init(NULL);
3042 if (global_loadparm_context == NULL) {
3045 global_loadparm_context->global = true;
3046 if (load_default && !global_loadparm_context->loaded) {
3047 lpcfg_load_default(global_loadparm_context);
3049 global_loadparm_context->refuse_free = true;
3050 return global_loadparm_context;
3054 * Initialise the global parameter structure.
3056 struct loadparm_context *loadparm_init_s3(TALLOC_CTX *mem_ctx,
3057 const struct loadparm_s3_helpers *s3_fns)
3059 struct loadparm_context *loadparm_context = talloc_zero(mem_ctx, struct loadparm_context);
3060 if (!loadparm_context) {
3063 loadparm_context->s3_fns = s3_fns;
3064 loadparm_context->globals = s3_fns->globals;
3065 loadparm_context->flags = s3_fns->flags;
3067 return loadparm_context;
3070 const char *lpcfg_configfile(struct loadparm_context *lp_ctx)
3072 return lp_ctx->szConfigFile;
3075 const char *lp_default_path(void)
3077 if (getenv("SMB_CONF_PATH"))
3078 return getenv("SMB_CONF_PATH");
3080 return dyn_CONFIGFILE;
3084 * Update the internal state of a loadparm context after settings
3087 static bool lpcfg_update(struct loadparm_context *lp_ctx)
3089 struct debug_settings settings;
3090 int max_protocol, min_protocol;
3091 TALLOC_CTX *tmp_ctx;
3092 const struct loadparm_substitution *lp_sub =
3093 lpcfg_noop_substitution();
3095 tmp_ctx = talloc_new(lp_ctx);
3096 if (tmp_ctx == NULL) {
3100 lpcfg_add_auto_services(lp_ctx, lpcfg_auto_services(lp_ctx, lp_sub, tmp_ctx));
3102 if (!lp_ctx->globals->wins_server_list && lp_ctx->globals->we_are_a_wins_server) {
3103 lpcfg_do_global_parameter(lp_ctx, "wins server", "127.0.0.1");
3106 if (!lp_ctx->global) {
3107 TALLOC_FREE(tmp_ctx);
3111 panic_action = lp_ctx->globals->panic_action;
3113 reload_charcnv(lp_ctx);
3115 ZERO_STRUCT(settings);
3116 /* Add any more debug-related smb.conf parameters created in
3118 settings.timestamp_logs = lp_ctx->globals->timestamp_logs;
3119 settings.debug_prefix_timestamp = lp_ctx->globals->debug_prefix_timestamp;
3120 settings.debug_hires_timestamp = lp_ctx->globals->debug_hires_timestamp;
3121 settings.debug_syslog_format = lp_ctx->globals->debug_syslog_format;
3122 settings.debug_pid = lp_ctx->globals->debug_pid;
3123 settings.debug_uid = lp_ctx->globals->debug_uid;
3124 settings.debug_class = lp_ctx->globals->debug_class;
3125 settings.max_log_size = lp_ctx->globals->max_log_size;
3126 debug_set_settings(&settings, lp_ctx->globals->logging,
3127 lp_ctx->globals->syslog,
3128 lp_ctx->globals->syslog_only);
3130 /* FIXME: This is a bit of a hack, but we can't use a global, since
3131 * not everything that uses lp also uses the socket library */
3132 if (lpcfg_parm_bool(lp_ctx, NULL, "socket", "testnonblock", false)) {
3133 setenv("SOCKET_TESTNONBLOCK", "1", 1);
3135 unsetenv("SOCKET_TESTNONBLOCK");
3138 /* Check if command line max protocol < min protocol, if so
3139 * report a warning to the user.
3141 max_protocol = lpcfg_client_max_protocol(lp_ctx);
3142 min_protocol = lpcfg_client_min_protocol(lp_ctx);
3143 if (lpcfg_client_max_protocol(lp_ctx) < lpcfg_client_min_protocol(lp_ctx)) {
3144 const char *max_protocolp, *min_protocolp;
3145 max_protocolp = lpcfg_get_smb_protocol(max_protocol);
3146 min_protocolp = lpcfg_get_smb_protocol(min_protocol);
3147 DBG_ERR("Max protocol %s is less than min protocol %s.\n",
3148 max_protocolp, min_protocolp);
3151 TALLOC_FREE(tmp_ctx);
3155 bool lpcfg_load_default(struct loadparm_context *lp_ctx)
3159 path = lp_default_path();
3161 if (!file_exist(path)) {
3162 /* We allow the default smb.conf file to not exist,
3163 * basically the equivalent of an empty file. */
3164 return lpcfg_update(lp_ctx);
3167 return lpcfg_load(lp_ctx, path);
3171 * Load the services array from the services file.
3173 * Return True on success, False on failure.
3175 static bool lpcfg_load_internal(struct loadparm_context *lp_ctx,
3176 const char *filename, bool set_global)
3181 if (lp_ctx->szConfigFile != NULL) {
3182 talloc_free(discard_const_p(char, lp_ctx->szConfigFile));
3183 lp_ctx->szConfigFile = NULL;
3186 lp_ctx->szConfigFile = talloc_strdup(lp_ctx, filename);
3188 if (lp_ctx->s3_fns) {
3189 return lp_ctx->s3_fns->load(filename);
3192 lp_ctx->bInGlobalSection = true;
3193 n2 = standard_sub_basic(lp_ctx, lp_ctx->szConfigFile);
3194 DEBUG(2, ("lpcfg_load: refreshing parameters from %s\n", n2));
3196 add_to_file_list(lp_ctx, &lp_ctx->file_lists, lp_ctx->szConfigFile, n2);
3198 /* We get sections first, so have to start 'behind' to make up */
3199 lp_ctx->currentService = NULL;
3200 bRetval = pm_process(n2, do_section, lpcfg_do_parameter, lp_ctx);
3202 /* finish up the last section */
3203 DEBUG(4, ("pm_process() returned %s\n", BOOLSTR(bRetval)));
3205 if (lp_ctx->currentService != NULL)
3206 bRetval = lpcfg_service_ok(lp_ctx->currentService);
3208 bRetval = bRetval && lpcfg_update(lp_ctx);
3210 /* we do this unconditionally, so that it happens even
3211 for a missing smb.conf */
3212 reload_charcnv(lp_ctx);
3214 if (bRetval == true && set_global) {
3215 /* set this up so that any child python tasks will
3216 find the right smb.conf */
3217 setenv("SMB_CONF_PATH", filename, 1);
3219 /* set the context used by the lp_*() function
3221 global_loadparm_context = lp_ctx;
3222 lp_ctx->loaded = true;
3228 bool lpcfg_load_no_global(struct loadparm_context *lp_ctx, const char *filename)
3230 return lpcfg_load_internal(lp_ctx, filename, false);
3233 bool lpcfg_load(struct loadparm_context *lp_ctx, const char *filename)
3235 return lpcfg_load_internal(lp_ctx, filename, true);
3239 * Return the max number of services.
3242 int lpcfg_numservices(struct loadparm_context *lp_ctx)
3244 if (lp_ctx->s3_fns) {
3245 return lp_ctx->s3_fns->get_numservices();
3248 return lp_ctx->iNumServices;
3252 * Display the contents of the services array in human-readable form.
3255 void lpcfg_dump(struct loadparm_context *lp_ctx, FILE *f, bool show_defaults,
3260 if (lp_ctx->s3_fns) {
3261 lp_ctx->s3_fns->dump(f, show_defaults, maxtoprint);
3265 lpcfg_dump_globals(lp_ctx, f, show_defaults);
3267 lpcfg_dump_a_service(lp_ctx->sDefault, lp_ctx->sDefault, f, lp_ctx->flags, show_defaults);
3269 for (iService = 0; iService < maxtoprint; iService++)
3270 lpcfg_dump_one(f, show_defaults, lp_ctx->services[iService], lp_ctx->sDefault);
3274 * Display the contents of one service in human-readable form.
3276 void lpcfg_dump_one(FILE *f, bool show_defaults, struct loadparm_service *service, struct loadparm_service *sDefault)
3278 if (service != NULL) {
3279 if (service->szService[0] == '\0')
3281 lpcfg_dump_a_service(service, sDefault, f, NULL, show_defaults);
3285 struct loadparm_service *lpcfg_servicebynum(struct loadparm_context *lp_ctx,
3288 if (lp_ctx->s3_fns) {
3289 return lp_ctx->s3_fns->get_servicebynum(snum);
3292 return lp_ctx->services[snum];
3295 struct loadparm_service *lpcfg_service(struct loadparm_context *lp_ctx,
3296 const char *service_name)
3301 if (lp_ctx->s3_fns) {
3302 return lp_ctx->s3_fns->get_service(service_name);
3305 for (iService = lp_ctx->iNumServices - 1; iService >= 0; iService--) {
3306 if (lp_ctx->services[iService] &&
3307 lp_ctx->services[iService]->szService) {
3309 * The substitution here is used to support %U is
3312 serviceName = standard_sub_basic(
3313 lp_ctx->services[iService],
3314 lp_ctx->services[iService]->szService);
3315 if (strequal(serviceName, service_name)) {
3316 talloc_free(serviceName);
3317 return lp_ctx->services[iService];
3319 talloc_free(serviceName);
3323 DEBUG(7,("lpcfg_servicenumber: couldn't find %s\n", service_name));
3327 const char *lpcfg_servicename(const struct loadparm_service *service)
3329 return service ? lpcfg_string((const char *)service->szService) : NULL;
3332 struct smb_iconv_handle *lpcfg_iconv_handle(struct loadparm_context *lp_ctx)
3334 if (lp_ctx == NULL) {
3335 return get_iconv_handle();
3337 return lp_ctx->iconv_handle;
3340 _PUBLIC_ void reload_charcnv(struct loadparm_context *lp_ctx)
3342 if (!lp_ctx->global) {
3346 lp_ctx->iconv_handle =
3347 reinit_iconv_handle(lp_ctx,
3348 lpcfg_dos_charset(lp_ctx),
3349 lpcfg_unix_charset(lp_ctx));
3350 if (lp_ctx->iconv_handle == NULL) {
3351 smb_panic("reinit_iconv_handle failed");
3355 _PUBLIC_ char *lpcfg_tls_keyfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
3357 return lpcfg_private_path(mem_ctx, lp_ctx, lpcfg__tls_keyfile(lp_ctx));
3360 _PUBLIC_ char *lpcfg_tls_certfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
3362 return lpcfg_private_path(mem_ctx, lp_ctx, lpcfg__tls_certfile(lp_ctx));
3365 _PUBLIC_ char *lpcfg_tls_cafile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
3367 return lpcfg_private_path(mem_ctx, lp_ctx, lpcfg__tls_cafile(lp_ctx));
3370 _PUBLIC_ char *lpcfg_tls_crlfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
3372 return lpcfg_private_path(mem_ctx, lp_ctx, lpcfg__tls_crlfile(lp_ctx));
3375 _PUBLIC_ char *lpcfg_tls_dhpfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
3377 return lpcfg_private_path(mem_ctx, lp_ctx, lpcfg__tls_dhpfile(lp_ctx));
3380 struct gensec_settings *lpcfg_gensec_settings(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
3382 struct gensec_settings *settings = talloc_zero(mem_ctx, struct gensec_settings);
3383 if (settings == NULL)
3385 SMB_ASSERT(lp_ctx != NULL);
3386 settings->lp_ctx = talloc_reference(settings, lp_ctx);
3387 settings->target_hostname = lpcfg_parm_string(lp_ctx, NULL, "gensec", "target_hostname");
3391 int lpcfg_server_role(struct loadparm_context *lp_ctx)
3393 int domain_master = lpcfg__domain_master(lp_ctx);
3395 return lp_find_server_role(lpcfg__server_role(lp_ctx),
3396 lpcfg__security(lp_ctx),
3397 lpcfg__domain_logons(lp_ctx),
3398 (domain_master == true) ||
3399 (domain_master == Auto));
3402 int lpcfg_security(struct loadparm_context *lp_ctx)
3404 return lp_find_security(lpcfg__server_role(lp_ctx),
3405 lpcfg__security(lp_ctx));
3408 int lpcfg_client_max_protocol(struct loadparm_context *lp_ctx)
3410 int client_max_protocol = lpcfg__client_max_protocol(lp_ctx);
3411 if (client_max_protocol == PROTOCOL_DEFAULT) {
3412 return PROTOCOL_LATEST;
3414 return client_max_protocol;
3417 int lpcfg_client_ipc_min_protocol(struct loadparm_context *lp_ctx)
3419 int client_ipc_min_protocol = lpcfg__client_ipc_min_protocol(lp_ctx);
3420 if (client_ipc_min_protocol == PROTOCOL_DEFAULT) {
3421 client_ipc_min_protocol = lpcfg_client_min_protocol(lp_ctx);
3423 if (client_ipc_min_protocol < PROTOCOL_NT1) {
3424 return PROTOCOL_NT1;
3426 return client_ipc_min_protocol;
3429 int lpcfg_client_ipc_max_protocol(struct loadparm_context *lp_ctx)
3431 int client_ipc_max_protocol = lpcfg__client_ipc_max_protocol(lp_ctx);
3432 if (client_ipc_max_protocol == PROTOCOL_DEFAULT) {
3433 return PROTOCOL_LATEST;
3435 if (client_ipc_max_protocol < PROTOCOL_NT1) {
3436 return PROTOCOL_NT1;
3438 return client_ipc_max_protocol;
3441 int lpcfg_client_ipc_signing(struct loadparm_context *lp_ctx)
3443 int client_ipc_signing = lpcfg__client_ipc_signing(lp_ctx);
3444 if (client_ipc_signing == SMB_SIGNING_DEFAULT) {
3445 return SMB_SIGNING_REQUIRED;
3447 return client_ipc_signing;
3450 enum credentials_use_kerberos lpcfg_client_use_kerberos(struct loadparm_context *lp_ctx)
3452 if (lpcfg_weak_crypto(lp_ctx) == SAMBA_WEAK_CRYPTO_DISALLOWED) {
3453 return CRED_USE_KERBEROS_REQUIRED;
3456 return lpcfg__client_use_kerberos(lp_ctx);
3459 bool lpcfg_server_signing_allowed(struct loadparm_context *lp_ctx, bool *mandatory)
3461 bool allowed = true;
3462 enum smb_signing_setting signing_setting = lpcfg_server_signing(lp_ctx);
3466 if (signing_setting == SMB_SIGNING_DEFAULT) {
3468 * If we are a domain controller, SMB signing is
3469 * really important, as it can prevent a number of
3470 * attacks on communications between us and the
3473 * However, it really sucks (no sendfile, CPU
3474 * overhead) performance-wise when used on a
3475 * file server, so disable it by default
3479 if (lpcfg_server_role(lp_ctx) >= ROLE_ACTIVE_DIRECTORY_DC) {
3480 signing_setting = SMB_SIGNING_REQUIRED;
3482 signing_setting = SMB_SIGNING_OFF;
3486 switch (signing_setting) {
3487 case SMB_SIGNING_REQUIRED:
3490 case SMB_SIGNING_DESIRED:
3491 case SMB_SIGNING_IF_REQUIRED:
3493 case SMB_SIGNING_OFF:
3496 case SMB_SIGNING_DEFAULT:
3497 case SMB_SIGNING_IPC_DEFAULT:
3498 smb_panic(__location__);
3505 int lpcfg_tdb_hash_size(struct loadparm_context *lp_ctx, const char *name)
3513 base = strrchr_m(name, '/');
3519 return lpcfg_parm_int(lp_ctx, NULL, "tdb_hashsize", base, 0);
3523 int lpcfg_tdb_flags(struct loadparm_context *lp_ctx, int tdb_flags)
3525 if (!lpcfg_use_mmap(lp_ctx)) {
3526 tdb_flags |= TDB_NOMMAP;
3532 * Do not allow LanMan auth if unless NTLMv1 is also allowed
3534 * This also ensures it is disabled if NTLM is totally disabled
3536 bool lpcfg_lanman_auth(struct loadparm_context *lp_ctx)
3538 enum ntlm_auth_level ntlm_auth_level = lpcfg_ntlm_auth(lp_ctx);
3540 if (ntlm_auth_level == NTLM_AUTH_ON) {
3541 return lpcfg__lanman_auth(lp_ctx);
3547 static char *lpcfg_noop_substitution_fn(
3548 TALLOC_CTX *mem_ctx,
3549 const struct loadparm_substitution *lp_sub,
3550 const char *raw_value,
3553 return talloc_strdup(mem_ctx, raw_value);
3556 static const struct loadparm_substitution global_noop_substitution = {
3557 .substituted_string_fn = lpcfg_noop_substitution_fn,
3560 const struct loadparm_substitution *lpcfg_noop_substitution(void)
3562 return &global_noop_substitution;
3565 char *lpcfg_substituted_string(TALLOC_CTX *mem_ctx,
3566 const struct loadparm_substitution *lp_sub,
3567 const char *raw_value)
3569 return lp_sub->substituted_string_fn(mem_ctx,
3572 lp_sub->private_data);
3576 * @brief Parse a string value of a given parameter to its integer enum value.
3578 * @param[in] param_name The parameter name (e.g. 'client smb encrypt')
3580 * @param[in] param_value The parameter value (e.g. 'required').
3582 * @return The integer value of the enum the param_value matches or INT32_MIN
3585 int32_t lpcfg_parse_enum_vals(const char *param_name,
3586 const char *param_value)
3588 struct parm_struct *parm = NULL;
3589 int32_t ret = INT32_MIN;
3592 parm = lpcfg_parm_struct(NULL, param_name);
3597 ok = lp_set_enum_parm(parm, param_value, &ret);