Implemented VerifyConsoleIoHandle().

svn path=/trunk/; revision=4243
This commit is contained in:
Eric Kohl 2003-03-05 22:51:48 +00:00
parent 7f5d1e97f4
commit cb8b8e6c15
8 changed files with 223 additions and 151 deletions

View file

@ -352,6 +352,11 @@ typedef struct
HANDLE Handle; HANDLE Handle;
} CSRSS_CLOSE_HANDLE_REQUEST, *PCSRSS_CLOSE_HANDLE_REQUEST; } CSRSS_CLOSE_HANDLE_REQUEST, *PCSRSS_CLOSE_HANDLE_REQUEST;
typedef struct
{
HANDLE Handle;
} CSRSS_VERIFY_HANDLE_REQUEST, *PCSRSS_VERIFY_HANDLE_REQUEST;
#define CSRSS_MAX_WRITE_CONSOLE_REQUEST \ #define CSRSS_MAX_WRITE_CONSOLE_REQUEST \
(MAX_MESSAGE_DATA - sizeof(ULONG) - sizeof(CSRSS_WRITE_CONSOLE_REQUEST)) (MAX_MESSAGE_DATA - sizeof(ULONG) - sizeof(CSRSS_WRITE_CONSOLE_REQUEST))
@ -406,9 +411,10 @@ typedef struct
#define CSRSS_PEEK_CONSOLE_INPUT (0x21) #define CSRSS_PEEK_CONSOLE_INPUT (0x21)
#define CSRSS_READ_CONSOLE_OUTPUT (0x22) #define CSRSS_READ_CONSOLE_OUTPUT (0x22)
#define CSRSS_WRITE_CONSOLE_INPUT (0x23) #define CSRSS_WRITE_CONSOLE_INPUT (0x23)
#define CSRSS_GET_INPUT_HANDLE (0x24) #define CSRSS_GET_INPUT_HANDLE (0x24)
#define CSRSS_GET_OUTPUT_HANDLE (0x25) #define CSRSS_GET_OUTPUT_HANDLE (0x25)
#define CSRSS_CLOSE_HANDLE (0x26) #define CSRSS_CLOSE_HANDLE (0x26)
#define CSRSS_VERIFY_HANDLE (0x27)
/* Keep in sync with definition below. */ /* Keep in sync with definition below. */
#define CSRSS_REQUEST_HEADER_SIZE (sizeof(LPC_MESSAGE) + sizeof(ULONG)) #define CSRSS_REQUEST_HEADER_SIZE (sizeof(LPC_MESSAGE) + sizeof(ULONG))
@ -453,6 +459,7 @@ typedef struct
CSRSS_READ_CONSOLE_OUTPUT_REQUEST ReadConsoleOutputRequest; CSRSS_READ_CONSOLE_OUTPUT_REQUEST ReadConsoleOutputRequest;
CSRSS_WRITE_CONSOLE_INPUT_REQUEST WriteConsoleInputRequest; CSRSS_WRITE_CONSOLE_INPUT_REQUEST WriteConsoleInputRequest;
CSRSS_CLOSE_HANDLE_REQUEST CloseHandleRequest; CSRSS_CLOSE_HANDLE_REQUEST CloseHandleRequest;
CSRSS_VERIFY_HANDLE_REQUEST VerifyHandleRequest;
} Data; } Data;
} CSRSS_API_REQUEST, *PCSRSS_API_REQUEST; } CSRSS_API_REQUEST, *PCSRSS_API_REQUEST;

View file

