ReactOS  0.4.14-dev-342-gdc047f9
setup.c File Reference
#include "samsrv.h"
#include <ntsecapi.h>
#include "resources.h"
Include dependency graph for setup.c:

Go to the source code of this file.

Macros

#define TICKS_PER_SECOND   10000000LL
 

Functions

static BOOL SampSetupAddMemberToAlias (HKEY hDomainKey, ULONG AliasId, PSID MemberSid)
 
static NTSTATUS SampSetupCreateAliasAccount (HANDLE hDomainKey, LPCWSTR lpAccountName, LPCWSTR lpDescription, ULONG ulRelativeId)
 
static NTSTATUS SampSetupAddMemberToGroup (IN HANDLE hDomainKey, IN ULONG GroupId, IN ULONG MemberId)
 
static NTSTATUS SampSetupCreateGroupAccount (HANDLE hDomainKey, LPCWSTR lpAccountName, LPCWSTR lpComment, ULONG ulRelativeId)
 
static NTSTATUS SampSetupCreateUserAccount (HANDLE hDomainKey, LPCWSTR lpAccountName, LPCWSTR lpComment, PSID lpDomainSid, ULONG ulRelativeId, ULONG UserAccountControl)
 
static NTSTATUS SampSetupCreateDomain (IN HANDLE hServerKey, IN LPCWSTR lpKeyName, IN LPCWSTR lpDomainName, IN PSID lpDomainSid, IN BOOLEAN bBuiltinDomain, OUT HANDLE *lpDomainKey)
 
static NTSTATUS SampSetupCreateServer (IN HANDLE hSamKey, OUT HANDLE *lpServerKey)
 
NTSTATUS SampGetAccountDomainInfo (PPOLICY_ACCOUNT_DOMAIN_INFO *AccountDomainInfo)
 
BOOL SampInitializeSAM (VOID)
 

Variables

SID_IDENTIFIER_AUTHORITY SecurityNtAuthority = {SECURITY_NT_AUTHORITY}
 

Macro Definition Documentation

◆ TICKS_PER_SECOND

#define TICKS_PER_SECOND   10000000LL

Definition at line 18 of file setup.c.

Function Documentation

◆ SampGetAccountDomainInfo()

NTSTATUS SampGetAccountDomainInfo ( PPOLICY_ACCOUNT_DOMAIN_INFO AccountDomainInfo)

Definition at line 856 of file setup.c.

857 {
859  LSA_HANDLE PolicyHandle;
861 
862  TRACE("SampGetAccountDomainInfo\n");
863 
866 
870  &PolicyHandle);
871  if (Status != STATUS_SUCCESS)
872  {
873  ERR("LsaOpenPolicy failed (Status: 0x%08lx)\n", Status);
874  return Status;
875  }
876 
877  Status = LsaQueryInformationPolicy(PolicyHandle,
879  (PVOID *)AccountDomainInfo);
880 
881  LsaClose(PolicyHandle);
882 
883  return Status;
884 }
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:35
NTSTATUS WINAPI LsaQueryInformationPolicy(IN LSA_HANDLE PolicyHandle, IN POLICY_INFORMATION_CLASS InformationClass, OUT PVOID *Buffer)
Definition: lsa.c:1471
#define POLICY_VIEW_LOCAL_INFORMATION
Definition: ntsecapi.h:61
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS WINAPI LsaClose(IN LSA_HANDLE ObjectHandle)
Definition: lsa.c:192
NTSTATUS WINAPI LsaOpenPolicy(IN PLSA_UNICODE_STRING SystemName OPTIONAL, IN PLSA_OBJECT_ATTRIBUTES ObjectAttributes, IN ACCESS_MASK DesiredAccess, OUT PLSA_HANDLE PolicyHandle)
Definition: lsa.c:1181
smooth NULL
Definition: ftsmooth.c:416
#define TRACE(s)
Definition: solgame.cpp:4
struct _LSA_OBJECT_ATTRIBUTES LSA_OBJECT_ATTRIBUTES
Status
Definition: gdiplustypes.h:24
#define ERR(fmt,...)
Definition: debug.h:109
return STATUS_SUCCESS
Definition: btrfs.c:2938
#define memset(x, y, z)
Definition: compat.h:39

Referenced by SampInitializeSAM().

◆ SampInitializeSAM()

BOOL SampInitializeSAM ( VOID  )

Definition at line 888 of file setup.c.

