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