r25014: Use talloc for allocating values as well.
[kai/samba.git] / source / param / loadparm.c
index dd52c55edf0238399ffc1a39a0c3e1a242577a6d..7a4f034ecb3b36b97ffa673a737e4ddfd77a861b 100644 (file)
    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,
@@ -22,8 +23,7 @@
    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/>.
 */
 
 /*
@@ -55,7 +55,6 @@
 #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;
@@ -90,13 +89,10 @@ struct param_opt {
  */
 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;
@@ -132,6 +128,8 @@ typedef struct
        char *ntptr_providor;
        char *szWinbindSeparator;
        char *szWinbinddSocketDirectory;
+       char *szTemplateShell;
+       char *szTemplateHomedir;
        int bWinbindSealedPipes;
        char *webapps_directory;
        int tls_enabled;
@@ -148,7 +146,6 @@ typedef struct
        int cli_maxprotocol;
        int cli_minprotocol;
        int security;
-       char **AuthMethods;
        int paranoid_server_security;
        int max_wins_ttl;
        int min_wins_ttl;
@@ -178,8 +175,8 @@ typedef struct
        int bLanmanAuth;
        int bNTLMAuth;
        int bUseSpnego;
-       int  server_signing;
-       int  client_signing;
+       int server_signing;
+       int client_signing;
        int bClientPlaintextAuth;
        int bClientLanManAuth;
        int bClientNTLMv2Auth;
@@ -200,7 +197,6 @@ static global Globals;
  */
 typedef struct
 {
-       int valid;
        char *szService;
        char *szPath;
        char *szCopy;
@@ -240,7 +236,6 @@ service;
 
 /* This is a default service used to prime a services structure */
 static service sDefault = {
-       True,                   /* valid */
        NULL,                   /* szService */
        NULL,                   /* szPath */
        NULL,                   /* szCopy */
@@ -280,13 +275,13 @@ static service sDefault = {
 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"},
@@ -383,10 +378,10 @@ static struct parm_struct parm_table[] = {
 
        {"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},
@@ -549,8 +544,6 @@ static struct parm_struct parm_table[] = {
        {"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},
        
@@ -565,6 +558,8 @@ static struct parm_struct parm_table[] = {
        {"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}
 };
@@ -593,7 +588,8 @@ static void init_globals(void)
                     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, "");
                }
        }
 
@@ -698,6 +694,8 @@ static void init_globals(void)
        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);
@@ -837,7 +835,7 @@ _PUBLIC_ FN_GLOBAL_INTEGER(lp_cldap_port, &Globals.cldap_port)
 _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)
@@ -845,8 +843,8 @@ _PUBLIC_ FN_GLOBAL_STRING(lp_tls_certfile, &Globals.tls_certfile)
 _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)
@@ -856,6 +854,8 @@ _PUBLIC_ FN_GLOBAL_STRING(lp_wins_config_url, &Globals.szWINS_CONFIG_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)
@@ -916,7 +916,6 @@ _PUBLIC_ FN_GLOBAL_INTEGER(lp_srv_minprotocol, &Globals.srv_minprotocol)
 _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)
@@ -959,8 +958,8 @@ static int getservicebyname(const char *pszServiceName,
                            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. */
@@ -971,7 +970,8 @@ const char *lp_get_parametric(int lookup_service, const char *type, const char *
        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;
@@ -1014,7 +1014,7 @@ static int lp_int(const char *s)
 
        if (!s) {
                DEBUG(0,("lp_int(%s): is called with NULL!\n",s));
-               return (-1);
+               return -1;
        }
 
        return strtol(s, NULL, 0); 
@@ -1028,7 +1028,7 @@ static int lp_ulong(const char *s)
 
        if (!s) {
                DEBUG(0,("lp_int(%s): is called with NULL!\n",s));
-               return (-1);
+               return -1;
        }
 
        return strtoul(s, NULL, 0);
@@ -1042,7 +1042,7 @@ static double lp_double(const char *s)
 
        if (!s) {
                DEBUG(0,("lp_double(%s): is called with NULL!\n",s));
-               return (-1);
+               return -1;
        }
 
        return strtod(s, NULL);
@@ -1173,10 +1173,20 @@ BOOL lp_parm_bool(int lookup_service, const char *type, const char *option, BOOL
  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;
+       }
 }
 
 /***************************************************************************
@@ -1249,20 +1259,18 @@ static int add_a_service(const service *pservice, const char *name)
                        /* 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 */
@@ -1273,28 +1281,25 @@ static int add_a_service(const service *pservice, const char *name)
                                           
                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;
 }
 
 /***************************************************************************
@@ -1311,7 +1316,7 @@ BOOL lp_add_home(const char *pszHomename, int iDefaultService,
        i = add_a_service(ServicePtrs[iDefaultService], pszHomename);
 
        if (i < 0)
-               return (False);
+               return false;
 
        if (!(*(ServicePtrs[iDefaultService]->szPath))
            || strequal(ServicePtrs[iDefaultService]->szPath, lp_pathname(-1))) {
@@ -1321,13 +1326,13 @@ BOOL lp_add_home(const char *pszHomename, int iDefaultService,
                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;
@@ -1335,7 +1340,7 @@ BOOL lp_add_home(const char *pszHomename, int iDefaultService,
        DEBUG(3, ("adding home's share [%s] for user '%s' at '%s'\n", pszHomename, 
               user, newHomedir));
        
-       return (True);
+       return true;
 }
 
 /***************************************************************************
@@ -1344,32 +1349,35 @@ BOOL lp_add_home(const char *pszHomename, int iDefaultService,
 
 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");
@@ -1377,20 +1385,20 @@ static BOOL lp_add_hidden(const char *name, const char *fstype)
 
        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 */
@@ -1398,8 +1406,9 @@ BOOL lp_add_printer(const char *pszPrintername, int iDefaultService)
        /* 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;
@@ -1408,7 +1417,7 @@ BOOL lp_add_printer(const char *pszPrintername, int iDefaultService)
 
        DEBUG(3, ("adding printer service %s\n", pszPrintername));
 
-       return (True);
+       return true;
 }
 
 /***************************************************************************
@@ -1421,11 +1430,11 @@ static int map_parameter(const char *pszParmName)
        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)
@@ -1433,7 +1442,7 @@ static int map_parameter(const char *pszParmName)
        /* We do return 'fail' for parametric options as well because they are
           stored in different storage
         */
-       return (-1);
+       return -1;
 }
 
 
