ReactOS 0.4.16-dev-117-g38f21f9
utils.c File Reference
#include "netapi32.h"
Include dependency graph for utils.c:

Go to the source code of this file.

Functions

 WINE_DEFAULT_DEBUG_CHANNEL (netapi32)
 
NTSTATUS GetAccountDomainSid (IN PUNICODE_STRING ServerName, OUT PSID *AccountDomainSid)
 
NTSTATUS GetBuiltinDomainSid (OUT PSID *BuiltinDomainSid)
 
NTSTATUS OpenAccountDomain (IN SAM_HANDLE ServerHandle, IN PUNICODE_STRING ServerName, IN ULONG DesiredAccess, OUT PSAM_HANDLE DomainHandle)
 
NTSTATUS OpenBuiltinDomain (IN SAM_HANDLE ServerHandle, IN ULONG DesiredAccess, OUT PSAM_HANDLE DomainHandle)
 
NET_API_STATUS BuildSidFromSidAndRid (IN PSID SrcSid, IN ULONG RelativeId, OUT PSID *DestSid)
 
VOID CopySidFromSidAndRid (_Out_ PSID DstSid, _In_ PSID SrcSid, _In_ ULONG RelativeId)
 

Variables

static SID_IDENTIFIER_AUTHORITY NtAuthority = {SECURITY_NT_AUTHORITY}
 

Function Documentation

◆ BuildSidFromSidAndRid()

NET_API_STATUS BuildSidFromSidAndRid ( IN PSID  SrcSid,
IN ULONG  RelativeId,
OUT PSID DestSid 
)

Definition at line 177 of file utils.c.

180{
181 UCHAR RidCount;
182 PSID DstSid;
183 ULONG i;
184 ULONG DstSidSize;
185 PULONG p, q;
186 NET_API_STATUS ApiStatus = NERR_Success;
187
188 RidCount = *RtlSubAuthorityCountSid(SrcSid);
189 if (RidCount >= 8)
191
192 DstSidSize = RtlLengthRequiredSid(RidCount + 1);
193
194 ApiStatus = NetApiBufferAllocate(DstSidSize,
195 &DstSid);
196 if (ApiStatus != NERR_Success)
197 return ApiStatus;
198
199 RtlInitializeSid(DstSid,
201 RidCount + 1);
202
203 for (i = 0; i < (ULONG)RidCount; i++)
204 {
205 p = RtlSubAuthoritySid(SrcSid, i);
206 q = RtlSubAuthoritySid(DstSid, i);
207 *q = *p;
208 }
209
210 q = RtlSubAuthoritySid(DstSid, (ULONG)RidCount);
211 *q = RelativeId;
212
213 *DestSid = DstSid;
214
215 return NERR_Success;
216}
#define ERROR_INVALID_PARAMETER
Definition: compat.h:101
NET_API_STATUS WINAPI NetApiBufferAllocate(DWORD ByteCount, LPVOID *Buffer)
Definition: apibuf.c:28
GLdouble GLdouble GLdouble GLdouble q
Definition: gl.h:2063
GLfloat GLfloat p
Definition: glext.h:8902
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
#define NERR_Success
Definition: lmerr.h:5
DWORD NET_API_STATUS
Definition: ms-dtyp.idl:91
NTSYSAPI PULONG NTAPI RtlSubAuthoritySid(_In_ PSID Sid, _In_ ULONG SubAuthority)
NTSYSAPI ULONG NTAPI RtlLengthRequiredSid(IN ULONG SubAuthorityCount)
Definition: sid.c:54
NTSYSAPI PSID_IDENTIFIER_AUTHORITY NTAPI RtlIdentifierAuthoritySid(PSID Sid)
NTSYSAPI PUCHAR NTAPI RtlSubAuthorityCountSid(IN PSID Sid)
Definition: sid.c:104
NTSYSAPI NTSTATUS NTAPI RtlInitializeSid(IN OUT PSID Sid, IN PSID_IDENTIFIER_AUTHORITY IdentifierAuthority, IN UCHAR SubAuthorityCount)
uint32_t * PULONG
Definition: typedefs.h:59
uint32_t ULONG
Definition: typedefs.h:59
unsigned char UCHAR
Definition: xmlstorage.h:181

Referenced by BuildSidListFromDomainAndName(), GetUserPrivileges(), and NetUserGetLocalGroups().

◆ CopySidFromSidAndRid()

VOID CopySidFromSidAndRid ( _Out_ PSID  DstSid,
_In_ PSID  SrcSid,
_In_ ULONG  RelativeId 
)

