ReactOS 0.4.15-dev-7906-g1b85a5f
NtAcceptConnectPort.c File Reference
#include "precomp.h"
#include <process.h>
Include dependency graph for NtAcceptConnectPort.c:

Go to the source code of this file.

Classes

struct  _TEST_CONNECTION_INFO
 
struct  _TEST_MESSAGE
 

Macros

#define TEST_CONNECTION_INFO_SIGNATURE1   0xaabb0123
 
#define TEST_CONNECTION_INFO_SIGNATURE2   0xaabb0124
 
#define TEST_MESSAGE_MESSAGE   0x4455cdef
 

Typedefs

typedef struct _TEST_CONNECTION_INFO TEST_CONNECTION_INFO
 
typedef struct _TEST_CONNECTION_INFOPTEST_CONNECTION_INFO
 
typedef struct _TEST_MESSAGE TEST_MESSAGE
 
typedef struct _TEST_MESSAGEPTEST_MESSAGE
 

Functions

UINT CALLBACK ServerThread (_Inout_ PVOID Parameter)
 
UINT CALLBACK ClientThread (_Inout_ PVOID Parameter)
 
 START_TEST (NtAcceptConnectPort)
 

Variables

static UNICODE_STRING PortName = RTL_CONSTANT_STRING(L"\\NtdllApitestNtAcceptConnectPortTestPort")
 
static UINT ServerThreadId
 
static UINT ClientThreadId
 
static UCHAR Context
 

Macro Definition Documentation

◆ TEST_CONNECTION_INFO_SIGNATURE1

#define TEST_CONNECTION_INFO_SIGNATURE1   0xaabb0123

Definition at line 12 of file NtAcceptConnectPort.c.

◆ TEST_CONNECTION_INFO_SIGNATURE2

#define TEST_CONNECTION_INFO_SIGNATURE2   0xaabb0124

Definition at line 13 of file NtAcceptConnectPort.c.

◆ TEST_MESSAGE_MESSAGE

#define TEST_MESSAGE_MESSAGE   0x4455cdef

Definition at line 19 of file NtAcceptConnectPort.c.

Typedef Documentation

◆ PTEST_CONNECTION_INFO

◆ PTEST_MESSAGE

◆ TEST_CONNECTION_INFO

◆ TEST_MESSAGE

Function Documentation

◆ ClientThread()

UINT CALLBACK ClientThread ( _Inout_ PVOID  Parameter)

Definition at line 134 of file NtAcceptConnectPort.c.

