s3-auth: Remove security=share (depricated since 3.6).
[kai/samba.git] / source3 / param / loadparm.c
index b23c8ddb88170cddeb89b1b41d9fe91cd08dc95c..453c8fd875970f54c7c385f5f7a582fbef4eaff1 100644 (file)
 #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>
@@ -310,29 +311,9 @@ 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_02, "SMB2"},
-       {PROTOCOL_SMB2_02, "SMB2_02"},
-       {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"},
@@ -410,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" },
@@ -657,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},
 
@@ -985,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,
@@ -1145,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",
@@ -1469,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,
@@ -1553,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,
@@ -1562,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,
@@ -1571,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,
@@ -1609,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,
@@ -1618,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,
@@ -1627,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,
@@ -1778,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,
@@ -1916,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,
@@ -2015,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,
@@ -2105,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,
@@ -2168,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,
@@ -2177,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,
@@ -2186,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,
@@ -3897,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,
@@ -4604,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);
 }
 
@@ -4700,7 +4668,7 @@ 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 ||
@@ -4781,6 +4749,7 @@ static void init_globals(bool reinit_globals)
        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 :-). */
@@ -4797,8 +4766,8 @@ static void init_globals(bool reinit_globals)
        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;
@@ -4822,7 +4791,7 @@ static void init_globals(bool reinit_globals)
        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;
@@ -4965,8 +4934,8 @@ static void init_globals(bool reinit_globals)
        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;
        string_set(&Globals.smb_ports, SMB_PORTS);
@@ -5250,7 +5219,7 @@ FN_GLOBAL_BOOL(lp_dns_proxy, bDNSproxy)
 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)
@@ -5298,7 +5267,6 @@ 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_GLOBAL_CONST_STRING(lp_dedicated_keytab_file, szDedicatedKeytabFile)
 FN_GLOBAL_INTEGER(lp_kerberos_method, iKerberosMethod)
@@ -5318,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_02) && (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)
@@ -5348,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)
@@ -5387,6 +5345,7 @@ FN_GLOBAL_INTEGER(lp_ctdb_timeout, ctdb_timeout)
 FN_GLOBAL_INTEGER(lp_ctdb_locktime_warn_threshold, ctdb_locktime_warn_threshold)
 FN_GLOBAL_BOOL(lp_async_smb_echo_handler, bAsyncSMBEchoHandler)
 FN_GLOBAL_BOOL(lp_multicast_dns_register, bMulticastDnsRegister)
+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)
@@ -5419,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 parmlist_entry **popts);
 static void show_parameter(int parmIndex);
 static bool is_synonym_of(int parm1, int parm2, bool *inverse);
 
@@ -5912,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))) {
@@ -5938,7 +5896,7 @@ bool lp_add_home(const char *pszHomename, int iDefaultService,
        DEBUG(3, ("adding home's share [%s] for user '%s' at '%s'\n", pszHomename, 
               user, ServicePtrs[i]->szPath ));
 
-       return (true);
+       return true;
 }
 
 /***************************************************************************
@@ -5964,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());
@@ -5987,7 +5945,7 @@ static bool lp_add_ipc(const char *ipc_name, bool guest_ok)
        DEBUG(3, ("adding IPC service\n"));
 
        SAFE_FREE(comment);
-       return (true);
+       return true;
 }
 
 /***************************************************************************
@@ -6000,7 +5958,7 @@ 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 - */
        /* we take it from the default service passed. This allows all */
@@ -6025,7 +5983,7 @@ bool lp_add_printer(const char *pszPrintername, int iDefaultService)
 
        DEBUG(3, ("adding printer service %s\n", pszPrintername));
 
-       return (true);
+       return true;
 }
 
 
@@ -6386,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;
@@ -6393,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;
        }
 
@@ -6508,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;
 
@@ -6917,7 +6881,7 @@ bool lp_file_list_changed(void)
                }
                f = f->next;
        }
-       return (false);
+       return false;
 }
 
 
@@ -7336,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;
                }
 
                /*
@@ -7347,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
@@ -7369,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]);
        }
@@ -7461,7 +7425,7 @@ bool lp_do_parameter(int snum, const char *pszParmName, const char *pszParmValue
                        break;
        }
 
-       return (true);
+       return true;
 }
 
 /***************************************************************************
@@ -7526,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));
 
@@ -7604,9 +7568,12 @@ 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;
                }
 
@@ -7679,7 +7646,7 @@ static bool equal_parameter(parm_type type, void *ptr1, void *ptr2)
                case P_SEP:
                        break;
        }
-       return (false);
+       return false;
 }
 
 /***************************************************************************
@@ -7714,11 +7681,11 @@ 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;
@@ -7735,14 +7702,14 @@ static bool do_section(const char *pszSectionName, void *userdata)
                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;
 }
 
 
@@ -8525,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));
                }
        }
 
@@ -8757,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;
@@ -8895,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. */
@@ -8940,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;
 }
@@ -8949,7 +8922,7 @@ 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;
 }
@@ -8965,7 +8938,7 @@ 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;
@@ -8987,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);
 
@@ -9032,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();
@@ -9042,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());
@@ -9057,12 +9037,9 @@ static bool lp_load_ex(const char *pszFname,
                }
        }
 
-       set_server_role();
        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"));
        }
 
@@ -9100,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)
@@ -9111,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,
@@ -9126,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*/
 }
 
 /***************************************************************************
@@ -9234,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. 
 ********************************************************************/
@@ -9318,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;
@@ -9578,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. "
@@ -9590,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);
@@ -9611,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());
+}