[NETAPI32]
[reactos.git] / reactos / dll / win32 / netapi32 / user.c
index 6db0c81..46c2bab 100644 (file)
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
  */
 
-#include <stdarg.h>
-
-#include "ntstatus.h"
-#define WIN32_NO_STATUS
-#include "windef.h"
-#include "winbase.h"
-#include "winerror.h"
-#include "lmcons.h"
-#include "lmaccess.h"
-#include "lmapibuf.h"
-#include "lmerr.h"
-#include "lmuse.h"
-#include "ntsecapi.h"
-#include "wine/debug.h"
-#include "wine/unicode.h"
-#include "wine/list.h"
+/*
+ *  TODO:
+ *    Implement NetUserChangePassword
+ *    Implement NetUserGetGroups
+ *    Implement NetUserSetGroups
+ *    NetUserGetLocalGroups does not support LG_INCLUDE_INDIRECT yet.
+ *    Add missing information levels.
+ *    ...
+ */
+
+#include "netapi32.h"
 
 WINE_DEFAULT_DEBUG_CHANNEL(netapi32);
 
-/* NOTE: So far, this is implemented to support tests that require user logins,
- *       but not designed to handle real user databases. Those should probably
- *       be synced with either the host's user database or with Samba.
- *
- * FIXME: The user database should hold all the information the USER_INFO_4 struct
- * needs, but for the first try, I will just implement the USER_INFO_1 fields.
- */
 
-struct sam_user
+typedef struct _ENUM_CONTEXT
 {
-    struct list entry;
-    WCHAR user_name[LM20_UNLEN+1];
-    WCHAR user_password[PWLEN + 1];
-    DWORD sec_since_passwd_change;
-    DWORD user_priv;
-    LPWSTR home_dir;
-    LPWSTR user_comment;
-    DWORD user_flags;
-    LPWSTR user_logon_script_path;
-};
+    SAM_HANDLE ServerHandle;
+    SAM_HANDLE BuiltinDomainHandle;
+    SAM_HANDLE AccountDomainHandle;
 
-static struct list user_list = LIST_INIT( user_list );
+    SAM_ENUMERATE_HANDLE EnumerationContext;
+    PSAM_RID_ENUMERATION Buffer;
+    ULONG Count;
+    ULONG Index;
+    BOOLEAN BuiltinDone;
 
-BOOL NETAPI_IsLocalComputer(LPCWSTR ServerName);
+} ENUM_CONTEXT, *PENUM_CONTEXT;
 
-/************************************************************
- *                NETAPI_ValidateServername
- *
- * Validates server name
- */
-static NET_API_STATUS NETAPI_ValidateServername(LPCWSTR ServerName)
+
+static
+ULONG
+GetAccountFlags(ULONG AccountControl)
 {
-    if (ServerName)
-    {
-        if (ServerName[0] == 0)
-            return ERROR_BAD_NETPATH;
-        else if (
-            ((ServerName[0] == '\\') &&
-             (ServerName[1] != '\\'))
-            ||
-            ((ServerName[0] == '\\') &&
-             (ServerName[1] == '\\') &&
-             (ServerName[2] == 0))
-            )
-            return ERROR_INVALID_NAME;
-    }
-    return NERR_Success;
+    ULONG Flags = UF_SCRIPT;
+
+    if (AccountControl & USER_ACCOUNT_DISABLED)
+        Flags |= UF_ACCOUNTDISABLE;
+
+    if (AccountControl & USER_HOME_DIRECTORY_REQUIRED)
+        Flags |= UF_HOMEDIR_REQUIRED;
+
+    if (AccountControl & USER_PASSWORD_NOT_REQUIRED)
+        Flags |= UF_PASSWD_NOTREQD;
+
+//    UF_PASSWD_CANT_CHANGE
+
+    if (AccountControl & USER_ACCOUNT_AUTO_LOCKED)
+        Flags |= UF_LOCKOUT;
+
+    if (AccountControl & USER_DONT_EXPIRE_PASSWORD)
+        Flags |= UF_DONT_EXPIRE_PASSWD;
+
+/*
+    if (AccountControl & USER_ENCRYPTED_TEXT_PASSWORD_ALLOWED)
+        Flags |= UF_ENCRYPTED_TEXT_PASSWORD_ALLOWED;
+
+    if (AccountControl & USER_SMARTCARD_REQUIRED)
+        Flags |= UF_SMARTCARD_REQUIRED;
+
+    if (AccountControl & USER_TRUSTED_FOR_DELEGATION)
+        Flags |= UF_TRUSTED_FOR_DELEGATION;
+
+    if (AccountControl & USER_NOT_DELEGATED)
+        Flags |= UF_NOT_DELEGATED;
+
+    if (AccountControl & USER_USE_DES_KEY_ONLY)
+        Flags |= UF_USE_DES_KEY_ONLY;
+
+    if (AccountControl & USER_DONT_REQUIRE_PREAUTH)
+        Flags |= UF_DONT_REQUIRE_PREAUTH;
+
+    if (AccountControl & USER_PASSWORD_EXPIRED)
+        Flags |= UF_PASSWORD_EXPIRED;
+*/
+
+    /* Set account type flags */
+    if (AccountControl & USER_TEMP_DUPLICATE_ACCOUNT)
+        Flags |= UF_TEMP_DUPLICATE_ACCOUNT;
+    else if (AccountControl & USER_NORMAL_ACCOUNT)
+        Flags |= UF_NORMAL_ACCOUNT;
+    else if (AccountControl & USER_INTERDOMAIN_TRUST_ACCOUNT)
+        Flags |= UF_INTERDOMAIN_TRUST_ACCOUNT;
+    else if (AccountControl & USER_WORKSTATION_TRUST_ACCOUNT)
+        Flags |= UF_WORKSTATION_TRUST_ACCOUNT;
+    else if (AccountControl & USER_SERVER_TRUST_ACCOUNT)
+        Flags |= UF_SERVER_TRUST_ACCOUNT;
+
+    return Flags;
 }
 
