LookupAccountNameW() handles first user account
Paul Bryan Roberts
pbronline-wine at yahoo.co.uk
Thu Sep 25 20:16:30 CDT 2008
---
dlls/advapi32/security.c | 118 +++++++++++++++++++++++-----------------
dlls/advapi32/tests/security.c | 7 +--
2 files changed, 69 insertions(+), 56 deletions(-)
diff --git a/dlls/advapi32/security.c b/dlls/advapi32/security.c
index 51d2de1..a09514e 100644
--- a/dlls/advapi32/security.c
+++ b/dlls/advapi32/security.c
@@ -2524,25 +2524,23 @@ BOOL WINAPI LookupAccountNameW( LPCWSTR lpSystemName, LPCWSTR lpAccountName, PSI
LPDWORD cbSid, LPWSTR ReferencedDomainName,
LPDWORD cchReferencedDomainName, PSID_NAME_USE peUse )
{
- /* Default implementation: Always return a default SID */
- SID_IDENTIFIER_AUTHORITY identifierAuthority = {SECURITY_NT_AUTHORITY};
BOOL ret;
- PSID pSid;
- static const WCHAR dm[] = {'D','O','M','A','I','N',0};
unsigned int i;
size_t nameLen;
LPCWSTR domainName;
- FIXME("%s %s %p %p %p %p %p - stub\n", debugstr_w(lpSystemName), debugstr_w(lpAccountName),
+ TRACE("%s %s %p %p %p %p %p\n", debugstr_w(lpSystemName), debugstr_w(lpAccountName),
Sid, cbSid, ReferencedDomainName, cchReferencedDomainName, peUse);
if (!ADVAPI_IsLocalComputer(lpSystemName))
{
- /*FIXME("Only local computer supported!\n");*/
+ FIXME("Only local computer supported!\n");
SetLastError(ERROR_NONE_MAPPED);
return FALSE;
}
+ /* Check well known SIDs first */
+
if (!lpAccountName || !strcmpW(lpAccountName, Blank))
{
lpAccountName = BUILTIN;
@@ -2557,12 +2555,20 @@ BOOL WINAPI LookupAccountNameW( LPCWSTR lpSystemName, LPCWSTR lpAccountName, PSI
ret = CreateWellKnownSid(ACCOUNT_SIDS[i].type, NULL, sidBuffer, &sidLen);
- if (ret && *cbSid >= sidLen)
+ if (ret)
{
- CopySid(*cbSid, Sid, sidBuffer);
- }
+ if (*cbSid < sidLen)
+ {
+ SetLastError(ERROR_INSUFFICIENT_BUFFER);
+ ret = FALSE;
+ }
+ else if (Sid)
+ {
+ CopySid(*cbSid, Sid, sidBuffer);
+ }
- *cbSid = sidLen;
+ *cbSid = sidLen;
+ }
domainName = ACCOUNT_SIDS[i].domain;
nameLen = strlenW(domainName);
@@ -2589,16 +2595,16 @@ BOOL WINAPI LookupAccountNameW( LPCWSTR lpSystemName, LPCWSTR lpAccountName, PSI
}
}
-
+ /* Let the current Unix user id pass as first user account */
{
- WCHAR userName [UNLEN + 1];
- size_t nameLen = UNLEN + 1;
+ WCHAR userName [UNLEN + 1];
+ nameLen = UNLEN + 1;
ret = GetUserNameW(userName, &nameLen);
if (ret && strcmpW(lpAccountName, userName) != 0)
{
- /* FIXME("Only first user account supported!\n"); */
+ FIXME("Only first user account supported!\n");
SetLastError(ERROR_NONE_MAPPED);
ret = FALSE;
}
@@ -2609,53 +2615,63 @@ BOOL WINAPI LookupAccountNameW( LPCWSTR lpSystemName, LPCWSTR lpAccountName, PSI
}
}
- ret = AllocateAndInitializeSid(&identifierAuthority,
- 2,
- SECURITY_BUILTIN_DOMAIN_RID,
- DOMAIN_ALIAS_RID_ADMINS,
- 0, 0, 0, 0, 0, 0,
- &pSid);
+ /* Find SID for the first user account */
+ {
+ MAX_SID max_sid;
- if (!ret)
- return FALSE;
+ ret = ADVAPI_GetComputerSid(&max_sid);
- if (!RtlValidSid(pSid))
- {
- FreeSid(pSid);
- return FALSE;
- }
+ if (ret)
+ {
+ int count = *GetSidSubAuthorityCount(&max_sid);
+ size_t sidLen;
- if (Sid != NULL && (*cbSid >= GetLengthSid(pSid)))
- CopySid(*cbSid, Sid, pSid);
- if (*cbSid < GetLengthSid(pSid))
- {
- SetLastError(ERROR_INSUFFICIENT_BUFFER);
- ret = FALSE;
- }
- *cbSid = GetLengthSid(pSid);
+ max_sid.SubAuthority[count] = 1000; /* first user account */
+ max_sid.SubAuthorityCount = count + 1;
- domainName = dm;
- nameLen = strlenW(domainName);
+ sidLen = GetSidLengthRequired(max_sid.SubAuthorityCount);
- if (*cchReferencedDomainName <= nameLen || !ret)
- {
- SetLastError(ERROR_INSUFFICIENT_BUFFER);
- nameLen += 1;
- ret = FALSE;
+ if (*cbSid < sidLen)
+ {
+ SetLastError(ERROR_INSUFFICIENT_BUFFER);
+ ret = FALSE;
+ }
+ else if (Sid)
+ {
+ CopySid(*cbSid, Sid, &max_sid);
+ }
+
+ *cbSid = sidLen;
+ }
}
- else if (ReferencedDomainName && domainName)
+
+ /* Let the computer name be the domain name */
{
- strcpyW(ReferencedDomainName, domainName);
- }
+ WCHAR computerName [MAX_COMPUTERNAME_LENGTH + 1];
+ nameLen = MAX_COMPUTERNAME_LENGTH + 1;
- *cchReferencedDomainName = nameLen;
+ ret &= GetComputerNameW(computerName, &nameLen);
- if (ret)
- {
- *peUse = SidTypeUser;
- }
+ domainName = computerName;
- FreeSid(pSid);
+ if (*cchReferencedDomainName <= nameLen || !ret)
+ {
+ SetLastError(ERROR_INSUFFICIENT_BUFFER);
+ nameLen += 1;
+ ret = FALSE;
+ }
+ else if (ReferencedDomainName && domainName)
+ {
+ strcpyW(ReferencedDomainName, domainName);
+ }
+
+ *cchReferencedDomainName = nameLen;
+
+ if (ret)
+ {
+ *peUse = SidTypeUser;
+ }
+ }
return ret;
}
diff --git a/dlls/advapi32/tests/security.c b/dlls/advapi32/tests/security.c
index 1c84b14..e94ea2a 100644
--- a/dlls/advapi32/tests/security.c
+++ b/dlls/advapi32/tests/security.c
@@ -1546,11 +1546,8 @@ static void test_LookupAccountName(void)
get_sid_info(psid, &account, &sid_dom);
ok(ret, "Failed to lookup account name\n");
ok(sid_size == GetLengthSid(psid), "Expected %d, got %d\n", GetLengthSid(psid), sid_size);
- todo_wine
- {
- ok(!lstrcmp(account, user_name), "Expected %s, got %s\n", user_name, account);
- ok(!lstrcmp(domain, sid_dom), "Expected %s, got %s\n", sid_dom, domain);
- }
+ ok(!lstrcmp(account, user_name), "Expected %s, got %s\n", user_name, account);
+ ok(!lstrcmp(domain, sid_dom), "Expected %s, got %s\n", sid_dom, domain);
ok(domain_size == domain_save - 1, "Expected %d, got %d\n", domain_save - 1, domain_size);
ok(lstrlen(domain) == domain_size, "Expected %d, got %d\n", lstrlen(domain), domain_size);
ok(sid_use == SidTypeUser, "Expected SidTypeUser, got %d\n", sid_use);
--
1.5.4.3
--------------010308020906060001090500--
More information about the wine-patches
mailing list