2 Unix SMB/CIFS implementation.
3 Parameter loading functions
4 Copyright (C) Karl Auer 1993-1998
6 Largely re-written by Andrew Tridgell, September 1994
8 Copyright (C) Simo Sorce 2001
9 Copyright (C) Alexander Bokovoy 2002
10 Copyright (C) Stefan (metze) Metzmacher 2002
11 Copyright (C) Jim McDonough (jmcd@us.ibm.com) 2003.
12 Copyright (C) James Myers 2003 <myersjj@samba.org>
13 Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2007
14 Copyright (C) Andrew Bartlett 2011-2012
16 This program is free software; you can redistribute it and/or modify
17 it under the terms of the GNU General Public License as published by
18 the Free Software Foundation; either version 3 of the License, or
19 (at your option) any later version.
21 This program is distributed in the hope that it will be useful,
22 but WITHOUT ANY WARRANTY; without even the implied warranty of
23 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 GNU General Public License for more details.
26 You should have received a copy of the GNU General Public License
27 along with this program. If not, see <http://www.gnu.org/licenses/>.
33 * This module provides suitable callback functions for the params
34 * module. It builds the internal table of service details which is
35 * then used by the rest of the server.
39 * 1) add it to the global or service structure definition
40 * 2) add it to the parm_table
41 * 3) add it to the list of available functions (eg: using FN_GLOBAL_STRING())
42 * 4) If it's a global then initialise it in init_globals. If a local
43 * (ie. service) parameter then initialise it in the sDefault structure
47 * The configuration file is processed sequentially for speed. It is NOT
48 * accessed randomly as happens in 'real' Windows. For this reason, there
49 * is a fair bit of sequence-dependent code here - ie., code which assumes
50 * that certain things happen before others. In particular, the code which
51 * happens at the boundary between sections is delicately poised, so be
58 #include "dynconfig/dynconfig.h"
59 #include "system/time.h"
60 #include "system/locale.h"
61 #include "system/network.h" /* needed for TCP_NODELAY */
62 #include "../lib/util/dlinklist.h"
63 #include "lib/param/param.h"
64 #include "lib/param/loadparm.h"
65 #include "auth/gensec/gensec.h"
66 #include "lib/param/s3_param.h"
67 #include "lib/util/bitmap.h"
68 #include "libcli/smb/smb_constants.h"
70 #include "librpc/gen_ndr/nbt.h"
71 #include "libds/common/roles.h"
73 #ifdef HAVE_HTTPCONNECTENCRYPT
74 #include <cups/http.h>
77 #define standard_sub_basic talloc_strdup
79 #include "lib/param/param_global.h"
81 struct loadparm_service *lpcfg_default_service(struct loadparm_context *lp_ctx)
83 return lp_ctx->sDefault;
87 * Convenience routine to grab string parameters into temporary memory
88 * and run standard_sub_basic on them.
90 * The buffers can be written to by
91 * callers without affecting the source string.
94 static const char *lpcfg_string(const char *s)
96 #if 0 /* until REWRITE done to make thread-safe */
97 size_t len = s ? strlen(s) : 0;
101 /* The follow debug is useful for tracking down memory problems
102 especially if you have an inner loop that is calling a lp_*()
103 function that returns a string. Perhaps this debug should be
104 present all the time? */
107 DEBUG(10, ("lpcfg_string(%s)\n", s));
110 #if 0 /* until REWRITE done to make thread-safe */
112 lp_talloc = talloc_init("lp_talloc");
114 ret = talloc_array(lp_talloc, char, len + 100); /* leave room for substitution */
122 strlcpy(ret, s, len);
124 if (trim_string(ret, "\"", "\"")) {
125 if (strchr(ret,'"') != NULL)
126 strlcpy(ret, s, len);
129 standard_sub_basic(ret,len+100);
136 In this section all the functions that are used to access the
137 parameters from the rest of the program are defined
141 * the creation of separate lpcfg_*() and lp_*() functions is to allow
142 * for code compatibility between existing Samba4 and Samba3 code.
145 /* this global context supports the lp_*() function varients */
146 static struct loadparm_context *global_loadparm_context;
148 #define FN_GLOBAL_STRING(fn_name,var_name) \
149 _PUBLIC_ char *lpcfg_ ## fn_name(struct loadparm_context *lp_ctx, TALLOC_CTX *ctx) {\
150 if (lp_ctx == NULL) return NULL; \
151 if (lp_ctx->s3_fns) { \
152 return lp_ctx->globals->var_name ? lp_ctx->s3_fns->lp_string(ctx, lp_ctx->globals->var_name) : talloc_strdup(ctx, ""); \
154 return lp_ctx->globals->var_name ? talloc_strdup(ctx, lpcfg_string(lp_ctx->globals->var_name)) : talloc_strdup(ctx, ""); \
157 #define FN_GLOBAL_CONST_STRING(fn_name,var_name) \
158 _PUBLIC_ const char *lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) { \
159 if (lp_ctx == NULL) return NULL; \
160 return lp_ctx->globals->var_name ? lpcfg_string(lp_ctx->globals->var_name) : ""; \
163 #define FN_GLOBAL_LIST(fn_name,var_name) \
164 _PUBLIC_ const char **lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) { \
165 if (lp_ctx == NULL) return NULL; \
166 return lp_ctx->globals->var_name; \
169 #define FN_GLOBAL_BOOL(fn_name,var_name) \
170 _PUBLIC_ bool lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) {\
171 if (lp_ctx == NULL) return false; \
172 return lp_ctx->globals->var_name; \
175 #define FN_GLOBAL_INTEGER(fn_name,var_name) \
176 _PUBLIC_ int lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) { \
177 return lp_ctx->globals->var_name; \
180 /* Local parameters don't need the ->s3_fns because the struct
181 * loadparm_service is shared and lpcfg_service() checks the ->s3_fns
183 #define FN_LOCAL_STRING(fn_name,val) \
184 _PUBLIC_ char *lpcfg_ ## fn_name(struct loadparm_service *service, \
185 struct loadparm_service *sDefault, TALLOC_CTX *ctx) { \
186 return(talloc_strdup(ctx, lpcfg_string((const char *)((service != NULL && service->val != NULL) ? service->val : sDefault->val)))); \
189 #define FN_LOCAL_CONST_STRING(fn_name,val) \
190 _PUBLIC_ const char *lpcfg_ ## fn_name(struct loadparm_service *service, \
191 struct loadparm_service *sDefault) { \
192 return((const char *)((service != NULL && service->val != NULL) ? service->val : sDefault->val)); \
195 #define FN_LOCAL_LIST(fn_name,val) \
196 _PUBLIC_ const char **lpcfg_ ## fn_name(struct loadparm_service *service, \
197 struct loadparm_service *sDefault) {\
198 return(const char **)(service != NULL && service->val != NULL? service->val : sDefault->val); \
201 #define FN_LOCAL_PARM_BOOL(fn_name, val) FN_LOCAL_BOOL(fn_name, val)
203 #define FN_LOCAL_BOOL(fn_name,val) \
204 _PUBLIC_ bool lpcfg_ ## fn_name(struct loadparm_service *service, \
205 struct loadparm_service *sDefault) { \
206 return((service != NULL)? service->val : sDefault->val); \
209 #define FN_LOCAL_INTEGER(fn_name,val) \
210 _PUBLIC_ int lpcfg_ ## fn_name(struct loadparm_service *service, \
211 struct loadparm_service *sDefault) { \
212 return((service != NULL)? service->val : sDefault->val); \
215 #define FN_LOCAL_PARM_INTEGER(fn_name, val) FN_LOCAL_INTEGER(fn_name, val)
217 #define FN_LOCAL_CHAR(fn_name,val) \
218 _PUBLIC_ char lpcfg_ ## fn_name(struct loadparm_service *service, \
219 struct loadparm_service *sDefault) { \
220 return((service != NULL)? service->val : sDefault->val); \
223 #define FN_LOCAL_PARM_CHAR(fn_name,val) FN_LOCAL_CHAR(fn_name, val)
225 #include "lib/param/param_functions.c"
227 /* These functions cannot be auto-generated */
228 FN_LOCAL_BOOL(autoloaded, autoloaded)
229 FN_GLOBAL_CONST_STRING(dnsdomain, dnsdomain)
231 /* local prototypes */
232 static struct loadparm_service *lpcfg_getservicebyname(struct loadparm_context *lp_ctx,
233 const char *pszServiceName);
234 static bool do_section(const char *pszSectionName, void *);
235 static bool set_variable_helper(TALLOC_CTX *mem_ctx, int parmnum, void *parm_ptr,
236 const char *pszParmName, const char *pszParmValue);
237 static bool lp_do_parameter_parametric(struct loadparm_context *lp_ctx,
238 struct loadparm_service *service,
239 const char *pszParmName,
240 const char *pszParmValue, int flags);
242 /* The following are helper functions for parametrical options support. */
243 /* It returns a pointer to parametrical option value if it exists or NULL otherwise */
244 /* Actual parametrical functions are quite simple */
245 struct parmlist_entry *get_parametric_helper(struct loadparm_service *service,
246 const char *type, const char *option,
247 struct parmlist_entry *global_opts)
249 size_t type_len = strlen(type);
250 size_t option_len = strlen(option);
251 char param_key[type_len + option_len + 2];
252 struct parmlist_entry *data = NULL;
254 snprintf(param_key, sizeof(param_key), "%s:%s", type, option);
257 * Try to fetch the option from the data.
259 if (service != NULL) {
260 data = service->param_opt;
261 while (data != NULL) {
262 if (strwicmp(data->key, param_key) == 0) {
270 * Fall back to fetching from the globals.
273 while (data != NULL) {
274 if (strwicmp(data->key, param_key) == 0) {
283 const char *lpcfg_get_parametric(struct loadparm_context *lp_ctx,
284 struct loadparm_service *service,
285 const char *type, const char *option)
287 struct parmlist_entry *data;
292 data = get_parametric_helper(service,
293 type, option, lp_ctx->globals->param_opt);
304 * convenience routine to return int parameters.
306 int lp_int(const char *s)
310 DEBUG(0,("lp_int(%s): is called with NULL!\n",s));
314 return strtol(s, NULL, 0);
318 * convenience routine to return unsigned long parameters.
320 unsigned long lp_ulong(const char *s)
324 DEBUG(0,("lp_ulong(%s): is called with NULL!\n",s));
328 return strtoul(s, NULL, 0);
332 * convenience routine to return unsigned long parameters.
334 static long lp_long(const char *s)
338 DEBUG(0,("lp_long(%s): is called with NULL!\n",s));
342 return strtol(s, NULL, 0);
346 * convenience routine to return unsigned long parameters.
348 static double lp_double(const char *s)
352 DEBUG(0,("lp_double(%s): is called with NULL!\n",s));
356 return strtod(s, NULL);
360 * convenience routine to return boolean parameters.
362 bool lp_bool(const char *s)
367 DEBUG(0,("lp_bool(%s): is called with NULL!\n",s));
371 if (!set_boolean(s, &ret)) {
372 DEBUG(0,("lp_bool(%s): value is not boolean!\n",s));
380 * Return parametric option from a given service. Type is a part of option before ':'
381 * Parametric option has following syntax: 'Type: option = value'
382 * Returned value is allocated in 'lp_talloc' context
385 const char *lpcfg_parm_string(struct loadparm_context *lp_ctx,
386 struct loadparm_service *service, const char *type,
389 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
392 return lpcfg_string(value);
398 * Return parametric option from a given service. Type is a part of option before ':'
399 * Parametric option has following syntax: 'Type: option = value'
400 * Returned value is allocated in 'lp_talloc' context
403 const char **lpcfg_parm_string_list(TALLOC_CTX *mem_ctx,
404 struct loadparm_context *lp_ctx,
405 struct loadparm_service *service,
407 const char *option, const char *separator)
409 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
412 char **l = str_list_make(mem_ctx, value, separator);
413 return discard_const_p(const char *, l);
420 * Return parametric option from a given service. Type is a part of option before ':'
421 * Parametric option has following syntax: 'Type: option = value'
424 int lpcfg_parm_int(struct loadparm_context *lp_ctx,
425 struct loadparm_service *service, const char *type,
426 const char *option, int default_v)
428 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
431 return lp_int(value);
437 * Return parametric option from a given service. Type is a part of
439 * Parametric option has following syntax: 'Type: option = value'.
442 int lpcfg_parm_bytes(struct loadparm_context *lp_ctx,
443 struct loadparm_service *service, const char *type,
444 const char *option, int default_v)
448 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
450 if (value && conv_str_size_error(value, &bval)) {
451 if (bval <= INT_MAX) {
460 * Return parametric option from a given service.
461 * Type is a part of option before ':'
462 * Parametric option has following syntax: 'Type: option = value'
464 unsigned long lpcfg_parm_ulong(struct loadparm_context *lp_ctx,
465 struct loadparm_service *service, const char *type,
466 const char *option, unsigned long default_v)
468 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
471 return lp_ulong(value);
476 long lpcfg_parm_long(struct loadparm_context *lp_ctx,
477 struct loadparm_service *service, const char *type,
478 const char *option, long default_v)
480 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
483 return lp_long(value);
488 double lpcfg_parm_double(struct loadparm_context *lp_ctx,
489 struct loadparm_service *service, const char *type,
490 const char *option, double default_v)
492 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
495 return lp_double(value);
501 * Return parametric option from a given service. Type is a part of option before ':'
502 * Parametric option has following syntax: 'Type: option = value'
505 bool lpcfg_parm_bool(struct loadparm_context *lp_ctx,
506 struct loadparm_service *service, const char *type,
507 const char *option, bool default_v)
509 const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
512 return lp_bool(value);
518 /* this is used to prevent lots of mallocs of size 1 */
519 static const char lpcfg_string_emtpy[] = "";
524 void lpcfg_string_free(char **s)
529 if (*s == lpcfg_string_emtpy) {
537 * Set a string value, deallocating any existing space, and allocing the space
540 bool lpcfg_string_set(TALLOC_CTX *mem_ctx, char **dest, const char *src)
542 lpcfg_string_free(dest);
544 if ((src == NULL) || (*src == '\0')) {
545 *dest = discard_const_p(char, lpcfg_string_emtpy);
549 *dest = talloc_strdup(mem_ctx, src);
550 if ((*dest) == NULL) {
551 DEBUG(0,("Out of memory in string_set\n"));
559 * Set a string value, deallocating any existing space, and allocing the space
562 bool lpcfg_string_set_upper(TALLOC_CTX *mem_ctx, char **dest, const char *src)
564 lpcfg_string_free(dest);
566 if ((src == NULL) || (*src == '\0')) {
567 *dest = discard_const_p(char, lpcfg_string_emtpy);
571 *dest = strupper_talloc(mem_ctx, src);
572 if ((*dest) == NULL) {
573 DEBUG(0,("Out of memory in string_set_upper\n"));
583 * Add a new service to the services array initialising it with the given
587 struct loadparm_service *lpcfg_add_service(struct loadparm_context *lp_ctx,
588 const struct loadparm_service *pservice,
592 int num_to_alloc = lp_ctx->iNumServices + 1;
593 struct parmlist_entry *data, *pdata;
595 if (lp_ctx->s3_fns != NULL) {
596 smb_panic("Add a service should not be called on an s3 loadparm ctx");
599 if (pservice == NULL) {
600 pservice = lp_ctx->sDefault;
603 /* it might already exist */
605 struct loadparm_service *service = lpcfg_getservicebyname(lp_ctx,
607 if (service != NULL) {
608 /* Clean all parametric options for service */
609 /* They will be added during parsing again */
610 data = service->param_opt;
616 service->param_opt = NULL;
621 /* find an invalid one */
622 for (i = 0; i < lp_ctx->iNumServices; i++)
623 if (lp_ctx->services[i] == NULL)
626 /* if not, then create one */
627 if (i == lp_ctx->iNumServices) {
628 struct loadparm_service **tsp;
630 tsp = talloc_realloc(lp_ctx, lp_ctx->services, struct loadparm_service *, num_to_alloc);
633 DEBUG(0,("lpcfg_add_service: failed to enlarge services!\n"));
636 lp_ctx->services = tsp;
637 lp_ctx->services[lp_ctx->iNumServices] = NULL;
640 lp_ctx->iNumServices++;
643 lp_ctx->services[i] = talloc_zero(lp_ctx->services, struct loadparm_service);
644 if (lp_ctx->services[i] == NULL) {
645 DEBUG(0,("lpcfg_add_service: out of memory!\n"));
648 copy_service(lp_ctx->services[i], pservice, NULL);
650 lpcfg_string_set(lp_ctx->services[i], &lp_ctx->services[i]->szService, name);
651 return lp_ctx->services[i];
655 * Add a new home service, with the specified home directory, defaults coming
656 * from service ifrom.
659 bool lpcfg_add_home(struct loadparm_context *lp_ctx,
660 const char *pszHomename,
661 struct loadparm_service *default_service,
662 const char *user, const char *pszHomedir)
664 struct loadparm_service *service;
666 service = lpcfg_add_service(lp_ctx, default_service, pszHomename);
671 if (!(*(default_service->path))
672 || strequal(default_service->path, lp_ctx->sDefault->path)) {
673 service->path = talloc_strdup(service, pszHomedir);
675 service->path = string_sub_talloc(service, lpcfg_path(default_service, lp_ctx->sDefault, service), "%H", pszHomedir);
678 if (!(*(service->comment))) {
679 service->comment = talloc_asprintf(service, "Home directory of %s", user);
681 service->available = default_service->available;
682 service->browseable = default_service->browseable;
684 DEBUG(3, ("adding home's share [%s] for user '%s' at '%s'\n",
685 pszHomename, user, service->path));
691 * Add a new printer service, with defaults coming from service iFrom.
694 bool lpcfg_add_printer(struct loadparm_context *lp_ctx,
695 const char *pszPrintername,
696 struct loadparm_service *default_service)
698 const char *comment = "From Printcap";
699 struct loadparm_service *service;
700 service = lpcfg_add_service(lp_ctx, default_service, pszPrintername);
705 /* note that we do NOT default the availability flag to True - */
706 /* we take it from the default service passed. This allows all */
707 /* dynamic printers to be disabled by disabling the [printers] */
708 /* entry (if/when the 'available' keyword is implemented!). */
710 /* the printer name is set to the service name. */
711 lpcfg_string_set(service, &service->_printername, pszPrintername);
712 lpcfg_string_set(service, &service->comment, comment);
713 service->browseable = default_service->browseable;
714 /* Printers cannot be read_only. */
715 service->read_only = false;
716 /* Printer services must be printable. */
717 service->printable = true;
719 DEBUG(3, ("adding printer service %s\n", pszPrintername));
725 * Map a parameter's string representation to something we can use.
726 * Returns False if the parameter string is not recognised, else TRUE.
729 int lpcfg_map_parameter(const char *pszParmName)
733 for (iIndex = 0; parm_table[iIndex].label; iIndex++)
734 if (strwicmp(parm_table[iIndex].label, pszParmName) == 0)
737 /* Warn only if it isn't parametric option */
738 if (strchr(pszParmName, ':') == NULL)
739 DEBUG(0, ("Unknown parameter encountered: \"%s\"\n", pszParmName));
740 /* We do return 'fail' for parametric options as well because they are
741 stored in different storage
748 return the parameter structure for a parameter
750 struct parm_struct *lpcfg_parm_struct(struct loadparm_context *lp_ctx, const char *name)
752 int num = lpcfg_map_parameter(name);
758 return &parm_table[num];
762 return the parameter pointer for a parameter
764 void *lpcfg_parm_ptr(struct loadparm_context *lp_ctx,
765 struct loadparm_service *service, struct parm_struct *parm)
767 if (lp_ctx->s3_fns) {
768 return lp_ctx->s3_fns->get_parm_ptr(service, parm);
771 if (service == NULL) {
772 if (parm->p_class == P_LOCAL)
773 return ((char *)lp_ctx->sDefault)+parm->offset;
774 else if (parm->p_class == P_GLOBAL)
775 return ((char *)lp_ctx->globals)+parm->offset;
778 return ((char *)service) + parm->offset;
783 return the parameter pointer for a parameter
785 bool lpcfg_parm_is_cmdline(struct loadparm_context *lp_ctx, const char *name)
789 parmnum = lpcfg_map_parameter(name);
790 if (parmnum == -1) return false;
792 return lp_ctx->flags[parmnum] & FLAG_CMDLINE;
796 * Find a service by name. Otherwise works like get_service.
799 static struct loadparm_service *lpcfg_getservicebyname(struct loadparm_context *lp_ctx,
800 const char *pszServiceName)
804 if (lp_ctx->s3_fns) {
805 return lp_ctx->s3_fns->get_service(pszServiceName);
808 for (iService = lp_ctx->iNumServices - 1; iService >= 0; iService--)
809 if (lp_ctx->services[iService] != NULL &&
810 strwicmp(lp_ctx->services[iService]->szService, pszServiceName) == 0) {
811 return lp_ctx->services[iService];
818 * Add a parametric option to a parmlist_entry,
819 * replacing old value, if already present.
821 void set_param_opt(TALLOC_CTX *mem_ctx,
822 struct parmlist_entry **opt_list,
823 const char *opt_name,
824 const char *opt_value,
827 struct parmlist_entry *new_opt, *opt;
831 /* Traverse destination */
833 /* If we already have same option, override it */
834 if (strwicmp(opt->key, opt_name) == 0) {
835 if ((opt->priority & FLAG_CMDLINE) &&
836 !(priority & FLAG_CMDLINE)) {
837 /* it's been marked as not to be
841 TALLOC_FREE(opt->list);
842 lpcfg_string_set(opt, &opt->value, opt_value);
843 opt->priority = priority;
849 new_opt = talloc_pooled_object(
850 mem_ctx, struct parmlist_entry,
851 2, strlen(opt_name) + 1 + strlen(opt_value) + 1);
852 if (new_opt == NULL) {
856 lpcfg_string_set(new_opt, &new_opt->key, opt_name);
857 new_opt->value = NULL;
858 lpcfg_string_set(new_opt, &new_opt->value, opt_value);
860 new_opt->list = NULL;
861 new_opt->priority = priority;
862 DLIST_ADD(*opt_list, new_opt);
866 * Copy a service structure to another.
867 * If pcopymapDest is NULL then copy all fields
870 void copy_service(struct loadparm_service *pserviceDest,
871 const struct loadparm_service *pserviceSource,
872 struct bitmap *pcopymapDest)
875 bool bcopyall = (pcopymapDest == NULL);
876 struct parmlist_entry *data;
878 for (i = 0; parm_table[i].label; i++)
879 if (parm_table[i].p_class == P_LOCAL &&
880 (bcopyall || bitmap_query(pcopymapDest, i))) {
881 const void *src_ptr =
882 ((const char *)pserviceSource) + parm_table[i].offset;
884 ((char *)pserviceDest) + parm_table[i].offset;
886 switch (parm_table[i].type) {
889 *(bool *)dest_ptr = *(const bool *)src_ptr;
896 *(int *)dest_ptr = *(const int *)src_ptr;
900 *(char *)dest_ptr = *(const char *)src_ptr;
904 lpcfg_string_set(pserviceDest,
906 *(const char * const *)src_ptr);
910 lpcfg_string_set_upper(pserviceDest,
912 *(const char * const *)src_ptr);
916 TALLOC_FREE(*((char ***)dest_ptr));
917 *(char ***)dest_ptr = str_list_copy(pserviceDest,
918 *discard_const_p(const char **, src_ptr));
926 init_copymap(pserviceDest);
927 if (pserviceSource->copymap)
928 bitmap_copy(pserviceDest->copymap,
929 pserviceSource->copymap);
932 for (data = pserviceSource->param_opt; data != NULL; data = data->next) {
933 set_param_opt(pserviceDest, &pserviceDest->param_opt,
934 data->key, data->value, data->priority);
939 * Check a service for consistency. Return False if the service is in any way
940 * incomplete or faulty, else True.
942 bool lpcfg_service_ok(struct loadparm_service *service)
947 if (service->szService[0] == '\0') {
948 DEBUG(0, ("The following message indicates an internal error:\n"));
949 DEBUG(0, ("No service name in service entry.\n"));
953 /* The [printers] entry MUST be printable. I'm all for flexibility, but */
954 /* I can't see why you'd want a non-printable printer service... */
955 if (strwicmp(service->szService, PRINTERS_NAME) == 0) {
956 if (!service->printable) {
957 DEBUG(0, ("WARNING: [%s] service MUST be printable!\n",
958 service->szService));
959 service->printable = true;
961 /* [printers] service must also be non-browsable. */
962 if (service->browseable)
963 service->browseable = false;
966 if (service->path[0] == '\0' &&
967 strwicmp(service->szService, HOMES_NAME) != 0 &&
968 service->msdfs_proxy[0] == '\0')
970 DEBUG(0, ("WARNING: No path in service %s - making it unavailable!\n",
971 service->szService));
972 service->available = false;
975 if (!service->available)
976 DEBUG(1, ("NOTE: Service %s is flagged unavailable.\n",
977 service->szService));
983 /*******************************************************************
984 Keep a linked list of all config files so we know when one has changed
985 it's date and needs to be reloaded.
986 ********************************************************************/
988 void add_to_file_list(TALLOC_CTX *mem_ctx, struct file_lists **list,
989 const char *fname, const char *subfname)
991 struct file_lists *f = *list;
994 if (f->name && !strcmp(f->name, fname))
1000 f = talloc(mem_ctx, struct file_lists);
1004 f->name = talloc_strdup(f, fname);
1009 f->subfname = talloc_strdup(f, subfname);
1015 f->modtime = file_modtime(subfname);
1017 time_t t = file_modtime(subfname);
1024 DEBUG(0, ("Unable to add file to file list: %s\n", fname));
1028 /*******************************************************************
1029 Check if a config file has changed date.
1030 ********************************************************************/
1031 bool lpcfg_file_list_changed(struct loadparm_context *lp_ctx)
1033 struct file_lists *f;
1034 DEBUG(6, ("lpcfg_file_list_changed()\n"));
1036 for (f = lp_ctx->file_lists; f != NULL; f = f->next) {
1040 n2 = standard_sub_basic(lp_ctx, f->name);
1042 DEBUGADD(6, ("file %s -> %s last mod_time: %s\n",
1043 f->name, n2, ctime(&f->modtime)));
1045 mod_time = file_modtime(n2);
1047 if (mod_time && ((f->modtime != mod_time) || (f->subfname == NULL) || (strcmp(n2, f->subfname) != 0))) {
1048 DEBUGADD(6, ("file %s modified: %s\n", n2,
1050 f->modtime = mod_time;
1051 talloc_free(f->subfname);
1052 f->subfname = talloc_strdup(f, n2);
1062 * set the value for a P_ENUM
1064 bool lp_set_enum_parm( struct parm_struct *parm, const char *pszParmValue,
1069 for (i = 0; parm->enum_list[i].name; i++) {
1070 if (strwicmp(pszParmValue, parm->enum_list[i].name) == 0) {
1071 *ptr = parm->enum_list[i].value;
1075 DEBUG(0, ("WARNING: Ignoring invalid value '%s' for parameter '%s'\n",
1076 pszParmValue, parm->label));
1081 /***************************************************************************
1082 Handle the "realm" parameter
1083 ***************************************************************************/
1085 bool handle_realm(struct loadparm_context *lp_ctx, struct loadparm_service *service,
1086 const char *pszParmValue, char **ptr)
1091 upper = strupper_talloc(lp_ctx, pszParmValue);
1092 if (upper == NULL) {
1096 lower = strlower_talloc(lp_ctx, pszParmValue);
1097 if (lower == NULL) {
1102 lpcfg_string_set(lp_ctx->globals->ctx, &lp_ctx->globals->realm_original, pszParmValue);
1103 lpcfg_string_set(lp_ctx->globals->ctx, &lp_ctx->globals->realm, upper);
1104 lpcfg_string_set(lp_ctx->globals->ctx, &lp_ctx->globals->dnsdomain, lower);
1109 /***************************************************************************
1110 Handle the include operation.
1111 ***************************************************************************/
1113 bool handle_include(struct loadparm_context *lp_ctx, struct loadparm_service *service,
1114 const char *pszParmValue, char **ptr)
1117 const char *substitution_variable_substring;
1120 if (lp_ctx->s3_fns) {
1121 return lp_ctx->s3_fns->lp_include(lp_ctx, service, pszParmValue, ptr);
1124 fname = standard_sub_basic(lp_ctx, pszParmValue);
1126 add_to_file_list(lp_ctx, &lp_ctx->file_lists, pszParmValue, fname);
1128 lpcfg_string_set(lp_ctx, ptr, fname);
1130 if (file_exist(fname))
1131 return pm_process(fname, do_section, lpcfg_do_parameter, lp_ctx);
1134 * If the file doesn't exist, we check that it isn't due to variable
1137 substitution_variable_substring = strchr(fname, '%');
1139 if (substitution_variable_substring != NULL) {
1140 next_char = substitution_variable_substring[1];
1141 if ((next_char >= 'a' && next_char <= 'z')
1142 || (next_char >= 'A' && next_char <= 'Z')) {
1143 DEBUG(2, ("Tried to load %s but variable substitution in "
1144 "filename, ignoring file.\n", fname));
1149 DEBUG(2, ("Can't find include file %s\n", fname));
1154 /***************************************************************************
1155 Handle the interpretation of the copy parameter.
1156 ***************************************************************************/
1158 bool handle_copy(struct loadparm_context *lp_ctx, struct loadparm_service *service,
1159 const char *pszParmValue, char **ptr)
1162 struct loadparm_service *serviceTemp = NULL;
1166 DEBUG(3, ("Copying service from service %s\n", pszParmValue));
1168 serviceTemp = lpcfg_getservicebyname(lp_ctx, pszParmValue);
1170 if (service == NULL) {
1171 DEBUG(0, ("Unable to copy service - invalid service destination.\n"));
1175 if (serviceTemp != NULL) {
1176 if (serviceTemp == service) {
1177 DEBUG(0, ("Can't copy service %s - unable to copy self!\n", pszParmValue));
1179 copy_service(service,
1182 lpcfg_string_set(service, ptr, pszParmValue);
1187 DEBUG(0, ("Unable to copy service - source not found: %s\n",
1195 bool handle_debug_list(struct loadparm_context *lp_ctx, struct loadparm_service *service,
1196 const char *pszParmValue, char **ptr)
1198 lpcfg_string_set(lp_ctx->globals->ctx, ptr, pszParmValue);
1200 return debug_parse_levels(pszParmValue);
1203 bool handle_logfile(struct loadparm_context *lp_ctx, struct loadparm_service *service,
1204 const char *pszParmValue, char **ptr)
1206 if (lp_ctx->s3_fns == NULL) {
1207 debug_set_logfile(pszParmValue);
1210 lpcfg_string_set(lp_ctx->globals->ctx, ptr, pszParmValue);
1216 * These special charset handling methods only run in the source3 code.
1219 bool handle_charset(struct loadparm_context *lp_ctx, struct loadparm_service *service,
1220 const char *pszParmValue, char **ptr)
1222 if (lp_ctx->s3_fns) {
1223 if (*ptr == NULL || strcmp(*ptr, pszParmValue) != 0) {
1224 global_iconv_handle = smb_iconv_handle_reinit(NULL,
1225 lpcfg_dos_charset(lp_ctx),
1226 lpcfg_unix_charset(lp_ctx),
1227 true, global_iconv_handle);
1231 return lpcfg_string_set(lp_ctx->globals->ctx, ptr, pszParmValue);
1235 bool handle_dos_charset(struct loadparm_context *lp_ctx, struct loadparm_service *service,
1236 const char *pszParmValue, char **ptr)
1238 bool is_utf8 = false;
1239 size_t len = strlen(pszParmValue);
1241 if (lp_ctx->s3_fns) {
1242 if (len == 4 || len == 5) {
1243 /* Don't use StrCaseCmp here as we don't want to
1244 initialize iconv. */
1245 if ((toupper_m(pszParmValue[0]) == 'U') &&
1246 (toupper_m(pszParmValue[1]) == 'T') &&
1247 (toupper_m(pszParmValue[2]) == 'F')) {
1249 if (pszParmValue[3] == '8') {
1253 if (pszParmValue[3] == '-' &&
1254 pszParmValue[4] == '8') {
1261 if (*ptr == NULL || strcmp(*ptr, pszParmValue) != 0) {
1263 DEBUG(0,("ERROR: invalid DOS charset: 'dos charset' must not "
1264 "be UTF8, using (default value) %s instead.\n",
1265 DEFAULT_DOS_CHARSET));
1266 pszParmValue = DEFAULT_DOS_CHARSET;
1268 global_iconv_handle = smb_iconv_handle_reinit(NULL,
1269 lpcfg_dos_charset(lp_ctx),
1270 lpcfg_unix_charset(lp_ctx),
1271 true, global_iconv_handle);
1275 return lpcfg_string_set(lp_ctx->globals->ctx, ptr, pszParmValue);
1278 bool handle_printing(struct loadparm_context *lp_ctx, struct loadparm_service *service,
1279 const char *pszParmValue, char **ptr)
1281 static int parm_num = -1;
1283 if (parm_num == -1) {
1284 parm_num = lpcfg_map_parameter("printing");
1287 if (!lp_set_enum_parm(&parm_table[parm_num], pszParmValue, (int*)ptr)) {
1291 if (lp_ctx->s3_fns) {
1292 if (service == NULL) {
1293 init_printer_values(lp_ctx, lp_ctx->globals->ctx, lp_ctx->sDefault);
1295 init_printer_values(lp_ctx, service, service);
1302 bool handle_ldap_debug_level(struct loadparm_context *lp_ctx, struct loadparm_service *service,
1303 const char *pszParmValue, char **ptr)
1305 lp_ctx->globals->ldap_debug_level = lp_int(pszParmValue);
1307 if (lp_ctx->s3_fns) {
1308 lp_ctx->s3_fns->init_ldap_debugging();
1313 bool handle_netbios_aliases(struct loadparm_context *lp_ctx, struct loadparm_service *service,
1314 const char *pszParmValue, char **ptr)
1316 TALLOC_FREE(lp_ctx->globals->netbios_aliases);
1317 lp_ctx->globals->netbios_aliases = str_list_make_v3_const(lp_ctx->globals->ctx,
1318 pszParmValue, NULL);
1320 if (lp_ctx->s3_fns) {
1321 return lp_ctx->s3_fns->set_netbios_aliases(lp_ctx->globals->netbios_aliases);
1327 * idmap related parameters
1330 bool handle_idmap_backend(struct loadparm_context *lp_ctx, struct loadparm_service *service,
1331 const char *pszParmValue, char **ptr)
1333 if (lp_ctx->s3_fns) {
1334 lp_do_parameter_parametric(lp_ctx, service, "idmap config * : backend",
1338 return lpcfg_string_set(lp_ctx->globals->ctx, ptr, pszParmValue);
1341 bool handle_idmap_uid(struct loadparm_context *lp_ctx, struct loadparm_service *service,
1342 const char *pszParmValue, char **ptr)
1344 if (lp_ctx->s3_fns) {
1345 lp_do_parameter_parametric(lp_ctx, service, "idmap config * : range",
1349 return lpcfg_string_set(lp_ctx->globals->ctx, ptr, pszParmValue);
1352 bool handle_idmap_gid(struct loadparm_context *lp_ctx, struct loadparm_service *service,
1353 const char *pszParmValue, char **ptr)
1355 if (lp_ctx->s3_fns) {
1356 lp_do_parameter_parametric(lp_ctx, service, "idmap config * : range",
1360 return lpcfg_string_set(lp_ctx->globals->ctx, ptr, pszParmValue);
1363 bool handle_smb_ports(struct loadparm_context *lp_ctx, struct loadparm_service *service,
1364 const char *pszParmValue, char **ptr)
1366 static int parm_num = -1;
1370 if (!pszParmValue || !*pszParmValue) {
1374 if (parm_num == -1) {
1375 parm_num = lpcfg_map_parameter("smb ports");
1376 if (parm_num == -1) {
1381 if(!set_variable_helper(lp_ctx->globals->ctx, parm_num, ptr, "smb ports",
1386 list = lp_ctx->globals->smb_ports;
1391 /* Check that each port is a valid integer and within range */
1392 for (i = 0; list[i] != NULL; i++) {
1395 port = strtol(list[i], &end, 10);
1396 if (*end != '\0' || port <= 0 || port > 65535) {
1405 bool handle_smb2_max_credits(struct loadparm_context *lp_ctx,
1406 struct loadparm_service *service,
1407 const char *pszParmValue, char **ptr)
1409 int value = lp_int(pszParmValue);
1412 value = DEFAULT_SMB2_MAX_CREDITS;
1415 *(int *)ptr = value;
1420 bool handle_cups_encrypt(struct loadparm_context *lp_ctx,
1421 struct loadparm_service *service,
1422 const char *pszParmValue, char **ptr)
1425 #ifdef HAVE_HTTPCONNECTENCRYPT
1426 int value = lp_int(pszParmValue);
1430 result = HTTP_ENCRYPT_REQUIRED;
1433 result = HTTP_ENCRYPT_ALWAYS;
1436 result = HTTP_ENCRYPT_NEVER;
1443 *(int *)ptr = result;
1448 /***************************************************************************
1449 Initialise a copymap.
1450 ***************************************************************************/
1453 * Initializes service copymap
1454 * Note: pservice *must* be valid TALLOC_CTX
1456 void init_copymap(struct loadparm_service *pservice)
1460 TALLOC_FREE(pservice->copymap);
1462 pservice->copymap = bitmap_talloc(pservice, num_parameters());
1463 if (!pservice->copymap) {
1465 ("Couldn't allocate copymap!! (size %d)\n",
1466 (int)num_parameters()));
1468 for (i = 0; i < num_parameters(); i++) {
1469 bitmap_set(pservice->copymap, i);
1475 * Process a parametric option
1477 static bool lp_do_parameter_parametric(struct loadparm_context *lp_ctx,
1478 struct loadparm_service *service,
1479 const char *pszParmName,
1480 const char *pszParmValue, int flags)
1482 struct parmlist_entry **data;
1484 TALLOC_CTX *mem_ctx;
1486 while (isspace((unsigned char)*pszParmName)) {
1490 name = strlower_talloc(lp_ctx, pszParmName);
1491 if (!name) return false;
1493 if (service == NULL) {
1494 data = &lp_ctx->globals->param_opt;
1496 * s3 code cannot deal with parametric options stored on the globals ctx.
1498 if (lp_ctx->s3_fns != NULL) {
1501 mem_ctx = lp_ctx->globals->ctx;
1504 data = &service->param_opt;
1508 set_param_opt(mem_ctx, data, name, pszParmValue, flags);
1515 static bool set_variable_helper(TALLOC_CTX *mem_ctx, int parmnum, void *parm_ptr,
1516 const char *pszParmName, const char *pszParmValue)
1520 /* switch on the type of variable it is */
1521 switch (parm_table[parmnum].type)
1525 if (!set_boolean(pszParmValue, &b)) {
1526 DEBUG(0, ("set_variable_helper(%s): value is not "
1527 "boolean!\n", pszParmValue));
1530 *(bool *)parm_ptr = b;
1536 if (!set_boolean(pszParmValue, &b)) {
1537 DEBUG(0, ("set_variable_helper(%s): value is not "
1538 "boolean!\n", pszParmValue));
1541 *(bool *)parm_ptr = !b;
1546 *(int *)parm_ptr = lp_int(pszParmValue);
1550 *(char *)parm_ptr = *pszParmValue;
1554 i = sscanf(pszParmValue, "%o", (int *)parm_ptr);
1556 DEBUG ( 0, ("Invalid octal number %s\n", pszParmName ));
1564 if (conv_str_size_error(pszParmValue, &val)) {
1565 if (val <= INT_MAX) {
1566 *(int *)parm_ptr = (int)val;
1571 DEBUG(0, ("set_variable_helper(%s): value is not "
1572 "a valid size specifier!\n", pszParmValue));
1577 TALLOC_FREE(*(char ***)parm_ptr);
1578 *(char ***)parm_ptr = str_list_make_v3(mem_ctx,
1579 pszParmValue, NULL);
1584 char **new_list = str_list_make_v3(mem_ctx,
1585 pszParmValue, NULL);
1586 if (new_list == NULL) {
1590 for (i=0; new_list[i]; i++) {
1591 if (*(const char ***)parm_ptr != NULL &&
1592 new_list[i][0] == '+' &&
1595 if (!str_list_check(*(const char ***)parm_ptr,
1597 *(const char ***)parm_ptr = str_list_add(*(const char ***)parm_ptr,
1600 } else if (*(const char ***)parm_ptr != NULL &&
1601 new_list[i][0] == '-' &&
1604 str_list_remove(*(const char ***)parm_ptr,
1608 DEBUG(0, ("Unsupported list syntax for: %s = %s\n",
1609 pszParmName, pszParmValue));
1612 *(char ***)parm_ptr = new_list;
1620 lpcfg_string_set(mem_ctx, (char **)parm_ptr, pszParmValue);
1624 lpcfg_string_set_upper(mem_ctx, (char **)parm_ptr, pszParmValue);
1628 if (!lp_set_enum_parm(&parm_table[parmnum], pszParmValue, (int*)parm_ptr)) {
1639 static bool set_variable(TALLOC_CTX *mem_ctx, struct loadparm_service *service,
1640 int parmnum, void *parm_ptr,
1641 const char *pszParmName, const char *pszParmValue,
1642 struct loadparm_context *lp_ctx, bool on_globals)
1647 /* if it is a special case then go ahead */
1648 if (parm_table[parmnum].special) {
1649 ok = parm_table[parmnum].special(lp_ctx, service, pszParmValue,
1652 ok = set_variable_helper(mem_ctx, parmnum, parm_ptr,
1653 pszParmName, pszParmValue);
1660 if (on_globals && (lp_ctx->flags[parmnum] & FLAG_DEFAULT)) {
1661 lp_ctx->flags[parmnum] &= ~FLAG_DEFAULT;
1662 /* we have to also unset FLAG_DEFAULT on aliases */
1663 for (i=parmnum-1;i>=0 && parm_table[i].offset == parm_table[parmnum].offset;i--) {
1664 lp_ctx->flags[i] &= ~FLAG_DEFAULT;
1666 for (i=parmnum+1;i<num_parameters() && parm_table[i].offset == parm_table[parmnum].offset;i++) {
1667 lp_ctx->flags[i] &= ~FLAG_DEFAULT;
1674 bool lpcfg_do_global_parameter(struct loadparm_context *lp_ctx,
1675 const char *pszParmName, const char *pszParmValue)
1677 int parmnum = lpcfg_map_parameter(pszParmName);
1681 if (strchr(pszParmName, ':')) {
1682 return lp_do_parameter_parametric(lp_ctx, NULL, pszParmName, pszParmValue, 0);
1684 DEBUG(0, ("Ignoring unknown parameter \"%s\"\n", pszParmName));
1688 /* if the flag has been set on the command line, then don't allow override,
1689 but don't report an error */
1690 if (lp_ctx->flags[parmnum] & FLAG_CMDLINE) {
1694 if (parm_table[parmnum].flags & FLAG_DEPRECATED) {
1695 DEBUG(1, ("WARNING: The \"%s\" option is deprecated\n",
1699 parm_ptr = lpcfg_parm_ptr(lp_ctx, NULL, &parm_table[parmnum]);
1701 return set_variable(lp_ctx->globals->ctx, NULL, parmnum, parm_ptr,
1702 pszParmName, pszParmValue, lp_ctx, true);
1705 bool lpcfg_do_service_parameter(struct loadparm_context *lp_ctx,
1706 struct loadparm_service *service,
1707 const char *pszParmName, const char *pszParmValue)
1711 int parmnum = lpcfg_map_parameter(pszParmName);
1714 if (strchr(pszParmName, ':')) {
1715 return lp_do_parameter_parametric(lp_ctx, service, pszParmName, pszParmValue, 0);
1717 DEBUG(0, ("Ignoring unknown parameter \"%s\"\n", pszParmName));
1721 /* if the flag has been set on the command line, then don't allow override,
1722 but don't report an error */
1723 if (lp_ctx->flags[parmnum] & FLAG_CMDLINE) {
1727 if (parm_table[parmnum].flags & FLAG_DEPRECATED) {
1728 DEBUG(1, ("WARNING: The \"%s\" option is deprecated\n",
1732 if (parm_table[parmnum].p_class == P_GLOBAL) {
1734 ("Global parameter %s found in service section!\n",
1738 parm_ptr = ((char *)service) + parm_table[parmnum].offset;
1740 if (!service->copymap)
1741 init_copymap(service);
1743 /* this handles the aliases - set the copymap for other
1744 * entries with the same data pointer */
1745 for (i = 0; parm_table[i].label; i++)
1746 if (parm_table[i].offset == parm_table[parmnum].offset &&
1747 parm_table[i].p_class == parm_table[parmnum].p_class)
1748 bitmap_clear(service->copymap, i);
1750 return set_variable(service, service, parmnum, parm_ptr, pszParmName,
1751 pszParmValue, lp_ctx, false);
1755 * Process a parameter.
1758 bool lpcfg_do_parameter(const char *pszParmName, const char *pszParmValue,
1761 struct loadparm_context *lp_ctx = (struct loadparm_context *)userdata;
1763 if (lp_ctx->bInGlobalSection)
1764 return lpcfg_do_global_parameter(lp_ctx, pszParmName,
1767 return lpcfg_do_service_parameter(lp_ctx, lp_ctx->currentService,
1768 pszParmName, pszParmValue);
1772 variable argument do parameter
1774 bool lpcfg_do_global_parameter_var(struct loadparm_context *lp_ctx, const char *pszParmName, const char *fmt, ...) PRINTF_ATTRIBUTE(3, 4);
1775 bool lpcfg_do_global_parameter_var(struct loadparm_context *lp_ctx,
1776 const char *pszParmName, const char *fmt, ...)
1783 s = talloc_vasprintf(NULL, fmt, ap);
1785 ret = lpcfg_do_global_parameter(lp_ctx, pszParmName, s);
1792 set a parameter from the commandline - this is called from command line parameter
1793 parsing code. It sets the parameter then marks the parameter as unable to be modified
1794 by smb.conf processing
1796 bool lpcfg_set_cmdline(struct loadparm_context *lp_ctx, const char *pszParmName,
1797 const char *pszParmValue)
1802 while (isspace((unsigned char)*pszParmValue)) pszParmValue++;
1804 parmnum = lpcfg_map_parameter(pszParmName);
1806 if (parmnum < 0 && strchr(pszParmName, ':')) {
1807 /* set a parametric option */
1809 ok = lp_do_parameter_parametric(lp_ctx, NULL, pszParmName,
1810 pszParmValue, FLAG_CMDLINE);
1811 if (lp_ctx->s3_fns != NULL) {
1813 lp_ctx->s3_fns->store_cmdline(pszParmName, pszParmValue);
1820 DEBUG(0,("Unknown option '%s'\n", pszParmName));
1824 /* reset the CMDLINE flag in case this has been called before */
1825 lp_ctx->flags[parmnum] &= ~FLAG_CMDLINE;
1827 if (!lpcfg_do_global_parameter(lp_ctx, pszParmName, pszParmValue)) {
1831 lp_ctx->flags[parmnum] |= FLAG_CMDLINE;
1833 /* we have to also set FLAG_CMDLINE on aliases */
1835 i>=0 && parm_table[i].p_class == parm_table[parmnum].p_class &&
1836 parm_table[i].offset == parm_table[parmnum].offset;
1838 lp_ctx->flags[i] |= FLAG_CMDLINE;
1841 i<num_parameters() &&
1842 parm_table[i].p_class == parm_table[parmnum].p_class &&
1843 parm_table[i].offset == parm_table[parmnum].offset;
1845 lp_ctx->flags[i] |= FLAG_CMDLINE;
1848 if (lp_ctx->s3_fns != NULL) {
1849 lp_ctx->s3_fns->store_cmdline(pszParmName, pszParmValue);
1856 set a option from the commandline in 'a=b' format. Use to support --option
1858 bool lpcfg_set_option(struct loadparm_context *lp_ctx, const char *option)
1863 s = talloc_strdup(NULL, option);
1876 ret = lpcfg_set_cmdline(lp_ctx, s, p+1);
1882 #define BOOLSTR(b) ((b) ? "Yes" : "No")
1885 * Print a parameter of the specified type.
1888 void lpcfg_print_parameter(struct parm_struct *p, void *ptr, FILE * f)
1890 /* For the seperation of lists values that we print below */
1891 const char *list_sep = ", ";
1896 for (i = 0; p->enum_list[i].name; i++) {
1897 if (*(int *)ptr == p->enum_list[i].value) {
1899 p->enum_list[i].name);
1906 fprintf(f, "%s", BOOLSTR(*(bool *)ptr));
1910 fprintf(f, "%s", BOOLSTR(!*(bool *)ptr));
1915 fprintf(f, "%d", *(int *)ptr);
1919 fprintf(f, "%c", *(char *)ptr);
1923 int val = *(int *)ptr;
1927 fprintf(f, "0%03o", val);
1936 if ((char ***)ptr && *(char ***)ptr) {
1937 char **list = *(char ***)ptr;
1938 for (; *list; list++) {
1939 /* surround strings with whitespace in double quotes */
1940 if (*(list+1) == NULL) {
1941 /* last item, no extra separator */
1944 if ( strchr_m( *list, ' ' ) ) {
1945 fprintf(f, "\"%s\"%s", *list, list_sep);
1947 fprintf(f, "%s%s", *list, list_sep);
1955 if (*(char **)ptr) {
1956 fprintf(f, "%s", *(char **)ptr);
1963 * Check if two parameters are equal.
1966 static bool lpcfg_equal_parameter(parm_type type, void *ptr1, void *ptr2)
1971 return (*((bool *)ptr1) == *((bool *)ptr2));
1977 return (*((int *)ptr1) == *((int *)ptr2));
1980 return (*((char *)ptr1) == *((char *)ptr2));
1984 return str_list_equal(*(const char ***)ptr1, *(const char ***)ptr2);
1989 char *p1 = *(char **)ptr1, *p2 = *(char **)ptr2;
1994 return (p1 == p2 || strequal(p1, p2));
2001 * Process a new section (service).
2003 * At this stage all sections are services.
2004 * Later we'll have special sections that permit server parameters to be set.
2005 * Returns True on success, False on failure.
2008 static bool do_section(const char *pszSectionName, void *userdata)
2010 struct loadparm_context *lp_ctx = (struct loadparm_context *)userdata;
2014 if (lp_ctx->s3_fns != NULL) {
2015 return lp_ctx->s3_fns->do_section(pszSectionName, lp_ctx);
2018 isglobal = ((strwicmp(pszSectionName, GLOBAL_NAME) == 0) ||
2019 (strwicmp(pszSectionName, GLOBAL_NAME2) == 0));
2023 /* if we've just struck a global section, note the fact. */
2024 lp_ctx->bInGlobalSection = isglobal;
2026 /* check for multiple global sections */
2027 if (lp_ctx->bInGlobalSection) {
2028 DEBUG(4, ("Processing section \"[%s]\"\n", pszSectionName));
2032 /* if we have a current service, tidy it up before moving on */
2035 if (lp_ctx->currentService != NULL)
2036 bRetval = lpcfg_service_ok(lp_ctx->currentService);
2038 /* if all is still well, move to the next record in the services array */
2040 /* We put this here to avoid an odd message order if messages are */
2041 /* issued by the post-processing of a previous section. */
2042 DEBUG(4, ("Processing section \"[%s]\"\n", pszSectionName));
2044 if ((lp_ctx->currentService = lpcfg_add_service(lp_ctx, lp_ctx->sDefault,
2047 DEBUG(0, ("Failed to add a new service\n"));
2057 * Determine if a particular base parameter is currently set to the default value.
2060 static bool is_default(void *base_structure, int i)
2062 void *def_ptr = ((char *)base_structure) + parm_table[i].offset;
2063 switch (parm_table[i].type) {
2066 return str_list_equal((const char * const *)parm_table[i].def.lvalue,
2067 *(const char * const **)def_ptr);
2070 return strequal(parm_table[i].def.svalue,
2074 return parm_table[i].def.bvalue ==
2081 return parm_table[i].def.ivalue ==
2088 *Display the contents of the global structure.
2091 void lpcfg_dump_globals(struct loadparm_context *lp_ctx, FILE *f,
2095 struct parmlist_entry *data;
2097 fprintf(f, "# Global parameters\n[global]\n");
2099 for (i = 0; parm_table[i].label; i++) {
2100 if (parm_table[i].p_class != P_GLOBAL) {
2104 if (parm_table[i].flags & FLAG_SYNONYM) {
2108 if (!show_defaults) {
2109 if (lp_ctx->flags && (lp_ctx->flags[i] & FLAG_DEFAULT)) {
2113 if (is_default(lp_ctx->globals, i)) {
2118 fprintf(f, "\t%s = ", parm_table[i].label);
2119 lpcfg_print_parameter(&parm_table[i], lpcfg_parm_ptr(lp_ctx, NULL, &parm_table[i]), f);
2122 if (lp_ctx->globals->param_opt != NULL) {
2123 for (data = lp_ctx->globals->param_opt; data;
2124 data = data->next) {
2125 if (!show_defaults && (data->priority & FLAG_DEFAULT)) {
2128 fprintf(f, "\t%s = %s\n", data->key, data->value);
2135 * Display the contents of a single services record.
2138 void lpcfg_dump_a_service(struct loadparm_service * pService, struct loadparm_service *sDefault, FILE * f,
2139 unsigned int *flags, bool show_defaults)
2142 struct parmlist_entry *data;
2144 if (pService != sDefault)
2145 fprintf(f, "\n[%s]\n", pService->szService);
2147 for (i = 0; parm_table[i].label; i++) {
2148 if (parm_table[i].p_class != P_LOCAL) {
2152 if (parm_table[i].flags & FLAG_SYNONYM) {
2156 if (*parm_table[i].label == '-') {
2160 if (pService == sDefault) {
2161 if (!show_defaults) {
2162 if (flags && (flags[i] & FLAG_DEFAULT)) {
2166 if (is_default(sDefault, i)) {
2173 equal = lpcfg_equal_parameter(parm_table[i].type,
2174 ((char *)pService) +
2175 parm_table[i].offset,
2176 ((char *)sDefault) +
2177 parm_table[i].offset);
2183 fprintf(f, "\t%s = ", parm_table[i].label);
2184 lpcfg_print_parameter(&parm_table[i],
2185 ((char *)pService) + parm_table[i].offset, f);
2188 if (pService->param_opt != NULL) {
2189 for (data = pService->param_opt; data; data = data->next) {
2190 if (!show_defaults && (data->priority & FLAG_DEFAULT)) {
2193 fprintf(f, "\t%s = %s\n", data->key, data->value);
2198 bool lpcfg_dump_a_parameter(struct loadparm_context *lp_ctx,
2199 struct loadparm_service *service,
2200 const char *parm_name, FILE * f)
2202 struct parm_struct *parm;
2204 char *local_parm_name;
2206 const char *parm_opt_value;
2208 /* check for parametrical option */
2209 local_parm_name = talloc_strdup(lp_ctx, parm_name);
2210 if (local_parm_name == NULL) {
2214 parm_opt = strchr( local_parm_name, ':');
2219 if (strlen(parm_opt)) {
2220 parm_opt_value = lpcfg_parm_string(lp_ctx, service,
2221 local_parm_name, parm_opt);
2222 if (parm_opt_value) {
2223 fprintf(f, "%s\n", parm_opt_value);
2230 /* parameter is not parametric, search the table */
2231 parm = lpcfg_parm_struct(lp_ctx, parm_name);
2236 if (service != NULL && parm->p_class == P_GLOBAL) {
2240 ptr = lpcfg_parm_ptr(lp_ctx, service,parm);
2242 lpcfg_print_parameter(parm, ptr, f);
2248 * Auto-load some home services.
2250 static void lpcfg_add_auto_services(struct loadparm_context *lp_ctx,
2256 /***************************************************************************
2257 Initialise the sDefault parameter structure for the printer values.
2258 ***************************************************************************/
2260 void init_printer_values(struct loadparm_context *lp_ctx, TALLOC_CTX *ctx,
2261 struct loadparm_service *pService)
2263 /* choose defaults depending on the type of printing */
2264 switch (pService->printing) {
2269 lpcfg_string_set(ctx, &pService->lpq_command, "lpq -P'%p'");
2270 lpcfg_string_set(ctx, &pService->lprm_command, "lprm -P'%p' %j");
2271 lpcfg_string_set(ctx, &pService->print_command, "lpr -r -P'%p' %s");
2276 lpcfg_string_set(ctx, &pService->lpq_command, "lpq -P'%p'");
2277 lpcfg_string_set(ctx, &pService->lprm_command, "lprm -P'%p' %j");
2278 lpcfg_string_set(ctx, &pService->print_command, "lpr -r -P'%p' %s");
2279 lpcfg_string_set(ctx, &pService->queuepause_command, "lpc stop '%p'");
2280 lpcfg_string_set(ctx, &pService->queueresume_command, "lpc start '%p'");
2281 lpcfg_string_set(ctx, &pService->lppause_command, "lpc hold '%p' %j");
2282 lpcfg_string_set(ctx, &pService->lpresume_command, "lpc release '%p' %j");
2287 /* set the lpq command to contain the destination printer
2288 name only. This is used by cups_queue_get() */
2289 lpcfg_string_set(ctx, &pService->lpq_command, "%p");
2290 lpcfg_string_set(ctx, &pService->lprm_command, "");
2291 lpcfg_string_set(ctx, &pService->print_command, "");
2292 lpcfg_string_set(ctx, &pService->lppause_command, "");
2293 lpcfg_string_set(ctx, &pService->lpresume_command, "");
2294 lpcfg_string_set(ctx, &pService->queuepause_command, "");
2295 lpcfg_string_set(ctx, &pService->queueresume_command, "");
2300 lpcfg_string_set(ctx, &pService->lpq_command, "lpstat -o%p");
2301 lpcfg_string_set(ctx, &pService->lprm_command, "cancel %p-%j");
2302 lpcfg_string_set(ctx, &pService->print_command, "lp -c -d%p %s; rm %s");
2303 lpcfg_string_set(ctx, &pService->queuepause_command, "disable %p");
2304 lpcfg_string_set(ctx, &pService->queueresume_command, "enable %p");
2306 lpcfg_string_set(ctx, &pService->lppause_command, "lp -i %p-%j -H hold");
2307 lpcfg_string_set(ctx, &pService->lpresume_command, "lp -i %p-%j -H resume");
2312 lpcfg_string_set(ctx, &pService->lpq_command, "lpq -P%p");
2313 lpcfg_string_set(ctx, &pService->lprm_command, "lprm -P%p %j");
2314 lpcfg_string_set(ctx, &pService->print_command, "lp -r -P%p %s");
2317 #if defined(DEVELOPER) || defined(ENABLE_SELFTEST)
2321 const char *tdbfile;
2322 TALLOC_CTX *tmp_ctx = talloc_new(ctx);
2325 tmp = lpcfg_parm_string(lp_ctx, NULL, "vlp", "tdbfile");
2327 tmp = "/tmp/vlp.tdb";
2330 tdbfile = talloc_asprintf(tmp_ctx, "tdbfile=%s", tmp);
2331 if (tdbfile == NULL) {
2332 tdbfile="tdbfile=/tmp/vlp.tdb";
2335 tmp = talloc_asprintf(tmp_ctx, "vlp %s print %%p %%s",
2337 lpcfg_string_set(ctx, &pService->print_command,
2338 tmp ? tmp : "vlp print %p %s");
2340 tmp = talloc_asprintf(tmp_ctx, "vlp %s lpq %%p",
2342 lpcfg_string_set(ctx, &pService->lpq_command,
2343 tmp ? tmp : "vlp lpq %p");
2345 tmp = talloc_asprintf(tmp_ctx, "vlp %s lprm %%p %%j",
2347 lpcfg_string_set(ctx, &pService->lprm_command,
2348 tmp ? tmp : "vlp lprm %p %j");
2350 tmp = talloc_asprintf(tmp_ctx, "vlp %s lppause %%p %%j",
2352 lpcfg_string_set(ctx, &pService->lppause_command,
2353 tmp ? tmp : "vlp lppause %p %j");
2355 tmp = talloc_asprintf(tmp_ctx, "vlp %s lpresume %%p %%j",
2357 lpcfg_string_set(ctx, &pService->lpresume_command,
2358 tmp ? tmp : "vlp lpresume %p %j");
2360 tmp = talloc_asprintf(tmp_ctx, "vlp %s queuepause %%p",
2362 lpcfg_string_set(ctx, &pService->queuepause_command,
2363 tmp ? tmp : "vlp queuepause %p");
2365 tmp = talloc_asprintf(tmp_ctx, "vlp %s queueresume %%p",
2367 lpcfg_string_set(ctx, &pService->queueresume_command,
2368 tmp ? tmp : "vlp queueresume %p");
2369 TALLOC_FREE(tmp_ctx);
2373 #endif /* DEVELOPER */
2379 * Unload unused services.
2382 void lpcfg_killunused(struct loadparm_context *lp_ctx,
2383 struct smbsrv_connection *smb,
2384 bool (*snumused) (struct smbsrv_connection *, int))
2388 if (lp_ctx->s3_fns != NULL) {
2389 smb_panic("Cannot be used from an s3 loadparm ctx");
2392 for (i = 0; i < lp_ctx->iNumServices; i++) {
2393 if (lp_ctx->services[i] == NULL)
2396 if (!snumused || !snumused(smb, i)) {
2397 talloc_free(lp_ctx->services[i]);
2398 lp_ctx->services[i] = NULL;
2404 static int lpcfg_destructor(struct loadparm_context *lp_ctx)
2406 struct parmlist_entry *data;
2408 if (lp_ctx->refuse_free) {
2409 /* someone is trying to free the
2410 global_loadparm_context.
2411 We can't allow that. */
2415 if (lp_ctx->globals->param_opt != NULL) {
2416 struct parmlist_entry *next;
2417 for (data = lp_ctx->globals->param_opt; data; data=next) {
2419 if (data->priority & FLAG_CMDLINE) continue;
2420 DLIST_REMOVE(lp_ctx->globals->param_opt, data);
2428 struct defaults_hook_data {
2430 lpcfg_defaults_hook hook;
2431 struct defaults_hook_data *prev, *next;
2432 } *defaults_hooks = NULL;
2435 bool lpcfg_register_defaults_hook(const char *name, lpcfg_defaults_hook hook)
2437 struct defaults_hook_data *hook_data = talloc(talloc_autofree_context(),
2438 struct defaults_hook_data);
2439 hook_data->name = talloc_strdup(hook_data, name);
2440 hook_data->hook = hook;
2441 DLIST_ADD(defaults_hooks, hook_data);
2446 * Initialise the global parameter structure.
2448 * Note that most callers should use loadparm_init_global() instead
2450 struct loadparm_context *loadparm_init(TALLOC_CTX *mem_ctx)
2454 struct loadparm_context *lp_ctx;
2455 struct parmlist_entry *parm;
2457 struct defaults_hook_data *defaults_hook;
2459 lp_ctx = talloc_zero(mem_ctx, struct loadparm_context);
2463 talloc_set_destructor(lp_ctx, lpcfg_destructor);
2464 lp_ctx->bInGlobalSection = true;
2465 lp_ctx->globals = talloc_zero(lp_ctx, struct loadparm_global);
2466 /* This appears odd, but globals in s3 isn't a pointer */
2467 lp_ctx->globals->ctx = lp_ctx->globals;
2468 lp_ctx->sDefault = talloc_zero(lp_ctx, struct loadparm_service);
2469 lp_ctx->flags = talloc_zero_array(lp_ctx, unsigned int, num_parameters());
2471 lp_ctx->sDefault->max_print_jobs = 1000;
2472 lp_ctx->sDefault->available = true;
2473 lp_ctx->sDefault->browseable = true;
2474 lp_ctx->sDefault->read_only = true;
2475 lp_ctx->sDefault->map_archive = true;
2476 lp_ctx->sDefault->strict_locking = true;
2477 lp_ctx->sDefault->oplocks = true;
2478 lp_ctx->sDefault->create_mask = 0744;
2479 lp_ctx->sDefault->force_create_mode = 0000;
2480 lp_ctx->sDefault->directory_mask = 0755;
2481 lp_ctx->sDefault->force_directory_mode = 0000;
2483 DEBUG(3, ("Initialising global parameters\n"));
2485 for (i = 0; parm_table[i].label; i++) {
2486 if ((parm_table[i].type == P_STRING ||
2487 parm_table[i].type == P_USTRING) &&
2488 !(lp_ctx->flags[i] & FLAG_CMDLINE)) {
2489 TALLOC_CTX *parent_mem;
2491 if (parm_table[i].p_class == P_LOCAL) {
2492 parent_mem = lp_ctx->sDefault;
2493 r = (char **)(((char *)lp_ctx->sDefault) + parm_table[i].offset);
2495 parent_mem = lp_ctx->globals;
2496 r = (char **)(((char *)lp_ctx->globals) + parm_table[i].offset);
2498 lpcfg_string_set(parent_mem, r, "");
2502 logfile = talloc_asprintf(lp_ctx, "%s/log.samba", dyn_LOGFILEBASE);
2503 lpcfg_do_global_parameter(lp_ctx, "log file", logfile);
2504 talloc_free(logfile);
2506 lpcfg_do_global_parameter(lp_ctx, "log level", "0");
2508 lpcfg_do_global_parameter(lp_ctx, "syslog", "1");
2509 lpcfg_do_global_parameter(lp_ctx, "syslog only", "No");
2510 lpcfg_do_global_parameter(lp_ctx, "debug timestamp", "Yes");
2511 lpcfg_do_global_parameter(lp_ctx, "debug prefix timestamp", "No");
2512 lpcfg_do_global_parameter(lp_ctx, "debug hires timestamp", "Yes");
2513 lpcfg_do_global_parameter(lp_ctx, "debug pid", "No");
2514 lpcfg_do_global_parameter(lp_ctx, "debug uid", "No");
2515 lpcfg_do_global_parameter(lp_ctx, "debug class", "No");
2517 lpcfg_do_global_parameter(lp_ctx, "share backend", "classic");
2519 lpcfg_do_global_parameter(lp_ctx, "server role", "auto");
2520 lpcfg_do_global_parameter(lp_ctx, "domain logons", "No");
2521 lpcfg_do_global_parameter(lp_ctx, "domain master", "Auto");
2523 /* options that can be set on the command line must be initialised via
2524 the slower lpcfg_do_global_parameter() to ensure that FLAG_CMDLINE is obeyed */
2526 lpcfg_do_global_parameter(lp_ctx, "socket options", "TCP_NODELAY");
2528 lpcfg_do_global_parameter(lp_ctx, "workgroup", DEFAULT_WORKGROUP);
2529 myname = get_myname(lp_ctx);
2530 lpcfg_do_global_parameter(lp_ctx, "netbios name", myname);
2531 talloc_free(myname);
2532 lpcfg_do_global_parameter(lp_ctx, "name resolve order", "lmhosts wins host bcast");
2534 lpcfg_do_global_parameter(lp_ctx, "fstype", "NTFS");
2536 lpcfg_do_global_parameter(lp_ctx, "ntvfs handler", "unixuid default");
2537 lpcfg_do_global_parameter(lp_ctx, "max connections", "0");
2539 lpcfg_do_global_parameter(lp_ctx, "dcerpc endpoint servers", "epmapper wkssvc rpcecho samr netlogon lsarpc spoolss drsuapi dssetup unixinfo browser eventlog6 backupkey dnsserver");
2540 lpcfg_do_global_parameter(lp_ctx, "server services", "s3fs rpc nbt wrepl ldap cldap kdc drepl winbindd ntp_signd kcc dnsupdate dns");
2541 lpcfg_do_global_parameter(lp_ctx, "kccsrv:samba_kcc", "false");
2542 /* the winbind method for domain controllers is for both RODC
2543 auth forwarding and for trusted domains */
2544 lpcfg_do_global_parameter(lp_ctx, "private dir", dyn_PRIVATE_DIR);
2545 lpcfg_do_global_parameter(lp_ctx, "registry:HKEY_LOCAL_MACHINE", "hklm.ldb");
2547 /* This hive should be dynamically generated by Samba using
2548 data from the sam, but for the moment leave it in a tdb to
2549 keep regedt32 from popping up an annoying dialog. */
2550 lpcfg_do_global_parameter(lp_ctx, "registry:HKEY_USERS", "hku.ldb");
2552 /* using UTF8 by default allows us to support all chars */
2553 lpcfg_do_global_parameter(lp_ctx, "unix charset", "UTF-8");
2555 /* Use codepage 850 as a default for the dos character set */
2556 lpcfg_do_global_parameter(lp_ctx, "dos charset", "CP850");
2559 * Allow the default PASSWD_CHAT to be overridden in local.h.
2561 lpcfg_do_global_parameter(lp_ctx, "passwd chat", DEFAULT_PASSWD_CHAT);
2563 lpcfg_do_global_parameter(lp_ctx, "pid directory", dyn_PIDDIR);
2564 lpcfg_do_global_parameter(lp_ctx, "lock dir", dyn_LOCKDIR);
2565 lpcfg_do_global_parameter(lp_ctx, "state directory", dyn_STATEDIR);
2566 lpcfg_do_global_parameter(lp_ctx, "cache directory", dyn_CACHEDIR);
2567 lpcfg_do_global_parameter(lp_ctx, "ncalrpc dir", dyn_NCALRPCDIR);
2569 lpcfg_do_global_parameter(lp_ctx, "nbt client socket address", "0.0.0.0");
2570 lpcfg_do_global_parameter_var(lp_ctx, "server string",
2571 "Samba %s", SAMBA_VERSION_STRING);
2573 lpcfg_do_global_parameter(lp_ctx, "password server", "*");
2575 lpcfg_do_global_parameter(lp_ctx, "max mux", "50");
2576 lpcfg_do_global_parameter(lp_ctx, "max xmit", "16644");
2577 lpcfg_do_global_parameter(lp_ctx, "host msdfs", "true");
2579 lpcfg_do_global_parameter(lp_ctx, "LargeReadwrite", "True");
2580 lpcfg_do_global_parameter(lp_ctx, "server min protocol", "LANMAN1");
2581 lpcfg_do_global_parameter(lp_ctx, "server max protocol", "SMB3");
2582 lpcfg_do_global_parameter(lp_ctx, "client min protocol", "CORE");
2583 lpcfg_do_global_parameter(lp_ctx, "client max protocol", "default");
2584 lpcfg_do_global_parameter(lp_ctx, "security", "AUTO");
2585 lpcfg_do_global_parameter(lp_ctx, "EncryptPasswords", "True");
2586 lpcfg_do_global_parameter(lp_ctx, "ReadRaw", "True");
2587 lpcfg_do_global_parameter(lp_ctx, "WriteRaw", "True");
2588 lpcfg_do_global_parameter(lp_ctx, "NullPasswords", "False");
2589 lpcfg_do_global_parameter(lp_ctx, "old password allowed period", "60");
2590 lpcfg_do_global_parameter(lp_ctx, "ObeyPamRestrictions", "False");
2592 lpcfg_do_global_parameter(lp_ctx, "TimeServer", "False");
2593 lpcfg_do_global_parameter(lp_ctx, "BindInterfacesOnly", "False");
2594 lpcfg_do_global_parameter(lp_ctx, "Unicode", "True");
2595 lpcfg_do_global_parameter(lp_ctx, "ClientLanManAuth", "False");
2596 lpcfg_do_global_parameter(lp_ctx, "ClientNTLMv2Auth", "True");
2597 lpcfg_do_global_parameter(lp_ctx, "LanmanAuth", "False");
2598 lpcfg_do_global_parameter(lp_ctx, "NTLMAuth", "True");
2599 lpcfg_do_global_parameter(lp_ctx, "client use spnego principal", "False");
2601 lpcfg_do_global_parameter(lp_ctx, "UnixExtensions", "True");
2603 lpcfg_do_global_parameter(lp_ctx, "PreferredMaster", "Auto");
2604 lpcfg_do_global_parameter(lp_ctx, "LocalMaster", "True");
2606 lpcfg_do_global_parameter(lp_ctx, "wins support", "False");
2607 lpcfg_do_global_parameter(lp_ctx, "dns proxy", "True");
2609 lpcfg_do_global_parameter(lp_ctx, "winbind separator", "\\");
2610 lpcfg_do_global_parameter(lp_ctx, "winbind sealed pipes", "True");
2611 lpcfg_do_global_parameter(lp_ctx, "require strong key", "True");
2612 lpcfg_do_global_parameter(lp_ctx, "winbindd socket directory", dyn_WINBINDD_SOCKET_DIR);
2613 lpcfg_do_global_parameter(lp_ctx, "winbindd privileged socket directory", dyn_WINBINDD_PRIVILEGED_SOCKET_DIR);
2614 lpcfg_do_global_parameter(lp_ctx, "ntp signd socket directory", dyn_NTP_SIGND_SOCKET_DIR);
2615 lpcfg_do_global_parameter_var(lp_ctx, "dns update command", "%s/samba_dnsupdate", dyn_SCRIPTSBINDIR);
2616 lpcfg_do_global_parameter_var(lp_ctx, "spn update command", "%s/samba_spnupdate", dyn_SCRIPTSBINDIR);
2617 lpcfg_do_global_parameter_var(lp_ctx, "samba kcc command",
2618 "%s/samba_kcc", dyn_SCRIPTSBINDIR);
2619 lpcfg_do_global_parameter(lp_ctx, "template shell", "/bin/false");
2620 lpcfg_do_global_parameter(lp_ctx, "template homedir", "/home/%D/%U");
2622 lpcfg_do_global_parameter(lp_ctx, "client signing", "default");
2623 lpcfg_do_global_parameter(lp_ctx, "server signing", "default");
2625 lpcfg_do_global_parameter(lp_ctx, "use spnego", "True");
2627 lpcfg_do_global_parameter(lp_ctx, "use mmap", "True");
2629 lpcfg_do_global_parameter(lp_ctx, "smb ports", "445 139");
2630 lpcfg_do_global_parameter_var(lp_ctx, "nbt port", "%d", NBT_NAME_SERVICE_PORT);
2631 lpcfg_do_global_parameter_var(lp_ctx, "dgram port", "%d", NBT_DGRAM_SERVICE_PORT);
2632 lpcfg_do_global_parameter(lp_ctx, "cldap port", "389");
2633 lpcfg_do_global_parameter(lp_ctx, "krb5 port", "88");
2634 lpcfg_do_global_parameter(lp_ctx, "kpasswd port", "464");
2635 lpcfg_do_global_parameter(lp_ctx, "web port", "901");
2637 lpcfg_do_global_parameter(lp_ctx, "nt status support", "True");
2639 lpcfg_do_global_parameter(lp_ctx, "max wins ttl", "518400"); /* 6 days */
2640 lpcfg_do_global_parameter(lp_ctx, "min wins ttl", "21600");
2642 lpcfg_do_global_parameter(lp_ctx, "tls enabled", "True");
2643 lpcfg_do_global_parameter(lp_ctx, "tls keyfile", "tls/key.pem");
2644 lpcfg_do_global_parameter(lp_ctx, "tls certfile", "tls/cert.pem");
2645 lpcfg_do_global_parameter(lp_ctx, "tls cafile", "tls/ca.pem");
2646 lpcfg_do_global_parameter(lp_ctx, "tls priority", "NORMAL:-VERS-SSL3.0");
2647 lpcfg_do_global_parameter(lp_ctx, "prefork children:smb", "4");
2649 lpcfg_do_global_parameter(lp_ctx, "rndc command", "/usr/sbin/rndc");
2650 lpcfg_do_global_parameter(lp_ctx, "nsupdate command", "/usr/bin/nsupdate -g");
2652 lpcfg_do_global_parameter(lp_ctx, "allow dns updates", "secure only");
2653 lpcfg_do_global_parameter(lp_ctx, "dns forwarder", "");
2655 lpcfg_do_global_parameter(lp_ctx, "algorithmic rid base", "1000");
2657 lpcfg_do_global_parameter(lp_ctx, "enhanced browsing", "True");
2659 lpcfg_do_global_parameter(lp_ctx, "winbind nss info", "template");
2661 lpcfg_do_global_parameter(lp_ctx, "server schannel", "Auto");
2663 lpcfg_do_global_parameter(lp_ctx, "short preserve case", "True");
2665 lpcfg_do_global_parameter(lp_ctx, "max open files", "16384");
2667 lpcfg_do_global_parameter(lp_ctx, "cups connection timeout", "30");
2669 lpcfg_do_global_parameter(lp_ctx, "locking", "True");
2671 lpcfg_do_global_parameter(lp_ctx, "block size", "1024");
2673 lpcfg_do_global_parameter(lp_ctx, "client use spnego", "True");
2675 lpcfg_do_global_parameter(lp_ctx, "change notify", "True");
2677 lpcfg_do_global_parameter(lp_ctx, "name cache timeout", "660");
2679 lpcfg_do_global_parameter(lp_ctx, "defer sharing violations", "True");
2681 lpcfg_do_global_parameter(lp_ctx, "ldap replication sleep", "1000");
2683 lpcfg_do_global_parameter(lp_ctx, "idmap backend", "tdb");
2685 lpcfg_do_global_parameter(lp_ctx, "enable privileges", "True");
2687 lpcfg_do_global_parameter_var(lp_ctx, "smb2 max write", "%u", DEFAULT_SMB2_MAX_WRITE);
2689 lpcfg_do_global_parameter(lp_ctx, "passdb backend", "tdbsam");
2691 lpcfg_do_global_parameter(lp_ctx, "getwd cache", "True");
2693 lpcfg_do_global_parameter(lp_ctx, "winbind nested groups", "True");
2695 lpcfg_do_global_parameter(lp_ctx, "mangled names", "True");
2697 lpcfg_do_global_parameter_var(lp_ctx, "smb2 max credits", "%u", DEFAULT_SMB2_MAX_CREDITS);
2699 lpcfg_do_global_parameter(lp_ctx, "ldap ssl", "start tls");
2701 lpcfg_do_global_parameter(lp_ctx, "ldap deref", "auto");
2703 lpcfg_do_global_parameter(lp_ctx, "lm interval", "60");
2705 lpcfg_do_global_parameter(lp_ctx, "mangling method", "hash2");
2707 lpcfg_do_global_parameter(lp_ctx, "hide dot files", "True");
2709 lpcfg_do_global_parameter(lp_ctx, "browse list", "True");
2711 lpcfg_do_global_parameter(lp_ctx, "passwd chat timeout", "2");
2713 lpcfg_do_global_parameter(lp_ctx, "guest account", GUEST_ACCOUNT);
2715 lpcfg_do_global_parameter(lp_ctx, "client schannel", "auto");
2717 lpcfg_do_global_parameter(lp_ctx, "smb encrypt", "default");
2719 lpcfg_do_global_parameter(lp_ctx, "max log size", "5000");
2721 lpcfg_do_global_parameter(lp_ctx, "idmap negative cache time", "120");
2723 lpcfg_do_global_parameter(lp_ctx, "ldap follow referral", "auto");
2725 lpcfg_do_global_parameter(lp_ctx, "multicast dns register", "yes");
2727 lpcfg_do_global_parameter(lp_ctx, "winbind reconnect delay", "30");
2729 lpcfg_do_global_parameter(lp_ctx, "winbind request timeout", "60");
2731 lpcfg_do_global_parameter(lp_ctx, "nt acl support", "yes");
2733 lpcfg_do_global_parameter(lp_ctx, "acl check permissions", "yes");
2735 lpcfg_do_global_parameter(lp_ctx, "keepalive", "300");
2737 lpcfg_do_global_parameter(lp_ctx, "smbd profiling level", "off");
2739 lpcfg_do_global_parameter(lp_ctx, "winbind cache time", "300");
2741 lpcfg_do_global_parameter(lp_ctx, "level2 oplocks", "yes");
2743 lpcfg_do_global_parameter(lp_ctx, "show add printer wizard", "yes");
2745 lpcfg_do_global_parameter(lp_ctx, "allocation roundup size", "1048576");
2747 lpcfg_do_global_parameter(lp_ctx, "ldap page size", "1024");
2749 lpcfg_do_global_parameter(lp_ctx, "kernel share modes", "yes");
2751 lpcfg_do_global_parameter(lp_ctx, "strict locking", "Auto");
2753 lpcfg_do_global_parameter(lp_ctx, "map readonly", "yes");
2755 lpcfg_do_global_parameter(lp_ctx, "allow trusted domains", "yes");
2757 lpcfg_do_global_parameter(lp_ctx, "default devmode", "yes");
2759 lpcfg_do_global_parameter(lp_ctx, "os level", "20");
2761 lpcfg_do_global_parameter(lp_ctx, "dos filetimes", "yes");
2763 lpcfg_do_global_parameter(lp_ctx, "mangling char", "~");
2765 lpcfg_do_global_parameter(lp_ctx, "printcap cache time", "750");
2767 lpcfg_do_global_parameter(lp_ctx, "create krb5 conf", "yes");
2769 lpcfg_do_global_parameter(lp_ctx, "winbind max clients", "200");
2771 lpcfg_do_global_parameter(lp_ctx, "acl map full control", "yes");
2773 lpcfg_do_global_parameter(lp_ctx, "nt pipe support", "yes");
2775 lpcfg_do_global_parameter(lp_ctx, "ldap debug threshold", "10");
2777 lpcfg_do_global_parameter(lp_ctx, "client ldap sasl wrapping", "sign");
2779 lpcfg_do_global_parameter(lp_ctx, "follow symlinks", "yes");
2781 lpcfg_do_global_parameter(lp_ctx, "machine password timeout", "604800");
2783 lpcfg_do_global_parameter(lp_ctx, "ldap connection timeout", "2");
2785 lpcfg_do_global_parameter(lp_ctx, "winbind expand groups", "0");
2787 lpcfg_do_global_parameter(lp_ctx, "stat cache", "yes");
2789 lpcfg_do_global_parameter(lp_ctx, "lpq cache time", "30");
2791 lpcfg_do_global_parameter_var(lp_ctx, "smb2 max trans", "%u", DEFAULT_SMB2_MAX_TRANSACT);
2793 lpcfg_do_global_parameter_var(lp_ctx, "smb2 max read", "%u", DEFAULT_SMB2_MAX_READ);
2795 lpcfg_do_global_parameter(lp_ctx, "durable handles", "yes");
2797 lpcfg_do_global_parameter(lp_ctx, "max stat cache size", "256");
2799 lpcfg_do_global_parameter(lp_ctx, "ldap passwd sync", "no");
2801 lpcfg_do_global_parameter(lp_ctx, "kernel change notify", "yes");
2803 lpcfg_do_global_parameter(lp_ctx, "max ttl", "259200");
2805 lpcfg_do_global_parameter(lp_ctx, "blocking locks", "yes");
2807 lpcfg_do_global_parameter(lp_ctx, "oplock contention limit", "2");
2809 lpcfg_do_global_parameter(lp_ctx, "load printers", "yes");
2811 lpcfg_do_global_parameter(lp_ctx, "idmap cache time", "604800");
2813 lpcfg_do_global_parameter(lp_ctx, "preserve case", "yes");
2815 lpcfg_do_global_parameter(lp_ctx, "lm announce", "auto");
2817 lpcfg_do_global_parameter(lp_ctx, "afs token lifetime", "604800");
2819 lpcfg_do_global_parameter(lp_ctx, "enable core files", "yes");
2821 lpcfg_do_global_parameter(lp_ctx, "winbind max domain connections", "1");
2823 lpcfg_do_global_parameter(lp_ctx, "case sensitive", "auto");
2825 lpcfg_do_global_parameter(lp_ctx, "ldap timeout", "15");
2827 lpcfg_do_global_parameter(lp_ctx, "mangle prefix", "1");
2829 lpcfg_do_global_parameter(lp_ctx, "posix locking", "yes");
2831 lpcfg_do_global_parameter(lp_ctx, "lock spin time", "200");
2833 lpcfg_do_global_parameter(lp_ctx, "directory name cache size", "100");
2835 lpcfg_do_global_parameter(lp_ctx, "nmbd bind explicit broadcast", "yes");
2837 lpcfg_do_global_parameter(lp_ctx, "init logon delay", "100");
2839 lpcfg_do_global_parameter(lp_ctx, "usershare owner only", "yes");
2841 lpcfg_do_global_parameter(lp_ctx, "-valid", "yes");
2843 lpcfg_do_global_parameter_var(lp_ctx, "usershare path", "%s/usershares", get_dyn_STATEDIR());
2846 lpcfg_do_global_parameter_var(lp_ctx, "panic action", "/bin/sleep 999999999");
2849 lpcfg_do_global_parameter(lp_ctx, "smb passwd file", get_dyn_SMB_PASSWD_FILE());
2851 lpcfg_do_global_parameter(lp_ctx, "logon home", "\\\\%N\\%U");
2853 lpcfg_do_global_parameter(lp_ctx, "logon path", "\\\\%N\\%U\\profile");
2855 lpcfg_do_global_parameter(lp_ctx, "printjob username", "%U");
2857 lpcfg_do_global_parameter(lp_ctx, "aio max threads", "100");
2859 /* Allow modules to adjust defaults */
2860 for (defaults_hook = defaults_hooks; defaults_hook;
2861 defaults_hook = defaults_hook->next) {
2864 ret = defaults_hook->hook(lp_ctx);
2866 DEBUG(1, ("Defaults hook %s failed to run.",
2867 defaults_hook->name));
2868 talloc_free(lp_ctx);
2873 for (i = 0; parm_table[i].label; i++) {
2874 if (!(lp_ctx->flags[i] & FLAG_CMDLINE)) {
2875 lp_ctx->flags[i] |= FLAG_DEFAULT;
2879 for (parm=lp_ctx->globals->param_opt; parm; parm=parm->next) {
2880 if (!(parm->priority & FLAG_CMDLINE)) {
2881 parm->priority |= FLAG_DEFAULT;
2885 for (parm=lp_ctx->sDefault->param_opt; parm; parm=parm->next) {
2886 if (!(parm->priority & FLAG_CMDLINE)) {
2887 parm->priority |= FLAG_DEFAULT;
2895 * Initialise the global parameter structure.
2897 struct loadparm_context *loadparm_init_global(bool load_default)
2899 if (global_loadparm_context == NULL) {
2900 global_loadparm_context = loadparm_init(NULL);
2902 if (global_loadparm_context == NULL) {
2905 global_loadparm_context->global = true;
2906 if (load_default && !global_loadparm_context->loaded) {
2907 lpcfg_load_default(global_loadparm_context);
2909 global_loadparm_context->refuse_free = true;
2910 return global_loadparm_context;
2914 * Initialise the global parameter structure.
2916 struct loadparm_context *loadparm_init_s3(TALLOC_CTX *mem_ctx,
2917 const struct loadparm_s3_helpers *s3_fns)
2919 struct loadparm_context *loadparm_context = talloc_zero(mem_ctx, struct loadparm_context);
2920 if (!loadparm_context) {
2923 loadparm_context->s3_fns = s3_fns;
2924 loadparm_context->globals = s3_fns->globals;
2925 loadparm_context->flags = s3_fns->flags;
2927 return loadparm_context;
2930 const char *lpcfg_configfile(struct loadparm_context *lp_ctx)
2932 return lp_ctx->szConfigFile;
2935 const char *lp_default_path(void)
2937 if (getenv("SMB_CONF_PATH"))
2938 return getenv("SMB_CONF_PATH");
2940 return dyn_CONFIGFILE;
2944 * Update the internal state of a loadparm context after settings
2947 static bool lpcfg_update(struct loadparm_context *lp_ctx)
2949 struct debug_settings settings;
2950 TALLOC_CTX *tmp_ctx;
2952 tmp_ctx = talloc_new(lp_ctx);
2953 if (tmp_ctx == NULL) {
2957 lpcfg_add_auto_services(lp_ctx, lpcfg_auto_services(lp_ctx, tmp_ctx));
2959 if (!lp_ctx->globals->wins_server_list && lp_ctx->globals->we_are_a_wins_server) {
2960 lpcfg_do_global_parameter(lp_ctx, "wins server", "127.0.0.1");
2963 if (!lp_ctx->global) {
2964 TALLOC_FREE(tmp_ctx);
2968 panic_action = lp_ctx->globals->panic_action;
2970 reload_charcnv(lp_ctx);
2972 ZERO_STRUCT(settings);
2973 /* Add any more debug-related smb.conf parameters created in
2975 settings.timestamp_logs = lp_ctx->globals->timestamp_logs;
2976 settings.debug_prefix_timestamp = lp_ctx->globals->debug_prefix_timestamp;
2977 settings.debug_hires_timestamp = lp_ctx->globals->debug_hires_timestamp;
2978 settings.debug_pid = lp_ctx->globals->debug_pid;
2979 settings.debug_uid = lp_ctx->globals->debug_uid;
2980 settings.debug_class = lp_ctx->globals->debug_class;
2981 debug_set_settings(&settings, lp_ctx->globals->logging,
2982 lp_ctx->globals->syslog,
2983 lp_ctx->globals->syslog_only);
2985 /* FIXME: This is a bit of a hack, but we can't use a global, since
2986 * not everything that uses lp also uses the socket library */
2987 if (lpcfg_parm_bool(lp_ctx, NULL, "socket", "testnonblock", false)) {
2988 setenv("SOCKET_TESTNONBLOCK", "1", 1);
2990 unsetenv("SOCKET_TESTNONBLOCK");
2993 TALLOC_FREE(tmp_ctx);
2997 bool lpcfg_load_default(struct loadparm_context *lp_ctx)
3001 path = lp_default_path();
3003 if (!file_exist(path)) {
3004 /* We allow the default smb.conf file to not exist,
3005 * basically the equivalent of an empty file. */
3006 return lpcfg_update(lp_ctx);
3009 return lpcfg_load(lp_ctx, path);
3013 * Load the services array from the services file.
3015 * Return True on success, False on failure.
3017 bool lpcfg_load(struct loadparm_context *lp_ctx, const char *filename)
3022 filename = talloc_strdup(lp_ctx, filename);
3024 lp_ctx->szConfigFile = filename;
3026 if (lp_ctx->s3_fns) {
3027 return lp_ctx->s3_fns->load(filename);
3030 lp_ctx->bInGlobalSection = true;
3031 n2 = standard_sub_basic(lp_ctx, lp_ctx->szConfigFile);
3032 DEBUG(2, ("lpcfg_load: refreshing parameters from %s\n", n2));
3034 add_to_file_list(lp_ctx, &lp_ctx->file_lists, lp_ctx->szConfigFile, n2);
3036 /* We get sections first, so have to start 'behind' to make up */
3037 lp_ctx->currentService = NULL;
3038 bRetval = pm_process(n2, do_section, lpcfg_do_parameter, lp_ctx);
3040 /* finish up the last section */
3041 DEBUG(4, ("pm_process() returned %s\n", BOOLSTR(bRetval)));
3043 if (lp_ctx->currentService != NULL)
3044 bRetval = lpcfg_service_ok(lp_ctx->currentService);
3046 bRetval = bRetval && lpcfg_update(lp_ctx);
3048 /* we do this unconditionally, so that it happens even
3049 for a missing smb.conf */
3050 reload_charcnv(lp_ctx);
3052 if (bRetval == true) {
3053 /* set this up so that any child python tasks will
3054 find the right smb.conf */
3055 setenv("SMB_CONF_PATH", filename, 1);
3057 /* set the context used by the lp_*() function
3059 global_loadparm_context = lp_ctx;
3060 lp_ctx->loaded = true;
3067 * Return the max number of services.
3070 int lpcfg_numservices(struct loadparm_context *lp_ctx)
3072 if (lp_ctx->s3_fns) {
3073 return lp_ctx->s3_fns->get_numservices();
3076 return lp_ctx->iNumServices;
3080 * Display the contents of the services array in human-readable form.
3083 void lpcfg_dump(struct loadparm_context *lp_ctx, FILE *f, bool show_defaults,
3088 if (lp_ctx->s3_fns) {
3089 lp_ctx->s3_fns->dump(f, show_defaults, maxtoprint);
3093 lpcfg_dump_globals(lp_ctx, f, show_defaults);
3095 lpcfg_dump_a_service(lp_ctx->sDefault, lp_ctx->sDefault, f, lp_ctx->flags, show_defaults);
3097 for (iService = 0; iService < maxtoprint; iService++)
3098 lpcfg_dump_one(f, show_defaults, lp_ctx->services[iService], lp_ctx->sDefault);
3102 * Display the contents of one service in human-readable form.
3104 void lpcfg_dump_one(FILE *f, bool show_defaults, struct loadparm_service *service, struct loadparm_service *sDefault)
3106 if (service != NULL) {
3107 if (service->szService[0] == '\0')
3109 lpcfg_dump_a_service(service, sDefault, f, NULL, show_defaults);
3113 struct loadparm_service *lpcfg_servicebynum(struct loadparm_context *lp_ctx,
3116 if (lp_ctx->s3_fns) {
3117 return lp_ctx->s3_fns->get_servicebynum(snum);
3120 return lp_ctx->services[snum];
3123 struct loadparm_service *lpcfg_service(struct loadparm_context *lp_ctx,
3124 const char *service_name)
3129 if (lp_ctx->s3_fns) {
3130 return lp_ctx->s3_fns->get_service(service_name);
3133 for (iService = lp_ctx->iNumServices - 1; iService >= 0; iService--) {
3134 if (lp_ctx->services[iService] &&
3135 lp_ctx->services[iService]->szService) {
3137 * The substitution here is used to support %U is
3140 serviceName = standard_sub_basic(
3141 lp_ctx->services[iService],
3142 lp_ctx->services[iService]->szService);
3143 if (strequal(serviceName, service_name)) {
3144 talloc_free(serviceName);
3145 return lp_ctx->services[iService];
3147 talloc_free(serviceName);
3151 DEBUG(7,("lpcfg_servicenumber: couldn't find %s\n", service_name));
3155 const char *lpcfg_servicename(const struct loadparm_service *service)
3157 return lpcfg_string((const char *)service->szService);
3161 * A useful volume label function.
3163 const char *lpcfg_volume_label(struct loadparm_service *service, struct loadparm_service *sDefault)
3166 ret = lpcfg_string((const char *)((service != NULL && service->volume != NULL) ?
3167 service->volume : sDefault->volume));
3169 return lpcfg_servicename(service);
3174 * Return the correct printer name.
3176 const char *lpcfg_printername(struct loadparm_service *service, struct loadparm_service *sDefault)
3179 ret = lpcfg_string((const char *)((service != NULL && service->_printername != NULL) ?
3180 service->_printername : sDefault->_printername));
3181 if (ret == NULL || (ret != NULL && *ret == '\0'))
3182 ret = lpcfg_servicename(service);
3189 * Return the max print jobs per queue.
3191 int lpcfg_maxprintjobs(struct loadparm_service *service, struct loadparm_service *sDefault)
3193 int maxjobs = lpcfg_max_print_jobs(service, sDefault);
3195 if (maxjobs <= 0 || maxjobs >= PRINT_MAX_JOBID)
3196 maxjobs = PRINT_MAX_JOBID - 1;
3201 struct smb_iconv_handle *lpcfg_iconv_handle(struct loadparm_context *lp_ctx)
3203 if (lp_ctx == NULL) {
3204 return get_iconv_handle();
3206 return lp_ctx->iconv_handle;
3209 _PUBLIC_ void reload_charcnv(struct loadparm_context *lp_ctx)
3211 struct smb_iconv_handle *old_ic = lp_ctx->iconv_handle;
3212 if (!lp_ctx->global) {
3216 if (old_ic == NULL) {
3217 old_ic = global_iconv_handle;
3219 lp_ctx->iconv_handle = smb_iconv_handle_reinit_lp(lp_ctx, lp_ctx, old_ic);
3220 global_iconv_handle = lp_ctx->iconv_handle;
3223 _PUBLIC_ char *lpcfg_tls_keyfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
3225 return lpcfg_private_path(mem_ctx, lp_ctx, lpcfg__tls_keyfile(lp_ctx));
3228 _PUBLIC_ char *lpcfg_tls_certfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
3230 return lpcfg_private_path(mem_ctx, lp_ctx, lpcfg__tls_certfile(lp_ctx));
3233 _PUBLIC_ char *lpcfg_tls_cafile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
3235 return lpcfg_private_path(mem_ctx, lp_ctx, lpcfg__tls_cafile(lp_ctx));
3238 _PUBLIC_ char *lpcfg_tls_crlfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
3240 return lpcfg_private_path(mem_ctx, lp_ctx, lpcfg__tls_crlfile(lp_ctx));
3243 _PUBLIC_ char *lpcfg_tls_dhpfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
3245 return lpcfg_private_path(mem_ctx, lp_ctx, lpcfg__tls_dhpfile(lp_ctx));
3248 struct gensec_settings *lpcfg_gensec_settings(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
3250 struct gensec_settings *settings = talloc_zero(mem_ctx, struct gensec_settings);
3251 if (settings == NULL)
3253 SMB_ASSERT(lp_ctx != NULL);
3254 settings->lp_ctx = talloc_reference(settings, lp_ctx);
3255 settings->target_hostname = lpcfg_parm_string(lp_ctx, NULL, "gensec", "target_hostname");
3259 int lpcfg_server_role(struct loadparm_context *lp_ctx)
3261 int domain_master = lpcfg__domain_master(lp_ctx);
3263 return lp_find_server_role(lpcfg__server_role(lp_ctx),
3264 lpcfg__security(lp_ctx),
3265 lpcfg__domain_logons(lp_ctx),
3266 (domain_master == true) ||
3267 (domain_master == Auto));
3270 int lpcfg_security(struct loadparm_context *lp_ctx)
3272 return lp_find_security(lpcfg__server_role(lp_ctx),
3273 lpcfg__security(lp_ctx));
3276 int lpcfg_client_max_protocol(struct loadparm_context *lp_ctx)
3278 int client_max_protocol = lpcfg__client_max_protocol(lp_ctx);
3279 if (client_max_protocol == PROTOCOL_DEFAULT) {
3280 return PROTOCOL_NT1;
3282 return client_max_protocol;
3285 bool lpcfg_server_signing_allowed(struct loadparm_context *lp_ctx, bool *mandatory)
3287 bool allowed = true;
3288 enum smb_signing_setting signing_setting = lpcfg_server_signing(lp_ctx);
3292 if (signing_setting == SMB_SIGNING_DEFAULT) {
3294 * If we are a domain controller, SMB signing is
3295 * really important, as it can prevent a number of
3296 * attacks on communications between us and the
3299 * However, it really sucks (no sendfile, CPU
3300 * overhead) performance-wise when used on a
3301 * file server, so disable it by default
3305 if (lpcfg_server_role(lp_ctx) >= ROLE_ACTIVE_DIRECTORY_DC) {
3306 signing_setting = SMB_SIGNING_REQUIRED;
3308 signing_setting = SMB_SIGNING_OFF;
3312 switch (signing_setting) {
3313 case SMB_SIGNING_REQUIRED:
3316 case SMB_SIGNING_DESIRED:
3317 case SMB_SIGNING_IF_REQUIRED:
3319 case SMB_SIGNING_DEFAULT:
3320 case SMB_SIGNING_OFF:
3328 int lpcfg_tdb_hash_size(struct loadparm_context *lp_ctx, const char *name)
3336 base = strrchr_m(name, '/');
3342 return lpcfg_parm_int(lp_ctx, NULL, "tdb_hashsize", base, 0);
3346 int lpcfg_tdb_flags(struct loadparm_context *lp_ctx, int tdb_flags)
3348 if (!lpcfg_use_mmap(lp_ctx)) {
3349 tdb_flags |= TDB_NOMMAP;