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
);
36 static const WCHAR wszZonesKey
[] =
37 L
"Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\Zones\\";
38 static const WCHAR zone_map_keyW
[] =
39 L
"Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\ZoneMap";
40 static const WCHAR wszZoneMapDomainsKey
[] =
41 L
"Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\ZoneMap\\Domains";
43 static inline BOOL
is_drive_path(const WCHAR
*path
)
45 return iswalpha(*path
) && *(path
+1) == ':';
48 /* List of schemes types Windows seems to expect to be hierarchical. */
49 static inline BOOL
is_hierarchical_scheme(URL_SCHEME type
) {
50 return(type
== URL_SCHEME_HTTP
|| type
== URL_SCHEME_FTP
||
51 type
== URL_SCHEME_GOPHER
|| type
== URL_SCHEME_NNTP
||
52 type
== URL_SCHEME_TELNET
|| type
== URL_SCHEME_WAIS
||
53 type
== URL_SCHEME_FILE
|| type
== URL_SCHEME_HTTPS
||
54 type
== URL_SCHEME_RES
);
57 /********************************************************************
58 * get_string_from_reg [internal]
60 * helper to get a string from the reg.
63 static void get_string_from_reg(HKEY hcu
, HKEY hklm
, LPCWSTR name
, LPWSTR out
, DWORD maxlen
)
66 DWORD len
= maxlen
* sizeof(WCHAR
);
69 res
= RegQueryValueExW(hcu
, name
, NULL
, &type
, (LPBYTE
) out
, &len
);
72 len
= maxlen
* sizeof(WCHAR
);
74 res
= RegQueryValueExW(hklm
, name
, NULL
, &type
, (LPBYTE
) out
, &len
);
78 TRACE("%s failed: %d\n", debugstr_w(name
), res
);
83 /********************************************************************
84 * get_dword_from_reg [internal]
86 * helper to get a dword from the reg.
89 static void get_dword_from_reg(HKEY hcu
, HKEY hklm
, LPCWSTR name
, LPDWORD out
)
91 DWORD type
= REG_DWORD
;
92 DWORD len
= sizeof(DWORD
);
95 res
= RegQueryValueExW(hcu
, name
, NULL
, &type
, (LPBYTE
) out
, &len
);
100 res
= RegQueryValueExW(hklm
, name
, NULL
, &type
, (LPBYTE
) out
, &len
);
104 TRACE("%s failed: %d\n", debugstr_w(name
), res
);
109 static HRESULT
get_zone_from_reg(LPCWSTR schema
, DWORD
*zone
)
114 static const WCHAR wszZoneMapProtocolKey
[] =
115 L
"Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\ZoneMap\\ProtocolDefaults";
117 res
= RegOpenKeyW(HKEY_CURRENT_USER
, wszZoneMapProtocolKey
, &hkey
);
118 if(res
!= ERROR_SUCCESS
) {
119 ERR("Could not open key %s\n", debugstr_w(wszZoneMapProtocolKey
));
123 size
= sizeof(DWORD
);
124 res
= RegQueryValueExW(hkey
, schema
, NULL
, NULL
, (PBYTE
)zone
, &size
);
126 if(res
== ERROR_SUCCESS
)
129 res
= RegOpenKeyW(HKEY_LOCAL_MACHINE
, wszZoneMapProtocolKey
, &hkey
);
130 if(res
!= ERROR_SUCCESS
) {
131 ERR("Could not open key %s\n", debugstr_w(wszZoneMapProtocolKey
));
135 size
= sizeof(DWORD
);
136 res
= RegQueryValueExW(hkey
, schema
, NULL
, NULL
, (PBYTE
)zone
, &size
);
138 if(res
== ERROR_SUCCESS
)
145 /********************************************************************
146 * matches_domain_pattern [internal]
148 * Checks if the given string matches the specified domain pattern.
150 * This function looks for explicit wildcard domain components iff
151 * they appear at the very beginning of the 'pattern' string
153 * pattern = "*.google.com"
155 static BOOL
matches_domain_pattern(LPCWSTR pattern
, LPCWSTR str
, BOOL implicit_wildcard
, LPCWSTR
*matched
)
157 BOOL matches
= FALSE
;
158 DWORD pattern_len
= lstrlenW(pattern
);
159 DWORD str_len
= lstrlenW(str
);
161 TRACE("(%d) Checking if %s matches %s\n", implicit_wildcard
, debugstr_w(str
), debugstr_w(pattern
));
164 if(str_len
>= pattern_len
) {
165 /* Check if there's an explicit wildcard in the pattern. */
166 if(pattern
[0] == '*' && pattern
[1] == '.') {
167 /* Make sure that 'str' matches the wildcard pattern.
170 * pattern = "*.google.com"
172 * So in this case 'str' would have to end with ".google.com" in order
173 * to map to this pattern.
175 if(str_len
>= pattern_len
+1 && !wcsicmp(str
+(str_len
-pattern_len
+1), pattern
+1)) {
176 /* Check if there's another '.' inside of the "unmatched" portion
180 * pattern = "*.google.com"
181 * str = "test.testing.google.com"
183 * The currently matched portion is ".google.com" in 'str', we need
184 * see if there's a '.' inside of the unmatched portion ("test.testing"), because
185 * if there is and 'implicit_wildcard' isn't set, then this isn't
189 for (ptr
= str
+ str_len
- pattern_len
; ptr
> str
; ptr
--) if (ptr
[-1] == '.') break;
190 if (ptr
== str
|| implicit_wildcard
) {
195 } else if(implicit_wildcard
&& str_len
> pattern_len
) {
196 /* When the pattern has an implicit wildcard component, it means
197 * that anything goes in 'str' as long as it ends with the pattern
198 * and that the beginning of the match has a '.' before it.
201 * pattern = "google.com"
202 * str = "www.google.com"
204 * Implicitly matches the pattern, where as:
206 * pattern = "google.com"
207 * str = "wwwgoogle.com"
209 * Doesn't match the pattern.
211 if(str
[str_len
-pattern_len
-1] == '.' && !wcsicmp(str
+(str_len
-pattern_len
), pattern
)) {
213 *matched
= str
+(str_len
-pattern_len
);
216 /* The pattern doesn't have an implicit wildcard, or an explicit wildcard,
217 * so 'str' has to be an exact match to the 'pattern'.
219 if(!wcsicmp(str
, pattern
)) {
227 TRACE("Found a match: matched=%s\n", debugstr_w(*matched
));
229 TRACE("No match found\n");
234 static BOOL
get_zone_for_scheme(HKEY key
, LPCWSTR schema
, DWORD
*zone
)
237 DWORD size
= sizeof(DWORD
);
240 /* See if the key contains a value for the scheme first. */
241 res
= RegQueryValueExW(key
, schema
, NULL
, &type
, (BYTE
*)zone
, &size
);
242 if(res
== ERROR_SUCCESS
) {
243 if(type
== REG_DWORD
)
245 WARN("Unexpected value type %d for value %s, expected REG_DWORD\n", type
, debugstr_w(schema
));
248 /* Try to get the zone for the wildcard scheme. */
249 size
= sizeof(DWORD
);
250 res
= RegQueryValueExW(key
, L
"*", NULL
, &type
, (BYTE
*)zone
, &size
);
251 if(res
!= ERROR_SUCCESS
)
254 if(type
!= REG_DWORD
) {
255 WARN("Unexpected value type %d for value %s, expected REG_DWORD\n", type
, debugstr_w(L
"*"));
262 /********************************************************************
263 * search_domain_for_zone [internal]
265 * Searches the specified 'domain' registry key to see if 'host' maps into it, or any
266 * of its subdomain registry keys.
268 * Returns S_OK if a match is found, S_FALSE if no matches were found, or an error code.
270 static HRESULT
search_domain_for_zone(HKEY domains
, LPCWSTR domain
, DWORD domain_len
, LPCWSTR schema
,
271 LPCWSTR host
, DWORD host_len
, DWORD
*zone
)
278 if(host_len
>= domain_len
&& matches_domain_pattern(domain
, host
, TRUE
, &matched
)) {
279 res
= RegOpenKeyW(domains
, domain
, &domain_key
);
280 if(res
!= ERROR_SUCCESS
) {
281 ERR("Failed to open domain key %s: %d\n", debugstr_w(domain
), res
);
286 found
= get_zone_for_scheme(domain_key
, schema
, zone
);
289 DWORD subdomain_count
, subdomain_len
;
290 BOOL check_domain
= TRUE
;
292 find_domain_name(domain
, domain_len
, &domain_offset
);
294 res
= RegQueryInfoKeyW(domain_key
, NULL
, NULL
, NULL
, &subdomain_count
, &subdomain_len
,
295 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
);
296 if(res
!= ERROR_SUCCESS
) {
297 ERR("Unable to query info for key %s: %d\n", debugstr_w(domain
), res
);
298 RegCloseKey(domain_key
);
302 if(subdomain_count
) {
307 subdomain
= heap_alloc((subdomain_len
+1)*sizeof(WCHAR
));
309 RegCloseKey(domain_key
);
310 return E_OUTOFMEMORY
;
313 component
= heap_strndupW(host
, matched
-host
-1);
315 heap_free(subdomain
);
316 RegCloseKey(domain_key
);
317 return E_OUTOFMEMORY
;
320 for(i
= 0; i
< subdomain_count
; ++i
) {
321 DWORD len
= subdomain_len
+1;
322 const WCHAR
*sub_matched
;
324 res
= RegEnumKeyExW(domain_key
, i
, subdomain
, &len
, NULL
, NULL
, NULL
, NULL
);
325 if(res
!= ERROR_SUCCESS
) {
326 heap_free(component
);
327 heap_free(subdomain
);
328 RegCloseKey(domain_key
);
332 if(matches_domain_pattern(subdomain
, component
, FALSE
, &sub_matched
)) {
335 res
= RegOpenKeyW(domain_key
, subdomain
, &subdomain_key
);
336 if(res
!= ERROR_SUCCESS
) {
337 ERR("Unable to open subdomain key %s of %s: %d\n", debugstr_w(subdomain
),
338 debugstr_w(domain
), res
);
339 heap_free(component
);
340 heap_free(subdomain
);
341 RegCloseKey(domain_key
);
345 found
= get_zone_for_scheme(subdomain_key
, schema
, zone
);
346 check_domain
= FALSE
;
347 RegCloseKey(subdomain_key
);
351 heap_free(subdomain
);
352 heap_free(component
);
355 /* There's a chance that 'host' implicitly mapped into 'domain', in
356 * which case we check to see if 'domain' contains zone information.
358 * This can only happen if 'domain' is its own domain name.
360 * "google.com" (domain name = "google.com")
363 * host = "www.google.com"
365 * Then host would map directly into the "google.com" domain key.
367 * If 'domain' has more than just its domain name, or it does not
368 * have a domain name, then we don't perform the check. The reason
369 * for this is that these domains don't allow implicit mappings.
371 * domain = "org" (has no domain name)
374 * The mapping would only happen if the "org" key had an explicit subkey
377 if(check_domain
&& !domain_offset
&& !wcschr(host
, matched
-host
-1))
378 found
= get_zone_for_scheme(domain_key
, schema
, zone
);
380 RegCloseKey(domain_key
);
383 return found
? S_OK
: S_FALSE
;
386 static HRESULT
search_for_domain_mapping(HKEY domains
, LPCWSTR schema
, LPCWSTR host
, DWORD host_len
, DWORD
*zone
)
389 DWORD domain_count
, domain_len
, i
;
391 HRESULT hres
= S_FALSE
;
393 res
= RegQueryInfoKeyW(domains
, NULL
, NULL
, NULL
, &domain_count
, &domain_len
,
394 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
);
395 if(res
!= ERROR_SUCCESS
) {
396 WARN("Failed to retrieve information about key\n");
403 domain
= heap_alloc((domain_len
+1)*sizeof(WCHAR
));
405 return E_OUTOFMEMORY
;
407 for(i
= 0; i
< domain_count
; ++i
) {
408 DWORD len
= domain_len
+1;
410 res
= RegEnumKeyExW(domains
, i
, domain
, &len
, NULL
, NULL
, NULL
, NULL
);
411 if(res
!= ERROR_SUCCESS
) {
416 hres
= search_domain_for_zone(domains
, domain
, len
, schema
, host
, host_len
, zone
);
417 if(FAILED(hres
) || hres
== S_OK
)
425 static HRESULT
get_zone_from_domains(IUri
*uri
, DWORD
*zone
)
433 hres
= IUri_GetScheme(uri
, &scheme_type
);
437 /* Windows doesn't play nice with unknown scheme types when it tries
438 * to check if a host name maps into any domains.
440 if(scheme_type
== URL_SCHEME_UNKNOWN
)
443 hres
= IUri_GetHost(uri
, &host
);
447 /* Known hierarchical scheme types must have a host. If they don't Windows
448 * assigns URLZONE_INVALID to the zone.
450 if((scheme_type
!= URL_SCHEME_UNKNOWN
&& scheme_type
!= URL_SCHEME_FILE
)
451 && is_hierarchical_scheme(scheme_type
) && !*host
) {
452 *zone
= URLZONE_INVALID
;
456 /* The MapUrlToZone functions return S_OK when this condition occurs. */
460 hres
= IUri_GetSchemeName(uri
, &scheme
);
466 /* First try CURRENT_USER. */
467 res
= RegOpenKeyW(HKEY_CURRENT_USER
, wszZoneMapDomainsKey
, &domains
);
468 if(res
== ERROR_SUCCESS
) {
469 hres
= search_for_domain_mapping(domains
, scheme
, host
, SysStringLen(host
), zone
);
470 RegCloseKey(domains
);
472 WARN("Failed to open HKCU's %s key\n", debugstr_w(wszZoneMapDomainsKey
));
474 /* If that doesn't work try LOCAL_MACHINE. */
475 if(hres
== S_FALSE
) {
476 res
= RegOpenKeyW(HKEY_LOCAL_MACHINE
, 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 HKLM's %s key\n", debugstr_w(wszZoneMapDomainsKey
));
485 SysFreeString(scheme
);
489 static HRESULT
map_security_uri_to_zone(IUri
*uri
, DWORD
*zone
)
494 *zone
= URLZONE_INVALID
;
496 hres
= IUri_GetSchemeName(uri
, &scheme
);
500 if(!wcsicmp(scheme
, L
"file")) {
502 WCHAR
*ptr
, *path_start
, root
[20];
504 hres
= IUri_GetPath(uri
, &path
);
506 SysFreeString(scheme
);
510 if(*path
== '/' && is_drive_path(path
+1))
515 if((ptr
= wcschr(path_start
, ':')) && ptr
-path_start
+1 < ARRAY_SIZE(root
)) {
518 memcpy(root
, path_start
, (ptr
-path_start
+1)*sizeof(WCHAR
));
519 root
[ptr
-path_start
+1] = 0;
521 type
= GetDriveTypeW(root
);
525 case DRIVE_NO_ROOT_DIR
:
527 case DRIVE_REMOVABLE
:
531 *zone
= URLZONE_LOCAL_MACHINE
;
535 *zone
= URLZONE_INTERNET
;
539 FIXME("unsupported drive type %d\n", type
);
545 if(*zone
== URLZONE_INVALID
) {
546 hres
= get_zone_from_domains(uri
, zone
);
548 hres
= get_zone_from_reg(scheme
, zone
);
551 SysFreeString(scheme
);
555 static HRESULT
map_url_to_zone(LPCWSTR url
, DWORD
*zone
, LPWSTR
*ret_url
)
561 *zone
= URLZONE_INVALID
;
563 hres
= CoInternetGetSecurityUrl(url
, &secur_url
, PSU_SECURITY_URL_ONLY
, 0);
565 DWORD size
= lstrlenW(url
)*sizeof(WCHAR
);
567 secur_url
= CoTaskMemAlloc(size
);
569 return E_OUTOFMEMORY
;
571 memcpy(secur_url
, url
, size
);
574 hres
= CreateUri(secur_url
, Uri_CREATE_ALLOW_IMPLICIT_FILE_SCHEME
, 0, &secur_uri
);
576 CoTaskMemFree(secur_url
);
580 hres
= map_security_uri_to_zone(secur_uri
, zone
);
581 IUri_Release(secur_uri
);
583 if(FAILED(hres
) || !ret_url
)
584 CoTaskMemFree(secur_url
);
586 *ret_url
= secur_url
;
591 static HRESULT
map_uri_to_zone(IUri
*uri
, DWORD
*zone
, IUri
**ret_uri
)
596 hres
= CoInternetGetSecurityUrlEx(uri
, &secur_uri
, PSU_SECURITY_URL_ONLY
, 0);
600 hres
= map_security_uri_to_zone(secur_uri
, zone
);
601 if(FAILED(hres
) || !ret_uri
)
602 IUri_Release(secur_uri
);
604 *ret_uri
= secur_uri
;
609 static HRESULT
open_zone_key(HKEY parent_key
, DWORD zone
, HKEY
*hkey
)
611 WCHAR key_name
[ARRAY_SIZE(wszZonesKey
) + 12];
614 wsprintfW(key_name
, L
"%s%u", wszZonesKey
, zone
);
616 res
= RegOpenKeyW(parent_key
, key_name
, hkey
);
618 if(res
!= ERROR_SUCCESS
) {
619 WARN("RegOpenKey failed\n");
626 static HRESULT
get_action_policy(DWORD zone
, DWORD action
, BYTE
*policy
, DWORD size
, URLZONEREG zone_reg
)
634 case URLACTION_SCRIPT_OVERRIDE_SAFETY
:
635 case URLACTION_ACTIVEX_OVERRIDE_SCRIPT_SAFETY
:
636 *(DWORD
*)policy
= URLPOLICY_DISALLOW
;
641 case URLZONEREG_DEFAULT
:
642 case URLZONEREG_HKCU
:
643 parent_key
= HKEY_CURRENT_USER
;
645 case URLZONEREG_HKLM
:
646 parent_key
= HKEY_LOCAL_MACHINE
;
649 WARN("Unknown URLZONEREG: %d\n", zone_reg
);
653 hres
= open_zone_key(parent_key
, zone
, &hkey
);
654 if(SUCCEEDED(hres
)) {
655 WCHAR action_str
[16];
658 wsprintfW(action_str
, L
"%X", action
);
660 res
= RegQueryValueExW(hkey
, action_str
, NULL
, NULL
, policy
, &len
);
661 if(res
== ERROR_MORE_DATA
) {
663 }else if(res
== ERROR_FILE_NOT_FOUND
) {
665 }else if(res
!= ERROR_SUCCESS
) {
666 ERR("RegQueryValue failed: %d\n", res
);
673 if(FAILED(hres
) && zone_reg
== URLZONEREG_DEFAULT
)
674 return get_action_policy(zone
, action
, policy
, size
, URLZONEREG_HKLM
);
679 static HRESULT
generate_security_id(IUri
*uri
, BYTE
*secid
, DWORD
*secid_len
, DWORD zone
)
685 if(zone
== URLZONE_INVALID
)
688 hres
= IUri_GetScheme(uri
, &scheme_type
);
692 /* Windows handles opaque URLs differently then hierarchical ones. */
693 if(!is_hierarchical_scheme(scheme_type
) && scheme_type
!= URL_SCHEME_WILDCARD
) {
696 hres
= IUri_GetDisplayUri(uri
, &display_uri
);
700 len
= WideCharToMultiByte(CP_ACP
, 0, display_uri
, -1, NULL
, 0, NULL
, NULL
)-1;
702 if(len
+sizeof(DWORD
) > *secid_len
) {
703 SysFreeString(display_uri
);
704 return E_NOT_SUFFICIENT_BUFFER
;
707 WideCharToMultiByte(CP_ACP
, 0, display_uri
, -1, (LPSTR
)secid
, len
, NULL
, NULL
);
708 SysFreeString(display_uri
);
710 *(DWORD
*)(secid
+len
) = zone
;
713 DWORD host_len
, scheme_len
;
716 hres
= IUri_GetHost(uri
, &host
);
720 /* The host can't be empty for Wildcard URIs. */
721 if(scheme_type
== URL_SCHEME_WILDCARD
&& !*host
) {
726 hres
= IUri_GetSchemeName(uri
, &scheme
);
732 host_len
= WideCharToMultiByte(CP_ACP
, 0, host
, -1, NULL
, 0, NULL
, NULL
)-1;
733 scheme_len
= WideCharToMultiByte(CP_ACP
, 0, scheme
, -1, NULL
, 0, NULL
, NULL
)-1;
735 len
= host_len
+scheme_len
+sizeof(BYTE
);
737 if(len
+sizeof(DWORD
) > *secid_len
) {
739 SysFreeString(scheme
);
740 return E_NOT_SUFFICIENT_BUFFER
;
743 WideCharToMultiByte(CP_ACP
, 0, scheme
, -1, (LPSTR
)secid
, len
, NULL
, NULL
);
744 SysFreeString(scheme
);
746 ptr
= secid
+scheme_len
;
749 WideCharToMultiByte(CP_ACP
, 0, host
, -1, (LPSTR
)ptr
, host_len
, NULL
, NULL
);
757 *secid_len
= len
+sizeof(DWORD
);
762 static HRESULT
get_security_id_for_url(LPCWSTR url
, BYTE
*secid
, DWORD
*secid_len
)
765 DWORD zone
= URLZONE_INVALID
;
766 LPWSTR secur_url
= NULL
;
769 hres
= map_url_to_zone(url
, &zone
, &secur_url
);
771 return hres
== 0x80041001 ? E_INVALIDARG
: hres
;
773 hres
= CreateUri(secur_url
, Uri_CREATE_ALLOW_IMPLICIT_FILE_SCHEME
, 0, &uri
);
774 CoTaskMemFree(secur_url
);
778 hres
= generate_security_id(uri
, secid
, secid_len
, zone
);
784 static HRESULT
get_security_id_for_uri(IUri
*uri
, BYTE
*secid
, DWORD
*secid_len
)
788 DWORD zone
= URLZONE_INVALID
;
790 hres
= map_uri_to_zone(uri
, &zone
, &secur_uri
);
794 hres
= generate_security_id(secur_uri
, secid
, secid_len
, zone
);
795 IUri_Release(secur_uri
);
800 /***********************************************************************
801 * InternetSecurityManager implementation
805 IInternetSecurityManagerEx2 IInternetSecurityManagerEx2_iface
;
809 IInternetSecurityMgrSite
*mgrsite
;
810 IInternetSecurityManager
*custom_manager
;
813 static inline SecManagerImpl
*impl_from_IInternetSecurityManagerEx2(IInternetSecurityManagerEx2
*iface
)
815 return CONTAINING_RECORD(iface
, SecManagerImpl
, IInternetSecurityManagerEx2_iface
);
818 static HRESULT WINAPI
SecManagerImpl_QueryInterface(IInternetSecurityManagerEx2
* iface
,REFIID riid
,void** ppvObject
)
820 SecManagerImpl
*This
= impl_from_IInternetSecurityManagerEx2(iface
);
822 TRACE("(%p)->(%s %p)\n",This
,debugstr_guid(riid
),ppvObject
);
827 if(IsEqualIID(&IID_IUnknown
, riid
) ||
828 IsEqualIID(&IID_IInternetSecurityManager
, riid
) ||
829 IsEqualIID(&IID_IInternetSecurityManagerEx
, riid
) ||
830 IsEqualIID(&IID_IInternetSecurityManagerEx2
, riid
)) {
833 WARN("not supported interface %s\n", debugstr_guid(riid
));
835 return E_NOINTERFACE
;
838 IInternetSecurityManagerEx2_AddRef(iface
);
842 static ULONG WINAPI
SecManagerImpl_AddRef(IInternetSecurityManagerEx2
* iface
)
844 SecManagerImpl
*This
= impl_from_IInternetSecurityManagerEx2(iface
);
845 ULONG refCount
= InterlockedIncrement(&This
->ref
);
847 TRACE("(%p) ref=%u\n", This
, refCount
);
852 static ULONG WINAPI
SecManagerImpl_Release(IInternetSecurityManagerEx2
* iface
)
854 SecManagerImpl
*This
= impl_from_IInternetSecurityManagerEx2(iface
);
855 ULONG refCount
= InterlockedDecrement(&This
->ref
);
857 TRACE("(%p) ref=%u\n", This
, refCount
);
859 /* destroy the object if there are no more references on it */
862 IInternetSecurityMgrSite_Release(This
->mgrsite
);
863 if(This
->custom_manager
)
864 IInternetSecurityManager_Release(This
->custom_manager
);
868 URLMON_UnlockModule();
874 static HRESULT WINAPI
SecManagerImpl_SetSecuritySite(IInternetSecurityManagerEx2
*iface
,
875 IInternetSecurityMgrSite
*pSite
)
877 SecManagerImpl
*This
= impl_from_IInternetSecurityManagerEx2(iface
);
879 TRACE("(%p)->(%p)\n", This
, pSite
);
882 IInternetSecurityMgrSite_Release(This
->mgrsite
);
884 if(This
->custom_manager
) {
885 IInternetSecurityManager_Release(This
->custom_manager
);
886 This
->custom_manager
= NULL
;
889 This
->mgrsite
= pSite
;
892 IServiceProvider
*servprov
;
895 IInternetSecurityMgrSite_AddRef(pSite
);
897 hres
= IInternetSecurityMgrSite_QueryInterface(pSite
, &IID_IServiceProvider
,
899 if(SUCCEEDED(hres
)) {
900 IServiceProvider_QueryService(servprov
, &SID_SInternetSecurityManager
,
901 &IID_IInternetSecurityManager
, (void**)&This
->custom_manager
);
902 IServiceProvider_Release(servprov
);
909 static HRESULT WINAPI
SecManagerImpl_GetSecuritySite(IInternetSecurityManagerEx2
*iface
,
910 IInternetSecurityMgrSite
**ppSite
)
912 SecManagerImpl
*This
= impl_from_IInternetSecurityManagerEx2(iface
);
914 TRACE("(%p)->(%p)\n", This
, ppSite
);
920 IInternetSecurityMgrSite_AddRef(This
->mgrsite
);
922 *ppSite
= This
->mgrsite
;
926 static HRESULT WINAPI
SecManagerImpl_MapUrlToZone(IInternetSecurityManagerEx2
*iface
,
927 LPCWSTR pwszUrl
, DWORD
*pdwZone
,
930 SecManagerImpl
*This
= impl_from_IInternetSecurityManagerEx2(iface
);
933 TRACE("(%p)->(%s %p %08x)\n", iface
, debugstr_w(pwszUrl
), pdwZone
, dwFlags
);
935 if(This
->custom_manager
) {
936 hres
= IInternetSecurityManager_MapUrlToZone(This
->custom_manager
,
937 pwszUrl
, pdwZone
, dwFlags
);
938 if(hres
!= INET_E_DEFAULT_ACTION
)
943 *pdwZone
= URLZONE_INVALID
;
948 FIXME("not supported flags: %08x\n", dwFlags
);
950 return map_url_to_zone(pwszUrl
, pdwZone
, NULL
);
953 static HRESULT WINAPI
SecManagerImpl_GetSecurityId(IInternetSecurityManagerEx2
*iface
,
954 LPCWSTR pwszUrl
, BYTE
*pbSecurityId
, DWORD
*pcbSecurityId
, DWORD_PTR dwReserved
)
956 SecManagerImpl
*This
= impl_from_IInternetSecurityManagerEx2(iface
);
958 TRACE("(%p)->(%s %p %p %08lx)\n", iface
, debugstr_w(pwszUrl
), pbSecurityId
,
959 pcbSecurityId
, dwReserved
);
961 if(This
->custom_manager
) {
964 hres
= IInternetSecurityManager_GetSecurityId(This
->custom_manager
,
965 pwszUrl
, pbSecurityId
, pcbSecurityId
, dwReserved
);
966 if(hres
!= INET_E_DEFAULT_ACTION
)
970 if(!pwszUrl
|| !pbSecurityId
|| !pcbSecurityId
)
974 FIXME("dwReserved is not supported\n");
976 return get_security_id_for_url(pwszUrl
, pbSecurityId
, pcbSecurityId
);
980 static HRESULT WINAPI
SecManagerImpl_ProcessUrlAction(IInternetSecurityManagerEx2
*iface
,
981 LPCWSTR pwszUrl
, DWORD dwAction
,
982 BYTE
*pPolicy
, DWORD cbPolicy
,
983 BYTE
*pContext
, DWORD cbContext
,
984 DWORD dwFlags
, DWORD dwReserved
)
986 SecManagerImpl
*This
= impl_from_IInternetSecurityManagerEx2(iface
);
990 TRACE("(%p)->(%s %08x %p %08x %p %08x %08x %08x)\n", iface
, debugstr_w(pwszUrl
), dwAction
,
991 pPolicy
, cbPolicy
, pContext
, cbContext
, dwFlags
, dwReserved
);
993 if(This
->custom_manager
) {
994 hres
= IInternetSecurityManager_ProcessUrlAction(This
->custom_manager
, pwszUrl
, dwAction
,
995 pPolicy
, cbPolicy
, pContext
, cbContext
, dwFlags
, dwReserved
);
996 if(hres
!= INET_E_DEFAULT_ACTION
)
1000 if(dwFlags
|| dwReserved
)
1001 FIXME("Unsupported arguments\n");
1004 return E_INVALIDARG
;
1006 hres
= map_url_to_zone(pwszUrl
, &zone
, NULL
);
1010 hres
= get_action_policy(zone
, dwAction
, (BYTE
*)&policy
, sizeof(policy
), URLZONEREG_DEFAULT
);
1014 TRACE("policy %x\n", policy
);
1015 if(cbPolicy
>= sizeof(DWORD
))
1016 *(DWORD
*)pPolicy
= policy
;
1018 switch(GetUrlPolicyPermissions(policy
)) {
1019 case URLPOLICY_ALLOW
:
1020 case URLPOLICY_CHANNEL_SOFTDIST_PRECACHE
:
1022 case URLPOLICY_DISALLOW
:
1024 case URLPOLICY_QUERY
:
1025 FIXME("URLPOLICY_QUERY not implemented\n");
1028 FIXME("Not implemented policy %x\n", policy
);
1035 static HRESULT WINAPI
SecManagerImpl_QueryCustomPolicy(IInternetSecurityManagerEx2
*iface
,
1036 LPCWSTR pwszUrl
, REFGUID guidKey
,
1037 BYTE
**ppPolicy
, DWORD
*pcbPolicy
,
1038 BYTE
*pContext
, DWORD cbContext
,
1041 SecManagerImpl
*This
= impl_from_IInternetSecurityManagerEx2(iface
);
1044 TRACE("(%p)->(%s %s %p %p %p %08x %08x )\n", iface
, debugstr_w(pwszUrl
), debugstr_guid(guidKey
),
1045 ppPolicy
, pcbPolicy
, pContext
, cbContext
, dwReserved
);
1047 if(This
->custom_manager
) {
1048 hres
= IInternetSecurityManager_QueryCustomPolicy(This
->custom_manager
, pwszUrl
, guidKey
,
1049 ppPolicy
, pcbPolicy
, pContext
, cbContext
, dwReserved
);
1050 if(hres
!= INET_E_DEFAULT_ACTION
)
1054 WARN("Unknown guidKey %s\n", debugstr_guid(guidKey
));
1055 return HRESULT_FROM_WIN32(ERROR_NOT_FOUND
);
1058 static HRESULT WINAPI
SecManagerImpl_SetZoneMapping(IInternetSecurityManagerEx2
*iface
,
1059 DWORD dwZone
, LPCWSTR pwszPattern
, DWORD dwFlags
)
1061 SecManagerImpl
*This
= impl_from_IInternetSecurityManagerEx2(iface
);
1064 TRACE("(%p)->(%08x %s %08x)\n", iface
, dwZone
, debugstr_w(pwszPattern
),dwFlags
);
1066 if(This
->custom_manager
) {
1067 hres
= IInternetSecurityManager_SetZoneMapping(This
->custom_manager
, dwZone
,
1068 pwszPattern
, dwFlags
);
1069 if(hres
!= INET_E_DEFAULT_ACTION
)
1073 FIXME("Default action is not implemented\n");
1077 static HRESULT WINAPI
SecManagerImpl_GetZoneMappings(IInternetSecurityManagerEx2
*iface
,
1078 DWORD dwZone
, IEnumString
**ppenumString
, DWORD dwFlags
)
1080 SecManagerImpl
*This
= impl_from_IInternetSecurityManagerEx2(iface
);
1083 TRACE("(%p)->(%08x %p %08x)\n", iface
, dwZone
, ppenumString
,dwFlags
);
1085 if(This
->custom_manager
) {
1086 hres
= IInternetSecurityManager_GetZoneMappings(This
->custom_manager
, dwZone
,
1087 ppenumString
, dwFlags
);
1088 if(hres
!= INET_E_DEFAULT_ACTION
)
1092 FIXME("Default action is not implemented\n");
1096 static HRESULT WINAPI
SecManagerImpl_ProcessUrlActionEx(IInternetSecurityManagerEx2
*iface
,
1097 LPCWSTR pwszUrl
, DWORD dwAction
, BYTE
*pPolicy
, DWORD cbPolicy
, BYTE
*pContext
, DWORD cbContext
,
1098 DWORD dwFlags
, DWORD dwReserved
, DWORD
*pdwOutFlags
)
1100 SecManagerImpl
*This
= impl_from_IInternetSecurityManagerEx2(iface
);
1101 FIXME("(%p)->(%s %08x %p %d %p %d %08x %08x %p) stub\n", This
, debugstr_w(pwszUrl
), dwAction
, pPolicy
, cbPolicy
,
1102 pContext
, cbContext
, dwFlags
, dwReserved
, pdwOutFlags
);
1106 static HRESULT WINAPI
SecManagerImpl_MapUrlToZoneEx2(IInternetSecurityManagerEx2
*iface
,
1107 IUri
*pUri
, DWORD
*pdwZone
, DWORD dwFlags
, LPWSTR
*ppwszMappedUrl
, DWORD
*pdwOutFlags
)
1109 SecManagerImpl
*This
= impl_from_IInternetSecurityManagerEx2(iface
);
1111 TRACE("(%p)->(%p %p %08x %p %p)\n", This
, pUri
, pdwZone
, dwFlags
, ppwszMappedUrl
, pdwOutFlags
);
1113 if(This
->custom_manager
) {
1115 IInternetSecurityManagerEx2
*sec_mgr2
;
1117 hres
= IInternetSecurityManager_QueryInterface(This
->custom_manager
, &IID_IInternetSecurityManagerEx2
,
1119 if(SUCCEEDED(hres
)) {
1120 hres
= IInternetSecurityManagerEx2_MapUrlToZoneEx2(sec_mgr2
, pUri
, pdwZone
, dwFlags
, ppwszMappedUrl
, pdwOutFlags
);
1121 IInternetSecurityManagerEx2_Release(sec_mgr2
);
1125 hres
= IUri_GetDisplayUri(pUri
, &url
);
1129 hres
= IInternetSecurityManager_MapUrlToZone(This
->custom_manager
, url
, pdwZone
, dwFlags
);
1133 if(hres
!= INET_E_DEFAULT_ACTION
)
1138 return E_INVALIDARG
;
1141 *pdwZone
= URLZONE_INVALID
;
1142 return E_INVALIDARG
;
1146 FIXME("Unsupported flags: %08x\n", dwFlags
);
1148 return map_uri_to_zone(pUri
, pdwZone
, NULL
);
1151 static HRESULT WINAPI
SecManagerImpl_ProcessUrlActionEx2(IInternetSecurityManagerEx2
*iface
,
1152 IUri
*pUri
, DWORD dwAction
, BYTE
*pPolicy
, DWORD cbPolicy
, BYTE
*pContext
, DWORD cbContext
,
1153 DWORD dwFlags
, DWORD_PTR dwReserved
, DWORD
*pdwOutFlags
)
1155 SecManagerImpl
*This
= impl_from_IInternetSecurityManagerEx2(iface
);
1156 FIXME("(%p)->(%p %08x %p %d %p %d %08x %08x %p) stub\n", This
, pUri
, dwAction
, pPolicy
,
1157 cbPolicy
, pContext
, cbContext
, dwFlags
, (DWORD
)dwReserved
, pdwOutFlags
);
1161 static HRESULT WINAPI
SecManagerImpl_GetSecurityIdEx2(IInternetSecurityManagerEx2
*iface
,
1162 IUri
*pUri
, BYTE
*pbSecurityId
, DWORD
*pcbSecurityId
, DWORD_PTR dwReserved
)
1164 SecManagerImpl
*This
= impl_from_IInternetSecurityManagerEx2(iface
);
1165 TRACE("(%p)->(%p %p %p %08x) stub\n", This
, pUri
, pbSecurityId
, pcbSecurityId
, (DWORD
)dwReserved
);
1168 FIXME("dwReserved is not supported yet\n");
1170 if(!pUri
|| !pcbSecurityId
|| !pbSecurityId
)
1171 return E_INVALIDARG
;
1173 return get_security_id_for_uri(pUri
, pbSecurityId
, pcbSecurityId
);
1176 static HRESULT WINAPI
SecManagerImpl_QueryCustomPolicyEx2(IInternetSecurityManagerEx2
*iface
,
1177 IUri
*pUri
, REFGUID guidKey
, BYTE
**ppPolicy
, DWORD
*pcbPolicy
, BYTE
*pContext
,
1178 DWORD cbContext
, DWORD_PTR dwReserved
)
1180 SecManagerImpl
*This
= impl_from_IInternetSecurityManagerEx2(iface
);
1181 FIXME("(%p)->(%p %s %p %p %p %d %08x) stub\n", This
, pUri
, debugstr_guid(guidKey
), ppPolicy
, pcbPolicy
,
1182 pContext
, cbContext
, (DWORD
)dwReserved
);
1186 static const IInternetSecurityManagerEx2Vtbl VT_SecManagerImpl
=
1188 SecManagerImpl_QueryInterface
,
1189 SecManagerImpl_AddRef
,
1190 SecManagerImpl_Release
,
1191 SecManagerImpl_SetSecuritySite
,
1192 SecManagerImpl_GetSecuritySite
,
1193 SecManagerImpl_MapUrlToZone
,
1194 SecManagerImpl_GetSecurityId
,
1195 SecManagerImpl_ProcessUrlAction
,
1196 SecManagerImpl_QueryCustomPolicy
,
1197 SecManagerImpl_SetZoneMapping
,
1198 SecManagerImpl_GetZoneMappings
,
1199 SecManagerImpl_ProcessUrlActionEx
,
1200 SecManagerImpl_MapUrlToZoneEx2
,
1201 SecManagerImpl_ProcessUrlActionEx2
,
1202 SecManagerImpl_GetSecurityIdEx2
,
1203 SecManagerImpl_QueryCustomPolicyEx2
1206 HRESULT
SecManagerImpl_Construct(IUnknown
*pUnkOuter
, LPVOID
*ppobj
)
1208 SecManagerImpl
*This
;
1210 TRACE("(%p,%p)\n",pUnkOuter
,ppobj
);
1211 This
= heap_alloc(sizeof(*This
));
1213 /* Initialize the virtual function table. */
1214 This
->IInternetSecurityManagerEx2_iface
.lpVtbl
= &VT_SecManagerImpl
;
1217 This
->mgrsite
= NULL
;
1218 This
->custom_manager
= NULL
;
1222 URLMON_LockModule();
1227 /***********************************************************************
1228 * InternetZoneManager implementation
1232 IInternetZoneManagerEx2 IInternetZoneManagerEx2_iface
;
1235 DWORD zonemap_count
;
1238 static inline ZoneMgrImpl
*impl_from_IInternetZoneManagerEx2(IInternetZoneManagerEx2
*iface
)
1240 return CONTAINING_RECORD(iface
, ZoneMgrImpl
, IInternetZoneManagerEx2_iface
);
1244 /***********************************************************************
1245 * build_zonemap_from_reg [internal]
1247 * Enumerate the Zones in the Registry and return the Zones in a DWORD-array
1248 * The number of the Zones is returned in data[0]
1250 static LPDWORD
build_zonemap_from_reg(void)
1254 LPDWORD data
= NULL
;
1255 DWORD allocated
= 6; /* space for the zonecount and Zone "0" up to Zone "4" */
1261 res
= RegOpenKeyW(HKEY_CURRENT_USER
, wszZonesKey
, &hkey
);
1265 data
= heap_alloc(allocated
* sizeof(DWORD
));
1271 len
= ARRAY_SIZE(name
);
1272 res
= RegEnumKeyExW(hkey
, used
, name
, &len
, NULL
, NULL
, NULL
, NULL
);
1276 if (used
== allocated
) {
1280 new_data
= heap_realloc_zero(data
, allocated
* sizeof(DWORD
));
1286 data
[used
] = wcstol(name
, NULL
, 10);
1296 /* something failed */
1302 /********************************************************************
1303 * IInternetZoneManager_QueryInterface
1305 static HRESULT WINAPI
ZoneMgrImpl_QueryInterface(IInternetZoneManagerEx2
* iface
, REFIID riid
, void** ppvObject
)
1307 ZoneMgrImpl
* This
= impl_from_IInternetZoneManagerEx2(iface
);
1309 TRACE("(%p)->(%s,%p)\n", This
, debugstr_guid(riid
), ppvObject
);
1311 if(!This
|| !ppvObject
)
1312 return E_INVALIDARG
;
1314 if(IsEqualIID(&IID_IUnknown
, riid
)) {
1315 TRACE("(%p)->(IID_IUnknown %p)\n", This
, ppvObject
);
1316 }else if(IsEqualIID(&IID_IInternetZoneManager
, riid
)) {
1317 TRACE("(%p)->(IID_InternetZoneManager %p)\n", This
, ppvObject
);
1318 }else if(IsEqualIID(&IID_IInternetZoneManagerEx
, riid
)) {
1319 TRACE("(%p)->(IID_InternetZoneManagerEx %p)\n", This
, ppvObject
);
1320 }else if(IsEqualIID(&IID_IInternetZoneManagerEx2
, riid
)) {
1321 TRACE("(%p)->(IID_InternetZoneManagerEx2 %p)\n", This
, ppvObject
);
1325 FIXME("Unknown interface: %s\n", debugstr_guid(riid
));
1327 return E_NOINTERFACE
;
1331 IInternetZoneManagerEx2_AddRef(iface
);
1335 /********************************************************************
1336 * IInternetZoneManager_AddRef
1338 static ULONG WINAPI
ZoneMgrImpl_AddRef(IInternetZoneManagerEx2
* iface
)
1340 ZoneMgrImpl
* This
= impl_from_IInternetZoneManagerEx2(iface
);
1341 ULONG refCount
= InterlockedIncrement(&This
->ref
);
1343 TRACE("(%p)->(ref before=%u)\n",This
, refCount
- 1);
1348 /********************************************************************
1349 * IInternetZoneManager_Release
1351 static ULONG WINAPI
ZoneMgrImpl_Release(IInternetZoneManagerEx2
* iface
)
1353 ZoneMgrImpl
* This
= impl_from_IInternetZoneManagerEx2(iface
);
1354 ULONG refCount
= InterlockedDecrement(&This
->ref
);
1356 TRACE("(%p)->(ref before=%u)\n",This
, refCount
+ 1);
1359 while (This
->zonemap_count
) heap_free(This
->zonemaps
[--This
->zonemap_count
]);
1360 heap_free(This
->zonemaps
);
1362 URLMON_UnlockModule();
1368 /********************************************************************
1369 * IInternetZoneManager_GetZoneAttributes
1371 static HRESULT WINAPI
ZoneMgrImpl_GetZoneAttributes(IInternetZoneManagerEx2
* iface
,
1373 ZONEATTRIBUTES
* pZoneAttributes
)
1375 ZoneMgrImpl
* This
= impl_from_IInternetZoneManagerEx2(iface
);
1380 TRACE("(%p)->(%d %p)\n", This
, dwZone
, pZoneAttributes
);
1382 if (!pZoneAttributes
)
1383 return E_INVALIDARG
;
1385 hr
= open_zone_key(HKEY_CURRENT_USER
, dwZone
, &hcu
);
1387 return S_OK
; /* IE6 and older returned E_FAIL here */
1389 hr
= open_zone_key(HKEY_LOCAL_MACHINE
, dwZone
, &hklm
);
1391 TRACE("Zone %d not in HKLM\n", dwZone
);
1393 get_string_from_reg(hcu
, hklm
, L
"DisplayName", pZoneAttributes
->szDisplayName
, MAX_ZONE_PATH
);
1394 get_string_from_reg(hcu
, hklm
, L
"Description", pZoneAttributes
->szDescription
, MAX_ZONE_DESCRIPTION
);
1395 get_string_from_reg(hcu
, hklm
, L
"Icon", pZoneAttributes
->szIconPath
, MAX_ZONE_PATH
);
1396 get_dword_from_reg(hcu
, hklm
, L
"MinLevel", &pZoneAttributes
->dwTemplateMinLevel
);
1397 get_dword_from_reg(hcu
, hklm
, L
"CurrentLevel", &pZoneAttributes
->dwTemplateCurrentLevel
);
1398 get_dword_from_reg(hcu
, hklm
, L
"RecommendedLevel", &pZoneAttributes
->dwTemplateRecommended
);
1399 get_dword_from_reg(hcu
, hklm
, L
"Flags", &pZoneAttributes
->dwFlags
);
1406 /********************************************************************
1407 * IInternetZoneManager_SetZoneAttributes
1409 static HRESULT WINAPI
ZoneMgrImpl_SetZoneAttributes(IInternetZoneManagerEx2
* iface
,
1411 ZONEATTRIBUTES
* pZoneAttributes
)
1413 ZoneMgrImpl
* This
= impl_from_IInternetZoneManagerEx2(iface
);
1417 TRACE("(%p)->(%d %p)\n", This
, dwZone
, pZoneAttributes
);
1419 if (!pZoneAttributes
)
1420 return E_INVALIDARG
;
1422 hr
= open_zone_key(HKEY_CURRENT_USER
, dwZone
, &hcu
);
1424 return S_OK
; /* IE6 returned E_FAIL here */
1426 /* cbSize is ignored */
1427 RegSetValueExW(hcu
, L
"DisplayName", 0, REG_SZ
, (BYTE
*)pZoneAttributes
->szDisplayName
,
1428 (lstrlenW(pZoneAttributes
->szDisplayName
)+1)* sizeof(WCHAR
));
1430 RegSetValueExW(hcu
, L
"Description", 0, REG_SZ
, (BYTE
*)pZoneAttributes
->szDescription
,
1431 (lstrlenW(pZoneAttributes
->szDescription
)+1)* sizeof(WCHAR
));
1433 RegSetValueExW(hcu
, L
"Icon", 0, REG_SZ
, (BYTE
*)pZoneAttributes
->szIconPath
,
1434 (lstrlenW(pZoneAttributes
->szIconPath
)+1)* sizeof(WCHAR
));
1436 RegSetValueExW(hcu
, L
"MinLevel", 0, REG_DWORD
,
1437 (const BYTE
*) &pZoneAttributes
->dwTemplateMinLevel
, sizeof(DWORD
));
1439 RegSetValueExW(hcu
, L
"CurrentLevel", 0, REG_DWORD
,
1440 (const BYTE
*) &pZoneAttributes
->dwTemplateCurrentLevel
, sizeof(DWORD
));
1442 RegSetValueExW(hcu
, L
"RecommendedLevel", 0, REG_DWORD
,
1443 (const BYTE
*) &pZoneAttributes
->dwTemplateRecommended
, sizeof(DWORD
));
1445 RegSetValueExW(hcu
, L
"Flags", 0, REG_DWORD
, (const BYTE
*) &pZoneAttributes
->dwFlags
, sizeof(DWORD
));
1451 /********************************************************************
1452 * IInternetZoneManager_GetZoneCustomPolicy
1454 static HRESULT WINAPI
ZoneMgrImpl_GetZoneCustomPolicy(IInternetZoneManagerEx2
* iface
,
1459 URLZONEREG ulrZoneReg
)
1461 FIXME("(%p)->(%08x %s %p %p %08x) stub\n", iface
, dwZone
, debugstr_guid(guidKey
),
1462 ppPolicy
, pcbPolicy
, ulrZoneReg
);
1466 /********************************************************************
1467 * IInternetZoneManager_SetZoneCustomPolicy
1469 static HRESULT WINAPI
ZoneMgrImpl_SetZoneCustomPolicy(IInternetZoneManagerEx2
* iface
,
1474 URLZONEREG ulrZoneReg
)
1476 FIXME("(%p)->(%08x %s %p %08x %08x) stub\n", iface
, dwZone
, debugstr_guid(guidKey
),
1477 ppPolicy
, cbPolicy
, ulrZoneReg
);
1481 /********************************************************************
1482 * IInternetZoneManager_GetZoneActionPolicy
1484 static HRESULT WINAPI
ZoneMgrImpl_GetZoneActionPolicy(IInternetZoneManagerEx2
* iface
,
1485 DWORD dwZone
, DWORD dwAction
, BYTE
* pPolicy
, DWORD cbPolicy
, URLZONEREG urlZoneReg
)
1487 TRACE("(%p)->(%d %08x %p %d %d)\n", iface
, dwZone
, dwAction
, pPolicy
,
1488 cbPolicy
, urlZoneReg
);
1491 return E_INVALIDARG
;
1493 return get_action_policy(dwZone
, dwAction
, pPolicy
, cbPolicy
, urlZoneReg
);
1496 /********************************************************************
1497 * IInternetZoneManager_SetZoneActionPolicy
1499 static HRESULT WINAPI
ZoneMgrImpl_SetZoneActionPolicy(IInternetZoneManagerEx2
* iface
,
1504 URLZONEREG urlZoneReg
)
1506 FIXME("(%p)->(%08x %08x %p %08x %08x) stub\n", iface
, dwZone
, dwAction
, pPolicy
,
1507 cbPolicy
, urlZoneReg
);
1511 /********************************************************************
1512 * IInternetZoneManager_PromptAction
1514 static HRESULT WINAPI
ZoneMgrImpl_PromptAction(IInternetZoneManagerEx2
* iface
,
1519 DWORD dwPromptFlags
)
1521 FIXME("%p %08x %p %s %s %08x\n", iface
, dwAction
, hwndParent
,
1522 debugstr_w(pwszUrl
), debugstr_w(pwszText
), dwPromptFlags
);
1526 /********************************************************************
1527 * IInternetZoneManager_LogAction
1529 static HRESULT WINAPI
ZoneMgrImpl_LogAction(IInternetZoneManagerEx2
* iface
,
1535 FIXME("(%p)->(%08x %s %s %08x) stub\n", iface
, dwAction
, debugstr_w(pwszUrl
),
1536 debugstr_w(pwszText
), dwLogFlags
);
1540 /********************************************************************
1541 * IInternetZoneManager_CreateZoneEnumerator
1543 static HRESULT WINAPI
ZoneMgrImpl_CreateZoneEnumerator(IInternetZoneManagerEx2
* iface
,
1548 ZoneMgrImpl
* This
= impl_from_IInternetZoneManagerEx2(iface
);
1553 TRACE("(%p)->(%p, %p, 0x%08x)\n", This
, pdwEnum
, pdwCount
, dwFlags
);
1554 if (!pdwEnum
|| !pdwCount
|| (dwFlags
!= 0))
1555 return E_INVALIDARG
;
1557 data
= build_zonemap_from_reg();
1558 TRACE("found %d zones\n", data
? data
[0] : -1);
1563 for (i
= 0; i
< This
->zonemap_count
; i
++) {
1564 if (This
->zonemaps
&& !This
->zonemaps
[i
]) {
1565 This
->zonemaps
[i
] = data
;
1567 *pdwCount
= data
[0];
1572 if (This
->zonemaps
) {
1573 /* try to double the nr. of pointers in the array */
1574 new_maps
= heap_realloc_zero(This
->zonemaps
, This
->zonemap_count
* 2 * sizeof(LPDWORD
));
1576 This
->zonemap_count
*= 2;
1580 This
->zonemap_count
= 2;
1581 new_maps
= heap_alloc_zero(This
->zonemap_count
* sizeof(LPDWORD
));
1588 This
->zonemaps
= new_maps
;
1589 This
->zonemaps
[i
] = data
;
1591 *pdwCount
= data
[0];
1595 /********************************************************************
1596 * IInternetZoneManager_GetZoneAt
1598 static HRESULT WINAPI
ZoneMgrImpl_GetZoneAt(IInternetZoneManagerEx2
* iface
,
1603 ZoneMgrImpl
* This
= impl_from_IInternetZoneManagerEx2(iface
);
1606 TRACE("(%p)->(0x%08x, %d, %p)\n", This
, dwEnum
, dwIndex
, pdwZone
);
1608 /* make sure, that dwEnum and dwIndex are in the valid range */
1609 if (dwEnum
< This
->zonemap_count
) {
1610 if ((data
= This
->zonemaps
[dwEnum
])) {
1611 if (dwIndex
< data
[0]) {
1612 *pdwZone
= data
[dwIndex
+ 1];
1617 return E_INVALIDARG
;
1620 /********************************************************************
1621 * IInternetZoneManager_DestroyZoneEnumerator
1623 static HRESULT WINAPI
ZoneMgrImpl_DestroyZoneEnumerator(IInternetZoneManagerEx2
* iface
,
1626 ZoneMgrImpl
* This
= impl_from_IInternetZoneManagerEx2(iface
);
1629 TRACE("(%p)->(0x%08x)\n", This
, dwEnum
);
1630 /* make sure, that dwEnum is valid */
1631 if (dwEnum
< This
->zonemap_count
) {
1632 if ((data
= This
->zonemaps
[dwEnum
])) {
1633 This
->zonemaps
[dwEnum
] = NULL
;
1638 return E_INVALIDARG
;
1641 /********************************************************************
1642 * IInternetZoneManager_CopyTemplatePoliciesToZone
1644 static HRESULT WINAPI
ZoneMgrImpl_CopyTemplatePoliciesToZone(IInternetZoneManagerEx2
* iface
,
1649 FIXME("(%p)->(%08x %08x %08x) stub\n", iface
, dwTemplate
, dwZone
, dwReserved
);
1653 /********************************************************************
1654 * IInternetZoneManagerEx_GetZoneActionPolicyEx
1656 static HRESULT WINAPI
ZoneMgrImpl_GetZoneActionPolicyEx(IInternetZoneManagerEx2
* iface
,
1661 URLZONEREG urlZoneReg
,
1664 TRACE("(%p)->(%d, 0x%x, %p, %d, %d, 0x%x)\n", iface
, dwZone
,
1665 dwAction
, pPolicy
, cbPolicy
, urlZoneReg
, dwFlags
);
1668 return E_INVALIDARG
;
1671 FIXME("dwFlags 0x%x ignored\n", dwFlags
);
1673 return get_action_policy(dwZone
, dwAction
, pPolicy
, cbPolicy
, urlZoneReg
);
1676 /********************************************************************
1677 * IInternetZoneManagerEx_SetZoneActionPolicyEx
1679 static HRESULT WINAPI
ZoneMgrImpl_SetZoneActionPolicyEx(IInternetZoneManagerEx2
* iface
,
1684 URLZONEREG urlZoneReg
,
1687 FIXME("(%p)->(%d, 0x%x, %p, %d, %d, 0x%x) stub\n", iface
, dwZone
, dwAction
, pPolicy
,
1688 cbPolicy
, urlZoneReg
, dwFlags
);
1692 /********************************************************************
1693 * IInternetZoneManagerEx2_GetZoneAttributesEx
1695 static HRESULT WINAPI
ZoneMgrImpl_GetZoneAttributesEx(IInternetZoneManagerEx2
* iface
,
1697 ZONEATTRIBUTES
* pZoneAttributes
,
1700 TRACE("(%p)->(%d, %p, 0x%x)\n", iface
, dwZone
, pZoneAttributes
, dwFlags
);
1703 FIXME("dwFlags 0x%x ignored\n", dwFlags
);
1705 return IInternetZoneManagerEx2_GetZoneAttributes(iface
, dwZone
, pZoneAttributes
);
1709 /********************************************************************
1710 * IInternetZoneManagerEx2_GetZoneSecurityState
1712 static HRESULT WINAPI
ZoneMgrImpl_GetZoneSecurityState(IInternetZoneManagerEx2
* iface
,
1714 BOOL fRespectPolicy
,
1716 BOOL
*pfPolicyEncountered
)
1718 FIXME("(%p)->(%d, %d, %p, %p) stub\n", iface
, dwZoneIndex
, fRespectPolicy
,
1719 pdwState
, pfPolicyEncountered
);
1721 *pdwState
= SECURITY_IE_STATE_GREEN
;
1723 if (pfPolicyEncountered
)
1724 *pfPolicyEncountered
= FALSE
;
1729 /********************************************************************
1730 * IInternetZoneManagerEx2_GetIESecurityState
1732 static HRESULT WINAPI
ZoneMgrImpl_GetIESecurityState(IInternetZoneManagerEx2
* iface
,
1733 BOOL fRespectPolicy
,
1735 BOOL
*pfPolicyEncountered
,
1738 FIXME("(%p)->(%d, %p, %p, %d) stub\n", iface
, fRespectPolicy
, pdwState
,
1739 pfPolicyEncountered
, fNoCache
);
1741 *pdwState
= SECURITY_IE_STATE_GREEN
;
1743 if (pfPolicyEncountered
)
1744 *pfPolicyEncountered
= FALSE
;
1749 /********************************************************************
1750 * IInternetZoneManagerEx2_FixInsecureSettings
1752 static HRESULT WINAPI
ZoneMgrImpl_FixInsecureSettings(IInternetZoneManagerEx2
* iface
)
1754 FIXME("(%p) stub\n", iface
);
1758 /********************************************************************
1759 * IInternetZoneManager_Construct
1761 static const IInternetZoneManagerEx2Vtbl ZoneMgrImplVtbl
= {
1762 ZoneMgrImpl_QueryInterface
,
1764 ZoneMgrImpl_Release
,
1765 /* IInternetZoneManager */
1766 ZoneMgrImpl_GetZoneAttributes
,
1767 ZoneMgrImpl_SetZoneAttributes
,
1768 ZoneMgrImpl_GetZoneCustomPolicy
,
1769 ZoneMgrImpl_SetZoneCustomPolicy
,
1770 ZoneMgrImpl_GetZoneActionPolicy
,
1771 ZoneMgrImpl_SetZoneActionPolicy
,
1772 ZoneMgrImpl_PromptAction
,
1773 ZoneMgrImpl_LogAction
,
1774 ZoneMgrImpl_CreateZoneEnumerator
,
1775 ZoneMgrImpl_GetZoneAt
,
1776 ZoneMgrImpl_DestroyZoneEnumerator
,
1777 ZoneMgrImpl_CopyTemplatePoliciesToZone
,
1778 /* IInternetZoneManagerEx */
1779 ZoneMgrImpl_GetZoneActionPolicyEx
,
1780 ZoneMgrImpl_SetZoneActionPolicyEx
,
1781 /* IInternetZoneManagerEx2 */
1782 ZoneMgrImpl_GetZoneAttributesEx
,
1783 ZoneMgrImpl_GetZoneSecurityState
,
1784 ZoneMgrImpl_GetIESecurityState
,
1785 ZoneMgrImpl_FixInsecureSettings
,
1788 HRESULT
ZoneMgrImpl_Construct(IUnknown
*pUnkOuter
, LPVOID
*ppobj
)
1790 ZoneMgrImpl
* ret
= heap_alloc_zero(sizeof(ZoneMgrImpl
));
1792 TRACE("(%p %p)\n", pUnkOuter
, ppobj
);
1793 ret
->IInternetZoneManagerEx2_iface
.lpVtbl
= &ZoneMgrImplVtbl
;
1795 *ppobj
= &ret
->IInternetZoneManagerEx2_iface
;
1797 URLMON_LockModule();
1802 /***********************************************************************
1803 * CoInternetCreateSecurityManager (URLMON.@)
1806 HRESULT WINAPI
CoInternetCreateSecurityManager( IServiceProvider
*pSP
,
1807 IInternetSecurityManager
**ppSM
, DWORD dwReserved
)
1809 TRACE("%p %p %d\n", pSP
, ppSM
, dwReserved
);
1812 FIXME("pSP not supported\n");
1814 return SecManagerImpl_Construct(NULL
, (void**) ppSM
);
1817 /********************************************************************
1818 * CoInternetCreateZoneManager (URLMON.@)
1820 HRESULT WINAPI
CoInternetCreateZoneManager(IServiceProvider
* pSP
, IInternetZoneManager
** ppZM
, DWORD dwReserved
)
1822 TRACE("(%p %p %x)\n", pSP
, ppZM
, dwReserved
);
1823 return ZoneMgrImpl_Construct(NULL
, (void**)ppZM
);
1826 static HRESULT
parse_security_url(const WCHAR
*url
, PSUACTION action
, WCHAR
**result
) {
1827 IInternetProtocolInfo
*protocol_info
;
1828 WCHAR
*tmp
, *new_url
= NULL
, *alloc_url
= NULL
;
1829 DWORD size
, new_size
;
1830 HRESULT hres
= S_OK
, parse_hres
;
1833 TRACE("parsing %s\n", debugstr_w(url
));
1835 protocol_info
= get_protocol_info(url
);
1839 size
= lstrlenW(url
)+1;
1840 new_url
= CoTaskMemAlloc(size
*sizeof(WCHAR
));
1842 hres
= E_OUTOFMEMORY
;
1847 parse_hres
= IInternetProtocolInfo_ParseUrl(protocol_info
, url
, PARSE_SECURITY_URL
, 0, new_url
, size
, &new_size
, 0);
1848 if(parse_hres
== S_FALSE
) {
1850 hres
= E_UNEXPECTED
;
1854 tmp
= CoTaskMemRealloc(new_url
, new_size
*sizeof(WCHAR
));
1856 hres
= E_OUTOFMEMORY
;
1860 parse_hres
= IInternetProtocolInfo_ParseUrl(protocol_info
, url
, PARSE_SECURITY_URL
, 0, new_url
,
1861 new_size
, &new_size
, 0);
1862 if(parse_hres
== S_FALSE
) {
1868 if(parse_hres
!= S_OK
|| !wcscmp(url
, new_url
))
1871 CoTaskMemFree(alloc_url
);
1872 url
= alloc_url
= new_url
;
1876 CoTaskMemFree(new_url
);
1879 WARN("failed: %08x\n", hres
);
1880 CoTaskMemFree(alloc_url
);
1884 if(action
== PSU_DEFAULT
&& (protocol_info
= get_protocol_info(url
))) {
1885 size
= lstrlenW(url
)+1;
1886 new_url
= CoTaskMemAlloc(size
* sizeof(WCHAR
));
1889 parse_hres
= IInternetProtocolInfo_ParseUrl(protocol_info
, url
, PARSE_SECURITY_DOMAIN
, 0,
1890 new_url
, size
, &new_size
, 0);
1891 if(parse_hres
== S_FALSE
) {
1893 tmp
= CoTaskMemRealloc(new_url
, new_size
*sizeof(WCHAR
));
1896 parse_hres
= IInternetProtocolInfo_ParseUrl(protocol_info
, url
, PARSE_SECURITY_DOMAIN
, 0, new_url
,
1897 new_size
, &new_size
, 0);
1898 if(parse_hres
== S_FALSE
)
1901 hres
= E_OUTOFMEMORY
;
1904 hres
= E_UNEXPECTED
;
1908 if(hres
== S_OK
&& parse_hres
== S_OK
) {
1909 CoTaskMemFree(alloc_url
);
1910 url
= alloc_url
= new_url
;
1914 CoTaskMemFree(new_url
);
1916 hres
= E_OUTOFMEMORY
;
1918 IInternetProtocolInfo_Release(protocol_info
);
1922 WARN("failed %08x\n", hres
);
1923 CoTaskMemFree(alloc_url
);
1928 size
= lstrlenW(url
)+1;
1929 alloc_url
= CoTaskMemAlloc(size
* sizeof(WCHAR
));
1931 return E_OUTOFMEMORY
;
1932 memcpy(alloc_url
, url
, size
* sizeof(WCHAR
));
1935 *result
= alloc_url
;
1939 /********************************************************************
1940 * CoInternetGetSecurityUrl (URLMON.@)
1942 HRESULT WINAPI
CoInternetGetSecurityUrl(LPCWSTR pwzUrl
, LPWSTR
*ppwzSecUrl
, PSUACTION psuAction
, DWORD dwReserved
)
1947 TRACE("(%p,%p,%u,%u)\n", pwzUrl
, ppwzSecUrl
, psuAction
, dwReserved
);
1949 hres
= parse_security_url(pwzUrl
, psuAction
, &secure_url
);
1953 if(psuAction
!= PSU_SECURITY_URL_ONLY
) {
1954 PARSEDURLW parsed_url
= { sizeof(parsed_url
) };
1957 /* FIXME: Use helpers from uri.c */
1958 if(SUCCEEDED(ParseURLW(secure_url
, &parsed_url
))) {
1961 switch(parsed_url
.nScheme
) {
1962 case URL_SCHEME_FTP
:
1963 case URL_SCHEME_HTTP
:
1964 case URL_SCHEME_HTTPS
:
1965 size
= lstrlenW(secure_url
)+1;
1966 new_url
= CoTaskMemAlloc(size
* sizeof(WCHAR
));
1968 hres
= UrlGetPartW(secure_url
, new_url
, &size
, URL_PART_HOSTNAME
, URL_PARTFLAG_KEEPSCHEME
);
1970 hres
= E_OUTOFMEMORY
;
1971 CoTaskMemFree(secure_url
);
1973 WARN("UrlGetPart failed: %08x\n", hres
);
1974 CoTaskMemFree(new_url
);
1975 return FAILED(hres
) ? hres
: E_FAIL
;
1977 secure_url
= new_url
;
1982 *ppwzSecUrl
= secure_url
;
1986 /********************************************************************
1987 * CoInternetGetSecurityUrlEx (URLMON.@)
1989 HRESULT WINAPI
CoInternetGetSecurityUrlEx(IUri
*pUri
, IUri
**ppSecUri
, PSUACTION psuAction
, DWORD_PTR dwReserved
)
1991 URL_SCHEME scheme_type
;
1996 TRACE("(%p,%p,%u,%u)\n", pUri
, ppSecUri
, psuAction
, (DWORD
)dwReserved
);
1998 if(!pUri
|| !ppSecUri
)
1999 return E_INVALIDARG
;
2001 hres
= IUri_GetDisplayUri(pUri
, &secure_uri
);
2005 hres
= parse_security_url(secure_uri
, psuAction
, &ret_url
);
2006 SysFreeString(secure_uri
);
2010 /* File URIs have to hierarchical. */
2011 hres
= IUri_GetScheme(pUri
, (DWORD
*)&scheme_type
);
2012 if(SUCCEEDED(hres
) && scheme_type
== URL_SCHEME_FILE
) {
2013 const WCHAR
*tmp
= ret_url
;
2015 /* Check and see if a "//" is after the scheme name. */
2016 tmp
+= ARRAY_SIZE(L
"file");
2017 if(*tmp
!= '/' || *(tmp
+1) != '/')
2018 hres
= E_INVALIDARG
;
2022 hres
= CreateUri(ret_url
, Uri_CREATE_ALLOW_IMPLICIT_WILDCARD_SCHEME
, 0, ppSecUri
);
2023 CoTaskMemFree(ret_url
);
2027 /********************************************************************
2028 * CompareSecurityIds (URLMON.@)
2030 HRESULT WINAPI
CompareSecurityIds(BYTE
*secid1
, DWORD size1
, BYTE
*secid2
, DWORD size2
, DWORD reserved
)
2032 FIXME("(%p %d %p %d %x)\n", secid1
, size1
, secid2
, size2
, reserved
);
2036 /********************************************************************
2037 * IsInternetESCEnabledLocal (URLMON.108)
2039 * Undocumented, returns TRUE if IE is running in Enhanced Security Configuration.
2041 BOOL WINAPI
IsInternetESCEnabledLocal(void)
2043 static BOOL esc_initialized
, esc_enabled
;
2047 if(!esc_initialized
) {
2048 DWORD type
, size
, val
;
2051 if(RegOpenKeyExW(HKEY_CURRENT_USER
, zone_map_keyW
, 0, KEY_QUERY_VALUE
, &zone_map
) == ERROR_SUCCESS
) {
2052 size
= sizeof(DWORD
);
2053 if(RegQueryValueExW(zone_map
, L
"IEHarden", NULL
, &type
, (BYTE
*)&val
, &size
) == ERROR_SUCCESS
)
2054 esc_enabled
= type
== REG_DWORD
&& val
!= 0;
2055 RegCloseKey(zone_map
);
2057 esc_initialized
= TRUE
;