@ -7297,6 +7297,12 @@ SetConsoleOutputCP(
UINT wCodePageID UINT wCodePageID
); );
BOOL
STDCALL
VerifyConsoleIoHandle(
HANDLE Handle
);
DWORD STDCALL DWORD STDCALL
WNetConnectionDialog( WNetConnectionDialog(
HWND hwnd, HWND hwnd,

View file

@ -1,4 +1,4 @@
/* $Id: console.c,v 1.53 2003/03/02 01:23:19 mdill Exp $ /* $Id: console.c,v 1.54 2003/03/05 22:51:48 ekohl Exp $
* *
* COPYRIGHT: See COPYING in the top level directory * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS system libraries * PROJECT: ReactOS system libraries
@ -500,16 +500,39 @@ ShowConsoleCursor (DWORD Unknown0,
return 0; return 0;
} }
DWORD STDCALL
VerifyConsoleIoHandle (DWORD Unknown0) /*
/* * FUNCTION: Checks whether the given handle is a valid console handle.
* Undocumented * ARGUMENTS:
*/ * Handle - Handle to be checked
* RETURNS:
* TRUE: Handle is a valid console handle
* FALSE: Handle is not a valid console handle.
* STATUS: Officially undocumented
*/
BOOL STDCALL
VerifyConsoleIoHandle(HANDLE Handle)
{ {
SetLastError(ERROR_CALL_NOT_IMPLEMENTED); CSRSS_API_REQUEST Request;
return 0; CSRSS_API_REPLY Reply;
NTSTATUS Status;
Request.Type = CSRSS_VERIFY_HANDLE;
Request.Data.VerifyHandleRequest.Handle = Handle;
Status = CsrClientCallServer(&Request,
&Reply,
sizeof(CSRSS_API_REQUEST),
sizeof(CSRSS_API_REPLY));
if (!NT_SUCCESS(Status))
{
SetLastErrorByStatus(Status);
return FALSE;
}
return (BOOL)NT_SUCCESS(Reply.Status);
} }
DWORD STDCALL DWORD STDCALL
WriteConsoleInputVDMA (DWORD Unknown0, WriteConsoleInputVDMA (DWORD Unknown0,
DWORD Unknown1, DWORD Unknown1,
@ -530,7 +553,7 @@ WriteConsoleInputVDMW (DWORD Unknown0,
return 0; return 0;
} }
WINBOOL STDCALL WINBOOL STDCALL
CloseConsoleHandle(HANDLE Handle) CloseConsoleHandle(HANDLE Handle)
/* /*
* Undocumented * Undocumented
@ -552,18 +575,16 @@ CloseConsoleHandle(HANDLE Handle)
&Reply, &Reply,
sizeof(CSRSS_API_REQUEST), sizeof(CSRSS_API_REQUEST),
sizeof(CSRSS_API_REPLY)); sizeof(CSRSS_API_REPLY));
if (!NT_SUCCESS(Status))
{
SetLastErrorByStatus(Status);
return FALSE;
}
if (NT_SUCCESS(Status)) return TRUE;
{
return TRUE;
}
else
{
SetLastErrorByStatus(Status);
return FALSE;
}
} }
BOOLEAN STDCALL BOOLEAN STDCALL
IsConsoleHandle(HANDLE Handle) IsConsoleHandle(HANDLE Handle)
{ {
@ -586,14 +607,20 @@ GetStdHandle(DWORD nStdHandle)
*/ */
{ {
PRTL_USER_PROCESS_PARAMETERS Ppb; PRTL_USER_PROCESS_PARAMETERS Ppb;
Ppb = NtCurrentPeb()->ProcessParameters; Ppb = NtCurrentPeb()->ProcessParameters;
switch (nStdHandle) switch (nStdHandle)
{ {
case STD_INPUT_HANDLE: return Ppb->hStdInput; case STD_INPUT_HANDLE:
case STD_OUTPUT_HANDLE: return Ppb->hStdOutput; return Ppb->hStdInput;
case STD_ERROR_HANDLE: return Ppb->hStdError;
case STD_OUTPUT_HANDLE:
return Ppb->hStdOutput;
case STD_ERROR_HANDLE:
return Ppb->hStdError;
} }
SetLastError (ERROR_INVALID_PARAMETER); SetLastError (ERROR_INVALID_PARAMETER);
return INVALID_HANDLE_VALUE; return INVALID_HANDLE_VALUE;
} }
@ -611,29 +638,33 @@ SetStdHandle(DWORD nStdHandle,
*/ */
{ {
PRTL_USER_PROCESS_PARAMETERS Ppb; PRTL_USER_PROCESS_PARAMETERS Ppb;
Ppb = NtCurrentPeb()->ProcessParameters; Ppb = NtCurrentPeb()->ProcessParameters;
/* More checking needed? */ /* More checking needed? */
if (hHandle == INVALID_HANDLE_VALUE) if (hHandle == INVALID_HANDLE_VALUE)
{ {
SetLastError (ERROR_INVALID_HANDLE); SetLastError (ERROR_INVALID_HANDLE);
return FALSE; return FALSE;
} }
SetLastError(ERROR_SUCCESS); /* OK */ SetLastError(ERROR_SUCCESS); /* OK */
switch (nStdHandle) switch (nStdHandle)
{ {
case STD_INPUT_HANDLE: case STD_INPUT_HANDLE:
Ppb->hStdInput = hHandle; Ppb->hStdInput = hHandle;
return TRUE; return TRUE;
case STD_OUTPUT_HANDLE:
Ppb->hStdOutput = hHandle; case STD_OUTPUT_HANDLE:
return TRUE; Ppb->hStdOutput = hHandle;
case STD_ERROR_HANDLE: return TRUE;
Ppb->hStdError = hHandle;
return TRUE; case STD_ERROR_HANDLE:
Ppb->hStdError = hHandle;
return TRUE;
} }
SetLastError (ERROR_INVALID_PARAMETER); SetLastError (ERROR_INVALID_PARAMETER);
return FALSE; return FALSE;
} }
@ -654,7 +685,7 @@ WriteConsoleA(HANDLE hConsoleOutput,
NTSTATUS Status; NTSTATUS Status;
USHORT Size; USHORT Size;
ULONG MessageSize; ULONG MessageSize;
Request = RtlAllocateHeap(GetProcessHeap(), Request = RtlAllocateHeap(GetProcessHeap(),
HEAP_ZERO_MEMORY, HEAP_ZERO_MEMORY,
sizeof(CSRSS_API_REQUEST) + sizeof(CSRSS_API_REQUEST) +
@ -664,7 +695,7 @@ WriteConsoleA(HANDLE hConsoleOutput,
SetLastError(ERROR_OUTOFMEMORY); SetLastError(ERROR_OUTOFMEMORY);
return(FALSE); return(FALSE);
} }
Request->Type = CSRSS_WRITE_CONSOLE; Request->Type = CSRSS_WRITE_CONSOLE;
Request->Data.WriteConsoleRequest.ConsoleHandle = hConsoleOutput; Request->Data.WriteConsoleRequest.ConsoleHandle = hConsoleOutput;
if (lpNumberOfCharsWritten != NULL) if (lpNumberOfCharsWritten != NULL)
@ -680,7 +711,7 @@ WriteConsoleA(HANDLE hConsoleOutput,
Size = nNumberOfCharsToWrite; Size = nNumberOfCharsToWrite;
} }
Request->Data.WriteConsoleRequest.NrCharactersToWrite = Size; Request->Data.WriteConsoleRequest.NrCharactersToWrite = Size;
memcpy(Request->Data.WriteConsoleRequest.Buffer, lpBuffer, Size); memcpy(Request->Data.WriteConsoleRequest.Buffer, lpBuffer, Size);
MessageSize = CSRSS_REQUEST_HEADER_SIZE + MessageSize = CSRSS_REQUEST_HEADER_SIZE +
@ -689,7 +720,7 @@ WriteConsoleA(HANDLE hConsoleOutput,
&Reply, &Reply,
MessageSize, MessageSize,
sizeof(CSRSS_API_REPLY)); sizeof(CSRSS_API_REPLY));
if (!NT_SUCCESS(Status) || !NT_SUCCESS(Status = Reply.Status)) if (!NT_SUCCESS(Status) || !NT_SUCCESS(Status = Reply.Status))
{ {
RtlFreeHeap(GetProcessHeap(), 0, Request); RtlFreeHeap(GetProcessHeap(), 0, Request);
@ -699,7 +730,9 @@ WriteConsoleA(HANDLE hConsoleOutput,
nNumberOfCharsToWrite -= Size; nNumberOfCharsToWrite -= Size;
lpBuffer += Size; lpBuffer += Size;
} }
RtlFreeHeap(GetProcessHeap(), 0, Request); RtlFreeHeap(GetProcessHeap(), 0, Request);
return TRUE; return TRUE;
} }

View file

@ -1,4 +1,4 @@
/* $Id: dllmain.c,v 1.26 2003/02/12 00:39:31 hyperion Exp $ /* $Id: dllmain.c,v 1.27 2003/03/05 22:51:48 ekohl Exp $
* *
* COPYRIGHT: See COPYING in the top level directory * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS system libraries * PROJECT: ReactOS system libraries
@ -26,139 +26,135 @@ HANDLE hBaseDir = NULL;
static WINBOOL DllInitialized = FALSE; static WINBOOL DllInitialized = FALSE;
WINBOOL STDCALL DllMain (HANDLE hInst, BOOL STDCALL
ULONG ul_reason_for_call, DllMain(HANDLE hInst,
LPVOID lpReserved); DWORD dwReason,
LPVOID lpReserved);
/* Critical section for various kernel32 data structures */ /* Critical section for various kernel32 data structures */
CRITICAL_SECTION DllLock; CRITICAL_SECTION DllLock;
/* FUNCTIONS *****************************************************************/ /* FUNCTIONS *****************************************************************/
static NTSTATUS static NTSTATUS
OpenBaseDirectory(PHANDLE DirHandle) OpenBaseDirectory(PHANDLE DirHandle)
{ {
OBJECT_ATTRIBUTES ObjectAttributes; OBJECT_ATTRIBUTES ObjectAttributes;
UNICODE_STRING Name = UNICODE_STRING_INITIALIZER(L"\\BaseNamedObjects"); UNICODE_STRING Name = UNICODE_STRING_INITIALIZER(L"\\BaseNamedObjects");
NTSTATUS Status; NTSTATUS Status;
InitializeObjectAttributes(&ObjectAttributes, InitializeObjectAttributes(&ObjectAttributes,
&Name, &Name,
OBJ_PERMANENT, OBJ_PERMANENT,
NULL, NULL,
NULL); NULL);
Status = NtOpenDirectoryObject(DirHandle, Status = NtOpenDirectoryObject(DirHandle,
DIRECTORY_ALL_ACCESS, DIRECTORY_ALL_ACCESS,
&ObjectAttributes); &ObjectAttributes);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
Status = NtCreateDirectoryObject(DirHandle, Status = NtCreateDirectoryObject(DirHandle,
DIRECTORY_ALL_ACCESS, DIRECTORY_ALL_ACCESS,
&ObjectAttributes); &ObjectAttributes);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
DbgPrint("NtCreateDirectoryObject() failed\n"); DbgPrint("NtCreateDirectoryObject() failed\n");
} }
return Status; return Status;
} }
return STATUS_SUCCESS; return STATUS_SUCCESS;
} }
BOOL WINAPI BOOL STDCALL
DllMainCRTStartup(HANDLE hDll, DWORD dwReason, LPVOID lpReserved) DllMain(HANDLE hDll,
{ DWORD dwReason,
return(DllMain(hDll,dwReason,lpReserved));
}
WINBOOL STDCALL
DllMain(HANDLE hInst,
ULONG ul_reason_for_call,
LPVOID lpReserved) LPVOID lpReserved)
{ {
(void)lpReserved; NTSTATUS Status;
DPRINT("DllMain(hInst %x, ul_reason_for_call %d)\n", (void)lpReserved;
hInst, ul_reason_for_call);
switch (ul_reason_for_call) DPRINT("DllMain(hInst %lx, dwReason %lu)\n",
{ hInst, dwReason);
switch (dwReason)
{
case DLL_PROCESS_ATTACH: case DLL_PROCESS_ATTACH:
DPRINT("DLL_PROCESS_ATTACH\n");
LdrDisableThreadCalloutsForDll ((PVOID)hDll);
/*
* Connect to the csrss server
*/
Status = CsrClientConnectToServer();
if (!NT_SUCCESS(Status))
{ {
NTSTATUS Status; DbgPrint("Failed to connect to csrss.exe (Status %lx)\n",
Status);
DPRINT("DLL_PROCESS_ATTACH\n"); ZwTerminateProcess(NtCurrentProcess(), Status);
return FALSE;
LdrDisableThreadCalloutsForDll ((PVOID)hInst);
/*
* Connect to the csrss server
*/
Status = CsrClientConnectToServer();
if (!NT_SUCCESS(Status))
{
DbgPrint("Failed to connect to csrss.exe: expect trouble "
"Status was %X\n", Status);
ZwTerminateProcess(NtCurrentProcess(), Status);
}
hProcessHeap = RtlGetProcessHeap();
/*
* Initialize WindowsDirectory and SystemDirectory
*/
DPRINT("NtSystemRoot: %S\n",
SharedUserData->NtSystemRoot);
RtlCreateUnicodeString (&WindowsDirectory,
SharedUserData->NtSystemRoot);
SystemDirectory.MaximumLength = WindowsDirectory.MaximumLength + 18;
SystemDirectory.Length = WindowsDirectory.Length + 18;
SystemDirectory.Buffer = RtlAllocateHeap (hProcessHeap,
0,
SystemDirectory.MaximumLength);
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");
}
/* Initialize the DLL critical section */
RtlInitializeCriticalSection(&DllLock);
/* Insert more dll attach stuff here! */
DllInitialized = TRUE;
break;
} }
hProcessHeap = RtlGetProcessHeap();
/*
* Initialize WindowsDirectory and SystemDirectory
*/
DPRINT("NtSystemRoot: %S\n",
SharedUserData->NtSystemRoot);
RtlCreateUnicodeString (&WindowsDirectory,
SharedUserData->NtSystemRoot);
SystemDirectory.MaximumLength = WindowsDirectory.MaximumLength + 18;
SystemDirectory.Length = WindowsDirectory.Length + 18;
SystemDirectory.Buffer = RtlAllocateHeap (hProcessHeap,
0,
SystemDirectory.MaximumLength);
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 (Status %lx)\n",
Status);
return FALSE;
}
/* Initialize the DLL critical section */
RtlInitializeCriticalSection(&DllLock);
/* Insert more dll attach stuff here! */
DllInitialized = TRUE;
break;
case DLL_PROCESS_DETACH: case DLL_PROCESS_DETACH:
DPRINT("DLL_PROCESS_DETACH\n");
if (DllInitialized == TRUE)
{ {
DPRINT("DLL_PROCESS_DETACH\n"); /* Insert more dll detach stuff here! */
if (DllInitialized == TRUE)
{
/* Insert more dll detach stuff here! */
/* Delete DLL critical section */
RtlDeleteCriticalSection (&DllLock);
/* Close object base directory */ /* Delete DLL critical section */
NtClose(hBaseDir); RtlDeleteCriticalSection (&DllLock);
RtlFreeUnicodeString (&SystemDirectory); /* Close object base directory */
RtlFreeUnicodeString (&WindowsDirectory); NtClose(hBaseDir);
}
break; RtlFreeUnicodeString (&SystemDirectory);
RtlFreeUnicodeString (&WindowsDirectory);
} }
break;
default: default:
break; break;
} }
return TRUE; return TRUE;
} }

