Implement ConvertSidToStringSidA/w

svn path=/trunk/; revision=10662
This commit is contained in:
Gé van Geldorp 2004-08-23 21:16:26 +00:00
parent a380ffb184
commit e208613f37
5 changed files with 124 additions and 3 deletions

View file

@ -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

View file

@ -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

View file

@ -6,4 +6,5 @@
#define NTOS_MODE_USER
#include <ntos.h>
#include <windows.h>
#include <sddl.h>
#include <rosrtl/string.h>

View file

@ -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 */

View file

@ -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 */