- 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 * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS system libraries * PROJECT: ReactOS system libraries
@ -16,6 +16,17 @@
#define NDEBUG #define NDEBUG
#include <kernel32/kernel32.h> #include <kernel32/kernel32.h>
/* GLOBALS *******************************************************************/
WINBOOL STDCALL
GetProcessId (HANDLE hProcess, LPDWORD lpProcessId);
HANDLE STDCALL
DuplicateConsoleHandle (HANDLE hConsole,
DWORD dwDesiredAccess,
BOOL bInheritHandle,
DWORD dwOptions);
/* FUNCTIONS *****************************************************************/ /* FUNCTIONS *****************************************************************/
WINBOOL WINAPI GetHandleInformation(HANDLE hObject, LPDWORD lpdwFlags) WINBOOL WINAPI GetHandleInformation(HANDLE hObject, LPDWORD lpdwFlags)
@ -119,18 +130,20 @@ WINBOOL STDCALL DuplicateHandle(HANDLE hSourceProcessHandle,
DWORD dwOptions) DWORD dwOptions)
{ {
NTSTATUS errCode; NTSTATUS errCode;
DWORD SourceProcessId, TargetProcessId;
if (IsConsoleHandle(hSourceHandle)) if (IsConsoleHandle(hSourceHandle))
{ {
/* FIXME: call CSRSS for console handle duplication */ if (FALSE == GetProcessId(hSourceProcessHandle, &SourceProcessId) ||
if (hSourceProcessHandle == hTargetProcessHandle) FALSE == GetProcessId(hTargetProcessHandle, &TargetProcessId) ||
SourceProcessId != TargetProcessId ||
SourceProcessId != GetCurrentProcessId())
{ {
*lpTargetHandle = hSourceHandle; SetLastError(ERROR_INVALID_PARAMETER);
return TRUE; return FALSE;
}
else
{
return FALSE;
} }
*lpTargetHandle = DuplicateConsoleHandle(hSourceHandle, dwDesiredAccess, bInheritHandle, dwOptions);
return *lpTargetHandle != INVALID_HANDLE_VALUE ? TRUE : FALSE;
} }
errCode = NtDuplicateObject(hSourceProcessHandle, errCode = NtDuplicateObject(hSourceProcessHandle,