1 /*
2  * PROJECT:         ReactOS api tests
3  * LICENSE:         LGPLv2.1+ - See COPYING.Lib in the top level directory
4  * PURPOSE:         Test for RegQueryInfoKey
5  * PROGRAMMER:      Thomas Faber <thomas.faber@reactos.org>
6  */
7 
8 #include "precomp.h"
9 
10 #define TestKeyAccess(da, er, es) TestKeyAccess_(__FILE__, __LINE__, da, er, es)
11 static
12 VOID
13 TestKeyAccess_(
14     _In_ PCSTR File,
15     _In_ INT Line,
16     _In_ REGSAM DesiredAccess,
17     _In_ LONG ExpectedReturn,
18     _In_ BOOLEAN ExpectSd)
19 {
20     DWORD cbSd;
21     HKEY hKey;
22     LONG ret;
23 
24     ret = RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"Software", 0, DesiredAccess, &hKey);
25     ok_(File, Line)(ret == NO_ERROR, "RegOpenKeyEx returned %ld\n", ret);
26     if (ret == NO_ERROR)
27     {
28         cbSd = 0x55555555;
29         ret = RegQueryInfoKeyW(hKey, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, &cbSd, NULL);
30         ok_(File, Line)(ret == ExpectedReturn, "RegQueryInfoKeyW returned %ld\n", ret);
31         if (ExpectSd)
32             ok_(File, Line)(cbSd != 0 && cbSd != 0x55555555, "RegQueryInfoKeyW - cbSd = %lu\n", cbSd);
33         else
34             ok_(File, Line)(cbSd == 0, "RegQueryInfoKeyW - cbSd = %lu\n", cbSd);
35 
36         cbSd = 0x55555555;
37         ret = RegQueryInfoKeyA(hKey, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, &cbSd, NULL);
38         ok_(File, Line)(ret == ExpectedReturn, "RegQueryInfoKeyA returned %ld\n", ret);
39         if (ExpectSd)
40             ok_(File, Line)(cbSd != 0 && cbSd != 0x55555555, "RegQueryInfoKeyA - cbSd = %lu\n", cbSd);
41         else
42             ok_(File, Line)(cbSd == 0, "RegQueryInfoKeyA - cbSd = %lu\n", cbSd);
43         ret = RegCloseKey(hKey);
44         ok_(File, Line)(ret == NO_ERROR, "RegCloseKey returned %ld\n", ret);
45     }
46     else
47     {
48         skip_(File, Line)("No key handle\n");
49     }
50 }
51 
52 START_TEST(RegQueryInfoKey)
53 {
54     /* 0 access just fails the open */
55     if (0)
56     TestKeyAccess(0,                                ERROR_ACCESS_DENIED, FALSE);
57     /* Without KEY_QUERY_VALUE we can't query anything */
58     TestKeyAccess(READ_CONTROL,                     ERROR_ACCESS_DENIED, FALSE);
59     /* Without READ_CONTROL we'll get success but SD size will yield 0 */
60     TestKeyAccess(KEY_QUERY_VALUE,                  NO_ERROR, FALSE);
61     /* With the two combined we get everything */
62     TestKeyAccess(KEY_QUERY_VALUE | READ_CONTROL,   NO_ERROR, TRUE);
63     /* Write rights return nothing on 2003 (but succeed and return SD size on Win7) */
64     TestKeyAccess(KEY_SET_VALUE,                    ERROR_ACCESS_DENIED, FALSE);
65     TestKeyAccess(KEY_CREATE_SUB_KEY,               ERROR_ACCESS_DENIED, FALSE);
66     TestKeyAccess(KEY_CREATE_LINK,                  ERROR_ACCESS_DENIED, FALSE);
67     TestKeyAccess(DELETE,                           ERROR_ACCESS_DENIED, FALSE);
68     TestKeyAccess(WRITE_DAC,                        ERROR_ACCESS_DENIED, FALSE);
69     TestKeyAccess(WRITE_OWNER,                      ERROR_ACCESS_DENIED, FALSE);
70     /* But these return nothing */
71     TestKeyAccess(KEY_ENUMERATE_SUB_KEYS,           ERROR_ACCESS_DENIED, FALSE);
72     TestKeyAccess(KEY_NOTIFY,                       ERROR_ACCESS_DENIED, FALSE);
73 }
74