Signed-off-by: Hugh McMaster hugh.mcmaster@outlook.com --- programs/reg/delete.c | 22 ++++++++++++++++++---- programs/reg/tests/delete.c | 28 ++++++++++++++-------------- 2 files changed, 32 insertions(+), 18 deletions(-)
diff --git a/programs/reg/delete.c b/programs/reg/delete.c index 8804e16e52f..f6965493faa 100644 --- a/programs/reg/delete.c +++ b/programs/reg/delete.c @@ -35,7 +35,7 @@ static void output_error(LONG rc) } }
-static int run_delete(HKEY root, WCHAR *path, WCHAR *key_name, WCHAR *value_name, +static int run_delete(HKEY root, WCHAR *path, REGSAM sam, WCHAR *key_name, WCHAR *value_name, BOOL value_empty, BOOL value_all, BOOL force) { LONG rc; @@ -72,7 +72,7 @@ static int run_delete(HKEY root, WCHAR *path, WCHAR *key_name, WCHAR *value_name return 0; }
- if ((rc = RegOpenKeyExW(root, path, 0, KEY_READ|KEY_SET_VALUE, &hkey))) + if ((rc = RegOpenKeyExW(root, path, 0, KEY_READ|KEY_SET_VALUE|sam, &hkey))) { output_error(rc); return 1; @@ -132,6 +132,7 @@ int reg_delete(int argc, WCHAR *argvW[]) HKEY root; WCHAR *path, *key_name, *value_name = NULL; BOOL value_all = FALSE, value_empty = FALSE, force = FALSE; + REGSAM sam = 0; int i;
if (!parse_registry_key(argvW[2], &root, &path)) @@ -158,8 +159,18 @@ int reg_delete(int argc, WCHAR *argvW[]) value_empty = TRUE; continue; } - else if (!lstrcmpiW(str, L"reg:32") || !lstrcmpiW(str, L"reg:64")) + else if (!lstrcmpiW(str, L"reg:32")) + { + if (sam & KEY_WOW64_32KEY) goto invalid; + sam |= KEY_WOW64_32KEY; + continue; + } + else if (!lstrcmpiW(str, L"reg:64")) + { + if (sam & KEY_WOW64_64KEY) goto invalid; + sam |= KEY_WOW64_64KEY; continue; + } else if (!str[0] || str[1]) goto invalid;
@@ -181,9 +192,12 @@ int reg_delete(int argc, WCHAR *argvW[]) if ((value_name && value_empty) || (value_name && value_all) || (value_empty && value_all)) goto invalid;
+ if (sam == (KEY_WOW64_32KEY|KEY_WOW64_64KEY)) + goto invalid; + key_name = get_long_key(root, path);
- return run_delete(root, path, key_name, value_name, value_empty, value_all, force); + return run_delete(root, path, sam, key_name, value_name, value_empty, value_all, force);
invalid: output_message(STRING_INVALID_SYNTAX); diff --git a/programs/reg/tests/delete.c b/programs/reg/tests/delete.c index d6a3b7e1d04..102fc0d788a 100644 --- a/programs/reg/tests/delete.c +++ b/programs/reg/tests/delete.c @@ -270,17 +270,17 @@ static void test_registry_view_win64(void) open_key(HKEY_LOCAL_MACHINE, KEY_BASE, KEY_WOW64_32KEY, &hkey);
run_reg_exe("reg delete HKLM\" KEY_BASE " /v DWORD /f /reg:32", &r); - todo_wine ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r); - todo_wine verify_reg_nonexist(hkey, "DWORD"); + ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r); + verify_reg_nonexist(hkey, "DWORD");
run_reg_exe("reg delete HKLM\" KEY_BASE " /ve /f /reg:32", &r); - todo_wine ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r); - todo_wine verify_reg_nonexist(hkey, NULL); + ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r); + verify_reg_nonexist(hkey, NULL);
run_reg_exe("reg delete HKLM\" KEY_BASE " /va /f /reg:32", &r); - todo_wine ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r); - todo_wine verify_reg_nonexist(hkey, "String"); - todo_wine verify_reg_nonexist(hkey, "Multiple Strings"); + ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r); + verify_reg_nonexist(hkey, "String"); + verify_reg_nonexist(hkey, "Multiple Strings"); verify_key(hkey, "Subkey", KEY_WOW64_32KEY);
run_reg_exe("reg delete HKLM\" KEY_BASE "\Subkey /f /reg:32", &r); @@ -380,17 +380,17 @@ static void test_registry_view_wow64(void) open_key(HKEY_LOCAL_MACHINE, KEY_BASE, KEY_WOW64_64KEY, &hkey);
run_reg_exe("reg delete HKLM\" KEY_BASE " /v DWORD /f /reg:64", &r); - todo_wine ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r); - todo_wine verify_reg_nonexist(hkey, "DWORD"); + ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r); + verify_reg_nonexist(hkey, "DWORD");
run_reg_exe("reg delete HKLM\" KEY_BASE " /ve /f /reg:64", &r); - todo_wine ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r); - todo_wine verify_reg_nonexist(hkey, NULL); + ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r); + verify_reg_nonexist(hkey, NULL);
run_reg_exe("reg delete HKLM\" KEY_BASE " /va /f /reg:64", &r); - todo_wine ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r); - todo_wine verify_reg_nonexist(hkey, "String"); - todo_wine verify_reg_nonexist(hkey, "Multiple Strings"); + ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r); + verify_reg_nonexist(hkey, "String"); + verify_reg_nonexist(hkey, "Multiple Strings"); verify_key(hkey, "Subkey", KEY_WOW64_64KEY);
run_reg_exe("reg delete HKLM\" KEY_BASE "\Subkey /f /reg:64", &r);
Signed-off-by: Hugh McMaster hugh.mcmaster@outlook.com --- programs/reg/delete.c | 18 +++++++++++------- programs/reg/tests/delete.c | 18 +++++++++--------- 2 files changed, 20 insertions(+), 16 deletions(-)
diff --git a/programs/reg/delete.c b/programs/reg/delete.c index f6965493faa..cf0108664fd 100644 --- a/programs/reg/delete.c +++ b/programs/reg/delete.c @@ -59,25 +59,29 @@ static int run_delete(HKEY root, WCHAR *path, REGSAM sam, WCHAR *key_name, WCHAR } }
+ if ((rc = RegOpenKeyExW(root, path, 0, KEY_READ|KEY_SET_VALUE|sam, &hkey))) + { + output_error(rc); + return 1; + } + /* Delete registry key if no /v* option is given */ if (!value_name && !value_empty && !value_all) { - if ((rc = RegDeleteTreeW(root, path))) + if ((rc = RegDeleteTreeW(hkey, NULL))) { + RegCloseKey(hkey); output_error(rc); return 1; }
+ RegDeleteKeyW(hkey, L""); + RegCloseKey(hkey); + output_message(STRING_SUCCESS); return 0; }
- if ((rc = RegOpenKeyExW(root, path, 0, KEY_READ|KEY_SET_VALUE|sam, &hkey))) - { - output_error(rc); - return 1; - } - op_delete_key = FALSE;
if (value_all) diff --git a/programs/reg/tests/delete.c b/programs/reg/tests/delete.c index 102fc0d788a..0c313c12a31 100644 --- a/programs/reg/tests/delete.c +++ b/programs/reg/tests/delete.c @@ -284,19 +284,19 @@ static void test_registry_view_win64(void) verify_key(hkey, "Subkey", KEY_WOW64_32KEY);
run_reg_exe("reg delete HKLM\" KEY_BASE "\Subkey /f /reg:32", &r); - todo_wine ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r); - todo_wine verify_key_nonexist(hkey, "Subkey", KEY_WOW64_32KEY); + ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r); + verify_key_nonexist(hkey, "Subkey", KEY_WOW64_32KEY);
close_key(hkey);
run_reg_exe("reg delete HKLM\" KEY_BASE " /f /reg:32", &r); - todo_wine ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r); - todo_wine verify_key_nonexist(HKEY_LOCAL_MACHINE, KEY_BASE, KEY_WOW64_32KEY); + ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r); + verify_key_nonexist(HKEY_LOCAL_MACHINE, KEY_BASE, KEY_WOW64_32KEY);
/* Test deletion from the 64-bit registry view (64-bit Windows) */ create_test_key(KEY_WOW64_64KEY);
- todo_wine verify_key_nonexist(HKEY_LOCAL_MACHINE, KEY_BASE, KEY_WOW64_32KEY); + verify_key_nonexist(HKEY_LOCAL_MACHINE, KEY_BASE, KEY_WOW64_32KEY);
open_key(HKEY_LOCAL_MACHINE, KEY_BASE, KEY_WOW64_64KEY, &hkey);
@@ -394,14 +394,14 @@ static void test_registry_view_wow64(void) verify_key(hkey, "Subkey", KEY_WOW64_64KEY);
run_reg_exe("reg delete HKLM\" KEY_BASE "\Subkey /f /reg:64", &r); - todo_wine ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r); - todo_wine verify_key_nonexist(hkey, "Subkey", KEY_WOW64_64KEY); + ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r); + verify_key_nonexist(hkey, "Subkey", KEY_WOW64_64KEY);
close_key(hkey);
run_reg_exe("reg delete HKLM\" KEY_BASE " /f /reg:64", &r); - todo_wine ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r); - todo_wine verify_key_nonexist(HKEY_LOCAL_MACHINE, KEY_BASE, KEY_WOW64_64KEY); + ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r); + verify_key_nonexist(HKEY_LOCAL_MACHINE, KEY_BASE, KEY_WOW64_64KEY); }
START_TEST(delete)
Signed-off-by: Hugh McMaster hugh.mcmaster@outlook.com --- programs/reg/tests/query.c | 54 +++++++++++++++++++++----------------- 1 file changed, 30 insertions(+), 24 deletions(-)
diff --git a/programs/reg/tests/query.c b/programs/reg/tests/query.c index 270f0aad75d..f5ba32f97e3 100644 --- a/programs/reg/tests/query.c +++ b/programs/reg/tests/query.c @@ -105,6 +105,35 @@ static void compare_query_(const char *file, unsigned line, const BYTE *buf,
/* Unit tests */
+static void test_command_syntax(void) +{ + DWORD r; + + run_reg_exe("reg query", &r); + ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r); + + run_reg_exe("reg query /?", &r); + ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r); + + run_reg_exe("reg query /h", &r); + ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r); + + run_reg_exe("reg query -H", &r); + ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r); + + run_reg_exe("reg query HKCU\" KEY_BASE " /v", &r); + ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r); + + run_reg_exe("reg query HKCU\" KEY_BASE " /v Test1 /v Test2", &r); + ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r); + + run_reg_exe("reg query HKCU\" KEY_BASE " /v Test1 /ve", &r); + ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r); + + run_reg_exe("reg query HKCU\" KEY_BASE " /s /s", &r); + ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r); +} + static void test_query(void) { const char *test1 = "\r\n" @@ -167,18 +196,6 @@ static void test_query(void) delete_tree(HKEY_CURRENT_USER, KEY_BASE, 0); verify_key_nonexist(HKEY_CURRENT_USER, KEY_BASE, 0);
- run_reg_exe("reg query", &r); - ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r); - - run_reg_exe("reg query /?", &r); - ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r); - - run_reg_exe("reg query /h", &r); - ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r); - - run_reg_exe("reg query -H", &r); - ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r); - /* Key not present */ run_reg_exe("reg query HKCU\" KEY_BASE, &r); ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r); @@ -188,21 +205,9 @@ static void test_query(void) add_value(hkey, "Test1", REG_SZ, "Hello, World", 13); add_value(hkey, "Test2", REG_DWORD, &dword, sizeof(dword));
- run_reg_exe("reg query HKCU\" KEY_BASE " /v", &r); - ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r); - run_reg_exe("reg query HKCU\" KEY_BASE " /v Missing", &r); ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
- run_reg_exe("reg query HKCU\" KEY_BASE " /v Test1 /v Test2", &r); - ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r); - - run_reg_exe("reg query HKCU\" KEY_BASE " /v Test1 /ve", &r); - ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r); - - run_reg_exe("reg query HKCU\" KEY_BASE " /s /s", &r); - ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r); - read_reg_output("reg query HKCU\" KEY_BASE, buf, sizeof(buf), &r); ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r); compare_query(buf, test1, FALSE, 0); @@ -300,5 +305,6 @@ START_TEST(query) return; }
+ test_command_syntax(); test_query(); }