2005-06-27 22:42:28 +00:00
|
|
|
/*
|
2004-02-25 14:25:11 +00:00
|
|
|
* COPYRIGHT: See COPYING in the top level directory
|
2012-02-18 12:00:50 +00:00
|
|
|
* WINE COPYRIGHT:
|
2008-11-24 19:27:30 +00:00
|
|
|
* Copyright 1999, 2000 Juergen Schmied <juergen.schmied@debitel.net>
|
|
|
|
* Copyright 2003 CodeWeavers Inc. (Ulrich Czekalla)
|
|
|
|
* Copyright 2006 Robert Reif
|
|
|
|
*
|
2004-02-25 14:25:11 +00:00
|
|
|
* PROJECT: ReactOS system libraries
|
2008-11-24 19:27:30 +00:00
|
|
|
* FILE: dll/win32/advapi32/sec/misc.c
|
2008-02-07 14:05:10 +00:00
|
|
|
* PURPOSE: Miscellaneous security functions (some ported from Wine)
|
2001-11-22 02:37:32 +00:00
|
|
|
*/
|
|
|
|
|
2005-08-05 10:31:28 +00:00
|
|
|
#include <advapi32.h>
|
2004-03-25 11:30:07 +00:00
|
|
|
|
2014-01-20 13:16:06 +00:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(advapi);
|
2008-11-10 14:23:57 +00:00
|
|
|
|
2005-07-26 21:20:55 +00:00
|
|
|
/* Interface to ntmarta.dll ***************************************************/
|
|
|
|
|
2005-07-27 17:20:57 +00:00
|
|
|
NTMARTA NtMartaStatic = { 0 };
|
2005-07-26 21:20:55 +00:00
|
|
|
static PNTMARTA NtMarta = NULL;
|
|
|
|
|
|
|
|
#define FindNtMartaProc(Name) \
|
|
|
|
NtMartaStatic.Name = (PVOID)GetProcAddress(NtMartaStatic.hDllInstance, \
|
|
|
|
"Acc" # Name ); \
|
|
|
|
if (NtMartaStatic.Name == NULL) \
|
|
|
|
{ \
|
|
|
|
return GetLastError(); \
|
|
|
|
}
|
|
|
|
|
2008-09-21 13:55:53 +00:00
|
|
|
|
2005-07-26 21:20:55 +00:00
|
|
|
static DWORD
|
|
|
|
LoadAndInitializeNtMarta(VOID)
|
|
|
|
{
|
|
|
|
/* this code may be executed simultaneously by multiple threads in case they're
|
|
|
|
trying to initialize the interface at the same time, but that's no problem
|
|
|
|
because the pointers returned by GetProcAddress will be the same. However,
|
|
|
|
only one of the threads will change the NtMarta pointer to the NtMartaStatic
|
|
|
|
structure, the others threads will detect that there were other threads
|
|
|
|
initializing the structure faster and will release the reference to the
|
|
|
|
DLL */
|
|
|
|
|
|
|
|
NtMartaStatic.hDllInstance = LoadLibraryW(L"ntmarta.dll");
|
|
|
|
if (NtMartaStatic.hDllInstance == NULL)
|
|
|
|
{
|
|
|
|
return GetLastError();
|
|
|
|
}
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
FindNtMartaProc(LookupAccountTrustee);
|
|
|
|
FindNtMartaProc(LookupAccountName);
|
|
|
|
FindNtMartaProc(LookupAccountSid);
|
|
|
|
FindNtMartaProc(SetEntriesInAList);
|
|
|
|
FindNtMartaProc(ConvertAccessToSecurityDescriptor);
|
|
|
|
FindNtMartaProc(ConvertSDToAccess);
|
|
|
|
FindNtMartaProc(ConvertAclToAccess);
|
|
|
|
FindNtMartaProc(GetAccessForTrustee);
|
|
|
|
FindNtMartaProc(GetExplicitEntries);
|
2005-07-26 22:21:02 +00:00
|
|
|
#endif
|
2005-07-26 21:20:55 +00:00
|
|
|
FindNtMartaProc(RewriteGetNamedRights);
|
|
|
|
FindNtMartaProc(RewriteSetNamedRights);
|
|
|
|
FindNtMartaProc(RewriteGetHandleRights);
|
|
|
|
FindNtMartaProc(RewriteSetHandleRights);
|
|
|
|
FindNtMartaProc(RewriteSetEntriesInAcl);
|
|
|
|
FindNtMartaProc(RewriteGetExplicitEntriesFromAcl);
|
|
|
|
FindNtMartaProc(TreeResetNamedSecurityInfo);
|
|
|
|
FindNtMartaProc(GetInheritanceSource);
|
|
|
|
FindNtMartaProc(FreeIndexArray);
|
2007-10-19 23:21:45 +00:00
|
|
|
|
2005-07-26 21:20:55 +00:00
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2008-09-21 13:55:53 +00:00
|
|
|
|
2005-07-27 17:20:57 +00:00
|
|
|
DWORD
|
2005-07-26 21:20:55 +00:00
|
|
|
CheckNtMartaPresent(VOID)
|
|
|
|
{
|
|
|
|
DWORD ErrorCode;
|
2007-10-19 23:21:45 +00:00
|
|
|
|
2010-03-25 01:06:20 +00:00
|
|
|
if (InterlockedCompareExchangePointer((PVOID)&NtMarta,
|
2007-11-16 13:16:43 +00:00
|
|
|
NULL,
|
|
|
|
NULL) == NULL)
|
2005-07-26 21:20:55 +00:00
|
|
|
{
|
|
|
|
/* we're the first one trying to use ntmarta, initialize it and change
|
|
|
|
the pointer after initialization */
|
|
|
|
ErrorCode = LoadAndInitializeNtMarta();
|
2007-10-19 23:21:45 +00:00
|
|
|
|
2005-07-26 21:20:55 +00:00
|
|
|
if (ErrorCode == ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
/* try change the NtMarta pointer */
|
2010-03-25 01:06:20 +00:00
|
|
|
if (InterlockedCompareExchangePointer((PVOID)&NtMarta,
|
2005-07-26 21:20:55 +00:00
|
|
|
&NtMartaStatic,
|
|
|
|
NULL) != NULL)
|
|
|
|
{
|
|
|
|
/* another thread initialized ntmarta in the meanwhile, release
|
|
|
|
the reference of the dll loaded. */
|
|
|
|
FreeLibrary(NtMartaStatic.hDllInstance);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#if DBG
|
|
|
|
else
|
|
|
|
{
|
2022-05-02 12:26:10 +00:00
|
|
|
ERR("Failed to initialize ntmarta.dll! Error: 0x%x\n", ErrorCode);
|
2005-07-26 21:20:55 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* ntmarta was already initialized */
|
|
|
|
ErrorCode = ERROR_SUCCESS;
|
|
|
|
}
|
2007-10-19 23:21:45 +00:00
|
|
|
|
2005-07-26 21:20:55 +00:00
|
|
|
return ErrorCode;
|
|
|
|
}
|
|
|
|
|
2008-09-21 13:55:53 +00:00
|
|
|
|
|
|
|
VOID
|
|
|
|
UnloadNtMarta(VOID)
|
2005-07-26 21:20:55 +00:00
|
|
|
{
|
2010-03-25 01:06:20 +00:00
|
|
|
if (InterlockedExchangePointer((PVOID)&NtMarta,
|
2005-07-26 21:20:55 +00:00
|
|
|
NULL) != NULL)
|
|
|
|
{
|
|
|
|
FreeLibrary(NtMartaStatic.hDllInstance);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-09-21 13:55:53 +00:00
|
|
|
|
2005-07-26 21:20:55 +00:00
|
|
|
/******************************************************************************/
|
2001-11-22 02:37:32 +00:00
|
|
|
|
2006-10-15 19:58:57 +00:00
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
BOOL
|
|
|
|
WINAPI
|
|
|
|
ImpersonateAnonymousToken(IN HANDLE ThreadHandle)
|
|
|
|
{
|
|
|
|
NTSTATUS Status;
|
|
|
|
|
|
|
|
Status = NtImpersonateAnonymousToken(ThreadHandle);
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
SetLastError(RtlNtStatusToDosError(Status));
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2003-07-10 15:05:55 +00:00
|
|
|
/*
|
2004-03-25 11:30:07 +00:00
|
|
|
* @implemented
|
2003-07-10 15:05:55 +00:00
|
|
|
*/
|
2008-09-21 13:55:53 +00:00
|
|
|
BOOL
|
2008-11-30 11:42:05 +00:00
|
|
|
WINAPI
|
2003-01-15 20:05:53 +00:00
|
|
|
ImpersonateLoggedOnUser(HANDLE hToken)
|
|
|
|
{
|
2008-09-21 13:55:53 +00:00
|
|
|
SECURITY_QUALITY_OF_SERVICE Qos;
|
|
|
|
OBJECT_ATTRIBUTES ObjectAttributes;
|
|
|
|
HANDLE NewToken;
|
|
|
|
TOKEN_TYPE Type;
|
|
|
|
ULONG ReturnLength;
|
|
|
|
BOOL Duplicated;
|
|
|
|
NTSTATUS Status;
|
|
|
|
|
|
|
|
/* Get the token type */
|
|
|
|
Status = NtQueryInformationToken(hToken,
|
|
|
|
TokenType,
|
|
|
|
&Type,
|
|
|
|
sizeof(TOKEN_TYPE),
|
|
|
|
&ReturnLength);
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
SetLastError(RtlNtStatusToDosError(Status));
|
|
|
|
return FALSE;
|
2004-03-25 11:30:07 +00:00
|
|
|
}
|
|
|
|
|
2008-09-21 13:55:53 +00:00
|
|
|
if (Type == TokenPrimary)
|
|
|
|
{
|
|
|
|
/* Create a duplicate impersonation token */
|
|
|
|
Qos.Length = sizeof(SECURITY_QUALITY_OF_SERVICE);
|
|
|
|
Qos.ImpersonationLevel = SecurityImpersonation;
|
|
|
|
Qos.ContextTrackingMode = SECURITY_DYNAMIC_TRACKING;
|
|
|
|
Qos.EffectiveOnly = FALSE;
|
|
|
|
|
|
|
|
ObjectAttributes.Length = sizeof(OBJECT_ATTRIBUTES);
|
|
|
|
ObjectAttributes.RootDirectory = NULL;
|
|
|
|
ObjectAttributes.ObjectName = NULL;
|
|
|
|
ObjectAttributes.Attributes = 0;
|
|
|
|
ObjectAttributes.SecurityDescriptor = NULL;
|
|
|
|
ObjectAttributes.SecurityQualityOfService = &Qos;
|
|
|
|
|
|
|
|
Status = NtDuplicateToken(hToken,
|
|
|
|
TOKEN_IMPERSONATE | TOKEN_QUERY,
|
|
|
|
&ObjectAttributes,
|
|
|
|
FALSE,
|
|
|
|
TokenImpersonation,
|
|
|
|
&NewToken);
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
2014-10-05 14:19:53 +00:00
|
|
|
ERR("NtDuplicateToken failed: Status %08x\n", Status);
|
2008-09-21 13:55:53 +00:00
|
|
|
SetLastError(RtlNtStatusToDosError(Status));
|
|
|
|
return FALSE;
|
|
|
|
}
|
2004-03-25 11:30:07 +00:00
|
|
|
|
2008-09-21 13:55:53 +00:00
|
|
|
Duplicated = TRUE;
|
2004-03-25 11:30:07 +00:00
|
|
|
}
|
2008-09-21 13:55:53 +00:00
|
|
|
else
|
2004-03-25 11:30:07 +00:00
|
|
|
{
|
2008-09-21 13:55:53 +00:00
|
|
|
/* User the original impersonation token */
|
|
|
|
NewToken = hToken;
|
|
|
|
Duplicated = FALSE;
|
2004-03-25 11:30:07 +00:00
|
|
|
}
|
|
|
|
|
2008-09-21 13:55:53 +00:00
|
|
|
/* Impersonate the the current thread */
|
|
|
|
Status = NtSetInformationThread(NtCurrentThread(),
|
|
|
|
ThreadImpersonationToken,
|
|
|
|
&NewToken,
|
|
|
|
sizeof(HANDLE));
|
2004-03-25 11:30:07 +00:00
|
|
|
|
2017-10-01 14:42:04 +00:00
|
|
|
if (Duplicated != FALSE)
|
2004-03-25 11:30:07 +00:00
|
|
|
{
|
2008-09-21 13:55:53 +00:00
|
|
|
NtClose(NewToken);
|
2004-03-25 11:30:07 +00:00
|
|
|
}
|
|
|
|
|
2008-09-21 13:55:53 +00:00
|
|
|
if (!NT_SUCCESS(Status))
|
2004-03-25 11:30:07 +00:00
|
|
|
{
|
2014-10-05 14:19:53 +00:00
|
|
|
ERR("NtSetInformationThread failed: Status %08x\n", Status);
|
2008-09-21 13:55:53 +00:00
|
|
|
SetLastError(RtlNtStatusToDosError(Status));
|
|
|
|
return FALSE;
|
2004-03-25 11:30:07 +00:00
|
|
|
}
|
|
|
|
|
2008-09-21 13:55:53 +00:00
|
|
|
return TRUE;
|
2003-01-15 20:05:53 +00:00
|
|
|
}
|
|
|
|
|
2004-02-25 23:54:13 +00:00
|
|
|
/******************************************************************************
|
|
|
|
* GetUserNameA [ADVAPI32.@]
|
|
|
|
*
|
|
|
|
* Get the current user name.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* lpszName [O] Destination for the user name.
|
|
|
|
* lpSize [I/O] Size of lpszName.
|
|
|
|
*
|
2004-03-08 18:09:05 +00:00
|
|
|
*
|
2004-12-13 07:09:56 +00:00
|
|
|
* @implemented
|
2004-02-25 23:54:13 +00:00
|
|
|
*/
|
2008-09-21 13:55:53 +00:00
|
|
|
BOOL
|
|
|
|
WINAPI
|
|
|
|
GetUserNameA(LPSTR lpszName,
|
|
|
|
LPDWORD lpSize)
|
2004-02-25 23:54:13 +00:00
|
|
|
{
|
2008-09-21 13:55:53 +00:00
|
|
|
UNICODE_STRING NameW;
|
|
|
|
ANSI_STRING NameA;
|
|
|
|
BOOL Ret;
|
2005-05-09 01:43:41 +00:00
|
|
|
|
2008-09-21 13:55:53 +00:00
|
|
|
/* apparently Win doesn't check whether lpSize is valid at all! */
|
2004-12-13 07:09:56 +00:00
|
|
|
|
2008-09-21 13:55:53 +00:00
|
|
|
NameW.MaximumLength = (*lpSize) * sizeof(WCHAR);
|
|
|
|
NameW.Buffer = LocalAlloc(LMEM_FIXED, NameW.MaximumLength);
|
|
|
|
if(NameW.Buffer == NULL)
|
|
|
|
{
|
|
|
|
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2005-05-09 01:43:41 +00:00
|
|
|
|
2008-09-21 13:55:53 +00:00
|
|
|
NameA.Length = 0;
|
|
|
|
NameA.MaximumLength = ((*lpSize) < 0xFFFF ? (USHORT)(*lpSize) : 0xFFFF);
|
|
|
|
NameA.Buffer = lpszName;
|
2005-05-09 01:43:41 +00:00
|
|
|
|
2008-09-21 13:55:53 +00:00
|
|
|
Ret = GetUserNameW(NameW.Buffer,
|
|
|
|
lpSize);
|
|
|
|
if(Ret)
|
|
|
|
{
|
|
|
|
NameW.Length = (*lpSize - 1) * sizeof(WCHAR);
|
|
|
|
RtlUnicodeStringToAnsiString(&NameA, &NameW, FALSE);
|
2005-05-09 01:43:41 +00:00
|
|
|
|
2008-09-21 13:55:53 +00:00
|
|
|
*lpSize = NameA.Length + 1;
|
|
|
|
}
|
2005-05-09 01:43:41 +00:00
|
|
|
|
2008-09-21 13:55:53 +00:00
|
|
|
LocalFree(NameW.Buffer);
|
2005-05-09 01:43:41 +00:00
|
|
|
|
2008-09-21 13:55:53 +00:00
|
|
|
return Ret;
|
2004-02-25 23:54:13 +00:00
|
|
|
}
|
|
|
|
|
2004-03-08 18:09:05 +00:00
|
|
|
/******************************************************************************
|
|
|
|
* GetUserNameW [ADVAPI32.@]
|
|
|
|
*
|
|
|
|
* See GetUserNameA.
|
|
|
|
*
|
2004-12-13 07:09:56 +00:00
|
|
|
* @implemented
|
2004-03-08 18:09:05 +00:00
|
|
|
*/
|
2008-09-21 13:55:53 +00:00
|
|
|
BOOL
|
|
|
|
WINAPI
|
|
|
|
GetUserNameW(LPWSTR lpszName,
|
2010-07-20 20:48:11 +00:00
|
|
|
LPDWORD lpSize)
|
2004-03-08 18:09:05 +00:00
|
|
|
{
|
2010-07-20 20:48:11 +00:00
|
|
|
HANDLE hToken = INVALID_HANDLE_VALUE;
|
|
|
|
DWORD tu_len = 0;
|
|
|
|
char* tu_buf = NULL;
|
|
|
|
TOKEN_USER* token_user = NULL;
|
|
|
|
DWORD an_len = 0;
|
|
|
|
SID_NAME_USE snu = SidTypeUser;
|
|
|
|
WCHAR* domain_name = NULL;
|
|
|
|
DWORD dn_len = 0;
|
|
|
|
|
|
|
|
if (!OpenThreadToken (GetCurrentThread(), TOKEN_QUERY, FALSE, &hToken))
|
2004-12-13 07:09:56 +00:00
|
|
|
{
|
2010-07-20 20:48:11 +00:00
|
|
|
DWORD dwLastError = GetLastError();
|
|
|
|
if (dwLastError != ERROR_NO_TOKEN
|
|
|
|
&& dwLastError != ERROR_NO_IMPERSONATION_TOKEN)
|
|
|
|
{
|
|
|
|
/* don't call SetLastError(),
|
|
|
|
as OpenThreadToken() ought to have set one */
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &hToken))
|
|
|
|
{
|
|
|
|
/* don't call SetLastError(),
|
|
|
|
as OpenProcessToken() ought to have set one */
|
|
|
|
return FALSE;
|
|
|
|
}
|
2004-12-13 07:09:56 +00:00
|
|
|
}
|
2010-07-20 20:48:11 +00:00
|
|
|
|
|
|
|
tu_buf = LocalAlloc(LMEM_FIXED, 36);
|
|
|
|
if (!tu_buf)
|
2004-12-13 07:09:56 +00:00
|
|
|
{
|
2010-07-20 20:48:11 +00:00
|
|
|
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
|
|
|
CloseHandle(hToken);
|
|
|
|
return FALSE;
|
2004-12-13 07:09:56 +00:00
|
|
|
}
|
2010-07-20 20:48:11 +00:00
|
|
|
|
|
|
|
if (!GetTokenInformation(hToken, TokenUser, tu_buf, 36, &tu_len) || tu_len > 36)
|
2004-12-13 07:09:56 +00:00
|
|
|
{
|
2010-07-20 20:48:11 +00:00
|
|
|
LocalFree(tu_buf);
|
|
|
|
tu_buf = LocalAlloc(LMEM_FIXED, tu_len);
|
|
|
|
if (!tu_buf)
|
|
|
|
{
|
|
|
|
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
|
|
|
CloseHandle(hToken);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!GetTokenInformation(hToken, TokenUser, tu_buf, tu_len, &tu_len))
|
|
|
|
{
|
|
|
|
/* don't call SetLastError(),
|
|
|
|
as GetTokenInformation() ought to have set one */
|
|
|
|
LocalFree(tu_buf);
|
|
|
|
CloseHandle(hToken);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2004-12-13 07:09:56 +00:00
|
|
|
}
|
2010-07-20 20:48:11 +00:00
|
|
|
|
|
|
|
CloseHandle(hToken);
|
|
|
|
token_user = (TOKEN_USER*)tu_buf;
|
|
|
|
|
|
|
|
an_len = *lpSize;
|
|
|
|
dn_len = 32;
|
|
|
|
domain_name = LocalAlloc(LMEM_FIXED, dn_len * sizeof(WCHAR));
|
|
|
|
if (!domain_name)
|
2004-12-13 07:09:56 +00:00
|
|
|
{
|
2010-07-20 20:48:11 +00:00
|
|
|
LocalFree(tu_buf);
|
|
|
|
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
2004-12-13 07:09:56 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2010-07-20 20:48:11 +00:00
|
|
|
|
|
|
|
if (!LookupAccountSidW(NULL, token_user->User.Sid, lpszName, &an_len, domain_name, &dn_len, &snu)
|
|
|
|
|| dn_len > 32)
|
2004-12-13 07:09:56 +00:00
|
|
|
{
|
2010-07-20 20:48:11 +00:00
|
|
|
if (dn_len > 32)
|
|
|
|
{
|
|
|
|
LocalFree(domain_name);
|
|
|
|
domain_name = LocalAlloc(LMEM_FIXED, dn_len * sizeof(WCHAR));
|
|
|
|
if (!domain_name)
|
|
|
|
{
|
|
|
|
LocalFree(tu_buf);
|
|
|
|
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
an_len = *lpSize;
|
|
|
|
if (!LookupAccountSidW(NULL, token_user->User.Sid, lpszName, &an_len, domain_name, &dn_len, &snu))
|
|
|
|
{
|
|
|
|
/* don't call SetLastError(),
|
|
|
|
as LookupAccountSid() ought to have set one */
|
|
|
|
LocalFree(domain_name);
|
|
|
|
LocalFree(tu_buf);
|
|
|
|
*lpSize = an_len;
|
|
|
|
return FALSE;
|
|
|
|
}
|
2004-12-13 07:09:56 +00:00
|
|
|
}
|
2004-03-08 18:09:05 +00:00
|
|
|
|
2010-07-20 20:48:11 +00:00
|
|
|
LocalFree(domain_name);
|
|
|
|
LocalFree(tu_buf);
|
|
|
|
*lpSize = an_len + 1;
|
|
|
|
return TRUE;
|
2004-03-08 18:09:05 +00:00
|
|
|
}
|
|
|
|
|
2004-03-25 11:30:07 +00:00
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* LookupAccountSidA [ADVAPI32.@]
|
|
|
|
*
|
2004-12-14 21:25:21 +00:00
|
|
|
* @implemented
|
2004-03-25 11:30:07 +00:00
|
|
|
*/
|
2008-09-21 13:55:53 +00:00
|
|
|
BOOL
|
2008-11-30 11:42:05 +00:00
|
|
|
WINAPI
|
2008-09-21 13:55:53 +00:00
|
|
|
LookupAccountSidA(LPCSTR lpSystemName,
|
|
|
|
PSID lpSid,
|
|
|
|
LPSTR lpName,
|
|
|
|
LPDWORD cchName,
|
|
|
|
LPSTR lpReferencedDomainName,
|
|
|
|
LPDWORD cchReferencedDomainName,
|
|
|
|
PSID_NAME_USE peUse)
|
2004-03-25 11:30:07 +00:00
|
|
|
{
|
2010-07-20 20:48:11 +00:00
|
|
|
UNICODE_STRING NameW, ReferencedDomainNameW, SystemNameW;
|
|
|
|
LPWSTR NameBuffer = NULL;
|
|
|
|
LPWSTR ReferencedDomainNameBuffer = NULL;
|
|
|
|
DWORD dwName, dwReferencedDomainName;
|
|
|
|
BOOL Ret;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* save the buffer sizes the caller passed to us, as they may get modified and
|
|
|
|
* we require the original values when converting back to ansi
|
|
|
|
*/
|
|
|
|
dwName = *cchName;
|
|
|
|
dwReferencedDomainName = *cchReferencedDomainName;
|
|
|
|
|
|
|
|
/* allocate buffers for the unicode strings to receive */
|
|
|
|
if (dwName > 0)
|
2004-12-14 21:25:21 +00:00
|
|
|
{
|
2012-02-18 12:00:50 +00:00
|
|
|
NameBuffer = LocalAlloc(LMEM_FIXED, dwName * sizeof(WCHAR));
|
2010-07-20 20:48:11 +00:00
|
|
|
if (NameBuffer == NULL)
|
|
|
|
{
|
|
|
|
SetLastError(ERROR_OUTOFMEMORY);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2004-12-14 21:25:21 +00:00
|
|
|
}
|
2010-07-20 20:48:11 +00:00
|
|
|
else
|
|
|
|
NameBuffer = NULL;
|
|
|
|
|
|
|
|
if (dwReferencedDomainName > 0)
|
2004-12-14 21:25:21 +00:00
|
|
|
{
|
2012-02-18 12:00:50 +00:00
|
|
|
ReferencedDomainNameBuffer = LocalAlloc(LMEM_FIXED, dwReferencedDomainName * sizeof(WCHAR));
|
2010-07-20 20:48:11 +00:00
|
|
|
if (ReferencedDomainNameBuffer == NULL)
|
|
|
|
{
|
|
|
|
if (dwName > 0)
|
|
|
|
{
|
|
|
|
LocalFree(NameBuffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
SetLastError(ERROR_OUTOFMEMORY);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2004-12-14 21:25:21 +00:00
|
|
|
}
|
2010-07-20 20:48:11 +00:00
|
|
|
else
|
|
|
|
ReferencedDomainNameBuffer = NULL;
|
|
|
|
|
|
|
|
|
|
|
|
/* convert the system name to unicode - if present */
|
|
|
|
if (lpSystemName != NULL)
|
|
|
|
{
|
|
|
|
ANSI_STRING SystemNameA;
|
|
|
|
|
|
|
|
RtlInitAnsiString(&SystemNameA, lpSystemName);
|
|
|
|
RtlAnsiStringToUnicodeString(&SystemNameW, &SystemNameA, TRUE);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
SystemNameW.Buffer = NULL;
|
|
|
|
|
|
|
|
/* it's time to call the unicode version */
|
|
|
|
Ret = LookupAccountSidW(SystemNameW.Buffer,
|
|
|
|
lpSid,
|
|
|
|
NameBuffer,
|
|
|
|
cchName,
|
|
|
|
ReferencedDomainNameBuffer,
|
|
|
|
cchReferencedDomainName,
|
|
|
|
peUse);
|
|
|
|
if (Ret)
|
2004-12-14 21:25:21 +00:00
|
|
|
{
|
2010-07-20 20:48:11 +00:00
|
|
|
/*
|
|
|
|
* convert unicode strings back to ansi, don't forget that we can't convert
|
|
|
|
* more than 0xFFFF (USHORT) characters! Also don't forget to explicitly
|
|
|
|
* terminate the converted string, the Rtl functions don't do that!
|
|
|
|
*/
|
|
|
|
if (lpName != NULL)
|
|
|
|
{
|
|
|
|
ANSI_STRING NameA;
|
2005-05-09 01:43:41 +00:00
|
|
|
|
2010-07-20 20:48:11 +00:00
|
|
|
NameA.Length = 0;
|
|
|
|
NameA.MaximumLength = ((dwName <= 0xFFFF) ? (USHORT)dwName : 0xFFFF);
|
|
|
|
NameA.Buffer = lpName;
|
|
|
|
|
|
|
|
RtlInitUnicodeString(&NameW, NameBuffer);
|
|
|
|
RtlUnicodeStringToAnsiString(&NameA, &NameW, FALSE);
|
|
|
|
NameA.Buffer[NameA.Length] = '\0';
|
|
|
|
}
|
2005-05-09 01:43:41 +00:00
|
|
|
|
2010-07-20 20:48:11 +00:00
|
|
|
if (lpReferencedDomainName != NULL)
|
|
|
|
{
|
|
|
|
ANSI_STRING ReferencedDomainNameA;
|
|
|
|
|
|
|
|
ReferencedDomainNameA.Length = 0;
|
|
|
|
ReferencedDomainNameA.MaximumLength = ((dwReferencedDomainName <= 0xFFFF) ?
|
|
|
|
(USHORT)dwReferencedDomainName : 0xFFFF);
|
|
|
|
ReferencedDomainNameA.Buffer = lpReferencedDomainName;
|
|
|
|
|
|
|
|
RtlInitUnicodeString(&ReferencedDomainNameW, ReferencedDomainNameBuffer);
|
|
|
|
RtlUnicodeStringToAnsiString(&ReferencedDomainNameA, &ReferencedDomainNameW, FALSE);
|
|
|
|
ReferencedDomainNameA.Buffer[ReferencedDomainNameA.Length] = '\0';
|
|
|
|
}
|
2004-12-14 21:25:21 +00:00
|
|
|
}
|
2005-05-09 01:43:41 +00:00
|
|
|
|
2010-07-20 20:48:11 +00:00
|
|
|
/* free previously allocated buffers */
|
|
|
|
if (SystemNameW.Buffer != NULL)
|
2004-12-14 21:25:21 +00:00
|
|
|
{
|
2010-07-20 20:48:11 +00:00
|
|
|
RtlFreeUnicodeString(&SystemNameW);
|
|
|
|
}
|
2004-12-14 21:25:21 +00:00
|
|
|
|
2010-07-20 20:48:11 +00:00
|
|
|
if (NameBuffer != NULL)
|
|
|
|
{
|
|
|
|
LocalFree(NameBuffer);
|
|
|
|
}
|
2004-12-14 21:25:21 +00:00
|
|
|
|
2010-07-20 20:48:11 +00:00
|
|
|
if (ReferencedDomainNameBuffer != NULL)
|
|
|
|
{
|
|
|
|
LocalFree(ReferencedDomainNameBuffer);
|
2004-12-14 21:25:21 +00:00
|
|
|
}
|
2010-07-20 20:48:11 +00:00
|
|
|
|
|
|
|
return Ret;
|
2004-03-25 11:30:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* LookupAccountSidW [ADVAPI32.@]
|
|
|
|
*
|
2004-12-14 06:40:50 +00:00
|
|
|
* @implemented
|
2004-03-25 11:30:07 +00:00
|
|
|
*/
|
2004-12-14 06:40:50 +00:00
|
|
|
BOOL WINAPI
|
2008-09-21 13:55:53 +00:00
|
|
|
LookupAccountSidW(LPCWSTR pSystemName,
|
|
|
|
PSID pSid,
|
|
|
|
LPWSTR pAccountName,
|
|
|
|
LPDWORD pdwAccountName,
|
|
|
|
LPWSTR pDomainName,
|
|
|
|
LPDWORD pdwDomainName,
|
|
|
|
PSID_NAME_USE peUse)
|
2004-03-25 11:30:07 +00:00
|
|
|
{
|
2010-07-20 20:48:11 +00:00
|
|
|
LSA_UNICODE_STRING SystemName;
|
|
|
|
LSA_OBJECT_ATTRIBUTES ObjectAttributes = {0};
|
|
|
|
LSA_HANDLE PolicyHandle = NULL;
|
|
|
|
NTSTATUS Status;
|
|
|
|
PLSA_REFERENCED_DOMAIN_LIST ReferencedDomain = NULL;
|
|
|
|
PLSA_TRANSLATED_NAME TranslatedName = NULL;
|
|
|
|
BOOL ret;
|
|
|
|
DWORD dwAccountName, dwDomainName;
|
|
|
|
|
|
|
|
RtlInitUnicodeString(&SystemName, pSystemName);
|
|
|
|
Status = LsaOpenPolicy(&SystemName, &ObjectAttributes, POLICY_LOOKUP_NAMES, &PolicyHandle);
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
SetLastError(LsaNtStatusToWinError(Status));
|
|
|
|
return FALSE;
|
|
|
|
}
|
2004-03-25 11:30:07 +00:00
|
|
|
|
2010-07-20 20:48:11 +00:00
|
|
|
Status = LsaLookupSids(PolicyHandle, 1, &pSid, &ReferencedDomain, &TranslatedName);
|
|
|
|
|
|
|
|
LsaClose(PolicyHandle);
|
|
|
|
|
|
|
|
if (!NT_SUCCESS(Status) || Status == STATUS_SOME_NOT_MAPPED)
|
|
|
|
{
|
|
|
|
SetLastError(LsaNtStatusToWinError(Status));
|
|
|
|
ret = FALSE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ret = TRUE;
|
|
|
|
|
|
|
|
dwAccountName = TranslatedName->Name.Length / sizeof(WCHAR);
|
|
|
|
if (ReferencedDomain && ReferencedDomain->Entries > 0)
|
|
|
|
dwDomainName = ReferencedDomain->Domains[0].Name.Length / sizeof(WCHAR);
|
|
|
|
else
|
|
|
|
dwDomainName = 0;
|
|
|
|
|
|
|
|
if (*pdwAccountName <= dwAccountName || *pdwDomainName <= dwDomainName)
|
|
|
|
{
|
|
|
|
/* One or two buffers are insufficient, add up a char for NULL termination */
|
|
|
|
*pdwAccountName = dwAccountName + 1;
|
|
|
|
*pdwDomainName = dwDomainName + 1;
|
|
|
|
ret = FALSE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Lengths are sufficient, copy the data */
|
|
|
|
if (dwAccountName)
|
|
|
|
RtlCopyMemory(pAccountName, TranslatedName->Name.Buffer, dwAccountName * sizeof(WCHAR));
|
|
|
|
pAccountName[dwAccountName] = L'\0';
|
|
|
|
|
|
|
|
if (dwDomainName)
|
|
|
|
RtlCopyMemory(pDomainName, ReferencedDomain->Domains[0].Name.Buffer, dwDomainName * sizeof(WCHAR));
|
|
|
|
pDomainName[dwDomainName] = L'\0';
|
|
|
|
|
|
|
|
*pdwAccountName = dwAccountName;
|
|
|
|
*pdwDomainName = dwDomainName;
|
|
|
|
|
|
|
|
if (peUse)
|
|
|
|
*peUse = TranslatedName->Use;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!ret)
|
|
|
|
SetLastError(ERROR_INSUFFICIENT_BUFFER);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ReferencedDomain)
|
|
|
|
LsaFreeMemory(ReferencedDomain);
|
|
|
|
|
|
|
|
if (TranslatedName)
|
|
|
|
LsaFreeMemory(TranslatedName);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
2004-03-25 11:30:07 +00:00
|
|
|
|
2004-09-26 20:26:13 +00:00
|
|
|
/******************************************************************************
|
|
|
|
* LookupAccountNameW [ADVAPI32.@]
|
|
|
|
*
|
2010-07-18 20:34:34 +00:00
|
|
|
* @implemented
|
2004-09-26 20:26:13 +00:00
|
|
|
*/
|
2008-09-21 13:55:53 +00:00
|
|
|
BOOL
|
|
|
|
WINAPI
|
|
|
|
LookupAccountNameW(LPCWSTR lpSystemName,
|
|
|
|
LPCWSTR lpAccountName,
|
|
|
|
PSID Sid,
|
|
|
|
LPDWORD cbSid,
|
|
|
|
LPWSTR ReferencedDomainName,
|
|
|
|
LPDWORD cchReferencedDomainName,
|
|
|
|
PSID_NAME_USE peUse)
|
2004-09-26 20:26:13 +00:00
|
|
|
{
|
2010-07-18 20:34:34 +00:00
|
|
|
OBJECT_ATTRIBUTES ObjectAttributes = {0};
|
|
|
|
UNICODE_STRING SystemName;
|
|
|
|
UNICODE_STRING AccountName;
|
|
|
|
LSA_HANDLE PolicyHandle = NULL;
|
|
|
|
PLSA_REFERENCED_DOMAIN_LIST ReferencedDomains = NULL;
|
|
|
|
PLSA_TRANSLATED_SID TranslatedSid = NULL;
|
|
|
|
PSID pDomainSid;
|
|
|
|
DWORD dwDomainNameLength;
|
|
|
|
DWORD dwSidLength;
|
|
|
|
UCHAR nSubAuthorities;
|
|
|
|
BOOL bResult;
|
|
|
|
NTSTATUS Status;
|
2008-02-07 14:05:10 +00:00
|
|
|
|
2010-07-18 20:34:34 +00:00
|
|
|
TRACE("%s %s %p %p %p %p %p\n", lpSystemName, lpAccountName,
|
2008-02-07 14:05:10 +00:00
|
|
|
Sid, cbSid, ReferencedDomainName, cchReferencedDomainName, peUse);
|
|
|
|
|
2010-07-18 20:34:34 +00:00
|
|
|
RtlInitUnicodeString(&SystemName,
|
|
|
|
lpSystemName);
|
|
|
|
|
|
|
|
Status = LsaOpenPolicy(lpSystemName ? &SystemName : NULL,
|
|
|
|
&ObjectAttributes,
|
|
|
|
POLICY_LOOKUP_NAMES,
|
|
|
|
&PolicyHandle);
|
|
|
|
if (!NT_SUCCESS(Status))
|
2008-12-30 16:01:13 +00:00
|
|
|
{
|
2010-07-18 20:34:34 +00:00
|
|
|
SetLastError(LsaNtStatusToWinError(Status));
|
2008-12-30 16:01:13 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2010-07-18 20:34:34 +00:00
|
|
|
RtlInitUnicodeString(&AccountName,
|
|
|
|
lpAccountName);
|
2008-02-07 14:05:10 +00:00
|
|
|
|
2010-07-18 20:34:34 +00:00
|
|
|
Status = LsaLookupNames(PolicyHandle,
|
|
|
|
1,
|
|
|
|
&AccountName,
|
|
|
|
&ReferencedDomains,
|
|
|
|
&TranslatedSid);
|
2008-02-07 14:05:10 +00:00
|
|
|
|
2010-07-18 20:34:34 +00:00
|
|
|
LsaClose(PolicyHandle);
|
2008-02-07 14:05:10 +00:00
|
|
|
|
2010-07-18 20:34:34 +00:00
|
|
|
if (!NT_SUCCESS(Status) || Status == STATUS_SOME_NOT_MAPPED)
|
2008-02-07 14:05:10 +00:00
|
|
|
{
|
2010-07-18 20:34:34 +00:00
|
|
|
SetLastError(LsaNtStatusToWinError(Status));
|
|
|
|
bResult = FALSE;
|
2008-02-07 14:05:10 +00:00
|
|
|
}
|
2010-07-18 20:34:34 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
pDomainSid = ReferencedDomains->Domains[TranslatedSid->DomainIndex].Sid;
|
|
|
|
nSubAuthorities = *GetSidSubAuthorityCount(pDomainSid);
|
|
|
|
dwSidLength = GetSidLengthRequired(nSubAuthorities + 1);
|
2008-02-07 14:05:10 +00:00
|
|
|
|
2010-07-18 20:34:34 +00:00
|
|
|
dwDomainNameLength = ReferencedDomains->Domains->Name.Length / sizeof(WCHAR);
|
2008-09-21 13:55:53 +00:00
|
|
|
|
2010-07-18 20:34:34 +00:00
|
|
|
if (*cbSid < dwSidLength ||
|
|
|
|
*cchReferencedDomainName < dwDomainNameLength + 1)
|
|
|
|
{
|
|
|
|
*cbSid = dwSidLength;
|
|
|
|
*cchReferencedDomainName = dwDomainNameLength + 1;
|
|
|
|
|
|
|
|
bResult = FALSE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
CopySid(*cbSid, Sid, pDomainSid);
|
|
|
|
*GetSidSubAuthorityCount(Sid) = nSubAuthorities + 1;
|
|
|
|
*GetSidSubAuthority(Sid, (DWORD)nSubAuthorities) = TranslatedSid->RelativeId;
|
2008-09-21 13:55:53 +00:00
|
|
|
|
2010-07-18 20:34:34 +00:00
|
|
|
RtlCopyMemory(ReferencedDomainName, ReferencedDomains->Domains->Name.Buffer, dwDomainNameLength * sizeof(WCHAR));
|
|
|
|
ReferencedDomainName[dwDomainNameLength] = L'\0';
|
2008-09-21 13:55:53 +00:00
|
|
|
|
2010-07-18 20:34:34 +00:00
|
|
|
*cchReferencedDomainName = dwDomainNameLength;
|
2008-02-07 14:05:10 +00:00
|
|
|
|
2010-07-18 20:34:34 +00:00
|
|
|
*peUse = TranslatedSid->Use;
|
|
|
|
|
|
|
|
bResult = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (bResult == FALSE)
|
|
|
|
SetLastError(ERROR_INSUFFICIENT_BUFFER);
|
2008-02-07 14:05:10 +00:00
|
|
|
}
|
|
|
|
|
2010-07-18 20:34:34 +00:00
|
|
|
if (ReferencedDomains != NULL)
|
|
|
|
LsaFreeMemory(ReferencedDomains);
|
2008-02-07 14:05:10 +00:00
|
|
|
|
2010-07-18 20:34:34 +00:00
|
|
|
if (TranslatedSid != NULL)
|
|
|
|
LsaFreeMemory(TranslatedSid);
|
|
|
|
|
|
|
|
return bResult;
|
2004-09-26 20:26:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-03-25 11:30:07 +00:00
|
|
|
/**********************************************************************
|
|
|
|
* LookupPrivilegeValueA EXPORTED
|
|
|
|
*
|
|
|
|
* @implemented
|
|
|
|
*/
|
2008-09-21 13:55:53 +00:00
|
|
|
BOOL
|
2008-11-30 11:42:05 +00:00
|
|
|
WINAPI
|
2008-09-21 13:55:53 +00:00
|
|
|
LookupPrivilegeValueA(LPCSTR lpSystemName,
|
|
|
|
LPCSTR lpName,
|
|
|
|
PLUID lpLuid)
|
2004-03-25 11:30:07 +00:00
|
|
|
{
|
2008-09-21 13:55:53 +00:00
|
|
|
UNICODE_STRING SystemName;
|
|
|
|
UNICODE_STRING Name;
|
|
|
|
BOOL Result;
|
2004-03-25 11:30:07 +00:00
|
|
|
|
2008-09-21 13:55:53 +00:00
|
|
|
/* Remote system? */
|
|
|
|
if (lpSystemName != NULL)
|
2004-03-25 11:30:07 +00:00
|
|
|
{
|
2008-09-21 13:55:53 +00:00
|
|
|
RtlCreateUnicodeStringFromAsciiz(&SystemName,
|
|
|
|
(LPSTR)lpSystemName);
|
2004-03-25 11:30:07 +00:00
|
|
|
}
|
2010-07-20 20:48:11 +00:00
|
|
|
else
|
|
|
|
SystemName.Buffer = NULL;
|
2004-03-25 11:30:07 +00:00
|
|
|
|
2008-09-21 13:55:53 +00:00
|
|
|
/* Check the privilege name is not NULL */
|
|
|
|
if (lpName == NULL)
|
2004-03-25 11:30:07 +00:00
|
|
|
{
|
2008-10-26 18:03:38 +00:00
|
|
|
SetLastError(ERROR_NO_SUCH_PRIVILEGE);
|
2008-09-21 13:55:53 +00:00
|
|
|
return FALSE;
|
2004-03-25 11:30:07 +00:00
|
|
|
}
|
|
|
|
|
2008-09-21 13:55:53 +00:00
|
|
|
RtlCreateUnicodeStringFromAsciiz(&Name,
|
|
|
|
(LPSTR)lpName);
|
2004-03-25 11:30:07 +00:00
|
|
|
|
2008-11-06 00:24:40 +00:00
|
|
|
Result = LookupPrivilegeValueW(SystemName.Buffer,
|
2008-09-21 13:55:53 +00:00
|
|
|
Name.Buffer,
|
|
|
|
lpLuid);
|
2004-03-25 11:30:07 +00:00
|
|
|
|
2008-09-21 13:55:53 +00:00
|
|
|
RtlFreeUnicodeString(&Name);
|
2004-03-25 11:30:07 +00:00
|
|
|
|
2008-09-21 13:55:53 +00:00
|
|
|
/* Remote system? */
|
2008-11-06 00:24:40 +00:00
|
|
|
if (SystemName.Buffer != NULL)
|
2004-03-25 11:30:07 +00:00
|
|
|
{
|
2008-09-21 13:55:53 +00:00
|
|
|
RtlFreeUnicodeString(&SystemName);
|
2004-03-25 11:30:07 +00:00
|
|
|
}
|
|
|
|
|
2008-09-21 13:55:53 +00:00
|
|
|
return Result;
|
2004-03-25 11:30:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**********************************************************************
|
2010-07-03 22:51:44 +00:00
|
|
|
* LookupPrivilegeValueW
|
2004-03-25 11:30:07 +00:00
|
|
|
*
|
2010-07-03 22:51:44 +00:00
|
|
|
* @implemented
|
2004-03-25 11:30:07 +00:00
|
|
|
*/
|
2008-09-21 13:55:53 +00:00
|
|
|
BOOL
|
2008-11-30 11:42:05 +00:00
|
|
|
WINAPI
|
2010-07-03 22:51:44 +00:00
|
|
|
LookupPrivilegeValueW(LPCWSTR lpSystemName,
|
|
|
|
LPCWSTR lpPrivilegeName,
|
|
|
|
PLUID lpLuid)
|
2004-03-25 11:30:07 +00:00
|
|
|
{
|
2010-07-04 12:51:39 +00:00
|
|
|
OBJECT_ATTRIBUTES ObjectAttributes = {0};
|
|
|
|
UNICODE_STRING SystemName;
|
|
|
|
UNICODE_STRING PrivilegeName;
|
2010-07-03 22:51:44 +00:00
|
|
|
LSA_HANDLE PolicyHandle = NULL;
|
|
|
|
NTSTATUS Status;
|
|
|
|
|
2010-07-04 12:51:39 +00:00
|
|
|
TRACE("%S,%S,%p\n", lpSystemName, lpPrivilegeName, lpLuid);
|
|
|
|
|
2010-07-03 22:51:44 +00:00
|
|
|
RtlInitUnicodeString(&SystemName,
|
|
|
|
lpSystemName);
|
|
|
|
|
|
|
|
Status = LsaOpenPolicy(lpSystemName ? &SystemName : NULL,
|
|
|
|
&ObjectAttributes,
|
|
|
|
POLICY_LOOKUP_NAMES,
|
|
|
|
&PolicyHandle);
|
|
|
|
if (!NT_SUCCESS(Status))
|
2008-12-30 17:10:40 +00:00
|
|
|
{
|
2010-07-03 22:51:44 +00:00
|
|
|
SetLastError(LsaNtStatusToWinError(Status));
|
Sync aclui, advapi32, atl, authz, kernel32, msi, oledlg, powrprof, qmgr, riched20, samlib to Wine 1.2rc5
Update some psdk Headers to get some more synched winetests build
svn path=/trunk/; revision=47930
2010-07-03 12:42:55 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2008-12-30 17:10:40 +00:00
|
|
|
|
2010-07-03 22:51:44 +00:00
|
|
|
RtlInitUnicodeString(&PrivilegeName,
|
|
|
|
lpPrivilegeName);
|
|
|
|
|
|
|
|
Status = LsaLookupPrivilegeValue(PolicyHandle,
|
|
|
|
&PrivilegeName,
|
|
|
|
lpLuid);
|
|
|
|
|
|
|
|
LsaClose(PolicyHandle);
|
2004-07-06 22:08:48 +00:00
|
|
|
|
2010-07-03 22:51:44 +00:00
|
|
|
if (!NT_SUCCESS(Status))
|
2004-07-06 22:08:48 +00:00
|
|
|
{
|
2010-07-03 22:51:44 +00:00
|
|
|
SetLastError(LsaNtStatusToWinError(Status));
|
|
|
|
return FALSE;
|
2004-07-06 22:08:48 +00:00
|
|
|
}
|
|
|
|
|
2010-07-03 22:51:44 +00:00
|
|
|
return TRUE;
|
2004-03-25 11:30:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* LookupPrivilegeNameW EXPORTED
|
|
|
|
*
|
2008-11-10 14:23:57 +00:00
|
|
|
* @implemented
|
2004-03-25 11:30:07 +00:00
|
|
|
*/
|
2008-09-21 13:55:53 +00:00
|
|
|
BOOL
|
2008-11-30 11:42:05 +00:00
|
|
|
WINAPI
|
2008-09-21 13:55:53 +00:00
|
|
|
LookupPrivilegeNameW(LPCWSTR lpSystemName,
|
|
|
|
PLUID lpLuid,
|
|
|
|
LPWSTR lpName,
|
2008-11-10 14:23:57 +00:00
|
|
|
LPDWORD cchName)
|
2004-03-25 11:30:07 +00:00
|
|
|
{
|
2010-07-04 12:51:39 +00:00
|
|
|
OBJECT_ATTRIBUTES ObjectAttributes = {0};
|
|
|
|
UNICODE_STRING SystemName;
|
|
|
|
PUNICODE_STRING PrivilegeName = NULL;
|
|
|
|
LSA_HANDLE PolicyHandle = NULL;
|
|
|
|
NTSTATUS Status;
|
2008-11-10 14:23:57 +00:00
|
|
|
|
2010-07-04 12:51:39 +00:00
|
|
|
TRACE("%S,%p,%p,%p\n", lpSystemName, lpLuid, lpName, cchName);
|
2008-11-10 14:23:57 +00:00
|
|
|
|
2010-07-04 12:51:39 +00:00
|
|
|
RtlInitUnicodeString(&SystemName,
|
|
|
|
lpSystemName);
|
|
|
|
|
|
|
|
Status = LsaOpenPolicy(lpSystemName ? &SystemName : NULL,
|
|
|
|
&ObjectAttributes,
|
|
|
|
POLICY_LOOKUP_NAMES,
|
|
|
|
&PolicyHandle);
|
|
|
|
if (!NT_SUCCESS(Status))
|
2008-11-10 14:23:57 +00:00
|
|
|
{
|
2010-07-04 12:51:39 +00:00
|
|
|
SetLastError(LsaNtStatusToWinError(Status));
|
2008-11-10 14:23:57 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2008-12-30 17:10:40 +00:00
|
|
|
|
2010-07-04 12:51:39 +00:00
|
|
|
Status = LsaLookupPrivilegeName(PolicyHandle,
|
|
|
|
lpLuid,
|
|
|
|
&PrivilegeName);
|
|
|
|
if (NT_SUCCESS(Status))
|
2008-11-10 14:23:57 +00:00
|
|
|
{
|
2010-07-18 20:34:34 +00:00
|
|
|
if (PrivilegeName->Length + sizeof(WCHAR) > *cchName * sizeof(WCHAR))
|
2010-07-04 12:51:39 +00:00
|
|
|
{
|
|
|
|
Status = STATUS_BUFFER_TOO_SMALL;
|
|
|
|
|
2010-07-18 20:34:34 +00:00
|
|
|
*cchName = (PrivilegeName->Length + sizeof(WCHAR)) / sizeof(WCHAR);
|
2010-07-04 12:51:39 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
RtlMoveMemory(lpName,
|
|
|
|
PrivilegeName->Buffer,
|
|
|
|
PrivilegeName->Length);
|
|
|
|
lpName[PrivilegeName->Length / sizeof(WCHAR)] = 0;
|
|
|
|
|
2010-07-18 20:34:34 +00:00
|
|
|
*cchName = PrivilegeName->Length / sizeof(WCHAR);
|
2010-07-04 12:51:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
LsaFreeMemory(PrivilegeName->Buffer);
|
|
|
|
LsaFreeMemory(PrivilegeName);
|
2008-11-10 14:23:57 +00:00
|
|
|
}
|
2010-07-04 12:51:39 +00:00
|
|
|
|
|
|
|
LsaClose(PolicyHandle);
|
|
|
|
|
|
|
|
if (!NT_SUCCESS(Status))
|
2008-11-10 14:23:57 +00:00
|
|
|
{
|
2010-07-04 12:51:39 +00:00
|
|
|
SetLastError(LsaNtStatusToWinError(Status));
|
2008-11-10 14:23:57 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2010-07-04 12:51:39 +00:00
|
|
|
|
|
|
|
return TRUE;
|
2004-03-25 11:30:07 +00:00
|
|
|
}
|
|
|
|
|
2014-12-27 19:57:42 +00:00
|
|
|
/**********************************************************************
|
|
|
|
* LookupPrivilegeDisplayNameW EXPORTED
|
|
|
|
*
|
|
|
|
* @unimplemented
|
|
|
|
*/
|
|
|
|
BOOL
|
|
|
|
WINAPI
|
|
|
|
LookupPrivilegeDisplayNameW(LPCWSTR lpSystemName,
|
|
|
|
LPCWSTR lpName,
|
|
|
|
LPWSTR lpDisplayName,
|
|
|
|
LPDWORD cchDisplayName,
|
|
|
|
LPDWORD lpLanguageId)
|
|
|
|
{
|
|
|
|
OBJECT_ATTRIBUTES ObjectAttributes = {0};
|
|
|
|
UNICODE_STRING SystemName, Name;
|
|
|
|
PUNICODE_STRING DisplayName;
|
|
|
|
LSA_HANDLE PolicyHandle = NULL;
|
|
|
|
USHORT LanguageId;
|
|
|
|
NTSTATUS Status;
|
|
|
|
|
|
|
|
TRACE("%S,%S,%p,%p,%p\n", lpSystemName, lpName, lpDisplayName, cchDisplayName, lpLanguageId);
|
|
|
|
|
|
|
|
RtlInitUnicodeString(&SystemName, lpSystemName);
|
|
|
|
RtlInitUnicodeString(&Name, lpName);
|
|
|
|
|
|
|
|
Status = LsaOpenPolicy(lpSystemName ? &SystemName : NULL,
|
|
|
|
&ObjectAttributes,
|
|
|
|
POLICY_LOOKUP_NAMES,
|
|
|
|
&PolicyHandle);
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
SetLastError(LsaNtStatusToWinError(Status));
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
Status = LsaLookupPrivilegeDisplayName(PolicyHandle, &Name, &DisplayName, &LanguageId);
|
|
|
|
if (NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
*lpLanguageId = LanguageId;
|
|
|
|
if (DisplayName->Length + sizeof(WCHAR) > *cchDisplayName * sizeof(WCHAR))
|
|
|
|
{
|
|
|
|
Status = STATUS_BUFFER_TOO_SMALL;
|
|
|
|
|
|
|
|
*cchDisplayName = (DisplayName->Length + sizeof(WCHAR)) / sizeof(WCHAR);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
RtlMoveMemory(lpDisplayName,
|
|
|
|
DisplayName->Buffer,
|
|
|
|
DisplayName->Length);
|
|
|
|
lpDisplayName[DisplayName->Length / sizeof(WCHAR)] = 0;
|
|
|
|
|
|
|
|
*cchDisplayName = DisplayName->Length / sizeof(WCHAR);
|
|
|
|
}
|
|
|
|
|
|
|
|
LsaFreeMemory(DisplayName->Buffer);
|
|
|
|
LsaFreeMemory(DisplayName);
|
|
|
|
}
|
|
|
|
|
|
|
|
LsaClose(PolicyHandle);
|
|
|
|
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
SetLastError(LsaNtStatusToWinError(Status));
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
2004-05-26 09:50:10 +00:00
|
|
|
|
2005-07-26 22:21:02 +00:00
|
|
|
static DWORD
|
|
|
|
pGetSecurityInfoCheck(SECURITY_INFORMATION SecurityInfo,
|
2008-09-21 13:55:53 +00:00
|
|
|
PSID *ppsidOwner,
|
|
|
|
PSID *ppsidGroup,
|
|
|
|
PACL *ppDacl,
|
|
|
|
PACL *ppSacl,
|
2005-07-26 22:21:02 +00:00
|
|
|
PSECURITY_DESCRIPTOR* ppSecurityDescriptor)
|
|
|
|
{
|
|
|
|
if ((SecurityInfo & (OWNER_SECURITY_INFORMATION |
|
|
|
|
GROUP_SECURITY_INFORMATION |
|
|
|
|
DACL_SECURITY_INFORMATION |
|
|
|
|
SACL_SECURITY_INFORMATION)) &&
|
|
|
|
ppSecurityDescriptor == NULL)
|
|
|
|
{
|
|
|
|
/* if one of the SIDs or ACLs are present, the security descriptor
|
|
|
|
most not be NULL */
|
|
|
|
return ERROR_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* reset the pointers unless they're ignored */
|
|
|
|
if ((SecurityInfo & OWNER_SECURITY_INFORMATION) &&
|
|
|
|
ppsidOwner != NULL)
|
|
|
|
{
|
2005-10-20 17:59:00 +00:00
|
|
|
*ppsidOwner = NULL;
|
2005-07-26 22:21:02 +00:00
|
|
|
}
|
|
|
|
if ((SecurityInfo & GROUP_SECURITY_INFORMATION) &&
|
2005-10-20 17:59:00 +00:00
|
|
|
ppsidGroup != NULL)
|
2005-07-26 22:21:02 +00:00
|
|
|
{
|
|
|
|
*ppsidGroup = NULL;
|
|
|
|
}
|
|
|
|
if ((SecurityInfo & DACL_SECURITY_INFORMATION) &&
|
|
|
|
ppDacl != NULL)
|
|
|
|
{
|
|
|
|
*ppDacl = NULL;
|
|
|
|
}
|
|
|
|
if ((SecurityInfo & SACL_SECURITY_INFORMATION) &&
|
|
|
|
ppSacl != NULL)
|
|
|
|
{
|
|
|
|
*ppSacl = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (SecurityInfo & (OWNER_SECURITY_INFORMATION |
|
|
|
|
GROUP_SECURITY_INFORMATION |
|
|
|
|
DACL_SECURITY_INFORMATION |
|
|
|
|
SACL_SECURITY_INFORMATION))
|
|
|
|
{
|
|
|
|
*ppSecurityDescriptor = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static DWORD
|
|
|
|
pSetSecurityInfoCheck(PSECURITY_DESCRIPTOR pSecurityDescriptor,
|
|
|
|
SECURITY_INFORMATION SecurityInfo,
|
|
|
|
PSID psidOwner,
|
|
|
|
PSID psidGroup,
|
|
|
|
PACL pDacl,
|
|
|
|
PACL pSacl)
|
|
|
|
{
|
|
|
|
/* initialize a security descriptor on the stack */
|
|
|
|
if (!InitializeSecurityDescriptor(pSecurityDescriptor,
|
|
|
|
SECURITY_DESCRIPTOR_REVISION))
|
|
|
|
{
|
|
|
|
return GetLastError();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (SecurityInfo & OWNER_SECURITY_INFORMATION)
|
|
|
|
{
|
|
|
|
if (RtlValidSid(psidOwner))
|
|
|
|
{
|
|
|
|
if (!SetSecurityDescriptorOwner(pSecurityDescriptor,
|
|
|
|
psidOwner,
|
|
|
|
FALSE))
|
|
|
|
{
|
|
|
|
return GetLastError();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return ERROR_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (SecurityInfo & GROUP_SECURITY_INFORMATION)
|
|
|
|
{
|
|
|
|
if (RtlValidSid(psidGroup))
|
|
|
|
{
|
|
|
|
if (!SetSecurityDescriptorGroup(pSecurityDescriptor,
|
|
|
|
psidGroup,
|
|
|
|
FALSE))
|
|
|
|
{
|
|
|
|
return GetLastError();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return ERROR_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (SecurityInfo & DACL_SECURITY_INFORMATION)
|
|
|
|
{
|
|
|
|
if (pDacl != NULL)
|
|
|
|
{
|
|
|
|
if (SetSecurityDescriptorDacl(pSecurityDescriptor,
|
|
|
|
TRUE,
|
|
|
|
pDacl,
|
|
|
|
FALSE))
|
|
|
|
{
|
|
|
|
/* check if the DACL needs to be protected from being
|
|
|
|
modified by inheritable ACEs */
|
|
|
|
if (SecurityInfo & PROTECTED_DACL_SECURITY_INFORMATION)
|
|
|
|
{
|
|
|
|
goto ProtectDacl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return GetLastError();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ProtectDacl:
|
|
|
|
/* protect the DACL from being modified by inheritable ACEs */
|
|
|
|
if (!SetSecurityDescriptorControl(pSecurityDescriptor,
|
|
|
|
SE_DACL_PROTECTED,
|
|
|
|
SE_DACL_PROTECTED))
|
|
|
|
{
|
|
|
|
return GetLastError();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (SecurityInfo & SACL_SECURITY_INFORMATION)
|
|
|
|
{
|
|
|
|
if (pSacl != NULL)
|
|
|
|
{
|
|
|
|
if (SetSecurityDescriptorSacl(pSecurityDescriptor,
|
|
|
|
TRUE,
|
|
|
|
pSacl,
|
|
|
|
FALSE))
|
|
|
|
{
|
|
|
|
/* check if the SACL needs to be protected from being
|
|
|
|
modified by inheritable ACEs */
|
|
|
|
if (SecurityInfo & PROTECTED_SACL_SECURITY_INFORMATION)
|
|
|
|
{
|
|
|
|
goto ProtectSacl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return GetLastError();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ProtectSacl:
|
|
|
|
/* protect the SACL from being modified by inheritable ACEs */
|
|
|
|
if (!SetSecurityDescriptorControl(pSecurityDescriptor,
|
|
|
|
SE_SACL_PROTECTED,
|
|
|
|
SE_SACL_PROTECTED))
|
|
|
|
{
|
|
|
|
return GetLastError();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-10-19 23:21:45 +00:00
|
|
|
|
2005-07-26 22:21:02 +00:00
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-05-26 09:50:10 +00:00
|
|
|
/**********************************************************************
|
|
|
|
* GetNamedSecurityInfoW EXPORTED
|
|
|
|
*
|
2005-07-26 22:21:02 +00:00
|
|
|
* @implemented
|
2004-05-26 09:50:10 +00:00
|
|
|
*/
|
2008-09-21 13:55:53 +00:00
|
|
|
DWORD
|
2008-11-30 11:42:05 +00:00
|
|
|
WINAPI
|
2004-05-26 09:50:10 +00:00
|
|
|
GetNamedSecurityInfoW(LPWSTR pObjectName,
|
|
|
|
SE_OBJECT_TYPE ObjectType,
|
|
|
|
SECURITY_INFORMATION SecurityInfo,
|
|
|
|
PSID *ppsidOwner,
|
|
|
|
PSID *ppsidGroup,
|
|
|
|
PACL *ppDacl,
|
|
|
|
PACL *ppSacl,
|
|
|
|
PSECURITY_DESCRIPTOR *ppSecurityDescriptor)
|
|
|
|
{
|
2005-07-26 22:21:02 +00:00
|
|
|
DWORD ErrorCode;
|
|
|
|
|
|
|
|
if (pObjectName != NULL)
|
|
|
|
{
|
|
|
|
ErrorCode = CheckNtMartaPresent();
|
|
|
|
if (ErrorCode == ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
ErrorCode = pGetSecurityInfoCheck(SecurityInfo,
|
|
|
|
ppsidOwner,
|
|
|
|
ppsidGroup,
|
|
|
|
ppDacl,
|
|
|
|
ppSacl,
|
|
|
|
ppSecurityDescriptor);
|
|
|
|
|
|
|
|
if (ErrorCode == ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
/* call the MARTA provider */
|
|
|
|
ErrorCode = AccRewriteGetNamedRights(pObjectName,
|
|
|
|
ObjectType,
|
|
|
|
SecurityInfo,
|
|
|
|
ppsidOwner,
|
|
|
|
ppsidGroup,
|
|
|
|
ppDacl,
|
|
|
|
ppSacl,
|
|
|
|
ppSecurityDescriptor);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
ErrorCode = ERROR_INVALID_PARAMETER;
|
|
|
|
|
|
|
|
return ErrorCode;
|
2004-05-26 09:50:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* SetNamedSecurityInfoW EXPORTED
|
|
|
|
*
|
2005-07-26 22:21:02 +00:00
|
|
|
* @implemented
|
2004-05-26 09:50:10 +00:00
|
|
|
*/
|
2008-09-21 13:55:53 +00:00
|
|
|
DWORD
|
2008-11-30 11:42:05 +00:00
|
|
|
WINAPI
|
2004-05-26 09:50:10 +00:00
|
|
|
SetNamedSecurityInfoW(LPWSTR pObjectName,
|
|
|
|
SE_OBJECT_TYPE ObjectType,
|
|
|
|
SECURITY_INFORMATION SecurityInfo,
|
|
|
|
PSID psidOwner,
|
|
|
|
PSID psidGroup,
|
|
|
|
PACL pDacl,
|
|
|
|
PACL pSacl)
|
|
|
|
{
|
2005-07-26 22:21:02 +00:00
|
|
|
DWORD ErrorCode;
|
2007-10-19 23:21:45 +00:00
|
|
|
|
2005-07-26 22:21:02 +00:00
|
|
|
if (pObjectName != NULL)
|
|
|
|
{
|
|
|
|
ErrorCode = CheckNtMartaPresent();
|
|
|
|
if (ErrorCode == ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
SECURITY_DESCRIPTOR SecurityDescriptor;
|
|
|
|
|
|
|
|
ErrorCode = pSetSecurityInfoCheck(&SecurityDescriptor,
|
|
|
|
SecurityInfo,
|
|
|
|
psidOwner,
|
|
|
|
psidGroup,
|
|
|
|
pDacl,
|
|
|
|
pSacl);
|
|
|
|
|
|
|
|
if (ErrorCode == ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
/* call the MARTA provider */
|
|
|
|
ErrorCode = AccRewriteSetNamedRights(pObjectName,
|
|
|
|
ObjectType,
|
|
|
|
SecurityInfo,
|
|
|
|
&SecurityDescriptor);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
ErrorCode = ERROR_INVALID_PARAMETER;
|
|
|
|
|
|
|
|
return ErrorCode;
|
2004-05-26 09:50:10 +00:00
|
|
|
}
|
|
|
|
|
2004-07-10 14:38:24 +00:00
|
|
|
/**********************************************************************
|
|
|
|
* GetSecurityInfo EXPORTED
|
|
|
|
*
|
2005-07-26 22:21:02 +00:00
|
|
|
* @implemented
|
2004-07-10 14:38:24 +00:00
|
|
|
*/
|
2008-09-21 13:55:53 +00:00
|
|
|
DWORD
|
2008-11-30 11:42:05 +00:00
|
|
|
WINAPI
|
2004-07-10 14:38:24 +00:00
|
|
|
GetSecurityInfo(HANDLE handle,
|
|
|
|
SE_OBJECT_TYPE ObjectType,
|
|
|
|
SECURITY_INFORMATION SecurityInfo,
|
2008-09-21 13:55:53 +00:00
|
|
|
PSID *ppsidOwner,
|
|
|
|
PSID *ppsidGroup,
|
|
|
|
PACL *ppDacl,
|
|
|
|
PACL *ppSacl,
|
|
|
|
PSECURITY_DESCRIPTOR *ppSecurityDescriptor)
|
2004-07-10 14:38:24 +00:00
|
|
|
{
|
2005-07-26 21:20:55 +00:00
|
|
|
DWORD ErrorCode;
|
2007-10-19 23:21:45 +00:00
|
|
|
|
2005-07-26 21:20:55 +00:00
|
|
|
if (handle != NULL)
|
|
|
|
{
|
|
|
|
ErrorCode = CheckNtMartaPresent();
|
|
|
|
if (ErrorCode == ERROR_SUCCESS)
|
|
|
|
{
|
2005-07-26 22:21:02 +00:00
|
|
|
ErrorCode = pGetSecurityInfoCheck(SecurityInfo,
|
|
|
|
ppsidOwner,
|
|
|
|
ppsidGroup,
|
|
|
|
ppDacl,
|
|
|
|
ppSacl,
|
|
|
|
ppSecurityDescriptor);
|
|
|
|
|
|
|
|
if (ErrorCode == ERROR_SUCCESS)
|
2005-07-26 21:20:55 +00:00
|
|
|
{
|
2005-07-26 22:21:02 +00:00
|
|
|
/* call the MARTA provider */
|
2005-07-26 21:20:55 +00:00
|
|
|
ErrorCode = AccRewriteGetHandleRights(handle,
|
|
|
|
ObjectType,
|
|
|
|
SecurityInfo,
|
|
|
|
ppsidOwner,
|
|
|
|
ppsidGroup,
|
|
|
|
ppDacl,
|
|
|
|
ppSacl,
|
|
|
|
ppSecurityDescriptor);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
ErrorCode = ERROR_INVALID_HANDLE;
|
|
|
|
|
|
|
|
return ErrorCode;
|
2004-07-10 14:38:24 +00:00
|
|
|
}
|
|
|
|
|
2004-09-06 22:12:25 +00:00
|
|
|
|
2004-12-13 19:06:28 +00:00
|
|
|
/**********************************************************************
|
|
|
|
* SetSecurityInfo EXPORTED
|
|
|
|
*
|
2005-07-26 22:21:02 +00:00
|
|
|
* @implemented
|
2004-12-13 19:06:28 +00:00
|
|
|
*/
|
|
|
|
DWORD
|
|
|
|
WINAPI
|
|
|
|
SetSecurityInfo(HANDLE handle,
|
|
|
|
SE_OBJECT_TYPE ObjectType,
|
|
|
|
SECURITY_INFORMATION SecurityInfo,
|
|
|
|
PSID psidOwner,
|
|
|
|
PSID psidGroup,
|
|
|
|
PACL pDacl,
|
|
|
|
PACL pSacl)
|
|
|
|
{
|
2005-07-26 21:20:55 +00:00
|
|
|
DWORD ErrorCode;
|
|
|
|
|
|
|
|
if (handle != NULL)
|
|
|
|
{
|
|
|
|
ErrorCode = CheckNtMartaPresent();
|
|
|
|
if (ErrorCode == ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
SECURITY_DESCRIPTOR SecurityDescriptor;
|
2007-10-19 23:21:45 +00:00
|
|
|
|
2005-07-26 22:21:02 +00:00
|
|
|
ErrorCode = pSetSecurityInfoCheck(&SecurityDescriptor,
|
|
|
|
SecurityInfo,
|
|
|
|
psidOwner,
|
|
|
|
psidGroup,
|
|
|
|
pDacl,
|
|
|
|
pSacl);
|
2007-10-19 23:21:45 +00:00
|
|
|
|
2005-07-26 22:21:02 +00:00
|
|
|
if (ErrorCode == ERROR_SUCCESS)
|
2005-07-26 21:20:55 +00:00
|
|
|
{
|
2005-07-26 22:21:02 +00:00
|
|
|
/* call the MARTA provider */
|
|
|
|
ErrorCode = AccRewriteSetHandleRights(handle,
|
|
|
|
ObjectType,
|
|
|
|
SecurityInfo,
|
|
|
|
&SecurityDescriptor);
|
2005-07-26 21:20:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
ErrorCode = ERROR_INVALID_HANDLE;
|
|
|
|
|
|
|
|
return ErrorCode;
|
2004-12-13 19:06:28 +00:00
|
|
|
}
|
|
|
|
|
2005-06-27 22:42:28 +00:00
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
2008-09-21 13:55:53 +00:00
|
|
|
BOOL
|
2008-11-30 11:42:05 +00:00
|
|
|
WINAPI
|
2005-06-27 22:42:28 +00:00
|
|
|
CreatePrivateObjectSecurity(PSECURITY_DESCRIPTOR ParentDescriptor,
|
|
|
|
PSECURITY_DESCRIPTOR CreatorDescriptor,
|
|
|
|
PSECURITY_DESCRIPTOR *NewDescriptor,
|
|
|
|
BOOL IsDirectoryObject,
|
|
|
|
HANDLE Token,
|
|
|
|
PGENERIC_MAPPING GenericMapping)
|
|
|
|
{
|
|
|
|
NTSTATUS Status;
|
|
|
|
|
|
|
|
Status = RtlNewSecurityObject(ParentDescriptor,
|
|
|
|
CreatorDescriptor,
|
|
|
|
NewDescriptor,
|
|
|
|
IsDirectoryObject,
|
|
|
|
Token,
|
|
|
|
GenericMapping);
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
SetLastError(RtlNtStatusToDosError(Status));
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-07-27 01:31:34 +00:00
|
|
|
/*
|
|
|
|
* @unimplemented
|
|
|
|
*/
|
2008-09-21 13:55:53 +00:00
|
|
|
BOOL
|
2008-11-30 11:42:05 +00:00
|
|
|
WINAPI
|
2005-07-27 01:31:34 +00:00
|
|
|
CreatePrivateObjectSecurityEx(PSECURITY_DESCRIPTOR ParentDescriptor,
|
|
|
|
PSECURITY_DESCRIPTOR CreatorDescriptor,
|
|
|
|
PSECURITY_DESCRIPTOR* NewDescriptor,
|
|
|
|
GUID* ObjectType,
|
|
|
|
BOOL IsContainerObject,
|
|
|
|
ULONG AutoInheritFlags,
|
|
|
|
HANDLE Token,
|
|
|
|
PGENERIC_MAPPING GenericMapping)
|
|
|
|
{
|
2008-02-08 17:04:39 +00:00
|
|
|
FIXME("%s() not implemented!\n", __FUNCTION__);
|
2005-07-27 01:31:34 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @unimplemented
|
|
|
|
*/
|
2008-09-21 13:55:53 +00:00
|
|
|
BOOL
|
2008-11-30 11:42:05 +00:00
|
|
|
WINAPI
|
2005-07-27 01:31:34 +00:00
|
|
|
CreatePrivateObjectSecurityWithMultipleInheritance(PSECURITY_DESCRIPTOR ParentDescriptor,
|
|
|
|
PSECURITY_DESCRIPTOR CreatorDescriptor,
|
|
|
|
PSECURITY_DESCRIPTOR* NewDescriptor,
|
|
|
|
GUID** ObjectTypes,
|
|
|
|
ULONG GuidCount,
|
|
|
|
BOOL IsContainerObject,
|
|
|
|
ULONG AutoInheritFlags,
|
|
|
|
HANDLE Token,
|
|
|
|
PGENERIC_MAPPING GenericMapping)
|
|
|
|
{
|
2015-11-28 21:33:49 +00:00
|
|
|
FIXME("%s() semi-stub\n", __FUNCTION__);
|
|
|
|
return CreatePrivateObjectSecurity(ParentDescriptor, CreatorDescriptor, NewDescriptor, IsContainerObject, Token, GenericMapping);
|
2005-07-27 01:31:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-06-27 22:42:28 +00:00
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
2008-09-21 13:55:53 +00:00
|
|
|
BOOL
|
2008-11-30 11:42:05 +00:00
|
|
|
WINAPI
|
2005-06-27 22:42:28 +00:00
|
|
|
DestroyPrivateObjectSecurity(PSECURITY_DESCRIPTOR *ObjectDescriptor)
|
|
|
|
{
|
|
|
|
NTSTATUS Status;
|
|
|
|
|
|
|
|
Status = RtlDeleteSecurityObject(ObjectDescriptor);
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
SetLastError(RtlNtStatusToDosError(Status));
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
2008-09-21 13:55:53 +00:00
|
|
|
BOOL
|
2008-11-30 11:42:05 +00:00
|
|
|
WINAPI
|
2009-01-02 17:14:42 +00:00
|
|
|
GetPrivateObjectSecurity(IN PSECURITY_DESCRIPTOR ObjectDescriptor,
|
|
|
|
IN SECURITY_INFORMATION SecurityInformation,
|
|
|
|
OUT PSECURITY_DESCRIPTOR ResultantDescriptor OPTIONAL,
|
|
|
|
IN DWORD DescriptorLength,
|
|
|
|
OUT PDWORD ReturnLength)
|
2005-06-27 22:42:28 +00:00
|
|
|
{
|
|
|
|
NTSTATUS Status;
|
|
|
|
|
2009-01-02 17:14:42 +00:00
|
|
|
/* Call RTL */
|
2005-06-27 22:42:28 +00:00
|
|
|
Status = RtlQuerySecurityObject(ObjectDescriptor,
|
|
|
|
SecurityInformation,
|
|
|
|
ResultantDescriptor,
|
|
|
|
DescriptorLength,
|
|
|
|
ReturnLength);
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
2009-01-02 17:14:42 +00:00
|
|
|
/* Fail */
|
2005-06-27 22:42:28 +00:00
|
|
|
SetLastError(RtlNtStatusToDosError(Status));
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2009-01-02 17:14:42 +00:00
|
|
|
/* Success */
|
2005-06-27 22:42:28 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
2008-09-21 13:55:53 +00:00
|
|
|
BOOL
|
2008-11-30 11:42:05 +00:00
|
|
|
WINAPI
|
2005-06-27 22:42:28 +00:00
|
|
|
SetPrivateObjectSecurity(SECURITY_INFORMATION SecurityInformation,
|
|
|
|
PSECURITY_DESCRIPTOR ModificationDescriptor,
|
|
|
|
PSECURITY_DESCRIPTOR *ObjectsSecurityDescriptor,
|
|
|
|
PGENERIC_MAPPING GenericMapping,
|
|
|
|
HANDLE Token)
|
|
|
|
{
|
|
|
|
NTSTATUS Status;
|
|
|
|
|
|
|
|
Status = RtlSetSecurityObject(SecurityInformation,
|
|
|
|
ModificationDescriptor,
|
|
|
|
ObjectsSecurityDescriptor,
|
|
|
|
GenericMapping,
|
|
|
|
Token);
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
SetLastError(RtlNtStatusToDosError(Status));
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2005-07-27 23:11:38 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
2008-09-21 13:55:53 +00:00
|
|
|
DWORD
|
2008-11-30 11:42:05 +00:00
|
|
|
WINAPI
|
2005-07-27 23:11:38 +00:00
|
|
|
TreeResetNamedSecurityInfoW(LPWSTR pObjectName,
|
|
|
|
SE_OBJECT_TYPE ObjectType,
|
|
|
|
SECURITY_INFORMATION SecurityInfo,
|
|
|
|
PSID pOwner,
|
|
|
|
PSID pGroup,
|
|
|
|
PACL pDacl,
|
|
|
|
PACL pSacl,
|
|
|
|
BOOL KeepExplicit,
|
|
|
|
FN_PROGRESSW fnProgress,
|
|
|
|
PROG_INVOKE_SETTING ProgressInvokeSetting,
|
|
|
|
PVOID Args)
|
|
|
|
{
|
|
|
|
DWORD ErrorCode;
|
|
|
|
|
|
|
|
if (pObjectName != NULL)
|
|
|
|
{
|
|
|
|
ErrorCode = CheckNtMartaPresent();
|
|
|
|
if (ErrorCode == ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
switch (ObjectType)
|
|
|
|
{
|
|
|
|
case SE_FILE_OBJECT:
|
|
|
|
case SE_REGISTRY_KEY:
|
|
|
|
{
|
|
|
|
/* check the SecurityInfo flags for sanity (both, the protected
|
2005-07-31 20:35:08 +00:00
|
|
|
and unprotected dacl/sacl flag must not be passed together) */
|
2005-07-27 23:11:38 +00:00
|
|
|
if (((SecurityInfo & DACL_SECURITY_INFORMATION) &&
|
|
|
|
(SecurityInfo & (PROTECTED_DACL_SECURITY_INFORMATION | UNPROTECTED_DACL_SECURITY_INFORMATION)) ==
|
|
|
|
(PROTECTED_DACL_SECURITY_INFORMATION | UNPROTECTED_DACL_SECURITY_INFORMATION))
|
|
|
|
|
|
|
|
||
|
|
|
|
|
|
|
|
((SecurityInfo & SACL_SECURITY_INFORMATION) &&
|
|
|
|
(SecurityInfo & (PROTECTED_SACL_SECURITY_INFORMATION | UNPROTECTED_SACL_SECURITY_INFORMATION)) ==
|
|
|
|
(PROTECTED_SACL_SECURITY_INFORMATION | UNPROTECTED_SACL_SECURITY_INFORMATION)))
|
|
|
|
{
|
|
|
|
ErrorCode = ERROR_INVALID_PARAMETER;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* call the MARTA provider */
|
|
|
|
ErrorCode = AccTreeResetNamedSecurityInfo(pObjectName,
|
|
|
|
ObjectType,
|
|
|
|
SecurityInfo,
|
|
|
|
pOwner,
|
|
|
|
pGroup,
|
|
|
|
pDacl,
|
|
|
|
pSacl,
|
|
|
|
KeepExplicit,
|
|
|
|
fnProgress,
|
|
|
|
ProgressInvokeSetting,
|
|
|
|
Args);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
/* object type not supported */
|
|
|
|
ErrorCode = ERROR_INVALID_PARAMETER;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
ErrorCode = ERROR_INVALID_PARAMETER;
|
|
|
|
|
|
|
|
return ErrorCode;
|
|
|
|
}
|
|
|
|
|
2006-07-03 21:43:04 +00:00
|
|
|
#ifdef HAS_FN_PROGRESSW
|
|
|
|
|
2016-11-12 21:53:33 +00:00
|
|
|
typedef struct _INTERNAL_FNPROGRESSW_DATA
|
2006-07-03 21:43:04 +00:00
|
|
|
{
|
|
|
|
FN_PROGRESSA fnProgress;
|
|
|
|
PVOID Args;
|
2016-11-12 21:53:33 +00:00
|
|
|
} INTERNAL_FNPROGRESSW_DATA, *PINTERNAL_FNPROGRESSW_DATA;
|
2006-07-03 21:43:04 +00:00
|
|
|
|
2008-11-30 11:42:05 +00:00
|
|
|
static VOID WINAPI
|
2006-07-03 21:43:04 +00:00
|
|
|
InternalfnProgressW(LPWSTR pObjectName,
|
|
|
|
DWORD Status,
|
|
|
|
PPROG_INVOKE_SETTING pInvokeSetting,
|
|
|
|
PVOID Args,
|
|
|
|
BOOL SecuritySet)
|
|
|
|
{
|
2016-11-12 21:53:33 +00:00
|
|
|
PINTERNAL_FNPROGRESSW_DATA pifnProgressData = (PINTERNAL_FNPROGRESSW_DATA)Args;
|
2006-07-03 21:43:04 +00:00
|
|
|
INT ObjectNameSize;
|
|
|
|
LPSTR pObjectNameA;
|
|
|
|
|
|
|
|
ObjectNameSize = WideCharToMultiByte(CP_ACP,
|
|
|
|
0,
|
|
|
|
pObjectName,
|
|
|
|
-1,
|
|
|
|
NULL,
|
|
|
|
0,
|
|
|
|
NULL,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
if (ObjectNameSize > 0)
|
|
|
|
{
|
|
|
|
pObjectNameA = RtlAllocateHeap(RtlGetProcessHeap(),
|
|
|
|
0,
|
|
|
|
ObjectNameSize);
|
|
|
|
if (pObjectNameA != NULL)
|
|
|
|
{
|
|
|
|
pObjectNameA[0] = '\0';
|
|
|
|
WideCharToMultiByte(CP_ACP,
|
|
|
|
0,
|
|
|
|
pObjectName,
|
|
|
|
-1,
|
|
|
|
pObjectNameA,
|
|
|
|
ObjectNameSize,
|
|
|
|
NULL,
|
|
|
|
NULL);
|
|
|
|
|
2006-10-11 22:14:05 +00:00
|
|
|
pifnProgressData->fnProgress((LPWSTR)pObjectNameA, /* FIXME: wrong cast!! */
|
2006-07-03 21:43:04 +00:00
|
|
|
Status,
|
|
|
|
pInvokeSetting,
|
|
|
|
pifnProgressData->Args,
|
|
|
|
SecuritySet);
|
|
|
|
|
|
|
|
RtlFreeHeap(RtlGetProcessHeap(),
|
|
|
|
0,
|
|
|
|
pObjectNameA);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2005-07-27 23:11:38 +00:00
|
|
|
|
|
|
|
/*
|
2006-07-03 21:43:04 +00:00
|
|
|
* @implemented
|
2005-07-27 23:11:38 +00:00
|
|
|
*/
|
2008-09-21 13:55:53 +00:00
|
|
|
DWORD
|
2008-11-30 11:42:05 +00:00
|
|
|
WINAPI
|
2005-07-27 23:11:38 +00:00
|
|
|
TreeResetNamedSecurityInfoA(LPSTR pObjectName,
|
|
|
|
SE_OBJECT_TYPE ObjectType,
|
|
|
|
SECURITY_INFORMATION SecurityInfo,
|
|
|
|
PSID pOwner,
|
|
|
|
PSID pGroup,
|
|
|
|
PACL pDacl,
|
|
|
|
PACL pSacl,
|
|
|
|
BOOL KeepExplicit,
|
|
|
|
FN_PROGRESSA fnProgress,
|
|
|
|
PROG_INVOKE_SETTING ProgressInvokeSetting,
|
|
|
|
PVOID Args)
|
|
|
|
{
|
2006-07-03 21:43:04 +00:00
|
|
|
#ifndef HAS_FN_PROGRESSW
|
2005-07-27 23:11:38 +00:00
|
|
|
/* That's all this function does, at least up to w2k3... Even MS was too
|
|
|
|
lazy to implement it... */
|
|
|
|
return ERROR_CALL_NOT_IMPLEMENTED;
|
2006-07-03 21:43:04 +00:00
|
|
|
#else
|
2016-11-12 21:53:33 +00:00
|
|
|
INTERNAL_FNPROGRESSW_DATA ifnProgressData;
|
2006-07-03 21:43:04 +00:00
|
|
|
UNICODE_STRING ObjectName;
|
|
|
|
DWORD Ret;
|
|
|
|
|
2012-07-12 19:48:30 +00:00
|
|
|
if (!RtlCreateUnicodeStringFromAsciiz(&ObjectName, pObjectName))
|
2006-07-03 21:43:04 +00:00
|
|
|
{
|
2012-07-12 19:48:30 +00:00
|
|
|
return ERROR_NOT_ENOUGH_MEMORY;
|
2006-07-03 21:43:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ifnProgressData.fnProgress = fnProgress;
|
|
|
|
ifnProgressData.Args = Args;
|
|
|
|
|
|
|
|
Ret = TreeResetNamedSecurityInfoW(ObjectName.Buffer,
|
|
|
|
ObjectType,
|
|
|
|
SecurityInfo,
|
|
|
|
pOwner,
|
|
|
|
pGroup,
|
|
|
|
pDacl,
|
|
|
|
pSacl,
|
|
|
|
KeepExplicit,
|
|
|
|
(fnProgress != NULL ? InternalfnProgressW : NULL),
|
|
|
|
ProgressInvokeSetting,
|
|
|
|
&ifnProgressData);
|
|
|
|
|
|
|
|
RtlFreeUnicodeString(&ObjectName);
|
|
|
|
|
|
|
|
return Ret;
|
|
|
|
#endif
|
2005-07-27 23:11:38 +00:00
|
|
|
}
|
|
|
|
|
2004-03-08 18:09:05 +00:00
|
|
|
/* EOF */
|