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.

1854 lines
45 KiB

  1. //////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 2000-2001 Microsoft Corporation
  4. //
  5. // Module Name:
  6. // ConfigurationConnection.cpp
  7. //
  8. // Description:
  9. // CConfigurationConnection implementation.
  10. //
  11. // Maintained By:
  12. // Galen Barbee (GalenB) 02-FEB-2000
  13. //
  14. //////////////////////////////////////////////////////////////////////////////
  15. #include "Pch.h"
  16. #include "TaskPollingCallback.h"
  17. #include "ConfigConnection.h"
  18. #include <ClusCfgPrivate.h>
  19. #include <nameutil.h>
  20. DEFINE_THISCLASS("CConfigurationConnection")
  21. // ************************************************************************
  22. //
  23. // Constructor / Destructor
  24. //
  25. // ************************************************************************
  26. //////////////////////////////////////////////////////////////////////////////
  27. //++
  28. //
  29. // HRESULT
  30. // CConfigurationConnection::S_HrCreateInstance(
  31. // IUnknown ** ppunkOut
  32. // )
  33. //
  34. //--
  35. //////////////////////////////////////////////////////////////////////////////
  36. HRESULT
  37. CConfigurationConnection::S_HrCreateInstance(
  38. IUnknown ** ppunkOut
  39. )
  40. {
  41. TraceFunc( "" );
  42. Assert( ppunkOut != NULL );
  43. HRESULT hr;
  44. CConfigurationConnection * pcc = new CConfigurationConnection;
  45. if ( pcc != NULL )
  46. {
  47. hr = THR( pcc->Init() );
  48. if ( SUCCEEDED( hr ) )
  49. {
  50. hr = THR( pcc->TypeSafeQI( IUnknown, ppunkOut ) );
  51. }
  52. pcc->Release();
  53. }
  54. else
  55. {
  56. hr = THR( E_OUTOFMEMORY );
  57. }
  58. HRETURN( hr );
  59. } //*** CConfigurationConnection::S_HrCreateInstance()
  60. //////////////////////////////////////////////////////////////////////////////
  61. //++
  62. //
  63. // CConfigurationConnection::CConfigurationConnection( void )
  64. //
  65. //--
  66. //////////////////////////////////////////////////////////////////////////////
  67. CConfigurationConnection::CConfigurationConnection( void )
  68. {
  69. TraceFunc( "" );
  70. InterlockedIncrement( &g_cObjects );
  71. TraceFuncExit();
  72. } //*** CConfigurationConnection::CConfigurationConnection()
  73. //////////////////////////////////////////////////////////////////////////////
  74. //++
  75. //
  76. // STDMETHODIMP
  77. // CConfigurationConnection::Init( void )
  78. //
  79. //--
  80. //////////////////////////////////////////////////////////////////////////////
  81. STDMETHODIMP
  82. CConfigurationConnection::Init( void )
  83. {
  84. TraceFunc( "" );
  85. HRESULT hr = S_OK;
  86. // IUnknown stuff
  87. Assert( m_cRef == 0 );
  88. AddRef(); // Add one count
  89. // IConfigurationConnection
  90. Assert( m_cookieGITServer == 0 );
  91. Assert( m_cookieGITVerify == 0 );
  92. Assert( m_cookieGITCallbackTask == 0 );
  93. Assert( m_pcccb == NULL );
  94. Assert( m_bstrLocalComputerName == NULL );
  95. Assert( m_bstrLocalHostname == NULL );
  96. Assert( m_hrLastStatus == S_OK );
  97. Assert( m_bstrBindingString == NULL );
  98. //
  99. // Figure out the local computer name.
  100. //
  101. hr = THR( HrGetComputerName( ComputerNameDnsFullyQualified, &m_bstrLocalComputerName ) );
  102. if ( FAILED( hr ) )
  103. {
  104. goto Cleanup;
  105. }
  106. hr = THR( HrGetComputerName( ComputerNameDnsHostname, &m_bstrLocalHostname ) );
  107. if ( FAILED( hr ) )
  108. {
  109. goto Cleanup;
  110. }
  111. Cleanup:
  112. HRETURN( hr );
  113. } //*** CConfigurationConnection::Init()
  114. //////////////////////////////////////////////////////////////////////////////
  115. //++
  116. //
  117. // CConfigurationConnection::~CConfigurationConnection( void )
  118. //
  119. //--
  120. //////////////////////////////////////////////////////////////////////////////
  121. CConfigurationConnection::~CConfigurationConnection( void )
  122. {
  123. TraceFunc( "" );
  124. TraceSysFreeString( m_bstrLocalComputerName );
  125. if ( m_pcccb != NULL )
  126. {
  127. m_pcccb->Release();
  128. }
  129. if ( m_pgit != NULL )
  130. {
  131. if ( m_cookieGITServer != 0 )
  132. {
  133. THR( m_pgit->RevokeInterfaceFromGlobal( m_cookieGITServer ) );
  134. }
  135. if ( m_cookieGITVerify != 0 )
  136. {
  137. THR( m_pgit->RevokeInterfaceFromGlobal( m_cookieGITVerify ) );
  138. }
  139. if ( m_cookieGITCallbackTask != 0 )
  140. {
  141. THR( HrStopPolling() );
  142. } // if:
  143. m_pgit->Release();
  144. }
  145. TraceSysFreeString( m_bstrBindingString );
  146. InterlockedDecrement( &g_cObjects );
  147. TraceFuncExit();
  148. } //*** CConfigurationConnection::~CConfigurationConnection()
  149. // ************************************************************************
  150. //
  151. // IUnknown
  152. //
  153. // ************************************************************************
  154. //////////////////////////////////////////////////////////////////////////////
  155. //++
  156. //
  157. // STDMETHODIMP
  158. // CConfigurationConnection::QueryInterface(
  159. // REFIID riidIn,
  160. // LPVOID * ppvOut
  161. // )
  162. //
  163. //////////////////////////////////////////////////////////////////////////////
  164. STDMETHODIMP
  165. CConfigurationConnection::QueryInterface(
  166. REFIID riidIn,
  167. LPVOID * ppvOut
  168. )
  169. {
  170. TraceQIFunc( riidIn, ppvOut );
  171. HRESULT hr = E_NOINTERFACE;
  172. if ( IsEqualIID( riidIn, IID_IUnknown ) )
  173. {
  174. *ppvOut = static_cast< IConfigurationConnection * >( this );
  175. hr = S_OK;
  176. } // if: IUnknown
  177. else if ( IsEqualIID( riidIn, IID_IConfigurationConnection ) )
  178. {
  179. *ppvOut = TraceInterface( __THISCLASS__, IConfigurationConnection, this, 0 );
  180. hr = S_OK;
  181. } // else if: IConfigurationConnection
  182. else if ( IsEqualIID( riidIn, IID_IClusCfgServer ) )
  183. {
  184. *ppvOut = TraceInterface( __THISCLASS__, IClusCfgServer, this, 0 );
  185. hr = S_OK;
  186. } // else if: IClusCfgServer
  187. else if ( IsEqualIID( riidIn, IID_IClusCfgCallback ) )
  188. {
  189. *ppvOut = TraceInterface( __THISCLASS__, IClusCfgCallback, this, 0 );
  190. hr = S_OK;
  191. } // else if: IClusCfgCallback
  192. else if ( IsEqualIID( riidIn, IID_IClusCfgCapabilities ) )
  193. {
  194. *ppvOut = TraceInterface( __THISCLASS__, IClusCfgCapabilities, this, 0 );
  195. hr = S_OK;
  196. } // else if: IClusCfgCapabilities
  197. else if ( IsEqualIID( riidIn, IID_IClusCfgVerify ) )
  198. {
  199. *ppvOut = TraceInterface( __THISCLASS__, IClusCfgVerify, this, 0 );
  200. hr = S_OK;
  201. } // else if: IClusCfgVerify
  202. if ( SUCCEEDED( hr ) )
  203. {
  204. ((IUnknown*) *ppvOut)->AddRef();
  205. } // if: success
  206. QIRETURN_IGNORESTDMARSHALLING( hr, riidIn );
  207. } //*** CConfigurationConnection::QueryInterface()
  208. //////////////////////////////////////////////////////////////////////////////
  209. //++
  210. //
  211. // STDMETHODIMP_( ULONG )
  212. // CConfigurationConnection::AddRef( void )
  213. //
  214. //--
  215. //////////////////////////////////////////////////////////////////////////////
  216. STDMETHODIMP_( ULONG )
  217. CConfigurationConnection::AddRef( void )
  218. {
  219. TraceFunc( "[IUnknown]" );
  220. InterlockedIncrement( &m_cRef );
  221. RETURN( m_cRef );
  222. } //*** CConfigurationConnection::AddRef()
  223. //////////////////////////////////////////////////////////////////////////////
  224. //++
  225. //
  226. // STDMETHODIMP_( ULONG )
  227. // CConfigurationConnection::Release( void )
  228. //
  229. //--
  230. //////////////////////////////////////////////////////////////////////////////
  231. STDMETHODIMP_( ULONG )
  232. CConfigurationConnection::Release( void )
  233. {
  234. TraceFunc( "[IUnknown]" );
  235. LONG cRef;
  236. cRef = InterlockedDecrement( &m_cRef );
  237. if ( cRef == 0 )
  238. {
  239. TraceDo( delete this );
  240. }
  241. RETURN( cRef );
  242. } //*** CConfigurationConnection::Release()
  243. //****************************************************************************
  244. //
  245. // IConfigurationConnection
  246. //
  247. //****************************************************************************
  248. //////////////////////////////////////////////////////////////////////////////
  249. //++
  250. //
  251. // STDMETHODIMP
  252. // CConfigurationConnection::ConnectTo(
  253. // OBJECTCOOKIE cookieIn
  254. // )
  255. //
  256. //--
  257. //////////////////////////////////////////////////////////////////////////////
  258. STDMETHODIMP
  259. CConfigurationConnection::ConnectTo(
  260. OBJECTCOOKIE cookieIn
  261. )
  262. {
  263. TraceFunc( "[IConfigurationConnection]" );
  264. //
  265. // VARIABLES
  266. //
  267. HRESULT hr;
  268. LCID lcid;
  269. bool fConnectingToNode;
  270. COSERVERINFO serverinfo;
  271. MULTI_QI mqi;
  272. CLSID clsidType;
  273. CLSID clsidMinorId;
  274. const CLSID * pclsidMajor;
  275. const CLSID * pclsidMinor;
  276. IServiceProvider * psp;
  277. IClusCfgCallback * pcccb; // don't free!
  278. ITaskManager * ptm = NULL;
  279. BSTR bstrName = NULL;
  280. BSTR bstrDescription = NULL;
  281. IUnknown * punk = NULL;
  282. IObjectManager * pom = NULL;
  283. IStandardInfo * psi = NULL;
  284. IClusCfgInitialize * pcci = NULL;
  285. IClusCfgServer * pccs = NULL;
  286. IClusCfgPollingCallbackInfo * pccpcbi = NULL;
  287. IClusCfgVerify * pccv = NULL;
  288. //
  289. // Retrieve the managers needs for the task ahead.
  290. //
  291. hr = THR( CoCreateInstance( CLSID_StdGlobalInterfaceTable,
  292. NULL,
  293. CLSCTX_INPROC_SERVER,
  294. IID_IGlobalInterfaceTable,
  295. reinterpret_cast< void ** >( &m_pgit )
  296. ) );
  297. if ( FAILED( hr ) )
  298. {
  299. goto Cleanup;
  300. }
  301. hr = THR( CoCreateInstance( CLSID_ServiceManager,
  302. NULL,
  303. CLSCTX_SERVER,
  304. TypeSafeParams( IServiceProvider, &psp )
  305. ) );
  306. if ( FAILED( hr ) )
  307. {
  308. goto Cleanup;
  309. }
  310. hr = THR( psp->TypeSafeQS( CLSID_TaskManager, ITaskManager, &ptm ) );
  311. if ( FAILED( hr ) )
  312. {
  313. psp->Release(); // release promptly
  314. goto Cleanup;
  315. }
  316. hr = THR( psp->TypeSafeQS( CLSID_ObjectManager, IObjectManager, &pom ) );
  317. psp->Release(); // release promptly
  318. if ( FAILED( hr ) )
  319. {
  320. goto Cleanup;
  321. }
  322. //
  323. // Figure out our locale.
  324. //
  325. lcid = GetUserDefaultLCID();
  326. Assert( lcid != 0 ); // What do we do if it is zero?
  327. //
  328. // Get the name of the node to contact.
  329. //
  330. hr = THR( pom->GetObject( DFGUID_StandardInfo, cookieIn, &punk ) );
  331. if ( FAILED( hr ) )
  332. {
  333. goto Cleanup;
  334. }
  335. hr = THR( punk->TypeSafeQI( IStandardInfo, &psi ) );
  336. if ( FAILED( hr ) )
  337. {
  338. goto Cleanup;
  339. }
  340. psi = TraceInterface( L"ConfigConnection!IStandardInfo", IStandardInfo, psi, 1 );
  341. hr = THR( psi->GetName( &bstrName ) );
  342. if ( FAILED( hr ) )
  343. {
  344. goto Cleanup;
  345. }
  346. LogMsg( L"[MT] The name to connect to is '%ws'.", bstrName );
  347. TraceMemoryAddBSTR( bstrName );
  348. hr = THR( psi->GetType( &clsidType ) );
  349. if ( FAILED( hr ) )
  350. {
  351. goto Cleanup;
  352. }
  353. //
  354. // Figure out where to logging information in the UI.
  355. //
  356. if ( IsEqualIID( clsidType, CLSID_NodeType ) )
  357. {
  358. fConnectingToNode = true;
  359. pclsidMajor = &TASKID_Major_Establish_Connection;
  360. }
  361. else if ( IsEqualIID( clsidType, CLSID_ClusterConfigurationType ) )
  362. {
  363. fConnectingToNode = false;
  364. pclsidMajor = &TASKID_Major_Checking_For_Existing_Cluster;
  365. }
  366. else
  367. {
  368. hr = THR( E_INVALIDARG );
  369. goto Cleanup;
  370. }
  371. //
  372. // If the connection is to the local machine, then invoke the server INPROC
  373. //
  374. hr = STHR( HrIsLocalComputer( bstrName ) );
  375. if ( hr == S_OK )
  376. {
  377. LogMsg( L"[MT] Requesting a local connection to '%ws'.", bstrName );
  378. //
  379. // Requesting connection to local computer.
  380. //
  381. hr = THR( CoCreateInstance( CLSID_ClusCfgServer,
  382. NULL,
  383. CLSCTX_INPROC_SERVER,
  384. IID_IClusCfgServer,
  385. reinterpret_cast< void ** >( &pccs )
  386. ) );
  387. if ( FAILED( hr ) )
  388. {
  389. goto Cleanup;
  390. }
  391. //
  392. // Store the connection. Don't ref again... but we'll track it with a
  393. // ref count of one.
  394. //
  395. pccs = TraceInterface( L"ClusCfgServer!Proxy", IClusCfgServer, pccs, 1 );
  396. //
  397. // Save it away to be used next time. Do this using the GlobalInterfaceTable.
  398. //
  399. hr = THR( m_pgit->RegisterInterfaceInGlobal( pccs,
  400. IID_IClusCfgServer,
  401. &m_cookieGITServer
  402. ) );
  403. if ( FAILED( hr ) )
  404. {
  405. goto Cleanup;
  406. }
  407. hr = THR( pccs->TypeSafeQI( IClusCfgVerify, &pccv ) );
  408. if ( FAILED( hr ) )
  409. {
  410. goto Cleanup;
  411. }
  412. pccv = TraceInterface( L"ClusCfgServer!Proxy", IClusCfgVerify, pccv, 1 );
  413. //
  414. // Save it away to be used next time. Do this using the GlobalInterfaceTable.
  415. //
  416. hr = THR( m_pgit->RegisterInterfaceInGlobal( pccv,
  417. IID_IClusCfgVerify,
  418. &m_cookieGITVerify
  419. ) );
  420. if ( FAILED( hr ) )
  421. {
  422. goto Cleanup;
  423. }
  424. // Track our IClusCfgCallback interface separately - this is a NOP in retail.
  425. pcccb = TraceInterface( L"CConfigurationConnection!Server", IClusCfgCallback, this, 0 );
  426. TraceSysFreeString( m_bstrBindingString );
  427. m_bstrBindingString = NULL;
  428. }
  429. else
  430. {
  431. LogMsg( L"[MT] Requesting a remote connection to '%ws'.", bstrName );
  432. //
  433. // Create a binding context for the remote server.
  434. //
  435. TraceSysFreeString( m_bstrBindingString );
  436. m_bstrBindingString = NULL;
  437. hr = STHR( HrCreateBinding( this, pclsidMajor, bstrName, &m_bstrBindingString ) );
  438. if ( FAILED( hr ) )
  439. {
  440. hr = HR_S_RPC_S_SERVER_UNAVAILABLE;
  441. goto Cleanup;
  442. }
  443. //
  444. // Report this connection request.
  445. //
  446. if ( fConnectingToNode )
  447. {
  448. //
  449. // Add in the major task in case it hasn't been added yet.
  450. //
  451. hr = THR( HrLoadStringIntoBSTR( g_hInstance, IDS_TASKID_MINOR_REMOTE_CONNECTION_REQUESTS, &bstrDescription ) );
  452. if ( FAILED( hr ) )
  453. {
  454. goto Cleanup;
  455. }
  456. hr = THR( SendStatusReport(
  457. m_bstrLocalHostname
  458. , TASKID_Major_Establish_Connection
  459. , TASKID_Minor_Remote_Node_Connection_Requests
  460. , 0
  461. , 1
  462. , 1
  463. , S_OK
  464. , bstrDescription
  465. , NULL
  466. , NULL
  467. ) );
  468. //
  469. // Add the specific minor task instance.
  470. // Generate a new GUID for this report so that it won't wipe out
  471. // any other reports like this.
  472. //
  473. hr = THR( CoCreateGuid( &clsidMinorId ) );
  474. if ( FAILED( hr ) )
  475. {
  476. goto Cleanup;
  477. }
  478. pclsidMajor = &TASKID_Minor_Remote_Node_Connection_Requests;
  479. pclsidMinor = &clsidMinorId;
  480. } // if: connecting to a node
  481. else
  482. {
  483. pclsidMajor = &TASKID_Major_Checking_For_Existing_Cluster;
  484. pclsidMinor = &TASKID_Minor_Requesting_Remote_Connection;
  485. } // else: connecting to a cluster
  486. hr = THR( HrFormatStringIntoBSTR( g_hInstance, IDS_TASKID_MINOR_REQUESTING_REMOTE_CONNECTION, &bstrDescription, bstrName, m_bstrBindingString ) );
  487. if ( FAILED( hr ) )
  488. {
  489. goto Cleanup;
  490. }
  491. hr = THR( SendStatusReport(
  492. m_bstrLocalHostname
  493. , *pclsidMajor
  494. , *pclsidMinor
  495. , 0
  496. , 1
  497. , 1
  498. , S_OK
  499. , bstrDescription
  500. , NULL
  501. , NULL
  502. ) );
  503. //
  504. // KB: 08-DEC-2000 DavidP
  505. // Workaround for IP address caching bug in COM.
  506. //
  507. {
  508. DWORD sc;
  509. DWORD dwClusterState;
  510. sc = GetNodeClusterState( m_bstrBindingString, &dwClusterState );
  511. if ( ( sc == RPC_S_SERVER_UNAVAILABLE )
  512. || ( sc == ERROR_BAD_NETPATH )
  513. || ( sc == RPC_S_INVALID_NET_ADDR ) )
  514. {
  515. //
  516. // Make the error into a success and update the status.
  517. // Translate both codes to the same success code so that
  518. // we don't have to propogate handling of several errors
  519. // to all parts of the code.
  520. //
  521. hr = HR_S_RPC_S_SERVER_UNAVAILABLE;
  522. goto Cleanup;
  523. }
  524. else if ( sc != ERROR_SUCCESS )
  525. {
  526. hr = HRESULT_FROM_WIN32( TW32( sc ) );
  527. goto Cleanup;
  528. }
  529. //
  530. // BUGBUG: GalenB 20-FEB-2001
  531. //
  532. // If we know the node is down why should we try to connect to it?
  533. //
  534. }
  535. //
  536. // Create the connection to the node.
  537. //
  538. ZeroMemory( &serverinfo, sizeof( serverinfo ) );
  539. ZeroMemory( &mqi, sizeof( mqi ) );
  540. serverinfo.pwszName = m_bstrBindingString;
  541. mqi.pIID = &IID_IClusCfgVerify;
  542. // don't wrap - this can fail.
  543. hr = CoCreateInstanceEx( CLSID_ClusCfgServer,
  544. NULL,
  545. CLSCTX_REMOTE_SERVER,
  546. &serverinfo,
  547. 1,
  548. &mqi
  549. );
  550. if ( hr == HRESULT_FROM_WIN32( RPC_S_SERVER_UNAVAILABLE ) )
  551. {
  552. LogMsg( L"[MT] Connection to '%ws' with binding string '%ws' failed because the RPC is not available.", bstrName, m_bstrBindingString );
  553. //
  554. // Make the error into a success and update the status.
  555. //
  556. hr = HR_S_RPC_S_SERVER_UNAVAILABLE;
  557. goto Cleanup;
  558. }
  559. else if( hr == HRESULT_FROM_WIN32( REGDB_E_CLASSNOTREG ) )
  560. {
  561. LogMsg( L"[MT] Connection to '%ws' with binding string '%ws' failed because one or more classes are not registered.", bstrName, m_bstrBindingString );
  562. // Known error. It must be a downlevel node.
  563. goto Cleanup;
  564. }
  565. else if ( FAILED( hr ) )
  566. {
  567. LogMsg( L"[MT] Connection to '%ws' with binding string '%ws' failed. (hr=%#08x)", bstrName, m_bstrBindingString, hr );
  568. THR( hr );
  569. goto Cleanup;
  570. }
  571. if ( FAILED( mqi.hr ) )
  572. {
  573. hr = THR( mqi.hr );
  574. goto Cleanup;
  575. } // if: qi failed
  576. //
  577. // Store the connection. Don't ref again... but we'll track it with a
  578. // ref count of one.
  579. //
  580. pccv = TraceInterface( L"ClusCfgServer!Proxy", IClusCfgVerify, reinterpret_cast< IClusCfgVerify * >( mqi.pItf ), 1 );
  581. //
  582. // Save it away to be used next time. Do this using the GlobalInterfaceTable.
  583. //
  584. hr = THR( m_pgit->RegisterInterfaceInGlobal( pccv,
  585. IID_IClusCfgVerify,
  586. &m_cookieGITVerify
  587. ) );
  588. if ( FAILED( hr ) )
  589. {
  590. goto Cleanup;
  591. }
  592. //
  593. // Verify our connection.
  594. //
  595. if ( fConnectingToNode )
  596. {
  597. hr = THR( pccv->VerifyConnectionToNode( bstrName ) );
  598. if ( FAILED( hr ) )
  599. {
  600. goto Cleanup;
  601. }
  602. }
  603. else
  604. {
  605. hr = THR( pccv->VerifyConnectionToCluster( bstrName ) );
  606. if ( FAILED( hr ) )
  607. {
  608. goto Cleanup;
  609. }
  610. }
  611. if ( hr == S_FALSE )
  612. {
  613. hr = THR( HRESULT_FROM_WIN32( ERROR_CONNECTION_REFUSED ) );
  614. goto Cleanup;
  615. }
  616. hr = THR( pccv->TypeSafeQI( IClusCfgServer, &pccs ) );
  617. if ( FAILED( hr ) )
  618. {
  619. goto Cleanup;
  620. }
  621. //
  622. // Store the connection. Don't ref again... but we'll track it with a
  623. // ref count of one.
  624. //
  625. pccs = TraceInterface( L"ClusCfgServer!Proxy", IClusCfgServer, pccs, 1 );
  626. // commented out by GalenB since this is investigative code.
  627. // hr = THR( HrSetSecurityBlanket( pccs ) );
  628. // if ( FAILED( hr ) )
  629. // goto Cleanup;
  630. hr = THR( pccs->SetBindingString( m_bstrBindingString ) );
  631. if ( FAILED( hr ) )
  632. {
  633. goto Cleanup;
  634. }
  635. //
  636. // Save it away to be used next time. Do this using the GlobalInterfaceTable.
  637. //
  638. hr = THR( m_pgit->RegisterInterfaceInGlobal( pccs,
  639. IID_IClusCfgServer,
  640. &m_cookieGITServer
  641. ) );
  642. if ( FAILED( hr ) )
  643. {
  644. goto Cleanup;
  645. }
  646. pcccb = NULL; // we're polling.
  647. hr = THR( pccs->TypeSafeQI( IClusCfgPollingCallbackInfo, &pccpcbi ) );
  648. if ( FAILED( hr ) )
  649. {
  650. goto Cleanup;
  651. }
  652. hr = THR( pccpcbi->SetPollingMode( true ) );
  653. if ( FAILED( hr ) )
  654. {
  655. goto Cleanup;
  656. }
  657. hr = THR( HrStartPolling() );
  658. if ( FAILED( hr ) )
  659. {
  660. goto Cleanup;
  661. }
  662. } // else: run server remotely
  663. //
  664. // Initialize the server.
  665. //
  666. hr = THR( pccs->TypeSafeQI( IClusCfgInitialize, &pcci ) );
  667. if ( FAILED( hr ) )
  668. {
  669. goto Cleanup;
  670. }
  671. hr = pcci->Initialize( pcccb, lcid );
  672. if ( FAILED( hr ) )
  673. {
  674. THR( hr );
  675. goto Cleanup;
  676. }
  677. else if ( hr == HR_S_RPC_S_CLUSTER_NODE_DOWN )
  678. {
  679. LogMsg( L"[MT] The cluster service on node '%ws' is down.", bstrName );
  680. } // else if:
  681. else
  682. {
  683. THR( hr );
  684. } // else:
  685. Cleanup:
  686. if ( punk != NULL )
  687. {
  688. punk->Release();
  689. }
  690. if ( pccpcbi != NULL )
  691. {
  692. pccpcbi->Release();
  693. } // if: pccpcbi
  694. if ( pom != NULL )
  695. {
  696. pom->Release();
  697. } // if: pom
  698. if ( ptm != NULL )
  699. {
  700. ptm->Release();
  701. } //if: ptm
  702. if ( psi != NULL )
  703. {
  704. psi->Release();
  705. } // if: psi
  706. if ( pcci != NULL )
  707. {
  708. pcci->Release();
  709. } // if: pcci
  710. TraceSysFreeString( bstrName );
  711. TraceSysFreeString( bstrDescription );
  712. if ( pccs != NULL )
  713. {
  714. pccs->Release();
  715. }
  716. if ( pccv != NULL )
  717. {
  718. pccv->Release();
  719. }
  720. m_hrLastStatus = hr;
  721. HRETURN( hr );
  722. } //*** CConfigurationConnection::ConnectTo()
  723. //////////////////////////////////////////////////////////////////////////////
  724. //++
  725. //
  726. // STDMETHODIMP
  727. // CConfigurationConnection::ConnectToObject(
  728. // OBJECTCOOKIE cookieIn,
  729. // REFIID riidIn,
  730. // LPUNKNOWN * ppunkOut
  731. // )
  732. //
  733. //--
  734. //////////////////////////////////////////////////////////////////////////////
  735. STDMETHODIMP
  736. CConfigurationConnection::ConnectToObject(
  737. OBJECTCOOKIE cookieIn,
  738. REFIID riidIn,
  739. LPUNKNOWN * ppunkOut
  740. )
  741. {
  742. TraceFunc( "[IConfigurationConnection]" );
  743. HRESULT hr;
  744. CLSID clsid;
  745. IServiceProvider * psp;
  746. IUnknown * punk = NULL;
  747. IObjectManager * pom = NULL;
  748. IStandardInfo * psi = NULL;
  749. //
  750. // Retrieve the managers needs for the task ahead.
  751. //
  752. hr = THR( CoCreateInstance( CLSID_ServiceManager,
  753. NULL,
  754. CLSCTX_INPROC_SERVER,
  755. TypeSafeParams( IServiceProvider, &psp )
  756. ) );
  757. if ( FAILED( hr ) )
  758. {
  759. goto Cleanup;
  760. }
  761. hr = THR( psp->QueryService( CLSID_ObjectManager,
  762. TypeSafeParams( IObjectManager, &pom )
  763. ) );
  764. psp->Release(); // release promptly
  765. if ( FAILED( hr ) )
  766. {
  767. goto Cleanup;
  768. }
  769. //
  770. // Retrieve the type of the object.
  771. //
  772. hr = THR( pom->GetObject( DFGUID_StandardInfo,
  773. cookieIn,
  774. &punk
  775. ) );
  776. if ( FAILED( hr ) )
  777. {
  778. goto Cleanup;
  779. }
  780. hr = THR( punk->TypeSafeQI( IStandardInfo, &psi ) );
  781. if ( FAILED( hr ) )
  782. {
  783. goto Cleanup;
  784. }
  785. psi = TraceInterface( L"ConfigConnection!IStandardInfo", IStandardInfo, psi, 1 );
  786. hr = THR( psi->GetType( &clsid ) );
  787. if ( FAILED( hr ) )
  788. {
  789. goto Cleanup;
  790. }
  791. if ( !IsEqualIID( clsid, CLSID_NodeType ) )
  792. {
  793. hr = THR( E_INVALIDARG );
  794. goto Cleanup;
  795. }
  796. //
  797. // Return the requested interface.
  798. //
  799. hr = THR( QueryInterface( riidIn, reinterpret_cast< void ** > ( ppunkOut ) ) );
  800. if ( FAILED( hr ) )
  801. {
  802. goto Cleanup;
  803. }
  804. Cleanup:
  805. if ( punk != NULL )
  806. {
  807. punk->Release();
  808. }
  809. if ( pom != NULL )
  810. {
  811. pom->Release();
  812. } // if: pom
  813. if ( psi != NULL )
  814. {
  815. psi->Release();
  816. } // if: psi
  817. HRETURN( hr );
  818. } //*** CConfigurationConnection::ConnectToObject()
  819. //****************************************************************************
  820. //
  821. // IClusCfgServer
  822. //
  823. //****************************************************************************
  824. //////////////////////////////////////////////////////////////////////////////
  825. //++
  826. //
  827. // STDMETHODIMP
  828. // CConfigurationConnection::GetClusterNodeInfo(
  829. // IClusCfgNodeInfo ** ppClusterNodeInfoOut
  830. // )
  831. //
  832. //--
  833. //////////////////////////////////////////////////////////////////////////////
  834. STDMETHODIMP
  835. CConfigurationConnection::GetClusterNodeInfo(
  836. IClusCfgNodeInfo ** ppClusterNodeInfoOut
  837. )
  838. {
  839. TraceFunc( "[IClusCfgServer]" );
  840. HRESULT hr;
  841. IClusCfgServer * pccs = NULL;
  842. if ( m_pgit == NULL )
  843. {
  844. hr = THR( m_hrLastStatus );
  845. goto Cleanup;
  846. }
  847. hr = THR( m_pgit->GetInterfaceFromGlobal( m_cookieGITServer, TypeSafeParams( IClusCfgServer, &pccs ) ) );
  848. if ( FAILED( hr ) )
  849. {
  850. goto Cleanup;
  851. }
  852. hr = THR( pccs->GetClusterNodeInfo( ppClusterNodeInfoOut ) );
  853. Cleanup:
  854. if ( pccs != NULL )
  855. {
  856. pccs->Release();
  857. }
  858. HRETURN( hr );
  859. } //*** CConfigurationConnection::GetClusterNodeInfo()
  860. //////////////////////////////////////////////////////////////////////////////
  861. //++
  862. //
  863. // STDMETHODIMP
  864. // CConfigurationConnection::GetManagedResourcesEnum(
  865. // IEnumClusCfgManagedResources ** ppEnumManagedResourcesOut
  866. // )
  867. //
  868. //--
  869. //////////////////////////////////////////////////////////////////////////////
  870. STDMETHODIMP
  871. CConfigurationConnection::GetManagedResourcesEnum(
  872. IEnumClusCfgManagedResources ** ppEnumManagedResourcesOut
  873. )
  874. {
  875. TraceFunc( "[IClusCfgServer]" );
  876. HRESULT hr;
  877. IClusCfgServer * pccs = NULL;
  878. if ( m_pgit == NULL )
  879. {
  880. hr = THR( m_hrLastStatus );
  881. goto Cleanup;
  882. }
  883. hr = THR( m_pgit->GetInterfaceFromGlobal( m_cookieGITServer, TypeSafeParams( IClusCfgServer, &pccs ) ) );
  884. if ( FAILED( hr ) )
  885. {
  886. goto Cleanup;
  887. }
  888. hr = THR( pccs->GetManagedResourcesEnum( ppEnumManagedResourcesOut ) );
  889. Cleanup:
  890. if ( pccs != NULL )
  891. {
  892. pccs->Release();
  893. }
  894. HRETURN( hr );
  895. } //*** CConfigurationConnection::GetManagedResourcesEnum()
  896. //////////////////////////////////////////////////////////////////////////////
  897. //++
  898. //
  899. // STDMETHODIMP
  900. // CConfigurationConnection::GetNetworksEnum(
  901. // IEnumClusCfgNetworks ** ppEnumNetworksOut
  902. // )
  903. //
  904. //--
  905. //////////////////////////////////////////////////////////////////////////////
  906. STDMETHODIMP
  907. CConfigurationConnection::GetNetworksEnum(
  908. IEnumClusCfgNetworks ** ppEnumNetworksOut
  909. )
  910. {
  911. TraceFunc( "[IClusCfgServer]" );
  912. HRESULT hr;
  913. IClusCfgServer * pccs = NULL;
  914. if ( m_pgit == NULL )
  915. {
  916. hr = THR( m_hrLastStatus );
  917. goto Cleanup;
  918. }
  919. hr = THR( m_pgit->GetInterfaceFromGlobal( m_cookieGITServer, TypeSafeParams( IClusCfgServer, &pccs ) ) );
  920. if ( FAILED( hr ) )
  921. {
  922. goto Cleanup;
  923. }
  924. hr = THR( pccs->GetNetworksEnum( ppEnumNetworksOut ) );
  925. Cleanup:
  926. if ( pccs != NULL )
  927. {
  928. pccs->Release();
  929. }
  930. HRETURN( hr );
  931. } //*** CConfigurationConnection::GetNetworksEnum()
  932. //////////////////////////////////////////////////////////////////////////////
  933. //++
  934. //
  935. // STDMETHODIMP
  936. // CConfigurationConnection::CommitChanges( void )
  937. //
  938. //--
  939. //////////////////////////////////////////////////////////////////////////////
  940. STDMETHODIMP
  941. CConfigurationConnection::CommitChanges( void )
  942. {
  943. TraceFunc( "[IClusCfgServer]" );
  944. HRESULT hr;
  945. IClusCfgServer * pccs = NULL;
  946. if ( m_pgit == NULL )
  947. {
  948. hr = THR( m_hrLastStatus );
  949. goto Cleanup;
  950. }
  951. hr = THR( m_pgit->GetInterfaceFromGlobal( m_cookieGITServer, TypeSafeParams( IClusCfgServer, &pccs ) ) );
  952. if ( FAILED( hr ) )
  953. {
  954. goto Cleanup;
  955. }
  956. hr = THR( pccs->CommitChanges( ) );
  957. Cleanup:
  958. if ( pccs != NULL )
  959. {
  960. pccs->Release();
  961. }
  962. HRETURN( hr );
  963. } //*** CConfigurationConnection::CommitChanges()
  964. //////////////////////////////////////////////////////////////////////////////
  965. //
  966. // STDMETHODIMP
  967. // CConfigurationConnection::GetBindingString(
  968. // BSTR * pbstrBindingOut
  969. // )
  970. //
  971. //////////////////////////////////////////////////////////////////////////////
  972. STDMETHODIMP
  973. CConfigurationConnection::GetBindingString(
  974. BSTR * pbstrBindingStringOut
  975. )
  976. {
  977. TraceFunc1( "[IClusCfgServer] pbstrBindingStringOut = %p", pbstrBindingStringOut );
  978. HRESULT hr = S_FALSE;
  979. if ( pbstrBindingStringOut == NULL )
  980. {
  981. hr = THR( E_POINTER );
  982. goto Cleanup;
  983. }
  984. // If local server, then there isn't a binding context.
  985. if ( m_bstrBindingString == NULL )
  986. {
  987. Assert( hr == S_FALSE );
  988. goto Cleanup;
  989. }
  990. *pbstrBindingStringOut = SysAllocString( m_bstrBindingString );
  991. if ( *pbstrBindingStringOut == NULL )
  992. {
  993. hr = THR( E_OUTOFMEMORY );
  994. goto Cleanup;
  995. }
  996. hr = S_OK;
  997. Cleanup:
  998. HRETURN( hr );
  999. } // CConfigurationConnection::GetBinding()
  1000. //////////////////////////////////////////////////////////////////////////////
  1001. //++
  1002. //
  1003. // STDMETHODIMP
  1004. // CConfigurationConnection::SetBindingString(
  1005. // LPCWSTR pcszBindingStringIn
  1006. // )
  1007. //
  1008. //--
  1009. //////////////////////////////////////////////////////////////////////////////
  1010. STDMETHODIMP
  1011. CConfigurationConnection::SetBindingString(
  1012. LPCWSTR pcszBindingStringIn
  1013. )
  1014. {
  1015. TraceFunc( "[IClusCfgServer]" );
  1016. HRESULT hr = S_OK;
  1017. BSTR bstr = NULL;
  1018. if ( pcszBindingStringIn == NULL )
  1019. {
  1020. hr = THR( E_INVALIDARG );
  1021. goto Cleanup;
  1022. } // if:
  1023. bstr = TraceSysAllocString( pcszBindingStringIn );
  1024. if ( bstr == NULL )
  1025. {
  1026. hr = THR( E_OUTOFMEMORY );
  1027. goto Cleanup;
  1028. } // if:
  1029. TraceSysFreeString( m_bstrBindingString );
  1030. m_bstrBindingString = bstr;
  1031. Cleanup:
  1032. HRETURN( hr );
  1033. } //*** CConfigurationConnection::SetBindingString()
  1034. //****************************************************************************
  1035. //
  1036. // IClusCfgVerify
  1037. //
  1038. //****************************************************************************
  1039. //////////////////////////////////////////////////////////////////////////////
  1040. //++
  1041. //
  1042. // STDMETHODIMP
  1043. // CConfigurationConnection::VerifyCredentials(
  1044. // LPCWSTR pcszUserIn,
  1045. // LPCWSTR pcszDomainIn,
  1046. // LPCWSTR pcszPasswordIn
  1047. // )
  1048. //
  1049. //--
  1050. //////////////////////////////////////////////////////////////////////////////
  1051. STDMETHODIMP
  1052. CConfigurationConnection::VerifyCredentials(
  1053. LPCWSTR pcszUserIn,
  1054. LPCWSTR pcszDomainIn,
  1055. LPCWSTR pcszPasswordIn
  1056. )
  1057. {
  1058. TraceFunc( "[IClusCfgVerify]" );
  1059. HRESULT hr;
  1060. IClusCfgVerify * pccv = NULL;
  1061. if ( m_pgit == NULL )
  1062. {
  1063. hr = THR( m_hrLastStatus );
  1064. goto Cleanup;
  1065. }
  1066. hr = THR( m_pgit->GetInterfaceFromGlobal( m_cookieGITVerify, TypeSafeParams( IClusCfgVerify, &pccv ) ) );
  1067. if ( FAILED( hr ) )
  1068. {
  1069. goto Cleanup;
  1070. }
  1071. hr = THR( pccv->VerifyCredentials( pcszUserIn, pcszDomainIn, pcszPasswordIn ) );
  1072. Cleanup:
  1073. if ( pccv != NULL )
  1074. {
  1075. pccv->Release();
  1076. }
  1077. HRETURN( hr );
  1078. } //*** CConfigurationConnection::VerifyCredentials()
  1079. //////////////////////////////////////////////////////////////////////////////
  1080. //++
  1081. //
  1082. // STDMETHODIMP
  1083. // CConfigurationConnection::VerifyConnectionToCluster(
  1084. // LPCWSTR pcszClusterNameIn
  1085. // )
  1086. //
  1087. //--
  1088. //////////////////////////////////////////////////////////////////////////////
  1089. STDMETHODIMP
  1090. CConfigurationConnection::VerifyConnectionToCluster(
  1091. LPCWSTR pcszClusterNameIn
  1092. )
  1093. {
  1094. TraceFunc1( "[IClusCfgVerify] pcszClusterNameIn = '%ws'", pcszClusterNameIn );
  1095. HRESULT hr;
  1096. IClusCfgVerify * pccv = NULL;
  1097. if ( m_pgit == NULL )
  1098. {
  1099. hr = THR( m_hrLastStatus );
  1100. goto Cleanup;
  1101. }
  1102. hr = THR( m_pgit->GetInterfaceFromGlobal( m_cookieGITVerify, TypeSafeParams( IClusCfgVerify, &pccv ) ) );
  1103. if ( FAILED( hr ) )
  1104. {
  1105. goto Cleanup;
  1106. }
  1107. hr = THR( pccv->VerifyConnectionToCluster( pcszClusterNameIn ) );
  1108. Cleanup:
  1109. if ( pccv != NULL )
  1110. {
  1111. pccv->Release();
  1112. }
  1113. HRETURN( hr );
  1114. } //*** CConfigurationConnection::VerifyConnection()
  1115. //////////////////////////////////////////////////////////////////////////////
  1116. //++
  1117. //
  1118. // STDMETHODIMP
  1119. // CConfigurationConnection::VerifyConnectionToNode(
  1120. // LPCWSTR pcszNodeNameIn
  1121. // )
  1122. //
  1123. //--
  1124. //////////////////////////////////////////////////////////////////////////////
  1125. STDMETHODIMP
  1126. CConfigurationConnection::VerifyConnectionToNode(
  1127. LPCWSTR pcszNodeNameIn
  1128. )
  1129. {
  1130. TraceFunc1( "[IClusCfgVerify] pcszNodeNameIn = '%ws'", pcszNodeNameIn );
  1131. HRESULT hr;
  1132. IClusCfgVerify * pccv = NULL;
  1133. if ( m_pgit == NULL )
  1134. {
  1135. hr = THR( m_hrLastStatus );
  1136. goto Cleanup;
  1137. }
  1138. hr = THR( m_pgit->GetInterfaceFromGlobal( m_cookieGITVerify, TypeSafeParams( IClusCfgVerify, &pccv ) ) );
  1139. if ( FAILED( hr ) )
  1140. {
  1141. goto Cleanup;
  1142. }
  1143. hr = THR( pccv->VerifyConnectionToNode( pcszNodeNameIn ) );
  1144. Cleanup:
  1145. if ( pccv != NULL )
  1146. {
  1147. pccv->Release();
  1148. }
  1149. HRETURN( hr );
  1150. } //*** CConfigurationConnection::VerifyConnection()
  1151. //****************************************************************************
  1152. //
  1153. // IClusCfgCallback
  1154. //
  1155. //****************************************************************************
  1156. //////////////////////////////////////////////////////////////////////////////
  1157. //++
  1158. //
  1159. // STDMETHODIMP
  1160. // CConfigurationConnection::SendStatusReport(
  1161. // LPCWSTR pcszNodeNameIn
  1162. // , CLSID clsidTaskMajorIn
  1163. // , CLSID clsidTaskMinorIn
  1164. // , ULONG ulMinIn
  1165. // , ULONG ulMaxIn
  1166. // , ULONG ulCurrentIn
  1167. // , HRESULT hrStatusIn
  1168. // , LPCWSTR ocszDescriptionIn
  1169. // , FILETIME * pftTimeIn
  1170. // , LPCWSTR pcszReferenceIn
  1171. // )
  1172. //
  1173. //--
  1174. //////////////////////////////////////////////////////////////////////////////
  1175. STDMETHODIMP
  1176. CConfigurationConnection::SendStatusReport(
  1177. LPCWSTR pcszNodeNameIn
  1178. , CLSID clsidTaskMajorIn
  1179. , CLSID clsidTaskMinorIn
  1180. , ULONG ulMinIn
  1181. , ULONG ulMaxIn
  1182. , ULONG ulCurrentIn
  1183. , HRESULT hrStatusIn
  1184. , LPCWSTR ocszDescriptionIn
  1185. , FILETIME * pftTimeIn
  1186. , LPCWSTR pcszReferenceIn
  1187. )
  1188. {
  1189. TraceFunc( "[IClusCfgCallback]" );
  1190. HRESULT hr = S_OK;
  1191. IServiceProvider * psp = NULL;
  1192. IConnectionPointContainer * pcpc = NULL;
  1193. IConnectionPoint * pcp = NULL;
  1194. FILETIME ft;
  1195. if ( m_pcccb == NULL )
  1196. {
  1197. //
  1198. // Collect the manager we need to complete this task.
  1199. //
  1200. hr = THR( CoCreateInstance( CLSID_ServiceManager,
  1201. NULL,
  1202. CLSCTX_INPROC_SERVER,
  1203. TypeSafeParams( IServiceProvider, &psp )
  1204. ) );
  1205. if ( FAILED( hr ) )
  1206. {
  1207. goto Cleanup;
  1208. }
  1209. hr = THR( psp->TypeSafeQS( CLSID_NotificationManager,
  1210. IConnectionPointContainer,
  1211. &pcpc
  1212. ) );
  1213. if ( FAILED( hr ) )
  1214. {
  1215. goto Cleanup;
  1216. }
  1217. hr = THR( pcpc->FindConnectionPoint( IID_IClusCfgCallback, &pcp ) );
  1218. if ( FAILED( hr ) )
  1219. {
  1220. goto Cleanup;
  1221. }
  1222. pcp = TraceInterface( L"CConfigurationConnection!IConnectionPoint", IConnectionPoint, pcp, 1 );
  1223. hr = THR( pcp->TypeSafeQI( IClusCfgCallback, &m_pcccb ) );
  1224. if ( FAILED( hr ) )
  1225. {
  1226. goto Cleanup;
  1227. }
  1228. m_pcccb = TraceInterface( L"CConfigurationConnection!IClusCfgCallback", IClusCfgCallback, m_pcccb, 1 );
  1229. psp->Release();
  1230. psp = NULL;
  1231. }
  1232. if ( pftTimeIn == NULL )
  1233. {
  1234. GetSystemTimeAsFileTime( &ft );
  1235. pftTimeIn = &ft;
  1236. } // if:
  1237. //
  1238. // Send the message!
  1239. //
  1240. hr = THR( m_pcccb->SendStatusReport( pcszNodeNameIn,
  1241. clsidTaskMajorIn,
  1242. clsidTaskMinorIn,
  1243. ulMinIn,
  1244. ulMaxIn,
  1245. ulCurrentIn,
  1246. hrStatusIn,
  1247. ocszDescriptionIn,
  1248. pftTimeIn,
  1249. pcszReferenceIn
  1250. ) );
  1251. Cleanup:
  1252. if ( psp != NULL )
  1253. {
  1254. psp->Release();
  1255. }
  1256. if ( pcpc != NULL )
  1257. {
  1258. pcpc->Release();
  1259. }
  1260. if ( pcp != NULL )
  1261. {
  1262. pcp->Release();
  1263. }
  1264. HRETURN( hr );
  1265. } //*** CConfigurationConnection::SendStatusReport()
  1266. //****************************************************************************
  1267. //
  1268. // IClusCfgCapabilities
  1269. //
  1270. //****************************************************************************
  1271. //////////////////////////////////////////////////////////////////////////////
  1272. //++
  1273. //
  1274. // STDMETHODIMP
  1275. // CConfigurationConnection::CanNodeBeClustered( void )
  1276. //
  1277. //--
  1278. //////////////////////////////////////////////////////////////////////////////
  1279. STDMETHODIMP
  1280. CConfigurationConnection::CanNodeBeClustered( void )
  1281. {
  1282. TraceFunc( "[IClusCfgCapabilities]" );
  1283. HRESULT hr;
  1284. IClusCfgServer * pccs = NULL;
  1285. IClusCfgCapabilities * pccc = NULL;
  1286. if ( m_pgit == NULL )
  1287. {
  1288. hr = THR( m_hrLastStatus );
  1289. goto Cleanup;
  1290. }
  1291. hr = THR( m_pgit->GetInterfaceFromGlobal( m_cookieGITServer, TypeSafeParams( IClusCfgServer, &pccs ) ) );
  1292. if ( FAILED( hr ) )
  1293. {
  1294. goto Cleanup;
  1295. }
  1296. hr = THR( pccs->TypeSafeQI( IClusCfgCapabilities, &pccc ) );
  1297. if ( FAILED( hr ) )
  1298. {
  1299. goto Cleanup;
  1300. }
  1301. hr = STHR( pccc->CanNodeBeClustered( ) );
  1302. Cleanup:
  1303. if ( pccc != NULL )
  1304. {
  1305. pccc->Release();
  1306. }
  1307. if ( pccs != NULL )
  1308. {
  1309. pccs->Release();
  1310. }
  1311. HRETURN( hr );
  1312. } //*** CConfigurationConnection::CanNodeBeClustered()
  1313. //////////////////////////////////////////////////////////////////////////////
  1314. //++
  1315. //
  1316. // HRESULT
  1317. // CConfigurationConnection::HrStartPolling( void )
  1318. //
  1319. //--
  1320. //////////////////////////////////////////////////////////////////////////////
  1321. HRESULT
  1322. CConfigurationConnection::HrStartPolling( void )
  1323. {
  1324. TraceFunc( "" );
  1325. HRESULT hr;
  1326. IServiceProvider * psp = NULL;
  1327. IUnknown * punk = NULL;
  1328. ITaskManager * ptm = NULL;
  1329. ITaskPollingCallback * ptpcb = NULL;
  1330. hr = THR( CoCreateInstance( CLSID_ServiceManager, NULL, CLSCTX_INPROC_SERVER, TypeSafeParams( IServiceProvider, &psp ) ) );
  1331. if ( FAILED( hr ) )
  1332. {
  1333. goto Cleanup;
  1334. }
  1335. hr = THR( psp->TypeSafeQS( CLSID_TaskManager, ITaskManager, &ptm ) );
  1336. if ( FAILED( hr ) )
  1337. {
  1338. psp->Release(); // release promptly
  1339. goto Cleanup;
  1340. }
  1341. //
  1342. // Create the task object.
  1343. //
  1344. hr = THR( ptm->CreateTask( TASK_PollingCallback, &punk ) );
  1345. if ( FAILED( hr ) )
  1346. {
  1347. goto Cleanup;
  1348. }
  1349. hr = THR( punk->TypeSafeQI( ITaskPollingCallback, &ptpcb ) );
  1350. if ( FAILED( hr ) )
  1351. {
  1352. goto Cleanup;
  1353. }
  1354. //
  1355. // Save it away to be used next time. Do this using the GlobalInterfaceTable.
  1356. //
  1357. hr = THR( m_pgit->RegisterInterfaceInGlobal( ptpcb, IID_ITaskPollingCallback, &m_cookieGITCallbackTask ) );
  1358. if ( FAILED( hr ) )
  1359. {
  1360. goto Cleanup;
  1361. }
  1362. hr = THR( ptpcb->SetServerGITCookie( m_cookieGITServer ) );
  1363. if ( FAILED( hr ) )
  1364. {
  1365. goto Cleanup;
  1366. }
  1367. hr = THR( ptm->SubmitTask( ptpcb ) );
  1368. Cleanup:
  1369. if ( punk != NULL )
  1370. {
  1371. punk->Release();
  1372. }
  1373. if ( psp != NULL )
  1374. {
  1375. psp->Release();
  1376. } // if:
  1377. if ( ptm != NULL )
  1378. {
  1379. ptm->Release();
  1380. } // if:
  1381. if ( ptpcb != NULL )
  1382. {
  1383. ptpcb->Release();
  1384. } // if:
  1385. HRETURN( hr );
  1386. } //*** CConfigurationConnection::HrStartPolling()
  1387. //////////////////////////////////////////////////////////////////////////////
  1388. //++
  1389. //
  1390. // HRESULT
  1391. // CConfigurationConnection::HrStopPolling( void )
  1392. //
  1393. //--
  1394. //////////////////////////////////////////////////////////////////////////////
  1395. HRESULT
  1396. CConfigurationConnection::HrStopPolling( void )
  1397. {
  1398. TraceFunc( "" );
  1399. HRESULT hr = S_OK;
  1400. ITaskPollingCallback * ptpcb = NULL;
  1401. hr = THR( m_pgit->GetInterfaceFromGlobal( m_cookieGITCallbackTask, TypeSafeParams( ITaskPollingCallback, &ptpcb ) ) );
  1402. if ( FAILED( hr ) )
  1403. {
  1404. goto Cleanup;
  1405. }
  1406. hr = THR( ptpcb->StopTask() );
  1407. if ( FAILED( hr ) )
  1408. {
  1409. goto Cleanup;
  1410. }
  1411. hr = THR( m_pgit->RevokeInterfaceFromGlobal( m_cookieGITCallbackTask ) );
  1412. Cleanup:
  1413. if ( ptpcb != NULL )
  1414. {
  1415. ptpcb->Release();
  1416. } // if:
  1417. HRETURN( hr );
  1418. } //*** CConfigurationConnection::HrStopPolling()
  1419. //////////////////////////////////////////////////////////////////////////////
  1420. //++
  1421. //
  1422. // HRESULT
  1423. // CConfigurationConnection::HrSetSecurityBlanket( IClusCfgServer * pccsIn )
  1424. //
  1425. //--
  1426. //////////////////////////////////////////////////////////////////////////////
  1427. HRESULT
  1428. CConfigurationConnection::HrSetSecurityBlanket( IClusCfgServer * pccsIn )
  1429. {
  1430. TraceFunc( "" );
  1431. Assert( pccsIn != NULL );
  1432. HRESULT hr = S_FALSE;
  1433. IClientSecurity * pCliSec;
  1434. hr = THR( pccsIn->TypeSafeQI( IClientSecurity, &pCliSec ) );
  1435. if ( SUCCEEDED( hr ) )
  1436. {
  1437. hr = THR( pCliSec->SetBlanket(
  1438. pccsIn,
  1439. RPC_C_AUTHN_WINNT,
  1440. RPC_C_AUTHZ_NONE,
  1441. NULL,
  1442. RPC_C_AUTHN_LEVEL_PKT_PRIVACY,
  1443. RPC_C_IMP_LEVEL_IMPERSONATE,
  1444. NULL,
  1445. EOAC_NONE
  1446. ) );
  1447. pCliSec->Release();
  1448. if ( FAILED( hr ) )
  1449. {
  1450. LogMsg( L"[MT] Failed to set the security blanket on the server object. (hr = %#08x)", hr );
  1451. } // if:
  1452. } // if:
  1453. HRETURN( hr );
  1454. } //*** CConfigurationConnection::HrSetSecurityBlanket()
  1455. //////////////////////////////////////////////////////////////////////////////
  1456. //
  1457. // HRESULT
  1458. // CConfigurationConnection::HrIsLocalComputer(
  1459. // LPCWSTR pcszNameIn
  1460. // )
  1461. //
  1462. // Parameters:
  1463. // pcszNameIn
  1464. // FQDN or Hostname name to match against local computer name.
  1465. //
  1466. // Return Values:
  1467. // S_OK
  1468. // Succeeded. Name matches local computer name.
  1469. //
  1470. // S_FALSE
  1471. // Succeeded. Name does not match local computer name.
  1472. //
  1473. // E_INVALIDARG
  1474. // pcszNameIn was NULL.
  1475. //
  1476. //////////////////////////////////////////////////////////////////////////////
  1477. HRESULT
  1478. CConfigurationConnection::HrIsLocalComputer(
  1479. LPCWSTR pcszNameIn
  1480. )
  1481. {
  1482. TraceFunc1( "pcszNameIn = '%s'", pcszNameIn );
  1483. HRESULT hr = S_OK; // assume success!
  1484. if ( pcszNameIn == NULL )
  1485. {
  1486. hr = THR( E_INVALIDARG );
  1487. goto Cleanup;
  1488. }
  1489. if ( m_bstrLocalComputerName != NULL )
  1490. {
  1491. if ( _wcsicmp( pcszNameIn, m_bstrLocalComputerName ) == 0 )
  1492. {
  1493. // Found a match.
  1494. goto Cleanup;
  1495. }
  1496. }
  1497. if ( m_bstrLocalHostname != NULL )
  1498. {
  1499. if ( _wcsicmp( pcszNameIn, m_bstrLocalHostname ) == 0 )
  1500. {
  1501. // Found a match
  1502. goto Cleanup;
  1503. }
  1504. }
  1505. if ( _wcsicmp( pcszNameIn, L"." ) == 0 )
  1506. {
  1507. goto Cleanup;
  1508. }
  1509. hr = S_FALSE; // didn't match
  1510. Cleanup:
  1511. HRETURN( hr );
  1512. } //*** CConfigurationConnection::HrIsLocalComputer