Definition at line 220 of file utils.c.

224{
225 UCHAR RidCount;
226 ULONG i;
227 PULONG p, q;
228
229 RidCount = *RtlSubAuthorityCountSid(SrcSid);
230 if (RidCount >= 8)
231 return;
232
233 RtlInitializeSid(DstSid,
235 RidCount + 1);
236
237 for (i = 0; i < (ULONG)RidCount; i++)
238 {
239 p = RtlSubAuthoritySid(SrcSid, i);
240 q = RtlSubAuthoritySid(DstSid, i);
241 *q = *p;
242 }
243
244 q = RtlSubAuthoritySid(DstSid, (ULONG)RidCount);
245 *q = RelativeId;
246}

Referenced by BuildUserInfoBuffer().

◆ GetAccountDomainSid()

NTSTATUS GetAccountDomainSid ( IN PUNICODE_STRING  ServerName,
OUT PSID AccountDomainSid 
)

Definition at line 23 of file utils.c.

25{
26 PPOLICY_ACCOUNT_DOMAIN_INFO AccountDomainInfo = NULL;
28 LSA_HANDLE PolicyHandle = NULL;
29 ULONG Length = 0;
31
33
34 Status = LsaOpenPolicy(ServerName,
37 &PolicyHandle);
38 if (!NT_SUCCESS(Status))
39 {
40 ERR("LsaOpenPolicy failed (Status %08lx)\n", Status);
41 return Status;
42 }
43
44 Status = LsaQueryInformationPolicy(PolicyHandle,
46 (PVOID *)&AccountDomainInfo);
47 if (!NT_SUCCESS(Status))
48 {
49 ERR("LsaQueryInformationPolicy failed (Status %08lx)\n", Status);
50 goto done;
51 }
52
53 Length = RtlLengthSid(AccountDomainInfo->DomainSid);
54
55 *AccountDomainSid = RtlAllocateHeap(RtlGetProcessHeap(), 0, Length);
56 if (*AccountDomainSid == NULL)
57 {
58 ERR("Failed to allocate SID\n");
60 goto done;
61 }
62
63 memcpy(*AccountDomainSid, AccountDomainInfo->DomainSid, Length);
64
65done:
66 if (AccountDomainInfo != NULL)
67 LsaFreeMemory(AccountDomainInfo);
68
69 LsaClose(PolicyHandle);
70
71 return Status;
72}
LONG NTSTATUS
Definition: precomp.h:26
#define ERR(fmt,...)
Definition: precomp.h:57
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:590
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:36
#define NULL
Definition: types.h:112
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
NTSTATUS WINAPI LsaOpenPolicy(IN PLSA_UNICODE_STRING SystemName OPTIONAL, IN PLSA_OBJECT_ATTRIBUTES ObjectAttributes, IN ACCESS_MASK DesiredAccess, OUT PLSA_HANDLE PolicyHandle)
Definition: lsa.c:1183
NTSTATUS WINAPI LsaQueryInformationPolicy(IN LSA_HANDLE PolicyHandle, IN POLICY_INFORMATION_CLASS InformationClass, OUT PVOID *Buffer)
Definition: lsa.c:1473
NTSTATUS WINAPI LsaFreeMemory(IN PVOID Buffer)
Definition: lsa.c:701
NTSTATUS WINAPI LsaClose(IN LSA_HANDLE ObjectHandle)
Definition: lsa.c:194
PSID AccountDomainSid
Definition: database.c:24
Status
Definition: gdiplustypes.h:25
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
NTSYSAPI ULONG NTAPI RtlLengthSid(IN PSID Sid)
Definition: sid.c:150
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:102
@ PolicyAccountDomainInformation
Definition: ntsecapi.h:247
#define POLICY_VIEW_LOCAL_INFORMATION
Definition: ntsecapi.h:61
#define memset(x, y, z)
Definition: compat.h:39
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158

Referenced by OpenAccountDomain().

◆ GetBuiltinDomainSid()

NTSTATUS GetBuiltinDomainSid ( OUT PSID BuiltinDomainSid)

Definition at line 76 of file utils.c.

