From f7de0933f3770359b54ea2950be51ad9889d6bbc Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Thu, 21 Jun 2007 22:18:42 +0000 Subject: r23578: When calling DeleteKey for a key that has subkey(s), Windows returns WERR_ACCESS_DENIED. This adapts reg_deletekey to behave the same way. Michael (This used to be commit 0c9cb69b45e8c51b8c3fa0b0d034a6cad2374055) --- source3/registry/reg_api.c | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) (limited to 'source3') diff --git a/source3/registry/reg_api.c b/source3/registry/reg_api.c index 4bcc6d7303..e163759dab 100644 --- a/source3/registry/reg_api.c +++ b/source3/registry/reg_api.c @@ -386,6 +386,7 @@ WERROR reg_deletekey(struct registry_key *parent, const char *path) TALLOC_CTX *mem_ctx; char *name, *end; int num_subkeys; + struct registry_key *tmp_key; if (!(mem_ctx = talloc_init("reg_createkey"))) return WERR_NOMEM; @@ -394,18 +395,30 @@ WERROR reg_deletekey(struct registry_key *parent, const char *path) goto error; } - if ((end = strrchr(name, '\\')) != NULL) { - struct registry_key *tmp; + /* check if the key has subkeys */ + err = reg_openkey(mem_ctx, parent, name, REG_KEY_READ, &tmp_key); + if (!W_ERROR_IS_OK(err)) { + goto error; + } + if (!W_ERROR_IS_OK(err = fill_subkey_cache(tmp_key))) { + goto error; + } + if (tmp_key->subkeys->num_subkeys > 0) { + err = WERR_ACCESS_DENIED; + goto error; + } + /* no subkeys - proceed with delete */ + if ((end = strrchr(name, '\\')) != NULL) { *end = '\0'; err = reg_openkey(mem_ctx, parent, name, - SEC_RIGHTS_CREATE_SUBKEY, &tmp); + SEC_RIGHTS_CREATE_SUBKEY, &tmp_key); if (!W_ERROR_IS_OK(err)) { goto error; } - parent = tmp; + parent = tmp_key; name = end+1; } -- cgit