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.

491 lines
10 KiB

  1. // File: zonemgr.cxx
  2. //
  3. // Contents: Implementation of the IInternetZoneManager interface for basic (i.e. not
  4. // pluggable protocols with weird Urls)
  5. //
  6. // Classes: CUrlZoneManager
  7. //
  8. // Functions:
  9. //
  10. // History:
  11. //
  12. //----------------------------------------------------------------------------
  13. #include "zonepch.h"
  14. CRegZoneContainer* CUrlZoneManager::s_pRegZoneContainer = NULL;
  15. CRITICAL_SECTION CUrlZoneManager::s_csect;
  16. BOOL CUrlZoneManager::s_bcsectInit = FALSE;
  17. STDAPI
  18. InternetCreateZoneManager
  19. (
  20. IUnknown * pUnkOuter,
  21. REFIID riid,
  22. void **ppvObj,
  23. DWORD dwReserved
  24. )
  25. {
  26. HRESULT hr = S_OK;
  27. *ppvObj = NULL;
  28. if ( !IsZonesInitialized() )
  29. return E_UNEXPECTED;
  30. if (dwReserved != 0 || !ppvObj || (pUnkOuter && riid != IID_IUnknown))
  31. {
  32. // If the object has to be aggregated the caller can only ask
  33. // for an IUnknown back.
  34. hr = E_INVALIDARG;
  35. }
  36. else
  37. {
  38. CUrlZoneManager * pZoneMgr = new CUrlZoneManager(pUnkOuter, (IUnknown **)ppvObj);
  39. if ( pZoneMgr )
  40. {
  41. if (!pZoneMgr->Initialize())
  42. {
  43. hr = E_UNEXPECTED;
  44. }
  45. else
  46. {
  47. if (riid == IID_IUnknown || riid == IID_IInternetZoneManager)
  48. {
  49. // The correct pointer is in ppvObj
  50. *ppvObj = (IInternetZoneManager *)pZoneMgr;
  51. }
  52. else
  53. {
  54. hr = E_NOINTERFACE;
  55. }
  56. }
  57. }
  58. else
  59. {
  60. hr = E_OUTOFMEMORY;
  61. }
  62. }
  63. return hr;
  64. }
  65. CUrlZoneManager::CUrlZoneManager(IUnknown *pUnkOuter, IUnknown **ppUnkInner)
  66. {
  67. DllAddRef();
  68. m_pSP = NULL;
  69. if (!pUnkOuter)
  70. {
  71. pUnkOuter = &m_Unknown;
  72. }
  73. else
  74. {
  75. TransAssert(ppUnkInner);
  76. if (ppUnkInner)
  77. {
  78. *ppUnkInner = &m_Unknown;
  79. m_ref = 0;
  80. }
  81. }
  82. m_pUnkOuter = pUnkOuter;
  83. }
  84. CUrlZoneManager::~CUrlZoneManager()
  85. {
  86. DllRelease();
  87. }
  88. BOOL CUrlZoneManager::Initialize()
  89. {
  90. BOOL bReturn = TRUE;
  91. EnterCriticalSection(&s_csect);
  92. if (s_pRegZoneContainer == NULL)
  93. {
  94. // We want to defer the initialization of the shared memory section.
  95. // This is a convenient place since it is already guarded by a critical
  96. // section and this code has to be run before any caching related operations
  97. // happen. This should be done before the reg zones themselves are initialized
  98. // since they can call into the shared memory sections.
  99. g_SharedMem.Init(SM_SECTION_NAME, SM_SECTION_SIZE);
  100. // InitializeCriticalSection in the CRegZoneContainer constructor
  101. // can raise a STATUS_NO_MEMORY exception:
  102. __try
  103. {
  104. s_pRegZoneContainer = new CRegZoneContainer();
  105. }
  106. __except(EXCEPTION_EXECUTE_HANDLER)
  107. {
  108. s_pRegZoneContainer = NULL; // Just in case
  109. }
  110. if (s_pRegZoneContainer == NULL )
  111. {
  112. bReturn = FALSE; // We are hosed.
  113. }
  114. else if (!s_pRegZoneContainer->Attach(g_bUseHKLMOnly))
  115. {
  116. bReturn = FALSE;
  117. }
  118. }
  119. LeaveCriticalSection(&s_csect);
  120. return bReturn;
  121. }
  122. STDMETHODIMP CUrlZoneManager::CPrivUnknown::QueryInterface(REFIID riid, void** ppvObj)
  123. {
  124. HRESULT hr = S_OK;
  125. *ppvObj = NULL;
  126. CUrlZoneManager * pUrlZoneManager = GETPPARENT(this, CUrlZoneManager, m_Unknown);
  127. if (riid == IID_IUnknown || riid == IID_IInternetZoneManager)
  128. {
  129. *ppvObj = (IInternetZoneManager *)pUrlZoneManager;
  130. pUrlZoneManager->AddRef();
  131. }
  132. else
  133. {
  134. hr = E_NOINTERFACE;
  135. }
  136. return hr;
  137. }
  138. STDMETHODIMP_(ULONG) CUrlZoneManager::CPrivUnknown::AddRef()
  139. {
  140. LONG lRet = ++m_ref;
  141. return lRet;
  142. }
  143. STDMETHODIMP_(ULONG) CUrlZoneManager::CPrivUnknown::Release()
  144. {
  145. CUrlZoneManager *pUrlZoneManager = GETPPARENT(this, CUrlZoneManager, m_Unknown);
  146. LONG lRet = --m_ref;
  147. if (lRet == 0)
  148. {
  149. delete pUrlZoneManager;
  150. }
  151. return lRet;
  152. }
  153. // IUnknown methods.
  154. STDMETHODIMP CUrlZoneManager::QueryInterface(REFIID riid, void **ppvObj)
  155. {
  156. *ppvObj = NULL;
  157. if (riid == IID_IUnknown || riid == IID_IInternetZoneManager)
  158. {
  159. *ppvObj = (IInternetZoneManager *)this;
  160. }
  161. if (*ppvObj != NULL)
  162. {
  163. ((IUnknown *)*ppvObj)->AddRef();
  164. return S_OK;
  165. }
  166. return E_NOINTERFACE;
  167. }
  168. STDMETHODIMP_(ULONG) CUrlZoneManager::AddRef()
  169. {
  170. LONG lRet = m_pUnkOuter->AddRef();
  171. return lRet;
  172. }
  173. STDMETHODIMP_(ULONG) CUrlZoneManager::Release()
  174. {
  175. LONG lRet = m_pUnkOuter->Release();
  176. // Controlling Unknown will delete the object if reqd.
  177. return lRet;
  178. }
  179. // The IInternetZoneManager methods
  180. HRESULT
  181. CUrlZoneManager::GetZoneAttributes
  182. (
  183. DWORD dwZone,
  184. ZONEATTRIBUTES *pZoneAttributes
  185. )
  186. {
  187. if (pZoneAttributes == NULL /* || !IsZoneValid(dwZone) */)
  188. {
  189. return E_INVALIDARG;
  190. }
  191. CRegZone *pRegZone = GetRegZoneById(dwZone);
  192. if (pRegZone != NULL)
  193. {
  194. return pRegZone->GetZoneAttributes(*pZoneAttributes);
  195. }
  196. return E_FAIL;
  197. }
  198. HRESULT
  199. CUrlZoneManager::SetZoneAttributes
  200. (
  201. DWORD dwZone,
  202. ZONEATTRIBUTES *pZoneAttributes
  203. )
  204. {
  205. if (pZoneAttributes == NULL /* || !IsZoneValid(dwZone) */)
  206. {
  207. return E_INVALIDARG;
  208. }
  209. CRegZone *pRegZone = GetRegZoneById(dwZone);
  210. if (pRegZone != NULL)
  211. {
  212. return (pRegZone->SetZoneAttributes(*pZoneAttributes));
  213. }
  214. return E_FAIL;
  215. }
  216. HRESULT
  217. CUrlZoneManager::GetZoneCustomPolicy
  218. (
  219. DWORD dwZone,
  220. REFGUID guidKey,
  221. BYTE **ppPolicy,
  222. DWORD *pcbPolicy,
  223. URLZONEREG urlZoneReg
  224. )
  225. {
  226. if (ppPolicy == NULL || pcbPolicy == NULL)
  227. {
  228. return E_INVALIDARG;
  229. }
  230. CRegZone *pRegZone = GetRegZoneById(dwZone);
  231. if (pRegZone == NULL)
  232. {
  233. return E_INVALIDARG; // Could be messed up registry here.
  234. }
  235. return (pRegZone->GetCustomPolicy(guidKey, urlZoneReg, ppPolicy, pcbPolicy));
  236. }
  237. HRESULT
  238. CUrlZoneManager::SetZoneCustomPolicy
  239. (
  240. DWORD dwZone,
  241. REFGUID guidKey,
  242. BYTE *pPolicy,
  243. DWORD cbPolicy,
  244. URLZONEREG urlZoneReg
  245. )
  246. {
  247. if (pPolicy == NULL )
  248. {
  249. return E_INVALIDARG;
  250. }
  251. CRegZone *pRegZone = GetRegZoneById(dwZone);
  252. if (pRegZone == NULL)
  253. {
  254. return E_INVALIDARG;
  255. }
  256. return (pRegZone->SetCustomPolicy(guidKey, urlZoneReg, pPolicy, cbPolicy));
  257. }
  258. HRESULT
  259. CUrlZoneManager::GetZoneActionPolicy
  260. (
  261. DWORD dwZone,
  262. DWORD dwAction,
  263. BYTE* pPolicy,
  264. DWORD cbPolicy,
  265. URLZONEREG urlZoneReg
  266. )
  267. {
  268. if (pPolicy == NULL || cbPolicy < sizeof(DWORD))
  269. {
  270. return E_INVALIDARG;
  271. }
  272. CRegZone *pRegZone = GetRegZoneById(dwZone);
  273. if (pRegZone == NULL)
  274. {
  275. return E_INVALIDARG; // Could be messed up registry here.
  276. }
  277. return (pRegZone->GetActionPolicy(dwAction, urlZoneReg, *((DWORD *)pPolicy)));
  278. }
  279. HRESULT
  280. CUrlZoneManager::SetZoneActionPolicy
  281. (
  282. DWORD dwZone,
  283. DWORD dwAction,
  284. BYTE* pPolicy,
  285. DWORD cbPolicy,
  286. URLZONEREG urlZoneReg
  287. )
  288. {
  289. if (pPolicy == NULL || cbPolicy != sizeof(DWORD))
  290. {
  291. return E_INVALIDARG;
  292. }
  293. CRegZone *pRegZone = GetRegZoneById(dwZone);
  294. if (pRegZone == NULL)
  295. {
  296. return E_INVALIDARG; // Could be messed up registry here.
  297. }
  298. return (pRegZone->SetActionPolicy(dwAction, urlZoneReg, *((DWORD *)pPolicy)));
  299. }
  300. // Actions that are actually carried out by the Zone Manager.
  301. HRESULT
  302. CUrlZoneManager::PromptAction
  303. (
  304. DWORD dwAction,
  305. HWND hwndParent,
  306. LPCWSTR pwszUrl,
  307. LPCWSTR pwszText,
  308. DWORD dwPromptFlags
  309. )
  310. {
  311. return E_NOTIMPL;
  312. }
  313. HRESULT
  314. CUrlZoneManager::LogAction
  315. (
  316. DWORD dwAction,
  317. LPCWSTR pwszUrl,
  318. LPCWSTR pwszText,
  319. DWORD dwLogFlags
  320. )
  321. {
  322. return E_NOTIMPL;
  323. }
  324. // Zone enumerations
  325. // This is really convoluted. These functions don't belong to the CUrlZoneManager but
  326. // really to the collection of zones. To support this we remember the pointer to the container
  327. // that created us and delegate these functions on.
  328. HRESULT
  329. CUrlZoneManager::CreateZoneEnumerator
  330. (
  331. DWORD* pdwEnum,
  332. DWORD* pdwCount,
  333. DWORD dwFlags
  334. )
  335. {
  336. if (dwFlags != 0)
  337. return E_INVALIDARG;
  338. if (s_pRegZoneContainer != NULL)
  339. {
  340. return s_pRegZoneContainer->CreateZoneEnumerator(pdwEnum, pdwCount);
  341. }
  342. else
  343. {
  344. TransAssert(FALSE);
  345. return E_FAIL;
  346. }
  347. }
  348. HRESULT
  349. CUrlZoneManager::GetZoneAt
  350. (
  351. DWORD dwEnum,
  352. DWORD dwIndex,
  353. DWORD *pdwZone
  354. )
  355. {
  356. if (s_pRegZoneContainer != NULL)
  357. {
  358. return s_pRegZoneContainer->GetZoneAt(dwEnum, dwIndex, pdwZone);
  359. }
  360. else
  361. {
  362. TransAssert(FALSE);
  363. return E_FAIL;
  364. }
  365. }
  366. HRESULT
  367. CUrlZoneManager::DestroyZoneEnumerator
  368. (
  369. DWORD dwEnum
  370. )
  371. {
  372. if (s_pRegZoneContainer != NULL)
  373. {
  374. return s_pRegZoneContainer->DestroyZoneEnumerator(dwEnum);
  375. }
  376. else
  377. {
  378. TransAssert(FALSE);
  379. return E_FAIL;
  380. }
  381. }
  382. HRESULT
  383. CUrlZoneManager::CopyTemplatePoliciesToZone
  384. (
  385. DWORD dwTemplate,
  386. DWORD dwZone,
  387. DWORD dwReserved
  388. )
  389. {
  390. if (URLTEMPLATE_PREDEFINED_MIN > dwTemplate || URLTEMPLATE_PREDEFINED_MAX < dwTemplate)
  391. return E_INVALIDARG;
  392. CRegZone *pRegZone = GetRegZoneById(dwZone);
  393. if (pRegZone == NULL)
  394. {
  395. return E_INVALIDARG; // Could be messed up registry here.
  396. }
  397. return (pRegZone->CopyTemplatePolicies(dwTemplate));
  398. }