summaryrefslogtreecommitdiff
path: root/source3
diff options
context:
space:
mode:
authorMichael Adam <obnox@samba.org>2008-05-06 22:20:49 +0200
committerMichael Adam <obnox@samba.org>2008-05-08 18:29:08 +0200
commitf5cbbb5c02a53193f2ac6b3fbbf1da3bc32d6d2a (patch)
tree39d158f0cbf46993dafec4049f9fae52f4aed890 /source3
parent120aacfac5b4f561999e84a325f53cbd5783fefc (diff)
downloadsamba-f5cbbb5c02a53193f2ac6b3fbbf1da3bc32d6d2a.tar.gz
samba-f5cbbb5c02a53193f2ac6b3fbbf1da3bc32d6d2a.tar.bz2
samba-f5cbbb5c02a53193f2ac6b3fbbf1da3bc32d6d2a.zip
registry: make normalize_reg_path() strip leading and trailing '/' chars.
Michael (This used to be commit 04762cfcdba741afa457c96cd2f24e50cf83b15a)
Diffstat (limited to 'source3')
-rw-r--r--source3/registry/reg_util.c33
1 files changed, 26 insertions, 7 deletions
diff --git a/source3/registry/reg_util.c b/source3/registry/reg_util.c
index e72353e7c5..714a39f307 100644
--- a/source3/registry/reg_util.c
+++ b/source3/registry/reg_util.c
@@ -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;
}