-/************************************************************
- *                NETAPI_FindUser
- *
- * Looks for a user in the user database.
- * Returns a pointer to the entry in the user list when the user
- * is found, NULL otherwise.
- */
-static struct sam_user* NETAPI_FindUser(LPCWSTR UserName)
+
+static
+NET_API_STATUS
+BuildUserInfoBuffer(PUSER_ALL_INFORMATION UserInfo,
+                    DWORD level,
+                    ULONG RelativeId,
+                    LPVOID *Buffer)
 {
-    struct sam_user *user;
+    UNICODE_STRING LogonServer = RTL_CONSTANT_STRING(L"\\\\*");
+    LPVOID LocalBuffer = NULL;
+    PUSER_INFO_0 UserInfo0;
+    PUSER_INFO_1 UserInfo1;
+    PUSER_INFO_2 UserInfo2;
+    PUSER_INFO_3 UserInfo3;
+    PUSER_INFO_10 UserInfo10;
+    PUSER_INFO_20 UserInfo20;
+    PUSER_INFO_23 UserInfo23;
+    LPWSTR Ptr;
+    ULONG Size = 0;
+    NET_API_STATUS ApiStatus = NERR_Success;
+
+    *Buffer = NULL;
 
-    LIST_FOR_EACH_ENTRY(user, &user_list, struct sam_user, entry)
+    switch (level)
     {
-        if(lstrcmpW(user->user_name, UserName) == 0)
-            return user;
+        case 0:
+            Size = sizeof(USER_INFO_0) +
+                   UserInfo->UserName.Length + sizeof(WCHAR);
+            break;
+
+        case 1:
+            Size = sizeof(USER_INFO_1) +
+                   UserInfo->UserName.Length + sizeof(WCHAR);
+
+            if (UserInfo->HomeDirectory.Length > 0)
+                Size += UserInfo->HomeDirectory.Length + sizeof(WCHAR);
+
+            if (UserInfo->AdminComment.Length > 0)
+                Size += UserInfo->AdminComment.Length + sizeof(WCHAR);
+
+            if (UserInfo->ScriptPath.Length > 0)
+                Size += UserInfo->ScriptPath.Length + sizeof(WCHAR);
+            break;
+
+        case 2:
+            Size = sizeof(USER_INFO_2) +
+                   UserInfo->UserName.Length + sizeof(WCHAR);
+
+            if (UserInfo->HomeDirectory.Length > 0)
+                Size += UserInfo->HomeDirectory.Length + sizeof(WCHAR);
+
+            if (UserInfo->AdminComment.Length > 0)
+                Size += UserInfo->AdminComment.Length + sizeof(WCHAR);
+
+            if (UserInfo->ScriptPath.Length > 0)
+                Size += UserInfo->ScriptPath.Length + sizeof(WCHAR);
+
+            if (UserInfo->FullName.Length > 0)
+                Size += UserInfo->FullName.Length + sizeof(WCHAR);
+
+            if (UserInfo->UserComment.Length > 0)
+                Size += UserInfo->UserComment.Length + sizeof(WCHAR);
+
+            if (UserInfo->Parameters.Length > 0)
+                Size += UserInfo->Parameters.Length + sizeof(WCHAR);
+
+            if (UserInfo->WorkStations.Length > 0)
+                Size += UserInfo->WorkStations.Length + sizeof(WCHAR);
+
+            if (UserInfo->LogonHours.UnitsPerWeek > 0)
+                Size += (((ULONG)UserInfo->LogonHours.UnitsPerWeek) + 7) / 8;
+
+            if (LogonServer.Length > 0)
+                Size += LogonServer.Length + sizeof(WCHAR);
+            break;
+
+        case 3:
+            Size = sizeof(USER_INFO_3) +
+                   UserInfo->UserName.Length + sizeof(WCHAR);
+
+            if (UserInfo->HomeDirectory.Length > 0)
+                Size += UserInfo->HomeDirectory.Length + sizeof(WCHAR);
+
+            if (UserInfo->AdminComment.Length > 0)
+                Size += UserInfo->AdminComment.Length + sizeof(WCHAR);
+
+            if (UserInfo->ScriptPath.Length > 0)
+                Size += UserInfo->ScriptPath.Length + sizeof(WCHAR);
+
+            if (UserInfo->FullName.Length > 0)
+                Size += UserInfo->FullName.Length + sizeof(WCHAR);
+
+            if (UserInfo->UserComment.Length > 0)
+                Size += UserInfo->UserComment.Length + sizeof(WCHAR);
+
+            if (UserInfo->Parameters.Length > 0)
+                Size += UserInfo->Parameters.Length + sizeof(WCHAR);
+
+            if (UserInfo->WorkStations.Length > 0)
+                Size += UserInfo->WorkStations.Length + sizeof(WCHAR);
+
+            if (UserInfo->LogonHours.UnitsPerWeek > 0)
+                Size += (((ULONG)UserInfo->LogonHours.UnitsPerWeek) + 7) / 8;
+
+            if (LogonServer.Length > 0)
+                Size += LogonServer.Length + sizeof(WCHAR);
+
+            if (UserInfo->ProfilePath.Length > 0)
+                Size += UserInfo->ProfilePath.Length + sizeof(WCHAR);
+
+            if (UserInfo->HomeDirectoryDrive.Length > 0)
+                Size += UserInfo->HomeDirectoryDrive.Length + sizeof(WCHAR);
+            break;
+
+//        case 4:
+
+        case 10:
+            Size = sizeof(USER_INFO_10) +
+                   UserInfo->UserName.Length + sizeof(WCHAR);
+
+            if (UserInfo->AdminComment.Length > 0)
+                Size += UserInfo->AdminComment.Length + sizeof(WCHAR);
+
+            if (UserInfo->UserComment.Length > 0)
+                Size += UserInfo->UserComment.Length + sizeof(WCHAR);
+
+            if (UserInfo->FullName.Length > 0)
+                Size += UserInfo->FullName.Length + sizeof(WCHAR);
+            break;
+
+//        case 11:
+
+        case 20:
+            Size = sizeof(USER_INFO_20) +
+                   UserInfo->UserName.Length + sizeof(WCHAR);
+
+            if (UserInfo->FullName.Length > 0)
+                Size += UserInfo->FullName.Length + sizeof(WCHAR);
+
+            if (UserInfo->AdminComment.Length > 0)
+                Size += UserInfo->AdminComment.Length + sizeof(WCHAR);
+            break;
+
+        case 23:
+            Size = sizeof(USER_INFO_23) +
+                   UserInfo->UserName.Length + sizeof(WCHAR);
+
+            if (UserInfo->FullName.Length > 0)
+                Size += UserInfo->FullName.Length + sizeof(WCHAR);
+
+            if (UserInfo->AdminComment.Length > 0)
+                Size += UserInfo->AdminComment.Length + sizeof(WCHAR);
+
+            /* FIXME: usri23_user_sid */
+            break;
+
+        default:
+            ApiStatus = ERROR_INVALID_LEVEL;
+            goto done;
     }
-    return NULL;
+
+    ApiStatus = NetApiBufferAllocate(Size, &LocalBuffer);
+    if (ApiStatus != NERR_Success)
+        goto done;
+
+    ZeroMemory(LocalBuffer, Size);
+
+    switch (level)
+    {
+        case 0:
+            UserInfo0 = (PUSER_INFO_0)LocalBuffer;
+
+            Ptr = (LPWSTR)((ULONG_PTR)UserInfo0 + sizeof(USER_INFO_0));
+            UserInfo0->usri0_name = Ptr;
+
+            memcpy(UserInfo0->usri0_name,
+                   UserInfo->UserName.Buffer,
+                   UserInfo->UserName.Length);
+            UserInfo0->usri0_name[UserInfo->UserName.Length / sizeof(WCHAR)] = UNICODE_NULL;
+            break;
+
+        case 1:
+            UserInfo1 = (PUSER_INFO_1)LocalBuffer;
+
+            Ptr = (LPWSTR)((ULONG_PTR)UserInfo1 + sizeof(USER_INFO_1));
+
+            UserInfo1->usri1_name = Ptr;
+
+            memcpy(UserInfo1->usri1_name,
+                   UserInfo->UserName.Buffer,
+                   UserInfo->UserName.Length);
+            UserInfo1->usri1_name[UserInfo->UserName.Length / sizeof(WCHAR)] = UNICODE_NULL;
+
+            Ptr = (LPWSTR)((ULONG_PTR)Ptr + UserInfo->UserName.Length + sizeof(WCHAR));
+
+            UserInfo1->usri1_password = NULL;
+
+            /* FIXME: UserInfo1->usri1_password_age */
+            /* FIXME: UserInfo1->usri1_priv */
+
+            if (UserInfo->HomeDirectory.Length > 0)
+            {
+                UserInfo1->usri1_home_dir = Ptr;
+
+                memcpy(UserInfo1->usri1_home_dir,
+                       UserInfo->HomeDirectory.Buffer,
+                       UserInfo->HomeDirectory.Length);
+                UserInfo1->usri1_home_dir[UserInfo->HomeDirectory.Length / sizeof(WCHAR)] = UNICODE_NULL;
+
+                Ptr = (LPWSTR)((ULONG_PTR)Ptr + UserInfo->HomeDirectory.Length + sizeof(WCHAR));
+            }
+
+            if (UserInfo->AdminComment.Length > 0)
+            {
+                UserInfo1->usri1_comment = Ptr;
+
+                memcpy(UserInfo1->usri1_comment,
+                       UserInfo->AdminComment.Buffer,
+                       UserInfo->AdminComment.Length);
+                UserInfo1->usri1_comment[UserInfo->AdminComment.Length / sizeof(WCHAR)] = UNICODE_NULL;
+
+                Ptr = (LPWSTR)((ULONG_PTR)Ptr + UserInfo->AdminComment.Length + sizeof(WCHAR));
+            }
+
+            UserInfo1->usri1_flags = GetAccountFlags(UserInfo->UserAccountControl);
+
+            if (UserInfo->ScriptPath.Length > 0)
+            {
+                UserInfo1->usri1_script_path = Ptr;
+
+                memcpy(UserInfo1->usri1_script_path,
+                       UserInfo->ScriptPath.Buffer,
+                       UserInfo->ScriptPath.Length);
+                UserInfo1->usri1_script_path[UserInfo->ScriptPath.Length / sizeof(WCHAR)] = UNICODE_NULL;
+            }
+            break;
+
+        case 2:
+            UserInfo2 = (PUSER_INFO_2)LocalBuffer;
+
+            Ptr = (LPWSTR)((ULONG_PTR)UserInfo2 + sizeof(USER_INFO_2));
+
+            UserInfo2->usri2_name = Ptr;
+
+            memcpy(UserInfo2->usri2_name,
+                   UserInfo->UserName.Buffer,
+                   UserInfo->UserName.Length);
+            UserInfo2->usri2_name[UserInfo->UserName.Length / sizeof(WCHAR)] = UNICODE_NULL;
+
+            Ptr = (LPWSTR)((ULONG_PTR)Ptr + UserInfo->UserName.Length + sizeof(WCHAR));
+
+            /* FIXME: usri2_password_age */
+            /* FIXME: usri2_priv */
+
+            if (UserInfo->HomeDirectory.Length > 0)
+            {
+                UserInfo2->usri2_home_dir = Ptr;
+
+                memcpy(UserInfo2->usri2_home_dir,
+                       UserInfo->HomeDirectory.Buffer,
+                       UserInfo->HomeDirectory.Length);
+                UserInfo2->usri2_home_dir[UserInfo->HomeDirectory.Length / sizeof(WCHAR)] = UNICODE_NULL;
+
+                Ptr = (LPWSTR)((ULONG_PTR)Ptr + UserInfo->HomeDirectory.Length + sizeof(WCHAR));
+            }
+
+            if (UserInfo->AdminComment.Length > 0)
+            {
+                UserInfo2->usri2_comment = Ptr;
+
+                memcpy(UserInfo2->usri2_comment,
+                       UserInfo->AdminComment.Buffer,
+                       UserInfo->AdminComment.Length);
+                UserInfo2->usri2_comment[UserInfo->AdminComment.Length / sizeof(WCHAR)] = UNICODE_NULL;
+
+                Ptr = (LPWSTR)((ULONG_PTR)Ptr + UserInfo->AdminComment.Length + sizeof(WCHAR));
+            }
+
+            UserInfo2->usri2_flags = GetAccountFlags(UserInfo->UserAccountControl);
+
+            if (UserInfo->ScriptPath.Length > 0)
+            {
+                UserInfo2->usri2_script_path = Ptr;
+
+                memcpy(UserInfo2->usri2_script_path,
+                       UserInfo->ScriptPath.Buffer,
+                       UserInfo->ScriptPath.Length);
+                UserInfo2->usri2_script_path[UserInfo->ScriptPath.Length / sizeof(WCHAR)] = UNICODE_NULL;
+
+                Ptr = (LPWSTR)((ULONG_PTR)Ptr + UserInfo->ScriptPath.Length + sizeof(WCHAR));
+            }
+
+            /* FIXME: usri2_auth_flags */
+
+            if (UserInfo->FullName.Length > 0)
+            {
+                UserInfo2->usri2_full_name = Ptr;
+
+                memcpy(UserInfo2->usri2_full_name,
+                       UserInfo->FullName.Buffer,
+                       UserInfo->FullName.Length);
+                UserInfo2->usri2_full_name[UserInfo->FullName.Length / sizeof(WCHAR)] = UNICODE_NULL;
+
+                Ptr = (LPWSTR)((ULONG_PTR)Ptr + UserInfo->FullName.Length + sizeof(WCHAR));
+            }
+
+            if (UserInfo->UserComment.Length > 0)
+            {
+                UserInfo2->usri2_usr_comment = Ptr;
+
+                memcpy(UserInfo2->usri2_usr_comment,
+                       UserInfo->UserComment.Buffer,
+                       UserInfo->UserComment.Length);
+                UserInfo2->usri2_usr_comment[UserInfo->UserComment.Length / sizeof(WCHAR)] = UNICODE_NULL;
+
+                Ptr = (LPWSTR)((ULONG_PTR)Ptr + UserInfo->UserComment.Length + sizeof(WCHAR));
+            }
+
+            if (UserInfo->Parameters.Length > 0)
+            {
+                UserInfo2->usri2_parms = Ptr;
+
+                memcpy(UserInfo2->usri2_parms,
+                       UserInfo->Parameters.Buffer,
+                       UserInfo->Parameters.Length);
+                UserInfo2->usri2_parms[UserInfo->Parameters.Length / sizeof(WCHAR)] = UNICODE_NULL;
+
+                Ptr = (LPWSTR)((ULONG_PTR)Ptr + UserInfo->Parameters.Length + sizeof(WCHAR));
+            }
+
+            if (UserInfo->WorkStations.Length > 0)
+            {
+                UserInfo2->usri2_workstations = Ptr;
+
+                memcpy(UserInfo2->usri2_workstations,
+                       UserInfo->WorkStations.Buffer,
+                       UserInfo->WorkStations.Length);
+                UserInfo2->usri2_workstations[UserInfo->WorkStations.Length / sizeof(WCHAR)] = UNICODE_NULL;
+
+                Ptr = (LPWSTR)((ULONG_PTR)Ptr + UserInfo->WorkStations.Length + sizeof(WCHAR));
+            }
+
+            RtlTimeToSecondsSince1970(&UserInfo->LastLogon,
+                                      &UserInfo2->usri2_last_logon);
+
+            RtlTimeToSecondsSince1970(&UserInfo->LastLogoff,
+                                      &UserInfo2->usri2_last_logoff);
+
+            RtlTimeToSecondsSince1970(&UserInfo->AccountExpires,
+                                      &UserInfo2->usri2_acct_expires);
+
+            UserInfo2->usri2_max_storage = USER_MAXSTORAGE_UNLIMITED;
+            UserInfo2->usri2_units_per_week = UserInfo->LogonHours.UnitsPerWeek;
+
+            if (UserInfo->LogonHours.UnitsPerWeek > 0)
+            {
+                UserInfo2->usri2_logon_hours = (PVOID)Ptr;
+
+                memcpy(UserInfo2->usri2_logon_hours,
+                       UserInfo->LogonHours.LogonHours,
+                       (((ULONG)UserInfo->LogonHours.UnitsPerWeek) + 7) / 8);
+
+                Ptr = (LPWSTR)((ULONG_PTR)Ptr + (((ULONG)UserInfo->LogonHours.UnitsPerWeek) + 7) / 8);
+            }
+
+            UserInfo2->usri2_bad_pw_count = UserInfo->BadPasswordCount;
+            UserInfo2->usri2_num_logons = UserInfo->LogonCount;
+
+            if (LogonServer.Length > 0)
+            {
+                UserInfo2->usri2_logon_server = Ptr;
+
+                memcpy(UserInfo2->usri2_logon_server,
+                       LogonServer.Buffer,
+                       LogonServer.Length);
+                UserInfo2->usri2_logon_server[LogonServer.Length / sizeof(WCHAR)] = UNICODE_NULL;
+
+                Ptr = (LPWSTR)((ULONG_PTR)Ptr + LogonServer.Length + sizeof(WCHAR));
+            }
+
+            UserInfo2->usri2_country_code = UserInfo->CountryCode;
+            UserInfo2->usri2_code_page = UserInfo->CodePage;
+            break;
+
+        case 3:
+            UserInfo3 = (PUSER_INFO_3)LocalBuffer;
+
+            Ptr = (LPWSTR)((ULONG_PTR)UserInfo3 + sizeof(USER_INFO_3));
+
+            UserInfo3->usri3_name = Ptr;
+
+            memcpy(UserInfo3->usri3_name,
+                   UserInfo->UserName.Buffer,
+                   UserInfo->UserName.Length);
+            UserInfo3->usri3_name[UserInfo->UserName.Length / sizeof(WCHAR)] = UNICODE_NULL;
+
+            Ptr = (LPWSTR)((ULONG_PTR)Ptr + UserInfo->UserName.Length + sizeof(WCHAR));
+
+            /* FIXME: usri3_password_age */
+            /* FIXME: usri3_priv */
+
+            if (UserInfo->HomeDirectory.Length > 0)
+            {
+                UserInfo3->usri3_home_dir = Ptr;
+
+                memcpy(UserInfo3->usri3_home_dir,
+                       UserInfo->HomeDirectory.Buffer,
+                       UserInfo->HomeDirectory.Length);
+                UserInfo3->usri3_home_dir[UserInfo->HomeDirectory.Length / sizeof(WCHAR)] = UNICODE_NULL;
+
+                Ptr = (LPWSTR)((ULONG_PTR)Ptr + UserInfo->HomeDirectory.Length + sizeof(WCHAR));
+            }
+
+            if (UserInfo->AdminComment.Length > 0)
+            {
+                UserInfo3->usri3_comment = Ptr;
+
+                memcpy(UserInfo3->usri3_comment,
+                       UserInfo->AdminComment.Buffer,
+                       UserInfo->AdminComment.Length);
+                UserInfo3->usri3_comment[UserInfo->AdminComment.Length / sizeof(WCHAR)] = UNICODE_NULL;
+
+                Ptr = (LPWSTR)((ULONG_PTR)Ptr + UserInfo->AdminComment.Length + sizeof(WCHAR));
+            }
+
+            UserInfo3->usri3_flags = GetAccountFlags(UserInfo->UserAccountControl);
+
+            if (UserInfo->ScriptPath.Length > 0)
+            {
+                UserInfo3->usri3_script_path = Ptr;
+
+                memcpy(UserInfo3->usri3_script_path,
+                       UserInfo->ScriptPath.Buffer,
+                       UserInfo->ScriptPath.Length);
+                UserInfo3->usri3_script_path[UserInfo->ScriptPath.Length / sizeof(WCHAR)] = UNICODE_NULL;
+
+                Ptr = (LPWSTR)((ULONG_PTR)Ptr + UserInfo->ScriptPath.Length + sizeof(WCHAR));
+            }
+
+            /* FIXME: usri3_auth_flags */
+
+            if (UserInfo->FullName.Length > 0)
+            {
+                UserInfo3->usri3_full_name = Ptr;
+
+                memcpy(UserInfo3->usri3_full_name,
+                       UserInfo->FullName.Buffer,
+                       UserInfo->FullName.Length);
+                UserInfo3->usri3_full_name[UserInfo->FullName.Length / sizeof(WCHAR)] = UNICODE_NULL;
+
+                Ptr = (LPWSTR)((ULONG_PTR)Ptr + UserInfo->FullName.Length + sizeof(WCHAR));
+            }
+
+            if (UserInfo->UserComment.Length > 0)
+            {
+                UserInfo3->usri3_usr_comment = Ptr;
+
+                memcpy(UserInfo3->usri3_usr_comment,
+                       UserInfo->UserComment.Buffer,
+                       UserInfo->UserComment.Length);
+                UserInfo3->usri3_usr_comment[UserInfo->UserComment.Length / sizeof(WCHAR)] = UNICODE_NULL;
+
+                Ptr = (LPWSTR)((ULONG_PTR)Ptr + UserInfo->UserComment.Length + sizeof(WCHAR));
+            }
+
+            if (UserInfo->Parameters.Length > 0)
+            {
+                UserInfo3->usri3_parms = Ptr;
+
+                memcpy(UserInfo3->usri3_parms,
+                       UserInfo->Parameters.Buffer,
+                       UserInfo->Parameters.Length);
+                UserInfo3->usri3_parms[UserInfo->Parameters.Length / sizeof(WCHAR)] = UNICODE_NULL;
+
+                Ptr = (LPWSTR)((ULONG_PTR)Ptr + UserInfo->Parameters.Length + sizeof(WCHAR));
+            }
+
+            if (UserInfo->WorkStations.Length > 0)
+            {
+                UserInfo3->usri3_workstations = Ptr;
+
+                memcpy(UserInfo3->usri3_workstations,
+                       UserInfo->WorkStations.Buffer,
+                       UserInfo->WorkStations.Length);
+                UserInfo3->usri3_workstations[UserInfo->WorkStations.Length / sizeof(WCHAR)] = UNICODE_NULL;
+
+                Ptr = (LPWSTR)((ULONG_PTR)Ptr + UserInfo->WorkStations.Length + sizeof(WCHAR));
+            }
+
+            RtlTimeToSecondsSince1970(&UserInfo->LastLogon,
+                                      &UserInfo3->usri3_last_logon);
+
+            RtlTimeToSecondsSince1970(&UserInfo->LastLogoff,
+                                      &UserInfo3->usri3_last_logoff);
+
+            RtlTimeToSecondsSince1970(&UserInfo->AccountExpires,
+                                      &UserInfo3->usri3_acct_expires);
+
+            UserInfo3->usri3_max_storage = USER_MAXSTORAGE_UNLIMITED;
+            UserInfo3->usri3_units_per_week = UserInfo->LogonHours.UnitsPerWeek;
+
+            if (UserInfo->LogonHours.UnitsPerWeek > 0)
+            {
+                UserInfo3->usri3_logon_hours = (PVOID)Ptr;
+
+                memcpy(UserInfo3->usri3_logon_hours,
+                       UserInfo->LogonHours.LogonHours,
+                       (((ULONG)UserInfo->LogonHours.UnitsPerWeek) + 7) / 8);
+
+                Ptr = (LPWSTR)((ULONG_PTR)Ptr + (((ULONG)UserInfo->LogonHours.UnitsPerWeek) + 7) / 8);
+            }
+
+            UserInfo3->usri3_bad_pw_count = UserInfo->BadPasswordCount;
+            UserInfo3->usri3_num_logons = UserInfo->LogonCount;
+
+            if (LogonServer.Length > 0)
+            {
+                UserInfo3->usri3_logon_server = Ptr;
+
+                memcpy(UserInfo3->usri3_logon_server,
+                       LogonServer.Buffer,
+                       LogonServer.Length);
+                UserInfo3->usri3_logon_server[LogonServer.Length / sizeof(WCHAR)] = UNICODE_NULL;
+
+                Ptr = (LPWSTR)((ULONG_PTR)Ptr + LogonServer.Length + sizeof(WCHAR));
+            }
+
+            UserInfo3->usri3_country_code = UserInfo->CountryCode;
+            UserInfo3->usri3_code_page = UserInfo->CodePage;
+            UserInfo3->usri3_user_id = RelativeId;
+            UserInfo3->usri3_primary_group_id = UserInfo->PrimaryGroupId;
+
+            if (UserInfo->ProfilePath.Length > 0)
+            {
+                UserInfo3->usri3_profile = Ptr;
+
+                memcpy(UserInfo3->usri3_profile,
+                       UserInfo->ProfilePath.Buffer,
+                       UserInfo->ProfilePath.Length);
+                UserInfo3->usri3_profile[UserInfo->ProfilePath.Length / sizeof(WCHAR)] = UNICODE_NULL;
+
+                Ptr = (LPWSTR)((ULONG_PTR)Ptr + UserInfo->ProfilePath.Length + sizeof(WCHAR));
+            }
+
+            if (UserInfo->HomeDirectoryDrive.Length > 0)
+            {
+                UserInfo3->usri3_home_dir_drive = Ptr;
+
+                memcpy(UserInfo3->usri3_home_dir_drive,
+                       UserInfo->HomeDirectoryDrive.Buffer,
+                       UserInfo->HomeDirectoryDrive.Length);
+                UserInfo3->usri3_home_dir_drive[UserInfo->HomeDirectoryDrive.Length / sizeof(WCHAR)] = UNICODE_NULL;
+
+                Ptr = (LPWSTR)((ULONG_PTR)Ptr + UserInfo->HomeDirectoryDrive.Length + sizeof(WCHAR));
+            }
+
+            UserInfo3->usri3_password_expired = (UserInfo->UserAccountControl & USER_PASSWORD_EXPIRED);
+            break;
+
+//        case 4:
+
+        case 10:
+            UserInfo10 = (PUSER_INFO_10)LocalBuffer;
+
+            Ptr = (LPWSTR)((ULONG_PTR)UserInfo10 + sizeof(USER_INFO_10));
+
+            UserInfo10->usri10_name = Ptr;
+
+            memcpy(UserInfo10->usri10_name,
+                   UserInfo->UserName.Buffer,
+                   UserInfo->UserName.Length);
+            UserInfo10->usri10_name[UserInfo->UserName.Length / sizeof(WCHAR)] = UNICODE_NULL;
+
+            Ptr = (LPWSTR)((ULONG_PTR)Ptr + UserInfo->UserName.Length + sizeof(WCHAR));
+
+            if (UserInfo->AdminComment.Length > 0)
+            {
+                UserInfo10->usri10_comment = Ptr;
+
+                memcpy(UserInfo10->usri10_comment,
+                       UserInfo->AdminComment.Buffer,
+                       UserInfo->AdminComment.Length);
+                UserInfo10->usri10_comment[UserInfo->AdminComment.Length / sizeof(WCHAR)] = UNICODE_NULL;
+
+                Ptr = (LPWSTR)((ULONG_PTR)Ptr + UserInfo->AdminComment.Length + sizeof(WCHAR));
+            }
+
+            if (UserInfo->UserComment.Length > 0)
+            {
+                UserInfo10->usri10_usr_comment = Ptr;
+
+                memcpy(UserInfo10->usri10_usr_comment,
+                       UserInfo->UserComment.Buffer,
+                       UserInfo->UserComment.Length);
+                UserInfo10->usri10_usr_comment[UserInfo->UserComment.Length / sizeof(WCHAR)] = UNICODE_NULL;
+
+                Ptr = (LPWSTR)((ULONG_PTR)Ptr + UserInfo->UserComment.Length + sizeof(WCHAR));
+            }
+
+            if (UserInfo->FullName.Length > 0)
+            {
+                UserInfo10->usri10_full_name = Ptr;
+
+                memcpy(UserInfo10->usri10_full_name,
+                       UserInfo->FullName.Buffer,
+                       UserInfo->FullName.Length);
+                UserInfo10->usri10_full_name[UserInfo->FullName.Length / sizeof(WCHAR)] = UNICODE_NULL;
+
+                Ptr = (LPWSTR)((ULONG_PTR)Ptr + UserInfo->FullName.Length + sizeof(WCHAR));
+            }
+            break;
+
+//        case 11:
+
+        case 20:
+            UserInfo20 = (PUSER_INFO_20)LocalBuffer;
+
+            Ptr = (LPWSTR)((ULONG_PTR)UserInfo20 + sizeof(USER_INFO_20));
+
+            UserInfo20->usri20_name = Ptr;
+
+            memcpy(UserInfo20->usri20_name,
+                   UserInfo->UserName.Buffer,
+                   UserInfo->UserName.Length);
+            UserInfo20->usri20_name[UserInfo->UserName.Length / sizeof(WCHAR)] = UNICODE_NULL;
+
+            Ptr = (LPWSTR)((ULONG_PTR)Ptr + UserInfo->UserName.Length + sizeof(WCHAR));
+
+            if (UserInfo->FullName.Length > 0)
+            {
+                UserInfo20->usri20_full_name = Ptr;
+
+                memcpy(UserInfo20->usri20_full_name,
+                       UserInfo->FullName.Buffer,
+                       UserInfo->FullName.Length);
+                UserInfo20->usri20_full_name[UserInfo->FullName.Length / sizeof(WCHAR)] = UNICODE_NULL;
+
+                Ptr = (LPWSTR)((ULONG_PTR)Ptr + UserInfo->FullName.Length + sizeof(WCHAR));
+            }
+
+            if (UserInfo->AdminComment.Length > 0)
+            {
+                UserInfo20->usri20_comment = Ptr;
+
+                memcpy(UserInfo20->usri20_comment,
+                       UserInfo->AdminComment.Buffer,
+                       UserInfo->AdminComment.Length);
+                UserInfo20->usri20_comment[UserInfo->AdminComment.Length / sizeof(WCHAR)] = UNICODE_NULL;
+
+                Ptr = (LPWSTR)((ULONG_PTR)Ptr + UserInfo->AdminComment.Length + sizeof(WCHAR));
+            }
+
+            UserInfo20->usri20_flags = GetAccountFlags(UserInfo->UserAccountControl);
+
+            UserInfo20->usri20_user_id = RelativeId;
+            break;
+
+        case 23:
+            UserInfo23 = (PUSER_INFO_23)LocalBuffer;
+
+            Ptr = (LPWSTR)((ULONG_PTR)UserInfo23 + sizeof(USER_INFO_23));
+
+            UserInfo23->usri23_name = Ptr;
+
+            memcpy(UserInfo23->usri23_name,
+                   UserInfo->UserName.Buffer,
+                   UserInfo->UserName.Length);
+            UserInfo23->usri23_name[UserInfo->UserName.Length / sizeof(WCHAR)] = UNICODE_NULL;
+
+            Ptr = (LPWSTR)((ULONG_PTR)Ptr + UserInfo->UserName.Length + sizeof(WCHAR));
+
+            if (UserInfo->FullName.Length > 0)
+            {
+                UserInfo23->usri23_full_name = Ptr;
+
+                memcpy(UserInfo23->usri23_full_name,
+                       UserInfo->FullName.Buffer,
+                       UserInfo->FullName.Length);
+                UserInfo23->usri23_full_name[UserInfo->FullName.Length / sizeof(WCHAR)] = UNICODE_NULL;
+
+                Ptr = (LPWSTR)((ULONG_PTR)Ptr + UserInfo->FullName.Length + sizeof(WCHAR));
+            }
+
+            if (UserInfo->AdminComment.Length > 0)
+            {
+                UserInfo23->usri23_comment = Ptr;
+
+                memcpy(UserInfo23->usri23_comment,
+                       UserInfo->AdminComment.Buffer,
+                       UserInfo->AdminComment.Length);
+                UserInfo23->usri23_comment[UserInfo->AdminComment.Length / sizeof(WCHAR)] = UNICODE_NULL;
+
+                Ptr = (LPWSTR)((ULONG_PTR)Ptr + UserInfo->AdminComment.Length + sizeof(WCHAR));
+            }
+
+            UserInfo23->usri23_flags = GetAccountFlags(UserInfo->UserAccountControl);
+
+            /* FIXME: usri23_user_sid */
+           break;
+    }
+
+done:
+    if (ApiStatus == NERR_Success)
+    {
+        *Buffer = LocalBuffer;
+    }
+    else
+    {
+        if (LocalBuffer != NULL)
+            NetApiBufferFree(LocalBuffer);
+    }
+
+    return ApiStatus;
+}
+
+
+static
+VOID
+FreeUserInfo(PUSER_ALL_INFORMATION UserInfo)
+{
+    if (UserInfo->UserName.Buffer != NULL)
+        SamFreeMemory(UserInfo->UserName.Buffer);
+
+    if (UserInfo->FullName.Buffer != NULL)
+        SamFreeMemory(UserInfo->FullName.Buffer);
+
+    if (UserInfo->HomeDirectory.Buffer != NULL)
+        SamFreeMemory(UserInfo->HomeDirectory.Buffer);
+
+    if (UserInfo->HomeDirectoryDrive.Buffer != NULL)
+        SamFreeMemory(UserInfo->HomeDirectoryDrive.Buffer);
+
+    if (UserInfo->ScriptPath.Buffer != NULL)
+        SamFreeMemory(UserInfo->ScriptPath.Buffer);
+
+    if (UserInfo->ProfilePath.Buffer != NULL)
+        SamFreeMemory(UserInfo->ProfilePath.Buffer);
+
+    if (UserInfo->AdminComment.Buffer != NULL)
+        SamFreeMemory(UserInfo->AdminComment.Buffer);
+
+    if (UserInfo->WorkStations.Buffer != NULL)
+        SamFreeMemory(UserInfo->WorkStations.Buffer);
+
+    if (UserInfo->UserComment.Buffer != NULL)
+        SamFreeMemory(UserInfo->UserComment.Buffer);
+
+    if (UserInfo->Parameters.Buffer != NULL)
+        SamFreeMemory(UserInfo->Parameters.Buffer);
+
+    if (UserInfo->PrivateData.Buffer != NULL)
+        SamFreeMemory(UserInfo->PrivateData.Buffer);
+
+    if (UserInfo->LogonHours.LogonHours != NULL)
+        SamFreeMemory(UserInfo->LogonHours.LogonHours);
+
+    SamFreeMemory(UserInfo);
 }
 
