2 * Unit tests for named pipe functions in Wine
4 * Copyright (c) 2002 Dan Kegel
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
31 #include "wine/test.h"
33 #define PIPENAME "\\\\.\\PiPe\\tests_pipe.c"
35 #define NB_SERVER_LOOPS 8
37 static HANDLE alarm_event
;
38 static BOOL (WINAPI
*pDuplicateTokenEx
)(HANDLE
,DWORD
,LPSECURITY_ATTRIBUTES
,
39 SECURITY_IMPERSONATION_LEVEL
,TOKEN_TYPE
,PHANDLE
);
42 static void test_CreateNamedPipe(int pipemode
)
46 static const char obuf
[] = "Bit Bucket";
47 static const char obuf2
[] = "More bits";
54 if (pipemode
== PIPE_TYPE_BYTE
)
55 trace("test_CreateNamedPipe starting in byte mode\n");
57 trace("test_CreateNamedPipe starting in message mode\n");
58 /* Bad parameter checks */
59 hnp
= CreateNamedPipe("not a named pipe", PIPE_ACCESS_DUPLEX
, pipemode
| PIPE_WAIT
,
60 /* nMaxInstances */ 1,
61 /* nOutBufSize */ 1024,
62 /* nInBufSize */ 1024,
63 /* nDefaultWait */ NMPWAIT_USE_DEFAULT_WAIT
,
64 /* lpSecurityAttrib */ NULL
);
65 ok(hnp
== INVALID_HANDLE_VALUE
&& GetLastError() == ERROR_INVALID_NAME
,
66 "CreateNamedPipe should fail if name doesn't start with \\\\.\\pipe\n");
68 hnp
= CreateNamedPipe(NULL
,
69 PIPE_ACCESS_DUPLEX
, pipemode
| PIPE_WAIT
,
70 1, 1024, 1024, NMPWAIT_USE_DEFAULT_WAIT
, NULL
);
71 ok(hnp
== INVALID_HANDLE_VALUE
&& GetLastError() == ERROR_PATH_NOT_FOUND
,
72 "CreateNamedPipe should fail if name is NULL\n");
74 hFile
= CreateFileA(PIPENAME
, GENERIC_READ
| GENERIC_WRITE
, 0, NULL
, OPEN_EXISTING
, 0, 0);
75 ok(hFile
== INVALID_HANDLE_VALUE
76 && GetLastError() == ERROR_FILE_NOT_FOUND
,
77 "connecting to nonexistent named pipe should fail with ERROR_FILE_NOT_FOUND\n");
79 /* Functional checks */
81 hnp
= CreateNamedPipe(PIPENAME
, PIPE_ACCESS_DUPLEX
, pipemode
| PIPE_WAIT
,
82 /* nMaxInstances */ 1,
83 /* nOutBufSize */ 1024,
84 /* nInBufSize */ 1024,
85 /* nDefaultWait */ NMPWAIT_USE_DEFAULT_WAIT
,
86 /* lpSecurityAttrib */ NULL
);
87 ok(hnp
!= INVALID_HANDLE_VALUE
, "CreateNamedPipe failed\n");
89 ok(WaitNamedPipeA(PIPENAME
, 2000), "WaitNamedPipe failed (%d)\n", GetLastError());
91 hFile
= CreateFileA(PIPENAME
, GENERIC_READ
| GENERIC_WRITE
, 0, NULL
, OPEN_EXISTING
, 0, 0);
92 ok(hFile
!= INVALID_HANDLE_VALUE
, "CreateFile failed (%d)\n", GetLastError());
94 ok(!WaitNamedPipeA(PIPENAME
, 1000), "WaitNamedPipe succeeded\n");
95 ok(GetLastError() == ERROR_SEM_TIMEOUT
, "wrong error %u\n", GetLastError());
97 /* don't try to do i/o if one side couldn't be opened, as it hangs */
98 if (hFile
!= INVALID_HANDLE_VALUE
) {
101 /* Make sure we can read and write a few bytes in both directions */
102 memset(ibuf
, 0, sizeof(ibuf
));
103 ok(WriteFile(hnp
, obuf
, sizeof(obuf
), &written
, NULL
), "WriteFile\n");
104 ok(written
== sizeof(obuf
), "write file len 1\n");
105 ok(PeekNamedPipe(hFile
, NULL
, 0, NULL
, &readden
, NULL
), "Peek\n");
106 ok(readden
== sizeof(obuf
), "peek 1 got %d bytes\n", readden
);
107 ok(ReadFile(hFile
, ibuf
, sizeof(ibuf
), &readden
, NULL
), "ReadFile\n");
108 ok(readden
== sizeof(obuf
), "read 1 got %d bytes\n", readden
);
109 ok(memcmp(obuf
, ibuf
, written
) == 0, "content 1 check\n");
111 memset(ibuf
, 0, sizeof(ibuf
));
112 ok(WriteFile(hFile
, obuf2
, sizeof(obuf2
), &written
, NULL
), "WriteFile\n");
113 ok(written
== sizeof(obuf2
), "write file len 2\n");
114 ok(PeekNamedPipe(hnp
, NULL
, 0, NULL
, &readden
, NULL
), "Peek\n");
115 ok(readden
== sizeof(obuf2
), "peek 2 got %d bytes\n", readden
);
116 ok(PeekNamedPipe(hnp
, (LPVOID
)1, 0, NULL
, &readden
, NULL
), "Peek\n");
117 ok(readden
== sizeof(obuf2
), "peek 2 got %d bytes\n", readden
);
118 ok(ReadFile(hnp
, ibuf
, sizeof(ibuf
), &readden
, NULL
), "ReadFile\n");
119 ok(readden
== sizeof(obuf2
), "read 2 got %d bytes\n", readden
);
120 ok(memcmp(obuf2
, ibuf
, written
) == 0, "content 2 check\n");
122 /* Test reading of multiple writes */
123 memset(ibuf
, 0, sizeof(ibuf
));
124 ok(WriteFile(hnp
, obuf
, sizeof(obuf
), &written
, NULL
), "WriteFile3a\n");
125 ok(written
== sizeof(obuf
), "write file len 3a\n");
126 ok(WriteFile(hnp
, obuf2
, sizeof(obuf2
), &written
, NULL
), " WriteFile3b\n");
127 ok(written
== sizeof(obuf2
), "write file len 3b\n");
128 ok(PeekNamedPipe(hFile
, ibuf
, sizeof(ibuf
), &readden
, &avail
, NULL
), "Peek3\n");
129 if (pipemode
== PIPE_TYPE_BYTE
) {
130 if (readden
!= sizeof(obuf
)) /* Linux only returns the first message */
131 ok(readden
== sizeof(obuf
) + sizeof(obuf2
), "peek3 got %d bytes\n", readden
);
133 todo_wine
ok(readden
== sizeof(obuf
) + sizeof(obuf2
), "peek3 got %d bytes\n", readden
);
137 if (readden
!= sizeof(obuf
) + sizeof(obuf2
)) /* MacOS returns both messages */
138 ok(readden
== sizeof(obuf
), "peek3 got %d bytes\n", readden
);
140 todo_wine
ok(readden
== sizeof(obuf
), "peek3 got %d bytes\n", readden
);
142 if (avail
!= sizeof(obuf
)) /* older Linux kernels only return the first write here */
143 ok(avail
== sizeof(obuf
) + sizeof(obuf2
), "peek3 got %d bytes available\n", avail
);
145 ok(memcmp(obuf
, pbuf
, sizeof(obuf
)) == 0, "pipe content 3a check\n");
146 if (pipemode
== PIPE_TYPE_BYTE
&& readden
>= sizeof(obuf
)+sizeof(obuf2
)) {
147 pbuf
+= sizeof(obuf
);
148 ok(memcmp(obuf2
, pbuf
, sizeof(obuf2
)) == 0, "pipe content 3b check\n");
150 ok(ReadFile(hFile
, ibuf
, sizeof(ibuf
), &readden
, NULL
), "ReadFile\n");
151 ok(readden
== sizeof(obuf
) + sizeof(obuf2
), "read 3 got %d bytes\n", readden
);
153 ok(memcmp(obuf
, pbuf
, sizeof(obuf
)) == 0, "content 3a check\n");
154 pbuf
+= sizeof(obuf
);
155 ok(memcmp(obuf2
, pbuf
, sizeof(obuf2
)) == 0, "content 3b check\n");
157 /* Multiple writes in the reverse direction */
158 memset(ibuf
, 0, sizeof(ibuf
));
159 ok(WriteFile(hFile
, obuf
, sizeof(obuf
), &written
, NULL
), "WriteFile4a\n");
160 ok(written
== sizeof(obuf
), "write file len 4a\n");
161 ok(WriteFile(hFile
, obuf2
, sizeof(obuf2
), &written
, NULL
), " WriteFile4b\n");
162 ok(written
== sizeof(obuf2
), "write file len 4b\n");
163 ok(PeekNamedPipe(hnp
, ibuf
, sizeof(ibuf
), &readden
, &avail
, NULL
), "Peek4\n");
164 if (pipemode
== PIPE_TYPE_BYTE
) {
165 if (readden
!= sizeof(obuf
)) /* Linux only returns the first message */
166 /* should return all 23 bytes */
167 ok(readden
== sizeof(obuf
) + sizeof(obuf2
), "peek4 got %d bytes\n", readden
);
169 todo_wine
ok(readden
== sizeof(obuf
) + sizeof(obuf2
), "peek4 got %d bytes\n", readden
);
173 if (readden
!= sizeof(obuf
) + sizeof(obuf2
)) /* MacOS returns both messages */
174 ok(readden
== sizeof(obuf
), "peek4 got %d bytes\n", readden
);
176 todo_wine
ok(readden
== sizeof(obuf
), "peek4 got %d bytes\n", readden
);
178 if (avail
!= sizeof(obuf
)) /* older Linux kernels only return the first write here */
179 ok(avail
== sizeof(obuf
) + sizeof(obuf2
), "peek4 got %d bytes available\n", avail
);
181 ok(memcmp(obuf
, pbuf
, sizeof(obuf
)) == 0, "pipe content 4a check\n");
182 if (pipemode
== PIPE_TYPE_BYTE
&& readden
>= sizeof(obuf
)+sizeof(obuf2
)) {
183 pbuf
+= sizeof(obuf
);
184 ok(memcmp(obuf2
, pbuf
, sizeof(obuf2
)) == 0, "pipe content 4b check\n");
186 ok(ReadFile(hnp
, ibuf
, sizeof(ibuf
), &readden
, NULL
), "ReadFile\n");
187 if (pipemode
== PIPE_TYPE_BYTE
) {
188 ok(readden
== sizeof(obuf
) + sizeof(obuf2
), "read 4 got %d bytes\n", readden
);
192 ok(readden
== sizeof(obuf
), "read 4 got %d bytes\n", readden
);
196 ok(memcmp(obuf
, pbuf
, sizeof(obuf
)) == 0, "content 4a check\n");
197 if (pipemode
== PIPE_TYPE_BYTE
) {
198 pbuf
+= sizeof(obuf
);
199 ok(memcmp(obuf2
, pbuf
, sizeof(obuf2
)) == 0, "content 4b check\n");
202 /* Test reading of multiple writes after a mode change
203 (CreateFile always creates a byte mode pipe) */
204 lpmode
= PIPE_READMODE_MESSAGE
;
205 if (pipemode
== PIPE_TYPE_BYTE
) {
206 /* trying to change the client end of a byte pipe to message mode should fail */
207 ok(!SetNamedPipeHandleState(hFile
, &lpmode
, NULL
, NULL
), "Change mode\n");
211 ok(SetNamedPipeHandleState(hFile
, &lpmode
, NULL
, NULL
), "Change mode\n");
214 memset(ibuf
, 0, sizeof(ibuf
));
215 ok(WriteFile(hnp
, obuf
, sizeof(obuf
), &written
, NULL
), "WriteFile5a\n");
216 ok(written
== sizeof(obuf
), "write file len 3a\n");
217 ok(WriteFile(hnp
, obuf2
, sizeof(obuf2
), &written
, NULL
), " WriteFile5b\n");
218 ok(written
== sizeof(obuf2
), "write file len 3b\n");
219 ok(PeekNamedPipe(hFile
, ibuf
, sizeof(ibuf
), &readden
, &avail
, NULL
), "Peek5\n");
220 if (readden
!= sizeof(obuf
) + sizeof(obuf2
)) /* MacOS returns both writes */
221 ok(readden
== sizeof(obuf
), "peek5 got %d bytes\n", readden
);
223 todo_wine
ok(readden
== sizeof(obuf
), "peek5 got %d bytes\n", readden
);
224 if (avail
!= sizeof(obuf
)) /* older Linux kernels only return the first write here */
225 ok(avail
== sizeof(obuf
) + sizeof(obuf2
), "peek5 got %d bytes available\n", avail
);
227 todo_wine
ok(avail
== sizeof(obuf
) + sizeof(obuf2
), "peek5 got %d bytes available\n", avail
);
229 ok(memcmp(obuf
, pbuf
, sizeof(obuf
)) == 0, "content 5a check\n");
230 ok(ReadFile(hFile
, ibuf
, sizeof(ibuf
), &readden
, NULL
), "ReadFile\n");
232 ok(readden
== sizeof(obuf
), "read 5 got %d bytes\n", readden
);
235 ok(memcmp(obuf
, pbuf
, sizeof(obuf
)) == 0, "content 5a check\n");
237 /* Multiple writes in the reverse direction */
238 /* the write of obuf2 from write4 should still be in the buffer */
239 ok(PeekNamedPipe(hnp
, ibuf
, sizeof(ibuf
), &readden
, &avail
, NULL
), "Peek6a\n");
241 ok(readden
== sizeof(obuf2
), "peek6a got %d bytes\n", readden
);
242 ok(avail
== sizeof(obuf2
), "peek6a got %d bytes available\n", avail
);
245 ok(ReadFile(hnp
, ibuf
, sizeof(ibuf
), &readden
, NULL
), "ReadFile\n");
246 ok(readden
== sizeof(obuf2
), "read 6a got %d bytes\n", readden
);
248 ok(memcmp(obuf2
, pbuf
, sizeof(obuf2
)) == 0, "content 6a check\n");
250 memset(ibuf
, 0, sizeof(ibuf
));
251 ok(WriteFile(hFile
, obuf
, sizeof(obuf
), &written
, NULL
), "WriteFile6a\n");
252 ok(written
== sizeof(obuf
), "write file len 6a\n");
253 ok(WriteFile(hFile
, obuf2
, sizeof(obuf2
), &written
, NULL
), " WriteFile6b\n");
254 ok(written
== sizeof(obuf2
), "write file len 6b\n");
255 ok(PeekNamedPipe(hnp
, ibuf
, sizeof(ibuf
), &readden
, &avail
, NULL
), "Peek6\n");
256 if (readden
!= sizeof(obuf
) + sizeof(obuf2
)) /* MacOS returns both writes */
257 ok(readden
== sizeof(obuf
), "peek6 got %d bytes\n", readden
);
259 todo_wine
ok(readden
== sizeof(obuf
), "peek6 got %d bytes\n", readden
);
260 if (avail
!= sizeof(obuf
)) /* older Linux kernels only return the first write here */
261 ok(avail
== sizeof(obuf
) + sizeof(obuf2
), "peek6b got %d bytes available\n", avail
);
263 ok(memcmp(obuf
, pbuf
, sizeof(obuf
)) == 0, "content 6a check\n");
264 ok(ReadFile(hnp
, ibuf
, sizeof(ibuf
), &readden
, NULL
), "ReadFile\n");
266 ok(readden
== sizeof(obuf
), "read 6b got %d bytes\n", readden
);
269 ok(memcmp(obuf
, pbuf
, sizeof(obuf
)) == 0, "content 6a check\n");
272 /* Picky conformance tests */
274 /* Verify that you can't connect to pipe again
275 * until server calls DisconnectNamedPipe+ConnectNamedPipe
276 * or creates a new pipe
277 * case 1: other client not yet closed
279 hFile2
= CreateFileA(PIPENAME
, GENERIC_READ
| GENERIC_WRITE
, 0, NULL
, OPEN_EXISTING
, 0, 0);
280 ok(hFile2
== INVALID_HANDLE_VALUE
,
281 "connecting to named pipe after other client closes but before DisconnectNamedPipe should fail\n");
282 ok(GetLastError() == ERROR_PIPE_BUSY
,
283 "connecting to named pipe before other client closes should fail with ERROR_PIPE_BUSY\n");
285 ok(CloseHandle(hFile
), "CloseHandle\n");
287 /* case 2: other client already closed */
288 hFile
= CreateFileA(PIPENAME
, GENERIC_READ
| GENERIC_WRITE
, 0, NULL
, OPEN_EXISTING
, 0, 0);
289 ok(hFile
== INVALID_HANDLE_VALUE
,
290 "connecting to named pipe after other client closes but before DisconnectNamedPipe should fail\n");
291 ok(GetLastError() == ERROR_PIPE_BUSY
,
292 "connecting to named pipe after other client closes but before DisconnectNamedPipe should fail with ERROR_PIPE_BUSY\n");
294 ok(DisconnectNamedPipe(hnp
), "DisconnectNamedPipe\n");
296 /* case 3: server has called DisconnectNamedPipe but not ConnectNamed Pipe */
297 hFile
= CreateFileA(PIPENAME
, GENERIC_READ
| GENERIC_WRITE
, 0, NULL
, OPEN_EXISTING
, 0, 0);
298 ok(hFile
== INVALID_HANDLE_VALUE
,
299 "connecting to named pipe after other client closes but before DisconnectNamedPipe should fail\n");
300 ok(GetLastError() == ERROR_PIPE_BUSY
,
301 "connecting to named pipe after other client closes but before ConnectNamedPipe should fail with ERROR_PIPE_BUSY\n");
303 /* to be complete, we'd call ConnectNamedPipe here and loop,
304 * but by default that's blocking, so we'd either have
305 * to turn on the uncommon nonblocking mode, or
306 * use another thread.
310 ok(CloseHandle(hnp
), "CloseHandle\n");
312 trace("test_CreateNamedPipe returning\n");
315 static void test_CreateNamedPipe_instances_must_match(void)
319 /* Check no mismatch */
320 hnp
= CreateNamedPipe(PIPENAME
, PIPE_ACCESS_DUPLEX
, PIPE_TYPE_BYTE
| PIPE_WAIT
,
321 /* nMaxInstances */ 2,
322 /* nOutBufSize */ 1024,
323 /* nInBufSize */ 1024,
324 /* nDefaultWait */ NMPWAIT_USE_DEFAULT_WAIT
,
325 /* lpSecurityAttrib */ NULL
);
326 ok(hnp
!= INVALID_HANDLE_VALUE
, "CreateNamedPipe failed\n");
328 hnp2
= CreateNamedPipe(PIPENAME
, PIPE_ACCESS_DUPLEX
, PIPE_TYPE_BYTE
| PIPE_WAIT
,
329 /* nMaxInstances */ 2,
330 /* nOutBufSize */ 1024,
331 /* nInBufSize */ 1024,
332 /* nDefaultWait */ NMPWAIT_USE_DEFAULT_WAIT
,
333 /* lpSecurityAttrib */ NULL
);
334 ok(hnp2
!= INVALID_HANDLE_VALUE
, "CreateNamedPipe failed\n");
336 ok(CloseHandle(hnp
), "CloseHandle\n");
337 ok(CloseHandle(hnp2
), "CloseHandle\n");
339 /* Check nMaxInstances */
340 hnp
= CreateNamedPipe(PIPENAME
, PIPE_ACCESS_DUPLEX
, PIPE_TYPE_BYTE
| PIPE_WAIT
,
341 /* nMaxInstances */ 1,
342 /* nOutBufSize */ 1024,
343 /* nInBufSize */ 1024,
344 /* nDefaultWait */ NMPWAIT_USE_DEFAULT_WAIT
,
345 /* lpSecurityAttrib */ NULL
);
346 ok(hnp
!= INVALID_HANDLE_VALUE
, "CreateNamedPipe failed\n");
348 hnp2
= CreateNamedPipe(PIPENAME
, PIPE_ACCESS_DUPLEX
, PIPE_TYPE_BYTE
| PIPE_WAIT
,
349 /* nMaxInstances */ 1,
350 /* nOutBufSize */ 1024,
351 /* nInBufSize */ 1024,
352 /* nDefaultWait */ NMPWAIT_USE_DEFAULT_WAIT
,
353 /* lpSecurityAttrib */ NULL
);
354 ok(hnp2
== INVALID_HANDLE_VALUE
355 && GetLastError() == ERROR_PIPE_BUSY
, "nMaxInstances not obeyed\n");
357 ok(CloseHandle(hnp
), "CloseHandle\n");
359 /* Check PIPE_ACCESS_* */
360 hnp
= CreateNamedPipe(PIPENAME
, PIPE_ACCESS_DUPLEX
, PIPE_TYPE_BYTE
| PIPE_WAIT
,
361 /* nMaxInstances */ 2,
362 /* nOutBufSize */ 1024,
363 /* nInBufSize */ 1024,
364 /* nDefaultWait */ NMPWAIT_USE_DEFAULT_WAIT
,
365 /* lpSecurityAttrib */ NULL
);
366 ok(hnp
!= INVALID_HANDLE_VALUE
, "CreateNamedPipe failed\n");
368 hnp2
= CreateNamedPipe(PIPENAME
, PIPE_ACCESS_INBOUND
, PIPE_TYPE_BYTE
| PIPE_WAIT
,
369 /* nMaxInstances */ 1,
370 /* nOutBufSize */ 1024,
371 /* nInBufSize */ 1024,
372 /* nDefaultWait */ NMPWAIT_USE_DEFAULT_WAIT
,
373 /* lpSecurityAttrib */ NULL
);
374 ok(hnp2
== INVALID_HANDLE_VALUE
375 && GetLastError() == ERROR_ACCESS_DENIED
, "PIPE_ACCESS_* mismatch allowed\n");
377 ok(CloseHandle(hnp
), "CloseHandle\n");
382 /** implementation of alarm() */
383 static DWORD CALLBACK
alarmThreadMain(LPVOID arg
)
385 DWORD_PTR timeout
= (DWORD_PTR
) arg
;
386 trace("alarmThreadMain\n");
387 if (WaitForSingleObject( alarm_event
, timeout
) == WAIT_TIMEOUT
)
389 ok(FALSE
, "alarm\n");
395 HANDLE hnp
= INVALID_HANDLE_VALUE
;
397 /** Trivial byte echo server - disconnects after each session */
398 static DWORD CALLBACK
serverThreadMain1(LPVOID arg
)
402 trace("serverThreadMain1 start\n");
403 /* Set up a simple echo server */
404 hnp
= CreateNamedPipe(PIPENAME
"serverThreadMain1", PIPE_ACCESS_DUPLEX
,
405 PIPE_TYPE_BYTE
| PIPE_WAIT
,
406 /* nMaxInstances */ 1,
407 /* nOutBufSize */ 1024,
408 /* nInBufSize */ 1024,
409 /* nDefaultWait */ NMPWAIT_USE_DEFAULT_WAIT
,
410 /* lpSecurityAttrib */ NULL
);
412 ok(hnp
!= INVALID_HANDLE_VALUE
, "CreateNamedPipe failed\n");
413 for (i
= 0; i
< NB_SERVER_LOOPS
; i
++) {
419 /* Wait for client to connect */
420 trace("Server calling ConnectNamedPipe...\n");
421 ok(ConnectNamedPipe(hnp
, NULL
)
422 || GetLastError() == ERROR_PIPE_CONNECTED
, "ConnectNamedPipe\n");
423 trace("ConnectNamedPipe returned.\n");
425 /* Echo bytes once */
426 memset(buf
, 0, sizeof(buf
));
428 trace("Server reading...\n");
429 success
= ReadFile(hnp
, buf
, sizeof(buf
), &readden
, NULL
);
430 trace("Server done reading.\n");
431 ok(success
, "ReadFile\n");
432 ok(readden
, "short read\n");
434 trace("Server writing...\n");
435 ok(WriteFile(hnp
, buf
, readden
, &written
, NULL
), "WriteFile\n");
436 trace("Server done writing.\n");
437 ok(written
== readden
, "write file len\n");
439 /* finish this connection, wait for next one */
440 ok(FlushFileBuffers(hnp
), "FlushFileBuffers\n");
441 trace("Server done flushing.\n");
442 ok(DisconnectNamedPipe(hnp
), "DisconnectNamedPipe\n");
443 trace("Server done disconnecting.\n");
448 /** Trivial byte echo server - closes after each connection */
449 static DWORD CALLBACK
serverThreadMain2(LPVOID arg
)
454 trace("serverThreadMain2\n");
455 /* Set up a simple echo server */
456 hnp
= CreateNamedPipe(PIPENAME
"serverThreadMain2", PIPE_ACCESS_DUPLEX
,
457 PIPE_TYPE_BYTE
| PIPE_WAIT
,
458 /* nMaxInstances */ 2,
459 /* nOutBufSize */ 1024,
460 /* nInBufSize */ 1024,
461 /* nDefaultWait */ NMPWAIT_USE_DEFAULT_WAIT
,
462 /* lpSecurityAttrib */ NULL
);
463 ok(hnp
!= INVALID_HANDLE_VALUE
, "CreateNamedPipe failed\n");
465 for (i
= 0; i
< NB_SERVER_LOOPS
; i
++) {
471 /* Wait for client to connect */
472 trace("Server calling ConnectNamedPipe...\n");
473 ok(ConnectNamedPipe(hnp
, NULL
)
474 || GetLastError() == ERROR_PIPE_CONNECTED
, "ConnectNamedPipe\n");
475 trace("ConnectNamedPipe returned.\n");
477 /* Echo bytes once */
478 memset(buf
, 0, sizeof(buf
));
480 trace("Server reading...\n");
481 success
= ReadFile(hnp
, buf
, sizeof(buf
), &readden
, NULL
);
482 trace("Server done reading.\n");
483 ok(success
, "ReadFile\n");
485 trace("Server writing...\n");
486 ok(WriteFile(hnp
, buf
, readden
, &written
, NULL
), "WriteFile\n");
487 trace("Server done writing.\n");
488 ok(written
== readden
, "write file len\n");
490 /* finish this connection, wait for next one */
491 ok(FlushFileBuffers(hnp
), "FlushFileBuffers\n");
492 ok(DisconnectNamedPipe(hnp
), "DisconnectNamedPipe\n");
494 /* Set up next echo server */
496 CreateNamedPipe(PIPENAME
"serverThreadMain2", PIPE_ACCESS_DUPLEX
,
497 PIPE_TYPE_BYTE
| PIPE_WAIT
,
498 /* nMaxInstances */ 2,
499 /* nOutBufSize */ 1024,
500 /* nInBufSize */ 1024,
501 /* nDefaultWait */ NMPWAIT_USE_DEFAULT_WAIT
,
502 /* lpSecurityAttrib */ NULL
);
504 ok(hnpNext
!= INVALID_HANDLE_VALUE
, "CreateNamedPipe failed\n");
506 ok(CloseHandle(hnp
), "CloseHandle\n");
512 /** Trivial byte echo server - uses overlapped named pipe calls */
513 static DWORD CALLBACK
serverThreadMain3(LPVOID arg
)
518 trace("serverThreadMain3\n");
519 /* Set up a simple echo server */
520 hnp
= CreateNamedPipe(PIPENAME
"serverThreadMain3", PIPE_ACCESS_DUPLEX
| FILE_FLAG_OVERLAPPED
,
521 PIPE_TYPE_BYTE
| PIPE_WAIT
,
522 /* nMaxInstances */ 1,
523 /* nOutBufSize */ 1024,
524 /* nInBufSize */ 1024,
525 /* nDefaultWait */ NMPWAIT_USE_DEFAULT_WAIT
,
526 /* lpSecurityAttrib */ NULL
);
527 ok(hnp
!= INVALID_HANDLE_VALUE
, "CreateNamedPipe failed\n");
529 hEvent
= CreateEvent(NULL
, /* security attribute */
530 TRUE
, /* manual reset event */
531 FALSE
, /* initial state */
533 ok(hEvent
!= NULL
, "CreateEvent\n");
535 for (i
= 0; i
< NB_SERVER_LOOPS
; i
++) {
542 int letWFSOEwait
= (i
& 2);
543 int letGORwait
= (i
& 1);
546 memset(&oOverlap
, 0, sizeof(oOverlap
));
547 oOverlap
.hEvent
= hEvent
;
549 /* Wait for client to connect */
551 trace("Server calling non-overlapped ConnectNamedPipe on overlapped pipe...\n");
552 success
= ConnectNamedPipe(hnp
, NULL
);
553 err
= GetLastError();
554 ok(success
|| (err
== ERROR_PIPE_CONNECTED
), "ConnectNamedPipe failed: %d\n", err
);
555 trace("ConnectNamedPipe operation complete.\n");
557 trace("Server calling overlapped ConnectNamedPipe...\n");
558 success
= ConnectNamedPipe(hnp
, &oOverlap
);
559 err
= GetLastError();
560 ok(!success
&& (err
== ERROR_IO_PENDING
|| err
== ERROR_PIPE_CONNECTED
), "overlapped ConnectNamedPipe\n");
561 trace("overlapped ConnectNamedPipe returned.\n");
562 if (!success
&& (err
== ERROR_IO_PENDING
)) {
567 ret
= WaitForSingleObjectEx(hEvent
, INFINITE
, TRUE
);
568 } while (ret
== WAIT_IO_COMPLETION
);
569 ok(ret
== 0, "wait ConnectNamedPipe returned %x\n", ret
);
571 success
= GetOverlappedResult(hnp
, &oOverlap
, &dummy
, letGORwait
);
572 if (!letGORwait
&& !letWFSOEwait
&& !success
) {
573 ok(GetLastError() == ERROR_IO_INCOMPLETE
, "GetOverlappedResult\n");
574 success
= GetOverlappedResult(hnp
, &oOverlap
, &dummy
, TRUE
);
577 ok(success
|| (err
== ERROR_PIPE_CONNECTED
), "GetOverlappedResult ConnectNamedPipe\n");
578 trace("overlapped ConnectNamedPipe operation complete.\n");
581 /* Echo bytes once */
582 memset(buf
, 0, sizeof(buf
));
584 trace("Server reading...\n");
585 success
= ReadFile(hnp
, buf
, sizeof(buf
), &readden
, &oOverlap
);
586 trace("Server ReadFile returned...\n");
587 err
= GetLastError();
588 ok(success
|| err
== ERROR_IO_PENDING
, "overlapped ReadFile\n");
589 trace("overlapped ReadFile returned.\n");
590 if (!success
&& (err
== ERROR_IO_PENDING
)) {
595 ret
= WaitForSingleObjectEx(hEvent
, INFINITE
, TRUE
);
596 } while (ret
== WAIT_IO_COMPLETION
);
597 ok(ret
== 0, "wait ReadFile returned %x\n", ret
);
599 success
= GetOverlappedResult(hnp
, &oOverlap
, &readden
, letGORwait
);
600 if (!letGORwait
&& !letWFSOEwait
&& !success
) {
601 ok(GetLastError() == ERROR_IO_INCOMPLETE
, "GetOverlappedResult\n");
602 success
= GetOverlappedResult(hnp
, &oOverlap
, &readden
, TRUE
);
605 trace("Server done reading.\n");
606 ok(success
, "overlapped ReadFile\n");
608 trace("Server writing...\n");
609 success
= WriteFile(hnp
, buf
, readden
, &written
, &oOverlap
);
610 trace("Server WriteFile returned...\n");
611 err
= GetLastError();
612 ok(success
|| err
== ERROR_IO_PENDING
, "overlapped WriteFile\n");
613 trace("overlapped WriteFile returned.\n");
614 if (!success
&& (err
== ERROR_IO_PENDING
)) {
619 ret
= WaitForSingleObjectEx(hEvent
, INFINITE
, TRUE
);
620 } while (ret
== WAIT_IO_COMPLETION
);
621 ok(ret
== 0, "wait WriteFile returned %x\n", ret
);
623 success
= GetOverlappedResult(hnp
, &oOverlap
, &written
, letGORwait
);
624 if (!letGORwait
&& !letWFSOEwait
&& !success
) {
625 ok(GetLastError() == ERROR_IO_INCOMPLETE
, "GetOverlappedResult\n");
626 success
= GetOverlappedResult(hnp
, &oOverlap
, &written
, TRUE
);
629 trace("Server done writing.\n");
630 ok(success
, "overlapped WriteFile\n");
631 ok(written
== readden
, "write file len\n");
633 /* finish this connection, wait for next one */
634 ok(FlushFileBuffers(hnp
), "FlushFileBuffers\n");
635 ok(DisconnectNamedPipe(hnp
), "DisconnectNamedPipe\n");
640 /** Trivial byte echo server - uses i/o completion ports */
641 static DWORD CALLBACK
serverThreadMain4(LPVOID arg
)
646 trace("serverThreadMain4\n");
647 /* Set up a simple echo server */
648 hnp
= CreateNamedPipe(PIPENAME
"serverThreadMain4", PIPE_ACCESS_DUPLEX
| FILE_FLAG_OVERLAPPED
,
649 PIPE_TYPE_BYTE
| PIPE_WAIT
,
650 /* nMaxInstances */ 1,
651 /* nOutBufSize */ 1024,
652 /* nInBufSize */ 1024,
653 /* nDefaultWait */ NMPWAIT_USE_DEFAULT_WAIT
,
654 /* lpSecurityAttrib */ NULL
);
655 ok(hnp
!= INVALID_HANDLE_VALUE
, "CreateNamedPipe failed\n");
657 hcompletion
= CreateIoCompletionPort(hnp
, NULL
, 12345, 1);
658 ok(hcompletion
!= NULL
, "CreateIoCompletionPort failed, error=%i\n", GetLastError());
660 for (i
= 0; i
< NB_SERVER_LOOPS
; i
++) {
673 memset(&oConnect
, 0, sizeof(oConnect
));
674 memset(&oRead
, 0, sizeof(oRead
));
675 memset(&oWrite
, 0, sizeof(oWrite
));
677 /* Wait for client to connect */
678 trace("Server calling overlapped ConnectNamedPipe...\n");
679 success
= ConnectNamedPipe(hnp
, &oConnect
);
680 err
= GetLastError();
681 ok(!success
&& (err
== ERROR_IO_PENDING
|| err
== ERROR_PIPE_CONNECTED
),
682 "overlapped ConnectNamedPipe got %u err %u\n", success
, err
);
683 if (!success
&& err
== ERROR_IO_PENDING
) {
684 trace("ConnectNamedPipe GetQueuedCompletionStatus\n");
685 success
= GetQueuedCompletionStatus(hcompletion
, &dummy
, &compkey
, &oResult
, 0);
688 ok( GetLastError() == WAIT_TIMEOUT
,
689 "ConnectNamedPipe GetQueuedCompletionStatus wrong error %u\n", GetLastError());
690 success
= GetQueuedCompletionStatus(hcompletion
, &dummy
, &compkey
, &oResult
, 10000);
692 ok(success
, "ConnectNamedPipe GetQueuedCompletionStatus failed, errno=%i\n", GetLastError());
695 ok(compkey
== 12345, "got completion key %i instead of 12345\n", (int)compkey
);
696 ok(oResult
== &oConnect
, "got overlapped pointer %p instead of %p\n", oResult
, &oConnect
);
699 trace("overlapped ConnectNamedPipe operation complete.\n");
701 /* Echo bytes once */
702 memset(buf
, 0, sizeof(buf
));
704 trace("Server reading...\n");
705 success
= ReadFile(hnp
, buf
, sizeof(buf
), &readden
, &oRead
);
706 trace("Server ReadFile returned...\n");
707 err
= GetLastError();
708 ok(success
|| err
== ERROR_IO_PENDING
, "overlapped ReadFile, err=%i\n", err
);
709 success
= GetQueuedCompletionStatus(hcompletion
, &readden
, &compkey
,
711 ok(success
, "ReadFile GetQueuedCompletionStatus failed, errno=%i\n", GetLastError());
714 ok(compkey
== 12345, "got completion key %i instead of 12345\n", (int)compkey
);
715 ok(oResult
== &oRead
, "got overlapped pointer %p instead of %p\n", oResult
, &oRead
);
717 trace("Server done reading.\n");
719 trace("Server writing...\n");
720 success
= WriteFile(hnp
, buf
, readden
, &written
, &oWrite
);
721 trace("Server WriteFile returned...\n");
722 err
= GetLastError();
723 ok(success
|| err
== ERROR_IO_PENDING
, "overlapped WriteFile failed, err=%u\n", err
);
724 success
= GetQueuedCompletionStatus(hcompletion
, &written
, &compkey
,
726 ok(success
, "WriteFile GetQueuedCompletionStatus failed, errno=%i\n", GetLastError());
729 ok(compkey
== 12345, "got completion key %i instead of 12345\n", (int)compkey
);
730 ok(oResult
== &oWrite
, "got overlapped pointer %p instead of %p\n", oResult
, &oWrite
);
731 ok(written
== readden
, "write file len\n");
733 trace("Server done writing.\n");
735 /* finish this connection, wait for next one */
736 ok(FlushFileBuffers(hnp
), "FlushFileBuffers\n");
737 success
= DisconnectNamedPipe(hnp
);
738 ok(success
, "DisconnectNamedPipe failed, err %u\n", GetLastError());
741 ok(CloseHandle(hnp
), "CloseHandle named pipe failed, err=%i\n", GetLastError());
742 ok(CloseHandle(hcompletion
), "CloseHandle completion failed, err=%i\n", GetLastError());
747 static void exercizeServer(const char *pipename
, HANDLE serverThread
)
751 trace("exercizeServer starting\n");
752 for (i
= 0; i
< NB_SERVER_LOOPS
; i
++) {
753 HANDLE hFile
=INVALID_HANDLE_VALUE
;
754 static const char obuf
[] = "Bit Bucket";
760 for (loop
= 0; loop
< 3; loop
++) {
762 trace("Client connecting...\n");
763 /* Connect to the server */
764 hFile
= CreateFileA(pipename
, GENERIC_READ
| GENERIC_WRITE
, 0,
765 NULL
, OPEN_EXISTING
, 0, 0);
766 if (hFile
!= INVALID_HANDLE_VALUE
)
768 err
= GetLastError();
770 ok(err
== ERROR_PIPE_BUSY
|| err
== ERROR_FILE_NOT_FOUND
, "connecting to pipe\n");
772 ok(err
== ERROR_PIPE_BUSY
, "connecting to pipe\n");
773 trace("connect failed, retrying\n");
776 ok(hFile
!= INVALID_HANDLE_VALUE
, "client opening named pipe\n");
778 /* Make sure it can echo */
779 memset(ibuf
, 0, sizeof(ibuf
));
780 trace("Client writing...\n");
781 ok(WriteFile(hFile
, obuf
, sizeof(obuf
), &written
, NULL
), "WriteFile to client end of pipe\n");
782 ok(written
== sizeof(obuf
), "write file len\n");
783 trace("Client reading...\n");
784 ok(ReadFile(hFile
, ibuf
, sizeof(obuf
), &readden
, NULL
), "ReadFile from client end of pipe\n");
785 ok(readden
== sizeof(obuf
), "read file len\n");
786 ok(memcmp(obuf
, ibuf
, written
) == 0, "content check\n");
788 trace("Client closing...\n");
789 ok(CloseHandle(hFile
), "CloseHandle\n");
792 ok(WaitForSingleObject(serverThread
,INFINITE
) == WAIT_OBJECT_0
, "WaitForSingleObject\n");
794 trace("exercizeServer returning\n");
797 static void test_NamedPipe_2(void)
800 DWORD serverThreadId
;
804 trace("test_NamedPipe_2 starting\n");
805 /* Set up a twenty second timeout */
806 alarm_event
= CreateEvent( NULL
, TRUE
, FALSE
, NULL
);
807 alarmThread
= CreateThread(NULL
, 0, alarmThreadMain
, (void *) 20000, 0, &alarmThreadId
);
809 /* The servers we're about to exercize do try to clean up carefully,
810 * but to reduce the change of a test failure due to a pipe handle
811 * leak in the test code, we'll use a different pipe name for each server.
815 serverThread
= CreateThread(NULL
, 0, serverThreadMain1
, (void *)8, 0, &serverThreadId
);
816 ok(serverThread
!= INVALID_HANDLE_VALUE
, "CreateThread\n");
817 exercizeServer(PIPENAME
"serverThreadMain1", serverThread
);
820 serverThread
= CreateThread(NULL
, 0, serverThreadMain2
, 0, 0, &serverThreadId
);
821 ok(serverThread
!= INVALID_HANDLE_VALUE
, "CreateThread\n");
822 exercizeServer(PIPENAME
"serverThreadMain2", serverThread
);
825 serverThread
= CreateThread(NULL
, 0, serverThreadMain3
, 0, 0, &serverThreadId
);
826 ok(serverThread
!= INVALID_HANDLE_VALUE
, "CreateThread\n");
827 exercizeServer(PIPENAME
"serverThreadMain3", serverThread
);
830 serverThread
= CreateThread(NULL
, 0, serverThreadMain4
, 0, 0, &serverThreadId
);
831 ok(serverThread
!= INVALID_HANDLE_VALUE
, "CreateThread\n");
832 exercizeServer(PIPENAME
"serverThreadMain4", serverThread
);
834 ok(SetEvent( alarm_event
), "SetEvent\n");
835 CloseHandle( alarm_event
);
836 trace("test_NamedPipe_2 returning\n");
839 static int test_DisconnectNamedPipe(void)
843 static const char obuf
[] = "Bit Bucket";
849 SetLastError(0xdeadbeef);
850 hnp
= CreateNamedPipe(PIPENAME
, PIPE_ACCESS_DUPLEX
, PIPE_TYPE_BYTE
| PIPE_WAIT
,
851 /* nMaxInstances */ 1,
852 /* nOutBufSize */ 1024,
853 /* nInBufSize */ 1024,
854 /* nDefaultWait */ NMPWAIT_USE_DEFAULT_WAIT
,
855 /* lpSecurityAttrib */ NULL
);
856 if ((hnp
== INVALID_HANDLE_VALUE
/* Win98 */ || !hnp
/* Win95 */)
857 && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
) {
859 win_skip("Named pipes are not implemented\n");
863 ok(WriteFile(hnp
, obuf
, sizeof(obuf
), &written
, NULL
) == 0
864 && GetLastError() == ERROR_PIPE_LISTENING
, "WriteFile to not-yet-connected pipe\n");
865 ok(ReadFile(hnp
, ibuf
, sizeof(ibuf
), &readden
, NULL
) == 0
866 && GetLastError() == ERROR_PIPE_LISTENING
, "ReadFile from not-yet-connected pipe\n");
868 hFile
= CreateFileA(PIPENAME
, GENERIC_READ
| GENERIC_WRITE
, 0, NULL
, OPEN_EXISTING
, 0, 0);
869 ok(hFile
!= INVALID_HANDLE_VALUE
, "CreateFile failed\n");
871 /* don't try to do i/o if one side couldn't be opened, as it hangs */
872 if (hFile
!= INVALID_HANDLE_VALUE
) {
874 /* see what happens if server calls DisconnectNamedPipe
875 * when there are bytes in the pipe
878 ok(WriteFile(hFile
, obuf
, sizeof(obuf
), &written
, NULL
), "WriteFile\n");
879 ok(written
== sizeof(obuf
), "write file len\n");
880 ok(DisconnectNamedPipe(hnp
), "DisconnectNamedPipe while messages waiting\n");
881 ok(WriteFile(hFile
, obuf
, sizeof(obuf
), &written
, NULL
) == 0
882 && GetLastError() == ERROR_PIPE_NOT_CONNECTED
, "WriteFile to disconnected pipe\n");
883 ok(ReadFile(hnp
, ibuf
, sizeof(ibuf
), &readden
, NULL
) == 0
884 && GetLastError() == ERROR_PIPE_NOT_CONNECTED
,
885 "ReadFile from disconnected pipe with bytes waiting\n");
886 ok(!DisconnectNamedPipe(hnp
) && GetLastError() == ERROR_PIPE_NOT_CONNECTED
,
887 "DisconnectNamedPipe worked twice\n");
888 ret
= WaitForSingleObject(hFile
, 0);
889 ok(ret
== WAIT_TIMEOUT
, "WaitForSingleObject returned %X\n", ret
);
890 ok(CloseHandle(hFile
), "CloseHandle\n");
893 ok(CloseHandle(hnp
), "CloseHandle\n");
897 static void test_CreatePipe(void)
899 SECURITY_ATTRIBUTES pipe_attr
;
900 HANDLE piperead
, pipewrite
;
907 pipe_attr
.nLength
= sizeof(SECURITY_ATTRIBUTES
);
908 pipe_attr
.bInheritHandle
= TRUE
;
909 pipe_attr
.lpSecurityDescriptor
= NULL
;
910 ok(CreatePipe(&piperead
, &pipewrite
, &pipe_attr
, 0) != 0, "CreatePipe failed\n");
911 ok(WriteFile(pipewrite
,PIPENAME
,sizeof(PIPENAME
), &written
, NULL
), "Write to anonymous pipe failed\n");
912 ok(written
== sizeof(PIPENAME
), "Write to anonymous pipe wrote %d bytes\n", written
);
913 ok(ReadFile(piperead
,readbuf
,sizeof(readbuf
),&read
, NULL
), "Read from non empty pipe failed\n");
914 ok(read
== sizeof(PIPENAME
), "Read from anonymous pipe got %d bytes\n", read
);
915 ok(CloseHandle(pipewrite
), "CloseHandle for the write pipe failed\n");
916 ok(CloseHandle(piperead
), "CloseHandle for the read pipe failed\n");
918 /* Now write another chunk*/
919 ok(CreatePipe(&piperead
, &pipewrite
, &pipe_attr
, 0) != 0, "CreatePipe failed\n");
920 ok(WriteFile(pipewrite
,PIPENAME
,sizeof(PIPENAME
), &written
, NULL
), "Write to anonymous pipe failed\n");
921 ok(written
== sizeof(PIPENAME
), "Write to anonymous pipe wrote %d bytes\n", written
);
922 /* and close the write end, read should still succeed*/
923 ok(CloseHandle(pipewrite
), "CloseHandle for the Write Pipe failed\n");
924 ok(ReadFile(piperead
,readbuf
,sizeof(readbuf
),&read
, NULL
), "Read from broken pipe withe with pending data failed\n");
925 ok(read
== sizeof(PIPENAME
), "Read from anonymous pipe got %d bytes\n", read
);
926 /* But now we need to get informed that the pipe is closed */
927 ok(ReadFile(piperead
,readbuf
,sizeof(readbuf
),&read
, NULL
) == 0, "Broken pipe not detected\n");
928 ok(CloseHandle(piperead
), "CloseHandle for the read pipe failed\n");
930 /* Try bigger chunks */
932 buffer
= HeapAlloc( GetProcessHeap(), 0, size
);
933 for (i
= 0; i
< size
; i
++) buffer
[i
] = i
;
934 ok(CreatePipe(&piperead
, &pipewrite
, &pipe_attr
, (size
+ 24)) != 0, "CreatePipe failed\n");
935 ok(WriteFile(pipewrite
, buffer
, size
, &written
, NULL
), "Write to anonymous pipe failed\n");
936 ok(written
== size
, "Write to anonymous pipe wrote %d bytes\n", written
);
937 /* and close the write end, read should still succeed*/
938 ok(CloseHandle(pipewrite
), "CloseHandle for the Write Pipe failed\n");
939 memset( buffer
, 0, size
);
940 ok(ReadFile(piperead
, buffer
, size
, &read
, NULL
), "Read from broken pipe withe with pending data failed\n");
941 ok(read
== size
, "Read from anonymous pipe got %d bytes\n", read
);
942 for (i
= 0; i
< size
; i
++) ok( buffer
[i
] == (BYTE
)i
, "invalid data %x at %x\n", buffer
[i
], i
);
943 /* But now we need to get informed that the pipe is closed */
944 ok(ReadFile(piperead
,readbuf
,sizeof(readbuf
),&read
, NULL
) == 0, "Broken pipe not detected\n");
945 ok(CloseHandle(piperead
), "CloseHandle for the read pipe failed\n");
946 HeapFree(GetProcessHeap(), 0, buffer
);
949 struct named_pipe_client_params
951 DWORD security_flags
;
956 #define PIPE_NAME "\\\\.\\pipe\\named_pipe_test"
958 static DWORD CALLBACK
named_pipe_client_func(LPVOID p
)
960 struct named_pipe_client_params
*params
= p
;
963 const char message
[] = "Test";
964 DWORD bytes_read
, bytes_written
;
966 TOKEN_PRIVILEGES
*Privileges
= NULL
;
972 /* modify the token so we can tell if the pipe impersonation
973 * token reverts to the process token */
974 ret
= AdjustTokenPrivileges(params
->token
, TRUE
, NULL
, 0, NULL
, NULL
);
975 ok(ret
, "AdjustTokenPrivileges failed with error %d\n", GetLastError());
977 ret
= SetThreadToken(NULL
, params
->token
);
978 ok(ret
, "SetThreadToken failed with error %d\n", GetLastError());
983 HANDLE process_token
;
985 ret
= OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY
|TOKEN_ADJUST_PRIVILEGES
, &process_token
);
986 ok(ret
, "OpenProcessToken failed with error %d\n", GetLastError());
988 ret
= GetTokenInformation(process_token
, TokenPrivileges
, NULL
, 0, &Size
);
989 ok(!ret
&& GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "GetTokenInformation(TokenPrivileges) failed with %d\n", GetLastError());
990 Privileges
= HeapAlloc(GetProcessHeap(), 0, Size
);
991 ret
= GetTokenInformation(process_token
, TokenPrivileges
, Privileges
, Size
, &Size
);
992 ok(ret
, "GetTokenInformation(TokenPrivileges) failed with %d\n", GetLastError());
994 ret
= AdjustTokenPrivileges(process_token
, TRUE
, NULL
, 0, NULL
, NULL
);
995 ok(ret
, "AdjustTokenPrivileges failed with error %d\n", GetLastError());
997 CloseHandle(process_token
);
1000 pipe
= CreateFile(PIPE_NAME
, GENERIC_READ
| GENERIC_WRITE
, 0, NULL
, OPEN_EXISTING
, params
->security_flags
, NULL
);
1001 ok(pipe
!= INVALID_HANDLE_VALUE
, "CreateFile for pipe failed with error %d\n", GetLastError());
1003 ret
= WriteFile(pipe
, message
, sizeof(message
), &bytes_written
, NULL
);
1004 ok(ret
, "WriteFile failed with error %d\n", GetLastError());
1006 ret
= ReadFile(pipe
, &dummy
, sizeof(dummy
), &bytes_read
, NULL
);
1007 ok(ret
, "ReadFile failed with error %d\n", GetLastError());
1013 ret
= RevertToSelf();
1014 ok(ret
, "RevertToSelf failed with error %d\n", GetLastError());
1018 ret
= AdjustTokenPrivileges(params
->token
, TRUE
, NULL
, 0, NULL
, NULL
);
1019 ok(ret
, "AdjustTokenPrivileges failed with error %d\n", GetLastError());
1024 HANDLE process_token
;
1026 ret
= OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES
, &process_token
);
1027 ok(ret
, "OpenProcessToken failed with error %d\n", GetLastError());
1029 ret
= AdjustTokenPrivileges(process_token
, FALSE
, Privileges
, 0, NULL
, NULL
);
1030 ok(ret
, "AdjustTokenPrivileges failed with error %d\n", GetLastError());
1032 HeapFree(GetProcessHeap(), 0, Privileges
);
1034 CloseHandle(process_token
);
1037 ret
= WriteFile(pipe
, message
, sizeof(message
), &bytes_written
, NULL
);
1038 ok(ret
, "WriteFile failed with error %d\n", GetLastError());
1040 ret
= ReadFile(pipe
, &dummy
, sizeof(dummy
), &bytes_read
, NULL
);
1041 ok(ret
, "ReadFile failed with error %d\n", GetLastError());
1048 static HANDLE
make_impersonation_token(DWORD Access
, SECURITY_IMPERSONATION_LEVEL ImpersonationLevel
)
1050 HANDLE ProcessToken
;
1051 HANDLE Token
= NULL
;
1054 ret
= OpenProcessToken(GetCurrentProcess(), TOKEN_DUPLICATE
, &ProcessToken
);
1055 ok(ret
, "OpenProcessToken failed with error %d\n", GetLastError());
1057 ret
= pDuplicateTokenEx(ProcessToken
, Access
, NULL
, ImpersonationLevel
, TokenImpersonation
, &Token
);
1058 ok(ret
, "DuplicateToken failed with error %d\n", GetLastError());
1060 CloseHandle(ProcessToken
);
1065 static void test_ImpersonateNamedPipeClient(HANDLE hClientToken
, DWORD security_flags
, BOOL revert
, void (*test_func
)(int, HANDLE
))
1074 struct named_pipe_client_params params
;
1076 DWORD dwBytesWritten
;
1077 HANDLE hToken
= NULL
;
1078 SECURITY_IMPERSONATION_LEVEL ImpersonationLevel
;
1081 hPipeServer
= CreateNamedPipe(PIPE_NAME
, PIPE_ACCESS_DUPLEX
, PIPE_TYPE_BYTE
| PIPE_READMODE_BYTE
| PIPE_WAIT
, 1, 100, 100, NMPWAIT_USE_DEFAULT_WAIT
, NULL
);
1082 ok(hPipeServer
!= INVALID_HANDLE_VALUE
, "CreateNamedPipe failed with error %d\n", GetLastError());
1084 params
.security_flags
= security_flags
;
1085 params
.token
= hClientToken
;
1086 params
.revert
= revert
;
1087 hThread
= CreateThread(NULL
, 0, named_pipe_client_func
, ¶ms
, 0, &dwTid
);
1088 ok(hThread
!= NULL
, "CreateThread failed with error %d\n", GetLastError());
1090 SetLastError(0xdeadbeef);
1091 ret
= ImpersonateNamedPipeClient(hPipeServer
);
1092 error
= GetLastError();
1093 ok(ret
/* win2k3 */ || (error
== ERROR_CANNOT_IMPERSONATE
),
1094 "ImpersonateNamedPipeClient should have failed with ERROR_CANNOT_IMPERSONATE instead of %d\n", GetLastError());
1096 ret
= ConnectNamedPipe(hPipeServer
, NULL
);
1097 ok(ret
|| (GetLastError() == ERROR_PIPE_CONNECTED
), "ConnectNamedPipe failed with error %d\n", GetLastError());
1099 ret
= ReadFile(hPipeServer
, buffer
, sizeof(buffer
), &dwBytesRead
, NULL
);
1100 ok(ret
, "ReadFile failed with error %d\n", GetLastError());
1102 ret
= ImpersonateNamedPipeClient(hPipeServer
);
1103 ok(ret
, "ImpersonateNamedPipeClient failed with error %d\n", GetLastError());
1105 ret
= OpenThreadToken(GetCurrentThread(), TOKEN_QUERY
, FALSE
, &hToken
);
1106 ok(ret
, "OpenThreadToken failed with error %d\n", GetLastError());
1108 (*test_func
)(0, hToken
);
1110 ImpersonationLevel
= 0xdeadbeef; /* to avoid false positives */
1111 ret
= GetTokenInformation(hToken
, TokenImpersonationLevel
, &ImpersonationLevel
, sizeof(ImpersonationLevel
), &size
);
1112 ok(ret
, "GetTokenInformation(TokenImpersonationLevel) failed with error %d\n", GetLastError());
1113 ok(ImpersonationLevel
== SecurityImpersonation
, "ImpersonationLevel should have been SecurityImpersonation(%d) instead of %d\n", SecurityImpersonation
, ImpersonationLevel
);
1115 CloseHandle(hToken
);
1119 ret
= WriteFile(hPipeServer
, &dummy
, sizeof(dummy
), &dwBytesWritten
, NULL
);
1120 ok(ret
, "WriteFile failed with error %d\n", GetLastError());
1122 ret
= ReadFile(hPipeServer
, buffer
, sizeof(buffer
), &dwBytesRead
, NULL
);
1123 ok(ret
, "ReadFile failed with error %d\n", GetLastError());
1125 ret
= ImpersonateNamedPipeClient(hPipeServer
);
1126 ok(ret
, "ImpersonateNamedPipeClient failed with error %d\n", GetLastError());
1128 ret
= OpenThreadToken(GetCurrentThread(), TOKEN_QUERY
, FALSE
, &hToken
);
1129 ok(ret
, "OpenThreadToken failed with error %d\n", GetLastError());
1131 (*test_func
)(1, hToken
);
1133 CloseHandle(hToken
);
1137 ret
= WriteFile(hPipeServer
, &dummy
, sizeof(dummy
), &dwBytesWritten
, NULL
);
1138 ok(ret
, "WriteFile failed with error %d\n", GetLastError());
1140 WaitForSingleObject(hThread
, INFINITE
);
1142 ret
= ImpersonateNamedPipeClient(hPipeServer
);
1143 ok(ret
, "ImpersonateNamedPipeClient failed with error %d\n", GetLastError());
1147 CloseHandle(hThread
);
1148 CloseHandle(hPipeServer
);
1151 static BOOL
are_all_privileges_disabled(HANDLE hToken
)
1154 TOKEN_PRIVILEGES
*Privileges
= NULL
;
1156 BOOL all_privs_disabled
= TRUE
;
1159 ret
= GetTokenInformation(hToken
, TokenPrivileges
, NULL
, 0, &Size
);
1160 if (!ret
&& GetLastError() == ERROR_INSUFFICIENT_BUFFER
)
1162 Privileges
= HeapAlloc(GetProcessHeap(), 0, Size
);
1163 ret
= GetTokenInformation(hToken
, TokenPrivileges
, Privileges
, Size
, &Size
);
1166 HeapFree(GetProcessHeap(), 0, Privileges
);
1173 for (i
= 0; i
< Privileges
->PrivilegeCount
; i
++)
1175 if (Privileges
->Privileges
[i
].Attributes
& SE_PRIVILEGE_ENABLED
)
1177 all_privs_disabled
= FALSE
;
1182 HeapFree(GetProcessHeap(), 0, Privileges
);
1184 return all_privs_disabled
;
1187 static DWORD
get_privilege_count(HANDLE hToken
)
1189 TOKEN_STATISTICS Statistics
;
1190 DWORD Size
= sizeof(Statistics
);
1193 ret
= GetTokenInformation(hToken
, TokenStatistics
, &Statistics
, Size
, &Size
);
1194 ok(ret
, "GetTokenInformation(TokenStatistics)\n");
1195 if (!ret
) return -1;
1197 return Statistics
.PrivilegeCount
;
1200 static void test_no_sqos_no_token(int call_index
, HANDLE hToken
)
1207 priv_count
= get_privilege_count(hToken
);
1209 ok(priv_count
== 0, "privilege count should have been 0 instead of %d\n", priv_count
);
1212 priv_count
= get_privilege_count(hToken
);
1213 ok(priv_count
> 0, "privilege count should now be > 0 instead of 0\n");
1214 ok(!are_all_privileges_disabled(hToken
), "impersonated token should not have been modified\n");
1217 ok(0, "shouldn't happen\n");
1221 static void test_no_sqos(int call_index
, HANDLE hToken
)
1226 ok(!are_all_privileges_disabled(hToken
), "token should be a copy of the process one\n");
1230 ok(are_all_privileges_disabled(hToken
), "impersonated token should have been modified\n");
1233 ok(0, "shouldn't happen\n");
1237 static void test_static_context(int call_index
, HANDLE hToken
)
1242 ok(!are_all_privileges_disabled(hToken
), "token should be a copy of the process one\n");
1245 ok(!are_all_privileges_disabled(hToken
), "impersonated token should not have been modified\n");
1248 ok(0, "shouldn't happen\n");
1252 static void test_dynamic_context(int call_index
, HANDLE hToken
)
1257 ok(!are_all_privileges_disabled(hToken
), "token should be a copy of the process one\n");
1261 ok(are_all_privileges_disabled(hToken
), "impersonated token should have been modified\n");
1264 ok(0, "shouldn't happen\n");
1268 static void test_dynamic_context_no_token(int call_index
, HANDLE hToken
)
1273 ok(are_all_privileges_disabled(hToken
), "token should be a copy of the process one\n");
1276 ok(!are_all_privileges_disabled(hToken
), "process token modification should have been detected and impersonation token updated\n");
1279 ok(0, "shouldn't happen\n");
1283 static void test_no_sqos_revert(int call_index
, HANDLE hToken
)
1289 priv_count
= get_privilege_count(hToken
);
1291 ok(priv_count
== 0, "privilege count should have been 0 instead of %d\n", priv_count
);
1294 priv_count
= get_privilege_count(hToken
);
1295 ok(priv_count
> 0, "privilege count should now be > 0 instead of 0\n");
1296 ok(!are_all_privileges_disabled(hToken
), "impersonated token should not have been modified\n");
1299 ok(0, "shouldn't happen\n");
1303 static void test_static_context_revert(int call_index
, HANDLE hToken
)
1309 ok(are_all_privileges_disabled(hToken
), "privileges should have been disabled\n");
1313 ok(are_all_privileges_disabled(hToken
), "impersonated token should not have been modified\n");
1316 ok(0, "shouldn't happen\n");
1320 static void test_dynamic_context_revert(int call_index
, HANDLE hToken
)
1326 ok(are_all_privileges_disabled(hToken
), "privileges should have been disabled\n");
1329 ok(!are_all_privileges_disabled(hToken
), "impersonated token should now be process token\n");
1332 ok(0, "shouldn't happen\n");
1336 static void test_impersonation(void)
1338 HANDLE hClientToken
;
1339 HANDLE hProcessToken
;
1342 if( !pDuplicateTokenEx
) {
1343 skip("DuplicateTokenEx not found\n");
1347 ret
= OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY
, &hProcessToken
);
1350 skip("couldn't open process token, skipping impersonation tests\n");
1354 if (!get_privilege_count(hProcessToken
) || are_all_privileges_disabled(hProcessToken
))
1356 skip("token didn't have any privileges or they were all disabled. token not suitable for impersonation tests\n");
1357 CloseHandle(hProcessToken
);
1360 CloseHandle(hProcessToken
);
1362 test_ImpersonateNamedPipeClient(NULL
, 0, FALSE
, test_no_sqos_no_token
);
1363 hClientToken
= make_impersonation_token(TOKEN_IMPERSONATE
| TOKEN_ADJUST_PRIVILEGES
| TOKEN_QUERY
, SecurityImpersonation
);
1364 test_ImpersonateNamedPipeClient(hClientToken
, 0, FALSE
, test_no_sqos
);
1365 CloseHandle(hClientToken
);
1366 hClientToken
= make_impersonation_token(TOKEN_IMPERSONATE
| TOKEN_ADJUST_PRIVILEGES
| TOKEN_QUERY
, SecurityImpersonation
);
1367 test_ImpersonateNamedPipeClient(hClientToken
,
1368 SECURITY_SQOS_PRESENT
| SECURITY_IMPERSONATION
, FALSE
,
1369 test_static_context
);
1370 CloseHandle(hClientToken
);
1371 hClientToken
= make_impersonation_token(TOKEN_IMPERSONATE
| TOKEN_ADJUST_PRIVILEGES
| TOKEN_QUERY
, SecurityImpersonation
);
1372 test_ImpersonateNamedPipeClient(hClientToken
,
1373 SECURITY_SQOS_PRESENT
| SECURITY_CONTEXT_TRACKING
| SECURITY_IMPERSONATION
,
1374 FALSE
, test_dynamic_context
);
1375 CloseHandle(hClientToken
);
1376 test_ImpersonateNamedPipeClient(NULL
,
1377 SECURITY_SQOS_PRESENT
| SECURITY_CONTEXT_TRACKING
| SECURITY_IMPERSONATION
,
1378 FALSE
, test_dynamic_context_no_token
);
1380 hClientToken
= make_impersonation_token(TOKEN_IMPERSONATE
| TOKEN_ADJUST_PRIVILEGES
| TOKEN_QUERY
, SecurityImpersonation
);
1381 test_ImpersonateNamedPipeClient(hClientToken
, 0, TRUE
, test_no_sqos_revert
);
1382 CloseHandle(hClientToken
);
1383 hClientToken
= make_impersonation_token(TOKEN_IMPERSONATE
| TOKEN_ADJUST_PRIVILEGES
| TOKEN_QUERY
, SecurityImpersonation
);
1384 test_ImpersonateNamedPipeClient(hClientToken
,
1385 SECURITY_SQOS_PRESENT
| SECURITY_IMPERSONATION
, TRUE
,
1386 test_static_context_revert
);
1387 CloseHandle(hClientToken
);
1388 hClientToken
= make_impersonation_token(TOKEN_IMPERSONATE
| TOKEN_ADJUST_PRIVILEGES
| TOKEN_QUERY
, SecurityImpersonation
);
1389 test_ImpersonateNamedPipeClient(hClientToken
,
1390 SECURITY_SQOS_PRESENT
| SECURITY_CONTEXT_TRACKING
| SECURITY_IMPERSONATION
,
1391 TRUE
, test_dynamic_context_revert
);
1392 CloseHandle(hClientToken
);
1395 struct overlapped_server_args
1397 HANDLE pipe_created
;
1400 static DWORD CALLBACK
overlapped_server(LPVOID arg
)
1405 struct overlapped_server_args
*a
= arg
;
1409 pipe
= CreateNamedPipeA("\\\\.\\pipe\\my pipe", FILE_FLAG_OVERLAPPED
| PIPE_ACCESS_DUPLEX
, PIPE_TYPE_MESSAGE
| PIPE_READMODE_MESSAGE
, 1, 0, 0, 100000, NULL
);
1410 ok(pipe
!= NULL
, "pipe NULL\n");
1412 ol
.hEvent
= CreateEventA(0, 1, 0, 0);
1413 ok(ol
.hEvent
!= NULL
, "event NULL\n");
1414 ret
= ConnectNamedPipe(pipe
, &ol
);
1415 err
= GetLastError();
1416 ok(ret
== 0, "ret %d\n", ret
);
1417 ok(err
== ERROR_IO_PENDING
, "gle %d\n", err
);
1418 SetEvent(a
->pipe_created
);
1420 ret
= WaitForSingleObjectEx(ol
.hEvent
, INFINITE
, 1);
1421 ok(ret
== WAIT_OBJECT_0
, "ret %x\n", ret
);
1423 ret
= GetOverlappedResult(pipe
, &ol
, &num
, 1);
1424 ok(ret
== 1, "ret %d\n", ret
);
1426 /* This should block */
1427 ret
= ReadFile(pipe
, buf
, sizeof(buf
), &num
, NULL
);
1428 ok(ret
== 1, "ret %d\n", ret
);
1430 DisconnectNamedPipe(pipe
);
1431 CloseHandle(ol
.hEvent
);
1436 static void test_overlapped(void)
1439 HANDLE thread
, pipe
;
1441 struct overlapped_server_args args
;
1443 args
.pipe_created
= CreateEventA(0, 1, 0, 0);
1444 thread
= CreateThread(NULL
, 0, overlapped_server
, &args
, 0, &tid
);
1446 WaitForSingleObject(args
.pipe_created
, INFINITE
);
1447 pipe
= CreateFileA("\\\\.\\pipe\\my pipe", GENERIC_READ
|GENERIC_WRITE
, 0, NULL
, OPEN_EXISTING
, 0, NULL
);
1448 ok(pipe
!= INVALID_HANDLE_VALUE
, "cf failed\n");
1450 /* Sleep to try to get the ReadFile in the server to occur before the following WriteFile */
1453 ret
= WriteFile(pipe
, "x", 1, &num
, NULL
);
1454 ok(ret
== 1, "ret %d\n", ret
);
1456 WaitForSingleObject(thread
, INFINITE
);
1458 CloseHandle(args
.pipe_created
);
1459 CloseHandle(thread
);
1462 static void test_NamedPipeHandleState(void)
1464 HANDLE server
, client
;
1466 DWORD state
, instances
, maxCollectionCount
, collectDataTimeout
;
1467 char userName
[MAX_PATH
];
1469 server
= CreateNamedPipe(PIPENAME
, PIPE_ACCESS_DUPLEX
,
1470 /* dwOpenMode */ PIPE_TYPE_BYTE
| PIPE_WAIT
,
1471 /* nMaxInstances */ 1,
1472 /* nOutBufSize */ 1024,
1473 /* nInBufSize */ 1024,
1474 /* nDefaultWait */ NMPWAIT_USE_DEFAULT_WAIT
,
1475 /* lpSecurityAttrib */ NULL
);
1476 ok(server
!= INVALID_HANDLE_VALUE
, "cf failed\n");
1477 ret
= GetNamedPipeHandleState(server
, NULL
, NULL
, NULL
, NULL
, NULL
, 0);
1479 ok(ret
, "GetNamedPipeHandleState failed: %d\n", GetLastError());
1480 ret
= GetNamedPipeHandleState(server
, &state
, &instances
, NULL
, NULL
, NULL
,
1483 ok(ret
, "GetNamedPipeHandleState failed: %d\n", GetLastError());
1486 ok(state
== 0, "unexpected state %08x\n", state
);
1487 ok(instances
== 1, "expected 1 instances, got %d\n", instances
);
1489 /* Some parameters have no meaning, and therefore can't be retrieved,
1492 SetLastError(0xdeadbeef);
1493 ret
= GetNamedPipeHandleState(server
, &state
, &instances
,
1494 &maxCollectionCount
, &collectDataTimeout
, userName
,
1495 sizeof(userName
) / sizeof(userName
[0]));
1497 ok(!ret
&& GetLastError() == ERROR_INVALID_PARAMETER
,
1498 "expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
1499 /* A byte-mode pipe server can't be changed to message mode. */
1500 state
= PIPE_READMODE_MESSAGE
;
1501 SetLastError(0xdeadbeef);
1502 ret
= SetNamedPipeHandleState(server
, &state
, NULL
, NULL
);
1504 ok(!ret
&& GetLastError() == ERROR_INVALID_PARAMETER
,
1505 "expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
1507 client
= CreateFileA(PIPENAME
, GENERIC_READ
|GENERIC_WRITE
, 0, NULL
,
1508 OPEN_EXISTING
, 0, NULL
);
1509 ok(client
!= INVALID_HANDLE_VALUE
, "cf failed\n");
1511 state
= PIPE_READMODE_BYTE
;
1512 ret
= SetNamedPipeHandleState(client
, &state
, NULL
, NULL
);
1514 ok(ret
, "SetNamedPipeHandleState failed: %d\n", GetLastError());
1515 /* A byte-mode pipe client can't be changed to message mode, either. */
1516 state
= PIPE_READMODE_MESSAGE
;
1517 SetLastError(0xdeadbeef);
1518 ret
= SetNamedPipeHandleState(server
, &state
, NULL
, NULL
);
1520 ok(!ret
&& GetLastError() == ERROR_INVALID_PARAMETER
,
1521 "expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
1523 CloseHandle(client
);
1524 CloseHandle(server
);
1526 server
= CreateNamedPipe(PIPENAME
, PIPE_ACCESS_DUPLEX
,
1527 /* dwOpenMode */ PIPE_TYPE_MESSAGE
| PIPE_WAIT
,
1528 /* nMaxInstances */ 1,
1529 /* nOutBufSize */ 1024,
1530 /* nInBufSize */ 1024,
1531 /* nDefaultWait */ NMPWAIT_USE_DEFAULT_WAIT
,
1532 /* lpSecurityAttrib */ NULL
);
1533 ok(server
!= INVALID_HANDLE_VALUE
, "cf failed\n");
1534 ret
= GetNamedPipeHandleState(server
, NULL
, NULL
, NULL
, NULL
, NULL
, 0);
1536 ok(ret
, "GetNamedPipeHandleState failed: %d\n", GetLastError());
1537 ret
= GetNamedPipeHandleState(server
, &state
, &instances
, NULL
, NULL
, NULL
,
1540 ok(ret
, "GetNamedPipeHandleState failed: %d\n", GetLastError());
1543 ok(state
== 0, "unexpected state %08x\n", state
);
1544 ok(instances
== 1, "expected 1 instances, got %d\n", instances
);
1546 /* In contrast to byte-mode pipes, a message-mode pipe server can be
1547 * changed to byte mode.
1549 state
= PIPE_READMODE_BYTE
;
1550 ret
= SetNamedPipeHandleState(server
, &state
, NULL
, NULL
);
1552 ok(ret
, "SetNamedPipeHandleState failed: %d\n", GetLastError());
1554 client
= CreateFileA(PIPENAME
, GENERIC_READ
|GENERIC_WRITE
, 0, NULL
,
1555 OPEN_EXISTING
, 0, NULL
);
1556 ok(client
!= INVALID_HANDLE_VALUE
, "cf failed\n");
1558 state
= PIPE_READMODE_MESSAGE
;
1559 ret
= SetNamedPipeHandleState(client
, &state
, NULL
, NULL
);
1561 ok(ret
, "SetNamedPipeHandleState failed: %d\n", GetLastError());
1562 /* A message-mode pipe client can also be changed to byte mode.
1564 state
= PIPE_READMODE_BYTE
;
1565 ret
= SetNamedPipeHandleState(client
, &state
, NULL
, NULL
);
1567 ok(ret
, "SetNamedPipeHandleState failed: %d\n", GetLastError());
1569 CloseHandle(client
);
1570 CloseHandle(server
);
1577 hmod
= GetModuleHandle("advapi32.dll");
1578 pDuplicateTokenEx
= (void *) GetProcAddress(hmod
, "DuplicateTokenEx");
1580 if (test_DisconnectNamedPipe())
1582 test_CreateNamedPipe_instances_must_match();
1584 test_CreateNamedPipe(PIPE_TYPE_BYTE
);
1585 test_CreateNamedPipe(PIPE_TYPE_MESSAGE
| PIPE_READMODE_MESSAGE
);
1587 test_impersonation();
1589 test_NamedPipeHandleState();