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.

312 lines
8.0 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] CSendToPipe*
  70. // [in] CPacketSender*
  71. // none
  72. //
  73. // Returns: BOOL - status
  74. //
  75. // Called By: CCollector class method
  76. //
  77. // History: MKarki Created 9/26/97
  78. //
  79. //----------------------------------------------------------------
  80. BOOL CPreProcessor::Init(
  81. CPreValidator *pCPreValidator,
  82. CHashMD5 *pCHashMD5,
  83. CSendToPipe *pCSendToPipe,
  84. CPacketSender *pCPacketSender,
  85. CReportEvent *pCReportEvent
  86. )
  87. {
  88. BOOL bRetVal = FALSE;
  89. BOOL bStatus = FALSE;
  90. _ASSERT (
  91. (NULL != pCPreValidator) &&
  92. (NULL != pCHashMD5) &&
  93. (NULL != pCSendToPipe) &&
  94. (NULL != pCPacketSender) &&
  95. (NULL != pCReportEvent)
  96. );
  97. m_pCSendToPipe = pCSendToPipe;
  98. //
  99. // Access Request processor
  100. //
  101. m_pCProcAccess = new (std::nothrow) CProcAccess ();
  102. if (NULL == m_pCProcAccess)
  103. {
  104. IASTracePrintf (
  105. "Unable to crate Access-Processing object in "
  106. "Pre-Processor initialization"
  107. );
  108. goto Cleanup;
  109. }
  110. //
  111. // initialize the access request processor
  112. //
  113. bStatus = m_pCProcAccess->Init (
  114. pCPreValidator,
  115. pCHashMD5,
  116. pCSendToPipe
  117. );
  118. if (FALSE == bStatus) { goto Cleanup; }
  119. //
  120. // Accounting Request processor
  121. //
  122. m_pCProcAccounting = new (std::nothrow) CProcAccounting ();
  123. if (NULL == m_pCProcAccounting)
  124. {
  125. IASTracePrintf (
  126. "Unable to crate Accounting-Processing object in "
  127. "Pre-Processor initialization"
  128. );
  129. goto Cleanup;
  130. }
  131. //
  132. // initialize the accounting request processor
  133. //
  134. bStatus = m_pCProcAccounting->Init (
  135. pCPreValidator,
  136. pCPacketSender,
  137. pCSendToPipe
  138. );
  139. if (FALSE == bStatus) { goto Cleanup; }
  140. //
  141. // Response packet processor
  142. //
  143. m_pCProcResponse = new (std::nothrow) CProcResponse ();
  144. if (NULL == m_pCProcResponse)
  145. {
  146. IASTracePrintf (
  147. "Unable to crate Response-Processing object in "
  148. "Pre-Processor initialization"
  149. );
  150. goto Cleanup;
  151. }
  152. //
  153. // initialize the response processor
  154. //
  155. bStatus = m_pCProcResponse->Init (
  156. pCPreValidator,
  157. pCPacketSender
  158. );
  159. if (FALSE == bStatus) { goto Cleanup; }
  160. //
  161. // success
  162. //
  163. bRetVal = TRUE;
  164. Cleanup:
  165. if (FALSE == bRetVal)
  166. {
  167. if (m_pCProcResponse) {delete (m_pCProcResponse);}
  168. if (m_pCProcAccounting){delete (m_pCProcAccounting);}
  169. if (m_pCProcAccess) {delete (m_pCProcAccess);}
  170. }
  171. return (bRetVal);
  172. } // end of CPreProcessor::Init method
  173. //+++-------------------------------------------------------------
  174. //
  175. // Function: StartInProcessing
  176. //
  177. // Synopsis: This is the CPreProcessor class method used to
  178. // initiate the processing of an inbound RADIUS packet
  179. //
  180. // Arguments: [in] - CPacketRadius*
  181. //
  182. // Returns: HRESULT - status
  183. //
  184. // History: MKarki Created 9/30/97
  185. //
  186. // Called By: CValidator derived class method
  187. //
  188. //----------------------------------------------------------------
  189. HRESULT
  190. CPreProcessor::StartInProcessing (
  191. CPacketRadius *pCPacketRadius
  192. )
  193. {
  194. HRESULT hr = S_OK;
  195. _ASSERT (pCPacketRadius);
  196. //
  197. // get the packet type for this RADIUS packet
  198. //
  199. PACKETTYPE ePacketType = pCPacketRadius->GetInCode ();
  200. if (ACCESS_REQUEST == ePacketType)
  201. {
  202. //
  203. // we still have to get the password out of the packet
  204. //
  205. hr = m_pCProcAccess->ProcessInPacket (pCPacketRadius);
  206. }
  207. else
  208. {
  209. //
  210. // in all other cases, there is no disassembly to be done
  211. // so call the Service Request Generator
  212. //
  213. hr = m_pCSendToPipe->Process (pCPacketRadius);
  214. }
  215. return (hr);
  216. } // end of CPreProcessor::StartInProcessing method
  217. //++--------------------------------------------------------------
  218. //
  219. // Function: StartOutProcessing
  220. //
  221. // Synopsis: This is the CPreProcessor class method used to
  222. // initiate the processing of an outbound RADIUS packet
  223. //
  224. // Arguments: [IN] - CPacketRadius*
  225. //
  226. // Returns: HRESULT - status
  227. //
  228. // History: MKarki Created 9/26/97
  229. //
  230. // Called By: CPacketReceiver class method
  231. //
  232. //----------------------------------------------------------------
  233. HRESULT
  234. CPreProcessor::StartOutProcessing(
  235. CPacketRadius * pCPacketRadius
  236. )
  237. {
  238. PACKETTYPE ePacketType;
  239. HRESULT hr = S_OK;
  240. __try
  241. {
  242. //
  243. // get the packet type for this RADIUS packet
  244. //
  245. ePacketType = pCPacketRadius->GetOutCode ();
  246. switch (ePacketType)
  247. {
  248. case ACCESS_REQUEST:
  249. hr = m_pCProcAccess->ProcessOutPacket (pCPacketRadius);
  250. break;
  251. case ACCOUNTING_REQUEST:
  252. hr = m_pCProcAccounting->ProcessOutPacket (pCPacketRadius);
  253. break;
  254. case ACCESS_CHALLENGE:
  255. case ACCESS_REJECT:
  256. case ACCESS_ACCEPT:
  257. case ACCOUNTING_RESPONSE:
  258. hr = m_pCProcResponse->ProcessOutPacket (pCPacketRadius);
  259. break;
  260. default:
  261. //
  262. // in all other cases, there is no disassembly to be done
  263. // so call the Service Request Generator
  264. //
  265. _ASSERT (0);
  266. IASTracePrintf (
  267. "Packet of unknown type:%d found in the pre-processing stage ",
  268. static_cast <DWORD> (ePacketType)
  269. );
  270. hr = E_FAIL;
  271. break;
  272. }
  273. //
  274. // we have completed the pre-validation successfully
  275. //
  276. }
  277. __finally
  278. {
  279. }
  280. return (hr);
  281. } // end of CPreProcessor::StartOutProcessing method