-static BOOL NETAPI_IsCurrentUser(LPCWSTR username)
+
+static
+NET_API_STATUS
+SetUserInfo(SAM_HANDLE UserHandle,
+            LPBYTE UserInfo,
+            DWORD Level)
 {
-    LPWSTR curr_user = NULL;
-    DWORD dwSize;
-    BOOL ret = FALSE;
+    USER_ALL_INFORMATION UserAllInfo;
+    PUSER_INFO_0 UserInfo0;
+    PUSER_INFO_1 UserInfo1;
+    PUSER_INFO_2 UserInfo2;
+    PUSER_INFO_3 UserInfo3;
+    PUSER_INFO_1003 UserInfo1003;
+    PUSER_INFO_1006 UserInfo1006;
+    PUSER_INFO_1007 UserInfo1007;
+    PUSER_INFO_1009 UserInfo1009;
+    PUSER_INFO_1011 UserInfo1011;
+    PUSER_INFO_1012 UserInfo1012;
+    PUSER_INFO_1013 UserInfo1013;
+    PUSER_INFO_1014 UserInfo1014;
+    PUSER_INFO_1052 UserInfo1052;
+    PUSER_INFO_1053 UserInfo1053;
+    NET_API_STATUS ApiStatus = NERR_Success;
+    NTSTATUS Status = STATUS_SUCCESS;
+
+    ZeroMemory(&UserAllInfo, sizeof(USER_ALL_INFORMATION));
+
+    switch (Level)
+    {
+        case 0:
+            UserInfo0 = (PUSER_INFO_0)UserInfo;
+
+            RtlInitUnicodeString(&UserAllInfo.UserName,
+                                 UserInfo0->usri0_name);
+
+            UserAllInfo.WhichFields |= USER_ALL_USERNAME;
+            break;
+
+        case 1:
+            UserInfo1 = (PUSER_INFO_1)UserInfo;
+
+            // usri1_name ignored
+
+            if (UserInfo1->usri1_password != NULL)
+            {
+                RtlInitUnicodeString(&UserAllInfo.NtPassword,
+                                     UserInfo1->usri1_password);
+                UserAllInfo.NtPasswordPresent = TRUE;
+                UserAllInfo.WhichFields |= USER_ALL_NTPASSWORDPRESENT;
+            }
+
+            // usri1_password_age ignored
+
+//          UserInfo1->usri1_priv
+
+            if (UserInfo1->usri1_home_dir != NULL)
+            {
+                RtlInitUnicodeString(&UserAllInfo.HomeDirectory,
+                                     UserInfo1->usri1_home_dir);
+                UserAllInfo.WhichFields |= USER_ALL_HOMEDIRECTORY;
+            }
+
+            if (UserInfo1->usri1_comment != NULL)
+            {
+                RtlInitUnicodeString(&UserAllInfo.AdminComment,
+                                     UserInfo1->usri1_comment);
+                UserAllInfo.WhichFields |= USER_ALL_ADMINCOMMENT;
+            }
+
+//          UserInfo1->usri1_flags
+//            UserAllInfo.WhichFields |= USER_ALL_USERACCOUNTCONTROL;
+
+            if (UserInfo1->usri1_script_path != NULL)
+            {
+                RtlInitUnicodeString(&UserAllInfo.ScriptPath,
+                                     UserInfo1->usri1_script_path);
+                UserAllInfo.WhichFields |= USER_ALL_SCRIPTPATH;
+            }
+            break;
+
+        case 2:
+            UserInfo2 = (PUSER_INFO_2)UserInfo;
+
+            // usri2_name ignored
+
+            if (UserInfo2->usri2_password != NULL)
+            {
+                RtlInitUnicodeString(&UserAllInfo.NtPassword,
+                                     UserInfo2->usri2_password);
+                UserAllInfo.NtPasswordPresent = TRUE;
+                UserAllInfo.WhichFields |= USER_ALL_NTPASSWORDPRESENT;
+            }
+
+            // usri2_password_age ignored
+
+//          UserInfo2->usri2_priv;
+
+            if (UserInfo2->usri2_home_dir != NULL)
+            {
+                RtlInitUnicodeString(&UserAllInfo.HomeDirectory,
+                                     UserInfo2->usri2_home_dir);
+                UserAllInfo.WhichFields |= USER_ALL_HOMEDIRECTORY;
+            }
+
+            if (UserInfo2->usri2_comment != NULL)
+            {
+                RtlInitUnicodeString(&UserAllInfo.AdminComment,
+                                     UserInfo2->usri2_comment);
+                UserAllInfo.WhichFields |= USER_ALL_ADMINCOMMENT;
+            }
+
+//          UserInfo2->usri2_flags;
+
+            if (UserInfo2->usri2_script_path != NULL)
+            {
+                RtlInitUnicodeString(&UserAllInfo.ScriptPath,
+                                     UserInfo2->usri2_script_path);
+                UserAllInfo.WhichFields |= USER_ALL_SCRIPTPATH;
+            }
+
+//          UserInfo2->usri2_auth_flags;
+
+            if (UserInfo2->usri2_full_name != NULL)
+            {
+                RtlInitUnicodeString(&UserAllInfo.FullName,
+                                     UserInfo2->usri2_full_name);
+                UserAllInfo.WhichFields |= USER_ALL_FULLNAME;
+            }
+
+            if (UserInfo2->usri2_usr_comment != NULL)
+            {
+                RtlInitUnicodeString(&UserAllInfo.UserComment,
+                                     UserInfo2->usri2_usr_comment);
+                UserAllInfo.WhichFields |= USER_ALL_USERCOMMENT;
+            }
+
+            if (UserInfo2->usri2_parms != NULL)
+            {
+                RtlInitUnicodeString(&UserAllInfo.Parameters,
+                                     UserInfo2->usri2_parms);
+                UserAllInfo.WhichFields |= USER_ALL_PARAMETERS;
+            }
+
+            if (UserInfo2->usri2_workstations != NULL)
+            {
+                RtlInitUnicodeString(&UserAllInfo.WorkStations,
+                                     UserInfo2->usri2_workstations);
+                UserAllInfo.WhichFields |= USER_ALL_WORKSTATIONS;
+            }
+
+            // usri2_last_logon ignored
+            // usri2_last_logoff ignored
+
+//          UserInfo2->usri2_acct_expires;
+//          UserInfo2->usri2_max_storage;
+//          UserInfo2->usri2_units_per_week;
+//          UserInfo2->usri2_logon_hours;
+
+            // usri2_bad_pw_count ignored
+            // usri2_num_logons ignored
+            // usri2_logon_server ignored
+
+//          UserInfo2->usri2_country_code;
+//          UserInfo2->usri2_code_page;
+            break;
+
+        case 3:
+            UserInfo3 = (PUSER_INFO_3)UserInfo;
+
+            // usri3_name ignored
+
+            if (UserInfo3->usri3_password != NULL)
+            {
+                RtlInitUnicodeString(&UserAllInfo.NtPassword,
+                                     UserInfo3->usri3_password);
+                UserAllInfo.NtPasswordPresent = TRUE;
+                UserAllInfo.WhichFields |= USER_ALL_NTPASSWORDPRESENT;
+            }
+
+            // usri3_password_age ignored
+
+//          UserInfo3->usri3_priv;
+
+            if (UserInfo3->usri3_home_dir != NULL)
+            {
+                RtlInitUnicodeString(&UserAllInfo.HomeDirectory,
+                                     UserInfo3->usri3_home_dir);
+                UserAllInfo.WhichFields |= USER_ALL_HOMEDIRECTORY;
+            }
+
+            if (UserInfo3->usri3_comment != NULL)
+            {
+                RtlInitUnicodeString(&UserAllInfo.AdminComment,
+                                     UserInfo3->usri3_comment);
+                UserAllInfo.WhichFields |= USER_ALL_ADMINCOMMENT;
+            }
+
+//          UserInfo3->usri3_flags;
+//              UserAllInfo.WhichFields |= USER_ALL_USERACCOUNTCONTROL;
+
+            if (UserInfo3->usri3_script_path != NULL)
+            {
+                RtlInitUnicodeString(&UserAllInfo.ScriptPath,
+                                     UserInfo3->usri3_script_path);
+                UserAllInfo.WhichFields |= USER_ALL_SCRIPTPATH;
+            }
+
+//          UserInfo3->usri3_auth_flags;
+
+            if (UserInfo3->usri3_full_name != NULL)
+            {
+                RtlInitUnicodeString(&UserAllInfo.FullName,
+                                     UserInfo3->usri3_full_name);
+                UserAllInfo.WhichFields |= USER_ALL_FULLNAME;
+            }
+
+            if (UserInfo3->usri3_usr_comment != NULL)
+            {
+                RtlInitUnicodeString(&UserAllInfo.UserComment,
+                                     UserInfo3->usri3_usr_comment);
+                UserAllInfo.WhichFields |= USER_ALL_USERCOMMENT;
+            }
+
+            if (UserInfo3->usri3_parms != NULL)
+            {
+                RtlInitUnicodeString(&UserAllInfo.Parameters,
+                                     UserInfo3->usri3_parms);
+                UserAllInfo.WhichFields |= USER_ALL_PARAMETERS;
+            }
+
+            if (UserInfo3->usri3_workstations != NULL)
+            {
+                RtlInitUnicodeString(&UserAllInfo.WorkStations,
+                                     UserInfo3->usri3_workstations);
+                UserAllInfo.WhichFields |= USER_ALL_WORKSTATIONS;
+            }
+
+            // usri3_last_logon ignored
+            // usri3_last_logoff ignored
+
+//          UserInfo3->usri3_acct_expires;
+//          UserInfo3->usri3_max_storage;
+//          UserInfo3->usri3_units_per_week;
+//          UserInfo3->usri3_logon_hours;
+
+            // usri3_bad_pw_count ignored
+            // usri3_num_logons ignored
+            // usri3_logon_server ignored
+
+//          UserInfo3->usri3_country_code;
+//          UserInfo3->usri3_code_page;
+
+            // usri3_user_id ignored
+
+//          UserInfo3->usri3_primary_group_id;
+
+            if (UserInfo3->usri3_profile != NULL)
+            {
+                RtlInitUnicodeString(&UserAllInfo.ProfilePath,
+                                     UserInfo3->usri3_profile);
+                UserAllInfo.WhichFields |= USER_ALL_PROFILEPATH;
+            }
+
+            if (UserInfo3->usri3_home_dir_drive != NULL)
+            {
+                RtlInitUnicodeString(&UserAllInfo.HomeDirectoryDrive,
+                                     UserInfo3->usri3_home_dir_drive);
+                UserAllInfo.WhichFields |= USER_ALL_HOMEDIRECTORYDRIVE;
+            }
+
+//          UserInfo3->usri3_password_expired;
+            break;
+
+//        case 4:
+//        case 21:
+//        case 22:
+
+        case 1003:
+            UserInfo1003 = (PUSER_INFO_1003)UserInfo;
+
+            if (UserInfo1003->usri1003_password != NULL)
+            {
+                RtlInitUnicodeString(&UserAllInfo.NtPassword,
+                                     UserInfo1003->usri1003_password);
+                UserAllInfo.NtPasswordPresent = TRUE;
+                UserAllInfo.WhichFields |= USER_ALL_NTPASSWORDPRESENT;
+            }
+            break;
+
+//        case 1005:
 
-    dwSize = LM20_UNLEN+1;
-    curr_user = HeapAlloc(GetProcessHeap(), 0, dwSize * sizeof(WCHAR));
-    if(!curr_user)
+        case 1006:
+            UserInfo1006 = (PUSER_INFO_1006)UserInfo;
+
+            if (UserInfo1006->usri1006_home_dir != NULL)
+            {
+                RtlInitUnicodeString(&UserAllInfo.HomeDirectory,
+                                     UserInfo1006->usri1006_home_dir);
+                UserAllInfo.WhichFields |= USER_ALL_HOMEDIRECTORY;
+            }
+            break;
+
+        case 1007:
+            UserInfo1007 = (PUSER_INFO_1007)UserInfo;
+
+            if (UserInfo1007->usri1007_comment != NULL)
+            {
+                RtlInitUnicodeString(&UserAllInfo.AdminComment,
+                                     UserInfo1007->usri1007_comment);
+                UserAllInfo.WhichFields |= USER_ALL_ADMINCOMMENT;
+            }
+            break;
+
+//        case 1008:
+
+        case 1009:
+            UserInfo1009 = (PUSER_INFO_1009)UserInfo;
+
+            if (UserInfo1009->usri1009_script_path != NULL)
+            {
+                RtlInitUnicodeString(&UserAllInfo.ScriptPath,
+                                     UserInfo1009->usri1009_script_path);
+                UserAllInfo.WhichFields |= USER_ALL_SCRIPTPATH;
+            }
+            break;
+
+//        case 1010:
+
+        case 1011:
+            UserInfo1011 = (PUSER_INFO_1011)UserInfo;
+
+            if (UserInfo1011->usri1011_full_name != NULL)
+            {
+                RtlInitUnicodeString(&UserAllInfo.FullName,
+                                     UserInfo1011->usri1011_full_name);
+                UserAllInfo.WhichFields |= USER_ALL_FULLNAME;
+            }
+            break;
+
+        case 1012:
+            UserInfo1012 = (PUSER_INFO_1012)UserInfo;
+
+            if (UserInfo1012->usri1012_usr_comment != NULL)
+            {
+                RtlInitUnicodeString(&UserAllInfo.UserComment,
+                                     UserInfo1012->usri1012_usr_comment);
+                UserAllInfo.WhichFields |= USER_ALL_USERCOMMENT;
+            }
+            break;
+
+        case 1013:
+            UserInfo1013 = (PUSER_INFO_1013)UserInfo;
+
+            if (UserInfo1013->usri1013_parms != NULL)
+            {
+                RtlInitUnicodeString(&UserAllInfo.Parameters,
+                                     UserInfo1013->usri1013_parms);
+                UserAllInfo.WhichFields |= USER_ALL_PARAMETERS;
+            }
+            break;
+
+        case 1014:
+            UserInfo1014 = (PUSER_INFO_1014)UserInfo;
+
+            if (UserInfo1014->usri1014_workstations != NULL)
+            {
+                RtlInitUnicodeString(&UserAllInfo.WorkStations,
+                                     UserInfo1014->usri1014_workstations);
+                UserAllInfo.WhichFields |= USER_ALL_WORKSTATIONS;
+            }
+            break;
+
+//        case 1017:
+//        case 1020:
+//        case 1024:
+//        case 1051:
+
+        case 1052:
+            UserInfo1052 = (PUSER_INFO_1052)UserInfo;
+
+            if (UserInfo1052->usri1052_profile != NULL)
+            {
+                RtlInitUnicodeString(&UserAllInfo.ProfilePath,
+                                     UserInfo1052->usri1052_profile);
+                UserAllInfo.WhichFields |= USER_ALL_PROFILEPATH;
+            }
+            break;
+
+        case 1053:
+            UserInfo1053 = (PUSER_INFO_1053)UserInfo;
+
+            if (UserInfo1053->usri1053_home_dir_drive != NULL)
+            {
+                RtlInitUnicodeString(&UserAllInfo.HomeDirectoryDrive,
+                                     UserInfo1053->usri1053_home_dir_drive);
+                UserAllInfo.WhichFields |= USER_ALL_HOMEDIRECTORYDRIVE;
+            }
+            break;
+
+        default:
+            ERR("Unsupported level %lu!\n", Level);
+            return ERROR_INVALID_PARAMETER;
+    }
+
+    Status = SamSetInformationUser(UserHandle,
+                                   UserAllInformation,
+                                   &UserAllInfo);
+    if (!NT_SUCCESS(Status))
+    {
+        ERR("SamSetInformationUser failed (Status %08lx)\n", Status);
+        ApiStatus = NetpNtStatusToApiStatus(Status);
+        goto done;
+    }
+
+done:
+    return ApiStatus;
+}
+
+
+static
+NET_API_STATUS
+OpenUserByName(SAM_HANDLE DomainHandle,
+               PUNICODE_STRING UserName,
+               ULONG DesiredAccess,
+               PSAM_HANDLE UserHandle)
+{
+    PULONG RelativeIds = NULL;
+    PSID_NAME_USE Use = NULL;
+    NET_API_STATUS ApiStatus = NERR_Success;
+    NTSTATUS Status = STATUS_SUCCESS;
+
+    /* Get the RID for the given user name */
+    Status = SamLookupNamesInDomain(DomainHandle,
+                                    1,
+                                    UserName,
+                                    &RelativeIds,
+                                    &Use);
+    if (!NT_SUCCESS(Status))
     {
-        ERR("Failed to allocate memory for user name.\n");
-        goto end;
+        ERR("SamLookupNamesInDomain failed (Status %08lx)\n", Status);
+        return NetpNtStatusToApiStatus(Status);
     }
-    if(!GetUserNameW(curr_user, &dwSize))
+
+    /* Fail, if it is not an alias account */
+    if (Use[0] != SidTypeUser)
     {
-        ERR("Failed to get current user's user name.\n");
-        goto end;
+        ERR("Object is not a user!\n");
+        ApiStatus = NERR_GroupNotFound;
+        goto done;
     }
-    if (!lstrcmpW(curr_user, username))
+
+    /* Open the alias account */
+    Status = SamOpenUser(DomainHandle,
+                         DesiredAccess,
+                         RelativeIds[0],
+                         UserHandle);
+    if (!NT_SUCCESS(Status))
     {
-        ret = TRUE;
+        ERR("SamOpenUser failed (Status %08lx)\n", Status);
+        ApiStatus = NetpNtStatusToApiStatus(Status);
+        goto done;
     }
 
-end:
-    HeapFree(GetProcessHeap(), 0, curr_user);
-    return ret;
+done:
+    if (RelativeIds != NULL)
+        SamFreeMemory(RelativeIds);
+
+    if (Use != NULL)
+        SamFreeMemory(Use);
+
+    return ApiStatus;
 }
 
