mirror of
https://github.com/reactos/reactos.git
synced 2024-12-27 01:24:38 +00:00
Fixed severe bug in CreateEventW()
Implemented use of "\BaseNamedObjects" directory svn path=/trunk/; revision=1546
This commit is contained in:
parent
86c7503953
commit
300201892a
5 changed files with 217 additions and 168 deletions
|
@ -32,7 +32,7 @@
|
|||
|
||||
extern WINBOOL bIsFileApiAnsi;
|
||||
extern HANDLE hProcessHeap;
|
||||
|
||||
extern HANDLE hBaseDir;
|
||||
|
||||
/* FUNCTION PROTOTYPES ********************************************************/
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $Id: dllmain.c,v 1.16 2001/01/20 12:19:57 ekohl Exp $
|
||||
/* $Id: dllmain.c,v 1.17 2001/01/20 18:37:08 ekohl Exp $
|
||||
*
|
||||
* COPYRIGHT: See COPYING in the top level directory
|
||||
* PROJECT: ReactOS system libraries
|
||||
|
@ -24,6 +24,7 @@ extern UNICODE_STRING SystemDirectory;
|
|||
extern UNICODE_STRING WindowsDirectory;
|
||||
|
||||
HANDLE hProcessHeap = NULL;
|
||||
HANDLE hBaseDir = NULL;
|
||||
|
||||
static WINBOOL DllInitialized = FALSE;
|
||||
|
||||
|
@ -32,6 +33,41 @@ WINBOOL STDCALL DllMain (HANDLE hInst,
|
|||
LPVOID lpReserved);
|
||||
|
||||
|
||||
static NTSTATUS OpenBaseDirectory(PHANDLE DirHandle)
|
||||
{
|
||||
OBJECT_ATTRIBUTES ObjectAttributes;
|
||||
UNICODE_STRING Name;
|
||||
NTSTATUS Status;
|
||||
|
||||
RtlInitUnicodeString(&Name,
|
||||
L"\\BaseNamedObjects");
|
||||
|
||||
InitializeObjectAttributes(&ObjectAttributes,
|
||||
&Name,
|
||||
OBJ_PERMANENT,
|
||||
NULL,
|
||||
NULL);
|
||||
|
||||
Status = NtOpenDirectoryObject(DirHandle,
|
||||
DIRECTORY_ALL_ACCESS,
|
||||
&ObjectAttributes);
|
||||
if (!NT_SUCCESS(Status))
|
||||
{
|
||||
Status = NtCreateDirectoryObject(DirHandle,
|
||||
DIRECTORY_ALL_ACCESS,
|
||||
&ObjectAttributes);
|
||||
if (!NT_SUCCESS(Status))
|
||||
{
|
||||
DbgPrint("NtCreateDirectoryObject() failed\n");
|
||||
}
|
||||
|
||||
return Status;
|
||||
}
|
||||
|
||||
return STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
BOOL WINAPI DllMainCRTStartup(HANDLE hDll, DWORD dwReason, LPVOID lpReserved)
|
||||
{
|
||||
return(DllMain(hDll,dwReason,lpReserved));
|
||||
|
@ -84,6 +120,13 @@ WINBOOL STDCALL DllMain(HANDLE hInst,
|
|||
wcscpy (SystemDirectory.Buffer, WindowsDirectory.Buffer);
|
||||
wcscat (SystemDirectory.Buffer, L"\\System32");
|
||||
|
||||
/* Open object base directory */
|
||||
Status = OpenBaseDirectory(&hBaseDir);
|
||||
if (!NT_SUCCESS(Status))
|
||||
{
|
||||
DbgPrint("Failed to open object base directory: expect trouble\n");
|
||||
}
|
||||
|
||||
/* Insert more dll attach stuff here! */
|
||||
|
||||
DllInitialized = TRUE;
|
||||
|
@ -95,11 +138,13 @@ WINBOOL STDCALL DllMain(HANDLE hInst,
|
|||
DPRINT("DLL_PROCESS_DETACH\n");
|
||||
if (DllInitialized == TRUE)
|
||||
{
|
||||
RtlFreeUnicodeString (&SystemDirectory);
|
||||
RtlFreeUnicodeString (&WindowsDirectory);
|
||||
|
||||
/* Insert more dll detach stuff here! */
|
||||
|
||||
/* Close object base directory */
|
||||
NtClose(hBaseDir);
|
||||
|
||||
RtlFreeUnicodeString (&SystemDirectory);
|
||||
RtlFreeUnicodeString (&WindowsDirectory);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $Id: event.c,v 1.9 2000/10/08 12:56:45 ekohl Exp $
|
||||
/* $Id: event.c,v 1.10 2001/01/20 18:37:58 ekohl Exp $
|
||||
*
|
||||
* COPYRIGHT: See COPYING in the top level directory
|
||||
* PROJECT: ReactOS system libraries
|
||||
|
@ -9,6 +9,8 @@
|
|||
* Created 01/11/98
|
||||
*/
|
||||
|
||||
/* INCLUDES *****************************************************************/
|
||||
|
||||
#include <ddk/ntddk.h>
|
||||
#include <windows.h>
|
||||
|
||||
|
@ -16,209 +18,211 @@
|
|||
#include <kernel32/kernel32.h>
|
||||
#include <kernel32/error.h>
|
||||
|
||||
WINBOOL STDCALL SetEvent(HANDLE hEvent)
|
||||
{
|
||||
NTSTATUS errCode;
|
||||
ULONG Count;
|
||||
|
||||
errCode = NtSetEvent(hEvent,&Count);
|
||||
if (!NT_SUCCESS(errCode))
|
||||
{
|
||||
SetLastErrorByStatus (errCode);
|
||||
return FALSE;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
/* FUNCTIONS ****************************************************************/
|
||||
|
||||
WINBOOL STDCALL ResetEvent(HANDLE hEvent)
|
||||
HANDLE STDCALL
|
||||
CreateEventA(LPSECURITY_ATTRIBUTES lpEventAttributes,
|
||||
WINBOOL bManualReset,
|
||||
WINBOOL bInitialState,
|
||||
LPCSTR lpName)
|
||||
{
|
||||
NTSTATUS errCode;
|
||||
ULONG Count;
|
||||
|
||||
errCode = NtResetEvent(hEvent, &Count);
|
||||
if (!NT_SUCCESS(errCode))
|
||||
UNICODE_STRING EventNameU;
|
||||
ANSI_STRING EventName;
|
||||
HANDLE EventHandle;
|
||||
|
||||
RtlInitUnicodeString (&EventNameU, NULL);
|
||||
|
||||
if (lpName)
|
||||
{
|
||||
SetLastErrorByStatus (errCode);
|
||||
return FALSE;
|
||||
RtlInitAnsiString(&EventName,
|
||||
(LPSTR)lpName);
|
||||
RtlAnsiStringToUnicodeString(&EventNameU,
|
||||
&EventName,
|
||||
TRUE);
|
||||
}
|
||||
return TRUE;
|
||||
|
||||
EventHandle = CreateEventW(lpEventAttributes,
|
||||
bManualReset,
|
||||
bInitialState,
|
||||
EventNameU.Buffer);
|
||||
|
||||
if (lpName)
|
||||
{
|
||||
RtlFreeUnicodeString(&EventNameU);
|
||||
}
|
||||
|
||||
return EventHandle;
|
||||
}
|
||||
|
||||
|
||||
|
||||
HANDLE
|
||||
STDCALL
|
||||
CreateEventW (
|
||||
LPSECURITY_ATTRIBUTES lpEventAttributes,
|
||||
WINBOOL bManualReset,
|
||||
WINBOOL bInitialState,
|
||||
LPCWSTR lpName
|
||||
)
|
||||
HANDLE STDCALL
|
||||
CreateEventW(LPSECURITY_ATTRIBUTES lpEventAttributes,
|
||||
WINBOOL bManualReset,
|
||||
WINBOOL bInitialState,
|
||||
LPCWSTR lpName)
|
||||
{
|
||||
NTSTATUS errCode;
|
||||
NTSTATUS Status;
|
||||
HANDLE hEvent;
|
||||
UNICODE_STRING EventNameString;
|
||||
POBJECT_ATTRIBUTES PtrObjectAttributes;
|
||||
OBJECT_ATTRIBUTES ObjectAttributes;
|
||||
|
||||
|
||||
ObjectAttributes.Length = sizeof(OBJECT_ATTRIBUTES);
|
||||
ObjectAttributes.RootDirectory = hBaseDir;
|
||||
ObjectAttributes.ObjectName = NULL;
|
||||
ObjectAttributes.Attributes = 0;
|
||||
ObjectAttributes.SecurityDescriptor = NULL;
|
||||
ObjectAttributes.SecurityQualityOfService = NULL;
|
||||
|
||||
if (lpName != NULL)
|
||||
{
|
||||
PtrObjectAttributes = &ObjectAttributes;
|
||||
ObjectAttributes.Attributes = 0;
|
||||
if (lpEventAttributes != NULL)
|
||||
{
|
||||
ObjectAttributes.SecurityDescriptor =
|
||||
lpEventAttributes->lpSecurityDescriptor;
|
||||
if ( lpEventAttributes->bInheritHandle == TRUE )
|
||||
ObjectAttributes.Attributes |= OBJ_INHERIT;
|
||||
}
|
||||
|
||||
RtlInitUnicodeString(&EventNameString, (LPWSTR)lpName);
|
||||
ObjectAttributes.ObjectName = &EventNameString;
|
||||
}
|
||||
else
|
||||
{
|
||||
PtrObjectAttributes = NULL;
|
||||
}
|
||||
|
||||
DPRINT( "Calling NtCreateEvent\n" );
|
||||
errCode = NtCreateEvent(&hEvent,
|
||||
STANDARD_RIGHTS_ALL|EVENT_READ_ACCESS|EVENT_WRITE_ACCESS,
|
||||
PtrObjectAttributes,
|
||||
bManualReset,
|
||||
bInitialState);
|
||||
|
||||
Status = NtCreateEvent(&hEvent,
|
||||
STANDARD_RIGHTS_ALL|EVENT_READ_ACCESS|EVENT_WRITE_ACCESS,
|
||||
&ObjectAttributes,
|
||||
bManualReset,
|
||||
bInitialState);
|
||||
DPRINT( "Called\n" );
|
||||
if (!NT_SUCCESS(errCode))
|
||||
if (!NT_SUCCESS(Status))
|
||||
{
|
||||
SetLastErrorByStatus (errCode);
|
||||
return INVALID_HANDLE_VALUE;
|
||||
SetLastErrorByStatus(Status);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return hEvent;
|
||||
}
|
||||
|
||||
|
||||
HANDLE
|
||||
STDCALL
|
||||
OpenEventW (
|
||||
DWORD dwDesiredAccess,
|
||||
WINBOOL bInheritHandle,
|
||||
LPCWSTR lpName
|
||||
)
|
||||
HANDLE STDCALL
|
||||
OpenEventA(DWORD dwDesiredAccess,
|
||||
WINBOOL bInheritHandle,
|
||||
LPCSTR lpName)
|
||||
{
|
||||
OBJECT_ATTRIBUTES ObjectAttributes;
|
||||
UNICODE_STRING EventNameString;
|
||||
NTSTATUS errCode;
|
||||
HANDLE hEvent = NULL;
|
||||
UNICODE_STRING EventNameU;
|
||||
ANSI_STRING EventName;
|
||||
HANDLE EventHandle;
|
||||
|
||||
if(lpName == NULL) {
|
||||
SetLastError(ERROR_INVALID_PARAMETER);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ObjectAttributes.Attributes = 0;
|
||||
ObjectAttributes.SecurityDescriptor = NULL;
|
||||
RtlInitUnicodeString(&EventNameString, (LPWSTR)lpName);
|
||||
ObjectAttributes.ObjectName = &EventNameString;
|
||||
RtlInitUnicodeString(&EventNameU,
|
||||
NULL);
|
||||
|
||||
if (bInheritHandle == TRUE )
|
||||
ObjectAttributes.Attributes |= OBJ_INHERIT;
|
||||
|
||||
if (lpName)
|
||||
{
|
||||
RtlInitAnsiString(&EventName,
|
||||
(LPSTR)lpName);
|
||||
RtlAnsiStringToUnicodeString(&EventNameU,
|
||||
&EventName,
|
||||
TRUE);
|
||||
}
|
||||
|
||||
errCode = NtOpenEvent(hEvent,dwDesiredAccess,&ObjectAttributes);
|
||||
if ( !NT_SUCCESS(errCode) ) {
|
||||
SetLastErrorByStatus (errCode);
|
||||
return NULL;
|
||||
}
|
||||
EventHandle = OpenEventW(dwDesiredAccess,
|
||||
bInheritHandle,
|
||||
EventNameU.Buffer);
|
||||
|
||||
return hEvent;
|
||||
if (lpName)
|
||||
{
|
||||
RtlFreeUnicodeString(&EventNameU);
|
||||
}
|
||||
|
||||
return EventHandle;
|
||||
}
|
||||
|
||||
|
||||
HANDLE
|
||||
STDCALL
|
||||
CreateEventA (
|
||||
LPSECURITY_ATTRIBUTES lpEventAttributes,
|
||||
WINBOOL bManualReset,
|
||||
WINBOOL bInitialState,
|
||||
LPCSTR lpName
|
||||
)
|
||||
HANDLE STDCALL
|
||||
OpenEventW(DWORD dwDesiredAccess,
|
||||
WINBOOL bInheritHandle,
|
||||
LPCWSTR lpName)
|
||||
{
|
||||
UNICODE_STRING EventNameU;
|
||||
ANSI_STRING EventName;
|
||||
HANDLE EventHandle;
|
||||
OBJECT_ATTRIBUTES ObjectAttributes;
|
||||
UNICODE_STRING EventNameString;
|
||||
NTSTATUS Status;
|
||||
HANDLE hEvent = NULL;
|
||||
|
||||
RtlInitUnicodeString (&EventNameU, NULL);
|
||||
if (lpName == NULL)
|
||||
{
|
||||
SetLastError(ERROR_INVALID_PARAMETER);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (lpName)
|
||||
{
|
||||
RtlInitAnsiString (&EventName,
|
||||
(LPSTR)lpName);
|
||||
RtlAnsiStringToUnicodeString (&EventNameU,
|
||||
&EventName,
|
||||
TRUE);
|
||||
}
|
||||
RtlInitUnicodeString(&EventNameString, (LPWSTR)lpName);
|
||||
|
||||
EventHandle = CreateEventW (lpEventAttributes,
|
||||
bManualReset,
|
||||
bInitialState,
|
||||
EventNameU.Buffer);
|
||||
ObjectAttributes.Length = sizeof(OBJECT_ATTRIBUTES);
|
||||
ObjectAttributes.RootDirectory = hBaseDir;
|
||||
ObjectAttributes.ObjectName = &EventNameString;
|
||||
ObjectAttributes.Attributes = 0;
|
||||
ObjectAttributes.SecurityDescriptor = NULL;
|
||||
ObjectAttributes.SecurityQualityOfService = NULL;
|
||||
if (bInheritHandle == TRUE)
|
||||
{
|
||||
ObjectAttributes.Attributes |= OBJ_INHERIT;
|
||||
}
|
||||
|
||||
if (lpName)
|
||||
RtlFreeUnicodeString (&EventNameU);
|
||||
Status = NtOpenEvent(&hEvent,
|
||||
dwDesiredAccess,
|
||||
&ObjectAttributes);
|
||||
if (!NT_SUCCESS(Status))
|
||||
{
|
||||
SetLastErrorByStatus(Status);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return EventHandle;
|
||||
return hEvent;
|
||||
}
|
||||
|
||||
|
||||
HANDLE
|
||||
STDCALL
|
||||
OpenEventA (
|
||||
DWORD dwDesiredAccess,
|
||||
WINBOOL bInheritHandle,
|
||||
LPCSTR lpName
|
||||
)
|
||||
WINBOOL STDCALL
|
||||
PulseEvent(HANDLE hEvent)
|
||||
{
|
||||
UNICODE_STRING EventNameU;
|
||||
ANSI_STRING EventName;
|
||||
HANDLE EventHandle;
|
||||
ULONG Count;
|
||||
NTSTATUS Status;
|
||||
|
||||
RtlInitUnicodeString (&EventNameU, NULL);
|
||||
Status = NtPulseEvent(hEvent,
|
||||
&Count);
|
||||
if (!NT_SUCCESS(Status))
|
||||
{
|
||||
SetLastErrorByStatus (Status);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (lpName)
|
||||
{
|
||||
RtlInitAnsiString (&EventName,
|
||||
(LPSTR)lpName);
|
||||
RtlAnsiStringToUnicodeString (&EventNameU,
|
||||
&EventName,
|
||||
TRUE);
|
||||
}
|
||||
|
||||
EventHandle = OpenEventW (dwDesiredAccess,
|
||||
bInheritHandle,
|
||||
EventNameU.Buffer);
|
||||
|
||||
if (lpName)
|
||||
RtlFreeUnicodeString (&EventNameU);
|
||||
|
||||
return EventHandle;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
WINBOOL
|
||||
STDCALL
|
||||
PulseEvent (
|
||||
HANDLE hEvent
|
||||
)
|
||||
WINBOOL STDCALL
|
||||
ResetEvent(HANDLE hEvent)
|
||||
{
|
||||
ULONG Count;
|
||||
NTSTATUS errCode;
|
||||
errCode = NtPulseEvent(hEvent,&Count);
|
||||
if ( !NT_SUCCESS(errCode) ) {
|
||||
SetLastErrorByStatus (errCode);
|
||||
return FALSE;
|
||||
}
|
||||
return TRUE;
|
||||
NTSTATUS Status;
|
||||
ULONG Count;
|
||||
|
||||
Status = NtResetEvent(hEvent,
|
||||
&Count);
|
||||
if (!NT_SUCCESS(Status))
|
||||
{
|
||||
SetLastErrorByStatus(Status);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
WINBOOL STDCALL
|
||||
SetEvent(HANDLE hEvent)
|
||||
{
|
||||
NTSTATUS Status;
|
||||
ULONG Count;
|
||||
|
||||
Status = NtSetEvent(hEvent,
|
||||
&Count);
|
||||
if (!NT_SUCCESS(Status))
|
||||
{
|
||||
SetLastErrorByStatus(Status);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/* EOF */
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $Id: mutex.c,v 1.1 2001/01/20 12:20:43 ekohl Exp $
|
||||
/* $Id: mutex.c,v 1.2 2001/01/20 18:37:58 ekohl Exp $
|
||||
*
|
||||
* COPYRIGHT: See COPYING in the top level directory
|
||||
* PROJECT: ReactOS system libraries
|
||||
|
@ -59,7 +59,7 @@ CreateMutexW(LPSECURITY_ATTRIBUTES lpMutexAttributes,
|
|||
(LPWSTR)lpName);
|
||||
|
||||
ObjectAttributes.Length = sizeof(OBJECT_ATTRIBUTES);
|
||||
ObjectAttributes.RootDirectory = NULL;
|
||||
ObjectAttributes.RootDirectory = hBaseDir;
|
||||
ObjectAttributes.ObjectName = &NameString;
|
||||
ObjectAttributes.Attributes = 0;
|
||||
ObjectAttributes.SecurityDescriptor = NULL;
|
||||
|
@ -112,7 +112,7 @@ OpenMutexA(DWORD dwDesiredAccess,
|
|||
TRUE);
|
||||
|
||||
ObjectAttributes.Length = sizeof(OBJECT_ATTRIBUTES);
|
||||
ObjectAttributes.RootDirectory = NULL;
|
||||
ObjectAttributes.RootDirectory = hBaseDir;
|
||||
ObjectAttributes.ObjectName = &NameU;
|
||||
ObjectAttributes.Attributes = 0;
|
||||
ObjectAttributes.SecurityDescriptor = NULL;
|
||||
|
@ -158,7 +158,7 @@ OpenMutexW(DWORD dwDesiredAccess,
|
|||
(LPWSTR)lpName);
|
||||
|
||||
ObjectAttributes.Length = sizeof(OBJECT_ATTRIBUTES);
|
||||
ObjectAttributes.RootDirectory = NULL;
|
||||
ObjectAttributes.RootDirectory = hBaseDir;
|
||||
ObjectAttributes.ObjectName = &Name;
|
||||
ObjectAttributes.Attributes = 0;
|
||||
ObjectAttributes.SecurityDescriptor = NULL;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $Id: sem.c,v 1.1 2001/01/20 12:20:43 ekohl Exp $
|
||||
/* $Id: sem.c,v 1.2 2001/01/20 18:37:58 ekohl Exp $
|
||||
*
|
||||
* COPYRIGHT: See COPYING in the top level directory
|
||||
* PROJECT: ReactOS system libraries
|
||||
|
@ -71,7 +71,7 @@ CreateSemaphoreW(LPSECURITY_ATTRIBUTES lpSemaphoreAttributes,
|
|||
NameString.MaximumLength = NameString.Length;
|
||||
|
||||
ObjectAttributes.Length = sizeof(OBJECT_ATTRIBUTES);
|
||||
ObjectAttributes.RootDirectory = NULL;
|
||||
ObjectAttributes.RootDirectory = hBaseDir;
|
||||
ObjectAttributes.ObjectName = &NameString;
|
||||
ObjectAttributes.Attributes = 0;
|
||||
ObjectAttributes.SecurityDescriptor = NULL;
|
||||
|
@ -123,7 +123,7 @@ OpenSemaphoreA(DWORD dwDesiredAccess,
|
|||
TRUE);
|
||||
|
||||
ObjectAttributes.Length = sizeof(OBJECT_ATTRIBUTES);
|
||||
ObjectAttributes.RootDirectory = NULL;
|
||||
ObjectAttributes.RootDirectory = hBaseDir;
|
||||
ObjectAttributes.ObjectName = &NameU;
|
||||
ObjectAttributes.Attributes = 0;
|
||||
ObjectAttributes.SecurityDescriptor = NULL;
|
||||
|
@ -169,7 +169,7 @@ OpenSemaphoreW(DWORD dwDesiredAccess,
|
|||
(LPWSTR)lpName);
|
||||
|
||||
ObjectAttributes.Length = sizeof(OBJECT_ATTRIBUTES);
|
||||
ObjectAttributes.RootDirectory = NULL;
|
||||
ObjectAttributes.RootDirectory = hBaseDir;
|
||||
ObjectAttributes.ObjectName = &Name;
|
||||
ObjectAttributes.Attributes = 0;
|
||||
ObjectAttributes.SecurityDescriptor = NULL;
|
||||
|
|
Loading…
Reference in a new issue