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.

353 lines
8.8 KiB

  1. //#--------------------------------------------------------------
  2. //
  3. // File: valproxy.cpp
  4. //
  5. // Synopsis: Implementation of CValProxy class methods
  6. //
  7. //
  8. // History: 9/23/97 MKarki Created
  9. //
  10. // Copyright (C) 1997-2001 Microsoft Corporation
  11. // All rights reserved.
  12. //
  13. //----------------------------------------------------------------
  14. #include "radcommon.h"
  15. #include "valproxy.h"
  16. #include "radpkt.h"
  17. //++--------------------------------------------------------------
  18. //
  19. // Function: CValProxy
  20. //
  21. // Synopsis: This is the constructor of the CValProxy
  22. // class
  23. //
  24. // Arguments: NONE
  25. //
  26. // Returns: NONE
  27. //
  28. //
  29. // History: MKarki Created 9/28/97
  30. //
  31. //----------------------------------------------------------------
  32. CValProxy::CValProxy(
  33. VOID
  34. )
  35. : m_pCSendToPipe (NULL)
  36. {
  37. } // end of CValProxy constructor
  38. //++--------------------------------------------------------------
  39. //
  40. // Function: ~CValProxy
  41. //
  42. // Synopsis: This is the destructor of the CValProxy
  43. // class
  44. //
  45. // Arguments: NONE
  46. //
  47. // Returns: NONE
  48. //
  49. //
  50. // History: MKarki Created 9/28/97
  51. //
  52. //----------------------------------------------------------------
  53. CValProxy::~CValProxy(
  54. VOID
  55. )
  56. {
  57. } // end of CValProxy destructor
  58. //++--------------------------------------------------------------
  59. //
  60. // Function: Init
  61. //
  62. // Synopsis: This is the CValProxy public method used
  63. // in initialization of the class object
  64. //
  65. // Arguments: NONE
  66. //
  67. // Returns: status
  68. //
  69. //
  70. // History: MKarki Created 9/28/97
  71. //
  72. //----------------------------------------------------------------
  73. BOOL
  74. CValProxy::Init (
  75. CValAttributes *pCValAttributes,
  76. CPreProcessor *pCPreProcessor,
  77. CClients *pCClients,
  78. CHashMD5 *pCHashMD5,
  79. CSendToPipe *pCSendToPipe,
  80. CReportEvent *pCReportEvent
  81. )
  82. {
  83. BOOL bRetVal = FALSE;
  84. BOOL bStatus = FALSE;
  85. __try
  86. {
  87. //
  88. // call the base classes init method
  89. //
  90. bStatus = CValidator::Init (
  91. pCValAttributes,
  92. pCPreProcessor,
  93. pCClients,
  94. pCHashMD5,
  95. pCReportEvent
  96. );
  97. if (FALSE == bStatus) { __leave; }
  98. //
  99. // set the proxy state
  100. //
  101. m_pCSendToPipe = pCSendToPipe;
  102. //
  103. // initalization complete
  104. //
  105. bRetVal = TRUE;
  106. }
  107. __finally
  108. {
  109. //
  110. // nothing here for now
  111. //
  112. }
  113. return (bRetVal);
  114. } // end of CValProxy::Init method
  115. //++--------------------------------------------------------------
  116. //
  117. // Function: ValidateInPacket
  118. //
  119. // Synopsis: This is CValProxy class public method
  120. // that validates inbound Access Request packet
  121. //
  122. // Arguments: [IN] - CPacketRadius*
  123. //
  124. // Returns: HRESULT - status
  125. //
  126. //
  127. // History: MKarki Created 9/28/97
  128. //
  129. // Calleed By: CPreValidator class method
  130. //
  131. //----------------------------------------------------------------
  132. HRESULT
  133. CValProxy::ValidateInPacket(
  134. CPacketRadius * pCPacketRadius
  135. )
  136. {
  137. BOOL bRetVal = FALSE;
  138. HRESULT hr = S_OK;
  139. __try
  140. {
  141. //
  142. // validate the attributes
  143. //
  144. hr = m_pCValAttributes->Validate (pCPacketRadius);
  145. if (FAILED(hr)) { __leave; }
  146. //
  147. // authenticate packet now
  148. //
  149. BYTE ReqAuthenticator[AUTHENTICATOR_SIZE];
  150. hr = AuthenticatePacket (
  151. pCPacketRadius,
  152. ReqAuthenticator
  153. );
  154. if (FAILED(hr)) { __leave; }
  155. //
  156. // now give the packet for processing
  157. //
  158. hr = m_pCPreProcessor->StartInProcessing (pCPacketRadius);
  159. if (FAILED(hr)) { __leave; }
  160. //
  161. // successfully processed packet
  162. //
  163. bRetVal = TRUE;
  164. }
  165. __finally
  166. {
  167. //
  168. // nothing here for now
  169. //
  170. }
  171. if (bRetVal)
  172. {
  173. return S_OK;
  174. }
  175. else
  176. {
  177. if (FAILED(hr))
  178. {
  179. return hr;
  180. }
  181. else
  182. {
  183. return E_FAIL;
  184. }
  185. }
  186. } // end of CValProxy::ValidateInPacket method
  187. //++--------------------------------------------------------------
  188. //
  189. // Function: ValidateOutPacket
  190. //
  191. // Synopsis: This is CValProxy class public method
  192. // that validates outbound Access Request packet
  193. //
  194. // Arguments: NONE
  195. //
  196. // Returns: HRESULT - status
  197. //
  198. //
  199. // History: MKarki Created 9/28/97
  200. //
  201. // Calleed By: CPreValidator class method
  202. //
  203. //----------------------------------------------------------------
  204. HRESULT
  205. CValProxy::ValidateOutPacket(
  206. CPacketRadius * pCPacketRadius
  207. )
  208. {
  209. return S_OK;
  210. } // end of CValProxy::ValidateOutPacket method
  211. //++--------------------------------------------------------------
  212. //
  213. // Function: AuthenticatePacket
  214. //
  215. // Synopsis: This is CValProxy class private method
  216. // that authenticates the packet, by generating a
  217. // response authenticator with the packet and then
  218. // comparing it with the request authenticator
  219. //
  220. // Arguments: [in] - CPacketRadius*
  221. //
  222. // Returns: BOOL - status
  223. //
  224. //
  225. // History: MKarki Created 9/28/97
  226. //
  227. // Called By: CValProxy::ValidateInPacket method
  228. //
  229. //----------------------------------------------------------------
  230. HRESULT
  231. CValProxy::AuthenticatePacket (
  232. CPacketRadius *pCPacketRadius,
  233. PBYTE pbyAuthenticator
  234. )
  235. {
  236. BOOL bRetVal = FALSE;
  237. BOOL bStatus = FALSE;
  238. PRADIUSPACKET pPacketRadius = NULL;
  239. DWORD dwPacketHeaderSize = 0;
  240. DWORD dwAttributesLength = 0;
  241. BYTE HashResult[AUTHENTICATOR_SIZE];
  242. IIasClient *pIIasClient = NULL;
  243. HRESULT hr = S_OK;
  244. __try
  245. {
  246. //
  247. // check that the arguments passed in are correct
  248. //
  249. if ((NULL == pCPacketRadius) || (NULL == pbyAuthenticator))
  250. __leave;
  251. //
  252. // get a pointer to the raw packet
  253. //
  254. pPacketRadius = reinterpret_cast <PRADIUSPACKET>
  255. (pCPacketRadius->GetInPacket ());
  256. //
  257. // get the size of the packet without the attributes and
  258. // request authenticator
  259. //
  260. dwPacketHeaderSize = sizeof (RADIUSPACKET)
  261. - sizeof (BYTE)
  262. - AUTHENTICATOR_SIZE;
  263. //
  264. // get the total attributes length now
  265. //
  266. dwAttributesLength = ntohs (pPacketRadius->wLength)
  267. - (dwPacketHeaderSize + AUTHENTICATOR_SIZE);
  268. //
  269. // get the CClients object
  270. //
  271. hr = pCPacketRadius->GetClient (&pIIasClient);
  272. if (FAILED (hr)) { __leave; }
  273. //
  274. // get the shared secret from the client object
  275. //
  276. DWORD dwSecretSize;
  277. const BYTE* bySecret = pIIasClient->GetSecret(&dwSecretSize);
  278. //
  279. // do the hashing here
  280. //
  281. m_pCHashMD5->HashIt (
  282. reinterpret_cast <PBYTE> (&HashResult),
  283. NULL,
  284. 0,
  285. reinterpret_cast <PBYTE> (pPacketRadius),
  286. dwPacketHeaderSize,
  287. pbyAuthenticator,
  288. AUTHENTICATOR_SIZE,
  289. pPacketRadius->AttributeStart,
  290. dwAttributesLength,
  291. const_cast<BYTE*>(bySecret),
  292. dwSecretSize,
  293. 0,
  294. 0
  295. );
  296. if (memcmp (
  297. HashResult,
  298. pPacketRadius->Authenticator,
  299. AUTHENTICATOR_SIZE
  300. )
  301. != 0
  302. )
  303. __leave;
  304. //
  305. // we have successfully authenticated this packet
  306. //
  307. bRetVal = TRUE;
  308. }
  309. __finally
  310. {
  311. if (NULL != pIIasClient)
  312. {
  313. pIIasClient->Release ();
  314. }
  315. }
  316. return S_OK;
  317. } // end of CValProxy::AuthenticatePacket method