msi/tests: Remove workarounds for Windows 2000.
[wine.git] / server / named_pipe.c
blobf97b14164154d4e54468caf739d9f354aee9755b
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, data_size_t result )
368 struct async *async = message->async;
370 message->async = NULL;
371 if (!async) return;
373 message->iosb->status = STATUS_SUCCESS;
374 message->iosb->result = result;
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, message->iosb->in_size );
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, message->iosb->in_size);
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, int reselect_write )
792 struct async *async;
793 struct iosb *iosb;
795 ignore_reselect = 1;
796 while (!list_empty( &pipe_end->message_queue ) && (async = find_pending_async( &pipe_end->read_q )))
798 iosb = async_get_iosb( async );
799 message_queue_read( pipe_end, iosb );
800 async_terminate( async, iosb->result ? STATUS_ALERTED : iosb->status );
801 release_object( async );
802 release_object( iosb );
803 reselect_write = 1;
805 ignore_reselect = 0;
807 if (pipe_end->connection)
809 if (list_empty( &pipe_end->message_queue ))
810 fd_async_wake_up( pipe_end->connection->fd, ASYNC_TYPE_WAIT, STATUS_SUCCESS );
811 else if (reselect_write)
812 reselect_write_queue( pipe_end->connection );
816 static void reselect_write_queue( struct pipe_end *pipe_end )
818 struct pipe_message *message, *next;
819 struct pipe_end *reader = pipe_end->connection;
820 data_size_t avail = 0;
822 if (!reader) return;
824 ignore_reselect = 1;
826 LIST_FOR_EACH_ENTRY_SAFE( message, next, &reader->message_queue, struct pipe_message, entry )
828 if (message->async && message->iosb->status != STATUS_PENDING)
830 release_object( message->async );
831 message->async = NULL;
832 free_message( message );
834 else
836 avail += message->iosb->in_size - message->read_pos;
837 if (message->async && (avail <= reader->buffer_size || !message->iosb->in_size))
839 wake_message( message, message->iosb->in_size );
841 else if (message->async && (pipe_end->flags & NAMED_PIPE_NONBLOCKING_MODE))
843 wake_message( message, message->read_pos );
844 free_message( message );
849 ignore_reselect = 0;
850 reselect_read_queue( reader, 0 );
853 static int pipe_end_read( struct fd *fd, struct async *async, file_pos_t pos )
855 struct pipe_end *pipe_end = get_fd_user( fd );
857 switch (pipe_end->state)
859 case FILE_PIPE_CONNECTED_STATE:
860 if ((pipe_end->flags & NAMED_PIPE_NONBLOCKING_MODE) && list_empty( &pipe_end->message_queue ))
862 set_error( STATUS_PIPE_EMPTY );
863 return 0;
865 break;
866 case FILE_PIPE_DISCONNECTED_STATE:
867 set_error( STATUS_PIPE_DISCONNECTED );
868 return 0;
869 case FILE_PIPE_LISTENING_STATE:
870 set_error( STATUS_PIPE_LISTENING );
871 return 0;
872 case FILE_PIPE_CLOSING_STATE:
873 if (!list_empty( &pipe_end->message_queue )) break;
874 set_error( STATUS_PIPE_BROKEN );
875 return 0;
878 queue_async( &pipe_end->read_q, async );
879 reselect_read_queue( pipe_end, 0 );
880 set_error( STATUS_PENDING );
881 return 1;
884 static int pipe_end_write( struct fd *fd, struct async *async, file_pos_t pos )
886 struct pipe_end *pipe_end = get_fd_user( fd );
887 struct pipe_message *message;
888 struct iosb *iosb;
890 switch (pipe_end->state)
892 case FILE_PIPE_CONNECTED_STATE:
893 break;
894 case FILE_PIPE_DISCONNECTED_STATE:
895 set_error( STATUS_PIPE_DISCONNECTED );
896 return 0;
897 case FILE_PIPE_LISTENING_STATE:
898 set_error( STATUS_PIPE_LISTENING );
899 return 0;
900 case FILE_PIPE_CLOSING_STATE:
901 set_error( STATUS_PIPE_CLOSING );
902 return 0;
905 if (!pipe_end->pipe->message_mode && !get_req_data_size()) return 1;
907 iosb = async_get_iosb( async );
908 message = queue_message( pipe_end->connection, iosb );
909 release_object( iosb );
910 if (!message) return 0;
912 message->async = (struct async *)grab_object( async );
913 queue_async( &pipe_end->write_q, async );
914 reselect_read_queue( pipe_end->connection, 1 );
915 set_error( STATUS_PENDING );
916 return 1;
919 static void pipe_end_reselect_async( struct fd *fd, struct async_queue *queue )
921 struct pipe_end *pipe_end = get_fd_user( fd );
923 if (ignore_reselect) return;
925 if (&pipe_end->write_q == queue)
926 reselect_write_queue( pipe_end );
927 else if (&pipe_end->read_q == queue)
928 reselect_read_queue( pipe_end, 0 );
931 static enum server_fd_type pipe_end_get_fd_type( struct fd *fd )
933 return FD_TYPE_PIPE;
936 static int pipe_end_peek( struct pipe_end *pipe_end )
938 unsigned reply_size = get_reply_max_size();
939 FILE_PIPE_PEEK_BUFFER *buffer;
940 struct pipe_message *message;
941 data_size_t avail = 0;
942 data_size_t message_length = 0;
944 if (reply_size < offsetof( FILE_PIPE_PEEK_BUFFER, Data ))
946 set_error( STATUS_INFO_LENGTH_MISMATCH );
947 return 0;
949 reply_size -= offsetof( FILE_PIPE_PEEK_BUFFER, Data );
951 switch (pipe_end->state)
953 case FILE_PIPE_CONNECTED_STATE:
954 break;
955 case FILE_PIPE_CLOSING_STATE:
956 if (!list_empty( &pipe_end->message_queue )) break;
957 set_error( STATUS_PIPE_BROKEN );
958 return 0;
959 default:
960 set_error( pipe_end->pipe ? STATUS_INVALID_PIPE_STATE : STATUS_PIPE_DISCONNECTED );
961 return 0;
964 LIST_FOR_EACH_ENTRY( message, &pipe_end->message_queue, struct pipe_message, entry )
965 avail += message->iosb->in_size - message->read_pos;
966 reply_size = min( reply_size, avail );
968 if (avail && pipe_end->pipe->message_mode)
970 message = LIST_ENTRY( list_head(&pipe_end->message_queue), struct pipe_message, entry );
971 message_length = message->iosb->in_size - message->read_pos;
972 reply_size = min( reply_size, message_length );
975 if (!(buffer = set_reply_data_size( offsetof( FILE_PIPE_PEEK_BUFFER, Data[reply_size] )))) return 0;
976 buffer->NamedPipeState = pipe_end->state;
977 buffer->ReadDataAvailable = avail;
978 buffer->NumberOfMessages = 0; /* FIXME */
979 buffer->MessageLength = message_length;
981 if (reply_size)
983 data_size_t write_pos = 0, writing;
984 LIST_FOR_EACH_ENTRY( message, &pipe_end->message_queue, struct pipe_message, entry )
986 writing = min( reply_size - write_pos, message->iosb->in_size - message->read_pos );
987 memcpy( buffer->Data + write_pos, (const char *)message->iosb->in_data + message->read_pos,
988 writing );
989 write_pos += writing;
990 if (write_pos == reply_size) break;
993 if (message_length > reply_size) set_error( STATUS_BUFFER_OVERFLOW );
994 return 1;
997 static int pipe_end_transceive( struct pipe_end *pipe_end, struct async *async )
999 struct pipe_message *message;
1000 struct iosb *iosb;
1002 if (!pipe_end->connection)
1004 set_error( pipe_end->pipe ? STATUS_INVALID_PIPE_STATE : STATUS_PIPE_DISCONNECTED );
1005 return 0;
1008 if (!(pipe_end->flags & NAMED_PIPE_MESSAGE_STREAM_READ))
1010 set_error( STATUS_INVALID_READ_MODE );
1011 return 0;
1014 /* not allowed if we already have read data buffered */
1015 if (!list_empty( &pipe_end->message_queue ))
1017 set_error( STATUS_PIPE_BUSY );
1018 return 0;
1021 iosb = async_get_iosb( async );
1022 /* ignore output buffer copy transferred because of METHOD_NEITHER */
1023 iosb->in_size -= iosb->out_size;
1024 /* transaction never blocks on write, so just queue a message without async */
1025 message = queue_message( pipe_end->connection, iosb );
1026 release_object( iosb );
1027 if (!message) return 0;
1028 reselect_read_queue( pipe_end->connection, 0 );
1030 queue_async( &pipe_end->read_q, async );
1031 reselect_read_queue( pipe_end, 0 );
1032 set_error( STATUS_PENDING );
1033 return 1;
1036 static int pipe_end_get_connection_attribute( struct pipe_end *pipe_end )
1038 const char *attr = get_req_data();
1039 data_size_t value_size, attr_size = get_req_data_size();
1040 void *value;
1042 if (attr_size == sizeof("ClientProcessId") && !memcmp( attr, "ClientProcessId", attr_size ))
1044 value = &pipe_end->client_pid;
1045 value_size = sizeof(pipe_end->client_pid);
1047 else if (attr_size == sizeof("ServerProcessId") && !memcmp( attr, "ServerProcessId", attr_size ))
1049 value = &pipe_end->server_pid;
1050 value_size = sizeof(pipe_end->server_pid);
1052 else
1054 set_error( STATUS_ILLEGAL_FUNCTION );
1055 return 0;
1058 if (get_reply_max_size() < value_size)
1060 set_error( STATUS_INFO_LENGTH_MISMATCH );
1061 return 0;
1064 set_reply_data( value, value_size );
1065 return 1;
1068 static int pipe_end_ioctl( struct pipe_end *pipe_end, ioctl_code_t code, struct async *async )
1070 switch(code)
1072 case FSCTL_PIPE_GET_CONNECTION_ATTRIBUTE:
1073 return pipe_end_get_connection_attribute( pipe_end );
1075 case FSCTL_PIPE_PEEK:
1076 return pipe_end_peek( pipe_end );
1078 case FSCTL_PIPE_TRANSCEIVE:
1079 return pipe_end_transceive( pipe_end, async );
1081 default:
1082 return default_fd_ioctl( pipe_end->fd, code, async );
1086 static int pipe_server_ioctl( struct fd *fd, ioctl_code_t code, struct async *async )
1088 struct pipe_server *server = get_fd_user( fd );
1090 switch(code)
1092 case FSCTL_PIPE_LISTEN:
1093 switch(server->pipe_end.state)
1095 case FILE_PIPE_LISTENING_STATE:
1096 break;
1097 case FILE_PIPE_DISCONNECTED_STATE:
1098 server->pipe_end.state = FILE_PIPE_LISTENING_STATE;
1099 list_add_tail( &server->pipe_end.pipe->listeners, &server->entry );
1100 break;
1101 case FILE_PIPE_CONNECTED_STATE:
1102 set_error( STATUS_PIPE_CONNECTED );
1103 return 0;
1104 case FILE_PIPE_CLOSING_STATE:
1105 set_error( STATUS_PIPE_CLOSING );
1106 return 0;
1109 if (server->pipe_end.flags & NAMED_PIPE_NONBLOCKING_MODE)
1111 set_error( STATUS_PIPE_LISTENING );
1112 return 0;
1114 queue_async( &server->listen_q, async );
1115 async_wake_up( &server->pipe_end.pipe->waiters, STATUS_SUCCESS );
1116 set_error( STATUS_PENDING );
1117 return 1;
1119 case FSCTL_PIPE_DISCONNECT:
1120 switch(server->pipe_end.state)
1122 case FILE_PIPE_CONNECTED_STATE:
1123 /* dump the client connection - all data is lost */
1124 assert( server->pipe_end.connection );
1125 release_object( server->pipe_end.connection->pipe );
1126 server->pipe_end.connection->pipe = NULL;
1127 break;
1128 case FILE_PIPE_CLOSING_STATE:
1129 break;
1130 case FILE_PIPE_LISTENING_STATE:
1131 set_error( STATUS_PIPE_LISTENING );
1132 return 0;
1133 case FILE_PIPE_DISCONNECTED_STATE:
1134 set_error( STATUS_PIPE_DISCONNECTED );
1135 return 0;
1138 pipe_end_disconnect( &server->pipe_end, STATUS_PIPE_DISCONNECTED );
1139 return 1;
1141 default:
1142 return pipe_end_ioctl( &server->pipe_end, code, async );
1146 static int pipe_client_ioctl( struct fd *fd, ioctl_code_t code, struct async *async )
1148 struct pipe_end *client = get_fd_user( fd );
1150 switch(code)
1152 case FSCTL_PIPE_LISTEN:
1153 set_error( STATUS_ILLEGAL_FUNCTION );
1154 return 0;
1156 default:
1157 return pipe_end_ioctl( client, code, async );
1161 static void init_pipe_end( struct pipe_end *pipe_end, struct named_pipe *pipe,
1162 unsigned int pipe_flags, data_size_t buffer_size )
1164 pipe_end->pipe = (struct named_pipe *)grab_object( pipe );
1165 pipe_end->fd = NULL;
1166 pipe_end->flags = pipe_flags;
1167 pipe_end->connection = NULL;
1168 pipe_end->buffer_size = buffer_size;
1169 init_async_queue( &pipe_end->read_q );
1170 init_async_queue( &pipe_end->write_q );
1171 list_init( &pipe_end->message_queue );
1174 static struct pipe_server *create_pipe_server( struct named_pipe *pipe, unsigned int options,
1175 unsigned int pipe_flags )
1177 struct pipe_server *server;
1179 server = alloc_object( &pipe_server_ops );
1180 if (!server)
1181 return NULL;
1183 server->options = options;
1184 init_pipe_end( &server->pipe_end, pipe, pipe_flags, pipe->insize );
1185 server->pipe_end.state = FILE_PIPE_LISTENING_STATE;
1186 server->pipe_end.server_pid = get_process_id( current->process );
1187 init_async_queue( &server->listen_q );
1189 list_add_tail( &pipe->listeners, &server->entry );
1190 if (!(server->pipe_end.fd = alloc_pseudo_fd( &pipe_server_fd_ops, &server->pipe_end.obj, options )))
1192 release_object( server );
1193 return NULL;
1195 allow_fd_caching( server->pipe_end.fd );
1196 set_fd_signaled( server->pipe_end.fd, 1 );
1197 async_wake_up( &pipe->waiters, STATUS_SUCCESS );
1198 return server;
1201 static struct pipe_end *create_pipe_client( struct named_pipe *pipe, data_size_t buffer_size, unsigned int options )
1203 struct pipe_end *client;
1205 client = alloc_object( &pipe_client_ops );
1206 if (!client)
1207 return NULL;
1209 init_pipe_end( client, pipe, 0, buffer_size );
1210 client->state = FILE_PIPE_CONNECTED_STATE;
1211 client->client_pid = get_process_id( current->process );
1213 client->fd = alloc_pseudo_fd( &pipe_client_fd_ops, &client->obj, options );
1214 if (!client->fd)
1216 release_object( client );
1217 return NULL;
1219 allow_fd_caching( client->fd );
1220 set_fd_signaled( client->fd, 1 );
1222 return client;
1225 static int named_pipe_link_name( struct object *obj, struct object_name *name, struct object *parent )
1227 struct named_pipe_device *dev = (struct named_pipe_device *)parent;
1229 if (parent->ops != &named_pipe_device_ops)
1231 set_error( STATUS_OBJECT_NAME_INVALID );
1232 return 0;
1234 namespace_add( dev->pipes, name );
1235 name->parent = grab_object( parent );
1236 return 1;
1239 static struct object *named_pipe_open_file( struct object *obj, unsigned int access,
1240 unsigned int sharing, unsigned int options )
1242 struct named_pipe *pipe = (struct named_pipe *)obj;
1243 struct pipe_server *server;
1244 struct pipe_end *client;
1245 unsigned int pipe_sharing;
1247 if (list_empty( &pipe->listeners ))
1249 set_error( STATUS_PIPE_NOT_AVAILABLE );
1250 return NULL;
1252 server = LIST_ENTRY( list_head( &pipe->listeners ), struct pipe_server, entry );
1254 pipe_sharing = pipe->sharing;
1255 if (((access & GENERIC_READ) && !(pipe_sharing & FILE_SHARE_READ)) ||
1256 ((access & GENERIC_WRITE) && !(pipe_sharing & FILE_SHARE_WRITE)))
1258 set_error( STATUS_ACCESS_DENIED );
1259 return NULL;
1262 if ((client = create_pipe_client( pipe, pipe->outsize, options )))
1264 async_wake_up( &server->listen_q, STATUS_SUCCESS );
1265 server->pipe_end.state = FILE_PIPE_CONNECTED_STATE;
1266 server->pipe_end.connection = client;
1267 client->connection = &server->pipe_end;
1268 server->pipe_end.client_pid = client->client_pid;
1269 client->server_pid = server->pipe_end.server_pid;
1270 list_remove( &server->entry );
1272 return &client->obj;
1275 static int named_pipe_device_ioctl( struct fd *fd, ioctl_code_t code, struct async *async )
1277 struct named_pipe_device *device = get_fd_user( fd );
1279 switch(code)
1281 case FSCTL_PIPE_WAIT:
1283 const FILE_PIPE_WAIT_FOR_BUFFER *buffer = get_req_data();
1284 data_size_t size = get_req_data_size();
1285 struct named_pipe *pipe;
1286 struct unicode_str name;
1287 timeout_t when;
1289 if (size < sizeof(*buffer) ||
1290 size < FIELD_OFFSET(FILE_PIPE_WAIT_FOR_BUFFER, Name[buffer->NameLength/sizeof(WCHAR)]))
1292 set_error( STATUS_INVALID_PARAMETER );
1293 return 0;
1295 name.str = buffer->Name;
1296 name.len = (buffer->NameLength / sizeof(WCHAR)) * sizeof(WCHAR);
1297 if (!(pipe = open_named_object( &device->obj, &named_pipe_ops, &name, 0 ))) return 0;
1299 if (list_empty( &pipe->listeners ))
1301 queue_async( &pipe->waiters, async );
1302 when = buffer->TimeoutSpecified ? buffer->Timeout.QuadPart : pipe->timeout;
1303 async_set_timeout( async, when, STATUS_IO_TIMEOUT );
1304 set_error( STATUS_PENDING );
1307 release_object( pipe );
1308 return 1;
1311 default:
1312 return default_fd_ioctl( fd, code, async );
1317 DECL_HANDLER(create_named_pipe)
1319 struct named_pipe *pipe;
1320 struct pipe_server *server;
1321 struct unicode_str name;
1322 struct object *root;
1323 const struct security_descriptor *sd;
1324 const struct object_attributes *objattr = get_req_object_attributes( &sd, &name, &root );
1326 if (!objattr) return;
1328 if (!req->sharing || (req->sharing & ~(FILE_SHARE_READ | FILE_SHARE_WRITE)) ||
1329 (!(req->flags & NAMED_PIPE_MESSAGE_STREAM_WRITE) && (req->flags & NAMED_PIPE_MESSAGE_STREAM_READ)))
1331 if (root) release_object( root );
1332 set_error( STATUS_INVALID_PARAMETER );
1333 return;
1336 if (!name.len) /* pipes need a root directory even without a name */
1338 if (!objattr->rootdir)
1340 set_error( STATUS_OBJECT_PATH_SYNTAX_BAD );
1341 return;
1343 if (!(root = get_directory_obj( current->process, objattr->rootdir ))) return;
1346 pipe = create_named_object( root, &named_pipe_ops, &name, objattr->attributes | OBJ_OPENIF, NULL );
1348 if (root) release_object( root );
1349 if (!pipe) return;
1351 if (get_error() != STATUS_OBJECT_NAME_EXISTS)
1353 /* initialize it if it didn't already exist */
1354 pipe->instances = 0;
1355 init_async_queue( &pipe->waiters );
1356 list_init( &pipe->listeners );
1357 pipe->insize = req->insize;
1358 pipe->outsize = req->outsize;
1359 pipe->maxinstances = req->maxinstances;
1360 pipe->timeout = req->timeout;
1361 pipe->message_mode = (req->flags & NAMED_PIPE_MESSAGE_STREAM_WRITE) != 0;
1362 pipe->sharing = req->sharing;
1363 if (sd) default_set_sd( &pipe->obj, sd, OWNER_SECURITY_INFORMATION |
1364 GROUP_SECURITY_INFORMATION |
1365 DACL_SECURITY_INFORMATION |
1366 SACL_SECURITY_INFORMATION );
1368 else
1370 if (pipe->maxinstances <= pipe->instances)
1372 set_error( STATUS_INSTANCE_NOT_AVAILABLE );
1373 release_object( pipe );
1374 return;
1376 if (pipe->sharing != req->sharing)
1378 set_error( STATUS_ACCESS_DENIED );
1379 release_object( pipe );
1380 return;
1382 clear_error(); /* clear the name collision */
1385 server = create_pipe_server( pipe, req->options, req->flags );
1386 if (server)
1388 reply->handle = alloc_handle( current->process, server, req->access, objattr->attributes );
1389 pipe->instances++;
1390 release_object( server );
1393 release_object( pipe );
1396 DECL_HANDLER(set_named_pipe_info)
1398 struct pipe_end *pipe_end;
1400 pipe_end = (struct pipe_end *)get_handle_obj( current->process, req->handle,
1401 FILE_WRITE_ATTRIBUTES, &pipe_server_ops );
1402 if (!pipe_end)
1404 if (get_error() != STATUS_OBJECT_TYPE_MISMATCH)
1405 return;
1407 clear_error();
1408 pipe_end = (struct pipe_end *)get_handle_obj( current->process, req->handle,
1409 0, &pipe_client_ops );
1410 if (!pipe_end) return;
1413 if (!pipe_end->pipe)
1415 set_error( STATUS_PIPE_DISCONNECTED );
1417 else if ((req->flags & ~(NAMED_PIPE_MESSAGE_STREAM_READ | NAMED_PIPE_NONBLOCKING_MODE)) ||
1418 ((req->flags & NAMED_PIPE_MESSAGE_STREAM_READ) && !pipe_end->pipe->message_mode))
1420 set_error( STATUS_INVALID_PARAMETER );
1422 else
1424 pipe_end->flags = req->flags;
1427 release_object( pipe_end );