ReactOS 0.4.15-dev-7918-g2a2556c
sid.c File Reference
#include "precomp.h"
#include <ndk/sefuncs.h>
#include <debug.h>
Include dependency graph for sid.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

PSID WINAPI GetUserSid (HANDLE hToken)
 
BOOL GetUserSidStringFromToken (HANDLE hToken, PUNICODE_STRING SidString)
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 31 of file sid.c.

Function Documentation

◆ GetUserSid()

PSID WINAPI GetUserSid ( HANDLE  hToken)

Definition at line 36 of file sid.c.

37{
38 PTOKEN_USER UserBuffer;
39 PTOKEN_USER TempBuffer;
42 PSID pSid;
43
44 Length = 256;
45 UserBuffer = LocalAlloc(LPTR, Length);
46 if (UserBuffer == NULL)
47 {
48 return NULL;
49 }
50
53 (PVOID)UserBuffer,
54 Length,
55 &Length);
57 {
58 TempBuffer = LocalReAlloc(UserBuffer, Length, LMEM_MOVEABLE);
59 if (TempBuffer == NULL)
60 {
61 LocalFree(UserBuffer);
62 return NULL;
63 }
64
65 UserBuffer = TempBuffer;
68 (PVOID)UserBuffer,
69 Length,
70 &Length);
71 }
72
73 if (!NT_SUCCESS(Status))
74 {
75 LocalFree(UserBuffer);
76 return NULL;
77 }
78
79 Length = RtlLengthSid(UserBuffer->User.Sid);
80
82 if (pSid == NULL)
83 {
84 LocalFree(UserBuffer);
85 return NULL;
86 }
87
88 Status = RtlCopySid(Length, pSid, UserBuffer->User.Sid);
89
90 LocalFree(UserBuffer);
91
92 if (!NT_SUCCESS(Status))
93 {
95 return NULL;
96 }
97
98 return pSid;
99}
LONG NTSTATUS
Definition: precomp.h:26
#define NULL
Definition: types.h:112
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
Status
Definition: gdiplustypes.h:25
HLOCAL NTAPI LocalReAlloc(HLOCAL hMem, SIZE_T dwBytes, UINT uFlags)
Definition: heapmem.c:1625
HLOCAL NTAPI LocalAlloc(UINT uFlags, SIZE_T dwBytes)
Definition: heapmem.c:1390
HLOCAL NTAPI LocalFree(HLOCAL hMem)
Definition: heapmem.c:1594
NTSYSAPI BOOLEAN WINAPI RtlCopySid(DWORD, PSID, PSID)
static PSID pSid
Definition: security.c:74
NTSYSAPI ULONG NTAPI RtlLengthSid(IN PSID Sid)
Definition: sid.c:150
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:102
#define STATUS_BUFFER_TOO_SMALL
Definition: shellext.h:69
SID_AND_ATTRIBUTES User
Definition: setypes.h:1010
_Must_inspect_result_ __kernel_entry NTSTATUS NTAPI NtQueryInformationToken(_In_ HANDLE TokenHandle, _In_ TOKEN_INFORMATION_CLASS TokenInformationClass, _Out_writes_bytes_to_opt_(TokenInformationLength, *ReturnLength) PVOID TokenInformation, _In_ ULONG TokenInformationLength, _Out_ PULONG ReturnLength)
Queries a specific type of information in regard of an access token based upon the information class....
Definition: tokencls.c:473
uint32_t ULONG
Definition: typedefs.h:59
#define LMEM_MOVEABLE
Definition: winbase.h:369
#define LPTR
Definition: winbase.h:381
@ TokenUser
Definition: setypes.h:966

Referenced by CopySystemProfile(), and GetUserAndDomainName().

◆ GetUserSidStringFromToken()

BOOL GetUserSidStringFromToken ( HANDLE  hToken,
PUNICODE_STRING  SidString 
)

Definition at line 102 of file sid.c.

104{
105 PTOKEN_USER UserBuffer, nsb;
108
109 Length = 256;
110 UserBuffer = LocalAlloc(LPTR, Length);
111 if (UserBuffer == NULL)
112 return FALSE;
113
115 TokenUser,
116 (PVOID)UserBuffer,
117 Length,
118 &Length);
120 {
121 nsb = LocalReAlloc(UserBuffer,
122 Length,
124 if (nsb == NULL)
125 {
126 LocalFree(UserBuffer);
127 return FALSE;
128 }
129
130 UserBuffer = nsb;
132 TokenUser,
133 (PVOID)UserBuffer,
134 Length,
135 &Length);
136 }
137
138 if (!NT_SUCCESS (Status))
139 {
140 LocalFree(UserBuffer);
142 return FALSE;
143 }
144
145 DPRINT("SidLength: %lu\n", RtlLengthSid (UserBuffer->User.Sid));
146
148 UserBuffer->User.Sid,
149 TRUE);
150
151 LocalFree(UserBuffer);
152
153 if (!NT_SUCCESS(Status))
154 {
156 return FALSE;
157 }
158
159 DPRINT("SidString.Length: %lu\n", SidString->Length);
160 DPRINT("SidString.MaximumLength: %lu\n", SidString->MaximumLength);
161 DPRINT("SidString: '%wZ'\n", SidString);
162
163 return TRUE;
164}
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define SetLastError(x)
Definition: compat.h:752
NTSYSAPI ULONG WINAPI RtlNtStatusToDosError(NTSTATUS)
NTSYSAPI NTSTATUS NTAPI RtlConvertSidToUnicodeString(OUT PUNICODE_STRING DestinationString, IN PVOID Sid, IN BOOLEAN AllocateDestinationString)
#define DPRINT
Definition: sndvol32.h:71
USHORT MaximumLength
Definition: env_spec_w32.h:370

Referenced by CheckForLoadedProfile(), CopySystemProfile(), GetCurrentUserKey(), GetProfileType(), GetUserProfileDirectoryW(), LoadUserProfileW(), and UnloadUserProfile().