+
 /************************************************************
- *                NetUserAdd (NETAPI32.@)
+ * NetUserAdd (NETAPI32.@)
  */
 NET_API_STATUS
 WINAPI
@@ -143,72 +1352,98 @@ NetUserAdd(LPCWSTR servername,
            LPBYTE bufptr,
            LPDWORD parm_err)
 {
-    NET_API_STATUS status;
-    struct sam_user * su = NULL;
-
-    FIXME("(%s, %d, %p, %p) stub!\n", debugstr_w(servername), level, bufptr, parm_err);
-
-    if((status = NETAPI_ValidateServername(servername)) != NERR_Success)
-        return status;
-
-    switch(level)
-    {
-    /* Level 3 and 4 are identical for the purposes of NetUserAdd */
-    case 4:
-    case 3:
-        FIXME("Level 3 and 4 not implemented.\n");
-        /* Fall through */
-    case 2:
-        FIXME("Level 2 not implemented.\n");
-        /* Fall through */
-    case 1:
+    UNICODE_STRING ServerName;
+    UNICODE_STRING UserName;
+    SAM_HANDLE ServerHandle = NULL;
+    SAM_HANDLE DomainHandle = NULL;
+    SAM_HANDLE UserHandle = NULL;
+    ULONG GrantedAccess;
+    ULONG RelativeId;
+    NET_API_STATUS ApiStatus = NERR_Success;
+    NTSTATUS Status = STATUS_SUCCESS;
+
+    TRACE("(%s, %d, %p, %p)\n", debugstr_w(servername), level, bufptr, parm_err);
+
+    /* Check the info level */
+    switch (level)
     {
-        PUSER_INFO_1 ui = (PUSER_INFO_1) bufptr;
-        su = HeapAlloc(GetProcessHeap(), 0, sizeof(struct sam_user));
-        if(!su)
-        {
-            status = NERR_InternalError;
-            break;
-        }
-
-        if(lstrlenW(ui->usri1_name) > LM20_UNLEN)
-        {
-            status = NERR_BadUsername;
+        case 1:
+        case 2:
+        case 3:
+        case 4:
             break;
-        }
 
-        /*FIXME: do other checks for a valid username */
-        lstrcpyW(su->user_name, ui->usri1_name);
+        default:
+            return ERROR_INVALID_LEVEL;
+    }
 
-        if(lstrlenW(ui->usri1_password) > PWLEN)
-        {
-            /* Always return PasswordTooShort on invalid passwords. */
-            status = NERR_PasswordTooShort;
-            break;
-        }
-        lstrcpyW(su->user_password, ui->usri1_password);
+    if (servername != NULL)
+        RtlInitUnicodeString(&ServerName, servername);
 
-        su->sec_since_passwd_change = ui->usri1_password_age;
-        su->user_priv = ui->usri1_priv;
-        su->user_flags = ui->usri1_flags;
+    /* Connect to the SAM Server */
+    Status = SamConnect((servername != NULL) ? &ServerName : NULL,
+                        &ServerHandle,
+                        SAM_SERVER_CONNECT | SAM_SERVER_LOOKUP_DOMAIN,
+                        NULL);
+    if (!NT_SUCCESS(Status))
+    {
+        ERR("SamConnect failed (Status %08lx)\n", Status);
+        ApiStatus = NetpNtStatusToApiStatus(Status);
+        goto done;
+    }
 
-        /*FIXME: set the other LPWSTRs to NULL for now */
-        su->home_dir = NULL;
-        su->user_comment = NULL;
-        su->user_logon_script_path = NULL;
+    /* Open the Account Domain */
+    Status = OpenAccountDomain(ServerHandle,
+                               (servername != NULL) ? &ServerName : NULL,
+                               DOMAIN_CREATE_USER | DOMAIN_LOOKUP,
+                               &DomainHandle);
+    if (!NT_SUCCESS(Status))
+    {
+        ERR("OpenAccountDomain failed (Status %08lx)\n", Status);
+        ApiStatus = NetpNtStatusToApiStatus(Status);
+        goto done;
+    }
 
-        list_add_head(&user_list, &su->entry);
-        return NERR_Success;
+    /* Initialize the user name string */
+    RtlInitUnicodeString(&UserName,
+                         ((PUSER_INFO_1)bufptr)->usri1_name);
+
+    /* Create the user account */
+    Status = SamCreateUser2InDomain(DomainHandle,
+                                    &UserName,
+                                    USER_NORMAL_ACCOUNT,
+                                    USER_ALL_ACCESS | DELETE | WRITE_DAC,
+                                    &UserHandle,
+                                    &GrantedAccess,
+                                    &RelativeId);
+    if (!NT_SUCCESS(Status))
+    {
+        ERR("SamCreateUser2InDomain failed (Status %08lx)\n", Status);
+        ApiStatus = NetpNtStatusToApiStatus(Status);
+        goto done;
     }
-    default:
-        TRACE("Invalid level %d specified.\n", level);
-        status = ERROR_INVALID_LEVEL;
-        break;
+
+    /* Set user information */
+    ApiStatus = SetUserInfo(UserHandle,
+                            bufptr,
+                            level);
+    if (ApiStatus != NERR_Success)
+    {
+        ERR("SetUserInfo failed (Status %lu)\n", ApiStatus);
+        goto done;
     }
 
-    HeapFree(GetProcessHeap(), 0, su);
+done:
+    if (UserHandle != NULL)
+        SamCloseHandle(UserHandle);
+
+    if (DomainHandle != NULL)
+        SamCloseHandle(DomainHandle);
 
-    return status;
+    if (ServerHandle != NULL)
+        SamCloseHandle(ServerHandle);
+
+    return ApiStatus;
 }
 
 
@@ -234,60 +1469,127 @@ NetUserChangePassword(LPCWSTR domainname,
                       LPCWSTR oldpassword,
                       LPCWSTR newpassword)
 {
-    struct sam_user *user;
-
     TRACE("(%s, %s, ..., ...)\n", debugstr_w(domainname), debugstr_w(username));
-
-    if(domainname)
-        FIXME("Ignoring domainname %s.\n", debugstr_w(domainname));
-
-    if((user = NETAPI_FindUser(username)) == NULL)
-        return NERR_UserNotFound;
-
-    if(lstrcmpW(user->user_password, oldpassword) != 0)
-        return ERROR_INVALID_PASSWORD;
-
-    if(lstrlenW(newpassword) > PWLEN)
-        return ERROR_PASSWORD_RESTRICTION;
-
-    lstrcpyW(user->user_password, newpassword);
-
     return NERR_Success;
 }
 
 
 /************************************************************
- *                NetUserDel  (NETAPI32.@)
+ * NetUserDel  (NETAPI32.@)
  */
 NET_API_STATUS
 WINAPI
 NetUserDel(LPCWSTR servername,
            LPCWSTR username)
 {
-    NET_API_STATUS status;
-    struct sam_user *user;
+    UNICODE_STRING ServerName;
+    UNICODE_STRING UserName;
+    SAM_HANDLE ServerHandle = NULL;
+    SAM_HANDLE DomainHandle = NULL;
+    SAM_HANDLE UserHandle = NULL;
+    NET_API_STATUS ApiStatus = NERR_Success;
+    NTSTATUS Status = STATUS_SUCCESS;
 
     TRACE("(%s, %s)\n", debugstr_w(servername), debugstr_w(username));
 
-    if((status = NETAPI_ValidateServername(servername))!= NERR_Success)
-        return status;
+    if (servername != NULL)
+        RtlInitUnicodeString(&ServerName, servername);
+
+    RtlInitUnicodeString(&UserName, username);
+
+    /* Connect to the SAM Server */
+    Status = SamConnect((servername != NULL) ? &ServerName : NULL,
+                        &ServerHandle,
+                        SAM_SERVER_CONNECT | SAM_SERVER_LOOKUP_DOMAIN,
+                        NULL);
+    if (!NT_SUCCESS(Status))
+    {
+        ERR("SamConnect failed (Status %08lx)\n", Status);
+        ApiStatus = NetpNtStatusToApiStatus(Status);
+        goto done;
+    }
 
-    if ((user = NETAPI_FindUser(username)) == NULL)
-        return NERR_UserNotFound;
+    /* Open the Builtin Domain */
+    Status = OpenBuiltinDomain(ServerHandle,
+                               DOMAIN_LOOKUP,
+                               &DomainHandle);
+    if (!NT_SUCCESS(Status))
+    {
+        ERR("OpenBuiltinDomain failed (Status %08lx)\n", Status);
+        ApiStatus = NetpNtStatusToApiStatus(Status);
+        goto done;
+    }
 
-    list_remove(&user->entry);
+    /* Open the user account in the builtin domain */
+    ApiStatus = OpenUserByName(DomainHandle,
+                               &UserName,
+                               DELETE,
+                               &UserHandle);
+    if (ApiStatus != NERR_Success && ApiStatus != ERROR_NONE_MAPPED)
+    {
+        TRACE("OpenUserByName failed (ApiStatus %lu)\n", ApiStatus);
+        goto done;
+    }
 
-    HeapFree(GetProcessHeap(), 0, user->home_dir);
-    HeapFree(GetProcessHeap(), 0, user->user_comment);
-    HeapFree(GetProcessHeap(), 0, user->user_logon_script_path);
-    HeapFree(GetProcessHeap(), 0, user);
+    if (UserHandle == NULL)
+    {
+        if (DomainHandle != NULL)
+        {
+            SamCloseHandle(DomainHandle);
+            DomainHandle = NULL;
+        }
 
-    return NERR_Success;
+        /* Open the Acount Domain */
+        Status = OpenAccountDomain(ServerHandle,
+                                   (servername != NULL) ? &ServerName : NULL,
+                                   DOMAIN_LOOKUP,
+                                   &DomainHandle);
+        if (!NT_SUCCESS(Status))
+        {
+            ERR("OpenAccountDomain failed (Status %08lx)\n", Status);
+            ApiStatus = NetpNtStatusToApiStatus(Status);
+            goto done;
+        }
+
+        /* Open the user account in the account domain */
+        ApiStatus = OpenUserByName(DomainHandle,
+                                   &UserName,
+                                   DELETE,
+                                   &UserHandle);
+        if (ApiStatus != NERR_Success)
+        {
+            ERR("OpenUserByName failed (ApiStatus %lu)\n", ApiStatus);
+            if (ApiStatus == ERROR_NONE_MAPPED)
+                ApiStatus = NERR_GroupNotFound;
+            goto done;
+        }
+    }
+
+    /* Delete the user */
+    Status = SamDeleteUser(UserHandle);
+    if (!NT_SUCCESS(Status))
+    {
+        ERR("SamDeleteUser failed (Status %08lx)\n", Status);
+        ApiStatus = NetpNtStatusToApiStatus(Status);
+        goto done;
+    }
+
+done:
+    if (UserHandle != NULL)
+        SamCloseHandle(UserHandle);
+
+    if (DomainHandle != NULL)
+        SamCloseHandle(DomainHandle);
+
+    if (ServerHandle != NULL)
+        SamCloseHandle(ServerHandle);
+
+    return ApiStatus;
 }
 
 
 /************************************************************
- *                NetUserEnum  (NETAPI32.@)
+ * NetUserEnum  (NETAPI32.@)
  */
 NET_API_STATUS
 WINAPI
@@ -300,15 +1602,224 @@ NetUserEnum(LPCWSTR servername,
             LPDWORD totalentries,
             LPDWORD resume_handle)
 {
-  FIXME("(%s,%d, 0x%d,%p,%d,%p,%p,%p) stub!\n", debugstr_w(servername), level,
-        filter, bufptr, prefmaxlen, entriesread, totalentries, resume_handle);
+    UNICODE_STRING ServerName;
+    PSAM_RID_ENUMERATION CurrentUser;
+    PENUM_CONTEXT EnumContext = NULL;
+    LPVOID Buffer = NULL;
+    ULONG i;
+    SAM_HANDLE UserHandle = NULL;
+    PUSER_ALL_INFORMATION UserInfo = NULL;
+
+    NET_API_STATUS ApiStatus = NERR_Success;
+    NTSTATUS Status = STATUS_SUCCESS;
+
+    TRACE("(%s %d 0x%d %p %d %p %p %p)\n", debugstr_w(servername), level,
+          filter, bufptr, prefmaxlen, entriesread, totalentries, resume_handle);
+
+    *entriesread = 0;
+    *totalentries = 0;
+    *bufptr = NULL;
+
+    if (servername != NULL)
+        RtlInitUnicodeString(&ServerName, servername);
+
+    if (resume_handle != NULL && *resume_handle != 0)
+    {
+        EnumContext = (PENUM_CONTEXT)*resume_handle;
+    }
+    else
+    {
+        ApiStatus = NetApiBufferAllocate(sizeof(ENUM_CONTEXT), (PVOID*)&EnumContext);
+        if (ApiStatus != NERR_Success)
+            goto done;
+
+        EnumContext->EnumerationContext = 0;
+        EnumContext->Buffer = NULL;
+        EnumContext->Count = 0;
+        EnumContext->Index = 0;
+        EnumContext->BuiltinDone = FALSE;
+
+        Status = SamConnect((servername != NULL) ? &ServerName : NULL,
+                            &EnumContext->ServerHandle,
+                            SAM_SERVER_CONNECT | SAM_SERVER_LOOKUP_DOMAIN,
+                            NULL);
+        if (!NT_SUCCESS(Status))
+        {
+            ERR("SamConnect failed (Status %08lx)\n", Status);
+            ApiStatus = NetpNtStatusToApiStatus(Status);
+            goto done;
+        }
+
+        Status = OpenAccountDomain(EnumContext->ServerHandle,
+                                   (servername != NULL) ? &ServerName : NULL,
+                                   DOMAIN_LIST_ACCOUNTS | DOMAIN_LOOKUP,
+                                   &EnumContext->AccountDomainHandle);
+        if (!NT_SUCCESS(Status))
+        {
+            ERR("OpenAccountDomain failed (Status %08lx)\n", Status);
+            ApiStatus = NetpNtStatusToApiStatus(Status);
+            goto done;
+        }
+
+        Status = OpenBuiltinDomain(EnumContext->ServerHandle,
+                                   DOMAIN_LIST_ACCOUNTS | DOMAIN_LOOKUP,
+                                   &EnumContext->BuiltinDomainHandle);
+        if (!NT_SUCCESS(Status))
+        {
+            ERR("OpenBuiltinDomain failed (Status %08lx)\n", Status);
+            ApiStatus = NetpNtStatusToApiStatus(Status);
+            goto done;
+        }
+    }
+
+//    while (TRUE)
+//    {
+        TRACE("EnumContext->Index: %lu\n", EnumContext->Index);
+        TRACE("EnumContext->Count: %lu\n", EnumContext->Count);
+
+        if (EnumContext->Index >= EnumContext->Count)
+        {
+//            if (EnumContext->BuiltinDone == TRUE)
+//            {
+//                ApiStatus = NERR_Success;
+//                goto done;
+//            }
+
+            TRACE("Calling SamEnumerateUsersInDomain\n");
+            Status = SamEnumerateUsersInDomain(EnumContext->AccountDomainHandle, //BuiltinDomainHandle,
+                                               &EnumContext->EnumerationContext,
+                                               0,
+                                               (PVOID *)&EnumContext->Buffer,
+                                               prefmaxlen,
+                                               &EnumContext->Count);
+
+            TRACE("SamEnumerateUsersInDomain returned (Status %08lx)\n", Status);
+            if (!NT_SUCCESS(Status))
+            {
+                ERR("SamEnumerateUsersInDomain failed (Status %08lx)\n", Status);
+                ApiStatus = NetpNtStatusToApiStatus(Status);
+                goto done;
+            }
+
+            if (Status == STATUS_MORE_ENTRIES)
+            {
+                ApiStatus = NERR_BufTooSmall;
+                goto done;
+            }
+            else
+            {
+                EnumContext->BuiltinDone = TRUE;
+            }
+        }
+
+        TRACE("EnumContext: %lu\n", EnumContext);
+        TRACE("EnumContext->Count: %lu\n", EnumContext->Count);
+        TRACE("EnumContext->Buffer: %p\n", EnumContext->Buffer);
+
+        /* Get a pointer to the current user */
+        CurrentUser = &EnumContext->Buffer[EnumContext->Index];
+
+        TRACE("RID: %lu\n", CurrentUser->RelativeId);
+
+        Status = SamOpenUser(EnumContext->AccountDomainHandle, //BuiltinDomainHandle,
+                             USER_READ_GENERAL | USER_READ_PREFERENCES | USER_READ_LOGON | USER_READ_ACCOUNT,
+                             CurrentUser->RelativeId,
+                             &UserHandle);
+        if (!NT_SUCCESS(Status))
+        {
+            ERR("SamOpenUser failed (Status %08lx)\n", Status);
+            ApiStatus = NetpNtStatusToApiStatus(Status);
+            goto done;
+        }
+
+        Status = SamQueryInformationUser(UserHandle,
+                                         UserAllInformation,
+                                         (PVOID *)&UserInfo);
+        if (!NT_SUCCESS(Status))
+        {
+            ERR("SamQueryInformationUser failed (Status %08lx)\n", Status);
+            ApiStatus = NetpNtStatusToApiStatus(Status);
+            goto done;
+        }
+
+        SamCloseHandle(UserHandle);
+        UserHandle = NULL;
 
-  return ERROR_ACCESS_DENIED;
+        ApiStatus = BuildUserInfoBuffer(UserInfo,
+                                        level,
+                                        CurrentUser->RelativeId,
+                                        &Buffer);
+        if (ApiStatus != NERR_Success)
+        {
+            ERR("BuildUserInfoBuffer failed (ApiStatus %lu)\n", ApiStatus);
+            goto done;
+        }
+
+        if (UserInfo != NULL)
+        {
+            FreeUserInfo(UserInfo);
+            UserInfo = NULL;
+        }
+
+        EnumContext->Index++;
+
+        (*entriesread)++;
+//    }
+
+done:
+    if (ApiStatus == NERR_Success && EnumContext->Index < EnumContext->Count)
+        ApiStatus = ERROR_MORE_DATA;
+
+    if (EnumContext != NULL)
+        *totalentries = EnumContext->Count;
+
+    if (resume_handle == NULL || ApiStatus != ERROR_MORE_DATA)
+    {
+        if (EnumContext != NULL)
+        {
+            if (EnumContext->BuiltinDomainHandle != NULL)
+                SamCloseHandle(EnumContext->BuiltinDomainHandle);
+
+            if (EnumContext->AccountDomainHandle != NULL)
+                SamCloseHandle(EnumContext->AccountDomainHandle);
+
+            if (EnumContext->ServerHandle != NULL)
+                SamCloseHandle(EnumContext->ServerHandle);
+
+            if (EnumContext->Buffer != NULL)
+            {
+                for (i = 0; i < EnumContext->Count; i++)
+                {
+                    SamFreeMemory(EnumContext->Buffer[i].Name.Buffer);
+                }
+
+                SamFreeMemory(EnumContext->Buffer);
+            }
+
+            NetApiBufferFree(EnumContext);
+            EnumContext = NULL;
+        }
+    }
+
+    if (UserHandle != NULL)
+        SamCloseHandle(UserHandle);
+
+    if (UserInfo != NULL)
+        FreeUserInfo(UserInfo);
+
+    if (resume_handle != NULL)
+        *resume_handle = (DWORD_PTR)EnumContext;
+
+    *bufptr = (LPBYTE)Buffer;
+
+    TRACE("return %lu\n", ApiStatus);
+
+    return ApiStatus;
 }
 
 
 /************************************************************
- *                NetUserGetGroups (NETAPI32.@)
+ * NetUserGetGroups (NETAPI32.@)
  */
 NET_API_STATUS
 WINAPI
@@ -342,172 +1853,127 @@ NetUserGetInfo(LPCWSTR servername,
                DWORD level,
                LPBYTE* bufptr)
 {
-    NET_API_STATUS status;
-    TRACE("(%s, %s, %d, %p)\n", debugstr_w(servername), debugstr_w(username),
-          level, bufptr);
-    status = NETAPI_ValidateServername(servername);
-    if (status != NERR_Success)
-        return status;
-
-    if(!NETAPI_IsLocalComputer(servername))
+    UNICODE_STRING ServerName;
+    UNICODE_STRING UserName;
+    SAM_HANDLE ServerHandle = NULL;
+    SAM_HANDLE AccountDomainHandle = NULL;
+    SAM_HANDLE UserHandle = NULL;
+    PULONG RelativeIds = NULL;
+    PSID_NAME_USE Use = NULL;
+    PUSER_ALL_INFORMATION UserInfo = NULL;
+    LPVOID Buffer = NULL;
+    NET_API_STATUS ApiStatus = NERR_Success;
+    NTSTATUS Status = STATUS_SUCCESS;
+
+    TRACE("(%s, %s, %d, %p)\n", debugstr_w(servername),
+          debugstr_w(username), level, bufptr);
+
+    if (servername != NULL)
+        RtlInitUnicodeString(&ServerName, servername);
+
+    RtlInitUnicodeString(&UserName, username);
+
+    /* Connect to the SAM Server */
+    Status = SamConnect((servername != NULL) ? &ServerName : NULL,
+                        &ServerHandle,
+                        SAM_SERVER_CONNECT | SAM_SERVER_LOOKUP_DOMAIN,
+                        NULL);
+    if (!NT_SUCCESS(Status))
     {
-        FIXME("Only implemented for local computer, but remote server"
-              "%s was requested.\n", debugstr_w(servername));
-        return NERR_InvalidComputer;
+        ERR("SamConnect failed (Status %08lx)\n", Status);
+        ApiStatus = NetpNtStatusToApiStatus(Status);
+        goto done;
     }
 
-    if(!NETAPI_FindUser(username) && !NETAPI_IsCurrentUser(username))
+    /* Open the Account Domain */
+    Status = OpenAccountDomain(ServerHandle,
+                               (servername != NULL) ? &ServerName : NULL,
+                               DOMAIN_LIST_ACCOUNTS | DOMAIN_LOOKUP,
+                               &AccountDomainHandle);
+    if (!NT_SUCCESS(Status))
     {
-        TRACE("User %s is unknown.\n", debugstr_w(username));
-        return NERR_UserNotFound;
+        ERR("OpenAccountDomain failed (Status %08lx)\n", Status);
+        ApiStatus = NetpNtStatusToApiStatus(Status);
+        goto done;
     }
 
-    switch (level)
-    {
-    case 0:
+    /* Get the RID for the given user name */
+    Status = SamLookupNamesInDomain(AccountDomainHandle,
+                                    1,
+                                    &UserName,
+                                    &RelativeIds,
+                                    &Use);
+    if (!NT_SUCCESS(Status))
     {
-        PUSER_INFO_0 ui;
-        int name_sz;
+        ERR("SamOpenDomain failed (Status %08lx)\n", Status);
+        ApiStatus = NetpNtStatusToApiStatus(Status);
+        goto done;
+    }
 
-        name_sz = lstrlenW(username) + 1;
+    /* Check if the account is a user account */
+    if (Use[0] != SidTypeUser)
+    {
+        ERR("No user found!\n");
+        ApiStatus = NERR_UserNotFound;
+        goto done;
+    }
 
-        /* set up buffer */
-        NetApiBufferAllocate(sizeof(USER_INFO_0) + name_sz * sizeof(WCHAR),
-                             (LPVOID *) bufptr);
+    TRACE("RID: %lu\n", RelativeIds[0]);
 
-        ui = (PUSER_INFO_0) *bufptr;
-        ui->usri0_name = (LPWSTR) (*bufptr + sizeof(USER_INFO_0));
+    /* Open the user object */
+    Status = SamOpenUser(AccountDomainHandle,
+                         USER_READ_GENERAL | USER_READ_PREFERENCES | USER_READ_LOGON | USER_READ_ACCOUNT,
+                         RelativeIds[0],
+                         &UserHandle);
+    if (!NT_SUCCESS(Status))
+    {
+        ERR("SamOpenUser failed (Status %08lx)\n", Status);
+        ApiStatus = NetpNtStatusToApiStatus(Status);
+        goto done;
+    }
 
-        /* get data */
-        lstrcpyW(ui->usri0_name, username);
-        break;
+    Status = SamQueryInformationUser(UserHandle,
+                                     UserAllInformation,
+                                     (PVOID *)&UserInfo);
+    if (!NT_SUCCESS(Status))
+    {
+        ERR("SamQueryInformationUser failed (Status %08lx)\n", Status);
+        ApiStatus = NetpNtStatusToApiStatus(Status);
+        goto done;
     }
 
-    case 10:
+    ApiStatus = BuildUserInfoBuffer(UserInfo,
+                                    level,
+                                    RelativeIds[0],
+                                    &Buffer);
+    if (ApiStatus != NERR_Success)
     {
-        PUSER_INFO_10 ui;
-        PUSER_INFO_0 ui0;
-        NET_API_STATUS status;
-        /* sizes of the field buffers in WCHARS */
-        int name_sz, comment_sz, usr_comment_sz, full_name_sz;
+        ERR("BuildUserInfoBuffer failed (ApiStatus %08lu)\n", ApiStatus);
+        goto done;
+    }
 
-        comment_sz = 1;
-        usr_comment_sz = 1;
-        full_name_sz = 1;
+done:
+    if (UserInfo != NULL)
+        FreeUserInfo(UserInfo);
 
-        /* get data */
-        status = NetUserGetInfo(servername, username, 0, (LPBYTE *) &ui0);
-        if (status != NERR_Success)
-        {
-            NetApiBufferFree(ui0);
-            return status;
-        }
-        name_sz = lstrlenW(ui0->usri0_name) + 1;
-
-        /* set up buffer */
-        NetApiBufferAllocate(sizeof(USER_INFO_10) +
-                             (name_sz + comment_sz + usr_comment_sz +
-                              full_name_sz) * sizeof(WCHAR),
-                             (LPVOID *) bufptr);
-        ui = (PUSER_INFO_10) *bufptr;
-        ui->usri10_name = (LPWSTR) (*bufptr + sizeof(USER_INFO_10));
-        ui->usri10_comment = (LPWSTR) (
-            ((PBYTE) ui->usri10_name) + name_sz * sizeof(WCHAR));
-        ui->usri10_usr_comment = (LPWSTR) (
-            ((PBYTE) ui->usri10_comment) + comment_sz * sizeof(WCHAR));
-        ui->usri10_full_name = (LPWSTR) (
-            ((PBYTE) ui->usri10_usr_comment) + usr_comment_sz * sizeof(WCHAR));
-
-        /* set data */
-        lstrcpyW(ui->usri10_name, ui0->usri0_name);
-        NetApiBufferFree(ui0);
-        ui->usri10_comment[0] = 0;
-        ui->usri10_usr_comment[0] = 0;
-        ui->usri10_full_name[0] = 0;
-        break;
-    }
-
-    case 1:
-      {
-        static const WCHAR homedirW[] = {'H','O','M','E',0};
-        PUSER_INFO_1 ui;
-        PUSER_INFO_0 ui0;
-        NET_API_STATUS status;
-        /* sizes of the field buffers in WCHARS */
-        int name_sz, password_sz, home_dir_sz, comment_sz, script_path_sz;
-
-        password_sz = 1; /* not filled out for security reasons for NetUserGetInfo*/
-        comment_sz = 1;
-        script_path_sz = 1;
-
-       /* get data */
-        status = NetUserGetInfo(servername, username, 0, (LPBYTE *) &ui0);
-        if (status != NERR_Success)
-        {
-            NetApiBufferFree(ui0);
-            return status;
-        }
-        name_sz = lstrlenW(ui0->usri0_name) + 1;
-        home_dir_sz = GetEnvironmentVariableW(homedirW, NULL,0);
-        /* set up buffer */
-        NetApiBufferAllocate(sizeof(USER_INFO_1) +
-                             (name_sz + password_sz + home_dir_sz +
-                              comment_sz + script_path_sz) * sizeof(WCHAR),
-                             (LPVOID *) bufptr);
-
-        ui = (PUSER_INFO_1) *bufptr;
-        ui->usri1_name = (LPWSTR) (ui + 1);
-        ui->usri1_password = ui->usri1_name + name_sz;
-        ui->usri1_home_dir = ui->usri1_password + password_sz;
-        ui->usri1_comment = ui->usri1_home_dir + home_dir_sz;
-        ui->usri1_script_path = ui->usri1_comment + comment_sz;
-        /* set data */
-        lstrcpyW(ui->usri1_name, ui0->usri0_name);
-        NetApiBufferFree(ui0);
-        ui->usri1_password[0] = 0;
-        ui->usri1_password_age = 0;
-        ui->usri1_priv = 0;
-        GetEnvironmentVariableW(homedirW, ui->usri1_home_dir,home_dir_sz);
-        ui->usri1_comment[0] = 0;
-        ui->usri1_flags = 0;
-        ui->usri1_script_path[0] = 0;
-        break;
-      }
-    case 2:
-    case 3:
-    case 4:
-    case 11:
-    case 20:
-    case 23:
-    case 1003:
-    case 1005:
-    case 1006:
-    case 1007:
-    case 1008:
-    case 1009:
-    case 1010:
-    case 1011:
-    case 1012:
-    case 1013:
-    case 1014:
-    case 1017:
-    case 1018:
-    case 1020:
-    case 1023:
-    case 1024:
-    case 1025:
-    case 1051:
-    case 1052:
-    case 1053:
-    {
-        FIXME("Level %d is not implemented\n", level);
-        return NERR_InternalError;
-    }
-    default:
-        TRACE("Invalid level %d is specified\n", level);
-        return ERROR_INVALID_LEVEL;
-    }
-    return NERR_Success;
+    if (UserHandle != NULL)
+        SamCloseHandle(UserHandle);
+
+    if (RelativeIds != NULL)
+        SamFreeMemory(RelativeIds);
+
+    if (Use != NULL)
+        SamFreeMemory(Use);
+
+    if (AccountDomainHandle != NULL)
+        SamCloseHandle(AccountDomainHandle);
+
+    if (ServerHandle != NULL)
+        SamCloseHandle(ServerHandle);
+
+    *bufptr = (LPBYTE)Buffer;
+
+    return ApiStatus;
 }
 
 
