ReactOS  0.4.13-dev-39-g8b6696f
user.c File Reference
#include "netapi32.h"
#include <ndk/kefuncs.h>
#include <ndk/obfuncs.h>
Include dependency graph for user.c:

Go to the source code of this file.

Classes

struct  _ENUM_CONTEXT
 

Typedefs

typedef struct _ENUM_CONTEXT ENUM_CONTEXT
 
typedef struct _ENUM_CONTEXTPENUM_CONTEXT
 

Functions

 WINE_DEFAULT_DEBUG_CHANNEL (netapi32)
 
static ULONG DeltaTimeToSeconds (LARGE_INTEGER DeltaTime)
 
static NTSTATUS GetAllowedWorldAce (IN PACL Acl, OUT PACCESS_ALLOWED_ACE *Ace)
 
static ULONG GetAccountFlags (ULONG AccountControl, PACL Dacl)
 
static ULONG GetAccountControl (ULONG Flags)
 
static DWORD GetPasswordAge (IN PLARGE_INTEGER PasswordLastSet)
 
static VOID ChangeUserDacl (IN PACL Dacl, IN ULONG Flags)
 
static NET_API_STATUS GetUserDacl (IN SAM_HANDLE UserHandle, OUT PACL *Dacl)
 
static VOID FreeUserInfo (PUSER_ALL_INFORMATION UserInfo)
 
static NET_API_STATUS GetUserPrivileges (_In_ SAM_HANDLE BuiltinDomainHandle, _In_ SAM_HANDLE UserHandle, _In_ PSID AccountDomainSid, _In_ ULONG RelativeId, _Out_ PDWORD Priv, _Out_ PDWORD AuthFlags)
 
static NET_API_STATUS BuildUserInfoBuffer (_In_ SAM_HANDLE BuiltinDomainHandle, _In_ SAM_HANDLE UserHandle, _In_ PSID AccountDomainSid, _In_ ULONG RelativeId, _In_ DWORD level, _Out_ LPVOID *Buffer)
 
static NET_API_STATUS SetUserInfo (SAM_HANDLE UserHandle, LPBYTE UserInfo, DWORD Level, PDWORD parm_err)
 
static NET_API_STATUS OpenUserByName (SAM_HANDLE DomainHandle, PUNICODE_STRING UserName, ULONG DesiredAccess, PSAM_HANDLE UserHandle)
 
NET_API_STATUS WINAPI NetUserAdd (LPCWSTR servername, DWORD level, LPBYTE bufptr, LPDWORD parm_err)
 
NET_API_STATUS WINAPI NetUserChangePassword (LPCWSTR domainname, LPCWSTR username, LPCWSTR oldpassword, LPCWSTR newpassword)
 
NET_API_STATUS WINAPI NetUserDel (LPCWSTR servername, LPCWSTR username)
 
static NET_API_STATUS AllocateEnumContext (PENUM_CONTEXT *AllocatedEnumContext)
 
static VOID FreeEnumContext (PENUM_CONTEXT EnumContext)
 
static PENUM_CONTEXT LookupEnumContext (SAM_ENUMERATE_HANDLE EnumerationHandle)
 
NET_API_STATUS WINAPI NetUserEnum (LPCWSTR servername, DWORD level, DWORD filter, LPBYTE *bufptr, DWORD prefmaxlen, LPDWORD entriesread, LPDWORD totalentries, LPDWORD resume_handle)
 
NET_API_STATUS WINAPI NetUserGetGroups (LPCWSTR servername, LPCWSTR username, DWORD level, LPBYTE *bufptr, DWORD prefixmaxlen, LPDWORD entriesread, LPDWORD totalentries)
 
NET_API_STATUS WINAPI NetUserGetInfo (LPCWSTR servername, LPCWSTR username, DWORD level, LPBYTE *bufptr)
 
NET_API_STATUS WINAPI NetUserGetLocalGroups (LPCWSTR servername, LPCWSTR username, DWORD level, DWORD flags, LPBYTE *bufptr, DWORD prefmaxlen, LPDWORD entriesread, LPDWORD totalentries)
 
NET_API_STATUS WINAPI NetUserModalsGet (LPCWSTR servername, DWORD level, LPBYTE *bufptr)
 
NET_API_STATUS WINAPI NetUserModalsSet (IN LPCWSTR servername, IN DWORD level, IN LPBYTE buf, OUT LPDWORD parm_err)
 
NET_API_STATUS WINAPI NetUserSetGroups (LPCWSTR servername, LPCWSTR username, DWORD level, LPBYTE buf, DWORD num_entries)
 
NET_API_STATUS WINAPI NetUserSetInfo (LPCWSTR servername, LPCWSTR username, DWORD level, LPBYTE buf, LPDWORD parm_err)
 

Variables

LIST_ENTRY g_EnumContextListHead
 
CRITICAL_SECTION g_EnumContextListLock
 
LONG g_EnumContextHandle = 0
 

Typedef Documentation

◆ ENUM_CONTEXT

◆ PENUM_CONTEXT

Function Documentation

◆ AllocateEnumContext()

static NET_API_STATUS AllocateEnumContext ( PENUM_CONTEXT AllocatedEnumContext)
static

Definition at line 2673 of file user.c.

2675 {
2676  NET_API_STATUS ApiStatus;
2677  PENUM_CONTEXT EnumContext;
2678 
2679  /* Allocate the context structure */
2680  ApiStatus = NetApiBufferAllocate(sizeof(ENUM_CONTEXT), (PVOID*)&EnumContext);
2681  if (ApiStatus != NERR_Success)
2682  return ApiStatus;
2683 
2684  /* Initialize the fields */
2685  EnumContext->EnumerationContext = 0;
2686  EnumContext->Buffer = NULL;
2687  EnumContext->Count = 0;
2688  EnumContext->Index = 0;
2689  EnumContext->BuiltinDone = FALSE;
2690 
2691  /* Set a "unique" handle */
2693  if (EnumContext->EnumHandle == 0)
2694  {
2696  }
2697 
2698  /* Insert the context in the list */
2702 
2703  *AllocatedEnumContext = EnumContext;
2704  return NERR_Success;
2705 }
NET_API_STATUS WINAPI NetApiBufferAllocate(DWORD ByteCount, LPVOID *Buffer)
Definition: apibuf.c:28
CRITICAL_SECTION g_EnumContextListLock
Definition: user.c:57
PSAM_RID_ENUMERATION Buffer
Definition: local_group.c:40
BOOLEAN BuiltinDone
Definition: user.c:52
void WINAPI EnterCriticalSection(LPCRITICAL_SECTION)
#define InsertTailList(ListHead, Entry)
#define NERR_Success
Definition: lmerr.h:5
smooth NULL
Definition: ftsmooth.c:416
SAM_ENUMERATE_HANDLE EnumerationContext
Definition: local_group.c:39
ULONG EnumHandle
Definition: user.c:40
LONG g_EnumContextHandle
Definition: user.c:58
DWORD NET_API_STATUS
Definition: ms-dtyp.idl:91
LIST_ENTRY g_EnumContextListHead
Definition: user.c:56
#define InterlockedIncrement
Definition: armddk.h:53
LIST_ENTRY ListLink
Definition: user.c:39
ULONG Count
Definition: user.c:50
void WINAPI LeaveCriticalSection(LPCRITICAL_SECTION)

Referenced by NetUserEnum().

◆ BuildUserInfoBuffer()

static NET_API_STATUS BuildUserInfoBuffer ( _In_ SAM_HANDLE  BuiltinDomainHandle,
_In_ SAM_HANDLE  UserHandle,
_In_ PSID  AccountDomainSid,
_In_ ULONG  RelativeId,
_In_ DWORD  level,
_Out_ LPVOID Buffer 
)
static

Definition at line 550 of file user.c.

