2 * Internet Security and Zone Manager
4 * Copyright (c) 2004 Huw D M Davies
5 * Copyright 2004 Jacek Caban
6 * Copyright 2009 Detlef Riekenberg
7 * Copyright 2011 Thomas Mullaly for CodeWeavers
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
26 #include "urlmon_main.h"
30 #define NO_SHLWAPI_REG
33 #include "wine/debug.h"
35 WINE_DEFAULT_DEBUG_CHANNEL(urlmon);
37 static const WCHAR currentlevelW[] = {'C','u','r','r','e','n','t','L','e','v','e','l',0};
38 static const WCHAR descriptionW[] = {'D','e','s','c','r','i','p','t','i','o','n',0};
39 static const WCHAR displaynameW[] = {'D','i','s','p','l','a','y','N','a','m','e',0};
40 static const WCHAR fileW[] = {'f','i','l','e',0};
41 static const WCHAR flagsW[] = {'F','l','a','g','s',0};
42 static const WCHAR iconW[] = {'I','c','o','n',0};
43 static const WCHAR minlevelW[] = {'M','i','n','L','e','v','e','l',0};
44 static const WCHAR recommendedlevelW[] = {'R','e','c','o','m','m','e','n','d','e','d',
45 'L','e','v','e','l',0};
46 static const WCHAR wszZonesKey[] = {'S','o','f','t','w','a','r','e','\\',
47 'M','i','c','r','o','s','o','f','t','\\',
48 'W','i','n','d','o','w','s','\\',
49 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
50 'I','n','t','e','r','n','e','t',' ','S','e','t','t','i','n','g','s','\\',
51 'Z','o','n','e','s','\\',0};
52 static const WCHAR wszZoneMapDomainsKey[] = {'S','o','f','t','w','a','r','e','\\',
53 'M','i','c','r','o','s','o','f','t','\\',
54 'W','i','n','d','o','w','s','\\',
55 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
56 'I','n','t','e','r','n','e','t',' ','S','e','t','t','i','n','g','s','\\',
57 'Z','o','n','e','M','a','p','\\',
58 'D','o','m','a','i','n','s',0};
60 static inline BOOL is_drive_path(const WCHAR *path)
62 return isalphaW(*path) && *(path+1) == ':';
65 /********************************************************************
66 * get_string_from_reg [internal]
68 * helper to get a string from the reg.
71 static void get_string_from_reg(HKEY hcu, HKEY hklm, LPCWSTR name, LPWSTR out, DWORD maxlen)
74 DWORD len = maxlen * sizeof(WCHAR);
77 res = RegQueryValueExW(hcu, name, NULL, &type, (LPBYTE) out, &len);
80 len = maxlen * sizeof(WCHAR);
82 res = RegQueryValueExW(hklm, name, NULL, &type, (LPBYTE) out, &len);
86 TRACE("%s failed: %d\n", debugstr_w(name), res);
91 /********************************************************************
92 * get_dword_from_reg [internal]
94 * helper to get a dword from the reg.
97 static void get_dword_from_reg(HKEY hcu, HKEY hklm, LPCWSTR name, LPDWORD out)
99 DWORD type = REG_DWORD;
100 DWORD len = sizeof(DWORD);
103 res = RegQueryValueExW(hcu, name, NULL, &type, (LPBYTE) out, &len);
108 res = RegQueryValueExW(hklm, name, NULL, &type, (LPBYTE) out, &len);
112 TRACE("%s failed: %d\n", debugstr_w(name), res);
117 static HRESULT get_zone_from_reg(LPCWSTR schema, DWORD *zone)
122 static const WCHAR wszZoneMapProtocolKey[] =
123 {'S','o','f','t','w','a','r','e','\\',
124 'M','i','c','r','o','s','o','f','t','\\',
125 'W','i','n','d','o','w','s','\\',
126 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
127 'I','n','t','e','r','n','e','t',' ','S','e','t','t','i','n','g','s','\\',
128 'Z','o','n','e','M','a','p','\\',
129 'P','r','o','t','o','c','o','l','D','e','f','a','u','l','t','s',0};
131 res = RegOpenKeyW(HKEY_CURRENT_USER, wszZoneMapProtocolKey, &hkey);
132 if(res != ERROR_SUCCESS) {
133 ERR("Could not open key %s\n", debugstr_w(wszZoneMapProtocolKey));
137 size = sizeof(DWORD);
138 res = RegQueryValueExW(hkey, schema, NULL, NULL, (PBYTE)zone, &size);
140 if(res == ERROR_SUCCESS)
143 res = RegOpenKeyW(HKEY_LOCAL_MACHINE, wszZoneMapProtocolKey, &hkey);
144 if(res != ERROR_SUCCESS) {
145 ERR("Could not open key %s\n", debugstr_w(wszZoneMapProtocolKey));
149 size = sizeof(DWORD);
150 res = RegQueryValueExW(hkey, schema, NULL, NULL, (PBYTE)zone, &size);
152 if(res == ERROR_SUCCESS)
159 /********************************************************************
160 * matches_domain_pattern [internal]
162 * Checks if the given string matches the specified domain pattern.
164 * This function looks for explicit wildcard domain components iff
165 * they appear at the very beginning of the 'pattern' string
167 * pattern = "*.google.com"
169 static BOOL matches_domain_pattern(LPCWSTR pattern, LPCWSTR str, BOOL implicit_wildcard, LPCWSTR *matched)
171 BOOL matches = FALSE;
172 DWORD pattern_len = strlenW(pattern);
173 DWORD str_len = strlenW(str);
175 TRACE("(%d) Checking if %s matches %s\n", implicit_wildcard, debugstr_w(str), debugstr_w(pattern));
178 if(str_len >= pattern_len) {
179 /* Check if there's an explicit wildcard in the pattern. */
180 if(pattern[0] == '*' && pattern[1] == '.') {
181 /* Make sure that 'str' matches the wildcard pattern.
184 * pattern = "*.google.com"
186 * So in this case 'str' would have to end with ".google.com" in order
187 * to map to this pattern.
189 if(str_len >= pattern_len+1 && !strcmpiW(str+(str_len-pattern_len+1), pattern+1)) {
190 /* Check if there's another '.' inside of the "unmatched" portion
194 * pattern = "*.google.com"
195 * str = "test.testing.google.com"
197 * The currently matched portion is ".google.com" in 'str', we need
198 * see if there's a '.' inside of the unmatched portion ("test.testing"), because
199 * if there is and 'implicit_wildcard' isn't set, then this isn't
203 if(str_len > pattern_len+1 && (ptr = memrchrW(str, '.', str_len-pattern_len-2))) {
204 if(implicit_wildcard) {
213 } else if(implicit_wildcard && str_len > pattern_len) {
214 /* When the pattern has an implicit wildcard component, it means
215 * that anything goes in 'str' as long as it ends with the pattern
216 * and that the beginning of the match has a '.' before it.
219 * pattern = "google.com"
220 * str = "www.google.com"
222 * Implicitly matches the pattern, where as:
224 * pattern = "google.com"
225 * str = "wwwgoogle.com"
227 * Doesn't match the pattern.
229 if(str_len > pattern_len) {
230 if(str[str_len-pattern_len-1] == '.' && !strcmpiW(str+(str_len-pattern_len), pattern)) {
232 *matched = str+(str_len-pattern_len);
236 /* The pattern doesn't have an implicit wildcard, or an explicit wildcard,
237 * so 'str' has to be an exact match to the 'pattern'.
239 if(!strcmpiW(str, pattern)) {
247 TRACE("Found a match: matched=%s\n", debugstr_w(*matched));
249 TRACE("No match found\n");
254 static BOOL get_zone_for_scheme(HKEY key, LPCWSTR schema, DWORD *zone)
256 static const WCHAR wildcardW[] = {'*',0};
259 DWORD size = sizeof(DWORD);
262 /* See if the key contains a value for the scheme first. */
263 res = RegQueryValueExW(key, schema, NULL, &type, (BYTE*)zone, &size);
264 if(res == ERROR_SUCCESS) {
265 if(type == REG_DWORD)
267 WARN("Unexpected value type %d for value %s, expected REG_DWORD\n", type, debugstr_w(schema));
270 /* Try to get the zone for the wildcard scheme. */
271 size = sizeof(DWORD);
272 res = RegQueryValueExW(key, wildcardW, NULL, &type, (BYTE*)zone, &size);
273 if(res != ERROR_SUCCESS)
276 if(type != REG_DWORD) {
277 WARN("Unexpected value type %d for value %s, expected REG_DWORD\n", type, debugstr_w(wildcardW));
284 /********************************************************************
285 * search_domain_for_zone [internal]
287 * Searches the specified 'domain' registry key to see if 'host' maps into it, or any
288 * of it's subdomain registry keys.
290 * Returns S_OK if a match is found, S_FALSE if no matches were found, or an error code.
292 static HRESULT search_domain_for_zone(HKEY domains, LPCWSTR domain, DWORD domain_len, LPCWSTR schema,
293 LPCWSTR host, DWORD host_len, DWORD *zone)
300 if(host_len >= domain_len && matches_domain_pattern(domain, host, TRUE, &matched)) {
301 res = RegOpenKeyW(domains, domain, &domain_key);
302 if(res != ERROR_SUCCESS) {
303 ERR("Failed to open domain key %s: %d\n", debugstr_w(domain), res);
308 found = get_zone_for_scheme(domain_key, schema, zone);
311 DWORD subdomain_count, subdomain_len;
312 BOOL check_domain = TRUE;
314 find_domain_name(domain, domain_len, &domain_offset);
316 res = RegQueryInfoKeyW(domain_key, NULL, NULL, NULL, &subdomain_count, &subdomain_len,
317 NULL, NULL, NULL, NULL, NULL, NULL);
318 if(res != ERROR_SUCCESS) {
319 ERR("Unable to query info for key %s: %d\n", debugstr_w(domain), res);
320 RegCloseKey(domain_key);
324 if(subdomain_count) {
329 subdomain = heap_alloc((subdomain_len+1)*sizeof(WCHAR));
331 RegCloseKey(domain_key);
332 return E_OUTOFMEMORY;
335 component = heap_strndupW(host, matched-host-1);
337 heap_free(subdomain);
338 RegCloseKey(domain_key);
339 return E_OUTOFMEMORY;
342 for(i = 0; i < subdomain_count; ++i) {
343 DWORD len = subdomain_len+1;
344 const WCHAR *sub_matched;
346 res = RegEnumKeyExW(domain_key, i, subdomain, &len, NULL, NULL, NULL, NULL);
347 if(res != ERROR_SUCCESS) {
348 heap_free(component);
349 heap_free(subdomain);
350 RegCloseKey(domain_key);
354 if(matches_domain_pattern(subdomain, component, FALSE, &sub_matched)) {
357 res = RegOpenKeyW(domain_key, subdomain, &subdomain_key);
358 if(res != ERROR_SUCCESS) {
359 ERR("Unable to open subdomain key %s of %s: %d\n", debugstr_w(subdomain),
360 debugstr_w(domain), res);
361 heap_free(component);
362 heap_free(subdomain);
363 RegCloseKey(domain_key);
367 found = get_zone_for_scheme(subdomain_key, schema, zone);
368 check_domain = FALSE;
369 RegCloseKey(subdomain_key);
373 heap_free(subdomain);
374 heap_free(component);
377 /* There's a chance that 'host' implicitly mapped into 'domain', in
378 * which case we check to see if 'domain' contains zone information.
380 * This can only happen if 'domain' is it's own domain name.
382 * "google.com" (domain name = "google.com")
385 * host = "www.google.com"
387 * Then host would map directly into the "google.com" domain key.
389 * If 'domain' has more than just it's domain name, or it does not
390 * have a domain name, then we don't perform the check. The reason
391 * for this is that these domains don't allow implicit mappings.
393 * domain = "org" (has no domain name)
396 * The mapping would only happen if the "org" key had an explicit subkey
399 if(check_domain && !domain_offset && !strchrW(host, matched-host-1))
400 found = get_zone_for_scheme(domain_key, schema, zone);
402 RegCloseKey(domain_key);
405 return found ? S_OK : S_FALSE;
408 static HRESULT search_for_domain_mapping(HKEY domains, LPCWSTR schema, LPCWSTR host, DWORD host_len, DWORD *zone)
411 DWORD domain_count, domain_len, i;
413 HRESULT hres = S_FALSE;
415 res = RegQueryInfoKeyW(domains, NULL, NULL, NULL, &domain_count, &domain_len,
416 NULL, NULL, NULL, NULL, NULL, NULL);
417 if(res != ERROR_SUCCESS) {
418 WARN("Failed to retrieve information about key\n");
425 domain = heap_alloc((domain_len+1)*sizeof(WCHAR));
427 return E_OUTOFMEMORY;
429 for(i = 0; i < domain_count; ++i) {
430 DWORD len = domain_len+1;
432 res = RegEnumKeyExW(domains, i, domain, &len, NULL, NULL, NULL, NULL);
433 if(res != ERROR_SUCCESS) {
438 hres = search_domain_for_zone(domains, domain, len, schema, host, host_len, zone);
439 if(FAILED(hres) || hres == S_OK)
447 static HRESULT get_zone_from_domains(IUri *uri, DWORD *zone)
455 hres = IUri_GetScheme(uri, &scheme_type);
459 /* Windows doesn't play nice with unknown scheme types when it tries
460 * to check if a host name maps into any domains.
462 if(scheme_type == URL_SCHEME_UNKNOWN)
465 hres = IUri_GetHost(uri, &host);
469 hres = IUri_GetSchemeName(uri, &scheme);
475 /* First try CURRENT_USER. */
476 res = RegOpenKeyW(HKEY_CURRENT_USER, wszZoneMapDomainsKey, &domains);
477 if(res == ERROR_SUCCESS) {
478 hres = search_for_domain_mapping(domains, scheme, host, SysStringLen(host), zone);
479 RegCloseKey(domains);
481 WARN("Failed to open HKCU's %s key\n", debugstr_w(wszZoneMapDomainsKey));
483 /* If that doesn't work try LOCAL_MACHINE. */
484 if(hres == S_FALSE) {
485 res = RegOpenKeyW(HKEY_LOCAL_MACHINE, wszZoneMapDomainsKey, &domains);
486 if(res == ERROR_SUCCESS) {
487 hres = search_for_domain_mapping(domains, scheme, host, SysStringLen(host), zone);
488 RegCloseKey(domains);
490 WARN("Failed to open HKLM's %s key\n", debugstr_w(wszZoneMapDomainsKey));
494 SysFreeString(scheme);
498 static HRESULT map_security_uri_to_zone(IUri *uri, DWORD *zone)
503 *zone = URLZONE_INVALID;
505 hres = IUri_GetSchemeName(uri, &scheme);
509 if(!strcmpiW(scheme, fileW)) {
511 WCHAR *ptr, *path_start, root[20];
513 hres = IUri_GetPath(uri, &path);
515 SysFreeString(scheme);
519 if(*path == '/' && is_drive_path(path+1))
524 if(((ptr = strchrW(path_start, '\\')) || (ptr = strchrW(path_start, '/'))) && ptr-path_start < sizeof(root)/sizeof(WCHAR)) {
527 memcpy(root, path_start, (ptr-path_start)*sizeof(WCHAR));
528 root[ptr-path_start] = 0;
530 type = GetDriveTypeW(root);
534 case DRIVE_NO_ROOT_DIR:
536 case DRIVE_REMOVABLE:
540 *zone = URLZONE_LOCAL_MACHINE;
544 *zone = URLZONE_INTERNET;
548 FIXME("unsupported drive type %d\n", type);
554 if(*zone == URLZONE_INVALID) {
555 hres = get_zone_from_domains(uri, zone);
557 hres = get_zone_from_reg(scheme, zone);
560 SysFreeString(scheme);
564 static HRESULT map_url_to_zone(LPCWSTR url, DWORD *zone, LPWSTR *ret_url)
570 *zone = URLZONE_INVALID;
572 hres = CoInternetGetSecurityUrl(url, &secur_url, PSU_SECURITY_URL_ONLY, 0);
574 DWORD size = strlenW(url)*sizeof(WCHAR);
576 secur_url = CoTaskMemAlloc(size);
578 return E_OUTOFMEMORY;
580 memcpy(secur_url, url, size);
583 hres = CreateUri(secur_url, 0, 0, &secur_uri);
585 CoTaskMemFree(secur_url);
589 hres = map_security_uri_to_zone(secur_uri, zone);
590 IUri_Release(secur_uri);
592 if(FAILED(hres) || !ret_url)
593 CoTaskMemFree(secur_url);
595 *ret_url = secur_url;
600 static HRESULT map_uri_to_zone(IUri *uri, DWORD *zone)
605 hres = CoInternetGetSecurityUrlEx(uri, &secur_uri, PSU_SECURITY_URL_ONLY, 0);
609 hres = map_security_uri_to_zone(secur_uri, zone);
610 IUri_Release(secur_uri);
615 static HRESULT open_zone_key(HKEY parent_key, DWORD zone, HKEY *hkey)
617 static const WCHAR wszFormat[] = {'%','s','%','u',0};
619 WCHAR key_name[sizeof(wszZonesKey)/sizeof(WCHAR)+12];
622 wsprintfW(key_name, wszFormat, wszZonesKey, zone);
624 res = RegOpenKeyW(parent_key, key_name, hkey);
626 if(res != ERROR_SUCCESS) {
627 WARN("RegOpenKey failed\n");
634 static HRESULT get_action_policy(DWORD zone, DWORD action, BYTE *policy, DWORD size, URLZONEREG zone_reg)
642 case URLACTION_SCRIPT_OVERRIDE_SAFETY:
643 case URLACTION_ACTIVEX_OVERRIDE_SCRIPT_SAFETY:
644 *(DWORD*)policy = URLPOLICY_DISALLOW;
649 case URLZONEREG_DEFAULT:
650 case URLZONEREG_HKCU:
651 parent_key = HKEY_CURRENT_USER;
653 case URLZONEREG_HKLM:
654 parent_key = HKEY_LOCAL_MACHINE;
657 WARN("Unknown URLZONEREG: %d\n", zone_reg);
661 hres = open_zone_key(parent_key, zone, &hkey);
662 if(SUCCEEDED(hres)) {
663 WCHAR action_str[16];
666 static const WCHAR formatW[] = {'%','X',0};
668 wsprintfW(action_str, formatW, action);
670 res = RegQueryValueExW(hkey, action_str, NULL, NULL, policy, &len);
671 if(res == ERROR_MORE_DATA) {
673 }else if(res == ERROR_FILE_NOT_FOUND) {
675 }else if(res != ERROR_SUCCESS) {
676 ERR("RegQueryValue failed: %d\n", res);
683 if(FAILED(hres) && zone_reg == URLZONEREG_DEFAULT)
684 return get_action_policy(zone, action, policy, size, URLZONEREG_HKLM);
689 static HRESULT get_security_id(LPCWSTR url, BYTE *secid, DWORD *secid_len)
691 LPWSTR secur_url, ptr, ptr2;
695 static const WCHAR wszFile[] = {'f','i','l','e',':'};
697 hres = map_url_to_zone(url, &zone, &secur_url);
699 return hres == 0x80041001 ? E_INVALIDARG : hres;
701 /* file protocol is a special case */
702 if(strlenW(secur_url) >= sizeof(wszFile)/sizeof(WCHAR)
703 && !memcmp(secur_url, wszFile, sizeof(wszFile))) {
704 WCHAR path[MAX_PATH];
705 len = sizeof(path)/sizeof(WCHAR);
707 hres = CoInternetParseUrl(secur_url, PARSE_PATH_FROM_URL, 0, path, len, &len, 0);
708 if(hres == S_OK && !PathIsNetworkPathW(path)) {
709 static const BYTE secidFile[] = {'f','i','l','e',':'};
711 CoTaskMemFree(secur_url);
713 if(*secid_len < sizeof(secidFile)+sizeof(zone))
714 return HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER);
716 memcpy(secid, secidFile, sizeof(secidFile));
717 *(DWORD*)(secid+sizeof(secidFile)) = zone;
719 *secid_len = sizeof(secidFile)+sizeof(zone);
724 ptr = strchrW(secur_url, ':');
729 memmove(ptr, ptr2, (strlenW(ptr2)+1)*sizeof(WCHAR));
731 ptr = strchrW(ptr, '/');
735 len = WideCharToMultiByte(CP_ACP, 0, secur_url, -1, NULL, 0, NULL, NULL)-1;
737 if(len+sizeof(DWORD) > *secid_len) {
738 CoTaskMemFree(secur_url);
739 return HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER);
742 WideCharToMultiByte(CP_ACP, 0, secur_url, -1, (LPSTR)secid, len, NULL, NULL);
743 CoTaskMemFree(secur_url);
745 *(DWORD*)(secid+len) = zone;
747 *secid_len = len+sizeof(DWORD);
752 /***********************************************************************
753 * InternetSecurityManager implementation
757 IInternetSecurityManagerEx2 IInternetSecurityManagerEx2_iface;
761 IInternetSecurityMgrSite *mgrsite;
762 IInternetSecurityManager *custom_manager;
765 static inline SecManagerImpl *impl_from_IInternetSecurityManagerEx2(IInternetSecurityManagerEx2 *iface)
767 return CONTAINING_RECORD(iface, SecManagerImpl, IInternetSecurityManagerEx2_iface);
770 static HRESULT WINAPI SecManagerImpl_QueryInterface(IInternetSecurityManagerEx2* iface,REFIID riid,void** ppvObject)
772 SecManagerImpl *This = impl_from_IInternetSecurityManagerEx2(iface);
774 TRACE("(%p)->(%s,%p)\n",This,debugstr_guid(riid),ppvObject);
776 /* Perform a sanity check on the parameters.*/
777 if ( (This==0) || (ppvObject==0) )
780 /* Initialize the return parameter */
783 /* Compare the riid with the interface IDs implemented by this object.*/
784 if (IsEqualIID(&IID_IUnknown, riid) ||
785 IsEqualIID(&IID_IInternetSecurityManager, riid) ||
786 IsEqualIID(&IID_IInternetSecurityManagerEx, riid) ||
787 IsEqualIID(&IID_IInternetSecurityManagerEx2, riid))
790 /* Check that we obtained an interface.*/
792 WARN("not supported interface %s\n", debugstr_guid(riid));
793 return E_NOINTERFACE;
796 /* Query Interface always increases the reference count by one when it is successful */
797 IInternetSecurityManager_AddRef(iface);
802 static ULONG WINAPI SecManagerImpl_AddRef(IInternetSecurityManagerEx2* iface)
804 SecManagerImpl *This = impl_from_IInternetSecurityManagerEx2(iface);
805 ULONG refCount = InterlockedIncrement(&This->ref);
807 TRACE("(%p) ref=%u\n", This, refCount);
812 static ULONG WINAPI SecManagerImpl_Release(IInternetSecurityManagerEx2* iface)
814 SecManagerImpl *This = impl_from_IInternetSecurityManagerEx2(iface);
815 ULONG refCount = InterlockedDecrement(&This->ref);
817 TRACE("(%p) ref=%u\n", This, refCount);
819 /* destroy the object if there's no more reference on it */
822 IInternetSecurityMgrSite_Release(This->mgrsite);
823 if(This->custom_manager)
824 IInternetSecurityManager_Release(This->custom_manager);
828 URLMON_UnlockModule();
834 static HRESULT WINAPI SecManagerImpl_SetSecuritySite(IInternetSecurityManagerEx2 *iface,
835 IInternetSecurityMgrSite *pSite)
837 SecManagerImpl *This = impl_from_IInternetSecurityManagerEx2(iface);
839 TRACE("(%p)->(%p)\n", This, pSite);
842 IInternetSecurityMgrSite_Release(This->mgrsite);
844 if(This->custom_manager) {
845 IInternetSecurityManager_Release(This->custom_manager);
846 This->custom_manager = NULL;
849 This->mgrsite = pSite;
852 IServiceProvider *servprov;
855 IInternetSecurityMgrSite_AddRef(pSite);
857 hres = IInternetSecurityMgrSite_QueryInterface(pSite, &IID_IServiceProvider,
859 if(SUCCEEDED(hres)) {
860 IServiceProvider_QueryService(servprov, &SID_SInternetSecurityManager,
861 &IID_IInternetSecurityManager, (void**)&This->custom_manager);
862 IServiceProvider_Release(servprov);
869 static HRESULT WINAPI SecManagerImpl_GetSecuritySite(IInternetSecurityManagerEx2 *iface,
870 IInternetSecurityMgrSite **ppSite)
872 SecManagerImpl *This = impl_from_IInternetSecurityManagerEx2(iface);
874 TRACE("(%p)->(%p)\n", This, ppSite);
880 IInternetSecurityMgrSite_AddRef(This->mgrsite);
882 *ppSite = This->mgrsite;
886 static HRESULT WINAPI SecManagerImpl_MapUrlToZone(IInternetSecurityManagerEx2 *iface,
887 LPCWSTR pwszUrl, DWORD *pdwZone,
890 SecManagerImpl *This = impl_from_IInternetSecurityManagerEx2(iface);
893 TRACE("(%p)->(%s %p %08x)\n", iface, debugstr_w(pwszUrl), pdwZone, dwFlags);
895 if(This->custom_manager) {
896 hres = IInternetSecurityManager_MapUrlToZone(This->custom_manager,
897 pwszUrl, pdwZone, dwFlags);
898 if(hres != INET_E_DEFAULT_ACTION)
903 *pdwZone = URLZONE_INVALID;
908 FIXME("not supported flags: %08x\n", dwFlags);
910 return map_url_to_zone(pwszUrl, pdwZone, NULL);
913 static HRESULT WINAPI SecManagerImpl_GetSecurityId(IInternetSecurityManagerEx2 *iface,
914 LPCWSTR pwszUrl, BYTE *pbSecurityId, DWORD *pcbSecurityId, DWORD_PTR dwReserved)
916 SecManagerImpl *This = impl_from_IInternetSecurityManagerEx2(iface);
918 TRACE("(%p)->(%s %p %p %08lx)\n", iface, debugstr_w(pwszUrl), pbSecurityId,
919 pcbSecurityId, dwReserved);
921 if(This->custom_manager) {
924 hres = IInternetSecurityManager_GetSecurityId(This->custom_manager,
925 pwszUrl, pbSecurityId, pcbSecurityId, dwReserved);
926 if(hres != INET_E_DEFAULT_ACTION)
930 if(!pwszUrl || !pbSecurityId || !pcbSecurityId)
934 FIXME("dwReserved is not supported\n");
936 return get_security_id(pwszUrl, pbSecurityId, pcbSecurityId);
940 static HRESULT WINAPI SecManagerImpl_ProcessUrlAction(IInternetSecurityManagerEx2 *iface,
941 LPCWSTR pwszUrl, DWORD dwAction,
942 BYTE *pPolicy, DWORD cbPolicy,
943 BYTE *pContext, DWORD cbContext,
944 DWORD dwFlags, DWORD dwReserved)
946 SecManagerImpl *This = impl_from_IInternetSecurityManagerEx2(iface);
950 TRACE("(%p)->(%s %08x %p %08x %p %08x %08x %08x)\n", iface, debugstr_w(pwszUrl), dwAction,
951 pPolicy, cbPolicy, pContext, cbContext, dwFlags, dwReserved);
953 if(This->custom_manager) {
954 hres = IInternetSecurityManager_ProcessUrlAction(This->custom_manager, pwszUrl, dwAction,
955 pPolicy, cbPolicy, pContext, cbContext, dwFlags, dwReserved);
956 if(hres != INET_E_DEFAULT_ACTION)
960 if(dwFlags || dwReserved)
961 FIXME("Unsupported arguments\n");
966 hres = map_url_to_zone(pwszUrl, &zone, NULL);
970 hres = get_action_policy(zone, dwAction, (BYTE*)&policy, sizeof(policy), URLZONEREG_DEFAULT);
974 TRACE("policy %x\n", policy);
975 if(cbPolicy >= sizeof(DWORD))
976 *(DWORD*)pPolicy = policy;
978 switch(GetUrlPolicyPermissions(policy)) {
979 case URLPOLICY_ALLOW:
980 case URLPOLICY_CHANNEL_SOFTDIST_PRECACHE:
982 case URLPOLICY_DISALLOW:
984 case URLPOLICY_QUERY:
985 FIXME("URLPOLICY_QUERY not implemented\n");
988 FIXME("Not implemented policy %x\n", policy);
995 static HRESULT WINAPI SecManagerImpl_QueryCustomPolicy(IInternetSecurityManagerEx2 *iface,
996 LPCWSTR pwszUrl, REFGUID guidKey,
997 BYTE **ppPolicy, DWORD *pcbPolicy,
998 BYTE *pContext, DWORD cbContext,
1001 SecManagerImpl *This = impl_from_IInternetSecurityManagerEx2(iface);
1004 TRACE("(%p)->(%s %s %p %p %p %08x %08x )\n", iface, debugstr_w(pwszUrl), debugstr_guid(guidKey),
1005 ppPolicy, pcbPolicy, pContext, cbContext, dwReserved);
1007 if(This->custom_manager) {
1008 hres = IInternetSecurityManager_QueryCustomPolicy(This->custom_manager, pwszUrl, guidKey,
1009 ppPolicy, pcbPolicy, pContext, cbContext, dwReserved);
1010 if(hres != INET_E_DEFAULT_ACTION)
1014 WARN("Unknown guidKey %s\n", debugstr_guid(guidKey));
1015 return HRESULT_FROM_WIN32(ERROR_NOT_FOUND);
1018 static HRESULT WINAPI SecManagerImpl_SetZoneMapping(IInternetSecurityManagerEx2 *iface,
1019 DWORD dwZone, LPCWSTR pwszPattern, DWORD dwFlags)
1021 SecManagerImpl *This = impl_from_IInternetSecurityManagerEx2(iface);
1024 TRACE("(%p)->(%08x %s %08x)\n", iface, dwZone, debugstr_w(pwszPattern),dwFlags);
1026 if(This->custom_manager) {
1027 hres = IInternetSecurityManager_SetZoneMapping(This->custom_manager, dwZone,
1028 pwszPattern, dwFlags);
1029 if(hres != INET_E_DEFAULT_ACTION)
1033 FIXME("Default action is not implemented\n");
1037 static HRESULT WINAPI SecManagerImpl_GetZoneMappings(IInternetSecurityManagerEx2 *iface,
1038 DWORD dwZone, IEnumString **ppenumString, DWORD dwFlags)
1040 SecManagerImpl *This = impl_from_IInternetSecurityManagerEx2(iface);
1043 TRACE("(%p)->(%08x %p %08x)\n", iface, dwZone, ppenumString,dwFlags);
1045 if(This->custom_manager) {
1046 hres = IInternetSecurityManager_GetZoneMappings(This->custom_manager, dwZone,
1047 ppenumString, dwFlags);
1048 if(hres != INET_E_DEFAULT_ACTION)
1052 FIXME("Default action is not implemented\n");
1056 static HRESULT WINAPI SecManagerImpl_ProcessUrlActionEx(IInternetSecurityManagerEx2 *iface,
1057 LPCWSTR pwszUrl, DWORD dwAction, BYTE *pPolicy, DWORD cbPolicy, BYTE *pContext, DWORD cbContext,
1058 DWORD dwFlags, DWORD dwReserved, DWORD *pdwOutFlags)
1060 SecManagerImpl *This = impl_from_IInternetSecurityManagerEx2(iface);
1061 FIXME("(%p)->(%s %08x %p %d %p %d %08x %08x %p) stub\n", This, debugstr_w(pwszUrl), dwAction, pPolicy, cbPolicy,
1062 pContext, cbContext, dwFlags, dwReserved, pdwOutFlags);
1066 static HRESULT WINAPI SecManagerImpl_MapUrlToZoneEx2(IInternetSecurityManagerEx2 *iface,
1067 IUri *pUri, DWORD *pdwZone, DWORD dwFlags, LPWSTR *ppwszMappedUrl, DWORD *pdwOutFlags)
1069 SecManagerImpl *This = impl_from_IInternetSecurityManagerEx2(iface);
1071 TRACE("(%p)->(%p %p %08x %p %p)\n", This, pUri, pdwZone, dwFlags, ppwszMappedUrl, pdwOutFlags);
1074 return E_INVALIDARG;
1077 *pdwZone = URLZONE_INVALID;
1078 return E_INVALIDARG;
1082 FIXME("Unsupported flags: %08x\n", dwFlags);
1084 return map_uri_to_zone(pUri, pdwZone);
1087 static HRESULT WINAPI SecManagerImpl_ProcessUrlActionEx2(IInternetSecurityManagerEx2 *iface,
1088 IUri *pUri, DWORD dwAction, BYTE *pPolicy, DWORD cbPolicy, BYTE *pContext, DWORD cbContext,
1089 DWORD dwFlags, DWORD_PTR dwReserved, DWORD *pdwOutFlags)
1091 SecManagerImpl *This = impl_from_IInternetSecurityManagerEx2(iface);
1092 FIXME("(%p)->(%p %08x %p %d %p %d %08x %08x %p) stub\n", This, pUri, dwAction, pPolicy,
1093 cbPolicy, pContext, cbContext, dwFlags, (DWORD)dwReserved, pdwOutFlags);
1097 static HRESULT WINAPI SecManagerImpl_GetSecurityIdEx2(IInternetSecurityManagerEx2 *iface,
1098 IUri *pUri, BYTE *pbSecurityId, DWORD *pcbSecurityId, DWORD_PTR dwReserved)
1100 SecManagerImpl *This = impl_from_IInternetSecurityManagerEx2(iface);
1101 FIXME("(%p)->(%p %p %p %08x) stub\n", This, pUri, pbSecurityId, pcbSecurityId, (DWORD)dwReserved);
1105 static HRESULT WINAPI SecManagerImpl_QueryCustomPolicyEx2(IInternetSecurityManagerEx2 *iface,
1106 IUri *pUri, REFGUID guidKey, BYTE **ppPolicy, DWORD *pcbPolicy, BYTE *pContext,
1107 DWORD cbContext, DWORD_PTR dwReserved)
1109 SecManagerImpl *This = impl_from_IInternetSecurityManagerEx2(iface);
1110 FIXME("(%p)->(%p %s %p %p %p %d %08x) stub\n", This, pUri, debugstr_guid(guidKey), ppPolicy, pcbPolicy,
1111 pContext, cbContext, (DWORD)dwReserved);
1115 static const IInternetSecurityManagerEx2Vtbl VT_SecManagerImpl =
1117 SecManagerImpl_QueryInterface,
1118 SecManagerImpl_AddRef,
1119 SecManagerImpl_Release,
1120 SecManagerImpl_SetSecuritySite,
1121 SecManagerImpl_GetSecuritySite,
1122 SecManagerImpl_MapUrlToZone,
1123 SecManagerImpl_GetSecurityId,
1124 SecManagerImpl_ProcessUrlAction,
1125 SecManagerImpl_QueryCustomPolicy,
1126 SecManagerImpl_SetZoneMapping,
1127 SecManagerImpl_GetZoneMappings,
1128 SecManagerImpl_ProcessUrlActionEx,
1129 SecManagerImpl_MapUrlToZoneEx2,
1130 SecManagerImpl_ProcessUrlActionEx2,
1131 SecManagerImpl_GetSecurityIdEx2,
1132 SecManagerImpl_QueryCustomPolicyEx2
1135 HRESULT SecManagerImpl_Construct(IUnknown *pUnkOuter, LPVOID *ppobj)
1137 SecManagerImpl *This;
1139 TRACE("(%p,%p)\n",pUnkOuter,ppobj);
1140 This = heap_alloc(sizeof(*This));
1142 /* Initialize the virtual function table. */
1143 This->IInternetSecurityManagerEx2_iface.lpVtbl = &VT_SecManagerImpl;
1146 This->mgrsite = NULL;
1147 This->custom_manager = NULL;
1151 URLMON_LockModule();
1156 /***********************************************************************
1157 * InternetZoneManager implementation
1161 IInternetZoneManagerEx2 IInternetZoneManagerEx2_iface;
1164 DWORD zonemap_count;
1167 static inline ZoneMgrImpl *impl_from_IInternetZoneManagerEx2(IInternetZoneManagerEx2 *iface)
1169 return CONTAINING_RECORD(iface, ZoneMgrImpl, IInternetZoneManagerEx2_iface);
1173 /***********************************************************************
1174 * build_zonemap_from_reg [internal]
1176 * Enumerate the Zones in the Registry and return the Zones in a DWORD-array
1177 * The number of the Zones is returned in data[0]
1179 static LPDWORD build_zonemap_from_reg(void)
1183 LPDWORD data = NULL;
1184 DWORD allocated = 6; /* space for the zonecount and Zone "0" up to Zone "4" */
1190 res = RegOpenKeyW(HKEY_CURRENT_USER, wszZonesKey, &hkey);
1194 data = heap_alloc(allocated * sizeof(DWORD));
1200 len = sizeof(name) / sizeof(name[0]);
1201 res = RegEnumKeyExW(hkey, used, name, &len, NULL, NULL, NULL, NULL);
1205 if (used == allocated) {
1209 new_data = heap_realloc_zero(data, allocated * sizeof(DWORD));
1215 data[used] = atoiW(name);
1225 /* something failed */
1231 /********************************************************************
1232 * IInternetZoneManager_QueryInterface
1234 static HRESULT WINAPI ZoneMgrImpl_QueryInterface(IInternetZoneManagerEx2* iface, REFIID riid, void** ppvObject)
1236 ZoneMgrImpl* This = impl_from_IInternetZoneManagerEx2(iface);
1238 TRACE("(%p)->(%s,%p)\n", This, debugstr_guid(riid), ppvObject);
1240 if(!This || !ppvObject)
1241 return E_INVALIDARG;
1243 if(IsEqualIID(&IID_IUnknown, riid)) {
1244 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppvObject);
1245 }else if(IsEqualIID(&IID_IInternetZoneManager, riid)) {
1246 TRACE("(%p)->(IID_InternetZoneManager %p)\n", This, ppvObject);
1247 }else if(IsEqualIID(&IID_IInternetZoneManagerEx, riid)) {
1248 TRACE("(%p)->(IID_InternetZoneManagerEx %p)\n", This, ppvObject);
1249 }else if(IsEqualIID(&IID_IInternetZoneManagerEx2, riid)) {
1250 TRACE("(%p)->(IID_InternetZoneManagerEx2 %p)\n", This, ppvObject);
1254 FIXME("Unknown interface: %s\n", debugstr_guid(riid));
1256 return E_NOINTERFACE;
1260 IInternetZoneManager_AddRef(iface);
1264 /********************************************************************
1265 * IInternetZoneManager_AddRef
1267 static ULONG WINAPI ZoneMgrImpl_AddRef(IInternetZoneManagerEx2* iface)
1269 ZoneMgrImpl* This = impl_from_IInternetZoneManagerEx2(iface);
1270 ULONG refCount = InterlockedIncrement(&This->ref);
1272 TRACE("(%p)->(ref before=%u)\n",This, refCount - 1);
1277 /********************************************************************
1278 * IInternetZoneManager_Release
1280 static ULONG WINAPI ZoneMgrImpl_Release(IInternetZoneManagerEx2* iface)
1282 ZoneMgrImpl* This = impl_from_IInternetZoneManagerEx2(iface);
1283 ULONG refCount = InterlockedDecrement(&This->ref);
1285 TRACE("(%p)->(ref before=%u)\n",This, refCount + 1);
1288 while (This->zonemap_count) heap_free(This->zonemaps[--This->zonemap_count]);
1289 heap_free(This->zonemaps);
1291 URLMON_UnlockModule();
1297 /********************************************************************
1298 * IInternetZoneManager_GetZoneAttributes
1300 static HRESULT WINAPI ZoneMgrImpl_GetZoneAttributes(IInternetZoneManagerEx2* iface,
1302 ZONEATTRIBUTES* pZoneAttributes)
1304 ZoneMgrImpl* This = impl_from_IInternetZoneManagerEx2(iface);
1309 TRACE("(%p)->(%d %p)\n", This, dwZone, pZoneAttributes);
1311 if (!pZoneAttributes)
1312 return E_INVALIDARG;
1314 hr = open_zone_key(HKEY_CURRENT_USER, dwZone, &hcu);
1316 return S_OK; /* IE6 and older returned E_FAIL here */
1318 hr = open_zone_key(HKEY_LOCAL_MACHINE, dwZone, &hklm);
1320 TRACE("Zone %d not in HKLM\n", dwZone);
1322 get_string_from_reg(hcu, hklm, displaynameW, pZoneAttributes->szDisplayName, MAX_ZONE_PATH);
1323 get_string_from_reg(hcu, hklm, descriptionW, pZoneAttributes->szDescription, MAX_ZONE_DESCRIPTION);
1324 get_string_from_reg(hcu, hklm, iconW, pZoneAttributes->szIconPath, MAX_ZONE_PATH);
1325 get_dword_from_reg(hcu, hklm, minlevelW, &pZoneAttributes->dwTemplateMinLevel);
1326 get_dword_from_reg(hcu, hklm, currentlevelW, &pZoneAttributes->dwTemplateCurrentLevel);
1327 get_dword_from_reg(hcu, hklm, recommendedlevelW, &pZoneAttributes->dwTemplateRecommended);
1328 get_dword_from_reg(hcu, hklm, flagsW, &pZoneAttributes->dwFlags);
1335 /********************************************************************
1336 * IInternetZoneManager_SetZoneAttributes
1338 static HRESULT WINAPI ZoneMgrImpl_SetZoneAttributes(IInternetZoneManagerEx2* iface,
1340 ZONEATTRIBUTES* pZoneAttributes)
1342 ZoneMgrImpl* This = impl_from_IInternetZoneManagerEx2(iface);
1346 TRACE("(%p)->(%d %p)\n", This, dwZone, pZoneAttributes);
1348 if (!pZoneAttributes)
1349 return E_INVALIDARG;
1351 hr = open_zone_key(HKEY_CURRENT_USER, dwZone, &hcu);
1353 return S_OK; /* IE6 returned E_FAIL here */
1355 /* cbSize is ignored */
1356 RegSetValueExW(hcu, displaynameW, 0, REG_SZ, (LPBYTE) pZoneAttributes->szDisplayName,
1357 (lstrlenW(pZoneAttributes->szDisplayName)+1)* sizeof(WCHAR));
1359 RegSetValueExW(hcu, descriptionW, 0, REG_SZ, (LPBYTE) pZoneAttributes->szDescription,
1360 (lstrlenW(pZoneAttributes->szDescription)+1)* sizeof(WCHAR));
1362 RegSetValueExW(hcu, iconW, 0, REG_SZ, (LPBYTE) pZoneAttributes->szIconPath,
1363 (lstrlenW(pZoneAttributes->szIconPath)+1)* sizeof(WCHAR));
1365 RegSetValueExW(hcu, minlevelW, 0, REG_DWORD,
1366 (const BYTE*) &pZoneAttributes->dwTemplateMinLevel, sizeof(DWORD));
1368 RegSetValueExW(hcu, currentlevelW, 0, REG_DWORD,
1369 (const BYTE*) &pZoneAttributes->dwTemplateCurrentLevel, sizeof(DWORD));
1371 RegSetValueExW(hcu, recommendedlevelW, 0, REG_DWORD,
1372 (const BYTE*) &pZoneAttributes->dwTemplateRecommended, sizeof(DWORD));
1374 RegSetValueExW(hcu, flagsW, 0, REG_DWORD, (const BYTE*) &pZoneAttributes->dwFlags, sizeof(DWORD));
1380 /********************************************************************
1381 * IInternetZoneManager_GetZoneCustomPolicy
1383 static HRESULT WINAPI ZoneMgrImpl_GetZoneCustomPolicy(IInternetZoneManagerEx2* iface,
1388 URLZONEREG ulrZoneReg)
1390 FIXME("(%p)->(%08x %s %p %p %08x) stub\n", iface, dwZone, debugstr_guid(guidKey),
1391 ppPolicy, pcbPolicy, ulrZoneReg);
1395 /********************************************************************
1396 * IInternetZoneManager_SetZoneCustomPolicy
1398 static HRESULT WINAPI ZoneMgrImpl_SetZoneCustomPolicy(IInternetZoneManagerEx2* iface,
1403 URLZONEREG ulrZoneReg)
1405 FIXME("(%p)->(%08x %s %p %08x %08x) stub\n", iface, dwZone, debugstr_guid(guidKey),
1406 ppPolicy, cbPolicy, ulrZoneReg);
1410 /********************************************************************
1411 * IInternetZoneManager_GetZoneActionPolicy
1413 static HRESULT WINAPI ZoneMgrImpl_GetZoneActionPolicy(IInternetZoneManagerEx2* iface,
1414 DWORD dwZone, DWORD dwAction, BYTE* pPolicy, DWORD cbPolicy, URLZONEREG urlZoneReg)
1416 TRACE("(%p)->(%d %08x %p %d %d)\n", iface, dwZone, dwAction, pPolicy,
1417 cbPolicy, urlZoneReg);
1420 return E_INVALIDARG;
1422 return get_action_policy(dwZone, dwAction, pPolicy, cbPolicy, urlZoneReg);
1425 /********************************************************************
1426 * IInternetZoneManager_SetZoneActionPolicy
1428 static HRESULT WINAPI ZoneMgrImpl_SetZoneActionPolicy(IInternetZoneManagerEx2* iface,
1433 URLZONEREG urlZoneReg)
1435 FIXME("(%p)->(%08x %08x %p %08x %08x) stub\n", iface, dwZone, dwAction, pPolicy,
1436 cbPolicy, urlZoneReg);
1440 /********************************************************************
1441 * IInternetZoneManager_PromptAction
1443 static HRESULT WINAPI ZoneMgrImpl_PromptAction(IInternetZoneManagerEx2* iface,
1448 DWORD dwPromptFlags)
1450 FIXME("%p %08x %p %s %s %08x\n", iface, dwAction, hwndParent,
1451 debugstr_w(pwszUrl), debugstr_w(pwszText), dwPromptFlags );
1455 /********************************************************************
1456 * IInternetZoneManager_LogAction
1458 static HRESULT WINAPI ZoneMgrImpl_LogAction(IInternetZoneManagerEx2* iface,
1464 FIXME("(%p)->(%08x %s %s %08x) stub\n", iface, dwAction, debugstr_w(pwszUrl),
1465 debugstr_w(pwszText), dwLogFlags);
1469 /********************************************************************
1470 * IInternetZoneManager_CreateZoneEnumerator
1472 static HRESULT WINAPI ZoneMgrImpl_CreateZoneEnumerator(IInternetZoneManagerEx2* iface,
1477 ZoneMgrImpl* This = impl_from_IInternetZoneManagerEx2(iface);
1482 TRACE("(%p)->(%p, %p, 0x%08x)\n", This, pdwEnum, pdwCount, dwFlags);
1483 if (!pdwEnum || !pdwCount || (dwFlags != 0))
1484 return E_INVALIDARG;
1486 data = build_zonemap_from_reg();
1487 TRACE("found %d zones\n", data ? data[0] : -1);
1492 for (i = 0; i < This->zonemap_count; i++) {
1493 if (This->zonemaps && !This->zonemaps[i]) {
1494 This->zonemaps[i] = data;
1496 *pdwCount = data[0];
1501 if (This->zonemaps) {
1502 /* try to double the nr. of pointers in the array */
1503 new_maps = heap_realloc_zero(This->zonemaps, This->zonemap_count * 2 * sizeof(LPDWORD));
1505 This->zonemap_count *= 2;
1509 This->zonemap_count = 2;
1510 new_maps = heap_alloc_zero(This->zonemap_count * sizeof(LPDWORD));
1517 This->zonemaps = new_maps;
1518 This->zonemaps[i] = data;
1520 *pdwCount = data[0];
1524 /********************************************************************
1525 * IInternetZoneManager_GetZoneAt
1527 static HRESULT WINAPI ZoneMgrImpl_GetZoneAt(IInternetZoneManagerEx2* iface,
1532 ZoneMgrImpl* This = impl_from_IInternetZoneManagerEx2(iface);
1535 TRACE("(%p)->(0x%08x, %d, %p)\n", This, dwEnum, dwIndex, pdwZone);
1537 /* make sure, that dwEnum and dwIndex are in the valid range */
1538 if (dwEnum < This->zonemap_count) {
1539 if ((data = This->zonemaps[dwEnum])) {
1540 if (dwIndex < data[0]) {
1541 *pdwZone = data[dwIndex + 1];
1546 return E_INVALIDARG;
1549 /********************************************************************
1550 * IInternetZoneManager_DestroyZoneEnumerator
1552 static HRESULT WINAPI ZoneMgrImpl_DestroyZoneEnumerator(IInternetZoneManagerEx2* iface,
1555 ZoneMgrImpl* This = impl_from_IInternetZoneManagerEx2(iface);
1558 TRACE("(%p)->(0x%08x)\n", This, dwEnum);
1559 /* make sure, that dwEnum is valid */
1560 if (dwEnum < This->zonemap_count) {
1561 if ((data = This->zonemaps[dwEnum])) {
1562 This->zonemaps[dwEnum] = NULL;
1567 return E_INVALIDARG;
1570 /********************************************************************
1571 * IInternetZoneManager_CopyTemplatePoliciesToZone
1573 static HRESULT WINAPI ZoneMgrImpl_CopyTemplatePoliciesToZone(IInternetZoneManagerEx2* iface,
1578 FIXME("(%p)->(%08x %08x %08x) stub\n", iface, dwTemplate, dwZone, dwReserved);
1582 /********************************************************************
1583 * IInternetZoneManagerEx_GetZoneActionPolicyEx
1585 static HRESULT WINAPI ZoneMgrImpl_GetZoneActionPolicyEx(IInternetZoneManagerEx2* iface,
1590 URLZONEREG urlZoneReg,
1593 TRACE("(%p)->(%d, 0x%x, %p, %d, %d, 0x%x)\n", iface, dwZone,
1594 dwAction, pPolicy, cbPolicy, urlZoneReg, dwFlags);
1597 return E_INVALIDARG;
1600 FIXME("dwFlags 0x%x ignored\n", dwFlags);
1602 return get_action_policy(dwZone, dwAction, pPolicy, cbPolicy, urlZoneReg);
1605 /********************************************************************
1606 * IInternetZoneManagerEx_SetZoneActionPolicyEx
1608 static HRESULT WINAPI ZoneMgrImpl_SetZoneActionPolicyEx(IInternetZoneManagerEx2* iface,
1613 URLZONEREG urlZoneReg,
1616 FIXME("(%p)->(%d, 0x%x, %p, %d, %d, 0x%x) stub\n", iface, dwZone, dwAction, pPolicy,
1617 cbPolicy, urlZoneReg, dwFlags);
1621 /********************************************************************
1622 * IInternetZoneManagerEx2_GetZoneAttributesEx
1624 static HRESULT WINAPI ZoneMgrImpl_GetZoneAttributesEx(IInternetZoneManagerEx2* iface,
1626 ZONEATTRIBUTES* pZoneAttributes,
1629 TRACE("(%p)->(%d, %p, 0x%x)\n", iface, dwZone, pZoneAttributes, dwFlags);
1632 FIXME("dwFlags 0x%x ignored\n", dwFlags);
1634 return IInternetZoneManager_GetZoneAttributes(iface, dwZone, pZoneAttributes);
1638 /********************************************************************
1639 * IInternetZoneManagerEx2_GetZoneSecurityState
1641 static HRESULT WINAPI ZoneMgrImpl_GetZoneSecurityState(IInternetZoneManagerEx2* iface,
1643 BOOL fRespectPolicy,
1645 BOOL *pfPolicyEncountered)
1647 FIXME("(%p)->(%d, %d, %p, %p) stub\n", iface, dwZoneIndex, fRespectPolicy,
1648 pdwState, pfPolicyEncountered);
1650 *pdwState = SECURITY_IE_STATE_GREEN;
1652 if (pfPolicyEncountered)
1653 *pfPolicyEncountered = FALSE;
1658 /********************************************************************
1659 * IInternetZoneManagerEx2_GetIESecurityState
1661 static HRESULT WINAPI ZoneMgrImpl_GetIESecurityState(IInternetZoneManagerEx2* iface,
1662 BOOL fRespectPolicy,
1664 BOOL *pfPolicyEncountered,
1667 FIXME("(%p)->(%d, %p, %p, %d) stub\n", iface, fRespectPolicy, pdwState,
1668 pfPolicyEncountered, fNoCache);
1670 *pdwState = SECURITY_IE_STATE_GREEN;
1672 if (pfPolicyEncountered)
1673 *pfPolicyEncountered = FALSE;
1678 /********************************************************************
1679 * IInternetZoneManagerEx2_FixInsecureSettings
1681 static HRESULT WINAPI ZoneMgrImpl_FixInsecureSettings(IInternetZoneManagerEx2* iface)
1683 FIXME("(%p) stub\n", iface);
1687 /********************************************************************
1688 * IInternetZoneManager_Construct
1690 static const IInternetZoneManagerEx2Vtbl ZoneMgrImplVtbl = {
1691 ZoneMgrImpl_QueryInterface,
1693 ZoneMgrImpl_Release,
1694 /* IInternetZoneManager */
1695 ZoneMgrImpl_GetZoneAttributes,
1696 ZoneMgrImpl_SetZoneAttributes,
1697 ZoneMgrImpl_GetZoneCustomPolicy,
1698 ZoneMgrImpl_SetZoneCustomPolicy,
1699 ZoneMgrImpl_GetZoneActionPolicy,
1700 ZoneMgrImpl_SetZoneActionPolicy,
1701 ZoneMgrImpl_PromptAction,
1702 ZoneMgrImpl_LogAction,
1703 ZoneMgrImpl_CreateZoneEnumerator,
1704 ZoneMgrImpl_GetZoneAt,
1705 ZoneMgrImpl_DestroyZoneEnumerator,
1706 ZoneMgrImpl_CopyTemplatePoliciesToZone,
1707 /* IInternetZoneManagerEx */
1708 ZoneMgrImpl_GetZoneActionPolicyEx,
1709 ZoneMgrImpl_SetZoneActionPolicyEx,
1710 /* IInternetZoneManagerEx2 */
1711 ZoneMgrImpl_GetZoneAttributesEx,
1712 ZoneMgrImpl_GetZoneSecurityState,
1713 ZoneMgrImpl_GetIESecurityState,
1714 ZoneMgrImpl_FixInsecureSettings,
1717 HRESULT ZoneMgrImpl_Construct(IUnknown *pUnkOuter, LPVOID *ppobj)
1719 ZoneMgrImpl* ret = heap_alloc_zero(sizeof(ZoneMgrImpl));
1721 TRACE("(%p %p)\n", pUnkOuter, ppobj);
1722 ret->IInternetZoneManagerEx2_iface.lpVtbl = &ZoneMgrImplVtbl;
1724 *ppobj = (IInternetZoneManagerEx*)ret;
1726 URLMON_LockModule();
1731 /***********************************************************************
1732 * CoInternetCreateSecurityManager (URLMON.@)
1735 HRESULT WINAPI CoInternetCreateSecurityManager( IServiceProvider *pSP,
1736 IInternetSecurityManager **ppSM, DWORD dwReserved )
1738 TRACE("%p %p %d\n", pSP, ppSM, dwReserved );
1741 FIXME("pSP not supported\n");
1743 return SecManagerImpl_Construct(NULL, (void**) ppSM);
1746 /********************************************************************
1747 * CoInternetCreateZoneManager (URLMON.@)
1749 HRESULT WINAPI CoInternetCreateZoneManager(IServiceProvider* pSP, IInternetZoneManager** ppZM, DWORD dwReserved)
1751 TRACE("(%p %p %x)\n", pSP, ppZM, dwReserved);
1752 return ZoneMgrImpl_Construct(NULL, (void**)ppZM);
1755 static HRESULT parse_security_url(const WCHAR *url, PSUACTION action, WCHAR **result) {
1756 IInternetProtocolInfo *protocol_info;
1757 WCHAR *tmp, *new_url = NULL, *alloc_url = NULL;
1758 DWORD size, new_size;
1759 HRESULT hres = S_OK, parse_hres;
1762 TRACE("parsing %s\n", debugstr_w(url));
1764 protocol_info = get_protocol_info(url);
1768 size = strlenW(url)+1;
1769 new_url = CoTaskMemAlloc(size*sizeof(WCHAR));
1771 hres = E_OUTOFMEMORY;
1776 parse_hres = IInternetProtocolInfo_ParseUrl(protocol_info, url, PARSE_SECURITY_URL, 0, new_url, size, &new_size, 0);
1777 if(parse_hres == S_FALSE) {
1779 hres = E_UNEXPECTED;
1783 tmp = CoTaskMemRealloc(new_url, new_size*sizeof(WCHAR));
1785 hres = E_OUTOFMEMORY;
1789 parse_hres = IInternetProtocolInfo_ParseUrl(protocol_info, url, PARSE_SECURITY_URL, 0, new_url,
1790 new_size, &new_size, 0);
1791 if(parse_hres == S_FALSE) {
1797 if(parse_hres != S_OK || !strcmpW(url, new_url))
1800 CoTaskMemFree(alloc_url);
1801 url = alloc_url = new_url;
1805 CoTaskMemFree(new_url);
1808 WARN("failed: %08x\n", hres);
1809 CoTaskMemFree(alloc_url);
1813 if(action == PSU_DEFAULT && (protocol_info = get_protocol_info(url))) {
1814 size = strlenW(url)+1;
1815 new_url = CoTaskMemAlloc(size * sizeof(WCHAR));
1818 parse_hres = IInternetProtocolInfo_ParseUrl(protocol_info, url, PARSE_SECURITY_DOMAIN, 0,
1819 new_url, size, &new_size, 0);
1820 if(parse_hres == S_FALSE) {
1822 tmp = CoTaskMemRealloc(new_url, new_size*sizeof(WCHAR));
1825 parse_hres = IInternetProtocolInfo_ParseUrl(protocol_info, url, PARSE_SECURITY_DOMAIN, 0, new_url,
1826 new_size, &new_size, 0);
1827 if(parse_hres == S_FALSE)
1830 hres = E_OUTOFMEMORY;
1833 hres = E_UNEXPECTED;
1837 if(hres == S_OK && parse_hres == S_OK) {
1838 CoTaskMemFree(alloc_url);
1839 url = alloc_url = new_url;
1843 CoTaskMemFree(new_url);
1845 hres = E_OUTOFMEMORY;
1847 IInternetProtocolInfo_Release(protocol_info);
1851 WARN("failed %08x\n", hres);
1852 CoTaskMemFree(alloc_url);
1857 size = strlenW(url)+1;
1858 alloc_url = CoTaskMemAlloc(size * sizeof(WCHAR));
1860 return E_OUTOFMEMORY;
1861 memcpy(alloc_url, url, size * sizeof(WCHAR));
1864 *result = alloc_url;
1868 /********************************************************************
1869 * CoInternetGetSecurityUrl (URLMON.@)
1871 HRESULT WINAPI CoInternetGetSecurityUrl(LPCWSTR pwzUrl, LPWSTR *ppwzSecUrl, PSUACTION psuAction, DWORD dwReserved)
1876 TRACE("(%p,%p,%u,%u)\n", pwzUrl, ppwzSecUrl, psuAction, dwReserved);
1878 hres = parse_security_url(pwzUrl, psuAction, &secure_url);
1882 if(psuAction != PSU_SECURITY_URL_ONLY) {
1883 PARSEDURLW parsed_url = { sizeof(parsed_url) };
1886 /* FIXME: Use helpers from uri.c */
1887 if(SUCCEEDED(ParseURLW(secure_url, &parsed_url))) {
1890 switch(parsed_url.nScheme) {
1891 case URL_SCHEME_FTP:
1892 case URL_SCHEME_HTTP:
1893 case URL_SCHEME_HTTPS:
1894 size = strlenW(secure_url)+1;
1895 new_url = CoTaskMemAlloc(size * sizeof(WCHAR));
1897 hres = UrlGetPartW(secure_url, new_url, &size, URL_PART_HOSTNAME, URL_PARTFLAG_KEEPSCHEME);
1899 hres = E_OUTOFMEMORY;
1900 CoTaskMemFree(secure_url);
1902 WARN("UrlGetPart failed: %08x\n", hres);
1903 CoTaskMemFree(new_url);
1904 return FAILED(hres) ? hres : E_FAIL;
1906 secure_url = new_url;
1911 *ppwzSecUrl = secure_url;
1915 /********************************************************************
1916 * CoInternetGetSecurityUrlEx (URLMON.@)
1918 HRESULT WINAPI CoInternetGetSecurityUrlEx(IUri *pUri, IUri **ppSecUri, PSUACTION psuAction, DWORD_PTR dwReserved)
1920 URL_SCHEME scheme_type;
1925 TRACE("(%p,%p,%u,%u)\n", pUri, ppSecUri, psuAction, (DWORD)dwReserved);
1927 if(!pUri || !ppSecUri)
1928 return E_INVALIDARG;
1930 hres = IUri_GetDisplayUri(pUri, &secure_uri);
1934 hres = parse_security_url(secure_uri, psuAction, &ret_url);
1935 SysFreeString(secure_uri);
1939 /* File URIs have to hierarchical. */
1940 hres = IUri_GetScheme(pUri, (DWORD*)&scheme_type);
1941 if(SUCCEEDED(hres) && scheme_type == URL_SCHEME_FILE) {
1942 const WCHAR *tmp = ret_url;
1944 /* Check and see if a "//" is after the scheme name. */
1945 tmp += sizeof(fileW)/sizeof(WCHAR);
1946 if(*tmp != '/' || *(tmp+1) != '/')
1947 hres = E_INVALIDARG;
1951 hres = CreateUri(ret_url, Uri_CREATE_ALLOW_IMPLICIT_WILDCARD_SCHEME, 0, ppSecUri);
1952 CoTaskMemFree(ret_url);