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

View file

@ -7297,6 +7297,12 @@ SetConsoleOutputCP(
UINT wCodePageID
);
BOOL
STDCALL
VerifyConsoleIoHandle(
HANDLE Handle
);
DWORD STDCALL
WNetConnectionDialog(
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
* PROJECT: ReactOS system libraries
@ -500,16 +500,39 @@ ShowConsoleCursor (DWORD Unknown0,
return 0;
}
DWORD STDCALL
VerifyConsoleIoHandle (DWORD Unknown0)
/*
* Undocumented
*/
/*
* FUNCTION: Checks whether the given handle is a valid console handle.
* 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);
return 0;
CSRSS_API_REQUEST Request;
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
WriteConsoleInputVDMA (DWORD Unknown0,
DWORD Unknown1,
@ -530,7 +553,7 @@ WriteConsoleInputVDMW (DWORD Unknown0,
return 0;
}
WINBOOL STDCALL
WINBOOL STDCALL
CloseConsoleHandle(HANDLE Handle)
/*
* Undocumented
@ -552,18 +575,16 @@ CloseConsoleHandle(HANDLE Handle)
&Reply,
sizeof(CSRSS_API_REQUEST),
sizeof(CSRSS_API_REPLY));
if (!NT_SUCCESS(Status))
{
SetLastErrorByStatus(Status);
return FALSE;
}
if (NT_SUCCESS(Status))
{
return TRUE;
}
else
{
SetLastErrorByStatus(Status);
return FALSE;
}
return TRUE;
}
BOOLEAN STDCALL
IsConsoleHandle(HANDLE Handle)
{
@ -586,14 +607,20 @@ GetStdHandle(DWORD nStdHandle)
*/
{
PRTL_USER_PROCESS_PARAMETERS Ppb;
Ppb = NtCurrentPeb()->ProcessParameters;
Ppb = NtCurrentPeb()->ProcessParameters;
switch (nStdHandle)
{
case STD_INPUT_HANDLE: return Ppb->hStdInput;
case STD_OUTPUT_HANDLE: return Ppb->hStdOutput;
case STD_ERROR_HANDLE: return Ppb->hStdError;
case STD_INPUT_HANDLE:
return Ppb->hStdInput;
case STD_OUTPUT_HANDLE:
return Ppb->hStdOutput;
case STD_ERROR_HANDLE:
return Ppb->hStdError;
}
SetLastError (ERROR_INVALID_PARAMETER);
return INVALID_HANDLE_VALUE;
}
@ -611,29 +638,33 @@ SetStdHandle(DWORD nStdHandle,
*/
{
PRTL_USER_PROCESS_PARAMETERS Ppb;
Ppb = NtCurrentPeb()->ProcessParameters;
/* More checking needed? */
if (hHandle == INVALID_HANDLE_VALUE)
{
SetLastError (ERROR_INVALID_HANDLE);
return FALSE;
}
SetLastError(ERROR_SUCCESS); /* OK */
switch (nStdHandle)
{
case STD_INPUT_HANDLE:
Ppb->hStdInput = hHandle;
return TRUE;
case STD_OUTPUT_HANDLE:
Ppb->hStdOutput = hHandle;
return TRUE;
case STD_ERROR_HANDLE:
Ppb->hStdError = hHandle;
return TRUE;
case STD_INPUT_HANDLE:
Ppb->hStdInput = hHandle;
return TRUE;
case STD_OUTPUT_HANDLE:
Ppb->hStdOutput = hHandle;
return TRUE;
case STD_ERROR_HANDLE:
Ppb->hStdError = hHandle;
return TRUE;
}
SetLastError (ERROR_INVALID_PARAMETER);
return FALSE;
}
@ -654,7 +685,7 @@ WriteConsoleA(HANDLE hConsoleOutput,
NTSTATUS Status;
USHORT Size;
ULONG MessageSize;
Request = RtlAllocateHeap(GetProcessHeap(),
HEAP_ZERO_MEMORY,
sizeof(CSRSS_API_REQUEST) +
@ -664,7 +695,7 @@ WriteConsoleA(HANDLE hConsoleOutput,
SetLastError(ERROR_OUTOFMEMORY);
return(FALSE);
}
Request->Type = CSRSS_WRITE_CONSOLE;
Request->Data.WriteConsoleRequest.ConsoleHandle = hConsoleOutput;
if (lpNumberOfCharsWritten != NULL)
@ -680,7 +711,7 @@ WriteConsoleA(HANDLE hConsoleOutput,
Size = nNumberOfCharsToWrite;
}
Request->Data.WriteConsoleRequest.NrCharactersToWrite = Size;
memcpy(Request->Data.WriteConsoleRequest.Buffer, lpBuffer, Size);
MessageSize = CSRSS_REQUEST_HEADER_SIZE +
@ -689,7 +720,7 @@ WriteConsoleA(HANDLE hConsoleOutput,
&Reply,
MessageSize,
sizeof(CSRSS_API_REPLY));
if (!NT_SUCCESS(Status) || !NT_SUCCESS(Status = Reply.Status))
{
RtlFreeHeap(GetProcessHeap(), 0, Request);
@ -699,7 +730,9 @@ WriteConsoleA(HANDLE hConsoleOutput,
nNumberOfCharsToWrite -= Size;
lpBuffer += Size;
}
RtlFreeHeap(GetProcessHeap(), 0, Request);
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
* PROJECT: ReactOS system libraries
@ -26,139 +26,135 @@ HANDLE hBaseDir = NULL;
static WINBOOL DllInitialized = FALSE;
WINBOOL STDCALL DllMain (HANDLE hInst,
ULONG ul_reason_for_call,
LPVOID lpReserved);
BOOL STDCALL
DllMain(HANDLE hInst,
DWORD dwReason,
LPVOID lpReserved);
/* Critical section for various kernel32 data structures */
CRITICAL_SECTION DllLock;
/* FUNCTIONS *****************************************************************/
static NTSTATUS
static NTSTATUS
OpenBaseDirectory(PHANDLE DirHandle)
{
OBJECT_ATTRIBUTES ObjectAttributes;
UNICODE_STRING Name = UNICODE_STRING_INITIALIZER(L"\\BaseNamedObjects");
NTSTATUS Status;
OBJECT_ATTRIBUTES ObjectAttributes;
UNICODE_STRING Name = UNICODE_STRING_INITIALIZER(L"\\BaseNamedObjects");
NTSTATUS Status;
InitializeObjectAttributes(&ObjectAttributes,
&Name,
OBJ_PERMANENT,
NULL,
NULL);
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");
}
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;
}
return STATUS_SUCCESS;
return STATUS_SUCCESS;
}
BOOL WINAPI
DllMainCRTStartup(HANDLE hDll, DWORD dwReason, LPVOID lpReserved)
{
return(DllMain(hDll,dwReason,lpReserved));
}
WINBOOL STDCALL
DllMain(HANDLE hInst,
ULONG ul_reason_for_call,
BOOL STDCALL
DllMain(HANDLE hDll,
DWORD dwReason,
LPVOID lpReserved)
{
(void)lpReserved;
NTSTATUS Status;
DPRINT("DllMain(hInst %x, ul_reason_for_call %d)\n",
hInst, ul_reason_for_call);
(void)lpReserved;
switch (ul_reason_for_call)
{
DPRINT("DllMain(hInst %lx, dwReason %lu)\n",
hInst, dwReason);
switch (dwReason)
{
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;
DPRINT("DLL_PROCESS_ATTACH\n");
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;
DbgPrint("Failed to connect to csrss.exe (Status %lx)\n",
Status);
ZwTerminateProcess(NtCurrentProcess(), Status);
return FALSE;
}
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:
DPRINT("DLL_PROCESS_DETACH\n");
if (DllInitialized == TRUE)
{
DPRINT("DLL_PROCESS_DETACH\n");
if (DllInitialized == TRUE)
{
/* Insert more dll detach stuff here! */
/* Delete DLL critical section */
RtlDeleteCriticalSection (&DllLock);
/* Insert more dll detach stuff here! */
/* Close object base directory */
NtClose(hBaseDir);
RtlFreeUnicodeString (&SystemDirectory);
RtlFreeUnicodeString (&WindowsDirectory);
}
break;
/* Delete DLL critical section */
RtlDeleteCriticalSection (&DllLock);
/* Close object base directory */
NtClose(hBaseDir);
RtlFreeUnicodeString (&SystemDirectory);
RtlFreeUnicodeString (&WindowsDirectory);
}
break;
default:
break;
}
return TRUE;
}

View file

@ -135,6 +135,7 @@ CSR_API(CsrWriteConsoleInput);
CSR_API(CsrGetInputHandle);
CSR_API(CsrGetOutputHandle);
CSR_API(CsrCloseHandle);
CSR_API(CsrVerifyHandle);
/* print.c */
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 );
BOOL STDCALL CsrServerInitialization (ULONG ArgumentCount, PWSTR *ArgumentArray);
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 );
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
*
@ -89,5 +89,16 @@ NTSTATUS STDCALL CsrInsertObject( PCSRSS_PROCESS_DATA ProcessData, PHANDLE Handl
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 */

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
*
@ -346,5 +346,21 @@ CSR_API(CsrCloseHandle)
}
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 */

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
*
@ -66,6 +66,7 @@ static const CsrFunc CsrFuncs[] = {
CsrGetInputHandle,
CsrGetOutputHandle,
CsrCloseHandle,
CsrVerifyHandle,
0 };
static void Thread_Api2(HANDLE ServerPort)