s4/heimdal/lib/krb5/pac.c: Align PAC buffers to match Windows
[Samba.git] / lib / param / loadparm.c
blob006caabc092afc634683fd8c5daf06248119dd7e
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"
77 #ifdef HAVE_HTTPCONNECTENCRYPT
78 #include <cups/http.h>
79 #endif
81 #define standard_sub_basic talloc_strdup
83 #include "lib/param/param_global.h"
85 struct loadparm_service *lpcfg_default_service(struct loadparm_context *lp_ctx)
87 return lp_ctx->sDefault;
90 int lpcfg_rpc_low_port(struct loadparm_context *lp_ctx)
92 return lp_ctx->globals->rpc_low_port;
95 int lpcfg_rpc_high_port(struct loadparm_context *lp_ctx)
97 return lp_ctx->globals->rpc_high_port;
100 enum samba_weak_crypto lpcfg_weak_crypto(struct loadparm_context *lp_ctx)
102 if (lp_ctx->globals->weak_crypto == SAMBA_WEAK_CRYPTO_UNKNOWN) {
103 lp_ctx->globals->weak_crypto = SAMBA_WEAK_CRYPTO_DISALLOWED;
105 if (samba_gnutls_weak_crypto_allowed()) {
106 lp_ctx->globals->weak_crypto = SAMBA_WEAK_CRYPTO_ALLOWED;
110 return lp_ctx->globals->weak_crypto;
114 * Convenience routine to grab string parameters into temporary memory
115 * and run standard_sub_basic on them.
117 * The buffers can be written to by
118 * callers without affecting the source string.
121 static const char *lpcfg_string(const char *s)
123 #if 0 /* until REWRITE done to make thread-safe */
124 size_t len = s ? strlen(s) : 0;
125 char *ret;
126 #endif
128 /* The follow debug is useful for tracking down memory problems
129 especially if you have an inner loop that is calling a lp_*()
130 function that returns a string. Perhaps this debug should be
131 present all the time? */
133 #if 0
134 DEBUG(10, ("lpcfg_string(%s)\n", s));
135 #endif
137 #if 0 /* until REWRITE done to make thread-safe */
138 if (!lp_talloc)
139 lp_talloc = talloc_init("lp_talloc");
141 ret = talloc_array(lp_talloc, char, len + 100); /* leave room for substitution */
143 if (!ret)
144 return NULL;
146 if (!s)
147 *ret = 0;
148 else
149 strlcpy(ret, s, len);
151 if (trim_string(ret, "\"", "\"")) {
152 if (strchr(ret,'"') != NULL)
153 strlcpy(ret, s, len);
156 standard_sub_basic(ret,len+100);
157 return (ret);
158 #endif
159 return s;
163 In this section all the functions that are used to access the
164 parameters from the rest of the program are defined
168 * the creation of separate lpcfg_*() and lp_*() functions is to allow
169 * for code compatibility between existing Samba4 and Samba3 code.
172 /* this global context supports the lp_*() function varients */
173 static struct loadparm_context *global_loadparm_context;
175 #define FN_GLOBAL_SUBSTITUTED_STRING(fn_name,var_name) \
176 _PUBLIC_ char *lpcfg_ ## fn_name(struct loadparm_context *lp_ctx, \
177 const struct loadparm_substitution *lp_sub, TALLOC_CTX *mem_ctx) \
179 if (lp_ctx == NULL) return NULL; \
180 return lpcfg_substituted_string(mem_ctx, lp_sub, \
181 lp_ctx->globals->var_name ? lp_ctx->globals->var_name : ""); \
184 #define FN_GLOBAL_CONST_STRING(fn_name,var_name) \
185 _PUBLIC_ const char *lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) { \
186 if (lp_ctx == NULL) return NULL; \
187 return lp_ctx->globals->var_name ? lpcfg_string(lp_ctx->globals->var_name) : ""; \
190 #define FN_GLOBAL_LIST(fn_name,var_name) \
191 _PUBLIC_ const char **lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) { \
192 if (lp_ctx == NULL) return NULL; \
193 return lp_ctx->globals->var_name; \
196 #define FN_GLOBAL_BOOL(fn_name,var_name) \
197 _PUBLIC_ bool lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) {\
198 if (lp_ctx == NULL) return false; \
199 return lp_ctx->globals->var_name; \
202 #define FN_GLOBAL_INTEGER(fn_name,var_name) \
203 _PUBLIC_ int lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) { \
204 return lp_ctx->globals->var_name; \
207 /* Local parameters don't need the ->s3_fns because the struct
208 * loadparm_service is shared and lpcfg_service() checks the ->s3_fns
209 * hook */
210 #define FN_LOCAL_SUBSTITUTED_STRING(fn_name,val) \
211 _PUBLIC_ char *lpcfg_ ## fn_name(struct loadparm_service *service, \
212 struct loadparm_service *sDefault, TALLOC_CTX *ctx) { \
213 return(talloc_strdup(ctx, lpcfg_string((const char *)((service != NULL && service->val != NULL) ? service->val : sDefault->val)))); \
216 #define FN_LOCAL_CONST_STRING(fn_name,val) \
217 _PUBLIC_ const char *lpcfg_ ## fn_name(struct loadparm_service *service, \
218 struct loadparm_service *sDefault) { \
219 return((const char *)((service != NULL && service->val != NULL) ? service->val : sDefault->val)); \
222 #define FN_LOCAL_LIST(fn_name,val) \
223 _PUBLIC_ const char **lpcfg_ ## fn_name(struct loadparm_service *service, \
224 struct loadparm_service *sDefault) {\
225 return(const char **)(service != NULL && service->val != NULL? service->val : sDefault->val); \
228 #define FN_LOCAL_PARM_BOOL(fn_name, val) FN_LOCAL_BOOL(fn_name, val)
230 #define FN_LOCAL_BOOL(fn_name,val) \
231 _PUBLIC_ bool lpcfg_ ## fn_name(struct loadparm_service *service, \
232 struct loadparm_service *sDefault) { \
233 return((service != NULL)? service->val : sDefault->val); \
236 #define FN_LOCAL_INTEGER(fn_name,val) \
237 _PUBLIC_ int lpcfg_ ## fn_name(struct loadparm_service *service, \
238 struct loadparm_service *sDefault) { \
239 return((service != NULL)? service->val : sDefault->val); \
242 #define FN_LOCAL_PARM_INTEGER(fn_name, val) FN_LOCAL_INTEGER(fn_name, val)
244 #define FN_LOCAL_CHAR(fn_name,val) \
245 _PUBLIC_ char lpcfg_ ## fn_name(struct loadparm_service *service, \
246 struct loadparm_service *sDefault) { \
247 return((service != NULL)? service->val : sDefault->val); \
250 #define FN_LOCAL_PARM_CHAR(fn_name,val) FN_LOCAL_CHAR(fn_name, val)
252 #include "lib/param/param_functions.c"
254 /* These functions cannot be auto-generated */
255 FN_LOCAL_BOOL(autoloaded, autoloaded)
256 FN_GLOBAL_CONST_STRING(dnsdomain, dnsdomain)
258 /* local prototypes */
259 static struct loadparm_service *lpcfg_getservicebyname(struct loadparm_context *lp_ctx,
260 const char *pszServiceName);
261 static bool do_section(const char *pszSectionName, void *);
262 static bool set_variable_helper(TALLOC_CTX *mem_ctx, int parmnum, void *parm_ptr,
263 const char *pszParmName, const char *pszParmValue);
264 static bool lp_do_parameter_parametric(struct loadparm_context *lp_ctx,
265 struct loadparm_service *service,
266 const char *pszParmName,
267 const char *pszParmValue, int flags);
269 /* The following are helper functions for parametrical options support. */
270 /* It returns a pointer to parametrical option value if it exists or NULL otherwise */
271 /* Actual parametrical functions are quite simple */
272 struct parmlist_entry *get_parametric_helper(struct loadparm_service *service,
273 const char *type, const char *option,
274 struct parmlist_entry *global_opts)
276 size_t type_len = strlen(type);
277 size_t option_len = strlen(option);
278 char param_key[type_len + option_len + 2];
279 struct parmlist_entry *data = NULL;
281 snprintf(param_key, sizeof(param_key), "%s:%s", type, option);
284 * Try to fetch the option from the data.
286 if (service != NULL) {
287 data = service->param_opt;
288 while (data != NULL) {
289 if (strwicmp(data->key, param_key) == 0) {
290 return data;
292 data = data->next;
297 * Fall back to fetching from the globals.
299 data = global_opts;
300 while (data != NULL) {
301 if (strwicmp(data->key, param_key) == 0) {
302 return data;
304 data = data->next;
307 return NULL;
310 const char *lpcfg_get_parametric(struct loadparm_context *lp_ctx,
311 struct loadparm_service *service,
312 const char *type, const char *option)
314 struct parmlist_entry *data;
316 if (lp_ctx == NULL)
317 return NULL;
319 data = get_parametric_helper(service,
320 type, option, lp_ctx->globals->param_opt);
322 if (data == NULL) {
323 return NULL;
324 } else {
325 return data->value;
331 * convenience routine to return int parameters.
333 int lp_int(const char *s)
336 if (!s || !*s) {
337 DEBUG(0,("lp_int(%s): is called with NULL!\n",s));
338 return -1;
341 return strtol(s, NULL, 0);
345 * convenience routine to return unsigned long parameters.
347 unsigned long lp_ulong(const char *s)
349 int error = 0;
350 unsigned long int ret;
352 if (!s || !*s) {
353 DBG_DEBUG("lp_ulong(%s): is called with NULL!\n",s);
354 return -1;
357 ret = smb_strtoul(s, NULL, 0, &error, SMB_STR_STANDARD);
358 if (error != 0) {
359 DBG_DEBUG("lp_ulong(%s): conversion failed\n",s);
360 return -1;
363 return ret;
367 * convenience routine to return unsigned long long parameters.
369 unsigned long long lp_ulonglong(const char *s)
371 int error = 0;
372 unsigned long long int ret;
374 if (!s || !*s) {
375 DBG_DEBUG("lp_ulonglong(%s): is called with NULL!\n", s);
376 return -1;
379 ret = smb_strtoull(s, NULL, 0, &error, SMB_STR_STANDARD);
380 if (error != 0) {
381 DBG_DEBUG("lp_ulonglong(%s): conversion failed\n",s);
382 return -1;
385 return ret;
389 * convenience routine to return unsigned long parameters.
391 static long lp_long(const char *s)
394 if (!s) {
395 DEBUG(0,("lp_long(%s): is called with NULL!\n",s));
396 return -1;
399 return strtol(s, NULL, 0);
403 * convenience routine to return unsigned long parameters.
405 static double lp_double(const char *s)
408 if (!s) {
409 DEBUG(0,("lp_double(%s): is called with NULL!\n",s));
410 return -1;
413 return strtod(s, NULL);
417 * convenience routine to return boolean parameters.
419 bool lp_bool(const char *s)
421 bool ret = false;
423 if (!s || !*s) {
424 DEBUG(0,("lp_bool(%s): is called with NULL!\n",s));
425 return false;
428 if (!set_boolean(s, &ret)) {
429 DEBUG(0,("lp_bool(%s): value is not boolean!\n",s));
430 return false;
433 return ret;
437 * Return parametric option from a given service. Type is a part of option before ':'
438 * Parametric option has following syntax: 'Type: option = value'
439 * Returned value is allocated in 'lp_talloc' context
442 const char *lpcfg_parm_string(struct loadparm_context *lp_ctx,
443 struct loadparm_service *service, const char *type,
444 const char *option)
446 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
448 if (value)
449 return lpcfg_string(value);
451 return NULL;
455 * Return parametric option from a given service. Type is a part of option before ':'
456 * Parametric option has following syntax: 'Type: option = value'
457 * Returned value is allocated in 'lp_talloc' context
460 const char **lpcfg_parm_string_list(TALLOC_CTX *mem_ctx,
461 struct loadparm_context *lp_ctx,
462 struct loadparm_service *service,
463 const char *type,
464 const char *option, const char *separator)
466 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
468 if (value != NULL) {
469 char **l = str_list_make(mem_ctx, value, separator);
470 return discard_const_p(const char *, l);
473 return NULL;
477 * Return parametric option from a given service. Type is a part of option before ':'
478 * Parametric option has following syntax: 'Type: option = value'
481 int lpcfg_parm_int(struct loadparm_context *lp_ctx,
482 struct loadparm_service *service, const char *type,
483 const char *option, int default_v)
485 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
487 if (value)
488 return lp_int(value);
490 return default_v;
494 * Return parametric option from a given service. Type is a part of
495 * option before ':'.
496 * Parametric option has following syntax: 'Type: option = value'.
499 int lpcfg_parm_bytes(struct loadparm_context *lp_ctx,
500 struct loadparm_service *service, const char *type,
501 const char *option, int default_v)
503 uint64_t bval;
505 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
507 if (value && conv_str_size_error(value, &bval)) {
508 if (bval <= INT_MAX) {
509 return (int)bval;
513 return default_v;
517 * Return parametric option from a given service.
518 * Type is a part of option before ':'
519 * Parametric option has following syntax: 'Type: option = value'
521 unsigned long lpcfg_parm_ulong(struct loadparm_context *lp_ctx,
522 struct loadparm_service *service, const char *type,
523 const char *option, unsigned long default_v)
525 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
527 if (value)
528 return lp_ulong(value);
530 return default_v;
534 * Return parametric option from a given service.
535 * Type is a part of option before ':'
536 * Parametric option has following syntax: 'Type: option = value'
538 unsigned long long lpcfg_parm_ulonglong(struct loadparm_context *lp_ctx,
539 struct loadparm_service *service,
540 const char *type, const char *option,
541 unsigned long long default_v)
543 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
545 if (value) {
546 return lp_ulonglong(value);
549 return default_v;
552 long lpcfg_parm_long(struct loadparm_context *lp_ctx,
553 struct loadparm_service *service, const char *type,
554 const char *option, long default_v)
556 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
558 if (value)
559 return lp_long(value);
561 return default_v;
564 double lpcfg_parm_double(struct loadparm_context *lp_ctx,
565 struct loadparm_service *service, const char *type,
566 const char *option, double default_v)
568 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
570 if (value != NULL)
571 return lp_double(value);
573 return default_v;
577 * Return parametric option from a given service. Type is a part of option before ':'
578 * Parametric option has following syntax: 'Type: option = value'
581 bool lpcfg_parm_bool(struct loadparm_context *lp_ctx,
582 struct loadparm_service *service, const char *type,
583 const char *option, bool default_v)
585 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
587 if (value != NULL)
588 return lp_bool(value);
590 return default_v;
594 /* this is used to prevent lots of mallocs of size 1 */
595 static const char lpcfg_string_empty[] = "";
598 Free a string value.
600 void lpcfg_string_free(char **s)
602 if (s == NULL) {
603 return;
605 if (*s == lpcfg_string_empty) {
606 *s = NULL;
607 return;
609 TALLOC_FREE(*s);
613 * Set a string value, deallocating any existing space, and allocing the space
614 * for the string
616 bool lpcfg_string_set(TALLOC_CTX *mem_ctx, char **dest, const char *src)
618 lpcfg_string_free(dest);
620 if ((src == NULL) || (*src == '\0')) {
621 *dest = discard_const_p(char, lpcfg_string_empty);
622 return true;
625 *dest = talloc_strdup(mem_ctx, src);
626 if ((*dest) == NULL) {
627 DEBUG(0,("Out of memory in string_set\n"));
628 return false;
631 return true;
635 * Set a string value, deallocating any existing space, and allocing the space
636 * for the string
638 bool lpcfg_string_set_upper(TALLOC_CTX *mem_ctx, char **dest, const char *src)
640 lpcfg_string_free(dest);
642 if ((src == NULL) || (*src == '\0')) {
643 *dest = discard_const_p(char, lpcfg_string_empty);
644 return true;
647 *dest = strupper_talloc(mem_ctx, src);
648 if ((*dest) == NULL) {
649 DEBUG(0,("Out of memory in string_set_upper\n"));
650 return false;
653 return true;
659 * Add a new service to the services array initialising it with the given
660 * service.
663 struct loadparm_service *lpcfg_add_service(struct loadparm_context *lp_ctx,
664 const struct loadparm_service *pservice,
665 const char *name)
667 int i;
668 int num_to_alloc = lp_ctx->iNumServices + 1;
669 struct parmlist_entry *data, *pdata;
671 if (lp_ctx->s3_fns != NULL) {
672 smb_panic("Add a service should not be called on an s3 loadparm ctx");
675 if (pservice == NULL) {
676 pservice = lp_ctx->sDefault;
679 /* it might already exist */
680 if (name) {
681 struct loadparm_service *service = lpcfg_getservicebyname(lp_ctx,
682 name);
683 if (service != NULL) {
684 /* Clean all parametric options for service */
685 /* They will be added during parsing again */
686 data = service->param_opt;
687 while (data) {
688 pdata = data->next;
689 talloc_free(data);
690 data = pdata;
692 service->param_opt = NULL;
693 return service;
697 /* find an invalid one */
698 for (i = 0; i < lp_ctx->iNumServices; i++)
699 if (lp_ctx->services[i] == NULL)
700 break;
702 /* if not, then create one */
703 if (i == lp_ctx->iNumServices) {
704 struct loadparm_service **tsp;
706 tsp = talloc_realloc(lp_ctx, lp_ctx->services, struct loadparm_service *, num_to_alloc);
708 if (!tsp) {
709 DEBUG(0,("lpcfg_add_service: failed to enlarge services!\n"));
710 return NULL;
711 } else {
712 lp_ctx->services = tsp;
713 lp_ctx->services[lp_ctx->iNumServices] = NULL;
716 lp_ctx->iNumServices++;
719 lp_ctx->services[i] = talloc_zero(lp_ctx->services, struct loadparm_service);
720 if (lp_ctx->services[i] == NULL) {
721 DEBUG(0,("lpcfg_add_service: out of memory!\n"));
722 return NULL;
724 copy_service(lp_ctx->services[i], pservice, NULL);
725 if (name != NULL)
726 lpcfg_string_set(lp_ctx->services[i], &lp_ctx->services[i]->szService, name);
727 return lp_ctx->services[i];
731 * Add a new home service, with the specified home directory, defaults coming
732 * from service ifrom.
735 bool lpcfg_add_home(struct loadparm_context *lp_ctx,
736 const char *pszHomename,
737 struct loadparm_service *default_service,
738 const char *user, const char *pszHomedir)
740 struct loadparm_service *service;
742 service = lpcfg_add_service(lp_ctx, default_service, pszHomename);
744 if (service == NULL)
745 return false;
747 if (!(*(default_service->path))
748 || strequal(default_service->path, lp_ctx->sDefault->path)) {
749 service->path = talloc_strdup(service, pszHomedir);
750 } else {
751 service->path = string_sub_talloc(service, lpcfg_path(default_service, lp_ctx->sDefault, service), "%H", pszHomedir);
754 if (!(*(service->comment))) {
755 service->comment = talloc_asprintf(service, "Home directory of %s", user);
757 service->available = default_service->available;
758 service->browseable = default_service->browseable;
760 DEBUG(3, ("adding home's share [%s] for user '%s' at '%s'\n",
761 pszHomename, user, service->path));
763 return true;
767 * Add a new printer service, with defaults coming from service iFrom.
770 bool lpcfg_add_printer(struct loadparm_context *lp_ctx,
771 const char *pszPrintername,
772 struct loadparm_service *default_service)
774 const char *comment = "From Printcap";
775 struct loadparm_service *service;
776 service = lpcfg_add_service(lp_ctx, default_service, pszPrintername);
778 if (service == NULL)
779 return false;
781 /* note that we do NOT default the availability flag to True - */
782 /* we take it from the default service passed. This allows all */
783 /* dynamic printers to be disabled by disabling the [printers] */
784 /* entry (if/when the 'available' keyword is implemented!). */
786 /* the printer name is set to the service name. */
787 lpcfg_string_set(service, &service->_printername, pszPrintername);
788 lpcfg_string_set(service, &service->comment, comment);
789 service->browseable = default_service->browseable;
790 /* Printers cannot be read_only. */
791 service->read_only = false;
792 /* Printer services must be printable. */
793 service->printable = true;
795 DEBUG(3, ("adding printer service %s\n", pszPrintername));
797 return true;
801 * Map a parameter's string representation to something we can use.
802 * Returns False if the parameter string is not recognised, else TRUE.
805 int lpcfg_map_parameter(const char *pszParmName)
807 int iIndex;
809 for (iIndex = 0; parm_table[iIndex].label; iIndex++)
810 if (strwicmp(parm_table[iIndex].label, pszParmName) == 0)
811 return iIndex;
813 /* Warn only if it isn't parametric option */
814 if (strchr(pszParmName, ':') == NULL)
815 DEBUG(0, ("Unknown parameter encountered: \"%s\"\n", pszParmName));
816 /* We do return 'fail' for parametric options as well because they are
817 stored in different storage
819 return -1;
824 return the parameter structure for a parameter
826 struct parm_struct *lpcfg_parm_struct(struct loadparm_context *lp_ctx, const char *name)
828 int num = lpcfg_map_parameter(name);
830 if (num < 0) {
831 return NULL;
834 return &parm_table[num];
838 return the parameter pointer for a parameter
840 void *lpcfg_parm_ptr(struct loadparm_context *lp_ctx,
841 struct loadparm_service *service, struct parm_struct *parm)
843 if (lp_ctx->s3_fns) {
844 return lp_ctx->s3_fns->get_parm_ptr(service, parm);
847 if (service == NULL) {
848 if (parm->p_class == P_LOCAL)
849 return ((char *)lp_ctx->sDefault)+parm->offset;
850 else if (parm->p_class == P_GLOBAL)
851 return ((char *)lp_ctx->globals)+parm->offset;
852 else return NULL;
853 } else {
854 return ((char *)service) + parm->offset;
859 return the parameter pointer for a parameter
861 bool lpcfg_parm_is_cmdline(struct loadparm_context *lp_ctx, const char *name)
863 int parmnum;
865 parmnum = lpcfg_map_parameter(name);
866 if (parmnum == -1) return false;
868 return lp_ctx->flags[parmnum] & FLAG_CMDLINE;
872 * Find a service by name. Otherwise works like get_service.
875 static struct loadparm_service *lpcfg_getservicebyname(struct loadparm_context *lp_ctx,
876 const char *pszServiceName)
878 int iService;
880 if (lp_ctx->s3_fns) {
881 return lp_ctx->s3_fns->get_service(pszServiceName);
884 for (iService = lp_ctx->iNumServices - 1; iService >= 0; iService--)
885 if (lp_ctx->services[iService] != NULL &&
886 strwicmp(lp_ctx->services[iService]->szService, pszServiceName) == 0) {
887 return lp_ctx->services[iService];
890 return NULL;
894 * Add a parametric option to a parmlist_entry,
895 * replacing old value, if already present.
897 void set_param_opt(TALLOC_CTX *mem_ctx,
898 struct parmlist_entry **opt_list,
899 const char *opt_name,
900 const char *opt_value,
901 unsigned priority)
903 struct parmlist_entry *new_opt, *opt;
905 opt = *opt_list;
907 /* Traverse destination */
908 while (opt) {
909 /* If we already have same option, override it */
910 if (strwicmp(opt->key, opt_name) == 0) {
911 if ((opt->priority & FLAG_CMDLINE) &&
912 !(priority & FLAG_CMDLINE)) {
913 /* it's been marked as not to be
914 overridden */
915 return;
917 TALLOC_FREE(opt->list);
918 lpcfg_string_set(opt, &opt->value, opt_value);
919 opt->priority = priority;
920 return;
922 opt = opt->next;
925 new_opt = talloc_pooled_object(
926 mem_ctx, struct parmlist_entry,
927 2, strlen(opt_name) + 1 + strlen(opt_value) + 1);
928 if (new_opt == NULL) {
929 smb_panic("OOM");
931 new_opt->key = NULL;
932 lpcfg_string_set(new_opt, &new_opt->key, opt_name);
933 new_opt->value = NULL;
934 lpcfg_string_set(new_opt, &new_opt->value, opt_value);
936 new_opt->list = NULL;
937 new_opt->priority = priority;
938 DLIST_ADD(*opt_list, new_opt);
942 * Copy a service structure to another.
943 * If pcopymapDest is NULL then copy all fields
946 void copy_service(struct loadparm_service *pserviceDest,
947 const struct loadparm_service *pserviceSource,
948 struct bitmap *pcopymapDest)
950 int i;
951 bool bcopyall = (pcopymapDest == NULL);
952 struct parmlist_entry *data;
954 for (i = 0; parm_table[i].label; i++)
955 if (parm_table[i].p_class == P_LOCAL &&
956 (bcopyall || bitmap_query(pcopymapDest, i))) {
957 const void *src_ptr =
958 ((const char *)pserviceSource) + parm_table[i].offset;
959 void *dest_ptr =
960 ((char *)pserviceDest) + parm_table[i].offset;
962 switch (parm_table[i].type) {
963 case P_BOOL:
964 case P_BOOLREV:
965 *(bool *)dest_ptr = *(const bool *)src_ptr;
966 break;
968 case P_INTEGER:
969 case P_BYTES:
970 case P_OCTAL:
971 case P_ENUM:
972 *(int *)dest_ptr = *(const int *)src_ptr;
973 break;
975 case P_CHAR:
976 *(char *)dest_ptr = *(const char *)src_ptr;
977 break;
979 case P_STRING:
980 lpcfg_string_set(pserviceDest,
981 (char **)dest_ptr,
982 *(const char * const *)src_ptr);
983 break;
985 case P_USTRING:
986 lpcfg_string_set_upper(pserviceDest,
987 (char **)dest_ptr,
988 *(const char * const *)src_ptr);
989 break;
990 case P_CMDLIST:
991 case P_LIST:
992 TALLOC_FREE(*((char ***)dest_ptr));
993 *(char ***)dest_ptr = str_list_copy(pserviceDest,
994 *discard_const_p(const char **, src_ptr));
995 break;
996 default:
997 break;
1001 if (bcopyall) {
1002 init_copymap(pserviceDest);
1003 if (pserviceSource->copymap)
1004 bitmap_copy(pserviceDest->copymap,
1005 pserviceSource->copymap);
1008 for (data = pserviceSource->param_opt; data != NULL; data = data->next) {
1009 set_param_opt(pserviceDest, &pserviceDest->param_opt,
1010 data->key, data->value, data->priority);
1015 * Check a service for consistency. Return False if the service is in any way
1016 * incomplete or faulty, else True.
1018 bool lpcfg_service_ok(struct loadparm_service *service)
1020 bool bRetval;
1022 bRetval = true;
1023 if (service->szService[0] == '\0') {
1024 DEBUG(0, ("The following message indicates an internal error:\n"));
1025 DEBUG(0, ("No service name in service entry.\n"));
1026 bRetval = false;
1029 /* The [printers] entry MUST be printable. I'm all for flexibility, but */
1030 /* I can't see why you'd want a non-printable printer service... */
1031 if (strwicmp(service->szService, PRINTERS_NAME) == 0) {
1032 if (!service->printable) {
1033 DEBUG(0, ("WARNING: [%s] service MUST be printable!\n",
1034 service->szService));
1035 service->printable = true;
1037 /* [printers] service must also be non-browsable. */
1038 if (service->browseable)
1039 service->browseable = false;
1042 if (service->path[0] == '\0' &&
1043 strwicmp(service->szService, HOMES_NAME) != 0 &&
1044 service->msdfs_proxy[0] == '\0')
1046 DEBUG(0, ("WARNING: No path in service %s - making it unavailable!\n",
1047 service->szService));
1048 service->available = false;
1051 if (!service->available)
1052 DEBUG(1, ("NOTE: Service %s is flagged unavailable.\n",
1053 service->szService));
1055 return bRetval;
1059 /*******************************************************************
1060 Keep a linked list of all config files so we know when one has changed
1061 it's date and needs to be reloaded.
1062 ********************************************************************/
1064 void add_to_file_list(TALLOC_CTX *mem_ctx, struct file_lists **list,
1065 const char *fname, const char *subfname)
1067 struct file_lists *f = *list;
1069 while (f) {
1070 if (f->name && !strcmp(f->name, fname))
1071 break;
1072 f = f->next;
1075 if (!f) {
1076 f = talloc(mem_ctx, struct file_lists);
1077 if (!f)
1078 goto fail;
1079 f->next = *list;
1080 f->name = talloc_strdup(f, fname);
1081 if (!f->name) {
1082 TALLOC_FREE(f);
1083 goto fail;
1085 f->subfname = talloc_strdup(f, subfname);
1086 if (!f->subfname) {
1087 TALLOC_FREE(f);
1088 goto fail;
1090 *list = f;
1091 f->modtime = file_modtime(subfname);
1092 } else {
1093 time_t t = file_modtime(subfname);
1094 if (t)
1095 f->modtime = t;
1097 return;
1099 fail:
1100 DEBUG(0, ("Unable to add file to file list: %s\n", fname));
1104 /*******************************************************************
1105 Check if a config file has changed date.
1106 ********************************************************************/
1107 bool lpcfg_file_list_changed(struct loadparm_context *lp_ctx)
1109 struct file_lists *f;
1110 DEBUG(6, ("lpcfg_file_list_changed()\n"));
1112 for (f = lp_ctx->file_lists; f != NULL; f = f->next) {
1113 char *n2;
1114 time_t mod_time;
1116 n2 = standard_sub_basic(lp_ctx, f->name);
1118 DEBUGADD(6, ("file %s -> %s last mod_time: %s\n",
1119 f->name, n2, ctime(&f->modtime)));
1121 mod_time = file_modtime(n2);
1123 if (mod_time && ((f->modtime != mod_time) || (f->subfname == NULL) || (strcmp(n2, f->subfname) != 0))) {
1124 DEBUGADD(6, ("file %s modified: %s\n", n2,
1125 ctime(&mod_time)));
1126 f->modtime = mod_time;
1127 talloc_free(f->subfname);
1128 f->subfname = talloc_strdup(f, n2);
1129 TALLOC_FREE(n2);
1130 return true;
1132 TALLOC_FREE(n2);
1134 return false;
1138 * set the value for a P_ENUM
1140 bool lp_set_enum_parm( struct parm_struct *parm, const char *pszParmValue,
1141 int *ptr )
1143 int i;
1145 for (i = 0; parm->enum_list[i].name; i++) {
1146 if (strwicmp(pszParmValue, parm->enum_list[i].name) == 0) {
1147 *ptr = parm->enum_list[i].value;
1148 return true;
1151 DEBUG(0, ("WARNING: Ignoring invalid value '%s' for parameter '%s'\n",
1152 pszParmValue, parm->label));
1153 return false;
1157 /***************************************************************************
1158 Handle the "realm" parameter
1159 ***************************************************************************/
1161 bool handle_realm(struct loadparm_context *lp_ctx, struct loadparm_service *service,
1162 const char *pszParmValue, char **ptr)
1164 char *upper;
1165 char *lower;
1167 upper = strupper_talloc(lp_ctx, pszParmValue);
1168 if (upper == NULL) {
1169 return false;
1172 lower = strlower_talloc(lp_ctx, pszParmValue);
1173 if (lower == NULL) {
1174 TALLOC_FREE(upper);
1175 return false;
1178 lpcfg_string_set(lp_ctx->globals->ctx, &lp_ctx->globals->realm, upper);
1179 lpcfg_string_set(lp_ctx->globals->ctx, &lp_ctx->globals->dnsdomain, lower);
1181 return true;
1184 /***************************************************************************
1185 Handle the include operation.
1186 ***************************************************************************/
1188 bool handle_include(struct loadparm_context *lp_ctx, struct loadparm_service *service,
1189 const char *pszParmValue, char **ptr)
1191 char *fname;
1192 const char *substitution_variable_substring;
1193 char next_char;
1195 if (lp_ctx->s3_fns) {
1196 return lp_ctx->s3_fns->lp_include(lp_ctx, service, pszParmValue, ptr);
1199 fname = standard_sub_basic(lp_ctx, pszParmValue);
1201 add_to_file_list(lp_ctx, &lp_ctx->file_lists, pszParmValue, fname);
1203 lpcfg_string_set(lp_ctx, ptr, fname);
1205 if (file_exist(fname))
1206 return pm_process(fname, do_section, lpcfg_do_parameter, lp_ctx);
1209 * If the file doesn't exist, we check that it isn't due to variable
1210 * substitution
1212 substitution_variable_substring = strchr(fname, '%');
1214 if (substitution_variable_substring != NULL) {
1215 next_char = substitution_variable_substring[1];
1216 if ((next_char >= 'a' && next_char <= 'z')
1217 || (next_char >= 'A' && next_char <= 'Z')) {
1218 DEBUG(2, ("Tried to load %s but variable substitution in "
1219 "filename, ignoring file.\n", fname));
1220 return true;
1224 DEBUG(2, ("Can't find include file %s\n", fname));
1226 return false;
1229 /***************************************************************************
1230 Handle the interpretation of the copy parameter.
1231 ***************************************************************************/
1233 bool handle_copy(struct loadparm_context *lp_ctx, struct loadparm_service *service,
1234 const char *pszParmValue, char **ptr)
1236 bool bRetval;
1237 struct loadparm_service *serviceTemp = NULL;
1239 bRetval = false;
1241 DEBUG(3, ("Copying service from service %s\n", pszParmValue));
1243 serviceTemp = lpcfg_getservicebyname(lp_ctx, pszParmValue);
1245 if (service == NULL) {
1246 DEBUG(0, ("Unable to copy service - invalid service destination.\n"));
1247 return false;
1250 if (serviceTemp != NULL) {
1251 if (serviceTemp == service) {
1252 DEBUG(0, ("Can't copy service %s - unable to copy self!\n", pszParmValue));
1253 } else {
1254 copy_service(service,
1255 serviceTemp,
1256 service->copymap);
1257 lpcfg_string_set(service, ptr, pszParmValue);
1259 bRetval = true;
1261 } else {
1262 DEBUG(0, ("Unable to copy service - source not found: %s\n",
1263 pszParmValue));
1264 bRetval = false;
1267 return bRetval;
1270 bool handle_debug_list(struct loadparm_context *lp_ctx, struct loadparm_service *service,
1271 const char *pszParmValue, char **ptr)
1273 lpcfg_string_set(lp_ctx->globals->ctx, ptr, pszParmValue);
1275 return debug_parse_levels(pszParmValue);
1278 bool handle_logfile(struct loadparm_context *lp_ctx, struct loadparm_service *service,
1279 const char *pszParmValue, char **ptr)
1281 if (lp_ctx->s3_fns == NULL) {
1282 debug_set_logfile(pszParmValue);
1285 lpcfg_string_set(lp_ctx->globals->ctx, ptr, pszParmValue);
1287 return true;
1291 * These special charset handling methods only run in the source3 code.
1294 bool handle_charset(struct loadparm_context *lp_ctx, struct loadparm_service *service,
1295 const char *pszParmValue, char **ptr)
1297 if (lp_ctx->s3_fns) {
1298 if (*ptr == NULL || strcmp(*ptr, pszParmValue) != 0) {
1299 struct smb_iconv_handle *ret = NULL;
1301 ret = reinit_iconv_handle(NULL,
1302 lpcfg_dos_charset(lp_ctx),
1303 lpcfg_unix_charset(lp_ctx));
1304 if (ret == NULL) {
1305 smb_panic("reinit_iconv_handle failed");
1310 return lpcfg_string_set(lp_ctx->globals->ctx, ptr, pszParmValue);
1314 bool handle_dos_charset(struct loadparm_context *lp_ctx, struct loadparm_service *service,
1315 const char *pszParmValue, char **ptr)
1317 bool is_utf8 = false;
1318 size_t len = strlen(pszParmValue);
1320 if (lp_ctx->s3_fns) {
1321 if (len == 4 || len == 5) {
1322 /* Don't use StrCaseCmp here as we don't want to
1323 initialize iconv. */
1324 if ((toupper_m(pszParmValue[0]) == 'U') &&
1325 (toupper_m(pszParmValue[1]) == 'T') &&
1326 (toupper_m(pszParmValue[2]) == 'F')) {
1327 if (len == 4) {
1328 if (pszParmValue[3] == '8') {
1329 is_utf8 = true;
1331 } else {
1332 if (pszParmValue[3] == '-' &&
1333 pszParmValue[4] == '8') {
1334 is_utf8 = true;
1340 if (*ptr == NULL || strcmp(*ptr, pszParmValue) != 0) {
1341 struct smb_iconv_handle *ret = NULL;
1342 if (is_utf8) {
1343 DEBUG(0,("ERROR: invalid DOS charset: 'dos charset' must not "
1344 "be UTF8, using (default value) %s instead.\n",
1345 DEFAULT_DOS_CHARSET));
1346 pszParmValue = DEFAULT_DOS_CHARSET;
1348 ret = reinit_iconv_handle(NULL,
1349 lpcfg_dos_charset(lp_ctx),
1350 lpcfg_unix_charset(lp_ctx));
1351 if (ret == NULL) {
1352 smb_panic("reinit_iconv_handle failed");
1357 return lpcfg_string_set(lp_ctx->globals->ctx, ptr, pszParmValue);
1360 bool handle_printing(struct loadparm_context *lp_ctx, struct loadparm_service *service,
1361 const char *pszParmValue, char **ptr)
1363 static int parm_num = -1;
1365 if (parm_num == -1) {
1366 parm_num = lpcfg_map_parameter("printing");
1369 if (!lp_set_enum_parm(&parm_table[parm_num], pszParmValue, (int*)ptr)) {
1370 return false;
1373 if (lp_ctx->s3_fns) {
1374 if (service == NULL) {
1375 init_printer_values(lp_ctx, lp_ctx->globals->ctx, lp_ctx->sDefault);
1376 } else {
1377 init_printer_values(lp_ctx, service, service);
1381 return true;
1384 bool handle_ldap_debug_level(struct loadparm_context *lp_ctx, struct loadparm_service *service,
1385 const char *pszParmValue, char **ptr)
1387 lp_ctx->globals->ldap_debug_level = lp_int(pszParmValue);
1389 if (lp_ctx->s3_fns) {
1390 lp_ctx->s3_fns->init_ldap_debugging();
1392 return true;
1395 bool handle_netbios_aliases(struct loadparm_context *lp_ctx, struct loadparm_service *service,
1396 const char *pszParmValue, char **ptr)
1398 TALLOC_FREE(lp_ctx->globals->netbios_aliases);
1399 lp_ctx->globals->netbios_aliases = str_list_make_v3_const(lp_ctx->globals->ctx,
1400 pszParmValue, NULL);
1402 if (lp_ctx->s3_fns) {
1403 return lp_ctx->s3_fns->set_netbios_aliases(lp_ctx->globals->netbios_aliases);
1405 return true;
1409 * idmap related parameters
1412 bool handle_idmap_backend(struct loadparm_context *lp_ctx, struct loadparm_service *service,
1413 const char *pszParmValue, char **ptr)
1415 if (lp_ctx->s3_fns) {
1416 lp_do_parameter_parametric(lp_ctx, service, "idmap config * : backend",
1417 pszParmValue, 0);
1420 return lpcfg_string_set(lp_ctx->globals->ctx, ptr, pszParmValue);
1423 bool handle_idmap_uid(struct loadparm_context *lp_ctx, struct loadparm_service *service,
1424 const char *pszParmValue, char **ptr)
1426 if (lp_ctx->s3_fns) {
1427 lp_do_parameter_parametric(lp_ctx, service, "idmap config * : range",
1428 pszParmValue, 0);
1431 return lpcfg_string_set(lp_ctx->globals->ctx, ptr, pszParmValue);
1434 bool handle_idmap_gid(struct loadparm_context *lp_ctx, struct loadparm_service *service,
1435 const char *pszParmValue, char **ptr)
1437 if (lp_ctx->s3_fns) {
1438 lp_do_parameter_parametric(lp_ctx, service, "idmap config * : range",
1439 pszParmValue, 0);
1442 return lpcfg_string_set(lp_ctx->globals->ctx, ptr, pszParmValue);
1445 bool handle_smb_ports(struct loadparm_context *lp_ctx, struct loadparm_service *service,
1446 const char *pszParmValue, char **ptr)
1448 static int parm_num = -1;
1449 int i;
1450 const char **list;
1452 if (!pszParmValue || !*pszParmValue) {
1453 return false;
1456 if (parm_num == -1) {
1457 parm_num = lpcfg_map_parameter("smb ports");
1458 if (parm_num == -1) {
1459 return false;
1463 if (!set_variable_helper(lp_ctx->globals->ctx, parm_num, ptr, "smb ports",
1464 pszParmValue)) {
1465 return false;
1468 list = lp_ctx->globals->smb_ports;
1469 if (list == NULL) {
1470 return false;
1473 /* Check that each port is a valid integer and within range */
1474 for (i = 0; list[i] != NULL; i++) {
1475 char *end = NULL;
1476 int port = 0;
1477 port = strtol(list[i], &end, 10);
1478 if (*end != '\0' || port <= 0 || port > 65535) {
1479 TALLOC_FREE(list);
1480 return false;
1484 return true;
1487 bool handle_rpc_server_dynamic_port_range(struct loadparm_context *lp_ctx,
1488 struct loadparm_service *service,
1489 const char *pszParmValue,
1490 char **ptr)
1492 static int parm_num = -1;
1493 int low_port = -1, high_port = -1;
1494 int rc;
1496 if (parm_num == -1) {
1497 parm_num = lpcfg_map_parameter("rpc server dynamic port range");
1498 if (parm_num == -1) {
1499 return false;
1503 if (pszParmValue == NULL || pszParmValue[0] == '\0') {
1504 return false;
1507 rc = sscanf(pszParmValue, "%d - %d", &low_port, &high_port);
1508 if (rc != 2) {
1509 return false;
1512 if (low_port > high_port) {
1513 return false;
1516 if (low_port < SERVER_TCP_PORT_MIN|| high_port > SERVER_TCP_PORT_MAX) {
1517 return false;
1520 if (!set_variable_helper(lp_ctx->globals->ctx, parm_num, ptr,
1521 "rpc server dynamic port range",
1522 pszParmValue)) {
1523 return false;
1526 lp_ctx->globals->rpc_low_port = low_port;
1527 lp_ctx->globals->rpc_high_port = high_port;
1529 return true;
1532 bool handle_smb2_max_credits(struct loadparm_context *lp_ctx,
1533 struct loadparm_service *service,
1534 const char *pszParmValue, char **ptr)
1536 int value = lp_int(pszParmValue);
1538 if (value <= 0) {
1539 value = DEFAULT_SMB2_MAX_CREDITS;
1542 *(int *)ptr = value;
1544 return true;
1547 bool handle_cups_encrypt(struct loadparm_context *lp_ctx,
1548 struct loadparm_service *service,
1549 const char *pszParmValue, char **ptr)
1551 int result = 0;
1552 #ifdef HAVE_HTTPCONNECTENCRYPT
1553 int value = lp_int(pszParmValue);
1555 switch (value) {
1556 case Auto:
1557 result = HTTP_ENCRYPT_REQUIRED;
1558 break;
1559 case true:
1560 result = HTTP_ENCRYPT_ALWAYS;
1561 break;
1562 case false:
1563 result = HTTP_ENCRYPT_NEVER;
1564 break;
1565 default:
1566 result = 0;
1567 break;
1569 #endif
1570 *(int *)ptr = result;
1572 return true;
1575 /***************************************************************************
1576 Initialise a copymap.
1577 ***************************************************************************/
1580 * Initializes service copymap
1581 * Note: pservice *must* be valid TALLOC_CTX
1583 void init_copymap(struct loadparm_service *pservice)
1585 int i;
1587 TALLOC_FREE(pservice->copymap);
1589 pservice->copymap = bitmap_talloc(pservice, num_parameters());
1590 if (!pservice->copymap) {
1591 DEBUG(0,
1592 ("Couldn't allocate copymap!! (size %d)\n",
1593 (int)num_parameters()));
1594 } else {
1595 for (i = 0; i < num_parameters(); i++) {
1596 bitmap_set(pservice->copymap, i);
1602 * Process a parametric option
1604 static bool lp_do_parameter_parametric(struct loadparm_context *lp_ctx,
1605 struct loadparm_service *service,
1606 const char *pszParmName,
1607 const char *pszParmValue, int flags)
1609 struct parmlist_entry **data;
1610 char *name;
1611 TALLOC_CTX *mem_ctx;
1613 while (isspace((unsigned char)*pszParmName)) {
1614 pszParmName++;
1617 name = strlower_talloc(lp_ctx, pszParmName);
1618 if (!name) return false;
1620 if (service == NULL) {
1621 data = &lp_ctx->globals->param_opt;
1623 * s3 code cannot deal with parametric options stored on the globals ctx.
1625 if (lp_ctx->s3_fns != NULL) {
1626 mem_ctx = NULL;
1627 } else {
1628 mem_ctx = lp_ctx->globals->ctx;
1630 } else {
1631 data = &service->param_opt;
1632 mem_ctx = service;
1635 set_param_opt(mem_ctx, data, name, pszParmValue, flags);
1637 talloc_free(name);
1639 return true;
1642 static bool set_variable_helper(TALLOC_CTX *mem_ctx, int parmnum, void *parm_ptr,
1643 const char *pszParmName, const char *pszParmValue)
1645 size_t i;
1647 /* switch on the type of variable it is */
1648 switch (parm_table[parmnum].type)
1650 case P_BOOL: {
1651 bool b;
1652 if (!set_boolean(pszParmValue, &b)) {
1653 DEBUG(0, ("set_variable_helper(%s): value is not "
1654 "boolean!\n", pszParmValue));
1655 return false;
1657 *(bool *)parm_ptr = b;
1659 break;
1661 case P_BOOLREV: {
1662 bool b;
1663 if (!set_boolean(pszParmValue, &b)) {
1664 DEBUG(0, ("set_variable_helper(%s): value is not "
1665 "boolean!\n", pszParmValue));
1666 return false;
1668 *(bool *)parm_ptr = !b;
1670 break;
1672 case P_INTEGER:
1673 *(int *)parm_ptr = lp_int(pszParmValue);
1674 break;
1676 case P_CHAR:
1677 *(char *)parm_ptr = *pszParmValue;
1678 break;
1680 case P_OCTAL:
1681 i = sscanf(pszParmValue, "%o", (int *)parm_ptr);
1682 if ( i != 1 ) {
1683 DEBUG ( 0, ("Invalid octal number %s\n", pszParmName ));
1684 return false;
1686 break;
1688 case P_BYTES:
1690 uint64_t val;
1691 if (conv_str_size_error(pszParmValue, &val)) {
1692 if (val <= INT_MAX) {
1693 *(int *)parm_ptr = (int)val;
1694 break;
1698 DEBUG(0, ("set_variable_helper(%s): value is not "
1699 "a valid size specifier!\n", pszParmValue));
1700 return false;
1703 case P_CMDLIST:
1704 TALLOC_FREE(*(char ***)parm_ptr);
1705 *(char ***)parm_ptr = str_list_make_v3(mem_ctx,
1706 pszParmValue, NULL);
1707 break;
1709 case P_LIST:
1711 char **new_list = str_list_make_v3(mem_ctx,
1712 pszParmValue, NULL);
1713 if (new_list == NULL) {
1714 break;
1717 for (i=0; new_list[i]; i++) {
1718 if (*(const char ***)parm_ptr != NULL &&
1719 new_list[i][0] == '+' &&
1720 new_list[i][1])
1722 if (!str_list_check(*(const char ***)parm_ptr,
1723 &new_list[i][1])) {
1724 *(const char ***)parm_ptr = str_list_add(*(const char ***)parm_ptr,
1725 &new_list[i][1]);
1727 } else if (*(const char ***)parm_ptr != NULL &&
1728 new_list[i][0] == '-' &&
1729 new_list[i][1])
1731 str_list_remove(*(const char ***)parm_ptr,
1732 &new_list[i][1]);
1733 } else {
1734 if (i != 0) {
1735 DEBUG(0, ("Unsupported list syntax for: %s = %s\n",
1736 pszParmName, pszParmValue));
1737 return false;
1739 *(char ***)parm_ptr = new_list;
1740 break;
1743 break;
1746 case P_STRING:
1747 lpcfg_string_set(mem_ctx, (char **)parm_ptr, pszParmValue);
1748 break;
1750 case P_USTRING:
1751 lpcfg_string_set_upper(mem_ctx, (char **)parm_ptr, pszParmValue);
1752 break;
1754 case P_ENUM:
1755 if (!lp_set_enum_parm(&parm_table[parmnum], pszParmValue, (int*)parm_ptr)) {
1756 return false;
1758 break;
1762 return true;
1766 bool handle_name_resolve_order(struct loadparm_context *lp_ctx,
1767 struct loadparm_service *service,
1768 const char *pszParmValue, char **ptr)
1770 const char **valid_values = NULL;
1771 const char **values_to_set = NULL;
1772 int i;
1773 bool value_is_valid = false;
1774 valid_values = str_list_make_v3_const(NULL,
1775 DEFAULT_NAME_RESOLVE_ORDER,
1776 NULL);
1777 if (valid_values == NULL) {
1778 DBG_ERR("OOM: failed to make string list from %s\n",
1779 DEFAULT_NAME_RESOLVE_ORDER);
1780 goto out;
1782 values_to_set = str_list_make_v3_const(lp_ctx->globals->ctx,
1783 pszParmValue,
1784 NULL);
1785 if (values_to_set == NULL) {
1786 DBG_ERR("OOM: failed to make string list from %s\n",
1787 pszParmValue);
1788 goto out;
1790 TALLOC_FREE(lp_ctx->globals->name_resolve_order);
1791 for (i = 0; values_to_set[i] != NULL; i++) {
1792 value_is_valid = str_list_check(valid_values, values_to_set[i]);
1793 if (!value_is_valid) {
1794 DBG_ERR("WARNING: Ignoring invalid list value '%s' "
1795 "for parameter 'name resolve order'\n",
1796 values_to_set[i]);
1797 break;
1800 out:
1801 if (value_is_valid) {
1802 lp_ctx->globals->name_resolve_order = values_to_set;
1803 } else {
1804 TALLOC_FREE(values_to_set);
1806 TALLOC_FREE(valid_values);
1807 return value_is_valid;
1810 static bool set_variable(TALLOC_CTX *mem_ctx, struct loadparm_service *service,
1811 int parmnum, void *parm_ptr,
1812 const char *pszParmName, const char *pszParmValue,
1813 struct loadparm_context *lp_ctx, bool on_globals)
1815 int i;
1816 bool ok;
1818 /* if it is a special case then go ahead */
1819 if (parm_table[parmnum].special) {
1820 ok = parm_table[parmnum].special(lp_ctx, service, pszParmValue,
1821 (char **)parm_ptr);
1822 } else {
1823 ok = set_variable_helper(mem_ctx, parmnum, parm_ptr,
1824 pszParmName, pszParmValue);
1827 if (!ok) {
1828 return false;
1831 if (on_globals && (lp_ctx->flags[parmnum] & FLAG_DEFAULT)) {
1832 lp_ctx->flags[parmnum] &= ~FLAG_DEFAULT;
1833 /* we have to also unset FLAG_DEFAULT on aliases */
1834 for (i=parmnum-1;i>=0 && parm_table[i].offset == parm_table[parmnum].offset;i--) {
1835 lp_ctx->flags[i] &= ~FLAG_DEFAULT;
1837 for (i=parmnum+1;i<num_parameters() && parm_table[i].offset == parm_table[parmnum].offset;i++) {
1838 lp_ctx->flags[i] &= ~FLAG_DEFAULT;
1841 return true;
1845 bool lpcfg_do_global_parameter(struct loadparm_context *lp_ctx,
1846 const char *pszParmName, const char *pszParmValue)
1848 int parmnum = lpcfg_map_parameter(pszParmName);
1849 void *parm_ptr;
1851 if (parmnum < 0) {
1852 if (strchr(pszParmName, ':')) {
1853 return lp_do_parameter_parametric(lp_ctx, NULL, pszParmName, pszParmValue, 0);
1855 DEBUG(0, ("Ignoring unknown parameter \"%s\"\n", pszParmName));
1856 return true;
1859 /* if the flag has been set on the command line, then don't allow override,
1860 but don't report an error */
1861 if (lp_ctx->flags[parmnum] & FLAG_CMDLINE) {
1862 return true;
1865 if (parm_table[parmnum].flags & FLAG_DEPRECATED) {
1866 char *suppress_env = getenv("SAMBA_DEPRECATED_SUPPRESS");
1867 bool print_warning = (suppress_env == NULL
1868 || suppress_env[0] == '\0');
1869 if (print_warning) {
1870 DBG_WARNING("WARNING: The \"%s\" option "
1871 "is deprecated\n",
1872 pszParmName);
1877 parm_ptr = lpcfg_parm_ptr(lp_ctx, NULL, &parm_table[parmnum]);
1879 return set_variable(lp_ctx->globals->ctx, NULL, parmnum, parm_ptr,
1880 pszParmName, pszParmValue, lp_ctx, true);
1883 bool lpcfg_do_service_parameter(struct loadparm_context *lp_ctx,
1884 struct loadparm_service *service,
1885 const char *pszParmName, const char *pszParmValue)
1887 void *parm_ptr;
1888 int i;
1889 int parmnum = lpcfg_map_parameter(pszParmName);
1891 if (parmnum < 0) {
1892 if (strchr(pszParmName, ':')) {
1893 return lp_do_parameter_parametric(lp_ctx, service, pszParmName, pszParmValue, 0);
1895 DEBUG(0, ("Ignoring unknown parameter \"%s\"\n", pszParmName));
1896 return true;
1899 /* if the flag has been set on the command line, then don't allow override,
1900 but don't report an error */
1901 if (lp_ctx->flags[parmnum] & FLAG_CMDLINE) {
1902 return true;
1905 if (parm_table[parmnum].flags & FLAG_DEPRECATED) {
1906 char *suppress_env = getenv("SAMBA_DEPRECATED_SUPPRESS");
1907 bool print_warning = (suppress_env == NULL
1908 || suppress_env[0] == '\0');
1909 if (print_warning) {
1910 DBG_WARNING("WARNING: The \"%s\" option "
1911 "is deprecated\n",
1912 pszParmName);
1917 if (parm_table[parmnum].p_class == P_GLOBAL) {
1918 DEBUG(0,
1919 ("Global parameter %s found in service section!\n",
1920 pszParmName));
1921 return true;
1923 parm_ptr = ((char *)service) + parm_table[parmnum].offset;
1925 if (!service->copymap)
1926 init_copymap(service);
1928 /* this handles the aliases - set the copymap for other
1929 * entries with the same data pointer */
1930 for (i = 0; parm_table[i].label; i++)
1931 if (parm_table[i].offset == parm_table[parmnum].offset &&
1932 parm_table[i].p_class == parm_table[parmnum].p_class)
1933 bitmap_clear(service->copymap, i);
1935 return set_variable(service, service, parmnum, parm_ptr, pszParmName,
1936 pszParmValue, lp_ctx, false);
1940 * Process a parameter.
1943 bool lpcfg_do_parameter(const char *pszParmName, const char *pszParmValue,
1944 void *userdata)
1946 struct loadparm_context *lp_ctx = (struct loadparm_context *)userdata;
1948 if (lp_ctx->bInGlobalSection)
1949 return lpcfg_do_global_parameter(lp_ctx, pszParmName,
1950 pszParmValue);
1951 else
1952 return lpcfg_do_service_parameter(lp_ctx, lp_ctx->currentService,
1953 pszParmName, pszParmValue);
1957 variable argument do parameter
1959 bool lpcfg_do_global_parameter_var(struct loadparm_context *lp_ctx, const char *pszParmName, const char *fmt, ...) PRINTF_ATTRIBUTE(3, 4);
1960 bool lpcfg_do_global_parameter_var(struct loadparm_context *lp_ctx,
1961 const char *pszParmName, const char *fmt, ...)
1963 char *s;
1964 bool ret;
1965 va_list ap;
1967 va_start(ap, fmt);
1968 s = talloc_vasprintf(NULL, fmt, ap);
1969 va_end(ap);
1970 ret = lpcfg_do_global_parameter(lp_ctx, pszParmName, s);
1971 talloc_free(s);
1972 return ret;
1977 set a parameter from the commandline - this is called from command line parameter
1978 parsing code. It sets the parameter then marks the parameter as unable to be modified
1979 by smb.conf processing
1981 bool lpcfg_set_cmdline(struct loadparm_context *lp_ctx, const char *pszParmName,
1982 const char *pszParmValue)
1984 int parmnum;
1985 int i;
1987 while (isspace((unsigned char)*pszParmValue)) pszParmValue++;
1989 parmnum = lpcfg_map_parameter(pszParmName);
1991 if (parmnum < 0 && strchr(pszParmName, ':')) {
1992 /* set a parametric option */
1993 bool ok;
1994 ok = lp_do_parameter_parametric(lp_ctx, NULL, pszParmName,
1995 pszParmValue, FLAG_CMDLINE);
1996 if (lp_ctx->s3_fns != NULL) {
1997 if (ok) {
1998 lp_ctx->s3_fns->store_cmdline(pszParmName, pszParmValue);
2001 return ok;
2004 if (parmnum < 0) {
2005 DEBUG(0,("Unknown option '%s'\n", pszParmName));
2006 return false;
2009 /* reset the CMDLINE flag in case this has been called before */
2010 lp_ctx->flags[parmnum] &= ~FLAG_CMDLINE;
2012 if (!lpcfg_do_global_parameter(lp_ctx, pszParmName, pszParmValue)) {
2013 return false;
2016 lp_ctx->flags[parmnum] |= FLAG_CMDLINE;
2018 /* we have to also set FLAG_CMDLINE on aliases */
2019 for (i=parmnum-1;
2020 i>=0 && parm_table[i].p_class == parm_table[parmnum].p_class &&
2021 parm_table[i].offset == parm_table[parmnum].offset;
2022 i--) {
2023 lp_ctx->flags[i] |= FLAG_CMDLINE;
2025 for (i=parmnum+1;
2026 i<num_parameters() &&
2027 parm_table[i].p_class == parm_table[parmnum].p_class &&
2028 parm_table[i].offset == parm_table[parmnum].offset;
2029 i++) {
2030 lp_ctx->flags[i] |= FLAG_CMDLINE;
2033 if (lp_ctx->s3_fns != NULL) {
2034 lp_ctx->s3_fns->store_cmdline(pszParmName, pszParmValue);
2037 return true;
2041 set a option from the commandline in 'a=b' format. Use to support --option
2043 bool lpcfg_set_option(struct loadparm_context *lp_ctx, const char *option)
2045 char *p, *s;
2046 bool ret;
2048 s = talloc_strdup(NULL, option);
2049 if (!s) {
2050 return false;
2053 p = strchr(s, '=');
2054 if (!p) {
2055 talloc_free(s);
2056 return false;
2059 *p = 0;
2061 ret = lpcfg_set_cmdline(lp_ctx, s, p+1);
2062 talloc_free(s);
2063 return ret;
2067 #define BOOLSTR(b) ((b) ? "Yes" : "No")
2070 * Print a parameter of the specified type.
2073 void lpcfg_print_parameter(struct parm_struct *p, void *ptr, FILE * f)
2075 /* For the seperation of lists values that we print below */
2076 const char *list_sep = ", ";
2077 int i;
2078 switch (p->type)
2080 case P_ENUM:
2081 for (i = 0; p->enum_list[i].name; i++) {
2082 if (*(int *)ptr == p->enum_list[i].value) {
2083 fprintf(f, "%s",
2084 p->enum_list[i].name);
2085 break;
2088 break;
2090 case P_BOOL:
2091 fprintf(f, "%s", BOOLSTR(*(bool *)ptr));
2092 break;
2094 case P_BOOLREV:
2095 fprintf(f, "%s", BOOLSTR(!*(bool *)ptr));
2096 break;
2098 case P_INTEGER:
2099 case P_BYTES:
2100 fprintf(f, "%d", *(int *)ptr);
2101 break;
2103 case P_CHAR:
2104 fprintf(f, "%c", *(char *)ptr);
2105 break;
2107 case P_OCTAL: {
2108 int val = *(int *)ptr;
2109 if (val == -1) {
2110 fprintf(f, "-1");
2111 } else {
2112 fprintf(f, "0%03o", val);
2114 break;
2117 case P_CMDLIST:
2118 list_sep = " ";
2120 FALL_THROUGH;
2121 case P_LIST:
2122 if ((char ***)ptr && *(char ***)ptr) {
2123 char **list = *(char ***)ptr;
2124 for (; *list; list++) {
2125 /* surround strings with whitespace in double quotes */
2126 if (*(list+1) == NULL) {
2127 /* last item, no extra separator */
2128 list_sep = "";
2130 if ( strchr_m( *list, ' ' ) ) {
2131 fprintf(f, "\"%s\"%s", *list, list_sep);
2132 } else {
2133 fprintf(f, "%s%s", *list, list_sep);
2137 break;
2139 case P_STRING:
2140 case P_USTRING:
2141 if (*(char **)ptr) {
2142 fprintf(f, "%s", *(char **)ptr);
2144 break;
2149 * Check if two parameters are equal.
2152 static bool lpcfg_equal_parameter(parm_type type, void *ptr1, void *ptr2)
2154 switch (type) {
2155 case P_BOOL:
2156 case P_BOOLREV:
2157 return (*((bool *)ptr1) == *((bool *)ptr2));
2159 case P_INTEGER:
2160 case P_ENUM:
2161 case P_OCTAL:
2162 case P_BYTES:
2163 return (*((int *)ptr1) == *((int *)ptr2));
2165 case P_CHAR:
2166 return (*((char *)ptr1) == *((char *)ptr2));
2168 case P_LIST:
2169 case P_CMDLIST:
2170 return str_list_equal(*(const char ***)ptr1, *(const char ***)ptr2);
2172 case P_STRING:
2173 case P_USTRING:
2175 char *p1 = *(char **)ptr1, *p2 = *(char **)ptr2;
2176 if (p1 && !*p1)
2177 p1 = NULL;
2178 if (p2 && !*p2)
2179 p2 = NULL;
2180 return (p1 == p2 || strequal(p1, p2));
2183 return false;
2187 * Process a new section (service).
2189 * At this stage all sections are services.
2190 * Later we'll have special sections that permit server parameters to be set.
2191 * Returns True on success, False on failure.
2194 static bool do_section(const char *pszSectionName, void *userdata)
2196 struct loadparm_context *lp_ctx = (struct loadparm_context *)userdata;
2197 bool bRetval;
2198 bool isglobal;
2200 if (lp_ctx->s3_fns != NULL) {
2201 return lp_ctx->s3_fns->do_section(pszSectionName, lp_ctx);
2204 isglobal = ((strwicmp(pszSectionName, GLOBAL_NAME) == 0) ||
2205 (strwicmp(pszSectionName, GLOBAL_NAME2) == 0));
2207 /* if we've just struck a global section, note the fact. */
2208 lp_ctx->bInGlobalSection = isglobal;
2210 /* check for multiple global sections */
2211 if (lp_ctx->bInGlobalSection) {
2212 DEBUG(4, ("Processing section \"[%s]\"\n", pszSectionName));
2213 bRetval = true;
2214 goto out;
2217 /* if we have a current service, tidy it up before moving on */
2218 bRetval = true;
2220 if (lp_ctx->currentService != NULL)
2221 bRetval = lpcfg_service_ok(lp_ctx->currentService);
2223 /* if all is still well, move to the next record in the services array */
2224 if (bRetval) {
2225 /* We put this here to avoid an odd message order if messages are */
2226 /* issued by the post-processing of a previous section. */
2227 DEBUG(4, ("Processing section \"[%s]\"\n", pszSectionName));
2229 if ((lp_ctx->currentService = lpcfg_add_service(lp_ctx, lp_ctx->sDefault,
2230 pszSectionName))
2231 == NULL) {
2232 DEBUG(0, ("Failed to add a new service\n"));
2233 bRetval = false;
2234 goto out;
2237 out:
2238 return bRetval;
2243 * Determine if a particular base parameter is currently set to the default value.
2246 static bool is_default(void *base_structure, int i)
2248 void *def_ptr = ((char *)base_structure) + parm_table[i].offset;
2249 switch (parm_table[i].type) {
2250 case P_CMDLIST:
2251 case P_LIST:
2252 return str_list_equal((const char * const *)parm_table[i].def.lvalue,
2253 *(const char * const **)def_ptr);
2254 case P_STRING:
2255 case P_USTRING:
2256 return strequal(parm_table[i].def.svalue,
2257 *(char **)def_ptr);
2258 case P_BOOL:
2259 case P_BOOLREV:
2260 return parm_table[i].def.bvalue ==
2261 *(bool *)def_ptr;
2262 case P_INTEGER:
2263 case P_CHAR:
2264 case P_OCTAL:
2265 case P_BYTES:
2266 case P_ENUM:
2267 return parm_table[i].def.ivalue ==
2268 *(int *)def_ptr;
2270 return false;
2274 *Display the contents of the global structure.
2277 void lpcfg_dump_globals(struct loadparm_context *lp_ctx, FILE *f,
2278 bool show_defaults)
2280 int i;
2281 struct parmlist_entry *data;
2283 fprintf(f, "# Global parameters\n[global]\n");
2285 for (i = 0; parm_table[i].label; i++) {
2286 if (parm_table[i].p_class != P_GLOBAL) {
2287 continue;
2290 if (parm_table[i].flags & FLAG_SYNONYM) {
2291 continue;
2294 if (!show_defaults) {
2295 if (lp_ctx->flags && (lp_ctx->flags[i] & FLAG_DEFAULT)) {
2296 continue;
2299 if (is_default(lp_ctx->globals, i)) {
2300 continue;
2304 fprintf(f, "\t%s = ", parm_table[i].label);
2305 lpcfg_print_parameter(&parm_table[i], lpcfg_parm_ptr(lp_ctx, NULL, &parm_table[i]), f);
2306 fprintf(f, "\n");
2308 if (lp_ctx->globals->param_opt != NULL) {
2309 for (data = lp_ctx->globals->param_opt; data;
2310 data = data->next) {
2311 if (!show_defaults && (data->priority & FLAG_DEFAULT)) {
2312 continue;
2314 fprintf(f, "\t%s = %s\n", data->key, data->value);
2321 * Display the contents of a single services record.
2324 void lpcfg_dump_a_service(struct loadparm_service * pService, struct loadparm_service *sDefault, FILE * f,
2325 unsigned int *flags, bool show_defaults)
2327 int i;
2328 struct parmlist_entry *data;
2330 if (pService != sDefault)
2331 fprintf(f, "\n[%s]\n", pService->szService);
2333 for (i = 0; parm_table[i].label; i++) {
2334 if (parm_table[i].p_class != P_LOCAL) {
2335 continue;
2338 if (parm_table[i].flags & FLAG_SYNONYM) {
2339 continue;
2342 if (*parm_table[i].label == '-') {
2343 continue;
2346 if (pService == sDefault) {
2347 if (!show_defaults) {
2348 if (flags && (flags[i] & FLAG_DEFAULT)) {
2349 continue;
2352 if (is_default(sDefault, i)) {
2353 continue;
2356 } else {
2357 bool equal;
2359 equal = lpcfg_equal_parameter(parm_table[i].type,
2360 ((char *)pService) +
2361 parm_table[i].offset,
2362 ((char *)sDefault) +
2363 parm_table[i].offset);
2364 if (equal) {
2365 continue;
2369 fprintf(f, "\t%s = ", parm_table[i].label);
2370 lpcfg_print_parameter(&parm_table[i],
2371 ((char *)pService) + parm_table[i].offset, f);
2372 fprintf(f, "\n");
2374 if (pService->param_opt != NULL) {
2375 for (data = pService->param_opt; data; data = data->next) {
2376 if (!show_defaults && (data->priority & FLAG_DEFAULT)) {
2377 continue;
2379 fprintf(f, "\t%s = %s\n", data->key, data->value);
2384 bool lpcfg_dump_a_parameter(struct loadparm_context *lp_ctx,
2385 struct loadparm_service *service,
2386 const char *parm_name, FILE * f)
2388 struct parm_struct *parm;
2389 void *ptr;
2390 char *local_parm_name;
2391 char *parm_opt;
2392 const char *parm_opt_value;
2394 /* check for parametrical option */
2395 local_parm_name = talloc_strdup(lp_ctx, parm_name);
2396 if (local_parm_name == NULL) {
2397 return false;
2400 parm_opt = strchr( local_parm_name, ':');
2402 if (parm_opt) {
2403 *parm_opt = '\0';
2404 parm_opt++;
2405 if (strlen(parm_opt)) {
2406 parm_opt_value = lpcfg_parm_string(lp_ctx, service,
2407 local_parm_name, parm_opt);
2408 if (parm_opt_value) {
2409 fprintf(f, "%s\n", parm_opt_value);
2410 return true;
2413 return false;
2416 /* parameter is not parametric, search the table */
2417 parm = lpcfg_parm_struct(lp_ctx, parm_name);
2418 if (!parm) {
2419 return false;
2422 if (service != NULL && parm->p_class == P_GLOBAL) {
2423 return false;
2426 ptr = lpcfg_parm_ptr(lp_ctx, service,parm);
2428 lpcfg_print_parameter(parm, ptr, f);
2429 fprintf(f, "\n");
2430 return true;
2434 * Auto-load some home services.
2436 static void lpcfg_add_auto_services(struct loadparm_context *lp_ctx,
2437 const char *str)
2439 return;
2442 /***************************************************************************
2443 Initialise the sDefault parameter structure for the printer values.
2444 ***************************************************************************/
2446 void init_printer_values(struct loadparm_context *lp_ctx, TALLOC_CTX *ctx,
2447 struct loadparm_service *pService)
2449 /* choose defaults depending on the type of printing */
2450 switch (pService->printing) {
2451 case PRINT_BSD:
2452 case PRINT_AIX:
2453 case PRINT_LPRNT:
2454 case PRINT_LPROS2:
2455 lpcfg_string_set(ctx, &pService->lpq_command, "lpq -P'%p'");
2456 lpcfg_string_set(ctx, &pService->lprm_command, "lprm -P'%p' %j");
2457 lpcfg_string_set(ctx, &pService->print_command, "lpr -r -P'%p' %s");
2458 break;
2460 case PRINT_LPRNG:
2461 case PRINT_PLP:
2462 lpcfg_string_set(ctx, &pService->lpq_command, "lpq -P'%p'");
2463 lpcfg_string_set(ctx, &pService->lprm_command, "lprm -P'%p' %j");
2464 lpcfg_string_set(ctx, &pService->print_command, "lpr -r -P'%p' %s");
2465 lpcfg_string_set(ctx, &pService->queuepause_command, "lpc stop '%p'");
2466 lpcfg_string_set(ctx, &pService->queueresume_command, "lpc start '%p'");
2467 lpcfg_string_set(ctx, &pService->lppause_command, "lpc hold '%p' %j");
2468 lpcfg_string_set(ctx, &pService->lpresume_command, "lpc release '%p' %j");
2469 break;
2471 case PRINT_CUPS:
2472 case PRINT_IPRINT:
2473 /* set the lpq command to contain the destination printer
2474 name only. This is used by cups_queue_get() */
2475 lpcfg_string_set(ctx, &pService->lpq_command, "%p");
2476 lpcfg_string_set(ctx, &pService->lprm_command, "");
2477 lpcfg_string_set(ctx, &pService->print_command, "");
2478 lpcfg_string_set(ctx, &pService->lppause_command, "");
2479 lpcfg_string_set(ctx, &pService->lpresume_command, "");
2480 lpcfg_string_set(ctx, &pService->queuepause_command, "");
2481 lpcfg_string_set(ctx, &pService->queueresume_command, "");
2482 break;
2484 case PRINT_SYSV:
2485 case PRINT_HPUX:
2486 lpcfg_string_set(ctx, &pService->lpq_command, "lpstat -o%p");
2487 lpcfg_string_set(ctx, &pService->lprm_command, "cancel %p-%j");
2488 lpcfg_string_set(ctx, &pService->print_command, "lp -c -d%p %s; rm %s");
2489 lpcfg_string_set(ctx, &pService->queuepause_command, "disable %p");
2490 lpcfg_string_set(ctx, &pService->queueresume_command, "enable %p");
2491 #ifndef HPUX
2492 lpcfg_string_set(ctx, &pService->lppause_command, "lp -i %p-%j -H hold");
2493 lpcfg_string_set(ctx, &pService->lpresume_command, "lp -i %p-%j -H resume");
2494 #endif /* HPUX */
2495 break;
2497 case PRINT_QNX:
2498 lpcfg_string_set(ctx, &pService->lpq_command, "lpq -P%p");
2499 lpcfg_string_set(ctx, &pService->lprm_command, "lprm -P%p %j");
2500 lpcfg_string_set(ctx, &pService->print_command, "lp -r -P%p %s");
2501 break;
2503 #if defined(DEVELOPER) || defined(ENABLE_SELFTEST)
2505 case PRINT_TEST:
2506 case PRINT_VLP: {
2507 const char *tdbfile;
2508 TALLOC_CTX *tmp_ctx = talloc_new(ctx);
2509 const char *tmp;
2511 tmp = lpcfg_parm_string(lp_ctx, NULL, "vlp", "tdbfile");
2512 if (tmp == NULL) {
2513 tmp = "/tmp/vlp.tdb";
2516 tdbfile = talloc_asprintf(tmp_ctx, "tdbfile=%s", tmp);
2517 if (tdbfile == NULL) {
2518 tdbfile="tdbfile=/tmp/vlp.tdb";
2521 tmp = talloc_asprintf(tmp_ctx, "vlp %s print %%p %%s",
2522 tdbfile);
2523 lpcfg_string_set(ctx, &pService->print_command,
2524 tmp ? tmp : "vlp print %p %s");
2526 tmp = talloc_asprintf(tmp_ctx, "vlp %s lpq %%p",
2527 tdbfile);
2528 lpcfg_string_set(ctx, &pService->lpq_command,
2529 tmp ? tmp : "vlp lpq %p");
2531 tmp = talloc_asprintf(tmp_ctx, "vlp %s lprm %%p %%j",
2532 tdbfile);
2533 lpcfg_string_set(ctx, &pService->lprm_command,
2534 tmp ? tmp : "vlp lprm %p %j");
2536 tmp = talloc_asprintf(tmp_ctx, "vlp %s lppause %%p %%j",
2537 tdbfile);
2538 lpcfg_string_set(ctx, &pService->lppause_command,
2539 tmp ? tmp : "vlp lppause %p %j");
2541 tmp = talloc_asprintf(tmp_ctx, "vlp %s lpresume %%p %%j",
2542 tdbfile);
2543 lpcfg_string_set(ctx, &pService->lpresume_command,
2544 tmp ? tmp : "vlp lpresume %p %j");
2546 tmp = talloc_asprintf(tmp_ctx, "vlp %s queuepause %%p",
2547 tdbfile);
2548 lpcfg_string_set(ctx, &pService->queuepause_command,
2549 tmp ? tmp : "vlp queuepause %p");
2551 tmp = talloc_asprintf(tmp_ctx, "vlp %s queueresume %%p",
2552 tdbfile);
2553 lpcfg_string_set(ctx, &pService->queueresume_command,
2554 tmp ? tmp : "vlp queueresume %p");
2555 TALLOC_FREE(tmp_ctx);
2557 break;
2559 #endif /* DEVELOPER */
2565 * Unload unused services.
2568 void lpcfg_killunused(struct loadparm_context *lp_ctx,
2569 struct smbsrv_connection *smb,
2570 bool (*snumused) (struct smbsrv_connection *, int))
2572 int i;
2574 if (lp_ctx->s3_fns != NULL) {
2575 smb_panic("Cannot be used from an s3 loadparm ctx");
2578 for (i = 0; i < lp_ctx->iNumServices; i++) {
2579 if (lp_ctx->services[i] == NULL)
2580 continue;
2582 if (!snumused || !snumused(smb, i)) {
2583 talloc_free(lp_ctx->services[i]);
2584 lp_ctx->services[i] = NULL;
2590 static int lpcfg_destructor(struct loadparm_context *lp_ctx)
2592 struct parmlist_entry *data;
2594 if (lp_ctx->refuse_free) {
2595 /* someone is trying to free the
2596 global_loadparm_context.
2597 We can't allow that. */
2598 return -1;
2601 if (lp_ctx->globals->param_opt != NULL) {
2602 struct parmlist_entry *next;
2603 for (data = lp_ctx->globals->param_opt; data; data=next) {
2604 next = data->next;
2605 if (data->priority & FLAG_CMDLINE) continue;
2606 DLIST_REMOVE(lp_ctx->globals->param_opt, data);
2607 talloc_free(data);
2611 return 0;
2615 * Initialise the global parameter structure.
2617 * Note that most callers should use loadparm_init_global() instead
2619 struct loadparm_context *loadparm_init(TALLOC_CTX *mem_ctx)
2621 int i;
2622 char *myname;
2623 struct loadparm_context *lp_ctx;
2624 struct parmlist_entry *parm;
2625 char *logfile;
2627 lp_ctx = talloc_zero(mem_ctx, struct loadparm_context);
2628 if (lp_ctx == NULL)
2629 return NULL;
2631 talloc_set_destructor(lp_ctx, lpcfg_destructor);
2632 lp_ctx->bInGlobalSection = true;
2633 lp_ctx->globals = talloc_zero(lp_ctx, struct loadparm_global);
2634 /* This appears odd, but globals in s3 isn't a pointer */
2635 lp_ctx->globals->ctx = lp_ctx->globals;
2636 lp_ctx->globals->rpc_low_port = SERVER_TCP_LOW_PORT;
2637 lp_ctx->globals->rpc_high_port = SERVER_TCP_HIGH_PORT;
2638 lp_ctx->globals->weak_crypto = SAMBA_WEAK_CRYPTO_UNKNOWN;
2639 lp_ctx->sDefault = talloc_zero(lp_ctx, struct loadparm_service);
2640 lp_ctx->flags = talloc_zero_array(lp_ctx, unsigned int, num_parameters());
2642 lp_ctx->sDefault->max_print_jobs = 1000;
2643 lp_ctx->sDefault->available = true;
2644 lp_ctx->sDefault->browseable = true;
2645 lp_ctx->sDefault->read_only = true;
2646 lp_ctx->sDefault->map_archive = true;
2647 lp_ctx->sDefault->strict_locking = true;
2648 lp_ctx->sDefault->oplocks = true;
2649 lp_ctx->sDefault->create_mask = 0744;
2650 lp_ctx->sDefault->force_create_mode = 0000;
2651 lp_ctx->sDefault->directory_mask = 0755;
2652 lp_ctx->sDefault->force_directory_mode = 0000;
2653 lp_ctx->sDefault->aio_read_size = 1;
2654 lp_ctx->sDefault->aio_write_size = 1;
2655 lp_ctx->sDefault->smbd_search_ask_sharemode = true;
2656 lp_ctx->sDefault->smbd_getinfo_ask_sharemode = true;
2658 DEBUG(3, ("Initialising global parameters\n"));
2660 for (i = 0; parm_table[i].label; i++) {
2661 if ((parm_table[i].type == P_STRING ||
2662 parm_table[i].type == P_USTRING) &&
2663 !(lp_ctx->flags[i] & FLAG_CMDLINE)) {
2664 TALLOC_CTX *parent_mem;
2665 char **r;
2666 if (parm_table[i].p_class == P_LOCAL) {
2667 parent_mem = lp_ctx->sDefault;
2668 r = (char **)(((char *)lp_ctx->sDefault) + parm_table[i].offset);
2669 } else {
2670 parent_mem = lp_ctx->globals;
2671 r = (char **)(((char *)lp_ctx->globals) + parm_table[i].offset);
2673 lpcfg_string_set(parent_mem, r, "");
2677 logfile = talloc_asprintf(lp_ctx, "%s/log.samba", dyn_LOGFILEBASE);
2678 lpcfg_do_global_parameter(lp_ctx, "log file", logfile);
2679 talloc_free(logfile);
2681 lpcfg_do_global_parameter(lp_ctx, "log level", "0");
2683 lpcfg_do_global_parameter(lp_ctx, "syslog", "1");
2684 lpcfg_do_global_parameter(lp_ctx, "syslog only", "No");
2685 lpcfg_do_global_parameter(lp_ctx, "debug timestamp", "Yes");
2686 lpcfg_do_global_parameter(lp_ctx, "debug prefix timestamp", "No");
2687 lpcfg_do_global_parameter(lp_ctx, "debug hires timestamp", "Yes");
2688 lpcfg_do_global_parameter(lp_ctx, "debug pid", "No");
2689 lpcfg_do_global_parameter(lp_ctx, "debug uid", "No");
2690 lpcfg_do_global_parameter(lp_ctx, "debug class", "No");
2692 lpcfg_do_global_parameter(lp_ctx, "share backend", "classic");
2694 lpcfg_do_global_parameter(lp_ctx, "server role", "auto");
2695 lpcfg_do_global_parameter(lp_ctx, "domain logons", "No");
2696 lpcfg_do_global_parameter(lp_ctx, "domain master", "Auto");
2698 /* options that can be set on the command line must be initialised via
2699 the slower lpcfg_do_global_parameter() to ensure that FLAG_CMDLINE is obeyed */
2700 #ifdef TCP_NODELAY
2701 lpcfg_do_global_parameter(lp_ctx, "socket options", "TCP_NODELAY");
2702 #endif
2703 lpcfg_do_global_parameter(lp_ctx, "workgroup", DEFAULT_WORKGROUP);
2704 myname = get_myname(lp_ctx);
2705 lpcfg_do_global_parameter(lp_ctx, "netbios name", myname);
2706 talloc_free(myname);
2707 lpcfg_do_global_parameter(lp_ctx,
2708 "name resolve order",
2709 DEFAULT_NAME_RESOLVE_ORDER);
2711 lpcfg_do_global_parameter(lp_ctx, "fstype", "NTFS");
2713 lpcfg_do_global_parameter(lp_ctx, "ntvfs handler", "unixuid default");
2714 lpcfg_do_global_parameter(lp_ctx, "max connections", "0");
2716 lpcfg_do_global_parameter(lp_ctx, "dcerpc endpoint servers", "epmapper wkssvc rpcecho samr netlogon lsarpc drsuapi dssetup unixinfo browser eventlog6 backupkey dnsserver");
2717 lpcfg_do_global_parameter(lp_ctx, "server services", "s3fs rpc nbt wrepl ldap cldap kdc drepl winbindd ntp_signd kcc dnsupdate dns");
2718 lpcfg_do_global_parameter(lp_ctx, "kccsrv:samba_kcc", "true");
2719 /* the winbind method for domain controllers is for both RODC
2720 auth forwarding and for trusted domains */
2721 lpcfg_do_global_parameter(lp_ctx, "private dir", dyn_PRIVATE_DIR);
2722 lpcfg_do_global_parameter(lp_ctx, "binddns dir", dyn_BINDDNS_DIR);
2723 lpcfg_do_global_parameter(lp_ctx, "registry:HKEY_LOCAL_MACHINE", "hklm.ldb");
2725 /* This hive should be dynamically generated by Samba using
2726 data from the sam, but for the moment leave it in a tdb to
2727 keep regedt32 from popping up an annoying dialog. */
2728 lpcfg_do_global_parameter(lp_ctx, "registry:HKEY_USERS", "hku.ldb");
2730 /* using UTF8 by default allows us to support all chars */
2731 lpcfg_do_global_parameter(lp_ctx, "unix charset", "UTF-8");
2733 /* Use codepage 850 as a default for the dos character set */
2734 lpcfg_do_global_parameter(lp_ctx, "dos charset", "CP850");
2737 * Allow the default PASSWD_CHAT to be overridden in local.h.
2739 lpcfg_do_global_parameter(lp_ctx, "passwd chat", DEFAULT_PASSWD_CHAT);
2741 lpcfg_do_global_parameter(lp_ctx, "pid directory", dyn_PIDDIR);
2742 lpcfg_do_global_parameter(lp_ctx, "lock dir", dyn_LOCKDIR);
2743 lpcfg_do_global_parameter(lp_ctx, "state directory", dyn_STATEDIR);
2744 lpcfg_do_global_parameter(lp_ctx, "cache directory", dyn_CACHEDIR);
2745 lpcfg_do_global_parameter(lp_ctx, "ncalrpc dir", dyn_NCALRPCDIR);
2747 lpcfg_do_global_parameter(lp_ctx, "nbt client socket address", "0.0.0.0");
2748 lpcfg_do_global_parameter_var(lp_ctx, "server string",
2749 "Samba %s", SAMBA_VERSION_STRING);
2751 lpcfg_do_global_parameter(lp_ctx, "password server", "*");
2753 lpcfg_do_global_parameter(lp_ctx, "max mux", "50");
2754 lpcfg_do_global_parameter(lp_ctx, "max xmit", "16644");
2755 lpcfg_do_global_parameter(lp_ctx, "host msdfs", "true");
2757 lpcfg_do_global_parameter(lp_ctx, "LargeReadwrite", "True");
2758 lpcfg_do_global_parameter(lp_ctx, "server min protocol", "SMB2_02");
2759 lpcfg_do_global_parameter(lp_ctx, "server max protocol", "SMB3");
2760 lpcfg_do_global_parameter(lp_ctx, "client min protocol", "SMB2_02");
2761 lpcfg_do_global_parameter(lp_ctx, "client max protocol", "default");
2762 lpcfg_do_global_parameter(lp_ctx, "client ipc min protocol", "default");
2763 lpcfg_do_global_parameter(lp_ctx, "client ipc max protocol", "default");
2764 lpcfg_do_global_parameter(lp_ctx, "security", "AUTO");
2765 lpcfg_do_global_parameter(lp_ctx, "EncryptPasswords", "True");
2766 lpcfg_do_global_parameter(lp_ctx, "ReadRaw", "True");
2767 lpcfg_do_global_parameter(lp_ctx, "WriteRaw", "True");
2768 lpcfg_do_global_parameter(lp_ctx, "NullPasswords", "False");
2769 lpcfg_do_global_parameter(lp_ctx, "old password allowed period", "60");
2770 lpcfg_do_global_parameter(lp_ctx, "ObeyPamRestrictions", "False");
2772 lpcfg_do_global_parameter(lp_ctx, "TimeServer", "False");
2773 lpcfg_do_global_parameter(lp_ctx, "BindInterfacesOnly", "False");
2774 lpcfg_do_global_parameter(lp_ctx, "Unicode", "True");
2775 lpcfg_do_global_parameter(lp_ctx, "ClientLanManAuth", "False");
2776 lpcfg_do_global_parameter(lp_ctx, "ClientNTLMv2Auth", "True");
2777 lpcfg_do_global_parameter(lp_ctx, "LanmanAuth", "False");
2778 lpcfg_do_global_parameter(lp_ctx, "NTLMAuth", "ntlmv2-only");
2779 lpcfg_do_global_parameter(lp_ctx, "RawNTLMv2Auth", "False");
2780 lpcfg_do_global_parameter(lp_ctx, "client use spnego principal", "False");
2782 lpcfg_do_global_parameter(lp_ctx, "allow dcerpc auth level connect", "False");
2784 lpcfg_do_global_parameter(lp_ctx, "UnixExtensions", "True");
2786 lpcfg_do_global_parameter(lp_ctx, "PreferredMaster", "Auto");
2787 lpcfg_do_global_parameter(lp_ctx, "LocalMaster", "True");
2789 lpcfg_do_global_parameter(lp_ctx, "wins support", "False");
2790 lpcfg_do_global_parameter(lp_ctx, "dns proxy", "True");
2792 lpcfg_do_global_parameter(lp_ctx, "winbind separator", "\\");
2793 lpcfg_do_global_parameter(lp_ctx, "winbind sealed pipes", "True");
2794 lpcfg_do_global_parameter(lp_ctx, "winbind scan trusted domains", "True");
2795 lpcfg_do_global_parameter(lp_ctx, "require strong key", "True");
2796 lpcfg_do_global_parameter(lp_ctx, "winbindd socket directory", dyn_WINBINDD_SOCKET_DIR);
2797 lpcfg_do_global_parameter(lp_ctx, "ntp signd socket directory", dyn_NTP_SIGND_SOCKET_DIR);
2798 lpcfg_do_global_parameter_var(lp_ctx, "gpo update command", "%s/samba-gpupdate", dyn_SCRIPTSBINDIR);
2799 lpcfg_do_global_parameter_var(lp_ctx, "apply group policies", "False");
2800 lpcfg_do_global_parameter_var(lp_ctx, "dns update command", "%s/samba_dnsupdate", dyn_SCRIPTSBINDIR);
2801 lpcfg_do_global_parameter_var(lp_ctx, "spn update command", "%s/samba_spnupdate", dyn_SCRIPTSBINDIR);
2802 lpcfg_do_global_parameter_var(lp_ctx, "samba kcc command",
2803 "%s/samba_kcc", dyn_SCRIPTSBINDIR);
2804 #ifdef MIT_KDC_PATH
2805 lpcfg_do_global_parameter_var(lp_ctx,
2806 "mit kdc command",
2807 MIT_KDC_PATH);
2808 #endif
2809 lpcfg_do_global_parameter(lp_ctx, "template shell", "/bin/false");
2810 lpcfg_do_global_parameter(lp_ctx, "template homedir", "/home/%D/%U");
2812 lpcfg_do_global_parameter(lp_ctx, "client signing", "default");
2813 lpcfg_do_global_parameter(lp_ctx, "client ipc signing", "default");
2814 lpcfg_do_global_parameter(lp_ctx, "server signing", "default");
2816 lpcfg_do_global_parameter(lp_ctx, "use mmap", "True");
2818 lpcfg_do_global_parameter(lp_ctx, "smb ports", "445 139");
2819 lpcfg_do_global_parameter_var(lp_ctx, "nbt port", "%d", NBT_NAME_SERVICE_PORT);
2820 lpcfg_do_global_parameter_var(lp_ctx, "dgram port", "%d", NBT_DGRAM_SERVICE_PORT);
2821 lpcfg_do_global_parameter(lp_ctx, "cldap port", "389");
2822 lpcfg_do_global_parameter(lp_ctx, "krb5 port", "88");
2823 lpcfg_do_global_parameter(lp_ctx, "kpasswd port", "464");
2825 lpcfg_do_global_parameter(lp_ctx, "nt status support", "True");
2827 lpcfg_do_global_parameter(lp_ctx, "max wins ttl", "518400"); /* 6 days */
2828 lpcfg_do_global_parameter(lp_ctx, "min wins ttl", "21600");
2830 lpcfg_do_global_parameter(lp_ctx, "tls enabled", "True");
2831 lpcfg_do_global_parameter(lp_ctx, "tls verify peer", "as_strict_as_possible");
2832 lpcfg_do_global_parameter(lp_ctx, "tls keyfile", "tls/key.pem");
2833 lpcfg_do_global_parameter(lp_ctx, "tls certfile", "tls/cert.pem");
2834 lpcfg_do_global_parameter(lp_ctx, "tls cafile", "tls/ca.pem");
2835 lpcfg_do_global_parameter(lp_ctx,
2836 "tls priority",
2837 "NORMAL:-VERS-SSL3.0");
2839 lpcfg_do_global_parameter(lp_ctx, "nsupdate command", "/usr/bin/nsupdate -g");
2841 lpcfg_do_global_parameter(lp_ctx, "allow dns updates", "secure only");
2842 lpcfg_do_global_parameter(lp_ctx, "dns zone scavenging", "False");
2843 lpcfg_do_global_parameter(lp_ctx, "dns forwarder", "");
2845 lpcfg_do_global_parameter(lp_ctx, "algorithmic rid base", "1000");
2847 lpcfg_do_global_parameter(lp_ctx, "enhanced browsing", "True");
2849 lpcfg_do_global_parameter(lp_ctx, "winbind nss info", "template");
2851 lpcfg_do_global_parameter(lp_ctx, "server schannel", "True");
2853 lpcfg_do_global_parameter(lp_ctx, "short preserve case", "True");
2855 lpcfg_do_global_parameter(lp_ctx, "max open files", "16384");
2857 lpcfg_do_global_parameter(lp_ctx, "cups connection timeout", "30");
2859 lpcfg_do_global_parameter(lp_ctx, "locking", "True");
2861 lpcfg_do_global_parameter(lp_ctx, "block size", "1024");
2863 lpcfg_do_global_parameter(lp_ctx, "client use spnego", "True");
2865 lpcfg_do_global_parameter(lp_ctx, "change notify", "True");
2867 lpcfg_do_global_parameter(lp_ctx, "name cache timeout", "660");
2869 lpcfg_do_global_parameter(lp_ctx, "defer sharing violations", "True");
2871 lpcfg_do_global_parameter(lp_ctx, "ldap replication sleep", "1000");
2873 lpcfg_do_global_parameter(lp_ctx, "idmap backend", "tdb");
2875 lpcfg_do_global_parameter(lp_ctx, "enable privileges", "True");
2877 lpcfg_do_global_parameter_var(lp_ctx, "smb2 max write", "%u", DEFAULT_SMB2_MAX_WRITE);
2879 lpcfg_do_global_parameter(lp_ctx, "passdb backend", "tdbsam");
2881 lpcfg_do_global_parameter(lp_ctx, "deadtime", "10080");
2883 lpcfg_do_global_parameter(lp_ctx, "getwd cache", "True");
2885 lpcfg_do_global_parameter(lp_ctx, "winbind nested groups", "True");
2887 lpcfg_do_global_parameter(lp_ctx, "mangled names", "illegal");
2889 lpcfg_do_global_parameter_var(lp_ctx, "smb2 max credits", "%u", DEFAULT_SMB2_MAX_CREDITS);
2891 lpcfg_do_global_parameter(lp_ctx, "ldap ssl", "start tls");
2893 lpcfg_do_global_parameter(lp_ctx, "ldap deref", "auto");
2895 lpcfg_do_global_parameter(lp_ctx, "lm interval", "60");
2897 lpcfg_do_global_parameter(lp_ctx, "mangling method", "hash2");
2899 lpcfg_do_global_parameter(lp_ctx, "hide dot files", "True");
2901 lpcfg_do_global_parameter(lp_ctx, "browse list", "True");
2903 lpcfg_do_global_parameter(lp_ctx, "passwd chat timeout", "2");
2905 lpcfg_do_global_parameter(lp_ctx, "guest account", GUEST_ACCOUNT);
2907 lpcfg_do_global_parameter(lp_ctx, "client schannel", "True");
2909 lpcfg_do_global_parameter(lp_ctx, "smb encrypt", "default");
2911 lpcfg_do_global_parameter(lp_ctx, "max log size", "5000");
2913 lpcfg_do_global_parameter(lp_ctx, "idmap negative cache time", "120");
2915 lpcfg_do_global_parameter(lp_ctx, "ldap follow referral", "auto");
2917 lpcfg_do_global_parameter(lp_ctx, "multicast dns register", "yes");
2919 lpcfg_do_global_parameter(lp_ctx, "winbind reconnect delay", "30");
2921 lpcfg_do_global_parameter(lp_ctx, "winbind request timeout", "60");
2923 lpcfg_do_global_parameter(lp_ctx, "nt acl support", "yes");
2925 lpcfg_do_global_parameter(lp_ctx, "acl check permissions", "yes");
2927 lpcfg_do_global_parameter(lp_ctx, "keepalive", "300");
2929 lpcfg_do_global_parameter(lp_ctx, "smbd profiling level", "off");
2931 lpcfg_do_global_parameter(lp_ctx, "winbind cache time", "300");
2933 lpcfg_do_global_parameter(lp_ctx, "level2 oplocks", "yes");
2935 lpcfg_do_global_parameter(lp_ctx, "show add printer wizard", "yes");
2937 lpcfg_do_global_parameter(lp_ctx, "ldap page size", "1000");
2939 lpcfg_do_global_parameter(lp_ctx, "kernel share modes", "yes");
2941 lpcfg_do_global_parameter(lp_ctx, "strict locking", "Auto");
2943 lpcfg_do_global_parameter(lp_ctx, "strict sync", "yes");
2945 lpcfg_do_global_parameter(lp_ctx, "map readonly", "no");
2947 lpcfg_do_global_parameter(lp_ctx, "allow trusted domains", "yes");
2949 lpcfg_do_global_parameter(lp_ctx, "default devmode", "yes");
2951 lpcfg_do_global_parameter(lp_ctx, "os level", "20");
2953 lpcfg_do_global_parameter(lp_ctx, "dos filetimes", "yes");
2955 lpcfg_do_global_parameter(lp_ctx, "mangling char", "~");
2957 lpcfg_do_global_parameter(lp_ctx, "printcap cache time", "750");
2959 lpcfg_do_global_parameter(lp_ctx, "create krb5 conf", "yes");
2961 lpcfg_do_global_parameter(lp_ctx, "winbind max clients", "200");
2963 lpcfg_do_global_parameter(lp_ctx, "acl map full control", "yes");
2965 lpcfg_do_global_parameter(lp_ctx, "nt pipe support", "yes");
2967 lpcfg_do_global_parameter(lp_ctx, "ldap debug threshold", "10");
2969 lpcfg_do_global_parameter(lp_ctx, "client ldap sasl wrapping", "sign");
2971 lpcfg_do_global_parameter(lp_ctx, "mdns name", "netbios");
2973 lpcfg_do_global_parameter(lp_ctx, "ldap server require strong auth", "yes");
2975 lpcfg_do_global_parameter(lp_ctx, "follow symlinks", "yes");
2977 lpcfg_do_global_parameter(lp_ctx, "machine password timeout", "604800");
2979 lpcfg_do_global_parameter(lp_ctx, "ldap connection timeout", "2");
2981 lpcfg_do_global_parameter(lp_ctx, "winbind expand groups", "0");
2983 lpcfg_do_global_parameter(lp_ctx, "stat cache", "yes");
2985 lpcfg_do_global_parameter(lp_ctx, "lpq cache time", "30");
2987 lpcfg_do_global_parameter_var(lp_ctx, "smb2 max trans", "%u", DEFAULT_SMB2_MAX_TRANSACT);
2989 lpcfg_do_global_parameter_var(lp_ctx, "smb2 max read", "%u", DEFAULT_SMB2_MAX_READ);
2991 lpcfg_do_global_parameter(lp_ctx, "durable handles", "yes");
2993 lpcfg_do_global_parameter(lp_ctx, "max stat cache size", "512");
2995 lpcfg_do_global_parameter(lp_ctx, "ldap passwd sync", "no");
2997 lpcfg_do_global_parameter(lp_ctx, "kernel change notify", "yes");
2999 lpcfg_do_global_parameter(lp_ctx, "max ttl", "259200");
3001 lpcfg_do_global_parameter(lp_ctx, "blocking locks", "yes");
3003 lpcfg_do_global_parameter(lp_ctx, "load printers", "yes");
3005 lpcfg_do_global_parameter(lp_ctx, "idmap cache time", "604800");
3007 lpcfg_do_global_parameter(lp_ctx, "preserve case", "yes");
3009 lpcfg_do_global_parameter(lp_ctx, "lm announce", "auto");
3011 lpcfg_do_global_parameter(lp_ctx, "afs token lifetime", "604800");
3013 lpcfg_do_global_parameter(lp_ctx, "enable core files", "yes");
3015 lpcfg_do_global_parameter(lp_ctx, "winbind max domain connections", "1");
3017 lpcfg_do_global_parameter(lp_ctx, "case sensitive", "auto");
3019 lpcfg_do_global_parameter(lp_ctx, "ldap timeout", "15");
3021 lpcfg_do_global_parameter(lp_ctx, "mangle prefix", "1");
3023 lpcfg_do_global_parameter(lp_ctx, "posix locking", "yes");
3025 lpcfg_do_global_parameter(lp_ctx, "lock spin time", "200");
3027 lpcfg_do_global_parameter(lp_ctx, "directory name cache size", "100");
3029 lpcfg_do_global_parameter(lp_ctx, "nmbd bind explicit broadcast", "yes");
3031 lpcfg_do_global_parameter(lp_ctx, "init logon delay", "100");
3033 lpcfg_do_global_parameter(lp_ctx, "usershare owner only", "yes");
3035 lpcfg_do_global_parameter(lp_ctx, "-valid", "yes");
3037 lpcfg_do_global_parameter_var(lp_ctx, "usershare path", "%s/usershares", get_dyn_STATEDIR());
3039 #ifdef DEVELOPER
3040 lpcfg_do_global_parameter_var(lp_ctx, "panic action", "/bin/sleep 999999999");
3041 #endif
3043 lpcfg_do_global_parameter(lp_ctx, "smb passwd file", get_dyn_SMB_PASSWD_FILE());
3045 lpcfg_do_global_parameter(lp_ctx, "logon home", "\\\\%N\\%U");
3047 lpcfg_do_global_parameter(lp_ctx, "logon path", "\\\\%N\\%U\\profile");
3049 lpcfg_do_global_parameter(lp_ctx, "printjob username", "%U");
3051 lpcfg_do_global_parameter(lp_ctx, "aio max threads", "100");
3053 lpcfg_do_global_parameter(lp_ctx, "smb2 leases", "yes");
3055 lpcfg_do_global_parameter(lp_ctx, "kerberos encryption types", "all");
3057 lpcfg_do_global_parameter(lp_ctx,
3058 "rpc server dynamic port range",
3059 "49152-65535");
3061 lpcfg_do_global_parameter(lp_ctx, "prefork children", "4");
3062 lpcfg_do_global_parameter(lp_ctx, "prefork backoff increment", "10");
3063 lpcfg_do_global_parameter(lp_ctx, "prefork maximum backoff", "120");
3065 lpcfg_do_global_parameter(lp_ctx, "check parent directory delete on close", "no");
3067 lpcfg_do_global_parameter(lp_ctx, "ea support", "yes");
3069 lpcfg_do_global_parameter(lp_ctx, "store dos attributes", "yes");
3071 lpcfg_do_global_parameter(lp_ctx, "debug encryption", "no");
3073 lpcfg_do_global_parameter(lp_ctx, "spotlight backend", "noindex");
3075 lpcfg_do_global_parameter(
3076 lp_ctx, "ldap max anonymous request size", "256000");
3077 lpcfg_do_global_parameter(
3078 lp_ctx, "ldap max authenticated request size", "16777216");
3079 lpcfg_do_global_parameter(
3080 lp_ctx, "ldap max search request size", "256000");
3082 for (i = 0; parm_table[i].label; i++) {
3083 if (!(lp_ctx->flags[i] & FLAG_CMDLINE)) {
3084 lp_ctx->flags[i] |= FLAG_DEFAULT;
3088 for (parm=lp_ctx->globals->param_opt; parm; parm=parm->next) {
3089 if (!(parm->priority & FLAG_CMDLINE)) {
3090 parm->priority |= FLAG_DEFAULT;
3094 for (parm=lp_ctx->sDefault->param_opt; parm; parm=parm->next) {
3095 if (!(parm->priority & FLAG_CMDLINE)) {
3096 parm->priority |= FLAG_DEFAULT;
3100 return lp_ctx;
3104 * Initialise the global parameter structure.
3106 struct loadparm_context *loadparm_init_global(bool load_default)
3108 if (global_loadparm_context == NULL) {
3109 global_loadparm_context = loadparm_init(NULL);
3111 if (global_loadparm_context == NULL) {
3112 return NULL;
3114 global_loadparm_context->global = true;
3115 if (load_default && !global_loadparm_context->loaded) {
3116 lpcfg_load_default(global_loadparm_context);
3118 global_loadparm_context->refuse_free = true;
3119 return global_loadparm_context;
3123 * Initialise the global parameter structure.
3125 struct loadparm_context *loadparm_init_s3(TALLOC_CTX *mem_ctx,
3126 const struct loadparm_s3_helpers *s3_fns)
3128 struct loadparm_context *loadparm_context = talloc_zero(mem_ctx, struct loadparm_context);
3129 if (!loadparm_context) {
3130 return NULL;
3132 loadparm_context->s3_fns = s3_fns;
3133 loadparm_context->globals = s3_fns->globals;
3134 loadparm_context->flags = s3_fns->flags;
3136 return loadparm_context;
3139 const char *lpcfg_configfile(struct loadparm_context *lp_ctx)
3141 return lp_ctx->szConfigFile;
3144 const char *lp_default_path(void)
3146 if (getenv("SMB_CONF_PATH"))
3147 return getenv("SMB_CONF_PATH");
3148 else
3149 return dyn_CONFIGFILE;
3153 * Update the internal state of a loadparm context after settings
3154 * have changed.
3156 static bool lpcfg_update(struct loadparm_context *lp_ctx)
3158 struct debug_settings settings;
3159 int max_protocol, min_protocol;
3160 TALLOC_CTX *tmp_ctx;
3161 const struct loadparm_substitution *lp_sub =
3162 lpcfg_noop_substitution();
3164 tmp_ctx = talloc_new(lp_ctx);
3165 if (tmp_ctx == NULL) {
3166 return false;
3169 lpcfg_add_auto_services(lp_ctx, lpcfg_auto_services(lp_ctx, lp_sub, tmp_ctx));
3171 if (!lp_ctx->globals->wins_server_list && lp_ctx->globals->we_are_a_wins_server) {
3172 lpcfg_do_global_parameter(lp_ctx, "wins server", "127.0.0.1");
3175 if (!lp_ctx->global) {
3176 TALLOC_FREE(tmp_ctx);
3177 return true;
3180 panic_action = lp_ctx->globals->panic_action;
3182 reload_charcnv(lp_ctx);
3184 ZERO_STRUCT(settings);
3185 /* Add any more debug-related smb.conf parameters created in
3186 * future here */
3187 settings.timestamp_logs = lp_ctx->globals->timestamp_logs;
3188 settings.debug_prefix_timestamp = lp_ctx->globals->debug_prefix_timestamp;
3189 settings.debug_hires_timestamp = lp_ctx->globals->debug_hires_timestamp;
3190 settings.debug_pid = lp_ctx->globals->debug_pid;
3191 settings.debug_uid = lp_ctx->globals->debug_uid;
3192 settings.debug_class = lp_ctx->globals->debug_class;
3193 settings.max_log_size = lp_ctx->globals->max_log_size;
3194 debug_set_settings(&settings, lp_ctx->globals->logging,
3195 lp_ctx->globals->syslog,
3196 lp_ctx->globals->syslog_only);
3198 /* FIXME: This is a bit of a hack, but we can't use a global, since
3199 * not everything that uses lp also uses the socket library */
3200 if (lpcfg_parm_bool(lp_ctx, NULL, "socket", "testnonblock", false)) {
3201 setenv("SOCKET_TESTNONBLOCK", "1", 1);
3202 } else {
3203 unsetenv("SOCKET_TESTNONBLOCK");
3206 /* Check if command line max protocol < min protocol, if so
3207 * report a warning to the user.
3209 max_protocol = lpcfg_client_max_protocol(lp_ctx);
3210 min_protocol = lpcfg_client_min_protocol(lp_ctx);
3211 if (lpcfg_client_max_protocol(lp_ctx) < lpcfg_client_min_protocol(lp_ctx)) {
3212 const char *max_protocolp, *min_protocolp;
3213 max_protocolp = lpcfg_get_smb_protocol(max_protocol);
3214 min_protocolp = lpcfg_get_smb_protocol(min_protocol);
3215 DBG_ERR("Max protocol %s is less than min protocol %s.\n",
3216 max_protocolp, min_protocolp);
3219 TALLOC_FREE(tmp_ctx);
3220 return true;
3223 bool lpcfg_load_default(struct loadparm_context *lp_ctx)
3225 const char *path;
3227 path = lp_default_path();
3229 if (!file_exist(path)) {
3230 /* We allow the default smb.conf file to not exist,
3231 * basically the equivalent of an empty file. */
3232 return lpcfg_update(lp_ctx);
3235 return lpcfg_load(lp_ctx, path);
3239 * Load the services array from the services file.
3241 * Return True on success, False on failure.
3243 static bool lpcfg_load_internal(struct loadparm_context *lp_ctx,
3244 const char *filename, bool set_global)
3246 char *n2;
3247 bool bRetval;
3249 if (lp_ctx->szConfigFile != NULL) {
3250 talloc_free(discard_const_p(char, lp_ctx->szConfigFile));
3251 lp_ctx->szConfigFile = NULL;
3254 lp_ctx->szConfigFile = talloc_strdup(lp_ctx, filename);
3256 if (lp_ctx->s3_fns) {
3257 return lp_ctx->s3_fns->load(filename);
3260 lp_ctx->bInGlobalSection = true;
3261 n2 = standard_sub_basic(lp_ctx, lp_ctx->szConfigFile);
3262 DEBUG(2, ("lpcfg_load: refreshing parameters from %s\n", n2));
3264 add_to_file_list(lp_ctx, &lp_ctx->file_lists, lp_ctx->szConfigFile, n2);
3266 /* We get sections first, so have to start 'behind' to make up */
3267 lp_ctx->currentService = NULL;
3268 bRetval = pm_process(n2, do_section, lpcfg_do_parameter, lp_ctx);
3270 /* finish up the last section */
3271 DEBUG(4, ("pm_process() returned %s\n", BOOLSTR(bRetval)));
3272 if (bRetval)
3273 if (lp_ctx->currentService != NULL)
3274 bRetval = lpcfg_service_ok(lp_ctx->currentService);
3276 bRetval = bRetval && lpcfg_update(lp_ctx);
3278 /* we do this unconditionally, so that it happens even
3279 for a missing smb.conf */
3280 reload_charcnv(lp_ctx);
3282 if (bRetval == true && set_global) {
3283 /* set this up so that any child python tasks will
3284 find the right smb.conf */
3285 setenv("SMB_CONF_PATH", filename, 1);
3287 /* set the context used by the lp_*() function
3288 varients */
3289 global_loadparm_context = lp_ctx;
3290 lp_ctx->loaded = true;
3293 return bRetval;
3296 bool lpcfg_load_no_global(struct loadparm_context *lp_ctx, const char *filename)
3298 return lpcfg_load_internal(lp_ctx, filename, false);
3301 bool lpcfg_load(struct loadparm_context *lp_ctx, const char *filename)
3303 return lpcfg_load_internal(lp_ctx, filename, true);
3307 * Return the max number of services.
3310 int lpcfg_numservices(struct loadparm_context *lp_ctx)
3312 if (lp_ctx->s3_fns) {
3313 return lp_ctx->s3_fns->get_numservices();
3316 return lp_ctx->iNumServices;
3320 * Display the contents of the services array in human-readable form.
3323 void lpcfg_dump(struct loadparm_context *lp_ctx, FILE *f, bool show_defaults,
3324 int maxtoprint)
3326 int iService;
3328 if (lp_ctx->s3_fns) {
3329 lp_ctx->s3_fns->dump(f, show_defaults, maxtoprint);
3330 return;
3333 lpcfg_dump_globals(lp_ctx, f, show_defaults);
3335 lpcfg_dump_a_service(lp_ctx->sDefault, lp_ctx->sDefault, f, lp_ctx->flags, show_defaults);
3337 for (iService = 0; iService < maxtoprint; iService++)
3338 lpcfg_dump_one(f, show_defaults, lp_ctx->services[iService], lp_ctx->sDefault);
3342 * Display the contents of one service in human-readable form.
3344 void lpcfg_dump_one(FILE *f, bool show_defaults, struct loadparm_service *service, struct loadparm_service *sDefault)
3346 if (service != NULL) {
3347 if (service->szService[0] == '\0')
3348 return;
3349 lpcfg_dump_a_service(service, sDefault, f, NULL, show_defaults);
3353 struct loadparm_service *lpcfg_servicebynum(struct loadparm_context *lp_ctx,
3354 int snum)
3356 if (lp_ctx->s3_fns) {
3357 return lp_ctx->s3_fns->get_servicebynum(snum);
3360 return lp_ctx->services[snum];
3363 struct loadparm_service *lpcfg_service(struct loadparm_context *lp_ctx,
3364 const char *service_name)
3366 int iService;
3367 char *serviceName;
3369 if (lp_ctx->s3_fns) {
3370 return lp_ctx->s3_fns->get_service(service_name);
3373 for (iService = lp_ctx->iNumServices - 1; iService >= 0; iService--) {
3374 if (lp_ctx->services[iService] &&
3375 lp_ctx->services[iService]->szService) {
3377 * The substitution here is used to support %U is
3378 * service names
3380 serviceName = standard_sub_basic(
3381 lp_ctx->services[iService],
3382 lp_ctx->services[iService]->szService);
3383 if (strequal(serviceName, service_name)) {
3384 talloc_free(serviceName);
3385 return lp_ctx->services[iService];
3387 talloc_free(serviceName);
3391 DEBUG(7,("lpcfg_servicenumber: couldn't find %s\n", service_name));
3392 return NULL;
3395 const char *lpcfg_servicename(const struct loadparm_service *service)
3397 return service ? lpcfg_string((const char *)service->szService) : NULL;
3401 * A useful volume label function.
3403 const char *lpcfg_volume_label(struct loadparm_service *service, struct loadparm_service *sDefault)
3405 const char *ret;
3406 ret = lpcfg_string((const char *)((service != NULL && service->volume != NULL) ?
3407 service->volume : sDefault->volume));
3408 if (!*ret)
3409 return lpcfg_servicename(service);
3410 return ret;
3414 * Return the correct printer name.
3416 const char *lpcfg_printername(struct loadparm_service *service, struct loadparm_service *sDefault)
3418 const char *ret;
3419 ret = lpcfg_string((const char *)((service != NULL && service->_printername != NULL) ?
3420 service->_printername : sDefault->_printername));
3421 if (ret == NULL || (ret != NULL && *ret == '\0'))
3422 ret = lpcfg_servicename(service);
3424 return ret;
3429 * Return the max print jobs per queue.
3431 int lpcfg_maxprintjobs(struct loadparm_service *service, struct loadparm_service *sDefault)
3433 int maxjobs = lpcfg_max_print_jobs(service, sDefault);
3435 if (maxjobs <= 0 || maxjobs >= PRINT_MAX_JOBID)
3436 maxjobs = PRINT_MAX_JOBID - 1;
3438 return maxjobs;
3441 struct smb_iconv_handle *lpcfg_iconv_handle(struct loadparm_context *lp_ctx)
3443 if (lp_ctx == NULL) {
3444 return get_iconv_handle();
3446 return lp_ctx->iconv_handle;
3449 _PUBLIC_ void reload_charcnv(struct loadparm_context *lp_ctx)
3451 if (!lp_ctx->global) {
3452 return;
3455 lp_ctx->iconv_handle =
3456 reinit_iconv_handle(lp_ctx,
3457 lpcfg_dos_charset(lp_ctx),
3458 lpcfg_unix_charset(lp_ctx));
3459 if (lp_ctx->iconv_handle == NULL) {
3460 smb_panic("reinit_iconv_handle failed");
3464 _PUBLIC_ char *lpcfg_tls_keyfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
3466 return lpcfg_private_path(mem_ctx, lp_ctx, lpcfg__tls_keyfile(lp_ctx));
3469 _PUBLIC_ char *lpcfg_tls_certfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
3471 return lpcfg_private_path(mem_ctx, lp_ctx, lpcfg__tls_certfile(lp_ctx));
3474 _PUBLIC_ char *lpcfg_tls_cafile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
3476 return lpcfg_private_path(mem_ctx, lp_ctx, lpcfg__tls_cafile(lp_ctx));
3479 _PUBLIC_ char *lpcfg_tls_crlfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
3481 return lpcfg_private_path(mem_ctx, lp_ctx, lpcfg__tls_crlfile(lp_ctx));
3484 _PUBLIC_ char *lpcfg_tls_dhpfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
3486 return lpcfg_private_path(mem_ctx, lp_ctx, lpcfg__tls_dhpfile(lp_ctx));
3489 struct gensec_settings *lpcfg_gensec_settings(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
3491 struct gensec_settings *settings = talloc_zero(mem_ctx, struct gensec_settings);
3492 if (settings == NULL)
3493 return NULL;
3494 SMB_ASSERT(lp_ctx != NULL);
3495 settings->lp_ctx = talloc_reference(settings, lp_ctx);
3496 settings->target_hostname = lpcfg_parm_string(lp_ctx, NULL, "gensec", "target_hostname");
3497 return settings;
3500 int lpcfg_server_role(struct loadparm_context *lp_ctx)
3502 int domain_master = lpcfg__domain_master(lp_ctx);
3504 return lp_find_server_role(lpcfg__server_role(lp_ctx),
3505 lpcfg__security(lp_ctx),
3506 lpcfg__domain_logons(lp_ctx),
3507 (domain_master == true) ||
3508 (domain_master == Auto));
3511 int lpcfg_security(struct loadparm_context *lp_ctx)
3513 return lp_find_security(lpcfg__server_role(lp_ctx),
3514 lpcfg__security(lp_ctx));
3517 int lpcfg_client_max_protocol(struct loadparm_context *lp_ctx)
3519 int client_max_protocol = lpcfg__client_max_protocol(lp_ctx);
3520 if (client_max_protocol == PROTOCOL_DEFAULT) {
3521 return PROTOCOL_LATEST;
3523 return client_max_protocol;
3526 int lpcfg_client_ipc_min_protocol(struct loadparm_context *lp_ctx)
3528 int client_ipc_min_protocol = lpcfg__client_ipc_min_protocol(lp_ctx);
3529 if (client_ipc_min_protocol == PROTOCOL_DEFAULT) {
3530 client_ipc_min_protocol = lpcfg_client_min_protocol(lp_ctx);
3532 if (client_ipc_min_protocol < PROTOCOL_NT1) {
3533 return PROTOCOL_NT1;
3535 return client_ipc_min_protocol;
3538 int lpcfg_client_ipc_max_protocol(struct loadparm_context *lp_ctx)
3540 int client_ipc_max_protocol = lpcfg__client_ipc_max_protocol(lp_ctx);
3541 if (client_ipc_max_protocol == PROTOCOL_DEFAULT) {
3542 return PROTOCOL_LATEST;
3544 if (client_ipc_max_protocol < PROTOCOL_NT1) {
3545 return PROTOCOL_NT1;
3547 return client_ipc_max_protocol;
3550 int lpcfg_client_ipc_signing(struct loadparm_context *lp_ctx)
3552 int client_ipc_signing = lpcfg__client_ipc_signing(lp_ctx);
3553 if (client_ipc_signing == SMB_SIGNING_DEFAULT) {
3554 return SMB_SIGNING_REQUIRED;
3556 return client_ipc_signing;
3559 bool lpcfg_server_signing_allowed(struct loadparm_context *lp_ctx, bool *mandatory)
3561 bool allowed = true;
3562 enum smb_signing_setting signing_setting = lpcfg_server_signing(lp_ctx);
3564 *mandatory = false;
3566 if (signing_setting == SMB_SIGNING_DEFAULT) {
3568 * If we are a domain controller, SMB signing is
3569 * really important, as it can prevent a number of
3570 * attacks on communications between us and the
3571 * clients
3573 * However, it really sucks (no sendfile, CPU
3574 * overhead) performance-wise when used on a
3575 * file server, so disable it by default
3576 * on non-DCs
3579 if (lpcfg_server_role(lp_ctx) >= ROLE_ACTIVE_DIRECTORY_DC) {
3580 signing_setting = SMB_SIGNING_REQUIRED;
3581 } else {
3582 signing_setting = SMB_SIGNING_OFF;
3586 switch (signing_setting) {
3587 case SMB_SIGNING_REQUIRED:
3588 *mandatory = true;
3589 break;
3590 case SMB_SIGNING_DESIRED:
3591 case SMB_SIGNING_IF_REQUIRED:
3592 break;
3593 case SMB_SIGNING_OFF:
3594 allowed = false;
3595 break;
3596 case SMB_SIGNING_DEFAULT:
3597 case SMB_SIGNING_IPC_DEFAULT:
3598 smb_panic(__location__);
3599 break;
3602 return allowed;
3605 int lpcfg_tdb_hash_size(struct loadparm_context *lp_ctx, const char *name)
3607 const char *base;
3609 if (name == NULL) {
3610 return 0;
3613 base = strrchr_m(name, '/');
3614 if (base != NULL) {
3615 base += 1;
3616 } else {
3617 base = name;
3619 return lpcfg_parm_int(lp_ctx, NULL, "tdb_hashsize", base, 0);
3623 int lpcfg_tdb_flags(struct loadparm_context *lp_ctx, int tdb_flags)
3625 if (!lpcfg_use_mmap(lp_ctx)) {
3626 tdb_flags |= TDB_NOMMAP;
3628 return tdb_flags;
3632 * Do not allow LanMan auth if unless NTLMv1 is also allowed
3634 * This also ensures it is disabled if NTLM is totally disabled
3636 bool lpcfg_lanman_auth(struct loadparm_context *lp_ctx)
3638 enum ntlm_auth_level ntlm_auth_level = lpcfg_ntlm_auth(lp_ctx);
3640 if (ntlm_auth_level == NTLM_AUTH_ON) {
3641 return lpcfg__lanman_auth(lp_ctx);
3642 } else {
3643 return false;
3647 static char *lpcfg_noop_substitution_fn(
3648 TALLOC_CTX *mem_ctx,
3649 const struct loadparm_substitution *lp_sub,
3650 const char *raw_value,
3651 void *private_data)
3653 return talloc_strdup(mem_ctx, raw_value);
3656 static const struct loadparm_substitution global_noop_substitution = {
3657 .substituted_string_fn = lpcfg_noop_substitution_fn,
3660 const struct loadparm_substitution *lpcfg_noop_substitution(void)
3662 return &global_noop_substitution;
3665 char *lpcfg_substituted_string(TALLOC_CTX *mem_ctx,
3666 const struct loadparm_substitution *lp_sub,
3667 const char *raw_value)
3669 return lp_sub->substituted_string_fn(mem_ctx,
3670 lp_sub,
3671 raw_value,
3672 lp_sub->private_data);