From 57484f56c0bf4a380de33fd12cd5a2ee57aeeb66 Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Tue, 10 Jul 2007 21:35:20 +0000 Subject: r23821: Extend the winreg test by a test for DeleteKey on a key that has subkeys. This should return WERR_ACCESS_DENIED. Michael (This used to be commit 9b8789a4b5f444e643ed7ee3ff55dc0c41986d07) --- source4/torture/rpc/winreg.c | 66 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/source4/torture/rpc/winreg.c b/source4/torture/rpc/winreg.c index d438a8b8ed..143be6defc 100644 --- a/source4/torture/rpc/winreg.c +++ b/source4/torture/rpc/winreg.c @@ -29,6 +29,8 @@ #define TEST_KEY_BASE "smbtorture test" #define TEST_KEY1 TEST_KEY_BASE "\\spottyfoot" #define TEST_KEY2 TEST_KEY_BASE "\\with a SD (#1)" +#define TEST_KEY3 TEST_KEY_BASE "\\with a subkey" +#define TEST_SUBKEY TEST_KEY3 "\\subkey" static void init_initshutdown_String(TALLOC_CTX *mem_ctx, struct initshutdown_String *name, const char *s) { @@ -368,6 +370,35 @@ static bool test_DeleteKey(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, return true; } +/* DeleteKey on a key with subkey(s) should + * return WERR_ACCESS_DENIED. */ +static bool test_DeleteKeyWithSubkey(struct dcerpc_pipe *p, + TALLOC_CTX* mem_ctx, + struct policy_handle *handle, const char *key) +{ + NTSTATUS status; + struct winreg_DeleteKey r; + + printf("\ntesting DeleteKeyWithSubkey\n"); + + r.in.handle = handle; + init_winreg_String(&r.in.key, key); + + status = dcerpc_winreg_DeleteKey(p, mem_ctx, &r); + + if (!NT_STATUS_IS_OK(status)) { + printf("DeleteKeyWithSubkey failed - %s\n", nt_errstr(status)); + return false; + } + + if (!W_ERROR_EQUAL(r.out.result, WERR_ACCESS_DENIED)) { + printf("DeleteKeyWithSubkey failed - %s\n", win_errstr(r.out.result)); + return false; + } + + return true; +} + static bool test_QueryInfoKey(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, struct policy_handle *handle, char *class) { @@ -709,6 +740,7 @@ static bool test_Open(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, { struct policy_handle handle, newhandle; bool ret = true, created = false, created2 = false, deleted = false; + bool created3 = false, created_subkey = false; struct winreg_OpenHKLM r; NTSTATUS status; @@ -725,6 +757,8 @@ static bool test_Open(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, test_Cleanup(p, mem_ctx, &handle, TEST_KEY1); test_Cleanup(p, mem_ctx, &handle, TEST_KEY2); + test_Cleanup(p, mem_ctx, &handle, TEST_SUBKEY); + test_Cleanup(p, mem_ctx, &handle, TEST_KEY3); test_Cleanup(p, mem_ctx, &handle, TEST_KEY_BASE); if (!test_CreateKey(p, mem_ctx, &handle, TEST_KEY1, NULL)) { @@ -786,6 +820,38 @@ static bool test_Open(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, ret = false; } + if (created && test_CreateKey(p, mem_ctx, &handle, TEST_KEY3, NULL)) { + created3 = true; + } + + if (created3 && + test_CreateKey(p, mem_ctx, &handle, TEST_SUBKEY, NULL)) + { + created_subkey = true; + } + + if (created_subkey && + !test_DeleteKeyWithSubkey(p, mem_ctx, &handle, TEST_KEY3)) + { + printf("DeleteKeyWithSubkey failed " + "(DeleteKey didn't return ACCESS_DENIED)\n"); + ret = false; + } + + if (created_subkey && + !test_DeleteKey(p, mem_ctx, &handle, TEST_SUBKEY)) + { + printf("DeleteKey failed\n"); + ret = false; + } + + if (created3 && + !test_DeleteKey(p, mem_ctx, &handle, TEST_KEY3)) + { + printf("DeleteKey failed\n"); + ret = false; + } + /* The HKCR hive has a very large fanout */ if (open_fn == (void *)dcerpc_winreg_OpenHKCR) { -- cgit