diff --git a/source/lib/registry/ldb.c b/source/lib/registry/ldb.c index 3e98d2f..93e2861 100644 --- a/source/lib/registry/ldb.c +++ b/source/lib/registry/ldb.c @@ -452,6 +452,32 @@ static WERROR ldb_del_key(const struct hive_key *key, const char *name) struct ldb_key_data *parentkd = talloc_get_type(key, struct ldb_key_data); struct ldb_dn *ldap_path; TALLOC_CTX *mem_ctx = talloc_init("ldb_del_key"); + WERROR werr; + struct hive_key *tmp_key; + struct ldb_key_data *kd; + + /* TODO: If we want this to be consistent with the Windows behavior, we + * should provide the capability of recursive deletion. */ + /* This is currently a workaround to prevent orphaned subkeys or values + * from re-appearing when a key is created using the same name as a + * previously deleted key that contained subkeys or values. + */ + /* Begin workaround */ + werr = ldb_open_key(mem_ctx, key, name, &tmp_key); + if (! W_ERROR_IS_OK(werr)) + { + talloc_free(mem_ctx); + return werr; + } + kd = talloc_get_type(tmp_key, struct ldb_key_data); + + /* Do not allow deletion if there are subkeys or values */ + if (kd->subkey_count > 0 || kd->value_count > 0) + { + talloc_free(mem_ctx); + return WERR_ACCESS_DENIED; + } + /* End workaround */ ldap_path = reg_path_to_ldb(mem_ctx, key, name, NULL);