Hugh McMaster : reg: Support use of registry views in the 'copy' operation.

Alexandre Julliard julliard at winehq.org
Tue Jul 27 15:51:01 CDT 2021


Module: wine
Branch: master
Commit: 04d52eb83fa5c37cfe1100f435e36c2f78918338
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=04d52eb83fa5c37cfe1100f435e36c2f78918338

Author: Hugh McMaster <hugh.mcmaster at outlook.com>
Date:   Tue Jul 27 21:43:16 2021 +1000

reg: Support use of registry views in the 'copy' operation.

Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=50962
Signed-off-by: Hugh McMaster <hugh.mcmaster at outlook.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 programs/reg/copy.c       | 26 ++++++++++++++++++++------
 programs/reg/tests/copy.c | 16 ++++++++--------
 2 files changed, 28 insertions(+), 14 deletions(-)

diff --git a/programs/reg/copy.c b/programs/reg/copy.c
index 3ede5440cb6..2970ab81cc1 100644
--- a/programs/reg/copy.c
+++ b/programs/reg/copy.c
@@ -77,7 +77,7 @@ static enum operation ask_overwrite_value(WCHAR *path, WCHAR *value)
     }
 }
 
-static int run_copy(struct key *src, struct key *dest, BOOL recurse, BOOL force)
+static int run_copy(struct key *src, struct key *dest, REGSAM sam, BOOL recurse, BOOL force)
 {
     LONG rc;
     DWORD max_subkey_len;
@@ -87,14 +87,14 @@ static int run_copy(struct key *src, struct key *dest, BOOL recurse, BOOL force)
     WCHAR *name = NULL;
     BYTE *data = NULL;
 
-    if ((rc = RegOpenKeyExW(src->root, src->subkey, 0, KEY_READ, &src->hkey)))
+    if ((rc = RegOpenKeyExW(src->root, src->subkey, 0, KEY_READ|sam, &src->hkey)))
     {
         output_error(rc);
         return 1;
     }
 
     if ((rc = RegCreateKeyExW(dest->root, dest->subkey, 0, NULL, REG_OPTION_NON_VOLATILE,
-                              KEY_READ|KEY_WRITE, NULL, &dest->hkey, &dispos)))
+                              KEY_READ|KEY_WRITE|sam, NULL, &dest->hkey, &dispos)))
     {
         RegCloseKey(src->hkey);
         output_error(rc);
@@ -173,7 +173,7 @@ static int run_copy(struct key *src, struct key *dest, BOOL recurse, BOOL force)
 
         swprintf(subkey_src.path, path_len, L"%s\\%s", src->path, name);
 
-        rc = run_copy(&subkey_src, &subkey_dest, TRUE, force);
+        rc = run_copy(&subkey_src, &subkey_dest, sam, TRUE, force);
 
         free(subkey_src.path);
 
@@ -194,6 +194,7 @@ int reg_copy(int argc, WCHAR *argvW[])
 {
     struct key src, dest;
     BOOL recurse = FALSE, force = FALSE;
+    REGSAM sam = 0;
     int i;
 
     if (argc == 3)
@@ -214,8 +215,18 @@ int reg_copy(int argc, WCHAR *argvW[])
 
         str = &argvW[i][1];
 
-        if (!lstrcmpiW(str, L"reg:32") || !lstrcmpiW(str, L"reg:64"))
+        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;
 
@@ -234,6 +245,9 @@ int reg_copy(int argc, WCHAR *argvW[])
         }
     }
 
+    if (sam == (KEY_WOW64_32KEY|KEY_WOW64_64KEY))
+        goto invalid;
+
     if (src.root == dest.root && !lstrcmpiW(src.subkey, dest.subkey))
     {
         output_message(STRING_COPY_SRC_DEST_SAME);
@@ -242,7 +256,7 @@ int reg_copy(int argc, WCHAR *argvW[])
 
     src.path = src.subkey;
 
-    return run_copy(&src, &dest, recurse, force);
+    return run_copy(&src, &dest, sam, recurse, force);
 
 invalid:
     output_message(STRING_INVALID_SYNTAX);
diff --git a/programs/reg/tests/copy.c b/programs/reg/tests/copy.c
index 0f9e1221200..bc07c3cafb9 100644
--- a/programs/reg/tests/copy.c
+++ b/programs/reg/tests/copy.c
@@ -666,11 +666,11 @@ static void test_registry_view_win64(void)
     verify_key_nonexist(HKEY_LOCAL_MACHINE, KEY_BASE, KEY_WOW64_64KEY);
 
     run_reg_exe("reg copy HKLM\\" COPY_SRC " HKLM\\" KEY_BASE " /s /f /reg:32", &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);
 
     run_reg_exe("reg export HKLM\\" 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, 0), "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 copy HKLM\\" COPY_SRC " HKLM\\" KEY_BASE " /s /f /reg:64", &r);
     ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
@@ -691,7 +691,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 copy HKLM\\" COPY_SRC " HKLM\\" KEY_BASE " /s /f /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, COPY_SRC, KEY_WOW64_64KEY);
     delete_tree(HKEY_LOCAL_MACHINE, KEY_BASE, KEY_WOW64_64KEY);
@@ -724,7 +724,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 copy HKLM\\" COPY_SRC " HKLM\\" KEY_BASE " /s /f /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, COPY_SRC, KEY_WOW64_32KEY);
     delete_tree(HKEY_LOCAL_MACHINE, KEY_BASE, KEY_WOW64_32KEY);
@@ -735,11 +735,11 @@ static void test_registry_view_wow64(void)
     verify_key_nonexist(HKEY_LOCAL_MACHINE, KEY_BASE, KEY_WOW64_32KEY);
 
     run_reg_exe("reg copy HKLM\\" COPY_SRC " HKLM\\" KEY_BASE " /s /f /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);
 
     run_reg_exe("reg export HKLM\\" KEY_BASE " file.reg /y /reg:64", &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, 0), "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 copy HKLM\\" COPY_SRC " HKLM\\" KEY_BASE " /s /f /reg:32", &r);
     ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);




More information about the wine-cvs mailing list