2005-03-30 12:02:15 -07:00
|
|
|
/*
|
|
|
|
* Server-side mailslot management
|
|
|
|
*
|
|
|
|
* Copyright (C) 1998 Alexandre Julliard
|
|
|
|
* Copyright (C) 2005 Mike McCormack
|
|
|
|
*
|
|
|
|
* 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
|
2005-03-30 12:02:15 -07:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <sys/time.h>
|
|
|
|
#include <sys/types.h>
|
2021-10-07 05:38:40 -07:00
|
|
|
#include <unistd.h>
|
2005-03-30 12:02:15 -07:00
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <sys/socket.h>
|
2005-05-07 05:14:18 -07:00
|
|
|
#ifdef HAVE_SYS_FILIO_H
|
|
|
|
#include <sys/filio.h>
|
|
|
|
#endif
|
2021-10-07 05:38:40 -07:00
|
|
|
|
|
|
|
#include "ntstatus.h"
|
|
|
|
#define WIN32_NO_STATUS
|
2005-03-30 12:02:15 -07:00
|
|
|
#include "windef.h"
|
2005-10-27 11:30:37 -07:00
|
|
|
#include "winternl.h"
|
2005-03-30 12:02:15 -07:00
|
|
|
|
|
|
|
#include "file.h"
|
|
|
|
#include "handle.h"
|
|
|
|
#include "thread.h"
|
|
|
|
#include "request.h"
|
|
|
|
|
2024-07-05 19:46:01 -07:00
|
|
|
struct mailslot_message
|
|
|
|
{
|
|
|
|
struct list entry;
|
|
|
|
struct iosb *iosb;
|
|
|
|
};
|
|
|
|
|
2005-03-30 12:02:15 -07:00
|
|
|
struct mailslot
|
|
|
|
{
|
|
|
|
struct object obj;
|
|
|
|
struct fd *fd;
|
|
|
|
unsigned int max_msgsize;
|
2007-04-17 11:08:59 -07:00
|
|
|
timeout_t read_timeout;
|
2005-03-30 12:02:15 -07:00
|
|
|
struct list writers;
|
2024-07-05 19:46:01 -07:00
|
|
|
struct list messages;
|
|
|
|
struct async_queue read_q;
|
2005-03-30 12:02:15 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
/* mailslot functions */
|
|
|
|
static void mailslot_dump( struct object*, int );
|
|
|
|
static struct fd *mailslot_get_fd( struct object * );
|
2005-12-12 08:46:17 -07:00
|
|
|
static unsigned int mailslot_map_access( struct object *obj, unsigned int access );
|
2016-02-04 05:08:02 -07:00
|
|
|
static int mailslot_link_name( struct object *obj, struct object_name *name, struct object *parent );
|
2007-03-22 08:36:54 -07:00
|
|
|
static struct object *mailslot_open_file( struct object *obj, unsigned int access,
|
|
|
|
unsigned int sharing, unsigned int options );
|
2005-03-30 12:02:15 -07:00
|
|
|
static void mailslot_destroy( struct object * );
|
|
|
|
|
|
|
|
static const struct object_ops mailslot_ops =
|
|
|
|
{
|
|
|
|
sizeof(struct mailslot), /* size */
|
2021-02-04 05:44:18 -07:00
|
|
|
&file_type, /* type */
|
2005-03-30 12:02:15 -07:00
|
|
|
mailslot_dump, /* dump */
|
2007-04-04 10:39:29 -07:00
|
|
|
add_queue, /* add_queue */
|
|
|
|
remove_queue, /* remove_queue */
|
2005-03-30 12:02:15 -07:00
|
|
|
default_fd_signaled, /* signaled */
|
|
|
|
no_satisfied, /* satisfied */
|
2005-04-24 10:35:52 -07:00
|
|
|
no_signal, /* signal */
|
2005-03-30 12:02:15 -07:00
|
|
|
mailslot_get_fd, /* get_fd */
|
2005-12-12 08:46:17 -07:00
|
|
|
mailslot_map_access, /* map_access */
|
2007-10-03 05:10:37 -07:00
|
|
|
default_get_sd, /* get_sd */
|
|
|
|
default_set_sd, /* set_sd */
|
2020-09-22 07:52:31 -07:00
|
|
|
default_get_full_name, /* get_full_name */
|
2005-11-22 07:55:42 -07:00
|
|
|
no_lookup_name, /* lookup_name */
|
2016-02-04 05:08:02 -07:00
|
|
|
mailslot_link_name, /* link_name */
|
|
|
|
default_unlink_name, /* unlink_name */
|
2007-03-22 08:36:54 -07:00
|
|
|
mailslot_open_file, /* open_file */
|
2019-03-25 06:37:09 -07:00
|
|
|
no_kernel_obj_list, /* get_kernel_obj_list */
|
2021-03-22 21:04:30 -07:00
|
|
|
no_close_handle, /* close_handle */
|
2005-03-30 12:02:15 -07:00
|
|
|
mailslot_destroy /* destroy */
|
|
|
|
};
|
|
|
|
|
2007-04-10 13:26:23 -07:00
|
|
|
static enum server_fd_type mailslot_get_fd_type( struct fd *fd );
|
2024-07-05 19:46:01 -07:00
|
|
|
static void mailslot_read( struct fd *fd, struct async *async, file_pos_t pos );
|
|
|
|
static void mailslot_write( struct fd *fd, struct async *async, file_pos_t pos );
|
|
|
|
static void mailslot_get_file_info( struct fd *fd, obj_handle_t handle, unsigned int info_class );
|
2005-03-30 12:02:15 -07:00
|
|
|
|
|
|
|
static const struct fd_ops mailslot_fd_ops =
|
|
|
|
{
|
2005-07-14 05:18:05 -07:00
|
|
|
default_fd_get_poll_events, /* get_poll_events */
|
|
|
|
default_poll_event, /* poll_event */
|
2007-04-10 13:26:23 -07:00
|
|
|
mailslot_get_fd_type, /* get_fd_type */
|
2024-07-05 19:46:01 -07:00
|
|
|
mailslot_read, /* read */
|
|
|
|
mailslot_write, /* write */
|
2015-05-04 20:17:45 -07:00
|
|
|
no_fd_flush, /* flush */
|
2024-07-05 19:46:01 -07:00
|
|
|
mailslot_get_file_info, /* get_file_info */
|
2017-10-02 07:42:16 -07:00
|
|
|
no_fd_get_volume_info, /* get_volume_info */
|
2007-04-16 05:45:03 -07:00
|
|
|
default_fd_ioctl, /* ioctl */
|
2021-09-03 21:11:38 -07:00
|
|
|
default_fd_cancel_async, /* cancel_async */
|
2024-07-05 19:46:01 -07:00
|
|
|
no_fd_queue_async, /* queue_async */
|
2016-12-01 04:10:34 -07:00
|
|
|
default_fd_reselect_async /* reselect_async */
|
2005-03-30 12:02:15 -07:00
|
|
|
};
|
|
|
|
|
2005-12-12 08:46:17 -07:00
|
|
|
|
2005-03-30 12:02:15 -07:00
|
|
|
struct mail_writer
|
|
|
|
{
|
|
|
|
struct object obj;
|
2007-04-12 11:19:28 -07:00
|
|
|
struct fd *fd;
|
2005-03-30 12:02:15 -07:00
|
|
|
struct mailslot *mailslot;
|
|
|
|
struct list entry;
|
2005-12-12 08:46:17 -07:00
|
|
|
unsigned int access;
|
|
|
|
unsigned int sharing;
|
2005-03-30 12:02:15 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
static void mail_writer_dump( struct object *obj, int verbose );
|
|
|
|
static struct fd *mail_writer_get_fd( struct object *obj );
|
2005-12-12 08:46:17 -07:00
|
|
|
static unsigned int mail_writer_map_access( struct object *obj, unsigned int access );
|
2005-03-30 12:02:15 -07:00
|
|
|
static void mail_writer_destroy( struct object *obj);
|
|
|
|
|
|
|
|
static const struct object_ops mail_writer_ops =
|
|
|
|
{
|
|
|
|
sizeof(struct mail_writer), /* size */
|
2021-02-04 05:44:18 -07:00
|
|
|
&file_type, /* type */
|
2005-03-30 12:02:15 -07:00
|
|
|
mail_writer_dump, /* dump */
|
|
|
|
no_add_queue, /* add_queue */
|
|
|
|
NULL, /* remove_queue */
|
|
|
|
NULL, /* signaled */
|
|
|
|
NULL, /* satisfied */
|
2005-04-24 10:35:52 -07:00
|
|
|
no_signal, /* signal */
|
2005-03-30 12:02:15 -07:00
|
|
|
mail_writer_get_fd, /* get_fd */
|
2005-12-12 08:46:17 -07:00
|
|
|
mail_writer_map_access, /* map_access */
|
2007-10-03 05:10:37 -07:00
|
|
|
default_get_sd, /* get_sd */
|
|
|
|
default_set_sd, /* set_sd */
|
2020-09-22 07:52:31 -07:00
|
|
|
no_get_full_name, /* get_full_name */
|
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 */
|
2021-03-22 21:04:30 -07:00
|
|
|
no_close_handle, /* close_handle */
|
2005-03-30 12:02:15 -07:00
|
|
|
mail_writer_destroy /* destroy */
|
|
|
|
};
|
|
|
|
|
2007-04-10 13:26:23 -07:00
|
|
|
static enum server_fd_type mail_writer_get_fd_type( struct fd *fd );
|
2024-07-05 19:46:01 -07:00
|
|
|
static void mail_writer_read( struct fd *fd, struct async *async, file_pos_t pos );
|
|
|
|
static void mail_writer_write( struct fd *fd, struct async *async, file_pos_t pos );
|
2005-03-30 12:02:15 -07:00
|
|
|
|
|
|
|
static const struct fd_ops mail_writer_fd_ops =
|
|
|
|
{
|
2007-04-12 11:19:28 -07:00
|
|
|
default_fd_get_poll_events, /* get_poll_events */
|
|
|
|
default_poll_event, /* poll_event */
|
2007-04-10 13:26:23 -07:00
|
|
|
mail_writer_get_fd_type, /* get_fd_type */
|
2024-07-05 19:46:01 -07:00
|
|
|
mail_writer_read, /* read */
|
|
|
|
mail_writer_write, /* write */
|
2015-05-04 20:17:45 -07:00
|
|
|
no_fd_flush, /* flush */
|
2018-10-23 08:45:06 -07:00
|
|
|
default_fd_get_file_info, /* get_file_info */
|
2017-10-02 07:42:16 -07:00
|
|
|
no_fd_get_volume_info, /* get_volume_info */
|
2007-04-16 05:45:03 -07:00
|
|
|
default_fd_ioctl, /* ioctl */
|
2021-09-03 21:11:38 -07:00
|
|
|
default_fd_cancel_async, /* cancel_async */
|
2007-04-12 11:19:28 -07:00
|
|
|
default_fd_queue_async, /* queue_async */
|
2016-12-01 04:10:34 -07:00
|
|
|
default_fd_reselect_async /* reselect_async */
|
2005-03-30 12:02:15 -07:00
|
|
|
};
|
|
|
|
|
2005-12-12 08:46:17 -07:00
|
|
|
|
|
|
|
struct mailslot_device
|
|
|
|
{
|
|
|
|
struct object obj; /* object header */
|
|
|
|
struct namespace *mailslots; /* mailslot namespace */
|
|
|
|
};
|
|
|
|
|
2020-08-01 21:35:53 -07:00
|
|
|
struct mailslot_device_file
|
|
|
|
{
|
|
|
|
struct object obj; /* object header */
|
|
|
|
struct fd *fd; /* pseudo-fd for ioctls */
|
|
|
|
struct mailslot_device *device; /* mailslot device */
|
|
|
|
};
|
|
|
|
|
2005-12-05 05:30:26 -07:00
|
|
|
static void mailslot_device_dump( struct object *obj, int verbose );
|
|
|
|
static struct object *mailslot_device_lookup_name( struct object *obj, struct unicode_str *name,
|
2020-11-25 11:42:42 -07:00
|
|
|
unsigned int attr, struct object *root );
|
2007-03-22 03:52:40 -07:00
|
|
|
static struct object *mailslot_device_open_file( struct object *obj, unsigned int access,
|
|
|
|
unsigned int sharing, unsigned int options );
|
2005-12-05 05:30:26 -07:00
|
|
|
static void mailslot_device_destroy( struct object *obj );
|
|
|
|
|
|
|
|
static const struct object_ops mailslot_device_ops =
|
|
|
|
{
|
|
|
|
sizeof(struct mailslot_device), /* size */
|
2021-02-04 05:44:18 -07:00
|
|
|
&device_type, /* type */
|
2005-12-12 06:39:27 -07:00
|
|
|
mailslot_device_dump, /* dump */
|
|
|
|
no_add_queue, /* add_queue */
|
|
|
|
NULL, /* remove_queue */
|
|
|
|
NULL, /* signaled */
|
|
|
|
no_satisfied, /* satisfied */
|
|
|
|
no_signal, /* signal */
|
2020-08-01 21:35:53 -07:00
|
|
|
no_get_fd, /* get_fd */
|
2021-02-05 04:10:44 -07:00
|
|
|
default_map_access, /* map_access */
|
2007-10-03 05:10:37 -07:00
|
|
|
default_get_sd, /* get_sd */
|
|
|
|
default_set_sd, /* set_sd */
|
2020-09-22 07:52:31 -07:00
|
|
|
default_get_full_name, /* get_full_name */
|
2005-12-12 06:39:27 -07:00
|
|
|
mailslot_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
|
|
|
mailslot_device_open_file, /* open_file */
|
2019-03-25 06:37:09 -07:00
|
|
|
no_kernel_obj_list, /* get_kernel_obj_list */
|
2020-08-01 21:35:53 -07:00
|
|
|
no_close_handle, /* close_handle */
|
2005-12-12 06:39:27 -07:00
|
|
|
mailslot_device_destroy /* destroy */
|
|
|
|
};
|
|
|
|
|
2020-08-01 21:35:53 -07:00
|
|
|
static void mailslot_device_file_dump( struct object *obj, int verbose );
|
|
|
|
static struct fd *mailslot_device_file_get_fd( struct object *obj );
|
2020-09-22 07:56:52 -07:00
|
|
|
static WCHAR *mailslot_device_file_get_full_name( struct object *obj, data_size_t *len );
|
2020-08-01 21:35:53 -07:00
|
|
|
static void mailslot_device_file_destroy( struct object *obj );
|
|
|
|
static enum server_fd_type mailslot_device_file_get_fd_type( struct fd *fd );
|
|
|
|
|
|
|
|
static const struct object_ops mailslot_device_file_ops =
|
|
|
|
{
|
|
|
|
sizeof(struct mailslot_device_file), /* size */
|
2021-02-04 05:44:18 -07:00
|
|
|
&file_type, /* type */
|
2020-08-01 21:35:53 -07:00
|
|
|
mailslot_device_file_dump, /* dump */
|
|
|
|
add_queue, /* add_queue */
|
|
|
|
remove_queue, /* remove_queue */
|
|
|
|
default_fd_signaled, /* signaled */
|
|
|
|
no_satisfied, /* satisfied */
|
|
|
|
no_signal, /* signal */
|
|
|
|
mailslot_device_file_get_fd, /* get_fd */
|
2021-02-05 04:10:44 -07:00
|
|
|
default_map_access, /* map_access */
|
2020-08-01 21:35:53 -07:00
|
|
|
default_get_sd, /* get_sd */
|
|
|
|
default_set_sd, /* set_sd */
|
2020-09-22 07:56:52 -07:00
|
|
|
mailslot_device_file_get_full_name, /* get_full_name */
|
2020-08-01 21:35:53 -07:00
|
|
|
no_lookup_name, /* lookup_name */
|
|
|
|
no_link_name, /* link_name */
|
|
|
|
NULL, /* unlink_name */
|
|
|
|
no_open_file, /* open_file */
|
|
|
|
no_kernel_obj_list, /* get_kernel_obj_list */
|
2021-03-22 21:04:30 -07:00
|
|
|
no_close_handle, /* close_handle */
|
2020-08-01 21:35:53 -07:00
|
|
|
mailslot_device_file_destroy /* destroy */
|
|
|
|
};
|
|
|
|
|
2005-12-12 06:39:27 -07:00
|
|
|
static const struct fd_ops mailslot_device_fd_ops =
|
|
|
|
{
|
2020-08-01 21:35:53 -07:00
|
|
|
default_fd_get_poll_events, /* get_poll_events */
|
|
|
|
default_poll_event, /* poll_event */
|
|
|
|
mailslot_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 */
|
|
|
|
default_fd_ioctl, /* ioctl */
|
2021-09-03 21:11:38 -07:00
|
|
|
default_fd_cancel_async, /* cancel_async */
|
2020-08-01 21:35:53 -07:00
|
|
|
default_fd_queue_async, /* queue_async */
|
|
|
|
default_fd_reselect_async /* reselect_async */
|
2005-12-05 05:30:26 -07:00
|
|
|
};
|
|
|
|
|
2024-07-05 19:46:01 -07:00
|
|
|
static struct mailslot_message *get_first_message( struct mailslot *mailslot )
|
|
|
|
{
|
2024-09-11 08:12:08 -07:00
|
|
|
struct list *ptr = list_head( &mailslot->messages );
|
|
|
|
return ptr ? LIST_ENTRY( ptr, struct mailslot_message, entry ) : NULL;
|
2024-07-05 19:46:01 -07:00
|
|
|
}
|
|
|
|
|
2005-03-30 12:02:15 -07:00
|
|
|
static void mailslot_destroy( struct object *obj)
|
|
|
|
{
|
|
|
|
struct mailslot *mailslot = (struct mailslot *) obj;
|
2024-07-05 19:46:01 -07:00
|
|
|
struct mailslot_message *message;
|
2005-03-30 12:02:15 -07:00
|
|
|
|
2024-07-05 19:46:01 -07:00
|
|
|
while ((message = get_first_message( mailslot )))
|
2007-04-12 11:19:28 -07:00
|
|
|
{
|
2024-07-05 19:46:01 -07:00
|
|
|
list_remove( &message->entry );
|
|
|
|
release_object( message->iosb );
|
|
|
|
free( message );
|
2007-04-12 11:19:28 -07:00
|
|
|
}
|
2024-07-05 19:46:01 -07:00
|
|
|
|
|
|
|
free_async_queue( &mailslot->read_q );
|
|
|
|
|
|
|
|
assert( mailslot->fd );
|
2005-03-30 12:02:15 -07:00
|
|
|
release_object( mailslot->fd );
|
|
|
|
}
|
|
|
|
|
|
|
|
static void mailslot_dump( struct object *obj, int verbose )
|
|
|
|
{
|
|
|
|
struct mailslot *mailslot = (struct mailslot *) obj;
|
|
|
|
|
|
|
|
assert( obj->ops == &mailslot_ops );
|
2007-04-17 11:08:59 -07:00
|
|
|
fprintf( stderr, "Mailslot max_msgsize=%d read_timeout=%s\n",
|
|
|
|
mailslot->max_msgsize, get_timeout_str(mailslot->read_timeout) );
|
2005-03-30 12:02:15 -07:00
|
|
|
}
|
|
|
|
|
2007-04-10 13:26:23 -07:00
|
|
|
static enum server_fd_type mailslot_get_fd_type( struct fd *fd )
|
2005-03-30 12:02:15 -07:00
|
|
|
{
|
2024-07-05 19:46:01 -07:00
|
|
|
return FD_TYPE_DEVICE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void reselect_mailslot( struct mailslot *mailslot )
|
|
|
|
{
|
|
|
|
struct mailslot_message *message;
|
|
|
|
struct async *async;
|
|
|
|
|
|
|
|
while ((message = get_first_message( mailslot )) && (async = find_pending_async( &mailslot->read_q )))
|
|
|
|
{
|
|
|
|
struct iosb *read_iosb = async_get_iosb( async );
|
|
|
|
|
|
|
|
if (read_iosb->out_size < message->iosb->in_size)
|
|
|
|
{
|
|
|
|
async_request_complete( async, STATUS_BUFFER_TOO_SMALL, 0, 0, NULL );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
async_request_complete( async, STATUS_SUCCESS, message->iosb->in_size,
|
|
|
|
message->iosb->in_size, message->iosb->in_data );
|
|
|
|
message->iosb->in_data = NULL;
|
|
|
|
list_remove( &message->entry );
|
|
|
|
release_object( message->iosb );
|
|
|
|
free( message );
|
|
|
|
}
|
|
|
|
|
|
|
|
release_object( async );
|
|
|
|
release_object( read_iosb );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void mailslot_read( struct fd *fd, struct async *async, file_pos_t pos )
|
|
|
|
{
|
|
|
|
struct mailslot *mailslot = get_fd_user( fd );
|
|
|
|
|
|
|
|
if (mailslot->read_timeout != (timeout_t)-1)
|
|
|
|
async_set_timeout( async, mailslot->read_timeout ? mailslot->read_timeout : -1, STATUS_IO_TIMEOUT );
|
|
|
|
queue_async( &mailslot->read_q, async );
|
|
|
|
reselect_mailslot( mailslot );
|
|
|
|
set_error( STATUS_PENDING );
|
|
|
|
}
|
|
|
|
|
|
|
|
static void mailslot_write( struct fd *fd, struct async *async, file_pos_t pos )
|
|
|
|
{
|
|
|
|
set_error( STATUS_INVALID_PARAMETER );
|
|
|
|
}
|
|
|
|
|
|
|
|
static void mailslot_get_file_info( struct fd *fd, obj_handle_t handle, unsigned int info_class )
|
|
|
|
{
|
|
|
|
struct mailslot *mailslot = get_fd_user( fd );
|
|
|
|
|
|
|
|
switch (info_class)
|
|
|
|
{
|
|
|
|
case FileMailslotQueryInformation:
|
|
|
|
{
|
|
|
|
FILE_MAILSLOT_QUERY_INFORMATION *info;
|
|
|
|
struct mailslot_message *message;
|
|
|
|
|
|
|
|
if (get_reply_max_size() < sizeof(*info))
|
|
|
|
{
|
|
|
|
set_error( STATUS_INFO_LENGTH_MISMATCH );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(info = set_reply_data_size( sizeof(*info) ))) return;
|
|
|
|
info->MaximumMessageSize = mailslot->max_msgsize;
|
|
|
|
info->MailslotQuota = 0;
|
|
|
|
info->MessagesAvailable = list_count( &mailslot->messages );
|
|
|
|
if ((message = get_first_message( mailslot )))
|
|
|
|
info->NextMessageSize = message->iosb->in_size;
|
|
|
|
else
|
|
|
|
info->NextMessageSize = MAILSLOT_NO_MESSAGE;
|
|
|
|
info->ReadTimeout.QuadPart = mailslot->read_timeout;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
default_fd_get_file_info( fd, handle, info_class );
|
|
|
|
}
|
2005-03-30 12:02:15 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static struct fd *mailslot_get_fd( struct object *obj )
|
|
|
|
{
|
|
|
|
struct mailslot *mailslot = (struct mailslot *) obj;
|
|
|
|
|
|
|
|
return (struct fd *)grab_object( mailslot->fd );
|
|
|
|
}
|
|
|
|
|
2005-12-12 08:46:17 -07:00
|
|
|
static unsigned int mailslot_map_access( struct object *obj, unsigned int access )
|
|
|
|
{
|
2007-04-02 11:24:55 -07:00
|
|
|
/* mailslots can only be read */
|
2021-02-05 04:10:44 -07:00
|
|
|
return default_map_access( obj, access ) & FILE_GENERIC_READ;
|
2005-12-12 08:46:17 -07:00
|
|
|
}
|
|
|
|
|
2016-02-04 05:08:02 -07:00
|
|
|
static int mailslot_link_name( struct object *obj, struct object_name *name, struct object *parent )
|
|
|
|
{
|
|
|
|
struct mailslot_device *dev = (struct mailslot_device *)parent;
|
|
|
|
|
|
|
|
if (parent->ops != &mailslot_device_ops)
|
|
|
|
{
|
|
|
|
set_error( STATUS_OBJECT_NAME_INVALID );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
namespace_add( dev->mailslots, name );
|
|
|
|
name->parent = grab_object( parent );
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2007-03-22 08:36:54 -07:00
|
|
|
static struct object *mailslot_open_file( struct object *obj, unsigned int access,
|
|
|
|
unsigned int sharing, unsigned int options )
|
|
|
|
{
|
|
|
|
struct mailslot *mailslot = (struct mailslot *)obj;
|
|
|
|
struct mail_writer *writer;
|
|
|
|
|
|
|
|
if (!(sharing & FILE_SHARE_READ))
|
|
|
|
{
|
|
|
|
set_error( STATUS_SHARING_VIOLATION );
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!list_empty( &mailslot->writers ))
|
|
|
|
{
|
|
|
|
/* Readers and writers cannot be mixed.
|
|
|
|
* If there's more than one writer, all writers must open with FILE_SHARE_WRITE
|
|
|
|
*/
|
|
|
|
writer = LIST_ENTRY( list_head(&mailslot->writers), struct mail_writer, entry );
|
|
|
|
|
|
|
|
if (((access & (GENERIC_WRITE|FILE_WRITE_DATA)) || (writer->access & FILE_WRITE_DATA)) &&
|
|
|
|
!((sharing & FILE_SHARE_WRITE) && (writer->sharing & FILE_SHARE_WRITE)))
|
|
|
|
{
|
|
|
|
set_error( STATUS_SHARING_VIOLATION );
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-04-12 11:19:28 -07:00
|
|
|
if (!(writer = alloc_object( &mail_writer_ops )))
|
|
|
|
return NULL;
|
2007-03-22 08:36:54 -07:00
|
|
|
grab_object( mailslot );
|
|
|
|
writer->mailslot = mailslot;
|
|
|
|
writer->access = mail_writer_map_access( &writer->obj, access );
|
|
|
|
writer->sharing = sharing;
|
|
|
|
list_add_head( &mailslot->writers, &writer->entry );
|
2007-04-12 11:19:28 -07:00
|
|
|
|
2024-07-05 19:46:01 -07:00
|
|
|
if (!(writer->fd = alloc_pseudo_fd( &mail_writer_fd_ops, &writer->obj, options )))
|
2007-04-12 11:19:28 -07:00
|
|
|
{
|
|
|
|
release_object( writer );
|
|
|
|
return NULL;
|
|
|
|
}
|
2010-08-23 08:09:45 -07:00
|
|
|
allow_fd_caching( writer->fd );
|
2007-03-22 08:36:54 -07:00
|
|
|
return &writer->obj;
|
|
|
|
}
|
|
|
|
|
2005-12-05 05:30:26 -07:00
|
|
|
static void mailslot_device_dump( struct object *obj, int verbose )
|
|
|
|
{
|
2016-01-21 05:08:56 -07:00
|
|
|
fputs( "Mailslot device\n", stderr );
|
2005-12-05 05:30:26 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static struct object *mailslot_device_lookup_name( struct object *obj, struct unicode_str *name,
|
2020-11-25 11:42:42 -07:00
|
|
|
unsigned int attr, struct object *root )
|
2005-12-05 05:30:26 -07:00
|
|
|
{
|
|
|
|
struct mailslot_device *device = (struct mailslot_device*)obj;
|
|
|
|
struct object *found;
|
|
|
|
|
|
|
|
assert( obj->ops == &mailslot_device_ops );
|
|
|
|
|
2016-02-09 04:16:27 -07:00
|
|
|
if (!name) return NULL; /* open the device itself */
|
|
|
|
|
2005-12-05 05:30:26 -07:00
|
|
|
if ((found = find_object( device->mailslots, name, attr | OBJ_CASE_INSENSITIVE )))
|
|
|
|
name->len = 0;
|
|
|
|
|
|
|
|
return found;
|
|
|
|
}
|
|
|
|
|
2007-03-22 03:52:40 -07:00
|
|
|
static struct object *mailslot_device_open_file( struct object *obj, unsigned int access,
|
|
|
|
unsigned int sharing, unsigned int options )
|
|
|
|
{
|
2020-08-01 21:35:53 -07:00
|
|
|
struct mailslot_device_file *file;
|
|
|
|
|
|
|
|
if (!(file = alloc_object( &mailslot_device_file_ops ))) return NULL;
|
|
|
|
file->device = (struct mailslot_device *)grab_object( obj );
|
|
|
|
if (!(file->fd = alloc_pseudo_fd( &mailslot_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:30:26 -07:00
|
|
|
static void mailslot_device_destroy( struct object *obj )
|
|
|
|
{
|
|
|
|
struct mailslot_device *device = (struct mailslot_device*)obj;
|
|
|
|
assert( obj->ops == &mailslot_device_ops );
|
2006-10-09 14:34:36 -07:00
|
|
|
free( device->mailslots );
|
2005-12-05 05:30:26 -07:00
|
|
|
}
|
|
|
|
|
2020-09-23 02:32:47 -07:00
|
|
|
struct object *create_mailslot_device( struct object *root, const struct unicode_str *name,
|
|
|
|
unsigned int attr, const struct security_descriptor *sd )
|
2005-12-05 05:30:26 -07:00
|
|
|
{
|
|
|
|
struct mailslot_device *dev;
|
|
|
|
|
2020-09-23 02:32:47 -07:00
|
|
|
if ((dev = create_named_object( root, &mailslot_device_ops, name, attr, sd )) &&
|
2005-12-05 05:30:26 -07:00
|
|
|
get_error() != STATUS_OBJECT_NAME_EXISTS)
|
|
|
|
{
|
2005-12-12 06:39:27 -07:00
|
|
|
dev->mailslots = NULL;
|
2020-08-01 21:35:53 -07:00
|
|
|
if (!(dev->mailslots = create_namespace( 7 )))
|
2005-12-05 05:30:26 -07:00
|
|
|
{
|
|
|
|
release_object( dev );
|
|
|
|
dev = NULL;
|
|
|
|
}
|
|
|
|
}
|
2016-07-17 23:34:08 -07:00
|
|
|
return &dev->obj;
|
2005-12-05 05:30:26 -07:00
|
|
|
}
|
|
|
|
|
2020-08-01 21:35:53 -07:00
|
|
|
static void mailslot_device_file_dump( struct object *obj, int verbose )
|
|
|
|
{
|
|
|
|
struct mailslot_device_file *file = (struct mailslot_device_file *)obj;
|
|
|
|
|
|
|
|
fprintf( stderr, "File on mailslot device %p\n", file->device );
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct fd *mailslot_device_file_get_fd( struct object *obj )
|
|
|
|
{
|
|
|
|
struct mailslot_device_file *file = (struct mailslot_device_file *)obj;
|
|
|
|
return (struct fd *)grab_object( file->fd );
|
|
|
|
}
|
|
|
|
|
2020-09-22 07:56:52 -07:00
|
|
|
static WCHAR *mailslot_device_file_get_full_name( struct object *obj, data_size_t *len )
|
|
|
|
{
|
|
|
|
struct mailslot_device_file *file = (struct mailslot_device_file *)obj;
|
|
|
|
return file->device->obj.ops->get_full_name( &file->device->obj, len );
|
|
|
|
}
|
|
|
|
|
2020-08-01 21:35:53 -07:00
|
|
|
static void mailslot_device_file_destroy( struct object *obj )
|
|
|
|
{
|
|
|
|
struct mailslot_device_file *file = (struct mailslot_device_file*)obj;
|
|
|
|
assert( obj->ops == &mailslot_device_file_ops );
|
|
|
|
if (file->fd) release_object( file->fd );
|
|
|
|
release_object( file->device );
|
|
|
|
}
|
|
|
|
|
|
|
|
static enum server_fd_type mailslot_device_file_get_fd_type( struct fd *fd )
|
|
|
|
{
|
|
|
|
return FD_TYPE_DEVICE;
|
|
|
|
}
|
|
|
|
|
2016-02-12 05:00:41 -07:00
|
|
|
static struct mailslot *create_mailslot( struct object *root,
|
2005-12-05 05:30:26 -07:00
|
|
|
const struct unicode_str *name, unsigned int attr,
|
2024-07-05 19:59:40 -07:00
|
|
|
unsigned int options, int max_msgsize, timeout_t read_timeout,
|
2016-01-15 02:57:02 -07:00
|
|
|
const struct security_descriptor *sd )
|
2005-03-30 12:02:15 -07:00
|
|
|
{
|
|
|
|
struct mailslot *mailslot;
|
|
|
|
|
2016-02-12 06:57:33 -07:00
|
|
|
if (!(mailslot = create_named_object( root, &mailslot_ops, name, attr, sd ))) return NULL;
|
2005-12-05 05:30:26 -07:00
|
|
|
|
2005-03-30 12:02:15 -07:00
|
|
|
mailslot->fd = NULL;
|
|
|
|
mailslot->max_msgsize = max_msgsize;
|
|
|
|
mailslot->read_timeout = read_timeout;
|
|
|
|
list_init( &mailslot->writers );
|
2024-07-05 19:46:01 -07:00
|
|
|
list_init( &mailslot->messages );
|
|
|
|
init_async_queue( &mailslot->read_q );
|
2005-03-30 12:02:15 -07:00
|
|
|
|
2024-07-05 19:46:01 -07:00
|
|
|
if ((mailslot->fd = alloc_pseudo_fd( &mailslot_fd_ops, &mailslot->obj, options )))
|
2005-03-30 12:02:15 -07:00
|
|
|
{
|
2024-07-05 19:46:01 -07:00
|
|
|
allow_fd_caching( mailslot->fd );
|
|
|
|
return mailslot;
|
2005-03-30 12:02:15 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
release_object( mailslot );
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void mail_writer_dump( struct object *obj, int verbose )
|
|
|
|
{
|
|
|
|
fprintf( stderr, "Mailslot writer\n" );
|
|
|
|
}
|
|
|
|
|
|
|
|
static void mail_writer_destroy( struct object *obj)
|
|
|
|
{
|
|
|
|
struct mail_writer *writer = (struct mail_writer *) obj;
|
|
|
|
|
2007-04-12 11:19:28 -07:00
|
|
|
if (writer->fd) release_object( writer->fd );
|
2005-03-30 12:02:15 -07:00
|
|
|
list_remove( &writer->entry );
|
|
|
|
release_object( writer->mailslot );
|
|
|
|
}
|
|
|
|
|
2007-04-10 13:26:23 -07:00
|
|
|
static enum server_fd_type mail_writer_get_fd_type( struct fd *fd )
|
2005-03-30 12:02:15 -07:00
|
|
|
{
|
2024-07-05 19:46:01 -07:00
|
|
|
return FD_TYPE_DEVICE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void mail_writer_read( struct fd *fd, struct async *async, file_pos_t pos )
|
|
|
|
{
|
|
|
|
set_error( STATUS_INVALID_PARAMETER );
|
|
|
|
}
|
|
|
|
|
|
|
|
static void mail_writer_write( struct fd *fd, struct async *async, file_pos_t pos )
|
|
|
|
{
|
|
|
|
struct mail_writer *writer = get_fd_user( fd );
|
|
|
|
struct mailslot_message *message;
|
|
|
|
data_size_t size;
|
|
|
|
|
|
|
|
if (!(message = mem_alloc( sizeof(*message) ))) return;
|
|
|
|
message->iosb = async_get_iosb( async );
|
|
|
|
size = message->iosb->in_size;
|
|
|
|
list_add_tail( &writer->mailslot->messages, &message->entry );
|
|
|
|
reselect_mailslot( writer->mailslot );
|
|
|
|
async_request_complete( async, STATUS_SUCCESS, size, 0, NULL );
|
2005-03-30 12:02:15 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static struct fd *mail_writer_get_fd( struct object *obj )
|
|
|
|
{
|
|
|
|
struct mail_writer *writer = (struct mail_writer *) obj;
|
2007-04-12 11:19:28 -07:00
|
|
|
return (struct fd *)grab_object( writer->fd );
|
2005-03-30 12:02:15 -07:00
|
|
|
}
|
|
|
|
|
2005-12-12 08:46:17 -07:00
|
|
|
static unsigned int mail_writer_map_access( struct object *obj, unsigned int access )
|
|
|
|
{
|
2007-03-22 08:36:54 -07:00
|
|
|
/* mailslot writers can only get write access */
|
2021-02-05 04:10:44 -07:00
|
|
|
return default_map_access( obj, access ) & FILE_GENERIC_WRITE;
|
2005-12-12 08:46:17 -07:00
|
|
|
}
|
|
|
|
|
2005-03-30 12:02:15 -07:00
|
|
|
static struct mailslot *get_mailslot_obj( struct process *process, obj_handle_t handle,
|
|
|
|
unsigned int access )
|
|
|
|
{
|
2005-12-05 05:30:26 -07:00
|
|
|
return (struct mailslot *)get_handle_obj( process, handle, access, &mailslot_ops );
|
2005-03-30 12:02:15 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* create a mailslot */
|
|
|
|
DECL_HANDLER(create_mailslot)
|
|
|
|
{
|
|
|
|
struct mailslot *mailslot;
|
2005-11-18 09:31:18 -07:00
|
|
|
struct unicode_str name;
|
2016-02-12 05:00:41 -07:00
|
|
|
struct object *root;
|
2016-01-15 02:57:02 -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 );
|
2005-03-30 12:02:15 -07:00
|
|
|
|
2016-01-15 02:57:02 -07:00
|
|
|
if (!objattr) return;
|
2016-01-31 22:57:37 -07:00
|
|
|
|
|
|
|
if (!name.len) /* mailslots 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:30:26 -07:00
|
|
|
|
2024-07-05 19:59:40 -07:00
|
|
|
if ((mailslot = create_mailslot( root, &name, objattr->attributes, req->options, req->max_msgsize,
|
2016-01-15 02:57:02 -07:00
|
|
|
req->read_timeout, sd )))
|
2005-03-30 12:02:15 -07:00
|
|
|
{
|
2016-01-15 02:57:02 -07:00
|
|
|
reply->handle = alloc_handle( current->process, mailslot, req->access, objattr->attributes );
|
2005-03-30 12:02:15 -07:00
|
|
|
release_object( mailslot );
|
|
|
|
}
|
2005-12-05 05:30:26 -07:00
|
|
|
|
|
|
|
if (root) release_object( root );
|
2005-03-30 12:02:15 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* set mailslot information */
|
|
|
|
DECL_HANDLER(set_mailslot_info)
|
|
|
|
{
|
|
|
|
struct mailslot *mailslot = get_mailslot_obj( current->process, req->handle, 0 );
|
|
|
|
|
2005-06-10 12:54:46 -07:00
|
|
|
if (mailslot)
|
2005-03-30 12:02:15 -07:00
|
|
|
{
|
2005-06-10 12:54:46 -07:00
|
|
|
if (req->flags & MAILSLOT_SET_READ_TIMEOUT)
|
2005-03-30 12:02:15 -07:00
|
|
|
mailslot->read_timeout = req->read_timeout;
|
|
|
|
reply->max_msgsize = mailslot->max_msgsize;
|
|
|
|
reply->read_timeout = mailslot->read_timeout;
|
|
|
|
release_object( mailslot );
|
|
|
|
}
|
|
|
|
}
|