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.

267 lines
6.8 KiB

  1. //#--------------------------------------------------------------
  2. //
  3. // File: valaccess.cpp
  4. //
  5. // Synopsis: Implementation of CValAccess class methods
  6. //
  7. //
  8. // History: 9/23/97 MKarki Created
  9. //
  10. // Copyright (C) 1997-98 Microsoft Corporation
  11. // All rights reserved.
  12. //
  13. //----------------------------------------------------------------
  14. #include "radcommon.h"
  15. #include "valaccess.h"
  16. //+++--------------------------------------------------------------
  17. //
  18. // Function: CValAccess
  19. //
  20. // Synopsis: This is the constructor of the CValAccess
  21. // class
  22. //
  23. // Arguments: NONE
  24. //
  25. // Returns: NONE
  26. //
  27. //
  28. // History: MKarki Created 9/28/97
  29. //
  30. //----------------------------------------------------------------
  31. CValAccess::CValAccess(
  32. VOID
  33. )
  34. {
  35. } // end of CValAccess constructor
  36. //+++--------------------------------------------------------------
  37. //
  38. // Function: ~CValAccess
  39. //
  40. // Synopsis: This is the destructor of the CValAccess
  41. // class
  42. //
  43. // Arguments: NONE
  44. //
  45. // Returns: NONE
  46. //
  47. //
  48. // History: MKarki Created 9/28/97
  49. //
  50. //----------------------------------------------------------------
  51. CValAccess::~CValAccess(
  52. VOID
  53. )
  54. {
  55. } // end of CValAccess destructor
  56. //+++--------------------------------------------------------------
  57. //
  58. // Function: ValidateInPacket
  59. //
  60. // Synopsis: This is CValAccess class public method
  61. // that validates inbound Access Request packet
  62. //
  63. // Arguments:
  64. // [in] - CPacketRadius*
  65. //
  66. // Returns: HRESULT - status
  67. //
  68. //
  69. // History: MKarki Created 9/28/97
  70. //
  71. // Calleed By: CPreValidator::StartInValidation class method
  72. //
  73. //----------------------------------------------------------------
  74. HRESULT
  75. CValAccess::ValidateInPacket(
  76. CPacketRadius * pCPacketRadius
  77. )
  78. {
  79. HRESULT hr = S_OK;
  80. DWORD dwClientAddress = 0;
  81. CClient *pCClient = NULL;
  82. _ASSERT (pCPacketRadius);
  83. __try
  84. {
  85. //
  86. // validate the attributes
  87. //
  88. hr = m_pCValAttributes->Validate (pCPacketRadius);
  89. if (FAILED (hr)) { __leave; }
  90. //
  91. // validate the Signature present in the packet
  92. // if no signature is present this call will return
  93. // success
  94. //
  95. hr = ValidateSignature (pCPacketRadius);
  96. if (FAILED (hr)) { __leave; }
  97. //
  98. // now give the packet for processing
  99. //
  100. hr = m_pCPreProcessor->StartInProcessing (pCPacketRadius);
  101. if (FAILED (hr)) { __leave; }
  102. }
  103. __finally
  104. {
  105. }
  106. return (hr);
  107. } // end of CValAccess::ValidateInPacket method
  108. //+++-------------------------------------------------------------
  109. //
  110. // Function: ValidateSignature
  111. //
  112. // Synopsis: This is CValAccesss class private method
  113. // that carries out validation provided in an
  114. // inbound RADIUS access request which has a
  115. // signature attribute
  116. //
  117. // Arguments:
  118. // [in] CPacketRadius*
  119. //
  120. // Returns: HRESULT - status
  121. //
  122. // History: MKarki Created 1/6/98
  123. //
  124. //----------------------------------------------------------------
  125. HRESULT
  126. CValAccess::ValidateSignature (
  127. CPacketRadius *pCPacketRadius
  128. )
  129. {
  130. HRESULT hr = S_OK;
  131. BOOL bCheckRequired = FALSE;
  132. BOOL bStatus = FALSE;
  133. PBYTE InPacketSignature[SIGNATURE_SIZE];
  134. PBYTE GeneratedSignature [SIGNATURE_SIZE];
  135. TCHAR szErrorString [IAS_ERROR_STRING_LENGTH];
  136. IIasClient *pIIasClient = NULL;
  137. __try
  138. {
  139. //
  140. // get the CClient class object
  141. //
  142. hr = pCPacketRadius->GetClient (&pIIasClient);
  143. if (FAILED (hr)) { __leave; }
  144. //
  145. // get the signature attribute value from the inbound
  146. // packet
  147. //
  148. if (FALSE == pCPacketRadius->GetInSignature (
  149. reinterpret_cast <PBYTE> (InPacketSignature)
  150. ))
  151. {
  152. //
  153. // check if signature check is required
  154. //
  155. HRESULT hr1 = pIIasClient->NeedSignatureCheck (&bCheckRequired);
  156. _ASSERT (SUCCEEDED (hr1));
  157. if (FALSE == bCheckRequired)
  158. {
  159. __leave;
  160. }
  161. else
  162. {
  163. IASTracePrintf (
  164. "In-Bound request does not have does not have "
  165. "Signature attribute which is required for this client"
  166. );
  167. //
  168. // this is an error, need to silenty discard the
  169. // packet
  170. //
  171. PCWSTR strings[] = { pCPacketRadius->GetClientName() };
  172. IASReportEvent (
  173. RADIUS_E_SIGNATURE_REQUIRED,
  174. 1,
  175. 0,
  176. strings,
  177. NULL
  178. );
  179. m_pCReportEvent->Process (
  180. RADIUS_MALFORMED_PACKET,
  181. pCPacketRadius->GetInCode (),
  182. pCPacketRadius->GetInLength(),
  183. pCPacketRadius->GetInAddress(),
  184. NULL,
  185. static_cast <LPVOID> (pCPacketRadius->GetInPacket())
  186. );
  187. hr = RADIUS_E_ERRORS_OCCURRED;
  188. __leave;
  189. }
  190. }
  191. //
  192. // generate the signature
  193. //
  194. DWORD dwBufSize = SIGNATURE_SIZE;
  195. hr = pCPacketRadius->GenerateInSignature (
  196. reinterpret_cast <PBYTE> (GeneratedSignature),
  197. &dwBufSize
  198. );
  199. if (FAILED (hr)) { __leave; }
  200. //
  201. // compare the signature attribute value in packet with
  202. // the one present
  203. //
  204. if (memcmp(InPacketSignature,GeneratedSignature,SIGNATURE_SIZE))
  205. {
  206. //
  207. // log error and generate audit event
  208. //
  209. IASTracePrintf (
  210. "Signatures in request packet does not match the "
  211. "signature generated by the server"
  212. );
  213. PCWSTR strings[] = { pCPacketRadius->GetClientName() };
  214. IASReportEvent (
  215. RADIUS_E_INVALID_SIGNATURE,
  216. 1,
  217. 0,
  218. strings,
  219. NULL
  220. );
  221. m_pCReportEvent->Process (
  222. RADIUS_MALFORMED_PACKET,
  223. pCPacketRadius->GetInCode (),
  224. pCPacketRadius->GetInLength(),
  225. pCPacketRadius->GetInAddress(),
  226. NULL,
  227. static_cast <LPVOID> (pCPacketRadius->GetInPacket())
  228. );
  229. hr = RADIUS_E_ERRORS_OCCURRED;
  230. __leave;
  231. }
  232. //
  233. // success
  234. //
  235. }
  236. __finally
  237. {
  238. if (pIIasClient) { pIIasClient->Release (); }
  239. }
  240. return (hr);
  241. } // end of CValAccess::ValidateSignature method