[BASESRV]

Implement BaseSrvIsVdmAllowed.


svn path=/branches/ntvdm/; revision=62349
This commit is contained in:
Aleksandar Andrejevic 2014-02-27 22:44:56 +00:00
parent 931a83808f
commit bde24e0bb4
3 changed files with 104 additions and 0 deletions

View file

@ -22,6 +22,7 @@
#include <ndk/psfuncs.h> #include <ndk/psfuncs.h>
#include <ndk/exfuncs.h> #include <ndk/exfuncs.h>
#include <ndk/umfuncs.h> #include <ndk/umfuncs.h>
#include <ndk/cmfuncs.h>
/* PSEH for SEH Support */ /* PSEH for SEH Support */
#include <pseh/pseh2.h> #include <pseh/pseh2.h>

View file

@ -69,6 +69,103 @@ ULONG NTAPI GetNextDosSesId(VOID)
return SessionId; return SessionId;
} }
BOOLEAN NTAPI BaseSrvIsVdmAllowed(VOID)
{
NTSTATUS Status;
BOOLEAN VdmAllowed = TRUE;
HANDLE RootKey, KeyHandle;
UNICODE_STRING KeyName, ValueName, MachineKeyName;
OBJECT_ATTRIBUTES Attributes;
UCHAR ValueBuffer[sizeof(KEY_VALUE_PARTIAL_INFORMATION) + sizeof(ULONG)];
PKEY_VALUE_PARTIAL_INFORMATION ValueInfo = (PKEY_VALUE_PARTIAL_INFORMATION)ValueBuffer;
ULONG ActualSize;
/* Initialize the unicode strings */
RtlInitUnicodeString(&MachineKeyName, L"\\Registry\\Machine");
RtlInitUnicodeString(&KeyName, VDM_POLICY_KEY_NAME);
RtlInitUnicodeString(&ValueName, VDM_DISALLOWED_VALUE_NAME);
InitializeObjectAttributes(&Attributes,
&MachineKeyName,
OBJ_CASE_INSENSITIVE,
NULL,
NULL);
/* Open the local machine key */
Status = NtOpenKey(&RootKey, KEY_READ, &Attributes);
if (!NT_SUCCESS(Status)) return FALSE;
InitializeObjectAttributes(&Attributes,
&KeyName,
OBJ_CASE_INSENSITIVE,
RootKey,
NULL);
/* Open the policy key in the local machine hive, if it exists */
if (NT_SUCCESS(NtOpenKey(&KeyHandle, KEY_READ, &Attributes)))
{
/* Read the value, if it's set */
if (NT_SUCCESS(NtQueryValueKey(KeyHandle,
&ValueName,
KeyValuePartialInformation,
ValueInfo,
sizeof(ValueBuffer),
&ActualSize)))
{
if (*((PULONG)ValueInfo->Data))
{
/* The VDM has been disabled in the registry */
VdmAllowed = FALSE;
}
}
NtClose(KeyHandle);
}
/* Close the local machine key */
NtClose(RootKey);
/* If it's disabled system-wide, there's no need to check the user key */
if (!VdmAllowed) return FALSE;
/* Open the current user key of the client */
if (!CsrImpersonateClient(NULL)) return VdmAllowed;
Status = RtlOpenCurrentUser(KEY_READ, &RootKey);
CsrRevertToSelf();
/* If that fails, return the system-wide setting */
if (!NT_SUCCESS(Status)) return VdmAllowed;
InitializeObjectAttributes(&Attributes,
&KeyName,
OBJ_CASE_INSENSITIVE,
RootKey,
NULL);
/* Open the policy key in the current user hive, if it exists */
if (NT_SUCCESS(NtOpenKey(&KeyHandle, KEY_READ, &Attributes)))
{
/* Read the value, if it's set */
if (NT_SUCCESS(NtQueryValueKey(KeyHandle,
&ValueName,
KeyValuePartialInformation,
ValueInfo,
sizeof(ValueBuffer),
&ActualSize)))
{
if (*((PULONG)ValueInfo->Data))
{
/* The VDM has been disabled in the registry */
VdmAllowed = FALSE;
}
}
NtClose(KeyHandle);
}
return VdmAllowed;
}
VOID NTAPI BaseInitializeVDM(VOID) VOID NTAPI BaseInitializeVDM(VOID)
{ {
/* Initialize the list head */ /* Initialize the list head */
@ -88,6 +185,9 @@ CSR_API(BaseSrvCheckVDM)
PRTL_CRITICAL_SECTION CriticalSection = NULL; PRTL_CRITICAL_SECTION CriticalSection = NULL;
PVDM_CONSOLE_RECORD ConsoleRecord = NULL; PVDM_CONSOLE_RECORD ConsoleRecord = NULL;
/* Don't do anything if the VDM has been disabled in the registry */
if (!BaseSrvIsVdmAllowed()) return STATUS_ACCESS_DENIED;
/* Validate the message buffers */ /* Validate the message buffers */
if (!CsrValidateMessageBuffer(ApiMessage, if (!CsrValidateMessageBuffer(ApiMessage,
(PVOID*)&CheckVdmRequest->CmdLine, (PVOID*)&CheckVdmRequest->CmdLine,

View file

@ -13,6 +13,9 @@
/* DEFINITIONS ****************************************************************/ /* DEFINITIONS ****************************************************************/
#define VDM_POLICY_KEY_NAME L"Software\\Policies\\Microsoft\\Windows\\AppCompat"
#define VDM_DISALLOWED_VALUE_NAME L"VDMDisallowed"
typedef struct _VDM_CONSOLE_RECORD typedef struct _VDM_CONSOLE_RECORD
{ {
LIST_ENTRY Entry; LIST_ENTRY Entry;