Jacek Caban : urlmon: Added GetSecurityId implementation.
Alexandre Julliard
julliard at wine.codeweavers.com
Mon Dec 26 11:47:11 CST 2005
Module: wine
Branch: refs/heads/master
Commit: fb042eb1229e93b855de979ae780c9762ab4fddb
URL: http://source.winehq.org/git/?p=wine.git;a=commit;h=fb042eb1229e93b855de979ae780c9762ab4fddb
Author: Jacek Caban <jacek at codeweavers.com>
Date: Mon Dec 26 13:27:25 2005 +0100
urlmon: Added GetSecurityId implementation.
---
dlls/urlmon/sec_mgr.c | 75 ++++++++++++++++++++++++++++++++----
dlls/urlmon/tests/misc.c | 95 +++++++++++++++++++++++++++++++++++++++++-----
2 files changed, 152 insertions(+), 18 deletions(-)
diff --git a/dlls/urlmon/sec_mgr.c b/dlls/urlmon/sec_mgr.c
index 576e82a..d2ac8e9 100644
--- a/dlls/urlmon/sec_mgr.c
+++ b/dlls/urlmon/sec_mgr.c
@@ -109,7 +109,7 @@ static HRESULT map_url_to_zone(LPCWSTR u
size = sizeof(DWORD);
res = RegQueryValueExW(hkey, schema, NULL, NULL, (PBYTE)zone, &size);
if(res == ERROR_SUCCESS)
- return S_OK;
+ return S_OK;
*zone = 3;
return S_OK;
@@ -268,15 +268,17 @@ static HRESULT WINAPI SecManagerImpl_Map
}
static HRESULT WINAPI SecManagerImpl_GetSecurityId(IInternetSecurityManager *iface,
- LPCWSTR pwszUrl,
- BYTE *pbSecurityId, DWORD *pcbSecurityId,
- DWORD_PTR dwReserved)
+ LPCWSTR pwszUrl, BYTE *pbSecurityId, DWORD *pcbSecurityId, DWORD_PTR dwReserved)
{
SecManagerImpl *This = SECMGR_THIS(iface);
+ LPWSTR buf, ptr, ptr2;
+ DWORD size, zone, len;
HRESULT hres;
- TRACE("(%p)->(%s %p %p %08lx)\n", iface, debugstr_w(pwszUrl), pbSecurityId, pcbSecurityId,
- dwReserved);
+ static const WCHAR wszFile[] = {'f','i','l','e',':'};
+
+ TRACE("(%p)->(%s %p %p %08lx)\n", iface, debugstr_w(pwszUrl), pbSecurityId,
+ pcbSecurityId, dwReserved);
if(This->custom_manager) {
hres = IInternetSecurityManager_GetSecurityId(This->custom_manager,
@@ -285,8 +287,65 @@ static HRESULT WINAPI SecManagerImpl_Get
return hres;
}
- FIXME("Default action is not implemented\n");
- return E_NOTIMPL;
+ if(!pwszUrl || !pbSecurityId || !pcbSecurityId)
+ return E_INVALIDARG;
+
+ if(dwReserved)
+ FIXME("dwReserved is not supported\n");
+
+ len = strlenW(pwszUrl)+1;
+ buf = HeapAlloc(GetProcessHeap(), 0, (len+16)*sizeof(WCHAR));
+
+ hres = CoInternetParseUrl(pwszUrl, PARSE_SECURITY_URL, 0, buf, len, &size, 0);
+ if(FAILED(hres))
+ memcpy(buf, pwszUrl, len*sizeof(WCHAR));
+
+ hres = map_url_to_zone(buf, &zone);
+ if(FAILED(hres)) {
+ HeapFree(GetProcessHeap(), 0, buf);
+ return hres == 0x80041001 ? E_INVALIDARG : hres;
+ }
+
+ /* file protocol is a special case */
+ if(strlenW(pwszUrl) >= sizeof(wszFile)/sizeof(WCHAR)
+ && !memcmp(buf, wszFile, sizeof(wszFile))) {
+
+ static const BYTE secidFile[] = {'f','i','l','e',':'};
+
+ if(*pcbSecurityId < sizeof(secidFile)+sizeof(zone))
+ return HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER);
+
+ memcpy(pbSecurityId, secidFile, sizeof(secidFile));
+ *(DWORD*)(pbSecurityId+sizeof(secidFile)) = zone;
+
+ *pcbSecurityId = sizeof(secidFile)+sizeof(zone);
+ return S_OK;
+ }
+
+ ptr = strchrW(buf, ':');
+ ptr2 = ++ptr;
+ while(*ptr2 == '/')
+ ptr2++;
+ if(ptr2 != ptr)
+ memmove(ptr, ptr2, (strlenW(ptr2)+1)*sizeof(WCHAR));
+
+ ptr = strchrW(ptr, '/');
+ if(ptr)
+ *ptr = 0;
+
+ len = WideCharToMultiByte(CP_ACP, 0, buf, -1, NULL, 0, NULL, NULL)-1;
+
+ if(len+sizeof(DWORD) > *pcbSecurityId)
+ return HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER);
+
+ WideCharToMultiByte(CP_ACP, 0, buf, -1, (LPSTR)pbSecurityId, -1, NULL, NULL);
+ HeapFree(GetProcessHeap(), 0, buf);
+
+ *(DWORD*)(pbSecurityId+len) = zone;
+
+ *pcbSecurityId = len+sizeof(DWORD);
+
+ return S_OK;
}
diff --git a/dlls/urlmon/tests/misc.c b/dlls/urlmon/tests/misc.c
index 1fd30a0..99b8c6f 100644
--- a/dlls/urlmon/tests/misc.c
+++ b/dlls/urlmon/tests/misc.c
@@ -26,6 +26,10 @@
#include "ole2.h"
#include "urlmon.h"
+#include "initguid.h"
+
+DEFINE_GUID(CLSID_AboutProtocol, 0x3050F406, 0x98B5, 0x11CF, 0xBB,0x82, 0x00,0xAA,0x00,0xBD,0xCE,0x0B);
+
static void test_CreateFormatEnum(void)
{
IEnumFORMATETC *fenum = NULL, *fenum2 = NULL;
@@ -409,25 +413,37 @@ static void test_FindMimeFromData(void)
ok(hres == E_INVALIDARG, "FindMimeFromData failed: %08lx, expected E_INVALIDARG\n", hres);
}
+static const BYTE secid1[] = {'f','i','l','e',':',0,0,0,0};
+static const BYTE secid4[] ={'f','i','l','e',':',3,0,0,0};
+static const BYTE secid5[] = {'h','t','t','p',':','w','w','w','.','w','i','n','e','h','q',
+ '.','o','r','g',3,0,0,0};
+static const BYTE secid6[] = {'a','b','o','u','t',':','b','l','a','n','k',3,0,0,0};
+static const BYTE secid7[] = {'f','t','p',':','w','i','n','e','h','q','.','o','r','g',
+ 3,0,0,0};
+
static struct secmgr_test {
LPCWSTR url;
DWORD zone;
HRESULT zone_hres;
+ DWORD secid_size;
+ const BYTE *secid;
+ HRESULT secid_hres;
} secmgr_tests[] = {
- {url1, 0, S_OK},
- {url2, 100, 0x80041001},
- {url3, 0, S_OK},
- {url4, 3, S_OK},
- {url5, 3, S_OK},
- {url6, 3, S_OK},
- {url7, 3, S_OK}
+ {url1, 0, S_OK, sizeof(secid1), secid1, S_OK},
+ {url2, 100, 0x80041001, 0, NULL, E_INVALIDARG},
+ {url3, 0, S_OK, sizeof(secid1), secid1, S_OK},
+ {url4, 3, S_OK, sizeof(secid4), secid4, S_OK},
+ {url5, 3, S_OK, sizeof(secid5), secid5, S_OK},
+ {url6, 3, S_OK, sizeof(secid6), secid6, S_OK},
+ {url7, 3, S_OK, sizeof(secid7), secid7, S_OK}
};
static void test_SecurityManager(void)
{
int i;
IInternetSecurityManager *secmgr = NULL;
- DWORD zone;
+ BYTE buf[512];
+ DWORD zone, size;
HRESULT hres;
hres = CoInternetCreateSecurityManager(NULL, &secmgr, 0);
@@ -437,17 +453,45 @@ static void test_SecurityManager(void)
for(i=0; i < sizeof(secmgr_tests)/sizeof(secmgr_tests[0]); i++) {
zone = 100;
- hres = IInternetSecurityManager_MapUrlToZone(secmgr, secmgr_tests[i].url, &zone, 0);
- ok(hres == secmgr_tests[i].zone_hres, "[%d] MapUrlToZone failed: %08lx, expected %08lx\n",
+ hres = IInternetSecurityManager_MapUrlToZone(secmgr, secmgr_tests[i].url,
+ &zone, 0);
+ ok(hres == secmgr_tests[i].zone_hres,
+ "[%d] MapUrlToZone failed: %08lx, expected %08lx\n",
i, hres, secmgr_tests[i].zone_hres);
ok(zone == secmgr_tests[i].zone, "[%d] zone=%ld, expected %ld\n", i, zone,
secmgr_tests[i].zone);
+
+ size = sizeof(buf);
+ memset(buf, 0xf0, sizeof(buf));
+ hres = IInternetSecurityManager_GetSecurityId(secmgr, secmgr_tests[i].url,
+ buf, &size, 0);
+ ok(hres == secmgr_tests[i].secid_hres,
+ "[%d] GetSecurityId failed: %08lx, expected %08lx\n",
+ i, hres, secmgr_tests[i].secid_hres);
+ if(secmgr_tests[i].secid) {
+ ok(size == secmgr_tests[i].secid_size, "[%d] size=%ld, expected %ld\n",
+ i, size, secmgr_tests[i].secid_size);
+ ok(!memcmp(buf, secmgr_tests[i].secid, size), "[%d] wrong secid\n", i);
+ }
}
zone = 100;
hres = IInternetSecurityManager_MapUrlToZone(secmgr, NULL, &zone, 0);
ok(hres == E_INVALIDARG, "MapUrlToZone failed: %08lx, expected E_INVALIDARG\n", hres);
+ size = sizeof(buf);
+ hres = IInternetSecurityManager_GetSecurityId(secmgr, NULL, buf, &size, 0);
+ ok(hres == E_INVALIDARG,
+ "GetSecurityId failed: %08lx, expected E_INVALIDARG\n", hres);
+ hres = IInternetSecurityManager_GetSecurityId(secmgr, secmgr_tests[1].url,
+ NULL, &size, 0);
+ ok(hres == E_INVALIDARG,
+ "GetSecurityId failed: %08lx, expected E_INVALIDARG\n", hres);
+ hres = IInternetSecurityManager_GetSecurityId(secmgr, secmgr_tests[1].url,
+ buf, NULL, 0);
+ ok(hres == E_INVALIDARG,
+ "GetSecurityId failed: %08lx, expected E_INVALIDARG\n", hres);
+
IInternetSecurityManager_Release(secmgr);
}
@@ -486,12 +530,43 @@ static void test_ZoneManager(void)
IInternetZoneManager_Release(zonemgr);
}
+static void register_protocols(void)
+{
+ IInternetSession *session;
+ IClassFactory *factory;
+ HRESULT hres;
+
+ static const WCHAR wszAbout[] = {'a','b','o','u','t',0};
+
+ hres = CoInternetGetSession(0, &session, 0);
+ ok(hres == S_OK, "CoInternetGetSession failed: %08lx\n", hres);
+ if(FAILED(hres))
+ return;
+
+ hres = CoGetClassObject(&CLSID_AboutProtocol, CLSCTX_INPROC_SERVER, NULL,
+ &IID_IClassFactory, (void**)&factory);
+ ok(hres == S_OK, "Coud not get AboutProtocol factory: %08lx\n", hres);
+ if(FAILED(hres))
+ return;
+
+ IInternetSession_RegisterNameSpace(session, factory, &CLSID_AboutProtocol,
+ wszAbout, 0, NULL, 0);
+ IClassFactory_Release(factory);
+
+}
+
START_TEST(misc)
{
+ OleInitialize(NULL);
+
+ register_protocols();
+
test_CreateFormatEnum();
test_RegisterFormatEnumerator();
test_CoInternetParseUrl();
test_FindMimeFromData();
test_SecurityManager();
test_ZoneManager();
+
+ OleUninitialize();
}
More information about the wine-cvs
mailing list