[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
|
|
|
/*
|
|
|
|
* COPYRIGHT: See COPYING in the top level directory
|
|
|
|
* PROJECT: ReactOS Console Server DLL
|
2015-10-05 12:21:25 +00:00
|
|
|
* FILE: win32ss/user/winsrv/consrv/settings.c
|
2013-04-07 23:18:59 +00:00
|
|
|
* PURPOSE: Console settings management
|
2013-04-10 20:22:30 +00:00
|
|
|
* PROGRAMMERS: Johannes Anderwald
|
|
|
|
* Hermes Belusca-Maito (hermes.belusca@sfr.fr)
|
[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
|
|
|
*/
|
|
|
|
|
|
|
|
/* INCLUDES *******************************************************************/
|
|
|
|
|
|
|
|
#include "consrv.h"
|
2020-02-29 16:35:57 +00:00
|
|
|
#include "history.h"
|
2020-01-07 06:26:58 +00:00
|
|
|
#include "../concfg/font.h"
|
[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
|
|
|
|
|
|
|
#define NDEBUG
|
|
|
|
#include <debug.h>
|
|
|
|
|
|
|
|
/* GLOBALS ********************************************************************/
|
|
|
|
|
|
|
|
extern const COLORREF s_Colors[16];
|
|
|
|
|
|
|
|
|
|
|
|
/* FUNCTIONS ******************************************************************/
|
|
|
|
|
2014-03-15 17:15:23 +00:00
|
|
|
NTSTATUS NTAPI
|
|
|
|
ConDrvChangeScreenBufferAttributes(IN PCONSOLE Console,
|
|
|
|
IN PTEXTMODE_SCREEN_BUFFER Buffer,
|
|
|
|
IN USHORT NewScreenAttrib,
|
|
|
|
IN USHORT NewPopupAttrib);
|
2013-10-10 01:16:02 +00:00
|
|
|
/*
|
2020-04-10 18:37:28 +00:00
|
|
|
* NOTE: This function explicitly references Console->ActiveBuffer.
|
2013-10-10 01:16:02 +00:00
|
|
|
* It is possible that it should go into some frontend...
|
|
|
|
*/
|
2013-03-24 17:08:10 +00:00
|
|
|
VOID
|
2020-04-10 18:37:28 +00:00
|
|
|
ConSrvApplyUserSettings(
|
|
|
|
IN PCONSRV_CONSOLE Console,
|
|
|
|
IN PCONSOLE_STATE_INFO ConsoleInfo)
|
2013-03-24 17:08:10 +00:00
|
|
|
{
|
|
|
|
PCONSOLE_SCREEN_BUFFER ActiveBuffer = Console->ActiveBuffer;
|
2013-04-01 17:26:53 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Apply terminal-edition settings:
|
|
|
|
* - QuickEdit and Insert modes,
|
2020-02-29 16:35:57 +00:00
|
|
|
* - History settings.
|
2013-04-01 17:26:53 +00:00
|
|
|
*/
|
2015-03-24 23:58:44 +00:00
|
|
|
Console->QuickEdit = !!ConsoleInfo->QuickEdit;
|
|
|
|
Console->InsertMode = !!ConsoleInfo->InsertMode;
|
2020-02-29 16:35:57 +00:00
|
|
|
/// Console->InputBufferSize = 0;
|
|
|
|
HistoryReshapeAllBuffers(Console,
|
|
|
|
ConsoleInfo->HistoryBufferSize,
|
|
|
|
ConsoleInfo->NumberOfHistoryBuffers,
|
|
|
|
ConsoleInfo->HistoryNoDup);
|
2013-04-01 17:26:53 +00:00
|
|
|
|
2014-03-15 17:15:23 +00:00
|
|
|
/* Copy the new console palette */
|
2015-03-24 23:58:44 +00:00
|
|
|
// FIXME: Possible buffer overflow if s_colors is bigger than ConsoleInfo->ColorTable.
|
|
|
|
RtlCopyMemory(Console->Colors, ConsoleInfo->ColorTable, sizeof(s_Colors));
|
2013-03-24 17:08:10 +00:00
|
|
|
|
|
|
|
/* Apply cursor size */
|
|
|
|
ActiveBuffer->CursorInfo.bVisible = (ConsoleInfo->CursorSize != 0);
|
|
|
|
ActiveBuffer->CursorInfo.dwSize = min(max(ConsoleInfo->CursorSize, 0), 100);
|
|
|
|
|
2017-04-24 00:24:34 +00:00
|
|
|
/* Update the code page */
|
|
|
|
if ((Console->OutputCodePage != ConsoleInfo->CodePage) &&
|
|
|
|
IsValidCodePage(ConsoleInfo->CodePage))
|
|
|
|
{
|
|
|
|
// ConDrvSetConsoleCP(Console, ConsoleInfo->CodePage, TRUE); // Output
|
|
|
|
// ConDrvSetConsoleCP(Console, ConsoleInfo->CodePage, FALSE); // Input
|
2021-07-03 22:41:33 +00:00
|
|
|
if (TermSetCodePage(Console, ConsoleInfo->CodePage))
|
|
|
|
{
|
2022-01-27 20:36:16 +00:00
|
|
|
CON_SET_OUTPUT_CP(Console, ConsoleInfo->CodePage);
|
|
|
|
Console->InputCodePage = ConsoleInfo->CodePage;
|
2021-07-03 22:41:33 +00:00
|
|
|
}
|
2017-04-24 00:24:34 +00:00
|
|
|
}
|
|
|
|
|
2016-10-18 23:51:59 +00:00
|
|
|
// FIXME: Check ConsoleInfo->WindowSize with respect to
|
|
|
|
// TermGetLargestConsoleWindowSize(...).
|
|
|
|
|
2013-05-29 00:29:07 +00:00
|
|
|
if (GetType(ActiveBuffer) == TEXTMODE_BUFFER)
|
2013-03-24 17:08:10 +00:00
|
|
|
{
|
2013-05-29 00:29:07 +00:00
|
|
|
/* Resize its active screen-buffer */
|
2019-05-25 22:00:39 +00:00
|
|
|
PTEXTMODE_SCREEN_BUFFER Buffer = (PTEXTMODE_SCREEN_BUFFER)ActiveBuffer;
|
|
|
|
COORD BufSize = ConsoleInfo->ScreenBufferSize;
|
2013-05-29 00:29:07 +00:00
|
|
|
|
|
|
|
if (Console->FixedSize)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* The console is in fixed-size mode, so we cannot resize anything
|
|
|
|
* at the moment. However, keep those settings somewhere so that
|
|
|
|
* we can try to set them up when we will be allowed to do so.
|
|
|
|
*/
|
2019-05-25 22:00:39 +00:00
|
|
|
if (ConsoleInfo->WindowSize.X != ActiveBuffer->OldViewSize.X ||
|
|
|
|
ConsoleInfo->WindowSize.Y != ActiveBuffer->OldViewSize.Y)
|
2013-05-29 00:29:07 +00:00
|
|
|
{
|
2019-05-25 22:00:39 +00:00
|
|
|
ActiveBuffer->OldViewSize = ConsoleInfo->WindowSize;
|
2013-05-29 00:29:07 +00:00
|
|
|
}
|
|
|
|
|
2019-05-25 22:00:39 +00:00
|
|
|
/* The buffer size is not allowed to be smaller than the view size */
|
|
|
|
if (BufSize.X >= ActiveBuffer->OldViewSize.X && BufSize.Y >= ActiveBuffer->OldViewSize.Y)
|
2013-05-29 00:29:07 +00:00
|
|
|
{
|
2019-05-25 22:00:39 +00:00
|
|
|
if (BufSize.X != ActiveBuffer->OldScreenBufferSize.X ||
|
|
|
|
BufSize.Y != ActiveBuffer->OldScreenBufferSize.Y)
|
2013-05-29 00:29:07 +00:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
* The console is in fixed-size mode, so we cannot resize anything
|
|
|
|
* at the moment. However, keep those settings somewhere so that
|
|
|
|
* we can try to set them up when we will be allowed to do so.
|
|
|
|
*/
|
2019-05-25 22:00:39 +00:00
|
|
|
ActiveBuffer->OldScreenBufferSize = BufSize;
|
2013-05-29 00:29:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
BOOL SizeChanged = FALSE;
|
|
|
|
|
|
|
|
/* Resize the console */
|
2019-05-25 22:00:39 +00:00
|
|
|
if (ConsoleInfo->WindowSize.X != ActiveBuffer->ViewSize.X ||
|
|
|
|
ConsoleInfo->WindowSize.Y != ActiveBuffer->ViewSize.Y)
|
2013-05-29 00:29:07 +00:00
|
|
|
{
|
2019-05-25 22:00:39 +00:00
|
|
|
ActiveBuffer->ViewSize = ConsoleInfo->WindowSize;
|
2013-05-29 00:29:07 +00:00
|
|
|
SizeChanged = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Resize the screen-buffer */
|
2019-05-25 22:00:39 +00:00
|
|
|
if (BufSize.X != ActiveBuffer->ScreenBufferSize.X ||
|
|
|
|
BufSize.Y != ActiveBuffer->ScreenBufferSize.Y)
|
2013-05-29 00:29:07 +00:00
|
|
|
{
|
2020-04-10 18:37:28 +00:00
|
|
|
if (NT_SUCCESS(ConioResizeBuffer((PCONSOLE)Console, Buffer, BufSize)))
|
2013-05-29 00:29:07 +00:00
|
|
|
SizeChanged = TRUE;
|
|
|
|
}
|
|
|
|
|
2013-10-10 01:16:02 +00:00
|
|
|
if (SizeChanged) TermResizeTerminal(Console);
|
2013-05-29 00:29:07 +00:00
|
|
|
}
|
2014-03-15 17:15:23 +00:00
|
|
|
|
|
|
|
/* Apply foreground and background colors for both screen and popup */
|
2020-04-10 18:37:28 +00:00
|
|
|
ConDrvChangeScreenBufferAttributes((PCONSOLE)Console,
|
2014-03-15 17:15:23 +00:00
|
|
|
Buffer,
|
2015-03-24 23:58:44 +00:00
|
|
|
ConsoleInfo->ScreenAttributes,
|
|
|
|
ConsoleInfo->PopupAttributes);
|
2013-03-24 17:08:10 +00:00
|
|
|
}
|
2013-05-29 00:29:07 +00:00
|
|
|
else // if (GetType(ActiveBuffer) == GRAPHICS_BUFFER)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* In any case we do NOT modify the size of the graphics screen-buffer.
|
|
|
|
* We just allow resizing the view only if the new size is smaller
|
|
|
|
* than the older one.
|
|
|
|
*/
|
|
|
|
if (Console->FixedSize)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* The console is in fixed-size mode, so we cannot resize anything
|
|
|
|
* at the moment. However, keep those settings somewhere so that
|
|
|
|
* we can try to set them up when we will be allowed to do so.
|
|
|
|
*/
|
2019-05-25 22:00:39 +00:00
|
|
|
if (ConsoleInfo->WindowSize.X <= ActiveBuffer->ViewSize.X ||
|
|
|
|
ConsoleInfo->WindowSize.Y <= ActiveBuffer->ViewSize.Y)
|
2013-05-29 00:29:07 +00:00
|
|
|
{
|
2019-05-25 22:00:39 +00:00
|
|
|
ActiveBuffer->OldViewSize = ConsoleInfo->WindowSize;
|
2013-05-29 00:29:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Resize the view if its size is bigger than the specified size */
|
2019-05-25 22:00:39 +00:00
|
|
|
if (ConsoleInfo->WindowSize.X <= ActiveBuffer->ViewSize.X ||
|
|
|
|
ConsoleInfo->WindowSize.Y <= ActiveBuffer->ViewSize.Y)
|
2013-05-29 00:29:07 +00:00
|
|
|
{
|
2019-05-25 22:00:39 +00:00
|
|
|
ActiveBuffer->ViewSize = ConsoleInfo->WindowSize;
|
2013-05-29 00:29:07 +00:00
|
|
|
// SizeChanged = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-03-24 17:08:10 +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
|
|
|
/* EOF */
|