@@ -525,53 +1991,298 @@ NetUserGetLocalGroups(LPCWSTR servername,
                       LPDWORD entriesread,
                       LPDWORD totalentries)
 {
-    NET_API_STATUS status;
-    const WCHAR admins[] = {'A','d','m','i','n','i','s','t','r','a','t','o','r','s',0};
-    LPWSTR currentuser;
-    LOCALGROUP_USERS_INFO_0* info;
-    DWORD size;
-
-    FIXME("(%s, %s, %d, %08x, %p %d, %p, %p) stub!\n",
+    UNICODE_STRING ServerName;
+    UNICODE_STRING UserName;
+    SAM_HANDLE ServerHandle = NULL;
+    SAM_HANDLE BuiltinDomainHandle = NULL;
+    SAM_HANDLE AccountDomainHandle = NULL;
+    PSID AccountDomainSid = NULL;
+    PSID UserSid = NULL;
+    PULONG RelativeIds = NULL;
+    PSID_NAME_USE Use = NULL;
+    ULONG BuiltinMemberCount = 0;
+    ULONG AccountMemberCount = 0;
+    PULONG BuiltinAliases = NULL;
+    PULONG AccountAliases = NULL;
+    PUNICODE_STRING BuiltinNames = NULL;
+    PUNICODE_STRING AccountNames = NULL;
+    PLOCALGROUP_USERS_INFO_0 Buffer = NULL;
+    ULONG Size;
+    ULONG Count = 0;
+    ULONG Index;
+    ULONG i;
+    LPWSTR StrPtr;
+    NET_API_STATUS ApiStatus = NERR_Success;
+    NTSTATUS Status = STATUS_SUCCESS;
+
+    TRACE("(%s, %s, %d, %08x, %p %d, %p, %p) stub!\n",
           debugstr_w(servername), debugstr_w(username), level, flags, bufptr,
           prefmaxlen, entriesread, totalentries);
 
-    status = NETAPI_ValidateServername(servername);
-    if (status != NERR_Success)
-        return status;
+    if (level != 0)
+        return ERROR_INVALID_LEVEL;
 
-    size = UNLEN + 1;
-    NetApiBufferAllocate(size * sizeof(WCHAR), (LPVOID*)&currentuser);
-    GetUserNameW(currentuser, &size);
+    if (flags & ~LG_INCLUDE_INDIRECT)
+        return ERROR_INVALID_PARAMETER;
 
-    if (lstrcmpiW(username, currentuser) && NETAPI_FindUser(username))
+    if (flags & LG_INCLUDE_INDIRECT)
     {
-        NetApiBufferFree(currentuser);
-        return NERR_UserNotFound;
+        WARN("The flag LG_INCLUDE_INDIRECT is not supported yet!\n");
     }
 
-    NetApiBufferFree(currentuser);
-    *totalentries = 1;
-    size = sizeof(*info) + sizeof(admins);
+    if (servername != NULL)
+        RtlInitUnicodeString(&ServerName, servername);
 
-    if(prefmaxlen < size)
-        status = ERROR_MORE_DATA;
-    else
-        status = NetApiBufferAllocate(size, (LPVOID*)&info);
+    RtlInitUnicodeString(&UserName, username);
 
-    if(status != NERR_Success)
+    /* Connect to the SAM Server */
+    Status = SamConnect((servername != NULL) ? &ServerName : NULL,
+                        &ServerHandle,
+                        SAM_SERVER_CONNECT | SAM_SERVER_LOOKUP_DOMAIN,
+                        NULL);
+    if (!NT_SUCCESS(Status))
     {
-        *bufptr = NULL;
-        *entriesread = 0;
-        return status;
+        ERR("SamConnect failed (Status %08lx)\n", Status);
+        ApiStatus = NetpNtStatusToApiStatus(Status);
+        goto done;
+    }
+
+    /* Open the Builtin Domain */
+    Status = OpenBuiltinDomain(ServerHandle,
+                               DOMAIN_LOOKUP | DOMAIN_GET_ALIAS_MEMBERSHIP,
+                               &BuiltinDomainHandle);
+    if (!NT_SUCCESS(Status))
+    {
+        ERR("OpenBuiltinDomain failed (Status %08lx)\n", Status);
+        ApiStatus = NetpNtStatusToApiStatus(Status);
+        goto done;
+    }
+
+    /* Get the Account Domain SID */
+    Status = GetAccountDomainSid((servername != NULL) ? &ServerName : NULL,
+                                 &AccountDomainSid);
+    if (!NT_SUCCESS(Status))
+    {
+        ERR("GetAccountDomainSid failed (Status %08lx)\n", Status);
+        ApiStatus = NetpNtStatusToApiStatus(Status);
+        goto done;
     }
 
-    info->lgrui0_name = (LPWSTR)((LPBYTE)info + sizeof(*info));
-    lstrcpyW(info->lgrui0_name, admins);
+    /* Open the Account Domain */
+    Status = SamOpenDomain(ServerHandle,
+                           DOMAIN_LOOKUP | DOMAIN_GET_ALIAS_MEMBERSHIP,
+                           AccountDomainSid,
+                           &AccountDomainHandle);
+    if (!NT_SUCCESS(Status))
+    {
+        ERR("OpenAccountDomain failed (Status %08lx)\n", Status);
+        ApiStatus = NetpNtStatusToApiStatus(Status);
+        goto done;
+    }
 
-    *bufptr = (LPBYTE)info;
-    *entriesread = 1;
+    /* Get the RID for the given user name */
+    Status = SamLookupNamesInDomain(AccountDomainHandle,
+                                    1,
+                                    &UserName,
+                                    &RelativeIds,
+                                    &Use);
+    if (!NT_SUCCESS(Status))
+    {
+        ERR("SamLookupNamesInDomain failed (Status %08lx)\n", Status);
+        ApiStatus = NetpNtStatusToApiStatus(Status);
+        goto done;
+    }
 
-    return NERR_Success;
+    /* Fail, if it is not a user account */
+    if (Use[0] != SidTypeUser)
+    {
+        ERR("Account is not a User!\n");
+        ApiStatus = NERR_UserNotFound;
+        goto done;
+    }
+
+    /* Build the User SID from the Account Domain SID and the users RID */
+    ApiStatus = BuildSidFromSidAndRid(AccountDomainSid,
+                                      RelativeIds[0],
+                                      &UserSid);
+    if (ApiStatus != NERR_Success)
+    {
+        ERR("BuildSidFromSidAndRid failed!\n");
+        goto done;
+    }
+
+    /* Get alias memberships in the Builtin Domain */
+    Status = SamGetAliasMembership(BuiltinDomainHandle,
+                                   1,
+                                   &UserSid,
+                                   &BuiltinMemberCount,
+                                   &BuiltinAliases);
+    if (!NT_SUCCESS(Status))
+    {
+        ERR("SamGetAliasMembership failed (Status %08lx)\n", Status);
+        ApiStatus = NetpNtStatusToApiStatus(Status);
+        goto done;
+    }
+
+    if (BuiltinMemberCount > 0)
+    {
+        /* Get the Names of the builtin alias members */
+        Status = SamLookupIdsInDomain(BuiltinDomainHandle,
+                                      BuiltinMemberCount,
+                                      BuiltinAliases,
+                                      &BuiltinNames,
+                                      NULL);
+        if (!NT_SUCCESS(Status))
+        {
+            ERR("SamLookupIdsInDomain failed (Status %08lx)\n", Status);
+            ApiStatus = NetpNtStatusToApiStatus(Status);
+            goto done;
+        }
+    }
+
+    /* Get alias memberships in the Account Domain */
+    Status = SamGetAliasMembership(AccountDomainHandle,
+                                   1,
+                                   &UserSid,
+                                   &AccountMemberCount,
+                                   &AccountAliases);
+    if (!NT_SUCCESS(Status))
+    {
+        ERR("SamGetAliasMembership failed (Status %08lx)\n", Status);
+        ApiStatus = NetpNtStatusToApiStatus(Status);
+        goto done;
+    }
+
+    if (AccountMemberCount > 0)
+    {
+        /* Get the Names of the builtin alias members */
+        Status = SamLookupIdsInDomain(AccountDomainHandle,
+                                      AccountMemberCount,
+                                      AccountAliases,
+                                      &AccountNames,
+                                      NULL);
+        if (!NT_SUCCESS(Status))
+        {
+            ERR("SamLookupIdsInDomain failed (Status %08lx)\n", Status);
+            ApiStatus = NetpNtStatusToApiStatus(Status);
+            goto done;
+        }
+    }
+
+    /* Calculate the required buffer size */
+    Size = 0;
+
+    for (i = 0; i < BuiltinMemberCount; i++)
+    {
+        if (BuiltinNames[i].Length > 0)
+        {
+            Size += (sizeof(LOCALGROUP_USERS_INFO_0) + BuiltinNames[i].Length + sizeof(UNICODE_NULL));
+            Count++;
+        }
+    }
+
+    for (i = 0; i < AccountMemberCount; i++)
+    {
+        if (BuiltinNames[i].Length > 0)
+        {
+            Size += (sizeof(LOCALGROUP_USERS_INFO_0) + AccountNames[i].Length + sizeof(UNICODE_NULL));
+            Count++;
+        }
+    }
+
+    if (Size == 0)
+    {
+        ApiStatus = NERR_Success;
+        goto done;
+    }
+
+    /* Allocate buffer */
+    ApiStatus = NetApiBufferAllocate(Size, (LPVOID*)&Buffer);
+    if (ApiStatus != NERR_Success)
+        goto done;
+
+    ZeroMemory(Buffer, Size);
+
+    StrPtr = (LPWSTR)((INT_PTR)Buffer + Count * sizeof(LOCALGROUP_USERS_INFO_0));
+
+    /* Copy data to the allocated buffer */
+    Index = 0;
+    for (i = 0; i < BuiltinMemberCount; i++)
+    {
+        if (BuiltinNames[i].Length > 0)
+        {
+            CopyMemory(StrPtr,
+                       BuiltinNames[i].Buffer,
+                       BuiltinNames[i].Length);
+            Buffer[Index].lgrui0_name = StrPtr;
+
+            StrPtr = (LPWSTR)((INT_PTR)StrPtr + BuiltinNames[i].Length + sizeof(UNICODE_NULL));
+            Index++;
+        }
+    }
+
+    for (i = 0; i < AccountMemberCount; i++)
+    {
+        if (AccountNames[i].Length > 0)
+        {
+            CopyMemory(StrPtr,
+                       AccountNames[i].Buffer,
+                       AccountNames[i].Length);
+            Buffer[Index].lgrui0_name = StrPtr;
+
+            StrPtr = (LPWSTR)((INT_PTR)StrPtr + AccountNames[i].Length + sizeof(UNICODE_NULL));
+            Index++;
+        }
+    }
+
+done:
+    if (AccountNames != NULL)
+        SamFreeMemory(AccountNames);
+
+    if (BuiltinNames != NULL)
+        SamFreeMemory(BuiltinNames);
+
+    if (AccountAliases != NULL)
+        SamFreeMemory(AccountAliases);
+
+    if (BuiltinAliases != NULL)
+        SamFreeMemory(BuiltinAliases);
+
+    if (RelativeIds != NULL)
+        SamFreeMemory(RelativeIds);
+
+    if (Use != NULL)
+        SamFreeMemory(Use);
+
+    if (UserSid != NULL)
+        NetApiBufferFree(UserSid);
+
+    if (AccountDomainSid != NULL)
+        RtlFreeHeap(RtlGetProcessHeap(), 0, AccountDomainSid);
+
+    if (AccountDomainHandle != NULL)
+        SamCloseHandle(AccountDomainHandle);
+
+    if (BuiltinDomainHandle != NULL)
+        SamCloseHandle(BuiltinDomainHandle);
+
+    if (ServerHandle != NULL)
+        SamCloseHandle(ServerHandle);
+
+    if (ApiStatus != NERR_Success && ApiStatus != ERROR_MORE_DATA)
+    {
+        *entriesread = 0;
+        *totalentries = 0;
+    }
+    else
+    {
+        *entriesread = Count;
+        *totalentries = Count;
+    }
+
+    *bufptr = (LPBYTE)Buffer;
+
+    return ApiStatus;
 }
 
 
@@ -592,7 +2303,6 @@ NetUserSetGroups(LPCWSTR servername,
 }
 
 
-
 /******************************************************************************
  * NetUserSetInfo  (NETAPI32.@)
  */
@@ -604,9 +2314,113 @@ NetUserSetInfo(LPCWSTR servername,
                LPBYTE buf,
                LPDWORD parm_err)
 {
-    FIXME("(%s %s %lu %p %p)\n",
+    UNICODE_STRING ServerName;
+    UNICODE_STRING UserName;
+    SAM_HANDLE ServerHandle = NULL;
+    SAM_HANDLE AccountDomainHandle = NULL;
+    SAM_HANDLE UserHandle = NULL;
+    NET_API_STATUS ApiStatus = NERR_Success;
+    NTSTATUS Status = STATUS_SUCCESS;
+
+    TRACE("(%s %s %lu %p %p)\n",
           debugstr_w(servername), debugstr_w(username), level, buf, parm_err);
-    return ERROR_ACCESS_DENIED;
+
+    if (parm_err != NULL)
+        *parm_err = PARM_ERROR_NONE;
+
+    /* Check the info level */
+    switch (level)
+    {
+        case 0:
+        case 1:
+        case 2:
+        case 3:
+//        case 4:
+//        case 21:
+//        case 22:
+        case 1003:
+//        case 1005:
+        case 1006:
+        case 1007:
+//        case 1008:
+        case 1009:
+//        case 1010:
+        case 1011:
+        case 1012:
+        case 1013:
+        case 1014:
+//        case 1017:
+//        case 1020:
+//        case 1024:
+//        case 1051:
+        case 1052:
+        case 1053:
+            break;
+
+        default:
+            return ERROR_INVALID_LEVEL;
+    }
+
+    if (servername != NULL)
+        RtlInitUnicodeString(&ServerName, servername);
+
+    RtlInitUnicodeString(&UserName, username);
+
+    /* Connect to the SAM Server */
+    Status = SamConnect((servername != NULL) ? &ServerName : NULL,
+                        &ServerHandle,
+                        SAM_SERVER_CONNECT | SAM_SERVER_LOOKUP_DOMAIN,
+                        NULL);
+    if (!NT_SUCCESS(Status))
+    {
+        ERR("SamConnect failed (Status %08lx)\n", Status);
+        ApiStatus = NetpNtStatusToApiStatus(Status);
+        goto done;
+    }
+
+    /* Open the Account Domain */
+    Status = OpenAccountDomain(ServerHandle,
+                               (servername != NULL) ? &ServerName : NULL,
+                               DOMAIN_LIST_ACCOUNTS | DOMAIN_LOOKUP,
+                               &AccountDomainHandle);
+    if (!NT_SUCCESS(Status))
+    {
+        ERR("OpenAccountDomain failed (Status %08lx)\n", Status);
+        ApiStatus = NetpNtStatusToApiStatus(Status);
+        goto done;
+    }
+
+    /* Open the User Account */
+    ApiStatus = OpenUserByName(AccountDomainHandle,
+                               &UserName,
+                               USER_ALL_ACCESS,
+                               &UserHandle);
+    if (ApiStatus != NERR_Success)
+    {
+        ERR("OpenUserByName failed (ApiStatus %lu)\n", ApiStatus);
+        goto done;
+    }
+
+    /* Set user information */
+    ApiStatus = SetUserInfo(UserHandle,
+                            buf,
+                            level);
+    if (ApiStatus != NERR_Success)
+    {
+        ERR("SetUserInfo failed (Status %lu)\n", ApiStatus);
+    }
+
+done:
+    if (UserHandle != NULL)
+        SamCloseHandle(UserHandle);
+
+    if (AccountDomainHandle != NULL)
+        SamCloseHandle(AccountDomainHandle);
+
+    if (ServerHandle != NULL)
+        SamCloseHandle(ServerHandle);
+
+    return ApiStatus;
 }
 
 /* EOF */