Author: tkreuzer
Date: Sat Feb 22 20:03:53 2014
New Revision: 62293
URL:
http://svn.reactos.org/svn/reactos?rev=62293&view=rev
Log:
[LSASRV]
Add beginning of the user mode part of the SRM server.
Modified:
branches/kernel-fun/reactos/dll/win32/lsasrv/lsasrv.c
Modified: branches/kernel-fun/reactos/dll/win32/lsasrv/lsasrv.c
URL:
http://svn.reactos.org/svn/reactos/branches/kernel-fun/reactos/dll/win32/ls…
==============================================================================
--- branches/kernel-fun/reactos/dll/win32/lsasrv/lsasrv.c [iso-8859-1] (original)
+++ branches/kernel-fun/reactos/dll/win32/lsasrv/lsasrv.c [iso-8859-1] Sat Feb 22 20:03:53
2014
@@ -6,7 +6,39 @@
* COPYRIGHT: Copyright 2006-2009 Eric Kohl
*/
+/* INCLUDES ****************************************************************/
+
#include "lsasrv.h"
+#include <ndk/ntndk.h>
+
+typedef struct _LSAP_RM_API_MESSAGE
+{
+ PORT_MESSAGE Header;
+ ULONG ApiNumber;
+ union
+ {
+ UCHAR Fill[PORT_MAXIMUM_MESSAGE_LENGTH - sizeof(PORT_MESSAGE)];
+ struct
+ {
+ ULONG Info1;
+ } WriteLog;
+
+ } u;
+} LSAP_RM_API_MESSAGE, *PLSAP_RM_API_MESSAGE;
+
+enum _LSAP_API_NUMBER
+{
+ LsapAdtWriteLogApi = 1,
+ LsapComponentTestApi,
+ LsapAsyncApi
+};
+
+
+/* GLOBALS *****************************************************************/
+
+HANDLE SeLsaCommandPort;
+HANDLE SeRmCommandPort;
+
/* FUNCTIONS ***************************************************************/
@@ -128,6 +160,230 @@
}
+VOID
+WINAPI
+LsapComponentTest(
+ PLSAP_RM_API_MESSAGE Message)
+{
+ ERR("Security: LSA Component Test Command Received\n");
+
+}
+
+VOID
+WINAPI
+LsapAdtWriteLog(
+ PLSAP_RM_API_MESSAGE Message)
+{
+ ERR("LsapAdtWriteLog\n");
+}
+
+VOID
+WINAPI
+LsapAsync(
+ PLSAP_RM_API_MESSAGE Message)
+{
+ ERR("LsapAsync\n");
+}
+
+DWORD
+WINAPI
+LsapRmServerThread(
+ PVOID StartContext)
+{
+ LSAP_RM_API_MESSAGE Message;
+ PPORT_MESSAGE ReplyMessage;
+ REMOTE_PORT_VIEW RemotePortView;
+ HANDLE MessagePort, DummyPortHandle;
+ NTSTATUS Status;
+
+ /* Initialize the port message */
+ Message.Header.u1.s1.TotalLength = sizeof(Message);
+ Message.Header.u1.s1.DataLength = 0;
+
+ /* Listen on the LSA command port */
+ Status = NtListenPort(SeLsaCommandPort, &Message.Header);
+ if (!NT_SUCCESS(Status))
+ {
+ ERR("LsapRmServerThread - Port Listen failed 0x%lx\n", Status);
+ return Status;
+ }
+
+ /* Setup the Port View Structure */
+ RemotePortView.Length = sizeof(REMOTE_PORT_VIEW);
+ RemotePortView.ViewSize = 0;
+ RemotePortView.ViewBase = NULL;
+
+ /* Accept the connection */
+ Status = NtAcceptConnectPort(&MessagePort,
+ 0,
+ &Message.Header,
+ TRUE,
+ NULL,
+ &RemotePortView);
+ if (!NT_SUCCESS(Status))
+ {
+ ERR("LsapRmServerThread - Port Accept Connect failed 0x%lx\n",
Status);
+ return Status;
+ }
+
+ /* Complete the connection */
+ Status = NtCompleteConnectPort(MessagePort);
+ if (!NT_SUCCESS(Status))
+ {
+ ERR("LsapRmServerThread - Port Complete Connect failed 0x%lx\n",
Status);
+ return Status;
+ }
+
+ /* No reply yet */
+ ReplyMessage = NULL;
+
+ /* Start looping */
+ while (TRUE)
+ {
+ /* Wait for a message */
+ Status = NtReplyWaitReceivePort(MessagePort,
+ NULL,
+ ReplyMessage,
+ &Message.Header);
+ if (!NT_SUCCESS(Status))
+ {
+ ERR("LsapRmServerThread - Failed to get message: 0x%lx", Status);
+ ReplyMessage = NULL;
+ continue;
+ }
+
+ /* Check if this is a connection request */
+ if (Message.Header.u2.s2.Type == LPC_CONNECTION_REQUEST)
+ {
+ /* Reject connection request */
+ NtAcceptConnectPort(&DummyPortHandle,
+ NULL,
+ &Message.Header,
+ FALSE,
+ NULL,
+ NULL);
+
+ /* Start over */
+ ReplyMessage = NULL;
+ continue;
+ }
+
+ /* Check if this is an actual request */
+ if (Message.Header.u2.s2.Type == LPC_REQUEST)
+ {
+ ReplyMessage = &Message.Header;
+
+ switch (Message.ApiNumber)
+ {
+ case LsapAdtWriteLogApi:
+ LsapAdtWriteLog(&Message);
+ break;
+
+ case LsapAsyncApi:
+ LsapAsync(&Message);
+ break;
+
+ case LsapComponentTestApi:
+ LsapComponentTest(&Message);
+ break;
+
+ default:
+ ERR("LsapRmServerThread - invalid API number: 0x%lx\n",
+ Message.ApiNumber);
+ ReplyMessage = NULL;
+ }
+
+ continue;
+ }
+
+ ERR("LsapRmServerThread - unexpected message type: 0x%lx\n",
+ Message.Header.u2.s2.Type);
+
+ /* Start over */
+ ReplyMessage = NULL;
+ }
+}
+
+NTSTATUS
+WINAPI
+LsapRmInitializeServer(
+ VOID)
+{
+ UNICODE_STRING Name;
+ OBJECT_ATTRIBUTES ObjectAttributes;
+ SECURITY_QUALITY_OF_SERVICE SecurityQos;
+ HANDLE InitEvent;
+ HANDLE ThreadHandle;
+ DWORD ThreadId;
+ NTSTATUS Status;
+
+ /* Create the LSA command port */
+ RtlInitUnicodeString(&Name, L"\\SeLsaCommandPort");
+ InitializeObjectAttributes(&ObjectAttributes, &Name, 0, NULL, NULL);
+ Status = NtCreatePort(&SeLsaCommandPort,
+ &ObjectAttributes,
+ 0,
+ PORT_MAXIMUM_MESSAGE_LENGTH,
+ 2 * PAGE_SIZE);
+ if (!NT_SUCCESS(Status))
+ {
+ ERR("LsapRmInitializeServer - Port Create failed 0x%lx\n", Status);
+ return Status;
+ }
+
+ /* Open the LSA init event */
+ RtlInitUnicodeString(&Name, L"\\SeLsaInitEvent");
+ InitializeObjectAttributes(&ObjectAttributes, &Name, 0, NULL, NULL);
+ Status = NtOpenEvent(&InitEvent, 2, &ObjectAttributes);
+ if (!NT_SUCCESS(Status))
+ {
+ ERR("LsapRmInitializeServer - Lsa Init Event Open failed 0x%lx\n",
Status);
+ return Status;
+ }
+
+ /* Signal the kernel, that we are ready */
+ Status = NtSetEvent(InitEvent, 0);
+ if (!NT_SUCCESS(Status))
+ {
+ ERR("LsapRmInitializeServer - Set Init Event failed 0x%lx\n", Status);
+ return Status;
+ }
+
+ /* Setup the QoS structure */
+ SecurityQos.ImpersonationLevel = SecurityIdentification;
+ SecurityQos.ContextTrackingMode = SECURITY_DYNAMIC_TRACKING;
+ SecurityQos.EffectiveOnly = TRUE;
+
+ /* Connect to the kernel server */
+ RtlInitUnicodeString(&Name, L"\\SeRmCommandPort");
+ Status = NtConnectPort(&SeRmCommandPort,
+ &Name,
+ &SecurityQos,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL);
+ if (!NT_SUCCESS(Status))
+ {
+ ERR("LsapRmInitializeServer - Connect to Rm Command Port failed
0x%lx\n", Status);
+ return Status;
+ }
+
+ /* Create the server thread */
+ ThreadHandle = CreateThread(NULL, 0, LsapRmServerThread, NULL, 0, &ThreadId);
+ if (ThreadHandle == NULL)
+ {
+ ERR("LsapRmInitializeServer - Create Thread failed 0x%lx\n", Status);
+ return STATUS_INSUFFICIENT_RESOURCES;
+ }
+
+ /* Close the server thread handle */
+ CloseHandle(ThreadHandle);
+
+ return STATUS_SUCCESS;
+}
+
NTSTATUS WINAPI
LsapInitLsa(VOID)
{
@@ -139,6 +395,14 @@
/* Initialize the well known SIDs */
LsapInitSids();
+
+ /* Initialize the SRM server */
+ Status = LsapRmInitializeServer();
+ if (!NT_SUCCESS(Status))
+ {
+ ERR("LsapRmInitializeServer() failed (Status 0x%08lx)\n", Status);
+ return Status;
+ }
/* Initialize the LSA database */
LsapInitDatabase();