diff --git a/reactos/lib/advapi32/advapi32.def b/reactos/lib/advapi32/advapi32.def index 34bfc17c4c2..80f3776c1be 100644 --- a/reactos/lib/advapi32/advapi32.def +++ b/reactos/lib/advapi32/advapi32.def @@ -1,4 +1,4 @@ -; $Id: advapi32.def,v 1.20 2004/07/10 14:38:23 weiden Exp $ +; $Id: advapi32.def,v 1.21 2004/08/23 21:16:25 gvg Exp $ ; ; advapi32.def ; @@ -47,6 +47,8 @@ ChangeServiceConfigW@44 ;CloseEventLog@4 CloseServiceHandle@4 ControlService@12 +ConvertSidToStringSidA@8 +ConvertSidToStringSidW@8 CopySid@12 ;CreatePrivateObjectSecurity@24 CreateProcessAsUserA@44 diff --git a/reactos/lib/advapi32/advapi32.edf b/reactos/lib/advapi32/advapi32.edf index 180ba865a45..f08749665ec 100644 --- a/reactos/lib/advapi32/advapi32.edf +++ b/reactos/lib/advapi32/advapi32.edf @@ -1,4 +1,4 @@ -; $Id: advapi32.edf,v 1.40 2004/07/10 14:38:23 weiden Exp $ +; $Id: advapi32.edf,v 1.41 2004/08/23 21:16:25 gvg Exp $ ; ; advapi32.edf ; @@ -44,6 +44,8 @@ ClearEventLogW=ClearEventLogW@8 CloseEventLog=CloseEventLog@4 CloseServiceHandle=CloseServiceHandle@4 ControlService=ControlService@12 +ConvertSidToStringSidA=ConvertSidToStringSidA@8 +ConvertSidToStringSidW=ConvertSidToStringSidW@8 CopySid=CopySid@12 ;CreatePrivateObjectSecurity=CreatePrivateObjectSecurity@24 CreateProcessAsUserA=CreateProcessAsUserA@44 diff --git a/reactos/lib/advapi32/advapi32.h b/reactos/lib/advapi32/advapi32.h index cb1c067ef6b..207820132db 100644 --- a/reactos/lib/advapi32/advapi32.h +++ b/reactos/lib/advapi32/advapi32.h @@ -6,4 +6,5 @@ #define NTOS_MODE_USER #include #include +#include #include diff --git a/reactos/lib/advapi32/sec/sid.c b/reactos/lib/advapi32/sec/sid.c index 3b452158e47..112d24f7ebb 100644 --- a/reactos/lib/advapi32/sec/sid.c +++ b/reactos/lib/advapi32/sec/sid.c @@ -1,4 +1,4 @@ -/* $Id: sid.c,v 1.14 2004/08/15 17:03:15 chorns Exp $ +/* $Id: sid.c,v 1.15 2004/08/23 21:16:26 gvg Exp $ * * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS system libraries @@ -210,4 +210,97 @@ IsValidSid (PSID pSid) return (BOOL)RtlValidSid (pSid); } +/* + * @implemented + */ +BOOL STDCALL +ConvertSidToStringSidW(PSID Sid, LPWSTR *StringSid) +{ + NTSTATUS Status; + UNICODE_STRING UnicodeString; + WCHAR FixedBuffer[64]; + + if (! RtlValidSid(Sid)) + { + SetLastError(ERROR_INVALID_SID); + return FALSE; + } + + UnicodeString.Length = 0; + UnicodeString.MaximumLength = sizeof(FixedBuffer); + UnicodeString.Buffer = FixedBuffer; + Status = RtlConvertSidToUnicodeString(&UnicodeString, Sid, FALSE); + if (STATUS_BUFFER_TOO_SMALL == Status) + { + Status = RtlConvertSidToUnicodeString(&UnicodeString, Sid, TRUE); + } + if (! NT_SUCCESS(Status)) + { + SetLastError(RtlNtStatusToDosError(Status)); + return FALSE; + } + + *StringSid = LocalAlloc(LMEM_FIXED, UnicodeString.Length + sizeof(WCHAR)); + if (NULL == *StringSid) + { + if (UnicodeString.Buffer != FixedBuffer) + { + RtlFreeUnicodeString(&UnicodeString); + } + SetLastError(ERROR_NOT_ENOUGH_MEMORY); + return FALSE; + } + + MoveMemory(*StringSid, UnicodeString.Buffer, UnicodeString.Length); + ZeroMemory((PCHAR) *StringSid + UnicodeString.Length, sizeof(WCHAR)); + if (UnicodeString.Buffer != FixedBuffer) + { + RtlFreeUnicodeString(&UnicodeString); + } + + return TRUE; +} + + +/* + * @implemented + */ +BOOL STDCALL +ConvertSidToStringSidA(PSID Sid, LPSTR *StringSid) +{ + LPWSTR StringSidW; + int Len; + + if (! ConvertSidToStringSidW(Sid, &StringSidW)) + { + return FALSE; + } + + Len = WideCharToMultiByte(CP_ACP, 0, StringSidW, -1, NULL, 0, NULL, NULL); + if (Len <= 0) + { + LocalFree(StringSidW); + SetLastError(ERROR_NOT_ENOUGH_MEMORY); + return FALSE; + } + *StringSid = LocalAlloc(LMEM_FIXED, Len); + if (NULL == *StringSid) + { + LocalFree(StringSidW); + SetLastError(ERROR_NOT_ENOUGH_MEMORY); + return FALSE; + } + + if (! WideCharToMultiByte(CP_ACP, 0, StringSidW, -1, *StringSid, Len, NULL, NULL)) + { + LocalFree(StringSid); + LocalFree(StringSidW); + return FALSE; + } + + LocalFree(StringSidW); + + return TRUE; +} + /* EOF */ diff --git a/reactos/w32api/include/sddl.h b/reactos/w32api/include/sddl.h new file mode 100644 index 00000000000..10ab1659571 --- /dev/null +++ b/reactos/w32api/include/sddl.h @@ -0,0 +1,23 @@ +#ifndef _SDDL_H +#define _SDDL_H +#if __GNUC__ >=3 +#pragma GCC system_header +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +BOOL WINAPI ConvertSidToStringSidA(PSID Sid, LPSTR *StringSid); +BOOL WINAPI ConvertSidToStringSidW(PSID Sid, LPWSTR *StringSid); + +#ifdef UNICODE +#define ConvertSidToStringSid ConvertSidToStringSidW +#else /* UNICODE */ +#define ConvertSidToStringSid ConvertSidToStringSidA +#endif /* UNICODE */ + +#ifdef __cplusplus +} +#endif +#endif /* ! defined _SDDL_H */