3 * COPYRIGHT: See COPYING in the top level directory
4 * PROJECT: ReactOS kernel
5 * PURPOSE: Security manager
7 * PROGRAMER: David Welch <welch@cwcom.net>
9 * 26/07/98: Added stubs for security functions
12 /* INCLUDES *****************************************************************/
15 #include <ddk/ntddk.h>
16 #include <ntdll/rtl.h>
23 /* FUNCTIONS ***************************************************************/
26 RtlValidSid(IN PSID Sid_
)
32 if ((Sid
->Revision
!= SID_REVISION
) ||
33 (Sid
->SubAuthorityCount
> SID_MAX_SUB_AUTHORITIES
))
46 RtlLengthRequiredSid(IN UCHAR SubAuthorityCount
)
50 return (sizeof(SID
) + (SubAuthorityCount
- 1) * sizeof(ULONG
));
58 RtlInitializeSid(IN PSID Sid_
,
59 IN PSID_IDENTIFIER_AUTHORITY IdentifierAuthority
,
60 IN UCHAR SubAuthorityCount
)
66 Sid
->Revision
= SID_REVISION
;
67 Sid
->SubAuthorityCount
= SubAuthorityCount
;
68 memcpy(&Sid
->IdentifierAuthority
,
70 sizeof(SID_IDENTIFIER_AUTHORITY
));
72 return STATUS_SUCCESS
;
80 RtlSubAuthoritySid(IN PSID Sid_
,
81 IN ULONG SubAuthority
)
87 return &Sid
->SubAuthority
[SubAuthority
];
95 RtlSubAuthorityCountSid(IN PSID Sid_
)
101 return &Sid
->SubAuthorityCount
;
109 RtlEqualSid(IN PSID Sid1_
,
117 if (Sid1
->Revision
!= Sid2
->Revision
)
121 if ((*RtlSubAuthorityCountSid(Sid1
)) != (*RtlSubAuthorityCountSid(Sid2
)))
125 if (RtlCompareMemory(Sid1
, Sid2
, RtlLengthSid(Sid1
)) != RtlLengthSid(Sid1
))
137 RtlLengthSid(IN PSID Sid_
)
143 return (sizeof(SID
) + (Sid
->SubAuthorityCount
-1) * sizeof(ULONG
));
151 RtlCopySid(ULONG BufferLength
,
157 if (BufferLength
< RtlLengthSid(Src
))
159 return STATUS_UNSUCCESSFUL
;
166 return STATUS_SUCCESS
;
174 RtlCopySidAndAttributesArray(ULONG Count
,
175 PSID_AND_ATTRIBUTES Src
,
177 PSID_AND_ATTRIBUTES Dest
,
179 PVOID
* RemainingSidArea
,
180 PULONG RemainingSidAreaSize
)
188 Length
= SidAreaSize
;
190 for (i
=0; i
<Count
; i
++)
192 if (RtlLengthSid(Src
[i
].Sid
) > Length
)
194 return(STATUS_BUFFER_TOO_SMALL
);
196 SidLength
= RtlLengthSid(Src
[i
].Sid
);
197 Length
= Length
- SidLength
;
198 Dest
[i
].Sid
= SidArea
;
199 Dest
[i
].Attributes
= Src
[i
].Attributes
;
200 RtlCopySid(SidLength
,
203 SidArea
= SidArea
+ SidLength
;
205 *RemainingSidArea
= SidArea
;
206 *RemainingSidAreaSize
= Length
;
207 return(STATUS_SUCCESS
);
214 PSID_IDENTIFIER_AUTHORITY STDCALL
215 RtlIdentifierAuthoritySid(IN PSID Sid_
)
221 return &Sid
->IdentifierAuthority
;
229 RtlAllocateAndInitializeSid(PSID_IDENTIFIER_AUTHORITY IdentifierAuthority
,
230 UCHAR SubAuthorityCount
,
245 if (SubAuthorityCount
> 8)
246 return STATUS_INVALID_SID
;
249 return STATUS_INVALID_PARAMETER
;
251 pSid
= (PSID
)ExAllocatePool(PagedPool
,
252 sizeof(SID
) + (SubAuthorityCount
- 1) * sizeof(ULONG
));
254 return STATUS_NO_MEMORY
;
256 pSid
->Revision
= SID_REVISION
;
257 pSid
->SubAuthorityCount
= SubAuthorityCount
;
258 memcpy(&pSid
->IdentifierAuthority
,
260 sizeof(SID_IDENTIFIER_AUTHORITY
));
262 switch (SubAuthorityCount
)
265 pSid
->SubAuthority
[7] = SubAuthority7
;
267 pSid
->SubAuthority
[6] = SubAuthority6
;
269 pSid
->SubAuthority
[5] = SubAuthority5
;
271 pSid
->SubAuthority
[4] = SubAuthority4
;
273 pSid
->SubAuthority
[3] = SubAuthority3
;
275 pSid
->SubAuthority
[2] = SubAuthority2
;
277 pSid
->SubAuthority
[1] = SubAuthority1
;
279 pSid
->SubAuthority
[0] = SubAuthority0
;
285 return STATUS_SUCCESS
;
293 * Docs says FreeSid does NOT return a value
294 * even thou it's defined to return a PVOID...
297 RtlFreeSid(IN PSID Sid
)
310 RtlEqualPrefixSid(IN PSID Sid1_
,
318 return(Sid1
->SubAuthorityCount
== Sid2
->SubAuthorityCount
&&
319 !RtlCompareMemory(Sid1
, Sid2
,
320 (Sid1
->SubAuthorityCount
- 1) * sizeof(DWORD
) + 8));
328 RtlConvertSidToUnicodeString(PUNICODE_STRING String
,
330 BOOLEAN AllocateBuffer
)
340 if (RtlValidSid (Sid
) == FALSE
)
341 return STATUS_INVALID_SID
;
344 wcs
+= swprintf (wcs
, L
"S-%u-", Sid
->Revision
);
345 if (Sid
->IdentifierAuthority
.Value
[0] == 0 &&
346 Sid
->IdentifierAuthority
.Value
[1] == 0)
348 wcs
+= swprintf (wcs
,
350 (ULONG
)Sid
->IdentifierAuthority
.Value
[2] << 24 |
351 (ULONG
)Sid
->IdentifierAuthority
.Value
[3] << 16 |
352 (ULONG
)Sid
->IdentifierAuthority
.Value
[4] << 8 |
353 (ULONG
)Sid
->IdentifierAuthority
.Value
[5]);
357 wcs
+= swprintf (wcs
,
358 L
"0x%02hx%02hx%02hx%02hx%02hx%02hx",
359 Sid
->IdentifierAuthority
.Value
[0],
360 Sid
->IdentifierAuthority
.Value
[1],
361 Sid
->IdentifierAuthority
.Value
[2],
362 Sid
->IdentifierAuthority
.Value
[3],
363 Sid
->IdentifierAuthority
.Value
[4],
364 Sid
->IdentifierAuthority
.Value
[5]);
367 for (i
= 0; i
< Sid
->SubAuthorityCount
; i
++)
369 wcs
+= swprintf (wcs
,
371 Sid
->SubAuthority
[i
]);
374 Length
= (wcs
- Buffer
) * sizeof(WCHAR
);
377 String
->Buffer
= ExAllocatePool(PagedPool
,Length
+ sizeof(WCHAR
));
378 if (String
->Buffer
== NULL
)
379 return STATUS_NO_MEMORY
;
380 String
->MaximumLength
= Length
+ sizeof(WCHAR
);
384 if (Length
> String
->MaximumLength
)
385 return STATUS_BUFFER_TOO_SMALL
;
388 String
->Length
= Length
;
389 RtlCopyMemory (String
->Buffer
,
392 if (Length
< String
->MaximumLength
)
393 String
->Buffer
[Length
/ sizeof(WCHAR
)] = 0;
395 return STATUS_SUCCESS
;