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> |
#include <sys/time.h> |
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 |
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, */ |
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 |
} |
} |
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; |
809 |
{ |
{ |
810 |
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). |
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 |
{ |
{ |