Signed-off-by: Hugh McMaster hugh.mcmaster@outlook.com --- programs/reg/reg.rc | 2 -- programs/reg/resource.h | 2 -- 2 files changed, 4 deletions(-)
diff --git a/programs/reg/reg.rc b/programs/reg/reg.rc index c091023384c..1b451dc016b 100644 --- a/programs/reg/reg.rc +++ b/programs/reg/reg.rc @@ -132,7 +132,6 @@ STRINGTABLE STRING_DELETE_SUBKEY, "Are you sure you want to delete the registry key '%1'?" STRING_INVALID_STRING, "reg: The option [/d] must be followed by a valid string\n" STRING_VALUEALL_FAILED, "reg: Unable to delete all registry values in '%1'\n" - STRING_GENERAL_FAILURE, "reg: Unable to complete the specified operation. An unexpected error occurred.\n" STRING_MATCHES_FOUND, "Search complete. Number of matches found: %1!d!\n" STRING_INVALID_SYNTAX, "reg: Invalid syntax. " STRING_INVALID_OPTION, "reg: Invalid option [%1]. " @@ -146,7 +145,6 @@ STRINGTABLE \ The name and path of the registry file to import.\n\n"
STRING_FILE_NOT_FOUND, "reg: The file '%1' was not found.\n" - STRING_OPEN_KEY_FAILED, "reg: Unable to open the registry key '%1'.\n" STRING_ESCAPE_SEQUENCE, "reg: Unrecognized escape sequence [\%1!c!]\n"
STRING_EXPORT_USAGE, "REG EXPORT <key> <file> [/y]\n\n\ diff --git a/programs/reg/resource.h b/programs/reg/resource.h index 670d297389a..2a84c1025b3 100644 --- a/programs/reg/resource.h +++ b/programs/reg/resource.h @@ -45,7 +45,6 @@ #define STRING_DELETE_SUBKEY 122 #define STRING_INVALID_STRING 123 #define STRING_VALUEALL_FAILED 124 -#define STRING_GENERAL_FAILURE 125 #define STRING_MATCHES_FOUND 126 #define STRING_INVALID_SYNTAX 127 #define STRING_INVALID_OPTION 128 @@ -54,7 +53,6 @@ #define STRING_VALUE_NOT_SET 131 #define STRING_IMPORT_USAGE 132 #define STRING_FILE_NOT_FOUND 133 -#define STRING_OPEN_KEY_FAILED 134 #define STRING_ESCAPE_SEQUENCE 135 #define STRING_EXPORT_USAGE 136 #define STRING_INVALID_SYSTEM_KEY 137
Signed-off-by: Hugh McMaster hugh.mcmaster@outlook.com --- programs/reg/resource.h | 98 +++++++++++++++++++++++------------------ 1 file changed, 56 insertions(+), 42 deletions(-)
diff --git a/programs/reg/resource.h b/programs/reg/resource.h index 2a84c1025b3..a4dcc5fc078 100644 --- a/programs/reg/resource.h +++ b/programs/reg/resource.h @@ -20,45 +20,59 @@
#include <windef.h>
-/* Translation IDs. */ -#define STRING_USAGE 101 -#define STRING_ADD_USAGE 102 -#define STRING_DELETE_USAGE 103 -#define STRING_QUERY_USAGE 104 -#define STRING_SUCCESS 105 -#define STRING_INVALID_KEY 106 -#define STRING_INVALID_CMDLINE 107 -#define STRING_NO_REMOTE 108 -#define STRING_VALUE_NONEXIST 109 -#define STRING_UNSUPPORTED_TYPE 110 -#define STRING_MISSING_NUMBER 111 -#define STRING_MISSING_HEXDATA 112 -#define STRING_UNHANDLED_TYPE 113 -#define STRING_OVERWRITE_VALUE 114 -#define STRING_YESNO 115 -#define STRING_YES 116 -#define STRING_NO 117 -#define STRING_CANCELLED 118 -#define STRING_DEFAULT_VALUE 119 -#define STRING_DELETE_VALUE 120 -#define STRING_DELETE_VALUEALL 121 -#define STRING_DELETE_SUBKEY 122 -#define STRING_INVALID_STRING 123 -#define STRING_VALUEALL_FAILED 124 -#define STRING_MATCHES_FOUND 126 -#define STRING_INVALID_SYNTAX 127 -#define STRING_INVALID_OPTION 128 -#define STRING_REG_HELP 129 -#define STRING_FUNC_HELP 130 -#define STRING_VALUE_NOT_SET 131 -#define STRING_IMPORT_USAGE 132 -#define STRING_FILE_NOT_FOUND 133 -#define STRING_ESCAPE_SEQUENCE 135 -#define STRING_EXPORT_USAGE 136 -#define STRING_INVALID_SYSTEM_KEY 137 -#define STRING_OVERWRITE_FILE 138 -#define STRING_KEY_NONEXIST 139 -#define STRING_KEY_IMPORT_FAILED 140 -#define STRING_REG_VIEW_USAGE 141 -#define STRING_ACCESS_DENIED 142 -#define STRING_COPY_USAGE 143 +/* Translation IDs */ + +/* Shared */ +#define STRING_YES 100 +#define STRING_NO 101 +#define STRING_YESNO 103 +#define STRING_INVALID_SYNTAX 105 +#define STRING_FUNC_HELP 106 +#define STRING_ACCESS_DENIED 107 +#define STRING_SUCCESS 108 +#define STRING_CANCELLED 109 +#define STRING_KEY_NONEXIST 110 +#define STRING_VALUE_NONEXIST 111 +#define STRING_DEFAULT_VALUE 112 + +/* reg.c */ +#define STRING_REG_HELP 150 +#define STRING_USAGE 151 +#define STRING_ADD_USAGE 152 +#define STRING_COPY_USAGE 153 +#define STRING_DELETE_USAGE 154 +#define STRING_EXPORT_USAGE 155 +#define STRING_IMPORT_USAGE 156 +#define STRING_QUERY_USAGE 157 +#define STRING_REG_VIEW_USAGE 164 +#define STRING_INVALID_KEY 165 +#define STRING_NO_REMOTE 166 +#define STRING_INVALID_SYSTEM_KEY 167 +#define STRING_INVALID_OPTION 168 + +/* add.c */ +#define STRING_MISSING_NUMBER 200 +#define STRING_MISSING_HEXDATA 201 +#define STRING_INVALID_STRING 202 +#define STRING_UNHANDLED_TYPE 203 +#define STRING_UNSUPPORTED_TYPE 204 +#define STRING_OVERWRITE_VALUE 205 +#define STRING_INVALID_CMDLINE 206 + +/* delete.c */ +#define STRING_DELETE_VALUE 300 +#define STRING_DELETE_VALUEALL 301 +#define STRING_DELETE_SUBKEY 302 +#define STRING_VALUEALL_FAILED 303 + +/* export.c */ +#define STRING_OVERWRITE_FILE 350 + +/* import.c */ +#define STRING_ESCAPE_SEQUENCE 400 +#define STRING_KEY_IMPORT_FAILED 401 +#define STRING_FILE_NOT_FOUND 402 + +/* query.c */ +#define STRING_VALUE_NOT_SET 450 +#define STRING_MATCHES_FOUND 451
Signed-off-by: Hugh McMaster hugh.mcmaster@outlook.com --- programs/reg/copy.c | 129 +++++++++++++++++++++++++++ programs/reg/tests/copy.c | 178 +++++++++++++++++++------------------- 2 files changed, 218 insertions(+), 89 deletions(-)
diff --git a/programs/reg/copy.c b/programs/reg/copy.c index ba0916e9956..29ada63da56 100644 --- a/programs/reg/copy.c +++ b/programs/reg/copy.c @@ -18,7 +18,136 @@
#include "reg.h"
+struct key { + HKEY root; /* system key */ + WCHAR *subkey; /* path to subkey */ + HKEY hkey; /* handle to opened or created key */ +}; + +static void output_error(LONG rc) +{ + if (rc == ERROR_FILE_NOT_FOUND) + output_message(STRING_KEY_NONEXIST); + else + output_message(STRING_ACCESS_DENIED); +} + +static int run_copy(struct key *src, struct key *dest, BOOL recurse, BOOL force) +{ + LONG rc; + DWORD max_subkey_len; + DWORD max_name_len, name_len; + DWORD max_data_size, data_size; + DWORD type, i; + WCHAR *name = NULL; + BYTE *data = NULL; + + if ((rc = RegOpenKeyExW(src->root, src->subkey, 0, KEY_READ, &src->hkey))) + { + output_error(rc); + return 1; + } + + if ((rc = RegCreateKeyExW(dest->root, dest->subkey, 0, NULL, REG_OPTION_NON_VOLATILE, + KEY_WRITE, NULL, &dest->hkey, NULL))) + { + RegCloseKey(src->hkey); + output_error(rc); + return 1; + } + + rc = RegQueryInfoKeyW(src->hkey, NULL, NULL, NULL, NULL, &max_subkey_len, NULL, + NULL, &max_name_len, &max_data_size, NULL, NULL); + if (rc) goto cleanup; + + max_name_len = max(max_subkey_len, max_name_len) + 1; + + if (!(name = malloc(max_name_len * sizeof(WCHAR)))) + { + rc = ERROR_NOT_ENOUGH_MEMORY; + goto cleanup; + } + + if (!(data = malloc(max_data_size))) + { + rc = ERROR_NOT_ENOUGH_MEMORY; + goto cleanup; + } + + for (i = 0; ; i++) + { + name_len = max_name_len; + data_size = max_data_size; + + rc = RegEnumValueW(src->hkey, i, name, &name_len, NULL, &type, data, &data_size); + if (rc == ERROR_NO_MORE_ITEMS) break; + if (rc) goto cleanup; + + if ((rc = RegSetValueExW(dest->hkey, name, 0, type, data, data_size))) + { + output_error(rc); + goto cleanup; + } + } + +cleanup: + free(name); + free(data); + + RegCloseKey(src->hkey); + RegCloseKey(dest->hkey); + + return rc != ERROR_NO_MORE_ITEMS; +} + int reg_copy(int argc, WCHAR *argvW[]) { + struct key src, dest; + BOOL recurse = FALSE, force = FALSE; + int i; + + if (argc == 3) + goto invalid; + + if (!parse_registry_key(argvW[2], &src.root, &src.subkey)) + return 1; + + if (!parse_registry_key(argvW[3], &dest.root, &dest.subkey)) + return 1; + + for (i = 4; i < argc; i++) + { + WCHAR *str; + + if (argvW[i][0] != '/' && argvW[i][0] != '-') + goto invalid; + + str = &argvW[i][1]; + + if (!lstrcmpiW(str, L"reg:32") || !lstrcmpiW(str, L"reg:64")) + continue; + else if (!str[0] || str[1]) + goto invalid; + + switch (towlower(*str)) + { + case 's': + if (recurse) goto invalid; + recurse = TRUE; + break; + case 'f': + if (force) goto invalid; + force = TRUE; + break; + default: + goto invalid; + } + } + + return run_copy(&src, &dest, recurse, force); + +invalid: + output_message(STRING_INVALID_SYNTAX); + output_message(STRING_FUNC_HELP, wcsupr(argvW[1])); return 1; } diff --git a/programs/reg/tests/copy.c b/programs/reg/tests/copy.c index 5ddcc2c0ffa..ef4a5f6acb8 100644 --- a/programs/reg/tests/copy.c +++ b/programs/reg/tests/copy.c @@ -136,54 +136,54 @@ static void test_copy_empty_key(void)
run_reg_exe("reg copy HKCU\" COPY_SRC " HKCU\" KEY_BASE " /f", &r); - todo_wine ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r); - todo_wine verify_key(HKEY_CURRENT_USER, KEY_BASE); + ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r); + verify_key(HKEY_CURRENT_USER, KEY_BASE);
run_reg_exe("reg export HKCU\" KEY_BASE " file.reg", &r); - todo_wine ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r); - todo_wine ok(compare_export("file.reg", empty_key_test, 0), "compare_export() failed\n"); + ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r); + ok(compare_export("file.reg", empty_key_test, 0), "compare_export() failed\n");
- todo_wine delete_key(HKEY_CURRENT_USER, KEY_BASE); + delete_key(HKEY_CURRENT_USER, KEY_BASE);
run_reg_exe("reg copy HKCU\" COPY_SRC "\ HKCU\" KEY_BASE " /f", &r); - todo_wine ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r); - todo_wine verify_key(HKEY_CURRENT_USER, KEY_BASE); + ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r); + verify_key(HKEY_CURRENT_USER, KEY_BASE);
run_reg_exe("reg export HKCU\" KEY_BASE " file.reg", &r); - todo_wine ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r); - todo_wine ok(compare_export("file.reg", empty_key_test, 0), "compare_export() failed\n"); + ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r); + ok(compare_export("file.reg", empty_key_test, 0), "compare_export() failed\n");
- todo_wine delete_key(HKEY_CURRENT_USER, KEY_BASE); + delete_key(HKEY_CURRENT_USER, KEY_BASE);
run_reg_exe("reg copy HKCU\" COPY_SRC " HKCU\" KEY_BASE "\ /f", &r); - todo_wine ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r); - todo_wine verify_key(HKEY_CURRENT_USER, KEY_BASE); + ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r); + verify_key(HKEY_CURRENT_USER, KEY_BASE);
run_reg_exe("reg export HKCU\" KEY_BASE " file.reg", &r); - todo_wine ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r); - todo_wine ok(compare_export("file.reg", empty_key_test, 0), "compare_export() failed\n"); + ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r); + ok(compare_export("file.reg", empty_key_test, 0), "compare_export() failed\n");
- todo_wine delete_key(HKEY_CURRENT_USER, KEY_BASE); + delete_key(HKEY_CURRENT_USER, KEY_BASE);
run_reg_exe("reg copy HKCU\" COPY_SRC "\ HKCU\" KEY_BASE "\ /f", &r); - todo_wine ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r); - todo_wine verify_key(HKEY_CURRENT_USER, KEY_BASE); + ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r); + verify_key(HKEY_CURRENT_USER, KEY_BASE);
run_reg_exe("reg export HKCU\" KEY_BASE " file.reg", &r); - todo_wine ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r); - todo_wine ok(compare_export("file.reg", empty_key_test, 0), "compare_export() failed\n"); + ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r); + ok(compare_export("file.reg", empty_key_test, 0), "compare_export() failed\n");
run_reg_exe("reg copy HKCU\" COPY_SRC " HKCU\" KEY_BASE " /s /f", &r); - todo_wine ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r); - todo_wine verify_key(HKEY_CURRENT_USER, KEY_BASE); + ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r); + verify_key(HKEY_CURRENT_USER, KEY_BASE);
run_reg_exe("reg export HKCU\" KEY_BASE " file.reg", &r); - todo_wine ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r); - todo_wine ok(compare_export("file.reg", empty_key_test, 0), "compare_export() failed\n"); + ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r); + ok(compare_export("file.reg", empty_key_test, 0), "compare_export() failed\n"); }
static void test_copy_simple_data(void) @@ -206,54 +206,54 @@ static void test_copy_simple_data(void)
run_reg_exe("reg copy HKCU\" COPY_SRC " HKCU\" KEY_BASE " /f", &r); - todo_wine ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r); - todo_wine verify_key(HKEY_CURRENT_USER, KEY_BASE); + ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r); + verify_key(HKEY_CURRENT_USER, KEY_BASE);
run_reg_exe("reg export HKCU\" KEY_BASE " file.reg /y", &r); - todo_wine ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r); - todo_wine ok(compare_export("file.reg", simple_data_test, 0), "compare_export() failed\n"); + ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r); + ok(compare_export("file.reg", simple_data_test, 0), "compare_export() failed\n");
- todo_wine delete_key(HKEY_CURRENT_USER, KEY_BASE); + delete_key(HKEY_CURRENT_USER, KEY_BASE);
run_reg_exe("reg copy HKCU\" COPY_SRC "\ HKCU\" KEY_BASE " /f", &r); - todo_wine ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r); - todo_wine verify_key(HKEY_CURRENT_USER, KEY_BASE); + ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r); + verify_key(HKEY_CURRENT_USER, KEY_BASE);
run_reg_exe("reg export HKCU\" KEY_BASE " file.reg /y", &r); - todo_wine ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r); - todo_wine ok(compare_export("file.reg", simple_data_test, 0), "compare_export() failed\n"); + ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r); + ok(compare_export("file.reg", simple_data_test, 0), "compare_export() failed\n");
- todo_wine delete_key(HKEY_CURRENT_USER, KEY_BASE); + delete_key(HKEY_CURRENT_USER, KEY_BASE);
run_reg_exe("reg copy HKCU\" COPY_SRC " HKCU\" KEY_BASE "\ /f", &r); - todo_wine ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r); - todo_wine verify_key(HKEY_CURRENT_USER, KEY_BASE); + ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r); + verify_key(HKEY_CURRENT_USER, KEY_BASE);
run_reg_exe("reg export HKCU\" KEY_BASE " file.reg /y", &r); - todo_wine ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r); - todo_wine ok(compare_export("file.reg", simple_data_test, 0), "compare_export() failed\n"); + ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r); + ok(compare_export("file.reg", simple_data_test, 0), "compare_export() failed\n");
- todo_wine delete_key(HKEY_CURRENT_USER, KEY_BASE); + delete_key(HKEY_CURRENT_USER, KEY_BASE);
run_reg_exe("reg copy HKCU\" COPY_SRC "\ HKCU\" KEY_BASE "\ /f", &r); - todo_wine ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r); - todo_wine verify_key(HKEY_CURRENT_USER, KEY_BASE); + ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r); + verify_key(HKEY_CURRENT_USER, KEY_BASE);
run_reg_exe("reg export HKCU\" KEY_BASE " file.reg /y", &r); - todo_wine ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r); - todo_wine ok(compare_export("file.reg", simple_data_test, 0), "compare_export() failed\n"); + ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r); + ok(compare_export("file.reg", simple_data_test, 0), "compare_export() failed\n");
run_reg_exe("reg copy HKCU\" COPY_SRC " HKCU\" KEY_BASE " /s /f", &r); - todo_wine ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r); - todo_wine verify_key(HKEY_CURRENT_USER, KEY_BASE); + ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r); + verify_key(HKEY_CURRENT_USER, KEY_BASE);
run_reg_exe("reg export HKCU\" KEY_BASE " file.reg /y", &r); - todo_wine ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r); - todo_wine ok(compare_export("file.reg", simple_data_test, 0), "compare_export() failed\n"); + ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r); + ok(compare_export("file.reg", simple_data_test, 0), "compare_export() failed\n"); }
static void test_copy_complex_data(void) @@ -308,21 +308,21 @@ static void test_copy_complex_data(void)
/* Copy values only */ run_reg_exe("reg copy HKCU\" COPY_SRC " HKCU\" KEY_BASE " /f", &r); - todo_wine ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r); - todo_wine verify_key(HKEY_CURRENT_USER, KEY_BASE); + ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r); + verify_key(HKEY_CURRENT_USER, KEY_BASE);
run_reg_exe("reg export HKEY_CURRENT_USER\" KEY_BASE " file.reg /y", &r); - todo_wine ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r); - todo_wine ok(compare_export("file.reg", simple_data_test, 0), "compare_export() failed\n"); + ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r); + ok(compare_export("file.reg", simple_data_test, 0), "compare_export() failed\n");
/* Copy subkeys and values */ run_reg_exe("reg copy HKCU\" COPY_SRC " HKCU\" KEY_BASE " /s /f", &r); - todo_wine ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r); - todo_wine verify_key(HKEY_CURRENT_USER, KEY_BASE); + ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r); + verify_key(HKEY_CURRENT_USER, KEY_BASE);
run_reg_exe("reg export HKEY_CURRENT_USER\" KEY_BASE " file.reg /y", &r); - todo_wine ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r); - todo_wine ok(compare_export("file.reg", complex_data_test, 0), "compare_export() failed\n"); + ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r); + ok(compare_export("file.reg", complex_data_test, TODO_REG_COMPARE), "compare_export() failed\n"); }
static void test_copy_key_order(void) @@ -342,12 +342,12 @@ static void test_copy_key_order(void) close_key(hkey);
run_reg_exe("reg copy HKCU\" COPY_SRC " HKCU\" KEY_BASE " /s /f", &r); - todo_wine ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r); - todo_wine verify_key(HKEY_CURRENT_USER, KEY_BASE); + ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r); + verify_key(HKEY_CURRENT_USER, KEY_BASE);
run_reg_exe("reg export HKCU\" KEY_BASE " file.reg /y", &r); - todo_wine ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r); - todo_wine ok(compare_export("file.reg", key_order_test, 0), "compare_export() failed\n"); + ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r); + ok(compare_export("file.reg", key_order_test, TODO_REG_COMPARE), "compare_export() failed\n"); }
static void test_copy_value_order(void) @@ -367,12 +367,12 @@ static void test_copy_value_order(void) close_key(hkey);
run_reg_exe("reg copy HKCU\" COPY_SRC " HKCU\" KEY_BASE " /f", &r); - todo_wine ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r); - todo_wine verify_key(HKEY_CURRENT_USER, KEY_BASE); + ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r); + verify_key(HKEY_CURRENT_USER, KEY_BASE);
run_reg_exe("reg export HKCU\" KEY_BASE " file.reg /y", &r); - todo_wine ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r); - todo_wine ok(compare_export("file.reg", value_order_test, 0), "compare_export() failed\n"); + ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r); + ok(compare_export("file.reg", value_order_test, TODO_REG_COMPARE), "compare_export() failed\n"); }
static void test_copy_hex_data(void) @@ -399,15 +399,15 @@ static void test_copy_hex_data(void) close_key(hkey);
run_reg_exe("reg copy HKCU\" COPY_SRC " HKCU\" KEY_BASE " /f", &r); - todo_wine ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r); - todo_wine verify_key(HKEY_CURRENT_USER, KEY_BASE); + ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r); + verify_key(HKEY_CURRENT_USER, KEY_BASE);
run_reg_exe("reg export HKCU\" KEY_BASE " file.reg /y", &r); - todo_wine ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r); - todo_wine ok(compare_export("file.reg", empty_hex_test, 0), "compare_export() failed\n"); + ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r); + ok(compare_export("file.reg", empty_hex_test, 0), "compare_export() failed\n");
delete_key(HKEY_CURRENT_USER, COPY_SRC); - todo_wine delete_key(HKEY_CURRENT_USER, KEY_BASE); + delete_key(HKEY_CURRENT_USER, KEY_BASE);
/* Try copying after importing alternative registry data types */ test_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n" @@ -418,15 +418,15 @@ static void test_copy_hex_data(void) ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
run_reg_exe("reg copy HKCU\" COPY_SRC " HKCU\" KEY_BASE " /f", &r); - todo_wine ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r); - todo_wine verify_key(HKEY_CURRENT_USER, KEY_BASE); + ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r); + verify_key(HKEY_CURRENT_USER, KEY_BASE);
run_reg_exe("reg export HKCU\" KEY_BASE " file.reg /y", &r); - todo_wine ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r); - todo_wine ok(compare_export("file.reg", empty_hex_test2, 0), "compare_export() failed\n"); + ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r); + ok(compare_export("file.reg", empty_hex_test2, 0), "compare_export() failed\n");
delete_key(HKEY_CURRENT_USER, COPY_SRC); - todo_wine delete_key(HKEY_CURRENT_USER, KEY_BASE); + delete_key(HKEY_CURRENT_USER, KEY_BASE);
/* Try copying more complex hex data */ test_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n" @@ -437,12 +437,12 @@ static void test_copy_hex_data(void) ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
run_reg_exe("reg copy HKCU\" COPY_SRC " HKCU\" KEY_BASE " /f", &r); - todo_wine ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r); - todo_wine verify_key(HKEY_CURRENT_USER, KEY_BASE); + ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r); + verify_key(HKEY_CURRENT_USER, KEY_BASE);
run_reg_exe("reg export HKEY_CURRENT_USER\" KEY_BASE " file.reg /y", &r); - todo_wine ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r); - todo_wine ok(compare_export("file.reg", hex_types_test, 0), "compare_export() failed\n"); + ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r); + ok(compare_export("file.reg", hex_types_test, 0), "compare_export() failed\n"); }
static void test_copy_embedded_null_values(void) @@ -469,12 +469,12 @@ static void test_copy_embedded_null_values(void) ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
run_reg_exe("reg copy HKCU\" COPY_SRC " HKCU\" KEY_BASE " /f", &r); - todo_wine ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r); - todo_wine verify_key(HKEY_CURRENT_USER, KEY_BASE); + ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r); + verify_key(HKEY_CURRENT_USER, KEY_BASE);
run_reg_exe("reg export HKEY_CURRENT_USER\" KEY_BASE " file.reg /y", &r); - todo_wine ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r); - todo_wine ok(compare_export("file.reg", embedded_null_test, 0), "compare_export() failed\n"); + ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r); + ok(compare_export("file.reg", embedded_null_test, 0), "compare_export() failed\n"); }
static void test_copy_slashes(void) @@ -495,12 +495,12 @@ static void test_copy_slashes(void) close_key(hkey);
run_reg_exe("reg copy HKCU\" COPY_SRC " HKCU\" KEY_BASE " /s /f", &r); - todo_wine ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r); - todo_wine verify_key(HKEY_CURRENT_USER, KEY_BASE); + ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r); + verify_key(HKEY_CURRENT_USER, KEY_BASE);
run_reg_exe("reg export HKCU\" KEY_BASE " file.reg /y", &r); - todo_wine ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r); - todo_wine ok(compare_export("file.reg", slashes_test, 0), "compare_export() failed\n"); + ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r); + ok(compare_export("file.reg", slashes_test, TODO_REG_COMPARE), "compare_export() failed\n"); }
static void test_copy_escaped_null_values(void) @@ -524,15 +524,15 @@ static void test_copy_escaped_null_values(void) close_key(hkey);
run_reg_exe("reg copy HKCU\" COPY_SRC " HKCU\" KEY_BASE " /f", &r); - todo_wine ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r); - todo_wine verify_key(HKEY_CURRENT_USER, KEY_BASE); + ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r); + verify_key(HKEY_CURRENT_USER, KEY_BASE);
run_reg_exe("reg export HKCU\" KEY_BASE " file.reg /y", &r); - todo_wine ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r); - todo_wine ok(compare_export("file.reg", escaped_null_test, 0), "compare_export() failed\n"); + ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r); + ok(compare_export("file.reg", escaped_null_test, 0), "compare_export() failed\n");
delete_key(HKEY_CURRENT_USER, COPY_SRC); - todo_wine delete_key(HKEY_CURRENT_USER, KEY_BASE); + delete_key(HKEY_CURRENT_USER, KEY_BASE); }
START_TEST(copy)
Signed-off-by: Hugh McMaster hugh.mcmaster@outlook.com --- programs/reg/copy.c | 19 +++++++++++++++++++ programs/reg/tests/copy.c | 4 ++-- 2 files changed, 21 insertions(+), 2 deletions(-)
diff --git a/programs/reg/copy.c b/programs/reg/copy.c index 29ada63da56..34abf8ade18 100644 --- a/programs/reg/copy.c +++ b/programs/reg/copy.c @@ -90,6 +90,25 @@ static int run_copy(struct key *src, struct key *dest, BOOL recurse, BOOL force) } }
+ for (i = 0; recurse; i++) + { + struct key subkey_src, subkey_dest; + + name_len = max_name_len; + + rc = RegEnumKeyExW(src->hkey, i, name, &name_len, NULL, NULL, NULL, NULL); + if (rc) break; + + subkey_src.root = src->hkey; + subkey_src.subkey = name; + + subkey_dest.root = dest->hkey; + subkey_dest.subkey = name; + + rc = run_copy(&subkey_src, &subkey_dest, TRUE, force); + if (rc) goto cleanup; + } + cleanup: free(name); free(data); diff --git a/programs/reg/tests/copy.c b/programs/reg/tests/copy.c index ef4a5f6acb8..70f9496b149 100644 --- a/programs/reg/tests/copy.c +++ b/programs/reg/tests/copy.c @@ -322,7 +322,7 @@ static void test_copy_complex_data(void)
run_reg_exe("reg export HKEY_CURRENT_USER\" KEY_BASE " file.reg /y", &r); ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r); - ok(compare_export("file.reg", complex_data_test, TODO_REG_COMPARE), "compare_export() failed\n"); + ok(compare_export("file.reg", complex_data_test, 0), "compare_export() failed\n"); }
static void test_copy_key_order(void) @@ -347,7 +347,7 @@ static void test_copy_key_order(void)
run_reg_exe("reg export HKCU\" KEY_BASE " file.reg /y", &r); ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r); - ok(compare_export("file.reg", key_order_test, TODO_REG_COMPARE), "compare_export() failed\n"); + ok(compare_export("file.reg", key_order_test, 0), "compare_export() failed\n"); }
static void test_copy_value_order(void)
Signed-off-by: Hugh McMaster hugh.mcmaster@outlook.com --- programs/reg/copy.c | 6 ++++++ programs/reg/reg.c | 17 +++++++---------- programs/reg/reg.rc | 2 ++ programs/reg/resource.h | 3 +++ 4 files changed, 18 insertions(+), 10 deletions(-)
diff --git a/programs/reg/copy.c b/programs/reg/copy.c index 34abf8ade18..208adc46e00 100644 --- a/programs/reg/copy.c +++ b/programs/reg/copy.c @@ -163,6 +163,12 @@ int reg_copy(int argc, WCHAR *argvW[]) } }
+ if (src.root == dest.root && !lstrcmpiW(src.subkey, dest.subkey)) + { + output_message(STRING_COPY_SRC_DEST_SAME); + return 1; + } + return run_copy(&src, &dest, recurse, force);
invalid: diff --git a/programs/reg/reg.c b/programs/reg/reg.c index 8d3bf78f0a9..617ec9df56f 100644 --- a/programs/reg/reg.c +++ b/programs/reg/reg.c @@ -206,7 +206,7 @@ WCHAR *build_subkey_path(WCHAR *path, DWORD path_len, WCHAR *subkey_name, DWORD
WCHAR *get_long_key(HKEY root, WCHAR *path) { - int i, len, path_len; + int i, len; WCHAR *long_key;
for (i = 0; i < ARRAY_SIZE(root_rels); i++) @@ -224,15 +224,7 @@ WCHAR *get_long_key(HKEY root, WCHAR *path) return long_key; }
- path_len = lstrlenW(path); - - if (path[path_len - 1] == '\') - { - path[path_len - 1] = 0; - path_len--; - } - - len += path_len + 1; /* add one for the concatenating backslash */ + len += lstrlenW(path) + 1; /* add one for the concatenating backslash */ long_key = malloc((len + 1) * sizeof(WCHAR)); swprintf(long_key, len + 1, L"%s\%s", root_rels[i].long_name, path); return long_key; @@ -240,6 +232,8 @@ WCHAR *get_long_key(HKEY root, WCHAR *path)
BOOL parse_registry_key(const WCHAR *key, HKEY *root, WCHAR **path) { + WCHAR *p; + if (!sane_path(key)) return FALSE;
@@ -263,6 +257,9 @@ BOOL parse_registry_key(const WCHAR *key, HKEY *root, WCHAR **path) return FALSE; }
+ p = *path + lstrlenW(*path) - 1; + if (*p == '\') *p = 0; + return TRUE; }
diff --git a/programs/reg/reg.rc b/programs/reg/reg.rc index 1b451dc016b..89df2c45c4c 100644 --- a/programs/reg/reg.rc +++ b/programs/reg/reg.rc @@ -197,4 +197,6 @@ STRINGTABLE \ /f\n\ \ Overwrite all registry data in <key2> without prompting for confirmation.\n\ \ This option does not modify subkeys and values that only exist in <key2>.\n\n" + + STRING_COPY_SRC_DEST_SAME, "reg: The source and destination keys cannot be the same\n" } diff --git a/programs/reg/resource.h b/programs/reg/resource.h index a4dcc5fc078..92d82d80a9b 100644 --- a/programs/reg/resource.h +++ b/programs/reg/resource.h @@ -59,6 +59,9 @@ #define STRING_OVERWRITE_VALUE 205 #define STRING_INVALID_CMDLINE 206
+/* copy.c */ +#define STRING_COPY_SRC_DEST_SAME 250 + /* delete.c */ #define STRING_DELETE_VALUE 300 #define STRING_DELETE_VALUEALL 301