Source code of Windows XP (NT5)
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.

224 lines
6.1 KiB

  1. /*************************************************************************
  2. *
  3. * icarpc.c
  4. *
  5. * Server specific routines for handling of RPC wire structures.
  6. *
  7. * Copyright Microsoft Corporation, 1998
  8. *
  9. *************************************************************************/
  10. /*
  11. * Includes
  12. */
  13. #include <nt.h>
  14. #include <ntrtl.h>
  15. #include <nturtl.h>
  16. #include <ntddkbd.h>
  17. #include <ntddmou.h>
  18. #include <windows.h>
  19. #include <winbase.h>
  20. #include <winerror.h>
  21. #include <winsta.h>
  22. #include "rpcwire.h"
  23. #if DBG
  24. ULONG
  25. DbgPrint(
  26. PCH Format,
  27. ...
  28. );
  29. #define DBGPRINT(x) DbgPrint x
  30. #if DBGTRACE
  31. #define TRACE0(x) DbgPrint x
  32. #define TRACE1(x) DbgPrint x
  33. #else
  34. #define TRACE0(x)
  35. #define TRACE1(x)
  36. #endif
  37. #else
  38. #define DBGPRINT(x)
  39. #define TRACE0(x)
  40. #define TRACE1(x)
  41. #endif
  42. /*****************************************************************************
  43. *
  44. * ValidWireBuffer
  45. *
  46. * Tests whether the buffer is a valid Winsta API Wire Buffer
  47. *
  48. * ENTRY:
  49. * InfoClass (input)
  50. * WinStationQuery/Set Information class.
  51. * WireBuf (input)
  52. * Data buffer
  53. * WireBufLen
  54. * Length of the wire buffer
  55. *
  56. * EXIT:
  57. * Returns true if the buffer is a valid wire format buffer, FALSE otherwise.
  58. *
  59. ****************************************************************************/
  60. BOOLEAN
  61. ValidWireBuffer(WINSTATIONINFOCLASS InfoClass,
  62. PVOID WireBuf,
  63. ULONG WireBufLen)
  64. {
  65. PVARDATA_WIRE GenericWire;
  66. PPDCONFIGWIREW PdConfigWire;
  67. PPDPARAMSWIREW PdParamsWire;
  68. PWINSTACONFIGWIREW WinStaConfigWire;
  69. switch(InfoClass) {
  70. case WinStationInformation:
  71. case WinStationWd:
  72. case WinStationClient:
  73. GenericWire = (PVARDATA_WIRE)WireBuf;
  74. if ((WireBufLen < sizeof(VARDATA_WIRE)) ||
  75. (GenericWire->Offset != sizeof(VARDATA_WIRE)) ||
  76. (WireBufLen < sizeof(VARDATA_WIRE) + GenericWire->Size)) {
  77. DBGPRINT(("ICASRV Bad Wire Buffer Type: %d\n",InfoClass));
  78. return(FALSE);
  79. }
  80. break;
  81. case WinStationPd:
  82. PdConfigWire = (PPDCONFIGWIREW)WireBuf;
  83. if ((WireBufLen < sizeof(PDCONFIGWIREW)) ||
  84. (PdConfigWire->PdConfig2W.Offset != sizeof(PDCONFIGWIREW)) ||
  85. (WireBufLen < sizeof(PDCONFIGWIREW) +
  86. PdConfigWire->PdConfig2W.Size +
  87. PdConfigWire->PdParams.SdClassSpecific.Size) ||
  88. (NextOffset(&PdConfigWire->PdConfig2W) !=
  89. PdConfigWire->PdParams.SdClassSpecific.Offset)) {
  90. DBGPRINT(("ICASRV Bad Wire Buffer Type: %d\n",InfoClass));
  91. return(FALSE);
  92. }
  93. break;
  94. case WinStationPdParams:
  95. PdParamsWire = (PPDPARAMSWIREW)WireBuf;
  96. if ((WireBufLen < sizeof(PDPARAMSWIREW)) ||
  97. (PdParamsWire->SdClassSpecific.Offset != sizeof(PDPARAMSWIREW)) ||
  98. (WireBufLen < sizeof(PDPARAMSWIREW) +
  99. PdParamsWire->SdClassSpecific.Size)) {
  100. DBGPRINT(("ICASRV Bad Wire Buffer Type: %d\n",InfoClass));
  101. return(FALSE);
  102. }
  103. break;
  104. case WinStationConfiguration:
  105. WinStaConfigWire = (PWINSTACONFIGWIREW)WireBuf;
  106. if ((WireBufLen < sizeof(WINSTACONFIGWIREW)) ||
  107. WinStaConfigWire->UserConfig.Offset != sizeof(WINSTACONFIGWIREW) ||
  108. (WireBufLen < sizeof(WINSTACONFIGWIREW) +
  109. WinStaConfigWire->UserConfig.Size +
  110. WinStaConfigWire->NewFields.Size) ||
  111. (NextOffset(&WinStaConfigWire->UserConfig) !=
  112. WinStaConfigWire->NewFields.Offset) ||
  113. (WireBufLen < NextOffset(&WinStaConfigWire->UserConfig)) ||
  114. (WireBufLen < NextOffset(&WinStaConfigWire->NewFields))) {
  115. DBGPRINT(("ICASRV Bad Wire Buffer Type: %d\n",InfoClass));
  116. return(FALSE);
  117. }
  118. break;
  119. default:
  120. return(FALSE);
  121. }
  122. return(TRUE);
  123. }
  124. /*****************************************************************************
  125. *
  126. * CheckWireBuffer
  127. *
  128. * Tests whether the buffer is a Winsta API Wire Buffer. If it is a valid
  129. * wire buffer, a local buffer is allocated and initialized from the data
  130. * in the wire buffer.
  131. *
  132. * ENTRY:
  133. * InfoClass (input)
  134. * WinStationQuery/Set Information class.
  135. * WireBuf (input)
  136. * Data buffer
  137. * WireBufLen
  138. * Length of the wire buffer
  139. * ppLocalBuf (output)
  140. * Local format buffer allocated for conversion from wire format to
  141. * native format.
  142. * pLocalBufLen
  143. * Length of the native buffer allocated.
  144. *
  145. * EXIT:
  146. * STATUS_SUCCESS if successful. If successful, a native local buffer
  147. * is allocated based on InfoClass and the wire buffer data is copied
  148. * into it.
  149. *
  150. ****************************************************************************/
  151. NTSTATUS
  152. CheckWireBuffer(WINSTATIONINFOCLASS InfoClass,
  153. PVOID WireBuf,
  154. ULONG WireBufLen,
  155. PVOID *ppLocalBuf,
  156. PULONG pLocalBufLen)
  157. {
  158. ULONG BufSize;
  159. PPDCONFIGWIREW PdConfigWire;
  160. PPDCONFIGW PdConfig;
  161. PPDPARAMSWIREW PdParamsWire;
  162. PPDPARAMSW PdParam;
  163. PWINSTACONFIGWIREW WinStaConfigWire;
  164. PWINSTATIONCONFIGW WinStaConfig;
  165. PVOID LocalBuf;
  166. switch (InfoClass) {
  167. case WinStationPd:
  168. BufSize = sizeof(PDCONFIGW);
  169. break;
  170. case WinStationPdParams:
  171. BufSize = sizeof(PDPARAMSW);
  172. break;
  173. case WinStationConfiguration:
  174. BufSize = sizeof(WINSTATIONCONFIGW);
  175. break;
  176. case WinStationInformation:
  177. BufSize = sizeof(WINSTATIONINFORMATIONW);
  178. break;
  179. case WinStationWd:
  180. BufSize = sizeof(WDCONFIGW);
  181. break;
  182. case WinStationClient:
  183. BufSize = sizeof(WINSTATIONCLIENTW);
  184. break;
  185. default:
  186. *ppLocalBuf = NULL;
  187. return(STATUS_INVALID_USER_BUFFER);
  188. }
  189. if (!ValidWireBuffer(InfoClass, WireBuf, WireBufLen)) {
  190. return(STATUS_INVALID_USER_BUFFER);
  191. }
  192. if ((LocalBuf = (PCHAR)LocalAlloc(0,BufSize)) == NULL)
  193. return(STATUS_NO_MEMORY);
  194. *pLocalBufLen = BufSize;
  195. *ppLocalBuf = LocalBuf;
  196. CopyOutWireBuf(InfoClass, LocalBuf, WireBuf);
  197. return(STATUS_SUCCESS);
  198. }