2010-05-31 06:28:55 +00:00
|
|
|
|
/*
|
2012-10-25 20:40:41 +00:00
|
|
|
|
* COPYRIGHT: See COPYING in the top level directory
|
|
|
|
|
* PROJECT: ReactOS Console Server DLL
|
2013-07-13 04:54:49 +00:00
|
|
|
|
* FILE: win32ss/user/winsrv/consrv/console.c
|
2013-04-07 23:18:59 +00:00
|
|
|
|
* PURPOSE: Console Management Functions
|
2013-04-10 20:22:30 +00:00
|
|
|
|
* PROGRAMMERS: G<EFBFBD> van Geldorp
|
|
|
|
|
* Jeffrey Morlan
|
|
|
|
|
* Hermes Belusca-Maito (hermes.belusca@sfr.fr)
|
2010-05-31 06:28:55 +00:00
|
|
|
|
*/
|
|
|
|
|
|
2013-03-19 22:05:38 +00:00
|
|
|
|
/* INCLUDES *******************************************************************/
|
2010-05-31 06:28:55 +00:00
|
|
|
|
|
2012-10-23 22:31:36 +00:00
|
|
|
|
#include "consrv.h"
|
2014-02-04 19:54:42 +00:00
|
|
|
|
|
|
|
|
|
#include <ndk/psfuncs.h>
|
2013-04-07 23:18:59 +00:00
|
|
|
|
#include "procinit.h"
|
2013-03-24 17:08:10 +00:00
|
|
|
|
|
2013-03-30 18:44:56 +00:00
|
|
|
|
#define NDEBUG
|
2010-05-31 06:28:55 +00:00
|
|
|
|
#include <debug.h>
|
|
|
|
|
|
2014-05-02 16:46:13 +00:00
|
|
|
|
// FIXME: Add this prototype to winternl.h / rtlfuncs.h / ...
|
|
|
|
|
NTSTATUS NTAPI RtlGetLastNtStatus(VOID);
|
|
|
|
|
|
2013-06-23 00:18:47 +00:00
|
|
|
|
/* GLOBALS ********************************************************************/
|
2012-10-23 22:31:36 +00:00
|
|
|
|
|
2013-06-23 00:18:47 +00:00
|
|
|
|
/* PRIVATE FUNCTIONS **********************************************************/
|
2013-01-24 22:41:33 +00:00
|
|
|
|
|
2014-05-02 16:46:13 +00:00
|
|
|
|
VOID
|
2013-01-24 22:41:33 +00:00
|
|
|
|
ConioPause(PCONSOLE Console, UINT Flags)
|
|
|
|
|
{
|
|
|
|
|
Console->PauseFlags |= Flags;
|
2014-05-02 16:46:13 +00:00
|
|
|
|
ConDrvPause(Console);
|
2013-01-24 22:41:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-05-02 16:46:13 +00:00
|
|
|
|
VOID
|
2013-01-24 22:41:33 +00:00
|
|
|
|
ConioUnpause(PCONSOLE Console, UINT Flags)
|
|
|
|
|
{
|
|
|
|
|
Console->PauseFlags &= ~Flags;
|
|
|
|
|
|
|
|
|
|
// if ((Console->PauseFlags & (PAUSED_FROM_KEYBOARD | PAUSED_FROM_SCROLLBAR | PAUSED_FROM_SELECTION)) == 0)
|
2014-05-02 16:46:13 +00:00
|
|
|
|
if (Console->PauseFlags == 0)
|
2013-01-24 22:41:33 +00:00
|
|
|
|
{
|
2014-05-02 16:46:13 +00:00
|
|
|
|
ConDrvUnpause(Console);
|
2013-01-24 22:41:33 +00:00
|
|
|
|
|
|
|
|
|
CsrNotifyWait(&Console->WriteWaitQueue,
|
2013-10-05 22:17:34 +00:00
|
|
|
|
TRUE,
|
2013-01-24 22:41:33 +00:00
|
|
|
|
NULL,
|
|
|
|
|
NULL);
|
2013-01-26 16:12:05 +00:00
|
|
|
|
if (!IsListEmpty(&Console->WriteWaitQueue))
|
|
|
|
|
{
|
|
|
|
|
CsrDereferenceWait(&Console->WriteWaitQueue);
|
|
|
|
|
}
|
2013-01-24 22:41:33 +00:00
|
|
|
|
}
|
2010-05-31 06:28:55 +00:00
|
|
|
|
}
|
2013-04-07 23:18:59 +00:00
|
|
|
|
|
2014-05-02 16:46:13 +00:00
|
|
|
|
NTSTATUS
|
2013-04-07 23:18:59 +00:00
|
|
|
|
ConSrvGetConsole(PCONSOLE_PROCESS_DATA ProcessData,
|
|
|
|
|
PCONSOLE* Console,
|
|
|
|
|
BOOL LockConsole)
|
|
|
|
|
{
|
|
|
|
|
NTSTATUS Status = STATUS_SUCCESS;
|
|
|
|
|
PCONSOLE ProcessConsole;
|
|
|
|
|
|
2013-06-23 00:18:47 +00:00
|
|
|
|
ASSERT(Console);
|
|
|
|
|
*Console = NULL;
|
|
|
|
|
|
2013-05-12 00:20:15 +00:00
|
|
|
|
// RtlEnterCriticalSection(&ProcessData->HandleTableLock);
|
2013-04-07 23:18:59 +00:00
|
|
|
|
|
2013-07-06 19:47:53 +00:00
|
|
|
|
Status = ConDrvGetConsole(&ProcessConsole, ProcessData->ConsoleHandle, LockConsole);
|
2013-06-23 00:18:47 +00:00
|
|
|
|
if (NT_SUCCESS(Status)) *Console = ProcessConsole;
|
2013-04-07 23:18:59 +00:00
|
|
|
|
|
2013-05-12 00:20:15 +00:00
|
|
|
|
// RtlLeaveCriticalSection(&ProcessData->HandleTableLock);
|
2013-04-07 23:18:59 +00:00
|
|
|
|
return Status;
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-02 16:46:13 +00:00
|
|
|
|
VOID
|
2013-04-07 23:18:59 +00:00
|
|
|
|
ConSrvReleaseConsole(PCONSOLE Console,
|
|
|
|
|
BOOL WasConsoleLocked)
|
|
|
|
|
{
|
2013-08-06 19:10:36 +00:00
|
|
|
|
/* Just call the driver */
|
2013-06-23 00:18:47 +00:00
|
|
|
|
ConDrvReleaseConsole(Console, WasConsoleLocked);
|
2013-03-30 18:44:56 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-02-10 12:36:57 +00:00
|
|
|
|
|
2014-05-02 18:44:26 +00:00
|
|
|
|
/* static */ NTSTATUS
|
|
|
|
|
ConSrvLoadFrontEnd(IN OUT PFRONTEND FrontEnd,
|
|
|
|
|
IN OUT PCONSOLE_INFO ConsoleInfo,
|
|
|
|
|
IN OUT PVOID ExtraConsoleInfo,
|
|
|
|
|
IN ULONG ProcessId);
|
|
|
|
|
/* static */ NTSTATUS
|
|
|
|
|
ConSrvUnloadFrontEnd(IN PFRONTEND FrontEnd);
|
|
|
|
|
|
2013-10-12 15:44:22 +00:00
|
|
|
|
NTSTATUS NTAPI
|
2013-07-06 19:47:53 +00:00
|
|
|
|
ConSrvInitConsole(OUT PHANDLE NewConsoleHandle,
|
|
|
|
|
OUT PCONSOLE* NewConsole,
|
[CONSOLE.DLL-KERNEL32-CONSRV]
Fix the console properties dialog, when launching and transmitting console properties. Before, the properties dialog was directly launched by the console server (consrv), running with CSRSS (System) privileges, what constituted a security hole. Now, I create a remote thread in the running process owning the console for launching the properties dialog (thus it has only user privileges, and not System ones anymore). For that purpose, I basically took the technique described in the following paper (Cesar Cerrudo, "Story of a dumb patch", http://www.argeniss.com/research/MSBugPaper.pdf or http://www.scn.rain.com/~neighorn/PDF/MSBugPaper.pdf), where basically the console server shares the console properties via a shared memory section with the console properties dialog dll. The address of the thread which launches the dialog in the context of the console app is given to the console server the same way as we do for the control handler (called e.g. when you press Ctrl-C, etc...)
Of course this is quite hackish, because you have the GUI interface split between the console server and the console properties dialog dll. Something far more elegant would be to put all the GUI thingie into a dedicated dll or exe, running with the same privileges as the console program itself (a kind of console -- or terminal -- emulator).
[CONSOLE.DLL]
Fix retriving / setting colors.c and other things.
[CONSRV.DLL]
- Fix retrieving / setting console properties from the registry (via the HKCU\Console\* keys), via the shell shortcuts (not totally done at the moment, because somebody has to implement properly that thing : http://msdn.microsoft.com/en-us/library/windows/desktop/bb773359(v=vs.85).aspx (NT_CONSOLE_PROPS structure stored as a shortcut data block) (at application launching time), and via the console properties dialog.
- Few DPRINTs removed.
svn path=/branches/ros-csrss/; revision=58415
2013-03-03 15:35:12 +00:00
|
|
|
|
IN OUT PCONSOLE_START_INFO ConsoleStartInfo,
|
2013-06-23 00:18:47 +00:00
|
|
|
|
IN ULONG ConsoleLeaderProcessId)
|
2010-05-31 06:28:55 +00:00
|
|
|
|
{
|
|
|
|
|
NTSTATUS Status;
|
2013-07-06 19:47:53 +00:00
|
|
|
|
HANDLE ConsoleHandle;
|
2013-01-05 23:37:04 +00:00
|
|
|
|
PCONSOLE Console;
|
2013-06-23 00:18:47 +00:00
|
|
|
|
CONSOLE_INFO ConsoleInfo;
|
|
|
|
|
SIZE_T Length = 0;
|
2014-05-02 18:44:26 +00:00
|
|
|
|
|
2013-06-23 00:18:47 +00:00
|
|
|
|
FRONTEND FrontEnd;
|
2010-05-31 06:28:55 +00:00
|
|
|
|
|
2013-06-23 00:18:47 +00:00
|
|
|
|
if (NewConsole == NULL || ConsoleStartInfo == NULL)
|
|
|
|
|
return STATUS_INVALID_PARAMETER;
|
2013-01-02 00:32:20 +00:00
|
|
|
|
|
2013-06-23 00:18:47 +00:00
|
|
|
|
*NewConsole = NULL;
|
2013-01-02 00:32:20 +00:00
|
|
|
|
|
2013-02-10 12:36:57 +00:00
|
|
|
|
/*
|
[CONSOLE.DLL-KERNEL32-CONSRV]
Fix the console properties dialog, when launching and transmitting console properties. Before, the properties dialog was directly launched by the console server (consrv), running with CSRSS (System) privileges, what constituted a security hole. Now, I create a remote thread in the running process owning the console for launching the properties dialog (thus it has only user privileges, and not System ones anymore). For that purpose, I basically took the technique described in the following paper (Cesar Cerrudo, "Story of a dumb patch", http://www.argeniss.com/research/MSBugPaper.pdf or http://www.scn.rain.com/~neighorn/PDF/MSBugPaper.pdf), where basically the console server shares the console properties via a shared memory section with the console properties dialog dll. The address of the thread which launches the dialog in the context of the console app is given to the console server the same way as we do for the control handler (called e.g. when you press Ctrl-C, etc...)
Of course this is quite hackish, because you have the GUI interface split between the console server and the console properties dialog dll. Something far more elegant would be to put all the GUI thingie into a dedicated dll or exe, running with the same privileges as the console program itself (a kind of console -- or terminal -- emulator).
[CONSOLE.DLL]
Fix retriving / setting colors.c and other things.
[CONSRV.DLL]
- Fix retrieving / setting console properties from the registry (via the HKCU\Console\* keys), via the shell shortcuts (not totally done at the moment, because somebody has to implement properly that thing : http://msdn.microsoft.com/en-us/library/windows/desktop/bb773359(v=vs.85).aspx (NT_CONSOLE_PROPS structure stored as a shortcut data block) (at application launching time), and via the console properties dialog.
- Few DPRINTs removed.
svn path=/branches/ros-csrss/; revision=58415
2013-03-03 15:35:12 +00:00
|
|
|
|
* Load the console settings
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/* 1. Load the default settings */
|
2013-06-23 00:18:47 +00:00
|
|
|
|
ConSrvGetDefaultSettings(&ConsoleInfo, ConsoleLeaderProcessId);
|
[CONSOLE.DLL-KERNEL32-CONSRV]
Fix the console properties dialog, when launching and transmitting console properties. Before, the properties dialog was directly launched by the console server (consrv), running with CSRSS (System) privileges, what constituted a security hole. Now, I create a remote thread in the running process owning the console for launching the properties dialog (thus it has only user privileges, and not System ones anymore). For that purpose, I basically took the technique described in the following paper (Cesar Cerrudo, "Story of a dumb patch", http://www.argeniss.com/research/MSBugPaper.pdf or http://www.scn.rain.com/~neighorn/PDF/MSBugPaper.pdf), where basically the console server shares the console properties via a shared memory section with the console properties dialog dll. The address of the thread which launches the dialog in the context of the console app is given to the console server the same way as we do for the control handler (called e.g. when you press Ctrl-C, etc...)
Of course this is quite hackish, because you have the GUI interface split between the console server and the console properties dialog dll. Something far more elegant would be to put all the GUI thingie into a dedicated dll or exe, running with the same privileges as the console program itself (a kind of console -- or terminal -- emulator).
[CONSOLE.DLL]
Fix retriving / setting colors.c and other things.
[CONSRV.DLL]
- Fix retrieving / setting console properties from the registry (via the HKCU\Console\* keys), via the shell shortcuts (not totally done at the moment, because somebody has to implement properly that thing : http://msdn.microsoft.com/en-us/library/windows/desktop/bb773359(v=vs.85).aspx (NT_CONSOLE_PROPS structure stored as a shortcut data block) (at application launching time), and via the console properties dialog.
- Few DPRINTs removed.
svn path=/branches/ros-csrss/; revision=58415
2013-03-03 15:35:12 +00:00
|
|
|
|
|
|
|
|
|
/* 2. Get the title of the console (initialize ConsoleInfo.ConsoleTitle) */
|
|
|
|
|
Length = min(wcslen(ConsoleStartInfo->ConsoleTitle),
|
|
|
|
|
sizeof(ConsoleInfo.ConsoleTitle) / sizeof(ConsoleInfo.ConsoleTitle[0]) - 1);
|
|
|
|
|
wcsncpy(ConsoleInfo.ConsoleTitle, ConsoleStartInfo->ConsoleTitle, Length);
|
|
|
|
|
ConsoleInfo.ConsoleTitle[Length] = L'\0';
|
|
|
|
|
|
2014-05-02 18:44:26 +00:00
|
|
|
|
#if 0
|
|
|
|
|
/* 3. Initialize the ConSrv terminal */
|
|
|
|
|
Status = ConSrvInitTerminal(&Terminal,
|
|
|
|
|
&ConsoleInfo,
|
|
|
|
|
ConsoleStartInfo,
|
|
|
|
|
ConsoleLeaderProcessId);
|
|
|
|
|
if (!NT_SUCCESS(Status))
|
2013-06-23 00:18:47 +00:00
|
|
|
|
{
|
2014-05-02 18:44:26 +00:00
|
|
|
|
DPRINT1("CONSRV: Failed to initialize a terminal, Status = 0x%08lx\n", Status);
|
|
|
|
|
return Status;
|
2013-06-23 00:18:47 +00:00
|
|
|
|
}
|
2014-05-02 18:44:26 +00:00
|
|
|
|
DPRINT("CONSRV: Terminal initialized\n");
|
|
|
|
|
#else
|
|
|
|
|
Status = ConSrvLoadFrontEnd(&FrontEnd,
|
|
|
|
|
&ConsoleInfo,
|
|
|
|
|
ConsoleStartInfo,
|
|
|
|
|
ConsoleLeaderProcessId);
|
2013-06-23 00:18:47 +00:00
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
|
{
|
|
|
|
|
DPRINT1("CONSRV: Failed to initialize a frontend, Status = 0x%08lx\n", Status);
|
|
|
|
|
return Status;
|
[CONSOLE.DLL-KERNEL32-CONSRV]
Fix the console properties dialog, when launching and transmitting console properties. Before, the properties dialog was directly launched by the console server (consrv), running with CSRSS (System) privileges, what constituted a security hole. Now, I create a remote thread in the running process owning the console for launching the properties dialog (thus it has only user privileges, and not System ones anymore). For that purpose, I basically took the technique described in the following paper (Cesar Cerrudo, "Story of a dumb patch", http://www.argeniss.com/research/MSBugPaper.pdf or http://www.scn.rain.com/~neighorn/PDF/MSBugPaper.pdf), where basically the console server shares the console properties via a shared memory section with the console properties dialog dll. The address of the thread which launches the dialog in the context of the console app is given to the console server the same way as we do for the control handler (called e.g. when you press Ctrl-C, etc...)
Of course this is quite hackish, because you have the GUI interface split between the console server and the console properties dialog dll. Something far more elegant would be to put all the GUI thingie into a dedicated dll or exe, running with the same privileges as the console program itself (a kind of console -- or terminal -- emulator).
[CONSOLE.DLL]
Fix retriving / setting colors.c and other things.
[CONSRV.DLL]
- Fix retrieving / setting console properties from the registry (via the HKCU\Console\* keys), via the shell shortcuts (not totally done at the moment, because somebody has to implement properly that thing : http://msdn.microsoft.com/en-us/library/windows/desktop/bb773359(v=vs.85).aspx (NT_CONSOLE_PROPS structure stored as a shortcut data block) (at application launching time), and via the console properties dialog.
- Few DPRINTs removed.
svn path=/branches/ros-csrss/; revision=58415
2013-03-03 15:35:12 +00:00
|
|
|
|
}
|
2013-06-23 00:18:47 +00:00
|
|
|
|
DPRINT("CONSRV: Frontend initialized\n");
|
2014-05-02 18:44:26 +00:00
|
|
|
|
#endif
|
2013-06-23 00:18:47 +00:00
|
|
|
|
|
[CONSOLE.DLL-KERNEL32-CONSRV]
Fix the console properties dialog, when launching and transmitting console properties. Before, the properties dialog was directly launched by the console server (consrv), running with CSRSS (System) privileges, what constituted a security hole. Now, I create a remote thread in the running process owning the console for launching the properties dialog (thus it has only user privileges, and not System ones anymore). For that purpose, I basically took the technique described in the following paper (Cesar Cerrudo, "Story of a dumb patch", http://www.argeniss.com/research/MSBugPaper.pdf or http://www.scn.rain.com/~neighorn/PDF/MSBugPaper.pdf), where basically the console server shares the console properties via a shared memory section with the console properties dialog dll. The address of the thread which launches the dialog in the context of the console app is given to the console server the same way as we do for the control handler (called e.g. when you press Ctrl-C, etc...)
Of course this is quite hackish, because you have the GUI interface split between the console server and the console properties dialog dll. Something far more elegant would be to put all the GUI thingie into a dedicated dll or exe, running with the same privileges as the console program itself (a kind of console -- or terminal -- emulator).
[CONSOLE.DLL]
Fix retriving / setting colors.c and other things.
[CONSRV.DLL]
- Fix retrieving / setting console properties from the registry (via the HKCU\Console\* keys), via the shell shortcuts (not totally done at the moment, because somebody has to implement properly that thing : http://msdn.microsoft.com/en-us/library/windows/desktop/bb773359(v=vs.85).aspx (NT_CONSOLE_PROPS structure stored as a shortcut data block) (at application launching time), and via the console properties dialog.
- Few DPRINTs removed.
svn path=/branches/ros-csrss/; revision=58415
2013-03-03 15:35:12 +00:00
|
|
|
|
/*
|
|
|
|
|
* 4. Load the remaining console settings via the registry.
|
|
|
|
|
*/
|
|
|
|
|
if ((ConsoleStartInfo->dwStartupFlags & STARTF_TITLEISLINKNAME) == 0)
|
|
|
|
|
{
|
|
|
|
|
/*
|
|
|
|
|
* Either we weren't created by an app launched via a shell-link,
|
|
|
|
|
* or we failed to load shell-link console properties.
|
|
|
|
|
* Therefore, load the console infos for the application from the registry.
|
|
|
|
|
*/
|
2013-06-23 00:18:47 +00:00
|
|
|
|
ConSrvReadUserSettings(&ConsoleInfo, ConsoleLeaderProcessId);
|
[CONSOLE.DLL-KERNEL32-CONSRV]
Fix the console properties dialog, when launching and transmitting console properties. Before, the properties dialog was directly launched by the console server (consrv), running with CSRSS (System) privileges, what constituted a security hole. Now, I create a remote thread in the running process owning the console for launching the properties dialog (thus it has only user privileges, and not System ones anymore). For that purpose, I basically took the technique described in the following paper (Cesar Cerrudo, "Story of a dumb patch", http://www.argeniss.com/research/MSBugPaper.pdf or http://www.scn.rain.com/~neighorn/PDF/MSBugPaper.pdf), where basically the console server shares the console properties via a shared memory section with the console properties dialog dll. The address of the thread which launches the dialog in the context of the console app is given to the console server the same way as we do for the control handler (called e.g. when you press Ctrl-C, etc...)
Of course this is quite hackish, because you have the GUI interface split between the console server and the console properties dialog dll. Something far more elegant would be to put all the GUI thingie into a dedicated dll or exe, running with the same privileges as the console program itself (a kind of console -- or terminal -- emulator).
[CONSOLE.DLL]
Fix retriving / setting colors.c and other things.
[CONSRV.DLL]
- Fix retrieving / setting console properties from the registry (via the HKCU\Console\* keys), via the shell shortcuts (not totally done at the moment, because somebody has to implement properly that thing : http://msdn.microsoft.com/en-us/library/windows/desktop/bb773359(v=vs.85).aspx (NT_CONSOLE_PROPS structure stored as a shortcut data block) (at application launching time), and via the console properties dialog.
- Few DPRINTs removed.
svn path=/branches/ros-csrss/; revision=58415
2013-03-03 15:35:12 +00:00
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Now, update them with the properties the user might gave to us
|
|
|
|
|
* via the STARTUPINFO structure before calling CreateProcess
|
|
|
|
|
* (and which was transmitted via the ConsoleStartInfo structure).
|
2013-03-24 17:08:10 +00:00
|
|
|
|
* We therefore overwrite the values read in the registry.
|
[CONSOLE.DLL-KERNEL32-CONSRV]
Fix the console properties dialog, when launching and transmitting console properties. Before, the properties dialog was directly launched by the console server (consrv), running with CSRSS (System) privileges, what constituted a security hole. Now, I create a remote thread in the running process owning the console for launching the properties dialog (thus it has only user privileges, and not System ones anymore). For that purpose, I basically took the technique described in the following paper (Cesar Cerrudo, "Story of a dumb patch", http://www.argeniss.com/research/MSBugPaper.pdf or http://www.scn.rain.com/~neighorn/PDF/MSBugPaper.pdf), where basically the console server shares the console properties via a shared memory section with the console properties dialog dll. The address of the thread which launches the dialog in the context of the console app is given to the console server the same way as we do for the control handler (called e.g. when you press Ctrl-C, etc...)
Of course this is quite hackish, because you have the GUI interface split between the console server and the console properties dialog dll. Something far more elegant would be to put all the GUI thingie into a dedicated dll or exe, running with the same privileges as the console program itself (a kind of console -- or terminal -- emulator).
[CONSOLE.DLL]
Fix retriving / setting colors.c and other things.
[CONSRV.DLL]
- Fix retrieving / setting console properties from the registry (via the HKCU\Console\* keys), via the shell shortcuts (not totally done at the moment, because somebody has to implement properly that thing : http://msdn.microsoft.com/en-us/library/windows/desktop/bb773359(v=vs.85).aspx (NT_CONSOLE_PROPS structure stored as a shortcut data block) (at application launching time), and via the console properties dialog.
- Few DPRINTs removed.
svn path=/branches/ros-csrss/; revision=58415
2013-03-03 15:35:12 +00:00
|
|
|
|
*/
|
|
|
|
|
if (ConsoleStartInfo->dwStartupFlags & STARTF_USEFILLATTRIBUTE)
|
|
|
|
|
{
|
2013-08-30 17:14:41 +00:00
|
|
|
|
ConsoleInfo.ScreenAttrib = (USHORT)ConsoleStartInfo->wFillAttribute;
|
[CONSOLE.DLL-KERNEL32-CONSRV]
Fix the console properties dialog, when launching and transmitting console properties. Before, the properties dialog was directly launched by the console server (consrv), running with CSRSS (System) privileges, what constituted a security hole. Now, I create a remote thread in the running process owning the console for launching the properties dialog (thus it has only user privileges, and not System ones anymore). For that purpose, I basically took the technique described in the following paper (Cesar Cerrudo, "Story of a dumb patch", http://www.argeniss.com/research/MSBugPaper.pdf or http://www.scn.rain.com/~neighorn/PDF/MSBugPaper.pdf), where basically the console server shares the console properties via a shared memory section with the console properties dialog dll. The address of the thread which launches the dialog in the context of the console app is given to the console server the same way as we do for the control handler (called e.g. when you press Ctrl-C, etc...)
Of course this is quite hackish, because you have the GUI interface split between the console server and the console properties dialog dll. Something far more elegant would be to put all the GUI thingie into a dedicated dll or exe, running with the same privileges as the console program itself (a kind of console -- or terminal -- emulator).
[CONSOLE.DLL]
Fix retriving / setting colors.c and other things.
[CONSRV.DLL]
- Fix retrieving / setting console properties from the registry (via the HKCU\Console\* keys), via the shell shortcuts (not totally done at the moment, because somebody has to implement properly that thing : http://msdn.microsoft.com/en-us/library/windows/desktop/bb773359(v=vs.85).aspx (NT_CONSOLE_PROPS structure stored as a shortcut data block) (at application launching time), and via the console properties dialog.
- Few DPRINTs removed.
svn path=/branches/ros-csrss/; revision=58415
2013-03-03 15:35:12 +00:00
|
|
|
|
}
|
|
|
|
|
if (ConsoleStartInfo->dwStartupFlags & STARTF_USECOUNTCHARS)
|
|
|
|
|
{
|
2013-08-30 17:14:41 +00:00
|
|
|
|
ConsoleInfo.ScreenBufferSize = ConsoleStartInfo->dwScreenBufferSize;
|
[CONSOLE.DLL-KERNEL32-CONSRV]
Fix the console properties dialog, when launching and transmitting console properties. Before, the properties dialog was directly launched by the console server (consrv), running with CSRSS (System) privileges, what constituted a security hole. Now, I create a remote thread in the running process owning the console for launching the properties dialog (thus it has only user privileges, and not System ones anymore). For that purpose, I basically took the technique described in the following paper (Cesar Cerrudo, "Story of a dumb patch", http://www.argeniss.com/research/MSBugPaper.pdf or http://www.scn.rain.com/~neighorn/PDF/MSBugPaper.pdf), where basically the console server shares the console properties via a shared memory section with the console properties dialog dll. The address of the thread which launches the dialog in the context of the console app is given to the console server the same way as we do for the control handler (called e.g. when you press Ctrl-C, etc...)
Of course this is quite hackish, because you have the GUI interface split between the console server and the console properties dialog dll. Something far more elegant would be to put all the GUI thingie into a dedicated dll or exe, running with the same privileges as the console program itself (a kind of console -- or terminal -- emulator).
[CONSOLE.DLL]
Fix retriving / setting colors.c and other things.
[CONSRV.DLL]
- Fix retrieving / setting console properties from the registry (via the HKCU\Console\* keys), via the shell shortcuts (not totally done at the moment, because somebody has to implement properly that thing : http://msdn.microsoft.com/en-us/library/windows/desktop/bb773359(v=vs.85).aspx (NT_CONSOLE_PROPS structure stored as a shortcut data block) (at application launching time), and via the console properties dialog.
- Few DPRINTs removed.
svn path=/branches/ros-csrss/; revision=58415
2013-03-03 15:35:12 +00:00
|
|
|
|
}
|
|
|
|
|
if (ConsoleStartInfo->dwStartupFlags & STARTF_USESIZE)
|
|
|
|
|
{
|
2013-08-30 17:14:41 +00:00
|
|
|
|
ConsoleInfo.ConsoleSize = ConsoleStartInfo->dwWindowSize;
|
[CONSOLE.DLL-KERNEL32-CONSRV]
Fix the console properties dialog, when launching and transmitting console properties. Before, the properties dialog was directly launched by the console server (consrv), running with CSRSS (System) privileges, what constituted a security hole. Now, I create a remote thread in the running process owning the console for launching the properties dialog (thus it has only user privileges, and not System ones anymore). For that purpose, I basically took the technique described in the following paper (Cesar Cerrudo, "Story of a dumb patch", http://www.argeniss.com/research/MSBugPaper.pdf or http://www.scn.rain.com/~neighorn/PDF/MSBugPaper.pdf), where basically the console server shares the console properties via a shared memory section with the console properties dialog dll. The address of the thread which launches the dialog in the context of the console app is given to the console server the same way as we do for the control handler (called e.g. when you press Ctrl-C, etc...)
Of course this is quite hackish, because you have the GUI interface split between the console server and the console properties dialog dll. Something far more elegant would be to put all the GUI thingie into a dedicated dll or exe, running with the same privileges as the console program itself (a kind of console -- or terminal -- emulator).
[CONSOLE.DLL]
Fix retriving / setting colors.c and other things.
[CONSRV.DLL]
- Fix retrieving / setting console properties from the registry (via the HKCU\Console\* keys), via the shell shortcuts (not totally done at the moment, because somebody has to implement properly that thing : http://msdn.microsoft.com/en-us/library/windows/desktop/bb773359(v=vs.85).aspx (NT_CONSOLE_PROPS structure stored as a shortcut data block) (at application launching time), and via the console properties dialog.
- Few DPRINTs removed.
svn path=/branches/ros-csrss/; revision=58415
2013-03-03 15:35:12 +00:00
|
|
|
|
}
|
2011-04-09 12:01:36 +00:00
|
|
|
|
}
|
2010-05-31 06:28:55 +00:00
|
|
|
|
|
2013-06-23 00:18:47 +00:00
|
|
|
|
/* Set-up the code page */
|
|
|
|
|
ConsoleInfo.CodePage = GetOEMCP();
|
2010-05-31 06:28:55 +00:00
|
|
|
|
|
2014-05-02 18:44:26 +00:00
|
|
|
|
/* Initialize a new console via the driver */
|
2013-07-06 19:47:53 +00:00
|
|
|
|
Status = ConDrvInitConsole(&ConsoleHandle,
|
|
|
|
|
&Console,
|
|
|
|
|
&ConsoleInfo,
|
|
|
|
|
ConsoleLeaderProcessId);
|
2013-02-10 12:36:57 +00:00
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
|
{
|
2013-06-23 00:18:47 +00:00
|
|
|
|
DPRINT1("Creating a new console failed, Status = 0x%08lx\n", Status);
|
2014-05-02 18:44:26 +00:00
|
|
|
|
ConSrvUnloadFrontEnd(&FrontEnd);
|
2013-02-10 12:36:57 +00:00
|
|
|
|
return Status;
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-23 00:18:47 +00:00
|
|
|
|
ASSERT(Console);
|
|
|
|
|
DPRINT("Console initialized\n");
|
2012-11-24 12:40:56 +00:00
|
|
|
|
|
2014-05-02 16:46:13 +00:00
|
|
|
|
/*** Register ConSrv features ***/
|
2014-05-02 18:44:26 +00:00
|
|
|
|
|
|
|
|
|
/* Initialize process support */
|
2014-05-02 16:46:13 +00:00
|
|
|
|
InitializeListHead(&Console->ProcessList);
|
|
|
|
|
Console->NotifiedLastCloseProcess = NULL;
|
|
|
|
|
Console->NotifyLastClose = FALSE;
|
2014-05-02 18:44:26 +00:00
|
|
|
|
|
|
|
|
|
/* Initialize pausing support */
|
|
|
|
|
Console->PauseFlags = 0;
|
2014-05-02 16:46:13 +00:00
|
|
|
|
InitializeListHead(&Console->ReadWaitQueue);
|
|
|
|
|
InitializeListHead(&Console->WriteWaitQueue);
|
|
|
|
|
|
2014-05-02 18:44:26 +00:00
|
|
|
|
Console->QuickEdit = ConsoleInfo.QuickEdit;
|
|
|
|
|
|
|
|
|
|
/* Attach the ConSrv terminal to the console */
|
2013-06-23 00:18:47 +00:00
|
|
|
|
Status = ConDrvRegisterFrontEnd(Console, &FrontEnd);
|
|
|
|
|
if (!NT_SUCCESS(Status))
|
2010-05-31 06:28:55 +00:00
|
|
|
|
{
|
2013-06-23 00:18:47 +00:00
|
|
|
|
DPRINT1("Failed to register frontend to the given console, Status = 0x%08lx\n", Status);
|
|
|
|
|
ConDrvDeleteConsole(Console);
|
2014-05-02 18:44:26 +00:00
|
|
|
|
ConSrvUnloadFrontEnd(&FrontEnd);
|
2013-06-23 00:18:47 +00:00
|
|
|
|
return Status;
|
2010-05-31 06:28:55 +00:00
|
|
|
|
}
|
2013-06-23 00:18:47 +00:00
|
|
|
|
DPRINT("FrontEnd registered\n");
|
2010-05-31 06:28:55 +00:00
|
|
|
|
|
[CONSOLE.DLL-KERNEL32-CONSRV]
Fix the console properties dialog, when launching and transmitting console properties. Before, the properties dialog was directly launched by the console server (consrv), running with CSRSS (System) privileges, what constituted a security hole. Now, I create a remote thread in the running process owning the console for launching the properties dialog (thus it has only user privileges, and not System ones anymore). For that purpose, I basically took the technique described in the following paper (Cesar Cerrudo, "Story of a dumb patch", http://www.argeniss.com/research/MSBugPaper.pdf or http://www.scn.rain.com/~neighorn/PDF/MSBugPaper.pdf), where basically the console server shares the console properties via a shared memory section with the console properties dialog dll. The address of the thread which launches the dialog in the context of the console app is given to the console server the same way as we do for the control handler (called e.g. when you press Ctrl-C, etc...)
Of course this is quite hackish, because you have the GUI interface split between the console server and the console properties dialog dll. Something far more elegant would be to put all the GUI thingie into a dedicated dll or exe, running with the same privileges as the console program itself (a kind of console -- or terminal -- emulator).
[CONSOLE.DLL]
Fix retriving / setting colors.c and other things.
[CONSRV.DLL]
- Fix retrieving / setting console properties from the registry (via the HKCU\Console\* keys), via the shell shortcuts (not totally done at the moment, because somebody has to implement properly that thing : http://msdn.microsoft.com/en-us/library/windows/desktop/bb773359(v=vs.85).aspx (NT_CONSOLE_PROPS structure stored as a shortcut data block) (at application launching time), and via the console properties dialog.
- Few DPRINTs removed.
svn path=/branches/ros-csrss/; revision=58415
2013-03-03 15:35:12 +00:00
|
|
|
|
/* Return the newly created console to the caller and a success code too */
|
2013-07-06 19:47:53 +00:00
|
|
|
|
*NewConsoleHandle = ConsoleHandle;
|
|
|
|
|
*NewConsole = Console;
|
2010-05-31 06:28:55 +00:00
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-12 15:44:22 +00:00
|
|
|
|
VOID NTAPI
|
2013-03-30 18:44:56 +00:00
|
|
|
|
ConSrvDeleteConsole(PCONSOLE Console)
|
2013-01-24 22:41:33 +00:00
|
|
|
|
{
|
2013-04-06 13:40:34 +00:00
|
|
|
|
DPRINT("ConSrvDeleteConsole\n");
|
2013-01-24 22:41:33 +00:00
|
|
|
|
|
2013-06-23 00:18:47 +00:00
|
|
|
|
/* Just call the driver. ConSrvDeregisterFrontEnd is called on-demand. */
|
|
|
|
|
ConDrvDeleteConsole(Console);
|
2013-01-24 22:41:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-03-19 22:05:38 +00:00
|
|
|
|
|
2014-05-02 16:46:13 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static NTSTATUS
|
|
|
|
|
ConSrvConsoleCtrlEventTimeout(IN ULONG CtrlEvent,
|
|
|
|
|
IN PCONSOLE_PROCESS_DATA ProcessData,
|
|
|
|
|
IN ULONG Timeout)
|
|
|
|
|
{
|
|
|
|
|
NTSTATUS Status = STATUS_SUCCESS;
|
|
|
|
|
|
|
|
|
|
DPRINT("ConSrvConsoleCtrlEventTimeout Parent ProcessId = %x\n", ProcessData->Process->ClientId.UniqueProcess);
|
|
|
|
|
|
|
|
|
|
if (ProcessData->CtrlDispatcher)
|
|
|
|
|
{
|
|
|
|
|
_SEH2_TRY
|
|
|
|
|
{
|
|
|
|
|
HANDLE Thread = NULL;
|
|
|
|
|
|
|
|
|
|
_SEH2_TRY
|
|
|
|
|
{
|
|
|
|
|
Thread = CreateRemoteThread(ProcessData->Process->ProcessHandle, NULL, 0,
|
|
|
|
|
ProcessData->CtrlDispatcher,
|
|
|
|
|
UlongToPtr(CtrlEvent), 0, NULL);
|
|
|
|
|
if (NULL == Thread)
|
|
|
|
|
{
|
|
|
|
|
Status = RtlGetLastNtStatus();
|
|
|
|
|
DPRINT1("Failed thread creation, Status = 0x%08lx\n", Status);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
DPRINT("ProcessData->CtrlDispatcher remote thread creation succeeded, ProcessId = %x, Process = 0x%p\n", ProcessData->Process->ClientId.UniqueProcess, ProcessData->Process);
|
|
|
|
|
WaitForSingleObject(Thread, Timeout);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
_SEH2_FINALLY
|
|
|
|
|
{
|
|
|
|
|
CloseHandle(Thread);
|
|
|
|
|
}
|
|
|
|
|
_SEH2_END;
|
|
|
|
|
}
|
|
|
|
|
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
|
|
|
|
|
{
|
|
|
|
|
Status = _SEH2_GetExceptionCode();
|
|
|
|
|
DPRINT1("ConSrvConsoleCtrlEventTimeout - Caught an exception, Status = 0x%08lx\n", Status);
|
|
|
|
|
}
|
|
|
|
|
_SEH2_END;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return Status;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NTSTATUS
|
|
|
|
|
ConSrvConsoleCtrlEvent(IN ULONG CtrlEvent,
|
|
|
|
|
IN PCONSOLE_PROCESS_DATA ProcessData)
|
|
|
|
|
{
|
|
|
|
|
return ConSrvConsoleCtrlEventTimeout(CtrlEvent, ProcessData, 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PCONSOLE_PROCESS_DATA NTAPI
|
|
|
|
|
ConSrvGetConsoleLeaderProcess(IN PCONSOLE Console)
|
|
|
|
|
{
|
|
|
|
|
if (Console == NULL) return NULL;
|
|
|
|
|
|
|
|
|
|
return CONTAINING_RECORD(Console->ProcessList.Blink,
|
|
|
|
|
CONSOLE_PROCESS_DATA,
|
|
|
|
|
ConsoleLink);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NTSTATUS NTAPI
|
|
|
|
|
ConSrvGetConsoleProcessList(IN PCONSOLE Console,
|
|
|
|
|
IN OUT PULONG ProcessIdsList,
|
|
|
|
|
IN ULONG MaxIdListItems,
|
|
|
|
|
OUT PULONG ProcessIdsTotal)
|
|
|
|
|
{
|
|
|
|
|
PCONSOLE_PROCESS_DATA current;
|
|
|
|
|
PLIST_ENTRY current_entry;
|
|
|
|
|
|
|
|
|
|
if (Console == NULL || ProcessIdsList == NULL || ProcessIdsTotal == NULL)
|
|
|
|
|
return STATUS_INVALID_PARAMETER;
|
|
|
|
|
|
|
|
|
|
*ProcessIdsTotal = 0;
|
|
|
|
|
|
|
|
|
|
for (current_entry = Console->ProcessList.Flink;
|
|
|
|
|
current_entry != &Console->ProcessList;
|
|
|
|
|
current_entry = current_entry->Flink)
|
|
|
|
|
{
|
|
|
|
|
current = CONTAINING_RECORD(current_entry, CONSOLE_PROCESS_DATA, ConsoleLink);
|
|
|
|
|
if (++(*ProcessIdsTotal) <= MaxIdListItems)
|
|
|
|
|
{
|
|
|
|
|
*ProcessIdsList++ = HandleToUlong(current->Process->ClientId.UniqueProcess);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ConSrvGenerateConsoleCtrlEvent
|
|
|
|
|
NTSTATUS NTAPI
|
|
|
|
|
ConSrvConsoleProcessCtrlEvent(IN PCONSOLE Console,
|
|
|
|
|
IN ULONG ProcessGroupId,
|
|
|
|
|
IN ULONG CtrlEvent)
|
|
|
|
|
{
|
|
|
|
|
NTSTATUS Status = STATUS_SUCCESS;
|
|
|
|
|
PLIST_ENTRY current_entry;
|
|
|
|
|
PCONSOLE_PROCESS_DATA current;
|
|
|
|
|
|
|
|
|
|
/* If the console is already being destroyed, just return */
|
|
|
|
|
if (!ConDrvValidateConsoleState(Console, CONSOLE_RUNNING))
|
|
|
|
|
return STATUS_UNSUCCESSFUL;
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Loop through the process list, from the most recent process
|
|
|
|
|
* (the active one) to the oldest one (the first created, i.e.
|
|
|
|
|
* the console leader process), and for each, send an event
|
|
|
|
|
* (new processes are inserted at the head of the console process list).
|
|
|
|
|
*/
|
|
|
|
|
current_entry = Console->ProcessList.Flink;
|
|
|
|
|
while (current_entry != &Console->ProcessList)
|
|
|
|
|
{
|
|
|
|
|
current = CONTAINING_RECORD(current_entry, CONSOLE_PROCESS_DATA, ConsoleLink);
|
|
|
|
|
current_entry = current_entry->Flink;
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Only processes belonging to the same process group are signaled.
|
|
|
|
|
* If the process group ID is zero, then all the processes are signaled.
|
|
|
|
|
*/
|
|
|
|
|
if (ProcessGroupId == 0 || current->Process->ProcessGroupId == ProcessGroupId)
|
|
|
|
|
{
|
|
|
|
|
Status = ConSrvConsoleCtrlEvent(CtrlEvent, current);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return Status;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-03-19 22:05:38 +00:00
|
|
|
|
/* PUBLIC SERVER APIS *********************************************************/
|
|
|
|
|
|
2012-10-22 23:55:51 +00:00
|
|
|
|
CSR_API(SrvAllocConsole)
|
2010-05-31 06:28:55 +00:00
|
|
|
|
{
|
2012-11-18 13:10:03 +00:00
|
|
|
|
NTSTATUS Status = STATUS_SUCCESS;
|
2013-01-05 23:10:12 +00:00
|
|
|
|
PCONSOLE_ALLOCCONSOLE AllocConsoleRequest = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.AllocConsoleRequest;
|
2013-02-10 12:36:57 +00:00
|
|
|
|
PCSR_PROCESS CsrProcess = CsrGetClientThread()->Process;
|
|
|
|
|
PCONSOLE_PROCESS_DATA ProcessData = ConsoleGetPerProcessData(CsrProcess);
|
2010-05-31 06:28:55 +00:00
|
|
|
|
|
2013-07-06 19:47:53 +00:00
|
|
|
|
if (ProcessData->ConsoleHandle != NULL)
|
2010-05-31 06:28:55 +00:00
|
|
|
|
{
|
|
|
|
|
DPRINT1("Process already has a console\n");
|
2013-01-13 17:07:25 +00:00
|
|
|
|
return STATUS_ACCESS_DENIED;
|
2010-05-31 06:28:55 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-03-24 17:08:10 +00:00
|
|
|
|
if (!CsrValidateMessageBuffer(ApiMessage,
|
|
|
|
|
(PVOID*)&AllocConsoleRequest->ConsoleStartInfo,
|
|
|
|
|
1,
|
|
|
|
|
sizeof(CONSOLE_START_INFO)))
|
2013-02-10 12:36:57 +00:00
|
|
|
|
{
|
|
|
|
|
return STATUS_INVALID_PARAMETER;
|
|
|
|
|
}
|
|
|
|
|
|
2013-01-04 00:41:10 +00:00
|
|
|
|
/* Initialize a new Console owned by the Console Leader Process */
|
2013-01-24 22:41:33 +00:00
|
|
|
|
Status = ConSrvAllocateConsole(ProcessData,
|
2013-02-01 23:36:23 +00:00
|
|
|
|
&AllocConsoleRequest->InputHandle,
|
|
|
|
|
&AllocConsoleRequest->OutputHandle,
|
|
|
|
|
&AllocConsoleRequest->ErrorHandle,
|
[CONSOLE.DLL-KERNEL32-CONSRV]
Fix the console properties dialog, when launching and transmitting console properties. Before, the properties dialog was directly launched by the console server (consrv), running with CSRSS (System) privileges, what constituted a security hole. Now, I create a remote thread in the running process owning the console for launching the properties dialog (thus it has only user privileges, and not System ones anymore). For that purpose, I basically took the technique described in the following paper (Cesar Cerrudo, "Story of a dumb patch", http://www.argeniss.com/research/MSBugPaper.pdf or http://www.scn.rain.com/~neighorn/PDF/MSBugPaper.pdf), where basically the console server shares the console properties via a shared memory section with the console properties dialog dll. The address of the thread which launches the dialog in the context of the console app is given to the console server the same way as we do for the control handler (called e.g. when you press Ctrl-C, etc...)
Of course this is quite hackish, because you have the GUI interface split between the console server and the console properties dialog dll. Something far more elegant would be to put all the GUI thingie into a dedicated dll or exe, running with the same privileges as the console program itself (a kind of console -- or terminal -- emulator).
[CONSOLE.DLL]
Fix retriving / setting colors.c and other things.
[CONSRV.DLL]
- Fix retrieving / setting console properties from the registry (via the HKCU\Console\* keys), via the shell shortcuts (not totally done at the moment, because somebody has to implement properly that thing : http://msdn.microsoft.com/en-us/library/windows/desktop/bb773359(v=vs.85).aspx (NT_CONSOLE_PROPS structure stored as a shortcut data block) (at application launching time), and via the console properties dialog.
- Few DPRINTs removed.
svn path=/branches/ros-csrss/; revision=58415
2013-03-03 15:35:12 +00:00
|
|
|
|
AllocConsoleRequest->ConsoleStartInfo);
|
2013-01-02 00:32:20 +00:00
|
|
|
|
if (!NT_SUCCESS(Status))
|
2010-05-31 06:28:55 +00:00
|
|
|
|
{
|
2013-01-16 22:25:12 +00:00
|
|
|
|
DPRINT1("Console allocation failed\n");
|
2013-01-02 00:32:20 +00:00
|
|
|
|
return Status;
|
2010-05-31 06:28:55 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-07-06 19:47:53 +00:00
|
|
|
|
/* Return the console handle and the input wait handle to the caller */
|
|
|
|
|
AllocConsoleRequest->ConsoleHandle = ProcessData->ConsoleHandle;
|
2013-01-02 00:32:20 +00:00
|
|
|
|
AllocConsoleRequest->InputWaitHandle = ProcessData->ConsoleEvent;
|
2010-05-31 06:28:55 +00:00
|
|
|
|
|
2013-07-06 19:47:53 +00:00
|
|
|
|
/* Set the Property-Dialog and Control-Dispatcher handlers */
|
[CONSOLE.DLL-KERNEL32-CONSRV]
Fix the console properties dialog, when launching and transmitting console properties. Before, the properties dialog was directly launched by the console server (consrv), running with CSRSS (System) privileges, what constituted a security hole. Now, I create a remote thread in the running process owning the console for launching the properties dialog (thus it has only user privileges, and not System ones anymore). For that purpose, I basically took the technique described in the following paper (Cesar Cerrudo, "Story of a dumb patch", http://www.argeniss.com/research/MSBugPaper.pdf or http://www.scn.rain.com/~neighorn/PDF/MSBugPaper.pdf), where basically the console server shares the console properties via a shared memory section with the console properties dialog dll. The address of the thread which launches the dialog in the context of the console app is given to the console server the same way as we do for the control handler (called e.g. when you press Ctrl-C, etc...)
Of course this is quite hackish, because you have the GUI interface split between the console server and the console properties dialog dll. Something far more elegant would be to put all the GUI thingie into a dedicated dll or exe, running with the same privileges as the console program itself (a kind of console -- or terminal -- emulator).
[CONSOLE.DLL]
Fix retriving / setting colors.c and other things.
[CONSRV.DLL]
- Fix retrieving / setting console properties from the registry (via the HKCU\Console\* keys), via the shell shortcuts (not totally done at the moment, because somebody has to implement properly that thing : http://msdn.microsoft.com/en-us/library/windows/desktop/bb773359(v=vs.85).aspx (NT_CONSOLE_PROPS structure stored as a shortcut data block) (at application launching time), and via the console properties dialog.
- Few DPRINTs removed.
svn path=/branches/ros-csrss/; revision=58415
2013-03-03 15:35:12 +00:00
|
|
|
|
ProcessData->PropDispatcher = AllocConsoleRequest->PropDispatcher;
|
2012-10-23 22:31:36 +00:00
|
|
|
|
ProcessData->CtrlDispatcher = AllocConsoleRequest->CtrlDispatcher;
|
2010-05-31 06:28:55 +00:00
|
|
|
|
|
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
|
2013-01-13 17:07:25 +00:00
|
|
|
|
CSR_API(SrvAttachConsole)
|
|
|
|
|
{
|
|
|
|
|
NTSTATUS Status = STATUS_SUCCESS;
|
|
|
|
|
PCONSOLE_ATTACHCONSOLE AttachConsoleRequest = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.AttachConsoleRequest;
|
|
|
|
|
PCSR_PROCESS SourceProcess = NULL; // The parent process.
|
|
|
|
|
PCSR_PROCESS TargetProcess = CsrGetClientThread()->Process; // Ourselves.
|
|
|
|
|
HANDLE ProcessId = ULongToHandle(AttachConsoleRequest->ProcessId);
|
|
|
|
|
PCONSOLE_PROCESS_DATA SourceProcessData, TargetProcessData;
|
|
|
|
|
|
|
|
|
|
TargetProcessData = ConsoleGetPerProcessData(TargetProcess);
|
|
|
|
|
|
2013-07-06 19:47:53 +00:00
|
|
|
|
if (TargetProcessData->ConsoleHandle != NULL)
|
2013-01-13 17:07:25 +00:00
|
|
|
|
{
|
|
|
|
|
DPRINT1("Process already has a console\n");
|
|
|
|
|
return STATUS_ACCESS_DENIED;
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-01 23:36:23 +00:00
|
|
|
|
/* Check whether we try to attach to the parent's console */
|
2013-01-13 17:07:25 +00:00
|
|
|
|
if (ProcessId == ULongToHandle(ATTACH_PARENT_PROCESS))
|
|
|
|
|
{
|
|
|
|
|
PROCESS_BASIC_INFORMATION ProcessInfo;
|
|
|
|
|
ULONG Length = sizeof(ProcessInfo);
|
|
|
|
|
|
|
|
|
|
/* Get the real parent's ID */
|
|
|
|
|
|
|
|
|
|
Status = NtQueryInformationProcess(TargetProcess->ProcessHandle,
|
|
|
|
|
ProcessBasicInformation,
|
|
|
|
|
&ProcessInfo,
|
|
|
|
|
Length, &Length);
|
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
|
{
|
|
|
|
|
DPRINT1("SrvAttachConsole - Cannot retrieve basic process info, Status = %lu\n", Status);
|
|
|
|
|
return Status;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ProcessId = ULongToHandle(ProcessInfo.InheritedFromUniqueProcessId);
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-01 23:36:23 +00:00
|
|
|
|
/* Lock the source process via its PID */
|
2013-01-13 17:07:25 +00:00
|
|
|
|
Status = CsrLockProcessByClientId(ProcessId, &SourceProcess);
|
|
|
|
|
if (!NT_SUCCESS(Status)) return Status;
|
|
|
|
|
|
|
|
|
|
SourceProcessData = ConsoleGetPerProcessData(SourceProcess);
|
|
|
|
|
|
2013-07-06 19:47:53 +00:00
|
|
|
|
if (SourceProcessData->ConsoleHandle == NULL)
|
2013-02-01 23:36:23 +00:00
|
|
|
|
{
|
|
|
|
|
Status = STATUS_INVALID_HANDLE;
|
|
|
|
|
goto Quit;
|
|
|
|
|
}
|
|
|
|
|
|
2013-01-13 17:07:25 +00:00
|
|
|
|
/*
|
|
|
|
|
* Inherit the console from the parent,
|
|
|
|
|
* if any, otherwise return an error.
|
|
|
|
|
*/
|
2013-02-01 23:36:23 +00:00
|
|
|
|
Status = ConSrvInheritConsole(TargetProcessData,
|
2013-07-06 19:47:53 +00:00
|
|
|
|
SourceProcessData->ConsoleHandle,
|
2013-02-01 23:36:23 +00:00
|
|
|
|
TRUE,
|
|
|
|
|
&AttachConsoleRequest->InputHandle,
|
|
|
|
|
&AttachConsoleRequest->OutputHandle,
|
|
|
|
|
&AttachConsoleRequest->ErrorHandle);
|
2013-01-13 17:07:25 +00:00
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
|
{
|
2013-02-01 23:36:23 +00:00
|
|
|
|
DPRINT1("Console inheritance failed\n");
|
2013-01-13 17:07:25 +00:00
|
|
|
|
goto Quit;
|
|
|
|
|
}
|
2013-01-16 22:25:12 +00:00
|
|
|
|
|
2013-07-06 19:47:53 +00:00
|
|
|
|
/* Return the console handle and the input wait handle to the caller */
|
|
|
|
|
AttachConsoleRequest->ConsoleHandle = TargetProcessData->ConsoleHandle;
|
2013-01-13 17:07:25 +00:00
|
|
|
|
AttachConsoleRequest->InputWaitHandle = TargetProcessData->ConsoleEvent;
|
|
|
|
|
|
2013-07-06 19:47:53 +00:00
|
|
|
|
/* Set the Property-Dialog and Control-Dispatcher handlers */
|
[CONSOLE.DLL-KERNEL32-CONSRV]
Fix the console properties dialog, when launching and transmitting console properties. Before, the properties dialog was directly launched by the console server (consrv), running with CSRSS (System) privileges, what constituted a security hole. Now, I create a remote thread in the running process owning the console for launching the properties dialog (thus it has only user privileges, and not System ones anymore). For that purpose, I basically took the technique described in the following paper (Cesar Cerrudo, "Story of a dumb patch", http://www.argeniss.com/research/MSBugPaper.pdf or http://www.scn.rain.com/~neighorn/PDF/MSBugPaper.pdf), where basically the console server shares the console properties via a shared memory section with the console properties dialog dll. The address of the thread which launches the dialog in the context of the console app is given to the console server the same way as we do for the control handler (called e.g. when you press Ctrl-C, etc...)
Of course this is quite hackish, because you have the GUI interface split between the console server and the console properties dialog dll. Something far more elegant would be to put all the GUI thingie into a dedicated dll or exe, running with the same privileges as the console program itself (a kind of console -- or terminal -- emulator).
[CONSOLE.DLL]
Fix retriving / setting colors.c and other things.
[CONSRV.DLL]
- Fix retrieving / setting console properties from the registry (via the HKCU\Console\* keys), via the shell shortcuts (not totally done at the moment, because somebody has to implement properly that thing : http://msdn.microsoft.com/en-us/library/windows/desktop/bb773359(v=vs.85).aspx (NT_CONSOLE_PROPS structure stored as a shortcut data block) (at application launching time), and via the console properties dialog.
- Few DPRINTs removed.
svn path=/branches/ros-csrss/; revision=58415
2013-03-03 15:35:12 +00:00
|
|
|
|
TargetProcessData->PropDispatcher = AttachConsoleRequest->PropDispatcher;
|
2013-01-13 17:07:25 +00:00
|
|
|
|
TargetProcessData->CtrlDispatcher = AttachConsoleRequest->CtrlDispatcher;
|
|
|
|
|
|
|
|
|
|
Status = STATUS_SUCCESS;
|
|
|
|
|
|
|
|
|
|
Quit:
|
2013-02-01 23:36:23 +00:00
|
|
|
|
/* Unlock the "source" process and exit */
|
2013-01-13 17:07:25 +00:00
|
|
|
|
CsrUnlockProcess(SourceProcess);
|
|
|
|
|
return Status;
|
|
|
|
|
}
|
|
|
|
|
|
2012-10-22 23:55:51 +00:00
|
|
|
|
CSR_API(SrvFreeConsole)
|
2010-05-31 06:28:55 +00:00
|
|
|
|
{
|
2013-01-24 22:41:33 +00:00
|
|
|
|
ConSrvRemoveConsole(ConsoleGetPerProcessData(CsrGetClientThread()->Process));
|
2012-02-19 06:44:09 +00:00
|
|
|
|
return STATUS_SUCCESS;
|
2010-05-31 06:28:55 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-06-23 00:18:47 +00:00
|
|
|
|
NTSTATUS NTAPI
|
|
|
|
|
ConDrvGetConsoleMode(IN PCONSOLE Console,
|
|
|
|
|
IN PCONSOLE_IO_OBJECT Object,
|
|
|
|
|
OUT PULONG ConsoleMode);
|
2013-04-07 23:39:39 +00:00
|
|
|
|
CSR_API(SrvGetConsoleMode)
|
|
|
|
|
{
|
|
|
|
|
NTSTATUS Status;
|
|
|
|
|
PCONSOLE_GETSETCONSOLEMODE ConsoleModeRequest = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.ConsoleModeRequest;
|
2013-06-23 00:18:47 +00:00
|
|
|
|
PCONSOLE_IO_OBJECT Object;
|
2013-04-07 23:39:39 +00:00
|
|
|
|
|
|
|
|
|
Status = ConSrvGetObject(ConsoleGetPerProcessData(CsrGetClientThread()->Process),
|
2014-04-20 11:25:38 +00:00
|
|
|
|
ConsoleModeRequest->Handle,
|
2013-04-07 23:39:39 +00:00
|
|
|
|
&Object, NULL, GENERIC_READ, TRUE, 0);
|
|
|
|
|
if (!NT_SUCCESS(Status)) return Status;
|
|
|
|
|
|
2013-06-23 00:18:47 +00:00
|
|
|
|
Status = ConDrvGetConsoleMode(Object->Console, Object,
|
2014-04-20 11:25:38 +00:00
|
|
|
|
&ConsoleModeRequest->Mode);
|
2013-04-07 23:39:39 +00:00
|
|
|
|
|
|
|
|
|
ConSrvReleaseObject(Object, TRUE);
|
|
|
|
|
return Status;
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-23 00:18:47 +00:00
|
|
|
|
NTSTATUS NTAPI
|
|
|
|
|
ConDrvSetConsoleMode(IN PCONSOLE Console,
|
|
|
|
|
IN PCONSOLE_IO_OBJECT Object,
|
|
|
|
|
IN ULONG ConsoleMode);
|
2012-10-22 23:55:51 +00:00
|
|
|
|
CSR_API(SrvSetConsoleMode)
|
2010-05-31 06:28:55 +00:00
|
|
|
|
{
|
|
|
|
|
NTSTATUS Status;
|
2013-01-05 23:10:12 +00:00
|
|
|
|
PCONSOLE_GETSETCONSOLEMODE ConsoleModeRequest = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.ConsoleModeRequest;
|
2013-06-23 00:18:47 +00:00
|
|
|
|
PCONSOLE_IO_OBJECT Object;
|
2010-05-31 06:28:55 +00:00
|
|
|
|
|
2013-01-24 22:41:33 +00:00
|
|
|
|
Status = ConSrvGetObject(ConsoleGetPerProcessData(CsrGetClientThread()->Process),
|
2014-04-20 11:25:38 +00:00
|
|
|
|
ConsoleModeRequest->Handle,
|
2013-04-01 00:23:34 +00:00
|
|
|
|
&Object, NULL, GENERIC_WRITE, TRUE, 0);
|
2012-11-17 23:07:59 +00:00
|
|
|
|
if (!NT_SUCCESS(Status)) return Status;
|
2010-05-31 06:28:55 +00:00
|
|
|
|
|
2013-06-23 00:18:47 +00:00
|
|
|
|
Status = ConDrvSetConsoleMode(Object->Console, Object,
|
2014-04-20 11:25:38 +00:00
|
|
|
|
ConsoleModeRequest->Mode);
|
2012-11-17 23:07:59 +00:00
|
|
|
|
|
2013-01-24 22:41:33 +00:00
|
|
|
|
ConSrvReleaseObject(Object, TRUE);
|
2010-05-31 06:28:55 +00:00
|
|
|
|
return Status;
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-23 00:18:47 +00:00
|
|
|
|
NTSTATUS NTAPI
|
|
|
|
|
ConDrvGetConsoleTitle(IN PCONSOLE Console,
|
2014-04-20 11:25:38 +00:00
|
|
|
|
IN BOOLEAN Unicode,
|
|
|
|
|
IN OUT PVOID TitleBuffer,
|
2013-06-23 00:18:47 +00:00
|
|
|
|
IN OUT PULONG BufLength);
|
2013-04-07 23:39:39 +00:00
|
|
|
|
CSR_API(SrvGetConsoleTitle)
|
2010-05-31 06:28:55 +00:00
|
|
|
|
{
|
|
|
|
|
NTSTATUS Status;
|
2013-04-07 23:39:39 +00:00
|
|
|
|
PCONSOLE_GETSETCONSOLETITLE TitleRequest = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.TitleRequest;
|
|
|
|
|
PCONSOLE Console;
|
2012-11-17 23:07:59 +00:00
|
|
|
|
|
2013-04-07 23:39:39 +00:00
|
|
|
|
if (!CsrValidateMessageBuffer(ApiMessage,
|
|
|
|
|
(PVOID)&TitleRequest->Title,
|
|
|
|
|
TitleRequest->Length,
|
|
|
|
|
sizeof(BYTE)))
|
2010-05-31 06:28:55 +00:00
|
|
|
|
{
|
2013-04-07 23:39:39 +00:00
|
|
|
|
return STATUS_INVALID_PARAMETER;
|
2010-05-31 06:28:55 +00:00
|
|
|
|
}
|
2013-04-07 23:39:39 +00:00
|
|
|
|
|
|
|
|
|
Status = ConSrvGetConsole(ConsoleGetPerProcessData(CsrGetClientThread()->Process), &Console, TRUE);
|
|
|
|
|
if (!NT_SUCCESS(Status))
|
2010-05-31 06:28:55 +00:00
|
|
|
|
{
|
2013-04-07 23:39:39 +00:00
|
|
|
|
DPRINT1("Can't get console\n");
|
|
|
|
|
return Status;
|
2010-05-31 06:28:55 +00:00
|
|
|
|
}
|
2013-04-07 23:39:39 +00:00
|
|
|
|
|
2013-06-23 00:18:47 +00:00
|
|
|
|
Status = ConDrvGetConsoleTitle(Console,
|
2014-04-20 11:25:38 +00:00
|
|
|
|
TitleRequest->Unicode,
|
2013-06-23 00:18:47 +00:00
|
|
|
|
TitleRequest->Title,
|
|
|
|
|
&TitleRequest->Length);
|
2013-04-07 23:39:39 +00:00
|
|
|
|
|
|
|
|
|
ConSrvReleaseConsole(Console, TRUE);
|
2013-06-23 00:18:47 +00:00
|
|
|
|
return Status;
|
2010-05-31 06:28:55 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-06-23 00:18:47 +00:00
|
|
|
|
NTSTATUS NTAPI
|
|
|
|
|
ConDrvSetConsoleTitle(IN PCONSOLE Console,
|
2014-04-20 11:25:38 +00:00
|
|
|
|
IN BOOLEAN Unicode,
|
|
|
|
|
IN PVOID TitleBuffer,
|
2013-06-23 00:18:47 +00:00
|
|
|
|
IN ULONG BufLength);
|
2012-10-22 23:55:51 +00:00
|
|
|
|
CSR_API(SrvSetConsoleTitle)
|
2010-05-31 06:28:55 +00:00
|
|
|
|
{
|
|
|
|
|
NTSTATUS Status;
|
2013-01-05 23:10:12 +00:00
|
|
|
|
PCONSOLE_GETSETCONSOLETITLE TitleRequest = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.TitleRequest;
|
2013-01-05 23:37:04 +00:00
|
|
|
|
PCONSOLE Console;
|
2010-05-31 06:28:55 +00:00
|
|
|
|
|
2012-11-18 13:10:03 +00:00
|
|
|
|
if (!CsrValidateMessageBuffer(ApiMessage,
|
|
|
|
|
(PVOID)&TitleRequest->Title,
|
|
|
|
|
TitleRequest->Length,
|
|
|
|
|
sizeof(BYTE)))
|
|
|
|
|
{
|
|
|
|
|
return STATUS_INVALID_PARAMETER;
|
|
|
|
|
}
|
2010-05-31 06:28:55 +00:00
|
|
|
|
|
2013-01-24 22:41:33 +00:00
|
|
|
|
Status = ConSrvGetConsole(ConsoleGetPerProcessData(CsrGetClientThread()->Process), &Console, TRUE);
|
2013-02-10 12:36:57 +00:00
|
|
|
|
if (!NT_SUCCESS(Status))
|
2010-05-31 06:28:55 +00:00
|
|
|
|
{
|
2013-02-10 12:36:57 +00:00
|
|
|
|
DPRINT1("Can't get console\n");
|
|
|
|
|
return Status;
|
|
|
|
|
}
|
2012-11-18 13:10:03 +00:00
|
|
|
|
|
2013-06-23 00:18:47 +00:00
|
|
|
|
Status = ConDrvSetConsoleTitle(Console,
|
2014-04-20 11:25:38 +00:00
|
|
|
|
TitleRequest->Unicode,
|
2013-06-23 00:18:47 +00:00
|
|
|
|
TitleRequest->Title,
|
|
|
|
|
TitleRequest->Length);
|
2013-10-10 01:16:02 +00:00
|
|
|
|
if (NT_SUCCESS(Status)) TermChangeTitle(Console);
|
2012-11-18 13:10:03 +00:00
|
|
|
|
|
2013-01-24 22:41:33 +00:00
|
|
|
|
ConSrvReleaseConsole(Console, TRUE);
|
2010-05-31 06:28:55 +00:00
|
|
|
|
return Status;
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-23 00:18:47 +00:00
|
|
|
|
NTSTATUS NTAPI
|
|
|
|
|
ConDrvGetConsoleCP(IN PCONSOLE Console,
|
|
|
|
|
OUT PUINT CodePage,
|
2014-03-08 15:31:05 +00:00
|
|
|
|
IN BOOLEAN OutputCP);
|
2012-10-22 23:55:51 +00:00
|
|
|
|
CSR_API(SrvGetConsoleCP)
|
2010-05-31 06:28:55 +00:00
|
|
|
|
{
|
|
|
|
|
NTSTATUS Status;
|
2014-03-08 15:31:05 +00:00
|
|
|
|
PCONSOLE_GETINPUTOUTPUTCP GetConsoleCPRequest = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.GetConsoleCPRequest;
|
2013-01-05 23:37:04 +00:00
|
|
|
|
PCONSOLE Console;
|
2010-05-31 06:28:55 +00:00
|
|
|
|
|
2012-11-18 13:10:03 +00:00
|
|
|
|
DPRINT("SrvGetConsoleCP, getting %s Code Page\n",
|
2014-03-08 15:31:05 +00:00
|
|
|
|
GetConsoleCPRequest->OutputCP ? "Output" : "Input");
|
2010-05-31 06:28:55 +00:00
|
|
|
|
|
2013-01-24 22:41:33 +00:00
|
|
|
|
Status = ConSrvGetConsole(ConsoleGetPerProcessData(CsrGetClientThread()->Process), &Console, TRUE);
|
2012-11-18 13:10:03 +00:00
|
|
|
|
if (!NT_SUCCESS(Status)) return Status;
|
2010-05-31 06:28:55 +00:00
|
|
|
|
|
2013-06-23 00:18:47 +00:00
|
|
|
|
Status = ConDrvGetConsoleCP(Console,
|
2014-03-08 15:31:05 +00:00
|
|
|
|
&GetConsoleCPRequest->CodePage,
|
|
|
|
|
GetConsoleCPRequest->OutputCP);
|
2013-06-23 00:18:47 +00:00
|
|
|
|
|
2013-01-24 22:41:33 +00:00
|
|
|
|
ConSrvReleaseConsole(Console, TRUE);
|
2013-06-23 00:18:47 +00:00
|
|
|
|
return Status;
|
2010-05-31 06:28:55 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-06-23 00:18:47 +00:00
|
|
|
|
NTSTATUS NTAPI
|
|
|
|
|
ConDrvSetConsoleCP(IN PCONSOLE Console,
|
|
|
|
|
IN UINT CodePage,
|
2014-03-08 15:31:05 +00:00
|
|
|
|
IN BOOLEAN OutputCP);
|
2012-10-22 23:55:51 +00:00
|
|
|
|
CSR_API(SrvSetConsoleCP)
|
2010-05-31 06:28:55 +00:00
|
|
|
|
{
|
2013-06-23 00:18:47 +00:00
|
|
|
|
NTSTATUS Status = STATUS_INVALID_PARAMETER;
|
2014-03-08 15:31:05 +00:00
|
|
|
|
PCONSOLE_SETINPUTOUTPUTCP SetConsoleCPRequest = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.SetConsoleCPRequest;
|
2013-01-05 23:37:04 +00:00
|
|
|
|
PCONSOLE Console;
|
2010-05-31 06:28:55 +00:00
|
|
|
|
|
2012-11-18 13:10:03 +00:00
|
|
|
|
DPRINT("SrvSetConsoleCP, setting %s Code Page\n",
|
2014-03-08 15:31:05 +00:00
|
|
|
|
SetConsoleCPRequest->OutputCP ? "Output" : "Input");
|
2010-05-31 06:28:55 +00:00
|
|
|
|
|
2013-01-24 22:41:33 +00:00
|
|
|
|
Status = ConSrvGetConsole(ConsoleGetPerProcessData(CsrGetClientThread()->Process), &Console, TRUE);
|
2012-11-18 13:10:03 +00:00
|
|
|
|
if (!NT_SUCCESS(Status)) return Status;
|
2010-05-31 06:28:55 +00:00
|
|
|
|
|
2013-06-23 00:18:47 +00:00
|
|
|
|
Status = ConDrvSetConsoleCP(Console,
|
2014-03-08 15:31:05 +00:00
|
|
|
|
SetConsoleCPRequest->CodePage,
|
|
|
|
|
SetConsoleCPRequest->OutputCP);
|
2010-05-31 06:28:55 +00:00
|
|
|
|
|
2013-01-24 22:41:33 +00:00
|
|
|
|
ConSrvReleaseConsole(Console, TRUE);
|
2013-06-23 00:18:47 +00:00
|
|
|
|
return Status;
|
2010-05-31 06:28:55 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-10-22 23:55:51 +00:00
|
|
|
|
CSR_API(SrvGetConsoleProcessList)
|
2010-05-31 06:28:55 +00:00
|
|
|
|
{
|
2012-11-18 13:10:03 +00:00
|
|
|
|
NTSTATUS Status;
|
2013-01-05 23:10:12 +00:00
|
|
|
|
PCONSOLE_GETPROCESSLIST GetProcessListRequest = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.GetProcessListRequest;
|
2013-01-05 23:37:04 +00:00
|
|
|
|
PCONSOLE Console;
|
2010-05-31 06:28:55 +00:00
|
|
|
|
|
2012-11-18 13:10:03 +00:00
|
|
|
|
if (!CsrValidateMessageBuffer(ApiMessage,
|
2014-03-08 15:31:05 +00:00
|
|
|
|
(PVOID)&GetProcessListRequest->ProcessIdsList,
|
|
|
|
|
GetProcessListRequest->ProcessCount,
|
2012-11-18 13:10:03 +00:00
|
|
|
|
sizeof(DWORD)))
|
|
|
|
|
{
|
|
|
|
|
return STATUS_INVALID_PARAMETER;
|
|
|
|
|
}
|
|
|
|
|
|
2013-01-24 22:41:33 +00:00
|
|
|
|
Status = ConSrvGetConsole(ConsoleGetPerProcessData(CsrGetClientThread()->Process), &Console, TRUE);
|
2012-11-18 13:10:03 +00:00
|
|
|
|
if (!NT_SUCCESS(Status)) return Status;
|
2010-05-31 06:28:55 +00:00
|
|
|
|
|
2014-05-02 16:46:13 +00:00
|
|
|
|
Status = ConSrvGetConsoleProcessList(Console,
|
2014-03-08 15:31:05 +00:00
|
|
|
|
GetProcessListRequest->ProcessIdsList,
|
|
|
|
|
GetProcessListRequest->ProcessCount,
|
|
|
|
|
&GetProcessListRequest->ProcessCount);
|
2010-05-31 06:28:55 +00:00
|
|
|
|
|
2013-01-24 22:41:33 +00:00
|
|
|
|
ConSrvReleaseConsole(Console, TRUE);
|
2013-06-23 00:18:47 +00:00
|
|
|
|
return Status;
|
2010-05-31 06:28:55 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-10-22 23:55:51 +00:00
|
|
|
|
CSR_API(SrvGenerateConsoleCtrlEvent)
|
2010-05-31 06:28:55 +00:00
|
|
|
|
{
|
2012-11-18 13:10:03 +00:00
|
|
|
|
NTSTATUS Status;
|
2013-01-05 23:10:12 +00:00
|
|
|
|
PCONSOLE_GENERATECTRLEVENT GenerateCtrlEventRequest = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.GenerateCtrlEventRequest;
|
2013-01-05 23:37:04 +00:00
|
|
|
|
PCONSOLE Console;
|
2010-05-31 06:28:55 +00:00
|
|
|
|
|
2013-01-24 22:41:33 +00:00
|
|
|
|
Status = ConSrvGetConsole(ConsoleGetPerProcessData(CsrGetClientThread()->Process), &Console, TRUE);
|
2012-11-18 13:10:03 +00:00
|
|
|
|
if (!NT_SUCCESS(Status)) return Status;
|
2010-05-31 06:28:55 +00:00
|
|
|
|
|
2014-05-02 16:46:13 +00:00
|
|
|
|
Status = ConSrvConsoleProcessCtrlEvent(Console,
|
2014-04-20 11:25:38 +00:00
|
|
|
|
GenerateCtrlEventRequest->ProcessGroupId,
|
|
|
|
|
GenerateCtrlEventRequest->CtrlEvent);
|
2010-05-31 06:28:55 +00:00
|
|
|
|
|
2013-01-24 22:41:33 +00:00
|
|
|
|
ConSrvReleaseConsole(Console, TRUE);
|
2010-05-31 06:28:55 +00:00
|
|
|
|
return Status;
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-30 17:53:45 +00:00
|
|
|
|
CSR_API(SrvConsoleNotifyLastClose)
|
|
|
|
|
{
|
2014-04-21 01:22:17 +00:00
|
|
|
|
NTSTATUS Status;
|
|
|
|
|
PCONSOLE_PROCESS_DATA ProcessData = ConsoleGetPerProcessData(CsrGetClientThread()->Process);
|
|
|
|
|
PCONSOLE Console;
|
|
|
|
|
|
|
|
|
|
Status = ConSrvGetConsole(ProcessData, &Console, TRUE);
|
|
|
|
|
if (!NT_SUCCESS(Status)) return Status;
|
|
|
|
|
|
|
|
|
|
/* Only one process is allowed to be registered for last close notification */
|
|
|
|
|
if (!Console->NotifyLastClose)
|
|
|
|
|
{
|
|
|
|
|
Console->NotifyLastClose = TRUE;
|
2014-04-22 00:47:24 +00:00
|
|
|
|
Console->NotifiedLastCloseProcess = ProcessData;
|
2014-04-21 01:22:17 +00:00
|
|
|
|
Status = STATUS_SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Status = STATUS_ACCESS_DENIED;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ConSrvReleaseConsole(Console, TRUE);
|
|
|
|
|
return Status;
|
2013-08-30 17:53:45 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CSR_API(SrvGetConsoleMouseInfo)
|
|
|
|
|
{
|
|
|
|
|
DPRINT1("%s not yet implemented\n", __FUNCTION__);
|
|
|
|
|
return STATUS_NOT_IMPLEMENTED;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CSR_API(SrvSetConsoleKeyShortcuts)
|
|
|
|
|
{
|
|
|
|
|
DPRINT1("%s not yet implemented\n", __FUNCTION__);
|
|
|
|
|
return STATUS_NOT_IMPLEMENTED;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CSR_API(SrvGetConsoleKeyboardLayoutName)
|
|
|
|
|
{
|
|
|
|
|
DPRINT1("%s not yet implemented\n", __FUNCTION__);
|
|
|
|
|
return STATUS_NOT_IMPLEMENTED;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CSR_API(SrvGetConsoleCharType)
|
|
|
|
|
{
|
|
|
|
|
DPRINT1("%s not yet implemented\n", __FUNCTION__);
|
|
|
|
|
return STATUS_NOT_IMPLEMENTED;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CSR_API(SrvSetConsoleLocalEUDC)
|
|
|
|
|
{
|
|
|
|
|
DPRINT1("%s not yet implemented\n", __FUNCTION__);
|
|
|
|
|
return STATUS_NOT_IMPLEMENTED;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CSR_API(SrvSetConsoleCursorMode)
|
|
|
|
|
{
|
|
|
|
|
DPRINT1("%s not yet implemented\n", __FUNCTION__);
|
|
|
|
|
return STATUS_NOT_IMPLEMENTED;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CSR_API(SrvGetConsoleCursorMode)
|
|
|
|
|
{
|
|
|
|
|
DPRINT1("%s not yet implemented\n", __FUNCTION__);
|
|
|
|
|
return STATUS_NOT_IMPLEMENTED;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CSR_API(SrvGetConsoleNlsMode)
|
|
|
|
|
{
|
|
|
|
|
DPRINT1("%s not yet implemented\n", __FUNCTION__);
|
|
|
|
|
return STATUS_NOT_IMPLEMENTED;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CSR_API(SrvSetConsoleNlsMode)
|
|
|
|
|
{
|
|
|
|
|
DPRINT1("%s not yet implemented\n", __FUNCTION__);
|
|
|
|
|
return STATUS_NOT_IMPLEMENTED;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CSR_API(SrvGetConsoleLangId)
|
|
|
|
|
{
|
|
|
|
|
DPRINT1("%s not yet implemented\n", __FUNCTION__);
|
|
|
|
|
return STATUS_NOT_IMPLEMENTED;
|
|
|
|
|
}
|
|
|
|
|
|
2010-05-31 06:28:55 +00:00
|
|
|
|
/* EOF */
|