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 #include "wine/debug.h"
31 WINE_DEFAULT_DEBUG_CHANNEL(urlmon);
33 static const WCHAR currentlevelW[] = {'C','u','r','r','e','n','t','L','e','v','e','l',0};
34 static const WCHAR descriptionW[] = {'D','e','s','c','r','i','p','t','i','o','n',0};
35 static const WCHAR displaynameW[] = {'D','i','s','p','l','a','y','N','a','m','e',0};
36 static const WCHAR fileW[] = {'f','i','l','e',0};
37 static const WCHAR flagsW[] = {'F','l','a','g','s',0};
38 static const WCHAR iconW[] = {'I','c','o','n',0};
39 static const WCHAR minlevelW[] = {'M','i','n','L','e','v','e','l',0};
40 static const WCHAR recommendedlevelW[] = {'R','e','c','o','m','m','e','n','d','e','d',
41 'L','e','v','e','l',0};
42 static const WCHAR wszZonesKey[] = {'S','o','f','t','w','a','r','e','\\',
43 'M','i','c','r','o','s','o','f','t','\\',
44 'W','i','n','d','o','w','s','\\',
45 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
46 'I','n','t','e','r','n','e','t',' ','S','e','t','t','i','n','g','s','\\',
47 'Z','o','n','e','s','\\',0};
49 /********************************************************************
50 * get_string_from_reg [internal]
52 * helper to get a string from the reg.
55 static void get_string_from_reg(HKEY hcu, HKEY hklm, LPCWSTR name, LPWSTR out, DWORD maxlen)
58 DWORD len = maxlen * sizeof(WCHAR);
61 res = RegQueryValueExW(hcu, name, NULL, &type, (LPBYTE) out, &len);
64 len = maxlen * sizeof(WCHAR);
66 res = RegQueryValueExW(hklm, name, NULL, &type, (LPBYTE) out, &len);
70 TRACE("%s failed: %d\n", debugstr_w(name), res);
75 /********************************************************************
76 * get_dword_from_reg [internal]
78 * helper to get a dword from the reg.
81 static void get_dword_from_reg(HKEY hcu, HKEY hklm, LPCWSTR name, LPDWORD out)
83 DWORD type = REG_DWORD;
84 DWORD len = sizeof(DWORD);
87 res = RegQueryValueExW(hcu, name, NULL, &type, (LPBYTE) out, &len);
92 res = RegQueryValueExW(hklm, name, NULL, &type, (LPBYTE) out, &len);
96 TRACE("%s failed: %d\n", debugstr_w(name), res);
101 static HRESULT get_zone_from_reg(LPCWSTR schema, DWORD *zone)
106 static const WCHAR wszZoneMapProtocolKey[] =
107 {'S','o','f','t','w','a','r','e','\\',
108 'M','i','c','r','o','s','o','f','t','\\',
109 'W','i','n','d','o','w','s','\\',
110 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
111 'I','n','t','e','r','n','e','t',' ','S','e','t','t','i','n','g','s','\\',
112 'Z','o','n','e','M','a','p','\\',
113 'P','r','o','t','o','c','o','l','D','e','f','a','u','l','t','s',0};
115 res = RegOpenKeyW(HKEY_CURRENT_USER, wszZoneMapProtocolKey, &hkey);
116 if(res != ERROR_SUCCESS) {
117 ERR("Could not open key %s\n", debugstr_w(wszZoneMapProtocolKey));
121 size = sizeof(DWORD);
122 res = RegQueryValueExW(hkey, schema, NULL, NULL, (PBYTE)zone, &size);
124 if(res == ERROR_SUCCESS)
127 res = RegOpenKeyW(HKEY_LOCAL_MACHINE, wszZoneMapProtocolKey, &hkey);
128 if(res != ERROR_SUCCESS) {
129 ERR("Could not open key %s\n", debugstr_w(wszZoneMapProtocolKey));
133 size = sizeof(DWORD);
134 res = RegQueryValueExW(hkey, schema, NULL, NULL, (PBYTE)zone, &size);
136 if(res == ERROR_SUCCESS)
143 static HRESULT map_url_to_zone(LPCWSTR url, DWORD *zone, LPWSTR *ret_url)
152 hres = CoInternetGetSecurityUrl(url, &secur_url, PSU_SECURITY_URL_ONLY, 0);
154 size = strlenW(url)*sizeof(WCHAR);
156 secur_url = heap_alloc(size);
158 return E_OUTOFMEMORY;
160 memcpy(secur_url, url, size);
163 hres = CoInternetParseUrl(secur_url, PARSE_SCHEMA, 0, schema, sizeof(schema)/sizeof(WCHAR), &size, 0);
164 if(FAILED(hres) || !*schema) {
165 heap_free(secur_url);
169 /* file protocol is a special case */
170 if(!strcmpW(schema, fileW)) {
171 WCHAR path[MAX_PATH], root[20];
174 hres = CoInternetParseUrl(secur_url, PARSE_PATH_FROM_URL, 0, path,
175 sizeof(path)/sizeof(WCHAR), &size, 0);
177 if(SUCCEEDED(hres) && (ptr = strchrW(path, '\\')) && ptr-path < sizeof(root)/sizeof(WCHAR)) {
180 memcpy(root, path, (ptr-path)*sizeof(WCHAR));
183 type = GetDriveTypeW(root);
187 case DRIVE_NO_ROOT_DIR:
189 case DRIVE_REMOVABLE:
201 FIXME("unsupported drive type %d\n", type);
207 WARN("domains are not yet implemented\n");
208 hres = get_zone_from_reg(schema, zone);
211 if(FAILED(hres) || !ret_url)
212 heap_free(secur_url);
214 *ret_url = secur_url;
219 static HRESULT open_zone_key(HKEY parent_key, DWORD zone, HKEY *hkey)
221 static const WCHAR wszFormat[] = {'%','s','%','l','d',0};
223 WCHAR key_name[sizeof(wszZonesKey)/sizeof(WCHAR)+8];
226 wsprintfW(key_name, wszFormat, wszZonesKey, zone);
228 res = RegOpenKeyW(parent_key, key_name, hkey);
230 if(res != ERROR_SUCCESS) {
231 WARN("RegOpenKey failed\n");
238 static HRESULT get_action_policy(DWORD zone, DWORD action, BYTE *policy, DWORD size, URLZONEREG zone_reg)
246 case URLACTION_SCRIPT_OVERRIDE_SAFETY:
247 case URLACTION_ACTIVEX_OVERRIDE_SCRIPT_SAFETY:
248 *(DWORD*)policy = URLPOLICY_DISALLOW;
253 case URLZONEREG_DEFAULT:
254 case URLZONEREG_HKCU:
255 parent_key = HKEY_CURRENT_USER;
257 case URLZONEREG_HKLM:
258 parent_key = HKEY_LOCAL_MACHINE;
261 WARN("Unknown URLZONEREG: %d\n", zone_reg);
265 hres = open_zone_key(parent_key, zone, &hkey);
266 if(SUCCEEDED(hres)) {
267 WCHAR action_str[16];
270 static const WCHAR formatW[] = {'%','X',0};
272 wsprintfW(action_str, formatW, action);
274 res = RegQueryValueExW(hkey, action_str, NULL, NULL, policy, &len);
275 if(res == ERROR_MORE_DATA) {
277 }else if(res == ERROR_FILE_NOT_FOUND) {
279 }else if(res != ERROR_SUCCESS) {
280 ERR("RegQueryValue failed: %d\n", res);
287 if(FAILED(hres) && zone_reg == URLZONEREG_DEFAULT)
288 return get_action_policy(zone, action, policy, size, URLZONEREG_HKLM);
293 /***********************************************************************
294 * InternetSecurityManager implementation
298 const IInternetSecurityManagerVtbl* lpInternetSecurityManagerVtbl;
302 IInternetSecurityMgrSite *mgrsite;
303 IInternetSecurityManager *custom_manager;
306 #define SECMGR_THIS(iface) DEFINE_THIS(SecManagerImpl, InternetSecurityManager, iface)
308 static HRESULT WINAPI SecManagerImpl_QueryInterface(IInternetSecurityManager* iface,REFIID riid,void** ppvObject)
310 SecManagerImpl *This = SECMGR_THIS(iface);
312 TRACE("(%p)->(%s,%p)\n",This,debugstr_guid(riid),ppvObject);
314 /* Perform a sanity check on the parameters.*/
315 if ( (This==0) || (ppvObject==0) )
318 /* Initialize the return parameter */
321 /* Compare the riid with the interface IDs implemented by this object.*/
322 if (IsEqualIID(&IID_IUnknown, riid) ||
323 IsEqualIID(&IID_IInternetSecurityManager, riid))
326 /* Check that we obtained an interface.*/
328 WARN("not supported interface %s\n", debugstr_guid(riid));
329 return E_NOINTERFACE;
332 /* Query Interface always increases the reference count by one when it is successful */
333 IInternetSecurityManager_AddRef(iface);
338 static ULONG WINAPI SecManagerImpl_AddRef(IInternetSecurityManager* iface)
340 SecManagerImpl *This = SECMGR_THIS(iface);
341 ULONG refCount = InterlockedIncrement(&This->ref);
343 TRACE("(%p) ref=%u\n", This, refCount);
348 static ULONG WINAPI SecManagerImpl_Release(IInternetSecurityManager* iface)
350 SecManagerImpl *This = SECMGR_THIS(iface);
351 ULONG refCount = InterlockedDecrement(&This->ref);
353 TRACE("(%p) ref=%u\n", This, refCount);
355 /* destroy the object if there's no more reference on it */
358 IInternetSecurityMgrSite_Release(This->mgrsite);
359 if(This->custom_manager)
360 IInternetSecurityManager_Release(This->custom_manager);
364 URLMON_UnlockModule();
370 static HRESULT WINAPI SecManagerImpl_SetSecuritySite(IInternetSecurityManager *iface,
371 IInternetSecurityMgrSite *pSite)
373 SecManagerImpl *This = SECMGR_THIS(iface);
375 TRACE("(%p)->(%p)\n", This, pSite);
378 IInternetSecurityMgrSite_Release(This->mgrsite);
380 if(This->custom_manager) {
381 IInternetSecurityManager_Release(This->custom_manager);
382 This->custom_manager = NULL;
385 This->mgrsite = pSite;
388 IServiceProvider *servprov;
391 IInternetSecurityMgrSite_AddRef(pSite);
393 hres = IInternetSecurityMgrSite_QueryInterface(pSite, &IID_IServiceProvider,
395 if(SUCCEEDED(hres)) {
396 IServiceProvider_QueryService(servprov, &SID_SInternetSecurityManager,
397 &IID_IInternetSecurityManager, (void**)&This->custom_manager);
398 IServiceProvider_Release(servprov);
405 static HRESULT WINAPI SecManagerImpl_GetSecuritySite(IInternetSecurityManager *iface,
406 IInternetSecurityMgrSite **ppSite)
408 SecManagerImpl *This = SECMGR_THIS(iface);
410 TRACE("(%p)->(%p)\n", This, ppSite);
416 IInternetSecurityMgrSite_AddRef(This->mgrsite);
418 *ppSite = This->mgrsite;
422 static HRESULT WINAPI SecManagerImpl_MapUrlToZone(IInternetSecurityManager *iface,
423 LPCWSTR pwszUrl, DWORD *pdwZone,
426 SecManagerImpl *This = SECMGR_THIS(iface);
429 TRACE("(%p)->(%s %p %08x)\n", iface, debugstr_w(pwszUrl), pdwZone, dwFlags);
431 if(This->custom_manager) {
432 hres = IInternetSecurityManager_MapUrlToZone(This->custom_manager,
433 pwszUrl, pdwZone, dwFlags);
434 if(hres != INET_E_DEFAULT_ACTION)
444 FIXME("not supported flags: %08x\n", dwFlags);
446 return map_url_to_zone(pwszUrl, pdwZone, NULL);
449 static HRESULT WINAPI SecManagerImpl_GetSecurityId(IInternetSecurityManager *iface,
450 LPCWSTR pwszUrl, BYTE *pbSecurityId, DWORD *pcbSecurityId, DWORD_PTR dwReserved)
452 SecManagerImpl *This = SECMGR_THIS(iface);
453 LPWSTR url, ptr, ptr2;
457 static const WCHAR wszFile[] = {'f','i','l','e',':'};
459 TRACE("(%p)->(%s %p %p %08lx)\n", iface, debugstr_w(pwszUrl), pbSecurityId,
460 pcbSecurityId, dwReserved);
462 if(This->custom_manager) {
463 hres = IInternetSecurityManager_GetSecurityId(This->custom_manager,
464 pwszUrl, pbSecurityId, pcbSecurityId, dwReserved);
465 if(hres != INET_E_DEFAULT_ACTION)
469 if(!pwszUrl || !pbSecurityId || !pcbSecurityId)
473 FIXME("dwReserved is not supported\n");
475 hres = map_url_to_zone(pwszUrl, &zone, &url);
477 return hres == 0x80041001 ? E_INVALIDARG : hres;
479 /* file protocol is a special case */
480 if(strlenW(url) >= sizeof(wszFile)/sizeof(WCHAR)
481 && !memcmp(url, wszFile, sizeof(wszFile)) && strchrW(url, '\\')) {
483 static const BYTE secidFile[] = {'f','i','l','e',':'};
487 if(*pcbSecurityId < sizeof(secidFile)+sizeof(zone))
488 return HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER);
490 memcpy(pbSecurityId, secidFile, sizeof(secidFile));
491 *(DWORD*)(pbSecurityId+sizeof(secidFile)) = zone;
493 *pcbSecurityId = sizeof(secidFile)+sizeof(zone);
497 ptr = strchrW(url, ':');
502 memmove(ptr, ptr2, (strlenW(ptr2)+1)*sizeof(WCHAR));
504 ptr = strchrW(ptr, '/');
508 len = WideCharToMultiByte(CP_ACP, 0, url, -1, NULL, 0, NULL, NULL)-1;
510 if(len+sizeof(DWORD) > *pcbSecurityId) {
512 return HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER);
515 WideCharToMultiByte(CP_ACP, 0, url, -1, (LPSTR)pbSecurityId, len, NULL, NULL);
518 *(DWORD*)(pbSecurityId+len) = zone;
520 *pcbSecurityId = len+sizeof(DWORD);
526 static HRESULT WINAPI SecManagerImpl_ProcessUrlAction(IInternetSecurityManager *iface,
527 LPCWSTR pwszUrl, DWORD dwAction,
528 BYTE *pPolicy, DWORD cbPolicy,
529 BYTE *pContext, DWORD cbContext,
530 DWORD dwFlags, DWORD dwReserved)
532 SecManagerImpl *This = SECMGR_THIS(iface);
536 TRACE("(%p)->(%s %08x %p %08x %p %08x %08x %08x)\n", iface, debugstr_w(pwszUrl), dwAction,
537 pPolicy, cbPolicy, pContext, cbContext, dwFlags, dwReserved);
539 if(This->custom_manager) {
540 hres = IInternetSecurityManager_ProcessUrlAction(This->custom_manager, pwszUrl, dwAction,
541 pPolicy, cbPolicy, pContext, cbContext, dwFlags, dwReserved);
542 if(hres != INET_E_DEFAULT_ACTION)
546 if(dwFlags || dwReserved)
547 FIXME("Unsupported arguments\n");
552 hres = map_url_to_zone(pwszUrl, &zone, NULL);
556 hres = get_action_policy(zone, dwAction, (BYTE*)&policy, sizeof(policy), URLZONEREG_DEFAULT);
560 TRACE("policy %x\n", policy);
561 if(cbPolicy >= sizeof(DWORD))
562 *(DWORD*)pPolicy = policy;
564 switch(GetUrlPolicyPermissions(policy)) {
565 case URLPOLICY_ALLOW:
566 case URLPOLICY_CHANNEL_SOFTDIST_PRECACHE:
568 case URLPOLICY_DISALLOW:
570 case URLPOLICY_QUERY:
571 FIXME("URLPOLICY_QUERY not implemented\n");
574 FIXME("Not implemented policy %x\n", policy);
581 static HRESULT WINAPI SecManagerImpl_QueryCustomPolicy(IInternetSecurityManager *iface,
582 LPCWSTR pwszUrl, REFGUID guidKey,
583 BYTE **ppPolicy, DWORD *pcbPolicy,
584 BYTE *pContext, DWORD cbContext,
587 SecManagerImpl *This = SECMGR_THIS(iface);
590 TRACE("(%p)->(%s %s %p %p %p %08x %08x )\n", iface, debugstr_w(pwszUrl), debugstr_guid(guidKey),
591 ppPolicy, pcbPolicy, pContext, cbContext, dwReserved);
593 if(This->custom_manager) {
594 hres = IInternetSecurityManager_QueryCustomPolicy(This->custom_manager, pwszUrl, guidKey,
595 ppPolicy, pcbPolicy, pContext, cbContext, dwReserved);
596 if(hres != INET_E_DEFAULT_ACTION)
600 WARN("Unknown guidKey %s\n", debugstr_guid(guidKey));
601 return HRESULT_FROM_WIN32(ERROR_NOT_FOUND);
604 static HRESULT WINAPI SecManagerImpl_SetZoneMapping(IInternetSecurityManager *iface,
605 DWORD dwZone, LPCWSTR pwszPattern, DWORD dwFlags)
607 SecManagerImpl *This = SECMGR_THIS(iface);
610 TRACE("(%p)->(%08x %s %08x)\n", iface, dwZone, debugstr_w(pwszPattern),dwFlags);
612 if(This->custom_manager) {
613 hres = IInternetSecurityManager_SetZoneMapping(This->custom_manager, dwZone,
614 pwszPattern, dwFlags);
615 if(hres != INET_E_DEFAULT_ACTION)
619 FIXME("Default action is not implemented\n");
623 static HRESULT WINAPI SecManagerImpl_GetZoneMappings(IInternetSecurityManager *iface,
624 DWORD dwZone, IEnumString **ppenumString, DWORD dwFlags)
626 SecManagerImpl *This = SECMGR_THIS(iface);
629 TRACE("(%p)->(%08x %p %08x)\n", iface, dwZone, ppenumString,dwFlags);
631 if(This->custom_manager) {
632 hres = IInternetSecurityManager_GetZoneMappings(This->custom_manager, dwZone,
633 ppenumString, dwFlags);
634 if(hres != INET_E_DEFAULT_ACTION)
638 FIXME("Default action is not implemented\n");
642 static const IInternetSecurityManagerVtbl VT_SecManagerImpl =
644 SecManagerImpl_QueryInterface,
645 SecManagerImpl_AddRef,
646 SecManagerImpl_Release,
647 SecManagerImpl_SetSecuritySite,
648 SecManagerImpl_GetSecuritySite,
649 SecManagerImpl_MapUrlToZone,
650 SecManagerImpl_GetSecurityId,
651 SecManagerImpl_ProcessUrlAction,
652 SecManagerImpl_QueryCustomPolicy,
653 SecManagerImpl_SetZoneMapping,
654 SecManagerImpl_GetZoneMappings
657 HRESULT SecManagerImpl_Construct(IUnknown *pUnkOuter, LPVOID *ppobj)
659 SecManagerImpl *This;
661 TRACE("(%p,%p)\n",pUnkOuter,ppobj);
662 This = heap_alloc(sizeof(*This));
664 /* Initialize the virtual function table. */
665 This->lpInternetSecurityManagerVtbl = &VT_SecManagerImpl;
668 This->mgrsite = NULL;
669 This->custom_manager = NULL;
678 /***********************************************************************
679 * InternetZoneManager implementation
683 const IInternetZoneManagerEx2Vtbl* lpVtbl;
690 /***********************************************************************
691 * build_zonemap_from_reg [internal]
693 * Enumerate the Zones in the Registry and return the Zones in a DWORD-array
694 * The number of the Zones is returned in data[0]
696 static LPDWORD build_zonemap_from_reg(void)
701 DWORD allocated = 6; /* space for the zonecount and Zone "0" up to Zone "4" */
707 res = RegOpenKeyW(HKEY_CURRENT_USER, wszZonesKey, &hkey);
711 data = heap_alloc(allocated * sizeof(DWORD));
717 len = sizeof(name) / sizeof(name[0]);
718 res = RegEnumKeyExW(hkey, used, name, &len, NULL, NULL, NULL, NULL);
722 if (used == allocated) {
726 new_data = heap_realloc_zero(data, allocated * sizeof(DWORD));
732 data[used] = atoiW(name);
742 /* something failed */
748 /********************************************************************
749 * IInternetZoneManager_QueryInterface
751 static HRESULT WINAPI ZoneMgrImpl_QueryInterface(IInternetZoneManagerEx2* iface, REFIID riid, void** ppvObject)
753 ZoneMgrImpl* This = (ZoneMgrImpl*)iface;
755 TRACE("(%p)->(%s,%p)\n", This, debugstr_guid(riid), ppvObject);
757 if(!This || !ppvObject)
760 if(IsEqualIID(&IID_IUnknown, riid)) {
761 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppvObject);
762 }else if(IsEqualIID(&IID_IInternetZoneManager, riid)) {
763 TRACE("(%p)->(IID_InternetZoneManager %p)\n", This, ppvObject);
764 }else if(IsEqualIID(&IID_IInternetZoneManagerEx, riid)) {
765 TRACE("(%p)->(IID_InternetZoneManagerEx %p)\n", This, ppvObject);
766 }else if(IsEqualIID(&IID_IInternetZoneManagerEx2, riid)) {
767 TRACE("(%p)->(IID_InternetZoneManagerEx2 %p)\n", This, ppvObject);
771 FIXME("Unknown interface: %s\n", debugstr_guid(riid));
773 return E_NOINTERFACE;
777 IInternetZoneManager_AddRef(iface);
781 /********************************************************************
782 * IInternetZoneManager_AddRef
784 static ULONG WINAPI ZoneMgrImpl_AddRef(IInternetZoneManagerEx2* iface)
786 ZoneMgrImpl* This = (ZoneMgrImpl*)iface;
787 ULONG refCount = InterlockedIncrement(&This->ref);
789 TRACE("(%p)->(ref before=%u)\n",This, refCount - 1);
794 /********************************************************************
795 * IInternetZoneManager_Release
797 static ULONG WINAPI ZoneMgrImpl_Release(IInternetZoneManagerEx2* iface)
799 ZoneMgrImpl* This = (ZoneMgrImpl*)iface;
800 ULONG refCount = InterlockedDecrement(&This->ref);
802 TRACE("(%p)->(ref before=%u)\n",This, refCount + 1);
805 while (This->zonemap_count) heap_free(This->zonemaps[--This->zonemap_count]);
806 heap_free(This->zonemaps);
808 URLMON_UnlockModule();
814 /********************************************************************
815 * IInternetZoneManager_GetZoneAttributes
817 static HRESULT WINAPI ZoneMgrImpl_GetZoneAttributes(IInternetZoneManagerEx2* iface,
819 ZONEATTRIBUTES* pZoneAttributes)
821 ZoneMgrImpl* This = (ZoneMgrImpl*)iface;
826 TRACE("(%p)->(%d %p)\n", This, dwZone, pZoneAttributes);
828 if (!pZoneAttributes)
831 hr = open_zone_key(HKEY_CURRENT_USER, dwZone, &hcu);
833 return S_OK; /* IE6 and older returned E_FAIL here */
835 hr = open_zone_key(HKEY_LOCAL_MACHINE, dwZone, &hklm);
837 TRACE("Zone %d not in HKLM\n", dwZone);
839 get_string_from_reg(hcu, hklm, displaynameW, pZoneAttributes->szDisplayName, MAX_ZONE_PATH);
840 get_string_from_reg(hcu, hklm, descriptionW, pZoneAttributes->szDescription, MAX_ZONE_DESCRIPTION);
841 get_string_from_reg(hcu, hklm, iconW, pZoneAttributes->szIconPath, MAX_ZONE_PATH);
842 get_dword_from_reg(hcu, hklm, minlevelW, &pZoneAttributes->dwTemplateMinLevel);
843 get_dword_from_reg(hcu, hklm, currentlevelW, &pZoneAttributes->dwTemplateCurrentLevel);
844 get_dword_from_reg(hcu, hklm, recommendedlevelW, &pZoneAttributes->dwTemplateRecommended);
845 get_dword_from_reg(hcu, hklm, flagsW, &pZoneAttributes->dwFlags);
852 /********************************************************************
853 * IInternetZoneManager_SetZoneAttributes
855 static HRESULT WINAPI ZoneMgrImpl_SetZoneAttributes(IInternetZoneManagerEx2* iface,
857 ZONEATTRIBUTES* pZoneAttributes)
859 FIXME("(%p)->(%08x %p) stub\n", iface, dwZone, pZoneAttributes);
863 /********************************************************************
864 * IInternetZoneManager_GetZoneCustomPolicy
866 static HRESULT WINAPI ZoneMgrImpl_GetZoneCustomPolicy(IInternetZoneManagerEx2* iface,
871 URLZONEREG ulrZoneReg)
873 FIXME("(%p)->(%08x %s %p %p %08x) stub\n", iface, dwZone, debugstr_guid(guidKey),
874 ppPolicy, pcbPolicy, ulrZoneReg);
878 /********************************************************************
879 * IInternetZoneManager_SetZoneCustomPolicy
881 static HRESULT WINAPI ZoneMgrImpl_SetZoneCustomPolicy(IInternetZoneManagerEx2* iface,
886 URLZONEREG ulrZoneReg)
888 FIXME("(%p)->(%08x %s %p %08x %08x) stub\n", iface, dwZone, debugstr_guid(guidKey),
889 ppPolicy, cbPolicy, ulrZoneReg);
893 /********************************************************************
894 * IInternetZoneManager_GetZoneActionPolicy
896 static HRESULT WINAPI ZoneMgrImpl_GetZoneActionPolicy(IInternetZoneManagerEx2* iface,
897 DWORD dwZone, DWORD dwAction, BYTE* pPolicy, DWORD cbPolicy, URLZONEREG urlZoneReg)
899 TRACE("(%p)->(%d %08x %p %d %d)\n", iface, dwZone, dwAction, pPolicy,
900 cbPolicy, urlZoneReg);
905 return get_action_policy(dwZone, dwAction, pPolicy, cbPolicy, urlZoneReg);
908 /********************************************************************
909 * IInternetZoneManager_SetZoneActionPolicy
911 static HRESULT WINAPI ZoneMgrImpl_SetZoneActionPolicy(IInternetZoneManagerEx2* iface,
916 URLZONEREG urlZoneReg)
918 FIXME("(%p)->(%08x %08x %p %08x %08x) stub\n", iface, dwZone, dwAction, pPolicy,
919 cbPolicy, urlZoneReg);
923 /********************************************************************
924 * IInternetZoneManager_PromptAction
926 static HRESULT WINAPI ZoneMgrImpl_PromptAction(IInternetZoneManagerEx2* iface,
933 FIXME("%p %08x %p %s %s %08x\n", iface, dwAction, hwndParent,
934 debugstr_w(pwszUrl), debugstr_w(pwszText), dwPromptFlags );
938 /********************************************************************
939 * IInternetZoneManager_LogAction
941 static HRESULT WINAPI ZoneMgrImpl_LogAction(IInternetZoneManagerEx2* iface,
947 FIXME("(%p)->(%08x %s %s %08x) stub\n", iface, dwAction, debugstr_w(pwszUrl),
948 debugstr_w(pwszText), dwLogFlags);
952 /********************************************************************
953 * IInternetZoneManager_CreateZoneEnumerator
955 static HRESULT WINAPI ZoneMgrImpl_CreateZoneEnumerator(IInternetZoneManagerEx2* iface,
960 ZoneMgrImpl* This = (ZoneMgrImpl*)iface;
965 TRACE("(%p)->(%p, %p, 0x%08x)\n", This, pdwEnum, pdwCount, dwFlags);
966 if (!pdwEnum || !pdwCount || (dwFlags != 0))
969 data = build_zonemap_from_reg();
970 TRACE("found %d zones\n", data ? data[0] : -1);
975 for (i = 0; i < This->zonemap_count; i++) {
976 if (This->zonemaps && !This->zonemaps[i]) {
977 This->zonemaps[i] = data;
984 if (This->zonemaps) {
985 /* try to double the nr. of pointers in the array */
986 new_maps = heap_realloc_zero(This->zonemaps, This->zonemap_count * 2 * sizeof(LPDWORD));
988 This->zonemap_count *= 2;
992 This->zonemap_count = 2;
993 new_maps = heap_alloc_zero(This->zonemap_count * sizeof(LPDWORD));
1000 This->zonemaps = new_maps;
1001 This->zonemaps[i] = data;
1003 *pdwCount = data[0];
1007 /********************************************************************
1008 * IInternetZoneManager_GetZoneAt
1010 static HRESULT WINAPI ZoneMgrImpl_GetZoneAt(IInternetZoneManagerEx2* iface,
1015 ZoneMgrImpl* This = (ZoneMgrImpl*)iface;
1018 TRACE("(%p)->(0x%08x, %d, %p)\n", This, dwEnum, dwIndex, pdwZone);
1020 /* make sure, that dwEnum and dwIndex are in the valid range */
1021 if (dwEnum < This->zonemap_count) {
1022 if ((data = This->zonemaps[dwEnum])) {
1023 if (dwIndex < data[0]) {
1024 *pdwZone = data[dwIndex + 1];
1029 return E_INVALIDARG;
1032 /********************************************************************
1033 * IInternetZoneManager_DestroyZoneEnumerator
1035 static HRESULT WINAPI ZoneMgrImpl_DestroyZoneEnumerator(IInternetZoneManagerEx2* iface,
1038 ZoneMgrImpl* This = (ZoneMgrImpl*)iface;
1041 TRACE("(%p)->(0x%08x)\n", This, dwEnum);
1042 /* make sure, that dwEnum is valid */
1043 if (dwEnum < This->zonemap_count) {
1044 if ((data = This->zonemaps[dwEnum])) {
1045 This->zonemaps[dwEnum] = NULL;
1050 return E_INVALIDARG;
1053 /********************************************************************
1054 * IInternetZoneManager_CopyTemplatePoliciesToZone
1056 static HRESULT WINAPI ZoneMgrImpl_CopyTemplatePoliciesToZone(IInternetZoneManagerEx2* iface,
1061 FIXME("(%p)->(%08x %08x %08x) stub\n", iface, dwTemplate, dwZone, dwReserved);
1065 /********************************************************************
1066 * IInternetZoneManagerEx_GetZoneActionPolicyEx
1068 static HRESULT WINAPI ZoneMgrImpl_GetZoneActionPolicyEx(IInternetZoneManagerEx2* iface,
1073 URLZONEREG urlZoneReg,
1076 TRACE("(%p)->(%d, 0x%x, %p, %d, %d, 0x%x)\n", iface, dwZone,
1077 dwAction, pPolicy, cbPolicy, urlZoneReg, dwFlags);
1080 return E_INVALIDARG;
1083 FIXME("dwFlags 0x%x ignored\n", dwFlags);
1085 return get_action_policy(dwZone, dwAction, pPolicy, cbPolicy, urlZoneReg);
1088 /********************************************************************
1089 * IInternetZoneManagerEx_SetZoneActionPolicyEx
1091 static HRESULT WINAPI ZoneMgrImpl_SetZoneActionPolicyEx(IInternetZoneManagerEx2* iface,
1096 URLZONEREG urlZoneReg,
1099 FIXME("(%p)->(%d, 0x%x, %p, %d, %d, 0x%x) stub\n", iface, dwZone, dwAction, pPolicy,
1100 cbPolicy, urlZoneReg, dwFlags);
1104 /********************************************************************
1105 * IInternetZoneManagerEx2_GetZoneAttributesEx
1107 static HRESULT WINAPI ZoneMgrImpl_GetZoneAttributesEx(IInternetZoneManagerEx2* iface,
1109 ZONEATTRIBUTES* pZoneAttributes,
1112 TRACE("(%p)->(%d, %p, 0x%x)\n", iface, dwZone, pZoneAttributes, dwFlags);
1115 FIXME("dwFlags 0x%x ignored\n", dwFlags);
1117 return IInternetZoneManager_GetZoneAttributes(iface, dwZone, pZoneAttributes);
1121 /********************************************************************
1122 * IInternetZoneManagerEx2_GetZoneSecurityState
1124 static HRESULT WINAPI ZoneMgrImpl_GetZoneSecurityState(IInternetZoneManagerEx2* iface,
1126 BOOL fRespectPolicy,
1128 BOOL *pfPolicyEncountered)
1130 FIXME("(%p)->(%d, %d, %p, %p) stub\n", iface, dwZoneIndex, fRespectPolicy,
1131 pdwState, pfPolicyEncountered);
1133 *pdwState = SECURITY_IE_STATE_GREEN;
1135 if (pfPolicyEncountered)
1136 *pfPolicyEncountered = FALSE;
1141 /********************************************************************
1142 * IInternetZoneManagerEx2_GetIESecurityState
1144 static HRESULT WINAPI ZoneMgrImpl_GetIESecurityState(IInternetZoneManagerEx2* iface,
1145 BOOL fRespectPolicy,
1147 BOOL *pfPolicyEncountered,
1150 FIXME("(%p)->(%d, %p, %p, %d) stub\n", iface, fRespectPolicy, pdwState,
1151 pfPolicyEncountered, fNoCache);
1153 *pdwState = SECURITY_IE_STATE_GREEN;
1155 if (pfPolicyEncountered)
1156 *pfPolicyEncountered = FALSE;
1161 /********************************************************************
1162 * IInternetZoneManagerEx2_FixInsecureSettings
1164 static HRESULT WINAPI ZoneMgrImpl_FixInsecureSettings(IInternetZoneManagerEx2* iface)
1166 FIXME("(%p) stub\n", iface);
1170 /********************************************************************
1171 * IInternetZoneManager_Construct
1173 static const IInternetZoneManagerEx2Vtbl ZoneMgrImplVtbl = {
1174 ZoneMgrImpl_QueryInterface,
1176 ZoneMgrImpl_Release,
1177 /* IInternetZoneManager */
1178 ZoneMgrImpl_GetZoneAttributes,
1179 ZoneMgrImpl_SetZoneAttributes,
1180 ZoneMgrImpl_GetZoneCustomPolicy,
1181 ZoneMgrImpl_SetZoneCustomPolicy,
1182 ZoneMgrImpl_GetZoneActionPolicy,
1183 ZoneMgrImpl_SetZoneActionPolicy,
1184 ZoneMgrImpl_PromptAction,
1185 ZoneMgrImpl_LogAction,
1186 ZoneMgrImpl_CreateZoneEnumerator,
1187 ZoneMgrImpl_GetZoneAt,
1188 ZoneMgrImpl_DestroyZoneEnumerator,
1189 ZoneMgrImpl_CopyTemplatePoliciesToZone,
1190 /* IInternetZoneManagerEx */
1191 ZoneMgrImpl_GetZoneActionPolicyEx,
1192 ZoneMgrImpl_SetZoneActionPolicyEx,
1193 /* IInternetZoneManagerEx2 */
1194 ZoneMgrImpl_GetZoneAttributesEx,
1195 ZoneMgrImpl_GetZoneSecurityState,
1196 ZoneMgrImpl_GetIESecurityState,
1197 ZoneMgrImpl_FixInsecureSettings,
1200 HRESULT ZoneMgrImpl_Construct(IUnknown *pUnkOuter, LPVOID *ppobj)
1202 ZoneMgrImpl* ret = heap_alloc_zero(sizeof(ZoneMgrImpl));
1204 TRACE("(%p %p)\n", pUnkOuter, ppobj);
1205 ret->lpVtbl = &ZoneMgrImplVtbl;
1207 *ppobj = (IInternetZoneManagerEx*)ret;
1209 URLMON_LockModule();
1214 /***********************************************************************
1215 * CoInternetCreateSecurityManager (URLMON.@)
1218 HRESULT WINAPI CoInternetCreateSecurityManager( IServiceProvider *pSP,
1219 IInternetSecurityManager **ppSM, DWORD dwReserved )
1221 TRACE("%p %p %d\n", pSP, ppSM, dwReserved );
1224 FIXME("pSP not supported\n");
1226 return SecManagerImpl_Construct(NULL, (void**) ppSM);
1229 /********************************************************************
1230 * CoInternetCreateZoneManager (URLMON.@)
1232 HRESULT WINAPI CoInternetCreateZoneManager(IServiceProvider* pSP, IInternetZoneManager** ppZM, DWORD dwReserved)
1234 TRACE("(%p %p %x)\n", pSP, ppZM, dwReserved);
1235 return ZoneMgrImpl_Construct(NULL, (void**)ppZM);
1238 /********************************************************************
1239 * CoInternetGetSecurityUrl (URLMON.@)
1241 HRESULT WINAPI CoInternetGetSecurityUrl(LPCWSTR pwzUrl, LPWSTR *ppwzSecUrl, PSUACTION psuAction, DWORD dwReserved)
1243 WCHAR buf1[INTERNET_MAX_URL_LENGTH], buf2[INTERNET_MAX_URL_LENGTH];
1248 TRACE("(%p,%p,%u,%u)\n", pwzUrl, ppwzSecUrl, psuAction, dwReserved);
1252 strcpyW(url, pwzUrl);
1255 hres = CoInternetParseUrl(url, PARSE_SECURITY_URL, 0, domain, INTERNET_MAX_URL_LENGTH, &len, 0);
1256 if(hres!=S_OK || !strcmpW(url, domain))
1268 if(psuAction==PSU_SECURITY_URL_ONLY) {
1269 len = lstrlenW(url)+1;
1270 *ppwzSecUrl = CoTaskMemAlloc(len*sizeof(WCHAR));
1272 return E_OUTOFMEMORY;
1274 memcpy(*ppwzSecUrl, url, len*sizeof(WCHAR));
1278 hres = CoInternetParseUrl(url, PARSE_SECURITY_DOMAIN, 0, domain,
1279 INTERNET_MAX_URL_LENGTH, &len, 0);
1280 if(SUCCEEDED(hres)) {
1282 *ppwzSecUrl = CoTaskMemAlloc(len*sizeof(WCHAR));
1284 return E_OUTOFMEMORY;
1286 memcpy(*ppwzSecUrl, domain, len*sizeof(WCHAR));
1290 hres = CoInternetParseUrl(url, PARSE_SCHEMA, 0, domain,
1291 INTERNET_MAX_URL_LENGTH, &len, 0);
1293 const WCHAR fileW[] = {'f','i','l','e',0};
1294 if(!strcmpW(domain, fileW)){
1295 hres = CoInternetParseUrl(url, PARSE_ROOTDOCUMENT, 0, domain, INTERNET_MAX_URL_LENGTH, &len, 0);
1298 hres = CoInternetParseUrl(url, PARSE_DOMAIN, 0, domain+len+1,
1299 INTERNET_MAX_URL_LENGTH-len-1, &len, 0);
1301 len = lstrlenW(domain)+1;
1302 *ppwzSecUrl = CoTaskMemAlloc(len*sizeof(WCHAR));
1304 return E_OUTOFMEMORY;
1306 memcpy(*ppwzSecUrl, domain, len*sizeof(WCHAR));
1313 len = lstrlenW(url)+1;
1314 *ppwzSecUrl = CoTaskMemAlloc(len*sizeof(WCHAR));
1316 return E_OUTOFMEMORY;
1318 memcpy(*ppwzSecUrl, url, len*sizeof(WCHAR));