From c3168d10e5bd15b877ccfc5f6f6a54e23ac7cc4b Mon Sep 17 00:00:00 2001 From: Royce Mitchell III Date: Tue, 14 Dec 2004 06:40:50 +0000 Subject: [PATCH] implemented LookupAccountSidW() thx to the help of Alex Ionescu - this function is needed for GetUserNameA/W(). svn path=/trunk/; revision=12114 --- reactos/lib/advapi32/sec/misc.c | 116 +++++++++++++++++++++++--------- 1 file changed, 86 insertions(+), 30 deletions(-) diff --git a/reactos/lib/advapi32/sec/misc.c b/reactos/lib/advapi32/sec/misc.c index 030a6de4a5f..270237f8df5 100644 --- a/reactos/lib/advapi32/sec/misc.c +++ b/reactos/lib/advapi32/sec/misc.c @@ -1,4 +1,4 @@ -/* $Id: misc.c,v 1.30 2004/12/13 19:06:28 weiden Exp $ +/* $Id: misc.c,v 1.31 2004/12/14 06:40:50 royce Exp $ * * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS system libraries @@ -9,6 +9,7 @@ #include "advapi32.h" #include #include +#include #define NDEBUG #include @@ -666,40 +667,95 @@ LookupAccountSidA (LPCSTR lpSystemName, /****************************************************************************** * LookupAccountSidW [ADVAPI32.@] * - * @unimplemented + * @implemented */ -BOOL STDCALL -LookupAccountSidW (LPCWSTR lpSystemName, - PSID lpSid, - LPWSTR lpName, - LPDWORD cchName, - LPWSTR lpReferencedDomainName, - LPDWORD cchReferencedDomainName, - PSID_NAME_USE peUse) +BOOL WINAPI +LookupAccountSidW ( + LPCWSTR pSystemName, + PSID pSid, + LPWSTR pAccountName, + LPDWORD pdwAccountName, + LPWSTR pDomainName, + LPDWORD pdwDomainName, + PSID_NAME_USE peUse ) { - DWORD NameLength; - DWORD DomainLength; - - DPRINT1("LookupAccountSidW is unimplemented, but returns success\n"); - - /* Calculate length needed */ - NameLength = wcslen(L"Administrator") + sizeof(WCHAR); - DomainLength = wcslen(L"BUILTIN") + sizeof(WCHAR); - - if (*cchName < NameLength || *cchReferencedDomainName < DomainLength) - { - *cchName = NameLength; - *cchReferencedDomainName = DomainLength; - SetLastError(ERROR_INSUFFICIENT_BUFFER); - return FALSE; - } - - if (lpName) lstrcpynW(lpName, L"Administrator", *cchName); - if (lpReferencedDomainName) lstrcpynW(lpReferencedDomainName, L"BUILTIN", *cchReferencedDomainName); - return TRUE; + LSA_UNICODE_STRING SystemName; + LSA_OBJECT_ATTRIBUTES ObjectAttributes; + LSA_HANDLE PolicyHandle = INVALID_HANDLE_VALUE; + NTSTATUS Status; + PLSA_REFERENCED_DOMAIN_LIST ReferencedDomain = NULL; + PLSA_TRANSLATED_NAME TranslatedName = NULL; + BOOL ret; + + RtlInitUnicodeString ( &SystemName, pSystemName ); + ZeroMemory(&ObjectAttributes, sizeof(ObjectAttributes)); + Status = LsaOpenPolicy ( &SystemName, &ObjectAttributes, POLICY_LOOKUP_NAMES, &PolicyHandle ); + if ( !SUCCEEDED(Status) ) + { + SetLastError ( LsaNtStatusToWinError(Status) ); + return FALSE; + } + Status = LsaLookupSids ( PolicyHandle, 1, &pSid, &ReferencedDomain, &TranslatedName ); + + LsaClose ( PolicyHandle ); + + if ( Status != 0 /* STATUS_SUCCESS */ ) + { + SetLastError ( LsaNtStatusToWinError(Status) ); + ret = FALSE; + } + else + { + ret = TRUE; + if ( TranslatedName ) + { + DWORD dwSrcLen = TranslatedName->Name.Length / sizeof(WCHAR); + if ( *pdwAccountName <= dwSrcLen ) + { + *pdwAccountName = dwSrcLen + 1; + ret = FALSE; + } + else + { + *pdwAccountName = dwSrcLen; + wcscpy ( pAccountName, TranslatedName->Name.Buffer ); + } + if ( peUse ) + *peUse = TranslatedName->Use; + } + + if ( ReferencedDomain ) + { + if ( ReferencedDomain->Entries > 0 ) + { + DWORD dwSrcLen = ReferencedDomain->Domains[0].Name.Length / sizeof(WCHAR); + if ( *pdwDomainName <= dwSrcLen ) + { + *pdwDomainName = dwSrcLen + 1; + ret = FALSE; + } + else + { + *pdwDomainName = dwSrcLen; + wcscpy ( pDomainName, ReferencedDomain->Domains[0].Name.Buffer ); + } + } + } + + if ( !ret ) + SetLastError(ERROR_INSUFFICIENT_BUFFER); + } + + if ( ReferencedDomain ) + LsaFreeMemory ( ReferencedDomain ); + if ( TranslatedName ) + LsaFreeMemory ( TranslatedName ); + + return ret; } + /****************************************************************************** * LookupAccountNameA [ADVAPI32.@] *