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.

317 lines
7.9 KiB

  1. //#--------------------------------------------------------------
  2. //
  3. // File: preprocessor.cpp
  4. //
  5. // Synopsis: Implementation of CPreProcessor class methods
  6. //
  7. //
  8. // History: 9/30/97 MKarki Created
  9. //
  10. // Copyright (C) 1997-98 Microsoft Corporation
  11. // All rights reserved.
  12. //
  13. //----------------------------------------------------------------
  14. #include "radcommon.h"
  15. #include "preprocessor.h"
  16. #include <new>
  17. //+++-------------------------------------------------------------
  18. //
  19. // Function: CPreProcessor
  20. //
  21. // Synopsis: This is the constructor of the CPreProcessor class
  22. //
  23. // Arguments: NONE
  24. //
  25. // Returns: NONE
  26. //
  27. //
  28. // History: MKarki Created 9/30/97
  29. //
  30. //----------------------------------------------------------------
  31. CPreProcessor::CPreProcessor(
  32. VOID
  33. )
  34. : m_pCSendToPipe (NULL),
  35. m_pCProcResponse (NULL),
  36. m_pCProcAccounting (NULL),
  37. m_pCProcAccess (NULL)
  38. {
  39. } // end of CPreProcessor constructor
  40. //+++-------------------------------------------------------------
  41. //
  42. // Function: ~CPreProcessor
  43. //
  44. // Synopsis: This is the destructor of the CPreProcessor class
  45. //
  46. // Arguments: NONE
  47. //
  48. // Returns: NONE
  49. //
  50. //
  51. // History: MKarki Created 9/30/97
  52. //
  53. //----------------------------------------------------------------
  54. CPreProcessor::~CPreProcessor(VOID)
  55. {
  56. if (m_pCProcResponse) {delete (m_pCProcResponse);}
  57. if (m_pCProcAccounting) {delete (m_pCProcAccounting);}
  58. if (m_pCProcAccess) { delete (m_pCProcAccess);}
  59. } // end of CPreProcessor destructor
  60. //+++-------------------------------------------------------------
  61. //
  62. // Function: Init
  63. //
  64. // Synopsis: This is the CPreProcessor class initialization method
  65. //
  66. // Arguments:
  67. // [in] CPreValidator*
  68. // [in] CHashMD5*
  69. // [in] CProxyState*
  70. // [in] CSendToPipe*
  71. // [in] CPacketSender*
  72. // none
  73. //
  74. // Returns: BOOL - status
  75. //
  76. // Called By: CCollector class method
  77. //
  78. // History: MKarki Created 9/26/97
  79. //
  80. //----------------------------------------------------------------
  81. BOOL CPreProcessor::Init(
  82. CPreValidator *pCPreValidator,
  83. CHashMD5 *pCHashMD5,
  84. CProxyState *pCProxyState,
  85. CSendToPipe *pCSendToPipe,
  86. CPacketSender *pCPacketSender,
  87. CReportEvent *pCReportEvent
  88. )
  89. {
  90. BOOL bRetVal = FALSE;
  91. BOOL bStatus = FALSE;
  92. _ASSERT (
  93. (NULL != pCPreValidator) &&
  94. (NULL != pCHashMD5) &&
  95. (NULL != pCProxyState) &&
  96. (NULL != pCSendToPipe) &&
  97. (NULL != pCPacketSender) &&
  98. (NULL != pCReportEvent)
  99. );
  100. m_pCSendToPipe = pCSendToPipe;
  101. //
  102. // Access Request processor
  103. //
  104. m_pCProcAccess = new (std::nothrow) CProcAccess ();
  105. if (NULL == m_pCProcAccess)
  106. {
  107. IASTracePrintf (
  108. "Unable to crate Access-Processing object in "
  109. "Pre-Processor initialization"
  110. );
  111. goto Cleanup;
  112. }
  113. //
  114. // initialize the access request processor
  115. //
  116. bStatus = m_pCProcAccess->Init (
  117. pCPreValidator,
  118. pCHashMD5,
  119. pCProxyState,
  120. pCSendToPipe
  121. );
  122. if (FALSE == bStatus) { goto Cleanup; }
  123. //
  124. // Accounting Request processor
  125. //
  126. m_pCProcAccounting = new (std::nothrow) CProcAccounting ();
  127. if (NULL == m_pCProcAccounting)
  128. {
  129. IASTracePrintf (
  130. "Unable to crate Accounting-Processing object in "
  131. "Pre-Processor initialization"
  132. );
  133. goto Cleanup;
  134. }
  135. //
  136. // initialize the accounting request processor
  137. //
  138. bStatus = m_pCProcAccounting->Init (
  139. pCPreValidator,
  140. pCProxyState,
  141. pCPacketSender,
  142. pCSendToPipe
  143. );
  144. if (FALSE == bStatus) { goto Cleanup; }
  145. //
  146. // Response packet processor
  147. //
  148. m_pCProcResponse = new (std::nothrow) CProcResponse ();
  149. if (NULL == m_pCProcResponse)
  150. {
  151. IASTracePrintf (
  152. "Unable to crate Response-Processing object in "
  153. "Pre-Processor initialization"
  154. );
  155. goto Cleanup;
  156. }
  157. //
  158. // initialize the response processor
  159. //
  160. bStatus = m_pCProcResponse->Init (
  161. pCPreValidator,
  162. pCPacketSender
  163. );
  164. if (FALSE == bStatus) { goto Cleanup; }
  165. //
  166. // success
  167. //
  168. bRetVal = TRUE;
  169. Cleanup:
  170. if (FALSE == bRetVal)
  171. {
  172. if (m_pCProcResponse) {delete (m_pCProcResponse);}
  173. if (m_pCProcAccounting){delete (m_pCProcAccounting);}
  174. if (m_pCProcAccess) {delete (m_pCProcAccess);}
  175. }
  176. return (bRetVal);
  177. } // end of CPreProcessor::Init method
  178. //+++-------------------------------------------------------------
  179. //
  180. // Function: StartInProcessing
  181. //
  182. // Synopsis: This is the CPreProcessor class method used to
  183. // initiate the processing of an inbound RADIUS packet
  184. //
  185. // Arguments: [in] - CPacketRadius*
  186. //
  187. // Returns: HRESULT - status
  188. //
  189. // History: MKarki Created 9/30/97
  190. //
  191. // Called By: CValidator derived class method
  192. //
  193. //----------------------------------------------------------------
  194. HRESULT
  195. CPreProcessor::StartInProcessing (
  196. CPacketRadius *pCPacketRadius
  197. )
  198. {
  199. HRESULT hr = S_OK;
  200. _ASSERT (pCPacketRadius);
  201. //
  202. // get the packet type for this RADIUS packet
  203. //
  204. PACKETTYPE ePacketType = pCPacketRadius->GetInCode ();
  205. if (ACCESS_REQUEST == ePacketType)
  206. {
  207. //
  208. // we still have to get the password out of the packet
  209. //
  210. hr = m_pCProcAccess->ProcessInPacket (pCPacketRadius);
  211. }
  212. else
  213. {
  214. //
  215. // in all other cases, there is no disassembly to be done
  216. // so call the Service Request Generator
  217. //
  218. hr = m_pCSendToPipe->Process (pCPacketRadius);
  219. }
  220. return (hr);
  221. } // end of CPreProcessor::StartInProcessing method
  222. //++--------------------------------------------------------------
  223. //
  224. // Function: StartOutProcessing
  225. //
  226. // Synopsis: This is the CPreProcessor class method used to
  227. // initiate the processing of an outbound RADIUS packet
  228. //
  229. // Arguments: [IN] - CPacketRadius*
  230. //
  231. // Returns: HRESULT - status
  232. //
  233. // History: MKarki Created 9/26/97
  234. //
  235. // Called By: CPacketReceiver class method
  236. //
  237. //----------------------------------------------------------------
  238. HRESULT
  239. CPreProcessor::StartOutProcessing(
  240. CPacketRadius * pCPacketRadius
  241. )
  242. {
  243. PACKETTYPE ePacketType;
  244. HRESULT hr = S_OK;
  245. __try
  246. {
  247. //
  248. // get the packet type for this RADIUS packet
  249. //
  250. ePacketType = pCPacketRadius->GetOutCode ();
  251. switch (ePacketType)
  252. {
  253. case ACCESS_REQUEST:
  254. hr = m_pCProcAccess->ProcessOutPacket (pCPacketRadius);
  255. break;
  256. case ACCOUNTING_REQUEST:
  257. hr = m_pCProcAccounting->ProcessOutPacket (pCPacketRadius);
  258. break;
  259. case ACCESS_CHALLENGE:
  260. case ACCESS_REJECT:
  261. case ACCESS_ACCEPT:
  262. case ACCOUNTING_RESPONSE:
  263. hr = m_pCProcResponse->ProcessOutPacket (pCPacketRadius);
  264. break;
  265. default:
  266. //
  267. // in all other cases, there is no disassembly to be done
  268. // so call the Service Request Generator
  269. //
  270. _ASSERT (0);
  271. IASTracePrintf (
  272. "Packet of unknown type:%d found in the pre-processing stage ",
  273. static_cast <DWORD> (ePacketType)
  274. );
  275. hr = E_FAIL;
  276. break;
  277. }
  278. //
  279. // we have completed the pre-validation successfully
  280. //
  281. }
  282. __finally
  283. {
  284. }
  285. return (hr);
  286. } // end of CPreProcessor::StartOutProcessing method