mirror of
https://github.com/reactos/reactos.git
synced 2024-08-20 18:35:32 +00:00
Don't use buffered input when reading username/password in text mode
svn path=/trunk/; revision=23997
This commit is contained in:
parent
4ca190a004
commit
52d59f6a4f
|
@ -33,13 +33,13 @@ TUIDisplayStatusMessage(
|
||||||
TRACE("TUIDisplayStatusMessage(%ws)\n", pMessage);
|
TRACE("TUIDisplayStatusMessage(%ws)\n", pMessage);
|
||||||
|
|
||||||
return
|
return
|
||||||
WriteConsole(
|
WriteConsoleW(
|
||||||
GetStdHandle(STD_OUTPUT_HANDLE),
|
GetStdHandle(STD_OUTPUT_HANDLE),
|
||||||
pMessage,
|
pMessage,
|
||||||
wcslen(pMessage),
|
wcslen(pMessage),
|
||||||
&result,
|
&result,
|
||||||
NULL) &&
|
NULL) &&
|
||||||
WriteConsole(
|
WriteConsoleW(
|
||||||
GetStdHandle(STD_OUTPUT_HANDLE),
|
GetStdHandle(STD_OUTPUT_HANDLE),
|
||||||
newLine,
|
newLine,
|
||||||
wcslen(newLine),
|
wcslen(newLine),
|
||||||
|
@ -66,7 +66,7 @@ DisplayResourceText(
|
||||||
|
|
||||||
if (!LoadStringW(hDllInstance, uIdResourceText, Prompt, 256))
|
if (!LoadStringW(hDllInstance, uIdResourceText, Prompt, 256))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
if (!WriteConsole(
|
if (!WriteConsoleW(
|
||||||
GetStdHandle(STD_OUTPUT_HANDLE),
|
GetStdHandle(STD_OUTPUT_HANDLE),
|
||||||
Prompt, wcslen(Prompt),
|
Prompt, wcslen(Prompt),
|
||||||
&count, NULL))
|
&count, NULL))
|
||||||
|
@ -122,27 +122,64 @@ ReadString(
|
||||||
IN BOOL ShowString)
|
IN BOOL ShowString)
|
||||||
{
|
{
|
||||||
DWORD count, i;
|
DWORD count, i;
|
||||||
|
WCHAR charToDisplay[] = { 0, UNICODE_NULL };
|
||||||
|
|
||||||
if (!SetConsoleMode(
|
if (!SetConsoleMode(GetStdHandle(STD_INPUT_HANDLE), 0))
|
||||||
GetStdHandle(STD_INPUT_HANDLE),
|
return FALSE;
|
||||||
ShowString ? ENABLE_ECHO_INPUT | ENABLE_LINE_INPUT: ENABLE_LINE_INPUT))
|
|
||||||
{
|
if (!FlushConsoleInputBuffer(GetStdHandle(STD_INPUT_HANDLE)))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
|
||||||
|
|
||||||
if (!DisplayResourceText(uIdResourcePrompt, FALSE))
|
if (!DisplayResourceText(uIdResourcePrompt, FALSE))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
i = 0;
|
i = 0;
|
||||||
do
|
for (;;)
|
||||||
{
|
{
|
||||||
if (!ReadConsole(GetStdHandle(STD_INPUT_HANDLE), &Buffer[i], 1, &count, NULL))
|
WCHAR readChar;
|
||||||
|
if (!ReadConsoleW(GetStdHandle(STD_INPUT_HANDLE), &readChar, 1, &count, NULL))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
i++;
|
if (readChar == '\r' || readChar == '\n')
|
||||||
|
{
|
||||||
|
/* End of string */
|
||||||
|
charToDisplay[0] = L'\n';
|
||||||
|
WriteConsoleW(
|
||||||
|
GetStdHandle(STD_OUTPUT_HANDLE),
|
||||||
|
charToDisplay,
|
||||||
|
wcslen(charToDisplay),
|
||||||
|
&count,
|
||||||
|
NULL);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (ShowString)
|
||||||
|
{
|
||||||
|
/* Display the char */
|
||||||
|
charToDisplay[0] = readChar;
|
||||||
|
WriteConsoleW(
|
||||||
|
GetStdHandle(STD_OUTPUT_HANDLE),
|
||||||
|
charToDisplay,
|
||||||
|
wcslen(charToDisplay),
|
||||||
|
&count,
|
||||||
|
NULL);
|
||||||
|
}
|
||||||
|
Buffer[i++] = readChar;
|
||||||
/* FIXME: buffer overflow if the user writes too many chars! */
|
/* FIXME: buffer overflow if the user writes too many chars! */
|
||||||
/* FIXME: handle backspace */
|
/* FIXME: handle backspace */
|
||||||
} while (Buffer[i - 1] != '\n');
|
}
|
||||||
Buffer[i - 1] = 0;
|
Buffer[i] = UNICODE_NULL;
|
||||||
|
|
||||||
|
if (!ShowString)
|
||||||
|
{
|
||||||
|
/* Still display the \n */
|
||||||
|
static LPCWSTR newLine = L"\n";
|
||||||
|
DWORD result;
|
||||||
|
WriteConsoleW(
|
||||||
|
GetStdHandle(STD_OUTPUT_HANDLE),
|
||||||
|
newLine,
|
||||||
|
wcslen(newLine),
|
||||||
|
&result,
|
||||||
|
NULL);
|
||||||
|
}
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue