2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: Local Security Authority Server DLL
4 * FILE: dll/win32/lsasrv/srm.c
5 * PURPOSE: Security Reference Monitor Server
7 * PROGRAMMERS: Timo Kreuzer (timo.kreuzer@reactos.org)
10 /* INCLUDES ****************************************************************/
13 #include <ndk/ntndk.h>
15 /* GLOBALS *****************************************************************/
17 HANDLE SeLsaCommandPort
;
18 HANDLE SeRmCommandPort
;
20 /* FUNCTIONS ***************************************************************/
25 PLSAP_RM_API_MESSAGE Message
)
27 ERR("Security: LSA Component Test Command Received\n");
33 PLSAP_RM_API_MESSAGE Message
)
35 ERR("LsapAdtWriteLog\n");
41 PLSAP_RM_API_MESSAGE Message
)
52 LSAP_RM_API_MESSAGE Message
;
53 PPORT_MESSAGE ReplyMessage
;
54 REMOTE_PORT_VIEW RemotePortView
;
55 HANDLE MessagePort
, DummyPortHandle
;
58 /* Initialize the port message */
59 Message
.Header
.u1
.s1
.TotalLength
= sizeof(Message
);
60 Message
.Header
.u1
.s1
.DataLength
= 0;
62 /* Listen on the LSA command port */
63 Status
= NtListenPort(SeLsaCommandPort
, &Message
.Header
);
64 if (!NT_SUCCESS(Status
))
66 ERR("LsapRmServerThread - Port Listen failed 0x%lx\n", Status
);
70 /* Setup the Port View Structure */
71 RemotePortView
.Length
= sizeof(REMOTE_PORT_VIEW
);
72 RemotePortView
.ViewSize
= 0;
73 RemotePortView
.ViewBase
= NULL
;
75 /* Accept the connection */
76 Status
= NtAcceptConnectPort(&MessagePort
,
82 if (!NT_SUCCESS(Status
))
84 ERR("LsapRmServerThread - Port Accept Connect failed 0x%lx\n", Status
);
88 /* Complete the connection */
89 Status
= NtCompleteConnectPort(MessagePort
);
90 if (!NT_SUCCESS(Status
))
92 ERR("LsapRmServerThread - Port Complete Connect failed 0x%lx\n", Status
);
102 /* Wait for a message */
103 Status
= NtReplyWaitReceivePort(MessagePort
,
107 if (!NT_SUCCESS(Status
))
109 ERR("LsapRmServerThread - Failed to get message: 0x%lx", Status
);
114 /* Check if this is a connection request */
115 if (Message
.Header
.u2
.s2
.Type
== LPC_CONNECTION_REQUEST
)
117 /* Reject connection request */
118 NtAcceptConnectPort(&DummyPortHandle
,
130 /* Check if this is an actual request */
131 if (Message
.Header
.u2
.s2
.Type
== LPC_REQUEST
)
133 ReplyMessage
= &Message
.Header
;
135 switch (Message
.ApiNumber
)
137 case LsapAdtWriteLogApi
:
138 LsapAdtWriteLog(&Message
);
145 case LsapComponentTestApi
:
146 LsapComponentTest(&Message
);
150 ERR("LsapRmServerThread - invalid API number: 0x%lx\n",
158 ERR("LsapRmServerThread - unexpected message type: 0x%lx\n",
159 Message
.Header
.u2
.s2
.Type
);
167 LsapRmInitializeServer(VOID
)
170 OBJECT_ATTRIBUTES ObjectAttributes
;
171 SECURITY_QUALITY_OF_SERVICE SecurityQos
;
177 /* Create the LSA command port */
178 RtlInitUnicodeString(&Name
, L
"\\SeLsaCommandPort");
179 InitializeObjectAttributes(&ObjectAttributes
, &Name
, 0, NULL
, NULL
);
180 Status
= NtCreatePort(&SeLsaCommandPort
,
183 PORT_MAXIMUM_MESSAGE_LENGTH
,
185 if (!NT_SUCCESS(Status
))
187 ERR("LsapRmInitializeServer - Port Create failed 0x%lx\n", Status
);
191 /* Open the LSA init event */
192 RtlInitUnicodeString(&Name
, L
"\\SeLsaInitEvent");
193 InitializeObjectAttributes(&ObjectAttributes
, &Name
, 0, NULL
, NULL
);
194 Status
= NtOpenEvent(&InitEvent
, 2, &ObjectAttributes
);
195 if (!NT_SUCCESS(Status
))
197 ERR("LsapRmInitializeServer - Lsa Init Event Open failed 0x%lx\n", Status
);
201 /* Signal the kernel, that we are ready */
202 Status
= NtSetEvent(InitEvent
, 0);
203 if (!NT_SUCCESS(Status
))
205 ERR("LsapRmInitializeServer - Set Init Event failed 0x%lx\n", Status
);
209 /* Setup the QoS structure */
210 SecurityQos
.ImpersonationLevel
= SecurityIdentification
;
211 SecurityQos
.ContextTrackingMode
= SECURITY_DYNAMIC_TRACKING
;
212 SecurityQos
.EffectiveOnly
= TRUE
;
214 /* Connect to the kernel server */
215 RtlInitUnicodeString(&Name
, L
"\\SeRmCommandPort");
216 Status
= NtConnectPort(&SeRmCommandPort
,
224 if (!NT_SUCCESS(Status
))
226 ERR("LsapRmInitializeServer - Connect to Rm Command Port failed 0x%lx\n", Status
);
230 /* Create the server thread */
231 ThreadHandle
= CreateThread(NULL
, 0, LsapRmServerThread
, NULL
, 0, &ThreadId
);
232 if (ThreadHandle
== NULL
)
234 ERR("LsapRmInitializeServer - Create Thread failed 0x%lx\n", Status
);
235 return STATUS_INSUFFICIENT_RESOURCES
;
238 /* Close the server thread handle */
239 CloseHandle(ThreadHandle
);
241 return STATUS_SUCCESS
;
245 LsapRmCreateLogonSession(
248 SEP_RM_API_MESSAGE RequestMessage
;
249 SEP_RM_API_MESSAGE ReplyMessage
;
252 TRACE("LsapRmCreateLogonSession(%p)\n", LogonId
);
254 RequestMessage
.Header
.u2
.ZeroInit
= 0;
255 RequestMessage
.Header
.u1
.s1
.TotalLength
=
256 (CSHORT
)(sizeof(PORT_MESSAGE
) + sizeof(ULONG
) + sizeof(LUID
));
257 RequestMessage
.Header
.u1
.s1
.DataLength
=
258 RequestMessage
.Header
.u1
.s1
.TotalLength
-
259 (CSHORT
)sizeof(PORT_MESSAGE
);
261 RequestMessage
.ApiNumber
= (ULONG
)RmCreateLogonSession
;
262 RtlCopyLuid(&RequestMessage
.u
.LogonLuid
, LogonId
);
264 ReplyMessage
.Header
.u2
.ZeroInit
= 0;
265 ReplyMessage
.Header
.u1
.s1
.TotalLength
=
266 (CSHORT
)(sizeof(PORT_MESSAGE
) + sizeof(ULONG
) + sizeof(NTSTATUS
));
267 ReplyMessage
.Header
.u1
.s1
.DataLength
=
268 ReplyMessage
.Header
.u1
.s1
.TotalLength
-
269 (CSHORT
)sizeof(PORT_MESSAGE
);
271 ReplyMessage
.u
.ResultStatus
= STATUS_SUCCESS
;
273 Status
= NtRequestWaitReplyPort(SeRmCommandPort
,
274 (PPORT_MESSAGE
)&RequestMessage
,
275 (PPORT_MESSAGE
)&ReplyMessage
);
276 if (NT_SUCCESS(Status
))
278 Status
= ReplyMessage
.u
.ResultStatus
;
285 LsapRmDeleteLogonSession(
288 SEP_RM_API_MESSAGE RequestMessage
;
289 SEP_RM_API_MESSAGE ReplyMessage
;
292 TRACE("LsapRmDeleteLogonSession(%p)\n", LogonId
);
294 RequestMessage
.Header
.u2
.ZeroInit
= 0;
295 RequestMessage
.Header
.u1
.s1
.TotalLength
=
296 (CSHORT
)(sizeof(PORT_MESSAGE
) + sizeof(ULONG
) + sizeof(LUID
));
297 RequestMessage
.Header
.u1
.s1
.DataLength
=
298 RequestMessage
.Header
.u1
.s1
.TotalLength
-
299 (CSHORT
)sizeof(PORT_MESSAGE
);
301 RequestMessage
.ApiNumber
= (ULONG
)RmDeleteLogonSession
;
302 RtlCopyLuid(&RequestMessage
.u
.LogonLuid
, LogonId
);
304 ReplyMessage
.Header
.u2
.ZeroInit
= 0;
305 ReplyMessage
.Header
.u1
.s1
.TotalLength
=
306 (CSHORT
)(sizeof(PORT_MESSAGE
) + sizeof(ULONG
) + sizeof(NTSTATUS
));
307 ReplyMessage
.Header
.u1
.s1
.DataLength
=
308 ReplyMessage
.Header
.u1
.s1
.TotalLength
-
309 (CSHORT
)sizeof(PORT_MESSAGE
);
311 ReplyMessage
.u
.ResultStatus
= STATUS_SUCCESS
;
313 Status
= NtRequestWaitReplyPort(SeRmCommandPort
,
314 (PPORT_MESSAGE
)&RequestMessage
,
315 (PPORT_MESSAGE
)&ReplyMessage
);
316 if (NT_SUCCESS(Status
))
318 Status
= ReplyMessage
.u
.ResultStatus
;