1 |
|
/* -*- c-basic-offset: 8 -*- |
2 |
|
rdesktop: A Remote Desktop Protocol client. |
3 |
|
Copyright (C) Matthew Chapman 1999-2005 |
4 |
|
|
5 |
|
This program is free software; you can redistribute it and/or modify |
6 |
|
it under the terms of the GNU General Public License as published by |
7 |
|
the Free Software Foundation; either version 2 of the License, or |
8 |
|
(at your option) any later version. |
9 |
|
|
10 |
|
This program is distributed in the hope that it will be useful, |
11 |
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 |
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 |
|
GNU General Public License for more details. |
14 |
|
|
15 |
|
You should have received a copy of the GNU General Public License |
16 |
|
along with this program; if not, write to the Free Software |
17 |
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
18 |
|
*/ |
19 |
|
|
20 |
|
/* |
21 |
|
Here are some resources, for your IRP hacking pleasure: |
22 |
|
|
23 |
|
http://cvs.sourceforge.net/viewcvs.py/mingw/w32api/include/ddk/winddk.h?view=markup |
24 |
|
|
25 |
|
http://win32.mvps.org/ntfs/streams.cpp |
26 |
|
|
27 |
|
http://www.acc.umu.se/~bosse/ntifs.h |
28 |
|
|
29 |
|
http://undocumented.ntinternals.net/UserMode/Undocumented%20Functions/NT%20Objects/File/ |
30 |
|
|
31 |
|
http://us1.samba.org/samba/ftp/specs/smb-nt01.txt |
32 |
|
|
33 |
|
http://www.osronline.com/ |
34 |
|
*/ |
35 |
|
|
36 |
#include <unistd.h> |
#include <unistd.h> |
37 |
#include <sys/types.h> |
#include <sys/types.h> |
38 |
#include <sys/time.h> |
#include <sys/time.h> |
39 |
|
#include <dirent.h> /* opendir, closedir, readdir */ |
40 |
#include <time.h> |
#include <time.h> |
41 |
|
#include <errno.h> |
42 |
#include "rdesktop.h" |
#include "rdesktop.h" |
43 |
|
|
|
#define IRP_MJ_CREATE 0x00 |
|
|
#define IRP_MJ_CLOSE 0x02 |
|
|
#define IRP_MJ_READ 0x03 |
|
|
#define IRP_MJ_WRITE 0x04 |
|
|
#define IRP_MJ_DEVICE_CONTROL 0x0e |
|
|
|
|
44 |
#define IRP_MJ_CREATE 0x00 |
#define IRP_MJ_CREATE 0x00 |
45 |
#define IRP_MJ_CLOSE 0x02 |
#define IRP_MJ_CLOSE 0x02 |
46 |
#define IRP_MJ_READ 0x03 |
#define IRP_MJ_READ 0x03 |
50 |
#define IRP_MJ_QUERY_VOLUME_INFORMATION 0x0a |
#define IRP_MJ_QUERY_VOLUME_INFORMATION 0x0a |
51 |
#define IRP_MJ_DIRECTORY_CONTROL 0x0c |
#define IRP_MJ_DIRECTORY_CONTROL 0x0c |
52 |
#define IRP_MJ_DEVICE_CONTROL 0x0e |
#define IRP_MJ_DEVICE_CONTROL 0x0e |
53 |
|
#define IRP_MJ_LOCK_CONTROL 0x11 |
54 |
|
|
55 |
#define IRP_MN_QUERY_DIRECTORY 0x01 |
#define IRP_MN_QUERY_DIRECTORY 0x01 |
56 |
#define IRP_MN_NOTIFY_CHANGE_DIRECTORY 0x02 |
#define IRP_MN_NOTIFY_CHANGE_DIRECTORY 0x02 |
57 |
|
|
58 |
extern char hostname[16]; |
extern char g_hostname[16]; |
59 |
extern DEVICE_FNS serial_fns; |
extern DEVICE_FNS serial_fns; |
60 |
extern DEVICE_FNS printer_fns; |
extern DEVICE_FNS printer_fns; |
61 |
extern DEVICE_FNS parallel_fns; |
extern DEVICE_FNS parallel_fns; |
62 |
extern DEVICE_FNS disk_fns; |
extern DEVICE_FNS disk_fns; |
63 |
|
extern FILEINFO g_fileinfo[]; |
64 |
|
extern BOOL g_notify_stamp; |
65 |
|
|
66 |
static VCHANNEL *rdpdr_channel; |
static VCHANNEL *rdpdr_channel; |
67 |
|
|
68 |
/* If select() times out, the request for the device with handle g_min_timeout_fd is aborted */ |
/* If select() times out, the request for the device with handle g_min_timeout_fd is aborted */ |
69 |
HANDLE g_min_timeout_fd; |
NTHANDLE g_min_timeout_fd; |
70 |
uint32 g_num_devices; |
uint32 g_num_devices; |
71 |
|
|
72 |
/* Table with information about rdpdr devices */ |
/* Table with information about rdpdr devices */ |
73 |
RDPDR_DEVICE g_rdpdr_device[RDPDR_MAX_DEVICES]; |
RDPDR_DEVICE g_rdpdr_device[RDPDR_MAX_DEVICES]; |
74 |
|
char *g_rdpdr_clientname = NULL; |
75 |
|
|
76 |
/* Used to store incoming io request, until they are ready to be completed */ |
/* Used to store incoming io request, until they are ready to be completed */ |
77 |
/* using a linked list ensures that they are processed in the right order, */ |
/* using a linked list ensures that they are processed in the right order, */ |
91 |
|
|
92 |
/* Return device_id for a given handle */ |
/* Return device_id for a given handle */ |
93 |
int |
int |
94 |
get_device_index(HANDLE handle) |
get_device_index(NTHANDLE handle) |
95 |
{ |
{ |
96 |
int i; |
int i; |
97 |
for (i = 0; i < RDPDR_MAX_DEVICES; i++) |
for (i = 0; i < RDPDR_MAX_DEVICES; i++) |
114 |
} |
} |
115 |
} |
} |
116 |
|
|
117 |
|
static BOOL |
118 |
|
rdpdr_handle_ok(int device, int handle) |
119 |
|
{ |
120 |
|
switch (g_rdpdr_device[device].device_type) |
121 |
|
{ |
122 |
|
case DEVICE_TYPE_PARALLEL: |
123 |
|
case DEVICE_TYPE_SERIAL: |
124 |
|
case DEVICE_TYPE_PRINTER: |
125 |
|
case DEVICE_TYPE_SCARD: |
126 |
|
if (g_rdpdr_device[device].handle != handle) |
127 |
|
return False; |
128 |
|
break; |
129 |
|
case DEVICE_TYPE_DISK: |
130 |
|
if (g_fileinfo[handle].device_id != device) |
131 |
|
return False; |
132 |
|
break; |
133 |
|
} |
134 |
|
return True; |
135 |
|
} |
136 |
|
|
137 |
/* Add a new io request to the table containing pending io requests so it won't block rdesktop */ |
/* Add a new io request to the table containing pending io requests so it won't block rdesktop */ |
138 |
BOOL |
static BOOL |
139 |
add_async_iorequest(uint32 device, uint32 file, uint32 id, uint32 major, uint32 length, |
add_async_iorequest(uint32 device, uint32 file, uint32 id, uint32 major, uint32 length, |
140 |
DEVICE_FNS * fns, uint32 total_timeout, uint32 interval_timeout, uint8 * buffer) |
DEVICE_FNS * fns, uint32 total_timeout, uint32 interval_timeout, uint8 * buffer, |
141 |
|
uint32 offset) |
142 |
{ |
{ |
143 |
struct async_iorequest *iorq; |
struct async_iorequest *iorq; |
144 |
|
|
177 |
iorq->timeout = total_timeout; |
iorq->timeout = total_timeout; |
178 |
iorq->itv_timeout = interval_timeout; |
iorq->itv_timeout = interval_timeout; |
179 |
iorq->buffer = buffer; |
iorq->buffer = buffer; |
180 |
|
iorq->offset = offset; |
181 |
return True; |
return True; |
182 |
} |
} |
183 |
|
|
184 |
void |
static void |
185 |
rdpdr_send_connect(void) |
rdpdr_send_connect(void) |
186 |
{ |
{ |
187 |
uint8 magic[4] = "rDCC"; |
uint8 magic[4] = "rDCC"; |
197 |
} |
} |
198 |
|
|
199 |
|
|
200 |
void |
static void |
201 |
rdpdr_send_name(void) |
rdpdr_send_name(void) |
202 |
{ |
{ |
203 |
uint8 magic[4] = "rDNC"; |
uint8 magic[4] = "rDNC"; |
|
uint32 hostlen = (strlen(hostname) + 1) * 2; |
|
204 |
STREAM s; |
STREAM s; |
205 |
|
uint32 hostlen; |
206 |
|
|
207 |
|
if (NULL == g_rdpdr_clientname) |
208 |
|
{ |
209 |
|
g_rdpdr_clientname = g_hostname; |
210 |
|
} |
211 |
|
hostlen = (strlen(g_rdpdr_clientname) + 1) * 2; |
212 |
|
|
213 |
s = channel_init(rdpdr_channel, 16 + hostlen); |
s = channel_init(rdpdr_channel, 16 + hostlen); |
214 |
out_uint8a(s, magic, 4); |
out_uint8a(s, magic, 4); |
216 |
out_uint16_le(s, 0x72); |
out_uint16_le(s, 0x72); |
217 |
out_uint32(s, 0); |
out_uint32(s, 0); |
218 |
out_uint32_le(s, hostlen); |
out_uint32_le(s, hostlen); |
219 |
rdp_out_unistr(s, hostname, hostlen - 2); |
rdp_out_unistr(s, g_rdpdr_clientname, hostlen - 2); |
220 |
s_mark_end(s); |
s_mark_end(s); |
221 |
channel_send(s, rdpdr_channel); |
channel_send(s, rdpdr_channel); |
222 |
} |
} |
223 |
|
|
224 |
/* Returns the size of the payload of the announce packet */ |
/* Returns the size of the payload of the announce packet */ |
225 |
int |
static int |
226 |
announcedata_size() |
announcedata_size() |
227 |
{ |
{ |
228 |
int size, i; |
int size, i; |
249 |
return size; |
return size; |
250 |
} |
} |
251 |
|
|
252 |
void |
static void |
253 |
rdpdr_send_available(void) |
rdpdr_send_available(void) |
254 |
{ |
{ |
255 |
|
|
267 |
{ |
{ |
268 |
out_uint32_le(s, g_rdpdr_device[i].device_type); |
out_uint32_le(s, g_rdpdr_device[i].device_type); |
269 |
out_uint32_le(s, i); /* RDP Device ID */ |
out_uint32_le(s, i); /* RDP Device ID */ |
270 |
|
/* Is it possible to use share names longer than 8 chars? |
271 |
|
/astrand */ |
272 |
out_uint8p(s, g_rdpdr_device[i].name, 8); |
out_uint8p(s, g_rdpdr_device[i].name, 8); |
273 |
|
|
274 |
switch (g_rdpdr_device[i].device_type) |
switch (g_rdpdr_device[i].device_type) |
309 |
channel_send(s, rdpdr_channel); |
channel_send(s, rdpdr_channel); |
310 |
} |
} |
311 |
|
|
312 |
void |
static void |
313 |
rdpdr_send_completion(uint32 device, uint32 id, uint32 status, uint32 result, uint8 * buffer, |
rdpdr_send_completion(uint32 device, uint32 id, uint32 status, uint32 result, uint8 * buffer, |
314 |
uint32 length) |
uint32 length) |
315 |
{ |
{ |
324 |
out_uint32_le(s, result); |
out_uint32_le(s, result); |
325 |
out_uint8p(s, buffer, length); |
out_uint8p(s, buffer, length); |
326 |
s_mark_end(s); |
s_mark_end(s); |
327 |
/* JIF |
/* JIF */ |
328 |
hexdump(s->channel_hdr + 8, s->end - s->channel_hdr - 8); */ |
#ifdef WITH_DEBUG_RDP5 |
329 |
|
printf("--> rdpdr_send_completion\n"); |
330 |
|
//hexdump(s->channel_hdr + 8, s->end - s->channel_hdr - 8); |
331 |
|
#endif |
332 |
channel_send(s, rdpdr_channel); |
channel_send(s, rdpdr_channel); |
333 |
} |
} |
334 |
|
|
457 |
#if WITH_DEBUG_RDP5 |
#if WITH_DEBUG_RDP5 |
458 |
DEBUG(("RDPDR IRP Read (length: %d, offset: %d)\n", length, offset)); |
DEBUG(("RDPDR IRP Read (length: %d, offset: %d)\n", length, offset)); |
459 |
#endif |
#endif |
460 |
|
if (!rdpdr_handle_ok(device, file)) |
461 |
|
{ |
462 |
|
status = STATUS_INVALID_HANDLE; |
463 |
|
break; |
464 |
|
} |
465 |
|
|
466 |
if (rw_blocking) // Complete read immediately |
if (rw_blocking) // Complete read immediately |
467 |
{ |
{ |
468 |
buffer = (uint8 *) xrealloc((void *) buffer, length); |
buffer = (uint8 *) xrealloc((void *) buffer, length); |
486 |
serial_get_timeout(file, length, &total_timeout, &interval_timeout); |
serial_get_timeout(file, length, &total_timeout, &interval_timeout); |
487 |
if (add_async_iorequest |
if (add_async_iorequest |
488 |
(device, file, id, major, length, fns, total_timeout, interval_timeout, |
(device, file, id, major, length, fns, total_timeout, interval_timeout, |
489 |
pst_buf)) |
pst_buf, offset)) |
490 |
{ |
{ |
491 |
status = STATUS_PENDING; |
status = STATUS_PENDING; |
492 |
break; |
break; |
510 |
#if WITH_DEBUG_RDP5 |
#if WITH_DEBUG_RDP5 |
511 |
DEBUG(("RDPDR IRP Write (length: %d)\n", result)); |
DEBUG(("RDPDR IRP Write (length: %d)\n", result)); |
512 |
#endif |
#endif |
513 |
|
if (!rdpdr_handle_ok(device, file)) |
514 |
|
{ |
515 |
|
status = STATUS_INVALID_HANDLE; |
516 |
|
break; |
517 |
|
} |
518 |
|
|
519 |
if (rw_blocking) // Complete immediately |
if (rw_blocking) // Complete immediately |
520 |
{ |
{ |
521 |
status = fns->write(file, s->p, length, offset, &result); |
status = fns->write(file, s->p, length, offset, &result); |
533 |
in_uint8a(s, pst_buf, length); |
in_uint8a(s, pst_buf, length); |
534 |
|
|
535 |
if (add_async_iorequest |
if (add_async_iorequest |
536 |
(device, file, id, major, length, fns, 0, 0, pst_buf)) |
(device, file, id, major, length, fns, 0, 0, pst_buf, offset)) |
537 |
{ |
{ |
538 |
status = STATUS_PENDING; |
status = STATUS_PENDING; |
539 |
break; |
break; |
627 |
case IRP_MN_NOTIFY_CHANGE_DIRECTORY: |
case IRP_MN_NOTIFY_CHANGE_DIRECTORY: |
628 |
|
|
629 |
/* JIF |
/* JIF |
630 |
unimpl("IRP major=0x%x minor=0x%x: IRP_MN_NOTIFY_CHANGE_DIRECTORY\n", major, minor); */ |
unimpl("IRP major=0x%x minor=0x%x: IRP_MN_NOTIFY_CHANGE_DIRECTORY\n", major, minor); */ |
631 |
status = STATUS_PENDING; // Don't send completion packet |
|
632 |
|
in_uint32_le(s, info_level); // notify mask |
633 |
|
|
634 |
|
g_notify_stamp = True; |
635 |
|
|
636 |
|
status = disk_create_notify(file, info_level); |
637 |
|
result = 0; |
638 |
|
|
639 |
|
if (status == STATUS_PENDING) |
640 |
|
add_async_iorequest(device, file, id, major, length, |
641 |
|
fns, 0, 0, NULL, 0); |
642 |
break; |
break; |
643 |
|
|
644 |
default: |
default: |
645 |
|
|
646 |
status = STATUS_INVALID_PARAMETER; |
status = STATUS_INVALID_PARAMETER; |
647 |
/* JIF |
/* JIF */ |
648 |
unimpl("IRP major=0x%x minor=0x%x\n", major, minor); */ |
unimpl("IRP major=0x%x minor=0x%x\n", major, minor); |
649 |
} |
} |
650 |
break; |
break; |
651 |
|
|
673 |
out.size = sizeof(buffer); |
out.size = sizeof(buffer); |
674 |
status = fns->device_control(file, request, s, &out); |
status = fns->device_control(file, request, s, &out); |
675 |
result = buffer_len = out.p - out.data; |
result = buffer_len = out.p - out.data; |
676 |
|
|
677 |
|
/* Serial SERIAL_WAIT_ON_MASK */ |
678 |
|
if (status == STATUS_PENDING) |
679 |
|
{ |
680 |
|
if (add_async_iorequest |
681 |
|
(device, file, id, major, length, fns, 0, 0, NULL, 0)) |
682 |
|
{ |
683 |
|
status = STATUS_PENDING; |
684 |
|
break; |
685 |
|
} |
686 |
|
} |
687 |
|
break; |
688 |
|
|
689 |
|
|
690 |
|
case IRP_MJ_LOCK_CONTROL: |
691 |
|
|
692 |
|
if (g_rdpdr_device[device].device_type != DEVICE_TYPE_DISK) |
693 |
|
{ |
694 |
|
status = STATUS_INVALID_HANDLE; |
695 |
|
break; |
696 |
|
} |
697 |
|
|
698 |
|
in_uint32_le(s, info_level); |
699 |
|
|
700 |
|
out.data = out.p = buffer; |
701 |
|
out.size = sizeof(buffer); |
702 |
|
/* FIXME: Perhaps consider actually *do* |
703 |
|
something here :-) */ |
704 |
|
status = STATUS_SUCCESS; |
705 |
|
result = buffer_len = out.p - out.data; |
706 |
break; |
break; |
707 |
|
|
708 |
default: |
default: |
719 |
buffer = NULL; |
buffer = NULL; |
720 |
} |
} |
721 |
|
|
722 |
void |
static void |
723 |
rdpdr_send_clientcapabilty(void) |
rdpdr_send_clientcapabilty(void) |
724 |
{ |
{ |
725 |
uint8 magic[4] = "rDPC"; |
uint8 magic[4] = "rDPC"; |
837 |
{ |
{ |
838 |
uint32 select_timeout = 0; // Timeout value to be used for select() (in millisecons). |
uint32 select_timeout = 0; // Timeout value to be used for select() (in millisecons). |
839 |
struct async_iorequest *iorq; |
struct async_iorequest *iorq; |
840 |
|
char c; |
841 |
|
|
842 |
iorq = g_iorequest; |
iorq = g_iorequest; |
843 |
while (iorq != NULL) |
while (iorq != NULL) |
847 |
switch (iorq->major) |
switch (iorq->major) |
848 |
{ |
{ |
849 |
case IRP_MJ_READ: |
case IRP_MJ_READ: |
850 |
|
/* Is this FD valid? FDs will |
851 |
|
be invalid when |
852 |
|
reconnecting. FIXME: Real |
853 |
|
support for reconnects. */ |
854 |
|
|
855 |
FD_SET(iorq->fd, rfds); |
FD_SET(iorq->fd, rfds); |
856 |
|
*n = MAX(*n, iorq->fd); |
857 |
|
|
858 |
// Check if io request timeout is smaller than current (but not 0). |
/* Check if io request timeout is smaller than current (but not 0). */ |
859 |
if (iorq->timeout |
if (iorq->timeout |
860 |
&& (select_timeout == 0 |
&& (select_timeout == 0 |
861 |
|| iorq->timeout < select_timeout)) |
|| iorq->timeout < select_timeout)) |
862 |
{ |
{ |
863 |
// Set new timeout |
/* Set new timeout */ |
864 |
select_timeout = iorq->timeout; |
select_timeout = iorq->timeout; |
865 |
g_min_timeout_fd = iorq->fd; /* Remember fd */ |
g_min_timeout_fd = iorq->fd; /* Remember fd */ |
866 |
tv->tv_sec = select_timeout / 1000; |
tv->tv_sec = select_timeout / 1000; |
867 |
tv->tv_usec = (select_timeout % 1000) * 1000; |
tv->tv_usec = (select_timeout % 1000) * 1000; |
868 |
*timeout = True; |
*timeout = True; |
869 |
|
break; |
870 |
|
} |
871 |
|
if (iorq->itv_timeout && iorq->partial_len > 0 |
872 |
|
&& (select_timeout == 0 |
873 |
|
|| iorq->itv_timeout < select_timeout)) |
874 |
|
{ |
875 |
|
/* Set new timeout */ |
876 |
|
select_timeout = iorq->itv_timeout; |
877 |
|
g_min_timeout_fd = iorq->fd; /* Remember fd */ |
878 |
|
tv->tv_sec = select_timeout / 1000; |
879 |
|
tv->tv_usec = (select_timeout % 1000) * 1000; |
880 |
|
*timeout = True; |
881 |
|
break; |
882 |
} |
} |
883 |
break; |
break; |
884 |
|
|
885 |
case IRP_MJ_WRITE: |
case IRP_MJ_WRITE: |
886 |
|
/* FD still valid? See above. */ |
887 |
|
if ((write(iorq->fd, &c, 0) != 0) && (errno == EBADF)) |
888 |
|
break; |
889 |
|
|
890 |
FD_SET(iorq->fd, wfds); |
FD_SET(iorq->fd, wfds); |
891 |
|
*n = MAX(*n, iorq->fd); |
892 |
|
break; |
893 |
|
|
894 |
|
case IRP_MJ_DEVICE_CONTROL: |
895 |
|
if (select_timeout > 5) |
896 |
|
select_timeout = 5; /* serial event queue */ |
897 |
break; |
break; |
898 |
|
|
899 |
} |
} |
900 |
*n = MAX(*n, iorq->fd); |
|
901 |
} |
} |
902 |
|
|
903 |
iorq = iorq->next; |
iorq = iorq->next; |
904 |
} |
} |
905 |
} |
} |
906 |
|
|
907 |
|
struct async_iorequest * |
908 |
|
rdpdr_remove_iorequest(struct async_iorequest *prev, struct async_iorequest *iorq) |
909 |
|
{ |
910 |
|
if (!iorq) |
911 |
|
return NULL; |
912 |
|
|
913 |
|
if (iorq->buffer) |
914 |
|
xfree(iorq->buffer); |
915 |
|
if (prev) |
916 |
|
{ |
917 |
|
prev->next = iorq->next; |
918 |
|
xfree(iorq); |
919 |
|
iorq = prev->next; |
920 |
|
} |
921 |
|
else |
922 |
|
{ |
923 |
|
// Even if NULL |
924 |
|
g_iorequest = iorq->next; |
925 |
|
xfree(iorq); |
926 |
|
iorq = NULL; |
927 |
|
} |
928 |
|
return iorq; |
929 |
|
} |
930 |
|
|
931 |
/* Check if select() returned with one of the rdpdr file descriptors, and complete io if it did */ |
/* Check if select() returned with one of the rdpdr file descriptors, and complete io if it did */ |
932 |
void |
void |
933 |
rdpdr_check_fds(fd_set * rfds, fd_set * wfds, BOOL timed_out) |
_rdpdr_check_fds(fd_set * rfds, fd_set * wfds, BOOL timed_out) |
934 |
{ |
{ |
935 |
NTSTATUS status; |
NTSTATUS status; |
936 |
uint32 result = 0; |
uint32 result = 0; |
938 |
struct async_iorequest *iorq; |
struct async_iorequest *iorq; |
939 |
struct async_iorequest *prev; |
struct async_iorequest *prev; |
940 |
uint32 req_size = 0; |
uint32 req_size = 0; |
941 |
|
uint32 buffer_len; |
942 |
|
struct stream out; |
943 |
|
uint8 *buffer = NULL; |
944 |
|
|
945 |
|
|
946 |
if (timed_out) |
if (timed_out) |
947 |
{ |
{ |
948 |
|
/* check serial iv_timeout */ |
949 |
|
|
950 |
|
iorq = g_iorequest; |
951 |
|
prev = NULL; |
952 |
|
while (iorq != NULL) |
953 |
|
{ |
954 |
|
if (iorq->fd == g_min_timeout_fd) |
955 |
|
{ |
956 |
|
if ((iorq->partial_len > 0) && |
957 |
|
(g_rdpdr_device[iorq->device].device_type == |
958 |
|
DEVICE_TYPE_SERIAL)) |
959 |
|
{ |
960 |
|
|
961 |
|
/* iv_timeout between 2 chars, send partial_len */ |
962 |
|
//printf("RDPDR: IVT total %u bytes read of %u\n", iorq->partial_len, iorq->length); |
963 |
|
rdpdr_send_completion(iorq->device, |
964 |
|
iorq->id, STATUS_SUCCESS, |
965 |
|
iorq->partial_len, |
966 |
|
iorq->buffer, iorq->partial_len); |
967 |
|
iorq = rdpdr_remove_iorequest(prev, iorq); |
968 |
|
return; |
969 |
|
} |
970 |
|
else |
971 |
|
{ |
972 |
|
break; |
973 |
|
} |
974 |
|
|
975 |
|
} |
976 |
|
else |
977 |
|
{ |
978 |
|
break; |
979 |
|
} |
980 |
|
|
981 |
|
|
982 |
|
prev = iorq; |
983 |
|
if (iorq) |
984 |
|
iorq = iorq->next; |
985 |
|
|
986 |
|
} |
987 |
|
|
988 |
rdpdr_abort_io(g_min_timeout_fd, 0, STATUS_TIMEOUT); |
rdpdr_abort_io(g_min_timeout_fd, 0, STATUS_TIMEOUT); |
989 |
return; |
return; |
990 |
} |
} |
1010 |
/* never read larger chunks than 8k - chances are that it will block */ |
/* never read larger chunks than 8k - chances are that it will block */ |
1011 |
status = fns->read(iorq->fd, |
status = fns->read(iorq->fd, |
1012 |
iorq->buffer + iorq->partial_len, |
iorq->buffer + iorq->partial_len, |
1013 |
req_size, 0, &result); |
req_size, iorq->offset, &result); |
|
iorq->partial_len += result; |
|
1014 |
|
|
1015 |
|
if ((long) result > 0) |
1016 |
|
{ |
1017 |
|
iorq->partial_len += result; |
1018 |
|
iorq->offset += result; |
1019 |
|
} |
1020 |
#if WITH_DEBUG_RDP5 |
#if WITH_DEBUG_RDP5 |
1021 |
DEBUG(("RDPDR: %d bytes of data read\n", result)); |
DEBUG(("RDPDR: %d bytes of data read\n", result)); |
1022 |
#endif |
#endif |
1028 |
#if WITH_DEBUG_RDP5 |
#if WITH_DEBUG_RDP5 |
1029 |
DEBUG(("RDPDR: AIO total %u bytes read of %u\n", iorq->partial_len, iorq->length)); |
DEBUG(("RDPDR: AIO total %u bytes read of %u\n", iorq->partial_len, iorq->length)); |
1030 |
#endif |
#endif |
|
/* send the data */ |
|
|
status = STATUS_SUCCESS; |
|
1031 |
rdpdr_send_completion(iorq->device, |
rdpdr_send_completion(iorq->device, |
1032 |
iorq->id, status, |
iorq->id, status, |
1033 |
iorq->partial_len, |
iorq->partial_len, |
1034 |
iorq->buffer, |
iorq->buffer, |
1035 |
iorq->partial_len); |
iorq->partial_len); |
1036 |
xfree(iorq->buffer); |
iorq = rdpdr_remove_iorequest(prev, iorq); |
|
iorq->fd = 0; |
|
|
if (prev != NULL) |
|
|
{ |
|
|
prev->next = iorq->next; |
|
|
xfree(iorq); |
|
|
} |
|
|
else |
|
|
{ |
|
|
// Even if NULL |
|
|
g_iorequest = iorq->next; |
|
|
xfree(iorq); |
|
|
} |
|
1037 |
} |
} |
1038 |
} |
} |
1039 |
break; |
break; |
1051 |
/* never write larger chunks than 8k - chances are that it will block */ |
/* never write larger chunks than 8k - chances are that it will block */ |
1052 |
status = fns->write(iorq->fd, |
status = fns->write(iorq->fd, |
1053 |
iorq->buffer + |
iorq->buffer + |
1054 |
iorq->partial_len, req_size, 0, |
iorq->partial_len, req_size, |
1055 |
&result); |
iorq->offset, &result); |
1056 |
iorq->partial_len += result; |
|
1057 |
|
if ((long) result > 0) |
1058 |
|
{ |
1059 |
|
iorq->partial_len += result; |
1060 |
|
iorq->offset += result; |
1061 |
|
} |
1062 |
|
|
1063 |
#if WITH_DEBUG_RDP5 |
#if WITH_DEBUG_RDP5 |
1064 |
DEBUG(("RDPDR: %d bytes of data written\n", |
DEBUG(("RDPDR: %d bytes of data written\n", |
1065 |
result)); |
result)); |
1072 |
#if WITH_DEBUG_RDP5 |
#if WITH_DEBUG_RDP5 |
1073 |
DEBUG(("RDPDR: AIO total %u bytes written of %u\n", iorq->partial_len, iorq->length)); |
DEBUG(("RDPDR: AIO total %u bytes written of %u\n", iorq->partial_len, iorq->length)); |
1074 |
#endif |
#endif |
|
/* send a status success */ |
|
|
status = STATUS_SUCCESS; |
|
1075 |
rdpdr_send_completion(iorq->device, |
rdpdr_send_completion(iorq->device, |
1076 |
iorq->id, status, |
iorq->id, status, |
1077 |
iorq->partial_len, |
iorq->partial_len, |
1078 |
(uint8 *) "", 1); |
(uint8 *) "", 1); |
1079 |
|
|
1080 |
xfree(iorq->buffer); |
iorq = rdpdr_remove_iorequest(prev, iorq); |
1081 |
iorq->fd = 0; |
} |
1082 |
if (prev != NULL) |
} |
1083 |
{ |
break; |
1084 |
prev->next = iorq->next; |
case IRP_MJ_DEVICE_CONTROL: |
1085 |
xfree(iorq); |
if (serial_get_event(iorq->fd, &result)) |
1086 |
} |
{ |
1087 |
else |
buffer = (uint8 *) xrealloc((void *) buffer, 0x14); |
1088 |
|
out.data = out.p = buffer; |
1089 |
|
out.size = sizeof(buffer); |
1090 |
|
out_uint32_le(&out, result); |
1091 |
|
result = buffer_len = out.p - out.data; |
1092 |
|
status = STATUS_SUCCESS; |
1093 |
|
rdpdr_send_completion(iorq->device, iorq->id, |
1094 |
|
status, result, buffer, |
1095 |
|
buffer_len); |
1096 |
|
xfree(buffer); |
1097 |
|
iorq = rdpdr_remove_iorequest(prev, iorq); |
1098 |
|
} |
1099 |
|
|
1100 |
|
break; |
1101 |
|
} |
1102 |
|
|
1103 |
|
} |
1104 |
|
prev = iorq; |
1105 |
|
if (iorq) |
1106 |
|
iorq = iorq->next; |
1107 |
|
} |
1108 |
|
|
1109 |
|
/* Check notify */ |
1110 |
|
iorq = g_iorequest; |
1111 |
|
prev = NULL; |
1112 |
|
while (iorq != NULL) |
1113 |
|
{ |
1114 |
|
if (iorq->fd != 0) |
1115 |
|
{ |
1116 |
|
switch (iorq->major) |
1117 |
|
{ |
1118 |
|
|
1119 |
|
case IRP_MJ_DIRECTORY_CONTROL: |
1120 |
|
if (g_rdpdr_device[iorq->device].device_type == |
1121 |
|
DEVICE_TYPE_DISK) |
1122 |
|
{ |
1123 |
|
|
1124 |
|
if (g_notify_stamp) |
1125 |
|
{ |
1126 |
|
g_notify_stamp = False; |
1127 |
|
status = disk_check_notify(iorq->fd); |
1128 |
|
if (status != STATUS_PENDING) |
1129 |
{ |
{ |
1130 |
// Even if NULL |
rdpdr_send_completion(iorq->device, |
1131 |
g_iorequest = iorq->next; |
iorq->id, |
1132 |
xfree(iorq); |
status, 0, |
1133 |
|
NULL, 0); |
1134 |
|
iorq = rdpdr_remove_iorequest(prev, |
1135 |
|
iorq); |
1136 |
} |
} |
1137 |
} |
} |
1138 |
} |
} |
1139 |
break; |
break; |
|
} |
|
1140 |
|
|
1141 |
|
|
1142 |
|
|
1143 |
|
} |
1144 |
} |
} |
1145 |
|
|
1146 |
prev = iorq; |
prev = iorq; |
1147 |
iorq = iorq->next; |
if (iorq) |
1148 |
|
iorq = iorq->next; |
1149 |
} |
} |
1150 |
|
|
1151 |
} |
} |
1152 |
|
|
1153 |
|
void |
1154 |
|
rdpdr_check_fds(fd_set * rfds, fd_set * wfds, BOOL timed_out) |
1155 |
|
{ |
1156 |
|
fd_set dummy; |
1157 |
|
|
1158 |
|
|
1159 |
|
FD_ZERO(&dummy); |
1160 |
|
|
1161 |
|
|
1162 |
|
/* fist check event queue only, |
1163 |
|
any serial wait event must be done before read block will be sent |
1164 |
|
*/ |
1165 |
|
|
1166 |
|
_rdpdr_check_fds(&dummy, &dummy, False); |
1167 |
|
_rdpdr_check_fds(rfds, wfds, timed_out); |
1168 |
|
} |
1169 |
|
|
1170 |
|
|
1171 |
/* Abort a pending io request for a given handle and major */ |
/* Abort a pending io request for a given handle and major */ |
1172 |
BOOL |
BOOL |
1173 |
rdpdr_abort_io(uint32 fd, uint32 major, NTSTATUS status) |
rdpdr_abort_io(uint32 fd, uint32 major, NTSTATUS status) |
1187 |
result = 0; |
result = 0; |
1188 |
rdpdr_send_completion(iorq->device, iorq->id, status, result, (uint8 *) "", |
rdpdr_send_completion(iorq->device, iorq->id, status, result, (uint8 *) "", |
1189 |
1); |
1); |
1190 |
xfree(iorq->buffer); |
|
1191 |
iorq->fd = 0; |
iorq = rdpdr_remove_iorequest(prev, iorq); |
|
if (prev != NULL) |
|
|
{ |
|
|
prev->next = iorq->next; |
|
|
xfree(iorq); |
|
|
} |
|
|
else |
|
|
{ |
|
|
// Even if NULL |
|
|
g_iorequest = iorq->next; |
|
|
xfree(iorq); |
|
|
} |
|
1192 |
return True; |
return True; |
1193 |
} |
} |
1194 |
|
|