cscg24-guacamole

CSCG 2024 Challenge 'Guacamole Mashup'
git clone https://git.sinitax.com/sinitax/cscg24-guacamole
Log | Files | Refs | sfeed.txt

rdpdr.h (10572B)


      1/**
      2 * FreeRDP: A Remote Desktop Protocol Implementation
      3 * Device Redirection Virtual Channel
      4 *
      5 * Copyright 2010-2011 Vic Lee
      6 * Copyright 2010-2012 Marc-Andre Moreau <marcandre.moreau@gmail.com>
      7 * Copyright 2015 Thincast Technologies GmbH
      8 * Copyright 2015 DI (FH) Martin Haimberger <martin.haimberger@thincast.com>
      9 *
     10 * Licensed under the Apache License, Version 2.0 (the "License");
     11 * you may not use this file except in compliance with the License.
     12 * You may obtain a copy of the License at
     13 *
     14 *     http://www.apache.org/licenses/LICENSE-2.0
     15 *
     16 * Unless required by applicable law or agreed to in writing, software
     17 * distributed under the License is distributed on an "AS IS" BASIS,
     18 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     19 * See the License for the specific language governing permissions and
     20 * limitations under the License.
     21 */
     22
     23#ifndef FREERDP_CHANNEL_RDPDR_H
     24#define FREERDP_CHANNEL_RDPDR_H
     25
     26#include <winpr/nt.h>
     27#include <winpr/io.h>
     28#include <winpr/crt.h>
     29#include <winpr/file.h>
     30#include <winpr/synch.h>
     31#include <winpr/thread.h>
     32#include <winpr/stream.h>
     33#include <winpr/interlocked.h>
     34#include <winpr/collections.h>
     35
     36#include <freerdp/freerdp.h>
     37
     38#define RDPDR_DEVICE_IO_REQUEST_LENGTH 24
     39#define RDPDR_DEVICE_IO_RESPONSE_LENGTH 16
     40
     41#define RDPDR_DEVICE_IO_CONTROL_REQ_HDR_LENGTH 32
     42#define RDPDR_DEVICE_IO_CONTROL_RSP_HDR_LENGTH 4
     43
     44/* RDPDR_HEADER.Component */
     45enum RDPDR_CTYP
     46{
     47	RDPDR_CTYP_CORE = 0x4472,
     48	RDPDR_CTYP_PRN = 0x5052
     49};
     50
     51/* RDPDR_HEADER.PacketId */
     52enum RDPDR_PAKID
     53{
     54	PAKID_CORE_SERVER_ANNOUNCE = 0x496E,
     55	PAKID_CORE_CLIENTID_CONFIRM = 0x4343,
     56	PAKID_CORE_CLIENT_NAME = 0x434E,
     57	PAKID_CORE_DEVICELIST_ANNOUNCE = 0x4441,
     58	PAKID_CORE_DEVICE_REPLY = 0x6472,
     59	PAKID_CORE_DEVICE_IOREQUEST = 0x4952,
     60	PAKID_CORE_DEVICE_IOCOMPLETION = 0x4943,
     61	PAKID_CORE_SERVER_CAPABILITY = 0x5350,
     62	PAKID_CORE_CLIENT_CAPABILITY = 0x4350,
     63	PAKID_CORE_DEVICELIST_REMOVE = 0x444D,
     64	PAKID_CORE_USER_LOGGEDON = 0x554C,
     65	PAKID_PRN_CACHE_DATA = 0x5043,
     66	PAKID_PRN_USING_XPS = 0x5543
     67};
     68
     69/* CAPABILITY_HEADER.CapabilityType */
     70enum RDPDR_CAP_TYPE
     71{
     72	CAP_GENERAL_TYPE = 0x0001,
     73	CAP_PRINTER_TYPE = 0x0002,
     74	CAP_PORT_TYPE = 0x0003,
     75	CAP_DRIVE_TYPE = 0x0004,
     76	CAP_SMARTCARD_TYPE = 0x0005
     77};
     78
     79/* CAPABILITY_HEADER.Version */
     80enum RDPDR_CAP_VERSION
     81{
     82	GENERAL_CAPABILITY_VERSION_01 = 0x00000001,
     83	GENERAL_CAPABILITY_VERSION_02 = 0x00000002,
     84	PRINT_CAPABILITY_VERSION_01 = 0x00000001,
     85	PORT_CAPABILITY_VERSION_01 = 0x00000001,
     86	DRIVE_CAPABILITY_VERSION_01 = 0x00000001,
     87	DRIVE_CAPABILITY_VERSION_02 = 0x00000002,
     88	SMARTCARD_CAPABILITY_VERSION_01 = 0x00000001
     89};
     90
     91/* DR_DEVICE_IOREQUEST.MajorFunction */
     92enum IRP_MJ
     93{
     94	IRP_MJ_CREATE = 0x00000000,
     95	IRP_MJ_CLOSE = 0x00000002,
     96	IRP_MJ_READ = 0x00000003,
     97	IRP_MJ_WRITE = 0x00000004,
     98	IRP_MJ_DEVICE_CONTROL = 0x0000000E,
     99	IRP_MJ_QUERY_VOLUME_INFORMATION = 0x0000000A,
    100	IRP_MJ_SET_VOLUME_INFORMATION = 0x0000000B,
    101	IRP_MJ_QUERY_INFORMATION = 0x00000005,
    102	IRP_MJ_SET_INFORMATION = 0x00000006,
    103	IRP_MJ_DIRECTORY_CONTROL = 0x0000000C,
    104	IRP_MJ_LOCK_CONTROL = 0x00000011
    105};
    106
    107/* DR_DEVICE_IOREQUEST.MinorFunction */
    108enum IRP_MN
    109{
    110	IRP_MN_QUERY_DIRECTORY = 0x00000001,
    111	IRP_MN_NOTIFY_CHANGE_DIRECTORY = 0x00000002
    112};
    113
    114/* DR_CREATE_REQ.CreateDisposition */
    115
    116/* DR_CREATE_REQ.CreateOptions [MS-SMB2] */
    117
    118/* DR_CREATE_REQ.DesiredAccess [MS-SMB2] */
    119
    120/* DR_CREATE_RSP.Information */
    121/* DR_DRIVE_CREATE_RSP.DeviceCreateResponse */
    122
    123#define FILE_OPENED 0x00000001
    124#define FILE_OVERWRITTEN 0x00000003
    125
    126/* DR_CORE_CLIENT_ANNOUNCE_RSP.VersionMinor */
    127enum RDPDR_MINOR_RDP_VERSION
    128{
    129	RDPDR_MINOR_RDP_VERSION_5_0 = 0x0002,
    130	RDPDR_MINOR_RDP_VERSION_5_1 = 0x0005,
    131	RDPDR_MINOR_RDP_VERSION_5_2 = 0x000A,
    132	RDPDR_MINOR_RDP_VERSION_6_X = 0x000C
    133};
    134
    135/* DR_CORE_CLIENT_NAME_REQ.UnicodeFlag */
    136enum RDPDR_CLIENT_NAME_FLAG
    137{
    138	RDPDR_CLIENT_NAME_UNICODE = 0x00000001,
    139	RDPDR_CLIENT_NAME_ASCII = 0x00000000
    140};
    141
    142/* GENERAL_CAPS_SET.ioCode1 */
    143enum RDPDR_CAPS_IRP_MJ
    144{
    145	RDPDR_IRP_MJ_CREATE = 0x00000001,
    146	RDPDR_IRP_MJ_CLEANUP = 0x00000002,
    147	RDPDR_IRP_MJ_CLOSE = 0x00000004,
    148	RDPDR_IRP_MJ_READ = 0x00000008,
    149	RDPDR_IRP_MJ_WRITE = 0x00000010,
    150	RDPDR_IRP_MJ_FLUSH_BUFFERS = 0x00000020,
    151	RDPDR_IRP_MJ_SHUTDOWN = 0x00000040,
    152	RDPDR_IRP_MJ_DEVICE_CONTROL = 0x00000080,
    153	RDPDR_IRP_MJ_QUERY_VOLUME_INFORMATION = 0x00000100,
    154	RDPDR_IRP_MJ_SET_VOLUME_INFORMATION = 0x00000200,
    155	RDPDR_IRP_MJ_QUERY_INFORMATION = 0x00000400,
    156	RDPDR_IRP_MJ_SET_INFORMATION = 0x00000800,
    157	RDPDR_IRP_MJ_DIRECTORY_CONTROL = 0x00001000,
    158	RDPDR_IRP_MJ_LOCK_CONTROL = 0x00002000,
    159	RDPDR_IRP_MJ_QUERY_SECURITY = 0x00004000,
    160	RDPDR_IRP_MJ_SET_SECURITY = 0x00008000
    161};
    162
    163/* GENERAL_CAPS_SET.extendedPDU */
    164enum RDPDR_CAPS_PDU
    165{
    166	RDPDR_DEVICE_REMOVE_PDUS = 0x00000001,
    167	RDPDR_CLIENT_DISPLAY_NAME_PDU = 0x00000002,
    168	RDPDR_USER_LOGGEDON_PDU = 0x00000004
    169};
    170
    171/* GENERAL_CAPS_SET.extraFlags1 */
    172enum RDPDR_CAPS_FLAG
    173{
    174	ENABLE_ASYNCIO = 0x00000001
    175};
    176
    177/* DR_DRIVE_LOCK_REQ.Operation */
    178enum RDP_LOWIO_OP
    179{
    180	RDP_LOWIO_OP_SHAREDLOCK = 0x00000002,
    181	RDP_LOWIO_OP_EXCLUSIVELOCK = 0x00000003,
    182	RDP_LOWIO_OP_UNLOCK = 0x00000004,
    183	RDP_LOWIO_OP_UNLOCK_MULTIPLE = 0x00000005
    184};
    185
    186enum RDPDR_PRINTER_ANNOUNCE_FLAG
    187{
    188	RDPDR_PRINTER_ANNOUNCE_FLAG_ASCII = 0x00000001,
    189	RDPDR_PRINTER_ANNOUNCE_FLAG_DEFAULTPRINTER = 0x00000002,
    190	RDPDR_PRINTER_ANNOUNCE_FLAG_NETWORKPRINTER = 0x00000004,
    191	RDPDR_PRINTER_ANNOUNCE_FLAG_TSPRINTER = 0x00000008,
    192	RDPDR_PRINTER_ANNOUNCE_FLAG_XPSFORMAT = 0x00000010
    193};
    194
    195/* [MS-FSCC] FileAttributes */
    196
    197#ifndef _WIN32
    198
    199#define FILE_ATTRIBUTE_ARCHIVE 0x00000020
    200#define FILE_ATTRIBUTE_COMPRESSED 0x00000800
    201#define FILE_ATTRIBUTE_DIRECTORY 0x00000010
    202#define FILE_ATTRIBUTE_ENCRYPTED 0x00004000
    203#define FILE_ATTRIBUTE_HIDDEN 0x00000002
    204#define FILE_ATTRIBUTE_NORMAL 0x00000080
    205#define FILE_ATTRIBUTE_NOT_CONTENT_INDEXED 0x00002000
    206#define FILE_ATTRIBUTE_OFFLINE 0x00001000
    207#define FILE_ATTRIBUTE_READONLY 0x00000001
    208#define FILE_ATTRIBUTE_REPARSE_POINT 0x00000400
    209#define FILE_ATTRIBUTE_SPARSE_FILE 0x00000200
    210#define FILE_ATTRIBUTE_SYSTEM 0x00000004
    211#define FILE_ATTRIBUTE_TEMPORARY 0x00000100
    212
    213#endif
    214
    215/* [MS-FSCC] FSCTL Structures */
    216
    217#if !defined(_WIN32) || (defined(_WIN32) && (_WIN32_WINNT < 0x0600))
    218#define FSCTL_LMR_SET_LINK_TRACKING_INFORMATION 0x1400ec
    219#define FSCTL_PIPE_PEEK 0x11400c
    220#define FSCTL_PIPE_TRANSCEIVE 0x11c017
    221#define FSCTL_PIPE_WAIT 0x110018
    222#define FSCTL_QUERY_ON_DISK_VOLUME_INFO 0x9013c
    223#define FSCTL_QUERY_SPARING_INFO 0x90138
    224#endif
    225
    226#ifndef _WIN32
    227#define FSCTL_CREATE_OR_GET_OBJECT_ID 0x900c0
    228#define FSCTL_GET_REPARSE_POINT 0x900a8
    229#define FSCTL_GET_RETRIEVAL_POINTERS 0x90073
    230#define FSCTL_IS_PATHNAME_VALID 0x9002c
    231#define FSCTL_READ_FILE_USN_DATA 0x900eb
    232#define FSCTL_RECALL_FILE 0x90117
    233#define FSCTL_QUERY_FAT_BPB 0x90058
    234#define FSCTL_QUERY_ALLOCATED_RANGES 0x940cf
    235#define FSCTL_SET_COMPRESSION 0x9c040
    236#define FSCTL_SET_ENCRYPTION 0x900D7
    237#define FSCTL_SET_OBJECT_ID 0x90098
    238#define FSCTL_SET_OBJECT_ID_EXTENDED 0x900bc
    239#define FSCTL_SET_REPARSE_POINT 0x900a4
    240#define FSCTL_SET_SPARSE 0x900c4
    241#define FSCTL_SET_ZERO_DATA 0x980c8
    242#define FSCTL_SIS_COPYFILE 0x90100
    243#define FSCTL_WRITE_USN_CLOSE_RECORD 0x900ef
    244#endif
    245
    246#if !defined(_WIN32) || (defined(_WIN32) && (_WIN32_WINNT < 0x0600))
    247#define FSCTL_SET_DEFECT_MANAGEMENT 0x98134
    248#define FSCTL_SET_ZERO_ON_DEALLOCATION 0x90194
    249#endif
    250
    251/* [MS-FSCC] FileFsAttributeInformation.FileSystemAttributes */
    252
    253#ifndef _WIN32
    254
    255#define FILE_SUPPORTS_USN_JOURNAL 0x02000000
    256#define FILE_SUPPORTS_OPEN_BY_FILE_ID 0x01000000
    257#define FILE_SUPPORTS_EXTENDED_ATTRIBUTES 0x00800000
    258#define FILE_SUPPORTS_HARD_LINKS 0x00400000
    259#define FILE_SUPPORTS_TRANSACTIONS 0x00200000
    260#define FILE_SEQUENTIAL_WRITE_ONCE 0x00100000
    261#define FILE_READ_ONLY_VOLUME 0x00080000
    262#define FILE_NAMED_STREAMS 0x00040000
    263#define FILE_SUPPORTS_ENCRYPTION 0x00020000
    264#define FILE_SUPPORTS_OBJECT_IDS 0x00010000
    265#define FILE_VOLUME_IS_COMPRESSED 0x00008000
    266#define FILE_SUPPORTS_REMOTE_STORAGE 0x00000100
    267#define FILE_SUPPORTS_REPARSE_POINTS 0x00000080
    268#define FILE_SUPPORTS_SPARSE_FILES 0x00000040
    269#define FILE_VOLUME_QUOTAS 0x00000020
    270#define FILE_FILE_COMPRESSION 0x00000010
    271#define FILE_PERSISTENT_ACLS 0x00000008
    272#define FILE_UNICODE_ON_DISK 0x00000004
    273#define FILE_CASE_PRESERVED_NAMES 0x00000002
    274#define FILE_CASE_SENSITIVE_SEARCH 0x00000001
    275
    276#endif
    277
    278/* [MS-FSCC] FileFsDeviceInformation.DeviceType */
    279
    280#ifndef FILE_DEVICE_CD_ROM
    281#define FILE_DEVICE_CD_ROM 0x00000002
    282#endif
    283
    284#ifndef FILE_DEVICE_DISK
    285#define FILE_DEVICE_DISK 0x00000007
    286#endif
    287
    288/* [MS-FSCC] FileFsDeviceInformation.Characteristics */
    289enum FILE_FS_DEVICE_FLAG
    290{
    291	FILE_REMOVABLE_MEDIA = 0x00000001,
    292	FILE_READ_ONLY_DEVICE = 0x00000002,
    293	FILE_FLOPPY_DISKETTE = 0x00000004,
    294	FILE_WRITE_ONCE_MEDIA = 0x00000008,
    295	FILE_REMOTE_DEVICE = 0x00000010,
    296	FILE_DEVICE_IS_MOUNTED = 0x00000020,
    297	FILE_VIRTUAL_VOLUME = 0x00000040,
    298	FILE_DEVICE_SECURE_OPEN = 0x00000100
    299};
    300
    301enum FILE_FS_INFORMATION_CLASS
    302{
    303	FileFsVolumeInformation = 1,
    304	FileFsLabelInformation,
    305	FileFsSizeInformation,
    306	FileFsDeviceInformation,
    307	FileFsAttributeInformation,
    308	FileFsControlInformation,
    309	FileFsFullSizeInformation,
    310	FileFsObjectIdInformation,
    311	FileFsDriverPathInformation,
    312	FileFsMaximumInformation
    313};
    314
    315typedef struct _DEVICE DEVICE;
    316typedef struct _IRP IRP;
    317typedef struct _DEVMAN DEVMAN;
    318
    319typedef UINT (*pcCustomComponentRequest)(DEVICE* device, UINT16 component, UINT16 packetId,
    320                                         wStream* s);
    321typedef UINT (*pcIRPRequest)(DEVICE* device, IRP* irp);
    322typedef UINT (*pcInitDevice)(DEVICE* device);
    323typedef UINT (*pcFreeDevice)(DEVICE* device);
    324
    325struct _DEVICE
    326{
    327	UINT32 id;
    328
    329	UINT32 type;
    330	const char* name;
    331	wStream* data;
    332
    333	pcCustomComponentRequest CustomComponentRequest;
    334	pcIRPRequest IRPRequest;
    335	pcInitDevice Init;
    336	pcFreeDevice Free;
    337};
    338
    339typedef UINT (*pcIRPResponse)(IRP* irp);
    340
    341struct _IRP
    342{
    343	WINPR_SLIST_ENTRY ItemEntry;
    344
    345	DEVICE* device;
    346	DEVMAN* devman;
    347	UINT32 FileId;
    348	UINT32 CompletionId;
    349	UINT32 MajorFunction;
    350	UINT32 MinorFunction;
    351	wStream* input;
    352
    353	UINT32 IoStatus;
    354	wStream* output;
    355
    356	pcIRPResponse Complete;
    357	pcIRPResponse Discard;
    358
    359	HANDLE thread;
    360	BOOL cancelled;
    361};
    362
    363struct _DEVMAN
    364{
    365	void* plugin;
    366	UINT32 id_sequence;
    367	wListDictionary* devices;
    368};
    369
    370typedef UINT (*pcRegisterDevice)(DEVMAN* devman, DEVICE* device);
    371
    372struct _DEVICE_SERVICE_ENTRY_POINTS
    373{
    374	DEVMAN* devman;
    375
    376	pcRegisterDevice RegisterDevice;
    377	RDPDR_DEVICE* device;
    378	rdpContext* rdpcontext;
    379};
    380typedef struct _DEVICE_SERVICE_ENTRY_POINTS DEVICE_SERVICE_ENTRY_POINTS;
    381typedef DEVICE_SERVICE_ENTRY_POINTS* PDEVICE_SERVICE_ENTRY_POINTS;
    382
    383typedef UINT (*PDEVICE_SERVICE_ENTRY)(PDEVICE_SERVICE_ENTRY_POINTS);
    384
    385#endif /* FREERDP_CHANNEL_RDPDR_H */