1 /* $Id: sid.c,v 1.15 2004/08/23 21:16:26 gvg Exp $
3 * COPYRIGHT: See COPYING in the top level directory
4 * PROJECT: ReactOS system libraries
5 * FILE: lib/advapi32/sec/sid.c
6 * PURPOSE: Security ID functions
17 AllocateLocallyUniqueId(PLUID Luid
)
21 Status
= NtAllocateLocallyUniqueId (Luid
);
22 if (!NT_SUCCESS (Status
))
24 SetLastError (RtlNtStatusToDosError (Status
));
36 AllocateAndInitializeSid (PSID_IDENTIFIER_AUTHORITY pIdentifierAuthority
,
37 BYTE nSubAuthorityCount
,
38 DWORD dwSubAuthority0
,
39 DWORD dwSubAuthority1
,
40 DWORD dwSubAuthority2
,
41 DWORD dwSubAuthority3
,
42 DWORD dwSubAuthority4
,
43 DWORD dwSubAuthority5
,
44 DWORD dwSubAuthority6
,
45 DWORD dwSubAuthority7
,
50 Status
= RtlAllocateAndInitializeSid (pIdentifierAuthority
,
61 if (!NT_SUCCESS (Status
))
63 SetLastError (RtlNtStatusToDosError (Status
));
75 CopySid (DWORD nDestinationSidLength
,
81 Status
= RtlCopySid (nDestinationSidLength
,
84 if (!NT_SUCCESS (Status
))
86 SetLastError (RtlNtStatusToDosError (Status
));
98 EqualPrefixSid (PSID pSid1
,
101 return RtlEqualPrefixSid (pSid1
, pSid2
);
109 EqualSid (PSID pSid1
,
112 return RtlEqualSid (pSid1
, pSid2
);
120 * Docs says this function does NOT return a value
121 * even thou it's defined to return a PVOID...
126 return RtlFreeSid (pSid
);
134 GetLengthSid (PSID pSid
)
136 return (DWORD
)RtlLengthSid (pSid
);
143 PSID_IDENTIFIER_AUTHORITY STDCALL
144 GetSidIdentifierAuthority (PSID pSid
)
146 return RtlIdentifierAuthoritySid (pSid
);
154 GetSidLengthRequired (UCHAR nSubAuthorityCount
)
156 return (DWORD
)RtlLengthRequiredSid (nSubAuthorityCount
);
164 GetSidSubAuthority (PSID pSid
,
167 return (PDWORD
)RtlSubAuthoritySid (pSid
, nSubAuthority
);
175 GetSidSubAuthorityCount (PSID pSid
)
177 return RtlSubAuthorityCountSid (pSid
);
185 InitializeSid (PSID Sid
,
186 PSID_IDENTIFIER_AUTHORITY pIdentifierAuthority
,
187 BYTE nSubAuthorityCount
)
191 Status
= RtlInitializeSid (Sid
,
192 pIdentifierAuthority
,
194 if (!NT_SUCCESS (Status
))
196 SetLastError (RtlNtStatusToDosError (Status
));
208 IsValidSid (PSID pSid
)
210 return (BOOL
)RtlValidSid (pSid
);
217 ConvertSidToStringSidW(PSID Sid
, LPWSTR
*StringSid
)
220 UNICODE_STRING UnicodeString
;
221 WCHAR FixedBuffer
[64];
223 if (! RtlValidSid(Sid
))
225 SetLastError(ERROR_INVALID_SID
);
229 UnicodeString
.Length
= 0;
230 UnicodeString
.MaximumLength
= sizeof(FixedBuffer
);
231 UnicodeString
.Buffer
= FixedBuffer
;
232 Status
= RtlConvertSidToUnicodeString(&UnicodeString
, Sid
, FALSE
);
233 if (STATUS_BUFFER_TOO_SMALL
== Status
)
235 Status
= RtlConvertSidToUnicodeString(&UnicodeString
, Sid
, TRUE
);
237 if (! NT_SUCCESS(Status
))
239 SetLastError(RtlNtStatusToDosError(Status
));
243 *StringSid
= LocalAlloc(LMEM_FIXED
, UnicodeString
.Length
+ sizeof(WCHAR
));
244 if (NULL
== *StringSid
)
246 if (UnicodeString
.Buffer
!= FixedBuffer
)
248 RtlFreeUnicodeString(&UnicodeString
);
250 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
254 MoveMemory(*StringSid
, UnicodeString
.Buffer
, UnicodeString
.Length
);
255 ZeroMemory((PCHAR
) *StringSid
+ UnicodeString
.Length
, sizeof(WCHAR
));
256 if (UnicodeString
.Buffer
!= FixedBuffer
)
258 RtlFreeUnicodeString(&UnicodeString
);
269 ConvertSidToStringSidA(PSID Sid
, LPSTR
*StringSid
)
274 if (! ConvertSidToStringSidW(Sid
, &StringSidW
))
279 Len
= WideCharToMultiByte(CP_ACP
, 0, StringSidW
, -1, NULL
, 0, NULL
, NULL
);
282 LocalFree(StringSidW
);
283 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
286 *StringSid
= LocalAlloc(LMEM_FIXED
, Len
);
287 if (NULL
== *StringSid
)
289 LocalFree(StringSidW
);
290 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
294 if (! WideCharToMultiByte(CP_ACP
, 0, StringSidW
, -1, *StringSid
, Len
, NULL
, NULL
))
296 LocalFree(StringSid
);
297 LocalFree(StringSidW
);
301 LocalFree(StringSidW
);