557 {
558  UNICODE_STRING LogonServer = RTL_CONSTANT_STRING(L"\\\\*");
559  PUSER_ALL_INFORMATION UserInfo = NULL;
560  LPVOID LocalBuffer = NULL;
561  PACL Dacl = NULL;
562  DWORD Priv = 0, AuthFlags = 0;
563  PUSER_INFO_0 UserInfo0;
564  PUSER_INFO_1 UserInfo1;
565  PUSER_INFO_2 UserInfo2;
566  PUSER_INFO_3 UserInfo3;
567  PUSER_INFO_4 UserInfo4;
568  PUSER_INFO_10 UserInfo10;
569  PUSER_INFO_11 UserInfo11;
570  PUSER_INFO_20 UserInfo20;
571  PUSER_INFO_23 UserInfo23;
572  LPWSTR Ptr;
573  ULONG Size = 0;
575  NET_API_STATUS ApiStatus = NERR_Success;
576 
577  *Buffer = NULL;
578 
579  Status = SamQueryInformationUser(UserHandle,
581  (PVOID *)&UserInfo);
582  if (!NT_SUCCESS(Status))
583  {
584  ERR("SamQueryInformationUser failed (Status %08lx)\n", Status);
585  ApiStatus = NetpNtStatusToApiStatus(Status);
586  goto done;
587  }
588 
589  if ((level == 1) || (level == 2) || (level == 3) ||
590  (level == 4) || (level == 20) || (level == 23))
591  {
592  ApiStatus = GetUserDacl(UserHandle, &Dacl);
593  if (ApiStatus != NERR_Success)
594  goto done;
595  }
596 
597  if ((level == 1) || (level == 2) || (level == 3) ||
598  (level == 4) || (level == 11))
599  {
600  ApiStatus = GetUserPrivileges(BuiltinDomainHandle,
601  UserHandle,
603  RelativeId,
604  &Priv,
605  &AuthFlags);
606  if (ApiStatus != NERR_Success)
607  goto done;
608  }
609 
610  switch (level)
611  {
612  case 0:
613  Size = sizeof(USER_INFO_0) +
614  UserInfo->UserName.Length + sizeof(WCHAR);
615  break;
616 
617  case 1:
618  Size = sizeof(USER_INFO_1) +
619  UserInfo->UserName.Length + sizeof(WCHAR) +
620  UserInfo->HomeDirectory.Length + sizeof(WCHAR) +
621  UserInfo->AdminComment.Length + sizeof(WCHAR) +
622  UserInfo->ScriptPath.Length + sizeof(WCHAR);
623  break;
624 
625  case 2:
626  Size = sizeof(USER_INFO_2) +
627  UserInfo->UserName.Length + sizeof(WCHAR) +
628  UserInfo->HomeDirectory.Length + sizeof(WCHAR) +
629  UserInfo->AdminComment.Length + sizeof(WCHAR) +
630  UserInfo->ScriptPath.Length + sizeof(WCHAR) +
631  UserInfo->FullName.Length + sizeof(WCHAR) +
632  UserInfo->UserComment.Length + sizeof(WCHAR) +
633  UserInfo->Parameters.Length + sizeof(WCHAR) +
634  UserInfo->WorkStations.Length + sizeof(WCHAR) +
635  LogonServer.Length + sizeof(WCHAR);
636 
637  if (UserInfo->LogonHours.UnitsPerWeek > 0)
638  Size += (((ULONG)UserInfo->LogonHours.UnitsPerWeek) + 7) / 8;
639  break;
640 
641  case 3:
642  Size = sizeof(USER_INFO_3) +
643  UserInfo->UserName.Length + sizeof(WCHAR) +
644  UserInfo->HomeDirectory.Length + sizeof(WCHAR) +
645  UserInfo->AdminComment.Length + sizeof(WCHAR) +
646  UserInfo->ScriptPath.Length + sizeof(WCHAR) +
647  UserInfo->FullName.Length + sizeof(WCHAR) +
648  UserInfo->UserComment.Length + sizeof(WCHAR) +
649  UserInfo->Parameters.Length + sizeof(WCHAR) +
650  UserInfo->WorkStations.Length + sizeof(WCHAR) +
651  LogonServer.Length + sizeof(WCHAR) +
652  UserInfo->ProfilePath.Length + sizeof(WCHAR) +
653  UserInfo->HomeDirectoryDrive.Length + sizeof(WCHAR);
654 
655  if (UserInfo->LogonHours.UnitsPerWeek > 0)
656  Size += (((ULONG)UserInfo->LogonHours.UnitsPerWeek) + 7) / 8;
657  break;
658 
659  case 4:
660  Size = sizeof(USER_INFO_4) +
661  UserInfo->UserName.Length + sizeof(WCHAR) +
662  UserInfo->HomeDirectory.Length + sizeof(WCHAR) +
663  UserInfo->AdminComment.Length + sizeof(WCHAR) +
664  UserInfo->ScriptPath.Length + sizeof(WCHAR) +
665  UserInfo->FullName.Length + sizeof(WCHAR) +
666  UserInfo->UserComment.Length + sizeof(WCHAR) +
667  UserInfo->Parameters.Length + sizeof(WCHAR) +
668  UserInfo->WorkStations.Length + sizeof(WCHAR) +
669  LogonServer.Length + sizeof(WCHAR) +
670  UserInfo->ProfilePath.Length + sizeof(WCHAR) +
671  UserInfo->HomeDirectoryDrive.Length + sizeof(WCHAR);
672 
673  if (UserInfo->LogonHours.UnitsPerWeek > 0)
674  Size += (((ULONG)UserInfo->LogonHours.UnitsPerWeek) + 7) / 8;
675 
676  Size += RtlLengthSid(AccountDomainSid) + sizeof(ULONG);
677  break;
678 
679  case 10:
680  Size = sizeof(USER_INFO_10) +
681  UserInfo->UserName.Length + sizeof(WCHAR) +
682  UserInfo->AdminComment.Length + sizeof(WCHAR) +
683  UserInfo->UserComment.Length + sizeof(WCHAR) +
684  UserInfo->FullName.Length + sizeof(WCHAR);
685  break;
686 
687  case 11:
688  Size = sizeof(USER_INFO_11) +
689  UserInfo->UserName.Length + sizeof(WCHAR) +
690  UserInfo->AdminComment.Length + sizeof(WCHAR) +
691  UserInfo->UserComment.Length + sizeof(WCHAR) +
692  UserInfo->FullName.Length + sizeof(WCHAR) +
693  UserInfo->HomeDirectory.Length + sizeof(WCHAR) +
694  UserInfo->Parameters.Length + sizeof(WCHAR) +
695  LogonServer.Length + sizeof(WCHAR) +
696  UserInfo->WorkStations.Length + sizeof(WCHAR);
697 
698  if (UserInfo->LogonHours.UnitsPerWeek > 0)
699  Size += (((ULONG)UserInfo->LogonHours.UnitsPerWeek) + 7) / 8;
700  break;
701 
702  case 20:
703  Size = sizeof(USER_INFO_20) +
704  UserInfo->UserName.Length + sizeof(WCHAR) +
705  UserInfo->FullName.Length + sizeof(WCHAR) +
706  UserInfo->AdminComment.Length + sizeof(WCHAR);
707  break;
708 
709  case 23:
710  Size = sizeof(USER_INFO_23) +
711  UserInfo->UserName.Length + sizeof(WCHAR) +
712  UserInfo->FullName.Length + sizeof(WCHAR) +
713  UserInfo->AdminComment.Length + sizeof(WCHAR);
714 
715  Size += RtlLengthSid(AccountDomainSid) + sizeof(ULONG);
716  break;
717 
718  default:
719  ApiStatus = ERROR_INVALID_LEVEL;
720  goto done;
721  }
722 
723  ApiStatus = NetApiBufferAllocate(Size, &LocalBuffer);
724  if (ApiStatus != NERR_Success)
725  goto done;
726 
727  ZeroMemory(LocalBuffer, Size);
728 
729  switch (level)
730  {
731  case 0:
732  UserInfo0 = (PUSER_INFO_0)LocalBuffer;
733 
734  Ptr = (LPWSTR)((ULONG_PTR)UserInfo0 + sizeof(USER_INFO_0));
735 
736  UserInfo0->usri0_name = Ptr;
737 
738  memcpy(UserInfo0->usri0_name,
739  UserInfo->UserName.Buffer,
740  UserInfo->UserName.Length);
741  UserInfo0->usri0_name[UserInfo->UserName.Length / sizeof(WCHAR)] = UNICODE_NULL;
742  break;
743 
744  case 1:
745  UserInfo1 = (PUSER_INFO_1)LocalBuffer;
746 
747  Ptr = (LPWSTR)((ULONG_PTR)UserInfo1 + sizeof(USER_INFO_1));
748 
749  UserInfo1->usri1_name = Ptr;
750 
751  memcpy(UserInfo1->usri1_name,
752  UserInfo->UserName.Buffer,
753  UserInfo->UserName.Length);
754  UserInfo1->usri1_name[UserInfo->UserName.Length / sizeof(WCHAR)] = UNICODE_NULL;
755 
756  Ptr = (LPWSTR)((ULONG_PTR)Ptr + UserInfo->UserName.Length + sizeof(WCHAR));
757 
758  UserInfo1->usri1_password = NULL;
759  UserInfo1->usri1_password_age = GetPasswordAge(&UserInfo->PasswordLastSet);
760 
761  UserInfo1->usri1_priv = Priv;
762 
763  UserInfo1->usri1_home_dir = Ptr;
764  memcpy(UserInfo1->usri1_home_dir,
765  UserInfo->HomeDirectory.Buffer,
766  UserInfo->HomeDirectory.Length);
767  UserInfo1->usri1_home_dir[UserInfo->HomeDirectory.Length / sizeof(WCHAR)] = UNICODE_NULL;
768  Ptr = (LPWSTR)((ULONG_PTR)Ptr + UserInfo->HomeDirectory.Length + sizeof(WCHAR));
769 
770  UserInfo1->usri1_comment = Ptr;
771  memcpy(UserInfo1->usri1_comment,
772  UserInfo->AdminComment.Buffer,
773  UserInfo->AdminComment.Length);
774  UserInfo1->usri1_comment[UserInfo->AdminComment.Length / sizeof(WCHAR)] = UNICODE_NULL;
775  Ptr = (LPWSTR)((ULONG_PTR)Ptr + UserInfo->AdminComment.Length + sizeof(WCHAR));
776 
777  UserInfo1->usri1_flags = GetAccountFlags(UserInfo->UserAccountControl,
778  Dacl);
779 
780  UserInfo1->usri1_script_path = Ptr;
781  memcpy(UserInfo1->usri1_script_path,
782  UserInfo->ScriptPath.Buffer,
783  UserInfo->ScriptPath.Length);
784  UserInfo1->usri1_script_path[UserInfo->ScriptPath.Length / sizeof(WCHAR)] = UNICODE_NULL;
785  break;
786 
787  case 2:
788  UserInfo2 = (PUSER_INFO_2)LocalBuffer;
789 
790  Ptr = (LPWSTR)((ULONG_PTR)UserInfo2 + sizeof(USER_INFO_2));
791 
792  UserInfo2->usri2_name = Ptr;
793 
794  memcpy(UserInfo2->usri2_name,
795  UserInfo->UserName.Buffer,
796  UserInfo->UserName.Length);
797  UserInfo2->usri2_name[UserInfo->UserName.Length / sizeof(WCHAR)] = UNICODE_NULL;
798 
799  Ptr = (LPWSTR)((ULONG_PTR)Ptr + UserInfo->UserName.Length + sizeof(WCHAR));
800 
801  UserInfo2->usri2_password = NULL;
802  UserInfo2->usri2_password_age = GetPasswordAge(&UserInfo->PasswordLastSet);
803 
804  UserInfo2->usri2_priv = Priv;
805 
806  UserInfo2->usri2_home_dir = Ptr;
807  memcpy(UserInfo2->usri2_home_dir,
808  UserInfo->HomeDirectory.Buffer,
809  UserInfo->HomeDirectory.Length);
810  UserInfo2->usri2_home_dir[UserInfo->HomeDirectory.Length / sizeof(WCHAR)] = UNICODE_NULL;
811  Ptr = (LPWSTR)((ULONG_PTR)Ptr + UserInfo->HomeDirectory.Length + sizeof(WCHAR));
812 
813  UserInfo2->usri2_comment = Ptr;
814  memcpy(UserInfo2->usri2_comment,
815  UserInfo->AdminComment.Buffer,
816  UserInfo->AdminComment.Length);
817  UserInfo2->usri2_comment[UserInfo->AdminComment.Length / sizeof(WCHAR)] = UNICODE_NULL;
818  Ptr = (LPWSTR)((ULONG_PTR)Ptr + UserInfo->AdminComment.Length + sizeof(WCHAR));
819 
820  UserInfo2->usri2_flags = GetAccountFlags(UserInfo->UserAccountControl,
821  Dacl);
822 
823  UserInfo2->usri2_script_path = Ptr;
824  memcpy(UserInfo2->usri2_script_path,
825  UserInfo->ScriptPath.Buffer,
826  UserInfo->ScriptPath.Length);
827  UserInfo2->usri2_script_path[UserInfo->ScriptPath.Length / sizeof(WCHAR)] = UNICODE_NULL;
828  Ptr = (LPWSTR)((ULONG_PTR)Ptr + UserInfo->ScriptPath.Length + sizeof(WCHAR));
829 
830  UserInfo2->usri2_auth_flags = AuthFlags;
831 
832  UserInfo2->usri2_full_name = Ptr;
833  memcpy(UserInfo2->usri2_full_name,
834  UserInfo->FullName.Buffer,
835  UserInfo->FullName.Length);
836  UserInfo2->usri2_full_name[UserInfo->FullName.Length / sizeof(WCHAR)] = UNICODE_NULL;
837  Ptr = (LPWSTR)((ULONG_PTR)Ptr + UserInfo->FullName.Length + sizeof(WCHAR));
838 
839  UserInfo2->usri2_usr_comment = Ptr;
840  memcpy(UserInfo2->usri2_usr_comment,
841  UserInfo->UserComment.Buffer,
842  UserInfo->UserComment.Length);
843  UserInfo2->usri2_usr_comment[UserInfo->UserComment.Length / sizeof(WCHAR)] = UNICODE_NULL;
844  Ptr = (LPWSTR)((ULONG_PTR)Ptr + UserInfo->UserComment.Length + sizeof(WCHAR));
845 
846  UserInfo2->usri2_parms = Ptr;
847  memcpy(UserInfo2->usri2_parms,
848  UserInfo->Parameters.Buffer,
849  UserInfo->Parameters.Length);
850  UserInfo2->usri2_parms[UserInfo->Parameters.Length / sizeof(WCHAR)] = UNICODE_NULL;
851  Ptr = (LPWSTR)((ULONG_PTR)Ptr + UserInfo->Parameters.Length + sizeof(WCHAR));
852 
853  UserInfo2->usri2_workstations = Ptr;
854  memcpy(UserInfo2->usri2_workstations,
855  UserInfo->WorkStations.Buffer,
856  UserInfo->WorkStations.Length);
857  UserInfo2->usri2_workstations[UserInfo->WorkStations.Length / sizeof(WCHAR)] = UNICODE_NULL;
858  Ptr = (LPWSTR)((ULONG_PTR)Ptr + UserInfo->WorkStations.Length + sizeof(WCHAR));
859 
860  if (UserInfo->LastLogon.QuadPart == 0)
861  UserInfo2->usri2_last_logon = 0;
862  else
864  &UserInfo2->usri2_last_logon);
865 
866  if (UserInfo->LastLogoff.QuadPart == 0)
867  UserInfo2->usri2_last_logoff = 0;
868  else
870  &UserInfo2->usri2_last_logoff);
871 
872  if (UserInfo->AccountExpires.QuadPart == MAXLONGLONG)
873  UserInfo2->usri2_acct_expires = TIMEQ_FOREVER;
874  else
876  &UserInfo2->usri2_acct_expires);
877 
879  UserInfo2->usri2_units_per_week = UserInfo->LogonHours.UnitsPerWeek;
880 
881  if (UserInfo->LogonHours.UnitsPerWeek > 0)
882  {
883  UserInfo2->usri2_logon_hours = (PVOID)Ptr;
884 
885  memcpy(UserInfo2->usri2_logon_hours,
886  UserInfo->LogonHours.LogonHours,
887  (((ULONG)UserInfo->LogonHours.UnitsPerWeek) + 7) / 8);
888 
889  Ptr = (LPWSTR)((ULONG_PTR)Ptr + (((ULONG)UserInfo->LogonHours.UnitsPerWeek) + 7) / 8);
890  }
891 
892  UserInfo2->usri2_bad_pw_count = UserInfo->BadPasswordCount;
893  UserInfo2->usri2_num_logons = UserInfo->LogonCount;
894 
895  UserInfo2->usri2_logon_server = Ptr;
896  memcpy(UserInfo2->usri2_logon_server,
897  LogonServer.Buffer,
898  LogonServer.Length);
899  UserInfo2->usri2_logon_server[LogonServer.Length / sizeof(WCHAR)] = UNICODE_NULL;
900  Ptr = (LPWSTR)((ULONG_PTR)Ptr + LogonServer.Length + sizeof(WCHAR));
901 
902  UserInfo2->usri2_country_code = UserInfo->CountryCode;
903  UserInfo2->usri2_code_page = UserInfo->CodePage;
904  break;
905 
906  case 3:
907  UserInfo3 = (PUSER_INFO_3)LocalBuffer;
908 
909  Ptr = (LPWSTR)((ULONG_PTR)UserInfo3 + sizeof(USER_INFO_3));
910 
911  UserInfo3->usri3_name = Ptr;
912 
913  memcpy(UserInfo3->usri3_name,
914  UserInfo->UserName.Buffer,
915  UserInfo->UserName.Length);
916  UserInfo3->usri3_name[UserInfo->UserName.Length / sizeof(WCHAR)] = UNICODE_NULL;
917 
918  Ptr = (LPWSTR)((ULONG_PTR)Ptr + UserInfo->UserName.Length + sizeof(WCHAR));
919 
920  UserInfo3->usri3_password = NULL;
921  UserInfo3->usri3_password_age = GetPasswordAge(&UserInfo->PasswordLastSet);
922 
923  UserInfo3->usri3_priv = Priv;
924 
925  UserInfo3->usri3_home_dir = Ptr;
926  memcpy(UserInfo3->usri3_home_dir,
927  UserInfo->HomeDirectory.Buffer,
928  UserInfo->HomeDirectory.Length);
929  UserInfo3->usri3_home_dir[UserInfo->HomeDirectory.Length / sizeof(WCHAR)] = UNICODE_NULL;
930  Ptr = (LPWSTR)((ULONG_PTR)Ptr + UserInfo->HomeDirectory.Length + sizeof(WCHAR));
931 
932  UserInfo3->usri3_comment = Ptr;
933  memcpy(UserInfo3->usri3_comment,
934  UserInfo->AdminComment.Buffer,
935  UserInfo->AdminComment.Length);
936  UserInfo3->usri3_comment[UserInfo->AdminComment.Length / sizeof(WCHAR)] = UNICODE_NULL;
937  Ptr = (LPWSTR)((ULONG_PTR)Ptr + UserInfo->AdminComment.Length + sizeof(WCHAR));
938 
939  UserInfo3->usri3_flags = GetAccountFlags(UserInfo->UserAccountControl,
940  Dacl);
941 
942  UserInfo3->usri3_script_path = Ptr;
943  memcpy(UserInfo3->usri3_script_path,
944  UserInfo->ScriptPath.Buffer,
945  UserInfo->ScriptPath.Length);
946  UserInfo3->usri3_script_path[UserInfo->ScriptPath.Length / sizeof(WCHAR)] = UNICODE_NULL;
947  Ptr = (LPWSTR)((ULONG_PTR)Ptr + UserInfo->ScriptPath.Length + sizeof(WCHAR));
948 
949  UserInfo3->usri3_auth_flags = AuthFlags;
950 
951  UserInfo3->usri3_full_name = Ptr;
952  memcpy(UserInfo3->usri3_full_name,
953  UserInfo->FullName.Buffer,
954  UserInfo->FullName.Length);
955  UserInfo3->usri3_full_name[UserInfo->FullName.Length / sizeof(WCHAR)] = UNICODE_NULL;
956  Ptr = (LPWSTR)((ULONG_PTR)Ptr + UserInfo->FullName.Length + sizeof(WCHAR));
957 
958  UserInfo3->usri3_usr_comment = Ptr;
959  memcpy(UserInfo3->usri3_usr_comment,
960  UserInfo->UserComment.Buffer,
961  UserInfo->UserComment.Length);
962  UserInfo3->usri3_usr_comment[UserInfo->UserComment.Length / sizeof(WCHAR)] = UNICODE_NULL;
963  Ptr = (LPWSTR)((ULONG_PTR)Ptr + UserInfo->UserComment.Length + sizeof(WCHAR));
964 
965  UserInfo3->usri3_parms = Ptr;
966  memcpy(UserInfo3->usri3_parms,
967  UserInfo->Parameters.Buffer,
968  UserInfo->Parameters.Length);
969  UserInfo3->usri3_parms[UserInfo->Parameters.Length / sizeof(WCHAR)] = UNICODE_NULL;
970  Ptr = (LPWSTR)((ULONG_PTR)Ptr + UserInfo->Parameters.Length + sizeof(WCHAR));
971 
972  UserInfo3->usri3_workstations = Ptr;
973  memcpy(UserInfo3->usri3_workstations,
974  UserInfo->WorkStations.Buffer,
975  UserInfo->WorkStations.Length);
976  UserInfo3->usri3_workstations[UserInfo->WorkStations.Length / sizeof(WCHAR)] = UNICODE_NULL;
977  Ptr = (LPWSTR)((ULONG_PTR)Ptr + UserInfo->WorkStations.Length + sizeof(WCHAR));
978 
979  if (UserInfo->LastLogon.QuadPart == 0)
980  UserInfo3->usri3_last_logon = 0;
981  else
983  &UserInfo3->usri3_last_logon);
984 
985  if (UserInfo->LastLogoff.QuadPart == 0)
986  UserInfo3->usri3_last_logoff = 0;
987  else
989  &UserInfo3->usri3_last_logoff);
990 
991  if (UserInfo->AccountExpires.QuadPart == MAXLONGLONG)
992  UserInfo3->usri3_acct_expires = TIMEQ_FOREVER;
993  else
995  &UserInfo3->usri3_acct_expires);
996 
998  UserInfo3->usri3_units_per_week = UserInfo->LogonHours.UnitsPerWeek;
999 
1000  if (UserInfo->LogonHours.UnitsPerWeek > 0)
1001  {
1002  UserInfo3->usri3_logon_hours = (PVOID)Ptr;
1003 
1004  memcpy(UserInfo3->usri3_logon_hours,
1005  UserInfo->LogonHours.LogonHours,
1006  (((ULONG)UserInfo->LogonHours.UnitsPerWeek) + 7) / 8);
1007 
1008  Ptr = (LPWSTR)((ULONG_PTR)Ptr + (((ULONG)UserInfo->LogonHours.UnitsPerWeek) + 7) / 8);
1009  }
1010 
1011  UserInfo3->usri3_bad_pw_count = UserInfo->BadPasswordCount;
1012  UserInfo3->usri3_num_logons = UserInfo->LogonCount;
1013 
1014  UserInfo3->usri3_logon_server = Ptr;
1015  memcpy(UserInfo3->usri3_logon_server,
1016  LogonServer.Buffer,
1017  LogonServer.Length);
1018  UserInfo3->usri3_logon_server[LogonServer.Length / sizeof(WCHAR)] = UNICODE_NULL;
1019  Ptr = (LPWSTR)((ULONG_PTR)Ptr + LogonServer.Length + sizeof(WCHAR));
1020 
1021  UserInfo3->usri3_country_code = UserInfo->CountryCode;
1022  UserInfo3->usri3_code_page = UserInfo->CodePage;
1023  UserInfo3->usri3_user_id = RelativeId;
1024  UserInfo3->usri3_primary_group_id = UserInfo->PrimaryGroupId;
1025 
1026  UserInfo3->usri3_profile = Ptr;
1027  memcpy(UserInfo3->usri3_profile,
1028  UserInfo->ProfilePath.Buffer,
1029  UserInfo->ProfilePath.Length);
1030  UserInfo3->usri3_profile[UserInfo->ProfilePath.Length / sizeof(WCHAR)] = UNICODE_NULL;
1031  Ptr = (LPWSTR)((ULONG_PTR)Ptr + UserInfo->ProfilePath.Length + sizeof(WCHAR));
1032 
1033  UserInfo3->usri3_home_dir_drive = Ptr;
1034  memcpy(UserInfo3->usri3_home_dir_drive,
1035  UserInfo->HomeDirectoryDrive.Buffer,
1036  UserInfo->HomeDirectoryDrive.Length);
1037  UserInfo3->usri3_home_dir_drive[UserInfo->HomeDirectoryDrive.Length / sizeof(WCHAR)] = UNICODE_NULL;
1038  Ptr = (LPWSTR)((ULONG_PTR)Ptr + UserInfo->HomeDirectoryDrive.Length + sizeof(WCHAR));
1039 
1041  break;
1042 
1043  case 4:
1044  UserInfo4 = (PUSER_INFO_4)LocalBuffer;
1045 
1046  Ptr = (LPWSTR)((ULONG_PTR)UserInfo4 + sizeof(USER_INFO_4));
1047 
1048  UserInfo4->usri4_name = Ptr;
1049 
1050  memcpy(UserInfo4->usri4_name,
1051  UserInfo->UserName.Buffer,
1052  UserInfo->UserName.Length);
1053  UserInfo4->usri4_name[UserInfo->UserName.Length / sizeof(WCHAR)] = UNICODE_NULL;
1054 
1055  Ptr = (LPWSTR)((ULONG_PTR)Ptr + UserInfo->UserName.Length + sizeof(WCHAR));
1056 
1057  UserInfo4->usri4_password = NULL;
1058  UserInfo4->usri4_password_age = GetPasswordAge(&UserInfo->PasswordLastSet);
1059 
1060  UserInfo4->usri4_priv = Priv;
1061 
1062  UserInfo4->usri4_home_dir = Ptr;
1063  memcpy(UserInfo4->usri4_home_dir,
1064  UserInfo->HomeDirectory.Buffer,
1065  UserInfo->HomeDirectory.Length);
1066  UserInfo4->usri4_home_dir[UserInfo->HomeDirectory.Length / sizeof(WCHAR)] = UNICODE_NULL;
1067  Ptr = (LPWSTR)((ULONG_PTR)Ptr + UserInfo->HomeDirectory.Length + sizeof(WCHAR));
1068 
1069  UserInfo4->usri4_comment = Ptr;
1070  memcpy(UserInfo4->usri4_comment,
1071  UserInfo->AdminComment.Buffer,
1072  UserInfo->AdminComment.Length);
1073  UserInfo4->usri4_comment[UserInfo->AdminComment.Length / sizeof(WCHAR)] = UNICODE_NULL;
1074  Ptr = (LPWSTR)((ULONG_PTR)Ptr + UserInfo->AdminComment.Length + sizeof(WCHAR));
1075 
1076  UserInfo4->usri4_flags = GetAccountFlags(UserInfo->UserAccountControl,
1077  Dacl);
1078 
1079  UserInfo4->usri4_script_path = Ptr;
1080  memcpy(UserInfo4->usri4_script_path,
1081  UserInfo->ScriptPath.Buffer,
1082  UserInfo->ScriptPath.Length);
1083  UserInfo4->usri4_script_path[UserInfo->ScriptPath.Length / sizeof(WCHAR)] = UNICODE_NULL;
1084  Ptr = (LPWSTR)((ULONG_PTR)Ptr + UserInfo->ScriptPath.Length + sizeof(WCHAR));
1085 
1086  UserInfo4->usri4_auth_flags = AuthFlags;
1087 
1088  UserInfo4->usri4_full_name = Ptr;
1089  memcpy(UserInfo4->usri4_full_name,
1090  UserInfo->FullName.Buffer,
1091  UserInfo->FullName.Length);
1092  UserInfo4->usri4_full_name[UserInfo->FullName.Length / sizeof(WCHAR)] = UNICODE_NULL;
1093  Ptr = (LPWSTR)((ULONG_PTR)Ptr + UserInfo->FullName.Length + sizeof(WCHAR));
1094 
1095  UserInfo4->usri4_usr_comment = Ptr;
1096  memcpy(UserInfo4->usri4_usr_comment,
1097  UserInfo->UserComment.Buffer,
1098  UserInfo->UserComment.Length);
1099  UserInfo4->usri4_usr_comment[UserInfo->UserComment.Length / sizeof(WCHAR)] = UNICODE_NULL;
1100  Ptr = (LPWSTR)((ULONG_PTR)Ptr + UserInfo->UserComment.Length + sizeof(WCHAR));
1101 
1102  UserInfo4->usri4_parms = Ptr;
1103  memcpy(UserInfo4->usri4_parms,
1104  UserInfo->Parameters.Buffer,
1105  UserInfo->Parameters.Length);
1106  UserInfo4->usri4_parms[UserInfo->Parameters.Length / sizeof(WCHAR)] = UNICODE_NULL;
1107  Ptr = (LPWSTR)((ULONG_PTR)Ptr + UserInfo->Parameters.Length + sizeof(WCHAR));
1108 
1109  UserInfo4->usri4_workstations = Ptr;
1110  memcpy(UserInfo4->usri4_workstations,
1111  UserInfo->WorkStations.Buffer,
1112  UserInfo->WorkStations.Length);
1113  UserInfo4->usri4_workstations[UserInfo->WorkStations.Length / sizeof(WCHAR)] = UNICODE_NULL;
1114  Ptr = (LPWSTR)((ULONG_PTR)Ptr + UserInfo->WorkStations.Length + sizeof(WCHAR));
1115 
1116  if (UserInfo->LastLogon.QuadPart == 0)
1117  UserInfo4->usri4_last_logon = 0;
1118  else
1120  &UserInfo4->usri4_last_logon);
1121 
1122  if (UserInfo->LastLogoff.QuadPart == 0)
1123  UserInfo4->usri4_last_logoff = 0;
1124  else
1126  &UserInfo4->usri4_last_logoff);
1127 
1128  if (UserInfo->AccountExpires.QuadPart == MAXLONGLONG)
1129  UserInfo4->usri4_acct_expires = TIMEQ_FOREVER;
1130  else
1132  &UserInfo4->usri4_acct_expires);
1133 
1135  UserInfo4->usri4_units_per_week = UserInfo->LogonHours.UnitsPerWeek;
1136 
1137  if (UserInfo->LogonHours.UnitsPerWeek > 0)
1138  {
1139  UserInfo4->usri4_logon_hours = (PVOID)Ptr;
1140 
1141  memcpy(UserInfo4->usri4_logon_hours,
1142  UserInfo->LogonHours.LogonHours,
1143  (((ULONG)UserInfo->LogonHours.UnitsPerWeek) + 7) / 8);
1144 
1145  Ptr = (LPWSTR)((ULONG_PTR)Ptr + (((ULONG)UserInfo->LogonHours.UnitsPerWeek) + 7) / 8);
1146  }
1147 
1148  UserInfo4->usri4_bad_pw_count = UserInfo->BadPasswordCount;
1149  UserInfo4->usri4_num_logons = UserInfo->LogonCount;
1150 
1151  UserInfo4->usri4_logon_server = Ptr;
1152  memcpy(UserInfo4->usri4_logon_server,
1153  LogonServer.Buffer,
1154  LogonServer.Length);
1155  UserInfo4->usri4_logon_server[LogonServer.Length / sizeof(WCHAR)] = UNICODE_NULL;
1156  Ptr = (LPWSTR)((ULONG_PTR)Ptr + LogonServer.Length + sizeof(WCHAR));
1157 
1158  UserInfo4->usri4_country_code = UserInfo->CountryCode;
1159  UserInfo4->usri4_code_page = UserInfo->CodePage;
1160 
1161  UserInfo4->usri4_user_sid = (PVOID)Ptr;
1162  CopySidFromSidAndRid(UserInfo4->usri4_user_sid, AccountDomainSid, RelativeId);
1164 
1165  UserInfo4->usri4_primary_group_id = UserInfo->PrimaryGroupId;
1166 
1167  UserInfo4->usri4_profile = Ptr;
1168  memcpy(UserInfo4->usri4_profile,
1169  UserInfo->ProfilePath.Buffer,
1170  UserInfo->ProfilePath.Length);
1171  UserInfo4->usri4_profile[UserInfo->ProfilePath.Length / sizeof(WCHAR)] = UNICODE_NULL;
1172  Ptr = (LPWSTR)((ULONG_PTR)Ptr + UserInfo->ProfilePath.Length + sizeof(WCHAR));
1173 
1174  UserInfo4->usri4_home_dir_drive = Ptr;
1175  memcpy(UserInfo4->usri4_home_dir_drive,
1176  UserInfo->HomeDirectoryDrive.Buffer,
1177  UserInfo->HomeDirectoryDrive.Length);
1178  UserInfo4->usri4_home_dir_drive[UserInfo->HomeDirectoryDrive.Length / sizeof(WCHAR)] = UNICODE_NULL;
1179  Ptr = (LPWSTR)((ULONG_PTR)Ptr + UserInfo->HomeDirectoryDrive.Length + sizeof(WCHAR));
1180 
1182  break;
1183 
1184  case 10:
1185  UserInfo10 = (PUSER_INFO_10)LocalBuffer;
1186 
1187  Ptr = (LPWSTR)((ULONG_PTR)UserInfo10 + sizeof(USER_INFO_10));
1188 
1189  UserInfo10->usri10_name = Ptr;
1190 
1191  memcpy(UserInfo10->usri10_name,
1192  UserInfo->UserName.Buffer,
1193  UserInfo->UserName.Length);
1194  UserInfo10->usri10_name[UserInfo->UserName.Length / sizeof(WCHAR)] = UNICODE_NULL;
1195 
1196  Ptr = (LPWSTR)((ULONG_PTR)Ptr + UserInfo->UserName.Length + sizeof(WCHAR));
1197 
1198  UserInfo10->usri10_comment = Ptr;
1199  memcpy(UserInfo10->usri10_comment,
1200  UserInfo->AdminComment.Buffer,
1201  UserInfo->AdminComment.Length);
1202  UserInfo10->usri10_comment[UserInfo->AdminComment.Length / sizeof(WCHAR)] = UNICODE_NULL;
1203  Ptr = (LPWSTR)((ULONG_PTR)Ptr + UserInfo->AdminComment.Length + sizeof(WCHAR));
1204 
1205  UserInfo10->usri10_usr_comment = Ptr;
1206  memcpy(UserInfo10->usri10_usr_comment,
1207  UserInfo->UserComment.Buffer,
1208  UserInfo->UserComment.Length);
1209  UserInfo10->usri10_usr_comment[UserInfo->UserComment.Length / sizeof(WCHAR)] = UNICODE_NULL;
1210  Ptr = (LPWSTR)((ULONG_PTR)Ptr + UserInfo->UserComment.Length + sizeof(WCHAR));
1211 
1212  UserInfo10->usri10_full_name = Ptr;
1213  memcpy(UserInfo10->usri10_full_name,
1214  UserInfo->FullName.Buffer,
1215  UserInfo->FullName.Length);
1216  UserInfo10->usri10_full_name[UserInfo->FullName.Length / sizeof(WCHAR)] = UNICODE_NULL;
1217  break;
1218 
1219  case 11:
1220  UserInfo11 = (PUSER_INFO_11)LocalBuffer;
1221 
1222  Ptr = (LPWSTR)((ULONG_PTR)UserInfo11 + sizeof(USER_INFO_11));
1223 
1224  UserInfo11->usri11_name = Ptr;
1225 
1226  memcpy(UserInfo11->usri11_name,
1227  UserInfo->UserName.Buffer,
1228  UserInfo->UserName.Length);
1229  UserInfo11->usri11_name[UserInfo->UserName.Length / sizeof(WCHAR)] = UNICODE_NULL;
1230 
1231  Ptr = (LPWSTR)((ULONG_PTR)Ptr + UserInfo->UserName.Length + sizeof(WCHAR));
1232 
1233  UserInfo11->usri11_comment = Ptr;
1234  memcpy(UserInfo11->usri11_comment,
1235  UserInfo->AdminComment.Buffer,
1236  UserInfo->AdminComment.Length);
1237  UserInfo11->usri11_comment[UserInfo->AdminComment.Length / sizeof(WCHAR)] = UNICODE_NULL;
1238  Ptr = (LPWSTR)((ULONG_PTR)Ptr + UserInfo->AdminComment.Length + sizeof(WCHAR));
1239 
1240  UserInfo11->usri11_usr_comment = Ptr;
1241  memcpy(UserInfo11->usri11_usr_comment,
1242  UserInfo->UserComment.Buffer,
1243  UserInfo->UserComment.Length);
1244  UserInfo11->usri11_usr_comment[UserInfo->UserComment.Length / sizeof(WCHAR)] = UNICODE_NULL;
1245  Ptr = (LPWSTR)((ULONG_PTR)Ptr + UserInfo->UserComment.Length + sizeof(WCHAR));
1246 
1247  UserInfo11->usri11_full_name = Ptr;
1248  memcpy(UserInfo11->usri11_full_name,
1249  UserInfo->FullName.Buffer,
1250  UserInfo->FullName.Length);
1251  UserInfo11->usri11_full_name[UserInfo->FullName.Length / sizeof(WCHAR)] = UNICODE_NULL;
1252  Ptr = (LPWSTR)((ULONG_PTR)Ptr + UserInfo->FullName.Length + sizeof(WCHAR));
1253 
1254  UserInfo11->usri11_priv = Priv;
1255  UserInfo11->usri11_auth_flags = AuthFlags;
1256 
1257  UserInfo11->usri11_password_age = GetPasswordAge(&UserInfo->PasswordLastSet);
1258 
1259  UserInfo11->usri11_home_dir = Ptr;
1260  memcpy(UserInfo11->usri11_home_dir,
1261  UserInfo->HomeDirectory.Buffer,
1262  UserInfo->HomeDirectory.Length);
1263  UserInfo11->usri11_home_dir[UserInfo->HomeDirectory.Length / sizeof(WCHAR)] = UNICODE_NULL;
1264  Ptr = (LPWSTR)((ULONG_PTR)Ptr + UserInfo->HomeDirectory.Length + sizeof(WCHAR));
1265 
1266  UserInfo11->usri11_parms = Ptr;
1267  memcpy(UserInfo11->usri11_parms,
1268  UserInfo->Parameters.Buffer,
1269  UserInfo->Parameters.Length);
1270  UserInfo11->usri11_parms[UserInfo->Parameters.Length / sizeof(WCHAR)] = UNICODE_NULL;
1271  Ptr = (LPWSTR)((ULONG_PTR)Ptr + UserInfo->Parameters.Length + sizeof(WCHAR));
1272 
1273  if (UserInfo->LastLogon.QuadPart == 0)
1274  UserInfo11->usri11_last_logon = 0;
1275  else
1277  &UserInfo11->usri11_last_logon);
1278 
1279  if (UserInfo->LastLogoff.QuadPart == 0)
1280  UserInfo11->usri11_last_logoff = 0;
1281  else
1283  &UserInfo11->usri11_last_logoff);
1284 
1285  UserInfo11->usri11_bad_pw_count = UserInfo->BadPasswordCount;
1286  UserInfo11->usri11_num_logons = UserInfo->LogonCount;
1287 
1288  UserInfo11->usri11_logon_server = Ptr;
1289  memcpy(UserInfo11->usri11_logon_server,
1290  LogonServer.Buffer,
1291  LogonServer.Length);
1292  UserInfo11->usri11_logon_server[LogonServer.Length / sizeof(WCHAR)] = UNICODE_NULL;
1293  Ptr = (LPWSTR)((ULONG_PTR)Ptr + LogonServer.Length + sizeof(WCHAR));
1294 
1295  UserInfo11->usri11_country_code = UserInfo->CountryCode;
1296 
1297  UserInfo11->usri11_workstations = Ptr;
1298  memcpy(UserInfo11->usri11_workstations,
1299  UserInfo->WorkStations.Buffer,
1300  UserInfo->WorkStations.Length);
1301  UserInfo11->usri11_workstations[UserInfo->WorkStations.Length / sizeof(WCHAR)] = UNICODE_NULL;
1302  Ptr = (LPWSTR)((ULONG_PTR)Ptr + UserInfo->WorkStations.Length + sizeof(WCHAR));
1303 
1305  UserInfo11->usri11_units_per_week = UserInfo->LogonHours.UnitsPerWeek;
1306 
1307  if (UserInfo->LogonHours.UnitsPerWeek > 0)
1308  {
1309  UserInfo11->usri11_logon_hours = (PVOID)Ptr;
1310 
1311  memcpy(UserInfo11->usri11_logon_hours,
1312  UserInfo->LogonHours.LogonHours,
1313  (((ULONG)UserInfo->LogonHours.UnitsPerWeek) + 7) / 8);
1314 
1315  Ptr = (LPWSTR)((ULONG_PTR)Ptr + (((ULONG)UserInfo->LogonHours.UnitsPerWeek) + 7) / 8);
1316  }
1317 
1318  UserInfo11->usri11_code_page = UserInfo->CodePage;
1319  break;
1320 
1321  case 20:
1322  UserInfo20 = (PUSER_INFO_20)LocalBuffer;
1323 
1324  Ptr = (LPWSTR)((ULONG_PTR)UserInfo20 + sizeof(USER_INFO_20));
1325 
1326  UserInfo20->usri20_name = Ptr;
1327 
1328  memcpy(UserInfo20->usri20_name,
1329  UserInfo->UserName.Buffer,
1330  UserInfo->UserName.Length);
1331  UserInfo20->usri20_name[UserInfo->UserName.Length / sizeof(WCHAR)] = UNICODE_NULL;
1332 
1333  Ptr = (LPWSTR)((ULONG_PTR)Ptr + UserInfo->UserName.Length + sizeof(WCHAR));
1334 
1335  UserInfo20->usri20_full_name = Ptr;
1336  memcpy(UserInfo20->usri20_full_name,
1337  UserInfo->FullName.Buffer,
1338  UserInfo->FullName.Length);
1339  UserInfo20->usri20_full_name[UserInfo->FullName.Length / sizeof(WCHAR)] = UNICODE_NULL;
1340  Ptr = (LPWSTR)((ULONG_PTR)Ptr + UserInfo->FullName.Length + sizeof(WCHAR));
1341 
1342  UserInfo20->usri20_comment = Ptr;
1343  memcpy(UserInfo20->usri20_comment,
1344  UserInfo->AdminComment.Buffer,
1345  UserInfo->AdminComment.Length);
1346  UserInfo20->usri20_comment[UserInfo->AdminComment.Length / sizeof(WCHAR)] = UNICODE_NULL;
1347  Ptr = (LPWSTR)((ULONG_PTR)Ptr + UserInfo->AdminComment.Length + sizeof(WCHAR));
1348 
1349  UserInfo20->usri20_flags = GetAccountFlags(UserInfo->UserAccountControl,
1350  Dacl);
1351 
1352  UserInfo20->usri20_user_id = RelativeId;
1353  break;
1354 
1355  case 23:
1356  UserInfo23 = (PUSER_INFO_23)LocalBuffer;
1357 
1358  Ptr = (LPWSTR)((ULONG_PTR)UserInfo23 + sizeof(USER_INFO_23));
1359 
1360  UserInfo23->usri23_name = Ptr;
1361 
1362  memcpy(UserInfo23->usri23_name,
1363  UserInfo->UserName.Buffer,
1364  UserInfo->UserName.Length);
1365  UserInfo23->usri23_name[UserInfo->UserName.Length / sizeof(WCHAR)] = UNICODE_NULL;
1366 
1367  Ptr = (LPWSTR)((ULONG_PTR)Ptr + UserInfo->UserName.Length + sizeof(WCHAR));
1368 
1369  UserInfo23->usri23_full_name = Ptr;
1370  memcpy(UserInfo23->usri23_full_name,
1371  UserInfo->FullName.Buffer,
1372  UserInfo->FullName.Length);
1373  UserInfo23->usri23_full_name[UserInfo->FullName.Length / sizeof(WCHAR)] = UNICODE_NULL;
1374  Ptr = (LPWSTR)((ULONG_PTR)Ptr + UserInfo->FullName.Length + sizeof(WCHAR));
1375 
1376  UserInfo23->usri23_comment = Ptr;
1377  memcpy(UserInfo23->usri23_comment,
1378  UserInfo->AdminComment.Buffer,
1379  UserInfo->AdminComment.Length);
1380  UserInfo23->usri23_comment[UserInfo->AdminComment.Length / sizeof(WCHAR)] = UNICODE_NULL;
1381  Ptr = (LPWSTR)((ULONG_PTR)Ptr + UserInfo->AdminComment.Length + sizeof(WCHAR));
1382 
1383  UserInfo23->usri23_flags = GetAccountFlags(UserInfo->UserAccountControl,
1384  Dacl);
1385 
1386  UserInfo23->usri23_user_sid = (PVOID)Ptr;
1387  CopySidFromSidAndRid(UserInfo23->usri23_user_sid, AccountDomainSid, RelativeId);
1389  break;
1390  }
1391 
1392 done:
1393  if (UserInfo != NULL)
1394  FreeUserInfo(UserInfo);
1395 
1396  if (Dacl != NULL)
1397  HeapFree(GetProcessHeap(), 0, Dacl);
1398 
1399  if (ApiStatus == NERR_Success)
1400  {
1401  *Buffer = LocalBuffer;
1402  }
1403  else
1404  {
1405  if (LocalBuffer != NULL)
1406  NetApiBufferFree(LocalBuffer);
1407  }
1408 
1409  return ApiStatus;
1410 }
DWORD usri4_password_expired
Definition: lmaccess.h:298
DWORD usri4_last_logoff
Definition: lmaccess.h:284
NET_API_STATUS WINAPI NetApiBufferAllocate(DWORD ByteCount, LPVOID *Buffer)
Definition: apibuf.c:28
LPWSTR usri11_usr_comment
Definition: lmaccess.h:309
LOGON_HOURS LogonHours
Definition: ntsam.h:682
#define USER_PASSWORD_EXPIRED
Definition: ntsam.h:184
DWORD usri11_auth_flags
Definition: lmaccess.h:312
DWORD usri1_password_age
Definition: lmaccess.h:205
LPWSTR usri1_password
Definition: lmaccess.h:204
GLint level
Definition: gl.h:1546
ULONG PrimaryGroupId
Definition: ntsam.h:679
LPWSTR usri3_comment
Definition: lmaccess.h:244
DWORD usri11_units_per_week
Definition: lmaccess.h:324
LARGE_INTEGER AccountExpires
Definition: ntsam.h:661
struct _USER_INFO_4 * PUSER_INFO_4
LARGE_INTEGER PasswordLastSet
Definition: ntsam.h:660
LPWSTR usri23_name
Definition: lmaccess.h:365
LPWSTR usri3_parms
Definition: lmaccess.h:250
LPWSTR usri2_logon_server
Definition: lmaccess.h:234
PBYTE usri11_logon_hours
Definition: lmaccess.h:325
DWORD usri3_bad_pw_count
Definition: lmaccess.h:258
UNICODE_STRING ScriptPath
Definition: ntsam.h:668
LPWSTR usri11_logon_server
Definition: lmaccess.h:320
USHORT CountryCode
Definition: ntsam.h:685
struct _USER_INFO_11 * PUSER_INFO_11
BOOLEAN NTAPI RtlTimeToSecondsSince1970(PLARGE_INTEGER Time, PULONG ElapsedSeconds)
LPWSTR usri3_home_dir
Definition: lmaccess.h:243
struct _USER_INFO_20 USER_INFO_20
DWORD usri2_priv
Definition: lmaccess.h:216
DWORD usri11_last_logon
Definition: lmaccess.h:316
DWORD usri2_num_logons
Definition: lmaccess.h:233
UNICODE_STRING HomeDirectoryDrive
Definition: ntsam.h:667
DWORD usri11_last_logoff
Definition: lmaccess.h:317
LPWSTR usri3_profile
Definition: lmaccess.h:265
_Must_inspect_result_ _In_ PFSRTL_PER_STREAM_CONTEXT Ptr
Definition: fsrtlfuncs.h:898
LPWSTR usri2_name
Definition: lmaccess.h:213
LONG NTSTATUS
Definition: precomp.h:26
struct _USER_INFO_10 USER_INFO_10
LPWSTR usri0_name
Definition: lmaccess.h:201
DWORD usri3_code_page
Definition: lmaccess.h:262
LPWSTR usri4_home_dir
Definition: lmaccess.h:274
struct _USER_INFO_10 * PUSER_INFO_10
LPWSTR usri10_comment
Definition: lmaccess.h:302
#define ZeroMemory
Definition: winbase.h:1635
LPWSTR usri10_name
Definition: lmaccess.h:301
DWORD usri3_acct_expires
Definition: lmaccess.h:254
LPWSTR usri11_full_name
Definition: lmaccess.h:310
struct _USER_INFO_4 USER_INFO_4
DWORD usri4_flags
Definition: lmaccess.h:276
UNICODE_STRING ProfilePath
Definition: ntsam.h:669
#define MAXLONGLONG
DWORD usri4_auth_flags
Definition: lmaccess.h:278
DWORD usri2_auth_flags
Definition: lmaccess.h:221
LPWSTR usri4_logon_server
Definition: lmaccess.h:291
ULONG UserAccountControl
Definition: ntsam.h:680
static DWORD GetPasswordAge(IN PLARGE_INTEGER PasswordLastSet)
Definition: user.c:243
USHORT UnitsPerWeek
Definition: ntsam.h:474
DWORD usri11_bad_pw_count
Definition: lmaccess.h:318
DWORD usri3_num_logons
Definition: lmaccess.h:259
DWORD usri2_acct_expires
Definition: lmaccess.h:228
DWORD usri4_priv
Definition: lmaccess.h:273
LPWSTR usri3_home_dir_drive
Definition: lmaccess.h:266
#define NERR_Success
Definition: lmerr.h:5
uint32_t ULONG_PTR
Definition: typedefs.h:63
DWORD usri2_last_logoff
Definition: lmaccess.h:227
DWORD usri4_country_code
Definition: lmaccess.h:292
#define USER_MAXSTORAGE_UNLIMITED
Definition: lmaccess.h:111
static NET_API_STATUS GetUserDacl(IN SAM_HANDLE UserHandle, OUT PACL *Dacl)
Definition: user.c:285
DWORD usri2_password_age
Definition: lmaccess.h:215
#define UNICODE_NULL
LPWSTR usri20_full_name
Definition: lmaccess.h:330
DWORD usri2_units_per_week
Definition: lmaccess.h:230
DWORD usri11_password_age
Definition: lmaccess.h:313
DWORD usri2_max_storage
Definition: lmaccess.h:229
PUCHAR LogonHours
Definition: ntsam.h:475
DWORD usri4_last_logon
Definition: lmaccess.h:283
struct _USER_INFO_1 USER_INFO_1
DWORD usri3_primary_group_id
Definition: lmaccess.h:264
LPWSTR usri4_workstations
Definition: lmaccess.h:282
static NET_API_STATUS GetUserPrivileges(_In_ SAM_HANDLE BuiltinDomainHandle, _In_ SAM_HANDLE UserHandle, _In_ PSID AccountDomainSid, _In_ ULONG RelativeId, _Out_ PDWORD Priv, _Out_ PDWORD AuthFlags)
Definition: user.c:410
LPWSTR usri4_full_name
Definition: lmaccess.h:279
LPWSTR usri3_full_name
Definition: lmaccess.h:248
struct _USER_INFO_20 * PUSER_INFO_20
struct _USER_INFO_2 * PUSER_INFO_2
DWORD usri4_primary_group_id
Definition: lmaccess.h:295
LPWSTR usri4_password
Definition: lmaccess.h:271
LPWSTR usri20_comment
Definition: lmaccess.h:331
smooth NULL
Definition: ftsmooth.c:416
struct _USER_INFO_3 USER_INFO_3
DWORD usri3_flags
Definition: lmaccess.h:245
Definition: bufpool.h:45
NTSYSAPI ULONG NTAPI RtlLengthSid(IN PSID Sid)
Definition: sid.c:150
LPWSTR usri20_name
Definition: lmaccess.h:329
void * PVOID
Definition: retypes.h:9
struct _USER_INFO_1 * PUSER_INFO_1
UNICODE_STRING AdminComment
Definition: ntsam.h:670
DWORD usri3_last_logoff
Definition: lmaccess.h:253
DWORD usri3_auth_flags
Definition: lmaccess.h:247
struct _USER_INFO_11 USER_INFO_11
DWORD usri2_country_code
Definition: lmaccess.h:235
LPWSTR usri2_parms
Definition: lmaccess.h:224
DWORD usri4_units_per_week
Definition: lmaccess.h:287
DWORD NET_API_STATUS
Definition: ms-dtyp.idl:91
LPWSTR usri2_full_name
Definition: lmaccess.h:222
DWORD usri11_num_logons
Definition: lmaccess.h:319
LPWSTR usri11_workstations
Definition: lmaccess.h:322
DWORD usri2_code_page
Definition: lmaccess.h:236
LPWSTR usri3_name
Definition: lmaccess.h:239
#define GetProcessHeap()
Definition: compat.h:395
DWORD usri4_acct_expires
Definition: lmaccess.h:285
LPWSTR usri11_home_dir
Definition: lmaccess.h:314
struct _USER_INFO_23 * PUSER_INFO_23
__wchar_t WCHAR
Definition: xmlstorage.h:180
LPWSTR usri2_workstations
Definition: lmaccess.h:225
LPWSTR usri1_comment
Definition: lmaccess.h:208
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
DWORD usri11_max_storage
Definition: lmaccess.h:323
DWORD usri4_code_page
Definition: lmaccess.h:293
LPWSTR usri3_logon_server
Definition: lmaccess.h:260
LPWSTR usri2_script_path
Definition: lmaccess.h:220
UNICODE_STRING HomeDirectory
Definition: ntsam.h:666
static VOID FreeUserInfo(PUSER_ALL_INFORMATION UserInfo)
Definition: user.c:366
LPWSTR usri11_comment
Definition: lmaccess.h:308
DWORD usri20_flags
Definition: lmaccess.h:332
LPWSTR usri4_profile
Definition: lmaccess.h:296
unsigned long DWORD
Definition: ntddk_ex.h:95
LPWSTR usri11_name
Definition: lmaccess.h:307
DWORD usri4_max_storage
Definition: lmaccess.h:286
DWORD usri4_password_age
Definition: lmaccess.h:272
LPWSTR usri1_name
Definition: lmaccess.h:203
LPWSTR usri2_home_dir
Definition: lmaccess.h:217
LPWSTR usri11_parms
Definition: lmaccess.h:315
PSID usri4_user_sid
Definition: lmaccess.h:294
LARGE_INTEGER LastLogoff
Definition: ntsam.h:659
DWORD usri11_country_code
Definition: lmaccess.h:321
_Out_writes_bytes_to_opt_ AbsoluteSecurityDescriptorSize PSECURITY_DESCRIPTOR _Inout_ PULONG _Out_writes_bytes_to_opt_ DaclSize PACL Dacl
Definition: rtlfuncs.h:1553
DWORD usri2_last_logon
Definition: lmaccess.h:226
UNICODE_STRING UserName
Definition: ntsam.h:664
DWORD usri3_last_logon
Definition: lmaccess.h:252
static const WCHAR L[]
Definition: oid.c:1250
NET_API_STATUS WINAPI NetpNtStatusToApiStatus(_In_ NTSTATUS Status)
Definition: misc.c:140
DWORD usri3_priv
Definition: lmaccess.h:242
PBYTE usri2_logon_hours
Definition: lmaccess.h:231
LPWSTR usri3_workstations
Definition: lmaccess.h:251
LPWSTR usri1_script_path
Definition: lmaccess.h:210
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
LPWSTR usri4_comment
Definition: lmaccess.h:275
DWORD usri20_user_id
Definition: lmaccess.h:333
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:359
struct _USER_INFO_0 USER_INFO_0
Status
Definition: gdiplustypes.h:24
UNICODE_STRING WorkStations
Definition: ntsam.h:671
VOID CopySidFromSidAndRid(_Out_ PSID DstSid, _In_ PSID SrcSid, _In_ ULONG RelativeId)
Definition: utils.c:220
LPWSTR usri3_password
Definition: lmaccess.h:240
UNICODE_STRING FullName
Definition: ntsam.h:665
#define ERR(fmt,...)
Definition: debug.h:109
LPWSTR usri3_usr_comment
Definition: lmaccess.h:249
PSID usri23_user_sid
Definition: lmaccess.h:369
LARGE_INTEGER LastLogon
Definition: ntsam.h:658
LPWSTR usri4_usr_comment
Definition: lmaccess.h:280
LPWSTR usri23_full_name
Definition: lmaccess.h:366
NET_API_STATUS WINAPI NetApiBufferFree(LPVOID Buffer)
Definition: apibuf.c:43
struct _USER_INFO_23 USER_INFO_23
LPWSTR usri10_full_name
Definition: lmaccess.h:304
DWORD usri3_max_storage
Definition: lmaccess.h:255
DWORD usri1_priv
Definition: lmaccess.h:206
DWORD usri3_password_age
Definition: lmaccess.h:241
USHORT BadPasswordCount
Definition: ntsam.h:683
UNICODE_STRING UserComment
Definition: ntsam.h:672
LPWSTR usri2_password
Definition: lmaccess.h:214
static ULONG GetAccountFlags(ULONG AccountControl, PACL Dacl)
Definition: user.c:127
PBYTE usri3_logon_hours
Definition: lmaccess.h:257
DWORD usri2_flags
Definition: lmaccess.h:219
struct _USER_INFO_3 * PUSER_INFO_3
DWORD usri4_bad_pw_count
Definition: lmaccess.h:289
DWORD usri3_password_expired
Definition: lmaccess.h:267
PBYTE usri4_logon_hours
Definition: lmaccess.h:288
DWORD usri23_flags
Definition: lmaccess.h:368
LPWSTR usri2_usr_comment
Definition: lmaccess.h:223
#define TIMEQ_FOREVER
Definition: lmaccess.h:110
DWORD usri3_units_per_week
Definition: lmaccess.h:256
DWORD usri1_flags
Definition: lmaccess.h:209
LPWSTR usri4_name
Definition: lmaccess.h:270
LPWSTR usri4_script_path
Definition: lmaccess.h:277
LPWSTR usri3_script_path
Definition: lmaccess.h:246
unsigned int ULONG
Definition: retypes.h:1
struct _USER_INFO_0 * PUSER_INFO_0
PSID AccountDomainSid
Definition: database.c:22
DWORD usri3_country_code
Definition: lmaccess.h:261
#define ERROR_INVALID_LEVEL
Definition: winerror.h:196
DWORD usri3_user_id
Definition: lmaccess.h:263
WCHAR * LPWSTR
Definition: xmlstorage.h:184
LPWSTR usri23_comment
Definition: lmaccess.h:367
LPWSTR usri4_parms
Definition: lmaccess.h:281
DWORD usri4_num_logons
Definition: lmaccess.h:290
LPWSTR usri4_home_dir_drive
Definition: lmaccess.h:297
struct _USER_INFO_2 USER_INFO_2
NTSTATUS NTAPI SamQueryInformationUser(IN SAM_HANDLE UserHandle, IN USER_INFORMATION_CLASS UserInformationClass, OUT PVOID *Buffer)
Definition: samlib.c:1695
LPWSTR usri2_comment
Definition: lmaccess.h:218
LPWSTR usri10_usr_comment
Definition: lmaccess.h:303
LPWSTR usri1_home_dir
Definition: lmaccess.h:207
#define HeapFree(x, y, z)
Definition: compat.h:394
DWORD usri2_bad_pw_count
Definition: lmaccess.h:232
LONGLONG QuadPart
Definition: typedefs.h:112
DWORD usri11_code_page
Definition: lmaccess.h:326
DWORD usri11_priv
Definition: lmaccess.h:311
UNICODE_STRING Parameters
Definition: ntsam.h:673
#define RTL_CONSTANT_STRING(s)
Definition: tunneltest.c:14

