2 * Internet Security and Zone Manager
4 * Copyright (c) 2004 Huw D M Davies
5 * Copyright 2004 Jacek Caban
6 * Copyright 2009 Detlef Riekenberg
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
25 #include "urlmon_main.h"
29 #define NO_SHLWAPI_REG
32 #include "wine/debug.h"
34 WINE_DEFAULT_DEBUG_CHANNEL(urlmon);
36 static const WCHAR currentlevelW[] = {'C','u','r','r','e','n','t','L','e','v','e','l',0};
37 static const WCHAR descriptionW[] = {'D','e','s','c','r','i','p','t','i','o','n',0};
38 static const WCHAR displaynameW[] = {'D','i','s','p','l','a','y','N','a','m','e',0};
39 static const WCHAR fileW[] = {'f','i','l','e',0};
40 static const WCHAR flagsW[] = {'F','l','a','g','s',0};
41 static const WCHAR iconW[] = {'I','c','o','n',0};
42 static const WCHAR minlevelW[] = {'M','i','n','L','e','v','e','l',0};
43 static const WCHAR recommendedlevelW[] = {'R','e','c','o','m','m','e','n','d','e','d',
44 'L','e','v','e','l',0};
45 static const WCHAR wszZonesKey[] = {'S','o','f','t','w','a','r','e','\\',
46 'M','i','c','r','o','s','o','f','t','\\',
47 'W','i','n','d','o','w','s','\\',
48 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
49 'I','n','t','e','r','n','e','t',' ','S','e','t','t','i','n','g','s','\\',
50 'Z','o','n','e','s','\\',0};
52 /********************************************************************
53 * get_string_from_reg [internal]
55 * helper to get a string from the reg.
58 static void get_string_from_reg(HKEY hcu, HKEY hklm, LPCWSTR name, LPWSTR out, DWORD maxlen)
61 DWORD len = maxlen * sizeof(WCHAR);
64 res = RegQueryValueExW(hcu, name, NULL, &type, (LPBYTE) out, &len);
67 len = maxlen * sizeof(WCHAR);
69 res = RegQueryValueExW(hklm, name, NULL, &type, (LPBYTE) out, &len);
73 TRACE("%s failed: %d\n", debugstr_w(name), res);
78 /********************************************************************
79 * get_dword_from_reg [internal]
81 * helper to get a dword from the reg.
84 static void get_dword_from_reg(HKEY hcu, HKEY hklm, LPCWSTR name, LPDWORD out)
86 DWORD type = REG_DWORD;
87 DWORD len = sizeof(DWORD);
90 res = RegQueryValueExW(hcu, name, NULL, &type, (LPBYTE) out, &len);
95 res = RegQueryValueExW(hklm, name, NULL, &type, (LPBYTE) out, &len);
99 TRACE("%s failed: %d\n", debugstr_w(name), res);
104 static HRESULT get_zone_from_reg(LPCWSTR schema, DWORD *zone)
109 static const WCHAR wszZoneMapProtocolKey[] =
110 {'S','o','f','t','w','a','r','e','\\',
111 'M','i','c','r','o','s','o','f','t','\\',
112 'W','i','n','d','o','w','s','\\',
113 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
114 'I','n','t','e','r','n','e','t',' ','S','e','t','t','i','n','g','s','\\',
115 'Z','o','n','e','M','a','p','\\',
116 'P','r','o','t','o','c','o','l','D','e','f','a','u','l','t','s',0};
118 res = RegOpenKeyW(HKEY_CURRENT_USER, wszZoneMapProtocolKey, &hkey);
119 if(res != ERROR_SUCCESS) {
120 ERR("Could not open key %s\n", debugstr_w(wszZoneMapProtocolKey));
124 size = sizeof(DWORD);
125 res = RegQueryValueExW(hkey, schema, NULL, NULL, (PBYTE)zone, &size);
127 if(res == ERROR_SUCCESS)
130 res = RegOpenKeyW(HKEY_LOCAL_MACHINE, wszZoneMapProtocolKey, &hkey);
131 if(res != ERROR_SUCCESS) {
132 ERR("Could not open key %s\n", debugstr_w(wszZoneMapProtocolKey));
136 size = sizeof(DWORD);
137 res = RegQueryValueExW(hkey, schema, NULL, NULL, (PBYTE)zone, &size);
139 if(res == ERROR_SUCCESS)
146 static HRESULT map_url_to_zone(LPCWSTR url, DWORD *zone, LPWSTR *ret_url)
153 *zone = URLZONE_INVALID;
155 hres = CoInternetGetSecurityUrl(url, &secur_url, PSU_SECURITY_URL_ONLY, 0);
157 size = strlenW(url)*sizeof(WCHAR);
159 secur_url = heap_alloc(size);
161 return E_OUTOFMEMORY;
163 memcpy(secur_url, url, size);
166 hres = CoInternetParseUrl(secur_url, PARSE_SCHEMA, 0, schema, sizeof(schema)/sizeof(WCHAR), &size, 0);
167 if(FAILED(hres) || !*schema) {
168 heap_free(secur_url);
172 /* file protocol is a special case */
173 if(!strcmpW(schema, fileW)) {
174 WCHAR path[MAX_PATH], root[20];
177 hres = CoInternetParseUrl(secur_url, PARSE_PATH_FROM_URL, 0, path,
178 sizeof(path)/sizeof(WCHAR), &size, 0);
180 if(SUCCEEDED(hres) && (ptr = strchrW(path, '\\')) && ptr-path < sizeof(root)/sizeof(WCHAR)) {
183 memcpy(root, path, (ptr-path)*sizeof(WCHAR));
186 type = GetDriveTypeW(root);
190 case DRIVE_NO_ROOT_DIR:
192 case DRIVE_REMOVABLE:
196 *zone = URLZONE_LOCAL_MACHINE;
200 *zone = URLZONE_INTERNET;
204 FIXME("unsupported drive type %d\n", type);
209 if(*zone == URLZONE_INVALID) {
210 WARN("domains are not yet implemented\n");
211 hres = get_zone_from_reg(schema, zone);
214 if(FAILED(hres) || !ret_url)
215 heap_free(secur_url);
217 *ret_url = secur_url;
222 static HRESULT open_zone_key(HKEY parent_key, DWORD zone, HKEY *hkey)
224 static const WCHAR wszFormat[] = {'%','s','%','u',0};
226 WCHAR key_name[sizeof(wszZonesKey)/sizeof(WCHAR)+12];
229 wsprintfW(key_name, wszFormat, wszZonesKey, zone);
231 res = RegOpenKeyW(parent_key, key_name, hkey);
233 if(res != ERROR_SUCCESS) {
234 WARN("RegOpenKey failed\n");
241 static HRESULT get_action_policy(DWORD zone, DWORD action, BYTE *policy, DWORD size, URLZONEREG zone_reg)
249 case URLACTION_SCRIPT_OVERRIDE_SAFETY:
250 case URLACTION_ACTIVEX_OVERRIDE_SCRIPT_SAFETY:
251 *(DWORD*)policy = URLPOLICY_DISALLOW;
256 case URLZONEREG_DEFAULT:
257 case URLZONEREG_HKCU:
258 parent_key = HKEY_CURRENT_USER;
260 case URLZONEREG_HKLM:
261 parent_key = HKEY_LOCAL_MACHINE;
264 WARN("Unknown URLZONEREG: %d\n", zone_reg);
268 hres = open_zone_key(parent_key, zone, &hkey);
269 if(SUCCEEDED(hres)) {
270 WCHAR action_str[16];
273 static const WCHAR formatW[] = {'%','X',0};
275 wsprintfW(action_str, formatW, action);
277 res = RegQueryValueExW(hkey, action_str, NULL, NULL, policy, &len);
278 if(res == ERROR_MORE_DATA) {
280 }else if(res == ERROR_FILE_NOT_FOUND) {
282 }else if(res != ERROR_SUCCESS) {
283 ERR("RegQueryValue failed: %d\n", res);
290 if(FAILED(hres) && zone_reg == URLZONEREG_DEFAULT)
291 return get_action_policy(zone, action, policy, size, URLZONEREG_HKLM);
296 /***********************************************************************
297 * InternetSecurityManager implementation
301 IInternetSecurityManager IInternetSecurityManager_iface;
305 IInternetSecurityMgrSite *mgrsite;
306 IInternetSecurityManager *custom_manager;
309 static inline SecManagerImpl *impl_from_IInternetSecurityManager(IInternetSecurityManager *iface)
311 return CONTAINING_RECORD(iface, SecManagerImpl, IInternetSecurityManager_iface);
314 static HRESULT WINAPI SecManagerImpl_QueryInterface(IInternetSecurityManager* iface,REFIID riid,void** ppvObject)
316 SecManagerImpl *This = impl_from_IInternetSecurityManager(iface);
318 TRACE("(%p)->(%s,%p)\n",This,debugstr_guid(riid),ppvObject);
320 /* Perform a sanity check on the parameters.*/
321 if ( (This==0) || (ppvObject==0) )
324 /* Initialize the return parameter */
327 /* Compare the riid with the interface IDs implemented by this object.*/
328 if (IsEqualIID(&IID_IUnknown, riid) ||
329 IsEqualIID(&IID_IInternetSecurityManager, riid))
332 /* Check that we obtained an interface.*/
334 WARN("not supported interface %s\n", debugstr_guid(riid));
335 return E_NOINTERFACE;
338 /* Query Interface always increases the reference count by one when it is successful */
339 IInternetSecurityManager_AddRef(iface);
344 static ULONG WINAPI SecManagerImpl_AddRef(IInternetSecurityManager* iface)
346 SecManagerImpl *This = impl_from_IInternetSecurityManager(iface);
347 ULONG refCount = InterlockedIncrement(&This->ref);
349 TRACE("(%p) ref=%u\n", This, refCount);
354 static ULONG WINAPI SecManagerImpl_Release(IInternetSecurityManager* iface)
356 SecManagerImpl *This = impl_from_IInternetSecurityManager(iface);
357 ULONG refCount = InterlockedDecrement(&This->ref);
359 TRACE("(%p) ref=%u\n", This, refCount);
361 /* destroy the object if there's no more reference on it */
364 IInternetSecurityMgrSite_Release(This->mgrsite);
365 if(This->custom_manager)
366 IInternetSecurityManager_Release(This->custom_manager);
370 URLMON_UnlockModule();
376 static HRESULT WINAPI SecManagerImpl_SetSecuritySite(IInternetSecurityManager *iface,
377 IInternetSecurityMgrSite *pSite)
379 SecManagerImpl *This = impl_from_IInternetSecurityManager(iface);
381 TRACE("(%p)->(%p)\n", This, pSite);
384 IInternetSecurityMgrSite_Release(This->mgrsite);
386 if(This->custom_manager) {
387 IInternetSecurityManager_Release(This->custom_manager);
388 This->custom_manager = NULL;
391 This->mgrsite = pSite;
394 IServiceProvider *servprov;
397 IInternetSecurityMgrSite_AddRef(pSite);
399 hres = IInternetSecurityMgrSite_QueryInterface(pSite, &IID_IServiceProvider,
401 if(SUCCEEDED(hres)) {
402 IServiceProvider_QueryService(servprov, &SID_SInternetSecurityManager,
403 &IID_IInternetSecurityManager, (void**)&This->custom_manager);
404 IServiceProvider_Release(servprov);
411 static HRESULT WINAPI SecManagerImpl_GetSecuritySite(IInternetSecurityManager *iface,
412 IInternetSecurityMgrSite **ppSite)
414 SecManagerImpl *This = impl_from_IInternetSecurityManager(iface);
416 TRACE("(%p)->(%p)\n", This, ppSite);
422 IInternetSecurityMgrSite_AddRef(This->mgrsite);
424 *ppSite = This->mgrsite;
428 static HRESULT WINAPI SecManagerImpl_MapUrlToZone(IInternetSecurityManager *iface,
429 LPCWSTR pwszUrl, DWORD *pdwZone,
432 SecManagerImpl *This = impl_from_IInternetSecurityManager(iface);
435 TRACE("(%p)->(%s %p %08x)\n", iface, debugstr_w(pwszUrl), pdwZone, dwFlags);
437 if(This->custom_manager) {
438 hres = IInternetSecurityManager_MapUrlToZone(This->custom_manager,
439 pwszUrl, pdwZone, dwFlags);
440 if(hres != INET_E_DEFAULT_ACTION)
445 *pdwZone = URLZONE_INVALID;
450 FIXME("not supported flags: %08x\n", dwFlags);
452 return map_url_to_zone(pwszUrl, pdwZone, NULL);
455 static HRESULT WINAPI SecManagerImpl_GetSecurityId(IInternetSecurityManager *iface,
456 LPCWSTR pwszUrl, BYTE *pbSecurityId, DWORD *pcbSecurityId, DWORD_PTR dwReserved)
458 SecManagerImpl *This = impl_from_IInternetSecurityManager(iface);
459 LPWSTR url, ptr, ptr2;
463 static const WCHAR wszFile[] = {'f','i','l','e',':'};
465 TRACE("(%p)->(%s %p %p %08lx)\n", iface, debugstr_w(pwszUrl), pbSecurityId,
466 pcbSecurityId, dwReserved);
468 if(This->custom_manager) {
469 hres = IInternetSecurityManager_GetSecurityId(This->custom_manager,
470 pwszUrl, pbSecurityId, pcbSecurityId, dwReserved);
471 if(hres != INET_E_DEFAULT_ACTION)
475 if(!pwszUrl || !pbSecurityId || !pcbSecurityId)
479 FIXME("dwReserved is not supported\n");
481 hres = map_url_to_zone(pwszUrl, &zone, &url);
483 return hres == 0x80041001 ? E_INVALIDARG : hres;
485 /* file protocol is a special case */
486 if(strlenW(url) >= sizeof(wszFile)/sizeof(WCHAR)
487 && !memcmp(url, wszFile, sizeof(wszFile)) && strchrW(url, '\\')) {
489 static const BYTE secidFile[] = {'f','i','l','e',':'};
493 if(*pcbSecurityId < sizeof(secidFile)+sizeof(zone))
494 return HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER);
496 memcpy(pbSecurityId, secidFile, sizeof(secidFile));
497 *(DWORD*)(pbSecurityId+sizeof(secidFile)) = zone;
499 *pcbSecurityId = sizeof(secidFile)+sizeof(zone);
503 ptr = strchrW(url, ':');
508 memmove(ptr, ptr2, (strlenW(ptr2)+1)*sizeof(WCHAR));
510 ptr = strchrW(ptr, '/');
514 len = WideCharToMultiByte(CP_ACP, 0, url, -1, NULL, 0, NULL, NULL)-1;
516 if(len+sizeof(DWORD) > *pcbSecurityId) {
518 return HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER);
521 WideCharToMultiByte(CP_ACP, 0, url, -1, (LPSTR)pbSecurityId, len, NULL, NULL);
524 *(DWORD*)(pbSecurityId+len) = zone;
526 *pcbSecurityId = len+sizeof(DWORD);
532 static HRESULT WINAPI SecManagerImpl_ProcessUrlAction(IInternetSecurityManager *iface,
533 LPCWSTR pwszUrl, DWORD dwAction,
534 BYTE *pPolicy, DWORD cbPolicy,
535 BYTE *pContext, DWORD cbContext,
536 DWORD dwFlags, DWORD dwReserved)
538 SecManagerImpl *This = impl_from_IInternetSecurityManager(iface);
542 TRACE("(%p)->(%s %08x %p %08x %p %08x %08x %08x)\n", iface, debugstr_w(pwszUrl), dwAction,
543 pPolicy, cbPolicy, pContext, cbContext, dwFlags, dwReserved);
545 if(This->custom_manager) {
546 hres = IInternetSecurityManager_ProcessUrlAction(This->custom_manager, pwszUrl, dwAction,
547 pPolicy, cbPolicy, pContext, cbContext, dwFlags, dwReserved);
548 if(hres != INET_E_DEFAULT_ACTION)
552 if(dwFlags || dwReserved)
553 FIXME("Unsupported arguments\n");
558 hres = map_url_to_zone(pwszUrl, &zone, NULL);
562 hres = get_action_policy(zone, dwAction, (BYTE*)&policy, sizeof(policy), URLZONEREG_DEFAULT);
566 TRACE("policy %x\n", policy);
567 if(cbPolicy >= sizeof(DWORD))
568 *(DWORD*)pPolicy = policy;
570 switch(GetUrlPolicyPermissions(policy)) {
571 case URLPOLICY_ALLOW:
572 case URLPOLICY_CHANNEL_SOFTDIST_PRECACHE:
574 case URLPOLICY_DISALLOW:
576 case URLPOLICY_QUERY:
577 FIXME("URLPOLICY_QUERY not implemented\n");
580 FIXME("Not implemented policy %x\n", policy);
587 static HRESULT WINAPI SecManagerImpl_QueryCustomPolicy(IInternetSecurityManager *iface,
588 LPCWSTR pwszUrl, REFGUID guidKey,
589 BYTE **ppPolicy, DWORD *pcbPolicy,
590 BYTE *pContext, DWORD cbContext,
593 SecManagerImpl *This = impl_from_IInternetSecurityManager(iface);
596 TRACE("(%p)->(%s %s %p %p %p %08x %08x )\n", iface, debugstr_w(pwszUrl), debugstr_guid(guidKey),
597 ppPolicy, pcbPolicy, pContext, cbContext, dwReserved);
599 if(This->custom_manager) {
600 hres = IInternetSecurityManager_QueryCustomPolicy(This->custom_manager, pwszUrl, guidKey,
601 ppPolicy, pcbPolicy, pContext, cbContext, dwReserved);
602 if(hres != INET_E_DEFAULT_ACTION)
606 WARN("Unknown guidKey %s\n", debugstr_guid(guidKey));
607 return HRESULT_FROM_WIN32(ERROR_NOT_FOUND);
610 static HRESULT WINAPI SecManagerImpl_SetZoneMapping(IInternetSecurityManager *iface,
611 DWORD dwZone, LPCWSTR pwszPattern, DWORD dwFlags)
613 SecManagerImpl *This = impl_from_IInternetSecurityManager(iface);
616 TRACE("(%p)->(%08x %s %08x)\n", iface, dwZone, debugstr_w(pwszPattern),dwFlags);
618 if(This->custom_manager) {
619 hres = IInternetSecurityManager_SetZoneMapping(This->custom_manager, dwZone,
620 pwszPattern, dwFlags);
621 if(hres != INET_E_DEFAULT_ACTION)
625 FIXME("Default action is not implemented\n");
629 static HRESULT WINAPI SecManagerImpl_GetZoneMappings(IInternetSecurityManager *iface,
630 DWORD dwZone, IEnumString **ppenumString, DWORD dwFlags)
632 SecManagerImpl *This = impl_from_IInternetSecurityManager(iface);
635 TRACE("(%p)->(%08x %p %08x)\n", iface, dwZone, ppenumString,dwFlags);
637 if(This->custom_manager) {
638 hres = IInternetSecurityManager_GetZoneMappings(This->custom_manager, dwZone,
639 ppenumString, dwFlags);
640 if(hres != INET_E_DEFAULT_ACTION)
644 FIXME("Default action is not implemented\n");
648 static const IInternetSecurityManagerVtbl VT_SecManagerImpl =
650 SecManagerImpl_QueryInterface,
651 SecManagerImpl_AddRef,
652 SecManagerImpl_Release,
653 SecManagerImpl_SetSecuritySite,
654 SecManagerImpl_GetSecuritySite,
655 SecManagerImpl_MapUrlToZone,
656 SecManagerImpl_GetSecurityId,
657 SecManagerImpl_ProcessUrlAction,
658 SecManagerImpl_QueryCustomPolicy,
659 SecManagerImpl_SetZoneMapping,
660 SecManagerImpl_GetZoneMappings
663 HRESULT SecManagerImpl_Construct(IUnknown *pUnkOuter, LPVOID *ppobj)
665 SecManagerImpl *This;
667 TRACE("(%p,%p)\n",pUnkOuter,ppobj);
668 This = heap_alloc(sizeof(*This));
670 /* Initialize the virtual function table. */
671 This->IInternetSecurityManager_iface.lpVtbl = &VT_SecManagerImpl;
674 This->mgrsite = NULL;
675 This->custom_manager = NULL;
684 /***********************************************************************
685 * InternetZoneManager implementation
689 IInternetZoneManagerEx2 IInternetZoneManagerEx2_iface;
695 static inline ZoneMgrImpl *impl_from_IInternetZoneManagerEx2(IInternetZoneManagerEx2 *iface)
697 return CONTAINING_RECORD(iface, ZoneMgrImpl, IInternetZoneManagerEx2_iface);
701 /***********************************************************************
702 * build_zonemap_from_reg [internal]
704 * Enumerate the Zones in the Registry and return the Zones in a DWORD-array
705 * The number of the Zones is returned in data[0]
707 static LPDWORD build_zonemap_from_reg(void)
712 DWORD allocated = 6; /* space for the zonecount and Zone "0" up to Zone "4" */
718 res = RegOpenKeyW(HKEY_CURRENT_USER, wszZonesKey, &hkey);
722 data = heap_alloc(allocated * sizeof(DWORD));
728 len = sizeof(name) / sizeof(name[0]);
729 res = RegEnumKeyExW(hkey, used, name, &len, NULL, NULL, NULL, NULL);
733 if (used == allocated) {
737 new_data = heap_realloc_zero(data, allocated * sizeof(DWORD));
743 data[used] = atoiW(name);
753 /* something failed */
759 /********************************************************************
760 * IInternetZoneManager_QueryInterface
762 static HRESULT WINAPI ZoneMgrImpl_QueryInterface(IInternetZoneManagerEx2* iface, REFIID riid, void** ppvObject)
764 ZoneMgrImpl* This = impl_from_IInternetZoneManagerEx2(iface);
766 TRACE("(%p)->(%s,%p)\n", This, debugstr_guid(riid), ppvObject);
768 if(!This || !ppvObject)
771 if(IsEqualIID(&IID_IUnknown, riid)) {
772 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppvObject);
773 }else if(IsEqualIID(&IID_IInternetZoneManager, riid)) {
774 TRACE("(%p)->(IID_InternetZoneManager %p)\n", This, ppvObject);
775 }else if(IsEqualIID(&IID_IInternetZoneManagerEx, riid)) {
776 TRACE("(%p)->(IID_InternetZoneManagerEx %p)\n", This, ppvObject);
777 }else if(IsEqualIID(&IID_IInternetZoneManagerEx2, riid)) {
778 TRACE("(%p)->(IID_InternetZoneManagerEx2 %p)\n", This, ppvObject);
782 FIXME("Unknown interface: %s\n", debugstr_guid(riid));
784 return E_NOINTERFACE;
788 IInternetZoneManager_AddRef(iface);
792 /********************************************************************
793 * IInternetZoneManager_AddRef
795 static ULONG WINAPI ZoneMgrImpl_AddRef(IInternetZoneManagerEx2* iface)
797 ZoneMgrImpl* This = impl_from_IInternetZoneManagerEx2(iface);
798 ULONG refCount = InterlockedIncrement(&This->ref);
800 TRACE("(%p)->(ref before=%u)\n",This, refCount - 1);
805 /********************************************************************
806 * IInternetZoneManager_Release
808 static ULONG WINAPI ZoneMgrImpl_Release(IInternetZoneManagerEx2* iface)
810 ZoneMgrImpl* This = impl_from_IInternetZoneManagerEx2(iface);
811 ULONG refCount = InterlockedDecrement(&This->ref);
813 TRACE("(%p)->(ref before=%u)\n",This, refCount + 1);
816 while (This->zonemap_count) heap_free(This->zonemaps[--This->zonemap_count]);
817 heap_free(This->zonemaps);
819 URLMON_UnlockModule();
825 /********************************************************************
826 * IInternetZoneManager_GetZoneAttributes
828 static HRESULT WINAPI ZoneMgrImpl_GetZoneAttributes(IInternetZoneManagerEx2* iface,
830 ZONEATTRIBUTES* pZoneAttributes)
832 ZoneMgrImpl* This = impl_from_IInternetZoneManagerEx2(iface);
837 TRACE("(%p)->(%d %p)\n", This, dwZone, pZoneAttributes);
839 if (!pZoneAttributes)
842 hr = open_zone_key(HKEY_CURRENT_USER, dwZone, &hcu);
844 return S_OK; /* IE6 and older returned E_FAIL here */
846 hr = open_zone_key(HKEY_LOCAL_MACHINE, dwZone, &hklm);
848 TRACE("Zone %d not in HKLM\n", dwZone);
850 get_string_from_reg(hcu, hklm, displaynameW, pZoneAttributes->szDisplayName, MAX_ZONE_PATH);
851 get_string_from_reg(hcu, hklm, descriptionW, pZoneAttributes->szDescription, MAX_ZONE_DESCRIPTION);
852 get_string_from_reg(hcu, hklm, iconW, pZoneAttributes->szIconPath, MAX_ZONE_PATH);
853 get_dword_from_reg(hcu, hklm, minlevelW, &pZoneAttributes->dwTemplateMinLevel);
854 get_dword_from_reg(hcu, hklm, currentlevelW, &pZoneAttributes->dwTemplateCurrentLevel);
855 get_dword_from_reg(hcu, hklm, recommendedlevelW, &pZoneAttributes->dwTemplateRecommended);
856 get_dword_from_reg(hcu, hklm, flagsW, &pZoneAttributes->dwFlags);
863 /********************************************************************
864 * IInternetZoneManager_SetZoneAttributes
866 static HRESULT WINAPI ZoneMgrImpl_SetZoneAttributes(IInternetZoneManagerEx2* iface,
868 ZONEATTRIBUTES* pZoneAttributes)
870 FIXME("(%p)->(%08x %p) stub\n", iface, dwZone, pZoneAttributes);
874 /********************************************************************
875 * IInternetZoneManager_GetZoneCustomPolicy
877 static HRESULT WINAPI ZoneMgrImpl_GetZoneCustomPolicy(IInternetZoneManagerEx2* iface,
882 URLZONEREG ulrZoneReg)
884 FIXME("(%p)->(%08x %s %p %p %08x) stub\n", iface, dwZone, debugstr_guid(guidKey),
885 ppPolicy, pcbPolicy, ulrZoneReg);
889 /********************************************************************
890 * IInternetZoneManager_SetZoneCustomPolicy
892 static HRESULT WINAPI ZoneMgrImpl_SetZoneCustomPolicy(IInternetZoneManagerEx2* iface,
897 URLZONEREG ulrZoneReg)
899 FIXME("(%p)->(%08x %s %p %08x %08x) stub\n", iface, dwZone, debugstr_guid(guidKey),
900 ppPolicy, cbPolicy, ulrZoneReg);
904 /********************************************************************
905 * IInternetZoneManager_GetZoneActionPolicy
907 static HRESULT WINAPI ZoneMgrImpl_GetZoneActionPolicy(IInternetZoneManagerEx2* iface,
908 DWORD dwZone, DWORD dwAction, BYTE* pPolicy, DWORD cbPolicy, URLZONEREG urlZoneReg)
910 TRACE("(%p)->(%d %08x %p %d %d)\n", iface, dwZone, dwAction, pPolicy,
911 cbPolicy, urlZoneReg);
916 return get_action_policy(dwZone, dwAction, pPolicy, cbPolicy, urlZoneReg);
919 /********************************************************************
920 * IInternetZoneManager_SetZoneActionPolicy
922 static HRESULT WINAPI ZoneMgrImpl_SetZoneActionPolicy(IInternetZoneManagerEx2* iface,
927 URLZONEREG urlZoneReg)
929 FIXME("(%p)->(%08x %08x %p %08x %08x) stub\n", iface, dwZone, dwAction, pPolicy,
930 cbPolicy, urlZoneReg);
934 /********************************************************************
935 * IInternetZoneManager_PromptAction
937 static HRESULT WINAPI ZoneMgrImpl_PromptAction(IInternetZoneManagerEx2* iface,
944 FIXME("%p %08x %p %s %s %08x\n", iface, dwAction, hwndParent,
945 debugstr_w(pwszUrl), debugstr_w(pwszText), dwPromptFlags );
949 /********************************************************************
950 * IInternetZoneManager_LogAction
952 static HRESULT WINAPI ZoneMgrImpl_LogAction(IInternetZoneManagerEx2* iface,
958 FIXME("(%p)->(%08x %s %s %08x) stub\n", iface, dwAction, debugstr_w(pwszUrl),
959 debugstr_w(pwszText), dwLogFlags);
963 /********************************************************************
964 * IInternetZoneManager_CreateZoneEnumerator
966 static HRESULT WINAPI ZoneMgrImpl_CreateZoneEnumerator(IInternetZoneManagerEx2* iface,
971 ZoneMgrImpl* This = impl_from_IInternetZoneManagerEx2(iface);
976 TRACE("(%p)->(%p, %p, 0x%08x)\n", This, pdwEnum, pdwCount, dwFlags);
977 if (!pdwEnum || !pdwCount || (dwFlags != 0))
980 data = build_zonemap_from_reg();
981 TRACE("found %d zones\n", data ? data[0] : -1);
986 for (i = 0; i < This->zonemap_count; i++) {
987 if (This->zonemaps && !This->zonemaps[i]) {
988 This->zonemaps[i] = data;
995 if (This->zonemaps) {
996 /* try to double the nr. of pointers in the array */
997 new_maps = heap_realloc_zero(This->zonemaps, This->zonemap_count * 2 * sizeof(LPDWORD));
999 This->zonemap_count *= 2;
1003 This->zonemap_count = 2;
1004 new_maps = heap_alloc_zero(This->zonemap_count * sizeof(LPDWORD));
1011 This->zonemaps = new_maps;
1012 This->zonemaps[i] = data;
1014 *pdwCount = data[0];
1018 /********************************************************************
1019 * IInternetZoneManager_GetZoneAt
1021 static HRESULT WINAPI ZoneMgrImpl_GetZoneAt(IInternetZoneManagerEx2* iface,
1026 ZoneMgrImpl* This = impl_from_IInternetZoneManagerEx2(iface);
1029 TRACE("(%p)->(0x%08x, %d, %p)\n", This, dwEnum, dwIndex, pdwZone);
1031 /* make sure, that dwEnum and dwIndex are in the valid range */
1032 if (dwEnum < This->zonemap_count) {
1033 if ((data = This->zonemaps[dwEnum])) {
1034 if (dwIndex < data[0]) {
1035 *pdwZone = data[dwIndex + 1];
1040 return E_INVALIDARG;
1043 /********************************************************************
1044 * IInternetZoneManager_DestroyZoneEnumerator
1046 static HRESULT WINAPI ZoneMgrImpl_DestroyZoneEnumerator(IInternetZoneManagerEx2* iface,
1049 ZoneMgrImpl* This = impl_from_IInternetZoneManagerEx2(iface);
1052 TRACE("(%p)->(0x%08x)\n", This, dwEnum);
1053 /* make sure, that dwEnum is valid */
1054 if (dwEnum < This->zonemap_count) {
1055 if ((data = This->zonemaps[dwEnum])) {
1056 This->zonemaps[dwEnum] = NULL;
1061 return E_INVALIDARG;
1064 /********************************************************************
1065 * IInternetZoneManager_CopyTemplatePoliciesToZone
1067 static HRESULT WINAPI ZoneMgrImpl_CopyTemplatePoliciesToZone(IInternetZoneManagerEx2* iface,
1072 FIXME("(%p)->(%08x %08x %08x) stub\n", iface, dwTemplate, dwZone, dwReserved);
1076 /********************************************************************
1077 * IInternetZoneManagerEx_GetZoneActionPolicyEx
1079 static HRESULT WINAPI ZoneMgrImpl_GetZoneActionPolicyEx(IInternetZoneManagerEx2* iface,
1084 URLZONEREG urlZoneReg,
1087 TRACE("(%p)->(%d, 0x%x, %p, %d, %d, 0x%x)\n", iface, dwZone,
1088 dwAction, pPolicy, cbPolicy, urlZoneReg, dwFlags);
1091 return E_INVALIDARG;
1094 FIXME("dwFlags 0x%x ignored\n", dwFlags);
1096 return get_action_policy(dwZone, dwAction, pPolicy, cbPolicy, urlZoneReg);
1099 /********************************************************************
1100 * IInternetZoneManagerEx_SetZoneActionPolicyEx
1102 static HRESULT WINAPI ZoneMgrImpl_SetZoneActionPolicyEx(IInternetZoneManagerEx2* iface,
1107 URLZONEREG urlZoneReg,
1110 FIXME("(%p)->(%d, 0x%x, %p, %d, %d, 0x%x) stub\n", iface, dwZone, dwAction, pPolicy,
1111 cbPolicy, urlZoneReg, dwFlags);
1115 /********************************************************************
1116 * IInternetZoneManagerEx2_GetZoneAttributesEx
1118 static HRESULT WINAPI ZoneMgrImpl_GetZoneAttributesEx(IInternetZoneManagerEx2* iface,
1120 ZONEATTRIBUTES* pZoneAttributes,
1123 TRACE("(%p)->(%d, %p, 0x%x)\n", iface, dwZone, pZoneAttributes, dwFlags);
1126 FIXME("dwFlags 0x%x ignored\n", dwFlags);
1128 return IInternetZoneManager_GetZoneAttributes(iface, dwZone, pZoneAttributes);
1132 /********************************************************************
1133 * IInternetZoneManagerEx2_GetZoneSecurityState
1135 static HRESULT WINAPI ZoneMgrImpl_GetZoneSecurityState(IInternetZoneManagerEx2* iface,
1137 BOOL fRespectPolicy,
1139 BOOL *pfPolicyEncountered)
1141 FIXME("(%p)->(%d, %d, %p, %p) stub\n", iface, dwZoneIndex, fRespectPolicy,
1142 pdwState, pfPolicyEncountered);
1144 *pdwState = SECURITY_IE_STATE_GREEN;
1146 if (pfPolicyEncountered)
1147 *pfPolicyEncountered = FALSE;
1152 /********************************************************************
1153 * IInternetZoneManagerEx2_GetIESecurityState
1155 static HRESULT WINAPI ZoneMgrImpl_GetIESecurityState(IInternetZoneManagerEx2* iface,
1156 BOOL fRespectPolicy,
1158 BOOL *pfPolicyEncountered,
1161 FIXME("(%p)->(%d, %p, %p, %d) stub\n", iface, fRespectPolicy, pdwState,
1162 pfPolicyEncountered, fNoCache);
1164 *pdwState = SECURITY_IE_STATE_GREEN;
1166 if (pfPolicyEncountered)
1167 *pfPolicyEncountered = FALSE;
1172 /********************************************************************
1173 * IInternetZoneManagerEx2_FixInsecureSettings
1175 static HRESULT WINAPI ZoneMgrImpl_FixInsecureSettings(IInternetZoneManagerEx2* iface)
1177 FIXME("(%p) stub\n", iface);
1181 /********************************************************************
1182 * IInternetZoneManager_Construct
1184 static const IInternetZoneManagerEx2Vtbl ZoneMgrImplVtbl = {
1185 ZoneMgrImpl_QueryInterface,
1187 ZoneMgrImpl_Release,
1188 /* IInternetZoneManager */
1189 ZoneMgrImpl_GetZoneAttributes,
1190 ZoneMgrImpl_SetZoneAttributes,
1191 ZoneMgrImpl_GetZoneCustomPolicy,
1192 ZoneMgrImpl_SetZoneCustomPolicy,
1193 ZoneMgrImpl_GetZoneActionPolicy,
1194 ZoneMgrImpl_SetZoneActionPolicy,
1195 ZoneMgrImpl_PromptAction,
1196 ZoneMgrImpl_LogAction,
1197 ZoneMgrImpl_CreateZoneEnumerator,
1198 ZoneMgrImpl_GetZoneAt,
1199 ZoneMgrImpl_DestroyZoneEnumerator,
1200 ZoneMgrImpl_CopyTemplatePoliciesToZone,
1201 /* IInternetZoneManagerEx */
1202 ZoneMgrImpl_GetZoneActionPolicyEx,
1203 ZoneMgrImpl_SetZoneActionPolicyEx,
1204 /* IInternetZoneManagerEx2 */
1205 ZoneMgrImpl_GetZoneAttributesEx,
1206 ZoneMgrImpl_GetZoneSecurityState,
1207 ZoneMgrImpl_GetIESecurityState,
1208 ZoneMgrImpl_FixInsecureSettings,
1211 HRESULT ZoneMgrImpl_Construct(IUnknown *pUnkOuter, LPVOID *ppobj)
1213 ZoneMgrImpl* ret = heap_alloc_zero(sizeof(ZoneMgrImpl));
1215 TRACE("(%p %p)\n", pUnkOuter, ppobj);
1216 ret->IInternetZoneManagerEx2_iface.lpVtbl = &ZoneMgrImplVtbl;
1218 *ppobj = (IInternetZoneManagerEx*)ret;
1220 URLMON_LockModule();
1225 /***********************************************************************
1226 * CoInternetCreateSecurityManager (URLMON.@)
1229 HRESULT WINAPI CoInternetCreateSecurityManager( IServiceProvider *pSP,
1230 IInternetSecurityManager **ppSM, DWORD dwReserved )
1232 TRACE("%p %p %d\n", pSP, ppSM, dwReserved );
1235 FIXME("pSP not supported\n");
1237 return SecManagerImpl_Construct(NULL, (void**) ppSM);
1240 /********************************************************************
1241 * CoInternetCreateZoneManager (URLMON.@)
1243 HRESULT WINAPI CoInternetCreateZoneManager(IServiceProvider* pSP, IInternetZoneManager** ppZM, DWORD dwReserved)
1245 TRACE("(%p %p %x)\n", pSP, ppZM, dwReserved);
1246 return ZoneMgrImpl_Construct(NULL, (void**)ppZM);
1249 static HRESULT parse_security_url(const WCHAR *url, PSUACTION action, WCHAR **result) {
1250 IInternetProtocolInfo *protocol_info;
1251 WCHAR *tmp, *new_url = NULL, *alloc_url = NULL;
1252 DWORD size, new_size;
1253 HRESULT hres = S_OK, parse_hres;
1256 TRACE("parsing %s\n", debugstr_w(url));
1258 protocol_info = get_protocol_info(url);
1262 size = strlenW(url)+1;
1263 new_url = CoTaskMemAlloc(size*sizeof(WCHAR));
1265 hres = E_OUTOFMEMORY;
1270 parse_hres = IInternetProtocolInfo_ParseUrl(protocol_info, url, PARSE_SECURITY_URL, 0, new_url, size, &new_size, 0);
1271 if(parse_hres == S_FALSE) {
1273 hres = E_UNEXPECTED;
1277 tmp = CoTaskMemRealloc(new_url, new_size*sizeof(WCHAR));
1279 hres = E_OUTOFMEMORY;
1283 parse_hres = IInternetProtocolInfo_ParseUrl(protocol_info, url, PARSE_SECURITY_URL, 0, new_url,
1284 new_size, &new_size, 0);
1285 if(parse_hres == S_FALSE) {
1291 if(parse_hres != S_OK || !strcmpW(url, new_url))
1294 CoTaskMemFree(alloc_url);
1295 url = alloc_url = new_url;
1299 CoTaskMemFree(new_url);
1302 WARN("failed: %08x\n", hres);
1303 CoTaskMemFree(alloc_url);
1307 if(action == PSU_DEFAULT && (protocol_info = get_protocol_info(url))) {
1308 size = strlenW(url)+1;
1309 new_url = CoTaskMemAlloc(size * sizeof(WCHAR));
1312 parse_hres = IInternetProtocolInfo_ParseUrl(protocol_info, url, PARSE_SECURITY_DOMAIN, 0,
1313 new_url, size, &new_size, 0);
1314 if(parse_hres == S_FALSE) {
1316 tmp = CoTaskMemRealloc(new_url, new_size*sizeof(WCHAR));
1319 parse_hres = IInternetProtocolInfo_ParseUrl(protocol_info, url, PARSE_SECURITY_DOMAIN, 0, new_url,
1320 new_size, &new_size, 0);
1321 if(parse_hres == S_FALSE)
1324 hres = E_OUTOFMEMORY;
1327 hres = E_UNEXPECTED;
1331 if(hres == S_OK && parse_hres == S_OK) {
1332 CoTaskMemFree(alloc_url);
1333 url = alloc_url = new_url;
1337 CoTaskMemFree(new_url);
1339 hres = E_OUTOFMEMORY;
1341 IInternetProtocolInfo_Release(protocol_info);
1345 WARN("failed %08x\n", hres);
1346 CoTaskMemFree(alloc_url);
1351 size = strlenW(url)+1;
1352 alloc_url = CoTaskMemAlloc(size * sizeof(WCHAR));
1354 return E_OUTOFMEMORY;
1355 memcpy(alloc_url, url, size * sizeof(WCHAR));
1358 *result = alloc_url;
1362 /********************************************************************
1363 * CoInternetGetSecurityUrl (URLMON.@)
1365 HRESULT WINAPI CoInternetGetSecurityUrl(LPCWSTR pwzUrl, LPWSTR *ppwzSecUrl, PSUACTION psuAction, DWORD dwReserved)
1370 TRACE("(%p,%p,%u,%u)\n", pwzUrl, ppwzSecUrl, psuAction, dwReserved);
1372 hres = parse_security_url(pwzUrl, psuAction, &secure_url);
1376 if(psuAction != PSU_SECURITY_URL_ONLY) {
1377 PARSEDURLW parsed_url = { sizeof(parsed_url) };
1380 /* FIXME: Use helpers from uri.c */
1381 if(SUCCEEDED(ParseURLW(secure_url, &parsed_url))) {
1384 switch(parsed_url.nScheme) {
1385 case URL_SCHEME_FTP:
1386 case URL_SCHEME_HTTP:
1387 case URL_SCHEME_HTTPS:
1388 size = strlenW(secure_url)+1;
1389 new_url = CoTaskMemAlloc(size * sizeof(WCHAR));
1391 hres = UrlGetPartW(secure_url, new_url, &size, URL_PART_HOSTNAME, URL_PARTFLAG_KEEPSCHEME);
1393 hres = E_OUTOFMEMORY;
1394 CoTaskMemFree(secure_url);
1396 WARN("UrlGetPart failed: %08x\n", hres);
1397 CoTaskMemFree(new_url);
1398 return FAILED(hres) ? hres : E_FAIL;
1400 secure_url = new_url;
1405 *ppwzSecUrl = secure_url;
1409 /********************************************************************
1410 * CoInternetGetSecurityUrlEx (URLMON.@)
1412 HRESULT WINAPI CoInternetGetSecurityUrlEx(IUri *pUri, IUri **ppSecUri, PSUACTION psuAction, DWORD_PTR dwReserved)
1414 URL_SCHEME scheme_type;
1419 TRACE("(%p,%p,%u,%u)\n", pUri, ppSecUri, psuAction, (DWORD)dwReserved);
1421 if(!pUri || !ppSecUri)
1422 return E_INVALIDARG;
1424 hres = IUri_GetDisplayUri(pUri, &secure_uri);
1428 hres = parse_security_url(secure_uri, psuAction, &ret_url);
1429 SysFreeString(secure_uri);
1433 hres = CreateUri(ret_url, Uri_CREATE_ALLOW_IMPLICIT_WILDCARD_SCHEME, 0, ppSecUri);
1435 CoTaskMemFree(ret_url);
1439 /* File URIs have to hierarchical. */
1440 hres = IUri_GetScheme(pUri, (DWORD*)&scheme_type);
1441 if(SUCCEEDED(hres) && scheme_type == URL_SCHEME_FILE) {
1442 const WCHAR *tmp = ret_url;
1444 /* Check and see if a "//" is after the scheme name. */
1445 tmp += sizeof(fileW)/sizeof(WCHAR);
1446 if(*tmp != '/' || *(tmp+1) != '/')
1447 hres = E_INVALIDARG;
1451 hres = CreateUri(ret_url, Uri_CREATE_ALLOW_IMPLICIT_WILDCARD_SCHEME, 0, ppSecUri);
1452 CoTaskMemFree(ret_url);