77{
78 PSID Sid = NULL;
79 PULONG Ptr;
81
83
84 Sid = RtlAllocateHeap(RtlGetProcessHeap(),
85 0,
87 if (Sid == NULL)
89
92 1);
93 if (!NT_SUCCESS(Status))
94 goto done;
95
98
100
101done:
102 if (!NT_SUCCESS(Status))
103 {
104 if (Sid != NULL)
105 RtlFreeHeap(RtlGetProcessHeap(), 0, Sid);
106 }
107
108 return Status;
109}
PSID BuiltinDomainSid
Definition: globals.c:16
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:608
static SID_IDENTIFIER_AUTHORITY NtAuthority
Definition: utils.c:18
_Must_inspect_result_ _In_ PFSRTL_PER_STREAM_CONTEXT Ptr
Definition: fsrtlfuncs.h:898
_In_ ULONG _In_ ACCESS_MASK _In_ PSID Sid
Definition: rtlfuncs.h:1145
#define STATUS_SUCCESS
Definition: shellext.h:65
#define SECURITY_BUILTIN_DOMAIN_RID
Definition: setypes.h:581

Referenced by NetUserEnum(), NetUserGetInfo(), and OpenBuiltinDomain().

◆ OpenAccountDomain()

NTSTATUS OpenAccountDomain ( IN SAM_HANDLE  ServerHandle,
IN PUNICODE_STRING  ServerName,
IN ULONG  DesiredAccess,
OUT PSAM_HANDLE  DomainHandle 
)

Definition at line 113 of file utils.c.

117{
118 PSID DomainSid = NULL;
120
121 Status = GetAccountDomainSid(ServerName,
122 &DomainSid);
123 if (!NT_SUCCESS(Status))
124 {
125 ERR("GetAccountDomainSid failed (Status %08lx)\n", Status);
126 return Status;
127 }
128
129 Status = SamOpenDomain(ServerHandle,
131 DomainSid,
132 DomainHandle);
133
134 RtlFreeHeap(RtlGetProcessHeap(), 0, DomainSid);
135
136 if (!NT_SUCCESS(Status))
137 {
138 ERR("SamOpenDomain failed (Status %08lx)\n", Status);
139 }
140
141 return Status;
142}
NTSTATUS GetAccountDomainSid(IN PUNICODE_STRING ServerName, OUT PSID *AccountDomainSid)
Definition: utils.c:23
NTSTATUS NTAPI SamOpenDomain(IN SAM_HANDLE ServerHandle, IN ACCESS_MASK DesiredAccess, IN PSID DomainId, OUT PSAM_HANDLE DomainHandle)
Definition: samlib.c:1477
_Must_inspect_result_ _In_ WDFDEVICE _In_ ULONG _In_ ACCESS_MASK DesiredAccess
Definition: wdfdevice.h:2658

Referenced by NetGetDisplayInformationIndex(), NetGroupAdd(), NetGroupAddUser(), NetGroupDel(), NetGroupDelUser(), NetGroupEnum(), NetGroupGetInfo(), NetGroupGetUsers(), NetGroupSetInfo(), NetGroupSetUsers(), NetLocalGroupAdd(), NetLocalGroupAddMembers(), NetLocalGroupDel(), NetLocalGroupDelMembers(), NetLocalGroupEnum(), NetLocalGroupGetInfo(), NetLocalGroupGetMembers(), NetLocalGroupSetInfo(), NetQueryDisplayInformation(), NetUserAdd(), NetUserDel(), and NetUserSetInfo().

◆ OpenBuiltinDomain()

NTSTATUS OpenBuiltinDomain ( IN SAM_HANDLE  ServerHandle,
IN ULONG  DesiredAccess,
OUT PSAM_HANDLE  DomainHandle 
)

Definition at line 146 of file utils.c.

149{
150 PSID DomainSid = NULL;
152
153 Status = GetBuiltinDomainSid(&DomainSid);
154 if (!NT_SUCCESS(Status))
155 {
156 ERR("GetBuiltinDomainSid failed (Status %08lx)\n", Status);
157 return Status;
158 }
159
160 Status = SamOpenDomain(ServerHandle,
162 DomainSid,
163 DomainHandle);
164
165 RtlFreeHeap(RtlGetProcessHeap(), 0, DomainSid);
166
167 if (!NT_SUCCESS(Status))
168 {
169 ERR("SamOpenDomain failed (Status %08lx)\n", Status);
170 }
171
172 return Status;
173}
NTSTATUS GetBuiltinDomainSid(OUT PSID *BuiltinDomainSid)
Definition: utils.c:76

◆ WINE_DEFAULT_DEBUG_CHANNEL()

WINE_DEFAULT_DEBUG_CHANNEL ( netapi32  )

Variable Documentation

◆ NtAuthority

Definition at line 18 of file utils.c.

Referenced by GetBuiltinDomainSid().