param: add "smbd profiling level" option
[bbaumbach/samba-autobuild/.git] / lib / param / loadparm.c
1 /* 
2    Unix SMB/CIFS implementation.
3    Parameter loading functions
4    Copyright (C) Karl Auer 1993-1998
5
6    Largely re-written by Andrew Tridgell, September 1994
7
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
15
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.
20
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.
25
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/>.
28 */
29
30 /*
31  *  Load parameters.
32  *
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.
36  *
37  * To add a parameter:
38  *
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
44  *
45  *
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!
53  *
54  */
55
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 #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"
69 #include "tdb.h"
70
71 #define standard_sub_basic talloc_strdup
72
73 #include "lib/param/param_global.h"
74
75 struct loadparm_service *lpcfg_default_service(struct loadparm_context *lp_ctx)
76 {
77         return lp_ctx->sDefault;
78 }
79
80 /**
81  * Convenience routine to grab string parameters into temporary memory
82  * and run standard_sub_basic on them.
83  *
84  * The buffers can be written to by
85  * callers without affecting the source string.
86  */
87
88 static const char *lpcfg_string(const char *s)
89 {
90 #if 0  /* until REWRITE done to make thread-safe */
91         size_t len = s ? strlen(s) : 0;
92         char *ret;
93 #endif
94
95         /* The follow debug is useful for tracking down memory problems
96            especially if you have an inner loop that is calling a lp_*()
97            function that returns a string.  Perhaps this debug should be
98            present all the time? */
99
100 #if 0
101         DEBUG(10, ("lpcfg_string(%s)\n", s));
102 #endif
103
104 #if 0  /* until REWRITE done to make thread-safe */
105         if (!lp_talloc)
106                 lp_talloc = talloc_init("lp_talloc");
107
108         ret = talloc_array(lp_talloc, char, len + 100); /* leave room for substitution */
109
110         if (!ret)
111                 return NULL;
112
113         if (!s)
114                 *ret = 0;
115         else
116                 strlcpy(ret, s, len);
117
118         if (trim_string(ret, "\"", "\"")) {
119                 if (strchr(ret,'"') != NULL)
120                         strlcpy(ret, s, len);
121         }
122
123         standard_sub_basic(ret,len+100);
124         return (ret);
125 #endif
126         return s;
127 }
128
129 /*
130    In this section all the functions that are used to access the
131    parameters from the rest of the program are defined
132 */
133
134 /*
135  * the creation of separate lpcfg_*() and lp_*() functions is to allow
136  * for code compatibility between existing Samba4 and Samba3 code.
137  */
138
139 /* this global context supports the lp_*() function varients */
140 static struct loadparm_context *global_loadparm_context;
141
142 #define lpcfg_default_service global_loadparm_context->sDefault
143 #define lpcfg_global_service(i) global_loadparm_context->services[i]
144
145 #define FN_GLOBAL_STRING(fn_name,var_name) \
146  _PUBLIC_ char *lpcfg_ ## fn_name(struct loadparm_context *lp_ctx, TALLOC_CTX *ctx) {\
147          if (lp_ctx == NULL) return NULL;                               \
148          if (lp_ctx->s3_fns) {                                          \
149                  return lp_ctx->globals->var_name ? lp_ctx->s3_fns->lp_string(ctx, lp_ctx->globals->var_name) : talloc_strdup(ctx, ""); \
150          }                                                              \
151          return lp_ctx->globals->var_name ? talloc_strdup(ctx, lpcfg_string(lp_ctx->globals->var_name)) : talloc_strdup(ctx, ""); \
152 }
153
154 #define FN_GLOBAL_CONST_STRING(fn_name,var_name)                                \
155  _PUBLIC_ const char *lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) { \
156         if (lp_ctx == NULL) return NULL;                                \
157         return lp_ctx->globals->var_name ? lpcfg_string(lp_ctx->globals->var_name) : ""; \
158 }
159
160 #define FN_GLOBAL_LIST(fn_name,var_name)                                \
161  _PUBLIC_ const char **lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) { \
162          if (lp_ctx == NULL) return NULL;                               \
163          return lp_ctx->globals->var_name;                              \
164  }
165
166 #define FN_GLOBAL_BOOL(fn_name,var_name) \
167  _PUBLIC_ bool lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) {\
168          if (lp_ctx == NULL) return false;                              \
169          return lp_ctx->globals->var_name;                              \
170 }
171
172 #define FN_GLOBAL_INTEGER(fn_name,var_name) \
173  _PUBLIC_ int lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) { \
174          return lp_ctx->globals->var_name;                              \
175  }
176
177 /* Local parameters don't need the ->s3_fns because the struct
178  * loadparm_service is shared and lpcfg_service() checks the ->s3_fns
179  * hook */
180 #define FN_LOCAL_STRING(fn_name,val) \
181  _PUBLIC_ char *lpcfg_ ## fn_name(struct loadparm_service *service, \
182                                         struct loadparm_service *sDefault, TALLOC_CTX *ctx) { \
183          return(talloc_strdup(ctx, lpcfg_string((const char *)((service != NULL && service->val != NULL) ? service->val : sDefault->val)))); \
184  }
185
186 #define FN_LOCAL_CONST_STRING(fn_name,val) \
187  _PUBLIC_ const char *lpcfg_ ## fn_name(struct loadparm_service *service, \
188                                         struct loadparm_service *sDefault) { \
189          return((const char *)((service != NULL && service->val != NULL) ? service->val : sDefault->val)); \
190  }
191
192 #define FN_LOCAL_LIST(fn_name,val) \
193  _PUBLIC_ const char **lpcfg_ ## fn_name(struct loadparm_service *service, \
194                                          struct loadparm_service *sDefault) {\
195          return(const char **)(service != NULL && service->val != NULL? service->val : sDefault->val); \
196  }
197
198 #define FN_LOCAL_PARM_BOOL(fn_name, val) FN_LOCAL_BOOL(fn_name, val)
199
200 #define FN_LOCAL_BOOL(fn_name,val) \
201  _PUBLIC_ bool lpcfg_ ## fn_name(struct loadparm_service *service, \
202                                  struct loadparm_service *sDefault) {   \
203          return((service != NULL)? service->val : sDefault->val); \
204  }
205
206 #define FN_LOCAL_INTEGER(fn_name,val) \
207  _PUBLIC_ int lpcfg_ ## fn_name(struct loadparm_service *service, \
208                                 struct loadparm_service *sDefault) {    \
209          return((service != NULL)? service->val : sDefault->val); \
210  }
211
212 #define FN_LOCAL_PARM_INTEGER(fn_name, val) FN_LOCAL_INTEGER(fn_name, val)
213
214 #define FN_LOCAL_PARM_CHAR(fn_name,val) \
215  _PUBLIC_ char lpcfg_ ## fn_name(struct loadparm_service *service, \
216                                 struct loadparm_service *sDefault) {    \
217          return((service != NULL)? service->val : sDefault->val); \
218  }
219
220 #include "lib/param/param_functions.c"
221
222 /* These functions cannot be auto-generated */
223 FN_LOCAL_BOOL(autoloaded, autoloaded)
224 FN_GLOBAL_CONST_STRING(dnsdomain, dnsdomain)
225
226 /* local prototypes */
227 static struct loadparm_service *lpcfg_getservicebyname(struct loadparm_context *lp_ctx,
228                                         const char *pszServiceName);
229 static bool do_section(const char *pszSectionName, void *);
230 static bool set_variable_helper(TALLOC_CTX *mem_ctx, int parmnum, void *parm_ptr,
231                                 const char *pszParmName, const char *pszParmValue);
232 static bool lp_do_parameter_parametric(struct loadparm_context *lp_ctx,
233                                        struct loadparm_service *service,
234                                        const char *pszParmName,
235                                        const char *pszParmValue, int flags);
236
237 /* The following are helper functions for parametrical options support. */
238 /* It returns a pointer to parametrical option value if it exists or NULL otherwise */
239 /* Actual parametrical functions are quite simple */
240 struct parmlist_entry *get_parametric_helper(struct loadparm_service *service,
241                                              const char *type, const char *option,
242                                              struct parmlist_entry *global_opts)
243 {
244         char* param_key;
245         struct parmlist_entry *data = NULL;
246         TALLOC_CTX *mem_ctx = talloc_stackframe();
247
248         param_key = talloc_asprintf(mem_ctx, "%s:%s", type, option);
249         if (param_key == NULL) {
250                 DEBUG(0,("asprintf failed!\n"));
251                 TALLOC_FREE(mem_ctx);
252                 return NULL;
253         }
254
255         /*
256          * Try to fetch the option from the data.
257          */
258         if (service != NULL) {
259                 data = service->param_opt;
260                 while (data != NULL) {
261                         if (strwicmp(data->key, param_key) == 0) {
262                                 TALLOC_FREE(mem_ctx);
263                                 return data;
264                         }
265                         data = data->next;
266                 }
267         }
268
269         /*
270          * Fall back to fetching from the globals.
271          */
272         data = global_opts;
273         while (data != NULL) {
274                 if (strwicmp(data->key, param_key) == 0) {
275                         TALLOC_FREE(mem_ctx);
276                         return data;
277                 }
278                 data = data->next;
279         }
280
281
282         TALLOC_FREE(mem_ctx);
283
284         return NULL;
285
286
287 }
288
289 const char *lpcfg_get_parametric(struct loadparm_context *lp_ctx,
290                               struct loadparm_service *service,
291                               const char *type, const char *option)
292 {
293         struct parmlist_entry *data;
294
295         if (lp_ctx == NULL)
296                 return NULL;
297
298         data = get_parametric_helper(service,
299                                      type, option, lp_ctx->globals->param_opt);
300
301         if (data == NULL) {
302                 return NULL;
303         } else {
304                 return data->value;
305         }
306 }
307
308
309 /**
310  * convenience routine to return int parameters.
311  */
312 int lp_int(const char *s)
313 {
314
315         if (!s || !*s) {
316                 DEBUG(0,("lp_int(%s): is called with NULL!\n",s));
317                 return -1;
318         }
319
320         return strtol(s, NULL, 0);
321 }
322
323 /**
324  * convenience routine to return unsigned long parameters.
325  */
326 unsigned long lp_ulong(const char *s)
327 {
328
329         if (!s || !*s) {
330                 DEBUG(0,("lp_ulong(%s): is called with NULL!\n",s));
331                 return -1;
332         }
333
334         return strtoul(s, NULL, 0);
335 }
336
337 /**
338  * convenience routine to return unsigned long parameters.
339  */
340 static long lp_long(const char *s)
341 {
342
343         if (!s) {
344                 DEBUG(0,("lp_long(%s): is called with NULL!\n",s));
345                 return -1;
346         }
347
348         return strtol(s, NULL, 0);
349 }
350
351 /**
352  * convenience routine to return unsigned long parameters.
353  */
354 static double lp_double(const char *s)
355 {
356
357         if (!s) {
358                 DEBUG(0,("lp_double(%s): is called with NULL!\n",s));
359                 return -1;
360         }
361
362         return strtod(s, NULL);
363 }
364
365 /**
366  * convenience routine to return boolean parameters.
367  */
368 bool lp_bool(const char *s)
369 {
370         bool ret = false;
371
372         if (!s || !*s) {
373                 DEBUG(0,("lp_bool(%s): is called with NULL!\n",s));
374                 return false;
375         }
376
377         if (!set_boolean(s, &ret)) {
378                 DEBUG(0,("lp_bool(%s): value is not boolean!\n",s));
379                 return false;
380         }
381
382         return ret;
383 }
384
385 /**
386  * Return parametric option from a given service. Type is a part of option before ':'
387  * Parametric option has following syntax: 'Type: option = value'
388  * Returned value is allocated in 'lp_talloc' context
389  */
390
391 const char *lpcfg_parm_string(struct loadparm_context *lp_ctx,
392                               struct loadparm_service *service, const char *type,
393                               const char *option)
394 {
395         const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
396
397         if (value)
398                 return lpcfg_string(value);
399
400         return NULL;
401 }
402
403 /**
404  * Return parametric option from a given service. Type is a part of option before ':'
405  * Parametric option has following syntax: 'Type: option = value'
406  * Returned value is allocated in 'lp_talloc' context
407  */
408
409 const char **lpcfg_parm_string_list(TALLOC_CTX *mem_ctx,
410                                     struct loadparm_context *lp_ctx,
411                                     struct loadparm_service *service,
412                                     const char *type,
413                                     const char *option, const char *separator)
414 {
415         const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
416
417         if (value != NULL) {
418                 char **l = str_list_make(mem_ctx, value, separator);
419                 return discard_const_p(const char *, l);
420         }
421
422         return NULL;
423 }
424
425 /**
426  * Return parametric option from a given service. Type is a part of option before ':'
427  * Parametric option has following syntax: 'Type: option = value'
428  */
429
430 int lpcfg_parm_int(struct loadparm_context *lp_ctx,
431                    struct loadparm_service *service, const char *type,
432                    const char *option, int default_v)
433 {
434         const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
435
436         if (value)
437                 return lp_int(value);
438
439         return default_v;
440 }
441
442 /**
443  * Return parametric option from a given service. Type is a part of
444  * option before ':'.
445  * Parametric option has following syntax: 'Type: option = value'.
446  */
447
448 int lpcfg_parm_bytes(struct loadparm_context *lp_ctx,
449                   struct loadparm_service *service, const char *type,
450                   const char *option, int default_v)
451 {
452         uint64_t bval;
453
454         const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
455
456         if (value && conv_str_size_error(value, &bval)) {
457                 if (bval <= INT_MAX) {
458                         return (int)bval;
459                 }
460         }
461
462         return default_v;
463 }
464
465 /**
466  * Return parametric option from a given service.
467  * Type is a part of option before ':'
468  * Parametric option has following syntax: 'Type: option = value'
469  */
470 unsigned long lpcfg_parm_ulong(struct loadparm_context *lp_ctx,
471                             struct loadparm_service *service, const char *type,
472                             const char *option, unsigned long default_v)
473 {
474         const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
475
476         if (value)
477                 return lp_ulong(value);
478
479         return default_v;
480 }
481
482 long lpcfg_parm_long(struct loadparm_context *lp_ctx,
483                      struct loadparm_service *service, const char *type,
484                      const char *option, long default_v)
485 {
486         const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
487
488         if (value)
489                 return lp_long(value);
490
491         return default_v;
492 }
493
494 double lpcfg_parm_double(struct loadparm_context *lp_ctx,
495                       struct loadparm_service *service, const char *type,
496                       const char *option, double default_v)
497 {
498         const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
499
500         if (value != NULL)
501                 return lp_double(value);
502
503         return default_v;
504 }
505
506 /**
507  * Return parametric option from a given service. Type is a part of option before ':'
508  * Parametric option has following syntax: 'Type: option = value'
509  */
510
511 bool lpcfg_parm_bool(struct loadparm_context *lp_ctx,
512                      struct loadparm_service *service, const char *type,
513                      const char *option, bool default_v)
514 {
515         const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
516
517         if (value != NULL)
518                 return lp_bool(value);
519
520         return default_v;
521 }
522
523
524 /**
525  * Set a string value, deallocating any existing space, and allocing the space
526  * for the string
527  */
528 bool lpcfg_string_set(TALLOC_CTX *mem_ctx, char **dest, const char *src)
529 {
530         talloc_free(*dest);
531
532         if (src == NULL)
533                 src = "";
534
535         *dest = talloc_strdup(mem_ctx, src);
536         if ((*dest) == NULL) {
537                 DEBUG(0,("Out of memory in string_set\n"));
538                 return false;
539         }
540
541         return true;
542 }
543
544 /**
545  * Set a string value, deallocating any existing space, and allocing the space
546  * for the string
547  */
548 bool lpcfg_string_set_upper(TALLOC_CTX *mem_ctx, char **dest, const char *src)
549 {
550         talloc_free(*dest);
551
552         if (src == NULL)
553                 src = "";
554
555         *dest = strupper_talloc(mem_ctx, src);
556         if ((*dest) == NULL) {
557                 DEBUG(0,("Out of memory in string_set_upper\n"));
558                 return false;
559         }
560
561         return true;
562 }
563
564
565
566 /**
567  * Add a new service to the services array initialising it with the given
568  * service.
569  */
570
571 struct loadparm_service *lpcfg_add_service(struct loadparm_context *lp_ctx,
572                                            const struct loadparm_service *pservice,
573                                            const char *name)
574 {
575         int i;
576         int num_to_alloc = lp_ctx->iNumServices + 1;
577         struct parmlist_entry *data, *pdata;
578
579         if (lp_ctx->s3_fns != NULL) {
580                 smb_panic("Add a service should not be called on an s3 loadparm ctx");
581         }
582
583         if (pservice == NULL) {
584                 pservice = lp_ctx->sDefault;
585         }
586
587         /* it might already exist */
588         if (name) {
589                 struct loadparm_service *service = lpcfg_getservicebyname(lp_ctx,
590                                                                     name);
591                 if (service != NULL) {
592                         /* Clean all parametric options for service */
593                         /* They will be added during parsing again */
594                         data = service->param_opt;
595                         while (data) {
596                                 pdata = data->next;
597                                 talloc_free(data);
598                                 data = pdata;
599                         }
600                         service->param_opt = NULL;
601                         return service;
602                 }
603         }
604
605         /* find an invalid one */
606         for (i = 0; i < lp_ctx->iNumServices; i++)
607                 if (lp_ctx->services[i] == NULL)
608                         break;
609
610         /* if not, then create one */
611         if (i == lp_ctx->iNumServices) {
612                 struct loadparm_service **tsp;
613
614                 tsp = talloc_realloc(lp_ctx, lp_ctx->services, struct loadparm_service *, num_to_alloc);
615
616                 if (!tsp) {
617                         DEBUG(0,("lpcfg_add_service: failed to enlarge services!\n"));
618                         return NULL;
619                 } else {
620                         lp_ctx->services = tsp;
621                         lp_ctx->services[lp_ctx->iNumServices] = NULL;
622                 }
623
624                 lp_ctx->iNumServices++;
625         }
626
627         lp_ctx->services[i] = talloc_zero(lp_ctx->services, struct loadparm_service);
628         if (lp_ctx->services[i] == NULL) {
629                 DEBUG(0,("lpcfg_add_service: out of memory!\n"));
630                 return NULL;
631         }
632         copy_service(lp_ctx->services[i], pservice, NULL);
633         if (name != NULL)
634                 lpcfg_string_set(lp_ctx->services[i], &lp_ctx->services[i]->szService, name);
635         return lp_ctx->services[i];
636 }
637
638 /**
639  * Add a new home service, with the specified home directory, defaults coming
640  * from service ifrom.
641  */
642
643 bool lpcfg_add_home(struct loadparm_context *lp_ctx,
644                  const char *pszHomename,
645                  struct loadparm_service *default_service,
646                  const char *user, const char *pszHomedir)
647 {
648         struct loadparm_service *service;
649
650         service = lpcfg_add_service(lp_ctx, default_service, pszHomename);
651
652         if (service == NULL)
653                 return false;
654
655         if (!(*(default_service->path))
656             || strequal(default_service->path, lp_ctx->sDefault->path)) {
657                 service->path = talloc_strdup(service, pszHomedir);
658         } else {
659                 service->path = string_sub_talloc(service, lpcfg_path(default_service, lp_ctx->sDefault, service), "%H", pszHomedir);
660         }
661
662         if (!(*(service->comment))) {
663                 service->comment = talloc_asprintf(service, "Home directory of %s", user);
664         }
665         service->bAvailable = default_service->bAvailable;
666         service->browseable = default_service->browseable;
667
668         DEBUG(3, ("adding home's share [%s] for user '%s' at '%s'\n",
669                   pszHomename, user, service->path));
670
671         return true;
672 }
673
674 /**
675  * Add a new printer service, with defaults coming from service iFrom.
676  */
677
678 bool lpcfg_add_printer(struct loadparm_context *lp_ctx,
679                        const char *pszPrintername,
680                        struct loadparm_service *default_service)
681 {
682         const char *comment = "From Printcap";
683         struct loadparm_service *service;
684         service = lpcfg_add_service(lp_ctx, default_service, pszPrintername);
685
686         if (service == NULL)
687                 return false;
688
689         /* note that we do NOT default the availability flag to True - */
690         /* we take it from the default service passed. This allows all */
691         /* dynamic printers to be disabled by disabling the [printers] */
692         /* entry (if/when the 'available' keyword is implemented!).    */
693
694         /* the printer name is set to the service name. */
695         lpcfg_string_set(service, &service->_printername, pszPrintername);
696         lpcfg_string_set(service, &service->comment, comment);
697         service->browseable = default_service->browseable;
698         /* Printers cannot be read_only. */
699         service->read_only = false;
700         /* Printer services must be printable. */
701         service->printable = true;
702
703         DEBUG(3, ("adding printer service %s\n", pszPrintername));
704
705         return true;
706 }
707
708 /**
709  * Map a parameter's string representation to something we can use.
710  * Returns False if the parameter string is not recognised, else TRUE.
711  */
712
713 int lpcfg_map_parameter(const char *pszParmName)
714 {
715         int iIndex;
716
717         for (iIndex = 0; parm_table[iIndex].label; iIndex++)
718                 if (strwicmp(parm_table[iIndex].label, pszParmName) == 0)
719                         return iIndex;
720
721         /* Warn only if it isn't parametric option */
722         if (strchr(pszParmName, ':') == NULL)
723                 DEBUG(0, ("Unknown parameter encountered: \"%s\"\n", pszParmName));
724         /* We do return 'fail' for parametric options as well because they are
725            stored in different storage
726          */
727         return -1;
728 }
729
730
731 /**
732   return the parameter structure for a parameter
733 */
734 struct parm_struct *lpcfg_parm_struct(struct loadparm_context *lp_ctx, const char *name)
735 {
736         int num = lpcfg_map_parameter(name);
737
738         if (num < 0) {
739                 return NULL;
740         }
741
742         return &parm_table[num];
743 }
744
745 /**
746   return the parameter pointer for a parameter
747 */
748 void *lpcfg_parm_ptr(struct loadparm_context *lp_ctx,
749                   struct loadparm_service *service, struct parm_struct *parm)
750 {
751         if (lp_ctx->s3_fns) {
752                 return lp_ctx->s3_fns->get_parm_ptr(service, parm);
753         }
754
755         if (service == NULL) {
756                 if (parm->p_class == P_LOCAL)
757                         return ((char *)lp_ctx->sDefault)+parm->offset;
758                 else if (parm->p_class == P_GLOBAL)
759                         return ((char *)lp_ctx->globals)+parm->offset;
760                 else return NULL;
761         } else {
762                 return ((char *)service) + parm->offset;
763         }
764 }
765
766 /**
767   return the parameter pointer for a parameter
768 */
769 bool lpcfg_parm_is_cmdline(struct loadparm_context *lp_ctx, const char *name)
770 {
771         int parmnum;
772
773         parmnum = lpcfg_map_parameter(name);
774         if (parmnum == -1) return false;
775
776         return lp_ctx->flags[parmnum] & FLAG_CMDLINE;
777 }
778
779 /**
780  * Find a service by name. Otherwise works like get_service.
781  */
782
783 static struct loadparm_service *lpcfg_getservicebyname(struct loadparm_context *lp_ctx,
784                                         const char *pszServiceName)
785 {
786         int iService;
787
788         if (lp_ctx->s3_fns) {
789                 return lp_ctx->s3_fns->get_service(pszServiceName);
790         }
791
792         for (iService = lp_ctx->iNumServices - 1; iService >= 0; iService--)
793                 if (lp_ctx->services[iService] != NULL &&
794                     strwicmp(lp_ctx->services[iService]->szService, pszServiceName) == 0) {
795                         return lp_ctx->services[iService];
796                 }
797
798         return NULL;
799 }
800
801 /**
802  * Add a parametric option to a parmlist_entry,
803  * replacing old value, if already present.
804  */
805 void set_param_opt(TALLOC_CTX *mem_ctx,
806                    struct parmlist_entry **opt_list,
807                    const char *opt_name,
808                    const char *opt_value,
809                    unsigned priority)
810 {
811         struct parmlist_entry *new_opt, *opt;
812         bool not_added;
813
814         opt = *opt_list;
815         not_added = true;
816
817         /* Traverse destination */
818         while (opt) {
819                 /* If we already have same option, override it */
820                 if (strwicmp(opt->key, opt_name) == 0) {
821                         if ((opt->priority & FLAG_CMDLINE) &&
822                             !(priority & FLAG_CMDLINE)) {
823                                 /* it's been marked as not to be
824                                    overridden */
825                                 return;
826                         }
827                         TALLOC_FREE(opt->value);
828                         TALLOC_FREE(opt->list);
829                         opt->value = talloc_strdup(opt, opt_value);
830                         opt->priority = priority;
831                         not_added = false;
832                         break;
833                 }
834                 opt = opt->next;
835         }
836         if (not_added) {
837                 new_opt = talloc(mem_ctx, struct parmlist_entry);
838                 if (new_opt == NULL) {
839                         smb_panic("OOM");
840                 }
841
842                 new_opt->key = talloc_strdup(new_opt, opt_name);
843                 if (new_opt->key == NULL) {
844                         smb_panic("talloc_strdup failed");
845                 }
846
847                 new_opt->value = talloc_strdup(new_opt, opt_value);
848                 if (new_opt->value == NULL) {
849                         smb_panic("talloc_strdup failed");
850                 }
851
852                 new_opt->list = NULL;
853                 new_opt->priority = priority;
854                 DLIST_ADD(*opt_list, new_opt);
855         }
856 }
857
858 /**
859  * Copy a service structure to another.
860  * If pcopymapDest is NULL then copy all fields
861  */
862
863 void copy_service(struct loadparm_service *pserviceDest,
864                   const struct loadparm_service *pserviceSource,
865                   struct bitmap *pcopymapDest)
866 {
867         int i;
868         bool bcopyall = (pcopymapDest == NULL);
869         struct parmlist_entry *data;
870
871         for (i = 0; parm_table[i].label; i++)
872                 if (parm_table[i].p_class == P_LOCAL &&
873                     (bcopyall || bitmap_query(pcopymapDest, i))) {
874                         const void *src_ptr =
875                                 ((const char *)pserviceSource) + parm_table[i].offset;
876                         void *dest_ptr =
877                                 ((char *)pserviceDest) + parm_table[i].offset;
878
879                         switch (parm_table[i].type) {
880                                 case P_BOOL:
881                                 case P_BOOLREV:
882                                         *(bool *)dest_ptr = *(const bool *)src_ptr;
883                                         break;
884
885                                 case P_INTEGER:
886                                 case P_BYTES:
887                                 case P_OCTAL:
888                                 case P_ENUM:
889                                         *(int *)dest_ptr = *(const int *)src_ptr;
890                                         break;
891
892                                 case P_CHAR:
893                                         *(char *)dest_ptr = *(const char *)src_ptr;
894                                         break;
895
896                                 case P_STRING:
897                                         lpcfg_string_set(pserviceDest,
898                                                    (char **)dest_ptr,
899                                                    *(const char * const *)src_ptr);
900                                         break;
901
902                                 case P_USTRING:
903                                         lpcfg_string_set_upper(pserviceDest,
904                                                          (char **)dest_ptr,
905                                                          *(const char * const *)src_ptr);
906                                         break;
907                                 case P_CMDLIST:
908                                 case P_LIST:
909                                         TALLOC_FREE(*((char ***)dest_ptr));
910                                         *(char ***)dest_ptr = str_list_copy(pserviceDest,
911                                                                             *discard_const_p(const char **, src_ptr));
912                                         break;
913                                 default:
914                                         break;
915                         }
916                 }
917
918         if (bcopyall) {
919                 init_copymap(pserviceDest);
920                 if (pserviceSource->copymap)
921                         bitmap_copy(pserviceDest->copymap,
922                                     pserviceSource->copymap);
923         }
924
925         for (data = pserviceSource->param_opt; data != NULL; data = data->next) {
926                 set_param_opt(pserviceDest, &pserviceDest->param_opt,
927                               data->key, data->value, data->priority);
928         }
929 }
930
931 /**
932  * Check a service for consistency. Return False if the service is in any way
933  * incomplete or faulty, else True.
934  */
935 bool lpcfg_service_ok(struct loadparm_service *service)
936 {
937         bool bRetval;
938
939         bRetval = true;
940         if (service->szService[0] == '\0') {
941                 DEBUG(0, ("The following message indicates an internal error:\n"));
942                 DEBUG(0, ("No service name in service entry.\n"));
943                 bRetval = false;
944         }
945
946         /* The [printers] entry MUST be printable. I'm all for flexibility, but */
947         /* I can't see why you'd want a non-printable printer service...        */
948         if (strwicmp(service->szService, PRINTERS_NAME) == 0) {
949                 if (!service->printable) {
950                         DEBUG(0, ("WARNING: [%s] service MUST be printable!\n",
951                                service->szService));
952                         service->printable = true;
953                 }
954                 /* [printers] service must also be non-browsable. */
955                 if (service->browseable)
956                         service->browseable = false;
957         }
958
959         if (service->path[0] == '\0' &&
960             strwicmp(service->szService, HOMES_NAME) != 0 &&
961             service->msdfs_proxy[0] == '\0')
962         {
963                 DEBUG(0, ("WARNING: No path in service %s - making it unavailable!\n",
964                         service->szService));
965                 service->bAvailable = false;
966         }
967
968         if (!service->bAvailable)
969                 DEBUG(1, ("NOTE: Service %s is flagged unavailable.\n",
970                           service->szService));
971
972         return bRetval;
973 }
974
975
976 /*******************************************************************
977  Keep a linked list of all config files so we know when one has changed
978  it's date and needs to be reloaded.
979 ********************************************************************/
980
981 void add_to_file_list(TALLOC_CTX *mem_ctx, struct file_lists **list,
982                              const char *fname, const char *subfname)
983 {
984         struct file_lists *f = *list;
985
986         while (f) {
987                 if (f->name && !strcmp(f->name, fname))
988                         break;
989                 f = f->next;
990         }
991
992         if (!f) {
993                 f = talloc(mem_ctx, struct file_lists);
994                 if (!f)
995                         goto fail;
996                 f->next = *list;
997                 f->name = talloc_strdup(f, fname);
998                 if (!f->name) {
999                         TALLOC_FREE(f);
1000                         goto fail;
1001                 }
1002                 f->subfname = talloc_strdup(f, subfname);
1003                 if (!f->subfname) {
1004                         TALLOC_FREE(f);
1005                         goto fail;
1006                 }
1007                 *list = f;
1008                 f->modtime = file_modtime(subfname);
1009         } else {
1010                 time_t t = file_modtime(subfname);
1011                 if (t)
1012                         f->modtime = t;
1013         }
1014         return;
1015
1016 fail:
1017         DEBUG(0, ("Unable to add file to file list: %s\n", fname));
1018
1019 }
1020
1021 /*******************************************************************
1022  Check if a config file has changed date.
1023 ********************************************************************/
1024 bool lpcfg_file_list_changed(struct loadparm_context *lp_ctx)
1025 {
1026         struct file_lists *f;
1027         DEBUG(6, ("lpcfg_file_list_changed()\n"));
1028
1029         for (f = lp_ctx->file_lists; f != NULL; f = f->next) {
1030                 char *n2;
1031                 time_t mod_time;
1032
1033                 n2 = standard_sub_basic(lp_ctx, f->name);
1034
1035                 DEBUGADD(6, ("file %s -> %s  last mod_time: %s\n",
1036                              f->name, n2, ctime(&f->modtime)));
1037
1038                 mod_time = file_modtime(n2);
1039
1040                 if (mod_time && ((f->modtime != mod_time) || (f->subfname == NULL) || (strcmp(n2, f->subfname) != 0))) {
1041                         DEBUGADD(6, ("file %s modified: %s\n", n2,
1042                                   ctime(&mod_time)));
1043                         f->modtime = mod_time;
1044                         talloc_free(f->subfname);
1045                         f->subfname = talloc_strdup(f, n2);
1046                         TALLOC_FREE(n2);
1047                         return true;
1048                 }
1049                 TALLOC_FREE(n2);
1050         }
1051         return false;
1052 }
1053
1054 /*
1055  * set the value for a P_ENUM
1056  */
1057 bool lp_set_enum_parm( struct parm_struct *parm, const char *pszParmValue,
1058                               int *ptr )
1059 {
1060         int i;
1061
1062         for (i = 0; parm->enum_list[i].name; i++) {
1063                 if ( strequal(pszParmValue, parm->enum_list[i].name)) {
1064                         *ptr = parm->enum_list[i].value;
1065                         return true;
1066                 }
1067         }
1068         DEBUG(0, ("WARNING: Ignoring invalid value '%s' for parameter '%s'\n",
1069                   pszParmValue, parm->label));
1070         return false;
1071 }
1072
1073
1074 /***************************************************************************
1075  Handle the "realm" parameter
1076 ***************************************************************************/
1077
1078 bool handle_realm(struct loadparm_context *lp_ctx, struct loadparm_service *service,
1079                   const char *pszParmValue, char **ptr)
1080 {
1081         char *upper;
1082         char *lower;
1083
1084         upper = strupper_talloc(lp_ctx, pszParmValue);
1085         if (upper == NULL) {
1086                 return false;
1087         }
1088
1089         lower = strlower_talloc(lp_ctx, pszParmValue);
1090         if (lower == NULL) {
1091                 TALLOC_FREE(upper);
1092                 return false;
1093         }
1094
1095         lpcfg_string_set(lp_ctx->globals->ctx, ptr, pszParmValue);
1096         lpcfg_string_set(lp_ctx->globals->ctx, &lp_ctx->globals->realm, upper);
1097         lpcfg_string_set(lp_ctx->globals->ctx, &lp_ctx->globals->dnsdomain, lower);
1098
1099         return true;
1100 }
1101
1102 /***************************************************************************
1103  Handle the include operation.
1104 ***************************************************************************/
1105
1106 bool handle_include(struct loadparm_context *lp_ctx, struct loadparm_service *service,
1107                            const char *pszParmValue, char **ptr)
1108 {
1109         char *fname;
1110
1111         if (lp_ctx->s3_fns) {
1112                 return lp_ctx->s3_fns->lp_include(lp_ctx, service, pszParmValue, ptr);
1113         }
1114
1115         fname = standard_sub_basic(lp_ctx, pszParmValue);
1116
1117         add_to_file_list(lp_ctx, &lp_ctx->file_lists, pszParmValue, fname);
1118
1119         lpcfg_string_set(lp_ctx, ptr, fname);
1120
1121         if (file_exist(fname))
1122                 return pm_process(fname, do_section, lpcfg_do_parameter, lp_ctx);
1123
1124         DEBUG(2, ("Can't find include file %s\n", fname));
1125
1126         return false;
1127 }
1128
1129 /***************************************************************************
1130  Handle the interpretation of the copy parameter.
1131 ***************************************************************************/
1132
1133 bool handle_copy(struct loadparm_context *lp_ctx, struct loadparm_service *service,
1134                         const char *pszParmValue, char **ptr)
1135 {
1136         bool bRetval;
1137         struct loadparm_service *serviceTemp = NULL;
1138
1139         bRetval = false;
1140
1141         DEBUG(3, ("Copying service from service %s\n", pszParmValue));
1142
1143         serviceTemp = lpcfg_getservicebyname(lp_ctx, pszParmValue);
1144
1145         if (service == NULL) {
1146                 DEBUG(0, ("Unable to copy service - invalid service destination.\n"));
1147                 return false;
1148         }
1149
1150         if (serviceTemp != NULL) {
1151                 if (serviceTemp == service) {
1152                         DEBUG(0, ("Can't copy service %s - unable to copy self!\n", pszParmValue));
1153                 } else {
1154                         copy_service(service,
1155                                      serviceTemp,
1156                                      service->copymap);
1157                         lpcfg_string_set(service, ptr, pszParmValue);
1158
1159                         bRetval = true;
1160                 }
1161         } else {
1162                 DEBUG(0, ("Unable to copy service - source not found: %s\n",
1163                           pszParmValue));
1164                 bRetval = false;
1165         }
1166
1167         return bRetval;
1168 }
1169
1170 bool handle_debug_list(struct loadparm_context *lp_ctx, struct loadparm_service *service,
1171                         const char *pszParmValue, char **ptr)
1172 {
1173         lpcfg_string_set(lp_ctx->globals->ctx, ptr, pszParmValue);
1174
1175         return debug_parse_levels(pszParmValue);
1176 }
1177
1178 bool handle_logfile(struct loadparm_context *lp_ctx, struct loadparm_service *service,
1179                     const char *pszParmValue, char **ptr)
1180 {
1181         if (lp_ctx->s3_fns == NULL) {
1182                 debug_set_logfile(pszParmValue);
1183         }
1184
1185         lpcfg_string_set(lp_ctx->globals->ctx, ptr, pszParmValue);
1186
1187         return true;
1188 }
1189
1190 /*
1191  * These special charset handling methods only run in the source3 code.
1192  */
1193
1194 bool handle_charset(struct loadparm_context *lp_ctx, struct loadparm_service *service,
1195                         const char *pszParmValue, char **ptr)
1196 {
1197         if (lp_ctx->s3_fns) {
1198                 if (*ptr == NULL || strcmp(*ptr, pszParmValue) != 0) {
1199                         global_iconv_handle = smb_iconv_handle_reinit(NULL,
1200                                                         lpcfg_dos_charset(lp_ctx),
1201                                                         lpcfg_unix_charset(lp_ctx),
1202                                                         true, global_iconv_handle);
1203                 }
1204
1205         }
1206         return lpcfg_string_set(lp_ctx->globals->ctx, ptr, pszParmValue);
1207
1208 }
1209
1210 bool handle_dos_charset(struct loadparm_context *lp_ctx, struct loadparm_service *service,
1211                         const char *pszParmValue, char **ptr)
1212 {
1213         bool is_utf8 = false;
1214         size_t len = strlen(pszParmValue);
1215
1216         if (lp_ctx->s3_fns) {
1217                 if (len == 4 || len == 5) {
1218                         /* Don't use StrCaseCmp here as we don't want to
1219                            initialize iconv. */
1220                         if ((toupper_m(pszParmValue[0]) == 'U') &&
1221                             (toupper_m(pszParmValue[1]) == 'T') &&
1222                             (toupper_m(pszParmValue[2]) == 'F')) {
1223                                 if (len == 4) {
1224                                         if (pszParmValue[3] == '8') {
1225                                                 is_utf8 = true;
1226                                         }
1227                                 } else {
1228                                         if (pszParmValue[3] == '-' &&
1229                                             pszParmValue[4] == '8') {
1230                                                 is_utf8 = true;
1231                                         }
1232                                 }
1233                         }
1234                 }
1235
1236                 if (*ptr == NULL || strcmp(*ptr, pszParmValue) != 0) {
1237                         if (is_utf8) {
1238                                 DEBUG(0,("ERROR: invalid DOS charset: 'dos charset' must not "
1239                                         "be UTF8, using (default value) %s instead.\n",
1240                                         DEFAULT_DOS_CHARSET));
1241                                 pszParmValue = DEFAULT_DOS_CHARSET;
1242                         }
1243                         global_iconv_handle = smb_iconv_handle_reinit(NULL,
1244                                                         lpcfg_dos_charset(lp_ctx),
1245                                                         lpcfg_unix_charset(lp_ctx),
1246                                                         true, global_iconv_handle);
1247                 }
1248         }
1249
1250         return lpcfg_string_set(lp_ctx->globals->ctx, ptr, pszParmValue);
1251 }
1252
1253 bool handle_printing(struct loadparm_context *lp_ctx, struct loadparm_service *service,
1254                             const char *pszParmValue, char **ptr)
1255 {
1256         static int parm_num = -1;
1257
1258         if (parm_num == -1) {
1259                 parm_num = lpcfg_map_parameter("printing");
1260         }
1261
1262         if (!lp_set_enum_parm(&parm_table[parm_num], pszParmValue, (int*)ptr)) {
1263                 return false;
1264         }
1265
1266         if (lp_ctx->s3_fns) {
1267                 if (service == NULL) {
1268                         init_printer_values(lp_ctx, lp_ctx->globals->ctx, lp_ctx->sDefault);
1269                 } else {
1270                         init_printer_values(lp_ctx, service, service);
1271                 }
1272         }
1273
1274         return true;
1275 }
1276
1277 bool handle_ldap_debug_level(struct loadparm_context *lp_ctx, struct loadparm_service *service,
1278                              const char *pszParmValue, char **ptr)
1279 {
1280         lp_ctx->globals->ldap_debug_level = lp_int(pszParmValue);
1281
1282         if (lp_ctx->s3_fns) {
1283                 lp_ctx->s3_fns->init_ldap_debugging();
1284         }
1285         return true;
1286 }
1287
1288 bool handle_netbios_aliases(struct loadparm_context *lp_ctx, struct loadparm_service *service,
1289                             const char *pszParmValue, char **ptr)
1290 {
1291         TALLOC_FREE(lp_ctx->globals->netbios_aliases);
1292         lp_ctx->globals->netbios_aliases = str_list_make_v3_const(lp_ctx->globals->ctx,
1293                                                                   pszParmValue, NULL);
1294
1295         if (lp_ctx->s3_fns) {
1296                 return lp_ctx->s3_fns->set_netbios_aliases(lp_ctx->globals->netbios_aliases);
1297         }
1298         return true;
1299 }
1300
1301 /*
1302  * idmap related parameters
1303  */
1304
1305 bool handle_idmap_backend(struct loadparm_context *lp_ctx, struct loadparm_service *service,
1306                           const char *pszParmValue, char **ptr)
1307 {
1308         if (lp_ctx->s3_fns) {
1309                 lp_do_parameter_parametric(lp_ctx, service, "idmap config * : backend",
1310                                            pszParmValue, 0);
1311         }
1312
1313         return lpcfg_string_set(lp_ctx->globals->ctx, ptr, pszParmValue);
1314 }
1315
1316 bool handle_idmap_uid(struct loadparm_context *lp_ctx, struct loadparm_service *service,
1317                       const char *pszParmValue, char **ptr)
1318 {
1319         if (lp_ctx->s3_fns) {
1320                 lp_do_parameter_parametric(lp_ctx, service, "idmap config * : range",
1321                                            pszParmValue, 0);
1322         }
1323
1324         return lpcfg_string_set(lp_ctx->globals->ctx, ptr, pszParmValue);
1325 }
1326
1327 bool handle_idmap_gid(struct loadparm_context *lp_ctx, struct loadparm_service *service,
1328                       const char *pszParmValue, char **ptr)
1329 {
1330         if (lp_ctx->s3_fns) {
1331                 lp_do_parameter_parametric(lp_ctx, service, "idmap config * : range",
1332                                            pszParmValue, 0);
1333         }
1334
1335         return lpcfg_string_set(lp_ctx->globals->ctx, ptr, pszParmValue);
1336 }
1337
1338 bool handle_smb_ports(struct loadparm_context *lp_ctx, struct loadparm_service *service,
1339                       const char *pszParmValue, char **ptr)
1340 {
1341         static int parm_num = -1;
1342         int i;
1343         const char **list;
1344
1345         if (!pszParmValue || !*pszParmValue) {
1346                 return false;
1347         }
1348
1349         if (parm_num == -1) {
1350                 parm_num = lpcfg_map_parameter("smb ports");
1351         }
1352
1353         if(!set_variable_helper(lp_ctx->globals->ctx, parm_num, ptr, "smb ports",
1354                                 pszParmValue)) {
1355                 return false;
1356         }
1357
1358         list = lp_ctx->globals->smb_ports;
1359         if (list == NULL) {
1360                 return false;
1361         }
1362
1363         /* Check that each port is a valid integer and within range */
1364         for (i = 0; list[i] != NULL; i++) {
1365                 char *end = NULL;
1366                 int port = 0;
1367                 port = strtol(list[i], &end, 10);
1368                 if (*end != '\0' || port <= 0 || port > 65535) {
1369                         TALLOC_FREE(list);
1370                         return false;
1371                 }
1372         }
1373
1374         return true;
1375 }
1376
1377 /***************************************************************************
1378  Initialise a copymap.
1379 ***************************************************************************/
1380
1381 /**
1382  * Initializes service copymap
1383  * Note: pservice *must* be valid TALLOC_CTX
1384  */
1385 void init_copymap(struct loadparm_service *pservice)
1386 {
1387         int i;
1388
1389         TALLOC_FREE(pservice->copymap);
1390
1391         pservice->copymap = bitmap_talloc(pservice, num_parameters());
1392         if (!pservice->copymap) {
1393                 DEBUG(0,
1394                       ("Couldn't allocate copymap!! (size %d)\n",
1395                        (int)num_parameters()));
1396         } else {
1397                 for (i = 0; i < num_parameters(); i++) {
1398                         bitmap_set(pservice->copymap, i);
1399                 }
1400         }
1401 }
1402
1403 /**
1404  * Process a parametric option
1405  */
1406 static bool lp_do_parameter_parametric(struct loadparm_context *lp_ctx,
1407                                        struct loadparm_service *service,
1408                                        const char *pszParmName,
1409                                        const char *pszParmValue, int flags)
1410 {
1411         struct parmlist_entry **data;
1412         char *name;
1413         TALLOC_CTX *mem_ctx;
1414
1415         while (isspace((unsigned char)*pszParmName)) {
1416                 pszParmName++;
1417         }
1418
1419         name = strlower_talloc(lp_ctx, pszParmName);
1420         if (!name) return false;
1421
1422         if (service == NULL) {
1423                 data = &lp_ctx->globals->param_opt;
1424                 /**
1425                  * s3 code cannot deal with parametric options stored on the globals ctx.
1426                  */
1427                 if (lp_ctx->s3_fns != NULL) {
1428                         mem_ctx = NULL;
1429                 } else {
1430                         mem_ctx = lp_ctx->globals->ctx;
1431                 }
1432         } else {
1433                 data = &service->param_opt;
1434                 mem_ctx = service;
1435         }
1436
1437         set_param_opt(mem_ctx, data, name, pszParmValue, flags);
1438
1439         talloc_free(name);
1440
1441         return true;
1442 }
1443
1444 static bool set_variable_helper(TALLOC_CTX *mem_ctx, int parmnum, void *parm_ptr,
1445                          const char *pszParmName, const char *pszParmValue)
1446 {
1447         int i;
1448
1449         /* switch on the type of variable it is */
1450         switch (parm_table[parmnum].type)
1451         {
1452                 case P_BOOL: {
1453                         bool b;
1454                         if (!set_boolean(pszParmValue, &b)) {
1455                                 DEBUG(0, ("set_variable_helper(%s): value is not "
1456                                           "boolean!\n", pszParmValue));
1457                                 return false;
1458                         }
1459                         *(bool *)parm_ptr = b;
1460                         }
1461                         break;
1462
1463                 case P_BOOLREV: {
1464                         bool b;
1465                         if (!set_boolean(pszParmValue, &b)) {
1466                                 DEBUG(0, ("set_variable_helper(%s): value is not "
1467                                           "boolean!\n", pszParmValue));
1468                                 return false;
1469                         }
1470                         *(bool *)parm_ptr = !b;
1471                         }
1472                         break;
1473
1474                 case P_INTEGER:
1475                         *(int *)parm_ptr = lp_int(pszParmValue);
1476                         break;
1477
1478                 case P_CHAR:
1479                         *(char *)parm_ptr = *pszParmValue;
1480                         break;
1481
1482                 case P_OCTAL:
1483                         i = sscanf(pszParmValue, "%o", (int *)parm_ptr);
1484                         if ( i != 1 ) {
1485                                 DEBUG ( 0, ("Invalid octal number %s\n", pszParmName ));
1486                                 return false;
1487                         }
1488                         break;
1489
1490                 case P_BYTES:
1491                 {
1492                         uint64_t val;
1493                         if (conv_str_size_error(pszParmValue, &val)) {
1494                                 if (val <= INT_MAX) {
1495                                         *(int *)parm_ptr = (int)val;
1496                                         break;
1497                                 }
1498                         }
1499
1500                         DEBUG(0, ("set_variable_helper(%s): value is not "
1501                                   "a valid size specifier!\n", pszParmValue));
1502                         return false;
1503                 }
1504
1505                 case P_CMDLIST:
1506                         TALLOC_FREE(*(char ***)parm_ptr);
1507                         *(char ***)parm_ptr = str_list_make_v3(mem_ctx,
1508                                                         pszParmValue, NULL);
1509                         break;
1510
1511                 case P_LIST:
1512                 {
1513                         char **new_list = str_list_make_v3(mem_ctx,
1514                                                         pszParmValue, NULL);
1515                         if (new_list == NULL) {
1516                                 break;
1517                         }
1518
1519                         for (i=0; new_list[i]; i++) {
1520                                 if (*(const char ***)parm_ptr != NULL &&
1521                                     new_list[i][0] == '+' &&
1522                                     new_list[i][1])
1523                                 {
1524                                         if (!str_list_check(*(const char ***)parm_ptr,
1525                                                             &new_list[i][1])) {
1526                                                 *(const char ***)parm_ptr = str_list_add(*(const char ***)parm_ptr,
1527                                                                                          &new_list[i][1]);
1528                                         }
1529                                 } else if (*(const char ***)parm_ptr != NULL &&
1530                                            new_list[i][0] == '-' &&
1531                                            new_list[i][1])
1532                                 {
1533                                         str_list_remove(*(const char ***)parm_ptr,
1534                                                         &new_list[i][1]);
1535                                 } else {
1536                                         if (i != 0) {
1537                                                 DEBUG(0, ("Unsupported list syntax for: %s = %s\n",
1538                                                           pszParmName, pszParmValue));
1539                                                 return false;
1540                                         }
1541                                         *(char ***)parm_ptr = new_list;
1542                                         break;
1543                                 }
1544                         }
1545                         break;
1546                 }
1547
1548                 case P_STRING:
1549                         lpcfg_string_set(mem_ctx, (char **)parm_ptr, pszParmValue);
1550                         break;
1551
1552                 case P_USTRING:
1553                         lpcfg_string_set_upper(mem_ctx, (char **)parm_ptr, pszParmValue);
1554                         break;
1555
1556                 case P_ENUM:
1557                         if (!lp_set_enum_parm(&parm_table[parmnum], pszParmValue, (int*)parm_ptr)) {
1558                                 return false;
1559                         }
1560                         break;
1561
1562                 case P_SEP:
1563                         break;
1564         }
1565
1566         return true;
1567
1568 }
1569
1570 bool set_variable(TALLOC_CTX *mem_ctx, struct loadparm_service *service, int parmnum, void *parm_ptr,
1571                          const char *pszParmName, const char *pszParmValue,
1572                          struct loadparm_context *lp_ctx, bool on_globals)
1573 {
1574         int i;
1575         bool ok;
1576
1577         /* if it is a special case then go ahead */
1578         if (parm_table[parmnum].special) {
1579                 ok = parm_table[parmnum].special(lp_ctx, service, pszParmValue,
1580                                                   (char **)parm_ptr);
1581                 if (!ok) {
1582                         return false;
1583                 }
1584                 goto mark_non_default;
1585         }
1586
1587         ok = set_variable_helper(mem_ctx, parmnum, parm_ptr, pszParmName, pszParmValue);
1588
1589         if (!ok) {
1590                 return false;
1591         }
1592
1593 mark_non_default:
1594         if (on_globals && (lp_ctx->flags[parmnum] & FLAG_DEFAULT)) {
1595                 lp_ctx->flags[parmnum] &= ~FLAG_DEFAULT;
1596                 /* we have to also unset FLAG_DEFAULT on aliases */
1597                 for (i=parmnum-1;i>=0 && parm_table[i].offset == parm_table[parmnum].offset;i--) {
1598                         lp_ctx->flags[i] &= ~FLAG_DEFAULT;
1599                 }
1600                 for (i=parmnum+1;i<num_parameters() && parm_table[i].offset == parm_table[parmnum].offset;i++) {
1601                         lp_ctx->flags[i] &= ~FLAG_DEFAULT;
1602                 }
1603         }
1604         return true;
1605 }
1606
1607
1608 bool lpcfg_do_global_parameter(struct loadparm_context *lp_ctx,
1609                                const char *pszParmName, const char *pszParmValue)
1610 {
1611         int parmnum = lpcfg_map_parameter(pszParmName);
1612         void *parm_ptr;
1613
1614         if (parmnum < 0) {
1615                 if (strchr(pszParmName, ':')) {
1616                         return lp_do_parameter_parametric(lp_ctx, NULL, pszParmName, pszParmValue, 0);
1617                 }
1618                 DEBUG(0, ("Ignoring unknown parameter \"%s\"\n", pszParmName));
1619                 return true;
1620         }
1621
1622         /* if the flag has been set on the command line, then don't allow override,
1623            but don't report an error */
1624         if (lp_ctx->flags[parmnum] & FLAG_CMDLINE) {
1625                 return true;
1626         }
1627
1628         if (parm_table[parmnum].flags & FLAG_DEPRECATED) {
1629                 DEBUG(1, ("WARNING: The \"%s\" option is deprecated\n",
1630                           pszParmName));
1631         }
1632
1633         parm_ptr = lpcfg_parm_ptr(lp_ctx, NULL, &parm_table[parmnum]);
1634
1635         return set_variable(lp_ctx->globals->ctx, NULL, parmnum, parm_ptr,
1636                             pszParmName, pszParmValue, lp_ctx, true);
1637 }
1638
1639 bool lpcfg_do_service_parameter(struct loadparm_context *lp_ctx,
1640                                 struct loadparm_service *service,
1641                                 const char *pszParmName, const char *pszParmValue)
1642 {
1643         void *parm_ptr;
1644         int i;
1645         int parmnum = lpcfg_map_parameter(pszParmName);
1646
1647         if (parmnum < 0) {
1648                 if (strchr(pszParmName, ':')) {
1649                         return lp_do_parameter_parametric(lp_ctx, service, pszParmName, pszParmValue, 0);
1650                 }
1651                 DEBUG(0, ("Ignoring unknown parameter \"%s\"\n", pszParmName));
1652                 return true;
1653         }
1654
1655         /* if the flag has been set on the command line, then don't allow override,
1656            but don't report an error */
1657         if (lp_ctx->flags[parmnum] & FLAG_CMDLINE) {
1658                 return true;
1659         }
1660
1661         if (parm_table[parmnum].flags & FLAG_DEPRECATED) {
1662                 DEBUG(1, ("WARNING: The \"%s\" option is deprecated\n",
1663                           pszParmName));
1664         }
1665
1666         if (parm_table[parmnum].p_class == P_GLOBAL) {
1667                 DEBUG(0,
1668                       ("Global parameter %s found in service section!\n",
1669                        pszParmName));
1670                 return true;
1671         }
1672         parm_ptr = ((char *)service) + parm_table[parmnum].offset;
1673
1674         if (!service->copymap)
1675                 init_copymap(service);
1676
1677         /* this handles the aliases - set the copymap for other
1678          * entries with the same data pointer */
1679         for (i = 0; parm_table[i].label; i++)
1680                 if (parm_table[i].offset == parm_table[parmnum].offset &&
1681                     parm_table[i].p_class == parm_table[parmnum].p_class)
1682                         bitmap_clear(service->copymap, i);
1683
1684         return set_variable(service, service, parmnum, parm_ptr, pszParmName,
1685                             pszParmValue, lp_ctx, false);
1686 }
1687
1688 /**
1689  * Process a parameter.
1690  */
1691
1692 bool lpcfg_do_parameter(const char *pszParmName, const char *pszParmValue,
1693                          void *userdata)
1694 {
1695         struct loadparm_context *lp_ctx = (struct loadparm_context *)userdata;
1696
1697         if (lp_ctx->bInGlobalSection)
1698                 return lpcfg_do_global_parameter(lp_ctx, pszParmName,
1699                                               pszParmValue);
1700         else
1701                 return lpcfg_do_service_parameter(lp_ctx, lp_ctx->currentService,
1702                                                   pszParmName, pszParmValue);
1703 }
1704
1705 /*
1706   variable argument do parameter
1707 */
1708 bool lpcfg_do_global_parameter_var(struct loadparm_context *lp_ctx, const char *pszParmName, const char *fmt, ...) PRINTF_ATTRIBUTE(3, 4);
1709 bool lpcfg_do_global_parameter_var(struct loadparm_context *lp_ctx,
1710                                 const char *pszParmName, const char *fmt, ...)
1711 {
1712         char *s;
1713         bool ret;
1714         va_list ap;
1715
1716         va_start(ap, fmt);
1717         s = talloc_vasprintf(NULL, fmt, ap);
1718         va_end(ap);
1719         ret = lpcfg_do_global_parameter(lp_ctx, pszParmName, s);
1720         talloc_free(s);
1721         return ret;
1722 }
1723
1724
1725 /*
1726   set a parameter from the commandline - this is called from command line parameter
1727   parsing code. It sets the parameter then marks the parameter as unable to be modified
1728   by smb.conf processing
1729 */
1730 bool lpcfg_set_cmdline(struct loadparm_context *lp_ctx, const char *pszParmName,
1731                        const char *pszParmValue)
1732 {
1733         int parmnum;
1734         int i;
1735
1736         while (isspace((unsigned char)*pszParmValue)) pszParmValue++;
1737
1738         parmnum = lpcfg_map_parameter(pszParmName);
1739
1740         if (parmnum < 0 && strchr(pszParmName, ':')) {
1741                 /* set a parametric option */
1742                 bool ok;
1743                 ok = lp_do_parameter_parametric(lp_ctx, NULL, pszParmName,
1744                                                 pszParmValue, FLAG_CMDLINE);
1745                 if (lp_ctx->s3_fns != NULL) {
1746                         if (ok) {
1747                                 lp_ctx->s3_fns->store_cmdline(pszParmName, pszParmValue);
1748                         }
1749                 }
1750                 return ok;
1751         }
1752
1753         if (parmnum < 0) {
1754                 DEBUG(0,("Unknown option '%s'\n", pszParmName));
1755                 return false;
1756         }
1757
1758         /* reset the CMDLINE flag in case this has been called before */
1759         lp_ctx->flags[parmnum] &= ~FLAG_CMDLINE;
1760
1761         if (!lpcfg_do_global_parameter(lp_ctx, pszParmName, pszParmValue)) {
1762                 return false;
1763         }
1764
1765         lp_ctx->flags[parmnum] |= FLAG_CMDLINE;
1766
1767         /* we have to also set FLAG_CMDLINE on aliases */
1768         for (i=parmnum-1;
1769              i>=0 && parm_table[i].p_class == parm_table[parmnum].p_class &&
1770              parm_table[i].offset == parm_table[parmnum].offset;
1771              i--) {
1772                 lp_ctx->flags[i] |= FLAG_CMDLINE;
1773         }
1774         for (i=parmnum+1;
1775              i<num_parameters() &&
1776              parm_table[i].p_class == parm_table[parmnum].p_class &&
1777              parm_table[i].offset == parm_table[parmnum].offset;
1778              i++) {
1779                 lp_ctx->flags[i] |= FLAG_CMDLINE;
1780         }
1781
1782         if (lp_ctx->s3_fns != NULL) {
1783                 lp_ctx->s3_fns->store_cmdline(pszParmName, pszParmValue);
1784         }
1785
1786         return true;
1787 }
1788
1789 /*
1790   set a option from the commandline in 'a=b' format. Use to support --option
1791 */
1792 bool lpcfg_set_option(struct loadparm_context *lp_ctx, const char *option)
1793 {
1794         char *p, *s;
1795         bool ret;
1796
1797         s = talloc_strdup(NULL, option);
1798         if (!s) {
1799                 return false;
1800         }
1801
1802         p = strchr(s, '=');
1803         if (!p) {
1804                 talloc_free(s);
1805                 return false;
1806         }
1807
1808         *p = 0;
1809
1810         ret = lpcfg_set_cmdline(lp_ctx, s, p+1);
1811         talloc_free(s);
1812         return ret;
1813 }
1814
1815
1816 #define BOOLSTR(b) ((b) ? "Yes" : "No")
1817
1818 /**
1819  * Print a parameter of the specified type.
1820  */
1821
1822 void lpcfg_print_parameter(struct parm_struct *p, void *ptr, FILE * f)
1823 {
1824         /* For the seperation of lists values that we print below */
1825         const char *list_sep = ", ";
1826         int i;
1827         switch (p->type)
1828         {
1829                 case P_ENUM:
1830                         for (i = 0; p->enum_list[i].name; i++) {
1831                                 if (*(int *)ptr == p->enum_list[i].value) {
1832                                         fprintf(f, "%s",
1833                                                 p->enum_list[i].name);
1834                                         break;
1835                                 }
1836                         }
1837                         break;
1838
1839                 case P_BOOL:
1840                         fprintf(f, "%s", BOOLSTR(*(bool *)ptr));
1841                         break;
1842
1843                 case P_BOOLREV:
1844                         fprintf(f, "%s", BOOLSTR(!*(bool *)ptr));
1845                         break;
1846
1847                 case P_INTEGER:
1848                 case P_BYTES:
1849                         fprintf(f, "%d", *(int *)ptr);
1850                         break;
1851
1852                 case P_CHAR:
1853                         fprintf(f, "%c", *(char *)ptr);
1854                         break;
1855
1856                 case P_OCTAL: {
1857                         int val = *(int *)ptr; 
1858                         if (val == -1) {
1859                                 fprintf(f, "-1");
1860                         } else {
1861                                 fprintf(f, "0%03o", val);
1862                         }
1863                         break;
1864                 }
1865
1866                 case P_CMDLIST:
1867                         list_sep = " ";
1868                         /* fall through */
1869                 case P_LIST:
1870                         if ((char ***)ptr && *(char ***)ptr) {
1871                                 char **list = *(char ***)ptr;
1872                                 for (; *list; list++) {
1873                                         /* surround strings with whitespace in double quotes */
1874                                         if (*(list+1) == NULL) {
1875                                                 /* last item, no extra separator */
1876                                                 list_sep = "";
1877                                         }
1878                                         if ( strchr_m( *list, ' ' ) ) {
1879                                                 fprintf(f, "\"%s\"%s", *list, list_sep);
1880                                         } else {
1881                                                 fprintf(f, "%s%s", *list, list_sep);
1882                                         }
1883                                 }
1884                         }
1885                         break;
1886
1887                 case P_STRING:
1888                 case P_USTRING:
1889                         if (*(char **)ptr) {
1890                                 fprintf(f, "%s", *(char **)ptr);
1891                         }
1892                         break;
1893                 case P_SEP:
1894                         break;
1895         }
1896 }
1897
1898 /**
1899  * Check if two parameters are equal.
1900  */
1901
1902 static bool lpcfg_equal_parameter(parm_type type, void *ptr1, void *ptr2)
1903 {
1904         switch (type) {
1905                 case P_BOOL:
1906                 case P_BOOLREV:
1907                         return (*((bool *)ptr1) == *((bool *)ptr2));
1908
1909                 case P_INTEGER:
1910                 case P_ENUM:
1911                 case P_OCTAL:
1912                 case P_BYTES:
1913                         return (*((int *)ptr1) == *((int *)ptr2));
1914
1915                 case P_CHAR:
1916                         return (*((char *)ptr1) == *((char *)ptr2));
1917
1918                 case P_LIST:
1919                 case P_CMDLIST:
1920                         return str_list_equal(*(const char ***)ptr1, *(const char ***)ptr2);
1921
1922                 case P_STRING:
1923                 case P_USTRING:
1924                 {
1925                         char *p1 = *(char **)ptr1, *p2 = *(char **)ptr2;
1926                         if (p1 && !*p1)
1927                                 p1 = NULL;
1928                         if (p2 && !*p2)
1929                                 p2 = NULL;
1930                         return (p1 == p2 || strequal(p1, p2));
1931                 }
1932                 case P_SEP:
1933                         break;
1934         }
1935         return false;
1936 }
1937
1938 /**
1939  * Process a new section (service).
1940  *
1941  * At this stage all sections are services.
1942  * Later we'll have special sections that permit server parameters to be set.
1943  * Returns True on success, False on failure.
1944  */
1945
1946 static bool do_section(const char *pszSectionName, void *userdata)
1947 {
1948         struct loadparm_context *lp_ctx = (struct loadparm_context *)userdata;
1949         bool bRetval;
1950         bool isglobal;
1951
1952         if (lp_ctx->s3_fns != NULL) {
1953                 return lp_ctx->s3_fns->do_section(pszSectionName, lp_ctx);
1954         }
1955
1956         isglobal = ((strwicmp(pszSectionName, GLOBAL_NAME) == 0) ||
1957                          (strwicmp(pszSectionName, GLOBAL_NAME2) == 0));
1958
1959         bRetval = false;
1960
1961         /* if we've just struck a global section, note the fact. */
1962         lp_ctx->bInGlobalSection = isglobal;
1963
1964         /* check for multiple global sections */
1965         if (lp_ctx->bInGlobalSection) {
1966                 DEBUG(4, ("Processing section \"[%s]\"\n", pszSectionName));
1967                 return true;
1968         }
1969
1970         /* if we have a current service, tidy it up before moving on */
1971         bRetval = true;
1972
1973         if (lp_ctx->currentService != NULL)
1974                 bRetval = lpcfg_service_ok(lp_ctx->currentService);
1975
1976         /* if all is still well, move to the next record in the services array */
1977         if (bRetval) {
1978                 /* We put this here to avoid an odd message order if messages are */
1979                 /* issued by the post-processing of a previous section. */
1980                 DEBUG(4, ("Processing section \"[%s]\"\n", pszSectionName));
1981
1982                 if ((lp_ctx->currentService = lpcfg_add_service(lp_ctx, lp_ctx->sDefault,
1983                                                                    pszSectionName))
1984                     == NULL) {
1985                         DEBUG(0, ("Failed to add a new service\n"));
1986                         return false;
1987                 }
1988         }
1989
1990         return bRetval;
1991 }
1992
1993
1994 /**
1995  * Determine if a particular base parameter is currently set to the default value.
1996  */
1997
1998 static bool is_default(void *base_structure, int i)
1999 {
2000         void *def_ptr = ((char *)base_structure) + parm_table[i].offset;
2001         switch (parm_table[i].type) {
2002                 case P_CMDLIST:
2003                 case P_LIST:
2004                         return str_list_equal((const char * const *)parm_table[i].def.lvalue,
2005                                               *(const char * const **)def_ptr);
2006                 case P_STRING:
2007                 case P_USTRING:
2008                         return strequal(parm_table[i].def.svalue,
2009                                         *(char **)def_ptr);
2010                 case P_BOOL:
2011                 case P_BOOLREV:
2012                         return parm_table[i].def.bvalue ==
2013                                 *(bool *)def_ptr;
2014                 case P_INTEGER:
2015                 case P_CHAR:
2016                 case P_OCTAL:
2017                 case P_BYTES:
2018                 case P_ENUM:
2019                         return parm_table[i].def.ivalue ==
2020                                 *(int *)def_ptr;
2021                 case P_SEP:
2022                         break;
2023         }
2024         return false;
2025 }
2026
2027 /**
2028  *Display the contents of the global structure.
2029  */
2030
2031 void lpcfg_dump_globals(struct loadparm_context *lp_ctx, FILE *f,
2032                          bool show_defaults)
2033 {
2034         int i;
2035         struct parmlist_entry *data;
2036
2037         fprintf(f, "# Global parameters\n[global]\n");
2038
2039         for (i = 0; parm_table[i].label; i++)
2040                 if (parm_table[i].p_class == P_GLOBAL &&
2041                     (i == 0 || (parm_table[i].offset != parm_table[i - 1].offset))) {
2042                         if (!show_defaults) {
2043                                 if (lp_ctx->flags && (lp_ctx->flags[i] & FLAG_DEFAULT)) {
2044                                         continue;
2045                                 }
2046
2047                                 if (is_default(lp_ctx->globals, i)) {
2048                                         continue;
2049                                 }
2050                         }
2051
2052                         fprintf(f, "\t%s = ", parm_table[i].label);
2053                         lpcfg_print_parameter(&parm_table[i], lpcfg_parm_ptr(lp_ctx, NULL, &parm_table[i]), f);
2054                         fprintf(f, "\n");
2055         }
2056         if (lp_ctx->globals->param_opt != NULL) {
2057                 for (data = lp_ctx->globals->param_opt; data;
2058                      data = data->next) {
2059                         if (!show_defaults && (data->priority & FLAG_DEFAULT)) {
2060                                 continue;
2061                         }
2062                         fprintf(f, "\t%s = %s\n", data->key, data->value);
2063                 }
2064         }
2065
2066 }
2067
2068 /**
2069  * Display the contents of a single services record.
2070  */
2071
2072 void lpcfg_dump_a_service(struct loadparm_service * pService, struct loadparm_service *sDefault, FILE * f,
2073                           unsigned int *flags, bool show_defaults)
2074 {
2075         int i;
2076         struct parmlist_entry *data;
2077
2078         if (pService != sDefault)
2079                 fprintf(f, "\n[%s]\n", pService->szService);
2080
2081         for (i = 0; parm_table[i].label; i++) {
2082                 if (parm_table[i].p_class == P_LOCAL &&
2083                     (*parm_table[i].label != '-') &&
2084                     (i == 0 || (parm_table[i].offset != parm_table[i - 1].offset)))
2085                 {
2086                         if (pService == sDefault) {
2087                                 if (flags && (flags[i] & FLAG_DEFAULT)) {
2088                                         continue;
2089                                 }
2090                                 if (!show_defaults) {
2091                                         if (is_default(sDefault, i)) {
2092                                                 continue;
2093                                         }
2094                                 }
2095                         } else {
2096                                 if (lpcfg_equal_parameter(parm_table[i].type,
2097                                                           ((char *)pService) +
2098                                                           parm_table[i].offset,
2099                                                           ((char *)sDefault) +
2100                                                           parm_table[i].offset))
2101                                         continue;
2102                         }
2103
2104                         fprintf(f, "\t%s = ", parm_table[i].label);
2105                         lpcfg_print_parameter(&parm_table[i],
2106                                         ((char *)pService) + parm_table[i].offset, f);
2107                         fprintf(f, "\n");
2108                 }
2109         }
2110         if (pService->param_opt != NULL) {
2111                 for (data = pService->param_opt; data; data = data->next) {
2112                         if (!show_defaults && (data->priority & FLAG_DEFAULT)) {
2113                                 continue;
2114                         }
2115                         fprintf(f, "\t%s = %s\n", data->key, data->value);
2116                 }
2117         }
2118 }
2119
2120 bool lpcfg_dump_a_parameter(struct loadparm_context *lp_ctx,
2121                             struct loadparm_service *service,
2122                             const char *parm_name, FILE * f)
2123 {
2124         struct parm_struct *parm;
2125         void *ptr;
2126         char *local_parm_name;
2127         char *parm_opt;
2128         const char *parm_opt_value;
2129
2130         /* check for parametrical option */
2131         local_parm_name = talloc_strdup(lp_ctx, parm_name);
2132         if (local_parm_name == NULL) {
2133                 return false;
2134         }
2135
2136         parm_opt = strchr( local_parm_name, ':');
2137
2138         if (parm_opt) {
2139                 *parm_opt = '\0';
2140                 parm_opt++;
2141                 if (strlen(parm_opt)) {
2142                         parm_opt_value = lpcfg_parm_string(lp_ctx, service,
2143                                 local_parm_name, parm_opt);
2144                         if (parm_opt_value) {
2145                                 fprintf(f, "%s\n", parm_opt_value);
2146                                 return true;
2147                         }
2148                 }
2149                 return false;
2150         }
2151
2152         /* parameter is not parametric, search the table */
2153         parm = lpcfg_parm_struct(lp_ctx, parm_name);
2154         if (!parm) {
2155                 return false;
2156         }
2157
2158         if (service != NULL && parm->p_class == P_GLOBAL) {
2159                 return false;
2160         }
2161
2162         ptr = lpcfg_parm_ptr(lp_ctx, service,parm);
2163
2164         lpcfg_print_parameter(parm, ptr, f);
2165         fprintf(f, "\n");
2166         return true;
2167 }
2168
2169 /**
2170  * Auto-load some home services.
2171  */
2172 static void lpcfg_add_auto_services(struct loadparm_context *lp_ctx,
2173                                     const char *str)
2174 {
2175         return;
2176 }
2177
2178 /***************************************************************************
2179  Initialise the sDefault parameter structure for the printer values.
2180 ***************************************************************************/
2181
2182 void init_printer_values(struct loadparm_context *lp_ctx, TALLOC_CTX *ctx,
2183                          struct loadparm_service *pService)
2184 {
2185         /* choose defaults depending on the type of printing */
2186         switch (pService->printing) {
2187                 case PRINT_BSD:
2188                 case PRINT_AIX:
2189                 case PRINT_LPRNT:
2190                 case PRINT_LPROS2:
2191                         lpcfg_string_set(ctx, &pService->lpq_command, "lpq -P'%p'");
2192                         lpcfg_string_set(ctx, &pService->lprm_command, "lprm -P'%p' %j");
2193                         lpcfg_string_set(ctx, &pService->print_command, "lpr -r -P'%p' %s");
2194                         break;
2195
2196                 case PRINT_LPRNG:
2197                 case PRINT_PLP:
2198                         lpcfg_string_set(ctx, &pService->lpq_command, "lpq -P'%p'");
2199                         lpcfg_string_set(ctx, &pService->lprm_command, "lprm -P'%p' %j");
2200                         lpcfg_string_set(ctx, &pService->print_command, "lpr -r -P'%p' %s");
2201                         lpcfg_string_set(ctx, &pService->queuepause_command, "lpc stop '%p'");
2202                         lpcfg_string_set(ctx, &pService->queueresume_command, "lpc start '%p'");
2203                         lpcfg_string_set(ctx, &pService->lppause_command, "lpc hold '%p' %j");
2204                         lpcfg_string_set(ctx, &pService->lpresume_command, "lpc release '%p' %j");
2205                         break;
2206
2207                 case PRINT_CUPS:
2208                 case PRINT_IPRINT:
2209                         /* set the lpq command to contain the destination printer
2210                            name only.  This is used by cups_queue_get() */
2211                         lpcfg_string_set(ctx, &pService->lpq_command, "%p");
2212                         lpcfg_string_set(ctx, &pService->lprm_command, "");
2213                         lpcfg_string_set(ctx, &pService->print_command, "");
2214                         lpcfg_string_set(ctx, &pService->lppause_command, "");
2215                         lpcfg_string_set(ctx, &pService->lpresume_command, "");
2216                         lpcfg_string_set(ctx, &pService->queuepause_command, "");
2217                         lpcfg_string_set(ctx, &pService->queueresume_command, "");
2218                         break;
2219
2220                 case PRINT_SYSV:
2221                 case PRINT_HPUX:
2222                         lpcfg_string_set(ctx, &pService->lpq_command, "lpstat -o%p");
2223                         lpcfg_string_set(ctx, &pService->lprm_command, "cancel %p-%j");
2224                         lpcfg_string_set(ctx, &pService->print_command, "lp -c -d%p %s; rm %s");
2225                         lpcfg_string_set(ctx, &pService->queuepause_command, "disable %p");
2226                         lpcfg_string_set(ctx, &pService->queueresume_command, "enable %p");
2227 #ifndef HPUX
2228                         lpcfg_string_set(ctx, &pService->lppause_command, "lp -i %p-%j -H hold");
2229                         lpcfg_string_set(ctx, &pService->lpresume_command, "lp -i %p-%j -H resume");
2230 #endif /* HPUX */
2231                         break;
2232
2233                 case PRINT_QNX:
2234                         lpcfg_string_set(ctx, &pService->lpq_command, "lpq -P%p");
2235                         lpcfg_string_set(ctx, &pService->lprm_command, "lprm -P%p %j");
2236                         lpcfg_string_set(ctx, &pService->print_command, "lp -r -P%p %s");
2237                         break;
2238
2239 #if defined(DEVELOPER) || defined(ENABLE_SELFTEST)
2240
2241         case PRINT_TEST:
2242         case PRINT_VLP: {
2243                 const char *tdbfile;
2244                 TALLOC_CTX *tmp_ctx = talloc_new(ctx);
2245                 const char *tmp;
2246
2247                 tmp = lpcfg_parm_string(lp_ctx, NULL, "vlp", "tdbfile");
2248                 if (tmp == NULL) {
2249                         tmp = "/tmp/vlp.tdb";
2250                 }
2251
2252                 tdbfile = talloc_asprintf(tmp_ctx, "tdbfile=%s", tmp);
2253                 if (tdbfile == NULL) {
2254                         tdbfile="tdbfile=/tmp/vlp.tdb";
2255                 }
2256
2257                 tmp = talloc_asprintf(tmp_ctx, "vlp %s print %%p %%s",
2258                                       tdbfile);
2259                 lpcfg_string_set(ctx, &pService->print_command,
2260                            tmp ? tmp : "vlp print %p %s");
2261
2262                 tmp = talloc_asprintf(tmp_ctx, "vlp %s lpq %%p",
2263                                       tdbfile);
2264                 lpcfg_string_set(ctx, &pService->lpq_command,
2265                            tmp ? tmp : "vlp lpq %p");
2266
2267                 tmp = talloc_asprintf(tmp_ctx, "vlp %s lprm %%p %%j",
2268                                       tdbfile);
2269                 lpcfg_string_set(ctx, &pService->lprm_command,
2270                            tmp ? tmp : "vlp lprm %p %j");
2271
2272                 tmp = talloc_asprintf(tmp_ctx, "vlp %s lppause %%p %%j",
2273                                       tdbfile);
2274                 lpcfg_string_set(ctx, &pService->lppause_command,
2275                            tmp ? tmp : "vlp lppause %p %j");
2276
2277                 tmp = talloc_asprintf(tmp_ctx, "vlp %s lpresume %%p %%j",
2278                                       tdbfile);
2279                 lpcfg_string_set(ctx, &pService->lpresume_command,
2280                            tmp ? tmp : "vlp lpresume %p %j");
2281
2282                 tmp = talloc_asprintf(tmp_ctx, "vlp %s queuepause %%p",
2283                                       tdbfile);
2284                 lpcfg_string_set(ctx, &pService->queuepause_command,
2285                            tmp ? tmp : "vlp queuepause %p");
2286
2287                 tmp = talloc_asprintf(tmp_ctx, "vlp %s queueresume %%p",
2288                                       tdbfile);
2289                 lpcfg_string_set(ctx, &pService->queueresume_command,
2290                            tmp ? tmp : "vlp queueresume %p");
2291                 TALLOC_FREE(tmp_ctx);
2292
2293                 break;
2294         }
2295 #endif /* DEVELOPER */
2296
2297         }
2298 }
2299
2300 /**
2301  * Unload unused services.
2302  */
2303
2304 void lpcfg_killunused(struct loadparm_context *lp_ctx,
2305                    struct smbsrv_connection *smb,
2306                    bool (*snumused) (struct smbsrv_connection *, int))
2307 {
2308         int i;
2309
2310         if (lp_ctx->s3_fns != NULL) {
2311                 smb_panic("Cannot be used from an s3 loadparm ctx");
2312         }
2313
2314         for (i = 0; i < lp_ctx->iNumServices; i++) {
2315                 if (lp_ctx->services[i] == NULL)
2316                         continue;
2317
2318                 if (!snumused || !snumused(smb, i)) {
2319                         talloc_free(lp_ctx->services[i]);
2320                         lp_ctx->services[i] = NULL;
2321                 }
2322         }
2323 }
2324
2325
2326 static int lpcfg_destructor(struct loadparm_context *lp_ctx)
2327 {
2328         struct parmlist_entry *data;
2329
2330         if (lp_ctx->refuse_free) {
2331                 /* someone is trying to free the
2332                    global_loadparm_context.
2333                    We can't allow that. */
2334                 return -1;
2335         }
2336
2337         if (lp_ctx->globals->param_opt != NULL) {
2338                 struct parmlist_entry *next;
2339                 for (data = lp_ctx->globals->param_opt; data; data=next) {
2340                         next = data->next;
2341                         if (data->priority & FLAG_CMDLINE) continue;
2342                         DLIST_REMOVE(lp_ctx->globals->param_opt, data);
2343                         talloc_free(data);
2344                 }
2345         }
2346
2347         return 0;
2348 }
2349
2350 /**
2351  * Initialise the global parameter structure.
2352  *
2353  * Note that most callers should use loadparm_init_global() instead
2354  */
2355 struct loadparm_context *loadparm_init(TALLOC_CTX *mem_ctx)
2356 {
2357         int i;
2358         char *myname;
2359         struct loadparm_context *lp_ctx;
2360         struct parmlist_entry *parm;
2361         char *logfile;
2362
2363         lp_ctx = talloc_zero(mem_ctx, struct loadparm_context);
2364         if (lp_ctx == NULL)
2365                 return NULL;
2366
2367         talloc_set_destructor(lp_ctx, lpcfg_destructor);
2368         lp_ctx->bInGlobalSection = true;
2369         lp_ctx->globals = talloc_zero(lp_ctx, struct loadparm_global);
2370         /* This appears odd, but globals in s3 isn't a pointer */
2371         lp_ctx->globals->ctx = lp_ctx->globals;
2372         lp_ctx->sDefault = talloc_zero(lp_ctx, struct loadparm_service);
2373         lp_ctx->flags = talloc_zero_array(lp_ctx, unsigned int, num_parameters());
2374
2375         lp_ctx->sDefault->iMaxPrintJobs = 1000;
2376         lp_ctx->sDefault->bAvailable = true;
2377         lp_ctx->sDefault->browseable = true;
2378         lp_ctx->sDefault->read_only = true;
2379         lp_ctx->sDefault->map_archive = true;
2380         lp_ctx->sDefault->strict_locking = true;
2381         lp_ctx->sDefault->oplocks = true;
2382         lp_ctx->sDefault->create_mask = 0744;
2383         lp_ctx->sDefault->force_create_mode = 0000;
2384         lp_ctx->sDefault->directory_mask = 0755;
2385         lp_ctx->sDefault->force_directory_mode = 0000;
2386
2387         DEBUG(3, ("Initialising global parameters\n"));
2388
2389         for (i = 0; parm_table[i].label; i++) {
2390                 if ((parm_table[i].type == P_STRING ||
2391                      parm_table[i].type == P_USTRING) &&
2392                     !(lp_ctx->flags[i] & FLAG_CMDLINE)) {
2393                         char **r;
2394                         if (parm_table[i].p_class == P_LOCAL) {
2395                                 r = (char **)(((char *)lp_ctx->sDefault) + parm_table[i].offset);
2396                         } else {
2397                                 r = (char **)(((char *)lp_ctx->globals) + parm_table[i].offset);
2398                         }
2399                         *r = talloc_strdup(lp_ctx, "");
2400                 }
2401         }
2402
2403         logfile = talloc_asprintf(lp_ctx, "%s/log.samba", dyn_LOGFILEBASE);
2404         lpcfg_do_global_parameter(lp_ctx, "log file", logfile);
2405         talloc_free(logfile);
2406
2407         lpcfg_do_global_parameter(lp_ctx, "log level", "0");
2408
2409         lpcfg_do_global_parameter(lp_ctx, "syslog", "1");
2410         lpcfg_do_global_parameter(lp_ctx, "syslog only", "No");
2411         lpcfg_do_global_parameter(lp_ctx, "debug timestamp", "Yes");
2412         lpcfg_do_global_parameter(lp_ctx, "debug prefix timestamp", "No");
2413         lpcfg_do_global_parameter(lp_ctx, "debug hires timestamp", "Yes");
2414         lpcfg_do_global_parameter(lp_ctx, "debug pid", "No");
2415         lpcfg_do_global_parameter(lp_ctx, "debug uid", "No");
2416         lpcfg_do_global_parameter(lp_ctx, "debug class", "No");
2417
2418         lpcfg_do_global_parameter(lp_ctx, "share backend", "classic");
2419
2420         lpcfg_do_global_parameter(lp_ctx, "server role", "auto");
2421         lpcfg_do_global_parameter(lp_ctx, "domain logons", "No");
2422         lpcfg_do_global_parameter(lp_ctx, "domain master", "Auto");
2423
2424         /* options that can be set on the command line must be initialised via
2425            the slower lpcfg_do_global_parameter() to ensure that FLAG_CMDLINE is obeyed */
2426 #ifdef TCP_NODELAY
2427         lpcfg_do_global_parameter(lp_ctx, "socket options", "TCP_NODELAY");
2428 #endif
2429         lpcfg_do_global_parameter(lp_ctx, "workgroup", DEFAULT_WORKGROUP);
2430         myname = get_myname(lp_ctx);
2431         lpcfg_do_global_parameter(lp_ctx, "netbios name", myname);
2432         talloc_free(myname);
2433         lpcfg_do_global_parameter(lp_ctx, "name resolve order", "lmhosts wins host bcast");
2434
2435         lpcfg_do_global_parameter(lp_ctx, "fstype", "NTFS");
2436
2437         lpcfg_do_global_parameter(lp_ctx, "ntvfs handler", "unixuid default");
2438         lpcfg_do_global_parameter(lp_ctx, "max connections", "0");
2439
2440         lpcfg_do_global_parameter(lp_ctx, "dcerpc endpoint servers", "epmapper wkssvc rpcecho samr netlogon lsarpc spoolss drsuapi dssetup unixinfo browser eventlog6 backupkey dnsserver");
2441         lpcfg_do_global_parameter(lp_ctx, "server services", "s3fs rpc nbt wrepl ldap cldap kdc drepl winbindd ntp_signd kcc dnsupdate dns");
2442         lpcfg_do_global_parameter(lp_ctx, "kccsrv:samba_kcc", "false");
2443         /* the winbind method for domain controllers is for both RODC
2444            auth forwarding and for trusted domains */
2445         lpcfg_do_global_parameter(lp_ctx, "private dir", dyn_PRIVATE_DIR);
2446         lpcfg_do_global_parameter(lp_ctx, "registry:HKEY_LOCAL_MACHINE", "hklm.ldb");
2447
2448         /* This hive should be dynamically generated by Samba using
2449            data from the sam, but for the moment leave it in a tdb to
2450            keep regedt32 from popping up an annoying dialog. */
2451         lpcfg_do_global_parameter(lp_ctx, "registry:HKEY_USERS", "hku.ldb");
2452
2453         /* using UTF8 by default allows us to support all chars */
2454         lpcfg_do_global_parameter(lp_ctx, "unix charset", "UTF-8");
2455
2456         /* Use codepage 850 as a default for the dos character set */
2457         lpcfg_do_global_parameter(lp_ctx, "dos charset", "CP850");
2458
2459         /*
2460          * Allow the default PASSWD_CHAT to be overridden in local.h.
2461          */
2462         lpcfg_do_global_parameter(lp_ctx, "passwd chat", DEFAULT_PASSWD_CHAT);
2463
2464         lpcfg_do_global_parameter(lp_ctx, "pid directory", dyn_PIDDIR);
2465         lpcfg_do_global_parameter(lp_ctx, "lock dir", dyn_LOCKDIR);
2466         lpcfg_do_global_parameter(lp_ctx, "state directory", dyn_STATEDIR);
2467         lpcfg_do_global_parameter(lp_ctx, "cache directory", dyn_CACHEDIR);
2468         lpcfg_do_global_parameter(lp_ctx, "ncalrpc dir", dyn_NCALRPCDIR);
2469
2470         lpcfg_do_global_parameter(lp_ctx, "nbt client socket address", "0.0.0.0");
2471         lpcfg_do_global_parameter_var(lp_ctx, "server string",
2472                                    "Samba %s", SAMBA_VERSION_STRING);
2473
2474         lpcfg_do_global_parameter(lp_ctx, "password server", "*");
2475
2476         lpcfg_do_global_parameter(lp_ctx, "max mux", "50");
2477         lpcfg_do_global_parameter(lp_ctx, "max xmit", "16644");
2478         lpcfg_do_global_parameter(lp_ctx, "host msdfs", "true");
2479
2480         lpcfg_do_global_parameter(lp_ctx, "LargeReadwrite", "True");
2481         lpcfg_do_global_parameter(lp_ctx, "server min protocol", "LANMAN1");
2482         lpcfg_do_global_parameter(lp_ctx, "server max protocol", "SMB3");
2483         lpcfg_do_global_parameter(lp_ctx, "client min protocol", "CORE");
2484         lpcfg_do_global_parameter(lp_ctx, "client max protocol", "default");
2485         lpcfg_do_global_parameter(lp_ctx, "security", "AUTO");
2486         lpcfg_do_global_parameter(lp_ctx, "EncryptPasswords", "True");
2487         lpcfg_do_global_parameter(lp_ctx, "ReadRaw", "True");
2488         lpcfg_do_global_parameter(lp_ctx, "WriteRaw", "True");
2489         lpcfg_do_global_parameter(lp_ctx, "NullPasswords", "False");
2490         lpcfg_do_global_parameter(lp_ctx, "old password allowed period", "60");
2491         lpcfg_do_global_parameter(lp_ctx, "ObeyPamRestrictions", "False");
2492
2493         lpcfg_do_global_parameter(lp_ctx, "TimeServer", "False");
2494         lpcfg_do_global_parameter(lp_ctx, "BindInterfacesOnly", "False");
2495         lpcfg_do_global_parameter(lp_ctx, "Unicode", "True");
2496         lpcfg_do_global_parameter(lp_ctx, "ClientLanManAuth", "False");
2497         lpcfg_do_global_parameter(lp_ctx, "ClientNTLMv2Auth", "True");
2498         lpcfg_do_global_parameter(lp_ctx, "LanmanAuth", "False");
2499         lpcfg_do_global_parameter(lp_ctx, "NTLMAuth", "True");
2500         lpcfg_do_global_parameter(lp_ctx, "client use spnego principal", "False");
2501
2502         lpcfg_do_global_parameter(lp_ctx, "UnixExtensions", "True");
2503
2504         lpcfg_do_global_parameter(lp_ctx, "PreferredMaster", "Auto");
2505         lpcfg_do_global_parameter(lp_ctx, "LocalMaster", "True");
2506
2507         lpcfg_do_global_parameter(lp_ctx, "wins support", "False");
2508         lpcfg_do_global_parameter(lp_ctx, "dns proxy", "True");
2509
2510         lpcfg_do_global_parameter(lp_ctx, "winbind separator", "\\");
2511         lpcfg_do_global_parameter(lp_ctx, "winbind sealed pipes", "True");
2512         lpcfg_do_global_parameter(lp_ctx, "require strong key", "True");
2513         lpcfg_do_global_parameter(lp_ctx, "winbindd socket directory", dyn_WINBINDD_SOCKET_DIR);
2514         lpcfg_do_global_parameter(lp_ctx, "winbindd privileged socket directory", dyn_WINBINDD_PRIVILEGED_SOCKET_DIR);
2515         lpcfg_do_global_parameter(lp_ctx, "ntp signd socket directory", dyn_NTP_SIGND_SOCKET_DIR);
2516         lpcfg_do_global_parameter_var(lp_ctx, "dns update command", "%s/samba_dnsupdate", dyn_SCRIPTSBINDIR);
2517         lpcfg_do_global_parameter_var(lp_ctx, "spn update command", "%s/samba_spnupdate", dyn_SCRIPTSBINDIR);
2518         lpcfg_do_global_parameter_var(lp_ctx, "samba kcc command",
2519                                         "%s/samba_kcc", dyn_SCRIPTSBINDIR);
2520         lpcfg_do_global_parameter(lp_ctx, "template shell", "/bin/false");
2521         lpcfg_do_global_parameter(lp_ctx, "template homedir", "/home/%D/%U");
2522
2523         lpcfg_do_global_parameter(lp_ctx, "client signing", "default");
2524         lpcfg_do_global_parameter(lp_ctx, "server signing", "default");
2525
2526         lpcfg_do_global_parameter(lp_ctx, "use spnego", "True");
2527
2528         lpcfg_do_global_parameter(lp_ctx, "use mmap", "True");
2529
2530         lpcfg_do_global_parameter(lp_ctx, "smb ports", "445 139");
2531         lpcfg_do_global_parameter(lp_ctx, "nbt port", "137");
2532         lpcfg_do_global_parameter(lp_ctx, "dgram port", "138");
2533         lpcfg_do_global_parameter(lp_ctx, "cldap port", "389");
2534         lpcfg_do_global_parameter(lp_ctx, "krb5 port", "88");
2535         lpcfg_do_global_parameter(lp_ctx, "kpasswd port", "464");
2536         lpcfg_do_global_parameter(lp_ctx, "web port", "901");
2537
2538         lpcfg_do_global_parameter(lp_ctx, "nt status support", "True");
2539
2540         lpcfg_do_global_parameter(lp_ctx, "max wins ttl", "518400"); /* 6 days */
2541         lpcfg_do_global_parameter(lp_ctx, "min wins ttl", "21600");
2542
2543         lpcfg_do_global_parameter(lp_ctx, "tls enabled", "True");
2544         lpcfg_do_global_parameter(lp_ctx, "tls keyfile", "tls/key.pem");
2545         lpcfg_do_global_parameter(lp_ctx, "tls certfile", "tls/cert.pem");
2546         lpcfg_do_global_parameter(lp_ctx, "tls cafile", "tls/ca.pem");
2547         lpcfg_do_global_parameter(lp_ctx, "prefork children:smb", "4");
2548
2549         lpcfg_do_global_parameter(lp_ctx, "rndc command", "/usr/sbin/rndc");
2550         lpcfg_do_global_parameter(lp_ctx, "nsupdate command", "/usr/bin/nsupdate -g");
2551
2552         lpcfg_do_global_parameter(lp_ctx, "allow dns updates", "secure only");
2553         lpcfg_do_global_parameter(lp_ctx, "dns forwarder", "");
2554
2555         lpcfg_do_global_parameter(lp_ctx, "algorithmic rid base", "1000");
2556
2557         lpcfg_do_global_parameter(lp_ctx, "enhanced browsing", "True");
2558
2559         lpcfg_do_global_parameter(lp_ctx, "winbind nss info", "template");
2560
2561         lpcfg_do_global_parameter(lp_ctx, "server schannel", "Auto");
2562
2563         lpcfg_do_global_parameter(lp_ctx, "short preserve case", "True");
2564
2565         lpcfg_do_global_parameter(lp_ctx, "max open files", "16384");
2566
2567         lpcfg_do_global_parameter(lp_ctx, "cups connection timeout", "30");
2568
2569         lpcfg_do_global_parameter(lp_ctx, "locking", "True");
2570
2571         lpcfg_do_global_parameter(lp_ctx, "block size", "1024");
2572
2573         lpcfg_do_global_parameter(lp_ctx, "client use spnego", "True");
2574
2575         lpcfg_do_global_parameter(lp_ctx, "change notify", "True");
2576
2577         lpcfg_do_global_parameter(lp_ctx, "name cache timeout", "660");
2578
2579         lpcfg_do_global_parameter(lp_ctx, "defer sharing violations", "True");
2580
2581         lpcfg_do_global_parameter(lp_ctx, "ldap replication sleep", "1000");
2582
2583         lpcfg_do_global_parameter(lp_ctx, "idmap backend", "tdb");
2584
2585         lpcfg_do_global_parameter(lp_ctx, "enable privileges", "True");
2586
2587         lpcfg_do_global_parameter_var(lp_ctx, "smb2 max write", "%u", DEFAULT_SMB2_MAX_WRITE);
2588
2589         lpcfg_do_global_parameter(lp_ctx, "passdb backend", "tdbsam");
2590
2591         lpcfg_do_global_parameter(lp_ctx, "getwd cache", "True");
2592
2593         lpcfg_do_global_parameter(lp_ctx, "winbind nested groups", "True");
2594
2595         lpcfg_do_global_parameter(lp_ctx, "mangled names", "True");
2596
2597         lpcfg_do_global_parameter_var(lp_ctx, "smb2 max credits", "%u", DEFAULT_SMB2_MAX_CREDITS);
2598
2599         lpcfg_do_global_parameter(lp_ctx, "ldap ssl", "start tls");
2600
2601         lpcfg_do_global_parameter(lp_ctx, "ldap deref", "auto");
2602
2603         lpcfg_do_global_parameter(lp_ctx, "lm interval", "60");
2604
2605         lpcfg_do_global_parameter(lp_ctx, "mangling method", "hash2");
2606
2607         lpcfg_do_global_parameter(lp_ctx, "hide dot files", "True");
2608
2609         lpcfg_do_global_parameter(lp_ctx, "browse list", "True");
2610
2611         lpcfg_do_global_parameter(lp_ctx, "passwd chat timeout", "2");
2612
2613         lpcfg_do_global_parameter(lp_ctx, "guest account", GUEST_ACCOUNT);
2614
2615         lpcfg_do_global_parameter(lp_ctx, "client schannel", "auto");
2616
2617         lpcfg_do_global_parameter(lp_ctx, "smb encrypt", "default");
2618
2619         lpcfg_do_global_parameter(lp_ctx, "max log size", "5000");
2620
2621         lpcfg_do_global_parameter(lp_ctx, "idmap negative cache time", "120");
2622
2623         lpcfg_do_global_parameter(lp_ctx, "ldap follow referral", "auto");
2624
2625         lpcfg_do_global_parameter(lp_ctx, "multicast dns register", "yes");
2626
2627         lpcfg_do_global_parameter(lp_ctx, "winbind reconnect delay", "30");
2628
2629         lpcfg_do_global_parameter(lp_ctx, "winbind request timeout", "60");
2630
2631         lpcfg_do_global_parameter(lp_ctx, "nt acl support", "yes");
2632
2633         lpcfg_do_global_parameter(lp_ctx, "acl check permissions", "yes");
2634
2635         lpcfg_do_global_parameter(lp_ctx, "keepalive", "300");
2636
2637         lpcfg_do_global_parameter(lp_ctx, "smbd profiling level", "off");
2638
2639         lpcfg_do_global_parameter(lp_ctx, "winbind cache time", "300");
2640
2641         lpcfg_do_global_parameter(lp_ctx, "level2 oplocks", "yes");
2642
2643         lpcfg_do_global_parameter(lp_ctx, "show add printer wizard", "yes");
2644
2645         lpcfg_do_global_parameter(lp_ctx, "allocation roundup size", "1048576");
2646
2647         lpcfg_do_global_parameter(lp_ctx, "ldap page size", "1024");
2648
2649         lpcfg_do_global_parameter(lp_ctx, "kernel share modes", "yes");
2650
2651         lpcfg_do_global_parameter(lp_ctx, "strict locking", "Auto");
2652
2653         lpcfg_do_global_parameter(lp_ctx, "map readonly", "yes");
2654
2655         lpcfg_do_global_parameter(lp_ctx, "allow trusted domains", "yes");
2656
2657         lpcfg_do_global_parameter(lp_ctx, "default devmode", "yes");
2658
2659         lpcfg_do_global_parameter(lp_ctx, "os level", "20");
2660
2661         lpcfg_do_global_parameter(lp_ctx, "dos filetimes", "yes");
2662
2663         lpcfg_do_global_parameter(lp_ctx, "mangling char", "~");
2664
2665         lpcfg_do_global_parameter(lp_ctx, "printcap cache time", "750");
2666
2667         lpcfg_do_global_parameter(lp_ctx, "create krb5 conf", "yes");
2668
2669         lpcfg_do_global_parameter(lp_ctx, "winbind max clients", "200");
2670
2671         lpcfg_do_global_parameter(lp_ctx, "acl map full control", "yes");
2672
2673         lpcfg_do_global_parameter(lp_ctx, "nt pipe support", "yes");
2674
2675         lpcfg_do_global_parameter(lp_ctx, "ldap debug threshold", "10");
2676
2677         lpcfg_do_global_parameter(lp_ctx, "client ldap sasl wrapping", "sign");
2678
2679         lpcfg_do_global_parameter(lp_ctx, "follow symlinks", "yes");
2680
2681         lpcfg_do_global_parameter(lp_ctx, "machine password timeout", "604800");
2682
2683         lpcfg_do_global_parameter(lp_ctx, "ldap connection timeout", "2");
2684
2685         lpcfg_do_global_parameter(lp_ctx, "winbind expand groups", "0");
2686
2687         lpcfg_do_global_parameter(lp_ctx, "stat cache", "yes");
2688
2689         lpcfg_do_global_parameter(lp_ctx, "lpq cache time", "30");
2690
2691         lpcfg_do_global_parameter_var(lp_ctx, "smb2 max trans", "%u", DEFAULT_SMB2_MAX_TRANSACT);
2692
2693         lpcfg_do_global_parameter_var(lp_ctx, "smb2 max read", "%u", DEFAULT_SMB2_MAX_READ);
2694
2695         lpcfg_do_global_parameter(lp_ctx, "durable handles", "yes");
2696
2697         lpcfg_do_global_parameter(lp_ctx, "max stat cache size", "256");
2698
2699         lpcfg_do_global_parameter(lp_ctx, "ldap passwd sync", "no");
2700
2701         lpcfg_do_global_parameter(lp_ctx, "kernel change notify", "yes");
2702
2703         lpcfg_do_global_parameter(lp_ctx, "max ttl", "259200");
2704
2705         lpcfg_do_global_parameter(lp_ctx, "blocking locks", "yes");
2706
2707         lpcfg_do_global_parameter(lp_ctx, "oplock contention limit", "2");
2708
2709         lpcfg_do_global_parameter(lp_ctx, "load printers", "yes");
2710
2711         lpcfg_do_global_parameter(lp_ctx, "idmap cache time", "604800");
2712
2713         lpcfg_do_global_parameter(lp_ctx, "preserve case", "yes");
2714
2715         lpcfg_do_global_parameter(lp_ctx, "lm announce", "auto");
2716
2717         lpcfg_do_global_parameter(lp_ctx, "afs token lifetime", "604800");
2718
2719         lpcfg_do_global_parameter(lp_ctx, "enable core files", "yes");
2720
2721         lpcfg_do_global_parameter(lp_ctx, "winbind max domain connections", "1");
2722
2723         lpcfg_do_global_parameter(lp_ctx, "case sensitive", "auto");
2724
2725         lpcfg_do_global_parameter(lp_ctx, "ldap timeout", "15");
2726
2727         lpcfg_do_global_parameter(lp_ctx, "mangle prefix", "1");
2728
2729         lpcfg_do_global_parameter(lp_ctx, "posix locking", "yes");
2730
2731         lpcfg_do_global_parameter(lp_ctx, "lock spin time", "200");
2732
2733         lpcfg_do_global_parameter(lp_ctx, "directory name cache size", "100");
2734
2735         lpcfg_do_global_parameter(lp_ctx, "nmbd bind explicit broadcast", "yes");
2736
2737         lpcfg_do_global_parameter(lp_ctx, "init logon delay", "100");
2738
2739         lpcfg_do_global_parameter(lp_ctx, "usershare owner only", "yes");
2740
2741         lpcfg_do_global_parameter(lp_ctx, "-valid", "yes");
2742
2743         lpcfg_do_global_parameter_var(lp_ctx, "usershare path", "%s/usershares", get_dyn_STATEDIR());
2744
2745 #ifdef DEVELOPER
2746         lpcfg_do_global_parameter_var(lp_ctx, "panic action", "/bin/sleep 999999999");
2747 #endif
2748
2749         lpcfg_do_global_parameter(lp_ctx, "smb passwd file", get_dyn_SMB_PASSWD_FILE());
2750
2751         lpcfg_do_global_parameter(lp_ctx, "logon home", "\\\\%N\\%U");
2752
2753         lpcfg_do_global_parameter(lp_ctx, "logon path", "\\\\%N\\%U\\profile");
2754
2755         lpcfg_do_global_parameter(lp_ctx, "printjob username", "%U");
2756
2757         for (i = 0; parm_table[i].label; i++) {
2758                 if (!(lp_ctx->flags[i] & FLAG_CMDLINE)) {
2759                         lp_ctx->flags[i] |= FLAG_DEFAULT;
2760                 }
2761         }
2762
2763         for (parm=lp_ctx->globals->param_opt; parm; parm=parm->next) {
2764                 if (!(parm->priority & FLAG_CMDLINE)) {
2765                         parm->priority |= FLAG_DEFAULT;
2766                 }
2767         }
2768
2769         for (parm=lp_ctx->sDefault->param_opt; parm; parm=parm->next) {
2770                 if (!(parm->priority & FLAG_CMDLINE)) {
2771                         parm->priority |= FLAG_DEFAULT;
2772                 }
2773         }
2774
2775
2776         return lp_ctx;
2777 }
2778
2779 /**
2780  * Initialise the global parameter structure.
2781  */
2782 struct loadparm_context *loadparm_init_global(bool load_default)
2783 {
2784         if (global_loadparm_context == NULL) {
2785                 global_loadparm_context = loadparm_init(NULL);
2786         }
2787         if (global_loadparm_context == NULL) {
2788                 return NULL;
2789         }
2790         global_loadparm_context->global = true;
2791         if (load_default && !global_loadparm_context->loaded) {
2792                 lpcfg_load_default(global_loadparm_context);
2793         }
2794         global_loadparm_context->refuse_free = true;
2795         return global_loadparm_context;
2796 }
2797
2798 /**
2799  * Initialise the global parameter structure.
2800  */
2801 struct loadparm_context *loadparm_init_s3(TALLOC_CTX *mem_ctx, 
2802                                           const struct loadparm_s3_helpers *s3_fns)
2803 {
2804         struct loadparm_context *loadparm_context = talloc_zero(mem_ctx, struct loadparm_context);
2805         if (!loadparm_context) {
2806                 return NULL;
2807         }
2808         loadparm_context->s3_fns = s3_fns;
2809         loadparm_context->globals = s3_fns->globals;
2810         loadparm_context->flags = s3_fns->flags;
2811
2812         return loadparm_context;
2813 }
2814
2815 const char *lpcfg_configfile(struct loadparm_context *lp_ctx)
2816 {
2817         return lp_ctx->szConfigFile;
2818 }
2819
2820 const char *lp_default_path(void)
2821 {
2822     if (getenv("SMB_CONF_PATH"))
2823         return getenv("SMB_CONF_PATH");
2824     else
2825         return dyn_CONFIGFILE;
2826 }
2827
2828 /**
2829  * Update the internal state of a loadparm context after settings 
2830  * have changed.
2831  */
2832 static bool lpcfg_update(struct loadparm_context *lp_ctx)
2833 {
2834         struct debug_settings settings;
2835         TALLOC_CTX *tmp_ctx;
2836
2837         tmp_ctx = talloc_new(lp_ctx);
2838         if (tmp_ctx == NULL) {
2839                 return false;
2840         }
2841
2842         lpcfg_add_auto_services(lp_ctx, lpcfg_auto_services(lp_ctx, tmp_ctx));
2843
2844         if (!lp_ctx->globals->wins_server_list && lp_ctx->globals->we_are_a_wins_server) {
2845                 lpcfg_do_global_parameter(lp_ctx, "wins server", "127.0.0.1");
2846         }
2847
2848         if (!lp_ctx->global) {
2849                 TALLOC_FREE(tmp_ctx);
2850                 return true;
2851         }
2852
2853         panic_action = lp_ctx->globals->panic_action;
2854
2855         reload_charcnv(lp_ctx);
2856
2857         ZERO_STRUCT(settings);
2858         /* Add any more debug-related smb.conf parameters created in
2859          * future here */
2860         settings.syslog = lp_ctx->globals->syslog;
2861         settings.syslog_only = lp_ctx->globals->syslog_only;
2862         settings.timestamp_logs = lp_ctx->globals->timestamp_logs;
2863         settings.debug_prefix_timestamp = lp_ctx->globals->debug_prefix_timestamp;
2864         settings.debug_hires_timestamp = lp_ctx->globals->debug_hires_timestamp;
2865         settings.debug_pid = lp_ctx->globals->debug_pid;
2866         settings.debug_uid = lp_ctx->globals->debug_uid;
2867         settings.debug_class = lp_ctx->globals->debug_class;
2868         debug_set_settings(&settings);
2869
2870         /* FIXME: This is a bit of a hack, but we can't use a global, since 
2871          * not everything that uses lp also uses the socket library */
2872         if (lpcfg_parm_bool(lp_ctx, NULL, "socket", "testnonblock", false)) {
2873                 setenv("SOCKET_TESTNONBLOCK", "1", 1);
2874         } else {
2875                 unsetenv("SOCKET_TESTNONBLOCK");
2876         }
2877
2878         TALLOC_FREE(tmp_ctx);
2879         return true;
2880 }
2881
2882 bool lpcfg_load_default(struct loadparm_context *lp_ctx)
2883 {
2884     const char *path;
2885
2886     path = lp_default_path();
2887
2888     if (!file_exist(path)) {
2889             /* We allow the default smb.conf file to not exist, 
2890              * basically the equivalent of an empty file. */
2891             return lpcfg_update(lp_ctx);
2892     }
2893
2894     return lpcfg_load(lp_ctx, path);
2895 }
2896
2897 /**
2898  * Load the services array from the services file.
2899  *
2900  * Return True on success, False on failure.
2901  */
2902 bool lpcfg_load(struct loadparm_context *lp_ctx, const char *filename)
2903 {
2904         char *n2;
2905         bool bRetval;
2906
2907         filename = talloc_strdup(lp_ctx, filename);
2908
2909         lp_ctx->szConfigFile = filename;
2910
2911         if (lp_ctx->s3_fns) {
2912                 return lp_ctx->s3_fns->load(filename);
2913         }
2914
2915         lp_ctx->bInGlobalSection = true;
2916         n2 = standard_sub_basic(lp_ctx, lp_ctx->szConfigFile);
2917         DEBUG(2, ("lpcfg_load: refreshing parameters from %s\n", n2));
2918
2919         add_to_file_list(lp_ctx, &lp_ctx->file_lists, lp_ctx->szConfigFile, n2);
2920
2921         /* We get sections first, so have to start 'behind' to make up */
2922         lp_ctx->currentService = NULL;
2923         bRetval = pm_process(n2, do_section, lpcfg_do_parameter, lp_ctx);
2924
2925         /* finish up the last section */
2926         DEBUG(4, ("pm_process() returned %s\n", BOOLSTR(bRetval)));
2927         if (bRetval)
2928                 if (lp_ctx->currentService != NULL)
2929                         bRetval = lpcfg_service_ok(lp_ctx->currentService);
2930
2931         bRetval = bRetval && lpcfg_update(lp_ctx);
2932
2933         /* we do this unconditionally, so that it happens even
2934            for a missing smb.conf */
2935         reload_charcnv(lp_ctx);
2936
2937         if (bRetval == true) {
2938                 /* set this up so that any child python tasks will
2939                    find the right smb.conf */
2940                 setenv("SMB_CONF_PATH", filename, 1);
2941
2942                 /* set the context used by the lp_*() function
2943                    varients */
2944                 global_loadparm_context = lp_ctx;
2945                 lp_ctx->loaded = true;
2946         }
2947
2948         return bRetval;
2949 }
2950
2951 /**
2952  * Return the max number of services.
2953  */
2954
2955 int lpcfg_numservices(struct loadparm_context *lp_ctx)
2956 {
2957         if (lp_ctx->s3_fns) {
2958                 return lp_ctx->s3_fns->get_numservices();
2959         }
2960
2961         return lp_ctx->iNumServices;
2962 }
2963
2964 /**
2965  * Display the contents of the services array in human-readable form.
2966  */
2967
2968 void lpcfg_dump(struct loadparm_context *lp_ctx, FILE *f, bool show_defaults,
2969              int maxtoprint)
2970 {
2971         int iService;
2972
2973         if (lp_ctx->s3_fns) {
2974                 lp_ctx->s3_fns->dump(f, show_defaults, maxtoprint);
2975                 return;
2976         }
2977
2978         lpcfg_dump_globals(lp_ctx, f, show_defaults);
2979
2980         lpcfg_dump_a_service(lp_ctx->sDefault, lp_ctx->sDefault, f, lp_ctx->flags, show_defaults);
2981
2982         for (iService = 0; iService < maxtoprint; iService++)
2983                 lpcfg_dump_one(f, show_defaults, lp_ctx->services[iService], lp_ctx->sDefault);
2984 }
2985
2986 /**
2987  * Display the contents of one service in human-readable form.
2988  */
2989 void lpcfg_dump_one(FILE *f, bool show_defaults, struct loadparm_service *service, struct loadparm_service *sDefault)
2990 {
2991         if (service != NULL) {
2992                 if (service->szService[0] == '\0')
2993                         return;
2994                 lpcfg_dump_a_service(service, sDefault, f, NULL, show_defaults);
2995         }
2996 }
2997
2998 struct loadparm_service *lpcfg_servicebynum(struct loadparm_context *lp_ctx,
2999                                             int snum)
3000 {
3001         if (lp_ctx->s3_fns) {
3002                 return lp_ctx->s3_fns->get_servicebynum(snum);
3003         }
3004
3005         return lp_ctx->services[snum];
3006 }
3007
3008 struct loadparm_service *lpcfg_service(struct loadparm_context *lp_ctx,
3009                                     const char *service_name)
3010 {
3011         int iService;
3012         char *serviceName;
3013
3014         if (lp_ctx->s3_fns) {
3015                 return lp_ctx->s3_fns->get_service(service_name);
3016         }
3017
3018         for (iService = lp_ctx->iNumServices - 1; iService >= 0; iService--) {
3019                 if (lp_ctx->services[iService] &&
3020                     lp_ctx->services[iService]->szService) {
3021                         /*
3022                          * The substitution here is used to support %U is
3023                          * service names
3024                          */
3025                         serviceName = standard_sub_basic(
3026                                         lp_ctx->services[iService],
3027                                         lp_ctx->services[iService]->szService);
3028                         if (strequal(serviceName, service_name)) {
3029                                 talloc_free(serviceName);
3030                                 return lp_ctx->services[iService];
3031                         }
3032                         talloc_free(serviceName);
3033                 }
3034         }
3035
3036         DEBUG(7,("lpcfg_servicenumber: couldn't find %s\n", service_name));
3037         return NULL;
3038 }
3039
3040 const char *lpcfg_servicename(const struct loadparm_service *service)
3041 {
3042         return lpcfg_string((const char *)service->szService);
3043 }
3044
3045 /**
3046  * A useful volume label function.
3047  */
3048 const char *lpcfg_volume_label(struct loadparm_service *service, struct loadparm_service *sDefault)
3049 {
3050         const char *ret;
3051         ret = lpcfg_string((const char *)((service != NULL && service->volume != NULL) ?
3052                                        service->volume : sDefault->volume));
3053         if (!*ret)
3054                 return lpcfg_servicename(service);
3055         return ret;
3056 }
3057
3058 /**
3059  * Return the correct printer name.
3060  */
3061 const char *lpcfg_printername(struct loadparm_service *service, struct loadparm_service *sDefault)
3062 {
3063         const char *ret;
3064         ret = lpcfg_string((const char *)((service != NULL && service->_printername != NULL) ?
3065                                        service->_printername : sDefault->_printername));
3066         if (ret == NULL || (ret != NULL && *ret == '\0'))
3067                 ret = lpcfg_servicename(service);
3068
3069         return ret;
3070 }
3071
3072
3073 /**
3074  * Return the max print jobs per queue.
3075  */
3076 int lpcfg_maxprintjobs(struct loadparm_service *service, struct loadparm_service *sDefault)
3077 {
3078         int maxjobs = (service != NULL) ? service->iMaxPrintJobs : sDefault->iMaxPrintJobs;
3079         if (maxjobs <= 0 || maxjobs >= PRINT_MAX_JOBID)
3080                 maxjobs = PRINT_MAX_JOBID - 1;
3081
3082         return maxjobs;
3083 }
3084
3085 struct smb_iconv_handle *lpcfg_iconv_handle(struct loadparm_context *lp_ctx)
3086 {
3087         if (lp_ctx == NULL) {
3088                 return get_iconv_handle();
3089         }
3090         return lp_ctx->iconv_handle;
3091 }
3092
3093 _PUBLIC_ void reload_charcnv(struct loadparm_context *lp_ctx)
3094 {
3095         struct smb_iconv_handle *old_ic = lp_ctx->iconv_handle;
3096         if (!lp_ctx->global) {
3097                 return;
3098         }
3099
3100         if (old_ic == NULL) {
3101                 old_ic = global_iconv_handle;
3102         }
3103         lp_ctx->iconv_handle = smb_iconv_handle_reinit_lp(lp_ctx, lp_ctx, old_ic);
3104         global_iconv_handle = lp_ctx->iconv_handle;
3105 }
3106
3107 _PUBLIC_ char *lpcfg_tls_keyfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
3108 {
3109         return lpcfg_private_path(mem_ctx, lp_ctx, lpcfg__tls_keyfile(lp_ctx));
3110 }
3111
3112 _PUBLIC_ char *lpcfg_tls_certfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
3113 {
3114         return lpcfg_private_path(mem_ctx, lp_ctx, lpcfg__tls_certfile(lp_ctx));
3115 }
3116
3117 _PUBLIC_ char *lpcfg_tls_cafile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
3118 {
3119         return lpcfg_private_path(mem_ctx, lp_ctx, lpcfg__tls_cafile(lp_ctx));
3120 }
3121
3122 _PUBLIC_ char *lpcfg_tls_crlfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
3123 {
3124         return lpcfg_private_path(mem_ctx, lp_ctx, lpcfg__tls_crlfile(lp_ctx));
3125 }
3126
3127 _PUBLIC_ char *lpcfg_tls_dhpfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
3128 {
3129         return lpcfg_private_path(mem_ctx, lp_ctx, lpcfg__tls_dhpfile(lp_ctx));
3130 }
3131
3132 struct gensec_settings *lpcfg_gensec_settings(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
3133 {
3134         struct gensec_settings *settings = talloc_zero(mem_ctx, struct gensec_settings);
3135         if (settings == NULL)
3136                 return NULL;
3137         SMB_ASSERT(lp_ctx != NULL);
3138         settings->lp_ctx = talloc_reference(settings, lp_ctx);
3139         settings->target_hostname = lpcfg_parm_string(lp_ctx, NULL, "gensec", "target_hostname");
3140         return settings;
3141 }
3142
3143 int lpcfg_server_role(struct loadparm_context *lp_ctx)
3144 {
3145         int domain_master = lpcfg__domain_master(lp_ctx);
3146
3147         return lp_find_server_role(lpcfg__server_role(lp_ctx),
3148                                    lpcfg__security(lp_ctx),
3149                                    lpcfg__domain_logons(lp_ctx),
3150                                    (domain_master == true) ||
3151                                    (domain_master == Auto));
3152 }
3153
3154 int lpcfg_security(struct loadparm_context *lp_ctx)
3155 {
3156         return lp_find_security(lpcfg__server_role(lp_ctx),
3157                                 lpcfg__security(lp_ctx));
3158 }
3159
3160 int lpcfg_client_max_protocol(struct loadparm_context *lp_ctx)
3161 {
3162         int client_max_protocol = lpcfg__client_max_protocol(lp_ctx);
3163         if (client_max_protocol == PROTOCOL_DEFAULT) {
3164                 return PROTOCOL_NT1;
3165         }
3166         return client_max_protocol;
3167 }
3168
3169 bool lpcfg_server_signing_allowed(struct loadparm_context *lp_ctx, bool *mandatory)
3170 {
3171         bool allowed = true;
3172         enum smb_signing_setting signing_setting = lpcfg_server_signing(lp_ctx);
3173
3174         *mandatory = false;
3175
3176         if (signing_setting == SMB_SIGNING_DEFAULT) {
3177                 /*
3178                  * If we are a domain controller, SMB signing is
3179                  * really important, as it can prevent a number of
3180                  * attacks on communications between us and the
3181                  * clients
3182                  *
3183                  * However, it really sucks (no sendfile, CPU
3184                  * overhead) performance-wise when used on a
3185                  * file server, so disable it by default
3186                  * on non-DCs
3187                  */
3188
3189                 if (lpcfg_server_role(lp_ctx) >= ROLE_ACTIVE_DIRECTORY_DC) {
3190                         signing_setting = SMB_SIGNING_REQUIRED;
3191                 } else {
3192                         signing_setting = SMB_SIGNING_OFF;
3193                 }
3194         }
3195
3196         switch (signing_setting) {
3197         case SMB_SIGNING_REQUIRED:
3198                 *mandatory = true;
3199                 break;
3200         case SMB_SIGNING_IF_REQUIRED:
3201                 break;
3202         case SMB_SIGNING_DEFAULT:
3203         case SMB_SIGNING_OFF:
3204                 allowed = false;
3205                 break;
3206         }
3207
3208         return allowed;
3209 }
3210
3211 int lpcfg_tdb_hash_size(struct loadparm_context *lp_ctx, const char *name)
3212 {
3213         const char *base;
3214
3215         if (name == NULL) {
3216                 return 0;
3217         }
3218
3219         base = strrchr_m(name, '/');
3220         if (base != NULL) {
3221                 base += 1;
3222         } else {
3223                 base = name;
3224         }
3225         return lpcfg_parm_int(lp_ctx, NULL, "tdb_hashsize", base, 0);
3226
3227 }
3228
3229 int lpcfg_tdb_flags(struct loadparm_context *lp_ctx, int tdb_flags)
3230 {
3231         if (!lpcfg_use_mmap(lp_ctx)) {
3232                 tdb_flags |= TDB_NOMMAP;
3233         }
3234         return tdb_flags;
3235 }