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.

1053 lines
25 KiB

  1. //////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 2000-2002 Microsoft Corporation
  4. //
  5. // Module Name:
  6. // CClusCfgCredentials.cpp
  7. //
  8. // Header File:
  9. // CClusCfgCredentials.h
  10. //
  11. // Description:
  12. // This file contains the definition of the CClusCfgCredentials
  13. // class.
  14. //
  15. // The class CClusCfgCredentials is the representation of
  16. // account credentials. It implements the IClusCfgCredentials interface.
  17. //
  18. // Maintained By:
  19. // Galen Barbee (GalenB) 17-May-2000
  20. //
  21. //////////////////////////////////////////////////////////////////////////////
  22. //////////////////////////////////////////////////////////////////////////////
  23. // Include Files
  24. //////////////////////////////////////////////////////////////////////////////
  25. #include "pch.h"
  26. #include "EncryptedBSTR.h"
  27. #include "CClusCfgCredentials.h"
  28. //////////////////////////////////////////////////////////////////////////////
  29. // Constant Definitions
  30. //////////////////////////////////////////////////////////////////////////////
  31. DEFINE_THISCLASS( "CClusCfgCredentials" );
  32. //*************************************************************************//
  33. /////////////////////////////////////////////////////////////////////////////
  34. // CClusCfgCredentials class
  35. /////////////////////////////////////////////////////////////////////////////
  36. //////////////////////////////////////////////////////////////////////////////
  37. //++
  38. //
  39. // CClusCfgCredentials::S_HrCreateInstance
  40. //
  41. // Description:
  42. // Create a CClusCfgCredentials instance.
  43. //
  44. // Arguments:
  45. // ppunkOut
  46. //
  47. // Return Values:
  48. // Pointer to CClusCfgCredentials instance.
  49. //
  50. //--
  51. //////////////////////////////////////////////////////////////////////////////
  52. HRESULT
  53. CClusCfgCredentials::S_HrCreateInstance( IUnknown ** ppunkOut )
  54. {
  55. TraceFunc( "" );
  56. HRESULT hr = S_OK;
  57. CClusCfgCredentials * pccc = NULL;
  58. if ( ppunkOut == NULL )
  59. {
  60. hr = THR( E_POINTER );
  61. goto Cleanup;
  62. } // if:
  63. pccc = new CClusCfgCredentials();
  64. if ( pccc == NULL )
  65. {
  66. hr = THR( E_OUTOFMEMORY );
  67. goto Cleanup;
  68. } // if: error allocating object
  69. hr = THR( pccc->HrInit() );
  70. if ( FAILED( hr ) )
  71. {
  72. goto Cleanup;
  73. } // if: HrInit() failed
  74. hr = THR( pccc->TypeSafeQI( IUnknown, ppunkOut ) );
  75. Cleanup:
  76. if ( FAILED( hr ) )
  77. {
  78. LogMsg( L"Server: CClusCfgCredentials::S_HrCreateInstance() failed. (hr = %#08x)", hr );
  79. } // if:
  80. if ( pccc != NULL )
  81. {
  82. pccc->Release();
  83. } // if:
  84. HRETURN( hr );
  85. } //*** CClusCfgCredentials::S_HrCreateInstance
  86. //////////////////////////////////////////////////////////////////////////////
  87. //++
  88. //
  89. // CClusCfgCredentials::CClusCfgCredentials
  90. //
  91. // Description:
  92. // Constructor of the CClusCfgCredentials class. This initializes
  93. // the m_cRef variable to 1 instead of 0 to account of possible
  94. // QueryInterface failure in DllGetClassObject.
  95. //
  96. // Arguments:
  97. // None.
  98. //
  99. // Return Value:
  100. // None.
  101. //
  102. //--
  103. //////////////////////////////////////////////////////////////////////////////
  104. CClusCfgCredentials::CClusCfgCredentials( void )
  105. : m_cRef( 1 )
  106. , m_lcid( LOCALE_NEUTRAL )
  107. , m_bstrAccountName( NULL )
  108. , m_bstrAccountDomain( NULL )
  109. {
  110. TraceFunc( "" );
  111. // Increment the count of components in memory so the DLL hosting this
  112. // object cannot be unloaded.
  113. InterlockedIncrement( &g_cObjects );
  114. Assert( m_picccCallback == NULL );
  115. TraceFuncExit();
  116. } //*** CClusCfgCredentials::CClusCfgCredentials
  117. //////////////////////////////////////////////////////////////////////////////
  118. //++
  119. //
  120. // CClusCfgCredentials::~CClusCfgCredentials
  121. //
  122. // Description:
  123. // Desstructor of the CClusCfgCredentials class.
  124. //
  125. // Arguments:
  126. // None.
  127. //
  128. // Return Value:
  129. // None.
  130. //
  131. //--
  132. //////////////////////////////////////////////////////////////////////////////
  133. CClusCfgCredentials::~CClusCfgCredentials( void )
  134. {
  135. TraceFunc( "" );
  136. // There's going to be one less component in memory. Decrement component count.
  137. InterlockedDecrement( &g_cObjects );
  138. if ( m_picccCallback != NULL )
  139. {
  140. m_picccCallback->Release();
  141. } // if:
  142. TraceSysFreeString( m_bstrAccountName );
  143. TraceSysFreeString( m_bstrAccountDomain );
  144. TraceFuncExit();
  145. } //*** CClusCfgCredentials::~CClusCfgCredentials
  146. //*************************************************************************//
  147. /////////////////////////////////////////////////////////////////////////////
  148. // CClusterConfiguration -- IUknkown interface.
  149. /////////////////////////////////////////////////////////////////////////////
  150. //////////////////////////////////////////////////////////////////////////////
  151. //++
  152. //
  153. // CClusCfgCredentials::AddRef
  154. //
  155. // Description:
  156. // Increment the reference count of this object by one.
  157. //
  158. // Arguments:
  159. // None.
  160. //
  161. // Return Value:
  162. // The new reference count.
  163. //
  164. //--
  165. //////////////////////////////////////////////////////////////////////////////
  166. STDMETHODIMP_( ULONG )
  167. CClusCfgCredentials::AddRef( void )
  168. {
  169. TraceFunc( "[IUnknown]" );
  170. InterlockedIncrement( & m_cRef );
  171. CRETURN( m_cRef );
  172. } //*** CClusCfgCredentials::AddRef
  173. //////////////////////////////////////////////////////////////////////////////
  174. //++
  175. //
  176. // CClusCfgCredentials::Release
  177. //
  178. // Description:
  179. // Decrement the reference count of this object by one.
  180. //
  181. // Arguments:
  182. // None.
  183. //
  184. // Return Value:
  185. // The new reference count.
  186. //
  187. //--
  188. //////////////////////////////////////////////////////////////////////////////
  189. STDMETHODIMP_( ULONG )
  190. CClusCfgCredentials::Release( void )
  191. {
  192. TraceFunc( "[IUnknown]" );
  193. LONG cRef;
  194. cRef = InterlockedDecrement( &m_cRef );
  195. if ( cRef == 0 )
  196. {
  197. TraceDo( delete this );
  198. } // if: reference count equal to zero
  199. CRETURN( cRef );
  200. } //*** CClusCfgCredentials::Release
  201. //////////////////////////////////////////////////////////////////////////////
  202. //++
  203. //
  204. // CClusCfgCredentials::QueryInterface
  205. //
  206. // Description:
  207. // Query this object for the passed in interface.
  208. //
  209. // Arguments:
  210. // riidIn
  211. // Id of interface requested.
  212. //
  213. // ppvOut
  214. // Pointer to the requested interface.
  215. //
  216. // Return Value:
  217. // S_OK
  218. // If the interface is available on this object.
  219. //
  220. // E_NOINTERFACE
  221. // If the interface is not available.
  222. //
  223. // E_POINTER
  224. // ppvOut was NULL.
  225. //
  226. //--
  227. //////////////////////////////////////////////////////////////////////////////
  228. STDMETHODIMP
  229. CClusCfgCredentials::QueryInterface(
  230. REFIID riidIn
  231. , void ** ppvOut
  232. )
  233. {
  234. TraceQIFunc( riidIn, ppvOut );
  235. HRESULT hr = S_OK;
  236. //
  237. // Validate arguments.
  238. //
  239. Assert( ppvOut != NULL );
  240. if ( ppvOut == NULL )
  241. {
  242. hr = THR( E_POINTER );
  243. goto Cleanup;
  244. }
  245. //
  246. // Handle known interfaces.
  247. //
  248. if ( IsEqualIID( riidIn, IID_IUnknown ) )
  249. {
  250. *ppvOut = static_cast< IClusCfgCredentials * >( this );
  251. } // if: IUnknown
  252. else if ( IsEqualIID( riidIn, IID_IClusCfgCredentials ) )
  253. {
  254. *ppvOut = TraceInterface( __THISCLASS__, IClusCfgCredentials, this, 0 );
  255. } // else if: IID_IClusCfgCredentials
  256. else if ( IsEqualIID( riidIn, IID_IClusCfgInitialize ) )
  257. {
  258. *ppvOut = TraceInterface( __THISCLASS__, IClusCfgInitialize, this, 0 );
  259. } // else if: IClusCfgInitialize
  260. else if ( IsEqualIID( riidIn, IID_IClusCfgSetCredentials ) )
  261. {
  262. *ppvOut = TraceInterface( __THISCLASS__, IClusCfgSetCredentials, this, 0 );
  263. } // else if: IClusCfgSetCredentials
  264. else
  265. {
  266. *ppvOut = NULL;
  267. hr = E_NOINTERFACE;
  268. }
  269. //
  270. // Add a reference to the interface if successful.
  271. //
  272. if ( SUCCEEDED( hr ) )
  273. {
  274. ((IUnknown *) *ppvOut)->AddRef();
  275. } // if: success
  276. Cleanup:
  277. QIRETURN_IGNORESTDMARSHALLING1( hr, riidIn, IID_IClusCfgWbemServices );
  278. } //*** CClusCfgCredentials::QueryInterface
  279. //*************************************************************************//
  280. /////////////////////////////////////////////////////////////////////////////
  281. // CClusCfgCredentials -- IClusCfgInitialze interface.
  282. /////////////////////////////////////////////////////////////////////////////
  283. //////////////////////////////////////////////////////////////////////////////
  284. //++
  285. //
  286. // CClusCfgCredentials::Initialize
  287. //
  288. // Description:
  289. // Initialize this component.
  290. //
  291. // Arguments:
  292. // punkCallbackIn
  293. // lcidIn
  294. //
  295. // Return Value:
  296. // S_OK
  297. // Success
  298. //
  299. //--
  300. //////////////////////////////////////////////////////////////////////////////
  301. STDMETHODIMP
  302. CClusCfgCredentials::Initialize(
  303. IUnknown * punkCallbackIn
  304. , LCID lcidIn
  305. )
  306. {
  307. TraceFunc( "[IClusCfgInitialize]" );
  308. HRESULT hr = S_OK;
  309. m_lcid = lcidIn;
  310. Assert( m_picccCallback == NULL );
  311. if ( punkCallbackIn != NULL )
  312. {
  313. hr = THR( punkCallbackIn->TypeSafeQI( IClusCfgCallback, &m_picccCallback ) );
  314. } // if:
  315. HRETURN( hr );
  316. } //*** CClusCfgCredentials::Initialize
  317. //*************************************************************************//
  318. /////////////////////////////////////////////////////////////////////////////
  319. // CClusCfgCredentials -- IClusCfgCredentials interface.
  320. /////////////////////////////////////////////////////////////////////////////
  321. //////////////////////////////////////////////////////////////////////////////
  322. //++
  323. //
  324. // CClusCfgCredentials::GetCredentials
  325. //
  326. // Description:
  327. //
  328. // Arguments:
  329. // pbstrNameOut
  330. // pbstrDomainOut
  331. // pbstrPasswordOut
  332. //
  333. // Return Value:
  334. // S_OK - Success.
  335. // E_OUTOFMEMORY - Error allocating memory.
  336. // Other HRESULTs.
  337. //
  338. //--
  339. //////////////////////////////////////////////////////////////////////////////
  340. STDMETHODIMP
  341. CClusCfgCredentials::GetCredentials(
  342. BSTR * pbstrNameOut
  343. , BSTR * pbstrDomainOut
  344. , BSTR * pbstrPasswordOut
  345. )
  346. {
  347. TraceFunc( "[IClusCfgCredentials]" );
  348. HRESULT hr = S_OK;
  349. BSTR bstrName = NULL;
  350. BSTR bstrDomain = NULL;
  351. BSTR bstrPassword = NULL;
  352. // The marshaller doesn't allow null out-parameters, but just to be explicit...
  353. if ( pbstrNameOut != NULL )
  354. {
  355. *pbstrNameOut = NULL;
  356. }
  357. if ( pbstrDomainOut != NULL )
  358. {
  359. *pbstrDomainOut = NULL;
  360. }
  361. if ( pbstrPasswordOut != NULL )
  362. {
  363. *pbstrPasswordOut = NULL;
  364. }
  365. if ( ( pbstrNameOut == NULL ) || ( pbstrDomainOut == NULL ) || ( pbstrPasswordOut == NULL ) )
  366. {
  367. hr = THR( E_POINTER );
  368. goto Cleanup;
  369. }
  370. if ( m_bstrAccountName != NULL )
  371. {
  372. bstrName = SysAllocString( m_bstrAccountName );
  373. if ( bstrName == NULL )
  374. {
  375. hr = THR( E_OUTOFMEMORY );
  376. goto Cleanup;
  377. }
  378. }
  379. if ( m_bstrAccountDomain != NULL )
  380. {
  381. bstrDomain = SysAllocString( m_bstrAccountDomain );
  382. if ( bstrDomain == NULL )
  383. {
  384. hr = THR( E_OUTOFMEMORY );
  385. goto Cleanup;
  386. }
  387. }
  388. hr = STHR( m_encbstrPassword.HrGetBSTR( &bstrPassword ) );
  389. if ( FAILED( hr ) )
  390. {
  391. goto Cleanup;
  392. }
  393. *pbstrNameOut = bstrName;
  394. bstrName = NULL;
  395. *pbstrDomainOut = bstrDomain;
  396. bstrDomain = NULL;
  397. *pbstrPasswordOut = bstrPassword;
  398. TraceMemoryDelete( bstrPassword, false );
  399. bstrPassword = NULL;
  400. hr = S_OK; // because decrypting might have returned S_FALSE
  401. Cleanup:
  402. SysFreeString( bstrName );
  403. SysFreeString( bstrDomain );
  404. if ( bstrPassword != NULL )
  405. {
  406. CEncryptedBSTR::SecureZeroBSTR( bstrPassword );
  407. TraceSysFreeString( bstrPassword );
  408. }
  409. HRETURN( hr );
  410. } //*** CClusCfgCredentials::GetCredentials
  411. //////////////////////////////////////////////////////////////////////////////
  412. //++
  413. //
  414. // CClusCfgCredentials::GetIdentity
  415. //
  416. // Description:
  417. //
  418. // Arguments:
  419. // pbstrNameOut
  420. // pbstrDomainOut
  421. //
  422. // Return Value:
  423. // S_OK - Success.
  424. // E_OUTOFMEMORY - Error allocating memory.
  425. // Other HRESULTs.
  426. //
  427. //--
  428. //////////////////////////////////////////////////////////////////////////////
  429. STDMETHODIMP
  430. CClusCfgCredentials::GetIdentity(
  431. BSTR * pbstrNameOut
  432. , BSTR * pbstrDomainOut
  433. )
  434. {
  435. TraceFunc( "[IClusCfgCredentials]" );
  436. HRESULT hr = S_OK;
  437. BSTR bstrName = NULL;
  438. BSTR bstrDomain = NULL;
  439. // The marshaller doesn't allow null out-parameters, but just to be explicit...
  440. if ( pbstrNameOut != NULL )
  441. {
  442. *pbstrNameOut = NULL;
  443. }
  444. if ( pbstrDomainOut != NULL )
  445. {
  446. *pbstrDomainOut = NULL;
  447. }
  448. if ( ( pbstrNameOut == NULL ) || ( pbstrDomainOut == NULL ) )
  449. {
  450. hr = THR( E_POINTER );
  451. goto Cleanup;
  452. }
  453. if ( m_bstrAccountName != NULL )
  454. {
  455. bstrName = SysAllocString( m_bstrAccountName );
  456. if ( bstrName == NULL )
  457. {
  458. hr = THR( E_OUTOFMEMORY );
  459. goto Cleanup;
  460. }
  461. }
  462. if ( m_bstrAccountDomain != NULL )
  463. {
  464. bstrDomain = SysAllocString( m_bstrAccountDomain );
  465. if ( bstrDomain == NULL )
  466. {
  467. hr = THR( E_OUTOFMEMORY );
  468. goto Cleanup;
  469. }
  470. }
  471. *pbstrNameOut = bstrName;
  472. bstrName = NULL;
  473. *pbstrDomainOut = bstrDomain;
  474. bstrDomain = NULL;
  475. Cleanup:
  476. SysFreeString( bstrName );
  477. SysFreeString( bstrDomain );
  478. HRETURN( hr );
  479. } //*** CClusCfgCredentials::GetCredentials
  480. //////////////////////////////////////////////////////////////////////////////
  481. //++
  482. //
  483. // CClusCfgCredentials::GetPassword
  484. //
  485. // Description:
  486. //
  487. // Arguments:
  488. // pbstrPasswordOut
  489. //
  490. // Return Value:
  491. // S_OK - Success.
  492. // E_OUTOFMEMORY - Error allocating memory.
  493. // Other HRESULTs.
  494. //
  495. //--
  496. //////////////////////////////////////////////////////////////////////////////
  497. STDMETHODIMP
  498. CClusCfgCredentials::GetPassword( BSTR * pbstrPasswordOut )
  499. {
  500. TraceFunc( "[IClusCfgCredentials]" );
  501. HRESULT hr = S_OK;
  502. BSTR bstrPassword = NULL;
  503. // The marshaller doesn't allow null out-parameters, but just to be explicit...
  504. if ( pbstrPasswordOut == NULL )
  505. {
  506. hr = THR( E_POINTER );
  507. goto Cleanup;
  508. }
  509. *pbstrPasswordOut = NULL;
  510. hr = STHR( m_encbstrPassword.HrGetBSTR( &bstrPassword ) );
  511. if ( FAILED( hr ) )
  512. {
  513. goto Cleanup;
  514. }
  515. *pbstrPasswordOut = bstrPassword;
  516. TraceMemoryDelete( bstrPassword, false );
  517. bstrPassword = NULL;
  518. hr = S_OK; // because decrypting might have returned S_FALSE
  519. Cleanup:
  520. if ( bstrPassword != NULL )
  521. {
  522. CEncryptedBSTR::SecureZeroBSTR( bstrPassword );
  523. TraceSysFreeString( bstrPassword );
  524. }
  525. HRETURN( hr );
  526. } //*** CClusCfgCredentials::GetPassword
  527. //////////////////////////////////////////////////////////////////////////////
  528. //++
  529. //
  530. // CClusCfgCredentials::SetCredentials
  531. //
  532. // Description:
  533. //
  534. // Arguments:
  535. // pcszNameIn
  536. // pcszDomainIn
  537. // pcszPasswordIn
  538. //
  539. // Return Value:
  540. // S_OK - Success.
  541. // E_OUTOFMEMORY - Error allocating memory.
  542. // Other HRESULTs.
  543. //
  544. //--
  545. //////////////////////////////////////////////////////////////////////////////
  546. STDMETHODIMP
  547. CClusCfgCredentials::SetCredentials(
  548. LPCWSTR pcszNameIn,
  549. LPCWSTR pcszDomainIn,
  550. LPCWSTR pcszPasswordIn
  551. )
  552. {
  553. TraceFunc( "[IClusCfgCredentials]" );
  554. HRESULT hr = S_OK;
  555. BSTR bstrNewName = NULL;
  556. BSTR bstrNewDomain = NULL;
  557. if ( pcszNameIn != NULL )
  558. {
  559. bstrNewName = TraceSysAllocString( pcszNameIn );
  560. if ( bstrNewName == NULL )
  561. {
  562. hr = THR( E_OUTOFMEMORY );
  563. goto Cleanup;
  564. } // if:
  565. } // if:
  566. if ( pcszDomainIn != NULL )
  567. {
  568. bstrNewDomain = TraceSysAllocString( pcszDomainIn );
  569. if ( bstrNewDomain == NULL )
  570. {
  571. hr = THR( E_OUTOFMEMORY );
  572. goto Cleanup;
  573. } // if:
  574. } // if:
  575. // Keep this after name and domain, to preserve password in case copying either of the others fails.
  576. if ( pcszPasswordIn != NULL )
  577. {
  578. size_t cchPassword = wcslen( pcszPasswordIn );
  579. hr = THR( m_encbstrPassword.HrSetWSTR( pcszPasswordIn, cchPassword ) );
  580. if ( FAILED( hr ) )
  581. {
  582. goto Cleanup;
  583. }
  584. } // if:
  585. if ( bstrNewName != NULL )
  586. {
  587. TraceSysFreeString( m_bstrAccountName );
  588. m_bstrAccountName = bstrNewName;
  589. bstrNewName = NULL;
  590. } // if:
  591. if ( bstrNewDomain != NULL )
  592. {
  593. TraceSysFreeString( m_bstrAccountDomain );
  594. m_bstrAccountDomain = bstrNewDomain;
  595. bstrNewDomain = NULL;
  596. } // if:
  597. Cleanup:
  598. TraceSysFreeString( bstrNewName );
  599. TraceSysFreeString( bstrNewDomain );
  600. HRETURN( hr );
  601. } //*** CClusCfgCredentials::SetCredentials
  602. //////////////////////////////////////////////////////////////////////////////
  603. //++
  604. //
  605. // CClusCfgCredentials::AssignTo
  606. //
  607. // Description:
  608. //
  609. // Arguments:
  610. // picccDestIn
  611. //
  612. // Return Value:
  613. // S_OK - Success.
  614. // E_OUTOFMEMORY - Error allocating memory.
  615. // Other HRESULTs.
  616. //
  617. //--
  618. //////////////////////////////////////////////////////////////////////////////
  619. STDMETHODIMP
  620. CClusCfgCredentials::AssignTo(
  621. IClusCfgCredentials * picccDestIn
  622. )
  623. {
  624. TraceFunc( "[IClusCfgCredentials]" );
  625. HRESULT hr = S_OK;
  626. BSTR bstrPassword = NULL;
  627. if ( picccDestIn == NULL )
  628. {
  629. hr = THR( E_POINTER );
  630. goto Cleanup;
  631. }
  632. hr = THR( m_encbstrPassword.HrGetBSTR( &bstrPassword ) );
  633. if ( FAILED( hr ) )
  634. {
  635. goto Cleanup;
  636. }
  637. hr = THR( picccDestIn->SetCredentials( m_bstrAccountName, m_bstrAccountDomain, bstrPassword ) );
  638. if ( FAILED( hr ) )
  639. {
  640. goto Cleanup;
  641. }
  642. Cleanup:
  643. if ( bstrPassword != NULL )
  644. {
  645. CEncryptedBSTR::SecureZeroBSTR( bstrPassword );
  646. TraceSysFreeString( bstrPassword );
  647. }
  648. HRETURN( hr );
  649. } //*** CClusCfgCredentials::AssignTo
  650. //////////////////////////////////////////////////////////////////////////////
  651. //++
  652. //
  653. // CClusCfgCredentials::AssignFrom
  654. //
  655. // Description:
  656. //
  657. // Arguments:
  658. // picccSourceIn
  659. //
  660. // Return Value:
  661. // S_OK - Success.
  662. // E_OUTOFMEMORY - Error allocating memory.
  663. // Other HRESULTs.
  664. //
  665. //--
  666. //////////////////////////////////////////////////////////////////////////////
  667. STDMETHODIMP
  668. CClusCfgCredentials::AssignFrom(
  669. IClusCfgCredentials * picccSourceIn
  670. )
  671. {
  672. TraceFunc( "[IClusCfgCredentials]" );
  673. HRESULT hr = S_OK;
  674. BSTR bstrName = NULL;
  675. BSTR bstrDomain = NULL;
  676. BSTR bstrPassword = NULL;
  677. hr = THR( picccSourceIn->GetCredentials( &bstrName, &bstrDomain, &bstrPassword ) );
  678. if ( FAILED( hr ) )
  679. {
  680. goto Cleanup;
  681. }
  682. hr = THR( m_encbstrPassword.HrSetBSTR( bstrPassword ) );
  683. if ( FAILED( hr ) )
  684. {
  685. goto Cleanup;
  686. }
  687. m_bstrAccountName = bstrName;
  688. TraceMemoryAddBSTR( m_bstrAccountName );
  689. bstrName = NULL;
  690. m_bstrAccountDomain = bstrDomain;
  691. TraceMemoryAddBSTR( m_bstrAccountDomain );
  692. bstrDomain = NULL;
  693. Cleanup:
  694. SysFreeString( bstrName );
  695. SysFreeString( bstrDomain );
  696. if ( bstrPassword != NULL )
  697. {
  698. CEncryptedBSTR::SecureZeroBSTR( bstrPassword );
  699. TraceSysFreeString( bstrPassword );
  700. }
  701. HRETURN( hr );
  702. } //*** CClusCfgCredentials::AssignFrom
  703. //*************************************************************************//
  704. /////////////////////////////////////////////////////////////////////////////
  705. // CClusCfgCredentials -- IClusCfgSetCredentials interface.
  706. /////////////////////////////////////////////////////////////////////////////
  707. //////////////////////////////////////////////////////////////////////////////
  708. //++
  709. //
  710. // CClusCfgCredentials::SetDomainCredentials
  711. //
  712. // Description:
  713. //
  714. // Arguments:
  715. // pcszCredentialsIn
  716. //
  717. // Return Value:
  718. // S_OK - Success.
  719. // E_INVALIDARG - Required input argument not specified
  720. // E_OUTOFMEMORY - Error allocating memory.
  721. // Other HRESULTs
  722. //
  723. //--
  724. //////////////////////////////////////////////////////////////////////////////
  725. STDMETHODIMP
  726. CClusCfgCredentials::SetDomainCredentials( LPCWSTR pcszCredentialsIn )
  727. {
  728. TraceFunc( "[IClusSetCfgCredentials]" );
  729. HRESULT hr = S_OK;
  730. WCHAR * pszBackslash = NULL;
  731. WCHAR * pszAtSign = NULL;
  732. BSTR bstrName = NULL;
  733. BSTR bstrDomain = NULL;
  734. if ( pcszCredentialsIn == NULL )
  735. {
  736. hr = THR( E_INVALIDARG );
  737. LogMsg( L"Server: CClusCfgCredentials::SetDomainCredentials() was given a NULL pointer argument." );
  738. goto Cleanup;
  739. } // if:
  740. pszBackslash = wcschr( pcszCredentialsIn, L'\\' );
  741. pszAtSign = wcschr( pcszCredentialsIn, L'@' );
  742. //
  743. // Are the credentials in domain\user format?
  744. //
  745. if ( pszBackslash != NULL )
  746. {
  747. *pszBackslash = L'\0';
  748. pszBackslash++;
  749. //
  750. // If no domain was specified (e.g. the account was specified in the
  751. // '\account' form), use the domain of the local machine.
  752. //
  753. if ( *pszBackslash == L'\0' )
  754. {
  755. //
  756. // A domain string was NOT specified in the credentials.
  757. //
  758. hr = THR( HrGetComputerName( ComputerNameDnsDomain, &bstrDomain, TRUE /*fBestEffortIn*/ ) );
  759. if ( FAILED( hr ) )
  760. {
  761. goto Cleanup;
  762. } // if: error getting the domain name
  763. } // if: no domain string was specified
  764. else
  765. {
  766. //
  767. // A domain string was specified in the credentials.
  768. //
  769. bstrDomain = TraceSysAllocString( pcszCredentialsIn );
  770. if ( bstrDomain == NULL )
  771. {
  772. hr = THR( E_OUTOFMEMORY );
  773. goto Cleanup;
  774. } // if:
  775. } // if: domain string was specified
  776. bstrName = TraceSysAllocString( pszBackslash );
  777. if ( bstrName == NULL )
  778. {
  779. hr = THR( E_OUTOFMEMORY );
  780. goto Cleanup;
  781. } // if:
  782. } // if: domain\user format
  783. else if ( pszAtSign != NULL )
  784. {
  785. //
  786. // Are the credentials in user@domain format?
  787. //
  788. *pszAtSign = L'\0';
  789. pszAtSign++;
  790. bstrName = TraceSysAllocString( pcszCredentialsIn );
  791. if ( bstrName == NULL )
  792. {
  793. hr = THR( E_OUTOFMEMORY );
  794. goto Cleanup;
  795. } // if:
  796. bstrDomain = TraceSysAllocString( pszAtSign );
  797. if ( bstrDomain == NULL )
  798. {
  799. hr = THR( E_OUTOFMEMORY );
  800. goto Cleanup;
  801. } // if:
  802. } // if: user@domain format
  803. else
  804. {
  805. //
  806. // Remember this as the user and get the FQDN for the local machine,
  807. // since this account is assumed to be an account local to this
  808. // machine.
  809. //
  810. bstrName = TraceSysAllocString( pcszCredentialsIn );
  811. if ( bstrName == NULL )
  812. {
  813. hr = THR( E_OUTOFMEMORY );
  814. goto Cleanup;
  815. } // if:
  816. hr = THR( HrGetComputerName(
  817. ComputerNameDnsFullyQualified
  818. , &bstrDomain
  819. , FALSE // fBestEffortIn
  820. ) );
  821. if ( FAILED( hr ) )
  822. {
  823. goto Cleanup;
  824. } // if: error getting the FQDN for the computer
  825. } // neither domain\user nor user@domain format
  826. TraceSysFreeString( m_bstrAccountName );
  827. m_bstrAccountName = bstrName;
  828. bstrName = NULL;
  829. TraceSysFreeString( m_bstrAccountDomain );
  830. m_bstrAccountDomain = bstrDomain;
  831. bstrDomain = NULL;
  832. Cleanup:
  833. TraceSysFreeString( bstrName );
  834. TraceSysFreeString( bstrDomain );
  835. HRETURN( hr );
  836. } //*** CClusCfgCredentials::SetDomainCredentials
  837. //*************************************************************************//
  838. /////////////////////////////////////////////////////////////////////////////
  839. // CClusCfgCredentials class -- Private Methods.
  840. /////////////////////////////////////////////////////////////////////////////
  841. //////////////////////////////////////////////////////////////////////////////
  842. //++
  843. //
  844. // CClusCfgCredentials::HrInit
  845. //
  846. // Description:
  847. // Initialize this component.
  848. //
  849. // Arguments:
  850. // None.
  851. //
  852. // Return Value:
  853. // S_OK - Success.
  854. //
  855. //--
  856. //////////////////////////////////////////////////////////////////////////////
  857. HRESULT
  858. CClusCfgCredentials::HrInit( void )
  859. {
  860. TraceFunc( "" );
  861. HRESULT hr = S_OK;
  862. HRETURN( hr );
  863. } //*** CClusCfgCredentials::HrInit