s3-auth: Remove security=share (depricated since 3.6).
[kai/samba.git] / source3 / param / loadparm.c
index 3c213420ae32ba08d17f71f3647a6bc5c1b2e628..453c8fd875970f54c7c385f5f7a582fbef4eaff1 100644 (file)
 #include "printing.h"
 #include "lib/smbconf/smbconf.h"
 #include "lib/smbconf/smbconf_init.h"
+#include "lib/param/loadparm.h"
 
 #include "ads.h"
 #include "../librpc/gen_ndr/svcctl.h"
 #include "intl.h"
-#include "smb_signing.h"
-#include "dbwrap.h"
-#include "smbldap.h"
+#include "../libcli/smb/smb_signing.h"
+#include "dbwrap/dbwrap.h"
+#include "dbwrap/dbwrap_rbt.h"
+#include "../lib/util/bitmap.h"
+#include "../source4/dns_server/dns_update.h"
 
 #ifdef HAVE_SYS_SYSCTL_H
 #include <sys/sysctl.h>
 #include <cups/http.h>
 #endif
 
-bool bLoaded = False;
+bool bLoaded = false;
 
 extern userdom_struct current_user_info;
 
-#ifndef GLOBAL_NAME
-#define GLOBAL_NAME "global"
-#endif
-
-#ifndef PRINTERS_NAME
-#define PRINTERS_NAME "printers"
-#endif
-
-#ifndef HOMES_NAME
-#define HOMES_NAME "homes"
-#endif
-
 /* the special value for the include parameter
  * to be interpreted not as a file name but to
  * trigger loading of the global smb.conf options
@@ -99,7 +90,7 @@ extern userdom_struct current_user_info;
 #define INCLUDE_REGISTRY_NAME "registry"
 #endif
 
-static bool in_client = False;         /* Not in the client by default */
+static bool in_client = false;         /* Not in the client by default */
 static struct smbconf_csn conf_last_csn;
 
 #define CONFIG_BACKEND_FILE 0
@@ -114,574 +105,180 @@ static int config_backend = CONFIG_BACKEND_FILE;
 #define USERSHARE_VALID 1
 #define USERSHARE_PENDING_DELETE 2
 
-static bool defaults_saved = False;
-
-struct param_opt_struct {
-       struct param_opt_struct *prev, *next;
-       char *key;
-       char *value;
-       char **list;
-       unsigned flags;
-};
-
-/*
- * This structure describes global (ie., server-wide) parameters.
- */
-struct loadparm_global {
-       int ConfigBackend;
-       char *smb_ports;
-       char *dos_charset;
-       char *unix_charset;
-       char *szPrintcapname;
-       char *szAddPortCommand;
-       char *szEnumPortsCommand;
-       char *szAddPrinterCommand;
-       char *szDeletePrinterCommand;
-       char *szOs2DriverMap;
-       char *szLockDir;
-       char *szStateDir;
-       char *szCacheDir;
-       char *szPidDir;
-       char *szRootdir;
-       char *szDefaultService;
-       char *szGetQuota;
-       char *szSetQuota;
-       char *szMsgCommand;
-       char *szServerString;
-       char *szAutoServices;
-       char *szPasswdProgram;
-       char *szPasswdChat;
-       char *szLogFile;
-       char *szConfigFile;
-       char *szSMBPasswdFile;
-       char *szPrivateDir;
-       char *szPassdbBackend;
-       char **szPreloadModules;
-       char *szPasswordServer;
-       char *szSocketOptions;
-       char *szRealm;
-       char *szRealmUpper;
-       char *szDnsDomain;
-       char *szAfsUsernameMap;
-       int iAfsTokenLifetime;
-       char *szLogNtTokenCommand;
-       char *szUsernameMap;
-       char *szLogonScript;
-       char *szLogonPath;
-       char *szLogonDrive;
-       char *szLogonHome;
-       char **szWINSservers;
-       char **szInterfaces;
-       char *szRemoteAnnounce;
-       char *szRemoteBrowseSync;
-       char *szSocketAddress;
-       bool bNmbdBindExplicitBroadcast;
-       char *szNISHomeMapName;
-       char *szWorkgroup;
-       char *szNetbiosName;
-       char **szNetbiosAliases;
-       char *szNetbiosScope;
-       char *szNameResolveOrder;
-       char *szPanicAction;
-       char *szAddUserScript;
-       char *szRenameUserScript;
-       char *szDelUserScript;
-       char *szAddGroupScript;
-       char *szDelGroupScript;
-       char *szAddUserToGroupScript;
-       char *szDelUserFromGroupScript;
-       char *szSetPrimaryGroupScript;
-       char *szAddMachineScript;
-       char *szShutdownScript;
-       char *szAbortShutdownScript;
-       char *szUsernameMapScript;
-       int iUsernameMapCacheTime;
-       char *szCheckPasswordScript;
-       char *szWINSHook;
-       char *szUtmpDir;
-       char *szWtmpDir;
-       bool bUtmp;
-       char *szIdmapUID;
-       char *szIdmapGID;
-       bool bPassdbExpandExplicit;
-       int AlgorithmicRidBase;
-       char *szTemplateHomedir;
-       char *szTemplateShell;
-       char *szWinbindSeparator;
-       bool bWinbindEnumUsers;
-       bool bWinbindEnumGroups;
-       bool bWinbindUseDefaultDomain;
-       bool bWinbindTrustedDomainsOnly;
-       bool bWinbindNestedGroups;
-       int  winbind_expand_groups;
-       bool bWinbindRefreshTickets;
-       bool bWinbindOfflineLogon;
-       bool bWinbindNormalizeNames;
-       bool bWinbindRpcOnly;
-       bool bCreateKrb5Conf;
-       int winbindMaxDomainConnections;
-       char *szIdmapBackend;
-       bool bIdmapReadOnly;
-       char *szAddShareCommand;
-       char *szChangeShareCommand;
-       char *szDeleteShareCommand;
-       char **szEventLogs;
-       char *szGuestaccount;
-       char *szManglingMethod;
-       char **szServicesList;
-       char *szUsersharePath;
-       char *szUsershareTemplateShare;
-       char **szUsersharePrefixAllowList;
-       char **szUsersharePrefixDenyList;
-       int mangle_prefix;
-       int max_log_size;
-       char *szLogLevel;
-       int max_xmit;
-       int max_mux;
-       int max_open_files;
-       int open_files_db_hash_size;
-       int pwordlevel;
-       int unamelevel;
-       int deadtime;
-       bool getwd_cache;
-       int maxprotocol;
-       int minprotocol;
-       int security;
-       char **AuthMethods;
-       bool paranoid_server_security;
-       int maxdisksize;
-       int lpqcachetime;
-       int iMaxSmbdProcesses;
-       bool bDisableSpoolss;
-       int syslog;
-       int os_level;
-       bool enhanced_browsing;
-       int max_ttl;
-       int max_wins_ttl;
-       int min_wins_ttl;
-       int lm_announce;
-       int lm_interval;
-       int machine_password_timeout;
-       int map_to_guest;
-       int oplock_break_wait_time;
-       int winbind_cache_time;
-       int winbind_reconnect_delay;
-       int winbind_max_clients;
-       char **szWinbindNssInfo;
-       int iLockSpinTime;
-       char *szLdapMachineSuffix;
-       char *szLdapUserSuffix;
-       char *szLdapIdmapSuffix;
-       char *szLdapGroupSuffix;
-       int ldap_ssl;
-       bool ldap_ssl_ads;
-       int ldap_deref;
-       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 ctdb_locktime_warn_threshold;
-       int ldap_passwd_sync;
-       int ldap_replication_sleep;
-       int ldap_timeout; /* This is initialised in init_globals */
-       int ldap_connection_timeout;
-       int ldap_page_size;
-       bool ldap_delete_dn;
-       bool bMsAddPrinterWizard;
-       bool bDNSproxy;
-       bool bWINSsupport;
-       bool bWINSproxy;
-       bool bLocalMaster;
-       int  iPreferredMaster;
-       int iDomainMaster;
-       bool bDomainLogons;
-       char **szInitLogonDelayedHosts;
-       int InitLogonDelay;
-       bool bEncryptPasswords;
-       bool bUpdateEncrypt;
-       int  clientSchannel;
-       int  serverSchannel;
-       bool bNullPasswords;
-       bool bObeyPamRestrictions;
-       bool bLoadPrinters;
-       int PrintcapCacheTime;
-       bool bLargeReadwrite;
-       bool bReadRaw;
-       bool bWriteRaw;
-       bool bSyslogOnly;
-       bool bBrowseList;
-       bool bNISHomeMap;
-       bool bTimeServer;
-       bool bBindInterfacesOnly;
-       bool bPamPasswordChange;
-       bool bUnixPasswdSync;
-       bool bPasswdChatDebug;
-       int iPasswdChatTimeout;
-       bool bTimestampLogs;
-       bool bNTSmbSupport;
-       bool bNTPipeSupport;
-       bool bNTStatusSupport;
-       bool bStatCache;
-       int iMaxStatCacheSize;
-       bool bKernelOplocks;
-       bool bAllowTrustedDomains;
-       bool bLanmanAuth;
-       bool bNTLMAuth;
-       bool bUseSpnego;
-       bool bClientLanManAuth;
-       bool bClientNTLMv2Auth;
-       bool bClientPlaintextAuth;
-       bool bClientUseSpnego;
-       bool client_use_spnego_principal;
-       bool send_spnego_principal;
-       bool bDebugPrefixTimestamp;
-       bool bDebugHiresTimestamp;
-       bool bDebugPid;
-       bool bDebugUid;
-       bool bDebugClass;
-       bool bEnableCoreFiles;
-       bool bHostMSDfs;
-       bool bUseMmap;
-       bool bHostnameLookups;
-       bool bUnixExtensions;
-       bool bDisableNetbios;
-       char * szDedicatedKeytabFile;
-       int  iKerberosMethod;
-       bool bDeferSharingViolations;
-       bool bEnablePrivileges;
-       bool bASUSupport;
-       bool bUsershareOwnerOnly;
-       bool bUsershareAllowGuests;
-       bool bRegistryShares;
-       int restrict_anonymous;
-       int name_cache_timeout;
-       int client_signing;
-       int server_signing;
-       int client_ldap_sasl_wrapping;
-       int iUsershareMaxShares;
-       int iIdmapCacheTime;
-       int iIdmapNegativeCacheTime;
-       bool bResetOnZeroVC;
-       bool bLogWriteableFilesOnExit;
-       int iKeepalive;
-       int iminreceivefile;
-       struct param_opt_struct *param_opt;
-       int cups_connection_timeout;
-       char *szSMBPerfcountModule;
-       bool bMapUntrustedToDomain;
-       bool bAsyncSMBEchoHandler;
-       bool bMulticastDnsRegister;
-       int ismb2_max_read;
-       int ismb2_max_write;
-       int ismb2_max_trans;
+static bool defaults_saved = false;
+
+#define LOADPARM_EXTRA_GLOBALS \
+       struct parmlist_entry *param_opt;                               \
+       char *szRealm;                                                  \
+       char *szLogLevel;                                               \
+       int iminreceivefile;                                            \
+       char *szPrintcapname;                                           \
+       int CupsEncrypt;                                                \
+       int  iPreferredMaster;                                          \
+       int iDomainMaster;                                              \
+       char *szLdapMachineSuffix;                                      \
+       char *szLdapUserSuffix;                                         \
+       char *szLdapIdmapSuffix;                                        \
+       char *szLdapGroupSuffix;                                        \
+       char *szStateDir;                                               \
+       char *szCacheDir;                                               \
+       char *szSocketAddress;                                          \
+       char *szUsershareTemplateShare;                                 \
+       char *szIdmapUID;                                               \
+       char *szIdmapGID;                                               \
+       int winbindMaxDomainConnections;                                \
        int ismb2_max_credits;
-       char *ncalrpc_dir;
-};
 
-static struct loadparm_global Globals;
-
-/*
- * This structure describes a single service.
- */
-struct loadparm_service {
-       bool valid;
-       bool autoloaded;
-       int usershare;
-       struct timespec usershare_last_mod;
-       char *szService;
-       char *szPath;
-       char *szUsername;
-       char **szInvalidUsers;
-       char **szValidUsers;
-       char **szAdminUsers;
-       char *szCopy;
-       char *szInclude;
-       char *szPreExec;
-       char *szPostExec;
-       char *szRootPreExec;
-       char *szRootPostExec;
-       char *szCupsOptions;
-       char *szPrintcommand;
-       char *szLpqcommand;
-       char *szLprmcommand;
-       char *szLppausecommand;
-       char *szLpresumecommand;
-       char *szQueuepausecommand;
-       char *szQueueresumecommand;
-       char *szPrintername;
-       char *szPrintjobUsername;
-       char *szDontdescend;
-       char **szHostsallow;
-       char **szHostsdeny;
-       char *szMagicScript;
-       char *szMagicOutput;
-       char *szVetoFiles;
-       char *szHideFiles;
-       char *szVetoOplockFiles;
-       char *comment;
-       char *force_user;
-       char *force_group;
-       char **readlist;
-       char **writelist;
-       char **printer_admin;
-       char *volume;
-       char *fstype;
-       char **szVfsObjects;
-       char *szMSDfsProxy;
-       char *szAioWriteBehind;
-       char *szDfree;
-       int iMinPrintSpace;
-       int iMaxPrintJobs;
-       int iMaxReportedPrintJobs;
-       int iWriteCacheSize;
-       int iCreate_mask;
-       int iCreate_force_mode;
-       int iSecurity_mask;
-       int iSecurity_force_mode;
-       int iDir_mask;
-       int iDir_force_mode;
-       int iDir_Security_mask;
-       int iDir_Security_force_mode;
-       int iMaxConnections;
-       int iDefaultCase;
-       int iPrinting;
-       int iOplockContentionLimit;
-       int iCSCPolicy;
-       int iBlock_size;
-       int iDfreeCacheTime;
-       bool bPreexecClose;
-       bool bRootpreexecClose;
-       int  iCaseSensitive;
-       bool bCasePreserve;
-       bool bShortCasePreserve;
-       bool bHideDotFiles;
-       bool bHideSpecialFiles;
-       bool bHideUnReadable;
-       bool bHideUnWriteableFiles;
-       bool bBrowseable;
-       bool bAccessBasedShareEnum;
-       bool bAvailable;
-       bool bRead_only;
-       bool bNo_set_dir;
-       bool bGuest_only;
-       bool bAdministrative_share;
-       bool bGuest_ok;
-       bool bPrint_ok;
-       bool bPrintNotifyBackchannel;
-       bool bMap_system;
-       bool bMap_hidden;
-       bool bMap_archive;
-       bool bStoreDosAttributes;
-       bool bDmapiSupport;
-       bool bLocking;
-       int iStrictLocking;
-       bool bPosixLocking;
-       bool bShareModes;
-       bool bOpLocks;
-       bool bLevel2OpLocks;
-       bool bOnlyUser;
-       bool bMangledNames;
-       bool bWidelinks;
-       bool bSymlinks;
-       bool bSyncAlways;
-       bool bStrictAllocate;
-       bool bStrictSync;
-       char magic_char;
-       struct bitmap *copymap;
-       bool bDeleteReadonly;
-       bool bFakeOplocks;
-       bool bDeleteVetoFiles;
-       bool bDosFilemode;
-       bool bDosFiletimes;
-       bool bDosFiletimeResolution;
-       bool bFakeDirCreateTimes;
-       bool bBlockingLocks;
-       bool bInheritPerms;
-       bool bInheritACLS;
-       bool bInheritOwner;
-       bool bMSDfsRoot;
-       bool bUseClientDriver;
-       bool bDefaultDevmode;
-       bool bForcePrintername;
-       bool bNTAclSupport;
-       bool bForceUnknownAclUser;
-       bool bUseSendfile;
-       bool bProfileAcls;
-       bool bMap_acl_inherit;
-       bool bAfs_Share;
-       bool bEASupport;
-       bool bAclCheckPermissions;
-       bool bAclMapFullControl;
-       bool bAclGroupControl;
-       bool bChangeNotify;
-       bool bKernelChangeNotify;
-       int iallocation_roundup_size;
-       int iAioReadSize;
-       int iAioWriteSize;
-       int iMap_readonly;
-       int iDirectoryNameCacheSize;
-       int ismb_encrypt;
-       struct param_opt_struct *param_opt;
-
-       char dummy[3];          /* for alignment */
-};
+#include "param/param_global.h"
 
+static struct loadparm_global Globals;
 
 /* This is a default service used to prime a services structure */
