Commit 62d3309a authored by Nikolay Sivov's avatar Nikolay Sivov Committed by Alexandre Julliard

advapi32: Make RegOpenCurrentUser() return real key handles for current SID.

parent 8fe18a16
...@@ -37,6 +37,7 @@ ...@@ -37,6 +37,7 @@
#include "winerror.h" #include "winerror.h"
#include "winternl.h" #include "winternl.h"
#include "winuser.h" #include "winuser.h"
#include "sddl.h"
#include "advapi32_misc.h" #include "advapi32_misc.h"
#include "wine/unicode.h" #include "wine/unicode.h"
...@@ -648,6 +649,21 @@ LSTATUS WINAPI RegOpenKeyA( HKEY hkey, LPCSTR name, PHKEY retkey ) ...@@ -648,6 +649,21 @@ LSTATUS WINAPI RegOpenKeyA( HKEY hkey, LPCSTR name, PHKEY retkey )
return RegOpenKeyExA( hkey, name, 0, MAXIMUM_ALLOWED, retkey ); return RegOpenKeyExA( hkey, name, 0, MAXIMUM_ALLOWED, retkey );
} }
static WCHAR *get_thread_token_user_sid(HANDLE token)
{
WCHAR *sidstring = NULL;
TOKEN_USER *info;
DWORD len = 0;
GetTokenInformation(token, TokenUser, NULL, 0, &len);
info = heap_alloc(len);
if (GetTokenInformation(token, TokenUser, info, len, &len))
ConvertSidToStringSidW(info->User.Sid, &sidstring);
heap_free(info);
return sidstring;
}
/****************************************************************************** /******************************************************************************
* RegOpenCurrentUser [ADVAPI32.@] * RegOpenCurrentUser [ADVAPI32.@]
...@@ -671,7 +687,37 @@ LSTATUS WINAPI RegOpenKeyA( HKEY hkey, LPCSTR name, PHKEY retkey ) ...@@ -671,7 +687,37 @@ LSTATUS WINAPI RegOpenKeyA( HKEY hkey, LPCSTR name, PHKEY retkey )
*/ */
LSTATUS WINAPI RegOpenCurrentUser( REGSAM access, PHKEY retkey ) LSTATUS WINAPI RegOpenCurrentUser( REGSAM access, PHKEY retkey )
{ {
return RegOpenKeyExA( HKEY_CURRENT_USER, "", 0, access, retkey ); WCHAR *sidstring = NULL;
HANDLE threadtoken;
LSTATUS ret;
/* get current user SID */
if (OpenThreadToken(GetCurrentThread(), TOKEN_QUERY, FALSE, &threadtoken))
{
sidstring = get_thread_token_user_sid(threadtoken);
CloseHandle(threadtoken);
}
if (!sidstring)
{
ImpersonateSelf(SecurityIdentification);
if (OpenThreadToken(GetCurrentThread(), TOKEN_QUERY, FALSE, &threadtoken))
{
sidstring = get_thread_token_user_sid(threadtoken);
CloseHandle(threadtoken);
}
RevertToSelf();
}
if (sidstring)
{
ret = RegOpenKeyExW( HKEY_USERS, sidstring, 0, access, retkey );
LocalFree(sidstring);
}
else
ret = RegOpenKeyExA( HKEY_CURRENT_USER, "", 0, access, retkey );
return ret;
} }
......
...@@ -3278,6 +3278,18 @@ static void test_delete_key_value(void) ...@@ -3278,6 +3278,18 @@ static void test_delete_key_value(void)
RegCloseKey(subkey); RegCloseKey(subkey);
} }
static void test_RegOpenCurrentUser(void)
{
HKEY key;
LONG ret;
key = HKEY_CURRENT_USER;
ret = RegOpenCurrentUser(KEY_READ, &key);
ok(!ret, "got %d, error %d\n", ret, GetLastError());
ok(key != HKEY_CURRENT_USER, "got %p\n", key);
RegCloseKey(key);
}
START_TEST(registry) START_TEST(registry)
{ {
/* Load pointers for functions that are not available in all Windows versions */ /* Load pointers for functions that are not available in all Windows versions */
...@@ -3310,6 +3322,7 @@ START_TEST(registry) ...@@ -3310,6 +3322,7 @@ START_TEST(registry)
test_deleted_key(); test_deleted_key();
test_delete_value(); test_delete_value();
test_delete_key_value(); test_delete_key_value();
test_RegOpenCurrentUser();
/* cleanup */ /* cleanup */
delete_key( hkey_main ); delete_key( hkey_main );
......
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