Referenced by NetUserEnum(), and NetUserGetInfo().

◆ ChangeUserDacl()

static VOID ChangeUserDacl ( IN PACL  Dacl,
IN ULONG  Flags 
)
static

Definition at line 263 of file user.c.

265 {
268 
269  if (Dacl == NULL)
270  return;
271 
273  if (!NT_SUCCESS(Status))
274  return;
275 
277  Ace->Mask &= ~USER_CHANGE_PASSWORD;
278  else
279  Ace->Mask |= USER_CHANGE_PASSWORD;
280 }
LONG NTSTATUS
Definition: precomp.h:26
#define UF_PASSWD_CANT_CHANGE
Definition: lmaccess.h:28
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
Definition: card.h:12
smooth NULL
Definition: ftsmooth.c:416
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
_Out_writes_bytes_to_opt_ AbsoluteSecurityDescriptorSize PSECURITY_DESCRIPTOR _Inout_ PULONG _Out_writes_bytes_to_opt_ DaclSize PACL Dacl
Definition: rtlfuncs.h:1553
Status
Definition: gdiplustypes.h:24
static NTSTATUS GetAllowedWorldAce(IN PACL Acl, OUT PACCESS_ALLOWED_ACE *Ace)
Definition: user.c:80
#define USER_CHANGE_PASSWORD
Definition: ntsam.h:132

