From d7aa49ecc2407be45d6849ee5d6716cfb9a7af26 Mon Sep 17 00:00:00 2001 From: Timo Kreuzer Date: Sat, 22 Feb 2014 20:03:53 +0000 Subject: [PATCH] [LSASRV] Add beginning of the user mode part of the SRM server. svn path=/branches/kernel-fun/; revision=62293 --- reactos/dll/win32/lsasrv/lsasrv.c | 264 ++++++++++++++++++++++++++++++ 1 file changed, 264 insertions(+) diff --git a/reactos/dll/win32/lsasrv/lsasrv.c b/reactos/dll/win32/lsasrv/lsasrv.c index 045a745f1b9..72dd6337df5 100644 --- a/reactos/dll/win32/lsasrv/lsasrv.c +++ b/reactos/dll/win32/lsasrv/lsasrv.c @@ -6,7 +6,39 @@ * COPYRIGHT: Copyright 2006-2009 Eric Kohl */ +/* INCLUDES ****************************************************************/ + #include "lsasrv.h" +#include + +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 @@ LsaIFree_LSAPR_PRIVILEGE_SET(IN PLSAPR_PRIVILEGE_SET Ptr) } +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) { @@ -140,6 +396,14 @@ LsapInitLsa(VOID) /* 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();