From 77d43d721793edda9b419f7426442a35f0cb5918 Mon Sep 17 00:00:00 2001
From: Qian Hong <qhong@codeweavers.com>
Date: Tue, 7 Apr 2015 11:23:34 +0800
Subject: advapi32: Fallback to Sid string when LookupAccountSid fails.

---
 dlls/advapi32/lsa.c | 31 +++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)

diff --git a/dlls/advapi32/lsa.c b/dlls/advapi32/lsa.c
index 1b270a80829..b8dedbd6d58 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"
@@ -562,6 +563,21 @@ NTSTATUS WINAPI LsaLookupSids(
                 domain.MaximumLength = sizeof(WCHAR);
             }
         }
+        else
+        {
+            WCHAR *strsid = NULL;
+
+            if (ConvertSidToStringSidW(Sids[i], &strsid))
+            {
+                name_size = strlenW(strsid) + 1;
+
+                (*Names)[i].Name.Length = (name_size - 1) * sizeof(WCHAR);
+                (*Names)[i].Name.MaximumLength = name_size * sizeof(WCHAR);
+                name_fullsize += (*Names)[i].Name.MaximumLength;
+
+                LocalFree(strsid);
+            }
+        }
     }
 
     /* now we have full length needed for both */
@@ -605,6 +621,21 @@ NTSTATUS WINAPI LsaLookupSids(
             (*Names)[i].DomainIndex = lsa_reflist_add_domain(*ReferencedDomains, &domain, &domain_data);
             heap_free(domain.Buffer);
         }
+        else
+        {
+            WCHAR *strsid = NULL;
+
+            if (ConvertSidToStringSidW(Sids[i], &strsid))
+            {
+                name_size = strlenW(strsid) + 1;
+                mapped++;
+
+                (*Names)[i].Name.Buffer = name_buffer;
+                memcpy((*Names)[i].Name.Buffer, strsid, name_size * sizeof(WCHAR));
+
+                LocalFree(strsid);
+            }
+        }
 
         name_buffer += name_size;
     }
-- 
2.11.0