Referenced by SetUserInfo().

◆ DeltaTimeToSeconds()

static ULONG DeltaTimeToSeconds ( LARGE_INTEGER  DeltaTime)
static

Definition at line 62 of file user.c.

63 {
64  LARGE_INTEGER Seconds;
65 
66  if (DeltaTime.QuadPart == 0)
67  return 0;
68 
69  Seconds.QuadPart = -DeltaTime.QuadPart / 10000000;
70 
71  if (Seconds.HighPart != 0)
72  return TIMEQ_FOREVER;
73 
74  return Seconds.LowPart;
75 }
ULONG LowPart
Definition: typedefs.h:104
#define TIMEQ_FOREVER
Definition: lmaccess.h:110
LONGLONG QuadPart
Definition: typedefs.h:112

Referenced by NetUserModalsGet().

◆ FreeEnumContext()

static VOID FreeEnumContext ( PENUM_CONTEXT  EnumContext)
static

Definition at line 2709 of file user.c.

2712 {
2713  /* Remove the context from the list */
2715  RemoveEntryList(&EnumContext->ListLink);
2717 
2718  /* Free it */
2719  NetApiBufferFree(EnumContext);
2720 }
CRITICAL_SECTION g_EnumContextListLock
Definition: user.c:57
void WINAPI EnterCriticalSection(LPCRITICAL_SECTION)
FORCEINLINE BOOLEAN RemoveEntryList(_In_ PLIST_ENTRY Entry)
Definition: rtlfuncs.h:105
NET_API_STATUS WINAPI NetApiBufferFree(LPVOID Buffer)
Definition: apibuf.c:43
LIST_ENTRY ListLink
Definition: user.c:39
void WINAPI LeaveCriticalSection(LPCRITICAL_SECTION)

Referenced by NetUserEnum().

◆ FreeUserInfo()

static VOID FreeUserInfo ( PUSER_ALL_INFORMATION  UserInfo)
static

Definition at line 366 of file user.c.

367 {
368  if (UserInfo->UserName.Buffer != NULL)
369  SamFreeMemory(UserInfo->UserName.Buffer);
370 
371  if (UserInfo->FullName.Buffer != NULL)
372  SamFreeMemory(UserInfo->FullName.Buffer);
373 
374  if (UserInfo->HomeDirectory.Buffer != NULL)
376 
377  if (UserInfo->HomeDirectoryDrive.Buffer != NULL)
379 
380  if (UserInfo->ScriptPath.Buffer != NULL)
381  SamFreeMemory(UserInfo->ScriptPath.Buffer);
382 
383  if (UserInfo->ProfilePath.Buffer != NULL)
384  SamFreeMemory(UserInfo->ProfilePath.Buffer);
385 
386  if (UserInfo->AdminComment.Buffer != NULL)
387  SamFreeMemory(UserInfo->AdminComment.Buffer);
388 
389  if (UserInfo->WorkStations.Buffer != NULL)
390  SamFreeMemory(UserInfo->WorkStations.Buffer);
391 
392  if (UserInfo->UserComment.Buffer != NULL)
393  SamFreeMemory(UserInfo->UserComment.Buffer);
394 
395  if (UserInfo->Parameters.Buffer != NULL)
396  SamFreeMemory(UserInfo->Parameters.Buffer);
397 
398  if (UserInfo->PrivateData.Buffer != NULL)
399  SamFreeMemory(UserInfo->PrivateData.Buffer);
400 
401  if (UserInfo->LogonHours.LogonHours != NULL)
403 
404  SamFreeMemory(UserInfo);
405 }
LOGON_HOURS LogonHours
Definition: ntsam.h:682
UNICODE_STRING ScriptPath
Definition: ntsam.h:668
UNICODE_STRING PrivateData
Definition: ntsam.h:676
UNICODE_STRING HomeDirectoryDrive
Definition: ntsam.h:667
UNICODE_STRING ProfilePath
Definition: ntsam.h:669
PUCHAR LogonHours
Definition: ntsam.h:475
smooth NULL
Definition: ftsmooth.c:416
UNICODE_STRING AdminComment
Definition: ntsam.h:670
UNICODE_STRING HomeDirectory
Definition: ntsam.h:666
UNICODE_STRING UserName
Definition: ntsam.h:664
NTSTATUS NTAPI SamFreeMemory(IN PVOID Buffer)
Definition: samlib.c:947
UNICODE_STRING WorkStations
Definition: ntsam.h:671
UNICODE_STRING FullName
Definition: ntsam.h:665
UNICODE_STRING UserComment
Definition: ntsam.h:672
UNICODE_STRING Parameters
Definition: ntsam.h:673

Referenced by BuildUserInfoBuffer().

◆ GetAccountControl()

static ULONG GetAccountControl ( ULONG  Flags)
static

Definition at line 206 of file user.c.

207 {
208  ULONG AccountControl = 0;
209 
210  if (Flags & UF_ACCOUNTDISABLE)
211  AccountControl |= USER_ACCOUNT_DISABLED;
212 
214  AccountControl |= USER_HOME_DIRECTORY_REQUIRED;
215 
216  if (Flags & UF_PASSWD_NOTREQD)
217  AccountControl |= USER_PASSWORD_NOT_REQUIRED;
218 
219  if (Flags & UF_LOCKOUT)
220  AccountControl |= USER_ACCOUNT_AUTO_LOCKED;
221 
223  AccountControl |= USER_DONT_EXPIRE_PASSWORD;
224 
225  /* Set account type flags */
227  AccountControl |= USER_TEMP_DUPLICATE_ACCOUNT;
228  else if (Flags & UF_NORMAL_ACCOUNT)
229  AccountControl |= USER_NORMAL_ACCOUNT;
231  AccountControl |= USER_INTERDOMAIN_TRUST_ACCOUNT;
233  AccountControl |= USER_WORKSTATION_TRUST_ACCOUNT;
234  else if (Flags & UF_SERVER_TRUST_ACCOUNT)
235  AccountControl |= USER_SERVER_TRUST_ACCOUNT;
236 
237  return AccountControl;
238 }
#define USER_INTERDOMAIN_TRUST_ACCOUNT
Definition: ntsam.h:173
#define USER_PASSWORD_NOT_REQUIRED
Definition: ntsam.h:169
#define UF_INTERDOMAIN_TRUST_ACCOUNT
Definition: lmaccess.h:31
#define USER_TEMP_DUPLICATE_ACCOUNT
Definition: ntsam.h:170
#define UF_TEMP_DUPLICATE_ACCOUNT
Definition: lmaccess.h:29
#define USER_HOME_DIRECTORY_REQUIRED
Definition: ntsam.h:168
#define USER_ACCOUNT_DISABLED
Definition: ntsam.h:167
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
#define UF_PASSWD_NOTREQD
Definition: lmaccess.h:27
#define UF_SERVER_TRUST_ACCOUNT
Definition: lmaccess.h:33
#define USER_NORMAL_ACCOUNT
Definition: ntsam.h:171
#define USER_ACCOUNT_AUTO_LOCKED
Definition: ntsam.h:177
#define UF_WORKSTATION_TRUST_ACCOUNT
Definition: lmaccess.h:32
#define UF_DONT_EXPIRE_PASSWD
Definition: lmaccess.h:37
#define UF_HOMEDIR_REQUIRED
Definition: lmaccess.h:25
#define UF_ACCOUNTDISABLE
Definition: lmaccess.h:24
#define UF_NORMAL_ACCOUNT
Definition: lmaccess.h:30
#define USER_SERVER_TRUST_ACCOUNT
Definition: ntsam.h:175
#define UF_LOCKOUT
Definition: lmaccess.h:26
unsigned int ULONG
Definition: retypes.h:1
#define USER_WORKSTATION_TRUST_ACCOUNT
Definition: ntsam.h:174
#define USER_DONT_EXPIRE_PASSWORD
Definition: ntsam.h:176

Referenced by SetUserInfo().

◆ GetAccountFlags()

static ULONG GetAccountFlags ( ULONG  AccountControl,
PACL  Dacl 
)
static

Definition at line 127 of file user.c.

129 {
133 
134  if (Dacl != NULL)
135  {
137  if (NT_SUCCESS(Status))
138  {
139  if (Ace == NULL)
140  {
142  }
143  else if ((Ace->Mask & USER_CHANGE_PASSWORD) == 0)
144  {
146  }
147  }
148  }
149 
150  if (AccountControl & USER_ACCOUNT_DISABLED)
152 
153  if (AccountControl & USER_HOME_DIRECTORY_REQUIRED)
155 
156  if (AccountControl & USER_PASSWORD_NOT_REQUIRED)
158 
159  if (AccountControl & USER_ACCOUNT_AUTO_LOCKED)
160  Flags |= UF_LOCKOUT;
161 
162  if (AccountControl & USER_DONT_EXPIRE_PASSWORD)
164 
165 /*
166  if (AccountControl & USER_ENCRYPTED_TEXT_PASSWORD_ALLOWED)
167  Flags |= UF_ENCRYPTED_TEXT_PASSWORD_ALLOWED;
168 
169  if (AccountControl & USER_SMARTCARD_REQUIRED)
170  Flags |= UF_SMARTCARD_REQUIRED;
171 
172  if (AccountControl & USER_TRUSTED_FOR_DELEGATION)
173  Flags |= UF_TRUSTED_FOR_DELEGATION;
174 
175  if (AccountControl & USER_NOT_DELEGATED)
176  Flags |= UF_NOT_DELEGATED;
177 
178  if (AccountControl & USER_USE_DES_KEY_ONLY)
179  Flags |= UF_USE_DES_KEY_ONLY;
180 
181  if (AccountControl & USER_DONT_REQUIRE_PREAUTH)
182  Flags |= UF_DONT_REQUIRE_PREAUTH;
183 
184  if (AccountControl & USER_PASSWORD_EXPIRED)
185  Flags |= UF_PASSWORD_EXPIRED;
186 */
187 
188  /* Set account type flags */
189  if (AccountControl & USER_TEMP_DUPLICATE_ACCOUNT)
191  else if (AccountControl & USER_NORMAL_ACCOUNT)
193  else if (AccountControl & USER_INTERDOMAIN_TRUST_ACCOUNT)
195  else if (AccountControl & USER_WORKSTATION_TRUST_ACCOUNT)
197  else if (AccountControl & USER_SERVER_TRUST_ACCOUNT)
199 
200  return Flags;
201 }
#define USER_INTERDOMAIN_TRUST_ACCOUNT
Definition: ntsam.h:173
#define USER_PASSWORD_NOT_REQUIRED
Definition: ntsam.h:169
#define UF_INTERDOMAIN_TRUST_ACCOUNT
Definition: lmaccess.h:31
#define USER_TEMP_DUPLICATE_ACCOUNT
Definition: ntsam.h:170
LONG NTSTATUS
Definition: precomp.h:26
#define UF_TEMP_DUPLICATE_ACCOUNT
Definition: lmaccess.h:29
#define USER_HOME_DIRECTORY_REQUIRED
Definition: ntsam.h:168
#define USER_ACCOUNT_DISABLED
Definition: ntsam.h:167
#define UF_PASSWD_CANT_CHANGE
Definition: lmaccess.h:28
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
Definition: card.h:12
smooth NULL
Definition: ftsmooth.c:416
#define UF_PASSWD_NOTREQD
Definition: lmaccess.h:27
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define UF_SERVER_TRUST_ACCOUNT
Definition: lmaccess.h:33
#define USER_NORMAL_ACCOUNT
Definition: ntsam.h:171
_Out_writes_bytes_to_opt_ AbsoluteSecurityDescriptorSize PSECURITY_DESCRIPTOR _Inout_ PULONG _Out_writes_bytes_to_opt_ DaclSize PACL Dacl
Definition: rtlfuncs.h:1553
#define USER_ACCOUNT_AUTO_LOCKED
Definition: ntsam.h:177
#define UF_WORKSTATION_TRUST_ACCOUNT
Definition: lmaccess.h:32
#define UF_DONT_EXPIRE_PASSWD
Definition: lmaccess.h:37
Status
Definition: gdiplustypes.h:24
#define UF_HOMEDIR_REQUIRED
Definition: lmaccess.h:25
#define UF_ACCOUNTDISABLE
Definition: lmaccess.h:24
static NTSTATUS GetAllowedWorldAce(IN PACL Acl, OUT PACCESS_ALLOWED_ACE *Ace)
Definition: user.c:80
#define UF_NORMAL_ACCOUNT
Definition: lmaccess.h:30
#define USER_SERVER_TRUST_ACCOUNT
Definition: ntsam.h:175
#define UF_LOCKOUT
Definition: lmaccess.h:26
unsigned int ULONG
Definition: retypes.h:1
#define UF_SCRIPT
Definition: lmaccess.h:23
#define USER_WORKSTATION_TRUST_ACCOUNT
Definition: ntsam.h:174
#define USER_DONT_EXPIRE_PASSWORD
Definition: ntsam.h:176
#define USER_CHANGE_PASSWORD
Definition: ntsam.h:132

Referenced by BuildUserInfoBuffer().

◆ GetAllowedWorldAce()

static NTSTATUS GetAllowedWorldAce ( IN PACL  Acl,
OUT PACCESS_ALLOWED_ACE Ace 
)
static

Definition at line 80 of file user.c.

82 {
84  ULONG WorldSid[sizeof(SID) / sizeof(ULONG) + SID_MAX_SUB_AUTHORITIES];
85  ACL_SIZE_INFORMATION AclSize;
86  PVOID LocalAce = NULL;
87  ULONG i;
89 
90  *Ace = NULL;
91 
94  1);
96 
98  &AclSize,
99  sizeof(AclSize),
101  if (!NT_SUCCESS(Status))
102  return Status;
103 
104  for (i = 0; i < AclSize.AceCount; i++)
105  {
106  Status = RtlGetAce(Acl, i, &LocalAce);
107  if (!NT_SUCCESS(Status))
108  return Status;
109 
110  if (((PACE_HEADER)LocalAce)->AceType != ACCESS_ALLOWED_ACE_TYPE)
111  continue;
112 
114  (PSID)&((PACCESS_ALLOWED_ACE)LocalAce)->SidStart))
115  {
116  *Ace = (PACCESS_ALLOWED_ACE)LocalAce;
117  return STATUS_SUCCESS;
118  }
119  }
120 
121  return STATUS_SUCCESS;
122 }
struct _SID SID
LONG NTSTATUS
Definition: precomp.h:26
static SID_IDENTIFIER_AUTHORITY WorldAuthority
Definition: security.c:14
NTSYSAPI PULONG NTAPI RtlSubAuthoritySid(_In_ PSID Sid, _In_ ULONG SubAuthority)
NTSYSAPI NTSTATUS NTAPI RtlGetAce(PACL Acl, ULONG AceIndex, PVOID *Ace)
NTSYSAPI NTSTATUS NTAPI RtlInitializeSid(IN OUT PSID Sid, IN PSID_IDENTIFIER_AUTHORITY IdentifierAuthority, IN UCHAR SubAuthorityCount)
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
Definition: card.h:12
#define SID_MAX_SUB_AUTHORITIES
Definition: setypes.h:454
smooth NULL
Definition: ftsmooth.c:416
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define SECURITY_WORLD_SID_AUTHORITY
Definition: setypes.h:499
#define ACCESS_ALLOWED_ACE_TYPE
Definition: setypes.h:685
#define SECURITY_WORLD_RID
Definition: setypes.h:513
PSID WorldSid
Definition: globals.c:15
Status
Definition: gdiplustypes.h:24
static const ACEFLAG AceType[]
Definition: security.c:2259
NTSYSAPI NTSTATUS WINAPI RtlQueryInformationAcl(PACL, LPVOID, DWORD, ACL_INFORMATION_CLASS)
struct _ACCESS_ALLOWED_ACE * PACCESS_ALLOWED_ACE
unsigned int ULONG
Definition: retypes.h:1
return STATUS_SUCCESS
Definition: btrfs.c:2725
NTSYSAPI BOOLEAN NTAPI RtlEqualSid(_In_ PSID Sid1, _In_ PSID Sid2)

Referenced by ChangeUserDacl(), and GetAccountFlags().

◆ GetPasswordAge()

static DWORD GetPasswordAge ( IN PLARGE_INTEGER  PasswordLastSet)
static

Definition at line 243 of file user.c.

244 {
245  LARGE_INTEGER SystemTime;
246  ULONG SystemSecondsSince1970;
247  ULONG PasswordSecondsSince1970;
249 
250  Status = NtQuerySystemTime(&SystemTime);
251  if (!NT_SUCCESS(Status))
252  return 0;
253 
254  RtlTimeToSecondsSince1970(&SystemTime, &SystemSecondsSince1970);
255  RtlTimeToSecondsSince1970(PasswordLastSet, &PasswordSecondsSince1970);
256 
257  return SystemSecondsSince1970 - PasswordSecondsSince1970;
258 }
BOOLEAN NTAPI RtlTimeToSecondsSince1970(PLARGE_INTEGER Time, PULONG ElapsedSeconds)
LONG NTSTATUS
Definition: precomp.h:26
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
Status
Definition: gdiplustypes.h:24
unsigned int ULONG
Definition: retypes.h:1
NTSTATUS NTAPI NtQuerySystemTime(OUT PLARGE_INTEGER SystemTime)
Definition: time.c:417

