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
24 #include "urlmon_main.h"
26 static const WCHAR currentlevelW
[] = {'C','u','r','r','e','n','t','L','e','v','e','l',0};
27 static const WCHAR descriptionW
[] = {'D','e','s','c','r','i','p','t','i','o','n',0};
28 static const WCHAR displaynameW
[] = {'D','i','s','p','l','a','y','N','a','m','e',0};
29 static const WCHAR fileW
[] = {'f','i','l','e',0};
30 static const WCHAR flagsW
[] = {'F','l','a','g','s',0};
31 static const WCHAR iconW
[] = {'I','c','o','n',0};
32 static const WCHAR minlevelW
[] = {'M','i','n','L','e','v','e','l',0};
33 static const WCHAR recommendedlevelW
[] = {'R','e','c','o','m','m','e','n','d','e','d',
34 'L','e','v','e','l',0};
35 static const WCHAR wszZonesKey
[] = {'S','o','f','t','w','a','r','e','\\',
36 'M','i','c','r','o','s','o','f','t','\\',
37 'W','i','n','d','o','w','s','\\',
38 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
39 'I','n','t','e','r','n','e','t',' ','S','e','t','t','i','n','g','s','\\',
40 'Z','o','n','e','s','\\',0};
41 static const WCHAR wszZoneMapDomainsKey
[] = {'S','o','f','t','w','a','r','e','\\',
42 'M','i','c','r','o','s','o','f','t','\\',
43 'W','i','n','d','o','w','s','\\',
44 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
45 'I','n','t','e','r','n','e','t',' ','S','e','t','t','i','n','g','s','\\',
46 'Z','o','n','e','M','a','p','\\',
47 'D','o','m','a','i','n','s',0};
49 static inline BOOL
is_drive_path(const WCHAR
*path
)
51 return isalphaW(*path
) && *(path
+1) == ':';
54 /* List of schemes types Windows seems to expect to be hierarchical. */
55 static inline BOOL
is_hierarchical_scheme(URL_SCHEME type
) {
56 return(type
== URL_SCHEME_HTTP
|| type
== URL_SCHEME_FTP
||
57 type
== URL_SCHEME_GOPHER
|| type
== URL_SCHEME_NNTP
||
58 type
== URL_SCHEME_TELNET
|| type
== URL_SCHEME_WAIS
||
59 type
== URL_SCHEME_FILE
|| type
== URL_SCHEME_HTTPS
||
60 type
== URL_SCHEME_RES
);
63 /********************************************************************
64 * get_string_from_reg [internal]
66 * helper to get a string from the reg.
69 static void get_string_from_reg(HKEY hcu
, HKEY hklm
, LPCWSTR name
, LPWSTR out
, DWORD maxlen
)
72 DWORD len
= maxlen
* sizeof(WCHAR
);
75 res
= RegQueryValueExW(hcu
, name
, NULL
, &type
, (LPBYTE
) out
, &len
);
78 len
= maxlen
* sizeof(WCHAR
);
80 res
= RegQueryValueExW(hklm
, name
, NULL
, &type
, (LPBYTE
) out
, &len
);
84 TRACE("%s failed: %d\n", debugstr_w(name
), res
);
89 /********************************************************************
90 * get_dword_from_reg [internal]
92 * helper to get a dword from the reg.
95 static void get_dword_from_reg(HKEY hcu
, HKEY hklm
, LPCWSTR name
, LPDWORD out
)
97 DWORD type
= REG_DWORD
;
98 DWORD len
= sizeof(DWORD
);
101 res
= RegQueryValueExW(hcu
, name
, NULL
, &type
, (LPBYTE
) out
, &len
);
106 res
= RegQueryValueExW(hklm
, name
, NULL
, &type
, (LPBYTE
) out
, &len
);
110 TRACE("%s failed: %d\n", debugstr_w(name
), res
);
115 static HRESULT
get_zone_from_reg(LPCWSTR schema
, DWORD
*zone
)
120 static const WCHAR wszZoneMapProtocolKey
[] =
121 {'S','o','f','t','w','a','r','e','\\',
122 'M','i','c','r','o','s','o','f','t','\\',
123 'W','i','n','d','o','w','s','\\',
124 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
125 'I','n','t','e','r','n','e','t',' ','S','e','t','t','i','n','g','s','\\',
126 'Z','o','n','e','M','a','p','\\',
127 'P','r','o','t','o','c','o','l','D','e','f','a','u','l','t','s',0};
129 res
= RegOpenKeyW(HKEY_CURRENT_USER
, wszZoneMapProtocolKey
, &hkey
);
130 if(res
!= ERROR_SUCCESS
) {
131 ERR("Could not open key %s\n", debugstr_w(wszZoneMapProtocolKey
));
135 size
= sizeof(DWORD
);
136 res
= RegQueryValueExW(hkey
, schema
, NULL
, NULL
, (PBYTE
)zone
, &size
);
138 if(res
== ERROR_SUCCESS
)
141 res
= RegOpenKeyW(HKEY_LOCAL_MACHINE
, wszZoneMapProtocolKey
, &hkey
);
142 if(res
!= ERROR_SUCCESS
) {
143 ERR("Could not open key %s\n", debugstr_w(wszZoneMapProtocolKey
));
147 size
= sizeof(DWORD
);
148 res
= RegQueryValueExW(hkey
, schema
, NULL
, NULL
, (PBYTE
)zone
, &size
);
150 if(res
== ERROR_SUCCESS
)
157 /********************************************************************
158 * matches_domain_pattern [internal]
160 * Checks if the given string matches the specified domain pattern.
162 * This function looks for explicit wildcard domain components iff
163 * they appear at the very beginning of the 'pattern' string
165 * pattern = "*.google.com"
167 static BOOL
matches_domain_pattern(LPCWSTR pattern
, LPCWSTR str
, BOOL implicit_wildcard
, LPCWSTR
*matched
)
169 BOOL matches
= FALSE
;
170 DWORD pattern_len
= strlenW(pattern
);
171 DWORD str_len
= strlenW(str
);
173 TRACE("(%d) Checking if %s matches %s\n", implicit_wildcard
, debugstr_w(str
), debugstr_w(pattern
));
176 if(str_len
>= pattern_len
) {
177 /* Check if there's an explicit wildcard in the pattern. */
178 if(pattern
[0] == '*' && pattern
[1] == '.') {
179 /* Make sure that 'str' matches the wildcard pattern.
182 * pattern = "*.google.com"
184 * So in this case 'str' would have to end with ".google.com" in order
185 * to map to this pattern.
187 if(str_len
>= pattern_len
+1 && !strcmpiW(str
+(str_len
-pattern_len
+1), pattern
+1)) {
188 /* Check if there's another '.' inside of the "unmatched" portion
192 * pattern = "*.google.com"
193 * str = "test.testing.google.com"
195 * The currently matched portion is ".google.com" in 'str', we need
196 * see if there's a '.' inside of the unmatched portion ("test.testing"), because
197 * if there is and 'implicit_wildcard' isn't set, then this isn't
201 if(str_len
> pattern_len
+1 && (ptr
= memrchrW(str
, '.', str_len
-pattern_len
-2))) {
202 if(implicit_wildcard
) {
211 } else if(implicit_wildcard
&& str_len
> pattern_len
) {
212 /* When the pattern has an implicit wildcard component, it means
213 * that anything goes in 'str' as long as it ends with the pattern
214 * and that the beginning of the match has a '.' before it.
217 * pattern = "google.com"
218 * str = "www.google.com"
220 * Implicitly matches the pattern, where as:
222 * pattern = "google.com"
223 * str = "wwwgoogle.com"
225 * Doesn't match the pattern.
227 if(str_len
> pattern_len
) {
228 if(str
[str_len
-pattern_len
-1] == '.' && !strcmpiW(str
+(str_len
-pattern_len
), pattern
)) {
230 *matched
= str
+(str_len
-pattern_len
);
234 /* The pattern doesn't have an implicit wildcard, or an explicit wildcard,
235 * so 'str' has to be an exact match to the 'pattern'.
237 if(!strcmpiW(str
, pattern
)) {
245 TRACE("Found a match: matched=%s\n", debugstr_w(*matched
));
247 TRACE("No match found\n");
252 static BOOL
get_zone_for_scheme(HKEY key
, LPCWSTR schema
, DWORD
*zone
)
254 static const WCHAR wildcardW
[] = {'*',0};
257 DWORD size
= sizeof(DWORD
);
260 /* See if the key contains a value for the scheme first. */
261 res
= RegQueryValueExW(key
, schema
, NULL
, &type
, (BYTE
*)zone
, &size
);
262 if(res
== ERROR_SUCCESS
) {
263 if(type
== REG_DWORD
)
265 WARN("Unexpected value type %d for value %s, expected REG_DWORD\n", type
, debugstr_w(schema
));
268 /* Try to get the zone for the wildcard scheme. */
269 size
= sizeof(DWORD
);
270 res
= RegQueryValueExW(key
, wildcardW
, NULL
, &type
, (BYTE
*)zone
, &size
);
271 if(res
!= ERROR_SUCCESS
)
274 if(type
!= REG_DWORD
) {
275 WARN("Unexpected value type %d for value %s, expected REG_DWORD\n", type
, debugstr_w(wildcardW
));
282 /********************************************************************
283 * search_domain_for_zone [internal]
285 * Searches the specified 'domain' registry key to see if 'host' maps into it, or any
286 * of it's subdomain registry keys.
288 * Returns S_OK if a match is found, S_FALSE if no matches were found, or an error code.
290 static HRESULT
search_domain_for_zone(HKEY domains
, LPCWSTR domain
, DWORD domain_len
, LPCWSTR schema
,
291 LPCWSTR host
, DWORD host_len
, DWORD
*zone
)
298 if(host_len
>= domain_len
&& matches_domain_pattern(domain
, host
, TRUE
, &matched
)) {
299 res
= RegOpenKeyW(domains
, domain
, &domain_key
);
300 if(res
!= ERROR_SUCCESS
) {
301 ERR("Failed to open domain key %s: %d\n", debugstr_w(domain
), res
);
306 found
= get_zone_for_scheme(domain_key
, schema
, zone
);
309 DWORD subdomain_count
, subdomain_len
;
310 BOOL check_domain
= TRUE
;
312 find_domain_name(domain
, domain_len
, &domain_offset
);
314 res
= RegQueryInfoKeyW(domain_key
, NULL
, NULL
, NULL
, &subdomain_count
, &subdomain_len
,
315 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
);
316 if(res
!= ERROR_SUCCESS
) {
317 ERR("Unable to query info for key %s: %d\n", debugstr_w(domain
), res
);
318 RegCloseKey(domain_key
);
322 if(subdomain_count
) {
327 subdomain
= heap_alloc((subdomain_len
+1)*sizeof(WCHAR
));
329 RegCloseKey(domain_key
);
330 return E_OUTOFMEMORY
;
333 component
= heap_strndupW(host
, matched
-host
-1);
335 heap_free(subdomain
);
336 RegCloseKey(domain_key
);
337 return E_OUTOFMEMORY
;
340 for(i
= 0; i
< subdomain_count
; ++i
) {
341 DWORD len
= subdomain_len
+1;
342 const WCHAR
*sub_matched
;
344 res
= RegEnumKeyExW(domain_key
, i
, subdomain
, &len
, NULL
, NULL
, NULL
, NULL
);
345 if(res
!= ERROR_SUCCESS
) {
346 heap_free(component
);
347 heap_free(subdomain
);
348 RegCloseKey(domain_key
);
352 if(matches_domain_pattern(subdomain
, component
, FALSE
, &sub_matched
)) {
355 res
= RegOpenKeyW(domain_key
, subdomain
, &subdomain_key
);
356 if(res
!= ERROR_SUCCESS
) {
357 ERR("Unable to open subdomain key %s of %s: %d\n", debugstr_w(subdomain
),
358 debugstr_w(domain
), res
);
359 heap_free(component
);
360 heap_free(subdomain
);
361 RegCloseKey(domain_key
);
365 found
= get_zone_for_scheme(subdomain_key
, schema
, zone
);
366 check_domain
= FALSE
;
367 RegCloseKey(subdomain_key
);
371 heap_free(subdomain
);
372 heap_free(component
);
375 /* There's a chance that 'host' implicitly mapped into 'domain', in
376 * which case we check to see if 'domain' contains zone information.
378 * This can only happen if 'domain' is it's own domain name.
380 * "google.com" (domain name = "google.com")
383 * host = "www.google.com"
385 * Then host would map directly into the "google.com" domain key.
387 * If 'domain' has more than just it's domain name, or it does not
388 * have a domain name, then we don't perform the check. The reason
389 * for this is that these domains don't allow implicit mappings.
391 * domain = "org" (has no domain name)
394 * The mapping would only happen if the "org" key had an explicit subkey
397 if(check_domain
&& !domain_offset
&& !strchrW(host
, matched
-host
-1))
398 found
= get_zone_for_scheme(domain_key
, schema
, zone
);
400 RegCloseKey(domain_key
);
403 return found
? S_OK
: S_FALSE
;
406 static HRESULT
search_for_domain_mapping(HKEY domains
, LPCWSTR schema
, LPCWSTR host
, DWORD host_len
, DWORD
*zone
)
409 DWORD domain_count
, domain_len
, i
;
411 HRESULT hres
= S_FALSE
;
413 res
= RegQueryInfoKeyW(domains
, NULL
, NULL
, NULL
, &domain_count
, &domain_len
,
414 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
);
415 if(res
!= ERROR_SUCCESS
) {
416 WARN("Failed to retrieve information about key\n");
423 domain
= heap_alloc((domain_len
+1)*sizeof(WCHAR
));
425 return E_OUTOFMEMORY
;
427 for(i
= 0; i
< domain_count
; ++i
) {
428 DWORD len
= domain_len
+1;
430 res
= RegEnumKeyExW(domains
, i
, domain
, &len
, NULL
, NULL
, NULL
, NULL
);
431 if(res
!= ERROR_SUCCESS
) {
436 hres
= search_domain_for_zone(domains
, domain
, len
, schema
, host
, host_len
, zone
);
437 if(FAILED(hres
) || hres
== S_OK
)
445 static HRESULT
get_zone_from_domains(IUri
*uri
, DWORD
*zone
)
453 hres
= IUri_GetScheme(uri
, &scheme_type
);
457 /* Windows doesn't play nice with unknown scheme types when it tries
458 * to check if a host name maps into any domains.
460 if(scheme_type
== URL_SCHEME_UNKNOWN
)
463 hres
= IUri_GetHost(uri
, &host
);
467 /* Known hierarchical scheme types must have a host. If they don't Windows
468 * assigns URLZONE_INVALID to the zone.
470 if((scheme_type
!= URL_SCHEME_UNKNOWN
&& scheme_type
!= URL_SCHEME_FILE
)
471 && is_hierarchical_scheme(scheme_type
) && !*host
) {
472 *zone
= URLZONE_INVALID
;
476 /* The MapUrlToZone functions return S_OK when this condition occurs. */
480 hres
= IUri_GetSchemeName(uri
, &scheme
);
486 /* First try CURRENT_USER. */
487 res
= RegOpenKeyW(HKEY_CURRENT_USER
, wszZoneMapDomainsKey
, &domains
);
488 if(res
== ERROR_SUCCESS
) {
489 hres
= search_for_domain_mapping(domains
, scheme
, host
, SysStringLen(host
), zone
);
490 RegCloseKey(domains
);
492 WARN("Failed to open HKCU's %s key\n", debugstr_w(wszZoneMapDomainsKey
));
494 /* If that doesn't work try LOCAL_MACHINE. */
495 if(hres
== S_FALSE
) {
496 res
= RegOpenKeyW(HKEY_LOCAL_MACHINE
, wszZoneMapDomainsKey
, &domains
);
497 if(res
== ERROR_SUCCESS
) {
498 hres
= search_for_domain_mapping(domains
, scheme
, host
, SysStringLen(host
), zone
);
499 RegCloseKey(domains
);
501 WARN("Failed to open HKLM's %s key\n", debugstr_w(wszZoneMapDomainsKey
));
505 SysFreeString(scheme
);
509 static HRESULT
map_security_uri_to_zone(IUri
*uri
, DWORD
*zone
)
514 *zone
= URLZONE_INVALID
;
516 hres
= IUri_GetSchemeName(uri
, &scheme
);
520 if(!strcmpiW(scheme
, fileW
)) {
522 WCHAR
*ptr
, *path_start
, root
[20];
524 hres
= IUri_GetPath(uri
, &path
);
526 SysFreeString(scheme
);
530 if(*path
== '/' && is_drive_path(path
+1))
535 if((ptr
= strchrW(path_start
, ':')) && ptr
-path_start
+1 < sizeof(root
)/sizeof(WCHAR
)) {
538 memcpy(root
, path_start
, (ptr
-path_start
+1)*sizeof(WCHAR
));
539 root
[ptr
-path_start
+1] = 0;
541 type
= GetDriveTypeW(root
);
545 case DRIVE_NO_ROOT_DIR
:
547 case DRIVE_REMOVABLE
:
551 *zone
= URLZONE_LOCAL_MACHINE
;
555 *zone
= URLZONE_INTERNET
;
559 FIXME("unsupported drive type %d\n", type
);
565 if(*zone
== URLZONE_INVALID
) {
566 hres
= get_zone_from_domains(uri
, zone
);
568 hres
= get_zone_from_reg(scheme
, zone
);
571 SysFreeString(scheme
);
575 static HRESULT
map_url_to_zone(LPCWSTR url
, DWORD
*zone
, LPWSTR
*ret_url
)
581 *zone
= URLZONE_INVALID
;
583 hres
= CoInternetGetSecurityUrl(url
, &secur_url
, PSU_SECURITY_URL_ONLY
, 0);
585 DWORD size
= strlenW(url
)*sizeof(WCHAR
);
587 secur_url
= CoTaskMemAlloc(size
);
589 return E_OUTOFMEMORY
;
591 memcpy(secur_url
, url
, size
);
594 hres
= CreateUri(secur_url
, Uri_CREATE_ALLOW_IMPLICIT_FILE_SCHEME
, 0, &secur_uri
);
596 CoTaskMemFree(secur_url
);
600 hres
= map_security_uri_to_zone(secur_uri
, zone
);
601 IUri_Release(secur_uri
);
603 if(FAILED(hres
) || !ret_url
)
604 CoTaskMemFree(secur_url
);
606 *ret_url
= secur_url
;
611 static HRESULT
map_uri_to_zone(IUri
*uri
, DWORD
*zone
, IUri
**ret_uri
)
616 hres
= CoInternetGetSecurityUrlEx(uri
, &secur_uri
, PSU_SECURITY_URL_ONLY
, 0);
620 hres
= map_security_uri_to_zone(secur_uri
, zone
);
621 if(FAILED(hres
) || !ret_uri
)
622 IUri_Release(secur_uri
);
624 *ret_uri
= secur_uri
;
629 static HRESULT
open_zone_key(HKEY parent_key
, DWORD zone
, HKEY
*hkey
)
631 static const WCHAR wszFormat
[] = {'%','s','%','u',0};
633 WCHAR key_name
[sizeof(wszZonesKey
)/sizeof(WCHAR
)+12];
636 wsprintfW(key_name
, wszFormat
, wszZonesKey
, zone
);
638 res
= RegOpenKeyW(parent_key
, key_name
, hkey
);
640 if(res
!= ERROR_SUCCESS
) {
641 WARN("RegOpenKey failed\n");
648 static HRESULT
get_action_policy(DWORD zone
, DWORD action
, BYTE
*policy
, DWORD size
, URLZONEREG zone_reg
)
656 case URLACTION_SCRIPT_OVERRIDE_SAFETY
:
657 case URLACTION_ACTIVEX_OVERRIDE_SCRIPT_SAFETY
:
658 *(DWORD
*)policy
= URLPOLICY_DISALLOW
;
663 case URLZONEREG_DEFAULT
:
664 case URLZONEREG_HKCU
:
665 parent_key
= HKEY_CURRENT_USER
;
667 case URLZONEREG_HKLM
:
668 parent_key
= HKEY_LOCAL_MACHINE
;
671 WARN("Unknown URLZONEREG: %d\n", zone_reg
);
675 hres
= open_zone_key(parent_key
, zone
, &hkey
);
676 if(SUCCEEDED(hres
)) {
677 WCHAR action_str
[16];
680 static const WCHAR formatW
[] = {'%','X',0};
682 wsprintfW(action_str
, formatW
, action
);
684 res
= RegQueryValueExW(hkey
, action_str
, NULL
, NULL
, policy
, &len
);
685 if(res
== ERROR_MORE_DATA
) {
687 }else if(res
== ERROR_FILE_NOT_FOUND
) {
689 }else if(res
!= ERROR_SUCCESS
) {
690 ERR("RegQueryValue failed: %d\n", res
);
697 if(FAILED(hres
) && zone_reg
== URLZONEREG_DEFAULT
)
698 return get_action_policy(zone
, action
, policy
, size
, URLZONEREG_HKLM
);
703 static HRESULT
generate_security_id(IUri
*uri
, BYTE
*secid
, DWORD
*secid_len
, DWORD zone
)
709 if(zone
== URLZONE_INVALID
)
712 hres
= IUri_GetScheme(uri
, &scheme_type
);
716 /* Windows handles opaque URLs differently then hierarchical ones. */
717 if(!is_hierarchical_scheme(scheme_type
) && scheme_type
!= URL_SCHEME_WILDCARD
) {
720 hres
= IUri_GetDisplayUri(uri
, &display_uri
);
724 len
= WideCharToMultiByte(CP_ACP
, 0, display_uri
, -1, NULL
, 0, NULL
, NULL
)-1;
726 if(len
+sizeof(DWORD
) > *secid_len
) {
727 SysFreeString(display_uri
);
728 return HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER
);
731 WideCharToMultiByte(CP_ACP
, 0, display_uri
, -1, (LPSTR
)secid
, len
, NULL
, NULL
);
732 SysFreeString(display_uri
);
734 *(DWORD
*)(secid
+len
) = zone
;
737 DWORD host_len
, scheme_len
;
740 hres
= IUri_GetHost(uri
, &host
);
744 /* The host can't be empty for Wildcard URIs. */
745 if(scheme_type
== URL_SCHEME_WILDCARD
&& !*host
) {
750 hres
= IUri_GetSchemeName(uri
, &scheme
);
756 host_len
= WideCharToMultiByte(CP_ACP
, 0, host
, -1, NULL
, 0, NULL
, NULL
)-1;
757 scheme_len
= WideCharToMultiByte(CP_ACP
, 0, scheme
, -1, NULL
, 0, NULL
, NULL
)-1;
759 len
= host_len
+scheme_len
+sizeof(BYTE
);
761 if(len
+sizeof(DWORD
) > *secid_len
) {
763 SysFreeString(scheme
);
764 return HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER
);
767 WideCharToMultiByte(CP_ACP
, 0, scheme
, -1, (LPSTR
)secid
, len
, NULL
, NULL
);
768 SysFreeString(scheme
);
770 ptr
= secid
+scheme_len
;
773 WideCharToMultiByte(CP_ACP
, 0, host
, -1, (LPSTR
)ptr
, host_len
, NULL
, NULL
);
781 *secid_len
= len
+sizeof(DWORD
);
786 static HRESULT
get_security_id_for_url(LPCWSTR url
, BYTE
*secid
, DWORD
*secid_len
)
789 DWORD zone
= URLZONE_INVALID
;
790 LPWSTR secur_url
= NULL
;
793 hres
= map_url_to_zone(url
, &zone
, &secur_url
);
795 return hres
== 0x80041001 ? E_INVALIDARG
: hres
;
797 hres
= CreateUri(secur_url
, Uri_CREATE_ALLOW_IMPLICIT_FILE_SCHEME
, 0, &uri
);
798 CoTaskMemFree(secur_url
);
802 hres
= generate_security_id(uri
, secid
, secid_len
, zone
);
808 static HRESULT
get_security_id_for_uri(IUri
*uri
, BYTE
*secid
, DWORD
*secid_len
)
812 DWORD zone
= URLZONE_INVALID
;
814 hres
= map_uri_to_zone(uri
, &zone
, &secur_uri
);
818 hres
= generate_security_id(secur_uri
, secid
, secid_len
, zone
);
819 IUri_Release(secur_uri
);
824 /***********************************************************************
825 * InternetSecurityManager implementation
829 IInternetSecurityManagerEx2 IInternetSecurityManagerEx2_iface
;
833 IInternetSecurityMgrSite
*mgrsite
;
834 IInternetSecurityManager
*custom_manager
;
837 static inline SecManagerImpl
*impl_from_IInternetSecurityManagerEx2(IInternetSecurityManagerEx2
*iface
)
839 return CONTAINING_RECORD(iface
, SecManagerImpl
, IInternetSecurityManagerEx2_iface
);
842 static HRESULT WINAPI
SecManagerImpl_QueryInterface(IInternetSecurityManagerEx2
* iface
,REFIID riid
,void** ppvObject
)
844 SecManagerImpl
*This
= impl_from_IInternetSecurityManagerEx2(iface
);
846 TRACE("(%p)->(%s %p)\n",This
,debugstr_guid(riid
),ppvObject
);
851 if(IsEqualIID(&IID_IUnknown
, riid
) ||
852 IsEqualIID(&IID_IInternetSecurityManager
, riid
) ||
853 IsEqualIID(&IID_IInternetSecurityManagerEx
, riid
) ||
854 IsEqualIID(&IID_IInternetSecurityManagerEx2
, riid
)) {
857 WARN("not supported interface %s\n", debugstr_guid(riid
));
859 return E_NOINTERFACE
;
862 IInternetSecurityManagerEx2_AddRef(iface
);
866 static ULONG WINAPI
SecManagerImpl_AddRef(IInternetSecurityManagerEx2
* iface
)
868 SecManagerImpl
*This
= impl_from_IInternetSecurityManagerEx2(iface
);
869 ULONG refCount
= InterlockedIncrement(&This
->ref
);
871 TRACE("(%p) ref=%u\n", This
, refCount
);
876 static ULONG WINAPI
SecManagerImpl_Release(IInternetSecurityManagerEx2
* iface
)
878 SecManagerImpl
*This
= impl_from_IInternetSecurityManagerEx2(iface
);
879 ULONG refCount
= InterlockedDecrement(&This
->ref
);
881 TRACE("(%p) ref=%u\n", This
, refCount
);
883 /* destroy the object if there's no more reference on it */
886 IInternetSecurityMgrSite_Release(This
->mgrsite
);
887 if(This
->custom_manager
)
888 IInternetSecurityManager_Release(This
->custom_manager
);
892 URLMON_UnlockModule();
898 static HRESULT WINAPI
SecManagerImpl_SetSecuritySite(IInternetSecurityManagerEx2
*iface
,
899 IInternetSecurityMgrSite
*pSite
)
901 SecManagerImpl
*This
= impl_from_IInternetSecurityManagerEx2(iface
);
903 TRACE("(%p)->(%p)\n", This
, pSite
);
906 IInternetSecurityMgrSite_Release(This
->mgrsite
);
908 if(This
->custom_manager
) {
909 IInternetSecurityManager_Release(This
->custom_manager
);
910 This
->custom_manager
= NULL
;
913 This
->mgrsite
= pSite
;
916 IServiceProvider
*servprov
;
919 IInternetSecurityMgrSite_AddRef(pSite
);
921 hres
= IInternetSecurityMgrSite_QueryInterface(pSite
, &IID_IServiceProvider
,
923 if(SUCCEEDED(hres
)) {
924 IServiceProvider_QueryService(servprov
, &SID_SInternetSecurityManager
,
925 &IID_IInternetSecurityManager
, (void**)&This
->custom_manager
);
926 IServiceProvider_Release(servprov
);
933 static HRESULT WINAPI
SecManagerImpl_GetSecuritySite(IInternetSecurityManagerEx2
*iface
,
934 IInternetSecurityMgrSite
**ppSite
)
936 SecManagerImpl
*This
= impl_from_IInternetSecurityManagerEx2(iface
);
938 TRACE("(%p)->(%p)\n", This
, ppSite
);
944 IInternetSecurityMgrSite_AddRef(This
->mgrsite
);
946 *ppSite
= This
->mgrsite
;
950 static HRESULT WINAPI
SecManagerImpl_MapUrlToZone(IInternetSecurityManagerEx2
*iface
,
951 LPCWSTR pwszUrl
, DWORD
*pdwZone
,
954 SecManagerImpl
*This
= impl_from_IInternetSecurityManagerEx2(iface
);
957 TRACE("(%p)->(%s %p %08x)\n", iface
, debugstr_w(pwszUrl
), pdwZone
, dwFlags
);
959 if(This
->custom_manager
) {
960 hres
= IInternetSecurityManager_MapUrlToZone(This
->custom_manager
,
961 pwszUrl
, pdwZone
, dwFlags
);
962 if(hres
!= INET_E_DEFAULT_ACTION
)
967 *pdwZone
= URLZONE_INVALID
;
972 FIXME("not supported flags: %08x\n", dwFlags
);
974 return map_url_to_zone(pwszUrl
, pdwZone
, NULL
);
977 static HRESULT WINAPI
SecManagerImpl_GetSecurityId(IInternetSecurityManagerEx2
*iface
,
978 LPCWSTR pwszUrl
, BYTE
*pbSecurityId
, DWORD
*pcbSecurityId
, DWORD_PTR dwReserved
)
980 SecManagerImpl
*This
= impl_from_IInternetSecurityManagerEx2(iface
);
982 TRACE("(%p)->(%s %p %p %08lx)\n", iface
, debugstr_w(pwszUrl
), pbSecurityId
,
983 pcbSecurityId
, dwReserved
);
985 if(This
->custom_manager
) {
988 hres
= IInternetSecurityManager_GetSecurityId(This
->custom_manager
,
989 pwszUrl
, pbSecurityId
, pcbSecurityId
, dwReserved
);
990 if(hres
!= INET_E_DEFAULT_ACTION
)
994 if(!pwszUrl
|| !pbSecurityId
|| !pcbSecurityId
)
998 FIXME("dwReserved is not supported\n");
1000 return get_security_id_for_url(pwszUrl
, pbSecurityId
, pcbSecurityId
);
1004 static HRESULT WINAPI
SecManagerImpl_ProcessUrlAction(IInternetSecurityManagerEx2
*iface
,
1005 LPCWSTR pwszUrl
, DWORD dwAction
,
1006 BYTE
*pPolicy
, DWORD cbPolicy
,
1007 BYTE
*pContext
, DWORD cbContext
,
1008 DWORD dwFlags
, DWORD dwReserved
)
1010 SecManagerImpl
*This
= impl_from_IInternetSecurityManagerEx2(iface
);
1014 TRACE("(%p)->(%s %08x %p %08x %p %08x %08x %08x)\n", iface
, debugstr_w(pwszUrl
), dwAction
,
1015 pPolicy
, cbPolicy
, pContext
, cbContext
, dwFlags
, dwReserved
);
1017 if(This
->custom_manager
) {
1018 hres
= IInternetSecurityManager_ProcessUrlAction(This
->custom_manager
, pwszUrl
, dwAction
,
1019 pPolicy
, cbPolicy
, pContext
, cbContext
, dwFlags
, dwReserved
);
1020 if(hres
!= INET_E_DEFAULT_ACTION
)
1024 if(dwFlags
|| dwReserved
)
1025 FIXME("Unsupported arguments\n");
1028 return E_INVALIDARG
;
1030 hres
= map_url_to_zone(pwszUrl
, &zone
, NULL
);
1034 hres
= get_action_policy(zone
, dwAction
, (BYTE
*)&policy
, sizeof(policy
), URLZONEREG_DEFAULT
);
1038 TRACE("policy %x\n", policy
);
1039 if(cbPolicy
>= sizeof(DWORD
))
1040 *(DWORD
*)pPolicy
= policy
;
1042 switch(GetUrlPolicyPermissions(policy
)) {
1043 case URLPOLICY_ALLOW
:
1044 case URLPOLICY_CHANNEL_SOFTDIST_PRECACHE
:
1046 case URLPOLICY_DISALLOW
:
1048 case URLPOLICY_QUERY
:
1049 FIXME("URLPOLICY_QUERY not implemented\n");
1052 FIXME("Not implemented policy %x\n", policy
);
1059 static HRESULT WINAPI
SecManagerImpl_QueryCustomPolicy(IInternetSecurityManagerEx2
*iface
,
1060 LPCWSTR pwszUrl
, REFGUID guidKey
,
1061 BYTE
**ppPolicy
, DWORD
*pcbPolicy
,
1062 BYTE
*pContext
, DWORD cbContext
,
1065 SecManagerImpl
*This
= impl_from_IInternetSecurityManagerEx2(iface
);
1068 TRACE("(%p)->(%s %s %p %p %p %08x %08x )\n", iface
, debugstr_w(pwszUrl
), debugstr_guid(guidKey
),
1069 ppPolicy
, pcbPolicy
, pContext
, cbContext
, dwReserved
);
1071 if(This
->custom_manager
) {
1072 hres
= IInternetSecurityManager_QueryCustomPolicy(This
->custom_manager
, pwszUrl
, guidKey
,
1073 ppPolicy
, pcbPolicy
, pContext
, cbContext
, dwReserved
);
1074 if(hres
!= INET_E_DEFAULT_ACTION
)
1078 WARN("Unknown guidKey %s\n", debugstr_guid(guidKey
));
1079 return HRESULT_FROM_WIN32(ERROR_NOT_FOUND
);
1082 static HRESULT WINAPI
SecManagerImpl_SetZoneMapping(IInternetSecurityManagerEx2
*iface
,
1083 DWORD dwZone
, LPCWSTR pwszPattern
, DWORD dwFlags
)
1085 SecManagerImpl
*This
= impl_from_IInternetSecurityManagerEx2(iface
);
1088 TRACE("(%p)->(%08x %s %08x)\n", iface
, dwZone
, debugstr_w(pwszPattern
),dwFlags
);
1090 if(This
->custom_manager
) {
1091 hres
= IInternetSecurityManager_SetZoneMapping(This
->custom_manager
, dwZone
,
1092 pwszPattern
, dwFlags
);
1093 if(hres
!= INET_E_DEFAULT_ACTION
)
1097 FIXME("Default action is not implemented\n");
1101 static HRESULT WINAPI
SecManagerImpl_GetZoneMappings(IInternetSecurityManagerEx2
*iface
,
1102 DWORD dwZone
, IEnumString
**ppenumString
, DWORD dwFlags
)
1104 SecManagerImpl
*This
= impl_from_IInternetSecurityManagerEx2(iface
);
1107 TRACE("(%p)->(%08x %p %08x)\n", iface
, dwZone
, ppenumString
,dwFlags
);
1109 if(This
->custom_manager
) {
1110 hres
= IInternetSecurityManager_GetZoneMappings(This
->custom_manager
, dwZone
,
1111 ppenumString
, dwFlags
);
1112 if(hres
!= INET_E_DEFAULT_ACTION
)
1116 FIXME("Default action is not implemented\n");
1120 static HRESULT WINAPI
SecManagerImpl_ProcessUrlActionEx(IInternetSecurityManagerEx2
*iface
,
1121 LPCWSTR pwszUrl
, DWORD dwAction
, BYTE
*pPolicy
, DWORD cbPolicy
, BYTE
*pContext
, DWORD cbContext
,
1122 DWORD dwFlags
, DWORD dwReserved
, DWORD
*pdwOutFlags
)
1124 SecManagerImpl
*This
= impl_from_IInternetSecurityManagerEx2(iface
);
1125 FIXME("(%p)->(%s %08x %p %d %p %d %08x %08x %p) stub\n", This
, debugstr_w(pwszUrl
), dwAction
, pPolicy
, cbPolicy
,
1126 pContext
, cbContext
, dwFlags
, dwReserved
, pdwOutFlags
);
1130 static HRESULT WINAPI
SecManagerImpl_MapUrlToZoneEx2(IInternetSecurityManagerEx2
*iface
,
1131 IUri
*pUri
, DWORD
*pdwZone
, DWORD dwFlags
, LPWSTR
*ppwszMappedUrl
, DWORD
*pdwOutFlags
)
1133 SecManagerImpl
*This
= impl_from_IInternetSecurityManagerEx2(iface
);
1135 TRACE("(%p)->(%p %p %08x %p %p)\n", This
, pUri
, pdwZone
, dwFlags
, ppwszMappedUrl
, pdwOutFlags
);
1137 if(This
->custom_manager
) {
1139 IInternetSecurityManagerEx2
*sec_mgr2
;
1141 hres
= IInternetSecurityManager_QueryInterface(This
->custom_manager
, &IID_IInternetSecurityManagerEx2
,
1143 if(SUCCEEDED(hres
)) {
1144 hres
= IInternetSecurityManagerEx2_MapUrlToZoneEx2(sec_mgr2
, pUri
, pdwZone
, dwFlags
, ppwszMappedUrl
, pdwOutFlags
);
1145 IInternetSecurityManagerEx2_Release(sec_mgr2
);
1149 hres
= IUri_GetDisplayUri(pUri
, &url
);
1153 hres
= IInternetSecurityManager_MapUrlToZone(This
->custom_manager
, url
, pdwZone
, dwFlags
);
1157 if(hres
!= INET_E_DEFAULT_ACTION
)
1162 return E_INVALIDARG
;
1165 *pdwZone
= URLZONE_INVALID
;
1166 return E_INVALIDARG
;
1170 FIXME("Unsupported flags: %08x\n", dwFlags
);
1172 return map_uri_to_zone(pUri
, pdwZone
, NULL
);
1175 static HRESULT WINAPI
SecManagerImpl_ProcessUrlActionEx2(IInternetSecurityManagerEx2
*iface
,
1176 IUri
*pUri
, DWORD dwAction
, BYTE
*pPolicy
, DWORD cbPolicy
, BYTE
*pContext
, DWORD cbContext
,
1177 DWORD dwFlags
, DWORD_PTR dwReserved
, DWORD
*pdwOutFlags
)
1179 SecManagerImpl
*This
= impl_from_IInternetSecurityManagerEx2(iface
);
1180 FIXME("(%p)->(%p %08x %p %d %p %d %08x %08x %p) stub\n", This
, pUri
, dwAction
, pPolicy
,
1181 cbPolicy
, pContext
, cbContext
, dwFlags
, (DWORD
)dwReserved
, pdwOutFlags
);
1185 static HRESULT WINAPI
SecManagerImpl_GetSecurityIdEx2(IInternetSecurityManagerEx2
*iface
,
1186 IUri
*pUri
, BYTE
*pbSecurityId
, DWORD
*pcbSecurityId
, DWORD_PTR dwReserved
)
1188 SecManagerImpl
*This
= impl_from_IInternetSecurityManagerEx2(iface
);
1189 TRACE("(%p)->(%p %p %p %08x) stub\n", This
, pUri
, pbSecurityId
, pcbSecurityId
, (DWORD
)dwReserved
);
1192 FIXME("dwReserved is not supported yet\n");
1194 if(!pUri
|| !pcbSecurityId
|| !pbSecurityId
)
1195 return E_INVALIDARG
;
1197 return get_security_id_for_uri(pUri
, pbSecurityId
, pcbSecurityId
);
1200 static HRESULT WINAPI
SecManagerImpl_QueryCustomPolicyEx2(IInternetSecurityManagerEx2
*iface
,
1201 IUri
*pUri
, REFGUID guidKey
, BYTE
**ppPolicy
, DWORD
*pcbPolicy
, BYTE
*pContext
,
1202 DWORD cbContext
, DWORD_PTR dwReserved
)
1204 SecManagerImpl
*This
= impl_from_IInternetSecurityManagerEx2(iface
);
1205 FIXME("(%p)->(%p %s %p %p %p %d %08x) stub\n", This
, pUri
, debugstr_guid(guidKey
), ppPolicy
, pcbPolicy
,
1206 pContext
, cbContext
, (DWORD
)dwReserved
);
1210 static const IInternetSecurityManagerEx2Vtbl VT_SecManagerImpl
=
1212 SecManagerImpl_QueryInterface
,
1213 SecManagerImpl_AddRef
,
1214 SecManagerImpl_Release
,
1215 SecManagerImpl_SetSecuritySite
,
1216 SecManagerImpl_GetSecuritySite
,
1217 SecManagerImpl_MapUrlToZone
,
1218 SecManagerImpl_GetSecurityId
,
1219 SecManagerImpl_ProcessUrlAction
,
1220 SecManagerImpl_QueryCustomPolicy
,
1221 SecManagerImpl_SetZoneMapping
,
1222 SecManagerImpl_GetZoneMappings
,
1223 SecManagerImpl_ProcessUrlActionEx
,
1224 SecManagerImpl_MapUrlToZoneEx2
,
1225 SecManagerImpl_ProcessUrlActionEx2
,
1226 SecManagerImpl_GetSecurityIdEx2
,
1227 SecManagerImpl_QueryCustomPolicyEx2
1230 HRESULT
SecManagerImpl_Construct(IUnknown
*pUnkOuter
, LPVOID
*ppobj
)
1232 SecManagerImpl
*This
;
1234 TRACE("(%p,%p)\n",pUnkOuter
,ppobj
);
1235 This
= heap_alloc(sizeof(*This
));
1237 /* Initialize the virtual function table. */
1238 This
->IInternetSecurityManagerEx2_iface
.lpVtbl
= &VT_SecManagerImpl
;
1241 This
->mgrsite
= NULL
;
1242 This
->custom_manager
= NULL
;
1246 URLMON_LockModule();
1251 /***********************************************************************
1252 * InternetZoneManager implementation
1256 IInternetZoneManagerEx2 IInternetZoneManagerEx2_iface
;
1259 DWORD zonemap_count
;
1262 static inline ZoneMgrImpl
*impl_from_IInternetZoneManagerEx2(IInternetZoneManagerEx2
*iface
)
1264 return CONTAINING_RECORD(iface
, ZoneMgrImpl
, IInternetZoneManagerEx2_iface
);
1268 /***********************************************************************
1269 * build_zonemap_from_reg [internal]
1271 * Enumerate the Zones in the Registry and return the Zones in a DWORD-array
1272 * The number of the Zones is returned in data[0]
1274 static LPDWORD
build_zonemap_from_reg(void)
1278 LPDWORD data
= NULL
;
1279 DWORD allocated
= 6; /* space for the zonecount and Zone "0" up to Zone "4" */
1285 res
= RegOpenKeyW(HKEY_CURRENT_USER
, wszZonesKey
, &hkey
);
1289 data
= heap_alloc(allocated
* sizeof(DWORD
));
1295 len
= sizeof(name
) / sizeof(name
[0]);
1296 res
= RegEnumKeyExW(hkey
, used
, name
, &len
, NULL
, NULL
, NULL
, NULL
);
1300 if (used
== allocated
) {
1304 new_data
= heap_realloc_zero(data
, allocated
* sizeof(DWORD
));
1310 data
[used
] = atoiW(name
);
1320 /* something failed */
1326 /********************************************************************
1327 * IInternetZoneManager_QueryInterface
1329 static HRESULT WINAPI
ZoneMgrImpl_QueryInterface(IInternetZoneManagerEx2
* iface
, REFIID riid
, void** ppvObject
)
1331 ZoneMgrImpl
* This
= impl_from_IInternetZoneManagerEx2(iface
);
1333 TRACE("(%p)->(%s,%p)\n", This
, debugstr_guid(riid
), ppvObject
);
1335 if(!This
|| !ppvObject
)
1336 return E_INVALIDARG
;
1338 if(IsEqualIID(&IID_IUnknown
, riid
)) {
1339 TRACE("(%p)->(IID_IUnknown %p)\n", This
, ppvObject
);
1340 }else if(IsEqualIID(&IID_IInternetZoneManager
, riid
)) {
1341 TRACE("(%p)->(IID_InternetZoneManager %p)\n", This
, ppvObject
);
1342 }else if(IsEqualIID(&IID_IInternetZoneManagerEx
, riid
)) {
1343 TRACE("(%p)->(IID_InternetZoneManagerEx %p)\n", This
, ppvObject
);
1344 }else if(IsEqualIID(&IID_IInternetZoneManagerEx2
, riid
)) {
1345 TRACE("(%p)->(IID_InternetZoneManagerEx2 %p)\n", This
, ppvObject
);
1349 FIXME("Unknown interface: %s\n", debugstr_guid(riid
));
1351 return E_NOINTERFACE
;
1355 IInternetZoneManagerEx2_AddRef(iface
);
1359 /********************************************************************
1360 * IInternetZoneManager_AddRef
1362 static ULONG WINAPI
ZoneMgrImpl_AddRef(IInternetZoneManagerEx2
* iface
)
1364 ZoneMgrImpl
* This
= impl_from_IInternetZoneManagerEx2(iface
);
1365 ULONG refCount
= InterlockedIncrement(&This
->ref
);
1367 TRACE("(%p)->(ref before=%u)\n",This
, refCount
- 1);
1372 /********************************************************************
1373 * IInternetZoneManager_Release
1375 static ULONG WINAPI
ZoneMgrImpl_Release(IInternetZoneManagerEx2
* iface
)
1377 ZoneMgrImpl
* This
= impl_from_IInternetZoneManagerEx2(iface
);
1378 ULONG refCount
= InterlockedDecrement(&This
->ref
);
1380 TRACE("(%p)->(ref before=%u)\n",This
, refCount
+ 1);
1383 while (This
->zonemap_count
) heap_free(This
->zonemaps
[--This
->zonemap_count
]);
1384 heap_free(This
->zonemaps
);
1386 URLMON_UnlockModule();
1392 /********************************************************************
1393 * IInternetZoneManager_GetZoneAttributes
1395 static HRESULT WINAPI
ZoneMgrImpl_GetZoneAttributes(IInternetZoneManagerEx2
* iface
,
1397 ZONEATTRIBUTES
* pZoneAttributes
)
1399 ZoneMgrImpl
* This
= impl_from_IInternetZoneManagerEx2(iface
);
1404 TRACE("(%p)->(%d %p)\n", This
, dwZone
, pZoneAttributes
);
1406 if (!pZoneAttributes
)
1407 return E_INVALIDARG
;
1409 hr
= open_zone_key(HKEY_CURRENT_USER
, dwZone
, &hcu
);
1411 return S_OK
; /* IE6 and older returned E_FAIL here */
1413 hr
= open_zone_key(HKEY_LOCAL_MACHINE
, dwZone
, &hklm
);
1415 TRACE("Zone %d not in HKLM\n", dwZone
);
1417 get_string_from_reg(hcu
, hklm
, displaynameW
, pZoneAttributes
->szDisplayName
, MAX_ZONE_PATH
);
1418 get_string_from_reg(hcu
, hklm
, descriptionW
, pZoneAttributes
->szDescription
, MAX_ZONE_DESCRIPTION
);
1419 get_string_from_reg(hcu
, hklm
, iconW
, pZoneAttributes
->szIconPath
, MAX_ZONE_PATH
);
1420 get_dword_from_reg(hcu
, hklm
, minlevelW
, &pZoneAttributes
->dwTemplateMinLevel
);
1421 get_dword_from_reg(hcu
, hklm
, currentlevelW
, &pZoneAttributes
->dwTemplateCurrentLevel
);
1422 get_dword_from_reg(hcu
, hklm
, recommendedlevelW
, &pZoneAttributes
->dwTemplateRecommended
);
1423 get_dword_from_reg(hcu
, hklm
, flagsW
, &pZoneAttributes
->dwFlags
);
1430 /********************************************************************
1431 * IInternetZoneManager_SetZoneAttributes
1433 static HRESULT WINAPI
ZoneMgrImpl_SetZoneAttributes(IInternetZoneManagerEx2
* iface
,
1435 ZONEATTRIBUTES
* pZoneAttributes
)
1437 ZoneMgrImpl
* This
= impl_from_IInternetZoneManagerEx2(iface
);
1441 TRACE("(%p)->(%d %p)\n", This
, dwZone
, pZoneAttributes
);
1443 if (!pZoneAttributes
)
1444 return E_INVALIDARG
;
1446 hr
= open_zone_key(HKEY_CURRENT_USER
, dwZone
, &hcu
);
1448 return S_OK
; /* IE6 returned E_FAIL here */
1450 /* cbSize is ignored */
1451 RegSetValueExW(hcu
, displaynameW
, 0, REG_SZ
, (LPBYTE
) pZoneAttributes
->szDisplayName
,
1452 (lstrlenW(pZoneAttributes
->szDisplayName
)+1)* sizeof(WCHAR
));
1454 RegSetValueExW(hcu
, descriptionW
, 0, REG_SZ
, (LPBYTE
) pZoneAttributes
->szDescription
,
1455 (lstrlenW(pZoneAttributes
->szDescription
)+1)* sizeof(WCHAR
));
1457 RegSetValueExW(hcu
, iconW
, 0, REG_SZ
, (LPBYTE
) pZoneAttributes
->szIconPath
,
1458 (lstrlenW(pZoneAttributes
->szIconPath
)+1)* sizeof(WCHAR
));
1460 RegSetValueExW(hcu
, minlevelW
, 0, REG_DWORD
,
1461 (const BYTE
*) &pZoneAttributes
->dwTemplateMinLevel
, sizeof(DWORD
));
1463 RegSetValueExW(hcu
, currentlevelW
, 0, REG_DWORD
,
1464 (const BYTE
*) &pZoneAttributes
->dwTemplateCurrentLevel
, sizeof(DWORD
));
1466 RegSetValueExW(hcu
, recommendedlevelW
, 0, REG_DWORD
,
1467 (const BYTE
*) &pZoneAttributes
->dwTemplateRecommended
, sizeof(DWORD
));
1469 RegSetValueExW(hcu
, flagsW
, 0, REG_DWORD
, (const BYTE
*) &pZoneAttributes
->dwFlags
, sizeof(DWORD
));
1475 /********************************************************************
1476 * IInternetZoneManager_GetZoneCustomPolicy
1478 static HRESULT WINAPI
ZoneMgrImpl_GetZoneCustomPolicy(IInternetZoneManagerEx2
* iface
,
1483 URLZONEREG ulrZoneReg
)
1485 FIXME("(%p)->(%08x %s %p %p %08x) stub\n", iface
, dwZone
, debugstr_guid(guidKey
),
1486 ppPolicy
, pcbPolicy
, ulrZoneReg
);
1490 /********************************************************************
1491 * IInternetZoneManager_SetZoneCustomPolicy
1493 static HRESULT WINAPI
ZoneMgrImpl_SetZoneCustomPolicy(IInternetZoneManagerEx2
* iface
,
1498 URLZONEREG ulrZoneReg
)
1500 FIXME("(%p)->(%08x %s %p %08x %08x) stub\n", iface
, dwZone
, debugstr_guid(guidKey
),
1501 ppPolicy
, cbPolicy
, ulrZoneReg
);
1505 /********************************************************************
1506 * IInternetZoneManager_GetZoneActionPolicy
1508 static HRESULT WINAPI
ZoneMgrImpl_GetZoneActionPolicy(IInternetZoneManagerEx2
* iface
,
1509 DWORD dwZone
, DWORD dwAction
, BYTE
* pPolicy
, DWORD cbPolicy
, URLZONEREG urlZoneReg
)
1511 TRACE("(%p)->(%d %08x %p %d %d)\n", iface
, dwZone
, dwAction
, pPolicy
,
1512 cbPolicy
, urlZoneReg
);
1515 return E_INVALIDARG
;
1517 return get_action_policy(dwZone
, dwAction
, pPolicy
, cbPolicy
, urlZoneReg
);
1520 /********************************************************************
1521 * IInternetZoneManager_SetZoneActionPolicy
1523 static HRESULT WINAPI
ZoneMgrImpl_SetZoneActionPolicy(IInternetZoneManagerEx2
* iface
,
1528 URLZONEREG urlZoneReg
)
1530 FIXME("(%p)->(%08x %08x %p %08x %08x) stub\n", iface
, dwZone
, dwAction
, pPolicy
,
1531 cbPolicy
, urlZoneReg
);
1535 /********************************************************************
1536 * IInternetZoneManager_PromptAction
1538 static HRESULT WINAPI
ZoneMgrImpl_PromptAction(IInternetZoneManagerEx2
* iface
,
1543 DWORD dwPromptFlags
)
1545 FIXME("%p %08x %p %s %s %08x\n", iface
, dwAction
, hwndParent
,
1546 debugstr_w(pwszUrl
), debugstr_w(pwszText
), dwPromptFlags
);
1550 /********************************************************************
1551 * IInternetZoneManager_LogAction
1553 static HRESULT WINAPI
ZoneMgrImpl_LogAction(IInternetZoneManagerEx2
* iface
,
1559 FIXME("(%p)->(%08x %s %s %08x) stub\n", iface
, dwAction
, debugstr_w(pwszUrl
),
1560 debugstr_w(pwszText
), dwLogFlags
);
1564 /********************************************************************
1565 * IInternetZoneManager_CreateZoneEnumerator
1567 static HRESULT WINAPI
ZoneMgrImpl_CreateZoneEnumerator(IInternetZoneManagerEx2
* iface
,
1572 ZoneMgrImpl
* This
= impl_from_IInternetZoneManagerEx2(iface
);
1577 TRACE("(%p)->(%p, %p, 0x%08x)\n", This
, pdwEnum
, pdwCount
, dwFlags
);
1578 if (!pdwEnum
|| !pdwCount
|| (dwFlags
!= 0))
1579 return E_INVALIDARG
;
1581 data
= build_zonemap_from_reg();
1582 TRACE("found %d zones\n", data
? data
[0] : -1);
1587 for (i
= 0; i
< This
->zonemap_count
; i
++) {
1588 if (This
->zonemaps
&& !This
->zonemaps
[i
]) {
1589 This
->zonemaps
[i
] = data
;
1591 *pdwCount
= data
[0];
1596 if (This
->zonemaps
) {
1597 /* try to double the nr. of pointers in the array */
1598 new_maps
= heap_realloc_zero(This
->zonemaps
, This
->zonemap_count
* 2 * sizeof(LPDWORD
));
1600 This
->zonemap_count
*= 2;
1604 This
->zonemap_count
= 2;
1605 new_maps
= heap_alloc_zero(This
->zonemap_count
* sizeof(LPDWORD
));
1612 This
->zonemaps
= new_maps
;
1613 This
->zonemaps
[i
] = data
;
1615 *pdwCount
= data
[0];
1619 /********************************************************************
1620 * IInternetZoneManager_GetZoneAt
1622 static HRESULT WINAPI
ZoneMgrImpl_GetZoneAt(IInternetZoneManagerEx2
* iface
,
1627 ZoneMgrImpl
* This
= impl_from_IInternetZoneManagerEx2(iface
);
1630 TRACE("(%p)->(0x%08x, %d, %p)\n", This
, dwEnum
, dwIndex
, pdwZone
);
1632 /* make sure, that dwEnum and dwIndex are in the valid range */
1633 if (dwEnum
< This
->zonemap_count
) {
1634 if ((data
= This
->zonemaps
[dwEnum
])) {
1635 if (dwIndex
< data
[0]) {
1636 *pdwZone
= data
[dwIndex
+ 1];
1641 return E_INVALIDARG
;
1644 /********************************************************************
1645 * IInternetZoneManager_DestroyZoneEnumerator
1647 static HRESULT WINAPI
ZoneMgrImpl_DestroyZoneEnumerator(IInternetZoneManagerEx2
* iface
,
1650 ZoneMgrImpl
* This
= impl_from_IInternetZoneManagerEx2(iface
);
1653 TRACE("(%p)->(0x%08x)\n", This
, dwEnum
);
1654 /* make sure, that dwEnum is valid */
1655 if (dwEnum
< This
->zonemap_count
) {
1656 if ((data
= This
->zonemaps
[dwEnum
])) {
1657 This
->zonemaps
[dwEnum
] = NULL
;
1662 return E_INVALIDARG
;
1665 /********************************************************************
1666 * IInternetZoneManager_CopyTemplatePoliciesToZone
1668 static HRESULT WINAPI
ZoneMgrImpl_CopyTemplatePoliciesToZone(IInternetZoneManagerEx2
* iface
,
1673 FIXME("(%p)->(%08x %08x %08x) stub\n", iface
, dwTemplate
, dwZone
, dwReserved
);
1677 /********************************************************************
1678 * IInternetZoneManagerEx_GetZoneActionPolicyEx
1680 static HRESULT WINAPI
ZoneMgrImpl_GetZoneActionPolicyEx(IInternetZoneManagerEx2
* iface
,
1685 URLZONEREG urlZoneReg
,
1688 TRACE("(%p)->(%d, 0x%x, %p, %d, %d, 0x%x)\n", iface
, dwZone
,
1689 dwAction
, pPolicy
, cbPolicy
, urlZoneReg
, dwFlags
);
1692 return E_INVALIDARG
;
1695 FIXME("dwFlags 0x%x ignored\n", dwFlags
);
1697 return get_action_policy(dwZone
, dwAction
, pPolicy
, cbPolicy
, urlZoneReg
);
1700 /********************************************************************
1701 * IInternetZoneManagerEx_SetZoneActionPolicyEx
1703 static HRESULT WINAPI
ZoneMgrImpl_SetZoneActionPolicyEx(IInternetZoneManagerEx2
* iface
,
1708 URLZONEREG urlZoneReg
,
1711 FIXME("(%p)->(%d, 0x%x, %p, %d, %d, 0x%x) stub\n", iface
, dwZone
, dwAction
, pPolicy
,
1712 cbPolicy
, urlZoneReg
, dwFlags
);
1716 /********************************************************************
1717 * IInternetZoneManagerEx2_GetZoneAttributesEx
1719 static HRESULT WINAPI
ZoneMgrImpl_GetZoneAttributesEx(IInternetZoneManagerEx2
* iface
,
1721 ZONEATTRIBUTES
* pZoneAttributes
,
1724 TRACE("(%p)->(%d, %p, 0x%x)\n", iface
, dwZone
, pZoneAttributes
, dwFlags
);
1727 FIXME("dwFlags 0x%x ignored\n", dwFlags
);
1729 return IInternetZoneManagerEx2_GetZoneAttributes(iface
, dwZone
, pZoneAttributes
);
1733 /********************************************************************
1734 * IInternetZoneManagerEx2_GetZoneSecurityState
1736 static HRESULT WINAPI
ZoneMgrImpl_GetZoneSecurityState(IInternetZoneManagerEx2
* iface
,
1738 BOOL fRespectPolicy
,
1740 BOOL
*pfPolicyEncountered
)
1742 FIXME("(%p)->(%d, %d, %p, %p) stub\n", iface
, dwZoneIndex
, fRespectPolicy
,
1743 pdwState
, pfPolicyEncountered
);
1745 *pdwState
= SECURITY_IE_STATE_GREEN
;
1747 if (pfPolicyEncountered
)
1748 *pfPolicyEncountered
= FALSE
;
1753 /********************************************************************
1754 * IInternetZoneManagerEx2_GetIESecurityState
1756 static HRESULT WINAPI
ZoneMgrImpl_GetIESecurityState(IInternetZoneManagerEx2
* iface
,
1757 BOOL fRespectPolicy
,
1759 BOOL
*pfPolicyEncountered
,
1762 FIXME("(%p)->(%d, %p, %p, %d) stub\n", iface
, fRespectPolicy
, pdwState
,
1763 pfPolicyEncountered
, fNoCache
);
1765 *pdwState
= SECURITY_IE_STATE_GREEN
;
1767 if (pfPolicyEncountered
)
1768 *pfPolicyEncountered
= FALSE
;
1773 /********************************************************************
1774 * IInternetZoneManagerEx2_FixInsecureSettings
1776 static HRESULT WINAPI
ZoneMgrImpl_FixInsecureSettings(IInternetZoneManagerEx2
* iface
)
1778 FIXME("(%p) stub\n", iface
);
1782 /********************************************************************
1783 * IInternetZoneManager_Construct
1785 static const IInternetZoneManagerEx2Vtbl ZoneMgrImplVtbl
= {
1786 ZoneMgrImpl_QueryInterface
,
1788 ZoneMgrImpl_Release
,
1789 /* IInternetZoneManager */
1790 ZoneMgrImpl_GetZoneAttributes
,
1791 ZoneMgrImpl_SetZoneAttributes
,
1792 ZoneMgrImpl_GetZoneCustomPolicy
,
1793 ZoneMgrImpl_SetZoneCustomPolicy
,
1794 ZoneMgrImpl_GetZoneActionPolicy
,
1795 ZoneMgrImpl_SetZoneActionPolicy
,
1796 ZoneMgrImpl_PromptAction
,
1797 ZoneMgrImpl_LogAction
,
1798 ZoneMgrImpl_CreateZoneEnumerator
,
1799 ZoneMgrImpl_GetZoneAt
,
1800 ZoneMgrImpl_DestroyZoneEnumerator
,
1801 ZoneMgrImpl_CopyTemplatePoliciesToZone
,
1802 /* IInternetZoneManagerEx */
1803 ZoneMgrImpl_GetZoneActionPolicyEx
,
1804 ZoneMgrImpl_SetZoneActionPolicyEx
,
1805 /* IInternetZoneManagerEx2 */
1806 ZoneMgrImpl_GetZoneAttributesEx
,
1807 ZoneMgrImpl_GetZoneSecurityState
,
1808 ZoneMgrImpl_GetIESecurityState
,
1809 ZoneMgrImpl_FixInsecureSettings
,
1812 HRESULT
ZoneMgrImpl_Construct(IUnknown
*pUnkOuter
, LPVOID
*ppobj
)
1814 ZoneMgrImpl
* ret
= heap_alloc_zero(sizeof(ZoneMgrImpl
));
1816 TRACE("(%p %p)\n", pUnkOuter
, ppobj
);
1817 ret
->IInternetZoneManagerEx2_iface
.lpVtbl
= &ZoneMgrImplVtbl
;
1819 *ppobj
= (IInternetZoneManagerEx
*)ret
;
1821 URLMON_LockModule();
1826 /***********************************************************************
1827 * CoInternetCreateSecurityManager (URLMON.@)
1830 HRESULT WINAPI
CoInternetCreateSecurityManager( IServiceProvider
*pSP
,
1831 IInternetSecurityManager
**ppSM
, DWORD dwReserved
)
1833 TRACE("%p %p %d\n", pSP
, ppSM
, dwReserved
);
1836 FIXME("pSP not supported\n");
1838 return SecManagerImpl_Construct(NULL
, (void**) ppSM
);
1841 /********************************************************************
1842 * CoInternetCreateZoneManager (URLMON.@)
1844 HRESULT WINAPI
CoInternetCreateZoneManager(IServiceProvider
* pSP
, IInternetZoneManager
** ppZM
, DWORD dwReserved
)
1846 TRACE("(%p %p %x)\n", pSP
, ppZM
, dwReserved
);
1847 return ZoneMgrImpl_Construct(NULL
, (void**)ppZM
);
1850 static HRESULT
parse_security_url(const WCHAR
*url
, PSUACTION action
, WCHAR
**result
) {
1851 IInternetProtocolInfo
*protocol_info
;
1852 WCHAR
*tmp
, *new_url
= NULL
, *alloc_url
= NULL
;
1853 DWORD size
, new_size
;
1854 HRESULT hres
= S_OK
, parse_hres
;
1857 TRACE("parsing %s\n", debugstr_w(url
));
1859 protocol_info
= get_protocol_info(url
);
1863 size
= strlenW(url
)+1;
1864 new_url
= CoTaskMemAlloc(size
*sizeof(WCHAR
));
1866 hres
= E_OUTOFMEMORY
;
1871 parse_hres
= IInternetProtocolInfo_ParseUrl(protocol_info
, url
, PARSE_SECURITY_URL
, 0, new_url
, size
, &new_size
, 0);
1872 if(parse_hres
== S_FALSE
) {
1874 hres
= E_UNEXPECTED
;
1878 tmp
= CoTaskMemRealloc(new_url
, new_size
*sizeof(WCHAR
));
1880 hres
= E_OUTOFMEMORY
;
1884 parse_hres
= IInternetProtocolInfo_ParseUrl(protocol_info
, url
, PARSE_SECURITY_URL
, 0, new_url
,
1885 new_size
, &new_size
, 0);
1886 if(parse_hres
== S_FALSE
) {
1892 if(parse_hres
!= S_OK
|| !strcmpW(url
, new_url
))
1895 CoTaskMemFree(alloc_url
);
1896 url
= alloc_url
= new_url
;
1900 CoTaskMemFree(new_url
);
1903 WARN("failed: %08x\n", hres
);
1904 CoTaskMemFree(alloc_url
);
1908 if(action
== PSU_DEFAULT
&& (protocol_info
= get_protocol_info(url
))) {
1909 size
= strlenW(url
)+1;
1910 new_url
= CoTaskMemAlloc(size
* sizeof(WCHAR
));
1913 parse_hres
= IInternetProtocolInfo_ParseUrl(protocol_info
, url
, PARSE_SECURITY_DOMAIN
, 0,
1914 new_url
, size
, &new_size
, 0);
1915 if(parse_hres
== S_FALSE
) {
1917 tmp
= CoTaskMemRealloc(new_url
, new_size
*sizeof(WCHAR
));
1920 parse_hres
= IInternetProtocolInfo_ParseUrl(protocol_info
, url
, PARSE_SECURITY_DOMAIN
, 0, new_url
,
1921 new_size
, &new_size
, 0);
1922 if(parse_hres
== S_FALSE
)
1925 hres
= E_OUTOFMEMORY
;
1928 hres
= E_UNEXPECTED
;
1932 if(hres
== S_OK
&& parse_hres
== S_OK
) {
1933 CoTaskMemFree(alloc_url
);
1934 url
= alloc_url
= new_url
;
1938 CoTaskMemFree(new_url
);
1940 hres
= E_OUTOFMEMORY
;
1942 IInternetProtocolInfo_Release(protocol_info
);
1946 WARN("failed %08x\n", hres
);
1947 CoTaskMemFree(alloc_url
);
1952 size
= strlenW(url
)+1;
1953 alloc_url
= CoTaskMemAlloc(size
* sizeof(WCHAR
));
1955 return E_OUTOFMEMORY
;
1956 memcpy(alloc_url
, url
, size
* sizeof(WCHAR
));
1959 *result
= alloc_url
;
1963 /********************************************************************
1964 * CoInternetGetSecurityUrl (URLMON.@)
1966 HRESULT WINAPI
CoInternetGetSecurityUrl(LPCWSTR pwzUrl
, LPWSTR
*ppwzSecUrl
, PSUACTION psuAction
, DWORD dwReserved
)
1971 TRACE("(%p,%p,%u,%u)\n", pwzUrl
, ppwzSecUrl
, psuAction
, dwReserved
);
1973 hres
= parse_security_url(pwzUrl
, psuAction
, &secure_url
);
1977 if(psuAction
!= PSU_SECURITY_URL_ONLY
) {
1978 PARSEDURLW parsed_url
= { sizeof(parsed_url
) };
1981 /* FIXME: Use helpers from uri.c */
1982 if(SUCCEEDED(ParseURLW(secure_url
, &parsed_url
))) {
1985 switch(parsed_url
.nScheme
) {
1986 case URL_SCHEME_FTP
:
1987 case URL_SCHEME_HTTP
:
1988 case URL_SCHEME_HTTPS
:
1989 size
= strlenW(secure_url
)+1;
1990 new_url
= CoTaskMemAlloc(size
* sizeof(WCHAR
));
1992 hres
= UrlGetPartW(secure_url
, new_url
, &size
, URL_PART_HOSTNAME
, URL_PARTFLAG_KEEPSCHEME
);
1994 hres
= E_OUTOFMEMORY
;
1995 CoTaskMemFree(secure_url
);
1997 WARN("UrlGetPart failed: %08x\n", hres
);
1998 CoTaskMemFree(new_url
);
1999 return FAILED(hres
) ? hres
: E_FAIL
;
2001 secure_url
= new_url
;
2006 *ppwzSecUrl
= secure_url
;
2010 /********************************************************************
2011 * CoInternetGetSecurityUrlEx (URLMON.@)
2013 HRESULT WINAPI
CoInternetGetSecurityUrlEx(IUri
*pUri
, IUri
**ppSecUri
, PSUACTION psuAction
, DWORD_PTR dwReserved
)
2015 URL_SCHEME scheme_type
;
2020 TRACE("(%p,%p,%u,%u)\n", pUri
, ppSecUri
, psuAction
, (DWORD
)dwReserved
);
2022 if(!pUri
|| !ppSecUri
)
2023 return E_INVALIDARG
;
2025 hres
= IUri_GetDisplayUri(pUri
, &secure_uri
);
2029 hres
= parse_security_url(secure_uri
, psuAction
, &ret_url
);
2030 SysFreeString(secure_uri
);
2034 /* File URIs have to hierarchical. */
2035 hres
= IUri_GetScheme(pUri
, (DWORD
*)&scheme_type
);
2036 if(SUCCEEDED(hres
) && scheme_type
== URL_SCHEME_FILE
) {
2037 const WCHAR
*tmp
= ret_url
;
2039 /* Check and see if a "//" is after the scheme name. */
2040 tmp
+= sizeof(fileW
)/sizeof(WCHAR
);
2041 if(*tmp
!= '/' || *(tmp
+1) != '/')
2042 hres
= E_INVALIDARG
;
2046 hres
= CreateUri(ret_url
, Uri_CREATE_ALLOW_IMPLICIT_WILDCARD_SCHEME
, 0, ppSecUri
);
2047 CoTaskMemFree(ret_url
);
2051 /********************************************************************
2052 * CompareSecurityIds (URLMON.@)
2054 HRESULT WINAPI
CompareSecurityIds(BYTE
*secid1
, DWORD size1
, BYTE
*secid2
, DWORD size2
, DWORD reserved
)
2056 FIXME("(%p %d %p %d %x)\n", secid1
, size1
, secid2
, size2
, reserved
);