[MSV1_0]
authorEric Kohl <eric.kohl@reactos.org>
Sat, 28 Dec 2013 23:47:04 +0000 (23:47 +0000)
committerEric Kohl <eric.kohl@reactos.org>
Sat, 28 Dec 2013 23:47:04 +0000 (23:47 +0000)
- Code clean-up.
- Take the user RID and pimary group RID from the user info data.

svn path=/trunk/; revision=61460

reactos/dll/win32/msv1_0/msv1_0.c

index b7ef433..ad9bc89 100644 (file)
@@ -257,7 +257,7 @@ BuildTokenUser(OUT PTOKEN_USER User,
     if (User->User.Sid == NULL)
     {
         ERR("Could not create the user SID\n");
-        return STATUS_UNSUCCESSFUL;
+        return STATUS_INSUFFICIENT_RESOURCES;
     }
 
     User->User.Attributes = 0;
@@ -268,10 +268,26 @@ BuildTokenUser(OUT PTOKEN_USER User,
 
 static
 NTSTATUS
-BuildTokenGroups(IN PSID AccountDomainSid,
-                 IN PLUID LogonId,
-                 OUT PTOKEN_GROUPS *Groups,
-                 OUT PSID *PrimaryGroupSid)
+BuildTokenPrimaryGroup(OUT PTOKEN_PRIMARY_GROUP PrimaryGroup,
+                       IN PSID AccountDomainSid,
+                       IN ULONG RelativeId)
+{
+    PrimaryGroup->PrimaryGroup = AppendRidToSid(AccountDomainSid,
+                                                RelativeId);
+    if (PrimaryGroup->PrimaryGroup == NULL)
+    {
+        ERR("Could not create the primary group SID\n");
+        return STATUS_INSUFFICIENT_RESOURCES;
+    }
+
+    return STATUS_SUCCESS;
+}
+
+
+static
+NTSTATUS
+BuildTokenGroups(OUT PTOKEN_GROUPS *Groups,
+                 IN PSID AccountDomainSid)
 {
     SID_IDENTIFIER_AUTHORITY SystemAuthority = {SECURITY_NT_AUTHORITY};
     PTOKEN_GROUPS TokenGroups;
@@ -297,7 +313,6 @@ BuildTokenGroups(IN PSID AccountDomainSid,
     TokenGroups->Groups[GroupCount].Sid = Sid;
     TokenGroups->Groups[GroupCount].Attributes =
         SE_GROUP_ENABLED | SE_GROUP_ENABLED_BY_DEFAULT | SE_GROUP_MANDATORY;
-    *PrimaryGroupSid = Sid;
     GroupCount++;
 
 
@@ -366,30 +381,6 @@ BuildTokenGroups(IN PSID AccountDomainSid,
 }
 
 
-static
-NTSTATUS
-BuildTokenPrimaryGroup(PTOKEN_PRIMARY_GROUP PrimaryGroup,
-                       PSID PrimaryGroupSid)
-{
-    ULONG RidCount;
-    ULONG Size;
-
-    RidCount = *RtlSubAuthorityCountSid(PrimaryGroupSid);
-    Size = RtlLengthRequiredSid(RidCount);
-
-    PrimaryGroup->PrimaryGroup = DispatchTable.AllocateLsaHeap(Size);
-    if (PrimaryGroup->PrimaryGroup == NULL)
-    {
-        return STATUS_INSUFFICIENT_RESOURCES;
-    }
-
-    RtlCopyMemory(PrimaryGroup->PrimaryGroup,
-                  PrimaryGroupSid,
-                  Size);
-
-    return STATUS_SUCCESS;
-}
-
 static
 NTSTATUS
 BuildTokenPrivileges(PTOKEN_PRIVILEGES *TokenPrivileges)
@@ -480,11 +471,9 @@ static
 NTSTATUS
 BuildTokenInformationBuffer(PLSA_TOKEN_INFORMATION_V1 *TokenInformation,
                             PRPC_SID AccountDomainSid,
-                            ULONG RelativeId,
-                            PLUID LogonId)
+                            PSAMPR_USER_INFO_BUFFER UserInfo)
 {
     PLSA_TOKEN_INFORMATION_V1 Buffer = NULL;
-    PSID PrimaryGroupSid = NULL;
     ULONG i;
     NTSTATUS Status = STATUS_SUCCESS;
 
@@ -501,19 +490,18 @@ BuildTokenInformationBuffer(PLSA_TOKEN_INFORMATION_V1 *TokenInformation,
 
     Status = BuildTokenUser(&Buffer->User,
                             (PSID)AccountDomainSid,
-                            RelativeId);
+                            UserInfo->All.UserId);
     if (!NT_SUCCESS(Status))
         goto done;
 
-    Status = BuildTokenGroups((PSID)AccountDomainSid,
-                              LogonId,
-                              &Buffer->Groups,
-                              &PrimaryGroupSid);
+    Status = BuildTokenPrimaryGroup(&Buffer->PrimaryGroup,
+                                    (PSID)AccountDomainSid,
+                                    UserInfo->All.PrimaryGroupId);
     if (!NT_SUCCESS(Status))
         goto done;
 
-    Status = BuildTokenPrimaryGroup(&Buffer->PrimaryGroup,
-                                    PrimaryGroupSid);
+    Status = BuildTokenGroups(&Buffer->Groups,
+                              (PSID)AccountDomainSid);
     if (!NT_SUCCESS(Status))
         goto done;
 
@@ -1047,8 +1035,7 @@ LsaApLogonUser(IN PLSA_CLIENT_REQUEST ClientRequest,
     /* Build and fill the token information buffer */
     Status = BuildTokenInformationBuffer((PLSA_TOKEN_INFORMATION_V1*)TokenInformation,
                                          AccountDomainSid,
-                                         RelativeIds.Element[0],
-                                         LogonId);
+                                         UserInfo);
     if (!NT_SUCCESS(Status))
     {
         TRACE("BuildTokenInformationBuffer failed (Status %08lx)\n", Status);