136{
138 HANDLE PortHandle;
139 TEST_CONNECTION_INFO ConnectInfo;
140 ULONG ConnectInfoLength;
141 SECURITY_QUALITY_OF_SERVICE SecurityQos;
143
144 SecurityQos.Length = sizeof(SecurityQos);
146 SecurityQos.EffectiveOnly = TRUE;
148
149 /* Attempt to connect -- will be rejected */
151 ConnectInfoLength = sizeof(ConnectInfo);
152 PortHandle = (PVOID)(ULONG_PTR)0x55555555;
153 Status = NtConnectPort(&PortHandle,
154 &PortName,
155 &SecurityQos,
156 NULL,
157 NULL,
158 NULL,
159 &ConnectInfo,
160 &ConnectInfoLength);
162 ok(PortHandle == (PVOID)(ULONG_PTR)0x55555555, "PortHandle = %p\n", PortHandle);
163
164 /* Try again, this time it will be accepted */
166 ConnectInfoLength = sizeof(ConnectInfo);
167 Status = NtConnectPort(&PortHandle,
168 &PortName,
169 &SecurityQos,
170 NULL,
171 NULL,
172 NULL,
173 &ConnectInfo,
174 &ConnectInfoLength);
176 if (!NT_SUCCESS(Status))
177 {
178 skip("Failed to connect\n");
179 return 0;
180 }
181
182 RtlZeroMemory(&Message, sizeof(Message));
183 Message.Header.u1.s1.TotalLength = sizeof(Message);
184 Message.Header.u1.s1.DataLength = sizeof(Message.Message);
186 Status = NtRequestPort(PortHandle,
187 &Message.Header);
189
190 Status = NtClose(PortHandle);
192
193 return 0;
194}
static UNICODE_STRING PortName
#define TEST_MESSAGE_MESSAGE
#define TEST_CONNECTION_INFO_SIGNATURE2
#define TEST_CONNECTION_INFO_SIGNATURE1
#define ok_hex(expression, result)
Definition: atltest.h:94
#define ok(value,...)
Definition: atltest.h:57
#define skip(...)
Definition: atltest.h:64
LONG NTSTATUS
Definition: precomp.h:26
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
static const WCHAR Message[]
Definition: register.c:74
Status
Definition: gdiplustypes.h:25
@ SecurityIdentification
Definition: lsa.idl:56
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
Definition: obhandle.c:3402
NTSTATUS NTAPI NtConnectPort(OUT PHANDLE PortHandle, IN PUNICODE_STRING PortName, IN PSECURITY_QUALITY_OF_SERVICE SecurityQos, IN OUT PPORT_VIEW ClientView OPTIONAL, IN OUT PREMOTE_PORT_VIEW ServerView OPTIONAL, OUT PULONG MaxMessageLength OPTIONAL, IN OUT PVOID ConnectionInformation OPTIONAL, IN OUT PULONG ConnectionInformationLength OPTIONAL)
Definition: connect.c:777
NTSTATUS NTAPI NtRequestPort(IN HANDLE PortHandle, IN PPORT_MESSAGE LpcRequest)
Definition: send.c:440
#define STATUS_PORT_CONNECTION_REFUSED
Definition: ntstatus.h:301
#define STATUS_SUCCESS
Definition: shellext.h:65
SECURITY_CONTEXT_TRACKING_MODE ContextTrackingMode
Definition: lsa.idl:66
SECURITY_IMPERSONATION_LEVEL ImpersonationLevel
Definition: lsa.idl:65
void * PVOID
Definition: typedefs.h:50
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
uint32_t ULONG_PTR
Definition: typedefs.h:65
uint32_t ULONG
Definition: typedefs.h:59
#define SECURITY_STATIC_TRACKING
Definition: setypes.h:104

Referenced by DoWriteConsole(), LpcpCopyRequestData(), LpcpValidateClientPort(), NtAcceptConnectPort(), NtImpersonateClientOfPort(), and START_TEST().

◆ ServerThread()

UINT CALLBACK ServerThread ( _Inout_ PVOID  Parameter)

Definition at line 33 of file NtAcceptConnectPort.c.

