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.

746 lines
19 KiB

  1. //////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 2000-2001 Microsoft Corporation
  4. //
  5. // Module Name:
  6. // CreateServices.h
  7. //
  8. // Description:
  9. // CreateServices implementation.
  10. //
  11. // Maintained By:
  12. // Galen Barbee (GalenB) 14-JUN-2001
  13. // Geoffrey Pease (GPease) 15-JUN-2000
  14. //
  15. //////////////////////////////////////////////////////////////////////////////
  16. #include "Pch.h"
  17. #include "GroupHandle.h"
  18. #include "ResourceEntry.h"
  19. #include "IPrivatePostCfgResource.h"
  20. #include "CreateServices.h"
  21. DEFINE_THISCLASS("CCreateServices")
  22. // ************************************************************************
  23. //
  24. // Constructor / Destructor
  25. //
  26. // ************************************************************************
  27. //////////////////////////////////////////////////////////////////////////////
  28. //
  29. // HRESULT
  30. // CCreateServices::S_HrCreateInstance(
  31. // IUnknown ** ppunkOut
  32. // )
  33. //
  34. //////////////////////////////////////////////////////////////////////////////
  35. HRESULT
  36. CCreateServices::S_HrCreateInstance(
  37. IUnknown ** ppunkOut
  38. )
  39. {
  40. TraceFunc( "" );
  41. HRESULT hr = S_OK;
  42. CCreateServices * pcs = NULL;
  43. Assert( ppunkOut != NULL );
  44. if ( ppunkOut == NULL )
  45. {
  46. hr = THR( E_POINTER );
  47. goto Cleanup;
  48. } // if:
  49. pcs = new CCreateServices;
  50. if ( pcs == NULL )
  51. {
  52. hr = THR( E_OUTOFMEMORY );
  53. goto Cleanup;
  54. } // if:
  55. hr = THR( pcs->HrInit() );
  56. if ( FAILED( hr ) )
  57. {
  58. goto Cleanup;
  59. } // if:
  60. hr = THR( pcs->TypeSafeQI( IUnknown, ppunkOut ) );
  61. if ( FAILED( hr ) )
  62. {
  63. goto Cleanup;
  64. }
  65. Cleanup:
  66. if ( pcs != NULL )
  67. {
  68. pcs->Release();
  69. } // if:
  70. HRETURN( hr );
  71. } //*** CCreateServices::S_HrCreateInstance
  72. //////////////////////////////////////////////////////////////////////////////
  73. //
  74. // CCreateServices::CCreateServices
  75. //
  76. //////////////////////////////////////////////////////////////////////////////
  77. CCreateServices::CCreateServices( void )
  78. : m_cRef( 1 )
  79. {
  80. TraceFunc( "" );
  81. InterlockedIncrement( &g_cObjects );
  82. TraceFuncExit();
  83. } //*** CCreateServices::CCreateServices
  84. //////////////////////////////////////////////////////////////////////////////
  85. //
  86. // HRESULT
  87. // CCreateServices::HrInit
  88. //
  89. //////////////////////////////////////////////////////////////////////////////
  90. HRESULT
  91. CCreateServices::HrInit( void )
  92. {
  93. TraceFunc( "" );
  94. HRESULT hr = S_OK;
  95. // IUnknown
  96. Assert( m_cRef == 1 );
  97. // Resource
  98. Assert( m_presentry == NULL );
  99. HRETURN( hr );
  100. } //*** CCreateServices::HrInit
  101. //////////////////////////////////////////////////////////////////////////////
  102. //
  103. // CCreateServices::~CCreateServices
  104. //
  105. //////////////////////////////////////////////////////////////////////////////
  106. CCreateServices::~CCreateServices( void )
  107. {
  108. TraceFunc( "" );
  109. InterlockedDecrement( &g_cObjects );
  110. TraceFuncExit();
  111. } //*** CCreateServices::~CCreateServices
  112. //****************************************************************************
  113. //
  114. // IUnknown
  115. //
  116. //****************************************************************************
  117. //////////////////////////////////////////////////////////////////////////////
  118. //++
  119. //
  120. // CCreateServices::QueryInterface
  121. //
  122. // Description:
  123. // Query this object for the passed in interface.
  124. //
  125. // Arguments:
  126. // riidIn
  127. // Id of interface requested.
  128. //
  129. // ppvOut
  130. // Pointer to the requested interface.
  131. //
  132. // Return Value:
  133. // S_OK
  134. // If the interface is available on this object.
  135. //
  136. // E_NOINTERFACE
  137. // If the interface is not available.
  138. //
  139. // E_POINTER
  140. // ppvOut was NULL.
  141. //
  142. // Remarks:
  143. // None.
  144. //
  145. //--
  146. //////////////////////////////////////////////////////////////////////////////
  147. STDMETHODIMP
  148. CCreateServices::QueryInterface(
  149. REFIID riidIn
  150. , LPVOID * ppvOut
  151. )
  152. {
  153. TraceQIFunc( riidIn, ppvOut );
  154. HRESULT hr = S_OK;
  155. //
  156. // Validate arguments.
  157. //
  158. Assert( ppvOut != NULL );
  159. if ( ppvOut == NULL )
  160. {
  161. hr = THR( E_POINTER );
  162. goto Cleanup;
  163. }
  164. //
  165. // Handle known interfaces.
  166. //
  167. if ( IsEqualIID( riidIn, IID_IUnknown ) )
  168. {
  169. *ppvOut = static_cast< IClusCfgResourceCreate * >( this );
  170. } // if: IUnknown
  171. else if ( IsEqualIID( riidIn, IID_IClusCfgResourceCreate ) )
  172. {
  173. *ppvOut = TraceInterface( __THISCLASS__, IClusCfgResourceCreate, this, 0 );
  174. } // else if: IClusCfgResourceCreate
  175. else if ( IsEqualIID( riidIn, IID_IPrivatePostCfgResource ) )
  176. {
  177. *ppvOut = TraceInterface( __THISCLASS__, IPrivatePostCfgResource, this, 0 );
  178. } // else if: IPrivatePostCfgResource
  179. else
  180. {
  181. *ppvOut = NULL;
  182. hr = E_NOINTERFACE;
  183. }
  184. //
  185. // Add a reference to the interface if successful.
  186. //
  187. if ( SUCCEEDED( hr ) )
  188. {
  189. ((IUnknown *) *ppvOut)->AddRef();
  190. } // if: success
  191. Cleanup:
  192. QIRETURN_IGNORESTDMARSHALLING( hr, riidIn );
  193. } //*** CCreateServices::QueryInterface
  194. //////////////////////////////////////////////////////////////////////////////
  195. //
  196. // STDMETHODIMP_(ULONG)
  197. // CCreateServices::AddRef
  198. //
  199. //////////////////////////////////////////////////////////////////////////////
  200. STDMETHODIMP_( ULONG )
  201. CCreateServices::AddRef( void )
  202. {
  203. TraceFunc( "[IUnknown]" );
  204. InterlockedIncrement( &m_cRef );
  205. CRETURN( m_cRef );
  206. } //*** CCreateServices::AddRef
  207. //////////////////////////////////////////////////////////////////////////////
  208. //
  209. // STDMETHODIMP_(ULONG)
  210. // CCreateServices::Release
  211. //
  212. //////////////////////////////////////////////////////////////////////////////
  213. STDMETHODIMP_( ULONG )
  214. CCreateServices::Release( void )
  215. {
  216. TraceFunc( "[IUnknown]" );
  217. LONG cRef;
  218. cRef = InterlockedDecrement( &m_cRef );
  219. if ( cRef == 0 )
  220. {
  221. TraceDo( delete this );
  222. }
  223. CRETURN( cRef );
  224. } //*** CCreateServices::Release
  225. //****************************************************************************
  226. //
  227. // IClusCfgResourceCreate
  228. //
  229. //****************************************************************************
  230. //////////////////////////////////////////////////////////////////////////////
  231. //
  232. // STDMETHODIMP
  233. // CCreateServices::SetPropertyBinary(
  234. // LPCWSTR pcszNameIn
  235. // , const DWORD cbSizeIn
  236. // , const BYTE * pbyteIn
  237. // )
  238. //
  239. //////////////////////////////////////////////////////////////////////////////
  240. STDMETHODIMP
  241. CCreateServices::SetPropertyBinary(
  242. LPCWSTR pcszNameIn
  243. , const DWORD cbSizeIn
  244. , const BYTE * pbyteIn
  245. )
  246. {
  247. TraceFunc( "[IClusCfgResourceCreate]" );
  248. HRESULT hr = S_OK;
  249. CClusPropList cpl( TRUE ); // always add the property.
  250. DWORD sc;
  251. const BYTE * pPrevValue = NULL; // always have no previous value.
  252. DWORD cbPrevValue = 0;
  253. //
  254. // Parameter validation
  255. //
  256. if ( ( pcszNameIn == NULL ) || ( pbyteIn == NULL ) || ( cbSizeIn == 0 ) )
  257. {
  258. hr = THR( E_INVALIDARG );
  259. goto Cleanup;
  260. } // if:
  261. sc = TW32( cpl.ScAddProp( pcszNameIn, pbyteIn, cbSizeIn, pPrevValue, cbPrevValue ) );
  262. if ( sc != ERROR_SUCCESS )
  263. {
  264. hr = HRESULT_FROM_WIN32( sc );
  265. goto Cleanup;
  266. } // if:
  267. hr = THR( m_presentry->StoreClusterResourceControl( CLUSCTL_RESOURCE_SET_PRIVATE_PROPERTIES, cpl ) );
  268. Cleanup:
  269. HRETURN( hr );
  270. } //*** CCreateServices::SetPropertyBinary
  271. //////////////////////////////////////////////////////////////////////////////
  272. //
  273. // STDMETHODIMP
  274. // CCreateServices::SetPropertyDWORD(
  275. // LPCWSTR pcszNameIn,
  276. // const DWORD dwDWORDIn
  277. // )
  278. //
  279. //////////////////////////////////////////////////////////////////////////////
  280. STDMETHODIMP
  281. CCreateServices::SetPropertyDWORD( LPCWSTR pcszNameIn, const DWORD dwDWORDIn )
  282. {
  283. TraceFunc( "[IClusCfgResourceCreate]" );
  284. HRESULT hr = S_OK;
  285. CClusPropList cpl( TRUE ); // always add the property.
  286. DWORD sc;
  287. DWORD nPrevValue = 0; // always have no previous value.
  288. //
  289. // Parameter validation
  290. //
  291. if ( pcszNameIn == NULL )
  292. {
  293. hr = THR( E_INVALIDARG );
  294. goto Cleanup;
  295. } // if:
  296. sc = TW32( cpl.ScAddProp( pcszNameIn, dwDWORDIn, nPrevValue ) );
  297. if ( sc != ERROR_SUCCESS )
  298. {
  299. hr = HRESULT_FROM_WIN32( sc );
  300. goto Cleanup;
  301. } // if:
  302. hr = THR( m_presentry->StoreClusterResourceControl( CLUSCTL_RESOURCE_SET_PRIVATE_PROPERTIES, cpl ) );
  303. Cleanup:
  304. HRETURN( hr );
  305. } //*** CCreateServices::SetPropertyDWORD
  306. //////////////////////////////////////////////////////////////////////////////
  307. //
  308. // STDMETHODIMP
  309. // CCreateServices::SetPropertyString(
  310. // LPCWSTR pcszNameIn
  311. // , LPCWSTR pcszStringIn
  312. // )
  313. //
  314. //////////////////////////////////////////////////////////////////////////////
  315. STDMETHODIMP
  316. CCreateServices::SetPropertyString(
  317. LPCWSTR pcszNameIn
  318. , LPCWSTR pcszStringIn
  319. )
  320. {
  321. TraceFunc( "[IClusCfgResourceCreate]" );
  322. HRESULT hr = S_OK;
  323. CClusPropList cpl( TRUE ); // always add the property.
  324. DWORD sc;
  325. LPCWSTR pPrevValue = NULL; // always have no previous value.
  326. //
  327. // Parameter validation
  328. //
  329. if ( ( pcszNameIn == NULL ) || ( pcszStringIn == NULL ) )
  330. {
  331. hr = THR( E_INVALIDARG );
  332. goto Cleanup;
  333. } // if:
  334. sc = TW32( cpl.ScAddProp( pcszNameIn, pcszStringIn, pPrevValue ) );
  335. if ( sc != ERROR_SUCCESS )
  336. {
  337. hr = HRESULT_FROM_WIN32( sc );
  338. goto Cleanup;
  339. } // if:
  340. hr = THR( m_presentry->StoreClusterResourceControl( CLUSCTL_RESOURCE_SET_PRIVATE_PROPERTIES, cpl ) );
  341. Cleanup:
  342. HRETURN( hr );
  343. } //*** CCreateServices::SetPropertyString
  344. //////////////////////////////////////////////////////////////////////////////
  345. //
  346. // STDMETHODIMP
  347. // CCreateServices::SetPropertyExpandString(
  348. // LPCWSTR pcszNameIn
  349. // , LPCWSTR pcszStringIn
  350. // )
  351. //
  352. //////////////////////////////////////////////////////////////////////////////
  353. STDMETHODIMP
  354. CCreateServices::SetPropertyExpandString(
  355. LPCWSTR pcszNameIn
  356. , LPCWSTR pcszStringIn
  357. )
  358. {
  359. TraceFunc( "[IClusCfgResourceCreate]" );
  360. HRESULT hr = S_OK;
  361. CClusPropList cpl( TRUE ); // always add the property.
  362. DWORD sc;
  363. LPCWSTR pPrevValue = NULL; // always have no previous value.
  364. //
  365. // Parameter validation
  366. //
  367. if ( ( pcszNameIn == NULL ) || ( pcszStringIn == NULL ) )
  368. {
  369. hr = THR( E_INVALIDARG );
  370. goto Cleanup;
  371. } // if:
  372. sc = TW32( cpl.ScAddExpandSzProp( pcszNameIn, pcszStringIn, pPrevValue ) );
  373. if ( sc != ERROR_SUCCESS )
  374. {
  375. hr = HRESULT_FROM_WIN32( sc );
  376. goto Cleanup;
  377. } // if:
  378. hr = THR( m_presentry->StoreClusterResourceControl( CLUSCTL_RESOURCE_SET_PRIVATE_PROPERTIES, cpl ) );
  379. Cleanup:
  380. HRETURN( hr );
  381. } //*** CCreateServices::SetPropertyExpandString
  382. //////////////////////////////////////////////////////////////////////////////
  383. //
  384. // STDMETHODIMP
  385. // CCreateServices::SetPropertyMultiString(
  386. // LPCWSTR pcszNameIn
  387. // , const DWORD cbSizeIn
  388. // , LPCWSTR pcszStringIn
  389. // )
  390. //
  391. //////////////////////////////////////////////////////////////////////////////
  392. STDMETHODIMP
  393. CCreateServices::SetPropertyMultiString(
  394. LPCWSTR pcszNameIn
  395. , const DWORD cbSizeIn
  396. , LPCWSTR pcszStringIn
  397. )
  398. {
  399. TraceFunc( "[IClusCfgResourceCreate]" );
  400. HRESULT hr = S_OK;
  401. CClusPropList cpl( TRUE ); // always add the property.
  402. DWORD sc;
  403. LPCWSTR pPrevValue = NULL; // always have no previous value.
  404. //
  405. // Parameter validation
  406. //
  407. if ( ( pcszNameIn == NULL ) || ( pcszStringIn == NULL ) || ( cbSizeIn == 0 ) )
  408. {
  409. hr = THR( E_INVALIDARG );
  410. goto Cleanup;
  411. } // if:
  412. sc = TW32( cpl.ScAddMultiSzProp( pcszNameIn, pcszStringIn, pPrevValue ) );
  413. if ( sc != ERROR_SUCCESS )
  414. {
  415. hr = HRESULT_FROM_WIN32( sc );
  416. goto Cleanup;
  417. } // if:
  418. hr = THR( m_presentry->StoreClusterResourceControl( CLUSCTL_RESOURCE_SET_PRIVATE_PROPERTIES, cpl ) );
  419. Cleanup:
  420. HRETURN( hr );
  421. } //*** CCreateServices::SetPropertyMultiString
  422. //////////////////////////////////////////////////////////////////////////////
  423. //
  424. // STDMETHODIMP
  425. // CCreateServices::SetPropertyUnsignedLargeInt(
  426. // LPCWSTR pcszNameIn
  427. // , const ULARGE_INTEGER ulIntIn
  428. // )
  429. //
  430. //////////////////////////////////////////////////////////////////////////////
  431. STDMETHODIMP
  432. CCreateServices::SetPropertyUnsignedLargeInt(
  433. LPCWSTR pcszNameIn
  434. , const ULARGE_INTEGER ulIntIn
  435. )
  436. {
  437. TraceFunc( "[IClusCfgResourceCreate]" );
  438. HRESULT hr = S_OK;
  439. CClusPropList cpl( TRUE ); // always add the property.
  440. DWORD sc;
  441. ULONGLONG ullPrevValue = 0; // always have no previous value.
  442. //
  443. // Parameter validation
  444. //
  445. if ( pcszNameIn == NULL )
  446. {
  447. hr = THR( E_INVALIDARG );
  448. goto Cleanup;
  449. } // if:
  450. sc = TW32( cpl.ScAddProp( pcszNameIn, ulIntIn.QuadPart, ullPrevValue ) );
  451. if ( sc != ERROR_SUCCESS )
  452. {
  453. hr = HRESULT_FROM_WIN32( sc );
  454. goto Cleanup;
  455. } // if:
  456. hr = THR( m_presentry->StoreClusterResourceControl( CLUSCTL_RESOURCE_SET_PRIVATE_PROPERTIES, cpl ) );
  457. Cleanup:
  458. HRETURN( hr );
  459. } //*** CCreateServices::SetPropertyUnsignedLargeInt
  460. //////////////////////////////////////////////////////////////////////////////
  461. //
  462. // STDMETHODIMP
  463. // CCreateServices::SetPropertyLong(
  464. // LPCWSTR pcszNameIn
  465. // , const LONG lLongIn
  466. // )
  467. //
  468. //////////////////////////////////////////////////////////////////////////////
  469. STDMETHODIMP
  470. CCreateServices::SetPropertyLong(
  471. LPCWSTR pcszNameIn
  472. , const LONG lLongIn
  473. )
  474. {
  475. TraceFunc( "[IClusCfgResourceCreate]" );
  476. HRESULT hr = S_OK;
  477. CClusPropList cpl( TRUE ); // always add the property.
  478. DWORD sc;
  479. LONG lPrevValue = 0; // always have no previous value.
  480. //
  481. // Parameter validation
  482. //
  483. if ( pcszNameIn == NULL )
  484. {
  485. hr = THR( E_INVALIDARG );
  486. goto Cleanup;
  487. } // if:
  488. sc = TW32( cpl.ScAddProp( pcszNameIn, lLongIn, lPrevValue ) );
  489. if ( sc != ERROR_SUCCESS )
  490. {
  491. hr = HRESULT_FROM_WIN32( sc );
  492. goto Cleanup;
  493. } // if:
  494. hr = THR( m_presentry->StoreClusterResourceControl( CLUSCTL_RESOURCE_SET_PRIVATE_PROPERTIES, cpl ) );
  495. Cleanup:
  496. HRETURN( hr );
  497. } //*** CCreateServices::SetPropertyLong
  498. //////////////////////////////////////////////////////////////////////////////
  499. //
  500. // STDMETHODIMP
  501. // CCreateServices::SetPropertySecurityDescriptor(
  502. // LPCWSTR pcszNameIn,
  503. // const SECURITY_DESCRIPTOR * pcsdIn
  504. // )
  505. //
  506. //////////////////////////////////////////////////////////////////////////////
  507. STDMETHODIMP
  508. CCreateServices::SetPropertySecurityDescriptor(
  509. LPCWSTR pcszNameIn,
  510. const SECURITY_DESCRIPTOR * pcsdIn
  511. )
  512. {
  513. TraceFunc( "[IClusCfgResourceCreate]" );
  514. HRESULT hr = THR( E_NOTIMPL );
  515. HRETURN( hr );
  516. } //*** CCreateServices::SetPropertySecurityDescriptor
  517. //////////////////////////////////////////////////////////////////////////////
  518. //
  519. // STDMETHODIMP
  520. // CCreateServices::SetPropertyLargeInt(
  521. // LPCWSTR pcszNameIn
  522. // , const LARGE_INTEGER lIntIn
  523. // )
  524. //
  525. //////////////////////////////////////////////////////////////////////////////
  526. STDMETHODIMP
  527. CCreateServices::SetPropertyLargeInt(
  528. LPCWSTR pcszNameIn
  529. , const LARGE_INTEGER lIntIn
  530. )
  531. {
  532. TraceFunc( "[IClusCfgResourceCreate]" );
  533. HRESULT hr = S_OK;
  534. CClusPropList cpl( TRUE ); // always add the property.
  535. DWORD sc;
  536. LONGLONG llPrevValue = 0; // always have no previous value.
  537. //
  538. // Parameter validation
  539. //
  540. if ( pcszNameIn == NULL )
  541. {
  542. hr = THR( E_INVALIDARG );
  543. goto Cleanup;
  544. } // if:
  545. sc = TW32( cpl.ScAddProp( pcszNameIn, lIntIn.QuadPart, llPrevValue ) );
  546. if ( sc != ERROR_SUCCESS )
  547. {
  548. hr = HRESULT_FROM_WIN32( sc );
  549. goto Cleanup;
  550. } // if:
  551. hr = THR( m_presentry->StoreClusterResourceControl( CLUSCTL_RESOURCE_SET_PRIVATE_PROPERTIES, cpl ) );
  552. Cleanup:
  553. HRETURN( hr );
  554. } //*** CCreateServices::SetPropertyLargeInt
  555. //////////////////////////////////////////////////////////////////////////////
  556. //
  557. // STDMETHODIMP
  558. // CCreateServices::SendResourceControl(
  559. // DWORD dwControlCode,
  560. // LPVOID lpInBuffer,
  561. // DWORD cbInBufferSize
  562. // )
  563. //
  564. //////////////////////////////////////////////////////////////////////////////
  565. STDMETHODIMP
  566. CCreateServices::SendResourceControl(
  567. DWORD dwControlCode,
  568. LPVOID lpInBuffer,
  569. DWORD cbInBufferSize
  570. )
  571. {
  572. TraceFunc( "[IClusCfgResourceCreate]" );
  573. HRESULT hr = S_OK;
  574. CClusPropList cpl( TRUE ); // always add the property.
  575. DWORD sc;
  576. sc = TW32( cpl.ScCopy( (PCLUSPROP_LIST) lpInBuffer, cbInBufferSize ) );
  577. if ( sc != ERROR_SUCCESS )
  578. {
  579. hr = HRESULT_FROM_WIN32( sc );
  580. goto Cleanup;
  581. } // if:
  582. hr = THR( m_presentry->StoreClusterResourceControl( dwControlCode, cpl ) );
  583. Cleanup:
  584. HRETURN( hr );
  585. } //*** CCreateServices::SendResourceControl
  586. //****************************************************************************
  587. //
  588. // IPrivatePostCfgResource
  589. //
  590. //****************************************************************************
  591. //////////////////////////////////////////////////////////////////////////////
  592. //
  593. // STDMETHODIMP
  594. // CCreateServices::SetEntry(
  595. // CResourceEntry * presentryIn
  596. // )
  597. //
  598. //////////////////////////////////////////////////////////////////////////////
  599. STDMETHODIMP
  600. CCreateServices::SetEntry(
  601. CResourceEntry * presentryIn
  602. )
  603. {
  604. TraceFunc( "[IPrivatePostCfgResource]" );
  605. HRESULT hr = S_OK;
  606. Assert( presentryIn != NULL );
  607. m_presentry = presentryIn;
  608. HRETURN( hr );
  609. } //*** CCreateServices::SetEntry