s3:registry: remove a superfluous fill_subkey_cache() in reg_createkey()
[ddiss/samba.git] / source3 / registry / reg_api.c
index 69b987a723d1589b683d58796a66c118a870162b..0363ca4fed777e428aaef4e36c4ebd429b1dd0a2 100644 (file)
@@ -116,7 +116,7 @@ static WERROR fill_subkey_cache(struct registry_key *key)
 
        if (fetch_reg_keys(key->key, key->subkeys) == -1) {
                TALLOC_FREE(key->subkeys);
-               return WERR_NO_MORE_ITEMS;
+               return WERR_BADFILE;
        }
 
        return WERR_OK;
@@ -137,7 +137,6 @@ static WERROR regkey_open_onelevel(TALLOC_CTX *mem_ctx,
        WERROR          result = WERR_OK;
        struct registry_key *regkey;
        struct registry_key_handle *key;
-       struct regsubkey_ctr    *subkeys = NULL;
 
        DEBUG(7,("regkey_open_onelevel: name = [%s]\n", name));
 
@@ -151,7 +150,8 @@ static WERROR regkey_open_onelevel(TALLOC_CTX *mem_ctx,
                goto done;
        }
 
-       if ( !(W_ERROR_IS_OK(result = regdb_open())) ) {
+       result = regdb_open();
+       if (!(W_ERROR_IS_OK(result))) {
                goto done;
        }
 
@@ -194,28 +194,21 @@ static WERROR regkey_open_onelevel(TALLOC_CTX *mem_ctx,
 
        /* Look up the table of registry I/O operations */
 
-       if ( !(key->ops = reghook_cache_find( key->name )) ) {
+       key->ops = reghook_cache_find( key->name );
+       if (key->ops == NULL) {
                DEBUG(0,("reg_open_onelevel: Failed to assign "
                         "registry_ops to [%s]\n", key->name ));
                result = WERR_BADFILE;
                goto done;
        }
 
-       /* check if the path really exists; failed is indicated by -1 */
-       /* if the subkey count failed, bail out */
+       /* FIXME: Existence is currently checked by fetching the subkeys */
 
-       result = regsubkey_ctr_init(key, &subkeys);
+       result = fill_subkey_cache(regkey);
        if (!W_ERROR_IS_OK(result)) {
                goto done;
        }
 
-       if ( fetch_reg_keys( key, subkeys ) == -1 )  {
-               result = WERR_BADFILE;
-               goto done;
-       }
-
-       TALLOC_FREE( subkeys );
-
        if ( !regkey_access_check( key, access_desired, &key->access_granted,
                                   token ) ) {
                result = WERR_ACCESS_DENIED;
@@ -257,13 +250,15 @@ WERROR reg_openkey(TALLOC_CTX *mem_ctx, struct registry_key *parent,
 {
        struct registry_key *direct_parent = parent;
        WERROR err;
-       char *p, *path, *to_free;
+       char *p, *path;
        size_t len;
+       TALLOC_CTX *frame = talloc_stackframe();
 
-       if (!(path = SMB_STRDUP(name))) {
-               return WERR_NOMEM;
+       path = talloc_strdup(frame, name);
+       if (path == NULL) {
+               err = WERR_NOMEM;
+               goto error;
        }
-       to_free = path;
 
        len = strlen(path);
 
@@ -275,22 +270,19 @@ WERROR reg_openkey(TALLOC_CTX *mem_ctx, struct registry_key *parent,
                char *name_component;
                struct registry_key *tmp;
 
-               if (!(name_component = SMB_STRNDUP(path, (p - path)))) {
+               name_component = talloc_strndup(frame, path, (p - path));
+               if (name_component == NULL) {
                        err = WERR_NOMEM;
                        goto error;
                }
 
-               err = regkey_open_onelevel(mem_ctx, direct_parent,
+               err = regkey_open_onelevel(frame, direct_parent,
                                           name_component, parent->token,
                                           KEY_ENUMERATE_SUB_KEYS, &tmp);
-               SAFE_FREE(name_component);
 
                if (!W_ERROR_IS_OK(err)) {
                        goto error;
                }
-               if (direct_parent != parent) {
-                       TALLOC_FREE(direct_parent);
-               }
 
                direct_parent = tmp;
                path = p+1;
@@ -298,11 +290,9 @@ WERROR reg_openkey(TALLOC_CTX *mem_ctx, struct registry_key *parent,
 
        err = regkey_open_onelevel(mem_ctx, direct_parent, path, parent->token,
                                   desired_access, pkey);
- error:
-       if (direct_parent != parent) {
-               TALLOC_FREE(direct_parent);
-       }
-       SAFE_FREE(to_free);
+
+error:
+       talloc_free(frame);
        return err;
 }
 
@@ -641,11 +631,6 @@ WERROR reg_createkey(TALLOC_CTX *ctx, struct registry_key *parent,
         * Actually create the subkey
         */
 
-       err = fill_subkey_cache(create_parent);
-       if (!W_ERROR_IS_OK(err)) {
-               goto trans_done;
-       }
-
        err = create_reg_subkey(key->key, path);
        if (!W_ERROR_IS_OK(err)) {
                goto trans_done;