advapi32: add computer sid support to LookupAccountSidW

Robert Reif reif at earthlink.net
Sat Jul 29 08:40:02 CDT 2006


Applies on top of previous patches.
-------------- next part --------------
--- wine.cvs/dlls/advapi32/security.c	2006-07-29 09:35:52.000000000 -0400
+++ wine/dlls/advapi32//security.c	2006-07-29 09:33:27.000000000 -0400
@@ -143,6 +143,7 @@ static const WCHAR DIALUP[] = { 'D','I',
 static const WCHAR DOMAIN[] = {'D','O','M','A','I','N',0};
 static const WCHAR ENTERPRISE_DOMAIN_CONTROLLERS[] = { 'E','N','T','E','R','P','R','I','S','E',' ','D','O','M','A','I','N',' ','C','O','N','T','R','O','L','L','E','R','S',0 };
 static const WCHAR Everyone[] = { 'E','v','e','r','y','o','n','e',0 };
+static const WCHAR Guest[] = { 'G','u','e','s','t',0 };
 static const WCHAR Guests[] = { 'G','u','e','s','t','s',0 };
 static const WCHAR INTERACTIVE[] = { 'I','N','T','E','R','A','C','T','I','V','E',0 };
 static const WCHAR LOCAL[] = { 'L','O','C','A','L',0 };
@@ -1836,9 +1837,9 @@ LookupAccountSidW(
 	OUT PSID_NAME_USE name_use )
 {
     int i, j;
-    const WCHAR * ac = Administrator;	/* FIXME */
-    const WCHAR * dm = DOMAIN;		/* FIXME */
-    SID_NAME_USE use = SidTypeUser;	/* FIXME */
+    const WCHAR * ac = NULL;
+    const WCHAR * dm = NULL;
+    SID_NAME_USE use = 0;
 
     TRACE("(%s,sid=%s,%p,%p(%lu),%p,%p(%lu),%p)\n",
 	  debugstr_w(system),debugstr_sid(sid),
@@ -1851,7 +1852,8 @@ LookupAccountSidW(
         SetLastError(ERROR_NONE_MAPPED);
         return FALSE;
     }
-    
+
+    /* check the well known SIDs first */
     for (i = 0; i <= 60; i++) {
         if (IsWellKnownSid(sid, i)) {
             for (j = 0; j < (sizeof(ACCOUNT_SIDS) / sizeof(ACCOUNT_SIDS[0])); j++) {
@@ -1865,16 +1867,51 @@ LookupAccountSidW(
         }
     }
 
-    *accountSize = strlenW(ac)+1;
-    if (account && (*accountSize > strlenW(ac)))
-        strcpyW(account, ac);
-
-    *domainSize = strlenW(dm)+1;
-    if (domain && (*domainSize > strlenW(dm)))
-        strcpyW(domain,dm);
+    if (dm == NULL) {
+        MAX_SID local;
+        MAX_SID admin;
+        MAX_SID guest;
+
+        /* check for the local computer next */
+        if (ADVAPI_GetComputerSid(&local)) {
+            CopySid(GetSidLengthRequired(local.SubAuthorityCount), &admin, &local);
+            admin.SubAuthorityCount++;
+            admin.SubAuthority[4] = DOMAIN_USER_RID_ADMIN;
+            CopySid(GetSidLengthRequired(local.SubAuthorityCount), &guest, &local);
+            guest.SubAuthorityCount++;
+            guest.SubAuthority[4] = DOMAIN_USER_RID_GUEST;
+
+            if (EqualSid(sid, &local)) {
+                dm = ADVAPI_GetComputerNameW();
+                ac = Blank;
+                use = 3;
+            } else if (EqualSid(sid, &admin)) {
+                dm = ADVAPI_GetComputerNameW();
+                ac = Administrator;
+                use = 1;
+            } else if (EqualSid(sid, &guest)) {
+                dm = ADVAPI_GetComputerNameW();
+                ac = Guest;
+                use = 1;
+            }
+        }
+    }
 
-    *name_use = use;
-    return TRUE;
+    if (dm) {
+        *accountSize = strlenW(ac)+1;
+        if (account && (*accountSize > strlenW(ac)))
+            strcpyW(account, ac);
+
+        *domainSize = strlenW(dm)+1;
+        if (domain && (*domainSize > strlenW(dm)))
+            strcpyW(domain,dm);
+
+        *name_use = use;
+        return TRUE;
+    }
+
+    SetLastError(ERROR_NONE_MAPPED);
+    return FALSE;
 }
 
 /******************************************************************************


More information about the wine-patches mailing list