[PATCH 10/12] LookupAccountNameW() - handles first user account
Paul Bryan Roberts
pbronline-wine at yahoo.co.uk
Sat Oct 18 17:19:19 CDT 2008
---
dlls/advapi32/security.c | 67 ++++++++++++++++++++++++---------------
dlls/advapi32/tests/security.c | 28 +++++++++++++---
2 files changed, 63 insertions(+), 32 deletions(-)
diff --git a/dlls/advapi32/security.c b/dlls/advapi32/security.c
index 882158c..74918fa 100644
--- a/dlls/advapi32/security.c
+++ b/dlls/advapi32/security.c
@@ -2524,14 +2524,13 @@ 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;
+ DWORD sidLen;
DWORD nameLen;
LPWSTR userName = NULL;
+ LPWSTR computerName = NULL;
LPCWSTR domainName;
FIXME("%s %s %p %p %p %p %p - stub\n", debugstr_w(lpSystemName), debugstr_w(lpAccountName),
@@ -2554,7 +2553,7 @@ BOOL WINAPI LookupAccountNameW( LPCWSTR lpSystemName, LPCWSTR lpAccountName, PSI
{
if (!strcmpW(lpAccountName, ACCOUNT_SIDS[i].account))
{
- DWORD sidLen = SECURITY_MAX_SID_SIZE;
+ sidLen = SECURITY_MAX_SID_SIZE;
pSid = HeapAlloc(GetProcessHeap(), 0, sidLen);
@@ -2623,33 +2622,49 @@ BOOL WINAPI LookupAccountNameW( LPCWSTR lpSystemName, LPCWSTR lpAccountName, PSI
return ret;
}
- 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 */
- if (!ret)
- return FALSE;
+ sidLen = SECURITY_MAX_SID_SIZE;
- if (!RtlValidSid(pSid))
- {
- FreeSid(pSid);
- return FALSE;
- }
+ pSid = HeapAlloc(GetProcessHeap(), 0, sidLen);
- if (Sid != NULL && (*cbSid >= GetLengthSid(pSid)))
- CopySid(*cbSid, Sid, pSid);
- if (*cbSid < GetLengthSid(pSid))
+ ret = ADVAPI_GetComputerSid(pSid);
+
+ if (ret)
{
- SetLastError(ERROR_INSUFFICIENT_BUFFER);
- ret = FALSE;
+ MAX_SID *max_sid = pSid;
+
+ int count = *GetSidSubAuthorityCount(pSid);
+
+ max_sid->SubAuthority[count] = 1000; /* first user account */
+ max_sid->SubAuthorityCount = count + 1;
+
+ sidLen = GetSidLengthRequired(max_sid->SubAuthorityCount);
+
+ if (*cbSid < sidLen)
+ {
+ SetLastError(ERROR_INSUFFICIENT_BUFFER);
+ ret = FALSE;
+ }
+ else if (Sid)
+ {
+ CopySid(*cbSid, Sid, pSid);
+ }
+
+ *cbSid = sidLen;
}
- *cbSid = GetLengthSid(pSid);
- domainName = dm;
- nameLen = strlenW(domainName);
+ HeapFree(GetProcessHeap(), 0, pSid);
+
+ /* Let the computer name be the domain name */
+
+ nameLen = MAX_COMPUTERNAME_LENGTH + 1;
+
+ computerName = HeapAlloc(GetProcessHeap(), 0, nameLen * sizeof(WCHAR));
+
+ ret &= GetComputerNameW(computerName, &nameLen);
+
+ domainName = computerName;
if (*cchReferencedDomainName <= nameLen || !ret)
{
@@ -2669,7 +2684,7 @@ BOOL WINAPI LookupAccountNameW( LPCWSTR lpSystemName, LPCWSTR lpAccountName, PSI
*peUse = SidTypeUser;
}
- FreeSid(pSid);
+ HeapFree(GetProcessHeap(), 0, computerName);
return ret;
}
diff --git a/dlls/advapi32/tests/security.c b/dlls/advapi32/tests/security.c
index 9d5d546..c411349 100644
--- a/dlls/advapi32/tests/security.c
+++ b/dlls/advapi32/tests/security.c
@@ -1503,9 +1503,10 @@ static void get_sid_info(PSID psid, LPSTR *user, LPSTR *dom)
static void test_LookupAccountName(void)
{
- DWORD sid_size, domain_size, user_size;
+ DWORD sid_size, domain_size, user_size, computer_size;
DWORD sid_save, domain_save;
CHAR user_name[UNLEN + 1];
+ CHAR computer_name[MAX_COMPUTERNAME_LENGTH + 1];
SID_NAME_USE sid_use;
LPSTR domain, account, sid_dom;
PSID psid;
@@ -1529,6 +1530,11 @@ static void test_LookupAccountName(void)
}
ok(ret, "Failed to get user name : %d\n", GetLastError());
+ computer_size = sizeof (computer_name);
+ SetLastError(0xdeadbeef);
+ ret = GetComputerNameA(computer_name, &computer_size);
+ ok(ret, "Failed to get computer name : %d\n", GetLastError());
+
/* get sizes */
sid_size = 0;
domain_size = 0;
@@ -1558,11 +1564,21 @@ 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);
+ domain_size = domain_save;
+ sid_size = sid_save;
+
+ /* try valid system name */
+ ret = LookupAccountNameA(computer_name, user_name, psid, &sid_size, domain, &domain_size, &sid_use);
+ 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);
+ 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 (%d), got %d\n", SidTypeUser, sid_use);
--
1.5.4.3
--------------020907030908040909070409--
More information about the wine-patches
mailing list