advapi32: LookupAccountNameW() - only first user account and well known SIDs accepted.

This commit is contained in:
Paul Bryan Roberts 2008-10-18 22:09:14 +01:00 committed by Alexandre Julliard
parent 2981650435
commit f04804f44c
2 changed files with 55 additions and 9 deletions

View File

@ -2027,7 +2027,7 @@ LookupAccountSidW(
if (!ADVAPI_IsLocalComputer(system)) {
FIXME("Only local computer supported!\n");
SetLastError(ERROR_NONE_MAPPED);
SetLastError(RPC_S_SERVER_UNAVAILABLE);
return FALSE;
}
@ -2535,16 +2535,25 @@ BOOL WINAPI LookupAccountNameW( LPCWSTR lpSystemName, LPCWSTR lpAccountName, PSI
static const WCHAR dm[] = {'D','O','M','A','I','N',0};
unsigned int i;
DWORD nameLen;
LPWSTR userName = NULL;
LPCWSTR domainName;
FIXME("%s %s %p %p %p %p %p - stub\n", debugstr_w(lpSystemName), debugstr_w(lpAccountName),
Sid, cbSid, ReferencedDomainName, cchReferencedDomainName, peUse);
if (!ADVAPI_IsLocalComputer(lpSystemName))
{
SetLastError(RPC_S_SERVER_UNAVAILABLE);
return FALSE;
}
if (!lpAccountName || !strcmpW(lpAccountName, Blank))
{
lpAccountName = BUILTIN;
}
/* Check well known SIDs first */
for (i = 0; i < (sizeof(ACCOUNT_SIDS) / sizeof(ACCOUNT_SIDS[0])); i++)
{
if (!strcmpW(lpAccountName, ACCOUNT_SIDS[i].account))
@ -2597,6 +2606,27 @@ BOOL WINAPI LookupAccountNameW( LPCWSTR lpSystemName, LPCWSTR lpAccountName, PSI
}
}
/* Let the current Unix user id masquerade as first Windows user account */
nameLen = UNLEN + 1;
userName = HeapAlloc(GetProcessHeap(), 0, nameLen);
ret = GetUserNameW(userName, &nameLen);
if (ret && strcmpW(lpAccountName, userName) != 0)
{
SetLastError(ERROR_NONE_MAPPED);
ret = FALSE;
}
HeapFree(GetProcessHeap(), 0, userName);
if (!ret)
{
return ret;
}
ret = AllocateAndInitializeSid(&identifierAuthority,
2,
SECURITY_BUILTIN_DOMAIN_RID,

View File

@ -1314,6 +1314,14 @@ static void test_LookupAccountSid(void)
ret = LookupAccountSidW(NULL, pUsersSid, accountW, &real_acc_sizeW, domainW, &real_dom_sizeW, &use);
ok(ret, "LookupAccountSidW() Expected TRUE, got FALSE\n");
/* try an invalid system name */
real_acc_sizeA = MAX_PATH;
real_dom_sizeA = MAX_PATH;
ret = LookupAccountSidA("deepthought", pUsersSid, accountA, &real_acc_sizeA, domainA, &real_dom_sizeA, &use);
ok(!ret, "LookupAccountSidA() Expected FALSE got TRUE\n");
ok(GetLastError() == RPC_S_SERVER_UNAVAILABLE,
"LookupAccountSidA() Expected RPC_S_SERVER_UNAVAILABLE, got %u\n", GetLastError());
/* native windows crashes if domainW or accountW is NULL */
/* try a small account buffer */
@ -1644,14 +1652,22 @@ static void test_LookupAccountName(void)
domain_size = 0;
ret = LookupAccountNameA(NULL, "oogabooga", NULL, &sid_size, NULL, &domain_size, &sid_use);
ok(!ret, "Expected 0, got %d\n", ret);
todo_wine
{
ok(GetLastError() == ERROR_NONE_MAPPED ||
broken(GetLastError() == ERROR_TRUSTED_RELATIONSHIP_FAILURE),
"Expected ERROR_NONE_MAPPED, got %d\n", GetLastError());
ok(sid_size == 0, "Expected 0, got %d\n", sid_size);
ok(domain_size == 0, "Expected 0, got %d\n", domain_size);
}
ok(GetLastError() == ERROR_NONE_MAPPED ||
broken(GetLastError() == ERROR_TRUSTED_RELATIONSHIP_FAILURE),
"Expected ERROR_NONE_MAPPED, got %d\n", GetLastError());
ok(sid_size == 0, "Expected 0, got %d\n", sid_size);
ok(domain_size == 0, "Expected 0, got %d\n", domain_size);
/* try an invalid system name */
SetLastError(0xdeadbeef);
sid_size = 0;
domain_size = 0;
ret = LookupAccountNameA("deepthought", NULL, NULL, &sid_size, NULL, &domain_size, &sid_use);
ok(!ret, "Expected 0, got %d\n", ret);
ok(GetLastError() == RPC_S_SERVER_UNAVAILABLE,
"Expected RPC_S_SERVER_UNAVAILABLE, got %d\n", GetLastError());
ok(sid_size == 0, "Expected 0, got %d\n", sid_size);
ok(domain_size == 0, "Expected 0, got %d\n", domain_size);
HeapFree(GetProcessHeap(), 0, psid);
HeapFree(GetProcessHeap(), 0, domain);