ReactOS 0.4.16-dev-197-g92996da
samsrv.h File Reference
#include <stdio.h>
#include <stdlib.h>
#include <windef.h>
#include <winbase.h>
#include <winreg.h>
#include <ndk/ketypes.h>
#include <ndk/kefuncs.h>
#include <ndk/obfuncs.h>
#include <ndk/rtlfuncs.h>
#include <ddk/ntsam.h>
#include <sddl.h>
#include <sam_s.h>
#include <wine/debug.h>
Include dependency graph for samsrv.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  _SAM_DB_OBJECT
 
struct  _SAM_ALIAS_FIXED_DATA
 
struct  _SAM_DOMAIN_FIXED_DATA
 
struct  _SAM_GROUP_FIXED_DATA
 
struct  _SAM_USER_FIXED_DATA
 

Macros

#define WIN32_NO_STATUS
 
#define _INC_WINDOWS
 
#define COM_NO_WINDOWS_H
 
#define NTOS_MODE_USER
 
#define SAMP_DB_SIGNATURE   0x87654321
 

Typedefs

typedef enum _SAM_DB_OBJECT_TYPE SAM_DB_OBJECT_TYPE
 
typedef struct _SAM_DB_OBJECT SAM_DB_OBJECT
 
typedef struct _SAM_DB_OBJECTPSAM_DB_OBJECT
 
typedef struct _SAM_ALIAS_FIXED_DATA SAM_ALIAS_FIXED_DATA
 
typedef struct _SAM_ALIAS_FIXED_DATAPSAM_ALIAS_FIXED_DATA
 
typedef struct _SAM_DOMAIN_FIXED_DATA SAM_DOMAIN_FIXED_DATA
 
typedef struct _SAM_DOMAIN_FIXED_DATAPSAM_DOMAIN_FIXED_DATA
 
typedef struct _SAM_GROUP_FIXED_DATA SAM_GROUP_FIXED_DATA
 
typedef struct _SAM_GROUP_FIXED_DATAPSAM_GROUP_FIXED_DATA
 
typedef struct _SAM_USER_FIXED_DATA SAM_USER_FIXED_DATA
 
typedef struct _SAM_USER_FIXED_DATAPSAM_USER_FIXED_DATA
 

Enumerations

enum  _SAM_DB_OBJECT_TYPE {
  SamDbIgnoreObject , SamDbServerObject , SamDbDomainObject , SamDbAliasObject ,
  SamDbGroupObject , SamDbUserObject
}
 

Functions

 WINE_DEFAULT_DEBUG_CHANNEL (samsrv)
 
NTSTATUS SampOpenAliasObject (IN PSAM_DB_OBJECT DomainObject, IN ULONG AliasId, IN ACCESS_MASK DesiredAccess, OUT PSAM_DB_OBJECT *AliasObject)
 
NTSTATUS SampAddMemberToAlias (IN PSAM_DB_OBJECT AliasObject, IN PRPC_SID MemberId)
 
NTSTATUS NTAPI SampRemoveMemberFromAlias (IN PSAM_DB_OBJECT AliasObject, IN PRPC_SID MemberId)
 
NTSTATUS SampGetMembersInAlias (IN PSAM_DB_OBJECT AliasObject, OUT PULONG MemberCount, OUT PSAMPR_SID_INFORMATION *MemberArray)
 
NTSTATUS SampRemoveAllMembersFromAlias (IN PSAM_DB_OBJECT AliasObject)
 
NTSTATUS SampInitDatabase (VOID)
 
NTSTATUS SampCreateDbObject (IN PSAM_DB_OBJECT ParentObject, IN LPWSTR ContainerName, IN LPWSTR ObjectName, IN ULONG RelativeId, IN SAM_DB_OBJECT_TYPE ObjectType, IN ACCESS_MASK DesiredAccess, OUT PSAM_DB_OBJECT *DbObject)
 
NTSTATUS SampOpenDbObject (IN PSAM_DB_OBJECT ParentObject, IN LPWSTR ContainerName, IN LPWSTR ObjectName, IN ULONG RelativeId, IN SAM_DB_OBJECT_TYPE ObjectType, IN ACCESS_MASK DesiredAccess, OUT PSAM_DB_OBJECT *DbObject)
 
NTSTATUS SampValidateDbObject (SAMPR_HANDLE Handle, SAM_DB_OBJECT_TYPE ObjectType, ACCESS_MASK DesiredAccess, PSAM_DB_OBJECT *DbObject)
 
NTSTATUS SampCloseDbObject (PSAM_DB_OBJECT DbObject)
 
NTSTATUS SampDeleteAccountDbObject (PSAM_DB_OBJECT DbObject)
 
NTSTATUS SampSetObjectAttribute (PSAM_DB_OBJECT DbObject, LPWSTR AttributeName, ULONG AttributeType, LPVOID AttributeData, ULONG AttributeSize)
 
NTSTATUS SampGetObjectAttribute (PSAM_DB_OBJECT DbObject, LPWSTR AttributeName, PULONG AttributeType, LPVOID AttributeData, PULONG AttributeSize)
 
NTSTATUS SampGetObjectAttributeString (PSAM_DB_OBJECT DbObject, LPWSTR AttributeName, PRPC_UNICODE_STRING String)
 
NTSTATUS SampSetObjectAttributeString (PSAM_DB_OBJECT DbObject, LPWSTR AttributeName, PRPC_UNICODE_STRING String)
 
NTSTATUS SampInitializeDisplayCache (VOID)
 
NTSTATUS SampShutdownDisplayCache (VOID)
 
NTSTATUS SampFillDisplayCache (_In_ PSAM_DB_OBJECT DomainObject, _In_ DOMAIN_DISPLAY_INFORMATION DisplayInformationClass)
 
NTSTATUS SampSetAccountNameInDomain (IN PSAM_DB_OBJECT DomainObject, IN LPCWSTR lpContainerName, IN LPCWSTR lpAccountName, IN ULONG ulRelativeId)
 
NTSTATUS SampRemoveAccountNameFromDomain (IN PSAM_DB_OBJECT DomainObject, IN LPCWSTR lpContainerName, IN LPCWSTR lpAccountName)
 
NTSTATUS SampCheckAccountNameInDomain (IN PSAM_DB_OBJECT DomainObject, IN LPCWSTR lpAccountName)
 
NTSTATUS SampRemoveMemberFromAllAliases (IN PSAM_DB_OBJECT DomainObject, IN PRPC_SID MemberSid)
 
NTSTATUS SampCreateAccountSid (IN PSAM_DB_OBJECT DomainObject, IN ULONG ulRelativeId, IN OUT PSID *AccountSid)
 
NTSTATUS SampOpenGroupObject (IN PSAM_DB_OBJECT DomainObject, IN ULONG GroupId, IN ACCESS_MASK DesiredAccess, OUT PSAM_DB_OBJECT *GroupObject)
 
NTSTATUS SampAddMemberToGroup (IN PSAM_DB_OBJECT GroupObject, IN ULONG MemberId)
 
NTSTATUS SampRemoveMemberFromGroup (IN PSAM_DB_OBJECT GroupObject, IN ULONG MemberId)
 
NTSTATUS SampRegCloseKey (IN OUT PHANDLE KeyHandle)
 
NTSTATUS SampRegCreateKey (IN HANDLE ParentKeyHandle, IN LPCWSTR KeyName, IN ACCESS_MASK DesiredAccess, OUT PHANDLE KeyHandle)
 
NTSTATUS SampRegDeleteKey (IN HANDLE ParentKeyHandle, IN LPCWSTR KeyName)
 
NTSTATUS SampRegEnumerateSubKey (IN HANDLE KeyHandle, IN ULONG Index, IN ULONG Length, OUT LPWSTR Buffer)
 
NTSTATUS SampRegOpenKey (IN HANDLE ParentKeyHandle, IN LPCWSTR KeyName, IN ACCESS_MASK DesiredAccess, OUT PHANDLE KeyHandle)
 
NTSTATUS SampRegQueryKeyInfo (IN HANDLE KeyHandle, OUT PULONG SubKeyCount, OUT PULONG ValueCount)
 
NTSTATUS SampRegDeleteValue (IN HANDLE KeyHandle, IN LPCWSTR ValueName)
 
NTSTATUS SampRegEnumerateValue (IN HANDLE KeyHandle, IN ULONG Index, OUT LPWSTR Name, IN OUT PULONG NameLength, OUT PULONG Type OPTIONAL, OUT PVOID Data OPTIONAL, IN OUT PULONG DataLength OPTIONAL)
 
NTSTATUS SampRegQueryValue (IN HANDLE KeyHandle, IN LPCWSTR ValueName, OUT PULONG Type OPTIONAL, OUT LPVOID Data OPTIONAL, IN OUT PULONG DataLength OPTIONAL)
 
NTSTATUS SampRegSetValue (IN HANDLE KeyHandle, IN LPCWSTR ValueName, IN ULONG Type, IN LPVOID Data, IN ULONG DataLength)
 
VOID SampStartRpcServer (VOID)
 
NTSTATUS SampCreateServerSD (OUT PSECURITY_DESCRIPTOR *ServerSd, OUT PULONG Size)
 
NTSTATUS SampCreateBuiltinDomainSD (OUT PSECURITY_DESCRIPTOR *DomainSd, OUT PULONG Size)
 
NTSTATUS SampCreateAccountDomainSD (OUT PSECURITY_DESCRIPTOR *DomainSd, OUT PULONG Size)
 
NTSTATUS SampCreateAliasSD (OUT PSECURITY_DESCRIPTOR *AliasSd, OUT PULONG Size)
 
NTSTATUS SampCreateGroupSD (OUT PSECURITY_DESCRIPTOR *GroupSd, OUT PULONG Size)
 
NTSTATUS SampCreateUserSD (IN PSID UserSid, OUT PSECURITY_DESCRIPTOR *UserSd, OUT PULONG Size)
 
BOOL SampInitializeSAM (VOID)
 
NTSTATUS SampOpenUserObject (IN PSAM_DB_OBJECT DomainObject, IN ULONG UserId, IN ACCESS_MASK DesiredAccess, OUT PSAM_DB_OBJECT *UserObject)
 
NTSTATUS SampAddGroupMembershipToUser (IN PSAM_DB_OBJECT UserObject, IN ULONG GroupId, IN ULONG Attributes)
 
NTSTATUS SampRemoveGroupMembershipFromUser (IN PSAM_DB_OBJECT UserObject, IN ULONG GroupId)
 
NTSTATUS SampGetUserGroupAttributes (IN PSAM_DB_OBJECT DomainObject, IN ULONG UserId, IN ULONG GroupId, OUT PULONG GroupAttributes)
 
NTSTATUS SampSetUserGroupAttributes (IN PSAM_DB_OBJECT DomainObject, IN ULONG UserId, IN ULONG GroupId, IN ULONG GroupAttributes)
 
NTSTATUS SampRemoveUserFromAllGroups (IN PSAM_DB_OBJECT UserObject)
 
NTSTATUS SampRemoveUserFromAllAliases (IN PSAM_DB_OBJECT UserObject)
 
NTSTATUS SampSetUserPassword (IN PSAM_DB_OBJECT UserObject, IN PENCRYPTED_NT_OWF_PASSWORD NtPassword, IN BOOLEAN NtPasswordPresent, IN PENCRYPTED_LM_OWF_PASSWORD LmPassword, IN BOOLEAN LmPasswordPresent)
 
NTSTATUS SampGetLogonHoursAttribute (IN PSAM_DB_OBJECT UserObject, IN OUT PSAMPR_LOGON_HOURS LogonHours)
 
NTSTATUS SampSetLogonHoursAttribute (IN PSAM_DB_OBJECT UserObject, IN PSAMPR_LOGON_HOURS LogonHours)
 
INT SampLoadString (HINSTANCE hInstance, UINT uId, LPWSTR lpBuffer, INT nBufferMax)
 
BOOL SampIsSetupRunning (VOID)
 
PSID AppendRidToSid (PSID SrcSid, ULONG Rid)
 
NTSTATUS SampGetRidFromSid (IN PSID Sid, OUT PULONG Rid)
 
NTSTATUS SampCheckAccountName (IN PRPC_UNICODE_STRING AccountName, IN USHORT MaxLength)
 
NTSTATUS WINAPI SystemFunction006 (LPCSTR password, LPSTR hash)
 
NTSTATUS WINAPI SystemFunction007 (PUNICODE_STRING string, LPBYTE hash)
 
NTSTATUS WINAPI SystemFunction013 (const BYTE *in, const BYTE *key, LPBYTE out)
 

Variables

PGENERIC_MAPPING pServerMapping
 
ENCRYPTED_NT_OWF_PASSWORD EmptyNtHash
 
ENCRYPTED_LM_OWF_PASSWORD EmptyLmHash
 
RTL_RESOURCE SampResource
 
NT_PRODUCT_TYPE SampProductType
 

Macro Definition Documentation

◆ _INC_WINDOWS

#define _INC_WINDOWS

Definition at line 17 of file samsrv.h.

◆ COM_NO_WINDOWS_H

#define COM_NO_WINDOWS_H

Definition at line 18 of file samsrv.h.

◆ NTOS_MODE_USER

#define NTOS_MODE_USER

Definition at line 23 of file samsrv.h.

◆ SAMP_DB_SIGNATURE

#define SAMP_DB_SIGNATURE   0x87654321

Definition at line 59 of file samsrv.h.

◆ WIN32_NO_STATUS

#define WIN32_NO_STATUS

Definition at line 16 of file samsrv.h.

Typedef Documentation

◆ PSAM_ALIAS_FIXED_DATA

◆ PSAM_DB_OBJECT

◆ PSAM_DOMAIN_FIXED_DATA

◆ PSAM_GROUP_FIXED_DATA

◆ PSAM_USER_FIXED_DATA

◆ SAM_ALIAS_FIXED_DATA

◆ SAM_DB_OBJECT

◆ SAM_DB_OBJECT_TYPE

◆ SAM_DOMAIN_FIXED_DATA

◆ SAM_GROUP_FIXED_DATA

◆ SAM_USER_FIXED_DATA

Enumeration Type Documentation

◆ _SAM_DB_OBJECT_TYPE

Enumerator
SamDbIgnoreObject 
SamDbServerObject 
SamDbDomainObject 
SamDbAliasObject 
SamDbGroupObject 
SamDbUserObject 

Definition at line 35 of file samsrv.h.

36{
enum _SAM_DB_OBJECT_TYPE SAM_DB_OBJECT_TYPE
@ SamDbGroupObject
Definition: samsrv.h:41
@ SamDbUserObject
Definition: samsrv.h:42
@ SamDbIgnoreObject
Definition: samsrv.h:37
@ SamDbAliasObject
Definition: samsrv.h:40
@ SamDbServerObject
Definition: samsrv.h:38
@ SamDbDomainObject
Definition: samsrv.h:39

Function Documentation

◆ AppendRidToSid()

PSID AppendRidToSid ( PSID  SrcSid,
ULONG  Rid 
)

Definition at line 103 of file utils.c.

105{
106 ULONG Rids[8] = {0, 0, 0, 0, 0, 0, 0, 0};
107 UCHAR RidCount;
108 PSID DstSid;
109 ULONG i;
110
111 RidCount = *RtlSubAuthorityCountSid(SrcSid);
112 if (RidCount >= 8)
113 return NULL;
114
115 for (i = 0; i < RidCount; i++)
116 Rids[i] = *RtlSubAuthoritySid(SrcSid, i);
117
118 Rids[RidCount] = Rid;
119 RidCount++;
120
122 RidCount,
123 Rids[0],
124 Rids[1],
125 Rids[2],
126 Rids[3],
127 Rids[4],
128 Rids[5],
129 Rids[6],
130 Rids[7],
131 &DstSid);
132
133 return DstSid;
134}
#define NULL
Definition: types.h:112
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
NTSYSAPI PULONG NTAPI RtlSubAuthoritySid(_In_ PSID Sid, _In_ ULONG SubAuthority)
NTSYSAPI PSID_IDENTIFIER_AUTHORITY NTAPI RtlIdentifierAuthoritySid(PSID Sid)
NTSYSAPI NTSTATUS NTAPI RtlAllocateAndInitializeSid(IN PSID_IDENTIFIER_AUTHORITY IdentifierAuthority, IN UCHAR SubAuthorityCount, IN ULONG SubAuthority0, IN ULONG SubAuthority1, IN ULONG SubAuthority2, IN ULONG SubAuthority3, IN ULONG SubAuthority4, IN ULONG SubAuthority5, IN ULONG SubAuthority6, IN ULONG SubAuthority7, OUT PSID *Sid)
Definition: sid.c:290
NTSYSAPI PUCHAR NTAPI RtlSubAuthorityCountSid(IN PSID Sid)
Definition: sid.c:104
uint32_t ULONG
Definition: typedefs.h:59
unsigned char UCHAR
Definition: xmlstorage.h:181

◆ SampAddGroupMembershipToUser()

NTSTATUS SampAddGroupMembershipToUser ( IN PSAM_DB_OBJECT  UserObject,
IN ULONG  GroupId,
IN ULONG  Attributes 
)

Definition at line 39 of file user.c.

42{
43 PGROUP_MEMBERSHIP GroupsBuffer = NULL;
44 ULONG GroupsCount = 0;
45 ULONG Length = 0;
46 ULONG i;
48
49 TRACE("(%p %lu %lx)\n",
50 UserObject, GroupId, Attributes);
51
52 Status = SampGetObjectAttribute(UserObject,
53 L"Groups",
54 NULL,
55 NULL,
56 &Length);
58 goto done;
59
60 GroupsBuffer = midl_user_allocate(Length + sizeof(GROUP_MEMBERSHIP));
61 if (GroupsBuffer == NULL)
62 {
64 goto done;
65 }
66
68 {
69 Status = SampGetObjectAttribute(UserObject,
70 L"Groups",
71 NULL,
72 GroupsBuffer,
73 &Length);
74 if (!NT_SUCCESS(Status))
75 goto done;
76
77 GroupsCount = Length / sizeof(GROUP_MEMBERSHIP);
78 }
79
80 for (i = 0; i < GroupsCount; i++)
81 {
82 if (GroupsBuffer[i].RelativeId == GroupId)
83 {
85 goto done;
86 }
87 }
88
89 GroupsBuffer[GroupsCount].RelativeId = GroupId;
90 GroupsBuffer[GroupsCount].Attributes = Attributes;
91 Length += sizeof(GROUP_MEMBERSHIP);
92
93 Status = SampSetObjectAttribute(UserObject,
94 L"Groups",
96 GroupsBuffer,
97 Length);
98
99done:
100 if (GroupsBuffer != NULL)
101 midl_user_free(GroupsBuffer);
102
103 return Status;
104}
LONG NTSTATUS
Definition: precomp.h:26
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
NTSTATUS SampGetObjectAttribute(PSAM_DB_OBJECT DbObject, LPWSTR AttributeName, PULONG AttributeType, LPVOID AttributeData, PULONG AttributeSize)
Definition: database.c:516
NTSTATUS SampSetObjectAttribute(PSAM_DB_OBJECT DbObject, LPWSTR AttributeName, ULONG AttributeType, LPVOID AttributeData, ULONG AttributeSize)
Definition: database.c:501
Status
Definition: gdiplustypes.h:25
#define REG_BINARY
Definition: nt_native.h:1496
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:102
struct _GROUP_MEMBERSHIP GROUP_MEMBERSHIP
#define STATUS_MEMBER_IN_GROUP
Definition: ntstatus.h:339
#define L(x)
Definition: ntvdm.h:50
#define midl_user_free
Definition: rpc.h:45
#define midl_user_allocate
Definition: rpc.h:44
#define TRACE(s)
Definition: solgame.cpp:4
ULONG RelativeId
Definition: ntsam.h:496
ULONG Attributes
Definition: ntsam.h:497
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
#define STATUS_OBJECT_NAME_NOT_FOUND
Definition: udferr_usr.h:149
_Must_inspect_result_ _In_ WDFDMAENABLER _In_ _In_opt_ PWDF_OBJECT_ATTRIBUTES Attributes

Referenced by SamrAddMemberToGroup().

◆ SampAddMemberToAlias()

NTSTATUS SampAddMemberToAlias ( IN PSAM_DB_OBJECT  AliasObject,
IN PRPC_SID  MemberId 
)

Definition at line 39 of file alias.c.

