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.

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