From bbe6233734d24c96d87aaf1f783f1eca794f0d5a Mon Sep 17 00:00:00 2001 From: Owen Rudge Date: Thu, 2 Feb 2017 10:30:55 +0000 Subject: [PATCH] advapi32/tests: Add test of LsaLookupSids buffer behaviour. Signed-off-by: Owen Rudge Signed-off-by: Alexandre Julliard --- dlls/advapi32/tests/lsa.c | 49 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) diff --git a/dlls/advapi32/tests/lsa.c b/dlls/advapi32/tests/lsa.c index 1a0d211e1a5..4daf75f58d1 100644 --- a/dlls/advapi32/tests/lsa.c +++ b/dlls/advapi32/tests/lsa.c @@ -42,8 +42,10 @@ static NTSTATUS (WINAPI *pLsaFreeMemory)(PVOID); static NTSTATUS (WINAPI *pLsaOpenPolicy)(PLSA_UNICODE_STRING,PLSA_OBJECT_ATTRIBUTES,ACCESS_MASK,PLSA_HANDLE); static NTSTATUS (WINAPI *pLsaQueryInformationPolicy)(LSA_HANDLE,POLICY_INFORMATION_CLASS,PVOID*); static BOOL (WINAPI *pConvertSidToStringSidA)(PSID,LPSTR*); +static BOOL (WINAPI *pConvertStringSidToSidA)(LPCSTR,PSID*); static NTSTATUS (WINAPI *pLsaLookupNames2)(LSA_HANDLE,ULONG,ULONG,PLSA_UNICODE_STRING,PLSA_REFERENCED_DOMAIN_LIST*,PLSA_TRANSLATED_SID2*); static NTSTATUS (WINAPI *pLsaLookupSids)(LSA_HANDLE,ULONG,PSID*,LSA_REFERENCED_DOMAIN_LIST**,LSA_TRANSLATED_NAME**); +static PVOID (WINAPI *pFreeSid)(PSID); static BOOL init(void) { @@ -55,10 +57,12 @@ static BOOL init(void) pLsaOpenPolicy = (void*)GetProcAddress(hadvapi32, "LsaOpenPolicy"); pLsaQueryInformationPolicy = (void*)GetProcAddress(hadvapi32, "LsaQueryInformationPolicy"); pConvertSidToStringSidA = (void*)GetProcAddress(hadvapi32, "ConvertSidToStringSidA"); + pConvertStringSidToSidA = (void*)GetProcAddress(hadvapi32, "ConvertStringSidToSidA"); pLsaLookupNames2 = (void*)GetProcAddress(hadvapi32, "LsaLookupNames2"); pLsaLookupSids = (void*)GetProcAddress(hadvapi32, "LsaLookupSids"); + pFreeSid = (void*)GetProcAddress(hadvapi32, "FreeSid"); - if (pLsaClose && pLsaEnumerateAccountRights && pLsaFreeMemory && pLsaOpenPolicy && pLsaQueryInformationPolicy && pConvertSidToStringSidA) + if (pLsaClose && pLsaEnumerateAccountRights && pLsaFreeMemory && pLsaOpenPolicy && pLsaQueryInformationPolicy && pConvertSidToStringSidA && pConvertStringSidToSidA && pFreeSid) return TRUE; return FALSE; @@ -405,6 +409,48 @@ static void test_LsaLookupSids(void) ok(status == STATUS_SUCCESS, "got 0x%08x\n", status); } +static void test_LsaLookupSids_NullBuffers(void) +{ + LSA_REFERENCED_DOMAIN_LIST *list; + LSA_OBJECT_ATTRIBUTES attrs; + LSA_TRANSLATED_NAME *names; + LSA_HANDLE policy; + NTSTATUS status; + BOOL ret; + PSID sid; + + memset(&attrs, 0, sizeof(attrs)); + attrs.Length = sizeof(attrs); + + status = pLsaOpenPolicy(NULL, &attrs, POLICY_LOOKUP_NAMES, &policy); + ok(status == STATUS_SUCCESS, "got 0x%08x\n", status); + + ret = pConvertStringSidToSidA("S-1-1-0", &sid); + ok(ret == TRUE, "pConvertStringSidToSidA returned false\n"); + + status = pLsaLookupSids(policy, 1, &sid, &list, &names); + ok(status == STATUS_SUCCESS, "got 0x%08x\n", status); + + ok(list->Entries > 0, "got %d\n", list->Entries); + + if (list->Entries) + { + ok((char*)list->Domains - (char*)list > 0, "%p, %p\n", list, list->Domains); + ok((char*)list->Domains[0].Sid - (char*)list->Domains > 0, "%p, %p\n", list->Domains, list->Domains[0].Sid); + ok(list->Domains[0].Name.MaximumLength > list->Domains[0].Name.Length, "got %d, %d\n", list->Domains[0].Name.MaximumLength, + list->Domains[0].Name.Length); + ok(list->Domains[0].Name.Buffer != NULL, "domain[0] name buffer is null\n"); + } + + pLsaFreeMemory(names); + pLsaFreeMemory(list); + + pFreeSid(sid); + + status = pLsaClose(policy); + ok(status == STATUS_SUCCESS, "got 0x%08x\n", status); +} + START_TEST(lsa) { if (!init()) { @@ -415,4 +461,5 @@ START_TEST(lsa) test_lsa(); test_LsaLookupNames2(); test_LsaLookupSids(); + test_LsaLookupSids_NullBuffers(); }