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 *****************************************************************/
19 #define TAG_SID TAG('p', 'S', 'i', 'd')
21 /* FUNCTIONS ***************************************************************/
24 RtlValidSid(IN PSID Sid_
)
30 if ((Sid
->Revision
!= SID_REVISION
) ||
31 (Sid
->SubAuthorityCount
> SID_MAX_SUB_AUTHORITIES
))
44 RtlLengthRequiredSid(IN UCHAR SubAuthorityCount
)
48 return (sizeof(SID
) + (SubAuthorityCount
- 1) * sizeof(ULONG
));
56 RtlInitializeSid(IN PSID Sid_
,
57 IN PSID_IDENTIFIER_AUTHORITY IdentifierAuthority
,
58 IN UCHAR SubAuthorityCount
)
64 Sid
->Revision
= SID_REVISION
;
65 Sid
->SubAuthorityCount
= SubAuthorityCount
;
66 memcpy(&Sid
->IdentifierAuthority
,
68 sizeof(SID_IDENTIFIER_AUTHORITY
));
70 return STATUS_SUCCESS
;
78 RtlSubAuthoritySid(IN PSID Sid_
,
79 IN ULONG SubAuthority
)
85 return &Sid
->SubAuthority
[SubAuthority
];
93 RtlSubAuthorityCountSid(IN PSID Sid_
)
99 return &Sid
->SubAuthorityCount
;
107 RtlEqualSid(IN PSID Sid1_
,
115 if (Sid1
->Revision
!= Sid2
->Revision
)
119 if ((*RtlSubAuthorityCountSid(Sid1
)) != (*RtlSubAuthorityCountSid(Sid2
)))
123 if (RtlCompareMemory(Sid1
, Sid2
, RtlLengthSid(Sid1
)) != RtlLengthSid(Sid1
))
135 RtlLengthSid(IN PSID Sid_
)
141 return (sizeof(SID
) + (Sid
->SubAuthorityCount
-1) * sizeof(ULONG
));
149 RtlCopySid(ULONG BufferLength
,
155 if (BufferLength
< RtlLengthSid(Src
))
157 return STATUS_UNSUCCESSFUL
;
164 return STATUS_SUCCESS
;
172 RtlCopySidAndAttributesArray(ULONG Count
,
173 PSID_AND_ATTRIBUTES Src
,
175 PSID_AND_ATTRIBUTES Dest
,
177 PVOID
* RemainingSidArea
,
178 PULONG RemainingSidAreaSize
)
186 Length
= SidAreaSize
;
188 for (i
=0; i
<Count
; i
++)
190 if (RtlLengthSid(Src
[i
].Sid
) > Length
)
192 return(STATUS_BUFFER_TOO_SMALL
);
194 SidLength
= RtlLengthSid(Src
[i
].Sid
);
195 Length
= Length
- SidLength
;
196 Dest
[i
].Sid
= SidArea
;
197 Dest
[i
].Attributes
= Src
[i
].Attributes
;
198 RtlCopySid(SidLength
,
201 SidArea
= (PVOID
)((ULONG_PTR
)SidArea
+ SidLength
);
203 *RemainingSidArea
= SidArea
;
204 *RemainingSidAreaSize
= Length
;
205 return(STATUS_SUCCESS
);
212 PSID_IDENTIFIER_AUTHORITY STDCALL
213 RtlIdentifierAuthoritySid(IN PSID Sid_
)
219 return &Sid
->IdentifierAuthority
;
227 RtlAllocateAndInitializeSid(PSID_IDENTIFIER_AUTHORITY IdentifierAuthority
,
228 UCHAR SubAuthorityCount
,
243 if (SubAuthorityCount
> 8)
244 return STATUS_INVALID_SID
;
247 return STATUS_INVALID_PARAMETER
;
249 pSid
= RtlpAllocateMemory(sizeof(SID
) + (SubAuthorityCount
- 1) * sizeof(ULONG
),
252 return STATUS_NO_MEMORY
;
254 pSid
->Revision
= SID_REVISION
;
255 pSid
->SubAuthorityCount
= SubAuthorityCount
;
256 memcpy(&pSid
->IdentifierAuthority
,
258 sizeof(SID_IDENTIFIER_AUTHORITY
));
260 switch (SubAuthorityCount
)
263 pSid
->SubAuthority
[7] = SubAuthority7
;
265 pSid
->SubAuthority
[6] = SubAuthority6
;
267 pSid
->SubAuthority
[5] = SubAuthority5
;
269 pSid
->SubAuthority
[4] = SubAuthority4
;
271 pSid
->SubAuthority
[3] = SubAuthority3
;
273 pSid
->SubAuthority
[2] = SubAuthority2
;
275 pSid
->SubAuthority
[1] = SubAuthority1
;
277 pSid
->SubAuthority
[0] = SubAuthority0
;
283 return STATUS_SUCCESS
;
291 * Docs says FreeSid does NOT return a value
292 * even thou it's defined to return a PVOID...
295 RtlFreeSid(IN PSID Sid
)
299 RtlpFreeMemory(Sid
, TAG_SID
);
308 RtlEqualPrefixSid(IN PSID Sid1_
,
316 return(Sid1
->SubAuthorityCount
== Sid2
->SubAuthorityCount
&&
317 !RtlCompareMemory(Sid1
, Sid2
,
318 (Sid1
->SubAuthorityCount
- 1) * sizeof(DWORD
) + 8));
326 RtlConvertSidToUnicodeString(PUNICODE_STRING String
,
328 BOOLEAN AllocateBuffer
)
338 if (RtlValidSid (Sid
) == FALSE
)
339 return STATUS_INVALID_SID
;
342 wcs
+= swprintf (wcs
, L
"S-%u-", Sid
->Revision
);
343 if (Sid
->IdentifierAuthority
.Value
[0] == 0 &&
344 Sid
->IdentifierAuthority
.Value
[1] == 0)
346 wcs
+= swprintf (wcs
,
348 (ULONG
)Sid
->IdentifierAuthority
.Value
[2] << 24 |
349 (ULONG
)Sid
->IdentifierAuthority
.Value
[3] << 16 |
350 (ULONG
)Sid
->IdentifierAuthority
.Value
[4] << 8 |
351 (ULONG
)Sid
->IdentifierAuthority
.Value
[5]);
355 wcs
+= swprintf (wcs
,
356 L
"0x%02hx%02hx%02hx%02hx%02hx%02hx",
357 Sid
->IdentifierAuthority
.Value
[0],
358 Sid
->IdentifierAuthority
.Value
[1],
359 Sid
->IdentifierAuthority
.Value
[2],
360 Sid
->IdentifierAuthority
.Value
[3],
361 Sid
->IdentifierAuthority
.Value
[4],
362 Sid
->IdentifierAuthority
.Value
[5]);
365 for (i
= 0; i
< Sid
->SubAuthorityCount
; i
++)
367 wcs
+= swprintf (wcs
,
369 Sid
->SubAuthority
[i
]);
372 Length
= (wcs
- Buffer
) * sizeof(WCHAR
);
375 String
->Buffer
= RtlpAllocateMemory(Length
+ sizeof(WCHAR
),
377 if (String
->Buffer
== NULL
)
378 return STATUS_NO_MEMORY
;
379 String
->MaximumLength
= Length
+ sizeof(WCHAR
);
383 if (Length
> String
->MaximumLength
)
384 return STATUS_BUFFER_TOO_SMALL
;
387 String
->Length
= Length
;
388 RtlCopyMemory (String
->Buffer
,
391 if (Length
< String
->MaximumLength
)
392 String
->Buffer
[Length
/ sizeof(WCHAR
)] = 0;
394 return STATUS_SUCCESS
;