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
[str_len
-pattern_len
-1] == '.' && !strcmpiW(str
+(str_len
-pattern_len
), pattern
)) {
246 *matched
= str
+(str_len
-pattern_len
);
249 /* The pattern doesn't have an implicit wildcard, or an explicit wildcard,
250 * so 'str' has to be an exact match to the 'pattern'.
252 if(!strcmpiW(str
, pattern
)) {
260 TRACE("Found a match: matched=%s\n", debugstr_w(*matched
));
262 TRACE("No match found\n");
267 static BOOL
get_zone_for_scheme(HKEY key
, LPCWSTR schema
, DWORD
*zone
)
269 static const WCHAR wildcardW
[] = {'*',0};
272 DWORD size
= sizeof(DWORD
);
275 /* See if the key contains a value for the scheme first. */
276 res
= RegQueryValueExW(key
, schema
, NULL
, &type
, (BYTE
*)zone
, &size
);
277 if(res
== ERROR_SUCCESS
) {
278 if(type
== REG_DWORD
)
280 WARN("Unexpected value type %d for value %s, expected REG_DWORD\n", type
, debugstr_w(schema
));
283 /* Try to get the zone for the wildcard scheme. */
284 size
= sizeof(DWORD
);
285 res
= RegQueryValueExW(key
, wildcardW
, NULL
, &type
, (BYTE
*)zone
, &size
);
286 if(res
!= ERROR_SUCCESS
)
289 if(type
!= REG_DWORD
) {
290 WARN("Unexpected value type %d for value %s, expected REG_DWORD\n", type
, debugstr_w(wildcardW
));
297 /********************************************************************
298 * search_domain_for_zone [internal]
300 * Searches the specified 'domain' registry key to see if 'host' maps into it, or any
301 * of its subdomain registry keys.
303 * Returns S_OK if a match is found, S_FALSE if no matches were found, or an error code.
305 static HRESULT
search_domain_for_zone(HKEY domains
, LPCWSTR domain
, DWORD domain_len
, LPCWSTR schema
,
306 LPCWSTR host
, DWORD host_len
, DWORD
*zone
)
313 if(host_len
>= domain_len
&& matches_domain_pattern(domain
, host
, TRUE
, &matched
)) {
314 res
= RegOpenKeyW(domains
, domain
, &domain_key
);
315 if(res
!= ERROR_SUCCESS
) {
316 ERR("Failed to open domain key %s: %d\n", debugstr_w(domain
), res
);
321 found
= get_zone_for_scheme(domain_key
, schema
, zone
);
324 DWORD subdomain_count
, subdomain_len
;
325 BOOL check_domain
= TRUE
;
327 find_domain_name(domain
, domain_len
, &domain_offset
);
329 res
= RegQueryInfoKeyW(domain_key
, NULL
, NULL
, NULL
, &subdomain_count
, &subdomain_len
,
330 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
);
331 if(res
!= ERROR_SUCCESS
) {
332 ERR("Unable to query info for key %s: %d\n", debugstr_w(domain
), res
);
333 RegCloseKey(domain_key
);
337 if(subdomain_count
) {
342 subdomain
= heap_alloc((subdomain_len
+1)*sizeof(WCHAR
));
344 RegCloseKey(domain_key
);
345 return E_OUTOFMEMORY
;
348 component
= heap_strndupW(host
, matched
-host
-1);
350 heap_free(subdomain
);
351 RegCloseKey(domain_key
);
352 return E_OUTOFMEMORY
;
355 for(i
= 0; i
< subdomain_count
; ++i
) {
356 DWORD len
= subdomain_len
+1;
357 const WCHAR
*sub_matched
;
359 res
= RegEnumKeyExW(domain_key
, i
, subdomain
, &len
, NULL
, NULL
, NULL
, NULL
);
360 if(res
!= ERROR_SUCCESS
) {
361 heap_free(component
);
362 heap_free(subdomain
);
363 RegCloseKey(domain_key
);
367 if(matches_domain_pattern(subdomain
, component
, FALSE
, &sub_matched
)) {
370 res
= RegOpenKeyW(domain_key
, subdomain
, &subdomain_key
);
371 if(res
!= ERROR_SUCCESS
) {
372 ERR("Unable to open subdomain key %s of %s: %d\n", debugstr_w(subdomain
),
373 debugstr_w(domain
), res
);
374 heap_free(component
);
375 heap_free(subdomain
);
376 RegCloseKey(domain_key
);
380 found
= get_zone_for_scheme(subdomain_key
, schema
, zone
);
381 check_domain
= FALSE
;
382 RegCloseKey(subdomain_key
);
386 heap_free(subdomain
);
387 heap_free(component
);
390 /* There's a chance that 'host' implicitly mapped into 'domain', in
391 * which case we check to see if 'domain' contains zone information.
393 * This can only happen if 'domain' is its own domain name.
395 * "google.com" (domain name = "google.com")
398 * host = "www.google.com"
400 * Then host would map directly into the "google.com" domain key.
402 * If 'domain' has more than just its domain name, or it does not
403 * have a domain name, then we don't perform the check. The reason
404 * for this is that these domains don't allow implicit mappings.
406 * domain = "org" (has no domain name)
409 * The mapping would only happen if the "org" key had an explicit subkey
412 if(check_domain
&& !domain_offset
&& !strchrW(host
, matched
-host
-1))
413 found
= get_zone_for_scheme(domain_key
, schema
, zone
);
415 RegCloseKey(domain_key
);
418 return found
? S_OK
: S_FALSE
;
421 static HRESULT
search_for_domain_mapping(HKEY domains
, LPCWSTR schema
, LPCWSTR host
, DWORD host_len
, DWORD
*zone
)
424 DWORD domain_count
, domain_len
, i
;
426 HRESULT hres
= S_FALSE
;
428 res
= RegQueryInfoKeyW(domains
, NULL
, NULL
, NULL
, &domain_count
, &domain_len
,
429 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
);
430 if(res
!= ERROR_SUCCESS
) {
431 WARN("Failed to retrieve information about key\n");
438 domain
= heap_alloc((domain_len
+1)*sizeof(WCHAR
));
440 return E_OUTOFMEMORY
;
442 for(i
= 0; i
< domain_count
; ++i
) {
443 DWORD len
= domain_len
+1;
445 res
= RegEnumKeyExW(domains
, i
, domain
, &len
, NULL
, NULL
, NULL
, NULL
);
446 if(res
!= ERROR_SUCCESS
) {
451 hres
= search_domain_for_zone(domains
, domain
, len
, schema
, host
, host_len
, zone
);
452 if(FAILED(hres
) || hres
== S_OK
)
460 static HRESULT
get_zone_from_domains(IUri
*uri
, DWORD
*zone
)
468 hres
= IUri_GetScheme(uri
, &scheme_type
);
472 /* Windows doesn't play nice with unknown scheme types when it tries
473 * to check if a host name maps into any domains.
475 if(scheme_type
== URL_SCHEME_UNKNOWN
)
478 hres
= IUri_GetHost(uri
, &host
);
482 /* Known hierarchical scheme types must have a host. If they don't Windows
483 * assigns URLZONE_INVALID to the zone.
485 if((scheme_type
!= URL_SCHEME_UNKNOWN
&& scheme_type
!= URL_SCHEME_FILE
)
486 && is_hierarchical_scheme(scheme_type
) && !*host
) {
487 *zone
= URLZONE_INVALID
;
491 /* The MapUrlToZone functions return S_OK when this condition occurs. */
495 hres
= IUri_GetSchemeName(uri
, &scheme
);
501 /* First try CURRENT_USER. */
502 res
= RegOpenKeyW(HKEY_CURRENT_USER
, wszZoneMapDomainsKey
, &domains
);
503 if(res
== ERROR_SUCCESS
) {
504 hres
= search_for_domain_mapping(domains
, scheme
, host
, SysStringLen(host
), zone
);
505 RegCloseKey(domains
);
507 WARN("Failed to open HKCU's %s key\n", debugstr_w(wszZoneMapDomainsKey
));
509 /* If that doesn't work try LOCAL_MACHINE. */
510 if(hres
== S_FALSE
) {
511 res
= RegOpenKeyW(HKEY_LOCAL_MACHINE
, wszZoneMapDomainsKey
, &domains
);
512 if(res
== ERROR_SUCCESS
) {
513 hres
= search_for_domain_mapping(domains
, scheme
, host
, SysStringLen(host
), zone
);
514 RegCloseKey(domains
);
516 WARN("Failed to open HKLM's %s key\n", debugstr_w(wszZoneMapDomainsKey
));
520 SysFreeString(scheme
);
524 static HRESULT
map_security_uri_to_zone(IUri
*uri
, DWORD
*zone
)
529 *zone
= URLZONE_INVALID
;
531 hres
= IUri_GetSchemeName(uri
, &scheme
);
535 if(!strcmpiW(scheme
, fileW
)) {
537 WCHAR
*ptr
, *path_start
, root
[20];
539 hres
= IUri_GetPath(uri
, &path
);
541 SysFreeString(scheme
);
545 if(*path
== '/' && is_drive_path(path
+1))
550 if((ptr
= strchrW(path_start
, ':')) && ptr
-path_start
+1 < sizeof(root
)/sizeof(WCHAR
)) {
553 memcpy(root
, path_start
, (ptr
-path_start
+1)*sizeof(WCHAR
));
554 root
[ptr
-path_start
+1] = 0;
556 type
= GetDriveTypeW(root
);
560 case DRIVE_NO_ROOT_DIR
:
562 case DRIVE_REMOVABLE
:
566 *zone
= URLZONE_LOCAL_MACHINE
;
570 *zone
= URLZONE_INTERNET
;
574 FIXME("unsupported drive type %d\n", type
);
580 if(*zone
== URLZONE_INVALID
) {
581 hres
= get_zone_from_domains(uri
, zone
);
583 hres
= get_zone_from_reg(scheme
, zone
);
586 SysFreeString(scheme
);
590 static HRESULT
map_url_to_zone(LPCWSTR url
, DWORD
*zone
, LPWSTR
*ret_url
)
596 *zone
= URLZONE_INVALID
;
598 hres
= CoInternetGetSecurityUrl(url
, &secur_url
, PSU_SECURITY_URL_ONLY
, 0);
600 DWORD size
= strlenW(url
)*sizeof(WCHAR
);
602 secur_url
= CoTaskMemAlloc(size
);
604 return E_OUTOFMEMORY
;
606 memcpy(secur_url
, url
, size
);
609 hres
= CreateUri(secur_url
, Uri_CREATE_ALLOW_IMPLICIT_FILE_SCHEME
, 0, &secur_uri
);
611 CoTaskMemFree(secur_url
);
615 hres
= map_security_uri_to_zone(secur_uri
, zone
);
616 IUri_Release(secur_uri
);
618 if(FAILED(hres
) || !ret_url
)
619 CoTaskMemFree(secur_url
);
621 *ret_url
= secur_url
;
626 static HRESULT
map_uri_to_zone(IUri
*uri
, DWORD
*zone
, IUri
**ret_uri
)
631 hres
= CoInternetGetSecurityUrlEx(uri
, &secur_uri
, PSU_SECURITY_URL_ONLY
, 0);
635 hres
= map_security_uri_to_zone(secur_uri
, zone
);
636 if(FAILED(hres
) || !ret_uri
)
637 IUri_Release(secur_uri
);
639 *ret_uri
= secur_uri
;
644 static HRESULT
open_zone_key(HKEY parent_key
, DWORD zone
, HKEY
*hkey
)
646 static const WCHAR wszFormat
[] = {'%','s','%','u',0};
648 WCHAR key_name
[sizeof(wszZonesKey
)/sizeof(WCHAR
)+12];
651 wsprintfW(key_name
, wszFormat
, wszZonesKey
, zone
);
653 res
= RegOpenKeyW(parent_key
, key_name
, hkey
);
655 if(res
!= ERROR_SUCCESS
) {
656 WARN("RegOpenKey failed\n");
663 static HRESULT
get_action_policy(DWORD zone
, DWORD action
, BYTE
*policy
, DWORD size
, URLZONEREG zone_reg
)
671 case URLACTION_SCRIPT_OVERRIDE_SAFETY
:
672 case URLACTION_ACTIVEX_OVERRIDE_SCRIPT_SAFETY
:
673 *(DWORD
*)policy
= URLPOLICY_DISALLOW
;
678 case URLZONEREG_DEFAULT
:
679 case URLZONEREG_HKCU
:
680 parent_key
= HKEY_CURRENT_USER
;
682 case URLZONEREG_HKLM
:
683 parent_key
= HKEY_LOCAL_MACHINE
;
686 WARN("Unknown URLZONEREG: %d\n", zone_reg
);
690 hres
= open_zone_key(parent_key
, zone
, &hkey
);
691 if(SUCCEEDED(hres
)) {
692 WCHAR action_str
[16];
695 static const WCHAR formatW
[] = {'%','X',0};
697 wsprintfW(action_str
, formatW
, action
);
699 res
= RegQueryValueExW(hkey
, action_str
, NULL
, NULL
, policy
, &len
);
700 if(res
== ERROR_MORE_DATA
) {
702 }else if(res
== ERROR_FILE_NOT_FOUND
) {
704 }else if(res
!= ERROR_SUCCESS
) {
705 ERR("RegQueryValue failed: %d\n", res
);
712 if(FAILED(hres
) && zone_reg
== URLZONEREG_DEFAULT
)
713 return get_action_policy(zone
, action
, policy
, size
, URLZONEREG_HKLM
);
718 static HRESULT
generate_security_id(IUri
*uri
, BYTE
*secid
, DWORD
*secid_len
, DWORD zone
)
724 if(zone
== URLZONE_INVALID
)
727 hres
= IUri_GetScheme(uri
, &scheme_type
);
731 /* Windows handles opaque URLs differently then hierarchical ones. */
732 if(!is_hierarchical_scheme(scheme_type
) && scheme_type
!= URL_SCHEME_WILDCARD
) {
735 hres
= IUri_GetDisplayUri(uri
, &display_uri
);
739 len
= WideCharToMultiByte(CP_ACP
, 0, display_uri
, -1, NULL
, 0, NULL
, NULL
)-1;
741 if(len
+sizeof(DWORD
) > *secid_len
) {
742 SysFreeString(display_uri
);
743 return HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER
);
746 WideCharToMultiByte(CP_ACP
, 0, display_uri
, -1, (LPSTR
)secid
, len
, NULL
, NULL
);
747 SysFreeString(display_uri
);
749 *(DWORD
*)(secid
+len
) = zone
;
752 DWORD host_len
, scheme_len
;
755 hres
= IUri_GetHost(uri
, &host
);
759 /* The host can't be empty for Wildcard URIs. */
760 if(scheme_type
== URL_SCHEME_WILDCARD
&& !*host
) {
765 hres
= IUri_GetSchemeName(uri
, &scheme
);
771 host_len
= WideCharToMultiByte(CP_ACP
, 0, host
, -1, NULL
, 0, NULL
, NULL
)-1;
772 scheme_len
= WideCharToMultiByte(CP_ACP
, 0, scheme
, -1, NULL
, 0, NULL
, NULL
)-1;
774 len
= host_len
+scheme_len
+sizeof(BYTE
);
776 if(len
+sizeof(DWORD
) > *secid_len
) {
778 SysFreeString(scheme
);
779 return HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER
);
782 WideCharToMultiByte(CP_ACP
, 0, scheme
, -1, (LPSTR
)secid
, len
, NULL
, NULL
);
783 SysFreeString(scheme
);
785 ptr
= secid
+scheme_len
;
788 WideCharToMultiByte(CP_ACP
, 0, host
, -1, (LPSTR
)ptr
, host_len
, NULL
, NULL
);
796 *secid_len
= len
+sizeof(DWORD
);
801 static HRESULT
get_security_id_for_url(LPCWSTR url
, BYTE
*secid
, DWORD
*secid_len
)
804 DWORD zone
= URLZONE_INVALID
;
805 LPWSTR secur_url
= NULL
;
808 hres
= map_url_to_zone(url
, &zone
, &secur_url
);
810 return hres
== 0x80041001 ? E_INVALIDARG
: hres
;
812 hres
= CreateUri(secur_url
, Uri_CREATE_ALLOW_IMPLICIT_FILE_SCHEME
, 0, &uri
);
813 CoTaskMemFree(secur_url
);
817 hres
= generate_security_id(uri
, secid
, secid_len
, zone
);
823 static HRESULT
get_security_id_for_uri(IUri
*uri
, BYTE
*secid
, DWORD
*secid_len
)
827 DWORD zone
= URLZONE_INVALID
;
829 hres
= map_uri_to_zone(uri
, &zone
, &secur_uri
);
833 hres
= generate_security_id(secur_uri
, secid
, secid_len
, zone
);
834 IUri_Release(secur_uri
);
839 /***********************************************************************
840 * InternetSecurityManager implementation
844 IInternetSecurityManagerEx2 IInternetSecurityManagerEx2_iface
;
848 IInternetSecurityMgrSite
*mgrsite
;
849 IInternetSecurityManager
*custom_manager
;
852 static inline SecManagerImpl
*impl_from_IInternetSecurityManagerEx2(IInternetSecurityManagerEx2
*iface
)
854 return CONTAINING_RECORD(iface
, SecManagerImpl
, IInternetSecurityManagerEx2_iface
);
857 static HRESULT WINAPI
SecManagerImpl_QueryInterface(IInternetSecurityManagerEx2
* iface
,REFIID riid
,void** ppvObject
)
859 SecManagerImpl
*This
= impl_from_IInternetSecurityManagerEx2(iface
);
861 TRACE("(%p)->(%s %p)\n",This
,debugstr_guid(riid
),ppvObject
);
866 if(IsEqualIID(&IID_IUnknown
, riid
) ||
867 IsEqualIID(&IID_IInternetSecurityManager
, riid
) ||
868 IsEqualIID(&IID_IInternetSecurityManagerEx
, riid
) ||
869 IsEqualIID(&IID_IInternetSecurityManagerEx2
, riid
)) {
872 WARN("not supported interface %s\n", debugstr_guid(riid
));
874 return E_NOINTERFACE
;
877 IInternetSecurityManagerEx2_AddRef(iface
);
881 static ULONG WINAPI
SecManagerImpl_AddRef(IInternetSecurityManagerEx2
* iface
)
883 SecManagerImpl
*This
= impl_from_IInternetSecurityManagerEx2(iface
);
884 ULONG refCount
= InterlockedIncrement(&This
->ref
);
886 TRACE("(%p) ref=%u\n", This
, refCount
);
891 static ULONG WINAPI
SecManagerImpl_Release(IInternetSecurityManagerEx2
* iface
)
893 SecManagerImpl
*This
= impl_from_IInternetSecurityManagerEx2(iface
);
894 ULONG refCount
= InterlockedDecrement(&This
->ref
);
896 TRACE("(%p) ref=%u\n", This
, refCount
);
898 /* destroy the object if there's no more reference on it */
901 IInternetSecurityMgrSite_Release(This
->mgrsite
);
902 if(This
->custom_manager
)
903 IInternetSecurityManager_Release(This
->custom_manager
);
907 URLMON_UnlockModule();
913 static HRESULT WINAPI
SecManagerImpl_SetSecuritySite(IInternetSecurityManagerEx2
*iface
,
914 IInternetSecurityMgrSite
*pSite
)
916 SecManagerImpl
*This
= impl_from_IInternetSecurityManagerEx2(iface
);
918 TRACE("(%p)->(%p)\n", This
, pSite
);
921 IInternetSecurityMgrSite_Release(This
->mgrsite
);
923 if(This
->custom_manager
) {
924 IInternetSecurityManager_Release(This
->custom_manager
);
925 This
->custom_manager
= NULL
;
928 This
->mgrsite
= pSite
;
931 IServiceProvider
*servprov
;
934 IInternetSecurityMgrSite_AddRef(pSite
);
936 hres
= IInternetSecurityMgrSite_QueryInterface(pSite
, &IID_IServiceProvider
,
938 if(SUCCEEDED(hres
)) {
939 IServiceProvider_QueryService(servprov
, &SID_SInternetSecurityManager
,
940 &IID_IInternetSecurityManager
, (void**)&This
->custom_manager
);
941 IServiceProvider_Release(servprov
);
948 static HRESULT WINAPI
SecManagerImpl_GetSecuritySite(IInternetSecurityManagerEx2
*iface
,
949 IInternetSecurityMgrSite
**ppSite
)
951 SecManagerImpl
*This
= impl_from_IInternetSecurityManagerEx2(iface
);
953 TRACE("(%p)->(%p)\n", This
, ppSite
);
959 IInternetSecurityMgrSite_AddRef(This
->mgrsite
);
961 *ppSite
= This
->mgrsite
;
965 static HRESULT WINAPI
SecManagerImpl_MapUrlToZone(IInternetSecurityManagerEx2
*iface
,
966 LPCWSTR pwszUrl
, DWORD
*pdwZone
,
969 SecManagerImpl
*This
= impl_from_IInternetSecurityManagerEx2(iface
);
972 TRACE("(%p)->(%s %p %08x)\n", iface
, debugstr_w(pwszUrl
), pdwZone
, dwFlags
);
974 if(This
->custom_manager
) {
975 hres
= IInternetSecurityManager_MapUrlToZone(This
->custom_manager
,
976 pwszUrl
, pdwZone
, dwFlags
);
977 if(hres
!= INET_E_DEFAULT_ACTION
)
982 *pdwZone
= URLZONE_INVALID
;
987 FIXME("not supported flags: %08x\n", dwFlags
);
989 return map_url_to_zone(pwszUrl
, pdwZone
, NULL
);
992 static HRESULT WINAPI
SecManagerImpl_GetSecurityId(IInternetSecurityManagerEx2
*iface
,
993 LPCWSTR pwszUrl
, BYTE
*pbSecurityId
, DWORD
*pcbSecurityId
, DWORD_PTR dwReserved
)
995 SecManagerImpl
*This
= impl_from_IInternetSecurityManagerEx2(iface
);
997 TRACE("(%p)->(%s %p %p %08lx)\n", iface
, debugstr_w(pwszUrl
), pbSecurityId
,
998 pcbSecurityId
, dwReserved
);
1000 if(This
->custom_manager
) {
1003 hres
= IInternetSecurityManager_GetSecurityId(This
->custom_manager
,
1004 pwszUrl
, pbSecurityId
, pcbSecurityId
, dwReserved
);
1005 if(hres
!= INET_E_DEFAULT_ACTION
)
1009 if(!pwszUrl
|| !pbSecurityId
|| !pcbSecurityId
)
1010 return E_INVALIDARG
;
1013 FIXME("dwReserved is not supported\n");
1015 return get_security_id_for_url(pwszUrl
, pbSecurityId
, pcbSecurityId
);
1019 static HRESULT WINAPI
SecManagerImpl_ProcessUrlAction(IInternetSecurityManagerEx2
*iface
,
1020 LPCWSTR pwszUrl
, DWORD dwAction
,
1021 BYTE
*pPolicy
, DWORD cbPolicy
,
1022 BYTE
*pContext
, DWORD cbContext
,
1023 DWORD dwFlags
, DWORD dwReserved
)
1025 SecManagerImpl
*This
= impl_from_IInternetSecurityManagerEx2(iface
);
1029 TRACE("(%p)->(%s %08x %p %08x %p %08x %08x %08x)\n", iface
, debugstr_w(pwszUrl
), dwAction
,
1030 pPolicy
, cbPolicy
, pContext
, cbContext
, dwFlags
, dwReserved
);
1032 if(This
->custom_manager
) {
1033 hres
= IInternetSecurityManager_ProcessUrlAction(This
->custom_manager
, pwszUrl
, dwAction
,
1034 pPolicy
, cbPolicy
, pContext
, cbContext
, dwFlags
, dwReserved
);
1035 if(hres
!= INET_E_DEFAULT_ACTION
)
1039 if(dwFlags
|| dwReserved
)
1040 FIXME("Unsupported arguments\n");
1043 return E_INVALIDARG
;
1045 hres
= map_url_to_zone(pwszUrl
, &zone
, NULL
);
1049 hres
= get_action_policy(zone
, dwAction
, (BYTE
*)&policy
, sizeof(policy
), URLZONEREG_DEFAULT
);
1053 TRACE("policy %x\n", policy
);
1054 if(cbPolicy
>= sizeof(DWORD
))
1055 *(DWORD
*)pPolicy
= policy
;
1057 switch(GetUrlPolicyPermissions(policy
)) {
1058 case URLPOLICY_ALLOW
:
1059 case URLPOLICY_CHANNEL_SOFTDIST_PRECACHE
:
1061 case URLPOLICY_DISALLOW
:
1063 case URLPOLICY_QUERY
:
1064 FIXME("URLPOLICY_QUERY not implemented\n");
1067 FIXME("Not implemented policy %x\n", policy
);
1074 static HRESULT WINAPI
SecManagerImpl_QueryCustomPolicy(IInternetSecurityManagerEx2
*iface
,
1075 LPCWSTR pwszUrl
, REFGUID guidKey
,
1076 BYTE
**ppPolicy
, DWORD
*pcbPolicy
,
1077 BYTE
*pContext
, DWORD cbContext
,
1080 SecManagerImpl
*This
= impl_from_IInternetSecurityManagerEx2(iface
);
1083 TRACE("(%p)->(%s %s %p %p %p %08x %08x )\n", iface
, debugstr_w(pwszUrl
), debugstr_guid(guidKey
),
1084 ppPolicy
, pcbPolicy
, pContext
, cbContext
, dwReserved
);
1086 if(This
->custom_manager
) {
1087 hres
= IInternetSecurityManager_QueryCustomPolicy(This
->custom_manager
, pwszUrl
, guidKey
,
1088 ppPolicy
, pcbPolicy
, pContext
, cbContext
, dwReserved
);
1089 if(hres
!= INET_E_DEFAULT_ACTION
)
1093 WARN("Unknown guidKey %s\n", debugstr_guid(guidKey
));
1094 return HRESULT_FROM_WIN32(ERROR_NOT_FOUND
);
1097 static HRESULT WINAPI
SecManagerImpl_SetZoneMapping(IInternetSecurityManagerEx2
*iface
,
1098 DWORD dwZone
, LPCWSTR pwszPattern
, DWORD dwFlags
)
1100 SecManagerImpl
*This
= impl_from_IInternetSecurityManagerEx2(iface
);
1103 TRACE("(%p)->(%08x %s %08x)\n", iface
, dwZone
, debugstr_w(pwszPattern
),dwFlags
);
1105 if(This
->custom_manager
) {
1106 hres
= IInternetSecurityManager_SetZoneMapping(This
->custom_manager
, dwZone
,
1107 pwszPattern
, dwFlags
);
1108 if(hres
!= INET_E_DEFAULT_ACTION
)
1112 FIXME("Default action is not implemented\n");
1116 static HRESULT WINAPI
SecManagerImpl_GetZoneMappings(IInternetSecurityManagerEx2
*iface
,
1117 DWORD dwZone
, IEnumString
**ppenumString
, DWORD dwFlags
)
1119 SecManagerImpl
*This
= impl_from_IInternetSecurityManagerEx2(iface
);
1122 TRACE("(%p)->(%08x %p %08x)\n", iface
, dwZone
, ppenumString
,dwFlags
);
1124 if(This
->custom_manager
) {
1125 hres
= IInternetSecurityManager_GetZoneMappings(This
->custom_manager
, dwZone
,
1126 ppenumString
, dwFlags
);
1127 if(hres
!= INET_E_DEFAULT_ACTION
)
1131 FIXME("Default action is not implemented\n");
1135 static HRESULT WINAPI
SecManagerImpl_ProcessUrlActionEx(IInternetSecurityManagerEx2
*iface
,
1136 LPCWSTR pwszUrl
, DWORD dwAction
, BYTE
*pPolicy
, DWORD cbPolicy
, BYTE
*pContext
, DWORD cbContext
,
1137 DWORD dwFlags
, DWORD dwReserved
, DWORD
*pdwOutFlags
)
1139 SecManagerImpl
*This
= impl_from_IInternetSecurityManagerEx2(iface
);
1140 FIXME("(%p)->(%s %08x %p %d %p %d %08x %08x %p) stub\n", This
, debugstr_w(pwszUrl
), dwAction
, pPolicy
, cbPolicy
,
1141 pContext
, cbContext
, dwFlags
, dwReserved
, pdwOutFlags
);
1145 static HRESULT WINAPI
SecManagerImpl_MapUrlToZoneEx2(IInternetSecurityManagerEx2
*iface
,
1146 IUri
*pUri
, DWORD
*pdwZone
, DWORD dwFlags
, LPWSTR
*ppwszMappedUrl
, DWORD
*pdwOutFlags
)
1148 SecManagerImpl
*This
= impl_from_IInternetSecurityManagerEx2(iface
);
1150 TRACE("(%p)->(%p %p %08x %p %p)\n", This
, pUri
, pdwZone
, dwFlags
, ppwszMappedUrl
, pdwOutFlags
);
1152 if(This
->custom_manager
) {
1154 IInternetSecurityManagerEx2
*sec_mgr2
;
1156 hres
= IInternetSecurityManager_QueryInterface(This
->custom_manager
, &IID_IInternetSecurityManagerEx2
,
1158 if(SUCCEEDED(hres
)) {
1159 hres
= IInternetSecurityManagerEx2_MapUrlToZoneEx2(sec_mgr2
, pUri
, pdwZone
, dwFlags
, ppwszMappedUrl
, pdwOutFlags
);
1160 IInternetSecurityManagerEx2_Release(sec_mgr2
);
1164 hres
= IUri_GetDisplayUri(pUri
, &url
);
1168 hres
= IInternetSecurityManager_MapUrlToZone(This
->custom_manager
, url
, pdwZone
, dwFlags
);
1172 if(hres
!= INET_E_DEFAULT_ACTION
)
1177 return E_INVALIDARG
;
1180 *pdwZone
= URLZONE_INVALID
;
1181 return E_INVALIDARG
;
1185 FIXME("Unsupported flags: %08x\n", dwFlags
);
1187 return map_uri_to_zone(pUri
, pdwZone
, NULL
);
1190 static HRESULT WINAPI
SecManagerImpl_ProcessUrlActionEx2(IInternetSecurityManagerEx2
*iface
,
1191 IUri
*pUri
, DWORD dwAction
, BYTE
*pPolicy
, DWORD cbPolicy
, BYTE
*pContext
, DWORD cbContext
,
1192 DWORD dwFlags
, DWORD_PTR dwReserved
, DWORD
*pdwOutFlags
)
1194 SecManagerImpl
*This
= impl_from_IInternetSecurityManagerEx2(iface
);
1195 FIXME("(%p)->(%p %08x %p %d %p %d %08x %08x %p) stub\n", This
, pUri
, dwAction
, pPolicy
,
1196 cbPolicy
, pContext
, cbContext
, dwFlags
, (DWORD
)dwReserved
, pdwOutFlags
);
1200 static HRESULT WINAPI
SecManagerImpl_GetSecurityIdEx2(IInternetSecurityManagerEx2
*iface
,
1201 IUri
*pUri
, BYTE
*pbSecurityId
, DWORD
*pcbSecurityId
, DWORD_PTR dwReserved
)
1203 SecManagerImpl
*This
= impl_from_IInternetSecurityManagerEx2(iface
);
1204 TRACE("(%p)->(%p %p %p %08x) stub\n", This
, pUri
, pbSecurityId
, pcbSecurityId
, (DWORD
)dwReserved
);
1207 FIXME("dwReserved is not supported yet\n");
1209 if(!pUri
|| !pcbSecurityId
|| !pbSecurityId
)
1210 return E_INVALIDARG
;
1212 return get_security_id_for_uri(pUri
, pbSecurityId
, pcbSecurityId
);
1215 static HRESULT WINAPI
SecManagerImpl_QueryCustomPolicyEx2(IInternetSecurityManagerEx2
*iface
,
1216 IUri
*pUri
, REFGUID guidKey
, BYTE
**ppPolicy
, DWORD
*pcbPolicy
, BYTE
*pContext
,
1217 DWORD cbContext
, DWORD_PTR dwReserved
)
1219 SecManagerImpl
*This
= impl_from_IInternetSecurityManagerEx2(iface
);
1220 FIXME("(%p)->(%p %s %p %p %p %d %08x) stub\n", This
, pUri
, debugstr_guid(guidKey
), ppPolicy
, pcbPolicy
,
1221 pContext
, cbContext
, (DWORD
)dwReserved
);
1225 static const IInternetSecurityManagerEx2Vtbl VT_SecManagerImpl
=
1227 SecManagerImpl_QueryInterface
,
1228 SecManagerImpl_AddRef
,
1229 SecManagerImpl_Release
,
1230 SecManagerImpl_SetSecuritySite
,
1231 SecManagerImpl_GetSecuritySite
,
1232 SecManagerImpl_MapUrlToZone
,
1233 SecManagerImpl_GetSecurityId
,
1234 SecManagerImpl_ProcessUrlAction
,
1235 SecManagerImpl_QueryCustomPolicy
,
1236 SecManagerImpl_SetZoneMapping
,
1237 SecManagerImpl_GetZoneMappings
,
1238 SecManagerImpl_ProcessUrlActionEx
,
1239 SecManagerImpl_MapUrlToZoneEx2
,
1240 SecManagerImpl_ProcessUrlActionEx2
,
1241 SecManagerImpl_GetSecurityIdEx2
,
1242 SecManagerImpl_QueryCustomPolicyEx2
1245 HRESULT
SecManagerImpl_Construct(IUnknown
*pUnkOuter
, LPVOID
*ppobj
)
1247 SecManagerImpl
*This
;
1249 TRACE("(%p,%p)\n",pUnkOuter
,ppobj
);
1250 This
= heap_alloc(sizeof(*This
));
1252 /* Initialize the virtual function table. */
1253 This
->IInternetSecurityManagerEx2_iface
.lpVtbl
= &VT_SecManagerImpl
;
1256 This
->mgrsite
= NULL
;
1257 This
->custom_manager
= NULL
;
1261 URLMON_LockModule();
1266 /***********************************************************************
1267 * InternetZoneManager implementation
1271 IInternetZoneManagerEx2 IInternetZoneManagerEx2_iface
;
1274 DWORD zonemap_count
;
1277 static inline ZoneMgrImpl
*impl_from_IInternetZoneManagerEx2(IInternetZoneManagerEx2
*iface
)
1279 return CONTAINING_RECORD(iface
, ZoneMgrImpl
, IInternetZoneManagerEx2_iface
);
1283 /***********************************************************************
1284 * build_zonemap_from_reg [internal]
1286 * Enumerate the Zones in the Registry and return the Zones in a DWORD-array
1287 * The number of the Zones is returned in data[0]
1289 static LPDWORD
build_zonemap_from_reg(void)
1293 LPDWORD data
= NULL
;
1294 DWORD allocated
= 6; /* space for the zonecount and Zone "0" up to Zone "4" */
1300 res
= RegOpenKeyW(HKEY_CURRENT_USER
, wszZonesKey
, &hkey
);
1304 data
= heap_alloc(allocated
* sizeof(DWORD
));
1310 len
= sizeof(name
) / sizeof(name
[0]);
1311 res
= RegEnumKeyExW(hkey
, used
, name
, &len
, NULL
, NULL
, NULL
, NULL
);
1315 if (used
== allocated
) {
1319 new_data
= heap_realloc_zero(data
, allocated
* sizeof(DWORD
));
1325 data
[used
] = atoiW(name
);
1335 /* something failed */
1341 /********************************************************************
1342 * IInternetZoneManager_QueryInterface
1344 static HRESULT WINAPI
ZoneMgrImpl_QueryInterface(IInternetZoneManagerEx2
* iface
, REFIID riid
, void** ppvObject
)
1346 ZoneMgrImpl
* This
= impl_from_IInternetZoneManagerEx2(iface
);
1348 TRACE("(%p)->(%s,%p)\n", This
, debugstr_guid(riid
), ppvObject
);
1350 if(!This
|| !ppvObject
)
1351 return E_INVALIDARG
;
1353 if(IsEqualIID(&IID_IUnknown
, riid
)) {
1354 TRACE("(%p)->(IID_IUnknown %p)\n", This
, ppvObject
);
1355 }else if(IsEqualIID(&IID_IInternetZoneManager
, riid
)) {
1356 TRACE("(%p)->(IID_InternetZoneManager %p)\n", This
, ppvObject
);
1357 }else if(IsEqualIID(&IID_IInternetZoneManagerEx
, riid
)) {
1358 TRACE("(%p)->(IID_InternetZoneManagerEx %p)\n", This
, ppvObject
);
1359 }else if(IsEqualIID(&IID_IInternetZoneManagerEx2
, riid
)) {
1360 TRACE("(%p)->(IID_InternetZoneManagerEx2 %p)\n", This
, ppvObject
);
1364 FIXME("Unknown interface: %s\n", debugstr_guid(riid
));
1366 return E_NOINTERFACE
;
1370 IInternetZoneManagerEx2_AddRef(iface
);
1374 /********************************************************************
1375 * IInternetZoneManager_AddRef
1377 static ULONG WINAPI
ZoneMgrImpl_AddRef(IInternetZoneManagerEx2
* iface
)
1379 ZoneMgrImpl
* This
= impl_from_IInternetZoneManagerEx2(iface
);
1380 ULONG refCount
= InterlockedIncrement(&This
->ref
);
1382 TRACE("(%p)->(ref before=%u)\n",This
, refCount
- 1);
1387 /********************************************************************
1388 * IInternetZoneManager_Release
1390 static ULONG WINAPI
ZoneMgrImpl_Release(IInternetZoneManagerEx2
* iface
)
1392 ZoneMgrImpl
* This
= impl_from_IInternetZoneManagerEx2(iface
);
1393 ULONG refCount
= InterlockedDecrement(&This
->ref
);
1395 TRACE("(%p)->(ref before=%u)\n",This
, refCount
+ 1);
1398 while (This
->zonemap_count
) heap_free(This
->zonemaps
[--This
->zonemap_count
]);
1399 heap_free(This
->zonemaps
);
1401 URLMON_UnlockModule();
1407 /********************************************************************
1408 * IInternetZoneManager_GetZoneAttributes
1410 static HRESULT WINAPI
ZoneMgrImpl_GetZoneAttributes(IInternetZoneManagerEx2
* iface
,
1412 ZONEATTRIBUTES
* pZoneAttributes
)
1414 ZoneMgrImpl
* This
= impl_from_IInternetZoneManagerEx2(iface
);
1419 TRACE("(%p)->(%d %p)\n", This
, dwZone
, pZoneAttributes
);
1421 if (!pZoneAttributes
)
1422 return E_INVALIDARG
;
1424 hr
= open_zone_key(HKEY_CURRENT_USER
, dwZone
, &hcu
);
1426 return S_OK
; /* IE6 and older returned E_FAIL here */
1428 hr
= open_zone_key(HKEY_LOCAL_MACHINE
, dwZone
, &hklm
);
1430 TRACE("Zone %d not in HKLM\n", dwZone
);
1432 get_string_from_reg(hcu
, hklm
, displaynameW
, pZoneAttributes
->szDisplayName
, MAX_ZONE_PATH
);
1433 get_string_from_reg(hcu
, hklm
, descriptionW
, pZoneAttributes
->szDescription
, MAX_ZONE_DESCRIPTION
);
1434 get_string_from_reg(hcu
, hklm
, iconW
, pZoneAttributes
->szIconPath
, MAX_ZONE_PATH
);
1435 get_dword_from_reg(hcu
, hklm
, minlevelW
, &pZoneAttributes
->dwTemplateMinLevel
);
1436 get_dword_from_reg(hcu
, hklm
, currentlevelW
, &pZoneAttributes
->dwTemplateCurrentLevel
);
1437 get_dword_from_reg(hcu
, hklm
, recommendedlevelW
, &pZoneAttributes
->dwTemplateRecommended
);
1438 get_dword_from_reg(hcu
, hklm
, flagsW
, &pZoneAttributes
->dwFlags
);
1445 /********************************************************************
1446 * IInternetZoneManager_SetZoneAttributes
1448 static HRESULT WINAPI
ZoneMgrImpl_SetZoneAttributes(IInternetZoneManagerEx2
* iface
,
1450 ZONEATTRIBUTES
* pZoneAttributes
)
1452 ZoneMgrImpl
* This
= impl_from_IInternetZoneManagerEx2(iface
);
1456 TRACE("(%p)->(%d %p)\n", This
, dwZone
, pZoneAttributes
);
1458 if (!pZoneAttributes
)
1459 return E_INVALIDARG
;
1461 hr
= open_zone_key(HKEY_CURRENT_USER
, dwZone
, &hcu
);
1463 return S_OK
; /* IE6 returned E_FAIL here */
1465 /* cbSize is ignored */
1466 RegSetValueExW(hcu
, displaynameW
, 0, REG_SZ
, (LPBYTE
) pZoneAttributes
->szDisplayName
,
1467 (lstrlenW(pZoneAttributes
->szDisplayName
)+1)* sizeof(WCHAR
));
1469 RegSetValueExW(hcu
, descriptionW
, 0, REG_SZ
, (LPBYTE
) pZoneAttributes
->szDescription
,
1470 (lstrlenW(pZoneAttributes
->szDescription
)+1)* sizeof(WCHAR
));
1472 RegSetValueExW(hcu
, iconW
, 0, REG_SZ
, (LPBYTE
) pZoneAttributes
->szIconPath
,
1473 (lstrlenW(pZoneAttributes
->szIconPath
)+1)* sizeof(WCHAR
));
1475 RegSetValueExW(hcu
, minlevelW
, 0, REG_DWORD
,
1476 (const BYTE
*) &pZoneAttributes
->dwTemplateMinLevel
, sizeof(DWORD
));
1478 RegSetValueExW(hcu
, currentlevelW
, 0, REG_DWORD
,
1479 (const BYTE
*) &pZoneAttributes
->dwTemplateCurrentLevel
, sizeof(DWORD
));
1481 RegSetValueExW(hcu
, recommendedlevelW
, 0, REG_DWORD
,
1482 (const BYTE
*) &pZoneAttributes
->dwTemplateRecommended
, sizeof(DWORD
));
1484 RegSetValueExW(hcu
, flagsW
, 0, REG_DWORD
, (const BYTE
*) &pZoneAttributes
->dwFlags
, sizeof(DWORD
));
1490 /********************************************************************
1491 * IInternetZoneManager_GetZoneCustomPolicy
1493 static HRESULT WINAPI
ZoneMgrImpl_GetZoneCustomPolicy(IInternetZoneManagerEx2
* iface
,
1498 URLZONEREG ulrZoneReg
)
1500 FIXME("(%p)->(%08x %s %p %p %08x) stub\n", iface
, dwZone
, debugstr_guid(guidKey
),
1501 ppPolicy
, pcbPolicy
, ulrZoneReg
);
1505 /********************************************************************
1506 * IInternetZoneManager_SetZoneCustomPolicy
1508 static HRESULT WINAPI
ZoneMgrImpl_SetZoneCustomPolicy(IInternetZoneManagerEx2
* iface
,
1513 URLZONEREG ulrZoneReg
)
1515 FIXME("(%p)->(%08x %s %p %08x %08x) stub\n", iface
, dwZone
, debugstr_guid(guidKey
),
1516 ppPolicy
, cbPolicy
, ulrZoneReg
);
1520 /********************************************************************
1521 * IInternetZoneManager_GetZoneActionPolicy
1523 static HRESULT WINAPI
ZoneMgrImpl_GetZoneActionPolicy(IInternetZoneManagerEx2
* iface
,
1524 DWORD dwZone
, DWORD dwAction
, BYTE
* pPolicy
, DWORD cbPolicy
, URLZONEREG urlZoneReg
)
1526 TRACE("(%p)->(%d %08x %p %d %d)\n", iface
, dwZone
, dwAction
, pPolicy
,
1527 cbPolicy
, urlZoneReg
);
1530 return E_INVALIDARG
;
1532 return get_action_policy(dwZone
, dwAction
, pPolicy
, cbPolicy
, urlZoneReg
);
1535 /********************************************************************
1536 * IInternetZoneManager_SetZoneActionPolicy
1538 static HRESULT WINAPI
ZoneMgrImpl_SetZoneActionPolicy(IInternetZoneManagerEx2
* iface
,
1543 URLZONEREG urlZoneReg
)
1545 FIXME("(%p)->(%08x %08x %p %08x %08x) stub\n", iface
, dwZone
, dwAction
, pPolicy
,
1546 cbPolicy
, urlZoneReg
);
1550 /********************************************************************
1551 * IInternetZoneManager_PromptAction
1553 static HRESULT WINAPI
ZoneMgrImpl_PromptAction(IInternetZoneManagerEx2
* iface
,
1558 DWORD dwPromptFlags
)
1560 FIXME("%p %08x %p %s %s %08x\n", iface
, dwAction
, hwndParent
,
1561 debugstr_w(pwszUrl
), debugstr_w(pwszText
), dwPromptFlags
);
1565 /********************************************************************
1566 * IInternetZoneManager_LogAction
1568 static HRESULT WINAPI
ZoneMgrImpl_LogAction(IInternetZoneManagerEx2
* iface
,
1574 FIXME("(%p)->(%08x %s %s %08x) stub\n", iface
, dwAction
, debugstr_w(pwszUrl
),
1575 debugstr_w(pwszText
), dwLogFlags
);
1579 /********************************************************************
1580 * IInternetZoneManager_CreateZoneEnumerator
1582 static HRESULT WINAPI
ZoneMgrImpl_CreateZoneEnumerator(IInternetZoneManagerEx2
* iface
,
1587 ZoneMgrImpl
* This
= impl_from_IInternetZoneManagerEx2(iface
);
1592 TRACE("(%p)->(%p, %p, 0x%08x)\n", This
, pdwEnum
, pdwCount
, dwFlags
);
1593 if (!pdwEnum
|| !pdwCount
|| (dwFlags
!= 0))
1594 return E_INVALIDARG
;
1596 data
= build_zonemap_from_reg();
1597 TRACE("found %d zones\n", data
? data
[0] : -1);
1602 for (i
= 0; i
< This
->zonemap_count
; i
++) {
1603 if (This
->zonemaps
&& !This
->zonemaps
[i
]) {
1604 This
->zonemaps
[i
] = data
;
1606 *pdwCount
= data
[0];
1611 if (This
->zonemaps
) {
1612 /* try to double the nr. of pointers in the array */
1613 new_maps
= heap_realloc_zero(This
->zonemaps
, This
->zonemap_count
* 2 * sizeof(LPDWORD
));
1615 This
->zonemap_count
*= 2;
1619 This
->zonemap_count
= 2;
1620 new_maps
= heap_alloc_zero(This
->zonemap_count
* sizeof(LPDWORD
));
1627 This
->zonemaps
= new_maps
;
1628 This
->zonemaps
[i
] = data
;
1630 *pdwCount
= data
[0];
1634 /********************************************************************
1635 * IInternetZoneManager_GetZoneAt
1637 static HRESULT WINAPI
ZoneMgrImpl_GetZoneAt(IInternetZoneManagerEx2
* iface
,
1642 ZoneMgrImpl
* This
= impl_from_IInternetZoneManagerEx2(iface
);
1645 TRACE("(%p)->(0x%08x, %d, %p)\n", This
, dwEnum
, dwIndex
, pdwZone
);
1647 /* make sure, that dwEnum and dwIndex are in the valid range */
1648 if (dwEnum
< This
->zonemap_count
) {
1649 if ((data
= This
->zonemaps
[dwEnum
])) {
1650 if (dwIndex
< data
[0]) {
1651 *pdwZone
= data
[dwIndex
+ 1];
1656 return E_INVALIDARG
;
1659 /********************************************************************
1660 * IInternetZoneManager_DestroyZoneEnumerator
1662 static HRESULT WINAPI
ZoneMgrImpl_DestroyZoneEnumerator(IInternetZoneManagerEx2
* iface
,
1665 ZoneMgrImpl
* This
= impl_from_IInternetZoneManagerEx2(iface
);
1668 TRACE("(%p)->(0x%08x)\n", This
, dwEnum
);
1669 /* make sure, that dwEnum is valid */
1670 if (dwEnum
< This
->zonemap_count
) {
1671 if ((data
= This
->zonemaps
[dwEnum
])) {
1672 This
->zonemaps
[dwEnum
] = NULL
;
1677 return E_INVALIDARG
;
1680 /********************************************************************
1681 * IInternetZoneManager_CopyTemplatePoliciesToZone
1683 static HRESULT WINAPI
ZoneMgrImpl_CopyTemplatePoliciesToZone(IInternetZoneManagerEx2
* iface
,
1688 FIXME("(%p)->(%08x %08x %08x) stub\n", iface
, dwTemplate
, dwZone
, dwReserved
);
1692 /********************************************************************
1693 * IInternetZoneManagerEx_GetZoneActionPolicyEx
1695 static HRESULT WINAPI
ZoneMgrImpl_GetZoneActionPolicyEx(IInternetZoneManagerEx2
* iface
,
1700 URLZONEREG urlZoneReg
,
1703 TRACE("(%p)->(%d, 0x%x, %p, %d, %d, 0x%x)\n", iface
, dwZone
,
1704 dwAction
, pPolicy
, cbPolicy
, urlZoneReg
, dwFlags
);
1707 return E_INVALIDARG
;
1710 FIXME("dwFlags 0x%x ignored\n", dwFlags
);
1712 return get_action_policy(dwZone
, dwAction
, pPolicy
, cbPolicy
, urlZoneReg
);
1715 /********************************************************************
1716 * IInternetZoneManagerEx_SetZoneActionPolicyEx
1718 static HRESULT WINAPI
ZoneMgrImpl_SetZoneActionPolicyEx(IInternetZoneManagerEx2
* iface
,
1723 URLZONEREG urlZoneReg
,
1726 FIXME("(%p)->(%d, 0x%x, %p, %d, %d, 0x%x) stub\n", iface
, dwZone
, dwAction
, pPolicy
,
1727 cbPolicy
, urlZoneReg
, dwFlags
);
1731 /********************************************************************
1732 * IInternetZoneManagerEx2_GetZoneAttributesEx
1734 static HRESULT WINAPI
ZoneMgrImpl_GetZoneAttributesEx(IInternetZoneManagerEx2
* iface
,
1736 ZONEATTRIBUTES
* pZoneAttributes
,
1739 TRACE("(%p)->(%d, %p, 0x%x)\n", iface
, dwZone
, pZoneAttributes
, dwFlags
);
1742 FIXME("dwFlags 0x%x ignored\n", dwFlags
);
1744 return IInternetZoneManagerEx2_GetZoneAttributes(iface
, dwZone
, pZoneAttributes
);
1748 /********************************************************************
1749 * IInternetZoneManagerEx2_GetZoneSecurityState
1751 static HRESULT WINAPI
ZoneMgrImpl_GetZoneSecurityState(IInternetZoneManagerEx2
* iface
,
1753 BOOL fRespectPolicy
,
1755 BOOL
*pfPolicyEncountered
)
1757 FIXME("(%p)->(%d, %d, %p, %p) stub\n", iface
, dwZoneIndex
, fRespectPolicy
,
1758 pdwState
, pfPolicyEncountered
);
1760 *pdwState
= SECURITY_IE_STATE_GREEN
;
1762 if (pfPolicyEncountered
)
1763 *pfPolicyEncountered
= FALSE
;
1768 /********************************************************************
1769 * IInternetZoneManagerEx2_GetIESecurityState
1771 static HRESULT WINAPI
ZoneMgrImpl_GetIESecurityState(IInternetZoneManagerEx2
* iface
,
1772 BOOL fRespectPolicy
,
1774 BOOL
*pfPolicyEncountered
,
1777 FIXME("(%p)->(%d, %p, %p, %d) stub\n", iface
, fRespectPolicy
, pdwState
,
1778 pfPolicyEncountered
, fNoCache
);
1780 *pdwState
= SECURITY_IE_STATE_GREEN
;
1782 if (pfPolicyEncountered
)
1783 *pfPolicyEncountered
= FALSE
;
1788 /********************************************************************
1789 * IInternetZoneManagerEx2_FixInsecureSettings
1791 static HRESULT WINAPI
ZoneMgrImpl_FixInsecureSettings(IInternetZoneManagerEx2
* iface
)
1793 FIXME("(%p) stub\n", iface
);
1797 /********************************************************************
1798 * IInternetZoneManager_Construct
1800 static const IInternetZoneManagerEx2Vtbl ZoneMgrImplVtbl
= {
1801 ZoneMgrImpl_QueryInterface
,
1803 ZoneMgrImpl_Release
,
1804 /* IInternetZoneManager */
1805 ZoneMgrImpl_GetZoneAttributes
,
1806 ZoneMgrImpl_SetZoneAttributes
,
1807 ZoneMgrImpl_GetZoneCustomPolicy
,
1808 ZoneMgrImpl_SetZoneCustomPolicy
,
1809 ZoneMgrImpl_GetZoneActionPolicy
,
1810 ZoneMgrImpl_SetZoneActionPolicy
,
1811 ZoneMgrImpl_PromptAction
,
1812 ZoneMgrImpl_LogAction
,
1813 ZoneMgrImpl_CreateZoneEnumerator
,
1814 ZoneMgrImpl_GetZoneAt
,
1815 ZoneMgrImpl_DestroyZoneEnumerator
,
1816 ZoneMgrImpl_CopyTemplatePoliciesToZone
,
1817 /* IInternetZoneManagerEx */
1818 ZoneMgrImpl_GetZoneActionPolicyEx
,
1819 ZoneMgrImpl_SetZoneActionPolicyEx
,
1820 /* IInternetZoneManagerEx2 */
1821 ZoneMgrImpl_GetZoneAttributesEx
,
1822 ZoneMgrImpl_GetZoneSecurityState
,
1823 ZoneMgrImpl_GetIESecurityState
,
1824 ZoneMgrImpl_FixInsecureSettings
,
1827 HRESULT
ZoneMgrImpl_Construct(IUnknown
*pUnkOuter
, LPVOID
*ppobj
)
1829 ZoneMgrImpl
* ret
= heap_alloc_zero(sizeof(ZoneMgrImpl
));
1831 TRACE("(%p %p)\n", pUnkOuter
, ppobj
);
1832 ret
->IInternetZoneManagerEx2_iface
.lpVtbl
= &ZoneMgrImplVtbl
;
1834 *ppobj
= (IInternetZoneManagerEx
*)ret
;
1836 URLMON_LockModule();
1841 /***********************************************************************
1842 * CoInternetCreateSecurityManager (URLMON.@)
1845 HRESULT WINAPI
CoInternetCreateSecurityManager( IServiceProvider
*pSP
,
1846 IInternetSecurityManager
**ppSM
, DWORD dwReserved
)
1848 TRACE("%p %p %d\n", pSP
, ppSM
, dwReserved
);
1851 FIXME("pSP not supported\n");
1853 return SecManagerImpl_Construct(NULL
, (void**) ppSM
);
1856 /********************************************************************
1857 * CoInternetCreateZoneManager (URLMON.@)
1859 HRESULT WINAPI
CoInternetCreateZoneManager(IServiceProvider
* pSP
, IInternetZoneManager
** ppZM
, DWORD dwReserved
)
1861 TRACE("(%p %p %x)\n", pSP
, ppZM
, dwReserved
);
1862 return ZoneMgrImpl_Construct(NULL
, (void**)ppZM
);
1865 static HRESULT
parse_security_url(const WCHAR
*url
, PSUACTION action
, WCHAR
**result
) {
1866 IInternetProtocolInfo
*protocol_info
;
1867 WCHAR
*tmp
, *new_url
= NULL
, *alloc_url
= NULL
;
1868 DWORD size
, new_size
;
1869 HRESULT hres
= S_OK
, parse_hres
;
1872 TRACE("parsing %s\n", debugstr_w(url
));
1874 protocol_info
= get_protocol_info(url
);
1878 size
= strlenW(url
)+1;
1879 new_url
= CoTaskMemAlloc(size
*sizeof(WCHAR
));
1881 hres
= E_OUTOFMEMORY
;
1886 parse_hres
= IInternetProtocolInfo_ParseUrl(protocol_info
, url
, PARSE_SECURITY_URL
, 0, new_url
, size
, &new_size
, 0);
1887 if(parse_hres
== S_FALSE
) {
1889 hres
= E_UNEXPECTED
;
1893 tmp
= CoTaskMemRealloc(new_url
, new_size
*sizeof(WCHAR
));
1895 hres
= E_OUTOFMEMORY
;
1899 parse_hres
= IInternetProtocolInfo_ParseUrl(protocol_info
, url
, PARSE_SECURITY_URL
, 0, new_url
,
1900 new_size
, &new_size
, 0);
1901 if(parse_hres
== S_FALSE
) {
1907 if(parse_hres
!= S_OK
|| !strcmpW(url
, new_url
))
1910 CoTaskMemFree(alloc_url
);
1911 url
= alloc_url
= new_url
;
1915 CoTaskMemFree(new_url
);
1918 WARN("failed: %08x\n", hres
);
1919 CoTaskMemFree(alloc_url
);
1923 if(action
== PSU_DEFAULT
&& (protocol_info
= get_protocol_info(url
))) {
1924 size
= strlenW(url
)+1;
1925 new_url
= CoTaskMemAlloc(size
* sizeof(WCHAR
));
1928 parse_hres
= IInternetProtocolInfo_ParseUrl(protocol_info
, url
, PARSE_SECURITY_DOMAIN
, 0,
1929 new_url
, size
, &new_size
, 0);
1930 if(parse_hres
== S_FALSE
) {
1932 tmp
= CoTaskMemRealloc(new_url
, new_size
*sizeof(WCHAR
));
1935 parse_hres
= IInternetProtocolInfo_ParseUrl(protocol_info
, url
, PARSE_SECURITY_DOMAIN
, 0, new_url
,
1936 new_size
, &new_size
, 0);
1937 if(parse_hres
== S_FALSE
)
1940 hres
= E_OUTOFMEMORY
;
1943 hres
= E_UNEXPECTED
;
1947 if(hres
== S_OK
&& parse_hres
== S_OK
) {
1948 CoTaskMemFree(alloc_url
);
1949 url
= alloc_url
= new_url
;
1953 CoTaskMemFree(new_url
);
1955 hres
= E_OUTOFMEMORY
;
1957 IInternetProtocolInfo_Release(protocol_info
);
1961 WARN("failed %08x\n", hres
);
1962 CoTaskMemFree(alloc_url
);
1967 size
= strlenW(url
)+1;
1968 alloc_url
= CoTaskMemAlloc(size
* sizeof(WCHAR
));
1970 return E_OUTOFMEMORY
;
1971 memcpy(alloc_url
, url
, size
* sizeof(WCHAR
));
1974 *result
= alloc_url
;
1978 /********************************************************************
1979 * CoInternetGetSecurityUrl (URLMON.@)
1981 HRESULT WINAPI
CoInternetGetSecurityUrl(LPCWSTR pwzUrl
, LPWSTR
*ppwzSecUrl
, PSUACTION psuAction
, DWORD dwReserved
)
1986 TRACE("(%p,%p,%u,%u)\n", pwzUrl
, ppwzSecUrl
, psuAction
, dwReserved
);
1988 hres
= parse_security_url(pwzUrl
, psuAction
, &secure_url
);
1992 if(psuAction
!= PSU_SECURITY_URL_ONLY
) {
1993 PARSEDURLW parsed_url
= { sizeof(parsed_url
) };
1996 /* FIXME: Use helpers from uri.c */
1997 if(SUCCEEDED(ParseURLW(secure_url
, &parsed_url
))) {
2000 switch(parsed_url
.nScheme
) {
2001 case URL_SCHEME_FTP
:
2002 case URL_SCHEME_HTTP
:
2003 case URL_SCHEME_HTTPS
:
2004 size
= strlenW(secure_url
)+1;
2005 new_url
= CoTaskMemAlloc(size
* sizeof(WCHAR
));
2007 hres
= UrlGetPartW(secure_url
, new_url
, &size
, URL_PART_HOSTNAME
, URL_PARTFLAG_KEEPSCHEME
);
2009 hres
= E_OUTOFMEMORY
;
2010 CoTaskMemFree(secure_url
);
2012 WARN("UrlGetPart failed: %08x\n", hres
);
2013 CoTaskMemFree(new_url
);
2014 return FAILED(hres
) ? hres
: E_FAIL
;
2016 secure_url
= new_url
;
2021 *ppwzSecUrl
= secure_url
;
2025 /********************************************************************
2026 * CoInternetGetSecurityUrlEx (URLMON.@)
2028 HRESULT WINAPI
CoInternetGetSecurityUrlEx(IUri
*pUri
, IUri
**ppSecUri
, PSUACTION psuAction
, DWORD_PTR dwReserved
)
2030 URL_SCHEME scheme_type
;
2035 TRACE("(%p,%p,%u,%u)\n", pUri
, ppSecUri
, psuAction
, (DWORD
)dwReserved
);
2037 if(!pUri
|| !ppSecUri
)
2038 return E_INVALIDARG
;
2040 hres
= IUri_GetDisplayUri(pUri
, &secure_uri
);
2044 hres
= parse_security_url(secure_uri
, psuAction
, &ret_url
);
2045 SysFreeString(secure_uri
);
2049 /* File URIs have to hierarchical. */
2050 hres
= IUri_GetScheme(pUri
, (DWORD
*)&scheme_type
);
2051 if(SUCCEEDED(hres
) && scheme_type
== URL_SCHEME_FILE
) {
2052 const WCHAR
*tmp
= ret_url
;
2054 /* Check and see if a "//" is after the scheme name. */
2055 tmp
+= sizeof(fileW
)/sizeof(WCHAR
);
2056 if(*tmp
!= '/' || *(tmp
+1) != '/')
2057 hres
= E_INVALIDARG
;
2061 hres
= CreateUri(ret_url
, Uri_CREATE_ALLOW_IMPLICIT_WILDCARD_SCHEME
, 0, ppSecUri
);
2062 CoTaskMemFree(ret_url
);
2066 /********************************************************************
2067 * CompareSecurityIds (URLMON.@)
2069 HRESULT WINAPI
CompareSecurityIds(BYTE
*secid1
, DWORD size1
, BYTE
*secid2
, DWORD size2
, DWORD reserved
)
2071 FIXME("(%p %d %p %d %x)\n", secid1
, size1
, secid2
, size2
, reserved
);
2075 /********************************************************************
2076 * IsInternetESCEnabledLocal (URLMON.108)
2078 * Undocumented, returns TRUE if IE is running in Enhanced Security Configuration.
2080 BOOL WINAPI
IsInternetESCEnabledLocal(void)
2082 static BOOL esc_initialized
, esc_enabled
;
2086 if(!esc_initialized
) {
2087 DWORD type
, size
, val
;
2090 static const WCHAR iehardenW
[] = {'I','E','H','a','r','d','e','n',0};
2092 if(RegOpenKeyExW(HKEY_CURRENT_USER
, zone_map_keyW
, 0, KEY_QUERY_VALUE
, &zone_map
) == ERROR_SUCCESS
) {
2093 size
= sizeof(DWORD
);
2094 if(RegQueryValueExW(zone_map
, iehardenW
, NULL
, &type
, (BYTE
*)&val
, &size
) == ERROR_SUCCESS
)
2095 esc_enabled
= type
== REG_DWORD
&& val
!= 0;
2096 RegCloseKey(zone_map
);
2098 esc_initialized
= TRUE
;