r25398: Parse loadparm context to all lp_*() functions.
[kai/samba.git] / source4 / param / loadparm.c
index 18a1e22d6c8db217ae693e03a4a3ffccaa373d60..cd990ab088a822861f4d67a3466467fa4e8b9234 100644 (file)
 #include "lib/util/dlinklist.h"
 #include "param/param.h"
 #include "param/loadparm.h"
-#include "pstring.h"
 
 static bool bLoaded = false;
 
 #define standard_sub_basic talloc_strdup
 
-/* some helpful bits */
-#define LP_SNUM_OK(i) (((i) >= 0) && ((i) < loadparm.iNumServices) && VALID(i))
-#define VALID(i) (loadparm.ServicePtrs[i] != NULL)
-
 static bool do_parameter(const char *, const char *, void *);
-
 static bool defaults_saved = false;
 
 struct param_opt {
@@ -87,11 +81,11 @@ struct param_opt {
 /* 
  * This structure describes global (ie., server-wide) parameters.
  */
-struct global
+struct loadparm_global
 {
        enum server_role server_role;
 
-       char **smb_ports;
+       const char **smb_ports;
        char *ncalrpc_dir;
        char *szLockDir;
        char *szModulesDir;
@@ -100,7 +94,7 @@ struct global
        char *szServerString;
        char *szAutoServices;
        char *szPasswdChat;
-       char *szConfigFile;
+       const char *szConfigFile;
        char *szShareBackend;
        char *szSAM_URL;
        char *szSECRETS_URL;
@@ -108,30 +102,30 @@ struct global
        char *szWINS_CONFIG_URL;
        char *szWINS_URL;
        char *szPrivateDir;
-       char **jsInclude;
+       const char **jsInclude;
        char *jsonrpcServicesDir;
-       char **szPasswordServers;
+       const char **szPasswordServers;
        char *szSocketOptions;
        char *szRealm;
-       char **szWINSservers;
-       char **szInterfaces;
+       const char **szWINSservers;
+       const char **szInterfaces;
        char *szSocketAddress;
        char *szAnnounceVersion;        /* This is initialised in init_globals */
        char *szWorkgroup;
        char *szNetbiosName;
-       char **szNetbiosAliases;
+       const char **szNetbiosAliases;
        char *szNetbiosScope;
        char *szDomainOtherSIDs;
-       char **szNameResolveOrder;
-       char **dcerpc_ep_servers;
-       char **server_services;
+       const char **szNameResolveOrder;
+       const char **dcerpc_ep_servers;
+       const char **server_services;
        char *ntptr_providor;
        char *szWinbindSeparator;
        char *szWinbinddSocketDirectory;
        char *szTemplateShell;
        char *szTemplateHomedir;
        int bWinbindSealedPipes;
-       char *webapps_directory;
+       char *swat_directory;
        int tls_enabled;
        char *tls_keyfile;
        char *tls_certfile;
@@ -193,7 +187,7 @@ struct global
 /* 
  * This structure describes a single service. 
  */
-struct service
+struct loadparm_service
 {
        char *szService;
        char *szPath;
@@ -232,7 +226,7 @@ struct service
 
 
 /* This is a default service used to prime a services structure */
-static struct service sDefault = {
+static struct loadparm_service sDefault = {
        NULL,                   /* szService */
        NULL,                   /* szPath */
        NULL,                   /* szCopy */
@@ -270,23 +264,28 @@ static struct service sDefault = {
 
 /* local variables */
 static struct loadparm_context {
-       struct global Globals;
-       struct service **ServicePtrs;
+       struct loadparm_global Globals;
+       struct loadparm_service **ServicePtrs;
        int iNumServices;
-       struct service *currentService;
+       struct loadparm_service *currentService;
        bool bInGlobalSection;
-} loadparm = {
-       .iNumServices = 0,
-       .currentService = NULL,
-       .bInGlobalSection = true,
-       .ServicePtrs = NULL,
-};
+       struct file_lists {
+               struct file_lists *next;
+               char *name;
+               char *subfname;
+               time_t modtime;
+       } *file_lists;
+} loadparm;
+
+struct loadparm_context *global_loadparm = &loadparm;
 
 #define NUMPARAMETERS (sizeof(parm_table) / sizeof(struct parm_struct))
 
 /* prototypes for the special type handlers */
-static bool handle_include(const char *pszParmValue, char **ptr);
-static bool handle_copy(const char *pszParmValue, char **ptr);
+static bool handle_include(struct loadparm_context *lp_ctx, 
+                          const char *pszParmValue, char **ptr);
+static bool handle_copy(struct loadparm_context *lp_ctx, 
+                       const char *pszParmValue, char **ptr);
 
 static const struct enum_list enum_protocol[] = {
        {PROTOCOL_SMB2, "SMB2"},
@@ -381,6 +380,8 @@ static const struct enum_list enum_server_role[] = {
 static struct parm_struct parm_table[] = {
        {"Base Options", P_SEP, P_SEPARATOR},
 
+       {"config file", P_STRING, P_GLOBAL, &loadparm.Globals.szConfigFile, NULL, NULL, FLAG_HIDE},
+
        {"server role", P_ENUM, P_GLOBAL, &loadparm.Globals.server_role, NULL, enum_server_role, FLAG_BASIC},
 
        {"dos charset", P_STRING, P_GLOBAL, &dos_charset, NULL, NULL, FLAG_ADVANCED | FLAG_DEVELOPER},
@@ -456,7 +457,7 @@ static struct parm_struct parm_table[] = {
        {"tls cafile", P_STRING, P_GLOBAL, &loadparm.Globals.tls_cafile, NULL, NULL, FLAG_ADVANCED | FLAG_DEVELOPER},
        {"tls crlfile", P_STRING, P_GLOBAL, &loadparm.Globals.tls_crlfile, NULL, NULL, FLAG_ADVANCED | FLAG_DEVELOPER},
        {"tls dh params file", P_STRING, P_GLOBAL, &loadparm.Globals.tls_dhpfile, NULL, NULL, FLAG_ADVANCED | FLAG_DEVELOPER},
-       {"web application directory", P_STRING, P_GLOBAL, &loadparm.Globals.webapps_directory, NULL, NULL, FLAG_ADVANCED | FLAG_DEVELOPER},
+       {"swat directory", P_STRING, P_GLOBAL, &loadparm.Globals.swat_directory, NULL, NULL, FLAG_ADVANCED | FLAG_DEVELOPER},
        {"large readwrite", P_BOOL, P_GLOBAL, &loadparm.Globals.bLargeReadwrite, NULL, NULL, FLAG_DEVELOPER},
        {"server max protocol", P_ENUM, P_GLOBAL, &loadparm.Globals.srv_maxprotocol, NULL, enum_protocol, FLAG_DEVELOPER},
        {"server min protocol", P_ENUM, P_GLOBAL, &loadparm.Globals.srv_minprotocol, NULL, enum_protocol, FLAG_DEVELOPER},
@@ -536,7 +537,6 @@ static struct parm_struct parm_table[] = {
 
        {"Miscellaneous Options", P_SEP, P_SEPARATOR},
        
-       {"config file", P_STRING, P_GLOBAL, &loadparm.Globals.szConfigFile, NULL, NULL, FLAG_HIDE},
        {"share backend", P_STRING, P_GLOBAL, &loadparm.Globals.szShareBackend, NULL, NULL, FLAG_ADVANCED | FLAG_DEVELOPER},
        {"preload", P_STRING, P_GLOBAL, &loadparm.Globals.szAutoServices, NULL, NULL, FLAG_ADVANCED | FLAG_DEVELOPER},
        {"auto services", P_STRING, P_GLOBAL, &loadparm.Globals.szAutoServices, NULL, NULL, FLAG_ADVANCED | FLAG_DEVELOPER},
@@ -545,7 +545,6 @@ static struct parm_struct parm_table[] = {
        {"modules dir", P_STRING, P_GLOBAL, &loadparm.Globals.szModulesDir, NULL, NULL, FLAG_ADVANCED | FLAG_DEVELOPER},
        {"pid directory", P_STRING, P_GLOBAL, &loadparm.Globals.szPidDir, NULL, NULL, FLAG_ADVANCED | FLAG_DEVELOPER}, 
        {"js include", P_LIST, P_GLOBAL, &loadparm.Globals.jsInclude, NULL, NULL, FLAG_ADVANCED | FLAG_DEVELOPER},
-       {"jsonrpc services directory", P_STRING, P_GLOBAL, &loadparm.Globals.jsonrpcServicesDir, NULL, NULL, FLAG_ADVANCED | FLAG_DEVELOPER},
        {"setup directory", P_STRING, P_GLOBAL, &loadparm.Globals.szSetupDir, NULL, NULL, FLAG_ADVANCED | FLAG_DEVELOPER},
        
        {"socket address", P_STRING, P_GLOBAL, &loadparm.Globals.szSocketAddress, NULL, NULL, FLAG_DEVELOPER},
@@ -644,125 +643,121 @@ static const char *lp_string(const char *s)
    parameters from the rest of the program are defined 
 */
 
-#define FN_GLOBAL_STRING(fn_name,ptr) \
- const char *fn_name(void) {return(lp_string(*(char **)(ptr) ? *(char **)(ptr) : ""));}
-#define FN_GLOBAL_CONST_STRING(fn_name,ptr) \
- const char *fn_name(void) {return(*(const char **)(ptr) ? *(const char **)(ptr) : "");}
-#define FN_GLOBAL_LIST(fn_name,ptr) \
- const char **fn_name(void) {return(*(const char ***)(ptr));}
-#define FN_GLOBAL_BOOL(fn_name,ptr) \
- bool fn_name(void) {return((bool)*(int *)(ptr));}
+#define FN_GLOBAL_STRING(fn_name,var_name) \
+ const char *fn_name(struct loadparm_context *lp_ctx) {if (lp_ctx == NULL) return NULL; return lp_ctx->Globals.var_name ? lp_string(lp_ctx->Globals.var_name) : "";}
+#define FN_GLOBAL_CONST_STRING(fn_name,var_name) \
+ const char *fn_name(struct loadparm_context *lp_ctx) {if (lp_ctx == NULL) return NULL; return lp_ctx->Globals.var_name ? lp_ctx->Globals.var_name : "";}
+#define FN_GLOBAL_LIST(fn_name,var_name) \
+ const char **fn_name(struct loadparm_context *lp_ctx) {if (lp_ctx == NULL) return NULL; return lp_ctx->Globals.var_name;}
+#define FN_GLOBAL_BOOL(fn_name,var_name) \
+ bool fn_name(struct loadparm_context *lp_ctx) {if (lp_ctx == NULL) return false; return lp_ctx->Globals.var_name;}
 #if 0 /* unused */
 #define FN_GLOBAL_CHAR(fn_name,ptr) \
  char fn_name(void) {return(*(char *)(ptr));}
 #endif
-#define FN_GLOBAL_INTEGER(fn_name,ptr) \
- int fn_name(void) {return(*(int *)(ptr));}
+#define FN_GLOBAL_INTEGER(fn_name,var_name) \
+ int fn_name(struct loadparm_context *lp_ctx) {if (lp_ctx == NULL) return 0; return lp_ctx->Globals.var_name;}
 
 #define FN_LOCAL_STRING(fn_name,val) \
- const char *fn_name(struct service *service) {return(lp_string((const char *)((service != NULL && service->val != NULL) ? service->val : sDefault.val)));}
+ const char *fn_name(struct loadparm_service *service) {return(lp_string((const char *)((service != NULL && service->val != NULL) ? service->val : sDefault.val)));}
 #define FN_LOCAL_CONST_STRING(fn_name,val) \
- const char *fn_name(struct service *service) {return (const char *)(service != NULL && service->val != NULL) ? service->val : sDefault.val;}
+ const char *fn_name(struct loadparm_service *service) {return (const char *)(service != NULL && service->val != NULL) ? service->val : sDefault.val;}
 #define FN_LOCAL_LIST(fn_name,val) \
- const char **fn_name(struct service *service) {return(const char **)(service != NULL && service->val != NULL? service->val : sDefault.val);}
+ const char **fn_name(struct loadparm_service *service) {return(const char **)(service != NULL && service->val != NULL? service->val : sDefault.val);}
 #define FN_LOCAL_BOOL(fn_name,val) \
- bool fn_name(struct service *service) {return((service != NULL)? service->val : sDefault.val);}
+ bool fn_name(struct loadparm_service *service) {return((service != NULL)? service->val : sDefault.val);}
 #define FN_LOCAL_INTEGER(fn_name,val) \
- int fn_name(struct service *service) {return((service != NULL)? service->val : sDefault.val);}
-
-_PUBLIC_ FN_GLOBAL_INTEGER(lp_server_role, &loadparm.Globals.server_role)
-_PUBLIC_ FN_GLOBAL_LIST(lp_smb_ports, &loadparm.Globals.smb_ports)
-_PUBLIC_ FN_GLOBAL_INTEGER(lp_nbt_port, &loadparm.Globals.nbt_port)
-_PUBLIC_ FN_GLOBAL_INTEGER(lp_dgram_port, &loadparm.Globals.dgram_port)
-_PUBLIC_ FN_GLOBAL_INTEGER(lp_cldap_port, &loadparm.Globals.cldap_port)
-_PUBLIC_ FN_GLOBAL_INTEGER(lp_krb5_port, &loadparm.Globals.krb5_port)
-_PUBLIC_ FN_GLOBAL_INTEGER(lp_kpasswd_port, &loadparm.Globals.kpasswd_port)
-_PUBLIC_ FN_GLOBAL_INTEGER(lp_web_port, &loadparm.Globals.web_port)
-_PUBLIC_ FN_GLOBAL_STRING(lp_dos_charset, &dos_charset)
-_PUBLIC_ FN_GLOBAL_STRING(lp_webapps_directory, &loadparm.Globals.webapps_directory)
-_PUBLIC_ FN_GLOBAL_BOOL(lp_tls_enabled, &loadparm.Globals.tls_enabled)
-_PUBLIC_ FN_GLOBAL_STRING(lp_tls_keyfile, &loadparm.Globals.tls_keyfile)
-_PUBLIC_ FN_GLOBAL_STRING(lp_tls_certfile, &loadparm.Globals.tls_certfile)
-_PUBLIC_ FN_GLOBAL_STRING(lp_tls_cafile, &loadparm.Globals.tls_cafile)
-_PUBLIC_ FN_GLOBAL_STRING(lp_tls_crlfile, &loadparm.Globals.tls_crlfile)
-_PUBLIC_ FN_GLOBAL_STRING(lp_tls_dhpfile, &loadparm.Globals.tls_dhpfile)
-_PUBLIC_ FN_GLOBAL_STRING(lp_unix_charset, &unix_charset)
-_PUBLIC_ FN_GLOBAL_STRING(lp_display_charset, &display_charset)
-_PUBLIC_ FN_GLOBAL_STRING(lp_configfile, &loadparm.Globals.szConfigFile)
-_PUBLIC_ FN_GLOBAL_STRING(lp_share_backend, &loadparm.Globals.szShareBackend)
-_PUBLIC_ FN_GLOBAL_STRING(lp_sam_url, &loadparm.Globals.szSAM_URL)
-_PUBLIC_ FN_GLOBAL_STRING(lp_secrets_url, &loadparm.Globals.szSECRETS_URL)
-_PUBLIC_ FN_GLOBAL_STRING(lp_spoolss_url, &loadparm.Globals.szSPOOLSS_URL)
-_PUBLIC_ FN_GLOBAL_STRING(lp_wins_config_url, &loadparm.Globals.szWINS_CONFIG_URL)
-_PUBLIC_ FN_GLOBAL_STRING(lp_wins_url, &loadparm.Globals.szWINS_URL)
-_PUBLIC_ FN_GLOBAL_CONST_STRING(lp_winbind_separator, &loadparm.Globals.szWinbindSeparator)
-_PUBLIC_ FN_GLOBAL_CONST_STRING(lp_winbindd_socket_directory, &loadparm.Globals.szWinbinddSocketDirectory)
-_PUBLIC_ FN_GLOBAL_CONST_STRING(lp_template_shell, &loadparm.Globals.szTemplateShell)
-_PUBLIC_ FN_GLOBAL_CONST_STRING(lp_template_homedir, &loadparm.Globals.szTemplateHomedir)
-_PUBLIC_ FN_GLOBAL_BOOL(lp_winbind_sealed_pipes, &loadparm.Globals.bWinbindSealedPipes)
-_PUBLIC_ FN_GLOBAL_STRING(lp_private_dir, &loadparm.Globals.szPrivateDir)
-_PUBLIC_ FN_GLOBAL_STRING(lp_serverstring, &loadparm.Globals.szServerString)
-_PUBLIC_ FN_GLOBAL_STRING(lp_lockdir, &loadparm.Globals.szLockDir)
-_PUBLIC_ FN_GLOBAL_STRING(lp_modulesdir, &loadparm.Globals.szModulesDir)
-_PUBLIC_ FN_GLOBAL_STRING(lp_setupdir, &loadparm.Globals.szSetupDir)
-_PUBLIC_ FN_GLOBAL_STRING(lp_ncalrpc_dir, &loadparm.Globals.ncalrpc_dir)
-_PUBLIC_ FN_GLOBAL_STRING(lp_piddir, &loadparm.Globals.szPidDir)
-_PUBLIC_ FN_GLOBAL_LIST(lp_dcerpc_endpoint_servers, &loadparm.Globals.dcerpc_ep_servers)
-_PUBLIC_ FN_GLOBAL_LIST(lp_server_services, &loadparm.Globals.server_services)
-_PUBLIC_ FN_GLOBAL_STRING(lp_ntptr_providor, &loadparm.Globals.ntptr_providor)
-_PUBLIC_ FN_GLOBAL_STRING(lp_auto_services, &loadparm.Globals.szAutoServices)
-_PUBLIC_ FN_GLOBAL_STRING(lp_passwd_chat, &loadparm.Globals.szPasswdChat)
-_PUBLIC_ FN_GLOBAL_LIST(lp_passwordserver, &loadparm.Globals.szPasswordServers)
-_PUBLIC_ FN_GLOBAL_LIST(lp_name_resolve_order, &loadparm.Globals.szNameResolveOrder)
-_PUBLIC_ FN_GLOBAL_STRING(lp_realm, &loadparm.Globals.szRealm)
-_PUBLIC_ FN_GLOBAL_STRING(lp_socket_options, &loadparm.Globals.socket_options)
-_PUBLIC_ FN_GLOBAL_STRING(lp_workgroup, &loadparm.Globals.szWorkgroup)
-_PUBLIC_ FN_GLOBAL_STRING(lp_netbios_name, &loadparm.Globals.szNetbiosName)
-_PUBLIC_ FN_GLOBAL_STRING(lp_netbios_scope, &loadparm.Globals.szNetbiosScope)
-_PUBLIC_ FN_GLOBAL_LIST(lp_wins_server_list, &loadparm.Globals.szWINSservers)
-_PUBLIC_ FN_GLOBAL_LIST(lp_interfaces, &loadparm.Globals.szInterfaces)
-_PUBLIC_ FN_GLOBAL_STRING(lp_socket_address, &loadparm.Globals.szSocketAddress)
-_PUBLIC_ FN_GLOBAL_LIST(lp_netbios_aliases, &loadparm.Globals.szNetbiosAliases)
-
-_PUBLIC_ FN_GLOBAL_BOOL(lp_disable_netbios, &loadparm.Globals.bDisableNetbios)
-_PUBLIC_ FN_GLOBAL_BOOL(lp_wins_support, &loadparm.Globals.bWINSsupport)
-_PUBLIC_ FN_GLOBAL_BOOL(lp_wins_dns_proxy, &loadparm.Globals.bWINSdnsProxy)
-_PUBLIC_ FN_GLOBAL_STRING(lp_wins_hook, &loadparm.Globals.szWINSHook)
-_PUBLIC_ FN_GLOBAL_BOOL(lp_local_master, &loadparm.Globals.bLocalMaster)
-_PUBLIC_ FN_GLOBAL_BOOL(lp_readraw, &loadparm.Globals.bReadRaw)
-_PUBLIC_ FN_GLOBAL_BOOL(lp_large_readwrite, &loadparm.Globals.bLargeReadwrite)
-_PUBLIC_ FN_GLOBAL_BOOL(lp_writeraw, &loadparm.Globals.bWriteRaw)
-_PUBLIC_ FN_GLOBAL_BOOL(lp_null_passwords, &loadparm.Globals.bNullPasswords)
-_PUBLIC_ FN_GLOBAL_BOOL(lp_obey_pam_restrictions, &loadparm.Globals.bObeyPamRestrictions)
-_PUBLIC_ FN_GLOBAL_BOOL(lp_encrypted_passwords, &loadparm.Globals.bEncryptPasswords)
-_PUBLIC_ FN_GLOBAL_BOOL(lp_time_server, &loadparm.Globals.bTimeServer)
-_PUBLIC_ FN_GLOBAL_BOOL(lp_bind_interfaces_only, &loadparm.Globals.bBindInterfacesOnly)
-_PUBLIC_ FN_GLOBAL_BOOL(lp_unicode, &loadparm.Globals.bUnicode)
-_PUBLIC_ FN_GLOBAL_BOOL(lp_nt_status_support, &loadparm.Globals.bNTStatusSupport)
-_PUBLIC_ FN_GLOBAL_BOOL(lp_lanman_auth, &loadparm.Globals.bLanmanAuth)
-_PUBLIC_ FN_GLOBAL_BOOL(lp_ntlm_auth, &loadparm.Globals.bNTLMAuth)
-_PUBLIC_ FN_GLOBAL_BOOL(lp_client_plaintext_auth, &loadparm.Globals.bClientPlaintextAuth)
-_PUBLIC_ FN_GLOBAL_BOOL(lp_client_lanman_auth, &loadparm.Globals.bClientLanManAuth)
-_PUBLIC_ FN_GLOBAL_BOOL(lp_client_ntlmv2_auth, &loadparm.Globals.bClientNTLMv2Auth)
-_PUBLIC_ FN_GLOBAL_BOOL(lp_client_use_spnego_principal, &loadparm.Globals.client_use_spnego_principal)
-_PUBLIC_ FN_GLOBAL_BOOL(lp_host_msdfs, &loadparm.Globals.bHostMSDfs)
-_PUBLIC_ FN_GLOBAL_BOOL(lp_unix_extensions, &loadparm.Globals.bUnixExtensions)
-_PUBLIC_ FN_GLOBAL_BOOL(lp_use_spnego, &loadparm.Globals.bUseSpnego)
-_PUBLIC_ FN_GLOBAL_BOOL(lp_rpc_big_endian, &loadparm.Globals.bRpcBigEndian)
-_PUBLIC_ FN_GLOBAL_INTEGER(lp_max_wins_ttl, &loadparm.Globals.max_wins_ttl)
-_PUBLIC_ FN_GLOBAL_INTEGER(lp_min_wins_ttl, &loadparm.Globals.min_wins_ttl)
-_PUBLIC_ FN_GLOBAL_INTEGER(lp_maxmux, &loadparm.Globals.max_mux)
-_PUBLIC_ FN_GLOBAL_INTEGER(lp_max_xmit, &loadparm.Globals.max_xmit)
-_PUBLIC_ FN_GLOBAL_INTEGER(lp_passwordlevel, &loadparm.Globals.pwordlevel)
-_PUBLIC_ FN_GLOBAL_INTEGER(lp_srv_maxprotocol, &loadparm.Globals.srv_maxprotocol)
-_PUBLIC_ FN_GLOBAL_INTEGER(lp_srv_minprotocol, &loadparm.Globals.srv_minprotocol)
-_PUBLIC_ FN_GLOBAL_INTEGER(lp_cli_maxprotocol, &loadparm.Globals.cli_maxprotocol)
-_PUBLIC_ FN_GLOBAL_INTEGER(lp_cli_minprotocol, &loadparm.Globals.cli_minprotocol)
-_PUBLIC_ FN_GLOBAL_INTEGER(lp_security, &loadparm.Globals.security)
-_PUBLIC_ FN_GLOBAL_BOOL(lp_paranoid_server_security, &loadparm.Globals.paranoid_server_security)
-_PUBLIC_ FN_GLOBAL_INTEGER(lp_announce_as, &loadparm.Globals.announce_as)
-_PUBLIC_ FN_GLOBAL_LIST(lp_js_include, &loadparm.Globals.jsInclude)
-_PUBLIC_ FN_GLOBAL_STRING(lp_jsonrpc_services_dir, &loadparm.Globals.jsonrpcServicesDir)
+ int fn_name(struct loadparm_service *service) {return((service != NULL)? service->val : sDefault.val);}
+
+_PUBLIC_ FN_GLOBAL_INTEGER(lp_server_role, server_role)
+_PUBLIC_ FN_GLOBAL_LIST(lp_smb_ports, smb_ports)
+_PUBLIC_ FN_GLOBAL_INTEGER(lp_nbt_port, nbt_port)
+_PUBLIC_ FN_GLOBAL_INTEGER(lp_dgram_port, dgram_port)
+_PUBLIC_ FN_GLOBAL_INTEGER(lp_cldap_port, cldap_port)
+_PUBLIC_ FN_GLOBAL_INTEGER(lp_krb5_port, krb5_port)
+_PUBLIC_ FN_GLOBAL_INTEGER(lp_kpasswd_port, kpasswd_port)
+_PUBLIC_ FN_GLOBAL_INTEGER(lp_web_port, web_port)
+_PUBLIC_ FN_GLOBAL_STRING(lp_swat_directory, swat_directory)
+_PUBLIC_ FN_GLOBAL_BOOL(lp_tls_enabled, tls_enabled)
+_PUBLIC_ FN_GLOBAL_STRING(lp_tls_keyfile, tls_keyfile)
+_PUBLIC_ FN_GLOBAL_STRING(lp_tls_certfile, tls_certfile)
+_PUBLIC_ FN_GLOBAL_STRING(lp_tls_cafile, tls_cafile)
+_PUBLIC_ FN_GLOBAL_STRING(lp_tls_crlfile, tls_crlfile)
+_PUBLIC_ FN_GLOBAL_STRING(lp_tls_dhpfile, tls_dhpfile)
+_PUBLIC_ FN_GLOBAL_STRING(lp_share_backend, szShareBackend)
+_PUBLIC_ FN_GLOBAL_STRING(lp_sam_url, szSAM_URL)
+_PUBLIC_ FN_GLOBAL_STRING(lp_secrets_url, szSECRETS_URL)
+_PUBLIC_ FN_GLOBAL_STRING(lp_spoolss_url, szSPOOLSS_URL)
+_PUBLIC_ FN_GLOBAL_STRING(lp_wins_config_url, szWINS_CONFIG_URL)
+_PUBLIC_ FN_GLOBAL_STRING(lp_wins_url, szWINS_URL)
+_PUBLIC_ FN_GLOBAL_CONST_STRING(lp_winbind_separator, szWinbindSeparator)
+_PUBLIC_ FN_GLOBAL_CONST_STRING(lp_winbindd_socket_directory, szWinbinddSocketDirectory)
+_PUBLIC_ FN_GLOBAL_CONST_STRING(lp_template_shell, szTemplateShell)
+_PUBLIC_ FN_GLOBAL_CONST_STRING(lp_template_homedir, szTemplateHomedir)
+_PUBLIC_ FN_GLOBAL_BOOL(lp_winbind_sealed_pipes, bWinbindSealedPipes)
+_PUBLIC_ FN_GLOBAL_STRING(lp_private_dir, szPrivateDir)
+_PUBLIC_ FN_GLOBAL_STRING(lp_serverstring, szServerString)
+_PUBLIC_ FN_GLOBAL_STRING(lp_lockdir, szLockDir)
+_PUBLIC_ FN_GLOBAL_STRING(lp_modulesdir, szModulesDir)
+_PUBLIC_ FN_GLOBAL_STRING(lp_setupdir, szSetupDir)
+_PUBLIC_ FN_GLOBAL_STRING(lp_ncalrpc_dir, ncalrpc_dir)
+_PUBLIC_ FN_GLOBAL_STRING(lp_piddir, szPidDir)
+_PUBLIC_ FN_GLOBAL_LIST(lp_dcerpc_endpoint_servers, dcerpc_ep_servers)
+_PUBLIC_ FN_GLOBAL_LIST(lp_server_services, server_services)
+_PUBLIC_ FN_GLOBAL_STRING(lp_ntptr_providor, ntptr_providor)
+_PUBLIC_ FN_GLOBAL_STRING(lp_auto_services, szAutoServices)
+_PUBLIC_ FN_GLOBAL_STRING(lp_passwd_chat, szPasswdChat)
+_PUBLIC_ FN_GLOBAL_LIST(lp_passwordserver, szPasswordServers)
+_PUBLIC_ FN_GLOBAL_LIST(lp_name_resolve_order, szNameResolveOrder)
+_PUBLIC_ FN_GLOBAL_STRING(lp_realm, szRealm)
+_PUBLIC_ FN_GLOBAL_STRING(lp_socket_options, socket_options)
+_PUBLIC_ FN_GLOBAL_STRING(lp_workgroup, szWorkgroup)
+_PUBLIC_ FN_GLOBAL_STRING(lp_netbios_name, szNetbiosName)
+_PUBLIC_ FN_GLOBAL_STRING(lp_netbios_scope, szNetbiosScope)
+_PUBLIC_ FN_GLOBAL_LIST(lp_wins_server_list, szWINSservers)
+_PUBLIC_ FN_GLOBAL_LIST(lp_interfaces, szInterfaces)
+_PUBLIC_ FN_GLOBAL_STRING(lp_socket_address, szSocketAddress)
+_PUBLIC_ FN_GLOBAL_LIST(lp_netbios_aliases, szNetbiosAliases)
+
+_PUBLIC_ FN_GLOBAL_BOOL(lp_disable_netbios, bDisableNetbios)
+_PUBLIC_ FN_GLOBAL_BOOL(lp_wins_support, bWINSsupport)
+_PUBLIC_ FN_GLOBAL_BOOL(lp_wins_dns_proxy, bWINSdnsProxy)
+_PUBLIC_ FN_GLOBAL_STRING(lp_wins_hook, szWINSHook)
+_PUBLIC_ FN_GLOBAL_STRING(lp_configfile, szConfigFile)
+_PUBLIC_ FN_GLOBAL_BOOL(lp_local_master, bLocalMaster)
+_PUBLIC_ FN_GLOBAL_BOOL(lp_readraw, bReadRaw)
+_PUBLIC_ FN_GLOBAL_BOOL(lp_large_readwrite, bLargeReadwrite)
+_PUBLIC_ FN_GLOBAL_BOOL(lp_writeraw, bWriteRaw)
+_PUBLIC_ FN_GLOBAL_BOOL(lp_null_passwords, bNullPasswords)
+_PUBLIC_ FN_GLOBAL_BOOL(lp_obey_pam_restrictions, bObeyPamRestrictions)
+_PUBLIC_ FN_GLOBAL_BOOL(lp_encrypted_passwords, bEncryptPasswords)
+_PUBLIC_ FN_GLOBAL_BOOL(lp_time_server, bTimeServer)
+_PUBLIC_ FN_GLOBAL_BOOL(lp_bind_interfaces_only, bBindInterfacesOnly)
+_PUBLIC_ FN_GLOBAL_BOOL(lp_unicode, bUnicode)
+_PUBLIC_ FN_GLOBAL_BOOL(lp_nt_status_support, bNTStatusSupport)
+_PUBLIC_ FN_GLOBAL_BOOL(lp_lanman_auth, bLanmanAuth)
+_PUBLIC_ FN_GLOBAL_BOOL(lp_ntlm_auth, bNTLMAuth)
+_PUBLIC_ FN_GLOBAL_BOOL(lp_client_plaintext_auth, bClientPlaintextAuth)
+_PUBLIC_ FN_GLOBAL_BOOL(lp_client_lanman_auth, bClientLanManAuth)
+_PUBLIC_ FN_GLOBAL_BOOL(lp_client_ntlmv2_auth, bClientNTLMv2Auth)
+_PUBLIC_ FN_GLOBAL_BOOL(lp_client_use_spnego_principal, client_use_spnego_principal)
+_PUBLIC_ FN_GLOBAL_BOOL(lp_host_msdfs, bHostMSDfs)
+_PUBLIC_ FN_GLOBAL_BOOL(lp_unix_extensions, bUnixExtensions)
+_PUBLIC_ FN_GLOBAL_BOOL(lp_use_spnego, bUseSpnego)
+_PUBLIC_ FN_GLOBAL_BOOL(lp_rpc_big_endian, bRpcBigEndian)
+_PUBLIC_ FN_GLOBAL_INTEGER(lp_max_wins_ttl, max_wins_ttl)
+_PUBLIC_ FN_GLOBAL_INTEGER(lp_min_wins_ttl, min_wins_ttl)
+_PUBLIC_ FN_GLOBAL_INTEGER(lp_maxmux, max_mux)
+_PUBLIC_ FN_GLOBAL_INTEGER(lp_max_xmit, max_xmit)
+_PUBLIC_ FN_GLOBAL_INTEGER(lp_passwordlevel, pwordlevel)
+_PUBLIC_ FN_GLOBAL_INTEGER(lp_srv_maxprotocol, srv_maxprotocol)
+_PUBLIC_ FN_GLOBAL_INTEGER(lp_srv_minprotocol, srv_minprotocol)
+_PUBLIC_ FN_GLOBAL_INTEGER(lp_cli_maxprotocol, cli_maxprotocol)
+_PUBLIC_ FN_GLOBAL_INTEGER(lp_cli_minprotocol, cli_minprotocol)
+_PUBLIC_ FN_GLOBAL_INTEGER(lp_security, security)
+_PUBLIC_ FN_GLOBAL_BOOL(lp_paranoid_server_security, paranoid_server_security)
+_PUBLIC_ FN_GLOBAL_INTEGER(lp_announce_as, announce_as)
+_PUBLIC_ FN_GLOBAL_LIST(lp_js_include, jsInclude)
 _PUBLIC_ FN_LOCAL_STRING(lp_servicename, szService)
 _PUBLIC_ FN_LOCAL_CONST_STRING(lp_const_servicename, szService)
 _PUBLIC_ FN_LOCAL_STRING(lp_pathname, szPath)
@@ -789,28 +784,30 @@ _PUBLIC_ FN_LOCAL_INTEGER(lp_create_mask, iCreate_mask)
 _PUBLIC_ FN_LOCAL_INTEGER(lp_force_create_mode, iCreate_force_mode)
 _PUBLIC_ FN_LOCAL_INTEGER(lp_dir_mask, iDir_mask)
 _PUBLIC_ FN_LOCAL_INTEGER(lp_force_dir_mode, iDir_force_mode)
-_PUBLIC_ FN_GLOBAL_INTEGER(lp_server_signing, &loadparm.Globals.server_signing)
-_PUBLIC_ FN_GLOBAL_INTEGER(lp_client_signing, &loadparm.Globals.client_signing)
+_PUBLIC_ FN_GLOBAL_INTEGER(lp_server_signing, server_signing)
+_PUBLIC_ FN_GLOBAL_INTEGER(lp_client_signing, client_signing)
 
 /* local prototypes */
-
 static int map_parameter(const char *pszParmName);
-static struct service *getservicebyname(const char *pszServiceName);
-static void copy_service(struct service * pserviceDest,
-                        struct service * pserviceSource, int *pcopymapDest);
-static bool service_ok(struct service *service);
+static struct loadparm_service *getservicebyname(struct loadparm_context *lp_ctx, 
+                                       const char *pszServiceName);
+static void copy_service(struct loadparm_service *pserviceDest,
+                        struct loadparm_service *pserviceSource, 
+                        int *pcopymapDest);
+static bool service_ok(struct loadparm_service *service);
 static bool do_section(const char *pszSectionName, void *);
-static void init_copymap(struct service * pservice);
+static void init_copymap(struct loadparm_service *pservice);
 
 /* 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 */
-const char *lp_get_parametric(struct service *service, const char *type, const char *option)
+const char *lp_get_parametric(struct loadparm_service *service, 
+                             const char *type, const char *option)
 {
        char *vfskey;
         struct param_opt *data;
        
-       data = (service == NULL ?  loadparm.Globals.param_opt : service->param_opt);
+       data = (service == NULL ? loadparm.Globals.param_opt : service->param_opt);
     
        asprintf(&vfskey, "%s:%s", type, option);
        strlower(vfskey);
@@ -908,7 +905,7 @@ static bool lp_bool(const char *s)
 /* Parametric option has following syntax: 'Type: option = value' */
 /* Returned value is allocated in 'lp_talloc' context */
 
-const char *lp_parm_string(struct service *service, const char *type, 
+const char *lp_parm_string(struct loadparm_service *service, const char *type, 
                           const char *option)
 {
        const char *value = lp_get_parametric(service, type, option);
@@ -923,13 +920,15 @@ const char *lp_parm_string(struct service *service, const char *type,
 /* Parametric option has following syntax: 'Type: option = value' */
 /* Returned value is allocated in 'lp_talloc' context */
 
-const char **lp_parm_string_list(struct service *service, const char *type, 
+const char **lp_parm_string_list(struct loadparm_service *service, 
+                                const char *type, 
                                 const char *option, const char *separator)
 {
        const char *value = lp_get_parametric(service, type, option);
        
        if (value)
-               return str_list_make(talloc_autofree_context(), value, separator);
+               return str_list_make(talloc_autofree_context(), value, 
+                                    separator);
 
        return NULL;
 }
@@ -937,8 +936,8 @@ const char **lp_parm_string_list(struct service *service, const char *type,
 /* Return parametric option from a given service. Type is a part of option before ':' */
 /* Parametric option has following syntax: 'Type: option = value' */
 
-int lp_parm_int(struct service *service, const char *type, const char *option
-               int default_v)
+int lp_parm_int(struct loadparm_service *service, const char *type
+               const char *option, int default_v)
 {
        const char *value = lp_get_parametric(service, type, option);
        
@@ -953,7 +952,7 @@ int lp_parm_int(struct service *service, const char *type, const char *option,
  * Parametric option has following syntax: 'Type: option = value'.
  */
 
-int lp_parm_bytes(struct service *service, const char *type, 
+int lp_parm_bytes(struct loadparm_service *service, const char *type, 
                  const char *option, int default_v)
 {
        uint64_t bval;
@@ -972,7 +971,7 @@ int lp_parm_bytes(struct service *service, const char *type,
 /* Return parametric option from a given service. Type is a part of option before ':' */
 /* Parametric option has following syntax: 'Type: option = value' */
 
-unsigned long lp_parm_ulong(struct service *service, const char *type, 
+unsigned long lp_parm_ulong(struct loadparm_service *service, const char *type, 
                            const char *option, unsigned long default_v)
 {
        const char *value = lp_get_parametric(service, type, option);
@@ -984,7 +983,7 @@ unsigned long lp_parm_ulong(struct service *service, const char *type,
 }
 
 
-double lp_parm_double(struct service *service, const char *type, 
+double lp_parm_double(struct loadparm_service *service, const char *type, 
                      const char *option, double default_v)
 {
        const char *value = lp_get_parametric(service, type, option);
@@ -998,7 +997,7 @@ double lp_parm_double(struct service *service, const char *type,
 /* Return parametric option from a given service. Type is a part of option before ':' */
 /* Parametric option has following syntax: 'Type: option = value' */
 
-bool lp_parm_bool(struct service *service, const char *type, 
+bool lp_parm_bool(struct loadparm_service *service, const char *type, 
                  const char *option, bool default_v)
 {
        const char *value = lp_get_parametric(service, type, option);
@@ -1014,38 +1013,56 @@ bool lp_parm_bool(struct service *service, const char *type,
  Initialise a service to the defaults.
 ***************************************************************************/
 
-static struct service *init_service(TALLOC_CTX *mem_ctx)
+static struct loadparm_service *init_service(TALLOC_CTX *mem_ctx)
 {
-       struct service *pservice = talloc_zero(mem_ctx, struct service);
+       struct loadparm_service *pservice = 
+               talloc_zero(mem_ctx, struct loadparm_service);
        copy_service(pservice, &sDefault, NULL);
        return pservice;
 }
 
-void string_free(char **str)
+/**
+ Set a string value, deallocating any existing space, and allocing the space
+ for the string
+**/
+static bool string_set(TALLOC_CTX *mem_ctx, char **dest, const char *src)
 {
-       if (str) {
-               talloc_free(*str);
-               *str = NULL;
+       talloc_free(*dest);
+
+       if (src == NULL) 
+               src = "";
+
+       *dest = talloc_strdup(mem_ctx, src);
+       if ((*dest) == NULL) {
+               DEBUG(0,("Out of memory in string_init\n"));
+               return false;
        }
+
+       return true;
 }
 
+
+
 /***************************************************************************
  Add a new service to the services array initialising it with the given 
  service. 
 ***************************************************************************/
 
-static struct service *add_a_service(const struct service *pservice, const char *name)
+static struct loadparm_service *add_a_service(struct loadparm_context *lp_ctx, 
+                                    const struct loadparm_service *pservice, 
+                                    const char *name)
 {
        int i;
-       struct service tservice;
-       int num_to_alloc = loadparm.iNumServices + 1;
+       struct loadparm_service tservice;
+       int num_to_alloc = lp_ctx->iNumServices + 1;
        struct param_opt *data, *pdata;
 
        tservice = *pservice;
 
        /* it might already exist */
        if (name) {
-               struct service *service = getservicebyname(name);
+               struct loadparm_service *service = getservicebyname(lp_ctx, 
+                                                                   name);
                if (service != NULL) {
                        /* Clean all parametric options for service */
                        /* They will be added during parsing again */
@@ -1061,37 +1078,38 @@ static struct service *add_a_service(const struct service *pservice, const char
        }
 
        /* find an invalid one */
-       for (i = 0; i < loadparm.iNumServices; i++)
-               if (loadparm.ServicePtrs[i] == NULL)
+       for (i = 0; i < lp_ctx->iNumServices; i++)
+               if (lp_ctx->ServicePtrs[i] == NULL)
                        break;
 
        /* if not, then create one */
-       if (i == loadparm.iNumServices) {
-               struct service **tsp;
+       if (i == lp_ctx->iNumServices) {
+               struct loadparm_service **tsp;
                
-               tsp = realloc_p(loadparm.ServicePtrs, struct service *, num_to_alloc);
+               tsp = realloc_p(lp_ctx->ServicePtrs, struct loadparm_service *, 
+                               num_to_alloc);
                                           
                if (!tsp) {
                        DEBUG(0,("add_a_service: failed to enlarge ServicePtrs!\n"));
                        return NULL;
                }
                else {
-                       loadparm.ServicePtrs = tsp;
-                       loadparm.ServicePtrs[loadparm.iNumServices] = NULL;
+                       lp_ctx->ServicePtrs = tsp;
+                       lp_ctx->ServicePtrs[lp_ctx->iNumServices] = NULL;
                }
 
-               loadparm.iNumServices++;
+               lp_ctx->iNumServices++;
        } 
 
-       loadparm.ServicePtrs[i] = init_service(talloc_autofree_context());
-       if (loadparm.ServicePtrs[i] == NULL) {
+       lp_ctx->ServicePtrs[i] = init_service(talloc_autofree_context());
+       if (lp_ctx->ServicePtrs[i] == NULL) {
                DEBUG(0,("add_a_service: out of memory!\n"));
                return NULL;
        }
-       copy_service(loadparm.ServicePtrs[i], &tservice, NULL);
+       copy_service(lp_ctx->ServicePtrs[i], &tservice, NULL);
        if (name != NULL)
-               string_set(loadparm.ServicePtrs[i], &loadparm.ServicePtrs[i]->szService, name);
-       return loadparm.ServicePtrs[i];
+               string_set(lp_ctx->ServicePtrs[i], &lp_ctx->ServicePtrs[i]->szService, name);
+       return lp_ctx->ServicePtrs[i];
 }
 
 /***************************************************************************
@@ -1099,27 +1117,25 @@ static struct service *add_a_service(const struct service *pservice, const char
  from service ifrom.
 ***************************************************************************/
 
-bool lp_add_home(const char *pszHomename, struct service *default_service,
+bool lp_add_home(struct loadparm_context *lp_ctx, 
+                const char *pszHomename, 
+                struct loadparm_service *default_service,
                 const char *user, const char *pszHomedir)
 {
-       struct service *service;
-       pstring newHomedir;
+       struct loadparm_service *service;
 
-       service = add_a_service(default_service, pszHomename);
+       service = add_a_service(lp_ctx, default_service, pszHomename);
 
        if (service == NULL)
                return false;
 
        if (!(*(default_service->szPath))
            || strequal(default_service->szPath, sDefault.szPath)) {
-               pstrcpy(newHomedir, pszHomedir);
+               service->szPath = talloc_strdup(service, pszHomedir);
        } else {
-               pstrcpy(newHomedir, lp_pathname(default_service));
-               string_sub(newHomedir,"%H", pszHomedir, sizeof(newHomedir)); 
+               service->szPath = string_sub_talloc(service, lp_pathname(default_service),"%H", pszHomedir); 
        }
 
-       string_set(service, &service->szPath, newHomedir);
-
        if (!(*(service->comment))) {
                service->comment = talloc_asprintf(service, "Home directory of %s", user);
        }
@@ -1127,7 +1143,7 @@ bool lp_add_home(const char *pszHomename, struct service *default_service,
        service->bBrowseable = default_service->bBrowseable;
 
        DEBUG(3, ("adding home's share [%s] for user '%s' at '%s'\n", 
-                 pszHomename, user, newHomedir));
+                 pszHomename, user, service->szPath));
        
        return true;
 }
@@ -1136,19 +1152,21 @@ bool lp_add_home(const char *pszHomename, struct service *default_service,
  Add a new service, based on an old one.
 ***************************************************************************/
 
-struct service *lp_add_service(const char *pszService, 
-                              struct service *default_service)
+struct loadparm_service *lp_add_service(struct loadparm_context *lp_ctx, 
+                              const char *pszService, 
+                              struct loadparm_service *default_service)
 {
-       return add_a_service(default_service, pszService);
+       return add_a_service(lp_ctx, default_service, pszService);
 }
 
 /***************************************************************************
  Add the IPC service.
 ***************************************************************************/
 
-static bool lp_add_hidden(const char *name, const char *fstype)
+static bool lp_add_hidden(struct loadparm_context *lp_ctx, const char *name, 
+                         const char *fstype)
 {
-       struct service *service = add_a_service(&sDefault, name);
+       struct loadparm_service *service = add_a_service(lp_ctx, &sDefault, name);
 
        if (service == NULL)
                return false;
@@ -1156,7 +1174,7 @@ static bool lp_add_hidden(const char *name, const char *fstype)
        string_set(service, &service->szPath, tmpdir());
 
        service->comment = talloc_asprintf(service, "%s Service (%s)", 
-                               fstype, loadparm.Globals.szServerString);
+                               fstype, lp_ctx->Globals.szServerString);
        string_set(service, &service->fstype, fstype);
        service->iMaxConnections = -1;
        service->bAvailable = true;
@@ -1165,7 +1183,8 @@ static bool lp_add_hidden(const char *name, const char *fstype)
        service->bBrowseable = false;
 
        if (strcasecmp(fstype, "IPC") == 0) {
-               lp_do_service_parameter(service, "ntvfs handler", "default");
+               lp_do_service_parameter(lp_ctx, service, "ntvfs handler", 
+                                       "default");
        }
 
        DEBUG(3, ("adding hidden service %s\n", name));
@@ -1177,11 +1196,13 @@ static bool lp_add_hidden(const char *name, const char *fstype)
  Add a new printer service, with defaults coming from service iFrom.
 ***************************************************************************/
 
-bool lp_add_printer(const char *pszPrintername, struct service *default_service)
+bool lp_add_printer(struct loadparm_context *lp_ctx,
+                   const char *pszPrintername, 
+                   struct loadparm_service *default_service)
 {
        const char *comment = "From Printcap";
-       struct service *service;
-       service = add_a_service(default_service, pszPrintername);
+       struct loadparm_service *service;
+       service = add_a_service(lp_ctx, default_service, pszPrintername);
 
        if (service == NULL)
                return false;
@@ -1244,7 +1265,7 @@ struct parm_struct *lp_parm_struct(const char *name)
 /*
   return the parameter pointer for a parameter
 */
-void *lp_parm_ptr(struct service *service, struct parm_struct *parm)
+void *lp_parm_ptr(struct loadparm_service *service, struct parm_struct *parm)
 {
        if (service == NULL)
                return parm->ptr;
@@ -1256,14 +1277,15 @@ void *lp_parm_ptr(struct service *service, struct parm_struct *parm)
 Find a service by name. Otherwise works like get_service.
 ***************************************************************************/
 
-static struct service *getservicebyname(const char *pszServiceName)
+static struct loadparm_service *getservicebyname(struct loadparm_context *lp_ctx, 
+                                       const char *pszServiceName)
 {
        int iService;
 
-       for (iService = loadparm.iNumServices - 1; iService >= 0; iService--)
-               if (VALID(iService) &&
-                   strwicmp(loadparm.ServicePtrs[iService]->szService, pszServiceName) == 0) {
-                       return loadparm.ServicePtrs[iService];
+       for (iService = lp_ctx->iNumServices - 1; iService >= 0; iService--)
+               if (lp_ctx->ServicePtrs[iService] != NULL &&
+                   strwicmp(lp_ctx->ServicePtrs[iService]->szService, pszServiceName) == 0) {
+                       return lp_ctx->ServicePtrs[iService];
                }
 
        return NULL;
@@ -1274,8 +1296,8 @@ static struct service *getservicebyname(const char *pszServiceName)
  If pcopymapDest is NULL then copy all fields
 ***************************************************************************/
 
-static void copy_service(struct service *pserviceDest, 
-                        struct service *pserviceSource, 
+static void copy_service(struct loadparm_service *pserviceDest, 
+                        struct loadparm_service *pserviceSource, 
                         int *pcopymapDest)
 {
        int i;
@@ -1342,7 +1364,7 @@ static void copy_service(struct service *pserviceDest,
                while (pdata) {
                        /* If we already have same option, override it */
                        if (strcmp(pdata->key, data->key) == 0) {
-                               string_free(&pdata->value);
+                               talloc_free(pdata->value);
                                pdata->value = talloc_reference(pdata, 
                                                             data->value);
                                not_added = false;
@@ -1367,7 +1389,7 @@ Check a service for consistency. Return False if the service is in any way
 incomplete or faulty, else True.
 ***************************************************************************/
 
-static bool service_ok(struct service *service)
+static bool service_ok(struct loadparm_service *service)
 {
        bool bRetval;
 
@@ -1399,21 +1421,16 @@ static bool service_ok(struct service *service)
        return bRetval;
 }
 
-static struct file_lists {
-       struct file_lists *next;
-       char *name;
-       char *subfname;
-       time_t modtime;
-} *file_lists = NULL;
 
 /*******************************************************************
  Keep a linked list of all config files so we know when one has changed 
  it's date and needs to be reloaded.
 ********************************************************************/
 
-static void add_to_file_list(const char *fname, const char *subfname)
+static void add_to_file_list(struct loadparm_context *lp_ctx, 
+                            const char *fname, const char *subfname)
 {
-       struct file_lists *f = file_lists;
+       struct file_lists *f = lp_ctx->file_lists;
 
        while (f) {
                if (f->name && !strcmp(f->name, fname))
@@ -1425,7 +1442,7 @@ static void add_to_file_list(const char *fname, const char *subfname)
                f = talloc(talloc_autofree_context(), struct file_lists);
                if (!f)
                        return;
-               f->next = file_lists;
+               f->next = lp_ctx->file_lists;
                f->name = talloc_strdup(f, fname);
                if (!f->name) {
                        talloc_free(f);
@@ -1436,7 +1453,7 @@ static void add_to_file_list(const char *fname, const char *subfname)
                        talloc_free(f);
                        return;
                }
-               file_lists = f;
+               lp_ctx->file_lists = f;
                f->modtime = file_modtime(subfname);
        } else {
                time_t t = file_modtime(subfname);
@@ -1449,12 +1466,12 @@ static void add_to_file_list(const char *fname, const char *subfname)
  Check if a config file has changed date.
 ********************************************************************/
 
-bool lp_file_list_changed(void)
+bool lp_file_list_changed(struct loadparm_context *lp_ctx)
 {
        struct file_lists *f;
        DEBUG(6, ("lp_file_list_changed()\n"));
 
-       for (f = file_lists; f != NULL; f = f->next) {
+       for (f = lp_ctx->file_lists; f != NULL; f = f->next) {
                char *n2;
                time_t mod_time;
 
@@ -1481,17 +1498,18 @@ bool lp_file_list_changed(void)
  Handle the include operation.
 ***************************************************************************/
 
-static bool handle_include(const char *pszParmValue, char **ptr)
+static bool handle_include(struct loadparm_context *lp_ctx, 
+                          const char *pszParmValue, char **ptr)
 {
        char *fname = standard_sub_basic(talloc_autofree_context(), 
                                         pszParmValue);
 
-       add_to_file_list(pszParmValue, fname);
+       add_to_file_list(lp_ctx, pszParmValue, fname);
 
        string_set(talloc_autofree_context(), ptr, fname);
 
        if (file_exist(fname))
-               return pm_process(fname, do_section, do_parameter, NULL);
+               return pm_process(fname, do_section, do_parameter, lp_ctx);
 
        DEBUG(2, ("Can't find include file %s\n", fname));
 
@@ -1502,10 +1520,11 @@ static bool handle_include(const char *pszParmValue, char **ptr)
  Handle the interpretation of the copy parameter.
 ***************************************************************************/
 
-static bool handle_copy(const char *pszParmValue, char **ptr)
+static bool handle_copy(struct loadparm_context *lp_ctx, 
+                       const char *pszParmValue, char **ptr)
 {
        bool bRetval;
-       struct service *serviceTemp;
+       struct loadparm_service *serviceTemp;
 
        string_set(talloc_autofree_context(), ptr, pszParmValue);
 
@@ -1513,17 +1532,18 @@ static bool handle_copy(const char *pszParmValue, char **ptr)
 
        DEBUG(3, ("Copying service from service %s\n", pszParmValue));
 
-       if ((serviceTemp = getservicebyname(pszParmValue)) != NULL) {
-               if (serviceTemp == loadparm.currentService) {
+       if ((serviceTemp = getservicebyname(lp_ctx, pszParmValue)) != NULL) {
+               if (serviceTemp == lp_ctx->currentService) {
                        DEBUG(0, ("Can't copy service %s - unable to copy self!\n", pszParmValue));
                } else {
-                       copy_service(loadparm.currentService,
+                       copy_service(lp_ctx->currentService,
                                     serviceTemp,
-                                    loadparm.currentService->copymap);
+                                    lp_ctx->currentService->copymap);
                        bRetval = true;
                }
        } else {
-               DEBUG(0, ("Unable to copy service - source not found: %s\n", pszParmValue));
+               DEBUG(0, ("Unable to copy service - source not found: %s\n", 
+                         pszParmValue));
                bRetval = false;
        }
 
@@ -1534,7 +1554,7 @@ static bool handle_copy(const char *pszParmValue, char **ptr)
  Initialise a copymap.
 ***************************************************************************/
 
-static void init_copymap(struct service *pservice)
+static void init_copymap(struct loadparm_service *pservice)
 {
        int i;
        talloc_free(pservice->copymap);
@@ -1549,22 +1569,10 @@ static void init_copymap(struct service *pservice)
                pservice->copymap[i] = true;
 }
 
-#if 0 /* not used anywhere */
-/***************************************************************************
- Return the local pointer to a parameter given the service number and the 
- pointer into the default structure.
-***************************************************************************/
-
-void *lp_local_ptr(int snum, void *ptr)
-{
-       return (void *)(((char *)ServicePtrs[snum]) + PTR_DIFF(ptr, &sDefault));
-}
-#endif
-
 /***************************************************************************
  Process a parametric option
 ***************************************************************************/
-static bool lp_do_parameter_parametric(struct service *service, 
+static bool lp_do_parameter_parametric(struct loadparm_service *service, 
                                       const char *pszParmName, 
                                       const char *pszParmValue, int flags)
 {
@@ -1625,12 +1633,14 @@ static bool lp_do_parameter_parametric(struct service *service,
 }
 
 static bool set_variable(TALLOC_CTX *mem_ctx, int parmnum, void *parm_ptr, 
-                        const char *pszParmName, const char *pszParmValue)
+                        const char *pszParmName, const char *pszParmValue,
+                        struct loadparm_context *lp_ctx)
 {
        int i;
        /* if it is a special case then go ahead */
        if (parm_table[parmnum].special) {
-               parm_table[parmnum].special(pszParmValue, (char **)parm_ptr);
+               parm_table[parmnum].special(lp_ctx, pszParmValue, 
+                                           (char **)parm_ptr);
                return true;
        }
 
@@ -1747,10 +1757,11 @@ bool lp_do_global_parameter(struct loadparm_context *lp_ctx,
        parm_ptr = parm_table[parmnum].ptr;
 
        return set_variable(talloc_autofree_context(), parmnum, parm_ptr, 
-                           pszParmName, pszParmValue);
+                           pszParmName, pszParmValue, lp_ctx);
 }
 
-bool lp_do_service_parameter(struct service *service, 
+bool lp_do_service_parameter(struct loadparm_context *lp_ctx, 
+                            struct loadparm_service *service, 
                             const char *pszParmName, const char *pszParmValue)
 {
        void *def_ptr = NULL;
@@ -1797,24 +1808,7 @@ bool lp_do_service_parameter(struct service *service,
                        service->copymap[i] = false;
 
        return set_variable(service, parmnum, parm_ptr, pszParmName, 
-                           pszParmValue);
-}
-
-/***************************************************************************
- Process a parameter for a particular service number. If snum < 0
- then assume we are in the globals.
-***************************************************************************/
-bool lp_do_parameter(struct service *service, const char *pszParmName, 
-                    const char *pszParmValue)
-{
-       if (service == NULL) {
-               return lp_do_global_parameter(&loadparm, pszParmName, 
-                                             pszParmValue);
-       } else {
-               return lp_do_service_parameter(service,
-                                       pszParmName, pszParmValue);
-       }
-       return true;
+                           pszParmValue, lp_ctx);
 }
 
 /***************************************************************************
@@ -1824,11 +1818,13 @@ bool lp_do_parameter(struct service *service, const char *pszParmName,
 static bool do_parameter(const char *pszParmName, const char *pszParmValue, 
                         void *userdata)
 {
-       if (loadparm.bInGlobalSection) 
-               return lp_do_global_parameter(&loadparm, pszParmName, 
+       struct loadparm_context *lp_ctx = (struct loadparm_context *)userdata;
+
+       if (lp_ctx->bInGlobalSection) 
+               return lp_do_global_parameter(lp_ctx, pszParmName, 
                                              pszParmValue);
        else 
-               return lp_do_service_parameter(loadparm.currentService,
+               return lp_do_service_parameter(lp_ctx, lp_ctx->currentService,
                                               pszParmName, pszParmValue);
 }
 
@@ -1857,7 +1853,8 @@ bool lp_do_global_parameter_var(struct loadparm_context *lp_ctx,
   parsing code. It sets the parameter then marks the parameter as unable to be modified
   by smb.conf processing
 */
-bool lp_set_cmdline(const char *pszParmName, const char *pszParmValue)
+bool lp_set_cmdline(struct loadparm_context *lp_ctx, const char *pszParmName, 
+                   const char *pszParmValue)
 {
        int parmnum = map_parameter(pszParmName);
        int i;
@@ -1878,7 +1875,7 @@ bool lp_set_cmdline(const char *pszParmName, const char *pszParmValue)
        /* reset the CMDLINE flag in case this has been called before */
        parm_table[parmnum].flags &= ~FLAG_CMDLINE;
 
-       if (!lp_do_parameter(NULL, pszParmName, pszParmValue)) {
+       if (!lp_do_global_parameter(lp_ctx, pszParmName, pszParmValue)) {
                return false;
        }
 
@@ -1898,7 +1895,7 @@ bool lp_set_cmdline(const char *pszParmName, const char *pszParmValue)
 /*
   set a option from the commandline in 'a=b' format. Use to support --option
 */
-bool lp_set_option(const char *option)
+bool lp_set_option(struct loadparm_context *lp_ctx, const char *option)
 {
        char *p, *s;
        bool ret;
@@ -1916,7 +1913,7 @@ bool lp_set_option(const char *option)
 
        *p = 0;
 
-       ret = lp_set_cmdline(s, p+1);
+       ret = lp_set_cmdline(lp_ctx, s, p+1);
        free(s);
        return ret;
 }
@@ -2021,16 +2018,17 @@ static bool equal_parameter(parm_type type, void *ptr1, void *ptr2)
 
 static bool do_section(const char *pszSectionName, void *userdata)
 {
+       struct loadparm_context *lp_ctx = (struct loadparm_context *)userdata;
        bool bRetval;
        bool isglobal = ((strwicmp(pszSectionName, GLOBAL_NAME) == 0) ||
                         (strwicmp(pszSectionName, GLOBAL_NAME2) == 0));
        bRetval = false;
 
        /* if we've just struck a global section, note the fact. */
-       loadparm.bInGlobalSection = isglobal;
+       lp_ctx->bInGlobalSection = isglobal;
 
        /* check for multiple global sections */
-       if (loadparm.bInGlobalSection) {
+       if (lp_ctx->bInGlobalSection) {
                DEBUG(3, ("Processing section \"[%s]\"\n", pszSectionName));
                return true;
        }
@@ -2038,8 +2036,8 @@ static bool do_section(const char *pszSectionName, void *userdata)
        /* if we have a current service, tidy it up before moving on */
        bRetval = true;
 
-       if (loadparm.currentService != NULL)
-               bRetval = service_ok(loadparm.currentService);
+       if (lp_ctx->currentService != NULL)
+               bRetval = service_ok(lp_ctx->currentService);
 
        /* if all is still well, move to the next record in the services array */
        if (bRetval) {
@@ -2047,7 +2045,8 @@ 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 ((loadparm.currentService = add_a_service(&sDefault, pszSectionName))
+               if ((lp_ctx->currentService = add_a_service(lp_ctx, &sDefault, 
+                                                            pszSectionName))
                    == NULL) {
                        DEBUG(0, ("Failed to add a new service\n"));
                        return false;
@@ -2093,7 +2092,7 @@ static bool is_default(int i)
 Display the contents of the global structure.
 ***************************************************************************/
 
-static void dump_globals(FILE *f, bool show_defaults)
+static void dump_globals(struct loadparm_context *lp_ctx, FILE *f, bool show_defaults)
 {
        int i;
        struct param_opt *data;
@@ -2110,8 +2109,8 @@ static void dump_globals(FILE *f, bool show_defaults)
                        print_parameter(&parm_table[i], parm_table[i].ptr, f);
                        fprintf(f, "\n");
        }
-       if (loadparm.Globals.param_opt != NULL) {
-               for (data = loadparm.Globals.param_opt; data; 
+       if (lp_ctx->Globals.param_opt != NULL) {
+               for (data = lp_ctx->Globals.param_opt; data; 
                     data = data->next) {
                        fprintf(f, "\t%s = %s\n", data->key, data->value);
                }
@@ -2123,7 +2122,7 @@ static void dump_globals(FILE *f, bool show_defaults)
  Display the contents of a single services record.
 ***************************************************************************/
 
-static void dump_a_service(struct service * pService, FILE * f)
+static void dump_a_service(struct loadparm_service * pService, FILE * f)
 {
        int i;
        struct param_opt *data;
@@ -2162,9 +2161,10 @@ static void dump_a_service(struct service * pService, FILE * f)
         }
 }
 
-bool lp_dump_a_parameter(int snum, char *parm_name, FILE * f, bool isGlobal)
+bool lp_dump_a_parameter(struct loadparm_context *lp_ctx, int snum, char *parm_name, FILE * f, 
+                        bool isGlobal)
 {
-       struct service * pService = loadparm.ServicePtrs[snum];
+       struct loadparm_service * pService = lp_ctx->ServicePtrs[snum];
        struct parm_struct *parm;
        void *ptr;
        
@@ -2190,7 +2190,8 @@ bool lp_dump_a_parameter(int snum, char *parm_name, FILE * f, bool isGlobal)
  Return NULL when out of parameters.
 ***************************************************************************/
 
-struct parm_struct *lp_next_parameter(int snum, int *i, int allparameters)
+struct parm_struct *lp_next_parameter(struct loadparm_context *lp_ctx, int snum, int *i, 
+                                     int allparameters)
 {
        if (snum == -1) {
                /* do the globals */
@@ -2210,7 +2211,7 @@ struct parm_struct *lp_next_parameter(int snum, int *i, int allparameters)
                        return &parm_table[(*i)++];
                }
        } else {
-               struct service *pService = loadparm.ServicePtrs[snum];
+               struct loadparm_service *pService = lp_ctx->ServicePtrs[snum];
 
                for (; parm_table[*i].label; (*i)++) {
                        if (parm_table[*i].class == P_SEPARATOR)
@@ -2244,20 +2245,12 @@ struct parm_struct *lp_next_parameter(int snum, int *i, int allparameters)
 }
 
 
-/***************************************************************************
- Return TRUE if the passed service number is within range.
-***************************************************************************/
-
-bool lp_snum_ok(int iService)
-{
-       return (LP_SNUM_OK(iService) && loadparm.ServicePtrs[iService]->bAvailable);
-}
-
 /***************************************************************************
  Auto-load some home services.
 ***************************************************************************/
 
-static void lp_add_auto_services(const char *str)
+static void lp_add_auto_services(struct loadparm_context *lp_ctx, 
+                                const char *str)
 {
        return;
 }
@@ -2275,32 +2268,22 @@ bool lp_loaded(void)
  Unload unused services.
 ***************************************************************************/
 
-void lp_killunused(struct smbsrv_connection *smb, bool (*snumused) (struct smbsrv_connection *, int))
+void lp_killunused(struct loadparm_context *lp_ctx, 
+                  struct smbsrv_connection *smb, 
+                  bool (*snumused) (struct smbsrv_connection *, int))
 {
        int i;
-       for (i = 0; i < loadparm.iNumServices; i++) {
-               if (!VALID(i))
+       for (i = 0; i < lp_ctx->iNumServices; i++) {
+               if (lp_ctx->ServicePtrs[i] == NULL)
                        continue;
 
                if (!snumused || !snumused(smb, i)) {
-                       talloc_free(loadparm.ServicePtrs[i]);
-                       loadparm.ServicePtrs[i] = NULL;
+                       talloc_free(lp_ctx->ServicePtrs[i]);
+                       lp_ctx->ServicePtrs[i] = NULL;
                }
        }
 }
 
-/***************************************************************************
- Unload a service.
-***************************************************************************/
-
-void lp_killservice(int iServiceIn)
-{
-       if (VALID(iServiceIn)) {
-               talloc_free(loadparm.ServicePtrs[iServiceIn]);
-               loadparm.ServicePtrs[iServiceIn] = NULL;
-       }
-}
-
 /***************************************************************************
  Initialise the global parameter structure.
 ***************************************************************************/
@@ -2309,6 +2292,8 @@ bool loadparm_init(struct loadparm_context *lp_ctx)
        int i;
        char *myname;
 
+       lp_ctx->bInGlobalSection = true;
+
        DEBUG(3, ("Initialising global parameters\n"));
 
        for (i = 0; parm_table[i].label; i++) {
@@ -2321,8 +2306,6 @@ bool loadparm_init(struct loadparm_context *lp_ctx)
                }
        }
 
-       lp_do_global_parameter(lp_ctx, "config file", dyn_CONFIGFILE);
-
        lp_do_global_parameter(lp_ctx, "share backend", "classic");
        
        lp_do_global_parameter(lp_ctx, "server role", "standalone");
@@ -2438,8 +2421,7 @@ bool loadparm_init(struct loadparm_context *lp_ctx)
        lp_do_global_parameter(lp_ctx, "krb5 port", "88");
        lp_do_global_parameter(lp_ctx, "kpasswd port", "464");
        lp_do_global_parameter(lp_ctx, "web port", "901");
-       lp_do_global_parameter(lp_ctx, "web application directory", dyn_WEBAPPSDIR);
-       lp_do_global_parameter(lp_ctx, "jsonrpc services directory", dyn_SERVICESDIR);
+       lp_do_global_parameter(lp_ctx, "swat directory", dyn_SWATDIR);
 
        lp_do_global_parameter(lp_ctx, "nt status support", "True");
 
@@ -2468,52 +2450,57 @@ bool loadparm_init(struct loadparm_context *lp_ctx)
  False on failure.
 ***************************************************************************/
 
-bool lp_load(void)
+bool lp_load(const char *filename)
 {
        char *n2;
        bool bRetval;
        struct param_opt *data;
+       struct loadparm_context *lp_ctx = &loadparm;
 
-       bRetval = false;
+       filename = talloc_strdup(talloc_autofree_context(), filename);
+
+       global_loadparm = lp_ctx;
 
-       if (loadparm.Globals.param_opt != NULL) {
+       if (lp_ctx->Globals.param_opt != NULL) {
                struct param_opt *next;
-               for (data=loadparm.Globals.param_opt; data; data=next) {
+               for (data = lp_ctx->Globals.param_opt; data; data=next) {
                        next = data->next;
                        if (data->flags & FLAG_CMDLINE) continue;
-                       DLIST_REMOVE(loadparm.Globals.param_opt, data);
+                       DLIST_REMOVE(lp_ctx->Globals.param_opt, data);
                        talloc_free(data);
                }
        }
 
-       if (!loadparm_init(&loadparm))
+       if (!loadparm_init(lp_ctx))
                return false;
+
+       lp_ctx->Globals.szConfigFile = filename;
        
-       loadparm.bInGlobalSection = true;
-       n2 = standard_sub_basic(talloc_autofree_context(), lp_configfile());
+       lp_ctx->bInGlobalSection = true;
+       n2 = standard_sub_basic(talloc_autofree_context(), lp_ctx->Globals.szConfigFile);
        DEBUG(2, ("lp_load: refreshing parameters from %s\n", n2));
        
-       add_to_file_list(lp_configfile(), n2);
+       add_to_file_list(lp_ctx, lp_ctx->Globals.szConfigFile, n2);
 
        /* We get sections first, so have to start 'behind' to make up */
-       loadparm.currentService = NULL;
-       bRetval = pm_process(n2, do_section, do_parameter, NULL);
+       lp_ctx->currentService = NULL;
+       bRetval = pm_process(n2, do_section, do_parameter, lp_ctx);
 
        /* finish up the last section */
        DEBUG(4, ("pm_process() returned %s\n", BOOLSTR(bRetval)));
        if (bRetval)
-               if (loadparm.currentService != NULL)
-                       bRetval = service_ok(loadparm.currentService);
+               if (lp_ctx->currentService != NULL)
+                       bRetval = service_ok(lp_ctx->currentService);
 
-       lp_add_auto_services(lp_auto_services());
+       lp_add_auto_services(lp_ctx, lp_auto_services(lp_ctx));
 
-       lp_add_hidden("IPC$", "IPC");
-       lp_add_hidden("ADMIN$", "DISK");
+       lp_add_hidden(lp_ctx, "IPC$", "IPC");
+       lp_add_hidden(lp_ctx, "ADMIN$", "DISK");
 
        bLoaded = true;
 
-       if (!loadparm.Globals.szWINSservers && loadparm.Globals.bWINSsupport) {
-               lp_do_parameter(NULL, "wins server", "127.0.0.1");
+       if (!lp_ctx->Globals.szWINSservers && lp_ctx->Globals.bWINSsupport) {
+               lp_do_global_parameter(lp_ctx, "wins server", "127.0.0.1");
        }
 
        init_iconv();
@@ -2525,35 +2512,36 @@ bool lp_load(void)
  Return the max number of services.
 ***************************************************************************/
 
-int lp_numservices(void)
+int lp_numservices(struct loadparm_context *lp_ctx)
 {
-       return loadparm.iNumServices;
+       return lp_ctx->iNumServices;
 }
 
 /***************************************************************************
 Display the contents of the services array in human-readable form.
 ***************************************************************************/
 
-void lp_dump(FILE *f, bool show_defaults, int maxtoprint)
+void lp_dump(struct loadparm_context *lp_ctx, FILE *f, bool show_defaults, 
+            int maxtoprint)
 {
        int iService;
 
        if (show_defaults)
                defaults_saved = false;
 
-       dump_globals(f, show_defaults);
+       dump_globals(lp_ctx, f, show_defaults);
 
        dump_a_service(&sDefault, f);
 
        for (iService = 0; iService < maxtoprint; iService++)
-               lp_dump_one(f, show_defaults, loadparm.ServicePtrs[iService]);
+               lp_dump_one(f, show_defaults, lp_ctx->ServicePtrs[iService]);
 }
 
 /***************************************************************************
 Display the contents of one service in human-readable form.
 ***************************************************************************/
 
-void lp_dump_one(FILE *f, bool show_defaults, struct service *service)
+void lp_dump_one(FILE *f, bool show_defaults, struct loadparm_service *service)
 {
        if (service != NULL) {
                if (service->szService[0] == '\0')
@@ -2562,73 +2550,42 @@ void lp_dump_one(FILE *f, bool show_defaults, struct service *service)
        }
 }
 
-struct service *lp_servicebynum(int snum)
-{
-       return loadparm.ServicePtrs[snum];
-}
-
-struct service *lp_service(const char *service_name)
+struct loadparm_service *lp_servicebynum(struct loadparm_context *lp_ctx,
+                                        int snum)
 {
-       int snum = lp_servicenumber(service_name);
-       if (snum < 0)
-               return NULL;
-       return loadparm.ServicePtrs[snum];
+       return lp_ctx->ServicePtrs[snum];
 }
 
-/***************************************************************************
-Return the number of the service with the given name, or -1 if it doesn't
-exist. Note that this is a DIFFERENT ANIMAL from the internal function
-getservicebyname()! This works ONLY if all services have been loaded, and
-does not copy the found service.
-***************************************************************************/
-
-int lp_servicenumber(const char *pszServiceName)
+struct loadparm_service *lp_service(struct loadparm_context *lp_ctx, 
+                                   const char *service_name)
 {
        int iService;
         char *serviceName;
  
-       for (iService = loadparm.iNumServices - 1; iService >= 0; iService--) {
-               if (VALID(iService) && loadparm.ServicePtrs[iService]->szService) {
+       for (iService = lp_ctx->iNumServices - 1; iService >= 0; iService--) {
+               if (lp_ctx->ServicePtrs[iService] && 
+                   lp_ctx->ServicePtrs[iService]->szService) {
                        /*
                         * The substitution here is used to support %U is
                         * service names
                         */
-                       serviceName = standard_sub_basic(loadparm.ServicePtrs[iService],
-                                                        loadparm.ServicePtrs[iService]->szService);
-                       if (strequal(serviceName, pszServiceName))
-                               break;
+                       serviceName = standard_sub_basic(
+                                       lp_ctx->ServicePtrs[iService],
+                                       lp_ctx->ServicePtrs[iService]->szService);
+                       if (strequal(serviceName, service_name))
+                               return lp_ctx->ServicePtrs[iService];
                }
        }
 
-       if (iService < 0)
-               DEBUG(7,("lp_servicenumber: couldn't find %s\n", pszServiceName));
-
-       return iService;
+       DEBUG(7,("lp_servicenumber: couldn't find %s\n", service_name));
+       return NULL;
 }
 
-int lp_find_valid_service(const char *pszServiceName)
-{
-       int iService;
-
-       iService = lp_servicenumber(pszServiceName);
-
-       if (iService >= 0 && !lp_snum_ok(iService)) {
-               DEBUG(0,("lp_find_valid_service: Invalid snum %d for '%s'\n",iService, pszServiceName));
-               iService = -1;
-       }
-
-       if (iService == -1) {
-               DEBUG(3,("lp_find_valid_service: failed to find service '%s'\n", pszServiceName));
-       }
-
-       return iService;
-}
 
 /*******************************************************************
  A useful volume label function. 
 ********************************************************************/
-const char *volume_label(struct service *service)
+const char *volume_label(struct loadparm_service *service)
 {
        const char *ret = lp_volume(service);
        if (!*ret)
@@ -2641,21 +2598,12 @@ const char *volume_label(struct service *service)
  If we are PDC then prefer us as DMB
 ************************************************************/
 
-bool lp_domain_logons(void)
-{
-       return (lp_server_role() == ROLE_DOMAIN_CONTROLLER);
-}
-
-/*******************************************************************
- Remove a service.
-********************************************************************/
-
-void lp_remove_service(int snum)
+bool lp_domain_logons(struct loadparm_context *lp_ctx)
 {
-       loadparm.ServicePtrs[snum] = NULL;
+       return (lp_server_role(lp_ctx) == ROLE_DOMAIN_CONTROLLER);
 }
 
-const char *lp_printername(struct service *service)
+const char *lp_printername(struct loadparm_service *service)
 {
        const char *ret = _lp_printername(service);
        if (ret == NULL || (ret != NULL && *ret == '\0'))
@@ -2669,9 +2617,9 @@ const char *lp_printername(struct service *service)
  Return the max print jobs per queue.
 ********************************************************************/
 
-int lp_maxprintjobs(int snum)
+int lp_maxprintjobs(struct loadparm_service *service)
 {
-       int maxjobs = LP_SNUM_OK(snum) ? loadparm.ServicePtrs[snum]->iMaxPrintJobs : sDefault.iMaxPrintJobs;
+       int maxjobs = (service != NULL) ? service->iMaxPrintJobs : sDefault.iMaxPrintJobs;
        if (maxjobs <= 0 || maxjobs >= PRINT_MAX_JOBID)
                maxjobs = PRINT_MAX_JOBID - 1;