1 /* $Id: sid.c,v 1.6 2000/10/08 19:12:01 ekohl Exp $
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>
9 * 26/07/98: Added stubs for security functions
12 /* INCLUDES *****************************************************************/
14 #include <ddk/ntddk.h>
16 #include <internal/debug.h>
18 /* FUNCTIONS ***************************************************************/
20 BOOLEAN STDCALL
RtlValidSid (PSID Sid
)
22 if ((Sid
->Revision
& 0xf) != 1)
26 if (Sid
->SubAuthorityCount
> 15)
33 ULONG STDCALL
RtlLengthRequiredSid (UCHAR SubAuthorityCount
)
35 return(sizeof(SID
) + (SubAuthorityCount
- 1) * sizeof(ULONG
));
38 NTSTATUS STDCALL
RtlInitializeSid (PSID Sid
,
39 PSID_IDENTIFIER_AUTHORITY IdentifierAuthority
,
40 UCHAR SubAuthorityCount
)
43 Sid
->SubAuthorityCount
= SubAuthorityCount
;
44 memcpy(&Sid
->IdentifierAuthority
, IdentifierAuthority
,
45 sizeof(SID_IDENTIFIER_AUTHORITY
));
46 return(STATUS_SUCCESS
);
49 PULONG STDCALL
RtlSubAuthoritySid (PSID Sid
, ULONG SubAuthority
)
51 return(&Sid
->SubAuthority
[SubAuthority
]);
54 PUCHAR STDCALL
RtlSubAuthorityCountSid (PSID Sid
)
56 return(&Sid
->SubAuthorityCount
);
59 BOOLEAN STDCALL
RtlEqualSid (PSID Sid1
, PSID Sid2
)
61 if (Sid1
->Revision
!= Sid2
->Revision
)
65 if ((*RtlSubAuthorityCountSid(Sid1
)) !=
66 (*RtlSubAuthorityCountSid(Sid2
)))
70 if (memcmp(Sid1
, Sid2
, RtlLengthSid(Sid1
) != 0))
77 ULONG STDCALL
RtlLengthSid (PSID Sid
)
79 return(sizeof(SID
) + (Sid
->SubAuthorityCount
-1)*4);
82 NTSTATUS STDCALL
RtlCopySid (ULONG BufferLength
, PSID Dest
, PSID Src
)
84 if (BufferLength
< RtlLengthSid(Src
))
86 return(STATUS_UNSUCCESSFUL
);
88 memmove(Dest
, Src
, RtlLengthSid(Src
));
89 return(STATUS_SUCCESS
);
93 RtlConvertSidToUnicodeString(PUNICODE_STRING String
,
95 BOOLEAN AllocateString
)
102 if (!RtlValidSid(Sid
))
103 return STATUS_INVALID_SID
;
106 Ptr
+= swprintf (Ptr
,
110 if(!Sid
->IdentifierAuthority
.Value
[0] &&
111 !Sid
->IdentifierAuthority
.Value
[1])
115 (ULONG
)Sid
->IdentifierAuthority
.Value
[2] << 24 |
116 (ULONG
)Sid
->IdentifierAuthority
.Value
[3] << 16 |
117 (ULONG
)Sid
->IdentifierAuthority
.Value
[4] << 8 |
118 (ULONG
)Sid
->IdentifierAuthority
.Value
[5]);
123 L
"0x%02hx%02hx%02hx%02hx%02hx%02hx",
124 Sid
->IdentifierAuthority
.Value
[0],
125 Sid
->IdentifierAuthority
.Value
[1],
126 Sid
->IdentifierAuthority
.Value
[2],
127 Sid
->IdentifierAuthority
.Value
[3],
128 Sid
->IdentifierAuthority
.Value
[4],
129 Sid
->IdentifierAuthority
.Value
[5]);
132 for (i
= 0; i
< Sid
->SubAuthorityCount
; i
++)
136 Sid
->SubAuthority
[i
]);
139 Length
= (Ptr
- Buffer
) * sizeof(WCHAR
);
143 String
->Buffer
= ExAllocatePool(NonPagedPool
,
144 Length
+ sizeof(WCHAR
));
145 if (String
->Buffer
== NULL
)
146 return STATUS_NO_MEMORY
;
148 String
->MaximumLength
= Length
+ sizeof(WCHAR
);
152 if (Length
> String
->MaximumLength
)
153 return STATUS_BUFFER_TOO_SMALL
;
155 String
->Length
= Length
;
156 memmove(String
->Buffer
,
159 if (Length
< String
->MaximumLength
)
160 String
->Buffer
[Length
] = 0;
162 return STATUS_SUCCESS
;