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.

297 lines
9.6 KiB

  1. /****************************************************************************/
  2. // icarpc.c
  3. //
  4. // winsta.dll RPC client code for interaction with termsrv.exe.
  5. //
  6. // Copyright (C) 1997-2000 Microsoft Corporation
  7. /****************************************************************************/
  8. #include <nt.h>
  9. #include <ntrtl.h>
  10. #include <nturtl.h>
  11. #include <ntddkbd.h>
  12. #include <ntddmou.h>
  13. #include <windows.h>
  14. #include <winbase.h>
  15. #include <winerror.h>
  16. #include <winsta.h>
  17. #include <icadd.h>
  18. #include "rpcwire.h"
  19. /****************************************************************************
  20. * ValidUserBuffer
  21. *
  22. * This function verifies that the caller if WinStationQueryInformation/
  23. * WinStationSetInformation has the correct structure size (i.e. client
  24. * application built with the same header files as winsta.dll).
  25. *
  26. * ENTRY:
  27. * BufferSize
  28. * The size of the bufferr.
  29. *
  30. * InfoClass
  31. * The WinStationQuery/Set information class.
  32. *
  33. * EXIT:
  34. * Retures TRUE if the buffer is valid, otherwise FALSE.
  35. ****************************************************************************/
  36. BOOLEAN ValidUserBuffer(ULONG BufferSize, WINSTATIONINFOCLASS InfoClass)
  37. {
  38. switch (InfoClass) {
  39. case WinStationLoadIndicator:
  40. return(BufferSize >= sizeof(WINSTATIONLOADINDICATORDATA));
  41. case WinStationCreateData:
  42. return(BufferSize == sizeof(WINSTATIONCREATEW));
  43. case WinStationConfiguration:
  44. return(BufferSize == sizeof(WINSTATIONCONFIGW));
  45. case WinStationPdParams:
  46. return(BufferSize == sizeof(PDPARAMSW));
  47. case WinStationWd:
  48. return(BufferSize == sizeof(WDCONFIGW));
  49. case WinStationPd:
  50. return(BufferSize == sizeof(PDCONFIGW));
  51. case WinStationPrinter:
  52. return(BufferSize == sizeof(WINSTATIONPRINTERW));
  53. case WinStationClient:
  54. return(BufferSize == sizeof(WINSTATIONCLIENTW));
  55. case WinStationModules:
  56. return(TRUE);
  57. case WinStationInformation:
  58. return(BufferSize == sizeof(WINSTATIONINFORMATIONW));
  59. case WinStationTrace:
  60. return(BufferSize == sizeof(ICA_TRACE));
  61. case WinStationBeep:
  62. return(BufferSize == sizeof(BEEPINPUT));
  63. case WinStationEncryptionOff:
  64. case WinStationEncryptionPerm:
  65. case WinStationNtSecurity:
  66. return(TRUE);
  67. case WinStationUserToken:
  68. return(BufferSize == sizeof(WINSTATIONUSERTOKEN));
  69. case WinStationVideoData:
  70. case WinStationInitialProgram:
  71. case WinStationCd:
  72. case WinStationSystemTrace:
  73. case WinStationVirtualData:
  74. return(TRUE); // Not Implemented - let server handle it
  75. case WinStationClientData:
  76. return(BufferSize >= sizeof(WINSTATIONCLIENTDATA));
  77. case WinStationLoadBalanceSessionTarget:
  78. return (BufferSize >= sizeof(ULONG));
  79. case WinStationShadowInfo:
  80. return(BufferSize == sizeof(WINSTATIONSHADOW));
  81. case WinStationDigProductId:
  82. return(BufferSize >= sizeof(WINSTATIONPRODID));
  83. case WinStationLockedState:
  84. return(BufferSize >= sizeof(BOOL));
  85. case WinStationRemoteAddress:
  86. return(BufferSize >= sizeof(WINSTATIONREMOTEADDRESS));
  87. case WinStationIdleTime:
  88. return(BufferSize >= sizeof(ULONG));
  89. case WinStationLastReconnectType:
  90. return(BufferSize >= sizeof(ULONG));
  91. case WinStationDisallowAutoReconnect:
  92. return(BufferSize >= sizeof(BOOLEAN));
  93. case WinStationExecSrvSystemPipe:
  94. return(BufferSize >= ( EXECSRVPIPENAMELEN * sizeof(WCHAR) ) );
  95. case WinStationMprNotifyInfo:
  96. return(BufferSize >= sizeof(ExtendedClientCredentials));
  97. case WinStationSDRedirectedSmartCardLogon:
  98. return(BufferSize >= sizeof(BOOLEAN));
  99. case WinStationIsAdminLoggedOn:
  100. return(BufferSize >= sizeof(BOOLEAN));
  101. default:
  102. return(FALSE);
  103. }
  104. }
  105. /****************************************************************************
  106. * CreateGenericWireBuf
  107. *
  108. * This function creates a generic wire buffer for structures which may
  109. * have new fields added to the end.
  110. *
  111. * ENTRY:
  112. *
  113. * DataSize (input)
  114. * The size of the structure.
  115. * pBuffer (output)
  116. * Pointer to the allocated buffer.
  117. * pBufSize (output)
  118. * Pointer to the wire buffer size.
  119. *
  120. * EXIT:
  121. * Returns ERROR_SUCCESS if successful. If successful, pBuffer
  122. * contains the generic wire buffer.
  123. ****************************************************************************/
  124. ULONG CreateGenericWireBuf(ULONG DataSize, PVOID *ppBuffer, PULONG pBufSize)
  125. {
  126. ULONG BufSize;
  127. PVARDATA_WIRE pVarData;
  128. BufSize = sizeof(VARDATA_WIRE) + DataSize;
  129. if ((pVarData = (PVARDATA_WIRE)LocalAlloc(0,BufSize)) == NULL)
  130. return(ERROR_NOT_ENOUGH_MEMORY);
  131. InitVarData(pVarData, DataSize, sizeof(VARDATA_WIRE));
  132. *ppBuffer = (PVOID) pVarData;
  133. *pBufSize = BufSize;
  134. return ERROR_SUCCESS;
  135. }
  136. /****************************************************************************
  137. * CheckUserBuffer
  138. *
  139. * This function determines if the buffer type should be converted to a
  140. * wire format. If so, a wire buffer is allocated.
  141. *
  142. * ENTRY:
  143. * InfoClass (input)
  144. * WinStationQuery/Set information class.
  145. *
  146. * UserBuf(input)
  147. * The client bufferr.
  148. *
  149. * UserBufLen (input)
  150. * The client buffer length.
  151. *
  152. * ppWireBuf(output)
  153. * Pointer to wirebuf pointer, updated with allocated wire buffer if
  154. * BufAllocated is TRUE.
  155. * pWireBufLen (output)
  156. * Pointer to the length of the wire buffer allocated, updated if
  157. * BufAllocated is TRUE.
  158. * pBufAllocated (output)
  159. * Pointer to flag indicating if a wire buffer was allocated.
  160. * EXIT:
  161. * Returns ERROR_SUCCESS if successful. If successful, BufAllocated
  162. * indicated whether a wire buffer was allocated.
  163. * on failure, an error code is returned.
  164. ****************************************************************************/
  165. ULONG CheckUserBuffer(
  166. WINSTATIONINFOCLASS InfoClass,
  167. PVOID UserBuf,
  168. ULONG UserBufLen,
  169. PVOID *ppWireBuf,
  170. PULONG pWireBufLen,
  171. BOOLEAN *pBufAllocated)
  172. {
  173. ULONG BufSize;
  174. ULONG Error;
  175. PPDCONFIGWIREW PdConfigWire;
  176. PPDCONFIGW PdConfig;
  177. PPDPARAMSWIREW PdParamsWire;
  178. PPDPARAMSW PdParam;
  179. PWINSTACONFIGWIREW WinStaConfigWire;
  180. PWINSTATIONCONFIGW WinStaConfig;
  181. PVOID WireBuf;
  182. if (!ValidUserBuffer(UserBufLen, InfoClass)) {
  183. return(ERROR_INSUFFICIENT_BUFFER);
  184. }
  185. switch (InfoClass) {
  186. case WinStationPd:
  187. BufSize = sizeof(PDCONFIGWIREW) + sizeof(PDCONFIG2W) + sizeof(PDPARAMSW);
  188. if ((WireBuf = (PCHAR)LocalAlloc(0,BufSize)) == NULL)
  189. return(ERROR_NOT_ENOUGH_MEMORY);
  190. PdConfigWire = (PPDCONFIGWIREW)WireBuf;
  191. InitVarData(&PdConfigWire->PdConfig2W,
  192. sizeof(PDCONFIG2W),
  193. sizeof(PDCONFIGWIREW));
  194. InitVarData(&PdConfigWire->PdParams.SdClassSpecific,
  195. sizeof(PDPARAMSW) - sizeof(SDCLASS),
  196. NextOffset(&PdConfigWire->PdConfig2W));
  197. break;
  198. case WinStationPdParams:
  199. BufSize = sizeof(PDPARAMSWIREW) + sizeof(PDPARAMSW);
  200. if ((WireBuf = (PCHAR)LocalAlloc(0,BufSize)) == NULL)
  201. return(ERROR_NOT_ENOUGH_MEMORY);
  202. PdParamsWire = (PPDPARAMSWIREW)WireBuf;
  203. InitVarData(&PdParamsWire->SdClassSpecific,
  204. sizeof(PDPARAMSW),
  205. sizeof(PDPARAMSWIREW));
  206. break;
  207. case WinStationConfiguration:
  208. BufSize = sizeof(WINSTACONFIGWIREW) + sizeof(USERCONFIGW);
  209. if ((WireBuf = (PCHAR)LocalAlloc(0,BufSize)) == NULL)
  210. return(ERROR_NOT_ENOUGH_MEMORY);
  211. WinStaConfigWire = (PWINSTACONFIGWIREW)WireBuf;
  212. InitVarData(&WinStaConfigWire->UserConfig,
  213. sizeof(USERCONFIGW),
  214. sizeof(WINSTACONFIGWIREW));
  215. InitVarData(&WinStaConfigWire->NewFields,
  216. 0,
  217. NextOffset(&WinStaConfigWire->UserConfig));
  218. break;
  219. case WinStationInformation:
  220. if ((Error = CreateGenericWireBuf(sizeof(WINSTATIONINFORMATIONW),
  221. &WireBuf,
  222. &BufSize)) != ERROR_SUCCESS)
  223. return(Error);
  224. break;
  225. case WinStationWd:
  226. if ((Error = CreateGenericWireBuf(sizeof(WDCONFIGW),
  227. &WireBuf,
  228. &BufSize)) != ERROR_SUCCESS)
  229. return(Error);
  230. break;
  231. case WinStationClient:
  232. if ((Error = CreateGenericWireBuf(sizeof(WINSTATIONCLIENTW),
  233. &WireBuf,
  234. &BufSize)) != ERROR_SUCCESS)
  235. return(Error);
  236. break;
  237. default:
  238. *ppWireBuf = NULL;
  239. *pBufAllocated = FALSE;
  240. return ERROR_SUCCESS;
  241. }
  242. *pWireBufLen = BufSize;
  243. *ppWireBuf = WireBuf;
  244. *pBufAllocated = TRUE;
  245. return ERROR_SUCCESS;
  246. }