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.

353 lines
7.4 KiB

  1. /*++
  2. Copyright (c) 1998-2000 Microsoft Corporation
  3. Module Name:
  4. drdev
  5. Abstract:
  6. This module defines the parent for the client-side RDP
  7. device redirection "device" class hierarchy, DrDevice.
  8. Author:
  9. Tad Brockway 3/23/99
  10. Revision History:
  11. --*/
  12. #include <precom.h>
  13. #define TRC_FILE "DrDev"
  14. #include "drdev.h"
  15. #include "proc.h"
  16. #include "drconfig.h"
  17. #include "utl.h"
  18. #include "drfile.h"
  19. #include "drobjmgr.h"
  20. #ifdef OS_WINCE
  21. #include "filemgr.h"
  22. #endif
  23. ///////////////////////////////////////////////////////////////
  24. //
  25. // DrDevice Methods
  26. //
  27. //
  28. DrDevice::DrDevice(ProcObj *processObject, ULONG deviceID)
  29. /*++
  30. Routine Description:
  31. Constructor for the DrDevice class.
  32. Arguments:
  33. processObject - Parent process object.
  34. id - Unique device ID.
  35. Return Value:
  36. None
  37. --*/
  38. {
  39. DC_BEGIN_FN("DrDevice::DrDevice");
  40. ASSERT(processObject != NULL);
  41. _deviceID = deviceID;
  42. _processObject = processObject;
  43. _deviceChange = DEVICENEW;
  44. _FileMgr = NULL;
  45. //
  46. // Not valid until initialized.
  47. //
  48. SetValid(FALSE);
  49. DC_END_FN();
  50. }
  51. DrDevice::~DrDevice()
  52. /*++
  53. Routine Description:
  54. Destructor for the DrDevice class.
  55. Arguments:
  56. None
  57. Return Value:
  58. None
  59. --*/
  60. {
  61. DrFile *pFileObj;
  62. DC_BEGIN_FN("DrDevice::~DrDevice");
  63. //
  64. // Clean up the file management list.
  65. //
  66. if (_FileMgr != NULL) {
  67. _FileMgr->Lock();
  68. while ((pFileObj = _FileMgr->GetFirstObject()) != NULL) {
  69. pFileObj->Close();
  70. _FileMgr->RemoveObject(pFileObj->GetID());
  71. pFileObj->Release();
  72. }
  73. _FileMgr->Unlock();
  74. delete _FileMgr;
  75. }
  76. DC_END_FN();
  77. }
  78. DWORD DrDevice::Initialize()
  79. /*++
  80. Routine Description:
  81. Initialize.
  82. Arguments:
  83. pIoRequestPacket - IO request from server.
  84. Return Value:
  85. None
  86. --*/
  87. {
  88. DWORD result;
  89. DC_BEGIN_FN("DrDevice::Initialize");
  90. _FileMgr = new DrFileMgr();
  91. if (_FileMgr == NULL) {
  92. TRC_ERR((TB, L"Error allocating file mgr."));
  93. result = ERROR_NOT_ENOUGH_MEMORY;
  94. goto CLEANUPANDEXIT;
  95. }
  96. result = _FileMgr->Initialize();
  97. if (result != ERROR_SUCCESS) {
  98. delete _FileMgr;
  99. _FileMgr = NULL;
  100. goto CLEANUPANDEXIT;
  101. }
  102. SetValid(TRUE);
  103. CLEANUPANDEXIT:
  104. DC_END_FN();
  105. return result;
  106. }
  107. VOID DrDevice::ProcessIORequest(
  108. IN PRDPDR_IOREQUEST_PACKET pIoRequestPacket,
  109. IN UINT32 packetLen
  110. )
  111. /*++
  112. Routine Description:
  113. Handle an IO request from the server.
  114. Arguments:
  115. pIoRequestPacket - IO request from server.
  116. packetLen - length of the packet
  117. Return Value:
  118. None
  119. --*/
  120. {
  121. PRDPDR_DEVICE_IOREQUEST pIORequest;
  122. DC_BEGIN_FN("DrDevice::ProcessIORequest");
  123. //
  124. // Make sure we are valid.
  125. //
  126. ASSERT(IsValid());
  127. if (!IsValid()) {
  128. DefaultIORequestMsgHandle(pIoRequestPacket, STATUS_UNSUCCESSFUL);
  129. DC_END_FN();
  130. return;
  131. }
  132. //
  133. // Dispatch the request.
  134. //
  135. pIORequest = &pIoRequestPacket->IoRequest;
  136. switch (pIORequest->MajorFunction) {
  137. case IRP_MJ_CREATE :
  138. MsgIrpCreate(pIoRequestPacket, packetLen);
  139. break;
  140. case IRP_MJ_CLEANUP :
  141. MsgIrpCleanup(pIoRequestPacket, packetLen);
  142. break;
  143. case IRP_MJ_CLOSE :
  144. MsgIrpClose(pIoRequestPacket, packetLen);
  145. break;
  146. case IRP_MJ_READ :
  147. MsgIrpRead(pIoRequestPacket, packetLen);
  148. break;
  149. case IRP_MJ_WRITE :
  150. MsgIrpWrite(pIoRequestPacket, packetLen);
  151. break;
  152. case IRP_MJ_FLUSH_BUFFERS :
  153. MsgIrpFlushBuffers(pIoRequestPacket, packetLen);
  154. break;
  155. case IRP_MJ_SHUTDOWN :
  156. MsgIrpShutdown(pIoRequestPacket, packetLen);
  157. break;
  158. case IRP_MJ_DEVICE_CONTROL :
  159. MsgIrpDeviceControl(pIoRequestPacket, packetLen);
  160. break;
  161. case IRP_MJ_LOCK_CONTROL :
  162. MsgIrpLockControl(pIoRequestPacket, packetLen);
  163. break;
  164. case IRP_MJ_INTERNAL_DEVICE_CONTROL :
  165. MsgIrpInternalDeviceControl(pIoRequestPacket, packetLen);
  166. break;
  167. case IRP_MJ_DIRECTORY_CONTROL :
  168. MsgIrpDirectoryControl(pIoRequestPacket, packetLen);
  169. break;
  170. case IRP_MJ_QUERY_VOLUME_INFORMATION :
  171. MsgIrpQueryVolumeInfo(pIoRequestPacket, packetLen);
  172. break;
  173. case IRP_MJ_SET_VOLUME_INFORMATION :
  174. MsgIrpSetVolumeInfo(pIoRequestPacket, packetLen);
  175. break;
  176. case IRP_MJ_QUERY_INFORMATION :
  177. MsgIrpQueryFileInfo(pIoRequestPacket, packetLen);
  178. break;
  179. case IRP_MJ_SET_INFORMATION :
  180. MsgIrpSetFileInfo(pIoRequestPacket, packetLen);
  181. break;
  182. case IRP_MJ_QUERY_SECURITY :
  183. MsgIrpQuerySdInfo(pIoRequestPacket, packetLen);
  184. break;
  185. case IRP_MJ_SET_SECURITY :
  186. MsgIrpSetSdInfo(pIoRequestPacket, packetLen);
  187. break;
  188. default:
  189. TRC_ALT((TB, _T("Unknown MajorFunction, %ld."), pIORequest->MajorFunction ));
  190. DefaultIORequestMsgHandle(pIoRequestPacket, STATUS_UNSUCCESSFUL);
  191. break;
  192. }
  193. DC_END_FN();
  194. }
  195. VOID
  196. DrDevice::DefaultIORequestMsgHandle(
  197. IN PRDPDR_IOREQUEST_PACKET pIoRequestPacket,
  198. IN NTSTATUS serverReturnStatus
  199. )
  200. /*++
  201. Routine Description:
  202. Default IO Request Handling.
  203. Arguments:
  204. pIoRequestPacket - IO request from server.
  205. serverReturnStatus - NT error status to return to server.
  206. Return Value:
  207. None
  208. --*/
  209. {
  210. PRDPDR_DEVICE_IOREQUEST pIoRequest;
  211. PRDPDR_IOCOMPLETION_PACKET pReplyPacket = NULL;
  212. ULONG ulReplyPacketSize = 0;
  213. DC_BEGIN_FN("DrDevice::DefaultIORequestMsgHandle entered");
  214. //
  215. // Get IO request pointer.
  216. //
  217. pIoRequest = &pIoRequestPacket->IoRequest;
  218. //
  219. // Calculate the size of the reply packet, based on the type
  220. // of request.
  221. //
  222. if ((serverReturnStatus != STATUS_SUCCESS) &&
  223. (pIoRequest->MajorFunction != IRP_MJ_DEVICE_CONTROL)) {
  224. ulReplyPacketSize = sizeof(RDPDR_IOCOMPLETION_PACKET);
  225. }
  226. else {
  227. pIoRequest->Parameters.DeviceIoControl.OutputBufferLength = 0;
  228. ulReplyPacketSize = DR_IOCTL_REPLYBUFSIZE(pIoRequest);
  229. }
  230. //
  231. // Allocate reply buffer.
  232. //
  233. pReplyPacket = DrUTL_AllocIOCompletePacket(pIoRequestPacket,
  234. ulReplyPacketSize) ;
  235. if (pReplyPacket != NULL) {
  236. pReplyPacket->IoCompletion.IoStatus = serverReturnStatus;
  237. ProcessObject()->GetVCMgr().ChannelWrite(
  238. (PVOID)pReplyPacket, (UINT)ulReplyPacketSize
  239. );
  240. }
  241. else {
  242. TRC_ERR((TB, _T("Failed to alloc %ld bytes."),ulReplyPacketSize));
  243. }
  244. Cleanup:
  245. //
  246. // Clean up the request packet.
  247. //
  248. delete pIoRequestPacket;
  249. DC_END_FN();
  250. }