lib/param: Remove unused functions in lib/param/loadparm.c
[Samba.git] / lib / param / loadparm.c
blob90f420c0b1b8bf3c026609d13789fef63cdf4f46
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 "libds/common/roles.h"
73 #include "lib/util/samba_util.h"
74 #include "libcli/auth/ntlm_check.h"
75 #include "lib/crypto/gnutls_helpers.h"
76 #include "lib/util/smb_strtox.h"
78 #ifdef HAVE_HTTPCONNECTENCRYPT
79 #include <cups/http.h>
80 #endif
82 #define standard_sub_basic talloc_strdup
84 #include "lib/param/param_global.h"
86 struct loadparm_service *lpcfg_default_service(struct loadparm_context *lp_ctx)
88 return lp_ctx->sDefault;
91 int lpcfg_rpc_low_port(struct loadparm_context *lp_ctx)
93 return lp_ctx->globals->rpc_low_port;
96 int lpcfg_rpc_high_port(struct loadparm_context *lp_ctx)
98 return lp_ctx->globals->rpc_high_port;
101 enum samba_weak_crypto lpcfg_weak_crypto(struct loadparm_context *lp_ctx)
103 if (lp_ctx->globals->weak_crypto == SAMBA_WEAK_CRYPTO_UNKNOWN) {
104 lp_ctx->globals->weak_crypto = SAMBA_WEAK_CRYPTO_DISALLOWED;
106 if (samba_gnutls_weak_crypto_allowed()) {
107 lp_ctx->globals->weak_crypto = SAMBA_WEAK_CRYPTO_ALLOWED;
111 return lp_ctx->globals->weak_crypto;
115 * Convenience routine to grab string parameters into temporary memory
116 * and run standard_sub_basic on them.
118 * The buffers can be written to by
119 * callers without affecting the source string.
122 static const char *lpcfg_string(const char *s)
124 #if 0 /* until REWRITE done to make thread-safe */
125 size_t len = s ? strlen(s) : 0;
126 char *ret;
127 #endif
129 /* The follow debug is useful for tracking down memory problems
130 especially if you have an inner loop that is calling a lp_*()
131 function that returns a string. Perhaps this debug should be
132 present all the time? */
134 #if 0
135 DEBUG(10, ("lpcfg_string(%s)\n", s));
136 #endif
138 #if 0 /* until REWRITE done to make thread-safe */
139 if (!lp_talloc)
140 lp_talloc = talloc_init("lp_talloc");
142 ret = talloc_array(lp_talloc, char, len + 100); /* leave room for substitution */
144 if (!ret)
145 return NULL;
147 if (!s)
148 *ret = 0;
149 else
150 strlcpy(ret, s, len);
152 if (trim_string(ret, "\"", "\"")) {
153 if (strchr(ret,'"') != NULL)
154 strlcpy(ret, s, len);
157 standard_sub_basic(ret,len+100);
158 return (ret);
159 #endif
160 return s;
164 In this section all the functions that are used to access the
165 parameters from the rest of the program are defined
169 * the creation of separate lpcfg_*() and lp_*() functions is to allow
170 * for code compatibility between existing Samba4 and Samba3 code.
173 /* this global context supports the lp_*() function varients */
174 static struct loadparm_context *global_loadparm_context;
176 #define FN_GLOBAL_SUBSTITUTED_STRING(fn_name,var_name) \
177 _PUBLIC_ char *lpcfg_ ## fn_name(struct loadparm_context *lp_ctx, \
178 const struct loadparm_substitution *lp_sub, TALLOC_CTX *mem_ctx) \
180 if (lp_ctx == NULL) return NULL; \
181 return lpcfg_substituted_string(mem_ctx, lp_sub, \
182 lp_ctx->globals->var_name ? lp_ctx->globals->var_name : ""); \
185 #define FN_GLOBAL_CONST_STRING(fn_name,var_name) \
186 _PUBLIC_ const char *lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) { \
187 if (lp_ctx == NULL) return NULL; \
188 return lp_ctx->globals->var_name ? lpcfg_string(lp_ctx->globals->var_name) : ""; \
191 #define FN_GLOBAL_LIST(fn_name,var_name) \
192 _PUBLIC_ const char **lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) { \
193 if (lp_ctx == NULL) return NULL; \
194 return lp_ctx->globals->var_name; \
197 #define FN_GLOBAL_BOOL(fn_name,var_name) \
198 _PUBLIC_ bool lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) {\
199 if (lp_ctx == NULL) return false; \
200 return lp_ctx->globals->var_name; \
203 #define FN_GLOBAL_INTEGER(fn_name,var_name) \
204 _PUBLIC_ int lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) { \
205 return lp_ctx->globals->var_name; \
208 /* Local parameters don't need the ->s3_fns because the struct
209 * loadparm_service is shared and lpcfg_service() checks the ->s3_fns
210 * hook */
211 #define FN_LOCAL_SUBSTITUTED_STRING(fn_name,val) \
212 _PUBLIC_ char *lpcfg_ ## fn_name(struct loadparm_service *service, \
213 struct loadparm_service *sDefault, TALLOC_CTX *ctx) { \
214 return(talloc_strdup(ctx, lpcfg_string((const char *)((service != NULL && service->val != NULL) ? service->val : sDefault->val)))); \
217 #define FN_LOCAL_CONST_STRING(fn_name,val) \
218 _PUBLIC_ const char *lpcfg_ ## fn_name(struct loadparm_service *service, \
219 struct loadparm_service *sDefault) { \
220 return((const char *)((service != NULL && service->val != NULL) ? service->val : sDefault->val)); \
223 #define FN_LOCAL_LIST(fn_name,val) \
224 _PUBLIC_ const char **lpcfg_ ## fn_name(struct loadparm_service *service, \
225 struct loadparm_service *sDefault) {\
226 return(const char **)(service != NULL && service->val != NULL? service->val : sDefault->val); \
229 #define FN_LOCAL_PARM_BOOL(fn_name, val) FN_LOCAL_BOOL(fn_name, val)
231 #define FN_LOCAL_BOOL(fn_name,val) \
232 _PUBLIC_ bool lpcfg_ ## fn_name(struct loadparm_service *service, \
233 struct loadparm_service *sDefault) { \
234 return((service != NULL)? service->val : sDefault->val); \
237 #define FN_LOCAL_INTEGER(fn_name,val) \
238 _PUBLIC_ int lpcfg_ ## fn_name(struct loadparm_service *service, \
239 struct loadparm_service *sDefault) { \
240 return((service != NULL)? service->val : sDefault->val); \
243 #define FN_LOCAL_PARM_INTEGER(fn_name, val) FN_LOCAL_INTEGER(fn_name, val)
245 #define FN_LOCAL_CHAR(fn_name,val) \
246 _PUBLIC_ char lpcfg_ ## fn_name(struct loadparm_service *service, \
247 struct loadparm_service *sDefault) { \
248 return((service != NULL)? service->val : sDefault->val); \
251 #define FN_LOCAL_PARM_CHAR(fn_name,val) FN_LOCAL_CHAR(fn_name, val)
253 #include "lib/param/param_functions.c"
255 /* These functions cannot be auto-generated */
256 FN_LOCAL_BOOL(autoloaded, autoloaded)
257 FN_GLOBAL_CONST_STRING(dnsdomain, dnsdomain)
259 /* local prototypes */
260 static struct loadparm_service *lpcfg_getservicebyname(struct loadparm_context *lp_ctx,
261 const char *pszServiceName);
262 static bool do_section(const char *pszSectionName, void *);
263 static bool set_variable_helper(TALLOC_CTX *mem_ctx, int parmnum, void *parm_ptr,
264 const char *pszParmName, const char *pszParmValue);
265 static bool lp_do_parameter_parametric(struct loadparm_context *lp_ctx,
266 struct loadparm_service *service,
267 const char *pszParmName,
268 const char *pszParmValue, int flags);
270 /* The following are helper functions for parametrical options support. */
271 /* It returns a pointer to parametrical option value if it exists or NULL otherwise */
272 /* Actual parametrical functions are quite simple */
273 struct parmlist_entry *get_parametric_helper(struct loadparm_service *service,
274 const char *type, const char *option,
275 struct parmlist_entry *global_opts)
277 size_t type_len = strlen(type);
278 size_t option_len = strlen(option);
279 char param_key[type_len + option_len + 2];
280 struct parmlist_entry *data = NULL;
282 snprintf(param_key, sizeof(param_key), "%s:%s", type, option);
285 * Try to fetch the option from the data.
287 if (service != NULL) {
288 data = service->param_opt;
289 while (data != NULL) {
290 if (strwicmp(data->key, param_key) == 0) {
291 return data;
293 data = data->next;
298 * Fall back to fetching from the globals.
300 data = global_opts;
301 while (data != NULL) {
302 if (strwicmp(data->key, param_key) == 0) {
303 return data;
305 data = data->next;
308 return NULL;
311 const char *lpcfg_get_parametric(struct loadparm_context *lp_ctx,
312 struct loadparm_service *service,
313 const char *type, const char *option)
315 struct parmlist_entry *data;
317 if (lp_ctx == NULL)
318 return NULL;
320 data = get_parametric_helper(service,
321 type, option, lp_ctx->globals->param_opt);
323 if (data == NULL) {
324 return NULL;
325 } else {
326 return data->value;
332 * convenience routine to return int parameters.
334 int lp_int(const char *s)
337 if (!s || !*s) {
338 DEBUG(0,("lp_int(%s): is called with NULL!\n",s));
339 return -1;
342 return strtol(s, NULL, 0);
346 * convenience routine to return unsigned long parameters.
348 unsigned long lp_ulong(const char *s)
350 int error = 0;
351 unsigned long int ret;
353 if (!s || !*s) {
354 DBG_DEBUG("lp_ulong(%s): is called with NULL!\n",s);
355 return -1;
358 ret = smb_strtoul(s, NULL, 0, &error, SMB_STR_STANDARD);
359 if (error != 0) {
360 DBG_DEBUG("lp_ulong(%s): conversion failed\n",s);
361 return -1;
364 return ret;
368 * convenience routine to return unsigned long long parameters.
370 unsigned long long lp_ulonglong(const char *s)
372 int error = 0;
373 unsigned long long int ret;
375 if (!s || !*s) {
376 DBG_DEBUG("lp_ulonglong(%s): is called with NULL!\n", s);
377 return -1;
380 ret = smb_strtoull(s, NULL, 0, &error, SMB_STR_STANDARD);
381 if (error != 0) {
382 DBG_DEBUG("lp_ulonglong(%s): conversion failed\n",s);
383 return -1;
386 return ret;
390 * convenience routine to return unsigned long parameters.
392 static long lp_long(const char *s)
395 if (!s) {
396 DEBUG(0,("lp_long(%s): is called with NULL!\n",s));
397 return -1;
400 return strtol(s, NULL, 0);
404 * convenience routine to return unsigned long parameters.
406 static double lp_double(const char *s)
409 if (!s) {
410 DEBUG(0,("lp_double(%s): is called with NULL!\n",s));
411 return -1;
414 return strtod(s, NULL);
418 * convenience routine to return boolean parameters.
420 bool lp_bool(const char *s)
422 bool ret = false;
424 if (!s || !*s) {
425 DEBUG(0,("lp_bool(%s): is called with NULL!\n",s));
426 return false;
429 if (!set_boolean(s, &ret)) {
430 DEBUG(0,("lp_bool(%s): value is not boolean!\n",s));
431 return false;
434 return ret;
438 * Return parametric option from a given service. Type is a part of option before ':'
439 * Parametric option has following syntax: 'Type: option = value'
440 * Returned value is allocated in 'lp_talloc' context
443 const char *lpcfg_parm_string(struct loadparm_context *lp_ctx,
444 struct loadparm_service *service, const char *type,
445 const char *option)
447 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
449 if (value)
450 return lpcfg_string(value);
452 return NULL;
456 * Return parametric option from a given service. Type is a part of option before ':'
457 * Parametric option has following syntax: 'Type: option = value'
458 * Returned value is allocated in 'lp_talloc' context
461 const char **lpcfg_parm_string_list(TALLOC_CTX *mem_ctx,
462 struct loadparm_context *lp_ctx,
463 struct loadparm_service *service,
464 const char *type,
465 const char *option, const char *separator)
467 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
469 if (value != NULL) {
470 char **l = str_list_make(mem_ctx, value, separator);
471 return discard_const_p(const char *, l);
474 return NULL;
478 * Return parametric option from a given service. Type is a part of option before ':'
479 * Parametric option has following syntax: 'Type: option = value'
482 int lpcfg_parm_int(struct loadparm_context *lp_ctx,
483 struct loadparm_service *service, const char *type,
484 const char *option, int default_v)
486 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
488 if (value)
489 return lp_int(value);
491 return default_v;
495 * Return parametric option from a given service. Type is a part of
496 * option before ':'.
497 * Parametric option has following syntax: 'Type: option = value'.
500 int lpcfg_parm_bytes(struct loadparm_context *lp_ctx,
501 struct loadparm_service *service, const char *type,
502 const char *option, int default_v)
504 uint64_t bval;
506 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
508 if (value && conv_str_size_error(value, &bval)) {
509 if (bval <= INT_MAX) {
510 return (int)bval;
514 return default_v;
518 * Return parametric option from a given service.
519 * Type is a part of option before ':'
520 * Parametric option has following syntax: 'Type: option = value'
522 unsigned long lpcfg_parm_ulong(struct loadparm_context *lp_ctx,
523 struct loadparm_service *service, const char *type,
524 const char *option, unsigned long default_v)
526 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
528 if (value)
529 return lp_ulong(value);
531 return default_v;
535 * Return parametric option from a given service.
536 * Type is a part of option before ':'
537 * Parametric option has following syntax: 'Type: option = value'
539 unsigned long long lpcfg_parm_ulonglong(struct loadparm_context *lp_ctx,
540 struct loadparm_service *service,
541 const char *type, const char *option,
542 unsigned long long default_v)
544 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
546 if (value) {
547 return lp_ulonglong(value);
550 return default_v;
553 long lpcfg_parm_long(struct loadparm_context *lp_ctx,
554 struct loadparm_service *service, const char *type,
555 const char *option, long default_v)
557 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
559 if (value)
560 return lp_long(value);
562 return default_v;
565 double lpcfg_parm_double(struct loadparm_context *lp_ctx,
566 struct loadparm_service *service, const char *type,
567 const char *option, double default_v)
569 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
571 if (value != NULL)
572 return lp_double(value);
574 return default_v;
578 * Return parametric option from a given service. Type is a part of option before ':'
579 * Parametric option has following syntax: 'Type: option = value'
582 bool lpcfg_parm_bool(struct loadparm_context *lp_ctx,
583 struct loadparm_service *service, const char *type,
584 const char *option, bool default_v)
586 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
588 if (value != NULL)
589 return lp_bool(value);
591 return default_v;
595 /* this is used to prevent lots of mallocs of size 1 */
596 static const char lpcfg_string_empty[] = "";
599 Free a string value.
601 void lpcfg_string_free(char **s)
603 if (s == NULL) {
604 return;
606 if (*s == lpcfg_string_empty) {
607 *s = NULL;
608 return;
610 TALLOC_FREE(*s);
614 * Set a string value, deallocating any existing space, and allocing the space
615 * for the string
617 bool lpcfg_string_set(TALLOC_CTX *mem_ctx, char **dest, const char *src)
619 lpcfg_string_free(dest);
621 if ((src == NULL) || (*src == '\0')) {
622 *dest = discard_const_p(char, lpcfg_string_empty);
623 return true;
626 *dest = talloc_strdup(mem_ctx, src);
627 if ((*dest) == NULL) {
628 DEBUG(0,("Out of memory in string_set\n"));
629 return false;
632 return true;
636 * Set a string value, deallocating any existing space, and allocing the space
637 * for the string
639 bool lpcfg_string_set_upper(TALLOC_CTX *mem_ctx, char **dest, const char *src)
641 lpcfg_string_free(dest);
643 if ((src == NULL) || (*src == '\0')) {
644 *dest = discard_const_p(char, lpcfg_string_empty);
645 return true;
648 *dest = strupper_talloc(mem_ctx, src);
649 if ((*dest) == NULL) {
650 DEBUG(0,("Out of memory in string_set_upper\n"));
651 return false;
654 return true;
660 * Add a new service to the services array initialising it with the given
661 * service.
664 struct loadparm_service *lpcfg_add_service(struct loadparm_context *lp_ctx,
665 const struct loadparm_service *pservice,
666 const char *name)
668 int i;
669 int num_to_alloc = lp_ctx->iNumServices + 1;
670 struct parmlist_entry *data, *pdata;
672 if (lp_ctx->s3_fns != NULL) {
673 smb_panic("Add a service should not be called on an s3 loadparm ctx");
676 if (pservice == NULL) {
677 pservice = lp_ctx->sDefault;
680 /* it might already exist */
681 if (name) {
682 struct loadparm_service *service = lpcfg_getservicebyname(lp_ctx,
683 name);
684 if (service != NULL) {
685 /* Clean all parametric options for service */
686 /* They will be added during parsing again */
687 data = service->param_opt;
688 while (data) {
689 pdata = data->next;
690 talloc_free(data);
691 data = pdata;
693 service->param_opt = NULL;
694 return service;
698 /* find an invalid one */
699 for (i = 0; i < lp_ctx->iNumServices; i++)
700 if (lp_ctx->services[i] == NULL)
701 break;
703 /* if not, then create one */
704 if (i == lp_ctx->iNumServices) {
705 struct loadparm_service **tsp;
707 tsp = talloc_realloc(lp_ctx, lp_ctx->services, struct loadparm_service *, num_to_alloc);
709 if (!tsp) {
710 DEBUG(0,("lpcfg_add_service: failed to enlarge services!\n"));
711 return NULL;
712 } else {
713 lp_ctx->services = tsp;
714 lp_ctx->services[lp_ctx->iNumServices] = NULL;
717 lp_ctx->iNumServices++;
720 lp_ctx->services[i] = talloc_zero(lp_ctx->services, struct loadparm_service);
721 if (lp_ctx->services[i] == NULL) {
722 DEBUG(0,("lpcfg_add_service: out of memory!\n"));
723 return NULL;
725 copy_service(lp_ctx->services[i], pservice, NULL);
726 if (name != NULL)
727 lpcfg_string_set(lp_ctx->services[i], &lp_ctx->services[i]->szService, name);
728 return lp_ctx->services[i];
732 * Map a parameter's string representation to something we can use.
733 * Returns False if the parameter string is not recognised, else TRUE.
736 int lpcfg_map_parameter(const char *pszParmName)
738 int iIndex;
740 for (iIndex = 0; parm_table[iIndex].label; iIndex++)
741 if (strwicmp(parm_table[iIndex].label, pszParmName) == 0)
742 return iIndex;
744 /* Warn only if it isn't parametric option */
745 if (strchr(pszParmName, ':') == NULL)
746 DEBUG(0, ("Unknown parameter encountered: \"%s\"\n", pszParmName));
747 /* We do return 'fail' for parametric options as well because they are
748 stored in different storage
750 return -1;
755 return the parameter structure for a parameter
757 struct parm_struct *lpcfg_parm_struct(struct loadparm_context *lp_ctx, const char *name)
759 int num = lpcfg_map_parameter(name);
761 if (num < 0) {
762 return NULL;
765 return &parm_table[num];
769 return the parameter pointer for a parameter
771 void *lpcfg_parm_ptr(struct loadparm_context *lp_ctx,
772 struct loadparm_service *service, struct parm_struct *parm)
774 if (lp_ctx->s3_fns) {
775 return lp_ctx->s3_fns->get_parm_ptr(service, parm);
778 if (service == NULL) {
779 if (parm->p_class == P_LOCAL)
780 return ((char *)lp_ctx->sDefault)+parm->offset;
781 else if (parm->p_class == P_GLOBAL)
782 return ((char *)lp_ctx->globals)+parm->offset;
783 else return NULL;
784 } else {
785 return ((char *)service) + parm->offset;
790 return the parameter pointer for a parameter
792 bool lpcfg_parm_is_cmdline(struct loadparm_context *lp_ctx, const char *name)
794 int parmnum;
796 parmnum = lpcfg_map_parameter(name);
797 if (parmnum == -1) return false;
799 return lp_ctx->flags[parmnum] & FLAG_CMDLINE;
803 * Find a service by name. Otherwise works like get_service.
806 static struct loadparm_service *lpcfg_getservicebyname(struct loadparm_context *lp_ctx,
807 const char *pszServiceName)
809 int iService;
811 if (lp_ctx->s3_fns) {
812 return lp_ctx->s3_fns->get_service(pszServiceName);
815 for (iService = lp_ctx->iNumServices - 1; iService >= 0; iService--)
816 if (lp_ctx->services[iService] != NULL &&
817 strwicmp(lp_ctx->services[iService]->szService, pszServiceName) == 0) {
818 return lp_ctx->services[iService];
821 return NULL;
825 * Add a parametric option to a parmlist_entry,
826 * replacing old value, if already present.
828 void set_param_opt(TALLOC_CTX *mem_ctx,
829 struct parmlist_entry **opt_list,
830 const char *opt_name,
831 const char *opt_value,
832 unsigned priority)
834 struct parmlist_entry *new_opt, *opt;
836 opt = *opt_list;
838 /* Traverse destination */
839 while (opt) {
840 /* If we already have same option, override it */
841 if (strwicmp(opt->key, opt_name) == 0) {
842 if ((opt->priority & FLAG_CMDLINE) &&
843 !(priority & FLAG_CMDLINE)) {
844 /* it's been marked as not to be
845 overridden */
846 return;
848 TALLOC_FREE(opt->list);
849 lpcfg_string_set(opt, &opt->value, opt_value);
850 opt->priority = priority;
851 return;
853 opt = opt->next;
856 new_opt = talloc_pooled_object(
857 mem_ctx, struct parmlist_entry,
858 2, strlen(opt_name) + 1 + strlen(opt_value) + 1);
859 if (new_opt == NULL) {
860 smb_panic("OOM");
862 new_opt->key = NULL;
863 lpcfg_string_set(new_opt, &new_opt->key, opt_name);
864 new_opt->value = NULL;
865 lpcfg_string_set(new_opt, &new_opt->value, opt_value);
867 new_opt->list = NULL;
868 new_opt->priority = priority;
869 DLIST_ADD(*opt_list, new_opt);
873 * Copy a service structure to another.
874 * If pcopymapDest is NULL then copy all fields
877 void copy_service(struct loadparm_service *pserviceDest,
878 const struct loadparm_service *pserviceSource,
879 struct bitmap *pcopymapDest)
881 int i;
882 bool bcopyall = (pcopymapDest == NULL);
883 struct parmlist_entry *data;
885 for (i = 0; parm_table[i].label; i++)
886 if (parm_table[i].p_class == P_LOCAL &&
887 (bcopyall || bitmap_query(pcopymapDest, i))) {
888 const void *src_ptr =
889 ((const char *)pserviceSource) + parm_table[i].offset;
890 void *dest_ptr =
891 ((char *)pserviceDest) + parm_table[i].offset;
893 switch (parm_table[i].type) {
894 case P_BOOL:
895 case P_BOOLREV:
896 *(bool *)dest_ptr = *(const bool *)src_ptr;
897 break;
899 case P_INTEGER:
900 case P_BYTES:
901 case P_OCTAL:
902 case P_ENUM:
903 *(int *)dest_ptr = *(const int *)src_ptr;
904 break;
906 case P_CHAR:
907 *(char *)dest_ptr = *(const char *)src_ptr;
908 break;
910 case P_STRING:
911 lpcfg_string_set(pserviceDest,
912 (char **)dest_ptr,
913 *(const char * const *)src_ptr);
914 break;
916 case P_USTRING:
917 lpcfg_string_set_upper(pserviceDest,
918 (char **)dest_ptr,
919 *(const char * const *)src_ptr);
920 break;
921 case P_CMDLIST:
922 case P_LIST:
923 TALLOC_FREE(*((char ***)dest_ptr));
924 *(char ***)dest_ptr = str_list_copy(pserviceDest,
925 *discard_const_p(const char **, src_ptr));
926 break;
927 default:
928 break;
932 if (bcopyall) {
933 init_copymap(pserviceDest);
934 if (pserviceSource->copymap)
935 bitmap_copy(pserviceDest->copymap,
936 pserviceSource->copymap);
939 for (data = pserviceSource->param_opt; data != NULL; data = data->next) {
940 set_param_opt(pserviceDest, &pserviceDest->param_opt,
941 data->key, data->value, data->priority);
946 * Check a service for consistency. Return False if the service is in any way
947 * incomplete or faulty, else True.
949 bool lpcfg_service_ok(struct loadparm_service *service)
951 bool bRetval;
953 bRetval = true;
954 if (service->szService[0] == '\0') {
955 DEBUG(0, ("The following message indicates an internal error:\n"));
956 DEBUG(0, ("No service name in service entry.\n"));
957 bRetval = false;
960 /* The [printers] entry MUST be printable. I'm all for flexibility, but */
961 /* I can't see why you'd want a non-printable printer service... */
962 if (strwicmp(service->szService, PRINTERS_NAME) == 0) {
963 if (!service->printable) {
964 DEBUG(0, ("WARNING: [%s] service MUST be printable!\n",
965 service->szService));
966 service->printable = true;
968 /* [printers] service must also be non-browsable. */
969 if (service->browseable)
970 service->browseable = false;
973 if (service->path[0] == '\0' &&
974 strwicmp(service->szService, HOMES_NAME) != 0 &&
975 service->msdfs_proxy[0] == '\0')
977 DEBUG(0, ("WARNING: No path in service %s - making it unavailable!\n",
978 service->szService));
979 service->available = false;
982 if (!service->available)
983 DEBUG(1, ("NOTE: Service %s is flagged unavailable.\n",
984 service->szService));
986 return bRetval;
990 /*******************************************************************
991 Keep a linked list of all config files so we know when one has changed
992 it's date and needs to be reloaded.
993 ********************************************************************/
995 void add_to_file_list(TALLOC_CTX *mem_ctx, struct file_lists **list,
996 const char *fname, const char *subfname)
998 struct file_lists *f = *list;
1000 while (f) {
1001 if (f->name && !strcmp(f->name, fname))
1002 break;
1003 f = f->next;
1006 if (!f) {
1007 f = talloc(mem_ctx, struct file_lists);
1008 if (!f)
1009 goto fail;
1010 f->next = *list;
1011 f->name = talloc_strdup(f, fname);
1012 if (!f->name) {
1013 TALLOC_FREE(f);
1014 goto fail;
1016 f->subfname = talloc_strdup(f, subfname);
1017 if (!f->subfname) {
1018 TALLOC_FREE(f);
1019 goto fail;
1021 *list = f;
1022 f->modtime = file_modtime(subfname);
1023 } else {
1024 time_t t = file_modtime(subfname);
1025 if (t)
1026 f->modtime = t;
1028 return;
1030 fail:
1031 DEBUG(0, ("Unable to add file to file list: %s\n", fname));
1036 * set the value for a P_ENUM
1038 bool lp_set_enum_parm( struct parm_struct *parm, const char *pszParmValue,
1039 int *ptr )
1041 int i;
1043 for (i = 0; parm->enum_list[i].name; i++) {
1044 if (strwicmp(pszParmValue, parm->enum_list[i].name) == 0) {
1045 *ptr = parm->enum_list[i].value;
1046 return true;
1049 DEBUG(0, ("WARNING: Ignoring invalid value '%s' for parameter '%s'\n",
1050 pszParmValue, parm->label));
1051 return false;
1055 /***************************************************************************
1056 Handle the "realm" parameter
1057 ***************************************************************************/
1059 bool handle_realm(struct loadparm_context *lp_ctx, struct loadparm_service *service,
1060 const char *pszParmValue, char **ptr)
1062 char *upper;
1063 char *lower;
1065 upper = strupper_talloc(lp_ctx, pszParmValue);
1066 if (upper == NULL) {
1067 return false;
1070 lower = strlower_talloc(lp_ctx, pszParmValue);
1071 if (lower == NULL) {
1072 TALLOC_FREE(upper);
1073 return false;
1076 lpcfg_string_set(lp_ctx->globals->ctx, &lp_ctx->globals->realm, upper);
1077 lpcfg_string_set(lp_ctx->globals->ctx, &lp_ctx->globals->dnsdomain, lower);
1079 return true;
1082 /***************************************************************************
1083 Handle the include operation.
1084 ***************************************************************************/
1086 bool handle_include(struct loadparm_context *lp_ctx, struct loadparm_service *service,
1087 const char *pszParmValue, char **ptr)
1089 char *fname;
1090 const char *substitution_variable_substring;
1091 char next_char;
1093 if (lp_ctx->s3_fns) {
1094 return lp_ctx->s3_fns->lp_include(lp_ctx, service, pszParmValue, ptr);
1097 fname = standard_sub_basic(lp_ctx, pszParmValue);
1099 add_to_file_list(lp_ctx, &lp_ctx->file_lists, pszParmValue, fname);
1101 lpcfg_string_set(lp_ctx, ptr, fname);
1103 if (file_exist(fname))
1104 return pm_process(fname, do_section, lpcfg_do_parameter, lp_ctx);
1107 * If the file doesn't exist, we check that it isn't due to variable
1108 * substitution
1110 substitution_variable_substring = strchr(fname, '%');
1112 if (substitution_variable_substring != NULL) {
1113 next_char = substitution_variable_substring[1];
1114 if ((next_char >= 'a' && next_char <= 'z')
1115 || (next_char >= 'A' && next_char <= 'Z')) {
1116 DEBUG(2, ("Tried to load %s but variable substitution in "
1117 "filename, ignoring file.\n", fname));
1118 return true;
1122 DEBUG(2, ("Can't find include file %s\n", fname));
1124 return false;
1127 /***************************************************************************
1128 Handle the interpretation of the copy parameter.
1129 ***************************************************************************/
1131 bool handle_copy(struct loadparm_context *lp_ctx, struct loadparm_service *service,
1132 const char *pszParmValue, char **ptr)
1134 bool bRetval;
1135 struct loadparm_service *serviceTemp = NULL;
1137 bRetval = false;
1139 DEBUG(3, ("Copying service from service %s\n", pszParmValue));
1141 serviceTemp = lpcfg_getservicebyname(lp_ctx, pszParmValue);
1143 if (service == NULL) {
1144 DEBUG(0, ("Unable to copy service - invalid service destination.\n"));
1145 return false;
1148 if (serviceTemp != NULL) {
1149 if (serviceTemp == service) {
1150 DEBUG(0, ("Can't copy service %s - unable to copy self!\n", pszParmValue));
1151 } else {
1152 copy_service(service,
1153 serviceTemp,
1154 service->copymap);
1155 lpcfg_string_set(service, ptr, pszParmValue);
1157 bRetval = true;
1159 } else {
1160 DEBUG(0, ("Unable to copy service - source not found: %s\n",
1161 pszParmValue));
1162 bRetval = false;
1165 return bRetval;
1168 bool handle_debug_list(struct loadparm_context *lp_ctx, struct loadparm_service *service,
1169 const char *pszParmValue, char **ptr)
1171 lpcfg_string_set(lp_ctx->globals->ctx, ptr, pszParmValue);
1173 return debug_parse_levels(pszParmValue);
1176 bool handle_logfile(struct loadparm_context *lp_ctx, struct loadparm_service *service,
1177 const char *pszParmValue, char **ptr)
1179 if (lp_ctx->s3_fns == NULL) {
1180 debug_set_logfile(pszParmValue);
1183 lpcfg_string_set(lp_ctx->globals->ctx, ptr, pszParmValue);
1185 return true;
1189 * These special charset handling methods only run in the source3 code.
1192 bool handle_charset(struct loadparm_context *lp_ctx, struct loadparm_service *service,
1193 const char *pszParmValue, char **ptr)
1195 if (lp_ctx->s3_fns) {
1196 if (*ptr == NULL || strcmp(*ptr, pszParmValue) != 0) {
1197 struct smb_iconv_handle *ret = NULL;
1199 ret = reinit_iconv_handle(NULL,
1200 lpcfg_dos_charset(lp_ctx),
1201 lpcfg_unix_charset(lp_ctx));
1202 if (ret == NULL) {
1203 smb_panic("reinit_iconv_handle failed");
1208 return lpcfg_string_set(lp_ctx->globals->ctx, ptr, pszParmValue);
1212 bool handle_dos_charset(struct loadparm_context *lp_ctx, struct loadparm_service *service,
1213 const char *pszParmValue, char **ptr)
1215 bool is_utf8 = false;
1216 size_t len = strlen(pszParmValue);
1218 if (lp_ctx->s3_fns) {
1219 if (len == 4 || len == 5) {
1220 /* Don't use StrCaseCmp here as we don't want to
1221 initialize iconv. */
1222 if ((toupper_m(pszParmValue[0]) == 'U') &&
1223 (toupper_m(pszParmValue[1]) == 'T') &&
1224 (toupper_m(pszParmValue[2]) == 'F')) {
1225 if (len == 4) {
1226 if (pszParmValue[3] == '8') {
1227 is_utf8 = true;
1229 } else {
1230 if (pszParmValue[3] == '-' &&
1231 pszParmValue[4] == '8') {
1232 is_utf8 = true;
1238 if (*ptr == NULL || strcmp(*ptr, pszParmValue) != 0) {
1239 struct smb_iconv_handle *ret = NULL;
1240 if (is_utf8) {
1241 DEBUG(0,("ERROR: invalid DOS charset: 'dos charset' must not "
1242 "be UTF8, using (default value) %s instead.\n",
1243 DEFAULT_DOS_CHARSET));
1244 pszParmValue = DEFAULT_DOS_CHARSET;
1246 ret = reinit_iconv_handle(NULL,
1247 lpcfg_dos_charset(lp_ctx),
1248 lpcfg_unix_charset(lp_ctx));
1249 if (ret == NULL) {
1250 smb_panic("reinit_iconv_handle failed");
1255 return lpcfg_string_set(lp_ctx->globals->ctx, ptr, pszParmValue);
1258 bool handle_printing(struct loadparm_context *lp_ctx, struct loadparm_service *service,
1259 const char *pszParmValue, char **ptr)
1261 static int parm_num = -1;
1263 if (parm_num == -1) {
1264 parm_num = lpcfg_map_parameter("printing");
1267 if (!lp_set_enum_parm(&parm_table[parm_num], pszParmValue, (int*)ptr)) {
1268 return false;
1271 if (lp_ctx->s3_fns) {
1272 if (service == NULL) {
1273 init_printer_values(lp_ctx, lp_ctx->globals->ctx, lp_ctx->sDefault);
1274 } else {
1275 init_printer_values(lp_ctx, service, service);
1279 return true;
1282 bool handle_ldap_debug_level(struct loadparm_context *lp_ctx, struct loadparm_service *service,
1283 const char *pszParmValue, char **ptr)
1285 lp_ctx->globals->ldap_debug_level = lp_int(pszParmValue);
1287 if (lp_ctx->s3_fns) {
1288 lp_ctx->s3_fns->init_ldap_debugging();
1290 return true;
1293 bool handle_netbios_aliases(struct loadparm_context *lp_ctx, struct loadparm_service *service,
1294 const char *pszParmValue, char **ptr)
1296 TALLOC_FREE(lp_ctx->globals->netbios_aliases);
1297 lp_ctx->globals->netbios_aliases = str_list_make_v3_const(lp_ctx->globals->ctx,
1298 pszParmValue, NULL);
1300 if (lp_ctx->s3_fns) {
1301 return lp_ctx->s3_fns->set_netbios_aliases(lp_ctx->globals->netbios_aliases);
1303 return true;
1307 * idmap related parameters
1310 bool handle_idmap_backend(struct loadparm_context *lp_ctx, struct loadparm_service *service,
1311 const char *pszParmValue, char **ptr)
1313 if (lp_ctx->s3_fns) {
1314 lp_do_parameter_parametric(lp_ctx, service, "idmap config * : backend",
1315 pszParmValue, 0);
1318 return lpcfg_string_set(lp_ctx->globals->ctx, ptr, pszParmValue);
1321 bool handle_idmap_uid(struct loadparm_context *lp_ctx, struct loadparm_service *service,
1322 const char *pszParmValue, char **ptr)
1324 if (lp_ctx->s3_fns) {
1325 lp_do_parameter_parametric(lp_ctx, service, "idmap config * : range",
1326 pszParmValue, 0);
1329 return lpcfg_string_set(lp_ctx->globals->ctx, ptr, pszParmValue);
1332 bool handle_idmap_gid(struct loadparm_context *lp_ctx, struct loadparm_service *service,
1333 const char *pszParmValue, char **ptr)
1335 if (lp_ctx->s3_fns) {
1336 lp_do_parameter_parametric(lp_ctx, service, "idmap config * : range",
1337 pszParmValue, 0);
1340 return lpcfg_string_set(lp_ctx->globals->ctx, ptr, pszParmValue);
1343 bool handle_smb_ports(struct loadparm_context *lp_ctx, struct loadparm_service *service,
1344 const char *pszParmValue, char **ptr)
1346 static int parm_num = -1;
1347 int i;
1348 const char **list;
1350 if (!pszParmValue || !*pszParmValue) {
1351 return false;
1354 if (parm_num == -1) {
1355 parm_num = lpcfg_map_parameter("smb ports");
1356 if (parm_num == -1) {
1357 return false;
1361 if (!set_variable_helper(lp_ctx->globals->ctx, parm_num, ptr, "smb ports",
1362 pszParmValue)) {
1363 return false;
1366 list = lp_ctx->globals->smb_ports;
1367 if (list == NULL) {
1368 return false;
1371 /* Check that each port is a valid integer and within range */
1372 for (i = 0; list[i] != NULL; i++) {
1373 char *end = NULL;
1374 int port = 0;
1375 port = strtol(list[i], &end, 10);
1376 if (*end != '\0' || port <= 0 || port > 65535) {
1377 TALLOC_FREE(list);
1378 return false;
1382 return true;
1385 bool handle_rpc_server_dynamic_port_range(struct loadparm_context *lp_ctx,
1386 struct loadparm_service *service,
1387 const char *pszParmValue,
1388 char **ptr)
1390 static int parm_num = -1;
1391 int low_port = -1, high_port = -1;
1392 int rc;
1394 if (parm_num == -1) {
1395 parm_num = lpcfg_map_parameter("rpc server dynamic port range");
1396 if (parm_num == -1) {
1397 return false;
1401 if (pszParmValue == NULL || pszParmValue[0] == '\0') {
1402 return false;
1405 rc = sscanf(pszParmValue, "%d - %d", &low_port, &high_port);
1406 if (rc != 2) {
1407 return false;
1410 if (low_port > high_port) {
1411 return false;
1414 if (low_port < SERVER_TCP_PORT_MIN|| high_port > SERVER_TCP_PORT_MAX) {
1415 return false;
1418 if (!set_variable_helper(lp_ctx->globals->ctx, parm_num, ptr,
1419 "rpc server dynamic port range",
1420 pszParmValue)) {
1421 return false;
1424 lp_ctx->globals->rpc_low_port = low_port;
1425 lp_ctx->globals->rpc_high_port = high_port;
1427 return true;
1430 bool handle_smb2_max_credits(struct loadparm_context *lp_ctx,
1431 struct loadparm_service *service,
1432 const char *pszParmValue, char **ptr)
1434 int value = lp_int(pszParmValue);
1436 if (value <= 0) {
1437 value = DEFAULT_SMB2_MAX_CREDITS;
1440 *(int *)ptr = value;
1442 return true;
1445 bool handle_cups_encrypt(struct loadparm_context *lp_ctx,
1446 struct loadparm_service *service,
1447 const char *pszParmValue, char **ptr)
1449 int result = 0;
1450 #ifdef HAVE_HTTPCONNECTENCRYPT
1451 int value = lp_int(pszParmValue);
1453 switch (value) {
1454 case Auto:
1455 result = HTTP_ENCRYPT_REQUIRED;
1456 break;
1457 case true:
1458 result = HTTP_ENCRYPT_ALWAYS;
1459 break;
1460 case false:
1461 result = HTTP_ENCRYPT_NEVER;
1462 break;
1463 default:
1464 result = 0;
1465 break;
1467 #endif
1468 *(int *)ptr = result;
1470 return true;
1473 /***************************************************************************
1474 Initialise a copymap.
1475 ***************************************************************************/
1478 * Initializes service copymap
1479 * Note: pservice *must* be valid TALLOC_CTX
1481 void init_copymap(struct loadparm_service *pservice)
1483 int i;
1485 TALLOC_FREE(pservice->copymap);
1487 pservice->copymap = bitmap_talloc(pservice, num_parameters());
1488 if (!pservice->copymap) {
1489 DEBUG(0,
1490 ("Couldn't allocate copymap!! (size %d)\n",
1491 (int)num_parameters()));
1492 } else {
1493 for (i = 0; i < num_parameters(); i++) {
1494 bitmap_set(pservice->copymap, i);
1500 * Process a parametric option
1502 static bool lp_do_parameter_parametric(struct loadparm_context *lp_ctx,
1503 struct loadparm_service *service,
1504 const char *pszParmName,
1505 const char *pszParmValue, int flags)
1507 struct parmlist_entry **data;
1508 char *name;
1509 TALLOC_CTX *mem_ctx;
1511 while (isspace((unsigned char)*pszParmName)) {
1512 pszParmName++;
1515 name = strlower_talloc(lp_ctx, pszParmName);
1516 if (!name) return false;
1518 if (service == NULL) {
1519 data = &lp_ctx->globals->param_opt;
1521 * s3 code cannot deal with parametric options stored on the globals ctx.
1523 if (lp_ctx->s3_fns != NULL) {
1524 mem_ctx = NULL;
1525 } else {
1526 mem_ctx = lp_ctx->globals->ctx;
1528 } else {
1529 data = &service->param_opt;
1530 mem_ctx = service;
1533 set_param_opt(mem_ctx, data, name, pszParmValue, flags);
1535 talloc_free(name);
1537 return true;
1540 static bool set_variable_helper(TALLOC_CTX *mem_ctx, int parmnum, void *parm_ptr,
1541 const char *pszParmName, const char *pszParmValue)
1543 size_t i;
1545 /* switch on the type of variable it is */
1546 switch (parm_table[parmnum].type)
1548 case P_BOOL: {
1549 bool b;
1550 if (!set_boolean(pszParmValue, &b)) {
1551 DEBUG(0, ("set_variable_helper(%s): value is not "
1552 "boolean!\n", pszParmValue));
1553 return false;
1555 *(bool *)parm_ptr = b;
1557 break;
1559 case P_BOOLREV: {
1560 bool b;
1561 if (!set_boolean(pszParmValue, &b)) {
1562 DEBUG(0, ("set_variable_helper(%s): value is not "
1563 "boolean!\n", pszParmValue));
1564 return false;
1566 *(bool *)parm_ptr = !b;
1568 break;
1570 case P_INTEGER:
1571 *(int *)parm_ptr = lp_int(pszParmValue);
1572 break;
1574 case P_CHAR:
1575 *(char *)parm_ptr = *pszParmValue;
1576 break;
1578 case P_OCTAL:
1579 i = sscanf(pszParmValue, "%o", (int *)parm_ptr);
1580 if ( i != 1 ) {
1581 DEBUG ( 0, ("Invalid octal number %s\n", pszParmName ));
1582 return false;
1584 break;
1586 case P_BYTES:
1588 uint64_t val;
1589 if (conv_str_size_error(pszParmValue, &val)) {
1590 if (val <= INT_MAX) {
1591 *(int *)parm_ptr = (int)val;
1592 break;
1596 DEBUG(0, ("set_variable_helper(%s): value is not "
1597 "a valid size specifier!\n", pszParmValue));
1598 return false;
1601 case P_CMDLIST:
1602 TALLOC_FREE(*(char ***)parm_ptr);
1603 *(char ***)parm_ptr = str_list_make_v3(mem_ctx,
1604 pszParmValue, NULL);
1605 break;
1607 case P_LIST:
1609 char **new_list = str_list_make_v3(mem_ctx,
1610 pszParmValue, NULL);
1611 if (new_list == NULL) {
1612 break;
1615 for (i=0; new_list[i]; i++) {
1616 if (*(const char ***)parm_ptr != NULL &&
1617 new_list[i][0] == '+' &&
1618 new_list[i][1])
1620 if (!str_list_check(*(const char ***)parm_ptr,
1621 &new_list[i][1])) {
1622 *(const char ***)parm_ptr = str_list_add(*(const char ***)parm_ptr,
1623 &new_list[i][1]);
1625 } else if (*(const char ***)parm_ptr != NULL &&
1626 new_list[i][0] == '-' &&
1627 new_list[i][1])
1629 str_list_remove(*(const char ***)parm_ptr,
1630 &new_list[i][1]);
1631 } else {
1632 if (i != 0) {
1633 DEBUG(0, ("Unsupported list syntax for: %s = %s\n",
1634 pszParmName, pszParmValue));
1635 return false;
1637 *(char ***)parm_ptr = new_list;
1638 break;
1641 break;
1644 case P_STRING:
1645 lpcfg_string_set(mem_ctx, (char **)parm_ptr, pszParmValue);
1646 break;
1648 case P_USTRING:
1649 lpcfg_string_set_upper(mem_ctx, (char **)parm_ptr, pszParmValue);
1650 break;
1652 case P_ENUM:
1653 if (!lp_set_enum_parm(&parm_table[parmnum], pszParmValue, (int*)parm_ptr)) {
1654 return false;
1656 break;
1660 return true;
1664 bool handle_name_resolve_order(struct loadparm_context *lp_ctx,
1665 struct loadparm_service *service,
1666 const char *pszParmValue, char **ptr)
1668 const char **valid_values = NULL;
1669 const char **values_to_set = NULL;
1670 int i;
1671 bool value_is_valid = false;
1672 valid_values = str_list_make_v3_const(NULL,
1673 DEFAULT_NAME_RESOLVE_ORDER,
1674 NULL);
1675 if (valid_values == NULL) {
1676 DBG_ERR("OOM: failed to make string list from %s\n",
1677 DEFAULT_NAME_RESOLVE_ORDER);
1678 goto out;
1680 values_to_set = str_list_make_v3_const(lp_ctx->globals->ctx,
1681 pszParmValue,
1682 NULL);
1683 if (values_to_set == NULL) {
1684 DBG_ERR("OOM: failed to make string list from %s\n",
1685 pszParmValue);
1686 goto out;
1688 TALLOC_FREE(lp_ctx->globals->name_resolve_order);
1689 for (i = 0; values_to_set[i] != NULL; i++) {
1690 value_is_valid = str_list_check(valid_values, values_to_set[i]);
1691 if (!value_is_valid) {
1692 DBG_ERR("WARNING: Ignoring invalid list value '%s' "
1693 "for parameter 'name resolve order'\n",
1694 values_to_set[i]);
1695 break;
1698 out:
1699 if (value_is_valid) {
1700 lp_ctx->globals->name_resolve_order = values_to_set;
1701 } else {
1702 TALLOC_FREE(values_to_set);
1704 TALLOC_FREE(valid_values);
1705 return value_is_valid;
1708 static bool set_variable(TALLOC_CTX *mem_ctx, struct loadparm_service *service,
1709 int parmnum, void *parm_ptr,
1710 const char *pszParmName, const char *pszParmValue,
1711 struct loadparm_context *lp_ctx, bool on_globals)
1713 int i;
1714 bool ok;
1716 /* if it is a special case then go ahead */
1717 if (parm_table[parmnum].special) {
1718 ok = parm_table[parmnum].special(lp_ctx, service, pszParmValue,
1719 (char **)parm_ptr);
1720 } else {
1721 ok = set_variable_helper(mem_ctx, parmnum, parm_ptr,
1722 pszParmName, pszParmValue);
1725 if (!ok) {
1726 return false;
1729 if (on_globals && (lp_ctx->flags[parmnum] & FLAG_DEFAULT)) {
1730 lp_ctx->flags[parmnum] &= ~FLAG_DEFAULT;
1731 /* we have to also unset FLAG_DEFAULT on aliases */
1732 for (i=parmnum-1;i>=0 && parm_table[i].offset == parm_table[parmnum].offset;i--) {
1733 lp_ctx->flags[i] &= ~FLAG_DEFAULT;
1735 for (i=parmnum+1;i<num_parameters() && parm_table[i].offset == parm_table[parmnum].offset;i++) {
1736 lp_ctx->flags[i] &= ~FLAG_DEFAULT;
1739 return true;
1743 bool lpcfg_do_global_parameter(struct loadparm_context *lp_ctx,
1744 const char *pszParmName, const char *pszParmValue)
1746 int parmnum = lpcfg_map_parameter(pszParmName);
1747 void *parm_ptr;
1749 if (parmnum < 0) {
1750 if (strchr(pszParmName, ':')) {
1751 return lp_do_parameter_parametric(lp_ctx, NULL, pszParmName, pszParmValue, 0);
1753 DEBUG(0, ("Ignoring unknown parameter \"%s\"\n", pszParmName));
1754 return true;
1757 /* if the flag has been set on the command line, then don't allow override,
1758 but don't report an error */
1759 if (lp_ctx->flags[parmnum] & FLAG_CMDLINE) {
1760 return true;
1763 if (parm_table[parmnum].flags & FLAG_DEPRECATED) {
1764 char *suppress_env = getenv("SAMBA_DEPRECATED_SUPPRESS");
1765 bool print_warning = (suppress_env == NULL
1766 || suppress_env[0] == '\0');
1767 if (print_warning) {
1768 DBG_WARNING("WARNING: The \"%s\" option "
1769 "is deprecated\n",
1770 pszParmName);
1775 parm_ptr = lpcfg_parm_ptr(lp_ctx, NULL, &parm_table[parmnum]);
1777 return set_variable(lp_ctx->globals->ctx, NULL, parmnum, parm_ptr,
1778 pszParmName, pszParmValue, lp_ctx, true);
1781 bool lpcfg_do_service_parameter(struct loadparm_context *lp_ctx,
1782 struct loadparm_service *service,
1783 const char *pszParmName, const char *pszParmValue)
1785 void *parm_ptr;
1786 int i;
1787 int parmnum = lpcfg_map_parameter(pszParmName);
1789 if (parmnum < 0) {
1790 if (strchr(pszParmName, ':')) {
1791 return lp_do_parameter_parametric(lp_ctx, service, pszParmName, pszParmValue, 0);
1793 DEBUG(0, ("Ignoring unknown parameter \"%s\"\n", pszParmName));
1794 return true;
1797 /* if the flag has been set on the command line, then don't allow override,
1798 but don't report an error */
1799 if (lp_ctx->flags[parmnum] & FLAG_CMDLINE) {
1800 return true;
1803 if (parm_table[parmnum].flags & FLAG_DEPRECATED) {
1804 char *suppress_env = getenv("SAMBA_DEPRECATED_SUPPRESS");
1805 bool print_warning = (suppress_env == NULL
1806 || suppress_env[0] == '\0');
1807 if (print_warning) {
1808 DBG_WARNING("WARNING: The \"%s\" option "
1809 "is deprecated\n",
1810 pszParmName);
1815 if (parm_table[parmnum].p_class == P_GLOBAL) {
1816 DEBUG(0,
1817 ("Global parameter %s found in service section!\n",
1818 pszParmName));
1819 return true;
1821 parm_ptr = ((char *)service) + parm_table[parmnum].offset;
1823 if (!service->copymap)
1824 init_copymap(service);
1826 /* this handles the aliases - set the copymap for other
1827 * entries with the same data pointer */
1828 for (i = 0; parm_table[i].label; i++)
1829 if (parm_table[i].offset == parm_table[parmnum].offset &&
1830 parm_table[i].p_class == parm_table[parmnum].p_class)
1831 bitmap_clear(service->copymap, i);
1833 return set_variable(service, service, parmnum, parm_ptr, pszParmName,
1834 pszParmValue, lp_ctx, false);
1838 * Process a parameter.
1841 bool lpcfg_do_parameter(const char *pszParmName, const char *pszParmValue,
1842 void *userdata)
1844 struct loadparm_context *lp_ctx = (struct loadparm_context *)userdata;
1846 if (lp_ctx->bInGlobalSection)
1847 return lpcfg_do_global_parameter(lp_ctx, pszParmName,
1848 pszParmValue);
1849 else
1850 return lpcfg_do_service_parameter(lp_ctx, lp_ctx->currentService,
1851 pszParmName, pszParmValue);
1855 variable argument do parameter
1857 bool lpcfg_do_global_parameter_var(struct loadparm_context *lp_ctx, const char *pszParmName, const char *fmt, ...) PRINTF_ATTRIBUTE(3, 4);
1858 bool lpcfg_do_global_parameter_var(struct loadparm_context *lp_ctx,
1859 const char *pszParmName, const char *fmt, ...)
1861 char *s;
1862 bool ret;
1863 va_list ap;
1865 va_start(ap, fmt);
1866 s = talloc_vasprintf(NULL, fmt, ap);
1867 va_end(ap);
1868 ret = lpcfg_do_global_parameter(lp_ctx, pszParmName, s);
1869 talloc_free(s);
1870 return ret;
1875 set a parameter from the commandline - this is called from command line parameter
1876 parsing code. It sets the parameter then marks the parameter as unable to be modified
1877 by smb.conf processing
1879 bool lpcfg_set_cmdline(struct loadparm_context *lp_ctx, const char *pszParmName,
1880 const char *pszParmValue)
1882 int parmnum;
1883 int i;
1885 while (isspace((unsigned char)*pszParmValue)) pszParmValue++;
1887 parmnum = lpcfg_map_parameter(pszParmName);
1889 if (parmnum < 0 && strchr(pszParmName, ':')) {
1890 /* set a parametric option */
1891 bool ok;
1892 ok = lp_do_parameter_parametric(lp_ctx, NULL, pszParmName,
1893 pszParmValue, FLAG_CMDLINE);
1894 if (lp_ctx->s3_fns != NULL) {
1895 if (ok) {
1896 lp_ctx->s3_fns->store_cmdline(pszParmName, pszParmValue);
1899 return ok;
1902 if (parmnum < 0) {
1903 DEBUG(0,("Unknown option '%s'\n", pszParmName));
1904 return false;
1907 /* reset the CMDLINE flag in case this has been called before */
1908 lp_ctx->flags[parmnum] &= ~FLAG_CMDLINE;
1910 if (!lpcfg_do_global_parameter(lp_ctx, pszParmName, pszParmValue)) {
1911 return false;
1914 lp_ctx->flags[parmnum] |= FLAG_CMDLINE;
1916 /* we have to also set FLAG_CMDLINE on aliases */
1917 for (i=parmnum-1;
1918 i>=0 && parm_table[i].p_class == parm_table[parmnum].p_class &&
1919 parm_table[i].offset == parm_table[parmnum].offset;
1920 i--) {
1921 lp_ctx->flags[i] |= FLAG_CMDLINE;
1923 for (i=parmnum+1;
1924 i<num_parameters() &&
1925 parm_table[i].p_class == parm_table[parmnum].p_class &&
1926 parm_table[i].offset == parm_table[parmnum].offset;
1927 i++) {
1928 lp_ctx->flags[i] |= FLAG_CMDLINE;
1931 if (lp_ctx->s3_fns != NULL) {
1932 lp_ctx->s3_fns->store_cmdline(pszParmName, pszParmValue);
1935 return true;
1939 set a option from the commandline in 'a=b' format. Use to support --option
1941 bool lpcfg_set_option(struct loadparm_context *lp_ctx, const char *option)
1943 char *p, *s;
1944 bool ret;
1946 s = talloc_strdup(NULL, option);
1947 if (!s) {
1948 return false;
1951 p = strchr(s, '=');
1952 if (!p) {
1953 talloc_free(s);
1954 return false;
1957 *p = 0;
1959 ret = lpcfg_set_cmdline(lp_ctx, s, p+1);
1960 talloc_free(s);
1961 return ret;
1965 #define BOOLSTR(b) ((b) ? "Yes" : "No")
1968 * Print a parameter of the specified type.
1971 void lpcfg_print_parameter(struct parm_struct *p, void *ptr, FILE * f)
1973 /* For the seperation of lists values that we print below */
1974 const char *list_sep = ", ";
1975 int i;
1976 switch (p->type)
1978 case P_ENUM:
1979 for (i = 0; p->enum_list[i].name; i++) {
1980 if (*(int *)ptr == p->enum_list[i].value) {
1981 fprintf(f, "%s",
1982 p->enum_list[i].name);
1983 break;
1986 break;
1988 case P_BOOL:
1989 fprintf(f, "%s", BOOLSTR(*(bool *)ptr));
1990 break;
1992 case P_BOOLREV:
1993 fprintf(f, "%s", BOOLSTR(!*(bool *)ptr));
1994 break;
1996 case P_INTEGER:
1997 case P_BYTES:
1998 fprintf(f, "%d", *(int *)ptr);
1999 break;
2001 case P_CHAR:
2002 fprintf(f, "%c", *(char *)ptr);
2003 break;
2005 case P_OCTAL: {
2006 int val = *(int *)ptr;
2007 if (val == -1) {
2008 fprintf(f, "-1");
2009 } else {
2010 fprintf(f, "0%03o", val);
2012 break;
2015 case P_CMDLIST:
2016 list_sep = " ";
2018 FALL_THROUGH;
2019 case P_LIST:
2020 if ((char ***)ptr && *(char ***)ptr) {
2021 char **list = *(char ***)ptr;
2022 for (; *list; list++) {
2023 /* surround strings with whitespace in double quotes */
2024 if (*(list+1) == NULL) {
2025 /* last item, no extra separator */
2026 list_sep = "";
2028 if ( strchr_m( *list, ' ' ) ) {
2029 fprintf(f, "\"%s\"%s", *list, list_sep);
2030 } else {
2031 fprintf(f, "%s%s", *list, list_sep);
2035 break;
2037 case P_STRING:
2038 case P_USTRING:
2039 if (*(char **)ptr) {
2040 fprintf(f, "%s", *(char **)ptr);
2042 break;
2047 * Check if two parameters are equal.
2050 static bool lpcfg_equal_parameter(parm_type type, void *ptr1, void *ptr2)
2052 switch (type) {
2053 case P_BOOL:
2054 case P_BOOLREV:
2055 return (*((bool *)ptr1) == *((bool *)ptr2));
2057 case P_INTEGER:
2058 case P_ENUM:
2059 case P_OCTAL:
2060 case P_BYTES:
2061 return (*((int *)ptr1) == *((int *)ptr2));
2063 case P_CHAR:
2064 return (*((char *)ptr1) == *((char *)ptr2));
2066 case P_LIST:
2067 case P_CMDLIST:
2068 return str_list_equal(*(const char ***)ptr1, *(const char ***)ptr2);
2070 case P_STRING:
2071 case P_USTRING:
2073 char *p1 = *(char **)ptr1, *p2 = *(char **)ptr2;
2074 if (p1 && !*p1)
2075 p1 = NULL;
2076 if (p2 && !*p2)
2077 p2 = NULL;
2078 return (p1 == p2 || strequal(p1, p2));
2081 return false;
2085 * Process a new section (service).
2087 * At this stage all sections are services.
2088 * Later we'll have special sections that permit server parameters to be set.
2089 * Returns True on success, False on failure.
2092 static bool do_section(const char *pszSectionName, void *userdata)
2094 struct loadparm_context *lp_ctx = (struct loadparm_context *)userdata;
2095 bool bRetval;
2096 bool isglobal;
2098 if (lp_ctx->s3_fns != NULL) {
2099 return lp_ctx->s3_fns->do_section(pszSectionName, lp_ctx);
2102 isglobal = ((strwicmp(pszSectionName, GLOBAL_NAME) == 0) ||
2103 (strwicmp(pszSectionName, GLOBAL_NAME2) == 0));
2105 /* if we've just struck a global section, note the fact. */
2106 lp_ctx->bInGlobalSection = isglobal;
2108 /* check for multiple global sections */
2109 if (lp_ctx->bInGlobalSection) {
2110 DEBUG(4, ("Processing section \"[%s]\"\n", pszSectionName));
2111 bRetval = true;
2112 goto out;
2115 /* if we have a current service, tidy it up before moving on */
2116 bRetval = true;
2118 if (lp_ctx->currentService != NULL)
2119 bRetval = lpcfg_service_ok(lp_ctx->currentService);
2121 /* if all is still well, move to the next record in the services array */
2122 if (bRetval) {
2123 /* We put this here to avoid an odd message order if messages are */
2124 /* issued by the post-processing of a previous section. */
2125 DEBUG(4, ("Processing section \"[%s]\"\n", pszSectionName));
2127 if ((lp_ctx->currentService = lpcfg_add_service(lp_ctx, lp_ctx->sDefault,
2128 pszSectionName))
2129 == NULL) {
2130 DEBUG(0, ("Failed to add a new service\n"));
2131 bRetval = false;
2132 goto out;
2135 out:
2136 return bRetval;
2141 * Determine if a particular base parameter is currently set to the default value.
2144 static bool is_default(void *base_structure, int i)
2146 void *def_ptr = ((char *)base_structure) + parm_table[i].offset;
2147 switch (parm_table[i].type) {
2148 case P_CMDLIST:
2149 case P_LIST:
2150 return str_list_equal((const char * const *)parm_table[i].def.lvalue,
2151 *(const char * const **)def_ptr);
2152 case P_STRING:
2153 case P_USTRING:
2154 return strequal(parm_table[i].def.svalue,
2155 *(char **)def_ptr);
2156 case P_BOOL:
2157 case P_BOOLREV:
2158 return parm_table[i].def.bvalue ==
2159 *(bool *)def_ptr;
2160 case P_INTEGER:
2161 case P_CHAR:
2162 case P_OCTAL:
2163 case P_BYTES:
2164 case P_ENUM:
2165 return parm_table[i].def.ivalue ==
2166 *(int *)def_ptr;
2168 return false;
2172 *Display the contents of the global structure.
2175 void lpcfg_dump_globals(struct loadparm_context *lp_ctx, FILE *f,
2176 bool show_defaults)
2178 int i;
2179 struct parmlist_entry *data;
2181 fprintf(f, "# Global parameters\n[global]\n");
2183 for (i = 0; parm_table[i].label; i++) {
2184 if (parm_table[i].p_class != P_GLOBAL) {
2185 continue;
2188 if (parm_table[i].flags & FLAG_SYNONYM) {
2189 continue;
2192 if (!show_defaults) {
2193 if (lp_ctx->flags && (lp_ctx->flags[i] & FLAG_DEFAULT)) {
2194 continue;
2197 if (is_default(lp_ctx->globals, i)) {
2198 continue;
2202 fprintf(f, "\t%s = ", parm_table[i].label);
2203 lpcfg_print_parameter(&parm_table[i], lpcfg_parm_ptr(lp_ctx, NULL, &parm_table[i]), f);
2204 fprintf(f, "\n");
2206 if (lp_ctx->globals->param_opt != NULL) {
2207 for (data = lp_ctx->globals->param_opt; data;
2208 data = data->next) {
2209 if (!show_defaults && (data->priority & FLAG_DEFAULT)) {
2210 continue;
2212 fprintf(f, "\t%s = %s\n", data->key, data->value);
2219 * Display the contents of a single services record.
2222 void lpcfg_dump_a_service(struct loadparm_service * pService, struct loadparm_service *sDefault, FILE * f,
2223 unsigned int *flags, bool show_defaults)
2225 int i;
2226 struct parmlist_entry *data;
2228 if (pService != sDefault)
2229 fprintf(f, "\n[%s]\n", pService->szService);
2231 for (i = 0; parm_table[i].label; i++) {
2232 if (parm_table[i].p_class != P_LOCAL) {
2233 continue;
2236 if (parm_table[i].flags & FLAG_SYNONYM) {
2237 continue;
2240 if (*parm_table[i].label == '-') {
2241 continue;
2244 if (pService == sDefault) {
2245 if (!show_defaults) {
2246 if (flags && (flags[i] & FLAG_DEFAULT)) {
2247 continue;
2250 if (is_default(sDefault, i)) {
2251 continue;
2254 } else {
2255 bool equal;
2257 equal = lpcfg_equal_parameter(parm_table[i].type,
2258 ((char *)pService) +
2259 parm_table[i].offset,
2260 ((char *)sDefault) +
2261 parm_table[i].offset);
2262 if (equal) {
2263 continue;
2267 fprintf(f, "\t%s = ", parm_table[i].label);
2268 lpcfg_print_parameter(&parm_table[i],
2269 ((char *)pService) + parm_table[i].offset, f);
2270 fprintf(f, "\n");
2272 if (pService->param_opt != NULL) {
2273 for (data = pService->param_opt; data; data = data->next) {
2274 if (!show_defaults && (data->priority & FLAG_DEFAULT)) {
2275 continue;
2277 fprintf(f, "\t%s = %s\n", data->key, data->value);
2282 bool lpcfg_dump_a_parameter(struct loadparm_context *lp_ctx,
2283 struct loadparm_service *service,
2284 const char *parm_name, FILE * f)
2286 struct parm_struct *parm;
2287 void *ptr;
2288 char *local_parm_name;
2289 char *parm_opt;
2290 const char *parm_opt_value;
2292 /* check for parametrical option */
2293 local_parm_name = talloc_strdup(lp_ctx, parm_name);
2294 if (local_parm_name == NULL) {
2295 return false;
2298 parm_opt = strchr( local_parm_name, ':');
2300 if (parm_opt) {
2301 *parm_opt = '\0';
2302 parm_opt++;
2303 if (strlen(parm_opt)) {
2304 parm_opt_value = lpcfg_parm_string(lp_ctx, service,
2305 local_parm_name, parm_opt);
2306 if (parm_opt_value) {
2307 fprintf(f, "%s\n", parm_opt_value);
2308 TALLOC_FREE(local_parm_name);
2309 return true;
2312 TALLOC_FREE(local_parm_name);
2313 return false;
2315 TALLOC_FREE(local_parm_name);
2317 /* parameter is not parametric, search the table */
2318 parm = lpcfg_parm_struct(lp_ctx, parm_name);
2319 if (!parm) {
2320 return false;
2323 if (service != NULL && parm->p_class == P_GLOBAL) {
2324 return false;
2327 ptr = lpcfg_parm_ptr(lp_ctx, service,parm);
2329 lpcfg_print_parameter(parm, ptr, f);
2330 fprintf(f, "\n");
2331 return true;
2335 * Auto-load some home services.
2337 static void lpcfg_add_auto_services(struct loadparm_context *lp_ctx,
2338 const char *str)
2340 return;
2343 /***************************************************************************
2344 Initialise the sDefault parameter structure for the printer values.
2345 ***************************************************************************/
2347 void init_printer_values(struct loadparm_context *lp_ctx, TALLOC_CTX *ctx,
2348 struct loadparm_service *pService)
2350 /* choose defaults depending on the type of printing */
2351 switch (pService->printing) {
2352 case PRINT_BSD:
2353 case PRINT_AIX:
2354 case PRINT_LPRNT:
2355 case PRINT_LPROS2:
2356 lpcfg_string_set(ctx, &pService->lpq_command, "lpq -P'%p'");
2357 lpcfg_string_set(ctx, &pService->lprm_command, "lprm -P'%p' %j");
2358 lpcfg_string_set(ctx, &pService->print_command, "lpr -r -P'%p' %s");
2359 break;
2361 case PRINT_LPRNG:
2362 case PRINT_PLP:
2363 lpcfg_string_set(ctx, &pService->lpq_command, "lpq -P'%p'");
2364 lpcfg_string_set(ctx, &pService->lprm_command, "lprm -P'%p' %j");
2365 lpcfg_string_set(ctx, &pService->print_command, "lpr -r -P'%p' %s");
2366 lpcfg_string_set(ctx, &pService->queuepause_command, "lpc stop '%p'");
2367 lpcfg_string_set(ctx, &pService->queueresume_command, "lpc start '%p'");
2368 lpcfg_string_set(ctx, &pService->lppause_command, "lpc hold '%p' %j");
2369 lpcfg_string_set(ctx, &pService->lpresume_command, "lpc release '%p' %j");
2370 break;
2372 case PRINT_CUPS:
2373 case PRINT_IPRINT:
2374 /* set the lpq command to contain the destination printer
2375 name only. This is used by cups_queue_get() */
2376 lpcfg_string_set(ctx, &pService->lpq_command, "%p");
2377 lpcfg_string_set(ctx, &pService->lprm_command, "");
2378 lpcfg_string_set(ctx, &pService->print_command, "");
2379 lpcfg_string_set(ctx, &pService->lppause_command, "");
2380 lpcfg_string_set(ctx, &pService->lpresume_command, "");
2381 lpcfg_string_set(ctx, &pService->queuepause_command, "");
2382 lpcfg_string_set(ctx, &pService->queueresume_command, "");
2383 break;
2385 case PRINT_SYSV:
2386 case PRINT_HPUX:
2387 lpcfg_string_set(ctx, &pService->lpq_command, "lpstat -o%p");
2388 lpcfg_string_set(ctx, &pService->lprm_command, "cancel %p-%j");
2389 lpcfg_string_set(ctx, &pService->print_command, "lp -c -d%p %s; rm %s");
2390 lpcfg_string_set(ctx, &pService->queuepause_command, "disable %p");
2391 lpcfg_string_set(ctx, &pService->queueresume_command, "enable %p");
2392 #ifndef HPUX
2393 lpcfg_string_set(ctx, &pService->lppause_command, "lp -i %p-%j -H hold");
2394 lpcfg_string_set(ctx, &pService->lpresume_command, "lp -i %p-%j -H resume");
2395 #endif /* HPUX */
2396 break;
2398 case PRINT_QNX:
2399 lpcfg_string_set(ctx, &pService->lpq_command, "lpq -P%p");
2400 lpcfg_string_set(ctx, &pService->lprm_command, "lprm -P%p %j");
2401 lpcfg_string_set(ctx, &pService->print_command, "lp -r -P%p %s");
2402 break;
2404 #if defined(DEVELOPER) || defined(ENABLE_SELFTEST)
2406 case PRINT_TEST:
2407 case PRINT_VLP: {
2408 const char *tdbfile;
2409 TALLOC_CTX *tmp_ctx = talloc_new(ctx);
2410 const char *tmp;
2412 tmp = lpcfg_parm_string(lp_ctx, NULL, "vlp", "tdbfile");
2413 if (tmp == NULL) {
2414 tmp = "/tmp/vlp.tdb";
2417 tdbfile = talloc_asprintf(tmp_ctx, "tdbfile=%s", tmp);
2418 if (tdbfile == NULL) {
2419 tdbfile="tdbfile=/tmp/vlp.tdb";
2422 tmp = talloc_asprintf(tmp_ctx, "vlp %s print %%p %%s",
2423 tdbfile);
2424 lpcfg_string_set(ctx, &pService->print_command,
2425 tmp ? tmp : "vlp print %p %s");
2427 tmp = talloc_asprintf(tmp_ctx, "vlp %s lpq %%p",
2428 tdbfile);
2429 lpcfg_string_set(ctx, &pService->lpq_command,
2430 tmp ? tmp : "vlp lpq %p");
2432 tmp = talloc_asprintf(tmp_ctx, "vlp %s lprm %%p %%j",
2433 tdbfile);
2434 lpcfg_string_set(ctx, &pService->lprm_command,
2435 tmp ? tmp : "vlp lprm %p %j");
2437 tmp = talloc_asprintf(tmp_ctx, "vlp %s lppause %%p %%j",
2438 tdbfile);
2439 lpcfg_string_set(ctx, &pService->lppause_command,
2440 tmp ? tmp : "vlp lppause %p %j");
2442 tmp = talloc_asprintf(tmp_ctx, "vlp %s lpresume %%p %%j",
2443 tdbfile);
2444 lpcfg_string_set(ctx, &pService->lpresume_command,
2445 tmp ? tmp : "vlp lpresume %p %j");
2447 tmp = talloc_asprintf(tmp_ctx, "vlp %s queuepause %%p",
2448 tdbfile);
2449 lpcfg_string_set(ctx, &pService->queuepause_command,
2450 tmp ? tmp : "vlp queuepause %p");
2452 tmp = talloc_asprintf(tmp_ctx, "vlp %s queueresume %%p",
2453 tdbfile);
2454 lpcfg_string_set(ctx, &pService->queueresume_command,
2455 tmp ? tmp : "vlp queueresume %p");
2456 TALLOC_FREE(tmp_ctx);
2458 break;
2460 #endif /* DEVELOPER */
2466 static int lpcfg_destructor(struct loadparm_context *lp_ctx)
2468 struct parmlist_entry *data;
2470 if (lp_ctx->refuse_free) {
2471 /* someone is trying to free the
2472 global_loadparm_context.
2473 We can't allow that. */
2474 return -1;
2477 if (lp_ctx->globals->param_opt != NULL) {
2478 struct parmlist_entry *next;
2479 for (data = lp_ctx->globals->param_opt; data; data=next) {
2480 next = data->next;
2481 if (data->priority & FLAG_CMDLINE) continue;
2482 DLIST_REMOVE(lp_ctx->globals->param_opt, data);
2483 talloc_free(data);
2487 return 0;
2491 * Initialise the global parameter structure.
2493 * Note that most callers should use loadparm_init_global() instead
2495 struct loadparm_context *loadparm_init(TALLOC_CTX *mem_ctx)
2497 int i;
2498 char *myname;
2499 struct loadparm_context *lp_ctx;
2500 struct parmlist_entry *parm;
2501 char *logfile;
2503 lp_ctx = talloc_zero(mem_ctx, struct loadparm_context);
2504 if (lp_ctx == NULL)
2505 return NULL;
2507 talloc_set_destructor(lp_ctx, lpcfg_destructor);
2508 lp_ctx->bInGlobalSection = true;
2509 lp_ctx->globals = talloc_zero(lp_ctx, struct loadparm_global);
2510 /* This appears odd, but globals in s3 isn't a pointer */
2511 lp_ctx->globals->ctx = lp_ctx->globals;
2512 lp_ctx->globals->rpc_low_port = SERVER_TCP_LOW_PORT;
2513 lp_ctx->globals->rpc_high_port = SERVER_TCP_HIGH_PORT;
2514 lp_ctx->globals->weak_crypto = SAMBA_WEAK_CRYPTO_UNKNOWN;
2515 lp_ctx->sDefault = talloc_zero(lp_ctx, struct loadparm_service);
2516 lp_ctx->flags = talloc_zero_array(lp_ctx, unsigned int, num_parameters());
2518 lp_ctx->sDefault->max_print_jobs = 1000;
2519 lp_ctx->sDefault->available = true;
2520 lp_ctx->sDefault->browseable = true;
2521 lp_ctx->sDefault->read_only = true;
2522 lp_ctx->sDefault->map_archive = true;
2523 lp_ctx->sDefault->strict_locking = true;
2524 lp_ctx->sDefault->oplocks = true;
2525 lp_ctx->sDefault->create_mask = 0744;
2526 lp_ctx->sDefault->force_create_mode = 0000;
2527 lp_ctx->sDefault->directory_mask = 0755;
2528 lp_ctx->sDefault->force_directory_mode = 0000;
2529 lp_ctx->sDefault->aio_read_size = 1;
2530 lp_ctx->sDefault->aio_write_size = 1;
2531 lp_ctx->sDefault->smbd_search_ask_sharemode = true;
2532 lp_ctx->sDefault->smbd_getinfo_ask_sharemode = true;
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;
2541 char **r;
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);
2545 } else {
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 pid", "No");
2565 lpcfg_do_global_parameter(lp_ctx, "debug uid", "No");
2566 lpcfg_do_global_parameter(lp_ctx, "debug class", "No");
2568 lpcfg_do_global_parameter(lp_ctx, "share backend", "classic");
2570 lpcfg_do_global_parameter(lp_ctx, "server role", "auto");
2571 lpcfg_do_global_parameter(lp_ctx, "domain logons", "No");
2572 lpcfg_do_global_parameter(lp_ctx, "domain master", "Auto");
2574 /* options that can be set on the command line must be initialised via
2575 the slower lpcfg_do_global_parameter() to ensure that FLAG_CMDLINE is obeyed */
2576 #ifdef TCP_NODELAY
2577 lpcfg_do_global_parameter(lp_ctx, "socket options", "TCP_NODELAY");
2578 #endif
2579 lpcfg_do_global_parameter(lp_ctx, "workgroup", DEFAULT_WORKGROUP);
2580 myname = get_myname(lp_ctx);
2581 lpcfg_do_global_parameter(lp_ctx, "netbios name", myname);
2582 talloc_free(myname);
2583 lpcfg_do_global_parameter(lp_ctx,
2584 "name resolve order",
2585 DEFAULT_NAME_RESOLVE_ORDER);
2587 lpcfg_do_global_parameter(lp_ctx, "fstype", "NTFS");
2589 lpcfg_do_global_parameter(lp_ctx, "ntvfs handler", "unixuid default");
2590 lpcfg_do_global_parameter(lp_ctx, "max connections", "0");
2592 lpcfg_do_global_parameter(lp_ctx, "dcerpc endpoint servers", "epmapper wkssvc rpcecho samr netlogon lsarpc drsuapi dssetup unixinfo browser eventlog6 backupkey dnsserver");
2593 lpcfg_do_global_parameter(lp_ctx, "server services", "s3fs rpc nbt wrepl ldap cldap kdc drepl winbindd ntp_signd kcc dnsupdate dns");
2594 lpcfg_do_global_parameter(lp_ctx, "kccsrv:samba_kcc", "true");
2595 /* the winbind method for domain controllers is for both RODC
2596 auth forwarding and for trusted domains */
2597 lpcfg_do_global_parameter(lp_ctx, "private dir", dyn_PRIVATE_DIR);
2598 lpcfg_do_global_parameter(lp_ctx, "binddns dir", dyn_BINDDNS_DIR);
2599 lpcfg_do_global_parameter(lp_ctx, "registry:HKEY_LOCAL_MACHINE", "hklm.ldb");
2601 /* This hive should be dynamically generated by Samba using
2602 data from the sam, but for the moment leave it in a tdb to
2603 keep regedt32 from popping up an annoying dialog. */
2604 lpcfg_do_global_parameter(lp_ctx, "registry:HKEY_USERS", "hku.ldb");
2606 /* using UTF8 by default allows us to support all chars */
2607 lpcfg_do_global_parameter(lp_ctx, "unix charset", "UTF-8");
2609 /* Use codepage 850 as a default for the dos character set */
2610 lpcfg_do_global_parameter(lp_ctx, "dos charset", "CP850");
2613 * Allow the default PASSWD_CHAT to be overridden in local.h.
2615 lpcfg_do_global_parameter(lp_ctx, "passwd chat", DEFAULT_PASSWD_CHAT);
2617 lpcfg_do_global_parameter(lp_ctx, "pid directory", dyn_PIDDIR);
2618 lpcfg_do_global_parameter(lp_ctx, "lock dir", dyn_LOCKDIR);
2619 lpcfg_do_global_parameter(lp_ctx, "state directory", dyn_STATEDIR);
2620 lpcfg_do_global_parameter(lp_ctx, "cache directory", dyn_CACHEDIR);
2621 lpcfg_do_global_parameter(lp_ctx, "ncalrpc dir", dyn_NCALRPCDIR);
2623 lpcfg_do_global_parameter(lp_ctx, "nbt client socket address", "0.0.0.0");
2624 lpcfg_do_global_parameter_var(lp_ctx, "server string",
2625 "Samba %s", SAMBA_VERSION_STRING);
2627 lpcfg_do_global_parameter(lp_ctx, "password server", "*");
2629 lpcfg_do_global_parameter(lp_ctx, "max mux", "50");
2630 lpcfg_do_global_parameter(lp_ctx, "max xmit", "16644");
2631 lpcfg_do_global_parameter(lp_ctx, "host msdfs", "true");
2633 lpcfg_do_global_parameter(lp_ctx, "LargeReadwrite", "True");
2634 lpcfg_do_global_parameter(lp_ctx, "server min protocol", "SMB2_02");
2635 lpcfg_do_global_parameter(lp_ctx, "server max protocol", "SMB3");
2636 lpcfg_do_global_parameter(lp_ctx, "client min protocol", "SMB2_02");
2637 lpcfg_do_global_parameter(lp_ctx, "client max protocol", "default");
2638 lpcfg_do_global_parameter(lp_ctx, "client ipc min protocol", "default");
2639 lpcfg_do_global_parameter(lp_ctx, "client ipc max protocol", "default");
2640 lpcfg_do_global_parameter(lp_ctx, "security", "AUTO");
2641 lpcfg_do_global_parameter(lp_ctx, "EncryptPasswords", "True");
2642 lpcfg_do_global_parameter(lp_ctx, "ReadRaw", "True");
2643 lpcfg_do_global_parameter(lp_ctx, "WriteRaw", "True");
2644 lpcfg_do_global_parameter(lp_ctx, "NullPasswords", "False");
2645 lpcfg_do_global_parameter(lp_ctx, "old password allowed period", "60");
2646 lpcfg_do_global_parameter(lp_ctx, "ObeyPamRestrictions", "False");
2648 lpcfg_do_global_parameter(lp_ctx, "TimeServer", "False");
2649 lpcfg_do_global_parameter(lp_ctx, "BindInterfacesOnly", "False");
2650 lpcfg_do_global_parameter(lp_ctx, "Unicode", "True");
2651 lpcfg_do_global_parameter(lp_ctx, "ClientLanManAuth", "False");
2652 lpcfg_do_global_parameter(lp_ctx, "ClientNTLMv2Auth", "True");
2653 lpcfg_do_global_parameter(lp_ctx, "LanmanAuth", "False");
2654 lpcfg_do_global_parameter(lp_ctx, "NTLMAuth", "ntlmv2-only");
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", "True");
2671 lpcfg_do_global_parameter(lp_ctx, "require strong key", "True");
2672 lpcfg_do_global_parameter(lp_ctx, "winbindd socket directory", dyn_WINBINDD_SOCKET_DIR);
2673 lpcfg_do_global_parameter(lp_ctx, "ntp signd socket directory", dyn_NTP_SIGND_SOCKET_DIR);
2674 lpcfg_do_global_parameter_var(lp_ctx, "gpo update command", "%s/samba-gpupdate", dyn_SCRIPTSBINDIR);
2675 lpcfg_do_global_parameter_var(lp_ctx, "apply group policies", "False");
2676 lpcfg_do_global_parameter_var(lp_ctx, "dns update command", "%s/samba_dnsupdate", dyn_SCRIPTSBINDIR);
2677 lpcfg_do_global_parameter_var(lp_ctx, "spn update command", "%s/samba_spnupdate", dyn_SCRIPTSBINDIR);
2678 lpcfg_do_global_parameter_var(lp_ctx, "samba kcc command",
2679 "%s/samba_kcc", dyn_SCRIPTSBINDIR);
2680 #ifdef MIT_KDC_PATH
2681 lpcfg_do_global_parameter_var(lp_ctx,
2682 "mit kdc command",
2683 MIT_KDC_PATH);
2684 #endif
2685 lpcfg_do_global_parameter(lp_ctx, "template shell", "/bin/false");
2686 lpcfg_do_global_parameter(lp_ctx, "template homedir", "/home/%D/%U");
2688 lpcfg_do_global_parameter(lp_ctx, "client signing", "default");
2689 lpcfg_do_global_parameter(lp_ctx, "client ipc signing", "default");
2690 lpcfg_do_global_parameter(lp_ctx, "server signing", "default");
2692 lpcfg_do_global_parameter(lp_ctx, "use mmap", "True");
2694 lpcfg_do_global_parameter(lp_ctx, "smb ports", "445 139");
2695 lpcfg_do_global_parameter_var(lp_ctx, "nbt port", "%d", NBT_NAME_SERVICE_PORT);
2696 lpcfg_do_global_parameter_var(lp_ctx, "dgram port", "%d", NBT_DGRAM_SERVICE_PORT);
2697 lpcfg_do_global_parameter(lp_ctx, "cldap port", "389");
2698 lpcfg_do_global_parameter(lp_ctx, "krb5 port", "88");
2699 lpcfg_do_global_parameter(lp_ctx, "kpasswd port", "464");
2701 lpcfg_do_global_parameter(lp_ctx, "nt status support", "True");
2703 lpcfg_do_global_parameter(lp_ctx, "max wins ttl", "518400"); /* 6 days */
2704 lpcfg_do_global_parameter(lp_ctx, "min wins ttl", "21600");
2706 lpcfg_do_global_parameter(lp_ctx, "tls enabled", "True");
2707 lpcfg_do_global_parameter(lp_ctx, "tls verify peer", "as_strict_as_possible");
2708 lpcfg_do_global_parameter(lp_ctx, "tls keyfile", "tls/key.pem");
2709 lpcfg_do_global_parameter(lp_ctx, "tls certfile", "tls/cert.pem");
2710 lpcfg_do_global_parameter(lp_ctx, "tls cafile", "tls/ca.pem");
2711 lpcfg_do_global_parameter(lp_ctx,
2712 "tls priority",
2713 "NORMAL:-VERS-SSL3.0");
2715 lpcfg_do_global_parameter(lp_ctx, "nsupdate command", "/usr/bin/nsupdate -g");
2717 lpcfg_do_global_parameter(lp_ctx, "allow dns updates", "secure only");
2718 lpcfg_do_global_parameter(lp_ctx, "dns zone scavenging", "False");
2719 lpcfg_do_global_parameter(lp_ctx, "dns forwarder", "");
2721 lpcfg_do_global_parameter(lp_ctx, "algorithmic rid base", "1000");
2723 lpcfg_do_global_parameter(lp_ctx, "enhanced browsing", "True");
2725 lpcfg_do_global_parameter(lp_ctx, "winbind nss info", "template");
2727 lpcfg_do_global_parameter(lp_ctx, "server schannel", "True");
2729 lpcfg_do_global_parameter(lp_ctx, "short preserve case", "True");
2731 lpcfg_do_global_parameter(lp_ctx, "max open files", "16384");
2733 lpcfg_do_global_parameter(lp_ctx, "cups connection timeout", "30");
2735 lpcfg_do_global_parameter(lp_ctx, "locking", "True");
2737 lpcfg_do_global_parameter(lp_ctx, "block size", "1024");
2739 lpcfg_do_global_parameter(lp_ctx, "client use spnego", "True");
2741 lpcfg_do_global_parameter(lp_ctx, "change notify", "True");
2743 lpcfg_do_global_parameter(lp_ctx, "name cache timeout", "660");
2745 lpcfg_do_global_parameter(lp_ctx, "defer sharing violations", "True");
2747 lpcfg_do_global_parameter(lp_ctx, "ldap replication sleep", "1000");
2749 lpcfg_do_global_parameter(lp_ctx, "idmap backend", "tdb");
2751 lpcfg_do_global_parameter(lp_ctx, "enable privileges", "True");
2753 lpcfg_do_global_parameter_var(lp_ctx, "smb2 max write", "%u", DEFAULT_SMB2_MAX_WRITE);
2755 lpcfg_do_global_parameter(lp_ctx, "passdb backend", "tdbsam");
2757 lpcfg_do_global_parameter(lp_ctx, "deadtime", "10080");
2759 lpcfg_do_global_parameter(lp_ctx, "getwd cache", "True");
2761 lpcfg_do_global_parameter(lp_ctx, "winbind nested groups", "True");
2763 lpcfg_do_global_parameter(lp_ctx, "mangled names", "illegal");
2765 lpcfg_do_global_parameter_var(lp_ctx, "smb2 max credits", "%u", DEFAULT_SMB2_MAX_CREDITS);
2767 lpcfg_do_global_parameter(lp_ctx, "ldap ssl", "start tls");
2769 lpcfg_do_global_parameter(lp_ctx, "ldap deref", "auto");
2771 lpcfg_do_global_parameter(lp_ctx, "lm interval", "60");
2773 lpcfg_do_global_parameter(lp_ctx, "mangling method", "hash2");
2775 lpcfg_do_global_parameter(lp_ctx, "hide dot files", "True");
2777 lpcfg_do_global_parameter(lp_ctx, "browse list", "True");
2779 lpcfg_do_global_parameter(lp_ctx, "passwd chat timeout", "2");
2781 lpcfg_do_global_parameter(lp_ctx, "guest account", GUEST_ACCOUNT);
2783 lpcfg_do_global_parameter(lp_ctx, "client schannel", "True");
2785 lpcfg_do_global_parameter(lp_ctx, "smb encrypt", "default");
2787 lpcfg_do_global_parameter(lp_ctx, "max log size", "5000");
2789 lpcfg_do_global_parameter(lp_ctx, "idmap negative cache time", "120");
2791 lpcfg_do_global_parameter(lp_ctx, "ldap follow referral", "auto");
2793 lpcfg_do_global_parameter(lp_ctx, "multicast dns register", "yes");
2795 lpcfg_do_global_parameter(lp_ctx, "winbind reconnect delay", "30");
2797 lpcfg_do_global_parameter(lp_ctx, "winbind request timeout", "60");
2799 lpcfg_do_global_parameter(lp_ctx, "nt acl support", "yes");
2801 lpcfg_do_global_parameter(lp_ctx, "acl check permissions", "yes");
2803 lpcfg_do_global_parameter(lp_ctx, "keepalive", "300");
2805 lpcfg_do_global_parameter(lp_ctx, "smbd profiling level", "off");
2807 lpcfg_do_global_parameter(lp_ctx, "winbind cache time", "300");
2809 lpcfg_do_global_parameter(lp_ctx, "level2 oplocks", "yes");
2811 lpcfg_do_global_parameter(lp_ctx, "show add printer wizard", "yes");
2813 lpcfg_do_global_parameter(lp_ctx, "ldap page size", "1000");
2815 lpcfg_do_global_parameter(lp_ctx, "kernel share modes", "yes");
2817 lpcfg_do_global_parameter(lp_ctx, "strict locking", "Auto");
2819 lpcfg_do_global_parameter(lp_ctx, "strict sync", "yes");
2821 lpcfg_do_global_parameter(lp_ctx, "map readonly", "no");
2823 lpcfg_do_global_parameter(lp_ctx, "allow trusted domains", "yes");
2825 lpcfg_do_global_parameter(lp_ctx, "default devmode", "yes");
2827 lpcfg_do_global_parameter(lp_ctx, "os level", "20");
2829 lpcfg_do_global_parameter(lp_ctx, "dos filetimes", "yes");
2831 lpcfg_do_global_parameter(lp_ctx, "mangling char", "~");
2833 lpcfg_do_global_parameter(lp_ctx, "printcap cache time", "750");
2835 lpcfg_do_global_parameter(lp_ctx, "create krb5 conf", "yes");
2837 lpcfg_do_global_parameter(lp_ctx, "winbind max clients", "200");
2839 lpcfg_do_global_parameter(lp_ctx, "acl map full control", "yes");
2841 lpcfg_do_global_parameter(lp_ctx, "nt pipe support", "yes");
2843 lpcfg_do_global_parameter(lp_ctx, "ldap debug threshold", "10");
2845 lpcfg_do_global_parameter(lp_ctx, "client ldap sasl wrapping", "sign");
2847 lpcfg_do_global_parameter(lp_ctx, "mdns name", "netbios");
2849 lpcfg_do_global_parameter(lp_ctx, "ldap server require strong auth", "yes");
2851 lpcfg_do_global_parameter(lp_ctx, "follow symlinks", "yes");
2853 lpcfg_do_global_parameter(lp_ctx, "machine password timeout", "604800");
2855 lpcfg_do_global_parameter(lp_ctx, "ldap connection timeout", "2");
2857 lpcfg_do_global_parameter(lp_ctx, "winbind expand groups", "0");
2859 lpcfg_do_global_parameter(lp_ctx, "stat cache", "yes");
2861 lpcfg_do_global_parameter(lp_ctx, "lpq cache time", "30");
2863 lpcfg_do_global_parameter_var(lp_ctx, "smb2 max trans", "%u", DEFAULT_SMB2_MAX_TRANSACT);
2865 lpcfg_do_global_parameter_var(lp_ctx, "smb2 max read", "%u", DEFAULT_SMB2_MAX_READ);
2867 lpcfg_do_global_parameter(lp_ctx, "durable handles", "yes");
2869 lpcfg_do_global_parameter(lp_ctx, "max stat cache size", "512");
2871 lpcfg_do_global_parameter(lp_ctx, "ldap passwd sync", "no");
2873 lpcfg_do_global_parameter(lp_ctx, "kernel change notify", "yes");
2875 lpcfg_do_global_parameter(lp_ctx, "max ttl", "259200");
2877 lpcfg_do_global_parameter(lp_ctx, "blocking locks", "yes");
2879 lpcfg_do_global_parameter(lp_ctx, "load printers", "yes");
2881 lpcfg_do_global_parameter(lp_ctx, "idmap cache time", "604800");
2883 lpcfg_do_global_parameter(lp_ctx, "preserve case", "yes");
2885 lpcfg_do_global_parameter(lp_ctx, "lm announce", "auto");
2887 lpcfg_do_global_parameter(lp_ctx, "afs token lifetime", "604800");
2889 lpcfg_do_global_parameter(lp_ctx, "enable core files", "yes");
2891 lpcfg_do_global_parameter(lp_ctx, "winbind max domain connections", "1");
2893 lpcfg_do_global_parameter(lp_ctx, "case sensitive", "auto");
2895 lpcfg_do_global_parameter(lp_ctx, "ldap timeout", "15");
2897 lpcfg_do_global_parameter(lp_ctx, "mangle prefix", "1");
2899 lpcfg_do_global_parameter(lp_ctx, "posix locking", "yes");
2901 lpcfg_do_global_parameter(lp_ctx, "lock spin time", "200");
2903 lpcfg_do_global_parameter(lp_ctx, "directory name cache size", "100");
2905 lpcfg_do_global_parameter(lp_ctx, "nmbd bind explicit broadcast", "yes");
2907 lpcfg_do_global_parameter(lp_ctx, "init logon delay", "100");
2909 lpcfg_do_global_parameter(lp_ctx, "usershare owner only", "yes");
2911 lpcfg_do_global_parameter(lp_ctx, "-valid", "yes");
2913 lpcfg_do_global_parameter_var(lp_ctx, "usershare path", "%s/usershares", get_dyn_STATEDIR());
2915 #ifdef DEVELOPER
2916 lpcfg_do_global_parameter_var(lp_ctx, "panic action", "/bin/sleep 999999999");
2917 #endif
2919 lpcfg_do_global_parameter(lp_ctx, "smb passwd file", get_dyn_SMB_PASSWD_FILE());
2921 lpcfg_do_global_parameter(lp_ctx, "logon home", "\\\\%N\\%U");
2923 lpcfg_do_global_parameter(lp_ctx, "logon path", "\\\\%N\\%U\\profile");
2925 lpcfg_do_global_parameter(lp_ctx, "printjob username", "%U");
2927 lpcfg_do_global_parameter(lp_ctx, "aio max threads", "100");
2929 lpcfg_do_global_parameter(lp_ctx, "smb2 leases", "yes");
2931 lpcfg_do_global_parameter(lp_ctx, "kerberos encryption types", "all");
2933 lpcfg_do_global_parameter(lp_ctx,
2934 "rpc server dynamic port range",
2935 "49152-65535");
2937 lpcfg_do_global_parameter(lp_ctx, "prefork children", "4");
2938 lpcfg_do_global_parameter(lp_ctx, "prefork backoff increment", "10");
2939 lpcfg_do_global_parameter(lp_ctx, "prefork maximum backoff", "120");
2941 lpcfg_do_global_parameter(lp_ctx, "check parent directory delete on close", "no");
2943 lpcfg_do_global_parameter(lp_ctx, "ea support", "yes");
2945 lpcfg_do_global_parameter(lp_ctx, "store dos attributes", "yes");
2947 lpcfg_do_global_parameter(lp_ctx, "debug encryption", "no");
2949 lpcfg_do_global_parameter(lp_ctx, "spotlight backend", "noindex");
2951 lpcfg_do_global_parameter(
2952 lp_ctx, "ldap max anonymous request size", "256000");
2953 lpcfg_do_global_parameter(
2954 lp_ctx, "ldap max authenticated request size", "16777216");
2955 lpcfg_do_global_parameter(
2956 lp_ctx, "ldap max search request size", "256000");
2958 /* Async DNS query timeout in seconds. */
2959 lpcfg_do_global_parameter(lp_ctx, "async dns timeout", "10");
2961 lpcfg_do_global_parameter(lp_ctx,
2962 "client smb encrypt",
2963 "default");
2965 for (i = 0; parm_table[i].label; i++) {
2966 if (!(lp_ctx->flags[i] & FLAG_CMDLINE)) {
2967 lp_ctx->flags[i] |= FLAG_DEFAULT;
2971 for (parm=lp_ctx->globals->param_opt; parm; parm=parm->next) {
2972 if (!(parm->priority & FLAG_CMDLINE)) {
2973 parm->priority |= FLAG_DEFAULT;
2977 for (parm=lp_ctx->sDefault->param_opt; parm; parm=parm->next) {
2978 if (!(parm->priority & FLAG_CMDLINE)) {
2979 parm->priority |= FLAG_DEFAULT;
2983 return lp_ctx;
2987 * Initialise the global parameter structure.
2989 struct loadparm_context *loadparm_init_global(bool load_default)
2991 if (global_loadparm_context == NULL) {
2992 global_loadparm_context = loadparm_init(NULL);
2994 if (global_loadparm_context == NULL) {
2995 return NULL;
2997 global_loadparm_context->global = true;
2998 if (load_default && !global_loadparm_context->loaded) {
2999 lpcfg_load_default(global_loadparm_context);
3001 global_loadparm_context->refuse_free = true;
3002 return global_loadparm_context;
3006 * Initialise the global parameter structure.
3008 struct loadparm_context *loadparm_init_s3(TALLOC_CTX *mem_ctx,
3009 const struct loadparm_s3_helpers *s3_fns)
3011 struct loadparm_context *loadparm_context = talloc_zero(mem_ctx, struct loadparm_context);
3012 if (!loadparm_context) {
3013 return NULL;
3015 loadparm_context->s3_fns = s3_fns;
3016 loadparm_context->globals = s3_fns->globals;
3017 loadparm_context->flags = s3_fns->flags;
3019 return loadparm_context;
3022 const char *lpcfg_configfile(struct loadparm_context *lp_ctx)
3024 return lp_ctx->szConfigFile;
3027 const char *lp_default_path(void)
3029 if (getenv("SMB_CONF_PATH"))
3030 return getenv("SMB_CONF_PATH");
3031 else
3032 return dyn_CONFIGFILE;
3036 * Update the internal state of a loadparm context after settings
3037 * have changed.
3039 static bool lpcfg_update(struct loadparm_context *lp_ctx)
3041 struct debug_settings settings;
3042 int max_protocol, min_protocol;
3043 TALLOC_CTX *tmp_ctx;
3044 const struct loadparm_substitution *lp_sub =
3045 lpcfg_noop_substitution();
3047 tmp_ctx = talloc_new(lp_ctx);
3048 if (tmp_ctx == NULL) {
3049 return false;
3052 lpcfg_add_auto_services(lp_ctx, lpcfg_auto_services(lp_ctx, lp_sub, tmp_ctx));
3054 if (!lp_ctx->globals->wins_server_list && lp_ctx->globals->we_are_a_wins_server) {
3055 lpcfg_do_global_parameter(lp_ctx, "wins server", "127.0.0.1");
3058 if (!lp_ctx->global) {
3059 TALLOC_FREE(tmp_ctx);
3060 return true;
3063 panic_action = lp_ctx->globals->panic_action;
3065 reload_charcnv(lp_ctx);
3067 ZERO_STRUCT(settings);
3068 /* Add any more debug-related smb.conf parameters created in
3069 * future here */
3070 settings.timestamp_logs = lp_ctx->globals->timestamp_logs;
3071 settings.debug_prefix_timestamp = lp_ctx->globals->debug_prefix_timestamp;
3072 settings.debug_hires_timestamp = lp_ctx->globals->debug_hires_timestamp;
3073 settings.debug_pid = lp_ctx->globals->debug_pid;
3074 settings.debug_uid = lp_ctx->globals->debug_uid;
3075 settings.debug_class = lp_ctx->globals->debug_class;
3076 settings.max_log_size = lp_ctx->globals->max_log_size;
3077 debug_set_settings(&settings, lp_ctx->globals->logging,
3078 lp_ctx->globals->syslog,
3079 lp_ctx->globals->syslog_only);
3081 /* FIXME: This is a bit of a hack, but we can't use a global, since
3082 * not everything that uses lp also uses the socket library */
3083 if (lpcfg_parm_bool(lp_ctx, NULL, "socket", "testnonblock", false)) {
3084 setenv("SOCKET_TESTNONBLOCK", "1", 1);
3085 } else {
3086 unsetenv("SOCKET_TESTNONBLOCK");
3089 /* Check if command line max protocol < min protocol, if so
3090 * report a warning to the user.
3092 max_protocol = lpcfg_client_max_protocol(lp_ctx);
3093 min_protocol = lpcfg_client_min_protocol(lp_ctx);
3094 if (lpcfg_client_max_protocol(lp_ctx) < lpcfg_client_min_protocol(lp_ctx)) {
3095 const char *max_protocolp, *min_protocolp;
3096 max_protocolp = lpcfg_get_smb_protocol(max_protocol);
3097 min_protocolp = lpcfg_get_smb_protocol(min_protocol);
3098 DBG_ERR("Max protocol %s is less than min protocol %s.\n",
3099 max_protocolp, min_protocolp);
3102 TALLOC_FREE(tmp_ctx);
3103 return true;
3106 bool lpcfg_load_default(struct loadparm_context *lp_ctx)
3108 const char *path;
3110 path = lp_default_path();
3112 if (!file_exist(path)) {
3113 /* We allow the default smb.conf file to not exist,
3114 * basically the equivalent of an empty file. */
3115 return lpcfg_update(lp_ctx);
3118 return lpcfg_load(lp_ctx, path);
3122 * Load the services array from the services file.
3124 * Return True on success, False on failure.
3126 static bool lpcfg_load_internal(struct loadparm_context *lp_ctx,
3127 const char *filename, bool set_global)
3129 char *n2;
3130 bool bRetval;
3132 if (lp_ctx->szConfigFile != NULL) {
3133 talloc_free(discard_const_p(char, lp_ctx->szConfigFile));
3134 lp_ctx->szConfigFile = NULL;
3137 lp_ctx->szConfigFile = talloc_strdup(lp_ctx, filename);
3139 if (lp_ctx->s3_fns) {
3140 return lp_ctx->s3_fns->load(filename);
3143 lp_ctx->bInGlobalSection = true;
3144 n2 = standard_sub_basic(lp_ctx, lp_ctx->szConfigFile);
3145 DEBUG(2, ("lpcfg_load: refreshing parameters from %s\n", n2));
3147 add_to_file_list(lp_ctx, &lp_ctx->file_lists, lp_ctx->szConfigFile, n2);
3149 /* We get sections first, so have to start 'behind' to make up */
3150 lp_ctx->currentService = NULL;
3151 bRetval = pm_process(n2, do_section, lpcfg_do_parameter, lp_ctx);
3153 /* finish up the last section */
3154 DEBUG(4, ("pm_process() returned %s\n", BOOLSTR(bRetval)));
3155 if (bRetval)
3156 if (lp_ctx->currentService != NULL)
3157 bRetval = lpcfg_service_ok(lp_ctx->currentService);
3159 bRetval = bRetval && lpcfg_update(lp_ctx);
3161 /* we do this unconditionally, so that it happens even
3162 for a missing smb.conf */
3163 reload_charcnv(lp_ctx);
3165 if (bRetval == true && set_global) {
3166 /* set this up so that any child python tasks will
3167 find the right smb.conf */
3168 setenv("SMB_CONF_PATH", filename, 1);
3170 /* set the context used by the lp_*() function
3171 varients */
3172 global_loadparm_context = lp_ctx;
3173 lp_ctx->loaded = true;
3176 return bRetval;
3179 bool lpcfg_load_no_global(struct loadparm_context *lp_ctx, const char *filename)
3181 return lpcfg_load_internal(lp_ctx, filename, false);
3184 bool lpcfg_load(struct loadparm_context *lp_ctx, const char *filename)
3186 return lpcfg_load_internal(lp_ctx, filename, true);
3190 * Return the max number of services.
3193 int lpcfg_numservices(struct loadparm_context *lp_ctx)
3195 if (lp_ctx->s3_fns) {
3196 return lp_ctx->s3_fns->get_numservices();
3199 return lp_ctx->iNumServices;
3203 * Display the contents of the services array in human-readable form.
3206 void lpcfg_dump(struct loadparm_context *lp_ctx, FILE *f, bool show_defaults,
3207 int maxtoprint)
3209 int iService;
3211 if (lp_ctx->s3_fns) {
3212 lp_ctx->s3_fns->dump(f, show_defaults, maxtoprint);
3213 return;
3216 lpcfg_dump_globals(lp_ctx, f, show_defaults);
3218 lpcfg_dump_a_service(lp_ctx->sDefault, lp_ctx->sDefault, f, lp_ctx->flags, show_defaults);
3220 for (iService = 0; iService < maxtoprint; iService++)
3221 lpcfg_dump_one(f, show_defaults, lp_ctx->services[iService], lp_ctx->sDefault);
3225 * Display the contents of one service in human-readable form.
3227 void lpcfg_dump_one(FILE *f, bool show_defaults, struct loadparm_service *service, struct loadparm_service *sDefault)
3229 if (service != NULL) {
3230 if (service->szService[0] == '\0')
3231 return;
3232 lpcfg_dump_a_service(service, sDefault, f, NULL, show_defaults);
3236 struct loadparm_service *lpcfg_servicebynum(struct loadparm_context *lp_ctx,
3237 int snum)
3239 if (lp_ctx->s3_fns) {
3240 return lp_ctx->s3_fns->get_servicebynum(snum);
3243 return lp_ctx->services[snum];
3246 struct loadparm_service *lpcfg_service(struct loadparm_context *lp_ctx,
3247 const char *service_name)
3249 int iService;
3250 char *serviceName;
3252 if (lp_ctx->s3_fns) {
3253 return lp_ctx->s3_fns->get_service(service_name);
3256 for (iService = lp_ctx->iNumServices - 1; iService >= 0; iService--) {
3257 if (lp_ctx->services[iService] &&
3258 lp_ctx->services[iService]->szService) {
3260 * The substitution here is used to support %U is
3261 * service names
3263 serviceName = standard_sub_basic(
3264 lp_ctx->services[iService],
3265 lp_ctx->services[iService]->szService);
3266 if (strequal(serviceName, service_name)) {
3267 talloc_free(serviceName);
3268 return lp_ctx->services[iService];
3270 talloc_free(serviceName);
3274 DEBUG(7,("lpcfg_servicenumber: couldn't find %s\n", service_name));
3275 return NULL;
3278 const char *lpcfg_servicename(const struct loadparm_service *service)
3280 return service ? lpcfg_string((const char *)service->szService) : NULL;
3284 * A useful volume label function.
3286 const char *lpcfg_volume_label(struct loadparm_service *service, struct loadparm_service *sDefault)
3288 const char *ret;
3289 ret = lpcfg_string((const char *)((service != NULL && service->volume != NULL) ?
3290 service->volume : sDefault->volume));
3291 if (!*ret)
3292 return lpcfg_servicename(service);
3293 return ret;
3295 struct smb_iconv_handle *lpcfg_iconv_handle(struct loadparm_context *lp_ctx)
3297 if (lp_ctx == NULL) {
3298 return get_iconv_handle();
3300 return lp_ctx->iconv_handle;
3303 _PUBLIC_ void reload_charcnv(struct loadparm_context *lp_ctx)
3305 if (!lp_ctx->global) {
3306 return;
3309 lp_ctx->iconv_handle =
3310 reinit_iconv_handle(lp_ctx,
3311 lpcfg_dos_charset(lp_ctx),
3312 lpcfg_unix_charset(lp_ctx));
3313 if (lp_ctx->iconv_handle == NULL) {
3314 smb_panic("reinit_iconv_handle failed");
3318 _PUBLIC_ char *lpcfg_tls_keyfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
3320 return lpcfg_private_path(mem_ctx, lp_ctx, lpcfg__tls_keyfile(lp_ctx));
3323 _PUBLIC_ char *lpcfg_tls_certfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
3325 return lpcfg_private_path(mem_ctx, lp_ctx, lpcfg__tls_certfile(lp_ctx));
3328 _PUBLIC_ char *lpcfg_tls_cafile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
3330 return lpcfg_private_path(mem_ctx, lp_ctx, lpcfg__tls_cafile(lp_ctx));
3333 _PUBLIC_ char *lpcfg_tls_crlfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
3335 return lpcfg_private_path(mem_ctx, lp_ctx, lpcfg__tls_crlfile(lp_ctx));
3338 _PUBLIC_ char *lpcfg_tls_dhpfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
3340 return lpcfg_private_path(mem_ctx, lp_ctx, lpcfg__tls_dhpfile(lp_ctx));
3343 struct gensec_settings *lpcfg_gensec_settings(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
3345 struct gensec_settings *settings = talloc_zero(mem_ctx, struct gensec_settings);
3346 if (settings == NULL)
3347 return NULL;
3348 SMB_ASSERT(lp_ctx != NULL);
3349 settings->lp_ctx = talloc_reference(settings, lp_ctx);
3350 settings->target_hostname = lpcfg_parm_string(lp_ctx, NULL, "gensec", "target_hostname");
3351 return settings;
3354 int lpcfg_server_role(struct loadparm_context *lp_ctx)
3356 int domain_master = lpcfg__domain_master(lp_ctx);
3358 return lp_find_server_role(lpcfg__server_role(lp_ctx),
3359 lpcfg__security(lp_ctx),
3360 lpcfg__domain_logons(lp_ctx),
3361 (domain_master == true) ||
3362 (domain_master == Auto));
3365 int lpcfg_security(struct loadparm_context *lp_ctx)
3367 return lp_find_security(lpcfg__server_role(lp_ctx),
3368 lpcfg__security(lp_ctx));
3371 int lpcfg_client_max_protocol(struct loadparm_context *lp_ctx)
3373 int client_max_protocol = lpcfg__client_max_protocol(lp_ctx);
3374 if (client_max_protocol == PROTOCOL_DEFAULT) {
3375 return PROTOCOL_LATEST;
3377 return client_max_protocol;
3380 int lpcfg_client_ipc_min_protocol(struct loadparm_context *lp_ctx)
3382 int client_ipc_min_protocol = lpcfg__client_ipc_min_protocol(lp_ctx);
3383 if (client_ipc_min_protocol == PROTOCOL_DEFAULT) {
3384 client_ipc_min_protocol = lpcfg_client_min_protocol(lp_ctx);
3386 if (client_ipc_min_protocol < PROTOCOL_NT1) {
3387 return PROTOCOL_NT1;
3389 return client_ipc_min_protocol;
3392 int lpcfg_client_ipc_max_protocol(struct loadparm_context *lp_ctx)
3394 int client_ipc_max_protocol = lpcfg__client_ipc_max_protocol(lp_ctx);
3395 if (client_ipc_max_protocol == PROTOCOL_DEFAULT) {
3396 return PROTOCOL_LATEST;
3398 if (client_ipc_max_protocol < PROTOCOL_NT1) {
3399 return PROTOCOL_NT1;
3401 return client_ipc_max_protocol;
3404 int lpcfg_client_ipc_signing(struct loadparm_context *lp_ctx)
3406 int client_ipc_signing = lpcfg__client_ipc_signing(lp_ctx);
3407 if (client_ipc_signing == SMB_SIGNING_DEFAULT) {
3408 return SMB_SIGNING_REQUIRED;
3410 return client_ipc_signing;
3413 bool lpcfg_server_signing_allowed(struct loadparm_context *lp_ctx, bool *mandatory)
3415 bool allowed = true;
3416 enum smb_signing_setting signing_setting = lpcfg_server_signing(lp_ctx);
3418 *mandatory = false;
3420 if (signing_setting == SMB_SIGNING_DEFAULT) {
3422 * If we are a domain controller, SMB signing is
3423 * really important, as it can prevent a number of
3424 * attacks on communications between us and the
3425 * clients
3427 * However, it really sucks (no sendfile, CPU
3428 * overhead) performance-wise when used on a
3429 * file server, so disable it by default
3430 * on non-DCs
3433 if (lpcfg_server_role(lp_ctx) >= ROLE_ACTIVE_DIRECTORY_DC) {
3434 signing_setting = SMB_SIGNING_REQUIRED;
3435 } else {
3436 signing_setting = SMB_SIGNING_OFF;
3440 switch (signing_setting) {
3441 case SMB_SIGNING_REQUIRED:
3442 *mandatory = true;
3443 break;
3444 case SMB_SIGNING_DESIRED:
3445 case SMB_SIGNING_IF_REQUIRED:
3446 break;
3447 case SMB_SIGNING_OFF:
3448 allowed = false;
3449 break;
3450 case SMB_SIGNING_DEFAULT:
3451 case SMB_SIGNING_IPC_DEFAULT:
3452 smb_panic(__location__);
3453 break;
3456 return allowed;
3459 int lpcfg_tdb_hash_size(struct loadparm_context *lp_ctx, const char *name)
3461 const char *base;
3463 if (name == NULL) {
3464 return 0;
3467 base = strrchr_m(name, '/');
3468 if (base != NULL) {
3469 base += 1;
3470 } else {
3471 base = name;
3473 return lpcfg_parm_int(lp_ctx, NULL, "tdb_hashsize", base, 0);
3477 int lpcfg_tdb_flags(struct loadparm_context *lp_ctx, int tdb_flags)
3479 if (!lpcfg_use_mmap(lp_ctx)) {
3480 tdb_flags |= TDB_NOMMAP;
3482 return tdb_flags;
3486 * Do not allow LanMan auth if unless NTLMv1 is also allowed
3488 * This also ensures it is disabled if NTLM is totally disabled
3490 bool lpcfg_lanman_auth(struct loadparm_context *lp_ctx)
3492 enum ntlm_auth_level ntlm_auth_level = lpcfg_ntlm_auth(lp_ctx);
3494 if (ntlm_auth_level == NTLM_AUTH_ON) {
3495 return lpcfg__lanman_auth(lp_ctx);
3496 } else {
3497 return false;
3501 static char *lpcfg_noop_substitution_fn(
3502 TALLOC_CTX *mem_ctx,
3503 const struct loadparm_substitution *lp_sub,
3504 const char *raw_value,
3505 void *private_data)
3507 return talloc_strdup(mem_ctx, raw_value);
3510 static const struct loadparm_substitution global_noop_substitution = {
3511 .substituted_string_fn = lpcfg_noop_substitution_fn,
3514 const struct loadparm_substitution *lpcfg_noop_substitution(void)
3516 return &global_noop_substitution;
3519 char *lpcfg_substituted_string(TALLOC_CTX *mem_ctx,
3520 const struct loadparm_substitution *lp_sub,
3521 const char *raw_value)
3523 return lp_sub->substituted_string_fn(mem_ctx,
3524 lp_sub,
3525 raw_value,
3526 lp_sub->private_data);
3530 * @brief Parse a string value of a given parameter to its integer enum value.
3532 * @param[in] param_name The parameter name (e.g. 'client smb encrypt')
3534 * @param[in] param_value The parameter value (e.g. 'required').
3536 * @return The integer value of the enum the param_value matches or INT32_MIN
3537 * on error.
3539 int32_t lpcfg_parse_enum_vals(const char *param_name,
3540 const char *param_value)
3542 struct parm_struct *parm = NULL;
3543 int32_t ret = INT32_MIN;
3544 bool ok;
3546 parm = lpcfg_parm_struct(NULL, param_name);
3547 if (parm == NULL) {
3548 return INT32_MIN;
3551 ok = lp_set_enum_parm(parm, param_value, &ret);
3552 if (!ok) {
3553 return INT32_MIN;
3556 return ret;