Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

153 lines
3.9 KiB

  1. #include "priv.h"
  2. #include <wintrust.h>
  3. #include "wvtp.h"
  4. #define WINTRUST TEXT("wintrust.dll")
  5. #ifdef DELAY_LOAD_WVT
  6. #ifndef _WVTP_NOCODE_
  7. Cwvt::Cwvt()
  8. {
  9. m_fInited = FALSE;
  10. }
  11. Cwvt::~Cwvt()
  12. {
  13. if (m_fInited) {
  14. FreeLibrary(m_hMod);
  15. }
  16. }
  17. HRESULT
  18. Cwvt::Init(void)
  19. {
  20. if (m_fInited) {
  21. return S_OK;
  22. }
  23. m_hMod = LoadLibrary( WINTRUST );
  24. if (NULL == m_hMod) {
  25. return (HRESULT_FROM_WIN32(ERROR_MOD_NOT_FOUND));
  26. }
  27. #define CHECKAPI(_fn) \
  28. *(FARPROC*)&(_pfn##_fn) = GetProcAddress(m_hMod, #_fn); \
  29. if (!(_pfn##_fn)) { \
  30. FreeLibrary(m_hMod); \
  31. return (HRESULT_FROM_WIN32(ERROR_MOD_NOT_FOUND)); \
  32. }
  33. CHECKAPI(WinVerifyTrust);
  34. m_fInited = TRUE;
  35. return S_OK;
  36. }
  37. #endif // _WVTP_NOCODE_
  38. #endif // DELAY_LOAD_WVT
  39. #define REGSTR_PATH_INFODEL_REST TEXT("Software\\Policies\\Microsoft\\Internet Explorer\\Infodelivery\\Restrictions")
  40. #define REGSTR_PATH_DOWNLOAD TEXT("Software\\Microsoft\\Internet Explorer\\Download")
  41. #define REGVAL_UI_REST TEXT("NoWinVerifyTrustUI")
  42. BOOL
  43. IsUIRestricted()
  44. {
  45. HKEY hkeyRest = 0;
  46. BOOL bUIRest = FALSE;
  47. DWORD dwValue = 0;
  48. DWORD dwLen = sizeof(DWORD);
  49. // per-machine UI off policy
  50. if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, REGSTR_PATH_INFODEL_REST, 0, KEY_READ, &hkeyRest) == ERROR_SUCCESS) {
  51. if (RegQueryValueEx( hkeyRest, REGVAL_UI_REST, NULL, NULL,
  52. (LPBYTE)&dwValue, &dwLen) == ERROR_SUCCESS && dwValue)
  53. bUIRest = TRUE;
  54. RegCloseKey(hkeyRest);
  55. }
  56. return bUIRest;
  57. }
  58. // FEATURE: move these to corpolicy.h in iedev\inc!!!
  59. // {D41E4F1F-A407-11d1-8BC9-00C04FA30A41}
  60. #define COR_POLICY_LOCKDOWN_CHECK \
  61. { 0xd41e4f1f, 0xa407, 0x11d1, {0x8b, 0xc9, 0x0, 0xc0, 0x4f, 0xa3, 0xa, 0x41 } }
  62. //--------------------------------------------------------------------
  63. // For COR_POLICY_LOCKDOWN_CHECK:
  64. // -----------------------------
  65. // Structure to pass into WVT
  66. typedef struct _COR_LOCKDOWN {
  67. DWORD cbSize; // Size of policy provider
  68. DWORD flag; // reserved
  69. BOOL fAllPublishers; // Trust all publishers or just ones in the trusted data base
  70. } COR_LOCKDOWN, *PCOR_LOCKDOWN;
  71. HRESULT Cwvt::VerifyTrust(HANDLE hFile, HWND hWnd, LPCWSTR szStatusText)
  72. {
  73. WINTRUST_DATA sWTD;
  74. WINTRUST_FILE_INFO sWTFI;
  75. GUID gV2 = COR_POLICY_LOCKDOWN_CHECK;
  76. COR_LOCKDOWN sCorPolicy;
  77. HRESULT hr = S_OK;
  78. memset(&sCorPolicy, 0, sizeof(COR_LOCKDOWN));
  79. sCorPolicy.cbSize = sizeof(COR_LOCKDOWN);
  80. if ( (hWnd == INVALID_HANDLE_VALUE) || IsUIRestricted())
  81. sCorPolicy.fAllPublishers = FALSE; // lockdown to only trusted pubs
  82. else
  83. sCorPolicy.fAllPublishers = TRUE; // regular behavior
  84. // Set up the winverify provider structures
  85. memset(&sWTD, 0x00, sizeof(WINTRUST_DATA));
  86. memset(&sWTFI, 0x00, sizeof(WINTRUST_FILE_INFO));
  87. sWTFI.cbStruct = sizeof(WINTRUST_FILE_INFO);
  88. sWTFI.hFile = hFile;
  89. sWTFI.pcwszFilePath = szStatusText;
  90. sWTD.cbStruct = sizeof(WINTRUST_DATA);
  91. sWTD.pPolicyCallbackData = &sCorPolicy; // Add in the cor trust information!!
  92. //check policy to find out if we should display UI
  93. if (SHRegGetBoolUSValue(REGSTR_PATH_DOWNLOAD, TEXT("CheckExeSignatures"),FALSE, FALSE))
  94. {
  95. sWTD.dwUIChoice = WTD_UI_ALL; // No bad UI is overridden in COR TRUST provider
  96. sWTD.dwUnionChoice = WTD_CHOICE_FILE;
  97. sWTD.pFile = &sWTFI;
  98. ULONG_PTR uCookie = 0;
  99. SHActivateContext(&uCookie);
  100. hr = WinVerifyTrust(hWnd, &gV2, &sWTD);
  101. if (uCookie)
  102. {
  103. SHDeactivateContext(uCookie);
  104. }
  105. // APPCOMPAT: this works around a wvt bug that returns 0x57 (success) when
  106. // you hit No to an usigned control
  107. if (SUCCEEDED(hr) && hr != S_OK) {
  108. hr = TRUST_E_FAIL;
  109. }
  110. }
  111. return hr;
  112. }