- Merge from trunk up to r45543
[reactos.git] / dll / win32 / lsasrv / authport.c
1 /*
2 * PROJECT: Local Security Authority Server DLL
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: dll/win32/lsasrv/authport.c
5 * PURPOSE: LsaAuthenticationPort server routines
6 * COPYRIGHT: Copyright 2009 Eric Kohl
7 */
8
9 /* INCLUDES ****************************************************************/
10
11 #define WIN32_NO_STATUS
12 #include <windows.h>
13 #define NTOS_MODE_USER
14 #include <ndk/ntndk.h>
15
16 #include "lsass.h"
17 #include "lsasrv.h"
18
19 #include "wine/debug.h"
20
21 WINE_DEFAULT_DEBUG_CHANNEL(lsasrv);
22
23
24 static HANDLE PortThreadHandle = NULL;
25 static HANDLE AuthPortHandle = NULL;
26
27
28 /* FUNCTIONS ***************************************************************/
29
30 NTSTATUS WINAPI
31 AuthPortThreadRoutine(PVOID Param)
32 {
33 LSASS_REQUEST Request;
34 PPORT_MESSAGE Reply = NULL;
35 NTSTATUS Status;
36
37 NTSTATUS Status2;
38
39 HANDLE ConnectionHandle = NULL;
40 PVOID Context = NULL;
41 BOOLEAN Accept;
42
43 TRACE("AuthPortThreadRoutine() called\n");
44
45 Status = STATUS_SUCCESS;
46
47 for (;;)
48 {
49 Status = NtReplyWaitReceivePort(AuthPortHandle,
50 0,
51 Reply,
52 &Request.Header);
53 if (!NT_SUCCESS(Status))
54 {
55 TRACE("NtReplyWaitReceivePort() failed (Status %lx)\n", Status);
56 break;
57 }
58
59 TRACE("Received message\n");
60
61 if (Request.Header.u2.s2.Type == LPC_CONNECTION_REQUEST)
62 {
63 TRACE("Port connection request\n");
64
65 Accept = TRUE;
66 Status2 = NtAcceptConnectPort(&ConnectionHandle,
67 &Context,
68 &Request.Header,
69 Accept,
70 NULL,
71 NULL);
72
73
74 Status2 = NtCompleteConnectPort(ConnectionHandle);
75
76 }
77 else if (Request.Header.u2.s2.Type == LPC_PORT_CLOSED ||
78 Request.Header.u2.s2.Type == LPC_CLIENT_DIED)
79 {
80 TRACE("Port closed or client died request\n");
81
82 // return STATUS_UNSUCCESSFUL;
83 }
84 else if (Request.Header.u2.s2.Type == LPC_REQUEST)
85 {
86 TRACE("Received request (Type: %lu)\n", Request.Type);
87
88 }
89 else if (Request.Header.u2.s2.Type == LPC_DATAGRAM)
90 {
91 TRACE("Received datagram\n");
92
93 }
94 }
95
96 return Status;
97 }
98
99
100 NTSTATUS
101 StartAuthenticationPort(VOID)
102 {
103 OBJECT_ATTRIBUTES ObjectAttributes;
104 UNICODE_STRING PortName;
105 DWORD ThreadId;
106 NTSTATUS Status;
107
108 RtlInitUnicodeString(&PortName,
109 L"\\LsaAuthenticationPort");
110
111 InitializeObjectAttributes(&ObjectAttributes,
112 &PortName,
113 0,
114 NULL,
115 NULL);
116
117 Status = NtCreatePort(&AuthPortHandle,
118 &ObjectAttributes,
119 0,
120 0x100,
121 0x2000);
122 if (!NT_SUCCESS(Status))
123 {
124 TRACE("NtCreatePort() failed (Status %lx)\n", Status);
125 return Status;
126 }
127
128 PortThreadHandle = CreateThread(NULL,
129 0x1000,
130 (LPTHREAD_START_ROUTINE)AuthPortThreadRoutine,
131 NULL,
132 0,
133 &ThreadId);
134
135
136 return STATUS_SUCCESS;
137 }
138
139 /* EOF */