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 /********************************************************************
61 * get_string_from_reg [internal]
63 * helper to get a string from the reg.
66 static void get_string_from_reg(HKEY hcu
, HKEY hklm
, LPCWSTR name
, LPWSTR out
, DWORD maxlen
)
69 DWORD len
= maxlen
* sizeof(WCHAR
);
72 res
= RegQueryValueExW(hcu
, name
, NULL
, &type
, (LPBYTE
) out
, &len
);
75 len
= maxlen
* sizeof(WCHAR
);
77 res
= RegQueryValueExW(hklm
, name
, NULL
, &type
, (LPBYTE
) out
, &len
);
81 TRACE("%s failed: %d\n", debugstr_w(name
), res
);
86 /********************************************************************
87 * get_dword_from_reg [internal]
89 * helper to get a dword from the reg.
92 static void get_dword_from_reg(HKEY hcu
, HKEY hklm
, LPCWSTR name
, LPDWORD out
)
94 DWORD type
= REG_DWORD
;
95 DWORD len
= sizeof(DWORD
);
98 res
= RegQueryValueExW(hcu
, name
, NULL
, &type
, (LPBYTE
) out
, &len
);
103 res
= RegQueryValueExW(hklm
, name
, NULL
, &type
, (LPBYTE
) out
, &len
);
107 TRACE("%s failed: %d\n", debugstr_w(name
), res
);
112 static HRESULT
get_zone_from_reg(LPCWSTR schema
, DWORD
*zone
)
117 static const WCHAR wszZoneMapProtocolKey
[] =
118 {'S','o','f','t','w','a','r','e','\\',
119 'M','i','c','r','o','s','o','f','t','\\',
120 'W','i','n','d','o','w','s','\\',
121 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
122 'I','n','t','e','r','n','e','t',' ','S','e','t','t','i','n','g','s','\\',
123 'Z','o','n','e','M','a','p','\\',
124 'P','r','o','t','o','c','o','l','D','e','f','a','u','l','t','s',0};
126 res
= RegOpenKeyW(HKEY_CURRENT_USER
, wszZoneMapProtocolKey
, &hkey
);
127 if(res
!= ERROR_SUCCESS
) {
128 ERR("Could not open key %s\n", debugstr_w(wszZoneMapProtocolKey
));
132 size
= sizeof(DWORD
);
133 res
= RegQueryValueExW(hkey
, schema
, NULL
, NULL
, (PBYTE
)zone
, &size
);
135 if(res
== ERROR_SUCCESS
)
138 res
= RegOpenKeyW(HKEY_LOCAL_MACHINE
, wszZoneMapProtocolKey
, &hkey
);
139 if(res
!= ERROR_SUCCESS
) {
140 ERR("Could not open key %s\n", debugstr_w(wszZoneMapProtocolKey
));
144 size
= sizeof(DWORD
);
145 res
= RegQueryValueExW(hkey
, schema
, NULL
, NULL
, (PBYTE
)zone
, &size
);
147 if(res
== ERROR_SUCCESS
)
154 /********************************************************************
155 * matches_domain_pattern [internal]
157 * Checks if the given string matches the specified domain pattern.
159 * This function looks for explicit wildcard domain components iff
160 * they appear at the very beginning of the 'pattern' string
162 * pattern = "*.google.com"
164 static BOOL
matches_domain_pattern(LPCWSTR pattern
, LPCWSTR str
, BOOL implicit_wildcard
, LPCWSTR
*matched
)
166 BOOL matches
= FALSE
;
167 DWORD pattern_len
= strlenW(pattern
);
168 DWORD str_len
= strlenW(str
);
170 TRACE("(%d) Checking if %s matches %s\n", implicit_wildcard
, debugstr_w(str
), debugstr_w(pattern
));
173 if(str_len
>= pattern_len
) {
174 /* Check if there's an explicit wildcard in the pattern. */
175 if(pattern
[0] == '*' && pattern
[1] == '.') {
176 /* Make sure that 'str' matches the wildcard pattern.
179 * pattern = "*.google.com"
181 * So in this case 'str' would have to end with ".google.com" in order
182 * to map to this pattern.
184 if(str_len
>= pattern_len
+1 && !strcmpiW(str
+(str_len
-pattern_len
+1), pattern
+1)) {
185 /* Check if there's another '.' inside of the "unmatched" portion
189 * pattern = "*.google.com"
190 * str = "test.testing.google.com"
192 * The currently matched portion is ".google.com" in 'str', we need
193 * see if there's a '.' inside of the unmatched portion ("test.testing"), because
194 * if there is and 'implicit_wildcard' isn't set, then this isn't
198 if(str_len
> pattern_len
+1 && (ptr
= memrchrW(str
, '.', str_len
-pattern_len
-2))) {
199 if(implicit_wildcard
) {
208 } else if(implicit_wildcard
&& str_len
> pattern_len
) {
209 /* When the pattern has an implicit wildcard component, it means
210 * that anything goes in 'str' as long as it ends with the pattern
211 * and that the beginning of the match has a '.' before it.
214 * pattern = "google.com"
215 * str = "www.google.com"
217 * Implicitly matches the pattern, where as:
219 * pattern = "google.com"
220 * str = "wwwgoogle.com"
222 * Doesn't match the pattern.
224 if(str_len
> pattern_len
) {
225 if(str
[str_len
-pattern_len
-1] == '.' && !strcmpiW(str
+(str_len
-pattern_len
), pattern
)) {
227 *matched
= str
+(str_len
-pattern_len
);
231 /* The pattern doesn't have an implicit wildcard, or an explicit wildcard,
232 * so 'str' has to be an exact match to the 'pattern'.
234 if(!strcmpiW(str
, pattern
)) {
242 TRACE("Found a match: matched=%s\n", debugstr_w(*matched
));
244 TRACE("No match found\n");
249 static BOOL
get_zone_for_scheme(HKEY key
, LPCWSTR schema
, DWORD
*zone
)
251 static const WCHAR wildcardW
[] = {'*',0};
254 DWORD size
= sizeof(DWORD
);
257 /* See if the key contains a value for the scheme first. */
258 res
= RegQueryValueExW(key
, schema
, NULL
, &type
, (BYTE
*)zone
, &size
);
259 if(res
== ERROR_SUCCESS
) {
260 if(type
== REG_DWORD
)
262 WARN("Unexpected value type %d for value %s, expected REG_DWORD\n", type
, debugstr_w(schema
));
265 /* Try to get the zone for the wildcard scheme. */
266 size
= sizeof(DWORD
);
267 res
= RegQueryValueExW(key
, wildcardW
, NULL
, &type
, (BYTE
*)zone
, &size
);
268 if(res
!= ERROR_SUCCESS
)
271 if(type
!= REG_DWORD
) {
272 WARN("Unexpected value type %d for value %s, expected REG_DWORD\n", type
, debugstr_w(wildcardW
));
279 /********************************************************************
280 * search_domain_for_zone [internal]
282 * Searches the specified 'domain' registry key to see if 'host' maps into it, or any
283 * of it's subdomain registry keys.
285 * Returns S_OK if a match is found, S_FALSE if no matches were found, or an error code.
287 static HRESULT
search_domain_for_zone(HKEY domains
, LPCWSTR domain
, DWORD domain_len
, LPCWSTR schema
,
288 LPCWSTR host
, DWORD host_len
, DWORD
*zone
)
295 if(host_len
>= domain_len
&& matches_domain_pattern(domain
, host
, TRUE
, &matched
)) {
296 res
= RegOpenKeyW(domains
, domain
, &domain_key
);
297 if(res
!= ERROR_SUCCESS
) {
298 ERR("Failed to open domain key %s: %d\n", debugstr_w(domain
), res
);
303 found
= get_zone_for_scheme(domain_key
, schema
, zone
);
306 DWORD subdomain_count
, subdomain_len
;
307 BOOL check_domain
= TRUE
;
309 find_domain_name(domain
, domain_len
, &domain_offset
);
311 res
= RegQueryInfoKeyW(domain_key
, NULL
, NULL
, NULL
, &subdomain_count
, &subdomain_len
,
312 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
);
313 if(res
!= ERROR_SUCCESS
) {
314 ERR("Unable to query info for key %s: %d\n", debugstr_w(domain
), res
);
315 RegCloseKey(domain_key
);
319 if(subdomain_count
) {
324 subdomain
= heap_alloc((subdomain_len
+1)*sizeof(WCHAR
));
326 RegCloseKey(domain_key
);
327 return E_OUTOFMEMORY
;
330 component
= heap_strndupW(host
, matched
-host
-1);
332 heap_free(subdomain
);
333 RegCloseKey(domain_key
);
334 return E_OUTOFMEMORY
;
337 for(i
= 0; i
< subdomain_count
; ++i
) {
338 DWORD len
= subdomain_len
+1;
339 const WCHAR
*sub_matched
;
341 res
= RegEnumKeyExW(domain_key
, i
, subdomain
, &len
, NULL
, NULL
, NULL
, NULL
);
342 if(res
!= ERROR_SUCCESS
) {
343 heap_free(component
);
344 heap_free(subdomain
);
345 RegCloseKey(domain_key
);
349 if(matches_domain_pattern(subdomain
, component
, FALSE
, &sub_matched
)) {
352 res
= RegOpenKeyW(domain_key
, subdomain
, &subdomain_key
);
353 if(res
!= ERROR_SUCCESS
) {
354 ERR("Unable to open subdomain key %s of %s: %d\n", debugstr_w(subdomain
),
355 debugstr_w(domain
), res
);
356 heap_free(component
);
357 heap_free(subdomain
);
358 RegCloseKey(domain_key
);
362 found
= get_zone_for_scheme(subdomain_key
, schema
, zone
);
363 check_domain
= FALSE
;
364 RegCloseKey(subdomain_key
);
368 heap_free(subdomain
);
369 heap_free(component
);
372 /* There's a chance that 'host' implicitly mapped into 'domain', in
373 * which case we check to see if 'domain' contains zone information.
375 * This can only happen if 'domain' is it's own domain name.
377 * "google.com" (domain name = "google.com")
380 * host = "www.google.com"
382 * Then host would map directly into the "google.com" domain key.
384 * If 'domain' has more than just it's domain name, or it does not
385 * have a domain name, then we don't perform the check. The reason
386 * for this is that these domains don't allow implicit mappings.
388 * domain = "org" (has no domain name)
391 * The mapping would only happen if the "org" key had an explicit subkey
394 if(check_domain
&& !domain_offset
&& !strchrW(host
, matched
-host
-1))
395 found
= get_zone_for_scheme(domain_key
, schema
, zone
);
397 RegCloseKey(domain_key
);
400 return found
? S_OK
: S_FALSE
;
403 static HRESULT
search_for_domain_mapping(HKEY domains
, LPCWSTR schema
, LPCWSTR host
, DWORD host_len
, DWORD
*zone
)
406 DWORD domain_count
, domain_len
, i
;
408 HRESULT hres
= S_FALSE
;
410 res
= RegQueryInfoKeyW(domains
, NULL
, NULL
, NULL
, &domain_count
, &domain_len
,
411 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
);
412 if(res
!= ERROR_SUCCESS
) {
413 WARN("Failed to retrieve information about key\n");
420 domain
= heap_alloc((domain_len
+1)*sizeof(WCHAR
));
422 return E_OUTOFMEMORY
;
424 for(i
= 0; i
< domain_count
; ++i
) {
425 DWORD len
= domain_len
+1;
427 res
= RegEnumKeyExW(domains
, i
, domain
, &len
, NULL
, NULL
, NULL
, NULL
);
428 if(res
!= ERROR_SUCCESS
) {
433 hres
= search_domain_for_zone(domains
, domain
, len
, schema
, host
, host_len
, zone
);
434 if(FAILED(hres
) || hres
== S_OK
)
442 static HRESULT
get_zone_from_domains(LPCWSTR url
, LPCWSTR schema
, DWORD
*zone
)
446 DWORD host_len
= lstrlenW(url
)+1;
450 host_name
= heap_alloc(host_len
*sizeof(WCHAR
));
452 return E_OUTOFMEMORY
;
454 hres
= CoInternetParseUrl(url
, PARSE_DOMAIN
, 0, host_name
, host_len
, &host_len
, 0);
455 if(hres
== S_FALSE
) {
456 WCHAR
*tmp
= heap_realloc(host_name
, (host_len
+1)*sizeof(WCHAR
));
458 heap_free(host_name
);
459 return E_OUTOFMEMORY
;
463 hres
= CoInternetParseUrl(url
, PARSE_DOMAIN
, 0, host_name
, host_len
+1, &host_len
, 0);
466 /* Windows doesn't play nice with unknown scheme types when it tries
467 * to check if a host name maps into any domains.
469 * The reason is with how CoInternetParseUrl handles unknown scheme types
470 * when it's parsing the domain of a URL (IE it always returns E_FAIL).
472 * Windows doesn't compenstate for this and simply doesn't check if
473 * the URL maps into any domains.
476 heap_free(host_name
);
482 /* First try CURRENT_USER. */
483 res
= RegOpenKeyW(HKEY_CURRENT_USER
, wszZoneMapDomainsKey
, &domains
);
484 if(res
== ERROR_SUCCESS
) {
485 hres
= search_for_domain_mapping(domains
, schema
, host_name
, host_len
, zone
);
486 RegCloseKey(domains
);
488 WARN("Failed to open HKCU's %s key\n", debugstr_w(wszZoneMapDomainsKey
));
490 /* If that doesn't work try LOCAL_MACHINE. */
491 if(hres
== S_FALSE
) {
492 res
= RegOpenKeyW(HKEY_LOCAL_MACHINE
, wszZoneMapDomainsKey
, &domains
);
493 if(res
== ERROR_SUCCESS
) {
494 hres
= search_for_domain_mapping(domains
, schema
, host_name
, host_len
, zone
);
495 RegCloseKey(domains
);
497 WARN("Failed to open HKLM's %s key\n", debugstr_w(wszZoneMapDomainsKey
));
500 heap_free(host_name
);
504 static HRESULT
map_url_to_zone(LPCWSTR url
, DWORD
*zone
, LPWSTR
*ret_url
)
511 *zone
= URLZONE_INVALID
;
513 hres
= CoInternetGetSecurityUrl(url
, &secur_url
, PSU_SECURITY_URL_ONLY
, 0);
515 size
= strlenW(url
)*sizeof(WCHAR
);
517 secur_url
= heap_alloc(size
);
519 return E_OUTOFMEMORY
;
521 memcpy(secur_url
, url
, size
);
524 hres
= CoInternetParseUrl(secur_url
, PARSE_SCHEMA
, 0, schema
, sizeof(schema
)/sizeof(WCHAR
), &size
, 0);
525 if(FAILED(hres
) || !*schema
) {
526 heap_free(secur_url
);
530 /* file protocol is a special case */
531 if(!strcmpW(schema
, fileW
)) {
532 WCHAR path
[MAX_PATH
], root
[20];
535 hres
= CoInternetParseUrl(secur_url
, PARSE_PATH_FROM_URL
, 0, path
,
536 sizeof(path
)/sizeof(WCHAR
), &size
, 0);
538 if(SUCCEEDED(hres
) && (ptr
= strchrW(path
, '\\')) && ptr
-path
< sizeof(root
)/sizeof(WCHAR
)) {
541 memcpy(root
, path
, (ptr
-path
)*sizeof(WCHAR
));
544 type
= GetDriveTypeW(root
);
548 case DRIVE_NO_ROOT_DIR
:
550 case DRIVE_REMOVABLE
:
554 *zone
= URLZONE_LOCAL_MACHINE
;
558 *zone
= URLZONE_INTERNET
;
562 FIXME("unsupported drive type %d\n", type
);
567 if(*zone
== URLZONE_INVALID
) {
568 hres
= get_zone_from_domains(secur_url
, schema
, zone
);
570 hres
= get_zone_from_reg(schema
, zone
);
573 if(FAILED(hres
) || !ret_url
)
574 heap_free(secur_url
);
576 *ret_url
= secur_url
;
581 static HRESULT
open_zone_key(HKEY parent_key
, DWORD zone
, HKEY
*hkey
)
583 static const WCHAR wszFormat
[] = {'%','s','%','u',0};
585 WCHAR key_name
[sizeof(wszZonesKey
)/sizeof(WCHAR
)+12];
588 wsprintfW(key_name
, wszFormat
, wszZonesKey
, zone
);
590 res
= RegOpenKeyW(parent_key
, key_name
, hkey
);
592 if(res
!= ERROR_SUCCESS
) {
593 WARN("RegOpenKey failed\n");
600 static HRESULT
get_action_policy(DWORD zone
, DWORD action
, BYTE
*policy
, DWORD size
, URLZONEREG zone_reg
)
608 case URLACTION_SCRIPT_OVERRIDE_SAFETY
:
609 case URLACTION_ACTIVEX_OVERRIDE_SCRIPT_SAFETY
:
610 *(DWORD
*)policy
= URLPOLICY_DISALLOW
;
615 case URLZONEREG_DEFAULT
:
616 case URLZONEREG_HKCU
:
617 parent_key
= HKEY_CURRENT_USER
;
619 case URLZONEREG_HKLM
:
620 parent_key
= HKEY_LOCAL_MACHINE
;
623 WARN("Unknown URLZONEREG: %d\n", zone_reg
);
627 hres
= open_zone_key(parent_key
, zone
, &hkey
);
628 if(SUCCEEDED(hres
)) {
629 WCHAR action_str
[16];
632 static const WCHAR formatW
[] = {'%','X',0};
634 wsprintfW(action_str
, formatW
, action
);
636 res
= RegQueryValueExW(hkey
, action_str
, NULL
, NULL
, policy
, &len
);
637 if(res
== ERROR_MORE_DATA
) {
639 }else if(res
== ERROR_FILE_NOT_FOUND
) {
641 }else if(res
!= ERROR_SUCCESS
) {
642 ERR("RegQueryValue failed: %d\n", res
);
649 if(FAILED(hres
) && zone_reg
== URLZONEREG_DEFAULT
)
650 return get_action_policy(zone
, action
, policy
, size
, URLZONEREG_HKLM
);
655 /***********************************************************************
656 * InternetSecurityManager implementation
660 IInternetSecurityManager IInternetSecurityManager_iface
;
664 IInternetSecurityMgrSite
*mgrsite
;
665 IInternetSecurityManager
*custom_manager
;
668 static inline SecManagerImpl
*impl_from_IInternetSecurityManager(IInternetSecurityManager
*iface
)
670 return CONTAINING_RECORD(iface
, SecManagerImpl
, IInternetSecurityManager_iface
);
673 static HRESULT WINAPI
SecManagerImpl_QueryInterface(IInternetSecurityManager
* iface
,REFIID riid
,void** ppvObject
)
675 SecManagerImpl
*This
= impl_from_IInternetSecurityManager(iface
);
677 TRACE("(%p)->(%s,%p)\n",This
,debugstr_guid(riid
),ppvObject
);
679 /* Perform a sanity check on the parameters.*/
680 if ( (This
==0) || (ppvObject
==0) )
683 /* Initialize the return parameter */
686 /* Compare the riid with the interface IDs implemented by this object.*/
687 if (IsEqualIID(&IID_IUnknown
, riid
) ||
688 IsEqualIID(&IID_IInternetSecurityManager
, riid
))
691 /* Check that we obtained an interface.*/
693 WARN("not supported interface %s\n", debugstr_guid(riid
));
694 return E_NOINTERFACE
;
697 /* Query Interface always increases the reference count by one when it is successful */
698 IInternetSecurityManager_AddRef(iface
);
703 static ULONG WINAPI
SecManagerImpl_AddRef(IInternetSecurityManager
* iface
)
705 SecManagerImpl
*This
= impl_from_IInternetSecurityManager(iface
);
706 ULONG refCount
= InterlockedIncrement(&This
->ref
);
708 TRACE("(%p) ref=%u\n", This
, refCount
);
713 static ULONG WINAPI
SecManagerImpl_Release(IInternetSecurityManager
* iface
)
715 SecManagerImpl
*This
= impl_from_IInternetSecurityManager(iface
);
716 ULONG refCount
= InterlockedDecrement(&This
->ref
);
718 TRACE("(%p) ref=%u\n", This
, refCount
);
720 /* destroy the object if there's no more reference on it */
723 IInternetSecurityMgrSite_Release(This
->mgrsite
);
724 if(This
->custom_manager
)
725 IInternetSecurityManager_Release(This
->custom_manager
);
729 URLMON_UnlockModule();
735 static HRESULT WINAPI
SecManagerImpl_SetSecuritySite(IInternetSecurityManager
*iface
,
736 IInternetSecurityMgrSite
*pSite
)
738 SecManagerImpl
*This
= impl_from_IInternetSecurityManager(iface
);
740 TRACE("(%p)->(%p)\n", This
, pSite
);
743 IInternetSecurityMgrSite_Release(This
->mgrsite
);
745 if(This
->custom_manager
) {
746 IInternetSecurityManager_Release(This
->custom_manager
);
747 This
->custom_manager
= NULL
;
750 This
->mgrsite
= pSite
;
753 IServiceProvider
*servprov
;
756 IInternetSecurityMgrSite_AddRef(pSite
);
758 hres
= IInternetSecurityMgrSite_QueryInterface(pSite
, &IID_IServiceProvider
,
760 if(SUCCEEDED(hres
)) {
761 IServiceProvider_QueryService(servprov
, &SID_SInternetSecurityManager
,
762 &IID_IInternetSecurityManager
, (void**)&This
->custom_manager
);
763 IServiceProvider_Release(servprov
);
770 static HRESULT WINAPI
SecManagerImpl_GetSecuritySite(IInternetSecurityManager
*iface
,
771 IInternetSecurityMgrSite
**ppSite
)
773 SecManagerImpl
*This
= impl_from_IInternetSecurityManager(iface
);
775 TRACE("(%p)->(%p)\n", This
, ppSite
);
781 IInternetSecurityMgrSite_AddRef(This
->mgrsite
);
783 *ppSite
= This
->mgrsite
;
787 static HRESULT WINAPI
SecManagerImpl_MapUrlToZone(IInternetSecurityManager
*iface
,
788 LPCWSTR pwszUrl
, DWORD
*pdwZone
,
791 SecManagerImpl
*This
= impl_from_IInternetSecurityManager(iface
);
794 TRACE("(%p)->(%s %p %08x)\n", iface
, debugstr_w(pwszUrl
), pdwZone
, dwFlags
);
796 if(This
->custom_manager
) {
797 hres
= IInternetSecurityManager_MapUrlToZone(This
->custom_manager
,
798 pwszUrl
, pdwZone
, dwFlags
);
799 if(hres
!= INET_E_DEFAULT_ACTION
)
804 *pdwZone
= URLZONE_INVALID
;
809 FIXME("not supported flags: %08x\n", dwFlags
);
811 return map_url_to_zone(pwszUrl
, pdwZone
, NULL
);
814 static HRESULT WINAPI
SecManagerImpl_GetSecurityId(IInternetSecurityManager
*iface
,
815 LPCWSTR pwszUrl
, BYTE
*pbSecurityId
, DWORD
*pcbSecurityId
, DWORD_PTR dwReserved
)
817 SecManagerImpl
*This
= impl_from_IInternetSecurityManager(iface
);
818 LPWSTR url
, ptr
, ptr2
;
822 static const WCHAR wszFile
[] = {'f','i','l','e',':'};
824 TRACE("(%p)->(%s %p %p %08lx)\n", iface
, debugstr_w(pwszUrl
), pbSecurityId
,
825 pcbSecurityId
, dwReserved
);
827 if(This
->custom_manager
) {
828 hres
= IInternetSecurityManager_GetSecurityId(This
->custom_manager
,
829 pwszUrl
, pbSecurityId
, pcbSecurityId
, dwReserved
);
830 if(hres
!= INET_E_DEFAULT_ACTION
)
834 if(!pwszUrl
|| !pbSecurityId
|| !pcbSecurityId
)
838 FIXME("dwReserved is not supported\n");
840 hres
= map_url_to_zone(pwszUrl
, &zone
, &url
);
842 return hres
== 0x80041001 ? E_INVALIDARG
: hres
;
844 /* file protocol is a special case */
845 if(strlenW(url
) >= sizeof(wszFile
)/sizeof(WCHAR
)
846 && !memcmp(url
, wszFile
, sizeof(wszFile
)) && strchrW(url
, '\\')) {
848 static const BYTE secidFile
[] = {'f','i','l','e',':'};
852 if(*pcbSecurityId
< sizeof(secidFile
)+sizeof(zone
))
853 return HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER
);
855 memcpy(pbSecurityId
, secidFile
, sizeof(secidFile
));
856 *(DWORD
*)(pbSecurityId
+sizeof(secidFile
)) = zone
;
858 *pcbSecurityId
= sizeof(secidFile
)+sizeof(zone
);
862 ptr
= strchrW(url
, ':');
867 memmove(ptr
, ptr2
, (strlenW(ptr2
)+1)*sizeof(WCHAR
));
869 ptr
= strchrW(ptr
, '/');
873 len
= WideCharToMultiByte(CP_ACP
, 0, url
, -1, NULL
, 0, NULL
, NULL
)-1;
875 if(len
+sizeof(DWORD
) > *pcbSecurityId
) {
877 return HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER
);
880 WideCharToMultiByte(CP_ACP
, 0, url
, -1, (LPSTR
)pbSecurityId
, len
, NULL
, NULL
);
883 *(DWORD
*)(pbSecurityId
+len
) = zone
;
885 *pcbSecurityId
= len
+sizeof(DWORD
);
891 static HRESULT WINAPI
SecManagerImpl_ProcessUrlAction(IInternetSecurityManager
*iface
,
892 LPCWSTR pwszUrl
, DWORD dwAction
,
893 BYTE
*pPolicy
, DWORD cbPolicy
,
894 BYTE
*pContext
, DWORD cbContext
,
895 DWORD dwFlags
, DWORD dwReserved
)
897 SecManagerImpl
*This
= impl_from_IInternetSecurityManager(iface
);
901 TRACE("(%p)->(%s %08x %p %08x %p %08x %08x %08x)\n", iface
, debugstr_w(pwszUrl
), dwAction
,
902 pPolicy
, cbPolicy
, pContext
, cbContext
, dwFlags
, dwReserved
);
904 if(This
->custom_manager
) {
905 hres
= IInternetSecurityManager_ProcessUrlAction(This
->custom_manager
, pwszUrl
, dwAction
,
906 pPolicy
, cbPolicy
, pContext
, cbContext
, dwFlags
, dwReserved
);
907 if(hres
!= INET_E_DEFAULT_ACTION
)
911 if(dwFlags
|| dwReserved
)
912 FIXME("Unsupported arguments\n");
917 hres
= map_url_to_zone(pwszUrl
, &zone
, NULL
);
921 hres
= get_action_policy(zone
, dwAction
, (BYTE
*)&policy
, sizeof(policy
), URLZONEREG_DEFAULT
);
925 TRACE("policy %x\n", policy
);
926 if(cbPolicy
>= sizeof(DWORD
))
927 *(DWORD
*)pPolicy
= policy
;
929 switch(GetUrlPolicyPermissions(policy
)) {
930 case URLPOLICY_ALLOW
:
931 case URLPOLICY_CHANNEL_SOFTDIST_PRECACHE
:
933 case URLPOLICY_DISALLOW
:
935 case URLPOLICY_QUERY
:
936 FIXME("URLPOLICY_QUERY not implemented\n");
939 FIXME("Not implemented policy %x\n", policy
);
946 static HRESULT WINAPI
SecManagerImpl_QueryCustomPolicy(IInternetSecurityManager
*iface
,
947 LPCWSTR pwszUrl
, REFGUID guidKey
,
948 BYTE
**ppPolicy
, DWORD
*pcbPolicy
,
949 BYTE
*pContext
, DWORD cbContext
,
952 SecManagerImpl
*This
= impl_from_IInternetSecurityManager(iface
);
955 TRACE("(%p)->(%s %s %p %p %p %08x %08x )\n", iface
, debugstr_w(pwszUrl
), debugstr_guid(guidKey
),
956 ppPolicy
, pcbPolicy
, pContext
, cbContext
, dwReserved
);
958 if(This
->custom_manager
) {
959 hres
= IInternetSecurityManager_QueryCustomPolicy(This
->custom_manager
, pwszUrl
, guidKey
,
960 ppPolicy
, pcbPolicy
, pContext
, cbContext
, dwReserved
);
961 if(hres
!= INET_E_DEFAULT_ACTION
)
965 WARN("Unknown guidKey %s\n", debugstr_guid(guidKey
));
966 return HRESULT_FROM_WIN32(ERROR_NOT_FOUND
);
969 static HRESULT WINAPI
SecManagerImpl_SetZoneMapping(IInternetSecurityManager
*iface
,
970 DWORD dwZone
, LPCWSTR pwszPattern
, DWORD dwFlags
)
972 SecManagerImpl
*This
= impl_from_IInternetSecurityManager(iface
);
975 TRACE("(%p)->(%08x %s %08x)\n", iface
, dwZone
, debugstr_w(pwszPattern
),dwFlags
);
977 if(This
->custom_manager
) {
978 hres
= IInternetSecurityManager_SetZoneMapping(This
->custom_manager
, dwZone
,
979 pwszPattern
, dwFlags
);
980 if(hres
!= INET_E_DEFAULT_ACTION
)
984 FIXME("Default action is not implemented\n");
988 static HRESULT WINAPI
SecManagerImpl_GetZoneMappings(IInternetSecurityManager
*iface
,
989 DWORD dwZone
, IEnumString
**ppenumString
, DWORD dwFlags
)
991 SecManagerImpl
*This
= impl_from_IInternetSecurityManager(iface
);
994 TRACE("(%p)->(%08x %p %08x)\n", iface
, dwZone
, ppenumString
,dwFlags
);
996 if(This
->custom_manager
) {
997 hres
= IInternetSecurityManager_GetZoneMappings(This
->custom_manager
, dwZone
,
998 ppenumString
, dwFlags
);
999 if(hres
!= INET_E_DEFAULT_ACTION
)
1003 FIXME("Default action is not implemented\n");
1007 static const IInternetSecurityManagerVtbl VT_SecManagerImpl
=
1009 SecManagerImpl_QueryInterface
,
1010 SecManagerImpl_AddRef
,
1011 SecManagerImpl_Release
,
1012 SecManagerImpl_SetSecuritySite
,
1013 SecManagerImpl_GetSecuritySite
,
1014 SecManagerImpl_MapUrlToZone
,
1015 SecManagerImpl_GetSecurityId
,
1016 SecManagerImpl_ProcessUrlAction
,
1017 SecManagerImpl_QueryCustomPolicy
,
1018 SecManagerImpl_SetZoneMapping
,
1019 SecManagerImpl_GetZoneMappings
1022 HRESULT
SecManagerImpl_Construct(IUnknown
*pUnkOuter
, LPVOID
*ppobj
)
1024 SecManagerImpl
*This
;
1026 TRACE("(%p,%p)\n",pUnkOuter
,ppobj
);
1027 This
= heap_alloc(sizeof(*This
));
1029 /* Initialize the virtual function table. */
1030 This
->IInternetSecurityManager_iface
.lpVtbl
= &VT_SecManagerImpl
;
1033 This
->mgrsite
= NULL
;
1034 This
->custom_manager
= NULL
;
1038 URLMON_LockModule();
1043 /***********************************************************************
1044 * InternetZoneManager implementation
1048 IInternetZoneManagerEx2 IInternetZoneManagerEx2_iface
;
1051 DWORD zonemap_count
;
1054 static inline ZoneMgrImpl
*impl_from_IInternetZoneManagerEx2(IInternetZoneManagerEx2
*iface
)
1056 return CONTAINING_RECORD(iface
, ZoneMgrImpl
, IInternetZoneManagerEx2_iface
);
1060 /***********************************************************************
1061 * build_zonemap_from_reg [internal]
1063 * Enumerate the Zones in the Registry and return the Zones in a DWORD-array
1064 * The number of the Zones is returned in data[0]
1066 static LPDWORD
build_zonemap_from_reg(void)
1070 LPDWORD data
= NULL
;
1071 DWORD allocated
= 6; /* space for the zonecount and Zone "0" up to Zone "4" */
1077 res
= RegOpenKeyW(HKEY_CURRENT_USER
, wszZonesKey
, &hkey
);
1081 data
= heap_alloc(allocated
* sizeof(DWORD
));
1087 len
= sizeof(name
) / sizeof(name
[0]);
1088 res
= RegEnumKeyExW(hkey
, used
, name
, &len
, NULL
, NULL
, NULL
, NULL
);
1092 if (used
== allocated
) {
1096 new_data
= heap_realloc_zero(data
, allocated
* sizeof(DWORD
));
1102 data
[used
] = atoiW(name
);
1112 /* something failed */
1118 /********************************************************************
1119 * IInternetZoneManager_QueryInterface
1121 static HRESULT WINAPI
ZoneMgrImpl_QueryInterface(IInternetZoneManagerEx2
* iface
, REFIID riid
, void** ppvObject
)
1123 ZoneMgrImpl
* This
= impl_from_IInternetZoneManagerEx2(iface
);
1125 TRACE("(%p)->(%s,%p)\n", This
, debugstr_guid(riid
), ppvObject
);
1127 if(!This
|| !ppvObject
)
1128 return E_INVALIDARG
;
1130 if(IsEqualIID(&IID_IUnknown
, riid
)) {
1131 TRACE("(%p)->(IID_IUnknown %p)\n", This
, ppvObject
);
1132 }else if(IsEqualIID(&IID_IInternetZoneManager
, riid
)) {
1133 TRACE("(%p)->(IID_InternetZoneManager %p)\n", This
, ppvObject
);
1134 }else if(IsEqualIID(&IID_IInternetZoneManagerEx
, riid
)) {
1135 TRACE("(%p)->(IID_InternetZoneManagerEx %p)\n", This
, ppvObject
);
1136 }else if(IsEqualIID(&IID_IInternetZoneManagerEx2
, riid
)) {
1137 TRACE("(%p)->(IID_InternetZoneManagerEx2 %p)\n", This
, ppvObject
);
1141 FIXME("Unknown interface: %s\n", debugstr_guid(riid
));
1143 return E_NOINTERFACE
;
1147 IInternetZoneManager_AddRef(iface
);
1151 /********************************************************************
1152 * IInternetZoneManager_AddRef
1154 static ULONG WINAPI
ZoneMgrImpl_AddRef(IInternetZoneManagerEx2
* iface
)
1156 ZoneMgrImpl
* This
= impl_from_IInternetZoneManagerEx2(iface
);
1157 ULONG refCount
= InterlockedIncrement(&This
->ref
);
1159 TRACE("(%p)->(ref before=%u)\n",This
, refCount
- 1);
1164 /********************************************************************
1165 * IInternetZoneManager_Release
1167 static ULONG WINAPI
ZoneMgrImpl_Release(IInternetZoneManagerEx2
* iface
)
1169 ZoneMgrImpl
* This
= impl_from_IInternetZoneManagerEx2(iface
);
1170 ULONG refCount
= InterlockedDecrement(&This
->ref
);
1172 TRACE("(%p)->(ref before=%u)\n",This
, refCount
+ 1);
1175 while (This
->zonemap_count
) heap_free(This
->zonemaps
[--This
->zonemap_count
]);
1176 heap_free(This
->zonemaps
);
1178 URLMON_UnlockModule();
1184 /********************************************************************
1185 * IInternetZoneManager_GetZoneAttributes
1187 static HRESULT WINAPI
ZoneMgrImpl_GetZoneAttributes(IInternetZoneManagerEx2
* iface
,
1189 ZONEATTRIBUTES
* pZoneAttributes
)
1191 ZoneMgrImpl
* This
= impl_from_IInternetZoneManagerEx2(iface
);
1196 TRACE("(%p)->(%d %p)\n", This
, dwZone
, pZoneAttributes
);
1198 if (!pZoneAttributes
)
1199 return E_INVALIDARG
;
1201 hr
= open_zone_key(HKEY_CURRENT_USER
, dwZone
, &hcu
);
1203 return S_OK
; /* IE6 and older returned E_FAIL here */
1205 hr
= open_zone_key(HKEY_LOCAL_MACHINE
, dwZone
, &hklm
);
1207 TRACE("Zone %d not in HKLM\n", dwZone
);
1209 get_string_from_reg(hcu
, hklm
, displaynameW
, pZoneAttributes
->szDisplayName
, MAX_ZONE_PATH
);
1210 get_string_from_reg(hcu
, hklm
, descriptionW
, pZoneAttributes
->szDescription
, MAX_ZONE_DESCRIPTION
);
1211 get_string_from_reg(hcu
, hklm
, iconW
, pZoneAttributes
->szIconPath
, MAX_ZONE_PATH
);
1212 get_dword_from_reg(hcu
, hklm
, minlevelW
, &pZoneAttributes
->dwTemplateMinLevel
);
1213 get_dword_from_reg(hcu
, hklm
, currentlevelW
, &pZoneAttributes
->dwTemplateCurrentLevel
);
1214 get_dword_from_reg(hcu
, hklm
, recommendedlevelW
, &pZoneAttributes
->dwTemplateRecommended
);
1215 get_dword_from_reg(hcu
, hklm
, flagsW
, &pZoneAttributes
->dwFlags
);
1222 /********************************************************************
1223 * IInternetZoneManager_SetZoneAttributes
1225 static HRESULT WINAPI
ZoneMgrImpl_SetZoneAttributes(IInternetZoneManagerEx2
* iface
,
1227 ZONEATTRIBUTES
* pZoneAttributes
)
1229 ZoneMgrImpl
* This
= impl_from_IInternetZoneManagerEx2(iface
);
1233 TRACE("(%p)->(%d %p)\n", This
, dwZone
, pZoneAttributes
);
1235 if (!pZoneAttributes
)
1236 return E_INVALIDARG
;
1238 hr
= open_zone_key(HKEY_CURRENT_USER
, dwZone
, &hcu
);
1240 return S_OK
; /* IE6 returned E_FAIL here */
1242 /* cbSize is ignored */
1243 RegSetValueExW(hcu
, displaynameW
, 0, REG_SZ
, (LPBYTE
) pZoneAttributes
->szDisplayName
,
1244 (lstrlenW(pZoneAttributes
->szDisplayName
)+1)* sizeof(WCHAR
));
1246 RegSetValueExW(hcu
, descriptionW
, 0, REG_SZ
, (LPBYTE
) pZoneAttributes
->szDescription
,
1247 (lstrlenW(pZoneAttributes
->szDescription
)+1)* sizeof(WCHAR
));
1249 RegSetValueExW(hcu
, iconW
, 0, REG_SZ
, (LPBYTE
) pZoneAttributes
->szIconPath
,
1250 (lstrlenW(pZoneAttributes
->szIconPath
)+1)* sizeof(WCHAR
));
1252 RegSetValueExW(hcu
, minlevelW
, 0, REG_DWORD
,
1253 (const BYTE
*) &pZoneAttributes
->dwTemplateMinLevel
, sizeof(DWORD
));
1255 RegSetValueExW(hcu
, currentlevelW
, 0, REG_DWORD
,
1256 (const BYTE
*) &pZoneAttributes
->dwTemplateCurrentLevel
, sizeof(DWORD
));
1258 RegSetValueExW(hcu
, recommendedlevelW
, 0, REG_DWORD
,
1259 (const BYTE
*) &pZoneAttributes
->dwTemplateRecommended
, sizeof(DWORD
));
1261 RegSetValueExW(hcu
, flagsW
, 0, REG_DWORD
, (const BYTE
*) &pZoneAttributes
->dwFlags
, sizeof(DWORD
));
1267 /********************************************************************
1268 * IInternetZoneManager_GetZoneCustomPolicy
1270 static HRESULT WINAPI
ZoneMgrImpl_GetZoneCustomPolicy(IInternetZoneManagerEx2
* iface
,
1275 URLZONEREG ulrZoneReg
)
1277 FIXME("(%p)->(%08x %s %p %p %08x) stub\n", iface
, dwZone
, debugstr_guid(guidKey
),
1278 ppPolicy
, pcbPolicy
, ulrZoneReg
);
1282 /********************************************************************
1283 * IInternetZoneManager_SetZoneCustomPolicy
1285 static HRESULT WINAPI
ZoneMgrImpl_SetZoneCustomPolicy(IInternetZoneManagerEx2
* iface
,
1290 URLZONEREG ulrZoneReg
)
1292 FIXME("(%p)->(%08x %s %p %08x %08x) stub\n", iface
, dwZone
, debugstr_guid(guidKey
),
1293 ppPolicy
, cbPolicy
, ulrZoneReg
);
1297 /********************************************************************
1298 * IInternetZoneManager_GetZoneActionPolicy
1300 static HRESULT WINAPI
ZoneMgrImpl_GetZoneActionPolicy(IInternetZoneManagerEx2
* iface
,
1301 DWORD dwZone
, DWORD dwAction
, BYTE
* pPolicy
, DWORD cbPolicy
, URLZONEREG urlZoneReg
)
1303 TRACE("(%p)->(%d %08x %p %d %d)\n", iface
, dwZone
, dwAction
, pPolicy
,
1304 cbPolicy
, urlZoneReg
);
1307 return E_INVALIDARG
;
1309 return get_action_policy(dwZone
, dwAction
, pPolicy
, cbPolicy
, urlZoneReg
);
1312 /********************************************************************
1313 * IInternetZoneManager_SetZoneActionPolicy
1315 static HRESULT WINAPI
ZoneMgrImpl_SetZoneActionPolicy(IInternetZoneManagerEx2
* iface
,
1320 URLZONEREG urlZoneReg
)
1322 FIXME("(%p)->(%08x %08x %p %08x %08x) stub\n", iface
, dwZone
, dwAction
, pPolicy
,
1323 cbPolicy
, urlZoneReg
);
1327 /********************************************************************
1328 * IInternetZoneManager_PromptAction
1330 static HRESULT WINAPI
ZoneMgrImpl_PromptAction(IInternetZoneManagerEx2
* iface
,
1335 DWORD dwPromptFlags
)
1337 FIXME("%p %08x %p %s %s %08x\n", iface
, dwAction
, hwndParent
,
1338 debugstr_w(pwszUrl
), debugstr_w(pwszText
), dwPromptFlags
);
1342 /********************************************************************
1343 * IInternetZoneManager_LogAction
1345 static HRESULT WINAPI
ZoneMgrImpl_LogAction(IInternetZoneManagerEx2
* iface
,
1351 FIXME("(%p)->(%08x %s %s %08x) stub\n", iface
, dwAction
, debugstr_w(pwszUrl
),
1352 debugstr_w(pwszText
), dwLogFlags
);
1356 /********************************************************************
1357 * IInternetZoneManager_CreateZoneEnumerator
1359 static HRESULT WINAPI
ZoneMgrImpl_CreateZoneEnumerator(IInternetZoneManagerEx2
* iface
,
1364 ZoneMgrImpl
* This
= impl_from_IInternetZoneManagerEx2(iface
);
1369 TRACE("(%p)->(%p, %p, 0x%08x)\n", This
, pdwEnum
, pdwCount
, dwFlags
);
1370 if (!pdwEnum
|| !pdwCount
|| (dwFlags
!= 0))
1371 return E_INVALIDARG
;
1373 data
= build_zonemap_from_reg();
1374 TRACE("found %d zones\n", data
? data
[0] : -1);
1379 for (i
= 0; i
< This
->zonemap_count
; i
++) {
1380 if (This
->zonemaps
&& !This
->zonemaps
[i
]) {
1381 This
->zonemaps
[i
] = data
;
1383 *pdwCount
= data
[0];
1388 if (This
->zonemaps
) {
1389 /* try to double the nr. of pointers in the array */
1390 new_maps
= heap_realloc_zero(This
->zonemaps
, This
->zonemap_count
* 2 * sizeof(LPDWORD
));
1392 This
->zonemap_count
*= 2;
1396 This
->zonemap_count
= 2;
1397 new_maps
= heap_alloc_zero(This
->zonemap_count
* sizeof(LPDWORD
));
1404 This
->zonemaps
= new_maps
;
1405 This
->zonemaps
[i
] = data
;
1407 *pdwCount
= data
[0];
1411 /********************************************************************
1412 * IInternetZoneManager_GetZoneAt
1414 static HRESULT WINAPI
ZoneMgrImpl_GetZoneAt(IInternetZoneManagerEx2
* iface
,
1419 ZoneMgrImpl
* This
= impl_from_IInternetZoneManagerEx2(iface
);
1422 TRACE("(%p)->(0x%08x, %d, %p)\n", This
, dwEnum
, dwIndex
, pdwZone
);
1424 /* make sure, that dwEnum and dwIndex are in the valid range */
1425 if (dwEnum
< This
->zonemap_count
) {
1426 if ((data
= This
->zonemaps
[dwEnum
])) {
1427 if (dwIndex
< data
[0]) {
1428 *pdwZone
= data
[dwIndex
+ 1];
1433 return E_INVALIDARG
;
1436 /********************************************************************
1437 * IInternetZoneManager_DestroyZoneEnumerator
1439 static HRESULT WINAPI
ZoneMgrImpl_DestroyZoneEnumerator(IInternetZoneManagerEx2
* iface
,
1442 ZoneMgrImpl
* This
= impl_from_IInternetZoneManagerEx2(iface
);
1445 TRACE("(%p)->(0x%08x)\n", This
, dwEnum
);
1446 /* make sure, that dwEnum is valid */
1447 if (dwEnum
< This
->zonemap_count
) {
1448 if ((data
= This
->zonemaps
[dwEnum
])) {
1449 This
->zonemaps
[dwEnum
] = NULL
;
1454 return E_INVALIDARG
;
1457 /********************************************************************
1458 * IInternetZoneManager_CopyTemplatePoliciesToZone
1460 static HRESULT WINAPI
ZoneMgrImpl_CopyTemplatePoliciesToZone(IInternetZoneManagerEx2
* iface
,
1465 FIXME("(%p)->(%08x %08x %08x) stub\n", iface
, dwTemplate
, dwZone
, dwReserved
);
1469 /********************************************************************
1470 * IInternetZoneManagerEx_GetZoneActionPolicyEx
1472 static HRESULT WINAPI
ZoneMgrImpl_GetZoneActionPolicyEx(IInternetZoneManagerEx2
* iface
,
1477 URLZONEREG urlZoneReg
,
1480 TRACE("(%p)->(%d, 0x%x, %p, %d, %d, 0x%x)\n", iface
, dwZone
,
1481 dwAction
, pPolicy
, cbPolicy
, urlZoneReg
, dwFlags
);
1484 return E_INVALIDARG
;
1487 FIXME("dwFlags 0x%x ignored\n", dwFlags
);
1489 return get_action_policy(dwZone
, dwAction
, pPolicy
, cbPolicy
, urlZoneReg
);
1492 /********************************************************************
1493 * IInternetZoneManagerEx_SetZoneActionPolicyEx
1495 static HRESULT WINAPI
ZoneMgrImpl_SetZoneActionPolicyEx(IInternetZoneManagerEx2
* iface
,
1500 URLZONEREG urlZoneReg
,
1503 FIXME("(%p)->(%d, 0x%x, %p, %d, %d, 0x%x) stub\n", iface
, dwZone
, dwAction
, pPolicy
,
1504 cbPolicy
, urlZoneReg
, dwFlags
);
1508 /********************************************************************
1509 * IInternetZoneManagerEx2_GetZoneAttributesEx
1511 static HRESULT WINAPI
ZoneMgrImpl_GetZoneAttributesEx(IInternetZoneManagerEx2
* iface
,
1513 ZONEATTRIBUTES
* pZoneAttributes
,
1516 TRACE("(%p)->(%d, %p, 0x%x)\n", iface
, dwZone
, pZoneAttributes
, dwFlags
);
1519 FIXME("dwFlags 0x%x ignored\n", dwFlags
);
1521 return IInternetZoneManager_GetZoneAttributes(iface
, dwZone
, pZoneAttributes
);
1525 /********************************************************************
1526 * IInternetZoneManagerEx2_GetZoneSecurityState
1528 static HRESULT WINAPI
ZoneMgrImpl_GetZoneSecurityState(IInternetZoneManagerEx2
* iface
,
1530 BOOL fRespectPolicy
,
1532 BOOL
*pfPolicyEncountered
)
1534 FIXME("(%p)->(%d, %d, %p, %p) stub\n", iface
, dwZoneIndex
, fRespectPolicy
,
1535 pdwState
, pfPolicyEncountered
);
1537 *pdwState
= SECURITY_IE_STATE_GREEN
;
1539 if (pfPolicyEncountered
)
1540 *pfPolicyEncountered
= FALSE
;
1545 /********************************************************************
1546 * IInternetZoneManagerEx2_GetIESecurityState
1548 static HRESULT WINAPI
ZoneMgrImpl_GetIESecurityState(IInternetZoneManagerEx2
* iface
,
1549 BOOL fRespectPolicy
,
1551 BOOL
*pfPolicyEncountered
,
1554 FIXME("(%p)->(%d, %p, %p, %d) stub\n", iface
, fRespectPolicy
, pdwState
,
1555 pfPolicyEncountered
, fNoCache
);
1557 *pdwState
= SECURITY_IE_STATE_GREEN
;
1559 if (pfPolicyEncountered
)
1560 *pfPolicyEncountered
= FALSE
;
1565 /********************************************************************
1566 * IInternetZoneManagerEx2_FixInsecureSettings
1568 static HRESULT WINAPI
ZoneMgrImpl_FixInsecureSettings(IInternetZoneManagerEx2
* iface
)
1570 FIXME("(%p) stub\n", iface
);
1574 /********************************************************************
1575 * IInternetZoneManager_Construct
1577 static const IInternetZoneManagerEx2Vtbl ZoneMgrImplVtbl
= {
1578 ZoneMgrImpl_QueryInterface
,
1580 ZoneMgrImpl_Release
,
1581 /* IInternetZoneManager */
1582 ZoneMgrImpl_GetZoneAttributes
,
1583 ZoneMgrImpl_SetZoneAttributes
,
1584 ZoneMgrImpl_GetZoneCustomPolicy
,
1585 ZoneMgrImpl_SetZoneCustomPolicy
,
1586 ZoneMgrImpl_GetZoneActionPolicy
,
1587 ZoneMgrImpl_SetZoneActionPolicy
,
1588 ZoneMgrImpl_PromptAction
,
1589 ZoneMgrImpl_LogAction
,
1590 ZoneMgrImpl_CreateZoneEnumerator
,
1591 ZoneMgrImpl_GetZoneAt
,
1592 ZoneMgrImpl_DestroyZoneEnumerator
,
1593 ZoneMgrImpl_CopyTemplatePoliciesToZone
,
1594 /* IInternetZoneManagerEx */
1595 ZoneMgrImpl_GetZoneActionPolicyEx
,
1596 ZoneMgrImpl_SetZoneActionPolicyEx
,
1597 /* IInternetZoneManagerEx2 */
1598 ZoneMgrImpl_GetZoneAttributesEx
,
1599 ZoneMgrImpl_GetZoneSecurityState
,
1600 ZoneMgrImpl_GetIESecurityState
,
1601 ZoneMgrImpl_FixInsecureSettings
,
1604 HRESULT
ZoneMgrImpl_Construct(IUnknown
*pUnkOuter
, LPVOID
*ppobj
)
1606 ZoneMgrImpl
* ret
= heap_alloc_zero(sizeof(ZoneMgrImpl
));
1608 TRACE("(%p %p)\n", pUnkOuter
, ppobj
);
1609 ret
->IInternetZoneManagerEx2_iface
.lpVtbl
= &ZoneMgrImplVtbl
;
1611 *ppobj
= (IInternetZoneManagerEx
*)ret
;
1613 URLMON_LockModule();
1618 /***********************************************************************
1619 * CoInternetCreateSecurityManager (URLMON.@)
1622 HRESULT WINAPI
CoInternetCreateSecurityManager( IServiceProvider
*pSP
,
1623 IInternetSecurityManager
**ppSM
, DWORD dwReserved
)
1625 TRACE("%p %p %d\n", pSP
, ppSM
, dwReserved
);
1628 FIXME("pSP not supported\n");
1630 return SecManagerImpl_Construct(NULL
, (void**) ppSM
);
1633 /********************************************************************
1634 * CoInternetCreateZoneManager (URLMON.@)
1636 HRESULT WINAPI
CoInternetCreateZoneManager(IServiceProvider
* pSP
, IInternetZoneManager
** ppZM
, DWORD dwReserved
)
1638 TRACE("(%p %p %x)\n", pSP
, ppZM
, dwReserved
);
1639 return ZoneMgrImpl_Construct(NULL
, (void**)ppZM
);
1642 static HRESULT
parse_security_url(const WCHAR
*url
, PSUACTION action
, WCHAR
**result
) {
1643 IInternetProtocolInfo
*protocol_info
;
1644 WCHAR
*tmp
, *new_url
= NULL
, *alloc_url
= NULL
;
1645 DWORD size
, new_size
;
1646 HRESULT hres
= S_OK
, parse_hres
;
1649 TRACE("parsing %s\n", debugstr_w(url
));
1651 protocol_info
= get_protocol_info(url
);
1655 size
= strlenW(url
)+1;
1656 new_url
= CoTaskMemAlloc(size
*sizeof(WCHAR
));
1658 hres
= E_OUTOFMEMORY
;
1663 parse_hres
= IInternetProtocolInfo_ParseUrl(protocol_info
, url
, PARSE_SECURITY_URL
, 0, new_url
, size
, &new_size
, 0);
1664 if(parse_hres
== S_FALSE
) {
1666 hres
= E_UNEXPECTED
;
1670 tmp
= CoTaskMemRealloc(new_url
, new_size
*sizeof(WCHAR
));
1672 hres
= E_OUTOFMEMORY
;
1676 parse_hres
= IInternetProtocolInfo_ParseUrl(protocol_info
, url
, PARSE_SECURITY_URL
, 0, new_url
,
1677 new_size
, &new_size
, 0);
1678 if(parse_hres
== S_FALSE
) {
1684 if(parse_hres
!= S_OK
|| !strcmpW(url
, new_url
))
1687 CoTaskMemFree(alloc_url
);
1688 url
= alloc_url
= new_url
;
1692 CoTaskMemFree(new_url
);
1695 WARN("failed: %08x\n", hres
);
1696 CoTaskMemFree(alloc_url
);
1700 if(action
== PSU_DEFAULT
&& (protocol_info
= get_protocol_info(url
))) {
1701 size
= strlenW(url
)+1;
1702 new_url
= CoTaskMemAlloc(size
* sizeof(WCHAR
));
1705 parse_hres
= IInternetProtocolInfo_ParseUrl(protocol_info
, url
, PARSE_SECURITY_DOMAIN
, 0,
1706 new_url
, size
, &new_size
, 0);
1707 if(parse_hres
== S_FALSE
) {
1709 tmp
= CoTaskMemRealloc(new_url
, new_size
*sizeof(WCHAR
));
1712 parse_hres
= IInternetProtocolInfo_ParseUrl(protocol_info
, url
, PARSE_SECURITY_DOMAIN
, 0, new_url
,
1713 new_size
, &new_size
, 0);
1714 if(parse_hres
== S_FALSE
)
1717 hres
= E_OUTOFMEMORY
;
1720 hres
= E_UNEXPECTED
;
1724 if(hres
== S_OK
&& parse_hres
== S_OK
) {
1725 CoTaskMemFree(alloc_url
);
1726 url
= alloc_url
= new_url
;
1730 CoTaskMemFree(new_url
);
1732 hres
= E_OUTOFMEMORY
;
1734 IInternetProtocolInfo_Release(protocol_info
);
1738 WARN("failed %08x\n", hres
);
1739 CoTaskMemFree(alloc_url
);
1744 size
= strlenW(url
)+1;
1745 alloc_url
= CoTaskMemAlloc(size
* sizeof(WCHAR
));
1747 return E_OUTOFMEMORY
;
1748 memcpy(alloc_url
, url
, size
* sizeof(WCHAR
));
1751 *result
= alloc_url
;
1755 /********************************************************************
1756 * CoInternetGetSecurityUrl (URLMON.@)
1758 HRESULT WINAPI
CoInternetGetSecurityUrl(LPCWSTR pwzUrl
, LPWSTR
*ppwzSecUrl
, PSUACTION psuAction
, DWORD dwReserved
)
1763 TRACE("(%p,%p,%u,%u)\n", pwzUrl
, ppwzSecUrl
, psuAction
, dwReserved
);
1765 hres
= parse_security_url(pwzUrl
, psuAction
, &secure_url
);
1769 if(psuAction
!= PSU_SECURITY_URL_ONLY
) {
1770 PARSEDURLW parsed_url
= { sizeof(parsed_url
) };
1773 /* FIXME: Use helpers from uri.c */
1774 if(SUCCEEDED(ParseURLW(secure_url
, &parsed_url
))) {
1777 switch(parsed_url
.nScheme
) {
1778 case URL_SCHEME_FTP
:
1779 case URL_SCHEME_HTTP
:
1780 case URL_SCHEME_HTTPS
:
1781 size
= strlenW(secure_url
)+1;
1782 new_url
= CoTaskMemAlloc(size
* sizeof(WCHAR
));
1784 hres
= UrlGetPartW(secure_url
, new_url
, &size
, URL_PART_HOSTNAME
, URL_PARTFLAG_KEEPSCHEME
);
1786 hres
= E_OUTOFMEMORY
;
1787 CoTaskMemFree(secure_url
);
1789 WARN("UrlGetPart failed: %08x\n", hres
);
1790 CoTaskMemFree(new_url
);
1791 return FAILED(hres
) ? hres
: E_FAIL
;
1793 secure_url
= new_url
;
1798 *ppwzSecUrl
= secure_url
;
1802 /********************************************************************
1803 * CoInternetGetSecurityUrlEx (URLMON.@)
1805 HRESULT WINAPI
CoInternetGetSecurityUrlEx(IUri
*pUri
, IUri
**ppSecUri
, PSUACTION psuAction
, DWORD_PTR dwReserved
)
1807 URL_SCHEME scheme_type
;
1812 TRACE("(%p,%p,%u,%u)\n", pUri
, ppSecUri
, psuAction
, (DWORD
)dwReserved
);
1814 if(!pUri
|| !ppSecUri
)
1815 return E_INVALIDARG
;
1817 hres
= IUri_GetDisplayUri(pUri
, &secure_uri
);
1821 hres
= parse_security_url(secure_uri
, psuAction
, &ret_url
);
1822 SysFreeString(secure_uri
);
1826 hres
= CreateUri(ret_url
, Uri_CREATE_ALLOW_IMPLICIT_WILDCARD_SCHEME
, 0, ppSecUri
);
1828 CoTaskMemFree(ret_url
);
1832 /* File URIs have to hierarchical. */
1833 hres
= IUri_GetScheme(pUri
, (DWORD
*)&scheme_type
);
1834 if(SUCCEEDED(hres
) && scheme_type
== URL_SCHEME_FILE
) {
1835 const WCHAR
*tmp
= ret_url
;
1837 /* Check and see if a "//" is after the scheme name. */
1838 tmp
+= sizeof(fileW
)/sizeof(WCHAR
);
1839 if(*tmp
!= '/' || *(tmp
+1) != '/')
1840 hres
= E_INVALIDARG
;
1844 hres
= CreateUri(ret_url
, Uri_CREATE_ALLOW_IMPLICIT_WILDCARD_SCHEME
, 0, ppSecUri
);
1845 CoTaskMemFree(ret_url
);