889 {
890  PPOLICY_ACCOUNT_DOMAIN_INFO AccountDomainInfo = NULL;
891  HANDLE hSamKey = NULL;
892  HANDLE hServerKey = NULL;
893  HANDLE hBuiltinDomainKey = NULL;
894  HANDLE hAccountDomainKey = NULL;
895  PSID pBuiltinSid = NULL;
896  PSID pInteractiveSid = NULL;
898  BOOL bResult = TRUE;
899  PSID pSid;
901  WCHAR szComment[256];
902  WCHAR szName[80];
904 
905  TRACE("SampInitializeSAM() called\n");
906 
907  hInstance = GetModuleHandleW(L"samsrv.dll");
908 
909  /* Open the SAM key */
911  L"\\Registry\\Machine\\SAM",
913  &hSamKey);
914  if (!NT_SUCCESS(Status))
915  {
916  ERR("Failed to open the SAM key (Status: 0x%08lx)\n", Status);
917  return FALSE;
918  }
919 
920  /* Create the SAM Server object */
921  Status = SampSetupCreateServer(hSamKey,
922  &hServerKey);
923  if (!NT_SUCCESS(Status))
924  {
925  bResult = FALSE;
926  goto done;
927  }
928 
929  /* Create and initialize the Builtin Domain SID */
930  pBuiltinSid = RtlAllocateHeap(RtlGetProcessHeap(), 0, RtlLengthRequiredSid(1));
931  if (pBuiltinSid == NULL)
932  {
933  ERR("Failed to allocate the Builtin Domain SID\n");
934  bResult = FALSE;
935  goto done;
936  }
937 
938  RtlInitializeSid(pBuiltinSid, &SecurityNtAuthority, 1);
939  *(RtlSubAuthoritySid(pBuiltinSid, 0)) = SECURITY_BUILTIN_DOMAIN_RID;
940 
941  /* Create and initialize the Interactive SID */
942  pInteractiveSid = RtlAllocateHeap(RtlGetProcessHeap(), 0, RtlLengthRequiredSid(1));
943  if (pInteractiveSid == NULL)
944  {
945  ERR("Failed to allocate the Interactive SID\n");
946  bResult = FALSE;
947  goto done;
948  }
949 
950  RtlInitializeSid(pInteractiveSid, &SecurityNtAuthority, 1);
951  *(RtlSubAuthoritySid(pInteractiveSid, 0)) = SECURITY_INTERACTIVE_RID;
952 
953  /* Create and initialize the Authenticated User SID */
954  pAuthenticatedUserSid = RtlAllocateHeap(RtlGetProcessHeap(), 0, RtlLengthRequiredSid(1));
956  {
957  ERR("Failed to allocate the Authenticated User SID\n");
958  bResult = FALSE;
959  goto done;
960  }
961 
964 
965  /* Get account domain information */
966  Status = SampGetAccountDomainInfo(&AccountDomainInfo);
967  if (!NT_SUCCESS(Status))
968  {
969  ERR("SampGetAccountDomainInfo failed (Status %08lx)\n", Status);
970  bResult = FALSE;
971  goto done;
972  }
973 
975 
976  /* Create the Builtin domain */
977  Status = SampSetupCreateDomain(hServerKey,
978  L"Builtin",
979  szName,
980  pBuiltinSid,
981  TRUE,
982  &hBuiltinDomainKey);
983  if (!NT_SUCCESS(Status))
984  {
985  bResult = FALSE;
986  goto done;
987  }
988 
991 
992  SampSetupCreateAliasAccount(hBuiltinDomainKey,
993  szName,
994  szComment,
996 
999 
1000  SampSetupCreateAliasAccount(hBuiltinDomainKey,
1001  szName,
1002  szComment,
1004 
1007 
1008  SampSetupCreateAliasAccount(hBuiltinDomainKey,
1009  szName,
1010  szComment,
1012 
1015 
1016  SampSetupCreateAliasAccount(hBuiltinDomainKey,
1017  szName,
1018  szComment,
1020 
1021  /* Add the Administrator user to the Administrators alias */
1022  pSid = AppendRidToSid(AccountDomainInfo->DomainSid,
1024  if (pSid != NULL)
1025  {
1026  SampSetupAddMemberToAlias(hBuiltinDomainKey,
1028  pSid);
1029 
1030  RtlFreeHeap(RtlGetProcessHeap(), 0, pSid);
1031  }
1032 
1033  /* Add the Guest user to the Guests alias */
1034  pSid = AppendRidToSid(AccountDomainInfo->DomainSid,
1036  if (pSid != NULL)
1037  {
1038  SampSetupAddMemberToAlias(hBuiltinDomainKey,
1040  pSid);
1041 
1042  RtlFreeHeap(RtlGetProcessHeap(), 0, pSid);
1043  }
1044 
1045  /* Add the Interactive SID to the Users alias */
1046  SampSetupAddMemberToAlias(hBuiltinDomainKey,
1048  pInteractiveSid);
1049 
1050  /* Add the Authenticated User SID to the Users alias */
1051  SampSetupAddMemberToAlias(hBuiltinDomainKey,
1054 
1055  /* Create the Account domain */
1056  Status = SampSetupCreateDomain(hServerKey,
1057  L"Account",
1058  L"",
1059  AccountDomainInfo->DomainSid,
1060  FALSE,
1061  &hAccountDomainKey);
1062  if (!NT_SUCCESS(Status))
1063  {
1064  bResult = FALSE;
1065  goto done;
1066  }
1067 
1070 
1071  SampSetupCreateGroupAccount(hAccountDomainKey,
1072  szName,
1073  szComment,
1075 
1078 
1079  SampSetupCreateUserAccount(hAccountDomainKey,
1080  szName,
1081  szComment,
1082  AccountDomainInfo->DomainSid,
1085 
1086  SampSetupAddMemberToGroup(hAccountDomainKey,
1089 
1092 
1093  SampSetupCreateUserAccount(hAccountDomainKey,
1094  szName,
1095  szComment,
1096  AccountDomainInfo->DomainSid,
1099 
1100  SampSetupAddMemberToGroup(hAccountDomainKey,
1103 
1104 done:
1105  if (AccountDomainInfo)
1106  LsaFreeMemory(AccountDomainInfo);
1107 
1109  RtlFreeHeap(RtlGetProcessHeap(), 0, pAuthenticatedUserSid);
1110 
1111  if (pInteractiveSid)
1112  RtlFreeHeap(RtlGetProcessHeap(), 0, pInteractiveSid);
1113 
1114  if (pBuiltinSid)
1115  RtlFreeHeap(RtlGetProcessHeap(), 0, pBuiltinSid);
1116 
1117  SampRegCloseKey(&hAccountDomainKey);
1118  SampRegCloseKey(&hBuiltinDomainKey);
1119  SampRegCloseKey(&hServerKey);
1120  SampRegCloseKey(&hSamKey);
1121 
1122  TRACE("SampInitializeSAM() done\n");
1123 
1124  return bResult;
1125 }
#define IDS_USER_ADMINISTRATOR_NAME
Definition: resources.h:25
#define SECURITY_AUTHENTICATED_USER_RID
Definition: setypes.h:540
#define IDS_GROUP_NONE_NAME
Definition: resources.h:13
#define TRUE
Definition: types.h:120
#define DOMAIN_ALIAS_RID_GUESTS
Definition: setypes.h:626
static NTSTATUS SampSetupCreateDomain(IN HANDLE hServerKey, IN LPCWSTR lpKeyName, IN LPCWSTR lpDomainName, IN PSID lpDomainSid, IN BOOLEAN bBuiltinDomain, OUT HANDLE *lpDomainKey)
Definition: setup.c:618
#define IDS_ALIAS_POWER_USERS_NAME
Definition: resources.h:20
#define IDS_DOMAIN_BUILTIN_NAME
Definition: resources.h:11
#define IDS_ALIAS_ADMINISTRATORS_NAME
Definition: resources.h:16
#define KEY_READ
Definition: nt_native.h:1023
static PSID pAuthenticatedUserSid
Definition: security.c:19
#define IDS_ALIAS_ADMINISTRATORS_COMMENT
Definition: resources.h:17
LONG NTSTATUS
Definition: precomp.h:26
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:606
static PSID AppendRidToSid(PSID SrcSid, ULONG Rid)
Definition: msv1_0.c:245
NTSYSAPI PULONG NTAPI RtlSubAuthoritySid(_In_ PSID Sid, _In_ ULONG SubAuthority)
#define IDS_USER_ADMINISTRATOR_COMMENT
Definition: resources.h:26
#define DOMAIN_ALIAS_RID_POWER_USERS
Definition: setypes.h:627
#define SECURITY_INTERACTIVE_RID
Definition: setypes.h:531
static NTSTATUS SampSetupCreateUserAccount(HANDLE hDomainKey, LPCWSTR lpAccountName, LPCWSTR lpComment, PSID lpDomainSid, ULONG ulRelativeId, ULONG UserAccountControl)
Definition: setup.c:357
static NTSTATUS SampSetupCreateServer(IN HANDLE hSamKey, OUT HANDLE *lpServerKey)
Definition: setup.c:805
#define USER_ACCOUNT_DISABLED
Definition: ntsam.h:167
NTSTATUS SampRegCloseKey(IN OUT PHANDLE KeyHandle)
Definition: registry.c:26
NTSYSAPI NTSTATUS NTAPI RtlInitializeSid(IN OUT PSID Sid, IN PSID_IDENTIFIER_AUTHORITY IdentifierAuthority, IN UCHAR SubAuthorityCount)
HINSTANCE hInstance
Definition: charmap.c:20
unsigned int BOOL
Definition: ntddk_ex.h:94
#define DOMAIN_USER_RID_ADMIN
Definition: setypes.h:603
#define IDS_GROUP_NONE_COMMENT
Definition: resources.h:14
smooth NULL
Definition: ftsmooth.c:416
#define IDS_USER_GUEST_COMMENT
Definition: resources.h:28
#define IDS_ALIAS_USERS_COMMENT
Definition: resources.h:23
NTSTATUS WINAPI LsaFreeMemory(IN PVOID Buffer)
Definition: lsa.c:699
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:588
#define DOMAIN_USER_RID_GUEST
Definition: setypes.h:604
#define TRACE(s)
Definition: solgame.cpp:4
#define SECURITY_BUILTIN_DOMAIN_RID
Definition: setypes.h:553
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define USER_NORMAL_ACCOUNT
Definition: ntsam.h:171
INT SampLoadString(HINSTANCE hInstance, UINT uId, LPWSTR lpBuffer, INT nBufferMax)
Definition: utils.c:17
static BOOL SampSetupAddMemberToAlias(HKEY hDomainKey, ULONG AliasId, PSID MemberSid)
Definition: setup.c:25
static NTSTATUS SampSetupCreateAliasAccount(HANDLE hDomainKey, LPCWSTR lpAccountName, LPCWSTR lpDescription, ULONG ulRelativeId)
Definition: setup.c:91
static const WCHAR L[]
Definition: oid.c:1250
NTSTATUS SampGetAccountDomainInfo(PPOLICY_ACCOUNT_DOMAIN_INFO *AccountDomainInfo)
Definition: setup.c:856
#define IDS_ALIAS_GUESTS_NAME
Definition: resources.h:18
Status
Definition: gdiplustypes.h:24
#define ERR(fmt,...)
Definition: debug.h:109
#define IDS_ALIAS_POWER_USERS_COMMENT
Definition: resources.h:21
NTSTATUS SampRegOpenKey(IN HANDLE ParentKeyHandle, IN LPCWSTR KeyName, IN ACCESS_MASK DesiredAccess, OUT PHANDLE KeyHandle)
Definition: registry.c:158
#define DOMAIN_ALIAS_RID_USERS
Definition: setypes.h:625
#define IDS_USER_GUEST_NAME
Definition: resources.h:27
static NTSTATUS SampSetupAddMemberToGroup(IN HANDLE hDomainKey, IN ULONG GroupId, IN ULONG MemberId)
Definition: setup.c:177
#define DOMAIN_GROUP_RID_USERS
Definition: setypes.h:612
static PSID pSid
Definition: security.c:74
static const WCHAR szName[]
Definition: msipriv.h:1194
HMODULE WINAPI GetModuleHandleW(LPCWSTR lpModuleName)
Definition: loader.c:847
#define IDS_ALIAS_GUESTS_COMMENT
Definition: resources.h:19
static NTSTATUS SampSetupCreateGroupAccount(HANDLE hDomainKey, LPCWSTR lpAccountName, LPCWSTR lpComment, ULONG ulRelativeId)
Definition: setup.c:256
#define DOMAIN_ALIAS_RID_ADMINS
Definition: setypes.h:624
#define KEY_CREATE_SUB_KEY
Definition: nt_native.h:1018
#define USER_DONT_EXPIRE_PASSWORD
Definition: ntsam.h:176
SID_IDENTIFIER_AUTHORITY SecurityNtAuthority
Definition: setup.c:20
#define IDS_ALIAS_USERS_NAME
Definition: resources.h:22
NTSYSAPI ULONG NTAPI RtlLengthRequiredSid(IN ULONG SubAuthorityCount)
Definition: sid.c:54
static const WCHAR szComment[]
Definition: domdoc.c:1167
#define KEY_ENUMERATE_SUB_KEYS
Definition: nt_native.h:1019

Referenced by SampInitializeRegistry().

◆ SampSetupAddMemberToAlias()

static BOOL SampSetupAddMemberToAlias ( HKEY  hDomainKey,
ULONG  AliasId,
PSID  MemberSid 
)
static

Definition at line 25 of file setup.c.

28 {
29  DWORD dwDisposition;
30  LPWSTR MemberSidString = NULL;
31  WCHAR szKeyName[256];
32  HKEY hMembersKey;
33 
34  ConvertSidToStringSidW(MemberSid, &MemberSidString);
35 
36  swprintf(szKeyName, L"Aliases\\%08lX\\Members", AliasId);
37 
38  if (!RegCreateKeyExW(hDomainKey,
39  szKeyName,
40  0,
41  NULL,
44  NULL,
45  &hMembersKey,
46  &dwDisposition))
47  {
48  RegSetValueEx(hMembersKey,
49  MemberSidString,
50  0,
51  REG_BINARY,
52  (LPVOID)MemberSid,
53  RtlLengthSid(MemberSid));
54 
55  RegCloseKey(hMembersKey);
56  }
57 
58  swprintf(szKeyName, L"Aliases\\Members\\%s", MemberSidString);
59 
60  if (!RegCreateKeyExW(hDomainKey,
61  szKeyName,
62  0,
63  NULL,
66  NULL,
67  &hMembersKey,
68  &dwDisposition))
69  {
70  swprintf(szKeyName, L"%08lX", AliasId);
71 
72  RegSetValueEx(hMembersKey,
73  szKeyName,
74  0,
75  REG_BINARY,
76  (LPVOID)MemberSid,
77  RtlLengthSid(MemberSid));
78 
79  RegCloseKey(hMembersKey);
80  }
81 
82  if (MemberSidString != NULL)
83  LocalFree(MemberSidString);
84 
85  return TRUE;
86 }
#define TRUE
Definition: types.h:120
#define REG_BINARY
Definition: nt_native.h:1496
BOOL WINAPI ConvertSidToStringSidW(PSID Sid, LPWSTR *StringSid)
Definition: security.c:3259
LONG WINAPI RegCreateKeyExW(_In_ HKEY hKey, _In_ LPCWSTR lpSubKey, _In_ DWORD Reserved, _In_opt_ LPWSTR lpClass, _In_ DWORD dwOptions, _In_ REGSAM samDesired, _In_opt_ LPSECURITY_ATTRIBUTES lpSecurityAttributes, _Out_ PHKEY phkResult, _Out_opt_ LPDWORD lpdwDisposition)
Definition: reg.c:1091
LONG WINAPI RegCloseKey(HKEY hKey)
Definition: reg.c:423
smooth NULL
Definition: ftsmooth.c:416
NTSYSAPI ULONG NTAPI RtlLengthSid(IN PSID Sid)
Definition: sid.c:150
#define REG_OPTION_NON_VOLATILE
Definition: nt_native.h:1057
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define swprintf(buf, format,...)
Definition: sprintf.c:56
unsigned long DWORD
Definition: ntddk_ex.h:95
static const WCHAR L[]
Definition: oid.c:1250
HLOCAL NTAPI LocalFree(HLOCAL hMem)
Definition: heapmem.c:1577
#define KEY_ALL_ACCESS
Definition: nt_native.h:1041
WCHAR * LPWSTR
Definition: xmlstorage.h:184
#define RegSetValueEx
Definition: winreg.h:533

Referenced by SampInitializeSAM().

◆ SampSetupAddMemberToGroup()

static NTSTATUS SampSetupAddMemberToGroup ( IN HANDLE  hDomainKey,
IN ULONG  GroupId,
IN ULONG  MemberId 
)
static

Definition at line 177 of file setup.c.

180 {
181  WCHAR szKeyName[256];
182  HANDLE hGroupKey = NULL;
183  PULONG MembersBuffer = NULL;
184  ULONG MembersCount = 0;
185  ULONG Length = 0;
186  ULONG i;
188 
189  swprintf(szKeyName, L"Groups\\%08lX", GroupId);
190 
191  Status = SampRegOpenKey(hDomainKey,
192  szKeyName,
194  &hGroupKey);
195  if (!NT_SUCCESS(Status))
196  return Status;
197 
198  Status = SampRegQueryValue(hGroupKey,
199  L"Members",
200  NULL,
201  NULL,
202  &Length);
204  goto done;
205 
206  MembersBuffer = midl_user_allocate(Length + sizeof(ULONG));
207  if (MembersBuffer == NULL)
208  {
210  goto done;
211  }
212 
214  {
215  Status = SampRegQueryValue(hGroupKey,
216  L"Members",
217  NULL,
218  MembersBuffer,
219  &Length);
220  if (!NT_SUCCESS(Status))
221  goto done;
222 
223  MembersCount = Length / sizeof(ULONG);
224  }
225 
226  for (i = 0; i < MembersCount; i++)
227  {
228  if (MembersBuffer[i] == MemberId)
229  {
231  goto done;
232  }
233  }
234 
235  MembersBuffer[MembersCount] = MemberId;
236  Length += sizeof(ULONG);
237 
238  Status = SampRegSetValue(hGroupKey,
239  L"Members",
240  REG_BINARY,
241  MembersBuffer,
242  Length);
243 
244 done:
245  if (MembersBuffer != NULL)
246  midl_user_free(MembersBuffer);
247 
248  SampRegCloseKey(&hGroupKey);
249 
250  return Status;
251 }
#define midl_user_free
Definition: rpc.h:45
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
#define REG_BINARY
Definition: nt_native.h:1496
#define midl_user_allocate
Definition: rpc.h:44
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS SampRegCloseKey(IN OUT PHANDLE KeyHandle)
Definition: registry.c:26
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
smooth NULL
Definition: ftsmooth.c:416
#define STATUS_MEMBER_IN_GROUP
Definition: ntstatus.h:325
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define swprintf(buf, format,...)
Definition: sprintf.c:56
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
NTSTATUS SampRegQueryValue(IN HANDLE KeyHandle, IN LPCWSTR ValueName, OUT PULONG Type OPTIONAL, OUT PVOID Data OPTIONAL, IN OUT PULONG DataLength OPTIONAL)
Definition: registry.c:332
static const WCHAR L[]
Definition: oid.c:1250
Status
Definition: gdiplustypes.h:24
#define STATUS_OBJECT_NAME_NOT_FOUND
Definition: udferr_usr.h:149
NTSTATUS SampRegOpenKey(IN HANDLE ParentKeyHandle, IN LPCWSTR KeyName, IN ACCESS_MASK DesiredAccess, OUT PHANDLE KeyHandle)
Definition: registry.c:158
#define KEY_ALL_ACCESS
Definition: nt_native.h:1041
unsigned int * PULONG
Definition: retypes.h:1
NTSTATUS SampRegSetValue(HANDLE KeyHandle, LPCWSTR ValueName, ULONG Type, LPVOID Data, ULONG DataLength)
Definition: registry.c:402
unsigned int ULONG
Definition: retypes.h:1

Referenced by SampInitializeSAM().

◆ SampSetupCreateAliasAccount()

static NTSTATUS SampSetupCreateAliasAccount ( HANDLE  hDomainKey,
LPCWSTR  lpAccountName,
LPCWSTR  lpDescription,
ULONG  ulRelativeId 
)
static

Definition at line 91 of file setup.c.

95 {
96  WCHAR szAccountKeyName[32];
97  HANDLE hAccountKey = NULL;
98  HANDLE hNamesKey = NULL;
100  ULONG SdSize = 0;
102 
103  swprintf(szAccountKeyName, L"Aliases\\%08lX", ulRelativeId);
104 
105  Status = SampRegCreateKey(hDomainKey,
106  szAccountKeyName,
108  &hAccountKey);
109  if (!NT_SUCCESS(Status))
110  return Status;
111 
112  Status = SampRegSetValue(hAccountKey,
113  L"Name",
114  REG_SZ,
116  (wcslen(lpAccountName) + 1) * sizeof(WCHAR));
117  if (!NT_SUCCESS(Status))
118  goto done;
119 
120  Status = SampRegSetValue(hAccountKey,
121  L"Description",
122  REG_SZ,
123  (LPVOID)lpDescription,
124  (wcslen(lpDescription) + 1) * sizeof(WCHAR));
125  if (!NT_SUCCESS(Status))
126  goto done;
127 
128  /* Create the server SD */
130  &SdSize);
131  if (!NT_SUCCESS(Status))
132  goto done;
133 
134  /* Set SecDesc attribute*/
135  Status = SampRegSetValue(hAccountKey,
136  L"SecDesc",
137  REG_BINARY,
138  Sd,
139  SdSize);
140  if (!NT_SUCCESS(Status))
141  goto done;
142 
143  Status = SampRegOpenKey(hDomainKey,
144  L"Aliases\\Names",
146  &hNamesKey);
147  if (!NT_SUCCESS(Status))
148  goto done;
149 
150  Status = SampRegSetValue(hNamesKey,
152  REG_DWORD,
153  (LPVOID)&ulRelativeId,
154  sizeof(ULONG));
155 
156 done:
157  SampRegCloseKey(&hNamesKey);
158 
159  if (Sd != NULL)
160  RtlFreeHeap(RtlGetProcessHeap(), 0, Sd);
161 
162  if (hAccountKey != NULL)
163  {
164  SampRegCloseKey(&hAccountKey);
165 
166  if (!NT_SUCCESS(Status))
167  SampRegDeleteKey(hDomainKey,
168  szAccountKeyName);
169  }
170 
171  return Status;
172 }
#define REG_BINARY
Definition: nt_native.h:1496
LONG NTSTATUS
Definition: precomp.h:26
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:606
_In_ LPCSTR lpAccountName
Definition: winbase.h:2688
NTSTATUS SampRegCloseKey(IN OUT PHANDLE KeyHandle)
Definition: registry.c:26
smooth NULL
Definition: ftsmooth.c:416
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define swprintf(buf, format,...)
Definition: sprintf.c:56
NTSTATUS SampRegDeleteKey(IN HANDLE ParentKeyHandle, IN LPCWSTR KeyName)
Definition: registry.c:71
static const WCHAR L[]
Definition: oid.c:1250
Status
Definition: gdiplustypes.h:24
NTSTATUS SampRegOpenKey(IN HANDLE ParentKeyHandle, IN LPCWSTR KeyName, IN ACCESS_MASK DesiredAccess, OUT PHANDLE KeyHandle)
Definition: registry.c:158
#define KEY_ALL_ACCESS
Definition: nt_native.h:1041
NTSTATUS SampRegSetValue(HANDLE KeyHandle, LPCWSTR ValueName, ULONG Type, LPVOID Data, ULONG DataLength)
Definition: registry.c:402
unsigned int ULONG
Definition: retypes.h:1
NTSTATUS SampCreateAliasSD(OUT PSECURITY_DESCRIPTOR *AliasSd, OUT PULONG Size)
Definition: security.c:859
NTSTATUS SampRegCreateKey(IN HANDLE ParentKeyHandle, IN LPCWSTR KeyName, IN ACCESS_MASK DesiredAccess, OUT PHANDLE KeyHandle)
Definition: registry.c:42
#define REG_DWORD
Definition: sdbapi.c:596
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
#define REG_SZ
Definition: layer.c:22

Referenced by SampInitializeSAM().

◆ SampSetupCreateDomain()

static NTSTATUS SampSetupCreateDomain ( IN HANDLE  hServerKey,
IN LPCWSTR  lpKeyName,
IN LPCWSTR  lpDomainName,
IN PSID  lpDomainSid,
IN BOOLEAN  bBuiltinDomain,
OUT HANDLE lpDomainKey 
)
static

Definition at line 618 of file setup.c.

624 {
625  SAM_DOMAIN_FIXED_DATA FixedData;
626  WCHAR szDomainKeyName[32];
627  LPWSTR lpEmptyString = L"";
628  HANDLE hDomainKey = NULL;
629  HANDLE hAliasesKey = NULL;
630  HANDLE hGroupsKey = NULL;
631  HANDLE hUsersKey = NULL;
632  HANDLE hNamesKey = NULL;
634  ULONG SdSize = 0;
636 
637  if (lpDomainKey != NULL)
638  *lpDomainKey = NULL;
639 
640  /* Initialize the fixed domain data */
641  memset(&FixedData, 0, sizeof(SAM_DOMAIN_FIXED_DATA));
642  FixedData.Version = 1;
643  NtQuerySystemTime(&FixedData.CreationTime);
644  FixedData.DomainModifiedCount.QuadPart = 0;
645  FixedData.MaxPasswordAge.QuadPart = -(6LL * 7LL * 24LL * 60LL * 60LL * TICKS_PER_SECOND); /* 6 weeks */
646  FixedData.MinPasswordAge.QuadPart = 0; /* right now */
647  FixedData.ForceLogoff.QuadPart = LLONG_MAX; /* very far in the future aka never */
648  FixedData.LockoutDuration.QuadPart = -(30LL * 60LL * TICKS_PER_SECOND); /* 30 minutes */
649  FixedData.LockoutObservationWindow.QuadPart = -(30LL * 60LL * TICKS_PER_SECOND); /* 30 minutes */
651  FixedData.NextRid = 1000;
652  FixedData.PasswordProperties = 0;
653  FixedData.MinPasswordLength = 0;
654  FixedData.PasswordHistoryLength = 0;
655  FixedData.LockoutThreshold = 0;
658  FixedData.UasCompatibilityRequired = TRUE;
659 
660  wcscpy(szDomainKeyName, L"Domains\\");
661  wcscat(szDomainKeyName, lpKeyName);
662 
663  Status = SampRegCreateKey(hServerKey,
664  szDomainKeyName,
666  &hDomainKey);
667  if (!NT_SUCCESS(Status))
668  return Status;
669 
670  /* Set the fixed data value */
671  Status = SampRegSetValue(hDomainKey,
672  L"F",
673  REG_BINARY,
674  (LPVOID)&FixedData,
675  sizeof(SAM_DOMAIN_FIXED_DATA));
676  if (!NT_SUCCESS(Status))
677  goto done;
678 
679  if (lpDomainSid != NULL)
680  {
681  Status = SampRegSetValue(hDomainKey,
682  L"Name",
683  REG_SZ,
684  (LPVOID)lpDomainName,
685  (wcslen(lpDomainName) + 1) * sizeof(WCHAR));
686  if (!NT_SUCCESS(Status))
687  goto done;
688 
689  Status = SampRegSetValue(hDomainKey,
690  L"SID",
691  REG_BINARY,
692  (LPVOID)lpDomainSid,
693  RtlLengthSid(lpDomainSid));
694  if (!NT_SUCCESS(Status))
695  goto done;
696  }
697 
698  Status = SampRegSetValue(hDomainKey,
699  L"OemInformation",
700  REG_SZ,
701  (LPVOID)lpEmptyString,
702  sizeof(WCHAR));
703  if (!NT_SUCCESS(Status))
704  goto done;
705 
706  Status = SampRegSetValue(hDomainKey,
707  L"ReplicaSourceNodeName",
708  REG_SZ,
709  (LPVOID)lpEmptyString,
710  sizeof(WCHAR));
711  if (!NT_SUCCESS(Status))
712  goto done;
713 
714  /* Create the Alias container */
715  Status = SampRegCreateKey(hDomainKey,
716  L"Aliases",
718  &hAliasesKey);
719  if (!NT_SUCCESS(Status))
720  goto done;
721 
722  Status = SampRegCreateKey(hAliasesKey,
723  L"Names",
725  &hNamesKey);
726  if (!NT_SUCCESS(Status))
727  goto done;
728 
729  SampRegCloseKey(&hNamesKey);
730 
731  /* Create the Groups container */
732  Status = SampRegCreateKey(hDomainKey,
733  L"Groups",
735  &hGroupsKey);
736  if (!NT_SUCCESS(Status))
737  goto done;
738 
739  Status = SampRegCreateKey(hGroupsKey,
740  L"Names",
742  &hNamesKey);
743  if (!NT_SUCCESS(Status))
744  goto done;
745 
746  SampRegCloseKey(&hNamesKey);
747 
748  /* Create the Users container */
749  Status = SampRegCreateKey(hDomainKey,
750  L"Users",
752  &hUsersKey);
753  if (!NT_SUCCESS(Status))
754  goto done;
755 
756  Status = SampRegCreateKey(hUsersKey,
757  L"Names",
759  &hNamesKey);
760  if (!NT_SUCCESS(Status))
761  goto done;
762 
763  /* Create the server SD */
764  if (bBuiltinDomain != FALSE)
766  &SdSize);
767  else
769  &SdSize);
770 
771  if (!NT_SUCCESS(Status))
772  goto done;
773 
774  /* Set SecDesc attribute*/
775  Status = SampRegSetValue(hServerKey,
776  L"SecDesc",
777  REG_BINARY,
778  Sd,
779  SdSize);
780  if (!NT_SUCCESS(Status))
781  goto done;
782 
783  SampRegCloseKey(&hNamesKey);
784 
785  if (lpDomainKey != NULL)
786  *lpDomainKey = hDomainKey;
787 
788 done:
789  if (Sd != NULL)
790  RtlFreeHeap(RtlGetProcessHeap(), 0, Sd);
791 
792  SampRegCloseKey(&hAliasesKey);
793  SampRegCloseKey(&hGroupsKey);
794  SampRegCloseKey(&hUsersKey);
795 
796  if (!NT_SUCCESS(Status))
797  SampRegCloseKey(&hDomainKey);
798 
799  return Status;
800 }
NTSTATUS SampCreateAccountDomainSD(OUT PSECURITY_DESCRIPTOR *DomainSd, OUT PULONG Size)
Definition: security.c:545
#define TRUE
Definition: types.h:120
#define LL
Definition: tui.h:85
#define REG_BINARY
Definition: nt_native.h:1496
USHORT MinPasswordLength
Definition: samsrv.h:81
LONG NTSTATUS
Definition: precomp.h:26
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:606
DOMAIN_SERVER_ENABLE_STATE DomainServerState
Definition: samsrv.h:84
LARGE_INTEGER DomainModifiedCount
Definition: samsrv.h:72
LARGE_INTEGER MinPasswordAge
Definition: samsrv.h:74
NTSTATUS SampRegCloseKey(IN OUT PHANDLE KeyHandle)
Definition: registry.c:26
BOOLEAN UasCompatibilityRequired
Definition: samsrv.h:86
#define LLONG_MAX
Definition: limits.h:45
ULONG PasswordProperties
Definition: samsrv.h:80
smooth NULL
Definition: ftsmooth.c:416
LARGE_INTEGER LockoutObservationWindow
Definition: samsrv.h:77
NTSYSAPI ULONG NTAPI RtlLengthSid(IN PSID Sid)
Definition: sid.c:150
LARGE_INTEGER ForceLogoff
Definition: samsrv.h:75
NTSTATUS SampCreateBuiltinDomainSD(OUT PSECURITY_DESCRIPTOR *DomainSd, OUT PULONG Size)
Definition: security.c:283
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
LARGE_INTEGER LockoutDuration
Definition: samsrv.h:76
_CRTIMP wchar_t *__cdecl wcscpy(_Out_writes_z_(_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
static const WCHAR L[]
Definition: oid.c:1250
#define TICKS_PER_SECOND
Definition: setup.c:18
Status
Definition: gdiplustypes.h:24
#define KEY_ALL_ACCESS
Definition: nt_native.h:1041
LARGE_INTEGER MaxPasswordAge
Definition: samsrv.h:73
_CRTIMP wchar_t *__cdecl wcscat(_Inout_updates_z_(_String_length_(_Dest)+_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
NTSTATUS SampRegSetValue(HANDLE KeyHandle, LPCWSTR ValueName, ULONG Type, LPVOID Data, ULONG DataLength)
Definition: registry.c:402
USHORT LockoutThreshold
Definition: samsrv.h:83
LARGE_INTEGER ModifiedCountAtLastPromotion
Definition: samsrv.h:78
DOMAIN_SERVER_ROLE DomainServerRole
Definition: samsrv.h:85
LARGE_INTEGER CreationTime
Definition: samsrv.h:71
unsigned int ULONG
Definition: retypes.h:1
USHORT PasswordHistoryLength
Definition: samsrv.h:82
NTSTATUS NTAPI NtQuerySystemTime(OUT PLARGE_INTEGER SystemTime)
Definition: time.c:417
NTSTATUS SampRegCreateKey(IN HANDLE ParentKeyHandle, IN LPCWSTR KeyName, IN ACCESS_MASK DesiredAccess, OUT PHANDLE KeyHandle)
Definition: registry.c:42
WCHAR * LPWSTR
Definition: xmlstorage.h:184
#define memset(x, y, z)
Definition: compat.h:39
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
LONGLONG QuadPart
Definition: typedefs.h:112
#define REG_SZ
Definition: layer.c:22

Referenced by SampInitializeSAM().

◆ SampSetupCreateGroupAccount()

static NTSTATUS SampSetupCreateGroupAccount ( HANDLE  hDomainKey,
LPCWSTR  lpAccountName,
LPCWSTR  lpComment,
ULONG  ulRelativeId 
)
static

Definition at line 256 of file setup.c.

260 {
261  SAM_GROUP_FIXED_DATA FixedGroupData;
262  WCHAR szAccountKeyName[32];
263  HANDLE hAccountKey = NULL;
264  HANDLE hNamesKey = NULL;
266  ULONG SdSize = 0;
268 
269  /* Initialize fixed group data */
270  FixedGroupData.Version = 1;
271  FixedGroupData.Reserved = 0;
272  FixedGroupData.GroupId = ulRelativeId;
273  FixedGroupData.Attributes = 0;
274 
275  swprintf(szAccountKeyName, L"Groups\\%08lX", ulRelativeId);
276 
277  Status = SampRegCreateKey(hDomainKey,
278  szAccountKeyName,
280  &hAccountKey);
281  if (!NT_SUCCESS(Status))
282  return Status;
283 
284  Status = SampRegSetValue(hAccountKey,
285  L"F",
286  REG_BINARY,
287  (LPVOID)&FixedGroupData,
288  sizeof(SAM_GROUP_FIXED_DATA));
289  if (!NT_SUCCESS(Status))
290  goto done;
291 
292  Status = SampRegSetValue(hAccountKey,
293  L"Name",
294  REG_SZ,
296  (wcslen(lpAccountName) + 1) * sizeof(WCHAR));
297  if (!NT_SUCCESS(Status))
298  goto done;
299 
300  Status = SampRegSetValue(hAccountKey,
301  L"AdminComment",
302  REG_SZ,
303  (LPVOID)lpComment,
304  (wcslen(lpComment) + 1) * sizeof(WCHAR));
305  if (!NT_SUCCESS(Status))
306  goto done;
307 
308  /* Create the security descriptor */
310  &SdSize);
311  if (!NT_SUCCESS(Status))
312  goto done;
313 
314  /* Set the SecDesc attribute*/
315  Status = SampRegSetValue(hAccountKey,
316  L"SecDesc",
317  REG_BINARY,
318  Sd,
319  SdSize);
320  if (!NT_SUCCESS(Status))
321  goto done;
322 
323  Status = SampRegOpenKey(hDomainKey,
324  L"Groups\\Names",
326  &hNamesKey);
327  if (!NT_SUCCESS(Status))
328  goto done;
329 
330  Status = SampRegSetValue(hNamesKey,
332  REG_DWORD,
333  (LPVOID)&ulRelativeId,
334  sizeof(ULONG));
335 
336 done:
337  SampRegCloseKey(&hNamesKey);
338 
339  if (Sd != NULL)
340  RtlFreeHeap(RtlGetProcessHeap(), 0, Sd);
341 
342  if (hAccountKey != NULL)
343  {
344  SampRegCloseKey(&hAccountKey);
345 
346  if (!NT_SUCCESS(Status))
347  SampRegDeleteKey(hDomainKey,
348  szAccountKeyName);
349  }
350 
351  return Status;
352 }
#define REG_BINARY
Definition: nt_native.h:1496
LONG NTSTATUS
Definition: precomp.h:26
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:606
_In_ LPCSTR lpAccountName
Definition: winbase.h:2688
NTSTATUS SampRegCloseKey(IN OUT PHANDLE KeyHandle)
Definition: registry.c:26
smooth NULL
Definition: ftsmooth.c:416
NTSTATUS SampCreateGroupSD(OUT PSECURITY_DESCRIPTOR *GroupSd, OUT PULONG Size)
Definition: security.c:1146
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define swprintf(buf, format,...)
Definition: sprintf.c:56
NTSTATUS SampRegDeleteKey(IN HANDLE ParentKeyHandle, IN LPCWSTR KeyName)
Definition: registry.c:71
static const WCHAR L[]
Definition: oid.c:1250
Status
Definition: gdiplustypes.h:24
NTSTATUS SampRegOpenKey(IN HANDLE ParentKeyHandle, IN LPCWSTR KeyName, IN ACCESS_MASK DesiredAccess, OUT PHANDLE KeyHandle)
Definition: registry.c:158
#define KEY_ALL_ACCESS
Definition: nt_native.h:1041
NTSTATUS SampRegSetValue(HANDLE KeyHandle, LPCWSTR ValueName, ULONG Type, LPVOID Data, ULONG DataLength)
Definition: registry.c:402
unsigned int ULONG
Definition: retypes.h:1
NTSTATUS SampRegCreateKey(IN HANDLE ParentKeyHandle, IN LPCWSTR KeyName, IN ACCESS_MASK DesiredAccess, OUT PHANDLE KeyHandle)
Definition: registry.c:42
#define REG_DWORD
Definition: sdbapi.c:596
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
#define REG_SZ
Definition: layer.c:22

Referenced by SampInitializeSAM().

◆ SampSetupCreateServer()

static NTSTATUS SampSetupCreateServer ( IN HANDLE  hSamKey,
OUT HANDLE lpServerKey 
)
static

Definition at line 805 of file setup.c.

807 {
808  HANDLE hServerKey = NULL;
809  HANDLE hDomainsKey = NULL;
811  ULONG SdSize = 0;
813 
814  Status = SampRegCreateKey(hSamKey,
815  L"SAM",
817  &hServerKey);
818  if (!NT_SUCCESS(Status))
819  return Status;
820 
821  Status = SampRegCreateKey(hServerKey,
822  L"Domains",
824  &hDomainsKey);
825  if (!NT_SUCCESS(Status))
826  goto done;
827 
828  /* Create the server SD */
830  &SdSize);
831  if (!NT_SUCCESS(Status))
832  goto done;
833 
834  /* Set SecDesc attribute*/
835  Status = SampRegSetValue(hServerKey,
836  L"SecDesc",
837  REG_BINARY,
838  Sd,
839  SdSize);
840  if (!NT_SUCCESS(Status))
841  goto done;
842 
843  SampRegCloseKey(&hDomainsKey);
844 
845  *lpServerKey = hServerKey;
846 
847 done:
848  if (Sd != NULL)
849  RtlFreeHeap(RtlGetProcessHeap(), 0, Sd);
850 
851  return Status;
852 }
NTSTATUS SampCreateServerSD(OUT PSECURITY_DESCRIPTOR *ServerSd, OUT PULONG Size)
Definition: security.c:21
#define REG_BINARY
Definition: nt_native.h:1496
LONG NTSTATUS
Definition: precomp.h:26
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:606
NTSTATUS SampRegCloseKey(IN OUT PHANDLE KeyHandle)
Definition: registry.c:26
smooth NULL
Definition: ftsmooth.c:416
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
static const WCHAR L[]
Definition: oid.c:1250
Status
Definition: gdiplustypes.h:24
#define KEY_ALL_ACCESS
Definition: nt_native.h:1041
NTSTATUS SampRegSetValue(HANDLE KeyHandle, LPCWSTR ValueName, ULONG Type, LPVOID Data, ULONG DataLength)
Definition: registry.c:402
unsigned int ULONG
Definition: retypes.h:1
NTSTATUS SampRegCreateKey(IN HANDLE ParentKeyHandle, IN LPCWSTR KeyName, IN ACCESS_MASK DesiredAccess, OUT PHANDLE KeyHandle)
Definition: registry.c:42

Referenced by SampInitializeSAM().

◆ SampSetupCreateUserAccount()

static NTSTATUS SampSetupCreateUserAccount ( HANDLE  hDomainKey,
LPCWSTR  lpAccountName,
LPCWSTR  lpComment,
PSID  lpDomainSid,
ULONG  ulRelativeId,
ULONG  UserAccountControl 
)
static

Definition at line 357 of file setup.c.

363 {
364  SAM_USER_FIXED_DATA FixedUserData;
365  GROUP_MEMBERSHIP GroupMembership;
366  UCHAR LogonHours[23];
367  LPWSTR lpEmptyString = L"";
368  WCHAR szAccountKeyName[32];
369  HANDLE hAccountKey = NULL;
370  HANDLE hNamesKey = NULL;
372  ULONG SdSize = 0;
373  PSID UserSid = NULL;
375 
376  UserSid = AppendRidToSid(lpDomainSid,
377  ulRelativeId);
378 
379  /* Create the security descriptor */
380  Status = SampCreateUserSD(UserSid,
381  &Sd,
382  &SdSize);
383  if (!NT_SUCCESS(Status))
384  goto done;
385 
386  /* Initialize fixed user data */
387  FixedUserData.Version = 1;
388  FixedUserData.Reserved = 0;
389  FixedUserData.LastLogon.QuadPart = 0;
390  FixedUserData.LastLogoff.QuadPart = 0;
391  FixedUserData.PasswordLastSet.QuadPart = 0;
392  FixedUserData.AccountExpires.QuadPart = MAXLONGLONG;
393  FixedUserData.LastBadPasswordTime.QuadPart = 0;
394  FixedUserData.UserId = ulRelativeId;
395  FixedUserData.PrimaryGroupId = DOMAIN_GROUP_RID_USERS;
396  FixedUserData.UserAccountControl = UserAccountControl;
397  FixedUserData.CountryCode = 0;
398  FixedUserData.CodePage = 0;
399  FixedUserData.BadPasswordCount = 0;
400  FixedUserData.LogonCount = 0;
401  FixedUserData.AdminCount = 0;
402  FixedUserData.OperatorCount = 0;
403 
404  swprintf(szAccountKeyName, L"Users\\%08lX", ulRelativeId);
405 
406  Status = SampRegCreateKey(hDomainKey,
407  szAccountKeyName,
409  &hAccountKey);
410  if (!NT_SUCCESS(Status))
411  return Status;
412 
413  Status = SampRegSetValue(hAccountKey,
414  L"F",
415  REG_BINARY,
416  (LPVOID)&FixedUserData,
417  sizeof(SAM_USER_FIXED_DATA));
418  if (!NT_SUCCESS(Status))
419  goto done;
420 
421  Status = SampRegSetValue(hAccountKey,
422  L"Name",
423  REG_SZ,
425  (wcslen(lpAccountName) + 1) * sizeof(WCHAR));
426  if (!NT_SUCCESS(Status))
427  goto done;
428 
429  Status = SampRegSetValue(hAccountKey,
430  L"FullName",
431  REG_SZ,
432  (LPVOID)lpEmptyString,
433  sizeof(WCHAR));
434  if (!NT_SUCCESS(Status))
435  goto done;
436 
437  Status = SampRegSetValue(hAccountKey,
438  L"HomeDirectory",
439  REG_SZ,
440  (LPVOID)lpEmptyString,
441  sizeof(WCHAR));
442  if (!NT_SUCCESS(Status))
443  goto done;
444 
445  Status = SampRegSetValue(hAccountKey,
446  L"HomeDirectoryDrive",
447  REG_SZ,
448  (LPVOID)lpEmptyString,
449  sizeof(WCHAR));
450  if (!NT_SUCCESS(Status))
451  goto done;
452 
453  Status = SampRegSetValue(hAccountKey,
454  L"ScriptPath",
455  REG_SZ,
456  (LPVOID)lpEmptyString,
457  sizeof(WCHAR));
458  if (!NT_SUCCESS(Status))
459  goto done;
460 
461  Status = SampRegSetValue(hAccountKey,
462  L"ProfilePath",
463  REG_SZ,
464  (LPVOID)lpEmptyString,
465  sizeof(WCHAR));
466  if (!NT_SUCCESS(Status))
467  goto done;
468 
469  Status = SampRegSetValue(hAccountKey,
470  L"AdminComment",
471  REG_SZ,
472  (LPVOID)lpComment,
473  (wcslen(lpComment) + 1) * sizeof(WCHAR));
474  if (!NT_SUCCESS(Status))
475  goto done;
476 
477  Status = SampRegSetValue(hAccountKey,
478  L"UserComment",
479  REG_SZ,
480  (LPVOID)lpEmptyString,
481  sizeof(WCHAR));
482  if (!NT_SUCCESS(Status))
483  goto done;
484 
485  Status = SampRegSetValue(hAccountKey,
486  L"WorkStations",
487  REG_SZ,
488  (LPVOID)lpEmptyString,
489  sizeof(WCHAR));
490  if (!NT_SUCCESS(Status))
491  goto done;
492 
493  Status = SampRegSetValue(hAccountKey,
494  L"Parameters",
495  REG_SZ,
496  (LPVOID)lpEmptyString,
497  sizeof(WCHAR));
498  if (!NT_SUCCESS(Status))
499  goto done;
500 
501  /* Set LogonHours attribute*/
502  *((PUSHORT)LogonHours) = 168;
503  memset(&(LogonHours[2]), 0xff, 21);
504 
505  Status = SampRegSetValue(hAccountKey,
506  L"LogonHours",
507  REG_BINARY,
508  (LPVOID)LogonHours,
509  sizeof(LogonHours));
510  if (!NT_SUCCESS(Status))
511  goto done;
512 
513  /* Set Groups attribute*/
514  GroupMembership.RelativeId = DOMAIN_GROUP_RID_USERS;
515  GroupMembership.Attributes = SE_GROUP_MANDATORY |
518 
519  Status = SampRegSetValue(hAccountKey,
520  L"Groups",
521  REG_BINARY,
522  (LPVOID)&GroupMembership,
523  sizeof(GROUP_MEMBERSHIP));
524  if (!NT_SUCCESS(Status))
525  goto done;
526 
527  /* Set LMPwd attribute*/
528  Status = SampRegSetValue(hAccountKey,
529  L"LMPwd",
530  REG_BINARY,
532  sizeof(ENCRYPTED_LM_OWF_PASSWORD));
533  if (!NT_SUCCESS(Status))
534  goto done;
535 
536  /* Set NTPwd attribute*/
537  Status = SampRegSetValue(hAccountKey,
538  L"NTPwd",
539  REG_BINARY,
541  sizeof(ENCRYPTED_NT_OWF_PASSWORD));
542  if (!NT_SUCCESS(Status))
543  goto done;
544 
545  /* Set LMPwdHistory attribute*/
546  Status = SampRegSetValue(hAccountKey,
547  L"LMPwdHistory",
548  REG_BINARY,
549  NULL,
550  0);
551  if (!NT_SUCCESS(Status))
552  goto done;
553 
554  /* Set NTPwdHistory attribute*/
555  Status = SampRegSetValue(hAccountKey,
556  L"NTPwdHistory",
557  REG_BINARY,
558  NULL,
559  0);
560  if (!NT_SUCCESS(Status))
561  goto done;
562 
563  /* Set PrivateData attribute*/
564  Status = SampRegSetValue(hAccountKey,
565  L"PrivateData",
566  REG_SZ,
567  (LPVOID)lpEmptyString,
568  sizeof(WCHAR));
569  if (!NT_SUCCESS(Status))
570  goto done;
571 
572  /* Set the SecDesc attribute*/
573  Status = SampRegSetValue(hAccountKey,
574  L"SecDesc",
575  REG_BINARY,
576  Sd,
577  SdSize);
578  if (!NT_SUCCESS(Status))
579  goto done;
580 
581  Status = SampRegOpenKey(hDomainKey,
582  L"Users\\Names",
584  &hNamesKey);
585  if (!NT_SUCCESS(Status))
586  goto done;
587 
588  Status = SampRegSetValue(hNamesKey,
590  REG_DWORD,
591  (LPVOID)&ulRelativeId,
592  sizeof(ULONG));
593 
594 done:
595  SampRegCloseKey(&hNamesKey);
596 
597  if (Sd != NULL)
598  RtlFreeHeap(RtlGetProcessHeap(), 0, Sd);
599 
600  if (UserSid != NULL)
601  RtlFreeHeap(RtlGetProcessHeap(), 0, UserSid);
602 
603  if (hAccountKey != NULL)
604  {
605  SampRegCloseKey(&hAccountKey);
606 
607  if (!NT_SUCCESS(Status))
608  SampRegDeleteKey(hDomainKey,
609  szAccountKeyName);
610  }
611 
612  return Status;
613 }
ULONG Attributes
Definition: ntsam.h:469
USHORT CountryCode
Definition: samsrv.h:109
ULONG RelativeId
Definition: ntsam.h:468
LARGE_INTEGER AccountExpires
Definition: samsrv.h:104
#define REG_BINARY
Definition: nt_native.h:1496
LARGE_INTEGER LastBadPasswordTime
Definition: samsrv.h:105
ULONG PrimaryGroupId
Definition: samsrv.h:107
LONG NTSTATUS
Definition: precomp.h:26
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:606
static PSID AppendRidToSid(PSID SrcSid, ULONG Rid)
Definition: msv1_0.c:245
#define MAXLONGLONG
NTSTATUS SampCreateUserSD(IN PSID UserSid, OUT PSECURITY_DESCRIPTOR *UserSd, OUT PULONG Size)
Definition: security.c:1433
_In_ LPCSTR lpAccountName
Definition: winbase.h:2688
ENCRYPTED_NT_OWF_PASSWORD EmptyNtHash
Definition: samsrv.c:26
NTSTATUS SampRegCloseKey(IN OUT PHANDLE KeyHandle)
Definition: registry.c:26
USHORT OperatorCount
Definition: samsrv.h:114
smooth NULL
Definition: ftsmooth.c:416
#define SE_GROUP_ENABLED_BY_DEFAULT
Definition: setypes.h:91
__wchar_t WCHAR
Definition: xmlstorage.h:180
LARGE_INTEGER PasswordLastSet
Definition: samsrv.h:103
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define SE_GROUP_ENABLED
Definition: setypes.h:92
#define swprintf(buf, format,...)
Definition: sprintf.c:56
#define SE_GROUP_MANDATORY
Definition: setypes.h:90
unsigned char UCHAR
Definition: xmlstorage.h:181
NTSTATUS SampRegDeleteKey(IN HANDLE ParentKeyHandle, IN LPCWSTR KeyName)
Definition: registry.c:71
static const WCHAR L[]
Definition: oid.c:1250
LARGE_INTEGER LastLogon
Definition: samsrv.h:101
Status
Definition: gdiplustypes.h:24
ENCRYPTED_LM_OWF_PASSWORD EmptyLmHash
Definition: samsrv.c:27
USHORT BadPasswordCount
Definition: samsrv.h:111
NTSTATUS SampRegOpenKey(IN HANDLE ParentKeyHandle, IN LPCWSTR KeyName, IN ACCESS_MASK DesiredAccess, OUT PHANDLE KeyHandle)
Definition: registry.c:158
#define KEY_ALL_ACCESS
Definition: nt_native.h:1041
#define DOMAIN_GROUP_RID_USERS
Definition: setypes.h:612
NTSTATUS SampRegSetValue(HANDLE KeyHandle, LPCWSTR ValueName, ULONG Type, LPVOID Data, ULONG DataLength)
Definition: registry.c:402
ULONG UserAccountControl
Definition: samsrv.h:108
unsigned int ULONG
Definition: retypes.h:1
NTSTATUS SampRegCreateKey(IN HANDLE ParentKeyHandle, IN LPCWSTR KeyName, IN ACCESS_MASK DesiredAccess, OUT PHANDLE KeyHandle)
Definition: registry.c:42
WCHAR * LPWSTR
Definition: xmlstorage.h:184
#define memset(x, y, z)
Definition: compat.h:39
#define REG_DWORD
Definition: sdbapi.c:596
LARGE_INTEGER LastLogoff
Definition: samsrv.h:102
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
unsigned short * PUSHORT
Definition: retypes.h:2
LONGLONG QuadPart
Definition: typedefs.h:112
#define REG_SZ
Definition: layer.c:22

Referenced by SampInitializeSAM().

Variable Documentation

◆ SecurityNtAuthority

Definition at line 20 of file setup.c.

Referenced by SampInitializeSAM().