56599300af78fe0fd640ee92e74a2a58340d280b
[reactos.git] / rostests / winetests / advapi32 / registry.c
1 /*
2 * Unit tests for registry functions
3 *
4 * Copyright (c) 2002 Alexandre Julliard
5 * Copyright (c) 2010 André Hentschel
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 */
21
22 #define WIN32_NO_STATUS
23 #define WIN32_LEAN_AND_MEAN
24
25 #include <assert.h>
26 #include <stdarg.h>
27 #include <stdio.h>
28 #include "wine/test.h"
29 #include "windef.h"
30 #include "winbase.h"
31 #include "winternl.h"
32 #include "winreg.h"
33 #include "winsvc.h"
34 #include "winerror.h"
35 #include "aclapi.h"
36
37 #define IS_HKCR(hk) ((UINT_PTR)hk > 0 && ((UINT_PTR)hk & 3) == 2)
38
39 static HKEY hkey_main;
40 static DWORD GLE;
41
42 static const char * sTestpath1 = "%LONGSYSTEMVAR%\\subdir1";
43 static const char * sTestpath2 = "%FOO%\\subdir1";
44 static const DWORD ptr_size = 8 * sizeof(void*);
45
46 static DWORD (WINAPI *pRegGetValueA)(HKEY,LPCSTR,LPCSTR,DWORD,LPDWORD,PVOID,LPDWORD);
47 static DWORD (WINAPI *pRegDeleteTreeA)(HKEY,LPCSTR);
48 static DWORD (WINAPI *pRegDeleteKeyExA)(HKEY,LPCSTR,REGSAM,DWORD);
49 static BOOL (WINAPI *pIsWow64Process)(HANDLE,PBOOL);
50 static NTSTATUS (WINAPI * pNtDeleteKey)(HANDLE);
51 static NTSTATUS (WINAPI * pRtlFormatCurrentUserKeyPath)(UNICODE_STRING*);
52 static NTSTATUS (WINAPI * pRtlFreeUnicodeString)(PUNICODE_STRING);
53
54
55 /* Debugging functions from wine/libs/wine/debug.c */
56
57 /* allocate some tmp string space */
58 /* FIXME: this is not 100% thread-safe */
59 static char *get_temp_buffer( int size )
60 {
61 static char *list[32];
62 static UINT pos;
63 char *ret;
64 UINT idx;
65
66 idx = ++pos % (sizeof(list)/sizeof(list[0]));
67 if (list[idx])
68 ret = HeapReAlloc( GetProcessHeap(), 0, list[idx], size );
69 else
70 ret = HeapAlloc( GetProcessHeap(), 0, size );
71 if (ret) list[idx] = ret;
72 return ret;
73 }
74
75 static const char *wine_debugstr_an( const char *str, int n )
76 {
77 static const char hex[16] = "0123456789abcdef";
78 char *dst, *res;
79 size_t size;
80
81 if (!((ULONG_PTR)str >> 16))
82 {
83 if (!str) return "(null)";
84 res = get_temp_buffer( 6 );
85 sprintf( res, "#%04x", LOWORD(str) );
86 return res;
87 }
88 if (n == -1) n = strlen(str);
89 if (n < 0) n = 0;
90 size = 10 + min( 300, n * 4 );
91 dst = res = get_temp_buffer( size );
92 *dst++ = '"';
93 while (n-- > 0 && dst <= res + size - 9)
94 {
95 unsigned char c = *str++;
96 switch (c)
97 {
98 case '\n': *dst++ = '\\'; *dst++ = 'n'; break;
99 case '\r': *dst++ = '\\'; *dst++ = 'r'; break;
100 case '\t': *dst++ = '\\'; *dst++ = 't'; break;
101 case '"': *dst++ = '\\'; *dst++ = '"'; break;
102 case '\\': *dst++ = '\\'; *dst++ = '\\'; break;
103 default:
104 if (c >= ' ' && c <= 126)
105 *dst++ = c;
106 else
107 {
108 *dst++ = '\\';
109 *dst++ = 'x';
110 *dst++ = hex[(c >> 4) & 0x0f];
111 *dst++ = hex[c & 0x0f];
112 }
113 }
114 }
115 *dst++ = '"';
116 if (n > 0)
117 {
118 *dst++ = '.';
119 *dst++ = '.';
120 *dst++ = '.';
121 }
122 *dst++ = 0;
123 return res;
124 }
125
126 #define ADVAPI32_GET_PROC(func) \
127 p ## func = (void*)GetProcAddress(hadvapi32, #func)
128
129 static void InitFunctionPtrs(void)
130 {
131 HMODULE hntdll = GetModuleHandleA("ntdll.dll");
132 HMODULE hkernel32 = GetModuleHandleA("kernel32.dll");
133 HMODULE hadvapi32 = GetModuleHandleA("advapi32.dll");
134
135 /* This function was introduced with Windows 2003 SP1 */
136 ADVAPI32_GET_PROC(RegGetValueA);
137 ADVAPI32_GET_PROC(RegDeleteTreeA);
138 ADVAPI32_GET_PROC(RegDeleteKeyExA);
139
140 pIsWow64Process = (void *)GetProcAddress( hkernel32, "IsWow64Process" );
141 pRtlFormatCurrentUserKeyPath = (void *)GetProcAddress( hntdll, "RtlFormatCurrentUserKeyPath" );
142 pRtlFreeUnicodeString = (void *)GetProcAddress(hntdll, "RtlFreeUnicodeString");
143 pNtDeleteKey = (void *)GetProcAddress( hntdll, "NtDeleteKey" );
144 }
145
146 /* delete key and all its subkeys */
147 static DWORD delete_key( HKEY hkey )
148 {
149 char name[MAX_PATH];
150 DWORD ret;
151
152 if ((ret = RegOpenKeyExA( hkey, "", 0, KEY_ENUMERATE_SUB_KEYS, &hkey ))) return ret;
153 while (!(ret = RegEnumKeyA(hkey, 0, name, sizeof(name))))
154 {
155 HKEY tmp;
156 if (!(ret = RegOpenKeyExA( hkey, name, 0, KEY_ENUMERATE_SUB_KEYS, &tmp )))
157 {
158 ret = delete_key( tmp );
159 RegCloseKey( tmp );
160 }
161 if (ret) break;
162 }
163 if (ret != ERROR_NO_MORE_ITEMS) return ret;
164 RegDeleteKeyA( hkey, "" );
165 RegCloseKey(hkey);
166 return 0;
167 }
168
169 static void setup_main_key(void)
170 {
171 if (!RegOpenKeyA( HKEY_CURRENT_USER, "Software\\Wine\\Test", &hkey_main )) delete_key( hkey_main );
172
173 assert (!RegCreateKeyA( HKEY_CURRENT_USER, "Software\\Wine\\Test", &hkey_main ));
174 }
175
176 #define lok ok_(__FILE__, line)
177 #define test_hkey_main_Value_A(name, string, full_byte_len) _test_hkey_main_Value_A(__LINE__, name, string, full_byte_len)
178 static void _test_hkey_main_Value_A(int line, LPCSTR name, LPCSTR string,
179 DWORD full_byte_len)
180 {
181 DWORD ret, type, cbData;
182 DWORD str_byte_len;
183 BYTE* value;
184
185 type=0xdeadbeef;
186 cbData=0xdeadbeef;
187 /* When successful RegQueryValueExA() leaves GLE as is,
188 * so we must reset it to detect unimplemented functions.
189 */
190 SetLastError(0xdeadbeef);
191 ret = RegQueryValueExA(hkey_main, name, NULL, &type, NULL, &cbData);
192 GLE = GetLastError();
193 lok(ret == ERROR_SUCCESS, "RegQueryValueExA/1 failed: %d, GLE=%d\n", ret, GLE);
194 /* It is wrong for the Ansi version to not be implemented */
195 ok(GLE == 0xdeadbeef, "RegQueryValueExA set GLE = %u\n", GLE);
196 if(GLE == ERROR_CALL_NOT_IMPLEMENTED) return;
197
198 str_byte_len = (string ? lstrlenA(string) : 0) + 1;
199 lok(type == REG_SZ, "RegQueryValueExA/1 returned type %d\n", type);
200 lok(cbData == full_byte_len, "cbData=%d instead of %d or %d\n", cbData, full_byte_len, str_byte_len);
201
202 value = HeapAlloc(GetProcessHeap(), 0, cbData+1);
203 memset(value, 0xbd, cbData+1);
204 type=0xdeadbeef;
205 ret = RegQueryValueExA(hkey_main, name, NULL, &type, value, &cbData);
206 GLE = GetLastError();
207 lok(ret == ERROR_SUCCESS, "RegQueryValueExA/2 failed: %d, GLE=%d\n", ret, GLE);
208 if (!string)
209 {
210 /* When cbData == 0, RegQueryValueExA() should not modify the buffer */
211 lok(*value == 0xbd, "RegQueryValueExA overflowed: cbData=%u *value=%02x\n", cbData, *value);
212 }
213 else
214 {
215 lok(memcmp(value, string, cbData) == 0, "RegQueryValueExA/2 failed: %s/%d != %s/%d\n",
216 wine_debugstr_an((char*)value, cbData), cbData,
217 wine_debugstr_an(string, full_byte_len), full_byte_len);
218 lok(*(value+cbData) == 0xbd, "RegQueryValueExA/2 overflowed at offset %u: %02x != bd\n", cbData, *(value+cbData));
219 }
220 HeapFree(GetProcessHeap(), 0, value);
221 }
222
223 #define test_hkey_main_Value_W(name, string, full_byte_len) _test_hkey_main_Value_W(__LINE__, name, string, full_byte_len)
224 static void _test_hkey_main_Value_W(int line, LPCWSTR name, LPCWSTR string,
225 DWORD full_byte_len)
226 {
227 DWORD ret, type, cbData;
228 BYTE* value;
229
230 type=0xdeadbeef;
231 cbData=0xdeadbeef;
232 /* When successful RegQueryValueExW() leaves GLE as is,
233 * so we must reset it to detect unimplemented functions.
234 */
235 SetLastError(0xdeadbeef);
236 ret = RegQueryValueExW(hkey_main, name, NULL, &type, NULL, &cbData);
237 GLE = GetLastError();
238 lok(ret == ERROR_SUCCESS, "RegQueryValueExW/1 failed: %d, GLE=%d\n", ret, GLE);
239 if(GLE == ERROR_CALL_NOT_IMPLEMENTED)
240 {
241 win_skip("RegQueryValueExW() is not implemented\n");
242 return;
243 }
244
245 lok(type == REG_SZ, "RegQueryValueExW/1 returned type %d\n", type);
246 lok(cbData == full_byte_len,
247 "cbData=%d instead of %d\n", cbData, full_byte_len);
248
249 /* Give enough space to overflow by one WCHAR */
250 value = HeapAlloc(GetProcessHeap(), 0, cbData+2);
251 memset(value, 0xbd, cbData+2);
252 type=0xdeadbeef;
253 ret = RegQueryValueExW(hkey_main, name, NULL, &type, value, &cbData);
254 GLE = GetLastError();
255 lok(ret == ERROR_SUCCESS, "RegQueryValueExW/2 failed: %d, GLE=%d\n", ret, GLE);
256 if (string)
257 {
258 lok(memcmp(value, string, cbData) == 0, "RegQueryValueExW failed: %s/%d != %s/%d\n",
259 wine_dbgstr_wn((WCHAR*)value, cbData / sizeof(WCHAR)), cbData,
260 wine_dbgstr_wn(string, full_byte_len / sizeof(WCHAR)), full_byte_len);
261 }
262 /* This implies that when cbData == 0, RegQueryValueExW() should not modify the buffer */
263 lok(*(value+cbData) == 0xbd, "RegQueryValueExW/2 overflowed at %u: %02x != bd\n", cbData, *(value+cbData));
264 lok(*(value+cbData+1) == 0xbd, "RegQueryValueExW/2 overflowed at %u+1: %02x != bd\n", cbData, *(value+cbData+1));
265 HeapFree(GetProcessHeap(), 0, value);
266 }
267
268 static void test_set_value(void)
269 {
270 DWORD ret;
271
272 static const WCHAR name1W[] = {'C','l','e','a','n','S','i','n','g','l','e','S','t','r','i','n','g', 0};
273 static const WCHAR name2W[] = {'S','o','m','e','I','n','t','r','a','Z','e','r','o','e','d','S','t','r','i','n','g', 0};
274 static const WCHAR emptyW[] = {0};
275 static const WCHAR string1W[] = {'T','h','i','s','N','e','v','e','r','B','r','e','a','k','s', 0};
276 static const WCHAR string2W[] = {'T','h','i','s', 0 ,'B','r','e','a','k','s', 0 , 0 ,'A', 0 , 0 , 0 , 'L','o','t', 0 , 0 , 0 , 0, 0};
277 static const WCHAR substring2W[] = {'T','h','i','s',0};
278
279 static const char name1A[] = "CleanSingleString";
280 static const char name2A[] = "SomeIntraZeroedString";
281 static const char emptyA[] = "";
282 static const char string1A[] = "ThisNeverBreaks";
283 static const char string2A[] = "This\0Breaks\0\0A\0\0\0Lot\0\0\0\0";
284 static const char substring2A[] = "This";
285
286 if (0)
287 {
288 /* Crashes on NT4, Windows 2000 and XP SP1 */
289 ret = RegSetValueA(hkey_main, NULL, REG_SZ, NULL, 0);
290 ok(ret == ERROR_INVALID_PARAMETER, "RegSetValueA should have failed with ERROR_INVALID_PARAMETER instead of %d\n", ret);
291 }
292
293 ret = RegSetValueA(hkey_main, NULL, REG_SZ, string1A, sizeof(string1A));
294 ok(ret == ERROR_SUCCESS, "RegSetValueA failed: %d, GLE=%d\n", ret, GetLastError());
295 test_hkey_main_Value_A(NULL, string1A, sizeof(string1A));
296 test_hkey_main_Value_W(NULL, string1W, sizeof(string1W));
297
298 /* RegSetValueA ignores the size passed in */
299 ret = RegSetValueA(hkey_main, NULL, REG_SZ, string1A, 4);
300 ok(ret == ERROR_SUCCESS, "RegSetValueA failed: %d, GLE=%d\n", ret, GetLastError());
301 test_hkey_main_Value_A(NULL, string1A, sizeof(string1A));
302 test_hkey_main_Value_W(NULL, string1W, sizeof(string1W));
303
304 /* stops at first null */
305 ret = RegSetValueA(hkey_main, NULL, REG_SZ, string2A, sizeof(string2A));
306 ok(ret == ERROR_SUCCESS, "RegSetValueA failed: %d, GLE=%d\n", ret, GetLastError());
307 test_hkey_main_Value_A(NULL, substring2A, sizeof(substring2A));
308 test_hkey_main_Value_W(NULL, substring2W, sizeof(substring2W));
309
310 /* only REG_SZ is supported on NT*/
311 ret = RegSetValueA(hkey_main, NULL, REG_BINARY, string2A, sizeof(string2A));
312 ok(ret == ERROR_INVALID_PARAMETER, "got %d (expected ERROR_INVALID_PARAMETER)\n", ret);
313
314 ret = RegSetValueA(hkey_main, NULL, REG_EXPAND_SZ, string2A, sizeof(string2A));
315 ok(ret == ERROR_INVALID_PARAMETER, "got %d (expected ERROR_INVALID_PARAMETER)\n", ret);
316
317 ret = RegSetValueA(hkey_main, NULL, REG_MULTI_SZ, string2A, sizeof(string2A));
318 ok(ret == ERROR_INVALID_PARAMETER, "got %d (expected ERROR_INVALID_PARAMETER)\n", ret);
319
320 /* Test RegSetValueExA with a 'zero-byte' string (as Office 2003 does).
321 * Surprisingly enough we're supposed to get zero bytes out of it.
322 */
323 ret = RegSetValueExA(hkey_main, name1A, 0, REG_SZ, (const BYTE *)emptyA, 0);
324 ok(ret == ERROR_SUCCESS, "RegSetValueExA failed: %d, GLE=%d\n", ret, GetLastError());
325 test_hkey_main_Value_A(name1A, NULL, 0);
326 test_hkey_main_Value_W(name1W, NULL, 0);
327
328 /* test RegSetValueExA with an empty string */
329 ret = RegSetValueExA(hkey_main, name1A, 0, REG_SZ, (const BYTE *)emptyA, sizeof(emptyA));
330 ok(ret == ERROR_SUCCESS, "RegSetValueExA failed: %d, GLE=%d\n", ret, GetLastError());
331 test_hkey_main_Value_A(name1A, emptyA, sizeof(emptyA));
332 test_hkey_main_Value_W(name1W, emptyW, sizeof(emptyW));
333
334 /* test RegSetValueExA with off-by-one size */
335 ret = RegSetValueExA(hkey_main, name1A, 0, REG_SZ, (const BYTE *)string1A, sizeof(string1A)-sizeof(string1A[0]));
336 ok(ret == ERROR_SUCCESS, "RegSetValueExA failed: %d, GLE=%d\n", ret, GetLastError());
337 test_hkey_main_Value_A(name1A, string1A, sizeof(string1A));
338 test_hkey_main_Value_W(name1W, string1W, sizeof(string1W));
339
340 /* test RegSetValueExA with normal string */
341 ret = RegSetValueExA(hkey_main, name1A, 0, REG_SZ, (const BYTE *)string1A, sizeof(string1A));
342 ok(ret == ERROR_SUCCESS, "RegSetValueExA failed: %d, GLE=%d\n", ret, GetLastError());
343 test_hkey_main_Value_A(name1A, string1A, sizeof(string1A));
344 test_hkey_main_Value_W(name1W, string1W, sizeof(string1W));
345
346 /* test RegSetValueExA with intrazeroed string */
347 ret = RegSetValueExA(hkey_main, name2A, 0, REG_SZ, (const BYTE *)string2A, sizeof(string2A));
348 ok(ret == ERROR_SUCCESS, "RegSetValueExA failed: %d, GLE=%d\n", ret, GetLastError());
349 test_hkey_main_Value_A(name2A, string2A, sizeof(string2A));
350 test_hkey_main_Value_W(name2W, string2W, sizeof(string2W));
351
352 if (0)
353 {
354 /* Crashes on NT4, Windows 2000 and XP SP1 */
355 ret = RegSetValueW(hkey_main, NULL, REG_SZ, NULL, 0);
356 ok(ret == ERROR_INVALID_PARAMETER, "RegSetValueW should have failed with ERROR_INVALID_PARAMETER instead of %d\n", ret);
357
358 RegSetValueExA(hkey_main, name2A, 0, REG_SZ, (const BYTE *)1, 1);
359 RegSetValueExA(hkey_main, name2A, 0, REG_DWORD, (const BYTE *)1, 1);
360 }
361
362 ret = RegSetValueW(hkey_main, NULL, REG_SZ, string1W, sizeof(string1W));
363 ok(ret == ERROR_SUCCESS, "RegSetValueW failed: %d, GLE=%d\n", ret, GetLastError());
364 test_hkey_main_Value_A(NULL, string1A, sizeof(string1A));
365 test_hkey_main_Value_W(NULL, string1W, sizeof(string1W));
366
367 ret = RegSetValueW(hkey_main, name1W, REG_SZ, string1W, sizeof(string1W));
368 ok(ret == ERROR_SUCCESS, "RegSetValueW failed: %d, GLE=%d\n", ret, GetLastError());
369 test_hkey_main_Value_A(name1A, string1A, sizeof(string1A));
370 test_hkey_main_Value_W(name1W, string1W, sizeof(string1W));
371
372 /* RegSetValueW ignores the size passed in */
373 ret = RegSetValueW(hkey_main, NULL, REG_SZ, string1W, 4 * sizeof(string1W[0]));
374 ok(ret == ERROR_SUCCESS, "RegSetValueW failed: %d, GLE=%d\n", ret, GetLastError());
375 test_hkey_main_Value_A(NULL, string1A, sizeof(string1A));
376 test_hkey_main_Value_W(NULL, string1W, sizeof(string1W));
377
378 /* stops at first null */
379 ret = RegSetValueW(hkey_main, NULL, REG_SZ, string2W, sizeof(string2W));
380 ok(ret == ERROR_SUCCESS, "RegSetValueW failed: %d, GLE=%d\n", ret, GetLastError());
381 test_hkey_main_Value_A(NULL, substring2A, sizeof(substring2A));
382 test_hkey_main_Value_W(NULL, substring2W, sizeof(substring2W));
383
384 /* only REG_SZ is supported */
385 ret = RegSetValueW(hkey_main, NULL, REG_BINARY, string2W, sizeof(string2W));
386 ok(ret == ERROR_INVALID_PARAMETER, "RegSetValueW should have returned ERROR_INVALID_PARAMETER instead of %d\n", ret);
387 ret = RegSetValueW(hkey_main, NULL, REG_EXPAND_SZ, string2W, sizeof(string2W));
388 ok(ret == ERROR_INVALID_PARAMETER, "RegSetValueW should have returned ERROR_INVALID_PARAMETER instead of %d\n", ret);
389 ret = RegSetValueW(hkey_main, NULL, REG_MULTI_SZ, string2W, sizeof(string2W));
390 ok(ret == ERROR_INVALID_PARAMETER, "RegSetValueW should have returned ERROR_INVALID_PARAMETER instead of %d\n", ret);
391
392 /* test RegSetValueExW with off-by-one size */
393 ret = RegSetValueExW(hkey_main, name1W, 0, REG_SZ, (const BYTE *)string1W, sizeof(string1W)-sizeof(string1W[0]));
394 ok(ret == ERROR_SUCCESS, "RegSetValueExW failed: %d, GLE=%d\n", ret, GetLastError());
395 test_hkey_main_Value_A(name1A, string1A, sizeof(string1A));
396 test_hkey_main_Value_W(name1W, string1W, sizeof(string1W));
397
398 /* test RegSetValueExW with normal string */
399 ret = RegSetValueExW(hkey_main, name1W, 0, REG_SZ, (const BYTE *)string1W, sizeof(string1W));
400 ok(ret == ERROR_SUCCESS, "RegSetValueExW failed: %d, GLE=%d\n", ret, GetLastError());
401 test_hkey_main_Value_A(name1A, string1A, sizeof(string1A));
402 test_hkey_main_Value_W(name1W, string1W, sizeof(string1W));
403
404 /* test RegSetValueExW with intrazeroed string */
405 ret = RegSetValueExW(hkey_main, name2W, 0, REG_SZ, (const BYTE *)string2W, sizeof(string2W));
406 ok(ret == ERROR_SUCCESS, "RegSetValueExW failed: %d, GLE=%d\n", ret, GetLastError());
407 test_hkey_main_Value_A(name2A, string2A, sizeof(string2A));
408 test_hkey_main_Value_W(name2W, string2W, sizeof(string2W));
409
410 /* test RegSetValueExW with data = 1 */
411 ret = RegSetValueExW(hkey_main, name2W, 0, REG_SZ, (const BYTE *)1, 1);
412 ok(ret == ERROR_NOACCESS, "RegSetValueExW should have failed with ERROR_NOACCESS: %d, GLE=%d\n", ret, GetLastError());
413 ret = RegSetValueExW(hkey_main, name2W, 0, REG_DWORD, (const BYTE *)1, 1);
414 ok(ret == ERROR_NOACCESS, "RegSetValueExW should have failed with ERROR_NOACCESS: %d, GLE=%d\n", ret, GetLastError());
415 }
416
417 static void create_test_entries(void)
418 {
419 static const DWORD qw[2] = { 0x12345678, 0x87654321 };
420
421 SetEnvironmentVariableA("LONGSYSTEMVAR", "bar");
422 SetEnvironmentVariableA("FOO", "ImARatherLongButIndeedNeededString");
423
424 ok(!RegSetValueExA(hkey_main,"TP1_EXP_SZ",0,REG_EXPAND_SZ, (const BYTE *)sTestpath1, strlen(sTestpath1)+1),
425 "RegSetValueExA failed\n");
426 ok(!RegSetValueExA(hkey_main,"TP1_SZ",0,REG_SZ, (const BYTE *)sTestpath1, strlen(sTestpath1)+1),
427 "RegSetValueExA failed\n");
428 ok(!RegSetValueExA(hkey_main,"TP1_ZB_SZ",0,REG_SZ, (const BYTE *)"", 0),
429 "RegSetValueExA failed\n");
430 ok(!RegSetValueExA(hkey_main,"TP2_EXP_SZ",0,REG_EXPAND_SZ, (const BYTE *)sTestpath2, strlen(sTestpath2)+1),
431 "RegSetValueExA failed\n");
432 ok(!RegSetValueExA(hkey_main,"DWORD",0,REG_DWORD, (const BYTE *)qw, 4),
433 "RegSetValueExA failed\n");
434 ok(!RegSetValueExA(hkey_main,"BIN32",0,REG_BINARY, (const BYTE *)qw, 4),
435 "RegSetValueExA failed\n");
436 ok(!RegSetValueExA(hkey_main,"BIN64",0,REG_BINARY, (const BYTE *)qw, 8),
437 "RegSetValueExA failed\n");
438 }
439
440 static void test_enum_value(void)
441 {
442 DWORD res;
443 HKEY test_key;
444 char value[20], data[20];
445 WCHAR valueW[20], dataW[20];
446 DWORD val_count, data_count, type;
447 static const WCHAR foobarW[] = {'f','o','o','b','a','r',0};
448 static const WCHAR testW[] = {'T','e','s','t',0};
449 static const WCHAR xxxW[] = {'x','x','x','x','x','x','x','x',0};
450
451 /* create the working key for new 'Test' value */
452 res = RegCreateKeyA( hkey_main, "TestKey", &test_key );
453 ok( res == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %d\n", res);
454
455 /* check NULL data with zero length */
456 res = RegSetValueExA( test_key, "Test", 0, REG_SZ, NULL, 0 );
457 if (GetVersion() & 0x80000000)
458 ok( res == ERROR_INVALID_PARAMETER, "RegSetValueExA returned %d\n", res );
459 else
460 ok( !res, "RegSetValueExA returned %d\n", res );
461 res = RegSetValueExA( test_key, "Test", 0, REG_EXPAND_SZ, NULL, 0 );
462 ok( ERROR_SUCCESS == res || ERROR_INVALID_PARAMETER == res, "RegSetValueExA returned %d\n", res );
463 res = RegSetValueExA( test_key, "Test", 0, REG_BINARY, NULL, 0 );
464 ok( ERROR_SUCCESS == res || ERROR_INVALID_PARAMETER == res, "RegSetValueExA returned %d\n", res );
465
466 res = RegSetValueExA( test_key, "Test", 0, REG_SZ, (const BYTE *)"foobar", 7 );
467 ok( res == 0, "RegSetValueExA failed error %d\n", res );
468
469 /* overflow both name and data */
470 val_count = 2;
471 data_count = 2;
472 type = 1234;
473 strcpy( value, "xxxxxxxxxx" );
474 strcpy( data, "xxxxxxxxxx" );
475 res = RegEnumValueA( test_key, 0, value, &val_count, NULL, &type, (LPBYTE)data, &data_count );
476 ok( res == ERROR_MORE_DATA, "expected ERROR_MORE_DATA, got %d\n", res );
477 ok( val_count == 2, "val_count set to %d\n", val_count );
478 ok( data_count == 7 || broken( data_count == 8 ), "data_count set to %d instead of 7\n", data_count );
479 ok( type == REG_SZ, "type %d is not REG_SZ\n", type );
480 ok( !strcmp( value, "xxxxxxxxxx" ), "value set to '%s'\n", value );
481 ok( !strcmp( data, "xxxxxxxxxx" ), "data set to '%s'\n", data );
482
483 /* overflow name */
484 val_count = 3;
485 data_count = 20;
486 type = 1234;
487 strcpy( value, "xxxxxxxxxx" );
488 strcpy( data, "xxxxxxxxxx" );
489 res = RegEnumValueA( test_key, 0, value, &val_count, NULL, &type, (LPBYTE)data, &data_count );
490 ok( res == ERROR_MORE_DATA, "expected ERROR_MORE_DATA, got %d\n", res );
491 ok( val_count == 3, "val_count set to %d\n", val_count );
492 ok( data_count == 7 || broken( data_count == 8 ), "data_count set to %d instead of 7\n", data_count );
493 ok( type == REG_SZ, "type %d is not REG_SZ\n", type );
494 /* v5.1.2600.0 (XP Home and Professional) does not touch value or data in this case */
495 ok( !strcmp( value, "Te" ) || !strcmp( value, "xxxxxxxxxx" ),
496 "value set to '%s' instead of 'Te' or 'xxxxxxxxxx'\n", value );
497 ok( !strcmp( data, "foobar" ) || !strcmp( data, "xxxxxxx" ) || broken( !strcmp( data, "xxxxxxxx" ) && data_count == 8 ),
498 "data set to '%s' instead of 'foobar' or 'xxxxxxx'\n", data );
499
500 /* overflow empty name */
501 val_count = 0;
502 data_count = 20;
503 type = 1234;
504 strcpy( value, "xxxxxxxxxx" );
505 strcpy( data, "xxxxxxxxxx" );
506 res = RegEnumValueA( test_key, 0, value, &val_count, NULL, &type, (LPBYTE)data, &data_count );
507 ok( res == ERROR_MORE_DATA, "expected ERROR_MORE_DATA, got %d\n", res );
508 ok( val_count == 0, "val_count set to %d\n", val_count );
509 ok( data_count == 7 || broken( data_count == 8 ), "data_count set to %d instead of 7\n", data_count );
510 ok( type == REG_SZ, "type %d is not REG_SZ\n", type );
511 ok( !strcmp( value, "xxxxxxxxxx" ), "value set to '%s'\n", value );
512 /* v5.1.2600.0 (XP Home and Professional) does not touch data in this case */
513 ok( !strcmp( data, "foobar" ) || !strcmp( data, "xxxxxxx" ) || broken( !strcmp( data, "xxxxxxxx" ) && data_count == 8 ),
514 "data set to '%s' instead of 'foobar' or 'xxxxxxx'\n", data );
515
516 /* overflow data */
517 val_count = 20;
518 data_count = 2;
519 type = 1234;
520 strcpy( value, "xxxxxxxxxx" );
521 strcpy( data, "xxxxxxxxxx" );
522 res = RegEnumValueA( test_key, 0, value, &val_count, NULL, &type, (LPBYTE)data, &data_count );
523 ok( res == ERROR_MORE_DATA, "expected ERROR_MORE_DATA, got %d\n", res );
524 ok( val_count == 20, "val_count set to %d\n", val_count );
525 ok( data_count == 7, "data_count set to %d instead of 7\n", data_count );
526 ok( type == REG_SZ, "type %d is not REG_SZ\n", type );
527 ok( !strcmp( value, "xxxxxxxxxx" ), "value set to '%s'\n", value );
528 ok( !strcmp( data, "xxxxxxxxxx" ), "data set to '%s'\n", data );
529
530 /* no overflow */
531 val_count = 20;
532 data_count = 20;
533 type = 1234;
534 strcpy( value, "xxxxxxxxxx" );
535 strcpy( data, "xxxxxxxxxx" );
536 res = RegEnumValueA( test_key, 0, value, &val_count, NULL, &type, (LPBYTE)data, &data_count );
537 ok( res == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %d\n", res );
538 ok( val_count == 4, "val_count set to %d instead of 4\n", val_count );
539 ok( data_count == 7, "data_count set to %d instead of 7\n", data_count );
540 ok( type == REG_SZ, "type %d is not REG_SZ\n", type );
541 ok( !strcmp( value, "Test" ), "value is '%s' instead of Test\n", value );
542 ok( !strcmp( data, "foobar" ), "data is '%s' instead of foobar\n", data );
543
544 /* Unicode tests */
545
546 SetLastError(0xdeadbeef);
547 res = RegSetValueExW( test_key, testW, 0, REG_SZ, (const BYTE *)foobarW, 7*sizeof(WCHAR) );
548 if (res==0 && GetLastError()==ERROR_CALL_NOT_IMPLEMENTED)
549 {
550 win_skip("RegSetValueExW is not implemented\n");
551 goto cleanup;
552 }
553 ok( res == 0, "RegSetValueExW failed error %d\n", res );
554
555 /* overflow both name and data */
556 val_count = 2;
557 data_count = 2;
558 type = 1234;
559 memcpy( valueW, xxxW, sizeof(xxxW) );
560 memcpy( dataW, xxxW, sizeof(xxxW) );
561 res = RegEnumValueW( test_key, 0, valueW, &val_count, NULL, &type, (BYTE*)dataW, &data_count );
562 ok( res == ERROR_MORE_DATA, "expected ERROR_MORE_DATA, got %d\n", res );
563 ok( val_count == 2, "val_count set to %d\n", val_count );
564 ok( data_count == 7*sizeof(WCHAR), "data_count set to %d instead of 7*sizeof(WCHAR)\n", data_count );
565 ok( type == REG_SZ, "type %d is not REG_SZ\n", type );
566 ok( !memcmp( valueW, xxxW, sizeof(xxxW) ), "value modified\n" );
567 ok( !memcmp( dataW, xxxW, sizeof(xxxW) ), "data modified\n" );
568
569 /* overflow name */
570 val_count = 3;
571 data_count = 20;
572 type = 1234;
573 memcpy( valueW, xxxW, sizeof(xxxW) );
574 memcpy( dataW, xxxW, sizeof(xxxW) );
575 res = RegEnumValueW( test_key, 0, valueW, &val_count, NULL, &type, (BYTE*)dataW, &data_count );
576 ok( res == ERROR_MORE_DATA, "expected ERROR_MORE_DATA, got %d\n", res );
577 ok( val_count == 3, "val_count set to %d\n", val_count );
578 ok( data_count == 7*sizeof(WCHAR), "data_count set to %d instead of 7*sizeof(WCHAR)\n", data_count );
579 ok( type == REG_SZ, "type %d is not REG_SZ\n", type );
580 ok( !memcmp( valueW, xxxW, sizeof(xxxW) ), "value modified\n" );
581 ok( !memcmp( dataW, xxxW, sizeof(xxxW) ), "data modified\n" );
582
583 /* overflow data */
584 val_count = 20;
585 data_count = 2;
586 type = 1234;
587 memcpy( valueW, xxxW, sizeof(xxxW) );
588 memcpy( dataW, xxxW, sizeof(xxxW) );
589 res = RegEnumValueW( test_key, 0, valueW, &val_count, NULL, &type, (BYTE*)dataW, &data_count );
590 ok( res == ERROR_MORE_DATA, "expected ERROR_MORE_DATA, got %d\n", res );
591 ok( val_count == 4, "val_count set to %d instead of 4\n", val_count );
592 ok( data_count == 7*sizeof(WCHAR), "data_count set to %d instead of 7*sizeof(WCHAR)\n", data_count );
593 ok( type == REG_SZ, "type %d is not REG_SZ\n", type );
594 ok( !memcmp( valueW, testW, sizeof(testW) ), "value is not 'Test'\n" );
595 ok( !memcmp( dataW, xxxW, sizeof(xxxW) ), "data modified\n" );
596
597 /* no overflow */
598 val_count = 20;
599 data_count = 20;
600 type = 1234;
601 memcpy( valueW, xxxW, sizeof(xxxW) );
602 memcpy( dataW, xxxW, sizeof(xxxW) );
603 res = RegEnumValueW( test_key, 0, valueW, &val_count, NULL, &type, (BYTE*)dataW, &data_count );
604 ok( res == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %d\n", res );
605 ok( val_count == 4, "val_count set to %d instead of 4\n", val_count );
606 ok( data_count == 7*sizeof(WCHAR), "data_count set to %d instead of 7*sizeof(WCHAR)\n", data_count );
607 ok( type == REG_SZ, "type %d is not REG_SZ\n", type );
608 ok( !memcmp( valueW, testW, sizeof(testW) ), "value is not 'Test'\n" );
609 ok( !memcmp( dataW, foobarW, sizeof(foobarW) ), "data is not 'foobar'\n" );
610
611 cleanup:
612 RegDeleteKeyA(test_key, "");
613 RegCloseKey(test_key);
614 }
615
616 static void test_query_value_ex(void)
617 {
618 DWORD ret;
619 DWORD size;
620 DWORD type;
621 BYTE buffer[10];
622
623 ret = RegQueryValueExA(hkey_main, "TP1_SZ", NULL, &type, NULL, &size);
624 ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %d\n", ret);
625 ok(size == strlen(sTestpath1) + 1, "(%d,%d)\n", (DWORD)strlen(sTestpath1) + 1, size);
626 ok(type == REG_SZ, "type %d is not REG_SZ\n", type);
627
628 type = 0xdeadbeef;
629 size = 0xdeadbeef;
630 ret = RegQueryValueExA(HKEY_CLASSES_ROOT, "Nonexistent Value", NULL, &type, NULL, &size);
631 ok(ret == ERROR_FILE_NOT_FOUND, "expected ERROR_FILE_NOT_FOUND, got %d\n", ret);
632 ok(size == 0, "size should have been set to 0 instead of %d\n", size);
633
634 size = sizeof(buffer);
635 ret = RegQueryValueExA(HKEY_CLASSES_ROOT, "Nonexistent Value", NULL, &type, buffer, &size);
636 ok(ret == ERROR_FILE_NOT_FOUND, "expected ERROR_FILE_NOT_FOUND, got %d\n", ret);
637 ok(size == sizeof(buffer), "size shouldn't have been changed to %d\n", size);
638
639 size = 4;
640 ret = RegQueryValueExA(hkey_main, "BIN32", NULL, &size, buffer, &size);
641 ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %d\n", ret);
642 }
643
644 static void test_get_value(void)
645 {
646 DWORD ret;
647 DWORD size;
648 DWORD type;
649 DWORD dw, qw[2];
650 CHAR buf[80];
651 CHAR expanded[] = "bar\\subdir1";
652 CHAR expanded2[] = "ImARatherLongButIndeedNeededString\\subdir1";
653
654 if(!pRegGetValueA)
655 {
656 win_skip("RegGetValue not available on this platform\n");
657 return;
658 }
659
660 /* Invalid parameter */
661 ret = pRegGetValueA(hkey_main, NULL, "DWORD", RRF_RT_REG_DWORD, &type, &dw, NULL);
662 ok(ret == ERROR_INVALID_PARAMETER, "ret=%d\n", ret);
663
664 /* Query REG_DWORD using RRF_RT_REG_DWORD (ok) */
665 size = type = dw = 0xdeadbeef;
666 ret = pRegGetValueA(hkey_main, NULL, "DWORD", RRF_RT_REG_DWORD, &type, &dw, &size);
667 ok(ret == ERROR_SUCCESS, "ret=%d\n", ret);
668 ok(size == 4, "size=%d\n", size);
669 ok(type == REG_DWORD, "type=%d\n", type);
670 ok(dw == 0x12345678, "dw=%d\n", dw);
671
672 /* Query by subkey-name */
673 ret = pRegGetValueA(HKEY_CURRENT_USER, "Software\\Wine\\Test", "DWORD", RRF_RT_REG_DWORD, NULL, NULL, NULL);
674 ok(ret == ERROR_SUCCESS, "ret=%d\n", ret);
675
676 /* Query REG_DWORD using RRF_RT_REG_BINARY (restricted) */
677 size = type = dw = 0xdeadbeef;
678 ret = pRegGetValueA(hkey_main, NULL, "DWORD", RRF_RT_REG_BINARY, &type, &dw, &size);
679 ok(ret == ERROR_UNSUPPORTED_TYPE, "ret=%d\n", ret);
680 /* Although the function failed all values are retrieved */
681 ok(size == 4, "size=%d\n", size);
682 ok(type == REG_DWORD, "type=%d\n", type);
683 ok(dw == 0x12345678, "dw=%d\n", dw);
684
685 /* Test RRF_ZEROONFAILURE */
686 type = dw = 0xdeadbeef; size = 4;
687 ret = pRegGetValueA(hkey_main, NULL, "DWORD", RRF_RT_REG_SZ|RRF_ZEROONFAILURE, &type, &dw, &size);
688 ok(ret == ERROR_UNSUPPORTED_TYPE, "ret=%d\n", ret);
689 /* Again all values are retrieved ... */
690 ok(size == 4, "size=%d\n", size);
691 ok(type == REG_DWORD, "type=%d\n", type);
692 /* ... except the buffer, which is zeroed out */
693 ok(dw == 0, "dw=%d\n", dw);
694
695 /* Test RRF_ZEROONFAILURE with a NULL buffer... */
696 type = size = 0xbadbeef;
697 ret = pRegGetValueA(hkey_main, NULL, "DWORD", RRF_RT_REG_SZ|RRF_ZEROONFAILURE, &type, NULL, &size);
698 ok(ret == ERROR_UNSUPPORTED_TYPE, "ret=%d\n", ret);
699 ok(size == 4, "size=%d\n", size);
700 ok(type == REG_DWORD, "type=%d\n", type);
701
702 /* Query REG_DWORD using RRF_RT_DWORD (ok) */
703 size = type = dw = 0xdeadbeef;
704 ret = pRegGetValueA(hkey_main, NULL, "DWORD", RRF_RT_DWORD, &type, &dw, &size);
705 ok(ret == ERROR_SUCCESS, "ret=%d\n", ret);
706 ok(size == 4, "size=%d\n", size);
707 ok(type == REG_DWORD, "type=%d\n", type);
708 ok(dw == 0x12345678, "dw=%d\n", dw);
709
710 /* Query 32-bit REG_BINARY using RRF_RT_DWORD (ok) */
711 size = type = dw = 0xdeadbeef;
712 ret = pRegGetValueA(hkey_main, NULL, "BIN32", RRF_RT_DWORD, &type, &dw, &size);
713 ok(ret == ERROR_SUCCESS, "ret=%d\n", ret);
714 ok(size == 4, "size=%d\n", size);
715 ok(type == REG_BINARY, "type=%d\n", type);
716 ok(dw == 0x12345678, "dw=%d\n", dw);
717
718 /* Query 64-bit REG_BINARY using RRF_RT_DWORD (type mismatch) */
719 qw[0] = qw[1] = size = type = 0xdeadbeef;
720 ret = pRegGetValueA(hkey_main, NULL, "BIN64", RRF_RT_DWORD, &type, qw, &size);
721 ok(ret == ERROR_DATATYPE_MISMATCH, "ret=%d\n", ret);
722 ok(size == 8, "size=%d\n", size);
723 ok(type == REG_BINARY, "type=%d\n", type);
724 ok(qw[0] == 0x12345678 &&
725 qw[1] == 0x87654321, "qw={%d,%d}\n", qw[0], qw[1]);
726
727 /* Query 64-bit REG_BINARY using 32-bit buffer (buffer too small) */
728 type = dw = 0xdeadbeef; size = 4;
729 ret = pRegGetValueA(hkey_main, NULL, "BIN64", RRF_RT_REG_BINARY, &type, &dw, &size);
730 ok(ret == ERROR_MORE_DATA, "ret=%d\n", ret);
731 ok(dw == 0xdeadbeef, "dw=%d\n", dw);
732 ok(size == 8, "size=%d\n", size);
733
734 /* Query 64-bit REG_BINARY using RRF_RT_QWORD (ok) */
735 qw[0] = qw[1] = size = type = 0xdeadbeef;
736 ret = pRegGetValueA(hkey_main, NULL, "BIN64", RRF_RT_QWORD, &type, qw, &size);
737 ok(ret == ERROR_SUCCESS, "ret=%d\n", ret);
738 ok(size == 8, "size=%d\n", size);
739 ok(type == REG_BINARY, "type=%d\n", type);
740 ok(qw[0] == 0x12345678 &&
741 qw[1] == 0x87654321, "qw={%d,%d}\n", qw[0], qw[1]);
742
743 /* Query REG_SZ using RRF_RT_REG_SZ (ok) */
744 buf[0] = 0; type = 0xdeadbeef; size = sizeof(buf);
745 ret = pRegGetValueA(hkey_main, NULL, "TP1_SZ", RRF_RT_REG_SZ, &type, buf, &size);
746 ok(ret == ERROR_SUCCESS, "ret=%d\n", ret);
747 ok(size == strlen(sTestpath1)+1, "strlen(sTestpath1)=%d size=%d\n", lstrlenA(sTestpath1), size);
748 ok(type == REG_SZ, "type=%d\n", type);
749 ok(!strcmp(sTestpath1, buf), "sTestpath=\"%s\" buf=\"%s\"\n", sTestpath1, buf);
750
751 /* Query REG_SZ using RRF_RT_REG_SZ and no buffer (ok) */
752 type = 0xdeadbeef; size = 0;
753 ret = pRegGetValueA(hkey_main, NULL, "TP1_SZ", RRF_RT_REG_SZ, &type, NULL, &size);
754 ok(ret == ERROR_SUCCESS, "ret=%d\n", ret);
755 /* v5.2.3790.1830 (2003 SP1) returns sTestpath1 length + 2 here. */
756 ok(size == strlen(sTestpath1)+1 || broken(size == strlen(sTestpath1)+2),
757 "strlen(sTestpath1)=%d size=%d\n", lstrlenA(sTestpath1), size);
758 ok(type == REG_SZ, "type=%d\n", type);
759
760 /* Query REG_SZ using RRF_RT_REG_SZ on a zero-byte value (ok) */
761 strcpy(buf, sTestpath1);
762 type = 0xdeadbeef;
763 size = sizeof(buf);
764 ret = pRegGetValueA(hkey_main, NULL, "TP1_ZB_SZ", RRF_RT_REG_SZ, &type, buf, &size);
765 ok(ret == ERROR_SUCCESS, "ret=%d\n", ret);
766 /* v5.2.3790.1830 (2003 SP1) returns sTestpath1 length + 2 here. */
767 ok(size == 0 ||
768 size == 1, /* win2k3 */
769 "size=%d\n", size);
770 ok(type == REG_SZ, "type=%d\n", type);
771 ok(!strcmp(sTestpath1, buf) ||
772 !strcmp(buf, ""),
773 "Expected \"%s\" or \"\", got \"%s\"\n", sTestpath1, buf);
774
775 /* Query REG_SZ using RRF_RT_REG_SZ|RRF_NOEXPAND (ok) */
776 buf[0] = 0; type = 0xdeadbeef; size = sizeof(buf);
777 ret = pRegGetValueA(hkey_main, NULL, "TP1_SZ", RRF_RT_REG_SZ|RRF_NOEXPAND, &type, buf, &size);
778 ok(ret == ERROR_SUCCESS, "ret=%d\n", ret);
779 ok(size == strlen(sTestpath1)+1, "strlen(sTestpath1)=%d size=%d\n", lstrlenA(sTestpath1), size);
780 ok(type == REG_SZ, "type=%d\n", type);
781 ok(!strcmp(sTestpath1, buf), "sTestpath=\"%s\" buf=\"%s\"\n", sTestpath1, buf);
782
783 /* Query REG_EXPAND_SZ using RRF_RT_REG_SZ and no buffer (ok, expands) */
784 size = 0;
785 ret = pRegGetValueA(hkey_main, NULL, "TP2_EXP_SZ", RRF_RT_REG_SZ, NULL, NULL, &size);
786 ok(ret == ERROR_SUCCESS, "ret=%d\n", ret);
787 ok((size == strlen(expanded2)+1) || /* win2k3 SP1 */
788 (size == strlen(expanded2)+2) || /* win2k3 SP2 */
789 (size == strlen(sTestpath2)+1),
790 "strlen(expanded2)=%d, strlen(sTestpath2)=%d, size=%d\n", lstrlenA(expanded2), lstrlenA(sTestpath2), size);
791
792 /* Query REG_EXPAND_SZ using RRF_RT_REG_SZ (ok, expands) */
793 buf[0] = 0; type = 0xdeadbeef; size = sizeof(buf);
794 ret = pRegGetValueA(hkey_main, NULL, "TP1_EXP_SZ", RRF_RT_REG_SZ, &type, buf, &size);
795 ok(ret == ERROR_SUCCESS, "ret=%d\n", ret);
796 /* At least v5.2.3790.1830 (2003 SP1) returns the unexpanded sTestpath1 length + 1 here. */
797 ok(size == strlen(expanded)+1 || broken(size == strlen(sTestpath1)+1),
798 "strlen(expanded)=%d, strlen(sTestpath1)=%d, size=%d\n", lstrlenA(expanded), lstrlenA(sTestpath1), size);
799 ok(type == REG_SZ, "type=%d\n", type);
800 ok(!strcmp(expanded, buf), "expanded=\"%s\" buf=\"%s\"\n", expanded, buf);
801
802 /* Query REG_EXPAND_SZ using RRF_RT_REG_SZ (ok, expands a lot) */
803 buf[0] = 0; type = 0xdeadbeef; size = sizeof(buf);
804 ret = pRegGetValueA(hkey_main, NULL, "TP2_EXP_SZ", RRF_RT_REG_SZ, &type, buf, &size);
805 ok(ret == ERROR_SUCCESS, "ret=%d\n", ret);
806 /* At least v5.2.3790.1830 (2003 SP1) returns the unexpanded sTestpath2 length + 1 here. */
807 ok(size == strlen(expanded2)+1 || broken(size == strlen(sTestpath2)+1),
808 "strlen(expanded2)=%d, strlen(sTestpath1)=%d, size=%d\n", lstrlenA(expanded2), lstrlenA(sTestpath2), size);
809 ok(type == REG_SZ, "type=%d\n", type);
810 ok(!strcmp(expanded2, buf), "expanded2=\"%s\" buf=\"%s\"\n", expanded2, buf);
811
812 /* Query REG_EXPAND_SZ using RRF_RT_REG_EXPAND_SZ|RRF_NOEXPAND (ok, doesn't expand) */
813 buf[0] = 0; type = 0xdeadbeef; size = sizeof(buf);
814 ret = pRegGetValueA(hkey_main, NULL, "TP1_EXP_SZ", RRF_RT_REG_EXPAND_SZ|RRF_NOEXPAND, &type, buf, &size);
815 ok(ret == ERROR_SUCCESS, "ret=%d\n", ret);
816 ok(size == strlen(sTestpath1)+1, "strlen(sTestpath1)=%d size=%d\n", lstrlenA(sTestpath1), size);
817 ok(type == REG_EXPAND_SZ, "type=%d\n", type);
818 ok(!strcmp(sTestpath1, buf), "sTestpath=\"%s\" buf=\"%s\"\n", sTestpath1, buf);
819
820 /* Query REG_EXPAND_SZ using RRF_RT_REG_EXPAND_SZ|RRF_NOEXPAND and no buffer (ok, doesn't expand) */
821 size = 0xbadbeef;
822 ret = pRegGetValueA(hkey_main, NULL, "TP1_EXP_SZ", RRF_RT_REG_EXPAND_SZ|RRF_NOEXPAND, NULL, NULL, &size);
823 ok(ret == ERROR_SUCCESS, "ret=%d\n", ret);
824 /* v5.2.3790.1830 (2003 SP1) returns sTestpath1 length + 2 here. */
825 ok(size == strlen(sTestpath1)+1 || broken(size == strlen(sTestpath1)+2),
826 "strlen(sTestpath1)=%d size=%d\n", lstrlenA(sTestpath1), size);
827
828 /* Query REG_EXPAND_SZ using RRF_RT_REG_SZ|RRF_NOEXPAND (type mismatch) */
829 ret = pRegGetValueA(hkey_main, NULL, "TP1_EXP_SZ", RRF_RT_REG_SZ|RRF_NOEXPAND, NULL, NULL, NULL);
830 ok(ret == ERROR_UNSUPPORTED_TYPE, "ret=%d\n", ret);
831
832 /* Query REG_EXPAND_SZ using RRF_RT_REG_EXPAND_SZ (not allowed without RRF_NOEXPAND) */
833 ret = pRegGetValueA(hkey_main, NULL, "TP1_EXP_SZ", RRF_RT_REG_EXPAND_SZ, NULL, NULL, NULL);
834 /* before win8: ERROR_INVALID_PARAMETER, win8: ERROR_UNSUPPORTED_TYPE */
835 ok(ret == ERROR_INVALID_PARAMETER || ret == ERROR_UNSUPPORTED_TYPE, "ret=%d\n", ret);
836
837 /* Query REG_EXPAND_SZ using RRF_RT_ANY */
838 buf[0] = 0; type = 0xdeadbeef; size = sizeof(buf);
839 ret = pRegGetValueA(hkey_main, NULL, "TP1_EXP_SZ", RRF_RT_ANY, &type, buf, &size);
840 ok(ret == ERROR_SUCCESS, "ret=%d\n", ret);
841 /* At least v5.2.3790.1830 (2003 SP1) returns the unexpanded sTestpath1 length + 1 here. */
842 ok(size == strlen(expanded)+1 || broken(size == strlen(sTestpath1)+1),
843 "strlen(expanded)=%d, strlen(sTestpath1)=%d, size=%d\n", lstrlenA(expanded), lstrlenA(sTestpath1), size);
844 ok(type == REG_SZ, "type=%d\n", type);
845 ok(!strcmp(expanded, buf), "expanded=\"%s\" buf=\"%s\"\n", expanded, buf);
846 }
847
848 static void test_reg_open_key(void)
849 {
850 DWORD ret = 0;
851 HKEY hkResult = NULL;
852 HKEY hkPreserve = NULL;
853 HKEY hkRoot64 = NULL;
854 HKEY hkRoot32 = NULL;
855 BOOL bRet;
856 SID_IDENTIFIER_AUTHORITY sid_authority = {SECURITY_WORLD_SID_AUTHORITY};
857 PSID world_sid;
858 EXPLICIT_ACCESSA access;
859 PACL key_acl;
860 SECURITY_DESCRIPTOR *sd;
861
862 /* successful open */
863 ret = RegOpenKeyA(HKEY_CURRENT_USER, "Software\\Wine\\Test", &hkResult);
864 ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %d\n", ret);
865 ok(hkResult != NULL, "expected hkResult != NULL\n");
866 hkPreserve = hkResult;
867
868 /* open same key twice */
869 ret = RegOpenKeyA(HKEY_CURRENT_USER, "Software\\Wine\\Test", &hkResult);
870 ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %d\n", ret);
871 ok(hkResult != hkPreserve, "expected hkResult != hkPreserve\n");
872 ok(hkResult != NULL, "hkResult != NULL\n");
873 RegCloseKey(hkResult);
874
875 /* open nonexistent key
876 * check that hkResult is set to NULL
877 */
878 hkResult = hkPreserve;
879 ret = RegOpenKeyA(HKEY_CURRENT_USER, "Software\\Wine\\Nonexistent", &hkResult);
880 ok(ret == ERROR_FILE_NOT_FOUND, "expected ERROR_FILE_NOT_FOUND, got %d\n", ret);
881 ok(hkResult == NULL, "expected hkResult == NULL\n");
882
883 /* open the same nonexistent key again to make sure the key wasn't created */
884 hkResult = hkPreserve;
885 ret = RegOpenKeyA(HKEY_CURRENT_USER, "Software\\Wine\\Nonexistent", &hkResult);
886 ok(ret == ERROR_FILE_NOT_FOUND, "expected ERROR_FILE_NOT_FOUND, got %d\n", ret);
887 ok(hkResult == NULL, "expected hkResult == NULL\n");
888
889 /* send in NULL lpSubKey
890 * check that hkResult receives the value of hKey
891 */
892 hkResult = hkPreserve;
893 ret = RegOpenKeyA(HKEY_CURRENT_USER, NULL, &hkResult);
894 ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %d\n", ret);
895 ok(hkResult == HKEY_CURRENT_USER, "expected hkResult == HKEY_CURRENT_USER\n");
896
897 /* send empty-string in lpSubKey */
898 hkResult = hkPreserve;
899 ret = RegOpenKeyA(HKEY_CURRENT_USER, "", &hkResult);
900 ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %d\n", ret);
901 ok(hkResult == HKEY_CURRENT_USER, "expected hkResult == HKEY_CURRENT_USER\n");
902
903 /* send in NULL lpSubKey and NULL hKey
904 * hkResult is set to NULL
905 */
906 hkResult = hkPreserve;
907 ret = RegOpenKeyA(NULL, NULL, &hkResult);
908 ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %d\n", ret);
909 ok(hkResult == NULL, "expected hkResult == NULL\n");
910
911 /* only send NULL hKey
912 * the value of hkResult remains unchanged
913 */
914 hkResult = hkPreserve;
915 ret = RegOpenKeyA(NULL, "Software\\Wine\\Test", &hkResult);
916 ok(ret == ERROR_INVALID_HANDLE || ret == ERROR_BADKEY, /* Windows 95 returns BADKEY */
917 "expected ERROR_INVALID_HANDLE or ERROR_BADKEY, got %d\n", ret);
918 ok(hkResult == hkPreserve, "expected hkResult == hkPreserve\n");
919 RegCloseKey(hkResult);
920
921 /* send in NULL hkResult */
922 ret = RegOpenKeyA(HKEY_CURRENT_USER, "Software\\Wine\\Test", NULL);
923 ok(ret == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %d\n", ret);
924
925 ret = RegOpenKeyA(HKEY_CURRENT_USER, NULL, NULL);
926 ok(ret == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %d\n", ret);
927
928 ret = RegOpenKeyA(NULL, NULL, NULL);
929 ok(ret == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %d\n", ret);
930
931 /* beginning backslash character */
932 ret = RegOpenKeyA(HKEY_CURRENT_USER, "\\Software\\Wine\\Test", &hkResult);
933 ok(ret == ERROR_BAD_PATHNAME || /* NT/2k/XP */
934 broken(ret == ERROR_SUCCESS), /* wow64 */
935 "expected ERROR_BAD_PATHNAME or ERROR_FILE_NOT_FOUND, got %d\n", ret);
936 if (!ret) RegCloseKey(hkResult);
937
938 hkResult = NULL;
939 ret = RegOpenKeyExA(HKEY_CLASSES_ROOT, "\\clsid", 0, KEY_QUERY_VALUE, &hkResult);
940 ok(ret == ERROR_SUCCESS || /* 2k/XP */
941 ret == ERROR_BAD_PATHNAME, /* NT */
942 "expected ERROR_SUCCESS, ERROR_BAD_PATHNAME or ERROR_FILE_NOT_FOUND, got %d\n", ret);
943 RegCloseKey(hkResult);
944
945 /* WOW64 flags */
946 hkResult = NULL;
947 ret = RegOpenKeyExA(HKEY_LOCAL_MACHINE, "Software", 0, KEY_READ|KEY_WOW64_32KEY, &hkResult);
948 ok((ret == ERROR_SUCCESS && hkResult != NULL) || broken(ret == ERROR_ACCESS_DENIED /* NT4, win2k */),
949 "RegOpenKeyEx with KEY_WOW64_32KEY failed (err=%u)\n", ret);
950 RegCloseKey(hkResult);
951
952 hkResult = NULL;
953 ret = RegOpenKeyExA(HKEY_LOCAL_MACHINE, "Software", 0, KEY_READ|KEY_WOW64_64KEY, &hkResult);
954 ok((ret == ERROR_SUCCESS && hkResult != NULL) || broken(ret == ERROR_ACCESS_DENIED /* NT4, win2k */),
955 "RegOpenKeyEx with KEY_WOW64_64KEY failed (err=%u)\n", ret);
956 RegCloseKey(hkResult);
957
958 /* check special HKEYs on 64bit
959 * only the lower 4 bytes of the supplied key are used
960 */
961 if (ptr_size == 64)
962 {
963 /* HKEY_CURRENT_USER */
964 ret = RegOpenKeyA(UlongToHandle(HandleToUlong(HKEY_CURRENT_USER)), "Software", &hkResult);
965 ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %d\n", ret);
966 ok(hkResult != NULL, "expected hkResult != NULL\n");
967 RegCloseKey(hkResult);
968
969 ret = RegOpenKeyA((HKEY)(HandleToUlong(HKEY_CURRENT_USER) | (ULONG64)1 << 32), "Software", &hkResult);
970 ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %d\n", ret);
971 ok(hkResult != NULL, "expected hkResult != NULL\n");
972 RegCloseKey(hkResult);
973
974 ret = RegOpenKeyA((HKEY)(HandleToUlong(HKEY_CURRENT_USER) | (ULONG64)0xdeadbeef << 32), "Software", &hkResult);
975 ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %d\n", ret);
976 ok(hkResult != NULL, "expected hkResult != NULL\n");
977 RegCloseKey(hkResult);
978
979 ret = RegOpenKeyA((HKEY)(HandleToUlong(HKEY_CURRENT_USER) | (ULONG64)0xffffffff << 32), "Software", &hkResult);
980 ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %d\n", ret);
981 ok(hkResult != NULL, "expected hkResult != NULL\n");
982 RegCloseKey(hkResult);
983
984 /* HKEY_LOCAL_MACHINE */
985 ret = RegOpenKeyA((HKEY)(HandleToUlong(HKEY_LOCAL_MACHINE) | (ULONG64)0xdeadbeef << 32), "Software", &hkResult);
986 ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %d\n", ret);
987 ok(hkResult != NULL, "expected hkResult != NULL\n");
988 RegCloseKey(hkResult);
989 }
990
991 /* Try using WOW64 flags when opening a key with a DACL set to verify that
992 * the registry access check is performed correctly. Redirection isn't
993 * being tested, so the tests don't care about whether the process is
994 * running under WOW64. */
995 if (!pIsWow64Process)
996 {
997 win_skip("WOW64 flags are not recognized\n");
998 return;
999 }
1000
1001 ret = RegCreateKeyExA(HKEY_LOCAL_MACHINE, "Software\\Wine", 0, NULL, 0,
1002 KEY_WOW64_32KEY | KEY_ALL_ACCESS, NULL, &hkRoot32, NULL);
1003 ok(ret == ERROR_SUCCESS && hkRoot32 != NULL,
1004 "RegCreateKeyEx with KEY_WOW64_32KEY failed (err=%u)\n", ret);
1005
1006 ret = RegCreateKeyExA(HKEY_LOCAL_MACHINE, "Software\\Wine", 0, NULL, 0,
1007 KEY_WOW64_64KEY | KEY_ALL_ACCESS, NULL, &hkRoot64, NULL);
1008 ok(ret == ERROR_SUCCESS && hkRoot64 != NULL,
1009 "RegCreateKeyEx with KEY_WOW64_64KEY failed (err=%u)\n", ret);
1010
1011 bRet = AllocateAndInitializeSid(&sid_authority, 1, SECURITY_WORLD_RID,
1012 0, 0, 0, 0, 0, 0, 0, &world_sid);
1013 ok(bRet == TRUE,
1014 "Expected AllocateAndInitializeSid to return TRUE, got %d, last error %u\n", bRet, GetLastError());
1015
1016 access.grfAccessPermissions = GENERIC_ALL | STANDARD_RIGHTS_ALL;
1017 access.grfAccessMode = SET_ACCESS;
1018 access.grfInheritance = SUB_CONTAINERS_AND_OBJECTS_INHERIT;
1019 access.Trustee.pMultipleTrustee = NULL;
1020 access.Trustee.MultipleTrusteeOperation = NO_MULTIPLE_TRUSTEE;
1021 access.Trustee.TrusteeForm = TRUSTEE_IS_SID;
1022 access.Trustee.TrusteeType = TRUSTEE_IS_WELL_KNOWN_GROUP;
1023 access.Trustee.ptstrName = (char *)world_sid;
1024
1025 ret = SetEntriesInAclA(1, &access, NULL, &key_acl);
1026 ok(ret == ERROR_SUCCESS,
1027 "Expected SetEntriesInAclA to return ERROR_SUCCESS, got %u, last error %u\n", ret, GetLastError());
1028
1029 sd = HeapAlloc(GetProcessHeap(), 0, SECURITY_DESCRIPTOR_MIN_LENGTH);
1030 bRet = InitializeSecurityDescriptor(sd, SECURITY_DESCRIPTOR_REVISION);
1031 ok(bRet == TRUE,
1032 "Expected InitializeSecurityDescriptor to return TRUE, got %d, last error %u\n", bRet, GetLastError());
1033
1034 bRet = SetSecurityDescriptorDacl(sd, TRUE, key_acl, FALSE);
1035 ok(bRet == TRUE,
1036 "Expected SetSecurityDescriptorDacl to return TRUE, got %d, last error %u\n", bRet, GetLastError());
1037
1038 /* The "sanctioned" methods of setting a registry ACL aren't implemented in Wine. */
1039 bRet = SetKernelObjectSecurity(hkRoot64, DACL_SECURITY_INFORMATION, sd);
1040 ok(bRet == TRUE,
1041 "Expected SetKernelObjectSecurity to return TRUE, got %d, last error %u\n", bRet, GetLastError());
1042
1043 bRet = SetKernelObjectSecurity(hkRoot32, DACL_SECURITY_INFORMATION, sd);
1044 ok(bRet == TRUE,
1045 "Expected SetKernelObjectSecurity to return TRUE, got %d, last error %u\n", bRet, GetLastError());
1046
1047 hkResult = NULL;
1048 ret = RegOpenKeyExA(HKEY_LOCAL_MACHINE, "Software\\Wine", 0, KEY_WOW64_64KEY | KEY_READ, &hkResult);
1049 ok(ret == ERROR_SUCCESS && hkResult != NULL,
1050 "RegOpenKeyEx with KEY_WOW64_64KEY failed (err=%u)\n", ret);
1051 RegCloseKey(hkResult);
1052
1053 hkResult = NULL;
1054 ret = RegOpenKeyExA(HKEY_LOCAL_MACHINE, "Software\\Wine", 0, KEY_WOW64_32KEY | KEY_READ, &hkResult);
1055 ok(ret == ERROR_SUCCESS && hkResult != NULL,
1056 "RegOpenKeyEx with KEY_WOW64_32KEY failed (err=%u)\n", ret);
1057 RegCloseKey(hkResult);
1058
1059 HeapFree(GetProcessHeap(), 0, sd);
1060 LocalFree(key_acl);
1061 FreeSid(world_sid);
1062 RegDeleteKeyA(hkRoot64, "");
1063 RegCloseKey(hkRoot64);
1064 RegDeleteKeyA(hkRoot32, "");
1065 RegCloseKey(hkRoot32);
1066 }
1067
1068 static void test_reg_create_key(void)
1069 {
1070 LONG ret;
1071 HKEY hkey1, hkey2;
1072 HKEY hkRoot64 = NULL;
1073 HKEY hkRoot32 = NULL;
1074 DWORD dwRet;
1075 BOOL bRet;
1076 SID_IDENTIFIER_AUTHORITY sid_authority = {SECURITY_WORLD_SID_AUTHORITY};
1077 PSID world_sid;
1078 EXPLICIT_ACCESSA access;
1079 PACL key_acl;
1080 SECURITY_DESCRIPTOR *sd;
1081
1082 ret = RegCreateKeyExA(hkey_main, "Subkey1", 0, NULL, 0, KEY_NOTIFY, NULL, &hkey1, NULL);
1083 ok(!ret, "RegCreateKeyExA failed with error %d\n", ret);
1084 /* should succeed: all versions of Windows ignore the access rights
1085 * to the parent handle */
1086 ret = RegCreateKeyExA(hkey1, "Subkey2", 0, NULL, 0, KEY_SET_VALUE, NULL, &hkey2, NULL);
1087 ok(!ret, "RegCreateKeyExA failed with error %d\n", ret);
1088
1089 /* clean up */
1090 RegDeleteKeyA(hkey2, "");
1091 RegDeleteKeyA(hkey1, "");
1092 RegCloseKey(hkey2);
1093 RegCloseKey(hkey1);
1094
1095 /* test creation of volatile keys */
1096 ret = RegCreateKeyExA(hkey_main, "Volatile", 0, NULL, REG_OPTION_VOLATILE, KEY_ALL_ACCESS, NULL, &hkey1, NULL);
1097 ok(!ret, "RegCreateKeyExA failed with error %d\n", ret);
1098 ret = RegCreateKeyExA(hkey1, "Subkey2", 0, NULL, 0, KEY_ALL_ACCESS, NULL, &hkey2, NULL);
1099 ok(ret == ERROR_CHILD_MUST_BE_VOLATILE, "RegCreateKeyExA failed with error %d\n", ret);
1100 if (!ret) RegCloseKey( hkey2 );
1101 ret = RegCreateKeyExA(hkey1, "Subkey2", 0, NULL, REG_OPTION_VOLATILE, KEY_ALL_ACCESS, NULL, &hkey2, NULL);
1102 ok(!ret, "RegCreateKeyExA failed with error %d\n", ret);
1103 RegCloseKey(hkey2);
1104 /* should succeed if the key already exists */
1105 ret = RegCreateKeyExA(hkey1, "Subkey2", 0, NULL, 0, KEY_ALL_ACCESS, NULL, &hkey2, NULL);
1106 ok(!ret, "RegCreateKeyExA failed with error %d\n", ret);
1107
1108 /* clean up */
1109 RegDeleteKeyA(hkey2, "");
1110 RegDeleteKeyA(hkey1, "");
1111 RegCloseKey(hkey2);
1112 RegCloseKey(hkey1);
1113
1114 /* beginning backslash character */
1115 ret = RegCreateKeyExA(hkey_main, "\\Subkey3", 0, NULL, 0, KEY_NOTIFY, NULL, &hkey1, NULL);
1116 if (!(GetVersion() & 0x80000000))
1117 ok(ret == ERROR_BAD_PATHNAME, "expected ERROR_BAD_PATHNAME, got %d\n", ret);
1118 else {
1119 ok(!ret, "RegCreateKeyExA failed with error %d\n", ret);
1120 RegDeleteKeyA(hkey1, NULL);
1121 RegCloseKey(hkey1);
1122 }
1123
1124 /* WOW64 flags - open an existing key */
1125 hkey1 = NULL;
1126 ret = RegCreateKeyExA(HKEY_LOCAL_MACHINE, "Software", 0, NULL, 0, KEY_READ|KEY_WOW64_32KEY, NULL, &hkey1, NULL);
1127 ok((ret == ERROR_SUCCESS && hkey1 != NULL) || broken(ret == ERROR_ACCESS_DENIED /* NT4, win2k */),
1128 "RegOpenKeyEx with KEY_WOW64_32KEY failed (err=%u)\n", ret);
1129 RegCloseKey(hkey1);
1130
1131 hkey1 = NULL;
1132 ret = RegCreateKeyExA(HKEY_LOCAL_MACHINE, "Software", 0, NULL, 0, KEY_READ|KEY_WOW64_64KEY, NULL, &hkey1, NULL);
1133 ok((ret == ERROR_SUCCESS && hkey1 != NULL) || broken(ret == ERROR_ACCESS_DENIED /* NT4, win2k */),
1134 "RegOpenKeyEx with KEY_WOW64_64KEY failed (err=%u)\n", ret);
1135 RegCloseKey(hkey1);
1136
1137 /* Try using WOW64 flags when opening a key with a DACL set to verify that
1138 * the registry access check is performed correctly. Redirection isn't
1139 * being tested, so the tests don't care about whether the process is
1140 * running under WOW64. */
1141 if (!pIsWow64Process)
1142 {
1143 win_skip("WOW64 flags are not recognized\n");
1144 return;
1145 }
1146
1147 ret = RegCreateKeyExA(HKEY_LOCAL_MACHINE, "Software\\Wine", 0, NULL, 0,
1148 KEY_WOW64_32KEY | KEY_ALL_ACCESS, NULL, &hkRoot32, NULL);
1149 ok(ret == ERROR_SUCCESS && hkRoot32 != NULL,
1150 "RegCreateKeyEx with KEY_WOW64_32KEY failed (err=%d)\n", ret);
1151
1152 ret = RegCreateKeyExA(HKEY_LOCAL_MACHINE, "Software\\Wine", 0, NULL, 0,
1153 KEY_WOW64_64KEY | KEY_ALL_ACCESS, NULL, &hkRoot64, NULL);
1154 ok(ret == ERROR_SUCCESS && hkRoot64 != NULL,
1155 "RegCreateKeyEx with KEY_WOW64_64KEY failed (err=%d)\n", ret);
1156
1157 bRet = AllocateAndInitializeSid(&sid_authority, 1, SECURITY_WORLD_RID,
1158 0, 0, 0, 0, 0, 0, 0, &world_sid);
1159 ok(bRet == TRUE,
1160 "Expected AllocateAndInitializeSid to return TRUE, got %d, last error %u\n", bRet, GetLastError());
1161
1162 access.grfAccessPermissions = GENERIC_ALL | STANDARD_RIGHTS_ALL;
1163 access.grfAccessMode = SET_ACCESS;
1164 access.grfInheritance = SUB_CONTAINERS_AND_OBJECTS_INHERIT;
1165 access.Trustee.pMultipleTrustee = NULL;
1166 access.Trustee.MultipleTrusteeOperation = NO_MULTIPLE_TRUSTEE;
1167 access.Trustee.TrusteeForm = TRUSTEE_IS_SID;
1168 access.Trustee.TrusteeType = TRUSTEE_IS_WELL_KNOWN_GROUP;
1169 access.Trustee.ptstrName = (char *)world_sid;
1170
1171 dwRet = SetEntriesInAclA(1, &access, NULL, &key_acl);
1172 ok(ret == ERROR_SUCCESS,
1173 "Expected SetEntriesInAclA to return ERROR_SUCCESS, got %u, last error %u\n", dwRet, GetLastError());
1174
1175 sd = HeapAlloc(GetProcessHeap(), 0, SECURITY_DESCRIPTOR_MIN_LENGTH);
1176 bRet = InitializeSecurityDescriptor(sd, SECURITY_DESCRIPTOR_REVISION);
1177 ok(bRet == TRUE,
1178 "Expected InitializeSecurityDescriptor to return TRUE, got %d, last error %u\n", bRet, GetLastError());
1179
1180 bRet = SetSecurityDescriptorDacl(sd, TRUE, key_acl, FALSE);
1181 ok(bRet == TRUE,
1182 "Expected SetSecurityDescriptorDacl to return TRUE, got %d, last error %u\n", bRet, GetLastError());
1183
1184 /* The "sanctioned" methods of setting a registry ACL aren't implemented in Wine. */
1185 bRet = SetKernelObjectSecurity(hkRoot64, DACL_SECURITY_INFORMATION, sd);
1186 ok(bRet == TRUE,
1187 "Expected SetKernelObjectSecurity to return TRUE, got %d, last error %u\n", bRet, GetLastError());
1188
1189 bRet = SetKernelObjectSecurity(hkRoot32, DACL_SECURITY_INFORMATION, sd);
1190 ok(bRet == TRUE,
1191 "Expected SetKernelObjectSecurity to return TRUE, got %d, last error %u\n", bRet, GetLastError());
1192
1193 hkey1 = NULL;
1194 ret = RegCreateKeyExA(HKEY_LOCAL_MACHINE, "Software\\Wine", 0, NULL, 0,
1195 KEY_WOW64_64KEY | KEY_READ, NULL, &hkey1, NULL);
1196 ok(ret == ERROR_SUCCESS && hkey1 != NULL,
1197 "RegOpenKeyEx with KEY_WOW64_64KEY failed (err=%u)\n", ret);
1198 RegCloseKey(hkey1);
1199
1200 hkey1 = NULL;
1201 ret = RegCreateKeyExA(HKEY_LOCAL_MACHINE, "Software\\Wine", 0, NULL, 0,
1202 KEY_WOW64_32KEY | KEY_READ, NULL, &hkey1, NULL);
1203 ok(ret == ERROR_SUCCESS && hkey1 != NULL,
1204 "RegOpenKeyEx with KEY_WOW64_32KEY failed (err=%u)\n", ret);
1205 RegCloseKey(hkey1);
1206
1207 HeapFree(GetProcessHeap(), 0, sd);
1208 LocalFree(key_acl);
1209 FreeSid(world_sid);
1210 RegDeleteKeyA(hkRoot64, "");
1211 RegCloseKey(hkRoot64);
1212 RegDeleteKeyA(hkRoot32, "");
1213 RegCloseKey(hkRoot32);
1214 }
1215
1216 static void test_reg_close_key(void)
1217 {
1218 DWORD ret = 0;
1219 HKEY hkHandle;
1220
1221 /* successfully close key
1222 * hkHandle remains changed after call to RegCloseKey
1223 */
1224 ret = RegOpenKeyA(HKEY_CURRENT_USER, "Software\\Wine\\Test", &hkHandle);
1225 ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %d\n", ret);
1226 ret = RegCloseKey(hkHandle);
1227 ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %d\n", ret);
1228
1229 /* try to close the key twice */
1230 ret = RegCloseKey(hkHandle); /* Windows 95 doesn't mind. */
1231 ok(ret == ERROR_INVALID_HANDLE || ret == ERROR_SUCCESS,
1232 "expected ERROR_INVALID_HANDLE or ERROR_SUCCESS, got %d\n", ret);
1233
1234 /* try to close a NULL handle */
1235 ret = RegCloseKey(NULL);
1236 ok(ret == ERROR_INVALID_HANDLE || ret == ERROR_BADKEY, /* Windows 95 returns BADKEY */
1237 "expected ERROR_INVALID_HANDLE or ERROR_BADKEY, got %d\n", ret);
1238
1239 /* Check to see if we didn't potentially close our main handle, which could happen on win98 as
1240 * win98 doesn't give a new handle when the same key is opened.
1241 * Not re-opening will make some next tests fail.
1242 */
1243 if (hkey_main == hkHandle)
1244 {
1245 trace("The main handle is most likely closed, so re-opening\n");
1246 RegOpenKeyA( HKEY_CURRENT_USER, "Software\\Wine\\Test", &hkey_main );
1247 }
1248 }
1249
1250 static void test_reg_delete_key(void)
1251 {
1252 DWORD ret;
1253
1254 ret = RegDeleteKeyA(hkey_main, NULL);
1255
1256 /* There is a bug in NT4 and W2K that doesn't check if the subkey is NULL. If
1257 * there are also no subkeys available it will delete the key pointed to by hkey_main.
1258 * Not re-creating will make some next tests fail.
1259 */
1260 if (ret == ERROR_SUCCESS)
1261 {
1262 trace("We are probably running on NT4 or W2K as the main key is deleted,"
1263 " re-creating the main key\n");
1264 setup_main_key();
1265 }
1266 else
1267 ok(ret == ERROR_INVALID_PARAMETER ||
1268 ret == ERROR_ACCESS_DENIED ||
1269 ret == ERROR_BADKEY, /* Win95 */
1270 "ret=%d\n", ret);
1271 }
1272
1273 static void test_reg_save_key(void)
1274 {
1275 DWORD ret;
1276
1277 ret = RegSaveKeyA(hkey_main, "saved_key", NULL);
1278 ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %d\n", ret);
1279 }
1280
1281 static void test_reg_load_key(void)
1282 {
1283 DWORD ret;
1284 HKEY hkHandle;
1285
1286 ret = RegLoadKeyA(HKEY_LOCAL_MACHINE, "Test", "saved_key");
1287 ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %d\n", ret);
1288
1289 ret = RegOpenKeyA(HKEY_LOCAL_MACHINE, "Test", &hkHandle);
1290 ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %d\n", ret);
1291
1292 RegCloseKey(hkHandle);
1293 }
1294
1295 static void test_reg_unload_key(void)
1296 {
1297 DWORD ret;
1298
1299 ret = RegUnLoadKeyA(HKEY_LOCAL_MACHINE, "Test");
1300 ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %d\n", ret);
1301
1302 DeleteFileA("saved_key");
1303 DeleteFileA("saved_key.LOG");
1304 }
1305
1306 static BOOL set_privileges(LPCSTR privilege, BOOL set)
1307 {
1308 TOKEN_PRIVILEGES tp;
1309 HANDLE hToken;
1310 LUID luid;
1311
1312 if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES, &hToken))
1313 return FALSE;
1314
1315 if(!LookupPrivilegeValueA(NULL, privilege, &luid))
1316 {
1317 CloseHandle(hToken);
1318 return FALSE;
1319 }
1320
1321 tp.PrivilegeCount = 1;
1322 tp.Privileges[0].Luid = luid;
1323
1324 if (set)
1325 tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
1326 else
1327 tp.Privileges[0].Attributes = 0;
1328
1329 AdjustTokenPrivileges(hToken, FALSE, &tp, sizeof(TOKEN_PRIVILEGES), NULL, NULL);
1330 if (GetLastError() != ERROR_SUCCESS)
1331 {
1332 CloseHandle(hToken);
1333 return FALSE;
1334 }
1335
1336 CloseHandle(hToken);
1337 return TRUE;
1338 }
1339
1340 /* tests that show that RegConnectRegistry and
1341 OpenSCManager accept computer names without the
1342 \\ prefix (what MSDN says). */
1343 static void test_regconnectregistry( void)
1344 {
1345 CHAR compName[MAX_COMPUTERNAME_LENGTH + 1];
1346 CHAR netwName[MAX_COMPUTERNAME_LENGTH + 3]; /* 2 chars for double backslash */
1347 DWORD len = sizeof(compName) ;
1348 BOOL ret;
1349 LONG retl;
1350 HKEY hkey;
1351 SC_HANDLE schnd;
1352
1353 SetLastError(0xdeadbeef);
1354 ret = GetComputerNameA(compName, &len);
1355 ok( ret, "GetComputerName failed err = %d\n", GetLastError());
1356 if( !ret) return;
1357
1358 lstrcpyA(netwName, "\\\\");
1359 lstrcpynA(netwName+2, compName, MAX_COMPUTERNAME_LENGTH + 1);
1360
1361 retl = RegConnectRegistryA( compName, HKEY_LOCAL_MACHINE, &hkey);
1362 ok( !retl ||
1363 retl == ERROR_DLL_INIT_FAILED ||
1364 retl == ERROR_BAD_NETPATH, /* some win2k */
1365 "RegConnectRegistryA failed err = %d\n", retl);
1366 if( !retl) RegCloseKey( hkey);
1367
1368 retl = RegConnectRegistryA( netwName, HKEY_LOCAL_MACHINE, &hkey);
1369 ok( !retl ||
1370 retl == ERROR_DLL_INIT_FAILED ||
1371 retl == ERROR_BAD_NETPATH, /* some win2k */
1372 "RegConnectRegistryA failed err = %d\n", retl);
1373 if( !retl) RegCloseKey( hkey);
1374
1375 SetLastError(0xdeadbeef);
1376 schnd = OpenSCManagerA( compName, NULL, GENERIC_READ);
1377 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
1378 {
1379 win_skip("OpenSCManagerA is not implemented\n");
1380 return;
1381 }
1382
1383 ok( schnd != NULL, "OpenSCManagerA failed err = %d\n", GetLastError());
1384 CloseServiceHandle( schnd);
1385
1386 SetLastError(0xdeadbeef);
1387 schnd = OpenSCManagerA( netwName, NULL, GENERIC_READ);
1388 ok( schnd != NULL, "OpenSCManagerA failed err = %d\n", GetLastError());
1389 CloseServiceHandle( schnd);
1390
1391 }
1392
1393 static void test_reg_query_value(void)
1394 {
1395 HKEY subkey;
1396 CHAR val[MAX_PATH];
1397 WCHAR valW[5];
1398 LONG size, ret;
1399
1400 static const WCHAR expected[] = {'d','a','t','a',0};
1401
1402 ret = RegCreateKeyA(hkey_main, "subkey", &subkey);
1403 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
1404
1405 ret = RegSetValueA(subkey, NULL, REG_SZ, "data", 4);
1406 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
1407
1408 /* try an invalid hkey */
1409 SetLastError(0xdeadbeef);
1410 size = MAX_PATH;
1411 ret = RegQueryValueA((HKEY)0xcafebabe, "subkey", val, &size);
1412 ok(ret == ERROR_INVALID_HANDLE ||
1413 ret == ERROR_BADKEY || /* Windows 98 returns BADKEY */
1414 ret == ERROR_ACCESS_DENIED, /* non-admin winxp */
1415 "Expected ERROR_INVALID_HANDLE or ERROR_BADKEY, got %d\n", ret);
1416 ok(GetLastError() == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", GetLastError());
1417
1418 /* try a NULL hkey */
1419 SetLastError(0xdeadbeef);
1420 size = MAX_PATH;
1421 ret = RegQueryValueA(NULL, "subkey", val, &size);
1422 ok(ret == ERROR_INVALID_HANDLE || ret == ERROR_BADKEY, /* Windows 98 returns BADKEY */
1423 "Expected ERROR_INVALID_HANDLE or ERROR_BADKEY, got %d\n", ret);
1424 ok(GetLastError() == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", GetLastError());
1425
1426 /* try a NULL value */
1427 size = MAX_PATH;
1428 ret = RegQueryValueA(hkey_main, "subkey", NULL, &size);
1429 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
1430 ok(size == 5, "Expected 5, got %d\n", size);
1431
1432 /* try a NULL size */
1433 SetLastError(0xdeadbeef);
1434 val[0] = '\0';
1435 ret = RegQueryValueA(hkey_main, "subkey", val, NULL);
1436 ok(ret == ERROR_INVALID_PARAMETER, "Expected ERROR_INVALID_PARAMETER, got %d\n", ret);
1437 ok(GetLastError() == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", GetLastError());
1438 ok(lstrlenA(val) == 0, "Expected val to be untouched, got %s\n", val);
1439
1440 /* try a NULL value and size */
1441 ret = RegQueryValueA(hkey_main, "subkey", NULL, NULL);
1442 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
1443
1444 /* try a size too small */
1445 SetLastError(0xdeadbeef);
1446 val[0] = '\0';
1447 size = 1;
1448 ret = RegQueryValueA(hkey_main, "subkey", val, &size);
1449 ok(ret == ERROR_MORE_DATA, "Expected ERROR_MORE_DATA, got %d\n", ret);
1450 ok(GetLastError() == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", GetLastError());
1451 ok(lstrlenA(val) == 0, "Expected val to be untouched, got %s\n", val);
1452 ok(size == 5, "Expected 5, got %d\n", size);
1453
1454 /* successfully read the value using 'subkey' */
1455 size = MAX_PATH;
1456 ret = RegQueryValueA(hkey_main, "subkey", val, &size);
1457 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
1458 ok(!lstrcmpA(val, "data"), "Expected 'data', got '%s'\n", val);
1459 ok(size == 5, "Expected 5, got %d\n", size);
1460
1461 /* successfully read the value using the subkey key */
1462 size = MAX_PATH;
1463 ret = RegQueryValueA(subkey, NULL, val, &size);
1464 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
1465 ok(!lstrcmpA(val, "data"), "Expected 'data', got '%s'\n", val);
1466 ok(size == 5, "Expected 5, got %d\n", size);
1467
1468 /* unicode - try size too small */
1469 SetLastError(0xdeadbeef);
1470 valW[0] = '\0';
1471 size = 0;
1472 ret = RegQueryValueW(subkey, NULL, valW, &size);
1473 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
1474 {
1475 win_skip("RegQueryValueW is not implemented\n");
1476 goto cleanup;
1477 }
1478 ok(ret == ERROR_MORE_DATA, "Expected ERROR_MORE_DATA, got %d\n", ret);
1479 ok(GetLastError() == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", GetLastError());
1480 ok(lstrlenW(valW) == 0, "Expected valW to be untouched\n");
1481 ok(size == sizeof(expected), "Got wrong size: %d\n", size);
1482
1483 /* unicode - try size in WCHARS */
1484 SetLastError(0xdeadbeef);
1485 size = sizeof(valW) / sizeof(WCHAR);
1486 ret = RegQueryValueW(subkey, NULL, valW, &size);
1487 ok(ret == ERROR_MORE_DATA, "Expected ERROR_MORE_DATA, got %d\n", ret);
1488 ok(GetLastError() == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", GetLastError());
1489 ok(lstrlenW(valW) == 0, "Expected valW to be untouched\n");
1490 ok(size == sizeof(expected), "Got wrong size: %d\n", size);
1491
1492 /* unicode - successfully read the value */
1493 size = sizeof(valW);
1494 ret = RegQueryValueW(subkey, NULL, valW, &size);
1495 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
1496 ok(!lstrcmpW(valW, expected), "Got wrong value\n");
1497 ok(size == sizeof(expected), "Got wrong size: %d\n", size);
1498
1499 /* unicode - set the value without a NULL terminator */
1500 ret = RegSetValueW(subkey, NULL, REG_SZ, expected, sizeof(expected)-sizeof(WCHAR));
1501 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
1502
1503 /* unicode - read the unterminated value, value is terminated for us */
1504 memset(valW, 'a', sizeof(valW));
1505 size = sizeof(valW);
1506 ret = RegQueryValueW(subkey, NULL, valW, &size);
1507 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
1508 ok(!lstrcmpW(valW, expected), "Got wrong value\n");
1509 ok(size == sizeof(expected), "Got wrong size: %d\n", size);
1510
1511 cleanup:
1512 RegDeleteKeyA(subkey, "");
1513 RegCloseKey(subkey);
1514 }
1515
1516 static void test_string_termination(void)
1517 {
1518 HKEY subkey;
1519 LSTATUS ret;
1520 static const char string[] = "FullString";
1521 char name[11];
1522 BYTE buffer[11];
1523 DWORD insize, outsize, nsize;
1524
1525 ret = RegCreateKeyA(hkey_main, "string_termination", &subkey);
1526 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
1527
1528 /* Off-by-one RegSetValueExA -> adds a trailing '\0'! */
1529 insize=sizeof(string)-1;
1530 ret = RegSetValueExA(subkey, "stringtest", 0, REG_SZ, (BYTE*)string, insize);
1531 ok(ret == ERROR_SUCCESS, "RegSetValueExA failed: %d\n", ret);
1532 outsize=insize;
1533 ret = RegQueryValueExA(subkey, "stringtest", NULL, NULL, buffer, &outsize);
1534 ok(ret == ERROR_MORE_DATA, "RegQueryValueExA returned: %d\n", ret);
1535
1536 /* Off-by-two RegSetValueExA -> no trailing '\0' */
1537 insize=sizeof(string)-2;
1538 ret = RegSetValueExA(subkey, "stringtest", 0, REG_SZ, (BYTE*)string, insize);
1539 ok(ret == ERROR_SUCCESS, "RegSetValueExA failed: %d\n", ret);
1540 outsize=0;
1541 ret = RegQueryValueExA(subkey, "stringtest", NULL, NULL, NULL, &outsize);
1542 ok(ret == ERROR_SUCCESS, "RegQueryValueExA failed: %d\n", ret);
1543 ok(outsize == insize, "wrong size %u != %u\n", outsize, insize);
1544
1545 /* RegQueryValueExA may return a string with no trailing '\0' */
1546 outsize=insize;
1547 memset(buffer, 0xbd, sizeof(buffer));
1548 ret = RegQueryValueExA(subkey, "stringtest", NULL, NULL, buffer, &outsize);
1549 ok(ret == ERROR_SUCCESS, "RegQueryValueExA failed: %d\n", ret);
1550 ok(outsize == insize, "wrong size: %u != %u\n", outsize, insize);
1551 ok(memcmp(buffer, string, outsize) == 0, "bad string: %s/%u != %s\n",
1552 wine_debugstr_an((char*)buffer, outsize), outsize, string);
1553 ok(buffer[insize] == 0xbd, "buffer overflow at %u %02x\n", insize, buffer[insize]);
1554
1555 /* RegQueryValueExA adds a trailing '\0' if there is room */
1556 outsize=insize+1;
1557 memset(buffer, 0xbd, sizeof(buffer));
1558 ret = RegQueryValueExA(subkey, "stringtest", NULL, NULL, buffer, &outsize);
1559 ok(ret == ERROR_SUCCESS, "RegQueryValueExA failed: %d\n", ret);
1560 ok(outsize == insize, "wrong size: %u != %u\n", outsize, insize);
1561 ok(memcmp(buffer, string, outsize) == 0, "bad string: %s/%u != %s\n",
1562 wine_debugstr_an((char*)buffer, outsize), outsize, string);
1563 ok(buffer[insize] == 0, "buffer overflow at %u %02x\n", insize, buffer[insize]);
1564
1565 /* RegEnumValueA may return a string with no trailing '\0' */
1566 outsize=insize;
1567 memset(buffer, 0xbd, sizeof(buffer));
1568 nsize=sizeof(name);
1569 ret = RegEnumValueA(subkey, 0, name, &nsize, NULL, NULL, buffer, &outsize);
1570 ok(ret == ERROR_SUCCESS, "RegEnumValueA failed: %d\n", ret);
1571 ok(strcmp(name, "stringtest") == 0, "wrong name: %s\n", name);
1572 ok(outsize == insize, "wrong size: %u != %u\n", outsize, insize);
1573 ok(memcmp(buffer, string, outsize) == 0, "bad string: %s/%u != %s\n",
1574 wine_debugstr_an((char*)buffer, outsize), outsize, string);
1575 ok(buffer[insize] == 0xbd, "buffer overflow at %u %02x\n", insize, buffer[insize]);
1576
1577 /* RegEnumValueA adds a trailing '\0' if there is room */
1578 outsize=insize+1;
1579 memset(buffer, 0xbd, sizeof(buffer));
1580 nsize=sizeof(name);
1581 ret = RegEnumValueA(subkey, 0, name, &nsize, NULL, NULL, buffer, &outsize);
1582 ok(ret == ERROR_SUCCESS, "RegEnumValueA failed: %d\n", ret);
1583 ok(strcmp(name, "stringtest") == 0, "wrong name: %s\n", name);
1584 ok(outsize == insize, "wrong size: %u != %u\n", outsize, insize);
1585 ok(memcmp(buffer, string, outsize) == 0, "bad string: %s/%u != %s\n",
1586 wine_debugstr_an((char*)buffer, outsize), outsize, string);
1587 ok(buffer[insize] == 0, "buffer overflow at %u %02x\n", insize, buffer[insize]);
1588
1589 RegDeleteKeyA(subkey, "");
1590 RegCloseKey(subkey);
1591 }
1592
1593 static void test_reg_delete_tree(void)
1594 {
1595 CHAR buffer[MAX_PATH];
1596 HKEY subkey, subkey2;
1597 LONG size, ret;
1598
1599 if(!pRegDeleteTreeA) {
1600 win_skip("Skipping RegDeleteTreeA tests, function not present\n");
1601 return;
1602 }
1603
1604 ret = RegCreateKeyA(hkey_main, "subkey", &subkey);
1605 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
1606 ret = RegCreateKeyA(subkey, "subkey2", &subkey2);
1607 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
1608 ret = RegSetValueA(subkey, NULL, REG_SZ, "data", 4);
1609 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
1610 ret = RegSetValueA(subkey2, NULL, REG_SZ, "data2", 5);
1611 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
1612 ret = RegCloseKey(subkey2);
1613 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
1614
1615 ret = pRegDeleteTreeA(subkey, "subkey2");
1616 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
1617 ok(RegOpenKeyA(subkey, "subkey2", &subkey2),
1618 "subkey2 was not deleted\n");
1619 size = MAX_PATH;
1620 ok(!RegQueryValueA(subkey, NULL, buffer, &size),
1621 "Default value of subkey not longer present\n");
1622
1623 ret = RegCreateKeyA(subkey, "subkey2", &subkey2);
1624 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
1625 ret = RegCloseKey(subkey2);
1626 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
1627 ret = pRegDeleteTreeA(hkey_main, "subkey\\subkey2");
1628 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
1629 ok(RegOpenKeyA(subkey, "subkey2", &subkey2),
1630 "subkey2 was not deleted\n");
1631 ok(!RegQueryValueA(subkey, NULL, buffer, &size),
1632 "Default value of subkey not longer present\n");
1633
1634 ret = RegCreateKeyA(subkey, "subkey2", &subkey2);
1635 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
1636 ret = RegCloseKey(subkey2);
1637 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
1638 ret = RegCreateKeyA(subkey, "subkey3", &subkey2);
1639 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
1640 ret = RegCloseKey(subkey2);
1641 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
1642 ret = RegSetValueA(subkey, "value", REG_SZ, "data2", 5);
1643 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
1644 ret = pRegDeleteTreeA(subkey, NULL);
1645 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
1646 ok(!RegOpenKeyA(hkey_main, "subkey", &subkey),
1647 "subkey was deleted\n");
1648 ok(RegOpenKeyA(subkey, "subkey2", &subkey2),
1649 "subkey2 was not deleted\n");
1650 ok(RegOpenKeyA(subkey, "subkey3", &subkey2),
1651 "subkey3 was not deleted\n");
1652 size = MAX_PATH;
1653 ret = RegQueryValueA(subkey, NULL, buffer, &size);
1654 ok(ret == ERROR_SUCCESS,
1655 "Default value of subkey is not present\n");
1656 ok(!lstrlenA(buffer),
1657 "Expected length 0 got length %u(%s)\n", lstrlenA(buffer), buffer);
1658 size = MAX_PATH;
1659 ok(RegQueryValueA(subkey, "value", buffer, &size),
1660 "Value is still present\n");
1661
1662 ret = pRegDeleteTreeA(hkey_main, "not-here");
1663 ok(ret == ERROR_FILE_NOT_FOUND,
1664 "Expected ERROR_FILE_NOT_FOUND, got %d\n", ret);
1665 }
1666
1667 static void test_rw_order(void)
1668 {
1669 HKEY hKey;
1670 DWORD dw = 0;
1671 static const char keyname[] = "test_rw_order";
1672 char value_buf[2];
1673 DWORD values, value_len, value_name_max_len;
1674 LSTATUS ret;
1675
1676 RegDeleteKeyA(HKEY_CURRENT_USER, keyname);
1677 ret = RegCreateKeyA(HKEY_CURRENT_USER, keyname, &hKey);
1678 if(ret != ERROR_SUCCESS) {
1679 skip("Couldn't create key. Skipping.\n");
1680 return;
1681 }
1682
1683 ok(!RegSetValueExA(hKey, "A", 0, REG_DWORD, (LPBYTE)&dw, sizeof(dw)),
1684 "RegSetValueExA for value \"A\" failed\n");
1685 ok(!RegSetValueExA(hKey, "C", 0, REG_DWORD, (LPBYTE)&dw, sizeof(dw)),
1686 "RegSetValueExA for value \"C\" failed\n");
1687 ok(!RegSetValueExA(hKey, "D", 0, REG_DWORD, (LPBYTE)&dw, sizeof(dw)),
1688 "RegSetValueExA for value \"D\" failed\n");
1689 ok(!RegSetValueExA(hKey, "B", 0, REG_DWORD, (LPBYTE)&dw, sizeof(dw)),
1690 "RegSetValueExA for value \"B\" failed\n");
1691
1692 ok(!RegQueryInfoKeyA(hKey, NULL, NULL, NULL, NULL, NULL, NULL, &values,
1693 &value_name_max_len, NULL, NULL, NULL), "RegQueryInfoKeyA failed\n");
1694 ok(values == 4, "Expected 4 values, got %u\n", values);
1695
1696 /* Value enumeration preserves RegSetValueEx call order */
1697 value_len = 2;
1698 ok(!RegEnumValueA(hKey, 0, value_buf, &value_len, NULL, NULL, NULL, NULL), "RegEnumValueA failed\n");
1699 ok(strcmp(value_buf, "A") == 0, "Expected name \"A\", got %s\n", value_buf);
1700 value_len = 2;
1701 ok(!RegEnumValueA(hKey, 1, value_buf, &value_len, NULL, NULL, NULL, NULL), "RegEnumValueA failed\n");
1702 todo_wine ok(strcmp(value_buf, "C") == 0, "Expected name \"C\", got %s\n", value_buf);
1703 value_len = 2;
1704 ok(!RegEnumValueA(hKey, 2, value_buf, &value_len, NULL, NULL, NULL, NULL), "RegEnumValueA failed\n");
1705 todo_wine ok(strcmp(value_buf, "D") == 0, "Expected name \"D\", got %s\n", value_buf);
1706 value_len = 2;
1707 ok(!RegEnumValueA(hKey, 3, value_buf, &value_len, NULL, NULL, NULL, NULL), "RegEnumValueA failed\n");
1708 todo_wine ok(strcmp(value_buf, "B") == 0, "Expected name \"B\", got %s\n", value_buf);
1709
1710 ok(!RegDeleteKeyA(HKEY_CURRENT_USER, keyname), "Failed to delete key\n");
1711 }
1712
1713 static void test_symlinks(void)
1714 {
1715 static const WCHAR targetW[] = {'\\','S','o','f','t','w','a','r','e','\\','W','i','n','e',
1716 '\\','T','e','s','t','\\','t','a','r','g','e','t',0};
1717 BYTE buffer[1024];
1718 UNICODE_STRING target_str;
1719 WCHAR *target;
1720 HKEY key, link;
1721 NTSTATUS status;
1722 DWORD target_len, type, len, dw, err;
1723
1724 if (!pRtlFormatCurrentUserKeyPath || !pNtDeleteKey)
1725 {
1726 win_skip( "Can't perform symlink tests\n" );
1727 return;
1728 }
1729
1730 pRtlFormatCurrentUserKeyPath( &target_str );
1731
1732 target_len = target_str.Length + sizeof(targetW);
1733 target = HeapAlloc( GetProcessHeap(), 0, target_len );
1734 memcpy( target, target_str.Buffer, target_str.Length );
1735 memcpy( target + target_str.Length/sizeof(WCHAR), targetW, sizeof(targetW) );
1736
1737 err = RegCreateKeyExA( hkey_main, "link", 0, NULL, REG_OPTION_CREATE_LINK,
1738 KEY_ALL_ACCESS, NULL, &link, NULL );
1739 ok( err == ERROR_SUCCESS, "RegCreateKeyEx failed: %u\n", err );
1740
1741 /* REG_SZ is not allowed */
1742 err = RegSetValueExA( link, "SymbolicLinkValue", 0, REG_SZ, (BYTE *)"foobar", sizeof("foobar") );
1743 ok( err == ERROR_ACCESS_DENIED, "RegSetValueEx wrong error %u\n", err );
1744 err = RegSetValueExA( link, "SymbolicLinkValue", 0, REG_LINK,
1745 (BYTE *)target, target_len - sizeof(WCHAR) );
1746 ok( err == ERROR_SUCCESS, "RegSetValueEx failed error %u\n", err );
1747 /* other values are not allowed */
1748 err = RegSetValueExA( link, "link", 0, REG_LINK, (BYTE *)target, target_len - sizeof(WCHAR) );
1749 ok( err == ERROR_ACCESS_DENIED, "RegSetValueEx wrong error %u\n", err );
1750
1751 /* try opening the target through the link */
1752
1753 err = RegOpenKeyA( hkey_main, "link", &key );
1754 ok( err == ERROR_FILE_NOT_FOUND, "RegOpenKey wrong error %u\n", err );
1755
1756 err = RegCreateKeyExA( hkey_main, "target", 0, NULL, 0, KEY_ALL_ACCESS, NULL, &key, NULL );
1757 ok( err == ERROR_SUCCESS, "RegCreateKeyEx failed error %u\n", err );
1758
1759 dw = 0xbeef;
1760 err = RegSetValueExA( key, "value", 0, REG_DWORD, (BYTE *)&dw, sizeof(dw) );
1761 ok( err == ERROR_SUCCESS, "RegSetValueEx failed error %u\n", err );
1762 RegCloseKey( key );
1763
1764 err = RegOpenKeyA( hkey_main, "link", &key );
1765 ok( err == ERROR_SUCCESS, "RegOpenKey failed error %u\n", err );
1766
1767 len = sizeof(buffer);
1768 err = RegQueryValueExA( key, "value", NULL, &type, buffer, &len );
1769 ok( err == ERROR_SUCCESS, "RegOpenKey failed error %u\n", err );
1770 ok( len == sizeof(DWORD), "wrong len %u\n", len );
1771
1772 len = sizeof(buffer);
1773 err = RegQueryValueExA( key, "SymbolicLinkValue", NULL, &type, buffer, &len );
1774 ok( err == ERROR_FILE_NOT_FOUND, "RegQueryValueEx wrong error %u\n", err );
1775
1776 /* REG_LINK can be created in non-link keys */
1777 err = RegSetValueExA( key, "SymbolicLinkValue", 0, REG_LINK,
1778 (BYTE *)target, target_len - sizeof(WCHAR) );
1779 ok( err == ERROR_SUCCESS, "RegSetValueEx failed error %u\n", err );
1780 len = sizeof(buffer);
1781 err = RegQueryValueExA( key, "SymbolicLinkValue", NULL, &type, buffer, &len );
1782 ok( err == ERROR_SUCCESS, "RegQueryValueEx failed error %u\n", err );
1783 ok( len == target_len - sizeof(WCHAR), "wrong len %u\n", len );
1784 err = RegDeleteValueA( key, "SymbolicLinkValue" );
1785 ok( err == ERROR_SUCCESS, "RegDeleteValue failed error %u\n", err );
1786
1787 RegCloseKey( key );
1788
1789 err = RegCreateKeyExA( hkey_main, "link", 0, NULL, 0, KEY_ALL_ACCESS, NULL, &key, NULL );
1790 ok( err == ERROR_SUCCESS, "RegCreateKeyEx failed error %u\n", err );
1791
1792 len = sizeof(buffer);
1793 err = RegQueryValueExA( key, "value", NULL, &type, buffer, &len );
1794 ok( err == ERROR_SUCCESS, "RegQueryValueEx failed error %u\n", err );
1795 ok( len == sizeof(DWORD), "wrong len %u\n", len );
1796
1797 err = RegQueryValueExA( key, "SymbolicLinkValue", NULL, &type, buffer, &len );
1798 ok( err == ERROR_FILE_NOT_FOUND, "RegQueryValueEx wrong error %u\n", err );
1799 RegCloseKey( key );
1800
1801 /* now open the symlink itself */
1802
1803 err = RegOpenKeyExA( hkey_main, "link", REG_OPTION_OPEN_LINK, KEY_ALL_ACCESS, &key );
1804 ok( err == ERROR_SUCCESS, "RegOpenKeyEx failed error %u\n", err );
1805 len = sizeof(buffer);
1806 err = RegQueryValueExA( key, "SymbolicLinkValue", NULL, &type, buffer, &len );
1807 ok( err == ERROR_SUCCESS, "RegQueryValueEx failed error %u\n", err );
1808 ok( len == target_len - sizeof(WCHAR), "wrong len %u\n", len );
1809 RegCloseKey( key );
1810
1811 err = RegCreateKeyExA( hkey_main, "link", 0, NULL, REG_OPTION_OPEN_LINK,
1812 KEY_ALL_ACCESS, NULL, &key, NULL );
1813 ok( err == ERROR_SUCCESS, "RegCreateKeyEx failed error %u\n", err );
1814 len = sizeof(buffer);
1815 err = RegQueryValueExA( key, "SymbolicLinkValue", NULL, &type, buffer, &len );
1816 ok( err == ERROR_SUCCESS, "RegQueryValueEx failed error %u\n", err );
1817 ok( len == target_len - sizeof(WCHAR), "wrong len %u\n", len );
1818 RegCloseKey( key );
1819
1820 err = RegCreateKeyExA( hkey_main, "link", 0, NULL, REG_OPTION_CREATE_LINK,
1821 KEY_ALL_ACCESS, NULL, &key, NULL );
1822 ok( err == ERROR_ALREADY_EXISTS, "RegCreateKeyEx wrong error %u\n", err );
1823
1824 err = RegCreateKeyExA( hkey_main, "link", 0, NULL, REG_OPTION_CREATE_LINK | REG_OPTION_OPEN_LINK,
1825 KEY_ALL_ACCESS, NULL, &key, NULL );
1826 ok( err == ERROR_ALREADY_EXISTS, "RegCreateKeyEx wrong error %u\n", err );
1827
1828 err = RegDeleteKeyA( hkey_main, "target" );
1829 ok( err == ERROR_SUCCESS, "RegDeleteKey failed error %u\n", err );
1830
1831 err = RegDeleteKeyA( hkey_main, "link" );
1832 ok( err == ERROR_FILE_NOT_FOUND, "RegDeleteKey wrong error %u\n", err );
1833
1834 status = pNtDeleteKey( link );
1835 ok( !status, "NtDeleteKey failed: 0x%08x\n", status );
1836 RegCloseKey( link );
1837
1838 HeapFree( GetProcessHeap(), 0, target );
1839 pRtlFreeUnicodeString( &target_str );
1840 }
1841
1842 static DWORD get_key_value( HKEY root, const char *name, DWORD flags )
1843 {
1844 HKEY key;
1845 DWORD err, type, dw, len = sizeof(dw);
1846
1847 err = RegCreateKeyExA( root, name, 0, NULL, 0, flags | KEY_ALL_ACCESS, NULL, &key, NULL );
1848 if (err == ERROR_FILE_NOT_FOUND) return 0;
1849 ok( err == ERROR_SUCCESS, "%08x: RegCreateKeyEx failed: %u\n", flags, err );
1850
1851 err = RegQueryValueExA( key, "value", NULL, &type, (BYTE *)&dw, &len );
1852 if (err == ERROR_FILE_NOT_FOUND)
1853 dw = 0;
1854 else
1855 ok( err == ERROR_SUCCESS, "%08x: RegQueryValueEx failed: %u\n", flags, err );
1856 RegCloseKey( key );
1857 return dw;
1858 }
1859
1860 static void _check_key_value( int line, HANDLE root, const char *name, DWORD flags, DWORD expect )
1861 {
1862 DWORD dw = get_key_value( root, name, flags );
1863 ok_(__FILE__,line)( dw == expect, "%08x: wrong value %u/%u\n", flags, dw, expect );
1864 }
1865 #define check_key_value(root,name,flags,expect) _check_key_value( __LINE__, root, name, flags, expect )
1866
1867 static void test_redirection(void)
1868 {
1869 DWORD err, type, dw, len;
1870 HKEY key, root32, root64, key32, key64, native, op_key;
1871 BOOL is_vista = FALSE;
1872 REGSAM opposite = (sizeof(void*) == 8 ? KEY_WOW64_32KEY : KEY_WOW64_64KEY);
1873
1874 if (ptr_size != 64)
1875 {
1876 BOOL is_wow64;
1877 if (!pIsWow64Process || !pIsWow64Process( GetCurrentProcess(), &is_wow64 ) || !is_wow64)
1878 {
1879 skip( "Not on Wow64, no redirection\n" );
1880 return;
1881 }
1882 }
1883
1884 err = RegCreateKeyExA( HKEY_LOCAL_MACHINE, "Software\\Wine", 0, NULL, 0,
1885 KEY_WOW64_64KEY | KEY_ALL_ACCESS, NULL, &root64, NULL );
1886 ok( err == ERROR_SUCCESS, "RegCreateKeyExA failed: %u\n", err );
1887
1888 err = RegCreateKeyExA( HKEY_LOCAL_MACHINE, "Software\\Wine", 0, NULL, 0,
1889 KEY_WOW64_32KEY | KEY_ALL_ACCESS, NULL, &root32, NULL );
1890 ok( err == ERROR_SUCCESS, "RegCreateKeyExA failed: %u\n", err );
1891
1892 err = RegCreateKeyExA( HKEY_LOCAL_MACHINE, "Software\\Wine\\Winetest", 0, NULL, 0,
1893 KEY_WOW64_64KEY | KEY_ALL_ACCESS, NULL, &key64, NULL );
1894 ok( err == ERROR_SUCCESS, "RegCreateKeyExA failed: %u\n", err );
1895
1896 err = RegCreateKeyExA( HKEY_LOCAL_MACHINE, "Software\\Wine\\Winetest", 0, NULL, 0,
1897 KEY_WOW64_32KEY | KEY_ALL_ACCESS, NULL, &key32, NULL );
1898 ok( err == ERROR_SUCCESS, "RegCreateKeyExA failed: %u\n", err );
1899
1900 dw = 64;
1901 err = RegSetValueExA( key64, "value", 0, REG_DWORD, (BYTE *)&dw, sizeof(dw) );
1902 ok( err == ERROR_SUCCESS, "RegSetValueExA failed: %u\n", err );
1903
1904 dw = 32;
1905 err = RegSetValueExA( key32, "value", 0, REG_DWORD, (BYTE *)&dw, sizeof(dw) );
1906 ok( err == ERROR_SUCCESS, "RegSetValueExA failed: %u\n", err );
1907
1908 dw = 0;
1909 len = sizeof(dw);
1910 err = RegQueryValueExA( key32, "value", NULL, &type, (BYTE *)&dw, &len );
1911 ok( err == ERROR_SUCCESS, "RegQueryValueExA failed: %u\n", err );
1912 ok( dw == 32, "wrong value %u\n", dw );
1913
1914 dw = 0;
1915 len = sizeof(dw);
1916 err = RegQueryValueExA( key64, "value", NULL, &type, (BYTE *)&dw, &len );
1917 ok( err == ERROR_SUCCESS, "RegQueryValueExA failed: %u\n", err );
1918 ok( dw == 64, "wrong value %u\n", dw );
1919
1920 err = RegCreateKeyExA( HKEY_LOCAL_MACHINE, "Software", 0, NULL, 0,
1921 KEY_ALL_ACCESS, NULL, &key, NULL );
1922 ok( err == ERROR_SUCCESS, "RegCreateKeyExA failed: %u\n", err );
1923
1924 if (ptr_size == 32)
1925 {
1926 /* the Vista mechanism allows opening Wow6432Node from a 32-bit key too */
1927 /* the new (and simpler) Win7 mechanism doesn't */
1928 if (get_key_value( key, "Wow6432Node\\Wine\\Winetest", 0 ) == 32)
1929 {
1930 trace( "using Vista-style Wow6432Node handling\n" );
1931 is_vista = TRUE;
1932 }
1933 check_key_value( key, "Wine\\Winetest", 0, 32 );
1934 check_key_value( key, "Wine\\Winetest", KEY_WOW64_64KEY, is_vista ? 64 : 32 );
1935 check_key_value( key, "Wine\\Winetest", KEY_WOW64_32KEY, 32 );
1936 check_key_value( key, "Wow6432Node\\Wine\\Winetest", 0, is_vista ? 32 : 0 );
1937 check_key_value( key, "Wow6432Node\\Wine\\Winetest", KEY_WOW64_64KEY, is_vista ? 64 : 0 );
1938 check_key_value( key, "Wow6432Node\\Wine\\Winetest", KEY_WOW64_32KEY, is_vista ? 32 : 0 );
1939 }
1940 else
1941 {
1942 if (get_key_value( HKEY_LOCAL_MACHINE, "Software\\Wow6432Node\\Wine\\Winetest", KEY_WOW64_64KEY ) == 64)
1943 {
1944 trace( "using Vista-style Wow6432Node handling\n" );
1945 is_vista = TRUE;
1946 }
1947 check_key_value( key, "Wine\\Winetest", 0, 64 );
1948 check_key_value( key, "Wow6432Node\\Wine\\Winetest", 0, 32 );
1949 }
1950 RegCloseKey( key );
1951
1952 if (ptr_size == 32)
1953 {
1954 err = RegCreateKeyExA( HKEY_LOCAL_MACHINE, "Software", 0, NULL, 0,
1955 KEY_WOW64_64KEY | KEY_ALL_ACCESS, NULL, &key, NULL );
1956 ok( err == ERROR_SUCCESS, "RegCreateKeyExA failed: %u\n", err );
1957 dw = get_key_value( key, "Wine\\Winetest", 0 );
1958 ok( dw == 64 || broken(dw == 32) /* xp64 */, "wrong value %u\n", dw );
1959 check_key_value( key, "Wine\\Winetest", KEY_WOW64_64KEY, 64 );
1960 check_key_value( key, "Wine\\Winetest", KEY_WOW64_32KEY, 32 );
1961 check_key_value( key, "Wow6432Node\\Wine\\Winetest", 0, 32 );
1962 dw = get_key_value( key, "Wow6432Node\\Wine\\Winetest", KEY_WOW64_64KEY );
1963 ok( dw == 32 || broken(dw == 64) /* xp64 */, "wrong value %u\n", dw );
1964 check_key_value( key, "Wow6432Node\\Wine\\Winetest", KEY_WOW64_32KEY, 32 );
1965 RegCloseKey( key );
1966
1967 err = RegCreateKeyExA( HKEY_LOCAL_MACHINE, "Software", 0, NULL, 0,
1968 KEY_WOW64_32KEY | KEY_ALL_ACCESS, NULL, &key, NULL );
1969 ok( err == ERROR_SUCCESS, "RegCreateKeyExA failed: %u\n", err );
1970 check_key_value( key, "Wine\\Winetest", 0, 32 );
1971 check_key_value( key, "Wine\\Winetest", KEY_WOW64_64KEY, is_vista ? 64 : 32 );
1972 check_key_value( key, "Wine\\Winetest", KEY_WOW64_32KEY, 32 );
1973 check_key_value( key, "Wow6432Node\\Wine\\Winetest", 0, is_vista ? 32 : 0 );
1974 check_key_value( key, "Wow6432Node\\Wine\\Winetest", KEY_WOW64_64KEY, is_vista ? 64 : 0 );
1975 check_key_value( key, "Wow6432Node\\Wine\\Winetest", KEY_WOW64_32KEY, is_vista ? 32 : 0 );
1976 RegCloseKey( key );
1977 }
1978
1979 check_key_value( HKEY_LOCAL_MACHINE, "Software\\Wine\\Winetest", 0, ptr_size );
1980 check_key_value( HKEY_LOCAL_MACHINE, "Software\\Wow6432Node\\Wine\\Winetest", 0, 32 );
1981 if (ptr_size == 64)
1982 {
1983 /* KEY_WOW64 flags have no effect on 64-bit */
1984 check_key_value( HKEY_LOCAL_MACHINE, "Software\\Wine\\Winetest", KEY_WOW64_64KEY, 64 );
1985 check_key_value( HKEY_LOCAL_MACHINE, "Software\\Wine\\Winetest", KEY_WOW64_32KEY, 32 );
1986 check_key_value( HKEY_LOCAL_MACHINE, "Software\\Wow6432Node\\Wine\\Winetest", KEY_WOW64_64KEY, is_vista ? 64 : 32 );
1987 check_key_value( HKEY_LOCAL_MACHINE, "Software\\Wow6432Node\\Wine\\Winetest", KEY_WOW64_32KEY, 32 );
1988 }
1989 else
1990 {
1991 check_key_value( HKEY_LOCAL_MACHINE, "Software\\Wine\\Winetest", KEY_WOW64_64KEY, 64 );
1992 check_key_value( HKEY_LOCAL_MACHINE, "Software\\Wine\\Winetest", KEY_WOW64_32KEY, 32 );
1993 check_key_value( HKEY_LOCAL_MACHINE, "Software\\Wow6432Node\\Wine\\Winetest", KEY_WOW64_64KEY, is_vista ? 64 : 32 );
1994 check_key_value( HKEY_LOCAL_MACHINE, "Software\\Wow6432Node\\Wine\\Winetest", KEY_WOW64_32KEY, 32 );
1995 }
1996
1997 err = RegCreateKeyExA( HKEY_LOCAL_MACHINE, "Software\\Wow6432Node", 0, NULL, 0,
1998 KEY_ALL_ACCESS, NULL, &key, NULL );
1999 ok( err == ERROR_SUCCESS, "RegCreateKeyExA failed: %u\n", err );
2000 check_key_value( key, "Wine\\Winetest", 0, 32 );
2001 check_key_value( key, "Wine\\Winetest", KEY_WOW64_64KEY, is_vista ? 64 : 32 );
2002 check_key_value( key, "Wine\\Winetest", KEY_WOW64_32KEY, 32 );
2003 RegCloseKey( key );
2004
2005 if (ptr_size == 32)
2006 {
2007 err = RegCreateKeyExA( HKEY_LOCAL_MACHINE, "Software\\Wow6432Node", 0, NULL, 0,
2008 KEY_WOW64_64KEY | KEY_ALL_ACCESS, NULL, &key, NULL );
2009 ok( err == ERROR_SUCCESS, "RegCreateKeyExA failed: %u\n", err );
2010 dw = get_key_value( key, "Wine\\Winetest", 0 );
2011 ok( dw == (is_vista ? 64 : 32) || broken(dw == 32) /* xp64 */, "wrong value %u\n", dw );
2012 check_key_value( key, "Wine\\Winetest", KEY_WOW64_64KEY, is_vista ? 64 : 32 );
2013 check_key_value( key, "Wine\\Winetest", KEY_WOW64_32KEY, 32 );
2014 RegCloseKey( key );
2015
2016 err = RegCreateKeyExA( HKEY_LOCAL_MACHINE, "Software\\Wow6432Node", 0, NULL, 0,
2017 KEY_WOW64_32KEY | KEY_ALL_ACCESS, NULL, &key, NULL );
2018 ok( err == ERROR_SUCCESS, "RegCreateKeyExA failed: %u\n", err );
2019 check_key_value( key, "Wine\\Winetest", 0, 32 );
2020 check_key_value( key, "Wine\\Winetest", KEY_WOW64_64KEY, is_vista ? 64 : 32 );
2021 check_key_value( key, "Wine\\Winetest", KEY_WOW64_32KEY, 32 );
2022 RegCloseKey( key );
2023 }
2024
2025 err = RegCreateKeyExA( HKEY_LOCAL_MACHINE, "Software\\Wow6432Node\\Wine", 0, NULL, 0,
2026 KEY_ALL_ACCESS, NULL, &key, NULL );
2027 ok( err == ERROR_SUCCESS, "RegCreateKeyExA failed: %u\n", err );
2028 check_key_value( key, "Winetest", 0, 32 );
2029 check_key_value( key, "Winetest", KEY_WOW64_64KEY, is_vista ? 64 : 32 );
2030 check_key_value( key, "Winetest", KEY_WOW64_32KEY, 32 );
2031 RegCloseKey( key );
2032
2033 if (ptr_size == 32)
2034 {
2035 err = RegCreateKeyExA( HKEY_LOCAL_MACHINE, "Software\\Wow6432Node\\Wine", 0, NULL, 0,
2036 KEY_WOW64_64KEY | KEY_ALL_ACCESS, NULL, &key, NULL );
2037 ok( err == ERROR_SUCCESS, "RegCreateKeyExA failed: %u\n", err );
2038 dw = get_key_value( key, "Winetest", 0 );
2039 ok( dw == 32 || (is_vista && dw == 64), "wrong value %u\n", dw );
2040 check_key_value( key, "Winetest", KEY_WOW64_64KEY, is_vista ? 64 : 32 );
2041 check_key_value( key, "Winetest", KEY_WOW64_32KEY, 32 );
2042 RegCloseKey( key );
2043
2044 err = RegCreateKeyExA( HKEY_LOCAL_MACHINE, "Software\\Wow6432Node\\Wine", 0, NULL, 0,
2045 KEY_WOW64_32KEY | KEY_ALL_ACCESS, NULL, &key, NULL );
2046 ok( err == ERROR_SUCCESS, "RegCreateKeyExA failed: %u\n", err );
2047 check_key_value( key, "Winetest", 0, 32 );
2048 check_key_value( key, "Winetest", KEY_WOW64_64KEY, is_vista ? 64 : 32 );
2049 check_key_value( key, "Winetest", KEY_WOW64_32KEY, 32 );
2050 RegCloseKey( key );
2051 }
2052
2053 err = RegCreateKeyExA( HKEY_LOCAL_MACHINE, "Software\\Wine", 0, NULL, 0,
2054 KEY_ALL_ACCESS, NULL, &key, NULL );
2055 ok( err == ERROR_SUCCESS, "RegCreateKeyExA failed: %u\n", err );
2056 check_key_value( key, "Winetest", 0, ptr_size );
2057 check_key_value( key, "Winetest", KEY_WOW64_64KEY, is_vista ? 64 : ptr_size );
2058 dw = get_key_value( key, "Winetest", KEY_WOW64_32KEY );
2059 if (ptr_size == 32) ok( dw == 32, "wrong value %u\n", dw );
2060 else todo_wine ok( dw == 32, "wrong value %u\n", dw );
2061 RegCloseKey( key );
2062
2063 if (ptr_size == 32)
2064 {
2065 err = RegCreateKeyExA( HKEY_LOCAL_MACHINE, "Software\\Wine", 0, NULL, 0,
2066 KEY_WOW64_64KEY | KEY_ALL_ACCESS, NULL, &key, NULL );
2067 ok( err == ERROR_SUCCESS, "RegCreateKeyExA failed: %u\n", err );
2068 dw = get_key_value( key, "Winetest", 0 );
2069 ok( dw == 64 || broken(dw == 32) /* xp64 */, "wrong value %u\n", dw );
2070 check_key_value( key, "Winetest", KEY_WOW64_64KEY, 64 );
2071 dw = get_key_value( key, "Winetest", KEY_WOW64_32KEY );
2072 todo_wine ok( dw == 32, "wrong value %u\n", dw );
2073 RegCloseKey( key );
2074
2075 err = RegCreateKeyExA( HKEY_LOCAL_MACHINE, "Software\\Wine", 0, NULL, 0,
2076 KEY_WOW64_32KEY | KEY_ALL_ACCESS, NULL, &key, NULL );
2077 ok( err == ERROR_SUCCESS, "RegCreateKeyExA failed: %u\n", err );
2078 check_key_value( key, "Winetest", 0, 32 );
2079 check_key_value( key, "Winetest", KEY_WOW64_64KEY, is_vista ? 64 : 32 );
2080 check_key_value( key, "Winetest", KEY_WOW64_32KEY, 32 );
2081 RegCloseKey( key );
2082 }
2083
2084 if (pRegDeleteKeyExA)
2085 {
2086 err = pRegDeleteKeyExA( key32, "", KEY_WOW64_32KEY, 0 );
2087 ok( err == ERROR_SUCCESS, "RegDeleteKey failed: %u\n", err );
2088 err = pRegDeleteKeyExA( key64, "", KEY_WOW64_64KEY, 0 );
2089 ok( err == ERROR_SUCCESS, "RegDeleteKey failed: %u\n", err );
2090 pRegDeleteKeyExA( key64, "", KEY_WOW64_64KEY, 0 );
2091 pRegDeleteKeyExA( root64, "", KEY_WOW64_64KEY, 0 );
2092 }
2093 else
2094 {
2095 err = RegDeleteKeyA( key32, "" );
2096 ok( err == ERROR_SUCCESS, "RegDeleteKey failed: %u\n", err );
2097 err = RegDeleteKeyA( key64, "" );
2098 ok( err == ERROR_SUCCESS, "RegDeleteKey failed: %u\n", err );
2099 RegDeleteKeyA( key64, "" );
2100 RegDeleteKeyA( root64, "" );
2101 }
2102 RegCloseKey( key32 );
2103 RegCloseKey( key64 );
2104 RegCloseKey( root32 );
2105 RegCloseKey( root64 );
2106
2107 /* open key in native bit mode */
2108 err = RegOpenKeyExA(HKEY_CLASSES_ROOT, "Interface", 0, KEY_ALL_ACCESS, &native);
2109 ok(err == ERROR_SUCCESS, "got %i\n", err);
2110
2111 pRegDeleteKeyExA(native, "AWineTest", 0, 0);
2112
2113 /* write subkey in opposite bit mode */
2114 err = RegOpenKeyExA(HKEY_CLASSES_ROOT, "Interface", 0, KEY_ALL_ACCESS | opposite, &op_key);
2115 ok(err == ERROR_SUCCESS, "got %i\n", err);
2116
2117 err = RegCreateKeyExA(op_key, "AWineTest", 0, NULL, 0, KEY_ALL_ACCESS | opposite,
2118 NULL, &key, NULL);
2119 ok(err == ERROR_SUCCESS || err == ERROR_ACCESS_DENIED, "got %i\n", err);
2120 if(err != ERROR_SUCCESS){
2121 win_skip("Can't write to registry\n");
2122 RegCloseKey(op_key);
2123 RegCloseKey(native);
2124 return;
2125 }
2126 RegCloseKey(key);
2127
2128 /* verify subkey is not present in native mode */
2129 err = RegOpenKeyExA(native, "AWineTest", 0, KEY_ALL_ACCESS, &key);
2130 ok(err == ERROR_FILE_NOT_FOUND ||
2131 broken(err == ERROR_SUCCESS), /* before Win7, HKCR is reflected instead of redirected */
2132 "got %i\n", err);
2133
2134 err = pRegDeleteKeyExA(op_key, "AWineTest", opposite, 0);
2135 ok(err == ERROR_SUCCESS, "got %i\n", err);
2136
2137 RegCloseKey(op_key);
2138 RegCloseKey(native);
2139 }
2140
2141 static void test_classesroot(void)
2142 {
2143 HKEY hkey, hklm, hkcr, hkeysub1, hklmsub1, hkcrsub1, hklmsub2, hkcrsub2;
2144 DWORD size = 8;
2145 DWORD type = REG_SZ;
2146 static CHAR buffer[8];
2147 LONG res;
2148
2149 /* create a key in the user's classes */
2150 if (!RegOpenKeyA( HKEY_CURRENT_USER, "Software\\Classes\\WineTestCls", &hkey ))
2151 {
2152 delete_key( hkey );
2153 RegCloseKey( hkey );
2154 }
2155 res = RegCreateKeyExA( HKEY_CURRENT_USER, "Software\\Classes\\WineTestCls", 0, NULL, 0,
2156 KEY_QUERY_VALUE|KEY_SET_VALUE, NULL, &hkey, NULL );
2157 if (res == ERROR_ACCESS_DENIED)
2158 {
2159 skip("not enough privileges to add a user class\n");
2160 return;
2161 }
2162 ok(!IS_HKCR(hkey), "hkcr mask set in %p\n", hkey);
2163
2164 /* try to open that key in hkcr */
2165 res = RegOpenKeyExA( HKEY_CLASSES_ROOT, "WineTestCls", 0,
2166 KEY_QUERY_VALUE|KEY_SET_VALUE, &hkcr );
2167 todo_wine ok(res == ERROR_SUCCESS ||
2168 broken(res == ERROR_FILE_NOT_FOUND /* WinNT */),
2169 "test key not found in hkcr: %d\n", res);
2170 if (res)
2171 {
2172 skip("HKCR key merging not supported\n");
2173 delete_key( hkey );
2174 RegCloseKey( hkey );
2175 return;
2176 }
2177
2178 todo_wine ok(IS_HKCR(hkcr), "hkcr mask not set in %p\n", hkcr);
2179
2180 /* set a value in user's classes */
2181 res = RegSetValueExA(hkey, "val1", 0, REG_SZ, (const BYTE *)"user", sizeof("user"));
2182 ok(res == ERROR_SUCCESS, "RegSetValueExA failed: %d, GLE=%x\n", res, GetLastError());
2183
2184 /* try to find the value in hkcr */
2185 res = RegQueryValueExA(hkcr, "val1", NULL, &type, (LPBYTE)buffer, &size);
2186 ok(res == ERROR_SUCCESS, "RegQueryValueExA failed: %d\n", res);
2187 ok(!strcmp( buffer, "user" ), "value set to '%s'\n", buffer );
2188
2189 /* modify the value in hkcr */
2190 res = RegSetValueExA(hkcr, "val1", 0, REG_SZ, (const BYTE *)"hkcr", sizeof("hkcr"));
2191 ok(res == ERROR_SUCCESS, "RegSetValueExA failed: %d, GLE=%x\n", res, GetLastError());
2192
2193 /* check if the value is also modified in user's classes */
2194 res = RegQueryValueExA(hkey, "val1", NULL, &type, (LPBYTE)buffer, &size);
2195 ok(res == ERROR_SUCCESS, "RegQueryValueExA failed: %d, GLE=%x\n", res, GetLastError());
2196 ok(!strcmp( buffer, "hkcr" ), "value set to '%s'\n", buffer );
2197
2198 /* set a value in hkcr */
2199 res = RegSetValueExA(hkcr, "val0", 0, REG_SZ, (const BYTE *)"hkcr", sizeof("hkcr"));
2200 ok(res == ERROR_SUCCESS, "RegSetValueExA failed: %d, GLE=%x\n", res, GetLastError());
2201
2202 /* try to find the value in user's classes */
2203 res = RegQueryValueExA(hkey, "val0", NULL, &type, (LPBYTE)buffer, &size);
2204 ok(res == ERROR_SUCCESS, "RegQueryValueExA failed: %d\n", res);
2205 ok(!strcmp( buffer, "hkcr" ), "value set to '%s'\n", buffer );
2206
2207 /* modify the value in user's classes */
2208 res = RegSetValueExA(hkey, "val0", 0, REG_SZ, (const BYTE *)"user", sizeof("user"));
2209 ok(res == ERROR_SUCCESS, "RegSetValueExA failed: %d, GLE=%x\n", res, GetLastError());
2210
2211 /* check if the value is also modified in hkcr */
2212 res = RegQueryValueExA(hkcr, "val0", NULL, &type, (LPBYTE)buffer, &size);
2213 ok(res == ERROR_SUCCESS, "RegQueryValueExA failed: %d, GLE=%x\n", res, GetLastError());
2214 ok(!strcmp( buffer, "user" ), "value set to '%s'\n", buffer );
2215
2216 /* cleanup */
2217 delete_key( hkey );
2218 delete_key( hkcr );
2219 RegCloseKey( hkey );
2220 RegCloseKey( hkcr );
2221
2222 /* create a key in the hklm classes */
2223 if (!RegOpenKeyA( HKEY_LOCAL_MACHINE, "Software\\Classes\\WineTestCls", &hklm ))
2224 {
2225 delete_key( hklm );
2226 RegCloseKey( hklm );
2227 }
2228 res = RegCreateKeyExA( HKEY_LOCAL_MACHINE, "Software\\Classes\\WineTestCls", 0, NULL, REG_OPTION_NON_VOLATILE,
2229 KEY_ALL_ACCESS, NULL, &hklm, NULL );
2230 if (res == ERROR_ACCESS_DENIED)
2231 {
2232 skip("not enough privileges to add a system class\n");
2233 return;
2234 }
2235 ok(!IS_HKCR(hklm), "hkcr mask set in %p\n", hklm);
2236
2237 /* try to open that key in hkcr */
2238 res = RegOpenKeyExA( HKEY_CLASSES_ROOT, "WineTestCls", 0,
2239 KEY_QUERY_VALUE|KEY_SET_VALUE, &hkcr );
2240 ok(res == ERROR_SUCCESS,
2241 "test key not found in hkcr: %d\n", res);
2242 ok(IS_HKCR(hkcr), "hkcr mask not set in %p\n", hkcr);
2243 if (res)
2244 {
2245 delete_key( hklm );
2246 RegCloseKey( hklm );
2247 return;
2248 }
2249
2250 /* set a value in hklm classes */
2251 res = RegSetValueExA(hklm, "val2", 0, REG_SZ, (const BYTE *)"hklm", sizeof("hklm"));
2252 ok(res == ERROR_SUCCESS, "RegSetValueExA failed: %d, GLE=%x\n", res, GetLastError());
2253
2254 /* try to find the value in hkcr */
2255 res = RegQueryValueExA(hkcr, "val2", NULL, &type, (LPBYTE)buffer, &size);
2256 ok(res == ERROR_SUCCESS, "RegQueryValueExA failed: %d\n", res);
2257 ok(!strcmp( buffer, "hklm" ), "value set to '%s'\n", buffer );
2258
2259 /* modify the value in hkcr */
2260 res = RegSetValueExA(hkcr, "val2", 0, REG_SZ, (const BYTE *)"hkcr", sizeof("hkcr"));
2261 ok(res == ERROR_SUCCESS, "RegSetValueExA failed: %d, GLE=%x\n", res, GetLastError());
2262
2263 /* check that the value is modified in hklm classes */
2264 res = RegQueryValueExA(hklm, "val2", NULL, &type, (LPBYTE)buffer, &size);
2265 ok(res == ERROR_SUCCESS, "RegQueryValueExA failed: %d, GLE=%x\n", res, GetLastError());
2266 ok(!strcmp( buffer, "hkcr" ), "value set to '%s'\n", buffer );
2267
2268 if (RegCreateKeyExA( HKEY_CURRENT_USER, "Software\\Classes\\WineTestCls", 0, NULL, 0,
2269 KEY_QUERY_VALUE|KEY_SET_VALUE, NULL, &hkey, NULL )) return;
2270 ok(!IS_HKCR(hkey), "hkcr mask set in %p\n", hkey);
2271
2272 /* try to open that key in hkcr */
2273 res = RegOpenKeyExA( HKEY_CLASSES_ROOT, "WineTestCls", 0,
2274 KEY_QUERY_VALUE|KEY_SET_VALUE, &hkcr );
2275 ok(res == ERROR_SUCCESS,
2276 "test key not found in hkcr: %d\n", res);
2277 ok(IS_HKCR(hkcr), "hkcr mask not set in %p\n", hkcr);
2278
2279 /* set a value in user's classes */
2280 res = RegSetValueExA(hkey, "val2", 0, REG_SZ, (const BYTE *)"user", sizeof("user"));
2281 ok(res == ERROR_SUCCESS, "RegSetValueExA failed: %d, GLE=%x\n", res, GetLastError());
2282
2283 /* try to find the value in hkcr */
2284 res = RegQueryValueExA(hkcr, "val2", NULL, &type, (LPBYTE)buffer, &size);
2285 ok(res == ERROR_SUCCESS, "RegQueryValueExA failed: %d\n", res);
2286 ok(!strcmp( buffer, "user" ), "value set to '%s'\n", buffer );
2287
2288 /* modify the value in hklm */
2289 res = RegSetValueExA(hklm, "val2", 0, REG_SZ, (const BYTE *)"hklm", sizeof("hklm"));
2290 ok(res == ERROR_SUCCESS, "RegSetValueExA failed: %d, GLE=%x\n", res, GetLastError());
2291
2292 /* check that the value is not overwritten in hkcr or user's classes */
2293 res = RegQueryValueExA(hkcr, "val2", NULL, &type, (LPBYTE)buffer, &size);
2294 ok(res == ERROR_SUCCESS, "RegQueryValueExA failed: %d\n", res);
2295 ok(!strcmp( buffer, "user" ), "value set to '%s'\n", buffer );
2296 res = RegQueryValueExA(hkey, "val2", NULL, &type, (LPBYTE)buffer, &size);
2297 ok(res == ERROR_SUCCESS, "RegQueryValueExA failed: %d, GLE=%x\n", res, GetLastError());
2298 ok(!strcmp( buffer, "user" ), "value set to '%s'\n", buffer );
2299
2300 /* modify the value in hkcr */
2301 res = RegSetValueExA(hkcr, "val2", 0, REG_SZ, (const BYTE *)"hkcr", sizeof("hkcr"));
2302 ok(res == ERROR_SUCCESS, "RegSetValueExA failed: %d, GLE=%x\n", res, GetLastError());
2303
2304 /* check that the value is overwritten in hklm and user's classes */
2305 res = RegQueryValueExA(hkcr, "val2", NULL, &type, (LPBYTE)buffer, &size);
2306 ok(res == ERROR_SUCCESS, "RegQueryValueExA failed: %d\n", res);
2307 ok(!strcmp( buffer, "hkcr" ), "value set to '%s'\n", buffer );
2308 res = RegQueryValueExA(hkey, "val2", NULL, &type, (LPBYTE)buffer, &size);
2309 ok(res == ERROR_SUCCESS, "RegQueryValueExA failed: %d, GLE=%x\n", res, GetLastError());
2310 ok(!strcmp( buffer, "hkcr" ), "value set to '%s'\n", buffer );
2311
2312 /* create a subkey in hklm */
2313 if (RegCreateKeyExA( hklm, "subkey1", 0, NULL, 0,
2314 KEY_QUERY_VALUE|KEY_SET_VALUE, NULL, &hklmsub1, NULL )) return;
2315 ok(!IS_HKCR(hklmsub1), "hkcr mask set in %p\n", hklmsub1);
2316 /* try to open that subkey in hkcr */
2317 res = RegOpenKeyExA( hkcr, "subkey1", 0, KEY_QUERY_VALUE|KEY_SET_VALUE, &hkcrsub1 );
2318 ok(res == ERROR_SUCCESS, "test key not found in hkcr: %d\n", res);
2319 ok(IS_HKCR(hkcrsub1), "hkcr mask not set in %p\n", hkcrsub1);
2320
2321 /* set a value in hklm classes */
2322 res = RegSetValueExA(hklmsub1, "subval1", 0, REG_SZ, (const BYTE *)"hklm", sizeof("hklm"));
2323 ok(res == ERROR_SUCCESS, "RegSetValueExA failed: %d, GLE=%x\n", res, GetLastError());
2324
2325 /* try to find the value in hkcr */
2326 res = RegQueryValueExA(hkcrsub1, "subval1", NULL, &type, (LPBYTE)buffer, &size);
2327 ok(res == ERROR_SUCCESS, "RegQueryValueExA failed: %d\n", res);
2328 ok(!strcmp( buffer, "hklm" ), "value set to '%s'\n", buffer );
2329
2330 /* modify the value in hkcr */
2331 res = RegSetValueExA(hkcrsub1, "subval1", 0, REG_SZ, (const BYTE *)"hkcr", sizeof("hkcr"));
2332 ok(res == ERROR_SUCCESS, "RegSetValueExA failed: %d, GLE=%x\n", res, GetLastError());
2333
2334 /* check that the value is modified in hklm classes */
2335 res = RegQueryValueExA(hklmsub1, "subval1", NULL, &type, (LPBYTE)buffer, &size);
2336 ok(res == ERROR_SUCCESS, "RegQueryValueExA failed: %d, GLE=%x\n", res, GetLastError());
2337 ok(!strcmp( buffer, "hkcr" ), "value set to '%s'\n", buffer );
2338
2339 /* create a subkey in user's classes */
2340 if (RegCreateKeyExA( hkey, "subkey1", 0, NULL, 0,
2341 KEY_QUERY_VALUE|KEY_SET_VALUE, NULL, &hkeysub1, NULL )) return;
2342 ok(!IS_HKCR(hkeysub1), "hkcr mask set in %p\n", hkeysub1);
2343
2344 /* set a value in user's classes */
2345 res = RegSetValueExA(hkeysub1, "subval1", 0, REG_SZ, (const BYTE *)"user", sizeof("user"));
2346 ok(res == ERROR_SUCCESS, "RegSetValueExA failed: %d, GLE=%x\n", res, GetLastError());
2347
2348 /* try to find the value in hkcr */
2349 res = RegQueryValueExA(hkcrsub1, "subval1", NULL, &type, (LPBYTE)buffer, &size);
2350 ok(res == ERROR_SUCCESS, "RegQueryValueExA failed: %d\n", res);
2351 ok(!strcmp( buffer, "user" ), "value set to '%s'\n", buffer );
2352
2353 /* modify the value in hklm */
2354 res = RegSetValueExA(hklmsub1, "subval1", 0, REG_SZ, (const BYTE *)"hklm", sizeof("hklm"));
2355 ok(res == ERROR_SUCCESS, "RegSetValueExA failed: %d, GLE=%x\n", res, GetLastError());
2356
2357 /* check that the value is not overwritten in hkcr or user's classes */
2358 res = RegQueryValueExA(hkcrsub1, "subval1", NULL, &type, (LPBYTE)buffer, &size);
2359 ok(res == ERROR_SUCCESS, "RegQueryValueExA failed: %d\n", res);
2360 ok(!strcmp( buffer, "user" ), "value set to '%s'\n", buffer );
2361 res = RegQueryValueExA(hkeysub1, "subval1", NULL, &type, (LPBYTE)buffer, &size);
2362 ok(res == ERROR_SUCCESS, "RegQueryValueExA failed: %d, GLE=%x\n", res, GetLastError());
2363 ok(!strcmp( buffer, "user" ), "value set to '%s'\n", buffer );
2364
2365 /* modify the value in hkcr */
2366 res = RegSetValueExA(hkcrsub1, "subval1", 0, REG_SZ, (const BYTE *)"hkcr", sizeof("hkcr"));
2367 ok(res == ERROR_SUCCESS, "RegSetValueExA failed: %d, GLE=%x\n", res, GetLastError());
2368
2369 /* check that the value is not overwritten in hklm, but in user's classes */
2370 res = RegQueryValueExA(hklmsub1, "subval1", NULL, &type, (LPBYTE)buffer, &size);
2371 ok(res == ERROR_SUCCESS, "RegQueryValueExA failed: %d\n", res);
2372 ok(!strcmp( buffer, "hklm" ), "value set to '%s'\n", buffer );
2373 res = RegQueryValueExA(hkeysub1, "subval1", NULL, &type, (LPBYTE)buffer, &size);
2374 ok(res == ERROR_SUCCESS, "RegQueryValueExA failed: %d, GLE=%x\n", res, GetLastError());
2375 ok(!strcmp( buffer, "hkcr" ), "value set to '%s'\n", buffer );
2376
2377 /* new subkey in hkcr */
2378 if (RegCreateKeyExA( hkcr, "subkey2", 0, NULL, 0,
2379 KEY_QUERY_VALUE|KEY_SET_VALUE, NULL, &hkcrsub2, NULL )) return;
2380 ok(IS_HKCR(hkcrsub2), "hkcr mask not set in %p\n", hkcrsub2);
2381 res = RegSetValueExA(hkcrsub2, "subval1", 0, REG_SZ, (const BYTE *)"hkcr", sizeof("hkcr"));
2382 ok(res == ERROR_SUCCESS, "RegSetValueExA failed: %d, GLE=%x\n", res, GetLastError());
2383
2384 /* try to open that new subkey in user's classes and hklm */
2385 res = RegOpenKeyExA( hkey, "subkey2", 0, KEY_QUERY_VALUE|KEY_SET_VALUE, &hklmsub2 );
2386 ok(res != ERROR_SUCCESS, "test key found in user's classes: %d\n", res);
2387 hklmsub2 = 0;
2388 res = RegOpenKeyExA( hklm, "subkey2", 0, KEY_QUERY_VALUE|KEY_SET_VALUE, &hklmsub2 );
2389 ok(res == ERROR_SUCCESS, "test key not found in hklm: %d\n", res);
2390 ok(!IS_HKCR(hklmsub2), "hkcr mask set in %p\n", hklmsub2);
2391
2392 /* check that the value is present in hklm */
2393 res = RegQueryValueExA(hklmsub2, "subval1", NULL, &type, (LPBYTE)buffer, &size);
2394 ok(res == ERROR_SUCCESS, "RegQueryValueExA failed: %d\n", res);
2395 ok(!strcmp( buffer, "hkcr" ), "value set to '%s'\n", buffer );
2396
2397 /* cleanup */
2398 RegCloseKey( hkeysub1 );
2399 RegCloseKey( hklmsub1 );
2400
2401 /* delete subkey1 from hkcr (should point at user's classes) */
2402 res = RegDeleteKeyA(hkcr, "subkey1");
2403 ok(res == ERROR_SUCCESS, "RegDeleteKey failed: %d\n", res);
2404
2405 /* confirm key was removed in hkey but not hklm */
2406 res = RegOpenKeyExA(hkey, "subkey1", 0, KEY_READ, &hkeysub1);
2407 ok(res == ERROR_FILE_NOT_FOUND, "test key found in user's classes: %d\n", res);
2408 res = RegOpenKeyExA(hklm, "subkey1", 0, KEY_READ, &hklmsub1);
2409 ok(res == ERROR_SUCCESS, "test key not found in hklm: %d\n", res);
2410 ok(!IS_HKCR(hklmsub1), "hkcr mask set in %p\n", hklmsub1);
2411
2412 /* delete subkey1 from hkcr again (which should now point at hklm) */
2413 res = RegDeleteKeyA(hkcr, "subkey1");
2414 ok(res == ERROR_SUCCESS, "RegDeleteKey failed: %d\n", res);
2415
2416 /* confirm hkey was removed in hklm */
2417 RegCloseKey( hklmsub1 );
2418 res = RegOpenKeyExA(hklm, "subkey1", 0, KEY_READ, &hklmsub1);
2419 ok(res == ERROR_FILE_NOT_FOUND, "test key found in hklm: %d\n", res);
2420
2421 /* final cleanup */
2422 delete_key( hkey );
2423 delete_key( hklm );
2424 delete_key( hkcr );
2425 delete_key( hkeysub1 );
2426 delete_key( hklmsub1 );
2427 delete_key( hkcrsub1 );
2428 delete_key( hklmsub2 );
2429 delete_key( hkcrsub2 );
2430 RegCloseKey( hkey );
2431 RegCloseKey( hklm );
2432 RegCloseKey( hkcr );
2433 RegCloseKey( hkeysub1 );
2434 RegCloseKey( hklmsub1 );
2435 RegCloseKey( hkcrsub1 );
2436 RegCloseKey( hklmsub2 );
2437 RegCloseKey( hkcrsub2 );
2438 }
2439
2440 static void test_classesroot_enum(void)
2441 {
2442 HKEY hkcu=0, hklm=0, hkcr=0, hkcusub[2]={0}, hklmsub[2]={0};
2443 DWORD size;
2444 static CHAR buffer[2];
2445 LONG res;
2446
2447 /* prepare initial testing env in HKCU */
2448 if (!RegOpenKeyA( HKEY_CURRENT_USER, "Software\\Classes\\WineTestCls", &hkcu ))
2449 {
2450 delete_key( hkcu );
2451 RegCloseKey( hkcu );
2452 }
2453 res = RegCreateKeyExA( HKEY_CURRENT_USER, "Software\\Classes\\WineTestCls", 0, NULL, 0,
2454 KEY_SET_VALUE|KEY_ENUMERATE_SUB_KEYS, NULL, &hkcu, NULL );
2455
2456 if (res != ERROR_SUCCESS)
2457 {
2458 skip("failed to add a user class\n");
2459 return;
2460 }
2461
2462 res = RegOpenKeyA( HKEY_CLASSES_ROOT, "WineTestCls", &hkcr );
2463 todo_wine ok(res == ERROR_SUCCESS ||
2464 broken(res == ERROR_FILE_NOT_FOUND /* WinNT */),
2465 "test key not found in hkcr: %d\n", res);
2466 if (res)
2467 {
2468 skip("HKCR key merging not supported\n");
2469 delete_key( hkcu );
2470 RegCloseKey( hkcu );
2471 return;
2472 }
2473
2474 res = RegSetValueExA( hkcu, "X", 0, REG_SZ, (const BYTE *) "AA", 3 );
2475 ok(res == ERROR_SUCCESS, "RegSetValueExA failed: %d\n", res);
2476 res = RegSetValueExA( hkcu, "Y", 0, REG_SZ, (const BYTE *) "B", 2 );
2477 ok(res == ERROR_SUCCESS, "RegSetValueExA failed: %d\n", res);
2478 res = RegCreateKeyA( hkcu, "A", &hkcusub[0] );
2479 ok(res == ERROR_SUCCESS, "RegCreateKeyA failed: %d\n", res);
2480 res = RegCreateKeyA( hkcu, "B", &hkcusub[1] );
2481 ok(res == ERROR_SUCCESS, "RegCreateKeyA failed: %d\n", res);
2482
2483 /* test on values in HKCU */
2484 size = sizeof(buffer);
2485 res = RegEnumValueA( hkcr, 0, buffer, &size, NULL, NULL, NULL, NULL );
2486 ok(res == ERROR_SUCCESS, "RegEnumValueA failed: %d\n", res );
2487 ok(!strcmp( buffer, "X" ), "expected 'X', got '%s'\n", buffer);
2488 size = sizeof(buffer);
2489 res = RegEnumValueA( hkcr, 1, buffer, &size, NULL, NULL, NULL, NULL );
2490 ok(res == ERROR_SUCCESS, "RegEnumValueA failed: %d\n", res );
2491 ok(!strcmp( buffer, "Y" ), "expected 'Y', got '%s'\n", buffer);
2492 size = sizeof(buffer);
2493 res = RegEnumValueA( hkcr, 2, buffer, &size, NULL, NULL, NULL, NULL );
2494 ok(res == ERROR_NO_MORE_ITEMS, "expected ERROR_NO_MORE_ITEMS, got %d\n", res );
2495
2496 res = RegEnumKeyA( hkcr, 0, buffer, size );
2497 ok(res == ERROR_SUCCESS, "RegEnumKey failed: %d\n", res );
2498 ok(!strcmp( buffer, "A" ), "expected 'A', got '%s'\n", buffer);
2499 res = RegEnumKeyA( hkcr, 1, buffer, size );
2500 ok(res == ERROR_SUCCESS, "RegEnumKey failed: %d\n", res );
2501 ok(!strcmp( buffer, "B" ), "expected 'B', got '%s'\n", buffer);
2502 res = RegEnumKeyA( hkcr, 2, buffer, size );
2503 ok(res == ERROR_NO_MORE_ITEMS, "expected ERROR_NO_MORE_ITEMS, got %d\n", res );
2504
2505 /* prepare test env in HKLM */
2506 if (!RegOpenKeyA( HKEY_LOCAL_MACHINE, "Software\\Classes\\WineTestCls", &hklm ))
2507 {
2508 delete_key( hklm );
2509 RegCloseKey( hklm );
2510 }
2511
2512 res = RegCreateKeyExA( HKEY_LOCAL_MACHINE, "Software\\Classes\\WineTestCls", 0, NULL, 0,
2513 KEY_SET_VALUE|KEY_ENUMERATE_SUB_KEYS, NULL, &hklm, NULL );
2514
2515 if (res == ERROR_ACCESS_DENIED)
2516 {
2517 RegCloseKey( hkcusub[0] );
2518 RegCloseKey( hkcusub[1] );
2519 delete_key( hkcu );
2520 RegCloseKey( hkcu );
2521 RegCloseKey( hkcr );
2522 skip("not enough privileges to add a system class\n");
2523 return;
2524 }
2525
2526 res = RegSetValueExA( hklm, "X", 0, REG_SZ, (const BYTE *) "AB", 3 );
2527 ok(res == ERROR_SUCCESS, "RegSetValueExA failed: %d\n", res);
2528 res = RegSetValueExA( hklm, "Z", 0, REG_SZ, (const BYTE *) "C", 2 );
2529 ok(res == ERROR_SUCCESS, "RegSetValueExA failed: %d\n", res);
2530 res = RegCreateKeyA( hklm, "A", &hklmsub[0] );
2531 ok(res == ERROR_SUCCESS, "RegCreateKeyA failed: %d\n", res);
2532 res = RegCreateKeyA( hklm, "C", &hklmsub[1] );
2533 ok(res == ERROR_SUCCESS, "RegCreateKeyA failed: %d\n", res);
2534
2535 /* test on values/keys in both HKCU and HKLM */
2536 size = sizeof(buffer);
2537 res = RegEnumValueA( hkcr, 0, buffer, &size, NULL, NULL, NULL, NULL );
2538 ok(res == ERROR_SUCCESS, "RegEnumValueA failed: %d\n", res );
2539 ok(!strcmp( buffer, "X" ), "expected 'X', got '%s'\n", buffer);
2540 size = sizeof(buffer);
2541 res = RegEnumValueA( hkcr, 1, buffer, &size, NULL, NULL, NULL, NULL );
2542 ok(res == ERROR_SUCCESS, "RegEnumValueA failed: %d\n", res );
2543 ok(!strcmp( buffer, "Y" ), "expected 'Y', got '%s'\n", buffer);
2544 size = sizeof(buffer);
2545 res = RegEnumValueA( hkcr, 2, buffer, &size, NULL, NULL, NULL, NULL );
2546 ok(res == ERROR_SUCCESS, "RegEnumValueA failed: %d\n", res );
2547 ok(!strcmp( buffer, "Z" ), "expected 'Z', got '%s'\n", buffer);
2548 size = sizeof(buffer);
2549 res = RegEnumValueA( hkcr, 3, buffer, &size, NULL, NULL, NULL, NULL );
2550 ok(res == ERROR_NO_MORE_ITEMS, "expected ERROR_NO_MORE_ITEMS, got %d\n", res );
2551
2552 res = RegEnumKeyA( hkcr, 0, buffer, size );
2553 ok(res == ERROR_SUCCESS, "RegEnumKey failed: %d\n", res );
2554 ok(!strcmp( buffer, "A" ), "expected 'A', got '%s'\n", buffer);
2555 res = RegEnumKeyA( hkcr, 1, buffer, size );
2556 ok(res == ERROR_SUCCESS, "RegEnumKey failed: %d\n", res );
2557 ok(!strcmp( buffer, "B" ), "expected 'B', got '%s'\n", buffer);
2558 res = RegEnumKeyA( hkcr, 2, buffer, size );
2559 ok(res == ERROR_SUCCESS, "RegEnumKey failed: %d\n", res );
2560 ok(!strcmp( buffer, "C" ), "expected 'C', got '%s'\n", buffer);
2561 res = RegEnumKeyA( hkcr, 3, buffer, size );
2562 ok(res == ERROR_NO_MORE_ITEMS, "expected ERROR_NO_MORE_ITEMS, got %d\n", res );
2563
2564 /* delete values/keys from HKCU to test only on HKLM */
2565 RegCloseKey( hkcusub[0] );
2566 RegCloseKey( hkcusub[1] );
2567 delete_key( hkcu );
2568 RegCloseKey( hkcu );
2569
2570 size = sizeof(buffer);
2571 res = RegEnumValueA( hkcr, 0, buffer, &size, NULL, NULL, NULL, NULL );
2572 ok(res == ERROR_KEY_DELETED ||
2573 res == ERROR_NO_SYSTEM_RESOURCES, /* Windows XP */
2574 "expected ERROR_KEY_DELETED, got %d\n", res);
2575 size = sizeof(buffer);
2576 res = RegEnumKeyA( hkcr, 0, buffer, size );
2577 ok(res == ERROR_KEY_DELETED ||
2578 res == ERROR_NO_SYSTEM_RESOURCES, /* Windows XP */
2579 "expected ERROR_KEY_DELETED, got %d\n", res);
2580
2581 /* reopen HKCR handle */
2582 RegCloseKey( hkcr );
2583 res = RegOpenKeyA( HKEY_CLASSES_ROOT, "WineTestCls", &hkcr );
2584 ok(res == ERROR_SUCCESS, "test key not found in hkcr: %d\n", res);
2585 if (res) goto cleanup;
2586
2587 /* test on values/keys in HKLM */
2588 size = sizeof(buffer);
2589 res = RegEnumValueA( hkcr, 0, buffer, &size, NULL, NULL, NULL, NULL );
2590 ok(res == ERROR_SUCCESS, "RegEnumValueA failed: %d\n", res );
2591 ok(!strcmp( buffer, "X" ), "expected 'X', got '%s'\n", buffer);
2592 size = sizeof(buffer);
2593 res = RegEnumValueA( hkcr, 1, buffer, &size, NULL, NULL, NULL, NULL );
2594 ok(res == ERROR_SUCCESS, "RegEnumValueA failed: %d\n", res );
2595 ok(!strcmp( buffer, "Z" ), "expected 'Z', got '%s'\n", buffer);
2596 size = sizeof(buffer);
2597 res = RegEnumValueA( hkcr, 2, buffer, &size, NULL, NULL, NULL, NULL );
2598 ok(res == ERROR_NO_MORE_ITEMS, "expected ERROR_NO_MORE_ITEMS, got %d\n", res );
2599
2600 res = RegEnumKeyA( hkcr, 0, buffer, size );
2601 ok(res == ERROR_SUCCESS, "RegEnumKey failed: %d\n", res );
2602 ok(!strcmp( buffer, "A" ), "expected 'A', got '%s'\n", buffer);
2603 res = RegEnumKeyA( hkcr, 1, buffer, size );
2604 ok(res == ERROR_SUCCESS, "RegEnumKey failed: %d\n", res );
2605 ok(!strcmp( buffer, "C" ), "expected 'C', got '%s'\n", buffer);
2606 res = RegEnumKeyA( hkcr, 2, buffer, size );
2607 ok(res == ERROR_NO_MORE_ITEMS, "expected ERROR_NO_MORE_ITEMS, got %d\n", res );
2608
2609 cleanup:
2610 RegCloseKey( hklmsub[0] );
2611 RegCloseKey( hklmsub[1] );
2612 delete_key( hklm );
2613 RegCloseKey( hklm );
2614 RegCloseKey( hkcr );
2615 }
2616
2617 static void test_classesroot_mask(void)
2618 {
2619 HKEY hkey;
2620 LSTATUS res;
2621
2622 res = RegOpenKeyA( HKEY_CLASSES_ROOT, "CLSID", &hkey );
2623 ok(res == ERROR_SUCCESS, "RegOpenKeyA failed: %d\n", res);
2624 todo_wine ok(IS_HKCR(hkey) || broken(!IS_HKCR(hkey)) /* WinNT */,
2625 "hkcr mask not set in %p\n", hkey);
2626 RegCloseKey( hkey );
2627
2628 res = RegOpenKeyA( HKEY_CURRENT_USER, "Software", &hkey );
2629 ok(res == ERROR_SUCCESS, "RegOpenKeyA failed: %d\n", res);
2630 ok(!IS_HKCR(hkey), "hkcr mask set in %p\n", hkey);
2631 RegCloseKey( hkey );
2632
2633 res = RegOpenKeyA( HKEY_LOCAL_MACHINE, "Software", &hkey );
2634 ok(res == ERROR_SUCCESS, "RegOpenKeyA failed: %d\n", res);
2635 ok(!IS_HKCR(hkey), "hkcr mask set in %p\n", hkey);
2636 RegCloseKey( hkey );
2637
2638 res = RegOpenKeyA( HKEY_USERS, ".Default", &hkey );
2639 ok(res == ERROR_SUCCESS, "RegOpenKeyA failed: %d\n", res);
2640 ok(!IS_HKCR(hkey), "hkcr mask set in %p\n", hkey);
2641 RegCloseKey( hkey );
2642
2643 res = RegOpenKeyA( HKEY_CURRENT_CONFIG, "Software", &hkey );
2644 ok(res == ERROR_SUCCESS, "RegOpenKeyA failed: %d\n", res);
2645 ok(!IS_HKCR(hkey), "hkcr mask set in %p\n", hkey);
2646 RegCloseKey( hkey );
2647 }
2648
2649 static void test_deleted_key(void)
2650 {
2651 HKEY hkey, hkey2;
2652 char value[20];
2653 DWORD val_count, type;
2654 LONG res;
2655
2656 /* Open the test key, then delete it while it's open */
2657 RegOpenKeyA( HKEY_CURRENT_USER, "Software\\Wine\\Test", &hkey );
2658
2659 delete_key( hkey_main );
2660
2661 val_count = sizeof(value);
2662 type = 0;
2663 res = RegEnumValueA( hkey, 0, value, &val_count, NULL, &type, 0, 0 );
2664 ok(res == ERROR_KEY_DELETED, "expect ERROR_KEY_DELETED, got %i\n", res);
2665
2666 res = RegEnumKeyA( hkey, 0, value, sizeof(value) );
2667 ok(res == ERROR_KEY_DELETED, "expect ERROR_KEY_DELETED, got %i\n", res);
2668
2669 val_count = sizeof(value);
2670 type = 0;
2671 res = RegQueryValueExA( hkey, "test", NULL, &type, (BYTE *)value, &val_count );
2672 ok(res == ERROR_KEY_DELETED, "expect ERROR_KEY_DELETED, got %i\n", res);
2673
2674 res = RegSetValueExA( hkey, "test", 0, REG_SZ, (const BYTE*)"value", 6);
2675 ok(res == ERROR_KEY_DELETED, "expect ERROR_KEY_DELETED, got %i\n", res);
2676
2677 res = RegOpenKeyA( hkey, "test", &hkey2 );
2678 ok(res == ERROR_KEY_DELETED, "expect ERROR_KEY_DELETED, got %i\n", res);
2679 if (res == 0)
2680 RegCloseKey( hkey2 );
2681
2682 res = RegCreateKeyA( hkey, "test", &hkey2 );
2683 ok(res == ERROR_KEY_DELETED, "expect ERROR_KEY_DELETED, got %i\n", res);
2684 if (res == 0)
2685 RegCloseKey( hkey2 );
2686
2687 res = RegFlushKey( hkey );
2688 ok(res == ERROR_KEY_DELETED, "expect ERROR_KEY_DELETED, got %i\n", res);
2689
2690 RegCloseKey( hkey );
2691
2692 setup_main_key();
2693 }
2694
2695 static void test_delete_value(void)
2696 {
2697 LONG res;
2698 char longname[401];
2699
2700 res = RegSetValueExA( hkey_main, "test", 0, REG_SZ, (const BYTE*)"value", 6 );
2701 ok(res == ERROR_SUCCESS, "expect ERROR_SUCCESS, got %i\n", res);
2702
2703 res = RegQueryValueExA( hkey_main, "test", NULL, NULL, NULL, NULL);
2704 ok(res == ERROR_SUCCESS, "expect ERROR_SUCCESS, got %i\n", res);
2705
2706 res = RegDeleteValueA( hkey_main, "test" );
2707 ok(res == ERROR_SUCCESS, "expect ERROR_SUCCESS, got %i\n", res);
2708
2709 res = RegQueryValueExA( hkey_main, "test", NULL, NULL, NULL, NULL);
2710 ok(res == ERROR_FILE_NOT_FOUND, "expect ERROR_FILE_NOT_FOUND, got %i\n", res);
2711
2712 res = RegDeleteValueA( hkey_main, "test" );
2713 ok(res == ERROR_FILE_NOT_FOUND, "expect ERROR_FILE_NOT_FOUND, got %i\n", res);
2714
2715 memset(longname, 'a', 400);
2716 longname[400] = 0;
2717 res = RegDeleteValueA( hkey_main, longname );