[PATCH 2/2] advapi32: Return the string SID if LookupAccountSid() fails.

Zebediah Figura z.figura12 at gmail.com
Sat Feb 1 12:10:17 CST 2020


Based on a patch by Qian Hong.

Signed-off-by: Zebediah Figura <z.figura12 at gmail.com>
---
I know of no application that requires this.

The patch was originally sent as part of a set in which some patches were
labeled as for Cygwin:

https://www.winehq.org/pipermail/wine-patches/2015-April/138518.html

However, Cygwin is currently too broken in Wine to test.

 dlls/advapi32/lsa.c       | 20 ++++++++++++++++++--
 dlls/advapi32/tests/lsa.c |  1 +
 2 files changed, 19 insertions(+), 2 deletions(-)

diff --git a/dlls/advapi32/lsa.c b/dlls/advapi32/lsa.c
index ce3a6e94bf9..906beffb036 100644
--- a/dlls/advapi32/lsa.c
+++ b/dlls/advapi32/lsa.c
@@ -29,6 +29,7 @@
 #include "winbase.h"
 #include "winreg.h"
 #include "winternl.h"
+#include "sddl.h"
 #include "advapi32_misc.h"
 
 #include "wine/debug.h"
@@ -482,6 +483,7 @@ NTSTATUS WINAPI LsaLookupSids(
     WCHAR *name_buffer;
     char *domain_data;
     SID_NAME_USE use;
+    WCHAR *strsid;
 
     TRACE("(%p, %u, %p, %p, %p)\n", PolicyHandle, Count, Sids, ReferencedDomains, Names);
 
@@ -557,6 +559,14 @@ NTSTATUS WINAPI LsaLookupSids(
                 domain.MaximumLength = sizeof(WCHAR);
             }
         }
+        else if (ConvertSidToStringSidW(Sids[i], &strsid))
+        {
+            (*Names)[i].Name.Length = strlenW(strsid) * sizeof(WCHAR);
+            (*Names)[i].Name.MaximumLength = (strlenW(strsid) + 1) * sizeof(WCHAR);
+            name_fullsize += (strlenW(strsid) + 1) * sizeof(WCHAR);
+
+            LocalFree(strsid);
+        }
     }
 
     /* now we have full length needed for both */
@@ -573,6 +583,8 @@ NTSTATUS WINAPI LsaLookupSids(
     {
         name_size = domain_size = 0;
 
+        (*Names)[i].Name.Buffer = name_buffer;
+
         if (!LookupAccountSidW(NULL, Sids[i], NULL, &name_size, NULL, &domain_size, &use) &&
             GetLastError() == ERROR_INSUFFICIENT_BUFFER)
         {
@@ -592,15 +604,19 @@ NTSTATUS WINAPI LsaLookupSids(
 
             domain.Buffer = heap_alloc(domain.MaximumLength);
 
-            (*Names)[i].Name.Buffer = name_buffer;
             LookupAccountSidW(NULL, Sids[i], (*Names)[i].Name.Buffer, &name_size, domain.Buffer, &domain_size, &use);
             (*Names)[i].Use = use;
 
             (*Names)[i].DomainIndex = lsa_reflist_add_domain(*ReferencedDomains, &domain, &domain_data);
             heap_free(domain.Buffer);
         }
+        else if (ConvertSidToStringSidW(Sids[i], &strsid))
+        {
+            strcpyW((*Names)[i].Name.Buffer, strsid);
+            LocalFree(strsid);
+        }
 
-        name_buffer += name_size;
+        name_buffer += strlenW(name_buffer) + 1;
     }
     TRACE("mapped %u out of %u\n", mapped, Count);
 
diff --git a/dlls/advapi32/tests/lsa.c b/dlls/advapi32/tests/lsa.c
index 7b8f6b8e849..57ec8994eb7 100644
--- a/dlls/advapi32/tests/lsa.c
+++ b/dlls/advapi32/tests/lsa.c
@@ -403,6 +403,7 @@ static void test_LsaLookupSids(void)
 
     ok(names[0].Use == SidTypeUnknown, "got type %u\n", names[0].Use);
     ok(names[0].DomainIndex == -1, "got index %u\n", names[0].DomainIndex);
+    check_unicode_string(&names[0].Name, L"S-1-1234-5678-1234-5678");
 
     LsaFreeMemory(names);
     LsaFreeMemory(list);
-- 
2.25.0




More information about the wine-devel mailing list