Commit 269fe5a4 authored by Thomas Mullaly's avatar Thomas Mullaly Committed by Alexandre Julliard

urlmon: Added basic GetSecurityIdEx2 implementation.

parent 714941f8
...@@ -619,7 +619,7 @@ static HRESULT map_url_to_zone(LPCWSTR url, DWORD *zone, LPWSTR *ret_url) ...@@ -619,7 +619,7 @@ static HRESULT map_url_to_zone(LPCWSTR url, DWORD *zone, LPWSTR *ret_url)
return hres; return hres;
} }
static HRESULT map_uri_to_zone(IUri *uri, DWORD *zone) static HRESULT map_uri_to_zone(IUri *uri, DWORD *zone, IUri **ret_uri)
{ {
HRESULT hres; HRESULT hres;
IUri *secur_uri; IUri *secur_uri;
...@@ -629,7 +629,10 @@ static HRESULT map_uri_to_zone(IUri *uri, DWORD *zone) ...@@ -629,7 +629,10 @@ static HRESULT map_uri_to_zone(IUri *uri, DWORD *zone)
return hres; return hres;
hres = map_security_uri_to_zone(secur_uri, zone); hres = map_security_uri_to_zone(secur_uri, zone);
IUri_Release(secur_uri); if(FAILED(hres) || !ret_uri)
IUri_Release(secur_uri);
else
*ret_uri = secur_uri;
return hres; return hres;
} }
...@@ -708,69 +711,127 @@ static HRESULT get_action_policy(DWORD zone, DWORD action, BYTE *policy, DWORD s ...@@ -708,69 +711,127 @@ static HRESULT get_action_policy(DWORD zone, DWORD action, BYTE *policy, DWORD s
return hres; return hres;
} }
static HRESULT get_security_id(LPCWSTR url, BYTE *secid, DWORD *secid_len) static HRESULT generate_security_id(IUri *uri, BYTE *secid, DWORD *secid_len, DWORD zone)
{ {
LPWSTR secur_url, ptr, ptr2; DWORD len;
DWORD zone, len;
HRESULT hres; HRESULT hres;
DWORD scheme_type;
static const WCHAR wszFile[] = {'f','i','l','e',':'};
hres = map_url_to_zone(url, &zone, &secur_url);
if(zone == URLZONE_INVALID) if(zone == URLZONE_INVALID)
return (hres == 0x80041001 || hres == S_OK) ? E_INVALIDARG : hres; return E_INVALIDARG;
hres = IUri_GetScheme(uri, &scheme_type);
if(FAILED(hres))
return hres;
/* Windows handles opaque URLs differently then hierarchical ones. */
if(!is_hierarchical_scheme(scheme_type) && scheme_type != URL_SCHEME_WILDCARD) {
BSTR display_uri;
/* file protocol is a special case */ hres = IUri_GetDisplayUri(uri, &display_uri);
if(strlenW(secur_url) >= sizeof(wszFile)/sizeof(WCHAR) if(FAILED(hres))
&& !memcmp(secur_url, wszFile, sizeof(wszFile))) { return hres;
WCHAR path[MAX_PATH];
len = sizeof(path)/sizeof(WCHAR);
hres = CoInternetParseUrl(secur_url, PARSE_PATH_FROM_URL, 0, path, len, &len, 0); len = WideCharToMultiByte(CP_ACP, 0, display_uri, -1, NULL, 0, NULL, NULL)-1;
if(hres == S_OK && !PathIsNetworkPathW(path)) {
static const BYTE secidFile[] = {'f','i','l','e',':'};
CoTaskMemFree(secur_url); if(len+sizeof(DWORD) > *secid_len) {
SysFreeString(display_uri);
return HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER);
}
if(*secid_len < sizeof(secidFile)+sizeof(zone)) WideCharToMultiByte(CP_ACP, 0, display_uri, -1, (LPSTR)secid, len, NULL, NULL);
return HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER); SysFreeString(display_uri);
memcpy(secid, secidFile, sizeof(secidFile)); *(DWORD*)(secid+len) = zone;
*(DWORD*)(secid+sizeof(secidFile)) = zone; } else {
BSTR host, scheme;
DWORD host_len, scheme_len;
BYTE *ptr;
*secid_len = sizeof(secidFile)+sizeof(zone); hres = IUri_GetHost(uri, &host);
return S_OK; if(FAILED(hres))
return hres;
/* The host can't be empty for Wildcard URIs. */
if(scheme_type == URL_SCHEME_WILDCARD && !*host) {
SysFreeString(host);
return E_INVALIDARG;
} }
}
ptr = strchrW(secur_url, ':'); hres = IUri_GetSchemeName(uri, &scheme);
ptr2 = ++ptr; if(FAILED(hres)) {
while(*ptr2 == '/') SysFreeString(host);
ptr2++; return hres;
if(ptr2 != ptr) }
memmove(ptr, ptr2, (strlenW(ptr2)+1)*sizeof(WCHAR));
ptr = strchrW(ptr, '/'); host_len = WideCharToMultiByte(CP_ACP, 0, host, -1, NULL, 0, NULL, NULL)-1;
if(ptr) scheme_len = WideCharToMultiByte(CP_ACP, 0, scheme, -1, NULL, 0, NULL, NULL)-1;
*ptr = 0;
len = WideCharToMultiByte(CP_ACP, 0, secur_url, -1, NULL, 0, NULL, NULL)-1; len = host_len+scheme_len+sizeof(BYTE);
if(len+sizeof(DWORD) > *secid_len) { if(len+sizeof(DWORD) > *secid_len) {
CoTaskMemFree(secur_url); SysFreeString(host);
return HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER); SysFreeString(scheme);
} return HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER);
}
WideCharToMultiByte(CP_ACP, 0, secur_url, -1, (LPSTR)secid, len, NULL, NULL); WideCharToMultiByte(CP_ACP, 0, scheme, -1, (LPSTR)secid, len, NULL, NULL);
CoTaskMemFree(secur_url); SysFreeString(scheme);
ptr = secid+scheme_len;
*ptr++ = ':';
WideCharToMultiByte(CP_ACP, 0, host, -1, (LPSTR)ptr, host_len, NULL, NULL);
SysFreeString(host);
ptr += host_len;
*(DWORD*)(secid+len) = zone; *(DWORD*)ptr = zone;
}
*secid_len = len+sizeof(DWORD); *secid_len = len+sizeof(DWORD);
return S_OK; return S_OK;
} }
static HRESULT get_security_id_for_url(LPCWSTR url, BYTE *secid, DWORD *secid_len)
{
HRESULT hres;
DWORD zone = URLZONE_INVALID;
LPWSTR secur_url = NULL;
IUri *uri;
hres = map_url_to_zone(url, &zone, &secur_url);
if(FAILED(hres))
return hres == 0x80041001 ? E_INVALIDARG : hres;
hres = CreateUri(secur_url, 0, 0, &uri);
CoTaskMemFree(secur_url);
if(FAILED(hres))
return hres;
hres = generate_security_id(uri, secid, secid_len, zone);
IUri_Release(uri);
return hres;
}
static HRESULT get_security_id_for_uri(IUri *uri, BYTE *secid, DWORD *secid_len)
{
HRESULT hres;
IUri *secur_uri;
DWORD zone = URLZONE_INVALID;
hres = map_uri_to_zone(uri, &zone, &secur_uri);
if(FAILED(hres))
return hres;
hres = generate_security_id(secur_uri, secid, secid_len, zone);
IUri_Release(secur_uri);
return hres;
}
/*********************************************************************** /***********************************************************************
* InternetSecurityManager implementation * InternetSecurityManager implementation
* *
...@@ -955,7 +1016,7 @@ static HRESULT WINAPI SecManagerImpl_GetSecurityId(IInternetSecurityManagerEx2 * ...@@ -955,7 +1016,7 @@ static HRESULT WINAPI SecManagerImpl_GetSecurityId(IInternetSecurityManagerEx2 *
if(dwReserved) if(dwReserved)
FIXME("dwReserved is not supported\n"); FIXME("dwReserved is not supported\n");
return get_security_id(pwszUrl, pbSecurityId, pcbSecurityId); return get_security_id_for_url(pwszUrl, pbSecurityId, pcbSecurityId);
} }
...@@ -1127,7 +1188,7 @@ static HRESULT WINAPI SecManagerImpl_MapUrlToZoneEx2(IInternetSecurityManagerEx2 ...@@ -1127,7 +1188,7 @@ static HRESULT WINAPI SecManagerImpl_MapUrlToZoneEx2(IInternetSecurityManagerEx2
if(dwFlags) if(dwFlags)
FIXME("Unsupported flags: %08x\n", dwFlags); FIXME("Unsupported flags: %08x\n", dwFlags);
return map_uri_to_zone(pUri, pdwZone); return map_uri_to_zone(pUri, pdwZone, NULL);
} }
static HRESULT WINAPI SecManagerImpl_ProcessUrlActionEx2(IInternetSecurityManagerEx2 *iface, static HRESULT WINAPI SecManagerImpl_ProcessUrlActionEx2(IInternetSecurityManagerEx2 *iface,
...@@ -1144,8 +1205,15 @@ static HRESULT WINAPI SecManagerImpl_GetSecurityIdEx2(IInternetSecurityManagerEx ...@@ -1144,8 +1205,15 @@ static HRESULT WINAPI SecManagerImpl_GetSecurityIdEx2(IInternetSecurityManagerEx
IUri *pUri, BYTE *pbSecurityId, DWORD *pcbSecurityId, DWORD_PTR dwReserved) IUri *pUri, BYTE *pbSecurityId, DWORD *pcbSecurityId, DWORD_PTR dwReserved)
{ {
SecManagerImpl *This = impl_from_IInternetSecurityManagerEx2(iface); SecManagerImpl *This = impl_from_IInternetSecurityManagerEx2(iface);
FIXME("(%p)->(%p %p %p %08x) stub\n", This, pUri, pbSecurityId, pcbSecurityId, (DWORD)dwReserved); TRACE("(%p)->(%p %p %p %08x) stub\n", This, pUri, pbSecurityId, pcbSecurityId, (DWORD)dwReserved);
return E_NOTIMPL;
if(dwReserved)
FIXME("dwReserved is not supported yet\n");
if(!pUri || !pcbSecurityId || !pbSecurityId)
return E_INVALIDARG;
return get_security_id_for_uri(pUri, pbSecurityId, pcbSecurityId);
} }
static HRESULT WINAPI SecManagerImpl_QueryCustomPolicyEx2(IInternetSecurityManagerEx2 *iface, static HRESULT WINAPI SecManagerImpl_QueryCustomPolicyEx2(IInternetSecurityManagerEx2 *iface,
......
...@@ -442,8 +442,8 @@ static void test_SecurityManager(void) ...@@ -442,8 +442,8 @@ static void test_SecurityManager(void)
memset(buf, 0xf0, sizeof(buf)); memset(buf, 0xf0, sizeof(buf));
hres = IInternetSecurityManager_GetSecurityId(secmgr, url14, buf, &size, 0); hres = IInternetSecurityManager_GetSecurityId(secmgr, url14, buf, &size, 0);
ok(hres == S_OK, "GetSecurityId failed: %08x, expected S_OK\n", hres); ok(hres == S_OK, "GetSecurityId failed: %08x, expected S_OK\n", hres);
todo_wine ok(size == sizeof(secid14), "size=%d\n", size); ok(size == sizeof(secid14), "size=%d\n", size);
todo_wine ok(!memcmp(buf, secid14, size), "wrong secid\n"); ok(!memcmp(buf, secid14, size), "wrong secid\n");
zone = 100; zone = 100;
hres = IInternetSecurityManager_MapUrlToZone(secmgr, NULL, &zone, 0); hres = IInternetSecurityManager_MapUrlToZone(secmgr, NULL, &zone, 0);
...@@ -1751,6 +1751,7 @@ static void test_InternetGetSecurityUrlEx_Pluggable(void) ...@@ -1751,6 +1751,7 @@ static void test_InternetGetSecurityUrlEx_Pluggable(void)
static const BYTE secidex2_1[] = {'z','i','p',':','/','/','t','e','s','t','i','n','g','.','c','o','m','/',3,0,0,0}; static const BYTE secidex2_1[] = {'z','i','p',':','/','/','t','e','s','t','i','n','g','.','c','o','m','/',3,0,0,0};
static const BYTE secidex2_2[] = {'z','i','p',':','t','e','s','t','i','n','g','.','c','o','m',3,0,0,0}; static const BYTE secidex2_2[] = {'z','i','p',':','t','e','s','t','i','n','g','.','c','o','m',3,0,0,0};
static const BYTE secidex2_3[] = {'*',':','t','e','s','t','i','n','g','.','c','o','m',3,0,0,0};
static const struct { static const struct {
const char *uri; const char *uri;
...@@ -1763,17 +1764,19 @@ static const struct { ...@@ -1763,17 +1764,19 @@ static const struct {
HRESULT secid_hres; HRESULT secid_hres;
BOOL secid_todo; BOOL secid_todo;
} sec_mgr_ex2_tests[] = { } sec_mgr_ex2_tests[] = {
{"res://mshtml.dll/blank.htm",0,S_OK,URLZONE_LOCAL_MACHINE,FALSE,secid1,sizeof(secid1),S_OK,TRUE}, {"res://mshtml.dll/blank.htm",0,S_OK,URLZONE_LOCAL_MACHINE,FALSE,secid1,sizeof(secid1),S_OK},
{"index.htm",Uri_CREATE_ALLOW_RELATIVE,0,URLZONE_INTERNET,FALSE,secid2,sizeof(secid2),S_OK,TRUE}, {"index.htm",Uri_CREATE_ALLOW_RELATIVE,0,URLZONE_INTERNET,FALSE,secid2,sizeof(secid2),S_OK},
{"file://c:\\Index.html",0,0,URLZONE_LOCAL_MACHINE,FALSE,secid1,sizeof(secid1),S_OK,TRUE}, {"file://c:\\Index.html",0,0,URLZONE_LOCAL_MACHINE,FALSE,secid1,sizeof(secid1),S_OK},
{"http://www.zone3.winetest/",0,0,URLZONE_INTERNET,FALSE,secid5,sizeof(secid5),S_OK,TRUE}, {"http://www.zone3.winetest/",0,0,URLZONE_INTERNET,FALSE,secid5,sizeof(secid5),S_OK},
{"about:blank",0,0,URLZONE_INTERNET,FALSE,secid6,sizeof(secid6),S_OK,TRUE}, {"about:blank",0,0,URLZONE_INTERNET,FALSE,secid6,sizeof(secid6),S_OK},
{"ftp://zone3.winetest/file.test",0,0,URLZONE_INTERNET,FALSE,secid7,sizeof(secid7),S_OK,TRUE}, {"ftp://zone3.winetest/file.test",0,0,URLZONE_INTERNET,FALSE,secid7,sizeof(secid7),S_OK},
{"/file/testing/test.test",Uri_CREATE_ALLOW_RELATIVE,0,URLZONE_INTERNET,FALSE,NULL,0,E_INVALIDARG,TRUE}, {"/file/testing/test.test",Uri_CREATE_ALLOW_RELATIVE,0,URLZONE_INTERNET,FALSE,NULL,0,E_INVALIDARG},
{"zip://testing.com/",0,0,URLZONE_INTERNET,FALSE,secidex2_1,sizeof(secidex2_1),S_OK,TRUE}, {"zip://testing.com/",0,0,URLZONE_INTERNET,FALSE,secidex2_1,sizeof(secidex2_1),S_OK},
{"zip:testing.com",0,0,URLZONE_INTERNET,FALSE,secidex2_2,sizeof(secidex2_2),S_OK,TRUE}, {"zip:testing.com",0,0,URLZONE_INTERNET,FALSE,secidex2_2,sizeof(secidex2_2),S_OK},
{"http:google.com",0,S_OK,URLZONE_INVALID,FALSE,NULL,0,E_INVALIDARG,TRUE}, {"http:google.com",0,S_OK,URLZONE_INVALID,FALSE,NULL,0,E_INVALIDARG},
{"http:/google.com",0,S_OK,URLZONE_INVALID,FALSE,NULL,0,E_INVALIDARG,TRUE} {"http:/google.com",0,S_OK,URLZONE_INVALID,FALSE,NULL,0,E_INVALIDARG},
{"*:/testing",0,S_OK,URLZONE_INTERNET,FALSE,NULL,0,E_INVALIDARG},
{"*://testing.com",0,S_OK,URLZONE_INTERNET,FALSE,secidex2_3,sizeof(secidex2_3),S_OK}
}; };
static void test_SecurityManagerEx2(void) static void test_SecurityManagerEx2(void)
...@@ -1808,7 +1811,7 @@ static void test_SecurityManagerEx2(void) ...@@ -1808,7 +1811,7 @@ static void test_SecurityManagerEx2(void)
ok(zone == URLZONE_INVALID, "zone was %d\n", zone); ok(zone == URLZONE_INVALID, "zone was %d\n", zone);
hres = IInternetSecurityManagerEx2_GetSecurityIdEx2(sec_mgr2, NULL, buf, &buf_size, 0); hres = IInternetSecurityManagerEx2_GetSecurityIdEx2(sec_mgr2, NULL, buf, &buf_size, 0);
todo_wine ok(hres == E_INVALIDARG, "GetSecurityIdEx2 returned %08x, expected E_INVALIDARG\n", hres); ok(hres == E_INVALIDARG, "GetSecurityIdEx2 returned %08x, expected E_INVALIDARG\n", hres);
ok(buf_size == sizeof(buf), "buf_size was %d\n", buf_size); ok(buf_size == sizeof(buf), "buf_size was %d\n", buf_size);
hres = pCreateUri(url5, 0, 0, &uri); hres = pCreateUri(url5, 0, 0, &uri);
...@@ -1819,11 +1822,11 @@ static void test_SecurityManagerEx2(void) ...@@ -1819,11 +1822,11 @@ static void test_SecurityManagerEx2(void)
buf_size = sizeof(buf); buf_size = sizeof(buf);
hres = IInternetSecurityManagerEx2_GetSecurityIdEx2(sec_mgr2, uri, NULL, &buf_size, 0); hres = IInternetSecurityManagerEx2_GetSecurityIdEx2(sec_mgr2, uri, NULL, &buf_size, 0);
todo_wine ok(hres == E_INVALIDARG || broken(hres == S_OK), "GetSecurityIdEx2 failed: %08x\n", hres); ok(hres == E_INVALIDARG || broken(hres == S_OK), "GetSecurityIdEx2 failed: %08x\n", hres);
ok(buf_size == sizeof(buf), "bug_size was %d\n", buf_size); ok(buf_size == sizeof(buf), "bug_size was %d\n", buf_size);
hres = IInternetSecurityManagerEx2_GetSecurityIdEx2(sec_mgr2, uri, buf, NULL, 0); hres = IInternetSecurityManagerEx2_GetSecurityIdEx2(sec_mgr2, uri, buf, NULL, 0);
todo_wine ok(hres == E_INVALIDARG, "GetSecurityIdEx2 returned %08x, expected E_INVALIDARG\n", hres); ok(hres == E_INVALIDARG, "GetSecurityIdEx2 returned %08x, expected E_INVALIDARG\n", hres);
IUri_Release(uri); IUri_Release(uri);
...@@ -1889,7 +1892,7 @@ static void test_SecurityManagerEx2(void) ...@@ -1889,7 +1892,7 @@ static void test_SecurityManagerEx2(void)
memset(buf, 0xf0, buf_size); memset(buf, 0xf0, buf_size);
hres = IInternetSecurityManagerEx2_GetSecurityIdEx2(sec_mgr2, uri, buf, &buf_size, (DWORD_PTR)domainW); hres = IInternetSecurityManagerEx2_GetSecurityIdEx2(sec_mgr2, uri, buf, &buf_size, (DWORD_PTR)domainW);
todo_wine ok(hres == S_OK, "GetSecurityIdEx2 failed: %08x\n", hres); ok(hres == S_OK, "GetSecurityIdEx2 failed: %08x\n", hres);
todo_wine ok(buf_size == sizeof(secid13), "buf_size was %d\n", buf_size); todo_wine ok(buf_size == sizeof(secid13), "buf_size was %d\n", buf_size);
todo_wine ok(!memcmp(buf, secid13, sizeof(secid13)), "Got wrong secid\n"); todo_wine ok(!memcmp(buf, secid13, sizeof(secid13)), "Got wrong secid\n");
...@@ -1897,9 +1900,9 @@ static void test_SecurityManagerEx2(void) ...@@ -1897,9 +1900,9 @@ static void test_SecurityManagerEx2(void)
memset(buf, 0xf0, buf_size); memset(buf, 0xf0, buf_size);
hres = IInternetSecurityManagerEx2_GetSecurityIdEx2(sec_mgr2, uri, buf, &buf_size, 0); hres = IInternetSecurityManagerEx2_GetSecurityIdEx2(sec_mgr2, uri, buf, &buf_size, 0);
todo_wine ok(hres == S_OK, "GetSecurityIdEx2 failed: %08x\n", hres); ok(hres == S_OK, "GetSecurityIdEx2 failed: %08x\n", hres);
todo_wine ok(buf_size == sizeof(secid13_2), "buf_size was %d\n", buf_size); ok(buf_size == sizeof(secid13_2), "buf_size was %d\n", buf_size);
todo_wine ok(!memcmp(buf, secid13_2, sizeof(secid13_2)), "Got wrong secid\n"); ok(!memcmp(buf, secid13_2, sizeof(secid13_2)), "Got wrong secid\n");
IUri_Release(uri); IUri_Release(uri);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment