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.

263 lines
7.1 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) 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 bStatus = FALSE;
  132. PBYTE InPacketSignature[SIGNATURE_SIZE];
  133. PBYTE GeneratedSignature [SIGNATURE_SIZE];
  134. TCHAR szErrorString [IAS_ERROR_STRING_LENGTH];
  135. IIasClient *pIIasClient = NULL;
  136. __try
  137. {
  138. //
  139. // get the CClient class object
  140. //
  141. hr = pCPacketRadius->GetClient (&pIIasClient);
  142. if (FAILED (hr)) { __leave; }
  143. //
  144. // get the signature attribute value from the inbound
  145. // packet
  146. //
  147. if (FALSE == pCPacketRadius->GetInSignature (
  148. reinterpret_cast <PBYTE> (InPacketSignature)
  149. ))
  150. {
  151. //
  152. // check if signature check is required
  153. //
  154. BOOL bCheckRequired = pIIasClient->NeedSignatureCheck ();
  155. if (!bCheckRequired)
  156. {
  157. __leave;
  158. }
  159. else
  160. {
  161. IASTracePrintf (
  162. "In-Bound request does not have does not have "
  163. "Message Authenticator attribute which is required for this client"
  164. );
  165. //
  166. // this is an error, need to silenty discard the
  167. // packet
  168. //
  169. PCWSTR strings[] = { pCPacketRadius->GetClientName() };
  170. IASReportEvent (
  171. RADIUS_E_SIGNATURE_REQUIRED,
  172. 1,
  173. 0,
  174. strings,
  175. NULL
  176. );
  177. m_pCReportEvent->Process (
  178. RADIUS_BAD_AUTHENTICATOR,
  179. pCPacketRadius->GetInCode (),
  180. pCPacketRadius->GetInLength(),
  181. pCPacketRadius->GetInAddress(),
  182. NULL,
  183. static_cast <LPVOID> (pCPacketRadius->GetInPacket())
  184. );
  185. hr = RADIUS_E_ERRORS_OCCURRED;
  186. __leave;
  187. }
  188. }
  189. //
  190. // generate the signature
  191. //
  192. DWORD dwBufSize = SIGNATURE_SIZE;
  193. hr = pCPacketRadius->GenerateInSignature (
  194. reinterpret_cast <PBYTE> (GeneratedSignature),
  195. &dwBufSize
  196. );
  197. if (FAILED (hr)) { __leave; }
  198. //
  199. // compare the signature attribute value in packet with
  200. // the one present
  201. //
  202. if (memcmp(InPacketSignature,GeneratedSignature,SIGNATURE_SIZE))
  203. {
  204. //
  205. // log error and generate audit event
  206. //
  207. IASTracePrintf (
  208. "Message Authenticator in request packet does not match the "
  209. "Message Authenticator generated by the server"
  210. );
  211. PCWSTR strings[] = { pCPacketRadius->GetClientName() };
  212. IASReportEvent (
  213. RADIUS_E_INVALID_SIGNATURE,
  214. 1,
  215. 0,
  216. strings,
  217. NULL
  218. );
  219. m_pCReportEvent->Process (
  220. RADIUS_BAD_AUTHENTICATOR,
  221. pCPacketRadius->GetInCode (),
  222. pCPacketRadius->GetInLength(),
  223. pCPacketRadius->GetInAddress(),
  224. NULL,
  225. static_cast <LPVOID> (pCPacketRadius->GetInPacket())
  226. );
  227. hr = RADIUS_E_ERRORS_OCCURRED;
  228. __leave;
  229. }
  230. //
  231. // success
  232. //
  233. }
  234. __finally
  235. {
  236. if (pIIasClient) { pIIasClient->Release (); }
  237. }
  238. return (hr);
  239. } // end of CValAccess::ValidateSignature method