2005-03-30 21:02:15 +02: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 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2005-03-30 21:02:15 +02:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
#include "wine/port.h"
|
2005-11-28 17:32:54 +01:00
|
|
|
#include "ntstatus.h"
|
|
|
|
#define WIN32_NO_STATUS
|
2005-03-30 21:02:15 +02:00
|
|
|
#include "wine/unicode.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>
|
|
|
|
|
|
|
|
#ifdef HAVE_SYS_IOCTL_H
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_SYS_SOCKET_H
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#endif
|
2005-05-07 14:14:18 +02:00
|
|
|
#ifdef HAVE_SYS_FILIO_H
|
|
|
|
#include <sys/filio.h>
|
|
|
|
#endif
|
2005-03-30 21:02:15 +02:00
|
|
|
#include "windef.h"
|
2005-10-27 20:30:37 +02:00
|
|
|
#include "winternl.h"
|
2005-03-30 21:02:15 +02:00
|
|
|
|
|
|
|
#include "file.h"
|
|
|
|
#include "handle.h"
|
|
|
|
#include "thread.h"
|
|
|
|
#include "request.h"
|
|
|
|
|
|
|
|
struct mailslot
|
|
|
|
{
|
|
|
|
struct object obj;
|
|
|
|
struct fd *fd;
|
2007-04-12 20:19:28 +02:00
|
|
|
int write_fd;
|
2005-03-30 21:02:15 +02:00
|
|
|
unsigned int max_msgsize;
|
2007-04-17 20:08:59 +02:00
|
|
|
timeout_t read_timeout;
|
2005-03-30 21:02:15 +02:00
|
|
|
struct list writers;
|
|
|
|
};
|
|
|
|
|
|
|
|
/* mailslot functions */
|
|
|
|
static void mailslot_dump( struct object*, int );
|
|
|
|
static struct fd *mailslot_get_fd( struct object * );
|
2005-12-12 16:46:17 +01:00
|
|
|
static unsigned int mailslot_map_access( struct object *obj, unsigned int access );
|
2007-03-22 16:36:54 +01:00
|
|
|
static struct object *mailslot_open_file( struct object *obj, unsigned int access,
|
|
|
|
unsigned int sharing, unsigned int options );
|
2005-03-30 21:02:15 +02:00
|
|
|
static void mailslot_destroy( struct object * );
|
|
|
|
|
|
|
|
static const struct object_ops mailslot_ops =
|
|
|
|
{
|
|
|
|
sizeof(struct mailslot), /* size */
|
|
|
|
mailslot_dump, /* dump */
|
2007-04-04 19:39:29 +02:00
|
|
|
add_queue, /* add_queue */
|
|
|
|
remove_queue, /* remove_queue */
|
2005-03-30 21:02:15 +02:00
|
|
|
default_fd_signaled, /* signaled */
|
|
|
|
no_satisfied, /* satisfied */
|
2005-04-24 19:35:52 +02:00
|
|
|
no_signal, /* signal */
|
2005-03-30 21:02:15 +02:00
|
|
|
mailslot_get_fd, /* get_fd */
|
2005-12-12 16:46:17 +01:00
|
|
|
mailslot_map_access, /* map_access */
|
2007-10-03 14:10:37 +02:00
|
|
|
default_get_sd, /* get_sd */
|
|
|
|
default_set_sd, /* set_sd */
|
2005-11-22 15:55:42 +01:00
|
|
|
no_lookup_name, /* lookup_name */
|
2007-03-22 16:36:54 +01:00
|
|
|
mailslot_open_file, /* open_file */
|
2006-11-02 20:52:22 +01:00
|
|
|
fd_close_handle, /* close_handle */
|
2005-03-30 21:02:15 +02:00
|
|
|
mailslot_destroy /* destroy */
|
|
|
|
};
|
|
|
|
|
2007-04-10 22:26:23 +02:00
|
|
|
static enum server_fd_type mailslot_get_fd_type( struct fd *fd );
|
2007-03-20 20:21:12 +01:00
|
|
|
static void mailslot_queue_async( struct fd *fd, const async_data_t *data, int type, int count );
|
2005-03-30 21:02:15 +02:00
|
|
|
|
|
|
|
static const struct fd_ops mailslot_fd_ops =
|
|
|
|
{
|
2005-07-14 14:18:05 +02:00
|
|
|
default_fd_get_poll_events, /* get_poll_events */
|
|
|
|
default_poll_event, /* poll_event */
|
|
|
|
no_flush, /* flush */
|
2007-04-10 22:26:23 +02:00
|
|
|
mailslot_get_fd_type, /* get_fd_type */
|
2007-04-16 14:45:03 +02:00
|
|
|
default_fd_ioctl, /* ioctl */
|
2005-07-14 14:18:05 +02:00
|
|
|
mailslot_queue_async, /* queue_async */
|
2007-04-10 17:07:27 +02:00
|
|
|
default_fd_reselect_async, /* reselect_async */
|
2005-07-14 14:18:05 +02:00
|
|
|
default_fd_cancel_async /* cancel_async */
|
2005-03-30 21:02:15 +02:00
|
|
|
};
|
|
|
|
|
2005-12-12 16:46:17 +01:00
|
|
|
|
2005-03-30 21:02:15 +02:00
|
|
|
struct mail_writer
|
|
|
|
{
|
|
|
|
struct object obj;
|
2007-04-12 20:19:28 +02:00
|
|
|
struct fd *fd;
|
2005-03-30 21:02:15 +02:00
|
|
|
struct mailslot *mailslot;
|
|
|
|
struct list entry;
|
2005-12-12 16:46:17 +01:00
|
|
|
unsigned int access;
|
|
|
|
unsigned int sharing;
|
2005-03-30 21:02:15 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
static void mail_writer_dump( struct object *obj, int verbose );
|
|
|
|
static struct fd *mail_writer_get_fd( struct object *obj );
|
2005-12-12 16:46:17 +01:00
|
|
|
static unsigned int mail_writer_map_access( struct object *obj, unsigned int access );
|
2005-03-30 21:02:15 +02:00
|
|
|
static void mail_writer_destroy( struct object *obj);
|
|
|
|
|
|
|
|
static const struct object_ops mail_writer_ops =
|
|
|
|
{
|
|
|
|
sizeof(struct mail_writer), /* size */
|
|
|
|
mail_writer_dump, /* dump */
|
|
|
|
no_add_queue, /* add_queue */
|
|
|
|
NULL, /* remove_queue */
|
|
|
|
NULL, /* signaled */
|
|
|
|
NULL, /* satisfied */
|
2005-04-24 19:35:52 +02:00
|
|
|
no_signal, /* signal */
|
2005-03-30 21:02:15 +02:00
|
|
|
mail_writer_get_fd, /* get_fd */
|
2005-12-12 16:46:17 +01:00
|
|
|
mail_writer_map_access, /* map_access */
|
2007-10-03 14:10:37 +02:00
|
|
|
default_get_sd, /* get_sd */
|
|
|
|
default_set_sd, /* set_sd */
|
2005-11-22 15:55:42 +01:00
|
|
|
no_lookup_name, /* lookup_name */
|
2007-03-22 11:44:29 +01:00
|
|
|
no_open_file, /* open_file */
|
2006-11-02 20:52:22 +01:00
|
|
|
fd_close_handle, /* close_handle */
|
2005-03-30 21:02:15 +02:00
|
|
|
mail_writer_destroy /* destroy */
|
|
|
|
};
|
|
|
|
|
2007-04-10 22:26:23 +02:00
|
|
|
static enum server_fd_type mail_writer_get_fd_type( struct fd *fd );
|
2005-03-30 21:02:15 +02:00
|
|
|
|
|
|
|
static const struct fd_ops mail_writer_fd_ops =
|
|
|
|
{
|
2007-04-12 20:19:28 +02:00
|
|
|
default_fd_get_poll_events, /* get_poll_events */
|
|
|
|
default_poll_event, /* poll_event */
|
2005-03-30 21:02:15 +02:00
|
|
|
no_flush, /* flush */
|
2007-04-10 22:26:23 +02:00
|
|
|
mail_writer_get_fd_type, /* get_fd_type */
|
2007-04-16 14:45:03 +02:00
|
|
|
default_fd_ioctl, /* ioctl */
|
2007-04-12 20:19:28 +02:00
|
|
|
default_fd_queue_async, /* queue_async */
|
|
|
|
default_fd_reselect_async, /* reselect_async */
|
|
|
|
default_fd_cancel_async /* cancel_async */
|
2005-03-30 21:02:15 +02:00
|
|
|
};
|
|
|
|
|
2005-12-12 16:46:17 +01:00
|
|
|
|
|
|
|
struct mailslot_device
|
|
|
|
{
|
|
|
|
struct object obj; /* object header */
|
|
|
|
struct fd *fd; /* pseudo-fd for ioctls */
|
|
|
|
struct namespace *mailslots; /* mailslot namespace */
|
|
|
|
};
|
|
|
|
|
2005-12-05 13:30:26 +01:00
|
|
|
static void mailslot_device_dump( struct object *obj, int verbose );
|
2005-12-12 14:39:27 +01:00
|
|
|
static struct fd *mailslot_device_get_fd( struct object *obj );
|
2005-12-05 13:30:26 +01:00
|
|
|
static struct object *mailslot_device_lookup_name( struct object *obj, struct unicode_str *name,
|
|
|
|
unsigned int attr );
|
2007-03-22 11:52:40 +01:00
|
|
|
static struct object *mailslot_device_open_file( struct object *obj, unsigned int access,
|
|
|
|
unsigned int sharing, unsigned int options );
|
2005-12-05 13:30:26 +01:00
|
|
|
static void mailslot_device_destroy( struct object *obj );
|
2007-04-10 22:26:23 +02:00
|
|
|
static enum server_fd_type mailslot_device_get_fd_type( struct fd *fd );
|
2005-12-05 13:30:26 +01:00
|
|
|
|
|
|
|
static const struct object_ops mailslot_device_ops =
|
|
|
|
{
|
|
|
|
sizeof(struct mailslot_device), /* size */
|
2005-12-12 14:39:27 +01:00
|
|
|
mailslot_device_dump, /* dump */
|
|
|
|
no_add_queue, /* add_queue */
|
|
|
|
NULL, /* remove_queue */
|
|
|
|
NULL, /* signaled */
|
|
|
|
no_satisfied, /* satisfied */
|
|
|
|
no_signal, /* signal */
|
|
|
|
mailslot_device_get_fd, /* get_fd */
|
2005-12-12 14:57:40 +01:00
|
|
|
no_map_access, /* map_access */
|
2007-10-03 14:10:37 +02:00
|
|
|
default_get_sd, /* get_sd */
|
|
|
|
default_set_sd, /* set_sd */
|
2005-12-12 14:39:27 +01:00
|
|
|
mailslot_device_lookup_name, /* lookup_name */
|
2007-03-22 11:52:40 +01:00
|
|
|
mailslot_device_open_file, /* open_file */
|
2006-11-02 20:52:22 +01:00
|
|
|
fd_close_handle, /* close_handle */
|
2005-12-12 14:39:27 +01:00
|
|
|
mailslot_device_destroy /* destroy */
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct fd_ops mailslot_device_fd_ops =
|
|
|
|
{
|
2005-12-13 12:00:11 +01:00
|
|
|
default_fd_get_poll_events, /* get_poll_events */
|
|
|
|
default_poll_event, /* poll_event */
|
|
|
|
no_flush, /* flush */
|
2007-04-10 22:26:23 +02:00
|
|
|
mailslot_device_get_fd_type, /* get_fd_type */
|
2007-04-16 14:45:03 +02:00
|
|
|
default_fd_ioctl, /* ioctl */
|
2005-12-13 12:00:11 +01:00
|
|
|
default_fd_queue_async, /* queue_async */
|
2007-04-10 17:07:27 +02:00
|
|
|
default_fd_reselect_async, /* reselect_async */
|
2005-12-13 12:00:11 +01:00
|
|
|
default_fd_cancel_async /* cancel_async */
|
2005-12-05 13:30:26 +01:00
|
|
|
};
|
|
|
|
|
2005-03-30 21:02:15 +02:00
|
|
|
static void mailslot_destroy( struct object *obj)
|
|
|
|
{
|
|
|
|
struct mailslot *mailslot = (struct mailslot *) obj;
|
|
|
|
|
|
|
|
assert( mailslot->fd );
|
|
|
|
|
2007-04-12 20:19:28 +02:00
|
|
|
if (mailslot->write_fd != -1)
|
|
|
|
{
|
|
|
|
shutdown( mailslot->write_fd, SHUT_RDWR );
|
|
|
|
close( mailslot->write_fd );
|
|
|
|
}
|
2005-03-30 21:02:15 +02: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 20:08:59 +02:00
|
|
|
fprintf( stderr, "Mailslot max_msgsize=%d read_timeout=%s\n",
|
|
|
|
mailslot->max_msgsize, get_timeout_str(mailslot->read_timeout) );
|
2005-03-30 21:02:15 +02:00
|
|
|
}
|
|
|
|
|
2007-04-10 22:26:23 +02:00
|
|
|
static enum server_fd_type mailslot_get_fd_type( struct fd *fd )
|
2005-03-30 21:02:15 +02:00
|
|
|
{
|
2006-11-20 14:14:04 +01:00
|
|
|
return FD_TYPE_MAILSLOT;
|
2005-03-30 21:02:15 +02: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 16:46:17 +01:00
|
|
|
static unsigned int mailslot_map_access( struct object *obj, unsigned int access )
|
|
|
|
{
|
2007-04-02 20:24:55 +02:00
|
|
|
/* mailslots can only be read */
|
2005-12-12 16:46:17 +01:00
|
|
|
if (access & GENERIC_READ) access |= FILE_GENERIC_READ;
|
2007-04-02 20:24:55 +02:00
|
|
|
if (access & GENERIC_ALL) access |= FILE_GENERIC_READ;
|
2005-12-12 16:46:17 +01:00
|
|
|
return access & ~(GENERIC_READ | GENERIC_WRITE | GENERIC_EXECUTE | GENERIC_ALL);
|
|
|
|
}
|
|
|
|
|
2007-03-22 16:36:54 +01: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;
|
2007-04-12 20:19:28 +02:00
|
|
|
int unix_fd;
|
2007-03-22 16:36:54 +01:00
|
|
|
|
|
|
|
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 20:19:28 +02:00
|
|
|
if ((unix_fd = dup( mailslot->write_fd )) == -1)
|
|
|
|
{
|
|
|
|
file_set_error();
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
if (!(writer = alloc_object( &mail_writer_ops )))
|
|
|
|
{
|
|
|
|
close( unix_fd );
|
|
|
|
return NULL;
|
|
|
|
}
|
2007-03-22 16:36:54 +01: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 20:19:28 +02:00
|
|
|
|
|
|
|
if (!(writer->fd = create_anonymous_fd( &mail_writer_fd_ops, unix_fd, &writer->obj, options )))
|
|
|
|
{
|
|
|
|
release_object( writer );
|
|
|
|
return NULL;
|
|
|
|
}
|
2007-03-22 16:36:54 +01:00
|
|
|
return &writer->obj;
|
|
|
|
}
|
|
|
|
|
2007-03-20 20:21:12 +01:00
|
|
|
static void mailslot_queue_async( struct fd *fd, const async_data_t *data, int type, int count )
|
2005-03-30 21:02:15 +02:00
|
|
|
{
|
|
|
|
struct mailslot *mailslot = get_fd_user( fd );
|
2007-04-02 20:41:59 +02:00
|
|
|
struct async *async;
|
2005-03-30 21:02:15 +02:00
|
|
|
|
|
|
|
assert(mailslot->obj.ops == &mailslot_ops);
|
|
|
|
|
2007-04-02 20:41:59 +02:00
|
|
|
if ((async = fd_queue_async( fd, data, type, count )))
|
2006-07-26 11:47:42 +02:00
|
|
|
{
|
2007-04-17 20:08:59 +02:00
|
|
|
async_set_timeout( async, mailslot->read_timeout ? mailslot->read_timeout : -1,
|
|
|
|
STATUS_IO_TIMEOUT );
|
2007-04-02 20:41:59 +02:00
|
|
|
release_object( async );
|
|
|
|
set_error( STATUS_PENDING );
|
2006-07-26 11:47:42 +02:00
|
|
|
}
|
2005-03-30 21:02:15 +02:00
|
|
|
}
|
|
|
|
|
2005-12-05 13:30:26 +01:00
|
|
|
static void mailslot_device_dump( struct object *obj, int verbose )
|
|
|
|
{
|
|
|
|
assert( obj->ops == &mailslot_device_ops );
|
|
|
|
fprintf( stderr, "Mail slot device\n" );
|
|
|
|
}
|
|
|
|
|
2005-12-12 14:39:27 +01:00
|
|
|
static struct fd *mailslot_device_get_fd( struct object *obj )
|
|
|
|
{
|
|
|
|
struct mailslot_device *device = (struct mailslot_device *)obj;
|
2005-12-13 11:22:28 +01:00
|
|
|
return (struct fd *)grab_object( device->fd );
|
2005-12-12 14:39:27 +01:00
|
|
|
}
|
|
|
|
|
2005-12-05 13:30:26 +01:00
|
|
|
static struct object *mailslot_device_lookup_name( struct object *obj, struct unicode_str *name,
|
|
|
|
unsigned int attr )
|
|
|
|
{
|
|
|
|
struct mailslot_device *device = (struct mailslot_device*)obj;
|
|
|
|
struct object *found;
|
|
|
|
|
|
|
|
assert( obj->ops == &mailslot_device_ops );
|
|
|
|
|
|
|
|
if ((found = find_object( device->mailslots, name, attr | OBJ_CASE_INSENSITIVE )))
|
|
|
|
name->len = 0;
|
|
|
|
|
|
|
|
return found;
|
|
|
|
}
|
|
|
|
|
2007-03-22 11:52:40 +01:00
|
|
|
static struct object *mailslot_device_open_file( struct object *obj, unsigned int access,
|
|
|
|
unsigned int sharing, unsigned int options )
|
|
|
|
{
|
|
|
|
return grab_object( obj );
|
|
|
|
}
|
|
|
|
|
2005-12-05 13:30:26 +01:00
|
|
|
static void mailslot_device_destroy( struct object *obj )
|
|
|
|
{
|
|
|
|
struct mailslot_device *device = (struct mailslot_device*)obj;
|
|
|
|
assert( obj->ops == &mailslot_device_ops );
|
2005-12-12 14:39:27 +01:00
|
|
|
if (device->fd) release_object( device->fd );
|
2006-10-09 23:34:36 +02:00
|
|
|
free( device->mailslots );
|
2005-12-05 13:30:26 +01:00
|
|
|
}
|
|
|
|
|
2007-04-10 22:26:23 +02:00
|
|
|
static enum server_fd_type mailslot_device_get_fd_type( struct fd *fd )
|
2005-12-13 12:00:11 +01:00
|
|
|
{
|
2006-11-20 14:14:04 +01:00
|
|
|
return FD_TYPE_DEVICE;
|
2005-12-13 12:00:11 +01:00
|
|
|
}
|
|
|
|
|
2006-03-22 20:32:04 +01:00
|
|
|
void create_mailslot_device( struct directory *root, const struct unicode_str *name )
|
2005-12-05 13:30:26 +01:00
|
|
|
{
|
|
|
|
struct mailslot_device *dev;
|
|
|
|
|
2005-12-05 14:52:02 +01:00
|
|
|
if ((dev = create_named_object_dir( root, name, 0, &mailslot_device_ops )) &&
|
2005-12-05 13:30:26 +01:00
|
|
|
get_error() != STATUS_OBJECT_NAME_EXISTS)
|
|
|
|
{
|
2005-12-12 14:39:27 +01:00
|
|
|
dev->mailslots = NULL;
|
2007-05-03 16:07:30 +02:00
|
|
|
if (!(dev->fd = alloc_pseudo_fd( &mailslot_device_fd_ops, &dev->obj, 0 )) ||
|
2005-12-12 14:39:27 +01:00
|
|
|
!(dev->mailslots = create_namespace( 7 )))
|
2005-12-05 13:30:26 +01:00
|
|
|
{
|
|
|
|
release_object( dev );
|
|
|
|
dev = NULL;
|
|
|
|
}
|
|
|
|
}
|
2006-03-22 20:32:04 +01:00
|
|
|
if (dev) make_object_static( &dev->obj );
|
2005-12-05 13:30:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static struct mailslot *create_mailslot( struct directory *root,
|
|
|
|
const struct unicode_str *name, unsigned int attr,
|
2007-04-17 20:08:59 +02:00
|
|
|
int max_msgsize, timeout_t read_timeout )
|
2005-03-30 21:02:15 +02:00
|
|
|
{
|
2005-12-05 13:30:26 +01:00
|
|
|
struct object *obj;
|
|
|
|
struct unicode_str new_name;
|
|
|
|
struct mailslot_device *dev;
|
2005-03-30 21:02:15 +02:00
|
|
|
struct mailslot *mailslot;
|
|
|
|
int fds[2];
|
|
|
|
|
2005-12-05 13:30:26 +01:00
|
|
|
if (!name || !name->len) return alloc_object( &mailslot_ops );
|
|
|
|
|
2007-03-22 14:41:37 +01:00
|
|
|
if (!(obj = find_object_dir( root, name, attr, &new_name )))
|
|
|
|
{
|
|
|
|
set_error( STATUS_OBJECT_NAME_INVALID );
|
|
|
|
return NULL;
|
|
|
|
}
|
2005-12-05 13:30:26 +01:00
|
|
|
|
|
|
|
if (!new_name.len)
|
2005-03-30 21:02:15 +02:00
|
|
|
{
|
2005-12-05 13:30:26 +01:00
|
|
|
if (attr & OBJ_OPENIF && obj->ops == &mailslot_ops)
|
|
|
|
/* it already exists - there can only be one mailslot to read from */
|
|
|
|
set_error( STATUS_OBJECT_NAME_EXISTS );
|
|
|
|
else if (attr & OBJ_OPENIF)
|
|
|
|
set_error( STATUS_OBJECT_TYPE_MISMATCH );
|
|
|
|
else
|
|
|
|
set_error( STATUS_OBJECT_NAME_COLLISION );
|
|
|
|
release_object( obj );
|
2005-03-30 21:02:15 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2005-12-05 13:30:26 +01:00
|
|
|
if (obj->ops != &mailslot_device_ops)
|
2005-03-30 21:02:15 +02:00
|
|
|
{
|
2007-03-22 14:41:37 +01:00
|
|
|
set_error( STATUS_OBJECT_NAME_INVALID );
|
2005-12-05 13:30:26 +01:00
|
|
|
release_object( obj );
|
2005-03-30 21:02:15 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2005-12-05 13:30:26 +01:00
|
|
|
dev = (struct mailslot_device *)obj;
|
|
|
|
mailslot = create_object( dev->mailslots, &mailslot_ops, &new_name, NULL );
|
|
|
|
release_object( dev );
|
|
|
|
|
|
|
|
if (!mailslot) return NULL;
|
|
|
|
|
2005-03-30 21:02:15 +02:00
|
|
|
mailslot->fd = NULL;
|
2007-04-12 20:19:28 +02:00
|
|
|
mailslot->write_fd = -1;
|
2005-03-30 21:02:15 +02:00
|
|
|
mailslot->max_msgsize = max_msgsize;
|
|
|
|
mailslot->read_timeout = read_timeout;
|
|
|
|
list_init( &mailslot->writers );
|
|
|
|
|
2005-06-10 21:54:46 +02:00
|
|
|
if (!socketpair( PF_UNIX, SOCK_DGRAM, 0, fds ))
|
2005-03-30 21:02:15 +02:00
|
|
|
{
|
|
|
|
fcntl( fds[0], F_SETFL, O_NONBLOCK );
|
|
|
|
fcntl( fds[1], F_SETFL, O_NONBLOCK );
|
2007-04-10 21:30:37 +02:00
|
|
|
shutdown( fds[0], SHUT_RD );
|
2007-04-12 20:19:28 +02:00
|
|
|
mailslot->write_fd = fds[0];
|
2007-04-10 22:25:07 +02:00
|
|
|
mailslot->fd = create_anonymous_fd( &mailslot_fd_ops, fds[1], &mailslot->obj,
|
|
|
|
FILE_SYNCHRONOUS_IO_NONALERT );
|
2007-04-12 20:19:28 +02:00
|
|
|
if (mailslot->fd) return mailslot;
|
2005-03-30 21:02:15 +02:00
|
|
|
}
|
|
|
|
else file_set_error();
|
|
|
|
|
|
|
|
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 20:19:28 +02:00
|
|
|
if (writer->fd) release_object( writer->fd );
|
2005-03-30 21:02:15 +02:00
|
|
|
list_remove( &writer->entry );
|
|
|
|
release_object( writer->mailslot );
|
|
|
|
}
|
|
|
|
|
2007-04-10 22:26:23 +02:00
|
|
|
static enum server_fd_type mail_writer_get_fd_type( struct fd *fd )
|
2005-03-30 21:02:15 +02:00
|
|
|
{
|
2006-11-20 14:14:04 +01:00
|
|
|
return FD_TYPE_MAILSLOT;
|
2005-03-30 21:02:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static struct fd *mail_writer_get_fd( struct object *obj )
|
|
|
|
{
|
|
|
|
struct mail_writer *writer = (struct mail_writer *) obj;
|
2007-04-12 20:19:28 +02:00
|
|
|
return (struct fd *)grab_object( writer->fd );
|
2005-03-30 21:02:15 +02:00
|
|
|
}
|
|
|
|
|
2005-12-12 16:46:17 +01:00
|
|
|
static unsigned int mail_writer_map_access( struct object *obj, unsigned int access )
|
|
|
|
{
|
2007-03-22 16:36:54 +01:00
|
|
|
/* mailslot writers can only get write access */
|
2005-12-12 16:46:17 +01:00
|
|
|
if (access & GENERIC_WRITE) access |= FILE_GENERIC_WRITE;
|
2007-03-22 16:36:54 +01:00
|
|
|
if (access & GENERIC_ALL) access |= FILE_GENERIC_WRITE;
|
2005-12-12 16:46:17 +01:00
|
|
|
return access & ~(GENERIC_READ | GENERIC_WRITE | GENERIC_EXECUTE | GENERIC_ALL);
|
|
|
|
}
|
|
|
|
|
2005-03-30 21:02:15 +02:00
|
|
|
static struct mailslot *get_mailslot_obj( struct process *process, obj_handle_t handle,
|
|
|
|
unsigned int access )
|
|
|
|
{
|
2005-12-05 13:30:26 +01:00
|
|
|
return (struct mailslot *)get_handle_obj( process, handle, access, &mailslot_ops );
|
2005-03-30 21:02:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* create a mailslot */
|
|
|
|
DECL_HANDLER(create_mailslot)
|
|
|
|
{
|
|
|
|
struct mailslot *mailslot;
|
2005-11-18 17:31:18 +01:00
|
|
|
struct unicode_str name;
|
2005-12-05 13:30:26 +01:00
|
|
|
struct directory *root = NULL;
|
2005-03-30 21:02:15 +02:00
|
|
|
|
|
|
|
reply->handle = 0;
|
2005-11-18 17:31:18 +01:00
|
|
|
get_req_unicode_str( &name );
|
2005-12-05 13:30:26 +01:00
|
|
|
if (req->rootdir && !(root = get_directory_obj( current->process, req->rootdir, 0 )))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if ((mailslot = create_mailslot( root, &name, req->attributes, req->max_msgsize,
|
|
|
|
req->read_timeout )))
|
2005-03-30 21:02:15 +02:00
|
|
|
{
|
2005-12-09 13:58:25 +01:00
|
|
|
reply->handle = alloc_handle( current->process, mailslot, req->access, req->attributes );
|
2005-03-30 21:02:15 +02:00
|
|
|
release_object( mailslot );
|
|
|
|
}
|
2005-12-05 13:30:26 +01:00
|
|
|
|
|
|
|
if (root) release_object( root );
|
2005-03-30 21:02:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* set mailslot information */
|
|
|
|
DECL_HANDLER(set_mailslot_info)
|
|
|
|
{
|
|
|
|
struct mailslot *mailslot = get_mailslot_obj( current->process, req->handle, 0 );
|
|
|
|
|
2005-06-10 21:54:46 +02:00
|
|
|
if (mailslot)
|
2005-03-30 21:02:15 +02:00
|
|
|
{
|
2005-06-10 21:54:46 +02:00
|
|
|
if (req->flags & MAILSLOT_SET_READ_TIMEOUT)
|
2005-03-30 21:02:15 +02:00
|
|
|
mailslot->read_timeout = req->read_timeout;
|
|
|
|
reply->max_msgsize = mailslot->max_msgsize;
|
|
|
|
reply->read_timeout = mailslot->read_timeout;
|
|
|
|
release_object( mailslot );
|
|
|
|
}
|
|
|
|
}
|