[PATCH 12/12] LookupAccountNameW() - accept account name of the form domain\user
Paul Bryan Roberts
pbronline-wine at yahoo.co.uk
Sun Oct 19 17:41:14 CDT 2008
---
dlls/advapi32/security.c | 81 ++++++++++++++++++++++++++--------------
dlls/advapi32/tests/security.c | 15 +++++++
2 files changed, 68 insertions(+), 28 deletions(-)
diff --git a/dlls/advapi32/security.c b/dlls/advapi32/security.c
index 86b0adf..69d4a6b 100644
--- a/dlls/advapi32/security.c
+++ b/dlls/advapi32/security.c
@@ -2531,43 +2531,57 @@ BOOL WINAPI LookupAccountNameW( LPCWSTR lpSystemName, LPCWSTR lpAccountName, PSI
DWORD nameLen;
LPWSTR userName = NULL;
LPWSTR computerName = NULL;
- LPCWSTR domainName = NULL;
- SID_NAME_USE sidUse = 0;
+ LPCWSTR domainName;
+ SID_NAME_USE sidUse = SidTypeUser;
TRACE("%s %s %p %p %p %p %p - stub\n", debugstr_w(lpSystemName), debugstr_w(lpAccountName),
Sid, cbSid, ReferencedDomainName, cchReferencedDomainName, peUse);
- if (!ADVAPI_IsLocalComputer(lpSystemName))
- {
- FIXME("Only local computer supported!\n");
- SetLastError(RPC_S_SERVER_UNAVAILABLE);
- return FALSE;
- }
+ /* Anticipate the need for the computer name (doubling as local domain name) */
- if (!lpAccountName || !lstrcmpW(lpAccountName, Blank))
- {
- lpAccountName = BUILTIN;
- }
+ nameLen = MAX_COMPUTERNAME_LENGTH + 1;
- /* Check well known SIDs first */
+ computerName = HeapAlloc(GetProcessHeap(), 0, nameLen * sizeof(WCHAR));
- for (i = 0; i < (sizeof(ACCOUNT_SIDS) / sizeof(ACCOUNT_SIDS[0])); i++)
+ if (!GetComputerNameW(computerName, &nameLen))
+ computerName[0] = 0;
+
+ if (computerName[0] == '\\' && computerName[1] == '\\')
+ domainName = computerName + 2;
+ else
+ domainName = computerName;
+
+ /* Check system name, if given */
+
+ if (lpSystemName && lpSystemName[0])
{
- if (!lstrcmpW(lpAccountName, ACCOUNT_SIDS[i].account))
+ if (lstrcmpW(lpSystemName, computerName))
{
- sidLen = SECURITY_MAX_SID_SIZE;
-
- pSid = HeapAlloc(GetProcessHeap(), 0, sidLen);
+ FIXME("Only local computer supported!\n");
+ SetLastError(RPC_S_SERVER_UNAVAILABLE);
+ return FALSE;
+ }
+ }
- ret = CreateWellKnownSid(ACCOUNT_SIDS[i].type, NULL, pSid, &sidLen);
+ /* Check for domain\account */
- domainName = ACCOUNT_SIDS[i].domain;
+ if (lpAccountName && lpAccountName[0])
+ {
+ for (i = 0; lpAccountName[i]; i++)
+ {
+ if (lpAccountName[i] == domainName[i])
+ continue;
- sidUse = ACCOUNT_SIDS[i].name_use;
+ if (lpAccountName[i] == '\\' && domainName[i] == 0)
+ lpAccountName += i + 1;
break;
}
}
+ else
+ {
+ lpAccountName = BUILTIN;
+ }
if (pSid == NULL)
{
@@ -2575,7 +2589,7 @@ BOOL WINAPI LookupAccountNameW( LPCWSTR lpSystemName, LPCWSTR lpAccountName, PSI
nameLen = UNLEN + 1;
- userName = HeapAlloc(GetProcessHeap(), 0, nameLen);
+ userName = HeapAlloc(GetProcessHeap(), 0, nameLen * sizeof(WCHAR));
ret = GetUserNameW(userName, &nameLen);
@@ -2600,18 +2614,29 @@ BOOL WINAPI LookupAccountNameW( LPCWSTR lpSystemName, LPCWSTR lpAccountName, PSI
sidLen = GetSidLengthRequired(max_sid->SubAuthorityCount);
}
+ }
+ }
+
+ if (pSid == NULL)
+ {
+ /* Check well known SIDs */
- /* Let the computer name be the domain name */
+ for (i = 0; i < (sizeof(ACCOUNT_SIDS) / sizeof(ACCOUNT_SIDS[0])); i++)
+ {
+ if (!lstrcmpW(lpAccountName, ACCOUNT_SIDS[i].account))
+ {
+ sidLen = SECURITY_MAX_SID_SIZE;
- nameLen = MAX_COMPUTERNAME_LENGTH + 1;
+ pSid = HeapAlloc(GetProcessHeap(), 0, sidLen);
- computerName = HeapAlloc(GetProcessHeap(), 0, nameLen * sizeof(WCHAR));
+ ret = CreateWellKnownSid(ACCOUNT_SIDS[i].type, NULL, pSid, &sidLen);
- ret &= GetComputerNameW(computerName, &nameLen);
+ domainName = ACCOUNT_SIDS[i].domain;
- domainName = computerName;
+ sidUse = ACCOUNT_SIDS[i].name_use;
- sidUse = SidTypeUser;
+ break;
+ }
}
}
diff --git a/dlls/advapi32/tests/security.c b/dlls/advapi32/tests/security.c
index c411349..dc4c63d 100644
--- a/dlls/advapi32/tests/security.c
+++ b/dlls/advapi32/tests/security.c
@@ -1507,6 +1507,7 @@ static void test_LookupAccountName(void)
DWORD sid_save, domain_save;
CHAR user_name[UNLEN + 1];
CHAR computer_name[MAX_COMPUTERNAME_LENGTH + 1];
+ CHAR domain_account[UNLEN + 1];
SID_NAME_USE sid_use;
LPSTR domain, account, sid_dom;
PSID psid;
@@ -1585,6 +1586,20 @@ static void test_LookupAccountName(void)
domain_size = domain_save;
sid_size = sid_save;
+ /* try domain\account form */
+ strcat (strcat (strcpy (domain_account, domain), "\\"), user_name);
+ ret = LookupAccountNameA(NULL, domain_account, 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, got %d\n", sid_use);
+ domain_size = domain_save;
+ sid_size = sid_save;
+
if (PRIMARYLANGID(LANGIDFROMLCID(GetThreadLocale())) != LANG_ENGLISH)
{
skip("Non-english locale (test with hardcoded 'Everyone')\n");
--
1.5.4.3
--------------000909010804010703070903--
More information about the wine-patches
mailing list