Leaked source code of windows server 2003
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.

197 lines
5.2 KiB

  1. #include "priv.h"
  2. #include "resource.h"
  3. #include <mluisupp.h>
  4. #define REGSTR_VAL_IEHARD_NOWARN L"IEHardenIENoWarn"
  5. #define REGSTR_VAL_OCHARD_NOWARN L"IEHardenOCNoWarn"
  6. #define REGSTR_VAL_IEHARD_TIMER L"IEHardenDlgTimeOut"
  7. #define IEHARD_TIMER_ID 45
  8. BOOL IEHard_DlgSetText(HWND hDlg, BOOL fIE)
  9. {
  10. BOOL fRet;
  11. WCHAR szBuff[512];
  12. fRet = MLLoadString(fIE ? IDS_IEHARDEN_TEXT_IE : IDS_IEHARDEN_TEXT_OC, szBuff, ARRAYSIZE(szBuff));
  13. if (fRet)
  14. {
  15. fRet = (BOOL)SendMessage(GetDlgItem(hDlg, IDC_IEHARDEN_TEXT), WM_SETTEXT, 0, (LPARAM)szBuff);
  16. }
  17. return fRet;
  18. }
  19. void IEHard_DlgSetTimer(HWND hDlg)
  20. {
  21. DWORD dwVal;
  22. DWORD cbSize = sizeof(dwVal);
  23. if (ERROR_SUCCESS == SHRegGetUSValue(REGSTR_PATH_INTERNET_SETTINGS, REGSTR_VAL_IEHARD_TIMER, NULL, &dwVal, &cbSize, FALSE, NULL, 0))
  24. {
  25. SetTimer(hDlg, IEHARD_TIMER_ID, dwVal * (1000), NULL);
  26. }
  27. }
  28. BOOL IEHard_InitDialog(HWND hDlg, BOOL fIE)
  29. {
  30. BOOL fRet;
  31. fRet = IEHard_DlgSetText(hDlg, fIE);
  32. if (fRet)
  33. {
  34. IEHard_DlgSetTimer(hDlg);
  35. CenterWindow(hDlg, GetParent(hDlg));
  36. }
  37. return fRet;
  38. }
  39. STDAPI ShowUrlInNewBrowserInstance(LPCWSTR pwszUrl)
  40. {
  41. /* Shell exec RIPs on debug builds since res: isn't registered, use IE directly
  42. SHELLEXECUTEINFO sei = {0};
  43. sei.cbSize = sizeof(sei);
  44. sei.lpFile = L"res://shdoclc/IESechelp.htm";
  45. ShellExecuteEx(&sei);
  46. */
  47. IWebBrowser2* pwb;
  48. if (SUCCEEDED(CoCreateInstance(CLSID_InternetExplorer, NULL, CLSCTX_LOCAL_SERVER, IID_PPV_ARG(IWebBrowser2, &pwb))))
  49. {
  50. VARIANT vNull = {0};
  51. VARIANT vTargetURL;
  52. vTargetURL.vt = VT_BSTR;
  53. vTargetURL.bstrVal = SysAllocString(pwszUrl);
  54. if (vTargetURL.bstrVal)
  55. {
  56. pwb->put_Visible(VARIANT_TRUE);
  57. pwb->Navigate2(&vTargetURL, &vNull, &vNull, &vNull, &vNull);
  58. SysFreeString(vTargetURL.bstrVal);
  59. }
  60. pwb->Release();
  61. return S_OK;
  62. }
  63. return E_FAIL;
  64. }
  65. INT_PTR CALLBACK IEHard_WarnDlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
  66. {
  67. BOOL fRet = FALSE;
  68. switch(uMsg)
  69. {
  70. case WM_INITDIALOG:
  71. IEHard_InitDialog(hDlg, lParam ? TRUE : FALSE);
  72. fRet = TRUE;
  73. break;
  74. case WM_TIMER:
  75. if (IEHARD_TIMER_ID == wParam)
  76. {
  77. PostMessage(hDlg, WM_COMMAND, IDCANCEL, 0);
  78. }
  79. break;
  80. case WM_COMMAND:
  81. switch(LOWORD(wParam))
  82. {
  83. case IDOK:
  84. case IDCANCEL:
  85. EndDialog(hDlg, IDOK == LOWORD(wParam) ? IsDlgButtonChecked(hDlg, IDC_IEHARDEN_DONT_SHOW) : FALSE);
  86. break;
  87. }
  88. break;
  89. case WM_NOTIFY:
  90. if (IDC_IEHARDEN_HELP == LOWORD(wParam))
  91. {
  92. NMHDR *pnmh = (NMHDR*) lParam;
  93. if ((NM_CLICK == pnmh->code) || (NM_RETURN == pnmh->code))
  94. {
  95. ShowUrlInNewBrowserInstance(L"res://shdoclc.dll/IESechelp.htm");
  96. }
  97. }
  98. break;
  99. }
  100. return fRet;
  101. }
  102. #define REGSTR_VAL_IEHARD_NOWARN L"IEHardenIENoWarn"
  103. #define REGSTR_VAL_OCHARD_NOWARN L"IEHardenOCNoWarn"
  104. BOOL UserDisabledIEHardNavWarning(BOOL fIE)
  105. {
  106. BOOL fRet = FALSE;
  107. DWORD dwVal;
  108. DWORD dwSize = sizeof(dwVal);
  109. if (ERROR_SUCCESS == SHRegGetUSValue(REGSTR_PATH_INTERNET_SETTINGS, fIE ? REGSTR_VAL_IEHARD_NOWARN : REGSTR_VAL_OCHARD_NOWARN, NULL,
  110. &dwVal, &dwSize, FALSE, NULL, 0))
  111. {
  112. fRet = (1 == dwVal);
  113. }
  114. return fRet;
  115. }
  116. BOOL IEHard_ShowOnNavigateComplete()
  117. {
  118. BOOL fRet = FALSE;
  119. DWORD dwVal;
  120. DWORD cbSize = sizeof(dwVal);
  121. if (ERROR_SUCCESS == SHRegGetUSValue(REGSTR_PATH_INTERNET_SETTINGS, L"IEHardenWarnOnNav", NULL,
  122. &dwVal, &cbSize, FALSE, NULL, 0))
  123. {
  124. fRet = (1 == dwVal);
  125. }
  126. return fRet;
  127. }
  128. BOOL IEHard_HostedInIE(IUnknown* punk)
  129. {
  130. BOOL fRet;
  131. IWebBrowserApp* pwba;
  132. if (SUCCEEDED(IUnknown_QueryServiceForWebBrowserApp(punk, IID_IWebBrowserApp, (void**)&pwba)))
  133. {
  134. ITargetEmbedding* pte;
  135. if (SUCCEEDED(pwba->QueryInterface(IID_ITargetEmbedding, (void**)&pte)))
  136. {
  137. fRet = FALSE;
  138. pte->Release();
  139. }
  140. else
  141. {
  142. fRet = TRUE;
  143. }
  144. pwba->Release();
  145. }
  146. else
  147. {
  148. fRet = FALSE;
  149. }
  150. return fRet;
  151. }
  152. void IEHard_NavWarning(HWND hwnd, BOOL fIE)
  153. {
  154. if (hwnd && fIE && IEHardened() && !UserDisabledIEHardNavWarning(fIE))
  155. {
  156. BOOL fDontShow = (BOOL)SHFusionDialogBoxParam(MLGetHinst(), MAKEINTRESOURCE(IDD_IEHARDEN1), hwnd, IEHard_WarnDlgProc, fIE);
  157. if (fDontShow)
  158. {
  159. DWORD dwVal = 1;
  160. SHSetValue(HKEY_CURRENT_USER, REGSTR_PATH_INTERNET_SETTINGS, fIE ? REGSTR_VAL_IEHARD_NOWARN : REGSTR_VAL_OCHARD_NOWARN,
  161. REG_DWORD, &dwVal, sizeof(dwVal));
  162. }
  163. }
  164. }