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.

463 lines
20 KiB

  1. /****************************************************************************/
  2. // nwdwapi.h
  3. //
  4. // General RDPWD header.
  5. //
  6. // Copyright (C) 1997-2000 Microsoft Corporation
  7. /****************************************************************************/
  8. #ifndef _H_NWDWAPI
  9. #define _H_NWDWAPI
  10. #include <tsrvexp.h>
  11. #include "license.h"
  12. #include <tssec.h>
  13. #include <at120ex.h>
  14. #include <nshmapi.h>
  15. #include <pchannel.h>
  16. #include <MCSKernl.h>
  17. /****************************************************************************/
  18. /* Constants */
  19. /****************************************************************************/
  20. /****************************************************************************/
  21. /* @@@MF Need to calculated real values for the following numbers */
  22. /* Remeber that buffer size needs to allow for 32K of T.128 data ??plus hdr */
  23. /* size. */
  24. /****************************************************************************/
  25. #define TSHARE_WD_BUFFER_COUNT 5
  26. #define TSHARE_TD_BUFFER_SIZE (NET_MAX_SIZE_SEND_PKT + 1000)
  27. /****************************************************************************/
  28. /* Macro for splitting the function from an IOCtl */
  29. /****************************************************************************/
  30. #define WDW_IOCTL_FUNCTION(ioctl) (((ioctl) >> 2) & 0xfff)
  31. /****************************************************************************/
  32. /* Max decl def's */
  33. /****************************************************************************/
  34. #define WD_MAX_DOMAIN_LENGTH 48
  35. #define WD_MAX_USERNAME_LENGTH 48
  36. #define WD_MAX_PASSWORD_LENGTH 48
  37. #define WD_MAX_SHADOW_BUFFER (8192 * 2)
  38. #define WD_MIN_COMPRESS_INPUT_BUF 50
  39. #define WD_VC_DECOMPR_REASSEMBLY_BUF (CHANNEL_CHUNK_LENGTH*2)
  40. /****************************************************************************/
  41. /* ID of the 'Thinwire' virtual channel */
  42. /****************************************************************************/
  43. #define WD_THINWIRE_CHANNEL 7
  44. typedef struct tagMALLOC_HEADER MALLOC_HEADER, * PMALLOC_HEADER;
  45. typedef struct tagMALLOC_HEADER
  46. {
  47. PMALLOC_HEADER pNext;
  48. PMALLOC_HEADER pPrev;
  49. PVOID pCaller;
  50. UINT32 length;
  51. } MALLOC_HEADER, * PMALLOC_HEADER;
  52. typedef struct tagTSHARE_WD {
  53. /************************************************************************/
  54. /* Returned from MCS initialization. Needed to attach a user to MCS. */
  55. /* NOTE: This MUST be first in struct. MCS will assume so. */
  56. /************************************************************************/
  57. DomainHandle hDomainKernel;
  58. /************************************************************************/
  59. /* Pointer back to the SDCONTEXT that is passed in on all calls. */
  60. /************************************************************************/
  61. PSDCONTEXT pContext;
  62. /************************************************************************/
  63. /* Is this WD prepared to process data? */
  64. /************************************************************************/
  65. BOOLEAN dead;
  66. /************************************************************************/
  67. /* Shadow data */
  68. /************************************************************************/
  69. BOOLEAN bInShadowShare;
  70. BYTE HotkeyVk;
  71. USHORT HotkeyModifiers;
  72. PSHADOW_INFO pShadowInfo;
  73. PSHADOWCERT pShadowCert;
  74. PCLIENTRANDOM pShadowRandom;
  75. PUSERDATAINFO pUserData;
  76. UINT32 shadowState;
  77. #define SHADOW_NONE 0
  78. #define SHADOW_CLIENT 1
  79. #define SHADOW_TARGET 2
  80. /************************************************************************/
  81. /* Pointer to protocol counters struct */
  82. /************************************************************************/
  83. PPROTOCOLSTATUS pProtocolStatus;
  84. /************************************************************************/
  85. /* Display characteristics */
  86. /************************************************************************/
  87. unsigned desktopHeight;
  88. unsigned desktopWidth;
  89. unsigned desktopBpp;
  90. #ifdef DC_HICOLOR
  91. unsigned supportedBpps; // holds RNS_UD_xxBPP_SUPPORT OR'ed flags
  92. unsigned maxServerBpp;
  93. #endif
  94. /************************************************************************/
  95. /* Timer to kick to talk to the DD */
  96. /************************************************************************/
  97. PKTIMER ritTimer;
  98. /************************************************************************/
  99. /* Events to sleep on while waiting for */
  100. /* - the connected indication */
  101. /* - Share creation to complete. */
  102. /* - security transaction tp complete. */
  103. /************************************************************************/
  104. PKEVENT pConnEvent;
  105. PKEVENT pCreateEvent;
  106. PKEVENT pSecEvent;
  107. PKEVENT pSessKeyEvent;
  108. PKEVENT pClientDisconnectEvent;
  109. // Associated error returns.
  110. NTSTATUS SessKeyCreationStatus;
  111. /************************************************************************/
  112. /* Internal handles we need */
  113. /************************************************************************/
  114. PVOID dcShare;
  115. PVOID pSmInfo;
  116. PVOID pNMInfo;
  117. #ifdef USE_LICENSE
  118. PVOID pSLicenseHandle;
  119. #endif
  120. /************************************************************************/
  121. /* Has the Share Class been initialized? */
  122. /************************************************************************/
  123. BOOLEAN shareClassInit;
  124. /************************************************************************/
  125. /* Has the WD connected successfully to the Client? */
  126. /************************************************************************/
  127. BOOLEAN connected;
  128. /************************************************************************/
  129. /* Was the Share created OK? */
  130. /************************************************************************/
  131. BOOLEAN shareCreated;
  132. /************************************************************************/
  133. /* Other useful stuff from user data */
  134. /************************************************************************/
  135. HANDLE hDomain;
  136. UINT16 sas;
  137. UINT16 clientProductId;
  138. UINT32 version;
  139. ULONG kbdLayout;
  140. UINT32 clientBuild;
  141. WCHAR clientName[RNS_UD_CS_CLIENTNAME_LENGTH + 1];
  142. ChannelID broadcastChannel;
  143. ULONG sessionId;
  144. ULONG serialNumber;
  145. ULONG clientAddressFamily;
  146. WCHAR clientAddress[CLIENTADDRESS_LENGTH + 2];
  147. WCHAR clientDir[DIRECTORY_LENGTH];
  148. RDP_TIME_ZONE_INFORMATION clientTimeZone;
  149. ULONG clientSessionId;
  150. WCHAR clientDigProductId[CLIENT_PRODUCT_ID_LENGTH]; //shadow loop fix
  151. //
  152. // Perf (slow link) disabled feature list (e.g wallpaper, themes)
  153. // defined in tsperf.h
  154. //
  155. ULONG performanceFlags;
  156. //
  157. // Client's active input locale information
  158. // (i.e. HKL returned from GetKeyboardLayout)
  159. //
  160. UINT32 activeInputLocale;
  161. /************************************************************************/
  162. /* Temporary storage for an IOCtl. */
  163. /************************************************************************/
  164. PSD_IOCTL pSdIoctl;
  165. /************************************************************************/
  166. /* Structs needed to support the keyboard IOCtls */
  167. /************************************************************************/
  168. KEYBOARD_TYPEMATIC_PARAMETERS KeyboardTypematic;
  169. KEYBOARD_INDICATOR_PARAMETERS KeyboardIndicators;
  170. PVOID pgafPhysKeyState;
  171. PVOID pKbdLayout;
  172. PVOID pKbdTbl;
  173. PVOID gpScancodeMap;
  174. BOOLEAN KeyboardType101;
  175. KEYBOARD_IME_STATUS KeyboardImeStatus;
  176. /************************************************************************/
  177. /* Name information */
  178. /************************************************************************/
  179. DLLNAME DLLName;
  180. WINSTATIONNAME WinStationRegName;
  181. /************************************************************************/
  182. /* These are used by the COM registry functions to store the handle of */
  183. /* an open key and to keep track of calls to COM_OpenRegistry and */
  184. /* COM_CloseRegistry. */
  185. /************************************************************************/
  186. HANDLE regKeyHandle;
  187. BOOLEAN regAttemptedOpen;
  188. /************************************************************************/
  189. /* For determining is a QUERY_VIRTUAL_BINDINGS has already occurred. */
  190. /************************************************************************/
  191. BOOLEAN bVirtualChannelBound;
  192. /************************************************************************/
  193. /* StartSessionInfo data */
  194. /************************************************************************/
  195. BOOLEAN fDontDisplayLastUserName;
  196. RNS_INFO_PACKET *pInfoPkt;
  197. /************************************************************************/
  198. /* FE data */
  199. /************************************************************************/
  200. UINT32 keyboardType;
  201. UINT32 keyboardSubType;
  202. UINT32 keyboardFunctionKey;
  203. WCHAR imeFileName[TS_MAX_IMEFILENAME];
  204. /************************************************************************/
  205. /* Transfer variables for scheduler settings. These correspond to */
  206. /* schNormalPeriod and schTurboPeriod respectively. */
  207. /************************************************************************/
  208. UINT32 outBufDelay;
  209. UINT32 interactiveDelay;
  210. /************************************************************************/
  211. // Connection info
  212. /************************************************************************/
  213. STACKCLASS StackClass;
  214. /*
  215. * Compression history
  216. */
  217. BOOLEAN bCompress;
  218. BOOLEAN bFlushed;
  219. BOOLEAN bOutputFlush;
  220. SendContext *pMPPCContext;
  221. BYTE *pCompressBuffer;
  222. /************************************************************************/
  223. /* Share load count */
  224. /************************************************************************/
  225. INT32 shareId;
  226. // Client load balancing capabilities.
  227. UINT32 bClientSupportsRedirection : 1;
  228. UINT32 bRequestedSessionIDFieldValid : 1;
  229. UINT32 bUseSmartcardLogon : 1;
  230. UINT32 RequestedSessionID;
  231. UINT32 ClientRedirectionVersion;
  232. // VC compression supported
  233. BOOLEAN bClientSupportsVCCompression;
  234. //
  235. // Recv decompression context
  236. // (this is 8K as VC's only support 8k compression
  237. // from client to server) to limit memory usage and
  238. // give better scalability.
  239. //
  240. RecvContext1 _DecomprContext1;
  241. RecvContext2_8K* _pRecvDecomprContext2;
  242. PUCHAR _pVcDecomprReassemblyBuf;
  243. /************************************************************************/
  244. /* NOTE: Add new elements above here, so that the #ifdef DEBUG stuff */
  245. /* below is always at the end. This allows the KD extensions to work */
  246. /* correctly for retail/debug builds. */
  247. /************************************************************************/
  248. BOOL bSupportErrorInfoPDU;
  249. BOOL bForceEncryptedCSPDU;
  250. #ifdef DC_DEBUG
  251. /************************************************************************/
  252. /* Memory allocation chain anchor point */
  253. /************************************************************************/
  254. UINT32 breakOnLeak;
  255. MALLOC_HEADER memoryHeader;
  256. /************************************************************************/
  257. /* Trace config - should always be the last elements in this structure. */
  258. /************************************************************************/
  259. BOOL trcShmNeedsUpdate;
  260. TRC_SHARED_DATA trc;
  261. char traceString[TRC_BUFFER_SIZE];
  262. #endif
  263. /************************************************************************/
  264. /* Channel Write Flow Control Sleep Interval */
  265. /************************************************************************/
  266. UINT32 flowControlSleepInterval;
  267. BOOL fPolicyDisablesArc;
  268. //
  269. // Autoreconnect token
  270. //
  271. BOOL arcTokenValid;
  272. UINT32 arcReconnectSessionID;
  273. BYTE arcCookie[ARC_SC_SECURITY_TOKEN_LEN];
  274. /************************************************************************/
  275. /* The SM/NM data is allocated as part of the block of data containing */
  276. /* this structure - it follows on at the next 4 byte boundary. */
  277. /************************************************************************/
  278. } TSHARE_WD, * PTSHARE_WD;
  279. /****************************************************************************/
  280. /* FUNCTION PROTOTYPES */
  281. /****************************************************************************/
  282. /****************************************************************************/
  283. /* Firstly, those APIs that are called by ICADD. */
  284. /****************************************************************************/
  285. #ifdef __cplusplus
  286. extern "C" {
  287. #endif
  288. NTSTATUS DriverEntry( PSDCONTEXT, BOOLEAN );
  289. NTSTATUS WD_Open( PTSHARE_WD, PSD_OPEN );
  290. NTSTATUS WD_RawWrite( PTSHARE_WD, PSD_RAWWRITE );
  291. NTSTATUS WD_Close( PTSHARE_WD, PSD_CLOSE );
  292. NTSTATUS WD_ChannelWrite( PTSHARE_WD, PSD_CHANNELWRITE );
  293. NTSTATUS WD_Ioctl( PTSHARE_WD, PSD_IOCTL );
  294. void RDPCALL WDW_LogAndDisconnect(
  295. PTSHARE_WD pTSWd,
  296. BOOL fSendErrorToClient,
  297. unsigned errDetailCode,
  298. PBYTE pDetailData,
  299. unsigned detailDataLen);
  300. /****************************************************************************/
  301. /* Now those APIs that are called by the other components within the WD. */
  302. /****************************************************************************/
  303. void RDPCALL WDW_OnSMConnecting(PVOID, PRNS_UD_SC_SEC, PRNS_UD_SC_NET);
  304. void RDPCALL WDW_OnSMConnected(PVOID, unsigned);
  305. void WDW_OnSMDisconnected(PVOID);
  306. void WDW_InvalidateRect(
  307. PTSHARE_WD pTSWd,
  308. PTS_REFRESH_RECT_PDU pRRPDU,
  309. unsigned DataLength);
  310. void WDW_OnDataReceived(PTSHARE_WD, PVOID, unsigned, UINT16);
  311. PTS_CAPABILITYHEADER WDW_GetCapSet(
  312. PTSHARE_WD pTSWd,
  313. UINT32 CapSetType,
  314. PTS_COMBINED_CAPABILITIES pCaps,
  315. UINT32 capsLength);
  316. NTSTATUS RDPCALL WDW_WaitForConnectionEvent(PTSHARE_WD, PKEVENT, LONG);
  317. /****************************************************************************/
  318. /* Name: WDW_ShareCreated */
  319. /* */
  320. /* Purpose: Called by Share Core when Share Create process is complete */
  321. /* */
  322. /* Params: pTSWd */
  323. /* result - TRUE Share created OK */
  324. /* - FALSE Share not created */
  325. /****************************************************************************/
  326. __inline void RDPCALL WDW_ShareCreated(PTSHARE_WD pTSWd, BOOLEAN result)
  327. {
  328. /************************************************************************/
  329. /* Unblock the Connect IOCtl. */
  330. /************************************************************************/
  331. pTSWd->shareCreated = result;
  332. KeSetEvent(pTSWd->pCreateEvent, EVENT_INCREMENT, FALSE);
  333. }
  334. /****************************************************************************/
  335. /* Name: WDW_Disconnect */
  336. /* */
  337. /* Purpose: Disconnect the session */
  338. /* */
  339. /* Params: pTSWd - pointer to WD structure */
  340. /****************************************************************************/
  341. __inline void WDW_Disconnect(PTSHARE_WD pTSWd)
  342. {
  343. ICA_CHANNEL_COMMAND BrokenConn;
  344. BrokenConn.Header.Command = ICA_COMMAND_BROKEN_CONNECTION;
  345. BrokenConn.BrokenConnection.Reason = Broken_Disconnect;
  346. BrokenConn.BrokenConnection.Source = BrokenSource_User;
  347. IcaChannelInput(pTSWd->pContext, Channel_Command, 0, NULL,
  348. (BYTE *)&BrokenConn, sizeof(BrokenConn));
  349. }
  350. /****************************************************************************/
  351. /* Name: WDW_StartRITTimer */
  352. /* */
  353. /* Purpose: Start the timer that will cause a kick to the WinStation's */
  354. /* RIT. */
  355. /* */
  356. /* Params: IN pTSWd - pointer to WD struct */
  357. /* IN milliSecs - time period. */
  358. /****************************************************************************/
  359. __inline void WDW_StartRITTimer(PTSHARE_WD pTSWd, UINT32 milliSecs)
  360. {
  361. if (pTSWd->ritTimer != NULL) {
  362. KeSetTimer(pTSWd->ritTimer, RtlConvertLongToLargeInteger(
  363. -((INT32)milliSecs * 10000)), NULL);
  364. }
  365. }
  366. /****************************************************************************/
  367. // Returns the current state of the keyboard indicators.
  368. /****************************************************************************/
  369. __inline NTSTATUS WDW_QueryKeyboardIndicators(
  370. PTSHARE_WD pTSWd,
  371. PSD_IOCTL pSdIoctl)
  372. {
  373. PKEYBOARD_INDICATOR_PARAMETERS pIndicator;
  374. if ( pSdIoctl->OutputBufferLength >=
  375. sizeof(KEYBOARD_INDICATOR_PARAMETERS)) {
  376. pIndicator = (PKEYBOARD_INDICATOR_PARAMETERS)
  377. pSdIoctl->OutputBuffer;
  378. *pIndicator = pTSWd->KeyboardIndicators;
  379. pSdIoctl->BytesReturned = sizeof(KEYBOARD_INDICATOR_PARAMETERS);
  380. return STATUS_SUCCESS;
  381. }
  382. else {
  383. return STATUS_BUFFER_TOO_SMALL;
  384. }
  385. }
  386. #ifdef __cplusplus
  387. }
  388. #endif
  389. #endif