Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

409 lines
9.7 KiB

  1. /*++
  2. Copyright (c) 1998-2000 Microsoft Corporation
  3. Module Name:
  4. proc.h
  5. Abstract:
  6. Contains the parent of the IO processing class hierarchy
  7. for TS Device Redirection, ProcObj.
  8. Author:
  9. Madan Appiah (madana) 17-Sep-1998
  10. Revision History:
  11. --*/
  12. #ifndef __PROC_H__
  13. #define __PROC_H__
  14. #include <rdpdr.h>
  15. #include "drobject.h"
  16. #include "drdev.h"
  17. #include "drobjmgr.h"
  18. #include <vcint.h>
  19. ///////////////////////////////////////////////////////////////
  20. //
  21. // Defines
  22. //
  23. //
  24. // Macros for returning the size of server reply buffers. BUGBUG:
  25. // these defines belong in a header that is accessible from the
  26. // server.
  27. //
  28. #define DR_IOCTL_REPLYBUFSIZE(pIoRequest) \
  29. ((ULONG)FIELD_OFFSET(RDPDR_IOCOMPLETION_PACKET, \
  30. IoCompletion.Parameters.DeviceIoControl.OutputBuffer) + \
  31. pIoRequest->Parameters.DeviceIoControl.OutputBufferLength)
  32. ///////////////////////////////////////////////////////////////
  33. //
  34. // Typedefs
  35. //
  36. //
  37. // Predeclare the ProcObj class.
  38. //
  39. class ProcObj;
  40. //
  41. // Async IO Operation Management Function Types
  42. //
  43. typedef HANDLE (*RDPAsyncFunc_StartIO)(PVOID context, DWORD *status);
  44. typedef VOID (*RDPAsyncFunc_IOComplete)(PVOID context, DWORD status);
  45. typedef VOID (*RDPAsyncFunc_IOCancel)(PVOID context);
  46. //
  47. // Device Enumeration Function Type
  48. //
  49. // Enumerate devices of a particular type by creating device instances
  50. // and and adding them to the device manager.
  51. //
  52. typedef DWORD (*RDPDeviceEnum)(ProcObj *procObj, DrDeviceMgr *deviceMgr);
  53. //
  54. // Client capability set
  55. //
  56. typedef struct tagRDPDR_CLIENT_COMBINED_CAPABILITYSET
  57. {
  58. RDPDR_CAPABILITY_SET_HEADER Header;
  59. #define RDPDR_NUM_CLIENT_CAPABILITIES 5
  60. RDPDR_GENERAL_CAPABILITY GeneralCap;
  61. #define RDPDR_CLIENT_IO_CODES 0xFFFF
  62. RDPDR_PRINT_CAPABILITY PrintCap;
  63. RDPDR_PORT_CAPABILITY PortCap;
  64. RDPDR_FS_CAPABILITY FileSysCap;
  65. RDPDR_SMARTCARD_CAPABILITY SmartCardCap;
  66. } RDPDR_CLIENT_COMBINED_CAPABILITYSET, *PRDPDR_CLIENT_COMBINED_CAPABILITYSET;
  67. //
  68. // Client default capability set sent to server
  69. //
  70. const RDPDR_CLIENT_COMBINED_CAPABILITYSET CLIENT_CAPABILITY_SET_DEFAULT = {
  71. // Capability Set Header
  72. {
  73. {
  74. RDPDR_CTYP_CORE,
  75. DR_CORE_CLIENT_CAPABILITY
  76. },
  77. RDPDR_NUM_CLIENT_CAPABILITIES,
  78. 0
  79. },
  80. // General Capability
  81. {
  82. RDPDR_GENERAL_CAPABILITY_TYPE,
  83. sizeof(RDPDR_GENERAL_CAPABILITY),
  84. RDPDR_GENERAL_CAPABILITY_VERSION_01,
  85. 0, // Need to specify the OS type
  86. 0, // Need to specify the OS version
  87. RDPDR_MAJOR_VERSION,
  88. RDPDR_MINOR_VERSION,
  89. RDPDR_CLIENT_IO_CODES,
  90. 0,
  91. RDPDR_DEVICE_REMOVE_PDUS | RDPDR_CLIENT_DISPLAY_NAME_PDU,
  92. 0,
  93. 0
  94. },
  95. // Printing Capability
  96. {
  97. RDPDR_PRINT_CAPABILITY_TYPE,
  98. sizeof(RDPDR_PRINT_CAPABILITY),
  99. RDPDR_PRINT_CAPABILITY_VERSION_01
  100. },
  101. // Port Capability
  102. {
  103. RDPDR_PORT_CAPABILITY_TYPE,
  104. sizeof(RDPDR_PORT_CAPABILITY),
  105. RDPDR_PORT_CAPABILITY_VERSION_01
  106. },
  107. // FileSystem Capability
  108. {
  109. RDPDR_FS_CAPABILITY_TYPE,
  110. sizeof(RDPDR_FS_CAPABILITY),
  111. RDPDR_FS_CAPABILITY_VERSION_01
  112. },
  113. // SmartCard Capability
  114. {
  115. RDPDR_SMARTCARD_CAPABILITY_TYPE,
  116. sizeof(RDPDR_SMARTCARD_CAPABILITY),
  117. RDPDR_SMARTCARD_CAPABILITY_VERSION_01
  118. }
  119. };
  120. //
  121. // Default server capability set sent from server
  122. //
  123. const RDPDR_CLIENT_COMBINED_CAPABILITYSET SERVER_CAPABILITY_SET_DEFAULT = {
  124. // Capability Set Header
  125. {
  126. {
  127. RDPDR_CTYP_CORE,
  128. DR_CORE_SERVER_CAPABILITY
  129. },
  130. RDPDR_NUM_CLIENT_CAPABILITIES,
  131. 0
  132. },
  133. // General Capability
  134. {
  135. RDPDR_GENERAL_CAPABILITY_TYPE,
  136. sizeof(RDPDR_GENERAL_CAPABILITY),
  137. 0,
  138. 0, // Need to specify the OS type
  139. 0, // Need to specify the OS version
  140. 0,
  141. 0,
  142. 0,
  143. 0,
  144. 0,
  145. 0,
  146. 0
  147. },
  148. // Printing Capability
  149. {
  150. RDPDR_PRINT_CAPABILITY_TYPE,
  151. sizeof(RDPDR_PRINT_CAPABILITY),
  152. 0
  153. },
  154. // Port Capability
  155. {
  156. RDPDR_PORT_CAPABILITY_TYPE,
  157. sizeof(RDPDR_PORT_CAPABILITY),
  158. 0
  159. },
  160. // FileSystem Capability
  161. {
  162. RDPDR_FS_CAPABILITY_TYPE,
  163. sizeof(RDPDR_FS_CAPABILITY),
  164. 0
  165. },
  166. // SmartCard Capability
  167. {
  168. RDPDR_SMARTCARD_CAPABILITY_TYPE,
  169. sizeof(RDPDR_SMARTCARD_CAPABILITY),
  170. 0
  171. }
  172. };
  173. ///////////////////////////////////////////////////////////////
  174. //
  175. // ProcObj
  176. //
  177. // ProcObj is the parent device IO processing class for TS
  178. // Device Redirection.
  179. //
  180. class ProcObj : public DrObject {
  181. protected:
  182. VOID ProcessIORequestPacket(PRDPDR_IOREQUEST_PACKET pIoRequestPacket, UINT32 packetLen);
  183. ULONG GetClientID();
  184. //
  185. // Device Enumeration List
  186. //
  187. static RDPDeviceEnum _DeviceEnumFunctions[];
  188. DWORD DeviceEnumFunctionsCount();
  189. //
  190. // Remember whether an instance of this class has been
  191. // initialized.
  192. //
  193. BOOL _initialized;
  194. //
  195. // User-Configurable Ability to Disable Device Redirection
  196. //
  197. ULONG _bDisableDeviceRedirection;
  198. //
  199. // List of all devices being redirected.
  200. //
  201. DrDeviceMgr *_deviceMgr;
  202. //
  203. // Local Device Status
  204. //
  205. RDPDR_VERSION _sServerVersion;
  206. //
  207. // Capability sets
  208. //
  209. RDPDR_CLIENT_COMBINED_CAPABILITYSET _cCapabilitySet;
  210. RDPDR_CLIENT_COMBINED_CAPABILITYSET _sCapabilitySet;
  211. //
  212. // Connection manager to route VC requests through
  213. //
  214. VCManager *_pVCMgr;
  215. VOID MsgCoreAnnounce(
  216. PRDPDR_SERVER_ANNOUNCE_PACKET pAnnounce
  217. );
  218. VOID MsgCoreDevicelistReply(
  219. PRDPDR_DEVICELIST_REPLY pDeviceReplyList
  220. );
  221. VOID AnnounceClientCapability();
  222. VOID AnnounceClientDisplayName();
  223. VOID OnServerCapability(PRDPDR_HEADER pRdpdrHeader, ULONG maxDataLength);
  224. BOOL InitServerCapability(PRDPDR_CAPABILITY_HEADER pCapHdr, PBYTE packetLimit);
  225. //
  226. // Handle a "core" server packet.
  227. //
  228. VOID ProcessCoreServerPacket(
  229. PRDPDR_HEADER pRdpdrHeader,
  230. UINT32 packetLen
  231. );
  232. //
  233. // Pure virtual functions.
  234. //
  235. virtual VOID GetClientComputerName(
  236. PBYTE pbBuffer,
  237. PULONG pulBufferLen,
  238. PBOOL pbUnicodeFlag,
  239. PULONG pulCodePage
  240. ) = NULL;
  241. //
  242. // Enumerate devices and announce them to the server.
  243. //
  244. virtual VOID AnnounceDevicesToServer() = 0;
  245. public:
  246. //
  247. // Constructor/Destructor
  248. //
  249. ProcObj(VCManager *pVCM);
  250. virtual ~ProcObj();
  251. //
  252. // Create the correct instance of this class.
  253. //
  254. static ProcObj *Instantiate(VCManager *virtualChannelMgr);
  255. //
  256. // Initialize an instance of this class.
  257. //
  258. virtual ULONG Initialize();
  259. //
  260. // Return Configurable DWORD parameter. Windows
  261. // error code is returned on error. Otherwise, ERROR_SUCCESS
  262. // should be returned.
  263. //
  264. virtual ULONG GetDWordParameter(LPTSTR valueName, PULONG value) = 0;
  265. //
  266. // Return Configurable string parameter. Windows
  267. // error code is returned on error. Otherwise, ERROR_SUCCESS
  268. // should be returned. maxSize contains the number of bytes
  269. // available in the "value" data area.
  270. //
  271. virtual ULONG GetStringParameter(LPTSTR valueName,
  272. DRSTRING value,
  273. ULONG maxSize) = 0;
  274. //
  275. // Dispatch an asynchronous IO function.
  276. //
  277. // startFunc points to the function that will be called to initiate the IO.
  278. // finishFunc, optionally, points to the function that will be called once
  279. // the IO has completed. Returns ERROR_SUCCESS or Windows error code.
  280. //
  281. virtual DWORD DispatchAsyncIORequest(
  282. RDPAsyncFunc_StartIO ioStartFunc,
  283. RDPAsyncFunc_IOComplete ioCompleteFunc = NULL,
  284. RDPAsyncFunc_IOCancel ioCancelFunc = NULL,
  285. PVOID clientContext = NULL
  286. ) = 0;
  287. //
  288. // Process a packet from the server.
  289. //
  290. VOID ProcessServerPacket(PVC_TX_DATA pData);
  291. //
  292. // Make a device announe message to send to the server.
  293. //
  294. PRDPDR_HEADER GenerateAnnouncePacket(INT *piSize, BOOL bCheckDeviceChange);
  295. //
  296. // Make a device remove message to send to the server.
  297. //
  298. PRDPDR_HEADER GenerateDeviceRemovePacket(INT *piSize);
  299. //
  300. // Return the Virtual Channel Manager
  301. //
  302. VCManager &GetVCMgr() {
  303. DC_BEGIN_FN("DrObject::DrObject");
  304. ASSERT(_pVCMgr != NULL);
  305. return *_pVCMgr;
  306. }
  307. //
  308. // Return the server capability
  309. //
  310. RDPDR_CLIENT_COMBINED_CAPABILITYSET &GetServerCap() {
  311. return _sCapabilitySet;
  312. }
  313. //
  314. // Returns whether the proc obj is in the middle of shutting down.
  315. //
  316. virtual BOOL IsShuttingDown() = 0;
  317. //
  318. // Return whether the platform is 9x.
  319. //
  320. virtual BOOL Is9x() = 0;
  321. //
  322. // Return the class name.
  323. //
  324. virtual DRSTRING className() { return TEXT("ProcObj"); }
  325. //
  326. // Return the server protocol version
  327. //
  328. RDPDR_VERSION serverVersion() { return _sServerVersion; }
  329. virtual void OnDeviceChange(WPARAM wParam, LPARAM lParam) = 0;
  330. };
  331. #endif