s3-param: fix set_inherit_acls().
[ira/wip.git] / source3 / param / loadparm.c
index 9bd664534ae7782c722b4ed39147b00fe5576780..9a0f834f99a6dffd0b806ecd68619ea74c25596d 100644 (file)
 #include "includes.h"
 #include "printing.h"
 
+#ifdef HAVE_SYS_SYSCTL_H
+#include <sys/sysctl.h>
+#endif
+
+#ifdef HAVE_HTTPCONNECTENCRYPT
+#include <cups/http.h>
+#endif
+
 bool bLoaded = False;
 
-extern enum protocol_types Protocol;
 extern userdom_struct current_user_info;
 
 #ifndef GLOBAL_NAME
@@ -94,8 +101,6 @@ static int config_backend = CONFIG_BACKEND_FILE;
 #define USERSHARE_VALID 1
 #define USERSHARE_PENDING_DELETE 2
 
-extern int extra_time_offset;
-
 static bool defaults_saved = False;
 
 struct param_opt_struct {
@@ -121,6 +126,8 @@ struct global {
        char *szDeletePrinterCommand;
        char *szOs2DriverMap;
        char *szLockDir;
+       char *szStateDir;
+       char *szCacheDir;
        char *szPidDir;
        char *szRootdir;
        char *szDefaultService;
@@ -195,6 +202,7 @@ struct global {
        bool bWinbindOfflineLogon;
        bool bWinbindNormalizeNames;
        bool bWinbindRpcOnly;
+       bool bCreateKrb5Conf;
        char *szIdmapBackend;
        char *szIdmapAllocBackend;
        char *szAddShareCommand;
@@ -250,16 +258,20 @@ struct global {
        char *szLdapIdmapSuffix;
        char *szLdapGroupSuffix;
        int ldap_ssl;
+       bool ldap_ssl_ads;
+       int ldap_follow_referral;
        char *szLdapSuffix;
        char *szLdapAdminDn;
        int ldap_debug_level;
        int ldap_debug_threshold;
        int iAclCompat;
        char *szCupsServer;
+       int CupsEncrypt;
        char *szIPrintServer;
        char *ctdbdSocket;
        char **szClusterAddresses;
        bool clustering;
+       int ctdb_timeout;
        int ldap_passwd_sync;
        int ldap_replication_sleep;
        int ldap_timeout; /* This is initialised in init_globals */
@@ -322,7 +334,8 @@ struct global {
        bool bHostnameLookups;
        bool bUnixExtensions;
        bool bDisableNetbios;
-       bool bUseKerberosKeytab;
+       char * szDedicatedKeytabFile;
+       int  iKerberosMethod;
        bool bDeferSharingViolations;
        bool bEnablePrivileges;
        bool bASUSupport;
@@ -342,6 +355,9 @@ struct global {
        int iminreceivefile;
        struct param_opt_struct *param_opt;
        int cups_connection_timeout;
+       char *szSMBPerfcountModule;
+       bool bMapUntrustedToDomain;
+       bool bFakeDirCreateTimes;
 };
 
 static struct global Globals;
@@ -353,7 +369,7 @@ struct service {
        bool valid;
        bool autoloaded;
        int usershare;
-       time_t usershare_last_mod;
+       struct timespec usershare_last_mod;
        char *szService;
        char *szPath;
        char *szUsername;
@@ -436,6 +452,7 @@ struct service {
        bool bMap_system;
        bool bMap_hidden;
        bool bMap_archive;
+       bool bStoreCreateTime;
        bool bStoreDosAttributes;
        bool bDmapiSupport;
        bool bLocking;
@@ -459,7 +476,6 @@ struct service {
        bool bDosFilemode;
        bool bDosFiletimes;
        bool bDosFiletimeResolution;
-       bool bFakeDirCreateTimes;
        bool bBlockingLocks;
        bool bInheritPerms;
        bool bInheritACLS;
@@ -497,7 +513,7 @@ static struct service sDefault = {
        True,                   /* valid */
        False,                  /* not autoloaded */
        0,                      /* not a usershare */
-       (time_t)0,              /* No last mod time */
+       {0, },                  /* No last mod time */
        NULL,                   /* szService */
        NULL,                   /* szPath */
        NULL,                   /* szUsername */
@@ -580,6 +596,7 @@ static struct service sDefault = {
        False,                  /* bMap_system */
        False,                  /* bMap_hidden */
        True,                   /* bMap_archive */
+       False,                  /* bStoreCreateTime */
        False,                  /* bStoreDosAttributes */
        False,                  /* bDmapiSupport */
        True,                   /* bLocking */
@@ -603,7 +620,6 @@ static struct service sDefault = {
        False,                  /* bDosFilemode */
        True,                   /* bDosFiletimes */
        False,                  /* bDosFiletimeResolution */
-       False,                  /* bFakeDirCreateTimes */
        True,                   /* bBlockingLocks */
        False,                  /* bInheritPerms */
        False,                  /* bInheritACLS */
@@ -673,7 +689,10 @@ static void set_allowed_client_auth(void);
 
 static void *lp_local_ptr(struct service *service, void *ptr);
 
+static void add_to_file_list(const char *fname, const char *subfname);
+
 static const struct enum_list enum_protocol[] = {
+       {PROTOCOL_SMB2, "SMB2"},
        {PROTOCOL_NT1, "NT1"},
        {PROTOCOL_LANMAN2, "LANMAN2"},
        {PROTOCOL_LANMAN1, "LANMAN1"},
@@ -722,24 +741,17 @@ static const struct enum_list enum_ldap_sasl_wrapping[] = {
 
 static const struct enum_list enum_ldap_ssl[] = {
        {LDAP_SSL_OFF, "no"},
-       {LDAP_SSL_OFF, "No"},
        {LDAP_SSL_OFF, "off"},
-       {LDAP_SSL_OFF, "Off"},
        {LDAP_SSL_START_TLS, "start tls"},
-       {LDAP_SSL_START_TLS, "Start_tls"},
+       {LDAP_SSL_START_TLS, "start_tls"},
        {-1, NULL}
 };
 
 static const struct enum_list enum_ldap_passwd_sync[] = {
        {LDAP_PASSWD_SYNC_OFF, "no"},
-       {LDAP_PASSWD_SYNC_OFF, "No"},
        {LDAP_PASSWD_SYNC_OFF, "off"},
-       {LDAP_PASSWD_SYNC_OFF, "Off"},
-       {LDAP_PASSWD_SYNC_ON, "Yes"},
        {LDAP_PASSWD_SYNC_ON, "yes"},
        {LDAP_PASSWD_SYNC_ON, "on"},
-       {LDAP_PASSWD_SYNC_ON, "On"},
-       {LDAP_PASSWD_SYNC_ONLY, "Only"},
        {LDAP_PASSWD_SYNC_ONLY, "only"},
        {-1, NULL}
 };
@@ -777,6 +789,8 @@ static const struct enum_list enum_case[] = {
        {-1, NULL}
 };
 
+
+
 static const struct enum_list enum_bool_auto[] = {
        {False, "No"},
        {False, "False"},
@@ -868,9 +882,20 @@ static const struct enum_list enum_config_backend[] = {
        {-1, NULL}
 };
 
+/* ADS kerberos ticket verification options */
+
+static const struct enum_list enum_kerberos_method[] = {
+       {KERBEROS_VERIFY_SECRETS, "default"},
+       {KERBEROS_VERIFY_SECRETS, "secrets only"},
+       {KERBEROS_VERIFY_SYSTEM_KEYTAB, "system keytab"},
+       {KERBEROS_VERIFY_DEDICATED_KEYTAB, "dedicated keytab"},
+       {KERBEROS_VERIFY_SECRETS_AND_KEYTAB, "secrets and keytab"},
+       {-1, NULL}
+};
+
 /* Note: We do not initialise the defaults union - it is not allowed in ANSI C
  *
- * The FLAG_HIDE is explicit. Paramters set this way do NOT appear in any edit
+ * The FLAG_HIDE is explicit. Parameters set this way do NOT appear in any edit
  * screen in SWAT. This is used to exclude parameters as well as to squash all
  * parameters that have been duplicated by pseudonyms.
  *
@@ -879,7 +904,7 @@ static const struct enum_list enum_config_backend[] = {
  *      Set FLAG_SHARE and FLAG_PRINT to specifically display parameters in
  *        respective views.
  *
- * NOTE2: Handling of duplicated (synonym) paramters:
+ * NOTE2: Handling of duplicated (synonym) parameters:
  *     Only the first occurance of a parameter should be enabled by FLAG_BASIC
  *     and/or FLAG_ADVANCED. All duplicates following the first mention should be
  *     set to FLAG_HIDE. ie: Make you must place the parameter that has the preferred
@@ -1024,7 +1049,7 @@ static struct parm_struct parm_table[] = {
                .ptr            = &Globals.ConfigBackend,
                .special        = NULL,
                .enum_list      = enum_config_backend,
-               .flags          = FLAG_ADVANCED,
+               .flags          = FLAG_HIDE|FLAG_ADVANCED|FLAG_META,
        },
 
        {N_("Security Options"), P_SEP, P_SEPARATOR},
@@ -1752,14 +1777,33 @@ static struct parm_struct parm_table[] = {
                .flags          = FLAG_ADVANCED | FLAG_GLOBAL,
        },
        {
-               .label          = "use kerberos keytab",
-               .type           = P_BOOL,
+               .label          = "dedicated keytab file",
+               .type           = P_STRING,
                .p_class        = P_GLOBAL,
-               .ptr            = &Globals.bUseKerberosKeytab,
+               .ptr            = &Globals.szDedicatedKeytabFile,
                .special        = NULL,
                .enum_list      = NULL,
                .flags          = FLAG_ADVANCED,
        },
+       {
+               .label          = "kerberos method",
+               .type           = P_ENUM,
+               .p_class        = P_GLOBAL,
+               .ptr            = &Globals.iKerberosMethod,
+               .special        = NULL,
+               .enum_list      = enum_kerberos_method,
+               .flags          = FLAG_ADVANCED,
+       },
+       {
+               .label          = "map untrusted to domain",
+               .type           = P_BOOL,
+               .p_class        = P_GLOBAL,
+               .ptr            = &Globals.bMapUntrustedToDomain,
+               .special        = NULL,
+               .enum_list      = NULL,
+               .flags          = FLAG_ADVANCED | FLAG_GLOBAL,
+       },
+
 
        {N_("Logging Options"), P_SEP, P_SEPARATOR},
 
@@ -2498,6 +2542,15 @@ static struct parm_struct parm_table[] = {
                .enum_list      = NULL,
                .flags          = FLAG_ADVANCED | FLAG_GLOBAL,
        },
+       {
+               .label          = "ctdb timeout",
+               .type           = P_INTEGER,
+               .p_class        = P_GLOBAL,
+               .ptr            = &Globals.ctdb_timeout,
+               .special        = NULL,
+               .enum_list      = NULL,
+               .flags          = FLAG_ADVANCED | FLAG_GLOBAL,
+       },
 
        {N_("Printing Options"), P_SEP, P_SEPARATOR},
 
@@ -2601,6 +2654,16 @@ static struct parm_struct parm_table[] = {
                .flags          = FLAG_ADVANCED | FLAG_PRINT | FLAG_GLOBAL,
        },
        {
+               .label          = "cups encrypt",
+               .type           = P_ENUM,
+               .p_class        = P_GLOBAL,
+               .ptr            = &Globals.CupsEncrypt,
+               .special        = NULL,
+               .enum_list      = enum_bool_auto,
+               .flags          = FLAG_ADVANCED | FLAG_PRINT | FLAG_GLOBAL,
+       },
+       {
+
                .label          = "cups connection timeout",
                .type           = P_INTEGER,
                .p_class        = P_GLOBAL,
@@ -3019,6 +3082,15 @@ static struct parm_struct parm_table[] = {
                .enum_list      = NULL,
                .flags          = FLAG_ADVANCED,
        },
+       {
+               .label          = "store create time",
+               .type           = P_BOOL,
+               .p_class        = P_LOCAL,
+               .ptr            = &sDefault.bStoreCreateTime,
+               .special        = NULL,
+               .enum_list      = NULL,
+               .flags          = FLAG_ADVANCED | FLAG_SHARE | FLAG_GLOBAL,
+       },
        {
                .label          = "store dos attributes",
                .type           = P_BOOL,
@@ -3212,6 +3284,8 @@ static struct parm_struct parm_table[] = {
                .type           = P_LIST,
                .p_class        = P_GLOBAL,
                .ptr            = &Globals.szInitLogonDelayedHosts,
+               .special        = NULL,
+               .enum_list      = NULL,
                .flags          = FLAG_ADVANCED,
        },
 
@@ -3220,6 +3294,8 @@ static struct parm_struct parm_table[] = {
                .type           = P_INTEGER,
                .p_class        = P_GLOBAL,
                .ptr            = &Globals.InitLogonDelay,
+               .special        = NULL,
+               .enum_list      = NULL,
                .flags          = FLAG_ADVANCED,
 
        },
@@ -3308,22 +3384,22 @@ static struct parm_struct parm_table[] = {
                .flags          = FLAG_BASIC | FLAG_ADVANCED | FLAG_SHARE | FLAG_PRINT,
        },
        {
-               .label          = "access based share enum",
+               .label          = "browsable",
                .type           = P_BOOL,
                .p_class        = P_LOCAL,
-               .ptr            = &sDefault.bAccessBasedShareEnum,
+               .ptr            = &sDefault.bBrowseable,
                .special        = NULL,
                .enum_list      = NULL,
-               .flags          = FLAG_BASIC | FLAG_ADVANCED | FLAG_SHARE
+               .flags          = FLAG_HIDE,
        },
        {
-               .label          = "browsable",
+               .label          = "access based share enum",
                .type           = P_BOOL,
                .p_class        = P_LOCAL,
-               .ptr            = &sDefault.bBrowseable,
+               .ptr            = &sDefault.bAccessBasedShareEnum,
                .special        = NULL,
                .enum_list      = NULL,
-               .flags          = FLAG_HIDE,
+               .flags          = FLAG_BASIC | FLAG_ADVANCED | FLAG_SHARE
        },
        {
                .label          = "enhanced browsing",
@@ -3500,7 +3576,7 @@ static struct parm_struct parm_table[] = {
                .ptr            = &sDefault.bShareModes,
                .special        = NULL,
                .enum_list      = NULL,
-               .flags          = FLAG_ADVANCED | FLAG_SHARE | FLAG_GLOBAL,
+               .flags          = FLAG_ADVANCED | FLAG_SHARE | FLAG_GLOBAL | FLAG_DEPRECATED,
        },
 
        {N_("Ldap Options"), P_SEP, P_SEPARATOR},
@@ -3595,6 +3671,24 @@ static struct parm_struct parm_table[] = {
                .enum_list      = enum_ldap_ssl,
                .flags          = FLAG_ADVANCED,
        },
+       {
+               .label          = "ldap ssl ads",
+               .type           = P_BOOL,
+               .p_class        = P_GLOBAL,
+               .ptr            = &Globals.ldap_ssl_ads,
+               .special        = NULL,
+               .enum_list      = NULL,
+               .flags          = FLAG_ADVANCED,
+       },
+       {
+               .label          = "ldap follow referral",
+               .type           = P_ENUM,
+               .p_class        = P_GLOBAL,
+               .ptr            = &Globals.ldap_follow_referral,
+               .special        = NULL,
+               .enum_list      = enum_bool_auto,
+               .flags          = FLAG_ADVANCED,
+       },
        {
                .label          = "ldap timeout",
                .type           = P_INTEGER,
@@ -3698,7 +3792,7 @@ static struct parm_struct parm_table[] = {
                .ptr            = &Globals.szConfigFile,
                .special        = NULL,
                .enum_list      = NULL,
-               .flags          = FLAG_HIDE,
+               .flags          = FLAG_HIDE|FLAG_META,
        },
        {
                .label          = "preload",
@@ -3736,6 +3830,24 @@ static struct parm_struct parm_table[] = {
                .enum_list      = NULL,
                .flags          = FLAG_HIDE,
        },
+       {
+               .label          = "state directory",
+               .type           = P_STRING,
+               .p_class        = P_GLOBAL,
+               .ptr            = &Globals.szStateDir,
+               .special        = NULL,
+               .enum_list      = NULL,
+               .flags          = FLAG_ADVANCED,
+       },
+       {
+               .label          = "cache directory",
+               .type           = P_STRING,
+               .p_class        = P_GLOBAL,
+               .ptr            = &Globals.szCacheDir,
+               .special        = NULL,
+               .enum_list      = NULL,
+               .flags          = FLAG_ADVANCED,
+       },
        {
                .label          = "pid directory",
                .type           = P_STRING,
@@ -3943,7 +4055,7 @@ static struct parm_struct parm_table[] = {
                .ptr            = &sDefault.szInclude,
                .special        = handle_include,
                .enum_list      = NULL,
-               .flags          = FLAG_HIDE,
+               .flags          = FLAG_HIDE|FLAG_META,
        },
        {
                .label          = "preexec",
@@ -4200,11 +4312,11 @@ static struct parm_struct parm_table[] = {
        {
                .label          = "fake directory create times",
                .type           = P_BOOL,
-               .p_class        = P_LOCAL,
-               .ptr            = &sDefault.bFakeDirCreateTimes,
+               .p_class        = P_GLOBAL,
+               .ptr            = &Globals.bFakeDirCreateTimes,
                .special        = NULL,
                .enum_list      = NULL,
-               .flags          = FLAG_ADVANCED | FLAG_SHARE | FLAG_GLOBAL,
+               .flags          = FLAG_ADVANCED | FLAG_GLOBAL,
        },
        {
                .label          = "panic action",
@@ -4215,6 +4327,15 @@ static struct parm_struct parm_table[] = {
                .enum_list      = NULL,
                .flags          = FLAG_ADVANCED,
        },
+       {
+               .label          = "perfcount module",
+               .type           = P_STRING,
+               .p_class        = P_GLOBAL,
+               .ptr            = &Globals.szSMBPerfcountModule,
+               .special        = NULL,
+               .enum_list      = NULL,
+               .flags          = FLAG_ADVANCED,
+       },
 
        {N_("VFS module options"), P_SEP, P_SEPARATOR},
 
@@ -4495,6 +4616,15 @@ static struct parm_struct parm_table[] = {
                .enum_list      = NULL,
                .flags          = FLAG_ADVANCED,
        },
+       {
+               .label          = "create krb5 conf",
+               .type           = P_BOOL,
+               .p_class        = P_GLOBAL,
+               .ptr            = &Globals.bCreateKrb5Conf,
+               .special        = NULL,
+               .enum_list      = NULL,
+               .flags          = FLAG_ADVANCED,
+       },
 
        {NULL,  P_BOOL,  P_NONE,  NULL,  NULL,  NULL,  0}
 };
@@ -4576,7 +4706,7 @@ static void init_printer_values(struct service *pService)
                string_set(&pService->szLpqcommand, "vlp lpq %p");
                string_set(&pService->szLprmcommand, "vlp lprm %p %j");
                string_set(&pService->szLppausecommand, "vlp lppause %p %j");
-               string_set(&pService->szLpresumecommand, "vlp lpresum %p %j");
+               string_set(&pService->szLpresumecommand, "vlp lpresume %p %j");
                string_set(&pService->szQueuepausecommand, "vlp queuepause %p");
                string_set(&pService->szQueueresumecommand, "vlp queueresume %p");
                break;
@@ -4584,6 +4714,43 @@ static void init_printer_values(struct service *pService)
 
        }
 }
+/**
+ *  Function to return the default value for the maximum number of open
+ *  file descriptors permitted.  This function tries to consult the
+ *  kernel-level (sysctl) and ulimit (getrlimit()) values and goes
+ *  the smaller of those.
+ */
+static int max_open_files(void)
+{
+       int sysctl_max = MAX_OPEN_FILES;
+       int rlimit_max = MAX_OPEN_FILES;
+
+#ifdef HAVE_SYSCTLBYNAME
+       {
+               size_t size = sizeof(sysctl_max);
+               sysctlbyname("kern.maxfilesperproc", &sysctl_max, &size, NULL,
+                            0);
+       }
+#endif
+
+#if (defined(HAVE_GETRLIMIT) && defined(RLIMIT_NOFILE))
+       {
+               struct rlimit rl;
+
+               ZERO_STRUCT(rl);
+
+               if (getrlimit(RLIMIT_NOFILE, &rl) == 0)
+                       rlimit_max = rl.rlim_cur;
+
+#if defined(RLIM_INFINITY)
+               if(rl.rlim_cur == RLIM_INFINITY)
+                       rlimit_max = MAX_OPEN_FILES;
+       }
+#endif
+#endif
+
+       return MIN(sysctl_max, rlimit_max);
+}
 
 /**
  * Common part of freeing allocated data for one parameter.
@@ -4639,7 +4806,7 @@ static void free_one_parameter_by_snum(int snum, struct parm_struct parm)
 {
        void *parm_ptr;
 
-       if (parm.ptr == NULL); {
+       if (parm.ptr == NULL) {
                return;
        }
 
@@ -4756,11 +4923,13 @@ static void init_globals(bool first_time_only)
        string_set(&Globals.szWorkgroup, lp_workgroup());
 
        string_set(&Globals.szPasswdProgram, "");
-       string_set(&Globals.szPidDir, get_dyn_PIDDIR());
        string_set(&Globals.szLockDir, get_dyn_LOCKDIR());
+       string_set(&Globals.szStateDir, get_dyn_STATEDIR());
+       string_set(&Globals.szCacheDir, get_dyn_CACHEDIR());
+       string_set(&Globals.szPidDir, get_dyn_PIDDIR());
        string_set(&Globals.szSocketAddress, "0.0.0.0");
 
-       if (asprintf(&s, "Samba %s", SAMBA_VERSION_STRING) < 0) {
+       if (asprintf(&s, "Samba %s", samba_version_string()) < 0) {
                smb_panic("init_globals: ENOMEM");
        }
        string_set(&Globals.szServerString, s);
@@ -4805,7 +4974,7 @@ static void init_globals(bool first_time_only)
        Globals.getwd_cache = true;
        Globals.bLargeReadwrite = True;
        Globals.max_log_size = 5000;
-       Globals.max_open_files = MAX_OPEN_FILES;
+       Globals.max_open_files = max_open_files();
        Globals.open_files_db_hash_size = SMB_OPEN_DATABASE_TDB_HASH_SIZE;
        Globals.maxprotocol = PROTOCOL_NT1;
        Globals.minprotocol = PROTOCOL_CORE;
@@ -4824,7 +4993,7 @@ static void init_globals(bool first_time_only)
        Globals.bTimestampLogs = True;
        string_set(&Globals.szLogLevel, "0");
        Globals.bDebugPrefixTimestamp = False;
-       Globals.bDebugHiresTimestamp = False;
+       Globals.bDebugHiresTimestamp = true;
        Globals.bDebugPid = False;
        Globals.bDebugUid = False;
        Globals.bDebugClass = False;
@@ -4873,12 +5042,13 @@ static void init_globals(bool first_time_only)
 #endif
        Globals.bUnixExtensions = True;
        Globals.bResetOnZeroVC = False;
+       Globals.bCreateKrb5Conf = true;
 
        /* hostname lookups can be very expensive and are broken on
           a large number of sites (tridge) */
        Globals.bHostnameLookups = False;
 
-       string_set(&Globals.szPassdbBackend, "smbpasswd");
+       string_set(&Globals.szPassdbBackend, "tdbsam");
        string_set(&Globals.szLdapSuffix, "");
        string_set(&Globals.szLdapMachineSuffix, "");
        string_set(&Globals.szLdapUserSuffix, "");
@@ -4886,10 +5056,12 @@ static void init_globals(bool first_time_only)
        string_set(&Globals.szLdapIdmapSuffix, "");
 
        string_set(&Globals.szLdapAdminDn, "");
-       Globals.ldap_ssl = LDAP_SSL_OFF;
+       Globals.ldap_ssl = LDAP_SSL_START_TLS;
+       Globals.ldap_ssl_ads = False;
        Globals.ldap_passwd_sync = LDAP_PASSWD_SYNC_OFF;
        Globals.ldap_delete_dn = False;
        Globals.ldap_replication_sleep = 1000; /* wait 1 sec for replication */
+       Globals.ldap_follow_referral = Auto;
        Globals.ldap_timeout = LDAP_DEFAULT_TIMEOUT;
        Globals.ldap_connection_timeout = LDAP_CONNECTION_DEFAULT_TIMEOUT;
        Globals.ldap_page_size = LDAP_PAGE_SIZE;
@@ -4945,6 +5117,7 @@ static void init_globals(bool first_time_only)
        string_set(&Globals.ctdbdSocket, "");
        Globals.szClusterAddresses = NULL;
        Globals.clustering = False;
+       Globals.ctdb_timeout = 0;
 
        Globals.winbind_cache_time = 300;       /* 5 minutes */
        Globals.winbind_reconnect_delay = 30;   /* 30 seconds */
@@ -4997,6 +5170,8 @@ static void init_globals(bool first_time_only)
        Globals.bRegistryShares = False;
 
        Globals.iminreceivefile = 0;
+
+       Globals.bMapUntrustedToDomain = false;
 }
 
 /*******************************************************************
@@ -5018,6 +5193,9 @@ static char *lp_string(const char *s)
 #if 0
        DEBUG(10, ("lp_string(%s)\n", s));
 #endif
+       if (!s) {
+               return NULL;
+       }
 
        ret = talloc_sub_basic(ctx,
                        get_current_username(),
@@ -5036,8 +5214,8 @@ static char *lp_string(const char *s)
 }
 
 /*
-   In this section all the functions that are used to access the 
-   parameters from the rest of the program are defined 
+   In this section all the functions that are used to access the
+   parameters from the rest of the program are defined
 */
 
 #define FN_GLOBAL_STRING(fn_name,ptr) \
@@ -5089,6 +5267,27 @@ FN_GLOBAL_STRING(lp_addprinter_cmd, &Globals.szAddPrinterCommand)
 FN_GLOBAL_STRING(lp_deleteprinter_cmd, &Globals.szDeletePrinterCommand)
 FN_GLOBAL_STRING(lp_os2_driver_map, &Globals.szOs2DriverMap)
 FN_GLOBAL_STRING(lp_lockdir, &Globals.szLockDir)
+/* If lp_statedir() and lp_cachedir() are explicitely set during the
+ * build process or in smb.conf, we use that value.  Otherwise they
+ * default to the value of lp_lockdir(). */
+char *lp_statedir(void) {
+       if ((strcmp(get_dyn_STATEDIR(), get_dyn_LOCKDIR()) != 0) ||
+           (strcmp(get_dyn_STATEDIR(), Globals.szStateDir) != 0))
+               return(lp_string(*(char **)(&Globals.szStateDir) ?
+                   *(char **)(&Globals.szStateDir) : ""));
+       else
+               return(lp_string(*(char **)(&Globals.szLockDir) ?
+                   *(char **)(&Globals.szLockDir) : ""));
+}
+char *lp_cachedir(void) {
+       if ((strcmp(get_dyn_CACHEDIR(), get_dyn_LOCKDIR()) != 0) ||
+           (strcmp(get_dyn_CACHEDIR(), Globals.szCacheDir) != 0))
+               return(lp_string(*(char **)(&Globals.szCacheDir) ?
+                   *(char **)(&Globals.szCacheDir) : ""));
+       else
+               return(lp_string(*(char **)(&Globals.szLockDir) ?
+                   *(char **)(&Globals.szLockDir) : ""));
+}
 FN_GLOBAL_STRING(lp_piddir, &Globals.szPidDir)
 FN_GLOBAL_STRING(lp_mangling_method, &Globals.szManglingMethod)
 FN_GLOBAL_INTEGER(lp_mangle_prefix, &Globals.mangle_prefix)
@@ -5096,6 +5295,7 @@ FN_GLOBAL_STRING(lp_utmpdir, &Globals.szUtmpDir)
 FN_GLOBAL_STRING(lp_wtmpdir, &Globals.szWtmpDir)
 FN_GLOBAL_BOOL(lp_utmp, &Globals.bUtmp)
 FN_GLOBAL_STRING(lp_rootdir, &Globals.szRootdir)
+FN_GLOBAL_STRING(lp_perfcount_module, &Globals.szSMBPerfcountModule)
 FN_GLOBAL_STRING(lp_defaultservice, &Globals.szDefaultService)
 FN_GLOBAL_STRING(lp_msg_command, &Globals.szMsgCommand)
 FN_GLOBAL_STRING(lp_get_quota_command, &Globals.szGetQuota)
@@ -5199,6 +5399,7 @@ FN_GLOBAL_BOOL(lp_winbind_refresh_tickets, &Globals.bWinbindRefreshTickets)
 FN_GLOBAL_BOOL(lp_winbind_offline_logon, &Globals.bWinbindOfflineLogon)
 FN_GLOBAL_BOOL(lp_winbind_normalize_names, &Globals.bWinbindNormalizeNames)
 FN_GLOBAL_BOOL(lp_winbind_rpc_only, &Globals.bWinbindRpcOnly)
+FN_GLOBAL_BOOL(lp_create_krb5_conf, &Globals.bCreateKrb5Conf)
 
 FN_GLOBAL_CONST_STRING(lp_idmap_backend, &Globals.szIdmapBackend)
 FN_GLOBAL_STRING(lp_idmap_alloc_backend, &Globals.szIdmapAllocBackend)
@@ -5210,6 +5411,8 @@ FN_GLOBAL_BOOL(lp_passdb_expand_explicit, &Globals.bPassdbExpandExplicit)
 FN_GLOBAL_STRING(lp_ldap_suffix, &Globals.szLdapSuffix)
 FN_GLOBAL_STRING(lp_ldap_admin_dn, &Globals.szLdapAdminDn)
 FN_GLOBAL_INTEGER(lp_ldap_ssl, &Globals.ldap_ssl)
+FN_GLOBAL_BOOL(lp_ldap_ssl_ads, &Globals.ldap_ssl_ads)
+FN_GLOBAL_INTEGER(lp_ldap_follow_referral, &Globals.ldap_follow_referral)
 FN_GLOBAL_INTEGER(lp_ldap_passwd_sync, &Globals.ldap_passwd_sync)
 FN_GLOBAL_BOOL(lp_ldap_delete_dn, &Globals.ldap_delete_dn)
 FN_GLOBAL_INTEGER(lp_ldap_replication_sleep, &Globals.ldap_replication_sleep)
@@ -5272,6 +5475,7 @@ FN_GLOBAL_BOOL(lp_nt_status_support, &Globals.bNTStatusSupport)
 FN_GLOBAL_BOOL(lp_stat_cache, &Globals.bStatCache)
 FN_GLOBAL_INTEGER(lp_max_stat_cache_size, &Globals.iMaxStatCacheSize)
 FN_GLOBAL_BOOL(lp_allow_trusted_domains, &Globals.bAllowTrustedDomains)
+FN_GLOBAL_BOOL(lp_map_untrusted_to_domain, &Globals.bMapUntrustedToDomain)
 FN_GLOBAL_INTEGER(lp_restrict_anonymous, &Globals.restrict_anonymous)
 FN_GLOBAL_BOOL(lp_lanman_auth, &Globals.bLanmanAuth)
 FN_GLOBAL_BOOL(lp_ntlm_auth, &Globals.bNTLMAuth)
@@ -5288,7 +5492,8 @@ FN_GLOBAL_BOOL(lp_client_use_spnego, &Globals.bClientUseSpnego)
 FN_GLOBAL_BOOL(lp_hostname_lookups, &Globals.bHostnameLookups)
 FN_LOCAL_PARM_BOOL(lp_change_notify, bChangeNotify)
 FN_LOCAL_PARM_BOOL(lp_kernel_change_notify, bKernelChangeNotify)
-FN_GLOBAL_BOOL(lp_use_kerberos_keytab, &Globals.bUseKerberosKeytab)
+FN_GLOBAL_STRING(lp_dedicated_keytab_file, &Globals.szDedicatedKeytabFile)
+FN_GLOBAL_INTEGER(lp_kerberos_method, &Globals.iKerberosMethod)
 FN_GLOBAL_BOOL(lp_defer_sharing_violations, &Globals.bDeferSharingViolations)
 FN_GLOBAL_BOOL(lp_enable_privileges, &Globals.bEnablePrivileges)
 FN_GLOBAL_BOOL(lp_enable_asu_support, &Globals.bASUSupport)
@@ -5341,11 +5546,29 @@ FN_LOCAL_LIST(lp_admin_users, szAdminUsers)
 FN_GLOBAL_LIST(lp_svcctl_list, &Globals.szServicesList)
 FN_LOCAL_STRING(lp_cups_options, szCupsOptions)
 FN_GLOBAL_STRING(lp_cups_server, &Globals.szCupsServer)
+int lp_cups_encrypt(void)
+{
+#ifdef HAVE_HTTPCONNECTENCRYPT
+       switch (Globals.CupsEncrypt) {
+               case Auto:
+                       Globals.CupsEncrypt = HTTP_ENCRYPT_REQUIRED;
+                       break;
+               case True:
+                       Globals.CupsEncrypt = HTTP_ENCRYPT_ALWAYS;
+                       break;
+               case False:
+                       Globals.CupsEncrypt = HTTP_ENCRYPT_NEVER;
+                       break;
+       }
+#endif
+       return Globals.CupsEncrypt;
+}
 FN_GLOBAL_STRING(lp_iprint_server, &Globals.szIPrintServer)
 FN_GLOBAL_INTEGER(lp_cups_connection_timeout, &Globals.cups_connection_timeout)
 FN_GLOBAL_CONST_STRING(lp_ctdbd_socket, &Globals.ctdbdSocket)
 FN_GLOBAL_LIST(lp_cluster_addresses, &Globals.szClusterAddresses)
 FN_GLOBAL_BOOL(lp_clustering, &Globals.clustering)
+FN_GLOBAL_INTEGER(lp_ctdb_timeout, &Globals.ctdb_timeout)
 FN_LOCAL_STRING(lp_printcommand, szPrintcommand)
 FN_LOCAL_STRING(lp_lpqcommand, szLpqcommand)
 FN_LOCAL_STRING(lp_lprmcommand, szLprmcommand)
@@ -5395,6 +5618,7 @@ FN_LOCAL_BOOL(lp_administrative_share, bAdministrative_share)
 FN_LOCAL_BOOL(lp_print_ok, bPrint_ok)
 FN_LOCAL_BOOL(lp_map_hidden, bMap_hidden)
 FN_LOCAL_BOOL(lp_map_archive, bMap_archive)
+FN_LOCAL_BOOL(lp_store_create_time, bStoreCreateTime)
 FN_LOCAL_BOOL(lp_store_dos_attributes, bStoreDosAttributes)
 FN_LOCAL_BOOL(lp_dmapi_support, bDmapiSupport)
 FN_LOCAL_PARM_BOOL(lp_locking, bLocking)
@@ -5417,7 +5641,7 @@ FN_LOCAL_BOOL(lp_recursive_veto_delete, bDeleteVetoFiles)
 FN_LOCAL_BOOL(lp_dos_filemode, bDosFilemode)
 FN_LOCAL_BOOL(lp_dos_filetimes, bDosFiletimes)
 FN_LOCAL_BOOL(lp_dos_filetime_resolution, bDosFiletimeResolution)
-FN_LOCAL_BOOL(lp_fake_dir_create_times, bFakeDirCreateTimes)
+FN_GLOBAL_BOOL(lp_fake_dir_create_times, &Globals.bFakeDirCreateTimes)
 FN_LOCAL_BOOL(lp_blocking_locks, bBlockingLocks)
 FN_LOCAL_BOOL(lp_inherit_perms, bInheritPerms)
 FN_LOCAL_BOOL(lp_inherit_acls, bInheritACLS)
@@ -5959,6 +6183,11 @@ bool lp_add_home(const char *pszHomename, int iDefaultService,
 {
        int i;
 
+       if (pszHomename == NULL || user == NULL || pszHomedir == NULL ||
+                       pszHomedir[0] == '\0') {
+               return false;
+       }
+
        i = add_a_service(ServicePtrs[iDefaultService], pszHomename);
 
        if (i < 0)
@@ -6654,13 +6883,16 @@ static bool process_smbconf_service(struct smbconf_service *service)
                        return false;
                }
        }
+       if (iServiceIndex >= 0) {
+               return service_ok(iServiceIndex);
+       }
        return true;
 }
 
-/*
- * process_registry_globals
+/**
+ * load a service from registry and activate it
  */
-static bool process_registry_globals(void)
+bool process_registry_service(const char *service_name)
 {
        WERROR werr;
        struct smbconf_service *service = NULL;
@@ -6672,19 +6904,18 @@ static bool process_registry_globals(void)
                goto done;
        }
 
-       ret = do_parameter("registry shares", "yes", NULL);
-       if (!ret) {
-               goto done;
-       }
+       DEBUG(5, ("process_registry_service: service name %s\n", service_name));
 
-       if (!smbconf_share_exists(conf_ctx, GLOBAL_NAME)) {
-               /* nothing to read from the registry yet but make sure lp_load
-                * doesn't return false */
+       if (!smbconf_share_exists(conf_ctx, service_name)) {
+               /*
+                * Registry does not contain data for this service (yet),
+                * but make sure lp_load doesn't return false.
+                */
                ret = true;
                goto done;
        }
 
-       werr = smbconf_get_share(conf_ctx, mem_ctx, GLOBAL_NAME, &service);
+       werr = smbconf_get_share(conf_ctx, mem_ctx, service_name, &service);
        if (!W_ERROR_IS_OK(werr)) {
                goto done;
        }
@@ -6702,7 +6933,24 @@ done:
        return ret;
 }
 
-static bool process_registry_shares(void)
+/*
+ * process_registry_globals
+ */
+static bool process_registry_globals(void)
+{
+       bool ret;
+
+       add_to_file_list(INCLUDE_REGISTRY_NAME, INCLUDE_REGISTRY_NAME);
+
+       ret = do_parameter("registry shares", "yes", NULL);
+       if (!ret) {
+               return ret;
+       }
+
+       return process_registry_service(GLOBAL_NAME);
+}
+
+bool process_registry_shares(void)
 {
        WERROR werr;
        uint32_t count;
@@ -6741,6 +6989,10 @@ done:
        return ret;
 }
 
+#define MAX_INCLUDE_DEPTH 100
+
+static uint8_t include_depth;
+
 static struct file_lists {
        struct file_lists *next;
        char *name;
@@ -6787,6 +7039,26 @@ static void add_to_file_list(const char *fname, const char *subfname)
        }
 }
 
+/**
+ * Free the file lists
+ */
+static void free_file_list(void)
+{
+       struct file_lists *f;
+       struct file_lists *next;
+
+       f = file_lists;
+       while( f ) {
+               next = f->next;
+               SAFE_FREE( f->name );
+               SAFE_FREE( f->subfname );
+               SAFE_FREE( f );
+               f = next;
+       }
+       file_lists = NULL;
+}
+
+
 /**
  * Utility function for outsiders to check if we're running on registry.
  */
@@ -6813,45 +7085,51 @@ bool lp_file_list_changed(void)
 
        DEBUG(6, ("lp_file_list_changed()\n"));
 
-       if (lp_config_backend_is_registry()) {
-               struct smbconf_ctx *conf_ctx = lp_smbconf_ctx();
-
-               if (conf_ctx == NULL) {
-                       return false;
-               }
-               if (smbconf_changed(conf_ctx, &conf_last_csn, NULL, NULL)) {
-                       DEBUGADD(6, ("registry config changed\n"));
-                       return true;
-               }
-       }
-
        while (f) {
                char *n2 = NULL;
                time_t mod_time;
 
-               n2 = alloc_sub_basic(get_current_username(),
-                                   current_user_info.domain,
-                                   f->name);
-               if (!n2) {
-                       return false;
-               }
-               DEBUGADD(6, ("file %s -> %s  last mod_time: %s\n",
-                            f->name, n2, ctime(&f->modtime)));
-
-               mod_time = file_modtime(n2);
-
-               if (mod_time && ((f->modtime != mod_time) || (f->subfname == NULL) || (strcmp(n2, f->subfname) != 0))) {
-                       DEBUGADD(6,
-                                ("file %s modified: %s\n", n2,
-                                 ctime(&mod_time)));
-                       f->modtime = mod_time;
-                       SAFE_FREE(f->subfname);
-                       f->subfname = n2; /* Passing ownership of
-                                            return from alloc_sub_basic
-                                            above. */
-                       return true;
+               if (strequal(f->name, INCLUDE_REGISTRY_NAME)) {
+                       struct smbconf_ctx *conf_ctx = lp_smbconf_ctx();
+
+                       if (conf_ctx == NULL) {
+                               return false;
+                       }
+                       if (smbconf_changed(conf_ctx, &conf_last_csn, NULL,
+                                           NULL))
+                       {
+                               DEBUGADD(6, ("registry config changed\n"));
+                               return true;
+                       }
+               } else {
+                       n2 = alloc_sub_basic(get_current_username(),
+                                           current_user_info.domain,
+                                           f->name);
+                       if (!n2) {
+                               return false;
+                       }
+                       DEBUGADD(6, ("file %s -> %s  last mod_time: %s\n",
+                                    f->name, n2, ctime(&f->modtime)));
+
+                       mod_time = file_modtime(n2);
+
+                       if (mod_time &&
+                           ((f->modtime != mod_time) ||
+                            (f->subfname == NULL) ||
+                            (strcmp(n2, f->subfname) != 0)))
+                       {
+                               DEBUGADD(6,
+                                        ("file %s modified: %s\n", n2,
+                                         ctime(&mod_time)));
+                               f->modtime = mod_time;
+                               SAFE_FREE(f->subfname);
+                               f->subfname = n2; /* Passing ownership of
+                                                    return from alloc_sub_basic
+                                                    above. */
+                               return true;
+                       }
+                       SAFE_FREE(n2);
                }
-               SAFE_FREE(n2);
                f = f->next;
        }
        return (False);
@@ -6928,12 +7206,22 @@ static bool handle_include(int snum, const char *pszParmValue, char **ptr)
 {
        char *fname;
 
+       if (include_depth >= MAX_INCLUDE_DEPTH) {
+               DEBUG(0, ("Error: Maximum include depth (%u) exceeded!\n",
+                         include_depth));
+               return false;
+       }
+
        if (strequal(pszParmValue, INCLUDE_REGISTRY_NAME)) {
                if (!bAllowIncludeRegistry) {
                        return true;
                }
                if (bInGlobalSection) {
-                       return process_registry_globals();
+                       bool ret;
+                       include_depth++;
+                       ret = process_registry_globals();
+                       include_depth--;
+                       return ret;
                } else {
                        DEBUG(1, ("\"include = registry\" only effective "
                                  "in %s section\n", GLOBAL_NAME));
@@ -6950,7 +7238,10 @@ static bool handle_include(int snum, const char *pszParmValue, char **ptr)
        string_set(ptr, fname);
 
        if (file_exist(fname)) {
-               bool ret = pm_process(fname, do_section, do_parameter, NULL);
+               bool ret;
+               include_depth++;
+               ret = pm_process(fname, do_section, do_parameter, NULL);
+               include_depth--;
                SAFE_FREE(fname);
                return ret;
        }
@@ -7578,6 +7869,7 @@ static void dump_globals(FILE *f)
 
        for (i = 0; parm_table[i].label; i++)
                if (parm_table[i].p_class == P_GLOBAL &&
+                   !(parm_table[i].flags & FLAG_META) &&
                    parm_table[i].ptr &&
                    (i == 0 || (parm_table[i].ptr != parm_table[i - 1].ptr))) {
                        if (defaults_saved && is_default(i))
@@ -7624,6 +7916,7 @@ static void dump_a_service(struct service *pService, FILE * f)
        for (i = 0; parm_table[i].label; i++) {
 
                if (parm_table[i].p_class == P_LOCAL &&
+                   !(parm_table[i].flags & FLAG_META) &&
                    parm_table[i].ptr &&
                    (*parm_table[i].label != '-') &&
                    (i == 0 || (parm_table[i].ptr != parm_table[i - 1].ptr))) 
@@ -7700,6 +7993,7 @@ bool dump_a_parameter(int snum, char *parm_name, FILE * f, bool isGlobal)
 
        for (i = 0; parm_table[i].label; i++) {
                if (strwicmp(parm_table[i].label, parm_name) == 0 &&
+                   !(parm_table[i].flags & FLAG_META) &&
                    (parm_table[i].p_class == p_class || parm_table[i].flags & flag) &&
                    parm_table[i].ptr &&
                    (*parm_table[i].label != '-') &&
@@ -7865,7 +8159,7 @@ static void lp_add_auto_services(char *str)
 
                home = get_user_home_dir(talloc_tos(), p);
 
-               if (home && homes >= 0)
+               if (home && home[0] && homes >= 0)
                        lp_add_home(p, homes, p, home);
 
                TALLOC_FREE(home);
@@ -8095,29 +8389,30 @@ static void set_allowed_client_auth(void)
  get their sorry ass fired.
 ***************************************************************************/
 
-static bool check_usershare_stat(const char *fname, SMB_STRUCT_STAT *psbuf)
+static bool check_usershare_stat(const char *fname,
+                                const SMB_STRUCT_STAT *psbuf)
 {
-       if (!S_ISREG(psbuf->st_mode)) {
+       if (!S_ISREG(psbuf->st_ex_mode)) {
                DEBUG(0,("check_usershare_stat: file %s owned by uid %u is "
                        "not a regular file\n",
-                       fname, (unsigned int)psbuf->st_uid ));
+                       fname, (unsigned int)psbuf->st_ex_uid ));
                return False;
        }
 
        /* Ensure this doesn't have the other write bit set. */
-       if (psbuf->st_mode & S_IWOTH) {
+       if (psbuf->st_ex_mode & S_IWOTH) {
                DEBUG(0,("check_usershare_stat: file %s owned by uid %u allows "
                        "public write. Refusing to allow as a usershare file.\n",
-                       fname, (unsigned int)psbuf->st_uid ));
+                       fname, (unsigned int)psbuf->st_ex_uid ));
                return False;
        }
 
        /* Should be 10k or less. */
-       if (psbuf->st_size > MAX_USERSHARE_FILE_SIZE) {
+       if (psbuf->st_ex_size > MAX_USERSHARE_FILE_SIZE) {
                DEBUG(0,("check_usershare_stat: file %s owned by uid %u is "
                        "too large (%u) to be a user share file.\n",
-                       fname, (unsigned int)psbuf->st_uid,
-                       (unsigned int)psbuf->st_size ));
+                       fname, (unsigned int)psbuf->st_ex_uid,
+                       (unsigned int)psbuf->st_ex_size ));
                return False;
        }
 
@@ -8276,7 +8571,7 @@ enum usershare_err parse_usershare_file(TALLOC_CTX *ctx,
 
        sys_closedir(dp);
 
-       if (!S_ISDIR(sbuf.st_mode)) {
+       if (!S_ISDIR(sbuf.st_ex_mode)) {
                DEBUG(2,("parse_usershare_file: share %s path %s is not a directory.\n",
                        servicename, sharepath ));
                return USERSHARE_PATH_NOT_DIRECTORY;
@@ -8288,7 +8583,7 @@ enum usershare_err parse_usershare_file(TALLOC_CTX *ctx,
 
        if (lp_usershare_owner_only()) {
                /* root can share anything. */
-               if ((psbuf->st_uid != 0) && (sbuf.st_uid != psbuf->st_uid)) {
+               if ((psbuf->st_ex_uid != 0) && (sbuf.st_ex_uid != psbuf->st_ex_uid)) {
                        return USERSHARE_PATH_NOT_ALLOWED;
                }
        }
@@ -8366,7 +8661,9 @@ static int process_usershare_file(const char *dir_name, const char *file_name, i
                TALLOC_FREE(canon_name);
        }
 
-       if (iService != -1 && ServicePtrs[iService]->usershare_last_mod == lsbuf.st_mtime) {
+       if (iService != -1 &&
+           timespec_compare(&ServicePtrs[iService]->usershare_last_mod,
+                            &lsbuf.st_ex_mtime) == 0) {
                /* Nothing changed - Mark valid and return. */
                DEBUG(10,("process_usershare_file: service %s not changed.\n",
                        service_name ));
@@ -8399,7 +8696,7 @@ static int process_usershare_file(const char *dir_name, const char *file_name, i
        }
 
        /* Is it the same dev/inode as was lstated ? */
-       if (lsbuf.st_dev != sbuf.st_dev || lsbuf.st_ino != sbuf.st_ino) {
+       if (lsbuf.st_ex_dev != sbuf.st_ex_dev || lsbuf.st_ex_ino != sbuf.st_ex_ino) {
                close(fd);
                DEBUG(0,("process_usershare_file: fstat of %s is a different file from lstat. "
                        "Symlink spoofing going on ?\n", fname ));
@@ -8419,7 +8716,7 @@ static int process_usershare_file(const char *dir_name, const char *file_name, i
        close(fd);
        if (lines == NULL) {
                DEBUG(0,("process_usershare_file: loading file %s owned by %u failed.\n",
-                       fname, (unsigned int)sbuf.st_uid ));
+                       fname, (unsigned int)sbuf.st_ex_uid ));
                SAFE_FREE(fname);
                return -1;
        }
@@ -8483,7 +8780,7 @@ static int process_usershare_file(const char *dir_name, const char *file_name, i
        }
 
        /* And note when it was loaded. */
-       ServicePtrs[iService]->usershare_last_mod = sbuf.st_mtime;
+       ServicePtrs[iService]->usershare_last_mod = sbuf.st_ex_mtime;
        string_set(&ServicePtrs[iService]->szPath, sharepath);
        string_set(&ServicePtrs[iService]->comment, comment);
 
@@ -8496,7 +8793,7 @@ static int process_usershare_file(const char *dir_name, const char *file_name, i
  Checks if a usershare entry has been modified since last load.
 ***************************************************************************/
 
-static bool usershare_exists(int iService, time_t *last_mod)
+static bool usershare_exists(int iService, struct timespec *last_mod)
 {
        SMB_STRUCT_STAT lsbuf;
        const char *usersharepath = Globals.szUsersharePath;
@@ -8513,13 +8810,13 @@ static bool usershare_exists(int iService, time_t *last_mod)
                return false;
        }
 
-       if (!S_ISREG(lsbuf.st_mode)) {
+       if (!S_ISREG(lsbuf.st_ex_mode)) {
                SAFE_FREE(fname);
                return false;
        }
 
        SAFE_FREE(fname);
-       *last_mod = lsbuf.st_mtime;
+       *last_mod = lsbuf.st_ex_mtime;
        return true;
 }
 
@@ -8544,7 +8841,7 @@ int load_usershare_service(const char *servicename)
                return -1;
        }
 
-       if (!S_ISDIR(sbuf.st_mode)) {
+       if (!S_ISDIR(sbuf.st_ex_mode)) {
                DEBUG(0,("load_usershare_service: %s is not a directory.\n",
                        usersharepath ));
                return -1;
@@ -8556,9 +8853,9 @@ int load_usershare_service(const char *servicename)
         */
 
 #ifdef S_ISVTX
-       if (sbuf.st_uid != 0 || !(sbuf.st_mode & S_ISVTX) || (sbuf.st_mode & S_IWOTH)) {
+       if (sbuf.st_ex_uid != 0 || !(sbuf.st_ex_mode & S_ISVTX) || (sbuf.st_ex_mode & S_IWOTH)) {
 #else
-       if (sbuf.st_uid != 0 || (sbuf.st_mode & S_IWOTH)) {
+       if (sbuf.st_ex_uid != 0 || (sbuf.st_ex_mode & S_IWOTH)) {
 #endif
                DEBUG(0,("load_usershare_service: directory %s is not owned by root "
                        "or does not have the sticky bit 't' set or is writable by anyone.\n",
@@ -8627,9 +8924,9 @@ int load_usershare_shares(void)
         */
 
 #ifdef S_ISVTX
-       if (sbuf.st_uid != 0 || !(sbuf.st_mode & S_ISVTX) || (sbuf.st_mode & S_IWOTH)) {
+       if (sbuf.st_ex_uid != 0 || !(sbuf.st_ex_mode & S_ISVTX) || (sbuf.st_ex_mode & S_IWOTH)) {
 #else
-       if (sbuf.st_uid != 0 || (sbuf.st_mode & S_IWOTH)) {
+       if (sbuf.st_ex_uid != 0 || (sbuf.st_ex_mode & S_IWOTH)) {
 #endif
                DEBUG(0,("load_usershare_shares: directory %s is not owned by root "
                        "or does not have the sticky bit 't' set or is writable by anyone.\n",
@@ -8754,21 +9051,9 @@ int load_usershare_shares(void)
 
 void gfree_loadparm(void)
 {
-       struct file_lists *f;
-       struct file_lists *next;
        int i;
 
-       /* Free the file lists */
-
-       f = file_lists;
-       while( f ) {
-               next = f->next;
-               SAFE_FREE( f->name );
-               SAFE_FREE( f->subfname );
-               SAFE_FREE( f );
-               f = next;
-       }
-       file_lists = NULL;
+       free_file_list();
 
        /* Free resources allocated to services */
 
@@ -8832,6 +9117,8 @@ bool lp_load_ex(const char *pszFname,
        init_globals(! initialize_globals);
        debug_init();
 
+       free_file_list();
+
        if (save_defaults) {
                init_locals();
                lp_save_defaults();
@@ -9040,7 +9327,7 @@ int lp_servicenumber(const char *pszServiceName)
        }
 
        if (iService >= 0 && ServicePtrs[iService]->usershare == USERSHARE_VALID) {
-               time_t last_mod;
+               struct timespec last_mod;
 
                if (!usershare_exists(iService, &last_mod)) {
                        /* Remove the share security tdb entry for it. */
@@ -9052,7 +9339,8 @@ int lp_servicenumber(const char *pszServiceName)
                }
 
                /* Has it been modified ? If so delete and reload. */
-               if (ServicePtrs[iService]->usershare_last_mod < last_mod) {
+               if (timespec_compare(&ServicePtrs[iService]->usershare_last_mod,
+                                    &last_mod) < 0) {
                        /* Remove it from the array. */
                        free_service_byindex(iService);
                        /* and now reload it. */
@@ -9412,10 +9700,6 @@ const char *lp_printcapname(void)
        return PRINTCAP_NAME;
 }
 
-/*******************************************************************
- Ensure we don't use sendfile if server smb signing is active.
-********************************************************************/
-
 static uint32 spoolss_state;
 
 bool lp_disable_spoolss( void )
@@ -9442,15 +9726,20 @@ uint32 lp_get_spoolss_state( void )
  Ensure we don't use sendfile if server smb signing is active.
 ********************************************************************/
 
-bool lp_use_sendfile(int snum)
+bool lp_use_sendfile(int snum, struct smb_signing_state *signing_state)
 {
+       bool sign_active = false;
+
        /* Using sendfile blows the brains out of any DOS or Win9x TCP stack... JRA. */
-       if (Protocol < PROTOCOL_NT1) {
-               return False;
+       if (get_Protocol() < PROTOCOL_NT1) {
+               return false;
+       }
+       if (signing_state) {
+               sign_active = smb_signing_is_active(signing_state);
        }
        return (_lp_use_sendfile(snum) &&
                        (get_remote_arch() != RA_WIN95) &&
-                       !srv_is_signing_active());
+                       !sign_active);
 }
 
 /*******************************************************************
@@ -9549,3 +9838,18 @@ const char *lp_socket_address(void)
        }
        return  Globals.szSocketAddress;
 }
+
+void lp_set_passdb_backend(const char *backend)
+{
+       string_set(&Globals.szPassdbBackend, backend);
+}
+
+bool set_inherit_acls(int i)
+{
+       if (!LP_SNUM_OK(i)) {
+               return false;
+       }
+       ServicePtrs[(i)]->bInheritACLS = true;
+
+       return true;
+}