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.

144 lines
5.6 KiB

  1. /*****************************************************************************\
  2. FILE: security.h
  3. \*****************************************************************************/
  4. #include "priv.h"
  5. #include "util.h"
  6. #include <imm.h>
  7. #include <mshtml.h>
  8. BOOL ProcessUrlAction(IUnknown * punkSite, LPCTSTR pszUrl, DWORD dwAction, DWORD dwFlags)
  9. {
  10. BOOL fAllowed = FALSE;
  11. if (pszUrl)
  12. {
  13. IInternetSecurityManager *pSecMgr;
  14. if (SUCCEEDED(CoCreateInstance(CLSID_InternetSecurityManager,
  15. NULL, CLSCTX_INPROC_SERVER,
  16. IID_IInternetSecurityManager,
  17. (void **)&pSecMgr)))
  18. {
  19. WCHAR wzUrl[MAX_URL_STRING];
  20. DWORD dwZoneID = URLZONE_UNTRUSTED;
  21. DWORD dwPolicy = 0;
  22. DWORD dwContext = 0;
  23. IUnknown_SetSite(pSecMgr, punkSite);
  24. SHTCharToUnicode(pszUrl, wzUrl, ARRAYSIZE(wzUrl));
  25. if (S_OK == pSecMgr->ProcessUrlAction(wzUrl, dwAction, (BYTE *)&dwPolicy, sizeof(dwPolicy), (BYTE *)&dwContext, sizeof(dwContext), dwFlags, 0))
  26. {
  27. if (GetUrlPolicyPermissions(dwPolicy) == URLPOLICY_ALLOW)
  28. fAllowed = TRUE;
  29. }
  30. IUnknown_SetSite(pSecMgr, NULL);
  31. pSecMgr->Release();
  32. }
  33. }
  34. return fAllowed;
  35. }
  36. /*****************************************************************************\
  37. FUNCTION: SecurityZoneCheck
  38. PARAMETERS:
  39. punkSite: Site for QS, and enabling modal if UI needed.
  40. dwAction: verb to check. normally URLACTION_SHELL_VERB
  41. pidl: FTP URL that we need to verify
  42. pszUrl: FTP URL that we need to verify
  43. dwFlags: normally PUAF_DEFAULT | PUAF_WARN_IF_DENIED
  44. DESCRIPTION:
  45. Only pidl or pszUrl is passed. This function will check if the verb
  46. (dwAction) is allowed in this zone. Our first job is to find the zone which
  47. can be any of the following:
  48. 1. Third party app that supports IInternetHostSecurityManager have a chance to disallow the action.
  49. 2. Hosted in DefView w/WebView. Zone of WebView can fail the action.
  50. 3. Hosted in HTML FRAME. Zone comes from trident can fail the action
  51. 4. Hosted in DefView w/o WebView. Zone comes from pidl or pszUrl and that can fail the action.
  52. \*****************************************************************************/
  53. BOOL ZoneCheckUrlAction(IUnknown * punkSite, DWORD dwAction, LPCTSTR pszUrl, DWORD dwFlags)
  54. {
  55. BOOL IsSafe = TRUE; // Assume we will allow this.
  56. IInternetHostSecurityManager * pihsm;
  57. // What we want to do is allow this to happen only if the author of the HTML that hosts
  58. // the DefView is safe. It's OK if they point to something unsafe, because they are
  59. // trusted.
  60. // 1. Third party app that supports IInternetHostSecurityManager have a chance to disallow the action.
  61. if (SUCCEEDED(IUnknown_QueryService(punkSite, IID_IInternetHostSecurityManager, IID_IInternetHostSecurityManager, (void**)&pihsm)))
  62. {
  63. if (S_OK != ZoneCheckHost(pihsm, dwAction, dwFlags))
  64. {
  65. // This zone is not OK or the user choose to not allow this to happen,
  66. // so cancel the operation.
  67. IsSafe = FALSE; // Turn off functionality.
  68. }
  69. pihsm->Release();
  70. }
  71. // 1. Hosted in DefView w/WebView. Zone of WebView can fail the action.
  72. if (IsSafe)
  73. {
  74. IOleCommandTarget * pct;
  75. if (SUCCEEDED(IUnknown_QueryService(punkSite, SID_DefView, IID_IOleCommandTarget, (void **)&pct)))
  76. {
  77. VARIANT vTemplatePath;
  78. vTemplatePath.vt = VT_EMPTY;
  79. if (pct->Exec(&CGID_DefView, DVCMDID_GETTEMPLATEDIRNAME, 0, NULL, &vTemplatePath) == S_OK)
  80. {
  81. if ((vTemplatePath.vt == VT_BSTR) && (S_OK != LocalZoneCheckPath(vTemplatePath.bstrVal, punkSite)))
  82. IsSafe = FALSE;
  83. // We were able to talk to the browser, so don't fall back on Trident because they may be
  84. // less secure.
  85. VariantClear(&vTemplatePath);
  86. }
  87. pct->Release();
  88. }
  89. }
  90. // 3. Hosted in HTML FRAME. Zone comes from trident can fail the action
  91. if (IsSafe)
  92. {
  93. // Try to use the URL from the document to zone check
  94. IHTMLDocument2 *pHtmlDoc;
  95. if (punkSite && SUCCEEDED(GetHTMLDoc2(punkSite, &pHtmlDoc)))
  96. {
  97. BSTR bstrPath;
  98. if (SUCCEEDED(pHtmlDoc->get_URL(&bstrPath)))
  99. {
  100. if (S_OK != ZoneCheckHost(pihsm, dwAction, dwFlags))
  101. {
  102. // This zone is not OK or the user choose to not allow this to happen,
  103. // so cancel the operation.
  104. IsSafe = FALSE; // Turn off functionality.
  105. }
  106. SysFreeString(bstrPath);
  107. }
  108. pHtmlDoc->Release();
  109. }
  110. }
  111. // 4. Hosted in DefView w/o WebView. Zone comes from pidl or pszUrl and that can fail the action.
  112. if (IsSafe)
  113. {
  114. IsSafe = ProcessUrlAction(punkSite, pszUrl, dwAction, dwFlags);
  115. }
  116. return IsSafe;
  117. }
  118. //*/
  119. BOOL ZoneCheckPidlAction(IUnknown * punkSite, DWORD dwAction, LPCITEMIDLIST pidl, DWORD dwFlags)
  120. {
  121. TCHAR szUrl[MAX_URL_STRING];
  122. if (FAILED(UrlCreateFromPidl(pidl, SHGDN_FORPARSING, szUrl, ARRAYSIZE(szUrl), (ICU_ESCAPE | ICU_USERNAME), FALSE)))
  123. return FALSE;
  124. return ZoneCheckUrlAction(punkSite, dwAction, szUrl, dwFlags);
  125. }