LCOV - code coverage report
Current view: top level - lib/param - loadparm.c (source / functions) Hit Total Coverage
Test: coverage report for v4-17-test 1498b464 Lines: 1320 1629 81.0 %
Date: 2024-06-13 04:01:37 Functions: 106 117 90.6 %

          Line data    Source code
       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             : #define LOADPARM_SUBSTITUTION_INTERNALS 1
      65             : #include "lib/param/loadparm.h"
      66             : #include "auth/gensec/gensec.h"
      67             : #include "lib/param/s3_param.h"
      68             : #include "lib/util/bitmap.h"
      69             : #include "libcli/smb/smb_constants.h"
      70             : #include "tdb.h"
      71             : #include "librpc/gen_ndr/nbt.h"
      72             : #include "librpc/gen_ndr/dns.h"
      73             : #include "librpc/gen_ndr/security.h"
      74             : #include "libds/common/roles.h"
      75             : #include "lib/util/samba_util.h"
      76             : #include "libcli/auth/ntlm_check.h"
      77             : #include "lib/crypto/gnutls_helpers.h"
      78             : #include "lib/util/smb_strtox.h"
      79             : #include "auth/credentials/credentials.h"
      80             : 
      81             : #ifdef HAVE_HTTPCONNECTENCRYPT
      82             : #include <cups/http.h>
      83             : #endif
      84             : 
      85             : #define standard_sub_basic talloc_strdup
      86             : 
      87             : #include "lib/param/param_global.h"
      88             : 
      89      225413 : struct loadparm_service *lpcfg_default_service(struct loadparm_context *lp_ctx)
      90             : {
      91      225413 :         return lp_ctx->sDefault;
      92             : }
      93             : 
      94          56 : int lpcfg_rpc_low_port(struct loadparm_context *lp_ctx)
      95             : {
      96          56 :         return lp_ctx->globals->rpc_low_port;
      97             : }
      98             : 
      99          56 : int lpcfg_rpc_high_port(struct loadparm_context *lp_ctx)
     100             : {
     101          56 :         return lp_ctx->globals->rpc_high_port;
     102             : }
     103             : 
     104      397804 : enum samba_weak_crypto lpcfg_weak_crypto(struct loadparm_context *lp_ctx)
     105             : {
     106      397804 :         if (lp_ctx->globals->weak_crypto == SAMBA_WEAK_CRYPTO_UNKNOWN) {
     107        9012 :                 lp_ctx->globals->weak_crypto = SAMBA_WEAK_CRYPTO_DISALLOWED;
     108             : 
     109        9012 :                 if (samba_gnutls_weak_crypto_allowed()) {
     110        9012 :                         lp_ctx->globals->weak_crypto = SAMBA_WEAK_CRYPTO_ALLOWED;
     111             :                 }
     112             :         }
     113             : 
     114      397804 :         return lp_ctx->globals->weak_crypto;
     115             : }
     116             : 
     117             : /**
     118             :  * Convenience routine to grab string parameters into temporary memory
     119             :  * and run standard_sub_basic on them.
     120             :  *
     121             :  * The buffers can be written to by
     122             :  * callers without affecting the source string.
     123             :  */
     124             : 
     125     6863977 : static const char *lpcfg_string(const char *s)
     126             : {
     127             : #if 0  /* until REWRITE done to make thread-safe */
     128             :         size_t len = s ? strlen(s) : 0;
     129             :         char *ret;
     130             : #endif
     131             : 
     132             :         /* The follow debug is useful for tracking down memory problems
     133             :            especially if you have an inner loop that is calling a lp_*()
     134             :            function that returns a string.  Perhaps this debug should be
     135             :            present all the time? */
     136             : 
     137             : #if 0
     138             :         DEBUG(10, ("lpcfg_string(%s)\n", s));
     139             : #endif
     140             : 
     141             : #if 0  /* until REWRITE done to make thread-safe */
     142             :         if (!lp_talloc)
     143             :                 lp_talloc = talloc_init("lp_talloc");
     144             : 
     145             :         ret = talloc_array(lp_talloc, char, len + 100); /* leave room for substitution */
     146             : 
     147             :         if (!ret)
     148             :                 return NULL;
     149             : 
     150             :         if (!s)
     151             :                 *ret = 0;
     152             :         else
     153             :                 strlcpy(ret, s, len);
     154             : 
     155             :         if (trim_string(ret, "\"", "\"")) {
     156             :                 if (strchr(ret,'"') != NULL)
     157             :                         strlcpy(ret, s, len);
     158             :         }
     159             : 
     160             :         standard_sub_basic(ret,len+100);
     161             :         return (ret);
     162             : #endif
     163     6863977 :         return s;
     164             : }
     165             : 
     166             : /*
     167             :    In this section all the functions that are used to access the
     168             :    parameters from the rest of the program are defined
     169             : */
     170             : 
     171             : /*
     172             :  * the creation of separate lpcfg_*() and lp_*() functions is to allow
     173             :  * for code compatibility between existing Samba4 and Samba3 code.
     174             :  */
     175             : 
     176             : /* this global context supports the lp_*() function varients */
     177             : static struct loadparm_context *global_loadparm_context;
     178             : 
     179             : #define FN_GLOBAL_SUBSTITUTED_STRING(fn_name,var_name) \
     180             :  _PUBLIC_ char *lpcfg_ ## fn_name(struct loadparm_context *lp_ctx, \
     181             :                  const struct loadparm_substitution *lp_sub, TALLOC_CTX *mem_ctx) \
     182             : { \
     183             :          if (lp_ctx == NULL) return NULL;                               \
     184             :          return lpcfg_substituted_string(mem_ctx, lp_sub, \
     185             :                          lp_ctx->globals->var_name ? lp_ctx->globals->var_name : ""); \
     186             : }
     187             : 
     188             : #define FN_GLOBAL_CONST_STRING(fn_name,var_name)                                \
     189             :  _PUBLIC_ const char *lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) { \
     190             :         if (lp_ctx == NULL) return NULL;                                \
     191             :         return lp_ctx->globals->var_name ? lpcfg_string(lp_ctx->globals->var_name) : ""; \
     192             : }
     193             : 
     194             : #define FN_GLOBAL_LIST(fn_name,var_name)                                \
     195             :  _PUBLIC_ const char **lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) { \
     196             :          if (lp_ctx == NULL) return NULL;                               \
     197             :          return lp_ctx->globals->var_name;                                \
     198             :  }
     199             : 
     200             : #define FN_GLOBAL_BOOL(fn_name,var_name) \
     201             :  _PUBLIC_ bool lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) {\
     202             :          if (lp_ctx == NULL) return false;                              \
     203             :          return lp_ctx->globals->var_name;                                \
     204             : }
     205             : 
     206             : #define FN_GLOBAL_INTEGER(fn_name,var_name) \
     207             :  _PUBLIC_ int lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) { \
     208             :          return lp_ctx->globals->var_name;                                \
     209             :  }
     210             : 
     211             : /* Local parameters don't need the ->s3_fns because the struct
     212             :  * loadparm_service is shared and lpcfg_service() checks the ->s3_fns
     213             :  * hook */
     214             : #define FN_LOCAL_SUBSTITUTED_STRING(fn_name,val) \
     215             :  _PUBLIC_ char *lpcfg_ ## fn_name(struct loadparm_service *service, \
     216             :                                         struct loadparm_service *sDefault, TALLOC_CTX *ctx) { \
     217             :          return(talloc_strdup(ctx, lpcfg_string((const char *)((service != NULL && service->val != NULL) ? service->val : sDefault->val)))); \
     218             :  }
     219             : 
     220             : #define FN_LOCAL_CONST_STRING(fn_name,val) \
     221             :  _PUBLIC_ const char *lpcfg_ ## fn_name(struct loadparm_service *service, \
     222             :                                         struct loadparm_service *sDefault) { \
     223             :          return((const char *)((service != NULL && service->val != NULL) ? service->val : sDefault->val)); \
     224             :  }
     225             : 
     226             : #define FN_LOCAL_LIST(fn_name,val) \
     227             :  _PUBLIC_ const char **lpcfg_ ## fn_name(struct loadparm_service *service, \
     228             :                                          struct loadparm_service *sDefault) {\
     229             :          return(const char **)(service != NULL && service->val != NULL? service->val : sDefault->val); \
     230             :  }
     231             : 
     232             : #define FN_LOCAL_PARM_BOOL(fn_name, val) FN_LOCAL_BOOL(fn_name, val)
     233             : 
     234             : #define FN_LOCAL_BOOL(fn_name,val) \
     235             :  _PUBLIC_ bool lpcfg_ ## fn_name(struct loadparm_service *service, \
     236             :                                  struct loadparm_service *sDefault) {   \
     237             :          return((service != NULL)? service->val : sDefault->val); \
     238             :  }
     239             : 
     240             : #define FN_LOCAL_INTEGER(fn_name,val) \
     241             :  _PUBLIC_ int lpcfg_ ## fn_name(struct loadparm_service *service, \
     242             :                                 struct loadparm_service *sDefault) {    \
     243             :          return((service != NULL)? service->val : sDefault->val); \
     244             :  }
     245             : 
     246             : #define FN_LOCAL_PARM_INTEGER(fn_name, val) FN_LOCAL_INTEGER(fn_name, val)
     247             : 
     248             : #define FN_LOCAL_CHAR(fn_name,val) \
     249             :  _PUBLIC_ char lpcfg_ ## fn_name(struct loadparm_service *service, \
     250             :                                 struct loadparm_service *sDefault) {    \
     251             :          return((service != NULL)? service->val : sDefault->val); \
     252             :  }
     253             : 
     254             : #define FN_LOCAL_PARM_CHAR(fn_name,val) FN_LOCAL_CHAR(fn_name, val)
     255             : 
     256             : #include "lib/param/param_functions.c"
     257             : 
     258             : /* These functions cannot be auto-generated */
     259           0 : FN_LOCAL_BOOL(autoloaded, autoloaded)
     260     3628081 : FN_GLOBAL_CONST_STRING(dnsdomain, dnsdomain)
     261             : 
     262             : /* local prototypes */
     263             : static struct loadparm_service *lpcfg_getservicebyname(struct loadparm_context *lp_ctx,
     264             :                                         const char *pszServiceName);
     265             : static bool do_section(const char *pszSectionName, void *);
     266             : static bool set_variable_helper(TALLOC_CTX *mem_ctx, int parmnum, void *parm_ptr,
     267             :                                 const char *pszParmName, const char *pszParmValue);
     268             : static bool lp_do_parameter_parametric(struct loadparm_context *lp_ctx,
     269             :                                        struct loadparm_service *service,
     270             :                                        const char *pszParmName,
     271             :                                        const char *pszParmValue, int flags);
     272             : 
     273             : /* The following are helper functions for parametrical options support. */
     274             : /* It returns a pointer to parametrical option value if it exists or NULL otherwise */
     275             : /* Actual parametrical functions are quite simple */
     276     4720997 : struct parmlist_entry *get_parametric_helper(struct loadparm_service *service,
     277             :                                              const char *type, const char *option,
     278             :                                              struct parmlist_entry *global_opts)
     279     4720997 : {
     280     4720997 :         size_t type_len = strlen(type);
     281     4720997 :         size_t option_len = strlen(option);
     282     4720997 :         char param_key[type_len + option_len + 2];
     283     4720997 :         struct parmlist_entry *data = NULL;
     284             : 
     285     4720997 :         snprintf(param_key, sizeof(param_key), "%s:%s", type, option);
     286             : 
     287             :         /*
     288             :          * Try to fetch the option from the data.
     289             :          */
     290     4720997 :         if (service != NULL) {
     291       96146 :                 data = service->param_opt;
     292      219172 :                 while (data != NULL) {
     293       55551 :                         if (strwicmp(data->key, param_key) == 0) {
     294        3975 :                                 return data;
     295             :                         }
     296       51576 :                         data = data->next;
     297             :                 }
     298             :         }
     299             : 
     300             :         /*
     301             :          * Fall back to fetching from the globals.
     302             :          */
     303     4717022 :         data = global_opts;
     304   154490182 :         while (data != NULL) {
     305   146392398 :                 if (strwicmp(data->key, param_key) == 0) {
     306      377384 :                         return data;
     307             :                 }
     308   146015014 :                 data = data->next;
     309             :         }
     310             : 
     311     4339638 :         return NULL;
     312             : }
     313             : 
     314     4545989 : const char *lpcfg_get_parametric(struct loadparm_context *lp_ctx,
     315             :                               struct loadparm_service *service,
     316             :                               const char *type, const char *option)
     317             : {
     318             :         struct parmlist_entry *data;
     319             : 
     320     4545989 :         if (lp_ctx == NULL)
     321           0 :                 return NULL;
     322             : 
     323     4545989 :         data = get_parametric_helper(service,
     324     4545989 :                                      type, option, lp_ctx->globals->param_opt);
     325             : 
     326     4545989 :         if (data == NULL) {
     327     4178356 :                 return NULL;
     328             :         } else {
     329      367633 :                 return data->value;
     330             :         }
     331             : }
     332             : 
     333             : 
     334             : /**
     335             :  * convenience routine to return int parameters.
     336             :  */
     337      519474 : int lp_int(const char *s)
     338             : {
     339             : 
     340      519474 :         if (!s || !*s) {
     341           0 :                 DEBUG(0,("lp_int(%s): is called with NULL!\n",s));
     342           0 :                 return -1;
     343             :         }
     344             : 
     345      519474 :         return strtol(s, NULL, 0);
     346             : }
     347             : 
     348             : /**
     349             :  * convenience routine to return unsigned long parameters.
     350             :  */
     351        4045 : unsigned long lp_ulong(const char *s)
     352             : {
     353        4045 :         int error = 0;
     354             :         unsigned long int ret;
     355             : 
     356        4045 :         if (!s || !*s) {
     357           0 :                 DBG_DEBUG("lp_ulong(%s): is called with NULL!\n",s);
     358           0 :                 return -1;
     359             :         }
     360             : 
     361        4045 :         ret = smb_strtoul(s, NULL, 0, &error, SMB_STR_STANDARD);
     362        4045 :         if (error != 0) {
     363           0 :                 DBG_DEBUG("lp_ulong(%s): conversion failed\n",s);
     364           0 :                 return -1;
     365             :         }
     366             : 
     367        4045 :         return ret;
     368             : }
     369             : 
     370             : /**
     371             :  * convenience routine to return unsigned long long parameters.
     372             :  */
     373           0 : unsigned long long lp_ulonglong(const char *s)
     374             : {
     375           0 :         int error = 0;
     376             :         unsigned long long int ret;
     377             : 
     378           0 :         if (!s || !*s) {
     379           0 :                 DBG_DEBUG("lp_ulonglong(%s): is called with NULL!\n", s);
     380           0 :                 return -1;
     381             :         }
     382             : 
     383           0 :         ret = smb_strtoull(s, NULL, 0, &error, SMB_STR_STANDARD);
     384           0 :         if (error != 0) {
     385           0 :                 DBG_DEBUG("lp_ulonglong(%s): conversion failed\n",s);
     386           0 :                 return -1;
     387             :         }
     388             : 
     389           0 :         return ret;
     390             : }
     391             : 
     392             : /**
     393             :  * convenience routine to return unsigned long parameters.
     394             :  */
     395           0 : static long lp_long(const char *s)
     396             : {
     397             : 
     398           0 :         if (!s) {
     399           0 :                 DEBUG(0,("lp_long(%s): is called with NULL!\n",s));
     400           0 :                 return -1;
     401             :         }
     402             : 
     403           0 :         return strtol(s, NULL, 0);
     404             : }
     405             : 
     406             : /**
     407             :  * convenience routine to return unsigned long parameters.
     408             :  */
     409           0 : static double lp_double(const char *s)
     410             : {
     411             : 
     412           0 :         if (!s) {
     413           0 :                 DEBUG(0,("lp_double(%s): is called with NULL!\n",s));
     414           0 :                 return -1;
     415             :         }
     416             : 
     417           0 :         return strtod(s, NULL);
     418             : }
     419             : 
     420             : /**
     421             :  * convenience routine to return boolean parameters.
     422             :  */
     423      269934 : bool lp_bool(const char *s)
     424             : {
     425      269934 :         bool ret = false;
     426             : 
     427      269934 :         if (!s || !*s) {
     428          14 :                 DEBUG(0,("lp_bool(%s): is called with NULL!\n",s));
     429          14 :                 return false;
     430             :         }
     431             : 
     432      269920 :         if (!set_boolean(s, &ret)) {
     433           0 :                 DEBUG(0,("lp_bool(%s): value is not boolean!\n",s));
     434           0 :                 return false;
     435             :         }
     436             : 
     437      269920 :         return ret;
     438             : }
     439             : 
     440             : /**
     441             :  * Return parametric option from a given service. Type is a part of option before ':'
     442             :  * Parametric option has following syntax: 'Type: option = value'
     443             :  * Returned value is allocated in 'lp_talloc' context
     444             :  */
     445             : 
     446      506145 : const char *lpcfg_parm_string(struct loadparm_context *lp_ctx,
     447             :                               struct loadparm_service *service, const char *type,
     448             :                               const char *option)
     449             : {
     450      506145 :         const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
     451             : 
     452      506145 :         if (value)
     453       33499 :                 return lpcfg_string(value);
     454             : 
     455      472646 :         return NULL;
     456             : }
     457             : 
     458             : /**
     459             :  * Return parametric option from a given service. Type is a part of option before ':'
     460             :  * Parametric option has following syntax: 'Type: option = value'
     461             :  * Returned value is allocated in 'lp_talloc' context
     462             :  */
     463             : 
     464           0 : const char **lpcfg_parm_string_list(TALLOC_CTX *mem_ctx,
     465             :                                     struct loadparm_context *lp_ctx,
     466             :                                     struct loadparm_service *service,
     467             :                                     const char *type,
     468             :                                     const char *option, const char *separator)
     469             : {
     470           0 :         const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
     471             : 
     472           0 :         if (value != NULL) {
     473           0 :                 char **l = str_list_make(mem_ctx, value, separator);
     474           0 :                 return discard_const_p(const char *, l);
     475             :         }
     476             : 
     477           0 :         return NULL;
     478             : }
     479             : 
     480             : /**
     481             :  * Return parametric option from a given service. Type is a part of option before ':'
     482             :  * Parametric option has following syntax: 'Type: option = value'
     483             :  */
     484             : 
     485      466037 : int lpcfg_parm_int(struct loadparm_context *lp_ctx,
     486             :                    struct loadparm_service *service, const char *type,
     487             :                    const char *option, int default_v)
     488             : {
     489      466037 :         const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
     490             : 
     491      466037 :         if (value)
     492       40948 :                 return lp_int(value);
     493             : 
     494      425089 :         return default_v;
     495             : }
     496             : 
     497             : /**
     498             :  * Return parametric option from a given service. Type is a part of
     499             :  * option before ':'.
     500             :  * Parametric option has following syntax: 'Type: option = value'.
     501             :  */
     502             : 
     503           0 : int lpcfg_parm_bytes(struct loadparm_context *lp_ctx,
     504             :                   struct loadparm_service *service, const char *type,
     505             :                   const char *option, int default_v)
     506             : {
     507             :         uint64_t bval;
     508             : 
     509           0 :         const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
     510             : 
     511           0 :         if (value && conv_str_size_error(value, &bval)) {
     512           0 :                 if (bval <= INT_MAX) {
     513           0 :                         return (int)bval;
     514             :                 }
     515             :         }
     516             : 
     517           0 :         return default_v;
     518             : }
     519             : 
     520             : /**
     521             :  * Return parametric option from a given service.
     522             :  * Type is a part of option before ':'
     523             :  * Parametric option has following syntax: 'Type: option = value'
     524             :  */
     525       21964 : unsigned long lpcfg_parm_ulong(struct loadparm_context *lp_ctx,
     526             :                             struct loadparm_service *service, const char *type,
     527             :                             const char *option, unsigned long default_v)
     528             : {
     529       21964 :         const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
     530             : 
     531       21964 :         if (value)
     532        4045 :                 return lp_ulong(value);
     533             : 
     534       17919 :         return default_v;
     535             : }
     536             : 
     537             : /**
     538             :  * Return parametric option from a given service.
     539             :  * Type is a part of option before ':'
     540             :  * Parametric option has following syntax: 'Type: option = value'
     541             :  */
     542           0 : unsigned long long lpcfg_parm_ulonglong(struct loadparm_context *lp_ctx,
     543             :                                         struct loadparm_service *service,
     544             :                                         const char *type, const char *option,
     545             :                                         unsigned long long default_v)
     546             : {
     547           0 :         const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
     548             : 
     549           0 :         if (value) {
     550           0 :                 return lp_ulonglong(value);
     551             :         }
     552             : 
     553           0 :         return default_v;
     554             : }
     555             : 
     556         502 : long lpcfg_parm_long(struct loadparm_context *lp_ctx,
     557             :                      struct loadparm_service *service, const char *type,
     558             :                      const char *option, long default_v)
     559             : {
     560         502 :         const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
     561             : 
     562         502 :         if (value)
     563           0 :                 return lp_long(value);
     564             : 
     565         502 :         return default_v;
     566             : }
     567             : 
     568           0 : double lpcfg_parm_double(struct loadparm_context *lp_ctx,
     569             :                       struct loadparm_service *service, const char *type,
     570             :                       const char *option, double default_v)
     571             : {
     572           0 :         const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
     573             : 
     574           0 :         if (value != NULL)
     575           0 :                 return lp_double(value);
     576             : 
     577           0 :         return default_v;
     578             : }
     579             : 
     580             : /**
     581             :  * Return parametric option from a given service. Type is a part of option before ':'
     582             :  * Parametric option has following syntax: 'Type: option = value'
     583             :  */
     584             : 
     585     3522625 : bool lpcfg_parm_bool(struct loadparm_context *lp_ctx,
     586             :                      struct loadparm_service *service, const char *type,
     587             :                      const char *option, bool default_v)
     588             : {
     589     3522625 :         const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
     590             : 
     591     3522625 :         if (value != NULL)
     592      263250 :                 return lp_bool(value);
     593             : 
     594     3259375 :         return default_v;
     595             : }
     596             : 
     597             : 
     598             : /* this is used to prevent lots of mallocs of size 1 */
     599             : static const char lpcfg_string_empty[] = "";
     600             : 
     601             : /**
     602             :  Free a string value.
     603             : **/
     604    14875416 : void lpcfg_string_free(char **s)
     605             : {
     606    14875416 :         if (s == NULL) {
     607           0 :                 return;
     608             :         }
     609    14875416 :         if (*s == lpcfg_string_empty) {
     610     4582675 :                 *s = NULL;
     611     4582675 :                 return;
     612             :         }
     613    10292741 :         TALLOC_FREE(*s);
     614             : }
     615             : 
     616             : /**
     617             :  * Set a string value, deallocating any existing space, and allocing the space
     618             :  * for the string
     619             :  */
     620    12642710 : bool lpcfg_string_set(TALLOC_CTX *mem_ctx, char **dest, const char *src)
     621             : {
     622    12642710 :         lpcfg_string_free(dest);
     623             : 
     624    12642710 :         if ((src == NULL) || (*src == '\0')) {
     625     7420010 :                 *dest = discard_const_p(char, lpcfg_string_empty);
     626     7420010 :                 return true;
     627             :         }
     628             : 
     629     5222700 :         *dest = talloc_strdup(mem_ctx, src);
     630     5222700 :         if ((*dest) == NULL) {
     631           0 :                 DEBUG(0,("Out of memory in string_set\n"));
     632           0 :                 return false;
     633             :         }
     634             : 
     635     5222700 :         return true;
     636             : }
     637             : 
     638             : /**
     639             :  * Set a string value, deallocating any existing space, and allocing the space
     640             :  * for the string
     641             :  */
     642       67036 : bool lpcfg_string_set_upper(TALLOC_CTX *mem_ctx, char **dest, const char *src)
     643             : {
     644       67036 :         lpcfg_string_free(dest);
     645             : 
     646       67036 :         if ((src == NULL) || (*src == '\0')) {
     647           6 :                 *dest = discard_const_p(char, lpcfg_string_empty);
     648           6 :                 return true;
     649             :         }
     650             : 
     651       67030 :         *dest = strupper_talloc(mem_ctx, src);
     652       67030 :         if ((*dest) == NULL) {
     653           0 :                 DEBUG(0,("Out of memory in string_set_upper\n"));
     654           0 :                 return false;
     655             :         }
     656             : 
     657       67030 :         return true;
     658             : }
     659             : 
     660             : 
     661             : 
     662             : /**
     663             :  * Add a new service to the services array initialising it with the given
     664             :  * service.
     665             :  */
     666             : 
     667      131463 : struct loadparm_service *lpcfg_add_service(struct loadparm_context *lp_ctx,
     668             :                                            const struct loadparm_service *pservice,
     669             :                                            const char *name)
     670             : {
     671             :         int i;
     672      131463 :         int num_to_alloc = lp_ctx->iNumServices + 1;
     673             :         struct parmlist_entry *data, *pdata;
     674             : 
     675      131463 :         if (lp_ctx->s3_fns != NULL) {
     676           0 :                 smb_panic("Add a service should not be called on an s3 loadparm ctx");
     677             :         }
     678             : 
     679      131463 :         if (pservice == NULL) {
     680          55 :                 pservice = lp_ctx->sDefault;
     681             :         }
     682             : 
     683             :         /* it might already exist */
     684      131463 :         if (name) {
     685      131463 :                 struct loadparm_service *service = lpcfg_getservicebyname(lp_ctx,
     686             :                                                                     name);
     687      131463 :                 if (service != NULL) {
     688             :                         /* Clean all parametric options for service */
     689             :                         /* They will be added during parsing again */
     690       73851 :                         data = service->param_opt;
     691      279376 :                         while (data) {
     692      135154 :                                 pdata = data->next;
     693      135154 :                                 talloc_free(data);
     694      135154 :                                 data = pdata;
     695             :                         }
     696       73851 :                         service->param_opt = NULL;
     697       73851 :                         return service;
     698             :                 }
     699             :         }
     700             : 
     701             :         /* find an invalid one */
     702      764000 :         for (i = 0; i < lp_ctx->iNumServices; i++)
     703      706388 :                 if (lp_ctx->services[i] == NULL)
     704           0 :                         break;
     705             : 
     706             :         /* if not, then create one */
     707       57612 :         if (i == lp_ctx->iNumServices) {
     708             :                 struct loadparm_service **tsp;
     709             : 
     710       57612 :                 tsp = talloc_realloc(lp_ctx, lp_ctx->services, struct loadparm_service *, num_to_alloc);
     711             : 
     712       57612 :                 if (!tsp) {
     713           0 :                         DEBUG(0,("lpcfg_add_service: failed to enlarge services!\n"));
     714           0 :                         return NULL;
     715             :                 } else {
     716       57612 :                         lp_ctx->services = tsp;
     717       57612 :                         lp_ctx->services[lp_ctx->iNumServices] = NULL;
     718             :                 }
     719             : 
     720       57612 :                 lp_ctx->iNumServices++;
     721             :         }
     722             : 
     723       57612 :         lp_ctx->services[i] = talloc_zero(lp_ctx->services, struct loadparm_service);
     724       57612 :         if (lp_ctx->services[i] == NULL) {
     725           0 :                 DEBUG(0,("lpcfg_add_service: out of memory!\n"));
     726           0 :                 return NULL;
     727             :         }
     728       57612 :         copy_service(lp_ctx->services[i], pservice, NULL);
     729       57612 :         if (name != NULL)
     730       57612 :                 lpcfg_string_set(lp_ctx->services[i], &lp_ctx->services[i]->szService, name);
     731       57612 :         return lp_ctx->services[i];
     732             : }
     733             : 
     734             : /**
     735             :  * Map a parameter's string representation to something we can use.
     736             :  * Returns False if the parameter string is not recognised, else TRUE.
     737             :  */
     738             : 
     739     5278447 : int lpcfg_map_parameter(const char *pszParmName)
     740             : {
     741             :         int iIndex;
     742             : 
     743  1700114769 :         for (iIndex = 0; parm_table[iIndex].label; iIndex++)
     744  1699213657 :                 if (strwicmp(parm_table[iIndex].label, pszParmName) == 0)
     745     4377335 :                         return iIndex;
     746             : 
     747             :         /* Warn only if it isn't parametric option */
     748      901112 :         if (strchr(pszParmName, ':') == NULL)
     749           0 :                 DEBUG(0, ("Unknown parameter encountered: \"%s\"\n", pszParmName));
     750             :         /* We do return 'fail' for parametric options as well because they are
     751             :            stored in different storage
     752             :          */
     753      901112 :         return -1;
     754             : }
     755             : 
     756             : 
     757             : /**
     758             :   return the parameter structure for a parameter
     759             : */
     760       25153 : struct parm_struct *lpcfg_parm_struct(struct loadparm_context *lp_ctx, const char *name)
     761             : {
     762       25153 :         int num = lpcfg_map_parameter(name);
     763             : 
     764       25153 :         if (num < 0) {
     765           0 :                 return NULL;
     766             :         }
     767             : 
     768       25153 :         return &parm_table[num];
     769             : }
     770             : 
     771             : /**
     772             :   return the parameter pointer for a parameter
     773             : */
     774     3172860 : void *lpcfg_parm_ptr(struct loadparm_context *lp_ctx,
     775             :                   struct loadparm_service *service, struct parm_struct *parm)
     776             : {
     777     3172860 :         if (lp_ctx->s3_fns) {
     778      414938 :                 return lp_ctx->s3_fns->get_parm_ptr(service, parm);
     779             :         }
     780             : 
     781     2757922 :         if (service == NULL) {
     782     2754027 :                 if (parm->p_class == P_LOCAL)
     783      353563 :                         return ((char *)lp_ctx->sDefault)+parm->offset;
     784     2400464 :                 else if (parm->p_class == P_GLOBAL)
     785     2400464 :                         return ((char *)lp_ctx->globals)+parm->offset;
     786           0 :                 else return NULL;
     787             :         } else {
     788        3895 :                 return ((char *)service) + parm->offset;
     789             :         }
     790             : }
     791             : 
     792             : /**
     793             :   return the parameter pointer for a parameter
     794             : */
     795      293488 : bool lpcfg_parm_is_cmdline(struct loadparm_context *lp_ctx, const char *name)
     796             : {
     797             :         int parmnum;
     798             : 
     799      293488 :         parmnum = lpcfg_map_parameter(name);
     800      293488 :         if (parmnum == -1) return false;
     801             : 
     802      293488 :         return lp_ctx->flags[parmnum] & FLAG_CMDLINE;
     803             : }
     804             : 
     805           0 : bool lpcfg_parm_is_unspecified(struct loadparm_context *lp_ctx, const char *name)
     806             : {
     807             :         int parmnum;
     808             : 
     809           0 :         parmnum = lpcfg_map_parameter(name);
     810           0 :         if (parmnum == -1) return false;
     811             : 
     812           0 :         return lp_ctx->flags[parmnum] & FLAG_DEFAULT;
     813             : }
     814             : 
     815             : /**
     816             :  * Find a service by name. Otherwise works like get_service.
     817             :  */
     818             : 
     819      223617 : static struct loadparm_service *lpcfg_getservicebyname(struct loadparm_context *lp_ctx,
     820             :                                         const char *pszServiceName)
     821             : {
     822             :         int iService;
     823             : 
     824      223617 :         if (lp_ctx->s3_fns) {
     825       55253 :                 return lp_ctx->s3_fns->get_service(pszServiceName);
     826             :         }
     827             : 
     828     2343184 :         for (iService = lp_ctx->iNumServices - 1; iService >= 0; iService--)
     829     4571142 :                 if (lp_ctx->services[iService] != NULL &&
     830     2285571 :                     strwicmp(lp_ctx->services[iService]->szService, pszServiceName) == 0) {
     831      110751 :                         return lp_ctx->services[iService];
     832             :                 }
     833             : 
     834       57613 :         return NULL;
     835             : }
     836             : 
     837             : /**
     838             :  * Add a parametric option to a parmlist_entry,
     839             :  * replacing old value, if already present.
     840             :  */
     841      983828 : void set_param_opt(TALLOC_CTX *mem_ctx,
     842             :                    struct parmlist_entry **opt_list,
     843             :                    const char *opt_name,
     844             :                    const char *opt_value,
     845             :                    unsigned priority)
     846             : {
     847             :         struct parmlist_entry *new_opt, *opt;
     848             : 
     849      983828 :         opt = *opt_list;
     850             : 
     851             :         /* Traverse destination */
     852    11588134 :         while (opt) {
     853             :                 /* If we already have same option, override it */
     854    10067145 :                 if (strwicmp(opt->key, opt_name) == 0) {
     855      234113 :                         if ((opt->priority & FLAG_CMDLINE) &&
     856        5062 :                             !(priority & FLAG_CMDLINE)) {
     857             :                                 /* it's been marked as not to be
     858             :                                    overridden */
     859         116 :                                 return;
     860             :                         }
     861      230880 :                         TALLOC_FREE(opt->list);
     862      230880 :                         lpcfg_string_set(opt, &opt->value, opt_value);
     863      230880 :                         opt->priority = priority;
     864      230880 :                         return;
     865             :                 }
     866     9836149 :                 opt = opt->next;
     867             :         }
     868             : 
     869      752832 :         new_opt = talloc_pooled_object(
     870             :                 mem_ctx, struct parmlist_entry,
     871             :                 2, strlen(opt_name) + 1 + strlen(opt_value) + 1);
     872      752832 :         if (new_opt == NULL) {
     873           0 :                 smb_panic("OOM");
     874             :         }
     875      752832 :         new_opt->key = NULL;
     876      752832 :         lpcfg_string_set(new_opt, &new_opt->key, opt_name);
     877      752832 :         new_opt->value = NULL;
     878      752832 :         lpcfg_string_set(new_opt, &new_opt->value, opt_value);
     879             : 
     880      752832 :         new_opt->list = NULL;
     881      752832 :         new_opt->priority = priority;
     882      752832 :         DLIST_ADD(*opt_list, new_opt);
     883             : }
     884             : 
     885             : /**
     886             :  * Copy a service structure to another.
     887             :  * If pcopymapDest is NULL then copy all fields
     888             :  */
     889             : 
     890      189447 : void copy_service(struct loadparm_service *pserviceDest,
     891             :                   const struct loadparm_service *pserviceSource,
     892             :                   struct bitmap *pcopymapDest)
     893             : {
     894             :         int i;
     895      189447 :         bool bcopyall = (pcopymapDest == NULL);
     896             :         struct parmlist_entry *data;
     897             : 
     898    97754652 :         for (i = 0; parm_table[i].label; i++)
     899   117049449 :                 if (parm_table[i].p_class == P_LOCAL &&
     900    14375712 :                     (bcopyall || bitmap_query(pcopymapDest, i))) {
     901    29365117 :                         const void *src_ptr =
     902    29365117 :                                 ((const char *)pserviceSource) + parm_table[i].offset;
     903    29365117 :                         void *dest_ptr =
     904    29365117 :                                 ((char *)pserviceDest) + parm_table[i].offset;
     905             : 
     906    29365117 :                         switch (parm_table[i].type) {
     907    14357782 :                                 case P_BOOL:
     908             :                                 case P_BOOLREV:
     909    14357782 :                                         *(bool *)dest_ptr = *(const bool *)src_ptr;
     910    14357782 :                                         break;
     911             : 
     912     6048764 :                                 case P_INTEGER:
     913             :                                 case P_BYTES:
     914             :                                 case P_OCTAL:
     915             :                                 case P_ENUM:
     916     6048764 :                                         *(int *)dest_ptr = *(const int *)src_ptr;
     917     6048764 :                                         break;
     918             : 
     919      189447 :                                 case P_CHAR:
     920      189447 :                                         *(char *)dest_ptr = *(const char *)src_ptr;
     921      189447 :                                         break;
     922             : 
     923     6526097 :                                 case P_STRING:
     924     6526097 :                                         lpcfg_string_set(pserviceDest,
     925             :                                                    (char **)dest_ptr,
     926             :                                                    *(const char * const *)src_ptr);
     927     6526097 :                                         break;
     928             : 
     929           0 :                                 case P_USTRING:
     930           0 :                                         lpcfg_string_set_upper(pserviceDest,
     931             :                                                          (char **)dest_ptr,
     932             :                                                          *(const char * const *)src_ptr);
     933           0 :                                         break;
     934     2243027 :                                 case P_CMDLIST:
     935             :                                 case P_LIST:
     936     2243027 :                                         TALLOC_FREE(*((char ***)dest_ptr));
     937     2243027 :                                         *(char ***)dest_ptr = str_list_copy(pserviceDest,
     938             :                                                                             *discard_const_p(const char **, src_ptr));
     939     2243027 :                                         break;
     940           0 :                                 default:
     941           0 :                                         break;
     942             :                         }
     943    44963737 :                 }
     944             : 
     945      189447 :         if (bcopyall) {
     946       97295 :                 init_copymap(pserviceDest);
     947       97295 :                 if (pserviceSource->copymap)
     948           2 :                         bitmap_copy(pserviceDest->copymap,
     949           2 :                                     pserviceSource->copymap);
     950             :         }
     951             : 
     952      272145 :         for (data = pserviceSource->param_opt; data != NULL; data = data->next) {
     953      159258 :                 set_param_opt(pserviceDest, &pserviceDest->param_opt,
     954      159258 :                               data->key, data->value, data->priority);
     955             :         }
     956      189447 : }
     957             : 
     958             : /**
     959             :  * Check a service for consistency. Return False if the service is in any way
     960             :  * incomplete or faulty, else True.
     961             :  */
     962      323935 : bool lpcfg_service_ok(struct loadparm_service *service)
     963             : {
     964             :         bool bRetval;
     965             : 
     966      323935 :         bRetval = true;
     967      323935 :         if (service->szService[0] == '\0') {
     968           0 :                 DEBUG(0, ("The following message indicates an internal error:\n"));
     969           0 :                 DEBUG(0, ("No service name in service entry.\n"));
     970           0 :                 bRetval = false;
     971             :         }
     972             : 
     973             :         /* The [printers] entry MUST be printable. I'm all for flexibility, but */
     974             :         /* I can't see why you'd want a non-printable printer service...        */
     975      323935 :         if (strwicmp(service->szService, PRINTERS_NAME) == 0) {
     976           0 :                 if (!service->printable) {
     977           0 :                         DEBUG(0, ("WARNING: [%s] service MUST be printable!\n",
     978             :                                service->szService));
     979           0 :                         service->printable = true;
     980             :                 }
     981             :                 /* [printers] service must also be non-browsable. */
     982           0 :                 if (service->browseable)
     983           0 :                         service->browseable = false;
     984             :         }
     985             : 
     986      323941 :         if (service->path[0] == '\0' &&
     987           8 :             strwicmp(service->szService, HOMES_NAME) != 0 &&
     988           2 :             service->msdfs_proxy[0] == '\0')
     989             :         {
     990           2 :                 DEBUG(0, ("WARNING: No path in service %s - making it unavailable!\n",
     991             :                         service->szService));
     992           2 :                 service->available = false;
     993             :         }
     994             : 
     995      323935 :         if (!service->available)
     996           2 :                 DEBUG(1, ("NOTE: Service %s is flagged unavailable.\n",
     997             :                           service->szService));
     998             : 
     999      323935 :         return bRetval;
    1000             : }
    1001             : 
    1002             : 
    1003             : /*******************************************************************
    1004             :  Keep a linked list of all config files so we know when one has changed
    1005             :  it's date and needs to be reloaded.
    1006             : ********************************************************************/
    1007             : 
    1008       42430 : void add_to_file_list(TALLOC_CTX *mem_ctx, struct file_lists **list,
    1009             :                              const char *fname, const char *subfname)
    1010             : {
    1011       42430 :         struct file_lists *f = *list;
    1012             : 
    1013      104063 :         while (f) {
    1014       45256 :                 if (f->name && !strcmp(f->name, fname))
    1015       15023 :                         break;
    1016       30233 :                 f = f->next;
    1017             :         }
    1018             : 
    1019       42430 :         if (!f) {
    1020       27407 :                 f = talloc(mem_ctx, struct file_lists);
    1021       27407 :                 if (!f)
    1022           0 :                         goto fail;
    1023       27407 :                 f->next = *list;
    1024       27407 :                 f->name = talloc_strdup(f, fname);
    1025       27407 :                 if (!f->name) {
    1026           0 :                         TALLOC_FREE(f);
    1027           0 :                         goto fail;
    1028             :                 }
    1029       27407 :                 f->subfname = talloc_strdup(f, subfname);
    1030       27407 :                 if (!f->subfname) {
    1031           0 :                         TALLOC_FREE(f);
    1032           0 :                         goto fail;
    1033             :                 }
    1034       27407 :                 *list = f;
    1035       27407 :                 f->modtime = file_modtime(subfname);
    1036             :         } else {
    1037       15023 :                 time_t t = file_modtime(subfname);
    1038       15023 :                 if (t)
    1039       14975 :                         f->modtime = t;
    1040             :         }
    1041       42430 :         return;
    1042             : 
    1043           0 : fail:
    1044           0 :         DEBUG(0, ("Unable to add file to file list: %s\n", fname));
    1045             : 
    1046             : }
    1047             : 
    1048             : /*
    1049             :  * set the value for a P_ENUM
    1050             :  */
    1051      602350 : bool lp_set_enum_parm( struct parm_struct *parm, const char *pszParmValue,
    1052             :                               int *ptr )
    1053             : {
    1054             :         int i;
    1055             : 
    1056     2378433 :         for (i = 0; parm->enum_list[i].name; i++) {
    1057     2378433 :                 if (strwicmp(pszParmValue, parm->enum_list[i].name) == 0) {
    1058      602350 :                         *ptr = parm->enum_list[i].value;
    1059      602350 :                         return true;
    1060             :                 }
    1061             :         }
    1062           0 :         DEBUG(0, ("WARNING: Ignoring invalid value '%s' for parameter '%s'\n",
    1063             :                   pszParmValue, parm->label));
    1064           0 :         return false;
    1065             : }
    1066             : 
    1067             : 
    1068             : /***************************************************************************
    1069             :  Handle the "realm" parameter
    1070             : ***************************************************************************/
    1071             : 
    1072       22535 : bool handle_realm(struct loadparm_context *lp_ctx, struct loadparm_service *service,
    1073             :                   const char *pszParmValue, char **ptr)
    1074             : {
    1075             :         char *upper;
    1076             :         char *lower;
    1077             : 
    1078       22535 :         upper = strupper_talloc(lp_ctx, pszParmValue);
    1079       22535 :         if (upper == NULL) {
    1080           0 :                 return false;
    1081             :         }
    1082             : 
    1083       22535 :         lower = strlower_talloc(lp_ctx, pszParmValue);
    1084       22535 :         if (lower == NULL) {
    1085           0 :                 TALLOC_FREE(upper);
    1086           0 :                 return false;
    1087             :         }
    1088             : 
    1089       22535 :         lpcfg_string_set(lp_ctx->globals->ctx, &lp_ctx->globals->realm, upper);
    1090       22535 :         lpcfg_string_set(lp_ctx->globals->ctx, &lp_ctx->globals->dnsdomain, lower);
    1091             : 
    1092       22535 :         return true;
    1093             : }
    1094             : 
    1095             : /***************************************************************************
    1096             :  Handle the include operation.
    1097             : ***************************************************************************/
    1098             : 
    1099       14806 : bool handle_include(struct loadparm_context *lp_ctx, struct loadparm_service *service,
    1100             :                            const char *pszParmValue, char **ptr)
    1101             : {
    1102             :         char *fname;
    1103             :         const char *substitution_variable_substring;
    1104             :         char next_char;
    1105             : 
    1106       14806 :         if (lp_ctx->s3_fns) {
    1107       14070 :                 return lp_ctx->s3_fns->lp_include(lp_ctx, service, pszParmValue, ptr);
    1108             :         }
    1109             : 
    1110         736 :         fname = standard_sub_basic(lp_ctx, pszParmValue);
    1111             : 
    1112         736 :         add_to_file_list(lp_ctx, &lp_ctx->file_lists, pszParmValue, fname);
    1113             : 
    1114         736 :         lpcfg_string_set(lp_ctx, ptr, fname);
    1115             : 
    1116         736 :         if (file_exist(fname))
    1117         630 :                 return pm_process(fname, do_section, lpcfg_do_parameter, lp_ctx);
    1118             : 
    1119             :        /*
    1120             :         * If the file doesn't exist, we check that it isn't due to variable
    1121             :         * substitution
    1122             :         */
    1123         106 :         substitution_variable_substring = strchr(fname, '%');
    1124             : 
    1125         106 :         if (substitution_variable_substring != NULL) {
    1126         105 :                 next_char = substitution_variable_substring[1];
    1127         105 :                 if ((next_char >= 'a' && next_char <= 'z')
    1128         105 :                     || (next_char >= 'A' && next_char <= 'Z')) {
    1129         105 :                         DEBUG(2, ("Tried to load %s but variable substitution in "
    1130             :                                  "filename, ignoring file.\n", fname));
    1131         105 :                         return true;
    1132             :                 }
    1133             :         }
    1134             : 
    1135           1 :         DEBUG(2, ("Can't find include file %s\n", fname));
    1136             : 
    1137           1 :         return false;
    1138             : }
    1139             : 
    1140             : /***************************************************************************
    1141             :  Handle the interpretation of the copy parameter.
    1142             : ***************************************************************************/
    1143             : 
    1144       92154 : bool handle_copy(struct loadparm_context *lp_ctx, struct loadparm_service *service,
    1145             :                         const char *pszParmValue, char **ptr)
    1146             : {
    1147             :         bool bRetval;
    1148       92154 :         struct loadparm_service *serviceTemp = NULL;
    1149             : 
    1150       92154 :         bRetval = false;
    1151             : 
    1152       92154 :         DEBUG(3, ("Copying service from service %s\n", pszParmValue));
    1153             : 
    1154       92154 :         serviceTemp = lpcfg_getservicebyname(lp_ctx, pszParmValue);
    1155             : 
    1156       92154 :         if (service == NULL) {
    1157           2 :                 DEBUG(0, ("Unable to copy service - invalid service destination.\n"));
    1158           2 :                 return false;
    1159             :         }
    1160             : 
    1161       92152 :         if (serviceTemp != NULL) {
    1162       92152 :                 if (serviceTemp == service) {
    1163           0 :                         DEBUG(0, ("Can't copy service %s - unable to copy self!\n", pszParmValue));
    1164             :                 } else {
    1165       92152 :                         copy_service(service,
    1166             :                                      serviceTemp,
    1167             :                                      service->copymap);
    1168       92152 :                         lpcfg_string_set(service, ptr, pszParmValue);
    1169             : 
    1170       92152 :                         bRetval = true;
    1171             :                 }
    1172             :         } else {
    1173           0 :                 DEBUG(0, ("Unable to copy service - source not found: %s\n",
    1174             :                           pszParmValue));
    1175           0 :                 bRetval = false;
    1176             :         }
    1177             : 
    1178       92152 :         return bRetval;
    1179             : }
    1180             : 
    1181       38495 : bool handle_debug_list(struct loadparm_context *lp_ctx, struct loadparm_service *service,
    1182             :                         const char *pszParmValue, char **ptr)
    1183             : {
    1184       38495 :         lpcfg_string_set(lp_ctx->globals->ctx, ptr, pszParmValue);
    1185             : 
    1186       38495 :         return debug_parse_levels(pszParmValue);
    1187             : }
    1188             : 
    1189       33677 : bool handle_logfile(struct loadparm_context *lp_ctx, struct loadparm_service *service,
    1190             :                     const char *pszParmValue, char **ptr)
    1191             : {
    1192       33677 :         if (lp_ctx->s3_fns == NULL) {
    1193       20851 :                 debug_set_logfile(pszParmValue);
    1194             :         }
    1195             : 
    1196       33677 :         lpcfg_string_set(lp_ctx->globals->ctx, ptr, pszParmValue);
    1197             : 
    1198       33677 :         return true;
    1199             : }
    1200             : 
    1201             : /*
    1202             :  * These special charset handling methods only run in the source3 code.
    1203             :  */
    1204             : 
    1205        8478 : bool handle_charset(struct loadparm_context *lp_ctx, struct loadparm_service *service,
    1206             :                         const char *pszParmValue, char **ptr)
    1207             : {
    1208        8478 :         if (lp_ctx->s3_fns) {
    1209           6 :                 if (*ptr == NULL || strcmp(*ptr, pszParmValue) != 0) {
    1210           5 :                         struct smb_iconv_handle *ret = NULL;
    1211             : 
    1212           5 :                         ret = reinit_iconv_handle(NULL,
    1213             :                                                   lpcfg_dos_charset(lp_ctx),
    1214             :                                                   lpcfg_unix_charset(lp_ctx));
    1215           5 :                         if (ret == NULL) {
    1216           0 :                                 smb_panic("reinit_iconv_handle failed");
    1217             :                         }
    1218             :                 }
    1219             : 
    1220             :         }
    1221        8478 :         return lpcfg_string_set(lp_ctx->globals->ctx, ptr, pszParmValue);
    1222             : 
    1223             : }
    1224             : 
    1225        8475 : bool handle_dos_charset(struct loadparm_context *lp_ctx, struct loadparm_service *service,
    1226             :                         const char *pszParmValue, char **ptr)
    1227             : {
    1228        8475 :         bool is_utf8 = false;
    1229        8475 :         size_t len = strlen(pszParmValue);
    1230             : 
    1231        8475 :         if (lp_ctx->s3_fns) {
    1232           4 :                 if (len == 4 || len == 5) {
    1233             :                         /* Don't use StrCaseCmp here as we don't want to
    1234             :                            initialize iconv. */
    1235           0 :                         if ((toupper_m(pszParmValue[0]) == 'U') &&
    1236           0 :                             (toupper_m(pszParmValue[1]) == 'T') &&
    1237           0 :                             (toupper_m(pszParmValue[2]) == 'F')) {
    1238           0 :                                 if (len == 4) {
    1239           0 :                                         if (pszParmValue[3] == '8') {
    1240           0 :                                                 is_utf8 = true;
    1241             :                                         }
    1242             :                                 } else {
    1243           0 :                                         if (pszParmValue[3] == '-' &&
    1244           0 :                                             pszParmValue[4] == '8') {
    1245           0 :                                                 is_utf8 = true;
    1246             :                                         }
    1247             :                                 }
    1248             :                         }
    1249             :                 }
    1250             : 
    1251           4 :                 if (*ptr == NULL || strcmp(*ptr, pszParmValue) != 0) {
    1252           4 :                         struct smb_iconv_handle *ret = NULL;
    1253           4 :                         if (is_utf8) {
    1254           0 :                                 DEBUG(0,("ERROR: invalid DOS charset: 'dos charset' must not "
    1255             :                                         "be UTF8, using (default value) %s instead.\n",
    1256             :                                         DEFAULT_DOS_CHARSET));
    1257           0 :                                 pszParmValue = DEFAULT_DOS_CHARSET;
    1258             :                         }
    1259           4 :                         ret = reinit_iconv_handle(NULL,
    1260             :                                                 lpcfg_dos_charset(lp_ctx),
    1261             :                                                 lpcfg_unix_charset(lp_ctx));
    1262           4 :                         if (ret == NULL) {
    1263           0 :                                 smb_panic("reinit_iconv_handle failed");
    1264             :                         }
    1265             :                 }
    1266             :         }
    1267             : 
    1268        8475 :         return lpcfg_string_set(lp_ctx->globals->ctx, ptr, pszParmValue);
    1269             : }
    1270             : 
    1271       12540 : bool handle_printing(struct loadparm_context *lp_ctx, struct loadparm_service *service,
    1272             :                             const char *pszParmValue, char **ptr)
    1273             : {
    1274             :         static int parm_num = -1;
    1275             : 
    1276       12540 :         if (parm_num == -1) {
    1277        2696 :                 parm_num = lpcfg_map_parameter("printing");
    1278             :         }
    1279             : 
    1280       12540 :         if (!lp_set_enum_parm(&parm_table[parm_num], pszParmValue, (int*)ptr)) {
    1281           0 :                 return false;
    1282             :         }
    1283             : 
    1284       12540 :         if (lp_ctx->s3_fns) {
    1285        7600 :                 if (service == NULL) {
    1286        7600 :                         init_printer_values(lp_ctx, lp_ctx->globals->ctx, lp_ctx->sDefault);
    1287             :                 } else {
    1288           0 :                         init_printer_values(lp_ctx, service, service);
    1289             :                 }
    1290             :         }
    1291             : 
    1292       12540 :         return true;
    1293             : }
    1294             : 
    1295           9 : bool handle_ldap_debug_level(struct loadparm_context *lp_ctx, struct loadparm_service *service,
    1296             :                              const char *pszParmValue, char **ptr)
    1297             : {
    1298           9 :         lp_ctx->globals->ldap_debug_level = lp_int(pszParmValue);
    1299             : 
    1300           9 :         if (lp_ctx->s3_fns) {
    1301           6 :                 lp_ctx->s3_fns->init_ldap_debugging();
    1302             :         }
    1303           9 :         return true;
    1304             : }
    1305             : 
    1306             : /*
    1307             :  * idmap related parameters
    1308             :  */
    1309             : 
    1310        8478 : bool handle_idmap_backend(struct loadparm_context *lp_ctx, struct loadparm_service *service,
    1311             :                           const char *pszParmValue, char **ptr)
    1312             : {
    1313        8478 :         if (lp_ctx->s3_fns) {
    1314           6 :                 lp_do_parameter_parametric(lp_ctx, service, "idmap config * : backend",
    1315             :                                            pszParmValue, 0);
    1316             :         }
    1317             : 
    1318        8478 :         return lpcfg_string_set(lp_ctx->globals->ctx, ptr, pszParmValue);
    1319             : }
    1320             : 
    1321           9 : bool handle_idmap_uid(struct loadparm_context *lp_ctx, struct loadparm_service *service,
    1322             :                       const char *pszParmValue, char **ptr)
    1323             : {
    1324           9 :         if (lp_ctx->s3_fns) {
    1325           6 :                 lp_do_parameter_parametric(lp_ctx, service, "idmap config * : range",
    1326             :                                            pszParmValue, 0);
    1327             :         }
    1328             : 
    1329           9 :         return lpcfg_string_set(lp_ctx->globals->ctx, ptr, pszParmValue);
    1330             : }
    1331             : 
    1332           9 : bool handle_idmap_gid(struct loadparm_context *lp_ctx, struct loadparm_service *service,
    1333             :                       const char *pszParmValue, char **ptr)
    1334             : {
    1335           9 :         if (lp_ctx->s3_fns) {
    1336           6 :                 lp_do_parameter_parametric(lp_ctx, service, "idmap config * : range",
    1337             :                                            pszParmValue, 0);
    1338             :         }
    1339             : 
    1340           9 :         return lpcfg_string_set(lp_ctx->globals->ctx, ptr, pszParmValue);
    1341             : }
    1342             : 
    1343        8472 : bool handle_smb_ports(struct loadparm_context *lp_ctx, struct loadparm_service *service,
    1344             :                       const char *pszParmValue, char **ptr)
    1345             : {
    1346             :         static int parm_num = -1;
    1347             :         int i;
    1348             :         const char **list;
    1349             : 
    1350        8472 :         if (!pszParmValue || !*pszParmValue) {
    1351           0 :                 return false;
    1352             :         }
    1353             : 
    1354        8472 :         if (parm_num == -1) {
    1355        8419 :                 parm_num = lpcfg_map_parameter("smb ports");
    1356        8419 :                 if (parm_num == -1) {
    1357           0 :                         return false;
    1358             :                 }
    1359             :         }
    1360             : 
    1361        8472 :         if (!set_variable_helper(lp_ctx->globals->ctx, parm_num, ptr, "smb ports",
    1362             :                                 pszParmValue)) {
    1363           0 :                 return false;
    1364             :         }
    1365             : 
    1366        8472 :         list = lp_ctx->globals->smb_ports;
    1367        8472 :         if (list == NULL) {
    1368           0 :                 return false;
    1369             :         }
    1370             : 
    1371             :         /* Check that each port is a valid integer and within range */
    1372       25416 :         for (i = 0; list[i] != NULL; i++) {
    1373       16944 :                 char *end = NULL;
    1374       16944 :                 int port = 0;
    1375       16944 :                 port = strtol(list[i], &end, 10);
    1376       16944 :                 if (*end != '\0' || port <= 0 || port > 65535) {
    1377           0 :                         TALLOC_FREE(list);
    1378           0 :                         return false;
    1379             :                 }
    1380             :         }
    1381             : 
    1382        8472 :         return true;
    1383             : }
    1384             : 
    1385        8472 : bool handle_rpc_server_dynamic_port_range(struct loadparm_context *lp_ctx,
    1386             :                                           struct loadparm_service *service,
    1387             :                                           const char *pszParmValue,
    1388             :                                           char **ptr)
    1389             : {
    1390             :         static int parm_num = -1;
    1391        8472 :         int low_port = -1, high_port = -1;
    1392             :         int rc;
    1393             : 
    1394        8472 :         if (parm_num == -1) {
    1395        8419 :                 parm_num = lpcfg_map_parameter("rpc server dynamic port range");
    1396        8419 :                 if (parm_num == -1) {
    1397           0 :                         return false;
    1398             :                 }
    1399             :         }
    1400             : 
    1401        8472 :         if (pszParmValue == NULL || pszParmValue[0] == '\0') {
    1402           0 :                 return false;
    1403             :         }
    1404             : 
    1405        8472 :         rc = sscanf(pszParmValue, "%d - %d", &low_port, &high_port);
    1406        8472 :         if (rc != 2) {
    1407           0 :                 return false;
    1408             :         }
    1409             : 
    1410        8472 :         if (low_port > high_port) {
    1411           0 :                 return false;
    1412             :         }
    1413             : 
    1414        8472 :         if (low_port < SERVER_TCP_PORT_MIN|| high_port > SERVER_TCP_PORT_MAX) {
    1415           0 :                 return false;
    1416             :         }
    1417             : 
    1418        8472 :         if (!set_variable_helper(lp_ctx->globals->ctx, parm_num, ptr,
    1419             :                                  "rpc server dynamic port range",
    1420             :                                  pszParmValue)) {
    1421           0 :                 return false;
    1422             :         }
    1423             : 
    1424        8472 :         lp_ctx->globals->rpc_low_port = low_port;
    1425        8472 :         lp_ctx->globals->rpc_high_port = high_port;
    1426             : 
    1427        8472 :         return true;
    1428             : }
    1429             : 
    1430        8478 : bool handle_smb2_max_credits(struct loadparm_context *lp_ctx,
    1431             :                              struct loadparm_service *service,
    1432             :                              const char *pszParmValue, char **ptr)
    1433             : {
    1434        8478 :         int value = lp_int(pszParmValue);
    1435             : 
    1436        8478 :         if (value <= 0) {
    1437           0 :                 value = DEFAULT_SMB2_MAX_CREDITS;
    1438             :         }
    1439             : 
    1440        8478 :         *(int *)ptr = value;
    1441             : 
    1442        8478 :         return true;
    1443             : }
    1444             : 
    1445           0 : bool handle_cups_encrypt(struct loadparm_context *lp_ctx,
    1446             :                          struct loadparm_service *service,
    1447             :                          const char *pszParmValue, char **ptr)
    1448             : {
    1449           0 :         int result = 0;
    1450             : #ifdef HAVE_HTTPCONNECTENCRYPT
    1451           0 :         int value = lp_int(pszParmValue);
    1452             : 
    1453           0 :         switch (value) {
    1454           0 :                 case Auto:
    1455           0 :                         result = HTTP_ENCRYPT_REQUIRED;
    1456           0 :                         break;
    1457           0 :                 case true:
    1458           0 :                         result = HTTP_ENCRYPT_ALWAYS;
    1459           0 :                         break;
    1460           0 :                 case false:
    1461           0 :                         result = HTTP_ENCRYPT_NEVER;
    1462           0 :                         break;
    1463           0 :                 default:
    1464           0 :                         result = 0;
    1465           0 :                         break;
    1466             :         }
    1467             : #endif
    1468           0 :         *(int *)ptr = result;
    1469             : 
    1470           0 :         return true;
    1471             : }
    1472             : 
    1473             : /***************************************************************************
    1474             :  Initialise a copymap.
    1475             : ***************************************************************************/
    1476             : 
    1477             : /**
    1478             :  * Initializes service copymap
    1479             :  * Note: pservice *must* be valid TALLOC_CTX
    1480             :  */
    1481       97295 : void init_copymap(struct loadparm_service *pservice)
    1482             : {
    1483             :         int i;
    1484             : 
    1485       97295 :         TALLOC_FREE(pservice->copymap);
    1486             : 
    1487       97295 :         pservice->copymap = bitmap_talloc(pservice, num_parameters());
    1488       97295 :         if (!pservice->copymap) {
    1489           0 :                 DEBUG(0,
    1490             :                       ("Couldn't allocate copymap!! (size %d)\n",
    1491             :                        (int)num_parameters()));
    1492             :         } else {
    1493    50301515 :                 for (i = 0; i < num_parameters(); i++) {
    1494    50204220 :                         bitmap_set(pservice->copymap, i);
    1495             :                 }
    1496             :         }
    1497       97295 : }
    1498             : 
    1499             : /**
    1500             :  * Process a parametric option
    1501             :  */
    1502      900883 : static bool lp_do_parameter_parametric(struct loadparm_context *lp_ctx,
    1503             :                                        struct loadparm_service *service,
    1504             :                                        const char *pszParmName,
    1505             :                                        const char *pszParmValue, int flags)
    1506             : {
    1507             :         struct parmlist_entry **data;
    1508             :         char *name;
    1509             :         TALLOC_CTX *mem_ctx;
    1510             : 
    1511     1592236 :         while (isspace((unsigned char)*pszParmName)) {
    1512           0 :                 pszParmName++;
    1513             :         }
    1514             : 
    1515      900883 :         name = strlower_talloc(lp_ctx, pszParmName);
    1516      900883 :         if (!name) return false;
    1517             : 
    1518      900883 :         if (service == NULL) {
    1519      522016 :                 data = &lp_ctx->globals->param_opt;
    1520             :                 /**
    1521             :                  * s3 code cannot deal with parametric options stored on the globals ctx.
    1522             :                  */
    1523      522016 :                 if (lp_ctx->s3_fns != NULL) {
    1524      129775 :                         mem_ctx = NULL;
    1525             :                 } else {
    1526      392241 :                         mem_ctx = lp_ctx->globals->ctx;
    1527             :                 }
    1528             :         } else {
    1529      378867 :                 data = &service->param_opt;
    1530      378867 :                 mem_ctx = service;
    1531             :         }
    1532             : 
    1533      900883 :         set_param_opt(mem_ctx, data, name, pszParmValue, flags);
    1534             : 
    1535      900883 :         talloc_free(name);
    1536             : 
    1537      900883 :         return true;
    1538             : }
    1539             : 
    1540     3754630 : static bool set_variable_helper(TALLOC_CTX *mem_ctx, int parmnum, void *parm_ptr,
    1541             :                          const char *pszParmName, const char *pszParmValue)
    1542             : {
    1543             :         size_t i;
    1544             : 
    1545             :         /* switch on the type of variable it is */
    1546     3754630 :         switch (parm_table[parmnum].type)
    1547             :         {
    1548     2125779 :                 case P_BOOL: {
    1549             :                         bool b;
    1550     1189445 :                         if (!set_boolean(pszParmValue, &b)) {
    1551           0 :                                 DEBUG(0, ("set_variable_helper(%s): value is not "
    1552             :                                           "boolean!\n", pszParmValue));
    1553           0 :                                 return false;
    1554             :                         }
    1555     1189445 :                         *(bool *)parm_ptr = b;
    1556             :                         }
    1557     1189445 :                         break;
    1558             : 
    1559        3930 :                 case P_BOOLREV: {
    1560             :                         bool b;
    1561        2606 :                         if (!set_boolean(pszParmValue, &b)) {
    1562           0 :                                 DEBUG(0, ("set_variable_helper(%s): value is not "
    1563             :                                           "boolean!\n", pszParmValue));
    1564           0 :                                 return false;
    1565             :                         }
    1566        2606 :                         *(bool *)parm_ptr = !b;
    1567             :                         }
    1568        2606 :                         break;
    1569             : 
    1570      469976 :                 case P_INTEGER:
    1571      469976 :                         *(int *)parm_ptr = lp_int(pszParmValue);
    1572      469976 :                         break;
    1573             : 
    1574        8478 :                 case P_CHAR:
    1575        8478 :                         *(char *)parm_ptr = *pszParmValue;
    1576        8478 :                         break;
    1577             : 
    1578       61368 :                 case P_OCTAL:
    1579       61368 :                         i = sscanf(pszParmValue, "%o", (int *)parm_ptr);
    1580       61368 :                         if ( i != 1 ) {
    1581           0 :                                 DEBUG ( 0, ("Invalid octal number %s\n", pszParmName ));
    1582           0 :                                 return false;
    1583             :                         }
    1584       61368 :                         break;
    1585             : 
    1586       80070 :                 case P_BYTES:
    1587             :                 {
    1588             :                         uint64_t val;
    1589       80070 :                         if (conv_str_size_error(pszParmValue, &val)) {
    1590       80070 :                                 if (val <= INT_MAX) {
    1591       80070 :                                         *(int *)parm_ptr = (int)val;
    1592       80070 :                                         break;
    1593             :                                 }
    1594             :                         }
    1595             : 
    1596           0 :                         DEBUG(0, ("set_variable_helper(%s): value is not "
    1597             :                                   "a valid size specifier!\n", pszParmValue));
    1598           0 :                         return false;
    1599             :                 }
    1600             : 
    1601      283168 :                 case P_CMDLIST:
    1602      283168 :                         TALLOC_FREE(*(char ***)parm_ptr);
    1603      283168 :                         *(char ***)parm_ptr = str_list_make_v3(mem_ctx,
    1604             :                                                         pszParmValue, NULL);
    1605      283168 :                         break;
    1606             : 
    1607      129291 :                 case P_LIST:
    1608             :                 {
    1609      129291 :                         char **new_list = str_list_make_v3(mem_ctx,
    1610             :                                                         pszParmValue, NULL);
    1611      129291 :                         if (new_list == NULL) {
    1612           3 :                                 break;
    1613             :                         }
    1614             : 
    1615      195866 :                         for (i=0; new_list[i]; i++) {
    1616      261206 :                                 if (*(const char ***)parm_ptr != NULL &&
    1617      145756 :                                     new_list[i][0] == '+' &&
    1618       49818 :                                     new_list[i][1])
    1619             :                                 {
    1620       92769 :                                         if (!str_list_check(*(const char ***)parm_ptr,
    1621       49818 :                                                             &new_list[i][1])) {
    1622       23093 :                                                 *(const char ***)parm_ptr = str_list_add(*(const char ***)parm_ptr,
    1623       23093 :                                                                                          &new_list[i][1]);
    1624             :                                         }
    1625      168437 :                                 } else if (*(const char ***)parm_ptr != NULL &&
    1626       67850 :                                            new_list[i][0] == '-' &&
    1627       16760 :                                            new_list[i][1])
    1628             :                                 {
    1629       16760 :                                         str_list_remove(*(const char ***)parm_ptr,
    1630       16760 :                                                         &new_list[i][1]);
    1631             :                                 } else {
    1632      105500 :                                         if (i != 0) {
    1633           0 :                                                 DEBUG(0, ("Unsupported list syntax for: %s = %s\n",
    1634             :                                                           pszParmName, pszParmValue));
    1635           0 :                                                 return false;
    1636             :                                         }
    1637      105500 :                                         *(char ***)parm_ptr = new_list;
    1638      105500 :                                         break;
    1639             :                                 }
    1640             :                         }
    1641      129288 :                         break;
    1642             :                 }
    1643             : 
    1644      985035 :                 case P_STRING:
    1645      985035 :                         lpcfg_string_set(mem_ctx, (char **)parm_ptr, pszParmValue);
    1646      985035 :                         break;
    1647             : 
    1648       67036 :                 case P_USTRING:
    1649       67036 :                         lpcfg_string_set_upper(mem_ctx, (char **)parm_ptr, pszParmValue);
    1650       67036 :                         break;
    1651             : 
    1652      478157 :                 case P_ENUM:
    1653      478157 :                         if (!lp_set_enum_parm(&parm_table[parmnum], pszParmValue, (int*)parm_ptr)) {
    1654           0 :                                 return false;
    1655             :                         }
    1656      478157 :                         break;
    1657             : 
    1658             :         }
    1659             : 
    1660     3754630 :         return true;
    1661             : 
    1662             : }
    1663             : 
    1664        8472 : bool handle_name_resolve_order(struct loadparm_context *lp_ctx,
    1665             :                                struct loadparm_service *service,
    1666             :                                const char *pszParmValue, char **ptr)
    1667             : {
    1668        8472 :         const char **valid_values = NULL;
    1669        8472 :         const char **values_to_set = NULL;
    1670             :         int i;
    1671        8472 :         bool value_is_valid = false;
    1672        8472 :         valid_values = str_list_make_v3_const(NULL,
    1673             :                                               DEFAULT_NAME_RESOLVE_ORDER,
    1674             :                                               NULL);
    1675        8472 :         if (valid_values == NULL) {
    1676           0 :                 DBG_ERR("OOM: failed to make string list from %s\n",
    1677             :                         DEFAULT_NAME_RESOLVE_ORDER);
    1678           0 :                 goto out;
    1679             :         }
    1680        8472 :         values_to_set = str_list_make_v3_const(lp_ctx->globals->ctx,
    1681             :                                                pszParmValue,
    1682             :                                                NULL);
    1683        8472 :         if (values_to_set == NULL) {
    1684           0 :                 DBG_ERR("OOM: failed to make string list from %s\n",
    1685             :                         pszParmValue);
    1686           0 :                 goto out;
    1687             :         }
    1688        8472 :         TALLOC_FREE(lp_ctx->globals->name_resolve_order);
    1689       42360 :         for (i = 0; values_to_set[i] != NULL; i++) {
    1690       33888 :                 value_is_valid = str_list_check(valid_values, values_to_set[i]);
    1691       33888 :                 if (!value_is_valid) {
    1692           0 :                         DBG_ERR("WARNING: Ignoring invalid list value '%s' "
    1693             :                                 "for parameter 'name resolve order'\n",
    1694             :                                 values_to_set[i]);
    1695           0 :                         break;
    1696             :                 }
    1697             :         }
    1698        8472 : out:
    1699        8472 :         if (value_is_valid) {
    1700        8472 :                 lp_ctx->globals->name_resolve_order = values_to_set;
    1701             :         } else {
    1702           0 :                 TALLOC_FREE(values_to_set);
    1703             :         }
    1704        8472 :         TALLOC_FREE(valid_values);
    1705        8472 :         return value_is_valid;
    1706             : }
    1707             : 
    1708           9 : bool handle_kdc_default_domain_supported_enctypes(struct loadparm_context *lp_ctx,
    1709             :                                                   struct loadparm_service *service,
    1710             :                                                   const char *pszParmValue, char **ptr)
    1711             : {
    1712           9 :         char **enctype_list = NULL;
    1713           9 :         char **enctype = NULL;
    1714           9 :         uint32_t result = 0;
    1715           9 :         bool ok = true;
    1716             : 
    1717           9 :         enctype_list = str_list_make(NULL, pszParmValue, NULL);
    1718           9 :         if (enctype_list == NULL) {
    1719           0 :                 DBG_ERR("OOM: failed to make string list from %s\n",
    1720             :                         pszParmValue);
    1721           0 :                 ok = false;
    1722           0 :                 goto out;
    1723             :         }
    1724             : 
    1725          18 :         for (enctype = enctype_list; *enctype != NULL; ++enctype) {
    1726          18 :                 if (strwicmp(*enctype, "arcfour-hmac-md5") == 0 ||
    1727           9 :                     strwicmp(*enctype, "rc4-hmac") == 0)
    1728             :                 {
    1729           0 :                         result |= KERB_ENCTYPE_RC4_HMAC_MD5;
    1730             :                 }
    1731          18 :                 else if (strwicmp(*enctype, "aes128-cts-hmac-sha1-96") == 0 ||
    1732           9 :                          strwicmp(*enctype, "aes128-cts") == 0)
    1733             :                 {
    1734           0 :                         result |= KERB_ENCTYPE_AES128_CTS_HMAC_SHA1_96;
    1735             :                 }
    1736          18 :                 else if (strwicmp(*enctype, "aes256-cts-hmac-sha1-96") == 0 ||
    1737           9 :                          strwicmp(*enctype, "aes256-cts") == 0)
    1738             :                 {
    1739           0 :                         result |= KERB_ENCTYPE_AES256_CTS_HMAC_SHA1_96;
    1740             :                 }
    1741          18 :                 else if (strwicmp(*enctype, "aes256-cts-hmac-sha1-96-sk") == 0 ||
    1742           9 :                          strwicmp(*enctype, "aes256-cts-sk") == 0)
    1743             :                 {
    1744           0 :                         result |= KERB_ENCTYPE_AES256_CTS_HMAC_SHA1_96_SK;
    1745             :                 }
    1746             :                 else {
    1747           9 :                         const char *bitstr = *enctype;
    1748             :                         int base;
    1749             :                         int error;
    1750             :                         unsigned long bit;
    1751             : 
    1752             :                         /* See if the bit's specified in hexadecimal. */
    1753          12 :                         if (bitstr[0] == '0' &&
    1754           6 :                             (bitstr[1] == 'x' || bitstr[2] == 'X'))
    1755             :                         {
    1756           0 :                                 base = 16;
    1757           0 :                                 bitstr += 2;
    1758             :                         }
    1759             :                         else {
    1760           9 :                                 base = 10;
    1761             :                         }
    1762             : 
    1763           9 :                         bit = smb_strtoul(bitstr, NULL, base, &error, SMB_STR_FULL_STR_CONV);
    1764           9 :                         if (error) {
    1765           0 :                                 DBG_ERR("WARNING: Ignoring invalid value '%s' "
    1766             :                                         "for parameter 'kdc default domain supported enctypes'\n",
    1767             :                                         *enctype);
    1768           0 :                                 ok = false;
    1769             :                         } else {
    1770           9 :                                 result |= bit;
    1771             :                         }
    1772             :                 }
    1773             :         }
    1774             : 
    1775           9 :         *(int *)ptr = result;
    1776           9 : out:
    1777           9 :         TALLOC_FREE(enctype_list);
    1778             : 
    1779           9 :         return ok;
    1780             : }
    1781             : 
    1782           9 : bool handle_kdc_supported_enctypes(struct loadparm_context *lp_ctx,
    1783             :                                    struct loadparm_service *service,
    1784             :                                    const char *pszParmValue, char **ptr)
    1785             : {
    1786           9 :         char **enctype_list = NULL;
    1787           9 :         char **enctype = NULL;
    1788           9 :         uint32_t result = 0;
    1789           9 :         bool ok = true;
    1790             : 
    1791           9 :         enctype_list = str_list_make(NULL, pszParmValue, NULL);
    1792           9 :         if (enctype_list == NULL) {
    1793           0 :                 DBG_ERR("OOM: failed to make string list from %s\n",
    1794             :                         pszParmValue);
    1795           0 :                 ok = false;
    1796           0 :                 goto out;
    1797             :         }
    1798             : 
    1799          18 :         for (enctype = enctype_list; *enctype != NULL; ++enctype) {
    1800          18 :                 if (strwicmp(*enctype, "arcfour-hmac-md5") == 0 ||
    1801           9 :                     strwicmp(*enctype, "rc4-hmac") == 0)
    1802             :                 {
    1803           0 :                         result |= KERB_ENCTYPE_RC4_HMAC_MD5;
    1804             :                 }
    1805          18 :                 else if (strwicmp(*enctype, "aes128-cts-hmac-sha1-96") == 0 ||
    1806           9 :                          strwicmp(*enctype, "aes128-cts") == 0)
    1807             :                 {
    1808           0 :                         result |= KERB_ENCTYPE_AES128_CTS_HMAC_SHA1_96;
    1809             :                 }
    1810          18 :                 else if (strwicmp(*enctype, "aes256-cts-hmac-sha1-96") == 0 ||
    1811           9 :                          strwicmp(*enctype, "aes256-cts") == 0)
    1812             :                 {
    1813           0 :                         result |= KERB_ENCTYPE_AES256_CTS_HMAC_SHA1_96;
    1814             :                 }
    1815             :                 else {
    1816           9 :                         const char *bitstr = *enctype;
    1817             :                         int base;
    1818             :                         int error;
    1819             :                         unsigned long bit;
    1820             : 
    1821             :                         /* See if the bit's specified in hexadecimal. */
    1822          12 :                         if (bitstr[0] == '0' &&
    1823           6 :                             (bitstr[1] == 'x' || bitstr[2] == 'X'))
    1824             :                         {
    1825           0 :                                 base = 16;
    1826           0 :                                 bitstr += 2;
    1827             :                         }
    1828             :                         else {
    1829           9 :                                 base = 10;
    1830             :                         }
    1831             : 
    1832           9 :                         bit = smb_strtoul(bitstr, NULL, base, &error, SMB_STR_FULL_STR_CONV);
    1833           9 :                         if (error) {
    1834           0 :                                 DBG_ERR("WARNING: Ignoring invalid value '%s' "
    1835             :                                         "for parameter 'kdc default domain supported enctypes'\n",
    1836             :                                         *enctype);
    1837           0 :                                 ok = false;
    1838             :                         } else {
    1839           9 :                                 result |= bit;
    1840             :                         }
    1841             :                 }
    1842             :         }
    1843             : 
    1844           9 :         *(int *)ptr = result;
    1845           9 : out:
    1846           9 :         TALLOC_FREE(enctype_list);
    1847             : 
    1848           9 :         return ok;
    1849             : }
    1850             : 
    1851     4011263 : static bool set_variable(TALLOC_CTX *mem_ctx, struct loadparm_service *service,
    1852             :                          int parmnum, void *parm_ptr,
    1853             :                          const char *pszParmName, const char *pszParmValue,
    1854             :                          struct loadparm_context *lp_ctx, bool on_globals)
    1855             : {
    1856             :         int i;
    1857             :         bool ok;
    1858             : 
    1859             :         /* if it is a special case then go ahead */
    1860     4011263 :         if (parm_table[parmnum].special) {
    1861      273577 :                 ok = parm_table[parmnum].special(lp_ctx, service, pszParmValue,
    1862             :                                                   (char **)parm_ptr);
    1863             :         } else {
    1864     3737686 :                 ok = set_variable_helper(mem_ctx, parmnum, parm_ptr,
    1865             :                                          pszParmName, pszParmValue);
    1866             :         }
    1867             : 
    1868     4011263 :         if (!ok) {
    1869           3 :                 return false;
    1870             :         }
    1871             : 
    1872     4011260 :         if (on_globals && (lp_ctx->flags[parmnum] & FLAG_DEFAULT)) {
    1873      245666 :                 lp_ctx->flags[parmnum] &= ~FLAG_DEFAULT;
    1874             :                 /* we have to also unset FLAG_DEFAULT on aliases */
    1875      251359 :                 for (i=parmnum-1;i>=0 && parm_table[i].offset == parm_table[parmnum].offset;i--) {
    1876        5693 :                         lp_ctx->flags[i] &= ~FLAG_DEFAULT;
    1877             :                 }
    1878      281560 :                 for (i=parmnum+1;i<num_parameters() && parm_table[i].offset == parm_table[parmnum].offset;i++) {
    1879       35894 :                         lp_ctx->flags[i] &= ~FLAG_DEFAULT;
    1880             :                 }
    1881             :         }
    1882     4011260 :         return true;
    1883             : }
    1884             : 
    1885             : 
    1886     3642874 : bool lpcfg_do_global_parameter(struct loadparm_context *lp_ctx,
    1887             :                                const char *pszParmName, const char *pszParmValue)
    1888             : {
    1889     3642874 :         int parmnum = lpcfg_map_parameter(pszParmName);
    1890             :         void *parm_ptr;
    1891             : 
    1892     3642874 :         if (parmnum < 0) {
    1893      509914 :                 if (strchr(pszParmName, ':')) {
    1894      509914 :                         return lp_do_parameter_parametric(lp_ctx, NULL, pszParmName, pszParmValue, 0);
    1895             :                 }
    1896           0 :                 DEBUG(0, ("Ignoring unknown parameter \"%s\"\n", pszParmName));
    1897           0 :                 return true;
    1898             :         }
    1899             : 
    1900             :         /* if the flag has been set on the command line, then don't allow override,
    1901             :            but don't report an error */
    1902     3132960 :         if (lp_ctx->flags[parmnum] & FLAG_CMDLINE) {
    1903        8559 :                 return true;
    1904             :         }
    1905             : 
    1906     3124401 :         if (parm_table[parmnum].flags & FLAG_DEPRECATED) {
    1907      211432 :                 char *suppress_env = getenv("SAMBA_DEPRECATED_SUPPRESS");
    1908      211432 :                 bool print_warning = (suppress_env == NULL
    1909      211432 :                                       || suppress_env[0] == '\0');
    1910      211432 :                 if (print_warning) {
    1911           0 :                         DBG_WARNING("WARNING: The \"%s\" option "
    1912             :                                     "is deprecated\n",
    1913             :                                     pszParmName);
    1914             : 
    1915             :                 }
    1916             :         }
    1917             : 
    1918     3124401 :         parm_ptr = lpcfg_parm_ptr(lp_ctx, NULL, &parm_table[parmnum]);
    1919             : 
    1920     3124401 :         return set_variable(lp_ctx->globals->ctx, NULL, parmnum, parm_ptr,
    1921             :                             pszParmName, pszParmValue, lp_ctx, true);
    1922             : }
    1923             : 
    1924     1265733 : bool lpcfg_do_service_parameter(struct loadparm_context *lp_ctx,
    1925             :                                 struct loadparm_service *service,
    1926             :                                 const char *pszParmName, const char *pszParmValue)
    1927             : {
    1928             :         void *parm_ptr;
    1929             :         int i;
    1930     1265733 :         int parmnum = lpcfg_map_parameter(pszParmName);
    1931             : 
    1932     1265733 :         if (parmnum < 0) {
    1933      378867 :                 if (strchr(pszParmName, ':')) {
    1934      378867 :                         return lp_do_parameter_parametric(lp_ctx, service, pszParmName, pszParmValue, 0);
    1935             :                 }
    1936           0 :                 DEBUG(0, ("Ignoring unknown parameter \"%s\"\n", pszParmName));
    1937           0 :                 return true;
    1938             :         }
    1939             : 
    1940             :         /* if the flag has been set on the command line, then don't allow override,
    1941             :            but don't report an error */
    1942      886866 :         if (lp_ctx->flags[parmnum] & FLAG_CMDLINE) {
    1943           4 :                 return true;
    1944             :         }
    1945             : 
    1946      886862 :         if (parm_table[parmnum].flags & FLAG_DEPRECATED) {
    1947           0 :                 char *suppress_env = getenv("SAMBA_DEPRECATED_SUPPRESS");
    1948           0 :                 bool print_warning = (suppress_env == NULL
    1949           0 :                                       || suppress_env[0] == '\0');
    1950           0 :                 if (print_warning) {
    1951           0 :                         DBG_WARNING("WARNING: The \"%s\" option "
    1952             :                                     "is deprecated\n",
    1953             :                                     pszParmName);
    1954             : 
    1955             :                 }
    1956             :         }
    1957             : 
    1958      886862 :         if (parm_table[parmnum].p_class == P_GLOBAL) {
    1959           0 :                 DEBUG(0,
    1960             :                       ("Global parameter %s found in service section!\n",
    1961             :                        pszParmName));
    1962           0 :                 return true;
    1963             :         }
    1964      886862 :         parm_ptr = ((char *)service) + parm_table[parmnum].offset;
    1965             : 
    1966      886862 :         if (!service->copymap)
    1967           0 :                 init_copymap(service);
    1968             : 
    1969             :         /* this handles the aliases - set the copymap for other
    1970             :          * entries with the same data pointer */
    1971   457620792 :         for (i = 0; parm_table[i].label; i++)
    1972   458329185 :                 if (parm_table[i].offset == parm_table[parmnum].offset &&
    1973     2398636 :                     parm_table[i].p_class == parm_table[parmnum].p_class)
    1974     1596905 :                         bitmap_clear(service->copymap, i);
    1975             : 
    1976      886862 :         return set_variable(service, service, parmnum, parm_ptr, pszParmName,
    1977             :                             pszParmValue, lp_ctx, false);
    1978             : }
    1979             : 
    1980             : /**
    1981             :  * Process a parameter.
    1982             :  */
    1983             : 
    1984     1503167 : bool lpcfg_do_parameter(const char *pszParmName, const char *pszParmValue,
    1985             :                          void *userdata)
    1986             : {
    1987     1503167 :         struct loadparm_context *lp_ctx = (struct loadparm_context *)userdata;
    1988             : 
    1989     1503167 :         if (lp_ctx->bInGlobalSection)
    1990     1016300 :                 return lpcfg_do_global_parameter(lp_ctx, pszParmName,
    1991             :                                               pszParmValue);
    1992             :         else
    1993      486867 :                 return lpcfg_do_service_parameter(lp_ctx, lp_ctx->currentService,
    1994             :                                                   pszParmName, pszParmValue);
    1995             : }
    1996             : 
    1997             : /*
    1998             :   variable argument do parameter
    1999             : */
    2000             : bool lpcfg_do_global_parameter_var(struct loadparm_context *lp_ctx, const char *pszParmName, const char *fmt, ...) PRINTF_ATTRIBUTE(3, 4);
    2001      128526 : bool lpcfg_do_global_parameter_var(struct loadparm_context *lp_ctx,
    2002             :                                 const char *pszParmName, const char *fmt, ...)
    2003             : {
    2004             :         char *s;
    2005             :         bool ret;
    2006             :         va_list ap;
    2007             : 
    2008      128526 :         va_start(ap, fmt);
    2009      128526 :         s = talloc_vasprintf(NULL, fmt, ap);
    2010      128526 :         va_end(ap);
    2011      128526 :         ret = lpcfg_do_global_parameter(lp_ctx, pszParmName, s);
    2012      128526 :         talloc_free(s);
    2013      128526 :         return ret;
    2014             : }
    2015             : 
    2016             : 
    2017             : /*
    2018             :   set a parameter from the commandline - this is called from command line parameter
    2019             :   parsing code. It sets the parameter then marks the parameter as unable to be modified
    2020             :   by smb.conf processing
    2021             : */
    2022       22589 : bool lpcfg_set_cmdline(struct loadparm_context *lp_ctx, const char *pszParmName,
    2023             :                        const char *pszParmValue)
    2024             : {
    2025             :         int parmnum;
    2026             :         int i;
    2027             : 
    2028       22589 :         while (isspace((unsigned char)*pszParmValue)) pszParmValue++;
    2029             : 
    2030       22589 :         parmnum = lpcfg_map_parameter(pszParmName);
    2031             : 
    2032       22589 :         if (parmnum < 0 && strchr(pszParmName, ':')) {
    2033             :                 /* set a parametric option */
    2034             :                 bool ok;
    2035       12084 :                 ok = lp_do_parameter_parametric(lp_ctx, NULL, pszParmName,
    2036             :                                                 pszParmValue, FLAG_CMDLINE);
    2037       12084 :                 if (lp_ctx->s3_fns != NULL) {
    2038         180 :                         if (ok) {
    2039         180 :                                 lp_ctx->s3_fns->store_cmdline(pszParmName, pszParmValue);
    2040             :                         }
    2041             :                 }
    2042       12084 :                 return ok;
    2043             :         }
    2044             : 
    2045       10505 :         if (parmnum < 0) {
    2046           0 :                 DEBUG(0,("Unknown option '%s'\n", pszParmName));
    2047           0 :                 return false;
    2048             :         }
    2049             : 
    2050             :         /* reset the CMDLINE flag in case this has been called before */
    2051       10505 :         lp_ctx->flags[parmnum] &= ~FLAG_CMDLINE;
    2052             : 
    2053       10505 :         if (!lpcfg_do_global_parameter(lp_ctx, pszParmName, pszParmValue)) {
    2054           3 :                 return false;
    2055             :         }
    2056             : 
    2057       10502 :         lp_ctx->flags[parmnum] |= FLAG_CMDLINE;
    2058             : 
    2059             :         /* we have to also set FLAG_CMDLINE on aliases */
    2060       19371 :         for (i=parmnum-1;
    2061       18710 :              i>=0 && parm_table[i].p_class == parm_table[parmnum].p_class &&
    2062        9843 :              parm_table[i].offset == parm_table[parmnum].offset;
    2063         225 :              i--) {
    2064         225 :                 lp_ctx->flags[i] |= FLAG_CMDLINE;
    2065             :         }
    2066       23003 :         for (i=parmnum+1;
    2067       27935 :              i<num_parameters() &&
    2068       25995 :              parm_table[i].p_class == parm_table[parmnum].p_class &&
    2069       13264 :              parm_table[i].offset == parm_table[parmnum].offset;
    2070        4932 :              i++) {
    2071        4932 :                 lp_ctx->flags[i] |= FLAG_CMDLINE;
    2072             :         }
    2073             : 
    2074       10502 :         if (lp_ctx->s3_fns != NULL) {
    2075        6757 :                 lp_ctx->s3_fns->store_cmdline(pszParmName, pszParmValue);
    2076             :         }
    2077             : 
    2078       10502 :         return true;
    2079             : }
    2080             : 
    2081             : /*
    2082             :   set a option from the commandline in 'a=b' format. Use to support --option
    2083             : */
    2084        4866 : bool lpcfg_set_option(struct loadparm_context *lp_ctx, const char *option)
    2085             : {
    2086             :         char *p, *s;
    2087             :         bool ret;
    2088             : 
    2089        4866 :         s = talloc_strdup(NULL, option);
    2090        4866 :         if (!s) {
    2091           0 :                 return false;
    2092             :         }
    2093             : 
    2094        4866 :         p = strchr(s, '=');
    2095        4866 :         if (!p) {
    2096           0 :                 talloc_free(s);
    2097           0 :                 return false;
    2098             :         }
    2099             : 
    2100        4866 :         *p = 0;
    2101             : 
    2102        4866 :         ret = lpcfg_set_cmdline(lp_ctx, s, p+1);
    2103        4866 :         talloc_free(s);
    2104        4866 :         return ret;
    2105             : }
    2106             : 
    2107             : 
    2108             : #define BOOLSTR(b) ((b) ? "Yes" : "No")
    2109             : 
    2110             : /**
    2111             :  * Print a parameter of the specified type.
    2112             :  */
    2113             : 
    2114       40405 : void lpcfg_print_parameter(struct parm_struct *p, void *ptr, FILE * f)
    2115             : {
    2116             :         /* For the seperation of lists values that we print below */
    2117       40405 :         const char *list_sep = ", ";
    2118             :         int i;
    2119       40405 :         switch (p->type)
    2120             :         {
    2121        3524 :                 case P_ENUM:
    2122       14632 :                         for (i = 0; p->enum_list[i].name; i++) {
    2123       14632 :                                 if (*(int *)ptr == p->enum_list[i].value) {
    2124        3524 :                                         fprintf(f, "%s",
    2125        3524 :                                                 p->enum_list[i].name);
    2126        3524 :                                         break;
    2127             :                                 }
    2128             :                         }
    2129        3524 :                         break;
    2130             : 
    2131       12586 :                 case P_BOOL:
    2132       12586 :                         fprintf(f, "%s", BOOLSTR(*(bool *)ptr));
    2133       12586 :                         break;
    2134             : 
    2135          12 :                 case P_BOOLREV:
    2136          12 :                         fprintf(f, "%s", BOOLSTR(!*(bool *)ptr));
    2137          12 :                         break;
    2138             : 
    2139        5289 :                 case P_INTEGER:
    2140             :                 case P_BYTES:
    2141        5289 :                         fprintf(f, "%d", *(int *)ptr);
    2142        5289 :                         break;
    2143             : 
    2144          61 :                 case P_CHAR:
    2145          61 :                         fprintf(f, "%c", *(char *)ptr);
    2146          61 :                         break;
    2147             : 
    2148         645 :                 case P_OCTAL: {
    2149         645 :                         int val = *(int *)ptr; 
    2150         645 :                         if (val == -1) {
    2151           0 :                                 fprintf(f, "-1");
    2152             :                         } else {
    2153         645 :                                 fprintf(f, "0%03o", val);
    2154             :                         }
    2155         645 :                         break;
    2156             :                 }
    2157             : 
    2158        2934 :                 case P_CMDLIST:
    2159        2934 :                         list_sep = " ";
    2160             : 
    2161             :                         FALL_THROUGH;
    2162        4052 :                 case P_LIST:
    2163        4052 :                         if ((char ***)ptr && *(char ***)ptr) {
    2164        2823 :                                 char **list = *(char ***)ptr;
    2165       14470 :                                 for (; *list; list++) {
    2166             :                                         /* surround strings with whitespace in double quotes */
    2167       11647 :                                         if (*(list+1) == NULL) {
    2168             :                                                 /* last item, no extra separator */
    2169        2823 :                                                 list_sep = "";
    2170             :                                         }
    2171       11647 :                                         if ( strchr_m( *list, ' ' ) ) {
    2172          24 :                                                 fprintf(f, "\"%s\"%s", *list, list_sep);
    2173             :                                         } else {
    2174       11623 :                                                 fprintf(f, "%s%s", *list, list_sep);
    2175             :                                         }
    2176             :                                 }
    2177             :                         }
    2178        4052 :                         break;
    2179             : 
    2180       14236 :                 case P_STRING:
    2181             :                 case P_USTRING:
    2182       14236 :                         if (*(char **)ptr) {
    2183       14236 :                                 fprintf(f, "%s", *(char **)ptr);
    2184             :                         }
    2185       14236 :                         break;
    2186             :         }
    2187       40405 : }
    2188             : 
    2189             : /**
    2190             :  * Check if two parameters are equal.
    2191             :  */
    2192             : 
    2193      331951 : static bool lpcfg_equal_parameter(parm_type type, void *ptr1, void *ptr2)
    2194             : {
    2195      331951 :         switch (type) {
    2196      164764 :                 case P_BOOL:
    2197             :                 case P_BOOLREV:
    2198      164764 :                         return (*((bool *)ptr1) == *((bool *)ptr2));
    2199             : 
    2200       67844 :                 case P_INTEGER:
    2201             :                 case P_ENUM:
    2202             :                 case P_OCTAL:
    2203             :                 case P_BYTES:
    2204       67844 :                         return (*((int *)ptr1) == *((int *)ptr2));
    2205             : 
    2206        2423 :                 case P_CHAR:
    2207        2423 :                         return (*((char *)ptr1) == *((char *)ptr2));
    2208             : 
    2209       21807 :                 case P_LIST:
    2210             :                 case P_CMDLIST:
    2211       21807 :                         return str_list_equal(*(const char ***)ptr1, *(const char ***)ptr2);
    2212             : 
    2213       75113 :                 case P_STRING:
    2214             :                 case P_USTRING:
    2215             :                 {
    2216       75113 :                         char *p1 = *(char **)ptr1, *p2 = *(char **)ptr2;
    2217       75113 :                         if (p1 && !*p1)
    2218       53862 :                                 p1 = NULL;
    2219       75113 :                         if (p2 && !*p2)
    2220       57409 :                                 p2 = NULL;
    2221       75113 :                         return (p1 == p2 || strequal(p1, p2));
    2222             :                 }
    2223             :         }
    2224           0 :         return false;
    2225             : }
    2226             : 
    2227             : /**
    2228             :  * Process a new section (service).
    2229             :  *
    2230             :  * At this stage all sections are services.
    2231             :  * Later we'll have special sections that permit server parameters to be set.
    2232             :  * Returns True on success, False on failure.
    2233             :  */
    2234             : 
    2235      148750 : static bool do_section(const char *pszSectionName, void *userdata)
    2236             : {
    2237      148750 :         struct loadparm_context *lp_ctx = (struct loadparm_context *)userdata;
    2238             :         bool bRetval;
    2239             :         bool isglobal;
    2240             : 
    2241      148750 :         if (lp_ctx->s3_fns != NULL) {
    2242           0 :                 return lp_ctx->s3_fns->do_section(pszSectionName, lp_ctx);
    2243             :         }
    2244             : 
    2245      280297 :         isglobal = ((strwicmp(pszSectionName, GLOBAL_NAME) == 0) ||
    2246      131547 :                          (strwicmp(pszSectionName, GLOBAL_NAME2) == 0));
    2247             : 
    2248             :         /* if we've just struck a global section, note the fact. */
    2249      148750 :         lp_ctx->bInGlobalSection = isglobal;
    2250             : 
    2251             :         /* check for multiple global sections */
    2252      148750 :         if (lp_ctx->bInGlobalSection) {
    2253       17342 :                 DEBUG(4, ("Processing section \"[%s]\"\n", pszSectionName));
    2254       17342 :                 bRetval = true;
    2255       17342 :                 goto out;
    2256             :         }
    2257             : 
    2258             :         /* if we have a current service, tidy it up before moving on */
    2259      131408 :         bRetval = true;
    2260             : 
    2261      131408 :         if (lp_ctx->currentService != NULL)
    2262      120415 :                 bRetval = lpcfg_service_ok(lp_ctx->currentService);
    2263             : 
    2264             :         /* if all is still well, move to the next record in the services array */
    2265      131408 :         if (bRetval) {
    2266             :                 /* We put this here to avoid an odd message order if messages are */
    2267             :                 /* issued by the post-processing of a previous section. */
    2268      131408 :                 DEBUG(4, ("Processing section \"[%s]\"\n", pszSectionName));
    2269             : 
    2270      131408 :                 if ((lp_ctx->currentService = lpcfg_add_service(lp_ctx, lp_ctx->sDefault,
    2271             :                                                                    pszSectionName))
    2272             :                     == NULL) {
    2273           0 :                         DEBUG(0, ("Failed to add a new service\n"));
    2274           0 :                         bRetval = false;
    2275           0 :                         goto out;
    2276             :                 }
    2277             :         }
    2278      257511 : out:
    2279      148750 :         return bRetval;
    2280             : }
    2281             : 
    2282             : 
    2283             : /**
    2284             :  * Determine if a particular base parameter is currently set to the default value.
    2285             :  */
    2286             : 
    2287        7523 : static bool is_default(void *base_structure, int i)
    2288             : {
    2289        7523 :         void *def_ptr = ((char *)base_structure) + parm_table[i].offset;
    2290        7523 :         switch (parm_table[i].type) {
    2291        1026 :                 case P_CMDLIST:
    2292             :                 case P_LIST:
    2293        1026 :                         return str_list_equal((const char * const *)parm_table[i].def.lvalue,
    2294             :                                               *(const char * const **)def_ptr);
    2295        3783 :                 case P_STRING:
    2296             :                 case P_USTRING:
    2297        3783 :                         return strequal(parm_table[i].def.svalue,
    2298             :                                         *(char **)def_ptr);
    2299        1414 :                 case P_BOOL:
    2300             :                 case P_BOOLREV:
    2301        2755 :                         return parm_table[i].def.bvalue ==
    2302        1414 :                                 *(bool *)def_ptr;
    2303        1300 :                 case P_INTEGER:
    2304             :                 case P_CHAR:
    2305             :                 case P_OCTAL:
    2306             :                 case P_BYTES:
    2307             :                 case P_ENUM:
    2308        2564 :                         return parm_table[i].def.ivalue ==
    2309        1300 :                                 *(int *)def_ptr;
    2310             :         }
    2311           0 :         return false;
    2312             : }
    2313             : 
    2314             : /**
    2315             :  *Display the contents of the global structure.
    2316             :  */
    2317             : 
    2318        1134 : void lpcfg_dump_globals(struct loadparm_context *lp_ctx, FILE *f,
    2319             :                          bool show_defaults)
    2320             : {
    2321             :         int i;
    2322             :         struct parmlist_entry *data;
    2323             : 
    2324        1134 :         fprintf(f, "# Global parameters\n[global]\n");
    2325             : 
    2326      585144 :         for (i = 0; parm_table[i].label; i++) {
    2327      584010 :                 if (parm_table[i].p_class != P_GLOBAL) {
    2328      176904 :                         continue;
    2329             :                 }
    2330             : 
    2331      407106 :                 if (parm_table[i].flags & FLAG_SYNONYM) {
    2332       22680 :                         continue;
    2333             :                 }
    2334             : 
    2335      384426 :                 if (!show_defaults) {
    2336      366459 :                         if (lp_ctx->flags && (lp_ctx->flags[i] & FLAG_DEFAULT)) {
    2337      359976 :                                 continue;
    2338             :                         }
    2339             : 
    2340        6483 :                         if (is_default(lp_ctx->globals, i)) {
    2341        1029 :                                 continue;
    2342             :                         }
    2343             :                 }
    2344             : 
    2345       23421 :                 fprintf(f, "\t%s = ", parm_table[i].label);
    2346       23421 :                 lpcfg_print_parameter(&parm_table[i], lpcfg_parm_ptr(lp_ctx, NULL, &parm_table[i]), f);
    2347       23421 :                 fprintf(f, "\n");
    2348             :         }
    2349        1134 :         if (lp_ctx->globals->param_opt != NULL) {
    2350        9843 :                 for (data = lp_ctx->globals->param_opt; data;
    2351        7595 :                      data = data->next) {
    2352        7595 :                         if (!show_defaults && (data->priority & FLAG_DEFAULT)) {
    2353        1853 :                                 continue;
    2354             :                         }
    2355        5742 :                         fprintf(f, "\t%s = %s\n", data->key, data->value);
    2356             :                 }
    2357             :         }
    2358             : 
    2359        1134 : }
    2360             : 
    2361             : /**
    2362             :  * Display the contents of a single services record.
    2363             :  */
    2364             : 
    2365        3557 : void lpcfg_dump_a_service(struct loadparm_service * pService, struct loadparm_service *sDefault, FILE * f,
    2366             :                           unsigned int *flags, bool show_defaults)
    2367             : {
    2368             :         int i;
    2369             :         struct parmlist_entry *data;
    2370             : 
    2371        3557 :         if (pService != sDefault)
    2372        2423 :                 fprintf(f, "\n[%s]\n", pService->szService);
    2373             : 
    2374     1835412 :         for (i = 0; parm_table[i].label; i++) {
    2375     1831855 :                 if (parm_table[i].p_class != P_LOCAL) {
    2376     1276963 :                         continue;
    2377             :                 }
    2378             : 
    2379      554892 :                 if (parm_table[i].flags & FLAG_SYNONYM) {
    2380       64026 :                         continue;
    2381             :                 }
    2382             : 
    2383      490866 :                 if (*parm_table[i].label == '-') {
    2384        3557 :                         continue;
    2385             :                 }
    2386             : 
    2387      487309 :                 if (pService == sDefault) {
    2388      155358 :                         if (!show_defaults) {
    2389      148097 :                                 if (flags && (flags[i] & FLAG_DEFAULT)) {
    2390      147057 :                                         continue;
    2391             :                                 }
    2392             : 
    2393        1040 :                                 if (is_default(sDefault, i)) {
    2394         192 :                                         continue;
    2395             :                                 }
    2396             :                         }
    2397             :                 } else {
    2398             :                         bool equal;
    2399             : 
    2400      587319 :                         equal = lpcfg_equal_parameter(parm_table[i].type,
    2401             :                                                       ((char *)pService) +
    2402      331951 :                                                       parm_table[i].offset,
    2403             :                                                       ((char *)sDefault) +
    2404      331951 :                                                       parm_table[i].offset);
    2405      331951 :                         if (equal) {
    2406      325814 :                                 continue;
    2407             :                         }
    2408             :                 }
    2409             : 
    2410       14246 :                 fprintf(f, "\t%s = ", parm_table[i].label);
    2411       14246 :                 lpcfg_print_parameter(&parm_table[i],
    2412       14246 :                                 ((char *)pService) + parm_table[i].offset, f);
    2413       14246 :                 fprintf(f, "\n");
    2414             :         }
    2415        3557 :         if (pService->param_opt != NULL) {
    2416        5730 :                 for (data = pService->param_opt; data; data = data->next) {
    2417        4315 :                         if (!show_defaults && (data->priority & FLAG_DEFAULT)) {
    2418           0 :                                 continue;
    2419             :                         }
    2420        4315 :                         fprintf(f, "\t%s = %s\n", data->key, data->value);
    2421             :                 }
    2422             :         }
    2423        3557 : }
    2424             : 
    2425        2876 : bool lpcfg_dump_a_parameter(struct loadparm_context *lp_ctx,
    2426             :                             struct loadparm_service *service,
    2427             :                             const char *parm_name, FILE * f)
    2428             : {
    2429             :         struct parm_struct *parm;
    2430             :         void *ptr;
    2431             :         char *local_parm_name;
    2432             :         char *parm_opt;
    2433             :         const char *parm_opt_value;
    2434             : 
    2435             :         /* check for parametrical option */
    2436        2876 :         local_parm_name = talloc_strdup(lp_ctx, parm_name);
    2437        2876 :         if (local_parm_name == NULL) {
    2438           0 :                 return false;
    2439             :         }
    2440             : 
    2441        2876 :         parm_opt = strchr( local_parm_name, ':');
    2442             : 
    2443        2876 :         if (parm_opt) {
    2444         138 :                 *parm_opt = '\0';
    2445         138 :                 parm_opt++;
    2446         138 :                 if (strlen(parm_opt)) {
    2447         138 :                         parm_opt_value = lpcfg_parm_string(lp_ctx, service,
    2448             :                                 local_parm_name, parm_opt);
    2449         138 :                         if (parm_opt_value) {
    2450         138 :                                 fprintf(f, "%s\n", parm_opt_value);
    2451         138 :                                 TALLOC_FREE(local_parm_name);
    2452         138 :                                 return true;
    2453             :                         }
    2454             :                 }
    2455           0 :                 TALLOC_FREE(local_parm_name);
    2456           0 :                 return false;
    2457             :         }
    2458        2738 :         TALLOC_FREE(local_parm_name);
    2459             : 
    2460             :         /* parameter is not parametric, search the table */
    2461        2738 :         parm = lpcfg_parm_struct(lp_ctx, parm_name);
    2462        2738 :         if (!parm) {
    2463           0 :                 return false;
    2464             :         }
    2465             : 
    2466        2738 :         if (service != NULL && parm->p_class == P_GLOBAL) {
    2467           0 :                 return false;
    2468             :         }
    2469             : 
    2470        2738 :         ptr = lpcfg_parm_ptr(lp_ctx, service,parm);
    2471             : 
    2472        2738 :         lpcfg_print_parameter(parm, ptr, f);
    2473        2738 :         fprintf(f, "\n");
    2474        2738 :         return true;
    2475             : }
    2476             : 
    2477             : /**
    2478             :  * Auto-load some home services.
    2479             :  */
    2480       19163 : static void lpcfg_add_auto_services(struct loadparm_context *lp_ctx,
    2481             :                                     const char *str)
    2482             : {
    2483       19163 :         return;
    2484             : }
    2485             : 
    2486             : /***************************************************************************
    2487             :  Initialise the sDefault parameter structure for the printer values.
    2488             : ***************************************************************************/
    2489             : 
    2490       15303 : void init_printer_values(struct loadparm_context *lp_ctx, TALLOC_CTX *ctx,
    2491             :                          struct loadparm_service *pService)
    2492             : {
    2493             :         /* choose defaults depending on the type of printing */
    2494       15303 :         switch (pService->printing) {
    2495           0 :                 case PRINT_BSD:
    2496             :                 case PRINT_AIX:
    2497             :                 case PRINT_LPRNT:
    2498             :                 case PRINT_LPROS2:
    2499           0 :                         lpcfg_string_set(ctx, &pService->lpq_command, "lpq -P'%p'");
    2500           0 :                         lpcfg_string_set(ctx, &pService->lprm_command, "lprm -P'%p' %j");
    2501           0 :                         lpcfg_string_set(ctx, &pService->print_command, "lpr -r -P'%p' %s");
    2502           0 :                         break;
    2503             : 
    2504           0 :                 case PRINT_LPRNG:
    2505             :                 case PRINT_PLP:
    2506           0 :                         lpcfg_string_set(ctx, &pService->lpq_command, "lpq -P'%p'");
    2507           0 :                         lpcfg_string_set(ctx, &pService->lprm_command, "lprm -P'%p' %j");
    2508           0 :                         lpcfg_string_set(ctx, &pService->print_command, "lpr -r -P'%p' %s");
    2509           0 :                         lpcfg_string_set(ctx, &pService->queuepause_command, "lpc stop '%p'");
    2510           0 :                         lpcfg_string_set(ctx, &pService->queueresume_command, "lpc start '%p'");
    2511           0 :                         lpcfg_string_set(ctx, &pService->lppause_command, "lpc hold '%p' %j");
    2512           0 :                         lpcfg_string_set(ctx, &pService->lpresume_command, "lpc release '%p' %j");
    2513           0 :                         break;
    2514             : 
    2515       15303 :                 case PRINT_CUPS:
    2516             :                 case PRINT_IPRINT:
    2517             :                         /* set the lpq command to contain the destination printer
    2518             :                            name only.  This is used by cups_queue_get() */
    2519       15303 :                         lpcfg_string_set(ctx, &pService->lpq_command, "%p");
    2520       15303 :                         lpcfg_string_set(ctx, &pService->lprm_command, "");
    2521       15303 :                         lpcfg_string_set(ctx, &pService->print_command, "");
    2522       15303 :                         lpcfg_string_set(ctx, &pService->lppause_command, "");
    2523       15303 :                         lpcfg_string_set(ctx, &pService->lpresume_command, "");
    2524       15303 :                         lpcfg_string_set(ctx, &pService->queuepause_command, "");
    2525       15303 :                         lpcfg_string_set(ctx, &pService->queueresume_command, "");
    2526       15303 :                         break;
    2527             : 
    2528           0 :                 case PRINT_SYSV:
    2529             :                 case PRINT_HPUX:
    2530           0 :                         lpcfg_string_set(ctx, &pService->lpq_command, "lpstat -o%p");
    2531           0 :                         lpcfg_string_set(ctx, &pService->lprm_command, "cancel %p-%j");
    2532           0 :                         lpcfg_string_set(ctx, &pService->print_command, "lp -c -d%p %s; rm %s");
    2533           0 :                         lpcfg_string_set(ctx, &pService->queuepause_command, "disable %p");
    2534           0 :                         lpcfg_string_set(ctx, &pService->queueresume_command, "enable %p");
    2535             : #ifndef HPUX
    2536           0 :                         lpcfg_string_set(ctx, &pService->lppause_command, "lp -i %p-%j -H hold");
    2537           0 :                         lpcfg_string_set(ctx, &pService->lpresume_command, "lp -i %p-%j -H resume");
    2538             : #endif /* HPUX */
    2539           0 :                         break;
    2540             : 
    2541           0 :                 case PRINT_QNX:
    2542           0 :                         lpcfg_string_set(ctx, &pService->lpq_command, "lpq -P%p");
    2543           0 :                         lpcfg_string_set(ctx, &pService->lprm_command, "lprm -P%p %j");
    2544           0 :                         lpcfg_string_set(ctx, &pService->print_command, "lp -r -P%p %s");
    2545           0 :                         break;
    2546             : 
    2547             : #if defined(DEVELOPER) || defined(ENABLE_SELFTEST)
    2548             : 
    2549           0 :         case PRINT_TEST:
    2550             :         case PRINT_VLP: {
    2551             :                 const char *tdbfile;
    2552           0 :                 TALLOC_CTX *tmp_ctx = talloc_new(ctx);
    2553             :                 const char *tmp;
    2554             : 
    2555           0 :                 tmp = lpcfg_parm_string(lp_ctx, NULL, "vlp", "tdbfile");
    2556           0 :                 if (tmp == NULL) {
    2557           0 :                         tmp = "/tmp/vlp.tdb";
    2558             :                 }
    2559             : 
    2560           0 :                 tdbfile = talloc_asprintf(tmp_ctx, "tdbfile=%s", tmp);
    2561           0 :                 if (tdbfile == NULL) {
    2562           0 :                         tdbfile="tdbfile=/tmp/vlp.tdb";
    2563             :                 }
    2564             : 
    2565           0 :                 tmp = talloc_asprintf(tmp_ctx, "vlp %s print %%p %%s",
    2566             :                                       tdbfile);
    2567           0 :                 lpcfg_string_set(ctx, &pService->print_command,
    2568             :                            tmp ? tmp : "vlp print %p %s");
    2569             : 
    2570           0 :                 tmp = talloc_asprintf(tmp_ctx, "vlp %s lpq %%p",
    2571             :                                       tdbfile);
    2572           0 :                 lpcfg_string_set(ctx, &pService->lpq_command,
    2573             :                            tmp ? tmp : "vlp lpq %p");
    2574             : 
    2575           0 :                 tmp = talloc_asprintf(tmp_ctx, "vlp %s lprm %%p %%j",
    2576             :                                       tdbfile);
    2577           0 :                 lpcfg_string_set(ctx, &pService->lprm_command,
    2578             :                            tmp ? tmp : "vlp lprm %p %j");
    2579             : 
    2580           0 :                 tmp = talloc_asprintf(tmp_ctx, "vlp %s lppause %%p %%j",
    2581             :                                       tdbfile);
    2582           0 :                 lpcfg_string_set(ctx, &pService->lppause_command,
    2583             :                            tmp ? tmp : "vlp lppause %p %j");
    2584             : 
    2585           0 :                 tmp = talloc_asprintf(tmp_ctx, "vlp %s lpresume %%p %%j",
    2586             :                                       tdbfile);
    2587           0 :                 lpcfg_string_set(ctx, &pService->lpresume_command,
    2588             :                            tmp ? tmp : "vlp lpresume %p %j");
    2589             : 
    2590           0 :                 tmp = talloc_asprintf(tmp_ctx, "vlp %s queuepause %%p",
    2591             :                                       tdbfile);
    2592           0 :                 lpcfg_string_set(ctx, &pService->queuepause_command,
    2593             :                            tmp ? tmp : "vlp queuepause %p");
    2594             : 
    2595           0 :                 tmp = talloc_asprintf(tmp_ctx, "vlp %s queueresume %%p",
    2596             :                                       tdbfile);
    2597           0 :                 lpcfg_string_set(ctx, &pService->queueresume_command,
    2598             :                            tmp ? tmp : "vlp queueresume %p");
    2599           0 :                 TALLOC_FREE(tmp_ctx);
    2600             : 
    2601           0 :                 break;
    2602             :         }
    2603             : #endif /* DEVELOPER */
    2604             : 
    2605             :         }
    2606       15303 : }
    2607             : 
    2608             : 
    2609           0 : static int lpcfg_destructor(struct loadparm_context *lp_ctx)
    2610             : {
    2611             :         struct parmlist_entry *data;
    2612             : 
    2613           0 :         if (lp_ctx->refuse_free) {
    2614             :                 /* someone is trying to free the
    2615             :                    global_loadparm_context.
    2616             :                    We can't allow that. */
    2617           0 :                 return -1;
    2618             :         }
    2619             : 
    2620           0 :         if (lp_ctx->globals->param_opt != NULL) {
    2621             :                 struct parmlist_entry *next;
    2622           0 :                 for (data = lp_ctx->globals->param_opt; data; data=next) {
    2623           0 :                         next = data->next;
    2624           0 :                         if (data->priority & FLAG_CMDLINE) continue;
    2625           0 :                         DLIST_REMOVE(lp_ctx->globals->param_opt, data);
    2626           0 :                         talloc_free(data);
    2627             :                 }
    2628             :         }
    2629             : 
    2630           0 :         return 0;
    2631             : }
    2632             : 
    2633             : /**
    2634             :  * Initialise the global parameter structure.
    2635             :  *
    2636             :  * Note that most callers should use loadparm_init_global() instead
    2637             :  */
    2638        8469 : struct loadparm_context *loadparm_init(TALLOC_CTX *mem_ctx)
    2639             : {
    2640             :         int i;
    2641             :         char *myname;
    2642             :         struct loadparm_context *lp_ctx;
    2643             :         struct parmlist_entry *parm;
    2644             :         char *logfile;
    2645             : 
    2646        8469 :         lp_ctx = talloc_zero(mem_ctx, struct loadparm_context);
    2647        8469 :         if (lp_ctx == NULL)
    2648           0 :                 return NULL;
    2649             : 
    2650        8469 :         talloc_set_destructor(lp_ctx, lpcfg_destructor);
    2651        8469 :         lp_ctx->bInGlobalSection = true;
    2652        8469 :         lp_ctx->globals = talloc_zero(lp_ctx, struct loadparm_global);
    2653             :         /* This appears odd, but globals in s3 isn't a pointer */
    2654        8469 :         lp_ctx->globals->ctx = lp_ctx->globals;
    2655        8469 :         lp_ctx->globals->rpc_low_port = SERVER_TCP_LOW_PORT;
    2656        8469 :         lp_ctx->globals->rpc_high_port = SERVER_TCP_HIGH_PORT;
    2657        8469 :         lp_ctx->globals->weak_crypto = SAMBA_WEAK_CRYPTO_UNKNOWN;
    2658        8469 :         lp_ctx->sDefault = talloc_zero(lp_ctx, struct loadparm_service);
    2659        8469 :         lp_ctx->flags = talloc_zero_array(lp_ctx, unsigned int, num_parameters());
    2660             : 
    2661        8469 :         lp_ctx->sDefault->max_print_jobs = 1000;
    2662        8469 :         lp_ctx->sDefault->available = true;
    2663        8469 :         lp_ctx->sDefault->browseable = true;
    2664        8469 :         lp_ctx->sDefault->read_only = true;
    2665        8469 :         lp_ctx->sDefault->map_archive = true;
    2666        8469 :         lp_ctx->sDefault->strict_locking = true;
    2667        8469 :         lp_ctx->sDefault->oplocks = true;
    2668        8469 :         lp_ctx->sDefault->create_mask = 0744;
    2669        8469 :         lp_ctx->sDefault->force_create_mode = 0000;
    2670        8469 :         lp_ctx->sDefault->directory_mask = 0755;
    2671        8469 :         lp_ctx->sDefault->force_directory_mode = 0000;
    2672        8469 :         lp_ctx->sDefault->aio_read_size = 1;
    2673        8469 :         lp_ctx->sDefault->aio_write_size = 1;
    2674        8469 :         lp_ctx->sDefault->smbd_search_ask_sharemode = true;
    2675        8469 :         lp_ctx->sDefault->smbd_getinfo_ask_sharemode = true;
    2676        8469 :         lp_ctx->sDefault->volume_serial_number = -1;
    2677             : 
    2678        8469 :         DEBUG(3, ("Initialising global parameters\n"));
    2679             : 
    2680     4370004 :         for (i = 0; parm_table[i].label; i++) {
    2681     6978285 :                 if ((parm_table[i].type == P_STRING ||
    2682     4173729 :                      parm_table[i].type == P_USTRING) &&
    2683     1211067 :                     !(lp_ctx->flags[i] & FLAG_CMDLINE)) {
    2684             :                         TALLOC_CTX *parent_mem;
    2685             :                         char **r;
    2686     1211067 :                         if (parm_table[i].p_class == P_LOCAL) {
    2687      296415 :                                 parent_mem = lp_ctx->sDefault;
    2688      296415 :                                 r = (char **)(((char *)lp_ctx->sDefault) + parm_table[i].offset);
    2689             :                         } else {
    2690      914652 :                                 parent_mem = lp_ctx->globals;
    2691      914652 :                                 r = (char **)(((char *)lp_ctx->globals) + parm_table[i].offset);
    2692             :                         }
    2693     1211067 :                         lpcfg_string_set(parent_mem, r, "");
    2694             :                 }
    2695             :         }
    2696             : 
    2697        8469 :         logfile = talloc_asprintf(lp_ctx, "%s/log.samba", dyn_LOGFILEBASE);
    2698        8469 :         lpcfg_do_global_parameter(lp_ctx, "log file", logfile);
    2699        8469 :         talloc_free(logfile);
    2700             : 
    2701        8469 :         lpcfg_do_global_parameter(lp_ctx, "log level", "0");
    2702             : 
    2703        8469 :         lpcfg_do_global_parameter(lp_ctx, "syslog", "1");
    2704        8469 :         lpcfg_do_global_parameter(lp_ctx, "syslog only", "No");
    2705        8469 :         lpcfg_do_global_parameter(lp_ctx, "debug timestamp", "Yes");
    2706        8469 :         lpcfg_do_global_parameter(lp_ctx, "debug prefix timestamp", "No");
    2707        8469 :         lpcfg_do_global_parameter(lp_ctx, "debug hires timestamp", "Yes");
    2708        8469 :         lpcfg_do_global_parameter(lp_ctx, "debug syslog format", "No");
    2709        8469 :         lpcfg_do_global_parameter(lp_ctx, "debug pid", "No");
    2710        8469 :         lpcfg_do_global_parameter(lp_ctx, "debug uid", "No");
    2711        8469 :         lpcfg_do_global_parameter(lp_ctx, "debug class", "No");
    2712             : 
    2713        8469 :         lpcfg_do_global_parameter(lp_ctx, "server role", "auto");
    2714        8469 :         lpcfg_do_global_parameter(lp_ctx, "domain logons", "No");
    2715        8469 :         lpcfg_do_global_parameter(lp_ctx, "domain master", "Auto");
    2716             : 
    2717             :         /* options that can be set on the command line must be initialised via
    2718             :            the slower lpcfg_do_global_parameter() to ensure that FLAG_CMDLINE is obeyed */
    2719             : #ifdef TCP_NODELAY
    2720        8469 :         lpcfg_do_global_parameter(lp_ctx, "socket options", "TCP_NODELAY");
    2721             : #endif
    2722        8469 :         lpcfg_do_global_parameter(lp_ctx, "workgroup", DEFAULT_WORKGROUP);
    2723        8469 :         myname = get_myname(lp_ctx);
    2724        8469 :         lpcfg_do_global_parameter(lp_ctx, "netbios name", myname);
    2725        8469 :         talloc_free(myname);
    2726        8469 :         lpcfg_do_global_parameter(lp_ctx,
    2727             :                                   "name resolve order",
    2728             :                                   DEFAULT_NAME_RESOLVE_ORDER);
    2729             : 
    2730        8469 :         lpcfg_do_global_parameter(lp_ctx, "fstype", "NTFS");
    2731             : 
    2732        8469 :         lpcfg_do_global_parameter(lp_ctx, "ntvfs handler", "unixuid default");
    2733        8469 :         lpcfg_do_global_parameter(lp_ctx, "max connections", "0");
    2734             : 
    2735        8469 :         lpcfg_do_global_parameter(lp_ctx, "dcerpc endpoint servers", "epmapper wkssvc samr netlogon lsarpc drsuapi dssetup unixinfo browser eventlog6 backupkey dnsserver");
    2736        8469 :         lpcfg_do_global_parameter(lp_ctx, "server services", "s3fs rpc nbt wrepl ldap cldap kdc drepl winbindd ntp_signd kcc dnsupdate dns");
    2737        8469 :         lpcfg_do_global_parameter(lp_ctx, "kccsrv:samba_kcc", "true");
    2738             :         /* the winbind method for domain controllers is for both RODC
    2739             :            auth forwarding and for trusted domains */
    2740        8469 :         lpcfg_do_global_parameter(lp_ctx, "private dir", dyn_PRIVATE_DIR);
    2741        8469 :         lpcfg_do_global_parameter(lp_ctx, "binddns dir", dyn_BINDDNS_DIR);
    2742        8469 :         lpcfg_do_global_parameter(lp_ctx, "registry:HKEY_LOCAL_MACHINE", "hklm.ldb");
    2743             : 
    2744             :         /* This hive should be dynamically generated by Samba using
    2745             :            data from the sam, but for the moment leave it in a tdb to
    2746             :            keep regedt32 from popping up an annoying dialog. */
    2747        8469 :         lpcfg_do_global_parameter(lp_ctx, "registry:HKEY_USERS", "hku.ldb");
    2748             : 
    2749             :         /* using UTF8 by default allows us to support all chars */
    2750        8469 :         lpcfg_do_global_parameter(lp_ctx, "unix charset", "UTF-8");
    2751             : 
    2752             :         /* Use codepage 850 as a default for the dos character set */
    2753        8469 :         lpcfg_do_global_parameter(lp_ctx, "dos charset", "CP850");
    2754             : 
    2755             :         /*
    2756             :          * Allow the default PASSWD_CHAT to be overridden in local.h.
    2757             :          */
    2758        8469 :         lpcfg_do_global_parameter(lp_ctx, "passwd chat", DEFAULT_PASSWD_CHAT);
    2759             : 
    2760        8469 :         lpcfg_do_global_parameter(lp_ctx, "pid directory", dyn_PIDDIR);
    2761        8469 :         lpcfg_do_global_parameter(lp_ctx, "lock dir", dyn_LOCKDIR);
    2762        8469 :         lpcfg_do_global_parameter(lp_ctx, "state directory", dyn_STATEDIR);
    2763        8469 :         lpcfg_do_global_parameter(lp_ctx, "cache directory", dyn_CACHEDIR);
    2764        8469 :         lpcfg_do_global_parameter(lp_ctx, "ncalrpc dir", dyn_NCALRPCDIR);
    2765             : 
    2766        8469 :         lpcfg_do_global_parameter(lp_ctx, "nbt client socket address", "0.0.0.0");
    2767        8469 :         lpcfg_do_global_parameter_var(lp_ctx, "server string",
    2768             :                                    "Samba %s", SAMBA_VERSION_STRING);
    2769             : 
    2770        8469 :         lpcfg_do_global_parameter(lp_ctx, "password server", "*");
    2771             : 
    2772        8469 :         lpcfg_do_global_parameter(lp_ctx, "max mux", "50");
    2773        8469 :         lpcfg_do_global_parameter(lp_ctx, "max xmit", "16644");
    2774        8469 :         lpcfg_do_global_parameter(lp_ctx, "host msdfs", "true");
    2775             : 
    2776        8469 :         lpcfg_do_global_parameter(lp_ctx, "LargeReadwrite", "True");
    2777        8469 :         lpcfg_do_global_parameter(lp_ctx, "server min protocol", "SMB2_02");
    2778        8469 :         lpcfg_do_global_parameter(lp_ctx, "server max protocol", "SMB3");
    2779        8469 :         lpcfg_do_global_parameter(lp_ctx, "client min protocol", "SMB2_02");
    2780        8469 :         lpcfg_do_global_parameter(lp_ctx, "client max protocol", "default");
    2781        8469 :         lpcfg_do_global_parameter(lp_ctx, "client ipc min protocol", "default");
    2782        8469 :         lpcfg_do_global_parameter(lp_ctx, "client ipc max protocol", "default");
    2783        8469 :         lpcfg_do_global_parameter(lp_ctx, "security", "AUTO");
    2784        8469 :         lpcfg_do_global_parameter(lp_ctx, "EncryptPasswords", "True");
    2785        8469 :         lpcfg_do_global_parameter(lp_ctx, "ReadRaw", "True");
    2786        8469 :         lpcfg_do_global_parameter(lp_ctx, "WriteRaw", "True");
    2787        8469 :         lpcfg_do_global_parameter(lp_ctx, "NullPasswords", "False");
    2788        8469 :         lpcfg_do_global_parameter(lp_ctx, "old password allowed period", "60");
    2789        8469 :         lpcfg_do_global_parameter(lp_ctx, "ObeyPamRestrictions", "False");
    2790             : 
    2791        8469 :         lpcfg_do_global_parameter(lp_ctx, "TimeServer", "False");
    2792        8469 :         lpcfg_do_global_parameter(lp_ctx, "BindInterfacesOnly", "False");
    2793        8469 :         lpcfg_do_global_parameter(lp_ctx, "Unicode", "True");
    2794        8469 :         lpcfg_do_global_parameter(lp_ctx, "ClientLanManAuth", "False");
    2795        8469 :         lpcfg_do_global_parameter(lp_ctx, "ClientNTLMv2Auth", "True");
    2796        8469 :         lpcfg_do_global_parameter(lp_ctx, "LanmanAuth", "False");
    2797        8469 :         lpcfg_do_global_parameter(lp_ctx, "NTLMAuth", "ntlmv2-only");
    2798        8469 :         lpcfg_do_global_parameter(lp_ctx, "NT hash store", "always");
    2799        8469 :         lpcfg_do_global_parameter(lp_ctx, "RawNTLMv2Auth", "False");
    2800        8469 :         lpcfg_do_global_parameter(lp_ctx, "client use spnego principal", "False");
    2801             : 
    2802        8469 :         lpcfg_do_global_parameter(lp_ctx, "allow dcerpc auth level connect", "False");
    2803             : 
    2804        8469 :         lpcfg_do_global_parameter(lp_ctx, "UnixExtensions", "True");
    2805             : 
    2806        8469 :         lpcfg_do_global_parameter(lp_ctx, "PreferredMaster", "Auto");
    2807        8469 :         lpcfg_do_global_parameter(lp_ctx, "LocalMaster", "True");
    2808             : 
    2809        8469 :         lpcfg_do_global_parameter(lp_ctx, "wins support", "False");
    2810        8469 :         lpcfg_do_global_parameter(lp_ctx, "dns proxy", "True");
    2811             : 
    2812        8469 :         lpcfg_do_global_parameter(lp_ctx, "winbind separator", "\\");
    2813        8469 :         lpcfg_do_global_parameter(lp_ctx, "winbind sealed pipes", "True");
    2814        8469 :         lpcfg_do_global_parameter(lp_ctx, "winbind scan trusted domains", "False");
    2815        8469 :         lpcfg_do_global_parameter(lp_ctx, "require strong key", "True");
    2816        8469 :         lpcfg_do_global_parameter(lp_ctx, "reject md5 servers", "True");
    2817        8469 :         lpcfg_do_global_parameter(lp_ctx, "winbindd socket directory", dyn_WINBINDD_SOCKET_DIR);
    2818        8469 :         lpcfg_do_global_parameter(lp_ctx, "ntp signd socket directory", dyn_NTP_SIGND_SOCKET_DIR);
    2819        8469 :         lpcfg_do_global_parameter_var(lp_ctx, "gpo update command", "%s/samba-gpupdate", dyn_SCRIPTSBINDIR);
    2820        8469 :         lpcfg_do_global_parameter_var(lp_ctx, "apply group policies", "False");
    2821        8469 :         lpcfg_do_global_parameter_var(lp_ctx, "dns update command", "%s/samba_dnsupdate", dyn_SCRIPTSBINDIR);
    2822        8469 :         lpcfg_do_global_parameter_var(lp_ctx, "spn update command", "%s/samba_spnupdate", dyn_SCRIPTSBINDIR);
    2823        8469 :         lpcfg_do_global_parameter_var(lp_ctx, "samba kcc command",
    2824             :                                         "%s/samba_kcc", dyn_SCRIPTSBINDIR);
    2825             : #ifdef MIT_KDC_PATH
    2826        1491 :         lpcfg_do_global_parameter_var(lp_ctx,
    2827             :                                       "mit kdc command",
    2828             :                                       MIT_KDC_PATH);
    2829             : #endif
    2830        8469 :         lpcfg_do_global_parameter(lp_ctx, "template shell", "/bin/false");
    2831        8469 :         lpcfg_do_global_parameter(lp_ctx, "template homedir", "/home/%D/%U");
    2832             : 
    2833        8469 :         lpcfg_do_global_parameter(lp_ctx, "client signing", "default");
    2834        8469 :         lpcfg_do_global_parameter(lp_ctx, "client ipc signing", "default");
    2835        8469 :         lpcfg_do_global_parameter(lp_ctx, "server signing", "default");
    2836             : 
    2837        8469 :         lpcfg_do_global_parameter(lp_ctx, "use mmap", "True");
    2838             : 
    2839        8469 :         lpcfg_do_global_parameter(lp_ctx, "smb ports", "445 139");
    2840        8469 :         lpcfg_do_global_parameter_var(lp_ctx, "nbt port", "%d", NBT_NAME_SERVICE_PORT);
    2841        8469 :         lpcfg_do_global_parameter_var(lp_ctx, "dgram port", "%d", NBT_DGRAM_SERVICE_PORT);
    2842        8469 :         lpcfg_do_global_parameter(lp_ctx, "cldap port", "389");
    2843        8469 :         lpcfg_do_global_parameter(lp_ctx, "krb5 port", "88");
    2844        8469 :         lpcfg_do_global_parameter(lp_ctx, "kpasswd port", "464");
    2845        8469 :         lpcfg_do_global_parameter_var(lp_ctx, "dns port", "%d", DNS_SERVICE_PORT);
    2846             : 
    2847        8469 :         lpcfg_do_global_parameter(lp_ctx, "kdc enable fast", "True");
    2848             : 
    2849        8469 :         lpcfg_do_global_parameter(lp_ctx, "nt status support", "True");
    2850             : 
    2851        8469 :         lpcfg_do_global_parameter(lp_ctx, "max wins ttl", "518400"); /* 6 days */
    2852        8469 :         lpcfg_do_global_parameter(lp_ctx, "min wins ttl", "21600");
    2853             : 
    2854        8469 :         lpcfg_do_global_parameter(lp_ctx, "tls enabled", "True");
    2855        8469 :         lpcfg_do_global_parameter(lp_ctx, "tls verify peer", "as_strict_as_possible");
    2856        8469 :         lpcfg_do_global_parameter(lp_ctx, "tls keyfile", "tls/key.pem");
    2857        8469 :         lpcfg_do_global_parameter(lp_ctx, "tls certfile", "tls/cert.pem");
    2858        8469 :         lpcfg_do_global_parameter(lp_ctx, "tls cafile", "tls/ca.pem");
    2859        8469 :         lpcfg_do_global_parameter(lp_ctx,
    2860             :                                   "tls priority",
    2861             :                                   "NORMAL:-VERS-SSL3.0");
    2862             : 
    2863        8469 :         lpcfg_do_global_parameter(lp_ctx, "nsupdate command", "/usr/bin/nsupdate -g");
    2864             : 
    2865        8469 :         lpcfg_do_global_parameter(lp_ctx, "allow dns updates", "secure only");
    2866        8469 :         lpcfg_do_global_parameter(lp_ctx, "dns zone scavenging", "False");
    2867        8469 :         lpcfg_do_global_parameter(lp_ctx, "dns forwarder", "");
    2868             : 
    2869        8469 :         lpcfg_do_global_parameter(lp_ctx, "algorithmic rid base", "1000");
    2870             : 
    2871        8469 :         lpcfg_do_global_parameter(lp_ctx, "enhanced browsing", "True");
    2872             : 
    2873        8469 :         lpcfg_do_global_parameter(lp_ctx, "winbind nss info", "template");
    2874             : 
    2875        8469 :         lpcfg_do_global_parameter(lp_ctx, "server schannel", "True");
    2876        8469 :         lpcfg_do_global_parameter(lp_ctx, "server schannel require seal", "True");
    2877        8469 :         lpcfg_do_global_parameter(lp_ctx, "reject md5 clients", "True");
    2878             : 
    2879        8469 :         lpcfg_do_global_parameter(lp_ctx, "short preserve case", "True");
    2880             : 
    2881        8469 :         lpcfg_do_global_parameter(lp_ctx, "max open files", "16384");
    2882             : 
    2883        8469 :         lpcfg_do_global_parameter(lp_ctx, "cups connection timeout", "30");
    2884             : 
    2885        8469 :         lpcfg_do_global_parameter(lp_ctx, "locking", "True");
    2886             : 
    2887        8469 :         lpcfg_do_global_parameter(lp_ctx, "block size", "1024");
    2888             : 
    2889        8469 :         lpcfg_do_global_parameter(lp_ctx, "client use spnego", "True");
    2890             : 
    2891        8469 :         lpcfg_do_global_parameter(lp_ctx, "change notify", "True");
    2892             : 
    2893        8469 :         lpcfg_do_global_parameter(lp_ctx, "name cache timeout", "660");
    2894             : 
    2895        8469 :         lpcfg_do_global_parameter(lp_ctx, "defer sharing violations", "True");
    2896             : 
    2897        8469 :         lpcfg_do_global_parameter(lp_ctx, "ldap replication sleep", "1000");
    2898             : 
    2899        8469 :         lpcfg_do_global_parameter(lp_ctx, "idmap backend", "tdb");
    2900             : 
    2901        8469 :         lpcfg_do_global_parameter(lp_ctx, "enable privileges", "True");
    2902             : 
    2903        8469 :         lpcfg_do_global_parameter_var(lp_ctx, "smb2 max write", "%u", DEFAULT_SMB2_MAX_WRITE);
    2904             : 
    2905        8469 :         lpcfg_do_global_parameter(lp_ctx, "passdb backend", "tdbsam");
    2906             : 
    2907        8469 :         lpcfg_do_global_parameter(lp_ctx, "deadtime", "10080");
    2908             : 
    2909        8469 :         lpcfg_do_global_parameter(lp_ctx, "getwd cache", "True");
    2910             : 
    2911        8469 :         lpcfg_do_global_parameter(lp_ctx, "winbind nested groups", "True");
    2912             : 
    2913        8469 :         lpcfg_do_global_parameter(lp_ctx, "mangled names", "illegal");
    2914             : 
    2915        8469 :         lpcfg_do_global_parameter_var(lp_ctx, "smb2 max credits", "%u", DEFAULT_SMB2_MAX_CREDITS);
    2916             : 
    2917        8469 :         lpcfg_do_global_parameter(lp_ctx, "ldap ssl", "start tls");
    2918             : 
    2919        8469 :         lpcfg_do_global_parameter(lp_ctx, "ldap deref", "auto");
    2920             : 
    2921        8469 :         lpcfg_do_global_parameter(lp_ctx, "lm interval", "60");
    2922             : 
    2923        8469 :         lpcfg_do_global_parameter(lp_ctx, "mangling method", "hash2");
    2924             : 
    2925        8469 :         lpcfg_do_global_parameter(lp_ctx, "hide dot files", "True");
    2926             : 
    2927        8469 :         lpcfg_do_global_parameter(lp_ctx, "browse list", "True");
    2928             : 
    2929        8469 :         lpcfg_do_global_parameter(lp_ctx, "passwd chat timeout", "2");
    2930             : 
    2931        8469 :         lpcfg_do_global_parameter(lp_ctx, "guest account", GUEST_ACCOUNT);
    2932             : 
    2933        8469 :         lpcfg_do_global_parameter(lp_ctx, "client schannel", "True");
    2934             : 
    2935        8469 :         lpcfg_do_global_parameter(lp_ctx, "smb encrypt", "default");
    2936             : 
    2937        8469 :         lpcfg_do_global_parameter(lp_ctx, "max log size", "5000");
    2938             : 
    2939        8469 :         lpcfg_do_global_parameter(lp_ctx, "idmap negative cache time", "120");
    2940             : 
    2941        8469 :         lpcfg_do_global_parameter(lp_ctx, "ldap follow referral", "auto");
    2942             : 
    2943        8469 :         lpcfg_do_global_parameter(lp_ctx, "multicast dns register", "yes");
    2944             : 
    2945        8469 :         lpcfg_do_global_parameter(lp_ctx, "winbind reconnect delay", "30");
    2946             : 
    2947        8469 :         lpcfg_do_global_parameter(lp_ctx, "winbind request timeout", "60");
    2948             : 
    2949        8469 :         lpcfg_do_global_parameter(lp_ctx, "nt acl support", "yes");
    2950             : 
    2951        8469 :         lpcfg_do_global_parameter(lp_ctx, "acl check permissions", "yes");
    2952             : 
    2953        8469 :         lpcfg_do_global_parameter(lp_ctx, "keepalive", "300");
    2954             : 
    2955        8469 :         lpcfg_do_global_parameter(lp_ctx, "smbd profiling level", "off");
    2956             : 
    2957        8469 :         lpcfg_do_global_parameter(lp_ctx, "winbind cache time", "300");
    2958             : 
    2959        8469 :         lpcfg_do_global_parameter(lp_ctx, "level2 oplocks", "yes");
    2960             : 
    2961        8469 :         lpcfg_do_global_parameter(lp_ctx, "show add printer wizard", "yes");
    2962             : 
    2963        8469 :         lpcfg_do_global_parameter(lp_ctx, "ldap page size", "1000");
    2964             : 
    2965        8469 :         lpcfg_do_global_parameter(lp_ctx, "kernel share modes", "no");
    2966             : 
    2967        8469 :         lpcfg_do_global_parameter(lp_ctx, "strict locking", "Auto");
    2968             : 
    2969        8469 :         lpcfg_do_global_parameter(lp_ctx, "strict sync", "yes");
    2970             : 
    2971        8469 :         lpcfg_do_global_parameter(lp_ctx, "map readonly", "no");
    2972             : 
    2973        8469 :         lpcfg_do_global_parameter(lp_ctx, "allow trusted domains", "yes");
    2974             : 
    2975        8469 :         lpcfg_do_global_parameter(lp_ctx, "default devmode", "yes");
    2976             : 
    2977        8469 :         lpcfg_do_global_parameter(lp_ctx, "os level", "20");
    2978             : 
    2979        8469 :         lpcfg_do_global_parameter(lp_ctx, "dos filetimes", "yes");
    2980             : 
    2981        8469 :         lpcfg_do_global_parameter(lp_ctx, "mangling char", "~");
    2982             : 
    2983        8469 :         lpcfg_do_global_parameter(lp_ctx, "printcap cache time", "750");
    2984             : 
    2985        8469 :         lpcfg_do_global_parameter(lp_ctx, "create krb5 conf", "yes");
    2986             : 
    2987        8469 :         lpcfg_do_global_parameter(lp_ctx, "winbind max clients", "200");
    2988             : 
    2989        8469 :         lpcfg_do_global_parameter(lp_ctx, "acl map full control", "yes");
    2990             : 
    2991        8469 :         lpcfg_do_global_parameter(lp_ctx, "nt pipe support", "yes");
    2992             : 
    2993        8469 :         lpcfg_do_global_parameter(lp_ctx, "ldap debug threshold", "10");
    2994             : 
    2995        8469 :         lpcfg_do_global_parameter(lp_ctx, "client ldap sasl wrapping", "seal");
    2996             : 
    2997        8469 :         lpcfg_do_global_parameter(lp_ctx, "mdns name", "netbios");
    2998             : 
    2999        8469 :         lpcfg_do_global_parameter(lp_ctx, "ldap server require strong auth", "yes");
    3000             : 
    3001        8469 :         lpcfg_do_global_parameter(lp_ctx, "follow symlinks", "yes");
    3002             : 
    3003        8469 :         lpcfg_do_global_parameter(lp_ctx, "machine password timeout", "604800");
    3004             : 
    3005        8469 :         lpcfg_do_global_parameter(lp_ctx, "ldap connection timeout", "2");
    3006             : 
    3007        8469 :         lpcfg_do_global_parameter(lp_ctx, "winbind expand groups", "0");
    3008             : 
    3009        8469 :         lpcfg_do_global_parameter(lp_ctx, "stat cache", "yes");
    3010             : 
    3011        8469 :         lpcfg_do_global_parameter(lp_ctx, "lpq cache time", "30");
    3012             : 
    3013        8469 :         lpcfg_do_global_parameter_var(lp_ctx, "smb2 max trans", "%u", DEFAULT_SMB2_MAX_TRANSACT);
    3014             : 
    3015        8469 :         lpcfg_do_global_parameter_var(lp_ctx, "smb2 max read", "%u", DEFAULT_SMB2_MAX_READ);
    3016             : 
    3017        8469 :         lpcfg_do_global_parameter(lp_ctx, "durable handles", "yes");
    3018             : 
    3019        8469 :         lpcfg_do_global_parameter(lp_ctx, "max stat cache size", "512");
    3020             : 
    3021        8469 :         lpcfg_do_global_parameter(lp_ctx, "ldap passwd sync", "no");
    3022             : 
    3023        8469 :         lpcfg_do_global_parameter(lp_ctx, "kernel change notify", "yes");
    3024             : 
    3025        8469 :         lpcfg_do_global_parameter(lp_ctx, "max ttl", "259200");
    3026             : 
    3027        8469 :         lpcfg_do_global_parameter(lp_ctx, "blocking locks", "yes");
    3028             : 
    3029        8469 :         lpcfg_do_global_parameter(lp_ctx, "load printers", "yes");
    3030             : 
    3031        8469 :         lpcfg_do_global_parameter(lp_ctx, "idmap cache time", "604800");
    3032             : 
    3033        8469 :         lpcfg_do_global_parameter(lp_ctx, "preserve case", "yes");
    3034             : 
    3035        8469 :         lpcfg_do_global_parameter(lp_ctx, "lm announce", "auto");
    3036             : 
    3037        8469 :         lpcfg_do_global_parameter(lp_ctx, "afs token lifetime", "604800");
    3038             : 
    3039        8469 :         lpcfg_do_global_parameter(lp_ctx, "enable core files", "yes");
    3040             : 
    3041        8469 :         lpcfg_do_global_parameter(lp_ctx, "winbind max domain connections", "1");
    3042             : 
    3043        8469 :         lpcfg_do_global_parameter(lp_ctx, "case sensitive", "auto");
    3044             : 
    3045        8469 :         lpcfg_do_global_parameter(lp_ctx, "ldap timeout", "15");
    3046             : 
    3047        8469 :         lpcfg_do_global_parameter(lp_ctx, "mangle prefix", "1");
    3048             : 
    3049        8469 :         lpcfg_do_global_parameter(lp_ctx, "posix locking", "yes");
    3050             : 
    3051        8469 :         lpcfg_do_global_parameter(lp_ctx, "lock spin time", "200");
    3052             : 
    3053        8469 :         lpcfg_do_global_parameter(lp_ctx, "directory name cache size", "100");
    3054             : 
    3055        8469 :         lpcfg_do_global_parameter(lp_ctx, "nmbd bind explicit broadcast", "yes");
    3056             : 
    3057        8469 :         lpcfg_do_global_parameter(lp_ctx, "init logon delay", "100");
    3058             : 
    3059        8469 :         lpcfg_do_global_parameter(lp_ctx, "usershare owner only", "yes");
    3060             : 
    3061        8469 :         lpcfg_do_global_parameter(lp_ctx, "-valid", "yes");
    3062             : 
    3063        8469 :         lpcfg_do_global_parameter_var(lp_ctx, "usershare path", "%s/usershares", get_dyn_STATEDIR());
    3064             : 
    3065             : #ifdef DEVELOPER
    3066        8469 :         lpcfg_do_global_parameter_var(lp_ctx, "panic action", "/bin/sleep 999999999");
    3067             : #endif
    3068             : 
    3069        8469 :         lpcfg_do_global_parameter(lp_ctx, "smb passwd file", get_dyn_SMB_PASSWD_FILE());
    3070             : 
    3071        8469 :         lpcfg_do_global_parameter(lp_ctx, "logon home", "\\\\%N\\%U");
    3072             : 
    3073        8469 :         lpcfg_do_global_parameter(lp_ctx, "logon path", "\\\\%N\\%U\\profile");
    3074             : 
    3075        8469 :         lpcfg_do_global_parameter(lp_ctx, "printjob username", "%U");
    3076             : 
    3077        8469 :         lpcfg_do_global_parameter(lp_ctx, "aio max threads", "100");
    3078             : 
    3079        8469 :         lpcfg_do_global_parameter(lp_ctx, "smb2 leases", "yes");
    3080             : 
    3081        8469 :         lpcfg_do_global_parameter(lp_ctx, "server multi channel support", "yes");
    3082             : 
    3083        8469 :         lpcfg_do_global_parameter(lp_ctx, "kerberos encryption types", "all");
    3084             : 
    3085        8469 :         lpcfg_do_global_parameter(lp_ctx,
    3086             :                                   "rpc server dynamic port range",
    3087             :                                   "49152-65535");
    3088             : 
    3089        8469 :         lpcfg_do_global_parameter(lp_ctx, "prefork children", "4");
    3090        8469 :         lpcfg_do_global_parameter(lp_ctx, "prefork backoff increment", "10");
    3091        8469 :         lpcfg_do_global_parameter(lp_ctx, "prefork maximum backoff", "120");
    3092             : 
    3093        8469 :         lpcfg_do_global_parameter(lp_ctx, "check parent directory delete on close", "no");
    3094             : 
    3095        8469 :         lpcfg_do_global_parameter(lp_ctx, "ea support", "yes");
    3096             : 
    3097        8469 :         lpcfg_do_global_parameter(lp_ctx, "store dos attributes", "yes");
    3098             : 
    3099        8469 :         lpcfg_do_global_parameter(lp_ctx, "debug encryption", "no");
    3100             : 
    3101        8469 :         lpcfg_do_global_parameter(lp_ctx, "spotlight backend", "noindex");
    3102             : 
    3103        8469 :         lpcfg_do_global_parameter(
    3104             :                 lp_ctx, "ldap max anonymous request size", "256000");
    3105        8469 :         lpcfg_do_global_parameter(
    3106             :                 lp_ctx, "ldap max authenticated request size", "16777216");
    3107        8469 :         lpcfg_do_global_parameter(
    3108             :                 lp_ctx, "ldap max search request size", "256000");
    3109             : 
    3110             :         /* Async DNS query timeout in seconds. */
    3111        8469 :         lpcfg_do_global_parameter(lp_ctx, "async dns timeout", "10");
    3112             : 
    3113        8469 :         lpcfg_do_global_parameter(lp_ctx,
    3114             :                                   "client smb encrypt",
    3115             :                                   "default");
    3116             : 
    3117        8469 :         lpcfg_do_global_parameter(lp_ctx,
    3118             :                                   "client use kerberos",
    3119             :                                   "desired");
    3120             : 
    3121        8469 :         lpcfg_do_global_parameter(lp_ctx,
    3122             :                                   "client protection",
    3123             :                                   "default");
    3124             : 
    3125        8469 :         lpcfg_do_global_parameter(lp_ctx,
    3126             :                                   "smbd max xattr size",
    3127             :                                   "65536");
    3128             : 
    3129        8469 :         lpcfg_do_global_parameter(lp_ctx,
    3130             :                                   "acl flag inherited canonicalization",
    3131             :                                   "yes");
    3132             : 
    3133        8469 :         lpcfg_do_global_parameter(lp_ctx,
    3134             :                                   "winbind use krb5 enterprise principals",
    3135             :                                   "yes");
    3136             : 
    3137        8469 :         lpcfg_do_global_parameter(lp_ctx,
    3138             :                                   "client smb3 signing algorithms",
    3139             :                                   DEFAULT_SMB3_SIGNING_ALGORITHMS);
    3140        8469 :         lpcfg_do_global_parameter(lp_ctx,
    3141             :                                   "server smb3 signing algorithms",
    3142             :                                   DEFAULT_SMB3_SIGNING_ALGORITHMS);
    3143             : 
    3144        8469 :         lpcfg_do_global_parameter(lp_ctx,
    3145             :                                   "client smb3 encryption algorithms",
    3146             :                                   DEFAULT_SMB3_ENCRYPTION_ALGORITHMS);
    3147        8469 :         lpcfg_do_global_parameter(lp_ctx,
    3148             :                                   "server smb3 encryption algorithms",
    3149             :                                   DEFAULT_SMB3_ENCRYPTION_ALGORITHMS);
    3150             : 
    3151        8469 :         lpcfg_do_global_parameter(lp_ctx,
    3152             :                                   "min domain uid",
    3153             :                                   "1000");
    3154             : 
    3155        8469 :         lpcfg_do_global_parameter(lp_ctx,
    3156             :                                   "rpc start on demand helpers",
    3157             :                                   "yes");
    3158             : 
    3159     4370004 :         for (i = 0; parm_table[i].label; i++) {
    3160     4361535 :                 if (!(lp_ctx->flags[i] & FLAG_CMDLINE)) {
    3161     4361535 :                         lp_ctx->flags[i] |= FLAG_DEFAULT;
    3162             :                 }
    3163             :         }
    3164             : 
    3165       33876 :         for (parm=lp_ctx->globals->param_opt; parm; parm=parm->next) {
    3166       25407 :                 if (!(parm->priority & FLAG_CMDLINE)) {
    3167       25407 :                         parm->priority |= FLAG_DEFAULT;
    3168             :                 }
    3169             :         }
    3170             : 
    3171        8469 :         for (parm=lp_ctx->sDefault->param_opt; parm; parm=parm->next) {
    3172           0 :                 if (!(parm->priority & FLAG_CMDLINE)) {
    3173           0 :                         parm->priority |= FLAG_DEFAULT;
    3174             :                 }
    3175             :         }
    3176             : 
    3177        8469 :         return lp_ctx;
    3178             : }
    3179             : 
    3180             : /**
    3181             :  * Initialise the global parameter structure.
    3182             :  */
    3183       47979 : struct loadparm_context *loadparm_init_global(bool load_default)
    3184             : {
    3185       47979 :         if (global_loadparm_context == NULL) {
    3186        8418 :                 global_loadparm_context = loadparm_init(NULL);
    3187             :         }
    3188       47979 :         if (global_loadparm_context == NULL) {
    3189           0 :                 return NULL;
    3190             :         }
    3191       47979 :         global_loadparm_context->global = true;
    3192       47979 :         if (load_default && !global_loadparm_context->loaded) {
    3193           5 :                 lpcfg_load_default(global_loadparm_context);
    3194             :         }
    3195       47979 :         global_loadparm_context->refuse_free = true;
    3196       47979 :         return global_loadparm_context;
    3197             : }
    3198             : 
    3199             : /**
    3200             :  * Initialise the global parameter structure.
    3201             :  */
    3202      155692 : struct loadparm_context *loadparm_init_s3(TALLOC_CTX *mem_ctx, 
    3203             :                                           const struct loadparm_s3_helpers *s3_fns)
    3204             : {
    3205      155692 :         struct loadparm_context *loadparm_context = talloc_zero(mem_ctx, struct loadparm_context);
    3206      155692 :         if (!loadparm_context) {
    3207           0 :                 return NULL;
    3208             :         }
    3209      155692 :         loadparm_context->s3_fns = s3_fns;
    3210      155692 :         loadparm_context->globals = s3_fns->globals;
    3211      155692 :         loadparm_context->flags = s3_fns->flags;
    3212             : 
    3213      155692 :         return loadparm_context;
    3214             : }
    3215             : 
    3216      246130 : const char *lpcfg_configfile(struct loadparm_context *lp_ctx)
    3217             : {
    3218      246130 :         return lp_ctx->szConfigFile;
    3219             : }
    3220             : 
    3221       20059 : const char *lp_default_path(void)
    3222             : {
    3223       20059 :     if (getenv("SMB_CONF_PATH"))
    3224       19733 :         return getenv("SMB_CONF_PATH");
    3225             :     else
    3226         326 :         return dyn_CONFIGFILE;
    3227             : }
    3228             : 
    3229             : /**
    3230             :  * Update the internal state of a loadparm context after settings 
    3231             :  * have changed.
    3232             :  */
    3233       19163 : static bool lpcfg_update(struct loadparm_context *lp_ctx)
    3234             : {
    3235             :         struct debug_settings settings;
    3236             :         int max_protocol, min_protocol;
    3237             :         TALLOC_CTX *tmp_ctx;
    3238       17362 :         const struct loadparm_substitution *lp_sub =
    3239        1801 :                 lpcfg_noop_substitution();
    3240             : 
    3241       19163 :         tmp_ctx = talloc_new(lp_ctx);
    3242       19163 :         if (tmp_ctx == NULL) {
    3243           0 :                 return false;
    3244             :         }
    3245             : 
    3246       19163 :         lpcfg_add_auto_services(lp_ctx, lpcfg_auto_services(lp_ctx, lp_sub, tmp_ctx));
    3247             : 
    3248       19163 :         if (!lp_ctx->globals->wins_server_list && lp_ctx->globals->we_are_a_wins_server) {
    3249        3553 :                 lpcfg_do_global_parameter(lp_ctx, "wins server", "127.0.0.1");
    3250             :         }
    3251             : 
    3252       19163 :         if (!lp_ctx->global) {
    3253          79 :                 TALLOC_FREE(tmp_ctx);
    3254          79 :                 return true;
    3255             :         }
    3256             : 
    3257       19084 :         panic_action = lp_ctx->globals->panic_action;
    3258             : 
    3259       19084 :         reload_charcnv(lp_ctx);
    3260             : 
    3261       19084 :         ZERO_STRUCT(settings);
    3262             :         /* Add any more debug-related smb.conf parameters created in
    3263             :          * future here */
    3264       19084 :         settings.timestamp_logs = lp_ctx->globals->timestamp_logs;
    3265       19084 :         settings.debug_prefix_timestamp = lp_ctx->globals->debug_prefix_timestamp;
    3266       19084 :         settings.debug_hires_timestamp = lp_ctx->globals->debug_hires_timestamp;
    3267       19084 :         settings.debug_syslog_format = lp_ctx->globals->debug_syslog_format;
    3268       19084 :         settings.debug_pid = lp_ctx->globals->debug_pid;
    3269       19084 :         settings.debug_uid = lp_ctx->globals->debug_uid;
    3270       19084 :         settings.debug_class = lp_ctx->globals->debug_class;
    3271       19084 :         settings.max_log_size = lp_ctx->globals->max_log_size;
    3272       36367 :         debug_set_settings(&settings, lp_ctx->globals->logging,
    3273       19084 :                            lp_ctx->globals->syslog,
    3274       19084 :                            lp_ctx->globals->syslog_only);
    3275             : 
    3276             :         /* FIXME: This is a bit of a hack, but we can't use a global, since 
    3277             :          * not everything that uses lp also uses the socket library */
    3278       19084 :         if (lpcfg_parm_bool(lp_ctx, NULL, "socket", "testnonblock", false)) {
    3279         176 :                 setenv("SOCKET_TESTNONBLOCK", "1", 1);
    3280             :         } else {
    3281       18908 :                 unsetenv("SOCKET_TESTNONBLOCK");
    3282             :         }
    3283             : 
    3284             :         /* Check if command line max protocol < min protocol, if so
    3285             :          * report a warning to the user.
    3286             :          */
    3287       19084 :         max_protocol = lpcfg_client_max_protocol(lp_ctx);
    3288       19084 :         min_protocol = lpcfg_client_min_protocol(lp_ctx);
    3289       19084 :         if (lpcfg_client_max_protocol(lp_ctx) < lpcfg_client_min_protocol(lp_ctx)) {
    3290             :                 const char *max_protocolp, *min_protocolp;
    3291           0 :                 max_protocolp = lpcfg_get_smb_protocol(max_protocol);
    3292           0 :                 min_protocolp = lpcfg_get_smb_protocol(min_protocol);
    3293           0 :                 DBG_ERR("Max protocol %s is less than min protocol %s.\n",
    3294             :                         max_protocolp, min_protocolp);
    3295             :         }
    3296             : 
    3297       19084 :         TALLOC_FREE(tmp_ctx);
    3298       19084 :         return true;
    3299             : }
    3300             : 
    3301           8 : bool lpcfg_load_default(struct loadparm_context *lp_ctx)
    3302             : {
    3303             :     const char *path;
    3304             : 
    3305           8 :     path = lp_default_path();
    3306             : 
    3307           8 :     if (!file_exist(path)) {
    3308             :             /* We allow the default smb.conf file to not exist, 
    3309             :              * basically the equivalent of an empty file. */
    3310           2 :             return lpcfg_update(lp_ctx);
    3311             :     }
    3312             : 
    3313           6 :     return lpcfg_load(lp_ctx, path);
    3314             : }
    3315             : 
    3316             : /**
    3317             :  * Load the services array from the services file.
    3318             :  *
    3319             :  * Return True on success, False on failure.
    3320             :  */
    3321       20053 : static bool lpcfg_load_internal(struct loadparm_context *lp_ctx,
    3322             :                                 const char *filename, bool set_global)
    3323             : {
    3324             :         char *n2;
    3325             :         bool bRetval;
    3326             : 
    3327       20053 :         if (lp_ctx->szConfigFile != NULL) {
    3328       11197 :                 talloc_free(discard_const_p(char, lp_ctx->szConfigFile));
    3329       11197 :                 lp_ctx->szConfigFile = NULL;
    3330             :         }
    3331             : 
    3332       20053 :         lp_ctx->szConfigFile = talloc_strdup(lp_ctx, filename);
    3333             : 
    3334       20053 :         if (lp_ctx->s3_fns) {
    3335         799 :                 return lp_ctx->s3_fns->load(filename);
    3336             :         }
    3337             : 
    3338       19254 :         lp_ctx->bInGlobalSection = true;
    3339       19254 :         n2 = standard_sub_basic(lp_ctx, lp_ctx->szConfigFile);
    3340       19254 :         DEBUG(2, ("lpcfg_load: refreshing parameters from %s\n", n2));
    3341             : 
    3342       19254 :         add_to_file_list(lp_ctx, &lp_ctx->file_lists, lp_ctx->szConfigFile, n2);
    3343             : 
    3344             :         /* We get sections first, so have to start 'behind' to make up */
    3345       19254 :         lp_ctx->currentService = NULL;
    3346       19254 :         bRetval = pm_process(n2, do_section, lpcfg_do_parameter, lp_ctx);
    3347             : 
    3348             :         /* finish up the last section */
    3349       19254 :         DEBUG(4, ("pm_process() returned %s\n", BOOLSTR(bRetval)));
    3350       19254 :         if (bRetval)
    3351       19161 :                 if (lp_ctx->currentService != NULL)
    3352       10993 :                         bRetval = lpcfg_service_ok(lp_ctx->currentService);
    3353             : 
    3354       19254 :         bRetval = bRetval && lpcfg_update(lp_ctx);
    3355             : 
    3356             :         /* we do this unconditionally, so that it happens even
    3357             :            for a missing smb.conf */
    3358       19254 :         reload_charcnv(lp_ctx);
    3359             : 
    3360       19254 :         if (bRetval == true && set_global) {
    3361             :                 /* set this up so that any child python tasks will
    3362             :                    find the right smb.conf */
    3363       19110 :                 setenv("SMB_CONF_PATH", filename, 1);
    3364             : 
    3365             :                 /* set the context used by the lp_*() function
    3366             :                    varients */
    3367       19110 :                 global_loadparm_context = lp_ctx;
    3368       19110 :                 lp_ctx->loaded = true;
    3369             :         }
    3370             : 
    3371       19254 :         return bRetval;
    3372             : }
    3373             : 
    3374          51 : bool lpcfg_load_no_global(struct loadparm_context *lp_ctx, const char *filename)
    3375             : {
    3376          51 :     return lpcfg_load_internal(lp_ctx, filename, false);
    3377             : }
    3378             : 
    3379       20002 : bool lpcfg_load(struct loadparm_context *lp_ctx, const char *filename)
    3380             : {
    3381       20002 :     return lpcfg_load_internal(lp_ctx, filename, true);
    3382             : }
    3383             : 
    3384             : /**
    3385             :  * Return the max number of services.
    3386             :  */
    3387             : 
    3388        4176 : int lpcfg_numservices(struct loadparm_context *lp_ctx)
    3389             : {
    3390        4176 :         if (lp_ctx->s3_fns) {
    3391           0 :                 return lp_ctx->s3_fns->get_numservices();
    3392             :         }
    3393             : 
    3394        4176 :         return lp_ctx->iNumServices;
    3395             : }
    3396             : 
    3397             : /**
    3398             :  * Display the contents of the services array in human-readable form.
    3399             :  */
    3400             : 
    3401         670 : void lpcfg_dump(struct loadparm_context *lp_ctx, FILE *f, bool show_defaults,
    3402             :              int maxtoprint)
    3403             : {
    3404             :         int iService;
    3405             : 
    3406         670 :         if (lp_ctx->s3_fns) {
    3407           0 :                 lp_ctx->s3_fns->dump(f, show_defaults, maxtoprint);
    3408           0 :                 return;
    3409             :         }
    3410             : 
    3411         670 :         lpcfg_dump_globals(lp_ctx, f, show_defaults);
    3412             : 
    3413         670 :         lpcfg_dump_a_service(lp_ctx->sDefault, lp_ctx->sDefault, f, lp_ctx->flags, show_defaults);
    3414             : 
    3415        2873 :         for (iService = 0; iService < maxtoprint; iService++)
    3416        2203 :                 lpcfg_dump_one(f, show_defaults, lp_ctx->services[iService], lp_ctx->sDefault);
    3417             : }
    3418             : 
    3419             : /**
    3420             :  * Display the contents of one service in human-readable form.
    3421             :  */
    3422        2203 : void lpcfg_dump_one(FILE *f, bool show_defaults, struct loadparm_service *service, struct loadparm_service *sDefault)
    3423             : {
    3424        2203 :         if (service != NULL) {
    3425        2203 :                 if (service->szService[0] == '\0')
    3426           0 :                         return;
    3427        2203 :                 lpcfg_dump_a_service(service, sDefault, f, NULL, show_defaults);
    3428             :         }
    3429             : }
    3430             : 
    3431        4258 : struct loadparm_service *lpcfg_servicebynum(struct loadparm_context *lp_ctx,
    3432             :                                             int snum)
    3433             : {
    3434        4258 :         if (lp_ctx->s3_fns) {
    3435           0 :                 return lp_ctx->s3_fns->get_servicebynum(snum);
    3436             :         }
    3437             : 
    3438        4258 :         return lp_ctx->services[snum];
    3439             : }
    3440             : 
    3441        7542 : struct loadparm_service *lpcfg_service(struct loadparm_context *lp_ctx,
    3442             :                                     const char *service_name)
    3443             : {
    3444             :         int iService;
    3445             :         char *serviceName;
    3446             : 
    3447        7542 :         if (lp_ctx->s3_fns) {
    3448           0 :                 return lp_ctx->s3_fns->get_service(service_name);
    3449             :         }
    3450             : 
    3451       57186 :         for (iService = lp_ctx->iNumServices - 1; iService >= 0; iService--) {
    3452      104848 :                 if (lp_ctx->services[iService] &&
    3453       57111 :                     lp_ctx->services[iService]->szService) {
    3454             :                         /*
    3455             :                          * The substitution here is used to support %U is
    3456             :                          * service names
    3457             :                          */
    3458       57111 :                         serviceName = standard_sub_basic(
    3459       57111 :                                         lp_ctx->services[iService],
    3460       57111 :                                         lp_ctx->services[iService]->szService);
    3461       57111 :                         if (strequal(serviceName, service_name)) {
    3462        7467 :                                 talloc_free(serviceName);
    3463        7467 :                                 return lp_ctx->services[iService];
    3464             :                         }
    3465       49644 :                         talloc_free(serviceName);
    3466             :                 }
    3467             :         }
    3468             : 
    3469          75 :         DEBUG(7,("lpcfg_servicenumber: couldn't find %s\n", service_name));
    3470          75 :         return NULL;
    3471             : }
    3472             : 
    3473        7820 : const char *lpcfg_servicename(const struct loadparm_service *service)
    3474             : {
    3475        7820 :         return service ? lpcfg_string((const char *)service->szService) : NULL;
    3476             : }
    3477             : 
    3478          54 : struct smb_iconv_handle *lpcfg_iconv_handle(struct loadparm_context *lp_ctx)
    3479             : {
    3480          54 :         if (lp_ctx == NULL) {
    3481           0 :                 return get_iconv_handle();
    3482             :         }
    3483          54 :         return lp_ctx->iconv_handle;
    3484             : }
    3485             : 
    3486       52259 : _PUBLIC_ void reload_charcnv(struct loadparm_context *lp_ctx)
    3487             : {
    3488       52259 :         if (!lp_ctx->global) {
    3489          79 :                 return;
    3490             :         }
    3491             : 
    3492       52180 :         lp_ctx->iconv_handle =
    3493       52180 :                 reinit_iconv_handle(lp_ctx,
    3494             :                                     lpcfg_dos_charset(lp_ctx),
    3495             :                                     lpcfg_unix_charset(lp_ctx));
    3496       52180 :         if (lp_ctx->iconv_handle == NULL) {
    3497           0 :                 smb_panic("reinit_iconv_handle failed");
    3498             :         }
    3499             : }
    3500             : 
    3501          48 : _PUBLIC_ char *lpcfg_tls_keyfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
    3502             : {
    3503          48 :         return lpcfg_private_path(mem_ctx, lp_ctx, lpcfg__tls_keyfile(lp_ctx));
    3504             : }
    3505             : 
    3506          48 : _PUBLIC_ char *lpcfg_tls_certfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
    3507             : {
    3508          48 :         return lpcfg_private_path(mem_ctx, lp_ctx, lpcfg__tls_certfile(lp_ctx));
    3509             : }
    3510             : 
    3511         453 : _PUBLIC_ char *lpcfg_tls_cafile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
    3512             : {
    3513         453 :         return lpcfg_private_path(mem_ctx, lp_ctx, lpcfg__tls_cafile(lp_ctx));
    3514             : }
    3515             : 
    3516         453 : _PUBLIC_ char *lpcfg_tls_crlfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
    3517             : {
    3518         453 :         return lpcfg_private_path(mem_ctx, lp_ctx, lpcfg__tls_crlfile(lp_ctx));
    3519             : }
    3520             : 
    3521          48 : _PUBLIC_ char *lpcfg_tls_dhpfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
    3522             : {
    3523          48 :         return lpcfg_private_path(mem_ctx, lp_ctx, lpcfg__tls_dhpfile(lp_ctx));
    3524             : }
    3525             : 
    3526      120335 : struct gensec_settings *lpcfg_gensec_settings(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
    3527             : {
    3528      120335 :         struct gensec_settings *settings = talloc_zero(mem_ctx, struct gensec_settings);
    3529      120335 :         if (settings == NULL)
    3530           0 :                 return NULL;
    3531      120335 :         SMB_ASSERT(lp_ctx != NULL);
    3532      120335 :         settings->lp_ctx = talloc_reference(settings, lp_ctx);
    3533      120335 :         settings->target_hostname = lpcfg_parm_string(lp_ctx, NULL, "gensec", "target_hostname");
    3534      120335 :         return settings;
    3535             : }
    3536             : 
    3537      339472 : int lpcfg_server_role(struct loadparm_context *lp_ctx)
    3538             : {
    3539      339472 :         int domain_master = lpcfg__domain_master(lp_ctx);
    3540             : 
    3541      678944 :         return lp_find_server_role(lpcfg__server_role(lp_ctx),
    3542             :                                    lpcfg__security(lp_ctx),
    3543      339472 :                                    lpcfg__domain_logons(lp_ctx),
    3544             :                                    (domain_master == true) ||
    3545             :                                    (domain_master == Auto));
    3546             : }
    3547             : 
    3548       41570 : int lpcfg_security(struct loadparm_context *lp_ctx)
    3549             : {
    3550       41570 :         return lp_find_security(lpcfg__server_role(lp_ctx),
    3551             :                                 lpcfg__security(lp_ctx));
    3552             : }
    3553             : 
    3554       38168 : int lpcfg_client_max_protocol(struct loadparm_context *lp_ctx)
    3555             : {
    3556       38168 :         int client_max_protocol = lpcfg__client_max_protocol(lp_ctx);
    3557       38168 :         if (client_max_protocol == PROTOCOL_DEFAULT) {
    3558       38152 :                 return PROTOCOL_LATEST;
    3559             :         }
    3560          16 :         return client_max_protocol;
    3561             : }
    3562             : 
    3563        3650 : int lpcfg_client_ipc_min_protocol(struct loadparm_context *lp_ctx)
    3564             : {
    3565        3650 :         int client_ipc_min_protocol = lpcfg__client_ipc_min_protocol(lp_ctx);
    3566        3650 :         if (client_ipc_min_protocol == PROTOCOL_DEFAULT) {
    3567        3650 :                 client_ipc_min_protocol = lpcfg_client_min_protocol(lp_ctx);
    3568             :         }
    3569        3650 :         if (client_ipc_min_protocol < PROTOCOL_NT1) {
    3570        3389 :                 return PROTOCOL_NT1;
    3571             :         }
    3572         261 :         return client_ipc_min_protocol;
    3573             : }
    3574             : 
    3575        3650 : int lpcfg_client_ipc_max_protocol(struct loadparm_context *lp_ctx)
    3576             : {
    3577        3650 :         int client_ipc_max_protocol = lpcfg__client_ipc_max_protocol(lp_ctx);
    3578        3650 :         if (client_ipc_max_protocol == PROTOCOL_DEFAULT) {
    3579        3650 :                 return PROTOCOL_LATEST;
    3580             :         }
    3581           0 :         if (client_ipc_max_protocol < PROTOCOL_NT1) {
    3582           0 :                 return PROTOCOL_NT1;
    3583             :         }
    3584           0 :         return client_ipc_max_protocol;
    3585             : }
    3586             : 
    3587      101935 : int lpcfg_client_ipc_signing(struct loadparm_context *lp_ctx)
    3588             : {
    3589      101935 :         int client_ipc_signing = lpcfg__client_ipc_signing(lp_ctx);
    3590      101935 :         if (client_ipc_signing == SMB_SIGNING_DEFAULT) {
    3591      101935 :                 return SMB_SIGNING_REQUIRED;
    3592             :         }
    3593           0 :         return client_ipc_signing;
    3594             : }
    3595             : 
    3596       90968 : enum credentials_use_kerberos lpcfg_client_use_kerberos(struct loadparm_context *lp_ctx)
    3597             : {
    3598       90968 :         if (lpcfg_weak_crypto(lp_ctx) == SAMBA_WEAK_CRYPTO_DISALLOWED) {
    3599           0 :                 return CRED_USE_KERBEROS_REQUIRED;
    3600             :         }
    3601             : 
    3602       90968 :         return lpcfg__client_use_kerberos(lp_ctx);
    3603             : }
    3604             : 
    3605       12893 : bool lpcfg_server_signing_allowed(struct loadparm_context *lp_ctx, bool *mandatory)
    3606             : {
    3607       12893 :         bool allowed = true;
    3608       12893 :         enum smb_signing_setting signing_setting = lpcfg_server_signing(lp_ctx);
    3609             : 
    3610       12893 :         *mandatory = false;
    3611             : 
    3612       12893 :         if (signing_setting == SMB_SIGNING_DEFAULT) {
    3613             :                 /*
    3614             :                  * If we are a domain controller, SMB signing is
    3615             :                  * really important, as it can prevent a number of
    3616             :                  * attacks on communications between us and the
    3617             :                  * clients
    3618             :                  *
    3619             :                  * However, it really sucks (no sendfile, CPU
    3620             :                  * overhead) performance-wise when used on a
    3621             :                  * file server, so disable it by default
    3622             :                  * on non-DCs
    3623             :                  */
    3624             : 
    3625       11887 :                 if (lpcfg_server_role(lp_ctx) >= ROLE_ACTIVE_DIRECTORY_DC) {
    3626        9593 :                         signing_setting = SMB_SIGNING_REQUIRED;
    3627             :                 } else {
    3628        2294 :                         signing_setting = SMB_SIGNING_OFF;
    3629             :                 }
    3630             :         }
    3631             : 
    3632       12893 :         switch (signing_setting) {
    3633       10465 :         case SMB_SIGNING_REQUIRED:
    3634       10465 :                 *mandatory = true;
    3635       10465 :                 break;
    3636         134 :         case SMB_SIGNING_DESIRED:
    3637             :         case SMB_SIGNING_IF_REQUIRED:
    3638         134 :                 break;
    3639        2294 :         case SMB_SIGNING_OFF:
    3640        2294 :                 allowed = false;
    3641        2294 :                 break;
    3642           0 :         case SMB_SIGNING_DEFAULT:
    3643             :         case SMB_SIGNING_IPC_DEFAULT:
    3644           0 :                 smb_panic(__location__);
    3645             :                 break;
    3646             :         }
    3647             : 
    3648       12893 :         return allowed;
    3649             : }
    3650             : 
    3651      160003 : int lpcfg_tdb_hash_size(struct loadparm_context *lp_ctx, const char *name)
    3652             : {
    3653             :         const char *base;
    3654             : 
    3655      160003 :         if (name == NULL) {
    3656           0 :                 return 0;
    3657             :         }
    3658             : 
    3659      160003 :         base = strrchr_m(name, '/');
    3660      160003 :         if (base != NULL) {
    3661      160003 :                 base += 1;
    3662             :         } else {
    3663           0 :                 base = name;
    3664             :         }
    3665      160003 :         return lpcfg_parm_int(lp_ctx, NULL, "tdb_hashsize", base, 0);
    3666             : 
    3667             : }
    3668             : 
    3669      593821 : int lpcfg_tdb_flags(struct loadparm_context *lp_ctx, int tdb_flags)
    3670             : {
    3671      593821 :         if (!lpcfg_use_mmap(lp_ctx)) {
    3672       13574 :                 tdb_flags |= TDB_NOMMAP;
    3673             :         }
    3674      593821 :         return tdb_flags;
    3675             : }
    3676             : 
    3677             : /*
    3678             :  * Do not allow LanMan auth if unless NTLMv1 is also allowed
    3679             :  *
    3680             :  * This also ensures it is disabled if NTLM is totally disabled
    3681             :  */
    3682       10306 : bool lpcfg_lanman_auth(struct loadparm_context *lp_ctx)
    3683             : {
    3684       10306 :         enum ntlm_auth_level ntlm_auth_level = lpcfg_ntlm_auth(lp_ctx);
    3685             : 
    3686       10306 :         if (ntlm_auth_level == NTLM_AUTH_ON) {
    3687        9324 :                 return lpcfg__lanman_auth(lp_ctx);
    3688             :         } else {
    3689         982 :                 return false;
    3690             :         }
    3691             : }
    3692             : 
    3693       30942 : static char *lpcfg_noop_substitution_fn(
    3694             :                         TALLOC_CTX *mem_ctx,
    3695             :                         const struct loadparm_substitution *lp_sub,
    3696             :                         const char *raw_value,
    3697             :                         void *private_data)
    3698             : {
    3699       30942 :         return talloc_strdup(mem_ctx, raw_value);
    3700             : }
    3701             : 
    3702             : static const struct loadparm_substitution global_noop_substitution = {
    3703             :         .substituted_string_fn = lpcfg_noop_substitution_fn,
    3704             : };
    3705             : 
    3706       31207 : const struct loadparm_substitution *lpcfg_noop_substitution(void)
    3707             : {
    3708       31207 :         return &global_noop_substitution;
    3709             : }
    3710             : 
    3711      277388 : char *lpcfg_substituted_string(TALLOC_CTX *mem_ctx,
    3712             :                                const struct loadparm_substitution *lp_sub,
    3713             :                                const char *raw_value)
    3714             : {
    3715      363986 :         return lp_sub->substituted_string_fn(mem_ctx,
    3716             :                                              lp_sub,
    3717             :                                              raw_value,
    3718       86598 :                                              lp_sub->private_data);
    3719             : }
    3720             : 
    3721             : /**
    3722             :  * @brief Parse a string value of a given parameter to its integer enum value.
    3723             :  *
    3724             :  * @param[in]  param_name    The parameter name (e.g. 'client smb encrypt')
    3725             :  *
    3726             :  * @param[in]  param_value   The parameter value (e.g. 'required').
    3727             :  *
    3728             :  * @return The integer value of the enum the param_value matches or INT32_MIN
    3729             :  * on error.
    3730             :  */
    3731         115 : int32_t lpcfg_parse_enum_vals(const char *param_name,
    3732             :                               const char *param_value)
    3733             : {
    3734         115 :         struct parm_struct *parm = NULL;
    3735         115 :         int32_t ret = INT32_MIN;
    3736             :         bool ok;
    3737             : 
    3738         115 :         parm = lpcfg_parm_struct(NULL, param_name);
    3739         115 :         if (parm == NULL) {
    3740           0 :                 return INT32_MIN;
    3741             :         }
    3742             : 
    3743         115 :         ok = lp_set_enum_parm(parm, param_value, &ret);
    3744         115 :         if (!ok) {
    3745           0 :                 return INT32_MIN;
    3746             :         }
    3747             : 
    3748         115 :         return ret;
    3749             : }

Generated by: LCOV version 1.13