35{
38 HANDLE PortHandle;
39 HANDLE ServerPortHandle = Parameter;
40
41 /* Listen, but refuse the connection */
42 RtlZeroMemory(&Message, sizeof(Message));
43 Status = NtListenPort(ServerPortHandle,
44 &Message.Header);
46
47 ok(Message.Header.u1.s1.TotalLength == RTL_SIZEOF_THROUGH_FIELD(TEST_MESSAGE, Message),
48 "TotalLength = %u, expected %lu\n",
49 Message.Header.u1.s1.TotalLength, RTL_SIZEOF_THROUGH_FIELD(TEST_MESSAGE, Message));
50 ok(Message.Header.u1.s1.DataLength == sizeof(TEST_CONNECTION_INFO),
51 "DataLength = %u\n", Message.Header.u1.s1.DataLength);
52 ok(Message.Header.u2.s2.Type == LPC_CONNECTION_REQUEST,
53 "Type = %x\n", Message.Header.u2.s2.Type);
54 ok(Message.Header.ClientId.UniqueProcess == UlongToHandle(GetCurrentProcessId()),
55 "UniqueProcess = %p, expected %lx\n",
56 Message.Header.ClientId.UniqueProcess, GetCurrentProcessId());
57 ok(Message.Header.ClientId.UniqueThread == UlongToHandle(ClientThreadId),
58 "UniqueThread = %p, expected %x\n",
59 Message.Header.ClientId.UniqueThread, ClientThreadId);
60 ok(Message.Message == TEST_CONNECTION_INFO_SIGNATURE1, "Message = %lx\n", Message.Message);
61
62 PortHandle = (PVOID)(ULONG_PTR)0x55555555;
63 Status = NtAcceptConnectPort(&PortHandle,
64 &Context,
65 &Message.Header,
66 FALSE,
67 NULL,
68 NULL);
70 ok(PortHandle == (PVOID)(ULONG_PTR)0x55555555, "PortHandle = %p\n", PortHandle);
71
72 /* Listen a second time, then accept */
73 RtlZeroMemory(&Message, sizeof(Message));
74 Status = NtListenPort(ServerPortHandle,
75 &Message.Header);
77
78 ok(Message.Header.u1.s1.TotalLength == RTL_SIZEOF_THROUGH_FIELD(TEST_MESSAGE, Message),
79 "TotalLength = %u, expected %lu\n",
80 Message.Header.u1.s1.TotalLength, RTL_SIZEOF_THROUGH_FIELD(TEST_MESSAGE, Message));
81 ok(Message.Header.u1.s1.DataLength == sizeof(TEST_CONNECTION_INFO),
82 "DataLength = %u\n", Message.Header.u1.s1.DataLength);
83 ok(Message.Header.u2.s2.Type == LPC_CONNECTION_REQUEST,
84 "Type = %x\n", Message.Header.u2.s2.Type);
85 ok(Message.Header.ClientId.UniqueProcess == UlongToHandle(GetCurrentProcessId()),
86 "UniqueProcess = %p, expected %lx\n",
87 Message.Header.ClientId.UniqueProcess, GetCurrentProcessId());
88 ok(Message.Header.ClientId.UniqueThread == UlongToHandle(ClientThreadId),
89 "UniqueThread = %p, expected %x\n",
90 Message.Header.ClientId.UniqueThread, ClientThreadId);
91 ok(Message.Message == TEST_CONNECTION_INFO_SIGNATURE2, "Message = %lx\n", Message.Message);
92
93 Status = NtAcceptConnectPort(&PortHandle,
94 &Context,
95 &Message.Header,
96 TRUE,
97 NULL,
98 NULL);
100
101 Status = NtCompleteConnectPort(PortHandle);
103
104 RtlZeroMemory(&Message, sizeof(Message));
105 Status = NtReplyWaitReceivePort(PortHandle,
106 NULL,
107 NULL,
108 &Message.Header);
110
111 ok(Message.Header.u1.s1.TotalLength == sizeof(Message),
112 "TotalLength = %u, expected %Iu\n",
113 Message.Header.u1.s1.TotalLength, sizeof(Message));
114 ok(Message.Header.u1.s1.DataLength == sizeof(Message.Message),
115 "DataLength = %u\n", Message.Header.u1.s1.DataLength);
116 ok(Message.Header.u2.s2.Type == LPC_DATAGRAM,
117 "Type = %x\n", Message.Header.u2.s2.Type);
118 ok(Message.Header.ClientId.UniqueProcess == UlongToHandle(GetCurrentProcessId()),
119 "UniqueProcess = %p, expected %lx\n",
120 Message.Header.ClientId.UniqueProcess, GetCurrentProcessId());
121 ok(Message.Header.ClientId.UniqueThread == UlongToHandle(ClientThreadId),
122 "UniqueThread = %p, expected %x\n",
123 Message.Header.ClientId.UniqueThread, ClientThreadId);
124 ok(Message.Message == TEST_MESSAGE_MESSAGE, "Message = %lx\n", Message.Message);
125
126 Status = NtClose(PortHandle);
128
129 return 0;
130}
static UINT ClientThreadId
#define UlongToHandle(ul)
Definition: basetsd.h:97
NTSTATUS NTAPI NtAcceptConnectPort(OUT PHANDLE PortHandle, IN PVOID PortContext OPTIONAL, IN PPORT_MESSAGE ReplyMessage, IN BOOLEAN AcceptConnection, IN OUT PPORT_VIEW ServerView OPTIONAL, OUT PREMOTE_PORT_VIEW ClientView OPTIONAL)
Definition: complete.c:40
NTSTATUS NTAPI NtCompleteConnectPort(IN HANDLE PortHandle)
Definition: complete.c:423
#define FALSE
Definition: types.h:117
#define LPC_DATAGRAM
Definition: port.c:95
#define LPC_CONNECTION_REQUEST
Definition: port.c:102
#define RTL_SIZEOF_THROUGH_FIELD(type, field)
Definition: ntbasedef.h:672
NTSTATUS NTAPI NtListenPort(IN HANDLE PortHandle, OUT PPORT_MESSAGE ConnectMessage)
Definition: listen.c:22
NTSTATUS NTAPI NtReplyWaitReceivePort(IN HANDLE PortHandle, OUT PVOID *PortContext OPTIONAL, IN PPORT_MESSAGE ReplyMessage OPTIONAL, OUT PPORT_MESSAGE ReceiveMessage)
Definition: reply.c:743
DWORD WINAPI GetCurrentProcessId(void)
Definition: proc.c:1158
_Inout_opt_ PVOID Parameter
Definition: rtltypes.h:323

