registry: make normalize_reg_path() strip leading and trailing '/' chars.
authorMichael Adam <obnox@samba.org>
Tue, 6 May 2008 20:20:49 +0000 (22:20 +0200)
committerMichael Adam <obnox@samba.org>
Thu, 8 May 2008 16:29:08 +0000 (18:29 +0200)
Michael
(This used to be commit 04762cfcdba741afa457c96cd2f24e50cf83b15a)

source3/registry/reg_util.c

index e72353e7c5416c5bef90b348adaf99a8c5ffe9d3..714a39f307a2adee3534598d5046c8d4f9021027 100644 (file)
@@ -83,19 +83,38 @@ bool reg_split_key(char *path, char **base, char **key)
        return true;
 }
 
-/**********************************************************************
- The full path to the registry key is used as database after the
- \'s are converted to /'s.  Key string is also normalized to UPPER
- case.
-**********************************************************************/
+/**
+ * The full path to the registry key is used as database key
+ * after the \'s are converted to /'s.
+ * Leading and trailing '/' and '\' characters are stripped.
+ * Key string is also normalized to UPPER case.
+ */
 
 char *normalize_reg_path(TALLOC_CTX *ctx, const char *keyname )
 {
-       char *nkeyname = talloc_string_sub(ctx, keyname, "\\", "/");
-       if (!nkeyname) {
+       char *p;
+       char *nkeyname;
+
+       /* skip leading '/' and '\' chars */
+       p = (char *)keyname;
+       while ((*p == '/') || (*p == '\\')) {
+               p++;
+       }
+
+       nkeyname = talloc_string_sub(ctx, p, "\\", "/");
+       if (nkeyname == NULL) {
                return NULL;
        }
+
+       /* strip trailing '/' chars */
+       p = strrchr(nkeyname, '/');
+       while ((p != NULL) && (p[1] == '\0')) {
+               *p = '\0';
+               p = strrchr(nkeyname, '/');
+       }
+
        strupper_m(nkeyname);
+
        return nkeyname;
 }