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.

196 lines
4.6 KiB

  1. /******************************************************************************
  2. Copyright (c) 1999 Microsoft Corporation
  3. Module Name:
  4. SecurityManager.cpp
  5. Abstract:
  6. This file contains the implementation of the CSecurityManager class,
  7. which is used to control access to the Scripting Framework.
  8. Revision History:
  9. Davide Massarenti (dmassare) 08/07/99
  10. created
  11. ******************************************************************************/
  12. #include "stdafx.h"
  13. #include <MPC_logging.h>
  14. CPCHSecurityManager::CPCHSecurityManager()
  15. {
  16. m_parent = NULL; // CPCHHelpCenterExternal* m_parent;
  17. m_fActivated = false; // bool m_fActivated;
  18. }
  19. void CPCHSecurityManager::Initialize( /*[in]*/ CPCHHelpCenterExternal* parent )
  20. {
  21. m_parent = parent;
  22. }
  23. /////////////////////////////////////////////////////////////////////////////
  24. HRESULT CPCHSecurityManager::ActivateService()
  25. {
  26. __HCP_FUNC_ENTRY( "CPCHSecurityManager::ActivateService" );
  27. HRESULT hr;
  28. CComPtr<IPCHService> svc;
  29. __MPC_EXIT_IF_METHOD_FAILS(hr, svc.CoCreateInstance( CLSID_PCHService ));
  30. m_fActivated = (svc != NULL);
  31. hr = S_OK;
  32. __HCP_FUNC_CLEANUP;
  33. Thread_Abort();
  34. __HCP_FUNC_EXIT(hr);
  35. }
  36. /////////////////////////////////////////////////////////////////////////////
  37. bool CPCHSecurityManager::IsUrlTrusted( /*[in]*/ LPCWSTR pwszURL, /*[in]*/ bool *pfSystem )
  38. {
  39. bool fTrusted = false;
  40. MPC::wstring strUrlModified;
  41. MPC::wstring strVendor;
  42. CPCHWrapProtocolInfo::NormalizeUrl( pwszURL, strUrlModified, /*fReverse*/true );
  43. //
  44. // Don't try to use the store at first. It requires the service to be up and running...
  45. //
  46. (void)CPCHContentStore::s_GLOBAL->IsTrusted( strUrlModified.c_str(), fTrusted, NULL, false );
  47. if(fTrusted == false)
  48. {
  49. CPCHProxy_IPCHService* svc = m_parent->Service();
  50. //
  51. // Not a system page, we need to wake up the service...
  52. //
  53. if(m_fActivated == false)
  54. {
  55. if(SUCCEEDED(Thread_Start( this, ActivateService, NULL )))
  56. {
  57. Thread_Wait( /*fForce*/false, /*fNoMsg*/true );
  58. }
  59. }
  60. if(m_fActivated)
  61. {
  62. //
  63. // Get the trust status from the content store.
  64. //
  65. (void)CPCHContentStore::s_GLOBAL->IsTrusted( strUrlModified.c_str(), fTrusted, &strVendor );
  66. }
  67. }
  68. if(pfSystem)
  69. {
  70. *pfSystem = (fTrusted && strVendor.length() == 0);
  71. }
  72. return fTrusted;
  73. }
  74. /////////////////////////////////////////////////////////////////////////////
  75. STDMETHODIMP CPCHSecurityManager::QueryService( REFGUID guidService, REFIID riid, void **ppv )
  76. {
  77. HRESULT hr = E_NOINTERFACE;
  78. if(InlineIsEqualGUID( riid, IID_IInternetSecurityManager ))
  79. {
  80. hr = QueryInterface( riid, ppv );
  81. }
  82. return hr;
  83. }
  84. STDMETHODIMP CPCHSecurityManager::MapUrlToZone( /*[in] */ LPCWSTR pwszUrl ,
  85. /*[out]*/ DWORD *pdwZone ,
  86. /*[in] */ DWORD dwFlags )
  87. {
  88. HRESULT hr = INET_E_DEFAULT_ACTION;
  89. if(IsUrlTrusted( pwszUrl ))
  90. {
  91. if(pdwZone) *pdwZone = URLZONE_TRUSTED;
  92. hr = S_OK;
  93. }
  94. return hr;
  95. }
  96. STDMETHODIMP CPCHSecurityManager::ProcessUrlAction( /*[in] */ LPCWSTR pwszUrl ,
  97. /*[in] */ DWORD dwAction ,
  98. /*[out]*/ BYTE *pPolicy ,
  99. /*[in] */ DWORD cbPolicy ,
  100. /*[in] */ BYTE *pContext ,
  101. /*[in] */ DWORD cbContext ,
  102. /*[in] */ DWORD dwFlags ,
  103. /*[in] */ DWORD dwReserved )
  104. {
  105. HRESULT hr;
  106. bool fSystem;
  107. bool fTrusted;
  108. fTrusted = IsUrlTrusted( pwszUrl, &fSystem );
  109. if(fTrusted)
  110. {
  111. //
  112. // If the page is trusted but not a system page, we normally map it to the TRUSTED zone.
  113. // However, the default settings for the trusted zone is to prompt for ActiveX not marked
  114. // as safe for scripting. Since this is the case for most of our objects, we allow all of them.
  115. //
  116. // Also, we enable all the script-related actions.
  117. //
  118. if(fSystem == false)
  119. {
  120. fTrusted = false;
  121. if(dwAction >= URLACTION_ACTIVEX_MIN &&
  122. dwAction <= URLACTION_ACTIVEX_MAX )
  123. {
  124. fTrusted = true;
  125. }
  126. if(dwAction >= URLACTION_SCRIPT_MIN &&
  127. dwAction <= URLACTION_SCRIPT_MAX )
  128. {
  129. fTrusted = true;
  130. }
  131. }
  132. }
  133. if(fTrusted)
  134. {
  135. if(cbPolicy >= sizeof (DWORD))
  136. {
  137. *(DWORD *)pPolicy = URLPOLICY_ALLOW;
  138. hr = S_OK;
  139. }
  140. else
  141. {
  142. hr = S_FALSE;
  143. }
  144. }
  145. else
  146. {
  147. hr = INET_E_DEFAULT_ACTION;
  148. }
  149. return hr;
  150. }