xinput: Avoid calling XInputGetStateEx() in XInputGetState().
[wine.git] / server / named_pipe.c
blob19a5426b1ff1541d305d8376cafaedec5c5edefb
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 pipe_client and pipe_server */
74 struct list entry; /* entry in named pipe servers list */
75 unsigned int options; /* pipe options */
76 struct async_queue listen_q; /* listen queue */
79 struct pipe_client
81 struct pipe_end pipe_end; /* common header for pipe_client and pipe_server */
82 unsigned int flags; /* file flags */
85 struct named_pipe
87 struct object obj; /* object header */
88 unsigned int flags;
89 unsigned int sharing;
90 unsigned int maxinstances;
91 unsigned int outsize;
92 unsigned int insize;
93 unsigned int instances;
94 timeout_t timeout;
95 struct list servers; /* list of servers using this pipe */
96 struct async_queue waiters; /* list of clients waiting to connect */
99 struct named_pipe_device
101 struct object obj; /* object header */
102 struct namespace *pipes; /* named pipe namespace */
105 struct named_pipe_device_file
107 struct object obj; /* object header */
108 struct fd *fd; /* pseudo-fd for ioctls */
109 struct named_pipe_device *device; /* named pipe device */
112 static void named_pipe_dump( struct object *obj, int verbose );
113 static unsigned int named_pipe_map_access( struct object *obj, unsigned int access );
114 static int named_pipe_link_name( struct object *obj, struct object_name *name, struct object *parent );
115 static struct object *named_pipe_open_file( struct object *obj, unsigned int access,
116 unsigned int sharing, unsigned int options );
117 static void named_pipe_destroy( struct object *obj );
119 static const struct object_ops named_pipe_ops =
121 sizeof(struct named_pipe), /* size */
122 named_pipe_dump, /* dump */
123 no_get_type, /* get_type */
124 no_add_queue, /* add_queue */
125 NULL, /* remove_queue */
126 NULL, /* signaled */
127 NULL, /* satisfied */
128 no_signal, /* signal */
129 no_get_fd, /* get_fd */
130 named_pipe_map_access, /* map_access */
131 default_get_sd, /* get_sd */
132 default_set_sd, /* set_sd */
133 no_lookup_name, /* lookup_name */
134 named_pipe_link_name, /* link_name */
135 default_unlink_name, /* unlink_name */
136 named_pipe_open_file, /* open_file */
137 no_close_handle, /* close_handle */
138 named_pipe_destroy /* destroy */
141 /* common server and client pipe end functions */
142 static void pipe_end_destroy( struct object *obj );
143 static struct object_type *pipe_end_get_type( struct object *obj );
144 static enum server_fd_type pipe_end_get_fd_type( struct fd *fd );
145 static struct fd *pipe_end_get_fd( struct object *obj );
146 static struct security_descriptor *pipe_end_get_sd( struct object *obj );
147 static int pipe_end_set_sd( struct object *obj, const struct security_descriptor *sd,
148 unsigned int set_info );
149 static int pipe_end_read( struct fd *fd, struct async *async, file_pos_t pos );
150 static int pipe_end_write( struct fd *fd, struct async *async_data, file_pos_t pos );
151 static int pipe_end_flush( struct fd *fd, struct async *async );
152 static void pipe_end_get_volume_info( struct fd *fd, unsigned int info_class );
153 static void pipe_end_reselect_async( struct fd *fd, struct async_queue *queue );
154 static void pipe_end_get_file_info( struct fd *fd, obj_handle_t handle, unsigned int info_class );
156 /* server end functions */
157 static void pipe_server_dump( struct object *obj, int verbose );
158 static void pipe_server_destroy( struct object *obj);
159 static int pipe_server_ioctl( struct fd *fd, ioctl_code_t code, struct async *async );
161 static const struct object_ops pipe_server_ops =
163 sizeof(struct pipe_server), /* size */
164 pipe_server_dump, /* dump */
165 pipe_end_get_type, /* get_type */
166 add_queue, /* add_queue */
167 remove_queue, /* remove_queue */
168 default_fd_signaled, /* signaled */
169 no_satisfied, /* satisfied */
170 no_signal, /* signal */
171 pipe_end_get_fd, /* get_fd */
172 default_fd_map_access, /* map_access */
173 pipe_end_get_sd, /* get_sd */
174 pipe_end_set_sd, /* set_sd */
175 no_lookup_name, /* lookup_name */
176 no_link_name, /* link_name */
177 NULL, /* unlink_name */
178 no_open_file, /* open_file */
179 fd_close_handle, /* close_handle */
180 pipe_server_destroy /* destroy */
183 static const struct fd_ops pipe_server_fd_ops =
185 default_fd_get_poll_events, /* get_poll_events */
186 default_poll_event, /* poll_event */
187 pipe_end_get_fd_type, /* get_fd_type */
188 pipe_end_read, /* read */
189 pipe_end_write, /* write */
190 pipe_end_flush, /* flush */
191 pipe_end_get_file_info, /* get_file_info */
192 pipe_end_get_volume_info, /* get_volume_info */
193 pipe_server_ioctl, /* ioctl */
194 no_fd_queue_async, /* queue_async */
195 pipe_end_reselect_async /* reselect_async */
198 /* client end functions */
199 static void pipe_client_dump( struct object *obj, int verbose );
200 static int pipe_client_ioctl( struct fd *fd, ioctl_code_t code, struct async *async );
202 static const struct object_ops pipe_client_ops =
204 sizeof(struct pipe_client), /* size */
205 pipe_client_dump, /* dump */
206 pipe_end_get_type, /* get_type */
207 add_queue, /* add_queue */
208 remove_queue, /* remove_queue */
209 default_fd_signaled, /* signaled */
210 no_satisfied, /* satisfied */
211 no_signal, /* signal */
212 pipe_end_get_fd, /* get_fd */
213 default_fd_map_access, /* map_access */
214 pipe_end_get_sd, /* get_sd */
215 pipe_end_set_sd, /* set_sd */
216 no_lookup_name, /* lookup_name */
217 no_link_name, /* link_name */
218 NULL, /* unlink_name */
219 no_open_file, /* open_file */
220 fd_close_handle, /* close_handle */
221 pipe_end_destroy /* destroy */
224 static const struct fd_ops pipe_client_fd_ops =
226 default_fd_get_poll_events, /* get_poll_events */
227 default_poll_event, /* poll_event */
228 pipe_end_get_fd_type, /* get_fd_type */
229 pipe_end_read, /* read */
230 pipe_end_write, /* write */
231 pipe_end_flush, /* flush */
232 pipe_end_get_file_info, /* get_file_info */
233 pipe_end_get_volume_info, /* get_volume_info */
234 pipe_client_ioctl, /* ioctl */
235 no_fd_queue_async, /* queue_async */
236 pipe_end_reselect_async /* reselect_async */
239 static void named_pipe_device_dump( struct object *obj, int verbose );
240 static struct object_type *named_pipe_device_get_type( struct object *obj );
241 static struct object *named_pipe_device_lookup_name( struct object *obj,
242 struct unicode_str *name, unsigned int attr );
243 static struct object *named_pipe_device_open_file( struct object *obj, unsigned int access,
244 unsigned int sharing, unsigned int options );
245 static void named_pipe_device_destroy( struct object *obj );
247 static const struct object_ops named_pipe_device_ops =
249 sizeof(struct named_pipe_device), /* size */
250 named_pipe_device_dump, /* dump */
251 named_pipe_device_get_type, /* get_type */
252 no_add_queue, /* add_queue */
253 NULL, /* remove_queue */
254 NULL, /* signaled */
255 no_satisfied, /* satisfied */
256 no_signal, /* signal */
257 no_get_fd, /* get_fd */
258 no_map_access, /* map_access */
259 default_get_sd, /* get_sd */
260 default_set_sd, /* set_sd */
261 named_pipe_device_lookup_name, /* lookup_name */
262 directory_link_name, /* link_name */
263 default_unlink_name, /* unlink_name */
264 named_pipe_device_open_file, /* open_file */
265 no_close_handle, /* close_handle */
266 named_pipe_device_destroy /* destroy */
269 static void named_pipe_device_file_dump( struct object *obj, int verbose );
270 static struct fd *named_pipe_device_file_get_fd( struct object *obj );
271 static int named_pipe_device_ioctl( struct fd *fd, ioctl_code_t code, struct async *async );
272 static enum server_fd_type named_pipe_device_file_get_fd_type( struct fd *fd );
273 static void named_pipe_device_file_destroy( struct object *obj );
275 static const struct object_ops named_pipe_device_file_ops =
277 sizeof(struct named_pipe_device_file), /* size */
278 named_pipe_device_file_dump, /* dump */
279 no_get_type, /* get_type */
280 add_queue, /* add_queue */
281 remove_queue, /* remove_queue */
282 default_fd_signaled, /* signaled */
283 no_satisfied, /* satisfied */
284 no_signal, /* signal */
285 named_pipe_device_file_get_fd, /* get_fd */
286 default_fd_map_access, /* map_access */
287 default_get_sd, /* get_sd */
288 default_set_sd, /* set_sd */
289 no_lookup_name, /* lookup_name */
290 no_link_name, /* link_name */
291 NULL, /* unlink_name */
292 no_open_file, /* open_file */
293 fd_close_handle, /* close_handle */
294 named_pipe_device_file_destroy /* destroy */
297 static const struct fd_ops named_pipe_device_fd_ops =
299 default_fd_get_poll_events, /* get_poll_events */
300 default_poll_event, /* poll_event */
301 named_pipe_device_file_get_fd_type, /* get_fd_type */
302 no_fd_read, /* read */
303 no_fd_write, /* write */
304 no_fd_flush, /* flush */
305 default_fd_get_file_info, /* get_file_info */
306 no_fd_get_volume_info, /* get_volume_info */
307 named_pipe_device_ioctl, /* ioctl */
308 default_fd_queue_async, /* queue_async */
309 default_fd_reselect_async /* reselect_async */
312 static void named_pipe_dump( struct object *obj, int verbose )
314 fputs( "Named pipe\n", stderr );
317 static unsigned int named_pipe_map_access( struct object *obj, unsigned int access )
319 if (access & GENERIC_READ) access |= STANDARD_RIGHTS_READ;
320 if (access & GENERIC_WRITE) access |= STANDARD_RIGHTS_WRITE | FILE_CREATE_PIPE_INSTANCE;
321 if (access & GENERIC_EXECUTE) access |= STANDARD_RIGHTS_EXECUTE;
322 if (access & GENERIC_ALL) access |= STANDARD_RIGHTS_ALL;
323 return access & ~(GENERIC_READ | GENERIC_WRITE | GENERIC_EXECUTE | GENERIC_ALL);
326 static void pipe_server_dump( struct object *obj, int verbose )
328 struct pipe_server *server = (struct pipe_server *) obj;
329 assert( obj->ops == &pipe_server_ops );
330 fprintf( stderr, "Named pipe server pipe=%p state=%d\n", server->pipe_end.pipe,
331 server->pipe_end.state );
334 static void pipe_client_dump( struct object *obj, int verbose )
336 struct pipe_client *client = (struct pipe_client *) obj;
337 assert( obj->ops == &pipe_client_ops );
338 fprintf( stderr, "Named pipe client server=%p\n", client->pipe_end.connection );
341 static void named_pipe_destroy( struct object *obj)
343 struct named_pipe *pipe = (struct named_pipe *) obj;
345 assert( list_empty( &pipe->servers ) );
346 assert( !pipe->instances );
347 free_async_queue( &pipe->waiters );
350 static struct object_type *pipe_end_get_type( struct object *obj )
352 static const WCHAR name[] = {'F','i','l','e'};
353 static const struct unicode_str str = { name, sizeof(name) };
354 return get_object_type( &str );
357 static struct fd *pipe_end_get_fd( struct object *obj )
359 struct pipe_end *pipe_end = (struct pipe_end *) obj;
360 return (struct fd *) grab_object( pipe_end->fd );
363 static struct pipe_message *queue_message( struct pipe_end *pipe_end, struct iosb *iosb )
365 struct pipe_message *message;
367 if (!(message = mem_alloc( sizeof(*message) ))) return NULL;
368 message->iosb = (struct iosb *)grab_object( iosb );
369 message->async = NULL;
370 message->read_pos = 0;
371 list_add_tail( &pipe_end->message_queue, &message->entry );
372 return message;
375 static void wake_message( struct pipe_message *message )
377 struct async *async = message->async;
379 message->async = NULL;
380 if (!async) return;
382 message->iosb->status = STATUS_SUCCESS;
383 message->iosb->result = message->iosb->in_size;
384 async_terminate( async, message->iosb->result ? STATUS_ALERTED : STATUS_SUCCESS );
385 release_object( async );
388 static void free_message( struct pipe_message *message )
390 list_remove( &message->entry );
391 if (message->iosb) release_object( message->iosb );
392 free( message );
395 static void pipe_end_disconnect( struct pipe_end *pipe_end, unsigned int status )
397 struct pipe_end *connection = pipe_end->connection;
398 struct pipe_message *message, *next;
399 struct async *async;
401 pipe_end->connection = NULL;
403 pipe_end->state = status == STATUS_PIPE_DISCONNECTED
404 ? FILE_PIPE_DISCONNECTED_STATE : FILE_PIPE_CLOSING_STATE;
405 fd_async_wake_up( pipe_end->fd, ASYNC_TYPE_WAIT, status );
406 async_wake_up( &pipe_end->read_q, status );
407 LIST_FOR_EACH_ENTRY_SAFE( message, next, &pipe_end->message_queue, struct pipe_message, entry )
409 async = message->async;
410 if (async || status == STATUS_PIPE_DISCONNECTED) free_message( message );
411 if (!async) continue;
412 async_terminate( async, status );
413 release_object( async );
415 if (status == STATUS_PIPE_DISCONNECTED) set_fd_signaled( pipe_end->fd, 0 );
417 if (connection)
419 connection->connection = NULL;
420 pipe_end_disconnect( connection, status );
424 static void pipe_end_destroy( struct object *obj )
426 struct pipe_end *pipe_end = (struct pipe_end *)obj;
427 struct pipe_message *message;
429 pipe_end_disconnect( pipe_end, STATUS_PIPE_BROKEN );
431 while (!list_empty( &pipe_end->message_queue ))
433 message = LIST_ENTRY( list_head(&pipe_end->message_queue), struct pipe_message, entry );
434 assert( !message->async );
435 free_message( message );
438 free_async_queue( &pipe_end->read_q );
439 free_async_queue( &pipe_end->write_q );
440 if (pipe_end->fd) release_object( pipe_end->fd );
441 if (pipe_end->pipe) release_object( pipe_end->pipe );
444 static void pipe_server_destroy( struct object *obj )
446 struct pipe_server *server = (struct pipe_server *)obj;
447 struct named_pipe *pipe = server->pipe_end.pipe;
449 assert( obj->ops == &pipe_server_ops );
451 assert( pipe->instances );
452 if (!--pipe->instances) unlink_named_object( &pipe->obj );
453 list_remove( &server->entry );
455 free_async_queue( &server->listen_q );
456 pipe_end_destroy( obj );
459 static void named_pipe_device_dump( struct object *obj, int verbose )
461 fputs( "Named pipe device\n", stderr );
464 static struct object_type *named_pipe_device_get_type( struct object *obj )
466 static const WCHAR name[] = {'D','e','v','i','c','e'};
467 static const struct unicode_str str = { name, sizeof(name) };
468 return get_object_type( &str );
471 static struct object *named_pipe_device_lookup_name( struct object *obj, struct unicode_str *name,
472 unsigned int attr )
474 struct named_pipe_device *device = (struct named_pipe_device*)obj;
475 struct object *found;
477 assert( obj->ops == &named_pipe_device_ops );
478 assert( device->pipes );
480 if (!name) return NULL; /* open the device itself */
482 if ((found = find_object( device->pipes, name, attr | OBJ_CASE_INSENSITIVE )))
483 name->len = 0;
485 return found;
488 static struct object *named_pipe_device_open_file( struct object *obj, unsigned int access,
489 unsigned int sharing, unsigned int options )
491 struct named_pipe_device_file *file;
493 if (!(file = alloc_object( &named_pipe_device_file_ops ))) return NULL;
494 file->device = (struct named_pipe_device *)grab_object( obj );
495 if (!(file->fd = alloc_pseudo_fd( &named_pipe_device_fd_ops, obj, options )))
497 release_object( file );
498 return NULL;
500 allow_fd_caching( file->fd );
501 return &file->obj;
504 static void named_pipe_device_destroy( struct object *obj )
506 struct named_pipe_device *device = (struct named_pipe_device*)obj;
507 assert( obj->ops == &named_pipe_device_ops );
508 free( device->pipes );
511 struct object *create_named_pipe_device( struct object *root, const struct unicode_str *name )
513 struct named_pipe_device *dev;
515 if ((dev = create_named_object( root, &named_pipe_device_ops, name, 0, NULL )) &&
516 get_error() != STATUS_OBJECT_NAME_EXISTS)
518 dev->pipes = NULL;
519 if (!(dev->pipes = create_namespace( 7 )))
521 release_object( dev );
522 dev = NULL;
525 return &dev->obj;
528 static void named_pipe_device_file_dump( struct object *obj, int verbose )
530 struct named_pipe_device_file *file = (struct named_pipe_device_file *)obj;
532 fprintf( stderr, "File on named pipe device %p\n", file->device );
535 static struct fd *named_pipe_device_file_get_fd( struct object *obj )
537 struct named_pipe_device_file *file = (struct named_pipe_device_file *)obj;
538 return (struct fd *)grab_object( file->fd );
541 static enum server_fd_type named_pipe_device_file_get_fd_type( struct fd *fd )
543 return FD_TYPE_DEVICE;
546 static void named_pipe_device_file_destroy( struct object *obj )
548 struct named_pipe_device_file *file = (struct named_pipe_device_file*)obj;
549 assert( obj->ops == &named_pipe_device_file_ops );
550 if (file->fd) release_object( file->fd );
551 release_object( file->device );
554 static int pipe_end_flush( struct fd *fd, struct async *async )
556 struct pipe_end *pipe_end = get_fd_user( fd );
558 if (!pipe_end->pipe)
560 set_error( STATUS_PIPE_DISCONNECTED );
561 return 0;
564 if (pipe_end->connection && !list_empty( &pipe_end->connection->message_queue ))
566 fd_queue_async( pipe_end->fd, async, ASYNC_TYPE_WAIT );
567 set_error( STATUS_PENDING );
569 return 1;
572 static void pipe_end_get_file_info( struct fd *fd, obj_handle_t handle, unsigned int info_class )
574 struct pipe_end *pipe_end = get_fd_user( fd );
575 struct named_pipe *pipe = pipe_end->pipe;
577 switch (info_class)
579 case FileNameInformation:
581 FILE_NAME_INFORMATION *name_info;
582 data_size_t name_len, reply_size;
583 const WCHAR *name;
585 if (get_reply_max_size() < sizeof(*name_info))
587 set_error( STATUS_INFO_LENGTH_MISMATCH );
588 return;
591 /* FIXME: We should be able to return on unlinked pipe */
592 if (!pipe || !(name = get_object_name( &pipe->obj, &name_len )))
594 set_error( STATUS_PIPE_DISCONNECTED );
595 return;
598 reply_size = offsetof( FILE_NAME_INFORMATION, FileName[name_len/sizeof(WCHAR) + 1] );
599 if (reply_size > get_reply_max_size())
601 reply_size = get_reply_max_size();
602 set_error( STATUS_BUFFER_OVERFLOW );
605 if (!(name_info = set_reply_data_size( reply_size ))) return;
606 name_info->FileNameLength = name_len + sizeof(WCHAR);
607 name_info->FileName[0] = '\\';
608 reply_size -= offsetof( FILE_NAME_INFORMATION, FileName[1] );
609 if (reply_size) memcpy( &name_info->FileName[1], name, reply_size );
610 break;
612 case FilePipeInformation:
614 FILE_PIPE_INFORMATION *pipe_info;
616 if (!(get_handle_access( current->process, handle) & FILE_READ_ATTRIBUTES))
618 set_error( STATUS_ACCESS_DENIED );
619 return;
622 if (get_reply_max_size() < sizeof(*pipe_info))
624 set_error( STATUS_INFO_LENGTH_MISMATCH );
625 return;
628 if (!pipe)
630 set_error( STATUS_PIPE_DISCONNECTED );
631 return;
634 if (!(pipe_info = set_reply_data_size( sizeof(*pipe_info) ))) return;
635 pipe_info->ReadMode = (pipe_end->flags & NAMED_PIPE_MESSAGE_STREAM_READ)
636 ? FILE_PIPE_MESSAGE_MODE : FILE_PIPE_BYTE_STREAM_MODE;
637 pipe_info->CompletionMode = (pipe_end->flags & NAMED_PIPE_NONBLOCKING_MODE)
638 ? FILE_PIPE_COMPLETE_OPERATION : FILE_PIPE_QUEUE_OPERATION;
639 break;
641 case FilePipeLocalInformation:
643 FILE_PIPE_LOCAL_INFORMATION *pipe_info;
645 if (!(get_handle_access( current->process, handle) & FILE_READ_ATTRIBUTES))
647 set_error( STATUS_ACCESS_DENIED );
648 return;
651 if (get_reply_max_size() < sizeof(*pipe_info))
653 set_error( STATUS_INFO_LENGTH_MISMATCH );
654 return;
657 if (!pipe)
659 set_error( STATUS_PIPE_DISCONNECTED );
660 return;
663 if (!(pipe_info = set_reply_data_size( sizeof(*pipe_info) ))) return;
664 pipe_info->NamedPipeType = (pipe_end->flags & NAMED_PIPE_MESSAGE_STREAM_WRITE) != 0;
665 switch (pipe->sharing)
667 case FILE_SHARE_READ:
668 pipe_info->NamedPipeConfiguration = FILE_PIPE_OUTBOUND;
669 break;
670 case FILE_SHARE_WRITE:
671 pipe_info->NamedPipeConfiguration = FILE_PIPE_INBOUND;
672 break;
673 case FILE_SHARE_READ | FILE_SHARE_WRITE:
674 pipe_info->NamedPipeConfiguration = FILE_PIPE_FULL_DUPLEX;
675 break;
677 pipe_info->MaximumInstances = pipe->maxinstances;
678 pipe_info->CurrentInstances = pipe->instances;
679 pipe_info->InboundQuota = pipe->insize;
680 pipe_info->ReadDataAvailable = 0; /* FIXME */
681 pipe_info->OutboundQuota = pipe->outsize;
682 pipe_info->WriteQuotaAvailable = 0; /* FIXME */
683 pipe_info->NamedPipeState = pipe_end->state;
684 pipe_info->NamedPipeEnd = pipe_end->obj.ops == &pipe_server_ops
685 ? FILE_PIPE_SERVER_END : FILE_PIPE_CLIENT_END;
686 break;
688 default:
689 default_fd_get_file_info( fd, handle, info_class );
693 static struct security_descriptor *pipe_end_get_sd( struct object *obj )
695 struct pipe_end *pipe_end = (struct pipe_end *) obj;
696 if (pipe_end->pipe) return default_get_sd( &pipe_end->pipe->obj );
697 set_error( STATUS_PIPE_DISCONNECTED );
698 return NULL;
701 static int pipe_end_set_sd( struct object *obj, const struct security_descriptor *sd,
702 unsigned int set_info )
704 struct pipe_end *pipe_end = (struct pipe_end *) obj;
705 if (pipe_end->pipe) return default_set_sd( &pipe_end->pipe->obj, sd, set_info );
706 set_error( STATUS_PIPE_DISCONNECTED );
707 return 0;
710 static void pipe_end_get_volume_info( struct fd *fd, unsigned int info_class )
712 switch (info_class)
714 case FileFsDeviceInformation:
716 static const FILE_FS_DEVICE_INFORMATION device_info =
718 FILE_DEVICE_NAMED_PIPE,
719 FILE_DEVICE_ALLOW_APPCONTAINER_TRAVERSAL
721 if (get_reply_max_size() >= sizeof(device_info))
722 set_reply_data( &device_info, sizeof(device_info) );
723 else
724 set_error( STATUS_BUFFER_TOO_SMALL );
725 break;
727 default:
728 set_error( STATUS_NOT_IMPLEMENTED );
732 static void message_queue_read( struct pipe_end *pipe_end, struct iosb *iosb )
734 struct pipe_message *message;
736 if (pipe_end->flags & NAMED_PIPE_MESSAGE_STREAM_READ)
738 message = LIST_ENTRY( list_head(&pipe_end->message_queue), struct pipe_message, entry );
739 iosb->out_size = min( iosb->out_size, message->iosb->in_size - message->read_pos );
740 iosb->status = message->read_pos + iosb->out_size < message->iosb->in_size
741 ? STATUS_BUFFER_OVERFLOW : STATUS_SUCCESS;
743 else
745 data_size_t avail = 0;
746 LIST_FOR_EACH_ENTRY( message, &pipe_end->message_queue, struct pipe_message, entry )
748 avail += message->iosb->in_size - message->read_pos;
749 if (avail >= iosb->out_size) break;
751 iosb->out_size = min( iosb->out_size, avail );
752 iosb->status = STATUS_SUCCESS;
755 message = LIST_ENTRY( list_head(&pipe_end->message_queue), struct pipe_message, entry );
756 if (!message->read_pos && message->iosb->in_size == iosb->out_size) /* fast path */
758 iosb->out_data = message->iosb->in_data;
759 message->iosb->in_data = NULL;
760 wake_message( message );
761 free_message( message );
763 else
765 data_size_t write_pos = 0, writing;
766 char *buf = NULL;
768 if (iosb->out_size && !(buf = iosb->out_data = malloc( iosb->out_size )))
770 iosb->out_size = 0;
771 iosb->status = STATUS_NO_MEMORY;
772 return;
777 message = LIST_ENTRY( list_head(&pipe_end->message_queue), struct pipe_message, entry );
778 writing = min( iosb->out_size - write_pos, message->iosb->in_size - message->read_pos );
779 if (writing) memcpy( buf + write_pos, (const char *)message->iosb->in_data + message->read_pos, writing );
780 write_pos += writing;
781 message->read_pos += writing;
782 if (message->read_pos == message->iosb->in_size)
784 wake_message(message);
785 free_message(message);
787 } while (write_pos < iosb->out_size);
789 iosb->result = iosb->out_size;
792 /* We call async_terminate in our reselect implementation, which causes recursive reselect.
793 * We're not interested in such reselect calls, so we ignore them. */
794 static int ignore_reselect;
796 static void reselect_write_queue( struct pipe_end *pipe_end );
798 static void reselect_read_queue( struct pipe_end *pipe_end )
800 struct async *async;
801 struct iosb *iosb;
802 int read_done = 0;
804 ignore_reselect = 1;
805 while (!list_empty( &pipe_end->message_queue ) && (async = find_pending_async( &pipe_end->read_q )))
807 iosb = async_get_iosb( async );
808 message_queue_read( pipe_end, iosb );
809 async_terminate( async, iosb->result ? STATUS_ALERTED : iosb->status );
810 release_object( async );
811 release_object( iosb );
812 read_done = 1;
814 ignore_reselect = 0;
816 if (pipe_end->connection)
818 if (list_empty( &pipe_end->message_queue ))
819 fd_async_wake_up( pipe_end->connection->fd, ASYNC_TYPE_WAIT, STATUS_SUCCESS );
820 else if (read_done)
821 reselect_write_queue( pipe_end->connection );
825 static void reselect_write_queue( struct pipe_end *pipe_end )
827 struct pipe_message *message, *next;
828 struct pipe_end *reader = pipe_end->connection;
829 data_size_t avail = 0;
831 if (!reader) return;
833 ignore_reselect = 1;
835 LIST_FOR_EACH_ENTRY_SAFE( message, next, &reader->message_queue, struct pipe_message, entry )
837 if (message->async && message->iosb->status != STATUS_PENDING)
839 release_object( message->async );
840 message->async = NULL;
841 free_message( message );
843 else
845 avail += message->iosb->in_size - message->read_pos;
846 if (message->async && (avail <= reader->buffer_size || !message->iosb->in_size))
847 wake_message( message );
851 ignore_reselect = 0;
852 reselect_read_queue( reader );
855 static int pipe_end_read( struct fd *fd, struct async *async, file_pos_t pos )
857 struct pipe_end *pipe_end = get_fd_user( fd );
859 switch (pipe_end->state)
861 case FILE_PIPE_CONNECTED_STATE:
862 break;
863 case FILE_PIPE_DISCONNECTED_STATE:
864 set_error( STATUS_PIPE_DISCONNECTED );
865 return 0;
866 case FILE_PIPE_LISTENING_STATE:
867 set_error( STATUS_PIPE_LISTENING );
868 return 0;
869 case FILE_PIPE_CLOSING_STATE:
870 if (!list_empty( &pipe_end->message_queue )) break;
871 set_error( STATUS_PIPE_BROKEN );
872 return 0;
875 queue_async( &pipe_end->read_q, async );
876 reselect_read_queue( pipe_end );
877 set_error( STATUS_PENDING );
878 return 1;
881 static int pipe_end_write( struct fd *fd, struct async *async, file_pos_t pos )
883 struct pipe_end *pipe_end = get_fd_user( fd );
884 struct pipe_message *message;
885 struct iosb *iosb;
887 switch (pipe_end->state)
889 case FILE_PIPE_CONNECTED_STATE:
890 break;
891 case FILE_PIPE_DISCONNECTED_STATE:
892 set_error( STATUS_PIPE_DISCONNECTED );
893 return 0;
894 case FILE_PIPE_LISTENING_STATE:
895 set_error( STATUS_PIPE_LISTENING );
896 return 0;
897 case FILE_PIPE_CLOSING_STATE:
898 set_error( STATUS_PIPE_CLOSING );
899 return 0;
902 if (!(pipe_end->flags & NAMED_PIPE_MESSAGE_STREAM_WRITE) && !get_req_data_size()) return 1;
904 iosb = async_get_iosb( async );
905 message = queue_message( pipe_end->connection, iosb );
906 release_object( iosb );
907 if (!message) return 0;
909 message->async = (struct async *)grab_object( async );
910 queue_async( &pipe_end->write_q, async );
911 reselect_write_queue( pipe_end );
912 set_error( STATUS_PENDING );
913 return 1;
916 static void pipe_end_reselect_async( struct fd *fd, struct async_queue *queue )
918 struct pipe_end *pipe_end = get_fd_user( fd );
920 if (ignore_reselect) return;
922 if (&pipe_end->write_q == queue)
923 reselect_write_queue( pipe_end );
924 else if (&pipe_end->read_q == queue)
925 reselect_read_queue( pipe_end );
928 static enum server_fd_type pipe_end_get_fd_type( struct fd *fd )
930 return FD_TYPE_PIPE;
933 static int pipe_end_peek( struct pipe_end *pipe_end )
935 unsigned reply_size = get_reply_max_size();
936 FILE_PIPE_PEEK_BUFFER *buffer;
937 struct pipe_message *message;
938 data_size_t avail = 0;
939 data_size_t message_length = 0;
941 if (reply_size < offsetof( FILE_PIPE_PEEK_BUFFER, Data ))
943 set_error( STATUS_INFO_LENGTH_MISMATCH );
944 return 0;
946 reply_size -= offsetof( FILE_PIPE_PEEK_BUFFER, Data );
948 switch (pipe_end->state)
950 case FILE_PIPE_CONNECTED_STATE:
951 break;
952 case FILE_PIPE_CLOSING_STATE:
953 if (!list_empty( &pipe_end->message_queue )) break;
954 set_error( STATUS_PIPE_BROKEN );
955 return 0;
956 default:
957 set_error( pipe_end->pipe ? STATUS_INVALID_PIPE_STATE : STATUS_PIPE_DISCONNECTED );
958 return 0;
961 LIST_FOR_EACH_ENTRY( message, &pipe_end->message_queue, struct pipe_message, entry )
962 avail += message->iosb->in_size - message->read_pos;
963 reply_size = min( reply_size, avail );
965 if (avail && (pipe_end->flags & NAMED_PIPE_MESSAGE_STREAM_WRITE))
967 message = LIST_ENTRY( list_head(&pipe_end->message_queue), struct pipe_message, entry );
968 message_length = message->iosb->in_size - message->read_pos;
969 reply_size = min( reply_size, message_length );
972 if (!(buffer = set_reply_data_size( offsetof( FILE_PIPE_PEEK_BUFFER, Data[reply_size] )))) return 0;
973 buffer->NamedPipeState = pipe_end->state;
974 buffer->ReadDataAvailable = avail;
975 buffer->NumberOfMessages = 0; /* FIXME */
976 buffer->MessageLength = message_length;
978 if (reply_size)
980 data_size_t write_pos = 0, writing;
981 LIST_FOR_EACH_ENTRY( message, &pipe_end->message_queue, struct pipe_message, entry )
983 writing = min( reply_size - write_pos, message->iosb->in_size - message->read_pos );
984 memcpy( buffer->Data + write_pos, (const char *)message->iosb->in_data + message->read_pos,
985 writing );
986 write_pos += writing;
987 if (write_pos == reply_size) break;
990 if (message_length > reply_size) set_error( STATUS_BUFFER_OVERFLOW );
991 return 1;
994 static int pipe_end_transceive( struct pipe_end *pipe_end, struct async *async )
996 struct pipe_message *message;
997 struct iosb *iosb;
999 if (!pipe_end->connection)
1001 set_error( pipe_end->pipe ? STATUS_INVALID_PIPE_STATE : STATUS_PIPE_DISCONNECTED );
1002 return 0;
1005 if ((pipe_end->flags & (NAMED_PIPE_MESSAGE_STREAM_WRITE | NAMED_PIPE_MESSAGE_STREAM_READ))
1006 != (NAMED_PIPE_MESSAGE_STREAM_WRITE | NAMED_PIPE_MESSAGE_STREAM_READ))
1008 set_error( STATUS_INVALID_READ_MODE );
1009 return 0;
1012 /* not allowed if we already have read data buffered */
1013 if (!list_empty( &pipe_end->message_queue ))
1015 set_error( STATUS_PIPE_BUSY );
1016 return 0;
1019 iosb = async_get_iosb( async );
1020 /* ignore output buffer copy transferred because of METHOD_NEITHER */
1021 iosb->in_size -= iosb->out_size;
1022 /* transaction never blocks on write, so just queue a message without async */
1023 message = queue_message( pipe_end->connection, iosb );
1024 release_object( iosb );
1025 if (!message) return 0;
1026 reselect_read_queue( pipe_end->connection );
1028 queue_async( &pipe_end->read_q, async );
1029 reselect_read_queue( pipe_end );
1030 set_error( STATUS_PENDING );
1031 return 1;
1034 static int pipe_end_get_connection_attribute( struct pipe_end *pipe_end )
1036 const char *attr = get_req_data();
1037 data_size_t value_size, attr_size = get_req_data_size();
1038 void *value;
1040 if (attr_size == sizeof("ClientProcessId") && !memcmp( attr, "ClientProcessId", attr_size ))
1042 value = &pipe_end->client_pid;
1043 value_size = sizeof(pipe_end->client_pid);
1045 else if (attr_size == sizeof("ServerProcessId") && !memcmp( attr, "ServerProcessId", attr_size ))
1047 value = &pipe_end->server_pid;
1048 value_size = sizeof(pipe_end->server_pid);
1050 else
1052 set_error( STATUS_ILLEGAL_FUNCTION );
1053 return 0;
1056 if (get_reply_max_size() < value_size)
1058 set_error( STATUS_INFO_LENGTH_MISMATCH );
1059 return 0;
1062 set_reply_data( value, value_size );
1063 return 1;
1066 static int pipe_end_ioctl( struct pipe_end *pipe_end, ioctl_code_t code, struct async *async )
1068 switch(code)
1070 case FSCTL_PIPE_GET_CONNECTION_ATTRIBUTE:
1071 return pipe_end_get_connection_attribute( pipe_end );
1073 case FSCTL_PIPE_PEEK:
1074 return pipe_end_peek( pipe_end );
1076 case FSCTL_PIPE_TRANSCEIVE:
1077 return pipe_end_transceive( pipe_end, async );
1079 default:
1080 return default_fd_ioctl( pipe_end->fd, code, async );
1084 static int pipe_server_ioctl( struct fd *fd, ioctl_code_t code, struct async *async )
1086 struct pipe_server *server = get_fd_user( fd );
1088 switch(code)
1090 case FSCTL_PIPE_LISTEN:
1091 switch(server->pipe_end.state)
1093 case FILE_PIPE_LISTENING_STATE:
1094 case FILE_PIPE_DISCONNECTED_STATE:
1095 break;
1096 case FILE_PIPE_CONNECTED_STATE:
1097 set_error( STATUS_PIPE_CONNECTED );
1098 return 0;
1099 case FILE_PIPE_CLOSING_STATE:
1100 set_error( STATUS_PIPE_CLOSING );
1101 return 0;
1104 server->pipe_end.state = FILE_PIPE_LISTENING_STATE;
1105 queue_async( &server->listen_q, async );
1106 async_wake_up( &server->pipe_end.pipe->waiters, STATUS_SUCCESS );
1107 set_error( STATUS_PENDING );
1108 return 1;
1110 case FSCTL_PIPE_DISCONNECT:
1111 switch(server->pipe_end.state)
1113 case FILE_PIPE_CONNECTED_STATE:
1114 /* dump the client connection - all data is lost */
1115 assert( server->pipe_end.connection );
1116 release_object( server->pipe_end.connection->pipe );
1117 server->pipe_end.connection->pipe = NULL;
1118 break;
1119 case FILE_PIPE_CLOSING_STATE:
1120 break;
1121 case FILE_PIPE_LISTENING_STATE:
1122 set_error( STATUS_PIPE_LISTENING );
1123 return 0;
1124 case FILE_PIPE_DISCONNECTED_STATE:
1125 set_error( STATUS_PIPE_DISCONNECTED );
1126 return 0;
1129 pipe_end_disconnect( &server->pipe_end, STATUS_PIPE_DISCONNECTED );
1130 return 1;
1132 default:
1133 return pipe_end_ioctl( &server->pipe_end, code, async );
1137 static int pipe_client_ioctl( struct fd *fd, ioctl_code_t code, struct async *async )
1139 struct pipe_client *client = get_fd_user( fd );
1141 switch(code)
1143 case FSCTL_PIPE_LISTEN:
1144 set_error( STATUS_ILLEGAL_FUNCTION );
1145 return 0;
1147 default:
1148 return pipe_end_ioctl( &client->pipe_end, code, async );
1152 static void init_pipe_end( struct pipe_end *pipe_end, struct named_pipe *pipe,
1153 unsigned int pipe_flags, data_size_t buffer_size )
1155 pipe_end->pipe = (struct named_pipe *)grab_object( pipe );
1156 pipe_end->fd = NULL;
1157 pipe_end->flags = pipe_flags;
1158 pipe_end->connection = NULL;
1159 pipe_end->buffer_size = buffer_size;
1160 init_async_queue( &pipe_end->read_q );
1161 init_async_queue( &pipe_end->write_q );
1162 list_init( &pipe_end->message_queue );
1165 static struct pipe_server *create_pipe_server( struct named_pipe *pipe, unsigned int options,
1166 unsigned int pipe_flags )
1168 struct pipe_server *server;
1170 server = alloc_object( &pipe_server_ops );
1171 if (!server)
1172 return NULL;
1174 server->options = options;
1175 init_pipe_end( &server->pipe_end, pipe, pipe_flags, pipe->insize );
1176 server->pipe_end.state = FILE_PIPE_LISTENING_STATE;
1177 server->pipe_end.server_pid = get_process_id( current->process );
1179 list_add_head( &pipe->servers, &server->entry );
1180 if (!(server->pipe_end.fd = alloc_pseudo_fd( &pipe_server_fd_ops, &server->pipe_end.obj, options )))
1182 release_object( server );
1183 return NULL;
1185 allow_fd_caching( server->pipe_end.fd );
1186 set_fd_signaled( server->pipe_end.fd, 1 );
1187 init_async_queue( &server->listen_q );
1188 return server;
1191 static struct pipe_client *create_pipe_client( unsigned int flags, struct named_pipe *pipe,
1192 data_size_t buffer_size, unsigned int options )
1194 struct pipe_client *client;
1196 client = alloc_object( &pipe_client_ops );
1197 if (!client)
1198 return NULL;
1200 client->flags = flags;
1201 init_pipe_end( &client->pipe_end, pipe, pipe->flags, buffer_size );
1202 client->pipe_end.state = FILE_PIPE_CONNECTED_STATE;
1203 client->pipe_end.client_pid = get_process_id( current->process );
1205 client->pipe_end.fd = alloc_pseudo_fd( &pipe_client_fd_ops, &client->pipe_end.obj, options );
1206 if (!client->pipe_end.fd)
1208 release_object( client );
1209 return NULL;
1211 allow_fd_caching( client->pipe_end.fd );
1212 set_fd_signaled( client->pipe_end.fd, 1 );
1214 return client;
1217 static struct pipe_server *find_available_server( struct named_pipe *pipe )
1219 struct pipe_server *server;
1221 /* look for pipe servers that are listening */
1222 LIST_FOR_EACH_ENTRY( server, &pipe->servers, struct pipe_server, entry )
1224 if (server->pipe_end.state == FILE_PIPE_LISTENING_STATE && async_queued( &server->listen_q ))
1225 return (struct pipe_server *)grab_object( server );
1228 /* fall back to pipe servers that are idle */
1229 LIST_FOR_EACH_ENTRY( server, &pipe->servers, struct pipe_server, entry )
1231 if (server->pipe_end.state == FILE_PIPE_LISTENING_STATE )
1232 return (struct pipe_server *)grab_object( server );
1235 return NULL;
1238 static int named_pipe_link_name( struct object *obj, struct object_name *name, struct object *parent )
1240 struct named_pipe_device *dev = (struct named_pipe_device *)parent;
1242 if (parent->ops != &named_pipe_device_ops)
1244 set_error( STATUS_OBJECT_NAME_INVALID );
1245 return 0;
1247 namespace_add( dev->pipes, name );
1248 name->parent = grab_object( parent );
1249 return 1;
1252 static struct object *named_pipe_open_file( struct object *obj, unsigned int access,
1253 unsigned int sharing, unsigned int options )
1255 struct named_pipe *pipe = (struct named_pipe *)obj;
1256 struct pipe_server *server;
1257 struct pipe_client *client;
1258 unsigned int pipe_sharing;
1260 if (!(server = find_available_server( pipe )))
1262 set_error( STATUS_PIPE_NOT_AVAILABLE );
1263 return NULL;
1266 pipe_sharing = pipe->sharing;
1267 if (((access & GENERIC_READ) && !(pipe_sharing & FILE_SHARE_READ)) ||
1268 ((access & GENERIC_WRITE) && !(pipe_sharing & FILE_SHARE_WRITE)))
1270 set_error( STATUS_ACCESS_DENIED );
1271 release_object( server );
1272 return NULL;
1275 if ((client = create_pipe_client( options, pipe, pipe->outsize, options )))
1277 async_wake_up( &server->listen_q, STATUS_SUCCESS );
1278 server->pipe_end.state = FILE_PIPE_CONNECTED_STATE;
1279 server->pipe_end.connection = &client->pipe_end;
1280 client->pipe_end.connection = &server->pipe_end;
1281 server->pipe_end.client_pid = client->pipe_end.client_pid;
1282 client->pipe_end.server_pid = server->pipe_end.server_pid;
1284 release_object( server );
1285 return &client->pipe_end.obj;
1288 static int named_pipe_device_ioctl( struct fd *fd, ioctl_code_t code, struct async *async )
1290 struct named_pipe_device *device = get_fd_user( fd );
1292 switch(code)
1294 case FSCTL_PIPE_WAIT:
1296 const FILE_PIPE_WAIT_FOR_BUFFER *buffer = get_req_data();
1297 data_size_t size = get_req_data_size();
1298 struct named_pipe *pipe;
1299 struct pipe_server *server;
1300 struct unicode_str name;
1301 timeout_t when;
1303 if (size < sizeof(*buffer) ||
1304 size < FIELD_OFFSET(FILE_PIPE_WAIT_FOR_BUFFER, Name[buffer->NameLength/sizeof(WCHAR)]))
1306 set_error( STATUS_INVALID_PARAMETER );
1307 return 0;
1309 name.str = buffer->Name;
1310 name.len = (buffer->NameLength / sizeof(WCHAR)) * sizeof(WCHAR);
1311 if (!(pipe = open_named_object( &device->obj, &named_pipe_ops, &name, 0 ))) return 0;
1313 if (!(server = find_available_server( pipe )))
1315 queue_async( &pipe->waiters, async );
1316 when = buffer->TimeoutSpecified ? buffer->Timeout.QuadPart : pipe->timeout;
1317 async_set_timeout( async, when, STATUS_IO_TIMEOUT );
1318 release_object( pipe );
1319 set_error( STATUS_PENDING );
1320 return 1;
1323 release_object( server );
1324 release_object( pipe );
1325 return 0;
1328 default:
1329 return default_fd_ioctl( fd, code, async );
1334 DECL_HANDLER(create_named_pipe)
1336 struct named_pipe *pipe;
1337 struct pipe_server *server;
1338 struct unicode_str name;
1339 struct object *root;
1340 const struct security_descriptor *sd;
1341 const struct object_attributes *objattr = get_req_object_attributes( &sd, &name, &root );
1343 if (!objattr) return;
1345 if (!req->sharing || (req->sharing & ~(FILE_SHARE_READ | FILE_SHARE_WRITE)) ||
1346 (!(req->flags & NAMED_PIPE_MESSAGE_STREAM_WRITE) && (req->flags & NAMED_PIPE_MESSAGE_STREAM_READ)))
1348 if (root) release_object( root );
1349 set_error( STATUS_INVALID_PARAMETER );
1350 return;
1353 if (!name.len) /* pipes need a root directory even without a name */
1355 if (!objattr->rootdir)
1357 set_error( STATUS_OBJECT_PATH_SYNTAX_BAD );
1358 return;
1360 if (!(root = get_directory_obj( current->process, objattr->rootdir ))) return;
1363 pipe = create_named_object( root, &named_pipe_ops, &name, objattr->attributes | OBJ_OPENIF, NULL );
1365 if (root) release_object( root );
1366 if (!pipe) return;
1368 if (get_error() != STATUS_OBJECT_NAME_EXISTS)
1370 /* initialize it if it didn't already exist */
1371 pipe->instances = 0;
1372 init_async_queue( &pipe->waiters );
1373 list_init( &pipe->servers );
1374 pipe->insize = req->insize;
1375 pipe->outsize = req->outsize;
1376 pipe->maxinstances = req->maxinstances;
1377 pipe->timeout = req->timeout;
1378 pipe->flags = req->flags & NAMED_PIPE_MESSAGE_STREAM_WRITE;
1379 pipe->sharing = req->sharing;
1380 if (sd) default_set_sd( &pipe->obj, sd, OWNER_SECURITY_INFORMATION |
1381 GROUP_SECURITY_INFORMATION |
1382 DACL_SECURITY_INFORMATION |
1383 SACL_SECURITY_INFORMATION );
1385 else
1387 if (pipe->maxinstances <= pipe->instances)
1389 set_error( STATUS_INSTANCE_NOT_AVAILABLE );
1390 release_object( pipe );
1391 return;
1393 if (pipe->sharing != req->sharing)
1395 set_error( STATUS_ACCESS_DENIED );
1396 release_object( pipe );
1397 return;
1399 clear_error(); /* clear the name collision */
1402 server = create_pipe_server( pipe, req->options, req->flags );
1403 if (server)
1405 reply->handle = alloc_handle( current->process, server, req->access, objattr->attributes );
1406 pipe->instances++;
1407 release_object( server );
1410 release_object( pipe );
1413 DECL_HANDLER(set_named_pipe_info)
1415 struct pipe_end *pipe_end;
1417 pipe_end = (struct pipe_end *)get_handle_obj( current->process, req->handle,
1418 FILE_WRITE_ATTRIBUTES, &pipe_server_ops );
1419 if (!pipe_end)
1421 if (get_error() != STATUS_OBJECT_TYPE_MISMATCH)
1422 return;
1424 clear_error();
1425 pipe_end = (struct pipe_end *)get_handle_obj( current->process, req->handle,
1426 0, &pipe_client_ops );
1427 if (!pipe_end) return;
1430 if ((req->flags & ~(NAMED_PIPE_MESSAGE_STREAM_READ | NAMED_PIPE_NONBLOCKING_MODE)) ||
1431 ((req->flags & NAMED_PIPE_MESSAGE_STREAM_READ) && !(pipe_end->pipe->flags & NAMED_PIPE_MESSAGE_STREAM_WRITE)))
1433 set_error( STATUS_INVALID_PARAMETER );
1435 else
1437 pipe_end->flags = pipe_end->pipe->flags | req->flags;
1440 release_object( pipe_end );