-static struct loadparm_service sDefault = {
-       True,                   /* valid */
-       False,                  /* not autoloaded */
-       0,                      /* not a usershare */
-       {0, },                  /* No last mod time */
-       NULL,                   /* szService */
-       NULL,                   /* szPath */
-       NULL,                   /* szUsername */
-       NULL,                   /* szInvalidUsers */
-       NULL,                   /* szValidUsers */
-       NULL,                   /* szAdminUsers */
-       NULL,                   /* szCopy */
-       NULL,                   /* szInclude */
-       NULL,                   /* szPreExec */
-       NULL,                   /* szPostExec */
-       NULL,                   /* szRootPreExec */
-       NULL,                   /* szRootPostExec */
-       NULL,                   /* szCupsOptions */
-       NULL,                   /* szPrintcommand */
-       NULL,                   /* szLpqcommand */
-       NULL,                   /* szLprmcommand */
-       NULL,                   /* szLppausecommand */
-       NULL,                   /* szLpresumecommand */
-       NULL,                   /* szQueuepausecommand */
-       NULL,                   /* szQueueresumecommand */
-       NULL,                   /* szPrintername */
-       NULL,                   /* szPrintjobUsername */
-       NULL,                   /* szDontdescend */
-       NULL,                   /* szHostsallow */
-       NULL,                   /* szHostsdeny */
-       NULL,                   /* szMagicScript */
-       NULL,                   /* szMagicOutput */
-       NULL,                   /* szVetoFiles */
-       NULL,                   /* szHideFiles */
-       NULL,                   /* szVetoOplockFiles */
-       NULL,                   /* comment */
-       NULL,                   /* force user */
-       NULL,                   /* force group */
-       NULL,                   /* readlist */
-       NULL,                   /* writelist */
-       NULL,                   /* printer admin */
-       NULL,                   /* volume */
-       NULL,                   /* fstype */
-       NULL,                   /* vfs objects */
-       NULL,                   /* szMSDfsProxy */
-       NULL,                   /* szAioWriteBehind */
-       NULL,                   /* szDfree */
-       0,                      /* iMinPrintSpace */
-       1000,                   /* iMaxPrintJobs */
-       0,                      /* iMaxReportedPrintJobs */
-       0,                      /* iWriteCacheSize */
-       0744,                   /* iCreate_mask */
-       0000,                   /* iCreate_force_mode */
-       0777,                   /* iSecurity_mask */
-       0,                      /* iSecurity_force_mode */
-       0755,                   /* iDir_mask */
-       0000,                   /* iDir_force_mode */
-       0777,                   /* iDir_Security_mask */
-       0,                      /* iDir_Security_force_mode */
-       0,                      /* iMaxConnections */
-       CASE_LOWER,             /* iDefaultCase */
-       DEFAULT_PRINTING,       /* iPrinting */
-       2,                      /* iOplockContentionLimit */
-       0,                      /* iCSCPolicy */
-       1024,                   /* iBlock_size */
-       0,                      /* iDfreeCacheTime */
-       False,                  /* bPreexecClose */
-       False,                  /* bRootpreexecClose */
-       Auto,                   /* case sensitive */
-       True,                   /* case preserve */
-       True,                   /* short case preserve */
-       True,                   /* bHideDotFiles */
-       False,                  /* bHideSpecialFiles */
-       False,                  /* bHideUnReadable */
-       False,                  /* bHideUnWriteableFiles */
-       True,                   /* bBrowseable */
-       False,                  /* bAccessBasedShareEnum */
-       True,                   /* bAvailable */
-       True,                   /* bRead_only */
-       True,                   /* bNo_set_dir */
-       False,                  /* bGuest_only */
-       False,                  /* bAdministrative_share */
-       False,                  /* bGuest_ok */
-       False,                  /* bPrint_ok */
-       True,                   /* bPrintNotifyBackchannel */
-       False,                  /* bMap_system */
-       False,                  /* bMap_hidden */
-       True,                   /* bMap_archive */
-       False,                  /* bStoreDosAttributes */
-       False,                  /* bDmapiSupport */
-       True,                   /* bLocking */
-       Auto,                   /* iStrictLocking */
-       True,                   /* bPosixLocking */
-       True,                   /* bShareModes */
-       True,                   /* bOpLocks */
-       True,                   /* bLevel2OpLocks */
-       False,                  /* bOnlyUser */
-       True,                   /* bMangledNames */
-       false,                  /* bWidelinks */
-       True,                   /* bSymlinks */
-       False,                  /* bSyncAlways */
-       False,                  /* bStrictAllocate */
-       False,                  /* bStrictSync */
-       '~',                    /* magic char */
-       NULL,                   /* copymap */
-       False,                  /* bDeleteReadonly */
-       False,                  /* bFakeOplocks */
-       False,                  /* bDeleteVetoFiles */
-       False,                  /* bDosFilemode */
-       True,                   /* bDosFiletimes */
-       False,                  /* bDosFiletimeResolution */
-       False,                  /* bFakeDirCreateTimes */
-       True,                   /* bBlockingLocks */
-       False,                  /* bInheritPerms */
-       False,                  /* bInheritACLS */
-       False,                  /* bInheritOwner */
-       False,                  /* bMSDfsRoot */
-       False,                  /* bUseClientDriver */
-       True,                   /* bDefaultDevmode */
-       False,                  /* bForcePrintername */
-       True,                   /* bNTAclSupport */
-       False,                  /* bForceUnknownAclUser */
-       False,                  /* bUseSendfile */
-       False,                  /* bProfileAcls */
-       False,                  /* bMap_acl_inherit */
-       False,                  /* bAfs_Share */
-       False,                  /* bEASupport */
-       True,                   /* bAclCheckPermissions */
-       True,                   /* bAclMapFullControl */
-       False,                  /* bAclGroupControl */
-       True,                   /* bChangeNotify */
-       True,                   /* bKernelChangeNotify */
-       SMB_ROUNDUP_ALLOCATION_SIZE,            /* iallocation_roundup_size */
-       0,                      /* iAioReadSize */
-       0,                      /* iAioWriteSize */
-       MAP_READONLY_YES,       /* iMap_readonly */
+static struct loadparm_service sDefault =
+{
+       .valid = true,
+       .autoloaded = false,
+       .usershare = 0,
+       .usershare_last_mod = {0, 0},
+       .szService = NULL,
+       .szPath = NULL,
+       .szUsername = NULL,
+       .szInvalidUsers = NULL,
+       .szValidUsers = NULL,
+       .szAdminUsers = NULL,
+       .szCopy = NULL,
+       .szInclude = NULL,
+       .szPreExec = NULL,
+       .szPostExec = NULL,
+       .szRootPreExec = NULL,
+       .szRootPostExec = NULL,
+       .szCupsOptions = NULL,
+       .szPrintcommand = NULL,
+       .szLpqcommand = NULL,
+       .szLprmcommand = NULL,
+       .szLppausecommand = NULL,
+       .szLpresumecommand = NULL,
+       .szQueuepausecommand = NULL,
+       .szQueueresumecommand = NULL,
+       .szPrintername = NULL,
+       .szPrintjobUsername = NULL,
+       .szDontdescend = NULL,
+       .szHostsallow = NULL,
+       .szHostsdeny = NULL,
+       .szMagicScript = NULL,
+       .szMagicOutput = NULL,
+       .szVetoFiles = NULL,
+       .szHideFiles = NULL,
+       .szVetoOplockFiles = NULL,
+       .comment = NULL,
+       .force_user = NULL,
+       .force_group = NULL,
+       .readlist = NULL,
+       .writelist = NULL,
+       .printer_admin = NULL,
+       .volume = NULL,
+       .fstype = NULL,
+       .szVfsObjects = NULL,
+       .szMSDfsProxy = NULL,
+       .szAioWriteBehind = NULL,
+       .szDfree = NULL,
+       .iMinPrintSpace = 0,
+       .iMaxPrintJobs = 1000,
+       .iMaxReportedPrintJobs = 0,
+       .iWriteCacheSize = 0,
+       .iCreate_mask = 0744,
+       .iCreate_force_mode = 0,
+       .iSecurity_mask = 0777,
+       .iSecurity_force_mode = 0,
+       .iDir_mask = 0755,
+       .iDir_force_mode = 0,
+       .iDir_Security_mask = 0777,
+       .iDir_Security_force_mode = 0,
+       .iMaxConnections = 0,
+       .iDefaultCase = CASE_LOWER,
+       .iPrinting = DEFAULT_PRINTING,
+       .iOplockContentionLimit = 2,
+       .iCSCPolicy = 0,
+       .iBlock_size = 1024,
+       .iDfreeCacheTime = 0,
+       .bPreexecClose = false,
+       .bRootpreexecClose = false,
+       .iCaseSensitive = Auto,
+       .bCasePreserve = true,
+       .bShortCasePreserve = true,
+       .bHideDotFiles = true,
+       .bHideSpecialFiles = false,
+       .bHideUnReadable = false,
+       .bHideUnWriteableFiles = false,
+       .bBrowseable = true,
+       .bAccessBasedShareEnum = false,
+       .bAvailable = true,
+       .bRead_only = true,
+       .bNo_set_dir = true,
+       .bGuest_only = false,
+       .bAdministrative_share = false,
+       .bGuest_ok = false,
+       .bPrint_ok = false,
+       .bPrintNotifyBackchannel = true,
+       .bMap_system = false,
+       .bMap_hidden = false,
+       .bMap_archive = true,
+       .bStoreDosAttributes = false,
+       .bDmapiSupport = false,
+       .bLocking = true,
+       .iStrictLocking = Auto,
+       .bPosixLocking = true,
+       .bShareModes = true,
+       .bOpLocks = true,
+       .bLevel2OpLocks = true,
+       .bOnlyUser = false,
+       .bMangledNames = true,
+       .bWidelinks = false,
+       .bSymlinks = true,
+       .bSyncAlways = false,
+       .bStrictAllocate = false,
+       .bStrictSync = false,
+       .magic_char = '~',
+       .copymap = NULL,
+       .bDeleteReadonly = false,
+       .bFakeOplocks = false,
+       .bDeleteVetoFiles = false,
+       .bDosFilemode = false,
+       .bDosFiletimes = true,
+       .bDosFiletimeResolution = false,
+       .bFakeDirCreateTimes = false,
+       .bBlockingLocks = true,
+       .bInheritPerms = false,
+       .bInheritACLS = false,
+       .bInheritOwner = false,
+       .bMSDfsRoot = false,
+       .bUseClientDriver = false,
+       .bDefaultDevmode = true,
+       .bForcePrintername = false,
+       .bNTAclSupport = true,
+       .bForceUnknownAclUser = false,
+       .bUseSendfile = false,
+       .bProfileAcls = false,
+       .bMap_acl_inherit = false,
+       .bAfs_Share = false,
+       .bEASupport = false,
+       .bAclCheckPermissions = true,
+       .bAclMapFullControl = true,
+       .bAclGroupControl = false,
+       .bChangeNotify = true,
+       .bKernelChangeNotify = true,
+       .iallocation_roundup_size = SMB_ROUNDUP_ALLOCATION_SIZE,
+       .iAioReadSize = 0,
+       .iAioWriteSize = 0,
+       .iMap_readonly = MAP_READONLY_YES,
 #ifdef BROKEN_DIRECTORY_HANDLING
-       0,                      /* iDirectoryNameCacheSize */
+       .iDirectoryNameCacheSize = 0,
 #else
-       100,                    /* iDirectoryNameCacheSize */
+       .iDirectoryNameCacheSize = 100,
 #endif
-       Auto,                   /* ismb_encrypt */
-       NULL,                   /* Parametric options */
-
-       ""                      /* dummy */
+       .ismb_encrypt = Auto,
+       .param_opt = NULL,
+       .dummy = ""
 };
 
 /* local variables */
@@ -691,9 +288,8 @@ static int iServiceIndex = 0;
 static struct db_context *ServiceHash;
 static int *invalid_services = NULL;
 static int num_invalid_services = 0;
-static bool bInGlobalSection = True;
-static bool bGlobalOnly = False;
-static int default_server_announce;
+static bool bInGlobalSection = true;
+static bool bGlobalOnly = false;
 
 #define NUMPARAMETERS (sizeof(parm_table) / sizeof(struct parm_struct))
 
@@ -711,33 +307,13 @@ static bool handle_dos_charset(struct loadparm_context *unused, int snum, const
 static bool handle_printing(struct loadparm_context *unused, int snum, const char *pszParmValue, char **ptr);
 static bool handle_ldap_debug_level(struct loadparm_context *unused, int snum, const char *pszParmValue, char **ptr);
 
-static void set_default_server_announce_type(void);
 static void set_allowed_client_auth(void);
 
 static void add_to_file_list(const char *fname, const char *subfname);
 static bool lp_set_cmdline_helper(const char *pszParmName, const char *pszParmValue, bool store_values);
+static void free_param_opts(struct parmlist_entry **popts);
 
-static const struct enum_list enum_protocol[] = {
-       {PROTOCOL_SMB2, "SMB2"},
-       {PROTOCOL_NT1, "NT1"},
-       {PROTOCOL_LANMAN2, "LANMAN2"},
-       {PROTOCOL_LANMAN1, "LANMAN1"},
-       {PROTOCOL_CORE, "CORE"},
-       {PROTOCOL_COREPLUS, "COREPLUS"},
-       {PROTOCOL_COREPLUS, "CORE+"},
-       {-1, NULL}
-};
-
-static const struct enum_list enum_security[] = {
-       {SEC_SHARE, "SHARE"},
-       {SEC_USER, "USER"},
-       {SEC_SERVER, "SERVER"},
-       {SEC_DOMAIN, "DOMAIN"},
-#ifdef HAVE_ADS
-       {SEC_ADS, "ADS"},
-#endif
-       {-1, NULL}
-};
+#include "lib/param/param_enums.c"
 
 static const struct enum_list enum_printing[] = {
        {PRINT_SYSV, "sysv"},
@@ -815,47 +391,6 @@ static const struct enum_list enum_case[] = {
 };
 
 
-
-static const struct enum_list enum_bool_auto[] = {
-       {False, "No"},
-       {False, "False"},
-       {False, "0"},
-       {True, "Yes"},
-       {True, "True"},
-       {True, "1"},
-       {Auto, "Auto"},
-       {-1, NULL}
-};
-
-static const struct enum_list enum_csc_policy[] = {
-       {CSC_POLICY_MANUAL, "manual"},
-       {CSC_POLICY_DOCUMENTS, "documents"},
-       {CSC_POLICY_PROGRAMS, "programs"},
-       {CSC_POLICY_DISABLE, "disable"},
-       {-1, NULL}
-};
-
-/* SMB signing types. */
-static const struct enum_list enum_smb_signing_vals[] = {
-       {False, "No"},
-       {False, "False"},
-       {False, "0"},
-       {False, "Off"},
-       {False, "disabled"},
-       {True, "Yes"},
-       {True, "True"},
-       {True, "1"},
-       {True, "On"},
-       {True, "enabled"},
-       {Auto, "auto"},
-       {Required, "required"},
-       {Required, "mandatory"},
-       {Required, "force"},
-       {Required, "forced"},
-       {Required, "enforced"},
-       {-1, NULL}
-};
-
 /* ACL compatibility options. */
 static const struct enum_list enum_acl_compat_vals[] = {
     { ACL_COMPAT_AUTO, "auto" },
@@ -1062,6 +597,15 @@ static struct parm_struct parm_table[] = {
                .enum_list      = enum_config_backend,
                .flags          = FLAG_HIDE|FLAG_ADVANCED|FLAG_META,
        },
+       {
+               .label          = "server role",
+               .type           = P_ENUM,
+               .p_class        = P_GLOBAL,
+               .offset         = GLOBAL_VAR(ServerRole),
+               .special        = NULL,
+               .enum_list      = enum_server_role,
+               .flags          = FLAG_BASIC | FLAG_ADVANCED,
+       },
 
        {N_("Security Options"), P_SEP, P_SEPARATOR},
 
@@ -1390,15 +934,6 @@ static struct parm_struct parm_table[] = {
                .enum_list      = NULL,
                .flags          = FLAG_ADVANCED,
        },
-       {
-               .label          = "send spnego principal",
-               .type           = P_BOOL,
-               .p_class        = P_GLOBAL,
-               .offset         = GLOBAL_VAR(send_spnego_principal),
-               .special        = NULL,
-               .enum_list      = NULL,
-               .flags          = FLAG_ADVANCED,
-       },
        {
                .label          = "username",
                .type           = P_STRING,
@@ -1550,7 +1085,7 @@ static struct parm_struct parm_table[] = {
                .offset         = LOCAL_VAR(bAclCheckPermissions),
                .special        = NULL,
                .enum_list      = NULL,
-               .flags          = FLAG_ADVANCED | FLAG_GLOBAL | FLAG_SHARE,
+               .flags          = FLAG_ADVANCED | FLAG_GLOBAL | FLAG_SHARE | FLAG_DEPRECATED,
        },
        {
                .label          = "acl group control",
@@ -1874,7 +1409,7 @@ static struct parm_struct parm_table[] = {
        },
        {
                .label          = "max log size",
-               .type           = P_INTEGER,
+               .type           = P_BYTES,
                .p_class        = P_GLOBAL,
                .offset         = GLOBAL_VAR(max_log_size),
                .special        = NULL,
@@ -1958,7 +1493,7 @@ static struct parm_struct parm_table[] = {
 
        {
                .label          = "allocation roundup size",
-               .type           = P_INTEGER,
+               .type           = P_BYTES,
                .p_class        = P_LOCAL,
                .offset         = LOCAL_VAR(iallocation_roundup_size),
                .special        = NULL,
@@ -1967,7 +1502,7 @@ static struct parm_struct parm_table[] = {
        },
        {
                .label          = "aio read size",
-               .type           = P_INTEGER,
+               .type           = P_BYTES,
                .p_class        = P_LOCAL,
                .offset         = LOCAL_VAR(iAioReadSize),
                .special        = NULL,
@@ -1976,7 +1511,7 @@ static struct parm_struct parm_table[] = {
        },
        {
                .label          = "aio write size",
-               .type           = P_INTEGER,
+               .type           = P_BYTES,
                .p_class        = P_LOCAL,
                .offset         = LOCAL_VAR(iAioWriteSize),
                .special        = NULL,
@@ -2014,7 +1549,16 @@ static struct parm_struct parm_table[] = {
                .label          = "max protocol",
                .type           = P_ENUM,
                .p_class        = P_GLOBAL,
-               .offset         = GLOBAL_VAR(maxprotocol),
+               .offset         = GLOBAL_VAR(srv_maxprotocol),
+               .special        = NULL,
+               .enum_list      = enum_protocol,
+               .flags          = FLAG_ADVANCED,
+       },
+       {
+               .label          = "server max protocol",
+               .type           = P_ENUM,
+               .p_class        = P_GLOBAL,
+               .offset         = GLOBAL_VAR(srv_maxprotocol),
                .special        = NULL,
                .enum_list      = enum_protocol,
                .flags          = FLAG_ADVANCED,
@@ -2023,7 +1567,7 @@ static struct parm_struct parm_table[] = {
                .label          = "protocol",
                .type           = P_ENUM,
                .p_class        = P_GLOBAL,
-               .offset         = GLOBAL_VAR(maxprotocol),
+               .offset         = GLOBAL_VAR(srv_maxprotocol),
                .special        = NULL,
                .enum_list      = enum_protocol,
                .flags          = FLAG_ADVANCED,
@@ -2032,14 +1576,23 @@ static struct parm_struct parm_table[] = {
                .label          = "min protocol",
                .type           = P_ENUM,
                .p_class        = P_GLOBAL,
-               .offset         = GLOBAL_VAR(minprotocol),
+               .offset         = GLOBAL_VAR(srv_minprotocol),
+               .special        = NULL,
+               .enum_list      = enum_protocol,
+               .flags          = FLAG_ADVANCED,
+       },
+       {
+               .label          = "server min protocol",
+               .type           = P_ENUM,
+               .p_class        = P_GLOBAL,
+               .offset         = GLOBAL_VAR(srv_minprotocol),
                .special        = NULL,
                .enum_list      = enum_protocol,
                .flags          = FLAG_ADVANCED,
        },
        {
                .label          = "min receivefile size",
-               .type           = P_INTEGER,
+               .type           = P_BYTES,
                .p_class        = P_GLOBAL,
                .offset         = GLOBAL_VAR(iminreceivefile),
                .special        = NULL,
@@ -2183,7 +1736,7 @@ static struct parm_struct parm_table[] = {
        },
        {
                .label          = "max xmit",
-               .type           = P_INTEGER,
+               .type           = P_BYTES,
                .p_class        = P_GLOBAL,
                .offset         = GLOBAL_VAR(max_xmit),
                .special        = NULL,
@@ -2321,7 +1874,7 @@ static struct parm_struct parm_table[] = {
 
        {
                .label          = "block size",
-               .type           = P_INTEGER,
+               .type           = P_BYTES,
                .p_class        = P_LOCAL,
                .offset         = LOCAL_VAR(iBlock_size),
                .special        = NULL,
@@ -2420,7 +1973,7 @@ static struct parm_struct parm_table[] = {
        },
        {
                .label          = "max disk size",
-               .type           = P_INTEGER,
+               .type           = P_BYTES,
                .p_class        = P_GLOBAL,
                .offset         = GLOBAL_VAR(maxdisksize),
                .special        = NULL,
@@ -2510,7 +2063,7 @@ static struct parm_struct parm_table[] = {
        },
        {
                .label          = "write cache size",
-               .type           = P_INTEGER,
+               .type           = P_BYTES,
                .p_class        = P_LOCAL,
                .offset         = LOCAL_VAR(iWriteCacheSize),
                .special        = NULL,
@@ -2573,7 +2126,7 @@ static struct parm_struct parm_table[] = {
        },
        {
                .label          = "smb2 max read",
-               .type           = P_INTEGER,
+               .type           = P_BYTES,
                .p_class        = P_GLOBAL,
                .offset         = GLOBAL_VAR(ismb2_max_read),
                .special        = NULL,
@@ -2582,7 +2135,7 @@ static struct parm_struct parm_table[] = {
        },
        {
                .label          = "smb2 max write",
-               .type           = P_INTEGER,
+               .type           = P_BYTES,
                .p_class        = P_GLOBAL,
                .offset         = GLOBAL_VAR(ismb2_max_write),
                .special        = NULL,
@@ -2591,7 +2144,7 @@ static struct parm_struct parm_table[] = {
        },
        {
                .label          = "smb2 max trans",
-               .type           = P_INTEGER,
+               .type           = P_BYTES,
                .p_class        = P_GLOBAL,
                .offset         = GLOBAL_VAR(ismb2_max_trans),
                .special        = NULL,
@@ -4302,6 +3855,15 @@ static struct parm_struct parm_table[] = {
                .enum_list      = NULL,
                .flags          = FLAG_ADVANCED | FLAG_SHARE,
        },
+       {
+               .label          = "allow insecure wide links",
+               .type           = P_BOOL,
+               .p_class        = P_GLOBAL,
+               .offset         = GLOBAL_VAR(bAllowInsecureWidelinks),
+               .special        = NULL,
+               .enum_list      = NULL,
+               .flags          = FLAG_ADVANCED,
+       },
        {
                .label          = "wide links",
                .type           = P_BOOL,
@@ -5009,6 +4571,7 @@ static void free_parameters_by_snum(int snum)
  */
 static void free_global_parameters(void)
 {
+       free_param_opts(&Globals.param_opt);
        free_parameters_by_snum(GLOBAL_SECTION_SNUM);
 }
 
@@ -5080,7 +4643,7 @@ static bool apply_lp_set_cmdline(void)
 
 static void init_globals(bool reinit_globals)
 {
-       static bool done_init = False;
+       static bool done_init = false;
        char *s = NULL;
        int i;
 
@@ -5096,7 +4659,7 @@ static void init_globals(bool reinit_globals)
                        string_free(&Globals.szLogFile);
                        Globals.szLogFile = NULL;
                }
-               done_init = True;
+               done_init = true;
        } else {
                free_global_parameters();
        }
@@ -5105,13 +4668,13 @@ static void init_globals(bool reinit_globals)
         * wipe out smb.conf options set with lp_set_cmdline().  The
         * apply_lp_set_cmdline() call puts these values back in the
         * table once the defaults are set */
-       memset((void *)&Globals, '\0', sizeof(Globals));
+       ZERO_STRUCT(Globals);
 
        for (i = 0; parm_table[i].label; i++) {
                if ((parm_table[i].type == P_STRING ||
                     parm_table[i].type == P_USTRING))
                {
-                       string_set(lp_parm_ptr(NULL, &parm_table[i]), "");
+                       string_set((char **)lp_parm_ptr(NULL, &parm_table[i]), "");
                }
        }
 
@@ -5147,7 +4710,7 @@ static void init_globals(bool reinit_globals)
         */
        string_set(&Globals.szPasswdChat, DEFAULT_PASSWD_CHAT);
 
-       string_set(&Globals.szWorkgroup, WORKGROUP);
+       string_set(&Globals.szWorkgroup, DEFAULT_WORKGROUP);
 
        string_set(&Globals.szPasswdProgram, "");
        string_set(&Globals.szLockDir, get_dyn_LOCKDIR());
@@ -5182,78 +4745,78 @@ static void init_globals(bool reinit_globals)
 
        Globals.AlgorithmicRidBase = BASE_RID;
 
-       Globals.bLoadPrinters = True;
+       Globals.bLoadPrinters = true;
        Globals.PrintcapCacheTime = 750;        /* 12.5 minutes */
 
        Globals.ConfigBackend = config_backend;
+       Globals.ServerRole = ROLE_AUTO;
 
        /* Was 65535 (0xFFFF). 0x4101 matches W2K and causes major speed improvements... */
        /* Discovered by 2 days of pain by Don McCall @ HP :-). */
        Globals.max_xmit = 0x4104;
        Globals.max_mux = 50;   /* This is *needed* for profile support. */
        Globals.lpqcachetime = 30;      /* changed to handle large print servers better -- jerry */
-       Globals.bDisableSpoolss = False;
+       Globals.bDisableSpoolss = false;
        Globals.iMaxSmbdProcesses = 0;/* no limit specified */
        Globals.pwordlevel = 0;
        Globals.unamelevel = 0;
        Globals.deadtime = 0;
        Globals.getwd_cache = true;
-       Globals.bLargeReadwrite = True;
+       Globals.bLargeReadwrite = true;
        Globals.max_log_size = 5000;
        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;
+       Globals.srv_maxprotocol = PROTOCOL_NT1;
+       Globals.srv_minprotocol = PROTOCOL_CORE;
        Globals.security = SEC_USER;
-       Globals.paranoid_server_security = True;
-       Globals.bEncryptPasswords = True;
-       Globals.bUpdateEncrypt = False;
+       Globals.paranoid_server_security = true;
+       Globals.bEncryptPasswords = true;
        Globals.clientSchannel = Auto;
        Globals.serverSchannel = Auto;
-       Globals.bReadRaw = True;
-       Globals.bWriteRaw = True;
-       Globals.bNullPasswords = False;
-       Globals.bObeyPamRestrictions = False;
+       Globals.bReadRaw = true;
+       Globals.bWriteRaw = true;
+       Globals.bNullPasswords = false;
+       Globals.bObeyPamRestrictions = false;
        Globals.syslog = 1;
-       Globals.bSyslogOnly = False;
-       Globals.bTimestampLogs = True;
+       Globals.bSyslogOnly = false;
+       Globals.bTimestampLogs = true;
        string_set(&Globals.szLogLevel, "0");
-       Globals.bDebugPrefixTimestamp = False;
+       Globals.bDebugPrefixTimestamp = false;
        Globals.bDebugHiresTimestamp = true;
-       Globals.bDebugPid = False;
-       Globals.bDebugUid = False;
-       Globals.bDebugClass = False;
-       Globals.bEnableCoreFiles = True;
+       Globals.bDebugPid = false;
+       Globals.bDebugUid = false;
+       Globals.bDebugClass = false;
+       Globals.bEnableCoreFiles = true;
        Globals.max_ttl = 60 * 60 * 24 * 3;     /* 3 days default. */
        Globals.max_wins_ttl = 60 * 60 * 24 * 6;        /* 6 days default. */
        Globals.min_wins_ttl = 60 * 60 * 6;     /* 6 hours default. */
        Globals.machine_password_timeout = 60 * 60 * 24 * 7;    /* 7 days default. */
-       Globals.lm_announce = 2;        /* = Auto: send only if LM clients found */
+       Globals.lm_announce = Auto;     /* = Auto: send only if LM clients found */
        Globals.lm_interval = 60;
 #if (defined(HAVE_NETGROUP) && defined(WITH_AUTOMOUNT))
-       Globals.bNISHomeMap = False;
+       Globals.bNISHomeMap = false;
 #ifdef WITH_NISPLUS_HOME
        string_set(&Globals.szNISHomeMapName, "auto_home.org_dir");
 #else
        string_set(&Globals.szNISHomeMapName, "auto.home");
 #endif
 #endif
-       Globals.bTimeServer = False;
-       Globals.bBindInterfacesOnly = False;
-       Globals.bUnixPasswdSync = False;
-       Globals.bPamPasswordChange = False;
-       Globals.bPasswdChatDebug = False;
+       Globals.bTimeServer = false;
+       Globals.bBindInterfacesOnly = false;
+       Globals.bUnixPasswdSync = false;
+       Globals.bPamPasswordChange = false;
+       Globals.bPasswdChatDebug = false;
        Globals.iPasswdChatTimeout = 2; /* 2 second default. */
-       Globals.bNTPipeSupport = True;  /* Do NT pipes by default. */
-       Globals.bNTStatusSupport = True; /* Use NT status by default. */
-       Globals.bStatCache = True;      /* use stat cache by default */
+       Globals.bNTPipeSupport = true;  /* Do NT pipes by default. */
+       Globals.bNTStatusSupport = true; /* Use NT status by default. */
+       Globals.bStatCache = true;      /* use stat cache by default */
        Globals.iMaxStatCacheSize = 256; /* 256k by default */
        Globals.restrict_anonymous = 0;
-       Globals.bClientLanManAuth = False;      /* Do NOT use the LanMan hash if it is available */
-       Globals.bClientPlaintextAuth = False;   /* Do NOT use a plaintext password even if is requested by the server */
-       Globals.bLanmanAuth = False;    /* Do NOT use the LanMan hash, even if it is supplied */
-       Globals.bNTLMAuth = True;       /* Do use NTLMv1 if it is supplied by the client (otherwise NTLMv2) */
-       Globals.bClientNTLMv2Auth = True; /* Client should always use use NTLMv2, as we can't tell that the server supports it, but most modern servers do */
+       Globals.bClientLanManAuth = false;      /* Do NOT use the LanMan hash if it is available */
+       Globals.bClientPlaintextAuth = false;   /* Do NOT use a plaintext password even if is requested by the server */
+       Globals.bLanmanAuth = false;    /* Do NOT use the LanMan hash, even if it is supplied */
+       Globals.bNTLMAuth = true;       /* Do use NTLMv1 if it is supplied by the client (otherwise NTLMv2) */
+       Globals.bClientNTLMv2Auth = true; /* Client should always use use NTLMv2, as we can't tell that the server supports it, but most modern servers do */
        /* Note, that we will also use NTLM2 session security (which is different), if it is available */
 
        Globals.map_to_guest = 0;       /* By Default, "Never" */
@@ -5261,19 +4824,19 @@ static void init_globals(bool reinit_globals)
        Globals.enhanced_browsing = true;
        Globals.iLockSpinTime = WINDOWS_MINIMUM_LOCK_TIMEOUT_MS; /* msec. */
 #ifdef MMAP_BLACKLIST
-       Globals.bUseMmap = False;
+       Globals.bUseMmap = false;
 #else
-       Globals.bUseMmap = True;
+       Globals.bUseMmap = true;
 #endif
-       Globals.bUnixExtensions = True;
-       Globals.bResetOnZeroVC = False;
-       Globals.bLogWriteableFilesOnExit = False;
+       Globals.bUnixExtensions = true;
+       Globals.bResetOnZeroVC = false;
+       Globals.bLogWriteableFilesOnExit = false;
        Globals.bCreateKrb5Conf = true;
        Globals.winbindMaxDomainConnections = 1;
 
        /* hostname lookups can be very expensive and are broken on
           a large number of sites (tridge) */
-       Globals.bHostnameLookups = False;
+       Globals.bHostnameLookups = false;
 
        string_set(&Globals.szPassdbBackend, "tdbsam");
        string_set(&Globals.szLdapSuffix, "");
@@ -5284,10 +4847,10 @@ static void init_globals(bool reinit_globals)
 
        string_set(&Globals.szLdapAdminDn, "");
        Globals.ldap_ssl = LDAP_SSL_START_TLS;
-       Globals.ldap_ssl_ads = False;
+       Globals.ldap_ssl_ads = false;
        Globals.ldap_deref = -1;
        Globals.ldap_passwd_sync = LDAP_PASSWD_SYNC_OFF;
-       Globals.ldap_delete_dn = False;
+       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;
@@ -5307,34 +4870,33 @@ static void init_globals(bool reinit_globals)
    for the increasing samba install base:
 
    as a member of the workgroup, that will possibly become a
-   _local_ master browser (lm = True).  this is opposed to a forced
-   local master browser startup (pm = True).
+   _local_ master browser (lm = true).  this is opposed to a forced
+   local master browser startup (pm = true).
 
-   doesn't provide WINS server service by default (wsupp = False),
+   doesn't provide WINS server service by default (wsupp = false),
    and doesn't provide domain master browser services by default, either.
 
 */
 
-       Globals.bMsAddPrinterWizard = True;
+       Globals.bMsAddPrinterWizard = true;
        Globals.os_level = 20;
-       Globals.bLocalMaster = True;
+       Globals.bLocalMaster = true;
        Globals.iDomainMaster = Auto;   /* depending on bDomainLogons */
-       Globals.bDomainLogons = False;
-       Globals.bBrowseList = True;
-       Globals.bWINSsupport = False;
-       Globals.bWINSproxy = False;
+       Globals.bDomainLogons = false;
+       Globals.bBrowseList = true;
+       Globals.bWINSsupport = false;
+       Globals.bWINSproxy = false;
 
        TALLOC_FREE(Globals.szInitLogonDelayedHosts);
        Globals.InitLogonDelay = 100; /* 100 ms default delay */
 
-       Globals.bDNSproxy = True;
+       Globals.bDNSproxy = true;
 
        /* this just means to use them if they exist */
-       Globals.bKernelOplocks = True;
+       Globals.bKernelOplocks = true;
 
-       Globals.bAllowTrustedDomains = True;
+       Globals.bAllowTrustedDomains = true;
        string_set(&Globals.szIdmapBackend, "tdb");
-       Globals.bIdmapReadOnly = false;
 
        string_set(&Globals.szTemplateShell, "/bin/false");
        string_set(&Globals.szTemplateHomedir, "/home/%D/%U");
@@ -5345,42 +4907,42 @@ static void init_globals(bool reinit_globals)
 
        string_set(&Globals.ctdbdSocket, "");
        Globals.szClusterAddresses = NULL;
-       Globals.clustering = False;
+       Globals.clustering = false;
        Globals.ctdb_timeout = 0;
        Globals.ctdb_locktime_warn_threshold = 0;
 
        Globals.winbind_cache_time = 300;       /* 5 minutes */
        Globals.winbind_reconnect_delay = 30;   /* 30 seconds */
        Globals.winbind_max_clients = 200;
-       Globals.bWinbindEnumUsers = False;
-       Globals.bWinbindEnumGroups = False;
-       Globals.bWinbindUseDefaultDomain = False;
-       Globals.bWinbindTrustedDomainsOnly = False;
-       Globals.bWinbindNestedGroups = True;
+       Globals.bWinbindEnumUsers = false;
+       Globals.bWinbindEnumGroups = false;
+       Globals.bWinbindUseDefaultDomain = false;
+       Globals.bWinbindTrustedDomainsOnly = false;
+       Globals.bWinbindNestedGroups = true;
        Globals.winbind_expand_groups = 1;
-       Globals.szWinbindNssInfo = str_list_make_v3(NULL, "template", NULL);
-       Globals.bWinbindRefreshTickets = False;
-       Globals.bWinbindOfflineLogon = False;
+       Globals.szWinbindNssInfo = (const char **)str_list_make_v3(NULL, "template", NULL);
+       Globals.bWinbindRefreshTickets = false;
+       Globals.bWinbindOfflineLogon = false;
 
        Globals.iIdmapCacheTime = 86400 * 7; /* a week by default */
        Globals.iIdmapNegativeCacheTime = 120; /* 2 minutes by default */
 
-       Globals.bPassdbExpandExplicit = False;
+       Globals.bPassdbExpandExplicit = false;
 
        Globals.name_cache_timeout = 660; /* In seconds */
 
-       Globals.bUseSpnego = True;
-       Globals.bClientUseSpnego = True;
+       Globals.bUseSpnego = true;
+       Globals.bClientUseSpnego = true;
 
-       Globals.client_signing = Auto;
-       Globals.server_signing = False;
+       Globals.client_signing = SMB_SIGNING_DEFAULT;
+       Globals.server_signing = SMB_SIGNING_DEFAULT;
 
-       Globals.bDeferSharingViolations = True;
+       Globals.bDeferSharingViolations = true;
        string_set(&Globals.smb_ports, SMB_PORTS);
 
-       Globals.bEnablePrivileges = True;
-       Globals.bHostMSDfs        = True;
-       Globals.bASUSupport       = False;
+       Globals.bEnablePrivileges = true;
+       Globals.bHostMSDfs        = true;
+       Globals.bASUSupport       = false;
 
        /* User defined shares. */
        if (asprintf(&s, "%s/usershares", get_dyn_STATEDIR()) < 0) {
@@ -5391,14 +4953,14 @@ static void init_globals(bool reinit_globals)
        string_set(&Globals.szUsershareTemplateShare, "");
        Globals.iUsershareMaxShares = 0;
        /* By default disallow sharing of directories not owned by the sharer. */
-       Globals.bUsershareOwnerOnly = True;
+       Globals.bUsershareOwnerOnly = true;
        /* By default disallow guest access to usershares. */
-       Globals.bUsershareAllowGuests = False;
+       Globals.bUsershareAllowGuests = false;
 
        Globals.iKeepalive = DEFAULT_KEEPALIVE;
 
        /* By default no shares out of the registry */
-       Globals.bRegistryShares = False;
+       Globals.bRegistryShares = false;
 
        Globals.iminreceivefile = 0;
 
@@ -5474,22 +5036,22 @@ static char *lp_string(const char *s)
  int fn_name(void) {return(*(int *)(&Globals.ptr));}
 
 #define FN_LOCAL_STRING(fn_name,val) \
- char *fn_name(int i) {return(lp_string((LP_SNUM_OK(i) && ServicePtrs[(i)]->val) ? ServicePtrs[(i)]->val : sDefault.val));}
+ char *lp_ ## fn_name(int i) {return(lp_string((LP_SNUM_OK(i) && ServicePtrs[(i)]->val) ? ServicePtrs[(i)]->val : sDefault.val));}
 #define FN_LOCAL_CONST_STRING(fn_name,val) \
- const char *fn_name(int i) {return (const char *)((LP_SNUM_OK(i) && ServicePtrs[(i)]->val) ? ServicePtrs[(i)]->val : sDefault.val);}
+ const char *lp_ ## fn_name(int i) {return (const char *)((LP_SNUM_OK(i) && ServicePtrs[(i)]->val) ? ServicePtrs[(i)]->val : sDefault.val);}
 #define FN_LOCAL_LIST(fn_name,val) \
- const char **fn_name(int i) {return(const char **)(LP_SNUM_OK(i)? ServicePtrs[(i)]->val : sDefault.val);}
+ const char **lp_ ## fn_name(int i) {return(const char **)(LP_SNUM_OK(i)? ServicePtrs[(i)]->val : sDefault.val);}
 #define FN_LOCAL_BOOL(fn_name,val) \
- bool fn_name(int i) {return(bool)(LP_SNUM_OK(i)? ServicePtrs[(i)]->val : sDefault.val);}
+ bool lp_ ## fn_name(int i) {return(bool)(LP_SNUM_OK(i)? ServicePtrs[(i)]->val : sDefault.val);}
 #define FN_LOCAL_INTEGER(fn_name,val) \
- int fn_name(int i) {return(LP_SNUM_OK(i)? ServicePtrs[(i)]->val : sDefault.val);}
+ int lp_ ## fn_name(int i) {return(LP_SNUM_OK(i)? ServicePtrs[(i)]->val : sDefault.val);}
 
 #define FN_LOCAL_PARM_BOOL(fn_name,val) \
- bool fn_name(const struct share_params *p) {return(bool)(LP_SNUM_OK(p->service)? ServicePtrs[(p->service)]->val : sDefault.val);}
+ bool lp_ ## fn_name(const struct share_params *p) {return(bool)(LP_SNUM_OK(p->service)? ServicePtrs[(p->service)]->val : sDefault.val);}
 #define FN_LOCAL_PARM_INTEGER(fn_name,val) \
- int fn_name(const struct share_params *p) {return(LP_SNUM_OK(p->service)? ServicePtrs[(p->service)]->val : sDefault.val);}
+ int lp_ ## fn_name(const struct share_params *p) {return(LP_SNUM_OK(p->service)? ServicePtrs[(p->service)]->val : sDefault.val);}
 #define FN_LOCAL_CHAR(fn_name,val) \
- char fn_name(const struct share_params *p) {return(LP_SNUM_OK(p->service)? ServicePtrs[(p->service)]->val : sDefault.val);}
+ char lp_ ## fn_name(const struct share_params *p) {return(LP_SNUM_OK(p->service)? ServicePtrs[(p->service)]->val : sDefault.val);}
 
 FN_GLOBAL_CONST_STRING(lp_smb_ports, smb_ports)
 FN_GLOBAL_CONST_STRING(lp_dos_charset, dos_charset)
@@ -5651,15 +5213,13 @@ FN_GLOBAL_BOOL(lp_usershare_allow_guests, bUsershareAllowGuests)
 FN_GLOBAL_BOOL(lp_usershare_owner_only, bUsershareOwnerOnly)
 FN_GLOBAL_BOOL(lp_disable_netbios, bDisableNetbios)
 FN_GLOBAL_BOOL(lp_reset_on_zero_vc, bResetOnZeroVC)
-FN_GLOBAL_BOOL(lp_log_writeable_files_on_exit,
-              bLogWriteableFilesOnExit)
+FN_GLOBAL_BOOL(lp_log_writeable_files_on_exit, bLogWriteableFilesOnExit)
 FN_GLOBAL_BOOL(lp_ms_add_printer_wizard, bMsAddPrinterWizard)
 FN_GLOBAL_BOOL(lp_dns_proxy, bDNSproxy)
-FN_GLOBAL_BOOL(lp_wins_support, bWINSsupport)
 FN_GLOBAL_BOOL(lp_we_are_a_wins_server, bWINSsupport)
 FN_GLOBAL_BOOL(lp_wins_proxy, bWINSproxy)
 FN_GLOBAL_BOOL(lp_local_master, bLocalMaster)
-FN_GLOBAL_BOOL(lp_domain_logons, bDomainLogons)
+static FN_GLOBAL_BOOL(lp_domain_logons, bDomainLogons)
 FN_GLOBAL_LIST(lp_init_logon_delayed_hosts, szInitLogonDelayedHosts)
 FN_GLOBAL_INTEGER(lp_init_logon_delay, InitLogonDelay)
 FN_GLOBAL_BOOL(lp_load_printers, bLoadPrinters)
@@ -5707,10 +5267,7 @@ FN_GLOBAL_BOOL(lp_unix_extensions, bUnixExtensions)
 FN_GLOBAL_BOOL(lp_use_spnego, bUseSpnego)
 FN_GLOBAL_BOOL(lp_client_use_spnego, bClientUseSpnego)
 FN_GLOBAL_BOOL(lp_client_use_spnego_principal, client_use_spnego_principal)
-FN_GLOBAL_BOOL(lp_send_spnego_principal, send_spnego_principal)
 FN_GLOBAL_BOOL(lp_hostname_lookups, bHostnameLookups)
-FN_LOCAL_PARM_BOOL(lp_change_notify, bChangeNotify)
-FN_LOCAL_PARM_BOOL(lp_kernel_change_notify, bKernelChangeNotify)
 FN_GLOBAL_CONST_STRING(lp_dedicated_keytab_file, szDedicatedKeytabFile)
 FN_GLOBAL_INTEGER(lp_kerberos_method, iKerberosMethod)
 FN_GLOBAL_BOOL(lp_defer_sharing_violations, bDeferSharingViolations)
@@ -5729,19 +5286,8 @@ FN_GLOBAL_INTEGER(lp_passwordlevel, pwordlevel)
 FN_GLOBAL_INTEGER(lp_usernamelevel, unamelevel)
 FN_GLOBAL_INTEGER(lp_deadtime, deadtime)
 FN_GLOBAL_BOOL(lp_getwd_cache, getwd_cache)
-static FN_GLOBAL_INTEGER(_lp_maxprotocol, maxprotocol)
-int lp_maxprotocol(void)
-{
-       int ret = _lp_maxprotocol();
-       if ((ret == PROTOCOL_SMB2) && (lp_security() == SEC_SHARE)) {
-               DEBUG(2,("WARNING!!: \"security = share\" is incompatible "
-                       "with the SMB2 protocol. Resetting to SMB1.\n" ));
-                       lp_do_parameter(-1, "max protocol", "NT1");
-               return PROTOCOL_NT1;
-       }
-       return ret;
-}
-FN_GLOBAL_INTEGER(lp_minprotocol, minprotocol)
+FN_GLOBAL_INTEGER(lp_srv_maxprotocol, srv_maxprotocol)
+FN_GLOBAL_INTEGER(lp_srv_minprotocol, srv_minprotocol)
 FN_GLOBAL_INTEGER(lp_security, security)
 FN_GLOBAL_LIST(lp_auth_methods, AuthMethods)
 FN_GLOBAL_BOOL(lp_paranoid_server_security, paranoid_server_security)
@@ -5759,6 +5305,7 @@ FN_GLOBAL_INTEGER(lp_lock_spin_time, iLockSpinTime)
 FN_GLOBAL_INTEGER(lp_usershare_max_shares, iUsershareMaxShares)
 FN_GLOBAL_CONST_STRING(lp_socket_options, szSocketOptions)
 FN_GLOBAL_INTEGER(lp_config_backend, ConfigBackend)
+static FN_GLOBAL_INTEGER(lp__server_role, ServerRole)
 FN_GLOBAL_INTEGER(lp_smb2_max_read, ismb2_max_read)
 FN_GLOBAL_INTEGER(lp_smb2_max_write, ismb2_max_write)
 FN_GLOBAL_INTEGER(lp_smb2_max_trans, ismb2_max_trans)
@@ -5769,20 +5316,7 @@ int lp_smb2_max_credits(void)
        }
        return Globals.ismb2_max_credits;
 }
-FN_LOCAL_STRING(lp_preexec, szPreExec)
-FN_LOCAL_STRING(lp_postexec, szPostExec)
-FN_LOCAL_STRING(lp_rootpreexec, szRootPreExec)
-FN_LOCAL_STRING(lp_rootpostexec, szRootPostExec)
-FN_LOCAL_STRING(lp_servicename, szService)
-FN_LOCAL_CONST_STRING(lp_const_servicename, szService)
-FN_LOCAL_STRING(lp_pathname, szPath)
-FN_LOCAL_STRING(lp_dontdescend, szDontdescend)
-FN_LOCAL_STRING(lp_username, szUsername)
-FN_LOCAL_LIST(lp_invalid_users, szInvalidUsers)
-FN_LOCAL_LIST(lp_valid_users, szValidUsers)
-FN_LOCAL_LIST(lp_admin_users, szAdminUsers)
 FN_GLOBAL_LIST(lp_svcctl_list, szServicesList)
-FN_LOCAL_STRING(lp_cups_options, szCupsOptions)
 FN_GLOBAL_STRING(lp_cups_server, szCupsServer)
 int lp_cups_encrypt(void)
 {
@@ -5792,10 +5326,10 @@ int lp_cups_encrypt(void)
                case Auto:
                        result = HTTP_ENCRYPT_REQUIRED;
                        break;
-               case True:
+               case true:
                        result = HTTP_ENCRYPT_ALWAYS;
                        break;
-               case False:
+               case false:
                        result = HTTP_ENCRYPT_NEVER;
                        break;
        }
@@ -5809,122 +5343,9 @@ FN_GLOBAL_LIST(lp_cluster_addresses, szClusterAddresses)
 FN_GLOBAL_BOOL(lp_clustering, clustering)
 FN_GLOBAL_INTEGER(lp_ctdb_timeout, ctdb_timeout)
 FN_GLOBAL_INTEGER(lp_ctdb_locktime_warn_threshold, ctdb_locktime_warn_threshold)
-FN_LOCAL_STRING(lp_printcommand, szPrintcommand)
-FN_LOCAL_STRING(lp_lpqcommand, szLpqcommand)
-FN_LOCAL_STRING(lp_lprmcommand, szLprmcommand)
-FN_LOCAL_STRING(lp_lppausecommand, szLppausecommand)
-FN_LOCAL_STRING(lp_lpresumecommand, szLpresumecommand)
-FN_LOCAL_STRING(lp_queuepausecommand, szQueuepausecommand)
-FN_LOCAL_STRING(lp_queueresumecommand, szQueueresumecommand)
-static FN_LOCAL_STRING(_lp_printername, szPrintername)
-FN_LOCAL_CONST_STRING(lp_printjob_username, szPrintjobUsername)
-FN_LOCAL_LIST(lp_hostsallow, szHostsallow)
-FN_LOCAL_LIST(lp_hostsdeny, szHostsdeny)
-FN_LOCAL_STRING(lp_magicscript, szMagicScript)
-FN_LOCAL_STRING(lp_magicoutput, szMagicOutput)
-FN_LOCAL_STRING(lp_comment, comment)
-FN_LOCAL_STRING(lp_force_user, force_user)
-FN_LOCAL_STRING(lp_force_group, force_group)
-FN_LOCAL_LIST(lp_readlist, readlist)
-FN_LOCAL_LIST(lp_writelist, writelist)
-FN_LOCAL_LIST(lp_printer_admin, printer_admin)
-FN_LOCAL_STRING(lp_fstype, fstype)
-FN_LOCAL_LIST(lp_vfs_objects, szVfsObjects)
-FN_LOCAL_STRING(lp_msdfs_proxy, szMSDfsProxy)
-static FN_LOCAL_STRING(lp_volume, volume)
-FN_LOCAL_STRING(lp_veto_files, szVetoFiles)
-FN_LOCAL_STRING(lp_hide_files, szHideFiles)
-FN_LOCAL_STRING(lp_veto_oplocks, szVetoOplockFiles)
-FN_LOCAL_BOOL(lp_msdfs_root, bMSDfsRoot)
-FN_LOCAL_STRING(lp_aio_write_behind, szAioWriteBehind)
-FN_LOCAL_STRING(lp_dfree_command, szDfree)
-FN_LOCAL_BOOL(lp_autoloaded, autoloaded)
-FN_LOCAL_BOOL(lp_preexec_close, bPreexecClose)
-FN_LOCAL_BOOL(lp_rootpreexec_close, bRootpreexecClose)
-FN_LOCAL_INTEGER(lp_casesensitive, iCaseSensitive)
-FN_LOCAL_BOOL(lp_preservecase, bCasePreserve)
-FN_LOCAL_BOOL(lp_shortpreservecase, bShortCasePreserve)
-FN_LOCAL_BOOL(lp_hide_dot_files, bHideDotFiles)
-FN_LOCAL_BOOL(lp_hide_special_files, bHideSpecialFiles)
-FN_LOCAL_BOOL(lp_hideunreadable, bHideUnReadable)
-FN_LOCAL_BOOL(lp_hideunwriteable_files, bHideUnWriteableFiles)
-FN_LOCAL_BOOL(lp_browseable, bBrowseable)
-FN_LOCAL_BOOL(lp_access_based_share_enum, bAccessBasedShareEnum)
-FN_LOCAL_BOOL(lp_readonly, bRead_only)
-FN_LOCAL_BOOL(lp_no_set_dir, bNo_set_dir)
-FN_LOCAL_BOOL(lp_guest_ok, bGuest_ok)
-FN_LOCAL_BOOL(lp_guest_only, bGuest_only)
-FN_LOCAL_BOOL(lp_administrative_share, bAdministrative_share)
-FN_LOCAL_BOOL(lp_print_ok, bPrint_ok)
-FN_LOCAL_BOOL(lp_print_notify_backchannel, bPrintNotifyBackchannel)
-FN_LOCAL_BOOL(lp_map_hidden, bMap_hidden)
-FN_LOCAL_BOOL(lp_map_archive, bMap_archive)
-FN_LOCAL_BOOL(lp_store_dos_attributes, bStoreDosAttributes)
-FN_LOCAL_BOOL(lp_dmapi_support, bDmapiSupport)
-FN_LOCAL_PARM_BOOL(lp_locking, bLocking)
-FN_LOCAL_PARM_INTEGER(lp_strict_locking, iStrictLocking)
-FN_LOCAL_PARM_BOOL(lp_posix_locking, bPosixLocking)
-FN_LOCAL_BOOL(lp_share_modes, bShareModes)
-FN_LOCAL_BOOL(lp_oplocks, bOpLocks)
-FN_LOCAL_BOOL(lp_level2_oplocks, bLevel2OpLocks)
-FN_LOCAL_BOOL(lp_onlyuser, bOnlyUser)
-FN_LOCAL_PARM_BOOL(lp_manglednames, bMangledNames)
-FN_LOCAL_BOOL(lp_symlinks, bSymlinks)
-FN_LOCAL_BOOL(lp_syncalways, bSyncAlways)
-FN_LOCAL_BOOL(lp_strict_allocate, bStrictAllocate)
-FN_LOCAL_BOOL(lp_strict_sync, bStrictSync)
-FN_LOCAL_BOOL(lp_map_system, bMap_system)
-FN_LOCAL_BOOL(lp_delete_readonly, bDeleteReadonly)
-FN_LOCAL_BOOL(lp_fake_oplocks, bFakeOplocks)
-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_async_smb_echo_handler, bAsyncSMBEchoHandler)
 FN_GLOBAL_BOOL(lp_multicast_dns_register, bMulticastDnsRegister)
-FN_LOCAL_BOOL(lp_blocking_locks, bBlockingLocks)
-FN_LOCAL_BOOL(lp_inherit_perms, bInheritPerms)
-FN_LOCAL_BOOL(lp_inherit_acls, bInheritACLS)
-FN_LOCAL_BOOL(lp_inherit_owner, bInheritOwner)
-FN_LOCAL_BOOL(lp_use_client_driver, bUseClientDriver)
-FN_LOCAL_BOOL(lp_default_devmode, bDefaultDevmode)
-FN_LOCAL_BOOL(lp_force_printername, bForcePrintername)
-FN_LOCAL_BOOL(lp_nt_acl_support, bNTAclSupport)
-FN_LOCAL_BOOL(lp_force_unknown_acl_user, bForceUnknownAclUser)
-FN_LOCAL_BOOL(lp_ea_support, bEASupport)
-FN_LOCAL_BOOL(_lp_use_sendfile, bUseSendfile)
-FN_LOCAL_BOOL(lp_profile_acls, bProfileAcls)
-FN_LOCAL_BOOL(lp_map_acl_inherit, bMap_acl_inherit)
-FN_LOCAL_BOOL(lp_afs_share, bAfs_Share)
-FN_LOCAL_BOOL(lp_acl_check_permissions, bAclCheckPermissions)
-FN_LOCAL_BOOL(lp_acl_group_control, bAclGroupControl)
-FN_LOCAL_BOOL(lp_acl_map_full_control, bAclMapFullControl)
-FN_LOCAL_INTEGER(lp_create_mask, iCreate_mask)
-FN_LOCAL_INTEGER(lp_force_create_mode, iCreate_force_mode)
-FN_LOCAL_INTEGER(lp_security_mask, iSecurity_mask)
-FN_LOCAL_INTEGER(lp_force_security_mode, iSecurity_force_mode)
-FN_LOCAL_INTEGER(lp_dir_mask, iDir_mask)
-FN_LOCAL_INTEGER(lp_force_dir_mode, iDir_force_mode)
-FN_LOCAL_INTEGER(lp_dir_security_mask, iDir_Security_mask)
-FN_LOCAL_INTEGER(lp_force_dir_security_mode, iDir_Security_force_mode)
-FN_LOCAL_INTEGER(lp_max_connections, iMaxConnections)
-FN_LOCAL_INTEGER(lp_defaultcase, iDefaultCase)
-FN_LOCAL_INTEGER(lp_minprintspace, iMinPrintSpace)
-FN_LOCAL_INTEGER(lp_printing, iPrinting)
-FN_LOCAL_INTEGER(lp_max_reported_jobs, iMaxReportedPrintJobs)
-FN_LOCAL_INTEGER(lp_oplock_contention_limit, iOplockContentionLimit)
-FN_LOCAL_INTEGER(lp_csc_policy, iCSCPolicy)
-FN_LOCAL_INTEGER(lp_write_cache_size, iWriteCacheSize)
-FN_LOCAL_INTEGER(lp_block_size, iBlock_size)
-FN_LOCAL_INTEGER(lp_dfree_cache_time, iDfreeCacheTime)
-FN_LOCAL_INTEGER(lp_allocation_roundup_size, iallocation_roundup_size)
-FN_LOCAL_INTEGER(lp_aio_read_size, iAioReadSize)
-FN_LOCAL_INTEGER(lp_aio_write_size, iAioWriteSize)
-FN_LOCAL_INTEGER(lp_map_readonly, iMap_readonly)
-FN_LOCAL_INTEGER(lp_directory_name_cache_size, iDirectoryNameCacheSize)
-FN_LOCAL_INTEGER(lp_smb_encrypt, ismb_encrypt)
-FN_LOCAL_CHAR(lp_magicchar, magic_char)
+FN_GLOBAL_BOOL(lp_allow_insecure_widelinks, bAllowInsecureWidelinks)
 FN_GLOBAL_INTEGER(lp_winbind_cache_time, winbind_cache_time)
 FN_GLOBAL_INTEGER(lp_winbind_reconnect_delay, winbind_reconnect_delay)
 FN_GLOBAL_INTEGER(lp_winbind_max_clients, winbind_max_clients)
@@ -5937,6 +5358,11 @@ FN_GLOBAL_INTEGER(lp_client_ldap_sasl_wrapping, client_ldap_sasl_wrapping)
 
 FN_GLOBAL_CONST_STRING(lp_ncalrpc_dir, ncalrpc_dir)
 
+#include "lib/param/param_functions.c"
+
+FN_LOCAL_STRING(servicename, szService)
+FN_LOCAL_CONST_STRING(const_servicename, szService)
+
 /* local prototypes */
 
 static int map_parameter_canonical(const char *pszParmName, bool *inverse);
@@ -5952,7 +5378,6 @@ static bool do_section(const char *pszSectionName, void *userdata);
 static void init_copymap(struct loadparm_service *pservice);
 static bool hash_a_service(const char *name, int number);
 static void free_service_byindex(int iService);
-static void free_param_opts(struct param_opt_struct **popts);
 static void show_parameter(int parmIndex);
 static bool is_synonym_of(int parm1, int parm2, bool *inverse);
 
@@ -5961,20 +5386,18 @@ static bool is_synonym_of(int parm1, int parm2, bool *inverse);
  * pointer to parametrical option value if it exists or NULL otherwise. Actual
  * parametrical functions are quite simple
  */
-static struct param_opt_struct *get_parametrics(int snum, const char *type,
-                                               const char *option)
+static struct parmlist_entry *get_parametrics_by_service(struct loadparm_service *service, const char *type,
+                                                          const char *option)
 {
-       bool global_section = False;
+       bool global_section = false;
        char* param_key;
-        struct param_opt_struct *data;
-
-       if (snum >= iNumServices) return NULL;
+        struct parmlist_entry *data;
 
-       if (snum < 0) { 
+       if (service == NULL) {
                data = Globals.param_opt;
-               global_section = True;
+               global_section = true;
        } else {
-               data = ServicePtrs[snum]->param_opt;
+               data = service->param_opt;
        }
 
        if (asprintf(&param_key, "%s:%s", type, option) == -1) {
@@ -6008,6 +5431,23 @@ static struct param_opt_struct *get_parametrics(int snum, const char *type,
        return NULL;
 }
 
+/*
+ * This is a helper function for parametrical options support.  It returns a
+ * pointer to parametrical option value if it exists or NULL otherwise. Actual
+ * parametrical functions are quite simple
+ */
+static struct parmlist_entry *get_parametrics(int snum, const char *type,
+                                               const char *option)
+{
+       if (snum >= iNumServices) return NULL;
+
+       if (snum < 0) {
+               return get_parametrics_by_service(NULL, type, option);
+       } else {
+               return get_parametrics_by_service(ServicePtrs[snum], type, option);
+       }
+}
+
 
 #define MISSING_PARAMETER(name) \
     DEBUG(0, ("%s(): value is NULL or empty!\n", #name))
@@ -6045,16 +5485,16 @@ convenience routine to return boolean parameters.
 ********************************************************************/
 static bool lp_bool(const char *s)
 {
-       bool ret = False;
+       bool ret = false;
 
        if (!s || !*s) {
                MISSING_PARAMETER(lp_bool);
-               return False;
+               return false;
        }
 
        if (!set_boolean(s, &ret)) {
                DEBUG(0,("lp_bool(%s): value is not boolean!\n",s));
-               return False;
+               return false;
        }
 
        return ret;
@@ -6088,7 +5528,7 @@ static int lp_enum(const char *s,const struct enum_list *_enum)
 /* the returned value is talloced on the talloc_tos() */
 char *lp_parm_talloc_string(int snum, const char *type, const char *option, const char *def)
 {
-       struct param_opt_struct *data = get_parametrics(snum, type, option);
+       struct parmlist_entry *data = get_parametrics(snum, type, option);
 
        if (data == NULL||data->value==NULL) {
                if (def) {
@@ -6105,7 +5545,7 @@ char *lp_parm_talloc_string(int snum, const char *type, const char *option, cons
 /* Parametric option has following syntax: 'Type: option = value' */
 const char *lp_parm_const_string(int snum, const char *type, const char *option, const char *def)
 {
-       struct param_opt_struct *data = get_parametrics(snum, type, option);
+       struct parmlist_entry *data = get_parametrics(snum, type, option);
 
        if (data == NULL||data->value==NULL)
                return def;
@@ -6113,12 +5553,23 @@ const char *lp_parm_const_string(int snum, const char *type, const char *option,
        return data->value;
 }
 
+const char *lp_parm_const_string_service(struct loadparm_service *service, const char *type, const char *option)
+{
+       struct parmlist_entry *data = get_parametrics_by_service(service, type, option);
+
+       if (data == NULL||data->value==NULL)
+               return NULL;
+
+       return data->value;
+}
+
+
 /* Return parametric option from a given service. Type is a part of option before ':' */
 /* Parametric option has following syntax: 'Type: option = value' */
 
 const char **lp_parm_string_list(int snum, const char *type, const char *option, const char **def)
 {
-       struct param_opt_struct *data = get_parametrics(snum, type, option);
+       struct parmlist_entry *data = get_parametrics(snum, type, option);
 
        if (data == NULL||data->value==NULL)
                return (const char **)def;
@@ -6135,7 +5586,7 @@ const char **lp_parm_string_list(int snum, const char *type, const char *option,
 
 int lp_parm_int(int snum, const char *type, const char *option, int def)
 {
-       struct param_opt_struct *data = get_parametrics(snum, type, option);
+       struct parmlist_entry *data = get_parametrics(snum, type, option);
 
        if (data && data->value && *data->value)
                return lp_int(data->value);
@@ -6148,7 +5599,7 @@ int lp_parm_int(int snum, const char *type, const char *option, int def)
 
 unsigned long lp_parm_ulong(int snum, const char *type, const char *option, unsigned long def)
 {
-       struct param_opt_struct *data = get_parametrics(snum, type, option);
+       struct parmlist_entry *data = get_parametrics(snum, type, option);
 
        if (data && data->value && *data->value)
                return lp_ulong(data->value);
@@ -6161,7 +5612,7 @@ unsigned long lp_parm_ulong(int snum, const char *type, const char *option, unsi
 
 bool lp_parm_bool(int snum, const char *type, const char *option, bool def)
 {
-       struct param_opt_struct *data = get_parametrics(snum, type, option);
+       struct parmlist_entry *data = get_parametrics(snum, type, option);
 
        if (data && data->value && *data->value)
                return lp_bool(data->value);
@@ -6175,7 +5626,7 @@ bool lp_parm_bool(int snum, const char *type, const char *option, bool def)
 int lp_parm_enum(int snum, const char *type, const char *option,
                 const struct enum_list *_enum, int def)
 {
-       struct param_opt_struct *data = get_parametrics(snum, type, option);
+       struct parmlist_entry *data = get_parametrics(snum, type, option);
 
        if (data && data->value && *data->value && _enum)
                return lp_enum(data->value, _enum);
@@ -6201,9 +5652,9 @@ static void init_service(struct loadparm_service *pservice)
  * then this whole functions reduces to a TALLOC_FREE().
  */
 
-static void free_param_opts(struct param_opt_struct **popts)
+static void free_param_opts(struct parmlist_entry **popts)
 {
-       struct param_opt_struct *opt, *next_opt;
+       struct parmlist_entry *opt, *next_opt;
 
        if (popts == NULL) {
                return;
@@ -6258,7 +5709,7 @@ static void free_service_byindex(int idx)
        if ( !LP_SNUM_OK(idx) ) 
                return;
 
-       ServicePtrs[idx]->valid = False;
+       ServicePtrs[idx]->valid = false;
        invalid_services[num_invalid_services++] = idx;
 
        /* we have to cleanup the hash record */
@@ -6333,7 +5784,7 @@ static int add_a_service(const struct loadparm_service *pservice, const char *na
                free_service_byindex(i);
        }
 
-       ServicePtrs[i]->valid = True;
+       ServicePtrs[i]->valid = true;
 
        init_service(ServicePtrs[i]);
        copy_service(ServicePtrs[i], &tservice, NULL);
@@ -6383,7 +5834,7 @@ static bool hash_a_service(const char *name, int idx)
                ServiceHash = db_open_rbt(NULL);
                if ( !ServiceHash ) {
                        DEBUG(0,("hash_a_service: open tdb servicehash failed!\n"));
-                       return False;
+                       return false;
                }
        }
 
@@ -6398,7 +5849,7 @@ static bool hash_a_service(const char *name, int idx)
 
        TALLOC_FREE(canon_name);
 
-       return True;
+       return true;
 }
 
 /***************************************************************************
@@ -6419,7 +5870,7 @@ bool lp_add_home(const char *pszHomename, int iDefaultService,
        i = add_a_service(ServicePtrs[iDefaultService], pszHomename);
 
        if (i < 0)
-               return (False);
+               return false;
 
        if (!(*(ServicePtrs[iDefaultService]->szPath))
            || strequal(ServicePtrs[iDefaultService]->szPath, lp_pathname(GLOBAL_SECTION_SNUM))) {
@@ -6440,12 +5891,12 @@ bool lp_add_home(const char *pszHomename, int iDefaultService,
        ServicePtrs[i]->bBrowseable = sDefault.bBrowseable;
        ServicePtrs[i]->bAccessBasedShareEnum = sDefault.bAccessBasedShareEnum;
 
-       ServicePtrs[i]->autoloaded = True;
+       ServicePtrs[i]->autoloaded = true;
 
        DEBUG(3, ("adding home's share [%s] for user '%s' at '%s'\n", pszHomename, 
               user, ServicePtrs[i]->szPath ));
 
-       return (True);
+       return true;
 }
 
 /***************************************************************************
@@ -6471,11 +5922,11 @@ static bool lp_add_ipc(const char *ipc_name, bool guest_ok)
        int i = add_a_service(&sDefault, ipc_name);
 
        if (i < 0)
-               return (False);
+               return false;
 
        if (asprintf(&comment, "IPC Service (%s)",
                                Globals.szServerString) < 0) {
-               return (False);
+               return false;
        }
 
        string_set(&ServicePtrs[i]->szPath, tmpdir());
@@ -6483,18 +5934,18 @@ static bool lp_add_ipc(const char *ipc_name, bool guest_ok)
        string_set(&ServicePtrs[i]->comment, comment);
        string_set(&ServicePtrs[i]->fstype, "IPC");
        ServicePtrs[i]->iMaxConnections = 0;
-       ServicePtrs[i]->bAvailable = True;
-       ServicePtrs[i]->bRead_only = True;
-       ServicePtrs[i]->bGuest_only = False;
-       ServicePtrs[i]->bAdministrative_share = True;
+       ServicePtrs[i]->bAvailable = true;
+       ServicePtrs[i]->bRead_only = true;
+       ServicePtrs[i]->bGuest_only = false;
+       ServicePtrs[i]->bAdministrative_share = true;
        ServicePtrs[i]->bGuest_ok = guest_ok;
-       ServicePtrs[i]->bPrint_ok = False;
+       ServicePtrs[i]->bPrint_ok = false;
        ServicePtrs[i]->bBrowseable = sDefault.bBrowseable;
 
        DEBUG(3, ("adding IPC service\n"));
 
        SAFE_FREE(comment);
-       return (True);
+       return true;
 }
 
 /***************************************************************************
@@ -6507,9 +5958,9 @@ bool lp_add_printer(const char *pszPrintername, int iDefaultService)
        int i = add_a_service(ServicePtrs[iDefaultService], pszPrintername);
 
        if (i < 0)
-               return (False);
+               return false;
 
-       /* note that we do NOT default the availability flag to True - */
+       /* note that we do NOT default the availability flag to true - */
        /* we take it from the default service passed. This allows all */
        /* dynamic printers to be disabled by disabling the [printers] */
        /* entry (if/when the 'available' keyword is implemented!).    */
@@ -6522,17 +5973,17 @@ bool lp_add_printer(const char *pszPrintername, int iDefaultService)
        ServicePtrs[i]->bBrowseable = sDefault.bBrowseable;
 
        /* Printers cannot be read_only. */
-       ServicePtrs[i]->bRead_only = False;
+       ServicePtrs[i]->bRead_only = false;
        /* No share modes on printer services. */
-       ServicePtrs[i]->bShareModes = False;
+       ServicePtrs[i]->bShareModes = false;
        /* No oplocks on printer services. */
-       ServicePtrs[i]->bOpLocks = False;
+       ServicePtrs[i]->bOpLocks = false;
        /* Printer services must be printable. */
-       ServicePtrs[i]->bPrint_ok = True;
+       ServicePtrs[i]->bPrint_ok = true;
 
        DEBUG(3, ("adding printer service %s\n", pszPrintername));
 
-       return (True);
+       return true;
 }
 
 
@@ -6549,8 +6000,8 @@ bool lp_parameter_is_valid(const char *pszParmName)
 
 /***************************************************************************
  Check whether the given name is the name of a global parameter.
- Returns True for strings belonging to parameters of class
- P_GLOBAL, False for all other strings, also for parametric options
+ Returns true for strings belonging to parameters of class
+ P_GLOBAL, false for all other strings, also for parametric options
  and strings not belonging to any option.
 ***************************************************************************/
 
@@ -6562,19 +6013,19 @@ bool lp_parameter_is_global(const char *pszParmName)
                return (parm_table[num].p_class == P_GLOBAL);
        }
 
-       return False;
+       return false;
 }
 
 /**************************************************************************
  Check whether the given name is the canonical name of a parameter.
- Returns False if it is not a valid parameter Name.
- For parametric options, True is returned.
+ Returns false if it is not a valid parameter Name.
+ For parametric options, true is returned.
 **************************************************************************/
 
 bool lp_parameter_is_canonical(const char *parm_name)
 {
        if (!lp_parameter_is_valid(parm_name)) {
-               return False;
+               return false;
        }
 
        return (map_parameter(parm_name) ==
@@ -6594,7 +6045,7 @@ bool lp_canonicalize_parameter(const char *parm_name, const char **canon_parm,
 
        if (!lp_parameter_is_valid(parm_name)) {
                *canon_parm = NULL;
-               return False;
+               return false;
        }
 
        num = map_parameter_canonical(parm_name, inverse);
@@ -6605,7 +6056,7 @@ bool lp_canonicalize_parameter(const char *parm_name, const char **canon_parm,
                *canon_parm = parm_table[num].label;
        }
 
-       return True;
+       return true;
 
 }
 
@@ -6614,7 +6065,7 @@ bool lp_canonicalize_parameter(const char *parm_name, const char **canon_parm,
  Turn the value given into the inverse boolean expression when
  the synonym is an invers boolean synonym.
 
- Return True if parm_name is a valid parameter name and
+ Return true if parm_name is a valid parameter name and
  in case it is an invers boolean synonym, if the val string could
  successfully be converted to the reverse bool.
  Return false in all other cases.
@@ -6631,7 +6082,7 @@ bool lp_canonicalize_parameter_with_value(const char *parm_name,
        if (!lp_parameter_is_valid(parm_name)) {
                *canon_parm = NULL;
                *canon_val = NULL;
-               return False;
+               return false;
        }
 
        num = map_parameter_canonical(parm_name, &inverse);
@@ -6644,19 +6095,19 @@ bool lp_canonicalize_parameter_with_value(const char *parm_name,
                if (inverse) {
                        if (!lp_invert_boolean(val, canon_val)) {
                                *canon_val = NULL;
-                               return False;
+                               return false;
                        }
                } else {
                        *canon_val = val;
                }
        }
 
-       return True;
+       return true;
 }
 
 /***************************************************************************
  Map a parameter's string representation to something we can use. 
- Returns False if the parameter string is not recognised, else TRUE.
+ Returns false if the parameter string is not recognised, else TRUE.
 ***************************************************************************/
 
 static int map_parameter(const char *pszParmName)
@@ -6688,7 +6139,7 @@ static int map_parameter(const char *pszParmName)
 static int map_parameter_canonical(const char *pszParmName, bool *inverse)
 {
        int parm_num, canon_num;
-       bool loc_inverse = False;
+       bool loc_inverse = false;
 
        parm_num = map_parameter(pszParmName);
        if ((parm_num < 0) || !(parm_table[parm_num].flags & FLAG_HIDE)) {
@@ -6713,13 +6164,14 @@ done:
 /***************************************************************************
  return true if parameter number parm1 is a synonym of parameter
  number parm2 (parm2 being the principal name).
- set inverse to True if parm1 is P_BOOLREV and parm2 is P_BOOL,
False otherwise.
+ set inverse to true if parm1 is P_BOOLREV and parm2 is P_BOOL,
false otherwise.
 ***************************************************************************/
 
 static bool is_synonym_of(int parm1, int parm2, bool *inverse)
 {
        if ((parm_table[parm1].offset == parm_table[parm2].offset) &&
+           (parm_table[parm1].p_class == parm_table[parm2].p_class) &&
            (parm_table[parm1].flags & FLAG_HIDE) &&
            !(parm_table[parm2].flags & FLAG_HIDE))
        {
@@ -6727,14 +6179,14 @@ static bool is_synonym_of(int parm1, int parm2, bool *inverse)
                        if ((parm_table[parm1].type == P_BOOLREV) &&
                            (parm_table[parm2].type == P_BOOL))
                        {
-                               *inverse = True;
+                               *inverse = true;
                        } else {
-                               *inverse = False;
+                               *inverse = false;
                        }
                }
-               return True;
+               return true;
        }
-       return False;
+       return false;
 }
 
 /***************************************************************************
@@ -6754,10 +6206,10 @@ static void show_parameter(int parmIndex)
                "P_ENUM", "P_SEP"};
        unsigned flags[] = { FLAG_BASIC, FLAG_SHARE, FLAG_PRINT, FLAG_GLOBAL,
                FLAG_WIZARD, FLAG_ADVANCED, FLAG_DEVELOPER, FLAG_DEPRECATED,
-               FLAG_HIDE, FLAG_DOS_STRING};
+               FLAG_HIDE};
        const char *flag_names[] = { "FLAG_BASIC", "FLAG_SHARE", "FLAG_PRINT",
                "FLAG_GLOBAL", "FLAG_WIZARD", "FLAG_ADVANCED", "FLAG_DEVELOPER",
-               "FLAG_DEPRECATED", "FLAG_HIDE", "FLAG_DOS_STRING", NULL};
+               "FLAG_DEPRECATED", "FLAG_HIDE", NULL};
 
        printf("%s=%s", parm_table[parmIndex].label,
               type[parm_table[parmIndex].type]);
@@ -6773,18 +6225,18 @@ static void show_parameter(int parmIndex)
                }
        }
        printf(",");
-       hadFlag = False;
+       hadFlag = false;
        for (flagIndex=0; flag_names[flagIndex]; flagIndex++) {
                if (parm_table[parmIndex].flags & flags[flagIndex]) {
                        printf("%s%s",
                                hadFlag ? "|" : "",
                                flag_names[flagIndex]);
-                       hadFlag = True;
+                       hadFlag = true;
                }
        }
 
        /* output synonyms */
-       hadSyn = False;
+       hadSyn = false;
        for (parmIndex2=0; parm_table[parmIndex2].label; parmIndex2++) {
                if (is_synonym_of(parmIndex, parmIndex2, &inverse)) {
                        printf(" (%ssynonym of %s)", inverse ? "inverse " : "",
@@ -6792,7 +6244,7 @@ static void show_parameter(int parmIndex)
                } else if (is_synonym_of(parmIndex2, parmIndex, &inverse)) {
                        if (!hadSyn) {
                                printf(" (synonyms: ");
-                               hadSyn = True;
+                               hadSyn = true;
                        } else {
                                printf(", ");
                        }
@@ -6849,7 +6301,7 @@ static const char *get_boolean(bool bool_value)
 
 /***************************************************************************
  Provide the string of the negated boolean value associated to the boolean
- given as a string. Returns False if the passed string does not correctly
+ given as a string. Returns false if the passed string does not correctly
  represent a boolean.
 ***************************************************************************/
 
@@ -6858,16 +6310,16 @@ bool lp_invert_boolean(const char *str, const char **inverse_str)
        bool val;
 
        if (!set_boolean(str, &val)) {
-               return False;
+               return false;
        }
 
        *inverse_str = get_boolean(!val);
-       return True;
+       return true;
 }
 
 /***************************************************************************
  Provide the canonical string representation of a boolean value given
- as a string. Return True on success, False if the string given does
+ as a string. Return true on success, false if the string given does
  not correctly represent a boolean.
 ***************************************************************************/
 
@@ -6876,11 +6328,11 @@ bool lp_canonicalize_boolean(const char *str, const char**canon_str)
        bool val;
 
        if (!set_boolean(str, &val)) {
-               return False;
+               return false;
        }
 
        *canon_str = get_boolean(val);
-       return True;
+       return true;
 }
 
 /***************************************************************************
@@ -6892,6 +6344,7 @@ static int getservicebyname(const char *pszServiceName, struct loadparm_service
        int iService = -1;
        char *canon_name;
        TDB_DATA data;
+       NTSTATUS status;
 
        if (ServiceHash == NULL) {
                return -1;
@@ -6899,9 +6352,13 @@ static int getservicebyname(const char *pszServiceName, struct loadparm_service
 
        canon_name = canonicalize_servicename(talloc_tos(), pszServiceName);
 
-       data = dbwrap_fetch_bystring(ServiceHash, canon_name, canon_name);
+       status = dbwrap_fetch_bystring(ServiceHash, canon_name, canon_name,
+                                      &data);
 
-       if ((data.dptr != NULL) && (data.dsize == sizeof(iService))) {
+       if (NT_STATUS_IS_OK(status) &&
+           (data.dptr != NULL) &&
+           (data.dsize == sizeof(iService)))
+       {
                iService = *(int *)data.dptr;
        }
 
@@ -6915,21 +6372,45 @@ static int getservicebyname(const char *pszServiceName, struct loadparm_service
        return (iService);
 }
 
+/* Return a pointer to a service by name.  Unlike getservicebyname, it does not copy the service */
+struct loadparm_service *lp_service(const char *pszServiceName)
+{
+       int iService = getservicebyname(pszServiceName, NULL);
+       if (iService == -1 || !LP_SNUM_OK(iService)) {
+               return NULL;
+       }
+       return ServicePtrs[iService];
+}
+
+struct loadparm_service *lp_servicebynum(int snum)
+{
+       if ((snum == -1) || !LP_SNUM_OK(snum)) {
+               return NULL;
+       }
+       return ServicePtrs[snum];
+}
+
+struct loadparm_service *lp_default_loadparm_service()
+{
+       return &sDefault;
+}
+
+
 /***************************************************************************
  Copy a service structure to another.
  If pcopymapDest is NULL then copy all fields
 ***************************************************************************/
 
 /**
- * Add a parametric option to a param_opt_struct,
+ * Add a parametric option to a parmlist_entry,
  * replacing old value, if already present.
  */
-static void set_param_opt(struct param_opt_struct **opt_list,
+static void set_param_opt(struct parmlist_entry **opt_list,
                          const char *opt_name,
                          const char *opt_value,
-                         unsigned flags)
+                         unsigned priority)
 {
-       struct param_opt_struct *new_opt, *opt;
+       struct parmlist_entry *new_opt, *opt;
        bool not_added;
 
        if (opt_list == NULL) {
@@ -6943,8 +6424,8 @@ static void set_param_opt(struct param_opt_struct **opt_list,
        while (opt) {
                /* If we already have same option, override it */
                if (strwicmp(opt->key, opt_name) == 0) {
-                       if ((opt->flags & FLAG_CMDLINE) &&
-                           !(flags & FLAG_CMDLINE)) {
+                       if ((opt->priority & FLAG_CMDLINE) &&
+                           !(priority & FLAG_CMDLINE)) {
                                /* it's been marked as not to be
                                   overridden */
                                return;
@@ -6952,18 +6433,18 @@ static void set_param_opt(struct param_opt_struct **opt_list,
                        string_free(&opt->value);
                        TALLOC_FREE(opt->list);
                        opt->value = SMB_STRDUP(opt_value);
-                       opt->flags = flags;
+                       opt->priority = priority;
                        not_added = false;
                        break;
                }
                opt = opt->next;
        }
        if (not_added) {
-           new_opt = SMB_XMALLOC_P(struct param_opt_struct);
+           new_opt = SMB_XMALLOC_P(struct parmlist_entry);
            new_opt->key = SMB_STRDUP(opt_name);
            new_opt->value = SMB_STRDUP(opt_value);
            new_opt->list = NULL;
-           new_opt->flags = flags;
+           new_opt->priority = priority;
            DLIST_ADD(*opt_list, new_opt);
        }
 }
@@ -6973,7 +6454,7 @@ static void copy_service(struct loadparm_service *pserviceDest, struct loadparm_
 {
        int i;
        bool bcopyall = (pcopymapDest == NULL);
-       struct param_opt_struct *data;
+       struct parmlist_entry *data;
 
        for (i = 0; parm_table[i].label; i++)
                if (parm_table[i].p_class == P_LOCAL &&
@@ -6990,6 +6471,7 @@ static void copy_service(struct loadparm_service *pserviceDest, struct loadparm_
                                case P_INTEGER:
                                case P_ENUM:
                                case P_OCTAL:
+                               case P_BYTES:
                                        *(int *)dest_ptr = *(int *)src_ptr;
                                        break;
 
@@ -7030,25 +6512,25 @@ static void copy_service(struct loadparm_service *pserviceDest, struct loadparm_
 
        data = pserviceSource->param_opt;
        while (data) {
-               set_param_opt(&pserviceDest->param_opt, data->key, data->value, data->flags);
+               set_param_opt(&pserviceDest->param_opt, data->key, data->value, data->priority);
                data = data->next;
        }
 }
 
 /***************************************************************************
-Check a service for consistency. Return False if the service is in any way
-incomplete or faulty, else True.
+Check a service for consistency. Return false if the service is in any way
+incomplete or faulty, else true.
 ***************************************************************************/
 
 bool service_ok(int iService)
 {
        bool bRetval;
 
-       bRetval = True;
+       bRetval = true;
        if (ServicePtrs[iService]->szService[0] == '\0') {
                DEBUG(0, ("The following message indicates an internal error:\n"));
                DEBUG(0, ("No service name in service entry.\n"));
-               bRetval = False;
+               bRetval = false;
        }
 
        /* The [printers] entry MUST be printable. I'm all for flexibility, but */
@@ -7057,11 +6539,11 @@ bool service_ok(int iService)
                if (!ServicePtrs[iService]->bPrint_ok) {
                        DEBUG(0, ("WARNING: [%s] service MUST be printable!\n",
                               ServicePtrs[iService]->szService));
-                       ServicePtrs[iService]->bPrint_ok = True;
+                       ServicePtrs[iService]->bPrint_ok = true;
                }
                /* [printers] service must also be non-browsable. */
                if (ServicePtrs[iService]->bBrowseable)
-                       ServicePtrs[iService]->bBrowseable = False;
+                       ServicePtrs[iService]->bBrowseable = false;
        }
 
        if (ServicePtrs[iService]->szPath[0] == '\0' &&
@@ -7070,7 +6552,7 @@ bool service_ok(int iService)
            ) {
                DEBUG(0, ("WARNING: No path in service %s - making it unavailable!\n",
                        ServicePtrs[iService]->szService));
-               ServicePtrs[iService]->bAvailable = False;
+               ServicePtrs[iService]->bAvailable = false;
        }
 
        /* If a service is flagged unavailable, log the fact at level 1. */
@@ -7225,6 +6707,35 @@ done:
        return ret;
 }
 
+/**
+ * reload those shares from registry that are already
+ * activated in the services array.
+ */
+static bool reload_registry_shares(void)
+{
+       int i;
+       bool ret = true;
+
+       for (i = 0; i < iNumServices; i++) {
+               if (!VALID(i)) {
+                       continue;
+               }
+
+               if (ServicePtrs[i]->usershare == USERSHARE_VALID) {
+                       continue;
+               }
+
+               ret = process_registry_service(ServicePtrs[i]->szService);
+               if (!ret) {
+                       goto done;
+               }
+       }
+
+done:
+       return ret;
+}
+
+
 #define MAX_INCLUDE_DEPTH 100
 
 static uint8_t include_depth;
@@ -7370,7 +6881,7 @@ bool lp_file_list_changed(void)
                }
                f = f->next;
        }
-       return (False);
+       return false;
 }
 
 
@@ -7394,7 +6905,7 @@ static bool handle_charset(struct loadparm_context *unused, int snum, const char
                string_set(ptr, pszParmValue);
                init_iconv();
        }
-       return True;
+       return true;
 }
 
 static bool handle_dos_charset(struct loadparm_context *unused, int snum, const char *pszParmValue, char **ptr)
@@ -7405,9 +6916,9 @@ static bool handle_dos_charset(struct loadparm_context *unused, int snum, const
        if (len == 4 || len == 5) {
                /* Don't use StrCaseCmp here as we don't want to
                   initialize iconv. */
-               if ((toupper_ascii(pszParmValue[0]) == 'U') &&
-                   (toupper_ascii(pszParmValue[1]) == 'T') &&
-                   (toupper_ascii(pszParmValue[2]) == 'F')) {
+               if ((toupper_m(pszParmValue[0]) == 'U') &&
+                   (toupper_m(pszParmValue[1]) == 'T') &&
+                   (toupper_m(pszParmValue[2]) == 'F')) {
                        if (len == 4) {
                                if (pszParmValue[3] == '8') {
                                        is_utf8 = true;
@@ -7452,8 +6963,8 @@ static bool handle_realm(struct loadparm_context *unused, int snum, const char *
 static bool handle_netbios_aliases(struct loadparm_context *unused, int snum, const char *pszParmValue, char **ptr)
 {
        TALLOC_FREE(Globals.szNetbiosAliases);
-       Globals.szNetbiosAliases = str_list_make_v3(NULL, pszParmValue, NULL);
-       return set_netbios_aliases((const char **)Globals.szNetbiosAliases);
+       Globals.szNetbiosAliases = (const char **)str_list_make_v3(NULL, pszParmValue, NULL);
+       return set_netbios_aliases(Globals.szNetbiosAliases);
 }
 
 /***************************************************************************
@@ -7524,7 +7035,7 @@ static bool handle_copy(struct loadparm_context *unused, int snum, const char *p
 
        init_service(&serviceTemp);
 
-       bRetval = False;
+       bRetval = false;
 
        DEBUG(3, ("Copying service from service %s\n", pszParmValue));
 
@@ -7535,11 +7046,11 @@ static bool handle_copy(struct loadparm_context *unused, int snum, const char *p
                        copy_service(ServicePtrs[iServiceIndex],
                                     &serviceTemp,
                                     ServicePtrs[iServiceIndex]->copymap);
-                       bRetval = True;
+                       bRetval = true;
                }
        } else {
                DEBUG(0, ("Unable to copy service - source not found: %s\n", pszParmValue));
-               bRetval = False;
+               bRetval = false;
        }
 
        free_service(&serviceTemp);
@@ -7575,7 +7086,7 @@ static gid_t idmap_gid_low, idmap_gid_high;
 bool lp_idmap_uid(uid_t *low, uid_t *high)
 {
         if (idmap_uid_low == 0 || idmap_uid_high == 0)
-                return False;
+                return false;
 
         if (low)
                 *low = idmap_uid_low;
@@ -7583,13 +7094,13 @@ bool lp_idmap_uid(uid_t *low, uid_t *high)
         if (high)
                 *high = idmap_uid_high;
 
-        return True;
+        return true;
 }
 
 bool lp_idmap_gid(gid_t *low, gid_t *high)
 {
         if (idmap_gid_low == 0 || idmap_gid_high == 0)
-                return False;
+                return false;
 
         if (low)
                 *low = idmap_gid_low;
@@ -7597,7 +7108,7 @@ bool lp_idmap_gid(gid_t *low, gid_t *high)
         if (high)
                 *high = idmap_gid_high;
 
-        return True;
+        return true;
 }
 
 static bool handle_idmap_backend(struct loadparm_context *unused, int snum, const char *pszParmValue, char **ptr)
@@ -7613,14 +7124,14 @@ static bool handle_idmap_uid(struct loadparm_context *unused, int snum, const ch
 {
        lp_do_parameter(snum, "idmap config * : range", pszParmValue);
 
-       return True;
+       return true;
 }
 
 static bool handle_idmap_gid(struct loadparm_context *unused, int snum, const char *pszParmValue, char **ptr)
 {
        lp_do_parameter(snum, "idmap config * : range", pszParmValue);
 
-       return True;
+       return true;
 }
 
 /***************************************************************************
@@ -7723,7 +7234,7 @@ static bool handle_printing(struct loadparm_context *unused, int snum, const cha
 
        init_printer_values( s );
 
-       return True;
+       return true;
 }
 
 
@@ -7781,7 +7292,7 @@ bool lp_do_parameter(int snum, const char *pszParmName, const char *pszParmValue
 {
        int parmnum, i;
        void *parm_ptr = NULL;  /* where we are going to store the result */
-       struct param_opt_struct **opt_list;
+       struct parmlist_entry **opt_list;
 
        parmnum = map_parameter(pszParmName);
 
@@ -7789,7 +7300,7 @@ bool lp_do_parameter(int snum, const char *pszParmName, const char *pszParmValue
                if (strchr(pszParmName, ':') == NULL) {
                        DEBUG(0, ("Ignoring unknown parameter \"%s\"\n",
                                  pszParmName));
-                       return (True);
+                       return true;
                }
 
                /*
@@ -7800,7 +7311,7 @@ bool lp_do_parameter(int snum, const char *pszParmName, const char *pszParmValue
                        ? &Globals.param_opt : &ServicePtrs[snum]->param_opt;
                set_param_opt(opt_list, pszParmName, pszParmValue, 0);
 
-               return (True);
+               return true;
        }
 
        /* if it's already been set by the command line, then we don't
@@ -7822,7 +7333,7 @@ bool lp_do_parameter(int snum, const char *pszParmName, const char *pszParmValue
                        DEBUG(0,
                              ("Global parameter %s found in service section!\n",
                               pszParmName));
-                       return (True);
+                       return true;
                }
                parm_ptr = lp_local_ptr_by_snum(snum, &parm_table[parmnum]);
        }
@@ -7833,9 +7344,12 @@ bool lp_do_parameter(int snum, const char *pszParmName, const char *pszParmValue
 
                /* this handles the aliases - set the copymap for other entries with
                   the same data pointer */
-               for (i = 0; parm_table[i].label; i++)
-                       if (parm_table[i].offset == parm_table[parmnum].offset)
+               for (i = 0; parm_table[i].label; i++) {
+                       if ((parm_table[i].offset == parm_table[parmnum].offset)
+                           && (parm_table[i].p_class == parm_table[parmnum].p_class)) {
                                bitmap_clear(ServicePtrs[snum]->copymap, i);
+                       }
+               }
        }
 
        /* if it is a special case then go ahead */
@@ -7870,7 +7384,23 @@ bool lp_do_parameter(int snum, const char *pszParmName, const char *pszParmValue
                        }
                        break;
 
+               case P_BYTES:
+               {
+                       uint64_t val;
+                       if (conv_str_size_error(pszParmValue, &val)) {
+                               if (val <= INT_MAX) {
+                                       *(int *)parm_ptr = (int)val;
+                                       break;
+                               }
+                       }
+
+                       DEBUG(0,("lp_do_parameter(%s): value is not "
+                           "a valid size specifier!\n", pszParmValue));
+                       return false;
+               }
+
                case P_LIST:
+               case P_CMDLIST:
                        TALLOC_FREE(*((char ***)parm_ptr));
                        *(char ***)parm_ptr = str_list_make_v3(
                                NULL, pszParmValue, NULL);
@@ -7895,7 +7425,7 @@ bool lp_do_parameter(int snum, const char *pszParmName, const char *pszParmValue
                        break;
        }
 
-       return (True);
+       return true;
 }
 
 /***************************************************************************
@@ -7917,10 +7447,14 @@ static bool lp_set_cmdline_helper(const char *pszParmName, const char *pszParmVa
                /* we have to also set FLAG_CMDLINE on aliases.  Aliases must
                 * be grouped in the table, so we don't have to search the
                 * whole table */
-               for (i=parmnum-1;i>=0 && parm_table[i].offset == parm_table[parmnum].offset;i--) {
+               for (i=parmnum-1;
+                    i>=0 && parm_table[i].offset == parm_table[parmnum].offset
+                            && parm_table[i].p_class == parm_table[parmnum].p_class;
+                    i--) {
                        parm_table[i].flags |= FLAG_CMDLINE;
                }
-               for (i=parmnum+1;i<NUMPARAMETERS && parm_table[i].offset == parm_table[parmnum].offset;i++) {
+               for (i=parmnum+1;i<NUMPARAMETERS && parm_table[i].offset == parm_table[parmnum].offset
+                            && parm_table[i].p_class == parm_table[parmnum].p_class;i++) {
                        parm_table[i].flags |= FLAG_CMDLINE;
                }
 
@@ -7956,7 +7490,7 @@ static bool do_parameter(const char *pszParmName, const char *pszParmValue,
                         void *userdata)
 {
        if (!bInGlobalSection && bGlobalOnly)
-               return (True);
+               return true;
 
        DEBUGADD(4, ("doing parameter %s = %s\n", pszParmName, pszParmValue));
 
@@ -8001,6 +7535,8 @@ bool lp_set_option(const char *option)
 
 static void print_parameter(struct parm_struct *p, void *ptr, FILE * f)
 {
+       /* For the seperation of lists values that we print below */
+       const char *list_sep = ", ";
        int i;
        switch (p->type)
        {
@@ -8023,6 +7559,7 @@ static void print_parameter(struct parm_struct *p, void *ptr, FILE * f)
                        break;
 
                case P_INTEGER:
+               case P_BYTES:
                        fprintf(f, "%d", *(int *)ptr);
                        break;
 
@@ -8031,21 +7568,32 @@ static void print_parameter(struct parm_struct *p, void *ptr, FILE * f)
                        break;
 
                case P_OCTAL: {
-                       char *o = octal_string(*(int *)ptr);
-                       fprintf(f, "%s", o);
-                       TALLOC_FREE(o);
+                       int val = *(int *)ptr; 
+                       if (val == -1) {
+                               fprintf(f, "-1");
+                       } else {
+                               fprintf(f, "0%o", val);
+                       }
                        break;
                }
 
+               case P_CMDLIST:
+                       list_sep = " ";
+                       /* fall through */
                case P_LIST:
                        if ((char ***)ptr && *(char ***)ptr) {
                                char **list = *(char ***)ptr;
                                for (; *list; list++) {
                                        /* surround strings with whitespace in double quotes */
-                                       if ( strchr_m( *list, ' ' ) )
-                                               fprintf(f, "\"%s\"%s", *list, ((*(list+1))?", ":""));
-                                       else
-                                               fprintf(f, "%s%s", *list, ((*(list+1))?", ":""));
+                                       if (*(list+1) == NULL) {
+                                               /* last item, no extra separator */
+                                               list_sep = "";
+                                       }
+                                       if ( strchr_m( *list, ' ' ) ) {
+                                               fprintf(f, "\"%s\"%s", *list, list_sep);
+                                       } else {
+                                               fprintf(f, "%s%s", *list, list_sep);
+                                       }
                                }
                        }
                        break;
@@ -8075,12 +7623,14 @@ static bool equal_parameter(parm_type type, void *ptr1, void *ptr2)
                case P_INTEGER:
                case P_ENUM:
                case P_OCTAL:
+               case P_BYTES:
                        return (*((int *)ptr1) == *((int *)ptr2));
 
                case P_CHAR:
                        return (*((char *)ptr1) == *((char *)ptr2));
 
                case P_LIST:
+               case P_CMDLIST:
                        return str_list_equal(*(const char ***)ptr1, *(const char ***)ptr2);
 
                case P_STRING:
@@ -8096,7 +7646,7 @@ static bool equal_parameter(parm_type type, void *ptr1, void *ptr2)
                case P_SEP:
                        break;
        }
-       return (False);
+       return false;
 }
 
 /***************************************************************************
@@ -8111,7 +7661,7 @@ void init_locals(void)
 /***************************************************************************
  Process a new section (service). At this stage all sections are services.
  Later we'll have special sections that permit server parameters to be set.
- Returns True on success, False on failure. 
+ Returns true on success, false on failure.
 ***************************************************************************/
 
 static bool do_section(const char *pszSectionName, void *userdata)
@@ -8119,7 +7669,7 @@ static bool do_section(const char *pszSectionName, void *userdata)
        bool bRetval;
        bool isglobal = ((strwicmp(pszSectionName, GLOBAL_NAME) == 0) ||
                         (strwicmp(pszSectionName, GLOBAL_NAME2) == 0));
-       bRetval = False;
+       bRetval = false;
 
        /* if we were in a global section then do the local inits */
        if (bInGlobalSection && !isglobal)
@@ -8131,14 +7681,14 @@ static bool do_section(const char *pszSectionName, void *userdata)
        /* check for multiple global sections */
        if (bInGlobalSection) {
                DEBUG(3, ("Processing section \"[%s]\"\n", pszSectionName));
-               return (True);
+               return true;
        }
 
        if (!bInGlobalSection && bGlobalOnly)
-               return (True);
+               return true;
 
        /* if we have a current service, tidy it up before moving on */
-       bRetval = True;
+       bRetval = true;
 
        if (iServiceIndex >= 0)
                bRetval = service_ok(iServiceIndex);
@@ -8149,17 +7699,17 @@ static bool do_section(const char *pszSectionName, void *userdata)
                /* issued by the post-processing of a previous section. */
                DEBUG(2, ("Processing section \"[%s]\"\n", pszSectionName));
 
-               if ((iServiceIndex = add_a_service(&sDefault, pszSectionName))
-                   < 0) {
+               iServiceIndex = add_a_service(&sDefault, pszSectionName);
+               if (iServiceIndex < 0) {
                        DEBUG(0, ("Failed to add a new service\n"));
-                       return (False);
+                       return false;
                }
                /* Clean all parametric options for service */
                /* They will be added during parsing again */
                free_param_opts(&ServicePtrs[iServiceIndex]->param_opt);
        }
 
-       return (bRetval);
+       return bRetval;
 }
 
 
@@ -8170,9 +7720,10 @@ static bool do_section(const char *pszSectionName, void *userdata)
 static bool is_default(int i)
 {
        if (!defaults_saved)
-               return False;
+               return false;
        switch (parm_table[i].type) {
                case P_LIST:
+               case P_CMDLIST:
                        return str_list_equal((const char **)parm_table[i].def.lvalue, 
                                              *(const char ***)lp_parm_ptr(NULL, 
                                                                           &parm_table[i]));
@@ -8193,13 +7744,14 @@ static bool is_default(int i)
                case P_INTEGER:
                case P_OCTAL:
                case P_ENUM:
+               case P_BYTES:
                        return parm_table[i].def.ivalue ==
                                *(int *)lp_parm_ptr(NULL, 
                                                    &parm_table[i]);
                case P_SEP:
                        break;
        }
-       return False;
+       return false;
 }
 
 /***************************************************************************
@@ -8209,7 +7761,7 @@ Display the contents of the global structure.
 static void dump_globals(FILE *f)
 {
        int i;
-       struct param_opt_struct *data;
+       struct parmlist_entry *data;
 
        fprintf(f, "[global]\n");
 
@@ -8236,7 +7788,7 @@ static void dump_globals(FILE *f)
 }
 
 /***************************************************************************
- Return True if a local parameter is currently set to the global default.
+ Return true if a local parameter is currently set to the global default.
 ***************************************************************************/
 
 bool lp_is_default(int snum, struct parm_struct *parm)
@@ -8253,7 +7805,7 @@ bool lp_is_default(int snum, struct parm_struct *parm)
 static void dump_a_service(struct loadparm_service *pService, FILE * f)
 {
        int i;
-       struct param_opt_struct *data;
+       struct parmlist_entry *data;
 
        if (pService != &sDefault)
                fprintf(f, "[%s]\n", pService->szService);
@@ -8299,7 +7851,7 @@ static void dump_a_service(struct loadparm_service *pService, FILE * f)
 bool dump_a_parameter(int snum, char *parm_name, FILE * f, bool isGlobal)
 {
        int i;
-       bool result = False;
+       bool result = false;
        parm_class p_class;
        unsigned flag = 0;
        fstring local_parm_name;
@@ -8318,7 +7870,7 @@ bool dump_a_parameter(int snum, char *parm_name, FILE * f, bool isGlobal)
                                local_parm_name, parm_opt, NULL);
                        if (parm_opt_value) {
                                printf( "%s\n", parm_opt_value);
-                               result = True;
+                               result = true;
                        }
                }
                return result;
@@ -8351,7 +7903,7 @@ bool dump_a_parameter(int snum, char *parm_name, FILE * f, bool isGlobal)
                        print_parameter(&parm_table[i],
                                        ptr, f);
                        fprintf(f, "\n");
-                       result = True;
+                       result = true;
                        break;
                }
        }
@@ -8394,7 +7946,9 @@ struct parm_struct *lp_next_parameter(int snum, int *i, int allparameters)
 
                        if ((*i) > 0
                            && (parm_table[*i].offset ==
-                               parm_table[(*i) - 1].offset))
+                               parm_table[(*i) - 1].offset)
+                           && (parm_table[*i].p_class ==
+                               parm_table[(*i) - 1].p_class))
                                continue;
 
                        if (is_default(*i) && !allparameters)
@@ -8514,7 +8068,7 @@ void lp_add_one_printer(const char *name, const char *comment,
                lp_add_printer(name, printers);
                if ((i = lp_servicenumber(name)) >= 0) {
                        string_set(&ServicePtrs[i]->comment, comment);
-                       ServicePtrs[i]->autoloaded = True;
+                       ServicePtrs[i]->autoloaded = true;
                }
        }
 }
@@ -8581,10 +8135,12 @@ static void lp_save_defaults(void)
 {
        int i;
        for (i = 0; parm_table[i].label; i++) {
-               if (i > 0 && parm_table[i].offset == parm_table[i - 1].offset)
+               if (i > 0 && parm_table[i].offset == parm_table[i - 1].offset
+                   && parm_table[i].p_class == parm_table[i - 1].p_class)
                        continue;
                switch (parm_table[i].type) {
                        case P_LIST:
+                       case P_CMDLIST:
                                parm_table[i].def.lvalue = str_list_copy(
                                        NULL, *(const char ***)lp_parm_ptr(NULL, &parm_table[i]));
                                break;
@@ -8604,6 +8160,7 @@ static void lp_save_defaults(void)
                        case P_INTEGER:
                        case P_OCTAL:
                        case P_ENUM:
+                       case P_BYTES:
                                parm_table[i].def.ivalue =
                                        *(int *)lp_parm_ptr(NULL, &parm_table[i]);
                                break;
@@ -8611,7 +8168,7 @@ static void lp_save_defaults(void)
                                break;
                }
        }
-       defaults_saved = True;
+       defaults_saved = true;
 }
 
 /***********************************************************
@@ -8621,10 +8178,10 @@ static void lp_save_defaults(void)
 static void set_allowed_client_auth(void)
 {
        if (Globals.bClientNTLMv2Auth) {
-               Globals.bClientLanManAuth = False;
+               Globals.bClientLanManAuth = false;
        }
        if (!Globals.bClientLanManAuth) {
-               Globals.bClientPlaintextAuth = False;
+               Globals.bClientPlaintextAuth = false;
        }
 }
 
@@ -8654,7 +8211,7 @@ static bool check_usershare_stat(const char *fname,
                DEBUG(0,("check_usershare_stat: file %s owned by uid %u is "
                        "not a regular file\n",
                        fname, (unsigned int)psbuf->st_ex_uid ));
-               return False;
+               return false;
        }
 
        /* Ensure this doesn't have the other write bit set. */
@@ -8662,7 +8219,7 @@ static bool check_usershare_stat(const char *fname,
                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_ex_uid ));
-               return False;
+               return false;
        }
 
        /* Should be 10k or less. */
@@ -8671,10 +8228,10 @@ static bool check_usershare_stat(const char *fname,
                        "too large (%u) to be a user share file.\n",
                        fname, (unsigned int)psbuf->st_ex_uid,
                        (unsigned int)psbuf->st_ex_size ));
-               return False;
+               return false;
        }
 
-       return True;
+       return true;
 }
 
 /***************************************************************************
@@ -8704,7 +8261,7 @@ enum usershare_err parse_usershare_file(TALLOC_CTX *ctx,
        *pp_sharepath = NULL;
        *pp_comment = NULL;
 
-       *pallow_guest = False;
+       *pallow_guest = false;
 
        if (numlines < 4) {
                return USERSHARE_MALFORMED_FILE;
@@ -8755,7 +8312,7 @@ enum usershare_err parse_usershare_file(TALLOC_CTX *ctx,
                        return USERSHARE_MALFORMED_ACL_DEF;
                }
                if (lines[4][9] == 'y') {
-                       *pallow_guest = True;
+                       *pallow_guest = true;
                }
 
                /* Backwards compatible extension to file version #2. */
@@ -8896,7 +8453,7 @@ static int process_usershare_file(const char *dir_name, const char *file_name, i
        int iService = -1;
        TALLOC_CTX *ctx = talloc_stackframe();
        struct security_descriptor *psd = NULL;
-       bool guest_ok = False;
+       bool guest_ok = false;
        char *canon_name = NULL;
        bool added_service = false;
        int ret = -1;
@@ -8935,13 +8492,18 @@ static int process_usershare_file(const char *dir_name, const char *file_name, i
        }
 
        {
-               TDB_DATA data = dbwrap_fetch_bystring(
-                       ServiceHash, canon_name, canon_name);
+               TDB_DATA data;
+               NTSTATUS status;
+
+               status = dbwrap_fetch_bystring(ServiceHash, canon_name,
+                                              canon_name, &data);
 
                iService = -1;
 
-               if ((data.dptr != NULL) && (data.dsize == sizeof(iService))) {
-                       iService = *(int *)data.dptr;
+               if (NT_STATUS_IS_OK(status) &&
+                   (data.dptr != NULL) &&
+                   (data.dsize == sizeof(iService))) {
+                       memcpy(&iService, data.dptr, sizeof(iService));
                }
        }
 
@@ -9023,7 +8585,7 @@ static int process_usershare_file(const char *dir_name, const char *file_name, i
                added_service = true;
 
                /* Read only is controlled by usershare ACL below. */
-               ServicePtrs[iService]->bRead_only = False;
+               ServicePtrs[iService]->bRead_only = false;
        }
 
        /* Write the ACL of the new/modified share. */
@@ -9035,7 +8597,7 @@ static int process_usershare_file(const char *dir_name, const char *file_name, i
        }
 
        /* If from a template it may be marked invalid. */
-       ServicePtrs[iService]->valid = True;
+       ServicePtrs[iService]->valid = true;
 
        /* Set the service as a valid usershare. */
        ServicePtrs[iService]->usershare = USERSHARE_VALID;
@@ -9140,7 +8702,7 @@ int load_usershare_service(const char *servicename)
        /* Ensure the template share exists if it's set. */
        if (Globals.szUsershareTemplateShare[0]) {
                /* We can't use lp_servicenumber here as we are recommending that
-                  template shares have -valid=False set. */
+                  template shares have -valid=false set. */
                for (snum_template = iNumServices - 1; snum_template >= 0; snum_template--) {
                        if (ServicePtrs[snum_template]->szService &&
                                        strequal(ServicePtrs[snum_template]->szService,
@@ -9167,7 +8729,8 @@ int load_usershare_service(const char *servicename)
  been removed.
 ***************************************************************************/
 
-int load_usershare_shares(struct smbd_server_connection *sconn)
+int load_usershare_shares(struct smbd_server_connection *sconn,
+                         bool (*snumused) (struct smbd_server_connection *, int))
 {
        SMB_STRUCT_DIR *dp;
        SMB_STRUCT_STAT sbuf;
@@ -9211,7 +8774,7 @@ int load_usershare_shares(struct smbd_server_connection *sconn)
        /* Ensure the template share exists if it's set. */
        if (Globals.szUsershareTemplateShare[0]) {
                /* We can't use lp_servicenumber here as we are recommending that
-                  template shares have -valid=False set. */
+                  template shares have -valid=false set. */
                for (snum_template = iNumServices - 1; snum_template >= 0; snum_template--) {
                        if (ServicePtrs[snum_template]->szService &&
                                        strequal(ServicePtrs[snum_template]->szService,
@@ -9305,7 +8868,7 @@ int load_usershare_shares(struct smbd_server_connection *sconn)
           not currently in use. */
        for (iService = iNumServices - 1; iService >= 0; iService--) {
                if (VALID(iService) && (ServicePtrs[iService]->usershare == USERSHARE_PENDING_DELETE)) {
-                       if (conn_snum_used(sconn, iService)) {
+                       if (snumused && snumused(sconn, iService)) {
                                continue;
                        }
                        /* Remove from the share ACL db. */
@@ -9350,7 +8913,7 @@ void gfree_loadparm(void)
 /***************************************************************************
  Allow client apps to specify that they are a client
 ***************************************************************************/
-void lp_set_in_client(bool b)
+static void lp_set_in_client(bool b)
 {
     in_client = b;
 }
@@ -9359,14 +8922,14 @@ void lp_set_in_client(bool b)
 /***************************************************************************
  Determine if we're running in a client app
 ***************************************************************************/
-bool lp_is_in_client(void)
+static bool lp_is_in_client(void)
 {
     return in_client;
 }
 
 /***************************************************************************
- Load the services array from the services file. Return True on success, 
False on failure.
+ Load the services array from the services file. Return true on success,
false on failure.
 ***************************************************************************/
 
 static bool lp_load_ex(const char *pszFname,
@@ -9375,16 +8938,16 @@ static bool lp_load_ex(const char *pszFname,
                       bool add_ipc,
                       bool initialize_globals,
                       bool allow_include_registry,
-                      bool allow_registry_shares)
+                      bool load_all_shares)
 {
        char *n2 = NULL;
        bool bRetval;
 
-       bRetval = False;
+       bRetval = false;
 
        DEBUG(3, ("lp_load_ex: refreshing parameters\n"));
 
-       bInGlobalSection = True;
+       bInGlobalSection = true;
        bGlobalOnly = global_only;
        bAllowIncludeRegistry = allow_include_registry;
 
@@ -9397,7 +8960,10 @@ static bool lp_load_ex(const char *pszFname,
                lp_save_defaults();
        }
 
-       free_param_opts(&Globals.param_opt);
+       if (!initialize_globals) {
+               free_param_opts(&Globals.param_opt);
+               apply_lp_set_cmdline();
+       }
 
        lp_do_parameter(-1, "idmap config * : backend", Globals.szIdmapBackend);
 
@@ -9442,7 +9008,7 @@ static bool lp_load_ex(const char *pszFname,
                        return lp_load_ex(pszFname, global_only, save_defaults,
                                          add_ipc, initialize_globals,
                                          allow_include_registry,
-                                         allow_registry_shares);
+                                         load_all_shares);
                }
        } else if (lp_config_backend_is_registry()) {
                bRetval = process_registry_globals();
@@ -9452,8 +9018,12 @@ static bool lp_load_ex(const char *pszFname,
                bRetval = false;
        }
 
-       if (bRetval && lp_registry_shares() && allow_registry_shares) {
-               bRetval = process_registry_shares();
+       if (bRetval && lp_registry_shares()) {
+               if (load_all_shares) {
+                       bRetval = process_registry_shares();
+               } else {
+                       bRetval = reload_registry_shares();
+               }
        }
 
        lp_add_auto_services(lp_auto_services());
@@ -9467,13 +9037,9 @@ static bool lp_load_ex(const char *pszFname,
                }
        }
 
-       set_server_role();
-       set_default_server_announce_type();
        set_allowed_client_auth();
 
-       if (lp_security() == SEC_SHARE) {
-               DEBUG(1, ("WARNING: The security=share option is deprecated\n"));
-       } else if (lp_security() == SEC_SERVER) {
+       if (lp_security() == SEC_SERVER) {
                DEBUG(1, ("WARNING: The security=server option is deprecated\n"));
        }
 
@@ -9482,7 +9048,7 @@ static bool lp_load_ex(const char *pszFname,
                          lp_passwordserver()));
        }
 
-       bLoaded = True;
+       bLoaded = true;
 
        /* Now we check bWINSsupport and set szWINSserver to 127.0.0.1 */
        /* if bWINSsupport is true and we are in the client            */
@@ -9511,7 +9077,7 @@ bool lp_load(const char *pszFname,
                          add_ipc,
                          initialize_globals,
                          true,   /* allow_include_registry */
-                         false); /* allow_registry_shares*/
+                         false); /* load_all_shares*/
 }
 
 bool lp_load_initial_only(const char *pszFname)
@@ -9522,7 +9088,57 @@ bool lp_load_initial_only(const char *pszFname)
                          false,  /* add_ipc */
                          true,   /* initialize_globals */
                          false,  /* allow_include_registry */
-                         false); /* allow_registry_shares*/
+                         false); /* load_all_shares*/
+}
+
+/**
+ * most common lp_load wrapper, loading only the globals
+ */
+bool lp_load_global(const char *file_name)
+{
+       return lp_load_ex(file_name,
+                         true,   /* global_only */
+                         false,  /* save_defaults */
+                         false,  /* add_ipc */
+                         true,   /* initialize_globals */
+                         true,   /* allow_include_registry */
+                         false); /* load_all_shares*/
+}
+
+/**
+ * lp_load wrapper, especially for clients
+ */
+bool lp_load_client(const char *file_name)
+{
+       lp_set_in_client(true);
+
+       return lp_load_global(file_name);
+}
+
+/**
+ * lp_load wrapper, loading only globals, but intended
+ * for subsequent calls, not reinitializing the globals
+ * to default values
+ */
+bool lp_load_global_no_reinit(const char *file_name)
+{
+       return lp_load_ex(file_name,
+                         true,   /* global_only */
+                         false,  /* save_defaults */
+                         false,  /* add_ipc */
+                         false,  /* initialize_globals */
+                         true,   /* allow_include_registry */
+                         false); /* load_all_shares*/
+}
+
+/**
+ * lp_load wrapper, especially for clients, no reinitialization
+ */
+bool lp_load_client_no_reinit(const char *file_name)
+{
+       lp_set_in_client(true);
+
+       return lp_load_global_no_reinit(file_name);
 }
 
 bool lp_load_with_registry_shares(const char *pszFname,
@@ -9537,7 +9153,7 @@ bool lp_load_with_registry_shares(const char *pszFname,
                          add_ipc,
                          initialize_globals,
                          true,  /* allow_include_registry */
-                         true); /* allow_registry_shares*/
+                         true); /* load_all_shares*/
 }
 
 /***************************************************************************
@@ -9558,7 +9174,7 @@ void lp_dump(FILE *f, bool show_defaults, int maxtoprint)
        int iService;
 
        if (show_defaults)
-               defaults_saved = False;
+               defaults_saved = false;
 
        dump_globals(f);
 
@@ -9645,11 +9261,6 @@ int lp_servicenumber(const char *pszServiceName)
        return (iService);
 }
 
-bool share_defined(const char *service_name)
-{
-       return (lp_servicenumber(service_name) != -1);
-}
-
 /*******************************************************************
  A useful volume label function. 
 ********************************************************************/
@@ -9671,12 +9282,12 @@ const char *volume_label(int snum)
 }
 
 /*******************************************************************
Set the server type we will announce as via nmbd.
Get the default server type we will announce as via nmbd.
 ********************************************************************/
 
-static void set_default_server_announce_type(void)
+int lp_default_server_announce(void)
 {
-       default_server_announce = 0;
+       int default_server_announce = 0;
        default_server_announce |= SV_TYPE_WORKSTATION;
        default_server_announce |= SV_TYPE_SERVER;
        default_server_announce |= SV_TYPE_SERVER_UNIX;
@@ -9709,6 +9320,8 @@ static void set_default_server_announce_type(void)
 
        if (lp_host_msdfs())
                default_server_announce |= SV_TYPE_DFS_SERVER;
+
+       return default_server_announce;
 }
 
 /***********************************************************
@@ -9727,7 +9340,7 @@ bool lp_domain_master(void)
  If we are PDC then prefer us as DMB
 ************************************************************/
 
-bool lp_domain_master_true_or_auto(void)
+static bool lp_domain_master_true_or_auto(void)
 {
        if (Globals.iDomainMaster) /* auto or yes */
                return true;
@@ -9753,7 +9366,7 @@ bool lp_preferred_master(void)
 
 void lp_remove_service(int snum)
 {
-       ServicePtrs[snum]->valid = False;
+       ServicePtrs[snum]->valid = false;
        invalid_services[num_invalid_services++] = snum;
 }
 
@@ -9772,15 +9385,6 @@ void lp_copy_service(int snum, const char *new_name)
 }
 
 
-/*******************************************************************
- Get the default server type we will announce as via nmbd.
-********************************************************************/
-
-int lp_default_server_announce(void)
-{
-       return default_server_announce;
-}
-
 /***********************************************************
  Set the global name resolution order (used in smbclient).
 ************************************************************/
@@ -9792,7 +9396,7 @@ void lp_set_name_resolve_order(const char *new_order)
 
 const char *lp_printername(int snum)
 {
-       const char *ret = _lp_printername(snum);
+       const char *ret = lp__printername(snum);
        if (ret == NULL || (ret != NULL && *ret == '\0'))
                ret = lp_const_servicename(snum);
 
@@ -9850,7 +9454,7 @@ bool lp_disable_spoolss( void )
        if ( spoolss_state == SVCCTL_STATE_UNKNOWN )
                spoolss_state = _lp_disable_spoolss() ? SVCCTL_STOPPED : SVCCTL_RUNNING;
 
-       return spoolss_state == SVCCTL_STOPPED ? True : False;
+       return spoolss_state == SVCCTL_STOPPED ? true : false;
 }
 
 void lp_set_spoolss_state( uint32 state )
@@ -9880,7 +9484,7 @@ bool lp_use_sendfile(int snum, struct smb_signing_state *signing_state)
        if (signing_state) {
                sign_active = smb_signing_is_active(signing_state);
        }
-       return (_lp_use_sendfile(snum) &&
+       return (lp__use_sendfile(snum) &&
                        (get_remote_arch() != RA_WIN95) &&
                        !sign_active);
 }
@@ -9931,7 +9535,7 @@ bool lp_posix_pathnames(void)
 
 void lp_set_posix_pathnames(void)
 {
-       posix_pathnames = True;
+       posix_pathnames = true;
 }
 
 /*******************************************************************
@@ -9955,7 +9559,7 @@ enum brl_flavour lp_posix_cifsu_locktype(files_struct *fsp)
 
 void lp_set_posix_default_cifsx_readwrite_locktype(enum brl_flavour val)
 {
-       posix_default_lock_was_set = True;
+       posix_default_lock_was_set = true;
        posix_cifsx_locktype = val;
 }
 
@@ -9982,11 +9586,6 @@ const char *lp_socket_address(void)
        return  Globals.szSocketAddress;
 }
 
-void lp_set_passdb_backend(const char *backend)
-{
-       string_set(&Globals.szPassdbBackend, backend);
-}
-
 /*******************************************************************
  Safe wide links checks.
  This helper function always verify the validity of wide links,
@@ -10001,6 +9600,10 @@ static bool lp_widelinks_internal(int snum)
 
 void widelinks_warning(int snum)
 {
+       if (lp_allow_insecure_widelinks()) {
+               return;
+       }
+
        if (lp_unix_extensions() && lp_widelinks_internal(snum)) {
                DEBUG(0,("Share '%s' has wide links and unix extensions enabled. "
                        "These parameters are incompatible. "
@@ -10013,7 +9616,13 @@ bool lp_widelinks(int snum)
 {
        /* wide links is always incompatible with unix extensions */
        if (lp_unix_extensions()) {
-               return false;
+               /*
+                * Unless we have "allow insecure widelinks"
+                * turned on.
+                */
+               if (!lp_allow_insecure_widelinks()) {
+                       return false;
+               }
        }
 
        return lp_widelinks_internal(snum);
@@ -10034,3 +9643,11 @@ bool lp_readraw(void)
        }
        return _lp_readraw();
 }
+
+int lp_server_role(void)
+{
+       return lp_find_server_role(lp__server_role(),
+                                  lp_security(),
+                                  lp_domain_logons(),
+                                  lp_domain_master_true_or_auto());
+}