Added some rtl functions
[reactos.git] / reactos / ntoskrnl / se / sid.c
1 /* $Id: sid.c,v 1.4 2000/04/15 23:14:32 ekohl Exp $
2 *
3 * COPYRIGHT: See COPYING in the top level directory
4 * PROJECT: ReactOS kernel
5 * PURPOSE: Security manager
6 * FILE: ntoskrnl/se/sid.c
7 * PROGRAMER: David Welch <welch@cwcom.net>
8 * REVISION HISTORY:
9 * 26/07/98: Added stubs for security functions
10 */
11
12 /* INCLUDES *****************************************************************/
13
14 #include <ddk/ntddk.h>
15
16 #include <internal/debug.h>
17
18 /* FUNCTIONS ***************************************************************/
19
20 BOOLEAN STDCALL RtlValidSid (PSID Sid)
21 {
22 if ((Sid->Revision & 0xf) != 1)
23 {
24 return(FALSE);
25 }
26 if (Sid->SubAuthorityCount > 15)
27 {
28 return(FALSE);
29 }
30 return(TRUE);
31 }
32
33 ULONG STDCALL RtlLengthRequiredSid (UCHAR SubAuthorityCount)
34 {
35 return(sizeof(SID) + (SubAuthorityCount - 1) * sizeof(ULONG));
36 }
37
38 NTSTATUS STDCALL RtlInitializeSid (PSID Sid,
39 PSID_IDENTIFIER_AUTHORITY IdentifierAuthority,
40 UCHAR SubAuthorityCount)
41 {
42 Sid->Revision = 1;
43 Sid->SubAuthorityCount = SubAuthorityCount;
44 memcpy(&Sid->IdentifierAuthority, IdentifierAuthority,
45 sizeof(SID_IDENTIFIER_AUTHORITY));
46 return(STATUS_SUCCESS);
47 }
48
49 PULONG STDCALL RtlSubAuthoritySid (PSID Sid, ULONG SubAuthority)
50 {
51 return(&Sid->SubAuthority[SubAuthority]);
52 }
53
54 PUCHAR STDCALL RtlSubAuthorityCountSid (PSID Sid)
55 {
56 return(&Sid->SubAuthorityCount);
57 }
58
59 BOOLEAN STDCALL RtlEqualSid (PSID Sid1, PSID Sid2)
60 {
61 if (Sid1->Revision != Sid2->Revision)
62 {
63 return(FALSE);
64 }
65 if ((*RtlSubAuthorityCountSid(Sid1)) !=
66 (*RtlSubAuthorityCountSid(Sid2)))
67 {
68 return(FALSE);
69 }
70 if (memcmp(Sid1, Sid2, RtlLengthSid(Sid1) != 0))
71 {
72 return(FALSE);
73 }
74 return(TRUE);
75 }
76
77 ULONG STDCALL RtlLengthSid (PSID Sid)
78 {
79 return(sizeof(SID) + (Sid->SubAuthorityCount-1)*4);
80 }
81
82 NTSTATUS STDCALL RtlCopySid (ULONG BufferLength, PSID Dest, PSID Src)
83 {
84 if (BufferLength < RtlLengthSid(Src))
85 {
86 return(STATUS_UNSUCCESSFUL);
87 }
88 memmove(Dest, Src, RtlLengthSid(Src));
89 return(STATUS_SUCCESS);
90 }
91
92 /* EOF */