s3-registry: Convert registry key delimiter from slash to backslash.
authorAndreas Schneider <asn@samba.org>
Thu, 24 Jun 2010 14:33:37 +0000 (16:33 +0200)
committerMichael Adam <obnox@samba.org>
Fri, 25 Jun 2010 15:35:41 +0000 (17:35 +0200)
This is needed to support keynames containing a '/' like TCP/IP. Which
is used in serveral standard paths.

Signed-off-by: Michael Adam <obnox@samba.org>
source3/lib/adt_tree.c
source3/registry/reg_api.c
source3/registry/reg_backend_db.c
source3/registry/reg_cachehook.c
source3/registry/reg_util_internal.c

index 7f4a39de6e510c811276d2450ff716a9b112ae64..6d481613c7b93a6683a89b5a46fe753ebfbd4f2f 100644 (file)
@@ -46,7 +46,7 @@ static bool trim_tree_keypath( char *path, char **base, char **new_path )
 
        *base = path;
 
-       p = strchr( path, '/' );
+       p = strchr( path, '\\' );
 
        if ( p ) {
                *p = '\0';
@@ -214,7 +214,7 @@ WERROR pathtree_add(struct sorted_tree *tree, const char *path, void *data_p)
 
        DEBUG(8,("pathtree_add: Enter\n"));
 
-       if ( !path || *path != '/' ) {
+       if ( !path || *path != '\\' ) {
                DEBUG(0,("pathtree_add: Attempt to add a node with a bad path [%s]\n",
                        path ? path : "NULL" ));
                return WERR_INVALID_PARAM;
@@ -225,7 +225,7 @@ WERROR pathtree_add(struct sorted_tree *tree, const char *path, void *data_p)
                return WERR_INVALID_PARAM;
        }
 
-       /* move past the first '/' */
+       /* move past the first '\\' */
 
        path++; 
        path2 = SMB_STRDUP( path );
@@ -248,7 +248,7 @@ WERROR pathtree_add(struct sorted_tree *tree, const char *path, void *data_p)
        do {
                /* break off the remaining part of the path */
 
-               str = strchr( str, '/' );
+               str = strchr( str, '\\' );
                if ( str )
                        *str = '\0';
 
@@ -269,7 +269,7 @@ WERROR pathtree_add(struct sorted_tree *tree, const char *path, void *data_p)
 
                base = str;
                if ( base ) {
-                       *base = '/';
+                       *base = '\\';
                        base++;
                        str = base;
                }
@@ -384,7 +384,7 @@ void* pathtree_find(struct sorted_tree *tree, char *key )
 
        /* make a copy to play with */
 
-       if ( *key == '/' )
+       if ( *key == '\\' )
                keystr = SMB_STRDUP( key+1 );
        else
                keystr = SMB_STRDUP( key );
index e380a0d6e23d5097eb84def133bf8b7fc647b769..79b9a1eb2bcfd687867b77ac984d67495309e018 100644 (file)
@@ -475,16 +475,6 @@ WERROR reg_createkey(TALLOC_CTX *ctx, struct registry_key *parent,
        char *path, *end;
        WERROR err;
 
-       /*
-        * We must refuse to handle subkey-paths containing
-        * a '/' character because at a lower level, after
-        * normalization, '/' is treated as a key separator
-        * just like '\\'.
-        */
-       if (strchr(subkeypath, '/') != NULL) {
-               return WERR_INVALID_PARAM;
-       }
-
        if (!(mem_ctx = talloc_new(ctx))) return WERR_NOMEM;
 
        if (!(path = talloc_strdup(mem_ctx, subkeypath))) {
index 9e6dbcbff31e494089ffe0772d6aa01261840ae7..e861d46d8814db513926994f175c193e254bb06c 100644 (file)
@@ -641,7 +641,7 @@ static WERROR regdb_delete_key_with_prefix(struct db_context *db,
        if (prefix == NULL) {
                path = discard_const_p(char, keyname);
        } else {
-               path = talloc_asprintf(mem_ctx, "%s/%s", prefix, keyname);
+               path = talloc_asprintf(mem_ctx, "%s\\%s", prefix, keyname);
                if (path == NULL) {
                        goto done;
                }
@@ -686,14 +686,14 @@ static WERROR regdb_delete_key_lists(struct db_context *db, const char *keyname)
 
        werr = regdb_delete_values(db, keyname);
        if (!W_ERROR_IS_OK(werr)) {
-               DEBUG(1, (__location__ " Deleting %s/%s failed: %s\n",
+               DEBUG(1, (__location__ " Deleting %s\\%s failed: %s\n",
                          REG_VALUE_PREFIX, keyname, win_errstr(werr)));
                goto done;
        }
 
        werr = regdb_delete_secdesc(db, keyname);
        if (!W_ERROR_IS_OK(werr)) {
-               DEBUG(1, (__location__ " Deleting %s/%s failed: %s\n",
+               DEBUG(1, (__location__ " Deleting %s\\%s failed: %s\n",
                          REG_SECDESC_PREFIX, keyname, win_errstr(werr)));
                goto done;
        }
@@ -806,7 +806,7 @@ static WERROR regdb_store_keys_internal2(struct db_context *db,
         * Delete a sorted subkey cache for regdb_key_exists, will be
         * recreated automatically
         */
-       keyname = talloc_asprintf(ctx, "%s/%s", REG_SORTED_SUBKEYS_PREFIX,
+       keyname = talloc_asprintf(ctx, "%s\\%s", REG_SORTED_SUBKEYS_PREFIX,
                                  keyname);
        if (keyname == NULL) {
                werr = WERR_NOMEM;
@@ -897,7 +897,7 @@ static NTSTATUS regdb_store_keys_action(struct db_context *db,
                        continue;
                }
 
-               path = talloc_asprintf(mem_ctx, "%s/%s", store_ctx->key,
+               path = talloc_asprintf(mem_ctx, "%s\\%s", store_ctx->key,
                                       oldkeyname);
                if (!path) {
                        werr = WERR_NOMEM;
@@ -941,7 +941,7 @@ static NTSTATUS regdb_store_keys_action(struct db_context *db,
        }
 
        for (i=0; i<num_subkeys; i++) {
-               path = talloc_asprintf(mem_ctx, "%s/%s", store_ctx->key,
+               path = talloc_asprintf(mem_ctx, "%s\\%s", store_ctx->key,
                                regsubkey_ctr_specific_key(store_ctx->ctr, i));
                if (!path) {
                        werr = WERR_NOMEM;
@@ -1184,7 +1184,7 @@ static WERROR regdb_delete_subkey(const char *key, const char *subkey)
                goto done;
        }
 
-       path = talloc_asprintf(mem_ctx, "%s/%s", key, subkey);
+       path = talloc_asprintf(mem_ctx, "%s\\%s", key, subkey);
        if (path == NULL) {
                werr = WERR_NOMEM;
                goto done;
@@ -1228,7 +1228,7 @@ static TDB_DATA regdb_fetch_key_internal(struct db_context *db,
 
 /**
  * check whether a given key name represents a base key,
- * i.e one without a subkey separator ('/' or '\').
+ * i.e one without a subkey separator ('\').
  */
 static bool regdb_key_is_base_key(const char *key)
 {
@@ -1250,7 +1250,7 @@ static bool regdb_key_is_base_key(const char *key)
                goto done;
        }
 
-       ret = (strrchr(path, '/') == NULL);
+       ret = (strrchr(path, '\\') == NULL);
 
 done:
        TALLOC_FREE(mem_ctx);
@@ -1453,7 +1453,7 @@ static bool scan_parent_subkeys(struct db_context *db, const char *parent,
                goto fail;
        }
 
-       key = talloc_asprintf(talloc_tos(), "%s/%s",
+       key = talloc_asprintf(talloc_tos(), "%s\\%s",
                              REG_SORTED_SUBKEYS_PREFIX, path);
        if (key == NULL) {
                goto fail;
@@ -1533,7 +1533,7 @@ static bool regdb_key_exists(struct db_context *db, const char *key)
                goto done;
        }
 
-       p = strrchr(path, '/');
+       p = strrchr(path, '\\');
        if (p == NULL) {
                /* this is a base key */
                value = regdb_fetch_key_internal(db, mem_ctx, path);
@@ -1727,7 +1727,7 @@ static int regdb_fetch_values_internal(struct db_context *db, const char* key,
                goto done;
        }
 
-       keystr = talloc_asprintf(ctx, "%s/%s", REG_VALUE_PREFIX, key);
+       keystr = talloc_asprintf(ctx, "%s\\%s", REG_VALUE_PREFIX, key);
        if (!keystr) {
                goto done;
        }
@@ -1786,7 +1786,7 @@ static bool regdb_store_values_internal(struct db_context *db, const char *key,
 
        SMB_ASSERT( len == data.dsize );
 
-       keystr = talloc_asprintf(ctx, "%s/%s", REG_VALUE_PREFIX, key );
+       keystr = talloc_asprintf(ctx, "%s\\%s", REG_VALUE_PREFIX, key );
        if (!keystr) {
                goto done;
        }
@@ -1835,7 +1835,7 @@ static WERROR regdb_get_secdesc(TALLOC_CTX *mem_ctx, const char *key,
                goto done;
        }
 
-       tdbkey = talloc_asprintf(tmp_ctx, "%s/%s", REG_SECDESC_PREFIX, key);
+       tdbkey = talloc_asprintf(tmp_ctx, "%s\\%s", REG_SECDESC_PREFIX, key);
        if (tdbkey == NULL) {
                err = WERR_NOMEM;
                goto done;
@@ -1880,7 +1880,7 @@ static WERROR regdb_set_secdesc(const char *key,
                goto done;
        }
 
-       tdbkey = talloc_asprintf(mem_ctx, "%s/%s", REG_SECDESC_PREFIX, key);
+       tdbkey = talloc_asprintf(mem_ctx, "%s\\%s", REG_SECDESC_PREFIX, key);
        if (tdbkey == NULL) {
                goto done;
        }
index 6b00ab4aa17024933f437eed128097006435eb24..dc07b51944e9a64ca6be736b0d7152733bcd7224 100644 (file)
@@ -46,12 +46,6 @@ static WERROR keyname_to_path(TALLOC_CTX *mem_ctx, const char *keyname,
                return WERR_NOMEM;
        }
 
-       tmp_path = talloc_string_sub(mem_ctx, tmp_path, "\\", "/");
-       if (tmp_path == NULL) {
-               DEBUG(0, ("talloc_string_sub_failed!\n"));
-               return WERR_NOMEM;
-       }
-
        *path = tmp_path;
 
        return WERR_OK;
index 47e2ce576fbba55fefa269a11a4799991acc31b5..a1aeaa405cda7647450c31af18f9d6824a5b1a89 100644 (file)
@@ -86,9 +86,8 @@ bool reg_split_key(char *path, char **base, char **key)
 }
 
 /**
- * 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.
+ * The full path to the registry key is used as database key.
+ * Leading and trailing '\' characters are stripped.
  * Key string is also normalized to UPPER case.
  */
 
@@ -97,22 +96,22 @@ char *normalize_reg_path(TALLOC_CTX *ctx, const char *keyname )
        char *p;
        char *nkeyname;
 
-       /* skip leading '/' and '\' chars */
+       /* skip leading '\' chars */
        p = (char *)keyname;
-       while ((*p == '/') || (*p == '\\')) {
+       while (*p == '\\') {
                p++;
        }
 
-       nkeyname = talloc_string_sub(ctx, p, "\\", "/");
+       nkeyname = talloc_strdup(ctx, p);
        if (nkeyname == NULL) {
                return NULL;
        }
 
-       /* strip trailing '/' chars */
-       p = strrchr(nkeyname, '/');
+       /* strip trailing '\' chars */
+       p = strrchr(nkeyname, '\\');
        while ((p != NULL) && (p[1] == '\0')) {
                *p = '\0';
-               p = strrchr(nkeyname, '/');
+               p = strrchr(nkeyname, '\\');
        }
 
        strupper_m(nkeyname);
@@ -139,11 +138,7 @@ char *reg_remaining_path(TALLOC_CTX *ctx, const char *key)
        }
        /* normalize_reg_path( new_path ); */
        if (!(p = strchr(new_path, '\\')) ) {
-               if (!(p = strchr( new_path, '/'))) {
-                       p = new_path;
-               } else {
-                       p++;
-               }
+               p = new_path;
        } else {
                p++;
        }