41{
42 LPWSTR MemberIdString = NULL;
43 HANDLE MembersKeyHandle = NULL;
44 HANDLE MemberKeyHandle = NULL;
45 ULONG MemberIdLength;
47
48 TRACE("(%p %p)\n",
49 AliasObject, MemberId);
50
51 ConvertSidToStringSidW(MemberId, &MemberIdString);
52 TRACE("Member SID: %S\n", MemberIdString);
53
54 MemberIdLength = RtlLengthSid(MemberId);
55
56 Status = SampRegCreateKey(AliasObject->KeyHandle,
57 L"Members",
59 &MembersKeyHandle);
60 if (!NT_SUCCESS(Status))
61 {
62 TRACE("SampRegCreateKey failed with status 0x%08lx\n", Status);
63 goto done;
64 }
65
66 Status = SampRegSetValue(MembersKeyHandle,
67 MemberIdString,
69 MemberId,
70 MemberIdLength);
71 if (!NT_SUCCESS(Status))
72 {
73 TRACE("SampRegSetValue failed with status 0x%08lx\n", Status);
74 goto done;
75 }
76
77 Status = SampRegCreateKey(AliasObject->MembersKeyHandle,
78 MemberIdString,
80 &MemberKeyHandle);
81 if (!NT_SUCCESS(Status))
82 {
83 TRACE("SampRegCreateKey failed with status 0x%08lx\n", Status);
84 goto done;
85 }
86
87 Status = SampRegSetValue(MemberKeyHandle,
88 AliasObject->Name,
90 MemberId,
91 MemberIdLength);
92 if (!NT_SUCCESS(Status))
93 {
94 TRACE("SampRegSetValue failed with status 0x%08lx\n", Status);
95 goto done;
96 }
97
98done:
99 SampRegCloseKey(&MemberKeyHandle);
100 SampRegCloseKey(&MembersKeyHandle);
101
102 if (MemberIdString != NULL)
103 LocalFree(MemberIdString);
104
105 return Status;
106}
BOOL WINAPI ConvertSidToStringSidW(PSID Sid, LPWSTR *StringSid)
Definition: security.c:3583
NTSTATUS SampRegCloseKey(IN OUT PHANDLE KeyHandle)
Definition: registry.c:26
NTSTATUS SampRegSetValue(HANDLE KeyHandle, LPCWSTR ValueName, ULONG Type, LPVOID Data, ULONG DataLength)
Definition: registry.c:402
NTSTATUS SampRegCreateKey(IN HANDLE ParentKeyHandle, IN LPCWSTR KeyName, IN ACCESS_MASK DesiredAccess, OUT PHANDLE KeyHandle)
Definition: registry.c:42
HLOCAL NTAPI LocalFree(HLOCAL hMem)
Definition: heapmem.c:1594
NTSYSAPI ULONG NTAPI RtlLengthSid(IN PSID Sid)
Definition: sid.c:150
#define KEY_WRITE
Definition: nt_native.h:1031
WCHAR * LPWSTR
Definition: xmlstorage.h:184

Referenced by SamrAddMemberToAlias().

◆ SampAddMemberToGroup()

NTSTATUS SampAddMemberToGroup ( IN PSAM_DB_OBJECT  GroupObject,
IN ULONG  MemberId 
)

Definition at line 39 of file group.c.

41{
42 PULONG MembersBuffer = NULL;
43 ULONG MembersCount = 0;
44 ULONG Length = 0;
45 ULONG i;
47
48 Status = SampGetObjectAttribute(GroupObject,
49 L"Members",
50 NULL,
51 NULL,
52 &Length);
54 goto done;
55
56 MembersBuffer = midl_user_allocate(Length + sizeof(ULONG));
57 if (MembersBuffer == NULL)
58 {
60 goto done;
61 }
62
64 {
65 Status = SampGetObjectAttribute(GroupObject,
66 L"Members",
67 NULL,
68 MembersBuffer,
69 &Length);
70 if (!NT_SUCCESS(Status))
71 goto done;
72
73 MembersCount = Length / sizeof(ULONG);
74 }
75
76 for (i = 0; i < MembersCount; i++)
77 {
78 if (MembersBuffer[i] == MemberId)
79 {
81 goto done;
82 }
83 }
84
85 MembersBuffer[MembersCount] = MemberId;
86 Length += sizeof(ULONG);
87
88 Status = SampSetObjectAttribute(GroupObject,
89 L"Members",
91 MembersBuffer,
92 Length);
93
94done:
95 if (MembersBuffer != NULL)
96 midl_user_free(MembersBuffer);
97
98 return Status;
99}
uint32_t * PULONG
Definition: typedefs.h:59

Referenced by SamrAddMemberToGroup().

◆ SampCheckAccountName()

NTSTATUS SampCheckAccountName ( IN PRPC_UNICODE_STRING  AccountName,
IN USHORT  MaxLength 
)

Definition at line 154 of file utils.c.

156{
157 if (AccountName->Length > MaxLength * sizeof(WCHAR))
159
160 return STATUS_SUCCESS;
161}
#define STATUS_INVALID_ACCOUNT_NAME
Definition: ntstatus.h:334
#define STATUS_SUCCESS
Definition: shellext.h:65
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by SampSetAliasName(), SampSetGroupName(), SampSetUserName(), SamrCreateAliasInDomain(), SamrCreateGroupInDomain(), SamrCreateUser2InDomain(), and SamrCreateUserInDomain().

◆ SampCheckAccountNameInDomain()

NTSTATUS SampCheckAccountNameInDomain ( IN PSAM_DB_OBJECT  DomainObject,
IN LPCWSTR  lpAccountName 
)

Definition at line 96 of file domain.c.

98{
99 HANDLE AccountKey = NULL;
100 HANDLE NamesKey = NULL;
102
103 TRACE("SampCheckAccountNameInDomain()\n");
104
105 Status = SampRegOpenKey(DomainObject->KeyHandle,
106 L"Aliases",
107 KEY_READ,
108 &AccountKey);
109 if (NT_SUCCESS(Status))
110 {
111 Status = SampRegOpenKey(AccountKey,
112 L"Names",
113 KEY_READ,
114 &NamesKey);
115 if (NT_SUCCESS(Status))
116 {
117 Status = SampRegQueryValue(NamesKey,
119 NULL,
120 NULL,
121 NULL);
122 if (Status == STATUS_SUCCESS)
123 {
124 SampRegCloseKey(&NamesKey);
126 }
129 }
130
131 SampRegCloseKey(&AccountKey);
132 }
133
134 if (!NT_SUCCESS(Status))
135 {
136 TRACE("Checking for alias account failed (Status 0x%08lx)\n", Status);
137 return Status;
138 }
139
140 Status = SampRegOpenKey(DomainObject->KeyHandle,
141 L"Groups",
142 KEY_READ,
143 &AccountKey);
144 if (NT_SUCCESS(Status))
145 {
146 Status = SampRegOpenKey(AccountKey,
147 L"Names",
148 KEY_READ,
149 &NamesKey);
150 if (NT_SUCCESS(Status))
151 {
152 Status = SampRegQueryValue(NamesKey,
154 NULL,
155 NULL,
156 NULL);
157 if (Status == STATUS_SUCCESS)
158 {
159 SampRegCloseKey(&NamesKey);
161 }
164 }
165
166 SampRegCloseKey(&AccountKey);
167 }
168
169 if (!NT_SUCCESS(Status))
170 {
171 TRACE("Checking for group account failed (Status 0x%08lx)\n", Status);
172 return Status;
173 }
174
175 Status = SampRegOpenKey(DomainObject->KeyHandle,
176 L"Users",
177 KEY_READ,
178 &AccountKey);
179 if (NT_SUCCESS(Status))
180 {
181 Status = SampRegOpenKey(AccountKey,
182 L"Names",
183 KEY_READ,
184 &NamesKey);
185 if (NT_SUCCESS(Status))
186 {
187 Status = SampRegQueryValue(NamesKey,
189 NULL,
190 NULL,
191 NULL);
192 if (Status == STATUS_SUCCESS)
193 {
194 SampRegCloseKey(&NamesKey);
196 }
199 }
200
201 SampRegCloseKey(&AccountKey);
202 }
203
204 if (!NT_SUCCESS(Status))
205 {
206 TRACE("Checking for user account failed (Status 0x%08lx)\n", Status);
207 }
208
209 return Status;
210}
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
NTSTATUS SampRegOpenKey(IN HANDLE ParentKeyHandle, IN LPCWSTR KeyName, IN ACCESS_MASK DesiredAccess, OUT PHANDLE KeyHandle)
Definition: registry.c:158
#define KEY_READ
Definition: nt_native.h:1023
#define STATUS_ALIAS_EXISTS
Definition: ntstatus.h:576
#define STATUS_USER_EXISTS
Definition: ntstatus.h:335
#define STATUS_GROUP_EXISTS
Definition: ntstatus.h:337
_In_ LPCSTR lpAccountName
Definition: winbase.h:2765

Referenced by SampSetAliasName(), SampSetGroupName(), SampSetUserName(), SamrCreateAliasInDomain(), SamrCreateGroupInDomain(), SamrCreateUser2InDomain(), and SamrCreateUserInDomain().

◆ SampCloseDbObject()

NTSTATUS SampCloseDbObject ( PSAM_DB_OBJECT  DbObject)

Definition at line 346 of file database.c.

347{
349
350 DbObject->RefCount--;
351
352 if (DbObject->RefCount > 0)
353 return STATUS_SUCCESS;
354
355 SampRegCloseKey(&DbObject->KeyHandle);
357
358 if (DbObject->Name != NULL)
359 RtlFreeHeap(RtlGetProcessHeap(), 0, DbObject->Name);
360
361 RtlFreeHeap(RtlGetProcessHeap(), 0, DbObject);
362
363 return Status;
364}
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:608
LPWSTR Name
Definition: samsrv.h:51
HANDLE KeyHandle
Definition: samsrv.h:52
ULONG RefCount
Definition: samsrv.h:49
HANDLE MembersKeyHandle
Definition: samsrv.h:53

Referenced by SampFillUserDisplayCache(), SampGetUserGroupAttributes(), SampRemoveUserFromAllGroups(), SampSetUserGroupAttributes(), SamrAddMemberToGroup(), SamrCloseHandle(), SamrGetDomainPasswordInformation(), and SamrRemoveMemberFromGroup().

◆ SampCreateAccountDomainSD()

NTSTATUS SampCreateAccountDomainSD ( OUT PSECURITY_DESCRIPTOR DomainSd,
OUT PULONG  Size 
)

Definition at line 545 of file security.c.

547{
550 PSID EveryoneSid = NULL;
551 PSID AnonymousSid = NULL;
552 PSID AdministratorsSid = NULL;
553 PSID UsersSid = NULL;
554 PSID GuestsSid = NULL;
555 PACL Dacl = NULL;
556 PACL Sacl = NULL;
559 ULONG RelSDSize = 0;
561
562
563 /* Create the Everyone SID */
565 1,
567 0,
568 0,
569 0,
570 0,
571 0,
572 0,
573 0,
574 &EveryoneSid);
576 if (!NT_SUCCESS(Status))
577 goto done;
578
579 /* Create the Anonymous SID */
581 1,
583 0,
584 0,
585 0,
586 0,
587 0,
588 0,
589 0,
590 &AnonymousSid);
592 if (!NT_SUCCESS(Status))
593 goto done;
594
595 /* Create the Administrators SID */
597 2,
600 0,
601 0,
602 0,
603 0,
604 0,
605 0,
606 &AdministratorsSid);
608 if (!NT_SUCCESS(Status))
609 goto done;
610
611 /* Create the Users SID */
613 2,
616 0,
617 0,
618 0,
619 0,
620 0,
621 0,
622 &UsersSid);
624 if (!NT_SUCCESS(Status))
625 goto done;
626
627 /* Create the Guests SID */
629 2,
632 0,
633 0,
634 0,
635 0,
636 0,
637 0,
638 &GuestsSid);
640 if (!NT_SUCCESS(Status))
641 goto done;
642
643
644 /* Allocate a buffer for the absolute SD */
645 AbsSD = RtlAllocateHeap(RtlGetProcessHeap(),
647 sizeof(SECURITY_DESCRIPTOR));
648 if (AbsSD == NULL)
649 {
652 goto done;
653 }
654
655 /* Create the absolute SD */
659 if (!NT_SUCCESS(Status))
660 goto done;
661
662 /* allocate and create the DACL */
663 DaclSize = sizeof(ACL) +
664 4 * sizeof(ACE) +
665 RtlLengthSid(EveryoneSid) +
666 RtlLengthSid(AdministratorsSid) +
667 RtlLengthSid(UsersSid) +
668 RtlLengthSid(GuestsSid);
669
670 Dacl = RtlAllocateHeap(RtlGetProcessHeap(),
672 DaclSize);
673 if (Dacl == NULL)
674 {
677 goto done;
678 }
679
681 DaclSize,
684 if (!NT_SUCCESS(Status))
685 goto done;
686
690 EveryoneSid);
692 if (!NT_SUCCESS(Status))
693 goto done;
694
698 UsersSid);
700 if (!NT_SUCCESS(Status))
701 goto done;
702
706 AdministratorsSid);
708 if (!NT_SUCCESS(Status))
709 goto done;
710
714 GuestsSid);
716 if (!NT_SUCCESS(Status))
717 goto done;
718
719 /* Set the DACL */
721 TRUE,
722 Dacl,
723 FALSE);
725 if (!NT_SUCCESS(Status))
726 goto done;
727
728 /* allocate and create the SACL */
729 SaclSize = sizeof(ACL) +
730 2 * sizeof(ACE) +
731 RtlLengthSid(EveryoneSid) +
732 RtlLengthSid(AnonymousSid);
733
734 Sacl = RtlAllocateHeap(RtlGetProcessHeap(),
736 DaclSize);
737 if (Sacl == NULL)
738 {
741 goto done;
742 }
743
745 SaclSize,
748 if (!NT_SUCCESS(Status))
749 goto done;
750
756 EveryoneSid,
757 TRUE,
758 TRUE);
760 if (!NT_SUCCESS(Status))
761 goto done;
762
766 AnonymousSid,
767 TRUE,
768 TRUE);
770 if (!NT_SUCCESS(Status))
771 goto done;
772
773 /* Set the SACL */
775 TRUE,
776 Sacl,
777 FALSE);
779 if (!NT_SUCCESS(Status))
780 goto done;
781
782 /* Set the owner SID */
784 AdministratorsSid,
785 FALSE);
787 if (!NT_SUCCESS(Status))
788 goto done;
789
790 /* Set the group SID */
792 AdministratorsSid,
793 FALSE);
795 if (!NT_SUCCESS(Status))
796 goto done;
797
798 /* Get the reqired buffer size for the self-relative SD */
800 NULL,
801 &RelSDSize);
803 goto done;
804
805 /* Allocate a buffer for the self-relative SD */
806 RelSD = RtlAllocateHeap(RtlGetProcessHeap(),
808 RelSDSize);
809 if (RelSD == NULL)
810 {
813 goto done;
814 }
815
816 /* Convert the absolute SD to self-relative format */
818 RelSD,
819 &RelSDSize);
821 {
823 goto done;
824 }
825
826 *ServerSd = RelSD;
827 *Size = RelSDSize;
828
829done:
830 if (!NT_SUCCESS(Status))
831 {
832 if (RelSD != NULL)
833 RtlFreeHeap(RtlGetProcessHeap(), 0, RelSD);
834 }
835
836 if (EveryoneSid != NULL)
837 RtlFreeSid(EveryoneSid);
838
839 if (AnonymousSid != NULL)
840 RtlFreeSid(AnonymousSid);
841
842 if (AdministratorsSid != NULL)
843 RtlFreeSid(AdministratorsSid);
844
845 if (Dacl != NULL)
846 RtlFreeHeap(RtlGetProcessHeap(), 0, Dacl);
847
848 if (Sacl != NULL)
849 RtlFreeHeap(RtlGetProcessHeap(), 0, Sacl);
850
851 if (AbsSD != NULL)
852 RtlFreeHeap(RtlGetProcessHeap(), 0, AbsSD);
853
854 return Status;
855}
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:590
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define HEAP_ZERO_MEMORY
Definition: compat.h:134
static SID_IDENTIFIER_AUTHORITY WorldAuthority
Definition: security.c:14
static SID_IDENTIFIER_AUTHORITY NtAuthority
Definition: security.c:15
NTSYSAPI NTSTATUS WINAPI RtlAddAccessAllowedAce(PACL, DWORD, DWORD, PSID)
NTSYSAPI NTSTATUS WINAPI RtlSetOwnerSecurityDescriptor(PSECURITY_DESCRIPTOR, PSID, BOOLEAN)
NTSYSAPI NTSTATUS WINAPI RtlSetDaclSecurityDescriptor(PSECURITY_DESCRIPTOR, BOOLEAN, PACL, BOOLEAN)
#define ASSERT(a)
Definition: mode.c:44
struct _ACL ACL
_Out_writes_bytes_to_opt_ AbsoluteSecurityDescriptorSize PSECURITY_DESCRIPTOR _Inout_ PULONG _Out_writes_bytes_to_opt_ DaclSize PACL Dacl
Definition: rtlfuncs.h:1605
NTSYSAPI NTSTATUS NTAPI RtlCreateAcl(PACL Acl, ULONG AclSize, ULONG AclRevision)
NTSYSAPI NTSTATUS NTAPI RtlAddAuditAccessAce(_Inout_ PACL Acl, _In_ ULONG Revision, _In_ ACCESS_MASK AccessMask, _In_ PSID Sid, _In_ BOOLEAN Success, _In_ BOOLEAN Failure)
_Out_writes_bytes_to_opt_ AbsoluteSecurityDescriptorSize PSECURITY_DESCRIPTOR _Inout_ PULONG _Out_writes_bytes_to_opt_ DaclSize PACL _Inout_ PULONG _Out_writes_bytes_to_opt_ SaclSize PACL _Inout_ PULONG SaclSize
Definition: rtlfuncs.h:1608
NTSYSAPI NTSTATUS NTAPI RtlCreateSecurityDescriptor(_Out_ PSECURITY_DESCRIPTOR SecurityDescriptor, _In_ ULONG Revision)
_Out_writes_bytes_to_opt_ AbsoluteSecurityDescriptorSize PSECURITY_DESCRIPTOR _Inout_ PULONG _Out_writes_bytes_to_opt_ DaclSize PACL _Inout_ PULONG _Out_writes_bytes_to_opt_ SaclSize PACL Sacl
Definition: rtlfuncs.h:1607
NTSYSAPI PVOID NTAPI RtlFreeSid(_In_ _Post_invalid_ PSID Sid)
_Out_writes_bytes_to_opt_ AbsoluteSecurityDescriptorSize PSECURITY_DESCRIPTOR _Inout_ PULONG _Out_writes_bytes_to_opt_ DaclSize PACL _Inout_ PULONG DaclSize
Definition: rtlfuncs.h:1606
#define SPECIFIC_RIGHTS_ALL
Definition: nt_native.h:71
#define WRITE_DAC
Definition: nt_native.h:59
#define ACCESS_SYSTEM_SECURITY
Definition: nt_native.h:77
#define STANDARD_RIGHTS_ALL
Definition: nt_native.h:69
#define DELETE
Definition: nt_native.h:57
NTSYSAPI NTSTATUS NTAPI RtlSetGroupSecurityDescriptor(IN OUT PSECURITY_DESCRIPTOR SecurityDescriptor, IN PSID Group, IN BOOLEAN GroupDefaulted)
Definition: sd.c:410
NTSYSAPI NTSTATUS NTAPI RtlSetSaclSecurityDescriptor(IN OUT PSECURITY_DESCRIPTOR SecurityDescriptor, IN BOOLEAN SaclPresent, IN PACL Sacl, IN BOOLEAN SaclDefaulted)
Definition: sd.c:342
NTSYSAPI NTSTATUS NTAPI RtlAbsoluteToSelfRelativeSD(IN PSECURITY_DESCRIPTOR AbsoluteSecurityDescriptor, IN OUT PSECURITY_DESCRIPTOR SelfRelativeSecurityDescriptor, IN PULONG BufferLength)
Definition: sd.c:626
#define DOMAIN_ALL_ACCESS
Definition: ntsam.h:62
#define SAM_SERVER_SHUTDOWN
Definition: ntsam.h:100
#define DOMAIN_CREATE_GROUP
Definition: ntsam.h:38
#define DOMAIN_CREATE_ALIAS
Definition: ntsam.h:39
#define DOMAIN_EXECUTE
Definition: ntsam.h:57
#define DOMAIN_CREATE_USER
Definition: ntsam.h:37
#define DOMAIN_READ
Definition: ntsam.h:45
#define SAM_SERVER_CREATE_DOMAIN
Definition: ntsam.h:102
#define SAM_SERVER_INITIALIZE
Definition: ntsam.h:101
#define STATUS_BUFFER_TOO_SMALL
Definition: shellext.h:69
Definition: rtltypes.h:993
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ DEVPROPTYPE _In_ ULONG Size
Definition: wdfdevice.h:4533
#define SECURITY_ANONYMOUS_LOGON_RID
Definition: setypes.h:563
#define DOMAIN_ALIAS_RID_USERS
Definition: setypes.h:653
#define DOMAIN_ALIAS_RID_GUESTS
Definition: setypes.h:654
#define SECURITY_BUILTIN_DOMAIN_RID
Definition: setypes.h:581
#define SECURITY_WORLD_RID
Definition: setypes.h:541
#define SECURITY_DESCRIPTOR_REVISION
Definition: setypes.h:58
#define ACL_REVISION
Definition: setypes.h:39
#define DOMAIN_ALIAS_RID_ADMINS
Definition: setypes.h:652

Referenced by SampSetupCreateDomain().

◆ SampCreateAccountSid()

NTSTATUS SampCreateAccountSid ( IN PSAM_DB_OBJECT  DomainObject,
IN ULONG  ulRelativeId,
IN OUT PSID AccountSid 
)

Definition at line 303 of file domain.c.

