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