2004-04-16 13:28:34 +02:00
|
|
|
/* -*- c-basic-offset: 8 -*-
|
|
|
|
rdesktop: A Remote Desktop Protocol client.
|
2007-01-04 06:39:39 +01:00
|
|
|
Copyright (C) Matthew Chapman 1999-2007
|
2004-04-16 13:28:34 +02:00
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program 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 General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
Here are some resources, for your IRP hacking pleasure:
|
|
|
|
|
|
|
|
http://cvs.sourceforge.net/viewcvs.py/mingw/w32api/include/ddk/winddk.h?view=markup
|
|
|
|
|
|
|
|
http://win32.mvps.org/ntfs/streams.cpp
|
|
|
|
|
|
|
|
http://www.acc.umu.se/~bosse/ntifs.h
|
|
|
|
|
|
|
|
http://undocumented.ntinternals.net/UserMode/Undocumented%20Functions/NT%20Objects/File/
|
|
|
|
|
|
|
|
http://us1.samba.org/samba/ftp/specs/smb-nt01.txt
|
|
|
|
|
|
|
|
http://www.osronline.com/
|
|
|
|
*/
|
|
|
|
|
2004-01-21 19:02:38 +01:00
|
|
|
#include <unistd.h>
|
2004-01-22 21:31:59 +01:00
|
|
|
#include <sys/types.h>
|
2004-02-16 21:28:09 +01:00
|
|
|
#include <sys/time.h>
|
2004-03-04 09:24:40 +01:00
|
|
|
#include <dirent.h> /* opendir, closedir, readdir */
|
2004-01-22 21:31:59 +01:00
|
|
|
#include <time.h>
|
2004-04-19 11:21:25 +02:00
|
|
|
#include <errno.h>
|
2003-07-01 11:31:25 +02:00
|
|
|
#include "rdesktop.h"
|
|
|
|
|
2004-01-21 15:40:40 +01:00
|
|
|
#define IRP_MJ_CREATE 0x00
|
|
|
|
#define IRP_MJ_CLOSE 0x02
|
|
|
|
#define IRP_MJ_READ 0x03
|
|
|
|
#define IRP_MJ_WRITE 0x04
|
|
|
|
#define IRP_MJ_QUERY_INFORMATION 0x05
|
|
|
|
#define IRP_MJ_SET_INFORMATION 0x06
|
|
|
|
#define IRP_MJ_QUERY_VOLUME_INFORMATION 0x0a
|
|
|
|
#define IRP_MJ_DIRECTORY_CONTROL 0x0c
|
|
|
|
#define IRP_MJ_DEVICE_CONTROL 0x0e
|
2004-04-15 22:11:19 +02:00
|
|
|
#define IRP_MJ_LOCK_CONTROL 0x11
|
2004-01-21 15:40:40 +01:00
|
|
|
|
|
|
|
#define IRP_MN_QUERY_DIRECTORY 0x01
|
|
|
|
#define IRP_MN_NOTIFY_CHANGE_DIRECTORY 0x02
|
|
|
|
|
2004-06-16 00:17:08 +02:00
|
|
|
extern char g_hostname[16];
|
2003-07-01 11:31:25 +02:00
|
|
|
extern DEVICE_FNS serial_fns;
|
|
|
|
extern DEVICE_FNS printer_fns;
|
2004-01-21 15:40:40 +01:00
|
|
|
extern DEVICE_FNS parallel_fns;
|
|
|
|
extern DEVICE_FNS disk_fns;
|
2006-11-01 21:52:01 +01:00
|
|
|
#ifdef WITH_SCARD
|
|
|
|
extern DEVICE_FNS scard_fns;
|
|
|
|
#endif
|
2004-03-04 09:24:40 +01:00
|
|
|
extern FILEINFO g_fileinfo[];
|
2007-01-08 05:47:06 +01:00
|
|
|
extern RD_BOOL g_notify_stamp;
|
2004-04-19 10:24:54 +02:00
|
|
|
|
2003-07-01 11:31:25 +02:00
|
|
|
static VCHANNEL *rdpdr_channel;
|
|
|
|
|
2004-01-21 15:40:40 +01:00
|
|
|
/* If select() times out, the request for the device with handle g_min_timeout_fd is aborted */
|
2007-01-04 05:55:56 +01:00
|
|
|
RD_NTHANDLE g_min_timeout_fd;
|
2004-01-21 15:40:40 +01:00
|
|
|
uint32 g_num_devices;
|
|
|
|
|
|
|
|
/* Table with information about rdpdr devices */
|
|
|
|
RDPDR_DEVICE g_rdpdr_device[RDPDR_MAX_DEVICES];
|
2004-04-15 22:12:42 +02:00
|
|
|
char *g_rdpdr_clientname = NULL;
|
2004-01-21 15:40:40 +01:00
|
|
|
|
|
|
|
/* Used to store incoming io request, until they are ready to be completed */
|
2004-01-30 15:10:32 +01:00
|
|
|
/* using a linked list ensures that they are processed in the right order, */
|
|
|
|
/* if multiple ios are being done on the same fd */
|
2004-01-21 15:40:40 +01:00
|
|
|
struct async_iorequest
|
|
|
|
{
|
2004-01-30 15:10:32 +01:00
|
|
|
uint32 fd, major, minor, offset, device, id, length, partial_len;
|
2004-01-21 15:40:40 +01:00
|
|
|
long timeout, /* Total timeout */
|
|
|
|
itv_timeout; /* Interval timeout (between serial characters) */
|
|
|
|
uint8 *buffer;
|
|
|
|
DEVICE_FNS *fns;
|
2004-01-30 15:10:32 +01:00
|
|
|
|
|
|
|
struct async_iorequest *next; /* next element in list */
|
2004-02-02 08:06:55 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
struct async_iorequest *g_iorequest;
|
2004-01-21 15:40:40 +01:00
|
|
|
|
|
|
|
/* Return device_id for a given handle */
|
|
|
|
int
|
2007-01-04 05:55:56 +01:00
|
|
|
get_device_index(RD_NTHANDLE handle)
|
2004-01-21 15:40:40 +01:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
for (i = 0; i < RDPDR_MAX_DEVICES; i++)
|
|
|
|
{
|
|
|
|
if (g_rdpdr_device[i].handle == handle)
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Converts a windows path to a unix path */
|
|
|
|
void
|
|
|
|
convert_to_unix_filename(char *filename)
|
|
|
|
{
|
|
|
|
char *p;
|
|
|
|
|
|
|
|
while ((p = strchr(filename, '\\')))
|
|
|
|
{
|
|
|
|
*p = '/';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-01-08 05:47:06 +01:00
|
|
|
static RD_BOOL
|
2004-03-04 09:24:40 +01:00
|
|
|
rdpdr_handle_ok(int device, int handle)
|
|
|
|
{
|
|
|
|
switch (g_rdpdr_device[device].device_type)
|
|
|
|
{
|
|
|
|
case DEVICE_TYPE_PARALLEL:
|
|
|
|
case DEVICE_TYPE_SERIAL:
|
|
|
|
case DEVICE_TYPE_PRINTER:
|
|
|
|
case DEVICE_TYPE_SCARD:
|
|
|
|
if (g_rdpdr_device[device].handle != handle)
|
|
|
|
return False;
|
|
|
|
break;
|
|
|
|
case DEVICE_TYPE_DISK:
|
|
|
|
if (g_fileinfo[handle].device_id != device)
|
|
|
|
return False;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return True;
|
|
|
|
}
|
|
|
|
|
2004-01-21 15:40:40 +01:00
|
|
|
/* Add a new io request to the table containing pending io requests so it won't block rdesktop */
|
2007-01-08 05:47:06 +01:00
|
|
|
static RD_BOOL
|
2004-01-21 15:40:40 +01:00
|
|
|
add_async_iorequest(uint32 device, uint32 file, uint32 id, uint32 major, uint32 length,
|
2004-02-23 11:34:18 +01:00
|
|
|
DEVICE_FNS * fns, uint32 total_timeout, uint32 interval_timeout, uint8 * buffer,
|
|
|
|
uint32 offset)
|
2004-01-21 15:40:40 +01:00
|
|
|
{
|
|
|
|
struct async_iorequest *iorq;
|
|
|
|
|
2004-02-02 08:06:55 +01:00
|
|
|
if (g_iorequest == NULL)
|
2004-01-21 15:40:40 +01:00
|
|
|
{
|
2004-02-02 08:06:55 +01:00
|
|
|
g_iorequest = (struct async_iorequest *) xmalloc(sizeof(struct async_iorequest));
|
2004-02-23 10:58:16 +01:00
|
|
|
if (!g_iorequest)
|
|
|
|
return False;
|
2004-02-02 08:06:55 +01:00
|
|
|
g_iorequest->fd = 0;
|
|
|
|
g_iorequest->next = NULL;
|
2004-01-30 15:10:32 +01:00
|
|
|
}
|
|
|
|
|
2004-02-02 08:06:55 +01:00
|
|
|
iorq = g_iorequest;
|
|
|
|
|
|
|
|
while (iorq->fd != 0)
|
2004-01-30 15:10:32 +01:00
|
|
|
{
|
2005-03-15 12:25:50 +01:00
|
|
|
/* create new element if needed */
|
2004-02-02 08:06:55 +01:00
|
|
|
if (iorq->next == NULL)
|
2004-01-30 15:10:32 +01:00
|
|
|
{
|
|
|
|
iorq->next =
|
|
|
|
(struct async_iorequest *) xmalloc(sizeof(struct async_iorequest));
|
2004-02-23 10:58:16 +01:00
|
|
|
if (!iorq->next)
|
|
|
|
return False;
|
2004-02-02 08:06:55 +01:00
|
|
|
iorq->next->fd = 0;
|
|
|
|
iorq->next->next = NULL;
|
2004-01-21 15:40:40 +01:00
|
|
|
}
|
2004-02-02 08:06:55 +01:00
|
|
|
iorq = iorq->next;
|
2004-01-21 15:40:40 +01:00
|
|
|
}
|
2004-01-30 15:10:32 +01:00
|
|
|
iorq->device = device;
|
|
|
|
iorq->fd = file;
|
|
|
|
iorq->id = id;
|
|
|
|
iorq->major = major;
|
|
|
|
iorq->length = length;
|
|
|
|
iorq->partial_len = 0;
|
|
|
|
iorq->fns = fns;
|
|
|
|
iorq->timeout = total_timeout;
|
|
|
|
iorq->itv_timeout = interval_timeout;
|
|
|
|
iorq->buffer = buffer;
|
2004-02-23 11:34:18 +01:00
|
|
|
iorq->offset = offset;
|
2004-01-30 15:10:32 +01:00
|
|
|
return True;
|
2004-01-21 15:40:40 +01:00
|
|
|
}
|
|
|
|
|
2004-04-17 08:58:30 +02:00
|
|
|
static void
|
2003-07-01 11:31:25 +02:00
|
|
|
rdpdr_send_connect(void)
|
|
|
|
{
|
|
|
|
uint8 magic[4] = "rDCC";
|
|
|
|
STREAM s;
|
|
|
|
|
|
|
|
s = channel_init(rdpdr_channel, 12);
|
|
|
|
out_uint8a(s, magic, 4);
|
2003-07-09 11:18:20 +02:00
|
|
|
out_uint16_le(s, 1); /* unknown */
|
2003-07-01 11:31:25 +02:00
|
|
|
out_uint16_le(s, 5);
|
2003-07-09 11:18:20 +02:00
|
|
|
out_uint32_be(s, 0x815ed39d); /* IP address (use 127.0.0.1) 0x815ed39d */
|
2003-07-01 11:31:25 +02:00
|
|
|
s_mark_end(s);
|
|
|
|
channel_send(s, rdpdr_channel);
|
|
|
|
}
|
|
|
|
|
2004-01-21 15:40:40 +01:00
|
|
|
|
2004-04-17 08:58:30 +02:00
|
|
|
static void
|
2003-07-01 11:31:25 +02:00
|
|
|
rdpdr_send_name(void)
|
|
|
|
{
|
|
|
|
uint8 magic[4] = "rDNC";
|
2004-04-05 21:23:08 +02:00
|
|
|
STREAM s;
|
|
|
|
uint32 hostlen;
|
|
|
|
|
2004-04-15 22:12:42 +02:00
|
|
|
if (NULL == g_rdpdr_clientname)
|
|
|
|
{
|
2004-06-16 00:17:08 +02:00
|
|
|
g_rdpdr_clientname = g_hostname;
|
2004-04-02 17:34:38 +02:00
|
|
|
}
|
2004-04-05 21:23:08 +02:00
|
|
|
hostlen = (strlen(g_rdpdr_clientname) + 1) * 2;
|
2003-07-01 11:31:25 +02:00
|
|
|
|
2003-07-09 11:18:20 +02:00
|
|
|
s = channel_init(rdpdr_channel, 16 + hostlen);
|
2003-07-01 11:31:25 +02:00
|
|
|
out_uint8a(s, magic, 4);
|
2003-07-09 11:18:20 +02:00
|
|
|
out_uint16_le(s, 0x63); /* unknown */
|
2003-07-01 11:31:25 +02:00
|
|
|
out_uint16_le(s, 0x72);
|
|
|
|
out_uint32(s, 0);
|
|
|
|
out_uint32_le(s, hostlen);
|
2004-04-02 17:34:38 +02:00
|
|
|
rdp_out_unistr(s, g_rdpdr_clientname, hostlen - 2);
|
2003-07-01 11:31:25 +02:00
|
|
|
s_mark_end(s);
|
|
|
|
channel_send(s, rdpdr_channel);
|
|
|
|
}
|
|
|
|
|
2004-01-21 15:40:40 +01:00
|
|
|
/* Returns the size of the payload of the announce packet */
|
2004-04-17 08:58:30 +02:00
|
|
|
static int
|
2004-01-21 15:40:40 +01:00
|
|
|
announcedata_size()
|
|
|
|
{
|
|
|
|
int size, i;
|
|
|
|
PRINTER *printerinfo;
|
|
|
|
|
2005-03-15 12:25:50 +01:00
|
|
|
size = 8; /* static announce size */
|
2004-01-21 15:40:40 +01:00
|
|
|
size += g_num_devices * 0x14;
|
|
|
|
|
|
|
|
for (i = 0; i < g_num_devices; i++)
|
|
|
|
{
|
|
|
|
if (g_rdpdr_device[i].device_type == DEVICE_TYPE_PRINTER)
|
|
|
|
{
|
|
|
|
printerinfo = (PRINTER *) g_rdpdr_device[i].pdevice_data;
|
|
|
|
printerinfo->bloblen =
|
|
|
|
printercache_load_blob(printerinfo->printer, &(printerinfo->blob));
|
|
|
|
|
|
|
|
size += 0x18;
|
|
|
|
size += 2 * strlen(printerinfo->driver) + 2;
|
|
|
|
size += 2 * strlen(printerinfo->printer) + 2;
|
|
|
|
size += printerinfo->bloblen;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
2004-04-17 08:58:30 +02:00
|
|
|
static void
|
2003-07-01 11:31:25 +02:00
|
|
|
rdpdr_send_available(void)
|
|
|
|
{
|
2004-01-21 15:40:40 +01:00
|
|
|
|
2003-07-01 11:31:25 +02:00
|
|
|
uint8 magic[4] = "rDAD";
|
2004-01-21 15:40:40 +01:00
|
|
|
uint32 driverlen, printerlen, bloblen;
|
|
|
|
int i;
|
2003-07-01 11:31:25 +02:00
|
|
|
STREAM s;
|
2004-01-21 15:40:40 +01:00
|
|
|
PRINTER *printerinfo;
|
2003-07-01 11:31:25 +02:00
|
|
|
|
2004-01-21 15:40:40 +01:00
|
|
|
s = channel_init(rdpdr_channel, announcedata_size());
|
2003-07-01 11:31:25 +02:00
|
|
|
out_uint8a(s, magic, 4);
|
2004-01-21 15:40:40 +01:00
|
|
|
out_uint32_le(s, g_num_devices);
|
2003-07-01 11:31:25 +02:00
|
|
|
|
2004-01-21 15:40:40 +01:00
|
|
|
for (i = 0; i < g_num_devices; i++)
|
|
|
|
{
|
|
|
|
out_uint32_le(s, g_rdpdr_device[i].device_type);
|
|
|
|
out_uint32_le(s, i); /* RDP Device ID */
|
2004-08-09 15:50:41 +02:00
|
|
|
/* Is it possible to use share names longer than 8 chars?
|
|
|
|
/astrand */
|
2004-01-21 15:40:40 +01:00
|
|
|
out_uint8p(s, g_rdpdr_device[i].name, 8);
|
|
|
|
|
2004-01-27 22:15:18 +01:00
|
|
|
switch (g_rdpdr_device[i].device_type)
|
2004-01-21 15:40:40 +01:00
|
|
|
{
|
2004-01-27 22:15:18 +01:00
|
|
|
case DEVICE_TYPE_PRINTER:
|
|
|
|
printerinfo = (PRINTER *) g_rdpdr_device[i].pdevice_data;
|
|
|
|
|
|
|
|
driverlen = 2 * strlen(printerinfo->driver) + 2;
|
|
|
|
printerlen = 2 * strlen(printerinfo->printer) + 2;
|
|
|
|
bloblen = printerinfo->bloblen;
|
|
|
|
|
|
|
|
out_uint32_le(s, 24 + driverlen + printerlen + bloblen); /* length of extra info */
|
|
|
|
out_uint32_le(s, printerinfo->default_printer ? 2 : 0);
|
|
|
|
out_uint8s(s, 8); /* unknown */
|
|
|
|
out_uint32_le(s, driverlen);
|
|
|
|
out_uint32_le(s, printerlen);
|
|
|
|
out_uint32_le(s, bloblen);
|
|
|
|
rdp_out_unistr(s, printerinfo->driver, driverlen - 2);
|
|
|
|
rdp_out_unistr(s, printerinfo->printer, printerlen - 2);
|
|
|
|
out_uint8a(s, printerinfo->blob, bloblen);
|
|
|
|
|
2004-02-06 11:32:13 +01:00
|
|
|
if (printerinfo->blob)
|
|
|
|
xfree(printerinfo->blob); /* Blob is sent twice if reconnecting */
|
2004-01-27 22:15:18 +01:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
out_uint32(s, 0);
|
2004-01-21 15:40:40 +01:00
|
|
|
}
|
|
|
|
}
|
2003-07-01 11:31:25 +02:00
|
|
|
#if 0
|
2003-07-09 11:18:20 +02:00
|
|
|
out_uint32_le(s, 0x20); /* Device type 0x20 - smart card */
|
2003-07-01 11:31:25 +02:00
|
|
|
out_uint32_le(s, 0);
|
|
|
|
out_uint8p(s, "SCARD", 5);
|
|
|
|
out_uint8s(s, 3);
|
|
|
|
out_uint32(s, 0);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
s_mark_end(s);
|
|
|
|
channel_send(s, rdpdr_channel);
|
|
|
|
}
|
|
|
|
|
2006-11-01 21:52:01 +01:00
|
|
|
void
|
2003-07-09 11:18:20 +02:00
|
|
|
rdpdr_send_completion(uint32 device, uint32 id, uint32 status, uint32 result, uint8 * buffer,
|
|
|
|
uint32 length)
|
2003-07-01 11:31:25 +02:00
|
|
|
{
|
|
|
|
uint8 magic[4] = "rDCI";
|
|
|
|
STREAM s;
|
|
|
|
|
2006-11-04 00:51:35 +01:00
|
|
|
#ifdef WITH_SCARD
|
|
|
|
scard_lock(SCARD_LOCK_RDPDR);
|
|
|
|
#endif
|
2003-07-01 11:31:25 +02:00
|
|
|
s = channel_init(rdpdr_channel, 20 + length);
|
|
|
|
out_uint8a(s, magic, 4);
|
|
|
|
out_uint32_le(s, device);
|
|
|
|
out_uint32_le(s, id);
|
|
|
|
out_uint32_le(s, status);
|
|
|
|
out_uint32_le(s, result);
|
|
|
|
out_uint8p(s, buffer, length);
|
|
|
|
s_mark_end(s);
|
2004-11-03 14:56:52 +01:00
|
|
|
/* JIF */
|
|
|
|
#ifdef WITH_DEBUG_RDP5
|
|
|
|
printf("--> rdpdr_send_completion\n");
|
2005-03-15 12:25:50 +01:00
|
|
|
/* hexdump(s->channel_hdr + 8, s->end - s->channel_hdr - 8); */
|
2004-11-03 14:56:52 +01:00
|
|
|
#endif
|
2003-07-01 11:31:25 +02:00
|
|
|
channel_send(s, rdpdr_channel);
|
2006-11-04 00:51:35 +01:00
|
|
|
#ifdef WITH_SCARD
|
|
|
|
scard_unlock(SCARD_LOCK_RDPDR);
|
|
|
|
#endif
|
2003-07-01 11:31:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
rdpdr_process_irp(STREAM s)
|
|
|
|
{
|
2004-01-21 15:40:40 +01:00
|
|
|
uint32 result = 0,
|
|
|
|
length = 0,
|
|
|
|
desired_access = 0,
|
|
|
|
request,
|
|
|
|
file,
|
|
|
|
info_level,
|
|
|
|
buffer_len,
|
|
|
|
id,
|
|
|
|
major,
|
|
|
|
minor,
|
|
|
|
device,
|
|
|
|
offset,
|
|
|
|
bytes_in,
|
|
|
|
bytes_out,
|
|
|
|
error_mode,
|
|
|
|
share_mode, disposition, total_timeout, interval_timeout, flags_and_attributes = 0;
|
|
|
|
|
2005-08-15 13:44:35 +02:00
|
|
|
char filename[PATH_MAX];
|
2004-01-21 15:40:40 +01:00
|
|
|
uint8 *buffer, *pst_buf;
|
2003-07-01 11:31:25 +02:00
|
|
|
struct stream out;
|
|
|
|
DEVICE_FNS *fns;
|
2007-01-08 05:47:06 +01:00
|
|
|
RD_BOOL rw_blocking = True;
|
2007-01-04 05:55:56 +01:00
|
|
|
RD_NTSTATUS status = RD_STATUS_INVALID_DEVICE_REQUEST;
|
2003-07-01 11:31:25 +02:00
|
|
|
|
|
|
|
in_uint32_le(s, device);
|
|
|
|
in_uint32_le(s, file);
|
|
|
|
in_uint32_le(s, id);
|
|
|
|
in_uint32_le(s, major);
|
|
|
|
in_uint32_le(s, minor);
|
|
|
|
|
2004-01-21 15:40:40 +01:00
|
|
|
buffer_len = 0;
|
|
|
|
buffer = (uint8 *) xmalloc(1024);
|
|
|
|
buffer[0] = 0;
|
|
|
|
|
|
|
|
switch (g_rdpdr_device[device].device_type)
|
2003-07-01 11:31:25 +02:00
|
|
|
{
|
2004-01-21 15:40:40 +01:00
|
|
|
case DEVICE_TYPE_SERIAL:
|
|
|
|
|
2003-07-01 11:31:25 +02:00
|
|
|
fns = &serial_fns;
|
2004-01-30 15:10:32 +01:00
|
|
|
rw_blocking = False;
|
2004-01-21 15:40:40 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case DEVICE_TYPE_PARALLEL:
|
|
|
|
|
|
|
|
fns = ¶llel_fns;
|
2004-01-30 15:10:32 +01:00
|
|
|
rw_blocking = False;
|
2004-01-21 15:40:40 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case DEVICE_TYPE_PRINTER:
|
|
|
|
|
2003-07-01 11:31:25 +02:00
|
|
|
fns = &printer_fns;
|
2004-01-21 15:40:40 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case DEVICE_TYPE_DISK:
|
|
|
|
|
|
|
|
fns = &disk_fns;
|
2004-02-03 15:02:59 +01:00
|
|
|
rw_blocking = False;
|
2004-01-21 15:40:40 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case DEVICE_TYPE_SCARD:
|
2006-11-01 21:52:01 +01:00
|
|
|
#ifdef WITH_SCARD
|
|
|
|
fns = &scard_fns;
|
|
|
|
rw_blocking = False;
|
|
|
|
break;
|
|
|
|
#endif
|
2003-07-01 11:31:25 +02:00
|
|
|
default:
|
2004-01-21 15:40:40 +01:00
|
|
|
|
2003-07-01 11:31:25 +02:00
|
|
|
error("IRP for bad device %ld\n", device);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (major)
|
|
|
|
{
|
|
|
|
case IRP_MJ_CREATE:
|
2004-01-21 15:40:40 +01:00
|
|
|
|
|
|
|
in_uint32_be(s, desired_access);
|
2005-03-15 12:25:50 +01:00
|
|
|
in_uint8s(s, 0x08); /* unknown */
|
2004-01-21 15:40:40 +01:00
|
|
|
in_uint32_le(s, error_mode);
|
|
|
|
in_uint32_le(s, share_mode);
|
|
|
|
in_uint32_le(s, disposition);
|
|
|
|
in_uint32_le(s, flags_and_attributes);
|
|
|
|
in_uint32_le(s, length);
|
|
|
|
|
|
|
|
if (length && (length / 2) < 256)
|
|
|
|
{
|
|
|
|
rdp_in_unistr(s, filename, length);
|
|
|
|
convert_to_unix_filename(filename);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
filename[0] = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!fns->create)
|
|
|
|
{
|
2007-01-04 05:55:56 +01:00
|
|
|
status = RD_STATUS_NOT_SUPPORTED;
|
2004-01-21 15:40:40 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
status = fns->create(device, desired_access, share_mode, disposition,
|
|
|
|
flags_and_attributes, filename, &result);
|
|
|
|
buffer_len = 1;
|
2003-07-01 11:31:25 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case IRP_MJ_CLOSE:
|
2004-01-21 15:40:40 +01:00
|
|
|
if (!fns->close)
|
|
|
|
{
|
2007-01-04 05:55:56 +01:00
|
|
|
status = RD_STATUS_NOT_SUPPORTED;
|
2004-01-21 15:40:40 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
status = fns->close(file);
|
2003-07-01 11:31:25 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case IRP_MJ_READ:
|
2004-01-21 15:40:40 +01:00
|
|
|
|
|
|
|
if (!fns->read)
|
2003-07-01 11:31:25 +02:00
|
|
|
{
|
2007-01-04 05:55:56 +01:00
|
|
|
status = RD_STATUS_NOT_SUPPORTED;
|
2004-01-21 15:40:40 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
in_uint32_le(s, length);
|
|
|
|
in_uint32_le(s, offset);
|
|
|
|
#if WITH_DEBUG_RDP5
|
|
|
|
DEBUG(("RDPDR IRP Read (length: %d, offset: %d)\n", length, offset));
|
|
|
|
#endif
|
2004-03-04 09:24:40 +01:00
|
|
|
if (!rdpdr_handle_ok(device, file))
|
|
|
|
{
|
2007-01-04 05:55:56 +01:00
|
|
|
status = RD_STATUS_INVALID_HANDLE;
|
2004-03-04 09:24:40 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2005-03-15 12:25:50 +01:00
|
|
|
if (rw_blocking) /* Complete read immediately */
|
2004-01-30 15:10:32 +01:00
|
|
|
{
|
2004-01-21 15:40:40 +01:00
|
|
|
buffer = (uint8 *) xrealloc((void *) buffer, length);
|
2004-02-23 10:58:16 +01:00
|
|
|
if (!buffer)
|
|
|
|
{
|
2007-01-04 05:55:56 +01:00
|
|
|
status = RD_STATUS_CANCELLED;
|
2004-02-23 10:58:16 +01:00
|
|
|
break;
|
|
|
|
}
|
2004-01-21 15:40:40 +01:00
|
|
|
status = fns->read(file, buffer, length, offset, &result);
|
2003-07-01 11:31:25 +02:00
|
|
|
buffer_len = result;
|
2004-01-21 15:40:40 +01:00
|
|
|
break;
|
2004-01-30 15:10:32 +01:00
|
|
|
}
|
2004-01-21 15:40:40 +01:00
|
|
|
|
2005-03-15 12:25:50 +01:00
|
|
|
/* Add request to table */
|
2004-01-21 15:40:40 +01:00
|
|
|
pst_buf = (uint8 *) xmalloc(length);
|
2004-02-23 10:58:16 +01:00
|
|
|
if (!pst_buf)
|
|
|
|
{
|
2007-01-04 05:55:56 +01:00
|
|
|
status = RD_STATUS_CANCELLED;
|
2004-02-23 10:58:16 +01:00
|
|
|
break;
|
|
|
|
}
|
2004-01-21 15:40:40 +01:00
|
|
|
serial_get_timeout(file, length, &total_timeout, &interval_timeout);
|
|
|
|
if (add_async_iorequest
|
|
|
|
(device, file, id, major, length, fns, total_timeout, interval_timeout,
|
2004-02-23 11:34:18 +01:00
|
|
|
pst_buf, offset))
|
2004-01-21 15:40:40 +01:00
|
|
|
{
|
2007-01-04 05:55:56 +01:00
|
|
|
status = RD_STATUS_PENDING;
|
2004-01-21 15:40:40 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2007-01-04 05:55:56 +01:00
|
|
|
status = RD_STATUS_CANCELLED;
|
2003-07-01 11:31:25 +02:00
|
|
|
break;
|
|
|
|
case IRP_MJ_WRITE:
|
2004-01-21 15:40:40 +01:00
|
|
|
|
|
|
|
buffer_len = 1;
|
|
|
|
|
|
|
|
if (!fns->write)
|
|
|
|
{
|
2007-01-04 05:55:56 +01:00
|
|
|
status = RD_STATUS_NOT_SUPPORTED;
|
2004-01-21 15:40:40 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
in_uint32_le(s, length);
|
|
|
|
in_uint32_le(s, offset);
|
|
|
|
in_uint8s(s, 0x18);
|
|
|
|
#if WITH_DEBUG_RDP5
|
|
|
|
DEBUG(("RDPDR IRP Write (length: %d)\n", result));
|
|
|
|
#endif
|
2004-03-04 09:24:40 +01:00
|
|
|
if (!rdpdr_handle_ok(device, file))
|
|
|
|
{
|
2007-01-04 05:55:56 +01:00
|
|
|
status = RD_STATUS_INVALID_HANDLE;
|
2004-03-04 09:24:40 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2005-03-15 12:25:50 +01:00
|
|
|
if (rw_blocking) /* Complete immediately */
|
2004-01-30 15:10:32 +01:00
|
|
|
{
|
2004-01-21 15:40:40 +01:00
|
|
|
status = fns->write(file, s->p, length, offset, &result);
|
|
|
|
break;
|
2004-01-30 15:10:32 +01:00
|
|
|
}
|
|
|
|
|
2005-03-15 12:25:50 +01:00
|
|
|
/* Add to table */
|
2004-01-21 15:40:40 +01:00
|
|
|
pst_buf = (uint8 *) xmalloc(length);
|
2004-02-23 10:58:16 +01:00
|
|
|
if (!pst_buf)
|
|
|
|
{
|
2007-01-04 05:55:56 +01:00
|
|
|
status = RD_STATUS_CANCELLED;
|
2004-02-23 10:58:16 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2004-01-21 15:40:40 +01:00
|
|
|
in_uint8a(s, pst_buf, length);
|
|
|
|
|
|
|
|
if (add_async_iorequest
|
2004-02-23 11:34:18 +01:00
|
|
|
(device, file, id, major, length, fns, 0, 0, pst_buf, offset))
|
2004-01-21 15:40:40 +01:00
|
|
|
{
|
2007-01-04 05:55:56 +01:00
|
|
|
status = RD_STATUS_PENDING;
|
2004-01-21 15:40:40 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2007-01-04 05:55:56 +01:00
|
|
|
status = RD_STATUS_CANCELLED;
|
2004-01-21 15:40:40 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case IRP_MJ_QUERY_INFORMATION:
|
|
|
|
|
|
|
|
if (g_rdpdr_device[device].device_type != DEVICE_TYPE_DISK)
|
|
|
|
{
|
2007-01-04 05:55:56 +01:00
|
|
|
status = RD_STATUS_INVALID_HANDLE;
|
2004-01-21 15:40:40 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
in_uint32_le(s, info_level);
|
|
|
|
|
|
|
|
out.data = out.p = buffer;
|
|
|
|
out.size = sizeof(buffer);
|
|
|
|
status = disk_query_information(file, info_level, &out);
|
|
|
|
result = buffer_len = out.p - out.data;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case IRP_MJ_SET_INFORMATION:
|
|
|
|
|
|
|
|
if (g_rdpdr_device[device].device_type != DEVICE_TYPE_DISK)
|
|
|
|
{
|
2007-01-04 05:55:56 +01:00
|
|
|
status = RD_STATUS_INVALID_HANDLE;
|
2004-01-21 15:40:40 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
in_uint32_le(s, info_level);
|
|
|
|
|
|
|
|
out.data = out.p = buffer;
|
|
|
|
out.size = sizeof(buffer);
|
|
|
|
status = disk_set_information(file, info_level, s, &out);
|
|
|
|
result = buffer_len = out.p - out.data;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case IRP_MJ_QUERY_VOLUME_INFORMATION:
|
|
|
|
|
|
|
|
if (g_rdpdr_device[device].device_type != DEVICE_TYPE_DISK)
|
|
|
|
{
|
2007-01-04 05:55:56 +01:00
|
|
|
status = RD_STATUS_INVALID_HANDLE;
|
2004-01-21 15:40:40 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
in_uint32_le(s, info_level);
|
|
|
|
|
|
|
|
out.data = out.p = buffer;
|
|
|
|
out.size = sizeof(buffer);
|
|
|
|
status = disk_query_volume_information(file, info_level, &out);
|
|
|
|
result = buffer_len = out.p - out.data;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case IRP_MJ_DIRECTORY_CONTROL:
|
|
|
|
|
|
|
|
if (g_rdpdr_device[device].device_type != DEVICE_TYPE_DISK)
|
|
|
|
{
|
2007-01-04 05:55:56 +01:00
|
|
|
status = RD_STATUS_INVALID_HANDLE;
|
2004-01-21 15:40:40 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (minor)
|
|
|
|
{
|
|
|
|
case IRP_MN_QUERY_DIRECTORY:
|
|
|
|
|
|
|
|
in_uint32_le(s, info_level);
|
|
|
|
in_uint8s(s, 1);
|
|
|
|
in_uint32_le(s, length);
|
|
|
|
in_uint8s(s, 0x17);
|
|
|
|
if (length && length < 2 * 255)
|
|
|
|
{
|
|
|
|
rdp_in_unistr(s, filename, length);
|
|
|
|
convert_to_unix_filename(filename);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
filename[0] = 0;
|
|
|
|
}
|
|
|
|
out.data = out.p = buffer;
|
|
|
|
out.size = sizeof(buffer);
|
|
|
|
status = disk_query_directory(file, info_level, filename,
|
|
|
|
&out);
|
|
|
|
result = buffer_len = out.p - out.data;
|
|
|
|
if (!buffer_len)
|
|
|
|
buffer_len++;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case IRP_MN_NOTIFY_CHANGE_DIRECTORY:
|
|
|
|
|
|
|
|
/* JIF
|
2004-11-03 14:56:52 +01:00
|
|
|
unimpl("IRP major=0x%x minor=0x%x: IRP_MN_NOTIFY_CHANGE_DIRECTORY\n", major, minor); */
|
|
|
|
|
2005-03-15 12:25:50 +01:00
|
|
|
in_uint32_le(s, info_level); /* notify mask */
|
2004-11-03 14:56:52 +01:00
|
|
|
|
|
|
|
status = disk_create_notify(file, info_level);
|
|
|
|
result = 0;
|
|
|
|
|
2007-01-04 05:55:56 +01:00
|
|
|
if (status == RD_STATUS_PENDING)
|
2004-11-03 14:56:52 +01:00
|
|
|
add_async_iorequest(device, file, id, major, length,
|
|
|
|
fns, 0, 0, NULL, 0);
|
2004-01-21 15:40:40 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
2007-01-04 05:55:56 +01:00
|
|
|
status = RD_STATUS_INVALID_PARAMETER;
|
2004-11-03 14:56:52 +01:00
|
|
|
/* JIF */
|
|
|
|
unimpl("IRP major=0x%x minor=0x%x\n", major, minor);
|
2004-01-21 15:40:40 +01:00
|
|
|
}
|
2003-07-01 11:31:25 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case IRP_MJ_DEVICE_CONTROL:
|
2004-01-21 15:40:40 +01:00
|
|
|
|
|
|
|
if (!fns->device_control)
|
2003-07-01 11:31:25 +02:00
|
|
|
{
|
2007-01-04 05:55:56 +01:00
|
|
|
status = RD_STATUS_NOT_SUPPORTED;
|
2004-01-21 15:40:40 +01:00
|
|
|
break;
|
2003-07-01 11:31:25 +02:00
|
|
|
}
|
2004-01-21 15:40:40 +01:00
|
|
|
|
|
|
|
in_uint32_le(s, bytes_out);
|
|
|
|
in_uint32_le(s, bytes_in);
|
|
|
|
in_uint32_le(s, request);
|
|
|
|
in_uint8s(s, 0x14);
|
|
|
|
|
|
|
|
buffer = (uint8 *) xrealloc((void *) buffer, bytes_out + 0x14);
|
2004-02-23 10:58:16 +01:00
|
|
|
if (!buffer)
|
|
|
|
{
|
2007-01-04 05:55:56 +01:00
|
|
|
status = RD_STATUS_CANCELLED;
|
2004-02-23 10:58:16 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2004-01-21 15:40:40 +01:00
|
|
|
out.data = out.p = buffer;
|
|
|
|
out.size = sizeof(buffer);
|
2006-11-02 21:48:28 +01:00
|
|
|
|
|
|
|
DEBUG_SCARD(("[SMART-CARD TRACE]\n"));
|
|
|
|
DEBUG_SCARD(("device 0x%.8x\n", device));
|
|
|
|
DEBUG_SCARD(("file 0x%.8x\n", file));
|
|
|
|
DEBUG_SCARD(("id 0x%.8x\n", id));
|
2006-11-01 21:52:01 +01:00
|
|
|
#ifdef WITH_SCARD
|
|
|
|
scardSetInfo(device, id, bytes_out + 0x14);
|
|
|
|
#endif
|
2004-01-21 15:40:40 +01:00
|
|
|
status = fns->device_control(file, request, s, &out);
|
|
|
|
result = buffer_len = out.p - out.data;
|
2006-11-02 21:48:28 +01:00
|
|
|
|
|
|
|
DEBUG_SCARD(("[SMART-CARD TRACE] OUT 0x%.8x\n", status));
|
|
|
|
|
2004-11-03 14:56:52 +01:00
|
|
|
/* Serial SERIAL_WAIT_ON_MASK */
|
2007-01-04 05:55:56 +01:00
|
|
|
if (status == RD_STATUS_PENDING)
|
2004-11-03 14:56:52 +01:00
|
|
|
{
|
|
|
|
if (add_async_iorequest
|
|
|
|
(device, file, id, major, length, fns, 0, 0, NULL, 0))
|
|
|
|
{
|
2007-01-04 05:55:56 +01:00
|
|
|
status = RD_STATUS_PENDING;
|
2004-11-03 14:56:52 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2006-11-01 21:52:01 +01:00
|
|
|
#ifdef WITH_SCARD
|
2007-01-04 05:55:56 +01:00
|
|
|
else if (status == (RD_STATUS_PENDING | 0xC0000000))
|
|
|
|
status = RD_STATUS_PENDING;
|
2006-11-01 21:52:01 +01:00
|
|
|
#endif
|
2003-07-01 11:31:25 +02:00
|
|
|
break;
|
|
|
|
|
2004-04-16 14:20:56 +02:00
|
|
|
|
|
|
|
case IRP_MJ_LOCK_CONTROL:
|
|
|
|
|
|
|
|
if (g_rdpdr_device[device].device_type != DEVICE_TYPE_DISK)
|
|
|
|
{
|
2007-01-04 05:55:56 +01:00
|
|
|
status = RD_STATUS_INVALID_HANDLE;
|
2004-04-16 14:20:56 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
in_uint32_le(s, info_level);
|
|
|
|
|
|
|
|
out.data = out.p = buffer;
|
|
|
|
out.size = sizeof(buffer);
|
|
|
|
/* FIXME: Perhaps consider actually *do*
|
|
|
|
something here :-) */
|
2007-01-04 05:55:56 +01:00
|
|
|
status = RD_STATUS_SUCCESS;
|
2004-04-16 14:20:56 +02:00
|
|
|
result = buffer_len = out.p - out.data;
|
|
|
|
break;
|
|
|
|
|
2003-07-01 11:31:25 +02:00
|
|
|
default:
|
|
|
|
unimpl("IRP major=0x%x minor=0x%x\n", major, minor);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2007-01-04 05:55:56 +01:00
|
|
|
if (status != RD_STATUS_PENDING)
|
2004-01-21 15:40:40 +01:00
|
|
|
{
|
|
|
|
rdpdr_send_completion(device, id, status, result, buffer, buffer_len);
|
|
|
|
}
|
2004-02-23 10:58:16 +01:00
|
|
|
if (buffer)
|
|
|
|
xfree(buffer);
|
|
|
|
buffer = NULL;
|
2004-01-21 15:40:40 +01:00
|
|
|
}
|
|
|
|
|
2004-04-17 08:58:30 +02:00
|
|
|
static void
|
2004-01-21 15:40:40 +01:00
|
|
|
rdpdr_send_clientcapabilty(void)
|
|
|
|
{
|
|
|
|
uint8 magic[4] = "rDPC";
|
|
|
|
STREAM s;
|
|
|
|
|
|
|
|
s = channel_init(rdpdr_channel, 0x50);
|
|
|
|
out_uint8a(s, magic, 4);
|
|
|
|
out_uint32_le(s, 5); /* count */
|
|
|
|
out_uint16_le(s, 1); /* first */
|
|
|
|
out_uint16_le(s, 0x28); /* length */
|
|
|
|
out_uint32_le(s, 1);
|
|
|
|
out_uint32_le(s, 2);
|
|
|
|
out_uint16_le(s, 2);
|
|
|
|
out_uint16_le(s, 5);
|
|
|
|
out_uint16_le(s, 1);
|
|
|
|
out_uint16_le(s, 5);
|
|
|
|
out_uint16_le(s, 0xFFFF);
|
|
|
|
out_uint16_le(s, 0);
|
|
|
|
out_uint32_le(s, 0);
|
|
|
|
out_uint32_le(s, 3);
|
|
|
|
out_uint32_le(s, 0);
|
|
|
|
out_uint32_le(s, 0);
|
|
|
|
out_uint16_le(s, 2); /* second */
|
|
|
|
out_uint16_le(s, 8); /* length */
|
|
|
|
out_uint32_le(s, 1);
|
|
|
|
out_uint16_le(s, 3); /* third */
|
|
|
|
out_uint16_le(s, 8); /* length */
|
|
|
|
out_uint32_le(s, 1);
|
|
|
|
out_uint16_le(s, 4); /* fourth */
|
|
|
|
out_uint16_le(s, 8); /* length */
|
|
|
|
out_uint32_le(s, 1);
|
|
|
|
out_uint16_le(s, 5); /* fifth */
|
|
|
|
out_uint16_le(s, 8); /* length */
|
|
|
|
out_uint32_le(s, 1);
|
|
|
|
|
|
|
|
s_mark_end(s);
|
|
|
|
channel_send(s, rdpdr_channel);
|
2003-07-01 11:31:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
rdpdr_process(STREAM s)
|
|
|
|
{
|
|
|
|
uint32 handle;
|
2003-10-31 05:29:57 +01:00
|
|
|
uint8 *magic;
|
2003-07-01 11:31:25 +02:00
|
|
|
|
2004-01-21 15:40:40 +01:00
|
|
|
#if WITH_DEBUG_RDP5
|
|
|
|
printf("--- rdpdr_process ---\n");
|
2003-07-09 11:18:20 +02:00
|
|
|
hexdump(s->p, s->end - s->p);
|
2004-01-21 15:40:40 +01:00
|
|
|
#endif
|
2003-07-01 11:31:25 +02:00
|
|
|
in_uint8p(s, magic, 4);
|
|
|
|
|
|
|
|
if ((magic[0] == 'r') && (magic[1] == 'D'))
|
|
|
|
{
|
|
|
|
if ((magic[2] == 'R') && (magic[3] == 'I'))
|
|
|
|
{
|
|
|
|
rdpdr_process_irp(s);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if ((magic[2] == 'n') && (magic[3] == 'I'))
|
|
|
|
{
|
|
|
|
rdpdr_send_connect();
|
|
|
|
rdpdr_send_name();
|
|
|
|
return;
|
|
|
|
}
|
2004-01-21 15:40:40 +01:00
|
|
|
if ((magic[2] == 'C') && (magic[3] == 'C'))
|
2003-07-01 11:31:25 +02:00
|
|
|
{
|
|
|
|
/* connect from server */
|
2004-01-21 15:40:40 +01:00
|
|
|
rdpdr_send_clientcapabilty();
|
|
|
|
rdpdr_send_available();
|
2003-07-01 11:31:25 +02:00
|
|
|
return;
|
|
|
|
}
|
2004-01-21 15:40:40 +01:00
|
|
|
if ((magic[2] == 'r') && (magic[3] == 'd'))
|
2003-07-01 11:31:25 +02:00
|
|
|
{
|
|
|
|
/* connect to a specific resource */
|
|
|
|
in_uint32(s, handle);
|
2004-01-21 15:40:40 +01:00
|
|
|
#if WITH_DEBUG_RDP5
|
|
|
|
DEBUG(("RDPDR: Server connected to resource %d\n", handle));
|
|
|
|
#endif
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if ((magic[2] == 'P') && (magic[3] == 'S'))
|
|
|
|
{
|
|
|
|
/* server capability */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ((magic[0] == 'R') && (magic[1] == 'P'))
|
|
|
|
{
|
|
|
|
if ((magic[2] == 'C') && (magic[3] == 'P'))
|
|
|
|
{
|
|
|
|
printercache_process(s);
|
2003-07-01 11:31:25 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
unimpl("RDPDR packet type %c%c%c%c\n", magic[0], magic[1], magic[2], magic[3]);
|
|
|
|
}
|
|
|
|
|
2007-01-08 05:47:06 +01:00
|
|
|
RD_BOOL
|
2004-01-21 15:40:40 +01:00
|
|
|
rdpdr_init()
|
2003-07-01 11:31:25 +02:00
|
|
|
{
|
2004-01-21 15:40:40 +01:00
|
|
|
if (g_num_devices > 0)
|
|
|
|
{
|
2004-01-23 09:35:52 +01:00
|
|
|
rdpdr_channel =
|
|
|
|
channel_register("rdpdr",
|
|
|
|
CHANNEL_OPTION_INITIALIZED | CHANNEL_OPTION_COMPRESS_RDP,
|
|
|
|
rdpdr_process);
|
2004-01-21 15:40:40 +01:00
|
|
|
}
|
|
|
|
|
2003-07-01 11:31:25 +02:00
|
|
|
return (rdpdr_channel != NULL);
|
|
|
|
}
|
2004-01-21 15:40:40 +01:00
|
|
|
|
|
|
|
/* Add file descriptors of pending io request to select() */
|
|
|
|
void
|
2007-01-08 05:47:06 +01:00
|
|
|
rdpdr_add_fds(int *n, fd_set * rfds, fd_set * wfds, struct timeval *tv, RD_BOOL * timeout)
|
2004-01-21 15:40:40 +01:00
|
|
|
{
|
2005-03-15 12:25:50 +01:00
|
|
|
uint32 select_timeout = 0; /* Timeout value to be used for select() (in millisecons). */
|
2004-01-21 15:40:40 +01:00
|
|
|
struct async_iorequest *iorq;
|
2004-04-16 16:04:02 +02:00
|
|
|
char c;
|
2004-01-21 15:40:40 +01:00
|
|
|
|
2004-02-02 08:06:55 +01:00
|
|
|
iorq = g_iorequest;
|
2004-01-30 15:10:32 +01:00
|
|
|
while (iorq != NULL)
|
2004-01-21 15:40:40 +01:00
|
|
|
{
|
2004-04-19 10:24:54 +02:00
|
|
|
if (iorq->fd != 0)
|
2004-01-21 15:40:40 +01:00
|
|
|
{
|
|
|
|
switch (iorq->major)
|
|
|
|
{
|
|
|
|
case IRP_MJ_READ:
|
2004-04-19 10:24:54 +02:00
|
|
|
/* Is this FD valid? FDs will
|
|
|
|
be invalid when
|
|
|
|
reconnecting. FIXME: Real
|
|
|
|
support for reconnects. */
|
|
|
|
|
2004-01-21 15:40:40 +01:00
|
|
|
FD_SET(iorq->fd, rfds);
|
2004-04-19 10:24:54 +02:00
|
|
|
*n = MAX(*n, iorq->fd);
|
2004-01-21 15:40:40 +01:00
|
|
|
|
2004-11-03 14:56:52 +01:00
|
|
|
/* Check if io request timeout is smaller than current (but not 0). */
|
2004-01-21 15:40:40 +01:00
|
|
|
if (iorq->timeout
|
|
|
|
&& (select_timeout == 0
|
|
|
|
|| iorq->timeout < select_timeout))
|
|
|
|
{
|
2004-11-03 14:56:52 +01:00
|
|
|
/* Set new timeout */
|
2004-01-21 15:40:40 +01:00
|
|
|
select_timeout = iorq->timeout;
|
|
|
|
g_min_timeout_fd = iorq->fd; /* Remember fd */
|
|
|
|
tv->tv_sec = select_timeout / 1000;
|
|
|
|
tv->tv_usec = (select_timeout % 1000) * 1000;
|
|
|
|
*timeout = True;
|
2004-11-03 14:56:52 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (iorq->itv_timeout && iorq->partial_len > 0
|
|
|
|
&& (select_timeout == 0
|
|
|
|
|| iorq->itv_timeout < select_timeout))
|
|
|
|
{
|
|
|
|
/* Set new timeout */
|
|
|
|
select_timeout = iorq->itv_timeout;
|
|
|
|
g_min_timeout_fd = iorq->fd; /* Remember fd */
|
|
|
|
tv->tv_sec = select_timeout / 1000;
|
|
|
|
tv->tv_usec = (select_timeout % 1000) * 1000;
|
|
|
|
*timeout = True;
|
|
|
|
break;
|
2004-01-21 15:40:40 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case IRP_MJ_WRITE:
|
2004-04-19 10:24:54 +02:00
|
|
|
/* FD still valid? See above. */
|
2004-04-19 11:21:25 +02:00
|
|
|
if ((write(iorq->fd, &c, 0) != 0) && (errno == EBADF))
|
2004-04-19 10:24:54 +02:00
|
|
|
break;
|
|
|
|
|
2004-01-21 15:40:40 +01:00
|
|
|
FD_SET(iorq->fd, wfds);
|
2004-04-19 10:24:54 +02:00
|
|
|
*n = MAX(*n, iorq->fd);
|
2004-01-21 15:40:40 +01:00
|
|
|
break;
|
|
|
|
|
2004-11-03 14:56:52 +01:00
|
|
|
case IRP_MJ_DEVICE_CONTROL:
|
|
|
|
if (select_timeout > 5)
|
|
|
|
select_timeout = 5; /* serial event queue */
|
|
|
|
break;
|
|
|
|
|
2004-01-21 15:40:40 +01:00
|
|
|
}
|
2004-04-19 10:24:54 +02:00
|
|
|
|
2004-01-21 15:40:40 +01:00
|
|
|
}
|
2004-01-30 15:10:32 +01:00
|
|
|
|
|
|
|
iorq = iorq->next;
|
2004-01-21 15:40:40 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-03-04 09:24:40 +01:00
|
|
|
struct async_iorequest *
|
|
|
|
rdpdr_remove_iorequest(struct async_iorequest *prev, struct async_iorequest *iorq)
|
|
|
|
{
|
|
|
|
if (!iorq)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (iorq->buffer)
|
|
|
|
xfree(iorq->buffer);
|
|
|
|
if (prev)
|
|
|
|
{
|
|
|
|
prev->next = iorq->next;
|
|
|
|
xfree(iorq);
|
|
|
|
iorq = prev->next;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-03-15 12:25:50 +01:00
|
|
|
/* Even if NULL */
|
2004-03-04 09:24:40 +01:00
|
|
|
g_iorequest = iorq->next;
|
|
|
|
xfree(iorq);
|
|
|
|
iorq = NULL;
|
|
|
|
}
|
|
|
|
return iorq;
|
|
|
|
}
|
2004-01-29 13:27:21 +01:00
|
|
|
|
2004-01-21 15:40:40 +01:00
|
|
|
/* Check if select() returned with one of the rdpdr file descriptors, and complete io if it did */
|
2005-08-02 11:45:11 +02:00
|
|
|
static void
|
2007-01-08 05:47:06 +01:00
|
|
|
_rdpdr_check_fds(fd_set * rfds, fd_set * wfds, RD_BOOL timed_out)
|
2004-01-21 15:40:40 +01:00
|
|
|
{
|
2007-01-04 05:55:56 +01:00
|
|
|
RD_NTSTATUS status;
|
2004-01-30 15:10:32 +01:00
|
|
|
uint32 result = 0;
|
2004-01-21 15:40:40 +01:00
|
|
|
DEVICE_FNS *fns;
|
|
|
|
struct async_iorequest *iorq;
|
2004-01-30 15:10:32 +01:00
|
|
|
struct async_iorequest *prev;
|
2004-02-03 15:02:59 +01:00
|
|
|
uint32 req_size = 0;
|
2004-11-03 14:56:52 +01:00
|
|
|
uint32 buffer_len;
|
|
|
|
struct stream out;
|
|
|
|
uint8 *buffer = NULL;
|
|
|
|
|
2004-01-21 15:40:40 +01:00
|
|
|
|
|
|
|
if (timed_out)
|
|
|
|
{
|
2004-11-03 14:56:52 +01:00
|
|
|
/* check serial iv_timeout */
|
|
|
|
|
|
|
|
iorq = g_iorequest;
|
|
|
|
prev = NULL;
|
|
|
|
while (iorq != NULL)
|
|
|
|
{
|
|
|
|
if (iorq->fd == g_min_timeout_fd)
|
|
|
|
{
|
|
|
|
if ((iorq->partial_len > 0) &&
|
|
|
|
(g_rdpdr_device[iorq->device].device_type ==
|
|
|
|
DEVICE_TYPE_SERIAL))
|
|
|
|
{
|
|
|
|
|
|
|
|
/* iv_timeout between 2 chars, send partial_len */
|
2005-04-03 20:08:05 +02:00
|
|
|
/*printf("RDPDR: IVT total %u bytes read of %u\n", iorq->partial_len, iorq->length); */
|
2004-11-03 14:56:52 +01:00
|
|
|
rdpdr_send_completion(iorq->device,
|
2007-01-04 05:55:56 +01:00
|
|
|
iorq->id, RD_STATUS_SUCCESS,
|
2004-11-03 14:56:52 +01:00
|
|
|
iorq->partial_len,
|
|
|
|
iorq->buffer, iorq->partial_len);
|
|
|
|
iorq = rdpdr_remove_iorequest(prev, iorq);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
prev = iorq;
|
|
|
|
if (iorq)
|
|
|
|
iorq = iorq->next;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2007-01-04 05:55:56 +01:00
|
|
|
rdpdr_abort_io(g_min_timeout_fd, 0, RD_STATUS_TIMEOUT);
|
2004-01-21 15:40:40 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2004-02-02 08:06:55 +01:00
|
|
|
iorq = g_iorequest;
|
2004-01-30 15:10:32 +01:00
|
|
|
prev = NULL;
|
|
|
|
while (iorq != NULL)
|
2004-01-21 15:40:40 +01:00
|
|
|
{
|
|
|
|
if (iorq->fd != 0)
|
|
|
|
{
|
|
|
|
switch (iorq->major)
|
|
|
|
{
|
|
|
|
case IRP_MJ_READ:
|
|
|
|
if (FD_ISSET(iorq->fd, rfds))
|
|
|
|
{
|
2004-01-30 15:10:32 +01:00
|
|
|
/* Read the data */
|
2004-01-21 15:40:40 +01:00
|
|
|
fns = iorq->fns;
|
2004-02-02 08:06:55 +01:00
|
|
|
|
2004-02-03 15:02:59 +01:00
|
|
|
req_size =
|
|
|
|
(iorq->length - iorq->partial_len) >
|
|
|
|
8192 ? 8192 : (iorq->length -
|
|
|
|
iorq->partial_len);
|
2004-02-02 08:06:55 +01:00
|
|
|
/* never read larger chunks than 8k - chances are that it will block */
|
2004-01-30 15:10:32 +01:00
|
|
|
status = fns->read(iorq->fd,
|
|
|
|
iorq->buffer + iorq->partial_len,
|
2004-02-23 11:34:18 +01:00
|
|
|
req_size, iorq->offset, &result);
|
2004-02-03 15:02:59 +01:00
|
|
|
|
2004-11-03 14:56:52 +01:00
|
|
|
if ((long) result > 0)
|
2004-03-04 09:24:40 +01:00
|
|
|
{
|
|
|
|
iorq->partial_len += result;
|
|
|
|
iorq->offset += result;
|
|
|
|
}
|
2004-01-21 15:40:40 +01:00
|
|
|
#if WITH_DEBUG_RDP5
|
|
|
|
DEBUG(("RDPDR: %d bytes of data read\n", result));
|
|
|
|
#endif
|
2004-01-30 15:10:32 +01:00
|
|
|
/* only delete link if all data has been transfered */
|
2004-02-03 15:02:59 +01:00
|
|
|
/* or if result was 0 and status success - EOF */
|
|
|
|
if ((iorq->partial_len == iorq->length) ||
|
2004-11-03 14:56:52 +01:00
|
|
|
(result == 0))
|
2004-01-30 15:10:32 +01:00
|
|
|
{
|
2004-02-03 15:02:59 +01:00
|
|
|
#if WITH_DEBUG_RDP5
|
|
|
|
DEBUG(("RDPDR: AIO total %u bytes read of %u\n", iorq->partial_len, iorq->length));
|
|
|
|
#endif
|
2004-01-30 15:10:32 +01:00
|
|
|
rdpdr_send_completion(iorq->device,
|
|
|
|
iorq->id, status,
|
2004-02-03 15:02:59 +01:00
|
|
|
iorq->partial_len,
|
|
|
|
iorq->buffer,
|
|
|
|
iorq->partial_len);
|
2004-03-04 09:24:40 +01:00
|
|
|
iorq = rdpdr_remove_iorequest(prev, iorq);
|
2004-01-30 15:10:32 +01:00
|
|
|
}
|
2004-01-21 15:40:40 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case IRP_MJ_WRITE:
|
|
|
|
if (FD_ISSET(iorq->fd, wfds))
|
|
|
|
{
|
2004-01-30 15:10:32 +01:00
|
|
|
/* Write data. */
|
2004-01-21 15:40:40 +01:00
|
|
|
fns = iorq->fns;
|
2004-02-02 08:06:55 +01:00
|
|
|
|
2004-02-03 15:02:59 +01:00
|
|
|
req_size =
|
|
|
|
(iorq->length - iorq->partial_len) >
|
|
|
|
8192 ? 8192 : (iorq->length -
|
|
|
|
iorq->partial_len);
|
|
|
|
|
2004-02-02 08:06:55 +01:00
|
|
|
/* never write larger chunks than 8k - chances are that it will block */
|
2004-01-30 15:10:32 +01:00
|
|
|
status = fns->write(iorq->fd,
|
|
|
|
iorq->buffer +
|
2004-02-23 11:34:18 +01:00
|
|
|
iorq->partial_len, req_size,
|
|
|
|
iorq->offset, &result);
|
2004-03-04 09:24:40 +01:00
|
|
|
|
2004-11-03 14:56:52 +01:00
|
|
|
if ((long) result > 0)
|
2004-03-04 09:24:40 +01:00
|
|
|
{
|
|
|
|
iorq->partial_len += result;
|
|
|
|
iorq->offset += result;
|
|
|
|
}
|
|
|
|
|
2004-01-30 15:10:32 +01:00
|
|
|
#if WITH_DEBUG_RDP5
|
|
|
|
DEBUG(("RDPDR: %d bytes of data written\n",
|
|
|
|
result));
|
|
|
|
#endif
|
|
|
|
/* only delete link if all data has been transfered */
|
2004-02-03 15:02:59 +01:00
|
|
|
/* or we couldn't write */
|
|
|
|
if ((iorq->partial_len == iorq->length)
|
|
|
|
|| (result == 0))
|
2004-01-30 15:10:32 +01:00
|
|
|
{
|
2004-02-03 15:02:59 +01:00
|
|
|
#if WITH_DEBUG_RDP5
|
|
|
|
DEBUG(("RDPDR: AIO total %u bytes written of %u\n", iorq->partial_len, iorq->length));
|
|
|
|
#endif
|
2004-01-30 15:10:32 +01:00
|
|
|
rdpdr_send_completion(iorq->device,
|
|
|
|
iorq->id, status,
|
2004-02-15 22:19:28 +01:00
|
|
|
iorq->partial_len,
|
|
|
|
(uint8 *) "", 1);
|
2004-01-30 15:10:32 +01:00
|
|
|
|
2004-03-04 09:24:40 +01:00
|
|
|
iorq = rdpdr_remove_iorequest(prev, iorq);
|
2004-01-30 15:10:32 +01:00
|
|
|
}
|
2004-01-21 15:40:40 +01:00
|
|
|
}
|
2004-11-03 14:56:52 +01:00
|
|
|
break;
|
|
|
|
case IRP_MJ_DEVICE_CONTROL:
|
|
|
|
if (serial_get_event(iorq->fd, &result))
|
|
|
|
{
|
|
|
|
buffer = (uint8 *) xrealloc((void *) buffer, 0x14);
|
|
|
|
out.data = out.p = buffer;
|
|
|
|
out.size = sizeof(buffer);
|
|
|
|
out_uint32_le(&out, result);
|
|
|
|
result = buffer_len = out.p - out.data;
|
2007-01-04 05:55:56 +01:00
|
|
|
status = RD_STATUS_SUCCESS;
|
2004-11-03 14:56:52 +01:00
|
|
|
rdpdr_send_completion(iorq->device, iorq->id,
|
|
|
|
status, result, buffer,
|
|
|
|
buffer_len);
|
|
|
|
xfree(buffer);
|
|
|
|
iorq = rdpdr_remove_iorequest(prev, iorq);
|
|
|
|
}
|
|
|
|
|
2004-01-21 15:40:40 +01:00
|
|
|
break;
|
|
|
|
}
|
2004-01-30 15:10:32 +01:00
|
|
|
|
2004-01-21 15:40:40 +01:00
|
|
|
}
|
2004-01-30 15:10:32 +01:00
|
|
|
prev = iorq;
|
2004-02-23 13:07:30 +01:00
|
|
|
if (iorq)
|
|
|
|
iorq = iorq->next;
|
2004-01-21 15:40:40 +01:00
|
|
|
}
|
2004-01-30 15:10:32 +01:00
|
|
|
|
2004-11-03 14:56:52 +01:00
|
|
|
/* Check notify */
|
|
|
|
iorq = g_iorequest;
|
|
|
|
prev = NULL;
|
|
|
|
while (iorq != NULL)
|
|
|
|
{
|
|
|
|
if (iorq->fd != 0)
|
|
|
|
{
|
|
|
|
switch (iorq->major)
|
|
|
|
{
|
|
|
|
|
|
|
|
case IRP_MJ_DIRECTORY_CONTROL:
|
|
|
|
if (g_rdpdr_device[iorq->device].device_type ==
|
|
|
|
DEVICE_TYPE_DISK)
|
|
|
|
{
|
|
|
|
|
|
|
|
if (g_notify_stamp)
|
|
|
|
{
|
|
|
|
g_notify_stamp = False;
|
|
|
|
status = disk_check_notify(iorq->fd);
|
2007-01-04 05:55:56 +01:00
|
|
|
if (status != RD_STATUS_PENDING)
|
2004-11-03 14:56:52 +01:00
|
|
|
{
|
|
|
|
rdpdr_send_completion(iorq->device,
|
|
|
|
iorq->id,
|
|
|
|
status, 0,
|
|
|
|
NULL, 0);
|
|
|
|
iorq = rdpdr_remove_iorequest(prev,
|
|
|
|
iorq);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
prev = iorq;
|
|
|
|
if (iorq)
|
|
|
|
iorq = iorq->next;
|
|
|
|
}
|
|
|
|
|
2004-01-21 15:40:40 +01:00
|
|
|
}
|
|
|
|
|
2004-11-03 14:56:52 +01:00
|
|
|
void
|
2007-01-08 05:47:06 +01:00
|
|
|
rdpdr_check_fds(fd_set * rfds, fd_set * wfds, RD_BOOL timed_out)
|
2004-11-03 14:56:52 +01:00
|
|
|
{
|
|
|
|
fd_set dummy;
|
|
|
|
|
|
|
|
|
|
|
|
FD_ZERO(&dummy);
|
|
|
|
|
|
|
|
|
|
|
|
/* fist check event queue only,
|
|
|
|
any serial wait event must be done before read block will be sent
|
|
|
|
*/
|
|
|
|
|
|
|
|
_rdpdr_check_fds(&dummy, &dummy, False);
|
|
|
|
_rdpdr_check_fds(rfds, wfds, timed_out);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-01-21 15:40:40 +01:00
|
|
|
/* Abort a pending io request for a given handle and major */
|
2007-01-08 05:47:06 +01:00
|
|
|
RD_BOOL
|
2007-01-04 05:55:56 +01:00
|
|
|
rdpdr_abort_io(uint32 fd, uint32 major, RD_NTSTATUS status)
|
2004-01-21 15:40:40 +01:00
|
|
|
{
|
|
|
|
uint32 result;
|
|
|
|
struct async_iorequest *iorq;
|
2004-01-30 15:10:32 +01:00
|
|
|
struct async_iorequest *prev;
|
2004-01-21 15:40:40 +01:00
|
|
|
|
2004-02-07 18:32:21 +01:00
|
|
|
iorq = g_iorequest;
|
2004-01-30 15:10:32 +01:00
|
|
|
prev = NULL;
|
|
|
|
while (iorq != NULL)
|
2004-01-21 15:40:40 +01:00
|
|
|
{
|
2005-03-15 12:25:50 +01:00
|
|
|
/* Only remove from table when major is not set, or when correct major is supplied.
|
|
|
|
Abort read should not abort a write io request. */
|
2004-01-21 15:40:40 +01:00
|
|
|
if ((iorq->fd == fd) && (major == 0 || iorq->major == major))
|
|
|
|
{
|
|
|
|
result = 0;
|
2004-02-15 22:19:28 +01:00
|
|
|
rdpdr_send_completion(iorq->device, iorq->id, status, result, (uint8 *) "",
|
|
|
|
1);
|
2004-03-04 09:24:40 +01:00
|
|
|
|
|
|
|
iorq = rdpdr_remove_iorequest(prev, iorq);
|
2004-01-21 15:40:40 +01:00
|
|
|
return True;
|
|
|
|
}
|
2004-01-30 15:10:32 +01:00
|
|
|
|
|
|
|
prev = iorq;
|
|
|
|
iorq = iorq->next;
|
2004-01-21 15:40:40 +01:00
|
|
|
}
|
2004-01-30 15:10:32 +01:00
|
|
|
|
2004-01-21 15:40:40 +01:00
|
|
|
return False;
|
|
|
|
}
|