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.

366 lines
8.3 KiB

  1. //#--------------------------------------------------------------
  2. //
  3. // File: prevalidator.cpp
  4. //
  5. // Synopsis: Implementation of CPreValidator 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 "radpkt.h"
  16. #include "prevalidator.h"
  17. #include <new>
  18. //+++-------------------------------------------------------------
  19. //
  20. // Function: CPreValidator
  21. //
  22. // Synopsis: This is the constructor of the CPreValidator class
  23. //
  24. // Arguments: NONE
  25. //
  26. // Returns: NONE
  27. //
  28. //
  29. // History: MKarki Created 9/26/97
  30. //
  31. //----------------------------------------------------------------
  32. CPreValidator::CPreValidator(
  33. VOID
  34. )
  35. : m_pCValAccess (NULL),
  36. m_pCValAttributes (NULL),
  37. m_pCValAccounting (NULL),
  38. m_pCValProxy (NULL)
  39. {
  40. } // end of CPreValidator constructor
  41. //+++-------------------------------------------------------------
  42. //
  43. // Function: ~CPreValidator
  44. //
  45. // Synopsis: This is the destructor of the CPreValidator class
  46. //
  47. // Arguments: NONE
  48. //
  49. // Returns: NONE
  50. //
  51. //
  52. // History: MKarki Created 9/26/97
  53. //
  54. //----------------------------------------------------------------
  55. CPreValidator::~CPreValidator(
  56. VOID
  57. )
  58. {
  59. if (m_pCValProxy) {delete m_pCValProxy;}
  60. if (m_pCValAttributes) {delete m_pCValAttributes;}
  61. if (m_pCValAccess) {delete m_pCValAccess;}
  62. if (m_pCValAccounting) {delete m_pCValAccounting;}
  63. } // end of CPreValidator::~CPreValidator
  64. //+++-------------------------------------------------------------
  65. //
  66. // Function: Init
  67. //
  68. // Synopsis: This is the CPreValidator class initialization method
  69. //
  70. // Arguments:
  71. // [in] - CDictionary*
  72. // [in] - CPreProcsssor*
  73. // [in] - CClients*
  74. // [in] - CHashMD5*
  75. // [in] - CProxyState*
  76. // [in] - CSendToPipe*
  77. // [in] - CReportEvent*
  78. //
  79. // Returns: BOOL - status
  80. //
  81. // Called By: CController::OnInit class public method
  82. //
  83. // History: MKarki Created 9/26/97
  84. //
  85. //----------------------------------------------------------------
  86. BOOL CPreValidator::Init(
  87. CDictionary *pCDictionary,
  88. CPreProcessor *pCPreProcessor,
  89. CClients *pCClients,
  90. CHashMD5 *pCHashMD5,
  91. CProxyState *pCProxyState,
  92. CSendToPipe *pCSendToPipe,
  93. CReportEvent *pCReportEvent
  94. )
  95. {
  96. BOOL bRetVal = FALSE;
  97. BOOL bStatus = FALSE;
  98. _ASSERT (
  99. (NULL != pCDictionary) &&
  100. (NULL != pCPreProcessor)&&
  101. (NULL != pCClients) &&
  102. (NULL != pCHashMD5) &&
  103. (NULL != pCProxyState) &&
  104. (NULL != pCSendToPipe) &&
  105. (NULL != pCReportEvent)
  106. );
  107. //
  108. // attribute validator
  109. //
  110. m_pCValAttributes = new (std::nothrow) CValAttributes();
  111. if (NULL == m_pCValAttributes)
  112. {
  113. IASTracePrintf (
  114. "Memory allocation for Attribute Validator failed during "
  115. "Pre-Validation"
  116. );
  117. goto Cleanup;
  118. }
  119. //
  120. // initalize the attribute validator class object
  121. //
  122. bStatus = m_pCValAttributes->Init (pCDictionary, pCReportEvent);
  123. if (FALSE == bStatus)
  124. {
  125. IASTracePrintf ("Attribute Validator Initialization failed");
  126. goto Cleanup;
  127. }
  128. //
  129. // Accounting Request validator
  130. //
  131. m_pCValAccounting = new (std::nothrow) CValAccounting ();
  132. if (NULL == m_pCValAccounting)
  133. {
  134. IASTracePrintf (
  135. "Memory allocation for accounting validator failed "
  136. "during pre-validation"
  137. );
  138. goto Cleanup;
  139. }
  140. bStatus = m_pCValAccounting->Init (
  141. m_pCValAttributes,
  142. pCPreProcessor,
  143. pCClients,
  144. pCHashMD5,
  145. pCReportEvent
  146. );
  147. if (FALSE == bStatus)
  148. {
  149. IASTracePrintf ("Accounting Validator Initialization failed");
  150. goto Cleanup;
  151. }
  152. //
  153. // Access Request validator
  154. //
  155. m_pCValAccess = new (std::nothrow) CValAccess();
  156. if (NULL == m_pCValAccess)
  157. {
  158. IASTracePrintf (
  159. "Memory allocation for access validator failed "
  160. "during pre-validation"
  161. );
  162. goto Cleanup;
  163. }
  164. bStatus = m_pCValAccess->Init (
  165. m_pCValAttributes,
  166. pCPreProcessor,
  167. pCClients,
  168. pCHashMD5,
  169. pCReportEvent
  170. );
  171. if (FALSE == bStatus)
  172. {
  173. IASTracePrintf ("Accounting Validator Initialization failed");
  174. goto Cleanup;
  175. }
  176. //
  177. // Proxy Packet validator
  178. //
  179. m_pCValProxy = new (std::nothrow) CValProxy ();
  180. if (NULL == m_pCValAttributes)
  181. {
  182. IASTracePrintf (
  183. "Memory allocation for proxy alidator failed "
  184. "during pre-validation"
  185. );
  186. goto Cleanup;
  187. }
  188. //
  189. // initialize the CValProxy class object
  190. //
  191. bStatus = m_pCValProxy->Init (
  192. m_pCValAttributes,
  193. pCPreProcessor,
  194. pCClients,
  195. pCHashMD5,
  196. pCProxyState,
  197. pCSendToPipe,
  198. pCReportEvent
  199. );
  200. if (FALSE == bStatus)
  201. {
  202. IASTracePrintf ("Proxy Validator Initialization failed");
  203. goto Cleanup;
  204. }
  205. //
  206. // success
  207. //
  208. bRetVal = TRUE;
  209. Cleanup:
  210. if (FALSE == bRetVal)
  211. {
  212. if (m_pCValProxy) {delete m_pCValProxy;}
  213. if (m_pCValAttributes) {delete m_pCValAttributes;}
  214. if (m_pCValAccess) {delete m_pCValAccess;}
  215. if (m_pCValAccounting) {delete m_pCValAccounting;}
  216. }
  217. return (bRetVal);
  218. } // end of CPreValidator::Init method
  219. //+++-------------------------------------------------------------
  220. //
  221. // Function: StartInValidation
  222. //
  223. // Synopsis: This is the CPreValidator class method used to
  224. // initiate the validation of an inbound RADIUS packet
  225. //
  226. // Arguments: [in] - CPacketRadius*
  227. //
  228. // Returns: HRESULT - status
  229. //
  230. // History: MKarki Created 9/26/97
  231. //
  232. // Called By: CPacketReceiver::ReceivePacket class private method
  233. //
  234. //----------------------------------------------------------------
  235. HRESULT
  236. CPreValidator::StartInValidation(
  237. CPacketRadius * pCPacketRadius
  238. )
  239. {
  240. HRESULT hr = S_OK;
  241. PACKETTYPE ePacketType;
  242. _ASSERT (NULL != pCPacketRadius);
  243. __try
  244. {
  245. //
  246. // get the packet type for this RADIUS packet
  247. //
  248. ePacketType = pCPacketRadius->GetInCode ();
  249. //
  250. // call the appropriate validator depending upon the packet
  251. // type
  252. //
  253. switch (ePacketType)
  254. {
  255. case ACCESS_REQUEST:
  256. hr = m_pCValAccess->ValidateInPacket (pCPacketRadius);
  257. break;
  258. case ACCOUNTING_REQUEST:
  259. hr = m_pCValAccounting->ValidateInPacket (pCPacketRadius);
  260. break;
  261. case ACCESS_REJECT:
  262. case ACCESS_CHALLENGE:
  263. case ACCESS_ACCEPT:
  264. case ACCOUNTING_RESPONSE:
  265. hr = m_pCValProxy->ValidateInPacket (pCPacketRadius);
  266. break;
  267. default:
  268. //
  269. // should never reach here
  270. //
  271. _ASSERT (0);
  272. IASTracePrintf (
  273. "Packet of Unknown Type:%d, in pre-validator",
  274. static_cast <DWORD> (ePacketType)
  275. );
  276. hr = E_FAIL;
  277. break;
  278. }
  279. }
  280. __finally
  281. {
  282. }
  283. return (hr);
  284. } // end of CPreValidator::StartInValidation method
  285. //+++-------------------------------------------------------------
  286. //
  287. // Function: StartOutValidation
  288. //
  289. // Synopsis: This is the CPreValidator class method used to
  290. // initiate the validation of an outbound RADIUS packet
  291. //
  292. // Arguments:
  293. // [in] CPacketRadius*
  294. //
  295. // Returns: HRESULT - status
  296. //
  297. // History: MKarki Created 9/26/97
  298. //
  299. // Called By:
  300. //
  301. //----------------------------------------------------------------
  302. HRESULT
  303. CPreValidator::StartOutValidation(
  304. CPacketRadius * pCPacketRadius
  305. )
  306. {
  307. HRESULT hr = S_OK;
  308. __try
  309. {
  310. /*
  311. bStatus = pCValidator->ValidateOutPacket (pCPacketRadius);
  312. if (FALSE == bStatus) { __leave; }
  313. */
  314. //
  315. // we have completeted the pre-validation successfully
  316. //
  317. }
  318. __finally
  319. {
  320. //
  321. // nothing here for now
  322. //
  323. }
  324. return (hr);
  325. } // end of CPreValidator::StartOutValidation method