@@ -1474,7 +1483,7 @@ static int getservicebyname(const char *pszServiceName, service * pserviceDest)
                        break;
                }
 
-       return (iService);
+       return iService;
 }
 
 /***************************************************************************
@@ -1482,12 +1491,13 @@ static int getservicebyname(const char *pszServiceName, service * pserviceDest)
  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 &&
@@ -1512,12 +1522,12 @@ static void copy_service(service * pserviceDest, service * pserviceSource, int *
                                        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;
@@ -1547,18 +1557,19 @@ static void copy_service(service * pserviceDest, service * pserviceSource, int *
                        /* 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;
@@ -1599,7 +1610,7 @@ static BOOL service_ok(int iService)
                DEBUG(1, ("NOTE: Service %s is flagged unavailable.\n",
                          ServicePtrs[iService]->szService));
 
-       return (bRetval);
+       return bRetval;
 }
 
 static struct file_lists {
@@ -1658,11 +1669,10 @@ BOOL lp_file_list_changed(void)
        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)));
@@ -1676,70 +1686,67 @@ BOOL lp_file_list_changed(void)
                        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;
 }
 
 /***************************************************************************
@@ -1775,10 +1782,12 @@ void *lp_local_ptr(int snum, void *ptr)
 /***************************************************************************
  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++;
@@ -1791,8 +1800,10 @@ static BOOL lp_do_parameter_parametric(int snum, const char *pszParmName, const
 
        if (snum < 0) {
                data = Globals.param_opt;
+               mem_ctx = talloc_autofree_context();
        } else {
                data = ServicePtrs[snum]->param_opt;
+               mem_ctx = ServicePtrs[snum];
        }
 
        /* Traverse destination */
@@ -1805,19 +1816,19 @@ static BOOL lp_do_parameter_parametric(int snum, const char *pszParmName, const
                                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);
@@ -1827,18 +1838,19 @@ static BOOL lp_do_parameter_parametric(int snum, const char *pszParmName, const
 
        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);
 
