Signed-off-by: Hugh McMaster hugh.mcmaster@outlook.com --- programs/reg/tests/export.c | 165 ++++++++++++++++++++++++++++++++++++ 1 file changed, 165 insertions(+)
diff --git a/programs/reg/tests/export.c b/programs/reg/tests/export.c index af00262212b..79135b0efb0 100644 --- a/programs/reg/tests/export.c +++ b/programs/reg/tests/export.c @@ -216,6 +216,15 @@ static void test_export(void) run_reg_exe("reg export HKEY_CURRENT_USER\" KEY_BASE " file.reg file2.reg", &r); ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
+ run_reg_exe("reg export HKEY_CURRENT_USER\" KEY_BASE " file.reg /reg:32 /reg:32", &r); + ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r); + + run_reg_exe("reg export HKEY_CURRENT_USER\" KEY_BASE " file.reg /reg:32 /reg:64", &r); + ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r); + + run_reg_exe("reg export HKEY_CURRENT_USER\" KEY_BASE " file.reg /reg:64 /reg:64", &r); + ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r); + /* Test registry export with an empty key */ add_key(HKEY_CURRENT_USER, KEY_BASE, 0, &hkey);
@@ -429,6 +438,150 @@ static void test_export(void) delete_tree(HKEY_CURRENT_USER, KEY_BASE, 0); }
+static void create_test_key(REGSAM sam) +{ + HKEY hkey, subkey; + DWORD dword = 0x100; + + add_key(HKEY_LOCAL_MACHINE, KEY_BASE, sam, &hkey); + add_value(hkey, "DWORD", REG_DWORD, &dword, sizeof(dword)); + add_value(hkey, "String", REG_SZ, "Your text here...", 18); + + add_key(hkey, "Subkey1", sam, &subkey); + add_value(subkey, "Binary", REG_BINARY, "\x11\x22\x33\x44", 4); + add_value(subkey, "Undefined hex", 0x100, "%PATH%", 7); + close_key(subkey); + + close_key(hkey); +} + +static const char *registry_view_test = + "\xef\xbb\xbfWindows Registry Editor Version 5.00\r\n\r\n" + "[HKEY_LOCAL_MACHINE\" KEY_BASE "]\r\n" + ""DWORD"=dword:00000100\r\n" + ""String"="Your text here..."\r\n\r\n" + "[HKEY_LOCAL_MACHINE\" KEY_BASE "\Subkey1]\r\n" + ""Binary"=hex:11,22,33,44\r\n" + ""Undefined hex"=hex(100):25,50,41,54,48,25,00\r\n\r\n"; + +static void test_registry_view_win32(void) +{ + DWORD r; + BOOL is_wow64, is_win32; + + IsWow64Process(GetCurrentProcess(), &is_wow64); + is_win32 = !is_wow64 && (sizeof(void *) == sizeof(int)); + + if (!is_win32) return; + + delete_tree(HKEY_LOCAL_MACHINE, KEY_BASE, KEY_WOW64_32KEY); + + /* Try exporting from the 32-bit registry view (32-bit Windows) */ + create_test_key(KEY_WOW64_32KEY); + + run_reg_exe("reg export HKEY_LOCAL_MACHINE\" KEY_BASE " file.reg /y /reg:32", &r); + ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r); + ok(compare_export("file.reg", registry_view_test, 0), "compare_export() failed\n"); + + run_reg_exe("reg export HKEY_LOCAL_MACHINE\" KEY_BASE " file.reg /y /reg:64", &r); + ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r); + ok(compare_export("file.reg", registry_view_test, 0), "compare_export() failed\n"); + + delete_tree(HKEY_LOCAL_MACHINE, KEY_BASE, KEY_WOW64_32KEY); + + /* Try exporting from the 64-bit registry view, which doesn't exist on 32-bit Windows */ + create_test_key(KEY_WOW64_64KEY); + + run_reg_exe("reg export HKEY_LOCAL_MACHINE\" KEY_BASE " file.reg /y /reg:64", &r); + ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r); + ok(compare_export("file.reg", registry_view_test, 0), "compare_export() failed\n"); + + run_reg_exe("reg export HKEY_LOCAL_MACHINE\" KEY_BASE " file.reg /y /reg:32", &r); + ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r); + ok(compare_export("file.reg", registry_view_test, 0), "compare_export() failed\n"); + + delete_tree(HKEY_LOCAL_MACHINE, KEY_BASE, KEY_WOW64_64KEY); +} + +static void test_registry_view_win64(void) +{ + DWORD r; + BOOL is_wow64, is_win64; + + IsWow64Process(GetCurrentProcess(), &is_wow64); + is_win64 = !is_wow64 && (sizeof(void *) > sizeof(int)); + + if (!is_win64) return; + + delete_tree(HKEY_LOCAL_MACHINE, KEY_BASE, KEY_WOW64_32KEY); + + /* Try exporting from the 32-bit registry view (64-bit Windows) */ + create_test_key(KEY_WOW64_32KEY); + verify_key_nonexist(HKEY_LOCAL_MACHINE, KEY_BASE, KEY_WOW64_64KEY); + + run_reg_exe("reg export HKEY_LOCAL_MACHINE\" KEY_BASE " file.reg /y /reg:32", &r); + todo_wine ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r); + todo_wine ok(compare_export("file.reg", registry_view_test, TODO_REG_COMPARE), "compare_export() failed\n"); + + run_reg_exe("reg export HKEY_LOCAL_MACHINE\" KEY_BASE " file.reg /y /reg:64", &r); + ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r); + + delete_tree(HKEY_LOCAL_MACHINE, KEY_BASE, KEY_WOW64_32KEY); + delete_tree(HKEY_LOCAL_MACHINE, KEY_BASE, KEY_WOW64_64KEY); + + /* Try exporting from the 64-bit registry view (64-bit Windows) */ + create_test_key(KEY_WOW64_64KEY); + verify_key_nonexist(HKEY_LOCAL_MACHINE, KEY_BASE, KEY_WOW64_32KEY); + + run_reg_exe("reg export HKEY_LOCAL_MACHINE\" KEY_BASE " file.reg /y /reg:64", &r); + ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r); + ok(compare_export("file.reg", registry_view_test, 0), "compare_export() failed\n"); + + run_reg_exe("reg export HKEY_LOCAL_MACHINE\" KEY_BASE " file.reg /y /reg:32", &r); + todo_wine ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r); + + delete_tree(HKEY_LOCAL_MACHINE, KEY_BASE, KEY_WOW64_64KEY); +} + +static void test_registry_view_wow64(void) +{ + DWORD r; + BOOL is_wow64; + + IsWow64Process(GetCurrentProcess(), &is_wow64); + + if (!is_wow64) return; + + delete_tree(HKEY_LOCAL_MACHINE, KEY_BASE, KEY_WOW64_32KEY); + + /* Try exporting from the 32-bit registry view (WOW64) */ + create_test_key(KEY_WOW64_32KEY); + verify_key_nonexist(HKEY_LOCAL_MACHINE, KEY_BASE, KEY_WOW64_64KEY); + + run_reg_exe("reg export HKEY_LOCAL_MACHINE\" KEY_BASE " file.reg /y /reg:32", &r); + ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r); + ok(compare_export("file.reg", registry_view_test, 0), "compare_export() failed\n"); + + run_reg_exe("reg export HKEY_LOCAL_MACHINE\" KEY_BASE " file.reg /y /reg:64", &r); + todo_wine ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r); + + delete_tree(HKEY_LOCAL_MACHINE, KEY_BASE, KEY_WOW64_32KEY); + delete_tree(HKEY_LOCAL_MACHINE, KEY_BASE, KEY_WOW64_64KEY); + + /* Try exporting from the 64-bit registry view (WOW64) */ + create_test_key(KEY_WOW64_64KEY); + verify_key_nonexist(HKEY_LOCAL_MACHINE, KEY_BASE, KEY_WOW64_32KEY); + + run_reg_exe("reg export HKEY_LOCAL_MACHINE\" KEY_BASE " file.reg /y /reg:64", &r); + todo_wine ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r); + ok(compare_export("file.reg", registry_view_test, 0), "compare_export() failed\n"); + + run_reg_exe("reg export HKEY_LOCAL_MACHINE\" KEY_BASE " file.reg /y /reg:32", &r); + ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r); + + delete_tree(HKEY_LOCAL_MACHINE, KEY_BASE, KEY_WOW64_64KEY); +} + START_TEST(export) { DWORD r; @@ -439,4 +592,16 @@ START_TEST(export) }
test_export(); + + /* Check if reg.exe is running with elevated privileges */ + if (!is_elevated_process()) + { + win_skip("reg.exe is not running with elevated privileges; " + "skipping registry view tests\n"); + return; + } + + test_registry_view_win32(); + test_registry_view_win64(); + test_registry_view_wow64(); }
Signed-off-by: Hugh McMaster hugh.mcmaster@outlook.com --- programs/reg/tests/export.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-)
diff --git a/programs/reg/tests/export.c b/programs/reg/tests/export.c index 79135b0efb0..31a75566fae 100644 --- a/programs/reg/tests/export.c +++ b/programs/reg/tests/export.c @@ -168,12 +168,9 @@ const char *escaped_null_test =
/* Unit tests */
-static void test_export(void) +static void test_command_syntax(void) { - LONG err; - DWORD r, dword, type, size; - HKEY hkey, subkey; - BYTE hex[4], buffer[8]; + DWORD r;
delete_tree(HKEY_CURRENT_USER, KEY_BASE, 0);
@@ -210,6 +207,7 @@ static void test_export(void) run_reg_exe("reg export HKEY_CURRENT_USER\" KEY_BASE, &r); ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
+ /* This test fails because the registry key doesn't exist */ run_reg_exe("reg export HKEY_CURRENT_USER\" KEY_BASE " file.reg", &r); ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
@@ -224,6 +222,16 @@ static void test_export(void)
run_reg_exe("reg export HKEY_CURRENT_USER\" KEY_BASE " file.reg /reg:64 /reg:64", &r); ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r); +} + +static void test_export(void) +{ + LONG err; + DWORD r, dword, type, size; + HKEY hkey, subkey; + BYTE hex[4], buffer[8]; + + delete_tree(HKEY_CURRENT_USER, KEY_BASE, 0);
/* Test registry export with an empty key */ add_key(HKEY_CURRENT_USER, KEY_BASE, 0, &hkey); @@ -591,6 +599,7 @@ START_TEST(export) return; }
+ test_command_syntax(); test_export();
/* Check if reg.exe is running with elevated privileges */
Signed-off-by: Hugh McMaster hugh.mcmaster@outlook.com --- programs/reg/tests/export.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/programs/reg/tests/export.c b/programs/reg/tests/export.c index 31a75566fae..0a460e08bcb 100644 --- a/programs/reg/tests/export.c +++ b/programs/reg/tests/export.c @@ -50,7 +50,7 @@ BOOL compare_export_(const char *file, unsigned line, const char *filename, todo_wine_if (todo & TODO_REG_COMPARE) lok(!lstrcmpW(fbuf, wstr), "export data does not match expected data\n");
- ret = delete_file(filename); + ret = delete_file_(file, line, filename);
exit: HeapFree(GetProcessHeap(), 0, fbuf);
Signed-off-by: Hugh McMaster hugh.mcmaster@outlook.com --- programs/reg/export.c | 26 ++++++++++++++++++++------ programs/reg/tests/export.c | 10 +++++----- 2 files changed, 25 insertions(+), 11 deletions(-)
diff --git a/programs/reg/export.c b/programs/reg/export.c index 79f6997ce35..e8b7e22c6dd 100644 --- a/programs/reg/export.c +++ b/programs/reg/export.c @@ -225,7 +225,7 @@ static void export_key_name(HANDLE hFile, WCHAR *name) free(buf); }
-static int export_registry_data(HANDLE hFile, HKEY hkey, WCHAR *path) +static int export_registry_data(HANDLE hFile, HKEY hkey, WCHAR *path, REGSAM sam) { LONG rc; DWORD max_value_len = 256, value_len; @@ -284,9 +284,9 @@ static int export_registry_data(HANDLE hFile, HKEY hkey, WCHAR *path) if (rc == ERROR_SUCCESS) { subkey_path = build_subkey_path(path, path_len, subkey_name, subkey_len); - if (!RegOpenKeyExW(hkey, subkey_name, 0, KEY_READ, &subkey)) + if (!RegOpenKeyExW(hkey, subkey_name, 0, KEY_READ|sam, &subkey)) { - export_registry_data(hFile, subkey, subkey_path); + export_registry_data(hFile, subkey, subkey_path, sam); RegCloseKey(subkey); } free(subkey_path); @@ -349,6 +349,7 @@ int reg_export(int argc, WCHAR *argvW[]) HKEY root, hkey; WCHAR *path, *key_name; BOOL overwrite_file = FALSE; + REGSAM sam = 0; HANDLE hFile; int i, ret;
@@ -368,13 +369,26 @@ int reg_export(int argc, WCHAR *argvW[])
if (is_char(*str, 'y') && !str[1]) overwrite_file = TRUE; - 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 goto invalid; }
- if (RegOpenKeyExW(root, path, 0, KEY_READ, &hkey)) + if (sam == (KEY_WOW64_32KEY|KEY_WOW64_64KEY)) + goto invalid; + + if (RegOpenKeyExW(root, path, 0, KEY_READ|sam, &hkey)) { output_message(STRING_KEY_NONEXIST); return 1; @@ -384,7 +398,7 @@ int reg_export(int argc, WCHAR *argvW[])
hFile = get_file_handle(argvW[3], overwrite_file); export_file_header(hFile); - ret = export_registry_data(hFile, hkey, key_name); + ret = export_registry_data(hFile, hkey, key_name, sam); export_newline(hFile); CloseHandle(hFile);
diff --git a/programs/reg/tests/export.c b/programs/reg/tests/export.c index 0a460e08bcb..7d352519690 100644 --- a/programs/reg/tests/export.c +++ b/programs/reg/tests/export.c @@ -528,8 +528,8 @@ static void test_registry_view_win64(void) verify_key_nonexist(HKEY_LOCAL_MACHINE, KEY_BASE, KEY_WOW64_64KEY);
run_reg_exe("reg export HKEY_LOCAL_MACHINE\" KEY_BASE " file.reg /y /reg:32", &r); - todo_wine ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r); - todo_wine ok(compare_export("file.reg", registry_view_test, TODO_REG_COMPARE), "compare_export() failed\n"); + ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r); + ok(compare_export("file.reg", registry_view_test, 0), "compare_export() failed\n");
run_reg_exe("reg export HKEY_LOCAL_MACHINE\" KEY_BASE " file.reg /y /reg:64", &r); ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r); @@ -546,7 +546,7 @@ static void test_registry_view_win64(void) ok(compare_export("file.reg", registry_view_test, 0), "compare_export() failed\n");
run_reg_exe("reg export HKEY_LOCAL_MACHINE\" KEY_BASE " file.reg /y /reg:32", &r); - todo_wine ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r); + ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
delete_tree(HKEY_LOCAL_MACHINE, KEY_BASE, KEY_WOW64_64KEY); } @@ -571,7 +571,7 @@ static void test_registry_view_wow64(void) ok(compare_export("file.reg", registry_view_test, 0), "compare_export() failed\n");
run_reg_exe("reg export HKEY_LOCAL_MACHINE\" KEY_BASE " file.reg /y /reg:64", &r); - todo_wine ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r); + ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
delete_tree(HKEY_LOCAL_MACHINE, KEY_BASE, KEY_WOW64_32KEY); delete_tree(HKEY_LOCAL_MACHINE, KEY_BASE, KEY_WOW64_64KEY); @@ -581,7 +581,7 @@ static void test_registry_view_wow64(void) verify_key_nonexist(HKEY_LOCAL_MACHINE, KEY_BASE, KEY_WOW64_32KEY);
run_reg_exe("reg export HKEY_LOCAL_MACHINE\" KEY_BASE " file.reg /y /reg:64", &r); - todo_wine ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r); + ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r); ok(compare_export("file.reg", registry_view_test, 0), "compare_export() failed\n");
run_reg_exe("reg export HKEY_LOCAL_MACHINE\" KEY_BASE " file.reg /y /reg:32", &r);