Commit 8340636c authored by Vincent Povirk's avatar Vincent Povirk Committed by Alexandre Julliard

advapi32/tests: Account for limited users in registry test.

parent fa8d59c3
...@@ -48,6 +48,8 @@ static NTSTATUS (WINAPI * pNtDeleteKey)(HANDLE); ...@@ -48,6 +48,8 @@ static NTSTATUS (WINAPI * pNtDeleteKey)(HANDLE);
static NTSTATUS (WINAPI * pRtlFormatCurrentUserKeyPath)(UNICODE_STRING*); static NTSTATUS (WINAPI * pRtlFormatCurrentUserKeyPath)(UNICODE_STRING*);
static NTSTATUS (WINAPI * pRtlFreeUnicodeString)(PUNICODE_STRING); static NTSTATUS (WINAPI * pRtlFreeUnicodeString)(PUNICODE_STRING);
static BOOL limited_user;
/* Debugging functions from wine/libs/wine/debug.c */ /* Debugging functions from wine/libs/wine/debug.c */
...@@ -170,6 +172,26 @@ static void setup_main_key(void) ...@@ -170,6 +172,26 @@ static void setup_main_key(void)
assert (!RegCreateKeyA( HKEY_CURRENT_USER, "Software\\Wine\\Test", &hkey_main )); assert (!RegCreateKeyA( HKEY_CURRENT_USER, "Software\\Wine\\Test", &hkey_main ));
} }
static void check_user_privs(void)
{
DWORD ret;
HKEY hkey = (HKEY)0xdeadbeef;
ret = RegOpenKeyExA( HKEY_LOCAL_MACHINE, "Software", 0, KEY_READ|KEY_WRITE, &hkey);
ok(ret == ERROR_SUCCESS || ret == ERROR_ACCESS_DENIED, "expected success or access denied, got %i\n", ret);
if (ret == ERROR_SUCCESS)
{
ok(hkey != NULL, "RegOpenKeyExA succeeded but returned NULL hkey\n");
RegCloseKey(hkey);
}
else
{
ok(hkey == NULL, "RegOpenKeyExA failed but returned hkey %p\n", hkey);
limited_user = TRUE;
trace("running as limited user\n");
}
}
#define lok ok_(__FILE__, line) #define lok ok_(__FILE__, line)
#define test_hkey_main_Value_A(name, string, full_byte_len) _test_hkey_main_Value_A(__LINE__, name, string, full_byte_len) #define test_hkey_main_Value_A(name, string, full_byte_len) _test_hkey_main_Value_A(__LINE__, name, string, full_byte_len)
static void _test_hkey_main_Value_A(int line, LPCSTR name, LPCSTR string, static void _test_hkey_main_Value_A(int line, LPCSTR name, LPCSTR string,
...@@ -997,13 +1019,21 @@ static void test_reg_open_key(void) ...@@ -997,13 +1019,21 @@ static void test_reg_open_key(void)
ret = RegCreateKeyExA(HKEY_LOCAL_MACHINE, "Software\\Wine", 0, NULL, 0, ret = RegCreateKeyExA(HKEY_LOCAL_MACHINE, "Software\\Wine", 0, NULL, 0,
KEY_WOW64_32KEY | KEY_ALL_ACCESS, NULL, &hkRoot32, NULL); KEY_WOW64_32KEY | KEY_ALL_ACCESS, NULL, &hkRoot32, NULL);
ok(ret == ERROR_SUCCESS && hkRoot32 != NULL, if (limited_user)
"RegCreateKeyEx with KEY_WOW64_32KEY failed (err=%u)\n", ret); ok(ret == ERROR_ACCESS_DENIED && hkRoot32 == NULL,
"RegCreateKeyEx with KEY_WOW64_32KEY failed (err=%u)\n", ret);
else
ok(ret == ERROR_SUCCESS && hkRoot32 != NULL,
"RegCreateKeyEx with KEY_WOW64_32KEY failed (err=%u)\n", ret);
ret = RegCreateKeyExA(HKEY_LOCAL_MACHINE, "Software\\Wine", 0, NULL, 0, ret = RegCreateKeyExA(HKEY_LOCAL_MACHINE, "Software\\Wine", 0, NULL, 0,
KEY_WOW64_64KEY | KEY_ALL_ACCESS, NULL, &hkRoot64, NULL); KEY_WOW64_64KEY | KEY_ALL_ACCESS, NULL, &hkRoot64, NULL);
ok(ret == ERROR_SUCCESS && hkRoot64 != NULL, if (limited_user)
"RegCreateKeyEx with KEY_WOW64_64KEY failed (err=%u)\n", ret); ok(ret == ERROR_ACCESS_DENIED && hkRoot64 == NULL,
"RegCreateKeyEx with KEY_WOW64_64KEY failed (err=%u)\n", ret);
else
ok(ret == ERROR_SUCCESS && hkRoot64 != NULL,
"RegCreateKeyEx with KEY_WOW64_64KEY failed (err=%u)\n", ret);
bRet = AllocateAndInitializeSid(&sid_authority, 1, SECURITY_WORLD_RID, bRet = AllocateAndInitializeSid(&sid_authority, 1, SECURITY_WORLD_RID,
0, 0, 0, 0, 0, 0, 0, &world_sid); 0, 0, 0, 0, 0, 0, 0, &world_sid);
...@@ -1032,26 +1062,33 @@ static void test_reg_open_key(void) ...@@ -1032,26 +1062,33 @@ static void test_reg_open_key(void)
ok(bRet == TRUE, ok(bRet == TRUE,
"Expected SetSecurityDescriptorDacl to return TRUE, got %d, last error %u\n", bRet, GetLastError()); "Expected SetSecurityDescriptorDacl to return TRUE, got %d, last error %u\n", bRet, GetLastError());
/* The "sanctioned" methods of setting a registry ACL aren't implemented in Wine. */ if (limited_user)
bRet = SetKernelObjectSecurity(hkRoot64, DACL_SECURITY_INFORMATION, sd); {
ok(bRet == TRUE, skip("not enough privileges to modify HKLM\n");
"Expected SetKernelObjectSecurity to return TRUE, got %d, last error %u\n", bRet, GetLastError()); }
else
bRet = SetKernelObjectSecurity(hkRoot32, DACL_SECURITY_INFORMATION, sd); {
ok(bRet == TRUE, /* The "sanctioned" methods of setting a registry ACL aren't implemented in Wine. */
"Expected SetKernelObjectSecurity to return TRUE, got %d, last error %u\n", bRet, GetLastError()); bRet = SetKernelObjectSecurity(hkRoot64, DACL_SECURITY_INFORMATION, sd);
ok(bRet == TRUE,
hkResult = NULL; "Expected SetKernelObjectSecurity to return TRUE, got %d, last error %u\n", bRet, GetLastError());
ret = RegOpenKeyExA(HKEY_LOCAL_MACHINE, "Software\\Wine", 0, KEY_WOW64_64KEY | KEY_READ, &hkResult);
ok(ret == ERROR_SUCCESS && hkResult != NULL, bRet = SetKernelObjectSecurity(hkRoot32, DACL_SECURITY_INFORMATION, sd);
"RegOpenKeyEx with KEY_WOW64_64KEY failed (err=%u)\n", ret); ok(bRet == TRUE,
RegCloseKey(hkResult); "Expected SetKernelObjectSecurity to return TRUE, got %d, last error %u\n", bRet, GetLastError());
hkResult = NULL;
ret = RegOpenKeyExA(HKEY_LOCAL_MACHINE, "Software\\Wine", 0, KEY_WOW64_64KEY | KEY_READ, &hkResult);
ok(ret == ERROR_SUCCESS && hkResult != NULL,
"RegOpenKeyEx with KEY_WOW64_64KEY failed (err=%u)\n", ret);
RegCloseKey(hkResult);
hkResult = NULL; hkResult = NULL;
ret = RegOpenKeyExA(HKEY_LOCAL_MACHINE, "Software\\Wine", 0, KEY_WOW64_32KEY | KEY_READ, &hkResult); ret = RegOpenKeyExA(HKEY_LOCAL_MACHINE, "Software\\Wine", 0, KEY_WOW64_32KEY | KEY_READ, &hkResult);
ok(ret == ERROR_SUCCESS && hkResult != NULL, ok(ret == ERROR_SUCCESS && hkResult != NULL,
"RegOpenKeyEx with KEY_WOW64_32KEY failed (err=%u)\n", ret); "RegOpenKeyEx with KEY_WOW64_32KEY failed (err=%u)\n", ret);
RegCloseKey(hkResult); RegCloseKey(hkResult);
}
HeapFree(GetProcessHeap(), 0, sd); HeapFree(GetProcessHeap(), 0, sd);
LocalFree(key_acl); LocalFree(key_acl);
...@@ -1143,13 +1180,21 @@ static void test_reg_create_key(void) ...@@ -1143,13 +1180,21 @@ static void test_reg_create_key(void)
ret = RegCreateKeyExA(HKEY_LOCAL_MACHINE, "Software\\Wine", 0, NULL, 0, ret = RegCreateKeyExA(HKEY_LOCAL_MACHINE, "Software\\Wine", 0, NULL, 0,
KEY_WOW64_32KEY | KEY_ALL_ACCESS, NULL, &hkRoot32, NULL); KEY_WOW64_32KEY | KEY_ALL_ACCESS, NULL, &hkRoot32, NULL);
ok(ret == ERROR_SUCCESS && hkRoot32 != NULL, if (limited_user)
"RegCreateKeyEx with KEY_WOW64_32KEY failed (err=%d)\n", ret); ok(ret == ERROR_ACCESS_DENIED && hkRoot32 == NULL,
"RegCreateKeyEx with KEY_WOW64_32KEY failed (err=%d)\n", ret);
else
ok(ret == ERROR_SUCCESS && hkRoot32 != NULL,
"RegCreateKeyEx with KEY_WOW64_32KEY failed (err=%d)\n", ret);
ret = RegCreateKeyExA(HKEY_LOCAL_MACHINE, "Software\\Wine", 0, NULL, 0, ret = RegCreateKeyExA(HKEY_LOCAL_MACHINE, "Software\\Wine", 0, NULL, 0,
KEY_WOW64_64KEY | KEY_ALL_ACCESS, NULL, &hkRoot64, NULL); KEY_WOW64_64KEY | KEY_ALL_ACCESS, NULL, &hkRoot64, NULL);
ok(ret == ERROR_SUCCESS && hkRoot64 != NULL, if (limited_user)
"RegCreateKeyEx with KEY_WOW64_64KEY failed (err=%d)\n", ret); ok(ret == ERROR_ACCESS_DENIED && hkRoot64 == NULL,
"RegCreateKeyEx with KEY_WOW64_64KEY failed (err=%d)\n", ret);
else
ok(ret == ERROR_SUCCESS && hkRoot64 != NULL,
"RegCreateKeyEx with KEY_WOW64_64KEY failed (err=%d)\n", ret);
bRet = AllocateAndInitializeSid(&sid_authority, 1, SECURITY_WORLD_RID, bRet = AllocateAndInitializeSid(&sid_authority, 1, SECURITY_WORLD_RID,
0, 0, 0, 0, 0, 0, 0, &world_sid); 0, 0, 0, 0, 0, 0, 0, &world_sid);
...@@ -1166,7 +1211,7 @@ static void test_reg_create_key(void) ...@@ -1166,7 +1211,7 @@ static void test_reg_create_key(void)
access.Trustee.ptstrName = (char *)world_sid; access.Trustee.ptstrName = (char *)world_sid;
dwRet = SetEntriesInAclA(1, &access, NULL, &key_acl); dwRet = SetEntriesInAclA(1, &access, NULL, &key_acl);
ok(ret == ERROR_SUCCESS, ok(dwRet == ERROR_SUCCESS,
"Expected SetEntriesInAclA to return ERROR_SUCCESS, got %u, last error %u\n", dwRet, GetLastError()); "Expected SetEntriesInAclA to return ERROR_SUCCESS, got %u, last error %u\n", dwRet, GetLastError());
sd = HeapAlloc(GetProcessHeap(), 0, SECURITY_DESCRIPTOR_MIN_LENGTH); sd = HeapAlloc(GetProcessHeap(), 0, SECURITY_DESCRIPTOR_MIN_LENGTH);
...@@ -1178,28 +1223,35 @@ static void test_reg_create_key(void) ...@@ -1178,28 +1223,35 @@ static void test_reg_create_key(void)
ok(bRet == TRUE, ok(bRet == TRUE,
"Expected SetSecurityDescriptorDacl to return TRUE, got %d, last error %u\n", bRet, GetLastError()); "Expected SetSecurityDescriptorDacl to return TRUE, got %d, last error %u\n", bRet, GetLastError());
/* The "sanctioned" methods of setting a registry ACL aren't implemented in Wine. */ if (limited_user)
bRet = SetKernelObjectSecurity(hkRoot64, DACL_SECURITY_INFORMATION, sd); {
ok(bRet == TRUE, skip("not enough privileges to modify HKLM\n");
"Expected SetKernelObjectSecurity to return TRUE, got %d, last error %u\n", bRet, GetLastError()); }
else
bRet = SetKernelObjectSecurity(hkRoot32, DACL_SECURITY_INFORMATION, sd); {
ok(bRet == TRUE, /* The "sanctioned" methods of setting a registry ACL aren't implemented in Wine. */
"Expected SetKernelObjectSecurity to return TRUE, got %d, last error %u\n", bRet, GetLastError()); bRet = SetKernelObjectSecurity(hkRoot64, DACL_SECURITY_INFORMATION, sd);
ok(bRet == TRUE,
hkey1 = NULL; "Expected SetKernelObjectSecurity to return TRUE, got %d, last error %u\n", bRet, GetLastError());
ret = RegCreateKeyExA(HKEY_LOCAL_MACHINE, "Software\\Wine", 0, NULL, 0,
KEY_WOW64_64KEY | KEY_READ, NULL, &hkey1, NULL); bRet = SetKernelObjectSecurity(hkRoot32, DACL_SECURITY_INFORMATION, sd);
ok(ret == ERROR_SUCCESS && hkey1 != NULL, ok(bRet == TRUE,
"RegOpenKeyEx with KEY_WOW64_64KEY failed (err=%u)\n", ret); "Expected SetKernelObjectSecurity to return TRUE, got %d, last error %u\n", bRet, GetLastError());
RegCloseKey(hkey1);
hkey1 = NULL;
ret = RegCreateKeyExA(HKEY_LOCAL_MACHINE, "Software\\Wine", 0, NULL, 0,
KEY_WOW64_64KEY | KEY_READ, NULL, &hkey1, NULL);
ok(ret == ERROR_SUCCESS && hkey1 != NULL,
"RegOpenKeyEx with KEY_WOW64_64KEY failed (err=%u)\n", ret);
RegCloseKey(hkey1);
hkey1 = NULL; hkey1 = NULL;
ret = RegCreateKeyExA(HKEY_LOCAL_MACHINE, "Software\\Wine", 0, NULL, 0, ret = RegCreateKeyExA(HKEY_LOCAL_MACHINE, "Software\\Wine", 0, NULL, 0,
KEY_WOW64_32KEY | KEY_READ, NULL, &hkey1, NULL); KEY_WOW64_32KEY | KEY_READ, NULL, &hkey1, NULL);
ok(ret == ERROR_SUCCESS && hkey1 != NULL, ok(ret == ERROR_SUCCESS && hkey1 != NULL,
"RegOpenKeyEx with KEY_WOW64_32KEY failed (err=%u)\n", ret); "RegOpenKeyEx with KEY_WOW64_32KEY failed (err=%u)\n", ret);
RegCloseKey(hkey1); RegCloseKey(hkey1);
}
HeapFree(GetProcessHeap(), 0, sd); HeapFree(GetProcessHeap(), 0, sd);
LocalFree(key_acl); LocalFree(key_acl);
...@@ -2722,6 +2774,7 @@ START_TEST(registry) ...@@ -2722,6 +2774,7 @@ START_TEST(registry)
InitFunctionPtrs(); InitFunctionPtrs();
setup_main_key(); setup_main_key();
check_user_privs();
test_set_value(); test_set_value();
create_test_entries(); create_test_entries();
test_enum_value(); test_enum_value();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment