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)
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:
204 FIXME("unsupported drive type %d\n", type);
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','%','l','d',0};
226 WCHAR key_name[sizeof(wszZonesKey)/sizeof(WCHAR)+8];
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 static HRESULT parse_security_uri(IUri *uri, PSUACTION action, IUri **result) {
297 WCHAR buf1[INTERNET_MAX_URL_LENGTH], buf2[INTERNET_MAX_URL_LENGTH];
301 BOOL use_url = FALSE;
307 hres = IUri_GetPropertyLength(uri, Uri_PROPERTY_ABSOLUTE_URI, &len, 0);
311 hres = CoInternetParseIUri(uri, PARSE_SECURITY_URL, 0, url, len+1, &len, 0);
315 hres = CoInternetParseUrl(url, PARSE_SECURITY_URL, 0, tmp, len+1, &len, 0);
316 if(hres != S_OK || !strcmpW(url, tmp))
329 if(action == PSU_DEFAULT) {
331 hres = CoInternetParseUrl(url, PARSE_SECURITY_DOMAIN, 0, tmp, len+1, &len, 0);
334 hres = CoInternetParseIUri(uri, PARSE_SECURITY_DOMAIN, 0, url, len+1, &len, 0);
341 hres = CreateUri(url, 0, 0, result);
349 /***********************************************************************
350 * InternetSecurityManager implementation
354 IInternetSecurityManager IInternetSecurityManager_iface;
358 IInternetSecurityMgrSite *mgrsite;
359 IInternetSecurityManager *custom_manager;
362 static inline SecManagerImpl *impl_from_IInternetSecurityManager(IInternetSecurityManager *iface)
364 return CONTAINING_RECORD(iface, SecManagerImpl, IInternetSecurityManager_iface);
367 static HRESULT WINAPI SecManagerImpl_QueryInterface(IInternetSecurityManager* iface,REFIID riid,void** ppvObject)
369 SecManagerImpl *This = impl_from_IInternetSecurityManager(iface);
371 TRACE("(%p)->(%s,%p)\n",This,debugstr_guid(riid),ppvObject);
373 /* Perform a sanity check on the parameters.*/
374 if ( (This==0) || (ppvObject==0) )
377 /* Initialize the return parameter */
380 /* Compare the riid with the interface IDs implemented by this object.*/
381 if (IsEqualIID(&IID_IUnknown, riid) ||
382 IsEqualIID(&IID_IInternetSecurityManager, riid))
385 /* Check that we obtained an interface.*/
387 WARN("not supported interface %s\n", debugstr_guid(riid));
388 return E_NOINTERFACE;
391 /* Query Interface always increases the reference count by one when it is successful */
392 IInternetSecurityManager_AddRef(iface);
397 static ULONG WINAPI SecManagerImpl_AddRef(IInternetSecurityManager* iface)
399 SecManagerImpl *This = impl_from_IInternetSecurityManager(iface);
400 ULONG refCount = InterlockedIncrement(&This->ref);
402 TRACE("(%p) ref=%u\n", This, refCount);
407 static ULONG WINAPI SecManagerImpl_Release(IInternetSecurityManager* iface)
409 SecManagerImpl *This = impl_from_IInternetSecurityManager(iface);
410 ULONG refCount = InterlockedDecrement(&This->ref);
412 TRACE("(%p) ref=%u\n", This, refCount);
414 /* destroy the object if there's no more reference on it */
417 IInternetSecurityMgrSite_Release(This->mgrsite);
418 if(This->custom_manager)
419 IInternetSecurityManager_Release(This->custom_manager);
423 URLMON_UnlockModule();
429 static HRESULT WINAPI SecManagerImpl_SetSecuritySite(IInternetSecurityManager *iface,
430 IInternetSecurityMgrSite *pSite)
432 SecManagerImpl *This = impl_from_IInternetSecurityManager(iface);
434 TRACE("(%p)->(%p)\n", This, pSite);
437 IInternetSecurityMgrSite_Release(This->mgrsite);
439 if(This->custom_manager) {
440 IInternetSecurityManager_Release(This->custom_manager);
441 This->custom_manager = NULL;
444 This->mgrsite = pSite;
447 IServiceProvider *servprov;
450 IInternetSecurityMgrSite_AddRef(pSite);
452 hres = IInternetSecurityMgrSite_QueryInterface(pSite, &IID_IServiceProvider,
454 if(SUCCEEDED(hres)) {
455 IServiceProvider_QueryService(servprov, &SID_SInternetSecurityManager,
456 &IID_IInternetSecurityManager, (void**)&This->custom_manager);
457 IServiceProvider_Release(servprov);
464 static HRESULT WINAPI SecManagerImpl_GetSecuritySite(IInternetSecurityManager *iface,
465 IInternetSecurityMgrSite **ppSite)
467 SecManagerImpl *This = impl_from_IInternetSecurityManager(iface);
469 TRACE("(%p)->(%p)\n", This, ppSite);
475 IInternetSecurityMgrSite_AddRef(This->mgrsite);
477 *ppSite = This->mgrsite;
481 static HRESULT WINAPI SecManagerImpl_MapUrlToZone(IInternetSecurityManager *iface,
482 LPCWSTR pwszUrl, DWORD *pdwZone,
485 SecManagerImpl *This = impl_from_IInternetSecurityManager(iface);
488 TRACE("(%p)->(%s %p %08x)\n", iface, debugstr_w(pwszUrl), pdwZone, dwFlags);
490 if(This->custom_manager) {
491 hres = IInternetSecurityManager_MapUrlToZone(This->custom_manager,
492 pwszUrl, pdwZone, dwFlags);
493 if(hres != INET_E_DEFAULT_ACTION)
503 FIXME("not supported flags: %08x\n", dwFlags);
505 return map_url_to_zone(pwszUrl, pdwZone, NULL);
508 static HRESULT WINAPI SecManagerImpl_GetSecurityId(IInternetSecurityManager *iface,
509 LPCWSTR pwszUrl, BYTE *pbSecurityId, DWORD *pcbSecurityId, DWORD_PTR dwReserved)
511 SecManagerImpl *This = impl_from_IInternetSecurityManager(iface);
512 LPWSTR url, ptr, ptr2;
516 static const WCHAR wszFile[] = {'f','i','l','e',':'};
518 TRACE("(%p)->(%s %p %p %08lx)\n", iface, debugstr_w(pwszUrl), pbSecurityId,
519 pcbSecurityId, dwReserved);
521 if(This->custom_manager) {
522 hres = IInternetSecurityManager_GetSecurityId(This->custom_manager,
523 pwszUrl, pbSecurityId, pcbSecurityId, dwReserved);
524 if(hres != INET_E_DEFAULT_ACTION)
528 if(!pwszUrl || !pbSecurityId || !pcbSecurityId)
532 FIXME("dwReserved is not supported\n");
534 hres = map_url_to_zone(pwszUrl, &zone, &url);
536 return hres == 0x80041001 ? E_INVALIDARG : hres;
538 /* file protocol is a special case */
539 if(strlenW(url) >= sizeof(wszFile)/sizeof(WCHAR)
540 && !memcmp(url, wszFile, sizeof(wszFile)) && strchrW(url, '\\')) {
542 static const BYTE secidFile[] = {'f','i','l','e',':'};
546 if(*pcbSecurityId < sizeof(secidFile)+sizeof(zone))
547 return HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER);
549 memcpy(pbSecurityId, secidFile, sizeof(secidFile));
550 *(DWORD*)(pbSecurityId+sizeof(secidFile)) = zone;
552 *pcbSecurityId = sizeof(secidFile)+sizeof(zone);
556 ptr = strchrW(url, ':');
561 memmove(ptr, ptr2, (strlenW(ptr2)+1)*sizeof(WCHAR));
563 ptr = strchrW(ptr, '/');
567 len = WideCharToMultiByte(CP_ACP, 0, url, -1, NULL, 0, NULL, NULL)-1;
569 if(len+sizeof(DWORD) > *pcbSecurityId) {
571 return HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER);
574 WideCharToMultiByte(CP_ACP, 0, url, -1, (LPSTR)pbSecurityId, len, NULL, NULL);
577 *(DWORD*)(pbSecurityId+len) = zone;
579 *pcbSecurityId = len+sizeof(DWORD);
585 static HRESULT WINAPI SecManagerImpl_ProcessUrlAction(IInternetSecurityManager *iface,
586 LPCWSTR pwszUrl, DWORD dwAction,
587 BYTE *pPolicy, DWORD cbPolicy,
588 BYTE *pContext, DWORD cbContext,
589 DWORD dwFlags, DWORD dwReserved)
591 SecManagerImpl *This = impl_from_IInternetSecurityManager(iface);
595 TRACE("(%p)->(%s %08x %p %08x %p %08x %08x %08x)\n", iface, debugstr_w(pwszUrl), dwAction,
596 pPolicy, cbPolicy, pContext, cbContext, dwFlags, dwReserved);
598 if(This->custom_manager) {
599 hres = IInternetSecurityManager_ProcessUrlAction(This->custom_manager, pwszUrl, dwAction,
600 pPolicy, cbPolicy, pContext, cbContext, dwFlags, dwReserved);
601 if(hres != INET_E_DEFAULT_ACTION)
605 if(dwFlags || dwReserved)
606 FIXME("Unsupported arguments\n");
611 hres = map_url_to_zone(pwszUrl, &zone, NULL);
615 hres = get_action_policy(zone, dwAction, (BYTE*)&policy, sizeof(policy), URLZONEREG_DEFAULT);
619 TRACE("policy %x\n", policy);
620 if(cbPolicy >= sizeof(DWORD))
621 *(DWORD*)pPolicy = policy;
623 switch(GetUrlPolicyPermissions(policy)) {
624 case URLPOLICY_ALLOW:
625 case URLPOLICY_CHANNEL_SOFTDIST_PRECACHE:
627 case URLPOLICY_DISALLOW:
629 case URLPOLICY_QUERY:
630 FIXME("URLPOLICY_QUERY not implemented\n");
633 FIXME("Not implemented policy %x\n", policy);
640 static HRESULT WINAPI SecManagerImpl_QueryCustomPolicy(IInternetSecurityManager *iface,
641 LPCWSTR pwszUrl, REFGUID guidKey,
642 BYTE **ppPolicy, DWORD *pcbPolicy,
643 BYTE *pContext, DWORD cbContext,
646 SecManagerImpl *This = impl_from_IInternetSecurityManager(iface);
649 TRACE("(%p)->(%s %s %p %p %p %08x %08x )\n", iface, debugstr_w(pwszUrl), debugstr_guid(guidKey),
650 ppPolicy, pcbPolicy, pContext, cbContext, dwReserved);
652 if(This->custom_manager) {
653 hres = IInternetSecurityManager_QueryCustomPolicy(This->custom_manager, pwszUrl, guidKey,
654 ppPolicy, pcbPolicy, pContext, cbContext, dwReserved);
655 if(hres != INET_E_DEFAULT_ACTION)
659 WARN("Unknown guidKey %s\n", debugstr_guid(guidKey));
660 return HRESULT_FROM_WIN32(ERROR_NOT_FOUND);
663 static HRESULT WINAPI SecManagerImpl_SetZoneMapping(IInternetSecurityManager *iface,
664 DWORD dwZone, LPCWSTR pwszPattern, DWORD dwFlags)
666 SecManagerImpl *This = impl_from_IInternetSecurityManager(iface);
669 TRACE("(%p)->(%08x %s %08x)\n", iface, dwZone, debugstr_w(pwszPattern),dwFlags);
671 if(This->custom_manager) {
672 hres = IInternetSecurityManager_SetZoneMapping(This->custom_manager, dwZone,
673 pwszPattern, dwFlags);
674 if(hres != INET_E_DEFAULT_ACTION)
678 FIXME("Default action is not implemented\n");
682 static HRESULT WINAPI SecManagerImpl_GetZoneMappings(IInternetSecurityManager *iface,
683 DWORD dwZone, IEnumString **ppenumString, DWORD dwFlags)
685 SecManagerImpl *This = impl_from_IInternetSecurityManager(iface);
688 TRACE("(%p)->(%08x %p %08x)\n", iface, dwZone, ppenumString,dwFlags);
690 if(This->custom_manager) {
691 hres = IInternetSecurityManager_GetZoneMappings(This->custom_manager, dwZone,
692 ppenumString, dwFlags);
693 if(hres != INET_E_DEFAULT_ACTION)
697 FIXME("Default action is not implemented\n");
701 static const IInternetSecurityManagerVtbl VT_SecManagerImpl =
703 SecManagerImpl_QueryInterface,
704 SecManagerImpl_AddRef,
705 SecManagerImpl_Release,
706 SecManagerImpl_SetSecuritySite,
707 SecManagerImpl_GetSecuritySite,
708 SecManagerImpl_MapUrlToZone,
709 SecManagerImpl_GetSecurityId,
710 SecManagerImpl_ProcessUrlAction,
711 SecManagerImpl_QueryCustomPolicy,
712 SecManagerImpl_SetZoneMapping,
713 SecManagerImpl_GetZoneMappings
716 HRESULT SecManagerImpl_Construct(IUnknown *pUnkOuter, LPVOID *ppobj)
718 SecManagerImpl *This;
720 TRACE("(%p,%p)\n",pUnkOuter,ppobj);
721 This = heap_alloc(sizeof(*This));
723 /* Initialize the virtual function table. */
724 This->IInternetSecurityManager_iface.lpVtbl = &VT_SecManagerImpl;
727 This->mgrsite = NULL;
728 This->custom_manager = NULL;
737 /***********************************************************************
738 * InternetZoneManager implementation
742 IInternetZoneManagerEx2 IInternetZoneManagerEx2_iface;
748 static inline ZoneMgrImpl *impl_from_IInternetZoneManagerEx2(IInternetZoneManagerEx2 *iface)
750 return CONTAINING_RECORD(iface, ZoneMgrImpl, IInternetZoneManagerEx2_iface);
754 /***********************************************************************
755 * build_zonemap_from_reg [internal]
757 * Enumerate the Zones in the Registry and return the Zones in a DWORD-array
758 * The number of the Zones is returned in data[0]
760 static LPDWORD build_zonemap_from_reg(void)
765 DWORD allocated = 6; /* space for the zonecount and Zone "0" up to Zone "4" */
771 res = RegOpenKeyW(HKEY_CURRENT_USER, wszZonesKey, &hkey);
775 data = heap_alloc(allocated * sizeof(DWORD));
781 len = sizeof(name) / sizeof(name[0]);
782 res = RegEnumKeyExW(hkey, used, name, &len, NULL, NULL, NULL, NULL);
786 if (used == allocated) {
790 new_data = heap_realloc_zero(data, allocated * sizeof(DWORD));
796 data[used] = atoiW(name);
806 /* something failed */
812 /********************************************************************
813 * IInternetZoneManager_QueryInterface
815 static HRESULT WINAPI ZoneMgrImpl_QueryInterface(IInternetZoneManagerEx2* iface, REFIID riid, void** ppvObject)
817 ZoneMgrImpl* This = impl_from_IInternetZoneManagerEx2(iface);
819 TRACE("(%p)->(%s,%p)\n", This, debugstr_guid(riid), ppvObject);
821 if(!This || !ppvObject)
824 if(IsEqualIID(&IID_IUnknown, riid)) {
825 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppvObject);
826 }else if(IsEqualIID(&IID_IInternetZoneManager, riid)) {
827 TRACE("(%p)->(IID_InternetZoneManager %p)\n", This, ppvObject);
828 }else if(IsEqualIID(&IID_IInternetZoneManagerEx, riid)) {
829 TRACE("(%p)->(IID_InternetZoneManagerEx %p)\n", This, ppvObject);
830 }else if(IsEqualIID(&IID_IInternetZoneManagerEx2, riid)) {
831 TRACE("(%p)->(IID_InternetZoneManagerEx2 %p)\n", This, ppvObject);
835 FIXME("Unknown interface: %s\n", debugstr_guid(riid));
837 return E_NOINTERFACE;
841 IInternetZoneManager_AddRef(iface);
845 /********************************************************************
846 * IInternetZoneManager_AddRef
848 static ULONG WINAPI ZoneMgrImpl_AddRef(IInternetZoneManagerEx2* iface)
850 ZoneMgrImpl* This = impl_from_IInternetZoneManagerEx2(iface);
851 ULONG refCount = InterlockedIncrement(&This->ref);
853 TRACE("(%p)->(ref before=%u)\n",This, refCount - 1);
858 /********************************************************************
859 * IInternetZoneManager_Release
861 static ULONG WINAPI ZoneMgrImpl_Release(IInternetZoneManagerEx2* iface)
863 ZoneMgrImpl* This = impl_from_IInternetZoneManagerEx2(iface);
864 ULONG refCount = InterlockedDecrement(&This->ref);
866 TRACE("(%p)->(ref before=%u)\n",This, refCount + 1);
869 while (This->zonemap_count) heap_free(This->zonemaps[--This->zonemap_count]);
870 heap_free(This->zonemaps);
872 URLMON_UnlockModule();
878 /********************************************************************
879 * IInternetZoneManager_GetZoneAttributes
881 static HRESULT WINAPI ZoneMgrImpl_GetZoneAttributes(IInternetZoneManagerEx2* iface,
883 ZONEATTRIBUTES* pZoneAttributes)
885 ZoneMgrImpl* This = impl_from_IInternetZoneManagerEx2(iface);
890 TRACE("(%p)->(%d %p)\n", This, dwZone, pZoneAttributes);
892 if (!pZoneAttributes)
895 hr = open_zone_key(HKEY_CURRENT_USER, dwZone, &hcu);
897 return S_OK; /* IE6 and older returned E_FAIL here */
899 hr = open_zone_key(HKEY_LOCAL_MACHINE, dwZone, &hklm);
901 TRACE("Zone %d not in HKLM\n", dwZone);
903 get_string_from_reg(hcu, hklm, displaynameW, pZoneAttributes->szDisplayName, MAX_ZONE_PATH);
904 get_string_from_reg(hcu, hklm, descriptionW, pZoneAttributes->szDescription, MAX_ZONE_DESCRIPTION);
905 get_string_from_reg(hcu, hklm, iconW, pZoneAttributes->szIconPath, MAX_ZONE_PATH);
906 get_dword_from_reg(hcu, hklm, minlevelW, &pZoneAttributes->dwTemplateMinLevel);
907 get_dword_from_reg(hcu, hklm, currentlevelW, &pZoneAttributes->dwTemplateCurrentLevel);
908 get_dword_from_reg(hcu, hklm, recommendedlevelW, &pZoneAttributes->dwTemplateRecommended);
909 get_dword_from_reg(hcu, hklm, flagsW, &pZoneAttributes->dwFlags);
916 /********************************************************************
917 * IInternetZoneManager_SetZoneAttributes
919 static HRESULT WINAPI ZoneMgrImpl_SetZoneAttributes(IInternetZoneManagerEx2* iface,
921 ZONEATTRIBUTES* pZoneAttributes)
923 FIXME("(%p)->(%08x %p) stub\n", iface, dwZone, pZoneAttributes);
927 /********************************************************************
928 * IInternetZoneManager_GetZoneCustomPolicy
930 static HRESULT WINAPI ZoneMgrImpl_GetZoneCustomPolicy(IInternetZoneManagerEx2* iface,
935 URLZONEREG ulrZoneReg)
937 FIXME("(%p)->(%08x %s %p %p %08x) stub\n", iface, dwZone, debugstr_guid(guidKey),
938 ppPolicy, pcbPolicy, ulrZoneReg);
942 /********************************************************************
943 * IInternetZoneManager_SetZoneCustomPolicy
945 static HRESULT WINAPI ZoneMgrImpl_SetZoneCustomPolicy(IInternetZoneManagerEx2* iface,
950 URLZONEREG ulrZoneReg)
952 FIXME("(%p)->(%08x %s %p %08x %08x) stub\n", iface, dwZone, debugstr_guid(guidKey),
953 ppPolicy, cbPolicy, ulrZoneReg);
957 /********************************************************************
958 * IInternetZoneManager_GetZoneActionPolicy
960 static HRESULT WINAPI ZoneMgrImpl_GetZoneActionPolicy(IInternetZoneManagerEx2* iface,
961 DWORD dwZone, DWORD dwAction, BYTE* pPolicy, DWORD cbPolicy, URLZONEREG urlZoneReg)
963 TRACE("(%p)->(%d %08x %p %d %d)\n", iface, dwZone, dwAction, pPolicy,
964 cbPolicy, urlZoneReg);
969 return get_action_policy(dwZone, dwAction, pPolicy, cbPolicy, urlZoneReg);
972 /********************************************************************
973 * IInternetZoneManager_SetZoneActionPolicy
975 static HRESULT WINAPI ZoneMgrImpl_SetZoneActionPolicy(IInternetZoneManagerEx2* iface,
980 URLZONEREG urlZoneReg)
982 FIXME("(%p)->(%08x %08x %p %08x %08x) stub\n", iface, dwZone, dwAction, pPolicy,
983 cbPolicy, urlZoneReg);
987 /********************************************************************
988 * IInternetZoneManager_PromptAction
990 static HRESULT WINAPI ZoneMgrImpl_PromptAction(IInternetZoneManagerEx2* iface,
997 FIXME("%p %08x %p %s %s %08x\n", iface, dwAction, hwndParent,
998 debugstr_w(pwszUrl), debugstr_w(pwszText), dwPromptFlags );
1002 /********************************************************************
1003 * IInternetZoneManager_LogAction
1005 static HRESULT WINAPI ZoneMgrImpl_LogAction(IInternetZoneManagerEx2* iface,
1011 FIXME("(%p)->(%08x %s %s %08x) stub\n", iface, dwAction, debugstr_w(pwszUrl),
1012 debugstr_w(pwszText), dwLogFlags);
1016 /********************************************************************
1017 * IInternetZoneManager_CreateZoneEnumerator
1019 static HRESULT WINAPI ZoneMgrImpl_CreateZoneEnumerator(IInternetZoneManagerEx2* iface,
1024 ZoneMgrImpl* This = impl_from_IInternetZoneManagerEx2(iface);
1029 TRACE("(%p)->(%p, %p, 0x%08x)\n", This, pdwEnum, pdwCount, dwFlags);
1030 if (!pdwEnum || !pdwCount || (dwFlags != 0))
1031 return E_INVALIDARG;
1033 data = build_zonemap_from_reg();
1034 TRACE("found %d zones\n", data ? data[0] : -1);
1039 for (i = 0; i < This->zonemap_count; i++) {
1040 if (This->zonemaps && !This->zonemaps[i]) {
1041 This->zonemaps[i] = data;
1043 *pdwCount = data[0];
1048 if (This->zonemaps) {
1049 /* try to double the nr. of pointers in the array */
1050 new_maps = heap_realloc_zero(This->zonemaps, This->zonemap_count * 2 * sizeof(LPDWORD));
1052 This->zonemap_count *= 2;
1056 This->zonemap_count = 2;
1057 new_maps = heap_alloc_zero(This->zonemap_count * sizeof(LPDWORD));
1064 This->zonemaps = new_maps;
1065 This->zonemaps[i] = data;
1067 *pdwCount = data[0];
1071 /********************************************************************
1072 * IInternetZoneManager_GetZoneAt
1074 static HRESULT WINAPI ZoneMgrImpl_GetZoneAt(IInternetZoneManagerEx2* iface,
1079 ZoneMgrImpl* This = impl_from_IInternetZoneManagerEx2(iface);
1082 TRACE("(%p)->(0x%08x, %d, %p)\n", This, dwEnum, dwIndex, pdwZone);
1084 /* make sure, that dwEnum and dwIndex are in the valid range */
1085 if (dwEnum < This->zonemap_count) {
1086 if ((data = This->zonemaps[dwEnum])) {
1087 if (dwIndex < data[0]) {
1088 *pdwZone = data[dwIndex + 1];
1093 return E_INVALIDARG;
1096 /********************************************************************
1097 * IInternetZoneManager_DestroyZoneEnumerator
1099 static HRESULT WINAPI ZoneMgrImpl_DestroyZoneEnumerator(IInternetZoneManagerEx2* iface,
1102 ZoneMgrImpl* This = impl_from_IInternetZoneManagerEx2(iface);
1105 TRACE("(%p)->(0x%08x)\n", This, dwEnum);
1106 /* make sure, that dwEnum is valid */
1107 if (dwEnum < This->zonemap_count) {
1108 if ((data = This->zonemaps[dwEnum])) {
1109 This->zonemaps[dwEnum] = NULL;
1114 return E_INVALIDARG;
1117 /********************************************************************
1118 * IInternetZoneManager_CopyTemplatePoliciesToZone
1120 static HRESULT WINAPI ZoneMgrImpl_CopyTemplatePoliciesToZone(IInternetZoneManagerEx2* iface,
1125 FIXME("(%p)->(%08x %08x %08x) stub\n", iface, dwTemplate, dwZone, dwReserved);
1129 /********************************************************************
1130 * IInternetZoneManagerEx_GetZoneActionPolicyEx
1132 static HRESULT WINAPI ZoneMgrImpl_GetZoneActionPolicyEx(IInternetZoneManagerEx2* iface,
1137 URLZONEREG urlZoneReg,
1140 TRACE("(%p)->(%d, 0x%x, %p, %d, %d, 0x%x)\n", iface, dwZone,
1141 dwAction, pPolicy, cbPolicy, urlZoneReg, dwFlags);
1144 return E_INVALIDARG;
1147 FIXME("dwFlags 0x%x ignored\n", dwFlags);
1149 return get_action_policy(dwZone, dwAction, pPolicy, cbPolicy, urlZoneReg);
1152 /********************************************************************
1153 * IInternetZoneManagerEx_SetZoneActionPolicyEx
1155 static HRESULT WINAPI ZoneMgrImpl_SetZoneActionPolicyEx(IInternetZoneManagerEx2* iface,
1160 URLZONEREG urlZoneReg,
1163 FIXME("(%p)->(%d, 0x%x, %p, %d, %d, 0x%x) stub\n", iface, dwZone, dwAction, pPolicy,
1164 cbPolicy, urlZoneReg, dwFlags);
1168 /********************************************************************
1169 * IInternetZoneManagerEx2_GetZoneAttributesEx
1171 static HRESULT WINAPI ZoneMgrImpl_GetZoneAttributesEx(IInternetZoneManagerEx2* iface,
1173 ZONEATTRIBUTES* pZoneAttributes,
1176 TRACE("(%p)->(%d, %p, 0x%x)\n", iface, dwZone, pZoneAttributes, dwFlags);
1179 FIXME("dwFlags 0x%x ignored\n", dwFlags);
1181 return IInternetZoneManager_GetZoneAttributes(iface, dwZone, pZoneAttributes);
1185 /********************************************************************
1186 * IInternetZoneManagerEx2_GetZoneSecurityState
1188 static HRESULT WINAPI ZoneMgrImpl_GetZoneSecurityState(IInternetZoneManagerEx2* iface,
1190 BOOL fRespectPolicy,
1192 BOOL *pfPolicyEncountered)
1194 FIXME("(%p)->(%d, %d, %p, %p) stub\n", iface, dwZoneIndex, fRespectPolicy,
1195 pdwState, pfPolicyEncountered);
1197 *pdwState = SECURITY_IE_STATE_GREEN;
1199 if (pfPolicyEncountered)
1200 *pfPolicyEncountered = FALSE;
1205 /********************************************************************
1206 * IInternetZoneManagerEx2_GetIESecurityState
1208 static HRESULT WINAPI ZoneMgrImpl_GetIESecurityState(IInternetZoneManagerEx2* iface,
1209 BOOL fRespectPolicy,
1211 BOOL *pfPolicyEncountered,
1214 FIXME("(%p)->(%d, %p, %p, %d) stub\n", iface, fRespectPolicy, pdwState,
1215 pfPolicyEncountered, fNoCache);
1217 *pdwState = SECURITY_IE_STATE_GREEN;
1219 if (pfPolicyEncountered)
1220 *pfPolicyEncountered = FALSE;
1225 /********************************************************************
1226 * IInternetZoneManagerEx2_FixInsecureSettings
1228 static HRESULT WINAPI ZoneMgrImpl_FixInsecureSettings(IInternetZoneManagerEx2* iface)
1230 FIXME("(%p) stub\n", iface);
1234 /********************************************************************
1235 * IInternetZoneManager_Construct
1237 static const IInternetZoneManagerEx2Vtbl ZoneMgrImplVtbl = {
1238 ZoneMgrImpl_QueryInterface,
1240 ZoneMgrImpl_Release,
1241 /* IInternetZoneManager */
1242 ZoneMgrImpl_GetZoneAttributes,
1243 ZoneMgrImpl_SetZoneAttributes,
1244 ZoneMgrImpl_GetZoneCustomPolicy,
1245 ZoneMgrImpl_SetZoneCustomPolicy,
1246 ZoneMgrImpl_GetZoneActionPolicy,
1247 ZoneMgrImpl_SetZoneActionPolicy,
1248 ZoneMgrImpl_PromptAction,
1249 ZoneMgrImpl_LogAction,
1250 ZoneMgrImpl_CreateZoneEnumerator,
1251 ZoneMgrImpl_GetZoneAt,
1252 ZoneMgrImpl_DestroyZoneEnumerator,
1253 ZoneMgrImpl_CopyTemplatePoliciesToZone,
1254 /* IInternetZoneManagerEx */
1255 ZoneMgrImpl_GetZoneActionPolicyEx,
1256 ZoneMgrImpl_SetZoneActionPolicyEx,
1257 /* IInternetZoneManagerEx2 */
1258 ZoneMgrImpl_GetZoneAttributesEx,
1259 ZoneMgrImpl_GetZoneSecurityState,
1260 ZoneMgrImpl_GetIESecurityState,
1261 ZoneMgrImpl_FixInsecureSettings,
1264 HRESULT ZoneMgrImpl_Construct(IUnknown *pUnkOuter, LPVOID *ppobj)
1266 ZoneMgrImpl* ret = heap_alloc_zero(sizeof(ZoneMgrImpl));
1268 TRACE("(%p %p)\n", pUnkOuter, ppobj);
1269 ret->IInternetZoneManagerEx2_iface.lpVtbl = &ZoneMgrImplVtbl;
1271 *ppobj = (IInternetZoneManagerEx*)ret;
1273 URLMON_LockModule();
1278 /***********************************************************************
1279 * CoInternetCreateSecurityManager (URLMON.@)
1282 HRESULT WINAPI CoInternetCreateSecurityManager( IServiceProvider *pSP,
1283 IInternetSecurityManager **ppSM, DWORD dwReserved )
1285 TRACE("%p %p %d\n", pSP, ppSM, dwReserved );
1288 FIXME("pSP not supported\n");
1290 return SecManagerImpl_Construct(NULL, (void**) ppSM);
1293 /********************************************************************
1294 * CoInternetCreateZoneManager (URLMON.@)
1296 HRESULT WINAPI CoInternetCreateZoneManager(IServiceProvider* pSP, IInternetZoneManager** ppZM, DWORD dwReserved)
1298 TRACE("(%p %p %x)\n", pSP, ppZM, dwReserved);
1299 return ZoneMgrImpl_Construct(NULL, (void**)ppZM);
1302 /********************************************************************
1303 * CoInternetGetSecurityUrl (URLMON.@)
1305 HRESULT WINAPI CoInternetGetSecurityUrl(LPCWSTR pwzUrl, LPWSTR *ppwzSecUrl, PSUACTION psuAction, DWORD dwReserved)
1307 WCHAR buf1[INTERNET_MAX_URL_LENGTH], buf2[INTERNET_MAX_URL_LENGTH];
1312 TRACE("(%p,%p,%u,%u)\n", pwzUrl, ppwzSecUrl, psuAction, dwReserved);
1316 strcpyW(url, pwzUrl);
1319 hres = CoInternetParseUrl(url, PARSE_SECURITY_URL, 0, domain, INTERNET_MAX_URL_LENGTH, &len, 0);
1320 if(hres!=S_OK || !strcmpW(url, domain))
1332 if(psuAction==PSU_SECURITY_URL_ONLY) {
1333 len = lstrlenW(url)+1;
1334 *ppwzSecUrl = CoTaskMemAlloc(len*sizeof(WCHAR));
1336 return E_OUTOFMEMORY;
1338 memcpy(*ppwzSecUrl, url, len*sizeof(WCHAR));
1342 hres = CoInternetParseUrl(url, PARSE_SECURITY_DOMAIN, 0, domain,
1343 INTERNET_MAX_URL_LENGTH, &len, 0);
1344 if(SUCCEEDED(hres)) {
1346 *ppwzSecUrl = CoTaskMemAlloc(len*sizeof(WCHAR));
1348 return E_OUTOFMEMORY;
1350 memcpy(*ppwzSecUrl, domain, len*sizeof(WCHAR));
1354 hres = CoInternetParseUrl(url, PARSE_SCHEMA, 0, domain,
1355 INTERNET_MAX_URL_LENGTH, &len, 0);
1357 const WCHAR fileW[] = {'f','i','l','e',0};
1358 if(!strcmpW(domain, fileW)){
1359 hres = CoInternetParseUrl(url, PARSE_ROOTDOCUMENT, 0, domain, INTERNET_MAX_URL_LENGTH, &len, 0);
1362 hres = CoInternetParseUrl(url, PARSE_DOMAIN, 0, domain+len+1,
1363 INTERNET_MAX_URL_LENGTH-len-1, &len, 0);
1365 len = lstrlenW(domain)+1;
1366 *ppwzSecUrl = CoTaskMemAlloc(len*sizeof(WCHAR));
1368 return E_OUTOFMEMORY;
1370 memcpy(*ppwzSecUrl, domain, len*sizeof(WCHAR));
1377 len = lstrlenW(url)+1;
1378 *ppwzSecUrl = CoTaskMemAlloc(len*sizeof(WCHAR));
1380 return E_OUTOFMEMORY;
1382 memcpy(*ppwzSecUrl, url, len*sizeof(WCHAR));
1386 /********************************************************************
1387 * CoInternetGetSecurityUrlEx (URLMON.@)
1389 HRESULT WINAPI CoInternetGetSecurityUrlEx(IUri *pUri, IUri **ppSecUri, PSUACTION psuAction, DWORD_PTR dwReserved)
1393 URL_SCHEME scheme_type;
1395 TRACE("(%p,%p,%u,%u)\n", pUri, ppSecUri, psuAction, (DWORD)dwReserved);
1397 if(!pUri || !ppSecUri)
1398 return E_INVALIDARG;
1400 /* Try to find the Security url using pluggable protocols first. */
1401 hres = parse_security_uri(pUri, psuAction, ppSecUri);
1402 if(FAILED(hres) || *ppSecUri)
1405 hres = IUri_GetScheme(pUri, (DWORD*)&scheme_type);
1409 hres = IUri_GetDisplayUri(pUri, &secure_uri);
1413 /* File URIs have to hierarchical. */
1414 if(scheme_type == URL_SCHEME_FILE) {
1415 const WCHAR *tmp = secure_uri;
1417 /* Check and see if a "//" is after the scheme name. */
1418 tmp += sizeof(fileW)/sizeof(WCHAR);
1419 if(*tmp != '/' || *(tmp+1) != '/') {
1420 SysFreeString(secure_uri);
1421 return E_INVALIDARG;
1425 hres = CreateUri(secure_uri, Uri_CREATE_ALLOW_IMPLICIT_WILDCARD_SCHEME, 0, ppSecUri);
1426 SysFreeString(secure_uri);