22 |
#define IRP_MN_QUERY_DIRECTORY 0x01 |
#define IRP_MN_QUERY_DIRECTORY 0x01 |
23 |
#define IRP_MN_NOTIFY_CHANGE_DIRECTORY 0x02 |
#define IRP_MN_NOTIFY_CHANGE_DIRECTORY 0x02 |
24 |
|
|
|
#define MAX_ASYNC_IO_REQUESTS 10 |
|
|
|
|
25 |
extern char hostname[16]; |
extern char hostname[16]; |
26 |
extern DEVICE_FNS serial_fns; |
extern DEVICE_FNS serial_fns; |
27 |
extern DEVICE_FNS printer_fns; |
extern DEVICE_FNS printer_fns; |
28 |
extern DEVICE_FNS parallel_fns; |
extern DEVICE_FNS parallel_fns; |
29 |
extern DEVICE_FNS disk_fns; |
extern DEVICE_FNS disk_fns; |
30 |
|
|
|
|
|
31 |
static VCHANNEL *rdpdr_channel; |
static VCHANNEL *rdpdr_channel; |
32 |
|
|
33 |
/* 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 */ |
38 |
RDPDR_DEVICE g_rdpdr_device[RDPDR_MAX_DEVICES]; |
RDPDR_DEVICE g_rdpdr_device[RDPDR_MAX_DEVICES]; |
39 |
|
|
40 |
/* 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 */ |
41 |
|
/* using a linked list ensures that they are processed in the right order, */ |
42 |
|
/* if multiple ios are being done on the same fd */ |
43 |
struct async_iorequest |
struct async_iorequest |
44 |
{ |
{ |
45 |
uint32 fd, major, minor, offset, device, id, length; |
uint32 fd, major, minor, offset, device, id, length, partial_len; |
46 |
long timeout, /* Total timeout */ |
long timeout, /* Total timeout */ |
47 |
itv_timeout; /* Interval timeout (between serial characters) */ |
itv_timeout; /* Interval timeout (between serial characters) */ |
48 |
uint8 *buffer; |
uint8 *buffer; |
49 |
DEVICE_FNS *fns; |
DEVICE_FNS *fns; |
50 |
} g_iorequest[MAX_ASYNC_IO_REQUESTS]; |
|
51 |
|
struct async_iorequest *next; /* next element in list */ |
52 |
|
}; |
53 |
|
|
54 |
|
struct async_iorequest *g_iorequest; |
55 |
|
|
56 |
/* Return device_id for a given handle */ |
/* Return device_id for a given handle */ |
57 |
int |
int |
83 |
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, |
84 |
DEVICE_FNS * fns, long total_timeout, long interval_timeout, uint8 * buffer) |
DEVICE_FNS * fns, long total_timeout, long interval_timeout, uint8 * buffer) |
85 |
{ |
{ |
|
int i; |
|
86 |
struct async_iorequest *iorq; |
struct async_iorequest *iorq; |
87 |
|
|
88 |
for (i = 0; i < MAX_ASYNC_IO_REQUESTS; i++) |
if (g_iorequest == NULL) |
89 |
{ |
{ |
90 |
iorq = &g_iorequest[i]; |
g_iorequest = (struct async_iorequest *) xmalloc(sizeof(struct async_iorequest)); |
91 |
|
g_iorequest->fd = 0; |
92 |
if (iorq->fd == 0) |
g_iorequest->next = NULL; |
93 |
{ |
} |
94 |
iorq->device = device; |
|
95 |
iorq->fd = file; |
iorq = g_iorequest; |
96 |
iorq->id = id; |
|
97 |
iorq->major = major; |
while (iorq->fd != 0) |
98 |
iorq->length = length; |
{ |
99 |
iorq->fns = fns; |
// create new element if needed |
100 |
iorq->timeout = total_timeout; |
if (iorq->next == NULL) |
101 |
iorq->itv_timeout = interval_timeout; |
{ |
102 |
iorq->buffer = buffer; |
iorq->next = |
103 |
return True; |
(struct async_iorequest *) xmalloc(sizeof(struct async_iorequest)); |
104 |
} |
iorq->next->fd = 0; |
105 |
} |
iorq->next->next = NULL; |
106 |
error("IO request table full. Increase MAX_ASYNC_IO_REQUESTS in rdpdr.c!\n"); |
} |
107 |
return False; |
iorq = iorq->next; |
108 |
|
} |
109 |
|
iorq->device = device; |
110 |
|
iorq->fd = file; |
111 |
|
iorq->id = id; |
112 |
|
iorq->major = major; |
113 |
|
iorq->length = length; |
114 |
|
iorq->partial_len = 0; |
115 |
|
iorq->fns = fns; |
116 |
|
iorq->timeout = total_timeout; |
117 |
|
iorq->itv_timeout = interval_timeout; |
118 |
|
iorq->buffer = buffer; |
119 |
|
return True; |
120 |
} |
} |
121 |
|
|
|
|
|
122 |
void |
void |
123 |
rdpdr_send_connect(void) |
rdpdr_send_connect(void) |
124 |
{ |
{ |
201 |
out_uint32_le(s, i); /* RDP Device ID */ |
out_uint32_le(s, i); /* RDP Device ID */ |
202 |
out_uint8p(s, g_rdpdr_device[i].name, 8); |
out_uint8p(s, g_rdpdr_device[i].name, 8); |
203 |
|
|
204 |
if (g_rdpdr_device[i].device_type == DEVICE_TYPE_PRINTER) |
switch (g_rdpdr_device[i].device_type) |
205 |
{ |
{ |
206 |
printerinfo = (PRINTER *) g_rdpdr_device[i].pdevice_data; |
case DEVICE_TYPE_PRINTER: |
207 |
|
printerinfo = (PRINTER *) g_rdpdr_device[i].pdevice_data; |
208 |
|
|
209 |
driverlen = 2 * strlen(printerinfo->driver) + 2; |
driverlen = 2 * strlen(printerinfo->driver) + 2; |
210 |
printerlen = 2 * strlen(printerinfo->printer) + 2; |
printerlen = 2 * strlen(printerinfo->printer) + 2; |
211 |
bloblen = printerinfo->bloblen; |
bloblen = printerinfo->bloblen; |
212 |
|
|
213 |
out_uint32_le(s, 24 + driverlen + printerlen + bloblen); /* length of extra info */ |
out_uint32_le(s, 24 + driverlen + printerlen + bloblen); /* length of extra info */ |
214 |
out_uint32_le(s, printerinfo->default_printer ? 2 : 0); |
out_uint32_le(s, printerinfo->default_printer ? 2 : 0); |
215 |
out_uint8s(s, 8); /* unknown */ |
out_uint8s(s, 8); /* unknown */ |
216 |
out_uint32_le(s, driverlen); |
out_uint32_le(s, driverlen); |
217 |
out_uint32_le(s, printerlen); |
out_uint32_le(s, printerlen); |
218 |
out_uint32_le(s, bloblen); |
out_uint32_le(s, bloblen); |
219 |
rdp_out_unistr(s, printerinfo->driver, driverlen - 2); |
rdp_out_unistr(s, printerinfo->driver, driverlen - 2); |
220 |
rdp_out_unistr(s, printerinfo->printer, printerlen - 2); |
rdp_out_unistr(s, printerinfo->printer, printerlen - 2); |
221 |
out_uint8a(s, printerinfo->blob, bloblen); |
out_uint8a(s, printerinfo->blob, bloblen); |
222 |
|
|
223 |
xfree(printerinfo->blob); /* Blob is sent twice if reconnecting */ |
xfree(printerinfo->blob); /* Blob is sent twice if reconnecting */ |
224 |
} |
break; |
225 |
else |
default: |
226 |
{ |
out_uint32(s, 0); |
|
out_uint32(s, 0); |
|
227 |
} |
} |
228 |
} |
} |
229 |
#if 0 |
#if 0 |
295 |
buffer = (uint8 *) xmalloc(1024); |
buffer = (uint8 *) xmalloc(1024); |
296 |
buffer[0] = 0; |
buffer[0] = 0; |
297 |
|
|
|
|
|
298 |
switch (g_rdpdr_device[device].device_type) |
switch (g_rdpdr_device[device].device_type) |
299 |
{ |
{ |
300 |
case DEVICE_TYPE_SERIAL: |
case DEVICE_TYPE_SERIAL: |
317 |
case DEVICE_TYPE_DISK: |
case DEVICE_TYPE_DISK: |
318 |
|
|
319 |
fns = &disk_fns; |
fns = &disk_fns; |
320 |
|
/*rw_blocking = False; */ |
321 |
break; |
break; |
322 |
|
|
323 |
case DEVICE_TYPE_SCARD: |
case DEVICE_TYPE_SCARD: |
404 |
|
|
405 |
status = STATUS_CANCELLED; |
status = STATUS_CANCELLED; |
406 |
break; |
break; |
|
|
|
407 |
case IRP_MJ_WRITE: |
case IRP_MJ_WRITE: |
408 |
|
|
409 |
buffer_len = 1; |
buffer_len = 1; |
673 |
{ |
{ |
674 |
if (g_num_devices > 0) |
if (g_num_devices > 0) |
675 |
{ |
{ |
676 |
rdpdr_channel = channel_register("rdpdr", CHANNEL_OPTION_INITIALIZED | CHANNEL_OPTION_COMPRESS_RDP, rdpdr_process); |
rdpdr_channel = |
677 |
|
channel_register("rdpdr", |
678 |
|
CHANNEL_OPTION_INITIALIZED | CHANNEL_OPTION_COMPRESS_RDP, |
679 |
|
rdpdr_process); |
680 |
} |
} |
681 |
|
|
682 |
return (rdpdr_channel != NULL); |
return (rdpdr_channel != NULL); |
686 |
void |
void |
687 |
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) |
688 |
{ |
{ |
|
int i; |
|
689 |
long select_timeout = 0; // Timeout value to be used for select() (in millisecons). |
long select_timeout = 0; // Timeout value to be used for select() (in millisecons). |
690 |
struct async_iorequest *iorq; |
struct async_iorequest *iorq; |
691 |
|
|
692 |
for (i = 0; i < MAX_ASYNC_IO_REQUESTS; i++) |
iorq = g_iorequest; |
693 |
|
while (iorq != NULL) |
694 |
{ |
{ |
695 |
iorq = &g_iorequest[i]; |
if (iorq->fd != 0) |
|
|
|
|
if (iorq->fd != 0) // Found a pending io request |
|
696 |
{ |
{ |
697 |
switch (iorq->major) |
switch (iorq->major) |
698 |
{ |
{ |
715 |
break; |
break; |
716 |
|
|
717 |
case IRP_MJ_WRITE: |
case IRP_MJ_WRITE: |
|
|
|
718 |
FD_SET(iorq->fd, wfds); |
FD_SET(iorq->fd, wfds); |
719 |
break; |
break; |
720 |
|
|
721 |
} |
} |
722 |
*n = MAX(*n, iorq->fd); |
*n = MAX(*n, iorq->fd); |
723 |
} |
} |
724 |
|
|
725 |
|
iorq = iorq->next; |
726 |
} |
} |
727 |
} |
} |
728 |
|
|
729 |
|
|
730 |
/* 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 */ |
731 |
void |
void |
732 |
rdpdr_check_fds(fd_set * rfds, fd_set * wfds, BOOL timed_out) |
rdpdr_check_fds(fd_set * rfds, fd_set * wfds, BOOL timed_out) |
733 |
{ |
{ |
|
int i; |
|
734 |
NTSTATUS status; |
NTSTATUS status; |
735 |
uint32 result = 0, buffer_len = 0; |
uint32 result = 0; |
736 |
DEVICE_FNS *fns; |
DEVICE_FNS *fns; |
737 |
struct async_iorequest *iorq; |
struct async_iorequest *iorq; |
738 |
|
struct async_iorequest *prev; |
739 |
|
|
740 |
if (timed_out) |
if (timed_out) |
741 |
{ |
{ |
743 |
return; |
return; |
744 |
} |
} |
745 |
|
|
746 |
// Walk through array of pending io_rq's |
iorq = g_iorequest; |
747 |
for (i = 0; i < MAX_ASYNC_IO_REQUESTS; i++) |
prev = NULL; |
748 |
|
while (iorq != NULL) |
749 |
{ |
{ |
|
iorq = &g_iorequest[i]; |
|
750 |
|
|
751 |
if (iorq->fd != 0) |
if (iorq->fd != 0) |
752 |
{ |
{ |
753 |
switch (iorq->major) |
switch (iorq->major) |
754 |
{ |
{ |
|
|
|
755 |
case IRP_MJ_READ: |
case IRP_MJ_READ: |
|
|
|
756 |
if (FD_ISSET(iorq->fd, rfds)) |
if (FD_ISSET(iorq->fd, rfds)) |
757 |
{ |
{ |
758 |
// Read, and send data. |
/* Read the data */ |
759 |
fns = iorq->fns; |
fns = iorq->fns; |
760 |
status = fns->read(iorq->fd, iorq->buffer, |
|
761 |
iorq->length, 0, &result); |
/* never read larger chunks than 8k - chances are that it will block */ |
762 |
buffer_len = result; |
status = fns->read(iorq->fd, |
763 |
|
iorq->buffer + iorq->partial_len, |
764 |
rdpdr_send_completion(iorq->device, iorq->id, |
(iorq->length - |
765 |
status, result, iorq->buffer, |
iorq->partial_len) > |
766 |
buffer_len); |
8192 ? 8192 : (iorq->length - |
767 |
|
iorq-> |
768 |
|
partial_len), 0, |
769 |
|
&result); |
770 |
|
iorq->partial_len += result; |
771 |
#if WITH_DEBUG_RDP5 |
#if WITH_DEBUG_RDP5 |
772 |
DEBUG(("RDPDR: %d bytes of data read\n", result)); |
DEBUG(("RDPDR: %d bytes of data read\n", result)); |
773 |
#endif |
#endif |
774 |
xfree(iorq->buffer); |
/* only delete link if all data has been transfered */ |
775 |
iorq->fd = 0; |
if (iorq->partial_len == iorq->length) |
776 |
|
{ |
777 |
|
/* send the data */ |
778 |
|
status = STATUS_SUCCESS; |
779 |
|
rdpdr_send_completion(iorq->device, |
780 |
|
iorq->id, status, |
781 |
|
iorq->length, |
782 |
|
iorq->buffer, result); |
783 |
|
|
784 |
|
xfree(iorq->buffer); |
785 |
|
iorq->fd = 0; |
786 |
|
if (prev != NULL) |
787 |
|
{ |
788 |
|
prev->next = iorq->next; |
789 |
|
xfree(iorq); |
790 |
|
} |
791 |
|
else |
792 |
|
{ |
793 |
|
// Even if NULL |
794 |
|
g_iorequest = iorq->next; |
795 |
|
xfree(iorq); |
796 |
|
} |
797 |
|
} |
798 |
} |
} |
799 |
break; |
break; |
|
|
|
800 |
case IRP_MJ_WRITE: |
case IRP_MJ_WRITE: |
|
|
|
801 |
if (FD_ISSET(iorq->fd, wfds)) |
if (FD_ISSET(iorq->fd, wfds)) |
802 |
{ |
{ |
803 |
// Write data and send completion. |
/* Write data. */ |
804 |
fns = iorq->fns; |
fns = iorq->fns; |
|
status = fns->write(iorq->fd, iorq->buffer, |
|
|
iorq->length, 0, &result); |
|
|
rdpdr_send_completion(iorq->device, iorq->id, |
|
|
status, result, "", 1); |
|
805 |
|
|
806 |
xfree(iorq->buffer); |
/* never write larger chunks than 8k - chances are that it will block */ |
807 |
iorq->fd = 0; |
status = fns->write(iorq->fd, |
808 |
|
iorq->buffer + |
809 |
|
iorq->partial_len, |
810 |
|
(iorq->length - |
811 |
|
iorq->partial_len) > |
812 |
|
8192 ? 8192 : (iorq->length - |
813 |
|
iorq-> |
814 |
|
partial_len), 0, |
815 |
|
&result); |
816 |
|
iorq->partial_len += result; |
817 |
|
#if WITH_DEBUG_RDP5 |
818 |
|
DEBUG(("RDPDR: %d bytes of data written\n", |
819 |
|
result)); |
820 |
|
#endif |
821 |
|
/* only delete link if all data has been transfered */ |
822 |
|
if (iorq->partial_len == iorq->length) |
823 |
|
{ |
824 |
|
/* send a status success */ |
825 |
|
status = STATUS_SUCCESS; |
826 |
|
rdpdr_send_completion(iorq->device, |
827 |
|
iorq->id, status, |
828 |
|
iorq->length, "", 1); |
829 |
|
|
830 |
|
xfree(iorq->buffer); |
831 |
|
iorq->fd = 0; |
832 |
|
if (prev != NULL) |
833 |
|
{ |
834 |
|
prev->next = iorq->next; |
835 |
|
xfree(iorq); |
836 |
|
} |
837 |
|
else |
838 |
|
{ |
839 |
|
// Even if NULL |
840 |
|
g_iorequest = iorq->next; |
841 |
|
xfree(iorq); |
842 |
|
} |
843 |
|
} |
844 |
} |
} |
845 |
break; |
break; |
846 |
} |
} |
847 |
|
|
848 |
} |
} |
849 |
|
prev = iorq; |
850 |
|
iorq = iorq->next; |
851 |
} |
} |
852 |
|
|
853 |
} |
} |
854 |
|
|
855 |
/* Abort a pending io request for a given handle and major */ |
/* Abort a pending io request for a given handle and major */ |
857 |
rdpdr_abort_io(uint32 fd, uint32 major, NTSTATUS status) |
rdpdr_abort_io(uint32 fd, uint32 major, NTSTATUS status) |
858 |
{ |
{ |
859 |
uint32 result; |
uint32 result; |
|
int i; |
|
860 |
struct async_iorequest *iorq; |
struct async_iorequest *iorq; |
861 |
|
struct async_iorequest *prev; |
862 |
|
|
863 |
for (i = 0; i < MAX_ASYNC_IO_REQUESTS; i++) |
iorq = &g_iorequest; |
864 |
|
prev = NULL; |
865 |
|
while (iorq != NULL) |
866 |
{ |
{ |
|
iorq = &g_iorequest[i]; |
|
|
|
|
867 |
// Only remove from table when major is not set, or when correct major is supplied. |
// Only remove from table when major is not set, or when correct major is supplied. |
868 |
// Abort read should not abort a write io request. |
// Abort read should not abort a write io request. |
869 |
if ((iorq->fd == fd) && (major == 0 || iorq->major == major)) |
if ((iorq->fd == fd) && (major == 0 || iorq->major == major)) |
872 |
rdpdr_send_completion(iorq->device, iorq->id, status, result, "", 1); |
rdpdr_send_completion(iorq->device, iorq->id, status, result, "", 1); |
873 |
xfree(iorq->buffer); |
xfree(iorq->buffer); |
874 |
iorq->fd = 0; |
iorq->fd = 0; |
875 |
|
if (prev != NULL) |
876 |
|
{ |
877 |
|
prev->next = iorq->next; |
878 |
|
xfree(iorq); |
879 |
|
} |
880 |
|
else |
881 |
|
{ |
882 |
|
// Even if NULL |
883 |
|
g_iorequest = iorq->next; |
884 |
|
xfree(iorq); |
885 |
|
} |
886 |
return True; |
return True; |
887 |
} |
} |
888 |
|
|
889 |
|
prev = iorq; |
890 |
|
iorq = iorq->next; |
891 |
} |
} |
892 |
|
|
893 |
return False; |
return False; |
894 |
} |
} |