Skip to content

Commit

Permalink
Fix problems with transferring large files
Browse files Browse the repository at this point in the history
The entire device redirection framework is documented to use 64-bit
offsets rather than 32-bit offsets. This should fix any problems
transfering large files with rdesktop.

Co-Authored-By: gpatel-fr <[email protected]>
  • Loading branch information
derfian and gpatel-fr committed Jan 31, 2019
1 parent 4e6787c commit 5351182
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 30 deletions.
4 changes: 2 additions & 2 deletions disk.c
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,7 @@ disk_close(RD_NTHANDLE handle)
}

static RD_NTSTATUS
disk_read(RD_NTHANDLE handle, uint8 * data, uint32 length, uint32 offset, uint32 * result)
disk_read(RD_NTHANDLE handle, uint8 * data, uint32 length, uint64 offset, uint32 * result)
{
int n;

Expand Down Expand Up @@ -623,7 +623,7 @@ disk_read(RD_NTHANDLE handle, uint8 * data, uint32 length, uint32 offset, uint32
}

static RD_NTSTATUS
disk_write(RD_NTHANDLE handle, uint8 * data, uint32 length, uint32 offset, uint32 * result)
disk_write(RD_NTHANDLE handle, uint8 * data, uint32 length, uint64 offset, uint32 * result)
{
int n;

Expand Down
8 changes: 4 additions & 4 deletions parallel.c
Original file line number Diff line number Diff line change
Expand Up @@ -119,17 +119,17 @@ parallel_close(RD_NTHANDLE handle)
}

static RD_NTSTATUS
parallel_read(RD_NTHANDLE handle, uint8 * data, uint32 length, uint32 offset, uint32 * result)
parallel_read(RD_NTHANDLE handle, uint8 * data, uint32 length, uint64 offset, uint32 * result)
{
UNUSED(offset);
UNUSED(offset); /* Offset must always be zero according to MS-RDPESP */
*result = read(handle, data, length);
return RD_STATUS_SUCCESS;
}

static RD_NTSTATUS
parallel_write(RD_NTHANDLE handle, uint8 * data, uint32 length, uint32 offset, uint32 * result)
parallel_write(RD_NTHANDLE handle, uint8 * data, uint32 length, uint64 offset, uint32 * result)
{
UNUSED(offset);
UNUSED(offset); /* Offset must always be zero according to MS-RDPESP */
int rc = RD_STATUS_SUCCESS;

int n = write(handle, data, length);
Expand Down
4 changes: 2 additions & 2 deletions printer.c
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,9 @@ printer_close(RD_NTHANDLE handle)
}

static RD_NTSTATUS
printer_write(RD_NTHANDLE handle, uint8 * data, uint32 length, uint32 offset, uint32 * result)
printer_write(RD_NTHANDLE handle, uint8 * data, uint32 length, uint64 offset, uint32 * result)
{
UNUSED(offset);
UNUSED(offset); /* Currently unused, MS-RDPEPC reserves for later use */
PRINTER *pprinter_data;

pprinter_data = get_printer_data(handle);
Expand Down
30 changes: 18 additions & 12 deletions rdpdr.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Copyright (C) Matthew Chapman <matthewc.unsw.edu.au> 1999-2008
Copyright 2004-2011 Peter Astrand <[email protected]> for Cendio AB
Copyright 2010-2017 Henrik Andersson <[email protected]> for Cendio AB
Copyright 2017 Karl Mikaelsson <[email protected]> for Cendio AB
Copyright 2017-2019 Karl Mikaelsson <[email protected]> for Cendio AB
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
Expand Down Expand Up @@ -86,7 +86,8 @@ char *g_rdpdr_clientname = NULL;
/* if multiple IOs are being done on the same FD */
struct async_iorequest
{
uint32 fd, major, minor, offset, device, id, length, partial_len;
uint32 fd, major, minor, device, id, length, partial_len;
uint64 offset;
long timeout, /* Total timeout */
itv_timeout; /* Interval timeout (between serial characters) */
uint8 *buffer;
Expand Down Expand Up @@ -146,7 +147,7 @@ rdpdr_handle_ok(uint32 device, RD_NTHANDLE handle)
static RD_BOOL
add_async_iorequest(uint32 device, uint32 file, uint32 id, uint32 major, uint32 length,
DEVICE_FNS * fns, uint32 total_timeout, uint32 interval_timeout, uint8 * buffer,
uint32 offset)
uint64 offset)
{
struct async_iorequest *iorq;

Expand Down Expand Up @@ -395,6 +396,7 @@ rdpdr_send_completion(uint32 device, uint32 id, uint32 status, uint32 result, ui
#endif
}

/* Processes a DR_DEVICE_IOREQUEST (minus the leading header field) */
static void
rdpdr_process_irp(STREAM s)
{
Expand All @@ -409,10 +411,11 @@ rdpdr_process_irp(STREAM s)
major,
minor,
device,
offset,
bytes_out,
share_mode, disposition, total_timeout, interval_timeout, flags_and_attributes = 0;

uint64 offset;

char *filename;
uint32 filename_len;

Expand Down Expand Up @@ -534,11 +537,12 @@ rdpdr_process_irp(STREAM s)
}

in_uint32_le(s, length);
in_uint32_le(s, offset);
in_uint64_le(s, offset);
in_uint8s(s, 20); /* 20 bytes of padding */

logger(Protocol, Debug,
"rdpdr_process_irp(), IRP Read length=%d, offset=%d", length,
offset);
"rdpdr_process_irp(), IRP Read length=%d, offset=%ld",
length, offset);

if (!rdpdr_handle_ok(device, file))
{
Expand Down Expand Up @@ -588,10 +592,12 @@ rdpdr_process_irp(STREAM s)
}

in_uint32_le(s, length);
in_uint32_le(s, offset);
in_uint8s(s, 0x18);
in_uint64_le(s, offset);
in_uint8s(s, 20); /* 20 bytes of padding before WriteData */

logger(Protocol, Debug, "rdpdr_process_irp(), IRP Write length=%d", result);
logger(Protocol, Debug,
"rdpdr_process_irp(), IRP Write length=%d, offset=%ld",
result, offset);

if (!rdpdr_handle_ok(device, file))
{
Expand Down Expand Up @@ -875,8 +881,8 @@ rdpdr_process(STREAM s)
logger(Protocol, Debug, "rdpdr_process()");
/* hexdump(s->p, s->end - s->p); */

in_uint16(s, component);
in_uint16(s, pakid);
in_uint16(s, component); /* RDPDR_HEADER.Component */
in_uint16(s, pakid); /* RDPDR_HEADER.PacketId */

if (component == RDPDR_CTYP_CORE)
{
Expand Down
4 changes: 2 additions & 2 deletions scard.c
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ scard_close(RD_NTHANDLE handle)
}

static RD_NTSTATUS
scard_read(RD_NTHANDLE handle, uint8 * data, uint32 length, uint32 offset, uint32 * result)
scard_read(RD_NTHANDLE handle, uint8 * data, uint32 length, uint64 offset, uint32 * result)
{
UNUSED(handle);
UNUSED(data);
Expand All @@ -131,7 +131,7 @@ scard_read(RD_NTHANDLE handle, uint8 * data, uint32 length, uint32 offset, uint3
}

static RD_NTSTATUS
scard_write(RD_NTHANDLE handle, uint8 * data, uint32 length, uint32 offset, uint32 * result)
scard_write(RD_NTHANDLE handle, uint8 * data, uint32 length, uint64 offset, uint32 * result)
{
UNUSED(handle);
UNUSED(data);
Expand Down
10 changes: 4 additions & 6 deletions serial.c
Original file line number Diff line number Diff line change
Expand Up @@ -628,9 +628,9 @@ serial_close(RD_NTHANDLE handle)
}

static RD_NTSTATUS
serial_read(RD_NTHANDLE handle, uint8 * data, uint32 length, uint32 offset, uint32 * result)
serial_read(RD_NTHANDLE handle, uint8 * data, uint32 length, uint64 offset, uint32 * result)
{
UNUSED(offset);
UNUSED(offset); /* Offset must always be zero according to MS-RDPESP */
long timeout;
SERIAL_DEVICE *pser_inf;
struct termios *ptermios;
Expand Down Expand Up @@ -684,13 +684,11 @@ serial_read(RD_NTHANDLE handle, uint8 * data, uint32 length, uint32 offset, uint
}

static RD_NTSTATUS
serial_write(RD_NTHANDLE handle, uint8 * data, uint32 length, uint32 offset, uint32 * result)
serial_write(RD_NTHANDLE handle, uint8 * data, uint32 length, uint64 offset, uint32 * result)
{
UNUSED(offset);
UNUSED(offset); /* Offset must always be zero according to MS-RDPESP */
SERIAL_DEVICE *pser_inf;

/* FIXME: offset is not used ? */

pser_inf = get_serial_info(handle);

*result = write(handle, data, length);
Expand Down
4 changes: 2 additions & 2 deletions types.h
Original file line number Diff line number Diff line change
Expand Up @@ -219,9 +219,9 @@ typedef struct _DEVICE_FNS
uint32 create_disposition, uint32 flags_and_attributes,
char *filename, RD_NTHANDLE * handle);
RD_NTSTATUS(*close) (RD_NTHANDLE handle);
RD_NTSTATUS(*read) (RD_NTHANDLE handle, uint8 * data, uint32 length, uint32 offset,
RD_NTSTATUS(*read) (RD_NTHANDLE handle, uint8 * data, uint32 length, uint64 offset,
uint32 * result);
RD_NTSTATUS(*write) (RD_NTHANDLE handle, uint8 * data, uint32 length, uint32 offset,
RD_NTSTATUS(*write) (RD_NTHANDLE handle, uint8 * data, uint32 length, uint64 offset,
uint32 * result);
RD_NTSTATUS(*device_control) (RD_NTHANDLE handle, uint32 request, STREAM in, STREAM out);
}
Expand Down

0 comments on commit 5351182

Please sign in to comment.