[NETAPI32]
authorEric Kohl <eric.kohl@reactos.org>
Sat, 1 Mar 2014 11:37:23 +0000 (11:37 +0000)
committerEric Kohl <eric.kohl@reactos.org>
Sat, 1 Mar 2014 11:37:23 +0000 (11:37 +0000)
- NetUserSetInfo: Implement the info level 22.
- Update the users DACL according to the user flags for the info levels 1, 2, 3, 4, 22 and 1008.

svn path=/trunk/; revision=62364

reactos/dll/win32/netapi32/user.c

index 6452a4a..01d787a 100644 (file)
@@ -250,6 +250,28 @@ GetPasswordAge(IN PLARGE_INTEGER PasswordLastSet)
 }
 
 
+static
+VOID
+ChangeUserDacl(IN PACL Dacl,
+               IN ULONG Flags)
+{
+    PACCESS_ALLOWED_ACE Ace = NULL;
+    NTSTATUS Status;
+
+    if (Dacl == NULL)
+        return;
+
+    Status = GetAllowedWorldAce(Dacl, &Ace);
+    if (!NT_SUCCESS(Status))
+        return;
+
+    if (Flags & UF_PASSWD_CANT_CHANGE)
+        Ace->Mask &= ~USER_CHANGE_PASSWORD;
+    else
+        Ace->Mask |= USER_CHANGE_PASSWORD;
+}
+
+
 static
 NET_API_STATUS
 GetUserDacl(IN SAM_HANDLE UserHandle,
@@ -1511,6 +1533,7 @@ SetUserInfo(SAM_HANDLE UserHandle,
     PUSER_INFO_2 UserInfo2;
     PUSER_INFO_3 UserInfo3;
     PUSER_INFO_4 UserInfo4;
+    PUSER_INFO_22 UserInfo22;
     PUSER_INFO_1003 UserInfo1003;
     PUSER_INFO_1006 UserInfo1006;
     PUSER_INFO_1007 UserInfo1007;
@@ -1527,11 +1550,20 @@ SetUserInfo(SAM_HANDLE UserHandle,
     PUSER_INFO_1051 UserInfo1051;
     PUSER_INFO_1052 UserInfo1052;
     PUSER_INFO_1053 UserInfo1053;
+    PACL Dacl = NULL;
     NET_API_STATUS ApiStatus = NERR_Success;
     NTSTATUS Status = STATUS_SUCCESS;
 
     ZeroMemory(&UserAllInfo, sizeof(USER_ALL_INFORMATION));
 
+    if ((Level == 1) || (Level == 2) || (Level == 3) ||
+        (Level == 4) || (Level == 22) || (Level == 1008))
+    {
+        ApiStatus = GetUserDacl(UserHandle, &Dacl);
+        if (ApiStatus != NERR_Success)
+            goto done;
+    }
+
     switch (Level)
     {
         case 0:
@@ -1574,6 +1606,7 @@ SetUserInfo(SAM_HANDLE UserHandle,
                 UserAllInfo.WhichFields |= USER_ALL_ADMINCOMMENT;
             }
 
+            ChangeUserDacl(Dacl, UserInfo1->usri1_flags);
             UserAllInfo.UserAccountControl = GetAccountControl(UserInfo1->usri1_flags);
             UserAllInfo.WhichFields |= USER_ALL_USERACCOUNTCONTROL;
 
@@ -1616,6 +1649,7 @@ SetUserInfo(SAM_HANDLE UserHandle,
                 UserAllInfo.WhichFields |= USER_ALL_ADMINCOMMENT;
             }
 
+            ChangeUserDacl(Dacl, UserInfo2->usri2_flags);
             UserAllInfo.UserAccountControl = GetAccountControl(UserInfo2->usri2_flags);
             UserAllInfo.WhichFields |= USER_ALL_USERACCOUNTCONTROL;
 
@@ -1718,6 +1752,7 @@ SetUserInfo(SAM_HANDLE UserHandle,
                 UserAllInfo.WhichFields |= USER_ALL_ADMINCOMMENT;
             }
 
+            ChangeUserDacl(Dacl, UserInfo3->usri3_flags);
             UserAllInfo.UserAccountControl = GetAccountControl(UserInfo3->usri3_flags);
             UserAllInfo.WhichFields |= USER_ALL_USERACCOUNTCONTROL;
 
@@ -1842,6 +1877,7 @@ SetUserInfo(SAM_HANDLE UserHandle,
                 UserAllInfo.WhichFields |= USER_ALL_ADMINCOMMENT;
             }
 
+            ChangeUserDacl(Dacl, UserInfo4->usri4_flags);
             UserAllInfo.UserAccountControl = GetAccountControl(UserInfo4->usri4_flags);
             UserAllInfo.WhichFields |= USER_ALL_USERACCOUNTCONTROL;
 
@@ -1899,8 +1935,8 @@ SetUserInfo(SAM_HANDLE UserHandle,
 
             // usri4_max_storage ignored
 
-//          UserInfo3->usri4_units_per_week;
-//          UserInfo3->usri4_logon_hours;
+//          UserInfo4->usri4_units_per_week;
+//          UserInfo4->usri4_logon_hours;
 
             // usri4_bad_pw_count ignored
             // usri4_num_logons ignored
@@ -1936,7 +1972,104 @@ SetUserInfo(SAM_HANDLE UserHandle,
             break;
 
 //        case 21:
-//        case 22:
+//            break;
+
+        case 22:
+            UserInfo22 = (PUSER_INFO_22)UserInfo;
+
+            // usri22_name ignored
+
+//          UserInfo22->usri22_password[ENCRYPTED_PWLEN];
+
+            // usri22_password_age ignored
+
+//          UserInfo3->usri3_priv;
+
+            if (UserInfo22->usri22_home_dir != NULL)
+            {
+                RtlInitUnicodeString(&UserAllInfo.HomeDirectory,
+                                     UserInfo22->usri22_home_dir);
+                UserAllInfo.WhichFields |= USER_ALL_HOMEDIRECTORY;
+            }
+
+            if (UserInfo22->usri22_comment != NULL)
+            {
+                RtlInitUnicodeString(&UserAllInfo.AdminComment,
+                                     UserInfo22->usri22_comment);
+                UserAllInfo.WhichFields |= USER_ALL_ADMINCOMMENT;
+            }
+
+            ChangeUserDacl(Dacl, UserInfo22->usri22_flags);
+            UserAllInfo.UserAccountControl = GetAccountControl(UserInfo22->usri22_flags);
+            UserAllInfo.WhichFields |= USER_ALL_USERACCOUNTCONTROL;
+
+            if (UserInfo22->usri22_script_path != NULL)
+            {
+                RtlInitUnicodeString(&UserAllInfo.ScriptPath,
+                                     UserInfo22->usri22_script_path);
+                UserAllInfo.WhichFields |= USER_ALL_SCRIPTPATH;
+            }
+
+//          UserInfo22->usri22_auth_flags;
+
+            if (UserInfo22->usri22_full_name != NULL)
+            {
+                RtlInitUnicodeString(&UserAllInfo.FullName,
+                                     UserInfo22->usri22_full_name);
+                UserAllInfo.WhichFields |= USER_ALL_FULLNAME;
+            }
+
+            if (UserInfo22->usri22_usr_comment != NULL)
+            {
+                RtlInitUnicodeString(&UserAllInfo.UserComment,
+                                     UserInfo22->usri22_usr_comment);
+                UserAllInfo.WhichFields |= USER_ALL_USERCOMMENT;
+            }
+
+            if (UserInfo22->usri22_parms != NULL)
+            {
+                RtlInitUnicodeString(&UserAllInfo.Parameters,
+                                     UserInfo22->usri22_parms);
+                UserAllInfo.WhichFields |= USER_ALL_PARAMETERS;
+            }
+
+            if (UserInfo22->usri22_workstations != NULL)
+            {
+                RtlInitUnicodeString(&UserAllInfo.WorkStations,
+                                     UserInfo22->usri22_workstations);
+                UserAllInfo.WhichFields |= USER_ALL_WORKSTATIONS;
+            }
+
+            // usri22_last_logon ignored
+            // usri22_last_logoff ignored
+
+            if (UserInfo22->usri22_acct_expires == TIMEQ_FOREVER)
+            {
+                UserAllInfo.AccountExpires.LowPart = 0;
+                UserAllInfo.AccountExpires.HighPart = 0;
+            }
+            else
+            {
+                RtlSecondsSince1970ToTime(UserInfo22->usri22_acct_expires,
+                                          &UserAllInfo.AccountExpires);
+            }
+            UserAllInfo.WhichFields |= USER_ALL_ACCOUNTEXPIRES;
+
+            // usri22_max_storage ignored
+
+//          UserInfo22->usri22_units_per_week;
+//          UserInfo22->usri22_logon_hours;
+
+            // usri22_bad_pw_count ignored
+            // usri22_num_logons ignored
+            // usri22_logon_server ignored
+
+            UserAllInfo.CountryCode = UserInfo22->usri22_country_code;
+            UserAllInfo.WhichFields |= USER_ALL_COUNTRYCODE;
+
+            UserAllInfo.CodePage = UserInfo22->usri22_code_page;
+            UserAllInfo.WhichFields |= USER_ALL_CODEPAGE;
+            break;
 
         case 1003:
             UserInfo1003 = (PUSER_INFO_1003)UserInfo;
@@ -1951,6 +2084,7 @@ SetUserInfo(SAM_HANDLE UserHandle,
             break;
 
 //        case 1005:
+//            break;
 
         case 1006:
             UserInfo1006 = (PUSER_INFO_1006)UserInfo;
@@ -1976,6 +2110,7 @@ SetUserInfo(SAM_HANDLE UserHandle,
 
         case 1008:
             UserInfo1008 = (PUSER_INFO_1008)UserInfo;
+            ChangeUserDacl(Dacl, UserInfo1008->usri1008_flags);
             UserAllInfo.UserAccountControl = GetAccountControl(UserInfo1008->usri1008_flags);
             UserAllInfo.WhichFields |= USER_ALL_USERACCOUNTCONTROL;
             break;
@@ -1992,6 +2127,7 @@ SetUserInfo(SAM_HANDLE UserHandle,
             break;
 
 //        case 1010:
+//            break;
 
         case 1011:
             UserInfo1011 = (PUSER_INFO_1011)UserInfo;
@@ -2064,6 +2200,7 @@ SetUserInfo(SAM_HANDLE UserHandle,
             break;
 
 //        case 1020:
+//            break;
 
         case 1024:
             UserInfo1024 = (PUSER_INFO_1024)UserInfo;
@@ -2124,6 +2261,9 @@ SetUserInfo(SAM_HANDLE UserHandle,
     }
 
 done:
+    if (Dacl != NULL)
+        HeapFree(GetProcessHeap(), 0, Dacl);
+
     return ApiStatus;
 }
 
@@ -2934,14 +3074,6 @@ done:
 //    *bufptr = (LPBYTE)Buffer;
 
     return ApiStatus;
-
-#if 0
-    *bufptr = NULL;
-    *entriesread = 0;
-    *totalentries = 0;
-
-    return ERROR_INVALID_LEVEL;
-#endif
 }