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.

339 lines
8.2 KiB

  1. //#--------------------------------------------------------------
  2. //
  3. // File: procaccess.cpp
  4. //
  5. // Synopsis: Implementation of CProcAccess class methods
  6. //
  7. //
  8. // History: 10/20/97 MKarki Created
  9. //
  10. // Copyright (C) 1997-98 Microsoft Corporation
  11. // All rights reserved.
  12. //
  13. //----------------------------------------------------------------
  14. #include "radcommon.h"
  15. #include "procaccess.h"
  16. //+++-------------------------------------------------------------
  17. //
  18. // Function: CProcAccess
  19. //
  20. // Synopsis: This is CProcAccess class constructor
  21. //
  22. // Arguments: NONE
  23. //
  24. // Returns: NONE
  25. //
  26. //
  27. // History: MKarki Created 10/20/97
  28. //
  29. //----------------------------------------------------------------
  30. CProcAccess::CProcAccess()
  31. : m_pCPreValidator (NULL),
  32. m_pCHashMD5 (NULL),
  33. m_pCProxyState (NULL),
  34. m_pCSendToPipe (NULL)
  35. {
  36. } // end of CProcAccess class constructor
  37. //+++-------------------------------------------------------------
  38. //
  39. // Function: CProcAccess
  40. //
  41. // Synopsis: This is CProcAccess class destructor
  42. //
  43. // Arguments: NONE
  44. //
  45. // Returns: NONE
  46. //
  47. //
  48. // History: MKarki Created 10/20/97
  49. //
  50. //----------------------------------------------------------------
  51. CProcAccess::~CProcAccess()
  52. {
  53. } // end of CProcAccess class destructor
  54. //+++-------------------------------------------------------------
  55. //
  56. // Function: Init
  57. //
  58. // Synopsis: This is CProcAccess class public initialization
  59. // method
  60. //
  61. // Arguments: NONE
  62. //
  63. // Returns: status
  64. //
  65. //
  66. // History: MKarki Created 10/20/97
  67. //
  68. //----------------------------------------------------------------
  69. BOOL
  70. CProcAccess::Init(
  71. CPreValidator *pCPreValidator,
  72. CHashMD5 *pCHashMD5,
  73. CProxyState *pCProxyState,
  74. CSendToPipe *pCSendToPipe
  75. )
  76. {
  77. _ASSERT ((NULL != pCPreValidator) &&
  78. (NULL != pCHashMD5) &&
  79. (NULL != pCProxyState) &&
  80. (NULL != pCSendToPipe)
  81. );
  82. m_pCPreValidator = pCPreValidator;
  83. m_pCHashMD5 = pCHashMD5;
  84. m_pCProxyState = pCProxyState;
  85. m_pCSendToPipe = pCSendToPipe;
  86. return (TRUE);
  87. } // end of CProcAccess::Init method
  88. //+++-------------------------------------------------------------
  89. //
  90. // Function: ProcessInPacket
  91. //
  92. // Synopsis: This is CProcAccess class public method
  93. // which carries out the processing of an inbound
  94. // RADIUS packet - for now it just decrypts the
  95. // password
  96. //
  97. // Arguments:
  98. // [in] CPacketRadius*
  99. //
  100. // Returns: HRESULT - status
  101. //
  102. // History: MKarki Created 10/20/97
  103. //
  104. // Called By: CPreProcessor::StartProcessing public method
  105. //
  106. //----------------------------------------------------------------
  107. HRESULT
  108. CProcAccess::ProcessInPacket (
  109. CPacketRadius *pCPacketRadius
  110. )
  111. {
  112. // If the User-Password is present, ...
  113. PIASATTRIBUTE pwd = pCPacketRadius->GetUserPassword();
  114. if (pwd)
  115. {
  116. // ... then decrypt it.
  117. pCPacketRadius->cryptBuffer(
  118. FALSE,
  119. FALSE,
  120. pwd->Value.OctetString.lpValue,
  121. pwd->Value.OctetString.dwLength
  122. );
  123. }
  124. return m_pCSendToPipe->Process (pCPacketRadius);
  125. }
  126. //++--------------------------------------------------------------
  127. //
  128. // Function: ProcessOutPacket
  129. //
  130. // Synopsis: This is CProcAccess class public method
  131. // which carries out the processing of an outbound
  132. // RADIUS packet - for now it just encrypts the
  133. // password
  134. //
  135. //
  136. // Arguments:
  137. // [in] CPacketRadius*
  138. //
  139. // Returns: HRESULT - status
  140. //
  141. //
  142. // History: MKarki Created 10/20/97
  143. //
  144. // Called By:
  145. //
  146. //----------------------------------------------------------------
  147. HRESULT
  148. CProcAccess::ProcessOutPacket (
  149. CPacketRadius *pCPacketRadius
  150. )
  151. {
  152. BOOL bStatus = FALSE;
  153. BOOL bRetVal = FALSE;
  154. DWORD dwSize = 0;
  155. DWORD dwPasswordLength = 0;
  156. BYTE RequestAuthenticator[AUTHENTICATOR_SIZE];
  157. DWORD dwProxyId = 0;
  158. _ASSERT (pCPacketRadius);
  159. /*
  160. __try
  161. {
  162. //
  163. // generate a request authenticator
  164. // TODO - make it a random value later
  165. //
  166. ZeroMemory (RequestAuthenticator, AUTHENTICATOR_SIZE);
  167. //
  168. // insert the proxy state attribute now
  169. //
  170. bStatus = m_pCProxyState->GenerateProxyState (
  171. pCPacketRadius,
  172. &dwProxyId
  173. );
  174. if (FALSE == bStatus) { __leave; }
  175. //
  176. // set the Proxy State information
  177. //
  178. bStatus = m_pCProxyState->SetProxyStateInfo (
  179. pCPacketRadius,
  180. dwProxyId,
  181. reinterpret_cast <PBYTE>
  182. (&RequestAuthenticator)
  183. );
  184. if (FALSE == bStatus) { __leave; }
  185. //
  186. // check if we have a User-Password attribute
  187. //
  188. //
  189. // take the cleartext password and put encrypted
  190. // password in its place
  191. //
  192. bStatus = GeneratePassword (pCPacketRadius);
  193. if (FALSE == bStatus)
  194. __leave;
  195. //
  196. // insert the User-Password attribute here
  197. //
  198. bStatus = InsertPassword (pCPacketRadius);
  199. if (FALSE == bStatus)
  200. __leave;
  201. //
  202. // we have successfully done the processing here
  203. //
  204. bRetVal = TRUE;
  205. }
  206. __finally
  207. {
  208. //
  209. // nothing here for now
  210. //
  211. }
  212. return (bRetVal);
  213. */
  214. return (S_OK);
  215. } // end of CProcAccess::ProcessOutPacket method
  216. //++--------------------------------------------------------------
  217. //
  218. // Function: InsertPassword
  219. //
  220. // Synopsis: This is CProcAccess class private method
  221. // which inserts an encrypted password into
  222. // the outbound RADIUS packet
  223. //
  224. // NOTE: The password is not a null-terminated
  225. // string
  226. //
  227. //
  228. // Arguments:
  229. // [in] CPacketRadius*
  230. //
  231. // Returns: status
  232. //
  233. //
  234. // History: MKarki Created 10/20/97
  235. //
  236. // Called By: CProcAccess::ProcessOutPacket method
  237. //
  238. //----------------------------------------------------------------
  239. BOOL
  240. CProcAccess::InsertPassword (
  241. CPacketRadius *pCPacketRadius
  242. )
  243. {
  244. BOOL bRetVal = FALSE;
  245. BYTE UserPassword[MAX_PASSWORD_SIZE];
  246. DWORD dwPasswordLength = MAX_PASSWORD_SIZE;
  247. BOOL bStatus = FALSE;
  248. _ASSERT (pCPacketRadius);
  249. /*
  250. __try
  251. {
  252. //
  253. // get the password out of the packet first
  254. //
  255. bStatus = pCPacketRadius->GetPassword (
  256. UserPassword,
  257. &dwPasswordLength
  258. );
  259. if (FALSE == bStatus)
  260. __leave;
  261. //
  262. // get a new out attribute now
  263. bStatus = pCPacketRadius->CreateOutAttribute (
  264. &pCAttribute,
  265. dwPasswordLength
  266. );
  267. if (FALSE == bStatus)
  268. __leave;
  269. //
  270. // set the attribute information
  271. //
  272. bStatus = pCAttribute->SetInfo (
  273. USER_PASSWORD_ATTRIB,
  274. reinterpret_cast <PBYTE> (UserPassword),
  275. dwPasswordLength
  276. );
  277. if (FALSE == bStatus)
  278. __leave;
  279. //
  280. // store the attribute into the collection
  281. //
  282. bStatus = pCPacketRadius->StoreOutAttribute (pCAttribute);
  283. if (FALSE == bStatus)
  284. __leave;
  285. //
  286. // success
  287. //
  288. bRetVal = TRUE;
  289. }
  290. __finally
  291. {
  292. //
  293. // nothing here for now
  294. //
  295. }
  296. */
  297. return (bRetVal);
  298. } // end of CProcAccess::InsertPassword method