2 * Internet Security and Zone Manager
4 * Copyright (c) 2004 Huw D M Davies
5 * Copyright 2004 Jacek Caban
6 * Copyright 2009 Detlef Riekenberg
7 * Copyright 2011 Thomas Mullaly for CodeWeavers
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
26 #include "urlmon_main.h"
30 #define NO_SHLWAPI_REG
33 #include "wine/debug.h"
35 WINE_DEFAULT_DEBUG_CHANNEL(urlmon
);
37 static const WCHAR currentlevelW
[] = {'C','u','r','r','e','n','t','L','e','v','e','l',0};
38 static const WCHAR descriptionW
[] = {'D','e','s','c','r','i','p','t','i','o','n',0};
39 static const WCHAR displaynameW
[] = {'D','i','s','p','l','a','y','N','a','m','e',0};
40 static const WCHAR fileW
[] = {'f','i','l','e',0};
41 static const WCHAR flagsW
[] = {'F','l','a','g','s',0};
42 static const WCHAR iconW
[] = {'I','c','o','n',0};
43 static const WCHAR minlevelW
[] = {'M','i','n','L','e','v','e','l',0};
44 static const WCHAR recommendedlevelW
[] = {'R','e','c','o','m','m','e','n','d','e','d',
45 'L','e','v','e','l',0};
46 static const WCHAR wszZonesKey
[] = {'S','o','f','t','w','a','r','e','\\',
47 'M','i','c','r','o','s','o','f','t','\\',
48 'W','i','n','d','o','w','s','\\',
49 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
50 'I','n','t','e','r','n','e','t',' ','S','e','t','t','i','n','g','s','\\',
51 'Z','o','n','e','s','\\',0};
52 static const WCHAR zone_map_keyW
[] = {'S','o','f','t','w','a','r','e','\\',
53 'M','i','c','r','o','s','o','f','t','\\',
54 'W','i','n','d','o','w','s','\\',
55 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
56 'I','n','t','e','r','n','e','t',' ','S','e','t','t','i','n','g','s','\\',
57 'Z','o','n','e','M','a','p',0};
58 static const WCHAR wszZoneMapDomainsKey
[] = {'S','o','f','t','w','a','r','e','\\',
59 'M','i','c','r','o','s','o','f','t','\\',
60 'W','i','n','d','o','w','s','\\',
61 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
62 'I','n','t','e','r','n','e','t',' ','S','e','t','t','i','n','g','s','\\',
63 'Z','o','n','e','M','a','p','\\',
64 'D','o','m','a','i','n','s',0};
66 static inline BOOL
is_drive_path(const WCHAR
*path
)
68 return isalphaW(*path
) && *(path
+1) == ':';
71 /* List of schemes types Windows seems to expect to be hierarchical. */
72 static inline BOOL
is_hierarchical_scheme(URL_SCHEME type
) {
73 return(type
== URL_SCHEME_HTTP
|| type
== URL_SCHEME_FTP
||
74 type
== URL_SCHEME_GOPHER
|| type
== URL_SCHEME_NNTP
||
75 type
== URL_SCHEME_TELNET
|| type
== URL_SCHEME_WAIS
||
76 type
== URL_SCHEME_FILE
|| type
== URL_SCHEME_HTTPS
||
77 type
== URL_SCHEME_RES
);
80 /********************************************************************
81 * get_string_from_reg [internal]
83 * helper to get a string from the reg.
86 static void get_string_from_reg(HKEY hcu
, HKEY hklm
, LPCWSTR name
, LPWSTR out
, DWORD maxlen
)
89 DWORD len
= maxlen
* sizeof(WCHAR
);
92 res
= RegQueryValueExW(hcu
, name
, NULL
, &type
, (LPBYTE
) out
, &len
);
95 len
= maxlen
* sizeof(WCHAR
);
97 res
= RegQueryValueExW(hklm
, name
, NULL
, &type
, (LPBYTE
) out
, &len
);
101 TRACE("%s failed: %d\n", debugstr_w(name
), res
);
106 /********************************************************************
107 * get_dword_from_reg [internal]
109 * helper to get a dword from the reg.
112 static void get_dword_from_reg(HKEY hcu
, HKEY hklm
, LPCWSTR name
, LPDWORD out
)
114 DWORD type
= REG_DWORD
;
115 DWORD len
= sizeof(DWORD
);
118 res
= RegQueryValueExW(hcu
, name
, NULL
, &type
, (LPBYTE
) out
, &len
);
123 res
= RegQueryValueExW(hklm
, name
, NULL
, &type
, (LPBYTE
) out
, &len
);
127 TRACE("%s failed: %d\n", debugstr_w(name
), res
);
132 static HRESULT
get_zone_from_reg(LPCWSTR schema
, DWORD
*zone
)
137 static const WCHAR wszZoneMapProtocolKey
[] =
138 {'S','o','f','t','w','a','r','e','\\',
139 'M','i','c','r','o','s','o','f','t','\\',
140 'W','i','n','d','o','w','s','\\',
141 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
142 'I','n','t','e','r','n','e','t',' ','S','e','t','t','i','n','g','s','\\',
143 'Z','o','n','e','M','a','p','\\',
144 'P','r','o','t','o','c','o','l','D','e','f','a','u','l','t','s',0};
146 res
= RegOpenKeyW(HKEY_CURRENT_USER
, wszZoneMapProtocolKey
, &hkey
);
147 if(res
!= ERROR_SUCCESS
) {
148 ERR("Could not open key %s\n", debugstr_w(wszZoneMapProtocolKey
));
152 size
= sizeof(DWORD
);
153 res
= RegQueryValueExW(hkey
, schema
, NULL
, NULL
, (PBYTE
)zone
, &size
);
155 if(res
== ERROR_SUCCESS
)
158 res
= RegOpenKeyW(HKEY_LOCAL_MACHINE
, wszZoneMapProtocolKey
, &hkey
);
159 if(res
!= ERROR_SUCCESS
) {
160 ERR("Could not open key %s\n", debugstr_w(wszZoneMapProtocolKey
));
164 size
= sizeof(DWORD
);
165 res
= RegQueryValueExW(hkey
, schema
, NULL
, NULL
, (PBYTE
)zone
, &size
);
167 if(res
== ERROR_SUCCESS
)
174 /********************************************************************
175 * matches_domain_pattern [internal]
177 * Checks if the given string matches the specified domain pattern.
179 * This function looks for explicit wildcard domain components iff
180 * they appear at the very beginning of the 'pattern' string
182 * pattern = "*.google.com"
184 static BOOL
matches_domain_pattern(LPCWSTR pattern
, LPCWSTR str
, BOOL implicit_wildcard
, LPCWSTR
*matched
)
186 BOOL matches
= FALSE
;
187 DWORD pattern_len
= strlenW(pattern
);
188 DWORD str_len
= strlenW(str
);
190 TRACE("(%d) Checking if %s matches %s\n", implicit_wildcard
, debugstr_w(str
), debugstr_w(pattern
));
193 if(str_len
>= pattern_len
) {
194 /* Check if there's an explicit wildcard in the pattern. */
195 if(pattern
[0] == '*' && pattern
[1] == '.') {
196 /* Make sure that 'str' matches the wildcard pattern.
199 * pattern = "*.google.com"
201 * So in this case 'str' would have to end with ".google.com" in order
202 * to map to this pattern.
204 if(str_len
>= pattern_len
+1 && !strcmpiW(str
+(str_len
-pattern_len
+1), pattern
+1)) {
205 /* Check if there's another '.' inside of the "unmatched" portion
209 * pattern = "*.google.com"
210 * str = "test.testing.google.com"
212 * The currently matched portion is ".google.com" in 'str', we need
213 * see if there's a '.' inside of the unmatched portion ("test.testing"), because
214 * if there is and 'implicit_wildcard' isn't set, then this isn't
218 if(str_len
> pattern_len
+1 && (ptr
= memrchrW(str
, '.', str_len
-pattern_len
-2))) {
219 if(implicit_wildcard
) {
228 } else if(implicit_wildcard
&& str_len
> pattern_len
) {
229 /* When the pattern has an implicit wildcard component, it means
230 * that anything goes in 'str' as long as it ends with the pattern
231 * and that the beginning of the match has a '.' before it.
234 * pattern = "google.com"
235 * str = "www.google.com"
237 * Implicitly matches the pattern, where as:
239 * pattern = "google.com"
240 * str = "wwwgoogle.com"
242 * Doesn't match the pattern.
244 if(str_len
> pattern_len
) {
245 if(str
[str_len
-pattern_len
-1] == '.' && !strcmpiW(str
+(str_len
-pattern_len
), pattern
)) {
247 *matched
= str
+(str_len
-pattern_len
);
251 /* The pattern doesn't have an implicit wildcard, or an explicit wildcard,
252 * so 'str' has to be an exact match to the 'pattern'.
254 if(!strcmpiW(str
, pattern
)) {
262 TRACE("Found a match: matched=%s\n", debugstr_w(*matched
));
264 TRACE("No match found\n");
269 static BOOL
get_zone_for_scheme(HKEY key
, LPCWSTR schema
, DWORD
*zone
)
271 static const WCHAR wildcardW
[] = {'*',0};
274 DWORD size
= sizeof(DWORD
);
277 /* See if the key contains a value for the scheme first. */
278 res
= RegQueryValueExW(key
, schema
, NULL
, &type
, (BYTE
*)zone
, &size
);
279 if(res
== ERROR_SUCCESS
) {
280 if(type
== REG_DWORD
)
282 WARN("Unexpected value type %d for value %s, expected REG_DWORD\n", type
, debugstr_w(schema
));
285 /* Try to get the zone for the wildcard scheme. */
286 size
= sizeof(DWORD
);
287 res
= RegQueryValueExW(key
, wildcardW
, NULL
, &type
, (BYTE
*)zone
, &size
);
288 if(res
!= ERROR_SUCCESS
)
291 if(type
!= REG_DWORD
) {
292 WARN("Unexpected value type %d for value %s, expected REG_DWORD\n", type
, debugstr_w(wildcardW
));
299 /********************************************************************
300 * search_domain_for_zone [internal]
302 * Searches the specified 'domain' registry key to see if 'host' maps into it, or any
303 * of its subdomain registry keys.
305 * Returns S_OK if a match is found, S_FALSE if no matches were found, or an error code.
307 static HRESULT
search_domain_for_zone(HKEY domains
, LPCWSTR domain
, DWORD domain_len
, LPCWSTR schema
,
308 LPCWSTR host
, DWORD host_len
, DWORD
*zone
)
315 if(host_len
>= domain_len
&& matches_domain_pattern(domain
, host
, TRUE
, &matched
)) {
316 res
= RegOpenKeyW(domains
, domain
, &domain_key
);
317 if(res
!= ERROR_SUCCESS
) {
318 ERR("Failed to open domain key %s: %d\n", debugstr_w(domain
), res
);
323 found
= get_zone_for_scheme(domain_key
, schema
, zone
);
326 DWORD subdomain_count
, subdomain_len
;
327 BOOL check_domain
= TRUE
;
329 find_domain_name(domain
, domain_len
, &domain_offset
);
331 res
= RegQueryInfoKeyW(domain_key
, NULL
, NULL
, NULL
, &subdomain_count
, &subdomain_len
,
332 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
);
333 if(res
!= ERROR_SUCCESS
) {
334 ERR("Unable to query info for key %s: %d\n", debugstr_w(domain
), res
);
335 RegCloseKey(domain_key
);
339 if(subdomain_count
) {
344 subdomain
= heap_alloc((subdomain_len
+1)*sizeof(WCHAR
));
346 RegCloseKey(domain_key
);
347 return E_OUTOFMEMORY
;
350 component
= heap_strndupW(host
, matched
-host
-1);
352 heap_free(subdomain
);
353 RegCloseKey(domain_key
);
354 return E_OUTOFMEMORY
;
357 for(i
= 0; i
< subdomain_count
; ++i
) {
358 DWORD len
= subdomain_len
+1;
359 const WCHAR
*sub_matched
;
361 res
= RegEnumKeyExW(domain_key
, i
, subdomain
, &len
, NULL
, NULL
, NULL
, NULL
);
362 if(res
!= ERROR_SUCCESS
) {
363 heap_free(component
);
364 heap_free(subdomain
);
365 RegCloseKey(domain_key
);
369 if(matches_domain_pattern(subdomain
, component
, FALSE
, &sub_matched
)) {
372 res
= RegOpenKeyW(domain_key
, subdomain
, &subdomain_key
);
373 if(res
!= ERROR_SUCCESS
) {
374 ERR("Unable to open subdomain key %s of %s: %d\n", debugstr_w(subdomain
),
375 debugstr_w(domain
), res
);
376 heap_free(component
);
377 heap_free(subdomain
);
378 RegCloseKey(domain_key
);
382 found
= get_zone_for_scheme(subdomain_key
, schema
, zone
);
383 check_domain
= FALSE
;
384 RegCloseKey(subdomain_key
);
388 heap_free(subdomain
);
389 heap_free(component
);
392 /* There's a chance that 'host' implicitly mapped into 'domain', in
393 * which case we check to see if 'domain' contains zone information.
395 * This can only happen if 'domain' is its own domain name.
397 * "google.com" (domain name = "google.com")
400 * host = "www.google.com"
402 * Then host would map directly into the "google.com" domain key.
404 * If 'domain' has more than just its domain name, or it does not
405 * have a domain name, then we don't perform the check. The reason
406 * for this is that these domains don't allow implicit mappings.
408 * domain = "org" (has no domain name)
411 * The mapping would only happen if the "org" key had an explicit subkey
414 if(check_domain
&& !domain_offset
&& !strchrW(host
, matched
-host
-1))
415 found
= get_zone_for_scheme(domain_key
, schema
, zone
);
417 RegCloseKey(domain_key
);
420 return found
? S_OK
: S_FALSE
;
423 static HRESULT
search_for_domain_mapping(HKEY domains
, LPCWSTR schema
, LPCWSTR host
, DWORD host_len
, DWORD
*zone
)
426 DWORD domain_count
, domain_len
, i
;
428 HRESULT hres
= S_FALSE
;
430 res
= RegQueryInfoKeyW(domains
, NULL
, NULL
, NULL
, &domain_count
, &domain_len
,
431 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
);
432 if(res
!= ERROR_SUCCESS
) {
433 WARN("Failed to retrieve information about key\n");
440 domain
= heap_alloc((domain_len
+1)*sizeof(WCHAR
));
442 return E_OUTOFMEMORY
;
444 for(i
= 0; i
< domain_count
; ++i
) {
445 DWORD len
= domain_len
+1;
447 res
= RegEnumKeyExW(domains
, i
, domain
, &len
, NULL
, NULL
, NULL
, NULL
);
448 if(res
!= ERROR_SUCCESS
) {
453 hres
= search_domain_for_zone(domains
, domain
, len
, schema
, host
, host_len
, zone
);
454 if(FAILED(hres
) || hres
== S_OK
)
462 static HRESULT
get_zone_from_domains(IUri
*uri
, DWORD
*zone
)
470 hres
= IUri_GetScheme(uri
, &scheme_type
);
474 /* Windows doesn't play nice with unknown scheme types when it tries
475 * to check if a host name maps into any domains.
477 if(scheme_type
== URL_SCHEME_UNKNOWN
)
480 hres
= IUri_GetHost(uri
, &host
);
484 /* Known hierarchical scheme types must have a host. If they don't Windows
485 * assigns URLZONE_INVALID to the zone.
487 if((scheme_type
!= URL_SCHEME_UNKNOWN
&& scheme_type
!= URL_SCHEME_FILE
)
488 && is_hierarchical_scheme(scheme_type
) && !*host
) {
489 *zone
= URLZONE_INVALID
;
493 /* The MapUrlToZone functions return S_OK when this condition occurs. */
497 hres
= IUri_GetSchemeName(uri
, &scheme
);
503 /* First try CURRENT_USER. */
504 res
= RegOpenKeyW(HKEY_CURRENT_USER
, wszZoneMapDomainsKey
, &domains
);
505 if(res
== ERROR_SUCCESS
) {
506 hres
= search_for_domain_mapping(domains
, scheme
, host
, SysStringLen(host
), zone
);
507 RegCloseKey(domains
);
509 WARN("Failed to open HKCU's %s key\n", debugstr_w(wszZoneMapDomainsKey
));
511 /* If that doesn't work try LOCAL_MACHINE. */
512 if(hres
== S_FALSE
) {
513 res
= RegOpenKeyW(HKEY_LOCAL_MACHINE
, wszZoneMapDomainsKey
, &domains
);
514 if(res
== ERROR_SUCCESS
) {
515 hres
= search_for_domain_mapping(domains
, scheme
, host
, SysStringLen(host
), zone
);
516 RegCloseKey(domains
);
518 WARN("Failed to open HKLM's %s key\n", debugstr_w(wszZoneMapDomainsKey
));
522 SysFreeString(scheme
);
526 static HRESULT
map_security_uri_to_zone(IUri
*uri
, DWORD
*zone
)
531 *zone
= URLZONE_INVALID
;
533 hres
= IUri_GetSchemeName(uri
, &scheme
);
537 if(!strcmpiW(scheme
, fileW
)) {
539 WCHAR
*ptr
, *path_start
, root
[20];
541 hres
= IUri_GetPath(uri
, &path
);
543 SysFreeString(scheme
);
547 if(*path
== '/' && is_drive_path(path
+1))
552 if((ptr
= strchrW(path_start
, ':')) && ptr
-path_start
+1 < sizeof(root
)/sizeof(WCHAR
)) {
555 memcpy(root
, path_start
, (ptr
-path_start
+1)*sizeof(WCHAR
));
556 root
[ptr
-path_start
+1] = 0;
558 type
= GetDriveTypeW(root
);
562 case DRIVE_NO_ROOT_DIR
:
564 case DRIVE_REMOVABLE
:
568 *zone
= URLZONE_LOCAL_MACHINE
;
572 *zone
= URLZONE_INTERNET
;
576 FIXME("unsupported drive type %d\n", type
);
582 if(*zone
== URLZONE_INVALID
) {
583 hres
= get_zone_from_domains(uri
, zone
);
585 hres
= get_zone_from_reg(scheme
, zone
);
588 SysFreeString(scheme
);
592 static HRESULT
map_url_to_zone(LPCWSTR url
, DWORD
*zone
, LPWSTR
*ret_url
)
598 *zone
= URLZONE_INVALID
;
600 hres
= CoInternetGetSecurityUrl(url
, &secur_url
, PSU_SECURITY_URL_ONLY
, 0);
602 DWORD size
= strlenW(url
)*sizeof(WCHAR
);
604 secur_url
= CoTaskMemAlloc(size
);
606 return E_OUTOFMEMORY
;
608 memcpy(secur_url
, url
, size
);
611 hres
= CreateUri(secur_url
, Uri_CREATE_ALLOW_IMPLICIT_FILE_SCHEME
, 0, &secur_uri
);
613 CoTaskMemFree(secur_url
);
617 hres
= map_security_uri_to_zone(secur_uri
, zone
);
618 IUri_Release(secur_uri
);
620 if(FAILED(hres
) || !ret_url
)
621 CoTaskMemFree(secur_url
);
623 *ret_url
= secur_url
;
628 static HRESULT
map_uri_to_zone(IUri
*uri
, DWORD
*zone
, IUri
**ret_uri
)
633 hres
= CoInternetGetSecurityUrlEx(uri
, &secur_uri
, PSU_SECURITY_URL_ONLY
, 0);
637 hres
= map_security_uri_to_zone(secur_uri
, zone
);
638 if(FAILED(hres
) || !ret_uri
)
639 IUri_Release(secur_uri
);
641 *ret_uri
= secur_uri
;
646 static HRESULT
open_zone_key(HKEY parent_key
, DWORD zone
, HKEY
*hkey
)
648 static const WCHAR wszFormat
[] = {'%','s','%','u',0};
650 WCHAR key_name
[sizeof(wszZonesKey
)/sizeof(WCHAR
)+12];
653 wsprintfW(key_name
, wszFormat
, wszZonesKey
, zone
);
655 res
= RegOpenKeyW(parent_key
, key_name
, hkey
);
657 if(res
!= ERROR_SUCCESS
) {
658 WARN("RegOpenKey failed\n");
665 static HRESULT
get_action_policy(DWORD zone
, DWORD action
, BYTE
*policy
, DWORD size
, URLZONEREG zone_reg
)
673 case URLACTION_SCRIPT_OVERRIDE_SAFETY
:
674 case URLACTION_ACTIVEX_OVERRIDE_SCRIPT_SAFETY
:
675 *(DWORD
*)policy
= URLPOLICY_DISALLOW
;
680 case URLZONEREG_DEFAULT
:
681 case URLZONEREG_HKCU
:
682 parent_key
= HKEY_CURRENT_USER
;
684 case URLZONEREG_HKLM
:
685 parent_key
= HKEY_LOCAL_MACHINE
;
688 WARN("Unknown URLZONEREG: %d\n", zone_reg
);
692 hres
= open_zone_key(parent_key
, zone
, &hkey
);
693 if(SUCCEEDED(hres
)) {
694 WCHAR action_str
[16];
697 static const WCHAR formatW
[] = {'%','X',0};
699 wsprintfW(action_str
, formatW
, action
);
701 res
= RegQueryValueExW(hkey
, action_str
, NULL
, NULL
, policy
, &len
);
702 if(res
== ERROR_MORE_DATA
) {
704 }else if(res
== ERROR_FILE_NOT_FOUND
) {
706 }else if(res
!= ERROR_SUCCESS
) {
707 ERR("RegQueryValue failed: %d\n", res
);
714 if(FAILED(hres
) && zone_reg
== URLZONEREG_DEFAULT
)
715 return get_action_policy(zone
, action
, policy
, size
, URLZONEREG_HKLM
);
720 static HRESULT
generate_security_id(IUri
*uri
, BYTE
*secid
, DWORD
*secid_len
, DWORD zone
)
726 if(zone
== URLZONE_INVALID
)
729 hres
= IUri_GetScheme(uri
, &scheme_type
);
733 /* Windows handles opaque URLs differently then hierarchical ones. */
734 if(!is_hierarchical_scheme(scheme_type
) && scheme_type
!= URL_SCHEME_WILDCARD
) {
737 hres
= IUri_GetDisplayUri(uri
, &display_uri
);
741 len
= WideCharToMultiByte(CP_ACP
, 0, display_uri
, -1, NULL
, 0, NULL
, NULL
)-1;
743 if(len
+sizeof(DWORD
) > *secid_len
) {
744 SysFreeString(display_uri
);
745 return HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER
);
748 WideCharToMultiByte(CP_ACP
, 0, display_uri
, -1, (LPSTR
)secid
, len
, NULL
, NULL
);
749 SysFreeString(display_uri
);
751 *(DWORD
*)(secid
+len
) = zone
;
754 DWORD host_len
, scheme_len
;
757 hres
= IUri_GetHost(uri
, &host
);
761 /* The host can't be empty for Wildcard URIs. */
762 if(scheme_type
== URL_SCHEME_WILDCARD
&& !*host
) {
767 hres
= IUri_GetSchemeName(uri
, &scheme
);
773 host_len
= WideCharToMultiByte(CP_ACP
, 0, host
, -1, NULL
, 0, NULL
, NULL
)-1;
774 scheme_len
= WideCharToMultiByte(CP_ACP
, 0, scheme
, -1, NULL
, 0, NULL
, NULL
)-1;
776 len
= host_len
+scheme_len
+sizeof(BYTE
);
778 if(len
+sizeof(DWORD
) > *secid_len
) {
780 SysFreeString(scheme
);
781 return HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER
);
784 WideCharToMultiByte(CP_ACP
, 0, scheme
, -1, (LPSTR
)secid
, len
, NULL
, NULL
);
785 SysFreeString(scheme
);
787 ptr
= secid
+scheme_len
;
790 WideCharToMultiByte(CP_ACP
, 0, host
, -1, (LPSTR
)ptr
, host_len
, NULL
, NULL
);
798 *secid_len
= len
+sizeof(DWORD
);
803 static HRESULT
get_security_id_for_url(LPCWSTR url
, BYTE
*secid
, DWORD
*secid_len
)
806 DWORD zone
= URLZONE_INVALID
;
807 LPWSTR secur_url
= NULL
;
810 hres
= map_url_to_zone(url
, &zone
, &secur_url
);
812 return hres
== 0x80041001 ? E_INVALIDARG
: hres
;
814 hres
= CreateUri(secur_url
, Uri_CREATE_ALLOW_IMPLICIT_FILE_SCHEME
, 0, &uri
);
815 CoTaskMemFree(secur_url
);
819 hres
= generate_security_id(uri
, secid
, secid_len
, zone
);
825 static HRESULT
get_security_id_for_uri(IUri
*uri
, BYTE
*secid
, DWORD
*secid_len
)
829 DWORD zone
= URLZONE_INVALID
;
831 hres
= map_uri_to_zone(uri
, &zone
, &secur_uri
);
835 hres
= generate_security_id(secur_uri
, secid
, secid_len
, zone
);
836 IUri_Release(secur_uri
);
841 /***********************************************************************
842 * InternetSecurityManager implementation
846 IInternetSecurityManagerEx2 IInternetSecurityManagerEx2_iface
;
850 IInternetSecurityMgrSite
*mgrsite
;
851 IInternetSecurityManager
*custom_manager
;
854 static inline SecManagerImpl
*impl_from_IInternetSecurityManagerEx2(IInternetSecurityManagerEx2
*iface
)
856 return CONTAINING_RECORD(iface
, SecManagerImpl
, IInternetSecurityManagerEx2_iface
);
859 static HRESULT WINAPI
SecManagerImpl_QueryInterface(IInternetSecurityManagerEx2
* iface
,REFIID riid
,void** ppvObject
)
861 SecManagerImpl
*This
= impl_from_IInternetSecurityManagerEx2(iface
);
863 TRACE("(%p)->(%s %p)\n",This
,debugstr_guid(riid
),ppvObject
);
868 if(IsEqualIID(&IID_IUnknown
, riid
) ||
869 IsEqualIID(&IID_IInternetSecurityManager
, riid
) ||
870 IsEqualIID(&IID_IInternetSecurityManagerEx
, riid
) ||
871 IsEqualIID(&IID_IInternetSecurityManagerEx2
, riid
)) {
874 WARN("not supported interface %s\n", debugstr_guid(riid
));
876 return E_NOINTERFACE
;
879 IInternetSecurityManagerEx2_AddRef(iface
);
883 static ULONG WINAPI
SecManagerImpl_AddRef(IInternetSecurityManagerEx2
* iface
)
885 SecManagerImpl
*This
= impl_from_IInternetSecurityManagerEx2(iface
);
886 ULONG refCount
= InterlockedIncrement(&This
->ref
);
888 TRACE("(%p) ref=%u\n", This
, refCount
);
893 static ULONG WINAPI
SecManagerImpl_Release(IInternetSecurityManagerEx2
* iface
)
895 SecManagerImpl
*This
= impl_from_IInternetSecurityManagerEx2(iface
);
896 ULONG refCount
= InterlockedDecrement(&This
->ref
);
898 TRACE("(%p) ref=%u\n", This
, refCount
);
900 /* destroy the object if there's no more reference on it */
903 IInternetSecurityMgrSite_Release(This
->mgrsite
);
904 if(This
->custom_manager
)
905 IInternetSecurityManager_Release(This
->custom_manager
);
909 URLMON_UnlockModule();
915 static HRESULT WINAPI
SecManagerImpl_SetSecuritySite(IInternetSecurityManagerEx2
*iface
,
916 IInternetSecurityMgrSite
*pSite
)
918 SecManagerImpl
*This
= impl_from_IInternetSecurityManagerEx2(iface
);
920 TRACE("(%p)->(%p)\n", This
, pSite
);
923 IInternetSecurityMgrSite_Release(This
->mgrsite
);
925 if(This
->custom_manager
) {
926 IInternetSecurityManager_Release(This
->custom_manager
);
927 This
->custom_manager
= NULL
;
930 This
->mgrsite
= pSite
;
933 IServiceProvider
*servprov
;
936 IInternetSecurityMgrSite_AddRef(pSite
);
938 hres
= IInternetSecurityMgrSite_QueryInterface(pSite
, &IID_IServiceProvider
,
940 if(SUCCEEDED(hres
)) {
941 IServiceProvider_QueryService(servprov
, &SID_SInternetSecurityManager
,
942 &IID_IInternetSecurityManager
, (void**)&This
->custom_manager
);
943 IServiceProvider_Release(servprov
);
950 static HRESULT WINAPI
SecManagerImpl_GetSecuritySite(IInternetSecurityManagerEx2
*iface
,
951 IInternetSecurityMgrSite
**ppSite
)
953 SecManagerImpl
*This
= impl_from_IInternetSecurityManagerEx2(iface
);
955 TRACE("(%p)->(%p)\n", This
, ppSite
);
961 IInternetSecurityMgrSite_AddRef(This
->mgrsite
);
963 *ppSite
= This
->mgrsite
;
967 static HRESULT WINAPI
SecManagerImpl_MapUrlToZone(IInternetSecurityManagerEx2
*iface
,
968 LPCWSTR pwszUrl
, DWORD
*pdwZone
,
971 SecManagerImpl
*This
= impl_from_IInternetSecurityManagerEx2(iface
);
974 TRACE("(%p)->(%s %p %08x)\n", iface
, debugstr_w(pwszUrl
), pdwZone
, dwFlags
);
976 if(This
->custom_manager
) {
977 hres
= IInternetSecurityManager_MapUrlToZone(This
->custom_manager
,
978 pwszUrl
, pdwZone
, dwFlags
);
979 if(hres
!= INET_E_DEFAULT_ACTION
)
984 *pdwZone
= URLZONE_INVALID
;
989 FIXME("not supported flags: %08x\n", dwFlags
);
991 return map_url_to_zone(pwszUrl
, pdwZone
, NULL
);
994 static HRESULT WINAPI
SecManagerImpl_GetSecurityId(IInternetSecurityManagerEx2
*iface
,
995 LPCWSTR pwszUrl
, BYTE
*pbSecurityId
, DWORD
*pcbSecurityId
, DWORD_PTR dwReserved
)
997 SecManagerImpl
*This
= impl_from_IInternetSecurityManagerEx2(iface
);
999 TRACE("(%p)->(%s %p %p %08lx)\n", iface
, debugstr_w(pwszUrl
), pbSecurityId
,
1000 pcbSecurityId
, dwReserved
);
1002 if(This
->custom_manager
) {
1005 hres
= IInternetSecurityManager_GetSecurityId(This
->custom_manager
,
1006 pwszUrl
, pbSecurityId
, pcbSecurityId
, dwReserved
);
1007 if(hres
!= INET_E_DEFAULT_ACTION
)
1011 if(!pwszUrl
|| !pbSecurityId
|| !pcbSecurityId
)
1012 return E_INVALIDARG
;
1015 FIXME("dwReserved is not supported\n");
1017 return get_security_id_for_url(pwszUrl
, pbSecurityId
, pcbSecurityId
);
1021 static HRESULT WINAPI
SecManagerImpl_ProcessUrlAction(IInternetSecurityManagerEx2
*iface
,
1022 LPCWSTR pwszUrl
, DWORD dwAction
,
1023 BYTE
*pPolicy
, DWORD cbPolicy
,
1024 BYTE
*pContext
, DWORD cbContext
,
1025 DWORD dwFlags
, DWORD dwReserved
)
1027 SecManagerImpl
*This
= impl_from_IInternetSecurityManagerEx2(iface
);
1031 TRACE("(%p)->(%s %08x %p %08x %p %08x %08x %08x)\n", iface
, debugstr_w(pwszUrl
), dwAction
,
1032 pPolicy
, cbPolicy
, pContext
, cbContext
, dwFlags
, dwReserved
);
1034 if(This
->custom_manager
) {
1035 hres
= IInternetSecurityManager_ProcessUrlAction(This
->custom_manager
, pwszUrl
, dwAction
,
1036 pPolicy
, cbPolicy
, pContext
, cbContext
, dwFlags
, dwReserved
);
1037 if(hres
!= INET_E_DEFAULT_ACTION
)
1041 if(dwFlags
|| dwReserved
)
1042 FIXME("Unsupported arguments\n");
1045 return E_INVALIDARG
;
1047 hres
= map_url_to_zone(pwszUrl
, &zone
, NULL
);
1051 hres
= get_action_policy(zone
, dwAction
, (BYTE
*)&policy
, sizeof(policy
), URLZONEREG_DEFAULT
);
1055 TRACE("policy %x\n", policy
);
1056 if(cbPolicy
>= sizeof(DWORD
))
1057 *(DWORD
*)pPolicy
= policy
;
1059 switch(GetUrlPolicyPermissions(policy
)) {
1060 case URLPOLICY_ALLOW
:
1061 case URLPOLICY_CHANNEL_SOFTDIST_PRECACHE
:
1063 case URLPOLICY_DISALLOW
:
1065 case URLPOLICY_QUERY
:
1066 FIXME("URLPOLICY_QUERY not implemented\n");
1069 FIXME("Not implemented policy %x\n", policy
);
1076 static HRESULT WINAPI
SecManagerImpl_QueryCustomPolicy(IInternetSecurityManagerEx2
*iface
,
1077 LPCWSTR pwszUrl
, REFGUID guidKey
,
1078 BYTE
**ppPolicy
, DWORD
*pcbPolicy
,
1079 BYTE
*pContext
, DWORD cbContext
,
1082 SecManagerImpl
*This
= impl_from_IInternetSecurityManagerEx2(iface
);
1085 TRACE("(%p)->(%s %s %p %p %p %08x %08x )\n", iface
, debugstr_w(pwszUrl
), debugstr_guid(guidKey
),
1086 ppPolicy
, pcbPolicy
, pContext
, cbContext
, dwReserved
);
1088 if(This
->custom_manager
) {
1089 hres
= IInternetSecurityManager_QueryCustomPolicy(This
->custom_manager
, pwszUrl
, guidKey
,
1090 ppPolicy
, pcbPolicy
, pContext
, cbContext
, dwReserved
);
1091 if(hres
!= INET_E_DEFAULT_ACTION
)
1095 WARN("Unknown guidKey %s\n", debugstr_guid(guidKey
));
1096 return HRESULT_FROM_WIN32(ERROR_NOT_FOUND
);
1099 static HRESULT WINAPI
SecManagerImpl_SetZoneMapping(IInternetSecurityManagerEx2
*iface
,
1100 DWORD dwZone
, LPCWSTR pwszPattern
, DWORD dwFlags
)
1102 SecManagerImpl
*This
= impl_from_IInternetSecurityManagerEx2(iface
);
1105 TRACE("(%p)->(%08x %s %08x)\n", iface
, dwZone
, debugstr_w(pwszPattern
),dwFlags
);
1107 if(This
->custom_manager
) {
1108 hres
= IInternetSecurityManager_SetZoneMapping(This
->custom_manager
, dwZone
,
1109 pwszPattern
, dwFlags
);
1110 if(hres
!= INET_E_DEFAULT_ACTION
)
1114 FIXME("Default action is not implemented\n");
1118 static HRESULT WINAPI
SecManagerImpl_GetZoneMappings(IInternetSecurityManagerEx2
*iface
,
1119 DWORD dwZone
, IEnumString
**ppenumString
, DWORD dwFlags
)
1121 SecManagerImpl
*This
= impl_from_IInternetSecurityManagerEx2(iface
);
1124 TRACE("(%p)->(%08x %p %08x)\n", iface
, dwZone
, ppenumString
,dwFlags
);
1126 if(This
->custom_manager
) {
1127 hres
= IInternetSecurityManager_GetZoneMappings(This
->custom_manager
, dwZone
,
1128 ppenumString
, dwFlags
);
1129 if(hres
!= INET_E_DEFAULT_ACTION
)
1133 FIXME("Default action is not implemented\n");
1137 static HRESULT WINAPI
SecManagerImpl_ProcessUrlActionEx(IInternetSecurityManagerEx2
*iface
,
1138 LPCWSTR pwszUrl
, DWORD dwAction
, BYTE
*pPolicy
, DWORD cbPolicy
, BYTE
*pContext
, DWORD cbContext
,
1139 DWORD dwFlags
, DWORD dwReserved
, DWORD
*pdwOutFlags
)
1141 SecManagerImpl
*This
= impl_from_IInternetSecurityManagerEx2(iface
);
1142 FIXME("(%p)->(%s %08x %p %d %p %d %08x %08x %p) stub\n", This
, debugstr_w(pwszUrl
), dwAction
, pPolicy
, cbPolicy
,
1143 pContext
, cbContext
, dwFlags
, dwReserved
, pdwOutFlags
);
1147 static HRESULT WINAPI
SecManagerImpl_MapUrlToZoneEx2(IInternetSecurityManagerEx2
*iface
,
1148 IUri
*pUri
, DWORD
*pdwZone
, DWORD dwFlags
, LPWSTR
*ppwszMappedUrl
, DWORD
*pdwOutFlags
)
1150 SecManagerImpl
*This
= impl_from_IInternetSecurityManagerEx2(iface
);
1152 TRACE("(%p)->(%p %p %08x %p %p)\n", This
, pUri
, pdwZone
, dwFlags
, ppwszMappedUrl
, pdwOutFlags
);
1154 if(This
->custom_manager
) {
1156 IInternetSecurityManagerEx2
*sec_mgr2
;
1158 hres
= IInternetSecurityManager_QueryInterface(This
->custom_manager
, &IID_IInternetSecurityManagerEx2
,
1160 if(SUCCEEDED(hres
)) {
1161 hres
= IInternetSecurityManagerEx2_MapUrlToZoneEx2(sec_mgr2
, pUri
, pdwZone
, dwFlags
, ppwszMappedUrl
, pdwOutFlags
);
1162 IInternetSecurityManagerEx2_Release(sec_mgr2
);
1166 hres
= IUri_GetDisplayUri(pUri
, &url
);
1170 hres
= IInternetSecurityManager_MapUrlToZone(This
->custom_manager
, url
, pdwZone
, dwFlags
);
1174 if(hres
!= INET_E_DEFAULT_ACTION
)
1179 return E_INVALIDARG
;
1182 *pdwZone
= URLZONE_INVALID
;
1183 return E_INVALIDARG
;
1187 FIXME("Unsupported flags: %08x\n", dwFlags
);
1189 return map_uri_to_zone(pUri
, pdwZone
, NULL
);
1192 static HRESULT WINAPI
SecManagerImpl_ProcessUrlActionEx2(IInternetSecurityManagerEx2
*iface
,
1193 IUri
*pUri
, DWORD dwAction
, BYTE
*pPolicy
, DWORD cbPolicy
, BYTE
*pContext
, DWORD cbContext
,
1194 DWORD dwFlags
, DWORD_PTR dwReserved
, DWORD
*pdwOutFlags
)
1196 SecManagerImpl
*This
= impl_from_IInternetSecurityManagerEx2(iface
);
1197 FIXME("(%p)->(%p %08x %p %d %p %d %08x %08x %p) stub\n", This
, pUri
, dwAction
, pPolicy
,
1198 cbPolicy
, pContext
, cbContext
, dwFlags
, (DWORD
)dwReserved
, pdwOutFlags
);
1202 static HRESULT WINAPI
SecManagerImpl_GetSecurityIdEx2(IInternetSecurityManagerEx2
*iface
,
1203 IUri
*pUri
, BYTE
*pbSecurityId
, DWORD
*pcbSecurityId
, DWORD_PTR dwReserved
)
1205 SecManagerImpl
*This
= impl_from_IInternetSecurityManagerEx2(iface
);
1206 TRACE("(%p)->(%p %p %p %08x) stub\n", This
, pUri
, pbSecurityId
, pcbSecurityId
, (DWORD
)dwReserved
);
1209 FIXME("dwReserved is not supported yet\n");
1211 if(!pUri
|| !pcbSecurityId
|| !pbSecurityId
)
1212 return E_INVALIDARG
;
1214 return get_security_id_for_uri(pUri
, pbSecurityId
, pcbSecurityId
);
1217 static HRESULT WINAPI
SecManagerImpl_QueryCustomPolicyEx2(IInternetSecurityManagerEx2
*iface
,
1218 IUri
*pUri
, REFGUID guidKey
, BYTE
**ppPolicy
, DWORD
*pcbPolicy
, BYTE
*pContext
,
1219 DWORD cbContext
, DWORD_PTR dwReserved
)
1221 SecManagerImpl
*This
= impl_from_IInternetSecurityManagerEx2(iface
);
1222 FIXME("(%p)->(%p %s %p %p %p %d %08x) stub\n", This
, pUri
, debugstr_guid(guidKey
), ppPolicy
, pcbPolicy
,
1223 pContext
, cbContext
, (DWORD
)dwReserved
);
1227 static const IInternetSecurityManagerEx2Vtbl VT_SecManagerImpl
=
1229 SecManagerImpl_QueryInterface
,
1230 SecManagerImpl_AddRef
,
1231 SecManagerImpl_Release
,
1232 SecManagerImpl_SetSecuritySite
,
1233 SecManagerImpl_GetSecuritySite
,
1234 SecManagerImpl_MapUrlToZone
,
1235 SecManagerImpl_GetSecurityId
,
1236 SecManagerImpl_ProcessUrlAction
,
1237 SecManagerImpl_QueryCustomPolicy
,
1238 SecManagerImpl_SetZoneMapping
,
1239 SecManagerImpl_GetZoneMappings
,
1240 SecManagerImpl_ProcessUrlActionEx
,
1241 SecManagerImpl_MapUrlToZoneEx2
,
1242 SecManagerImpl_ProcessUrlActionEx2
,
1243 SecManagerImpl_GetSecurityIdEx2
,
1244 SecManagerImpl_QueryCustomPolicyEx2
1247 HRESULT
SecManagerImpl_Construct(IUnknown
*pUnkOuter
, LPVOID
*ppobj
)
1249 SecManagerImpl
*This
;
1251 TRACE("(%p,%p)\n",pUnkOuter
,ppobj
);
1252 This
= heap_alloc(sizeof(*This
));
1254 /* Initialize the virtual function table. */
1255 This
->IInternetSecurityManagerEx2_iface
.lpVtbl
= &VT_SecManagerImpl
;
1258 This
->mgrsite
= NULL
;
1259 This
->custom_manager
= NULL
;
1263 URLMON_LockModule();
1268 /***********************************************************************
1269 * InternetZoneManager implementation
1273 IInternetZoneManagerEx2 IInternetZoneManagerEx2_iface
;
1276 DWORD zonemap_count
;
1279 static inline ZoneMgrImpl
*impl_from_IInternetZoneManagerEx2(IInternetZoneManagerEx2
*iface
)
1281 return CONTAINING_RECORD(iface
, ZoneMgrImpl
, IInternetZoneManagerEx2_iface
);
1285 /***********************************************************************
1286 * build_zonemap_from_reg [internal]
1288 * Enumerate the Zones in the Registry and return the Zones in a DWORD-array
1289 * The number of the Zones is returned in data[0]
1291 static LPDWORD
build_zonemap_from_reg(void)
1295 LPDWORD data
= NULL
;
1296 DWORD allocated
= 6; /* space for the zonecount and Zone "0" up to Zone "4" */
1302 res
= RegOpenKeyW(HKEY_CURRENT_USER
, wszZonesKey
, &hkey
);
1306 data
= heap_alloc(allocated
* sizeof(DWORD
));
1312 len
= sizeof(name
) / sizeof(name
[0]);
1313 res
= RegEnumKeyExW(hkey
, used
, name
, &len
, NULL
, NULL
, NULL
, NULL
);
1317 if (used
== allocated
) {
1321 new_data
= heap_realloc_zero(data
, allocated
* sizeof(DWORD
));
1327 data
[used
] = atoiW(name
);
1337 /* something failed */
1343 /********************************************************************
1344 * IInternetZoneManager_QueryInterface
1346 static HRESULT WINAPI
ZoneMgrImpl_QueryInterface(IInternetZoneManagerEx2
* iface
, REFIID riid
, void** ppvObject
)
1348 ZoneMgrImpl
* This
= impl_from_IInternetZoneManagerEx2(iface
);
1350 TRACE("(%p)->(%s,%p)\n", This
, debugstr_guid(riid
), ppvObject
);
1352 if(!This
|| !ppvObject
)
1353 return E_INVALIDARG
;
1355 if(IsEqualIID(&IID_IUnknown
, riid
)) {
1356 TRACE("(%p)->(IID_IUnknown %p)\n", This
, ppvObject
);
1357 }else if(IsEqualIID(&IID_IInternetZoneManager
, riid
)) {
1358 TRACE("(%p)->(IID_InternetZoneManager %p)\n", This
, ppvObject
);
1359 }else if(IsEqualIID(&IID_IInternetZoneManagerEx
, riid
)) {
1360 TRACE("(%p)->(IID_InternetZoneManagerEx %p)\n", This
, ppvObject
);
1361 }else if(IsEqualIID(&IID_IInternetZoneManagerEx2
, riid
)) {
1362 TRACE("(%p)->(IID_InternetZoneManagerEx2 %p)\n", This
, ppvObject
);
1366 FIXME("Unknown interface: %s\n", debugstr_guid(riid
));
1368 return E_NOINTERFACE
;
1372 IInternetZoneManagerEx2_AddRef(iface
);
1376 /********************************************************************
1377 * IInternetZoneManager_AddRef
1379 static ULONG WINAPI
ZoneMgrImpl_AddRef(IInternetZoneManagerEx2
* iface
)
1381 ZoneMgrImpl
* This
= impl_from_IInternetZoneManagerEx2(iface
);
1382 ULONG refCount
= InterlockedIncrement(&This
->ref
);
1384 TRACE("(%p)->(ref before=%u)\n",This
, refCount
- 1);
1389 /********************************************************************
1390 * IInternetZoneManager_Release
1392 static ULONG WINAPI
ZoneMgrImpl_Release(IInternetZoneManagerEx2
* iface
)
1394 ZoneMgrImpl
* This
= impl_from_IInternetZoneManagerEx2(iface
);
1395 ULONG refCount
= InterlockedDecrement(&This
->ref
);
1397 TRACE("(%p)->(ref before=%u)\n",This
, refCount
+ 1);
1400 while (This
->zonemap_count
) heap_free(This
->zonemaps
[--This
->zonemap_count
]);
1401 heap_free(This
->zonemaps
);
1403 URLMON_UnlockModule();
1409 /********************************************************************
1410 * IInternetZoneManager_GetZoneAttributes
1412 static HRESULT WINAPI
ZoneMgrImpl_GetZoneAttributes(IInternetZoneManagerEx2
* iface
,
1414 ZONEATTRIBUTES
* pZoneAttributes
)
1416 ZoneMgrImpl
* This
= impl_from_IInternetZoneManagerEx2(iface
);
1421 TRACE("(%p)->(%d %p)\n", This
, dwZone
, pZoneAttributes
);
1423 if (!pZoneAttributes
)
1424 return E_INVALIDARG
;
1426 hr
= open_zone_key(HKEY_CURRENT_USER
, dwZone
, &hcu
);
1428 return S_OK
; /* IE6 and older returned E_FAIL here */
1430 hr
= open_zone_key(HKEY_LOCAL_MACHINE
, dwZone
, &hklm
);
1432 TRACE("Zone %d not in HKLM\n", dwZone
);
1434 get_string_from_reg(hcu
, hklm
, displaynameW
, pZoneAttributes
->szDisplayName
, MAX_ZONE_PATH
);
1435 get_string_from_reg(hcu
, hklm
, descriptionW
, pZoneAttributes
->szDescription
, MAX_ZONE_DESCRIPTION
);
1436 get_string_from_reg(hcu
, hklm
, iconW
, pZoneAttributes
->szIconPath
, MAX_ZONE_PATH
);
1437 get_dword_from_reg(hcu
, hklm
, minlevelW
, &pZoneAttributes
->dwTemplateMinLevel
);
1438 get_dword_from_reg(hcu
, hklm
, currentlevelW
, &pZoneAttributes
->dwTemplateCurrentLevel
);
1439 get_dword_from_reg(hcu
, hklm
, recommendedlevelW
, &pZoneAttributes
->dwTemplateRecommended
);
1440 get_dword_from_reg(hcu
, hklm
, flagsW
, &pZoneAttributes
->dwFlags
);
1447 /********************************************************************
1448 * IInternetZoneManager_SetZoneAttributes
1450 static HRESULT WINAPI
ZoneMgrImpl_SetZoneAttributes(IInternetZoneManagerEx2
* iface
,
1452 ZONEATTRIBUTES
* pZoneAttributes
)
1454 ZoneMgrImpl
* This
= impl_from_IInternetZoneManagerEx2(iface
);
1458 TRACE("(%p)->(%d %p)\n", This
, dwZone
, pZoneAttributes
);
1460 if (!pZoneAttributes
)
1461 return E_INVALIDARG
;
1463 hr
= open_zone_key(HKEY_CURRENT_USER
, dwZone
, &hcu
);
1465 return S_OK
; /* IE6 returned E_FAIL here */
1467 /* cbSize is ignored */
1468 RegSetValueExW(hcu
, displaynameW
, 0, REG_SZ
, (LPBYTE
) pZoneAttributes
->szDisplayName
,
1469 (lstrlenW(pZoneAttributes
->szDisplayName
)+1)* sizeof(WCHAR
));
1471 RegSetValueExW(hcu
, descriptionW
, 0, REG_SZ
, (LPBYTE
) pZoneAttributes
->szDescription
,
1472 (lstrlenW(pZoneAttributes
->szDescription
)+1)* sizeof(WCHAR
));
1474 RegSetValueExW(hcu
, iconW
, 0, REG_SZ
, (LPBYTE
) pZoneAttributes
->szIconPath
,
1475 (lstrlenW(pZoneAttributes
->szIconPath
)+1)* sizeof(WCHAR
));
1477 RegSetValueExW(hcu
, minlevelW
, 0, REG_DWORD
,
1478 (const BYTE
*) &pZoneAttributes
->dwTemplateMinLevel
, sizeof(DWORD
));
1480 RegSetValueExW(hcu
, currentlevelW
, 0, REG_DWORD
,
1481 (const BYTE
*) &pZoneAttributes
->dwTemplateCurrentLevel
, sizeof(DWORD
));
1483 RegSetValueExW(hcu
, recommendedlevelW
, 0, REG_DWORD
,
1484 (const BYTE
*) &pZoneAttributes
->dwTemplateRecommended
, sizeof(DWORD
));
1486 RegSetValueExW(hcu
, flagsW
, 0, REG_DWORD
, (const BYTE
*) &pZoneAttributes
->dwFlags
, sizeof(DWORD
));
1492 /********************************************************************
1493 * IInternetZoneManager_GetZoneCustomPolicy
1495 static HRESULT WINAPI
ZoneMgrImpl_GetZoneCustomPolicy(IInternetZoneManagerEx2
* iface
,
1500 URLZONEREG ulrZoneReg
)
1502 FIXME("(%p)->(%08x %s %p %p %08x) stub\n", iface
, dwZone
, debugstr_guid(guidKey
),
1503 ppPolicy
, pcbPolicy
, ulrZoneReg
);
1507 /********************************************************************
1508 * IInternetZoneManager_SetZoneCustomPolicy
1510 static HRESULT WINAPI
ZoneMgrImpl_SetZoneCustomPolicy(IInternetZoneManagerEx2
* iface
,
1515 URLZONEREG ulrZoneReg
)
1517 FIXME("(%p)->(%08x %s %p %08x %08x) stub\n", iface
, dwZone
, debugstr_guid(guidKey
),
1518 ppPolicy
, cbPolicy
, ulrZoneReg
);
1522 /********************************************************************
1523 * IInternetZoneManager_GetZoneActionPolicy
1525 static HRESULT WINAPI
ZoneMgrImpl_GetZoneActionPolicy(IInternetZoneManagerEx2
* iface
,
1526 DWORD dwZone
, DWORD dwAction
, BYTE
* pPolicy
, DWORD cbPolicy
, URLZONEREG urlZoneReg
)
1528 TRACE("(%p)->(%d %08x %p %d %d)\n", iface
, dwZone
, dwAction
, pPolicy
,
1529 cbPolicy
, urlZoneReg
);
1532 return E_INVALIDARG
;
1534 return get_action_policy(dwZone
, dwAction
, pPolicy
, cbPolicy
, urlZoneReg
);
1537 /********************************************************************
1538 * IInternetZoneManager_SetZoneActionPolicy
1540 static HRESULT WINAPI
ZoneMgrImpl_SetZoneActionPolicy(IInternetZoneManagerEx2
* iface
,
1545 URLZONEREG urlZoneReg
)
1547 FIXME("(%p)->(%08x %08x %p %08x %08x) stub\n", iface
, dwZone
, dwAction
, pPolicy
,
1548 cbPolicy
, urlZoneReg
);
1552 /********************************************************************
1553 * IInternetZoneManager_PromptAction
1555 static HRESULT WINAPI
ZoneMgrImpl_PromptAction(IInternetZoneManagerEx2
* iface
,
1560 DWORD dwPromptFlags
)
1562 FIXME("%p %08x %p %s %s %08x\n", iface
, dwAction
, hwndParent
,
1563 debugstr_w(pwszUrl
), debugstr_w(pwszText
), dwPromptFlags
);
1567 /********************************************************************
1568 * IInternetZoneManager_LogAction
1570 static HRESULT WINAPI
ZoneMgrImpl_LogAction(IInternetZoneManagerEx2
* iface
,
1576 FIXME("(%p)->(%08x %s %s %08x) stub\n", iface
, dwAction
, debugstr_w(pwszUrl
),
1577 debugstr_w(pwszText
), dwLogFlags
);
1581 /********************************************************************
1582 * IInternetZoneManager_CreateZoneEnumerator
1584 static HRESULT WINAPI
ZoneMgrImpl_CreateZoneEnumerator(IInternetZoneManagerEx2
* iface
,
1589 ZoneMgrImpl
* This
= impl_from_IInternetZoneManagerEx2(iface
);
1594 TRACE("(%p)->(%p, %p, 0x%08x)\n", This
, pdwEnum
, pdwCount
, dwFlags
);
1595 if (!pdwEnum
|| !pdwCount
|| (dwFlags
!= 0))
1596 return E_INVALIDARG
;
1598 data
= build_zonemap_from_reg();
1599 TRACE("found %d zones\n", data
? data
[0] : -1);
1604 for (i
= 0; i
< This
->zonemap_count
; i
++) {
1605 if (This
->zonemaps
&& !This
->zonemaps
[i
]) {
1606 This
->zonemaps
[i
] = data
;
1608 *pdwCount
= data
[0];
1613 if (This
->zonemaps
) {
1614 /* try to double the nr. of pointers in the array */
1615 new_maps
= heap_realloc_zero(This
->zonemaps
, This
->zonemap_count
* 2 * sizeof(LPDWORD
));
1617 This
->zonemap_count
*= 2;
1621 This
->zonemap_count
= 2;
1622 new_maps
= heap_alloc_zero(This
->zonemap_count
* sizeof(LPDWORD
));
1629 This
->zonemaps
= new_maps
;
1630 This
->zonemaps
[i
] = data
;
1632 *pdwCount
= data
[0];
1636 /********************************************************************
1637 * IInternetZoneManager_GetZoneAt
1639 static HRESULT WINAPI
ZoneMgrImpl_GetZoneAt(IInternetZoneManagerEx2
* iface
,
1644 ZoneMgrImpl
* This
= impl_from_IInternetZoneManagerEx2(iface
);
1647 TRACE("(%p)->(0x%08x, %d, %p)\n", This
, dwEnum
, dwIndex
, pdwZone
);
1649 /* make sure, that dwEnum and dwIndex are in the valid range */
1650 if (dwEnum
< This
->zonemap_count
) {
1651 if ((data
= This
->zonemaps
[dwEnum
])) {
1652 if (dwIndex
< data
[0]) {
1653 *pdwZone
= data
[dwIndex
+ 1];
1658 return E_INVALIDARG
;
1661 /********************************************************************
1662 * IInternetZoneManager_DestroyZoneEnumerator
1664 static HRESULT WINAPI
ZoneMgrImpl_DestroyZoneEnumerator(IInternetZoneManagerEx2
* iface
,
1667 ZoneMgrImpl
* This
= impl_from_IInternetZoneManagerEx2(iface
);
1670 TRACE("(%p)->(0x%08x)\n", This
, dwEnum
);
1671 /* make sure, that dwEnum is valid */
1672 if (dwEnum
< This
->zonemap_count
) {
1673 if ((data
= This
->zonemaps
[dwEnum
])) {
1674 This
->zonemaps
[dwEnum
] = NULL
;
1679 return E_INVALIDARG
;
1682 /********************************************************************
1683 * IInternetZoneManager_CopyTemplatePoliciesToZone
1685 static HRESULT WINAPI
ZoneMgrImpl_CopyTemplatePoliciesToZone(IInternetZoneManagerEx2
* iface
,
1690 FIXME("(%p)->(%08x %08x %08x) stub\n", iface
, dwTemplate
, dwZone
, dwReserved
);
1694 /********************************************************************
1695 * IInternetZoneManagerEx_GetZoneActionPolicyEx
1697 static HRESULT WINAPI
ZoneMgrImpl_GetZoneActionPolicyEx(IInternetZoneManagerEx2
* iface
,
1702 URLZONEREG urlZoneReg
,
1705 TRACE("(%p)->(%d, 0x%x, %p, %d, %d, 0x%x)\n", iface
, dwZone
,
1706 dwAction
, pPolicy
, cbPolicy
, urlZoneReg
, dwFlags
);
1709 return E_INVALIDARG
;
1712 FIXME("dwFlags 0x%x ignored\n", dwFlags
);
1714 return get_action_policy(dwZone
, dwAction
, pPolicy
, cbPolicy
, urlZoneReg
);
1717 /********************************************************************
1718 * IInternetZoneManagerEx_SetZoneActionPolicyEx
1720 static HRESULT WINAPI
ZoneMgrImpl_SetZoneActionPolicyEx(IInternetZoneManagerEx2
* iface
,
1725 URLZONEREG urlZoneReg
,
1728 FIXME("(%p)->(%d, 0x%x, %p, %d, %d, 0x%x) stub\n", iface
, dwZone
, dwAction
, pPolicy
,
1729 cbPolicy
, urlZoneReg
, dwFlags
);
1733 /********************************************************************
1734 * IInternetZoneManagerEx2_GetZoneAttributesEx
1736 static HRESULT WINAPI
ZoneMgrImpl_GetZoneAttributesEx(IInternetZoneManagerEx2
* iface
,
1738 ZONEATTRIBUTES
* pZoneAttributes
,
1741 TRACE("(%p)->(%d, %p, 0x%x)\n", iface
, dwZone
, pZoneAttributes
, dwFlags
);
1744 FIXME("dwFlags 0x%x ignored\n", dwFlags
);
1746 return IInternetZoneManagerEx2_GetZoneAttributes(iface
, dwZone
, pZoneAttributes
);
1750 /********************************************************************
1751 * IInternetZoneManagerEx2_GetZoneSecurityState
1753 static HRESULT WINAPI
ZoneMgrImpl_GetZoneSecurityState(IInternetZoneManagerEx2
* iface
,
1755 BOOL fRespectPolicy
,
1757 BOOL
*pfPolicyEncountered
)
1759 FIXME("(%p)->(%d, %d, %p, %p) stub\n", iface
, dwZoneIndex
, fRespectPolicy
,
1760 pdwState
, pfPolicyEncountered
);
1762 *pdwState
= SECURITY_IE_STATE_GREEN
;
1764 if (pfPolicyEncountered
)
1765 *pfPolicyEncountered
= FALSE
;
1770 /********************************************************************
1771 * IInternetZoneManagerEx2_GetIESecurityState
1773 static HRESULT WINAPI
ZoneMgrImpl_GetIESecurityState(IInternetZoneManagerEx2
* iface
,
1774 BOOL fRespectPolicy
,
1776 BOOL
*pfPolicyEncountered
,
1779 FIXME("(%p)->(%d, %p, %p, %d) stub\n", iface
, fRespectPolicy
, pdwState
,
1780 pfPolicyEncountered
, fNoCache
);
1782 *pdwState
= SECURITY_IE_STATE_GREEN
;
1784 if (pfPolicyEncountered
)
1785 *pfPolicyEncountered
= FALSE
;
1790 /********************************************************************
1791 * IInternetZoneManagerEx2_FixInsecureSettings
1793 static HRESULT WINAPI
ZoneMgrImpl_FixInsecureSettings(IInternetZoneManagerEx2
* iface
)
1795 FIXME("(%p) stub\n", iface
);
1799 /********************************************************************
1800 * IInternetZoneManager_Construct
1802 static const IInternetZoneManagerEx2Vtbl ZoneMgrImplVtbl
= {
1803 ZoneMgrImpl_QueryInterface
,
1805 ZoneMgrImpl_Release
,
1806 /* IInternetZoneManager */
1807 ZoneMgrImpl_GetZoneAttributes
,
1808 ZoneMgrImpl_SetZoneAttributes
,
1809 ZoneMgrImpl_GetZoneCustomPolicy
,
1810 ZoneMgrImpl_SetZoneCustomPolicy
,
1811 ZoneMgrImpl_GetZoneActionPolicy
,
1812 ZoneMgrImpl_SetZoneActionPolicy
,
1813 ZoneMgrImpl_PromptAction
,
1814 ZoneMgrImpl_LogAction
,
1815 ZoneMgrImpl_CreateZoneEnumerator
,
1816 ZoneMgrImpl_GetZoneAt
,
1817 ZoneMgrImpl_DestroyZoneEnumerator
,
1818 ZoneMgrImpl_CopyTemplatePoliciesToZone
,
1819 /* IInternetZoneManagerEx */
1820 ZoneMgrImpl_GetZoneActionPolicyEx
,
1821 ZoneMgrImpl_SetZoneActionPolicyEx
,
1822 /* IInternetZoneManagerEx2 */
1823 ZoneMgrImpl_GetZoneAttributesEx
,
1824 ZoneMgrImpl_GetZoneSecurityState
,
1825 ZoneMgrImpl_GetIESecurityState
,
1826 ZoneMgrImpl_FixInsecureSettings
,
1829 HRESULT
ZoneMgrImpl_Construct(IUnknown
*pUnkOuter
, LPVOID
*ppobj
)
1831 ZoneMgrImpl
* ret
= heap_alloc_zero(sizeof(ZoneMgrImpl
));
1833 TRACE("(%p %p)\n", pUnkOuter
, ppobj
);
1834 ret
->IInternetZoneManagerEx2_iface
.lpVtbl
= &ZoneMgrImplVtbl
;
1836 *ppobj
= (IInternetZoneManagerEx
*)ret
;
1838 URLMON_LockModule();
1843 /***********************************************************************
1844 * CoInternetCreateSecurityManager (URLMON.@)
1847 HRESULT WINAPI
CoInternetCreateSecurityManager( IServiceProvider
*pSP
,
1848 IInternetSecurityManager
**ppSM
, DWORD dwReserved
)
1850 TRACE("%p %p %d\n", pSP
, ppSM
, dwReserved
);
1853 FIXME("pSP not supported\n");
1855 return SecManagerImpl_Construct(NULL
, (void**) ppSM
);
1858 /********************************************************************
1859 * CoInternetCreateZoneManager (URLMON.@)
1861 HRESULT WINAPI
CoInternetCreateZoneManager(IServiceProvider
* pSP
, IInternetZoneManager
** ppZM
, DWORD dwReserved
)
1863 TRACE("(%p %p %x)\n", pSP
, ppZM
, dwReserved
);
1864 return ZoneMgrImpl_Construct(NULL
, (void**)ppZM
);
1867 static HRESULT
parse_security_url(const WCHAR
*url
, PSUACTION action
, WCHAR
**result
) {
1868 IInternetProtocolInfo
*protocol_info
;
1869 WCHAR
*tmp
, *new_url
= NULL
, *alloc_url
= NULL
;
1870 DWORD size
, new_size
;
1871 HRESULT hres
= S_OK
, parse_hres
;
1874 TRACE("parsing %s\n", debugstr_w(url
));
1876 protocol_info
= get_protocol_info(url
);
1880 size
= strlenW(url
)+1;
1881 new_url
= CoTaskMemAlloc(size
*sizeof(WCHAR
));
1883 hres
= E_OUTOFMEMORY
;
1888 parse_hres
= IInternetProtocolInfo_ParseUrl(protocol_info
, url
, PARSE_SECURITY_URL
, 0, new_url
, size
, &new_size
, 0);
1889 if(parse_hres
== S_FALSE
) {
1891 hres
= E_UNEXPECTED
;
1895 tmp
= CoTaskMemRealloc(new_url
, new_size
*sizeof(WCHAR
));
1897 hres
= E_OUTOFMEMORY
;
1901 parse_hres
= IInternetProtocolInfo_ParseUrl(protocol_info
, url
, PARSE_SECURITY_URL
, 0, new_url
,
1902 new_size
, &new_size
, 0);
1903 if(parse_hres
== S_FALSE
) {
1909 if(parse_hres
!= S_OK
|| !strcmpW(url
, new_url
))
1912 CoTaskMemFree(alloc_url
);
1913 url
= alloc_url
= new_url
;
1917 CoTaskMemFree(new_url
);
1920 WARN("failed: %08x\n", hres
);
1921 CoTaskMemFree(alloc_url
);
1925 if(action
== PSU_DEFAULT
&& (protocol_info
= get_protocol_info(url
))) {
1926 size
= strlenW(url
)+1;
1927 new_url
= CoTaskMemAlloc(size
* sizeof(WCHAR
));
1930 parse_hres
= IInternetProtocolInfo_ParseUrl(protocol_info
, url
, PARSE_SECURITY_DOMAIN
, 0,
1931 new_url
, size
, &new_size
, 0);
1932 if(parse_hres
== S_FALSE
) {
1934 tmp
= CoTaskMemRealloc(new_url
, new_size
*sizeof(WCHAR
));
1937 parse_hres
= IInternetProtocolInfo_ParseUrl(protocol_info
, url
, PARSE_SECURITY_DOMAIN
, 0, new_url
,
1938 new_size
, &new_size
, 0);
1939 if(parse_hres
== S_FALSE
)
1942 hres
= E_OUTOFMEMORY
;
1945 hres
= E_UNEXPECTED
;
1949 if(hres
== S_OK
&& parse_hres
== S_OK
) {
1950 CoTaskMemFree(alloc_url
);
1951 url
= alloc_url
= new_url
;
1955 CoTaskMemFree(new_url
);
1957 hres
= E_OUTOFMEMORY
;
1959 IInternetProtocolInfo_Release(protocol_info
);
1963 WARN("failed %08x\n", hres
);
1964 CoTaskMemFree(alloc_url
);
1969 size
= strlenW(url
)+1;
1970 alloc_url
= CoTaskMemAlloc(size
* sizeof(WCHAR
));
1972 return E_OUTOFMEMORY
;
1973 memcpy(alloc_url
, url
, size
* sizeof(WCHAR
));
1976 *result
= alloc_url
;
1980 /********************************************************************
1981 * CoInternetGetSecurityUrl (URLMON.@)
1983 HRESULT WINAPI
CoInternetGetSecurityUrl(LPCWSTR pwzUrl
, LPWSTR
*ppwzSecUrl
, PSUACTION psuAction
, DWORD dwReserved
)
1988 TRACE("(%p,%p,%u,%u)\n", pwzUrl
, ppwzSecUrl
, psuAction
, dwReserved
);
1990 hres
= parse_security_url(pwzUrl
, psuAction
, &secure_url
);
1994 if(psuAction
!= PSU_SECURITY_URL_ONLY
) {
1995 PARSEDURLW parsed_url
= { sizeof(parsed_url
) };
1998 /* FIXME: Use helpers from uri.c */
1999 if(SUCCEEDED(ParseURLW(secure_url
, &parsed_url
))) {
2002 switch(parsed_url
.nScheme
) {
2003 case URL_SCHEME_FTP
:
2004 case URL_SCHEME_HTTP
:
2005 case URL_SCHEME_HTTPS
:
2006 size
= strlenW(secure_url
)+1;
2007 new_url
= CoTaskMemAlloc(size
* sizeof(WCHAR
));
2009 hres
= UrlGetPartW(secure_url
, new_url
, &size
, URL_PART_HOSTNAME
, URL_PARTFLAG_KEEPSCHEME
);
2011 hres
= E_OUTOFMEMORY
;
2012 CoTaskMemFree(secure_url
);
2014 WARN("UrlGetPart failed: %08x\n", hres
);
2015 CoTaskMemFree(new_url
);
2016 return FAILED(hres
) ? hres
: E_FAIL
;
2018 secure_url
= new_url
;
2023 *ppwzSecUrl
= secure_url
;
2027 /********************************************************************
2028 * CoInternetGetSecurityUrlEx (URLMON.@)
2030 HRESULT WINAPI
CoInternetGetSecurityUrlEx(IUri
*pUri
, IUri
**ppSecUri
, PSUACTION psuAction
, DWORD_PTR dwReserved
)
2032 URL_SCHEME scheme_type
;
2037 TRACE("(%p,%p,%u,%u)\n", pUri
, ppSecUri
, psuAction
, (DWORD
)dwReserved
);
2039 if(!pUri
|| !ppSecUri
)
2040 return E_INVALIDARG
;
2042 hres
= IUri_GetDisplayUri(pUri
, &secure_uri
);
2046 hres
= parse_security_url(secure_uri
, psuAction
, &ret_url
);
2047 SysFreeString(secure_uri
);
2051 /* File URIs have to hierarchical. */
2052 hres
= IUri_GetScheme(pUri
, (DWORD
*)&scheme_type
);
2053 if(SUCCEEDED(hres
) && scheme_type
== URL_SCHEME_FILE
) {
2054 const WCHAR
*tmp
= ret_url
;
2056 /* Check and see if a "//" is after the scheme name. */
2057 tmp
+= sizeof(fileW
)/sizeof(WCHAR
);
2058 if(*tmp
!= '/' || *(tmp
+1) != '/')
2059 hres
= E_INVALIDARG
;
2063 hres
= CreateUri(ret_url
, Uri_CREATE_ALLOW_IMPLICIT_WILDCARD_SCHEME
, 0, ppSecUri
);
2064 CoTaskMemFree(ret_url
);
2068 /********************************************************************
2069 * CompareSecurityIds (URLMON.@)
2071 HRESULT WINAPI
CompareSecurityIds(BYTE
*secid1
, DWORD size1
, BYTE
*secid2
, DWORD size2
, DWORD reserved
)
2073 FIXME("(%p %d %p %d %x)\n", secid1
, size1
, secid2
, size2
, reserved
);
2077 /********************************************************************
2078 * IsInternetESCEnabledLocal (URLMON.108)
2080 * Undocumented, returns TRUE if IE is running in Enhanced Security Configuration.
2082 BOOL WINAPI
IsInternetESCEnabledLocal(void)
2084 static BOOL esc_initialized
, esc_enabled
;
2088 if(!esc_initialized
) {
2089 DWORD type
, size
, val
;
2092 static const WCHAR iehardenW
[] = {'I','E','H','a','r','d','e','n',0};
2094 if(RegOpenKeyExW(HKEY_CURRENT_USER
, zone_map_keyW
, 0, KEY_QUERY_VALUE
, &zone_map
) == ERROR_SUCCESS
) {
2095 size
= sizeof(DWORD
);
2096 if(RegQueryValueExW(zone_map
, iehardenW
, NULL
, &type
, (BYTE
*)&val
, &size
) == ERROR_SUCCESS
)
2097 esc_enabled
= type
== REG_DWORD
&& val
!= 0;
2098 RegCloseKey(zone_map
);
2100 esc_initialized
= TRUE
;