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
24 #include "wine/port.h"
33 #define WIN32_NO_STATUS
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 */
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 */
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 */
81 struct object obj
; /* object header */
84 unsigned int maxinstances
;
87 unsigned int instances
;
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 */
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 default_get_full_name
, /* get_full_name */
128 no_lookup_name
, /* lookup_name */
129 named_pipe_link_name
, /* link_name */
130 default_unlink_name
, /* unlink_name */
131 named_pipe_open_file
, /* open_file */
132 no_kernel_obj_list
, /* get_kernel_obj_list */
133 no_close_handle
, /* close_handle */
134 named_pipe_destroy
/* destroy */
137 /* common server and client pipe end functions */
138 static void pipe_end_destroy( struct object
*obj
);
139 static enum server_fd_type
pipe_end_get_fd_type( struct fd
*fd
);
140 static struct fd
*pipe_end_get_fd( struct object
*obj
);
141 static struct security_descriptor
*pipe_end_get_sd( struct object
*obj
);
142 static int pipe_end_set_sd( struct object
*obj
, const struct security_descriptor
*sd
,
143 unsigned int set_info
);
144 static WCHAR
*pipe_end_get_full_name( struct object
*obj
, data_size_t
*len
);
145 static int pipe_end_read( struct fd
*fd
, struct async
*async
, file_pos_t pos
);
146 static int pipe_end_write( struct fd
*fd
, struct async
*async_data
, file_pos_t pos
);
147 static int pipe_end_flush( struct fd
*fd
, struct async
*async
);
148 static void pipe_end_get_volume_info( struct fd
*fd
, unsigned int info_class
);
149 static void pipe_end_reselect_async( struct fd
*fd
, struct async_queue
*queue
);
150 static void pipe_end_get_file_info( struct fd
*fd
, obj_handle_t handle
, unsigned int info_class
);
152 /* server end functions */
153 static void pipe_server_dump( struct object
*obj
, int verbose
);
154 static void pipe_server_destroy( struct object
*obj
);
155 static int pipe_server_ioctl( struct fd
*fd
, ioctl_code_t code
, struct async
*async
);
157 static const struct object_ops pipe_server_ops
=
159 sizeof(struct pipe_server
), /* size */
160 pipe_server_dump
, /* dump */
161 file_get_type
, /* get_type */
162 add_queue
, /* add_queue */
163 remove_queue
, /* remove_queue */
164 default_fd_signaled
, /* signaled */
165 no_satisfied
, /* satisfied */
166 no_signal
, /* signal */
167 pipe_end_get_fd
, /* get_fd */
168 default_fd_map_access
, /* map_access */
169 pipe_end_get_sd
, /* get_sd */
170 pipe_end_set_sd
, /* set_sd */
171 pipe_end_get_full_name
, /* get_full_name */
172 no_lookup_name
, /* lookup_name */
173 no_link_name
, /* link_name */
174 NULL
, /* unlink_name */
175 no_open_file
, /* open_file */
176 no_kernel_obj_list
, /* get_kernel_obj_list */
177 fd_close_handle
, /* close_handle */
178 pipe_server_destroy
/* destroy */
181 static const struct fd_ops pipe_server_fd_ops
=
183 default_fd_get_poll_events
, /* get_poll_events */
184 default_poll_event
, /* poll_event */
185 pipe_end_get_fd_type
, /* get_fd_type */
186 pipe_end_read
, /* read */
187 pipe_end_write
, /* write */
188 pipe_end_flush
, /* flush */
189 pipe_end_get_file_info
, /* get_file_info */
190 pipe_end_get_volume_info
, /* get_volume_info */
191 pipe_server_ioctl
, /* ioctl */
192 no_fd_queue_async
, /* queue_async */
193 pipe_end_reselect_async
/* reselect_async */
196 /* client end functions */
197 static void pipe_client_dump( struct object
*obj
, int verbose
);
198 static int pipe_client_ioctl( struct fd
*fd
, ioctl_code_t code
, struct async
*async
);
200 static const struct object_ops pipe_client_ops
=
202 sizeof(struct pipe_end
), /* size */
203 pipe_client_dump
, /* dump */
204 file_get_type
, /* get_type */
205 add_queue
, /* add_queue */
206 remove_queue
, /* remove_queue */
207 default_fd_signaled
, /* signaled */
208 no_satisfied
, /* satisfied */
209 no_signal
, /* signal */
210 pipe_end_get_fd
, /* get_fd */
211 default_fd_map_access
, /* map_access */
212 pipe_end_get_sd
, /* get_sd */
213 pipe_end_set_sd
, /* set_sd */
214 pipe_end_get_full_name
, /* get_full_name */
215 no_lookup_name
, /* lookup_name */
216 no_link_name
, /* link_name */
217 NULL
, /* unlink_name */
218 no_open_file
, /* open_file */
219 no_kernel_obj_list
, /* get_kernel_obj_list */
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
, struct object
*root
);
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 */
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 default_get_full_name
, /* get_full_name */
262 named_pipe_device_lookup_name
, /* lookup_name */
263 directory_link_name
, /* link_name */
264 default_unlink_name
, /* unlink_name */
265 named_pipe_device_open_file
, /* open_file */
266 no_kernel_obj_list
, /* get_kernel_obj_list */
267 no_close_handle
, /* close_handle */
268 named_pipe_device_destroy
/* destroy */
271 static void named_pipe_device_file_dump( struct object
*obj
, int verbose
);
272 static struct fd
*named_pipe_device_file_get_fd( struct object
*obj
);
273 static WCHAR
*named_pipe_device_file_get_full_name( struct object
*obj
, data_size_t
*len
);
274 static int named_pipe_device_ioctl( struct fd
*fd
, ioctl_code_t code
, struct async
*async
);
275 static enum server_fd_type
named_pipe_device_file_get_fd_type( struct fd
*fd
);
276 static void named_pipe_device_file_destroy( struct object
*obj
);
278 static const struct object_ops named_pipe_device_file_ops
=
280 sizeof(struct named_pipe_device_file
), /* size */
281 named_pipe_device_file_dump
, /* dump */
282 file_get_type
, /* get_type */
283 add_queue
, /* add_queue */
284 remove_queue
, /* remove_queue */
285 default_fd_signaled
, /* signaled */
286 no_satisfied
, /* satisfied */
287 no_signal
, /* signal */
288 named_pipe_device_file_get_fd
, /* get_fd */
289 default_fd_map_access
, /* map_access */
290 default_get_sd
, /* get_sd */
291 default_set_sd
, /* set_sd */
292 named_pipe_device_file_get_full_name
, /* get_full_name */
293 no_lookup_name
, /* lookup_name */
294 no_link_name
, /* link_name */
295 NULL
, /* unlink_name */
296 no_open_file
, /* open_file */
297 no_kernel_obj_list
, /* get_kernel_obj_list */
298 fd_close_handle
, /* close_handle */
299 named_pipe_device_file_destroy
/* destroy */
302 static const struct fd_ops named_pipe_device_fd_ops
=
304 default_fd_get_poll_events
, /* get_poll_events */
305 default_poll_event
, /* poll_event */
306 named_pipe_device_file_get_fd_type
, /* get_fd_type */
307 no_fd_read
, /* read */
308 no_fd_write
, /* write */
309 no_fd_flush
, /* flush */
310 default_fd_get_file_info
, /* get_file_info */
311 no_fd_get_volume_info
, /* get_volume_info */
312 named_pipe_device_ioctl
, /* ioctl */
313 default_fd_queue_async
, /* queue_async */
314 default_fd_reselect_async
/* reselect_async */
317 static void named_pipe_dump( struct object
*obj
, int verbose
)
319 fputs( "Named pipe\n", stderr
);
322 static unsigned int named_pipe_map_access( struct object
*obj
, unsigned int access
)
324 if (access
& GENERIC_READ
) access
|= STANDARD_RIGHTS_READ
;
325 if (access
& GENERIC_WRITE
) access
|= STANDARD_RIGHTS_WRITE
| FILE_CREATE_PIPE_INSTANCE
;
326 if (access
& GENERIC_EXECUTE
) access
|= STANDARD_RIGHTS_EXECUTE
;
327 if (access
& GENERIC_ALL
) access
|= STANDARD_RIGHTS_ALL
;
328 return access
& ~(GENERIC_READ
| GENERIC_WRITE
| GENERIC_EXECUTE
| GENERIC_ALL
);
331 static void pipe_server_dump( struct object
*obj
, int verbose
)
333 struct pipe_server
*server
= (struct pipe_server
*) obj
;
334 assert( obj
->ops
== &pipe_server_ops
);
335 fprintf( stderr
, "Named pipe server pipe=%p state=%d\n", server
->pipe_end
.pipe
,
336 server
->pipe_end
.state
);
339 static void pipe_client_dump( struct object
*obj
, int verbose
)
341 struct pipe_end
*client
= (struct pipe_end
*) obj
;
342 assert( obj
->ops
== &pipe_client_ops
);
343 fprintf( stderr
, "Named pipe client server=%p\n", client
->connection
);
346 static void named_pipe_destroy( struct object
*obj
)
348 struct named_pipe
*pipe
= (struct named_pipe
*) obj
;
350 assert( list_empty( &pipe
->listeners
) );
351 assert( !pipe
->instances
);
352 free_async_queue( &pipe
->waiters
);
355 static struct fd
*pipe_end_get_fd( struct object
*obj
)
357 struct pipe_end
*pipe_end
= (struct pipe_end
*) obj
;
358 return (struct fd
*) grab_object( pipe_end
->fd
);
361 static struct pipe_message
*queue_message( struct pipe_end
*pipe_end
, struct iosb
*iosb
)
363 struct pipe_message
*message
;
365 if (!(message
= mem_alloc( sizeof(*message
) ))) return NULL
;
366 message
->iosb
= (struct iosb
*)grab_object( iosb
);
367 message
->async
= NULL
;
368 message
->read_pos
= 0;
369 list_add_tail( &pipe_end
->message_queue
, &message
->entry
);
373 static void wake_message( struct pipe_message
*message
, data_size_t result
)
375 struct async
*async
= message
->async
;
377 message
->async
= NULL
;
380 message
->iosb
->status
= STATUS_SUCCESS
;
381 message
->iosb
->result
= result
;
382 async_terminate( async
, message
->iosb
->result
? STATUS_ALERTED
: STATUS_SUCCESS
);
383 release_object( async
);
386 static void free_message( struct pipe_message
*message
)
388 list_remove( &message
->entry
);
389 if (message
->iosb
) release_object( message
->iosb
);
393 static void pipe_end_disconnect( struct pipe_end
*pipe_end
, unsigned int status
)
395 struct pipe_end
*connection
= pipe_end
->connection
;
396 struct pipe_message
*message
, *next
;
399 pipe_end
->connection
= NULL
;
401 pipe_end
->state
= status
== STATUS_PIPE_DISCONNECTED
402 ? FILE_PIPE_DISCONNECTED_STATE
: FILE_PIPE_CLOSING_STATE
;
403 fd_async_wake_up( pipe_end
->fd
, ASYNC_TYPE_WAIT
, status
);
404 async_wake_up( &pipe_end
->read_q
, status
);
405 LIST_FOR_EACH_ENTRY_SAFE( message
, next
, &pipe_end
->message_queue
, struct pipe_message
, entry
)
407 async
= message
->async
;
408 if (async
|| status
== STATUS_PIPE_DISCONNECTED
) free_message( message
);
409 if (!async
) continue;
410 async_terminate( async
, status
);
411 release_object( async
);
413 if (status
== STATUS_PIPE_DISCONNECTED
) set_fd_signaled( pipe_end
->fd
, 0 );
417 connection
->connection
= NULL
;
418 pipe_end_disconnect( connection
, status
);
422 static void pipe_end_destroy( struct object
*obj
)
424 struct pipe_end
*pipe_end
= (struct pipe_end
*)obj
;
425 struct pipe_message
*message
;
427 pipe_end_disconnect( pipe_end
, STATUS_PIPE_BROKEN
);
429 while (!list_empty( &pipe_end
->message_queue
))
431 message
= LIST_ENTRY( list_head(&pipe_end
->message_queue
), struct pipe_message
, entry
);
432 assert( !message
->async
);
433 free_message( message
);
436 free_async_queue( &pipe_end
->read_q
);
437 free_async_queue( &pipe_end
->write_q
);
438 if (pipe_end
->fd
) release_object( pipe_end
->fd
);
439 if (pipe_end
->pipe
) release_object( pipe_end
->pipe
);
442 static void pipe_server_destroy( struct object
*obj
)
444 struct pipe_server
*server
= (struct pipe_server
*)obj
;
445 struct named_pipe
*pipe
= server
->pipe_end
.pipe
;
447 assert( obj
->ops
== &pipe_server_ops
);
449 assert( pipe
->instances
);
450 if (!--pipe
->instances
) unlink_named_object( &pipe
->obj
);
451 if (server
->pipe_end
.state
== FILE_PIPE_LISTENING_STATE
)
452 list_remove( &server
->entry
);
454 free_async_queue( &server
->listen_q
);
455 pipe_end_destroy( obj
);
458 static void named_pipe_device_dump( struct object
*obj
, int verbose
)
460 fputs( "Named pipe device\n", stderr
);
463 static struct object_type
*named_pipe_device_get_type( struct object
*obj
)
465 static const WCHAR name
[] = {'D','e','v','i','c','e'};
466 static const struct unicode_str str
= { name
, sizeof(name
) };
467 return get_object_type( &str
);
470 static struct object
*named_pipe_device_lookup_name( struct object
*obj
, struct unicode_str
*name
,
471 unsigned int attr
, struct object
*root
)
473 struct named_pipe_device
*device
= (struct named_pipe_device
*)obj
;
474 struct object
*found
;
476 assert( obj
->ops
== &named_pipe_device_ops
);
477 assert( device
->pipes
);
479 if (!name
) return NULL
; /* open the device itself */
481 if ((found
= find_object( device
->pipes
, name
, attr
| OBJ_CASE_INSENSITIVE
)))
487 static struct object
*named_pipe_device_open_file( struct object
*obj
, unsigned int access
,
488 unsigned int sharing
, unsigned int options
)
490 struct named_pipe_device_file
*file
;
492 if (!(file
= alloc_object( &named_pipe_device_file_ops
))) return NULL
;
493 file
->device
= (struct named_pipe_device
*)grab_object( obj
);
494 if (!(file
->fd
= alloc_pseudo_fd( &named_pipe_device_fd_ops
, obj
, options
)))
496 release_object( file
);
499 allow_fd_caching( file
->fd
);
503 static void named_pipe_device_destroy( struct object
*obj
)
505 struct named_pipe_device
*device
= (struct named_pipe_device
*)obj
;
506 assert( obj
->ops
== &named_pipe_device_ops
);
507 free( device
->pipes
);
510 struct object
*create_named_pipe_device( struct object
*root
, const struct unicode_str
*name
,
511 unsigned int attr
, const struct security_descriptor
*sd
)
513 struct named_pipe_device
*dev
;
515 if ((dev
= create_named_object( root
, &named_pipe_device_ops
, name
, attr
, sd
)) &&
516 get_error() != STATUS_OBJECT_NAME_EXISTS
)
519 if (!(dev
->pipes
= create_namespace( 7 )))
521 release_object( dev
);
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 WCHAR
*named_pipe_device_file_get_full_name( struct object
*obj
, data_size_t
*len
)
543 struct named_pipe_device_file
*file
= (struct named_pipe_device_file
*)obj
;
544 return file
->device
->obj
.ops
->get_full_name( &file
->device
->obj
, len
);
547 static enum server_fd_type
named_pipe_device_file_get_fd_type( struct fd
*fd
)
549 return FD_TYPE_DEVICE
;
552 static void named_pipe_device_file_destroy( struct object
*obj
)
554 struct named_pipe_device_file
*file
= (struct named_pipe_device_file
*)obj
;
555 assert( obj
->ops
== &named_pipe_device_file_ops
);
556 if (file
->fd
) release_object( file
->fd
);
557 release_object( file
->device
);
560 static int pipe_end_flush( struct fd
*fd
, struct async
*async
)
562 struct pipe_end
*pipe_end
= get_fd_user( fd
);
566 set_error( STATUS_PIPE_DISCONNECTED
);
570 if (pipe_end
->connection
&& !list_empty( &pipe_end
->connection
->message_queue
))
572 fd_queue_async( pipe_end
->fd
, async
, ASYNC_TYPE_WAIT
);
573 set_error( STATUS_PENDING
);
578 static void pipe_end_get_file_info( struct fd
*fd
, obj_handle_t handle
, unsigned int info_class
)
580 struct pipe_end
*pipe_end
= get_fd_user( fd
);
581 struct named_pipe
*pipe
= pipe_end
->pipe
;
585 case FileNameInformation
:
587 FILE_NAME_INFORMATION
*name_info
;
588 data_size_t name_len
, reply_size
;
591 if (get_reply_max_size() < sizeof(*name_info
))
593 set_error( STATUS_INFO_LENGTH_MISMATCH
);
597 /* FIXME: We should be able to return on unlinked pipe */
598 if (!pipe
|| !(name
= get_object_name( &pipe
->obj
, &name_len
)))
600 set_error( STATUS_PIPE_DISCONNECTED
);
604 reply_size
= offsetof( FILE_NAME_INFORMATION
, FileName
[name_len
/sizeof(WCHAR
) + 1] );
605 if (reply_size
> get_reply_max_size())
607 reply_size
= get_reply_max_size();
608 set_error( STATUS_BUFFER_OVERFLOW
);
611 if (!(name_info
= set_reply_data_size( reply_size
))) return;
612 name_info
->FileNameLength
= name_len
+ sizeof(WCHAR
);
613 name_info
->FileName
[0] = '\\';
614 reply_size
-= offsetof( FILE_NAME_INFORMATION
, FileName
[1] );
615 if (reply_size
) memcpy( &name_info
->FileName
[1], name
, reply_size
);
618 case FilePipeInformation
:
620 FILE_PIPE_INFORMATION
*pipe_info
;
622 if (!(get_handle_access( current
->process
, handle
) & FILE_READ_ATTRIBUTES
))
624 set_error( STATUS_ACCESS_DENIED
);
628 if (get_reply_max_size() < sizeof(*pipe_info
))
630 set_error( STATUS_INFO_LENGTH_MISMATCH
);
636 set_error( STATUS_PIPE_DISCONNECTED
);
640 if (!(pipe_info
= set_reply_data_size( sizeof(*pipe_info
) ))) return;
641 pipe_info
->ReadMode
= (pipe_end
->flags
& NAMED_PIPE_MESSAGE_STREAM_READ
)
642 ? FILE_PIPE_MESSAGE_MODE
: FILE_PIPE_BYTE_STREAM_MODE
;
643 pipe_info
->CompletionMode
= (pipe_end
->flags
& NAMED_PIPE_NONBLOCKING_MODE
)
644 ? FILE_PIPE_COMPLETE_OPERATION
: FILE_PIPE_QUEUE_OPERATION
;
647 case FilePipeLocalInformation
:
649 FILE_PIPE_LOCAL_INFORMATION
*pipe_info
;
651 if (!(get_handle_access( current
->process
, handle
) & FILE_READ_ATTRIBUTES
))
653 set_error( STATUS_ACCESS_DENIED
);
657 if (get_reply_max_size() < sizeof(*pipe_info
))
659 set_error( STATUS_INFO_LENGTH_MISMATCH
);
665 set_error( STATUS_PIPE_DISCONNECTED
);
669 if (!(pipe_info
= set_reply_data_size( sizeof(*pipe_info
) ))) return;
670 pipe_info
->NamedPipeType
= pipe
->message_mode
;
671 switch (pipe
->sharing
)
673 case FILE_SHARE_READ
:
674 pipe_info
->NamedPipeConfiguration
= FILE_PIPE_OUTBOUND
;
676 case FILE_SHARE_WRITE
:
677 pipe_info
->NamedPipeConfiguration
= FILE_PIPE_INBOUND
;
679 case FILE_SHARE_READ
| FILE_SHARE_WRITE
:
680 pipe_info
->NamedPipeConfiguration
= FILE_PIPE_FULL_DUPLEX
;
683 pipe_info
->MaximumInstances
= pipe
->maxinstances
;
684 pipe_info
->CurrentInstances
= pipe
->instances
;
685 pipe_info
->InboundQuota
= pipe
->insize
;
686 pipe_info
->ReadDataAvailable
= 0; /* FIXME */
687 pipe_info
->OutboundQuota
= pipe
->outsize
;
688 pipe_info
->WriteQuotaAvailable
= 0; /* FIXME */
689 pipe_info
->NamedPipeState
= pipe_end
->state
;
690 pipe_info
->NamedPipeEnd
= pipe_end
->obj
.ops
== &pipe_server_ops
691 ? FILE_PIPE_SERVER_END
: FILE_PIPE_CLIENT_END
;
695 default_fd_get_file_info( fd
, handle
, info_class
);
699 static struct security_descriptor
*pipe_end_get_sd( struct object
*obj
)
701 struct pipe_end
*pipe_end
= (struct pipe_end
*) obj
;
702 if (pipe_end
->pipe
) return default_get_sd( &pipe_end
->pipe
->obj
);
703 set_error( STATUS_PIPE_DISCONNECTED
);
707 static int pipe_end_set_sd( struct object
*obj
, const struct security_descriptor
*sd
,
708 unsigned int set_info
)
710 struct pipe_end
*pipe_end
= (struct pipe_end
*) obj
;
711 if (pipe_end
->pipe
) return default_set_sd( &pipe_end
->pipe
->obj
, sd
, set_info
);
712 set_error( STATUS_PIPE_DISCONNECTED
);
716 static WCHAR
*pipe_end_get_full_name( struct object
*obj
, data_size_t
*len
)
718 struct pipe_end
*pipe_end
= (struct pipe_end
*) obj
;
719 return pipe_end
->pipe
->obj
.ops
->get_full_name( &pipe_end
->pipe
->obj
, len
);
722 static void pipe_end_get_volume_info( struct fd
*fd
, unsigned int info_class
)
726 case FileFsDeviceInformation
:
728 static const FILE_FS_DEVICE_INFORMATION device_info
=
730 FILE_DEVICE_NAMED_PIPE
,
731 FILE_DEVICE_ALLOW_APPCONTAINER_TRAVERSAL
733 if (get_reply_max_size() >= sizeof(device_info
))
734 set_reply_data( &device_info
, sizeof(device_info
) );
736 set_error( STATUS_BUFFER_TOO_SMALL
);
740 set_error( STATUS_NOT_IMPLEMENTED
);
744 static void message_queue_read( struct pipe_end
*pipe_end
, struct iosb
*iosb
)
746 struct pipe_message
*message
;
748 if (pipe_end
->flags
& NAMED_PIPE_MESSAGE_STREAM_READ
)
750 message
= LIST_ENTRY( list_head(&pipe_end
->message_queue
), struct pipe_message
, entry
);
751 iosb
->out_size
= min( iosb
->out_size
, message
->iosb
->in_size
- message
->read_pos
);
752 iosb
->status
= message
->read_pos
+ iosb
->out_size
< message
->iosb
->in_size
753 ? STATUS_BUFFER_OVERFLOW
: STATUS_SUCCESS
;
757 data_size_t avail
= 0;
758 LIST_FOR_EACH_ENTRY( message
, &pipe_end
->message_queue
, struct pipe_message
, entry
)
760 avail
+= message
->iosb
->in_size
- message
->read_pos
;
761 if (avail
>= iosb
->out_size
) break;
763 iosb
->out_size
= min( iosb
->out_size
, avail
);
764 iosb
->status
= STATUS_SUCCESS
;
767 message
= LIST_ENTRY( list_head(&pipe_end
->message_queue
), struct pipe_message
, entry
);
768 if (!message
->read_pos
&& message
->iosb
->in_size
== iosb
->out_size
) /* fast path */
770 iosb
->out_data
= message
->iosb
->in_data
;
771 message
->iosb
->in_data
= NULL
;
772 wake_message( message
, message
->iosb
->in_size
);
773 free_message( message
);
777 data_size_t write_pos
= 0, writing
;
780 if (iosb
->out_size
&& !(buf
= iosb
->out_data
= malloc( iosb
->out_size
)))
783 iosb
->status
= STATUS_NO_MEMORY
;
789 message
= LIST_ENTRY( list_head(&pipe_end
->message_queue
), struct pipe_message
, entry
);
790 writing
= min( iosb
->out_size
- write_pos
, message
->iosb
->in_size
- message
->read_pos
);
791 if (writing
) memcpy( buf
+ write_pos
, (const char *)message
->iosb
->in_data
+ message
->read_pos
, writing
);
792 write_pos
+= writing
;
793 message
->read_pos
+= writing
;
794 if (message
->read_pos
== message
->iosb
->in_size
)
796 wake_message(message
, message
->iosb
->in_size
);
797 free_message(message
);
799 } while (write_pos
< iosb
->out_size
);
801 iosb
->result
= iosb
->out_size
;
804 /* We call async_terminate in our reselect implementation, which causes recursive reselect.
805 * We're not interested in such reselect calls, so we ignore them. */
806 static int ignore_reselect
;
808 static void reselect_write_queue( struct pipe_end
*pipe_end
);
810 static void reselect_read_queue( struct pipe_end
*pipe_end
, int reselect_write
)
816 while (!list_empty( &pipe_end
->message_queue
) && (async
= find_pending_async( &pipe_end
->read_q
)))
818 iosb
= async_get_iosb( async
);
819 message_queue_read( pipe_end
, iosb
);
820 async_terminate( async
, iosb
->result
? STATUS_ALERTED
: iosb
->status
);
821 release_object( async
);
822 release_object( iosb
);
827 if (pipe_end
->connection
)
829 if (list_empty( &pipe_end
->message_queue
))
830 fd_async_wake_up( pipe_end
->connection
->fd
, ASYNC_TYPE_WAIT
, STATUS_SUCCESS
);
831 else if (reselect_write
)
832 reselect_write_queue( pipe_end
->connection
);
836 static void reselect_write_queue( struct pipe_end
*pipe_end
)
838 struct pipe_message
*message
, *next
;
839 struct pipe_end
*reader
= pipe_end
->connection
;
840 data_size_t avail
= 0;
846 LIST_FOR_EACH_ENTRY_SAFE( message
, next
, &reader
->message_queue
, struct pipe_message
, entry
)
848 if (message
->async
&& message
->iosb
->status
!= STATUS_PENDING
)
850 release_object( message
->async
);
851 message
->async
= NULL
;
852 free_message( message
);
856 avail
+= message
->iosb
->in_size
- message
->read_pos
;
857 if (message
->async
&& (avail
<= reader
->buffer_size
|| !message
->iosb
->in_size
))
859 wake_message( message
, message
->iosb
->in_size
);
861 else if (message
->async
&& (pipe_end
->flags
& NAMED_PIPE_NONBLOCKING_MODE
))
863 wake_message( message
, message
->read_pos
);
864 free_message( message
);
870 reselect_read_queue( reader
, 0 );
873 static int pipe_end_read( struct fd
*fd
, struct async
*async
, file_pos_t pos
)
875 struct pipe_end
*pipe_end
= get_fd_user( fd
);
877 switch (pipe_end
->state
)
879 case FILE_PIPE_CONNECTED_STATE
:
880 if ((pipe_end
->flags
& NAMED_PIPE_NONBLOCKING_MODE
) && list_empty( &pipe_end
->message_queue
))
882 set_error( STATUS_PIPE_EMPTY
);
886 case FILE_PIPE_DISCONNECTED_STATE
:
887 set_error( STATUS_PIPE_DISCONNECTED
);
889 case FILE_PIPE_LISTENING_STATE
:
890 set_error( STATUS_PIPE_LISTENING
);
892 case FILE_PIPE_CLOSING_STATE
:
893 if (!list_empty( &pipe_end
->message_queue
)) break;
894 set_error( STATUS_PIPE_BROKEN
);
898 queue_async( &pipe_end
->read_q
, async
);
899 reselect_read_queue( pipe_end
, 0 );
900 set_error( STATUS_PENDING
);
904 static int pipe_end_write( struct fd
*fd
, struct async
*async
, file_pos_t pos
)
906 struct pipe_end
*pipe_end
= get_fd_user( fd
);
907 struct pipe_message
*message
;
910 switch (pipe_end
->state
)
912 case FILE_PIPE_CONNECTED_STATE
:
914 case FILE_PIPE_DISCONNECTED_STATE
:
915 set_error( STATUS_PIPE_DISCONNECTED
);
917 case FILE_PIPE_LISTENING_STATE
:
918 set_error( STATUS_PIPE_LISTENING
);
920 case FILE_PIPE_CLOSING_STATE
:
921 set_error( STATUS_PIPE_CLOSING
);
925 if (!pipe_end
->pipe
->message_mode
&& !get_req_data_size()) return 1;
927 iosb
= async_get_iosb( async
);
928 message
= queue_message( pipe_end
->connection
, iosb
);
929 release_object( iosb
);
930 if (!message
) return 0;
932 message
->async
= (struct async
*)grab_object( async
);
933 queue_async( &pipe_end
->write_q
, async
);
934 reselect_read_queue( pipe_end
->connection
, 1 );
935 set_error( STATUS_PENDING
);
939 static void pipe_end_reselect_async( struct fd
*fd
, struct async_queue
*queue
)
941 struct pipe_end
*pipe_end
= get_fd_user( fd
);
943 if (ignore_reselect
) return;
945 if (&pipe_end
->write_q
== queue
)
946 reselect_write_queue( pipe_end
);
947 else if (&pipe_end
->read_q
== queue
)
948 reselect_read_queue( pipe_end
, 0 );
951 static enum server_fd_type
pipe_end_get_fd_type( struct fd
*fd
)
956 static int pipe_end_peek( struct pipe_end
*pipe_end
)
958 unsigned reply_size
= get_reply_max_size();
959 FILE_PIPE_PEEK_BUFFER
*buffer
;
960 struct pipe_message
*message
;
961 data_size_t avail
= 0;
962 data_size_t message_length
= 0;
964 if (reply_size
< offsetof( FILE_PIPE_PEEK_BUFFER
, Data
))
966 set_error( STATUS_INFO_LENGTH_MISMATCH
);
969 reply_size
-= offsetof( FILE_PIPE_PEEK_BUFFER
, Data
);
971 switch (pipe_end
->state
)
973 case FILE_PIPE_CONNECTED_STATE
:
975 case FILE_PIPE_CLOSING_STATE
:
976 if (!list_empty( &pipe_end
->message_queue
)) break;
977 set_error( STATUS_PIPE_BROKEN
);
980 set_error( pipe_end
->pipe
? STATUS_INVALID_PIPE_STATE
: STATUS_PIPE_DISCONNECTED
);
984 LIST_FOR_EACH_ENTRY( message
, &pipe_end
->message_queue
, struct pipe_message
, entry
)
985 avail
+= message
->iosb
->in_size
- message
->read_pos
;
986 reply_size
= min( reply_size
, avail
);
988 if (avail
&& pipe_end
->pipe
->message_mode
)
990 message
= LIST_ENTRY( list_head(&pipe_end
->message_queue
), struct pipe_message
, entry
);
991 message_length
= message
->iosb
->in_size
- message
->read_pos
;
992 reply_size
= min( reply_size
, message_length
);
995 if (!(buffer
= set_reply_data_size( offsetof( FILE_PIPE_PEEK_BUFFER
, Data
[reply_size
] )))) return 0;
996 buffer
->NamedPipeState
= pipe_end
->state
;
997 buffer
->ReadDataAvailable
= avail
;
998 buffer
->NumberOfMessages
= 0; /* FIXME */
999 buffer
->MessageLength
= message_length
;
1003 data_size_t write_pos
= 0, writing
;
1004 LIST_FOR_EACH_ENTRY( message
, &pipe_end
->message_queue
, struct pipe_message
, entry
)
1006 writing
= min( reply_size
- write_pos
, message
->iosb
->in_size
- message
->read_pos
);
1007 memcpy( buffer
->Data
+ write_pos
, (const char *)message
->iosb
->in_data
+ message
->read_pos
,
1009 write_pos
+= writing
;
1010 if (write_pos
== reply_size
) break;
1013 if (message_length
> reply_size
) set_error( STATUS_BUFFER_OVERFLOW
);
1017 static int pipe_end_transceive( struct pipe_end
*pipe_end
, struct async
*async
)
1019 struct pipe_message
*message
;
1022 if (!pipe_end
->connection
)
1024 set_error( pipe_end
->pipe
? STATUS_INVALID_PIPE_STATE
: STATUS_PIPE_DISCONNECTED
);
1028 if (!(pipe_end
->flags
& NAMED_PIPE_MESSAGE_STREAM_READ
))
1030 set_error( STATUS_INVALID_READ_MODE
);
1034 /* not allowed if we already have read data buffered */
1035 if (!list_empty( &pipe_end
->message_queue
))
1037 set_error( STATUS_PIPE_BUSY
);
1041 iosb
= async_get_iosb( async
);
1042 /* ignore output buffer copy transferred because of METHOD_NEITHER */
1043 iosb
->in_size
-= iosb
->out_size
;
1044 /* transaction never blocks on write, so just queue a message without async */
1045 message
= queue_message( pipe_end
->connection
, iosb
);
1046 release_object( iosb
);
1047 if (!message
) return 0;
1048 reselect_read_queue( pipe_end
->connection
, 0 );
1050 queue_async( &pipe_end
->read_q
, async
);
1051 reselect_read_queue( pipe_end
, 0 );
1052 set_error( STATUS_PENDING
);
1056 static int pipe_end_get_connection_attribute( struct pipe_end
*pipe_end
)
1058 const char *attr
= get_req_data();
1059 data_size_t value_size
, attr_size
= get_req_data_size();
1062 if (attr_size
== sizeof("ClientProcessId") && !memcmp( attr
, "ClientProcessId", attr_size
))
1064 value
= &pipe_end
->client_pid
;
1065 value_size
= sizeof(pipe_end
->client_pid
);
1067 else if (attr_size
== sizeof("ServerProcessId") && !memcmp( attr
, "ServerProcessId", attr_size
))
1069 value
= &pipe_end
->server_pid
;
1070 value_size
= sizeof(pipe_end
->server_pid
);
1074 set_error( STATUS_ILLEGAL_FUNCTION
);
1078 if (get_reply_max_size() < value_size
)
1080 set_error( STATUS_INFO_LENGTH_MISMATCH
);
1084 set_reply_data( value
, value_size
);
1088 static int pipe_end_ioctl( struct pipe_end
*pipe_end
, ioctl_code_t code
, struct async
*async
)
1092 case FSCTL_PIPE_GET_CONNECTION_ATTRIBUTE
:
1093 return pipe_end_get_connection_attribute( pipe_end
);
1095 case FSCTL_PIPE_PEEK
:
1096 return pipe_end_peek( pipe_end
);
1098 case FSCTL_PIPE_TRANSCEIVE
:
1099 return pipe_end_transceive( pipe_end
, async
);
1102 return default_fd_ioctl( pipe_end
->fd
, code
, async
);
1106 static int pipe_server_ioctl( struct fd
*fd
, ioctl_code_t code
, struct async
*async
)
1108 struct pipe_server
*server
= get_fd_user( fd
);
1112 case FSCTL_PIPE_LISTEN
:
1113 switch(server
->pipe_end
.state
)
1115 case FILE_PIPE_LISTENING_STATE
:
1117 case FILE_PIPE_DISCONNECTED_STATE
:
1118 server
->pipe_end
.state
= FILE_PIPE_LISTENING_STATE
;
1119 list_add_tail( &server
->pipe_end
.pipe
->listeners
, &server
->entry
);
1121 case FILE_PIPE_CONNECTED_STATE
:
1122 set_error( STATUS_PIPE_CONNECTED
);
1124 case FILE_PIPE_CLOSING_STATE
:
1125 set_error( STATUS_PIPE_CLOSING
);
1129 if (server
->pipe_end
.flags
& NAMED_PIPE_NONBLOCKING_MODE
)
1131 set_error( STATUS_PIPE_LISTENING
);
1134 queue_async( &server
->listen_q
, async
);
1135 async_wake_up( &server
->pipe_end
.pipe
->waiters
, STATUS_SUCCESS
);
1136 set_error( STATUS_PENDING
);
1139 case FSCTL_PIPE_DISCONNECT
:
1140 switch(server
->pipe_end
.state
)
1142 case FILE_PIPE_CONNECTED_STATE
:
1143 /* dump the client connection - all data is lost */
1144 assert( server
->pipe_end
.connection
);
1145 release_object( server
->pipe_end
.connection
->pipe
);
1146 server
->pipe_end
.connection
->pipe
= NULL
;
1148 case FILE_PIPE_CLOSING_STATE
:
1150 case FILE_PIPE_LISTENING_STATE
:
1151 set_error( STATUS_PIPE_LISTENING
);
1153 case FILE_PIPE_DISCONNECTED_STATE
:
1154 set_error( STATUS_PIPE_DISCONNECTED
);
1158 pipe_end_disconnect( &server
->pipe_end
, STATUS_PIPE_DISCONNECTED
);
1161 case FSCTL_PIPE_IMPERSONATE
:
1162 if (current
->process
->token
) /* FIXME: use the client token */
1164 struct token
*token
;
1165 if (!(token
= token_duplicate( current
->process
->token
, 0, SecurityImpersonation
, NULL
, NULL
, 0, NULL
, 0 )))
1167 if (current
->token
) release_object( current
->token
);
1168 current
->token
= token
;
1173 return pipe_end_ioctl( &server
->pipe_end
, code
, async
);
1177 static int pipe_client_ioctl( struct fd
*fd
, ioctl_code_t code
, struct async
*async
)
1179 struct pipe_end
*client
= get_fd_user( fd
);
1183 case FSCTL_PIPE_LISTEN
:
1184 set_error( STATUS_ILLEGAL_FUNCTION
);
1188 return pipe_end_ioctl( client
, code
, async
);
1192 static void init_pipe_end( struct pipe_end
*pipe_end
, struct named_pipe
*pipe
,
1193 unsigned int pipe_flags
, data_size_t buffer_size
)
1195 pipe_end
->pipe
= (struct named_pipe
*)grab_object( pipe
);
1196 pipe_end
->fd
= NULL
;
1197 pipe_end
->flags
= pipe_flags
;
1198 pipe_end
->connection
= NULL
;
1199 pipe_end
->buffer_size
= buffer_size
;
1200 init_async_queue( &pipe_end
->read_q
);
1201 init_async_queue( &pipe_end
->write_q
);
1202 list_init( &pipe_end
->message_queue
);
1205 static struct pipe_server
*create_pipe_server( struct named_pipe
*pipe
, unsigned int options
,
1206 unsigned int pipe_flags
)
1208 struct pipe_server
*server
;
1210 server
= alloc_object( &pipe_server_ops
);
1214 server
->options
= options
;
1215 init_pipe_end( &server
->pipe_end
, pipe
, pipe_flags
, pipe
->insize
);
1216 server
->pipe_end
.state
= FILE_PIPE_LISTENING_STATE
;
1217 server
->pipe_end
.server_pid
= get_process_id( current
->process
);
1218 init_async_queue( &server
->listen_q
);
1220 list_add_tail( &pipe
->listeners
, &server
->entry
);
1221 if (!(server
->pipe_end
.fd
= alloc_pseudo_fd( &pipe_server_fd_ops
, &server
->pipe_end
.obj
, options
)))
1223 release_object( server
);
1226 allow_fd_caching( server
->pipe_end
.fd
);
1227 set_fd_signaled( server
->pipe_end
.fd
, 1 );
1228 async_wake_up( &pipe
->waiters
, STATUS_SUCCESS
);
1232 static struct pipe_end
*create_pipe_client( struct named_pipe
*pipe
, data_size_t buffer_size
, unsigned int options
)
1234 struct pipe_end
*client
;
1236 client
= alloc_object( &pipe_client_ops
);
1240 init_pipe_end( client
, pipe
, 0, buffer_size
);
1241 client
->state
= FILE_PIPE_CONNECTED_STATE
;
1242 client
->client_pid
= get_process_id( current
->process
);
1244 client
->fd
= alloc_pseudo_fd( &pipe_client_fd_ops
, &client
->obj
, options
);
1247 release_object( client
);
1250 allow_fd_caching( client
->fd
);
1251 set_fd_signaled( client
->fd
, 1 );
1256 static int named_pipe_link_name( struct object
*obj
, struct object_name
*name
, struct object
*parent
)
1258 struct named_pipe_device
*dev
= (struct named_pipe_device
*)parent
;
1260 if (parent
->ops
!= &named_pipe_device_ops
)
1262 set_error( STATUS_OBJECT_NAME_INVALID
);
1265 namespace_add( dev
->pipes
, name
);
1266 name
->parent
= grab_object( parent
);
1270 static struct object
*named_pipe_open_file( struct object
*obj
, unsigned int access
,
1271 unsigned int sharing
, unsigned int options
)
1273 struct named_pipe
*pipe
= (struct named_pipe
*)obj
;
1274 struct pipe_server
*server
;
1275 struct pipe_end
*client
;
1276 unsigned int pipe_sharing
;
1278 if (list_empty( &pipe
->listeners
))
1280 set_error( STATUS_PIPE_NOT_AVAILABLE
);
1283 server
= LIST_ENTRY( list_head( &pipe
->listeners
), struct pipe_server
, entry
);
1285 pipe_sharing
= pipe
->sharing
;
1286 if (((access
& GENERIC_READ
) && !(pipe_sharing
& FILE_SHARE_READ
)) ||
1287 ((access
& GENERIC_WRITE
) && !(pipe_sharing
& FILE_SHARE_WRITE
)))
1289 set_error( STATUS_ACCESS_DENIED
);
1293 if ((client
= create_pipe_client( pipe
, pipe
->outsize
, options
)))
1295 async_wake_up( &server
->listen_q
, STATUS_SUCCESS
);
1296 server
->pipe_end
.state
= FILE_PIPE_CONNECTED_STATE
;
1297 server
->pipe_end
.connection
= client
;
1298 client
->connection
= &server
->pipe_end
;
1299 server
->pipe_end
.client_pid
= client
->client_pid
;
1300 client
->server_pid
= server
->pipe_end
.server_pid
;
1301 list_remove( &server
->entry
);
1303 return &client
->obj
;
1306 static int named_pipe_device_ioctl( struct fd
*fd
, ioctl_code_t code
, struct async
*async
)
1308 struct named_pipe_device
*device
= get_fd_user( fd
);
1312 case FSCTL_PIPE_WAIT
:
1314 const FILE_PIPE_WAIT_FOR_BUFFER
*buffer
= get_req_data();
1315 data_size_t size
= get_req_data_size();
1316 struct named_pipe
*pipe
;
1317 struct unicode_str name
;
1320 if (size
< sizeof(*buffer
) ||
1321 size
< FIELD_OFFSET(FILE_PIPE_WAIT_FOR_BUFFER
, Name
[buffer
->NameLength
/sizeof(WCHAR
)]))
1323 set_error( STATUS_INVALID_PARAMETER
);
1326 name
.str
= buffer
->Name
;
1327 name
.len
= (buffer
->NameLength
/ sizeof(WCHAR
)) * sizeof(WCHAR
);
1328 if (!(pipe
= open_named_object( &device
->obj
, &named_pipe_ops
, &name
, 0 ))) return 0;
1330 if (list_empty( &pipe
->listeners
))
1332 queue_async( &pipe
->waiters
, async
);
1333 when
= buffer
->TimeoutSpecified
? buffer
->Timeout
.QuadPart
: pipe
->timeout
;
1334 async_set_timeout( async
, when
, STATUS_IO_TIMEOUT
);
1335 set_error( STATUS_PENDING
);
1338 release_object( pipe
);
1343 return default_fd_ioctl( fd
, code
, async
);
1348 DECL_HANDLER(create_named_pipe
)
1350 struct named_pipe
*pipe
;
1351 struct pipe_server
*server
;
1352 struct unicode_str name
;
1353 struct object
*root
;
1354 const struct security_descriptor
*sd
;
1355 const struct object_attributes
*objattr
= get_req_object_attributes( &sd
, &name
, &root
);
1357 if (!objattr
) return;
1359 if (!req
->sharing
|| (req
->sharing
& ~(FILE_SHARE_READ
| FILE_SHARE_WRITE
)) ||
1360 (!(req
->flags
& NAMED_PIPE_MESSAGE_STREAM_WRITE
) && (req
->flags
& NAMED_PIPE_MESSAGE_STREAM_READ
)))
1362 if (root
) release_object( root
);
1363 set_error( STATUS_INVALID_PARAMETER
);
1367 if (!name
.len
) /* pipes need a root directory even without a name */
1369 if (!objattr
->rootdir
)
1371 set_error( STATUS_OBJECT_PATH_SYNTAX_BAD
);
1374 if (!(root
= get_directory_obj( current
->process
, objattr
->rootdir
))) return;
1377 pipe
= create_named_object( root
, &named_pipe_ops
, &name
, objattr
->attributes
| OBJ_OPENIF
, NULL
);
1379 if (root
) release_object( root
);
1382 if (get_error() != STATUS_OBJECT_NAME_EXISTS
)
1384 /* initialize it if it didn't already exist */
1385 pipe
->instances
= 0;
1386 init_async_queue( &pipe
->waiters
);
1387 list_init( &pipe
->listeners
);
1388 pipe
->insize
= req
->insize
;
1389 pipe
->outsize
= req
->outsize
;
1390 pipe
->maxinstances
= req
->maxinstances
;
1391 pipe
->timeout
= req
->timeout
;
1392 pipe
->message_mode
= (req
->flags
& NAMED_PIPE_MESSAGE_STREAM_WRITE
) != 0;
1393 pipe
->sharing
= req
->sharing
;
1394 if (sd
) default_set_sd( &pipe
->obj
, sd
, OWNER_SECURITY_INFORMATION
|
1395 GROUP_SECURITY_INFORMATION
|
1396 DACL_SECURITY_INFORMATION
|
1397 SACL_SECURITY_INFORMATION
);
1401 if (pipe
->maxinstances
<= pipe
->instances
)
1403 set_error( STATUS_INSTANCE_NOT_AVAILABLE
);
1404 release_object( pipe
);
1407 if (pipe
->sharing
!= req
->sharing
)
1409 set_error( STATUS_ACCESS_DENIED
);
1410 release_object( pipe
);
1413 clear_error(); /* clear the name collision */
1416 server
= create_pipe_server( pipe
, req
->options
, req
->flags
);
1419 reply
->handle
= alloc_handle( current
->process
, server
, req
->access
, objattr
->attributes
);
1421 release_object( server
);
1424 release_object( pipe
);
1427 DECL_HANDLER(set_named_pipe_info
)
1429 struct pipe_end
*pipe_end
;
1431 pipe_end
= (struct pipe_end
*)get_handle_obj( current
->process
, req
->handle
,
1432 FILE_WRITE_ATTRIBUTES
, &pipe_server_ops
);
1435 if (get_error() != STATUS_OBJECT_TYPE_MISMATCH
)
1439 pipe_end
= (struct pipe_end
*)get_handle_obj( current
->process
, req
->handle
,
1440 0, &pipe_client_ops
);
1441 if (!pipe_end
) return;
1444 if (!pipe_end
->pipe
)
1446 set_error( STATUS_PIPE_DISCONNECTED
);
1448 else if ((req
->flags
& ~(NAMED_PIPE_MESSAGE_STREAM_READ
| NAMED_PIPE_NONBLOCKING_MODE
)) ||
1449 ((req
->flags
& NAMED_PIPE_MESSAGE_STREAM_READ
) && !pipe_end
->pipe
->message_mode
))
1451 set_error( STATUS_INVALID_PARAMETER
);
1455 pipe_end
->flags
= req
->flags
;
1458 release_object( pipe_end
);