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"
|
2020-12-21 15:36:00 +03:00
|
|
|
#include "string_calls.h"
|
2013-05-16 04:06:05 +04:00
|
|
|
#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"
|
2019-11-14 17:43:57 +03:00
|
|
|
#include "ms-rdpefs.h"
|
|
|
|
#include "ms-smb2.h"
|
|
|
|
#include "ms-fscc.h"
|
|
|
|
#include "ms-erref.h"
|
2013-05-16 04:06:05 +04:00
|
|
|
|
2009-04-22 08:34:45 +04:00
|
|
|
|
2019-11-14 17:43:57 +03:00
|
|
|
/* client minor versions */
|
|
|
|
#define RDP_CLIENT_50 0x0002
|
|
|
|
#define RDP_CLIENT_51 0x0005
|
|
|
|
#define RDP_CLIENT_52 0x000a
|
|
|
|
#define RDP_CLIENT_60_61 0x000c
|
|
|
|
|
|
|
|
/* Windows time starts on Jan 1, 1601 */
|
|
|
|
/* Linux time starts on Jan 1, 1970 */
|
|
|
|
#define EPOCH_DIFF 11644473600LL
|
|
|
|
#define WINDOWS_TO_LINUX_TIME(_t) (((_t) / 10000000) - EPOCH_DIFF);
|
|
|
|
#define LINUX_TO_WINDOWS_TIME(_t) (((_t) + EPOCH_DIFF) * 10000000)
|
|
|
|
|
2019-03-21 19:48:01 +03:00
|
|
|
/*
|
2019-11-14 17:43:57 +03:00
|
|
|
* CompletionID types, used in IRPs to indicate I/O operation
|
2019-03-21 19:48:01 +03:00
|
|
|
*/
|
2019-11-14 17:43:57 +03:00
|
|
|
|
|
|
|
enum COMPLETION_TYPE
|
|
|
|
{
|
|
|
|
CID_CREATE_DIR_REQ = 1,
|
|
|
|
CID_DIRECTORY_CONTROL,
|
|
|
|
CID_CREATE_REQ,
|
|
|
|
CID_OPEN_REQ,
|
|
|
|
CID_READ,
|
|
|
|
CID_WRITE,
|
|
|
|
CID_CLOSE,
|
|
|
|
CID_FILE_CLOSE,
|
|
|
|
CID_RMDIR_OR_FILE,
|
|
|
|
CID_RMDIR_OR_FILE_RESP,
|
|
|
|
CID_RENAME_FILE,
|
|
|
|
CID_RENAME_FILE_RESP,
|
|
|
|
CID_LOOKUP,
|
|
|
|
CID_SETATTR
|
|
|
|
};
|
|
|
|
|
2019-03-21 19:48:01 +03:00
|
|
|
|
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;
|
|
|
|
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
|
|
|
/*
|
2019-11-14 17:43:57 +03:00
|
|
|
* Local functions called from devredir_proc_device_iocompletion()
|
2019-03-12 15:16:50 +03:00
|
|
|
*/
|
2019-12-05 19:44:52 +03:00
|
|
|
static void devredir_proc_cid_rmdir_or_file(IRP *irp, enum NTSTATUS IoStatus);
|
|
|
|
static void devredir_proc_cid_rmdir_or_file_resp(IRP *irp,
|
2020-11-30 03:36:20 +03:00
|
|
|
enum NTSTATUS IoStatus);
|
2019-12-05 19:44:52 +03:00
|
|
|
static void devredir_proc_cid_rename_file(IRP *irp, enum NTSTATUS IoStatus);
|
|
|
|
static void devredir_proc_cid_rename_file_resp(IRP *irp,
|
2020-11-30 03:36:20 +03:00
|
|
|
enum NTSTATUS IoStatus);
|
2019-11-14 17:43:57 +03:00
|
|
|
static void devredir_proc_cid_lookup( IRP *irp,
|
|
|
|
struct stream *s_in,
|
2019-12-05 19:44:52 +03:00
|
|
|
enum NTSTATUS IoStatus);
|
2019-11-14 17:43:57 +03:00
|
|
|
static void devredir_proc_cid_setattr( IRP *irp,
|
|
|
|
struct stream *s_in,
|
2019-12-05 19:44:52 +03:00
|
|
|
enum NTSTATUS IoStatus);
|
2019-03-21 19:48:01 +03:00
|
|
|
/* Other local functions */
|
2019-11-14 17:43:57 +03:00
|
|
|
static void devredir_send_server_core_cap_req(void);
|
|
|
|
static void devredir_send_server_clientID_confirm(void);
|
|
|
|
static void devredir_send_server_user_logged_on(void);
|
|
|
|
|
2022-12-06 15:48:57 +03:00
|
|
|
static int devredir_proc_client_core_cap_resp(struct stream *s);
|
|
|
|
static int devredir_proc_client_devlist_announce_req(struct stream *s);
|
|
|
|
static int devredir_proc_client_devlist_remove_req(struct stream *s);
|
|
|
|
static int devredir_proc_device_iocompletion(struct stream *s);
|
2019-12-05 19:44:52 +03:00
|
|
|
static void devredir_proc_query_dir_response(IRP *irp,
|
2020-11-30 03:36:20 +03:00
|
|
|
struct stream *s_in,
|
|
|
|
tui32 DeviceId,
|
|
|
|
tui32 CompletionId,
|
|
|
|
enum NTSTATUS IoStatus);
|
2019-11-14 17:43:57 +03:00
|
|
|
|
|
|
|
static void devredir_cvt_slash(char *path);
|
|
|
|
static void devredir_cvt_to_unicode(char *unicode, const char *path);
|
|
|
|
static void devredir_cvt_from_unicode_len(char *path, char *unicode, int len);
|
|
|
|
static int devredir_string_ends_with(const char *string, char c);
|
2009-04-22 08:34:45 +04:00
|
|
|
|
|
|
|
/*****************************************************************************/
|
2017-03-12 19:35:00 +03:00
|
|
|
int
|
2019-11-14 17:43:57 +03:00
|
|
|
devredir_init(void)
|
2009-04-22 08:34:45 +04:00
|
|
|
{
|
2013-03-09 03:37:30 +04:00
|
|
|
struct stream *s;
|
|
|
|
int bytes;
|
2020-01-16 14:49:13 +03:00
|
|
|
tui32 clientID;
|
2013-03-09 03:37:30 +04:00
|
|
|
|
|
|
|
/* get a random number that will act as a unique clientID */
|
2020-01-16 14:49:13 +03:00
|
|
|
g_random((char *) &clientID, sizeof(clientID));
|
2013-03-09 03:37:30 +04:00
|
|
|
|
|
|
|
/* 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 */
|
2020-01-16 14:49:13 +03:00
|
|
|
xstream_wr_u32_le(s, 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
|
2019-11-14 17:43:57 +03:00
|
|
|
devredir_deinit(void)
|
2009-08-15 06:47:51 +04:00
|
|
|
{
|
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
|
|
|
}
|
|
|
|
|
2019-11-14 17:43:57 +03:00
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Convert a COMPLETION_TYPE to a string
|
|
|
|
*/
|
|
|
|
const char *completion_type_to_str(enum COMPLETION_TYPE cid)
|
|
|
|
{
|
2020-11-30 03:36:20 +03:00
|
|
|
return
|
|
|
|
(cid == CID_CREATE_DIR_REQ) ? "CID_CREATE_DIR_REQ" :
|
|
|
|
(cid == CID_DIRECTORY_CONTROL) ? "CID_DIRECTORY_CONTROL" :
|
|
|
|
(cid == CID_CREATE_REQ) ? "CID_CREATE_REQ" :
|
|
|
|
(cid == CID_OPEN_REQ) ? "CID_OPEN_REQ" :
|
|
|
|
(cid == CID_READ) ? "CID_READ" :
|
|
|
|
(cid == CID_WRITE) ? "CID_WRITE" :
|
|
|
|
(cid == CID_CLOSE) ? "CID_CLOSE" :
|
|
|
|
(cid == CID_FILE_CLOSE) ? "CID_FILE_CLOSE" :
|
|
|
|
(cid == CID_RMDIR_OR_FILE) ? "CID_RMDIR_OR_FILE" :
|
|
|
|
(cid == CID_RMDIR_OR_FILE_RESP) ? "CID_RMDIR_OR_FILE_RESP" :
|
|
|
|
(cid == CID_RENAME_FILE) ? "CID_RENAME_FILE" :
|
|
|
|
(cid == CID_RENAME_FILE_RESP) ? "CID_RENAME_FILE_RESP" :
|
|
|
|
(cid == CID_LOOKUP) ? "CID_LOOKUP" :
|
|
|
|
(cid == CID_SETATTR) ? "CID_SETATTR" :
|
2019-11-14 17:43:57 +03:00
|
|
|
/* default */ "<unknown>";
|
|
|
|
};
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
/*
|
2022-09-03 02:48:01 +03:00
|
|
|
* Convert Windows permissions to Linux permissions.
|
2019-11-14 17:43:57 +03:00
|
|
|
*
|
2022-09-03 02:48:01 +03:00
|
|
|
* We can't currently support group or other permissions as separate from the
|
2019-11-14 17:43:57 +03:00
|
|
|
* owner (not that there's much point). We'll assume our caller will provide
|
|
|
|
* a umask if appropriate
|
|
|
|
*/
|
|
|
|
static tui32
|
|
|
|
WindowsToLinuxFilePerm(tui32 wperm)
|
|
|
|
{
|
|
|
|
tui32 result;
|
|
|
|
if (wperm & W_FILE_ATTRIBUTE_DIRECTORY)
|
|
|
|
{
|
|
|
|
result = S_IFDIR | 0555; /* dirs are always readable and executable */
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
result = S_IFREG | 0444; /* files are always readable */
|
2020-11-30 03:36:20 +03:00
|
|
|
if (wperm & W_FILE_ATTRIBUTE_SYSTEM)
|
|
|
|
{
|
|
|
|
result |= 0111; /* Executable */
|
|
|
|
}
|
2019-11-14 17:43:57 +03:00
|
|
|
}
|
|
|
|
|
2020-11-30 03:36:20 +03:00
|
|
|
if ((wperm & W_FILE_ATTRIBUTE_READONLY) == 0)
|
|
|
|
{
|
|
|
|
result |= 0222;
|
|
|
|
}
|
2019-11-14 17:43:57 +03:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
static tui32
|
|
|
|
LinuxToWindowsFilePerm(tui32 lperm)
|
|
|
|
{
|
|
|
|
tui32 result = 0;
|
|
|
|
|
|
|
|
/* Writeable flag is common to files and directories */
|
|
|
|
if ((lperm & S_IWUSR) == 0)
|
|
|
|
{
|
|
|
|
result |= W_FILE_ATTRIBUTE_READONLY;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (lperm & S_IFDIR)
|
|
|
|
{
|
|
|
|
result |= W_FILE_ATTRIBUTE_DIRECTORY;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* For normal files the system attribute is used to store the owner
|
|
|
|
executable bit */
|
|
|
|
if (lperm & S_IXUSR)
|
|
|
|
{
|
|
|
|
result |= W_FILE_ATTRIBUTE_SYSTEM;
|
|
|
|
}
|
|
|
|
if (result == 0)
|
|
|
|
{
|
|
|
|
/* See MS-FSCC section 2.6 */
|
|
|
|
result = W_FILE_ATTRIBUTE_NORMAL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
2019-11-14 17:43:57 +03:00
|
|
|
devredir_data_in(struct stream *s, int chan_id, int chan_flags, int length,
|
|
|
|
int total_length)
|
2009-04-22 08:34:45 +04:00
|
|
|
{
|
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)
|
2020-11-30 03:36:20 +03:00
|
|
|
{
|
2013-05-03 13:25:13 +04:00
|
|
|
xstream_new(g_input_stream, total_length);
|
2020-11-30 03:36:20 +03:00
|
|
|
}
|
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)
|
2020-11-30 03:36:20 +03:00
|
|
|
{
|
2013-03-09 03:37:30 +04:00
|
|
|
return 0;
|
2020-11-30 03:36:20 +03:00
|
|
|
}
|
2013-03-09 03:37:30 +04:00
|
|
|
|
2021-05-18 18:02:35 +03:00
|
|
|
s_mark_end(g_input_stream);
|
2013-03-09 03:37:30 +04:00
|
|
|
g_input_stream->p = g_input_stream->data;
|
|
|
|
ls = g_input_stream;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* read header from incoming data */
|
2022-12-06 15:48:57 +03:00
|
|
|
if (!s_check_rem_and_log(ls, 4, "Parsing [MS-RDPEFS] RDPDR_HEADER"))
|
|
|
|
{
|
|
|
|
rv = -1;
|
|
|
|
goto done;
|
|
|
|
}
|
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)
|
|
|
|
{
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_ERROR, "invalid component type in response; expected 0x%x got 0x%x",
|
2013-03-09 03:37:30 +04:00
|
|
|
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:
|
2022-12-06 15:48:57 +03:00
|
|
|
if (!s_check_rem_and_log(ls, 6, "Parsing [MS-RDPEFS] DR_CORE_CLIENT_ANNOUNCE_RSP"))
|
|
|
|
{
|
|
|
|
rv = -1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
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
|
|
|
|
2022-12-06 15:48:57 +03:00
|
|
|
g_client_rdp_version = minor_ver;
|
2013-03-09 03:37:30 +04:00
|
|
|
|
2022-12-06 15:48:57 +03:00
|
|
|
switch (minor_ver)
|
|
|
|
{
|
|
|
|
case RDP_CLIENT_50:
|
|
|
|
break;
|
2013-03-09 03:37:30 +04:00
|
|
|
|
2022-12-06 15:48:57 +03:00
|
|
|
case RDP_CLIENT_51:
|
|
|
|
break;
|
2013-03-09 03:37:30 +04:00
|
|
|
|
2022-12-06 15:48:57 +03:00
|
|
|
case RDP_CLIENT_52:
|
|
|
|
break;
|
2013-03-09 03:37:30 +04:00
|
|
|
|
2022-12-06 15:48:57 +03:00
|
|
|
case RDP_CLIENT_60_61:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
// LK_TODO devredir_send_server_clientID_confirm();
|
2013-03-09 03:37:30 +04:00
|
|
|
}
|
|
|
|
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 */
|
2019-11-14 17:43:57 +03:00
|
|
|
devredir_send_server_user_logged_on();
|
2013-03-09 03:37:30 +04:00
|
|
|
usleep(1000 * 100);
|
|
|
|
|
2016-02-14 07:41:07 +03:00
|
|
|
/* let client know our capabilities */
|
2019-11-14 17:43:57 +03:00
|
|
|
devredir_send_server_core_cap_req();
|
2013-03-09 03:37:30 +04:00
|
|
|
|
|
|
|
/* send confirm clientID */
|
2019-11-14 17:43:57 +03:00
|
|
|
devredir_send_server_clientID_confirm();
|
2013-03-09 03:37:30 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case PAKID_CORE_CLIENT_CAPABILITY:
|
2022-12-06 15:48:57 +03:00
|
|
|
rv = devredir_proc_client_core_cap_resp(ls);
|
2013-03-09 03:37:30 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case PAKID_CORE_DEVICELIST_ANNOUNCE:
|
2022-12-06 15:48:57 +03:00
|
|
|
rv = devredir_proc_client_devlist_announce_req(ls);
|
2013-03-09 03:37:30 +04:00
|
|
|
break;
|
|
|
|
|
2019-11-14 17:43:57 +03:00
|
|
|
case PAKID_CORE_DEVICELIST_REMOVE:
|
2022-12-06 15:48:57 +03:00
|
|
|
rv = devredir_proc_client_devlist_remove_req(ls);
|
2019-11-14 17:43:57 +03:00
|
|
|
break;
|
|
|
|
|
2013-03-09 03:37:30 +04:00
|
|
|
case PAKID_CORE_DEVICE_IOCOMPLETION:
|
2022-12-06 15:48:57 +03:00
|
|
|
rv = devredir_proc_device_iocompletion(ls);
|
2013-03-09 03:37:30 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_ERROR, "got unknown response 0x%x", pktID);
|
2013-03-09 03:37:30 +04:00
|
|
|
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
|
2019-11-14 17:43:57 +03:00
|
|
|
devredir_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
|
2019-11-14 17:43:57 +03:00
|
|
|
devredir_check_wait_objs(void)
|
2009-04-22 08:34:45 +04:00
|
|
|
{
|
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
|
|
|
|
*****************************************************************************/
|
|
|
|
|
2019-11-14 17:43:57 +03:00
|
|
|
static void
|
|
|
|
devredir_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 */
|
2020-11-30 03:36:20 +03:00
|
|
|
/* CAPABILITY_SET in bytes, inc */
|
|
|
|
/* the header */
|
2013-05-03 13:25:13 +04:00
|
|
|
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 */
|
2020-11-30 03:36:20 +03: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
|
|
|
}
|
|
|
|
|
2019-11-14 17:43:57 +03:00
|
|
|
static void
|
|
|
|
devredir_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
|
|
|
}
|
|
|
|
|
2019-11-14 17:43:57 +03:00
|
|
|
static void
|
|
|
|
devredir_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
|
|
|
}
|
|
|
|
|
2019-11-14 17:43:57 +03:00
|
|
|
static void
|
2020-03-03 13:02:32 +03:00
|
|
|
devredir_send_server_device_announce_resp(tui32 device_id,
|
2020-11-30 03:36:20 +03:00
|
|
|
enum NTSTATUS result_code)
|
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);
|
2020-03-03 13:02:32 +03:00
|
|
|
xstream_wr_u32_le(s, (tui32)result_code);
|
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
|
|
|
|
*****************************************************************************/
|
|
|
|
|
2019-11-14 17:43:57 +03:00
|
|
|
static int
|
|
|
|
devredir_send_drive_create_request(tui32 device_id,
|
|
|
|
const char *path,
|
|
|
|
tui32 DesiredAccess,
|
|
|
|
tui32 CreateOptions,
|
|
|
|
tui32 FileAttributes,
|
|
|
|
tui32 CreateDisposition,
|
|
|
|
tui32 completion_id)
|
2013-03-09 03:37:30 +04:00
|
|
|
{
|
|
|
|
struct stream *s;
|
|
|
|
int bytes;
|
|
|
|
int len;
|
2019-11-14 17:43:57 +03:00
|
|
|
tui32 SharedAccess;
|
2013-03-09 03:37:30 +04:00
|
|
|
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "device_id=%d path=\"%s\""
|
2020-11-30 03:36:20 +03:00
|
|
|
" DesiredAccess=0x%x CreateDisposition=0x%x"
|
|
|
|
" FileAttributes=0x%x CreateOptions=0x%x"
|
|
|
|
" CompletionId=%d",
|
|
|
|
device_id, path,
|
|
|
|
DesiredAccess, CreateDisposition,
|
|
|
|
FileAttributes, CreateOptions,
|
|
|
|
completion_id);
|
2013-03-09 03:37:30 +04:00
|
|
|
|
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
|
|
|
|
2019-11-14 17:43:57 +03:00
|
|
|
/* FILE_SHARE_DELETE allows files to be renamed while in use
|
|
|
|
(in some circumstances) */
|
|
|
|
SharedAccess = SA_FILE_SHARE_READ | SA_FILE_SHARE_WRITE |
|
|
|
|
SA_FILE_SHARE_DELETE;
|
|
|
|
|
2013-05-16 04:06:05 +04:00
|
|
|
devredir_insert_DeviceIoRequest(s,
|
|
|
|
device_id,
|
|
|
|
0,
|
|
|
|
completion_id,
|
|
|
|
IRP_MJ_CREATE,
|
2019-12-05 19:44:52 +03:00
|
|
|
IRP_MN_NONE);
|
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 */
|
2019-11-14 17:43:57 +03:00
|
|
|
xstream_wr_u32_le(s, FileAttributes); /* FileAttributes */
|
|
|
|
xstream_wr_u32_le(s, SharedAccess); /* SharedAccess */
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-11-14 17:43:57 +03:00
|
|
|
* Close a request previously created by devredir_send_drive_create_request()
|
2013-03-09 03:37:30 +04:00
|
|
|
*****************************************************************************/
|
|
|
|
|
2019-11-14 17:43:57 +03:00
|
|
|
static int
|
|
|
|
devredir_send_drive_close_request(tui16 Component, tui16 PacketId,
|
|
|
|
tui32 DeviceId,
|
|
|
|
tui32 FileId,
|
|
|
|
tui32 CompletionId,
|
|
|
|
enum IRP_MJ MajorFunction,
|
|
|
|
enum IRP_MN MinorFunc,
|
|
|
|
int pad_len)
|
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
|
|
|
|
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)
|
2020-11-30 03:36:20 +03:00
|
|
|
{
|
2013-05-03 13:25:13 +04:00
|
|
|
xstream_seek(s, pad_len);
|
2020-11-30 03:36:20 +03:00
|
|
|
}
|
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);
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_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
|
2019-11-14 17:43:57 +03:00
|
|
|
static void
|
|
|
|
devredir_send_drive_dir_request(IRP *irp, tui32 device_id,
|
|
|
|
tui32 InitialQuery, char *Path)
|
2013-03-09 03:37:30 +04:00
|
|
|
{
|
|
|
|
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-05-03 13:25:13 +04:00
|
|
|
xstream_wr_u32_le(s, FileDirectoryInformation); /* FsInformationClass */
|
|
|
|
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
|
2022-12-06 15:48:57 +03:00
|
|
|
* @return 0 for success, -1 otherwise
|
2013-03-09 03:37:30 +04:00
|
|
|
*****************************************************************************/
|
2022-12-06 15:48:57 +03:00
|
|
|
static int
|
2019-11-14 17:43:57 +03:00
|
|
|
devredir_proc_client_core_cap_resp(struct stream *s)
|
2013-03-09 03:37:30 +04:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
tui16 num_caps;
|
|
|
|
tui16 cap_type;
|
|
|
|
tui16 cap_len;
|
|
|
|
tui32 cap_version;
|
2020-11-30 03:36:20 +03:00
|
|
|
char *holdp;
|
2013-03-09 03:37:30 +04:00
|
|
|
|
2022-12-06 15:48:57 +03:00
|
|
|
if (!s_check_rem_and_log(s, 4, "Parsing [MS-RDPEFS] DR_CORE_CAPABLITY_RSP"))
|
|
|
|
{
|
|
|
|
return -1;
|
|
|
|
}
|
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;
|
2022-12-06 15:48:57 +03:00
|
|
|
if (!s_check_rem_and_log(s, 8, "Parsing [MS-RDPEFS] CAPABILITY_HEADER"))
|
|
|
|
{
|
|
|
|
return -1;
|
|
|
|
}
|
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);
|
2022-12-06 15:48:57 +03:00
|
|
|
/* Convert the length to a remaining length. Underflow is possible,
|
|
|
|
* but this is an unsigned type so that's OK */
|
|
|
|
cap_len -= (s->p - holdp);
|
|
|
|
if (cap_len > 0 &&
|
|
|
|
!s_check_rem_and_log(s, cap_len, "Parsing [MS-RDPEFS] CAPABILITY_HEADER length"))
|
|
|
|
{
|
|
|
|
return -1;
|
|
|
|
}
|
2013-03-09 03:37:30 +04:00
|
|
|
|
|
|
|
switch (cap_type)
|
|
|
|
{
|
|
|
|
case CAP_GENERAL_TYPE:
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "got CAP_GENERAL_TYPE");
|
2013-03-09 03:37:30 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case CAP_PRINTER_TYPE:
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "got CAP_PRINTER_TYPE");
|
2013-03-09 03:37:30 +04:00
|
|
|
g_is_printer_redir_supported = 1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CAP_PORT_TYPE:
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "got CAP_PORT_TYPE");
|
2013-03-09 03:37:30 +04:00
|
|
|
g_is_port_redir_supported = 1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CAP_DRIVE_TYPE:
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "got CAP_DRIVE_TYPE");
|
2013-03-09 03:37:30 +04:00
|
|
|
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:
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "got CAP_SMARTCARD_TYPE");
|
2023-01-16 16:41:18 +03:00
|
|
|
g_is_smartcard_redir_supported = (scard_init() == 0);
|
2013-03-09 03:37:30 +04:00
|
|
|
break;
|
|
|
|
}
|
2022-12-06 15:48:57 +03:00
|
|
|
xstream_seek(s, cap_len);
|
2013-03-09 03:37:30 +04:00
|
|
|
}
|
2022-12-06 15:48:57 +03:00
|
|
|
return 0;
|
2013-03-09 03:37:30 +04:00
|
|
|
}
|
|
|
|
|
2022-12-06 15:48:57 +03:00
|
|
|
static int
|
2019-11-14 17:43:57 +03:00
|
|
|
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];
|
2020-03-03 13:02:32 +03:00
|
|
|
enum NTSTATUS response_status;
|
2013-03-09 03:37:30 +04:00
|
|
|
|
|
|
|
/* get number of devices being announced */
|
2022-12-06 15:48:57 +03:00
|
|
|
if (!s_check_rem_and_log(s, 4, "Parsing [MS-RDPEFS] DR_CORE_DEVICELIST_ANNOUNCE_REQ"))
|
|
|
|
{
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2013-05-03 13:25:13 +04:00
|
|
|
xstream_rd_u32_le(s, device_count);
|
2013-03-09 03:37:30 +04:00
|
|
|
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "num of devices announced: %d", device_count);
|
2013-03-09 03:37:30 +04:00
|
|
|
|
|
|
|
for (i = 0; i < device_count; i++)
|
|
|
|
{
|
2022-12-06 15:48:57 +03:00
|
|
|
if (!s_check_rem_and_log(s, 4 + 4 + 8 + 4,
|
|
|
|
"Parsing [MS-RDPEFS] DEVICE_ANNOUNCE"))
|
|
|
|
{
|
|
|
|
return -1;
|
|
|
|
}
|
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);
|
2020-03-03 13:02:32 +03:00
|
|
|
/* get preferred DOS name
|
|
|
|
* DOS names that are 8 chars long are not NULL terminated */
|
|
|
|
for (j = 0; j < 8; j++)
|
|
|
|
{
|
|
|
|
preferred_dos_name[j] = *s->p++;
|
|
|
|
}
|
|
|
|
preferred_dos_name[8] = 0;
|
|
|
|
|
|
|
|
/* Assume this device isn't supported by us */
|
|
|
|
response_status = STATUS_NOT_SUPPORTED;
|
2013-03-09 03:37:30 +04:00
|
|
|
|
2021-09-02 19:08:53 +03:00
|
|
|
/* Read the device data length from the stream */
|
|
|
|
xstream_rd_u32_le(s, device_data_len);
|
2022-12-09 21:12:25 +03:00
|
|
|
if (device_data_len > 0 &&
|
2022-12-06 15:48:57 +03:00
|
|
|
!s_check_rem_and_log(s, device_data_len,
|
|
|
|
"Parsing [MS-RDPEFS] DEVICE_ANNOUNCE devdata"))
|
|
|
|
{
|
|
|
|
return -1;
|
|
|
|
}
|
2021-09-02 19:08:53 +03:00
|
|
|
|
2013-03-09 03:37:30 +04:00
|
|
|
switch (device_type)
|
|
|
|
{
|
|
|
|
case RDPDR_DTYP_FILESYSTEM:
|
2022-12-08 17:13:48 +03:00
|
|
|
/* At present we don't use the full name - see
|
|
|
|
* [MS-RDPEFS] 2.2.3.1 for details of the contents */
|
|
|
|
xstream_skip_u8(s, device_data_len);
|
2013-03-09 03:37:30 +04:00
|
|
|
|
2021-09-08 13:33:35 +03:00
|
|
|
LOG(LOG_LEVEL_INFO, "Detected remote drive '%s'",
|
2021-09-02 19:08:53 +03:00
|
|
|
preferred_dos_name);
|
|
|
|
|
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG,
|
|
|
|
"device_type=FILE_SYSTEM device_id=0x%x dosname=%s "
|
2022-12-08 17:13:48 +03:00
|
|
|
"device_data_len=%d", g_device_id,
|
2013-05-16 04:06:05 +04:00
|
|
|
preferred_dos_name,
|
2022-12-08 17:13:48 +03:00
|
|
|
device_data_len);
|
2013-03-09 03:37:30 +04:00
|
|
|
|
2020-03-03 13:02:32 +03:00
|
|
|
response_status = STATUS_SUCCESS;
|
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:
|
2021-09-02 19:08:53 +03:00
|
|
|
xstream_skip_u8(s, device_data_len);
|
2013-05-16 04:06:05 +04:00
|
|
|
|
2021-09-02 19:08:53 +03:00
|
|
|
LOG(LOG_LEVEL_INFO, "Detected remote smartcard '%s'",
|
|
|
|
preferred_dos_name);
|
2020-03-03 13:02:32 +03:00
|
|
|
|
2020-11-30 03:36:20 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG,
|
2021-09-02 19:08:53 +03:00
|
|
|
"device_type=SMARTCARD device_id=0x%x dosname=%s",
|
2020-11-30 03:36:20 +03:00
|
|
|
g_device_id, preferred_dos_name);
|
2020-03-03 13:02:32 +03:00
|
|
|
|
2021-09-02 19:08:53 +03:00
|
|
|
response_status = STATUS_SUCCESS;
|
2020-03-03 13:02:32 +03:00
|
|
|
|
2021-09-02 19:08:53 +03:00
|
|
|
scard_device_announce(g_device_id);
|
2020-03-03 13:02:32 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2021-09-02 19:08:53 +03:00
|
|
|
{
|
|
|
|
/* All other devices are unsupported */
|
|
|
|
const char *description =
|
|
|
|
(device_type == RDPDR_DTYP_SERIAL) ? "serial port" :
|
|
|
|
(device_type == RDPDR_DTYP_PARALLEL) ? "parallel port" :
|
|
|
|
(device_type == RDPDR_DTYP_PRINT) ? "printer" :
|
|
|
|
/* default */ "unknown device";
|
|
|
|
|
|
|
|
xstream_skip_u8(s, device_data_len);
|
2021-09-08 13:33:35 +03:00
|
|
|
LOG(LOG_LEVEL_INFO, "Detected remote %s '%s' (not supported)",
|
2021-09-02 19:08:53 +03:00
|
|
|
description, preferred_dos_name);
|
2020-11-30 03:36:20 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG,
|
2021-09-02 19:08:53 +03:00
|
|
|
"description=%s dosname=%s device_id=0x%x",
|
|
|
|
description, preferred_dos_name, g_device_id);
|
|
|
|
}
|
|
|
|
break;
|
2013-03-09 03:37:30 +04:00
|
|
|
}
|
2020-03-03 13:02:32 +03:00
|
|
|
|
|
|
|
/* Tell the client wheth or not we're supporting this one */
|
|
|
|
devredir_send_server_device_announce_resp(g_device_id,
|
2020-11-30 03:36:20 +03:00
|
|
|
response_status);
|
2013-03-09 03:37:30 +04:00
|
|
|
}
|
2022-12-06 15:48:57 +03:00
|
|
|
|
|
|
|
return 0;
|
2013-03-09 03:37:30 +04:00
|
|
|
}
|
|
|
|
|
2022-12-06 15:48:57 +03:00
|
|
|
static int
|
2019-11-14 17:43:57 +03:00
|
|
|
devredir_proc_client_devlist_remove_req(struct stream *s)
|
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
tui32 device_count;
|
|
|
|
tui32 device_id;
|
|
|
|
|
|
|
|
/* get number of devices being announced */
|
2022-12-06 15:48:57 +03:00
|
|
|
if (!s_check_rem_and_log(s, 4, "Parsing [MS-RDPEFS] DR_DEVICELIST_REMOVE"))
|
|
|
|
{
|
|
|
|
return -1;
|
|
|
|
}
|
2019-11-14 17:43:57 +03:00
|
|
|
xstream_rd_u32_le(s, device_count);
|
2022-12-06 15:48:57 +03:00
|
|
|
if (!s_check_rem_and_log(s, 4 * device_count,
|
|
|
|
"Parsing [MS-RDPEFS] DR_DEVICELIST_REMOVE list"))
|
|
|
|
{
|
|
|
|
return -1;
|
|
|
|
}
|
2019-11-14 17:43:57 +03:00
|
|
|
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "num of devices removed: %d", device_count);
|
2019-11-14 17:43:57 +03:00
|
|
|
{
|
|
|
|
for (i = 0; i < device_count; i++)
|
|
|
|
{
|
|
|
|
xstream_rd_u32_le(s, device_id);
|
|
|
|
xfuse_delete_share(device_id);
|
|
|
|
}
|
|
|
|
}
|
2022-12-06 15:48:57 +03:00
|
|
|
return 0;
|
2019-11-14 17:43:57 +03:00
|
|
|
}
|
|
|
|
|
2022-12-06 15:48:57 +03:00
|
|
|
static int
|
2019-11-14 17:43:57 +03:00
|
|
|
devredir_proc_device_iocompletion(struct stream *s)
|
2013-03-09 03:37:30 +04:00
|
|
|
{
|
|
|
|
IRP *irp = NULL;
|
|
|
|
|
|
|
|
tui32 DeviceId;
|
|
|
|
tui32 CompletionId;
|
2019-12-05 19:44:52 +03:00
|
|
|
tui32 IoStatus32;
|
2013-03-09 03:37:30 +04:00
|
|
|
tui32 Length;
|
2019-12-05 19:44:52 +03:00
|
|
|
enum COMPLETION_TYPE comp_type;
|
2013-03-09 03:37:30 +04:00
|
|
|
|
2022-12-06 15:48:57 +03:00
|
|
|
if (!s_check_rem_and_log(s, 12, "Parsing [MS-RDPEFS] DR_DEVICE_IOCOMPLETION"))
|
|
|
|
{
|
|
|
|
return -1;
|
|
|
|
}
|
2013-05-03 13:25:13 +04:00
|
|
|
xstream_rd_u32_le(s, DeviceId);
|
|
|
|
xstream_rd_u32_le(s, CompletionId);
|
2019-12-05 19:44:52 +03:00
|
|
|
xstream_rd_u32_le(s, IoStatus32);
|
|
|
|
enum NTSTATUS IoStatus = (enum NTSTATUS) IoStatus32; /* Needed by C++ */
|
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
|
|
|
{
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_ERROR, "IRP with completion ID %d not found", CompletionId);
|
2013-03-09 03:37:30 +04:00
|
|
|
}
|
2020-11-30 03:36:20 +03:00
|
|
|
else if (irp->callback)
|
2013-05-16 04:06:05 +04:00
|
|
|
{
|
2019-11-14 17:43:57 +03:00
|
|
|
/* Callback has been set - call it */
|
2013-05-16 04:06:05 +04:00
|
|
|
(*irp->callback)(s, irp, DeviceId, CompletionId, IoStatus);
|
|
|
|
}
|
2019-11-14 17:43:57 +03:00
|
|
|
else
|
2013-03-09 03:37:30 +04:00
|
|
|
{
|
2019-12-05 19:44:52 +03:00
|
|
|
comp_type = (enum COMPLETION_TYPE) irp->completion_type;
|
2019-11-14 17:43:57 +03:00
|
|
|
/* Log something about the IRP */
|
2019-12-19 12:55:38 +03:00
|
|
|
if (IoStatus == STATUS_SUCCESS ||
|
2020-11-30 03:36:20 +03:00
|
|
|
IoStatus == STATUS_NO_MORE_FILES ||
|
|
|
|
(IoStatus == STATUS_NO_SUCH_FILE && comp_type == CID_LOOKUP))
|
2019-11-14 17:43:57 +03:00
|
|
|
{
|
|
|
|
/* Successes or common occurrences - debug logging only */
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "got %s", completion_type_to_str(comp_type));
|
2019-11-14 17:43:57 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_ERROR, "CompletionType = %s, IoStatus=%08x "
|
2019-11-14 17:43:57 +03:00
|
|
|
"Pathname = %s",
|
|
|
|
completion_type_to_str(comp_type),
|
|
|
|
IoStatus,
|
2020-10-08 04:55:08 +03:00
|
|
|
(irp->pathname) ? irp->pathname : "<none>");
|
2019-11-14 17:43:57 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
switch (comp_type)
|
2013-03-24 23:08:55 +04:00
|
|
|
{
|
2020-11-30 03:36:20 +03:00
|
|
|
case CID_CREATE_DIR_REQ:
|
|
|
|
if (IoStatus != STATUS_SUCCESS)
|
|
|
|
{
|
|
|
|
xfuse_devredir_cb_enum_dir_done(
|
|
|
|
(struct state_dirscan *) irp->fuse_info, IoStatus);
|
|
|
|
devredir_irp_delete(irp);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-12-06 15:48:57 +03:00
|
|
|
if (!s_check_rem_and_log(s, 4, "Parsing [MS-RDPEFS] DR_CREATE_RSP"))
|
|
|
|
{
|
|
|
|
return -1;
|
|
|
|
}
|
2020-11-30 03:36:20 +03:00
|
|
|
xstream_rd_u32_le(s, irp->FileId);
|
|
|
|
devredir_send_drive_dir_request(irp, DeviceId,
|
|
|
|
1, irp->pathname);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CID_CREATE_REQ:
|
2022-12-06 15:48:57 +03:00
|
|
|
if (!s_check_rem_and_log(s, 4, "Parsing [MS-RDPEFS] DR_CREATE_RSP"))
|
|
|
|
{
|
|
|
|
return -1;
|
|
|
|
}
|
2019-11-14 17:43:57 +03:00
|
|
|
xstream_rd_u32_le(s, irp->FileId);
|
2013-03-09 03:37:30 +04:00
|
|
|
|
2020-11-30 03:36:20 +03:00
|
|
|
xfuse_devredir_cb_create_file(
|
|
|
|
(struct state_create *) irp->fuse_info,
|
|
|
|
IoStatus, DeviceId, irp->FileId);
|
|
|
|
if (irp->gen.create.creating_dir || IoStatus != STATUS_SUCCESS)
|
|
|
|
{
|
|
|
|
devredir_irp_delete(irp);
|
|
|
|
}
|
|
|
|
break;
|
2013-04-21 03:42:49 +04:00
|
|
|
|
2020-11-30 03:36:20 +03:00
|
|
|
case CID_OPEN_REQ:
|
2022-12-06 15:48:57 +03:00
|
|
|
if (!s_check_rem_and_log(s, 4, "Parsing [MS-RDPEFS] DR_CREATE_RSP"))
|
|
|
|
{
|
|
|
|
return -1;
|
|
|
|
}
|
2020-11-30 03:36:20 +03:00
|
|
|
xstream_rd_u32_le(s, irp->FileId);
|
2013-03-09 03:37:30 +04:00
|
|
|
|
2020-11-30 03:36:20 +03:00
|
|
|
xfuse_devredir_cb_open_file((struct state_open *) irp->fuse_info,
|
|
|
|
IoStatus, DeviceId, irp->FileId);
|
|
|
|
if (IoStatus != STATUS_SUCCESS)
|
|
|
|
{
|
|
|
|
devredir_irp_delete(irp);
|
|
|
|
}
|
|
|
|
break;
|
2013-06-09 05:44:21 +04:00
|
|
|
|
2020-11-30 03:36:20 +03:00
|
|
|
case CID_READ:
|
2022-12-06 15:48:57 +03:00
|
|
|
if (!s_check_rem_and_log(s, 4, "Parsing [MS-RDPEFS] DR_READ_RSP"))
|
|
|
|
{
|
|
|
|
return -1;
|
|
|
|
}
|
2020-11-30 03:36:20 +03:00
|
|
|
xstream_rd_u32_le(s, Length);
|
2022-12-06 15:48:57 +03:00
|
|
|
if (!s_check_rem_and_log(s, Length, "Parsing [MS-RDPEFS] DR_READ_RSP"))
|
|
|
|
{
|
|
|
|
return -1;
|
|
|
|
}
|
2020-11-30 03:36:20 +03:00
|
|
|
xfuse_devredir_cb_read_file((struct state_read *) irp->fuse_info,
|
|
|
|
IoStatus,
|
|
|
|
s->p, Length);
|
2019-11-14 17:43:57 +03:00
|
|
|
devredir_irp_delete(irp);
|
2020-11-30 03:36:20 +03:00
|
|
|
break;
|
2013-06-03 02:33:51 +04:00
|
|
|
|
2020-11-30 03:36:20 +03:00
|
|
|
case CID_WRITE:
|
2022-12-06 15:48:57 +03:00
|
|
|
if (!s_check_rem_and_log(s, 4, "Parsing [MS-RDPEFS] DR_WRITE_RSP"))
|
|
|
|
{
|
|
|
|
return -1;
|
|
|
|
}
|
2020-11-30 03:36:20 +03:00
|
|
|
xstream_rd_u32_le(s, Length);
|
|
|
|
xfuse_devredir_cb_write_file((struct state_write *) irp->fuse_info,
|
|
|
|
IoStatus,
|
|
|
|
irp->gen.write.offset, Length);
|
|
|
|
devredir_irp_delete(irp);
|
|
|
|
break;
|
2013-06-03 02:33:51 +04:00
|
|
|
|
2020-11-30 03:36:20 +03:00
|
|
|
case CID_CLOSE:
|
|
|
|
devredir_irp_delete(irp);
|
|
|
|
break;
|
2013-03-09 03:37:30 +04:00
|
|
|
|
2020-11-30 03:36:20 +03:00
|
|
|
case CID_FILE_CLOSE:
|
|
|
|
xfuse_devredir_cb_file_close((struct state_close *) irp->fuse_info);
|
|
|
|
devredir_irp_delete(irp);
|
|
|
|
break;
|
2013-03-09 03:37:30 +04:00
|
|
|
|
2020-11-30 03:36:20 +03:00
|
|
|
case CID_DIRECTORY_CONTROL:
|
|
|
|
devredir_proc_query_dir_response(irp, s, DeviceId,
|
|
|
|
CompletionId, IoStatus);
|
|
|
|
break;
|
2013-03-19 06:43:20 +04:00
|
|
|
|
2020-11-30 03:36:20 +03:00
|
|
|
case CID_RMDIR_OR_FILE:
|
2022-12-06 15:48:57 +03:00
|
|
|
if (!s_check_rem_and_log(s, 4, "Parsing [MS-RDPEFS] DR_CREATE_RSP"))
|
|
|
|
{
|
|
|
|
return -1;
|
|
|
|
}
|
2020-11-30 03:36:20 +03:00
|
|
|
xstream_rd_u32_le(s, irp->FileId);
|
|
|
|
devredir_proc_cid_rmdir_or_file(irp, IoStatus);
|
|
|
|
break;
|
2013-03-09 03:37:30 +04:00
|
|
|
|
2020-11-30 03:36:20 +03:00
|
|
|
case CID_RMDIR_OR_FILE_RESP:
|
|
|
|
devredir_proc_cid_rmdir_or_file_resp(irp, IoStatus);
|
|
|
|
break;
|
2013-03-09 03:37:30 +04:00
|
|
|
|
2020-11-30 03:36:20 +03:00
|
|
|
case CID_RENAME_FILE:
|
2022-12-06 15:48:57 +03:00
|
|
|
if (!s_check_rem_and_log(s, 4, "Parsing [MS-RDPEFS] DR_CREATE_RSP"))
|
|
|
|
{
|
|
|
|
return -1;
|
|
|
|
}
|
2020-11-30 03:36:20 +03:00
|
|
|
xstream_rd_u32_le(s, irp->FileId);
|
|
|
|
devredir_proc_cid_rename_file(irp, IoStatus);
|
|
|
|
break;
|
2013-03-19 06:43:20 +04:00
|
|
|
|
2020-11-30 03:36:20 +03:00
|
|
|
case CID_RENAME_FILE_RESP:
|
|
|
|
devredir_proc_cid_rename_file_resp(irp, IoStatus);
|
|
|
|
break;
|
2013-03-19 06:43:20 +04:00
|
|
|
|
2020-11-30 03:36:20 +03:00
|
|
|
case CID_LOOKUP:
|
|
|
|
devredir_proc_cid_lookup(irp, s, IoStatus);
|
|
|
|
break;
|
2013-03-09 03:37:30 +04:00
|
|
|
|
2020-11-30 03:36:20 +03:00
|
|
|
case CID_SETATTR:
|
|
|
|
devredir_proc_cid_setattr(irp, s, IoStatus);
|
|
|
|
break;
|
2013-05-16 04:06:05 +04:00
|
|
|
|
2020-11-30 03:36:20 +03:00
|
|
|
default:
|
|
|
|
LOG_DEVEL(LOG_LEVEL_ERROR, "got unknown CompletionID: DeviceId=0x%x "
|
|
|
|
"CompletionId=0x%x IoStatus=0x%x",
|
|
|
|
DeviceId, CompletionId, IoStatus);
|
|
|
|
break;
|
2019-11-14 17:43:57 +03:00
|
|
|
}
|
2013-05-19 06:44:16 +04:00
|
|
|
}
|
2022-12-06 15:48:57 +03:00
|
|
|
return 0;
|
2013-03-09 03:37:30 +04:00
|
|
|
}
|
|
|
|
|
2019-11-14 17:43:57 +03:00
|
|
|
static void
|
|
|
|
devredir_proc_query_dir_response(IRP *irp,
|
|
|
|
struct stream *s_in,
|
|
|
|
tui32 DeviceId,
|
|
|
|
tui32 CompletionId,
|
2019-12-05 19:44:52 +03:00
|
|
|
enum NTSTATUS IoStatus)
|
2013-03-09 03:37:30 +04:00
|
|
|
{
|
|
|
|
tui32 Length;
|
2013-05-03 13:25:13 +04:00
|
|
|
xstream_rd_u32_le(s_in, Length);
|
2013-03-09 03:37:30 +04:00
|
|
|
|
2019-12-19 12:55:38 +03:00
|
|
|
if (IoStatus == STATUS_SUCCESS)
|
2013-03-09 03:37:30 +04:00
|
|
|
{
|
2019-11-14 17:43:57 +03:00
|
|
|
unsigned int i;
|
|
|
|
/* process FILE_DIRECTORY_INFORMATION structures */
|
|
|
|
for (i = 0 ; i < Length ; ++i)
|
|
|
|
{
|
|
|
|
char filename[256];
|
|
|
|
tui64 LastAccessTime;
|
|
|
|
tui64 LastWriteTime;
|
|
|
|
tui64 EndOfFile;
|
|
|
|
tui32 FileAttributes;
|
|
|
|
tui32 FileNameLength;
|
|
|
|
struct file_attr fattr;
|
|
|
|
|
|
|
|
xstream_seek(s_in, 4); /* NextEntryOffset */
|
|
|
|
xstream_seek(s_in, 4); /* FileIndex */
|
|
|
|
xstream_seek(s_in, 8); /* CreationTime */
|
|
|
|
xstream_rd_u64_le(s_in, LastAccessTime);
|
|
|
|
xstream_rd_u64_le(s_in, LastWriteTime);
|
|
|
|
xstream_seek(s_in, 8); /* ChangeTime */
|
|
|
|
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);
|
|
|
|
|
|
|
|
devredir_cvt_from_unicode_len(filename, s_in->p, FileNameLength);
|
|
|
|
|
|
|
|
i += 64 + FileNameLength;
|
|
|
|
|
2020-10-08 04:55:08 +03:00
|
|
|
//LOG_DEVEL(LOG_LEVEL_DEBUG, "LastAccessTime: 0x%llx", LastAccessTime);
|
|
|
|
//LOG_DEVEL(LOG_LEVEL_DEBUG, "LastWriteTime: 0x%llx", LastWriteTime);
|
|
|
|
//LOG_DEVEL(LOG_LEVEL_DEBUG, "EndOfFile: %lld", EndOfFile);
|
|
|
|
//LOG_DEVEL(LOG_LEVEL_DEBUG, "FileAttributes: 0x%x", FileAttributes);
|
|
|
|
//LOG_DEVEL(LOG_LEVEL_DEBUG, "FileNameLength: %d", FileNameLength);
|
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "FileName: %s", filename);
|
2019-11-14 17:43:57 +03:00
|
|
|
|
|
|
|
fattr.mode = WindowsToLinuxFilePerm(FileAttributes);
|
|
|
|
fattr.size = (size_t) EndOfFile;
|
|
|
|
fattr.atime = WINDOWS_TO_LINUX_TIME(LastAccessTime);
|
|
|
|
fattr.mtime = WINDOWS_TO_LINUX_TIME(LastWriteTime);
|
|
|
|
|
|
|
|
/* add this entry to xrdp file system */
|
2019-12-05 19:44:52 +03:00
|
|
|
xfuse_devredir_cb_enum_dir_add_entry(
|
2020-11-30 03:36:20 +03:00
|
|
|
(struct state_dirscan *) irp->fuse_info,
|
|
|
|
filename, &fattr);
|
2019-11-14 17:43:57 +03:00
|
|
|
}
|
2013-03-09 03:37:30 +04:00
|
|
|
|
2019-11-14 17:43:57 +03:00
|
|
|
/* Ask for more directory entries */
|
|
|
|
devredir_send_drive_dir_request(irp, DeviceId, 0, NULL);
|
|
|
|
}
|
|
|
|
else
|
2013-03-09 03:37:30 +04:00
|
|
|
{
|
2019-12-19 12:55:38 +03:00
|
|
|
if (IoStatus == STATUS_NO_MORE_FILES)
|
2019-11-14 17:43:57 +03:00
|
|
|
{
|
2019-12-19 12:55:38 +03:00
|
|
|
IoStatus = STATUS_SUCCESS;
|
2019-11-14 17:43:57 +03:00
|
|
|
}
|
2019-12-05 19:44:52 +03:00
|
|
|
xfuse_devredir_cb_enum_dir_done((struct state_dirscan *)irp->fuse_info,
|
|
|
|
IoStatus);
|
2019-11-14 17:43:57 +03:00
|
|
|
irp->completion_type = CID_CLOSE;
|
|
|
|
devredir_send_drive_close_request(RDPDR_CTYP_CORE,
|
|
|
|
PAKID_CORE_DEVICE_IOREQUEST,
|
|
|
|
DeviceId,
|
|
|
|
irp->FileId,
|
|
|
|
irp->CompletionId,
|
2019-12-05 19:44:52 +03:00
|
|
|
IRP_MJ_CLOSE, IRP_MN_NONE, 32);
|
2013-03-09 03:37:30 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
2019-11-14 17:43:57 +03:00
|
|
|
devredir_get_dir_listing(struct state_dirscan *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;
|
2019-11-14 17:43:57 +03:00
|
|
|
int rval = -1;
|
2013-03-09 03:37:30 +04:00
|
|
|
IRP *irp;
|
|
|
|
|
2019-11-14 17:43:57 +03:00
|
|
|
/*
|
|
|
|
* We need to be able to append two additional characters to the
|
|
|
|
* path after we create the IRP
|
|
|
|
*/
|
|
|
|
if ((irp = devredir_irp_with_pathnamelen_new(strlen(path) + 2)) != NULL)
|
|
|
|
{
|
|
|
|
/* convert / to windows compatible \ */
|
|
|
|
strcpy(irp->pathname, path);
|
|
|
|
devredir_cvt_slash(irp->pathname);
|
|
|
|
|
|
|
|
irp->CompletionId = g_completion_id++;
|
|
|
|
irp->completion_type = CID_CREATE_DIR_REQ;
|
|
|
|
irp->DeviceId = device_id;
|
|
|
|
irp->fuse_info = fusep;
|
|
|
|
|
|
|
|
DesiredAccess = DA_FILE_READ_DATA | DA_SYNCHRONIZE;
|
|
|
|
CreateOptions = CO_FILE_DIRECTORY_FILE |
|
|
|
|
CO_FILE_SYNCHRONOUS_IO_NONALERT;
|
|
|
|
CreateDisposition = CD_FILE_OPEN;
|
|
|
|
|
|
|
|
rval = devredir_send_drive_create_request(device_id, irp->pathname,
|
2020-11-30 03:36:20 +03:00
|
|
|
DesiredAccess, CreateOptions,
|
|
|
|
0, CreateDisposition,
|
|
|
|
irp->CompletionId);
|
2019-11-14 17:43:57 +03:00
|
|
|
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "looking for device_id=%d path=%s", device_id, irp->pathname);
|
2019-11-14 17:43:57 +03:00
|
|
|
|
2020-11-30 03:36:20 +03:00
|
|
|
/* when we get a response to devredir_send_drive_create_request(), we
|
2019-11-14 17:43:57 +03:00
|
|
|
* call devredir_send_drive_dir_request(), which needs the following
|
|
|
|
* at the end of the path argument */
|
|
|
|
if (devredir_string_ends_with(irp->pathname, '\\'))
|
|
|
|
{
|
|
|
|
strcat(irp->pathname, "*");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
strcat(irp->pathname, "\\*");
|
|
|
|
}
|
|
|
|
}
|
2013-03-09 03:37:30 +04:00
|
|
|
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
|
2019-11-14 17:43:57 +03:00
|
|
|
devredir_lookup_entry(struct state_lookup *fusep, tui32 device_id,
|
|
|
|
const char *path)
|
2019-03-21 19:48:01 +03:00
|
|
|
{
|
|
|
|
tui32 DesiredAccess;
|
|
|
|
tui32 CreateOptions;
|
|
|
|
tui32 CreateDisposition;
|
|
|
|
int rval = -1;
|
|
|
|
IRP *irp;
|
|
|
|
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "fusep=%p", fusep);
|
2019-03-21 19:48:01 +03:00
|
|
|
|
2019-11-14 17:43:57 +03:00
|
|
|
if ((irp = devredir_irp_with_pathname_new(path)) != NULL)
|
2019-03-21 19:48:01 +03:00
|
|
|
{
|
2019-11-14 17:43:57 +03:00
|
|
|
/* 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;
|
|
|
|
irp->DeviceId = device_id;
|
|
|
|
irp->gen.lookup.state = E_LOOKUP_GET_FH;
|
|
|
|
irp->fuse_info = fusep;
|
|
|
|
|
|
|
|
DesiredAccess = DA_FILE_READ_ATTRIBUTES | DA_SYNCHRONIZE;
|
|
|
|
CreateOptions = 0;
|
|
|
|
CreateDisposition = CD_FILE_OPEN;
|
|
|
|
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "lookup for device_id=%d path=%s CompletionId=%d",
|
2019-11-14 17:43:57 +03:00
|
|
|
device_id, irp->pathname, irp->CompletionId);
|
|
|
|
|
|
|
|
rval = devredir_send_drive_create_request(device_id,
|
2020-11-30 03:36:20 +03:00
|
|
|
irp->pathname,
|
|
|
|
DesiredAccess, CreateOptions,
|
|
|
|
0, CreateDisposition,
|
|
|
|
irp->CompletionId);
|
2019-03-21 19:48:01 +03:00
|
|
|
}
|
2019-11-14 17:43:57 +03:00
|
|
|
|
|
|
|
return rval;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* FUSE calls this function whenever it wants us to set the attributes for
|
|
|
|
* 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 filename the name of the file
|
|
|
|
* @param fattr the file attributes to set for the file
|
|
|
|
* @param to_set Which bits of the file attributes have changed
|
|
|
|
*
|
|
|
|
* @return 0 on success, -1 on failure
|
|
|
|
*****************************************************************************/
|
|
|
|
int
|
|
|
|
devredir_setattr_for_entry(struct state_setattr *fusep, tui32 device_id,
|
|
|
|
const char *filename,
|
|
|
|
const struct file_attr *fattr,
|
|
|
|
tui32 to_set)
|
|
|
|
{
|
|
|
|
tui32 DesiredAccess;
|
|
|
|
tui32 CreateOptions;
|
|
|
|
tui32 CreateDisposition;
|
|
|
|
int rval = -1;
|
|
|
|
IRP *irp;
|
|
|
|
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "fusep=%p", fusep);
|
2019-11-14 17:43:57 +03:00
|
|
|
|
|
|
|
if ((irp = devredir_irp_with_pathname_new(filename)) != NULL)
|
2019-03-21 19:48:01 +03:00
|
|
|
{
|
2019-11-14 17:43:57 +03:00
|
|
|
/* convert / to windows compatible \ */
|
|
|
|
devredir_cvt_slash(irp->pathname);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Allocate an IRP to open the file, update the attributes
|
|
|
|
* and close the file.
|
|
|
|
*/
|
|
|
|
irp->CompletionId = g_completion_id++;
|
|
|
|
irp->completion_type = CID_SETATTR;
|
|
|
|
irp->DeviceId = device_id;
|
|
|
|
irp->fuse_info = fusep;
|
|
|
|
|
|
|
|
irp->gen.setattr.state = E_SETATTR_GET_FH;
|
|
|
|
irp->gen.setattr.to_set = to_set;
|
|
|
|
irp->gen.setattr.fattr = *fattr;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Don't set DA_FILE_WRITE_DATA unless we're changing the
|
|
|
|
* EndOfFile pointer. Otherwise we can't change the attributes
|
|
|
|
* of read-only files! */
|
|
|
|
DesiredAccess = DA_FILE_WRITE_ATTRIBUTES;
|
|
|
|
if (to_set & TO_SET_SIZE)
|
2019-03-21 19:48:01 +03:00
|
|
|
{
|
2019-11-14 17:43:57 +03:00
|
|
|
DesiredAccess |= DA_FILE_WRITE_DATA;
|
2019-03-21 19:48:01 +03:00
|
|
|
}
|
2019-11-14 17:43:57 +03:00
|
|
|
CreateOptions = 0;
|
|
|
|
CreateDisposition = CD_FILE_OPEN;
|
|
|
|
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "lookup for device_id=%d path=%s",
|
2020-11-30 03:36:20 +03:00
|
|
|
device_id, irp->pathname);
|
2019-11-14 17:43:57 +03:00
|
|
|
|
|
|
|
rval = devredir_send_drive_create_request(device_id,
|
2020-11-30 03:36:20 +03:00
|
|
|
irp->pathname,
|
|
|
|
DesiredAccess, CreateOptions,
|
|
|
|
0, CreateDisposition,
|
|
|
|
irp->CompletionId);
|
2019-03-21 19:48:01 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return rval;
|
|
|
|
}
|
|
|
|
|
2017-03-12 19:35:00 +03:00
|
|
|
int
|
2019-11-14 17:43:57 +03:00
|
|
|
devredir_file_create(struct state_create *fusep, tui32 device_id,
|
|
|
|
const char *path, int mode)
|
2013-03-09 03:37:30 +04:00
|
|
|
{
|
|
|
|
tui32 DesiredAccess;
|
|
|
|
tui32 CreateOptions;
|
2019-11-14 17:43:57 +03:00
|
|
|
tui32 FileAttributes = 0;
|
2013-03-24 23:08:55 +04:00
|
|
|
tui32 CreateDisposition;
|
2019-11-14 17:43:57 +03:00
|
|
|
int rval = -1;
|
2013-03-09 03:37:30 +04:00
|
|
|
IRP *irp;
|
|
|
|
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "device_id=%d path=%s mode=0%o", device_id, path, mode);
|
2013-03-09 03:37:30 +04:00
|
|
|
|
2019-11-14 17:43:57 +03:00
|
|
|
if ((irp = devredir_irp_with_pathname_new(path)) != NULL)
|
2013-03-24 23:08:55 +04:00
|
|
|
{
|
2019-11-14 17:43:57 +03:00
|
|
|
/* convert / to windows compatible \ */
|
|
|
|
devredir_cvt_slash(irp->pathname);
|
2014-07-19 22:56:00 +04:00
|
|
|
|
2019-11-14 17:43:57 +03:00
|
|
|
irp->completion_type = CID_CREATE_REQ;
|
|
|
|
irp->CompletionId = g_completion_id++;
|
|
|
|
irp->DeviceId = device_id;
|
|
|
|
irp->fuse_info = fusep;
|
2013-03-09 03:37:30 +04:00
|
|
|
|
2020-10-08 04:55:08 +03:00
|
|
|
|
2013-05-06 05:42:17 +04:00
|
|
|
DesiredAccess = 0x0016019f; /* got this value from windows */
|
2019-11-14 17:43:57 +03:00
|
|
|
FileAttributes = LinuxToWindowsFilePerm(mode);
|
|
|
|
if (mode & S_IFDIR)
|
2013-03-09 03:37:30 +04:00
|
|
|
{
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "creating dir");
|
2013-03-09 03:37:30 +04:00
|
|
|
CreateOptions = CO_FILE_DIRECTORY_FILE | CO_FILE_SYNCHRONOUS_IO_NONALERT;
|
2019-11-14 17:43:57 +03:00
|
|
|
irp->gen.create.creating_dir = 1;
|
2013-03-09 03:37:30 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "creating file");
|
2013-05-06 05:42:17 +04:00
|
|
|
CreateOptions = 0x44; /* got this value from windows */
|
2019-11-14 17:43:57 +03:00
|
|
|
irp->gen.create.creating_dir = 0;
|
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 */
|
2019-11-14 17:43:57 +03:00
|
|
|
|
|
|
|
rval = devredir_send_drive_create_request(device_id, path,
|
2020-11-30 03:36:20 +03:00
|
|
|
DesiredAccess, CreateOptions,
|
|
|
|
FileAttributes,
|
|
|
|
CreateDisposition,
|
|
|
|
irp->CompletionId);
|
2013-03-09 03:37:30 +04:00
|
|
|
}
|
2019-03-13 13:56:37 +03:00
|
|
|
|
2019-11-14 17:43:57 +03:00
|
|
|
return rval;
|
|
|
|
}
|
2019-03-13 13:56:37 +03:00
|
|
|
|
2019-11-14 17:43:57 +03:00
|
|
|
int
|
|
|
|
devredir_file_open(struct state_open *fusep, tui32 device_id,
|
|
|
|
const char *path, int flags)
|
|
|
|
{
|
|
|
|
tui32 DesiredAccess;
|
|
|
|
tui32 CreateOptions;
|
|
|
|
tui32 FileAttributes = 0;
|
|
|
|
tui32 CreateDisposition;
|
|
|
|
int rval = -1;
|
|
|
|
IRP *irp;
|
|
|
|
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "device_id=%d path=%s flags=0%x",
|
2019-11-14 17:43:57 +03:00
|
|
|
device_id, path, flags);
|
|
|
|
|
|
|
|
if ((irp = devredir_irp_with_pathname_new(path)) != NULL)
|
|
|
|
{
|
|
|
|
/* convert / to windows compatible \ */
|
|
|
|
devredir_cvt_slash(irp->pathname);
|
|
|
|
|
|
|
|
irp->completion_type = CID_OPEN_REQ;
|
|
|
|
irp->CompletionId = g_completion_id++;
|
|
|
|
irp->DeviceId = device_id;
|
|
|
|
|
|
|
|
irp->fuse_info = fusep;
|
|
|
|
|
2020-11-30 03:36:20 +03:00
|
|
|
switch (flags & O_ACCMODE)
|
2019-11-14 17:43:57 +03:00
|
|
|
{
|
|
|
|
case O_RDONLY:
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "open file in O_RDONLY");
|
2019-11-14 17:43:57 +03:00
|
|
|
DesiredAccess = DA_FILE_READ_DATA | DA_SYNCHRONIZE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case O_WRONLY:
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "open file in O_WRONLY");
|
2019-11-14 17:43:57 +03:00
|
|
|
DesiredAccess = DA_FILE_WRITE_DATA | DA_SYNCHRONIZE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
/*
|
|
|
|
* The access mode could conceivably be invalid here,
|
2019-03-13 13:56:37 +03:00
|
|
|
* but we assume this has been checked by the caller
|
|
|
|
*/
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "open file in O_RDWR");
|
2019-03-13 13:56:37 +03:00
|
|
|
/* without the 0x00000010 rdesktop opens files in */
|
|
|
|
/* O_RDONLY instead of O_RDWR mode */
|
2020-11-30 03:36:20 +03:00
|
|
|
DesiredAccess = DA_FILE_READ_DATA | DA_FILE_WRITE_DATA |
|
2019-03-13 13:56:37 +03:00
|
|
|
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
|
|
|
|
2019-11-14 17:43:57 +03:00
|
|
|
rval = devredir_send_drive_create_request(device_id, path,
|
2020-11-30 03:36:20 +03:00
|
|
|
DesiredAccess, CreateOptions,
|
|
|
|
FileAttributes,
|
|
|
|
CreateDisposition,
|
|
|
|
irp->CompletionId);
|
2019-11-14 17:43:57 +03:00
|
|
|
}
|
2013-03-09 03:37:30 +04:00
|
|
|
|
|
|
|
return rval;
|
|
|
|
}
|
|
|
|
|
2019-11-14 17:43:57 +03:00
|
|
|
int devredir_file_close(struct state_close *fusep, tui32 device_id,
|
|
|
|
tui32 FileId)
|
2013-03-19 06:43:20 +04:00
|
|
|
{
|
|
|
|
IRP *irp;
|
|
|
|
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "entered: fusep=%p device_id=%d FileId=%d",
|
2013-05-19 06:44:16 +04:00
|
|
|
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)
|
2020-11-30 03:36:20 +03:00
|
|
|
{
|
2013-03-19 06:43:20 +04:00
|
|
|
return -1;
|
2020-11-30 03:36:20 +03:00
|
|
|
}
|
2013-03-19 06:43:20 +04:00
|
|
|
|
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
|
|
|
{
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_ERROR, "no IRP found with FileId = %d", FileId);
|
2013-03-31 02:51:50 +04:00
|
|
|
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;
|
2019-11-14 17:43:57 +03:00
|
|
|
irp->fuse_info = fusep;
|
|
|
|
|
|
|
|
return devredir_send_drive_close_request(RDPDR_CTYP_CORE,
|
2020-11-30 03:36:20 +03:00
|
|
|
PAKID_CORE_DEVICE_IOREQUEST,
|
|
|
|
device_id,
|
|
|
|
FileId,
|
|
|
|
irp->CompletionId,
|
|
|
|
IRP_MJ_CLOSE,
|
|
|
|
IRP_MN_NONE, 32);
|
2013-03-19 06:43:20 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
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
|
2019-11-14 17:43:57 +03:00
|
|
|
devredir_rmdir_or_file(struct state_remove *fusep, tui32 device_id,
|
|
|
|
const char *path)
|
2013-03-19 06:43:20 +04:00
|
|
|
{
|
|
|
|
tui32 DesiredAccess;
|
|
|
|
tui32 CreateOptions;
|
|
|
|
tui32 CreateDisposition;
|
2019-11-14 17:43:57 +03:00
|
|
|
int rval = -1;
|
2013-03-19 06:43:20 +04:00
|
|
|
IRP *irp;
|
|
|
|
|
2019-11-14 17:43:57 +03:00
|
|
|
if ((irp = devredir_irp_with_pathname_new(path)) != NULL)
|
|
|
|
{
|
|
|
|
/* convert / to windows compatible \ */
|
|
|
|
devredir_cvt_slash(irp->pathname);
|
2013-03-19 06:43:20 +04:00
|
|
|
|
2019-11-14 17:43:57 +03:00
|
|
|
irp->CompletionId = g_completion_id++;
|
|
|
|
irp->completion_type = CID_RMDIR_OR_FILE;
|
|
|
|
irp->DeviceId = device_id;
|
2014-07-19 22:56:00 +04:00
|
|
|
|
2019-11-14 17:43:57 +03:00
|
|
|
irp->fuse_info = fusep;
|
2013-03-19 06:43:20 +04:00
|
|
|
|
2019-11-14 17:43:57 +03: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
|
|
|
|
2019-11-14 17:43:57 +03: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
|
|
|
|
2019-11-14 17:43:57 +03:00
|
|
|
//CreateDisposition = CD_FILE_OPEN; // WAS 1
|
|
|
|
CreateDisposition = 0x01; /* got this value from windows */
|
2013-03-19 06:43:20 +04:00
|
|
|
|
2019-11-14 17:43:57 +03:00
|
|
|
rval = devredir_send_drive_create_request(device_id, path,
|
2020-11-30 03:36:20 +03:00
|
|
|
DesiredAccess, CreateOptions,
|
|
|
|
0, CreateDisposition,
|
|
|
|
irp->CompletionId);
|
2019-11-14 17:43:57 +03:00
|
|
|
}
|
2013-03-19 06:43:20 +04:00
|
|
|
|
|
|
|
return rval;
|
|
|
|
}
|
|
|
|
|
2013-03-09 03:37:30 +04:00
|
|
|
/**
|
|
|
|
* Read data from previously opened file
|
|
|
|
*
|
2020-03-03 13:02:32 +03:00
|
|
|
* Errors are reported via xfuse_devredir_cb_read_file()
|
2013-03-09 03:37:30 +04:00
|
|
|
*****************************************************************************/
|
|
|
|
|
2020-03-03 13:02:32 +03:00
|
|
|
void
|
2019-11-14 17:43:57 +03:00
|
|
|
devredir_file_read(struct state_read *fusep, tui32 DeviceId, tui32 FileId,
|
2013-07-24 07:57:38 +04:00
|
|
|
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
|
|
|
|
2019-11-14 17:43:57 +03:00
|
|
|
/* Check we've got an open IRP for this file already */
|
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
|
|
|
{
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_ERROR, "no IRP found with FileId = %d", FileId);
|
2020-03-03 13:02:32 +03:00
|
|
|
xfuse_devredir_cb_read_file(fusep, STATUS_UNSUCCESSFUL, NULL, 0);
|
2014-07-19 22:56:00 +04:00
|
|
|
xstream_free(s);
|
2013-03-09 03:37:30 +04:00
|
|
|
}
|
2013-06-03 02:33:51 +04:00
|
|
|
/* create a new IRP for this request */
|
2019-11-14 17:43:57 +03:00
|
|
|
else if ((new_irp = devredir_irp_new()) == NULL)
|
2013-06-03 02:33:51 +04:00
|
|
|
{
|
|
|
|
/* system out of memory */
|
2020-03-03 13:02:32 +03:00
|
|
|
xfuse_devredir_cb_read_file(fusep, STATUS_UNSUCCESSFUL, NULL, 0);
|
2014-07-19 22:56:00 +04:00
|
|
|
xstream_free(s);
|
2013-06-03 02:33:51 +04:00
|
|
|
}
|
2019-11-14 17:43:57 +03:00
|
|
|
else
|
|
|
|
{
|
|
|
|
new_irp->DeviceId = DeviceId;
|
|
|
|
new_irp->FileId = FileId;
|
|
|
|
new_irp->completion_type = CID_READ;
|
|
|
|
new_irp->CompletionId = g_completion_id++;
|
|
|
|
new_irp->fuse_info = fusep;
|
|
|
|
|
|
|
|
devredir_insert_DeviceIoRequest(s,
|
|
|
|
DeviceId,
|
|
|
|
FileId,
|
|
|
|
new_irp->CompletionId,
|
|
|
|
IRP_MJ_READ,
|
2019-12-05 19:44:52 +03:00
|
|
|
IRP_MN_NONE);
|
2019-11-14 17:43:57 +03: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
|
|
|
|
2019-11-14 17:43:57 +03:00
|
|
|
/* send to client */
|
|
|
|
bytes = xstream_len(s);
|
|
|
|
send_channel_data(g_rdpdr_chan_id, s->data, bytes);
|
|
|
|
xstream_free(s);
|
|
|
|
}
|
2013-03-09 03:37:30 +04:00
|
|
|
}
|
|
|
|
|
2020-03-03 13:02:32 +03:00
|
|
|
/**
|
|
|
|
* Read data from previously opened file
|
|
|
|
*
|
|
|
|
* Errors are reported via xfuse_devredir_cb_write_file()
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
void
|
2019-11-14 17:43:57 +03:00
|
|
|
devredir_file_write(struct state_write *fusep, tui32 DeviceId, tui32 FileId,
|
|
|
|
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;
|
|
|
|
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "DeviceId=%d FileId=%d Length=%d Offset=%lld",
|
2017-01-28 00:07:36 +03:00
|
|
|
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
|
|
|
{
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_ERROR, "no IRP found with FileId = %d", FileId);
|
2019-12-19 12:55:38 +03:00
|
|
|
xfuse_devredir_cb_write_file(fusep, STATUS_UNSUCCESSFUL, 0, 0);
|
2014-07-19 22:56:00 +04:00
|
|
|
xstream_free(s);
|
2013-03-09 03:37:30 +04:00
|
|
|
}
|
2013-06-03 02:33:51 +04:00
|
|
|
/* create a new IRP for this request */
|
2019-11-14 17:43:57 +03:00
|
|
|
else if ((new_irp = devredir_irp_new()) == NULL)
|
2013-06-03 02:33:51 +04:00
|
|
|
{
|
|
|
|
/* system out of memory */
|
2019-12-19 12:55:38 +03:00
|
|
|
xfuse_devredir_cb_write_file(fusep, STATUS_UNSUCCESSFUL, 0, 0);
|
2014-07-19 22:56:00 +04:00
|
|
|
xstream_free(s);
|
2013-06-03 02:33:51 +04:00
|
|
|
}
|
2019-11-14 17:43:57 +03:00
|
|
|
else
|
|
|
|
{
|
|
|
|
new_irp->DeviceId = DeviceId;
|
|
|
|
new_irp->FileId = FileId;
|
|
|
|
new_irp->completion_type = CID_WRITE;
|
|
|
|
new_irp->CompletionId = g_completion_id++;
|
|
|
|
new_irp->fuse_info = fusep;
|
|
|
|
/* Offset needed after write to calculate new EOF */
|
|
|
|
new_irp->gen.write.offset = Offset;
|
|
|
|
|
|
|
|
devredir_insert_DeviceIoRequest(s,
|
|
|
|
DeviceId,
|
|
|
|
FileId,
|
|
|
|
new_irp->CompletionId,
|
|
|
|
IRP_MJ_WRITE,
|
2019-12-05 19:44:52 +03:00
|
|
|
IRP_MN_NONE);
|
2019-11-14 17:43:57 +03:00
|
|
|
|
|
|
|
xstream_wr_u32_le(s, Length);
|
|
|
|
xstream_wr_u64_le(s, Offset);
|
|
|
|
xstream_seek(s, 20); /* padding */
|
|
|
|
|
|
|
|
/* now insert real data */
|
|
|
|
xstream_copyin(s, buf, Length);
|
2013-03-09 03:37:30 +04:00
|
|
|
|
2019-11-14 17:43:57 +03:00
|
|
|
/* send to client */
|
|
|
|
bytes = xstream_len(s);
|
|
|
|
send_channel_data(g_rdpdr_chan_id, s->data, bytes);
|
|
|
|
xstream_free(s);
|
|
|
|
}
|
2020-10-08 04:55:08 +03:00
|
|
|
|
2013-03-09 03:37:30 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-11-14 17:43:57 +03:00
|
|
|
int devredir_file_rename(struct state_rename *fusep, tui32 device_id,
|
|
|
|
const char *old_name,
|
|
|
|
const char *new_name)
|
2013-03-09 03:37:30 +04:00
|
|
|
{
|
2019-11-14 17:43:57 +03:00
|
|
|
tui32 DesiredAccess;
|
|
|
|
tui32 CreateOptions;
|
|
|
|
tui32 FileAttributes = 0;
|
|
|
|
tui32 CreateDisposition;
|
|
|
|
int rval = -1;
|
|
|
|
IRP *irp;
|
|
|
|
unsigned int len;
|
2020-11-30 03:36:20 +03:00
|
|
|
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "device_id=%d old_name=%s new_name=%s",
|
2019-11-14 17:43:57 +03:00
|
|
|
device_id, old_name, new_name);
|
2013-03-09 03:37:30 +04:00
|
|
|
|
2019-11-14 17:43:57 +03:00
|
|
|
/*
|
|
|
|
* Allocate an IRP with enough space for both the old and new names.
|
|
|
|
* We'll store the new name after the old name:-
|
|
|
|
*
|
|
|
|
* | n | a | m | e | 1 | \0 | n | a | m | e | 2 | \0 |
|
|
|
|
* ^ ^
|
|
|
|
* irp->pathname ----+ |
|
|
|
|
* irp->gen.rename.new_name ------------------+
|
|
|
|
*/
|
|
|
|
len = strlen(old_name) + 1 + strlen(new_name);
|
|
|
|
if ((irp = devredir_irp_with_pathnamelen_new(len)) != NULL)
|
2013-03-09 03:37:30 +04:00
|
|
|
{
|
2019-11-14 17:43:57 +03:00
|
|
|
/* Set up pointer to new name string */
|
|
|
|
irp->gen.rename.new_name = irp->pathname + strlen(old_name) + 1;
|
2013-03-09 03:37:30 +04:00
|
|
|
|
2019-11-14 17:43:57 +03:00
|
|
|
/* Copy both strings, and change'/' to '\\' characters */
|
|
|
|
strcpy(irp->pathname, old_name);
|
|
|
|
devredir_cvt_slash(irp->pathname);
|
|
|
|
strcpy(irp->gen.rename.new_name, new_name);
|
|
|
|
devredir_cvt_slash(irp->gen.rename.new_name);
|
2013-03-09 03:37:30 +04:00
|
|
|
|
2019-11-14 17:43:57 +03:00
|
|
|
irp->completion_type = CID_RENAME_FILE;
|
|
|
|
irp->CompletionId = g_completion_id++;
|
|
|
|
irp->DeviceId = device_id;
|
2013-03-09 03:37:30 +04:00
|
|
|
|
2019-11-14 17:43:57 +03:00
|
|
|
irp->fuse_info = fusep;
|
2013-03-09 03:37:30 +04:00
|
|
|
|
2019-11-14 17:43:57 +03:00
|
|
|
DesiredAccess = DA_FILE_WRITE_ATTRIBUTES | DA_DELETE;
|
|
|
|
CreateOptions = 0;
|
|
|
|
CreateDisposition = CD_FILE_OPEN; // WAS 1
|
2013-03-09 03:37:30 +04:00
|
|
|
|
2019-11-14 17:43:57 +03:00
|
|
|
rval = devredir_send_drive_create_request(device_id, old_name,
|
2020-11-30 03:36:20 +03:00
|
|
|
DesiredAccess, CreateOptions,
|
|
|
|
FileAttributes,
|
|
|
|
CreateDisposition,
|
|
|
|
irp->CompletionId);
|
2013-03-09 03:37:30 +04:00
|
|
|
}
|
|
|
|
|
2019-11-14 17:43:57 +03:00
|
|
|
return rval;
|
2013-03-09 03:37:30 +04:00
|
|
|
}
|
|
|
|
|
2019-11-14 17:43:57 +03:00
|
|
|
|
2013-03-09 03:37:30 +04:00
|
|
|
/******************************************************************************
|
|
|
|
** 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,
|
2019-11-14 17:43:57 +03:00
|
|
|
enum IRP_MJ MajorFunction,
|
|
|
|
enum IRP_MN 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 \
|
|
|
|
*****************************************************************************/
|
|
|
|
|
2019-11-14 17:43:57 +03:00
|
|
|
static 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 == '/')
|
2020-11-30 03:36:20 +03:00
|
|
|
{
|
2013-04-21 03:42:49 +04:00
|
|
|
*cptr = '\\';
|
2020-11-30 03:36:20 +03:00
|
|
|
}
|
2013-04-21 03:42:49 +04:00
|
|
|
cptr++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-14 17:43:57 +03:00
|
|
|
static 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
|
|
|
}
|
|
|
|
|
2019-11-14 17:43:57 +03:00
|
|
|
static 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
|
|
|
}
|
|
|
|
|
2019-11-14 17:43:57 +03:00
|
|
|
static int
|
|
|
|
devredir_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
|
|
|
}
|
|
|
|
|
2019-03-12 15:16:50 +03:00
|
|
|
static void
|
2019-12-05 19:44:52 +03:00
|
|
|
devredir_proc_cid_rmdir_or_file(IRP *irp, enum NTSTATUS IoStatus)
|
2013-03-19 06:43:20 +04:00
|
|
|
{
|
|
|
|
struct stream *s;
|
|
|
|
int bytes;
|
|
|
|
|
2019-12-19 12:55:38 +03:00
|
|
|
if (IoStatus != STATUS_SUCCESS)
|
2013-03-19 06:43:20 +04:00
|
|
|
{
|
2019-12-05 19:44:52 +03:00
|
|
|
xfuse_devredir_cb_rmdir_or_file((struct state_remove *) irp->fuse_info,
|
2020-11-30 03:36:20 +03:00
|
|
|
IoStatus);
|
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,
|
2019-12-05 19:44:52 +03:00
|
|
|
IRP_MJ_SET_INFORMATION, IRP_MN_NONE);
|
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
|
2019-12-05 19:44:52 +03:00
|
|
|
devredir_proc_cid_rmdir_or_file_resp(IRP *irp, enum NTSTATUS IoStatus)
|
2013-03-19 06:43:20 +04:00
|
|
|
{
|
2019-12-05 19:44:52 +03:00
|
|
|
xfuse_devredir_cb_rmdir_or_file((struct state_remove *)irp->fuse_info,
|
|
|
|
IoStatus);
|
2013-03-19 06:43:20 +04:00
|
|
|
|
2019-12-19 12:55:38 +03:00
|
|
|
if (IoStatus != STATUS_SUCCESS)
|
2013-03-19 06:43:20 +04:00
|
|
|
{
|
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;
|
2019-11-14 17:43:57 +03:00
|
|
|
devredir_send_drive_close_request(RDPDR_CTYP_CORE,
|
|
|
|
PAKID_CORE_DEVICE_IOREQUEST,
|
|
|
|
irp->DeviceId,
|
|
|
|
irp->FileId,
|
|
|
|
irp->CompletionId,
|
2019-12-05 19:44:52 +03:00
|
|
|
IRP_MJ_CLOSE, IRP_MN_NONE, 32);
|
2013-03-19 06:43:20 +04:00
|
|
|
}
|
2013-03-24 23:08:55 +04:00
|
|
|
|
2019-03-12 15:16:50 +03:00
|
|
|
static void
|
2019-12-05 19:44:52 +03:00
|
|
|
devredir_proc_cid_rename_file(IRP *irp, enum NTSTATUS 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
|
|
|
|
|
|
|
|
2019-12-19 12:55:38 +03:00
|
|
|
if (IoStatus != STATUS_SUCCESS)
|
2013-03-24 23:08:55 +04:00
|
|
|
{
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "rename returned with IoStatus=0x%x", IoStatus);
|
2013-05-06 05:42:17 +04:00
|
|
|
|
2019-12-05 19:44:52 +03:00
|
|
|
xfuse_devredir_cb_rename_file((struct state_rename *)irp->fuse_info,
|
|
|
|
IoStatus);
|
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-11-14 17:43:57 +03:00
|
|
|
flen = ((g_mbstowcs(NULL, irp->gen.rename.new_name, 0)
|
2020-11-30 03:36:20 +03:00
|
|
|
* 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,
|
2019-12-05 19:44:52 +03:00
|
|
|
IRP_MJ_SET_INFORMATION, IRP_MN_NONE);
|
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-11-14 17:43:57 +03:00
|
|
|
devredir_cvt_to_unicode(s->p, irp->gen.rename.new_name); /* 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
|
2019-12-05 19:44:52 +03:00
|
|
|
devredir_proc_cid_rename_file_resp(IRP *irp, enum NTSTATUS IoStatus)
|
2013-03-24 23:08:55 +04:00
|
|
|
{
|
2019-12-05 19:44:52 +03:00
|
|
|
xfuse_devredir_cb_rename_file((struct state_rename *)irp->fuse_info,
|
|
|
|
IoStatus);
|
2013-03-24 23:08:55 +04:00
|
|
|
|
2019-12-19 12:55:38 +03:00
|
|
|
if (IoStatus != STATUS_SUCCESS)
|
2013-03-24 23:08:55 +04:00
|
|
|
{
|
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;
|
2019-11-14 17:43:57 +03:00
|
|
|
devredir_send_drive_close_request(RDPDR_CTYP_CORE,
|
2020-11-30 03:36:20 +03:00
|
|
|
PAKID_CORE_DEVICE_IOREQUEST,
|
|
|
|
irp->DeviceId,
|
|
|
|
irp->FileId,
|
|
|
|
irp->CompletionId,
|
|
|
|
IRP_MJ_CLOSE, IRP_MN_NONE, 32);
|
2013-03-24 23:08:55 +04:00
|
|
|
}
|
2019-03-21 19:48:01 +03:00
|
|
|
|
2019-11-14 17:43:57 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Re-uses the specified IRP to issue a request to get file attributes
|
|
|
|
* of varying types
|
|
|
|
*
|
|
|
|
* References : [MS-RDPEFS] 2.2.3.3.9 [MS-FSCC] 2.4
|
|
|
|
*****************************************************************************/
|
|
|
|
static void issue_lookup(IRP *irp, int lookup_type)
|
2019-03-21 19:48:01 +03:00
|
|
|
{
|
|
|
|
struct stream *s;
|
|
|
|
int bytes;
|
|
|
|
|
2019-11-14 17:43:57 +03:00
|
|
|
bytes =
|
|
|
|
lookup_type == FileBasicInformation ? FILE_BASIC_INFORMATION_SIZE :
|
|
|
|
lookup_type == FileStandardInformation ? FILE_STD_INFORMATION_SIZE :
|
|
|
|
0;
|
|
|
|
xstream_new(s, 1024);
|
|
|
|
devredir_insert_DeviceIoRequest(s, irp->DeviceId, irp->FileId,
|
|
|
|
irp->CompletionId,
|
2019-12-05 19:44:52 +03:00
|
|
|
IRP_MJ_QUERY_INFORMATION, IRP_MN_NONE);
|
2019-03-21 19:48:01 +03:00
|
|
|
|
2019-11-14 17:43:57 +03:00
|
|
|
xstream_wr_u32_le(s, lookup_type);
|
|
|
|
xstream_wr_u32_le(s, bytes); /* buffer length */
|
|
|
|
xstream_seek(s, 24); /* padding */
|
|
|
|
xstream_seek(s, bytes); /* buffer */
|
|
|
|
|
|
|
|
/* send to client */
|
|
|
|
bytes = xstream_len(s);
|
|
|
|
send_channel_data(g_rdpdr_chan_id, s->data, bytes);
|
|
|
|
xstream_free(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Parses an incoming FileBasicInformation structure
|
|
|
|
*****************************************************************************/
|
|
|
|
static void lookup_read_basic_attributes(IRP *irp, struct stream *s_in)
|
|
|
|
{
|
|
|
|
tui64 LastAccessTime;
|
|
|
|
tui64 LastWriteTime;
|
|
|
|
tui32 FileAttributes;
|
|
|
|
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "processing FILE_BASIC_INFORMATION");
|
2019-11-14 17:43:57 +03:00
|
|
|
|
|
|
|
xstream_seek(s_in, 8); /* 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);
|
|
|
|
|
2020-10-08 04:55:08 +03:00
|
|
|
//LOG_DEVEL(LOG_LEVEL_DEBUG, "LastAccessTime: 0x%llx",
|
2019-11-14 17:43:57 +03:00
|
|
|
// (unsigned long long)LastAccessTime);
|
2020-10-08 04:55:08 +03:00
|
|
|
//LOG_DEVEL(LOG_LEVEL_DEBUG, "LastWriteTime: 0x%llx",
|
2019-11-14 17:43:57 +03:00
|
|
|
// (unsigned long long)LastWriteTime);
|
2020-10-08 04:55:08 +03:00
|
|
|
//LOG_DEVEL(LOG_LEVEL_DEBUG, "ChangeTime: 0x%llx",
|
2019-11-14 17:43:57 +03:00
|
|
|
// (unsigned long long)ChangeTime);
|
2020-10-08 04:55:08 +03:00
|
|
|
//LOG_DEVEL(LOG_LEVEL_DEBUG, "FileAttributes: 0x%x", (unsigned int)FileAttributes);
|
2019-11-14 17:43:57 +03:00
|
|
|
|
|
|
|
/* Save the basic attributes in the IRP */
|
|
|
|
irp->gen.lookup.fattr.mode = WindowsToLinuxFilePerm(FileAttributes);
|
|
|
|
irp->gen.lookup.fattr.atime = WINDOWS_TO_LINUX_TIME(LastAccessTime);
|
|
|
|
irp->gen.lookup.fattr.mtime = WINDOWS_TO_LINUX_TIME(LastWriteTime);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Parses an incoming FileStandardInformation structure
|
|
|
|
*****************************************************************************/
|
|
|
|
static void lookup_read_standard_attributes(IRP *irp, struct stream *s_in)
|
|
|
|
{
|
|
|
|
tui64 EndOfFile;
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "processing FILE_STD_INFORMATION");
|
2019-11-14 17:43:57 +03:00
|
|
|
xstream_seek(s_in, 8); /* AllocationSize */
|
|
|
|
xstream_rd_u64_le(s_in, EndOfFile);
|
2020-10-08 04:55:08 +03:00
|
|
|
//LOG_DEVEL(LOG_LEVEL_DEBUG, "EndOfFile: %lld",
|
2019-11-14 17:43:57 +03:00
|
|
|
// (unsigned long long)EndOfFile);
|
|
|
|
|
|
|
|
irp->gen.lookup.fattr.size = EndOfFile;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Completes a lookup request and returns status to the caller.
|
|
|
|
*
|
2019-12-19 12:55:38 +03:00
|
|
|
* Unless IoStatus is STATUS_SUCCESS, the lookup has failed.
|
2019-11-14 17:43:57 +03:00
|
|
|
*****************************************************************************/
|
2019-12-05 19:44:52 +03:00
|
|
|
static void lookup_done(IRP *irp, enum NTSTATUS IoStatus)
|
2019-11-14 17:43:57 +03:00
|
|
|
{
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "Lookup with completion_id=%d returning 0x%x",
|
2020-11-30 03:36:20 +03:00
|
|
|
irp->CompletionId, IoStatus);
|
2019-12-05 19:44:52 +03:00
|
|
|
xfuse_devredir_cb_lookup_entry((struct state_lookup *)irp->fuse_info,
|
|
|
|
IoStatus,
|
2019-11-14 17:43:57 +03:00
|
|
|
&irp->gen.lookup.fattr);
|
|
|
|
|
|
|
|
if (irp->FileId == 0)
|
|
|
|
{
|
|
|
|
/* Open failed - no file handle */
|
2019-03-21 19:48:01 +03:00
|
|
|
devredir_irp_delete(irp);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-11-14 17:43:57 +03:00
|
|
|
/* Close the file handle */
|
|
|
|
irp->completion_type = CID_CLOSE;
|
|
|
|
devredir_send_drive_close_request(RDPDR_CTYP_CORE,
|
2020-11-30 03:36:20 +03:00
|
|
|
PAKID_CORE_DEVICE_IOREQUEST,
|
|
|
|
irp->DeviceId,
|
|
|
|
irp->FileId,
|
|
|
|
irp->CompletionId,
|
|
|
|
IRP_MJ_CLOSE, IRP_MN_NONE, 32);
|
2019-03-21 19:48:01 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-14 17:43:57 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* lookup has a mini state machine built-in, as it needs to issue
|
|
|
|
* multiple I/O requests, but unlike lookup these are not always the same.
|
|
|
|
*/
|
2019-03-21 19:48:01 +03:00
|
|
|
static void
|
2019-11-14 17:43:57 +03:00
|
|
|
devredir_proc_cid_lookup(IRP *irp,
|
|
|
|
struct stream *s_in,
|
2019-12-05 19:44:52 +03:00
|
|
|
enum NTSTATUS IoStatus)
|
2019-03-21 19:48:01 +03:00
|
|
|
{
|
2019-11-14 17:43:57 +03:00
|
|
|
tui32 Length;
|
2019-03-21 19:48:01 +03:00
|
|
|
|
2020-11-30 03:36:20 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "entry state is %d", irp->gen.lookup.state);
|
2019-12-19 12:55:38 +03:00
|
|
|
if (IoStatus != STATUS_SUCCESS)
|
2019-11-14 17:43:57 +03:00
|
|
|
{
|
|
|
|
/* This is common to all setattr states */
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "last lookup returned with IoStatus=0x%08x", IoStatus);
|
2019-11-14 17:43:57 +03:00
|
|
|
lookup_done(irp, IoStatus);
|
|
|
|
}
|
|
|
|
else
|
2019-03-21 19:48:01 +03:00
|
|
|
{
|
2019-11-14 17:43:57 +03:00
|
|
|
/* Read and validate any data we've got queued up */
|
2020-11-30 03:36:20 +03:00
|
|
|
switch (irp->gen.lookup.state)
|
2019-03-21 19:48:01 +03:00
|
|
|
{
|
2019-11-14 17:43:57 +03:00
|
|
|
case E_LOOKUP_GET_FH:
|
|
|
|
/* We've been sent the file ID */
|
|
|
|
xstream_rd_u32_le(s_in, irp->FileId);
|
|
|
|
issue_lookup(irp, FileBasicInformation);
|
|
|
|
irp->gen.lookup.state = E_LOOKUP_CHECK_BASIC;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case E_LOOKUP_CHECK_BASIC:
|
|
|
|
/* Returned length what we expected? */
|
|
|
|
xstream_rd_u32_le(s_in, Length);
|
|
|
|
if (Length != FILE_BASIC_INFORMATION_SIZE)
|
|
|
|
{
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_ERROR, "Expected FILE_BASIC_INFORMATION length"
|
2019-11-14 17:43:57 +03:00
|
|
|
"%d, got len=%d",
|
|
|
|
FILE_BASIC_INFORMATION_SIZE, Length);
|
2019-12-19 12:55:38 +03:00
|
|
|
IoStatus = STATUS_UNSUCCESSFUL;
|
2019-11-14 17:43:57 +03:00
|
|
|
lookup_done(irp, IoStatus);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
lookup_read_basic_attributes(irp, s_in);
|
|
|
|
issue_lookup(irp, FileStandardInformation);
|
|
|
|
irp->gen.lookup.state = E_LOOKUP_CHECK_EOF;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case E_LOOKUP_CHECK_EOF:
|
|
|
|
/* Returned length what we expected? */
|
|
|
|
xstream_rd_u32_le(s_in, Length);
|
|
|
|
if (Length != FILE_STD_INFORMATION_SIZE)
|
|
|
|
{
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_ERROR, "Expected FILE_STD_INFORMATION length"
|
2019-11-14 17:43:57 +03:00
|
|
|
"%d, got len=%d",
|
|
|
|
FILE_STD_INFORMATION_SIZE, Length);
|
2019-12-19 12:55:38 +03:00
|
|
|
IoStatus = STATUS_UNSUCCESSFUL;
|
2019-11-14 17:43:57 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
lookup_read_standard_attributes(irp, s_in);
|
|
|
|
}
|
|
|
|
lookup_done(irp, IoStatus);
|
|
|
|
break;
|
2019-03-21 19:48:01 +03:00
|
|
|
}
|
|
|
|
}
|
2019-11-14 17:43:57 +03:00
|
|
|
}
|
|
|
|
|
2019-03-21 19:48:01 +03:00
|
|
|
|
2019-11-14 17:43:57 +03:00
|
|
|
/*
|
|
|
|
* Re-uses the specified IRP to issue a request to set basic file attributes
|
|
|
|
*
|
|
|
|
* References : [MS-RDPEFS] 2.2.3.3.9 [MS-FSCC] 2.4.7
|
|
|
|
*****************************************************************************/
|
|
|
|
static void issue_setattr_basic(IRP *irp)
|
|
|
|
{
|
|
|
|
struct stream *s;
|
|
|
|
int bytes;
|
|
|
|
const struct file_attr *fattr = &irp->gen.setattr.fattr;
|
|
|
|
tui32 to_set = irp->gen.setattr.to_set;
|
|
|
|
|
|
|
|
tui32 FileAttributes = 0;
|
|
|
|
tui64 atime = 0;
|
|
|
|
tui64 mtime = 0;
|
|
|
|
|
|
|
|
if (to_set & TO_SET_MODE)
|
2019-03-21 19:48:01 +03:00
|
|
|
{
|
2019-11-14 17:43:57 +03:00
|
|
|
FileAttributes = LinuxToWindowsFilePerm(fattr->mode);
|
2019-03-21 19:48:01 +03:00
|
|
|
}
|
2019-11-14 17:43:57 +03:00
|
|
|
if (to_set & TO_SET_ATIME)
|
|
|
|
{
|
|
|
|
atime = LINUX_TO_WINDOWS_TIME(fattr->atime);
|
|
|
|
}
|
|
|
|
if (to_set & TO_SET_MTIME)
|
2019-03-21 19:48:01 +03:00
|
|
|
{
|
2019-11-14 17:43:57 +03:00
|
|
|
mtime = LINUX_TO_WINDOWS_TIME(fattr->mtime);
|
2019-03-21 19:48:01 +03:00
|
|
|
}
|
2019-11-14 17:43:57 +03:00
|
|
|
|
|
|
|
xstream_new(s, 1024);
|
|
|
|
devredir_insert_DeviceIoRequest(s, irp->DeviceId, irp->FileId,
|
|
|
|
irp->CompletionId,
|
2019-12-05 19:44:52 +03:00
|
|
|
IRP_MJ_SET_INFORMATION, IRP_MN_NONE);
|
2019-11-14 17:43:57 +03:00
|
|
|
|
|
|
|
xstream_wr_u32_le(s, FileBasicInformation);
|
|
|
|
xstream_wr_u32_le(s, FILE_BASIC_INFORMATION_SIZE);
|
2020-11-30 03:36:20 +03:00
|
|
|
/* buffer length */
|
2019-11-14 17:43:57 +03:00
|
|
|
xstream_seek(s, 24); /* padding */
|
|
|
|
|
|
|
|
xstream_wr_u64_le(s, 0LL); /* CreationTime */
|
|
|
|
xstream_wr_u64_le(s, atime); /* LastAccessTime */
|
|
|
|
xstream_wr_u64_le(s, mtime); /* LastWriteTime */
|
|
|
|
xstream_wr_u64_le(s, 0LL); /* ChangeTime */
|
|
|
|
xstream_wr_u32_le(s, FileAttributes); /* FileAttributes */
|
|
|
|
|
|
|
|
/* send to client */
|
|
|
|
bytes = xstream_len(s);
|
|
|
|
send_channel_data(g_rdpdr_chan_id, s->data, bytes);
|
|
|
|
xstream_free(s);
|
2019-03-21 19:48:01 +03:00
|
|
|
}
|
|
|
|
|
2019-11-14 17:43:57 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Re-uses the specified IRP to issue a request to set file EOF
|
|
|
|
*
|
|
|
|
* References : [MS-RDPEFS] 2.2.3.3.9 [MS-FSCC] 2.4.13
|
|
|
|
*****************************************************************************/
|
|
|
|
static void issue_setattr_eof(IRP *irp)
|
2019-03-21 19:48:01 +03:00
|
|
|
{
|
|
|
|
struct stream *s;
|
|
|
|
int bytes;
|
|
|
|
|
|
|
|
xstream_new(s, 1024);
|
|
|
|
devredir_insert_DeviceIoRequest(s, irp->DeviceId, irp->FileId,
|
|
|
|
irp->CompletionId,
|
2019-12-05 19:44:52 +03:00
|
|
|
IRP_MJ_SET_INFORMATION, IRP_MN_NONE);
|
2019-03-21 19:48:01 +03:00
|
|
|
|
2019-11-14 17:43:57 +03:00
|
|
|
xstream_wr_u32_le(s, FileEndOfFileInformation);
|
|
|
|
xstream_wr_u32_le(s, FILE_END_OF_FILE_INFORMATION_SIZE);
|
2020-11-30 03:36:20 +03:00
|
|
|
/* buffer length */
|
2019-03-21 19:48:01 +03:00
|
|
|
xstream_seek(s, 24); /* padding */
|
2019-12-05 19:44:52 +03:00
|
|
|
xstream_wr_u64_le(s, (tui64)irp->gen.setattr.fattr.size);
|
2020-11-30 03:36:20 +03:00
|
|
|
/* File size */
|
2019-03-21 19:48:01 +03:00
|
|
|
/* send to client */
|
|
|
|
bytes = xstream_len(s);
|
|
|
|
send_channel_data(g_rdpdr_chan_id, s->data, bytes);
|
|
|
|
xstream_free(s);
|
|
|
|
}
|
|
|
|
|
2019-11-14 17:43:57 +03:00
|
|
|
/*
|
|
|
|
* Completes a setattr request and returns status to the caller.
|
|
|
|
*****************************************************************************/
|
2019-12-05 19:44:52 +03:00
|
|
|
static void setattr_done(IRP *irp, enum NTSTATUS IoStatus)
|
2019-11-14 17:43:57 +03:00
|
|
|
{
|
2019-12-05 19:44:52 +03:00
|
|
|
xfuse_devredir_cb_setattr((struct state_setattr *) irp->fuse_info,
|
|
|
|
IoStatus);
|
2019-11-14 17:43:57 +03:00
|
|
|
|
|
|
|
if (irp->FileId == 0)
|
|
|
|
{
|
|
|
|
/* Open failed - no file handle */
|
|
|
|
devredir_irp_delete(irp);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Close the file handle */
|
|
|
|
irp->completion_type = CID_CLOSE;
|
|
|
|
devredir_send_drive_close_request(RDPDR_CTYP_CORE,
|
2020-11-30 03:36:20 +03:00
|
|
|
PAKID_CORE_DEVICE_IOREQUEST,
|
|
|
|
irp->DeviceId,
|
|
|
|
irp->FileId,
|
|
|
|
irp->CompletionId,
|
|
|
|
IRP_MJ_CLOSE, IRP_MN_NONE, 32);
|
2019-11-14 17:43:57 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* setattr has a mini state machine built-in, as it needs to issue
|
|
|
|
* multiple I/O requests, but unlike lookup these are not always the same.
|
|
|
|
*/
|
2019-03-21 19:48:01 +03:00
|
|
|
static void
|
2019-11-14 17:43:57 +03:00
|
|
|
devredir_proc_cid_setattr(IRP *irp,
|
|
|
|
struct stream *s_in,
|
2019-12-05 19:44:52 +03:00
|
|
|
enum NTSTATUS IoStatus)
|
2019-03-21 19:48:01 +03:00
|
|
|
{
|
2019-11-14 17:43:57 +03:00
|
|
|
#define TO_SET_BASIC_ATTRS (TO_SET_MODE | \
|
|
|
|
TO_SET_ATIME | TO_SET_MTIME)
|
2019-03-21 19:48:01 +03:00
|
|
|
tui32 Length;
|
|
|
|
|
2020-11-30 03:36:20 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "entry state is %d", irp->gen.setattr.state);
|
2019-12-19 12:55:38 +03:00
|
|
|
if (IoStatus != STATUS_SUCCESS)
|
2019-03-21 19:48:01 +03:00
|
|
|
{
|
2019-11-14 17:43:57 +03:00
|
|
|
/* This is common to all setattr states */
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "last setattr returned with IoStatus=0x%08x", IoStatus);
|
2019-11-14 17:43:57 +03:00
|
|
|
setattr_done(irp, IoStatus);
|
2019-03-21 19:48:01 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-11-14 17:43:57 +03:00
|
|
|
/* Read and validate any data we've got queued up */
|
2020-11-30 03:36:20 +03:00
|
|
|
switch (irp->gen.setattr.state)
|
2019-03-21 19:48:01 +03:00
|
|
|
{
|
2019-11-14 17:43:57 +03:00
|
|
|
case E_SETATTR_GET_FH:
|
|
|
|
/* We've been sent the file ID */
|
|
|
|
xstream_rd_u32_le(s_in, irp->FileId);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case E_SETATTR_CHECK_BASIC:
|
|
|
|
/* Returned length what we expected? */
|
|
|
|
xstream_rd_u32_le(s_in, Length);
|
|
|
|
if (Length != FILE_BASIC_INFORMATION_SIZE)
|
|
|
|
{
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_ERROR, "Expected FILE_BASIC_INFORMATION length"
|
2019-11-14 17:43:57 +03:00
|
|
|
"%d, got len=%d",
|
|
|
|
FILE_BASIC_INFORMATION_SIZE, Length);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Clear the basic bits so we don't end up in here again */
|
|
|
|
irp->gen.setattr.to_set &= ~TO_SET_BASIC_ATTRS;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case E_SETATTR_CHECK_EOF:
|
|
|
|
/* Returned length what we expected? */
|
|
|
|
xstream_rd_u32_le(s_in, Length);
|
|
|
|
if (Length != FILE_END_OF_FILE_INFORMATION_SIZE)
|
|
|
|
{
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_ERROR, "Expected FILE_END_OF_FILE_INFORMATION length"
|
2019-11-14 17:43:57 +03:00
|
|
|
"%d, got len=%d",
|
|
|
|
FILE_END_OF_FILE_INFORMATION_SIZE, Length);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Clear the size bits so we don't end up in here again */
|
|
|
|
irp->gen.setattr.to_set &= ~TO_SET_SIZE;
|
|
|
|
break;
|
2019-03-21 19:48:01 +03:00
|
|
|
}
|
|
|
|
|
2019-11-14 17:43:57 +03:00
|
|
|
/* Work out the next call to issue */
|
|
|
|
if (irp->gen.setattr.to_set & TO_SET_BASIC_ATTRS)
|
|
|
|
{
|
|
|
|
issue_setattr_basic(irp);
|
|
|
|
irp->gen.setattr.state = E_SETATTR_CHECK_BASIC;
|
|
|
|
}
|
|
|
|
else if (irp->gen.setattr.to_set & TO_SET_SIZE)
|
|
|
|
{
|
|
|
|
issue_setattr_eof(irp);
|
|
|
|
irp->gen.setattr.state = E_SETATTR_CHECK_EOF;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
setattr_done(irp, IoStatus);
|
|
|
|
}
|
2019-03-21 19:48:01 +03:00
|
|
|
}
|
2019-11-14 17:43:57 +03:00
|
|
|
#undef TO_SET_BASIC_ATTRS
|
2019-03-21 19:48:01 +03:00
|
|
|
}
|