@@ -1847,7 +1859,7 @@ BOOL lp_do_parameter(int snum, const char *pszParmName, const char *pszParmValue
                        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) {
@@ -1866,16 +1878,18 @@ BOOL lp_do_parameter(int snum, const char *pszParmName, const char *pszParmValue
        /* 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) {
@@ -1892,7 +1906,7 @@ BOOL lp_do_parameter(int snum, const char *pszParmName, const char *pszParmValue
        /* 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 */
@@ -1932,16 +1946,16 @@ BOOL lp_do_parameter(int snum, const char *pszParmName, const char *pszParmValue
                }
 
                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;
 
@@ -1977,7 +1991,7 @@ BOOL lp_do_parameter(int snum, const char *pszParmName, const char *pszParmValue
                }
        }
 
-       return (True);
+       return true;
 }
 
 /***************************************************************************
@@ -1986,8 +2000,8 @@ BOOL lp_do_parameter(int snum, const char *pszParmName, const char *pszParmValue
 
 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);
 }
 
 /*
@@ -2168,7 +2182,7 @@ static BOOL equal_parameter(parm_type type, void *ptr1, void *ptr2)
                case P_SEP:
                        break;
        }
-       return (False);
+       return false;
 }
 
 /***************************************************************************
@@ -2190,7 +2204,7 @@ static BOOL do_section(const char *pszSectionName, void *userdata)
        /* check for multiple global sections */
        if (bInGlobalSection) {
                DEBUG(3, ("Processing section \"[%s]\"\n", pszSectionName));
-               return (True);
+               return true;
        }
 
        /* if we have a current service, tidy it up before moving on */
@@ -2208,11 +2222,11 @@ static BOOL do_section(const char *pszSectionName, void *userdata)
                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;
 }
 
 
@@ -2409,7 +2423,7 @@ struct parm_struct *lp_next_parameter(int snum, int *i, int allparameters)
  Return TRUE if the passed service number is within range.
 ***************************************************************************/
 
-BOOL lp_snum_ok(int iService)
+bool lp_snum_ok(int iService)
 {
        return (LP_SNUM_OK(iService) && ServicePtrs[iService]->bAvailable);
 }
@@ -2429,7 +2443,7 @@ static void lp_add_auto_services(const char *str)
 
 BOOL lp_loaded(void)
 {
-       return (bLoaded);
+       return bLoaded;
 }
 
 /***************************************************************************
@@ -2444,8 +2458,8 @@ void lp_killunused(struct smbsrv_connection *smb, BOOL (*snumused) (struct smbsr
                        continue;
 
                if (!snumused || !snumused(smb, i)) {
-                       ServicePtrs[i]->valid = False;
                        free_service(ServicePtrs[i]);
+                       ServicePtrs[i] = NULL;
                }
        }
 }
@@ -2457,8 +2471,8 @@ void lp_killunused(struct smbsrv_connection *smb, BOOL (*snumused) (struct smbsr
 void lp_killservice(int iServiceIn)
 {
        if (VALID(iServiceIn)) {
-               ServicePtrs[iServiceIn]->valid = False;
                free_service(ServicePtrs[iServiceIn]);
+               ServicePtrs[iServiceIn] = NULL;
        }
 }
 
@@ -2467,32 +2481,29 @@ void lp_killservice(int iServiceIn)
  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);
@@ -2512,7 +2523,7 @@ BOOL lp_load(void)
        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");
@@ -2520,7 +2531,7 @@ BOOL lp_load(void)
 
        init_iconv();
 
-       return (bRetval);
+       return bRetval;
 }
 
 /***************************************************************************
@@ -2538,7 +2549,7 @@ void lp_resetnumservices(void)
 
 int lp_numservices(void)
 {
-       return (iNumServices);
+       return iNumServices;
 }
 
 /***************************************************************************
@@ -2564,7 +2575,7 @@ void lp_dump(FILE *f, BOOL show_defaults, int maxtoprint)
 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')
@@ -2583,7 +2594,7 @@ does not copy the found service.
 int lp_servicenumber(const char *pszServiceName)
 {
        int iService;
-        fstring serviceName;
+        char *serviceName;
  
  
        for (iService = iNumServices - 1; iService >= 0; iService--) {
@@ -2592,8 +2603,7 @@ int lp_servicenumber(const char *pszServiceName)
                         * 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;
                }
@@ -2602,7 +2612,7 @@ int lp_servicenumber(const char *pszServiceName)
        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)
@@ -2631,7 +2641,7 @@ const char *volume_label(int snum)
        const char *ret = lp_volume(snum);
        if (!*ret)
                return lp_servicename(snum);
-       return (ret);
+       return ret;
 }
 
 
@@ -2639,7 +2649,7 @@ const char *volume_label(int snum)
  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);
 }
@@ -2650,7 +2660,7 @@ BOOL lp_domain_logons(void)
 
 void lp_remove_service(int snum)
 {
-       ServicePtrs[snum]->valid = False;
+       ServicePtrs[snum] = NULL;
 }
 
 /*******************************************************************