#include "smb_server/smb_server.h"
#include "libcli/raw/signing.h"
#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 do_parameter_var(const char *pszParmName, const char *fmt, ...);
-
static bool defaults_saved = false;
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;
char *szServerString;
char *szAutoServices;
char *szPasswdChat;
- char *szConfigFile;
+ const char *szConfigFile;
char *szShareBackend;
char *szSAM_URL;
char *szSECRETS_URL;
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;
/*
* This structure describes a single service.
*/
-struct service
+struct loadparm_service
{
char *szService;
char *szPath;
/* 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 */
1000, /* iMaxPrintJobs */
0, /* iMaxConnections */
0, /* iCSCPolicy */
- True, /* bAvailable */
- True, /* bBrowseable */
- True, /* bRead_only */
- False, /* bPrint_ok */
- False, /* bMap_system */
- False, /* bMap_hidden */
- True, /* bMap_archive */
- True, /* bStrictLocking */
+ true, /* bAvailable */
+ true, /* bBrowseable */
+ true, /* bRead_only */
+ false, /* bPrint_ok */
+ false, /* bMap_system */
+ false, /* bMap_hidden */
+ true, /* bMap_archive */
+ true, /* bStrictLocking */
0744, /* iCreate_mask */
0000, /* iCreate_force_mode */
0755, /* iDir_mask */
0000, /* iDir_force_mode */
NULL, /* copymap */
- False, /* bMSDfsRoot */
- False, /* bStrictSync */
- False, /* bCIFileSystem */
+ false, /* bMSDfsRoot */
+ false, /* bStrictSync */
+ false, /* bCIFileSystem */
NULL, /* Parametric options */
"" /* dummy */
/* local variables */
static struct loadparm_context {
- struct global Globals;
- struct service **ServicePtrs;
+ struct loadparm_global Globals;
+ struct loadparm_service **ServicePtrs;
int iNumServices;
- int iServiceIndex;
+ struct loadparm_service *currentService;
bool bInGlobalSection;
-} loadparm = {
- .iNumServices = 0,
- .iServiceIndex = 0,
- .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"},
};
static const struct enum_list enum_bool_auto[] = {
- {False, "No"},
- {False, "False"},
- {False, "0"},
- {True, "Yes"},
- {True, "True"},
- {True, "1"},
+ {false, "No"},
+ {false, "False"},
+ {false, "0"},
+ {true, "Yes"},
+ {true, "True"},
+ {true, "1"},
{Auto, "Auto"},
{-1, NULL}
};
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},
{"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},
{"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},
{"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},
return parm_table;
}
-/***************************************************************************
- Initialise the global parameter structure.
-***************************************************************************/
-static void init_globals(void)
-{
- int i;
- char *myname;
-
- DEBUG(3, ("Initialising global parameters\n"));
-
- for (i = 0; parm_table[i].label; i++) {
- if ((parm_table[i].type == P_STRING ||
- parm_table[i].type == P_USTRING) &&
- parm_table[i].ptr &&
- !(parm_table[i].flags & FLAG_CMDLINE)) {
- string_set(talloc_autofree_context(),
- parm_table[i].ptr, "");
- }
- }
-
- do_parameter("config file", dyn_CONFIGFILE, NULL);
-
- do_parameter("share backend", "classic", NULL);
-
- do_parameter("server role", "standalone", NULL);
-
- /* options that can be set on the command line must be initialised via
- the slower do_parameter() to ensure that FLAG_CMDLINE is obeyed */
-#ifdef TCP_NODELAY
- do_parameter("socket options", "TCP_NODELAY", NULL);
-#endif
- do_parameter("workgroup", DEFAULT_WORKGROUP, NULL);
- myname = get_myname();
- do_parameter("netbios name", myname, NULL);
- SAFE_FREE(myname);
- do_parameter("name resolve order", "lmhosts wins host bcast", NULL);
-
- do_parameter("fstype", FSTYPE_STRING, NULL);
- do_parameter("ntvfs handler", "unixuid default", NULL);
- do_parameter("max connections", "-1", NULL);
-
- do_parameter("dcerpc endpoint servers", "epmapper srvsvc wkssvc rpcecho samr netlogon lsarpc spoolss drsuapi winreg dssetup unixinfo", NULL);
- do_parameter("server services", "smb rpc nbt wrepl ldap cldap web kdc drepl winbind", NULL);
- do_parameter("ntptr providor", "simple_ldb", NULL);
- do_parameter("auth methods:domain controller", "anonymous sam_ignoredomain", NULL);
- do_parameter("auth methods:member server", "anonymous sam winbind", NULL);
- do_parameter("auth methods:standalone", "anonymous sam_ignoredomain", NULL);
- do_parameter("private dir", dyn_PRIVATE_DIR, NULL);
- do_parameter("sam database", "sam.ldb", NULL);
- do_parameter("secrets database", "secrets.ldb", NULL);
- do_parameter("spoolss database", "spoolss.ldb", NULL);
- do_parameter("wins config database", "wins_config.ldb", NULL);
- do_parameter("wins database", "wins.ldb", NULL);
- do_parameter("registry:HKEY_LOCAL_MACHINE", "hklm.ldb", NULL);
-
- /* This hive should be dynamically generated by Samba using
- data from the sam, but for the moment leave it in a tdb to
- keep regedt32 from popping up an annoying dialog. */
- do_parameter("registry:HKEY_USERS", "hku.ldb", NULL);
-
- /* using UTF8 by default allows us to support all chars */
- do_parameter("unix charset", "UTF8", NULL);
-
- /* Use codepage 850 as a default for the dos character set */
- do_parameter("dos charset", "CP850", NULL);
-
- /*
- * Allow the default PASSWD_CHAT to be overridden in local.h.
- */
- do_parameter("passwd chat", DEFAULT_PASSWD_CHAT, NULL);
-
- do_parameter("pid directory", dyn_PIDDIR, NULL);
- do_parameter("lock dir", dyn_LOCKDIR, NULL);
- do_parameter("modules dir", dyn_MODULESDIR, NULL);
- do_parameter("ncalrpc dir", dyn_NCALRPCDIR, NULL);
-
- do_parameter("socket address", "0.0.0.0", NULL);
- do_parameter_var("server string", "Samba %s", SAMBA_VERSION_STRING);
-
- do_parameter_var("announce version", "%d.%d",
- DEFAULT_MAJOR_VERSION,
- DEFAULT_MINOR_VERSION);
-
- do_parameter("password server", "*", NULL);
-
- do_parameter("max mux", "50", NULL);
- do_parameter("max xmit", "12288", NULL);
- do_parameter("password level", "0", NULL);
- do_parameter("LargeReadwrite", "True", NULL);
- do_parameter("server min protocol", "CORE", NULL);
- do_parameter("server max protocol", "NT1", NULL);
- do_parameter("client min protocol", "CORE", NULL);
- do_parameter("client max protocol", "NT1", NULL);
- do_parameter("security", "USER", NULL);
- do_parameter("paranoid server security", "True", NULL);
- do_parameter("EncryptPasswords", "True", NULL);
- do_parameter("ReadRaw", "True", NULL);
- do_parameter("WriteRaw", "True", NULL);
- do_parameter("NullPasswords", "False", NULL);
- do_parameter("ObeyPamRestrictions", "False", NULL);
- do_parameter("announce as", "NT SERVER", NULL);
-
- do_parameter("TimeServer", "False", NULL);
- do_parameter("BindInterfacesOnly", "False", NULL);
- do_parameter("Unicode", "True", NULL);
- do_parameter("ClientLanManAuth", "True", NULL);
- do_parameter("LanmanAuth", "True", NULL);
- do_parameter("NTLMAuth", "True", NULL);
- do_parameter("client use spnego principal", "False", NULL);
-
- do_parameter("UnixExtensions", "False", NULL);
-
- do_parameter("PreferredMaster", "Auto", NULL);
- do_parameter("LocalMaster", "True", NULL);
-
- do_parameter("wins support", "False", NULL);
- do_parameter("dns proxy", "True", NULL);
-
- do_parameter("winbind separator", "\\", NULL);
- do_parameter("winbind sealed pipes", "True", NULL);
- do_parameter("winbindd socket directory", dyn_WINBINDD_SOCKET_DIR, NULL);
- do_parameter("template shell", "/bin/false", NULL);
- do_parameter("template homedir", "/home/%WORKGROUP%/%ACCOUNTNAME%", NULL);
-
- do_parameter("client signing", "Yes", NULL);
- do_parameter("server signing", "auto", NULL);
-
- do_parameter("use spnego", "True", NULL);
-
- do_parameter("smb ports", "445 139", NULL);
- do_parameter("nbt port", "137", NULL);
- do_parameter("dgram port", "138", NULL);
- do_parameter("cldap port", "389", NULL);
- do_parameter("krb5 port", "88", NULL);
- do_parameter("kpasswd port", "464", NULL);
- do_parameter("web port", "901", NULL);
- do_parameter("web application directory", dyn_WEBAPPSDIR, NULL);
- do_parameter("jsonrpc services directory", dyn_SERVICESDIR, NULL);
-
- do_parameter("nt status support", "True", NULL);
-
- do_parameter("max wins ttl", "518400", NULL); /* 6 days */
- do_parameter("min wins ttl", "10", NULL);
-
- do_parameter("tls enabled", "True", NULL);
- do_parameter("tls keyfile", "tls/key.pem", NULL);
- do_parameter("tls certfile", "tls/cert.pem", NULL);
- do_parameter("tls cafile", "tls/ca.pem", NULL);
- do_parameter_var("js include", "%s", dyn_JSDIR);
- do_parameter_var("setup directory", "%s", dyn_SETUPDIR);
-
- for (i = 0; parm_table[i].label; i++) {
- if (!(parm_table[i].flags & FLAG_CMDLINE)) {
- parm_table[i].flags |= FLAG_DEFAULT;
- }
- }
-}
-
static TALLOC_CTX *lp_talloc;
/******************************************************************* a
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(int i) {return(lp_string((LP_SNUM_OK(i) && loadparm.ServicePtrs[(i)]->val) ? loadparm.ServicePtrs[(i)]->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(int i) {return (const char *)((LP_SNUM_OK(i) && loadparm.ServicePtrs[(i)]->val) ? loadparm.ServicePtrs[(i)]->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(int i) {return(const char **)(LP_SNUM_OK(i)? loadparm.ServicePtrs[(i)]->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(int i) {return(LP_SNUM_OK(i)? loadparm.ServicePtrs[(i)]->val : sDefault.val);}
-#if 0 /* unused */
-#define FN_LOCAL_CHAR(fn_name,val) \
- char fn_name(int i) {return(LP_SNUM_OK(i)? ServicePtrs[(i)]->val : sDefault.val);}
-#endif
+ bool fn_name(struct loadparm_service *service) {return((service != NULL)? service->val : sDefault.val);}
#define FN_LOCAL_INTEGER(fn_name,val) \
- int fn_name(int i) {return(LP_SNUM_OK(i)? loadparm.ServicePtrs[(i)]->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)
_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 int getservicebyname(const char *pszServiceName,
- struct service * pserviceDest);
-static void copy_service(struct service * pserviceDest,
- struct service * pserviceSource, int *pcopymapDest);
-static bool service_ok(int iService);
+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(int lookup_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;
- if (lookup_service >= 0 && !LP_SNUM_OK(lookup_service))
- return NULL;
-
- data = (lookup_service < 0) ?
- loadparm.Globals.param_opt : loadparm.ServicePtrs[lookup_service]->param_opt;
+ data = (service == NULL ? loadparm.Globals.param_opt : service->param_opt);
asprintf(&vfskey, "%s:%s", type, option);
strlower(vfskey);
data = data->next;
}
- if (lookup_service >= 0) {
+ if (service != NULL) {
/* Try to fetch the same option but from globals */
/* but only if we are not already working with Globals */
for (data = loadparm.Globals.param_opt; data;
/* Parametric option has following syntax: 'Type: option = value' */
/* Returned value is allocated in 'lp_talloc' context */
-const char *lp_parm_string(int lookup_service, const char *type, const char *option)
+const char *lp_parm_string(struct loadparm_service *service, const char *type,
+ const char *option)
{
- const char *value = lp_get_parametric(lookup_service, type, option);
+ const char *value = lp_get_parametric(service, type, option);
if (value)
return lp_string(value);
/* Parametric option has following syntax: 'Type: option = value' */
/* Returned value is allocated in 'lp_talloc' context */
-const char **lp_parm_string_list(int lookup_service, const char *type, const char *option,
- const char *separator)
+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(lookup_service, type, option);
+ 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;
}
/* 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(int lookup_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(lookup_service, type, option);
+ const char *value = lp_get_parametric(service, type, option);
if (value)
return lp_int(value);
* Parametric option has following syntax: 'Type: option = value'.
*/
-int lp_parm_bytes(int lookup_service, const char *type, const char *option, int default_v)
+int lp_parm_bytes(struct loadparm_service *service, const char *type,
+ const char *option, int default_v)
{
uint64_t bval;
- const char *value = lp_get_parametric(lookup_service, type, option);
+ const char *value = lp_get_parametric(service, type, option);
if (value && conv_str_size(value, &bval)) {
if (bval <= INT_MAX) {
/* 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(int lookup_service, const char *type, const char *option, unsigned long default_v)
+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(lookup_service, type, option);
+ const char *value = lp_get_parametric(service, type, option);
if (value)
return lp_ulong(value);
}
-double lp_parm_double(int lookup_service, const char *type, const char *option, double default_v)
+double lp_parm_double(struct loadparm_service *service, const char *type,
+ const char *option, double default_v)
{
- const char *value = lp_get_parametric(lookup_service, type, option);
+ const char *value = lp_get_parametric(service, type, option);
if (value)
return lp_double(value);
/* 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(int lookup_service, const char *type, const char *option,
- bool default_v)
+bool lp_parm_bool(struct loadparm_service *service, const char *type,
+ const char *option, bool default_v)
{
- const char *value = lp_get_parametric(lookup_service, type, option);
+ const char *value = lp_get_parametric(service, type, option);
if (value)
return lp_bool(value);
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 int 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) {
- i = getservicebyname(name, NULL);
- if (i >= 0) {
+ struct loadparm_service *service = getservicebyname(lp_ctx,
+ name);
+ if (service != NULL) {
/* Clean all parametric options for service */
/* They will be added during parsing again */
- data = loadparm.ServicePtrs[i]->param_opt;
+ data = service->param_opt;
while (data) {
pdata = data->next;
talloc_free(data);
data = pdata;
}
- loadparm.ServicePtrs[i]->param_opt = NULL;
- return i;
+ service->param_opt = NULL;
+ return service;
}
}
/* 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 -1;
+ 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 -1;
+ 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 i;
+ string_set(lp_ctx->ServicePtrs[i], &lp_ctx->ServicePtrs[i]->szService, name);
+ return lp_ctx->ServicePtrs[i];
}
/***************************************************************************
from service ifrom.
***************************************************************************/
-bool lp_add_home(const char *pszHomename, int iDefaultService,
+bool lp_add_home(struct loadparm_context *lp_ctx,
+ const char *pszHomename,
+ struct loadparm_service *default_service,
const char *user, const char *pszHomedir)
{
- int i;
- pstring newHomedir;
+ struct loadparm_service *service;
- i = add_a_service(loadparm.ServicePtrs[iDefaultService], pszHomename);
+ service = add_a_service(lp_ctx, default_service, pszHomename);
- if (i < 0)
+ if (service == NULL)
return false;
- if (!(*(loadparm.ServicePtrs[iDefaultService]->szPath))
- || strequal(loadparm.ServicePtrs[iDefaultService]->szPath, lp_pathname(-1))) {
- pstrcpy(newHomedir, pszHomedir);
+ if (!(*(default_service->szPath))
+ || strequal(default_service->szPath, sDefault.szPath)) {
+ service->szPath = talloc_strdup(service, pszHomedir);
} else {
- pstrcpy(newHomedir, lp_pathname(iDefaultService));
- string_sub(newHomedir,"%H", pszHomedir, sizeof(newHomedir));
+ service->szPath = string_sub_talloc(service, lp_pathname(default_service),"%H", pszHomedir);
}
- string_set(loadparm.ServicePtrs[i], &loadparm.ServicePtrs[i]->szPath, newHomedir);
-
- if (!(*(loadparm.ServicePtrs[i]->comment))) {
- loadparm.ServicePtrs[i]->comment = talloc_asprintf(loadparm.ServicePtrs[i], "Home directory of %s", user);
+ if (!(*(service->comment))) {
+ service->comment = talloc_asprintf(service, "Home directory of %s", user);
}
- loadparm.ServicePtrs[i]->bAvailable = sDefault.bAvailable;
- loadparm.ServicePtrs[i]->bBrowseable = sDefault.bBrowseable;
+ service->bAvailable = default_service->bAvailable;
+ service->bBrowseable = default_service->bBrowseable;
- DEBUG(3, ("adding home's share [%s] for user '%s' at '%s'\n", pszHomename,
- user, newHomedir));
+ DEBUG(3, ("adding home's share [%s] for user '%s' at '%s'\n",
+ pszHomename, user, service->szPath));
return true;
}
Add a new service, based on an old one.
***************************************************************************/
-int lp_add_service(const char *pszService, int iDefaultService)
+struct loadparm_service *lp_add_service(struct loadparm_context *lp_ctx,
+ const char *pszService,
+ struct loadparm_service *default_service)
{
- return add_a_service(loadparm.ServicePtrs[iDefaultService], 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)
{
- int i = add_a_service(&sDefault, name);
- struct service *service = loadparm.ServicePtrs[i];
+ struct loadparm_service *service = add_a_service(lp_ctx, &sDefault, name);
- if (i < 0)
+ if (service == NULL)
return false;
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;
service->bBrowseable = false;
if (strcasecmp(fstype, "IPC") == 0) {
- lp_do_parameter(i, "ntvfs handler", "default");
+ lp_do_service_parameter(lp_ctx, service, "ntvfs handler",
+ "default");
}
DEBUG(3, ("adding hidden service %s\n", name));
Add a new printer service, with defaults coming from service iFrom.
***************************************************************************/
-bool lp_add_printer(const char *pszPrintername, int iDefaultService)
+bool lp_add_printer(struct loadparm_context *lp_ctx,
+ const char *pszPrintername,
+ struct loadparm_service *default_service)
{
const char *comment = "From Printcap";
- int i = add_a_service(loadparm.ServicePtrs[iDefaultService],
- pszPrintername);
+ struct loadparm_service *service;
+ service = add_a_service(lp_ctx, default_service, pszPrintername);
- if (i < 0)
+ if (service == NULL)
return false;
/* note that we do NOT default the availability flag to True - */
/* entry (if/when the 'available' keyword is implemented!). */
/* the printer name is set to the service name. */
- string_set(loadparm.ServicePtrs[i], &loadparm.ServicePtrs[i]->szPrintername,
- pszPrintername);
- string_set(loadparm.ServicePtrs[i], &loadparm.ServicePtrs[i]->comment, comment);
- loadparm.ServicePtrs[i]->bBrowseable = sDefault.bBrowseable;
+ string_set(service, &service->szPrintername, pszPrintername);
+ string_set(service, &service->comment, comment);
+ service->bBrowseable = sDefault.bBrowseable;
/* Printers cannot be read_only. */
- loadparm.ServicePtrs[i]->bRead_only = False;
+ service->bRead_only = false;
/* Printer services must be printable. */
- loadparm.ServicePtrs[i]->bPrint_ok = True;
+ service->bPrint_ok = true;
DEBUG(3, ("adding printer service %s\n", pszPrintername));
/*
return the parameter pointer for a parameter
*/
-void *lp_parm_ptr(int snum, struct parm_struct *parm)
+void *lp_parm_ptr(struct loadparm_service *service, struct parm_struct *parm)
{
- if (snum == -1) {
+ if (service == NULL)
return parm->ptr;
- }
- return ((char *)loadparm.ServicePtrs[snum]) + PTR_DIFF(parm->ptr, &sDefault);
+
+ return ((char *)service) + PTR_DIFF(parm->ptr, &sDefault);
}
/***************************************************************************
Find a service by name. Otherwise works like get_service.
***************************************************************************/
-static int getservicebyname(const char *pszServiceName,
- struct service * pserviceDest)
+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) {
- if (pserviceDest != NULL)
- copy_service(pserviceDest, loadparm.ServicePtrs[iService], NULL);
- break;
+ 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 iService;
+ return NULL;
}
/***************************************************************************
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;
break;
case P_STRING:
- string_set(pserviceDest, dest_ptr,
+ string_set(pserviceDest,
+ (char **)dest_ptr,
*(char **)src_ptr);
break;
case P_USTRING:
- string_set(pserviceDest, dest_ptr,
+ string_set(pserviceDest,
+ (char **)dest_ptr,
*(char **)src_ptr);
strupper(*(char **)dest_ptr);
break;
data = pserviceSource->param_opt;
while (data) {
- not_added = True;
+ not_added = true;
pdata = pserviceDest->param_opt;
/* Traverse destination */
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;
incomplete or faulty, else True.
***************************************************************************/
-static bool service_ok(int iService)
+static bool service_ok(struct loadparm_service *service)
{
bool bRetval;
bRetval = true;
- if (loadparm.ServicePtrs[iService]->szService[0] == '\0') {
+ if (service->szService[0] == '\0') {
DEBUG(0, ("The following message indicates an internal error:\n"));
DEBUG(0, ("No service name in service entry.\n"));
bRetval = false;
/* The [printers] entry MUST be printable. I'm all for flexibility, but */
/* I can't see why you'd want a non-printable printer service... */
- if (strwicmp(loadparm.ServicePtrs[iService]->szService, PRINTERS_NAME) == 0) {
- if (!loadparm.ServicePtrs[iService]->bPrint_ok) {
+ if (strwicmp(service->szService, PRINTERS_NAME) == 0) {
+ if (!service->bPrint_ok) {
DEBUG(0, ("WARNING: [%s] service MUST be printable!\n",
- loadparm.ServicePtrs[iService]->szService));
- loadparm.ServicePtrs[iService]->bPrint_ok = True;
+ service->szService));
+ service->bPrint_ok = true;
}
/* [printers] service must also be non-browsable. */
- if (loadparm.ServicePtrs[iService]->bBrowseable)
- loadparm.ServicePtrs[iService]->bBrowseable = False;
+ if (service->bBrowseable)
+ service->bBrowseable = false;
}
/* If a service is flagged unavailable, log the fact at level 0. */
- if (!loadparm.ServicePtrs[iService]->bAvailable)
+ if (!service->bAvailable)
DEBUG(1, ("NOTE: Service %s is flagged unavailable.\n",
- loadparm.ServicePtrs[iService]->szService));
+ service->szService));
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))
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);
talloc_free(f);
return;
}
- file_lists = f;
+ lp_ctx->file_lists = f;
f->modtime = file_modtime(subfname);
} else {
time_t t = file_modtime(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 = file_lists;
+ struct file_lists *f;
DEBUG(6, ("lp_file_list_changed()\n"));
- while (f) {
+ for (f = lp_ctx->file_lists; f != NULL; f = f->next) {
char *n2;
time_t mod_time;
mod_time = file_modtime(n2);
if (mod_time && ((f->modtime != mod_time) || (f->subfname == NULL) || (strcmp(n2, f->subfname) != 0))) {
- DEBUGADD(6,
- ("file %s modified: %s\n", n2,
+ DEBUGADD(6, ("file %s modified: %s\n", n2,
ctime(&mod_time)));
f->modtime = mod_time;
talloc_free(f->subfname);
f->subfname = talloc_strdup(f, n2);
return true;
}
- f = f->next;
}
return false;
}
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));
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;
- int iTemp;
- struct service *serviceTemp;
+ struct loadparm_service *serviceTemp;
string_set(talloc_autofree_context(), ptr, pszParmValue);
- serviceTemp = init_service(talloc_autofree_context());
-
bRetval = false;
DEBUG(3, ("Copying service from service %s\n", pszParmValue));
- if ((iTemp = getservicebyname(pszParmValue, serviceTemp)) >= 0) {
- if (iTemp == loadparm.iServiceIndex) {
+ 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.ServicePtrs[loadparm.iServiceIndex],
+ copy_service(lp_ctx->currentService,
serviceTemp,
- loadparm.ServicePtrs[loadparm.iServiceIndex]->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;
}
- talloc_free(serviceTemp);
return bRetval;
}
Initialise a copymap.
***************************************************************************/
-static void init_copymap(struct service *pservice)
+static void init_copymap(struct loadparm_service *pservice)
{
int i;
talloc_free(pservice->copymap);
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(int snum, const char *pszParmName,
+static bool lp_do_parameter_parametric(struct loadparm_service *service,
+ const char *pszParmName,
const char *pszParmValue, int flags)
{
struct param_opt *paramo, *data;
}
name = strdup(pszParmName);
- if (!name) return False;
+ if (!name) return false;
strlower(name);
- if (snum < 0) {
+ if (service == NULL) {
data = loadparm.Globals.param_opt;
mem_ctx = talloc_autofree_context();
} else {
- data = loadparm.ServicePtrs[snum]->param_opt;
- mem_ctx = loadparm.ServicePtrs[snum];
+ data = service->param_opt;
+ mem_ctx = service;
}
/* Traverse destination */
if (strcmp(paramo->key, name) == 0) {
if ((paramo->flags & FLAG_CMDLINE) &&
!(flags & FLAG_CMDLINE)) {
- return True;
+ return true;
}
talloc_free(paramo->value);
paramo->value = talloc_strdup(paramo, pszParmValue);
paramo->flags = flags;
free(name);
- return True;
+ return true;
}
}
paramo->key = talloc_strdup(paramo, name);
paramo->value = talloc_strdup(paramo, pszParmValue);
paramo->flags = flags;
- if (snum < 0) {
+ if (service == NULL) {
DLIST_ADD(loadparm.Globals.param_opt, paramo);
} else {
- DLIST_ADD(loadparm.ServicePtrs[snum]->param_opt, paramo);
+ DLIST_ADD(service->param_opt, paramo);
}
free(name);
return true;
}
-/***************************************************************************
- Process a parameter for a particular service number. If snum < 0
- then assume we are in the globals.
-***************************************************************************/
-bool lp_do_parameter(int snum, const char *pszParmName, const char *pszParmValue)
+static bool set_variable(TALLOC_CTX *mem_ctx, int parmnum, void *parm_ptr,
+ const char *pszParmName, const char *pszParmValue,
+ struct loadparm_context *lp_ctx)
{
- int parmnum, i;
- void *parm_ptr = NULL; /* where we are going to store the result */
- void *def_ptr = NULL;
- TALLOC_CTX *mem_ctx;
-
- parmnum = map_parameter(pszParmName);
-
- if (parmnum < 0) {
- if (strchr(pszParmName, ':')) {
- return lp_do_parameter_parametric(snum, pszParmName, pszParmValue, 0);
- }
- DEBUG(0, ("Ignoring unknown parameter \"%s\"\n", pszParmName));
- return true;
- }
-
- if (parm_table[parmnum].flags & FLAG_DEPRECATED) {
- DEBUG(1, ("WARNING: The \"%s\" option is deprecated\n",
- pszParmName));
- }
-
- /* if the flag has been set on the command line, then don't allow override,
- but don't report an error */
- if (parm_table[parmnum].flags & FLAG_CMDLINE) {
- return True;
- }
-
- def_ptr = parm_table[parmnum].ptr;
-
- /* we might point at a service, the default service or a global */
- if (snum < 0) {
- parm_ptr = def_ptr;
- mem_ctx = talloc_autofree_context();
- } else {
- if (parm_table[parmnum].class == P_GLOBAL) {
- DEBUG(0,
- ("Global parameter %s found in service section!\n",
- pszParmName));
- return true;
- }
- parm_ptr =
- ((char *)loadparm.ServicePtrs[snum]) + PTR_DIFF(def_ptr,
- &sDefault);
- mem_ctx = loadparm.ServicePtrs[snum];
- }
-
- if (snum >= 0) {
- if (!loadparm.ServicePtrs[snum]->copymap)
- init_copymap(loadparm.ServicePtrs[snum]);
-
- /* this handles the aliases - set the copymap for other entries with
- the same data pointer */
- for (i = 0; parm_table[i].label; i++)
- if (parm_table[i].ptr == parm_table[parmnum].ptr)
- loadparm.ServicePtrs[snum]->copymap[i] = false;
- }
-
+ 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;
}
switch (parm_table[parmnum].type)
{
case P_BOOL: {
- BOOL b;
+ bool b;
if (!set_boolean(pszParmValue, &b)) {
DEBUG(0,("lp_do_parameter(%s): value is not boolean!\n", pszParmValue));
- return False;
+ return false;
}
*(int *)parm_ptr = b;
}
DEBUG(0,("lp_do_parameter(%s): value is not "
"a valid size specifier!\n", pszParmValue));
- return False;
+ return false;
}
case P_LIST:
break;
case P_STRING:
- string_set(mem_ctx, parm_ptr, pszParmValue);
+ string_set(mem_ctx, (char **)parm_ptr, pszParmValue);
break;
case P_USTRING:
- string_set(mem_ctx, parm_ptr, pszParmValue);
+ string_set(mem_ctx, (char **)parm_ptr, pszParmValue);
strupper(*(char **)parm_ptr);
break;
if (!parm_table[parmnum].enum_list[i].name) {
DEBUG(0,("Unknown enumerated value '%s' for '%s'\n",
pszParmValue, pszParmName));
- return False;
+ return false;
}
break;
case P_SEP:
parm_table[i].flags &= ~FLAG_DEFAULT;
}
}
-
return true;
}
+
+bool lp_do_global_parameter(struct loadparm_context *lp_ctx,
+ const char *pszParmName, const char *pszParmValue)
+{
+ int parmnum = map_parameter(pszParmName);
+ void *parm_ptr;
+
+ if (parmnum < 0) {
+ if (strchr(pszParmName, ':')) {
+ return lp_do_parameter_parametric(NULL, pszParmName, pszParmValue, 0);
+ }
+ DEBUG(0, ("Ignoring unknown parameter \"%s\"\n", pszParmName));
+ return true;
+ }
+
+ if (parm_table[parmnum].flags & FLAG_DEPRECATED) {
+ DEBUG(1, ("WARNING: The \"%s\" option is deprecated\n",
+ pszParmName));
+ }
+
+ /* if the flag has been set on the command line, then don't allow override,
+ but don't report an error */
+ if (parm_table[parmnum].flags & FLAG_CMDLINE) {
+ return true;
+ }
+
+ parm_ptr = parm_table[parmnum].ptr;
+
+ return set_variable(talloc_autofree_context(), parmnum, parm_ptr,
+ pszParmName, pszParmValue, lp_ctx);
+}
+
+bool lp_do_service_parameter(struct loadparm_context *lp_ctx,
+ struct loadparm_service *service,
+ const char *pszParmName, const char *pszParmValue)
+{
+ void *def_ptr = NULL;
+ void *parm_ptr;
+ int i;
+ int parmnum = map_parameter(pszParmName);
+
+ if (parmnum < 0) {
+ if (strchr(pszParmName, ':')) {
+ return lp_do_parameter_parametric(service, pszParmName, pszParmValue, 0);
+ }
+ DEBUG(0, ("Ignoring unknown parameter \"%s\"\n", pszParmName));
+ return true;
+ }
+
+ if (parm_table[parmnum].flags & FLAG_DEPRECATED) {
+ DEBUG(1, ("WARNING: The \"%s\" option is deprecated\n",
+ pszParmName));
+ }
+
+ /* if the flag has been set on the command line, then don't allow override,
+ but don't report an error */
+ if (parm_table[parmnum].flags & FLAG_CMDLINE) {
+ return true;
+ }
+
+ def_ptr = parm_table[parmnum].ptr;
+
+ if (parm_table[parmnum].class == P_GLOBAL) {
+ DEBUG(0,
+ ("Global parameter %s found in service section!\n",
+ pszParmName));
+ return true;
+ }
+ parm_ptr = ((char *)service) + PTR_DIFF(def_ptr, &sDefault);
+
+ if (!service->copymap)
+ init_copymap(service);
+
+ /* this handles the aliases - set the copymap for other
+ * entries with the same data pointer */
+ for (i = 0; parm_table[i].label; i++)
+ if (parm_table[i].ptr == parm_table[parmnum].ptr)
+ service->copymap[i] = false;
+
+ return set_variable(service, parmnum, parm_ptr, pszParmName,
+ pszParmValue, lp_ctx);
+}
+
/***************************************************************************
Process a parameter.
***************************************************************************/
-static BOOL do_parameter(const char *pszParmName, const char *pszParmValue, void *userdata)
+static bool do_parameter(const char *pszParmName, const char *pszParmValue,
+ void *userdata)
{
- return lp_do_parameter(loadparm.bInGlobalSection ? -2 : loadparm.iServiceIndex,
- pszParmName, pszParmValue);
+ 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(lp_ctx, lp_ctx->currentService,
+ pszParmName, pszParmValue);
}
/*
variable argument do parameter
*/
-static BOOL do_parameter_var(const char *pszParmName, const char *fmt, ...) PRINTF_ATTRIBUTE(2, 3);
-
-static BOOL do_parameter_var(const char *pszParmName, const char *fmt, ...)
+bool lp_do_global_parameter_var(struct loadparm_context *lp_ctx, const char *pszParmName, const char *fmt, ...) PRINTF_ATTRIBUTE(3, 4);
+bool lp_do_global_parameter_var(struct loadparm_context *lp_ctx,
+ const char *pszParmName, const char *fmt, ...)
{
char *s;
- BOOL ret;
+ bool ret;
va_list ap;
va_start(ap, fmt);
s = talloc_vasprintf(NULL, fmt, ap);
va_end(ap);
- ret = do_parameter(pszParmName, s, NULL);
+ ret = lp_do_global_parameter(lp_ctx, pszParmName, s);
talloc_free(s);
return ret;
}
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;
if (parmnum < 0 && strchr(pszParmName, ':')) {
/* set a parametric option */
- return lp_do_parameter_parametric(-1, pszParmName, pszParmValue, FLAG_CMDLINE);
+ return lp_do_parameter_parametric(NULL, pszParmName, pszParmValue, FLAG_CMDLINE);
}
if (parmnum < 0) {
DEBUG(0,("Unknown option '%s'\n", pszParmName));
- return False;
+ return false;
}
/* reset the CMDLINE flag in case this has been called before */
parm_table[parmnum].flags &= ~FLAG_CMDLINE;
- if (!lp_do_parameter(-2, pszParmName, pszParmValue)) {
- return False;
+ if (!lp_do_global_parameter(lp_ctx, pszParmName, pszParmValue)) {
+ return false;
}
parm_table[parmnum].flags |= FLAG_CMDLINE;
parm_table[i].flags |= FLAG_CMDLINE;
}
- return True;
+ return true;
}
/*
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;
+ bool ret;
s = strdup(option);
if (!s) {
- return False;
+ return false;
}
p = strchr(s, '=');
if (!p) {
free(s);
- return False;
+ return false;
}
*p = 0;
- ret = lp_set_cmdline(s, p+1);
+ ret = lp_set_cmdline(lp_ctx, s, p+1);
free(s);
return ret;
}
break;
case P_BOOL:
- fprintf(f, "%s", BOOLSTR((BOOL)*(int *)ptr));
+ fprintf(f, "%s", BOOLSTR((bool)*(int *)ptr));
break;
case P_INTEGER:
Check if two parameters are equal.
***************************************************************************/
-static BOOL equal_parameter(parm_type type, void *ptr1, void *ptr2)
+static bool equal_parameter(parm_type type, void *ptr1, void *ptr2)
{
switch (type) {
case P_BOOL:
Returns True on success, False on failure.
***************************************************************************/
-static BOOL do_section(const char *pszSectionName, void *userdata)
+static bool do_section(const char *pszSectionName, void *userdata)
{
- BOOL bRetval;
- BOOL isglobal = ((strwicmp(pszSectionName, GLOBAL_NAME) == 0) ||
+ 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;
+ 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;
}
/* if we have a current service, tidy it up before moving on */
- bRetval = True;
+ bRetval = true;
- if (loadparm.iServiceIndex >= 0)
- bRetval = service_ok(loadparm.iServiceIndex);
+ 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) {
/* issued by the post-processing of a previous section. */
DEBUG(2, ("Processing section \"[%s]\"\n", pszSectionName));
- if ((loadparm.iServiceIndex = add_a_service(&sDefault, pszSectionName))
- < 0) {
+ if ((lp_ctx->currentService = add_a_service(lp_ctx, &sDefault,
+ pszSectionName))
+ == NULL) {
DEBUG(0, ("Failed to add a new service\n"));
return false;
}
Determine if a partcular base parameter is currentl set to the default value.
***************************************************************************/
-static BOOL is_default(int i)
+static bool is_default(int i)
{
if (!defaults_saved)
- return False;
+ return false;
switch (parm_table[i].type) {
case P_LIST:
return str_list_equal((const char **)parm_table[i].def.lvalue,
case P_SEP:
break;
}
- return False;
+ return false;
}
/***************************************************************************
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;
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);
}
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;
}
}
-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;
parm = lp_parm_struct(parm_name);
if (!parm) {
- return False;
+ return false;
}
if (isGlobal)
print_parameter(parm,
ptr, f);
fprintf(f, "\n");
- return True;
+ return true;
}
/***************************************************************************
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 */
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)
}
-/***************************************************************************
- 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;
}
Have we loaded a services file yet?
***************************************************************************/
-BOOL lp_loaded(void)
+bool lp_loaded(void)
{
return bLoaded;
}
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.
+ Initialise the global parameter structure.
***************************************************************************/
-
-void lp_killservice(int iServiceIn)
+bool loadparm_init(struct loadparm_context *lp_ctx)
{
- if (VALID(iServiceIn)) {
- talloc_free(loadparm.ServicePtrs[iServiceIn]);
- loadparm.ServicePtrs[iServiceIn] = NULL;
+ int i;
+ char *myname;
+
+ lp_ctx->bInGlobalSection = true;
+
+ DEBUG(3, ("Initialising global parameters\n"));
+
+ for (i = 0; parm_table[i].label; i++) {
+ if ((parm_table[i].type == P_STRING ||
+ parm_table[i].type == P_USTRING) &&
+ parm_table[i].ptr &&
+ !(parm_table[i].flags & FLAG_CMDLINE)) {
+ string_set(talloc_autofree_context(),
+ (char **)parm_table[i].ptr, "");
+ }
}
+
+ lp_do_global_parameter(lp_ctx, "share backend", "classic");
+
+ lp_do_global_parameter(lp_ctx, "server role", "standalone");
+
+ /* options that can be set on the command line must be initialised via
+ the slower lp_do_global_parameter() to ensure that FLAG_CMDLINE is obeyed */
+#ifdef TCP_NODELAY
+ lp_do_global_parameter(lp_ctx, "socket options", "TCP_NODELAY");
+#endif
+ lp_do_global_parameter(lp_ctx, "workgroup", DEFAULT_WORKGROUP);
+ myname = get_myname();
+ lp_do_global_parameter(lp_ctx, "netbios name", myname);
+ SAFE_FREE(myname);
+ lp_do_global_parameter(lp_ctx, "name resolve order", "lmhosts wins host bcast");
+
+ lp_do_global_parameter(lp_ctx, "fstype", FSTYPE_STRING);
+ lp_do_global_parameter(lp_ctx, "ntvfs handler", "unixuid default");
+ lp_do_global_parameter(lp_ctx, "max connections", "-1");
+
+ lp_do_global_parameter(lp_ctx, "dcerpc endpoint servers", "epmapper srvsvc wkssvc rpcecho samr netlogon lsarpc spoolss drsuapi winreg dssetup unixinfo");
+ lp_do_global_parameter(lp_ctx, "server services", "smb rpc nbt wrepl ldap cldap web kdc drepl winbind");
+ lp_do_global_parameter(lp_ctx, "ntptr providor", "simple_ldb");
+ lp_do_global_parameter(lp_ctx, "auth methods:domain controller", "anonymous sam_ignoredomain");
+ lp_do_global_parameter(lp_ctx, "auth methods:member server", "anonymous sam winbind");
+ lp_do_global_parameter(lp_ctx, "auth methods:standalone", "anonymous sam_ignoredomain");
+ lp_do_global_parameter(lp_ctx, "private dir", dyn_PRIVATE_DIR);
+ lp_do_global_parameter(lp_ctx, "sam database", "sam.ldb");
+ lp_do_global_parameter(lp_ctx, "secrets database", "secrets.ldb");
+ lp_do_global_parameter(lp_ctx, "spoolss database", "spoolss.ldb");
+ lp_do_global_parameter(lp_ctx, "wins config database", "wins_config.ldb");
+ lp_do_global_parameter(lp_ctx, "wins database", "wins.ldb");
+ lp_do_global_parameter(lp_ctx, "registry:HKEY_LOCAL_MACHINE", "hklm.ldb");
+
+ /* This hive should be dynamically generated by Samba using
+ data from the sam, but for the moment leave it in a tdb to
+ keep regedt32 from popping up an annoying dialog. */
+ lp_do_global_parameter(lp_ctx, "registry:HKEY_USERS", "hku.ldb");
+
+ /* using UTF8 by default allows us to support all chars */
+ lp_do_global_parameter(lp_ctx, "unix charset", "UTF8");
+
+ /* Use codepage 850 as a default for the dos character set */
+ lp_do_global_parameter(lp_ctx, "dos charset", "CP850");
+
+ /*
+ * Allow the default PASSWD_CHAT to be overridden in local.h.
+ */
+ lp_do_global_parameter(lp_ctx, "passwd chat", DEFAULT_PASSWD_CHAT);
+
+ lp_do_global_parameter(lp_ctx, "pid directory", dyn_PIDDIR);
+ lp_do_global_parameter(lp_ctx, "lock dir", dyn_LOCKDIR);
+ lp_do_global_parameter(lp_ctx, "modules dir", dyn_MODULESDIR);
+ lp_do_global_parameter(lp_ctx, "ncalrpc dir", dyn_NCALRPCDIR);
+
+ lp_do_global_parameter(lp_ctx, "socket address", "0.0.0.0");
+ lp_do_global_parameter_var(lp_ctx, "server string",
+ "Samba %s", SAMBA_VERSION_STRING);
+
+ lp_do_global_parameter_var(lp_ctx, "announce version", "%d.%d",
+ DEFAULT_MAJOR_VERSION,
+ DEFAULT_MINOR_VERSION);
+
+ lp_do_global_parameter(lp_ctx, "password server", "*");
+
+ lp_do_global_parameter(lp_ctx, "max mux", "50");
+ lp_do_global_parameter(lp_ctx, "max xmit", "12288");
+ lp_do_global_parameter(lp_ctx, "password level", "0");
+ lp_do_global_parameter(lp_ctx, "LargeReadwrite", "True");
+ lp_do_global_parameter(lp_ctx, "server min protocol", "CORE");
+ lp_do_global_parameter(lp_ctx, "server max protocol", "NT1");
+ lp_do_global_parameter(lp_ctx, "client min protocol", "CORE");
+ lp_do_global_parameter(lp_ctx, "client max protocol", "NT1");
+ lp_do_global_parameter(lp_ctx, "security", "USER");
+ lp_do_global_parameter(lp_ctx, "paranoid server security", "True");
+ lp_do_global_parameter(lp_ctx, "EncryptPasswords", "True");
+ lp_do_global_parameter(lp_ctx, "ReadRaw", "True");
+ lp_do_global_parameter(lp_ctx, "WriteRaw", "True");
+ lp_do_global_parameter(lp_ctx, "NullPasswords", "False");
+ lp_do_global_parameter(lp_ctx, "ObeyPamRestrictions", "False");
+ lp_do_global_parameter(lp_ctx, "announce as", "NT SERVER");
+
+ lp_do_global_parameter(lp_ctx, "TimeServer", "False");
+ lp_do_global_parameter(lp_ctx, "BindInterfacesOnly", "False");
+ lp_do_global_parameter(lp_ctx, "Unicode", "True");
+ lp_do_global_parameter(lp_ctx, "ClientLanManAuth", "True");
+ lp_do_global_parameter(lp_ctx, "LanmanAuth", "True");
+ lp_do_global_parameter(lp_ctx, "NTLMAuth", "True");
+ lp_do_global_parameter(lp_ctx, "client use spnego principal", "False");
+
+ lp_do_global_parameter(lp_ctx, "UnixExtensions", "False");
+
+ lp_do_global_parameter(lp_ctx, "PreferredMaster", "Auto");
+ lp_do_global_parameter(lp_ctx, "LocalMaster", "True");
+
+ lp_do_global_parameter(lp_ctx, "wins support", "False");
+ lp_do_global_parameter(lp_ctx, "dns proxy", "True");
+
+ lp_do_global_parameter(lp_ctx, "winbind separator", "\\");
+ lp_do_global_parameter(lp_ctx, "winbind sealed pipes", "True");
+ lp_do_global_parameter(lp_ctx, "winbindd socket directory", dyn_WINBINDD_SOCKET_DIR);
+ lp_do_global_parameter(lp_ctx, "template shell", "/bin/false");
+ lp_do_global_parameter(lp_ctx, "template homedir", "/home/%WORKGROUP%/%ACCOUNTNAME%");
+
+ lp_do_global_parameter(lp_ctx, "client signing", "Yes");
+ lp_do_global_parameter(lp_ctx, "server signing", "auto");
+
+ lp_do_global_parameter(lp_ctx, "use spnego", "True");
+
+ lp_do_global_parameter(lp_ctx, "smb ports", "445 139");
+ lp_do_global_parameter(lp_ctx, "nbt port", "137");
+ lp_do_global_parameter(lp_ctx, "dgram port", "138");
+ lp_do_global_parameter(lp_ctx, "cldap port", "389");
+ 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, "swat directory", dyn_SWATDIR);
+
+ lp_do_global_parameter(lp_ctx, "nt status support", "True");
+
+ lp_do_global_parameter(lp_ctx, "max wins ttl", "518400"); /* 6 days */
+ lp_do_global_parameter(lp_ctx, "min wins ttl", "10");
+
+ lp_do_global_parameter(lp_ctx, "tls enabled", "True");
+ lp_do_global_parameter(lp_ctx, "tls keyfile", "tls/key.pem");
+ lp_do_global_parameter(lp_ctx, "tls certfile", "tls/cert.pem");
+ lp_do_global_parameter(lp_ctx, "tls cafile", "tls/ca.pem");
+ lp_do_global_parameter_var(lp_ctx, "js include", "%s", dyn_JSDIR);
+ lp_do_global_parameter_var(lp_ctx, "setup directory", "%s",
+ dyn_SETUPDIR);
+
+ for (i = 0; parm_table[i].label; i++) {
+ if (!(parm_table[i].flags & FLAG_CMDLINE)) {
+ parm_table[i].flags |= FLAG_DEFAULT;
+ }
+ }
+
+ return true;
}
/***************************************************************************
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);
- loadparm.bInGlobalSection = true;
+ 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);
}
}
-
- init_globals();
- n2 = standard_sub_basic(talloc_autofree_context(), lp_configfile());
+ if (!loadparm_init(lp_ctx))
+ return false;
+
+ lp_ctx->Globals.szConfigFile = filename;
+
+ 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.iServiceIndex = -1;
- 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.iServiceIndex >= 0)
- bRetval = service_ok(loadparm.iServiceIndex);
+ 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(-1, "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();
return bRetval;
}
-/***************************************************************************
- Reset the max number of services.
-***************************************************************************/
-
-void lp_resetnumservices(void)
-{
- loadparm.iNumServices = 0;
-}
-
/***************************************************************************
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;
+ 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, 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, int snum)
+void lp_dump_one(FILE *f, bool show_defaults, struct loadparm_service *service)
{
- if (VALID(snum)) {
- if (loadparm.ServicePtrs[snum]->szService[0] == '\0')
+ if (service != NULL) {
+ if (service->szService[0] == '\0')
return;
- dump_a_service(loadparm.ServicePtrs[snum], f);
+ dump_a_service(service, f);
}
}
-/***************************************************************************
-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.
-***************************************************************************/
+struct loadparm_service *lp_servicebynum(struct loadparm_context *lp_ctx,
+ int snum)
+{
+ return lp_ctx->ServicePtrs[snum];
+}
-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(int snum)
+const char *volume_label(struct loadparm_service *service)
{
- const char *ret = lp_volume(snum);
+ const char *ret = lp_volume(service);
if (!*ret)
- return lp_servicename(snum);
+ return lp_servicename(service);
return ret;
}
If we are PDC then prefer us as DMB
************************************************************/
-bool lp_domain_logons(void)
+bool lp_domain_logons(struct loadparm_context *lp_ctx)
{
- return (lp_server_role() == ROLE_DOMAIN_CONTROLLER);
-}
-
-/*******************************************************************
- Remove a service.
-********************************************************************/
-
-void lp_remove_service(int snum)
-{
- loadparm.ServicePtrs[snum] = NULL;
-}
-
-/*******************************************************************
- Copy a service.
-********************************************************************/
-
-void lp_copy_service(int snum, const char *new_name)
-{
- const char *oldname = lp_servicename(snum);
- do_section(new_name, NULL);
- if (snum >= 0) {
- snum = lp_servicenumber(new_name);
- if (snum >= 0)
- lp_do_parameter(snum, "copy", oldname);
- }
+ return (lp_server_role(lp_ctx) == ROLE_DOMAIN_CONTROLLER);
}
-const char *lp_printername(int snum)
+const char *lp_printername(struct loadparm_service *service)
{
- const char *ret = _lp_printername(snum);
+ const char *ret = _lp_printername(service);
if (ret == NULL || (ret != NULL && *ret == '\0'))
- ret = lp_const_servicename(snum);
+ ret = lp_const_servicename(service);
return ret;
}
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;