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.

748 lines
18 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1997-1998
  5. //
  6. // File: ScopeAdm.cxx
  7. //
  8. // Contents: CI Scope Administration Interface methods
  9. //
  10. // Classes: CScopeAdm
  11. //
  12. // History: 12-10-97 mohamedn created
  13. //
  14. //----------------------------------------------------------------------------
  15. #include "pch.cxx"
  16. #pragma hdrstop
  17. #include "stdafx.h"
  18. //+---------------------------------------------------------------------------
  19. //
  20. // Member: CScopeAdm::InterfaceSupportsErrorInfo, public
  21. //
  22. // Arguments: [riid] -- interface iid
  23. //
  24. // Returns: S_OK if interface supports IErrorInfo
  25. //
  26. // History: 12-10-97 mohamedn created
  27. //
  28. //----------------------------------------------------------------------------
  29. STDMETHODIMP CScopeAdm::InterfaceSupportsErrorInfo(REFIID riid)
  30. {
  31. return ( riid == IID_IScopeAdm );
  32. }
  33. //+---------------------------------------------------------------------------
  34. //
  35. // Member: CScopeAdm::SetErrorInfo, public
  36. //
  37. // Synopsis: Creates & sets the error object
  38. //
  39. // Arguments: [hRes] -- HRESULT error code to set
  40. // [ pwszDesc] -- error description
  41. //
  42. // Returns: S_OK upon success, other values upon failure
  43. //
  44. // History: 12-10-97 mohamedn created
  45. //
  46. //----------------------------------------------------------------------------
  47. void CScopeAdm::SetErrorInfo( HRESULT hRes )
  48. {
  49. CiodmError err(hRes);
  50. AtlSetErrorInfo(CLSID_ScopeAdm, err.GetErrorMessage(), 0 , 0, IID_IScopeAdm, hRes, 0 );
  51. }
  52. //+---------------------------------------------------------------------------
  53. //
  54. // Member: CScopeAdm::Initialize, public
  55. //
  56. // Synopsis: Initializes CScopeAdm object
  57. //
  58. // Arguments: [xScopeAdmin] -- CScopeAdmin to encapsulate.
  59. //
  60. // History: 12-10-97 mohamedn created
  61. //
  62. //----------------------------------------------------------------------------
  63. void CScopeAdm::Initialize( XPtr<CScopeAdmin> & xScopeAdmin )
  64. {
  65. Win4Assert( _pICatAdm );
  66. Win4Assert( !xScopeAdmin.IsNull() );
  67. _xScopeAdmin.Set( xScopeAdmin.Acquire() );
  68. _fValid = TRUE;
  69. }
  70. //+---------------------------------------------------------------------------
  71. //
  72. // Member: CScopeAdm::InternalAddRef, public
  73. //
  74. // Synopsis: overrides CComObjectRootEx<Base>::InternalAddRef, to AddRef parent too
  75. //
  76. // Arguments: none
  77. //
  78. // History: 12-10-97 mohamedn created
  79. //
  80. //----------------------------------------------------------------------------
  81. ULONG CScopeAdm::InternalAddRef()
  82. {
  83. CLock lock(_mtx);
  84. //
  85. // AddRef self
  86. //
  87. unsigned cRef = CComObjectRootEx<CComMultiThreadModel>::InternalAddRef();
  88. odmDebugOut(( DEB_TRACE,"CScopeAdm(%ws) AddRef returned: %d\n",
  89. _xScopeAdmin.IsNull() ? L"" : _xScopeAdmin->GetPath(), cRef ));
  90. //
  91. // AddRef parent. It won't exist if the object is created independently
  92. //
  93. if ( 0 != _pICatAdm )
  94. _pICatAdm->AddRef();
  95. return cRef;
  96. } //InternalAddRef
  97. //+---------------------------------------------------------------------------
  98. //
  99. // Member: CScopeAdm::InternalRelease, public
  100. //
  101. // Synopsis: overrides CComObjectRootEx<Base>::InternalRelease, to release parent too.
  102. //
  103. // Arguments: none
  104. //
  105. // History: 12-10-97 mohamedn created
  106. //
  107. //----------------------------------------------------------------------------
  108. ULONG CScopeAdm::InternalRelease()
  109. {
  110. CLock lock(_mtx);
  111. //
  112. // Rlease parent
  113. //
  114. if ( ( 0 != _pICatAdm ) &&
  115. ( 1 == m_dwRef ) ) // we're being deleted
  116. {
  117. _pICatAdm->DecObjectCount();
  118. }
  119. //
  120. // Release self
  121. //
  122. unsigned cRef = CComObjectRootEx<CComMultiThreadModel>::InternalRelease();
  123. if ( 0 != _pICatAdm )
  124. _pICatAdm->Release();
  125. return cRef;
  126. } //InternalRelease
  127. //+---------------------------------------------------------------------------
  128. //
  129. // Member: CScopeAdm::Rescan, public
  130. //
  131. // Synopsis: Forces a rescan
  132. //
  133. // Arguments: [fFull] -- TRUE --> full rescan, FALSE --> incremental
  134. //
  135. // Returns: S_OK upon success, other values upon failure
  136. //
  137. // History: 12-10-97 mohamedn created
  138. //
  139. //----------------------------------------------------------------------------
  140. STDMETHODIMP CScopeAdm::Rescan(VARIANT_BOOL fFull)
  141. {
  142. SCODE sc = S_OK;
  143. CLock lock(_mtx);
  144. TRANSLATE_EXCEPTIONS;
  145. TRY
  146. {
  147. SafeForScripting();
  148. if ( !_fValid )
  149. {
  150. odmDebugOut(( DEB_ERROR, "Invalid Scope: %ws\n", _xScopeAdmin->GetPath() ));
  151. sc = HRESULT_FROM_WIN32( ERROR_INVALID_STATE );
  152. }
  153. else
  154. {
  155. CCatalogAdmin * pCatalogAdmin = _pICatAdm->GetCatalogAdmin();
  156. Win4Assert( pCatalogAdmin );
  157. sc = UpdateContentIndex( _xScopeAdmin->GetPath(), // root of scope to scan for updates
  158. pCatalogAdmin->GetName(), // catalog name
  159. pCatalogAdmin->GetMachName(),// machine name
  160. fFull );
  161. }
  162. }
  163. CATCH( CException, e )
  164. {
  165. sc = e.GetErrorCode();
  166. }
  167. END_CATCH
  168. UNTRANSLATE_EXCEPTIONS;
  169. if ( FAILED(sc) )
  170. {
  171. odmDebugOut(( DEB_ERROR, "Rescan Failed: %x\n",sc ));
  172. SetErrorInfo( sc );
  173. }
  174. return sc;
  175. }
  176. //+---------------------------------------------------------------------------
  177. //
  178. // Member: CScopeAdm::SetLogonInfo, public
  179. //
  180. // Synopsis: Sets Logon Name/password
  181. //
  182. // Arguments: [bstrLogon] -- Logon name
  183. // [bstrPassword] -- password
  184. //
  185. // Returns: S_OK upon success, other values upon failure
  186. //
  187. // History: 12-10-97 mohamedn created
  188. //
  189. //----------------------------------------------------------------------------
  190. STDMETHODIMP CScopeAdm::SetLogonInfo( BSTR bstrLogon, BSTR bstrPassword )
  191. {
  192. SCODE sc = S_OK;
  193. CLock lock(_mtx);
  194. TRANSLATE_EXCEPTIONS;
  195. TRY
  196. {
  197. SafeForScripting();
  198. ValidateInputParam( bstrLogon );
  199. ValidateInputParam( bstrPassword );
  200. if ( !_fValid )
  201. {
  202. odmDebugOut(( DEB_ERROR, "Invalid Scope: %ws\n", _xScopeAdmin->GetPath() ));
  203. sc = HRESULT_FROM_WIN32( ERROR_INVALID_STATE );
  204. }
  205. else
  206. {
  207. CCatalogAdmin * pCatalogAdmin = _pICatAdm->GetCatalogAdmin();
  208. WCHAR const * pwszPath = _xScopeAdmin->GetPath();
  209. Win4Assert( pCatalogAdmin );
  210. Win4Assert( pwszPath );
  211. if ( pwszPath[1] == L':' )
  212. {
  213. odmDebugOut(( DEB_ERROR, "Can't set Logon info for local drives\n" ));
  214. sc = E_INVALIDARG;
  215. }
  216. else if ( bstrLogon && *bstrLogon )
  217. {
  218. _xScopeAdmin->SetLogonInfo( bstrLogon, bstrPassword, *pCatalogAdmin );
  219. }
  220. else
  221. {
  222. odmDebugOut(( DEB_ERROR, "invalid logon arguments\n" ));
  223. sc = E_INVALIDARG;
  224. }
  225. }
  226. }
  227. CATCH( CException, e )
  228. {
  229. sc = e.GetErrorCode();
  230. }
  231. END_CATCH
  232. UNTRANSLATE_EXCEPTIONS;
  233. if ( FAILED(sc) )
  234. {
  235. odmDebugOut(( DEB_ERROR, "SetLogonInfo Failed: %x\n",sc ));
  236. SetErrorInfo( sc );
  237. }
  238. return sc;
  239. }
  240. //+---------------------------------------------------------------------------
  241. //
  242. // Member: CScopeAdm::get_Path, public
  243. //
  244. // Synopsis: Gets the scope path Property
  245. //
  246. // Arguments: [pVal] -- out param, buffer containing scope path
  247. //
  248. // Returns: S_OK upon success, other values upon failure.
  249. //
  250. // History: 12-10-97 mohamedn created
  251. //
  252. //----------------------------------------------------------------------------
  253. STDMETHODIMP CScopeAdm::get_Path(BSTR * pVal)
  254. {
  255. SCODE sc = S_OK;
  256. CLock lock(_mtx);
  257. TRANSLATE_EXCEPTIONS;
  258. TRY
  259. {
  260. SafeForScripting();
  261. if ( !_fValid )
  262. {
  263. odmDebugOut(( DEB_ERROR, "Invalid Scope: %ws\n", _xScopeAdmin->GetPath() ));
  264. sc = HRESULT_FROM_WIN32( ERROR_INVALID_STATE );
  265. }
  266. else
  267. {
  268. WCHAR const * pwszPath = _xScopeAdmin->GetPath();
  269. *pVal = SysAllocString(pwszPath);
  270. if ( !*pVal )
  271. {
  272. sc = E_OUTOFMEMORY;
  273. }
  274. }
  275. }
  276. CATCH( CException, e )
  277. {
  278. sc = e.GetErrorCode();
  279. }
  280. END_CATCH
  281. UNTRANSLATE_EXCEPTIONS;
  282. if ( FAILED(sc) )
  283. {
  284. odmDebugOut(( DEB_ERROR, "get_PathRescan Failed: %x\n",sc ));
  285. SetErrorInfo( sc );
  286. }
  287. return sc;
  288. }
  289. //+---------------------------------------------------------------------------
  290. //
  291. // Member: CScopeAdm::put_Path, public
  292. //
  293. // Synopsis: Sets the scope path Property
  294. //
  295. // Arguments: [newVal] -- in param, buffer containing scope path
  296. //
  297. // Returns: S_OK upon success, other values upon failure.
  298. //
  299. // History: 12-10-97 mohamedn created
  300. //
  301. //----------------------------------------------------------------------------
  302. STDMETHODIMP CScopeAdm::put_Path(BSTR newVal)
  303. {
  304. SCODE sc = S_OK;
  305. CLock lock(_mtx);
  306. TRANSLATE_EXCEPTIONS;
  307. TRY
  308. {
  309. SafeForScripting();
  310. ValidateInputParam( newVal );
  311. if ( !_fValid )
  312. {
  313. odmDebugOut(( DEB_ERROR, "Invalid Scope: %ws\n", _xScopeAdmin->GetPath() ));
  314. sc = HRESULT_FROM_WIN32( ERROR_INVALID_STATE );
  315. }
  316. else
  317. {
  318. if ( _xScopeAdmin->IsVirtual() )
  319. {
  320. odmDebugOut(( DEB_ERROR, "Can't change virtual path, must use IIS\n" ));
  321. sc = HRESULT_FROM_WIN32(ERROR_INVALID_FUNCTION);
  322. }
  323. else
  324. {
  325. _xScopeAdmin->SetPath(newVal);
  326. }
  327. }
  328. }
  329. CATCH( CException, e )
  330. {
  331. sc = e.GetErrorCode();
  332. }
  333. END_CATCH
  334. UNTRANSLATE_EXCEPTIONS;
  335. if ( FAILED(sc) )
  336. {
  337. odmDebugOut(( DEB_ERROR, "put_PathRescan Failed: %x\n",sc ));
  338. SetErrorInfo( sc );
  339. }
  340. return sc;
  341. }
  342. //+---------------------------------------------------------------------------
  343. //
  344. // Member: CScopeAdm::get_Alias, public
  345. //
  346. // Synopsis: Gets the scope Alias Property
  347. //
  348. // Arguments: [pVal] -- out param, buffer containing scope Alias
  349. //
  350. // Returns: S_OK upon success, other values upon failure.
  351. //
  352. // History: 12-10-97 mohamedn created
  353. //
  354. //----------------------------------------------------------------------------
  355. STDMETHODIMP CScopeAdm::get_Alias(BSTR * pVal)
  356. {
  357. SCODE sc = S_OK;
  358. CLock lock(_mtx);
  359. TRANSLATE_EXCEPTIONS;
  360. TRY
  361. {
  362. SafeForScripting();
  363. if ( !_fValid )
  364. {
  365. odmDebugOut(( DEB_ERROR, "Invalid Scope: %ws\n", _xScopeAdmin->GetPath() ));
  366. sc = HRESULT_FROM_WIN32( ERROR_INVALID_STATE );
  367. }
  368. else
  369. {
  370. WCHAR const * pwszAlias = _xScopeAdmin->GetAlias();
  371. *pVal = SysAllocString(pwszAlias);
  372. if ( !*pVal )
  373. {
  374. sc = E_OUTOFMEMORY;
  375. }
  376. }
  377. }
  378. CATCH( CException, e )
  379. {
  380. sc = e.GetErrorCode();
  381. }
  382. END_CATCH
  383. UNTRANSLATE_EXCEPTIONS;
  384. if ( FAILED(sc) )
  385. {
  386. odmDebugOut(( DEB_ERROR, "get_Alias Failed: %x\n",sc ));
  387. SetErrorInfo( sc );
  388. }
  389. return sc;
  390. }
  391. //+---------------------------------------------------------------------------
  392. //
  393. // Member: CScopeAdm::put_Alias , public
  394. //
  395. // Synopsis: Sets the scope alias Property
  396. //
  397. // Arguments: [newVal] -- in param, buffer containing scope alias
  398. //
  399. // Returns: S_OK upon success, other values upon failure.
  400. //
  401. // History: 12-10-97 mohamedn created
  402. //
  403. //----------------------------------------------------------------------------
  404. STDMETHODIMP CScopeAdm::put_Alias(BSTR newVal)
  405. {
  406. SCODE sc = S_OK;
  407. CLock lock(_mtx);
  408. TRANSLATE_EXCEPTIONS;
  409. TRY
  410. {
  411. SafeForScripting();
  412. ValidateInputParam( newVal );
  413. if ( !_fValid )
  414. {
  415. odmDebugOut(( DEB_ERROR, "Invalid Scope: %ws\n", _xScopeAdmin->GetPath() ));
  416. sc = HRESULT_FROM_WIN32( ERROR_INVALID_STATE );
  417. }
  418. else
  419. {
  420. _xScopeAdmin->SetAlias(newVal);
  421. }
  422. }
  423. CATCH( CException, e )
  424. {
  425. sc = e.GetErrorCode();
  426. }
  427. END_CATCH
  428. UNTRANSLATE_EXCEPTIONS;
  429. if ( FAILED(sc) )
  430. {
  431. odmDebugOut(( DEB_ERROR, "put_Alias Failed: %x\n",sc ));
  432. SetErrorInfo( sc );
  433. }
  434. return sc;
  435. }
  436. //+---------------------------------------------------------------------------
  437. //
  438. // Member: CScopeAdm::get_ExcludeScope, public
  439. //
  440. // Synopsis: Gets the exclude scope Property
  441. //
  442. // Arguments: [pVal] -- out param, containing exclude scope flag
  443. //
  444. // Returns: S_OK upon success, other values upon failure.
  445. //
  446. // History: 12-10-97 mohamedn created
  447. //
  448. //----------------------------------------------------------------------------
  449. STDMETHODIMP CScopeAdm::get_ExcludeScope(VARIANT_BOOL * pVal)
  450. {
  451. SCODE sc = S_OK;
  452. CLock lock(_mtx);
  453. TRANSLATE_EXCEPTIONS;
  454. TRY
  455. {
  456. SafeForScripting();
  457. if ( !_fValid )
  458. {
  459. odmDebugOut(( DEB_ERROR, "Invalid Scope: %ws\n", _xScopeAdmin->GetPath() ));
  460. sc = HRESULT_FROM_WIN32( ERROR_INVALID_STATE );
  461. }
  462. else
  463. {
  464. *pVal = (SHORT)_xScopeAdmin->IsExclude();
  465. }
  466. }
  467. CATCH( CException, e )
  468. {
  469. sc = e.GetErrorCode();
  470. }
  471. END_CATCH
  472. UNTRANSLATE_EXCEPTIONS;
  473. if ( FAILED(sc) )
  474. {
  475. odmDebugOut(( DEB_ERROR, "get_ExcludeScope Failed: %x\n",sc ));
  476. SetErrorInfo( sc );
  477. }
  478. return sc;
  479. }
  480. //+---------------------------------------------------------------------------
  481. //
  482. // Member: CScopeAdm::put_ExcludeScope , public
  483. //
  484. // Synopsis: Sets the scope Exclude flag Property
  485. //
  486. // Arguments: [newVal] -- in param, Exclude scope flag to set
  487. //
  488. // Returns: S_OK upon success, other values upon failure.
  489. //
  490. // History: 12-10-97 mohamedn created
  491. //
  492. //----------------------------------------------------------------------------
  493. STDMETHODIMP CScopeAdm::put_ExcludeScope(VARIANT_BOOL newVal)
  494. {
  495. SCODE sc = S_OK;
  496. CLock lock(_mtx);
  497. TRANSLATE_EXCEPTIONS;
  498. TRY
  499. {
  500. SafeForScripting();
  501. if ( !_fValid )
  502. {
  503. odmDebugOut(( DEB_ERROR, "Invalid Scope: %ws\n", _xScopeAdmin->GetPath() ));
  504. sc = HRESULT_FROM_WIN32( ERROR_INVALID_STATE );
  505. }
  506. else
  507. {
  508. _xScopeAdmin->SetExclude(newVal);
  509. }
  510. }
  511. CATCH( CException, e )
  512. {
  513. sc = e.GetErrorCode();
  514. }
  515. END_CATCH
  516. UNTRANSLATE_EXCEPTIONS;
  517. if ( FAILED(sc) )
  518. {
  519. odmDebugOut(( DEB_ERROR, "put_ExcludeScope Failed: %x\n",sc ));
  520. SetErrorInfo( sc );
  521. }
  522. return sc;
  523. }
  524. //+---------------------------------------------------------------------------
  525. //
  526. // Member: CScopeAdm::get_VirtualScope, public
  527. //
  528. // Synopsis: Gets the VirtualScope property
  529. //
  530. // Arguments: [pVal] -- out param, containing VirtualScope flag
  531. //
  532. // Returns: S_OK upon success, other values upon failure.
  533. //
  534. // History: 12-10-97 mohamedn created
  535. //
  536. //----------------------------------------------------------------------------
  537. STDMETHODIMP CScopeAdm::get_VirtualScope(VARIANT_BOOL * pVal)
  538. {
  539. SCODE sc = S_OK;
  540. CLock lock(_mtx);
  541. TRANSLATE_EXCEPTIONS;
  542. TRY
  543. {
  544. SafeForScripting();
  545. if ( !_fValid )
  546. {
  547. odmDebugOut(( DEB_ERROR, "Invalid Scope: %ws\n", _xScopeAdmin->GetPath() ));
  548. sc = HRESULT_FROM_WIN32( ERROR_INVALID_STATE );
  549. }
  550. else
  551. {
  552. *pVal = (SHORT)_xScopeAdmin->IsVirtual();
  553. }
  554. }
  555. CATCH( CException, e )
  556. {
  557. sc = e.GetErrorCode();
  558. }
  559. END_CATCH
  560. UNTRANSLATE_EXCEPTIONS;
  561. if ( FAILED(sc) )
  562. {
  563. odmDebugOut(( DEB_ERROR, "get_VirtualScope Failed: %x\n",sc ));
  564. SetErrorInfo( sc );
  565. }
  566. return sc;
  567. }
  568. //+---------------------------------------------------------------------------
  569. //
  570. // Member: CScopeAdm::get_Logon, public
  571. //
  572. // Synopsis: Gets the logon name
  573. //
  574. // Arguments: [pVal] -- out param, containing logon name
  575. //
  576. // Returns: S_OK upon success, other values upon failure.
  577. //
  578. // History: 12-10-97 mohamedn created
  579. //
  580. //----------------------------------------------------------------------------
  581. STDMETHODIMP CScopeAdm::get_Logon(BSTR * pVal)
  582. {
  583. SCODE sc = S_OK;
  584. CLock lock(_mtx);
  585. TRANSLATE_EXCEPTIONS;
  586. TRY
  587. {
  588. SafeForScripting();
  589. if ( !_fValid )
  590. {
  591. odmDebugOut(( DEB_ERROR, "Invalid Scope: %ws\n", _xScopeAdmin->GetPath() ));
  592. sc = HRESULT_FROM_WIN32( ERROR_INVALID_STATE );
  593. }
  594. else
  595. {
  596. WCHAR const * pwszLogon = _xScopeAdmin->GetLogon();
  597. *pVal = SysAllocString(pwszLogon);
  598. if ( !*pVal )
  599. {
  600. sc = E_OUTOFMEMORY;
  601. }
  602. }
  603. }
  604. CATCH( CException, e )
  605. {
  606. sc = e.GetErrorCode();
  607. }
  608. END_CATCH
  609. UNTRANSLATE_EXCEPTIONS;
  610. if ( FAILED(sc) )
  611. {
  612. odmDebugOut(( DEB_ERROR, "get_Logon Failed: %x\n",sc ));
  613. SetErrorInfo( sc );
  614. }
  615. return sc;
  616. }