Referenced by CsrApiPortInitialize(), SeImpersonateClient(), SeImpersonateClientEx(), and START_TEST().

◆ START_TEST()

START_TEST ( NtAcceptConnectPort  )

Definition at line 196 of file NtAcceptConnectPort.c.

197{
200 HANDLE PortHandle;
201 HANDLE ThreadHandles[2];
202
204 &PortName,
206 NULL,
207 NULL);
208 Status = NtCreatePort(&PortHandle,
210 sizeof(TEST_CONNECTION_INFO),
211 sizeof(TEST_MESSAGE),
212 2 * sizeof(TEST_MESSAGE));
214 if (!NT_SUCCESS(Status))
215 {
216 skip("Failed to create port\n");
217 return;
218 }
219
220 ThreadHandles[0] = (HANDLE)_beginthreadex(NULL,
221 0,
223 PortHandle,
224 0,
226 ok(ThreadHandles[0] != NULL, "_beginthreadex failed\n");
227
228 ThreadHandles[1] = (HANDLE)_beginthreadex(NULL,
229 0,
231 PortHandle,
232 0,
234 ok(ThreadHandles[1] != NULL, "_beginthreadex failed\n");
235
237 ThreadHandles,
238 WaitAll,
239 FALSE,
240 NULL);
242
243 Status = NtClose(ThreadHandles[0]);
245 Status = NtClose(ThreadHandles[1]);
247
248 Status = NtClose(PortHandle);
250}
static UINT ServerThreadId
UINT CALLBACK ClientThread(_Inout_ PVOID Parameter)
UINT CALLBACK ServerThread(_Inout_ PVOID Parameter)
#define RTL_NUMBER_OF(x)
Definition: RtlRegistry.c:12
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:36
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
@ WaitAll
NTSTATUS NTAPI NtCreatePort(OUT PHANDLE PortHandle, IN POBJECT_ATTRIBUTES ObjectAttributes, IN ULONG MaxConnectInfoLength, IN ULONG MaxDataLength, IN ULONG MaxPoolUsage)
Definition: create.c:222
NTSTATUS NTAPI NtWaitForMultipleObjects(IN ULONG ObjectCount, IN PHANDLE HandleArray, IN WAIT_TYPE WaitType, IN BOOLEAN Alertable, IN PLARGE_INTEGER TimeOut OPTIONAL)
Definition: obwait.c:46
_CRTIMP uintptr_t __cdecl _beginthreadex(_In_opt_ void *_Security, _In_ unsigned _StackSize, _In_ unsigned(__stdcall *_StartAddress)(void *), _In_opt_ void *_ArgList, _In_ unsigned _InitFlag, _Out_opt_ unsigned *_ThrdAddr)
PVOID HANDLE
Definition: typedefs.h:73

Variable Documentation

◆ ClientThreadId

UINT ClientThreadId
static

Definition at line 28 of file NtAcceptConnectPort.c.

Referenced by ServerThread(), and START_TEST().

◆ Context

UCHAR Context
static

Definition at line 29 of file NtAcceptConnectPort.c.

◆ PortName

◆ ServerThreadId

UINT ServerThreadId
static

Definition at line 27 of file NtAcceptConnectPort.c.

Referenced by START_TEST().