From: Michael Adam Date: Tue, 6 May 2008 20:20:49 +0000 (+0200) Subject: registry: make normalize_reg_path() strip leading and trailing '/' chars. X-Git-Url: http://git.samba.org/samba.git/?p=kai%2Fsamba.git;a=commitdiff_plain;h=f5cbbb5c02a53193f2ac6b3fbbf1da3bc32d6d2a;hp=120aacfac5b4f561999e84a325f53cbd5783fefc registry: make normalize_reg_path() strip leading and trailing '/' chars. Michael (This used to be commit 04762cfcdba741afa457c96cd2f24e50cf83b15a) --- diff --git a/source3/registry/reg_util.c b/source3/registry/reg_util.c index e72353e7c54..714a39f307a 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; }