1 |
|
/* -*- c-basic-offset: 8 -*- |
2 |
|
rdesktop: A Remote Desktop Protocol client. |
3 |
|
Copyright (C) Matthew Chapman 1999-2004 |
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> |
39 |
|
#include <dirent.h> /* opendir, closedir, readdir */ |
40 |
#include <time.h> |
#include <time.h> |
41 |
#include "rdesktop.h" |
#include "rdesktop.h" |
42 |
|
|
|
#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 |
|
|
|
|
43 |
#define IRP_MJ_CREATE 0x00 |
#define IRP_MJ_CREATE 0x00 |
44 |
#define IRP_MJ_CLOSE 0x02 |
#define IRP_MJ_CLOSE 0x02 |
45 |
#define IRP_MJ_READ 0x03 |
#define IRP_MJ_READ 0x03 |
49 |
#define IRP_MJ_QUERY_VOLUME_INFORMATION 0x0a |
#define IRP_MJ_QUERY_VOLUME_INFORMATION 0x0a |
50 |
#define IRP_MJ_DIRECTORY_CONTROL 0x0c |
#define IRP_MJ_DIRECTORY_CONTROL 0x0c |
51 |
#define IRP_MJ_DEVICE_CONTROL 0x0e |
#define IRP_MJ_DEVICE_CONTROL 0x0e |
52 |
|
#define IRP_MJ_LOCK_CONTROL 0x11 |
53 |
|
|
54 |
#define IRP_MN_QUERY_DIRECTORY 0x01 |
#define IRP_MN_QUERY_DIRECTORY 0x01 |
55 |
#define IRP_MN_NOTIFY_CHANGE_DIRECTORY 0x02 |
#define IRP_MN_NOTIFY_CHANGE_DIRECTORY 0x02 |
59 |
extern DEVICE_FNS printer_fns; |
extern DEVICE_FNS printer_fns; |
60 |
extern DEVICE_FNS parallel_fns; |
extern DEVICE_FNS parallel_fns; |
61 |
extern DEVICE_FNS disk_fns; |
extern DEVICE_FNS disk_fns; |
62 |
|
extern FILEINFO g_fileinfo[]; |
63 |
|
|
64 |
static VCHANNEL *rdpdr_channel; |
static VCHANNEL *rdpdr_channel; |
65 |
|
|
66 |
/* 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 |
|
|
70 |
/* Table with information about rdpdr devices */ |
/* Table with information about rdpdr devices */ |
71 |
RDPDR_DEVICE g_rdpdr_device[RDPDR_MAX_DEVICES]; |
RDPDR_DEVICE g_rdpdr_device[RDPDR_MAX_DEVICES]; |
72 |
|
char *g_rdpdr_clientname = NULL; |
73 |
|
|
74 |
/* 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 */ |
75 |
/* 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, */ |
112 |
} |
} |
113 |
} |
} |
114 |
|
|
115 |
|
static BOOL |
116 |
|
rdpdr_handle_ok(int device, int handle) |
117 |
|
{ |
118 |
|
switch (g_rdpdr_device[device].device_type) |
119 |
|
{ |
120 |
|
case DEVICE_TYPE_PARALLEL: |
121 |
|
case DEVICE_TYPE_SERIAL: |
122 |
|
case DEVICE_TYPE_PRINTER: |
123 |
|
case DEVICE_TYPE_SCARD: |
124 |
|
if (g_rdpdr_device[device].handle != handle) |
125 |
|
return False; |
126 |
|
break; |
127 |
|
case DEVICE_TYPE_DISK: |
128 |
|
if (g_fileinfo[handle].device_id != device) |
129 |
|
return False; |
130 |
|
break; |
131 |
|
} |
132 |
|
return True; |
133 |
|
} |
134 |
|
|
135 |
/* 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 */ |
136 |
BOOL |
static BOOL |
137 |
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, |
138 |
DEVICE_FNS * fns, long total_timeout, long interval_timeout, uint8 * buffer) |
DEVICE_FNS * fns, uint32 total_timeout, uint32 interval_timeout, uint8 * buffer, |
139 |
|
uint32 offset) |
140 |
{ |
{ |
141 |
struct async_iorequest *iorq; |
struct async_iorequest *iorq; |
142 |
|
|
143 |
if (g_iorequest == NULL) |
if (g_iorequest == NULL) |
144 |
{ |
{ |
145 |
g_iorequest = (struct async_iorequest *) xmalloc(sizeof(struct async_iorequest)); |
g_iorequest = (struct async_iorequest *) xmalloc(sizeof(struct async_iorequest)); |
146 |
|
if (!g_iorequest) |
147 |
|
return False; |
148 |
g_iorequest->fd = 0; |
g_iorequest->fd = 0; |
149 |
g_iorequest->next = NULL; |
g_iorequest->next = NULL; |
150 |
} |
} |
158 |
{ |
{ |
159 |
iorq->next = |
iorq->next = |
160 |
(struct async_iorequest *) xmalloc(sizeof(struct async_iorequest)); |
(struct async_iorequest *) xmalloc(sizeof(struct async_iorequest)); |
161 |
|
if (!iorq->next) |
162 |
|
return False; |
163 |
iorq->next->fd = 0; |
iorq->next->fd = 0; |
164 |
iorq->next->next = NULL; |
iorq->next->next = NULL; |
165 |
} |
} |
175 |
iorq->timeout = total_timeout; |
iorq->timeout = total_timeout; |
176 |
iorq->itv_timeout = interval_timeout; |
iorq->itv_timeout = interval_timeout; |
177 |
iorq->buffer = buffer; |
iorq->buffer = buffer; |
178 |
|
iorq->offset = offset; |
179 |
return True; |
return True; |
180 |
} |
} |
181 |
|
|
182 |
void |
static void |
183 |
rdpdr_send_connect(void) |
rdpdr_send_connect(void) |
184 |
{ |
{ |
185 |
uint8 magic[4] = "rDCC"; |
uint8 magic[4] = "rDCC"; |
195 |
} |
} |
196 |
|
|
197 |
|
|
198 |
void |
static void |
199 |
rdpdr_send_name(void) |
rdpdr_send_name(void) |
200 |
{ |
{ |
201 |
uint8 magic[4] = "rDNC"; |
uint8 magic[4] = "rDNC"; |
|
uint32 hostlen = (strlen(hostname) + 1) * 2; |
|
202 |
STREAM s; |
STREAM s; |
203 |
|
uint32 hostlen; |
204 |
|
|
205 |
|
if (NULL == g_rdpdr_clientname) |
206 |
|
{ |
207 |
|
g_rdpdr_clientname = hostname; |
208 |
|
} |
209 |
|
hostlen = (strlen(g_rdpdr_clientname) + 1) * 2; |
210 |
|
|
211 |
s = channel_init(rdpdr_channel, 16 + hostlen); |
s = channel_init(rdpdr_channel, 16 + hostlen); |
212 |
out_uint8a(s, magic, 4); |
out_uint8a(s, magic, 4); |
214 |
out_uint16_le(s, 0x72); |
out_uint16_le(s, 0x72); |
215 |
out_uint32(s, 0); |
out_uint32(s, 0); |
216 |
out_uint32_le(s, hostlen); |
out_uint32_le(s, hostlen); |
217 |
rdp_out_unistr(s, hostname, hostlen - 2); |
rdp_out_unistr(s, g_rdpdr_clientname, hostlen - 2); |
218 |
s_mark_end(s); |
s_mark_end(s); |
219 |
channel_send(s, rdpdr_channel); |
channel_send(s, rdpdr_channel); |
220 |
} |
} |
221 |
|
|
222 |
/* Returns the size of the payload of the announce packet */ |
/* Returns the size of the payload of the announce packet */ |
223 |
int |
static int |
224 |
announcedata_size() |
announcedata_size() |
225 |
{ |
{ |
226 |
int size, i; |
int size, i; |
247 |
return size; |
return size; |
248 |
} |
} |
249 |
|
|
250 |
void |
static void |
251 |
rdpdr_send_available(void) |
rdpdr_send_available(void) |
252 |
{ |
{ |
253 |
|
|
286 |
rdp_out_unistr(s, printerinfo->printer, printerlen - 2); |
rdp_out_unistr(s, printerinfo->printer, printerlen - 2); |
287 |
out_uint8a(s, printerinfo->blob, bloblen); |
out_uint8a(s, printerinfo->blob, bloblen); |
288 |
|
|
289 |
xfree(printerinfo->blob); /* Blob is sent twice if reconnecting */ |
if (printerinfo->blob) |
290 |
|
xfree(printerinfo->blob); /* Blob is sent twice if reconnecting */ |
291 |
break; |
break; |
292 |
default: |
default: |
293 |
out_uint32(s, 0); |
out_uint32(s, 0); |
305 |
channel_send(s, rdpdr_channel); |
channel_send(s, rdpdr_channel); |
306 |
} |
} |
307 |
|
|
308 |
void |
static void |
309 |
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, |
310 |
uint32 length) |
uint32 length) |
311 |
{ |
{ |
384 |
case DEVICE_TYPE_DISK: |
case DEVICE_TYPE_DISK: |
385 |
|
|
386 |
fns = &disk_fns; |
fns = &disk_fns; |
387 |
/*rw_blocking = False; */ |
rw_blocking = False; |
388 |
break; |
break; |
389 |
|
|
390 |
case DEVICE_TYPE_SCARD: |
case DEVICE_TYPE_SCARD: |
450 |
#if WITH_DEBUG_RDP5 |
#if WITH_DEBUG_RDP5 |
451 |
DEBUG(("RDPDR IRP Read (length: %d, offset: %d)\n", length, offset)); |
DEBUG(("RDPDR IRP Read (length: %d, offset: %d)\n", length, offset)); |
452 |
#endif |
#endif |
453 |
|
if (!rdpdr_handle_ok(device, file)) |
454 |
|
{ |
455 |
|
status = STATUS_INVALID_HANDLE; |
456 |
|
break; |
457 |
|
} |
458 |
|
|
459 |
if (rw_blocking) // Complete read immediately |
if (rw_blocking) // Complete read immediately |
460 |
{ |
{ |
461 |
buffer = (uint8 *) xrealloc((void *) buffer, length); |
buffer = (uint8 *) xrealloc((void *) buffer, length); |
462 |
|
if (!buffer) |
463 |
|
{ |
464 |
|
status = STATUS_CANCELLED; |
465 |
|
break; |
466 |
|
} |
467 |
status = fns->read(file, buffer, length, offset, &result); |
status = fns->read(file, buffer, length, offset, &result); |
468 |
buffer_len = result; |
buffer_len = result; |
469 |
break; |
break; |
471 |
|
|
472 |
// Add request to table |
// Add request to table |
473 |
pst_buf = (uint8 *) xmalloc(length); |
pst_buf = (uint8 *) xmalloc(length); |
474 |
|
if (!pst_buf) |
475 |
|
{ |
476 |
|
status = STATUS_CANCELLED; |
477 |
|
break; |
478 |
|
} |
479 |
serial_get_timeout(file, length, &total_timeout, &interval_timeout); |
serial_get_timeout(file, length, &total_timeout, &interval_timeout); |
480 |
if (add_async_iorequest |
if (add_async_iorequest |
481 |
(device, file, id, major, length, fns, total_timeout, interval_timeout, |
(device, file, id, major, length, fns, total_timeout, interval_timeout, |
482 |
pst_buf)) |
pst_buf, offset)) |
483 |
{ |
{ |
484 |
status = STATUS_PENDING; |
status = STATUS_PENDING; |
485 |
break; |
break; |
503 |
#if WITH_DEBUG_RDP5 |
#if WITH_DEBUG_RDP5 |
504 |
DEBUG(("RDPDR IRP Write (length: %d)\n", result)); |
DEBUG(("RDPDR IRP Write (length: %d)\n", result)); |
505 |
#endif |
#endif |
506 |
|
if (!rdpdr_handle_ok(device, file)) |
507 |
|
{ |
508 |
|
status = STATUS_INVALID_HANDLE; |
509 |
|
break; |
510 |
|
} |
511 |
|
|
512 |
if (rw_blocking) // Complete immediately |
if (rw_blocking) // Complete immediately |
513 |
{ |
{ |
514 |
status = fns->write(file, s->p, length, offset, &result); |
status = fns->write(file, s->p, length, offset, &result); |
517 |
|
|
518 |
// Add to table |
// Add to table |
519 |
pst_buf = (uint8 *) xmalloc(length); |
pst_buf = (uint8 *) xmalloc(length); |
520 |
|
if (!pst_buf) |
521 |
|
{ |
522 |
|
status = STATUS_CANCELLED; |
523 |
|
break; |
524 |
|
} |
525 |
|
|
526 |
in_uint8a(s, pst_buf, length); |
in_uint8a(s, pst_buf, length); |
527 |
|
|
528 |
if (add_async_iorequest |
if (add_async_iorequest |
529 |
(device, file, id, major, length, fns, 0, 0, pst_buf)) |
(device, file, id, major, length, fns, 0, 0, pst_buf, offset)) |
530 |
{ |
{ |
531 |
status = STATUS_PENDING; |
status = STATUS_PENDING; |
532 |
break; |
break; |
646 |
in_uint8s(s, 0x14); |
in_uint8s(s, 0x14); |
647 |
|
|
648 |
buffer = (uint8 *) xrealloc((void *) buffer, bytes_out + 0x14); |
buffer = (uint8 *) xrealloc((void *) buffer, bytes_out + 0x14); |
649 |
|
if (!buffer) |
650 |
|
{ |
651 |
|
status = STATUS_CANCELLED; |
652 |
|
break; |
653 |
|
} |
654 |
|
|
655 |
out.data = out.p = buffer; |
out.data = out.p = buffer; |
656 |
out.size = sizeof(buffer); |
out.size = sizeof(buffer); |
657 |
status = fns->device_control(file, request, s, &out); |
status = fns->device_control(file, request, s, &out); |
658 |
result = buffer_len = out.p - out.data; |
result = buffer_len = out.p - out.data; |
659 |
break; |
break; |
660 |
|
|
661 |
|
|
662 |
|
case IRP_MJ_LOCK_CONTROL: |
663 |
|
|
664 |
|
if (g_rdpdr_device[device].device_type != DEVICE_TYPE_DISK) |
665 |
|
{ |
666 |
|
status = STATUS_INVALID_HANDLE; |
667 |
|
break; |
668 |
|
} |
669 |
|
|
670 |
|
in_uint32_le(s, info_level); |
671 |
|
|
672 |
|
out.data = out.p = buffer; |
673 |
|
out.size = sizeof(buffer); |
674 |
|
/* FIXME: Perhaps consider actually *do* |
675 |
|
something here :-) */ |
676 |
|
status = STATUS_SUCCESS; |
677 |
|
result = buffer_len = out.p - out.data; |
678 |
|
break; |
679 |
|
|
680 |
default: |
default: |
681 |
unimpl("IRP major=0x%x minor=0x%x\n", major, minor); |
unimpl("IRP major=0x%x minor=0x%x\n", major, minor); |
682 |
break; |
break; |
686 |
{ |
{ |
687 |
rdpdr_send_completion(device, id, status, result, buffer, buffer_len); |
rdpdr_send_completion(device, id, status, result, buffer, buffer_len); |
688 |
} |
} |
689 |
xfree(buffer); |
if (buffer) |
690 |
|
xfree(buffer); |
691 |
|
buffer = NULL; |
692 |
} |
} |
693 |
|
|
694 |
void |
static void |
695 |
rdpdr_send_clientcapabilty(void) |
rdpdr_send_clientcapabilty(void) |
696 |
{ |
{ |
697 |
uint8 magic[4] = "rDPC"; |
uint8 magic[4] = "rDPC"; |
807 |
void |
void |
808 |
rdpdr_add_fds(int *n, fd_set * rfds, fd_set * wfds, struct timeval *tv, BOOL * timeout) |
rdpdr_add_fds(int *n, fd_set * rfds, fd_set * wfds, struct timeval *tv, BOOL * timeout) |
809 |
{ |
{ |
810 |
long 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). |
811 |
struct async_iorequest *iorq; |
struct async_iorequest *iorq; |
812 |
|
char c; |
813 |
|
|
814 |
iorq = g_iorequest; |
iorq = g_iorequest; |
815 |
while (iorq != NULL) |
while (iorq != NULL) |
816 |
{ |
{ |
817 |
if (iorq->fd != 0) |
/* We need to test that the fd is still valid */ |
818 |
|
if ((iorq->fd != 0) && (read(iorq->fd, &c, 0) == 0)) |
819 |
{ |
{ |
820 |
switch (iorq->major) |
switch (iorq->major) |
821 |
{ |
{ |
849 |
} |
} |
850 |
} |
} |
851 |
|
|
852 |
|
struct async_iorequest * |
853 |
|
rdpdr_remove_iorequest(struct async_iorequest *prev, struct async_iorequest *iorq) |
854 |
|
{ |
855 |
|
if (!iorq) |
856 |
|
return NULL; |
857 |
|
|
858 |
|
if (iorq->buffer) |
859 |
|
xfree(iorq->buffer); |
860 |
|
if (prev) |
861 |
|
{ |
862 |
|
prev->next = iorq->next; |
863 |
|
xfree(iorq); |
864 |
|
iorq = prev->next; |
865 |
|
} |
866 |
|
else |
867 |
|
{ |
868 |
|
// Even if NULL |
869 |
|
g_iorequest = iorq->next; |
870 |
|
xfree(iorq); |
871 |
|
iorq = NULL; |
872 |
|
} |
873 |
|
return iorq; |
874 |
|
} |
875 |
|
|
876 |
/* 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 */ |
877 |
void |
void |
882 |
DEVICE_FNS *fns; |
DEVICE_FNS *fns; |
883 |
struct async_iorequest *iorq; |
struct async_iorequest *iorq; |
884 |
struct async_iorequest *prev; |
struct async_iorequest *prev; |
885 |
|
uint32 req_size = 0; |
886 |
|
|
887 |
if (timed_out) |
if (timed_out) |
888 |
{ |
{ |
894 |
prev = NULL; |
prev = NULL; |
895 |
while (iorq != NULL) |
while (iorq != NULL) |
896 |
{ |
{ |
|
|
|
897 |
if (iorq->fd != 0) |
if (iorq->fd != 0) |
898 |
{ |
{ |
899 |
switch (iorq->major) |
switch (iorq->major) |
904 |
/* Read the data */ |
/* Read the data */ |
905 |
fns = iorq->fns; |
fns = iorq->fns; |
906 |
|
|
907 |
|
req_size = |
908 |
|
(iorq->length - iorq->partial_len) > |
909 |
|
8192 ? 8192 : (iorq->length - |
910 |
|
iorq->partial_len); |
911 |
/* never read larger chunks than 8k - chances are that it will block */ |
/* never read larger chunks than 8k - chances are that it will block */ |
912 |
status = fns->read(iorq->fd, |
status = fns->read(iorq->fd, |
913 |
iorq->buffer + iorq->partial_len, |
iorq->buffer + iorq->partial_len, |
914 |
(iorq->length - |
req_size, iorq->offset, &result); |
915 |
iorq->partial_len) > |
|
916 |
8192 ? 8192 : (iorq->length - |
if (result > 0) |
917 |
iorq-> |
{ |
918 |
partial_len), 0, |
iorq->partial_len += result; |
919 |
&result); |
iorq->offset += result; |
920 |
iorq->partial_len += result; |
} |
921 |
#if WITH_DEBUG_RDP5 |
#if WITH_DEBUG_RDP5 |
922 |
DEBUG(("RDPDR: %d bytes of data read\n", result)); |
DEBUG(("RDPDR: %d bytes of data read\n", result)); |
923 |
#endif |
#endif |
924 |
/* only delete link if all data has been transfered */ |
/* only delete link if all data has been transfered */ |
925 |
if (iorq->partial_len == iorq->length) |
/* or if result was 0 and status success - EOF */ |
926 |
|
if ((iorq->partial_len == iorq->length) || |
927 |
|
(result == 0)) |
928 |
{ |
{ |
929 |
/* send the data */ |
#if WITH_DEBUG_RDP5 |
930 |
status = STATUS_SUCCESS; |
DEBUG(("RDPDR: AIO total %u bytes read of %u\n", iorq->partial_len, iorq->length)); |
931 |
|
#endif |
932 |
rdpdr_send_completion(iorq->device, |
rdpdr_send_completion(iorq->device, |
933 |
iorq->id, status, |
iorq->id, status, |
934 |
iorq->length, |
iorq->partial_len, |
935 |
iorq->buffer, result); |
iorq->buffer, |
936 |
|
iorq->partial_len); |
937 |
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); |
|
|
} |
|
938 |
} |
} |
939 |
} |
} |
940 |
break; |
break; |
944 |
/* Write data. */ |
/* Write data. */ |
945 |
fns = iorq->fns; |
fns = iorq->fns; |
946 |
|
|
947 |
|
req_size = |
948 |
|
(iorq->length - iorq->partial_len) > |
949 |
|
8192 ? 8192 : (iorq->length - |
950 |
|
iorq->partial_len); |
951 |
|
|
952 |
/* never write larger chunks than 8k - chances are that it will block */ |
/* never write larger chunks than 8k - chances are that it will block */ |
953 |
status = fns->write(iorq->fd, |
status = fns->write(iorq->fd, |
954 |
iorq->buffer + |
iorq->buffer + |
955 |
iorq->partial_len, |
iorq->partial_len, req_size, |
956 |
(iorq->length - |
iorq->offset, &result); |
957 |
iorq->partial_len) > |
|
958 |
8192 ? 8192 : (iorq->length - |
if (result > 0) |
959 |
iorq-> |
{ |
960 |
partial_len), 0, |
iorq->partial_len += result; |
961 |
&result); |
iorq->offset += result; |
962 |
iorq->partial_len += result; |
} |
963 |
|
|
964 |
#if WITH_DEBUG_RDP5 |
#if WITH_DEBUG_RDP5 |
965 |
DEBUG(("RDPDR: %d bytes of data written\n", |
DEBUG(("RDPDR: %d bytes of data written\n", |
966 |
result)); |
result)); |
967 |
#endif |
#endif |
968 |
/* only delete link if all data has been transfered */ |
/* only delete link if all data has been transfered */ |
969 |
if (iorq->partial_len == iorq->length) |
/* or we couldn't write */ |
970 |
|
if ((iorq->partial_len == iorq->length) |
971 |
|
|| (result == 0)) |
972 |
{ |
{ |
973 |
/* send a status success */ |
#if WITH_DEBUG_RDP5 |
974 |
status = STATUS_SUCCESS; |
DEBUG(("RDPDR: AIO total %u bytes written of %u\n", iorq->partial_len, iorq->length)); |
975 |
|
#endif |
976 |
rdpdr_send_completion(iorq->device, |
rdpdr_send_completion(iorq->device, |
977 |
iorq->id, status, |
iorq->id, status, |
978 |
iorq->length, "", 1); |
iorq->partial_len, |
979 |
|
(uint8 *) "", 1); |
980 |
|
|
981 |
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); |
|
|
} |
|
982 |
} |
} |
983 |
} |
} |
984 |
break; |
break; |
986 |
|
|
987 |
} |
} |
988 |
prev = iorq; |
prev = iorq; |
989 |
iorq = iorq->next; |
if (iorq) |
990 |
|
iorq = iorq->next; |
991 |
} |
} |
992 |
|
|
993 |
} |
} |
1000 |
struct async_iorequest *iorq; |
struct async_iorequest *iorq; |
1001 |
struct async_iorequest *prev; |
struct async_iorequest *prev; |
1002 |
|
|
1003 |
iorq = &g_iorequest; |
iorq = g_iorequest; |
1004 |
prev = NULL; |
prev = NULL; |
1005 |
while (iorq != NULL) |
while (iorq != NULL) |
1006 |
{ |
{ |
1009 |
if ((iorq->fd == fd) && (major == 0 || iorq->major == major)) |
if ((iorq->fd == fd) && (major == 0 || iorq->major == major)) |
1010 |
{ |
{ |
1011 |
result = 0; |
result = 0; |
1012 |
rdpdr_send_completion(iorq->device, iorq->id, status, result, "", 1); |
rdpdr_send_completion(iorq->device, iorq->id, status, result, (uint8 *) "", |
1013 |
xfree(iorq->buffer); |
1); |
1014 |
iorq->fd = 0; |
|
1015 |
if (prev != NULL) |
iorq = rdpdr_remove_iorequest(prev, iorq); |
|
{ |
|
|
prev->next = iorq->next; |
|
|
xfree(iorq); |
|
|
} |
|
|
else |
|
|
{ |
|
|
// Even if NULL |
|
|
g_iorequest = iorq->next; |
|
|
xfree(iorq); |
|
|
} |
|
1016 |
return True; |
return True; |
1017 |
} |
} |
1018 |
|
|