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.

914 lines
20 KiB

  1. //////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 2000-2001 Microsoft Corporation
  4. //
  5. // Module Name:
  6. // ConfigClusApi.cpp
  7. //
  8. // Description:
  9. // CConfigClusApi implementation.
  10. //
  11. // Maintained By:
  12. // Galen Barbee (GalenB) 02-AUG-2000
  13. //
  14. //////////////////////////////////////////////////////////////////////////////
  15. //////////////////////////////////////////////////////////////////////////////
  16. // Include Files
  17. //////////////////////////////////////////////////////////////////////////////
  18. #include "pch.h"
  19. #include "CProxyCfgClusterInfo.h"
  20. #include "CClusCfgCredentials.h"
  21. #include "CProxyCfgNetworkInfo.h"
  22. //////////////////////////////////////////////////////////////////////////////
  23. // Constant Definitions
  24. //////////////////////////////////////////////////////////////////////////////
  25. DEFINE_THISCLASS("CProxyCfgClusterInfo")
  26. //
  27. //
  28. //
  29. HRESULT
  30. CProxyCfgClusterInfo::S_HrCreateInstance(
  31. IUnknown ** ppunkOut,
  32. IUnknown * punkOuterIn,
  33. HCLUSTER * phClusterIn,
  34. CLSID * pclsidMajorIn,
  35. LPCWSTR pcszDomainIn
  36. )
  37. {
  38. TraceFunc( "" );
  39. HRESULT hr = S_OK;
  40. CProxyCfgClusterInfo * pcc = NULL;
  41. if ( ppunkOut == NULL )
  42. {
  43. hr = THR( E_POINTER );
  44. goto Cleanup;
  45. } // if:
  46. pcc = new CProxyCfgClusterInfo;
  47. if ( pcc == NULL )
  48. {
  49. hr = THR( E_OUTOFMEMORY );
  50. goto Cleanup;
  51. } // if:
  52. hr = THR( pcc->HrInit( punkOuterIn, phClusterIn, pclsidMajorIn, pcszDomainIn ) );
  53. if ( FAILED( hr ) )
  54. goto Cleanup;
  55. hr = THR( pcc->TypeSafeQI( IUnknown, ppunkOut ) );
  56. Cleanup:
  57. if ( pcc != NULL )
  58. {
  59. pcc->Release();
  60. } // if:
  61. HRETURN( hr );
  62. } //*** CProxyCfgClusterInfo::S_HrCreateInstance()
  63. //
  64. //
  65. //
  66. CProxyCfgClusterInfo::CProxyCfgClusterInfo( void )
  67. : m_cRef( 1 )
  68. {
  69. TraceFunc( "" );
  70. InterlockedIncrement( &g_cObjects );
  71. Assert( m_cRef == 1 );
  72. Assert( m_punkOuter == NULL );
  73. Assert( m_pcccb == NULL );
  74. Assert( m_phCluster == NULL );
  75. Assert( m_pclsidMajor == NULL );
  76. Assert( m_bstrClusterName == NULL);
  77. Assert( m_ulIPAddress == 0 );
  78. Assert( m_ulSubnetMask == 0 );
  79. Assert( m_bstrNetworkName == NULL);
  80. Assert( m_pccc == NULL );
  81. Assert( m_bstrBindingString == NULL );
  82. TraceFuncExit();
  83. } //*** CProxyCfgClusterInfo::CProxyCfgClusterInfo()
  84. //
  85. //
  86. //
  87. CProxyCfgClusterInfo::~CProxyCfgClusterInfo( void )
  88. {
  89. TraceFunc( "" );
  90. // m_cRef - noop
  91. if ( m_punkOuter != NULL )
  92. {
  93. m_punkOuter->Release( );
  94. }
  95. if ( m_pcccb != NULL )
  96. {
  97. m_pcccb->Release();
  98. } // if:
  99. // m_phCluster - DO NOT CLOSE!
  100. // m_pclsidMajor - noop
  101. TraceSysFreeString( m_bstrClusterName );
  102. // m_ulIPAddress
  103. // m_ulSubnetMask
  104. TraceSysFreeString( m_bstrNetworkName );
  105. TraceSysFreeString( m_bstrBindingString );
  106. if ( m_pccc != NULL )
  107. {
  108. m_pccc->Release( );
  109. }
  110. InterlockedDecrement( &g_cObjects );
  111. TraceFuncExit();
  112. } //*** CProxyCfgClusterInfo::~CProxyCfgClusterInfo()
  113. //
  114. //
  115. //
  116. HRESULT
  117. CProxyCfgClusterInfo::HrInit(
  118. IUnknown * punkOuterIn,
  119. HCLUSTER * phClusterIn,
  120. CLSID * pclsidMajorIn,
  121. LPCWSTR pcszDomainIn
  122. )
  123. {
  124. TraceFunc( "" );
  125. HRESULT hr;
  126. DWORD sc;
  127. DWORD cch;
  128. BSTR bstrClusterName = NULL;
  129. CLUSTERVERSIONINFO cvi;
  130. if ( punkOuterIn != NULL )
  131. {
  132. m_punkOuter = punkOuterIn;
  133. m_punkOuter->AddRef( );
  134. }
  135. if ( phClusterIn == NULL )
  136. goto InvalidArg;
  137. m_phCluster = phClusterIn;
  138. if ( pclsidMajorIn != NULL )
  139. {
  140. m_pclsidMajor = pclsidMajorIn;
  141. }
  142. else
  143. {
  144. m_pclsidMajor = (CLSID *) &TASKID_Major_Client_And_Server_Log;
  145. }
  146. if ( punkOuterIn != NULL )
  147. {
  148. hr = THR( punkOuterIn->TypeSafeQI( IClusCfgCallback, &m_pcccb ) );
  149. if ( FAILED( hr ) )
  150. goto Cleanup;
  151. }
  152. //
  153. // Get the cluster's name and version info.
  154. //
  155. cvi.dwVersionInfoSize = sizeof(cvi);
  156. cch = 64; // arbitary starting buffer size
  157. bstrClusterName = TraceSysAllocStringLen( NULL, cch );
  158. if ( bstrClusterName == NULL )
  159. goto OutOfMemory;
  160. cch ++; // SysAllocStringLen allocates an extra character
  161. sc = GetClusterInformation( *m_phCluster, bstrClusterName, &cch, &cvi );
  162. if ( sc == ERROR_MORE_DATA )
  163. {
  164. TraceSysFreeString( bstrClusterName );
  165. bstrClusterName = TraceSysAllocStringLen( NULL, cch );
  166. if ( bstrClusterName == NULL )
  167. goto OutOfMemory;
  168. cch ++; // SysAllocStringLen allocates an extra character
  169. sc = GetClusterInformation( *m_phCluster, bstrClusterName, &cch, &cvi );
  170. }
  171. if ( sc != ERROR_SUCCESS )
  172. {
  173. hr = HRESULT_FROM_WIN32( TW32( sc ) );
  174. SSR_W2KPROXY_STATUS( TASKID_Major_Client_And_Server_Log, TASKID_Minor_HrInit_GetClusterInformation_Failed, hr );
  175. goto Cleanup;
  176. }
  177. // Give up ownership
  178. m_bstrClusterName = TraceSysAllocStringLen( NULL, SysStringLen( bstrClusterName ) + 1 + (UINT) wcslen( pcszDomainIn ) );
  179. if ( m_bstrClusterName == NULL )
  180. goto OutOfMemory;
  181. wcscpy( m_bstrClusterName, bstrClusterName );
  182. wcscat( m_bstrClusterName, L"." );
  183. wcscat( m_bstrClusterName, pcszDomainIn );
  184. Assert( m_bstrNetworkName == NULL );
  185. hr = THR( HrGetIPAddressOfCluster( *m_phCluster, &m_ulIPAddress, &m_ulSubnetMask, &m_bstrNetworkName ) );
  186. if ( FAILED( hr ) )
  187. goto Cleanup;
  188. hr = THR( HrLoadCredentials( ) );
  189. if ( FAILED( hr ) )
  190. goto Cleanup;
  191. hr = S_OK;
  192. Cleanup:
  193. TraceSysFreeString( bstrClusterName );
  194. HRETURN( hr );
  195. InvalidArg:
  196. hr = THR( E_INVALIDARG );
  197. SSR_W2KPROXY_STATUS( TASKID_Major_Client_And_Server_Log, TASKID_Minor_W2KProxy_ClusterInfo_HrInit_InvalidArg, hr );
  198. goto Cleanup;
  199. OutOfMemory:
  200. hr = E_OUTOFMEMORY;
  201. SSR_W2KPROXY_STATUS( TASKID_Major_Client_And_Server_Log, TASKID_Minor_W2KProxy_ClusterInfo_HrInit_OutOfMemory, hr );
  202. goto Cleanup;
  203. } //*** CProxyCfgClusterInfo::HrInit()
  204. //*************************************************************************//
  205. /////////////////////////////////////////////////////////////////////////////
  206. // CProxyCfgClusterInfo -- IUknkown interface.
  207. /////////////////////////////////////////////////////////////////////////////
  208. //
  209. //
  210. //
  211. STDMETHODIMP
  212. CProxyCfgClusterInfo::QueryInterface(
  213. REFIID riid,
  214. LPVOID *ppv
  215. )
  216. {
  217. TraceQIFunc( riid, ppv );
  218. HRESULT hr = E_NOINTERFACE;
  219. if ( IsEqualIID( riid, IID_IUnknown ) )
  220. {
  221. *ppv = static_cast< IClusCfgClusterInfo * >( this );
  222. hr = S_OK;
  223. } // if: IUnknown
  224. else if ( IsEqualIID( riid, IID_IClusCfgClusterInfo ) )
  225. {
  226. *ppv = TraceInterface( __THISCLASS__, IClusCfgClusterInfo, this, 0 );
  227. hr = S_OK;
  228. } // else if:
  229. if ( SUCCEEDED( hr ) )
  230. {
  231. ((IUnknown*) *ppv)->AddRef();
  232. } // if: success
  233. QIRETURN_IGNORESTDMARSHALLING( hr, riid );
  234. } //*** CConfigClusApi::QueryInterface()
  235. //////////////////////////////////////////////////////////////////////////////
  236. //++
  237. //
  238. // STDMETHODIMP_( ULONG )
  239. // CProxyCfgClusterInfo:: [IUNKNOWN] AddRef()
  240. //
  241. // Description:
  242. // Increment the reference count of this object by one.
  243. //
  244. // Arguments:
  245. // None.
  246. //
  247. // Return Value:
  248. // The new reference count.
  249. //
  250. // Remarks:
  251. // None.
  252. //
  253. //--
  254. //////////////////////////////////////////////////////////////////////////////
  255. STDMETHODIMP_(ULONG)
  256. CProxyCfgClusterInfo::AddRef( void )
  257. {
  258. TraceFunc( "[IUnknown]" );
  259. InterlockedIncrement( &m_cRef );
  260. RETURN( m_cRef );
  261. } //*** CProxyCfgClusterInfo::AddRef()
  262. //////////////////////////////////////////////////////////////////////////////
  263. //++
  264. //
  265. // STDMETHODIMP_( ULONG )
  266. // CProxyCfgClusterInfo:: [IUNKNOWN] Release()
  267. //
  268. // Description:
  269. // Decrement the reference count of this object by one.
  270. //
  271. // Arguments:
  272. // None.
  273. //
  274. // Return Value:
  275. // The new reference count.
  276. //
  277. // Remarks:
  278. // None.
  279. //
  280. //--
  281. //////////////////////////////////////////////////////////////////////////////
  282. STDMETHODIMP_(ULONG)
  283. CProxyCfgClusterInfo::Release( void )
  284. {
  285. TraceFunc( "[IUnknown]" );
  286. InterlockedDecrement( &m_cRef );
  287. if ( m_cRef )
  288. RETURN( m_cRef );
  289. TraceDo( delete this );
  290. RETURN( 0 );
  291. } //*** CProxyCfgClusterInfo::Release()
  292. //****************************************************************************
  293. //
  294. // IClusCfgClusterInfo
  295. //
  296. //****************************************************************************
  297. //
  298. //
  299. //
  300. STDMETHODIMP
  301. CProxyCfgClusterInfo::GetName(
  302. BSTR * pbstrNameOut
  303. )
  304. {
  305. TraceFunc( "[IClusCfgClusterInfo]" );
  306. HRESULT hr = S_OK;
  307. if ( pbstrNameOut == NULL )
  308. goto InvalidPointer;
  309. *pbstrNameOut = SysAllocString( m_bstrClusterName );
  310. if ( *pbstrNameOut == NULL )
  311. {
  312. hr = THR( E_OUTOFMEMORY );
  313. }
  314. CharLower( *pbstrNameOut );
  315. Cleanup:
  316. HRETURN( hr );
  317. InvalidPointer:
  318. hr = THR( E_POINTER );
  319. SSR_W2KPROXY_STATUS( TASKID_Major_Client_And_Server_Log, TASKID_Minor_W2kProxy_ClusterInfo_GetName_InvalidPointer, hr );
  320. goto Cleanup;
  321. } //*** CProxyCfgClusterInfo::GetName()
  322. //
  323. //
  324. //
  325. STDMETHODIMP
  326. CProxyCfgClusterInfo::GetIPAddress(
  327. DWORD * pdwIPAddress
  328. )
  329. {
  330. TraceFunc( "[IClusCfgClusterInfo]" );
  331. HRESULT hr = S_OK;
  332. if ( pdwIPAddress == NULL )
  333. goto InvalidPointer;
  334. *pdwIPAddress = m_ulIPAddress;
  335. Cleanup:
  336. HRETURN( hr );
  337. InvalidPointer:
  338. hr = THR( E_POINTER );
  339. SSR_W2KPROXY_STATUS( TASKID_Major_Client_And_Server_Log, TASKID_Minor_W2KProxy_ClusterInfo_GetIPAddress_InvalidPointer, hr );
  340. goto Cleanup;
  341. } //*** CProxyCfgClusterInfo::GetIPAddress()
  342. //
  343. //
  344. //
  345. STDMETHODIMP
  346. CProxyCfgClusterInfo::GetSubnetMask(
  347. DWORD * pdwNetMask
  348. )
  349. {
  350. TraceFunc( "[IClusCfgClusterInfo]" );
  351. HRESULT hr = S_OK;
  352. if ( pdwNetMask == NULL )
  353. goto InvalidPointer;
  354. *pdwNetMask = m_ulSubnetMask;
  355. Cleanup:
  356. HRETURN( hr );
  357. InvalidPointer:
  358. hr = THR( E_POINTER );
  359. SSR_W2KPROXY_STATUS( TASKID_Major_Client_And_Server_Log, TASKID_Minor_W2KProxy_ClusterInfo_GetSubnetMask_InvalidPointer, hr );
  360. goto Cleanup;
  361. } //*** CProxyCfgClusterInfo::GetSubnetMask()
  362. //
  363. //
  364. //
  365. STDMETHODIMP
  366. CProxyCfgClusterInfo::GetNetworkInfo(
  367. IClusCfgNetworkInfo ** ppICCNetInfoOut
  368. )
  369. {
  370. TraceFunc( "[IClusCfgClusterInfo]" );
  371. HRESULT hr;
  372. IUnknown * punk = NULL;
  373. if ( ppICCNetInfoOut == NULL )
  374. goto InvalidPointer;
  375. //
  376. // Create the network info object.
  377. //
  378. hr = THR( CProxyCfgNetworkInfo::S_HrCreateInstance( &punk,
  379. m_punkOuter,
  380. m_phCluster,
  381. m_pclsidMajor,
  382. m_bstrNetworkName
  383. ) );
  384. if ( FAILED( hr ) )
  385. goto Cleanup;
  386. hr = THR( punk->TypeSafeQI( IClusCfgNetworkInfo, ppICCNetInfoOut ) );
  387. Cleanup:
  388. if ( punk != NULL )
  389. {
  390. punk->Release();
  391. }
  392. HRETURN( hr );
  393. InvalidPointer:
  394. hr = THR( E_POINTER );
  395. SSR_W2KPROXY_STATUS( TASKID_Major_Client_And_Server_Log, TASKID_Minor_GetNetworkInfo_InvalidPointer, hr );
  396. goto Cleanup;
  397. } //*** CProxyCfgClusterInfo::GetNetworkInfo()
  398. //
  399. //
  400. //
  401. STDMETHODIMP
  402. CProxyCfgClusterInfo::GetClusterServiceAccountCredentials(
  403. IClusCfgCredentials ** ppICCCredentialsOut
  404. )
  405. {
  406. TraceFunc( "[IClusCfgClusterInfo]" );
  407. HRESULT hr;
  408. if ( ppICCCredentialsOut == NULL )
  409. goto InvalidPointer;
  410. hr = THR( m_pccc->TypeSafeQI( IClusCfgCredentials, ppICCCredentialsOut ) );
  411. if ( FAILED( hr ) )
  412. goto Cleanup;
  413. Cleanup:
  414. HRETURN( hr );
  415. InvalidPointer:
  416. hr = THR( E_POINTER );
  417. SSR_W2KPROXY_STATUS( TASKID_Major_Client_And_Server_Log, TASKID_Minor_GetClusterServiceAccountCredentials_InvalidPointer, hr );
  418. goto Cleanup;
  419. } //*** CProxyCfgClusterInfo::GetClusterServiceAccountCredentials()
  420. //
  421. //
  422. //
  423. STDMETHODIMP
  424. CProxyCfgClusterInfo::GetBindingString(
  425. BSTR * pbstrBindingStringOut
  426. )
  427. {
  428. TraceFunc( "[IClusCfgClusterInfo]" );
  429. HRESULT hr = S_OK;
  430. if ( pbstrBindingStringOut == NULL )
  431. goto InvalidPointer;
  432. *pbstrBindingStringOut = SysAllocString( m_bstrBindingString );
  433. if ( *pbstrBindingStringOut == NULL )
  434. {
  435. hr = THR( E_OUTOFMEMORY );
  436. }
  437. Cleanup:
  438. HRETURN( hr );
  439. InvalidPointer:
  440. hr = THR( E_POINTER );
  441. SSR_W2KPROXY_STATUS( TASKID_Major_Client_And_Server_Log, TASKID_Minor_W2kProxy_ClusterInfo_GetBindingString_InvalidPointer, hr );
  442. goto Cleanup;
  443. } //*** CProxyCfgClusterInfo::GetBindingString()
  444. //
  445. //
  446. //
  447. STDMETHODIMP
  448. CProxyCfgClusterInfo::SetCommitMode( ECommitMode ecmNewModeIn )
  449. {
  450. TraceFunc( "[IClusCfgClusterInfo]" );
  451. Assert( ecmNewModeIn != cmUNKNOWN );
  452. HRESULT hr = THR( E_NOTIMPL );
  453. HRETURN( hr );
  454. } //*** CProxyCfgClusterInfo::SetCommitMode()
  455. //
  456. //
  457. //
  458. STDMETHODIMP
  459. CProxyCfgClusterInfo::GetCommitMode( ECommitMode * pecmCurrentModeOut )
  460. {
  461. TraceFunc( "[IClusCfgClusterInfo]" );
  462. Assert( pecmCurrentModeOut != NULL );
  463. HRESULT hr = S_FALSE;
  464. HRETURN( hr );
  465. } //*** CProxyCfgClusterInfo::GetCommitMode()
  466. //
  467. //
  468. //
  469. STDMETHODIMP
  470. CProxyCfgClusterInfo::SetName( LPCWSTR pcszNameIn )
  471. {
  472. TraceFunc1( "[IClusCfgClusterInfo] pcszNameIn = '%ls'", pcszNameIn );
  473. HRESULT hr = THR( E_NOTIMPL );
  474. HRETURN( hr );
  475. } //*** CProxyCfgClusterInfo::SetName()
  476. //
  477. //
  478. //
  479. STDMETHODIMP
  480. CProxyCfgClusterInfo::SetIPAddress( DWORD dwIPAddressIn )
  481. {
  482. TraceFunc( "[IClusCfgClusterInfo]" );
  483. HRESULT hr = S_OK;
  484. if ( dwIPAddressIn != m_ulIPAddress )
  485. {
  486. hr = THR( E_FAIL );
  487. }
  488. HRETURN( hr );
  489. } //*** CProxyCfgClusterInfo::SetIPAddress()
  490. //
  491. //
  492. //
  493. STDMETHODIMP
  494. CProxyCfgClusterInfo::SetSubnetMask( DWORD dwNetMaskIn )
  495. {
  496. TraceFunc( "[IClusCfgClusterInfo]" );
  497. HRESULT hr = S_OK;
  498. if ( dwNetMaskIn != m_ulSubnetMask )
  499. {
  500. hr = THR( E_FAIL );
  501. }
  502. HRETURN( hr );
  503. } //*** CProxyCfgClusterInfo::SetSubnetMask()
  504. //
  505. //
  506. //
  507. STDMETHODIMP
  508. CProxyCfgClusterInfo::SetNetworkInfo( IClusCfgNetworkInfo * pICCNetInfoIn )
  509. {
  510. TraceFunc( "[IClusCfgClusterInfo]" );
  511. HRESULT hr = THR( E_NOTIMPL );
  512. HRETURN( hr );
  513. } //*** CProxyCfgClusterInfo::SetNetworkInfo()
  514. //
  515. //
  516. //
  517. STDMETHODIMP
  518. CProxyCfgClusterInfo::SetBindingString( LPCWSTR pcszBindingStringIn )
  519. {
  520. TraceFunc1( "[IClusCfgClusterInfo] pcszBindingStringIn = '%ls'", pcszBindingStringIn );
  521. HRESULT hr = S_OK;
  522. BSTR bstr = NULL;
  523. if ( pcszBindingStringIn == NULL )
  524. {
  525. hr = THR( E_INVALIDARG );
  526. goto Cleanup;
  527. } // if:
  528. bstr = TraceSysAllocString( pcszBindingStringIn );
  529. if ( bstr == NULL )
  530. {
  531. hr = THR( E_OUTOFMEMORY );
  532. goto Cleanup;
  533. } // if:
  534. TraceSysFreeString( m_bstrBindingString );
  535. m_bstrBindingString = bstr;
  536. Cleanup:
  537. HRETURN( hr );
  538. } //*** CProxyCfgClusterInfo::SetName()
  539. //****************************************************************************
  540. //
  541. // IClusCfgCallback
  542. //
  543. //****************************************************************************
  544. //////////////////////////////////////////////////////////////////////////////
  545. //++
  546. //
  547. // CProxyCfgClusterInfo::SendStatusReport()
  548. //
  549. // Description:
  550. //
  551. // Arguments:
  552. //
  553. // Return Value:
  554. //
  555. // Remarks:
  556. // None.
  557. //
  558. //--
  559. //////////////////////////////////////////////////////////////////////////////
  560. STDMETHODIMP
  561. CProxyCfgClusterInfo::SendStatusReport(
  562. LPCWSTR pcszNodeNameIn
  563. , CLSID clsidTaskMajorIn
  564. , CLSID clsidTaskMinorIn
  565. , ULONG ulMinIn
  566. , ULONG ulMaxIn
  567. , ULONG ulCurrentIn
  568. , HRESULT hrStatusIn
  569. , LPCWSTR pcszDescriptionIn
  570. , FILETIME * pftTimeIn
  571. , LPCWSTR pcszReferenceIn
  572. )
  573. {
  574. TraceFunc( "[IClusCfgCallback]" );
  575. HRESULT hr = S_OK;
  576. if ( m_pcccb != NULL )
  577. {
  578. hr = THR( m_pcccb->SendStatusReport( pcszNodeNameIn,
  579. clsidTaskMajorIn,
  580. clsidTaskMinorIn,
  581. ulMinIn,
  582. ulMaxIn,
  583. ulCurrentIn,
  584. hrStatusIn,
  585. pcszDescriptionIn,
  586. pftTimeIn,
  587. pcszReferenceIn
  588. ) );
  589. } // if:
  590. HRETURN( hr );
  591. } //*** CProxyCfgClusterInfo::SendStatusReport()
  592. //****************************************************************************
  593. //
  594. // IClusCfgCallback
  595. //
  596. //****************************************************************************
  597. //////////////////////////////////////////////////////////////////////////////
  598. //++
  599. //
  600. // CProxyCfgClusterInfo::HrLoadCredentials()
  601. //
  602. // Description:
  603. //
  604. //
  605. // Arguments:
  606. //
  607. //
  608. // Return Value:
  609. //
  610. //
  611. // Remarks:
  612. // None.
  613. //
  614. //--
  615. //////////////////////////////////////////////////////////////////////////////
  616. HRESULT
  617. CProxyCfgClusterInfo::HrLoadCredentials( void )
  618. {
  619. TraceFunc( "" );
  620. HRESULT hr = S_OK;
  621. SC_HANDLE schSCM = NULL;
  622. SC_HANDLE schClusSvc = NULL;
  623. DWORD sc;
  624. DWORD cbpqsc = 128;
  625. DWORD cbRequired;
  626. QUERY_SERVICE_CONFIG * pqsc = NULL;
  627. IUnknown * punk = NULL;
  628. IClusCfgSetCredentials * piccsc = NULL;
  629. schSCM = OpenSCManager( m_bstrClusterName, NULL, GENERIC_READ );
  630. if ( schSCM == NULL )
  631. {
  632. hr = HRESULT_FROM_WIN32( TW32( GetLastError() ) );
  633. SSR_W2KPROXY_STATUS( TASKID_Major_Client_And_Server_Log, TASKID_Minor_HrLoadCredentials_OpenSCManager_Failed, hr );
  634. goto Cleanup;
  635. } // if:
  636. schClusSvc = OpenService( schSCM, L"ClusSvc", GENERIC_READ );
  637. if ( schClusSvc == NULL )
  638. {
  639. hr = HRESULT_FROM_WIN32( TW32( GetLastError() ) );
  640. SSR_W2KPROXY_STATUS( TASKID_Major_Client_And_Server_Log, TASKID_Minor_HrLoadCredentials_OpenService_Failed, hr );
  641. goto Cleanup;
  642. } // if:
  643. for ( ; ; )
  644. {
  645. BOOL fRet;
  646. pqsc = (QUERY_SERVICE_CONFIG *) TraceAlloc( 0, cbpqsc );
  647. if ( pqsc == NULL )
  648. goto OutOfMemory;
  649. fRet = QueryServiceConfig( schClusSvc, pqsc, cbpqsc, &cbRequired );
  650. if ( !fRet )
  651. {
  652. sc = GetLastError();
  653. if ( sc == ERROR_INSUFFICIENT_BUFFER )
  654. {
  655. TraceFree( pqsc );
  656. pqsc = NULL;
  657. cbpqsc = cbRequired;
  658. continue;
  659. } // if:
  660. else
  661. {
  662. hr = HRESULT_FROM_WIN32( TW32( sc ) );
  663. SSR_W2KPROXY_STATUS( TASKID_Major_Client_And_Server_Log, TASKID_Minor_HrLoadCredentials_QueryServiceConfig_Failed, hr );
  664. goto Cleanup;
  665. } // else:
  666. } // if:
  667. else
  668. {
  669. break;
  670. } // else:
  671. } // for:
  672. Assert( m_pccc == NULL );
  673. hr = THR( CClusCfgCredentials::S_HrCreateInstance( &punk ) );
  674. if ( FAILED( hr ) )
  675. goto Cleanup;
  676. hr = THR( punk->TypeSafeQI( IClusCfgCredentials, &m_pccc ) );
  677. if ( FAILED( hr ) )
  678. goto Cleanup;
  679. hr = THR( m_pccc->TypeSafeQI( IClusCfgSetCredentials, &piccsc ) );
  680. if ( FAILED( hr ) )
  681. {
  682. goto Cleanup;
  683. } // if:
  684. hr = THR( piccsc->SetDomainCredentials( pqsc->lpServiceStartName ) );
  685. Cleanup:
  686. if ( punk != NULL )
  687. {
  688. punk->Release( );
  689. }
  690. if ( schClusSvc != NULL )
  691. {
  692. CloseServiceHandle( schClusSvc );
  693. } // if:
  694. if ( schSCM != NULL )
  695. {
  696. CloseServiceHandle( schSCM );
  697. } // if:
  698. if ( pqsc != NULL )
  699. {
  700. TraceFree( pqsc );
  701. } // if:
  702. if ( piccsc != NULL )
  703. {
  704. piccsc->Release();
  705. } // if:
  706. HRETURN( hr );
  707. OutOfMemory:
  708. hr = E_OUTOFMEMORY;
  709. SSR_W2KPROXY_STATUS( TASKID_Major_Client_And_Server_Log, TASKID_Minor_HrLoadCredentials_OutOfMemory, hr );
  710. goto Cleanup;
  711. } //*** CProxyCfgClusterInfo::HrLoadCredentials()