Referenced by BuildUserInfoBuffer().

◆ GetUserDacl()

static NET_API_STATUS GetUserDacl ( IN SAM_HANDLE  UserHandle,
OUT PACL Dacl 
)
static

Definition at line 285 of file user.c.

287 {
289  PACL SamDacl;
290  PACL LocalDacl;
291  BOOLEAN Defaulted;
292  BOOLEAN Present;
293  ACL_SIZE_INFORMATION AclSize;
294  NET_API_STATUS ApiStatus;
296 
297  TRACE("(%p %p)\n", UserHandle, Dacl);
298 
299  *Dacl = NULL;
300 
301  Status = SamQuerySecurityObject(UserHandle,
304  if (!NT_SUCCESS(Status))
305  {
306  TRACE("SamQuerySecurityObject() failed (Status 0x%08lx)\n", Status);
307  ApiStatus = NetpNtStatusToApiStatus(Status);
308  goto done;
309  }
310 
312  &Present,
313  &SamDacl,
314  &Defaulted);
315  if (!NT_SUCCESS(Status))
316  {
317  TRACE("RtlGetDaclSecurityDescriptor() failed (Status 0x%08lx)\n", Status);
318  ApiStatus = NERR_InternalError;
319  goto done;
320  }
321 
322  if (Present == FALSE)
323  {
324  TRACE("No DACL present\n");
325  ApiStatus = NERR_Success;
326  goto done;
327  }
328 
329  Status = RtlQueryInformationAcl(SamDacl,
330  &AclSize,
331  sizeof(AclSize),
333  if (!NT_SUCCESS(Status))
334  {
335  TRACE("RtlQueryInformationAcl() failed (Status 0x%08lx)\n", Status);
336  ApiStatus = NERR_InternalError;
337  goto done;
338  }
339 
340  LocalDacl = HeapAlloc(GetProcessHeap(), 0, AclSize.AclBytesInUse);
341  if (LocalDacl == NULL)
342  {
343  TRACE("Memory allocation failed\n");
344  ApiStatus = ERROR_NOT_ENOUGH_MEMORY;
345  goto done;
346  }
347 
348  RtlCopyMemory(LocalDacl, SamDacl, AclSize.AclBytesInUse);
349 
350  *Dacl = LocalDacl;
351 
352  ApiStatus = NERR_Success;
353 
354 done:
355  if (SecurityDescriptor != NULL)
357 
358  TRACE("done (ApiStatus: 0x%08lx)\n", ApiStatus);
359 
360  return ApiStatus;
361 }
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
_In_ USHORT _In_ ULONG _In_ PSOCKADDR _In_ PSOCKADDR _Reserved_ ULONG _In_opt_ PVOID _In_opt_ const WSK_CLIENT_CONNECTION_DISPATCH _In_opt_ PEPROCESS _In_opt_ PETHREAD _In_opt_ PSECURITY_DESCRIPTOR SecurityDescriptor
Definition: wsk.h:182
LONG NTSTATUS
Definition: precomp.h:26
#define ERROR_NOT_ENOUGH_MEMORY
Definition: dderror.h:7
NTSYSAPI NTSTATUS NTAPI RtlGetDaclSecurityDescriptor(_In_ PSECURITY_DESCRIPTOR SecurityDescriptor, _Out_ PBOOLEAN DaclPresent, _Out_ PACL *Dacl, _Out_ PBOOLEAN DaclDefaulted)
#define NERR_Success
Definition: lmerr.h:5
#define NERR_InternalError
Definition: lmerr.h:28
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
DWORD NET_API_STATUS
Definition: ms-dtyp.idl:91
#define TRACE(s)
Definition: solgame.cpp:4
#define GetProcessHeap()
Definition: compat.h:395
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
_Out_writes_bytes_to_opt_ AbsoluteSecurityDescriptorSize PSECURITY_DESCRIPTOR _Inout_ PULONG _Out_writes_bytes_to_opt_ DaclSize PACL Dacl
Definition: rtlfuncs.h:1553
NET_API_STATUS WINAPI NetpNtStatusToApiStatus(_In_ NTSTATUS Status)
Definition: misc.c:140
NTSTATUS NTAPI SamFreeMemory(IN PVOID Buffer)
Definition: samlib.c:947
Status
Definition: gdiplustypes.h:24
NTSYSAPI NTSTATUS WINAPI RtlQueryInformationAcl(PACL, LPVOID, DWORD, ACL_INFORMATION_CLASS)
NTSTATUS NTAPI SamQuerySecurityObject(IN SAM_HANDLE ObjectHandle, IN SECURITY_INFORMATION SecurityInformation, OUT PSECURITY_DESCRIPTOR *SecurityDescriptor)
Definition: samlib.c:1722
#define DACL_SECURITY_INFORMATION
Definition: setypes.h:125

Referenced by BuildUserInfoBuffer(), and SetUserInfo().

◆ GetUserPrivileges()

static NET_API_STATUS GetUserPrivileges ( _In_ SAM_HANDLE  BuiltinDomainHandle,
_In_ SAM_HANDLE  UserHandle,
_In_ PSID  AccountDomainSid,
_In_ ULONG  RelativeId,
_Out_ PDWORD  Priv,
_Out_ PDWORD  AuthFlags 
)
static

Definition at line 410 of file user.c.

417 {
418  PGROUP_MEMBERSHIP GroupMembership = NULL;
419  ULONG GroupCount, SidCount, AliasCount, i;
420  PSID *SidArray = NULL;
421  PULONG AliasArray = NULL;
422  BOOL bAdmin = FALSE, bUser = FALSE;
423  NET_API_STATUS ApiStatus = NERR_Success;
425 
426  FIXME("GetUserPrivileges(%p)\n", UserHandle);
427 
428  /* Get the users group memberships */
429  Status = SamGetGroupsForUser(UserHandle,
430  &GroupMembership,
431  &GroupCount);
432  if (!NT_SUCCESS(Status))
433  {
434  ERR("SamGetGroupsForUser() failed (Status 0x%08lx)\n", Status);
435  ApiStatus = NetpNtStatusToApiStatus(Status);
436  goto done;
437  }
438 
439  /* Allocate the SID array */
440  ApiStatus = NetApiBufferAllocate((GroupCount + 1) * sizeof(PSID),
441  (PVOID*)&SidArray);
442  if (ApiStatus != NERR_Success)
443  {
444  goto done;
445  }
446 
447  /* Add the user to the SID array */
448  SidCount = 0;
450  RelativeId,
451  &SidArray[0]);
452  if (ApiStatus != NERR_Success)
453  {
454  goto done;
455  }
456 
457  SidCount++;
458 
459  /* Add the groups to the SID array */
460  for (i = 0; i < GroupCount; i++)
461  {
463  GroupMembership[i].RelativeId,
464  &SidArray[i + 1]);
465  if (ApiStatus != NERR_Success)
466  {
467  goto done;
468  }
469 
470  SidCount++;
471  }
472 
473  /* Get aliases for the user and his groups */
474  Status = SamGetAliasMembership(BuiltinDomainHandle,
475  SidCount,
476  SidArray,
477  &AliasCount,
478  &AliasArray);
479  if (!NT_SUCCESS(Status))
480  {
481  ERR("SamGetAliasMembership() failed (Status 0x%08lx)\n", Status);
482  ApiStatus = NetpNtStatusToApiStatus(Status);
483  goto done;
484  }
485 
486  *AuthFlags = 0;
487 
488  /* Set the AuthFlags */
489  for (i = 0; i < AliasCount; i++)
490  {
491  switch (AliasArray[i])
492  {
494  bAdmin = TRUE;
495  break;
496 
498  bUser = TRUE;
499  break;
500 
502  *AuthFlags |= AF_OP_ACCOUNTS;
503  break;
504 
506  *AuthFlags |= AF_OP_SERVER;
507  break;
508 
510  *AuthFlags |= AF_OP_PRINT;
511  break;
512  }
513  }
514 
515  /* Set the prvileges */
516  if (bAdmin)
517  {
518  *Priv = USER_PRIV_ADMIN;
519  }
520  else if (bUser)
521  {
522  *Priv = USER_PRIV_USER;
523  }
524  else
525  {
526  *Priv = USER_PRIV_GUEST;
527  }
528 
529 done:
530  if (AliasArray != NULL)
531  SamFreeMemory(AliasArray);
532 
533  if (SidArray != NULL)
534  {
535  for (i = 0; i < SidCount; i++)
536  NetApiBufferFree(SidArray[i]);
537 
538  NetApiBufferFree(SidArray);
539  }
540 
541  if (GroupMembership != NULL)
542  SamFreeMemory(GroupMembership);
543 
544  return ApiStatus;
545 }
#define AF_OP_ACCOUNTS
Definition: lmaccess.h:48
NET_API_STATUS WINAPI NetApiBufferAllocate(DWORD ByteCount, LPVOID *Buffer)
Definition: apibuf.c:28
NTSTATUS NTAPI SamGetGroupsForUser(IN SAM_HANDLE UserHandle, OUT PGROUP_MEMBERSHIP *Groups, OUT PULONG MembershipCount)
Definition: samlib.c:1058
#define TRUE
Definition: types.h:120
#define DOMAIN_ALIAS_RID_ACCOUNT_OPS
Definition: setypes.h:629
LONG NTSTATUS
Definition: precomp.h:26
#define AF_OP_SERVER
Definition: lmaccess.h:47
#define NERR_Success
Definition: lmerr.h:5
#define USER_PRIV_USER
Definition: lmaccess.h:117
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
unsigned int BOOL
Definition: ntddk_ex.h:94
#define FIXME(fmt,...)
Definition: debug.h:110
#define AF_OP_PRINT
Definition: lmaccess.h:45
smooth NULL
Definition: ftsmooth.c:416
DWORD NET_API_STATUS
Definition: ms-dtyp.idl:91
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define DOMAIN_ALIAS_RID_SYSTEM_OPS
Definition: setypes.h:630
NET_API_STATUS WINAPI NetpNtStatusToApiStatus(_In_ NTSTATUS Status)
Definition: misc.c:140
NTSTATUS NTAPI SamFreeMemory(IN PVOID Buffer)
Definition: samlib.c:947
#define USER_PRIV_ADMIN
Definition: lmaccess.h:118
Status
Definition: gdiplustypes.h:24
#define ERR(fmt,...)
Definition: debug.h:109
NET_API_STATUS WINAPI NetApiBufferFree(LPVOID Buffer)
Definition: apibuf.c:43
#define DOMAIN_ALIAS_RID_USERS
Definition: setypes.h:625
unsigned int * PULONG
Definition: retypes.h:1
#define DOMAIN_ALIAS_RID_PRINT_OPS
Definition: setypes.h:631
NTSTATUS NTAPI SamGetAliasMembership(IN SAM_HANDLE DomainHandle, IN ULONG PassedCount, IN PSID *Sids, OUT PULONG MembershipCount, OUT PULONG *Aliases)
Definition: samlib.c:958
unsigned int ULONG
Definition: retypes.h:1
PSID AccountDomainSid
Definition: database.c:22
NET_API_STATUS BuildSidFromSidAndRid(IN PSID SrcSid, IN ULONG RelativeId, OUT PSID *DestSid)
Definition: utils.c:177
#define USER_PRIV_GUEST
Definition: lmaccess.h:116
#define DOMAIN_ALIAS_RID_ADMINS
Definition: setypes.h:624

Referenced by BuildUserInfoBuffer().

◆ LookupEnumContext()

static PENUM_CONTEXT LookupEnumContext ( SAM_ENUMERATE_HANDLE  EnumerationHandle)
static

Definition at line 2724 of file user.c.

2726 {
2727  PENUM_CONTEXT FoundEnumContext = NULL;
2728  PLIST_ENTRY ListEntry;
2729 
2730  /* Acquire the list lock */
2732 
2733  /* Search the list for the handle */
2734  for (ListEntry = g_EnumContextListHead.Flink;
2735  ListEntry != &g_EnumContextListHead;
2736  ListEntry = ListEntry->Flink)
2737  {
2738  PENUM_CONTEXT EnumContext = CONTAINING_RECORD(ListEntry, ENUM_CONTEXT, ListLink);
2739  if (EnumContext->EnumHandle == EnumerationHandle)
2740  {
2741  FoundEnumContext = EnumContext;
2742  break;
2743  }
2744  }
2745 
2746  /* Release the list lock */
2748 
2749  return FoundEnumContext;
2750 }
CRITICAL_SECTION g_EnumContextListLock
Definition: user.c:57
void WINAPI EnterCriticalSection(LPCRITICAL_SECTION)
smooth NULL
Definition: ftsmooth.c:416
ULONG EnumHandle
Definition: user.c:40
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
Definition: typedefs.h:117
LIST_ENTRY g_EnumContextListHead
Definition: user.c:56
void WINAPI LeaveCriticalSection(LPCRITICAL_SECTION)

Referenced by NetUserEnum().

◆ NetUserAdd()

NET_API_STATUS WINAPI NetUserAdd ( LPCWSTR  servername,
DWORD  level,
LPBYTE  bufptr,
LPDWORD  parm_err 
)

Definition at line 2290 of file user.c.

2294 {
2295  UNICODE_STRING ServerName;
2296  UNICODE_STRING UserName;
2297  SAM_HANDLE ServerHandle = NULL;
2298  SAM_HANDLE DomainHandle = NULL;
2299  SAM_HANDLE UserHandle = NULL;
2301  ULONG RelativeId;
2302  NET_API_STATUS ApiStatus = NERR_Success;
2304 
2305  TRACE("(%s, %d, %p, %p)\n", debugstr_w(servername), level, bufptr, parm_err);
2306 
2307  if (parm_err != NULL)
2308  *parm_err = PARM_ERROR_NONE;
2309 
2310  /* Check the info level */
2311  switch (level)
2312  {
2313  case 1:
2314  case 2:
2315  case 3:
2316  case 4:
2317  break;
2318 
2319  default:
2320  return ERROR_INVALID_LEVEL;
2321  }
2322 
2323  if (servername != NULL)
2324  RtlInitUnicodeString(&ServerName, servername);
2325 
2326  /* Connect to the SAM Server */
2327  Status = SamConnect((servername != NULL) ? &ServerName : NULL,
2328  &ServerHandle,
2330  NULL);
2331  if (!NT_SUCCESS(Status))
2332  {
2333  ERR("SamConnect failed (Status %08lx)\n", Status);
2334  ApiStatus = NetpNtStatusToApiStatus(Status);
2335  goto done;
2336  }
2337 
2338  /* Open the Account Domain */
2339  Status = OpenAccountDomain(ServerHandle,
2340  (servername != NULL) ? &ServerName : NULL,
2342  &DomainHandle);
2343  if (!NT_SUCCESS(Status))
2344  {
2345  ERR("OpenAccountDomain failed (Status %08lx)\n", Status);
2346  ApiStatus = NetpNtStatusToApiStatus(Status);
2347  goto done;
2348  }
2349 
2350  /* Initialize the user name string */
2351  RtlInitUnicodeString(&UserName,
2352  ((PUSER_INFO_1)bufptr)->usri1_name);
2353 
2354  /* Create the user account */
2355  Status = SamCreateUser2InDomain(DomainHandle,
2356  &UserName,
2359  &UserHandle,
2360  &GrantedAccess,
2361  &RelativeId);
2362  if (!NT_SUCCESS(Status))
2363  {
2364  ERR("SamCreateUser2InDomain failed (Status %08lx)\n", Status);
2365  ApiStatus = NetpNtStatusToApiStatus(Status);
2366  goto done;
2367  }
2368 
2369  /* Set user information */
2370  ApiStatus = SetUserInfo(UserHandle,
2371  bufptr,
2372  level,
2373  parm_err);
2374  if (ApiStatus != NERR_Success)
2375  {
2376  ERR("SetUserInfo failed (Status %lu)\n", ApiStatus);
2377  goto done;
2378  }
2379 
2380 done:
2381  if (UserHandle != NULL)
2382  {
2383  if (ApiStatus != NERR_Success)
2384  SamDeleteUser(UserHandle);
2385  else
2386  SamCloseHandle(UserHandle);
2387  }
2388 
2389  if (DomainHandle != NULL)
2390  SamCloseHandle(DomainHandle);
2391 
2392  if (ServerHandle != NULL)
2393  SamCloseHandle(ServerHandle);
2394 
2395  return ApiStatus;
2396 }
NTSTATUS NTAPI SamCloseHandle(IN SAM_HANDLE SamHandle)
Definition: samlib.c:476
#define SAM_SERVER_CONNECT
Definition: ntsam.h:99
GLint level
Definition: gl.h:1546
static unsigned int bufptr
Definition: tncon.cpp:77
LONG NTSTATUS
Definition: precomp.h:26
#define PARM_ERROR_NONE
Definition: lmcons.h:56
NTSTATUS OpenAccountDomain(IN SAM_HANDLE ServerHandle, IN PUNICODE_STRING ServerName, IN ULONG DesiredAccess, OUT PSAM_HANDLE DomainHandle)
Definition: utils.c:113
#define NERR_Success
Definition: lmerr.h:5
static NET_API_STATUS SetUserInfo(SAM_HANDLE UserHandle, LPBYTE UserInfo, DWORD Level, PDWORD parm_err)
Definition: user.c:1415
NTSTATUS NTAPI SamCreateUser2InDomain(IN SAM_HANDLE DomainHandle, IN PUNICODE_STRING AccountName, IN ULONG AccountType, IN ACCESS_MASK DesiredAccess, OUT PSAM_HANDLE UserHandle, OUT PULONG GrantedAccess, OUT PULONG RelativeId)
Definition: samlib.c:594
#define debugstr_w
Definition: kernel32.h:32
smooth NULL
Definition: ftsmooth.c:416
#define SAM_SERVER_LOOKUP_DOMAIN
Definition: ntsam.h:104
DWORD NET_API_STATUS
Definition: ms-dtyp.idl:91
#define TRACE(s)
Definition: solgame.cpp:4
NTSTATUS NTAPI SamDeleteUser(IN SAM_HANDLE UserHandle)
Definition: samlib.c:724
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define DOMAIN_READ_PASSWORD_PARAMETERS
Definition: ntsam.h:33
#define WRITE_DAC
Definition: nt_native.h:59
#define USER_ALL_ACCESS
Definition: ntsam.h:153
#define USER_NORMAL_ACCOUNT
Definition: ntsam.h:171
#define DOMAIN_CREATE_USER
Definition: ntsam.h:37
NET_API_STATUS WINAPI NetpNtStatusToApiStatus(_In_ NTSTATUS Status)
Definition: misc.c:140
Status
Definition: gdiplustypes.h:24
#define ERR(fmt,...)
Definition: debug.h:109
unsigned int ULONG
Definition: retypes.h:1
#define DOMAIN_LOOKUP
Definition: ntsam.h:42
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define ERROR_INVALID_LEVEL
Definition: winerror.h:196
_In_ PSECURITY_SUBJECT_CONTEXT _In_ BOOLEAN _In_ ACCESS_MASK _In_ ACCESS_MASK _Outptr_opt_ PPRIVILEGE_SET _In_ PGENERIC_MAPPING _In_ KPROCESSOR_MODE _Out_ PACCESS_MASK GrantedAccess
Definition: sefuncs.h:13
return STATUS_SUCCESS
Definition: btrfs.c:2725
NTSTATUS NTAPI SamConnect(IN OUT PUNICODE_STRING ServerName OPTIONAL, OUT PSAM_HANDLE ServerHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes)
Definition: samlib.c:498
#define DELETE
Definition: nt_native.h:57

Referenced by cmdComputer(), cmdUser(), and UserNew().

◆ NetUserChangePassword()

NET_API_STATUS WINAPI NetUserChangePassword ( LPCWSTR  domainname,
LPCWSTR  username,
LPCWSTR  oldpassword,
LPCWSTR  newpassword 
)

Definition at line 2416 of file user.c.

