- Improved DuplicateHandle for console handles.

svn path=/trunk/; revision=4272
This commit is contained in:
Hartmut Birr 2003-03-09 21:37:57 +00:00
parent bb63ba9048
commit 59798c6f34

View file

@ -1,4 +1,4 @@
/* $Id: handle.c,v 1.10 2003/02/12 00:39:31 hyperion Exp $
/* $Id: handle.c,v 1.11 2003/03/09 21:37:57 hbirr Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS system libraries
@ -16,6 +16,17 @@
#define NDEBUG
#include <kernel32/kernel32.h>
/* GLOBALS *******************************************************************/
WINBOOL STDCALL
GetProcessId (HANDLE hProcess, LPDWORD lpProcessId);
HANDLE STDCALL
DuplicateConsoleHandle (HANDLE hConsole,
DWORD dwDesiredAccess,
BOOL bInheritHandle,
DWORD dwOptions);
/* FUNCTIONS *****************************************************************/
WINBOOL WINAPI GetHandleInformation(HANDLE hObject, LPDWORD lpdwFlags)
@ -119,18 +130,20 @@ WINBOOL STDCALL DuplicateHandle(HANDLE hSourceProcessHandle,
DWORD dwOptions)
{
NTSTATUS errCode;
DWORD SourceProcessId, TargetProcessId;
if (IsConsoleHandle(hSourceHandle))
{
/* FIXME: call CSRSS for console handle duplication */
if (hSourceProcessHandle == hTargetProcessHandle)
if (FALSE == GetProcessId(hSourceProcessHandle, &SourceProcessId) ||
FALSE == GetProcessId(hTargetProcessHandle, &TargetProcessId) ||
SourceProcessId != TargetProcessId ||
SourceProcessId != GetCurrentProcessId())
{
*lpTargetHandle = hSourceHandle;
return TRUE;
}
else
{
return FALSE;
SetLastError(ERROR_INVALID_PARAMETER);
return FALSE;
}
*lpTargetHandle = DuplicateConsoleHandle(hSourceHandle, dwDesiredAccess, bInheritHandle, dwOptions);
return *lpTargetHandle != INVALID_HANDLE_VALUE ? TRUE : FALSE;
}
errCode = NtDuplicateObject(hSourceProcessHandle,