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.

1466 lines
34 KiB

  1. //#--------------------------------------------------------------
  2. //
  3. // File: controller.cpp
  4. //
  5. // Synopsis: Implementation of CController class methods
  6. //
  7. //
  8. // History: 10/02/97 MKarki Created
  9. // 6/04/98 SBens Added the InfoBase class.
  10. // 9/09/98 SBens Let the InfoBase know when we're reset.
  11. // 1/25/00 SBens Clear the ports in InternalCleanup.
  12. //
  13. // Copyright (C) 1997-98 Microsoft Corporation
  14. // All rights reserved.
  15. //
  16. //----------------------------------------------------------------
  17. #include "radcommon.h"
  18. #include "controller.h"
  19. #include <new>
  20. LONG g_lPacketCount = 0;
  21. LONG g_lThreadCount = 0;
  22. const DWORD MAX_SLEEP_TIME = 50; //milliseconds
  23. //++--------------------------------------------------------------
  24. //
  25. // Function: CController
  26. //
  27. // Synopsis: This is CController class constructor
  28. //
  29. // Arguments: NONE
  30. //
  31. // Returns: NONE
  32. //
  33. //
  34. // History: MKarki Created 10/2/97
  35. //
  36. //----------------------------------------------------------------
  37. CController::CController (
  38. VOID
  39. )
  40. :m_objCRequestSource (this),
  41. m_pCSendToPipe (NULL),
  42. m_pCProxyState (NULL),
  43. m_pCDictionary (NULL),
  44. m_pCPacketReceiver (NULL),
  45. m_pCPreValidator (NULL),
  46. m_pCPreProcessor (NULL),
  47. m_pCClients (NULL),
  48. m_pCHashMD5 (NULL),
  49. m_pCHashHmacMD5 (NULL),
  50. m_pCRecvFromPipe (NULL),
  51. m_pCPacketSender (NULL),
  52. m_pCReportEvent (NULL),
  53. m_pCVSAFilter (NULL),
  54. m_pInfoBase (NULL),
  55. m_pCTunnelPassword (NULL),
  56. m_wAuthPort (IAS_DEFAULT_AUTH_PORT),
  57. m_wAcctPort (IAS_DEFAULT_ACCT_PORT),
  58. m_dwAuthHandle (0),
  59. m_dwAcctHandle (0),
  60. m_pIRequestHandler (NULL),
  61. m_eRadCompState (COMP_SHUTDOWN)
  62. {
  63. } // end of CController constructor
  64. //++--------------------------------------------------------------
  65. //
  66. // Function: ~CController
  67. //
  68. // Synopsis: This is CController class destructor
  69. //
  70. // Arguments: NONE
  71. //
  72. // Returns: NONE
  73. //
  74. //
  75. // History: MKarki Created 10/2/97
  76. //
  77. //----------------------------------------------------------------
  78. CController::~CController(
  79. VOID
  80. )
  81. {
  82. } // end of CController destructor
  83. //++--------------------------------------------------------------
  84. //
  85. // Function: InitNew
  86. //
  87. // Synopsis: This is the InitNew method exposed through the
  88. // IIasComponent COM Interface. It is used to
  89. // initialize the RADIUS protocol component
  90. //
  91. // Arguments: NONE
  92. //
  93. // Returns: HRESULT - status
  94. //
  95. //
  96. // History: MKarki Created 10/2/97
  97. //
  98. //----------------------------------------------------------------
  99. STDMETHODIMP
  100. CController::InitNew (
  101. VOID
  102. )
  103. {
  104. HRESULT hr = S_OK;
  105. BOOL bStatus = FALSE;
  106. //
  107. // InitNew can only be called from the shutdown state
  108. //
  109. if (COMP_SHUTDOWN != m_eRadCompState)
  110. {
  111. IASTracePrintf ("Incorrect state for calling InitNew");
  112. hr = E_UNEXPECTED;
  113. goto Cleanup;
  114. }
  115. //
  116. // create the CReportEvent class object
  117. //
  118. m_pCReportEvent = new (std::nothrow) CReportEvent ();
  119. if (NULL == m_pCReportEvent)
  120. {
  121. IASTracePrintf (
  122. "Unable to create ReportEvent object in Controller initialization"
  123. );
  124. hr = E_OUTOFMEMORY;
  125. goto Cleanup;
  126. }
  127. //
  128. // create the CTunnelPassword class object
  129. //
  130. m_pCTunnelPassword = new (std::nothrow) CTunnelPassword;
  131. if (NULL == m_pCTunnelPassword)
  132. {
  133. IASTracePrintf (
  134. "Unable to create Tunnel-Password object in Controller initialization"
  135. );
  136. hr = E_FAIL;
  137. goto Cleanup;
  138. }
  139. //
  140. // create the VSAFilter class object
  141. //
  142. m_pCVSAFilter = new (std::nothrow) VSAFilter;
  143. if (NULL == m_pCVSAFilter)
  144. {
  145. IASTracePrintf (
  146. "Unable to create VSA-Filter object in Controller initialization"
  147. );
  148. hr = E_FAIL;
  149. goto Cleanup;
  150. }
  151. //
  152. // initialize the VSA filter class object
  153. //
  154. hr = m_pCVSAFilter->initialize ();
  155. if (FAILED (hr))
  156. {
  157. IASTracePrintf (
  158. "Unable to initalize VSA-Filter object in Controller initialization"
  159. );
  160. delete m_pCVSAFilter;
  161. m_pCVSAFilter = NULL;
  162. goto Cleanup;
  163. }
  164. //
  165. // create the CPacketSender class object
  166. //
  167. m_pCPacketSender = new (std::nothrow) CPacketSender ();
  168. if (NULL == m_pCPacketSender)
  169. {
  170. IASTracePrintf (
  171. "Unable to create Packet-Sender object in Controller initialization"
  172. );
  173. hr = E_OUTOFMEMORY;
  174. goto Cleanup;
  175. }
  176. //
  177. // create the CProxyState class object
  178. //
  179. m_pCProxyState = new (std::nothrow) CProxyState ();
  180. if (NULL == m_pCProxyState)
  181. {
  182. IASTracePrintf (
  183. "Unable to create Proxy-State object in Controller initialization"
  184. );
  185. hr = E_OUTOFMEMORY;
  186. goto Cleanup;
  187. }
  188. //
  189. // initialize the CProxyState class object
  190. // TODO - initalize the IP address and the Table Size
  191. //
  192. bStatus = m_pCProxyState->Init (212, 1024);
  193. if (FALSE == bStatus)
  194. {
  195. IASTracePrintf (
  196. "Unable to initialize Proxy-State object in Controller initialization"
  197. );
  198. hr = E_FAIL;
  199. goto Cleanup;
  200. }
  201. //
  202. // create the CHashHmacMD5 class object
  203. //
  204. m_pCHashHmacMD5 = new (std::nothrow) CHashHmacMD5 ();
  205. if (NULL == m_pCHashHmacMD5)
  206. {
  207. IASTracePrintf (
  208. "Unable to create HMAC-MD5 object in Controller initialization"
  209. );
  210. hr = E_OUTOFMEMORY;
  211. goto Cleanup;
  212. }
  213. //
  214. // create the CHashMD5 class object
  215. //
  216. m_pCHashMD5 = new (std::nothrow) CHashMD5 ();
  217. if (NULL == m_pCHashMD5)
  218. {
  219. IASTracePrintf (
  220. "Unable to create MD5 object in Controller initialization"
  221. );
  222. hr = E_OUTOFMEMORY;
  223. goto Cleanup;
  224. }
  225. //
  226. // create the CDictionary class object
  227. //
  228. m_pCDictionary = new (std::nothrow) CDictionary ();
  229. if (NULL == m_pCDictionary)
  230. {
  231. IASTracePrintf (
  232. "Unable to create Dictionary object in Controller initialization"
  233. );
  234. hr = E_OUTOFMEMORY;
  235. goto Cleanup;
  236. }
  237. //
  238. // initialize the CDictionary class object
  239. //
  240. bStatus = m_pCDictionary->Init ();
  241. if (FALSE == bStatus)
  242. {
  243. IASTracePrintf (
  244. "Unable to initialize Dictionary object in Controller initialization"
  245. );
  246. hr = E_FAIL;
  247. goto Cleanup;
  248. }
  249. //
  250. // create the CClients class object
  251. //
  252. m_pCClients = new (std::nothrow) CClients ();
  253. if (NULL == m_pCClients)
  254. {
  255. IASTracePrintf (
  256. "Unable to create clients object in Controller initialization"
  257. );
  258. hr = E_OUTOFMEMORY;
  259. goto Cleanup;
  260. }
  261. //
  262. // initialize the CClients call object now
  263. //
  264. hr = m_pCClients->Init ();
  265. if (FAILED (hr))
  266. {
  267. IASTracePrintf (
  268. "Unable to initialize clients object in Controller initialization"
  269. );
  270. delete m_pCClients;
  271. m_pCClients = NULL;
  272. goto Cleanup;
  273. }
  274. //
  275. // create the CSendToPipe class object
  276. //
  277. m_pCSendToPipe = new (std::nothrow) CSendToPipe();
  278. if (NULL == m_pCSendToPipe)
  279. {
  280. IASTracePrintf (
  281. "Unable to create Send-To-Pipe object in Controller initialization"
  282. );
  283. hr = E_OUTOFMEMORY;
  284. goto Cleanup;
  285. }
  286. //
  287. // create the CPreProcessor class object
  288. //
  289. //
  290. m_pCPreProcessor = new (std::nothrow) CPreProcessor();
  291. if (NULL == m_pCPreProcessor)
  292. {
  293. IASTracePrintf (
  294. "Unable to create Pre-Processor object in Controller initialization"
  295. );
  296. hr = E_OUTOFMEMORY;
  297. goto Cleanup;
  298. }
  299. //
  300. // create the CPreValidator class object
  301. //
  302. //
  303. m_pCPreValidator = new (std::nothrow) CPreValidator ();
  304. if (NULL == m_pCPreValidator)
  305. {
  306. IASTracePrintf (
  307. "Unable to create Pre-Validator object in Controller initialization"
  308. );
  309. hr = E_OUTOFMEMORY;
  310. goto Cleanup;
  311. }
  312. //
  313. // initialize the CPreProcessor class object
  314. //
  315. bStatus = m_pCPreProcessor->Init (
  316. m_pCPreValidator,
  317. m_pCHashMD5,
  318. m_pCProxyState,
  319. m_pCSendToPipe,
  320. m_pCPacketSender,
  321. m_pCReportEvent
  322. );
  323. if (FALSE == bStatus)
  324. {
  325. IASTracePrintf (
  326. "Unable to initialize Pre-Processor object in Controller initialization"
  327. );
  328. hr = E_FAIL;
  329. goto Cleanup;
  330. }
  331. //
  332. // initialize the CPreValidator class object
  333. //
  334. bStatus = m_pCPreValidator->Init (
  335. m_pCDictionary,
  336. m_pCPreProcessor,
  337. m_pCClients,
  338. m_pCHashMD5,
  339. m_pCProxyState,
  340. m_pCSendToPipe,
  341. m_pCReportEvent
  342. );
  343. if (FALSE == bStatus)
  344. {
  345. IASTracePrintf (
  346. "Unable to initialize Pre-Validator object in Controller initialization"
  347. );
  348. hr = E_FAIL;
  349. goto Cleanup;
  350. }
  351. //
  352. // create the CRecvFromPipe class object
  353. //
  354. m_pCRecvFromPipe = new (std::nothrow) CRecvFromPipe (
  355. m_pCPreProcessor,
  356. m_pCHashMD5,
  357. m_pCHashHmacMD5,
  358. m_pCClients,
  359. m_pCVSAFilter,
  360. m_pCTunnelPassword,
  361. m_pCReportEvent
  362. );
  363. if (NULL == m_pCRecvFromPipe)
  364. {
  365. IASTracePrintf (
  366. "Unable to create RecvFromPipe object in Controller initialization"
  367. );
  368. hr = E_FAIL;
  369. goto Cleanup;
  370. }
  371. // create the CPacketReceiver class object
  372. //
  373. m_pCPacketReceiver = new (std::nothrow) CPacketReceiver ();
  374. if (NULL == m_pCPacketReceiver)
  375. {
  376. IASTracePrintf (
  377. "Unable to create Packet-Receiver object in Controller initialization"
  378. );
  379. hr = E_OUTOFMEMORY;
  380. goto Cleanup;
  381. }
  382. //
  383. // initialize the CPacketReceiver class object
  384. //
  385. bStatus = m_pCPacketReceiver->Init (
  386. m_pCDictionary,
  387. m_pCPreValidator,
  388. m_pCHashMD5,
  389. m_pCHashHmacMD5,
  390. m_pCClients,
  391. m_pCReportEvent
  392. );
  393. if (FALSE == bStatus)
  394. {
  395. IASTracePrintf (
  396. "Unable to initialize Packet-Receiver object "
  397. "in Controller initialization"
  398. );
  399. hr = E_FAIL;
  400. goto Cleanup;
  401. }
  402. //
  403. // initialize the CSendToPipe class object
  404. //
  405. bStatus = m_pCSendToPipe->Init (
  406. reinterpret_cast <IRequestSource*>
  407. (&m_objCRequestSource),
  408. m_pCVSAFilter,
  409. m_pCReportEvent
  410. );
  411. if (FALSE == bStatus)
  412. {
  413. IASTracePrintf (
  414. "Unable to initialize Send-to-pipe object in Controller initialization"
  415. );
  416. hr = E_FAIL;
  417. goto Cleanup;
  418. }
  419. //
  420. // Create and InitNew the InfoBase object
  421. //
  422. CLSID clsid;
  423. hr = CLSIDFromProgID(IAS_PROGID(InfoBase), &clsid);
  424. if (SUCCEEDED(hr))
  425. {
  426. hr = CoCreateInstance(clsid,
  427. NULL,
  428. CLSCTX_INPROC_SERVER,
  429. __uuidof(IIasComponent),
  430. (PVOID*)&m_pInfoBase);
  431. if (SUCCEEDED(hr))
  432. {
  433. hr = m_pInfoBase->InitNew();
  434. }
  435. }
  436. if (FAILED(hr))
  437. {
  438. IASTracePrintf (
  439. "Unable to create InfoBase auditor in Controller initialization"
  440. );
  441. goto Cleanup;
  442. }
  443. //
  444. // reset make the global counts as a precaution
  445. //
  446. g_lPacketCount = 0;
  447. g_lThreadCount = 0;
  448. //
  449. // if we have reached here than InitNew succeeded and we
  450. // are in Uninitialized state
  451. //
  452. m_eRadCompState = COMP_UNINITIALIZED;
  453. Cleanup:
  454. //
  455. // if we failed its time to cleanup
  456. //
  457. if (FAILED (hr)) { InternalCleanup (); }
  458. return (hr);
  459. } // end of CController::OnInit method
  460. //++--------------------------------------------------------------
  461. //
  462. // Function: Load
  463. //
  464. // Synopsis: This is the IPersistPropertyBag2 COM Interface
  465. // method which is called in to indicate that its
  466. // time to load configuration information from the
  467. // property bag.
  468. //
  469. // Arguments:
  470. // [in] IPropertyBag2
  471. // [in] IErrorLog
  472. //
  473. // Returns: HRESULT - status
  474. //
  475. //
  476. // History: MKarki Created 10/2/97
  477. //
  478. //----------------------------------------------------------------
  479. STDMETHODIMP
  480. CController::Load (
  481. IPropertyBag2 *pIPropertyBag,
  482. IErrorLog *pIErrorLog
  483. )
  484. {
  485. if ((NULL == pIPropertyBag) || (NULL == pIErrorLog)){return (E_POINTER);}
  486. return (S_OK);
  487. } // end of CController::Load method
  488. //++--------------------------------------------------------------
  489. //
  490. // Function: Save
  491. //
  492. // Synopsis: This is the IPersistPropertyBag2 COM Interface
  493. // method which is called in to indicate that its
  494. // time to save configuration information from the
  495. // property bag.
  496. //
  497. // Arguments:
  498. // [in] IPropertyBag2
  499. // [in] BOOL - Dirty Bit flag
  500. // [in] BOOL - save all properties
  501. //
  502. // Returns: HRESULT - status
  503. //
  504. //
  505. // History: MKarki Created 10/2/97
  506. //
  507. //----------------------------------------------------------------
  508. STDMETHODIMP
  509. CController::Save (
  510. IPropertyBag2 *pIPropertyBag,
  511. BOOL bClearDirty,
  512. BOOL bSaveAllProperties
  513. )
  514. {
  515. if (NULL == pIPropertyBag) {return (E_POINTER);}
  516. return (S_OK);
  517. } // end of CController::Save method
  518. //++--------------------------------------------------------------
  519. //
  520. // Function: IsDirty
  521. //
  522. // Synopsis: This is the IPersistPropertyBag2 COM Interface
  523. // method which is called to check if any of the
  524. // properties data have become dirty
  525. //
  526. // Arguments:
  527. //
  528. // Returns: HRESULT - status
  529. //
  530. //
  531. // History: MKarki Created 10/2/97
  532. //
  533. //----------------------------------------------------------------
  534. STDMETHODIMP
  535. CController::IsDirty (
  536. VOID
  537. )
  538. {
  539. return (S_FALSE);
  540. } // end of CController::Save method
  541. //++--------------------------------------------------------------
  542. //
  543. // Function: Initialize
  544. //
  545. // Synopsis: This is the OnStart method exposed through the
  546. // IIasComponent COM Interface. It is used to start
  547. // processing data
  548. //
  549. // Arguments: NONE
  550. //
  551. // Returns: HRESULT - status
  552. //
  553. //
  554. // History: MKarki Created 10/2/97
  555. //
  556. //----------------------------------------------------------------
  557. STDMETHODIMP
  558. CController::Initialize (
  559. VOID
  560. )
  561. {
  562. IASTracePrintf ("Initializing Radius component....");
  563. //
  564. // Initialize call can only be made from Uninitialized state
  565. //
  566. if (COMP_INITIALIZED == m_eRadCompState)
  567. {
  568. return (S_OK);
  569. }
  570. else if (COMP_UNINITIALIZED != m_eRadCompState)
  571. {
  572. IASTracePrintf (
  573. "Unable to initialize Radius Component in this state"
  574. );
  575. return (E_UNEXPECTED);
  576. }
  577. //
  578. // We forward all state transitions to the InfoBase auditor.
  579. //
  580. HRESULT hr = m_pInfoBase->Initialize();
  581. if (FAILED (hr))
  582. {
  583. IASTracePrintf ( "InfoBase initialization failed" );
  584. return (hr);
  585. }
  586. //
  587. // call the internal initializer now
  588. //
  589. hr = InternalInit ();
  590. if (FAILED (hr)) { return (hr); }
  591. //
  592. // we have finished initialization here
  593. //
  594. m_eRadCompState = COMP_INITIALIZED;
  595. IASTracePrintf ("Radius component initialized.");
  596. return (S_OK);
  597. } // end of CController::Start method
  598. //++--------------------------------------------------------------
  599. //
  600. // Function: Shutdown
  601. //
  602. // Synopsis: This is the OnShutDown method exposed through the
  603. // IComponent COM Interface. It is used to stop
  604. // processing data
  605. //
  606. // Arguments: NONE
  607. //
  608. // Returns: HRESULT - status
  609. //
  610. //
  611. // History: MKarki Created 10/2/97
  612. //
  613. //----------------------------------------------------------------
  614. STDMETHODIMP
  615. CController::Shutdown (
  616. VOID
  617. )
  618. {
  619. BOOL bStatus = FALSE;
  620. HRESULT hr = S_OK;
  621. IASTracePrintf ("Shutting down Radius Component...");
  622. //
  623. // shutdown can only be called from the suspend state
  624. //
  625. if (COMP_SHUTDOWN == m_eRadCompState)
  626. {
  627. return (S_OK);
  628. }
  629. else if (
  630. (COMP_SUSPENDED != m_eRadCompState) &&
  631. (COMP_UNINITIALIZED != m_eRadCompState)
  632. )
  633. {
  634. IASTracePrintf (
  635. "Radius component can not be shutdown in this state"
  636. );
  637. return (E_UNEXPECTED);
  638. }
  639. //
  640. // We forward all state transitions to the InfoBase auditor.
  641. //
  642. hr = m_pInfoBase->Shutdown();
  643. if (FAILED (hr))
  644. {
  645. IASTracePrintf ("InfoBase shutdown failed");
  646. }
  647. //
  648. // do the internal cleanup now
  649. //
  650. InternalCleanup ();
  651. //
  652. // we have cleanly shutdown
  653. //
  654. m_eRadCompState = COMP_SHUTDOWN;
  655. IASTracePrintf ("Radius component shutdown completed");
  656. return (hr);
  657. } // end of CController::Shutdown method
  658. //++--------------------------------------------------------------
  659. //
  660. // Function: Suspend
  661. //
  662. // Synopsis: This is the Suspend method exposed through the
  663. // IComponent COM Interface. It is used to suspend
  664. // packet processing operations
  665. //
  666. // Arguments: NONE
  667. //
  668. // Returns: HRESULT - status
  669. //
  670. //
  671. // History: MKarki Created 10/2/97
  672. //
  673. //----------------------------------------------------------------
  674. STDMETHODIMP
  675. CController::Suspend (
  676. VOID
  677. )
  678. {
  679. BOOL bStatus = FALSE;
  680. HRESULT hr = S_OK;
  681. IASTracePrintf ("Suspending Radius component...");
  682. //
  683. // suspend can only be called from the initialized state
  684. //
  685. if (COMP_SUSPENDED == m_eRadCompState)
  686. {
  687. return (S_OK);
  688. }
  689. else if (COMP_INITIALIZED != m_eRadCompState)
  690. {
  691. IASTracePrintf (
  692. "Radius component can not be suspended in current state"
  693. );
  694. return (E_UNEXPECTED);
  695. }
  696. //
  697. // We forward all state transitions to the InfoBase auditor.
  698. //
  699. hr = m_pInfoBase->Suspend();
  700. if (FAILED (hr))
  701. {
  702. IASTracePrintf ("Infobase suspend failed");
  703. }
  704. //
  705. // stop receiving packets now
  706. //
  707. bStatus = m_pCPacketReceiver->StopProcessing ();
  708. if (FALSE == bStatus) { hr = E_FAIL; }
  709. //
  710. // now wait till all requests are completed
  711. //
  712. while ( g_lPacketCount )
  713. {
  714. IASTracePrintf (
  715. "Packet Left to process:%d",
  716. g_lPacketCount
  717. );
  718. Sleep (MAX_SLEEP_TIME);
  719. }
  720. //
  721. // stop sending out packets
  722. //
  723. bStatus = m_pCPacketSender->StopProcessing ();
  724. if (FALSE == bStatus) { hr = E_FAIL; }
  725. //
  726. // stop sending packets to the pipeline
  727. //
  728. bStatus = m_pCSendToPipe->StopProcessing ();
  729. if (FALSE == bStatus) { hr = E_FAIL; }
  730. //
  731. // now wait till allour earlier threads are back
  732. // and requests are completed
  733. //
  734. while ( g_lThreadCount )
  735. {
  736. IASTracePrintf (
  737. "Worker thread active:%d",
  738. g_lThreadCount
  739. );
  740. Sleep (MAX_SLEEP_TIME);
  741. }
  742. //
  743. // we have successfully suspended RADIUS component's packet
  744. // processing operations
  745. //
  746. m_eRadCompState = COMP_SUSPENDED;
  747. IASTracePrintf ("Radius component suspended.");
  748. return (hr);
  749. } // end of CController::Suspend method
  750. //++--------------------------------------------------------------
  751. //
  752. // Function: Resume
  753. //
  754. // Synopsis: This is the Resume method exposed through the
  755. // IComponent COM Interface. It is used to resume
  756. // packet processing operations which had been
  757. // stopped by a previous call to Suspend API
  758. //
  759. //
  760. // Arguments: NONE
  761. //
  762. // Returns: HRESULT - status
  763. //
  764. //
  765. // History: MKarki Created 10/2/97
  766. //
  767. //----------------------------------------------------------------
  768. STDMETHODIMP
  769. CController::Resume (
  770. VOID
  771. )
  772. {
  773. IASTracePrintf ("Resuming Radius component...");
  774. if (COMP_SUSPENDED != m_eRadCompState)
  775. {
  776. IASTracePrintf ("Can not resume Radius component in current state");
  777. return (E_UNEXPECTED);
  778. }
  779. //
  780. // We forward all state transitions to the InfoBase auditor.
  781. //
  782. HRESULT hr = m_pInfoBase->Resume();
  783. if (FAILED (hr))
  784. {
  785. IASTracePrintf ("Unable to resume Infobase");
  786. return (hr);
  787. }
  788. //
  789. // now call the internal initializer to start up the component
  790. //
  791. hr = InternalInit ();
  792. if (FAILED (hr)) { return (hr); }
  793. //
  794. // we have successfully resumed operations in the RADIUS component
  795. //
  796. m_eRadCompState = COMP_INITIALIZED;
  797. IASTracePrintf ("Radius componend resumed.");
  798. return (S_OK);
  799. } // end of CController::Resume method
  800. //++--------------------------------------------------------------
  801. //
  802. // Function: GetProperty
  803. //
  804. // Synopsis: This is the IIasComponent Interface method used
  805. // to get property information from the RADIUS protocol
  806. // component
  807. //
  808. // Arguments:
  809. // [in] LONG - id
  810. // [out] VARIANT - *pValue
  811. //
  812. // Returns: HRESULT - status
  813. //
  814. //
  815. // History: MKarki Created 10/2/97
  816. //
  817. //----------------------------------------------------------------
  818. STDMETHODIMP
  819. CController::GetProperty (
  820. LONG id,
  821. VARIANT *pValue
  822. )
  823. {
  824. return (S_OK);
  825. } // end of CController::GetProperty method
  826. //++--------------------------------------------------------------
  827. //
  828. // Function: PutProperty
  829. //
  830. // Synopsis: This is the IIasComponent Interface method used
  831. // to put property information int the RADIUS protocol
  832. // component
  833. //
  834. // Arguments:
  835. // [in] LONG - id
  836. // [out] VARIANT - *pValue
  837. //
  838. // Returns: HRESULT - status
  839. //
  840. //
  841. // History: MKarki Created 10/2/97
  842. //
  843. //----------------------------------------------------------------
  844. STDMETHODIMP
  845. CController::PutProperty (
  846. LONG id,
  847. VARIANT *pValue
  848. )
  849. {
  850. HRESULT hr = S_OK;
  851. //
  852. // PutProperty method can only be called from
  853. // Uninitialized, Initialized or Suspended state
  854. //
  855. if (
  856. (COMP_UNINITIALIZED != m_eRadCompState) &&
  857. (COMP_INITIALIZED != m_eRadCompState) &&
  858. (COMP_SUSPENDED != m_eRadCompState)
  859. )
  860. {
  861. IASTracePrintf ("Unable to PutProperty in current state");
  862. return (E_UNEXPECTED);
  863. }
  864. //
  865. // check if valid arguments where passed in
  866. //
  867. if (NULL == pValue) { return (E_POINTER); }
  868. //
  869. // carry out the property intialization now
  870. //
  871. switch (id)
  872. {
  873. case PROPERTY_RADIUS_ACCOUNTING_PORT:
  874. if (VT_BSTR != V_VT (pValue))
  875. {
  876. hr = DISP_E_TYPEMISMATCH;
  877. }
  878. else if (COMP_INITIALIZED != m_eRadCompState)
  879. {
  880. //
  881. // initialize Accounting Port
  882. //
  883. m_objAcctPort.Resolve (pValue);
  884. }
  885. break;
  886. case PROPERTY_RADIUS_AUTHENTICATION_PORT:
  887. if (VT_BSTR != V_VT (pValue))
  888. {
  889. hr = DISP_E_TYPEMISMATCH;
  890. }
  891. else if (COMP_INITIALIZED != m_eRadCompState)
  892. {
  893. //
  894. // initialize Authentication Port
  895. //
  896. m_objAuthPort.Resolve (pValue);
  897. }
  898. break;
  899. case PROPERTY_RADIUS_CLIENTS_COLLECTION:
  900. hr = m_pCClients->SetClients (pValue);
  901. break;
  902. case PROPERTY_PROTOCOL_REQUEST_HANDLER:
  903. if (VT_DISPATCH != pValue->vt)
  904. {
  905. hr = DISP_E_TYPEMISMATCH;
  906. }
  907. else if (NULL == pValue->punkVal)
  908. {
  909. hr = E_INVALIDARG;
  910. }
  911. else
  912. {
  913. //
  914. // initialize the provider
  915. //
  916. m_pIRequestHandler = reinterpret_cast <IRequestHandler*>
  917. (pValue->punkVal);
  918. m_pIRequestHandler->AddRef ();
  919. //
  920. // now that we have the request handler set,
  921. // we are ready to start processing requests
  922. //
  923. if (COMP_INITIALIZED == m_eRadCompState)
  924. {
  925. hr = InternalInit ();
  926. }
  927. }
  928. break;
  929. default:
  930. hr = DISP_E_MEMBERNOTFOUND;
  931. break;
  932. }
  933. //
  934. // Tickle the InfoBase to let it know we've been reset.
  935. //
  936. m_pInfoBase->PutProperty(0, NULL);
  937. return (hr);
  938. } // end of CController::PutProperty method
  939. //++--------------------------------------------------------------
  940. //
  941. // Function: InternalInit
  942. //
  943. // Synopsis: This is the InternalInit private method
  944. // of the CController class object which is used
  945. // to the initialization when the Initialize or
  946. // Resume methods of the IIasComponent interface
  947. // are called
  948. //
  949. // Arguments: NONE
  950. //
  951. // Returns: HRESULT - status
  952. //
  953. // History: MKarki Created 4/28/98
  954. //
  955. //----------------------------------------------------------------
  956. HRESULT
  957. CController::InternalInit (
  958. VOID
  959. )
  960. {
  961. BOOL bStatus = FALSE;
  962. HRESULT hr = S_OK;
  963. __try
  964. {
  965. //
  966. //
  967. // check if we have the RequestHandler in place
  968. //
  969. if (NULL == m_pIRequestHandler) { __leave; }
  970. //
  971. // get the authentication socket set
  972. //
  973. fd_set AuthSet;
  974. hr = m_objAuthPort.GetSocketSet (&AuthSet);
  975. if (FAILED (hr))
  976. {
  977. IASTracePrintf (
  978. "Unable to obtain Authentication Socket set during "
  979. "internal initialization of Radius Component"
  980. );
  981. __leave;
  982. }
  983. //
  984. // get the accounting socket set
  985. //
  986. fd_set AcctSet;
  987. hr = m_objAcctPort.GetSocketSet (&AcctSet);
  988. if (FAILED (hr))
  989. {
  990. IASTracePrintf (
  991. "Unable to obtain Accounting Socket set during "
  992. "internal initialization of Radius Component"
  993. );
  994. __leave;
  995. }
  996. //
  997. // start sending data to pipe
  998. //
  999. bStatus = m_pCSendToPipe->StartProcessing (m_pIRequestHandler);
  1000. if (FALSE == bStatus)
  1001. {
  1002. hr = E_FAIL;
  1003. __leave;
  1004. }
  1005. //
  1006. // start sending out packets
  1007. //
  1008. bStatus = m_pCPacketSender->StartProcessing ();
  1009. if (FALSE == bStatus)
  1010. {
  1011. hr = E_FAIL;
  1012. __leave;
  1013. }
  1014. //
  1015. // start receiving packets now
  1016. //
  1017. bStatus = m_pCPacketReceiver->StartProcessing (AuthSet, AcctSet);
  1018. if (FALSE == bStatus)
  1019. {
  1020. hr = E_FAIL;
  1021. __leave;
  1022. }
  1023. //
  1024. // we have finished internal initialization here
  1025. //
  1026. }
  1027. __finally
  1028. {
  1029. if (FAILED (hr))
  1030. {
  1031. //
  1032. // if failed, disconnect from backend
  1033. //
  1034. m_pCPacketReceiver->StopProcessing ();
  1035. m_pCPacketSender->StopProcessing ();
  1036. m_pCSendToPipe->StopProcessing ();
  1037. }
  1038. }
  1039. return (hr);
  1040. } // end of CController::InternalInit method
  1041. //++--------------------------------------------------------------
  1042. //
  1043. // Function: InternalCleanup
  1044. //
  1045. // Synopsis: This is the InternalInit private method
  1046. // of the CController class object which is used
  1047. // to shutdown the internal resources when then
  1048. // InitNew call failed or Shutdown is called
  1049. //
  1050. // Arguments: NONE
  1051. //
  1052. // Returns: HRESULT - status
  1053. //
  1054. // History: MKarki Created 4/28/98
  1055. //
  1056. //----------------------------------------------------------------
  1057. VOID
  1058. CController::InternalCleanup (
  1059. VOID
  1060. )
  1061. {
  1062. //
  1063. // release the IRequestHandler interfaces
  1064. //
  1065. if (m_pIRequestHandler)
  1066. {
  1067. m_pIRequestHandler->Release ();
  1068. m_pIRequestHandler = NULL;
  1069. }
  1070. //
  1071. // shutdown the VSA filter object
  1072. //
  1073. if (m_pCVSAFilter) { m_pCVSAFilter->shutdown (); }
  1074. //
  1075. // stop the CClients object from resolving DNS names
  1076. //
  1077. if (m_pCClients) { m_pCClients->Shutdown (); }
  1078. // Close all the ports.
  1079. m_objAuthPort.Clear();
  1080. m_objAcctPort.Clear();
  1081. //
  1082. // delete all the internal objects
  1083. //
  1084. if (m_pInfoBase)
  1085. {
  1086. m_pInfoBase->Release();
  1087. m_pInfoBase = NULL;
  1088. }
  1089. if (m_pCTunnelPassword)
  1090. {
  1091. delete m_pCTunnelPassword;
  1092. m_pCTunnelPassword = NULL;
  1093. }
  1094. if (m_pCVSAFilter)
  1095. {
  1096. delete m_pCVSAFilter;
  1097. m_pCVSAFilter = NULL;
  1098. }
  1099. if (m_pCPacketSender)
  1100. {
  1101. delete m_pCPacketSender;
  1102. m_pCPacketSender = NULL;
  1103. }
  1104. if (m_pCSendToPipe)
  1105. {
  1106. delete m_pCSendToPipe;
  1107. m_pCSendToPipe = NULL;
  1108. }
  1109. if (m_pCProxyState)
  1110. {
  1111. delete m_pCProxyState;
  1112. m_pCProxyState = NULL;
  1113. }
  1114. if (m_pCRecvFromPipe)
  1115. {
  1116. delete m_pCRecvFromPipe;
  1117. m_pCRecvFromPipe = NULL;
  1118. }
  1119. if (m_pCPacketReceiver)
  1120. {
  1121. delete m_pCPacketReceiver;
  1122. m_pCPacketReceiver = NULL;
  1123. }
  1124. if (m_pCPreProcessor)
  1125. {
  1126. delete m_pCPreProcessor;
  1127. m_pCPreProcessor = NULL;
  1128. }
  1129. if (m_pCPreValidator)
  1130. {
  1131. delete m_pCPreValidator;
  1132. m_pCPreValidator = NULL;
  1133. }
  1134. if (m_pCDictionary)
  1135. {
  1136. delete m_pCDictionary;
  1137. m_pCDictionary = NULL;
  1138. }
  1139. if (m_pCClients)
  1140. {
  1141. delete m_pCClients;
  1142. m_pCClients = NULL;
  1143. }
  1144. if (m_pCHashMD5)
  1145. {
  1146. delete m_pCHashMD5;
  1147. m_pCHashMD5 = NULL;
  1148. }
  1149. if (m_pCHashHmacMD5)
  1150. {
  1151. delete m_pCHashHmacMD5;
  1152. m_pCHashHmacMD5 = NULL;
  1153. }
  1154. if (m_pCReportEvent)
  1155. {
  1156. delete m_pCReportEvent;
  1157. m_pCReportEvent = NULL;
  1158. }
  1159. return;
  1160. } // end of CController::InternalCleanup method
  1161. //++--------------------------------------------------------------
  1162. //
  1163. // Function: OnPropertyChange
  1164. //
  1165. // Synopsis: This is the OnPropertyChange method exposed through the
  1166. // IComponentNotify COM Interface. It is called to notify
  1167. // the component of any change in its properties
  1168. //
  1169. // Arguments:
  1170. //
  1171. // Returns: HRESULT - status
  1172. //
  1173. //
  1174. // History: MKarki Created 12/3/97
  1175. //
  1176. //----------------------------------------------------------------
  1177. STDMETHODIMP
  1178. CController::OnPropertyChange (
  1179. ULONG ulProperties,
  1180. ULONG *pulProperties,
  1181. IPropertyBag2 *pIPropertyBag
  1182. )
  1183. {
  1184. if ((NULL == pulProperties) || (NULL == pIPropertyBag))
  1185. return (E_POINTER);
  1186. return (S_OK);
  1187. } // end of CController::OnPropertyChange method
  1188. //++--------------------------------------------------------------
  1189. //
  1190. // Function: QueryInterfaceReqSrc
  1191. //
  1192. // Synopsis: This is the function called when this Component
  1193. // is called and queried for its IRequestSource
  1194. // interface
  1195. //
  1196. // Arguments: NONE
  1197. //
  1198. // Returns: HRESULT - status
  1199. //
  1200. //
  1201. // History: MKarki Created 11/21/97
  1202. //
  1203. //----------------------------------------------------------------
  1204. HRESULT WINAPI
  1205. CController::QueryInterfaceReqSrc (
  1206. PVOID pThis,
  1207. REFIID riid,
  1208. LPVOID *ppv,
  1209. ULONG_PTR ulpValue
  1210. )
  1211. {
  1212. *ppv = &(static_cast<CController*>(pThis))->m_objCRequestSource;
  1213. //
  1214. // increment count
  1215. //
  1216. ((LPUNKNOWN)*ppv)->AddRef();
  1217. return (S_OK);
  1218. } // end of CController::QueryInterfaceReqSrc method
  1219. //++--------------------------------------------------------------
  1220. //
  1221. // Function: CRequestSource
  1222. //
  1223. // Synopsis: This is the constructor of the CRequestSource
  1224. // nested class
  1225. //
  1226. // Arguments:
  1227. // CController*
  1228. //
  1229. // Returns:
  1230. //
  1231. //
  1232. // History: MKarki Created 11/21/97
  1233. //
  1234. //----------------------------------------------------------------
  1235. CController::CRequestSource::CRequestSource (
  1236. CController *pCController
  1237. )
  1238. :m_pCController (pCController)
  1239. {
  1240. _ASSERT (pCController);
  1241. } // end of CRequestSource constructor
  1242. //++--------------------------------------------------------------
  1243. //
  1244. // Function: ~CRequestSource
  1245. //
  1246. // Synopsis: This is the destructor of the CRequestSource
  1247. // nested class
  1248. //
  1249. // Arguments:
  1250. //
  1251. //
  1252. // Returns: HRESULT - status
  1253. //
  1254. //
  1255. // History: MKarki Created 11/21/97
  1256. //
  1257. //----------------------------------------------------------------
  1258. CController::CRequestSource::~CRequestSource()
  1259. {
  1260. } // end of CRequestSource destructor
  1261. //++--------------------------------------------------------------
  1262. //
  1263. // Function: OnRequestComplete
  1264. //
  1265. // Synopsis: This is the function called when a request is
  1266. // is being pushed back after backend processing
  1267. //
  1268. // Arguments:
  1269. // [in] IRequest*
  1270. // [in] IASREQUESTSTATUS
  1271. //
  1272. // Returns: HRESULT - status
  1273. //
  1274. //
  1275. // History: MKarki Created 1/20/98
  1276. //
  1277. //----------------------------------------------------------------
  1278. STDMETHODIMP CController::CRequestSource::OnRequestComplete (
  1279. IRequest *pIRequest,
  1280. IASREQUESTSTATUS eStatus
  1281. )
  1282. {
  1283. HRESULT hr = S_OK;
  1284. BOOL bStatus = FALSE;
  1285. __try
  1286. {
  1287. if (NULL == pIRequest)
  1288. {
  1289. IASTracePrintf (
  1290. "Invalid argument passed to OnRequestComplete method"
  1291. );
  1292. hr = E_POINTER;
  1293. __leave;
  1294. }
  1295. //
  1296. // start using this interface in processing outbound
  1297. // requests now
  1298. //
  1299. hr = m_pCController->m_pCRecvFromPipe->Process (pIRequest);
  1300. if (FAILED (hr)) { __leave; }
  1301. //
  1302. // success
  1303. //
  1304. }
  1305. __finally
  1306. {
  1307. }
  1308. return (hr);
  1309. } // end of CController::CRequestSource::OnRequestComplete method