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: %ld\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: %ld\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 %ld 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 %ld 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: %ld\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: %ld\n", debugstr_w(domain
), res
);
298 RegCloseKey(domain_key
);
302 if(subdomain_count
) {
307 subdomain
= malloc((subdomain_len
+ 1) * sizeof(WCHAR
));
309 RegCloseKey(domain_key
);
310 return E_OUTOFMEMORY
;
313 component
= strndupW(host
, matched
-host
- 1);
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
) {
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: %ld\n", debugstr_w(subdomain
),
338 debugstr_w(domain
), res
);
341 RegCloseKey(domain_key
);
345 found
= get_zone_for_scheme(subdomain_key
, schema
, zone
);
346 check_domain
= FALSE
;
347 RegCloseKey(subdomain_key
);
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
= malloc((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: %ld\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=%lu\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=%lu\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 %08lx)\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: %08lx\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 %08Ix)\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 %08lx %p %08lx %p %08lx %08lx %08lx)\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 %lx\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 %lx\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 %08lx %08lx )\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)->(%08lx %s %08lx)\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)->(%08lx %p %08lx)\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 %08lx %p %ld %p %ld %08lx %08lx %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 %08lx %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: %08lx\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 %08lx %p %ld %p %ld %08lx %08Ix %p) stub\n", This
, pUri
, dwAction
, pPolicy
,
1157 cbPolicy
, pContext
, cbContext
, dwFlags
, 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 %08Ix) stub\n", This
, pUri
, pbSecurityId
, pcbSecurityId
, 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 %ld %08Ix) stub\n", This
, pUri
, debugstr_guid(guidKey
), ppPolicy
, pcbPolicy
,
1182 pContext
, cbContext
, 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
= malloc(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
= malloc(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
= realloc(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=%lu)\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=%lu)\n",This
, refCount
+ 1);
1359 while (This
->zonemap_count
) free(This
->zonemaps
[--This
->zonemap_count
]);
1360 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)->(%ld %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 %ld 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)->(%ld %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)->(%08lx %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)->(%08lx %s %p %08lx %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)->(%ld %08lx %p %ld %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)->(%08lx %08lx %p %08lx %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 %08lx %p %s %s %08lx\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)->(%08lx %s %s %08lx) 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
);
1551 DWORD new_map_count
;
1554 TRACE("(%p)->(%p, %p, 0x%08lx)\n", This
, pdwEnum
, pdwCount
, dwFlags
);
1555 if (!pdwEnum
|| !pdwCount
|| (dwFlags
!= 0))
1556 return E_INVALIDARG
;
1558 data
= build_zonemap_from_reg();
1559 TRACE("found %ld zones\n", data
? data
[0] : -1);
1564 for (i
= 0; i
< This
->zonemap_count
; i
++) {
1565 if (This
->zonemaps
&& !This
->zonemaps
[i
]) {
1566 This
->zonemaps
[i
] = data
;
1568 *pdwCount
= data
[0];
1573 /* try to double the number of pointers in the array */
1574 new_map_count
= This
->zonemaps
? This
->zonemap_count
* 2 : 2;
1575 new_maps
= _recalloc(This
->zonemaps
, new_map_count
, sizeof(DWORD
*));
1580 This
->zonemaps
= new_maps
;
1581 This
->zonemap_count
= new_map_count
;
1582 This
->zonemaps
[i
] = data
;
1584 *pdwCount
= data
[0];
1588 /********************************************************************
1589 * IInternetZoneManager_GetZoneAt
1591 static HRESULT WINAPI
ZoneMgrImpl_GetZoneAt(IInternetZoneManagerEx2
* iface
,
1596 ZoneMgrImpl
* This
= impl_from_IInternetZoneManagerEx2(iface
);
1599 TRACE("(%p)->(0x%08lx, %ld, %p)\n", This
, dwEnum
, dwIndex
, pdwZone
);
1601 /* make sure, that dwEnum and dwIndex are in the valid range */
1602 if (dwEnum
< This
->zonemap_count
) {
1603 if ((data
= This
->zonemaps
[dwEnum
])) {
1604 if (dwIndex
< data
[0]) {
1605 *pdwZone
= data
[dwIndex
+ 1];
1610 return E_INVALIDARG
;
1613 /********************************************************************
1614 * IInternetZoneManager_DestroyZoneEnumerator
1616 static HRESULT WINAPI
ZoneMgrImpl_DestroyZoneEnumerator(IInternetZoneManagerEx2
* iface
,
1619 ZoneMgrImpl
* This
= impl_from_IInternetZoneManagerEx2(iface
);
1622 TRACE("(%p)->(0x%08lx)\n", This
, dwEnum
);
1623 /* make sure, that dwEnum is valid */
1624 if (dwEnum
< This
->zonemap_count
) {
1625 if ((data
= This
->zonemaps
[dwEnum
])) {
1626 This
->zonemaps
[dwEnum
] = NULL
;
1631 return E_INVALIDARG
;
1634 /********************************************************************
1635 * IInternetZoneManager_CopyTemplatePoliciesToZone
1637 static HRESULT WINAPI
ZoneMgrImpl_CopyTemplatePoliciesToZone(IInternetZoneManagerEx2
* iface
,
1642 FIXME("(%p)->(%08lx %08lx %08lx) stub\n", iface
, dwTemplate
, dwZone
, dwReserved
);
1646 /********************************************************************
1647 * IInternetZoneManagerEx_GetZoneActionPolicyEx
1649 static HRESULT WINAPI
ZoneMgrImpl_GetZoneActionPolicyEx(IInternetZoneManagerEx2
* iface
,
1654 URLZONEREG urlZoneReg
,
1657 TRACE("(%p)->(%ld, 0x%lx, %p, %ld, %d, 0x%lx)\n", iface
, dwZone
,
1658 dwAction
, pPolicy
, cbPolicy
, urlZoneReg
, dwFlags
);
1661 return E_INVALIDARG
;
1664 FIXME("dwFlags 0x%lx ignored\n", dwFlags
);
1666 return get_action_policy(dwZone
, dwAction
, pPolicy
, cbPolicy
, urlZoneReg
);
1669 /********************************************************************
1670 * IInternetZoneManagerEx_SetZoneActionPolicyEx
1672 static HRESULT WINAPI
ZoneMgrImpl_SetZoneActionPolicyEx(IInternetZoneManagerEx2
* iface
,
1677 URLZONEREG urlZoneReg
,
1680 FIXME("(%p)->(%ld, 0x%lx, %p, %ld, %d, 0x%lx) stub\n", iface
, dwZone
, dwAction
, pPolicy
,
1681 cbPolicy
, urlZoneReg
, dwFlags
);
1685 /********************************************************************
1686 * IInternetZoneManagerEx2_GetZoneAttributesEx
1688 static HRESULT WINAPI
ZoneMgrImpl_GetZoneAttributesEx(IInternetZoneManagerEx2
* iface
,
1690 ZONEATTRIBUTES
* pZoneAttributes
,
1693 TRACE("(%p)->(%ld, %p, 0x%lx)\n", iface
, dwZone
, pZoneAttributes
, dwFlags
);
1696 FIXME("dwFlags 0x%lx ignored\n", dwFlags
);
1698 return IInternetZoneManagerEx2_GetZoneAttributes(iface
, dwZone
, pZoneAttributes
);
1702 /********************************************************************
1703 * IInternetZoneManagerEx2_GetZoneSecurityState
1705 static HRESULT WINAPI
ZoneMgrImpl_GetZoneSecurityState(IInternetZoneManagerEx2
* iface
,
1707 BOOL fRespectPolicy
,
1709 BOOL
*pfPolicyEncountered
)
1711 FIXME("(%p)->(%ld, %d, %p, %p) stub\n", iface
, dwZoneIndex
, fRespectPolicy
,
1712 pdwState
, pfPolicyEncountered
);
1714 *pdwState
= SECURITY_IE_STATE_GREEN
;
1716 if (pfPolicyEncountered
)
1717 *pfPolicyEncountered
= FALSE
;
1722 /********************************************************************
1723 * IInternetZoneManagerEx2_GetIESecurityState
1725 static HRESULT WINAPI
ZoneMgrImpl_GetIESecurityState(IInternetZoneManagerEx2
* iface
,
1726 BOOL fRespectPolicy
,
1728 BOOL
*pfPolicyEncountered
,
1731 FIXME("(%p)->(%d, %p, %p, %d) stub\n", iface
, fRespectPolicy
, pdwState
,
1732 pfPolicyEncountered
, fNoCache
);
1734 *pdwState
= SECURITY_IE_STATE_GREEN
;
1736 if (pfPolicyEncountered
)
1737 *pfPolicyEncountered
= FALSE
;
1742 /********************************************************************
1743 * IInternetZoneManagerEx2_FixInsecureSettings
1745 static HRESULT WINAPI
ZoneMgrImpl_FixInsecureSettings(IInternetZoneManagerEx2
* iface
)
1747 FIXME("(%p) stub\n", iface
);
1751 /********************************************************************
1752 * IInternetZoneManager_Construct
1754 static const IInternetZoneManagerEx2Vtbl ZoneMgrImplVtbl
= {
1755 ZoneMgrImpl_QueryInterface
,
1757 ZoneMgrImpl_Release
,
1758 /* IInternetZoneManager */
1759 ZoneMgrImpl_GetZoneAttributes
,
1760 ZoneMgrImpl_SetZoneAttributes
,
1761 ZoneMgrImpl_GetZoneCustomPolicy
,
1762 ZoneMgrImpl_SetZoneCustomPolicy
,
1763 ZoneMgrImpl_GetZoneActionPolicy
,
1764 ZoneMgrImpl_SetZoneActionPolicy
,
1765 ZoneMgrImpl_PromptAction
,
1766 ZoneMgrImpl_LogAction
,
1767 ZoneMgrImpl_CreateZoneEnumerator
,
1768 ZoneMgrImpl_GetZoneAt
,
1769 ZoneMgrImpl_DestroyZoneEnumerator
,
1770 ZoneMgrImpl_CopyTemplatePoliciesToZone
,
1771 /* IInternetZoneManagerEx */
1772 ZoneMgrImpl_GetZoneActionPolicyEx
,
1773 ZoneMgrImpl_SetZoneActionPolicyEx
,
1774 /* IInternetZoneManagerEx2 */
1775 ZoneMgrImpl_GetZoneAttributesEx
,
1776 ZoneMgrImpl_GetZoneSecurityState
,
1777 ZoneMgrImpl_GetIESecurityState
,
1778 ZoneMgrImpl_FixInsecureSettings
,
1781 HRESULT
ZoneMgrImpl_Construct(IUnknown
*pUnkOuter
, LPVOID
*ppobj
)
1783 ZoneMgrImpl
*ret
= calloc(1, sizeof(ZoneMgrImpl
));
1785 TRACE("(%p %p)\n", pUnkOuter
, ppobj
);
1786 ret
->IInternetZoneManagerEx2_iface
.lpVtbl
= &ZoneMgrImplVtbl
;
1788 *ppobj
= &ret
->IInternetZoneManagerEx2_iface
;
1790 URLMON_LockModule();
1795 /***********************************************************************
1796 * CoInternetCreateSecurityManager (URLMON.@)
1799 HRESULT WINAPI
CoInternetCreateSecurityManager( IServiceProvider
*pSP
,
1800 IInternetSecurityManager
**ppSM
, DWORD dwReserved
)
1802 TRACE("%p %p %ld\n", pSP
, ppSM
, dwReserved
);
1805 FIXME("pSP not supported\n");
1807 return SecManagerImpl_Construct(NULL
, (void**) ppSM
);
1810 /********************************************************************
1811 * CoInternetCreateZoneManager (URLMON.@)
1813 HRESULT WINAPI
CoInternetCreateZoneManager(IServiceProvider
* pSP
, IInternetZoneManager
** ppZM
, DWORD dwReserved
)
1815 TRACE("(%p %p %lx)\n", pSP
, ppZM
, dwReserved
);
1816 return ZoneMgrImpl_Construct(NULL
, (void**)ppZM
);
1819 static HRESULT
parse_security_url(const WCHAR
*url
, PSUACTION action
, WCHAR
**result
) {
1820 IInternetProtocolInfo
*protocol_info
;
1821 WCHAR
*tmp
, *new_url
= NULL
, *alloc_url
= NULL
;
1822 DWORD size
, new_size
;
1823 HRESULT hres
= S_OK
, parse_hres
;
1826 TRACE("parsing %s\n", debugstr_w(url
));
1828 protocol_info
= get_protocol_info(url
);
1832 size
= lstrlenW(url
)+1;
1833 new_url
= CoTaskMemAlloc(size
*sizeof(WCHAR
));
1835 hres
= E_OUTOFMEMORY
;
1840 parse_hres
= IInternetProtocolInfo_ParseUrl(protocol_info
, url
, PARSE_SECURITY_URL
, 0, new_url
, size
, &new_size
, 0);
1841 if(parse_hres
== S_FALSE
) {
1843 hres
= E_UNEXPECTED
;
1847 tmp
= CoTaskMemRealloc(new_url
, new_size
*sizeof(WCHAR
));
1849 hres
= E_OUTOFMEMORY
;
1853 parse_hres
= IInternetProtocolInfo_ParseUrl(protocol_info
, url
, PARSE_SECURITY_URL
, 0, new_url
,
1854 new_size
, &new_size
, 0);
1855 if(parse_hres
== S_FALSE
) {
1861 if(parse_hres
!= S_OK
|| !wcscmp(url
, new_url
))
1864 CoTaskMemFree(alloc_url
);
1865 url
= alloc_url
= new_url
;
1869 CoTaskMemFree(new_url
);
1872 WARN("failed: %08lx\n", hres
);
1873 CoTaskMemFree(alloc_url
);
1877 if(action
== PSU_DEFAULT
&& (protocol_info
= get_protocol_info(url
))) {
1878 size
= lstrlenW(url
)+1;
1879 new_url
= CoTaskMemAlloc(size
* sizeof(WCHAR
));
1882 parse_hres
= IInternetProtocolInfo_ParseUrl(protocol_info
, url
, PARSE_SECURITY_DOMAIN
, 0,
1883 new_url
, size
, &new_size
, 0);
1884 if(parse_hres
== S_FALSE
) {
1886 tmp
= CoTaskMemRealloc(new_url
, new_size
*sizeof(WCHAR
));
1889 parse_hres
= IInternetProtocolInfo_ParseUrl(protocol_info
, url
, PARSE_SECURITY_DOMAIN
, 0, new_url
,
1890 new_size
, &new_size
, 0);
1891 if(parse_hres
== S_FALSE
)
1894 hres
= E_OUTOFMEMORY
;
1897 hres
= E_UNEXPECTED
;
1901 if(hres
== S_OK
&& parse_hres
== S_OK
) {
1902 CoTaskMemFree(alloc_url
);
1903 url
= alloc_url
= new_url
;
1907 CoTaskMemFree(new_url
);
1909 hres
= E_OUTOFMEMORY
;
1911 IInternetProtocolInfo_Release(protocol_info
);
1915 WARN("failed %08lx\n", hres
);
1916 CoTaskMemFree(alloc_url
);
1921 size
= lstrlenW(url
)+1;
1922 alloc_url
= CoTaskMemAlloc(size
* sizeof(WCHAR
));
1924 return E_OUTOFMEMORY
;
1925 memcpy(alloc_url
, url
, size
* sizeof(WCHAR
));
1928 *result
= alloc_url
;
1932 /********************************************************************
1933 * CoInternetGetSecurityUrl (URLMON.@)
1935 HRESULT WINAPI
CoInternetGetSecurityUrl(LPCWSTR pwzUrl
, LPWSTR
*ppwzSecUrl
, PSUACTION psuAction
, DWORD dwReserved
)
1940 TRACE("(%p,%p,%u,%lu)\n", pwzUrl
, ppwzSecUrl
, psuAction
, dwReserved
);
1942 hres
= parse_security_url(pwzUrl
, psuAction
, &secure_url
);
1946 if(psuAction
!= PSU_SECURITY_URL_ONLY
) {
1947 PARSEDURLW parsed_url
= { sizeof(parsed_url
) };
1950 /* FIXME: Use helpers from uri.c */
1951 if(SUCCEEDED(ParseURLW(secure_url
, &parsed_url
))) {
1954 switch(parsed_url
.nScheme
) {
1955 case URL_SCHEME_FTP
:
1956 case URL_SCHEME_HTTP
:
1957 case URL_SCHEME_HTTPS
:
1958 size
= lstrlenW(secure_url
)+1;
1959 new_url
= CoTaskMemAlloc(size
* sizeof(WCHAR
));
1961 hres
= UrlGetPartW(secure_url
, new_url
, &size
, URL_PART_HOSTNAME
, URL_PARTFLAG_KEEPSCHEME
);
1963 hres
= E_OUTOFMEMORY
;
1964 CoTaskMemFree(secure_url
);
1966 WARN("UrlGetPart failed: %08lx\n", hres
);
1967 CoTaskMemFree(new_url
);
1968 return FAILED(hres
) ? hres
: E_FAIL
;
1970 secure_url
= new_url
;
1975 *ppwzSecUrl
= secure_url
;
1979 /********************************************************************
1980 * CoInternetGetSecurityUrlEx (URLMON.@)
1982 HRESULT WINAPI
CoInternetGetSecurityUrlEx(IUri
*pUri
, IUri
**ppSecUri
, PSUACTION psuAction
, DWORD_PTR dwReserved
)
1984 URL_SCHEME scheme_type
;
1989 TRACE("(%p,%p,%u,%Iu)\n", pUri
, ppSecUri
, psuAction
, dwReserved
);
1991 if(!pUri
|| !ppSecUri
)
1992 return E_INVALIDARG
;
1994 hres
= IUri_GetDisplayUri(pUri
, &secure_uri
);
1998 hres
= parse_security_url(secure_uri
, psuAction
, &ret_url
);
1999 SysFreeString(secure_uri
);
2003 /* File URIs have to hierarchical. */
2004 hres
= IUri_GetScheme(pUri
, (DWORD
*)&scheme_type
);
2005 if(SUCCEEDED(hres
) && scheme_type
== URL_SCHEME_FILE
) {
2006 const WCHAR
*tmp
= ret_url
;
2008 /* Check and see if a "//" is after the scheme name. */
2009 tmp
+= ARRAY_SIZE(L
"file");
2010 if(*tmp
!= '/' || *(tmp
+1) != '/')
2011 hres
= E_INVALIDARG
;
2015 hres
= CreateUri(ret_url
, Uri_CREATE_ALLOW_IMPLICIT_WILDCARD_SCHEME
, 0, ppSecUri
);
2016 CoTaskMemFree(ret_url
);
2020 /********************************************************************
2021 * CompareSecurityIds (URLMON.@)
2023 HRESULT WINAPI
CompareSecurityIds(BYTE
*secid1
, DWORD size1
, BYTE
*secid2
, DWORD size2
, DWORD reserved
)
2025 FIXME("(%p %ld %p %ld %lx)\n", secid1
, size1
, secid2
, size2
, reserved
);
2029 /********************************************************************
2030 * IsInternetESCEnabledLocal (URLMON.108)
2032 * Undocumented, returns TRUE if IE is running in Enhanced Security Configuration.
2034 BOOL WINAPI
IsInternetESCEnabledLocal(void)
2036 static BOOL esc_initialized
, esc_enabled
;
2040 if(!esc_initialized
) {
2041 DWORD type
, size
, val
;
2044 if(RegOpenKeyExW(HKEY_CURRENT_USER
, zone_map_keyW
, 0, KEY_QUERY_VALUE
, &zone_map
) == ERROR_SUCCESS
) {
2045 size
= sizeof(DWORD
);
2046 if(RegQueryValueExW(zone_map
, L
"IEHarden", NULL
, &type
, (BYTE
*)&val
, &size
) == ERROR_SUCCESS
)
2047 esc_enabled
= type
== REG_DWORD
&& val
!= 0;
2048 RegCloseKey(zone_map
);
2050 esc_initialized
= TRUE
;