Copyright (C) Stefan (metze) Metzmacher 2002
Copyright (C) Jim McDonough (jmcd@us.ibm.com) 2003.
Copyright (C) James Myers 2003 <myersjj@samba.org>
+ Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2007
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
+ the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/*
#include "includes.h"
#include "version.h"
#include "dynconfig.h"
-#include "pstring.h"
#include "system/time.h"
#include "system/locale.h"
#include "system/network.h" /* needed for TCP_NODELAY */
#include "libcli/raw/signing.h"
#include "lib/util/dlinklist.h"
#include "param/loadparm.h"
+#include "pstring.h"
-static BOOL bLoaded = False;
+static bool bLoaded = false;
-#define standard_sub_basic(str,len)
+#define standard_sub_basic strdup
/* some helpful bits */
-#define LP_SNUM_OK(i) (((i) >= 0) && ((i) < iNumServices) && ServicePtrs[(i)]->valid)
-#define VALID(i) ServicePtrs[i]->valid
-
-static BOOL do_parameter(const char *, const char *, void *);
-static BOOL do_parameter_var(const char *pszParmName, const char *fmt, ...);
+#define LP_SNUM_OK(i) (((i) >= 0) && ((i) < iNumServices) && VALID(i))
+#define VALID(i) (ServicePtrs[i] != NULL)
-static BOOL defaults_saved = False;
+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 {
struct param_opt *prev, *next;
*/
typedef struct
{
- int server_role;
+ enum server_role server_role;
char **smb_ports;
- char *dos_charset;
- char *unix_charset;
char *ncalrpc_dir;
- char *display_charset;
char *szLockDir;
char *szModulesDir;
char *szPidDir;
char *ntptr_providor;
char *szWinbindSeparator;
char *szWinbinddSocketDirectory;
+ char *szTemplateShell;
+ char *szTemplateHomedir;
int bWinbindSealedPipes;
char *webapps_directory;
int tls_enabled;
int cli_maxprotocol;
int cli_minprotocol;
int security;
- char **AuthMethods;
int paranoid_server_security;
int max_wins_ttl;
int min_wins_ttl;
int bLanmanAuth;
int bNTLMAuth;
int bUseSpnego;
- int server_signing;
- int client_signing;
+ int server_signing;
+ int client_signing;
int bClientPlaintextAuth;
int bClientLanManAuth;
int bClientNTLMv2Auth;
*/
typedef struct
{
- int valid;
char *szService;
char *szPath;
char *szCopy;
/* This is a default service used to prime a services structure */
static service sDefault = {
- True, /* valid */
NULL, /* szService */
NULL, /* szPath */
NULL, /* szCopy */
static service **ServicePtrs = NULL;
static int iNumServices = 0;
static int iServiceIndex = 0;
-static BOOL bInGlobalSection = True;
+static bool bInGlobalSection = True;
#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(const char *pszParmValue, char **ptr);
+static bool handle_copy(const char *pszParmValue, char **ptr);
static const struct enum_list enum_protocol[] = {
{PROTOCOL_SMB2, "SMB2"},
{"server role", P_ENUM, P_GLOBAL, &Globals.server_role, NULL, enum_server_role, FLAG_BASIC},
- {"dos charset", P_STRING, P_GLOBAL, &Globals.dos_charset, NULL, NULL, FLAG_ADVANCED | FLAG_DEVELOPER},
- {"unix charset", P_STRING, P_GLOBAL, &Globals.unix_charset, NULL, NULL, FLAG_ADVANCED | FLAG_DEVELOPER},
+ {"dos charset", P_STRING, P_GLOBAL, &dos_charset, NULL, NULL, FLAG_ADVANCED | FLAG_DEVELOPER},
+ {"unix charset", P_STRING, P_GLOBAL, &unix_charset, NULL, NULL, FLAG_ADVANCED | FLAG_DEVELOPER},
{"ncalrpc dir", P_STRING, P_GLOBAL, &Globals.ncalrpc_dir, NULL, NULL, FLAG_ADVANCED | FLAG_DEVELOPER},
- {"display charset", P_STRING, P_GLOBAL, &Globals.display_charset, NULL, NULL, FLAG_ADVANCED | FLAG_DEVELOPER},
+ {"display charset", P_STRING, P_GLOBAL, &display_charset, NULL, NULL, FLAG_ADVANCED | FLAG_DEVELOPER},
{"comment", P_STRING, P_LOCAL, &sDefault.comment, NULL, NULL, FLAG_BASIC | FLAG_ADVANCED | FLAG_SHARE | FLAG_PRINT | FLAG_DEVELOPER},
{"path", P_STRING, P_LOCAL, &sDefault.szPath, NULL, NULL, FLAG_BASIC | FLAG_ADVANCED | FLAG_SHARE | FLAG_PRINT | FLAG_DEVELOPER},
{"directory", P_STRING, P_LOCAL, &sDefault.szPath, NULL, NULL, FLAG_HIDE},
{"setup directory", P_STRING, P_GLOBAL, &Globals.szSetupDir, NULL, NULL, FLAG_ADVANCED | FLAG_DEVELOPER},
{"socket address", P_STRING, P_GLOBAL, &Globals.szSocketAddress, NULL, NULL, FLAG_DEVELOPER},
- {"-valid", P_BOOL, P_LOCAL, &sDefault.valid, NULL, NULL, FLAG_HIDE},
-
{"copy", P_STRING, P_LOCAL, &sDefault.szCopy, handle_copy, NULL, FLAG_HIDE},
{"include", P_STRING, P_LOCAL, &sDefault.szInclude, handle_include, NULL, FLAG_HIDE},
{"winbind separator", P_STRING, P_GLOBAL, &Globals.szWinbindSeparator, NULL, NULL, FLAG_ADVANCED | FLAG_DEVELOPER },
{"winbindd socket directory", P_STRING, P_GLOBAL, &Globals.szWinbinddSocketDirectory, NULL, NULL, FLAG_ADVANCED | FLAG_DEVELOPER },
{"winbind sealed pipes", P_BOOL, P_GLOBAL, &Globals.bWinbindSealedPipes, NULL, NULL, FLAG_ADVANCED | FLAG_DEVELOPER },
+ {"template shell", P_STRING, P_GLOBAL, &Globals.szTemplateShell, NULL, NULL, FLAG_ADVANCED | FLAG_DEVELOPER },
+ {"template homedir", P_STRING, P_GLOBAL, &Globals.szTemplateHomedir, NULL, NULL, FLAG_ADVANCED | FLAG_DEVELOPER },
{NULL, P_BOOL, P_NONE, NULL, NULL, NULL, 0}
};
parm_table[i].type == P_USTRING) &&
parm_table[i].ptr &&
!(parm_table[i].flags & FLAG_CMDLINE)) {
- string_set(parm_table[i].ptr, "");
+ string_set(talloc_autofree_context(),
+ parm_table[i].ptr, "");
}
}
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);
_PUBLIC_ FN_GLOBAL_INTEGER(lp_krb5_port, &Globals.krb5_port)
_PUBLIC_ FN_GLOBAL_INTEGER(lp_kpasswd_port, &Globals.kpasswd_port)
_PUBLIC_ FN_GLOBAL_INTEGER(lp_web_port, &Globals.web_port)
-_PUBLIC_ FN_GLOBAL_STRING(lp_dos_charset, &Globals.dos_charset)
+_PUBLIC_ FN_GLOBAL_STRING(lp_dos_charset, &dos_charset)
_PUBLIC_ FN_GLOBAL_STRING(lp_webapps_directory, &Globals.webapps_directory)
_PUBLIC_ FN_GLOBAL_BOOL(lp_tls_enabled, &Globals.tls_enabled)
_PUBLIC_ FN_GLOBAL_STRING(lp_tls_keyfile, &Globals.tls_keyfile)
_PUBLIC_ FN_GLOBAL_STRING(lp_tls_cafile, &Globals.tls_cafile)
_PUBLIC_ FN_GLOBAL_STRING(lp_tls_crlfile, &Globals.tls_crlfile)
_PUBLIC_ FN_GLOBAL_STRING(lp_tls_dhpfile, &Globals.tls_dhpfile)
-_PUBLIC_ FN_GLOBAL_STRING(lp_unix_charset, &Globals.unix_charset)
-_PUBLIC_ FN_GLOBAL_STRING(lp_display_charset, &Globals.display_charset)
+_PUBLIC_ FN_GLOBAL_STRING(lp_unix_charset, &unix_charset)
+_PUBLIC_ FN_GLOBAL_STRING(lp_display_charset, &display_charset)
_PUBLIC_ FN_GLOBAL_STRING(lp_configfile, &Globals.szConfigFile)
_PUBLIC_ FN_GLOBAL_STRING(lp_share_backend, &Globals.szShareBackend)
_PUBLIC_ FN_GLOBAL_STRING(lp_sam_url, &Globals.szSAM_URL)
_PUBLIC_ FN_GLOBAL_STRING(lp_wins_url, &Globals.szWINS_URL)
_PUBLIC_ FN_GLOBAL_CONST_STRING(lp_winbind_separator, &Globals.szWinbindSeparator)
_PUBLIC_ FN_GLOBAL_CONST_STRING(lp_winbindd_socket_directory, &Globals.szWinbinddSocketDirectory)
+_PUBLIC_ FN_GLOBAL_CONST_STRING(lp_template_shell, &Globals.szTemplateShell)
+_PUBLIC_ FN_GLOBAL_CONST_STRING(lp_template_homedir, &Globals.szTemplateHomedir)
_PUBLIC_ FN_GLOBAL_BOOL(lp_winbind_sealed_pipes, &Globals.bWinbindSealedPipes)
_PUBLIC_ FN_GLOBAL_STRING(lp_private_dir, &Globals.szPrivateDir)
_PUBLIC_ FN_GLOBAL_STRING(lp_serverstring, &Globals.szServerString)
_PUBLIC_ FN_GLOBAL_INTEGER(lp_cli_maxprotocol, &Globals.cli_maxprotocol)
_PUBLIC_ FN_GLOBAL_INTEGER(lp_cli_minprotocol, &Globals.cli_minprotocol)
_PUBLIC_ FN_GLOBAL_INTEGER(lp_security, &Globals.security)
-_PUBLIC_ FN_GLOBAL_LIST(lp_auth_methods, &Globals.AuthMethods)
_PUBLIC_ FN_GLOBAL_BOOL(lp_paranoid_server_security, &Globals.paranoid_server_security)
_PUBLIC_ FN_GLOBAL_INTEGER(lp_announce_as, &Globals.announce_as)
_PUBLIC_ FN_GLOBAL_LIST(lp_js_include, &Globals.jsInclude)
service * pserviceDest);
static void copy_service(service * pserviceDest,
service * pserviceSource, int *pcopymapDest);
-static BOOL service_ok(int iService);
-static BOOL do_section(const char *pszSectionName, void *);
+static bool service_ok(int iService);
+static bool do_section(const char *pszSectionName, void *);
static void init_copymap(service * pservice);
/* This is a helper function for parametrical options support. */
char *vfskey;
struct param_opt *data;
- if (lookup_service >= iNumServices) return NULL;
+ if (lookup_service >= 0 && !LP_SNUM_OK(lookup_service))
+ return NULL;
data = (lookup_service < 0) ?
Globals.param_opt : ServicePtrs[lookup_service]->param_opt;
if (!s) {
DEBUG(0,("lp_int(%s): is called with NULL!\n",s));
- return (-1);
+ return -1;
}
return strtol(s, NULL, 0);
if (!s) {
DEBUG(0,("lp_int(%s): is called with NULL!\n",s));
- return (-1);
+ return -1;
}
return strtoul(s, NULL, 0);
if (!s) {
DEBUG(0,("lp_double(%s): is called with NULL!\n",s));
- return (-1);
+ return -1;
}
return strtod(s, NULL);
Initialise a service to the defaults.
***************************************************************************/
-static void init_service(service * pservice)
+static service *init_service(TALLOC_CTX *mem_ctx)
{
+ service *pservice = talloc(mem_ctx, service);
memset((char *)pservice, '\0', sizeof(service));
copy_service(pservice, &sDefault, NULL);
+ return pservice;
+}
+
+void string_free(char **str)
+{
+ if (str) {
+ talloc_free(*str);
+ *str = NULL;
+ }
}
/***************************************************************************
/* They will be added during parsing again */
data = ServicePtrs[i]->param_opt;
while (data) {
- string_free(&data->key);
- string_free(&data->value);
pdata = data->next;
- SAFE_FREE(data);
+ talloc_free(data);
data = pdata;
}
ServicePtrs[i]->param_opt = NULL;
- return (i);
+ return i;
}
}
/* find an invalid one */
for (i = 0; i < iNumServices; i++)
- if (!ServicePtrs[i]->valid)
+ if (ServicePtrs[i] == NULL)
break;
/* if not, then create one */
if (!tsp) {
DEBUG(0,("add_a_service: failed to enlarge ServicePtrs!\n"));
- return (-1);
+ return -1;
}
else {
ServicePtrs = tsp;
- ServicePtrs[iNumServices] = malloc_p(service);
- }
- if (!ServicePtrs[iNumServices]) {
- DEBUG(0,("add_a_service: out of memory!\n"));
- return (-1);
+ ServicePtrs[iNumServices] = NULL;
}
iNumServices++;
- } else
- free_service(ServicePtrs[i]);
-
- ServicePtrs[i]->valid = True;
+ }
- init_service(ServicePtrs[i]);
+ ServicePtrs[i] = init_service(talloc_autofree_context());
+ if (ServicePtrs[i] == NULL) {
+ DEBUG(0,("add_a_service: out of memory!\n"));
+ return -1;
+ }
copy_service(ServicePtrs[i], &tservice, NULL);
- if (name)
- string_set(&ServicePtrs[i]->szService, name);
- return (i);
+ if (name != NULL)
+ string_set(ServicePtrs[i], &ServicePtrs[i]->szService, name);
+ return i;
}
/***************************************************************************
i = add_a_service(ServicePtrs[iDefaultService], pszHomename);
if (i < 0)
- return (False);
+ return false;
if (!(*(ServicePtrs[iDefaultService]->szPath))
|| strequal(ServicePtrs[iDefaultService]->szPath, lp_pathname(-1))) {
string_sub(newHomedir,"%H", pszHomedir, sizeof(newHomedir));
}
- string_set(&ServicePtrs[i]->szPath, newHomedir);
+ string_set(ServicePtrs[i], &ServicePtrs[i]->szPath, newHomedir);
if (!(*(ServicePtrs[i]->comment))) {
- pstring comment;
- slprintf(comment, sizeof(comment) - 1,
+ char *comment = talloc_asprintf(ServicePtrs[i],
"Home directory of %s", user);
- string_set(&ServicePtrs[i]->comment, comment);
+ string_set(ServicePtrs[i], &ServicePtrs[i]->comment, comment);
+ talloc_free(comment);
}
ServicePtrs[i]->bAvailable = sDefault.bAvailable;
ServicePtrs[i]->bBrowseable = sDefault.bBrowseable;
DEBUG(3, ("adding home's share [%s] for user '%s' at '%s'\n", pszHomename,
user, newHomedir));
- return (True);
+ return true;
}
/***************************************************************************
int lp_add_service(const char *pszService, int iDefaultService)
{
- return (add_a_service(ServicePtrs[iDefaultService], pszService));
+ return add_a_service(ServicePtrs[iDefaultService], pszService);
}
/***************************************************************************
Add the IPC service.
***************************************************************************/
-static BOOL lp_add_hidden(const char *name, const char *fstype)
+static bool lp_add_hidden(const char *name, const char *fstype)
{
- pstring comment;
+ char *comment = NULL;
int i = add_a_service(&sDefault, name);
if (i < 0)
- return (False);
+ return false;
- slprintf(comment, sizeof(comment) - 1,
- "%s Service (%s)", fstype, Globals.szServerString);
+ string_set(ServicePtrs[i], &ServicePtrs[i]->szPath, tmpdir());
- string_set(&ServicePtrs[i]->szPath, tmpdir());
- string_set(&ServicePtrs[i]->comment, comment);
- string_set(&ServicePtrs[i]->fstype, fstype);
+ asprintf(&comment, "%s Service (%s)", fstype, Globals.szServerString);
+ if (comment == NULL)
+ return false;
+
+ string_set(ServicePtrs[i], &ServicePtrs[i]->comment, comment);
+ SAFE_FREE(comment);
+ string_set(ServicePtrs[i], &ServicePtrs[i]->fstype, fstype);
ServicePtrs[i]->iMaxConnections = -1;
- ServicePtrs[i]->bAvailable = True;
- ServicePtrs[i]->bRead_only = True;
- ServicePtrs[i]->bPrint_ok = False;
- ServicePtrs[i]->bBrowseable = False;
+ ServicePtrs[i]->bAvailable = true;
+ ServicePtrs[i]->bRead_only = true;
+ ServicePtrs[i]->bPrint_ok = false;
+ ServicePtrs[i]->bBrowseable = false;
if (strcasecmp(fstype, "IPC") == 0) {
lp_do_parameter(i, "ntvfs handler", "default");
DEBUG(3, ("adding hidden service %s\n", name));
- return (True);
+ return true;
}
/***************************************************************************
Add a new printer service, with defaults coming from service iFrom.
***************************************************************************/
-BOOL lp_add_printer(const char *pszPrintername, int iDefaultService)
+bool lp_add_printer(const char *pszPrintername, int iDefaultService)
{
const char *comment = "From Printcap";
int i = add_a_service(ServicePtrs[iDefaultService], pszPrintername);
if (i < 0)
- return (False);
+ return false;
/* note that we do NOT default the availability flag to True - */
/* we take it from the default service passed. This allows all */
/* entry (if/when the 'available' keyword is implemented!). */
/* the printer name is set to the service name. */
- string_set(&ServicePtrs[i]->szPrintername, pszPrintername);
- string_set(&ServicePtrs[i]->comment, comment);
+ string_set(ServicePtrs[i], &ServicePtrs[i]->szPrintername,
+ pszPrintername);
+ string_set(ServicePtrs[i], &ServicePtrs[i]->comment, comment);
ServicePtrs[i]->bBrowseable = sDefault.bBrowseable;
/* Printers cannot be read_only. */
ServicePtrs[i]->bRead_only = False;
DEBUG(3, ("adding printer service %s\n", pszPrintername));
- return (True);
+ return true;
}
/***************************************************************************
int iIndex;
if (*pszParmName == '-')
- return (-1);
+ return -1;
for (iIndex = 0; parm_table[iIndex].label; iIndex++)
if (strwicmp(parm_table[iIndex].label, pszParmName) == 0)
- return (iIndex);
+ return iIndex;
/* Warn only if it isn't parametric option */
if (strchr(pszParmName, ':') == NULL)
/* We do return 'fail' for parametric options as well because they are
stored in different storage
*/
- return (-1);
+ return -1;
}
break;
}
- return (iService);
+ return iService;
}
/***************************************************************************
If pcopymapDest is NULL then copy all fields
***************************************************************************/
-static void copy_service(service * pserviceDest, service * pserviceSource, int *pcopymapDest)
+static void copy_service(service *pserviceDest, service *pserviceSource,
+ int *pcopymapDest)
{
int i;
- BOOL bcopyall = (pcopymapDest == NULL);
+ bool bcopyall = (pcopymapDest == NULL);
struct param_opt *data, *pdata, *paramo;
- BOOL not_added;
+ bool not_added;
for (i = 0; parm_table[i].label; i++)
if (parm_table[i].ptr && parm_table[i].class == P_LOCAL &&
break;
case P_STRING:
- string_set(dest_ptr,
+ string_set(pserviceDest, dest_ptr,
*(char **)src_ptr);
break;
case P_USTRING:
- string_set(dest_ptr,
+ string_set(pserviceDest, dest_ptr,
*(char **)src_ptr);
strupper(*(char **)dest_ptr);
break;
/* If we already have same option, override it */
if (strcmp(pdata->key, data->key) == 0) {
string_free(&pdata->value);
- pdata->value = strdup(data->value);
- not_added = False;
+ pdata->value = talloc_reference(pdata,
+ data->value);
+ not_added = false;
break;
}
pdata = pdata->next;
}
if (not_added) {
- paramo = malloc_p(struct param_opt);
- if (!paramo)
+ paramo = talloc(pserviceDest, struct param_opt);
+ if (paramo == NULL)
smb_panic("OOM");
- paramo->key = strdup(data->key);
- paramo->value = strdup(data->value);
+ paramo->key = talloc_reference(paramo, data->key);
+ paramo->value = talloc_reference(paramo, data->value);
DLIST_ADD(pserviceDest->param_opt, paramo);
}
data = data->next;
DEBUG(1, ("NOTE: Service %s is flagged unavailable.\n",
ServicePtrs[iService]->szService));
- return (bRetval);
+ return bRetval;
}
static struct file_lists {
DEBUG(6, ("lp_file_list_changed()\n"));
while (f) {
- pstring n2;
+ char *n2;
time_t mod_time;
- pstrcpy(n2, f->name);
- standard_sub_basic(n2,sizeof(n2));
+ n2 = standard_sub_basic(f->name);
DEBUGADD(6, ("file %s -> %s last mod_time: %s\n",
f->name, n2, ctime(&f->modtime)));
f->modtime = mod_time;
SAFE_FREE(f->subfname);
f->subfname = strdup(n2);
- return (True);
+ return true;
}
f = f->next;
}
- return (False);
+ return false;
}
/***************************************************************************
Handle the include operation.
***************************************************************************/
-static BOOL handle_include(const char *pszParmValue, char **ptr)
+static bool handle_include(const char *pszParmValue, char **ptr)
{
- pstring fname;
- pstrcpy(fname, pszParmValue);
-
- standard_sub_basic(fname,sizeof(fname));
+ char *fname = standard_sub_basic(pszParmValue);
add_to_file_list(pszParmValue, fname);
- string_set(ptr, 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, NULL);
DEBUG(2, ("Can't find include file %s\n", fname));
- return (False);
+ return false;
}
/***************************************************************************
Handle the interpretation of the copy parameter.
***************************************************************************/
-static BOOL handle_copy(const char *pszParmValue, char **ptr)
+static bool handle_copy(const char *pszParmValue, char **ptr)
{
- BOOL bRetval;
+ bool bRetval;
int iTemp;
- service serviceTemp;
+ service *serviceTemp;
- string_set(ptr, pszParmValue);
+ string_set(talloc_autofree_context(), ptr, pszParmValue);
- init_service(&serviceTemp);
+ serviceTemp = init_service(talloc_autofree_context());
- bRetval = False;
+ bRetval = false;
DEBUG(3, ("Copying service from service %s\n", pszParmValue));
- if ((iTemp = getservicebyname(pszParmValue, &serviceTemp)) >= 0) {
+ if ((iTemp = getservicebyname(pszParmValue, serviceTemp)) >= 0) {
if (iTemp == iServiceIndex) {
DEBUG(0, ("Can't copy service %s - unable to copy self!\n", pszParmValue));
} else {
copy_service(ServicePtrs[iServiceIndex],
- &serviceTemp,
+ serviceTemp,
ServicePtrs[iServiceIndex]->copymap);
- bRetval = True;
+ bRetval = true;
}
} else {
DEBUG(0, ("Unable to copy service - source not found: %s\n", pszParmValue));
- bRetval = False;
+ bRetval = false;
}
- free_service(&serviceTemp);
- return (bRetval);
+ free_service(serviceTemp);
+ return bRetval;
}
/***************************************************************************
/***************************************************************************
Process a parametric option
***************************************************************************/
-static BOOL lp_do_parameter_parametric(int snum, const char *pszParmName, const char *pszParmValue, int flags)
+static bool lp_do_parameter_parametric(int snum, const char *pszParmName,
+ const char *pszParmValue, int flags)
{
struct param_opt *paramo, *data;
char *name;
+ TALLOC_CTX *mem_ctx;
while (isspace((unsigned char)*pszParmName)) {
pszParmName++;
if (snum < 0) {
data = Globals.param_opt;
+ mem_ctx = talloc_autofree_context();
} else {
data = ServicePtrs[snum]->param_opt;
+ mem_ctx = ServicePtrs[snum];
}
/* Traverse destination */
return True;
}
- free(paramo->value);
- paramo->value = strdup(pszParmValue);
+ talloc_free(paramo->value);
+ paramo->value = talloc_strdup(paramo, pszParmValue);
paramo->flags = flags;
free(name);
return True;
}
}
- paramo = malloc_p(struct param_opt);
+ paramo = talloc(mem_ctx, struct param_opt);
if (!paramo)
smb_panic("OOM");
- paramo->key = strdup(name);
- paramo->value = strdup(pszParmValue);
+ paramo->key = talloc_strdup(paramo, name);
+ paramo->value = talloc_strdup(paramo, pszParmValue);
paramo->flags = flags;
if (snum < 0) {
DLIST_ADD(Globals.param_opt, paramo);
free(name);
- return True;
+ 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)
+bool lp_do_parameter(int snum, const char *pszParmName, const char *pszParmValue)
{
int parmnum, i;
void *parm_ptr = NULL; /* where we are going to store the result */
void *def_ptr = NULL;
+ TALLOC_CTX *mem_ctx;
parmnum = map_parameter(pszParmName);
return lp_do_parameter_parametric(snum, pszParmName, pszParmValue, 0);
}
DEBUG(0, ("Ignoring unknown parameter \"%s\"\n", pszParmName));
- return (True);
+ return true;
}
if (parm_table[parmnum].flags & FLAG_DEPRECATED) {
/* 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);
+ return true;
}
parm_ptr =
((char *)ServicePtrs[snum]) + PTR_DIFF(def_ptr,
&sDefault);
+ mem_ctx = ServicePtrs[snum];
}
if (snum >= 0) {
/* if it is a special case then go ahead */
if (parm_table[parmnum].special) {
parm_table[parmnum].special(pszParmValue, (char **)parm_ptr);
- return (True);
+ return true;
}
/* now switch on the type of variable it is */
}
case P_LIST:
- *(const char ***)parm_ptr = str_list_make(talloc_autofree_context(),
+ *(const char ***)parm_ptr = str_list_make(mem_ctx,
pszParmValue, NULL);
break;
case P_STRING:
- string_set(parm_ptr, pszParmValue);
+ string_set(mem_ctx, parm_ptr, pszParmValue);
break;
case P_USTRING:
- string_set(parm_ptr, pszParmValue);
+ string_set(mem_ctx, parm_ptr, pszParmValue);
strupper(*(char **)parm_ptr);
break;
}
}
- return (True);
+ return true;
}
/***************************************************************************
static BOOL do_parameter(const char *pszParmName, const char *pszParmValue, void *userdata)
{
- return (lp_do_parameter(bInGlobalSection ? -2 : iServiceIndex,
- pszParmName, pszParmValue));
+ return lp_do_parameter(bInGlobalSection ? -2 : iServiceIndex,
+ pszParmName, pszParmValue);
}
/*
case P_SEP:
break;
}
- return (False);
+ return false;
}
/***************************************************************************
/* check for multiple global sections */
if (bInGlobalSection) {
DEBUG(3, ("Processing section \"[%s]\"\n", pszSectionName));
- return (True);
+ return true;
}
/* if we have a current service, tidy it up before moving on */
if ((iServiceIndex = add_a_service(&sDefault, pszSectionName))
< 0) {
DEBUG(0, ("Failed to add a new service\n"));
- return (False);
+ return false;
}
}
- return (bRetval);
+ return bRetval;
}
Return TRUE if the passed service number is within range.
***************************************************************************/
-BOOL lp_snum_ok(int iService)
+bool lp_snum_ok(int iService)
{
return (LP_SNUM_OK(iService) && ServicePtrs[iService]->bAvailable);
}
BOOL lp_loaded(void)
{
- return (bLoaded);
+ return bLoaded;
}
/***************************************************************************
continue;
if (!snumused || !snumused(smb, i)) {
- ServicePtrs[i]->valid = False;
free_service(ServicePtrs[i]);
+ ServicePtrs[i] = NULL;
}
}
}
void lp_killservice(int iServiceIn)
{
if (VALID(iServiceIn)) {
- ServicePtrs[iServiceIn]->valid = False;
free_service(ServicePtrs[iServiceIn]);
+ ServicePtrs[iServiceIn] = NULL;
}
}
False on failure.
***************************************************************************/
-BOOL lp_load(void)
+bool lp_load(void)
{
- pstring n2;
- BOOL bRetval;
+ char *n2;
+ bool bRetval;
struct param_opt *data;
- bRetval = False;
+ bRetval = false;
- bInGlobalSection = True;
+ bInGlobalSection = true;
if (Globals.param_opt != NULL) {
struct param_opt *next;
for (data=Globals.param_opt; data; data=next) {
next = data->next;
if (data->flags & FLAG_CMDLINE) continue;
- free(data->key);
- free(data->value);
DLIST_REMOVE(Globals.param_opt, data);
- free(data);
+ talloc_free(data);
}
}
init_globals();
- pstrcpy(n2, lp_configfile());
- standard_sub_basic(n2,sizeof(n2));
+ n2 = standard_sub_basic(lp_configfile());
DEBUG(2, ("lp_load: refreshing parameters from %s\n", n2));
add_to_file_list(lp_configfile(), n2);
lp_add_hidden("IPC$", "IPC");
lp_add_hidden("ADMIN$", "DISK");
- bLoaded = True;
+ bLoaded = true;
if (!Globals.szWINSservers && Globals.bWINSsupport) {
lp_do_parameter(-1, "wins server", "127.0.0.1");
init_iconv();
- return (bRetval);
+ return bRetval;
}
/***************************************************************************
int lp_numservices(void)
{
- return (iNumServices);
+ return iNumServices;
}
/***************************************************************************
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, int snum)
{
if (VALID(snum)) {
if (ServicePtrs[snum]->szService[0] == '\0')
int lp_servicenumber(const char *pszServiceName)
{
int iService;
- fstring serviceName;
+ char *serviceName;
for (iService = iNumServices - 1; iService >= 0; iService--) {
* The substitution here is used to support %U is
* service names
*/
- fstrcpy(serviceName, ServicePtrs[iService]->szService);
- standard_sub_basic(serviceName,sizeof(serviceName));
+ serviceName = standard_sub_basic(ServicePtrs[iService]->szService);
if (strequal(serviceName, pszServiceName))
break;
}
if (iService < 0)
DEBUG(7,("lp_servicenumber: couldn't find %s\n", pszServiceName));
- return (iService);
+ return iService;
}
int lp_find_valid_service(const char *pszServiceName)
const char *ret = lp_volume(snum);
if (!*ret)
return lp_servicename(snum);
- return (ret);
+ return ret;
}
If we are PDC then prefer us as DMB
************************************************************/
-BOOL lp_domain_logons(void)
+bool lp_domain_logons(void)
{
return (lp_server_role() == ROLE_DOMAIN_CONTROLLER);
}
void lp_remove_service(int snum)
{
- ServicePtrs[snum]->valid = False;
+ ServicePtrs[snum] = NULL;
}
/*******************************************************************