2006-11-08 11:47:44 +00:00
|
|
|
|
/*
|
|
|
|
|
* PROJECT: ReactOS msgina.dll
|
|
|
|
|
* FILE: dll/win32/msgina/tui.c
|
|
|
|
|
* PURPOSE: ReactOS Logon GINA DLL
|
|
|
|
|
* PROGRAMMER: Herv<EFBFBD> Poussineau (hpoussin@reactos.org)
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "msgina.h"
|
|
|
|
|
|
2014-02-07 17:38:56 +00:00
|
|
|
|
#include <wincon.h>
|
|
|
|
|
|
2006-11-08 11:47:44 +00:00
|
|
|
|
static BOOL
|
|
|
|
|
TUIInitialize(
|
2013-05-06 21:43:03 +00:00
|
|
|
|
IN OUT PGINA_CONTEXT pgContext)
|
2006-11-08 11:47:44 +00:00
|
|
|
|
{
|
2013-05-06 21:43:03 +00:00
|
|
|
|
TRACE("TUIInitialize(%p)\n", pgContext);
|
2006-11-08 11:47:44 +00:00
|
|
|
|
|
2013-05-06 21:43:03 +00:00
|
|
|
|
return AllocConsole();
|
2006-11-08 11:47:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static BOOL
|
|
|
|
|
TUIDisplayStatusMessage(
|
2013-05-06 21:43:03 +00:00
|
|
|
|
IN PGINA_CONTEXT pgContext,
|
|
|
|
|
IN HDESK hDesktop,
|
|
|
|
|
IN DWORD dwOptions,
|
|
|
|
|
IN PWSTR pTitle,
|
|
|
|
|
IN PWSTR pMessage)
|
2006-11-08 11:47:44 +00:00
|
|
|
|
{
|
2013-05-06 21:43:03 +00:00
|
|
|
|
static LPCWSTR newLine = L"\n";
|
|
|
|
|
DWORD result;
|
|
|
|
|
|
|
|
|
|
TRACE("TUIDisplayStatusMessage(%ws)\n", pMessage);
|
|
|
|
|
|
|
|
|
|
UNREFERENCED_PARAMETER(pgContext);
|
|
|
|
|
UNREFERENCED_PARAMETER(hDesktop);
|
|
|
|
|
UNREFERENCED_PARAMETER(dwOptions);
|
|
|
|
|
UNREFERENCED_PARAMETER(pTitle);
|
|
|
|
|
|
|
|
|
|
return
|
|
|
|
|
WriteConsoleW(
|
|
|
|
|
GetStdHandle(STD_OUTPUT_HANDLE),
|
|
|
|
|
pMessage,
|
|
|
|
|
wcslen(pMessage),
|
|
|
|
|
&result,
|
|
|
|
|
NULL) &&
|
|
|
|
|
WriteConsoleW(
|
|
|
|
|
GetStdHandle(STD_OUTPUT_HANDLE),
|
|
|
|
|
newLine,
|
|
|
|
|
wcslen(newLine),
|
|
|
|
|
&result,
|
|
|
|
|
NULL);
|
2006-11-08 11:47:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static BOOL
|
|
|
|
|
TUIRemoveStatusMessage(
|
2013-05-06 21:43:03 +00:00
|
|
|
|
IN PGINA_CONTEXT pgContext)
|
2006-11-08 11:47:44 +00:00
|
|
|
|
{
|
2013-05-06 21:43:03 +00:00
|
|
|
|
UNREFERENCED_PARAMETER(pgContext);
|
2007-01-20 13:29:04 +00:00
|
|
|
|
|
2013-05-06 21:43:03 +00:00
|
|
|
|
/* Nothing to do */
|
|
|
|
|
return TRUE;
|
2006-11-08 11:47:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static BOOL
|
|
|
|
|
DisplayResourceText(
|
2013-05-06 21:43:03 +00:00
|
|
|
|
IN UINT uIdResourceText,
|
|
|
|
|
IN BOOL AddNewLine)
|
2006-11-08 11:47:44 +00:00
|
|
|
|
{
|
2013-05-06 21:43:03 +00:00
|
|
|
|
WCHAR Prompt[256];
|
|
|
|
|
static LPCWSTR newLine = L"\n";
|
|
|
|
|
DWORD count;
|
|
|
|
|
|
2016-09-18 19:37:25 +00:00
|
|
|
|
if (0 == LoadStringW(hDllInstance, uIdResourceText, Prompt, _countof(Prompt)))
|
2013-05-06 21:43:03 +00:00
|
|
|
|
return FALSE;
|
|
|
|
|
if (!WriteConsoleW(
|
|
|
|
|
GetStdHandle(STD_OUTPUT_HANDLE),
|
|
|
|
|
Prompt, wcslen(Prompt),
|
|
|
|
|
&count, NULL))
|
|
|
|
|
{
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
if (AddNewLine)
|
|
|
|
|
{
|
|
|
|
|
if (!WriteConsoleW(
|
|
|
|
|
GetStdHandle(STD_OUTPUT_HANDLE),
|
|
|
|
|
newLine, wcslen(newLine),
|
|
|
|
|
&count, NULL))
|
|
|
|
|
{
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return TRUE;
|
2006-11-08 11:47:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static VOID
|
|
|
|
|
TUIDisplaySASNotice(
|
2013-05-06 21:43:03 +00:00
|
|
|
|
IN OUT PGINA_CONTEXT pgContext)
|
2006-11-08 11:47:44 +00:00
|
|
|
|
{
|
2013-05-06 21:43:03 +00:00
|
|
|
|
TRACE("TUIDisplaySASNotice()\n");
|
2006-11-08 11:47:44 +00:00
|
|
|
|
|
2013-05-06 21:43:03 +00:00
|
|
|
|
UNREFERENCED_PARAMETER(pgContext);
|
2007-01-20 13:29:04 +00:00
|
|
|
|
|
2013-05-06 21:43:03 +00:00
|
|
|
|
DisplayResourceText(IDS_LOGGEDOUTSAS, TRUE);
|
|
|
|
|
DisplayResourceText(IDS_PRESSCTRLALTDELETE, TRUE);
|
2006-11-08 11:47:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static INT
|
|
|
|
|
TUILoggedOnSAS(
|
2013-05-06 21:43:03 +00:00
|
|
|
|
IN OUT PGINA_CONTEXT pgContext,
|
|
|
|
|
IN DWORD dwSasType)
|
2006-11-08 11:47:44 +00:00
|
|
|
|
{
|
2013-05-06 21:43:03 +00:00
|
|
|
|
TRACE("TUILoggedOnSAS()\n");
|
2006-11-08 11:47:44 +00:00
|
|
|
|
|
2013-05-06 21:43:03 +00:00
|
|
|
|
UNREFERENCED_PARAMETER(pgContext);
|
2007-01-20 13:29:04 +00:00
|
|
|
|
|
2013-05-06 21:43:03 +00:00
|
|
|
|
if (dwSasType != WLX_SAS_TYPE_CTRL_ALT_DEL)
|
|
|
|
|
{
|
|
|
|
|
/* Nothing to do for WLX_SAS_TYPE_TIMEOUT */
|
|
|
|
|
return WLX_SAS_ACTION_NONE;
|
|
|
|
|
}
|
2006-11-08 11:47:44 +00:00
|
|
|
|
|
2013-05-06 21:43:03 +00:00
|
|
|
|
FIXME("FIXME: TUILoggedOnSAS(): Let's suppose the user wants to log off...\n");
|
|
|
|
|
return WLX_SAS_ACTION_LOGOFF;
|
2006-11-08 11:47:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static BOOL
|
|
|
|
|
ReadString(
|
2013-05-06 21:43:03 +00:00
|
|
|
|
IN UINT uIdResourcePrompt,
|
|
|
|
|
IN OUT PWSTR Buffer,
|
|
|
|
|
IN DWORD BufferLength,
|
|
|
|
|
IN BOOL ShowString)
|
2006-11-08 11:47:44 +00:00
|
|
|
|
{
|
2013-05-06 21:43:03 +00:00
|
|
|
|
DWORD count, i;
|
|
|
|
|
WCHAR charToDisplay[] = { 0, UNICODE_NULL };
|
|
|
|
|
|
|
|
|
|
if (!SetConsoleMode(GetStdHandle(STD_INPUT_HANDLE), 0))
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
if (!FlushConsoleInputBuffer(GetStdHandle(STD_INPUT_HANDLE)))
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
if (!DisplayResourceText(uIdResourcePrompt, FALSE))
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
i = 0;
|
|
|
|
|
for (;;)
|
|
|
|
|
{
|
|
|
|
|
WCHAR readChar;
|
|
|
|
|
if (!ReadConsoleW(GetStdHandle(STD_INPUT_HANDLE), &readChar, 1, &count, NULL))
|
|
|
|
|
return FALSE;
|
|
|
|
|
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! */
|
|
|
|
|
UNREFERENCED_PARAMETER(BufferLength);
|
|
|
|
|
/* FIXME: handle backspace */
|
|
|
|
|
}
|
|
|
|
|
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;
|
2006-11-08 11:47:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static INT
|
|
|
|
|
TUILoggedOutSAS(
|
2013-05-06 21:43:03 +00:00
|
|
|
|
IN OUT PGINA_CONTEXT pgContext)
|
2006-11-08 11:47:44 +00:00
|
|
|
|
{
|
2013-05-06 21:43:03 +00:00
|
|
|
|
WCHAR UserName[256];
|
|
|
|
|
WCHAR Password[256];
|
2014-03-08 22:13:19 +00:00
|
|
|
|
NTSTATUS Status;
|
|
|
|
|
NTSTATUS SubStatus = STATUS_SUCCESS;
|
2006-11-08 11:47:44 +00:00
|
|
|
|
|
2013-05-06 21:43:03 +00:00
|
|
|
|
TRACE("TUILoggedOutSAS()\n");
|
2006-11-08 11:47:44 +00:00
|
|
|
|
|
2013-05-06 21:43:03 +00:00
|
|
|
|
/* Ask the user for credentials */
|
2016-09-18 19:37:25 +00:00
|
|
|
|
if (!ReadString(IDS_ASKFORUSER, UserName, _countof(UserName), TRUE))
|
2013-05-06 21:43:03 +00:00
|
|
|
|
return WLX_SAS_ACTION_NONE;
|
2016-09-18 19:37:25 +00:00
|
|
|
|
if (!ReadString(IDS_ASKFORPASSWORD, Password, _countof(Password), FALSE))
|
2013-05-06 21:43:03 +00:00
|
|
|
|
return WLX_SAS_ACTION_NONE;
|
2006-11-08 11:47:44 +00:00
|
|
|
|
|
2014-03-08 22:13:19 +00:00
|
|
|
|
Status = DoLoginTasks(pgContext, UserName, NULL, Password, &SubStatus);
|
|
|
|
|
if (Status == STATUS_SUCCESS)
|
|
|
|
|
{
|
|
|
|
|
if (CreateProfile(pgContext, UserName, NULL, Password))
|
|
|
|
|
return WLX_SAS_ACTION_LOGON;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return WLX_SAS_ACTION_NONE;
|
2006-11-08 11:47:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static INT
|
|
|
|
|
TUILockedSAS(
|
2013-05-06 21:43:03 +00:00
|
|
|
|
IN OUT PGINA_CONTEXT pgContext)
|
2006-11-08 11:47:44 +00:00
|
|
|
|
{
|
2013-05-06 21:43:03 +00:00
|
|
|
|
HANDLE hToken;
|
|
|
|
|
WCHAR UserName[256];
|
|
|
|
|
WCHAR Password[256];
|
2014-03-01 20:45:10 +00:00
|
|
|
|
NTSTATUS SubStatus;
|
|
|
|
|
NTSTATUS Status;
|
2013-05-06 21:43:03 +00:00
|
|
|
|
|
|
|
|
|
TRACE("TUILockedSAS()\n");
|
|
|
|
|
|
|
|
|
|
UNREFERENCED_PARAMETER(pgContext);
|
|
|
|
|
|
|
|
|
|
if (!DisplayResourceText(IDS_LOGGEDOUTSAS, TRUE))
|
|
|
|
|
return WLX_SAS_ACTION_UNLOCK_WKSTA;
|
|
|
|
|
|
|
|
|
|
/* Ask the user for credentials */
|
2016-09-18 19:37:25 +00:00
|
|
|
|
if (!ReadString(IDS_ASKFORUSER, UserName, _countof(UserName), TRUE))
|
2013-05-06 21:43:03 +00:00
|
|
|
|
return WLX_SAS_ACTION_NONE;
|
2016-09-18 19:37:25 +00:00
|
|
|
|
if (!ReadString(IDS_ASKFORPASSWORD, Password, _countof(Password), FALSE))
|
2013-05-06 21:43:03 +00:00
|
|
|
|
return WLX_SAS_ACTION_NONE;
|
|
|
|
|
|
2014-03-01 20:45:10 +00:00
|
|
|
|
Status = ConnectToLsa(pgContext);
|
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
|
{
|
|
|
|
|
WARN("ConnectToLsa() failed\n");
|
2014-02-02 21:52:27 +00:00
|
|
|
|
return WLX_SAS_ACTION_NONE;
|
2014-03-01 20:45:10 +00:00
|
|
|
|
}
|
2014-02-02 21:52:27 +00:00
|
|
|
|
|
2014-03-01 20:45:10 +00:00
|
|
|
|
Status = MyLogonUser(pgContext->LsaHandle,
|
|
|
|
|
pgContext->AuthenticationPackage,
|
|
|
|
|
UserName,
|
|
|
|
|
NULL,
|
|
|
|
|
Password,
|
|
|
|
|
&hToken,
|
|
|
|
|
&SubStatus);
|
|
|
|
|
if (!NT_SUCCESS(Status))
|
2013-05-06 21:43:03 +00:00
|
|
|
|
{
|
2014-03-01 20:45:10 +00:00
|
|
|
|
WARN("MyLogonUser() failed\n");
|
2013-05-06 21:43:03 +00:00
|
|
|
|
return WLX_SAS_ACTION_NONE;
|
|
|
|
|
}
|
2014-02-02 21:52:27 +00:00
|
|
|
|
|
2013-05-06 21:43:03 +00:00
|
|
|
|
CloseHandle(hToken);
|
|
|
|
|
return WLX_SAS_ACTION_UNLOCK_WKSTA;
|
2006-11-08 11:47:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-02-13 23:24:15 +00:00
|
|
|
|
static VOID
|
|
|
|
|
TUIDisplayLockedNotice(
|
2013-05-06 21:43:03 +00:00
|
|
|
|
IN OUT PGINA_CONTEXT pgContext)
|
2013-02-13 23:24:15 +00:00
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2006-11-08 11:47:44 +00:00
|
|
|
|
GINA_UI GinaTextUI = {
|
2013-05-06 21:43:03 +00:00
|
|
|
|
TUIInitialize,
|
|
|
|
|
TUIDisplayStatusMessage,
|
|
|
|
|
TUIRemoveStatusMessage,
|
|
|
|
|
TUIDisplaySASNotice,
|
|
|
|
|
TUILoggedOnSAS,
|
|
|
|
|
TUILoggedOutSAS,
|
|
|
|
|
TUILockedSAS,
|
|
|
|
|
TUIDisplayLockedNotice,
|
2006-11-08 11:47:44 +00:00
|
|
|
|
};
|