306{
307 PSID DomainSid = NULL;
308 ULONG Length = 0;
310
311 Status = SampGetObjectAttribute(DomainObject,
312 L"SID",
313 NULL,
314 NULL,
315 &Length);
317 {
318 TRACE("Status 0x%08lx\n", Status);
319 goto done;
320 }
321
322 TRACE("Length: %lu\n", Length);
323
324 DomainSid = RtlAllocateHeap(RtlGetProcessHeap(), 0, Length);
325 if (DomainSid == NULL)
326 {
328 goto done;
329 }
330
331 Status = SampGetObjectAttribute(DomainObject,
332 L"SID",
333 NULL,
334 DomainSid,
335 &Length);
336 if (!NT_SUCCESS(Status))
337 {
338 TRACE("Status 0x%08lx\n", Status);
339 goto done;
340 }
341
342 *AccountSid = AppendRidToSid(DomainSid,
343 ulRelativeId);
344
345done:
346 if (DomainSid != NULL)
347 RtlFreeHeap(RtlGetProcessHeap(), 0, DomainSid);
348
349 return Status;
350}
static PSID AppendRidToSid(PSID SrcSid, ULONG Rid)
Definition: msv1_0.c:292
#define STATUS_BUFFER_OVERFLOW
Definition: shellext.h:66

Referenced by SamrCreateUser2InDomain(), and SamrCreateUserInDomain().

◆ SampCreateAliasSD()

NTSTATUS SampCreateAliasSD ( OUT PSECURITY_DESCRIPTOR AliasSd,
OUT PULONG  Size 
)

Definition at line 859 of file security.c.

861{
864 PSID EveryoneSid = NULL;
865 PSID AnonymousSid = NULL;
866 PSID AdministratorsSid = NULL;
867 PSID AccountOperatorsSid = NULL;
868 PACL Dacl = NULL;
869 PACL Sacl = NULL;
872 ULONG RelSDSize = 0;
874
875
876 /* Create the Everyone SID */
878 1,
880 0,
881 0,
882 0,
883 0,
884 0,
885 0,
886 0,
887 &EveryoneSid);
889 if (!NT_SUCCESS(Status))
890 goto done;
891
892 /* Create the Anonymous SID */
894 1,
896 0,
897 0,
898 0,
899 0,
900 0,
901 0,
902 0,
903 &AnonymousSid);
905 if (!NT_SUCCESS(Status))
906 goto done;
907
908 /* Create the Administrators SID */
910 2,
913 0,
914 0,
915 0,
916 0,
917 0,
918 0,
919 &AdministratorsSid);
921 if (!NT_SUCCESS(Status))
922 goto done;
923
924 /* Create the Account Operators SID */
926 2,
929 0,
930 0,
931 0,
932 0,
933 0,
934 0,
935 &AccountOperatorsSid);
937 if (!NT_SUCCESS(Status))
938 goto done;
939
940 /* Allocate a buffer for the absolute SD */
941 AbsSD = RtlAllocateHeap(RtlGetProcessHeap(),
943 sizeof(SECURITY_DESCRIPTOR));
944 if (AbsSD == NULL)
945 {
948 goto done;
949 }
950
951 /* Create the absolute SD */
955 if (!NT_SUCCESS(Status))
956 goto done;
957
958 /* allocate and create the DACL */
959 DaclSize = sizeof(ACL) +
960 3 * sizeof(ACE) +
961 RtlLengthSid(EveryoneSid) +
962 RtlLengthSid(AdministratorsSid) +
963 RtlLengthSid(AccountOperatorsSid);
964
965 Dacl = RtlAllocateHeap(RtlGetProcessHeap(),
967 DaclSize);
968 if (Dacl == NULL)
969 {
972 goto done;
973 }
974
976 DaclSize,
979 if (!NT_SUCCESS(Status))
980 goto done;
981
985 EveryoneSid);
987 if (!NT_SUCCESS(Status))
988 goto done;
989
993 AdministratorsSid);
995 if (!NT_SUCCESS(Status))
996 goto done;
997
1001 AccountOperatorsSid);
1003 if (!NT_SUCCESS(Status))
1004 goto done;
1005
1006 /* Set the DACL */
1008 TRUE,
1009 Dacl,
1010 FALSE);
1012 if (!NT_SUCCESS(Status))
1013 goto done;
1014
1015 /* allocate and create the SACL */
1016 SaclSize = sizeof(ACL) +
1017 2 * sizeof(ACE) +
1018 RtlLengthSid(EveryoneSid) +
1019 RtlLengthSid(AnonymousSid);
1020
1021 Sacl = RtlAllocateHeap(RtlGetProcessHeap(),
1023 DaclSize);
1024 if (Sacl == NULL)
1025 {
1028 goto done;
1029 }
1030
1032 SaclSize,
1033 ACL_REVISION);
1035 if (!NT_SUCCESS(Status))
1036 goto done;
1037
1043 EveryoneSid,
1044 TRUE,
1045 TRUE);
1047 if (!NT_SUCCESS(Status))
1048 goto done;
1049
1053 AnonymousSid,
1054 TRUE,
1055 TRUE);
1057 if (!NT_SUCCESS(Status))
1058 goto done;
1059
1060 /* Set the SACL */
1062 TRUE,
1063 Sacl,
1064 FALSE);
1066 if (!NT_SUCCESS(Status))
1067 goto done;
1068
1069 /* Set the owner SID */
1071 AdministratorsSid,
1072 FALSE);
1074 if (!NT_SUCCESS(Status))
1075 goto done;
1076
1077 /* Set the group SID */
1079 AdministratorsSid,
1080 FALSE);
1082 if (!NT_SUCCESS(Status))
1083 goto done;
1084
1085 /* Get the reqired buffer size for the self-relative SD */
1087 NULL,
1088 &RelSDSize);
1090 goto done;
1091
1092 /* Allocate a buffer for the self-relative SD */
1093 RelSD = RtlAllocateHeap(RtlGetProcessHeap(),
1095 RelSDSize);
1096 if (RelSD == NULL)
1097 {
1100 goto done;
1101 }
1102
1103 /* Convert the absolute SD to self-relative format */
1105 RelSD,
1106 &RelSDSize);
1108 {
1110 goto done;
1111 }
1112
1113 *AliasSd = RelSD;
1114 *Size = RelSDSize;
1115
1116done:
1117 if (!NT_SUCCESS(Status))
1118 {
1119 if (RelSD != NULL)
1120 RtlFreeHeap(RtlGetProcessHeap(), 0, RelSD);
1121 }
1122
1123 if (EveryoneSid != NULL)
1124 RtlFreeSid(EveryoneSid);
1125
1126 if (AnonymousSid != NULL)
1127 RtlFreeSid(AnonymousSid);
1128
1129 if (AdministratorsSid != NULL)
1130 RtlFreeSid(AdministratorsSid);
1131
1132 if (Dacl != NULL)
1133 RtlFreeHeap(RtlGetProcessHeap(), 0, Dacl);
1134
1135 if (Sacl != NULL)
1136 RtlFreeHeap(RtlGetProcessHeap(), 0, Sacl);
1137
1138 if (AbsSD != NULL)
1139 RtlFreeHeap(RtlGetProcessHeap(), 0, AbsSD);
1140
1141 return Status;
1142}
#define READ_CONTROL
Definition: nt_native.h:58
#define ALIAS_WRITE_ACCOUNT
Definition: ntsam.h:13
#define ALIAS_LIST_MEMBERS
Definition: ntsam.h:11
#define ALIAS_READ_INFORMATION
Definition: ntsam.h:12
#define ALIAS_REMOVE_MEMBER
Definition: ntsam.h:10
#define ALIAS_ALL_ACCESS
Definition: ntsam.h:26
#define ALIAS_ADD_MEMBER
Definition: ntsam.h:9
#define DOMAIN_ALIAS_RID_ACCOUNT_OPS
Definition: setypes.h:657

Referenced by SampSetupCreateAliasAccount(), and SamrCreateAliasInDomain().

◆ SampCreateBuiltinDomainSD()

NTSTATUS SampCreateBuiltinDomainSD ( OUT PSECURITY_DESCRIPTOR DomainSd,
OUT PULONG  Size 
)

Definition at line 283 of file security.c.

285{
288 PSID EveryoneSid = NULL;
289 PSID AnonymousSid = NULL;
290 PSID AdministratorsSid = NULL;
291 PACL Dacl = NULL;
292 PACL Sacl = NULL;
295 ULONG RelSDSize = 0;
297
298
299 /* Create the Everyone SID */
301 1,
303 0,
304 0,
305 0,
306 0,
307 0,
308 0,
309 0,
310 &EveryoneSid);
312 if (!NT_SUCCESS(Status))
313 goto done;
314
315 /* Create the Anonymous SID */
317 1,
319 0,
320 0,
321 0,
322 0,
323 0,
324 0,
325 0,
326 &AnonymousSid);
328 if (!NT_SUCCESS(Status))
329 goto done;
330
331 /* Create the Administrators SID */
333 2,
336 0,
337 0,
338 0,
339 0,
340 0,
341 0,
342 &AdministratorsSid);
344 if (!NT_SUCCESS(Status))
345 goto done;
346
347
348 /* Allocate a buffer for the absolute SD */
349 AbsSD = RtlAllocateHeap(RtlGetProcessHeap(),
351 sizeof(SECURITY_DESCRIPTOR));
352 if (AbsSD == NULL)
353 {
356 goto done;
357 }
358
359 /* Create the absolute SD */
363 if (!NT_SUCCESS(Status))
364 goto done;
365
366 /* allocate and create the DACL */
367 DaclSize = sizeof(ACL) +
368 2 * sizeof(ACE) +
369 RtlLengthSid(EveryoneSid) +
370 RtlLengthSid(AdministratorsSid);
371
372 Dacl = RtlAllocateHeap(RtlGetProcessHeap(),
374 DaclSize);
375 if (Dacl == NULL)
376 {
379 goto done;
380 }
381
383 DaclSize,
386 if (!NT_SUCCESS(Status))
387 goto done;
388
392 EveryoneSid);
394 if (!NT_SUCCESS(Status))
395 goto done;
396
400 AdministratorsSid);
402 if (!NT_SUCCESS(Status))
403 goto done;
404
405 /* Set the DACL */
407 TRUE,
408 Dacl,
409 FALSE);
411 if (!NT_SUCCESS(Status))
412 goto done;
413
414 /* allocate and create the SACL */
415 SaclSize = sizeof(ACL) +
416 2 * sizeof(ACE) +
417 RtlLengthSid(EveryoneSid) +
418 RtlLengthSid(AnonymousSid);
419
420 Sacl = RtlAllocateHeap(RtlGetProcessHeap(),
422 DaclSize);
423 if (Sacl == NULL)
424 {
427 goto done;
428 }
429
431 SaclSize,
434 if (!NT_SUCCESS(Status))
435 goto done;
436
442 EveryoneSid,
443 TRUE,
444 TRUE);
446 if (!NT_SUCCESS(Status))
447 goto done;
448
452 AnonymousSid,
453 TRUE,
454 TRUE);
456 if (!NT_SUCCESS(Status))
457 goto done;
458
459 /* Set the SACL */
461 TRUE,
462 Sacl,
463 FALSE);
465 if (!NT_SUCCESS(Status))
466 goto done;
467
468 /* Set the owner SID */
470 AdministratorsSid,
471 FALSE);
473 if (!NT_SUCCESS(Status))
474 goto done;
475
476 /* Set the group SID */
478 AdministratorsSid,
479 FALSE);
481 if (!NT_SUCCESS(Status))
482 goto done;
483
484 /* Get the reqired buffer size for the self-relative SD */
486 NULL,
487 &RelSDSize);
489 goto done;
490
491 /* Allocate a buffer for the self-relative SD */
492 RelSD = RtlAllocateHeap(RtlGetProcessHeap(),
494 RelSDSize);
495 if (RelSD == NULL)
496 {
499 goto done;
500 }
501
502 /* Convert the absolute SD to self-relative format */
504 RelSD,
505 &RelSDSize);
507 {
509 goto done;
510 }
511
512 *ServerSd = RelSD;
513 *Size = RelSDSize;
514
515done:
516 if (!NT_SUCCESS(Status))
517 {
518 if (RelSD != NULL)
519 RtlFreeHeap(RtlGetProcessHeap(), 0, RelSD);
520 }
521
522 if (EveryoneSid != NULL)
523 RtlFreeSid(EveryoneSid);
524
525 if (AnonymousSid != NULL)
526 RtlFreeSid(AnonymousSid);
527
528 if (AdministratorsSid != NULL)
529 RtlFreeSid(AdministratorsSid);
530
531 if (Dacl != NULL)
532 RtlFreeHeap(RtlGetProcessHeap(), 0, Dacl);
533
534 if (Sacl != NULL)
535 RtlFreeHeap(RtlGetProcessHeap(), 0, Sacl);
536
537 if (AbsSD != NULL)
538 RtlFreeHeap(RtlGetProcessHeap(), 0, AbsSD);
539
540 return Status;
541}
#define SAM_SERVER_ALL_ACCESS
Definition: ntsam.h:118

Referenced by SampSetupCreateDomain().

◆ SampCreateDbObject()

NTSTATUS SampCreateDbObject ( IN PSAM_DB_OBJECT  ParentObject,
IN LPWSTR  ContainerName,
IN LPWSTR  ObjectName,
IN ULONG  RelativeId,
IN SAM_DB_OBJECT_TYPE  ObjectType,
IN ACCESS_MASK  DesiredAccess,
OUT PSAM_DB_OBJECT DbObject 
)

Definition at line 44 of file database.c.

51{
53 HANDLE ParentKeyHandle;
54 HANDLE ContainerKeyHandle = NULL;
55 HANDLE ObjectKeyHandle = NULL;
56 HANDLE MembersKeyHandle = NULL;
58
59 if (DbObject == NULL)
61
62 *DbObject = NULL;
63
64 if (ParentObject == NULL)
65 ParentKeyHandle = SamKeyHandle;
66 else
67 ParentKeyHandle = ParentObject->KeyHandle;
68
69 if (ContainerName != NULL)
70 {
71 /* Open the container key */
72 Status = SampRegOpenKey(ParentKeyHandle,
73 ContainerName,
75 &ContainerKeyHandle);
76 if (!NT_SUCCESS(Status))
77 {
78 goto done;
79 }
80
81 /* Create the object key */
82 Status = SampRegCreateKey(ContainerKeyHandle,
85 &ObjectKeyHandle);
86 if (!NT_SUCCESS(Status))
87 {
88 goto done;
89 }
90
92 {
93 /* Create the object key */
94 Status = SampRegCreateKey(ContainerKeyHandle,
95 L"Members",
97 &MembersKeyHandle);
98 if (!NT_SUCCESS(Status))
99 {
100 goto done;
101 }
102 }
103 }
104 else
105 {
106 /* Create the object key */
107 Status = SampRegCreateKey(ParentKeyHandle,
110 &ObjectKeyHandle);
111 if (!NT_SUCCESS(Status))
112 {
113 goto done;
114 }
115 }
116
117 NewObject = RtlAllocateHeap(RtlGetProcessHeap(),
119 sizeof(SAM_DB_OBJECT));
120 if (NewObject == NULL)
121 {
123 goto done;
124 }
125
126 NewObject->Name = RtlAllocateHeap(RtlGetProcessHeap(),
127 0,
128 (wcslen(ObjectName) + 1) * sizeof(WCHAR));
129 if (NewObject->Name == NULL)
130 {
132 goto done;
133 }
134
136
137 NewObject->Signature = SAMP_DB_SIGNATURE;
138 NewObject->RefCount = 1;
139 NewObject->ObjectType = ObjectType;
140 NewObject->Access = DesiredAccess;
141 NewObject->KeyHandle = ObjectKeyHandle;
142 NewObject->MembersKeyHandle = MembersKeyHandle;
143 NewObject->RelativeId = RelativeId;
144 NewObject->ParentObject = ParentObject;
145
146 if (ParentObject != NULL)
147 NewObject->Trusted = ParentObject->Trusted;
148
149 *DbObject = NewObject;
150
151done:
152 if (!NT_SUCCESS(Status))
153 {
154 if (NewObject != NULL)
155 {
156 if (NewObject->Name != NULL)
157 RtlFreeHeap(RtlGetProcessHeap(), 0, NewObject->Name);
158
159 RtlFreeHeap(RtlGetProcessHeap(), 0, NewObject);
160 }
161
162 SampRegCloseKey(&MembersKeyHandle);
163 SampRegCloseKey(&ObjectKeyHandle);
164 }
165
166 SampRegCloseKey(&ContainerKeyHandle);
167
168 return Status;
169}
static HANDLE SamKeyHandle
Definition: database.c:15
#define SAMP_DB_SIGNATURE
Definition: samsrv.h:59
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
ObjectType
Definition: metafile.c:81
#define KEY_ALL_ACCESS
Definition: nt_native.h:1041
_CRTIMP wchar_t *__cdecl wcscpy(_Out_writes_z_(_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
_Must_inspect_result_ _In_ WDFDEVICE _In_ ULONG _In_ ACCESS_MASK DesiredAccess
Definition: wdfdevice.h:2658
_In_ PVOID _Out_opt_ PULONG_PTR _Outptr_opt_ PCUNICODE_STRING * ObjectName
Definition: cmfuncs.h:64
_Inout_opt_ PACCESS_STATE _In_opt_ ACCESS_MASK _In_ ULONG _Out_opt_ PVOID * NewObject
Definition: obfuncs.h:74

Referenced by SamrCreateAliasInDomain(), SamrCreateGroupInDomain(), SamrCreateUser2InDomain(), and SamrCreateUserInDomain().

◆ SampCreateGroupSD()

NTSTATUS SampCreateGroupSD ( OUT PSECURITY_DESCRIPTOR GroupSd,
OUT PULONG  Size 
)

Definition at line 1146 of file security.c.

1148{
1149 PSECURITY_DESCRIPTOR AbsSD = NULL;
1150 PSECURITY_DESCRIPTOR RelSD = NULL;
1151 PSID EveryoneSid = NULL;
1152 PSID AnonymousSid = NULL;
1153 PSID AdministratorsSid = NULL;
1154 PSID AccountOperatorsSid = NULL;
1155 PACL Dacl = NULL;
1156 PACL Sacl = NULL;
1159 ULONG RelSDSize = 0;
1161
1162
1163 /* Create the Everyone SID */
1165 1,
1167 0,
1168 0,
1169 0,
1170 0,
1171 0,
1172 0,
1173 0,
1174 &EveryoneSid);
1176 if (!NT_SUCCESS(Status))
1177 goto done;
1178
1179 /* Create the Anonymous SID */
1181 1,
1183 0,
1184 0,
1185 0,
1186 0,
1187 0,
1188 0,
1189 0,
1190 &AnonymousSid);
1192 if (!NT_SUCCESS(Status))
1193 goto done;
1194
1195 /* Create the Administrators SID */
1197 2,
1200 0,
1201 0,
1202 0,
1203 0,
1204 0,
1205 0,
1206 &AdministratorsSid);
1208 if (!NT_SUCCESS(Status))
1209 goto done;
1210
1211 /* Create the Account Operators SID */
1213 2,
1216 0,
1217 0,
1218 0,
1219 0,
1220 0,
1221 0,
1222 &AccountOperatorsSid);
1224 if (!NT_SUCCESS(Status))
1225 goto done;
1226
1227 /* Allocate a buffer for the absolute SD */
1228 AbsSD = RtlAllocateHeap(RtlGetProcessHeap(),
1230 sizeof(SECURITY_DESCRIPTOR));
1231 if (AbsSD == NULL)
1232 {
1235 goto done;
1236 }
1237
1238 /* Create the absolute SD */
1242 if (!NT_SUCCESS(Status))
1243 goto done;
1244
1245 /* allocate and create the DACL */
1246 DaclSize = sizeof(ACL) +
1247 3 * sizeof(ACE) +
1248 RtlLengthSid(EveryoneSid) +
1249 RtlLengthSid(AdministratorsSid) +
1250 RtlLengthSid(AccountOperatorsSid);
1251
1252 Dacl = RtlAllocateHeap(RtlGetProcessHeap(),
1254 DaclSize);
1255 if (Dacl == NULL)
1256 {
1259 goto done;
1260 }
1261
1263 DaclSize,
1264 ACL_REVISION);
1266 if (!NT_SUCCESS(Status))
1267 goto done;
1268
1272 EveryoneSid);
1274 if (!NT_SUCCESS(Status))
1275 goto done;
1276
1280 AdministratorsSid);
1282 if (!NT_SUCCESS(Status))
1283 goto done;
1284
1288 AccountOperatorsSid);
1290 if (!NT_SUCCESS(Status))
1291 goto done;
1292
1293 /* Set the DACL */
1295 TRUE,
1296 Dacl,
1297 FALSE);
1299 if (!NT_SUCCESS(Status))
1300 goto done;
1301
1302 /* allocate and create the SACL */
1303 SaclSize = sizeof(ACL) +
1304 2 * sizeof(ACE) +
1305 RtlLengthSid(EveryoneSid) +
1306 RtlLengthSid(AnonymousSid);
1307
1308 Sacl = RtlAllocateHeap(RtlGetProcessHeap(),
1310 DaclSize);
1311 if (Sacl == NULL)
1312 {
1315 goto done;
1316 }
1317
1319 SaclSize,
1320 ACL_REVISION);
1322 if (!NT_SUCCESS(Status))
1323 goto done;
1324
1330 EveryoneSid,
1331 TRUE,
1332 TRUE);
1334 if (!NT_SUCCESS(Status))
1335 goto done;
1336
1340 AnonymousSid,
1341 TRUE,
1342 TRUE);
1344 if (!NT_SUCCESS(Status))
1345 goto done;
1346
1347 /* Set the SACL */
1349 TRUE,
1350 Sacl,
1351 FALSE);
1353 if (!NT_SUCCESS(Status))
1354 goto done;
1355
1356 /* Set the owner SID */
1358 AdministratorsSid,
1359 FALSE);
1361 if (!NT_SUCCESS(Status))
1362 goto done;
1363
1364 /* Set the group SID */
1366 AdministratorsSid,
1367 FALSE);
1369 if (!NT_SUCCESS(Status))
1370 goto done;
1371
1372 /* Get the reqired buffer size for the self-relative SD */
1374 NULL,
1375 &RelSDSize);
1377 goto done;
1378
1379 /* Allocate a buffer for the self-relative SD */
1380 RelSD = RtlAllocateHeap(RtlGetProcessHeap(),
1382 RelSDSize);
1383 if (RelSD == NULL)
1384 {
1387 goto done;
1388 }
1389
1390 /* Convert the absolute SD to self-relative format */
1392 RelSD,
1393 &RelSDSize);
1395 {
1397 goto done;
1398 }
1399
1400 *GroupSd = RelSD;
1401 *Size = RelSDSize;
1402
1403done:
1404 if (!NT_SUCCESS(Status))
1405 {
1406 if (RelSD != NULL)
1407 RtlFreeHeap(RtlGetProcessHeap(), 0, RelSD);
1408 }
1409
1410 if (EveryoneSid != NULL)
1411 RtlFreeSid(EveryoneSid);
1412
1413 if (AnonymousSid != NULL)
1414 RtlFreeSid(AnonymousSid);
1415
1416 if (AdministratorsSid != NULL)
1417 RtlFreeSid(AdministratorsSid);
1418
1419 if (Dacl != NULL)
1420 RtlFreeHeap(RtlGetProcessHeap(), 0, Dacl);
1421
1422 if (Sacl != NULL)
1423 RtlFreeHeap(RtlGetProcessHeap(), 0, Sacl);
1424
1425 if (AbsSD != NULL)
1426 RtlFreeHeap(RtlGetProcessHeap(), 0, AbsSD);
1427
1428 return Status;
1429}
#define GROUP_ALL_ACCESS
Definition: ntsam.h:92
#define GROUP_READ_INFORMATION
Definition: ntsam.h:75
#define GROUP_ADD_MEMBER
Definition: ntsam.h:77
#define GROUP_LIST_MEMBERS
Definition: ntsam.h:79
#define GROUP_WRITE_ACCOUNT
Definition: ntsam.h:76
#define GROUP_REMOVE_MEMBER
Definition: ntsam.h:78

Referenced by SampSetupCreateGroupAccount(), and SamrCreateGroupInDomain().

◆ SampCreateServerSD()

NTSTATUS SampCreateServerSD ( OUT PSECURITY_DESCRIPTOR ServerSd,
OUT PULONG  Size 
)

Definition at line 21 of file security.c.

23{
26 PSID EveryoneSid = NULL;
27 PSID AnonymousSid = NULL;
28 PSID AdministratorsSid = NULL;
29 PACL Dacl = NULL;
30 PACL Sacl = NULL;
33 ULONG RelSDSize = 0;
35
36
37 /* Create the Everyone SID */
39 1,
41 0,
42 0,
43 0,
44 0,
45 0,
46 0,
47 0,
48 &EveryoneSid);
50 if (!NT_SUCCESS(Status))
51 goto done;
52
53 /* Create the Anonymous SID */
55 1,
57 0,
58 0,
59 0,
60 0,
61 0,
62 0,
63 0,
64 &AnonymousSid);
66 if (!NT_SUCCESS(Status))
67 goto done;
68
69 /* Create the Administrators SID */
71 2,
74 0,
75 0,
76 0,
77 0,
78 0,
79 0,
80 &AdministratorsSid);
82 if (!NT_SUCCESS(Status))
83 goto done;
84
85
86 /* Allocate a buffer for the absolute SD */
87 AbsSD = RtlAllocateHeap(RtlGetProcessHeap(),
89 sizeof(SECURITY_DESCRIPTOR));
90 if (AbsSD == NULL)
91 {
94 goto done;
95 }
96
97 /* Create the absolute SD */
101 if (!NT_SUCCESS(Status))
102 goto done;
103
104 /* allocate and create the DACL */
105 DaclSize = sizeof(ACL) +
106 2 * sizeof(ACE) +
107 RtlLengthSid(EveryoneSid) +
108 RtlLengthSid(AdministratorsSid);
109
110 Dacl = RtlAllocateHeap(RtlGetProcessHeap(),
112 DaclSize);
113 if (Dacl == NULL)
114 {
117 goto done;
118 }
119
121 DaclSize,
124 if (!NT_SUCCESS(Status))
125 goto done;
126
130 EveryoneSid);
132 if (!NT_SUCCESS(Status))
133 goto done;
134
138 AdministratorsSid);
140 if (!NT_SUCCESS(Status))
141 goto done;
142
143 /* Set the DACL */
145 TRUE,
146 Dacl,
147 FALSE);
149 if (!NT_SUCCESS(Status))
150 goto done;
151
152 /* allocate and create the SACL */
153 SaclSize = sizeof(ACL) +
154 2 * sizeof(ACE) +
155 RtlLengthSid(EveryoneSid) +
156 RtlLengthSid(AnonymousSid);
157
158 Sacl = RtlAllocateHeap(RtlGetProcessHeap(),
160 DaclSize);
161 if (Sacl == NULL)
162 {
165 goto done;
166 }
167
169 SaclSize,
172 if (!NT_SUCCESS(Status))
173 goto done;
174
180 EveryoneSid,
181 TRUE,
182 TRUE);
184 if (!NT_SUCCESS(Status))
185 goto done;
186
190 AnonymousSid,
191 TRUE,
192 TRUE);
194 if (!NT_SUCCESS(Status))
195 goto done;
196
197 /* Set the SACL */
199 TRUE,
200 Sacl,
201 FALSE);
203 if (!NT_SUCCESS(Status))
204 goto done;
205
206 /* Set the owner SID */
208 AdministratorsSid,
209 FALSE);
211 if (!NT_SUCCESS(Status))
212 goto done;
213
214 /* Set the group SID */
216 AdministratorsSid,
217 FALSE);
219 if (!NT_SUCCESS(Status))
220 goto done;
221
222 /* Get the reqired buffer size for the self-relative SD */
224 NULL,
225 &RelSDSize);
227 goto done;
228
229 /* Allocate a buffer for the self-relative SD */
230 RelSD = RtlAllocateHeap(RtlGetProcessHeap(),
232 RelSDSize);
233 if (RelSD == NULL)
234 {
237 goto done;
238 }
239
240 /* Convert the absolute SD to self-relative format */
242 RelSD,
243 &RelSDSize);
245 {
247 goto done;
248 }
249
250 *ServerSd = RelSD;
251 *Size = RelSDSize;
252
253done:
254 if (!NT_SUCCESS(Status))
255 {
256 if (RelSD != NULL)
257 RtlFreeHeap(RtlGetProcessHeap(), 0, RelSD);
258 }
259
260 if (EveryoneSid != NULL)
261 RtlFreeSid(EveryoneSid);
262
263 if (AnonymousSid != NULL)
264 RtlFreeSid(AnonymousSid);
265
266 if (AdministratorsSid != NULL)
267 RtlFreeSid(AdministratorsSid);
268
269 if (Dacl != NULL)
270 RtlFreeHeap(RtlGetProcessHeap(), 0, Dacl);
271
272 if (Sacl != NULL)
273 RtlFreeHeap(RtlGetProcessHeap(), 0, Sacl);
274
275 if (AbsSD != NULL)
276 RtlFreeHeap(RtlGetProcessHeap(), 0, AbsSD);
277
278 return Status;
279}
#define SAM_SERVER_READ
Definition: ntsam.h:106
#define SAM_SERVER_EXECUTE
Definition: ntsam.h:114

Referenced by SampSetupCreateServer().

◆ SampCreateUserSD()

NTSTATUS SampCreateUserSD ( IN PSID  UserSid,
OUT PSECURITY_DESCRIPTOR UserSd,
OUT PULONG  Size 
)

Definition at line 1433 of file security.c.

1436{
1437 PSECURITY_DESCRIPTOR AbsSD = NULL;
1438 PSECURITY_DESCRIPTOR RelSD = NULL;
1439 PSID EveryoneSid = NULL;
1440 PSID AnonymousSid = NULL;
1441 PSID AdministratorsSid = NULL;
1442 PACL Dacl = NULL;
1443 PACL Sacl = NULL;
1446 ULONG RelSDSize = 0;
1448
1449
1450 /* Create the Everyone SID */
1452 1,
1454 0,
1455 0,
1456 0,
1457 0,
1458 0,
1459 0,
1460 0,
1461 &EveryoneSid);
1463 if (!NT_SUCCESS(Status))
1464 goto done;
1465
1466 /* Create the Anonymous SID */
1468 1,
1470 0,
1471 0,
1472 0,
1473 0,
1474 0,
1475 0,
1476 0,
1477 &AnonymousSid);
1479 if (!NT_SUCCESS(Status))
1480 goto done;
1481
1482 /* Create the Administrators SID */
1484 2,
1487 0,
1488 0,
1489 0,
1490 0,
1491 0,
1492 0,
1493 &AdministratorsSid);
1495 if (!NT_SUCCESS(Status))
1496 goto done;
1497
1498 /* Allocate a buffer for the absolute SD */
1499 AbsSD = RtlAllocateHeap(RtlGetProcessHeap(),
1501 sizeof(SECURITY_DESCRIPTOR));
1502 if (AbsSD == NULL)
1503 {
1506 goto done;
1507 }
1508
1509 /* Create the absolute SD */
1513 if (!NT_SUCCESS(Status))
1514 goto done;
1515
1516 /* allocate and create the DACL */
1517 DaclSize = sizeof(ACL) +
1518 3 * sizeof(ACE) +
1519 RtlLengthSid(EveryoneSid) +
1520 RtlLengthSid(AdministratorsSid) +
1521 RtlLengthSid(UserSid);
1522
1523 Dacl = RtlAllocateHeap(RtlGetProcessHeap(),
1525 DaclSize);
1526 if (Dacl == NULL)
1527 {
1530 goto done;
1531 }
1532
1534 DaclSize,
1535 ACL_REVISION);
1537 if (!NT_SUCCESS(Status))
1538 goto done;
1539
1545 EveryoneSid);
1547 if (!NT_SUCCESS(Status))
1548 goto done;
1549
1553 AdministratorsSid);
1555 if (!NT_SUCCESS(Status))
1556 goto done;
1557
1561 UserSid);
1563 if (!NT_SUCCESS(Status))
1564 goto done;
1565
1566 /* Set the DACL */
1568 TRUE,
1569 Dacl,
1570 FALSE);
1572 if (!NT_SUCCESS(Status))
1573 goto done;
1574
1575 /* allocate and create the SACL */
1576 SaclSize = sizeof(ACL) +
1577 2 * sizeof(ACE) +
1578 RtlLengthSid(EveryoneSid) +
1579 RtlLengthSid(AnonymousSid);
1580
1581 Sacl = RtlAllocateHeap(RtlGetProcessHeap(),
1583 DaclSize);
1584 if (Sacl == NULL)
1585 {
1588 goto done;
1589 }
1590
1592 SaclSize,
1593 ACL_REVISION);
1595 if (!NT_SUCCESS(Status))
1596 goto done;
1597
1602 EveryoneSid,
1603 TRUE,
1604 TRUE);
1606 if (!NT_SUCCESS(Status))
1607 goto done;
1608
1612 AnonymousSid,
1613 TRUE,
1614 TRUE);
1616 if (!NT_SUCCESS(Status))
1617 goto done;
1618
1619 /* Set the SACL */
1621 TRUE,
1622 Sacl,
1623 FALSE);
1625 if (!NT_SUCCESS(Status))
1626 goto done;
1627
1628 /* Set the owner SID */
1630 AdministratorsSid,
1631 FALSE);
1633 if (!NT_SUCCESS(Status))
1634 goto done;
1635
1636 /* Set the group SID */
1638 AdministratorsSid,
1639 FALSE);
1641 if (!NT_SUCCESS(Status))
1642 goto done;
1643
1644 /* Get the reqired buffer size for the self-relative SD */
1646 NULL,
1647 &RelSDSize);
1649 goto done;
1650
1651 /* Allocate a buffer for the self-relative SD */
1652 RelSD = RtlAllocateHeap(RtlGetProcessHeap(),
1654 RelSDSize);
1655 if (RelSD == NULL)
1656 {
1659 goto done;
1660 }
1661
1662 /* Convert the absolute SD to self-relative format */
1664 RelSD,
1665 &RelSDSize);
1667 {
1669 goto done;
1670 }
1671
1672 *UserSd = RelSD;
1673 *Size = RelSDSize;
1674
1675done:
1676 if (!NT_SUCCESS(Status))
1677 {
1678 if (RelSD != NULL)
1679 RtlFreeHeap(RtlGetProcessHeap(), 0, RelSD);
1680 }
1681
1682 if (EveryoneSid != NULL)
1683 RtlFreeSid(EveryoneSid);
1684
1685 if (AnonymousSid != NULL)
1686 RtlFreeSid(AnonymousSid);
1687
1688 if (AdministratorsSid != NULL)
1689 RtlFreeSid(AdministratorsSid);
1690
1691 if (Dacl != NULL)
1692 RtlFreeHeap(RtlGetProcessHeap(), 0, Dacl);
1693
1694 if (Sacl != NULL)
1695 RtlFreeHeap(RtlGetProcessHeap(), 0, Sacl);
1696
1697 if (AbsSD != NULL)
1698 RtlFreeHeap(RtlGetProcessHeap(), 0, AbsSD);
1699
1700 return Status;
1701}
#define USER_READ_GENERAL
Definition: ntsam.h:126
#define USER_READ_LOGON
Definition: ntsam.h:129
#define USER_READ_PREFERENCES
Definition: ntsam.h:127
#define USER_READ_ACCOUNT
Definition: ntsam.h:130
#define USER_LIST_GROUPS
Definition: ntsam.h:134
#define USER_WRITE_PREFERENCES
Definition: ntsam.h:128
#define USER_ALL_ACCESS
Definition: ntsam.h:153
#define USER_CHANGE_PASSWORD
Definition: ntsam.h:132
#define USER_READ_GROUP_INFORMATION
Definition: ntsam.h:135

Referenced by SampSetupCreateUserAccount(), SamrCreateUser2InDomain(), and SamrCreateUserInDomain().

◆ SampDeleteAccountDbObject()

NTSTATUS SampDeleteAccountDbObject ( PSAM_DB_OBJECT  DbObject)

Definition at line 368 of file database.c.

369{
370 LPCWSTR ContainerName;
371 LPWSTR AccountName = NULL;
372 HANDLE ContainerKey = NULL;
373 HANDLE NamesKey = NULL;
374 ULONG Length = 0;
376
377 TRACE("(%p)\n", DbObject);
378
379 /* Server and Domain objects cannot be deleted */
380 switch (DbObject->ObjectType)
381 {
382 case SamDbAliasObject:
383 ContainerName = L"Aliases";
384 break;
385
386 case SamDbGroupObject:
387 ContainerName = L"Groups";
388 break;
389
390 case SamDbUserObject:
391 ContainerName = L"Users";
392 break;
393
394 default:
396 }
397
398 /* Get the account name */
400 L"Name",
401 NULL,
402 NULL,
403 &Length);
405 {
406 TRACE("SampGetObjectAttribute failed (Status 0x%08lx)\n", Status);
407 goto done;
408 }
409
410 AccountName = RtlAllocateHeap(RtlGetProcessHeap(),
412 Length);
413 if (AccountName == NULL)
414 {
416 goto done;
417 }
418
420 L"Name",
421 NULL,
422 (PVOID)AccountName,
423 &Length);
424 if (!NT_SUCCESS(Status))
425 {
426 TRACE("SampGetObjectAttribute failed (Status 0x%08lx)\n", Status);
427 goto done;
428 }
429
430 SampRegCloseKey(&DbObject->KeyHandle);
431
432 if (DbObject->ObjectType == SamDbAliasObject)
433 {
435
436 SampRegDeleteKey(DbObject->KeyHandle,
437 L"Members");
438 }
439
440 /* Open the domain container key */
441 Status = SampRegOpenKey(DbObject->ParentObject->KeyHandle,
442 ContainerName,
444 &ContainerKey);
445 if (!NT_SUCCESS(Status))
446 {
447 TRACE("SampRegOpenKey failed (Status 0x%08lx)\n", Status);
448 goto done;
449 }
450
451 /* Open the Names key */
452 Status = SampRegOpenKey(ContainerKey,
453 L"Names",
455 &NamesKey);
456 if (!NT_SUCCESS(Status))
457 {
458 TRACE("SampRegOpenKey failed (Status 0x%08lx)\n", Status);
459 goto done;
460 }
461
462 /* Remove the account from the Names key */
463 Status = SampRegDeleteValue(NamesKey,
464 AccountName);
465 if (!NT_SUCCESS(Status))
466 {
467 TRACE("SampRegDeleteValue failed (Status 0x%08lx)\n", Status);
468 goto done;
469 }
470
471 /* Remove the account key from the container */
472 Status = SampRegDeleteKey(ContainerKey,
473 DbObject->Name);
474 if (!NT_SUCCESS(Status))
475 {
476 TRACE("SampRegDeleteKey failed (Status 0x%08lx)\n", Status);
477 goto done;
478 }
479
480 /* Release the database object name */
481 if (DbObject->Name != NULL)
482 RtlFreeHeap(RtlGetProcessHeap(), 0, DbObject->Name);
483
484 /* Release the database object */
485 RtlFreeHeap(RtlGetProcessHeap(), 0, DbObject);
486
488
489done:
490 SampRegCloseKey(&NamesKey);
491 SampRegCloseKey(&ContainerKey);
492
493 if (AccountName != NULL)
494 RtlFreeHeap(RtlGetProcessHeap(), 0, AccountName);
495
496 return Status;
497}
NTSTATUS SampRegDeleteKey(IN HANDLE ParentKeyHandle, IN LPCWSTR KeyName)
Definition: registry.c:71
NTSTATUS SampRegDeleteValue(IN HANDLE KeyHandle, IN LPCWSTR ValueName)
Definition: registry.c:212
#define KEY_SET_VALUE
Definition: nt_native.h:1017
SAM_DB_OBJECT_TYPE ObjectType
Definition: samsrv.h:48
struct _SAM_DB_OBJECT * ParentObject
Definition: samsrv.h:56
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185

Referenced by SamrDeleteAlias(), SamrDeleteGroup(), and SamrDeleteUser().

◆ SampFillDisplayCache()

NTSTATUS SampFillDisplayCache ( _In_ PSAM_DB_OBJECT  DomainObject,
_In_ DOMAIN_DISPLAY_INFORMATION  DisplayInformationClass 
)

Definition at line 172 of file display.c.

175{
177
178 TRACE("SampFillDisplayCache()\n");
179
180 switch (DisplayInformationClass)
181 {
183 Status = SampFillUserDisplayCache(DomainObject);
184 break;
185/*
186 case DomainDisplayMachine:
187 Status = SampFillMachineDisplayCache(DomainObject);
188 break;
189
190 case DomainDisplayGroup:
191 Status = SampFillGroupDisplayCache(DomainObject);
192 break;
193*/
194 default:
196 break;
197 }
198
199 return Status;
200}
static NTSTATUS SampFillUserDisplayCache(_In_ PSAM_DB_OBJECT DomainObject)
Definition: display.c:36
@ DomainDisplayUser
Definition: ntsam.h:303
#define STATUS_INVALID_INFO_CLASS
Definition: ntstatus.h:240

Referenced by SamrQueryDisplayInformation3().

◆ SampGetLogonHoursAttribute()

NTSTATUS SampGetLogonHoursAttribute ( IN PSAM_DB_OBJECT  UserObject,
IN OUT PSAMPR_LOGON_HOURS  LogonHours 
)

Definition at line 619 of file user.c.

