[GLUE] Rsync SAMBA_3_2_0 SVN r25598 in order to create the v3-2-test branch.
[samba.git] / source / param / loadparm.c
index 2d64d541a0c5d4cde21d6f6e54e0adf1166f63cc..8b15073ed0083f0087a55797537b54934ebd716a 100644 (file)
@@ -306,6 +306,7 @@ typedef struct {
        BOOL bDebugHiresTimestamp;
        BOOL bDebugPid;
        BOOL bDebugUid;
+       BOOL bDebugClass;
        BOOL bEnableCoreFiles;
        BOOL bHostMSDfs;
        BOOL bUseMmap;
@@ -370,7 +371,6 @@ typedef struct {
        char **szHostsdeny;
        char *szMagicScript;
        char *szMagicOutput;
-       char *szMangledMap;
        char *szVetoFiles;
        char *szHideFiles;
        char *szVetoOplockFiles;
@@ -384,6 +384,7 @@ typedef struct {
        char *fstype;
        char **szVfsObjects;
        char *szMSDfsProxy;
+       char *szAioWriteBehind;
        char *szDfree;
        int iMinPrintSpace;
        int iMaxPrintJobs;
@@ -471,6 +472,7 @@ typedef struct {
        int iAioReadSize;
        int iAioWriteSize;
        int iMap_readonly;
+       int iDirectoryNameCacheSize;
        param_opt_struct *param_opt;
 
        char dummy[3];          /* for alignment */
@@ -510,7 +512,6 @@ static service sDefault = {
        NULL,                   /* szHostsdeny */
        NULL,                   /* szMagicScript */
        NULL,                   /* szMagicOutput */
-       NULL,                   /* szMangledMap */
        NULL,                   /* szVetoFiles */
        NULL,                   /* szHideFiles */
        NULL,                   /* szVetoOplockFiles */
@@ -524,6 +525,7 @@ static service sDefault = {
        NULL,                   /* fstype */
        NULL,                   /* vfs objects */
        NULL,                   /* szMSDfsProxy */
+       NULL,                   /* szAioWriteBehind */
        NULL,                   /* szDfree */
        0,                      /* iMinPrintSpace */
        1000,                   /* iMaxPrintJobs */
@@ -611,7 +613,11 @@ static service sDefault = {
        0,                      /* iAioReadSize */
        0,                      /* iAioWriteSize */
        MAP_READONLY_YES,       /* iMap_readonly */
-       
+#ifdef BROKEN_DIRECTORY_HANDLING
+       0,                      /* iDirectoryNameCacheSize */
+#else
+       100,                    /* iDirectoryNameCacheSize */
+#endif
        NULL,                   /* Parametric options */
 
        ""                      /* dummy */
@@ -978,6 +984,7 @@ static struct parm_struct parm_table[] = {
        {"debug hires timestamp", P_BOOL, P_GLOBAL, &Globals.bDebugHiresTimestamp, NULL, NULL, FLAG_ADVANCED}, 
        {"debug pid", P_BOOL, P_GLOBAL, &Globals.bDebugPid, NULL, NULL, FLAG_ADVANCED}, 
        {"debug uid", P_BOOL, P_GLOBAL, &Globals.bDebugUid, NULL, NULL, FLAG_ADVANCED}, 
+       {"debug class", P_BOOL, P_GLOBAL, &Globals.bDebugClass, NULL, NULL, FLAG_ADVANCED},
        {"enable core files", P_BOOL, P_GLOBAL, &Globals.bEnableCoreFiles, NULL, NULL, FLAG_ADVANCED},
 
        {N_("Protocol Options"), P_SEP, P_SEPARATOR}, 
@@ -985,6 +992,7 @@ static struct parm_struct parm_table[] = {
        {"allocation roundup size", P_INTEGER, P_LOCAL, &sDefault.iallocation_roundup_size, NULL, NULL, FLAG_ADVANCED}, 
        {"aio read size", P_INTEGER, P_LOCAL, &sDefault.iAioReadSize, NULL, NULL, FLAG_ADVANCED}, 
        {"aio write size", P_INTEGER, P_LOCAL, &sDefault.iAioWriteSize, NULL, NULL, FLAG_ADVANCED}, 
+       {"aio write behind", P_STRING, P_LOCAL, &sDefault.szAioWriteBehind, NULL, NULL, FLAG_ADVANCED | FLAG_SHARE | FLAG_GLOBAL }, 
        {"smb ports", P_STRING, P_GLOBAL, &Globals.smb_ports, NULL, NULL, FLAG_ADVANCED}, 
        {"large readwrite", P_BOOL, P_GLOBAL, &Globals.bLargeReadwrite, NULL, NULL, FLAG_ADVANCED}, 
        {"max protocol", P_ENUM, P_GLOBAL, &Globals.maxprotocol, NULL, enum_protocol, FLAG_ADVANCED}, 
@@ -1029,8 +1037,9 @@ static struct parm_struct parm_table[] = {
        {"block size", P_INTEGER, P_LOCAL, &sDefault.iBlock_size, NULL, NULL, FLAG_ADVANCED | FLAG_SHARE | FLAG_GLOBAL}, 
        {"deadtime", P_INTEGER, P_GLOBAL, &Globals.deadtime, NULL, NULL, FLAG_ADVANCED}, 
        {"getwd cache", P_BOOL, P_GLOBAL, &use_getwd_cache, NULL, NULL, FLAG_ADVANCED}, 
-       {"keepalive", P_INTEGER, P_GLOBAL, &Globals.iKeepalive, NULL, NULL, FLAG_ADVANCED}, 
+       {"keepalive", P_INTEGER, P_GLOBAL, &Globals.iKeepalive, NULL, NULL, FLAG_ADVANCED},
        {"change notify", P_BOOL, P_LOCAL, &sDefault.bChangeNotify, NULL, NULL, FLAG_ADVANCED | FLAG_SHARE },
+       {"directory name cache size", P_INTEGER, P_LOCAL, &sDefault.iDirectoryNameCacheSize, NULL, NULL, FLAG_ADVANCED | FLAG_SHARE },
        {"kernel change notify", P_BOOL, P_LOCAL, &sDefault.bKernelChangeNotify, NULL, NULL, FLAG_ADVANCED | FLAG_SHARE },
 
        {"lpq cache time", P_INTEGER, P_GLOBAL, &Globals.lpqcachetime, NULL, NULL, FLAG_ADVANCED}, 
@@ -1116,7 +1125,6 @@ static struct parm_struct parm_table[] = {
        {"map system", P_BOOL, P_LOCAL, &sDefault.bMap_system, NULL, NULL, FLAG_ADVANCED | FLAG_SHARE | FLAG_GLOBAL}, 
        {"map readonly", P_ENUM, P_LOCAL, &sDefault.iMap_readonly, NULL, enum_map_readonly, FLAG_ADVANCED | FLAG_SHARE | FLAG_GLOBAL}, 
        {"mangled names", P_BOOL, P_LOCAL, &sDefault.bMangledNames, NULL, NULL, FLAG_ADVANCED | FLAG_SHARE | FLAG_GLOBAL}, 
-       {"mangled map", P_STRING, P_LOCAL, &sDefault.szMangledMap, NULL, NULL, FLAG_ADVANCED | FLAG_SHARE | FLAG_GLOBAL | FLAG_DEPRECATED }, 
        {"max stat cache size", P_INTEGER, P_GLOBAL, &Globals.iMaxStatCacheSize, NULL, NULL, FLAG_ADVANCED}, 
        {"stat cache", P_BOOL, P_GLOBAL, &Globals.bStatCache, NULL, NULL, FLAG_ADVANCED}, 
        {"store dos attributes", P_BOOL, P_LOCAL, &sDefault.bStoreDosAttributes, NULL, NULL, FLAG_ADVANCED | FLAG_SHARE | FLAG_GLOBAL}, 
@@ -1544,6 +1552,7 @@ static void init_globals(BOOL first_time_only)
        Globals.bDebugHiresTimestamp = False;
        Globals.bDebugPid = False;
        Globals.bDebugUid = False;
+       Globals.bDebugClass = False;
        Globals.bEnableCoreFiles = True;
        Globals.max_ttl = 60 * 60 * 24 * 3;     /* 3 days default. */
        Globals.max_wins_ttl = 60 * 60 * 24 * 6;        /* 6 days default. */
@@ -1571,10 +1580,10 @@ static void init_globals(BOOL first_time_only)
        Globals.bStatCache = True;      /* use stat cache by default */
        Globals.iMaxStatCacheSize = 1024; /* one Meg by default. */
        Globals.restrict_anonymous = 0;
-       Globals.bClientLanManAuth = True;       /* Do use the LanMan hash if it is available */
-       Globals.bClientPlaintextAuth = True;    /* Do use a plaintext password if is requested by the server */
-       Globals.bLanmanAuth = True;     /* Do use the LanMan hash if it is available */
-       Globals.bNTLMAuth = True;       /* Do use NTLMv1 if it is available (otherwise NTLMv2) */
+       Globals.bClientLanManAuth = False;      /* Do NOT use the LanMan hash if it is available */
+       Globals.bClientPlaintextAuth = False;   /* Do NOT use a plaintext password even if is requested by the server */
+       Globals.bLanmanAuth = False;    /* Do NOT use the LanMan hash, even if it is supplied */
+       Globals.bNTLMAuth = True;       /* Do use NTLMv1 if it is supplied by the client (otherwise NTLMv2) */
        Globals.bClientNTLMv2Auth = False; /* Client should not use NTLMv2, as we can't tell that the server supports it. */
        /* Note, that we will use NTLM2 session security (which is different), if it is available */
 
@@ -1660,7 +1669,7 @@ static void init_globals(BOOL first_time_only)
        Globals.bWinbindUseDefaultDomain = False;
        Globals.bWinbindTrustedDomainsOnly = False;
        Globals.bWinbindNestedGroups = True;
-       Globals.winbind_expand_groups = 1;      
+       Globals.winbind_expand_groups = 1;
        Globals.szWinbindNssInfo = str_list_make("template", NULL);
        Globals.bWinbindRefreshTickets = False;
        Globals.bWinbindOfflineLogon = False;
@@ -1702,33 +1711,6 @@ static void init_globals(BOOL first_time_only)
        Globals.bRegistryShares = False;
 }
 
-static TALLOC_CTX *lp_talloc;
-
-/******************************************************************* a
- Free up temporary memory - called from the main loop.
-********************************************************************/
-
-void lp_TALLOC_FREE(void)
-{
-       if (!lp_talloc)
-               return;
-       TALLOC_FREE(lp_talloc);
-       lp_talloc = NULL;
-}
-
-TALLOC_CTX *tmp_talloc_ctx(void)
-{
-       if (lp_talloc == NULL) {
-               lp_talloc = talloc_init("tmp_talloc_ctx");
-       }
-
-       if (lp_talloc == NULL) {
-               smb_panic("Could not create temporary talloc context");
-       }
-
-       return lp_talloc;
-}
-
 /*******************************************************************
  Convenience routine to grab string parameters into temporary memory
  and run standard_sub_basic on them. The buffers can be written to by
@@ -1748,9 +1730,6 @@ static char *lp_string(const char *s)
        DEBUG(10, ("lp_string(%s)\n", s));
 #endif
 
-       if (!lp_talloc)
-               lp_talloc = talloc_init("lp_talloc");
-
        tmpstr = alloc_sub_basic(get_current_username(),
                                 current_user_info.domain, s);
        if (trim_char(tmpstr, '\"', '\"')) {
@@ -1760,7 +1739,7 @@ static char *lp_string(const char *s)
                                                 current_user_info.domain, s);
                }
        }
-       ret = talloc_strdup(lp_talloc, tmpstr);
+       ret = talloc_strdup(talloc_tos(), tmpstr);
        SAFE_FREE(tmpstr);
                        
        return (ret);
@@ -1985,6 +1964,7 @@ FN_GLOBAL_BOOL(lp_debug_prefix_timestamp, &Globals.bDebugPrefixTimestamp)
 FN_GLOBAL_BOOL(lp_debug_hires_timestamp, &Globals.bDebugHiresTimestamp)
 FN_GLOBAL_BOOL(lp_debug_pid, &Globals.bDebugPid)
 FN_GLOBAL_BOOL(lp_debug_uid, &Globals.bDebugUid)
+FN_GLOBAL_BOOL(lp_debug_class, &Globals.bDebugClass)
 FN_GLOBAL_BOOL(lp_enable_core_files, &Globals.bEnableCoreFiles)
 FN_GLOBAL_BOOL(lp_browse_list, &Globals.bBrowseList)
 FN_GLOBAL_BOOL(lp_nis_home_map, &Globals.bNISHomeMap)
@@ -2092,11 +2072,11 @@ FN_LOCAL_STRING(lp_fstype, fstype)
 FN_LOCAL_LIST(lp_vfs_objects, szVfsObjects)
 FN_LOCAL_STRING(lp_msdfs_proxy, szMSDfsProxy)
 static FN_LOCAL_STRING(lp_volume, volume)
-FN_LOCAL_PARM_STRING(lp_mangled_map, szMangledMap)
 FN_LOCAL_STRING(lp_veto_files, szVetoFiles)
 FN_LOCAL_STRING(lp_hide_files, szHideFiles)
 FN_LOCAL_STRING(lp_veto_oplocks, szVetoOplockFiles)
 FN_LOCAL_BOOL(lp_msdfs_root, bMSDfsRoot)
+FN_LOCAL_STRING(lp_aio_write_behind, szAioWriteBehind)
 FN_LOCAL_STRING(lp_dfree_command, szDfree)
 FN_LOCAL_BOOL(lp_autoloaded, autoloaded)
 FN_LOCAL_BOOL(lp_preexec_close, bPreexecClose)
@@ -2178,6 +2158,7 @@ FN_LOCAL_INTEGER(lp_allocation_roundup_size, iallocation_roundup_size)
 FN_LOCAL_INTEGER(lp_aio_read_size, iAioReadSize)
 FN_LOCAL_INTEGER(lp_aio_write_size, iAioWriteSize)
 FN_LOCAL_INTEGER(lp_map_readonly, iMap_readonly)
+FN_LOCAL_INTEGER(lp_directory_name_cache_size, iDirectoryNameCacheSize)
 FN_LOCAL_CHAR(lp_magicchar, magic_char)
 FN_GLOBAL_INTEGER(lp_winbind_cache_time, &Globals.winbind_cache_time)
 FN_GLOBAL_LIST(lp_winbind_nss_info, &Globals.szWinbindNssInfo)
@@ -2190,7 +2171,9 @@ FN_GLOBAL_INTEGER(lp_client_ldap_sasl_wrapping, &Globals.client_ldap_sasl_wrappi
 /* local prototypes */
 
 static int map_parameter(const char *pszParmName);
+static int map_parameter_canonical(const char *pszParmName, BOOL *inverse);
 static BOOL set_boolean(BOOL *pb, const char *pszParmValue);
+static const char *get_boolean(BOOL bool_value);
 static int getservicebyname(const char *pszServiceName,
                            service * pserviceDest);
 static void copy_service(service * pserviceDest,
@@ -2201,6 +2184,8 @@ static void init_copymap(service * pservice);
 static BOOL hash_a_service(const char *name, int number);
 static void free_service_byindex(int iService);
 static char * canonicalize_servicename(const char *name);
+static void show_parameter(int parmIndex);
+static BOOL is_synonym_of(int parm1, int parm2, BOOL *inverse);
 
 /* This is a helper function for parametrical options support. */
 /* It returns a pointer to parametrical option value if it exists or NULL otherwise */
@@ -2341,7 +2326,7 @@ static int lp_enum(const char *s,const struct enum_list *_enum)
 
 /* Return parametric option from a given service. Type is a part of option before ':' */
 /* Parametric option has following syntax: 'Type: option = value' */
-/* the returned value is talloced in lp_talloc */
+/* the returned value is talloced on the talloc_tos() */
 char *lp_parm_talloc_string(int snum, const char *type, const char *option, const char *def)
 {
        param_opt_struct *data = get_parametrics(snum, type, option);
@@ -2612,7 +2597,7 @@ static int add_a_service(const service *pservice, const char *name)
 }
 
 /***************************************************************************
-  Canonicalize by converting to lowercase.
+  Convert a string to uppercase and remove whitespaces.
 ***************************************************************************/
 
 static char *canonicalize_servicename(const char *src)
@@ -2813,6 +2798,95 @@ BOOL lp_parameter_is_global(const char *pszParmName)
        return False;
 }
 
+/**************************************************************************
+ Check whether the given name is the canonical name of a parameter.
+ Returns False if it is not a valid parameter Name.
+ For parametric options, True is returned.
+**************************************************************************/
+
+BOOL lp_parameter_is_canonical(const char *parm_name)
+{
+       if (!lp_parameter_is_valid(parm_name)) {
+               return False;
+       }
+
+       return (map_parameter(parm_name) ==
+               map_parameter_canonical(parm_name, NULL));
+}
+
+/**************************************************************************
+ Determine the canonical name for a parameter.
+ Indicate when it is an inverse (boolean) synonym instead of a
+ "usual" synonym.
+**************************************************************************/
+
+BOOL lp_canonicalize_parameter(const char *parm_name, const char **canon_parm,
+                              BOOL *inverse)
+{
+       int num;
+
+       if (!lp_parameter_is_valid(parm_name)) {
+               *canon_parm = NULL;
+               return False;
+       }
+
+       num = map_parameter_canonical(parm_name, inverse);
+       if (num < 0) {
+               /* parametric option */
+               *canon_parm = parm_name;
+       } else {
+               *canon_parm = parm_table[num].label;
+       }
+
+       return True;
+
+}
+
+/**************************************************************************
+ Determine the canonical name for a parameter.
+ Turn the value given into the inverse boolean expression when
+ the synonym is an invers boolean synonym.
+
+ Return True if parm_name is a valid parameter name and
+ in case it is an invers boolean synonym, if the val string could
+ successfully be converted to the reverse bool.
+ Return false in all other cases.
+**************************************************************************/
+
+BOOL lp_canonicalize_parameter_with_value(const char *parm_name,
+                                         const char *val,
+                                         const char **canon_parm,
+                                         const char **canon_val)
+{
+       int num;
+       BOOL inverse;
+
+       if (!lp_parameter_is_valid(parm_name)) {
+               *canon_parm = NULL;
+               *canon_val = NULL;
+               return False;
+       }
+
+       num = map_parameter_canonical(parm_name, &inverse);
+       if (num < 0) {
+               /* parametric option */
+               *canon_parm = parm_name;
+               *canon_val = val;
+       } else {
+               *canon_parm = parm_table[num].label;
+               if (inverse) {
+                       if (!lp_invert_boolean(val, canon_val)) {
+                               *canon_val = NULL;
+                               return False;
+                       }
+               } else {
+                       *canon_val = val;
+               }
+       }
+
+       return True;
+}
+
 /***************************************************************************
  Map a parameter's string representation to something we can use. 
  Returns False if the parameter string is not recognised, else TRUE.
@@ -2839,14 +2913,75 @@ static int map_parameter(const char *pszParmName)
 }
 
 /***************************************************************************
- Show all parameter's name, type, [values,] and flags.
+ Map a parameter's string representation to the index of the canonical
+ form of the parameter (it might be a synonym).
+ Returns -1 if the parameter string is not recognised.
 ***************************************************************************/
 
-void show_parameter_list(void)
+static int map_parameter_canonical(const char *pszParmName, BOOL *inverse)
+{
+       int parm_num, canon_num;
+       BOOL loc_inverse = False;
+
+       parm_num = map_parameter(pszParmName);
+       if ((parm_num < 0) || !(parm_table[parm_num].flags & FLAG_HIDE)) {
+               /* invalid, parametric or no canidate for synonyms ... */
+               goto done;
+       }
+
+       for (canon_num = 0; parm_table[canon_num].label; canon_num++) {
+               if (is_synonym_of(parm_num, canon_num, &loc_inverse)) {
+                       parm_num = canon_num;
+                       goto done;
+               }
+       }
+
+done:
+       if (inverse != NULL) {
+               *inverse = loc_inverse;
+       }
+       return parm_num;
+}
+
+/***************************************************************************
+ return true if parameter number parm1 is a synonym of parameter
+ number parm2 (parm2 being the principal name).
+ set inverse to True if parm1 is P_BOOLREV and parm2 is P_BOOL,
+ False otherwise.
+***************************************************************************/
+
+static BOOL is_synonym_of(int parm1, int parm2, BOOL *inverse)
 {
-       int classIndex, parmIndex, enumIndex, flagIndex;
+       if ((parm_table[parm1].ptr == parm_table[parm2].ptr) &&
+           (parm_table[parm1].flags & FLAG_HIDE) &&
+           !(parm_table[parm2].flags & FLAG_HIDE))
+       {
+               if (inverse != NULL) {
+                       if ((parm_table[parm1].type == P_BOOLREV) &&
+                           (parm_table[parm2].type == P_BOOL))
+                       {
+                               *inverse = True;
+                       } else {
+                               *inverse = False;
+                       }
+               }
+               return True;
+       }
+       return False;
+}
+
+/***************************************************************************
+ Show one parameter's name, type, [values,] and flags.
+ (helper functions for show_parameter_list)
+***************************************************************************/
+
+static void show_parameter(int parmIndex)
+{
+       int enumIndex, flagIndex;
+       int parmIndex2;
        BOOL hadFlag;
-       const char *section_names[] = { "local", "global", NULL};
+       BOOL hadSyn;
+       BOOL inverse;
        const char *type[] = { "P_BOOL", "P_BOOLREV", "P_CHAR", "P_INTEGER",
                "P_OCTAL", "P_LIST", "P_STRING", "P_USTRING", "P_GSTRING",
                "P_UGSTRING", "P_ENUM", "P_SEP"};
@@ -2857,35 +2992,68 @@ void show_parameter_list(void)
                "FLAG_GLOBAL", "FLAG_WIZARD", "FLAG_ADVANCED", "FLAG_DEVELOPER",
                "FLAG_DEPRECATED", "FLAG_HIDE", "FLAG_DOS_STRING", NULL};
 
-       for ( classIndex=0; section_names[classIndex]; classIndex++) {
+       printf("%s=%s", parm_table[parmIndex].label,
+              type[parm_table[parmIndex].type]);
+       if (parm_table[parmIndex].type == P_ENUM) {
+               printf(",");
+               for (enumIndex=0;
+                    parm_table[parmIndex].enum_list[enumIndex].name;
+                    enumIndex++)
+               {
+                       printf("%s%s",
+                              enumIndex ? "|" : "",
+                              parm_table[parmIndex].enum_list[enumIndex].name);
+               }
+       }
+       printf(",");
+       hadFlag = False;
+       for (flagIndex=0; flag_names[flagIndex]; flagIndex++) {
+               if (parm_table[parmIndex].flags & flags[flagIndex]) {
+                       printf("%s%s",
+                               hadFlag ? "|" : "",
+                               flag_names[flagIndex]);
+                       hadFlag = True;
+               }
+       }
+
+       /* output synonyms */
+       hadSyn = False;
+       for (parmIndex2=0; parm_table[parmIndex2].label; parmIndex2++) {
+               if (is_synonym_of(parmIndex, parmIndex2, &inverse)) {
+                       printf(" (%ssynonym of %s)", inverse ? "inverse " : "",
+                              parm_table[parmIndex2].label);
+               } else if (is_synonym_of(parmIndex2, parmIndex, &inverse)) {
+                       if (!hadSyn) {
+                               printf(" (synonyms: ");
+                               hadSyn = True;
+                       } else {
+                               printf(", ");
+                       }
+                       printf("%s%s", parm_table[parmIndex2].label,
+                              inverse ? "[i]" : "");
+               }
+       }
+       if (hadSyn) {
+               printf(")");
+       }
+
+       printf("\n");
+}
+
+/***************************************************************************
+ Show all parameter's name, type, [values,] and flags.
+***************************************************************************/
+
+void show_parameter_list(void)
+{
+       int classIndex, parmIndex;
+       const char *section_names[] = { "local", "global", NULL};
+
+       for (classIndex=0; section_names[classIndex]; classIndex++) {
                printf("[%s]\n", section_names[classIndex]);
                for (parmIndex = 0; parm_table[parmIndex].label; parmIndex++) {
                        if (parm_table[parmIndex].p_class == classIndex) {
-                               printf("%s=%s", 
-                                       parm_table[parmIndex].label,
-                                       type[parm_table[parmIndex].type]);
-                               switch (parm_table[parmIndex].type) {
-                               case P_ENUM:
-                                       printf(",");
-                                       for (enumIndex=0; parm_table[parmIndex].enum_list[enumIndex].name; enumIndex++)
-                                               printf("%s%s",
-                                                       enumIndex ? "|" : "",
-                                                       parm_table[parmIndex].enum_list[enumIndex].name);
-                                       break;
-                               default:
-                                       break;
-                               }
-                               printf(",");
-                               hadFlag = False;
-                               for ( flagIndex=0; flag_names[flagIndex]; flagIndex++ ) {
-                                       if (parm_table[parmIndex].flags & flags[flagIndex]) {
-                                               printf("%s%s",
-                                                       hadFlag ? "|" : "",
-                                                       flag_names[flagIndex]);
-                                               hadFlag = True;
-                                       }
-                               }
-                               printf("\n");
+                               show_parameter(parmIndex);
                        }
                }
        }
@@ -2900,25 +3068,90 @@ void show_parameter_list(void)
 static BOOL set_boolean(BOOL *pb, const char *pszParmValue)
 {
        BOOL bRetval;
+       BOOL value;
 
        bRetval = True;
+       value = False;
        if (strwicmp(pszParmValue, "yes") == 0 ||
            strwicmp(pszParmValue, "true") == 0 ||
            strwicmp(pszParmValue, "1") == 0)
-               *pb = True;
+               value = True;
        else if (strwicmp(pszParmValue, "no") == 0 ||
                    strwicmp(pszParmValue, "False") == 0 ||
                    strwicmp(pszParmValue, "0") == 0)
-               *pb = False;
+               value = False;
        else {
-               DEBUG(0,
+               DEBUG(2,
                      ("ERROR: Badly formed boolean in configuration file: \"%s\".\n",
                       pszParmValue));
                bRetval = False;
        }
+
+       if ((pb != NULL) && (bRetval != False)) {
+               *pb = value;
+       }
+
        return (bRetval);
 }
 
+
+/***************************************************************************
+ Check if a given string correctly represents a boolean value.
+***************************************************************************/
+
+BOOL lp_string_is_valid_boolean(const char *parm_value)
+{
+       return set_boolean(NULL, parm_value);
+}
+
+/***************************************************************************
+ Get the standard string representation of a boolean value ("yes" or "no")
+***************************************************************************/
+
+static const char *get_boolean(BOOL bool_value)
+{
+       static const char *yes_str = "yes";
+       static const char *no_str = "no";
+
+       return (bool_value ? yes_str : no_str);
+}
+
+/***************************************************************************
+ Provide the string of the negated boolean value associated to the boolean
+ given as a string. Returns False if the passed string does not correctly
+ represent a boolean.
+***************************************************************************/
+
+BOOL lp_invert_boolean(const char *str, const char **inverse_str)
+{
+       BOOL val;
+
+       if (!set_boolean(&val, str)) {
+               return False;
+       }
+
+       *inverse_str = get_boolean(!val);
+       return True;
+}
+
+/***************************************************************************
+ Provide the canonical string representation of a boolean value given
+ as a string. Return True on success, False if the string given does
+ not correctly represent a boolean.
+***************************************************************************/
+
+BOOL lp_canonicalize_boolean(const char *str, const char**canon_str)
+{
+       BOOL val;
+
+       if (!set_boolean(&val, str)) {
+               return False;
+       }
+
+       *canon_str = get_boolean(val);
+       return True;
+}
+
 /***************************************************************************
 Find a service by name. Otherwise works like get_service.
 ***************************************************************************/
@@ -3105,6 +3338,7 @@ static struct tdb_wrap *lp_regdb_open(void)
        become_root();
        reg_tdb = tdb_wrap_open(NULL, lock_path("registry.tdb"), 0, 
                                REG_TDB_FLAGS, O_RDWR, 0600);
+       unbecome_root();
        if (!reg_tdb) {
                DEBUG(1, ("lp_regdb_open: failed to open %s: %s\n",
                         lock_path("registry.tdb"), strerror(errno)));
@@ -3113,7 +3347,6 @@ static struct tdb_wrap *lp_regdb_open(void)
        else {
                DEBUG(10, ("lp_regdb_open: reg tdb opened.\n"));
        }
-       unbecome_root();
 
        vers_id = tdb_fetch_int32(reg_tdb->tdb, vstring);
        if (vers_id != REGVER_V1) {
@@ -3658,10 +3891,8 @@ static const char *append_ldap_suffix( const char *str )
        const char *suffix_string;
 
 
-       if (!lp_talloc)
-               lp_talloc = talloc_init("lp_talloc");
-
-       suffix_string = talloc_asprintf( lp_talloc, "%s,%s", str, Globals.szLdapSuffix );
+       suffix_string = talloc_asprintf(talloc_tos(), "%s,%s", str,
+                                       Globals.szLdapSuffix );
        if ( !suffix_string ) {
                DEBUG(0,("append_ldap_suffix: talloc_asprintf() failed!\n"));
                return "";
@@ -3850,7 +4081,9 @@ BOOL lp_do_parameter(int snum, const char *pszParmName, const char *pszParmValue
                parm_ptr =
                        ((char *)ServicePtrs[snum]) + PTR_DIFF(def_ptr,
                                                            &sDefault);
+       }
 
+       if (snum >= 0) {
                if (!ServicePtrs[snum]->copymap)
                        init_copymap(ServicePtrs[snum]);
 
@@ -4320,6 +4553,22 @@ BOOL dump_a_parameter(int snum, char *parm_name, FILE * f, BOOL isGlobal)
        return result;
 }
 
+/***************************************************************************
+ Return info about the requested parameter (given as a string).
+ Return NULL when the string is not a valid parameter name.
+***************************************************************************/
+
+struct parm_struct *lp_get_parameter(const char *param_name)
+{
+       int num = map_parameter(param_name);
+
+       if (num < 0) {
+               return NULL;
+       }
+
+       return &parm_table[num];
+}
+
 /***************************************************************************
  Return info about the next parameter in a service.
  snum==GLOBAL_SECTION_SNUM gives the globals.
@@ -5274,7 +5523,7 @@ int load_usershare_shares(void)
                        /* Remove from the share ACL db. */
                        DEBUG(10,("load_usershare_shares: Removing deleted usershare %s\n",
                                lp_servicename(iService) ));
-                       delete_share_security(snum2params_static(iService));
+                       delete_share_security(lp_servicename(iService));
                        free_service_byindex(iService);
                }
        }
@@ -5292,8 +5541,6 @@ void gfree_loadparm(void)
        struct file_lists *next;
        int i;
 
-       lp_TALLOC_FREE();
-
        /* Free the file lists */
 
        f = file_lists;
@@ -5508,7 +5755,7 @@ int lp_servicenumber(const char *pszServiceName)
 
                if (!usershare_exists(iService, &last_mod)) {
                        /* Remove the share security tdb entry for it. */
-                       delete_share_security(snum2params_static(iService));
+                       delete_share_security(lp_servicename(iService));
                        /* Remove it from the array. */
                        free_service_byindex(iService);
                        /* Doesn't exist anymore. */
@@ -5637,7 +5884,7 @@ const char *volume_label(int snum)
        }
                
        /* This returns a 33 byte guarenteed null terminated string. */
-       ret = talloc_strndup(main_loop_talloc_get(), label, 32);
+       ret = talloc_strndup(talloc_tos(), label, 32);
        if (!ret) {
                return "";
        }