ReactOS  0.4.12-dev-916-gffc4e30
tui.c
Go to the documentation of this file.
1 /*
2  * PROJECT: ReactOS msgina.dll
3  * FILE: dll/win32/msgina/tui.c
4  * PURPOSE: ReactOS Logon GINA DLL
5  * PROGRAMMER: Hervé Poussineau (hpoussin@reactos.org)
6  */
7 
8 #include "msgina.h"
9 
10 #include <wincon.h>
11 
12 static BOOL
14  IN OUT PGINA_CONTEXT pgContext)
15 {
16  TRACE("TUIInitialize(%p)\n", pgContext);
17 
18  return AllocConsole();
19 }
20 
21 static BOOL
23  IN PGINA_CONTEXT pgContext,
24  IN HDESK hDesktop,
26  IN PWSTR pTitle,
27  IN PWSTR pMessage)
28 {
29  static LPCWSTR newLine = L"\n";
30  DWORD result;
31 
32  TRACE("TUIDisplayStatusMessage(%ws)\n", pMessage);
33 
34  UNREFERENCED_PARAMETER(pgContext);
35  UNREFERENCED_PARAMETER(hDesktop);
37  UNREFERENCED_PARAMETER(pTitle);
38 
39  return
42  pMessage,
43  wcslen(pMessage),
44  &result,
45  NULL) &&
48  newLine,
49  wcslen(newLine),
50  &result,
51  NULL);
52 }
53 
54 static BOOL
56  IN PGINA_CONTEXT pgContext)
57 {
58  UNREFERENCED_PARAMETER(pgContext);
59 
60  /* Nothing to do */
61  return TRUE;
62 }
63 
64 static BOOL
66  IN UINT uIdResourceText,
67  IN BOOL AddNewLine)
68 {
69  WCHAR Prompt[256];
70  static LPCWSTR newLine = L"\n";
71  DWORD count;
72 
73  if (0 == LoadStringW(hDllInstance, uIdResourceText, Prompt, _countof(Prompt)))
74  return FALSE;
75  if (!WriteConsoleW(
77  Prompt, wcslen(Prompt),
78  &count, NULL))
79  {
80  return FALSE;
81  }
82  if (AddNewLine)
83  {
84  if (!WriteConsoleW(
86  newLine, wcslen(newLine),
87  &count, NULL))
88  {
89  return FALSE;
90  }
91  }
92  return TRUE;
93 }
94 
95 static VOID
97  IN OUT PGINA_CONTEXT pgContext)
98 {
99  TRACE("TUIDisplaySASNotice()\n");
100 
101  UNREFERENCED_PARAMETER(pgContext);
102 
105 }
106 
107 static INT
109  IN OUT PGINA_CONTEXT pgContext,
110  IN DWORD dwSasType)
111 {
112  TRACE("TUILoggedOnSAS()\n");
113 
114  UNREFERENCED_PARAMETER(pgContext);
115 
116  if (dwSasType != WLX_SAS_TYPE_CTRL_ALT_DEL)
117  {
118  /* Nothing to do for WLX_SAS_TYPE_TIMEOUT */
119  return WLX_SAS_ACTION_NONE;
120  }
121 
122  FIXME("FIXME: TUILoggedOnSAS(): Let's suppose the user wants to log off...\n");
123  return WLX_SAS_ACTION_LOGOFF;
124 }
125 
126 static BOOL
128  IN UINT uIdResourcePrompt,
129  IN OUT PWSTR Buffer,
131  IN BOOL ShowString)
132 {
133  DWORD count, i;
134  WCHAR charToDisplay[] = { 0, UNICODE_NULL };
135 
137  return FALSE;
138 
140  return FALSE;
141 
142  if (!DisplayResourceText(uIdResourcePrompt, FALSE))
143  return FALSE;
144 
145  i = 0;
146  for (;;)
147  {
148  WCHAR readChar;
149  if (!ReadConsoleW(GetStdHandle(STD_INPUT_HANDLE), &readChar, 1, &count, NULL))
150  return FALSE;
151  if (readChar == '\r' || readChar == '\n')
152  {
153  /* End of string */
154  charToDisplay[0] = L'\n';
157  charToDisplay,
158  wcslen(charToDisplay),
159  &count,
160  NULL);
161  break;
162  }
163  if (ShowString)
164  {
165  /* Display the char */
166  charToDisplay[0] = readChar;
169  charToDisplay,
170  wcslen(charToDisplay),
171  &count,
172  NULL);
173  }
174  Buffer[i++] = readChar;
175  /* FIXME: buffer overflow if the user writes too many chars! */
177  /* FIXME: handle backspace */
178  }
179  Buffer[i] = UNICODE_NULL;
180 
181  if (!ShowString)
182  {
183  /* Still display the \n */
184  static LPCWSTR newLine = L"\n";
185  DWORD result;
188  newLine,
189  wcslen(newLine),
190  &result,
191  NULL);
192  }
193  return TRUE;
194 }
195 
196 static INT
198  IN OUT PGINA_CONTEXT pgContext)
199 {
200  WCHAR UserName[256];
201  WCHAR Password[256];
204 
205  TRACE("TUILoggedOutSAS()\n");
206 
207  /* Ask the user for credentials */
208  if (!ReadString(IDS_ASKFORUSER, UserName, _countof(UserName), TRUE))
209  return WLX_SAS_ACTION_NONE;
211  return WLX_SAS_ACTION_NONE;
212 
213  Status = DoLoginTasks(pgContext, UserName, NULL, Password, &SubStatus);
214  if (Status == STATUS_SUCCESS)
215  {
216  if (CreateProfile(pgContext, UserName, NULL, Password))
217  return WLX_SAS_ACTION_LOGON;
218  }
219 
220  return WLX_SAS_ACTION_NONE;
221 }
222 
223 static INT
225  IN OUT PGINA_CONTEXT pgContext)
226 {
227  HANDLE hToken;
228  WCHAR UserName[256];
229  WCHAR Password[256];
232 
233  TRACE("TUILockedSAS()\n");
234 
235  UNREFERENCED_PARAMETER(pgContext);
236 
239 
240  /* Ask the user for credentials */
241  if (!ReadString(IDS_ASKFORUSER, UserName, _countof(UserName), TRUE))
242  return WLX_SAS_ACTION_NONE;
244  return WLX_SAS_ACTION_NONE;
245 
246  Status = ConnectToLsa(pgContext);
247  if (!NT_SUCCESS(Status))
248  {
249  WARN("ConnectToLsa() failed\n");
250  return WLX_SAS_ACTION_NONE;
251  }
252 
253  Status = MyLogonUser(pgContext->LsaHandle,
254  pgContext->AuthenticationPackage,
255  UserName,
256  NULL,
257  Password,
258  &hToken,
259  &SubStatus);
260  if (!NT_SUCCESS(Status))
261  {
262  WARN("MyLogonUser() failed\n");
263  return WLX_SAS_ACTION_NONE;
264  }
265 
266  CloseHandle(hToken);
268 }
269 
270 static VOID
272  IN OUT PGINA_CONTEXT pgContext)
273 {
274 }
275 
283  TUILockedSAS,
285 };
DWORD dwOptions
Definition: solitaire.cpp:23
#define IN
Definition: typedefs.h:38
static INT TUILoggedOutSAS(IN OUT PGINA_CONTEXT pgContext)
Definition: tui.c:197
#define TRUE
Definition: types.h:120
BOOL WINAPI AllocConsole(VOID)
Definition: console.c:48
static INT TUILockedSAS(IN OUT PGINA_CONTEXT pgContext)
Definition: tui.c:224
static BOOL TUIInitialize(IN OUT PGINA_CONTEXT pgContext)
Definition: tui.c:13
#define CloseHandle
Definition: compat.h:398
#define IDS_ASKFORUSER
Definition: resource.h:74
NTSTATUS MyLogonUser(HANDLE LsaHandle, ULONG AuthenticationPackage, LPWSTR lpszUsername, LPWSTR lpszDomain, LPWSTR lpszPassword, PHANDLE phToken, PNTSTATUS SubStatus)
Definition: lsa.c:53
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185
static BOOL ReadString(IN UINT uIdResourcePrompt, IN OUT PWSTR Buffer, IN DWORD BufferLength, IN BOOL ShowString)
Definition: tui.c:127
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:323
uint16_t * PWSTR
Definition: typedefs.h:54
#define _countof(array)
Definition: fontsub.cpp:30
NTSTATUS ConnectToLsa(PGINA_CONTEXT pgContext)
Definition: lsa.c:11
BOOL WINAPI DECLSPEC_HOTPATCH WriteConsoleW(IN HANDLE hConsoleOutput, IN CONST VOID *lpBuffer, IN DWORD nNumberOfCharsToWrite, OUT LPDWORD lpNumberOfCharsWritten, LPVOID lpReserved)
Definition: readwrite.c:1449
GLuint GLuint GLsizei count
Definition: gl.h:1545
#define WARN(fmt,...)
Definition: debug.h:111
LONG NTSTATUS
Definition: precomp.h:26
static BOOL TUIRemoveStatusMessage(IN PGINA_CONTEXT pgContext)
Definition: tui.c:55
BOOL WINAPI FlushConsoleInputBuffer(IN HANDLE hConsoleInput)
Definition: console.c:169
HANDLE WINAPI GetStdHandle(IN DWORD nStdHandle)
Definition: console.c:152
int WINAPI LoadStringW(_In_opt_ HINSTANCE hInstance, _In_ UINT uID, _Out_writes_to_(cchBufferMax, return+1) LPWSTR lpBuffer, _In_ int cchBufferMax)
int32_t INT
Definition: typedefs.h:56
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
static VOID TUIDisplaySASNotice(IN OUT PGINA_CONTEXT pgContext)
Definition: tui.c:96
#define UNICODE_NULL
_IRQL_requires_same_ _In_ PLSA_STRING _In_ SECURITY_LOGON_TYPE _In_ ULONG _In_ ULONG _In_opt_ PTOKEN_GROUPS _In_ PTOKEN_SOURCE _Out_ PVOID _Out_ PULONG _Inout_ PLUID _Out_ PHANDLE _Out_ PQUOTA_LIMITS _Out_ PNTSTATUS SubStatus
unsigned int BOOL
Definition: ntddk_ex.h:94
_In_ ULONG BufferLength
Definition: usbdlib.h:225
BOOL WINAPI DECLSPEC_HOTPATCH SetConsoleMode(HANDLE hConsoleHandle, DWORD dwMode)
Definition: console.c:1608
#define FIXME(fmt,...)
Definition: debug.h:110
#define WLX_SAS_ACTION_LOGOFF
Definition: winwlx.h:56
#define WLX_SAS_ACTION_UNLOCK_WKSTA
Definition: winwlx.h:60
smooth NULL
Definition: ftsmooth.c:416
NTSTATUS DoLoginTasks(IN OUT PGINA_CONTEXT pgContext, IN PWSTR UserName, IN PWSTR Domain, IN PWSTR Password, OUT PNTSTATUS SubStatus)
Definition: msgina.c:752
Definition: bufpool.h:45
#define STD_INPUT_HANDLE
Definition: winbase.h:264
static HINSTANCE hDllInstance
Definition: clb.c:30
#define TRACE(s)
Definition: solgame.cpp:4
BOOL WINAPI DECLSPEC_HOTPATCH ReadConsoleW(IN HANDLE hConsoleInput, OUT LPVOID lpBuffer, IN DWORD nNumberOfCharsToRead, OUT LPDWORD lpNumberOfCharsRead, IN PCONSOLE_READCONSOLE_CONTROL pInputControl OPTIONAL)
Definition: readwrite.c:1176
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
unsigned long DWORD
Definition: ntddk_ex.h:95
GINA_UI GinaTextUI
Definition: tui.c:276
#define WLX_SAS_ACTION_LOGON
Definition: winwlx.h:53
static const WCHAR L[]
Definition: oid.c:1250
#define WLX_SAS_TYPE_CTRL_ALT_DEL
Definition: winwlx.h:36
#define IDS_PRESSCTRLALTDELETE
Definition: resource.h:73
#define STD_OUTPUT_HANDLE
Definition: winbase.h:265
Status
Definition: gdiplustypes.h:24
static VOID TUIDisplayLockedNotice(IN OUT PGINA_CONTEXT pgContext)
Definition: tui.c:271
#define IDS_LOGGEDOUTSAS
Definition: resource.h:71
#define WLX_SAS_ACTION_NONE
Definition: winwlx.h:54
unsigned int UINT
Definition: ndis.h:50
static INT TUILoggedOnSAS(IN OUT PGINA_CONTEXT pgContext, IN DWORD dwSasType)
Definition: tui.c:108
#define OUT
Definition: typedefs.h:39
#define IDS_ASKFORPASSWORD
Definition: resource.h:75
return STATUS_SUCCESS
Definition: btrfs.c:2725
GLuint64EXT * result
Definition: glext.h:11304
static BOOL TUIDisplayStatusMessage(IN PGINA_CONTEXT pgContext, IN HDESK hDesktop, IN DWORD dwOptions, IN PWSTR pTitle, IN PWSTR pMessage)
Definition: tui.c:22
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
BOOL CreateProfile(IN OUT PGINA_CONTEXT pgContext, IN PWSTR UserName, IN PWSTR Domain, IN PWSTR Password)
Definition: msgina.c:785
static BOOL DisplayResourceText(IN UINT uIdResourceText, IN BOOL AddNewLine)
Definition: tui.c:65