621{
622 PUCHAR RawBuffer = NULL;
623 ULONG Length = 0;
626
627 Status = SampGetObjectAttribute(UserObject,
628 L"LogonHours",
629 NULL,
630 NULL,
631 &Length);
633 {
634 TRACE("SampGetObjectAttribute failed (Status 0x%08lx)\n", Status);
635 return Status;
636 }
637
639
640 if (Length == 0)
641 {
642 LogonHours->UnitsPerWeek = 0;
643 LogonHours->LogonHours = NULL;
644 }
645 else
646 {
647 RawBuffer = midl_user_allocate(Length);
648 if (RawBuffer == NULL)
649 {
651 goto done;
652 }
653
654 Status = SampGetObjectAttribute(UserObject,
655 L"LogonHours",
656 NULL,
657 (PVOID)RawBuffer,
658 &Length);
659 if (!NT_SUCCESS(Status))
660 goto done;
661
662 LogonHours->UnitsPerWeek = *((PUSHORT)RawBuffer);
663
664 BufferLength = (((ULONG)LogonHours->UnitsPerWeek) + 7) / 8;
665
666 LogonHours->LogonHours = midl_user_allocate(BufferLength);
667 if (LogonHours->LogonHours == NULL)
668 {
669 TRACE("Failed to allocate LogonHours buffer!\n");
671 goto done;
672 }
673
674 memcpy(LogonHours->LogonHours,
675 &(RawBuffer[2]),
677 }
678
679done:
680
681 if (RawBuffer != NULL)
682 midl_user_free(RawBuffer);
683
684 return Status;
685}
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
uint16_t * PUSHORT
Definition: typedefs.h:56
unsigned char * PUCHAR
Definition: typedefs.h:53
_Must_inspect_result_ _In_ WDFDEVICE _In_ DEVICE_REGISTRY_PROPERTY _In_ ULONG BufferLength
Definition: wdfdevice.h:3771

Referenced by SampQueryUserAccount(), SampQueryUserAll(), SampQueryUserLogon(), and SampQueryUserLogonHours().

◆ SampGetMembersInAlias()

NTSTATUS SampGetMembersInAlias ( IN PSAM_DB_OBJECT  AliasObject,
OUT PULONG  MemberCount,
OUT PSAMPR_SID_INFORMATION MemberArray 
)

Definition at line 218 of file alias.c.

221{
222 HANDLE MembersKeyHandle = NULL;
224 ULONG Count = 0;
226 ULONG Index;
228
229 /* Open the members key of the alias object */
230 Status = SampRegOpenKey(AliasObject->KeyHandle,
231 L"Members",
232 KEY_READ,
233 &MembersKeyHandle);
234 if (!NT_SUCCESS(Status))
235 {
236 ERR("SampRegOpenKey failed with status 0x%08lx\n", Status);
237 goto done;
238 }
239
240 /* Get the number of members */
241 Status = SampRegQueryKeyInfo(MembersKeyHandle,
242 NULL,
243 &Count);
244 if (!NT_SUCCESS(Status))
245 {
246 ERR("SampRegQueryKeyInfo failed with status 0x%08lx\n", Status);
247 goto done;
248 }
249
250 /* Allocate the member array */
252 if (Members == NULL)
253 {
255 goto done;
256 }
257
258 /* Enumerate the members */
259 Index = 0;
260 while (TRUE)
261 {
262 /* Get the size of the next SID */
263 DataLength = 0;
264 Status = SampRegEnumerateValue(MembersKeyHandle,
265 Index,
266 NULL,
267 NULL,
268 NULL,
269 NULL,
270 &DataLength);
271 if (!NT_SUCCESS(Status))
272 {
275 break;
276 }
277
278 /* Allocate a buffer for the SID */
280 if (Members[Index].SidPointer == NULL)
281 {
283 goto done;
284 }
285
286 /* Read the SID into the buffer */
287 Status = SampRegEnumerateValue(MembersKeyHandle,
288 Index,
289 NULL,
290 NULL,
291 NULL,
292 (PVOID)Members[Index].SidPointer,
293 &DataLength);
294 if (!NT_SUCCESS(Status))
295 {
296 goto done;
297 }
298
299 Index++;
300 }
301
302 if (NT_SUCCESS(Status))
303 {
304 *MemberCount = Count;
305 *MemberArray = Members;
306 }
307
308done:
309 return Status;
310}
#define ERR(fmt,...)
Definition: precomp.h:57
_In_ ULONG _In_opt_ WDFREQUEST _In_opt_ PVOID _In_ size_t _In_ PVOID _In_ size_t _Out_ size_t * DataLength
Definition: cdrom.h:1444
NTSTATUS SampRegEnumerateValue(IN HANDLE KeyHandle, IN ULONG Index, OUT LPWSTR Name, IN OUT PULONG NameLength, OUT PULONG Type OPTIONAL, OUT PVOID Data OPTIONAL, IN OUT PULONG DataLength OPTIONAL)
Definition: registry.c:226
NTSTATUS SampRegQueryKeyInfo(IN HANDLE KeyHandle, OUT PULONG SubKeyCount, OUT PULONG ValueCount)
Definition: registry.c:181
int Count
Definition: noreturn.cpp:7
#define STATUS_NO_MORE_ENTRIES
Definition: ntstatus.h:205
_In_ WDFCOLLECTION _In_ ULONG Index

Referenced by SampRemoveAllMembersFromAlias(), and SamrGetMembersInAlias().

◆ SampGetObjectAttribute()

NTSTATUS SampGetObjectAttribute ( PSAM_DB_OBJECT  DbObject,
LPWSTR  AttributeName,
PULONG  AttributeType,
LPVOID  AttributeData,
PULONG  AttributeSize 
)

Definition at line 516 of file database.c.

521{
522 return SampRegQueryValue(DbObject->KeyHandle,
523 AttributeName,
524 AttributeType,
526 AttributeSize);
527}
@ AttributeData
Definition: ntfs.h:168

Referenced by SampAddGroupMembershipToUser(), SampAddMemberToGroup(), SampCreateAccountSid(), SampDeleteAccountDbObject(), SampFillUserDisplayCache(), SampGetLogonHoursAttribute(), SampGetObjectAttributeString(), SampGetUserGroupAttributes(), SampQueryDomainGeneral(), SampQueryDomainGeneral2(), SampQueryDomainLockout(), SampQueryDomainLogoff(), SampQueryDomainModified(), SampQueryDomainModified2(), SampQueryDomainPassword(), SampQueryDomainServerRole(), SampQueryDomainState(), SampQueryGroupAttribute(), SampQueryGroupGeneral(), SampQueryUserAccount(), SampQueryUserAll(), SampQueryUserControl(), SampQueryUserExpires(), SampQueryUserGeneral(), SampQueryUserInternal1(), SampQueryUserInternal2(), SampQueryUserLogon(), SampQueryUserPreferences(), SampQueryUserPrimaryGroup(), SampRemoveGroupMembershipFromUser(), SampRemoveMemberFromGroup(), SampRemoveUserFromAllGroups(), SampSetDomainLockout(), SampSetDomainLogoff(), SampSetDomainPassword(), SampSetDomainServerRole(), SampSetDomainState(), SampSetGroupAttribute(), SampSetUserAll(), SampSetUserControl(), SampSetUserExpires(), SampSetUserGeneral(), SampSetUserGroupAttributes(), SampSetUserInternal1(), SampSetUserInternal2(), SampSetUserPassword(), SampSetUserPreferences(), SampSetUserPrimaryGroup(), SamrChangePasswordUser(), SamrCreateAliasInDomain(), SamrCreateGroupInDomain(), SamrCreateUser2InDomain(), SamrCreateUserInDomain(), SamrDeleteGroup(), SamrGetDomainPasswordInformation(), SamrGetGroupsForUser(), SamrGetMembersInGroup(), SamrGetUserDomainPasswordInformation(), SamrQuerySecurityObject(), and SamrSetSecurityObject().

◆ SampGetObjectAttributeString()

NTSTATUS SampGetObjectAttributeString ( PSAM_DB_OBJECT  DbObject,
LPWSTR  AttributeName,
PRPC_UNICODE_STRING  String 
)

Definition at line 531 of file database.c.

534{
535 ULONG Length = 0;
537
539 AttributeName,
540 NULL,
541 NULL,
542 &Length);
544 {
545 TRACE("Status 0x%08lx\n", Status);
546 goto done;
547 }
548
549 if (Length == 0)
550 {
551 String->Length = 0;
552 String->MaximumLength = 0;
553 String->Buffer = NULL;
554
556 goto done;
557 }
558
559 String->Length = (USHORT)(Length - sizeof(WCHAR));
560 String->MaximumLength = (USHORT)Length;
562 if (String->Buffer == NULL)
563 {
565 goto done;
566 }
567
568 TRACE("Length: %lu\n", Length);
570 AttributeName,
571 NULL,
572 (PVOID)String->Buffer,
573 &Length);
574 if (!NT_SUCCESS(Status))
575 {
576 TRACE("Status 0x%08lx\n", Status);
577 goto done;
578 }
579
580done:
581 if (!NT_SUCCESS(Status))
582 {
583 if (String->Buffer != NULL)
584 {
585 midl_user_free(String->Buffer);
586 String->Buffer = NULL;
587 }
588 }
589
590 return Status;
591}
unsigned short USHORT
Definition: pedump.c:61
_Must_inspect_result_ _In_ WDFDEVICE _In_ WDFSTRING String
Definition: wdfdevice.h:2433

Referenced by SampQueryAliasAdminComment(), SampQueryAliasGeneral(), SampQueryAliasName(), SampQueryDomainGeneral(), SampQueryDomainGeneral2(), SampQueryDomainName(), SampQueryDomainOem(), SampQueryDomainReplication(), SampQueryGroupAdminComment(), SampQueryGroupGeneral(), SampQueryGroupName(), SampQueryUserAccount(), SampQueryUserAccountName(), SampQueryUserAdminComment(), SampQueryUserAll(), SampQueryUserFullName(), SampQueryUserGeneral(), SampQueryUserHome(), SampQueryUserLogon(), SampQueryUserName(), SampQueryUserParameters(), SampQueryUserPreferences(), SampQueryUserProfile(), SampQueryUserScript(), SampQueryUserWorkStations(), SampSetAliasName(), SampSetGroupName(), and SampSetUserName().

◆ SampGetRidFromSid()

NTSTATUS SampGetRidFromSid ( IN PSID  Sid,
OUT PULONG  Rid 
)

Definition at line 138 of file utils.c.

140{
141 UCHAR RidCount;
142
143 RidCount = *RtlSubAuthorityCountSid(Sid);
144 if (RidCount < 1)
145 return STATUS_INVALID_SID;
146
147 *Rid = *RtlSubAuthoritySid(Sid, RidCount - 1);
148
149 return STATUS_SUCCESS;
150}
_In_ ULONG _In_ ACCESS_MASK _In_ PSID Sid
Definition: rtlfuncs.h:1145
#define STATUS_INVALID_SID
Definition: ntstatus.h:356

Referenced by SamrRemoveMemberFromForeignDomain().

◆ SampGetUserGroupAttributes()

NTSTATUS SampGetUserGroupAttributes ( IN PSAM_DB_OBJECT  DomainObject,
IN ULONG  UserId,
IN ULONG  GroupId,
OUT PULONG  GroupAttributes 
)

Definition at line 183 of file user.c.

187{
188 PSAM_DB_OBJECT UserObject = NULL;
189 PGROUP_MEMBERSHIP GroupsBuffer = NULL;
190 ULONG Length = 0;
191 ULONG i;
193
194 Status = SampOpenUserObject(DomainObject,
195 UserId,
196 0,
197 &UserObject);
198 if (!NT_SUCCESS(Status))
199 {
200 return Status;
201 }
202
203 SampGetObjectAttribute(UserObject,
204 L"Groups",
205 NULL,
206 NULL,
207 &Length);
208
209 if (Length == 0)
210 return STATUS_UNSUCCESSFUL; /* FIXME */
211
212 GroupsBuffer = midl_user_allocate(Length);
213 if (GroupsBuffer == NULL)
214 {
216 goto done;
217 }
218
219 Status = SampGetObjectAttribute(UserObject,
220 L"Groups",
221 NULL,
222 GroupsBuffer,
223 &Length);
224 if (!NT_SUCCESS(Status))
225 goto done;
226
227 for (i = 0; i < (Length / sizeof(GROUP_MEMBERSHIP)); i++)
228 {
229 if (GroupsBuffer[i].RelativeId == GroupId)
230 {
231 *GroupAttributes = GroupsBuffer[i].Attributes;
232 goto done;
233 }
234 }
235
236done:
237 if (GroupsBuffer != NULL)
238 midl_user_free(GroupsBuffer);
239
240 if (UserObject != NULL)
241 SampCloseDbObject(UserObject);
242
243 return Status;
244}
NTSTATUS SampCloseDbObject(PSAM_DB_OBJECT DbObject)
Definition: database.c:346
NTSTATUS SampOpenUserObject(IN PSAM_DB_OBJECT DomainObject, IN ULONG UserId, IN ACCESS_MASK DesiredAccess, OUT PSAM_DB_OBJECT *UserObject)
Definition: user.c:14
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132

Referenced by SamrGetMembersInGroup().

◆ SampInitDatabase()

NTSTATUS SampInitDatabase ( VOID  )

Definition at line 21 of file database.c.

22{
24
25 TRACE("SampInitDatabase()\n");
26
28 L"\\Registry\\Machine\\SAM",
31 if (!NT_SUCCESS(Status))
32 {
33 ERR("Failed to open the SAM key (Status: 0x%08lx)\n", Status);
34 return Status;
35 }
36
37 TRACE("SampInitDatabase() done\n");
38
39 return STATUS_SUCCESS;
40}
#define KEY_CREATE_SUB_KEY
Definition: nt_native.h:1018
#define KEY_ENUMERATE_SUB_KEYS
Definition: nt_native.h:1019

Referenced by SamIInitialize().

◆ SampInitializeDisplayCache()

NTSTATUS SampInitializeDisplayCache ( VOID  )

Definition at line 143 of file display.c.

144{
145 TRACE("SampInitializeDisplayCache()\n");
146
149 UserListCount = 0;
150
151// InitializeListHead(&MachineListHead);
152// MachineListFilled = FALSE;
153// MachineListCount = 0;
154
155// InitializeListHead(&GroupListHead);
156// GroupListFilled = FALSE;
157// GroupListCount = 0;
158
159 return STATUS_SUCCESS;
160}
static BOOLEAN UserListFilled
Definition: display.c:24
static LIST_ENTRY UserListHead
Definition: display.c:23
static ULONG UserListCount
Definition: display.c:25
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944

Referenced by SamIInitialize().

◆ 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 */
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);
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
989 /* Create the Administrators alias */
992
993 SampSetupCreateAliasAccount(hBuiltinDomainKey,
994 szName,
995 szComment,
997
998 /* Create the Users alias */
1001
1002 SampSetupCreateAliasAccount(hBuiltinDomainKey,
1003 szName,
1004 szComment,
1006
1007 /* Create the Guests alias */
1010
1011 SampSetupCreateAliasAccount(hBuiltinDomainKey,
1012 szName,
1013 szComment,
1015
1016 /* Create the Power Users alias */
1019
1020 SampSetupCreateAliasAccount(hBuiltinDomainKey,
1021 szName,
1022 szComment,
1024
1026 {
1027 /* Create the Print Operators alias (Server only) */
1030
1031 SampSetupCreateAliasAccount(hBuiltinDomainKey,
1032 szName,
1033 szComment,
1035 }
1036
1037 /* Create the Backup Operators alias */
1040
1041 SampSetupCreateAliasAccount(hBuiltinDomainKey,
1042 szName,
1043 szComment,
1045
1046 /* Create the Replicator alias */
1049
1050 SampSetupCreateAliasAccount(hBuiltinDomainKey,
1051 szName,
1052 szComment,
1054
1055 /* Create the Remote Desktop Users alias */
1058
1059 SampSetupCreateAliasAccount(hBuiltinDomainKey,
1060 szName,
1061 szComment,
1063
1064 /* Create the Network Configuration Operators alias */
1067
1068 SampSetupCreateAliasAccount(hBuiltinDomainKey,
1069 szName,
1070 szComment,
1072
1074 {
1075 /* Create the Performance Monitor Users alias (Server only) */
1078
1079 SampSetupCreateAliasAccount(hBuiltinDomainKey,
1080 szName,
1081 szComment,
1083
1084 /* Create the Performance Log Users alias (Server only) */
1087
1088 SampSetupCreateAliasAccount(hBuiltinDomainKey,
1089 szName,
1090 szComment,
1092 }
1093
1094 /* Add the Administrator user to the Administrators alias */
1095 pSid = AppendRidToSid(AccountDomainInfo->DomainSid,
1097 if (pSid != NULL)
1098 {
1099 SampSetupAddMemberToAlias(hBuiltinDomainKey,
1101 pSid);
1102
1103 RtlFreeHeap(RtlGetProcessHeap(), 0, pSid);
1104 }
1105
1106 /* Add the Guest user to the Guests alias */
1107 pSid = AppendRidToSid(AccountDomainInfo->DomainSid,
1109 if (pSid != NULL)
1110 {
1111 SampSetupAddMemberToAlias(hBuiltinDomainKey,
1113 pSid);
1114
1115 RtlFreeHeap(RtlGetProcessHeap(), 0, pSid);
1116 }
1117
1118 /* Add the Interactive SID to the Users alias */
1119 SampSetupAddMemberToAlias(hBuiltinDomainKey,
1121 pInteractiveSid);
1122
1123 /* Add the Authenticated User SID to the Users alias */
1124 SampSetupAddMemberToAlias(hBuiltinDomainKey,
1127
1128 /* Create the Account domain */
1129 Status = SampSetupCreateDomain(hServerKey,
1130 L"Account",
1131 L"",
1132 AccountDomainInfo->DomainSid,
1133 FALSE,
1134 &hAccountDomainKey);
1135 if (!NT_SUCCESS(Status))
1136 {
1137 bResult = FALSE;
1138 goto done;
1139 }
1140
1141 /* Create the None group */
1144
1145 SampSetupCreateGroupAccount(hAccountDomainKey,
1146 szName,
1147 szComment,
1149
1150 /* Create the Administrator user */
1153
1154 SampSetupCreateUserAccount(hAccountDomainKey,
1155 szName,
1156 szComment,
1157 AccountDomainInfo->DomainSid,
1160
1161 /* Add the Adminitrator user to the Administrators alias */
1162 SampSetupAddMemberToGroup(hAccountDomainKey,
1165
1166 /* Create the Guest user */
1169
1170 SampSetupCreateUserAccount(hAccountDomainKey,
1171 szName,
1172 szComment,
1173 AccountDomainInfo->DomainSid,
1176
1177 /* Add the Guest user to the Guests alias */
1178 SampSetupAddMemberToGroup(hAccountDomainKey,
1181
1182done:
1183 if (AccountDomainInfo)
1184 LsaFreeMemory(AccountDomainInfo);
1185
1187 RtlFreeHeap(RtlGetProcessHeap(), 0, pAuthenticatedUserSid);
1188
1189 if (pInteractiveSid)
1190 RtlFreeHeap(RtlGetProcessHeap(), 0, pInteractiveSid);
1191
1192 if (pBuiltinSid)
1193 RtlFreeHeap(RtlGetProcessHeap(), 0, pBuiltinSid);
1194
1195 SampRegCloseKey(&hAccountDomainKey);
1196 SampRegCloseKey(&hBuiltinDomainKey);
1197 SampRegCloseKey(&hServerKey);
1198 SampRegCloseKey(&hSamKey);
1199
1200 TRACE("SampInitializeSAM() done\n");
1201
1202 return bResult;
1203}
static PSID pAuthenticatedUserSid
Definition: security.c:19
HINSTANCE hInstance
Definition: charmap.c:19
NTSTATUS WINAPI LsaFreeMemory(IN PVOID Buffer)
Definition: lsa.c:701
HMODULE WINAPI GetModuleHandleW(LPCWSTR lpModuleName)
Definition: loader.c:838
#define IDS_ALIAS_REPLICATOR_COMMENT
Definition: resources.h:29
#define IDS_ALIAS_ADMINISTRATORS_COMMENT
Definition: resources.h:17
#define IDS_ALIAS_USERS_COMMENT
Definition: resources.h:23
#define IDS_ALIAS_BACKUP_OPS_COMMENT
Definition: resources.h:27
#define IDS_ALIAS_REPLICATOR_NAME
Definition: resources.h:28
#define IDS_ALIAS_NETWORK_CONFIGURATION_OPS_NAME
Definition: resources.h:32
#define IDS_ALIAS_POWER_USERS_NAME
Definition: resources.h:20
#define IDS_ALIAS_USERS_NAME
Definition: resources.h:22
#define IDS_ALIAS_LOGGING_USERS_COMMENT
Definition: resources.h:37
#define IDS_ALIAS_ADMINISTRATORS_NAME
Definition: resources.h:16
#define IDS_ALIAS_LOGGING_USERS_NAME
Definition: resources.h:36
#define IDS_ALIAS_PRINT_OPS_NAME
Definition: resources.h:24
#define IDS_USER_ADMINISTRATOR_NAME
Definition: resources.h:39
#define IDS_ALIAS_GUESTS_COMMENT
Definition: resources.h:19
#define IDS_USER_GUEST_COMMENT
Definition: resources.h:42
#define IDS_ALIAS_MONITORING_USERS_NAME
Definition: resources.h:34
#define IDS_ALIAS_BACKUP_OPS_NAME
Definition: resources.h:26
#define IDS_ALIAS_POWER_USERS_COMMENT
Definition: resources.h:21
#define IDS_ALIAS_PRINT_OPS_COMMENT
Definition: resources.h:25
#define IDS_USER_ADMINISTRATOR_COMMENT
Definition: resources.h:40
#define IDS_ALIAS_NETWORK_CONFIGURATION_OPS_COMMENT
Definition: resources.h:33
#define IDS_GROUP_NONE_COMMENT
Definition: resources.h:14
#define IDS_ALIAS_GUESTS_NAME
Definition: resources.h:18
#define IDS_ALIAS_MONITORING_USERS_COMMENT
Definition: resources.h:35
#define IDS_ALIAS_REMOTE_DESKTOP_USERS_COMMENT
Definition: resources.h:31
#define IDS_USER_GUEST_NAME
Definition: resources.h:41
#define IDS_ALIAS_REMOTE_DESKTOP_USERS_NAME
Definition: resources.h:30
#define IDS_DOMAIN_BUILTIN_NAME
Definition: resources.h:11
#define IDS_GROUP_NONE_NAME
Definition: resources.h:13
INT SampLoadString(HINSTANCE hInstance, UINT uId, LPWSTR lpBuffer, INT nBufferMax)
Definition: utils.c:17
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
static NTSTATUS SampSetupCreateServer(IN HANDLE hSamKey, OUT HANDLE *lpServerKey)
Definition: setup.c:805
static NTSTATUS SampSetupCreateGroupAccount(HANDLE hDomainKey, LPCWSTR lpAccountName, LPCWSTR lpComment, ULONG ulRelativeId)
Definition: setup.c:256
static NTSTATUS SampSetupCreateAliasAccount(HANDLE hDomainKey, LPCWSTR lpAccountName, LPCWSTR lpDescription, ULONG ulRelativeId)
Definition: setup.c:91
NTSTATUS SampGetAccountDomainInfo(PPOLICY_ACCOUNT_DOMAIN_INFO *AccountDomainInfo)
Definition: setup.c:856
static NTSTATUS SampSetupAddMemberToGroup(IN HANDLE hDomainKey, IN ULONG GroupId, IN ULONG MemberId)
Definition: setup.c:177
static BOOL SampSetupAddMemberToAlias(HKEY hDomainKey, ULONG AliasId, PSID MemberSid)
Definition: setup.c:25
SID_IDENTIFIER_AUTHORITY SecurityNtAuthority
Definition: setup.c:20
static NTSTATUS SampSetupCreateUserAccount(HANDLE hDomainKey, LPCWSTR lpAccountName, LPCWSTR lpComment, PSID lpDomainSid, ULONG ulRelativeId, ULONG UserAccountControl)
Definition: setup.c:357
@ NtProductWinNt
Definition: shellpath.c:64
unsigned int BOOL
Definition: ntddk_ex.h:94
static PSID pSid
Definition: security.c:74
static const WCHAR szComment[]
Definition: domdoc.c:1167
NTSYSAPI ULONG NTAPI RtlLengthRequiredSid(IN ULONG SubAuthorityCount)
Definition: sid.c:54
NTSYSAPI NTSTATUS NTAPI RtlInitializeSid(IN OUT PSID Sid, IN PSID_IDENTIFIER_AUTHORITY IdentifierAuthority, IN UCHAR SubAuthorityCount)
#define USER_NORMAL_ACCOUNT
Definition: ntsam.h:171
#define USER_DONT_EXPIRE_PASSWORD
Definition: ntsam.h:176
#define USER_ACCOUNT_DISABLED
Definition: ntsam.h:167
static const WCHAR szName[]
Definition: powrprof.c:45
NT_PRODUCT_TYPE SampProductType
Definition: samsrv.c:29
#define DOMAIN_ALIAS_RID_NETWORK_CONFIGURATION_OPS
Definition: setypes.h:666
#define DOMAIN_USER_RID_ADMIN
Definition: setypes.h:631
#define SECURITY_INTERACTIVE_RID
Definition: setypes.h:559
#define DOMAIN_ALIAS_RID_REMOTE_DESKTOP_USERS
Definition: setypes.h:665
#define DOMAIN_ALIAS_RID_MONITORING_USERS
Definition: setypes.h:669
#define SECURITY_AUTHENTICATED_USER_RID
Definition: setypes.h:568
#define DOMAIN_ALIAS_RID_LOGGING_USERS
Definition: setypes.h:670
#define DOMAIN_USER_RID_GUEST
Definition: setypes.h:632
#define DOMAIN_ALIAS_RID_BACKUP_OPS
Definition: setypes.h:660
#define DOMAIN_ALIAS_RID_PRINT_OPS
Definition: setypes.h:659
#define DOMAIN_ALIAS_RID_REPLICATOR
Definition: setypes.h:662
#define DOMAIN_ALIAS_RID_POWER_USERS
Definition: setypes.h:655
#define DOMAIN_GROUP_RID_USERS
Definition: setypes.h:640

Referenced by SampInitializeRegistry().

◆ SampIsSetupRunning()

BOOL SampIsSetupRunning ( VOID  )

Definition at line 64 of file utils.c.

65{
66 DWORD dwError;
67 HKEY hKey;
68 DWORD dwType;
70 DWORD dwSetupType;
71
72 TRACE("SampIsSetupRunning()\n");
73
74 /* Open key */
76 L"SYSTEM\\Setup",
77 0,
79 &hKey);
80 if (dwError != ERROR_SUCCESS)
81 return FALSE;
82
83 /* Read key */
84 dwSize = sizeof(DWORD);
85 dwError = RegQueryValueExW(hKey,
86 L"SetupType",
87 NULL,
88 &dwType,
89 (LPBYTE)&dwSetupType,
90 &dwSize);
91
92 /* Close key, and check if returned values are correct */
94 if (dwError != ERROR_SUCCESS || dwType != REG_DWORD || dwSize != sizeof(DWORD))
95 return FALSE;
96
97 TRACE("SampIsSetupRunning() returns %s\n", (dwSetupType != 0) ? "TRUE" : "FALSE");
98 return (dwSetupType != 0);
99}
#define RegCloseKey(hKey)
Definition: registry.h:49
#define ERROR_SUCCESS
Definition: deptool.c:10
LONG WINAPI RegOpenKeyExW(HKEY hKey, LPCWSTR lpSubKey, DWORD ulOptions, REGSAM samDesired, PHKEY phkResult)
Definition: reg.c:3333
LONG WINAPI RegQueryValueExW(_In_ HKEY hkeyorg, _In_ LPCWSTR name, _In_ LPDWORD reserved, _In_ LPDWORD type, _In_ LPBYTE data, _In_ LPDWORD count)
Definition: reg.c:4103
unsigned long DWORD
Definition: ntddk_ex.h:95
FxAutoRegKey hKey
PSDBQUERYRESULT_VISTA PVOID DWORD * dwSize
Definition: env.c:56
#define KEY_QUERY_VALUE
Definition: nt_native.h:1016
#define DWORD
Definition: nt_native.h:44
#define REG_DWORD
Definition: sdbapi.c:596
unsigned char * LPBYTE
Definition: typedefs.h:53
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12

Referenced by SamIInitialize().

◆ SampLoadString()

INT SampLoadString ( HINSTANCE  hInstance,
UINT  uId,
LPWSTR  lpBuffer,
INT  nBufferMax 
)

Definition at line 17 of file utils.c.

21{
22 HGLOBAL hmem;
23 HRSRC hrsrc;
24 WCHAR *p;
25 int string_num;
26 int i;
27
28 /* Use loword (incremented by 1) as resourceid */
30 MAKEINTRESOURCEW((LOWORD(uId) >> 4) + 1),
32 if (!hrsrc)
33 return 0;
34
35 hmem = LoadResource(hInstance, hrsrc);
36 if (!hmem)
37 return 0;
38
39 p = LockResource(hmem);
40 string_num = uId & 0x000f;
41 for (i = 0; i < string_num; i++)
42 p += *p + 1;
43
44 i = min(nBufferMax - 1, *p);
45 if (i > 0)
46 {
47 memcpy(lpBuffer, p + 1, i * sizeof(WCHAR));
48 lpBuffer[i] = 0;
49 }
50 else
51 {
52 if (nBufferMax > 1)
53 {
54 lpBuffer[0] = 0;
55 return 0;
56 }
57 }
58
59 return i;
60}
static TAGREF LPCWSTR LPDWORD LPVOID lpBuffer
Definition: db.cpp:175
HRSRC WINAPI FindResourceW(HINSTANCE hModule, LPCWSTR name, LPCWSTR type)
Definition: res.c:176
LPVOID WINAPI LockResource(HGLOBAL handle)
Definition: res.c:550
HGLOBAL WINAPI LoadResource(HINSTANCE hModule, HRSRC hRsrc)
Definition: res.c:532
GLfloat GLfloat p
Definition: glext.h:8902
#define min(a, b)
Definition: monoChain.cc:55
#define LOWORD(l)
Definition: pedump.c:82
#define RT_STRING
Definition: pedump.c:368
#define MAKEINTRESOURCEW(i)
Definition: winuser.h:582

Referenced by SampInitializeSAM().

◆ SampOpenAliasObject()

NTSTATUS SampOpenAliasObject ( IN PSAM_DB_OBJECT  DomainObject,
IN ULONG  AliasId,
IN ACCESS_MASK  DesiredAccess,
OUT PSAM_DB_OBJECT AliasObject 
)

Definition at line 14 of file alias.c.

18{
19 WCHAR szRid[9];
20
21 TRACE("(%p %lu %lx %p)\n",
22 DomainObject, AliasId, DesiredAccess, AliasObject);
23
24 /* Convert the RID into a string (hex) */
25 swprintf(szRid, L"%08lX", AliasId);
26
27 /* Create the user object */
28 return SampOpenDbObject(DomainObject,
29 L"Aliases",
30 szRid,
31 AliasId,
34 AliasObject);
35}
NTSTATUS SampOpenDbObject(IN PSAM_DB_OBJECT ParentObject, IN LPWSTR ContainerName, IN LPWSTR ObjectName, IN ULONG RelativeId, IN SAM_DB_OBJECT_TYPE ObjectType, IN ACCESS_MASK DesiredAccess, OUT PSAM_DB_OBJECT *DbObject)
Definition: database.c:173
#define swprintf
Definition: precomp.h:40

◆ SampOpenDbObject()

NTSTATUS SampOpenDbObject ( IN PSAM_DB_OBJECT  ParentObject,
IN LPWSTR  ContainerName,
IN LPWSTR  ObjectName,
IN ULONG  RelativeId,
IN SAM_DB_OBJECT_TYPE  ObjectType,
IN ACCESS_MASK  DesiredAccess,
OUT PSAM_DB_OBJECT DbObject 
)

Definition at line 173 of file database.c.

180{
182 HANDLE ParentKeyHandle;
183 HANDLE ContainerKeyHandle = NULL;
184 HANDLE ObjectKeyHandle = NULL;
185 HANDLE MembersKeyHandle = NULL;
187
188 if (DbObject == NULL)
190
191 *DbObject = NULL;
192
193 if (ParentObject == NULL)
194 ParentKeyHandle = SamKeyHandle;
195 else
196 ParentKeyHandle = ParentObject->KeyHandle;
197
198 if (ContainerName != NULL)
199 {
200 /* Open the container key */
201 Status = SampRegOpenKey(ParentKeyHandle,
202 ContainerName,
204 &ContainerKeyHandle);
205 if (!NT_SUCCESS(Status))
206 {
207 goto done;
208 }
209
210 /* Open the object key */
211 Status = SampRegOpenKey(ContainerKeyHandle,
214 &ObjectKeyHandle);
215 if (!NT_SUCCESS(Status))
216 {
217 goto done;
218 }
219
221 {
222 /* Open the object key */
223 Status = SampRegOpenKey(ContainerKeyHandle,
224 L"Members",
226 &MembersKeyHandle);
227 if (!NT_SUCCESS(Status))
228 {
229 goto done;
230 }
231 }
232 }
233 else
234 {
235 /* Open the object key */
236 Status = SampRegOpenKey(ParentKeyHandle,
239 &ObjectKeyHandle);
240 if (!NT_SUCCESS(Status))
241 {
242 goto done;
243 }
244 }
245
246 NewObject = RtlAllocateHeap(RtlGetProcessHeap(),
248 sizeof(SAM_DB_OBJECT));
249 if (NewObject == NULL)
250 {
252 goto done;
253 }
254
255 NewObject->Name = RtlAllocateHeap(RtlGetProcessHeap(),
256 0,
257 (wcslen(ObjectName) + 1) * sizeof(WCHAR));
258 if (NewObject->Name == NULL)
259 {
261 goto done;
262 }
263
265 NewObject->Signature = SAMP_DB_SIGNATURE;
266 NewObject->RefCount = 1;
267 NewObject->ObjectType = ObjectType;
268 NewObject->Access = DesiredAccess;
269 NewObject->KeyHandle = ObjectKeyHandle;
270 NewObject->MembersKeyHandle = MembersKeyHandle;
271 NewObject->RelativeId = RelativeId;
272 NewObject->ParentObject = ParentObject;
273
274 if (ParentObject != NULL)
275 NewObject->Trusted = ParentObject->Trusted;
276
277 *DbObject = NewObject;
278
279done:
280 if (!NT_SUCCESS(Status))
281 {
282 if (NewObject != NULL)
283 {
284 if (NewObject->Name != NULL)
285 RtlFreeHeap(RtlGetProcessHeap(), 0, NewObject->Name);
286
287 RtlFreeHeap(RtlGetProcessHeap(), 0, NewObject);
288 }
289
290 SampRegCloseKey(&MembersKeyHandle);
291 SampRegCloseKey(&ObjectKeyHandle);
292 }
293
294 SampRegCloseKey(&ContainerKeyHandle);
295
296 return Status;
297}

Referenced by SamIConnect(), SampFillUserDisplayCache(), SampOpenAliasObject(), SampOpenGroupObject(), SampOpenUserObject(), SamrConnect5(), SamrGetDomainPasswordInformation(), SamrOpenAlias(), SamrOpenDomain(), SamrOpenGroup(), and SamrOpenUser().

◆ SampOpenGroupObject()

NTSTATUS SampOpenGroupObject ( IN PSAM_DB_OBJECT  DomainObject,
IN ULONG  GroupId,
IN ACCESS_MASK  DesiredAccess,
OUT PSAM_DB_OBJECT GroupObject 
)

Definition at line 14 of file group.c.

18{
19 WCHAR szRid[9];
20
21 TRACE("(%p %lu %lx %p)\n",
22 DomainObject, GroupId, DesiredAccess, GroupObject);
23
24 /* Convert the RID into a string (hex) */
25 swprintf(szRid, L"%08lX", GroupId);
26
27 /* Create the user object */
28 return SampOpenDbObject(DomainObject,
29 L"Groups",
30 szRid,
31 GroupId,
34 GroupObject);
35}

Referenced by SampRemoveUserFromAllGroups().

◆ SampOpenUserObject()

NTSTATUS SampOpenUserObject ( IN PSAM_DB_OBJECT  DomainObject,
IN ULONG  UserId,
IN ACCESS_MASK  DesiredAccess,
OUT PSAM_DB_OBJECT UserObject 
)

Definition at line 14 of file user.c.

18{
19 WCHAR szRid[9];
20
21 TRACE("(%p %lu %lx %p)\n",
22 DomainObject, UserId, DesiredAccess, UserObject);
23
24 /* Convert the RID into a string (hex) */
25 swprintf(szRid, L"%08lX", UserId);
26
27 /* Create the user object */
28 return SampOpenDbObject(DomainObject,
29 L"Users",
30 szRid,
31 UserId,
34 UserObject);
35}

Referenced by SampGetUserGroupAttributes(), SampSetUserGroupAttributes(), SamrAddMemberToGroup(), and SamrRemoveMemberFromGroup().

◆ SampRegCloseKey()

◆ SampRegCreateKey()

NTSTATUS SampRegCreateKey ( IN HANDLE  ParentKeyHandle,
IN LPCWSTR  KeyName,
IN ACCESS_MASK  DesiredAccess,
OUT PHANDLE  KeyHandle 
)

Definition at line 42 of file registry.c.

46{
50
52
54 &Name,
56 ParentKeyHandle,
57 NULL);
58
59 /* Create the key */
60 return ZwCreateKey(KeyHandle,
63 0,
64 NULL,
65 0,
67}
struct NameRec_ * Name
Definition: cdprocs.h:460
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:36
#define OBJ_OPENIF
Definition: winternl.h:229
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
_In_ ACCESS_MASK _In_ POBJECT_ATTRIBUTES _Reserved_ ULONG _In_opt_ PUNICODE_STRING _In_ ULONG _Out_opt_ PULONG Disposition
Definition: cmfuncs.h:56
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
_Must_inspect_result_ _In_ WDFDEVICE _In_ PCUNICODE_STRING KeyName
Definition: wdfdevice.h:2699

Referenced by SampAddMemberToAlias(), SampCreateDbObject(), SampSetupCreateAliasAccount(), SampSetupCreateDomain(), SampSetupCreateGroupAccount(), SampSetupCreateServer(), and SampSetupCreateUserAccount().

◆ SampRegDeleteKey()

NTSTATUS SampRegDeleteKey ( IN HANDLE  ParentKeyHandle,
IN LPCWSTR  KeyName 
)

Definition at line 71 of file registry.c.

73{
76 HANDLE TargetKey;
78
84 ParentKeyHandle,
85 NULL);
86 Status = NtOpenKey(&TargetKey,
87 DELETE,
89 if (!NT_SUCCESS(Status))
90 return Status;
91
92 Status = NtDeleteKey(TargetKey);
93
94 NtClose(TargetKey);
95
96 return Status;
97}
_Must_inspect_result_ _Out_ PNDIS_STATUS _In_ NDIS_HANDLE _In_ PNDIS_STRING SubKeyName
Definition: ndis.h:4725
NTSYSAPI NTSTATUS NTAPI NtOpenKey(OUT PHANDLE KeyHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes)
Definition: ntapi.c:336
NTSTATUS NTAPI NtDeleteKey(IN HANDLE KeyHandle)
Definition: ntapi.c:408

Referenced by SampDeleteAccountDbObject(), SampRemoveMemberFromAlias(), SampRemoveMemberFromAllAliases(), SampSetupCreateAliasAccount(), SampSetupCreateGroupAccount(), and SampSetupCreateUserAccount().

◆ SampRegDeleteValue()

NTSTATUS SampRegDeleteValue ( IN HANDLE  KeyHandle,
IN LPCWSTR  ValueName 
)

Definition at line 212 of file registry.c.

214{
216
218 ValueName);
219
221 &Name);
222}
NTSYSAPI NTSTATUS NTAPI NtDeleteValueKey(IN HANDLE KeyHandle, IN PUNICODE_STRING ValueName)
Definition: ntapi.c:1014
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING ValueName
Definition: wdfregistry.h:243

Referenced by SampDeleteAccountDbObject(), SampRemoveAccountNameFromDomain(), SampRemoveMemberFromAlias(), and SampRemoveMemberFromAllAliases().

◆ SampRegEnumerateSubKey()

NTSTATUS SampRegEnumerateSubKey ( IN HANDLE  KeyHandle,
IN ULONG  Index,
IN ULONG  Length,
OUT LPWSTR  Buffer 
)

Definition at line 101 of file registry.c.

105{
110
111 /* Check if we have a name */
112 if (Length)
113 {
114 /* Allocate a buffer for it */
115 BufferLength = sizeof(KEY_BASIC_INFORMATION) + Length * sizeof(WCHAR);
116
117 KeyInfo = RtlAllocateHeap(RtlGetProcessHeap(), 0, BufferLength);
118 if (KeyInfo == NULL)
119 return STATUS_NO_MEMORY;
120 }
121
122 /* Enumerate the key */
123 Status = ZwEnumerateKey(KeyHandle,
124 Index,
126 KeyInfo,
129 if (NT_SUCCESS(Status))
130 {
131 /* Check if the name fits */
132 if (KeyInfo->NameLength < (Length * sizeof(WCHAR)))
133 {
134 /* Copy it */
136 KeyInfo->Name,
137 KeyInfo->NameLength);
138
139 /* Terminate the string */
140 Buffer[KeyInfo->NameLength / sizeof(WCHAR)] = 0;
141 }
142 else
143 {
144 /* Otherwise, we ran out of buffer space */
146 }
147 }
148
149 /* Free the buffer and return status */
150 if (KeyInfo)
151 RtlFreeHeap(RtlGetProcessHeap(), 0, KeyInfo);
152
153 return Status;
154}
_In_ ULONG _In_ BATTERY_QUERY_INFORMATION_LEVEL _In_ LONG _In_ ULONG _Out_ PULONG ReturnedLength
Definition: batclass.h:188
Definition: bufpool.h:45
#define STATUS_NO_MEMORY
Definition: d3dkmdt.h:51
@ KeyBasicInformation
Definition: nt_native.h:1131
struct _KEY_BASIC_INFORMATION KEY_BASIC_INFORMATION
#define RtlMoveMemory(Destination, Source, Length)
Definition: typedefs.h:264

Referenced by SampFillUserDisplayCache(), SampRemoveMemberFromAllAliases(), SamrEnumerateDomainsInSamServer(), and SamrLookupDomainInSamServer().

◆ SampRegEnumerateValue()

NTSTATUS SampRegEnumerateValue ( IN HANDLE  KeyHandle,
IN ULONG  Index,
OUT LPWSTR  Name,
IN OUT PULONG  NameLength,
OUT PULONG Type  OPTIONAL,
OUT PVOID Data  OPTIONAL,
IN OUT PULONG DataLength  OPTIONAL 
)

Definition at line 226 of file registry.c.

233{
238
239 TRACE("Index: %lu\n", Index);
240
241 /* Calculate the required buffer length */
243 BufferLength += (MAX_PATH + 1) * sizeof(WCHAR);
244 if (Data != NULL)
246
247 /* Allocate the value buffer */
248 ValueInfo = RtlAllocateHeap(RtlGetProcessHeap(), 0, BufferLength);
249 if (ValueInfo == NULL)
250 return STATUS_NO_MEMORY;
251
252 /* Enumerate the value*/
253 Status = ZwEnumerateValueKey(KeyHandle,
254 Index,
256 ValueInfo,
259 if (NT_SUCCESS(Status))
260 {
261 if (Name != NULL)
262 {
263 /* Check if the name fits */
264 if (ValueInfo->NameLength < (*NameLength * sizeof(WCHAR)))
265 {
266 /* Copy it */
268 ValueInfo->Name,
269 ValueInfo->NameLength);
270
271 /* Terminate the string */
272 Name[ValueInfo->NameLength / sizeof(WCHAR)] = 0;
273 }
274 else
275 {
276 /* Otherwise, we ran out of buffer space */
278 goto done;
279 }
280 }
281
282 if (Data != NULL)
283 {
284 /* Check if the data fits */
285 if (ValueInfo->DataLength <= *DataLength)
286 {
287 /* Copy it */
289 (PVOID)((ULONG_PTR)ValueInfo + ValueInfo->DataOffset),
290 ValueInfo->DataLength);
291
292 /* if the type is REG_SZ and data is not 0-terminated
293 * and there is enough space in the buffer NT appends a \0 */
294 if (IsStringType(ValueInfo->Type) &&
295 ValueInfo->DataLength <= *DataLength - sizeof(WCHAR))
296 {
297 WCHAR *ptr = (WCHAR *)((ULONG_PTR)Data + ValueInfo->DataLength);
298 if ((ptr > (WCHAR *)Data) && ptr[-1])
299 *ptr = 0;
300 }
301 }
302 else
303 {
305 goto done;
306 }
307 }
308 }
309
310done:
312 {
313 if (Type != NULL)
314 *Type = ValueInfo->Type;
315
316 if (NameLength != NULL)
317 *NameLength = ValueInfo->NameLength;
318
319 if (DataLength != NULL)
320 *DataLength = ValueInfo->DataLength;
321 }
322
323 /* Free the buffer and return status */
324 if (ValueInfo)
325 RtlFreeHeap(RtlGetProcessHeap(), 0, ValueInfo);
326
327 return Status;
328}
Type
Definition: Type.h:7
#define MAX_PATH
Definition: compat.h:34
static BOOLEAN IsStringType(ULONG Type)
Definition: registry.c:19
static PVOID ptr
Definition: dispmode.c:27
@ KeyValueFullInformation
Definition: nt_native.h:1181
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:255
uint32_t ULONG_PTR
Definition: typedefs.h:65

Referenced by SampGetMembersInAlias(), SamrEnumerateAliasesInDomain(), SamrEnumerateGroupsInDomain(), SamrEnumerateUsersInDomain(), and SamrGetAliasMembership().

◆ SampRegOpenKey()

◆ SampRegQueryKeyInfo()

NTSTATUS SampRegQueryKeyInfo ( IN HANDLE  KeyHandle,
OUT PULONG  SubKeyCount,
OUT PULONG  ValueCount 
)

Definition at line 181 of file registry.c.

184{
185 KEY_FULL_INFORMATION FullInfoBuffer;
188
189 FullInfoBuffer.ClassLength = 0;
191
194 &FullInfoBuffer,
195 sizeof(KEY_FULL_INFORMATION),
196 &Length);
197 TRACE("NtQueryKey() returned status 0x%08lX\n", Status);
198 if (!NT_SUCCESS(Status))
199 return Status;
200
201 if (SubKeyCount != NULL)
202 *SubKeyCount = FullInfoBuffer.SubKeys;
203
204 if (ValueCount != NULL)
205 *ValueCount = FullInfoBuffer.Values;
206
207 return Status;
208}
@ KeyFullInformation
Definition: nt_native.h:1133
NTSTATUS NTAPI NtQueryKey(IN HANDLE KeyHandle, IN KEY_INFORMATION_CLASS KeyInformationClass, OUT PVOID KeyInformation, IN ULONG Length, OUT PULONG ResultLength)
Definition: ntapi.c:632

Referenced by SampGetMembersInAlias(), SampGetNumberOfAccounts(), SampQueryAliasGeneral(), SampRemoveMemberFromAlias(), and SamrGetAliasMembership().

◆ SampRegQueryValue()

NTSTATUS SampRegQueryValue ( IN HANDLE  KeyHandle,
IN LPCWSTR  ValueName,
OUT PULONG Type  OPTIONAL,
OUT LPVOID Data  OPTIONAL,
IN OUT PULONG DataLength  OPTIONAL 
)

Definition at line 332 of file registry.c.

337{
342
344 ValueName);
345
346 if (DataLength != NULL)
348
350
351 /* Allocate memory for the value */
352 ValueInfo = RtlAllocateHeap(RtlGetProcessHeap(), 0, BufferLength);
353 if (ValueInfo == NULL)
354 return STATUS_NO_MEMORY;
355
356 /* Query the value */
357 Status = ZwQueryValueKey(KeyHandle,
358 &Name,
360 ValueInfo,
362 &BufferLength);
364 {
365 if (Type != NULL)
366 *Type = ValueInfo->Type;
367
368 if (DataLength != NULL)
369 *DataLength = ValueInfo->DataLength;
370 }
371
372 /* Check if the caller wanted data back, and we got it */
373 if ((NT_SUCCESS(Status)) && (Data != NULL))
374 {
375 /* Copy it */
377 ValueInfo->Data,
378 ValueInfo->DataLength);
379
380 /* if the type is REG_SZ and data is not 0-terminated
381 * and there is enough space in the buffer NT appends a \0 */
382 if (IsStringType(ValueInfo->Type) &&
383 ValueInfo->DataLength <= *DataLength - sizeof(WCHAR))
384 {
385 WCHAR *ptr = (WCHAR *)((ULONG_PTR)Data + ValueInfo->DataLength);
386 if ((ptr > (WCHAR *)Data) && ptr[-1])
387 *ptr = 0;
388 }
389 }
390
391 /* Free the memory and return status */
392 RtlFreeHeap(RtlGetProcessHeap(), 0, ValueInfo);
393
394 if ((Data == NULL) && (Status == STATUS_BUFFER_OVERFLOW))
396
397 return Status;
398}
@ KeyValuePartialInformation
Definition: nt_native.h:1182

Referenced by SampCheckAccountNameInDomain(), SampGetObjectAttribute(), SampSetupAddMemberToGroup(), SamrEnumerateDomainsInSamServer(), SamrLookupDomainInSamServer(), SamrLookupIdsInDomain(), and SamrLookupNamesInDomain().

◆ SampRegSetValue()

NTSTATUS SampRegSetValue ( IN HANDLE  KeyHandle,
IN LPCWSTR  ValueName,
IN ULONG  Type,
IN LPVOID  Data,
IN ULONG  DataLength 
)

◆ SampRemoveAccountNameFromDomain()

NTSTATUS SampRemoveAccountNameFromDomain ( IN PSAM_DB_OBJECT  DomainObject,
IN LPCWSTR  lpContainerName,
IN LPCWSTR  lpAccountName 
)

Definition at line 57 of file domain.c.

60{
61 HANDLE ContainerKeyHandle = NULL;
62 HANDLE NamesKeyHandle = NULL;
64
65 TRACE("(%S %S)\n", lpContainerName, lpAccountName);
66
67 /* Open the container key */
68 Status = SampRegOpenKey(DomainObject->KeyHandle,
69 lpContainerName,
71 &ContainerKeyHandle);
72 if (!NT_SUCCESS(Status))
73 return Status;
74
75 /* Open the 'Names' key */
76 Status = SampRegOpenKey(ContainerKeyHandle,
77 L"Names",
79 &NamesKeyHandle);
80 if (!NT_SUCCESS(Status))
81 goto done;
82
83 /* Delete the account name value */
84 Status = SampRegDeleteValue(NamesKeyHandle,
86
87done:
88 SampRegCloseKey(&NamesKeyHandle);
89 SampRegCloseKey(&ContainerKeyHandle);
90
91 return Status;
92}

Referenced by SampSetAliasName(), SampSetGroupName(), and SampSetUserName().

◆ SampRemoveAllMembersFromAlias()

NTSTATUS SampRemoveAllMembersFromAlias ( IN PSAM_DB_OBJECT  AliasObject)

Definition at line 314 of file alias.c.

315{
316 HANDLE MembersKeyHandle = NULL;
317 PSAMPR_SID_INFORMATION MemberArray = NULL;
318 ULONG MemberCount = 0;
319 ULONG Index;
321
322 TRACE("(%p)\n", AliasObject);
323
324 /* Open the members key of the alias object */
325 Status = SampRegOpenKey(AliasObject->KeyHandle,
326 L"Members",
327 KEY_READ,
328 &MembersKeyHandle);
329 if (!NT_SUCCESS(Status))
330 {
331 ERR("SampRegOpenKey failed (Status 0x%08lx)\n", Status);
332 goto done;
333 }
334
335 /* Get a list of all members of the alias */
336 Status = SampGetMembersInAlias(AliasObject,
337 &MemberCount,
338 &MemberArray);
339 if (!NT_SUCCESS(Status))
340 {
341 ERR("SampGetMembersInAlias failed (Status 0x%08lx)\n", Status);
342 goto done;
343 }
344
345 /* Remove all members from the alias */
346 for (Index = 0; Index < MemberCount; Index++)
347 {
348 Status = SampRemoveMemberFromAlias(AliasObject,
349 MemberArray[Index].SidPointer);
350 if (!NT_SUCCESS(Status))
351 goto done;
352 }
353
354done:
355 if (MemberArray != NULL)
356 {
357 for (Index = 0; Index < MemberCount; Index++)
358 {
359 if (MemberArray[Index].SidPointer != NULL)
360 midl_user_free(MemberArray[Index].SidPointer);
361 }
362
363 midl_user_free(MemberArray);
364 }
365
366 SampRegCloseKey(&MembersKeyHandle);
367
368 return Status;
369}
NTSTATUS SampGetMembersInAlias(IN PSAM_DB_OBJECT AliasObject, OUT PULONG MemberCount, OUT PSAMPR_SID_INFORMATION *MemberArray)
Definition: alias.c:218
NTSTATUS NTAPI SampRemoveMemberFromAlias(IN PSAM_DB_OBJECT AliasObject, IN PRPC_SID MemberId)
Definition: alias.c:111

Referenced by SamrDeleteAlias().

◆ SampRemoveGroupMembershipFromUser()

NTSTATUS SampRemoveGroupMembershipFromUser ( IN PSAM_DB_OBJECT  UserObject,
IN ULONG  GroupId 
)

Definition at line 108 of file user.c.

110{
111 PGROUP_MEMBERSHIP GroupsBuffer = NULL;
112 ULONG GroupsCount = 0;
113 ULONG Length = 0;
114 ULONG i;
116
117 TRACE("(%p %lu)\n",
118 UserObject, GroupId);
119
120 SampGetObjectAttribute(UserObject,
121 L"Groups",
122 NULL,
123 NULL,
124 &Length);
125
126 if (Length == 0)
128
129 GroupsBuffer = midl_user_allocate(Length);
130 if (GroupsBuffer == NULL)
131 {
133 goto done;
134 }
135
136 Status = SampGetObjectAttribute(UserObject,
137 L"Groups",
138 NULL,
139 GroupsBuffer,
140 &Length);
141 if (!NT_SUCCESS(Status))
142 goto done;
143
145
146 GroupsCount = Length / sizeof(GROUP_MEMBERSHIP);
147 for (i = 0; i < GroupsCount; i++)
148 {
149 if (GroupsBuffer[i].RelativeId == GroupId)
150 {
151 Length -= sizeof(GROUP_MEMBERSHIP);
153
154 if (GroupsCount - i - 1 > 0)
155 {
156 CopyMemory(&GroupsBuffer[i],
157 &GroupsBuffer[i + 1],
158 (GroupsCount - i - 1) * sizeof(GROUP_MEMBERSHIP));
159 }
160
161 break;
162 }
163 }
164
165 if (!NT_SUCCESS(Status))
166 goto done;
167
168 Status = SampSetObjectAttribute(UserObject,
169 L"Groups",
171 GroupsBuffer,
172 Length);
173
174done:
175 if (GroupsBuffer != NULL)
176 midl_user_free(GroupsBuffer);
177
178 return Status;
179}
#define STATUS_MEMBER_NOT_IN_GROUP
Definition: ntstatus.h:340
#define CopyMemory
Definition: winbase.h:1734

Referenced by SamrRemoveMemberFromGroup().

◆ SampRemoveMemberFromAlias()

NTSTATUS NTAPI SampRemoveMemberFromAlias ( IN PSAM_DB_OBJECT  AliasObject,
IN PRPC_SID  MemberId 
)

Definition at line 111 of file alias.c.

113{
114 LPWSTR MemberIdString = NULL;
115 HANDLE MembersKeyHandle = NULL;
116 HANDLE MemberKeyHandle = NULL;
117 ULONG ulValueCount;
119
120 TRACE("(%p %p)\n",
121 AliasObject, MemberId);
122
123 ConvertSidToStringSidW(MemberId, &MemberIdString);
124 TRACE("Member SID: %S\n", MemberIdString);
125
126 Status = SampRegOpenKey(AliasObject->MembersKeyHandle,
127 MemberIdString,
129 &MemberKeyHandle);
130 if (!NT_SUCCESS(Status))
131 {
132 TRACE("SampRegOpenKey failed with status 0x%08lx\n", Status);
133 goto done;
134 }
135
136 Status = SampRegDeleteValue(MemberKeyHandle,
137 AliasObject->Name);
138 if (!NT_SUCCESS(Status))
139 {
140 TRACE("SampRegDeleteValue failed with status 0x%08lx\n", Status);
141 goto done;
142 }
143
144 Status = SampRegQueryKeyInfo(MemberKeyHandle,
145 NULL,
146 &ulValueCount);
147 if (!NT_SUCCESS(Status))
148 {
149 TRACE("SampRegQueryKeyInfo failed with status 0x%08lx\n", Status);
150 goto done;
151 }
152
153 if (ulValueCount == 0)
154 {
155 SampRegCloseKey(&MemberKeyHandle);
156
157 Status = SampRegDeleteKey(AliasObject->MembersKeyHandle,
158 MemberIdString);
159 if (!NT_SUCCESS(Status))
160 {
161 TRACE("SampRegDeleteKey failed with status 0x%08lx\n", Status);
162 goto done;
163 }
164 }
165
166 Status = SampRegOpenKey(AliasObject->KeyHandle,
167 L"Members",
169 &MembersKeyHandle);
170 if (!NT_SUCCESS(Status))
171 {
172 TRACE("SampRegOpenKey failed with status 0x%08lx\n", Status);
173 goto done;
174 }
175
176 Status = SampRegDeleteValue(MembersKeyHandle,
177 MemberIdString);
178 if (!NT_SUCCESS(Status))
179 {
180 TRACE("SampRegDeleteValue failed with status 0x%08lx\n", Status);
181 goto done;
182 }
183
184 Status = SampRegQueryKeyInfo(MembersKeyHandle,
185 NULL,
186 &ulValueCount);
187 if (!NT_SUCCESS(Status))
188 {
189 TRACE("SampRegQueryKeyInfo failed with status 0x%08lx\n", Status);
190 goto done;
191 }
192
193 if (ulValueCount == 0)
194 {
195 SampRegCloseKey(&MembersKeyHandle);
196
197 Status = SampRegDeleteKey(AliasObject->KeyHandle,
198 L"Members");
199 if (!NT_SUCCESS(Status))
200 {
201 TRACE("SampRegDeleteKey failed with status 0x%08lx\n", Status);
202 goto done;
203 }
204 }
205
206done:
207 SampRegCloseKey(&MemberKeyHandle);
208 SampRegCloseKey(&MembersKeyHandle);
209
210 if (MemberIdString != NULL)
211 LocalFree(MemberIdString);
212
213 return Status;
214}

Referenced by SampRemoveAllMembersFromAlias(), and SamrRemoveMemberFromAlias().

◆ SampRemoveMemberFromAllAliases()

NTSTATUS SampRemoveMemberFromAllAliases ( IN PSAM_DB_OBJECT  DomainObject,
IN PRPC_SID  MemberSid 
)

Definition at line 214 of file domain.c.

216{
217 WCHAR AliasKeyName[64];
218 LPWSTR MemberSidString = NULL;
219 HANDLE AliasesKey = NULL;
220 HANDLE MembersKey = NULL;
221 HANDLE AliasKey = NULL;
222 ULONG Index;
224
225 TRACE("(%p %p)\n", DomainObject, MemberSid);
226
227 ConvertSidToStringSidW(MemberSid, &MemberSidString);
228 TRACE("Member SID: %S\n", MemberSidString);
229
230 Status = SampRegOpenKey(DomainObject->KeyHandle,
231 L"Aliases",
232 KEY_READ,
233 &AliasesKey);
234 if (NT_SUCCESS(Status))
235 {
236 Index = 0;
237 while (TRUE)
238 {
239 Status = SampRegEnumerateSubKey(AliasesKey,
240 Index,
241 64,
242 AliasKeyName);
243 if (!NT_SUCCESS(Status))
244 {
247 break;
248 }
249
250 TRACE("Alias key name: %S\n", AliasKeyName);
251
252 Status = SampRegOpenKey(AliasesKey,
253 AliasKeyName,
254 KEY_READ,
255 &AliasKey);
256 if (NT_SUCCESS(Status))
257 {
258 Status = SampRegOpenKey(AliasKey,
259 L"Members",
260 KEY_WRITE,
261 &MembersKey);
262 if (NT_SUCCESS(Status))
263 {
264 Status = SampRegDeleteValue(AliasKey,
265 MemberSidString);
266
267 SampRegCloseKey(&MembersKey);
268 }
271
272 SampRegCloseKey(&AliasKey);
273 }
274
275 Index++;
276 }
277
278 Status = SampRegOpenKey(AliasesKey,
279 L"Members",
280 KEY_WRITE,
281 &MembersKey);
282 if (NT_SUCCESS(Status))
283 {
284 Status = SampRegDeleteKey(MembersKey,
285 MemberSidString);
288
289 SampRegCloseKey(&MembersKey);
290 }
291
292 SampRegCloseKey(&AliasesKey);
293 }
294
295 if (MemberSidString != NULL)
296 LocalFree(MemberSidString);
297
298 return Status;
299}
NTSTATUS SampRegEnumerateSubKey(IN HANDLE KeyHandle, IN ULONG Index, IN ULONG Length, OUT LPWSTR Buffer)
Definition: registry.c:101

Referenced by SamrRemoveMemberFromForeignDomain().

◆ SampRemoveMemberFromGroup()

NTSTATUS SampRemoveMemberFromGroup ( IN PSAM_DB_OBJECT  GroupObject,
IN ULONG  MemberId 
)

Definition at line 103 of file group.c.

105{
106 PULONG MembersBuffer = NULL;
107 ULONG MembersCount = 0;
108 ULONG Length = 0;
109 ULONG i;
111
112 SampGetObjectAttribute(GroupObject,
113 L"Members",
114 NULL,
115 NULL,
116 &Length);
117
118 if (Length == 0)
120
121 MembersBuffer = midl_user_allocate(Length);
122 if (MembersBuffer == NULL)
123 {
125 goto done;
126 }
127
128 Status = SampGetObjectAttribute(GroupObject,
129 L"Members",
130 NULL,
131 MembersBuffer,
132 &Length);
133 if (!NT_SUCCESS(Status))
134 goto done;
135
137
138 MembersCount = Length / sizeof(ULONG);
139 for (i = 0; i < MembersCount; i++)
140 {
141 if (MembersBuffer[i] == MemberId)
142 {
143 Length -= sizeof(ULONG);
145
146 if (MembersCount - i - 1 > 0)
147 {
148 CopyMemory(&MembersBuffer[i],
149 &MembersBuffer[i + 1],
150 (MembersCount - i - 1) * sizeof(ULONG));
151 }
152
153 break;
154 }
155 }
156
157 if (!NT_SUCCESS(Status))
158 goto done;
159
160 Status = SampSetObjectAttribute(GroupObject,
161 L"Members",
163 MembersBuffer,
164 Length);
165
166done:
167 if (MembersBuffer != NULL)
168 midl_user_free(MembersBuffer);
169
170 return Status;
171}

Referenced by SampRemoveUserFromAllGroups(), and SamrRemoveMemberFromGroup().

◆ SampRemoveUserFromAllAliases()

NTSTATUS SampRemoveUserFromAllAliases ( IN PSAM_DB_OBJECT  UserObject)

Definition at line 391 of file user.c.

392{
393 FIXME("(%p)\n", UserObject);
394 return STATUS_SUCCESS;
395}
#define FIXME(fmt,...)
Definition: precomp.h:53

Referenced by SamrDeleteUser().

◆ SampRemoveUserFromAllGroups()

NTSTATUS SampRemoveUserFromAllGroups ( IN PSAM_DB_OBJECT  UserObject)

Definition at line 319 of file user.c.

320{
321 PGROUP_MEMBERSHIP GroupsBuffer = NULL;
322 PSAM_DB_OBJECT GroupObject;
323 ULONG Length = 0;
324 ULONG i;
326
327 SampGetObjectAttribute(UserObject,
328 L"Groups",
329 NULL,
330 NULL,
331 &Length);
332
333 if (Length == 0)
334 return STATUS_SUCCESS;
335
336 GroupsBuffer = midl_user_allocate(Length);
337 if (GroupsBuffer == NULL)
338 {
340 goto done;
341 }
342
343 Status = SampGetObjectAttribute(UserObject,
344 L"Groups",
345 NULL,
346 GroupsBuffer,
347 &Length);
348 if (!NT_SUCCESS(Status))
349 goto done;
350
351 for (i = 0; i < (Length / sizeof(GROUP_MEMBERSHIP)); i++)
352 {
353 Status = SampOpenGroupObject(UserObject->ParentObject,
354 GroupsBuffer[i].RelativeId,
355 0,
356 &GroupObject);
357 if (!NT_SUCCESS(Status))
358 {
359 goto done;
360 }
361
362 Status = SampRemoveMemberFromGroup(GroupObject,
363 UserObject->RelativeId);
366
367 SampCloseDbObject(GroupObject);
368
369 if (!NT_SUCCESS(Status))
370 {
371 goto done;
372 }
373 }
374
375 /* Remove all groups from the Groups attribute */
376 Status = SampSetObjectAttribute(UserObject,
377 L"Groups",
379 NULL,
380 0);
381
382done:
383 if (GroupsBuffer != NULL)
384 midl_user_free(GroupsBuffer);
385
386 return Status;
387}
NTSTATUS SampRemoveMemberFromGroup(IN PSAM_DB_OBJECT GroupObject, IN ULONG MemberId)
Definition: group.c:103
NTSTATUS SampOpenGroupObject(IN PSAM_DB_OBJECT DomainObject, IN ULONG GroupId, IN ACCESS_MASK DesiredAccess, OUT PSAM_DB_OBJECT *GroupObject)
Definition: group.c:14

Referenced by SamrDeleteUser().

◆ SampSetAccountNameInDomain()

NTSTATUS SampSetAccountNameInDomain ( IN PSAM_DB_OBJECT  DomainObject,
IN LPCWSTR  lpContainerName,
IN LPCWSTR  lpAccountName,
IN ULONG  ulRelativeId 
)

Definition at line 14 of file domain.c.

18{
19 HANDLE ContainerKeyHandle = NULL;
20 HANDLE NamesKeyHandle = NULL;
22
23 TRACE("SampSetAccountNameInDomain()\n");
24
25 /* Open the container key */
26 Status = SampRegOpenKey(DomainObject->KeyHandle,
27 lpContainerName,
29 &ContainerKeyHandle);
30 if (!NT_SUCCESS(Status))
31 return Status;
32
33 /* Open the 'Names' key */
34 Status = SampRegOpenKey(ContainerKeyHandle,
35 L"Names",
37 &NamesKeyHandle);
38 if (!NT_SUCCESS(Status))
39 goto done;
40
41 /* Set the alias value */
42 Status = SampRegSetValue(NamesKeyHandle,
45 (LPVOID)&ulRelativeId,
46 sizeof(ULONG));
47
48done:
49 SampRegCloseKey(&NamesKeyHandle);
50 SampRegCloseKey(&ContainerKeyHandle);
51
52 return Status;
53}

Referenced by SampSetAliasName(), SampSetGroupName(), SampSetUserName(), SamrCreateAliasInDomain(), SamrCreateGroupInDomain(), SamrCreateUser2InDomain(), and SamrCreateUserInDomain().

◆ SampSetLogonHoursAttribute()

NTSTATUS SampSetLogonHoursAttribute ( IN PSAM_DB_OBJECT  UserObject,
IN PSAMPR_LOGON_HOURS  LogonHours 
)

Definition at line 689 of file user.c.

691{
692 PUCHAR RawBuffer = NULL;
694 ULONG Length = 0;
696
697 if (LogonHours->UnitsPerWeek > 0)
698 {
699 BufferLength = (((ULONG)LogonHours->UnitsPerWeek) + 7) / 8;
700
701 Length = BufferLength + sizeof(USHORT);
702
703 RawBuffer = midl_user_allocate(Length);
704 if (RawBuffer == NULL)
705 {
707 goto done;
708 }
709
710 *((PUSHORT)RawBuffer) = LogonHours->UnitsPerWeek;
711
712 memcpy(&(RawBuffer[2]),
713 LogonHours->LogonHours,
715 }
716
717 Status = SampSetObjectAttribute(UserObject,
718 L"LogonHours",
720 RawBuffer,
721 Length);
722
723done:
724 if (RawBuffer != NULL)
725 midl_user_free(RawBuffer);
726
727 return Status;
728}

Referenced by SampSetUserAll(), and SamrSetInformationUser2().

◆ SampSetObjectAttribute()

◆ SampSetObjectAttributeString()

NTSTATUS SampSetObjectAttributeString ( PSAM_DB_OBJECT  DbObject,
LPWSTR  AttributeName,
PRPC_UNICODE_STRING  String 
)

Definition at line 595 of file database.c.

598{
600 USHORT Length = 0;
601
602 if ((String != NULL) && (String->Buffer != NULL))
603 {
604 Buffer = String->Buffer;
605 Length = String->Length + sizeof(WCHAR);
606 }
607
608 return SampSetObjectAttribute(DbObject,
609 AttributeName,
610 REG_SZ,
611 Buffer,
612 Length);
613}
#define REG_SZ
Definition: layer.c:22
uint16_t * PWCHAR
Definition: typedefs.h:56

Referenced by SampSetAliasName(), SampSetGroupName(), SampSetUserAll(), SampSetUserGeneral(), SampSetUserName(), SampSetUserPreferences(), SamrCreateAliasInDomain(), SamrCreateGroupInDomain(), SamrCreateUser2InDomain(), SamrCreateUserInDomain(), SamrSetInformationAlias(), SamrSetInformationDomain(), SamrSetInformationGroup(), and SamrSetInformationUser2().

◆ SampSetUserGroupAttributes()

NTSTATUS SampSetUserGroupAttributes ( IN PSAM_DB_OBJECT  DomainObject,
IN ULONG  UserId,
IN ULONG  GroupId,
IN ULONG  GroupAttributes 
)

Definition at line 248 of file user.c.

252{
253 PSAM_DB_OBJECT UserObject = NULL;
254 PGROUP_MEMBERSHIP GroupsBuffer = NULL;
255 ULONG Length = 0;
256 ULONG i;
258
259 Status = SampOpenUserObject(DomainObject,
260 UserId,
261 0,
262 &UserObject);
263 if (!NT_SUCCESS(Status))
264 {
265 return Status;
266 }
267
268 SampGetObjectAttribute(UserObject,
269 L"Groups",
270 NULL,
271 NULL,
272 &Length);
273
274 if (Length == 0)
275 return STATUS_UNSUCCESSFUL; /* FIXME */
276
277 GroupsBuffer = midl_user_allocate(Length);
278 if (GroupsBuffer == NULL)
279 {
281 goto done;
282 }
283
284 Status = SampGetObjectAttribute(UserObject,
285 L"Groups",
286 NULL,
287 GroupsBuffer,
288 &Length);
289 if (!NT_SUCCESS(Status))
290 goto done;
291
292 for (i = 0; i < (Length / sizeof(GROUP_MEMBERSHIP)); i++)
293 {
294 if (GroupsBuffer[i].RelativeId == GroupId)
295 {
296 GroupsBuffer[i].Attributes = GroupAttributes;
297 break;
298 }
299 }
300
301 Status = SampSetObjectAttribute(UserObject,
302 L"Groups",
304 GroupsBuffer,
305 Length);
306
307done:
308 if (GroupsBuffer != NULL)
309 midl_user_free(GroupsBuffer);
310
311 if (UserObject != NULL)
312 SampCloseDbObject(UserObject);
313
314 return Status;
315}

Referenced by SamrSetMemberAttributesOfGroup().

◆ SampSetUserPassword()

NTSTATUS SampSetUserPassword ( IN PSAM_DB_OBJECT  UserObject,
IN PENCRYPTED_NT_OWF_PASSWORD  NtPassword,
IN BOOLEAN  NtPasswordPresent,
IN PENCRYPTED_LM_OWF_PASSWORD  LmPassword,
IN BOOLEAN  LmPasswordPresent 
)

Definition at line 399 of file user.c.

404{
407 ULONG NtHistoryLength = 0;
408 ULONG LmHistoryLength = 0;
409 ULONG CurrentHistoryLength;
410 ULONG MaxHistoryLength = 3;
411 ULONG Length = 0;
412 BOOLEAN UseNtPassword;
413 BOOLEAN UseLmPassword;
415
416 UseNtPassword =
417 ((NtPasswordPresent != FALSE) &&
418 (NtPassword != NULL) &&
419 (memcmp(NtPassword, &EmptyNtHash, sizeof(ENCRYPTED_NT_OWF_PASSWORD)) != 0));
420
421 UseLmPassword =
422 ((LmPasswordPresent != FALSE) &&
423 (LmPassword != NULL) &&
424 (memcmp(LmPassword, &EmptyLmHash, sizeof(ENCRYPTED_LM_OWF_PASSWORD)) != 0));
425
426 /* Update the NT password history only if we have a new non-empty NT password */
427 if (UseNtPassword)
428 {
429 /* Get the size of the NT history */
430 SampGetObjectAttribute(UserObject,
431 L"NTPwdHistory",
432 NULL,
433 NULL,
434 &Length);
435
436 CurrentHistoryLength = Length / sizeof(ENCRYPTED_NT_OWF_PASSWORD);
437 if (CurrentHistoryLength < MaxHistoryLength)
438 {
439 NtHistoryLength = (CurrentHistoryLength + 1) * sizeof(ENCRYPTED_NT_OWF_PASSWORD);
440 }
441 else
442 {
443 NtHistoryLength = MaxHistoryLength * sizeof(ENCRYPTED_NT_OWF_PASSWORD);
444 }
445
446 /* Allocate the history buffer */
447 NtHistory = midl_user_allocate(NtHistoryLength);
448 if (NtHistory == NULL)
450
451 if (Length > 0)
452 {
453 /* Get the history */
454 Status = SampGetObjectAttribute(UserObject,
455 L"NTPwdHistory",
456 NULL,
457 NtHistory,
458 &Length);
459 if (!NT_SUCCESS(Status))
460 goto done;
461 }
462
463 /* Move the old passwords down by one entry */
464 if (NtHistoryLength > sizeof(ENCRYPTED_NT_OWF_PASSWORD))
465 {
466 MoveMemory(&(NtHistory[1]),
467 &(NtHistory[0]),
468 NtHistoryLength - sizeof(ENCRYPTED_NT_OWF_PASSWORD));
469 }
470
471 /* Add the new password to the top of the history */
472 if (NtPasswordPresent)
473 {
474 CopyMemory(&(NtHistory[0]),
475 NtPassword,
477 }
478 else
479 {
480 ZeroMemory(&(NtHistory[0]),
482 }
483
484 /* Set the history */
485 Status = SampSetObjectAttribute(UserObject,
486 L"NTPwdHistory",
488 (PVOID)NtHistory,
489 NtHistoryLength);
490 if (!NT_SUCCESS(Status))
491 goto done;
492 }
493
494 /* Update the LM password history only if we have a new non-empty LM password */
495 if (UseLmPassword)
496 {
497 /* Get the size of the LM history */
498 Length = 0;
499 SampGetObjectAttribute(UserObject,
500 L"LMPwdHistory",
501 NULL,
502 NULL,
503 &Length);
504
505 CurrentHistoryLength = Length / sizeof(ENCRYPTED_LM_OWF_PASSWORD);
506 if (CurrentHistoryLength < MaxHistoryLength)
507 {
508 LmHistoryLength = (CurrentHistoryLength + 1) * sizeof(ENCRYPTED_LM_OWF_PASSWORD);
509 }
510 else
511 {
512 LmHistoryLength = MaxHistoryLength * sizeof(ENCRYPTED_LM_OWF_PASSWORD);
513 }
514
515 /* Allocate the history buffer */
516 LmHistory = midl_user_allocate(LmHistoryLength);
517 if (LmHistory == NULL)
519
520 if (Length > 0)
521 {
522 /* Get the history */
523 Status = SampGetObjectAttribute(UserObject,
524 L"LMPwdHistory",
525 NULL,
526 LmHistory,
527 &Length);
528 if (!NT_SUCCESS(Status))
529 goto done;
530 }
531
532 /* Move the old passwords down by one entry */
533 if (LmHistoryLength > sizeof(ENCRYPTED_LM_OWF_PASSWORD))
534 {
535 MoveMemory(&(LmHistory[1]),
536 &(LmHistory[0]),
537 LmHistoryLength - sizeof(ENCRYPTED_LM_OWF_PASSWORD));
538 }
539
540 /* Add the new password to the top of the history */
541 if (LmPasswordPresent)
542 {
543 CopyMemory(&(LmHistory[0]),
544 LmPassword,
546 }
547 else
548 {
549 ZeroMemory(&(LmHistory[0]),
551 }
552
553 /* Set the LM password history */
554 Status = SampSetObjectAttribute(UserObject,
555 L"LMPwdHistory",
557 (PVOID)LmHistory,
558 LmHistoryLength);
559 if (!NT_SUCCESS(Status))
560 goto done;
561 }
562
563 /* Set the new NT password */
564 if (UseNtPassword)
565 {
566 Status = SampSetObjectAttribute(UserObject,
567 L"NTPwd",
569 (PVOID)NtPassword,
571 if (!NT_SUCCESS(Status))
572 goto done;
573 }
574 else
575 {
576 Status = SampSetObjectAttribute(UserObject,
577 L"NTPwd",
581 if (!NT_SUCCESS(Status))
582 goto done;
583 }
584
585 /* Set the new LM password */
586 if (UseLmPassword)
587 {
588 Status = SampSetObjectAttribute(UserObject,
589 L"LMPwd",
591 (PVOID)LmPassword,
593 if (!NT_SUCCESS(Status))
594 goto done;
595 }
596 else
597 {
598 Status = SampSetObjectAttribute(UserObject,
599 L"LMPwd",
603 if (!NT_SUCCESS(Status))
604 goto done;
605 }
606
607done:
608 if (NtHistory != NULL)
609 midl_user_free(NtHistory);
610
611 if (LmHistory != NULL)
612 midl_user_free(LmHistory);
613
614 return Status;
615}
unsigned char BOOLEAN
int memcmp(void *Buffer1, void *Buffer2, ACPI_SIZE Count)
Definition: utclib.c:112
struct _ENCRYPTED_LM_OWF_PASSWORD ENCRYPTED_NT_OWF_PASSWORD
struct _ENCRYPTED_LM_OWF_PASSWORD ENCRYPTED_LM_OWF_PASSWORD
ENCRYPTED_LM_OWF_PASSWORD EmptyLmHash
Definition: samsrv.c:27
ENCRYPTED_NT_OWF_PASSWORD EmptyNtHash
Definition: samsrv.c:26
#define ZeroMemory
Definition: winbase.h:1736
#define MoveMemory
Definition: winbase.h:1733

Referenced by SampSetUserAll(), SampSetUserInternal1(), and SamrChangePasswordUser().

◆ SampShutdownDisplayCache()

NTSTATUS SampShutdownDisplayCache ( VOID  )

Definition at line 164 of file display.c.

165{
166 TRACE("SampShutdownDisplayCache()\n");
167 return STATUS_SUCCESS;
168}

Referenced by SamrShutdownSamServer().

◆ SampStartRpcServer()

VOID SampStartRpcServer ( VOID  )

Definition at line 78 of file samrpc.c.

79{
81
82 TRACE("SampStartRpcServer() called\n");
83
86 L"\\pipe\\samr",
87 NULL);
88 if (Status != RPC_S_OK)
89 {
90 WARN("RpcServerUseProtseqEpW() failed (Status %lx)\n", Status);
91 return;
92 }
93
94 Status = RpcServerRegisterIf(samr_v1_0_s_ifspec,
95 NULL,
96 NULL);
97 if (Status != RPC_S_OK)
98 {
99 WARN("RpcServerRegisterIf() failed (Status %lx)\n", Status);
100 return;
101 }
102
103 Status = RpcServerListen(1, 20, TRUE);
104 if (Status != RPC_S_OK)
105 {
106 WARN("RpcServerListen() failed (Status %lx)\n", Status);
107 return;
108 }
109
110 TRACE("SampStartRpcServer() done\n");
111}
#define WARN(fmt,...)
Definition: precomp.h:61
RPC_STATUS WINAPI RpcServerListen(UINT MinimumCallThreads, UINT MaxCalls, UINT DontWait)
Definition: rpc_server.c:1520
RPC_STATUS WINAPI RpcServerRegisterIf(RPC_IF_HANDLE IfSpec, UUID *MgrTypeUuid, RPC_MGR_EPV *MgrEpv)
Definition: rpc_server.c:1116
RPC_STATUS WINAPI RpcServerUseProtseqEpW(RPC_WSTR Protseq, UINT MaxCalls, RPC_WSTR Endpoint, LPVOID SecurityDescriptor)
Definition: rpc_server.c:927
#define RPC_C_PROTSEQ_MAX_REQS_DEFAULT
Definition: rpcdce.h:123
#define RPC_S_OK
Definition: rpcnterr.h:22
long RPC_STATUS
Definition: rpc.h:52

Referenced by SamIInitialize().

◆ SampValidateDbObject()

NTSTATUS SampValidateDbObject ( SAMPR_HANDLE  Handle,
SAM_DB_OBJECT_TYPE  ObjectType,
ACCESS_MASK  DesiredAccess,
PSAM_DB_OBJECT DbObject 
)

Definition at line 301 of file database.c.

305{
306 PSAM_DB_OBJECT LocalObject = (PSAM_DB_OBJECT)Handle;
307 BOOLEAN bValid = FALSE;
308
310 {
311 if (LocalObject->Signature == SAMP_DB_SIGNATURE)
312 {
313 if ((ObjectType == SamDbIgnoreObject) ||
314 (LocalObject->ObjectType == ObjectType))
315 bValid = TRUE;
316 }
317 }
319 {
320 bValid = FALSE;
321 }
322 _SEH2_END;
323
324 if (bValid == FALSE)
326
327 if (DesiredAccess != 0)
328 {
329 /* Check for granted access rights */
330 if ((LocalObject->Access & DesiredAccess) != DesiredAccess)
331 {
332 ERR("SampValidateDbObject access check failed %08lx %08lx\n",
333 LocalObject->Access, DesiredAccess);
335 }
336 }
337
338 if (DbObject != NULL)
339 *DbObject = LocalObject;
340
341 return STATUS_SUCCESS;
342}
#define STATUS_INVALID_HANDLE
Definition: d3dkmdt.h:40
struct _SAM_DB_OBJECT * PSAM_DB_OBJECT
#define _SEH2_END
Definition: filesup.c:22
#define _SEH2_TRY
Definition: filesup.c:19
ULONG Handle
Definition: gdb_input.c:15
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:66
ACCESS_MASK Access
Definition: samsrv.h:50
ULONG Signature
Definition: samsrv.h:47
#define STATUS_ACCESS_DENIED
Definition: udferr_usr.h:145

Referenced by SamrAddMemberToAlias(), SamrAddMemberToGroup(), SamrChangePasswordUser(), SamrCloseHandle(), SamrCreateAliasInDomain(), SamrCreateGroupInDomain(), SamrCreateUser2InDomain(), SamrCreateUserInDomain(), SamrDeleteAlias(), SamrDeleteGroup(), SamrDeleteUser(), SamrEnumerateAliasesInDomain(), SamrEnumerateDomainsInSamServer(), SamrEnumerateGroupsInDomain(), SamrEnumerateUsersInDomain(), SamrGetAliasMembership(), SamrGetGroupsForUser(), SamrGetMembersInAlias(), SamrGetMembersInGroup(), SamrGetUserDomainPasswordInformation(), SamrLookupDomainInSamServer(), SamrLookupIdsInDomain(), SamrLookupNamesInDomain(), SamrOpenAlias(), SamrOpenDomain(), SamrOpenGroup(), SamrOpenUser(), SamrQueryDisplayInformation3(), SamrQueryInformationAlias(), SamrQueryInformationDomain2(), SamrQueryInformationGroup(), SamrQueryInformationUser2(), SamrQuerySecurityObject(), SamrRemoveMemberFromAlias(), SamrRemoveMemberFromForeignDomain(), SamrRemoveMemberFromGroup(), SamrSetInformationAlias(), SamrSetInformationDomain(), SamrSetInformationGroup(), SamrSetInformationUser2(), SamrSetMemberAttributesOfGroup(), SamrSetSecurityObject(), and SamrShutdownSamServer().

◆ SystemFunction006()

NTSTATUS WINAPI SystemFunction006 ( LPCSTR  password,
LPSTR  hash 
)

Definition at line 53 of file crypt_lmhash.c.

54{
55 CRYPT_LMhash( (unsigned char*)hash, (const unsigned char*)password, strlen(password) );
56
57 return STATUS_SUCCESS;
58}
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
static void CRYPT_LMhash(unsigned char *dst, const unsigned char *pwd, const int len)
Definition: crypt_lmhash.c:39
static WCHAR password[]
Definition: url.c:33
Definition: _hash_fun.h:40

Referenced by MsvpChangePassword(), MsvpCheckPassword(), and SampInitHashes().

◆ SystemFunction007()

NTSTATUS WINAPI SystemFunction007 ( PUNICODE_STRING  string,
LPBYTE  hash 
)

◆ SystemFunction013()

NTSTATUS WINAPI SystemFunction013 ( const BYTE in,
const BYTE key,
LPBYTE  out 
)

Definition at line 383 of file sysfunc.c.

384{
385 if (!in || !out)
386 return STATUS_UNSUCCESSFUL;
388 CRYPT_DESunhash(out+8, key+7, in+8);
389 return STATUS_SUCCESS;
390}
unsigned char * CRYPT_DESunhash(unsigned char *dst, const unsigned char *key, const unsigned char *src) DECLSPEC_HIDDEN
Definition: crypt_des.c:299
GLuint in
Definition: glext.h:9616
static FILE * out
Definition: regtests2xml.c:44
Definition: copy.c:22

Referenced by SamrChangePasswordUser().

◆ WINE_DEFAULT_DEBUG_CHANNEL()

WINE_DEFAULT_DEBUG_CHANNEL ( samsrv  )

Variable Documentation

◆ EmptyLmHash

◆ EmptyNtHash

◆ pServerMapping

PGENERIC_MAPPING pServerMapping
extern

Definition at line 56 of file samrpc.c.

Referenced by SamIConnect().

◆ SampProductType

NT_PRODUCT_TYPE SampProductType
extern

Definition at line 29 of file samsrv.c.

Referenced by SamIInitialize(), and SampInitializeSAM().

◆ SampResource