2012-07-25 06:16:00 +04:00
|
|
|
/**
|
|
|
|
* xrdp: A Remote Desktop Protocol server.
|
|
|
|
*
|
2013-03-09 03:37:30 +04:00
|
|
|
* xrdp device redirection - only drive redirection is currently supported
|
|
|
|
*
|
2013-03-24 23:08:55 +04:00
|
|
|
* Copyright (C) Laxmikant Rashinkar 2013 LK.Rashinkar@gmail.com
|
2012-07-25 06:16:00 +04:00
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
2009-04-22 08:34:45 +04:00
|
|
|
|
2013-03-09 03:37:30 +04:00
|
|
|
/*
|
|
|
|
* TODO
|
|
|
|
* o there is one difference in the protocol initialization
|
|
|
|
* sequence upon reconnection: if a user is already logged on,
|
|
|
|
* send a SERVER_USER_LOGGED_ON msg as per section 3.3.5.1.5
|
|
|
|
*
|
|
|
|
* o how to announce / delete a drive after a connection has been
|
|
|
|
* established?
|
|
|
|
*
|
|
|
|
* o need to support multiple drives;
|
|
|
|
* o for multiple drives, we cannot have global device_id's and file_id's
|
|
|
|
* and all functions must be reenterant
|
|
|
|
* o replace printf's with log_xxx
|
|
|
|
* o mark local funcs with static
|
|
|
|
*/
|
|
|
|
|
2017-03-03 07:33:23 +03:00
|
|
|
#if defined(HAVE_CONFIG_H)
|
|
|
|
#include <config_ac.h>
|
|
|
|
#endif
|
|
|
|
|
2013-05-16 04:06:05 +04:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "arch.h"
|
|
|
|
#include "parse.h"
|
|
|
|
#include "os_calls.h"
|
|
|
|
#include "log.h"
|
2016-12-09 03:50:36 +03:00
|
|
|
#include "chansrv.h"
|
2013-05-16 04:06:05 +04:00
|
|
|
#include "chansrv_fuse.h"
|
2013-03-09 03:37:30 +04:00
|
|
|
#include "devredir.h"
|
2013-05-16 04:06:05 +04:00
|
|
|
#include "smartcard.h"
|
|
|
|
|
|
|
|
/* module based logging */
|
|
|
|
#define LOG_ERROR 0
|
|
|
|
#define LOG_INFO 1
|
|
|
|
#define LOG_DEBUG 2
|
|
|
|
|
|
|
|
#ifndef LOG_LEVEL
|
2013-05-19 06:44:16 +04:00
|
|
|
#define LOG_LEVEL LOG_ERROR
|
2013-05-16 04:06:05 +04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#define log_error(_params...) \
|
|
|
|
{ \
|
|
|
|
g_write("[%10.10u]: DEV_REDIR %s: %d : ERROR: ", \
|
|
|
|
g_time3(), __func__, __LINE__); \
|
|
|
|
g_writeln (_params); \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define log_info(_params...) \
|
|
|
|
{ \
|
2013-09-25 04:19:10 +04:00
|
|
|
if (LOG_INFO <= LOG_LEVEL) \
|
2013-05-16 04:06:05 +04:00
|
|
|
{ \
|
|
|
|
g_write("[%10.10u]: DEV_REDIR %s: %d : ", \
|
|
|
|
g_time3(), __func__, __LINE__); \
|
|
|
|
g_writeln (_params); \
|
|
|
|
} \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define log_debug(_params...) \
|
|
|
|
{ \
|
2013-09-25 04:19:10 +04:00
|
|
|
if (LOG_DEBUG <= LOG_LEVEL) \
|
2013-05-16 04:06:05 +04:00
|
|
|
{ \
|
|
|
|
g_write("[%10.10u]: DEV_REDIR %s: %d : ", \
|
|
|
|
g_time3(), __func__, __LINE__); \
|
|
|
|
g_writeln (_params); \
|
|
|
|
} \
|
|
|
|
}
|
2009-04-22 08:34:45 +04:00
|
|
|
|
2019-03-21 19:48:01 +03:00
|
|
|
/*
|
|
|
|
* Size of structs supported by IRP_MJ_QUERY_INFORMATION without
|
|
|
|
* trailing RESERVED fields (MS-RDPEFS 2.2.3.3.8)
|
|
|
|
*/
|
|
|
|
#define FILE_BASIC_INFORMATION_SIZE 36
|
|
|
|
#define FILE_STD_INFORMATION_SIZE 22
|
|
|
|
|
2013-03-09 03:37:30 +04:00
|
|
|
/* globals */
|
2009-04-22 08:34:45 +04:00
|
|
|
extern int g_rdpdr_chan_id; /* in chansrv.c */
|
2013-03-09 03:37:30 +04:00
|
|
|
int g_is_printer_redir_supported = 0;
|
|
|
|
int g_is_port_redir_supported = 0;
|
|
|
|
int g_is_drive_redir_supported = 0;
|
|
|
|
int g_is_smartcard_redir_supported = 0;
|
|
|
|
int g_drive_redir_version = 1;
|
|
|
|
char g_full_name_for_filesystem[1024];
|
|
|
|
tui32 g_completion_id = 1;
|
|
|
|
|
|
|
|
tui32 g_clientID; /* unique client ID - announced by client */
|
|
|
|
tui32 g_device_id; /* unique device ID - announced by client */
|
|
|
|
tui16 g_client_rdp_version; /* returned by client */
|
|
|
|
struct stream *g_input_stream = NULL;
|
|
|
|
|
2019-03-12 15:16:50 +03:00
|
|
|
/*
|
|
|
|
* Local functions called from dev_redir_proc_device_iocompletion()
|
|
|
|
*/
|
|
|
|
static void devredir_proc_cid_rmdir_or_file(IRP *irp, tui32 IoStatus);
|
|
|
|
static void devredir_proc_cid_rmdir_or_file_resp(IRP *irp, tui32 IoStatus);
|
|
|
|
static void devredir_proc_cid_rename_file(IRP *irp, tui32 IoStatus);
|
|
|
|
static void devredir_proc_cid_rename_file_resp(IRP *irp, tui32 IoStatus);
|
2019-03-21 19:48:01 +03:00
|
|
|
static void devredir_proc_cid_lookup_basic_entry(IRP *irp, tui32 IoStatus);
|
|
|
|
static void devredir_proc_cid_lookup_basic_entry_resp(
|
|
|
|
IRP *irp,
|
|
|
|
struct stream *s_in,
|
|
|
|
tui32 IoStatus);
|
|
|
|
static void devredir_proc_cid_lookup_std_entry_resp(
|
|
|
|
IRP *irp,
|
|
|
|
struct stream *s_in,
|
|
|
|
tui32 DeviceId,
|
|
|
|
tui32 CompletionId,
|
|
|
|
tui32 IoStatus);
|
|
|
|
/* Other local functions */
|
|
|
|
static void lookup_std_entry(IRP *irp);
|
2009-04-22 08:34:45 +04:00
|
|
|
|
|
|
|
/*****************************************************************************/
|
2017-03-12 19:35:00 +03:00
|
|
|
int
|
2009-04-22 08:34:45 +04:00
|
|
|
dev_redir_init(void)
|
|
|
|
{
|
2013-03-09 03:37:30 +04:00
|
|
|
struct stream *s;
|
|
|
|
int bytes;
|
|
|
|
int fd;
|
|
|
|
|
|
|
|
union _u
|
|
|
|
{
|
|
|
|
tui32 clientID;
|
|
|
|
char buf[4];
|
|
|
|
} u;
|
|
|
|
|
|
|
|
/* get a random number that will act as a unique clientID */
|
2014-07-24 06:07:38 +04:00
|
|
|
if ((fd = open("/dev/urandom", O_RDONLY)) != -1)
|
2013-03-09 03:37:30 +04:00
|
|
|
{
|
2013-08-05 12:10:57 +04:00
|
|
|
if (read(fd, u.buf, 4) != 4)
|
|
|
|
{
|
|
|
|
}
|
2013-03-09 03:37:30 +04:00
|
|
|
close(fd);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* /dev/urandom did not work - use address of struct s */
|
2013-08-05 12:10:57 +04:00
|
|
|
tui64 u64 = (tui64) (tintptr) &s;
|
2013-03-09 03:37:30 +04:00
|
|
|
u.clientID = (tui32) u64;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* setup stream */
|
2013-05-03 13:25:13 +04:00
|
|
|
xstream_new(s, 1024);
|
2013-03-09 03:37:30 +04:00
|
|
|
|
|
|
|
/* initiate drive redirection protocol by sending Server Announce Req */
|
2013-05-03 13:25:13 +04:00
|
|
|
xstream_wr_u16_le(s, RDPDR_CTYP_CORE);
|
|
|
|
xstream_wr_u16_le(s, PAKID_CORE_SERVER_ANNOUNCE);
|
|
|
|
xstream_wr_u16_le(s, 0x0001); /* server major ver */
|
|
|
|
xstream_wr_u16_le(s, 0x000C); /* server minor ver - pretend 2 b Win 7 */
|
|
|
|
xstream_wr_u32_le(s, u.clientID); /* unique ClientID */
|
2013-03-09 03:37:30 +04:00
|
|
|
|
|
|
|
/* send data to client */
|
2013-05-03 13:25:13 +04:00
|
|
|
bytes = xstream_len(s);
|
2013-03-09 03:37:30 +04:00
|
|
|
send_channel_data(g_rdpdr_chan_id, s->data, bytes);
|
|
|
|
|
2013-05-03 13:25:13 +04:00
|
|
|
xstream_free(s);
|
2012-09-20 07:51:34 +04:00
|
|
|
return 0;
|
2009-04-22 08:34:45 +04:00
|
|
|
}
|
|
|
|
|
2009-08-15 06:47:51 +04:00
|
|
|
/*****************************************************************************/
|
2017-03-12 19:35:00 +03:00
|
|
|
int
|
2009-08-15 06:47:51 +04:00
|
|
|
dev_redir_deinit(void)
|
|
|
|
{
|
2013-08-05 12:10:57 +04:00
|
|
|
scard_deinit();
|
2012-09-20 07:51:34 +04:00
|
|
|
return 0;
|
2009-08-15 06:47:51 +04:00
|
|
|
}
|
|
|
|
|
2013-03-09 03:37:30 +04:00
|
|
|
/**
|
|
|
|
* @brief process incoming data
|
|
|
|
*
|
|
|
|
* @return 0 on success, -1 on failure
|
|
|
|
*****************************************************************************/
|
|
|
|
|
2017-03-12 19:35:00 +03:00
|
|
|
int
|
2012-09-20 07:51:34 +04:00
|
|
|
dev_redir_data_in(struct stream *s, int chan_id, int chan_flags, int length,
|
2009-04-22 08:34:45 +04:00
|
|
|
int total_length)
|
|
|
|
{
|
2013-03-09 03:37:30 +04:00
|
|
|
struct stream *ls;
|
|
|
|
tui16 comp_type;
|
|
|
|
tui16 pktID;
|
|
|
|
tui16 minor_ver;
|
|
|
|
int rv = 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* handle packet fragmentation
|
|
|
|
*/
|
|
|
|
if ((chan_flags & 3) == 3)
|
|
|
|
{
|
|
|
|
/* all data contained in one packet */
|
|
|
|
ls = s;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* is this is the first packet? */
|
|
|
|
if (chan_flags & 1)
|
2013-05-03 13:25:13 +04:00
|
|
|
xstream_new(g_input_stream, total_length);
|
2013-03-09 03:37:30 +04:00
|
|
|
|
2013-05-03 13:25:13 +04:00
|
|
|
xstream_copyin(g_input_stream, s->p, length);
|
2013-03-09 03:37:30 +04:00
|
|
|
|
|
|
|
/* in last packet, chan_flags & 0x02 will be true */
|
|
|
|
if ((chan_flags & 2) == 0)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
g_input_stream->p = g_input_stream->data;
|
|
|
|
ls = g_input_stream;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* read header from incoming data */
|
2013-05-03 13:25:13 +04:00
|
|
|
xstream_rd_u16_le(ls, comp_type);
|
|
|
|
xstream_rd_u16_le(ls, pktID);
|
2013-03-09 03:37:30 +04:00
|
|
|
|
|
|
|
/* for now we only handle core type, not printers */
|
|
|
|
if (comp_type != RDPDR_CTYP_CORE)
|
|
|
|
{
|
|
|
|
log_error("invalid component type in response; expected 0x%x got 0x%x",
|
|
|
|
RDPDR_CTYP_CORE, comp_type);
|
|
|
|
|
|
|
|
rv = -1;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* figure out what kind of response we have gotten */
|
|
|
|
switch (pktID)
|
|
|
|
{
|
|
|
|
case PAKID_CORE_CLIENTID_CONFIRM:
|
2013-05-03 13:25:13 +04:00
|
|
|
xstream_seek(ls, 2); /* major version, we ignore it */
|
|
|
|
xstream_rd_u16_le(ls, minor_ver);
|
|
|
|
xstream_rd_u32_le(ls, g_clientID);
|
2013-03-09 03:37:30 +04:00
|
|
|
|
|
|
|
g_client_rdp_version = minor_ver;
|
|
|
|
|
|
|
|
switch (minor_ver)
|
|
|
|
{
|
|
|
|
case RDP_CLIENT_50:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case RDP_CLIENT_51:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case RDP_CLIENT_52:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case RDP_CLIENT_60_61:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
// LK_TODO dev_redir_send_server_clientID_confirm();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PAKID_CORE_CLIENT_NAME:
|
|
|
|
/* client is telling us its computer name; do we even care? */
|
|
|
|
|
2016-02-14 07:41:07 +03:00
|
|
|
/* let client know login was successful */
|
2013-03-09 03:37:30 +04:00
|
|
|
dev_redir_send_server_user_logged_on();
|
|
|
|
usleep(1000 * 100);
|
|
|
|
|
2016-02-14 07:41:07 +03:00
|
|
|
/* let client know our capabilities */
|
2013-03-09 03:37:30 +04:00
|
|
|
dev_redir_send_server_core_cap_req();
|
|
|
|
|
|
|
|
/* send confirm clientID */
|
|
|
|
dev_redir_send_server_clientID_confirm();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PAKID_CORE_CLIENT_CAPABILITY:
|
|
|
|
dev_redir_proc_client_core_cap_resp(ls);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PAKID_CORE_DEVICELIST_ANNOUNCE:
|
2013-05-16 04:06:05 +04:00
|
|
|
devredir_proc_client_devlist_announce_req(ls);
|
2013-03-09 03:37:30 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case PAKID_CORE_DEVICE_IOCOMPLETION:
|
|
|
|
dev_redir_proc_device_iocompletion(ls);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
log_error("got unknown response 0x%x", pktID);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
done:
|
|
|
|
|
|
|
|
if (g_input_stream)
|
|
|
|
{
|
2013-05-03 13:25:13 +04:00
|
|
|
xstream_free(g_input_stream);
|
2013-03-09 03:37:30 +04:00
|
|
|
g_input_stream = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
2009-04-22 08:34:45 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2017-03-12 19:35:00 +03:00
|
|
|
int
|
2012-09-20 07:51:34 +04:00
|
|
|
dev_redir_get_wait_objs(tbus *objs, int *count, int *timeout)
|
2009-04-22 08:34:45 +04:00
|
|
|
{
|
2013-08-05 12:10:57 +04:00
|
|
|
if (g_is_smartcard_redir_supported)
|
|
|
|
{
|
|
|
|
return scard_get_wait_objs(objs, count, timeout);
|
|
|
|
}
|
2012-09-20 07:51:34 +04:00
|
|
|
return 0;
|
2009-04-22 08:34:45 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2017-03-12 19:35:00 +03:00
|
|
|
int
|
2009-04-22 08:34:45 +04:00
|
|
|
dev_redir_check_wait_objs(void)
|
|
|
|
{
|
2013-08-05 12:10:57 +04:00
|
|
|
if (g_is_smartcard_redir_supported)
|
|
|
|
{
|
|
|
|
return scard_check_wait_objs();
|
|
|
|
}
|
2012-09-20 07:51:34 +04:00
|
|
|
return 0;
|
2009-04-22 08:34:45 +04:00
|
|
|
}
|
2013-03-09 03:37:30 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief let client know our capabilities
|
|
|
|
*****************************************************************************/
|
|
|
|
|
2013-07-02 11:45:40 +04:00
|
|
|
void dev_redir_send_server_core_cap_req(void)
|
2013-03-09 03:37:30 +04:00
|
|
|
{
|
|
|
|
struct stream *s;
|
|
|
|
int bytes;
|
|
|
|
|
2013-05-03 13:25:13 +04:00
|
|
|
xstream_new(s, 1024);
|
2013-03-09 03:37:30 +04:00
|
|
|
|
|
|
|
/* setup header */
|
2013-05-03 13:25:13 +04:00
|
|
|
xstream_wr_u16_le(s, RDPDR_CTYP_CORE);
|
|
|
|
xstream_wr_u16_le(s, PAKID_CORE_SERVER_CAPABILITY);
|
2013-03-09 03:37:30 +04:00
|
|
|
|
2013-05-03 13:25:13 +04:00
|
|
|
xstream_wr_u16_le(s, 5); /* num of caps we are sending */
|
|
|
|
xstream_wr_u16_le(s, 0x0000); /* padding */
|
2013-03-09 03:37:30 +04:00
|
|
|
|
|
|
|
/* setup general capability */
|
2013-05-03 13:25:13 +04:00
|
|
|
xstream_wr_u16_le(s, CAP_GENERAL_TYPE); /* CapabilityType */
|
|
|
|
xstream_wr_u16_le(s, 44); /* CapabilityLength - len of this */
|
|
|
|
/* CAPABILITY_SET in bytes, inc */
|
|
|
|
/* the header */
|
|
|
|
xstream_wr_u32_le(s, 2); /* Version */
|
|
|
|
xstream_wr_u32_le(s, 2); /* O.S type */
|
|
|
|
xstream_wr_u32_le(s, 0); /* O.S version */
|
|
|
|
xstream_wr_u16_le(s, 1); /* protocol major version */
|
|
|
|
xstream_wr_u16_le(s, g_client_rdp_version); /* protocol minor version */
|
|
|
|
xstream_wr_u32_le(s, 0xffff); /* I/O code 1 */
|
|
|
|
xstream_wr_u32_le(s, 0); /* I/O code 2 */
|
|
|
|
xstream_wr_u32_le(s, 7); /* Extended PDU */
|
|
|
|
xstream_wr_u32_le(s, 0); /* extra flags 1 */
|
|
|
|
xstream_wr_u32_le(s, 0); /* extra flags 2 */
|
|
|
|
xstream_wr_u32_le(s, 2); /* special type device cap */
|
2013-03-09 03:37:30 +04:00
|
|
|
|
|
|
|
/* setup printer capability */
|
2013-05-03 13:25:13 +04:00
|
|
|
xstream_wr_u16_le(s, CAP_PRINTER_TYPE);
|
|
|
|
xstream_wr_u16_le(s, 8);
|
|
|
|
xstream_wr_u32_le(s, 1);
|
2013-03-09 03:37:30 +04:00
|
|
|
|
|
|
|
/* setup serial port capability */
|
2013-05-03 13:25:13 +04:00
|
|
|
xstream_wr_u16_le(s, CAP_PORT_TYPE);
|
|
|
|
xstream_wr_u16_le(s, 8);
|
|
|
|
xstream_wr_u32_le(s, 1);
|
2013-03-09 03:37:30 +04:00
|
|
|
|
|
|
|
/* setup file system capability */
|
2013-05-03 13:25:13 +04:00
|
|
|
xstream_wr_u16_le(s, CAP_DRIVE_TYPE); /* CapabilityType */
|
|
|
|
xstream_wr_u16_le(s, 8); /* CapabilityLength - len of this */
|
2013-07-02 11:45:40 +04:00
|
|
|
/* CAPABILITY_SET in bytes, inc */
|
|
|
|
/* the header */
|
2013-05-03 13:25:13 +04:00
|
|
|
xstream_wr_u32_le(s, 2); /* Version */
|
2013-03-09 03:37:30 +04:00
|
|
|
|
|
|
|
/* setup smart card capability */
|
2013-05-03 13:25:13 +04:00
|
|
|
xstream_wr_u16_le(s, CAP_SMARTCARD_TYPE);
|
|
|
|
xstream_wr_u16_le(s, 8);
|
|
|
|
xstream_wr_u32_le(s, 1);
|
2013-03-09 03:37:30 +04:00
|
|
|
|
|
|
|
/* send to client */
|
2013-05-03 13:25:13 +04:00
|
|
|
bytes = xstream_len(s);
|
2013-03-09 03:37:30 +04:00
|
|
|
send_channel_data(g_rdpdr_chan_id, s->data, bytes);
|
|
|
|
|
2013-05-03 13:25:13 +04:00
|
|
|
xstream_free(s);
|
2013-03-09 03:37:30 +04:00
|
|
|
}
|
|
|
|
|
2013-07-02 11:45:40 +04:00
|
|
|
void dev_redir_send_server_clientID_confirm(void)
|
2013-03-09 03:37:30 +04:00
|
|
|
{
|
|
|
|
struct stream *s;
|
|
|
|
int bytes;
|
|
|
|
|
2013-05-03 13:25:13 +04:00
|
|
|
xstream_new(s, 1024);
|
2013-03-09 03:37:30 +04:00
|
|
|
|
|
|
|
/* setup stream */
|
2013-05-03 13:25:13 +04:00
|
|
|
xstream_wr_u16_le(s, RDPDR_CTYP_CORE);
|
|
|
|
xstream_wr_u16_le(s, PAKID_CORE_CLIENTID_CONFIRM);
|
|
|
|
xstream_wr_u16_le(s, 0x0001);
|
|
|
|
xstream_wr_u16_le(s, g_client_rdp_version);
|
|
|
|
xstream_wr_u32_le(s, g_clientID);
|
2013-03-09 03:37:30 +04:00
|
|
|
|
|
|
|
/* send to client */
|
2013-05-03 13:25:13 +04:00
|
|
|
bytes = xstream_len(s);
|
2013-03-09 03:37:30 +04:00
|
|
|
send_channel_data(g_rdpdr_chan_id, s->data, bytes);
|
|
|
|
|
2013-05-03 13:25:13 +04:00
|
|
|
xstream_free(s);
|
2013-03-09 03:37:30 +04:00
|
|
|
}
|
|
|
|
|
2013-07-02 11:45:40 +04:00
|
|
|
void dev_redir_send_server_user_logged_on(void)
|
2013-03-09 03:37:30 +04:00
|
|
|
{
|
|
|
|
struct stream *s;
|
|
|
|
int bytes;
|
|
|
|
|
2013-05-03 13:25:13 +04:00
|
|
|
xstream_new(s, 1024);
|
2013-03-09 03:37:30 +04:00
|
|
|
|
|
|
|
/* setup stream */
|
2013-05-03 13:25:13 +04:00
|
|
|
xstream_wr_u16_le(s, RDPDR_CTYP_CORE);
|
|
|
|
xstream_wr_u16_le(s, PAKID_CORE_USER_LOGGEDON);
|
2013-03-09 03:37:30 +04:00
|
|
|
|
|
|
|
/* send to client */
|
2013-05-03 13:25:13 +04:00
|
|
|
bytes = xstream_len(s);
|
2013-03-09 03:37:30 +04:00
|
|
|
send_channel_data(g_rdpdr_chan_id, s->data, bytes);
|
|
|
|
|
2013-05-03 13:25:13 +04:00
|
|
|
xstream_free(s);
|
2013-03-09 03:37:30 +04:00
|
|
|
}
|
|
|
|
|
2013-05-16 04:06:05 +04:00
|
|
|
void devredir_send_server_device_announce_resp(tui32 device_id)
|
2013-03-09 03:37:30 +04:00
|
|
|
{
|
|
|
|
struct stream *s;
|
|
|
|
int bytes;
|
|
|
|
|
2013-05-03 13:25:13 +04:00
|
|
|
xstream_new(s, 1024);
|
2013-03-09 03:37:30 +04:00
|
|
|
|
|
|
|
/* setup stream */
|
2013-05-03 13:25:13 +04:00
|
|
|
xstream_wr_u16_le(s, RDPDR_CTYP_CORE);
|
|
|
|
xstream_wr_u16_le(s, PAKID_CORE_DEVICE_REPLY);
|
|
|
|
xstream_wr_u32_le(s, device_id);
|
|
|
|
xstream_wr_u32_le(s, 0); /* ResultCode */
|
2013-03-09 03:37:30 +04:00
|
|
|
|
|
|
|
/* send to client */
|
2013-05-03 13:25:13 +04:00
|
|
|
bytes = xstream_len(s);
|
2013-03-09 03:37:30 +04:00
|
|
|
send_channel_data(g_rdpdr_chan_id, s->data, bytes);
|
|
|
|
|
2013-05-03 13:25:13 +04:00
|
|
|
xstream_free(s);
|
2013-03-09 03:37:30 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return 0 on success, -1 on failure
|
|
|
|
*****************************************************************************/
|
|
|
|
|
2016-11-16 07:04:59 +03:00
|
|
|
int dev_redir_send_drive_create_request(tui32 device_id,
|
|
|
|
const char *path,
|
2013-03-09 03:37:30 +04:00
|
|
|
tui32 DesiredAccess,
|
|
|
|
tui32 CreateOptions,
|
|
|
|
tui32 CreateDisposition,
|
|
|
|
tui32 completion_id)
|
|
|
|
{
|
|
|
|
struct stream *s;
|
|
|
|
int bytes;
|
|
|
|
int len;
|
|
|
|
|
2013-04-21 03:42:49 +04:00
|
|
|
log_debug("DesiredAccess=0x%x CreateDisposition=0x%x CreateOptions=0x%x",
|
2013-03-09 03:37:30 +04:00
|
|
|
DesiredAccess, CreateDisposition, CreateOptions);
|
|
|
|
|
2013-06-09 05:44:21 +04:00
|
|
|
/* path in unicode needs this much space */
|
|
|
|
len = ((g_mbstowcs(NULL, path, 0) * sizeof(twchar)) / 2) + 2;
|
2013-03-09 03:37:30 +04:00
|
|
|
|
2013-05-03 13:25:13 +04:00
|
|
|
xstream_new(s, 1024 + len);
|
2013-03-09 03:37:30 +04:00
|
|
|
|
2013-05-16 04:06:05 +04:00
|
|
|
devredir_insert_DeviceIoRequest(s,
|
|
|
|
device_id,
|
|
|
|
0,
|
|
|
|
completion_id,
|
|
|
|
IRP_MJ_CREATE,
|
|
|
|
0);
|
2013-03-09 03:37:30 +04:00
|
|
|
|
2013-05-16 04:06:05 +04:00
|
|
|
xstream_wr_u32_le(s, DesiredAccess); /* DesiredAccess */
|
2013-05-03 13:25:13 +04:00
|
|
|
xstream_wr_u32_le(s, 0); /* AllocationSize high unused */
|
|
|
|
xstream_wr_u32_le(s, 0); /* AllocationSize low unused */
|
|
|
|
xstream_wr_u32_le(s, 0); /* FileAttributes */
|
2013-05-06 06:38:32 +04:00
|
|
|
xstream_wr_u32_le(s, 3); /* SharedAccess LK_TODO */
|
2013-05-03 13:25:13 +04:00
|
|
|
xstream_wr_u32_le(s, CreateDisposition); /* CreateDisposition */
|
|
|
|
xstream_wr_u32_le(s, CreateOptions); /* CreateOptions */
|
|
|
|
xstream_wr_u32_le(s, len); /* PathLength */
|
2013-05-16 04:06:05 +04:00
|
|
|
devredir_cvt_to_unicode(s->p, path); /* path in unicode */
|
2013-05-03 13:25:13 +04:00
|
|
|
xstream_seek(s, len);
|
2013-03-09 03:37:30 +04:00
|
|
|
|
|
|
|
/* send to client */
|
2013-05-03 13:25:13 +04:00
|
|
|
bytes = xstream_len(s);
|
2013-03-09 03:37:30 +04:00
|
|
|
send_channel_data(g_rdpdr_chan_id, s->data, bytes);
|
|
|
|
|
2013-05-03 13:25:13 +04:00
|
|
|
xstream_free(s);
|
2013-03-09 03:37:30 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Close a request previously created by dev_redir_send_drive_create_request()
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
int dev_redir_send_drive_close_request(tui16 Component, tui16 PacketId,
|
|
|
|
tui32 DeviceId,
|
|
|
|
tui32 FileId,
|
|
|
|
tui32 CompletionId,
|
|
|
|
tui32 MajorFunction,
|
|
|
|
tui32 MinorFunc,
|
|
|
|
int pad_len)
|
|
|
|
{
|
|
|
|
struct stream *s;
|
|
|
|
int bytes;
|
|
|
|
|
2013-05-03 13:25:13 +04:00
|
|
|
xstream_new(s, 1024);
|
2013-03-09 03:37:30 +04:00
|
|
|
|
2013-05-16 04:06:05 +04:00
|
|
|
devredir_insert_DeviceIoRequest(s, DeviceId, FileId, CompletionId,
|
|
|
|
MajorFunction, MinorFunc);
|
2013-03-09 03:37:30 +04:00
|
|
|
|
|
|
|
if (pad_len)
|
2013-05-03 13:25:13 +04:00
|
|
|
xstream_seek(s, pad_len);
|
2013-03-09 03:37:30 +04:00
|
|
|
|
|
|
|
/* send to client */
|
2013-05-03 13:25:13 +04:00
|
|
|
bytes = xstream_len(s);
|
2013-03-09 03:37:30 +04:00
|
|
|
send_channel_data(g_rdpdr_chan_id, s->data, bytes);
|
|
|
|
|
2013-05-03 13:25:13 +04:00
|
|
|
xstream_free(s);
|
2013-05-06 05:42:17 +04:00
|
|
|
log_debug("sent close request; expect CID_FILE_CLOSE");
|
2013-03-09 03:37:30 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief ask client to enumerate directory
|
|
|
|
*
|
|
|
|
* Server Drive Query Directory Request
|
|
|
|
* DR_DRIVE_QUERY_DIRECTORY_REQ
|
|
|
|
*
|
|
|
|
*****************************************************************************/
|
|
|
|
// LK_TODO Path needs to be Unicode
|
|
|
|
void dev_redir_send_drive_dir_request(IRP *irp, tui32 device_id,
|
|
|
|
tui32 InitialQuery, char *Path)
|
|
|
|
{
|
|
|
|
struct stream *s;
|
|
|
|
int bytes;
|
|
|
|
char upath[4096]; // LK_TODO need to malloc this
|
|
|
|
int path_len = 0;
|
|
|
|
|
|
|
|
/* during Initial Query, Path cannot be NULL */
|
|
|
|
if (InitialQuery)
|
|
|
|
{
|
|
|
|
if (Path == NULL)
|
2013-07-24 07:57:38 +04:00
|
|
|
{
|
2013-03-09 03:37:30 +04:00
|
|
|
return;
|
2013-07-24 07:57:38 +04:00
|
|
|
}
|
2013-03-09 03:37:30 +04:00
|
|
|
|
2013-06-09 05:44:21 +04:00
|
|
|
/* Path in unicode needs this much space */
|
|
|
|
path_len = ((g_mbstowcs(NULL, Path, 0) * sizeof(twchar)) / 2) + 2;
|
2013-03-09 03:37:30 +04:00
|
|
|
devredir_cvt_to_unicode(upath, Path);
|
|
|
|
}
|
|
|
|
|
2013-05-03 13:25:13 +04:00
|
|
|
xstream_new(s, 1024 + path_len);
|
2013-03-09 03:37:30 +04:00
|
|
|
|
|
|
|
irp->completion_type = CID_DIRECTORY_CONTROL;
|
2013-05-16 04:06:05 +04:00
|
|
|
devredir_insert_DeviceIoRequest(s,
|
|
|
|
device_id,
|
|
|
|
irp->FileId,
|
|
|
|
irp->CompletionId,
|
|
|
|
IRP_MJ_DIRECTORY_CONTROL,
|
|
|
|
IRP_MN_QUERY_DIRECTORY);
|
2013-03-09 03:37:30 +04:00
|
|
|
|
2013-04-21 03:42:49 +04:00
|
|
|
#ifdef USE_SHORT_NAMES_IN_DIR_LISTING
|
2013-05-03 13:25:13 +04:00
|
|
|
xstream_wr_u32_le(s, FileBothDirectoryInformation); /* FsInformationClass */
|
2013-04-21 03:42:49 +04:00
|
|
|
#else
|
2013-05-03 13:25:13 +04:00
|
|
|
xstream_wr_u32_le(s, FileDirectoryInformation); /* FsInformationClass */
|
2013-04-21 03:42:49 +04:00
|
|
|
#endif
|
2013-05-03 13:25:13 +04:00
|
|
|
xstream_wr_u8(s, InitialQuery); /* InitialQuery */
|
2013-03-09 03:37:30 +04:00
|
|
|
|
|
|
|
if (!InitialQuery)
|
|
|
|
{
|
2013-05-03 13:25:13 +04:00
|
|
|
xstream_wr_u32_le(s, 0); /* PathLength */
|
|
|
|
xstream_seek(s, 23);
|
2013-03-09 03:37:30 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-05-03 13:25:13 +04:00
|
|
|
xstream_wr_u32_le(s, path_len); /* PathLength */
|
|
|
|
xstream_seek(s, 23); /* Padding */
|
|
|
|
xstream_wr_string(s, upath, path_len);
|
2013-03-09 03:37:30 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* send to client */
|
2013-05-03 13:25:13 +04:00
|
|
|
bytes = xstream_len(s);
|
2013-03-09 03:37:30 +04:00
|
|
|
send_channel_data(g_rdpdr_chan_id, s->data, bytes);
|
|
|
|
|
2013-05-03 13:25:13 +04:00
|
|
|
xstream_free(s);
|
2013-03-09 03:37:30 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
** process data received from client **
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
/**
|
2016-02-14 07:41:07 +03:00
|
|
|
* @brief process client's response to our core_capability_req() msg
|
2013-03-09 03:37:30 +04:00
|
|
|
*
|
|
|
|
* @param s stream containing client's response
|
|
|
|
*****************************************************************************/
|
|
|
|
void dev_redir_proc_client_core_cap_resp(struct stream *s)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
tui16 num_caps;
|
|
|
|
tui16 cap_type;
|
|
|
|
tui16 cap_len;
|
|
|
|
tui32 cap_version;
|
2013-09-09 01:22:53 +04:00
|
|
|
char* holdp;
|
2013-03-09 03:37:30 +04:00
|
|
|
|
2013-05-03 13:25:13 +04:00
|
|
|
xstream_rd_u16_le(s, num_caps);
|
|
|
|
xstream_seek(s, 2); /* padding */
|
2013-03-09 03:37:30 +04:00
|
|
|
|
|
|
|
for (i = 0; i < num_caps; i++)
|
|
|
|
{
|
2013-09-09 01:22:53 +04:00
|
|
|
holdp = s->p;
|
2013-05-03 13:25:13 +04:00
|
|
|
xstream_rd_u16_le(s, cap_type);
|
|
|
|
xstream_rd_u16_le(s, cap_len);
|
|
|
|
xstream_rd_u32_le(s, cap_version);
|
2013-03-09 03:37:30 +04:00
|
|
|
|
|
|
|
switch (cap_type)
|
|
|
|
{
|
|
|
|
case CAP_GENERAL_TYPE:
|
|
|
|
log_debug("got CAP_GENERAL_TYPE");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CAP_PRINTER_TYPE:
|
|
|
|
log_debug("got CAP_PRINTER_TYPE");
|
|
|
|
g_is_printer_redir_supported = 1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CAP_PORT_TYPE:
|
|
|
|
log_debug("got CAP_PORT_TYPE");
|
|
|
|
g_is_port_redir_supported = 1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CAP_DRIVE_TYPE:
|
|
|
|
log_debug("got CAP_DRIVE_TYPE");
|
|
|
|
g_is_drive_redir_supported = 1;
|
|
|
|
if (cap_version == 2)
|
2013-09-09 01:22:53 +04:00
|
|
|
{
|
2013-03-09 03:37:30 +04:00
|
|
|
g_drive_redir_version = 2;
|
2013-09-09 01:22:53 +04:00
|
|
|
}
|
2013-03-09 03:37:30 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case CAP_SMARTCARD_TYPE:
|
|
|
|
log_debug("got CAP_SMARTCARD_TYPE");
|
|
|
|
g_is_smartcard_redir_supported = 1;
|
2013-08-05 12:10:57 +04:00
|
|
|
scard_init();
|
2013-03-09 03:37:30 +04:00
|
|
|
break;
|
|
|
|
}
|
2013-09-09 01:22:53 +04:00
|
|
|
s->p = holdp + cap_len;
|
2013-03-09 03:37:30 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-16 04:06:05 +04:00
|
|
|
void devredir_proc_client_devlist_announce_req(struct stream *s)
|
2013-03-09 03:37:30 +04:00
|
|
|
{
|
2016-06-22 02:30:19 +03:00
|
|
|
unsigned int i;
|
2013-03-09 03:37:30 +04:00
|
|
|
int j;
|
|
|
|
tui32 device_count;
|
|
|
|
tui32 device_type;
|
|
|
|
tui32 device_data_len;
|
2013-05-16 04:06:05 +04:00
|
|
|
char preferred_dos_name[9];
|
2013-03-09 03:37:30 +04:00
|
|
|
|
|
|
|
/* get number of devices being announced */
|
2013-05-03 13:25:13 +04:00
|
|
|
xstream_rd_u32_le(s, device_count);
|
2013-03-09 03:37:30 +04:00
|
|
|
|
|
|
|
log_debug("num of devices announced: %d", device_count);
|
|
|
|
|
|
|
|
for (i = 0; i < device_count; i++)
|
|
|
|
{
|
2013-05-03 13:25:13 +04:00
|
|
|
xstream_rd_u32_le(s, device_type);
|
2013-05-16 04:06:05 +04:00
|
|
|
xstream_rd_u32_le(s, g_device_id);
|
2013-03-09 03:37:30 +04:00
|
|
|
|
|
|
|
switch (device_type)
|
|
|
|
{
|
|
|
|
case RDPDR_DTYP_FILESYSTEM:
|
|
|
|
/* get preferred DOS name */
|
|
|
|
for (j = 0; j < 8; j++)
|
|
|
|
{
|
2013-05-16 04:06:05 +04:00
|
|
|
preferred_dos_name[j] = *s->p++;
|
2013-03-09 03:37:30 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* DOS names that are 8 chars long are not NULL terminated */
|
2013-05-16 04:06:05 +04:00
|
|
|
preferred_dos_name[8] = 0;
|
2013-03-09 03:37:30 +04:00
|
|
|
|
|
|
|
/* get device data len */
|
2013-05-03 13:25:13 +04:00
|
|
|
xstream_rd_u32_le(s, device_data_len);
|
2013-03-09 03:37:30 +04:00
|
|
|
if (device_data_len)
|
|
|
|
{
|
2013-05-03 13:25:13 +04:00
|
|
|
xstream_rd_string(g_full_name_for_filesystem, s,
|
2013-03-09 03:37:30 +04:00
|
|
|
device_data_len);
|
|
|
|
}
|
|
|
|
|
|
|
|
log_debug("device_type=FILE_SYSTEM device_id=0x%x dosname=%s "
|
|
|
|
"device_data_len=%d full_name=%s", g_device_id,
|
2013-05-16 04:06:05 +04:00
|
|
|
preferred_dos_name,
|
2013-03-09 03:37:30 +04:00
|
|
|
device_data_len, g_full_name_for_filesystem);
|
|
|
|
|
2013-05-16 04:06:05 +04:00
|
|
|
devredir_send_server_device_announce_resp(g_device_id);
|
2013-03-09 03:37:30 +04:00
|
|
|
|
|
|
|
/* create share directory in xrdp file system; */
|
|
|
|
/* think of this as the mount point for this share */
|
2013-05-16 04:06:05 +04:00
|
|
|
xfuse_create_share(g_device_id, preferred_dos_name);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case RDPDR_DTYP_SMARTCARD:
|
|
|
|
/* get preferred DOS name */
|
|
|
|
for (j = 0; j < 8; j++)
|
|
|
|
{
|
|
|
|
preferred_dos_name[j] = *s->p++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* DOS names that are 8 chars long are not NULL terminated */
|
|
|
|
preferred_dos_name[8] = 0;
|
|
|
|
|
|
|
|
/* for smart cards, device data len always 0 */
|
|
|
|
|
2016-12-09 04:08:04 +03:00
|
|
|
log_debug("device_type=SMARTCARD device_id=0x%x dosname=%s",
|
|
|
|
g_device_id, preferred_dos_name);
|
2013-05-16 04:06:05 +04:00
|
|
|
|
|
|
|
devredir_send_server_device_announce_resp(g_device_id);
|
|
|
|
scard_device_announce(g_device_id);
|
2013-03-09 03:37:30 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
/* we don't yet support these devices */
|
|
|
|
case RDPDR_DTYP_SERIAL:
|
|
|
|
case RDPDR_DTYP_PARALLEL:
|
|
|
|
case RDPDR_DTYP_PRINT:
|
|
|
|
log_debug("unsupported dev: 0x%x", device_type);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-12 19:35:00 +03:00
|
|
|
void
|
2013-07-24 07:57:38 +04:00
|
|
|
dev_redir_proc_device_iocompletion(struct stream *s)
|
2013-03-09 03:37:30 +04:00
|
|
|
{
|
|
|
|
FUSE_DATA *fuse_data = NULL;
|
|
|
|
IRP *irp = NULL;
|
|
|
|
|
|
|
|
tui32 DeviceId;
|
|
|
|
tui32 CompletionId;
|
|
|
|
tui32 IoStatus;
|
|
|
|
tui32 Length;
|
|
|
|
|
2013-05-03 13:25:13 +04:00
|
|
|
xstream_rd_u32_le(s, DeviceId);
|
|
|
|
xstream_rd_u32_le(s, CompletionId);
|
|
|
|
xstream_rd_u32_le(s, IoStatus);
|
2013-03-09 03:37:30 +04:00
|
|
|
|
2013-04-21 03:42:49 +04:00
|
|
|
log_debug("entered: IoStatus=0x%x CompletionId=%d", IoStatus, CompletionId);
|
2013-03-09 03:37:30 +04:00
|
|
|
|
2013-05-16 04:06:05 +04:00
|
|
|
if ((irp = devredir_irp_find(CompletionId)) == NULL)
|
2013-03-09 03:37:30 +04:00
|
|
|
{
|
|
|
|
log_error("IRP with completion ID %d not found", CompletionId);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-05-16 04:06:05 +04:00
|
|
|
/* if callback has been set, call it */
|
|
|
|
if (irp->callback)
|
|
|
|
{
|
|
|
|
(*irp->callback)(s, irp, DeviceId, CompletionId, IoStatus);
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2013-03-09 03:37:30 +04:00
|
|
|
switch (irp->completion_type)
|
|
|
|
{
|
2013-03-24 23:08:55 +04:00
|
|
|
case CID_CREATE_DIR_REQ:
|
|
|
|
log_debug("got CID_CREATE_DIR_REQ");
|
|
|
|
if (IoStatus != NT_STATUS_SUCCESS)
|
|
|
|
{
|
|
|
|
/* we were trying to create a request to enumerate a dir */
|
|
|
|
/* that does not exist; let FUSE know */
|
2013-05-19 06:44:16 +04:00
|
|
|
fuse_data = devredir_fuse_data_dequeue(irp);
|
2013-03-24 23:08:55 +04:00
|
|
|
if (fuse_data)
|
2013-03-09 03:37:30 +04:00
|
|
|
{
|
2013-03-24 23:08:55 +04:00
|
|
|
xfuse_devredir_cb_enum_dir_done(fuse_data->data_ptr,
|
|
|
|
IoStatus);
|
|
|
|
free(fuse_data);
|
2013-03-09 03:37:30 +04:00
|
|
|
}
|
2013-05-16 04:06:05 +04:00
|
|
|
devredir_irp_delete(irp);
|
2013-03-24 23:08:55 +04:00
|
|
|
return;
|
|
|
|
}
|
2013-03-09 03:37:30 +04:00
|
|
|
|
2013-05-03 13:25:13 +04:00
|
|
|
xstream_rd_u32_le(s, irp->FileId);
|
2013-03-24 23:08:55 +04:00
|
|
|
log_debug("got CID_CREATE_DIR_REQ IoStatus=0x%x FileId=%d",
|
|
|
|
IoStatus, irp->FileId);
|
2013-04-21 03:42:49 +04:00
|
|
|
|
2013-03-24 23:08:55 +04:00
|
|
|
dev_redir_send_drive_dir_request(irp, DeviceId, 1, irp->pathname);
|
|
|
|
break;
|
2013-03-09 03:37:30 +04:00
|
|
|
|
2013-03-24 23:08:55 +04:00
|
|
|
case CID_CREATE_OPEN_REQ:
|
2013-05-03 13:25:13 +04:00
|
|
|
xstream_rd_u32_le(s, irp->FileId);
|
2013-06-09 05:44:21 +04:00
|
|
|
|
2013-03-24 23:08:55 +04:00
|
|
|
log_debug("got CID_CREATE_OPEN_REQ IoStatus=0x%x FileId=%d",
|
|
|
|
IoStatus, irp->FileId);
|
2013-06-09 05:44:21 +04:00
|
|
|
|
2013-05-19 06:44:16 +04:00
|
|
|
fuse_data = devredir_fuse_data_dequeue(irp);
|
2013-06-09 05:44:21 +04:00
|
|
|
xfuse_devredir_cb_open_file(fuse_data->data_ptr, IoStatus,
|
2013-03-24 23:08:55 +04:00
|
|
|
DeviceId, irp->FileId);
|
2013-06-09 05:44:21 +04:00
|
|
|
if ((irp->type == S_IFDIR) || (IoStatus != NT_STATUS_SUCCESS))
|
2013-05-16 04:06:05 +04:00
|
|
|
devredir_irp_delete(irp);
|
2013-03-24 23:08:55 +04:00
|
|
|
break;
|
2013-03-09 03:37:30 +04:00
|
|
|
|
2013-03-24 23:08:55 +04:00
|
|
|
case CID_READ:
|
|
|
|
log_debug("got CID_READ");
|
2013-05-03 13:25:13 +04:00
|
|
|
xstream_rd_u32_le(s, Length);
|
2013-05-19 06:44:16 +04:00
|
|
|
fuse_data = devredir_fuse_data_dequeue(irp);
|
2013-06-03 02:33:51 +04:00
|
|
|
|
2013-05-21 23:57:06 +04:00
|
|
|
if (fuse_data == NULL)
|
2014-07-21 03:36:33 +04:00
|
|
|
{
|
2013-05-21 23:57:06 +04:00
|
|
|
log_error("fuse_data is NULL");
|
2014-07-21 03:36:33 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
xfuse_devredir_cb_read_file(fuse_data->data_ptr, s->p, Length);
|
|
|
|
devredir_irp_delete(irp);
|
|
|
|
}
|
2013-03-24 23:08:55 +04:00
|
|
|
break;
|
2013-03-09 03:37:30 +04:00
|
|
|
|
2013-03-24 23:08:55 +04:00
|
|
|
case CID_WRITE:
|
|
|
|
log_debug("got CID_WRITE");
|
2013-05-03 13:25:13 +04:00
|
|
|
xstream_rd_u32_le(s, Length);
|
2013-05-19 06:44:16 +04:00
|
|
|
fuse_data = devredir_fuse_data_dequeue(irp);
|
2013-06-03 02:33:51 +04:00
|
|
|
|
|
|
|
if (fuse_data == NULL)
|
2014-07-21 03:36:33 +04:00
|
|
|
{
|
2013-06-03 02:33:51 +04:00
|
|
|
log_error("fuse_data is NULL");
|
2014-07-21 03:36:33 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-03-13 13:56:37 +03:00
|
|
|
xfuse_devredir_cb_write_file(fuse_data->data_ptr, IoStatus,
|
|
|
|
s->p, Length);
|
2014-07-21 03:36:33 +04:00
|
|
|
devredir_irp_delete(irp);
|
|
|
|
}
|
2013-03-24 23:08:55 +04:00
|
|
|
break;
|
2013-03-09 03:37:30 +04:00
|
|
|
|
2013-03-24 23:08:55 +04:00
|
|
|
case CID_CLOSE:
|
|
|
|
log_debug("got CID_CLOSE");
|
2013-03-31 02:51:50 +04:00
|
|
|
log_debug("deleting irp with completion_id=%d comp_type=%d",
|
2013-05-16 04:06:05 +04:00
|
|
|
irp->CompletionId, irp->completion_type);
|
|
|
|
devredir_irp_delete(irp);
|
2013-03-24 23:08:55 +04:00
|
|
|
break;
|
2013-03-09 03:37:30 +04:00
|
|
|
|
2013-03-24 23:08:55 +04:00
|
|
|
case CID_FILE_CLOSE:
|
|
|
|
log_debug("got CID_FILE_CLOSE");
|
2013-05-19 06:44:16 +04:00
|
|
|
fuse_data = devredir_fuse_data_dequeue(irp);
|
2013-03-24 23:08:55 +04:00
|
|
|
xfuse_devredir_cb_file_close(fuse_data->data_ptr);
|
2013-05-16 04:06:05 +04:00
|
|
|
devredir_irp_delete(irp);
|
2013-03-24 23:08:55 +04:00
|
|
|
break;
|
2013-03-19 06:43:20 +04:00
|
|
|
|
2013-03-24 23:08:55 +04:00
|
|
|
case CID_DIRECTORY_CONTROL:
|
|
|
|
log_debug("got CID_DIRECTORY_CONTROL");
|
2013-03-09 03:37:30 +04:00
|
|
|
|
2013-03-24 23:08:55 +04:00
|
|
|
dev_redir_proc_query_dir_response(irp, s, DeviceId,
|
|
|
|
CompletionId, IoStatus);
|
|
|
|
break;
|
2013-03-09 03:37:30 +04:00
|
|
|
|
2013-03-24 23:08:55 +04:00
|
|
|
case CID_RMDIR_OR_FILE:
|
|
|
|
log_debug("got CID_RMDIR_OR_FILE");
|
2013-05-03 13:25:13 +04:00
|
|
|
xstream_rd_u32_le(s, irp->FileId);
|
2013-03-24 23:08:55 +04:00
|
|
|
devredir_proc_cid_rmdir_or_file(irp, IoStatus);
|
|
|
|
return;
|
|
|
|
break;
|
2013-03-19 06:43:20 +04:00
|
|
|
|
2013-03-24 23:08:55 +04:00
|
|
|
case CID_RMDIR_OR_FILE_RESP:
|
|
|
|
log_debug("got CID_RMDIR_OR_FILE_RESP");
|
|
|
|
devredir_proc_cid_rmdir_or_file_resp(irp, IoStatus);
|
|
|
|
break;
|
2013-03-19 06:43:20 +04:00
|
|
|
|
2013-03-24 23:08:55 +04:00
|
|
|
case CID_RENAME_FILE:
|
|
|
|
log_debug("got CID_RENAME_FILE");
|
2013-05-03 13:25:13 +04:00
|
|
|
xstream_rd_u32_le(s, irp->FileId);
|
2013-03-24 23:08:55 +04:00
|
|
|
devredir_proc_cid_rename_file(irp, IoStatus);
|
|
|
|
return;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CID_RENAME_FILE_RESP:
|
|
|
|
log_debug("got CID_RENAME_FILE_RESP");
|
|
|
|
devredir_proc_cid_rename_file_resp(irp, IoStatus);
|
|
|
|
break;
|
|
|
|
|
2019-03-21 19:48:01 +03:00
|
|
|
case CID_LOOKUP_BASIC_ENTRY:
|
|
|
|
log_debug("got CID_LOOKUP_BASIC_ENTRY");
|
|
|
|
xstream_rd_u32_le(s, irp->FileId);
|
|
|
|
/* Issue a call to get the FileBasicInformation */
|
|
|
|
devredir_proc_cid_lookup_basic_entry(irp, IoStatus);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CID_LOOKUP_STD_ENTRY:
|
|
|
|
log_debug("got CID_LOOKUP_STD_ENTRY");
|
|
|
|
/* Parse the FileBasicInformation and request the
|
|
|
|
* FileStandardInformation */
|
|
|
|
devredir_proc_cid_lookup_basic_entry_resp(irp, s, IoStatus);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CID_LOOKUP_ENTRY_RESP:
|
|
|
|
/* Parse the FileStandardInformation and respond to caller */
|
|
|
|
log_debug("got CID_LOOKUP_ENTRY_RESP");
|
|
|
|
devredir_proc_cid_lookup_std_entry_resp(irp, s, DeviceId,
|
|
|
|
CompletionId, IoStatus);
|
|
|
|
break;
|
|
|
|
|
2013-03-24 23:08:55 +04:00
|
|
|
default:
|
|
|
|
log_error("got unknown CompletionID: DeviceId=0x%x "
|
|
|
|
"CompletionId=0x%x IoStatus=0x%x",
|
|
|
|
DeviceId, CompletionId, IoStatus);
|
|
|
|
break;
|
2013-03-09 03:37:30 +04:00
|
|
|
}
|
|
|
|
|
2013-05-16 04:06:05 +04:00
|
|
|
done:
|
|
|
|
|
2013-03-09 03:37:30 +04:00
|
|
|
if (fuse_data)
|
2013-05-19 06:44:16 +04:00
|
|
|
{
|
|
|
|
log_debug("free FUSE_DATA=%p", fuse_data);
|
2013-03-09 03:37:30 +04:00
|
|
|
free(fuse_data);
|
2013-05-19 06:44:16 +04:00
|
|
|
}
|
2013-03-09 03:37:30 +04:00
|
|
|
|
|
|
|
log_debug("exiting");
|
|
|
|
}
|
|
|
|
|
2017-03-12 19:35:00 +03:00
|
|
|
void
|
2013-07-24 07:57:38 +04:00
|
|
|
dev_redir_proc_query_dir_response(IRP *irp,
|
|
|
|
struct stream *s_in,
|
|
|
|
tui32 DeviceId,
|
|
|
|
tui32 CompletionId,
|
|
|
|
tui32 IoStatus)
|
2013-03-09 03:37:30 +04:00
|
|
|
{
|
|
|
|
FUSE_DATA *fuse_data = NULL;
|
|
|
|
|
|
|
|
tui32 Length;
|
|
|
|
tui64 CreationTime;
|
|
|
|
tui64 LastAccessTime;
|
|
|
|
tui64 LastWriteTime;
|
|
|
|
tui64 EndOfFile;
|
|
|
|
tui32 FileAttributes;
|
|
|
|
tui32 FileNameLength;
|
|
|
|
tui32 status;
|
2019-03-21 19:48:01 +03:00
|
|
|
struct file_attr fattr;
|
2013-03-09 03:37:30 +04:00
|
|
|
|
|
|
|
char filename[256];
|
2016-06-22 02:30:19 +03:00
|
|
|
unsigned int i = 0;
|
2013-03-09 03:37:30 +04:00
|
|
|
|
2013-05-03 13:25:13 +04:00
|
|
|
xstream_rd_u32_le(s_in, Length);
|
2013-03-09 03:37:30 +04:00
|
|
|
|
|
|
|
if ((IoStatus == NT_STATUS_UNSUCCESSFUL) ||
|
|
|
|
(IoStatus == STATUS_NO_MORE_FILES))
|
|
|
|
{
|
|
|
|
status = (IoStatus == STATUS_NO_MORE_FILES) ? 0 : IoStatus;
|
2013-05-19 06:44:16 +04:00
|
|
|
fuse_data = devredir_fuse_data_dequeue(irp);
|
2013-03-09 03:37:30 +04:00
|
|
|
xfuse_devredir_cb_enum_dir_done(fuse_data->data_ptr, status);
|
|
|
|
irp->completion_type = CID_CLOSE;
|
|
|
|
dev_redir_send_drive_close_request(RDPDR_CTYP_CORE,
|
|
|
|
PAKID_CORE_DEVICE_IOREQUEST,
|
|
|
|
DeviceId,
|
|
|
|
irp->FileId,
|
2013-05-16 04:06:05 +04:00
|
|
|
irp->CompletionId,
|
2013-03-09 03:37:30 +04:00
|
|
|
IRP_MJ_CLOSE, 0, 32);
|
|
|
|
free(fuse_data);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* TODO check status for errors */
|
|
|
|
|
|
|
|
/* process FILE_DIRECTORY_INFORMATION structures */
|
|
|
|
while (i < Length)
|
|
|
|
{
|
|
|
|
log_debug("processing FILE_DIRECTORY_INFORMATION structs");
|
|
|
|
|
2016-05-07 04:41:45 +03:00
|
|
|
xstream_seek(s_in, 4); /* NextEntryOffset */
|
2013-05-03 13:25:13 +04:00
|
|
|
xstream_seek(s_in, 4); /* FileIndex */
|
|
|
|
xstream_rd_u64_le(s_in, CreationTime);
|
|
|
|
xstream_rd_u64_le(s_in, LastAccessTime);
|
|
|
|
xstream_rd_u64_le(s_in, LastWriteTime);
|
2016-05-07 04:41:45 +03:00
|
|
|
xstream_seek(s_in, 8); /* ChangeTime */
|
2013-05-03 13:25:13 +04:00
|
|
|
xstream_rd_u64_le(s_in, EndOfFile);
|
|
|
|
xstream_seek(s_in, 8); /* AllocationSize */
|
|
|
|
xstream_rd_u32_le(s_in, FileAttributes);
|
|
|
|
xstream_rd_u32_le(s_in, FileNameLength);
|
2013-03-09 03:37:30 +04:00
|
|
|
|
2013-04-21 03:42:49 +04:00
|
|
|
#ifdef USE_SHORT_NAMES_IN_DIR_LISTING
|
2016-05-07 04:41:45 +03:00
|
|
|
xstream_seek(s_in, 4); /* EaSize */
|
|
|
|
xstream_seek(s_in, 1); /* ShortNameLength */
|
|
|
|
xstream_seek(s_in, 1); /* Reserved */
|
2013-05-03 13:25:13 +04:00
|
|
|
xstream_seek(s_in, 23); /* ShortName in Unicode */
|
2013-04-21 03:42:49 +04:00
|
|
|
#endif
|
2013-03-09 03:37:30 +04:00
|
|
|
devredir_cvt_from_unicode_len(filename, s_in->p, FileNameLength);
|
|
|
|
|
2013-04-21 03:42:49 +04:00
|
|
|
#ifdef USE_SHORT_NAMES_IN_DIR_LISTING
|
|
|
|
i += 70 + 23 + FileNameLength;
|
|
|
|
#else
|
2013-03-09 03:37:30 +04:00
|
|
|
i += 64 + FileNameLength;
|
2013-04-21 03:42:49 +04:00
|
|
|
#endif
|
|
|
|
//log_debug("CreationTime: 0x%llx", CreationTime);
|
|
|
|
//log_debug("LastAccessTime: 0x%llx", LastAccessTime);
|
|
|
|
//log_debug("LastWriteTime: 0x%llx", LastWriteTime);
|
|
|
|
//log_debug("EndOfFile: %lld", EndOfFile);
|
|
|
|
//log_debug("FileAttributes: 0x%x", FileAttributes);
|
|
|
|
#ifdef USE_SHORT_NAMES_IN_DIR_LISTING
|
|
|
|
//log_debug("ShortNameLength: %d", ShortNameLength);
|
|
|
|
#endif
|
|
|
|
//log_debug("FileNameLength: %d", FileNameLength);
|
2013-03-09 03:37:30 +04:00
|
|
|
log_debug("FileName: %s", filename);
|
|
|
|
|
2019-03-21 19:48:01 +03:00
|
|
|
fattr.name = filename;
|
|
|
|
fattr.mode = WINDOWS_TO_LINUX_FILE_PERM(FileAttributes);
|
|
|
|
fattr.size = (size_t) EndOfFile;
|
|
|
|
fattr.atime = WINDOWS_TO_LINUX_TIME(LastAccessTime);
|
|
|
|
fattr.mtime = WINDOWS_TO_LINUX_TIME(LastWriteTime);
|
|
|
|
fattr.ctime = WINDOWS_TO_LINUX_TIME(CreationTime);
|
2013-03-09 03:37:30 +04:00
|
|
|
|
|
|
|
/* add this entry to xrdp file system */
|
2013-05-19 06:44:16 +04:00
|
|
|
fuse_data = devredir_fuse_data_peek(irp);
|
2019-03-21 19:48:01 +03:00
|
|
|
(void)xfuse_devredir_add_file_or_dir(fuse_data->data_ptr, &fattr);
|
2013-03-09 03:37:30 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
dev_redir_send_drive_dir_request(irp, DeviceId, 0, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* FUSE calls this function whenever it wants us to enumerate a dir
|
|
|
|
*
|
|
|
|
* @param fusep opaque data struct that we just pass back to FUSE when done
|
|
|
|
* @param device_id device_id of the redirected share
|
|
|
|
* @param path the dir path to enumerate
|
|
|
|
*
|
|
|
|
* @return 0 on success, -1 on failure
|
|
|
|
*****************************************************************************/
|
|
|
|
|
2017-03-12 19:35:00 +03:00
|
|
|
int
|
2016-11-16 07:04:59 +03:00
|
|
|
dev_redir_get_dir_listing(void *fusep, tui32 device_id, const char *path)
|
2013-03-09 03:37:30 +04:00
|
|
|
{
|
|
|
|
tui32 DesiredAccess;
|
|
|
|
tui32 CreateOptions;
|
2013-08-12 05:06:39 +04:00
|
|
|
tui32 CreateDisposition;
|
2013-03-09 03:37:30 +04:00
|
|
|
int rval;
|
|
|
|
IRP *irp;
|
|
|
|
|
2013-05-06 05:42:17 +04:00
|
|
|
log_debug("fusep=%p", fusep);
|
|
|
|
|
2013-05-16 04:06:05 +04:00
|
|
|
if ((irp = devredir_irp_new()) == NULL)
|
2013-03-09 03:37:30 +04:00
|
|
|
return -1;
|
|
|
|
|
2016-11-16 08:24:49 +03:00
|
|
|
strncpy(irp->pathname, path, 255);
|
|
|
|
|
|
|
|
/* convert / to windows compatible \ */
|
|
|
|
devredir_cvt_slash(irp->pathname);
|
2013-04-21 03:42:49 +04:00
|
|
|
|
2013-05-16 04:06:05 +04:00
|
|
|
irp->CompletionId = g_completion_id++;
|
2013-03-09 03:37:30 +04:00
|
|
|
irp->completion_type = CID_CREATE_DIR_REQ;
|
2013-05-16 04:06:05 +04:00
|
|
|
irp->DeviceId = device_id;
|
2014-07-19 22:56:00 +04:00
|
|
|
|
2013-05-19 06:44:16 +04:00
|
|
|
devredir_fuse_data_enqueue(irp, fusep);
|
2013-03-09 03:37:30 +04:00
|
|
|
|
|
|
|
DesiredAccess = DA_FILE_READ_DATA | DA_SYNCHRONIZE;
|
|
|
|
CreateOptions = CO_FILE_DIRECTORY_FILE | CO_FILE_SYNCHRONOUS_IO_NONALERT;
|
|
|
|
CreateDisposition = CD_FILE_OPEN;
|
2013-04-21 03:42:49 +04:00
|
|
|
|
2016-11-16 08:24:49 +03:00
|
|
|
rval = dev_redir_send_drive_create_request(device_id, irp->pathname,
|
2013-03-09 03:37:30 +04:00
|
|
|
DesiredAccess, CreateOptions,
|
|
|
|
CreateDisposition,
|
2013-05-16 04:06:05 +04:00
|
|
|
irp->CompletionId);
|
2013-03-09 03:37:30 +04:00
|
|
|
|
2016-11-16 08:24:49 +03:00
|
|
|
log_debug("looking for device_id=%d path=%s", device_id, irp->pathname);
|
2013-03-09 03:37:30 +04:00
|
|
|
|
2016-02-14 07:41:07 +03:00
|
|
|
/* when we get a response to dev_redir_send_drive_create_request(), we */
|
2013-03-09 03:37:30 +04:00
|
|
|
/* call dev_redir_send_drive_dir_request(), which needs the following */
|
|
|
|
/* at the end of the path argument */
|
|
|
|
if (dev_redir_string_ends_with(irp->pathname, '\\'))
|
|
|
|
strcat(irp->pathname, "*");
|
|
|
|
else
|
|
|
|
strcat(irp->pathname, "\\*");
|
|
|
|
|
|
|
|
return rval;
|
|
|
|
}
|
|
|
|
|
2019-03-21 19:48:01 +03:00
|
|
|
/**
|
|
|
|
* FUSE calls this function whenever it wants us to lookup a file or directory
|
|
|
|
*
|
|
|
|
* @param fusep opaque data struct that we just pass back to FUSE when done
|
|
|
|
* @param device_id device_id of the redirected share
|
|
|
|
* @param path the name of the directory containing the file
|
|
|
|
* @param file the filename
|
|
|
|
*
|
|
|
|
* @return 0 on success, -1 on failure
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
int
|
|
|
|
dev_redir_lookup_entry(void *fusep, tui32 device_id, const char *dirpath,
|
|
|
|
const char *entry)
|
|
|
|
{
|
|
|
|
tui32 DesiredAccess;
|
|
|
|
tui32 CreateOptions;
|
|
|
|
tui32 CreateDisposition;
|
|
|
|
int rval = -1;
|
|
|
|
IRP *irp;
|
|
|
|
size_t pathlen;
|
|
|
|
|
|
|
|
log_debug("fusep=%p", fusep);
|
|
|
|
|
|
|
|
/* Check the qualified name of the file fits in the IRP */
|
|
|
|
pathlen = strlen(dirpath) + strlen(entry);
|
|
|
|
if (!dev_redir_string_ends_with(dirpath,'/'))
|
|
|
|
{
|
|
|
|
++pathlen;
|
|
|
|
}
|
|
|
|
if (pathlen < sizeof(irp->pathname))
|
|
|
|
{
|
|
|
|
if ((irp = devredir_irp_new()) != NULL)
|
|
|
|
{
|
|
|
|
strcpy(irp->pathname, dirpath);
|
|
|
|
if (!dev_redir_string_ends_with(dirpath, '/'))
|
|
|
|
{
|
|
|
|
strcat(irp->pathname, "/");
|
|
|
|
}
|
|
|
|
strcat(irp->pathname, entry);
|
|
|
|
|
|
|
|
/* convert / to windows compatible \ */
|
|
|
|
devredir_cvt_slash(irp->pathname);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Allocate an IRP to open the file, read the basic attributes,
|
|
|
|
* read the standard attributes, and then close the file
|
|
|
|
*/
|
|
|
|
irp->CompletionId = g_completion_id++;
|
|
|
|
irp->completion_type = CID_LOOKUP_BASIC_ENTRY;
|
|
|
|
irp->DeviceId = device_id;
|
|
|
|
|
|
|
|
devredir_fuse_data_enqueue(irp, fusep);
|
|
|
|
|
|
|
|
DesiredAccess = DA_FILE_READ_ATTRIBUTES | DA_SYNCHRONIZE;
|
|
|
|
CreateOptions = 0x020; /* Same as rmdir or file */
|
|
|
|
CreateDisposition = CD_FILE_OPEN;
|
|
|
|
|
|
|
|
log_debug("lookup for device_id=%d path=%s",
|
|
|
|
device_id, irp->pathname);
|
|
|
|
|
|
|
|
rval = dev_redir_send_drive_create_request(device_id,
|
|
|
|
irp->pathname,
|
|
|
|
DesiredAccess, CreateOptions,
|
|
|
|
CreateDisposition,
|
|
|
|
irp->CompletionId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return rval;
|
|
|
|
}
|
|
|
|
|
2017-03-12 19:35:00 +03:00
|
|
|
int
|
2016-11-16 07:04:59 +03:00
|
|
|
dev_redir_file_open(void *fusep, tui32 device_id, const char *path,
|
|
|
|
int mode, int type, const char *gen_buf)
|
2013-03-09 03:37:30 +04:00
|
|
|
{
|
|
|
|
tui32 DesiredAccess;
|
|
|
|
tui32 CreateOptions;
|
2013-03-24 23:08:55 +04:00
|
|
|
tui32 CreateDisposition;
|
2013-03-09 03:37:30 +04:00
|
|
|
int rval;
|
|
|
|
IRP *irp;
|
|
|
|
|
|
|
|
log_debug("device_id=%d path=%s mode=0x%x", device_id, path, mode);
|
|
|
|
|
2013-05-16 04:06:05 +04:00
|
|
|
if ((irp = devredir_irp_new()) == NULL)
|
2013-03-09 03:37:30 +04:00
|
|
|
return -1;
|
|
|
|
|
2013-03-24 23:08:55 +04:00
|
|
|
if (type & OP_RENAME_FILE)
|
|
|
|
{
|
|
|
|
irp->completion_type = CID_RENAME_FILE;
|
2019-03-21 19:48:01 +03:00
|
|
|
strncpy(irp->gen.buf, gen_buf, 1023);
|
2013-03-24 23:08:55 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
irp->completion_type = CID_CREATE_OPEN_REQ;
|
|
|
|
}
|
|
|
|
|
2013-05-16 04:06:05 +04:00
|
|
|
irp->CompletionId = g_completion_id++;
|
|
|
|
irp->DeviceId = device_id;
|
2014-07-19 22:56:00 +04:00
|
|
|
|
2014-07-27 03:33:36 +04:00
|
|
|
strncpy(irp->pathname, path, 255);
|
2013-05-19 06:44:16 +04:00
|
|
|
devredir_fuse_data_enqueue(irp, fusep);
|
2013-03-09 03:37:30 +04:00
|
|
|
|
|
|
|
if (mode & O_CREAT)
|
|
|
|
{
|
2013-03-24 23:08:55 +04:00
|
|
|
log_debug("open file in O_CREAT");
|
2013-05-06 05:42:17 +04:00
|
|
|
DesiredAccess = 0x0016019f; /* got this value from windows */
|
2013-03-09 03:37:30 +04:00
|
|
|
|
2013-03-24 23:08:55 +04:00
|
|
|
if (type & S_IFDIR)
|
2013-03-09 03:37:30 +04:00
|
|
|
{
|
|
|
|
log_debug("creating dir");
|
|
|
|
CreateOptions = CO_FILE_DIRECTORY_FILE | CO_FILE_SYNCHRONOUS_IO_NONALERT;
|
2013-03-31 02:51:50 +04:00
|
|
|
irp->type = S_IFDIR;
|
2013-03-09 03:37:30 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
log_debug("creating file");
|
2013-05-06 05:42:17 +04:00
|
|
|
CreateOptions = 0x44; /* got this value from windows */
|
2013-03-09 03:37:30 +04:00
|
|
|
}
|
|
|
|
|
2013-05-06 05:42:17 +04:00
|
|
|
//CreateDisposition = CD_FILE_CREATE;
|
|
|
|
CreateDisposition = 0x02; /* got this value from windows */
|
2013-03-09 03:37:30 +04:00
|
|
|
}
|
2013-05-21 23:57:06 +04:00
|
|
|
else
|
2013-03-09 03:37:30 +04:00
|
|
|
{
|
2013-05-06 05:42:17 +04:00
|
|
|
#if 1
|
2019-03-13 13:56:37 +03:00
|
|
|
switch(mode & O_ACCMODE)
|
|
|
|
{
|
|
|
|
case O_RDONLY:
|
|
|
|
log_debug("open file in O_RDONLY");
|
|
|
|
DesiredAccess = DA_FILE_READ_DATA | DA_SYNCHRONIZE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case O_WRONLY:
|
|
|
|
log_debug("open file in O_WRONLY");
|
|
|
|
DesiredAccess = DA_FILE_WRITE_DATA | DA_SYNCHRONIZE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
/*
|
|
|
|
* The access mode could conceivably be invalid here,
|
|
|
|
* but we assume this has been checked by the caller
|
|
|
|
*/
|
|
|
|
log_debug("open file in O_RDWR");
|
|
|
|
/* without the 0x00000010 rdesktop opens files in */
|
|
|
|
/* O_RDONLY instead of O_RDWR mode */
|
|
|
|
DesiredAccess = DA_FILE_READ_DATA | DA_FILE_WRITE_DATA |
|
|
|
|
DA_SYNCHRONIZE | 0x00000010;
|
|
|
|
}
|
2013-09-25 04:19:10 +04:00
|
|
|
|
2013-03-09 03:37:30 +04:00
|
|
|
CreateOptions = CO_FILE_SYNCHRONOUS_IO_NONALERT;
|
|
|
|
CreateDisposition = CD_FILE_OPEN; // WAS 1
|
2013-05-06 05:42:17 +04:00
|
|
|
#else
|
2013-05-21 23:57:06 +04:00
|
|
|
/* got this value from windows; the 0x00000010 was added by LK; */
|
|
|
|
/* without this rdesktop opens files in O_RDONLY instead of */
|
|
|
|
/* O_RDWR mode */
|
|
|
|
DesiredAccess = 0x00120089 | 0x00000010;
|
2013-05-06 05:42:17 +04:00
|
|
|
CreateOptions = 0x20060;
|
|
|
|
CreateDisposition = 0x01;
|
2013-03-09 03:37:30 +04:00
|
|
|
#endif
|
2013-05-06 05:42:17 +04:00
|
|
|
}
|
|
|
|
|
2013-03-09 03:37:30 +04:00
|
|
|
rval = dev_redir_send_drive_create_request(device_id, path,
|
|
|
|
DesiredAccess, CreateOptions,
|
|
|
|
CreateDisposition,
|
2013-05-16 04:06:05 +04:00
|
|
|
irp->CompletionId);
|
2013-03-09 03:37:30 +04:00
|
|
|
|
|
|
|
return rval;
|
|
|
|
}
|
|
|
|
|
2013-03-31 02:51:50 +04:00
|
|
|
int devredir_file_close(void *fusep, tui32 device_id, tui32 FileId)
|
2013-03-19 06:43:20 +04:00
|
|
|
{
|
|
|
|
IRP *irp;
|
|
|
|
|
2013-05-19 06:44:16 +04:00
|
|
|
log_debug("entered: fusep=%p device_id=%d FileId=%d",
|
|
|
|
fusep, device_id, FileId);
|
2013-05-06 05:42:17 +04:00
|
|
|
|
2013-03-31 02:51:50 +04:00
|
|
|
#if 0
|
2013-05-16 04:06:05 +04:00
|
|
|
if ((irp = devredir_irp_new()) == NULL)
|
2013-03-19 06:43:20 +04:00
|
|
|
return -1;
|
|
|
|
|
2013-05-16 04:06:05 +04:00
|
|
|
irp->CompletionId = g_completion_id++;
|
2013-03-31 02:51:50 +04:00
|
|
|
#else
|
2013-05-16 04:06:05 +04:00
|
|
|
if ((irp = devredir_irp_find_by_fileid(FileId)) == NULL)
|
2013-03-31 02:51:50 +04:00
|
|
|
{
|
|
|
|
log_error("no IRP found with FileId = %d", FileId);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
#endif
|
2013-03-19 06:43:20 +04:00
|
|
|
irp->completion_type = CID_FILE_CLOSE;
|
2013-05-16 04:06:05 +04:00
|
|
|
irp->DeviceId = device_id;
|
2013-05-19 06:44:16 +04:00
|
|
|
devredir_fuse_data_enqueue(irp, fusep);
|
2013-03-19 06:43:20 +04:00
|
|
|
|
|
|
|
return dev_redir_send_drive_close_request(RDPDR_CTYP_CORE,
|
|
|
|
PAKID_CORE_DEVICE_IOREQUEST,
|
|
|
|
device_id,
|
2013-03-31 02:51:50 +04:00
|
|
|
FileId,
|
2013-05-16 04:06:05 +04:00
|
|
|
irp->CompletionId,
|
2013-03-19 06:43:20 +04:00
|
|
|
IRP_MJ_CLOSE,
|
|
|
|
0, 32);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-05-06 05:42:17 +04:00
|
|
|
* Remove (delete) a directory or file
|
2013-03-19 06:43:20 +04:00
|
|
|
*****************************************************************************/
|
|
|
|
|
2017-03-12 19:35:00 +03:00
|
|
|
int
|
2016-11-16 07:04:59 +03:00
|
|
|
devredir_rmdir_or_file(void *fusep, tui32 device_id, const char *path, int mode)
|
2013-03-19 06:43:20 +04:00
|
|
|
{
|
|
|
|
tui32 DesiredAccess;
|
|
|
|
tui32 CreateOptions;
|
|
|
|
tui32 CreateDisposition;
|
|
|
|
int rval;
|
|
|
|
IRP *irp;
|
|
|
|
|
2013-05-16 04:06:05 +04:00
|
|
|
if ((irp = devredir_irp_new()) == NULL)
|
2013-03-19 06:43:20 +04:00
|
|
|
return -1;
|
|
|
|
|
2013-05-16 04:06:05 +04:00
|
|
|
irp->CompletionId = g_completion_id++;
|
2013-03-19 06:43:20 +04:00
|
|
|
irp->completion_type = CID_RMDIR_OR_FILE;
|
2013-05-16 04:06:05 +04:00
|
|
|
irp->DeviceId = device_id;
|
2014-07-19 22:56:00 +04:00
|
|
|
|
2014-07-27 03:33:36 +04:00
|
|
|
strncpy(irp->pathname, path, 255);
|
2013-05-19 06:44:16 +04:00
|
|
|
devredir_fuse_data_enqueue(irp, fusep);
|
2013-03-19 06:43:20 +04:00
|
|
|
|
2013-05-06 05:42:17 +04:00
|
|
|
//DesiredAccess = DA_DELETE | DA_FILE_READ_ATTRIBUTES | DA_SYNCHRONIZE;
|
|
|
|
DesiredAccess = 0x00100080; /* got this value from windows */
|
2013-03-19 06:43:20 +04:00
|
|
|
|
2013-05-06 05:42:17 +04:00
|
|
|
//CreateOptions = CO_FILE_DELETE_ON_CLOSE | CO_FILE_DIRECTORY_FILE |
|
|
|
|
// CO_FILE_SYNCHRONOUS_IO_NONALERT;
|
|
|
|
CreateOptions = 0x020; /* got this value from windows */
|
2013-03-19 06:43:20 +04:00
|
|
|
|
2013-05-06 05:42:17 +04:00
|
|
|
//CreateDisposition = CD_FILE_OPEN; // WAS 1
|
|
|
|
CreateDisposition = 0x01; /* got this value from windows */
|
2013-03-19 06:43:20 +04:00
|
|
|
|
|
|
|
rval = dev_redir_send_drive_create_request(device_id, path,
|
|
|
|
DesiredAccess, CreateOptions,
|
|
|
|
CreateDisposition,
|
2013-05-16 04:06:05 +04:00
|
|
|
irp->CompletionId);
|
2013-03-19 06:43:20 +04:00
|
|
|
|
|
|
|
return rval;
|
|
|
|
}
|
|
|
|
|
2013-03-09 03:37:30 +04:00
|
|
|
/**
|
|
|
|
* Read data from previously opened file
|
|
|
|
*
|
|
|
|
* @return 0 on success, -1 on failure
|
|
|
|
*****************************************************************************/
|
|
|
|
|
2017-03-12 19:35:00 +03:00
|
|
|
int
|
2013-07-24 07:57:38 +04:00
|
|
|
devredir_file_read(void *fusep, tui32 DeviceId, tui32 FileId,
|
|
|
|
tui32 Length, tui64 Offset)
|
2013-03-09 03:37:30 +04:00
|
|
|
{
|
|
|
|
struct stream *s;
|
|
|
|
IRP *irp;
|
2013-06-03 02:33:51 +04:00
|
|
|
IRP *new_irp;
|
2013-03-09 03:37:30 +04:00
|
|
|
int bytes;
|
|
|
|
|
2013-05-03 13:25:13 +04:00
|
|
|
xstream_new(s, 1024);
|
2013-03-09 03:37:30 +04:00
|
|
|
|
2013-05-16 04:06:05 +04:00
|
|
|
if ((irp = devredir_irp_find_by_fileid(FileId)) == NULL)
|
2013-03-09 03:37:30 +04:00
|
|
|
{
|
|
|
|
log_error("no IRP found with FileId = %d", FileId);
|
|
|
|
xfuse_devredir_cb_read_file(fusep, NULL, 0);
|
2014-07-19 22:56:00 +04:00
|
|
|
xstream_free(s);
|
2013-03-09 03:37:30 +04:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2013-06-03 02:33:51 +04:00
|
|
|
/* create a new IRP for this request */
|
|
|
|
if ((new_irp = devredir_irp_clone(irp)) == NULL)
|
|
|
|
{
|
|
|
|
/* system out of memory */
|
|
|
|
xfuse_devredir_cb_read_file(fusep, NULL, 0);
|
2014-07-19 22:56:00 +04:00
|
|
|
xstream_free(s);
|
2013-06-03 02:33:51 +04:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
new_irp->FileId = 0;
|
|
|
|
new_irp->completion_type = CID_READ;
|
|
|
|
new_irp->CompletionId = g_completion_id++;
|
|
|
|
devredir_fuse_data_enqueue(new_irp, fusep);
|
|
|
|
|
2013-05-16 04:06:05 +04:00
|
|
|
devredir_insert_DeviceIoRequest(s,
|
|
|
|
DeviceId,
|
|
|
|
FileId,
|
2013-06-03 02:33:51 +04:00
|
|
|
new_irp->CompletionId,
|
2013-05-16 04:06:05 +04:00
|
|
|
IRP_MJ_READ,
|
|
|
|
0);
|
2013-03-09 03:37:30 +04:00
|
|
|
|
2013-05-03 13:25:13 +04:00
|
|
|
xstream_wr_u32_le(s, Length);
|
|
|
|
xstream_wr_u64_le(s, Offset);
|
|
|
|
xstream_seek(s, 20);
|
2013-03-09 03:37:30 +04:00
|
|
|
|
|
|
|
/* send to client */
|
2013-05-03 13:25:13 +04:00
|
|
|
bytes = xstream_len(s);
|
2013-03-09 03:37:30 +04:00
|
|
|
send_channel_data(g_rdpdr_chan_id, s->data, bytes);
|
2013-05-03 13:25:13 +04:00
|
|
|
xstream_free(s);
|
2013-03-09 03:37:30 +04:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-03-12 19:35:00 +03:00
|
|
|
int
|
2013-07-24 07:57:38 +04:00
|
|
|
dev_redir_file_write(void *fusep, tui32 DeviceId, tui32 FileId,
|
2016-06-22 02:30:19 +03:00
|
|
|
const char *buf, int Length, tui64 Offset)
|
2013-03-09 03:37:30 +04:00
|
|
|
{
|
|
|
|
struct stream *s;
|
|
|
|
IRP *irp;
|
2013-06-03 02:33:51 +04:00
|
|
|
IRP *new_irp;
|
2013-03-09 03:37:30 +04:00
|
|
|
int bytes;
|
|
|
|
|
2017-01-28 00:07:36 +03:00
|
|
|
log_debug("DeviceId=%d FileId=%d Length=%d Offset=%lld",
|
|
|
|
DeviceId, FileId, Length, (long long)Offset);
|
2013-05-06 05:42:17 +04:00
|
|
|
|
2013-05-03 13:25:13 +04:00
|
|
|
xstream_new(s, 1024 + Length);
|
2013-03-09 03:37:30 +04:00
|
|
|
|
2013-05-16 04:06:05 +04:00
|
|
|
if ((irp = devredir_irp_find_by_fileid(FileId)) == NULL)
|
2013-03-09 03:37:30 +04:00
|
|
|
{
|
|
|
|
log_error("no IRP found with FileId = %d", FileId);
|
2019-03-13 13:56:37 +03:00
|
|
|
xfuse_devredir_cb_write_file(fusep, NT_STATUS_UNSUCCESSFUL, NULL, 0);
|
2014-07-19 22:56:00 +04:00
|
|
|
xstream_free(s);
|
2013-03-09 03:37:30 +04:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2013-06-03 02:33:51 +04:00
|
|
|
/* create a new IRP for this request */
|
|
|
|
if ((new_irp = devredir_irp_clone(irp)) == NULL)
|
|
|
|
{
|
|
|
|
/* system out of memory */
|
2019-03-13 13:56:37 +03:00
|
|
|
xfuse_devredir_cb_write_file(fusep, NT_STATUS_UNSUCCESSFUL, NULL, 0);
|
2014-07-19 22:56:00 +04:00
|
|
|
xstream_free(s);
|
2013-06-03 02:33:51 +04:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
new_irp->FileId = 0;
|
|
|
|
new_irp->completion_type = CID_WRITE;
|
|
|
|
new_irp->CompletionId = g_completion_id++;
|
|
|
|
devredir_fuse_data_enqueue(new_irp, fusep);
|
|
|
|
|
2013-05-16 04:06:05 +04:00
|
|
|
devredir_insert_DeviceIoRequest(s,
|
|
|
|
DeviceId,
|
|
|
|
FileId,
|
2013-06-03 02:33:51 +04:00
|
|
|
new_irp->CompletionId,
|
2013-05-16 04:06:05 +04:00
|
|
|
IRP_MJ_WRITE,
|
|
|
|
0);
|
2013-03-09 03:37:30 +04:00
|
|
|
|
2013-05-03 13:25:13 +04:00
|
|
|
xstream_wr_u32_le(s, Length);
|
|
|
|
xstream_wr_u64_le(s, Offset);
|
|
|
|
xstream_seek(s, 20); /* padding */
|
2013-03-09 03:37:30 +04:00
|
|
|
|
|
|
|
/* now insert real data */
|
2013-05-03 13:25:13 +04:00
|
|
|
xstream_copyin(s, buf, Length);
|
2013-03-09 03:37:30 +04:00
|
|
|
|
|
|
|
/* send to client */
|
2013-05-03 13:25:13 +04:00
|
|
|
bytes = xstream_len(s);
|
2013-03-09 03:37:30 +04:00
|
|
|
send_channel_data(g_rdpdr_chan_id, s->data, bytes);
|
2013-05-03 13:25:13 +04:00
|
|
|
xstream_free(s);
|
2013-03-09 03:37:30 +04:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
** FIFO for FUSE_DATA **
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return FUSE_DATA at the head of the queue without removing it
|
|
|
|
*
|
|
|
|
* @return FUSE_DATA on success, or NULL on failure
|
|
|
|
*****************************************************************************/
|
|
|
|
|
2017-03-12 19:35:00 +03:00
|
|
|
FUSE_DATA *
|
2013-07-24 07:57:38 +04:00
|
|
|
devredir_fuse_data_peek(IRP *irp)
|
2013-03-09 03:37:30 +04:00
|
|
|
{
|
2013-05-19 06:44:16 +04:00
|
|
|
log_debug("returning %p", irp->fd_head);
|
2013-03-09 03:37:30 +04:00
|
|
|
return irp->fd_head;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return oldest FUSE_DATA from queue
|
|
|
|
*
|
|
|
|
* @return FUSE_DATA on success, NULL on failure
|
|
|
|
*****************************************************************************/
|
|
|
|
|
2017-03-12 19:35:00 +03:00
|
|
|
FUSE_DATA *
|
2013-07-24 07:57:38 +04:00
|
|
|
devredir_fuse_data_dequeue(IRP *irp)
|
2013-03-09 03:37:30 +04:00
|
|
|
{
|
|
|
|
FUSE_DATA *head;
|
|
|
|
|
|
|
|
if ((irp == NULL) || (irp->fd_head == NULL))
|
2013-05-19 06:44:16 +04:00
|
|
|
{
|
|
|
|
log_debug("+++ returning NULL");
|
2013-03-09 03:37:30 +04:00
|
|
|
return NULL;
|
2013-05-19 06:44:16 +04:00
|
|
|
}
|
2013-03-09 03:37:30 +04:00
|
|
|
|
|
|
|
if (irp->fd_head->next == NULL)
|
|
|
|
{
|
|
|
|
/* only one element in queue */
|
|
|
|
head = irp->fd_head;
|
|
|
|
irp->fd_head = NULL;
|
|
|
|
irp->fd_tail = NULL;
|
2013-05-19 06:44:16 +04:00
|
|
|
log_debug("+++ returning FUSE_DATA=%p containing FUSE_INFO=%p",
|
|
|
|
head, head->data_ptr);
|
2013-03-09 03:37:30 +04:00
|
|
|
return head;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* more than one element in queue */
|
|
|
|
head = irp->fd_head;
|
|
|
|
irp->fd_head = head->next;
|
2013-05-19 06:44:16 +04:00
|
|
|
log_debug("+++ returning FUSE_DATA=%p containing FUSE_INFO=%p",
|
|
|
|
head, head->data_ptr);
|
2013-03-09 03:37:30 +04:00
|
|
|
return head;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Insert specified FUSE_DATA at the end of our queue
|
|
|
|
*
|
|
|
|
* @return 0 on success, -1 on failure
|
|
|
|
*****************************************************************************/
|
|
|
|
|
2017-03-12 19:35:00 +03:00
|
|
|
int
|
2013-07-24 07:57:38 +04:00
|
|
|
devredir_fuse_data_enqueue(IRP *irp, void *vp)
|
2013-03-09 03:37:30 +04:00
|
|
|
{
|
|
|
|
FUSE_DATA *fd;
|
|
|
|
FUSE_DATA *tail;
|
|
|
|
|
|
|
|
if (irp == NULL)
|
|
|
|
return -1;
|
|
|
|
|
2016-06-22 02:30:18 +03:00
|
|
|
fd = g_new0(FUSE_DATA, 1);
|
|
|
|
if (fd == NULL)
|
2013-03-09 03:37:30 +04:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
fd->data_ptr = vp;
|
|
|
|
fd->next = NULL;
|
|
|
|
|
|
|
|
if (irp->fd_tail == NULL)
|
|
|
|
{
|
|
|
|
/* queue is empty, insert at head */
|
|
|
|
irp->fd_head = fd;
|
|
|
|
irp->fd_tail = fd;
|
2013-05-19 06:44:16 +04:00
|
|
|
log_debug("+++ inserted FUSE_DATA=%p containing FUSE_INFO=%p at head",
|
|
|
|
fd, vp);
|
2013-03-09 03:37:30 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* queue is not empty, insert at tail end */
|
|
|
|
tail = irp->fd_tail;
|
|
|
|
tail->next = fd;
|
|
|
|
irp->fd_tail = fd;
|
2013-05-19 06:44:16 +04:00
|
|
|
log_debug("+++ inserted FUSE_DATA=%p containing FUSE_INFO=%p at tail",
|
|
|
|
fd, vp);
|
2013-03-09 03:37:30 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
** miscellaneous stuff **
|
|
|
|
******************************************************************************/
|
|
|
|
|
2017-03-12 19:35:00 +03:00
|
|
|
void
|
2013-07-24 07:57:38 +04:00
|
|
|
devredir_insert_DeviceIoRequest(struct stream *s,
|
|
|
|
tui32 DeviceId,
|
|
|
|
tui32 FileId,
|
|
|
|
tui32 CompletionId,
|
|
|
|
tui32 MajorFunction,
|
|
|
|
tui32 MinorFunction)
|
2013-03-09 03:37:30 +04:00
|
|
|
{
|
|
|
|
/* setup DR_DEVICE_IOREQUEST header */
|
2013-05-03 13:25:13 +04:00
|
|
|
xstream_wr_u16_le(s, RDPDR_CTYP_CORE);
|
|
|
|
xstream_wr_u16_le(s, PAKID_CORE_DEVICE_IOREQUEST);
|
|
|
|
xstream_wr_u32_le(s, DeviceId);
|
|
|
|
xstream_wr_u32_le(s, FileId);
|
|
|
|
xstream_wr_u32_le(s, CompletionId);
|
|
|
|
xstream_wr_u32_le(s, MajorFunction);
|
|
|
|
xstream_wr_u32_le(s, MinorFunction);
|
2013-03-09 03:37:30 +04:00
|
|
|
}
|
|
|
|
|
2013-04-21 03:42:49 +04:00
|
|
|
/**
|
|
|
|
* Convert / to windows compatible \
|
|
|
|
*****************************************************************************/
|
|
|
|
|
2017-03-12 19:35:00 +03:00
|
|
|
void
|
2013-07-24 07:57:38 +04:00
|
|
|
devredir_cvt_slash(char *path)
|
2013-04-21 03:42:49 +04:00
|
|
|
{
|
|
|
|
char *cptr = path;
|
|
|
|
|
|
|
|
while (*cptr != 0)
|
|
|
|
{
|
|
|
|
if (*cptr == '/')
|
|
|
|
*cptr = '\\';
|
|
|
|
cptr++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-12 19:35:00 +03:00
|
|
|
void
|
2016-11-16 07:04:59 +03:00
|
|
|
devredir_cvt_to_unicode(char *unicode, const char *path)
|
2013-03-09 03:37:30 +04:00
|
|
|
{
|
2013-06-09 05:44:21 +04:00
|
|
|
char *dest;
|
|
|
|
char *src;
|
|
|
|
int rv;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
rv = g_mbstowcs((twchar *) unicode, path, strlen(path));
|
2013-03-09 03:37:30 +04:00
|
|
|
|
2013-06-09 05:44:21 +04:00
|
|
|
/* unicode is typically 4 bytes, but microsoft only uses 2 bytes */
|
|
|
|
|
|
|
|
src = unicode + sizeof(twchar); /* skip 1st unicode char */
|
|
|
|
dest = unicode + 2; /* first char already in place */
|
|
|
|
|
|
|
|
for (i = 1; i < rv; i++)
|
2013-03-09 03:37:30 +04:00
|
|
|
{
|
2013-06-09 05:44:21 +04:00
|
|
|
*dest++ = *src++;
|
|
|
|
*dest++ = *src++;
|
|
|
|
src += 2;
|
2013-03-09 03:37:30 +04:00
|
|
|
}
|
2013-06-09 05:44:21 +04:00
|
|
|
|
|
|
|
*dest++ = 0;
|
|
|
|
*dest++ = 0;
|
2013-03-09 03:37:30 +04:00
|
|
|
}
|
|
|
|
|
2017-03-12 19:35:00 +03:00
|
|
|
void
|
2013-07-24 07:57:38 +04:00
|
|
|
devredir_cvt_from_unicode_len(char *path, char *unicode, int len)
|
2013-03-09 03:37:30 +04:00
|
|
|
{
|
2013-06-09 05:44:21 +04:00
|
|
|
char *dest;
|
|
|
|
char *dest_saved;
|
|
|
|
char *src;
|
|
|
|
int i;
|
|
|
|
int bytes_to_alloc;
|
|
|
|
int max_bytes;
|
2013-03-09 03:37:30 +04:00
|
|
|
|
2013-06-09 05:44:21 +04:00
|
|
|
bytes_to_alloc = (((len / 2) * sizeof(twchar)) + sizeof(twchar));
|
|
|
|
|
|
|
|
src = unicode;
|
2016-06-22 02:30:18 +03:00
|
|
|
dest = g_new0(char, bytes_to_alloc);
|
2013-06-09 05:44:21 +04:00
|
|
|
dest_saved = dest;
|
|
|
|
|
|
|
|
for (i = 0; i < len; i += 2)
|
|
|
|
{
|
|
|
|
*dest++ = *src++;
|
|
|
|
*dest++ = *src++;
|
|
|
|
dest += 2;
|
|
|
|
}
|
|
|
|
*dest++ = 0;
|
|
|
|
*dest++ = 0;
|
|
|
|
*dest++ = 0;
|
|
|
|
*dest++ = 0;
|
|
|
|
|
|
|
|
max_bytes = wcstombs(NULL, (wchar_t *) dest_saved, 0);
|
|
|
|
if (max_bytes > 0)
|
2013-03-09 03:37:30 +04:00
|
|
|
{
|
2016-05-07 04:47:15 +03:00
|
|
|
wcstombs(path, (wchar_t *) dest_saved, max_bytes);
|
2013-06-09 05:44:21 +04:00
|
|
|
path[max_bytes] = 0;
|
2013-03-09 03:37:30 +04:00
|
|
|
}
|
2013-06-09 05:44:21 +04:00
|
|
|
|
|
|
|
g_free(dest_saved);
|
2013-03-09 03:37:30 +04:00
|
|
|
}
|
|
|
|
|
2017-03-12 19:35:00 +03:00
|
|
|
int
|
2019-03-12 15:16:50 +03:00
|
|
|
dev_redir_string_ends_with(const char *string, char c)
|
2013-03-09 03:37:30 +04:00
|
|
|
{
|
2019-03-12 15:16:50 +03:00
|
|
|
size_t len;
|
2013-03-09 03:37:30 +04:00
|
|
|
|
|
|
|
len = strlen(string);
|
2019-03-12 15:16:50 +03:00
|
|
|
return (len > 0 && string[len - 1] == c) ? 1 : 0;
|
2013-03-09 03:37:30 +04:00
|
|
|
}
|
|
|
|
|
2017-03-12 19:35:00 +03:00
|
|
|
void
|
2013-07-24 07:57:38 +04:00
|
|
|
devredir_insert_RDPDR_header(struct stream *s, tui16 Component,
|
|
|
|
tui16 PacketId)
|
2013-03-09 03:37:30 +04:00
|
|
|
{
|
2013-05-03 13:25:13 +04:00
|
|
|
xstream_wr_u16_le(s, Component);
|
|
|
|
xstream_wr_u16_le(s, PacketId);
|
2013-03-09 03:37:30 +04:00
|
|
|
}
|
2013-03-19 06:43:20 +04:00
|
|
|
|
2019-03-12 15:16:50 +03:00
|
|
|
static void
|
2013-07-24 07:57:38 +04:00
|
|
|
devredir_proc_cid_rmdir_or_file(IRP *irp, tui32 IoStatus)
|
2013-03-19 06:43:20 +04:00
|
|
|
{
|
|
|
|
struct stream *s;
|
|
|
|
int bytes;
|
|
|
|
|
|
|
|
if (IoStatus != NT_STATUS_SUCCESS)
|
|
|
|
{
|
2013-05-19 06:44:16 +04:00
|
|
|
FUSE_DATA *fuse_data = devredir_fuse_data_dequeue(irp);
|
2013-03-19 06:43:20 +04:00
|
|
|
if (fuse_data)
|
|
|
|
{
|
|
|
|
xfuse_devredir_cb_rmdir_or_file(fuse_data->data_ptr, IoStatus);
|
|
|
|
free(fuse_data);
|
|
|
|
}
|
2013-05-16 04:06:05 +04:00
|
|
|
devredir_irp_delete(irp);
|
2013-03-19 06:43:20 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-05-03 13:25:13 +04:00
|
|
|
xstream_new(s, 1024);
|
2013-03-19 06:43:20 +04:00
|
|
|
|
|
|
|
irp->completion_type = CID_RMDIR_OR_FILE_RESP;
|
2013-05-16 04:06:05 +04:00
|
|
|
devredir_insert_DeviceIoRequest(s, irp->DeviceId, irp->FileId,
|
|
|
|
irp->CompletionId,
|
|
|
|
IRP_MJ_SET_INFORMATION, 0);
|
2013-03-19 06:43:20 +04:00
|
|
|
|
2013-05-03 13:25:13 +04:00
|
|
|
xstream_wr_u32_le(s, FileDispositionInformation);
|
|
|
|
xstream_wr_u32_le(s, 0); /* length is zero */
|
|
|
|
xstream_seek(s, 24); /* padding */
|
2013-03-19 06:43:20 +04:00
|
|
|
|
|
|
|
/* send to client */
|
2013-05-03 13:25:13 +04:00
|
|
|
bytes = xstream_len(s);
|
2013-03-19 06:43:20 +04:00
|
|
|
send_channel_data(g_rdpdr_chan_id, s->data, bytes);
|
2013-05-03 13:25:13 +04:00
|
|
|
xstream_free(s);
|
2013-03-19 06:43:20 +04:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-03-12 15:16:50 +03:00
|
|
|
static void
|
2013-07-24 07:57:38 +04:00
|
|
|
devredir_proc_cid_rmdir_or_file_resp(IRP *irp, tui32 IoStatus)
|
2013-03-19 06:43:20 +04:00
|
|
|
{
|
|
|
|
FUSE_DATA *fuse_data;
|
|
|
|
|
2013-05-19 06:44:16 +04:00
|
|
|
fuse_data = devredir_fuse_data_dequeue(irp);
|
2013-03-19 06:43:20 +04:00
|
|
|
if (fuse_data)
|
|
|
|
{
|
|
|
|
xfuse_devredir_cb_rmdir_or_file(fuse_data->data_ptr, IoStatus);
|
|
|
|
free(fuse_data);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (IoStatus != NT_STATUS_SUCCESS)
|
|
|
|
{
|
2013-05-16 04:06:05 +04:00
|
|
|
devredir_irp_delete(irp);
|
2013-03-19 06:43:20 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
irp->completion_type = CID_CLOSE;
|
|
|
|
dev_redir_send_drive_close_request(RDPDR_CTYP_CORE,
|
|
|
|
PAKID_CORE_DEVICE_IOREQUEST,
|
2013-05-16 04:06:05 +04:00
|
|
|
irp->DeviceId,
|
2013-03-19 06:43:20 +04:00
|
|
|
irp->FileId,
|
2013-05-16 04:06:05 +04:00
|
|
|
irp->CompletionId,
|
2013-03-19 06:43:20 +04:00
|
|
|
IRP_MJ_CLOSE, 0, 32);
|
|
|
|
}
|
2013-03-24 23:08:55 +04:00
|
|
|
|
2019-03-12 15:16:50 +03:00
|
|
|
static void
|
2013-07-24 07:57:38 +04:00
|
|
|
devredir_proc_cid_rename_file(IRP *irp, tui32 IoStatus)
|
2013-03-24 23:08:55 +04:00
|
|
|
{
|
|
|
|
struct stream *s;
|
|
|
|
int bytes;
|
|
|
|
int sblen; /* SetBuffer length */
|
2013-06-09 05:44:21 +04:00
|
|
|
int flen; /* FileNameLength */
|
2013-03-24 23:08:55 +04:00
|
|
|
|
|
|
|
|
|
|
|
if (IoStatus != NT_STATUS_SUCCESS)
|
|
|
|
{
|
2013-05-06 05:42:17 +04:00
|
|
|
log_debug("rename returned with IoStatus=0x%x", IoStatus);
|
|
|
|
|
2013-05-19 06:44:16 +04:00
|
|
|
FUSE_DATA *fuse_data = devredir_fuse_data_dequeue(irp);
|
2013-03-24 23:08:55 +04:00
|
|
|
if (fuse_data)
|
|
|
|
{
|
|
|
|
xfuse_devredir_cb_rename_file(fuse_data->data_ptr, IoStatus);
|
|
|
|
free(fuse_data);
|
|
|
|
}
|
2013-05-16 04:06:05 +04:00
|
|
|
devredir_irp_delete(irp);
|
2013-03-24 23:08:55 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-06-09 05:44:21 +04:00
|
|
|
/* Path in unicode needs this much space */
|
2019-03-21 19:48:01 +03:00
|
|
|
flen = ((g_mbstowcs(NULL, irp->gen.buf, 0) * sizeof(twchar)) / 2) + 2;
|
2013-06-09 05:44:21 +04:00
|
|
|
sblen = 6 + flen;
|
|
|
|
|
|
|
|
xstream_new(s, 1024 + flen);
|
2013-03-24 23:08:55 +04:00
|
|
|
|
|
|
|
irp->completion_type = CID_RENAME_FILE_RESP;
|
2013-05-16 04:06:05 +04:00
|
|
|
devredir_insert_DeviceIoRequest(s, irp->DeviceId, irp->FileId,
|
|
|
|
irp->CompletionId,
|
|
|
|
IRP_MJ_SET_INFORMATION, 0);
|
2013-03-24 23:08:55 +04:00
|
|
|
|
2013-05-03 13:25:13 +04:00
|
|
|
xstream_wr_u32_le(s, FileRenameInformation);
|
2013-06-09 05:44:21 +04:00
|
|
|
xstream_wr_u32_le(s, sblen); /* number of bytes after padding */
|
|
|
|
xstream_seek(s, 24); /* padding */
|
|
|
|
xstream_wr_u8(s, 1); /* ReplaceIfExists */
|
|
|
|
xstream_wr_u8(s, 0); /* RootDirectory */
|
|
|
|
xstream_wr_u32_le(s, flen); /* FileNameLength */
|
2013-03-24 23:08:55 +04:00
|
|
|
|
|
|
|
/* filename in unicode */
|
2019-03-21 19:48:01 +03:00
|
|
|
devredir_cvt_to_unicode(s->p, irp->gen.buf); /* UNICODE_TODO */
|
2013-05-03 13:25:13 +04:00
|
|
|
xstream_seek(s, flen);
|
2013-03-24 23:08:55 +04:00
|
|
|
|
|
|
|
/* send to client */
|
2013-05-03 13:25:13 +04:00
|
|
|
bytes = xstream_len(s);
|
2013-03-24 23:08:55 +04:00
|
|
|
send_channel_data(g_rdpdr_chan_id, s->data, bytes);
|
2013-05-03 13:25:13 +04:00
|
|
|
xstream_free(s);
|
2013-03-24 23:08:55 +04:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-03-12 15:16:50 +03:00
|
|
|
static void
|
2013-07-24 07:57:38 +04:00
|
|
|
devredir_proc_cid_rename_file_resp(IRP *irp, tui32 IoStatus)
|
2013-03-24 23:08:55 +04:00
|
|
|
{
|
|
|
|
FUSE_DATA *fuse_data;
|
|
|
|
|
2013-05-06 05:42:17 +04:00
|
|
|
log_debug("entered");
|
|
|
|
|
2013-05-19 06:44:16 +04:00
|
|
|
fuse_data = devredir_fuse_data_dequeue(irp);
|
2013-03-24 23:08:55 +04:00
|
|
|
if (fuse_data)
|
|
|
|
{
|
|
|
|
xfuse_devredir_cb_rename_file(fuse_data->data_ptr, IoStatus);
|
|
|
|
free(fuse_data);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (IoStatus != NT_STATUS_SUCCESS)
|
|
|
|
{
|
2013-05-16 04:06:05 +04:00
|
|
|
devredir_irp_delete(irp);
|
2013-03-24 23:08:55 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
irp->completion_type = CID_CLOSE;
|
|
|
|
dev_redir_send_drive_close_request(RDPDR_CTYP_CORE,
|
|
|
|
PAKID_CORE_DEVICE_IOREQUEST,
|
2013-05-16 04:06:05 +04:00
|
|
|
irp->DeviceId,
|
2013-03-24 23:08:55 +04:00
|
|
|
irp->FileId,
|
2013-05-16 04:06:05 +04:00
|
|
|
irp->CompletionId,
|
2013-03-24 23:08:55 +04:00
|
|
|
IRP_MJ_CLOSE, 0, 32);
|
|
|
|
}
|
2019-03-21 19:48:01 +03:00
|
|
|
|
|
|
|
static void
|
|
|
|
devredir_proc_cid_lookup_basic_entry(IRP *irp, tui32 IoStatus)
|
|
|
|
{
|
|
|
|
struct stream *s;
|
|
|
|
int bytes;
|
|
|
|
|
|
|
|
if (IoStatus != NT_STATUS_SUCCESS)
|
|
|
|
{
|
|
|
|
log_debug("lookup returned with IoStatus=0x%08x", IoStatus);
|
|
|
|
|
|
|
|
FUSE_DATA *fuse_data = devredir_fuse_data_dequeue(irp);
|
|
|
|
if (fuse_data)
|
|
|
|
{
|
|
|
|
xfuse_devredir_cb_lookup_entry(fuse_data->data_ptr, IoStatus, NULL);
|
|
|
|
free(fuse_data);
|
|
|
|
}
|
|
|
|
devredir_irp_delete(irp);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
xstream_new(s, 1024);
|
|
|
|
|
|
|
|
irp->completion_type = CID_LOOKUP_STD_ENTRY;
|
|
|
|
devredir_insert_DeviceIoRequest(s, irp->DeviceId, irp->FileId,
|
|
|
|
irp->CompletionId,
|
|
|
|
IRP_MJ_QUERY_INFORMATION, 0);
|
|
|
|
|
|
|
|
xstream_wr_u32_le(s, FileBasicInformation);
|
|
|
|
xstream_wr_u32_le(s, FILE_BASIC_INFORMATION_SIZE);
|
|
|
|
/* buffer length */
|
|
|
|
xstream_seek(s, 24); /* padding */
|
|
|
|
xstream_seek(s, FILE_BASIC_INFORMATION_SIZE);
|
|
|
|
/* buffer */
|
|
|
|
/* send to client */
|
|
|
|
bytes = xstream_len(s);
|
|
|
|
send_channel_data(g_rdpdr_chan_id, s->data, bytes);
|
|
|
|
xstream_free(s);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
devredir_proc_cid_lookup_basic_entry_resp(IRP *irp,
|
|
|
|
struct stream *s_in,
|
|
|
|
tui32 IoStatus)
|
|
|
|
{
|
|
|
|
tui32 Length = 0;
|
|
|
|
tui64 CreationTime;
|
|
|
|
tui64 LastAccessTime;
|
|
|
|
tui64 LastWriteTime;
|
|
|
|
tui32 FileAttributes;
|
|
|
|
|
|
|
|
log_debug("basic_lookup returned with IoStatus=0x%08x", IoStatus);
|
|
|
|
|
|
|
|
/* Data as we expect? */
|
|
|
|
if (IoStatus == NT_STATUS_SUCCESS)
|
|
|
|
{
|
|
|
|
xstream_rd_u32_le(s_in, Length);
|
|
|
|
if (Length != FILE_BASIC_INFORMATION_SIZE)
|
|
|
|
{
|
|
|
|
log_error("Expected FILE_BASIC_OPEN_INFORMATION data but len=%d",
|
|
|
|
Length);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (IoStatus != NT_STATUS_SUCCESS ||
|
|
|
|
Length != FILE_BASIC_INFORMATION_SIZE)
|
|
|
|
{
|
|
|
|
/* Return a lookup fail to the FUSE caller */
|
|
|
|
FUSE_DATA *fuse_data = devredir_fuse_data_dequeue(irp);
|
|
|
|
if (fuse_data)
|
|
|
|
{
|
|
|
|
xfuse_devredir_cb_lookup_entry(fuse_data->data_ptr, IoStatus, NULL);
|
|
|
|
free(fuse_data);
|
|
|
|
}
|
|
|
|
devredir_irp_delete(irp);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
log_debug("processing FILE_BASIC_INFORMATION");
|
|
|
|
|
|
|
|
xstream_rd_u64_le(s_in, CreationTime);
|
|
|
|
xstream_rd_u64_le(s_in, LastAccessTime);
|
|
|
|
xstream_rd_u64_le(s_in, LastWriteTime);
|
|
|
|
xstream_seek(s_in, 8); /* ChangeTime */
|
|
|
|
xstream_rd_u32_le(s_in, FileAttributes);
|
|
|
|
|
|
|
|
//log_debug("CreationTime: 0x%llx",
|
|
|
|
// (unsigned long long)CreationTime);
|
|
|
|
//log_debug("LastAccessTime: 0x%llx",
|
|
|
|
// (unsigned long long)LastAccessTime);
|
|
|
|
//log_debug("LastWriteTime: 0x%llx",
|
|
|
|
// (unsigned long long)LastWriteTime);
|
|
|
|
//log_debug("FileAttributes: 0x%x", (unsigned int)FileAttributes);
|
|
|
|
|
|
|
|
/* Save the basic attributes in the IRP */
|
|
|
|
irp->gen.fattr.mode = WINDOWS_TO_LINUX_FILE_PERM(FileAttributes);
|
|
|
|
irp->gen.fattr.atime = WINDOWS_TO_LINUX_TIME(LastAccessTime);
|
|
|
|
irp->gen.fattr.mtime = WINDOWS_TO_LINUX_TIME(LastWriteTime);
|
|
|
|
irp->gen.fattr.ctime = WINDOWS_TO_LINUX_TIME(CreationTime);
|
|
|
|
|
|
|
|
/* Re-use the IRP to lookup the FileStandardInformation */
|
|
|
|
lookup_std_entry(irp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
lookup_std_entry(IRP *irp)
|
|
|
|
{
|
|
|
|
struct stream *s;
|
|
|
|
int bytes;
|
|
|
|
|
|
|
|
xstream_new(s, 1024);
|
|
|
|
|
|
|
|
irp->completion_type = CID_LOOKUP_ENTRY_RESP;
|
|
|
|
devredir_insert_DeviceIoRequest(s, irp->DeviceId, irp->FileId,
|
|
|
|
irp->CompletionId,
|
|
|
|
IRP_MJ_QUERY_INFORMATION, 0);
|
|
|
|
|
|
|
|
xstream_wr_u32_le(s, FileStandardInformation);
|
|
|
|
xstream_wr_u32_le(s, FILE_STD_INFORMATION_SIZE);
|
|
|
|
/* buffer length */
|
|
|
|
xstream_seek(s, 24); /* padding */
|
|
|
|
xstream_seek(s, FILE_STD_INFORMATION_SIZE);
|
|
|
|
/* buffer */
|
|
|
|
/* send to client */
|
|
|
|
bytes = xstream_len(s);
|
|
|
|
send_channel_data(g_rdpdr_chan_id, s->data, bytes);
|
|
|
|
xstream_free(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
devredir_proc_cid_lookup_std_entry_resp(IRP *irp,
|
|
|
|
struct stream *s_in,
|
|
|
|
tui32 DeviceId,
|
|
|
|
tui32 CompletionId,
|
|
|
|
tui32 IoStatus)
|
|
|
|
{
|
|
|
|
FUSE_DATA *fuse_data;
|
|
|
|
tui32 Length;
|
|
|
|
tui64 EndOfFile;
|
|
|
|
struct xrdp_inode *xinode = NULL;
|
|
|
|
|
|
|
|
fuse_data = devredir_fuse_data_dequeue(irp);
|
|
|
|
if (!fuse_data)
|
|
|
|
{
|
|
|
|
log_error("fuse_data unexpectedly NULL!");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (IoStatus == NT_STATUS_SUCCESS)
|
|
|
|
{
|
|
|
|
/* Data as we expect? */
|
|
|
|
xstream_rd_u32_le(s_in, Length);
|
|
|
|
if (Length != FILE_STD_INFORMATION_SIZE)
|
|
|
|
{
|
|
|
|
log_error("Expected FILE_STD_OPEN_INFORMATION data but len=%d",
|
|
|
|
Length);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
log_debug("processing FILE_STD_INFORMATION");
|
|
|
|
xstream_seek(s_in, 8); /* AllocationSize */
|
|
|
|
xstream_rd_u64_le(s_in, EndOfFile);
|
|
|
|
//log_debug("EndOfFile: %lld",
|
|
|
|
// (unsigned long long)EndOfFile);
|
|
|
|
|
|
|
|
/* Finish the attribute block off and add the file */
|
|
|
|
irp->gen.fattr.size = EndOfFile;
|
|
|
|
irp->gen.fattr.name = strrchr(irp->pathname,'\\') + 1;
|
|
|
|
|
|
|
|
xinode = xfuse_devredir_add_file_or_dir(fuse_data->data_ptr,
|
|
|
|
&irp->gen.fattr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
xfuse_devredir_cb_lookup_entry(fuse_data->data_ptr, IoStatus, xinode);
|
|
|
|
free(fuse_data);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Close the file handle */
|
|
|
|
irp->completion_type = CID_CLOSE;
|
|
|
|
dev_redir_send_drive_close_request(RDPDR_CTYP_CORE,
|
|
|
|
PAKID_CORE_DEVICE_IOREQUEST,
|
|
|
|
irp->DeviceId,
|
|
|
|
irp->FileId,
|
|
|
|
irp->CompletionId,
|
|
|
|
IRP_MJ_CLOSE, 0, 32);
|
|
|
|
}
|