ReactOS 0.4.15-dev-7889-g76290a6
sid.c
Go to the documentation of this file.
1/*
2 * ReactOS kernel
3 * Copyright (C) 2004 ReactOS Team
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19/*
20 * COPYRIGHT: See COPYING in the top level directory
21 * PROJECT: ReactOS system libraries
22 * FILE: dll/win32/userenv/sid.c
23 * PURPOSE: User profile code
24 * PROGRAMMER: Eric Kohl
25 */
26
27#include "precomp.h"
28
29#include <ndk/sefuncs.h>
30
31#define NDEBUG
32#include <debug.h>
33
34PSID
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}
100
101BOOL
103 PUNICODE_STRING SidString)
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}
LONG NTSTATUS
Definition: precomp.h:26
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define SetLastError(x)
Definition: compat.h:752
PSID WINAPI GetUserSid(HANDLE hToken)
Definition: sid.c:36
BOOL GetUserSidStringFromToken(HANDLE hToken, PUNICODE_STRING SidString)
Definition: sid.c:102
unsigned int BOOL
Definition: ntddk_ex.h:94
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 ULONG WINAPI RtlNtStatusToDosError(NTSTATUS)
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
NTSYSAPI NTSTATUS NTAPI RtlConvertSidToUnicodeString(OUT PUNICODE_STRING DestinationString, IN PVOID Sid, IN BOOLEAN AllocateDestinationString)
#define STATUS_BUFFER_TOO_SMALL
Definition: shellext.h:69
#define DPRINT
Definition: sndvol32.h:71
SID_AND_ATTRIBUTES User
Definition: setypes.h:1010
USHORT MaximumLength
Definition: env_spec_w32.h:370
_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
#define WINAPI
Definition: msvc.h:6
@ TokenUser
Definition: setypes.h:966