Juan Lang : advapi32: Support the computer name as an account name in LookupAccountNameW.
Alexandre Julliard
julliard at winehq.org
Thu Feb 5 09:21:21 CST 2009
Module: wine
Branch: master
Commit: fc5ea773e5f78049a7fa6f989d9f79a0d5933c97
URL: http://source.winehq.org/git/wine.git/?a=commit;h=fc5ea773e5f78049a7fa6f989d9f79a0d5933c97
Author: Juan Lang <juan.lang at gmail.com>
Date: Wed Feb 4 13:20:39 2009 -0800
advapi32: Support the computer name as an account name in LookupAccountNameW.
---
dlls/advapi32/security.c | 179 ++++++++++++++++++++++++++--------------
dlls/advapi32/tests/security.c | 1 -
2 files changed, 118 insertions(+), 62 deletions(-)
diff --git a/dlls/advapi32/security.c b/dlls/advapi32/security.c
index ee06270..d62bb23 100644
--- a/dlls/advapi32/security.c
+++ b/dlls/advapi32/security.c
@@ -2531,17 +2531,119 @@ LookupAccountNameA(
}
/******************************************************************************
+ * lookup_user_account_name
+ */
+static BOOL lookup_user_account_name(PSID Sid, PDWORD 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};
+ DWORD nameLen;
+ LPCWSTR domainName;
+
+ ret = AllocateAndInitializeSid(&identifierAuthority,
+ 2,
+ SECURITY_BUILTIN_DOMAIN_RID,
+ DOMAIN_ALIAS_RID_ADMINS,
+ 0, 0, 0, 0, 0, 0,
+ &pSid);
+
+ if (!ret)
+ return FALSE;
+
+ if (!RtlValidSid(pSid))
+ {
+ FreeSid(pSid);
+ return FALSE;
+ }
+
+ if (Sid != NULL && (*cbSid >= GetLengthSid(pSid)))
+ CopySid(*cbSid, Sid, pSid);
+ if (*cbSid < GetLengthSid(pSid))
+ {
+ SetLastError(ERROR_INSUFFICIENT_BUFFER);
+ ret = FALSE;
+ }
+ *cbSid = GetLengthSid(pSid);
+
+ domainName = dm;
+ nameLen = strlenW(domainName);
+
+ if (*cchReferencedDomainName <= nameLen || !ret)
+ {
+ SetLastError(ERROR_INSUFFICIENT_BUFFER);
+ nameLen += 1;
+ ret = FALSE;
+ }
+ else if (ReferencedDomainName)
+ strcpyW(ReferencedDomainName, domainName);
+
+ *cchReferencedDomainName = nameLen;
+
+ if (ret)
+ *peUse = SidTypeUser;
+
+ FreeSid(pSid);
+
+ return ret;
+}
+
+/******************************************************************************
+ * lookup_computer_account_name
+ */
+static BOOL lookup_computer_account_name(PSID Sid, PDWORD cbSid, LPWSTR ReferencedDomainName,
+ LPDWORD cchReferencedDomainName, PSID_NAME_USE peUse )
+{
+ MAX_SID local;
+ BOOL ret;
+ static const WCHAR dm[] = {'D','O','M','A','I','N',0};
+ DWORD nameLen;
+ LPCWSTR domainName;
+
+ if ((ret = ADVAPI_GetComputerSid(&local)))
+ {
+ if (Sid != NULL && (*cbSid >= GetLengthSid(&local)))
+ CopySid(*cbSid, Sid, &local);
+ if (*cbSid < GetLengthSid(&local))
+ {
+ SetLastError(ERROR_INSUFFICIENT_BUFFER);
+ ret = FALSE;
+ }
+ *cbSid = GetLengthSid(&local);
+ }
+
+ domainName = dm;
+ nameLen = strlenW(domainName);
+
+ if (*cchReferencedDomainName <= nameLen || !ret)
+ {
+ SetLastError(ERROR_INSUFFICIENT_BUFFER);
+ nameLen += 1;
+ ret = FALSE;
+ }
+ else if (ReferencedDomainName)
+ strcpyW(ReferencedDomainName, domainName);
+
+ *cchReferencedDomainName = nameLen;
+
+ if (ret)
+ *peUse = SidTypeDomain;
+
+ return ret;
+}
+
+/******************************************************************************
* LookupAccountNameW [ADVAPI32.@]
*/
BOOL WINAPI LookupAccountNameW( LPCWSTR lpSystemName, LPCWSTR lpAccountName, PSID Sid,
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 nameLen;
LPWSTR userName = NULL;
@@ -2621,69 +2723,24 @@ BOOL WINAPI LookupAccountNameW( LPCWSTR lpSystemName, LPCWSTR lpAccountName, PSI
userName = HeapAlloc(GetProcessHeap(), 0, nameLen);
- ret = GetUserNameW(userName, &nameLen);
-
- if (ret && strcmpW(lpAccountName, userName) != 0)
+ if (GetUserNameW(userName, &nameLen) && !strcmpW(lpAccountName, userName))
+ ret = lookup_user_account_name(Sid, cbSid, ReferencedDomainName,
+ cchReferencedDomainName, peUse);
+ else
{
- SetLastError(ERROR_NONE_MAPPED);
- ret = FALSE;
+ nameLen = UNLEN + 1;
+ if (GetComputerNameW(userName, &nameLen) && !strcmpW(lpAccountName, userName))
+ ret = lookup_computer_account_name(Sid, cbSid, ReferencedDomainName,
+ cchReferencedDomainName, peUse);
+ else
+ {
+ SetLastError(ERROR_NONE_MAPPED);
+ ret = FALSE;
+ }
}
HeapFree(GetProcessHeap(), 0, userName);
- if (!ret)
- {
- return ret;
- }
-
- ret = AllocateAndInitializeSid(&identifierAuthority,
- 2,
- SECURITY_BUILTIN_DOMAIN_RID,
- DOMAIN_ALIAS_RID_ADMINS,
- 0, 0, 0, 0, 0, 0,
- &pSid);
-
- if (!ret)
- return FALSE;
-
- if (!RtlValidSid(pSid))
- {
- FreeSid(pSid);
- return FALSE;
- }
-
- if (Sid != NULL && (*cbSid >= GetLengthSid(pSid)))
- CopySid(*cbSid, Sid, pSid);
- if (*cbSid < GetLengthSid(pSid))
- {
- SetLastError(ERROR_INSUFFICIENT_BUFFER);
- ret = FALSE;
- }
- *cbSid = GetLengthSid(pSid);
-
- domainName = dm;
- nameLen = strlenW(domainName);
-
- if (*cchReferencedDomainName <= nameLen || !ret)
- {
- SetLastError(ERROR_INSUFFICIENT_BUFFER);
- nameLen += 1;
- ret = FALSE;
- }
- else if (ReferencedDomainName)
- {
- strcpyW(ReferencedDomainName, domainName);
- }
-
- *cchReferencedDomainName = nameLen;
-
- if (ret)
- {
- *peUse = SidTypeUser;
- }
-
- FreeSid(pSid);
-
return ret;
}
diff --git a/dlls/advapi32/tests/security.c b/dlls/advapi32/tests/security.c
index 8ca4d54..a681cb1 100644
--- a/dlls/advapi32/tests/security.c
+++ b/dlls/advapi32/tests/security.c
@@ -1883,7 +1883,6 @@ static void test_LookupAccountName(void)
sid_size = 0;
domain_size = 0;
ret = LookupAccountNameA(NULL, computer_name, NULL, &sid_size, NULL, &domain_size, &sid_use);
- todo_wine
ok(!ret && (GetLastError() == ERROR_INSUFFICIENT_BUFFER ||
broken(GetLastError() == ERROR_TRUSTED_DOMAIN_FAILURE) ||
broken(GetLastError() == ERROR_TRUSTED_RELATIONSHIP_FAILURE)),
More information about the wine-cvs
mailing list