View file

@ -135,6 +135,7 @@ CSR_API(CsrWriteConsoleInput);
CSR_API(CsrGetInputHandle); CSR_API(CsrGetInputHandle);
CSR_API(CsrGetOutputHandle); CSR_API(CsrGetOutputHandle);
CSR_API(CsrCloseHandle); CSR_API(CsrCloseHandle);
CSR_API(CsrVerifyHandle);
/* print.c */ /* print.c */
VOID STDCALL DisplayString(LPCWSTR lpwString); VOID STDCALL DisplayString(LPCWSTR lpwString);
@ -163,6 +164,7 @@ NTSTATUS STDCALL CsrInsertObject( PCSRSS_PROCESS_DATA ProcessData, PHANDLE Handl
NTSTATUS STDCALL CsrGetObject( PCSRSS_PROCESS_DATA ProcessData, HANDLE Handle, Object_t **Object ); NTSTATUS STDCALL CsrGetObject( PCSRSS_PROCESS_DATA ProcessData, HANDLE Handle, Object_t **Object );
BOOL STDCALL CsrServerInitialization (ULONG ArgumentCount, PWSTR *ArgumentArray); BOOL STDCALL CsrServerInitialization (ULONG ArgumentCount, PWSTR *ArgumentArray);
NTSTATUS STDCALL CsrReleaseObject( PCSRSS_PROCESS_DATA ProcessData, HANDLE Object ); NTSTATUS STDCALL CsrReleaseObject( PCSRSS_PROCESS_DATA ProcessData, HANDLE Object );
NTSTATUS STDCALL CsrVerifyObject( PCSRSS_PROCESS_DATA ProcessData, HANDLE Object );
VOID STDCALL CsrDrawConsole( PCSRSS_SCREEN_BUFFER Console ); VOID STDCALL CsrDrawConsole( PCSRSS_SCREEN_BUFFER Console );
NTSTATUS STDCALL CsrpWriteConsole( PCSRSS_SCREEN_BUFFER Buff, CHAR *Buffer, DWORD Length, BOOL Attrib ); NTSTATUS STDCALL CsrpWriteConsole( PCSRSS_SCREEN_BUFFER Buff, CHAR *Buffer, DWORD Length, BOOL Attrib );

View file

@ -1,4 +1,4 @@
/* $Id: handle.c,v 1.12 2002/09/08 10:23:45 chorns Exp $ /* $Id: handle.c,v 1.13 2003/03/05 22:50:24 ekohl Exp $
* *
* reactos/subsys/csrss/api/handle.c * reactos/subsys/csrss/api/handle.c
* *
@ -89,5 +89,16 @@ NTSTATUS STDCALL CsrInsertObject( PCSRSS_PROCESS_DATA ProcessData, PHANDLE Handl
return(STATUS_SUCCESS); return(STATUS_SUCCESS);
} }
NTSTATUS STDCALL CsrVerifyObject( PCSRSS_PROCESS_DATA ProcessData, HANDLE Handle )
{
ULONG h = (((ULONG)Handle) >> 2) - 1;
if (h >= ProcessData->HandleTableSize)
{
return STATUS_INVALID_HANDLE;
}
return ProcessData->HandleTable[h] ? STATUS_SUCCESS : STATUS_INVALID_HANDLE;
}
/* EOF */ /* EOF */

View file

@ -1,4 +1,4 @@
/* $Id: process.c,v 1.24 2003/02/24 23:20:15 hbirr Exp $ /* $Id: process.c,v 1.25 2003/03/05 22:50:24 ekohl Exp $
* *
* reactos/subsys/csrss/api/process.c * reactos/subsys/csrss/api/process.c
* *
@ -346,5 +346,21 @@ CSR_API(CsrCloseHandle)
} }
return Reply->Status; return Reply->Status;
} }
CSR_API(CsrVerifyHandle)
{
Reply->Header.MessageSize = sizeof(CSRSS_API_REPLY);
Reply->Header.DataSize = sizeof(CSRSS_API_REPLY) - sizeof(LPC_MESSAGE);
if (ProcessData == NULL)
{
Reply->Status = STATUS_INVALID_PARAMETER;
}
else
{
Reply->Status = CsrVerifyObject(ProcessData, Request->Data.VerifyHandleRequest.Handle);
}
return Reply->Status;
}
/* EOF */ /* EOF */

View file

@ -1,4 +1,4 @@
/* $Id: wapi.c,v 1.26 2003/02/24 23:20:15 hbirr Exp $ /* $Id: wapi.c,v 1.27 2003/03/05 22:50:24 ekohl Exp $
* *
* reactos/subsys/csrss/api/wapi.c * reactos/subsys/csrss/api/wapi.c
* *
@ -66,6 +66,7 @@ static const CsrFunc CsrFuncs[] = {
CsrGetInputHandle, CsrGetInputHandle,
CsrGetOutputHandle, CsrGetOutputHandle,
CsrCloseHandle, CsrCloseHandle,
CsrVerifyHandle,
0 }; 0 };
static void Thread_Api2(HANDLE ServerPort) static void Thread_Api2(HANDLE ServerPort)