2420 {
2421  PMSV1_0_CHANGEPASSWORD_REQUEST RequestBuffer = NULL;
2422  PMSV1_0_CHANGEPASSWORD_RESPONSE ResponseBuffer = NULL;
2423  ULONG RequestBufferSize;
2424  ULONG ResponseBufferSize = 0;
2425  LPWSTR Ptr;
2426  ANSI_STRING PackageName;
2428  HANDLE LsaHandle = NULL;
2429  NET_API_STATUS ApiStatus = NERR_Success;
2432 
2433  TRACE("(%s, %s, ..., ...)\n", debugstr_w(domainname), debugstr_w(username));
2434 
2435  /* FIXME: handle null domain or user name */
2436 
2437  /* Check the parameters */
2438  if ((oldpassword == NULL) ||
2439  (newpassword == NULL))
2440  return ERROR_INVALID_PARAMETER;
2441 
2442  /* Connect to the LSA server */
2444  if (!NT_SUCCESS(Status))
2446 
2447  /* Get the authentication package ID */
2448  RtlInitAnsiString(&PackageName,
2450 
2452  &PackageName,
2454  if (!NT_SUCCESS(Status))
2455  {
2456  ApiStatus = NetpNtStatusToApiStatus(Status);
2457  goto done;
2458  }
2459 
2460  /* Calculate the request buffer size */
2461  RequestBufferSize = sizeof(MSV1_0_CHANGEPASSWORD_REQUEST) +
2462  ((wcslen(domainname) + 1) * sizeof(WCHAR)) +
2463  ((wcslen(username) + 1) * sizeof(WCHAR)) +
2464  ((wcslen(oldpassword) + 1) * sizeof(WCHAR)) +
2465  ((wcslen(newpassword) + 1) * sizeof(WCHAR));
2466 
2467  /* Allocate the request buffer */
2468  ApiStatus = NetApiBufferAllocate(RequestBufferSize,
2469  (PVOID*)&RequestBuffer);
2470  if (ApiStatus != NERR_Success)
2471  goto done;
2472 
2473  /* Initialize the request buffer */
2474  RequestBuffer->MessageType = MsV1_0ChangePassword;
2475  RequestBuffer->Impersonating = TRUE;
2476 
2477  Ptr = (LPWSTR)((ULONG_PTR)RequestBuffer + sizeof(MSV1_0_CHANGEPASSWORD_REQUEST));
2478 
2479  /* Pack the domain name */
2480  RequestBuffer->DomainName.Length = wcslen(domainname) * sizeof(WCHAR);
2481  RequestBuffer->DomainName.MaximumLength = RequestBuffer->DomainName.Length + sizeof(WCHAR);
2482  RequestBuffer->DomainName.Buffer = Ptr;
2483 
2484  RtlCopyMemory(RequestBuffer->DomainName.Buffer,
2485  domainname,
2486  RequestBuffer->DomainName.MaximumLength);
2487 
2488  Ptr = (LPWSTR)((ULONG_PTR)Ptr + RequestBuffer->DomainName.MaximumLength);
2489 
2490  /* Pack the user name */
2491  RequestBuffer->AccountName.Length = wcslen(username) * sizeof(WCHAR);
2492  RequestBuffer->AccountName.MaximumLength = RequestBuffer->AccountName.Length + sizeof(WCHAR);
2493  RequestBuffer->AccountName.Buffer = Ptr;
2494 
2495  RtlCopyMemory(RequestBuffer->AccountName.Buffer,
2496  username,
2497  RequestBuffer->AccountName.MaximumLength);
2498 
2499  Ptr = (LPWSTR)((ULONG_PTR)Ptr + RequestBuffer->AccountName.MaximumLength);
2500 
2501  /* Pack the old password */
2502  RequestBuffer->OldPassword.Length = wcslen(oldpassword) * sizeof(WCHAR);
2503  RequestBuffer->OldPassword.MaximumLength = RequestBuffer->OldPassword.Length + sizeof(WCHAR);
2504  RequestBuffer->OldPassword.Buffer = Ptr;
2505 
2506  RtlCopyMemory(RequestBuffer->OldPassword.Buffer,
2507  oldpassword,
2508  RequestBuffer->OldPassword.MaximumLength);
2509 
2510  Ptr = (LPWSTR)((ULONG_PTR)Ptr + RequestBuffer->OldPassword.MaximumLength);
2511 
2512  /* Pack the new password */
2513  RequestBuffer->NewPassword.Length = wcslen(newpassword) * sizeof(WCHAR);
2514  RequestBuffer->NewPassword.MaximumLength = RequestBuffer->NewPassword.Length + sizeof(WCHAR);
2515  RequestBuffer->NewPassword.Buffer = Ptr;
2516 
2517  RtlCopyMemory(RequestBuffer->NewPassword.Buffer,
2518  newpassword,
2519  RequestBuffer->NewPassword.MaximumLength);
2520 
2521  /* Call the authentication package */
2524  RequestBuffer,
2525  RequestBufferSize,
2526  (PVOID*)&ResponseBuffer,
2527  &ResponseBufferSize,
2528  &ProtocolStatus);
2529  if (!NT_SUCCESS(Status))
2530  {
2531  ApiStatus = NetpNtStatusToApiStatus(Status);
2532  goto done;
2533  }
2534 
2535  if (!NT_SUCCESS(ProtocolStatus))
2536  {
2538  goto done;
2539  }
2540 
2541 done:
2542  if (RequestBuffer != NULL)
2543  NetApiBufferFree(RequestBuffer);
2544 
2545  if (ResponseBuffer != NULL)
2546  LsaFreeReturnBuffer(ResponseBuffer);
2547 
2548  if (LsaHandle != NULL)
2549  NtClose(LsaHandle);
2550 
2551  return ApiStatus;
2552 }
NET_API_STATUS WINAPI NetApiBufferAllocate(DWORD ByteCount, LPVOID *Buffer)
Definition: apibuf.c:28
#define ERROR_INVALID_PARAMETER
Definition: compat.h:91
#define TRUE
Definition: types.h:120
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
#define MSV1_0_PACKAGE_NAME
Definition: ntsecapi.h:42
struct _MSV1_0_CHANGEPASSWORD_REQUEST MSV1_0_CHANGEPASSWORD_REQUEST
USHORT MaximumLength
Definition: env_spec_w32.h:370
_Must_inspect_result_ _In_ PFSRTL_PER_STREAM_CONTEXT Ptr
Definition: fsrtlfuncs.h:898
LONG NTSTATUS
Definition: precomp.h:26
UNICODE_STRING AccountName
Definition: ntsecapi.h:510
#define NERR_Success
Definition: lmerr.h:5
NTSYSAPI VOID NTAPI RtlInitAnsiString(PANSI_STRING DestinationString, PCSZ SourceString)
uint32_t ULONG_PTR
Definition: typedefs.h:63
HANDLE LsaHandle
Definition: logon.c:14
VOID NTAPI ProtocolStatus(NDIS_HANDLE BindingContext, NDIS_STATUS GenerelStatus, PVOID StatusBuffer, UINT StatusBufferSize)
Called by NDIS when the underlying driver has changed state.
Definition: lan.c:461
#define debugstr_w
Definition: kernel32.h:32
smooth NULL
Definition: ftsmooth.c:416
static WCHAR username[]
Definition: url.c:32
DWORD NET_API_STATUS
Definition: ms-dtyp.idl:91
#define TRACE(s)
Definition: solgame.cpp:4
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
UNICODE_STRING NewPassword
Definition: ntsecapi.h:512
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
Definition: obhandle.c:3399
NET_API_STATUS WINAPI NetpNtStatusToApiStatus(_In_ NTSTATUS Status)
Definition: misc.c:140
ULONG AuthenticationPackage
Definition: logon.c:15
Status
Definition: gdiplustypes.h:24
NTSTATUS NTAPI LsaConnectUntrusted(OUT PHANDLE LsaHandle)
Definition: lsalpc.c:111
NTSTATUS NTAPI LsaLookupAuthenticationPackage(HANDLE, PLSA_STRING, PULONG)
NET_API_STATUS WINAPI NetApiBufferFree(LPVOID Buffer)
Definition: apibuf.c:43
MSV1_0_PROTOCOL_MESSAGE_TYPE MessageType
Definition: ntsecapi.h:508
NTSTATUS NTAPI LsaFreeReturnBuffer(PVOID)
UNICODE_STRING OldPassword
Definition: ntsecapi.h:511
unsigned int ULONG
Definition: retypes.h:1
WCHAR * LPWSTR
Definition: xmlstorage.h:184
return STATUS_SUCCESS
Definition: btrfs.c:2725
NTSTATUS NTAPI LsaCallAuthenticationPackage(HANDLE, ULONG, PVOID, ULONG, PVOID *, PULONG, PNTSTATUS)
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)

◆ NetUserDel()

NET_API_STATUS WINAPI NetUserDel ( LPCWSTR  servername,
LPCWSTR  username 
)

Definition at line 2560 of file user.c.

2562 {
2563  UNICODE_STRING ServerName;
2564  UNICODE_STRING UserName;
2565  SAM_HANDLE ServerHandle = NULL;
2566  SAM_HANDLE DomainHandle = NULL;
2567  SAM_HANDLE UserHandle = NULL;
2568  NET_API_STATUS ApiStatus = NERR_Success;
2570 
2571  TRACE("(%s, %s)\n", debugstr_w(servername), debugstr_w(username));
2572 
2573  if (servername != NULL)
2574  RtlInitUnicodeString(&ServerName, servername);
2575 
2576  RtlInitUnicodeString(&UserName, username);
2577 
2578  /* Connect to the SAM Server */
2579  Status = SamConnect((servername != NULL) ? &ServerName : NULL,
2580  &ServerHandle,
2582  NULL);
2583  if (!NT_SUCCESS(Status))
2584  {
2585  ERR("SamConnect failed (Status %08lx)\n", Status);
2586  ApiStatus = NetpNtStatusToApiStatus(Status);
2587  goto done;
2588  }
2589 
2590  /* Open the Builtin Domain */
2591  Status = OpenBuiltinDomain(ServerHandle,
2592  DOMAIN_LOOKUP,
2593  &DomainHandle);
2594  if (!NT_SUCCESS(Status))
2595  {
2596  ERR("OpenBuiltinDomain failed (Status %08lx)\n", Status);
2597  ApiStatus = NetpNtStatusToApiStatus(Status);
2598  goto done;
2599  }
2600 
2601  /* Open the user account in the builtin domain */
2602  ApiStatus = OpenUserByName(DomainHandle,
2603  &UserName,
2604  DELETE,
2605  &UserHandle);
2606  if (ApiStatus != NERR_Success && ApiStatus != ERROR_NONE_MAPPED)
2607  {
2608  TRACE("OpenUserByName failed (ApiStatus %lu)\n", ApiStatus);
2609  goto done;
2610  }
2611 
2612  if (UserHandle == NULL)
2613  {
2614  if (DomainHandle != NULL)
2615  {
2616  SamCloseHandle(DomainHandle);
2617  DomainHandle = NULL;
2618  }
2619 
2620  /* Open the Acount Domain */
2621  Status = OpenAccountDomain(ServerHandle,
2622  (servername != NULL) ? &ServerName : NULL,
2623  DOMAIN_LOOKUP,
2624  &DomainHandle);
2625  if (!NT_SUCCESS(Status))
2626  {
2627  ERR("OpenAccountDomain failed (Status %08lx)\n", Status);
2628  ApiStatus = NetpNtStatusToApiStatus(Status);
2629  goto done;
2630  }
2631 
2632  /* Open the user account in the account domain */
2633  ApiStatus = OpenUserByName(DomainHandle,
2634  &UserName,
2635  DELETE,
2636  &UserHandle);
2637  if (ApiStatus != NERR_Success)
2638  {
2639  ERR("OpenUserByName failed (ApiStatus %lu)\n", ApiStatus);
2640  if (ApiStatus == ERROR_NONE_MAPPED)
2641  ApiStatus = NERR_UserNotFound;
2642  goto done;
2643  }
2644  }
2645 
2646  /* Delete the user */
2647  Status = SamDeleteUser(UserHandle);
2648  if (!NT_SUCCESS(Status))
2649  {
2650  ERR("SamDeleteUser failed (Status %08lx)\n", Status);
2651  ApiStatus = NetpNtStatusToApiStatus(Status);
2652  goto done;
2653  }
2654 
2655  /* A successful delete invalidates the handle */
2656  UserHandle = NULL;
2657 
2658 done:
2659  if (UserHandle != NULL)
2660  SamCloseHandle(UserHandle);
2661 
2662  if (DomainHandle != NULL)
2663  SamCloseHandle(DomainHandle);
2664 
2665  if (ServerHandle != NULL)
2666  SamCloseHandle(ServerHandle);
2667 
2668  return ApiStatus;
2669 }
NTSTATUS NTAPI SamCloseHandle(IN SAM_HANDLE SamHandle)
Definition: samlib.c:476
#define SAM_SERVER_CONNECT
Definition: ntsam.h:99
static NET_API_STATUS OpenUserByName(SAM_HANDLE DomainHandle, PUNICODE_STRING UserName, ULONG DesiredAccess, PSAM_HANDLE UserHandle)
Definition: user.c:2232
#define ERROR_NONE_MAPPED
Definition: winerror.h:814
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS OpenAccountDomain(IN SAM_HANDLE ServerHandle, IN PUNICODE_STRING ServerName, IN ULONG DesiredAccess, OUT PSAM_HANDLE DomainHandle)
Definition: utils.c:113
#define NERR_Success
Definition: lmerr.h:5
#define debugstr_w
Definition: kernel32.h:32
smooth NULL
Definition: ftsmooth.c:416
#define SAM_SERVER_LOOKUP_DOMAIN
Definition: ntsam.h:104
static WCHAR username[]
Definition: url.c:32
DWORD NET_API_STATUS
Definition: ms-dtyp.idl:91
#define TRACE(s)
Definition: solgame.cpp:4
NTSTATUS NTAPI SamDeleteUser(IN SAM_HANDLE UserHandle)
Definition: samlib.c:724
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
NET_API_STATUS WINAPI NetpNtStatusToApiStatus(_In_ NTSTATUS Status)
Definition: misc.c:140
Status
Definition: gdiplustypes.h:24
#define ERR(fmt,...)
Definition: debug.h:109
NTSTATUS OpenBuiltinDomain(IN SAM_HANDLE ServerHandle, IN ULONG DesiredAccess, OUT SAM_HANDLE *DomainHandle)
#define DOMAIN_LOOKUP
Definition: ntsam.h:42
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
return STATUS_SUCCESS
Definition: btrfs.c:2725
NTSTATUS NTAPI SamConnect(IN OUT PUNICODE_STRING ServerName OPTIONAL, OUT PSAM_HANDLE ServerHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes)
Definition: samlib.c:498
#define NERR_UserNotFound
Definition: lmerr.h:88
#define DELETE
Definition: nt_native.h:57

Referenced by cmdComputer(), cmdUser(), and UserDelete().

◆ NetUserEnum()

NET_API_STATUS WINAPI NetUserEnum ( LPCWSTR  servername,
DWORD  level,
DWORD  filter,
LPBYTE bufptr,
DWORD  prefmaxlen,
LPDWORD  entriesread,
LPDWORD  totalentries,
LPDWORD  resume_handle 
)

Definition at line 2757 of file user.c.

2765 {
2766  UNICODE_STRING ServerName;
2768  PENUM_CONTEXT EnumContext = NULL;
2769  LPVOID Buffer = NULL;
2770  ULONG i;
2771  SAM_HANDLE UserHandle = NULL;
2773  NET_API_STATUS ApiStatus = NERR_Success;
2775 
2776  TRACE("(%s %d 0x%d %p %d %p %p %p)\n", debugstr_w(servername), level,
2777  filter, bufptr, prefmaxlen, entriesread, totalentries, resume_handle);
2778 
2779  *entriesread = 0;
2780  *totalentries = 0;
2781  *bufptr = NULL;
2782 
2783  if (servername != NULL)
2784  RtlInitUnicodeString(&ServerName, servername);
2785 
2786  if (resume_handle != NULL && *resume_handle != 0)
2787  {
2788  EnumContext = LookupEnumContext(*resume_handle);
2789  }
2790  else
2791  {
2792  ApiStatus = AllocateEnumContext(&EnumContext);
2793  if (ApiStatus != NERR_Success)
2794  goto done;
2795 
2796  Status = SamConnect((servername != NULL) ? &ServerName : NULL,
2797  &EnumContext->ServerHandle,
2799  NULL);
2800  if (!NT_SUCCESS(Status))
2801  {
2802  ERR("SamConnect failed (Status %08lx)\n", Status);
2803  ApiStatus = NetpNtStatusToApiStatus(Status);
2804  goto done;
2805  }
2806 
2807  /* Get the Account Domain SID */
2808  Status = GetAccountDomainSid((servername != NULL) ? &ServerName : NULL,
2809  &EnumContext->AccountDomainSid);
2810  if (!NT_SUCCESS(Status))
2811  {
2812  ERR("GetAccountDomainSid failed (Status %08lx)\n", Status);
2813  ApiStatus = NetpNtStatusToApiStatus(Status);
2814  goto done;
2815  }
2816 
2817  /* Open the Account Domain */
2818  Status = SamOpenDomain(EnumContext->ServerHandle,
2820  EnumContext->AccountDomainSid,
2821  &EnumContext->AccountDomainHandle);
2822  if (!NT_SUCCESS(Status))
2823  {
2824  ERR("SamOpenDomain failed (Status %08lx)\n", Status);
2825  ApiStatus = NetpNtStatusToApiStatus(Status);
2826  goto done;
2827  }
2828 
2829  /* Get the Builtin Domain SID */
2830  Status = GetBuiltinDomainSid(&EnumContext->BuiltinDomainSid);
2831  if (!NT_SUCCESS(Status))
2832  {
2833  ERR("GetBuiltinDomainSid failed (Status %08lx)\n", Status);
2834  ApiStatus = NetpNtStatusToApiStatus(Status);
2835  goto done;
2836  }
2837 
2839  if ((level == 1) || (level == 2) || (level == 3) || (level == 4) || (level == 11))
2841 
2842  /* Open the Builtin Domain */
2843  Status = SamOpenDomain(EnumContext->ServerHandle,
2844  DesiredAccess,
2845  EnumContext->BuiltinDomainSid,
2846  &EnumContext->BuiltinDomainHandle);
2847  if (!NT_SUCCESS(Status))
2848  {
2849  ERR("SamOpenDomain failed (Status %08lx)\n", Status);
2850  ApiStatus = NetpNtStatusToApiStatus(Status);
2851  goto done;
2852  }
2853  }
2854 
2855 // while (TRUE)
2856 // {
2857  TRACE("EnumContext->Index: %lu\n", EnumContext->Index);
2858  TRACE("EnumContext->Count: %lu\n", EnumContext->Count);
2859 
2860  if (EnumContext->Index >= EnumContext->Count)
2861  {
2862 // if (EnumContext->BuiltinDone != FALSE)
2863 // {
2864 // ApiStatus = NERR_Success;
2865 // goto done;
2866 // }
2867 
2868  TRACE("Calling SamEnumerateUsersInDomain\n");
2869  Status = SamEnumerateUsersInDomain(EnumContext->AccountDomainHandle, //BuiltinDomainHandle,
2870  &EnumContext->EnumerationContext,
2871  0,
2872  (PVOID *)&EnumContext->Buffer,
2873  prefmaxlen,
2874  &EnumContext->Count);
2875 
2876  TRACE("SamEnumerateUsersInDomain returned (Status %08lx)\n", Status);
2877  if (!NT_SUCCESS(Status))
2878  {
2879  ERR("SamEnumerateUsersInDomain failed (Status %08lx)\n", Status);
2880  ApiStatus = NetpNtStatusToApiStatus(Status);
2881  goto done;
2882  }
2883 
2884  if (Status == STATUS_MORE_ENTRIES)
2885  {
2886  ApiStatus = NERR_BufTooSmall;
2887  goto done;
2888  }
2889  else
2890  {
2891  EnumContext->BuiltinDone = TRUE;
2892  }
2893  }
2894 
2895  TRACE("EnumContext: %lu\n", EnumContext);
2896  TRACE("EnumContext->Count: %lu\n", EnumContext->Count);
2897  TRACE("EnumContext->Buffer: %p\n", EnumContext->Buffer);
2898 
2899  /* Get a pointer to the current user */
2900  CurrentUser = &EnumContext->Buffer[EnumContext->Index];
2901 
2902  TRACE("RID: %lu\n", CurrentUser->RelativeId);
2903 
2905  if ((level == 1) || (level == 2) || (level == 3) || (level == 4) || (level == 11))
2907 
2908  Status = SamOpenUser(EnumContext->AccountDomainHandle, //BuiltinDomainHandle,
2909  DesiredAccess,
2910  CurrentUser->RelativeId,
2911  &UserHandle);
2912  if (!NT_SUCCESS(Status))
2913  {
2914  ERR("SamOpenUser failed (Status %08lx)\n", Status);
2915  ApiStatus = NetpNtStatusToApiStatus(Status);
2916  goto done;
2917  }
2918 
2919  ApiStatus = BuildUserInfoBuffer(EnumContext->BuiltinDomainHandle,
2920  UserHandle,
2921  EnumContext->AccountDomainSid,
2922  CurrentUser->RelativeId,
2923  level,
2924  &Buffer);
2925  if (ApiStatus != NERR_Success)
2926  {
2927  ERR("BuildUserInfoBuffer failed (ApiStatus %lu)\n", ApiStatus);
2928  goto done;
2929  }
2930 
2931  SamCloseHandle(UserHandle);
2932  UserHandle = NULL;
2933 
2934  EnumContext->Index++;
2935 
2936  (*entriesread)++;
2937 // }
2938 
2939 done:
2940  if (ApiStatus == NERR_Success && EnumContext != NULL && EnumContext->Index < EnumContext->Count)
2941  ApiStatus = ERROR_MORE_DATA;
2942 
2943  if (EnumContext != NULL)
2944  *totalentries = EnumContext->Count;
2945 
2946  if (resume_handle == NULL || ApiStatus != ERROR_MORE_DATA)
2947  {
2948  if (EnumContext != NULL)
2949  {
2950  if (EnumContext->BuiltinDomainHandle != NULL)
2951  SamCloseHandle(EnumContext->BuiltinDomainHandle);
2952 
2953  if (EnumContext->AccountDomainHandle != NULL)
2954  SamCloseHandle(EnumContext->AccountDomainHandle);
2955 
2956  if (EnumContext->BuiltinDomainSid != NULL)
2957  RtlFreeHeap(RtlGetProcessHeap(), 0, EnumContext->BuiltinDomainSid);
2958 
2959  if (EnumContext->AccountDomainSid != NULL)
2960  RtlFreeHeap(RtlGetProcessHeap(), 0, EnumContext->AccountDomainSid);
2961 
2962  if (EnumContext->ServerHandle != NULL)
2963  SamCloseHandle(EnumContext->ServerHandle);
2964 
2965  if (EnumContext->Buffer != NULL)
2966  {
2967  for (i = 0; i < EnumContext->Count; i++)
2968  {
2969  SamFreeMemory(EnumContext->Buffer[i].Name.Buffer);
2970  }
2971 
2972  SamFreeMemory(EnumContext->Buffer);
2973  }
2974 
2975  FreeEnumContext(EnumContext);
2976  EnumContext = NULL;
2977  }
2978  }
2979 
2980  if (UserHandle != NULL)
2981  SamCloseHandle(UserHandle);
2982 
2983  if (resume_handle != NULL)
2984  *resume_handle = EnumContext ? EnumContext->EnumHandle : 0;
2985 
2986  *bufptr = (LPBYTE)Buffer;
2987 
2988  TRACE("return %lu\n", ApiStatus);
2989 
2990  return ApiStatus;
2991 }
NTSTATUS NTAPI SamCloseHandle(IN SAM_HANDLE SamHandle)
Definition: samlib.c:476
#define SAM_SERVER_CONNECT
Definition: ntsam.h:99
GLint level
Definition: gl.h:1546
#define TRUE
Definition: types.h:120
static unsigned int bufptr
Definition: tncon.cpp:77
static NET_API_STATUS BuildUserInfoBuffer(_In_ SAM_HANDLE BuiltinDomainHandle, _In_ SAM_HANDLE UserHandle, _In_ PSID AccountDomainSid, _In_ ULONG RelativeId, _In_ DWORD level, _Out_ LPVOID *Buffer)
Definition: user.c:550
#define DOMAIN_GET_ALIAS_MEMBERSHIP
Definition: ntsam.h:40
SAM_HANDLE BuiltinDomainHandle
Definition: local_group.c:36
NTSTATUS NTAPI SamOpenDomain(IN SAM_HANDLE ServerHandle, IN ACCESS_MASK DesiredAccess, IN PSID DomainId, OUT PSAM_HANDLE DomainHandle)
Definition: samlib.c:1441
LONG NTSTATUS
Definition: precomp.h:26
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:603
UNICODE_STRING Name
Definition: ntsam.h:268
PSAM_RID_ENUMERATION Buffer
Definition: local_group.c:40
BOOLEAN BuiltinDone
Definition: user.c:52
NTSTATUS NTAPI SamEnumerateUsersInDomain(IN SAM_HANDLE DomainHandle, IN OUT PSAM_ENUMERATE_HANDLE EnumerationContext, IN ULONG UserAccountControl, OUT PVOID *Buffer, IN ULONG PreferedMaximumLength, OUT PULONG CountReturned)
Definition: samlib.c:897
static PENUM_CONTEXT LookupEnumContext(SAM_ENUMERATE_HANDLE EnumerationHandle)
Definition: user.c:2724
#define NERR_Success
Definition: lmerr.h:5
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
static NTSTATUS GetAccountDomainSid(PRPC_SID *Sid)
Definition: msv1_0.c:25
unsigned char * LPBYTE
Definition: typedefs.h:52
#define USER_READ_GENERAL
Definition: ntsam.h:126
#define debugstr_w
Definition: kernel32.h:32
PSID AccountDomainSid
Definition: user.c:46
smooth NULL
Definition: ftsmooth.c:416
#define SAM_SERVER_LOOKUP_DOMAIN
Definition: ntsam.h:104
SAM_ENUMERATE_HANDLE EnumerationContext
Definition: local_group.c:39
Definition: bufpool.h:45
static VOID FreeEnumContext(PENUM_CONTEXT EnumContext)
Definition: user.c:2709
#define USER_LIST_GROUPS
Definition: ntsam.h:134
ULONG EnumHandle
Definition: user.c:40
DWORD NET_API_STATUS
Definition: ms-dtyp.idl:91
#define TRACE(s)
Definition: solgame.cpp:4
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define USER_READ_ACCOUNT
Definition: ntsam.h:130
SAM_HANDLE AccountDomainHandle
Definition: local_group.c:37
PSID BuiltinDomainSid
Definition: user.c:45
static NET_API_STATUS AllocateEnumContext(PENUM_CONTEXT *AllocatedEnumContext)
Definition: user.c:2673
#define READ_CONTROL
Definition: nt_native.h:58
NET_API_STATUS WINAPI NetpNtStatusToApiStatus(_In_ NTSTATUS Status)
Definition: misc.c:140
NTSTATUS NTAPI SamFreeMemory(IN PVOID Buffer)
Definition: samlib.c:947
#define STATUS_MORE_ENTRIES
Definition: udferr_usr.h:124
#define ERROR_MORE_DATA
Definition: dderror.h:13
NTSTATUS GetBuiltinDomainSid(OUT PSID *BuiltinDomainSid)
Definition: utils.c:76
Status
Definition: gdiplustypes.h:24
#define ERR(fmt,...)
Definition: debug.h:109
_In_ PIO_STACK_LOCATION _Inout_ PFILE_OBJECT _Inout_ PVCB _Outptr_result_maybenull_ PDCB _In_ PDCB _In_ PDIRENT _In_ ULONG _In_ ULONG _In_ PUNICODE_STRING _In_ PACCESS_MASK DesiredAccess
Definition: create.c:4157
ULONG Count
Definition: user.c:50
#define USER_READ_PREFERENCES
Definition: ntsam.h:127
#define DOMAIN_LIST_ACCOUNTS
Definition: ntsam.h:41
unsigned int ULONG
Definition: retypes.h:1
#define DOMAIN_LOOKUP
Definition: ntsam.h:42
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
static PVOID CurrentUser
return STATUS_SUCCESS
Definition: btrfs.c:2725
SAM_HANDLE ServerHandle
Definition: local_group.c:34
NTSTATUS NTAPI SamConnect(IN OUT PUNICODE_STRING ServerName OPTIONAL, OUT PSAM_HANDLE ServerHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes)
Definition: samlib.c:498
#define USER_READ_LOGON
Definition: ntsam.h:129
GLint GLint GLint GLint GLint GLint GLint GLbitfield GLenum filter
Definition: glext.h:7005
ULONG ACCESS_MASK
Definition: nt_native.h:40
#define NERR_BufTooSmall
Definition: lmerr.h:21
NTSTATUS NTAPI SamOpenUser(IN SAM_HANDLE DomainHandle, IN ACCESS_MASK DesiredAccess, IN ULONG UserId, OUT PSAM_HANDLE UserHandle)
Definition: samlib.c:1499

