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.

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