Paul Bryan Roberts : advapi32: LookupAccountNameW() - only first user account and well known SIDs accepted.
Alexandre Julliard
julliard at winehq.org
Tue Oct 21 07:07:04 CDT 2008
Module: wine
Branch: master
Commit: f04804f44cbe07fe95d5fc18b431ed39209834c7
URL: http://source.winehq.org/git/wine.git/?a=commit;h=f04804f44cbe07fe95d5fc18b431ed39209834c7
Author: Paul Bryan Roberts <pbronline-wine at yahoo.co.uk>
Date: Sat Oct 18 22:09:14 2008 +0100
advapi32: LookupAccountNameW() - only first user account and well known SIDs accepted.
---
dlls/advapi32/security.c | 32 +++++++++++++++++++++++++++++++-
dlls/advapi32/tests/security.c | 32 ++++++++++++++++++++++++--------
2 files changed, 55 insertions(+), 9 deletions(-)
diff --git a/dlls/advapi32/security.c b/dlls/advapi32/security.c
index 29ff696..2093f7e 100644
--- a/dlls/advapi32/security.c
+++ b/dlls/advapi32/security.c
@@ -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,
diff --git a/dlls/advapi32/tests/security.c b/dlls/advapi32/tests/security.c
index b6756f5..d4f532d 100644
--- a/dlls/advapi32/tests/security.c
+++ b/dlls/advapi32/tests/security.c
@@ -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);
More information about the wine-cvs
mailing list