Referenced by EnumerateUsers(), InitGroupMembersList(), and UpdateUsersList().

◆ NetUserGetGroups()

NET_API_STATUS WINAPI NetUserGetGroups ( LPCWSTR  servername,
LPCWSTR  username,
DWORD  level,
LPBYTE bufptr,
DWORD  prefixmaxlen,
LPDWORD  entriesread,
LPDWORD  totalentries 
)

Definition at line 2999 of file user.c.

3006 {
3007  UNICODE_STRING ServerName;
3008  UNICODE_STRING UserName;
3009  SAM_HANDLE ServerHandle = NULL;
3010  SAM_HANDLE AccountDomainHandle = NULL;
3011  SAM_HANDLE UserHandle = NULL;
3013  PULONG RelativeIds = NULL;
3014  PSID_NAME_USE Use = NULL;
3015  PGROUP_MEMBERSHIP GroupMembership = NULL;
3016  ULONG GroupCount;
3017 
3018  NET_API_STATUS ApiStatus = NERR_Success;
3020 
3021  TRACE("%s %s %d %p %d %p %p stub\n", debugstr_w(servername),
3022  debugstr_w(username), level, bufptr, prefixmaxlen, entriesread,
3023  totalentries);
3024 
3025  if (servername != NULL)
3026  RtlInitUnicodeString(&ServerName, servername);
3027 
3028  RtlInitUnicodeString(&UserName, username);
3029 
3030  /* Connect to the SAM Server */
3031  Status = SamConnect((servername != NULL) ? &ServerName : NULL,
3032  &ServerHandle,
3034  NULL);
3035  if (!NT_SUCCESS(Status))
3036  {
3037  ERR("SamConnect failed (Status %08lx)\n", Status);
3038  ApiStatus = NetpNtStatusToApiStatus(Status);
3039  goto done;
3040  }
3041 
3042  /* Get the Account Domain SID */
3043  Status = GetAccountDomainSid((servername != NULL) ? &ServerName : NULL,
3044  &AccountDomainSid);
3045  if (!NT_SUCCESS(Status))
3046  {
3047  ERR("GetAccountDomainSid failed (Status %08lx)\n", Status);
3048  ApiStatus = NetpNtStatusToApiStatus(Status);
3049  goto done;
3050  }
3051 
3052  /* Open the Account Domain */
3053  Status = SamOpenDomain(ServerHandle,
3056  &AccountDomainHandle);
3057  if (!NT_SUCCESS(Status))
3058  {
3059  ERR("OpenAccountDomain failed (Status %08lx)\n", Status);
3060  ApiStatus = NetpNtStatusToApiStatus(Status);
3061  goto done;
3062  }
3063 
3064  /* Get the RID for the given user name */
3065  Status = SamLookupNamesInDomain(AccountDomainHandle,
3066  1,
3067  &UserName,
3068  &RelativeIds,
3069  &Use);
3070  if (!NT_SUCCESS(Status))
3071  {
3072  ERR("SamLookupNamesInDomain failed (Status %08lx)\n", Status);
3073  if (Status == STATUS_NONE_MAPPED)
3074  ApiStatus = NERR_UserNotFound;
3075  else
3076  ApiStatus = NetpNtStatusToApiStatus(Status);
3077  goto done;
3078  }
3079 
3080  /* Fail, if it is not a user account */
3081  if (Use[0] != SidTypeUser)
3082  {
3083  ERR("Account is not a User!\n");
3084  ApiStatus = NERR_UserNotFound;
3085  goto done;
3086  }
3087 
3088  /* Open the user object */
3089  Status = SamOpenUser(AccountDomainHandle,
3091  RelativeIds[0],
3092  &UserHandle);
3093  if (!NT_SUCCESS(Status))
3094  {
3095  ERR("SamOpenUser failed (Status %08lx)\n", Status);
3096  ApiStatus = NetpNtStatusToApiStatus(Status);
3097  goto done;
3098  }
3099 
3100  /* Get the group memberships of this user */
3101  Status = SamGetGroupsForUser(UserHandle,
3102  &GroupMembership,
3103  &GroupCount);
3104  if (!NT_SUCCESS(Status))
3105  {
3106  ERR("SamGetGroupsForUser failed (Status %08lx)\n", Status);
3107  ApiStatus = NetpNtStatusToApiStatus(Status);
3108  goto done;
3109  }
3110 
3111  /* If there is no group membership, we're done */
3112  if (GroupCount == 0)
3113  {
3114  ApiStatus = NERR_Success;
3115  goto done;
3116  }
3117 
3118 
3119 done:
3120 
3121  if (GroupMembership != NULL)
3122  SamFreeMemory(GroupMembership);
3123 
3124  if (UserHandle != NULL)
3125  SamCloseHandle(UserHandle);
3126 
3127  if (RelativeIds != NULL)
3128  SamFreeMemory(RelativeIds);
3129 
3130  if (Use != NULL)
3131  SamFreeMemory(Use);
3132 
3133  if (AccountDomainSid != NULL)
3134  RtlFreeHeap(RtlGetProcessHeap(), 0, AccountDomainSid);
3135 
3136  if (AccountDomainHandle != NULL)
3137  SamCloseHandle(AccountDomainHandle);
3138 
3139  if (ServerHandle != NULL)
3140  SamCloseHandle(ServerHandle);
3141 
3142  if (ApiStatus != NERR_Success && ApiStatus != ERROR_MORE_DATA)
3143  {
3144  *entriesread = 0;
3145  *totalentries = 0;
3146  }
3147  else
3148  {
3149 // *entriesread = Count;
3150 // *totalentries = Count;
3151  }
3152 
3153 // *bufptr = (LPBYTE)Buffer;
3154 
3155  return ApiStatus;
3156 }
NTSTATUS NTAPI SamCloseHandle(IN SAM_HANDLE SamHandle)
Definition: samlib.c:476
NTSTATUS NTAPI SamGetGroupsForUser(IN SAM_HANDLE UserHandle, OUT PGROUP_MEMBERSHIP *Groups, OUT PULONG MembershipCount)
Definition: samlib.c:1058
#define SAM_SERVER_CONNECT
Definition: ntsam.h:99
GLint level
Definition: gl.h:1546
static unsigned int bufptr
Definition: tncon.cpp:77
#define DOMAIN_GET_ALIAS_MEMBERSHIP
Definition: ntsam.h:40
NTSTATUS NTAPI SamOpenDomain(IN SAM_HANDLE ServerHandle, IN ACCESS_MASK DesiredAccess, IN PSID DomainId, OUT PSAM_HANDLE DomainHandle)
Definition: samlib.c:1441
LONG NTSTATUS
Definition: precomp.h:26
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:603
#define STATUS_NONE_MAPPED
Definition: ntstatus.h:337
#define NERR_Success
Definition: lmerr.h:5
static NTSTATUS GetAccountDomainSid(PRPC_SID *Sid)
Definition: msv1_0.c:25
#define debugstr_w
Definition: kernel32.h:32
NTSTATUS NTAPI SamLookupNamesInDomain(IN SAM_HANDLE DomainHandle, IN ULONG Count, IN PUNICODE_STRING Names, OUT PULONG *RelativeIds, OUT PSID_NAME_USE *Use)
Definition: samlib.c:1335
smooth NULL
Definition: ftsmooth.c:416
#define SAM_SERVER_LOOKUP_DOMAIN
Definition: ntsam.h:104
#define USER_LIST_GROUPS
Definition: ntsam.h:134
static WCHAR username[]
Definition: url.c:32
DWORD NET_API_STATUS
Definition: ms-dtyp.idl:91
enum _SID_NAME_USE * PSID_NAME_USE
#define TRACE(s)
Definition: solgame.cpp:4
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
NET_API_STATUS WINAPI NetpNtStatusToApiStatus(_In_ NTSTATUS Status)
Definition: misc.c:140
NTSTATUS NTAPI SamFreeMemory(IN PVOID Buffer)
Definition: samlib.c:947
#define ERROR_MORE_DATA
Definition: dderror.h:13
Status
Definition: gdiplustypes.h:24
#define ERR(fmt,...)
Definition: debug.h:109
unsigned int * PULONG
Definition: retypes.h:1
unsigned int ULONG
Definition: retypes.h:1
#define DOMAIN_LOOKUP
Definition: ntsam.h:42
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
PSID AccountDomainSid
Definition: database.c:22
return STATUS_SUCCESS
Definition: btrfs.c:2725
NTSTATUS NTAPI SamConnect(IN OUT PUNICODE_STRING ServerName OPTIONAL, OUT PSAM_HANDLE ServerHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes)
Definition: samlib.c:498
#define NERR_UserNotFound
Definition: lmerr.h:88
NTSTATUS NTAPI SamOpenUser(IN SAM_HANDLE DomainHandle, IN ACCESS_MASK DesiredAccess, IN ULONG UserId, OUT PSAM_HANDLE UserHandle)
Definition: samlib.c:1499

Referenced by DisplayUser().

◆ NetUserGetInfo()

NET_API_STATUS WINAPI NetUserGetInfo ( LPCWSTR  servername,
LPCWSTR  username,
DWORD  level,
LPBYTE bufptr 
)

Definition at line 3164 of file user.c.

