2001-07-10 12:16:49 -07:00
|
|
|
/*
|
|
|
|
* Server-side pipe management
|
|
|
|
*
|
|
|
|
* Copyright (C) 1998 Alexandre Julliard
|
2001-08-23 16:29:20 -07:00
|
|
|
* Copyright (C) 2001 Mike McCormack
|
2017-03-26 03:52:39 -07:00
|
|
|
* Copyright 2016 Jacek Caban for CodeWeavers
|
2001-08-23 16:29:20 -07:00
|
|
|
*
|
2002-03-09 16:29:33 -07:00
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 05:49:52 -07:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2001-07-10 12:16:49 -07:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
2002-04-26 12:05:15 -07:00
|
|
|
#include "wine/port.h"
|
2001-07-10 12:16:49 -07:00
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
#include <string.h>
|
2003-09-05 16:08:26 -07:00
|
|
|
#include <stdarg.h>
|
2001-07-10 12:16:49 -07:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
2005-11-28 09:32:54 -07:00
|
|
|
#include "ntstatus.h"
|
|
|
|
#define WIN32_NO_STATUS
|
2003-09-05 16:08:26 -07:00
|
|
|
#include "windef.h"
|
2005-06-08 12:11:46 -07:00
|
|
|
#include "winternl.h"
|
2007-04-16 05:51:29 -07:00
|
|
|
#include "winioctl.h"
|
2001-07-10 12:16:49 -07:00
|
|
|
|
2003-01-29 17:26:44 -07:00
|
|
|
#include "file.h"
|
2001-07-10 12:16:49 -07:00
|
|
|
#include "handle.h"
|
|
|
|
#include "thread.h"
|
|
|
|
#include "request.h"
|
2014-11-12 03:25:23 -07:00
|
|
|
#include "security.h"
|
2018-04-11 05:32:56 -07:00
|
|
|
#include "process.h"
|
2001-07-10 12:16:49 -07:00
|
|
|
|
|
|
|
struct named_pipe;
|
|
|
|
|
2017-03-21 05:03:03 -07:00
|
|
|
struct pipe_message
|
|
|
|
{
|
|
|
|
struct list entry; /* entry in message queue */
|
|
|
|
data_size_t read_pos; /* already read bytes */
|
|
|
|
struct iosb *iosb; /* message iosb */
|
|
|
|
struct async *async; /* async of pending write */
|
|
|
|
};
|
|
|
|
|
2017-02-22 06:51:06 -07:00
|
|
|
struct pipe_end
|
2003-05-14 21:22:45 -07:00
|
|
|
{
|
2005-02-03 03:48:23 -07:00
|
|
|
struct object obj; /* object header */
|
|
|
|
struct fd *fd; /* pipe file descriptor */
|
2017-02-22 06:51:06 -07:00
|
|
|
unsigned int flags; /* pipe flags */
|
2018-08-08 13:00:32 -07:00
|
|
|
unsigned int state; /* pipe state */
|
2018-08-16 06:10:33 -07:00
|
|
|
struct named_pipe *pipe;
|
2017-03-15 15:25:25 -07:00
|
|
|
struct pipe_end *connection; /* the other end of the pipe */
|
2018-04-11 05:32:56 -07:00
|
|
|
process_id_t client_pid; /* process that created the client */
|
|
|
|
process_id_t server_pid; /* process that created the server */
|
2017-03-15 15:25:31 -07:00
|
|
|
data_size_t buffer_size;/* size of buffered data that doesn't block caller */
|
2017-03-21 05:03:03 -07:00
|
|
|
struct list message_queue;
|
2017-07-04 06:26:19 -07:00
|
|
|
struct async_queue read_q; /* read queue */
|
|
|
|
struct async_queue write_q; /* write queue */
|
2017-02-22 06:51:06 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
struct pipe_server
|
|
|
|
{
|
2018-11-23 07:13:24 -07:00
|
|
|
struct pipe_end pipe_end; /* common header for both pipe ends */
|
2019-03-11 09:03:23 -07:00
|
|
|
struct list entry; /* entry in named pipe listeners list */
|
2005-06-08 12:11:46 -07:00
|
|
|
unsigned int options; /* pipe options */
|
2018-08-17 08:41:01 -07:00
|
|
|
struct async_queue listen_q; /* listen queue */
|
2003-05-14 21:22:45 -07:00
|
|
|
};
|
|
|
|
|
2001-07-10 12:16:49 -07:00
|
|
|
struct named_pipe
|
|
|
|
{
|
|
|
|
struct object obj; /* object header */
|
2018-11-23 07:13:07 -07:00
|
|
|
int message_mode;
|
2011-09-26 04:57:15 -07:00
|
|
|
unsigned int sharing;
|
2001-07-10 12:16:49 -07:00
|
|
|
unsigned int maxinstances;
|
|
|
|
unsigned int outsize;
|
|
|
|
unsigned int insize;
|
2003-05-14 21:22:45 -07:00
|
|
|
unsigned int instances;
|
2007-04-17 11:08:59 -07:00
|
|
|
timeout_t timeout;
|
2019-03-11 09:03:23 -07:00
|
|
|
struct list listeners; /* list of servers listening on this pipe */
|
2017-07-04 06:26:19 -07:00
|
|
|
struct async_queue waiters; /* list of clients waiting to connect */
|
2001-07-10 12:16:49 -07:00
|
|
|
};
|
|
|
|
|
2005-12-05 05:09:35 -07:00
|
|
|
struct named_pipe_device
|
|
|
|
{
|
|
|
|
struct object obj; /* object header */
|
|
|
|
struct namespace *pipes; /* named pipe namespace */
|
|
|
|
};
|
|
|
|
|
2018-10-29 07:49:47 -07:00
|
|
|
struct named_pipe_device_file
|
|
|
|
{
|
|
|
|
struct object obj; /* object header */
|
|
|
|
struct fd *fd; /* pseudo-fd for ioctls */
|
|
|
|
struct named_pipe_device *device; /* named pipe device */
|
|
|
|
};
|
|
|
|
|
2001-07-10 12:16:49 -07:00
|
|
|
static void named_pipe_dump( struct object *obj, int verbose );
|
2005-12-12 08:46:17 -07:00
|
|
|
static unsigned int named_pipe_map_access( struct object *obj, unsigned int access );
|
2016-02-04 05:08:02 -07:00
|
|
|
static int named_pipe_link_name( struct object *obj, struct object_name *name, struct object *parent );
|
2007-03-22 08:47:46 -07:00
|
|
|
static struct object *named_pipe_open_file( struct object *obj, unsigned int access,
|
|
|
|
unsigned int sharing, unsigned int options );
|
2003-05-14 21:22:45 -07:00
|
|
|
static void named_pipe_destroy( struct object *obj );
|
2001-07-10 12:16:49 -07:00
|
|
|
|
|
|
|
static const struct object_ops named_pipe_ops =
|
|
|
|
{
|
|
|
|
sizeof(struct named_pipe), /* size */
|
|
|
|
named_pipe_dump, /* dump */
|
2007-12-05 10:16:42 -07:00
|
|
|
no_get_type, /* get_type */
|
2001-07-10 12:16:49 -07:00
|
|
|
no_add_queue, /* add_queue */
|
|
|
|
NULL, /* remove_queue */
|
|
|
|
NULL, /* signaled */
|
|
|
|
NULL, /* satisfied */
|
2005-04-24 10:35:52 -07:00
|
|
|
no_signal, /* signal */
|
2001-07-10 12:16:49 -07:00
|
|
|
no_get_fd, /* get_fd */
|
2005-12-12 08:46:17 -07:00
|
|
|
named_pipe_map_access, /* map_access */
|
2007-10-03 05:10:37 -07:00
|
|
|
default_get_sd, /* get_sd */
|
|
|
|
default_set_sd, /* set_sd */
|
2005-11-22 07:55:42 -07:00
|
|
|
no_lookup_name, /* lookup_name */
|
2016-02-04 05:08:02 -07:00
|
|
|
named_pipe_link_name, /* link_name */
|
|
|
|
default_unlink_name, /* unlink_name */
|
2007-03-22 08:47:46 -07:00
|
|
|
named_pipe_open_file, /* open_file */
|
2019-03-25 06:37:09 -07:00
|
|
|
no_kernel_obj_list, /* get_kernel_obj_list */
|
2005-06-09 08:39:52 -07:00
|
|
|
no_close_handle, /* close_handle */
|
2001-07-10 12:16:49 -07:00
|
|
|
named_pipe_destroy /* destroy */
|
|
|
|
};
|
|
|
|
|
2017-03-15 15:25:42 -07:00
|
|
|
/* common server and client pipe end functions */
|
2018-08-17 08:41:30 -07:00
|
|
|
static void pipe_end_destroy( struct object *obj );
|
2017-04-24 06:18:14 -07:00
|
|
|
static enum server_fd_type pipe_end_get_fd_type( struct fd *fd );
|
2017-10-09 05:28:46 -07:00
|
|
|
static struct fd *pipe_end_get_fd( struct object *obj );
|
2018-08-16 06:10:55 -07:00
|
|
|
static struct security_descriptor *pipe_end_get_sd( struct object *obj );
|
|
|
|
static int pipe_end_set_sd( struct object *obj, const struct security_descriptor *sd,
|
|
|
|
unsigned int set_info );
|
2017-06-26 03:17:36 -07:00
|
|
|
static int pipe_end_read( struct fd *fd, struct async *async, file_pos_t pos );
|
2017-06-26 03:18:23 -07:00
|
|
|
static int pipe_end_write( struct fd *fd, struct async *async_data, file_pos_t pos );
|
2017-10-04 06:18:53 -07:00
|
|
|
static int pipe_end_flush( struct fd *fd, struct async *async );
|
2017-10-02 07:42:24 -07:00
|
|
|
static void pipe_end_get_volume_info( struct fd *fd, unsigned int info_class );
|
2017-03-21 05:03:26 -07:00
|
|
|
static void pipe_end_reselect_async( struct fd *fd, struct async_queue *queue );
|
2018-10-15 04:40:36 -07:00
|
|
|
static void pipe_end_get_file_info( struct fd *fd, obj_handle_t handle, unsigned int info_class );
|
2017-03-15 15:25:42 -07:00
|
|
|
|
2003-05-14 21:22:45 -07:00
|
|
|
/* server end functions */
|
|
|
|
static void pipe_server_dump( struct object *obj, int verbose );
|
|
|
|
static void pipe_server_destroy( struct object *obj);
|
2017-06-26 03:20:10 -07:00
|
|
|
static int pipe_server_ioctl( struct fd *fd, ioctl_code_t code, struct async *async );
|
2003-05-14 21:22:45 -07:00
|
|
|
|
|
|
|
static const struct object_ops pipe_server_ops =
|
|
|
|
{
|
|
|
|
sizeof(struct pipe_server), /* size */
|
|
|
|
pipe_server_dump, /* dump */
|
2019-02-22 05:14:34 -07:00
|
|
|
file_get_type, /* get_type */
|
2007-04-04 10:39:29 -07:00
|
|
|
add_queue, /* add_queue */
|
|
|
|
remove_queue, /* remove_queue */
|
2003-05-14 21:22:45 -07:00
|
|
|
default_fd_signaled, /* signaled */
|
|
|
|
no_satisfied, /* satisfied */
|
2005-04-24 10:35:52 -07:00
|
|
|
no_signal, /* signal */
|
2017-10-09 05:28:46 -07:00
|
|
|
pipe_end_get_fd, /* get_fd */
|
2007-10-02 05:20:15 -07:00
|
|
|
default_fd_map_access, /* map_access */
|
2018-08-16 06:10:55 -07:00
|
|
|
pipe_end_get_sd, /* get_sd */
|
|
|
|
pipe_end_set_sd, /* set_sd */
|
2005-11-22 07:55:42 -07:00
|
|
|
no_lookup_name, /* lookup_name */
|
2016-02-04 05:07:19 -07:00
|
|
|
no_link_name, /* link_name */
|
|
|
|
NULL, /* unlink_name */
|
2007-03-22 03:44:29 -07:00
|
|
|
no_open_file, /* open_file */
|
2019-03-25 06:37:09 -07:00
|
|
|
no_kernel_obj_list, /* get_kernel_obj_list */
|
2006-11-02 12:52:22 -07:00
|
|
|
fd_close_handle, /* close_handle */
|
2003-05-14 21:22:45 -07:00
|
|
|
pipe_server_destroy /* destroy */
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct fd_ops pipe_server_fd_ops =
|
|
|
|
{
|
2007-04-10 08:07:27 -07:00
|
|
|
default_fd_get_poll_events, /* get_poll_events */
|
2003-05-14 21:22:45 -07:00
|
|
|
default_poll_event, /* poll_event */
|
2017-04-24 06:18:14 -07:00
|
|
|
pipe_end_get_fd_type, /* get_fd_type */
|
2017-03-23 07:42:03 -07:00
|
|
|
pipe_end_read, /* read */
|
2017-03-21 05:03:39 -07:00
|
|
|
pipe_end_write, /* write */
|
2017-10-04 06:18:53 -07:00
|
|
|
pipe_end_flush, /* flush */
|
2018-08-16 06:11:08 -07:00
|
|
|
pipe_end_get_file_info, /* get_file_info */
|
2017-10-02 07:42:24 -07:00
|
|
|
pipe_end_get_volume_info, /* get_volume_info */
|
2007-04-16 05:51:29 -07:00
|
|
|
pipe_server_ioctl, /* ioctl */
|
2017-10-05 05:29:54 -07:00
|
|
|
no_fd_queue_async, /* queue_async */
|
2017-03-21 05:03:26 -07:00
|
|
|
pipe_end_reselect_async /* reselect_async */
|
2003-05-14 21:22:45 -07:00
|
|
|
};
|
2003-02-18 17:33:32 -07:00
|
|
|
|
2003-05-14 21:22:45 -07:00
|
|
|
/* client end functions */
|
|
|
|
static void pipe_client_dump( struct object *obj, int verbose );
|
2017-06-26 03:20:10 -07:00
|
|
|
static int pipe_client_ioctl( struct fd *fd, ioctl_code_t code, struct async *async );
|
2001-07-10 12:16:49 -07:00
|
|
|
|
2003-05-14 21:22:45 -07:00
|
|
|
static const struct object_ops pipe_client_ops =
|
2001-07-10 12:16:49 -07:00
|
|
|
{
|
2018-11-23 07:13:24 -07:00
|
|
|
sizeof(struct pipe_end), /* size */
|
2003-05-14 21:22:45 -07:00
|
|
|
pipe_client_dump, /* dump */
|
2019-02-22 05:14:34 -07:00
|
|
|
file_get_type, /* get_type */
|
2007-04-04 10:39:29 -07:00
|
|
|
add_queue, /* add_queue */
|
|
|
|
remove_queue, /* remove_queue */
|
2017-11-28 09:35:34 -07:00
|
|
|
default_fd_signaled, /* signaled */
|
2001-07-10 12:16:49 -07:00
|
|
|
no_satisfied, /* satisfied */
|
2005-04-24 10:35:52 -07:00
|
|
|
no_signal, /* signal */
|
2017-10-09 05:28:46 -07:00
|
|
|
pipe_end_get_fd, /* get_fd */
|
2007-10-02 05:20:15 -07:00
|
|
|
default_fd_map_access, /* map_access */
|
2018-08-16 06:10:55 -07:00
|
|
|
pipe_end_get_sd, /* get_sd */
|
|
|
|
pipe_end_set_sd, /* set_sd */
|
2005-11-22 07:55:42 -07:00
|
|
|
no_lookup_name, /* lookup_name */
|
2016-02-04 05:07:19 -07:00
|
|
|
no_link_name, /* link_name */
|
|
|
|
NULL, /* unlink_name */
|
2007-03-22 03:44:29 -07:00
|
|
|
no_open_file, /* open_file */
|
2019-03-25 06:37:09 -07:00
|
|
|
no_kernel_obj_list, /* get_kernel_obj_list */
|
2006-11-02 12:52:22 -07:00
|
|
|
fd_close_handle, /* close_handle */
|
2018-08-17 08:41:30 -07:00
|
|
|
pipe_end_destroy /* destroy */
|
2003-01-29 17:26:44 -07:00
|
|
|
};
|
|
|
|
|
2003-05-14 21:22:45 -07:00
|
|
|
static const struct fd_ops pipe_client_fd_ops =
|
2003-01-29 17:26:44 -07:00
|
|
|
{
|
2005-06-08 12:11:46 -07:00
|
|
|
default_fd_get_poll_events, /* get_poll_events */
|
2001-07-10 12:16:49 -07:00
|
|
|
default_poll_event, /* poll_event */
|
2017-04-24 06:18:14 -07:00
|
|
|
pipe_end_get_fd_type, /* get_fd_type */
|
2017-03-23 07:42:03 -07:00
|
|
|
pipe_end_read, /* read */
|
2017-03-21 05:03:39 -07:00
|
|
|
pipe_end_write, /* write */
|
2017-10-04 06:18:53 -07:00
|
|
|
pipe_end_flush, /* flush */
|
2018-08-16 06:11:08 -07:00
|
|
|
pipe_end_get_file_info, /* get_file_info */
|
2017-10-02 07:42:24 -07:00
|
|
|
pipe_end_get_volume_info, /* get_volume_info */
|
2017-03-21 05:03:55 -07:00
|
|
|
pipe_client_ioctl, /* ioctl */
|
2017-10-05 05:29:54 -07:00
|
|
|
no_fd_queue_async, /* queue_async */
|
2017-03-21 05:03:26 -07:00
|
|
|
pipe_end_reselect_async /* reselect_async */
|
2001-07-10 12:16:49 -07:00
|
|
|
};
|
|
|
|
|
2005-12-05 05:09:35 -07:00
|
|
|
static void named_pipe_device_dump( struct object *obj, int verbose );
|
2007-12-05 10:16:42 -07:00
|
|
|
static struct object_type *named_pipe_device_get_type( struct object *obj );
|
2005-12-05 05:09:35 -07:00
|
|
|
static struct object *named_pipe_device_lookup_name( struct object *obj,
|
|
|
|
struct unicode_str *name, unsigned int attr );
|
2007-03-22 03:52:40 -07:00
|
|
|
static struct object *named_pipe_device_open_file( struct object *obj, unsigned int access,
|
|
|
|
unsigned int sharing, unsigned int options );
|
2005-12-05 05:09:35 -07:00
|
|
|
static void named_pipe_device_destroy( struct object *obj );
|
|
|
|
|
|
|
|
static const struct object_ops named_pipe_device_ops =
|
|
|
|
{
|
|
|
|
sizeof(struct named_pipe_device), /* size */
|
|
|
|
named_pipe_device_dump, /* dump */
|
2007-12-05 10:16:42 -07:00
|
|
|
named_pipe_device_get_type, /* get_type */
|
2005-12-05 05:09:35 -07:00
|
|
|
no_add_queue, /* add_queue */
|
|
|
|
NULL, /* remove_queue */
|
|
|
|
NULL, /* signaled */
|
|
|
|
no_satisfied, /* satisfied */
|
|
|
|
no_signal, /* signal */
|
2018-10-29 07:49:47 -07:00
|
|
|
no_get_fd, /* get_fd */
|
2007-04-18 07:32:31 -07:00
|
|
|
no_map_access, /* map_access */
|
2007-10-03 05:10:37 -07:00
|
|
|
default_get_sd, /* get_sd */
|
|
|
|
default_set_sd, /* set_sd */
|
2005-12-05 05:09:35 -07:00
|
|
|
named_pipe_device_lookup_name, /* lookup_name */
|
2016-02-04 05:08:02 -07:00
|
|
|
directory_link_name, /* link_name */
|
|
|
|
default_unlink_name, /* unlink_name */
|
2007-03-22 03:52:40 -07:00
|
|
|
named_pipe_device_open_file, /* open_file */
|
2019-03-25 06:37:09 -07:00
|
|
|
no_kernel_obj_list, /* get_kernel_obj_list */
|
2018-10-29 07:49:47 -07:00
|
|
|
no_close_handle, /* close_handle */
|
2005-12-05 05:09:35 -07:00
|
|
|
named_pipe_device_destroy /* destroy */
|
|
|
|
};
|
|
|
|
|
2018-10-29 07:49:47 -07:00
|
|
|
static void named_pipe_device_file_dump( struct object *obj, int verbose );
|
|
|
|
static struct fd *named_pipe_device_file_get_fd( struct object *obj );
|
|
|
|
static int named_pipe_device_ioctl( struct fd *fd, ioctl_code_t code, struct async *async );
|
|
|
|
static enum server_fd_type named_pipe_device_file_get_fd_type( struct fd *fd );
|
|
|
|
static void named_pipe_device_file_destroy( struct object *obj );
|
|
|
|
|
|
|
|
static const struct object_ops named_pipe_device_file_ops =
|
|
|
|
{
|
|
|
|
sizeof(struct named_pipe_device_file), /* size */
|
|
|
|
named_pipe_device_file_dump, /* dump */
|
|
|
|
no_get_type, /* get_type */
|
|
|
|
add_queue, /* add_queue */
|
|
|
|
remove_queue, /* remove_queue */
|
|
|
|
default_fd_signaled, /* signaled */
|
|
|
|
no_satisfied, /* satisfied */
|
|
|
|
no_signal, /* signal */
|
|
|
|
named_pipe_device_file_get_fd, /* get_fd */
|
|
|
|
default_fd_map_access, /* map_access */
|
|
|
|
default_get_sd, /* get_sd */
|
|
|
|
default_set_sd, /* set_sd */
|
|
|
|
no_lookup_name, /* lookup_name */
|
|
|
|
no_link_name, /* link_name */
|
|
|
|
NULL, /* unlink_name */
|
|
|
|
no_open_file, /* open_file */
|
2019-03-25 06:37:09 -07:00
|
|
|
no_kernel_obj_list, /* get_kernel_obj_list */
|
2018-10-29 07:49:47 -07:00
|
|
|
fd_close_handle, /* close_handle */
|
|
|
|
named_pipe_device_file_destroy /* destroy */
|
|
|
|
};
|
|
|
|
|
2005-12-12 06:30:06 -07:00
|
|
|
static const struct fd_ops named_pipe_device_fd_ops =
|
|
|
|
{
|
2018-10-29 07:49:47 -07:00
|
|
|
default_fd_get_poll_events, /* get_poll_events */
|
|
|
|
default_poll_event, /* poll_event */
|
|
|
|
named_pipe_device_file_get_fd_type, /* get_fd_type */
|
|
|
|
no_fd_read, /* read */
|
|
|
|
no_fd_write, /* write */
|
|
|
|
no_fd_flush, /* flush */
|
|
|
|
default_fd_get_file_info, /* get_file_info */
|
|
|
|
no_fd_get_volume_info, /* get_volume_info */
|
|
|
|
named_pipe_device_ioctl, /* ioctl */
|
|
|
|
default_fd_queue_async, /* queue_async */
|
|
|
|
default_fd_reselect_async /* reselect_async */
|
2005-12-12 06:30:06 -07:00
|
|
|
};
|
|
|
|
|
2001-07-10 12:16:49 -07:00
|
|
|
static void named_pipe_dump( struct object *obj, int verbose )
|
|
|
|
{
|
2016-01-21 05:08:56 -07:00
|
|
|
fputs( "Named pipe\n", stderr );
|
2001-07-10 12:16:49 -07:00
|
|
|
}
|
|
|
|
|
2005-12-12 08:46:17 -07:00
|
|
|
static unsigned int named_pipe_map_access( struct object *obj, unsigned int access )
|
|
|
|
{
|
|
|
|
if (access & GENERIC_READ) access |= STANDARD_RIGHTS_READ;
|
|
|
|
if (access & GENERIC_WRITE) access |= STANDARD_RIGHTS_WRITE | FILE_CREATE_PIPE_INSTANCE;
|
|
|
|
if (access & GENERIC_EXECUTE) access |= STANDARD_RIGHTS_EXECUTE;
|
|
|
|
if (access & GENERIC_ALL) access |= STANDARD_RIGHTS_ALL;
|
|
|
|
return access & ~(GENERIC_READ | GENERIC_WRITE | GENERIC_EXECUTE | GENERIC_ALL);
|
|
|
|
}
|
|
|
|
|
2003-05-14 21:22:45 -07:00
|
|
|
static void pipe_server_dump( struct object *obj, int verbose )
|
|
|
|
{
|
|
|
|
struct pipe_server *server = (struct pipe_server *) obj;
|
|
|
|
assert( obj->ops == &pipe_server_ops );
|
2018-08-17 08:41:17 -07:00
|
|
|
fprintf( stderr, "Named pipe server pipe=%p state=%d\n", server->pipe_end.pipe,
|
|
|
|
server->pipe_end.state );
|
2003-05-14 21:22:45 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void pipe_client_dump( struct object *obj, int verbose )
|
2001-07-10 12:16:49 -07:00
|
|
|
{
|
2018-11-23 07:13:24 -07:00
|
|
|
struct pipe_end *client = (struct pipe_end *) obj;
|
2005-02-03 03:48:23 -07:00
|
|
|
assert( obj->ops == &pipe_client_ops );
|
2018-11-23 07:13:24 -07:00
|
|
|
fprintf( stderr, "Named pipe client server=%p\n", client->connection );
|
2001-07-10 12:16:49 -07:00
|
|
|
}
|
|
|
|
|
2005-02-03 03:48:23 -07:00
|
|
|
static void named_pipe_destroy( struct object *obj)
|
|
|
|
{
|
|
|
|
struct named_pipe *pipe = (struct named_pipe *) obj;
|
|
|
|
|
2019-03-11 09:03:23 -07:00
|
|
|
assert( list_empty( &pipe->listeners ) );
|
2005-02-03 03:48:23 -07:00
|
|
|
assert( !pipe->instances );
|
2017-07-04 06:26:19 -07:00
|
|
|
free_async_queue( &pipe->waiters );
|
2003-05-14 21:22:45 -07:00
|
|
|
}
|
|
|
|
|
2017-10-09 05:28:46 -07:00
|
|
|
static struct fd *pipe_end_get_fd( struct object *obj )
|
2003-05-14 21:22:45 -07:00
|
|
|
{
|
2017-10-09 05:28:46 -07:00
|
|
|
struct pipe_end *pipe_end = (struct pipe_end *) obj;
|
|
|
|
return (struct fd *) grab_object( pipe_end->fd );
|
2003-02-18 17:33:32 -07:00
|
|
|
}
|
|
|
|
|
2018-03-28 13:46:32 -07:00
|
|
|
static struct pipe_message *queue_message( struct pipe_end *pipe_end, struct iosb *iosb )
|
|
|
|
{
|
|
|
|
struct pipe_message *message;
|
|
|
|
|
|
|
|
if (!(message = mem_alloc( sizeof(*message) ))) return NULL;
|
|
|
|
message->iosb = (struct iosb *)grab_object( iosb );
|
|
|
|
message->async = NULL;
|
|
|
|
message->read_pos = 0;
|
|
|
|
list_add_tail( &pipe_end->message_queue, &message->entry );
|
|
|
|
return message;
|
|
|
|
}
|
|
|
|
|
2017-03-21 05:03:26 -07:00
|
|
|
static void wake_message( struct pipe_message *message )
|
|
|
|
{
|
|
|
|
struct async *async = message->async;
|
|
|
|
|
|
|
|
message->async = NULL;
|
2018-03-28 13:46:27 -07:00
|
|
|
if (!async) return;
|
|
|
|
|
2017-03-21 05:03:26 -07:00
|
|
|
message->iosb->status = STATUS_SUCCESS;
|
|
|
|
message->iosb->result = message->iosb->in_size;
|
2018-03-28 13:46:27 -07:00
|
|
|
async_terminate( async, message->iosb->result ? STATUS_ALERTED : STATUS_SUCCESS );
|
|
|
|
release_object( async );
|
2017-03-21 05:03:26 -07:00
|
|
|
}
|
|
|
|
|
2017-03-21 05:03:03 -07:00
|
|
|
static void free_message( struct pipe_message *message )
|
|
|
|
{
|
|
|
|
list_remove( &message->entry );
|
|
|
|
if (message->iosb) release_object( message->iosb );
|
|
|
|
free( message );
|
|
|
|
}
|
|
|
|
|
2017-03-15 15:25:25 -07:00
|
|
|
static void pipe_end_disconnect( struct pipe_end *pipe_end, unsigned int status )
|
|
|
|
{
|
|
|
|
struct pipe_end *connection = pipe_end->connection;
|
2017-10-05 05:30:12 -07:00
|
|
|
struct pipe_message *message, *next;
|
|
|
|
struct async *async;
|
2017-03-15 15:25:25 -07:00
|
|
|
|
|
|
|
pipe_end->connection = NULL;
|
|
|
|
|
2018-08-08 13:00:32 -07:00
|
|
|
pipe_end->state = status == STATUS_PIPE_DISCONNECTED
|
|
|
|
? FILE_PIPE_DISCONNECTED_STATE : FILE_PIPE_CLOSING_STATE;
|
2017-11-28 09:35:34 -07:00
|
|
|
fd_async_wake_up( pipe_end->fd, ASYNC_TYPE_WAIT, status );
|
2017-10-05 05:30:12 -07:00
|
|
|
async_wake_up( &pipe_end->read_q, status );
|
|
|
|
LIST_FOR_EACH_ENTRY_SAFE( message, next, &pipe_end->message_queue, struct pipe_message, entry )
|
2017-03-21 05:03:12 -07:00
|
|
|
{
|
2017-10-05 05:30:12 -07:00
|
|
|
async = message->async;
|
|
|
|
if (async || status == STATUS_PIPE_DISCONNECTED) free_message( message );
|
|
|
|
if (!async) continue;
|
|
|
|
async_terminate( async, status );
|
|
|
|
release_object( async );
|
2017-03-21 05:03:12 -07:00
|
|
|
}
|
2017-10-05 05:30:12 -07:00
|
|
|
if (status == STATUS_PIPE_DISCONNECTED) set_fd_signaled( pipe_end->fd, 0 );
|
|
|
|
|
2017-03-15 15:25:25 -07:00
|
|
|
if (connection)
|
|
|
|
{
|
|
|
|
connection->connection = NULL;
|
|
|
|
pipe_end_disconnect( connection, status );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-17 08:41:30 -07:00
|
|
|
static void pipe_end_destroy( struct object *obj )
|
2017-03-21 05:03:03 -07:00
|
|
|
{
|
2018-08-17 08:41:30 -07:00
|
|
|
struct pipe_end *pipe_end = (struct pipe_end *)obj;
|
2017-03-21 05:03:03 -07:00
|
|
|
struct pipe_message *message;
|
|
|
|
|
2018-08-17 08:41:30 -07:00
|
|
|
pipe_end_disconnect( pipe_end, STATUS_PIPE_BROKEN );
|
|
|
|
|
2017-03-21 05:03:03 -07:00
|
|
|
while (!list_empty( &pipe_end->message_queue ))
|
|
|
|
{
|
|
|
|
message = LIST_ENTRY( list_head(&pipe_end->message_queue), struct pipe_message, entry );
|
|
|
|
assert( !message->async );
|
|
|
|
free_message( message );
|
|
|
|
}
|
2017-03-21 05:03:26 -07:00
|
|
|
|
2017-07-04 06:26:19 -07:00
|
|
|
free_async_queue( &pipe_end->read_q );
|
|
|
|
free_async_queue( &pipe_end->write_q );
|
2017-10-09 05:28:46 -07:00
|
|
|
if (pipe_end->fd) release_object( pipe_end->fd );
|
2018-08-16 06:10:33 -07:00
|
|
|
if (pipe_end->pipe) release_object( pipe_end->pipe );
|
2017-03-21 05:03:03 -07:00
|
|
|
}
|
|
|
|
|
2018-08-17 08:41:30 -07:00
|
|
|
static void pipe_server_destroy( struct object *obj )
|
2003-05-14 21:22:45 -07:00
|
|
|
{
|
|
|
|
struct pipe_server *server = (struct pipe_server *)obj;
|
2018-08-16 06:10:33 -07:00
|
|
|
struct named_pipe *pipe = server->pipe_end.pipe;
|
2003-05-14 21:22:45 -07:00
|
|
|
|
|
|
|
assert( obj->ops == &pipe_server_ops );
|
|
|
|
|
2018-08-16 06:10:33 -07:00
|
|
|
assert( pipe->instances );
|
|
|
|
if (!--pipe->instances) unlink_named_object( &pipe->obj );
|
2019-03-11 09:03:23 -07:00
|
|
|
if (server->pipe_end.state == FILE_PIPE_LISTENING_STATE)
|
|
|
|
list_remove( &server->entry );
|
2018-08-16 06:10:33 -07:00
|
|
|
|
2018-08-17 08:41:01 -07:00
|
|
|
free_async_queue( &server->listen_q );
|
2018-08-17 08:41:30 -07:00
|
|
|
pipe_end_destroy( obj );
|
2003-02-18 17:33:32 -07:00
|
|
|
}
|
|
|
|
|
2005-12-05 05:09:35 -07:00
|
|
|
static void named_pipe_device_dump( struct object *obj, int verbose )
|
|
|
|
{
|
2016-01-21 05:08:56 -07:00
|
|
|
fputs( "Named pipe device\n", stderr );
|
2005-12-05 05:09:35 -07:00
|
|
|
}
|
|
|
|
|
2007-12-05 10:16:42 -07:00
|
|
|
static struct object_type *named_pipe_device_get_type( struct object *obj )
|
|
|
|
{
|
|
|
|
static const WCHAR name[] = {'D','e','v','i','c','e'};
|
|
|
|
static const struct unicode_str str = { name, sizeof(name) };
|
|
|
|
return get_object_type( &str );
|
|
|
|
}
|
|
|
|
|
2005-12-05 05:09:35 -07:00
|
|
|
static struct object *named_pipe_device_lookup_name( struct object *obj, struct unicode_str *name,
|
|
|
|
unsigned int attr )
|
|
|
|
{
|
|
|
|
struct named_pipe_device *device = (struct named_pipe_device*)obj;
|
|
|
|
struct object *found;
|
|
|
|
|
|
|
|
assert( obj->ops == &named_pipe_device_ops );
|
|
|
|
assert( device->pipes );
|
|
|
|
|
2016-02-09 04:16:27 -07:00
|
|
|
if (!name) return NULL; /* open the device itself */
|
|
|
|
|
2005-12-05 05:09:35 -07:00
|
|
|
if ((found = find_object( device->pipes, name, attr | OBJ_CASE_INSENSITIVE )))
|
|
|
|
name->len = 0;
|
|
|
|
|
|
|
|
return found;
|
|
|
|
}
|
|
|
|
|
2007-03-22 03:52:40 -07:00
|
|
|
static struct object *named_pipe_device_open_file( struct object *obj, unsigned int access,
|
|
|
|
unsigned int sharing, unsigned int options )
|
|
|
|
{
|
2018-10-29 07:49:47 -07:00
|
|
|
struct named_pipe_device_file *file;
|
|
|
|
|
|
|
|
if (!(file = alloc_object( &named_pipe_device_file_ops ))) return NULL;
|
|
|
|
file->device = (struct named_pipe_device *)grab_object( obj );
|
|
|
|
if (!(file->fd = alloc_pseudo_fd( &named_pipe_device_fd_ops, obj, options )))
|
|
|
|
{
|
|
|
|
release_object( file );
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
allow_fd_caching( file->fd );
|
|
|
|
return &file->obj;
|
2007-03-22 03:52:40 -07:00
|
|
|
}
|
|
|
|
|
2005-12-05 05:09:35 -07:00
|
|
|
static void named_pipe_device_destroy( struct object *obj )
|
|
|
|
{
|
|
|
|
struct named_pipe_device *device = (struct named_pipe_device*)obj;
|
|
|
|
assert( obj->ops == &named_pipe_device_ops );
|
2006-10-09 14:34:36 -07:00
|
|
|
free( device->pipes );
|
2005-12-05 05:09:35 -07:00
|
|
|
}
|
|
|
|
|
2016-07-17 23:34:08 -07:00
|
|
|
struct object *create_named_pipe_device( struct object *root, const struct unicode_str *name )
|
2005-12-05 05:09:35 -07:00
|
|
|
{
|
|
|
|
struct named_pipe_device *dev;
|
|
|
|
|
2016-02-12 06:57:33 -07:00
|
|
|
if ((dev = create_named_object( root, &named_pipe_device_ops, name, 0, NULL )) &&
|
2005-12-05 05:09:35 -07:00
|
|
|
get_error() != STATUS_OBJECT_NAME_EXISTS)
|
|
|
|
{
|
2005-12-12 06:30:06 -07:00
|
|
|
dev->pipes = NULL;
|
2018-10-29 07:49:47 -07:00
|
|
|
if (!(dev->pipes = create_namespace( 7 )))
|
2005-12-05 05:09:35 -07:00
|
|
|
{
|
|
|
|
release_object( dev );
|
|
|
|
dev = NULL;
|
|
|
|
}
|
|
|
|
}
|
2016-07-17 23:34:08 -07:00
|
|
|
return &dev->obj;
|
2005-12-05 05:09:35 -07:00
|
|
|
}
|
|
|
|
|
2018-10-29 07:49:47 -07:00
|
|
|
static void named_pipe_device_file_dump( struct object *obj, int verbose )
|
|
|
|
{
|
|
|
|
struct named_pipe_device_file *file = (struct named_pipe_device_file *)obj;
|
|
|
|
|
|
|
|
fprintf( stderr, "File on named pipe device %p\n", file->device );
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct fd *named_pipe_device_file_get_fd( struct object *obj )
|
|
|
|
{
|
|
|
|
struct named_pipe_device_file *file = (struct named_pipe_device_file *)obj;
|
|
|
|
return (struct fd *)grab_object( file->fd );
|
|
|
|
}
|
|
|
|
|
|
|
|
static enum server_fd_type named_pipe_device_file_get_fd_type( struct fd *fd )
|
|
|
|
{
|
|
|
|
return FD_TYPE_DEVICE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void named_pipe_device_file_destroy( struct object *obj )
|
|
|
|
{
|
|
|
|
struct named_pipe_device_file *file = (struct named_pipe_device_file*)obj;
|
|
|
|
assert( obj->ops == &named_pipe_device_file_ops );
|
|
|
|
if (file->fd) release_object( file->fd );
|
|
|
|
release_object( file->device );
|
|
|
|
}
|
|
|
|
|
2017-10-04 06:18:53 -07:00
|
|
|
static int pipe_end_flush( struct fd *fd, struct async *async )
|
2003-05-14 21:22:45 -07:00
|
|
|
{
|
2017-10-04 06:18:53 -07:00
|
|
|
struct pipe_end *pipe_end = get_fd_user( fd );
|
2003-05-14 21:22:45 -07:00
|
|
|
|
2018-10-20 10:18:37 -07:00
|
|
|
if (!pipe_end->pipe)
|
|
|
|
{
|
|
|
|
set_error( STATUS_PIPE_DISCONNECTED );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-10-04 06:18:53 -07:00
|
|
|
if (pipe_end->connection && !list_empty( &pipe_end->connection->message_queue ))
|
2004-07-15 11:59:58 -07:00
|
|
|
{
|
2017-10-04 06:18:53 -07:00
|
|
|
fd_queue_async( pipe_end->fd, async, ASYNC_TYPE_WAIT );
|
|
|
|
set_error( STATUS_PENDING );
|
2004-07-15 11:59:58 -07:00
|
|
|
}
|
2017-06-26 03:20:20 -07:00
|
|
|
return 1;
|
2017-02-22 06:51:17 -07:00
|
|
|
}
|
|
|
|
|
2018-10-15 04:40:36 -07:00
|
|
|
static void pipe_end_get_file_info( struct fd *fd, obj_handle_t handle, unsigned int info_class )
|
2017-12-21 08:12:12 -07:00
|
|
|
{
|
2018-08-16 06:11:08 -07:00
|
|
|
struct pipe_end *pipe_end = get_fd_user( fd );
|
|
|
|
struct named_pipe *pipe = pipe_end->pipe;
|
|
|
|
|
2017-12-21 08:12:12 -07:00
|
|
|
switch (info_class)
|
|
|
|
{
|
|
|
|
case FileNameInformation:
|
|
|
|
{
|
|
|
|
FILE_NAME_INFORMATION *name_info;
|
|
|
|
data_size_t name_len, reply_size;
|
|
|
|
const WCHAR *name;
|
|
|
|
|
|
|
|
if (get_reply_max_size() < sizeof(*name_info))
|
|
|
|
{
|
|
|
|
set_error( STATUS_INFO_LENGTH_MISMATCH );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-08-16 06:10:33 -07:00
|
|
|
/* FIXME: We should be able to return on unlinked pipe */
|
2018-10-23 08:45:06 -07:00
|
|
|
if (!pipe || !(name = get_object_name( &pipe->obj, &name_len )))
|
2018-08-16 06:10:33 -07:00
|
|
|
{
|
|
|
|
set_error( STATUS_PIPE_DISCONNECTED );
|
|
|
|
return;
|
|
|
|
}
|
2018-10-23 08:45:06 -07:00
|
|
|
|
2017-12-21 08:12:12 -07:00
|
|
|
reply_size = offsetof( FILE_NAME_INFORMATION, FileName[name_len/sizeof(WCHAR) + 1] );
|
|
|
|
if (reply_size > get_reply_max_size())
|
|
|
|
{
|
|
|
|
reply_size = get_reply_max_size();
|
|
|
|
set_error( STATUS_BUFFER_OVERFLOW );
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(name_info = set_reply_data_size( reply_size ))) return;
|
|
|
|
name_info->FileNameLength = name_len + sizeof(WCHAR);
|
|
|
|
name_info->FileName[0] = '\\';
|
|
|
|
reply_size -= offsetof( FILE_NAME_INFORMATION, FileName[1] );
|
|
|
|
if (reply_size) memcpy( &name_info->FileName[1], name, reply_size );
|
|
|
|
break;
|
|
|
|
}
|
2018-10-15 04:41:00 -07:00
|
|
|
case FilePipeInformation:
|
|
|
|
{
|
|
|
|
FILE_PIPE_INFORMATION *pipe_info;
|
|
|
|
|
|
|
|
if (!(get_handle_access( current->process, handle) & FILE_READ_ATTRIBUTES))
|
|
|
|
{
|
|
|
|
set_error( STATUS_ACCESS_DENIED );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (get_reply_max_size() < sizeof(*pipe_info))
|
|
|
|
{
|
|
|
|
set_error( STATUS_INFO_LENGTH_MISMATCH );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-10-23 08:45:06 -07:00
|
|
|
if (!pipe)
|
|
|
|
{
|
|
|
|
set_error( STATUS_PIPE_DISCONNECTED );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-10-15 04:41:00 -07:00
|
|
|
if (!(pipe_info = set_reply_data_size( sizeof(*pipe_info) ))) return;
|
|
|
|
pipe_info->ReadMode = (pipe_end->flags & NAMED_PIPE_MESSAGE_STREAM_READ)
|
|
|
|
? FILE_PIPE_MESSAGE_MODE : FILE_PIPE_BYTE_STREAM_MODE;
|
|
|
|
pipe_info->CompletionMode = (pipe_end->flags & NAMED_PIPE_NONBLOCKING_MODE)
|
|
|
|
? FILE_PIPE_COMPLETE_OPERATION : FILE_PIPE_QUEUE_OPERATION;
|
|
|
|
break;
|
|
|
|
}
|
2018-10-15 04:40:36 -07:00
|
|
|
case FilePipeLocalInformation:
|
|
|
|
{
|
|
|
|
FILE_PIPE_LOCAL_INFORMATION *pipe_info;
|
|
|
|
|
|
|
|
if (!(get_handle_access( current->process, handle) & FILE_READ_ATTRIBUTES))
|
|
|
|
{
|
|
|
|
set_error( STATUS_ACCESS_DENIED );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (get_reply_max_size() < sizeof(*pipe_info))
|
|
|
|
{
|
|
|
|
set_error( STATUS_INFO_LENGTH_MISMATCH );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-10-23 08:45:06 -07:00
|
|
|
if (!pipe)
|
|
|
|
{
|
|
|
|
set_error( STATUS_PIPE_DISCONNECTED );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-10-15 04:40:36 -07:00
|
|
|
if (!(pipe_info = set_reply_data_size( sizeof(*pipe_info) ))) return;
|
2018-11-23 07:13:07 -07:00
|
|
|
pipe_info->NamedPipeType = pipe->message_mode;
|
2018-10-15 04:40:36 -07:00
|
|
|
switch (pipe->sharing)
|
|
|
|
{
|
|
|
|
case FILE_SHARE_READ:
|
|
|
|
pipe_info->NamedPipeConfiguration = FILE_PIPE_OUTBOUND;
|
|
|
|
break;
|
|
|
|
case FILE_SHARE_WRITE:
|
|
|
|
pipe_info->NamedPipeConfiguration = FILE_PIPE_INBOUND;
|
|
|
|
break;
|
|
|
|
case FILE_SHARE_READ | FILE_SHARE_WRITE:
|
|
|
|
pipe_info->NamedPipeConfiguration = FILE_PIPE_FULL_DUPLEX;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
pipe_info->MaximumInstances = pipe->maxinstances;
|
|
|
|
pipe_info->CurrentInstances = pipe->instances;
|
|
|
|
pipe_info->InboundQuota = pipe->insize;
|
|
|
|
pipe_info->ReadDataAvailable = 0; /* FIXME */
|
|
|
|
pipe_info->OutboundQuota = pipe->outsize;
|
|
|
|
pipe_info->WriteQuotaAvailable = 0; /* FIXME */
|
2018-10-15 04:41:08 -07:00
|
|
|
pipe_info->NamedPipeState = pipe_end->state;
|
2018-10-15 04:40:36 -07:00
|
|
|
pipe_info->NamedPipeEnd = pipe_end->obj.ops == &pipe_server_ops
|
|
|
|
? FILE_PIPE_SERVER_END : FILE_PIPE_CLIENT_END;
|
|
|
|
break;
|
|
|
|
}
|
2017-12-21 08:12:12 -07:00
|
|
|
default:
|
2018-10-23 08:45:06 -07:00
|
|
|
default_fd_get_file_info( fd, handle, info_class );
|
2017-12-21 08:12:12 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-16 06:10:55 -07:00
|
|
|
static struct security_descriptor *pipe_end_get_sd( struct object *obj )
|
2018-02-26 11:25:08 -07:00
|
|
|
{
|
2018-08-16 06:10:55 -07:00
|
|
|
struct pipe_end *pipe_end = (struct pipe_end *) obj;
|
|
|
|
if (pipe_end->pipe) return default_get_sd( &pipe_end->pipe->obj );
|
2018-02-26 11:25:08 -07:00
|
|
|
set_error( STATUS_PIPE_DISCONNECTED );
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2018-08-16 06:10:55 -07:00
|
|
|
static int pipe_end_set_sd( struct object *obj, const struct security_descriptor *sd,
|
|
|
|
unsigned int set_info )
|
2018-02-26 11:25:08 -07:00
|
|
|
{
|
2018-08-16 06:10:55 -07:00
|
|
|
struct pipe_end *pipe_end = (struct pipe_end *) obj;
|
|
|
|
if (pipe_end->pipe) return default_set_sd( &pipe_end->pipe->obj, sd, set_info );
|
2018-02-26 11:25:08 -07:00
|
|
|
set_error( STATUS_PIPE_DISCONNECTED );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-10-02 07:42:24 -07:00
|
|
|
static void pipe_end_get_volume_info( struct fd *fd, unsigned int info_class )
|
|
|
|
{
|
|
|
|
switch (info_class)
|
|
|
|
{
|
|
|
|
case FileFsDeviceInformation:
|
|
|
|
{
|
|
|
|
static const FILE_FS_DEVICE_INFORMATION device_info =
|
|
|
|
{
|
|
|
|
FILE_DEVICE_NAMED_PIPE,
|
|
|
|
FILE_DEVICE_ALLOW_APPCONTAINER_TRAVERSAL
|
|
|
|
};
|
|
|
|
if (get_reply_max_size() >= sizeof(device_info))
|
|
|
|
set_reply_data( &device_info, sizeof(device_info) );
|
|
|
|
else
|
|
|
|
set_error( STATUS_BUFFER_TOO_SMALL );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
set_error( STATUS_NOT_IMPLEMENTED );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-23 07:41:43 -07:00
|
|
|
static void message_queue_read( struct pipe_end *pipe_end, struct iosb *iosb )
|
|
|
|
{
|
|
|
|
struct pipe_message *message;
|
|
|
|
|
2017-03-26 03:52:39 -07:00
|
|
|
if (pipe_end->flags & NAMED_PIPE_MESSAGE_STREAM_READ)
|
2017-03-23 07:41:43 -07:00
|
|
|
{
|
2017-03-26 03:52:39 -07:00
|
|
|
message = LIST_ENTRY( list_head(&pipe_end->message_queue), struct pipe_message, entry );
|
|
|
|
iosb->out_size = min( iosb->out_size, message->iosb->in_size - message->read_pos );
|
|
|
|
iosb->status = message->read_pos + iosb->out_size < message->iosb->in_size
|
|
|
|
? STATUS_BUFFER_OVERFLOW : STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
data_size_t avail = 0;
|
|
|
|
LIST_FOR_EACH_ENTRY( message, &pipe_end->message_queue, struct pipe_message, entry )
|
|
|
|
{
|
|
|
|
avail += message->iosb->in_size - message->read_pos;
|
|
|
|
if (avail >= iosb->out_size) break;
|
|
|
|
}
|
|
|
|
iosb->out_size = min( iosb->out_size, avail );
|
|
|
|
iosb->status = STATUS_SUCCESS;
|
2017-03-23 07:41:43 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
message = LIST_ENTRY( list_head(&pipe_end->message_queue), struct pipe_message, entry );
|
|
|
|
if (!message->read_pos && message->iosb->in_size == iosb->out_size) /* fast path */
|
|
|
|
{
|
|
|
|
iosb->out_data = message->iosb->in_data;
|
|
|
|
message->iosb->in_data = NULL;
|
|
|
|
wake_message( message );
|
|
|
|
free_message( message );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
data_size_t write_pos = 0, writing;
|
|
|
|
char *buf = NULL;
|
|
|
|
|
|
|
|
if (iosb->out_size && !(buf = iosb->out_data = malloc( iosb->out_size )))
|
|
|
|
{
|
|
|
|
iosb->out_size = 0;
|
|
|
|
iosb->status = STATUS_NO_MEMORY;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
message = LIST_ENTRY( list_head(&pipe_end->message_queue), struct pipe_message, entry );
|
|
|
|
writing = min( iosb->out_size - write_pos, message->iosb->in_size - message->read_pos );
|
|
|
|
if (writing) memcpy( buf + write_pos, (const char *)message->iosb->in_data + message->read_pos, writing );
|
|
|
|
write_pos += writing;
|
|
|
|
message->read_pos += writing;
|
|
|
|
if (message->read_pos == message->iosb->in_size)
|
|
|
|
{
|
|
|
|
wake_message(message);
|
|
|
|
free_message(message);
|
|
|
|
}
|
|
|
|
} while (write_pos < iosb->out_size);
|
|
|
|
}
|
|
|
|
iosb->result = iosb->out_size;
|
|
|
|
}
|
|
|
|
|
2017-03-21 05:03:26 -07:00
|
|
|
/* We call async_terminate in our reselect implementation, which causes recursive reselect.
|
|
|
|
* We're not interested in such reselect calls, so we ignore them. */
|
|
|
|
static int ignore_reselect;
|
|
|
|
|
2017-03-23 07:41:43 -07:00
|
|
|
static void reselect_write_queue( struct pipe_end *pipe_end );
|
|
|
|
|
|
|
|
static void reselect_read_queue( struct pipe_end *pipe_end )
|
|
|
|
{
|
|
|
|
struct async *async;
|
|
|
|
struct iosb *iosb;
|
|
|
|
int read_done = 0;
|
|
|
|
|
|
|
|
ignore_reselect = 1;
|
2017-07-04 06:26:19 -07:00
|
|
|
while (!list_empty( &pipe_end->message_queue ) && (async = find_pending_async( &pipe_end->read_q )))
|
2017-03-23 07:41:43 -07:00
|
|
|
{
|
|
|
|
iosb = async_get_iosb( async );
|
|
|
|
message_queue_read( pipe_end, iosb );
|
|
|
|
async_terminate( async, iosb->result ? STATUS_ALERTED : iosb->status );
|
|
|
|
release_object( async );
|
|
|
|
release_object( iosb );
|
|
|
|
read_done = 1;
|
|
|
|
}
|
|
|
|
ignore_reselect = 0;
|
|
|
|
|
|
|
|
if (pipe_end->connection)
|
|
|
|
{
|
|
|
|
if (list_empty( &pipe_end->message_queue ))
|
|
|
|
fd_async_wake_up( pipe_end->connection->fd, ASYNC_TYPE_WAIT, STATUS_SUCCESS );
|
|
|
|
else if (read_done)
|
|
|
|
reselect_write_queue( pipe_end->connection );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-21 05:03:26 -07:00
|
|
|
static void reselect_write_queue( struct pipe_end *pipe_end )
|
|
|
|
{
|
|
|
|
struct pipe_message *message, *next;
|
|
|
|
struct pipe_end *reader = pipe_end->connection;
|
|
|
|
data_size_t avail = 0;
|
|
|
|
|
|
|
|
if (!reader) return;
|
|
|
|
|
|
|
|
ignore_reselect = 1;
|
|
|
|
|
|
|
|
LIST_FOR_EACH_ENTRY_SAFE( message, next, &reader->message_queue, struct pipe_message, entry )
|
|
|
|
{
|
|
|
|
if (message->async && message->iosb->status != STATUS_PENDING)
|
|
|
|
{
|
|
|
|
release_object( message->async );
|
|
|
|
message->async = NULL;
|
|
|
|
free_message( message );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
avail += message->iosb->in_size - message->read_pos;
|
2018-03-28 13:46:27 -07:00
|
|
|
if (message->async && (avail <= reader->buffer_size || !message->iosb->in_size))
|
2017-03-21 05:03:26 -07:00
|
|
|
wake_message( message );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ignore_reselect = 0;
|
2017-03-23 07:42:03 -07:00
|
|
|
reselect_read_queue( reader );
|
|
|
|
}
|
|
|
|
|
2017-06-26 03:17:36 -07:00
|
|
|
static int pipe_end_read( struct fd *fd, struct async *async, file_pos_t pos )
|
2017-03-23 07:42:03 -07:00
|
|
|
{
|
|
|
|
struct pipe_end *pipe_end = get_fd_user( fd );
|
|
|
|
|
2018-08-08 13:00:48 -07:00
|
|
|
switch (pipe_end->state)
|
2017-03-23 07:42:03 -07:00
|
|
|
{
|
2018-08-08 13:00:48 -07:00
|
|
|
case FILE_PIPE_CONNECTED_STATE:
|
2019-10-16 05:50:02 -07:00
|
|
|
if ((pipe_end->flags & NAMED_PIPE_NONBLOCKING_MODE) && list_empty( &pipe_end->message_queue ))
|
|
|
|
{
|
|
|
|
set_error( STATUS_PIPE_EMPTY );
|
|
|
|
return 0;
|
|
|
|
}
|
2018-08-08 13:00:48 -07:00
|
|
|
break;
|
|
|
|
case FILE_PIPE_DISCONNECTED_STATE:
|
|
|
|
set_error( STATUS_PIPE_DISCONNECTED );
|
|
|
|
return 0;
|
|
|
|
case FILE_PIPE_LISTENING_STATE:
|
|
|
|
set_error( STATUS_PIPE_LISTENING );
|
|
|
|
return 0;
|
|
|
|
case FILE_PIPE_CLOSING_STATE:
|
|
|
|
if (!list_empty( &pipe_end->message_queue )) break;
|
2017-03-23 07:42:03 -07:00
|
|
|
set_error( STATUS_PIPE_BROKEN );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-07-04 06:26:19 -07:00
|
|
|
queue_async( &pipe_end->read_q, async );
|
2017-03-23 07:42:03 -07:00
|
|
|
reselect_read_queue( pipe_end );
|
|
|
|
set_error( STATUS_PENDING );
|
2017-06-26 03:17:36 -07:00
|
|
|
return 1;
|
2017-03-21 05:03:26 -07:00
|
|
|
}
|
|
|
|
|
2017-06-26 03:18:23 -07:00
|
|
|
static int pipe_end_write( struct fd *fd, struct async *async, file_pos_t pos )
|
2017-03-21 05:03:39 -07:00
|
|
|
{
|
2018-03-28 13:46:32 -07:00
|
|
|
struct pipe_end *pipe_end = get_fd_user( fd );
|
2017-03-21 05:03:39 -07:00
|
|
|
struct pipe_message *message;
|
2018-03-28 13:46:32 -07:00
|
|
|
struct iosb *iosb;
|
2017-03-21 05:03:39 -07:00
|
|
|
|
2018-08-08 13:00:55 -07:00
|
|
|
switch (pipe_end->state)
|
2017-03-21 05:03:39 -07:00
|
|
|
{
|
2018-08-08 13:00:55 -07:00
|
|
|
case FILE_PIPE_CONNECTED_STATE:
|
|
|
|
break;
|
|
|
|
case FILE_PIPE_DISCONNECTED_STATE:
|
2017-03-21 05:03:39 -07:00
|
|
|
set_error( STATUS_PIPE_DISCONNECTED );
|
|
|
|
return 0;
|
2018-08-08 13:00:55 -07:00
|
|
|
case FILE_PIPE_LISTENING_STATE:
|
|
|
|
set_error( STATUS_PIPE_LISTENING );
|
|
|
|
return 0;
|
|
|
|
case FILE_PIPE_CLOSING_STATE:
|
|
|
|
set_error( STATUS_PIPE_CLOSING );
|
|
|
|
return 0;
|
2017-03-21 05:03:39 -07:00
|
|
|
}
|
|
|
|
|
2018-11-23 07:13:07 -07:00
|
|
|
if (!pipe_end->pipe->message_mode && !get_req_data_size()) return 1;
|
2017-10-04 06:18:02 -07:00
|
|
|
|
2018-03-28 13:46:32 -07:00
|
|
|
iosb = async_get_iosb( async );
|
|
|
|
message = queue_message( pipe_end->connection, iosb );
|
|
|
|
release_object( iosb );
|
|
|
|
if (!message) return 0;
|
2017-03-21 05:03:39 -07:00
|
|
|
|
2018-03-28 13:46:32 -07:00
|
|
|
message->async = (struct async *)grab_object( async );
|
|
|
|
queue_async( &pipe_end->write_q, async );
|
|
|
|
reselect_write_queue( pipe_end );
|
2017-03-21 05:03:39 -07:00
|
|
|
set_error( STATUS_PENDING );
|
2017-06-26 03:18:23 -07:00
|
|
|
return 1;
|
2017-03-21 05:03:39 -07:00
|
|
|
}
|
|
|
|
|
2017-03-21 05:03:26 -07:00
|
|
|
static void pipe_end_reselect_async( struct fd *fd, struct async_queue *queue )
|
|
|
|
{
|
|
|
|
struct pipe_end *pipe_end = get_fd_user( fd );
|
|
|
|
|
|
|
|
if (ignore_reselect) return;
|
|
|
|
|
2017-10-05 05:30:12 -07:00
|
|
|
if (&pipe_end->write_q == queue)
|
2017-03-21 05:03:26 -07:00
|
|
|
reselect_write_queue( pipe_end );
|
2017-07-04 06:26:19 -07:00
|
|
|
else if (&pipe_end->read_q == queue)
|
2017-03-23 07:41:43 -07:00
|
|
|
reselect_read_queue( pipe_end );
|
2017-03-21 05:03:26 -07:00
|
|
|
}
|
|
|
|
|
2017-04-24 06:18:14 -07:00
|
|
|
static enum server_fd_type pipe_end_get_fd_type( struct fd *fd )
|
2005-06-08 12:11:46 -07:00
|
|
|
{
|
2006-11-20 06:14:04 -07:00
|
|
|
return FD_TYPE_PIPE;
|
2001-10-05 12:45:45 -07:00
|
|
|
}
|
|
|
|
|
2017-06-26 03:20:10 -07:00
|
|
|
static int pipe_end_peek( struct pipe_end *pipe_end )
|
2017-03-21 05:03:55 -07:00
|
|
|
{
|
|
|
|
unsigned reply_size = get_reply_max_size();
|
|
|
|
FILE_PIPE_PEEK_BUFFER *buffer;
|
|
|
|
struct pipe_message *message;
|
|
|
|
data_size_t avail = 0;
|
2017-05-21 06:53:51 -07:00
|
|
|
data_size_t message_length = 0;
|
2017-03-21 05:03:55 -07:00
|
|
|
|
|
|
|
if (reply_size < offsetof( FILE_PIPE_PEEK_BUFFER, Data ))
|
|
|
|
{
|
|
|
|
set_error( STATUS_INFO_LENGTH_MISMATCH );
|
2017-06-26 03:20:10 -07:00
|
|
|
return 0;
|
2017-03-21 05:03:55 -07:00
|
|
|
}
|
|
|
|
reply_size -= offsetof( FILE_PIPE_PEEK_BUFFER, Data );
|
|
|
|
|
2018-08-08 13:00:41 -07:00
|
|
|
switch (pipe_end->state)
|
2017-10-04 06:17:35 -07:00
|
|
|
{
|
2018-08-08 13:00:41 -07:00
|
|
|
case FILE_PIPE_CONNECTED_STATE:
|
|
|
|
break;
|
|
|
|
case FILE_PIPE_CLOSING_STATE:
|
|
|
|
if (!list_empty( &pipe_end->message_queue )) break;
|
2017-10-04 06:17:35 -07:00
|
|
|
set_error( STATUS_PIPE_BROKEN );
|
|
|
|
return 0;
|
2018-08-08 13:00:41 -07:00
|
|
|
default:
|
2018-10-20 10:18:37 -07:00
|
|
|
set_error( pipe_end->pipe ? STATUS_INVALID_PIPE_STATE : STATUS_PIPE_DISCONNECTED );
|
2018-08-08 13:00:41 -07:00
|
|
|
return 0;
|
2017-10-04 06:17:35 -07:00
|
|
|
}
|
|
|
|
|
2017-03-21 05:03:55 -07:00
|
|
|
LIST_FOR_EACH_ENTRY( message, &pipe_end->message_queue, struct pipe_message, entry )
|
|
|
|
avail += message->iosb->in_size - message->read_pos;
|
2017-10-04 06:17:52 -07:00
|
|
|
reply_size = min( reply_size, avail );
|
2017-03-21 05:03:55 -07:00
|
|
|
|
2018-11-23 07:13:07 -07:00
|
|
|
if (avail && pipe_end->pipe->message_mode)
|
2017-03-21 05:03:55 -07:00
|
|
|
{
|
|
|
|
message = LIST_ENTRY( list_head(&pipe_end->message_queue), struct pipe_message, entry );
|
2017-05-21 06:53:51 -07:00
|
|
|
message_length = message->iosb->in_size - message->read_pos;
|
|
|
|
reply_size = min( reply_size, message_length );
|
2017-03-21 05:03:55 -07:00
|
|
|
}
|
|
|
|
|
2017-06-26 03:20:10 -07:00
|
|
|
if (!(buffer = set_reply_data_size( offsetof( FILE_PIPE_PEEK_BUFFER, Data[reply_size] )))) return 0;
|
2018-08-08 13:00:32 -07:00
|
|
|
buffer->NamedPipeState = pipe_end->state;
|
2017-03-21 05:03:55 -07:00
|
|
|
buffer->ReadDataAvailable = avail;
|
|
|
|
buffer->NumberOfMessages = 0; /* FIXME */
|
2017-05-21 06:53:51 -07:00
|
|
|
buffer->MessageLength = message_length;
|
2017-10-04 06:17:52 -07:00
|
|
|
|
|
|
|
if (reply_size)
|
|
|
|
{
|
|
|
|
data_size_t write_pos = 0, writing;
|
|
|
|
LIST_FOR_EACH_ENTRY( message, &pipe_end->message_queue, struct pipe_message, entry )
|
|
|
|
{
|
|
|
|
writing = min( reply_size - write_pos, message->iosb->in_size - message->read_pos );
|
|
|
|
memcpy( buffer->Data + write_pos, (const char *)message->iosb->in_data + message->read_pos,
|
|
|
|
writing );
|
|
|
|
write_pos += writing;
|
|
|
|
if (write_pos == reply_size) break;
|
|
|
|
}
|
|
|
|
}
|
2018-10-20 10:18:06 -07:00
|
|
|
if (message_length > reply_size) set_error( STATUS_BUFFER_OVERFLOW );
|
2017-06-26 03:20:10 -07:00
|
|
|
return 1;
|
2017-03-21 05:03:55 -07:00
|
|
|
}
|
|
|
|
|
2018-03-28 13:46:38 -07:00
|
|
|
static int pipe_end_transceive( struct pipe_end *pipe_end, struct async *async )
|
|
|
|
{
|
|
|
|
struct pipe_message *message;
|
|
|
|
struct iosb *iosb;
|
|
|
|
|
2018-08-08 13:01:02 -07:00
|
|
|
if (!pipe_end->connection)
|
2018-03-28 13:46:38 -07:00
|
|
|
{
|
2018-10-20 10:18:37 -07:00
|
|
|
set_error( pipe_end->pipe ? STATUS_INVALID_PIPE_STATE : STATUS_PIPE_DISCONNECTED );
|
2018-03-28 13:46:38 -07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-11-23 07:13:07 -07:00
|
|
|
if (!(pipe_end->flags & NAMED_PIPE_MESSAGE_STREAM_READ))
|
2018-03-28 13:46:38 -07:00
|
|
|
{
|
2018-08-08 13:01:02 -07:00
|
|
|
set_error( STATUS_INVALID_READ_MODE );
|
2018-03-28 13:46:38 -07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* not allowed if we already have read data buffered */
|
|
|
|
if (!list_empty( &pipe_end->message_queue ))
|
|
|
|
{
|
|
|
|
set_error( STATUS_PIPE_BUSY );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
iosb = async_get_iosb( async );
|
|
|
|
/* ignore output buffer copy transferred because of METHOD_NEITHER */
|
|
|
|
iosb->in_size -= iosb->out_size;
|
|
|
|
/* transaction never blocks on write, so just queue a message without async */
|
|
|
|
message = queue_message( pipe_end->connection, iosb );
|
|
|
|
release_object( iosb );
|
|
|
|
if (!message) return 0;
|
|
|
|
reselect_read_queue( pipe_end->connection );
|
|
|
|
|
|
|
|
queue_async( &pipe_end->read_q, async );
|
|
|
|
reselect_read_queue( pipe_end );
|
|
|
|
set_error( STATUS_PENDING );
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2018-04-11 05:32:56 -07:00
|
|
|
static int pipe_end_get_connection_attribute( struct pipe_end *pipe_end )
|
|
|
|
{
|
|
|
|
const char *attr = get_req_data();
|
|
|
|
data_size_t value_size, attr_size = get_req_data_size();
|
|
|
|
void *value;
|
|
|
|
|
|
|
|
if (attr_size == sizeof("ClientProcessId") && !memcmp( attr, "ClientProcessId", attr_size ))
|
|
|
|
{
|
|
|
|
value = &pipe_end->client_pid;
|
|
|
|
value_size = sizeof(pipe_end->client_pid);
|
|
|
|
}
|
|
|
|
else if (attr_size == sizeof("ServerProcessId") && !memcmp( attr, "ServerProcessId", attr_size ))
|
|
|
|
{
|
|
|
|
value = &pipe_end->server_pid;
|
|
|
|
value_size = sizeof(pipe_end->server_pid);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
set_error( STATUS_ILLEGAL_FUNCTION );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (get_reply_max_size() < value_size)
|
|
|
|
{
|
|
|
|
set_error( STATUS_INFO_LENGTH_MISMATCH );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
set_reply_data( value, value_size );
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2018-03-28 13:46:38 -07:00
|
|
|
static int pipe_end_ioctl( struct pipe_end *pipe_end, ioctl_code_t code, struct async *async )
|
|
|
|
{
|
|
|
|
switch(code)
|
|
|
|
{
|
2018-04-11 05:32:56 -07:00
|
|
|
case FSCTL_PIPE_GET_CONNECTION_ATTRIBUTE:
|
|
|
|
return pipe_end_get_connection_attribute( pipe_end );
|
|
|
|
|
2018-03-28 13:46:38 -07:00
|
|
|
case FSCTL_PIPE_PEEK:
|
|
|
|
return pipe_end_peek( pipe_end );
|
|
|
|
|
|
|
|
case FSCTL_PIPE_TRANSCEIVE:
|
|
|
|
return pipe_end_transceive( pipe_end, async );
|
|
|
|
|
|
|
|
default:
|
|
|
|
return default_fd_ioctl( pipe_end->fd, code, async );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-26 03:20:10 -07:00
|
|
|
static int pipe_server_ioctl( struct fd *fd, ioctl_code_t code, struct async *async )
|
2007-04-16 05:51:29 -07:00
|
|
|
{
|
|
|
|
struct pipe_server *server = get_fd_user( fd );
|
|
|
|
|
|
|
|
switch(code)
|
|
|
|
{
|
2007-04-18 07:26:37 -07:00
|
|
|
case FSCTL_PIPE_LISTEN:
|
2018-08-17 08:40:44 -07:00
|
|
|
switch(server->pipe_end.state)
|
2007-04-18 07:26:37 -07:00
|
|
|
{
|
2018-08-17 08:40:44 -07:00
|
|
|
case FILE_PIPE_LISTENING_STATE:
|
2019-03-11 09:03:23 -07:00
|
|
|
break;
|
2018-08-17 08:40:44 -07:00
|
|
|
case FILE_PIPE_DISCONNECTED_STATE:
|
2019-03-11 09:03:23 -07:00
|
|
|
server->pipe_end.state = FILE_PIPE_LISTENING_STATE;
|
|
|
|
list_add_tail( &server->pipe_end.pipe->listeners, &server->entry );
|
2007-04-18 07:26:37 -07:00
|
|
|
break;
|
2018-08-17 08:40:44 -07:00
|
|
|
case FILE_PIPE_CONNECTED_STATE:
|
|
|
|
set_error( STATUS_PIPE_CONNECTED );
|
|
|
|
return 0;
|
|
|
|
case FILE_PIPE_CLOSING_STATE:
|
|
|
|
set_error( STATUS_PIPE_CLOSING );
|
|
|
|
return 0;
|
2007-04-18 07:26:37 -07:00
|
|
|
}
|
2018-08-17 08:40:44 -07:00
|
|
|
|
2018-08-17 08:41:01 -07:00
|
|
|
queue_async( &server->listen_q, async );
|
2018-08-17 08:40:44 -07:00
|
|
|
async_wake_up( &server->pipe_end.pipe->waiters, STATUS_SUCCESS );
|
|
|
|
set_error( STATUS_PENDING );
|
|
|
|
return 1;
|
2007-04-18 07:26:37 -07:00
|
|
|
|
2007-04-16 05:51:29 -07:00
|
|
|
case FSCTL_PIPE_DISCONNECT:
|
2018-08-17 08:40:55 -07:00
|
|
|
switch(server->pipe_end.state)
|
2007-04-16 05:51:29 -07:00
|
|
|
{
|
2018-08-17 08:40:55 -07:00
|
|
|
case FILE_PIPE_CONNECTED_STATE:
|
2018-08-16 06:10:33 -07:00
|
|
|
/* dump the client connection - all data is lost */
|
2018-08-17 08:40:55 -07:00
|
|
|
assert( server->pipe_end.connection );
|
2018-08-16 06:10:33 -07:00
|
|
|
release_object( server->pipe_end.connection->pipe );
|
|
|
|
server->pipe_end.connection->pipe = NULL;
|
2007-04-16 05:51:29 -07:00
|
|
|
break;
|
2018-08-17 08:40:55 -07:00
|
|
|
case FILE_PIPE_CLOSING_STATE:
|
2007-04-16 05:51:29 -07:00
|
|
|
break;
|
2018-08-17 08:40:55 -07:00
|
|
|
case FILE_PIPE_LISTENING_STATE:
|
2007-04-18 07:26:37 -07:00
|
|
|
set_error( STATUS_PIPE_LISTENING );
|
2017-06-26 03:20:10 -07:00
|
|
|
return 0;
|
2018-08-17 08:40:55 -07:00
|
|
|
case FILE_PIPE_DISCONNECTED_STATE:
|
2007-04-18 07:26:37 -07:00
|
|
|
set_error( STATUS_PIPE_DISCONNECTED );
|
2017-06-26 03:20:10 -07:00
|
|
|
return 0;
|
2007-04-16 05:51:29 -07:00
|
|
|
}
|
2018-08-17 08:40:55 -07:00
|
|
|
|
|
|
|
pipe_end_disconnect( &server->pipe_end, STATUS_PIPE_DISCONNECTED );
|
2017-06-26 03:20:10 -07:00
|
|
|
return 1;
|
2007-04-18 07:26:37 -07:00
|
|
|
|
2017-03-21 05:03:55 -07:00
|
|
|
default:
|
2018-03-28 13:46:38 -07:00
|
|
|
return pipe_end_ioctl( &server->pipe_end, code, async );
|
2017-03-21 05:03:55 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-26 03:20:10 -07:00
|
|
|
static int pipe_client_ioctl( struct fd *fd, ioctl_code_t code, struct async *async )
|
2017-03-21 05:03:55 -07:00
|
|
|
{
|
2018-11-23 07:13:24 -07:00
|
|
|
struct pipe_end *client = get_fd_user( fd );
|
2017-03-21 05:03:55 -07:00
|
|
|
|
|
|
|
switch(code)
|
|
|
|
{
|
2017-10-10 09:40:43 -07:00
|
|
|
case FSCTL_PIPE_LISTEN:
|
|
|
|
set_error( STATUS_ILLEGAL_FUNCTION );
|
|
|
|
return 0;
|
|
|
|
|
2007-04-16 05:51:29 -07:00
|
|
|
default:
|
2018-11-23 07:13:24 -07:00
|
|
|
return pipe_end_ioctl( client, code, async );
|
2007-04-16 05:51:29 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-16 06:10:33 -07:00
|
|
|
static void init_pipe_end( struct pipe_end *pipe_end, struct named_pipe *pipe,
|
|
|
|
unsigned int pipe_flags, data_size_t buffer_size )
|
2017-02-22 06:51:06 -07:00
|
|
|
{
|
2018-08-16 06:10:33 -07:00
|
|
|
pipe_end->pipe = (struct named_pipe *)grab_object( pipe );
|
2017-02-22 06:51:06 -07:00
|
|
|
pipe_end->fd = NULL;
|
|
|
|
pipe_end->flags = pipe_flags;
|
2017-03-15 15:25:25 -07:00
|
|
|
pipe_end->connection = NULL;
|
2017-03-15 15:25:31 -07:00
|
|
|
pipe_end->buffer_size = buffer_size;
|
2017-07-04 06:26:19 -07:00
|
|
|
init_async_queue( &pipe_end->read_q );
|
|
|
|
init_async_queue( &pipe_end->write_q );
|
2017-03-21 05:03:03 -07:00
|
|
|
list_init( &pipe_end->message_queue );
|
2017-02-22 06:51:06 -07:00
|
|
|
}
|
|
|
|
|
2014-08-11 06:35:50 -07:00
|
|
|
static struct pipe_server *create_pipe_server( struct named_pipe *pipe, unsigned int options,
|
|
|
|
unsigned int pipe_flags )
|
2001-07-10 12:16:49 -07:00
|
|
|
{
|
2003-05-14 21:22:45 -07:00
|
|
|
struct pipe_server *server;
|
2001-07-10 12:16:49 -07:00
|
|
|
|
2003-05-14 21:22:45 -07:00
|
|
|
server = alloc_object( &pipe_server_ops );
|
2005-06-10 12:54:46 -07:00
|
|
|
if (!server)
|
2001-07-10 12:16:49 -07:00
|
|
|
return NULL;
|
|
|
|
|
2005-06-08 12:11:46 -07:00
|
|
|
server->options = options;
|
2018-08-16 06:10:33 -07:00
|
|
|
init_pipe_end( &server->pipe_end, pipe, pipe_flags, pipe->insize );
|
2018-08-08 13:00:32 -07:00
|
|
|
server->pipe_end.state = FILE_PIPE_LISTENING_STATE;
|
2018-04-11 05:32:56 -07:00
|
|
|
server->pipe_end.server_pid = get_process_id( current->process );
|
2018-11-23 07:13:32 -07:00
|
|
|
init_async_queue( &server->listen_q );
|
2001-07-10 12:16:49 -07:00
|
|
|
|
2019-03-11 09:03:23 -07:00
|
|
|
list_add_tail( &pipe->listeners, &server->entry );
|
2017-10-09 05:28:46 -07:00
|
|
|
if (!(server->pipe_end.fd = alloc_pseudo_fd( &pipe_server_fd_ops, &server->pipe_end.obj, options )))
|
2007-04-18 07:26:37 -07:00
|
|
|
{
|
|
|
|
release_object( server );
|
2007-05-08 12:13:14 -07:00
|
|
|
return NULL;
|
2007-04-18 07:26:37 -07:00
|
|
|
}
|
2018-08-08 13:01:20 -07:00
|
|
|
allow_fd_caching( server->pipe_end.fd );
|
2017-10-09 05:28:46 -07:00
|
|
|
set_fd_signaled( server->pipe_end.fd, 1 );
|
2019-03-11 09:03:33 -07:00
|
|
|
async_wake_up( &pipe->waiters, STATUS_SUCCESS );
|
2003-05-14 21:22:45 -07:00
|
|
|
return server;
|
2001-07-10 12:16:49 -07:00
|
|
|
}
|
|
|
|
|
2018-11-23 07:13:24 -07:00
|
|
|
static struct pipe_end *create_pipe_client( struct named_pipe *pipe, data_size_t buffer_size, unsigned int options )
|
2001-07-10 12:16:49 -07:00
|
|
|
{
|
2018-11-23 07:13:24 -07:00
|
|
|
struct pipe_end *client;
|
2001-07-10 12:16:49 -07:00
|
|
|
|
2003-05-14 21:22:45 -07:00
|
|
|
client = alloc_object( &pipe_client_ops );
|
2005-06-10 12:54:46 -07:00
|
|
|
if (!client)
|
2003-05-14 21:22:45 -07:00
|
|
|
return NULL;
|
|
|
|
|
2018-11-23 07:13:24 -07:00
|
|
|
init_pipe_end( client, pipe, 0, buffer_size );
|
|
|
|
client->state = FILE_PIPE_CONNECTED_STATE;
|
|
|
|
client->client_pid = get_process_id( current->process );
|
2003-05-14 21:22:45 -07:00
|
|
|
|
2018-11-23 07:13:24 -07:00
|
|
|
client->fd = alloc_pseudo_fd( &pipe_client_fd_ops, &client->obj, options );
|
|
|
|
if (!client->fd)
|
2017-10-04 06:18:40 -07:00
|
|
|
{
|
|
|
|
release_object( client );
|
|
|
|
return NULL;
|
|
|
|
}
|
2018-11-23 07:13:24 -07:00
|
|
|
allow_fd_caching( client->fd );
|
|
|
|
set_fd_signaled( client->fd, 1 );
|
2017-10-04 06:18:40 -07:00
|
|
|
|
2003-05-14 21:22:45 -07:00
|
|
|
return client;
|
|
|
|
}
|
|
|
|
|
2016-02-04 05:08:02 -07:00
|
|
|
static int named_pipe_link_name( struct object *obj, struct object_name *name, struct object *parent )
|
|
|
|
{
|
|
|
|
struct named_pipe_device *dev = (struct named_pipe_device *)parent;
|
|
|
|
|
|
|
|
if (parent->ops != &named_pipe_device_ops)
|
|
|
|
{
|
|
|
|
set_error( STATUS_OBJECT_NAME_INVALID );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
namespace_add( dev->pipes, name );
|
|
|
|
name->parent = grab_object( parent );
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2007-03-22 08:47:46 -07:00
|
|
|
static struct object *named_pipe_open_file( struct object *obj, unsigned int access,
|
|
|
|
unsigned int sharing, unsigned int options )
|
|
|
|
{
|
|
|
|
struct named_pipe *pipe = (struct named_pipe *)obj;
|
|
|
|
struct pipe_server *server;
|
2018-11-23 07:13:24 -07:00
|
|
|
struct pipe_end *client;
|
2011-09-29 02:20:50 -07:00
|
|
|
unsigned int pipe_sharing;
|
2007-03-22 08:47:46 -07:00
|
|
|
|
2019-03-11 09:03:23 -07:00
|
|
|
if (list_empty( &pipe->listeners ))
|
2007-03-22 08:47:46 -07:00
|
|
|
{
|
|
|
|
set_error( STATUS_PIPE_NOT_AVAILABLE );
|
|
|
|
return NULL;
|
|
|
|
}
|
2019-03-11 09:03:23 -07:00
|
|
|
server = LIST_ENTRY( list_head( &pipe->listeners ), struct pipe_server, entry );
|
2007-03-22 08:47:46 -07:00
|
|
|
|
2018-08-16 06:11:48 -07:00
|
|
|
pipe_sharing = pipe->sharing;
|
2011-09-29 02:20:50 -07:00
|
|
|
if (((access & GENERIC_READ) && !(pipe_sharing & FILE_SHARE_READ)) ||
|
|
|
|
((access & GENERIC_WRITE) && !(pipe_sharing & FILE_SHARE_WRITE)))
|
|
|
|
{
|
|
|
|
set_error( STATUS_ACCESS_DENIED );
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2018-11-23 07:13:24 -07:00
|
|
|
if ((client = create_pipe_client( pipe, pipe->outsize, options )))
|
2007-03-22 08:47:46 -07:00
|
|
|
{
|
2018-08-17 08:41:01 -07:00
|
|
|
async_wake_up( &server->listen_q, STATUS_SUCCESS );
|
2018-08-08 13:00:32 -07:00
|
|
|
server->pipe_end.state = FILE_PIPE_CONNECTED_STATE;
|
2018-11-23 07:13:24 -07:00
|
|
|
server->pipe_end.connection = client;
|
|
|
|
client->connection = &server->pipe_end;
|
|
|
|
server->pipe_end.client_pid = client->client_pid;
|
|
|
|
client->server_pid = server->pipe_end.server_pid;
|
2019-03-11 09:03:23 -07:00
|
|
|
list_remove( &server->entry );
|
2007-03-22 08:47:46 -07:00
|
|
|
}
|
2018-11-23 07:13:24 -07:00
|
|
|
return &client->obj;
|
2007-03-22 08:47:46 -07:00
|
|
|
}
|
|
|
|
|
2017-06-26 03:20:10 -07:00
|
|
|
static int named_pipe_device_ioctl( struct fd *fd, ioctl_code_t code, struct async *async )
|
2007-04-17 13:07:07 -07:00
|
|
|
{
|
|
|
|
struct named_pipe_device *device = get_fd_user( fd );
|
|
|
|
|
|
|
|
switch(code)
|
|
|
|
{
|
|
|
|
case FSCTL_PIPE_WAIT:
|
|
|
|
{
|
2015-05-04 20:02:59 -07:00
|
|
|
const FILE_PIPE_WAIT_FOR_BUFFER *buffer = get_req_data();
|
|
|
|
data_size_t size = get_req_data_size();
|
2007-04-17 13:07:07 -07:00
|
|
|
struct named_pipe *pipe;
|
|
|
|
struct unicode_str name;
|
2017-02-15 14:12:28 -07:00
|
|
|
timeout_t when;
|
2007-04-17 13:07:07 -07:00
|
|
|
|
|
|
|
if (size < sizeof(*buffer) ||
|
|
|
|
size < FIELD_OFFSET(FILE_PIPE_WAIT_FOR_BUFFER, Name[buffer->NameLength/sizeof(WCHAR)]))
|
|
|
|
{
|
|
|
|
set_error( STATUS_INVALID_PARAMETER );
|
2007-05-03 08:43:18 -07:00
|
|
|
return 0;
|
2007-04-17 13:07:07 -07:00
|
|
|
}
|
|
|
|
name.str = buffer->Name;
|
|
|
|
name.len = (buffer->NameLength / sizeof(WCHAR)) * sizeof(WCHAR);
|
2016-02-07 22:30:07 -07:00
|
|
|
if (!(pipe = open_named_object( &device->obj, &named_pipe_ops, &name, 0 ))) return 0;
|
|
|
|
|
2019-03-11 09:03:23 -07:00
|
|
|
if (list_empty( &pipe->listeners ))
|
2007-04-17 13:07:07 -07:00
|
|
|
{
|
2017-07-04 06:26:19 -07:00
|
|
|
queue_async( &pipe->waiters, async );
|
2017-02-15 14:12:59 -07:00
|
|
|
when = buffer->TimeoutSpecified ? buffer->Timeout.QuadPart : pipe->timeout;
|
|
|
|
async_set_timeout( async, when, STATUS_IO_TIMEOUT );
|
|
|
|
set_error( STATUS_PENDING );
|
2007-04-17 13:07:07 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
release_object( pipe );
|
2019-03-11 09:03:23 -07:00
|
|
|
return 1;
|
2007-04-17 13:07:07 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
2017-04-12 04:54:17 -07:00
|
|
|
return default_fd_ioctl( fd, code, async );
|
2007-04-17 13:07:07 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-07-10 12:16:49 -07:00
|
|
|
DECL_HANDLER(create_named_pipe)
|
|
|
|
{
|
|
|
|
struct named_pipe *pipe;
|
2003-05-14 21:22:45 -07:00
|
|
|
struct pipe_server *server;
|
2005-11-18 09:31:18 -07:00
|
|
|
struct unicode_str name;
|
2016-02-12 05:00:41 -07:00
|
|
|
struct object *root;
|
2014-11-12 03:25:23 -07:00
|
|
|
const struct security_descriptor *sd;
|
2016-01-31 22:57:37 -07:00
|
|
|
const struct object_attributes *objattr = get_req_object_attributes( &sd, &name, &root );
|
2016-01-15 02:15:31 -07:00
|
|
|
|
|
|
|
if (!objattr) return;
|
2001-07-10 12:16:49 -07:00
|
|
|
|
2011-10-12 05:50:40 -07:00
|
|
|
if (!req->sharing || (req->sharing & ~(FILE_SHARE_READ | FILE_SHARE_WRITE)) ||
|
|
|
|
(!(req->flags & NAMED_PIPE_MESSAGE_STREAM_WRITE) && (req->flags & NAMED_PIPE_MESSAGE_STREAM_READ)))
|
2011-09-26 04:57:38 -07:00
|
|
|
{
|
2016-04-25 18:34:58 -07:00
|
|
|
if (root) release_object( root );
|
2011-09-26 04:57:38 -07:00
|
|
|
set_error( STATUS_INVALID_PARAMETER );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-01-31 22:57:37 -07:00
|
|
|
if (!name.len) /* pipes need a root directory even without a name */
|
|
|
|
{
|
|
|
|
if (!objattr->rootdir)
|
|
|
|
{
|
|
|
|
set_error( STATUS_OBJECT_PATH_SYNTAX_BAD );
|
|
|
|
return;
|
|
|
|
}
|
2016-02-12 05:00:41 -07:00
|
|
|
if (!(root = get_directory_obj( current->process, objattr->rootdir ))) return;
|
2016-01-31 22:57:37 -07:00
|
|
|
}
|
2005-12-05 05:09:35 -07:00
|
|
|
|
2016-02-12 06:57:33 -07:00
|
|
|
pipe = create_named_object( root, &named_pipe_ops, &name, objattr->attributes | OBJ_OPENIF, NULL );
|
2005-12-05 05:09:35 -07:00
|
|
|
|
|
|
|
if (root) release_object( root );
|
|
|
|
if (!pipe) return;
|
2001-07-10 12:16:49 -07:00
|
|
|
|
2005-11-21 09:27:03 -07:00
|
|
|
if (get_error() != STATUS_OBJECT_NAME_EXISTS)
|
2001-08-27 12:03:42 -07:00
|
|
|
{
|
2005-12-05 05:09:35 -07:00
|
|
|
/* initialize it if it didn't already exist */
|
|
|
|
pipe->instances = 0;
|
2017-07-04 06:26:19 -07:00
|
|
|
init_async_queue( &pipe->waiters );
|
2019-03-11 09:03:23 -07:00
|
|
|
list_init( &pipe->listeners );
|
2001-08-27 12:03:42 -07:00
|
|
|
pipe->insize = req->insize;
|
|
|
|
pipe->outsize = req->outsize;
|
|
|
|
pipe->maxinstances = req->maxinstances;
|
|
|
|
pipe->timeout = req->timeout;
|
2018-11-23 07:13:07 -07:00
|
|
|
pipe->message_mode = (req->flags & NAMED_PIPE_MESSAGE_STREAM_WRITE) != 0;
|
2011-09-26 04:57:15 -07:00
|
|
|
pipe->sharing = req->sharing;
|
2018-02-26 11:25:08 -07:00
|
|
|
if (sd) default_set_sd( &pipe->obj, sd, OWNER_SECURITY_INFORMATION |
|
|
|
|
GROUP_SECURITY_INFORMATION |
|
|
|
|
DACL_SECURITY_INFORMATION |
|
|
|
|
SACL_SECURITY_INFORMATION );
|
2001-08-27 12:03:42 -07:00
|
|
|
}
|
2003-05-14 21:22:45 -07:00
|
|
|
else
|
|
|
|
{
|
2005-06-10 12:54:46 -07:00
|
|
|
if (pipe->maxinstances <= pipe->instances)
|
2003-05-14 21:22:45 -07:00
|
|
|
{
|
2005-11-01 14:37:30 -07:00
|
|
|
set_error( STATUS_INSTANCE_NOT_AVAILABLE );
|
2003-05-14 21:22:45 -07:00
|
|
|
release_object( pipe );
|
|
|
|
return;
|
|
|
|
}
|
2011-09-26 04:57:29 -07:00
|
|
|
if (pipe->sharing != req->sharing)
|
2003-05-14 21:22:45 -07:00
|
|
|
{
|
|
|
|
set_error( STATUS_ACCESS_DENIED );
|
|
|
|
release_object( pipe );
|
|
|
|
return;
|
|
|
|
}
|
2006-05-26 03:10:11 -07:00
|
|
|
clear_error(); /* clear the name collision */
|
2003-05-14 21:22:45 -07:00
|
|
|
}
|
2001-08-27 12:03:42 -07:00
|
|
|
|
2014-08-11 06:35:50 -07:00
|
|
|
server = create_pipe_server( pipe, req->options, req->flags );
|
2005-06-10 12:54:46 -07:00
|
|
|
if (server)
|
2001-07-10 12:16:49 -07:00
|
|
|
{
|
2016-01-15 01:53:34 -07:00
|
|
|
reply->handle = alloc_handle( current->process, server, req->access, objattr->attributes );
|
2018-08-16 06:11:48 -07:00
|
|
|
pipe->instances++;
|
2003-05-14 21:22:45 -07:00
|
|
|
release_object( server );
|
2001-07-10 12:16:49 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
release_object( pipe );
|
|
|
|
}
|
|
|
|
|
2014-08-11 08:06:49 -07:00
|
|
|
DECL_HANDLER(set_named_pipe_info)
|
|
|
|
{
|
2018-08-16 06:11:32 -07:00
|
|
|
struct pipe_end *pipe_end;
|
2014-08-11 08:06:49 -07:00
|
|
|
|
2018-08-16 06:11:32 -07:00
|
|
|
pipe_end = (struct pipe_end *)get_handle_obj( current->process, req->handle,
|
|
|
|
FILE_WRITE_ATTRIBUTES, &pipe_server_ops );
|
|
|
|
if (!pipe_end)
|
2014-08-11 08:06:49 -07:00
|
|
|
{
|
|
|
|
if (get_error() != STATUS_OBJECT_TYPE_MISMATCH)
|
|
|
|
return;
|
|
|
|
|
|
|
|
clear_error();
|
2018-08-16 06:11:32 -07:00
|
|
|
pipe_end = (struct pipe_end *)get_handle_obj( current->process, req->handle,
|
|
|
|
0, &pipe_client_ops );
|
|
|
|
if (!pipe_end) return;
|
2014-08-11 08:06:49 -07:00
|
|
|
}
|
|
|
|
|
2018-11-23 07:12:35 -07:00
|
|
|
if (!pipe_end->pipe)
|
|
|
|
{
|
|
|
|
set_error( STATUS_PIPE_DISCONNECTED );
|
|
|
|
}
|
|
|
|
else if ((req->flags & ~(NAMED_PIPE_MESSAGE_STREAM_READ | NAMED_PIPE_NONBLOCKING_MODE)) ||
|
2018-11-23 07:13:07 -07:00
|
|
|
((req->flags & NAMED_PIPE_MESSAGE_STREAM_READ) && !pipe_end->pipe->message_mode))
|
2014-08-11 08:06:49 -07:00
|
|
|
{
|
|
|
|
set_error( STATUS_INVALID_PARAMETER );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-11-23 07:13:07 -07:00
|
|
|
pipe_end->flags = req->flags;
|
2014-08-11 08:06:49 -07:00
|
|
|
}
|
|
|
|
|
2018-08-16 06:11:32 -07:00
|
|
|
release_object( pipe_end );
|
2014-08-11 08:06:49 -07:00
|
|
|
}
|