diff --git a/dlls/wintrust/tests/register.c b/dlls/wintrust/tests/register.c index 95f8dc68032..8046a780807 100644 --- a/dlls/wintrust/tests/register.c +++ b/dlls/wintrust/tests/register.c @@ -286,6 +286,65 @@ static void test_LoadFunctionPointers(void) ok(ret, "WintrustLoadFunctionPointers failed: %d\n", GetLastError()); } +typedef void (WINAPI *WintrustGetRegPolicyFlagsFunc)(DWORD *); +typedef BOOL (WINAPI *WintrustSetRegPolicyFlagsFunc)(DWORD); + +static void test_RegPolicyFlags(void) +{ + /* Default state value 0x00023c00, which is + * WTPF_IGNOREREVOCATIONONTS | + * WTPF_OFFLINEOKNBU_COM | + * WTPF_OFFLINEOKNBU_IND | + * WTPF_OFFLINEOK_COM | + * WTPF_OFFLINEOK_IND + */ + static const WCHAR Software_Publishing[] = { + 'S','o','f','t','w','a','r','e','\\', + 'M','i','c','r','o','s','o','f','t','\\', + 'W','i','n','d','o','w','s','\\', + 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\', + 'W','i','n','t','r','u','s','t','\\', + 'T','r','u','s','t',' ','P','r','o','v','i','d','e','r','s','\\', + 'S','o','f','t','w','a','r','e',' ', + 'P','u','b','l','i','s','h','i','n','g',0 }; + static const WCHAR State[] = { 'S','t','a','t','e',0 }; + WintrustGetRegPolicyFlagsFunc pGetFlags; + WintrustSetRegPolicyFlagsFunc pSetFlags; + HKEY key; + LONG r; + DWORD flags1, flags2, flags3, size; + BOOL ret; + + pGetFlags = (WintrustGetRegPolicyFlagsFunc)GetProcAddress(hWintrust, + "WintrustGetRegPolicyFlags"); + pSetFlags = (WintrustSetRegPolicyFlagsFunc)GetProcAddress(hWintrust, + "WintrustSetRegPolicyFlags"); + if (!pGetFlags || !pSetFlags) + skip("Policy flags functions not present\n"); + + r = RegOpenKeyExW(HKEY_CURRENT_USER, Software_Publishing, 0, KEY_ALL_ACCESS, + &key); + ok(!r, "RegOpenKeyEx failed: %d\n", r); + + size = sizeof(flags1); + r = RegQueryValueExW(key, State, NULL, NULL, (LPBYTE)&flags1, &size); + ok(!r, "RegQueryValueEx failed: %d\n", r); + + pGetFlags(&flags2); + ok(flags1 == flags2, "Didn't get expected flags\n"); + + flags3 = flags2 | 1; + ret = pSetFlags(flags3); + ok(ret, "pSetFlags failed: %d\n", GetLastError()); + size = sizeof(flags1); + r = RegQueryValueExW(key, State, NULL, NULL, (LPBYTE)&flags1, &size); + ok(flags1 == flags3, "Didn't get expected flags\n"); + + pSetFlags(flags2); + + RegCloseKey(key); +} + START_TEST(register) { if(!InitFunctionPtrs()) @@ -294,6 +353,7 @@ START_TEST(register) test_AddRem_ActionID(); test_AddDefaultForUsage(); test_LoadFunctionPointers(); + test_RegPolicyFlags(); FreeLibrary(hWintrust); } diff --git a/dlls/wintrust/wintrust_main.c b/dlls/wintrust/wintrust_main.c index 073a36991a8..66ad3228028 100644 --- a/dlls/wintrust/wintrust_main.c +++ b/dlls/wintrust/wintrust_main.c @@ -23,6 +23,7 @@ #include "windef.h" #include "winbase.h" #include "winerror.h" +#include "winreg.h" #include "guiddef.h" #include "wintrust.h" #include "softpub.h" @@ -118,13 +119,48 @@ CRYPT_PROVIDER_DATA * WINAPI WTHelperProvDataFromStateData(HANDLE hStateData) return NULL; } +static const WCHAR Software_Publishing[] = { + 'S','o','f','t','w','a','r','e','\\', + 'M','i','c','r','o','s','o','f','t','\\', + 'W','i','n','d','o','w','s','\\', + 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\', + 'W','i','n','t','r','u','s','t','\\', + 'T','r','u','s','t',' ','P','r','o','v','i','d','e','r','s','\\', + 'S','o','f','t','w','a','r','e',' ', + 'P','u','b','l','i','s','h','i','n','g',0 }; +static const WCHAR State[] = { 'S','t','a','t','e',0 }; + /*********************************************************************** * WintrustGetRegPolicyFlags (WINTRUST.@) */ void WINAPI WintrustGetRegPolicyFlags( DWORD* pdwPolicyFlags ) { - FIXME("%p\n", pdwPolicyFlags); + HKEY key; + LONG r; + + TRACE("%p\n", pdwPolicyFlags); + *pdwPolicyFlags = 0; + r = RegCreateKeyExW(HKEY_CURRENT_USER, Software_Publishing, 0, NULL, 0, + KEY_READ, NULL, &key, NULL); + if (!r) + { + DWORD size = sizeof(DWORD); + + r = RegQueryValueExW(key, State, NULL, NULL, (LPBYTE)pdwPolicyFlags, + &size); + RegCloseKey(key); + if (r) + { + /* Failed to query, create and return default value */ + *pdwPolicyFlags = WTPF_IGNOREREVOCATIONONTS | + WTPF_OFFLINEOKNBU_COM | + WTPF_OFFLINEOKNBU_IND | + WTPF_OFFLINEOK_COM | + WTPF_OFFLINEOK_IND; + WintrustSetRegPolicyFlags(*pdwPolicyFlags); + } + } } /*********************************************************************** @@ -132,6 +168,19 @@ void WINAPI WintrustGetRegPolicyFlags( DWORD* pdwPolicyFlags ) */ BOOL WINAPI WintrustSetRegPolicyFlags( DWORD dwPolicyFlags) { - FIXME("stub: %x\n", dwPolicyFlags); - return TRUE; + HKEY key; + LONG r; + + TRACE("%x\n", dwPolicyFlags); + + r = RegCreateKeyExW(HKEY_CURRENT_USER, Software_Publishing, 0, + NULL, 0, KEY_WRITE, NULL, &key, NULL); + if (!r) + { + r = RegSetValueExW(key, State, 0, REG_DWORD, (LPBYTE)&dwPolicyFlags, + sizeof(DWORD)); + RegCloseKey(key); + } + if (r) SetLastError(r); + return r == ERROR_SUCCESS; } diff --git a/include/wintrust.h b/include/wintrust.h index a422f9d39f7..f7c066790d8 100644 --- a/include/wintrust.h +++ b/include/wintrust.h @@ -364,6 +364,7 @@ BOOL WINAPI WintrustRemoveActionID(GUID*); BOOL WINAPI WintrustLoadFunctionPointers(GUID*,CRYPT_PROVIDER_FUNCTIONS*); BOOL WINAPI WintrustAddDefaultForUsage(const char*,CRYPT_PROVIDER_REGDEFUSAGE*); void WINAPI WintrustGetRegPolicyFlags(DWORD*); +BOOL WINAPI WintrustSetRegPolicyFlags(DWORD); LONG WINAPI WinVerifyTrust(HWND,GUID*,LPVOID); HRESULT WINAPI WinVerifyTrustEx(HWND,GUID*,WINTRUST_DATA*);