diff --git a/dlls/advapi32/advapi32.spec b/dlls/advapi32/advapi32.spec index 438b6713358..4826df93e35 100644 --- a/dlls/advapi32/advapi32.spec +++ b/dlls/advapi32/advapi32.spec @@ -475,7 +475,7 @@ @ stdcall RegDeleteKeyW(long wstr) @ stdcall RegDeleteValueA(long str) @ stdcall RegDeleteValueW(long wstr) -# @ stub RegDisablePredefinedCache +@ stdcall RegDisablePredefinedCache() @ stdcall RegEnumKeyA(long long ptr long) @ stdcall RegEnumKeyExA(long long ptr ptr ptr ptr ptr ptr) @ stdcall RegEnumKeyExW(long long ptr ptr ptr ptr ptr ptr) diff --git a/dlls/advapi32/registry.c b/dlls/advapi32/registry.c index 7790862001a..e99cce70b4b 100644 --- a/dlls/advapi32/registry.c +++ b/dlls/advapi32/registry.c @@ -52,6 +52,7 @@ WINE_DEFAULT_DEBUG_CHANNEL(reg); #define NB_SPECIAL_ROOT_KEYS ((UINT)HKEY_SPECIAL_ROOT_LAST - (UINT)HKEY_SPECIAL_ROOT_FIRST + 1) static HKEY special_root_keys[NB_SPECIAL_ROOT_KEYS]; +static BOOL hkcu_cache_disabled; static const WCHAR name_CLASSES_ROOT[] = {'M','a','c','h','i','n','e','\\', @@ -108,6 +109,10 @@ static HKEY create_special_root_hkey( HANDLE hkey, DWORD access ) { if (RtlOpenCurrentUser( access, &hkey )) return 0; TRACE( "HKEY_CURRENT_USER -> %p\n", hkey ); + + /* don't cache the key in the table if caching is disabled */ + if (hkcu_cache_disabled) + return hkey; } else { @@ -2565,3 +2570,34 @@ cleanup: return result; } + +/****************************************************************************** + * RegDisablePredefinedCache [ADVAPI32.@] + * + * Disables the caching of the HKEY_CLASSES_ROOT key for the process. + * + * PARAMS + * None. + * + * RETURNS + * Success: ERROR_SUCCESS + * Failure: nonzero error code from Winerror.h + * + * NOTES + * This is useful for services that use impersonation. + */ +LONG WINAPI RegDisablePredefinedCache(void) +{ + HKEY hkey_current_user; + int idx = (UINT_PTR)HKEY_CURRENT_USER - (UINT_PTR)HKEY_SPECIAL_ROOT_FIRST; + + /* prevent caching of future requests */ + hkcu_cache_disabled = TRUE; + + hkey_current_user = InterlockedExchangePointer( (void **)&special_root_keys[idx], NULL ); + + if (hkey_current_user) + NtClose( hkey_current_user ); + + return ERROR_SUCCESS; +}