3168 {
3169  UNICODE_STRING ServerName;
3170  UNICODE_STRING UserName;
3171  SAM_HANDLE ServerHandle = NULL;
3172  SAM_HANDLE AccountDomainHandle = NULL;
3173  SAM_HANDLE BuiltinDomainHandle = NULL;
3174  SAM_HANDLE UserHandle = NULL;
3175  PULONG RelativeIds = NULL;
3176  PSID_NAME_USE Use = NULL;
3177  LPVOID Buffer = NULL;
3181  NET_API_STATUS ApiStatus = NERR_Success;
3183 
3184  TRACE("(%s, %s, %d, %p)\n", debugstr_w(servername),
3186 
3187  if (servername != NULL)
3188  RtlInitUnicodeString(&ServerName, servername);
3189 
3190  RtlInitUnicodeString(&UserName, username);
3191 
3192  /* Connect to the SAM Server */
3193  Status = SamConnect((servername != NULL) ? &ServerName : NULL,
3194  &ServerHandle,
3196  NULL);
3197  if (!NT_SUCCESS(Status))
3198  {
3199  ERR("SamConnect failed (Status %08lx)\n", Status);
3200  ApiStatus = NetpNtStatusToApiStatus(Status);
3201  goto done;
3202  }
3203 
3204  /* Get the Builtin Domain SID */
3206  if (!NT_SUCCESS(Status))
3207  {
3208  ERR("GetBuiltinDomainSid failed (Status %08lx)\n", Status);
3209  ApiStatus = NetpNtStatusToApiStatus(Status);
3210  goto done;
3211  }
3212 
3214  if ((level == 1) || (level == 2) || (level == 3) || (level == 4) || (level == 11))
3216 
3217  /* Open the Builtin Domain */
3218  Status = SamOpenDomain(ServerHandle,
3219  DesiredAccess,
3221  &BuiltinDomainHandle);
3222  if (!NT_SUCCESS(Status))
3223  {
3224  ERR("SamOpenDomain failed (Status %08lx)\n", Status);
3225  ApiStatus = NetpNtStatusToApiStatus(Status);
3226  goto done;
3227  }
3228 
3229  /* Get the Account Domain SID */
3230  Status = GetAccountDomainSid((servername != NULL) ? &ServerName : NULL,
3231  &AccountDomainSid);
3232  if (!NT_SUCCESS(Status))
3233  {
3234  ERR("GetAccountDomainSid failed (Status %08lx)\n", Status);
3235  ApiStatus = NetpNtStatusToApiStatus(Status);
3236  goto done;
3237  }
3238 
3239  /* Open the Account Domain */
3240  Status = SamOpenDomain(ServerHandle,
3243  &AccountDomainHandle);
3244  if (!NT_SUCCESS(Status))
3245  {
3246  ERR("OpenAccountDomain failed (Status %08lx)\n", Status);
3247  ApiStatus = NetpNtStatusToApiStatus(Status);
3248  goto done;
3249  }
3250 
3251  /* Get the RID for the given user name */
3252  Status = SamLookupNamesInDomain(AccountDomainHandle,
3253  1,
3254  &UserName,
3255  &RelativeIds,
3256  &Use);
3257  if (!NT_SUCCESS(Status))
3258  {
3259  ERR("SamOpenDomain failed (Status %08lx)\n", Status);
3260  if (Status == STATUS_NONE_MAPPED)
3261  ApiStatus = NERR_UserNotFound;
3262  else
3263  ApiStatus = NetpNtStatusToApiStatus(Status);
3264  goto done;
3265  }
3266 
3267  /* Check if the account is a user account */
3268  if (Use[0] != SidTypeUser)
3269  {
3270  ERR("No user found!\n");
3271  ApiStatus = NERR_UserNotFound;
3272  goto done;
3273  }
3274 
3275  TRACE("RID: %lu\n", RelativeIds[0]);
3276 
3278  if ((level == 1) || (level == 2) || (level == 3) || (level == 4) || (level == 11))
3280 
3281  /* Open the user object */
3282  Status = SamOpenUser(AccountDomainHandle,
3283  DesiredAccess,
3284  RelativeIds[0],
3285  &UserHandle);
3286  if (!NT_SUCCESS(Status))
3287  {
3288  ERR("SamOpenUser failed (Status %08lx)\n", Status);
3289  ApiStatus = NetpNtStatusToApiStatus(Status);
3290  goto done;
3291  }
3292 
3293  ApiStatus = BuildUserInfoBuffer(BuiltinDomainHandle,
3294  UserHandle,
3296  RelativeIds[0],
3297  level,
3298  &Buffer);
3299  if (ApiStatus != NERR_Success)
3300  {
3301  ERR("BuildUserInfoBuffer failed (ApiStatus %08lu)\n", ApiStatus);
3302  goto done;
3303  }
3304 
3305 done:
3306  if (UserHandle != NULL)
3307  SamCloseHandle(UserHandle);
3308 
3309  if (RelativeIds != NULL)
3310  SamFreeMemory(RelativeIds);
3311 
3312  if (Use != NULL)
3313  SamFreeMemory(Use);
3314 
3315  if (AccountDomainHandle != NULL)
3316  SamCloseHandle(AccountDomainHandle);
3317 
3318  if (AccountDomainSid != NULL)
3319  RtlFreeHeap(RtlGetProcessHeap(), 0, AccountDomainSid);
3320 
3321  if (BuiltinDomainHandle != NULL)
3322  SamCloseHandle(BuiltinDomainHandle);
3323 
3324  if (BuiltinDomainSid != NULL)
3325  RtlFreeHeap(RtlGetProcessHeap(), 0, BuiltinDomainSid);
3326 
3327  if (ServerHandle != NULL)
3328  SamCloseHandle(ServerHandle);
3329 
3330  *bufptr = (LPBYTE)Buffer;
3331 
3332  return ApiStatus;
3333 }
NTSTATUS NTAPI SamCloseHandle(IN SAM_HANDLE SamHandle)
Definition: samlib.c:476
#define SAM_SERVER_CONNECT
Definition: ntsam.h:99
GLint level
Definition: gl.h:1546
static unsigned int bufptr
Definition: tncon.cpp:77
static NET_API_STATUS BuildUserInfoBuffer(_In_ SAM_HANDLE BuiltinDomainHandle, _In_ SAM_HANDLE UserHandle, _In_ PSID AccountDomainSid, _In_ ULONG RelativeId, _In_ DWORD level, _Out_ LPVOID *Buffer)
Definition: user.c:550
#define DOMAIN_GET_ALIAS_MEMBERSHIP
Definition: ntsam.h:40
NTSTATUS NTAPI SamOpenDomain(IN SAM_HANDLE ServerHandle, IN ACCESS_MASK DesiredAccess, IN PSID DomainId, OUT PSAM_HANDLE DomainHandle)
Definition: samlib.c:1441
LONG NTSTATUS
Definition: precomp.h:26
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:603
PSID BuiltinDomainSid
Definition: globals.c:16
#define STATUS_NONE_MAPPED
Definition: ntstatus.h:337
#define NERR_Success
Definition: lmerr.h:5
static NTSTATUS GetAccountDomainSid(PRPC_SID *Sid)
Definition: msv1_0.c:25
unsigned char * LPBYTE
Definition: typedefs.h:52
#define USER_READ_GENERAL
Definition: ntsam.h:126
#define debugstr_w
Definition: kernel32.h:32
NTSTATUS NTAPI SamLookupNamesInDomain(IN SAM_HANDLE DomainHandle, IN ULONG Count, IN PUNICODE_STRING Names, OUT PULONG *RelativeIds, OUT PSID_NAME_USE *Use)
Definition: samlib.c:1335
smooth NULL
Definition: ftsmooth.c:416
#define SAM_SERVER_LOOKUP_DOMAIN
Definition: ntsam.h:104
Definition: bufpool.h:45
#define USER_LIST_GROUPS
Definition: ntsam.h:134
static WCHAR username[]
Definition: url.c:32
DWORD NET_API_STATUS
Definition: ms-dtyp.idl:91
enum _SID_NAME_USE * PSID_NAME_USE
#define TRACE(s)
Definition: solgame.cpp:4
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define USER_READ_ACCOUNT
Definition: ntsam.h:130
#define READ_CONTROL
Definition: nt_native.h:58
NET_API_STATUS WINAPI NetpNtStatusToApiStatus(_In_ NTSTATUS Status)
Definition: misc.c:140
NTSTATUS NTAPI SamFreeMemory(IN PVOID Buffer)
Definition: samlib.c:947
NTSTATUS GetBuiltinDomainSid(OUT PSID *BuiltinDomainSid)
Definition: utils.c:76
Status
Definition: gdiplustypes.h:24
#define ERR(fmt,...)
Definition: debug.h:109
_In_ PIO_STACK_LOCATION _Inout_ PFILE_OBJECT _Inout_ PVCB _Outptr_result_maybenull_ PDCB _In_ PDCB _In_ PDIRENT _In_ ULONG _In_ ULONG _In_ PUNICODE_STRING _In_ PACCESS_MASK DesiredAccess
Definition: create.c:4157
unsigned int * PULONG
Definition: retypes.h:1
#define USER_READ_PREFERENCES
Definition: ntsam.h:127
#define DOMAIN_LIST_ACCOUNTS
Definition: ntsam.h:41
#define DOMAIN_LOOKUP
Definition: ntsam.h:42
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
PSID AccountDomainSid
Definition: database.c:22
return STATUS_SUCCESS
Definition: btrfs.c:2725
NTSTATUS NTAPI SamConnect(IN OUT PUNICODE_STRING ServerName OPTIONAL, OUT PSAM_HANDLE ServerHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes)
Definition: samlib.c:498
#define USER_READ_LOGON
Definition: ntsam.h:129
ULONG ACCESS_MASK
Definition: nt_native.h:40
#define NERR_UserNotFound
Definition: lmerr.h:88
NTSTATUS NTAPI SamOpenUser(IN SAM_HANDLE DomainHandle, IN ACCESS_MASK DesiredAccess, IN ULONG UserId, OUT PSAM_HANDLE UserHandle)
Definition: samlib.c:1499

Referenced by cmdUser(), DisplayUser(), GetUserGeneralData(), GetUserProfileData(), SetUserGeneralData(), SetUserProfileData(), and UpdateUserProperties().

◆ NetUserGetLocalGroups()

NET_API_STATUS WINAPI NetUserGetLocalGroups ( LPCWSTR  servername,
LPCWSTR  username,
DWORD  level,
DWORD  flags,
LPBYTE bufptr,
DWORD  prefmaxlen,
LPDWORD  entriesread,
LPDWORD  totalentries 
)

Definition at line 3341 of file user.c.

3349 {
3350  UNICODE_STRING ServerName;
3351  UNICODE_STRING UserName;
3352  SAM_HANDLE ServerHandle = NULL;
3353  SAM_HANDLE BuiltinDomainHandle = NULL;
3354  SAM_HANDLE AccountDomainHandle = NULL;
3356  PSID UserSid = NULL;
3357  PULONG RelativeIds = NULL;
3358  PSID_NAME_USE Use = NULL;
3359  ULONG BuiltinMemberCount = 0;
3360  ULONG AccountMemberCount = 0;
3361  PULONG BuiltinAliases = NULL;
3362  PULONG AccountAliases = NULL;
3363  PUNICODE_STRING BuiltinNames = NULL;
3364  PUNICODE_STRING AccountNames = NULL;
3366  ULONG Size;
3367  ULONG Count = 0;
3368  ULONG Index;
3369  ULONG i;
3370  LPWSTR StrPtr;
3371  NET_API_STATUS ApiStatus = NERR_Success;
3373 
3374  TRACE("(%s, %s, %d, %08x, %p %d, %p, %p) stub!\n",
3375  debugstr_w(servername), debugstr_w(username), level, flags, bufptr,
3376  prefmaxlen, entriesread, totalentries);
3377 
3378  if (level != 0)
3379  return ERROR_INVALID_LEVEL;
3380 
3381  if (flags & ~LG_INCLUDE_INDIRECT)
3382  return ERROR_INVALID_PARAMETER;
3383 
3384  if (flags & LG_INCLUDE_INDIRECT)
3385  {
3386  WARN("The flag LG_INCLUDE_INDIRECT is not supported yet!\n");
3387  }
3388 
3389  if (servername != NULL)
3390  RtlInitUnicodeString(&ServerName, servername);
3391 
3392  RtlInitUnicodeString(&UserName, username);
3393 
3394  /* Connect to the SAM Server */
3395  Status = SamConnect((servername != NULL) ? &ServerName : NULL,
3396  &ServerHandle,
3398  NULL);
3399  if (!NT_SUCCESS(Status))
3400  {
3401  ERR("SamConnect failed (Status %08lx)\n", Status);
3402  ApiStatus = NetpNtStatusToApiStatus(Status);
3403  goto done;
3404  }
3405 
3406  /* Open the Builtin Domain */
3407  Status = OpenBuiltinDomain(ServerHandle,
3409  &BuiltinDomainHandle);
3410  if (!NT_SUCCESS(Status))
3411  {
3412  ERR("OpenBuiltinDomain failed (Status %08lx)\n", Status);
3413  ApiStatus = NetpNtStatusToApiStatus(Status);
3414  goto done;
3415  }
3416 
3417  /* Get the Account Domain SID */
3418  Status = GetAccountDomainSid((servername != NULL) ? &ServerName : NULL,
3419  &AccountDomainSid);
3420  if (!NT_SUCCESS(Status))
3421  {
3422  ERR("GetAccountDomainSid failed (Status %08lx)\n", Status);
3423  ApiStatus = NetpNtStatusToApiStatus(Status);
3424  goto done;
3425  }
3426 
3427  /* Open the Account Domain */
3428  Status = SamOpenDomain(ServerHandle,
3431  &AccountDomainHandle);
3432  if (!NT_SUCCESS(Status))
3433  {
3434  ERR("OpenAccountDomain failed (Status %08lx)\n", Status);
3435  ApiStatus = NetpNtStatusToApiStatus(Status);
3436  goto done;
3437  }
3438 
3439  /* Get the RID for the given user name */
3440  Status = SamLookupNamesInDomain(AccountDomainHandle,
3441  1,
3442  &UserName,
3443  &RelativeIds,
3444  &Use);
3445  if (!NT_SUCCESS(Status))
3446  {
3447  ERR("SamLookupNamesInDomain failed (Status %08lx)\n", Status);
3448  if (Status == STATUS_NONE_MAPPED)
3449  ApiStatus = NERR_UserNotFound;
3450  else
3451  ApiStatus = NetpNtStatusToApiStatus(Status);
3452  goto done;
3453  }
3454 
3455  /* Fail, if it is not a user account */
3456  if (Use[0] != SidTypeUser)
3457  {
3458  ERR("Account is not a User!\n");
3459  ApiStatus = NERR_UserNotFound;
3460  goto done;
3461  }
3462 
3463  /* Build the User SID from the Account Domain SID and the users RID */
3465  RelativeIds[0],
3466  &UserSid);
3467  if (ApiStatus != NERR_Success)
3468  {
3469  ERR("BuildSidFromSidAndRid failed!\n");
3470  goto done;
3471  }
3472 
3473  /* Get alias memberships in the Builtin Domain */
3474  Status = SamGetAliasMembership(BuiltinDomainHandle,
3475  1,
3476  &UserSid,
3477  &BuiltinMemberCount,
3478  &BuiltinAliases);
3479  if (!NT_SUCCESS(Status))
3480  {
3481  ERR("SamGetAliasMembership failed (Status %08lx)\n", Status);
3482  ApiStatus = NetpNtStatusToApiStatus(Status);
3483  goto done;
3484  }
3485 
3486  if (BuiltinMemberCount > 0)
3487  {
3488  /* Get the Names of the builtin alias members */
3489  Status = SamLookupIdsInDomain(BuiltinDomainHandle,
3490  BuiltinMemberCount,
3491  BuiltinAliases,
3492  &BuiltinNames,
3493  NULL);
3494  if (!NT_SUCCESS(Status))
3495  {
3496  ERR("SamLookupIdsInDomain failed (Status %08lx)\n", Status);
3497  ApiStatus = NetpNtStatusToApiStatus(Status);
3498  goto done;
3499  }
3500  }
3501 
3502  /* Get alias memberships in the Account Domain */
3503  Status = SamGetAliasMembership(AccountDomainHandle,
3504  1,
3505  &UserSid,
3506  &AccountMemberCount,
3507  &AccountAliases);
3508  if (!NT_SUCCESS(Status))
3509  {
3510  ERR("SamGetAliasMembership failed (Status %08lx)\n", Status);
3511  ApiStatus = NetpNtStatusToApiStatus(Status);
3512  goto done;
3513  }
3514 
3515  if (AccountMemberCount > 0)
3516  {
3517  /* Get the Names of the builtin alias members */
3518  Status = SamLookupIdsInDomain(AccountDomainHandle,
3519  AccountMemberCount,
3520  AccountAliases,
3521  &AccountNames,
3522  NULL);
3523  if (!NT_SUCCESS(Status))
3524  {
3525  ERR("SamLookupIdsInDomain failed (Status %08lx)\n", Status);
3526  ApiStatus = NetpNtStatusToApiStatus(Status);
3527  goto done;
3528  }
3529  }
3530 
3531  /* Calculate the required buffer size */
3532  Size = 0;
3533 
3534  for (i = 0; i < BuiltinMemberCount; i++)
3535  {
3536  if (BuiltinNames[i].Length > 0)
3537  {
3538  Size += (sizeof(LOCALGROUP_USERS_INFO_0) + BuiltinNames[i].Length + sizeof(UNICODE_NULL));
3539  Count++;
3540  }
3541  }
3542 
3543  for (i = 0; i < AccountMemberCount; i++)
3544  {
3545  if (AccountNames[i].Length > 0)
3546  {
3547  Size += (sizeof(LOCALGROUP_USERS_INFO_0) + AccountNames[i].Length + sizeof(UNICODE_NULL));
3548  Count++;
3549  }
3550  }
3551 
3552  if (Size == 0)
3553  {
3554  ApiStatus = NERR_Success;
3555  goto done;
3556  }
3557 
3558  /* Allocate buffer */
3559  ApiStatus = NetApiBufferAllocate(Size, (LPVOID*)&Buffer);
3560  if (ApiStatus != NERR_Success)
3561  goto done;
3562 
3564 
3565  StrPtr = (LPWSTR)((INT_PTR)Buffer + Count * sizeof(LOCALGROUP_USERS_INFO_0));
3566 
3567  /* Copy data to the allocated buffer */
3568  Index = 0;
3569  for (i = 0; i < BuiltinMemberCount; i++)
3570  {
3571  if (BuiltinNames[i].Length > 0)
3572  {
3573  CopyMemory(StrPtr,
3574  BuiltinNames[i].Buffer,
3575  BuiltinNames[i].Length);
3576  Buffer[Index].lgrui0_name = StrPtr;
3577 
3578  StrPtr = (LPWSTR)((INT_PTR)StrPtr + BuiltinNames[i].Length + sizeof(UNICODE_NULL));
3579  Index++;
3580  }
3581  }
3582 
3583  for (i = 0; i < AccountMemberCount; i++)
3584  {
3585  if (AccountNames[i].Length > 0)
3586  {
3587  CopyMemory(StrPtr,
3588  AccountNames[i].Buffer,
3589  AccountNames[i].Length);
3590  Buffer[Index].lgrui0_name = StrPtr;
3591 
3592  StrPtr = (LPWSTR)((INT_PTR)StrPtr + AccountNames[i].Length + sizeof(UNICODE_NULL));
3593  Index++;
3594  }
3595  }
3596 
3597 done:
3598  if (AccountNames != NULL)
3599  SamFreeMemory(AccountNames);
3600 
3601  if (BuiltinNames != NULL)
3602  SamFreeMemory(BuiltinNames);
3603 
3604  if (AccountAliases != NULL)
3605  SamFreeMemory(AccountAliases);
3606 
3607  if (BuiltinAliases != NULL)
3608  SamFreeMemory(BuiltinAliases);
3609 
3610  if (RelativeIds != NULL)
3611  SamFreeMemory(RelativeIds);
3612 
3613  if (Use != NULL)
3614  SamFreeMemory(Use);
3615 
3616  if (UserSid != NULL)
3617  NetApiBufferFree(UserSid);
3618 
3619  if (AccountDomainSid != NULL)
3620  RtlFreeHeap(RtlGetProcessHeap(), 0, AccountDomainSid);
3621 
3622  if (AccountDomainHandle != NULL)
3623  SamCloseHandle(AccountDomainHandle);
3624 
3625  if (BuiltinDomainHandle != NULL)
3626  SamCloseHandle(BuiltinDomainHandle);
3627 
3628  if (ServerHandle != NULL)
3629  SamCloseHandle(ServerHandle);
3630 
3631  if (ApiStatus != NERR_Success && ApiStatus != ERROR_MORE_DATA)
3632  {
3633  *entriesread = 0;
3634  *totalentries = 0;
3635  }
3636  else
3637  {
3638  *entriesread = Count;
3639  *totalentries = Count;
3640  }
3641 
3642  *bufptr = (LPBYTE)Buffer;
3643 
3644  return ApiStatus;
3645 }
NET_API_STATUS WINAPI NetApiBufferAllocate(DWORD ByteCount, LPVOID *Buffer)
Definition: apibuf.c:28
#define ERROR_INVALID_PARAMETER
Definition: compat.h:91
NTSTATUS NTAPI SamCloseHandle(IN SAM_HANDLE SamHandle)
Definition: samlib.c:476
#define SAM_SERVER_CONNECT
Definition: ntsam.h:99
GLint level
Definition: gl.h:1546
static unsigned int bufptr
Definition: tncon.cpp:77
#define DOMAIN_GET_ALIAS_MEMBERSHIP
Definition: ntsam.h:40
NTSTATUS NTAPI SamOpenDomain(IN SAM_HANDLE ServerHandle, IN ACCESS_MASK DesiredAccess, IN PSID DomainId, OUT PSAM_HANDLE DomainHandle)
Definition: samlib.c:1441
#define WARN(fmt,...)
Definition: debug.h:111
LONG NTSTATUS
Definition: precomp.h:26
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:603
_Inout_ __drv_aliasesMem PSLIST_ENTRY _Inout_ PSLIST_ENTRY _In_ ULONG Count
Definition: exfuncs.h:1015
#define ZeroMemory
Definition: winbase.h:1635
int32_t INT_PTR
Definition: typedefs.h:62
#define STATUS_NONE_MAPPED
Definition: ntstatus.h:337
#define NERR_Success
Definition: lmerr.h:5
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
static NTSTATUS GetAccountDomainSid(PRPC_SID *Sid)
Definition: msv1_0.c:25
unsigned char * LPBYTE
Definition: typedefs.h:52
#define UNICODE_NULL
#define debugstr_w
Definition: kernel32.h:32
NTSTATUS NTAPI SamLookupIdsInDomain(IN SAM_HANDLE DomainHandle, IN ULONG Count, IN PULONG RelativeIds, OUT PUNICODE_STRING *Names, OUT PSID_NAME_USE *Use OPTIONAL)
Definition: samlib.c:1220
NTSTATUS NTAPI SamLookupNamesInDomain(IN SAM_HANDLE DomainHandle, IN ULONG Count, IN PUNICODE_STRING Names, OUT PULONG *RelativeIds, OUT PSID_NAME_USE *Use)
Definition: samlib.c:1335
smooth NULL
Definition: ftsmooth.c:416
#define SAM_SERVER_LOOKUP_DOMAIN
Definition: ntsam.h:104
#define LG_INCLUDE_INDIRECT
Definition: lmaccess.h:44
Definition: bufpool.h:45
static WCHAR username[]
Definition: url.c:32
DWORD NET_API_STATUS
Definition: ms-dtyp.idl:91
enum _SID_NAME_USE * PSID_NAME_USE
#define TRACE(s)
Definition: solgame.cpp:4
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define CopyMemory
Definition: winbase.h:1633
static const UCHAR Index[8]
Definition: usbohci.c:18
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
GLbitfield flags
Definition: glext.h:7161
NET_API_STATUS WINAPI NetpNtStatusToApiStatus(_In_ NTSTATUS Status)
Definition: misc.c:140
NTSTATUS NTAPI SamFreeMemory(IN PVOID Buffer)
Definition: samlib.c:947
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:359
#define ERROR_MORE_DATA
Definition: dderror.h:13
Status
Definition: gdiplustypes.h:24
#define ERR(fmt,...)
Definition: debug.h:109
NTSTATUS OpenBuiltinDomain(IN SAM_HANDLE ServerHandle, IN ULONG DesiredAccess, OUT SAM_HANDLE *DomainHandle)
NET_API_STATUS WINAPI NetApiBufferFree(LPVOID Buffer)
Definition: apibuf.c:43
unsigned int * PULONG
Definition: retypes.h:1
NTSTATUS NTAPI SamGetAliasMembership(IN SAM_HANDLE DomainHandle, IN ULONG PassedCount, IN PSID *Sids, OUT PULONG MembershipCount, OUT PULONG *Aliases)
Definition: samlib.c:958
unsigned int ULONG
Definition: retypes.h:1
#define DOMAIN_LOOKUP
Definition: ntsam.h:42
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
PSID AccountDomainSid
Definition: database.c:22
NET_API_STATUS BuildSidFromSidAndRid(IN PSID SrcSid, IN ULONG RelativeId, OUT PSID *DestSid)
Definition: utils.c:177
#define ERROR_INVALID_LEVEL
Definition: winerror.h:196
WCHAR * LPWSTR
Definition: xmlstorage.h:184
return STATUS_SUCCESS
Definition: btrfs.c:2725
struct _LOCALGROUP_USERS_INFO_0 LOCALGROUP_USERS_INFO_0
NTSTATUS NTAPI SamConnect(IN OUT PUNICODE_STRING ServerName OPTIONAL, OUT PSAM_HANDLE ServerHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes)
Definition: samlib.c:498
#define NERR_UserNotFound
Definition: lmerr.h:88

Referenced by AddGroupToUser(), DisplayUser(), and GetUserMembershipData().

◆ NetUserModalsGet()

NET_API_STATUS WINAPI NetUserModalsGet ( LPCWSTR  servername,
DWORD  level,
LPBYTE bufptr 
)

Definition at line 3676 of file user.c.

3679 {
3680  UNICODE_STRING ServerName;
3681  SAM_HANDLE ServerHandle = NULL;
3682  SAM_HANDLE DomainHandle = NULL;
3683  PSID DomainSid = NULL;
3684  PDOMAIN_PASSWORD_INFORMATION PasswordInfo = NULL;
3685  PDOMAIN_LOGOFF_INFORMATION LogoffInfo = NULL;
3686  PDOMAIN_SERVER_ROLE_INFORMATION ServerRoleInfo = NULL;
3687  PDOMAIN_REPLICATION_INFORMATION ReplicationInfo = NULL;
3688  PDOMAIN_NAME_INFORMATION NameInfo = NULL;
3689  PDOMAIN_LOCKOUT_INFORMATION LockoutInfo = NULL;
3691  ULONG BufferSize;
3692  PUSER_MODALS_INFO_0 umi0;
3693  PUSER_MODALS_INFO_1 umi1;
3694  PUSER_MODALS_INFO_2 umi2;
3695  PUSER_MODALS_INFO_3 umi3;
3696  NET_API_STATUS ApiStatus = NERR_Success;
3698 
3699  TRACE("(%s %d %p)\n", debugstr_w(servername), level, bufptr);
3700 
3701  *bufptr = NULL;
3702 
3703  if (servername != NULL)
3704  RtlInitUnicodeString(&ServerName, servername);
3705 
3706  /* Connect to the SAM Server */
3707  Status = SamConnect((servername != NULL) ? &ServerName : NULL,
3708  &ServerHandle,