msvcrt: Reimplement _mbsspnp using _mbsspn.
[wine.git] / server / named_pipe.c
blob8e0380d060da1121ab17355733c797ae9e1dec06
1 /*
2 * Server-side pipe management
4 * Copyright (C) 1998 Alexandre Julliard
5 * Copyright (C) 2001 Mike McCormack
6 * Copyright 2016 Jacek Caban for CodeWeavers
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 #include "config.h"
24 #include "wine/port.h"
26 #include <assert.h>
27 #include <string.h>
28 #include <stdarg.h>
29 #include <stdio.h>
30 #include <stdlib.h>
32 #include "ntstatus.h"
33 #define WIN32_NO_STATUS
34 #include "windef.h"
35 #include "winternl.h"
36 #include "winioctl.h"
38 #include "file.h"
39 #include "handle.h"
40 #include "thread.h"
41 #include "request.h"
42 #include "security.h"
43 #include "process.h"
45 struct named_pipe;
47 struct pipe_message
49 struct list entry; /* entry in message queue */
50 data_size_t read_pos; /* already read bytes */
51 struct iosb *iosb; /* message iosb */
52 struct async *async; /* async of pending write */
55 struct pipe_end
57 struct object obj; /* object header */
58 struct fd *fd; /* pipe file descriptor */
59 unsigned int flags; /* pipe flags */
60 unsigned int state; /* pipe state */
61 struct named_pipe *pipe;
62 struct pipe_end *connection; /* the other end of the pipe */
63 process_id_t client_pid; /* process that created the client */
64 process_id_t server_pid; /* process that created the server */
65 data_size_t buffer_size;/* size of buffered data that doesn't block caller */
66 struct list message_queue;
67 struct async_queue read_q; /* read queue */
68 struct async_queue write_q; /* write queue */
71 struct pipe_server
73 struct pipe_end pipe_end; /* common header for both pipe ends */
74 struct list entry; /* entry in named pipe listeners list */
75 unsigned int options; /* pipe options */
76 struct async_queue listen_q; /* listen queue */
79 struct named_pipe
81 struct object obj; /* object header */
82 int message_mode;
83 unsigned int sharing;
84 unsigned int maxinstances;
85 unsigned int outsize;
86 unsigned int insize;
87 unsigned int instances;
88 timeout_t timeout;
89 struct list listeners; /* list of servers listening on this pipe */
90 struct async_queue waiters; /* list of clients waiting to connect */
93 struct named_pipe_device
95 struct object obj; /* object header */
96 struct namespace *pipes; /* named pipe namespace */
99 struct named_pipe_device_file
101 struct object obj; /* object header */
102 struct fd *fd; /* pseudo-fd for ioctls */
103 struct named_pipe_device *device; /* named pipe device */
106 static void named_pipe_dump( struct object *obj, int verbose );
107 static unsigned int named_pipe_map_access( struct object *obj, unsigned int access );
108 static int named_pipe_link_name( struct object *obj, struct object_name *name, struct object *parent );
109 static struct object *named_pipe_open_file( struct object *obj, unsigned int access,
110 unsigned int sharing, unsigned int options );
111 static void named_pipe_destroy( struct object *obj );
113 static const struct object_ops named_pipe_ops =
115 sizeof(struct named_pipe), /* size */
116 named_pipe_dump, /* dump */
117 no_get_type, /* get_type */
118 no_add_queue, /* add_queue */
119 NULL, /* remove_queue */
120 NULL, /* signaled */
121 NULL, /* satisfied */
122 no_signal, /* signal */
123 no_get_fd, /* get_fd */
124 named_pipe_map_access, /* map_access */
125 default_get_sd, /* get_sd */
126 default_set_sd, /* set_sd */
127 no_lookup_name, /* lookup_name */
128 named_pipe_link_name, /* link_name */
129 default_unlink_name, /* unlink_name */
130 named_pipe_open_file, /* open_file */
131 no_kernel_obj_list, /* get_kernel_obj_list */
132 no_close_handle, /* close_handle */
133 named_pipe_destroy /* destroy */
136 /* common server and client pipe end functions */
137 static void pipe_end_destroy( struct object *obj );
138 static enum server_fd_type pipe_end_get_fd_type( struct fd *fd );
139 static struct fd *pipe_end_get_fd( struct object *obj );
140 static struct security_descriptor *pipe_end_get_sd( struct object *obj );
141 static int pipe_end_set_sd( struct object *obj, const struct security_descriptor *sd,
142 unsigned int set_info );
143 static int pipe_end_read( struct fd *fd, struct async *async, file_pos_t pos );
144 static int pipe_end_write( struct fd *fd, struct async *async_data, file_pos_t pos );
145 static int pipe_end_flush( struct fd *fd, struct async *async );
146 static void pipe_end_get_volume_info( struct fd *fd, unsigned int info_class );
147 static void pipe_end_reselect_async( struct fd *fd, struct async_queue *queue );
148 static void pipe_end_get_file_info( struct fd *fd, obj_handle_t handle, unsigned int info_class );
150 /* server end functions */
151 static void pipe_server_dump( struct object *obj, int verbose );
152 static void pipe_server_destroy( struct object *obj);
153 static int pipe_server_ioctl( struct fd *fd, ioctl_code_t code, struct async *async );
155 static const struct object_ops pipe_server_ops =
157 sizeof(struct pipe_server), /* size */
158 pipe_server_dump, /* dump */
159 file_get_type, /* get_type */
160 add_queue, /* add_queue */
161 remove_queue, /* remove_queue */
162 default_fd_signaled, /* signaled */
163 no_satisfied, /* satisfied */
164 no_signal, /* signal */
165 pipe_end_get_fd, /* get_fd */
166 default_fd_map_access, /* map_access */
167 pipe_end_get_sd, /* get_sd */
168 pipe_end_set_sd, /* set_sd */
169 no_lookup_name, /* lookup_name */
170 no_link_name, /* link_name */
171 NULL, /* unlink_name */
172 no_open_file, /* open_file */
173 no_kernel_obj_list, /* get_kernel_obj_list */
174 fd_close_handle, /* close_handle */
175 pipe_server_destroy /* destroy */
178 static const struct fd_ops pipe_server_fd_ops =
180 default_fd_get_poll_events, /* get_poll_events */
181 default_poll_event, /* poll_event */
182 pipe_end_get_fd_type, /* get_fd_type */
183 pipe_end_read, /* read */
184 pipe_end_write, /* write */
185 pipe_end_flush, /* flush */
186 pipe_end_get_file_info, /* get_file_info */
187 pipe_end_get_volume_info, /* get_volume_info */
188 pipe_server_ioctl, /* ioctl */
189 no_fd_queue_async, /* queue_async */
190 pipe_end_reselect_async /* reselect_async */
193 /* client end functions */
194 static void pipe_client_dump( struct object *obj, int verbose );
195 static int pipe_client_ioctl( struct fd *fd, ioctl_code_t code, struct async *async );
197 static const struct object_ops pipe_client_ops =
199 sizeof(struct pipe_end), /* size */
200 pipe_client_dump, /* dump */
201 file_get_type, /* get_type */
202 add_queue, /* add_queue */
203 remove_queue, /* remove_queue */
204 default_fd_signaled, /* signaled */
205 no_satisfied, /* satisfied */
206 no_signal, /* signal */
207 pipe_end_get_fd, /* get_fd */
208 default_fd_map_access, /* map_access */
209 pipe_end_get_sd, /* get_sd */
210 pipe_end_set_sd, /* set_sd */
211 no_lookup_name, /* lookup_name */
212 no_link_name, /* link_name */
213 NULL, /* unlink_name */
214 no_open_file, /* open_file */
215 no_kernel_obj_list, /* get_kernel_obj_list */
216 fd_close_handle, /* close_handle */
217 pipe_end_destroy /* destroy */
220 static const struct fd_ops pipe_client_fd_ops =
222 default_fd_get_poll_events, /* get_poll_events */
223 default_poll_event, /* poll_event */
224 pipe_end_get_fd_type, /* get_fd_type */
225 pipe_end_read, /* read */
226 pipe_end_write, /* write */
227 pipe_end_flush, /* flush */
228 pipe_end_get_file_info, /* get_file_info */
229 pipe_end_get_volume_info, /* get_volume_info */
230 pipe_client_ioctl, /* ioctl */
231 no_fd_queue_async, /* queue_async */
232 pipe_end_reselect_async /* reselect_async */
235 static void named_pipe_device_dump( struct object *obj, int verbose );
236 static struct object_type *named_pipe_device_get_type( struct object *obj );
237 static struct object *named_pipe_device_lookup_name( struct object *obj,
238 struct unicode_str *name, unsigned int attr );
239 static struct object *named_pipe_device_open_file( struct object *obj, unsigned int access,
240 unsigned int sharing, unsigned int options );
241 static void named_pipe_device_destroy( struct object *obj );
243 static const struct object_ops named_pipe_device_ops =
245 sizeof(struct named_pipe_device), /* size */
246 named_pipe_device_dump, /* dump */
247 named_pipe_device_get_type, /* get_type */
248 no_add_queue, /* add_queue */
249 NULL, /* remove_queue */
250 NULL, /* signaled */
251 no_satisfied, /* satisfied */
252 no_signal, /* signal */
253 no_get_fd, /* get_fd */
254 no_map_access, /* map_access */
255 default_get_sd, /* get_sd */
256 default_set_sd, /* set_sd */
257 named_pipe_device_lookup_name, /* lookup_name */
258 directory_link_name, /* link_name */
259 default_unlink_name, /* unlink_name */
260 named_pipe_device_open_file, /* open_file */
261 no_kernel_obj_list, /* get_kernel_obj_list */
262 no_close_handle, /* close_handle */
263 named_pipe_device_destroy /* destroy */
266 static void named_pipe_device_file_dump( struct object *obj, int verbose );
267 static struct fd *named_pipe_device_file_get_fd( struct object *obj );
268 static int named_pipe_device_ioctl( struct fd *fd, ioctl_code_t code, struct async *async );
269 static enum server_fd_type named_pipe_device_file_get_fd_type( struct fd *fd );
270 static void named_pipe_device_file_destroy( struct object *obj );
272 static const struct object_ops named_pipe_device_file_ops =
274 sizeof(struct named_pipe_device_file), /* size */
275 named_pipe_device_file_dump, /* dump */
276 no_get_type, /* get_type */
277 add_queue, /* add_queue */
278 remove_queue, /* remove_queue */
279 default_fd_signaled, /* signaled */
280 no_satisfied, /* satisfied */
281 no_signal, /* signal */
282 named_pipe_device_file_get_fd, /* get_fd */
283 default_fd_map_access, /* map_access */
284 default_get_sd, /* get_sd */
285 default_set_sd, /* set_sd */
286 no_lookup_name, /* lookup_name */
287 no_link_name, /* link_name */
288 NULL, /* unlink_name */
289 no_open_file, /* open_file */
290 no_kernel_obj_list, /* get_kernel_obj_list */
291 fd_close_handle, /* close_handle */
292 named_pipe_device_file_destroy /* destroy */
295 static const struct fd_ops named_pipe_device_fd_ops =
297 default_fd_get_poll_events, /* get_poll_events */
298 default_poll_event, /* poll_event */
299 named_pipe_device_file_get_fd_type, /* get_fd_type */
300 no_fd_read, /* read */
301 no_fd_write, /* write */
302 no_fd_flush, /* flush */
303 default_fd_get_file_info, /* get_file_info */
304 no_fd_get_volume_info, /* get_volume_info */
305 named_pipe_device_ioctl, /* ioctl */
306 default_fd_queue_async, /* queue_async */
307 default_fd_reselect_async /* reselect_async */
310 static void named_pipe_dump( struct object *obj, int verbose )
312 fputs( "Named pipe\n", stderr );
315 static unsigned int named_pipe_map_access( struct object *obj, unsigned int access )
317 if (access & GENERIC_READ) access |= STANDARD_RIGHTS_READ;
318 if (access & GENERIC_WRITE) access |= STANDARD_RIGHTS_WRITE | FILE_CREATE_PIPE_INSTANCE;
319 if (access & GENERIC_EXECUTE) access |= STANDARD_RIGHTS_EXECUTE;
320 if (access & GENERIC_ALL) access |= STANDARD_RIGHTS_ALL;
321 return access & ~(GENERIC_READ | GENERIC_WRITE | GENERIC_EXECUTE | GENERIC_ALL);
324 static void pipe_server_dump( struct object *obj, int verbose )
326 struct pipe_server *server = (struct pipe_server *) obj;
327 assert( obj->ops == &pipe_server_ops );
328 fprintf( stderr, "Named pipe server pipe=%p state=%d\n", server->pipe_end.pipe,
329 server->pipe_end.state );
332 static void pipe_client_dump( struct object *obj, int verbose )
334 struct pipe_end *client = (struct pipe_end *) obj;
335 assert( obj->ops == &pipe_client_ops );
336 fprintf( stderr, "Named pipe client server=%p\n", client->connection );
339 static void named_pipe_destroy( struct object *obj)
341 struct named_pipe *pipe = (struct named_pipe *) obj;
343 assert( list_empty( &pipe->listeners ) );
344 assert( !pipe->instances );
345 free_async_queue( &pipe->waiters );
348 static struct fd *pipe_end_get_fd( struct object *obj )
350 struct pipe_end *pipe_end = (struct pipe_end *) obj;
351 return (struct fd *) grab_object( pipe_end->fd );
354 static struct pipe_message *queue_message( struct pipe_end *pipe_end, struct iosb *iosb )
356 struct pipe_message *message;
358 if (!(message = mem_alloc( sizeof(*message) ))) return NULL;
359 message->iosb = (struct iosb *)grab_object( iosb );
360 message->async = NULL;
361 message->read_pos = 0;
362 list_add_tail( &pipe_end->message_queue, &message->entry );
363 return message;
366 static void wake_message( struct pipe_message *message )
368 struct async *async = message->async;
370 message->async = NULL;
371 if (!async) return;
373 message->iosb->status = STATUS_SUCCESS;
374 message->iosb->result = message->iosb->in_size;
375 async_terminate( async, message->iosb->result ? STATUS_ALERTED : STATUS_SUCCESS );
376 release_object( async );
379 static void free_message( struct pipe_message *message )
381 list_remove( &message->entry );
382 if (message->iosb) release_object( message->iosb );
383 free( message );
386 static void pipe_end_disconnect( struct pipe_end *pipe_end, unsigned int status )
388 struct pipe_end *connection = pipe_end->connection;
389 struct pipe_message *message, *next;
390 struct async *async;
392 pipe_end->connection = NULL;
394 pipe_end->state = status == STATUS_PIPE_DISCONNECTED
395 ? FILE_PIPE_DISCONNECTED_STATE : FILE_PIPE_CLOSING_STATE;
396 fd_async_wake_up( pipe_end->fd, ASYNC_TYPE_WAIT, status );
397 async_wake_up( &pipe_end->read_q, status );
398 LIST_FOR_EACH_ENTRY_SAFE( message, next, &pipe_end->message_queue, struct pipe_message, entry )
400 async = message->async;
401 if (async || status == STATUS_PIPE_DISCONNECTED) free_message( message );
402 if (!async) continue;
403 async_terminate( async, status );
404 release_object( async );
406 if (status == STATUS_PIPE_DISCONNECTED) set_fd_signaled( pipe_end->fd, 0 );
408 if (connection)
410 connection->connection = NULL;
411 pipe_end_disconnect( connection, status );
415 static void pipe_end_destroy( struct object *obj )
417 struct pipe_end *pipe_end = (struct pipe_end *)obj;
418 struct pipe_message *message;
420 pipe_end_disconnect( pipe_end, STATUS_PIPE_BROKEN );
422 while (!list_empty( &pipe_end->message_queue ))
424 message = LIST_ENTRY( list_head(&pipe_end->message_queue), struct pipe_message, entry );
425 assert( !message->async );
426 free_message( message );
429 free_async_queue( &pipe_end->read_q );
430 free_async_queue( &pipe_end->write_q );
431 if (pipe_end->fd) release_object( pipe_end->fd );
432 if (pipe_end->pipe) release_object( pipe_end->pipe );
435 static void pipe_server_destroy( struct object *obj )
437 struct pipe_server *server = (struct pipe_server *)obj;
438 struct named_pipe *pipe = server->pipe_end.pipe;
440 assert( obj->ops == &pipe_server_ops );
442 assert( pipe->instances );
443 if (!--pipe->instances) unlink_named_object( &pipe->obj );
444 if (server->pipe_end.state == FILE_PIPE_LISTENING_STATE)
445 list_remove( &server->entry );
447 free_async_queue( &server->listen_q );
448 pipe_end_destroy( obj );
451 static void named_pipe_device_dump( struct object *obj, int verbose )
453 fputs( "Named pipe device\n", stderr );
456 static struct object_type *named_pipe_device_get_type( struct object *obj )
458 static const WCHAR name[] = {'D','e','v','i','c','e'};
459 static const struct unicode_str str = { name, sizeof(name) };
460 return get_object_type( &str );
463 static struct object *named_pipe_device_lookup_name( struct object *obj, struct unicode_str *name,
464 unsigned int attr )
466 struct named_pipe_device *device = (struct named_pipe_device*)obj;
467 struct object *found;
469 assert( obj->ops == &named_pipe_device_ops );
470 assert( device->pipes );
472 if (!name) return NULL; /* open the device itself */
474 if ((found = find_object( device->pipes, name, attr | OBJ_CASE_INSENSITIVE )))
475 name->len = 0;
477 return found;
480 static struct object *named_pipe_device_open_file( struct object *obj, unsigned int access,
481 unsigned int sharing, unsigned int options )
483 struct named_pipe_device_file *file;
485 if (!(file = alloc_object( &named_pipe_device_file_ops ))) return NULL;
486 file->device = (struct named_pipe_device *)grab_object( obj );
487 if (!(file->fd = alloc_pseudo_fd( &named_pipe_device_fd_ops, obj, options )))
489 release_object( file );
490 return NULL;
492 allow_fd_caching( file->fd );
493 return &file->obj;
496 static void named_pipe_device_destroy( struct object *obj )
498 struct named_pipe_device *device = (struct named_pipe_device*)obj;
499 assert( obj->ops == &named_pipe_device_ops );
500 free( device->pipes );
503 struct object *create_named_pipe_device( struct object *root, const struct unicode_str *name )
505 struct named_pipe_device *dev;
507 if ((dev = create_named_object( root, &named_pipe_device_ops, name, 0, NULL )) &&
508 get_error() != STATUS_OBJECT_NAME_EXISTS)
510 dev->pipes = NULL;
511 if (!(dev->pipes = create_namespace( 7 )))
513 release_object( dev );
514 dev = NULL;
517 return &dev->obj;
520 static void named_pipe_device_file_dump( struct object *obj, int verbose )
522 struct named_pipe_device_file *file = (struct named_pipe_device_file *)obj;
524 fprintf( stderr, "File on named pipe device %p\n", file->device );
527 static struct fd *named_pipe_device_file_get_fd( struct object *obj )
529 struct named_pipe_device_file *file = (struct named_pipe_device_file *)obj;
530 return (struct fd *)grab_object( file->fd );
533 static enum server_fd_type named_pipe_device_file_get_fd_type( struct fd *fd )
535 return FD_TYPE_DEVICE;
538 static void named_pipe_device_file_destroy( struct object *obj )
540 struct named_pipe_device_file *file = (struct named_pipe_device_file*)obj;
541 assert( obj->ops == &named_pipe_device_file_ops );
542 if (file->fd) release_object( file->fd );
543 release_object( file->device );
546 static int pipe_end_flush( struct fd *fd, struct async *async )
548 struct pipe_end *pipe_end = get_fd_user( fd );
550 if (!pipe_end->pipe)
552 set_error( STATUS_PIPE_DISCONNECTED );
553 return 0;
556 if (pipe_end->connection && !list_empty( &pipe_end->connection->message_queue ))
558 fd_queue_async( pipe_end->fd, async, ASYNC_TYPE_WAIT );
559 set_error( STATUS_PENDING );
561 return 1;
564 static void pipe_end_get_file_info( struct fd *fd, obj_handle_t handle, unsigned int info_class )
566 struct pipe_end *pipe_end = get_fd_user( fd );
567 struct named_pipe *pipe = pipe_end->pipe;
569 switch (info_class)
571 case FileNameInformation:
573 FILE_NAME_INFORMATION *name_info;
574 data_size_t name_len, reply_size;
575 const WCHAR *name;
577 if (get_reply_max_size() < sizeof(*name_info))
579 set_error( STATUS_INFO_LENGTH_MISMATCH );
580 return;
583 /* FIXME: We should be able to return on unlinked pipe */
584 if (!pipe || !(name = get_object_name( &pipe->obj, &name_len )))
586 set_error( STATUS_PIPE_DISCONNECTED );
587 return;
590 reply_size = offsetof( FILE_NAME_INFORMATION, FileName[name_len/sizeof(WCHAR) + 1] );
591 if (reply_size > get_reply_max_size())
593 reply_size = get_reply_max_size();
594 set_error( STATUS_BUFFER_OVERFLOW );
597 if (!(name_info = set_reply_data_size( reply_size ))) return;
598 name_info->FileNameLength = name_len + sizeof(WCHAR);
599 name_info->FileName[0] = '\\';
600 reply_size -= offsetof( FILE_NAME_INFORMATION, FileName[1] );
601 if (reply_size) memcpy( &name_info->FileName[1], name, reply_size );
602 break;
604 case FilePipeInformation:
606 FILE_PIPE_INFORMATION *pipe_info;
608 if (!(get_handle_access( current->process, handle) & FILE_READ_ATTRIBUTES))
610 set_error( STATUS_ACCESS_DENIED );
611 return;
614 if (get_reply_max_size() < sizeof(*pipe_info))
616 set_error( STATUS_INFO_LENGTH_MISMATCH );
617 return;
620 if (!pipe)
622 set_error( STATUS_PIPE_DISCONNECTED );
623 return;
626 if (!(pipe_info = set_reply_data_size( sizeof(*pipe_info) ))) return;
627 pipe_info->ReadMode = (pipe_end->flags & NAMED_PIPE_MESSAGE_STREAM_READ)
628 ? FILE_PIPE_MESSAGE_MODE : FILE_PIPE_BYTE_STREAM_MODE;
629 pipe_info->CompletionMode = (pipe_end->flags & NAMED_PIPE_NONBLOCKING_MODE)
630 ? FILE_PIPE_COMPLETE_OPERATION : FILE_PIPE_QUEUE_OPERATION;
631 break;
633 case FilePipeLocalInformation:
635 FILE_PIPE_LOCAL_INFORMATION *pipe_info;
637 if (!(get_handle_access( current->process, handle) & FILE_READ_ATTRIBUTES))
639 set_error( STATUS_ACCESS_DENIED );
640 return;
643 if (get_reply_max_size() < sizeof(*pipe_info))
645 set_error( STATUS_INFO_LENGTH_MISMATCH );
646 return;
649 if (!pipe)
651 set_error( STATUS_PIPE_DISCONNECTED );
652 return;
655 if (!(pipe_info = set_reply_data_size( sizeof(*pipe_info) ))) return;
656 pipe_info->NamedPipeType = pipe->message_mode;
657 switch (pipe->sharing)
659 case FILE_SHARE_READ:
660 pipe_info->NamedPipeConfiguration = FILE_PIPE_OUTBOUND;
661 break;
662 case FILE_SHARE_WRITE:
663 pipe_info->NamedPipeConfiguration = FILE_PIPE_INBOUND;
664 break;
665 case FILE_SHARE_READ | FILE_SHARE_WRITE:
666 pipe_info->NamedPipeConfiguration = FILE_PIPE_FULL_DUPLEX;
667 break;
669 pipe_info->MaximumInstances = pipe->maxinstances;
670 pipe_info->CurrentInstances = pipe->instances;
671 pipe_info->InboundQuota = pipe->insize;
672 pipe_info->ReadDataAvailable = 0; /* FIXME */
673 pipe_info->OutboundQuota = pipe->outsize;
674 pipe_info->WriteQuotaAvailable = 0; /* FIXME */
675 pipe_info->NamedPipeState = pipe_end->state;
676 pipe_info->NamedPipeEnd = pipe_end->obj.ops == &pipe_server_ops
677 ? FILE_PIPE_SERVER_END : FILE_PIPE_CLIENT_END;
678 break;
680 default:
681 default_fd_get_file_info( fd, handle, info_class );
685 static struct security_descriptor *pipe_end_get_sd( struct object *obj )
687 struct pipe_end *pipe_end = (struct pipe_end *) obj;
688 if (pipe_end->pipe) return default_get_sd( &pipe_end->pipe->obj );
689 set_error( STATUS_PIPE_DISCONNECTED );
690 return NULL;
693 static int pipe_end_set_sd( struct object *obj, const struct security_descriptor *sd,
694 unsigned int set_info )
696 struct pipe_end *pipe_end = (struct pipe_end *) obj;
697 if (pipe_end->pipe) return default_set_sd( &pipe_end->pipe->obj, sd, set_info );
698 set_error( STATUS_PIPE_DISCONNECTED );
699 return 0;
702 static void pipe_end_get_volume_info( struct fd *fd, unsigned int info_class )
704 switch (info_class)
706 case FileFsDeviceInformation:
708 static const FILE_FS_DEVICE_INFORMATION device_info =
710 FILE_DEVICE_NAMED_PIPE,
711 FILE_DEVICE_ALLOW_APPCONTAINER_TRAVERSAL
713 if (get_reply_max_size() >= sizeof(device_info))
714 set_reply_data( &device_info, sizeof(device_info) );
715 else
716 set_error( STATUS_BUFFER_TOO_SMALL );
717 break;
719 default:
720 set_error( STATUS_NOT_IMPLEMENTED );
724 static void message_queue_read( struct pipe_end *pipe_end, struct iosb *iosb )
726 struct pipe_message *message;
728 if (pipe_end->flags & NAMED_PIPE_MESSAGE_STREAM_READ)
730 message = LIST_ENTRY( list_head(&pipe_end->message_queue), struct pipe_message, entry );
731 iosb->out_size = min( iosb->out_size, message->iosb->in_size - message->read_pos );
732 iosb->status = message->read_pos + iosb->out_size < message->iosb->in_size
733 ? STATUS_BUFFER_OVERFLOW : STATUS_SUCCESS;
735 else
737 data_size_t avail = 0;
738 LIST_FOR_EACH_ENTRY( message, &pipe_end->message_queue, struct pipe_message, entry )
740 avail += message->iosb->in_size - message->read_pos;
741 if (avail >= iosb->out_size) break;
743 iosb->out_size = min( iosb->out_size, avail );
744 iosb->status = STATUS_SUCCESS;
747 message = LIST_ENTRY( list_head(&pipe_end->message_queue), struct pipe_message, entry );
748 if (!message->read_pos && message->iosb->in_size == iosb->out_size) /* fast path */
750 iosb->out_data = message->iosb->in_data;
751 message->iosb->in_data = NULL;
752 wake_message( message );
753 free_message( message );
755 else
757 data_size_t write_pos = 0, writing;
758 char *buf = NULL;
760 if (iosb->out_size && !(buf = iosb->out_data = malloc( iosb->out_size )))
762 iosb->out_size = 0;
763 iosb->status = STATUS_NO_MEMORY;
764 return;
769 message = LIST_ENTRY( list_head(&pipe_end->message_queue), struct pipe_message, entry );
770 writing = min( iosb->out_size - write_pos, message->iosb->in_size - message->read_pos );
771 if (writing) memcpy( buf + write_pos, (const char *)message->iosb->in_data + message->read_pos, writing );
772 write_pos += writing;
773 message->read_pos += writing;
774 if (message->read_pos == message->iosb->in_size)
776 wake_message(message);
777 free_message(message);
779 } while (write_pos < iosb->out_size);
781 iosb->result = iosb->out_size;
784 /* We call async_terminate in our reselect implementation, which causes recursive reselect.
785 * We're not interested in such reselect calls, so we ignore them. */
786 static int ignore_reselect;
788 static void reselect_write_queue( struct pipe_end *pipe_end );
790 static void reselect_read_queue( struct pipe_end *pipe_end )
792 struct async *async;
793 struct iosb *iosb;
794 int read_done = 0;
796 ignore_reselect = 1;
797 while (!list_empty( &pipe_end->message_queue ) && (async = find_pending_async( &pipe_end->read_q )))
799 iosb = async_get_iosb( async );
800 message_queue_read( pipe_end, iosb );
801 async_terminate( async, iosb->result ? STATUS_ALERTED : iosb->status );
802 release_object( async );
803 release_object( iosb );
804 read_done = 1;
806 ignore_reselect = 0;
808 if (pipe_end->connection)
810 if (list_empty( &pipe_end->message_queue ))
811 fd_async_wake_up( pipe_end->connection->fd, ASYNC_TYPE_WAIT, STATUS_SUCCESS );
812 else if (read_done)
813 reselect_write_queue( pipe_end->connection );
817 static void reselect_write_queue( struct pipe_end *pipe_end )
819 struct pipe_message *message, *next;
820 struct pipe_end *reader = pipe_end->connection;
821 data_size_t avail = 0;
823 if (!reader) return;
825 ignore_reselect = 1;
827 LIST_FOR_EACH_ENTRY_SAFE( message, next, &reader->message_queue, struct pipe_message, entry )
829 if (message->async && message->iosb->status != STATUS_PENDING)
831 release_object( message->async );
832 message->async = NULL;
833 free_message( message );
835 else
837 avail += message->iosb->in_size - message->read_pos;
838 if (message->async && (avail <= reader->buffer_size || !message->iosb->in_size))
839 wake_message( message );
843 ignore_reselect = 0;
844 reselect_read_queue( reader );
847 static int pipe_end_read( struct fd *fd, struct async *async, file_pos_t pos )
849 struct pipe_end *pipe_end = get_fd_user( fd );
851 switch (pipe_end->state)
853 case FILE_PIPE_CONNECTED_STATE:
854 break;
855 case FILE_PIPE_DISCONNECTED_STATE:
856 set_error( STATUS_PIPE_DISCONNECTED );
857 return 0;
858 case FILE_PIPE_LISTENING_STATE:
859 set_error( STATUS_PIPE_LISTENING );
860 return 0;
861 case FILE_PIPE_CLOSING_STATE:
862 if (!list_empty( &pipe_end->message_queue )) break;
863 set_error( STATUS_PIPE_BROKEN );
864 return 0;
867 queue_async( &pipe_end->read_q, async );
868 reselect_read_queue( pipe_end );
869 set_error( STATUS_PENDING );
870 return 1;
873 static int pipe_end_write( struct fd *fd, struct async *async, file_pos_t pos )
875 struct pipe_end *pipe_end = get_fd_user( fd );
876 struct pipe_message *message;
877 struct iosb *iosb;
879 switch (pipe_end->state)
881 case FILE_PIPE_CONNECTED_STATE:
882 break;
883 case FILE_PIPE_DISCONNECTED_STATE:
884 set_error( STATUS_PIPE_DISCONNECTED );
885 return 0;
886 case FILE_PIPE_LISTENING_STATE:
887 set_error( STATUS_PIPE_LISTENING );
888 return 0;
889 case FILE_PIPE_CLOSING_STATE:
890 set_error( STATUS_PIPE_CLOSING );
891 return 0;
894 if (!pipe_end->pipe->message_mode && !get_req_data_size()) return 1;
896 iosb = async_get_iosb( async );
897 message = queue_message( pipe_end->connection, iosb );
898 release_object( iosb );
899 if (!message) return 0;
901 message->async = (struct async *)grab_object( async );
902 queue_async( &pipe_end->write_q, async );
903 reselect_write_queue( pipe_end );
904 set_error( STATUS_PENDING );
905 return 1;
908 static void pipe_end_reselect_async( struct fd *fd, struct async_queue *queue )
910 struct pipe_end *pipe_end = get_fd_user( fd );
912 if (ignore_reselect) return;
914 if (&pipe_end->write_q == queue)
915 reselect_write_queue( pipe_end );
916 else if (&pipe_end->read_q == queue)
917 reselect_read_queue( pipe_end );
920 static enum server_fd_type pipe_end_get_fd_type( struct fd *fd )
922 return FD_TYPE_PIPE;
925 static int pipe_end_peek( struct pipe_end *pipe_end )
927 unsigned reply_size = get_reply_max_size();
928 FILE_PIPE_PEEK_BUFFER *buffer;
929 struct pipe_message *message;
930 data_size_t avail = 0;
931 data_size_t message_length = 0;
933 if (reply_size < offsetof( FILE_PIPE_PEEK_BUFFER, Data ))
935 set_error( STATUS_INFO_LENGTH_MISMATCH );
936 return 0;
938 reply_size -= offsetof( FILE_PIPE_PEEK_BUFFER, Data );
940 switch (pipe_end->state)
942 case FILE_PIPE_CONNECTED_STATE:
943 break;
944 case FILE_PIPE_CLOSING_STATE:
945 if (!list_empty( &pipe_end->message_queue )) break;
946 set_error( STATUS_PIPE_BROKEN );
947 return 0;
948 default:
949 set_error( pipe_end->pipe ? STATUS_INVALID_PIPE_STATE : STATUS_PIPE_DISCONNECTED );
950 return 0;
953 LIST_FOR_EACH_ENTRY( message, &pipe_end->message_queue, struct pipe_message, entry )
954 avail += message->iosb->in_size - message->read_pos;
955 reply_size = min( reply_size, avail );
957 if (avail && pipe_end->pipe->message_mode)
959 message = LIST_ENTRY( list_head(&pipe_end->message_queue), struct pipe_message, entry );
960 message_length = message->iosb->in_size - message->read_pos;
961 reply_size = min( reply_size, message_length );
964 if (!(buffer = set_reply_data_size( offsetof( FILE_PIPE_PEEK_BUFFER, Data[reply_size] )))) return 0;
965 buffer->NamedPipeState = pipe_end->state;
966 buffer->ReadDataAvailable = avail;
967 buffer->NumberOfMessages = 0; /* FIXME */
968 buffer->MessageLength = message_length;
970 if (reply_size)
972 data_size_t write_pos = 0, writing;
973 LIST_FOR_EACH_ENTRY( message, &pipe_end->message_queue, struct pipe_message, entry )
975 writing = min( reply_size - write_pos, message->iosb->in_size - message->read_pos );
976 memcpy( buffer->Data + write_pos, (const char *)message->iosb->in_data + message->read_pos,
977 writing );
978 write_pos += writing;
979 if (write_pos == reply_size) break;
982 if (message_length > reply_size) set_error( STATUS_BUFFER_OVERFLOW );
983 return 1;
986 static int pipe_end_transceive( struct pipe_end *pipe_end, struct async *async )
988 struct pipe_message *message;
989 struct iosb *iosb;
991 if (!pipe_end->connection)
993 set_error( pipe_end->pipe ? STATUS_INVALID_PIPE_STATE : STATUS_PIPE_DISCONNECTED );
994 return 0;
997 if (!(pipe_end->flags & NAMED_PIPE_MESSAGE_STREAM_READ))
999 set_error( STATUS_INVALID_READ_MODE );
1000 return 0;
1003 /* not allowed if we already have read data buffered */
1004 if (!list_empty( &pipe_end->message_queue ))
1006 set_error( STATUS_PIPE_BUSY );
1007 return 0;
1010 iosb = async_get_iosb( async );
1011 /* ignore output buffer copy transferred because of METHOD_NEITHER */
1012 iosb->in_size -= iosb->out_size;
1013 /* transaction never blocks on write, so just queue a message without async */
1014 message = queue_message( pipe_end->connection, iosb );
1015 release_object( iosb );
1016 if (!message) return 0;
1017 reselect_read_queue( pipe_end->connection );
1019 queue_async( &pipe_end->read_q, async );
1020 reselect_read_queue( pipe_end );
1021 set_error( STATUS_PENDING );
1022 return 1;
1025 static int pipe_end_get_connection_attribute( struct pipe_end *pipe_end )
1027 const char *attr = get_req_data();
1028 data_size_t value_size, attr_size = get_req_data_size();
1029 void *value;
1031 if (attr_size == sizeof("ClientProcessId") && !memcmp( attr, "ClientProcessId", attr_size ))
1033 value = &pipe_end->client_pid;
1034 value_size = sizeof(pipe_end->client_pid);
1036 else if (attr_size == sizeof("ServerProcessId") && !memcmp( attr, "ServerProcessId", attr_size ))
1038 value = &pipe_end->server_pid;
1039 value_size = sizeof(pipe_end->server_pid);
1041 else
1043 set_error( STATUS_ILLEGAL_FUNCTION );
1044 return 0;
1047 if (get_reply_max_size() < value_size)
1049 set_error( STATUS_INFO_LENGTH_MISMATCH );
1050 return 0;
1053 set_reply_data( value, value_size );
1054 return 1;
1057 static int pipe_end_ioctl( struct pipe_end *pipe_end, ioctl_code_t code, struct async *async )
1059 switch(code)
1061 case FSCTL_PIPE_GET_CONNECTION_ATTRIBUTE:
1062 return pipe_end_get_connection_attribute( pipe_end );
1064 case FSCTL_PIPE_PEEK:
1065 return pipe_end_peek( pipe_end );
1067 case FSCTL_PIPE_TRANSCEIVE:
1068 return pipe_end_transceive( pipe_end, async );
1070 default:
1071 return default_fd_ioctl( pipe_end->fd, code, async );
1075 static int pipe_server_ioctl( struct fd *fd, ioctl_code_t code, struct async *async )
1077 struct pipe_server *server = get_fd_user( fd );
1079 switch(code)
1081 case FSCTL_PIPE_LISTEN:
1082 switch(server->pipe_end.state)
1084 case FILE_PIPE_LISTENING_STATE:
1085 break;
1086 case FILE_PIPE_DISCONNECTED_STATE:
1087 server->pipe_end.state = FILE_PIPE_LISTENING_STATE;
1088 list_add_tail( &server->pipe_end.pipe->listeners, &server->entry );
1089 break;
1090 case FILE_PIPE_CONNECTED_STATE:
1091 set_error( STATUS_PIPE_CONNECTED );
1092 return 0;
1093 case FILE_PIPE_CLOSING_STATE:
1094 set_error( STATUS_PIPE_CLOSING );
1095 return 0;
1098 queue_async( &server->listen_q, async );
1099 async_wake_up( &server->pipe_end.pipe->waiters, STATUS_SUCCESS );
1100 set_error( STATUS_PENDING );
1101 return 1;
1103 case FSCTL_PIPE_DISCONNECT:
1104 switch(server->pipe_end.state)
1106 case FILE_PIPE_CONNECTED_STATE:
1107 /* dump the client connection - all data is lost */
1108 assert( server->pipe_end.connection );
1109 release_object( server->pipe_end.connection->pipe );
1110 server->pipe_end.connection->pipe = NULL;
1111 break;
1112 case FILE_PIPE_CLOSING_STATE:
1113 break;
1114 case FILE_PIPE_LISTENING_STATE:
1115 set_error( STATUS_PIPE_LISTENING );
1116 return 0;
1117 case FILE_PIPE_DISCONNECTED_STATE:
1118 set_error( STATUS_PIPE_DISCONNECTED );
1119 return 0;
1122 pipe_end_disconnect( &server->pipe_end, STATUS_PIPE_DISCONNECTED );
1123 return 1;
1125 default:
1126 return pipe_end_ioctl( &server->pipe_end, code, async );
1130 static int pipe_client_ioctl( struct fd *fd, ioctl_code_t code, struct async *async )
1132 struct pipe_end *client = get_fd_user( fd );
1134 switch(code)
1136 case FSCTL_PIPE_LISTEN:
1137 set_error( STATUS_ILLEGAL_FUNCTION );
1138 return 0;
1140 default:
1141 return pipe_end_ioctl( client, code, async );
1145 static void init_pipe_end( struct pipe_end *pipe_end, struct named_pipe *pipe,
1146 unsigned int pipe_flags, data_size_t buffer_size )
1148 pipe_end->pipe = (struct named_pipe *)grab_object( pipe );
1149 pipe_end->fd = NULL;
1150 pipe_end->flags = pipe_flags;
1151 pipe_end->connection = NULL;
1152 pipe_end->buffer_size = buffer_size;
1153 init_async_queue( &pipe_end->read_q );
1154 init_async_queue( &pipe_end->write_q );
1155 list_init( &pipe_end->message_queue );
1158 static struct pipe_server *create_pipe_server( struct named_pipe *pipe, unsigned int options,
1159 unsigned int pipe_flags )
1161 struct pipe_server *server;
1163 server = alloc_object( &pipe_server_ops );
1164 if (!server)
1165 return NULL;
1167 server->options = options;
1168 init_pipe_end( &server->pipe_end, pipe, pipe_flags, pipe->insize );
1169 server->pipe_end.state = FILE_PIPE_LISTENING_STATE;
1170 server->pipe_end.server_pid = get_process_id( current->process );
1171 init_async_queue( &server->listen_q );
1173 list_add_tail( &pipe->listeners, &server->entry );
1174 if (!(server->pipe_end.fd = alloc_pseudo_fd( &pipe_server_fd_ops, &server->pipe_end.obj, options )))
1176 release_object( server );
1177 return NULL;
1179 allow_fd_caching( server->pipe_end.fd );
1180 set_fd_signaled( server->pipe_end.fd, 1 );
1181 async_wake_up( &pipe->waiters, STATUS_SUCCESS );
1182 return server;
1185 static struct pipe_end *create_pipe_client( struct named_pipe *pipe, data_size_t buffer_size, unsigned int options )
1187 struct pipe_end *client;
1189 client = alloc_object( &pipe_client_ops );
1190 if (!client)
1191 return NULL;
1193 init_pipe_end( client, pipe, 0, buffer_size );
1194 client->state = FILE_PIPE_CONNECTED_STATE;
1195 client->client_pid = get_process_id( current->process );
1197 client->fd = alloc_pseudo_fd( &pipe_client_fd_ops, &client->obj, options );
1198 if (!client->fd)
1200 release_object( client );
1201 return NULL;
1203 allow_fd_caching( client->fd );
1204 set_fd_signaled( client->fd, 1 );
1206 return client;
1209 static int named_pipe_link_name( struct object *obj, struct object_name *name, struct object *parent )
1211 struct named_pipe_device *dev = (struct named_pipe_device *)parent;
1213 if (parent->ops != &named_pipe_device_ops)
1215 set_error( STATUS_OBJECT_NAME_INVALID );
1216 return 0;
1218 namespace_add( dev->pipes, name );
1219 name->parent = grab_object( parent );
1220 return 1;
1223 static struct object *named_pipe_open_file( struct object *obj, unsigned int access,
1224 unsigned int sharing, unsigned int options )
1226 struct named_pipe *pipe = (struct named_pipe *)obj;
1227 struct pipe_server *server;
1228 struct pipe_end *client;
1229 unsigned int pipe_sharing;
1231 if (list_empty( &pipe->listeners ))
1233 set_error( STATUS_PIPE_NOT_AVAILABLE );
1234 return NULL;
1236 server = LIST_ENTRY( list_head( &pipe->listeners ), struct pipe_server, entry );
1238 pipe_sharing = pipe->sharing;
1239 if (((access & GENERIC_READ) && !(pipe_sharing & FILE_SHARE_READ)) ||
1240 ((access & GENERIC_WRITE) && !(pipe_sharing & FILE_SHARE_WRITE)))
1242 set_error( STATUS_ACCESS_DENIED );
1243 return NULL;
1246 if ((client = create_pipe_client( pipe, pipe->outsize, options )))
1248 async_wake_up( &server->listen_q, STATUS_SUCCESS );
1249 server->pipe_end.state = FILE_PIPE_CONNECTED_STATE;
1250 server->pipe_end.connection = client;
1251 client->connection = &server->pipe_end;
1252 server->pipe_end.client_pid = client->client_pid;
1253 client->server_pid = server->pipe_end.server_pid;
1254 list_remove( &server->entry );
1256 return &client->obj;
1259 static int named_pipe_device_ioctl( struct fd *fd, ioctl_code_t code, struct async *async )
1261 struct named_pipe_device *device = get_fd_user( fd );
1263 switch(code)
1265 case FSCTL_PIPE_WAIT:
1267 const FILE_PIPE_WAIT_FOR_BUFFER *buffer = get_req_data();
1268 data_size_t size = get_req_data_size();
1269 struct named_pipe *pipe;
1270 struct unicode_str name;
1271 timeout_t when;
1273 if (size < sizeof(*buffer) ||
1274 size < FIELD_OFFSET(FILE_PIPE_WAIT_FOR_BUFFER, Name[buffer->NameLength/sizeof(WCHAR)]))
1276 set_error( STATUS_INVALID_PARAMETER );
1277 return 0;
1279 name.str = buffer->Name;
1280 name.len = (buffer->NameLength / sizeof(WCHAR)) * sizeof(WCHAR);
1281 if (!(pipe = open_named_object( &device->obj, &named_pipe_ops, &name, 0 ))) return 0;
1283 if (list_empty( &pipe->listeners ))
1285 queue_async( &pipe->waiters, async );
1286 when = buffer->TimeoutSpecified ? buffer->Timeout.QuadPart : pipe->timeout;
1287 async_set_timeout( async, when, STATUS_IO_TIMEOUT );
1288 set_error( STATUS_PENDING );
1291 release_object( pipe );
1292 return 1;
1295 default:
1296 return default_fd_ioctl( fd, code, async );
1301 DECL_HANDLER(create_named_pipe)
1303 struct named_pipe *pipe;
1304 struct pipe_server *server;
1305 struct unicode_str name;
1306 struct object *root;
1307 const struct security_descriptor *sd;
1308 const struct object_attributes *objattr = get_req_object_attributes( &sd, &name, &root );
1310 if (!objattr) return;
1312 if (!req->sharing || (req->sharing & ~(FILE_SHARE_READ | FILE_SHARE_WRITE)) ||
1313 (!(req->flags & NAMED_PIPE_MESSAGE_STREAM_WRITE) && (req->flags & NAMED_PIPE_MESSAGE_STREAM_READ)))
1315 if (root) release_object( root );
1316 set_error( STATUS_INVALID_PARAMETER );
1317 return;
1320 if (!name.len) /* pipes need a root directory even without a name */
1322 if (!objattr->rootdir)
1324 set_error( STATUS_OBJECT_PATH_SYNTAX_BAD );
1325 return;
1327 if (!(root = get_directory_obj( current->process, objattr->rootdir ))) return;
1330 pipe = create_named_object( root, &named_pipe_ops, &name, objattr->attributes | OBJ_OPENIF, NULL );
1332 if (root) release_object( root );
1333 if (!pipe) return;
1335 if (get_error() != STATUS_OBJECT_NAME_EXISTS)
1337 /* initialize it if it didn't already exist */
1338 pipe->instances = 0;
1339 init_async_queue( &pipe->waiters );
1340 list_init( &pipe->listeners );
1341 pipe->insize = req->insize;
1342 pipe->outsize = req->outsize;
1343 pipe->maxinstances = req->maxinstances;
1344 pipe->timeout = req->timeout;
1345 pipe->message_mode = (req->flags & NAMED_PIPE_MESSAGE_STREAM_WRITE) != 0;
1346 pipe->sharing = req->sharing;
1347 if (sd) default_set_sd( &pipe->obj, sd, OWNER_SECURITY_INFORMATION |
1348 GROUP_SECURITY_INFORMATION |
1349 DACL_SECURITY_INFORMATION |
1350 SACL_SECURITY_INFORMATION );
1352 else
1354 if (pipe->maxinstances <= pipe->instances)
1356 set_error( STATUS_INSTANCE_NOT_AVAILABLE );
1357 release_object( pipe );
1358 return;
1360 if (pipe->sharing != req->sharing)
1362 set_error( STATUS_ACCESS_DENIED );
1363 release_object( pipe );
1364 return;
1366 clear_error(); /* clear the name collision */
1369 server = create_pipe_server( pipe, req->options, req->flags );
1370 if (server)
1372 reply->handle = alloc_handle( current->process, server, req->access, objattr->attributes );
1373 pipe->instances++;
1374 release_object( server );
1377 release_object( pipe );
1380 DECL_HANDLER(set_named_pipe_info)
1382 struct pipe_end *pipe_end;
1384 pipe_end = (struct pipe_end *)get_handle_obj( current->process, req->handle,
1385 FILE_WRITE_ATTRIBUTES, &pipe_server_ops );
1386 if (!pipe_end)
1388 if (get_error() != STATUS_OBJECT_TYPE_MISMATCH)
1389 return;
1391 clear_error();
1392 pipe_end = (struct pipe_end *)get_handle_obj( current->process, req->handle,
1393 0, &pipe_client_ops );
1394 if (!pipe_end) return;
1397 if (!pipe_end->pipe)
1399 set_error( STATUS_PIPE_DISCONNECTED );
1401 else if ((req->flags & ~(NAMED_PIPE_MESSAGE_STREAM_READ | NAMED_PIPE_NONBLOCKING_MODE)) ||
1402 ((req->flags & NAMED_PIPE_MESSAGE_STREAM_READ) && !pipe_end->pipe->message_mode))
1404 set_error( STATUS_INVALID_PARAMETER );
1406 else
1408 pipe_end->flags = req->flags;
1411 release_object( pipe_end );