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.

1709 lines
41 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1997-1998
  5. //
  6. // File: MacAdmin.cxx
  7. //
  8. // Contents: Index Server Administration Interface methods
  9. //
  10. // Classes: CMachineAdm
  11. //
  12. // History: 12-10-97 mohamedn created
  13. //
  14. //----------------------------------------------------------------------------
  15. #include "pch.cxx"
  16. #pragma hdrstop
  17. #include "stdafx.h"
  18. #include <mshtml.h>
  19. DECLARE_INFOLEVEL( odm );
  20. //+---------------------------------------------------------------------------
  21. //
  22. // Member: CMachineAdm::InterfaceSupportsErrorInfo, public
  23. //
  24. // Arguments: [riid] -- interface iid
  25. //
  26. // Returns: S_OK if interface supports IErrorInfo
  27. //
  28. // History: 12-10-97 mohamedn created
  29. //
  30. //----------------------------------------------------------------------------
  31. STDMETHODIMP CMachineAdm::InterfaceSupportsErrorInfo(REFIID riid)
  32. {
  33. return ( riid == IID_IAdminIndexServer );
  34. }
  35. //+---------------------------------------------------------------------------
  36. //
  37. // Member: CMachineAdm::SetErrorInfo, public
  38. //
  39. // Synopsis: Creates & sets the error object
  40. //
  41. // Arguments: [hRes] -- HRESULT error code to set
  42. // [ pwszDesc] -- error description
  43. //
  44. // Returns: S_OK upon success, other values upon failure
  45. //
  46. // History: 12-10-97 mohamedn created
  47. //
  48. //----------------------------------------------------------------------------
  49. void CMachineAdm::SetErrorInfo( HRESULT hRes )
  50. {
  51. CiodmError err(hRes);
  52. AtlSetErrorInfo(CLSID_AdminIndexServer, err.GetErrorMessage() , 0 , 0, IID_IAdminIndexServer, hRes, 0 );
  53. }
  54. //+---------------------------------------------------------------------------
  55. //
  56. // Member: CMachineAdm::CMachineAdm, public
  57. //
  58. // Synopsis: Constructor
  59. //
  60. // History: 12-10-97 mohamedn created
  61. //
  62. //----------------------------------------------------------------------------
  63. CMachineAdm::CMachineAdm()
  64. :_eCurrentState(CIODM_NOT_INITIALIZED),
  65. _cMinRefCountToDestroy(1),
  66. _cEnumIndex(0)
  67. {
  68. wcscpy(_wcsMachineName,L"."); // default to local machine
  69. }
  70. //+---------------------------------------------------------------------------
  71. //
  72. // Member: CMachineAdm::InternalAddRef, public
  73. //
  74. // Synopsis: overrides CComObjectRootEx<Base>::InternalAddRef, for debugging only.
  75. //
  76. // Arguments: none
  77. //
  78. // History: 12-10-97 mohamedn created
  79. //
  80. //----------------------------------------------------------------------------
  81. ULONG CMachineAdm::InternalAddRef()
  82. {
  83. unsigned cRef = CComObjectRootEx<CComMultiThreadModel>::InternalAddRef();
  84. odmDebugOut(( DEB_TRACE,"CMachineAdm AddRef returned: %d\n", cRef ));
  85. odmDebugOut(( DEB_TRACE,"=========================== CMachineAdm object count: %d\n",
  86. _cMinRefCountToDestroy ));
  87. return cRef;
  88. }
  89. //+---------------------------------------------------------------------------
  90. //
  91. // Member: CMachineAdm::InternalRelease, public
  92. //
  93. // Synopsis: overrides CComObjectRootEx<Base>::InternalRelease, for debugging only.
  94. //
  95. // Arguments: none
  96. //
  97. // History: 12-10-97 mohamedn created
  98. //
  99. //----------------------------------------------------------------------------
  100. ULONG CMachineAdm::InternalRelease()
  101. {
  102. CLock lock(_mtx);
  103. //
  104. // Delete contained objects if we're being destoryed.
  105. // m_dwRef is an internal ATL public refcount member.
  106. //
  107. if ( _eCurrentState != CIODM_DESTROY && m_dwRef == _cMinRefCountToDestroy )
  108. {
  109. _eCurrentState = CIODM_DESTROY;
  110. _aICatAdmin.Free();
  111. }
  112. unsigned cRef = CComObjectRootEx<CComMultiThreadModel>::InternalRelease();
  113. odmDebugOut(( DEB_TRACE,"CMachineAdm Release returned: %d\n", cRef ));
  114. odmDebugOut(( DEB_TRACE,"=========================== CMachineAdm object count: %d\n",
  115. _cMinRefCountToDestroy ));
  116. return cRef;
  117. }
  118. //+---------------------------------------------------------------------------
  119. //
  120. // Member: CMachineAdm::Initialize, public
  121. //
  122. // Synopsis: Initializes CMachineAdm object, creates CMachineAdmin object,
  123. // populates catalogs lists.
  124. //
  125. // Arguments: none.
  126. //
  127. // History: 12-10-97 mohamedn created
  128. //
  129. //----------------------------------------------------------------------------
  130. void CMachineAdm::Initialize()
  131. {
  132. //
  133. // create CMachineAdmin object
  134. //
  135. if ( IsCurrentObjectValid() )
  136. {
  137. return;
  138. }
  139. TRY
  140. {
  141. _xMachineAdmin.Set (new CMachineAdmin( _wcsMachineName ) );
  142. XPtr<CCatalogEnum> xCatEnum( _xMachineAdmin->QueryCatalogEnum() );
  143. Win4Assert( 0 == _aICatAdmin.Count() );
  144. while ( xCatEnum->Next() )
  145. {
  146. XPtr<CCatalogAdmin> xCatAdmin(xCatEnum->QueryCatalogAdmin());
  147. XInterface<CatAdmObject> xICatAdm;
  148. GetCatalogAutomationObject( xCatAdmin, xICatAdm );
  149. _aICatAdmin.Add( xICatAdm.GetPointer(), _aICatAdmin.Count() );
  150. xICatAdm.Acquire();
  151. }
  152. _eCurrentState = CIODM_INITIALIZED;
  153. }
  154. CATCH ( CException, e )
  155. {
  156. _xMachineAdmin.Free();
  157. _cEnumIndex = 0;
  158. wcscpy(_wcsMachineName,L".");
  159. _aICatAdmin.Free();
  160. _eCurrentState = CIODM_NOT_INITIALIZED;
  161. RETHROW();
  162. }
  163. END_CATCH
  164. }
  165. //+---------------------------------------------------------------------------
  166. //
  167. // Member: CMachineAdm::GetCatalogAutomationObject, public
  168. //
  169. // Synopsis: Wraps a CCatalogAdmin pointer in an IDispatch interface.
  170. //
  171. // Arguments: [xCatAdmin] -- Catalog admin object
  172. // [xICatAdm] -- XInterface to contain created CatAdmObject
  173. //
  174. // Returns: none, throws upon error.
  175. //
  176. // History: 12-10-97 mohamedn created
  177. //
  178. //----------------------------------------------------------------------------
  179. void CMachineAdm::GetCatalogAutomationObject( XPtr<CCatalogAdmin> & xCatAdmin,
  180. XInterface<CatAdmObject> & xICatAdm )
  181. {
  182. Win4Assert( !xCatAdmin.IsNull() );
  183. SCODE sc = CatAdmObject::CreateInstance( xICatAdm.GetPPointer() );
  184. if ( FAILED(sc) )
  185. {
  186. odmDebugOut(( DEB_ERROR, "CatAdmObject::CreateInstance() Failed: %x\n", sc ));
  187. THROW(CException(sc));
  188. }
  189. else
  190. {
  191. Win4Assert( !xICatAdm.IsNull() );
  192. xICatAdm->SetParent( (CComObject<CMachineAdm> *)this );
  193. xICatAdm->AddRef();
  194. IncObjectCount(); // inc. internal object count
  195. }
  196. //
  197. // Initialize the new object
  198. //
  199. xICatAdm->Initialize( xCatAdmin );
  200. }
  201. //+---------------------------------------------------------------------------
  202. //
  203. // Member: CMachineAdm::GetIDisp, public
  204. //
  205. // Synopsis: QI for IDispatch on CCatAdm object given by the passed in index.
  206. //
  207. // Arguments: [cPosition] -- index of CCatAdm object
  208. //
  209. // Returns: [IDispatch *] -- pointer to IDispatch on CCatAdm, throws upon failure.
  210. //
  211. // History: 12-10-97 mohamedn created
  212. //
  213. //----------------------------------------------------------------------------
  214. IDispatch * CMachineAdm::GetIDisp( unsigned i )
  215. {
  216. IDispatch * pTmpIDisp = 0;
  217. SCODE sc = _aICatAdmin[i]->QueryInterface(IID_IDispatch, (void **) &pTmpIDisp);
  218. if ( FAILED(sc) )
  219. {
  220. odmDebugOut(( DEB_ERROR, "QueryInterface() Failed: %x\n", sc ));
  221. THROW(CException(sc));
  222. }
  223. Win4Assert( pTmpIDisp );
  224. return pTmpIDisp;
  225. }
  226. //+---------------------------------------------------------------------------
  227. //
  228. // Member: CMachineAdm::get_MachineName, public
  229. //
  230. // Synopsis: Gets MachineName property
  231. //
  232. // Arguments: [pVal] pointer to bstr buffer return value
  233. //
  234. // Returns: S_OK on success, other values on failure.
  235. //
  236. // History: 12-10-97 mohamedn created
  237. //
  238. //----------------------------------------------------------------------------
  239. STDMETHODIMP CMachineAdm::get_MachineName(BSTR * pVal)
  240. {
  241. SCODE sc = S_OK;
  242. CLock lock(_mtx);
  243. TRANSLATE_EXCEPTIONS;
  244. TRY
  245. {
  246. SafeForScripting();
  247. Initialize();
  248. *pVal = SysAllocString(_wcsMachineName);
  249. if ( 0 == *pVal )
  250. {
  251. sc = E_OUTOFMEMORY;
  252. }
  253. }
  254. CATCH ( CException,e )
  255. {
  256. sc = e.GetErrorCode();
  257. }
  258. END_CATCH
  259. UNTRANSLATE_EXCEPTIONS;
  260. if ( FAILED(sc) )
  261. {
  262. odmDebugOut(( DEB_ERROR, "CMachineAdm::get_MachineName exception: %x\n",sc ));
  263. SetErrorInfo( sc );
  264. }
  265. return sc;
  266. }
  267. //+---------------------------------------------------------------------------
  268. //
  269. // Member: CMachineAdm::put_MachineName, public
  270. //
  271. // Synopsis: Gets MachineName property
  272. //
  273. // Arguments: [newVal] -- machine name to set.
  274. //
  275. // Returns: S_OK on success, other values on failure.
  276. //
  277. // History: 12-10-97 mohamedn created
  278. //
  279. //----------------------------------------------------------------------------
  280. STDMETHODIMP CMachineAdm::put_MachineName(BSTR newVal)
  281. {
  282. SCODE sc = S_OK;
  283. CLock lock(_mtx);
  284. TRANSLATE_EXCEPTIONS;
  285. TRY
  286. {
  287. SafeForScripting();
  288. ValidateInputParam(newVal);
  289. if ( IsCurrentObjectValid() )
  290. {
  291. odmDebugOut(( DEB_ERROR,"CMachineAdm(%ws) already initialized", newVal));
  292. sc = HRESULT_FROM_WIN32(ERROR_ALREADY_INITIALIZED);
  293. }
  294. else if ( SysStringLen( newVal ) >= MAX_PATH )
  295. {
  296. odmDebugOut(( DEB_ERROR,"CMachineAdm(%ws): Path too long", newVal));
  297. sc = E_INVALIDARG;
  298. }
  299. else
  300. {
  301. Win4Assert( L'.' == _wcsMachineName[0] && L'' == _wcsMachineName[1] );
  302. if ( newVal[0] == L'' )
  303. {
  304. wcscpy( _wcsMachineName, L"." );
  305. }
  306. else
  307. {
  308. wcscpy( _wcsMachineName, newVal );
  309. }
  310. Initialize();
  311. }
  312. }
  313. CATCH ( CException,e )
  314. {
  315. sc = e.GetErrorCode();
  316. }
  317. END_CATCH
  318. UNTRANSLATE_EXCEPTIONS;
  319. if ( FAILED(sc) )
  320. {
  321. odmDebugOut(( DEB_ERROR,"put_MachineName Failed: %x\n", sc));
  322. SetErrorInfo( sc );
  323. }
  324. return sc;
  325. }
  326. //+---------------------------------------------------------------------------
  327. //
  328. // Member: CMachineAdm::AddCatalog, public
  329. //
  330. // Synopsis: Adds a catalog.
  331. //
  332. // Arguments: [bstrCatName] - in param, catalog name
  333. // [bstrCatLocation] - in param, catalog location
  334. // [pIDisp] - out param, IDisp interface to the new catalog
  335. //
  336. // Returns: S_OK upon success, other values upon failure.
  337. //
  338. // History: 12-10-97 mohamedn created
  339. //
  340. //----------------------------------------------------------------------------
  341. STDMETHODIMP CMachineAdm::AddCatalog(BSTR bstrCatName, BSTR bstrCatLocation, IDispatch * * pIDisp)
  342. {
  343. SCODE sc = S_OK;
  344. CLock lock(_mtx);
  345. TRANSLATE_EXCEPTIONS;
  346. TRY
  347. {
  348. SafeForScripting();
  349. ValidateInputParam(bstrCatName);
  350. ValidateInputParam(bstrCatLocation);
  351. Initialize();
  352. if ( CatalogExists( bstrCatName, bstrCatLocation ) )
  353. {
  354. sc = HRESULT_FROM_WIN32( ERROR_ALREADY_EXISTS );
  355. }
  356. else
  357. {
  358. _xMachineAdmin->AddCatalog( bstrCatName, bstrCatLocation );
  359. XPtr<CCatalogAdmin> xCatAdmin( _xMachineAdmin->QueryCatalogAdmin( bstrCatName ) );
  360. unsigned cPosition = _aICatAdmin.Count();
  361. XInterface<CatAdmObject> xICatAdm;
  362. GetCatalogAutomationObject( xCatAdmin, xICatAdm );
  363. _aICatAdmin.Add( xICatAdm.GetPointer(), cPosition );
  364. xICatAdm.Acquire();
  365. *pIDisp = GetIDisp(cPosition);
  366. }
  367. }
  368. CATCH( CException, e )
  369. {
  370. sc = e.GetErrorCode();
  371. }
  372. END_CATCH
  373. UNTRANSLATE_EXCEPTIONS;
  374. if ( FAILED (sc) )
  375. {
  376. odmDebugOut(( DEB_ERROR, "AddCatalog Failed: %x\n", sc ));
  377. SetErrorInfo( sc );
  378. }
  379. return sc;
  380. }
  381. //+---------------------------------------------------------------------------
  382. //
  383. // member: CMachineAdm::CatalogExists, public
  384. //
  385. // Synopsis: determines if a catalog name or location is used up.
  386. //
  387. // Arguments: [pCatName] -- Catalog name
  388. // [pCatLocation] -- Catalog location.
  389. //
  390. // Returns: TRUE if catalog already exists, false otherwise.
  391. //
  392. // History: 12-10-97 mohamedn created
  393. //
  394. //----------------------------------------------------------------------------
  395. BOOL CMachineAdm::CatalogExists( WCHAR const * pCatName, WCHAR const * pCatLocation )
  396. {
  397. Win4Assert( pCatName );
  398. Win4Assert( pCatLocation);
  399. unsigned cMaxCatalogs = _aICatAdmin.Count();
  400. for ( DWORD i = 0; i < cMaxCatalogs; i++ )
  401. {
  402. Win4Assert( _aICatAdmin[i] );
  403. CCatalogAdmin * pCatalogAdmin = _aICatAdmin[i]->GetCatalogAdmin();
  404. Win4Assert( pCatalogAdmin );
  405. if ( !_wcsicmp( pCatName, pCatalogAdmin->GetName() ) ||
  406. !_wcsicmp( pCatLocation, pCatalogAdmin->GetLocation() ) )
  407. {
  408. return TRUE;
  409. }
  410. }
  411. return FALSE;
  412. }
  413. //+---------------------------------------------------------------------------
  414. //
  415. // Member: CMachineAdm::RemoveCatalog, public
  416. //
  417. // Synopsis: deletes a catalog, and optionally the corresponding directory
  418. //
  419. // Arguments: [bstrCatName] - Catalog Name
  420. // [fDelDirectory] - TRUE --> delete catalog directory.
  421. //
  422. // Returns: S_OK upon success, other values upon failure.
  423. //
  424. // History: 12-10-97 mohamedn created
  425. //
  426. //----------------------------------------------------------------------------
  427. STDMETHODIMP CMachineAdm::RemoveCatalog(BSTR bstrCatName, VARIANT_BOOL fDelDirectory)
  428. {
  429. SCODE sc = S_OK;
  430. CLock lock(_mtx);
  431. TRANSLATE_EXCEPTIONS;
  432. TRY
  433. {
  434. SafeForScripting();
  435. ValidateInputParam(bstrCatName);
  436. Initialize();
  437. if (_xMachineAdmin->IsCIStarted())
  438. sc = CI_E_INVALID_STATE;
  439. else
  440. {
  441. unsigned cMax = _aICatAdmin.Count();
  442. for ( DWORD i = 0; i < cMax ; i++ )
  443. {
  444. Win4Assert( _aICatAdmin[i] );
  445. CCatalogAdmin * pCatalogAdmin = _aICatAdmin[i]->GetCatalogAdmin();
  446. Win4Assert( pCatalogAdmin );
  447. if ( !_wcsicmp( bstrCatName, pCatalogAdmin->GetName() ) )
  448. {
  449. //
  450. // Remove from CI
  451. //
  452. _xMachineAdmin->RemoveCatalog( bstrCatName, fDelDirectory );
  453. //
  454. // Remove catalog from local list, set catalog object to invalid,
  455. // and release removed catalog
  456. //
  457. CatAdmObject * pICatAdm = _aICatAdmin.AcquireAndShrink(i);
  458. pICatAdm->SetInvalid();
  459. pICatAdm->Release();
  460. break;
  461. }
  462. }
  463. if ( i == cMax )
  464. {
  465. odmDebugOut(( DEB_ERROR, "RemoveCatalog Failed, Catalog(%ws) not found\n", bstrCatName ));
  466. sc = HRESULT_FROM_WIN32(ERROR_NOT_FOUND);
  467. }
  468. }
  469. }
  470. CATCH( CException, e )
  471. {
  472. sc = e.GetErrorCode();
  473. }
  474. END_CATCH
  475. UNTRANSLATE_EXCEPTIONS;
  476. if ( FAILED (sc) )
  477. {
  478. odmDebugOut(( DEB_ERROR, "RemoveCatalog Failed: %x\n", sc ));
  479. SetErrorInfo( sc );
  480. }
  481. return sc;
  482. }
  483. //+---------------------------------------------------------------------------
  484. //
  485. // Member: CMachineAdm::GetCatalogByName, public
  486. //
  487. // Arguments: [bstrCatalogName] -- Catalog name to search for.
  488. // [pIDisp] -- IDisp interface to the found catalog
  489. //
  490. // Returns: S_OK upon success, other values upon failure.
  491. //
  492. // History: 12-10-97 mohamedn created
  493. //
  494. //----------------------------------------------------------------------------
  495. STDMETHODIMP CMachineAdm::GetCatalogByName(BSTR bstrCatalogName, IDispatch * * pIDisp)
  496. {
  497. SCODE sc = S_OK;
  498. CLock lock(_mtx);
  499. TRANSLATE_EXCEPTIONS;
  500. TRY
  501. {
  502. SafeForScripting();
  503. ValidateInputParam(bstrCatalogName);
  504. Initialize();
  505. unsigned cMaxCatalogs = _aICatAdmin.Count();
  506. for ( DWORD i = 0; i < cMaxCatalogs; i++ )
  507. {
  508. Win4Assert( _aICatAdmin[i] );
  509. CCatalogAdmin * pCatalogAdmin = _aICatAdmin[i]->GetCatalogAdmin();
  510. Win4Assert( pCatalogAdmin );
  511. if ( !_wcsicmp( bstrCatalogName, pCatalogAdmin->GetName() ) )
  512. {
  513. *pIDisp = GetIDisp(i);
  514. break;
  515. }
  516. }
  517. if ( i == cMaxCatalogs )
  518. {
  519. odmDebugOut(( DEB_ERROR, "Catalog(%ws) not found\n", bstrCatalogName ));
  520. sc = HRESULT_FROM_WIN32( ERROR_NOT_FOUND );
  521. }
  522. }
  523. CATCH ( CException,e )
  524. {
  525. sc = e.GetErrorCode();
  526. }
  527. END_CATCH
  528. UNTRANSLATE_EXCEPTIONS;
  529. if ( FAILED(sc) )
  530. {
  531. odmDebugOut(( DEB_ERROR, "GetCatalogByName Failed: %x\n", sc ));
  532. SetErrorInfo( sc );
  533. }
  534. return sc;
  535. }
  536. //+---------------------------------------------------------------------------
  537. //
  538. // Member: CMachineAdm::FindFirstCatalog, public
  539. //
  540. // Synopsis: Catalog enumerator. Resets scan to start of list.
  541. //
  542. // Arguments: [pfFound] -- out param, True --> Found at least one catalog
  543. //
  544. // Returns: SO_OK upon success, other values upon faillure
  545. //
  546. // History: 12-10-97 mohamedn created
  547. //
  548. //----------------------------------------------------------------------------
  549. STDMETHODIMP CMachineAdm::FindFirstCatalog(VARIANT_BOOL * pfFound)
  550. {
  551. SCODE sc = S_OK;
  552. CLock lock(_mtx);
  553. TRANSLATE_EXCEPTIONS;
  554. TRY
  555. {
  556. SafeForScripting();
  557. Initialize();
  558. _cEnumIndex = 0;
  559. if ( _aICatAdmin.Count() > 0 )
  560. {
  561. Win4Assert( _aICatAdmin[_cEnumIndex] );
  562. *pfFound = VARIANT_TRUE;
  563. }
  564. else
  565. {
  566. *pfFound = VARIANT_FALSE;
  567. }
  568. }
  569. CATCH( CException, e )
  570. {
  571. sc = e.GetErrorCode();
  572. }
  573. END_CATCH
  574. UNTRANSLATE_EXCEPTIONS;
  575. if ( FAILED(sc) )
  576. {
  577. odmDebugOut(( DEB_ERROR, "FindFirstCatalog Failed: %x\n", sc ));
  578. SetErrorInfo( sc );
  579. }
  580. return sc;
  581. }
  582. //+---------------------------------------------------------------------------
  583. //
  584. // Member: CMachineAdm::FindNextCatalog, public
  585. //
  586. // Synopsis: Catalog enumerator. Scans for next catalog in the list
  587. //
  588. // Arguments: [pfFound] -- out param, True --> Found next catalog
  589. //
  590. // Returns: SO_OK upon success, other values upon faillure
  591. //
  592. // History: 12-10-97 mohamedn created
  593. //
  594. //----------------------------------------------------------------------------
  595. STDMETHODIMP CMachineAdm::FindNextCatalog(VARIANT_BOOL * pfFound)
  596. {
  597. SCODE sc = S_OK;
  598. CLock lock(_mtx);
  599. TRANSLATE_EXCEPTIONS;
  600. TRY
  601. {
  602. SafeForScripting();
  603. if ( !IsCurrentObjectValid() )
  604. {
  605. odmDebugOut(( DEB_ERROR,"CMachineAdm not initialized" ));
  606. sc = HRESULT_FROM_WIN32(ERROR_INVALID_STATE);
  607. }
  608. else
  609. {
  610. _cEnumIndex++;
  611. if ( _cEnumIndex < _aICatAdmin.Count() )
  612. {
  613. Win4Assert( _aICatAdmin[_cEnumIndex] );
  614. *pfFound = VARIANT_TRUE;
  615. }
  616. else
  617. {
  618. *pfFound = VARIANT_FALSE;
  619. }
  620. }
  621. }
  622. CATCH( CException, e )
  623. {
  624. sc = e.GetErrorCode();
  625. }
  626. END_CATCH
  627. UNTRANSLATE_EXCEPTIONS;
  628. if ( FAILED(sc) )
  629. {
  630. odmDebugOut(( DEB_ERROR, "FindNextCatalog Failed: %x\n", sc ));
  631. SetErrorInfo( sc );
  632. }
  633. return sc;
  634. }
  635. //+---------------------------------------------------------------------------
  636. //
  637. // Member: CMachineAdm::GetCatalog, public
  638. //
  639. // Synopsis: Catalog enumerator. Returns IDispatch to current catalog
  640. //
  641. // Arguments: [pIDisp] -- out param, IDispatch to current catalog
  642. //
  643. // Returns: SO_OK upon success, other values upon faillure
  644. //
  645. // History: 12-10-97 mohamedn created
  646. //
  647. //----------------------------------------------------------------------------
  648. STDMETHODIMP CMachineAdm::GetCatalog(IDispatch * * pIDisp)
  649. {
  650. SCODE sc = S_OK;
  651. CLock lock(_mtx);
  652. TRANSLATE_EXCEPTIONS;
  653. TRY
  654. {
  655. SafeForScripting();
  656. if ( !IsCurrentObjectValid() )
  657. {
  658. odmDebugOut(( DEB_ERROR,"CMachineAdm not initialized" ));
  659. sc = HRESULT_FROM_WIN32(ERROR_INVALID_STATE);
  660. }
  661. else
  662. {
  663. if ( _cEnumIndex >= _aICatAdmin.Count() )
  664. {
  665. odmDebugOut(( DEB_ERROR, "No More Catalogs, Index: %d\n", _cEnumIndex ));
  666. sc = HRESULT_FROM_WIN32(ERROR_NO_MORE_ITEMS);
  667. }
  668. else
  669. {
  670. Win4Assert( _aICatAdmin[_cEnumIndex] );
  671. *pIDisp = GetIDisp(_cEnumIndex);
  672. }
  673. }
  674. }
  675. CATCH( CException, e )
  676. {
  677. sc = e.GetErrorCode();
  678. }
  679. END_CATCH
  680. UNTRANSLATE_EXCEPTIONS;
  681. if ( FAILED(sc) )
  682. {
  683. odmDebugOut(( DEB_ERROR, "GetCatalog Failed: %x\n", sc ));
  684. SetErrorInfo( sc );
  685. }
  686. return sc;
  687. }
  688. //+---------------------------------------------------------------------------
  689. //
  690. // Member: CMachineAdm::Start, public
  691. //
  692. // Synopsis: Starts cisvc service
  693. //
  694. // Returns: S_OK upon success, othervalues upon failure
  695. //
  696. // History: 12-10-97 mohamedn created
  697. //
  698. //----------------------------------------------------------------------------
  699. STDMETHODIMP CMachineAdm::Start()
  700. {
  701. SCODE sc = S_OK;
  702. CLock lock(_mtx);
  703. TRANSLATE_EXCEPTIONS;
  704. TRY
  705. {
  706. SafeForScripting();
  707. Initialize();
  708. _xMachineAdmin->StartCI();
  709. }
  710. CATCH( CException, e )
  711. {
  712. sc = e.GetErrorCode();
  713. }
  714. END_CATCH
  715. UNTRANSLATE_EXCEPTIONS;
  716. if ( FAILED(sc) )
  717. {
  718. odmDebugOut(( DEB_ERROR, "Start cisvc Failed: %x\n", sc ));
  719. SetErrorInfo( sc );
  720. }
  721. return sc;
  722. }
  723. //+---------------------------------------------------------------------------
  724. //
  725. // Member: CMachineAdm::Stop, public
  726. //
  727. // Synopsis: Stops cisvc service
  728. //
  729. // Returns: S_OK upon success, othervalues upon failure
  730. //
  731. // History: 12-10-97 mohamedn created
  732. //
  733. //----------------------------------------------------------------------------
  734. STDMETHODIMP CMachineAdm::Stop()
  735. {
  736. SCODE sc = S_OK;
  737. CLock lock(_mtx);
  738. TRANSLATE_EXCEPTIONS;
  739. TRY
  740. {
  741. SafeForScripting();
  742. Initialize();
  743. _xMachineAdmin->StopCI();
  744. }
  745. CATCH( CException, e )
  746. {
  747. sc = e.GetErrorCode();
  748. }
  749. END_CATCH
  750. UNTRANSLATE_EXCEPTIONS;
  751. if ( FAILED(sc) )
  752. {
  753. odmDebugOut(( DEB_ERROR, "Stop cisvc Failed: %x\n", sc ));
  754. SetErrorInfo( sc );
  755. }
  756. return sc;
  757. }
  758. //+---------------------------------------------------------------------------
  759. //
  760. // Member: CMachineAdm::IsRunning, public
  761. //
  762. // Synopsis: is cisvc running
  763. //
  764. // Returns: True if cisvc is running, False otherwise.
  765. //
  766. // History: 12-10-97 mohamedn created
  767. //
  768. //----------------------------------------------------------------------------
  769. STDMETHODIMP CMachineAdm::IsRunning( VARIANT_BOOL *pfIsRunning )
  770. {
  771. SCODE sc = S_OK;
  772. CLock lock(_mtx);
  773. TRANSLATE_EXCEPTIONS;
  774. TRY
  775. {
  776. SafeForScripting();
  777. Initialize();
  778. *pfIsRunning = _xMachineAdmin->IsCIStarted() ? VARIANT_TRUE : VARIANT_FALSE;
  779. }
  780. CATCH( CException, e )
  781. {
  782. sc = e.GetErrorCode();
  783. }
  784. END_CATCH
  785. UNTRANSLATE_EXCEPTIONS;
  786. if ( FAILED(sc) )
  787. {
  788. odmDebugOut(( DEB_ERROR, "Failed to see if cisvc is running: %x\n", sc ));
  789. SetErrorInfo( sc );
  790. }
  791. return sc;
  792. }
  793. //+---------------------------------------------------------------------------
  794. //
  795. // Member: CMachineAdm::IsPaused, public
  796. //
  797. // Synopsis: is cisvc paused
  798. //
  799. // Returns: True if cisvc is paused, False otherwise.
  800. //
  801. // History: 08-11-98 kitmanh created
  802. //
  803. //----------------------------------------------------------------------------
  804. STDMETHODIMP CMachineAdm::IsPaused( VARIANT_BOOL *pfIsPaused )
  805. {
  806. SCODE sc = S_OK;
  807. CLock lock(_mtx);
  808. TRANSLATE_EXCEPTIONS;
  809. TRY
  810. {
  811. SafeForScripting();
  812. Initialize();
  813. *pfIsPaused = _xMachineAdmin->IsCIPaused() ? VARIANT_TRUE : VARIANT_FALSE;
  814. }
  815. CATCH( CException, e )
  816. {
  817. sc = e.GetErrorCode();
  818. }
  819. END_CATCH
  820. UNTRANSLATE_EXCEPTIONS;
  821. if ( FAILED(sc) )
  822. {
  823. odmDebugOut(( DEB_ERROR, "Failed to see if cisvc is paused: %x\n", sc ));
  824. SetErrorInfo( sc );
  825. }
  826. return sc;
  827. }
  828. //+---------------------------------------------------------------------------
  829. //
  830. // Member: CMachineAdm::EnableCI, public
  831. //
  832. // Synopsis: Sets cisvc to auto-start (enabled) or manual start (disabled)
  833. //
  834. // Arguments: [fAutoStart] - True -> set to auto start, False -> set to demand start
  835. //
  836. // Returns: S_OK upon success, failure error if failed to set service setting.
  837. //
  838. // History: 12-10-97 mohamedn created
  839. //
  840. //----------------------------------------------------------------------------
  841. STDMETHODIMP CMachineAdm::EnableCI( VARIANT_BOOL fAutoStart )
  842. {
  843. SCODE sc = S_OK;
  844. CLock lock(_mtx);
  845. TRANSLATE_EXCEPTIONS;
  846. TRY
  847. {
  848. SafeForScripting();
  849. Initialize();
  850. sc = fAutoStart ? _xMachineAdmin->EnableCI() : _xMachineAdmin->DisableCI();
  851. }
  852. CATCH( CException, e )
  853. {
  854. sc = e.GetErrorCode();
  855. }
  856. END_CATCH
  857. UNTRANSLATE_EXCEPTIONS;
  858. if ( FAILED(sc) )
  859. {
  860. odmDebugOut(( DEB_ERROR, "Failed enable/disable cisvc settings: %x\n", sc ));
  861. SetErrorInfo( sc );
  862. }
  863. return sc;
  864. }
  865. //+---------------------------------------------------------------------------
  866. //
  867. // Member: CMachineAdm::SetLongProperty, public
  868. //
  869. // Synopsis: Sets CI registry params
  870. //
  871. // Arguments: [bstrPropName] -- property name
  872. // [lPropVal] -- property value
  873. //
  874. // Returns: S_OK upon success, othervalues upon failure
  875. //
  876. // Notes: Property value is an unsigned value, though it is being
  877. // passed in as a signed LONG for compatiblity with automation
  878. // clients (VB5, VB6 don't support unsigned long).
  879. //
  880. // History: 12-10-97 mohamedn created
  881. //
  882. //----------------------------------------------------------------------------
  883. STDMETHODIMP CMachineAdm::SetLongProperty(BSTR bstrPropName, LONG lPropVal )
  884. {
  885. SCODE sc = S_OK;
  886. CLock lock(_mtx);
  887. TRANSLATE_EXCEPTIONS;
  888. TRY
  889. {
  890. SafeForScripting();
  891. ValidateInputParam( bstrPropName );
  892. Initialize();
  893. _xMachineAdmin->SetDWORDParam( bstrPropName, lPropVal );
  894. }
  895. CATCH( CException, e )
  896. {
  897. sc = e.GetErrorCode();
  898. }
  899. END_CATCH
  900. UNTRANSLATE_EXCEPTIONS;
  901. if ( FAILED(sc) )
  902. {
  903. odmDebugOut(( DEB_ERROR, "SetLongParam Failed: %x\n", sc ));
  904. SetErrorInfo( sc );
  905. }
  906. return sc;
  907. }
  908. //+---------------------------------------------------------------------------
  909. //
  910. // Member: CMachineAdm::GetLongProperty, public
  911. //
  912. // Synopsis: Gets CI registry params
  913. //
  914. // Arguments: [bstrPropName] -- property name
  915. // [plPropVal] -- returned property value
  916. //
  917. // Returns: S_OK upon success, othervalues upon failure
  918. //
  919. // Notes: Property value is an unsigned value, though it is being
  920. // passed in as a signed LONG for compatiblity with automation
  921. // clients (VB5, VB6 don't support unsigned long).
  922. //
  923. // History: 12-10-97 mohamedn created
  924. //
  925. //----------------------------------------------------------------------------
  926. STDMETHODIMP CMachineAdm::GetLongProperty(BSTR bstrPropName, LONG * plPropVal )
  927. {
  928. SCODE sc = S_OK;
  929. CLock lock(_mtx);
  930. TRANSLATE_EXCEPTIONS;
  931. TRY
  932. {
  933. SafeForScripting();
  934. ValidateInputParam( bstrPropName );
  935. Initialize();
  936. unsigned long uVar = 0;
  937. if ( !_xMachineAdmin->GetDWORDParam( bstrPropName, uVar ) )
  938. {
  939. sc = E_FAIL;
  940. }
  941. else
  942. {
  943. *plPropVal = uVar;
  944. }
  945. }
  946. CATCH( CException, e )
  947. {
  948. sc = e.GetErrorCode();
  949. }
  950. END_CATCH
  951. UNTRANSLATE_EXCEPTIONS;
  952. if ( FAILED(sc) )
  953. {
  954. odmDebugOut(( DEB_ERROR, "GetLONGParam Failed: %x\n", sc ));
  955. SetErrorInfo( sc );
  956. }
  957. return sc;
  958. }
  959. //+---------------------------------------------------------------------------
  960. //
  961. // Member: CMachineAdm::SetSZProperty, public
  962. //
  963. // Synopsis: Sets CI registry params
  964. //
  965. // Arguments: [bstrPropName] -- property name
  966. // [bstrVal] -- property value
  967. //
  968. // Returns: S_OK upon success, othervalues upon failure
  969. //
  970. // History: 4-6-97 mohamedn created
  971. //
  972. //----------------------------------------------------------------------------
  973. STDMETHODIMP CMachineAdm::SetSZProperty(BSTR bstrPropName, BSTR bstrVal)
  974. {
  975. SCODE sc = S_OK;
  976. CLock lock(_mtx);
  977. TRANSLATE_EXCEPTIONS;
  978. TRY
  979. {
  980. SafeForScripting();
  981. ValidateInputParam( bstrPropName );
  982. ValidateInputParam( bstrVal );
  983. Initialize();
  984. unsigned cLen = SysStringLen( bstrVal );
  985. unsigned cbLen = sizeof WCHAR * (cLen + 1);
  986. _xMachineAdmin->SetSZParam( bstrPropName, bstrVal, cbLen );
  987. }
  988. CATCH( CException, e )
  989. {
  990. sc = e.GetErrorCode();
  991. }
  992. END_CATCH
  993. UNTRANSLATE_EXCEPTIONS;
  994. if ( FAILED(sc) )
  995. {
  996. odmDebugOut(( DEB_ERROR, "SetSZParam Failed: %x\n", sc ));
  997. SetErrorInfo( sc );
  998. }
  999. return sc;
  1000. }
  1001. //+---------------------------------------------------------------------------
  1002. //
  1003. // Member: CMachineAdm::GetSZProperty, public
  1004. //
  1005. // Synopsis: Gets CI registry params
  1006. //
  1007. // Arguments: [bstrPropName] -- property name
  1008. // [pbstrVal] -- returned property value
  1009. //
  1010. // Returns: S_OK upon success, othervalues upon failure
  1011. //
  1012. // History: 4-6-97 mohamedn created
  1013. //
  1014. //----------------------------------------------------------------------------
  1015. STDMETHODIMP CMachineAdm::GetSZProperty(BSTR bstrPropName, BSTR * pbstrVal)
  1016. {
  1017. SCODE sc = S_OK;
  1018. CLock lock(_mtx);
  1019. TRANSLATE_EXCEPTIONS;
  1020. TRY
  1021. {
  1022. SafeForScripting();
  1023. ValidateInputParam( bstrPropName );
  1024. Initialize();
  1025. WCHAR awcPropVal[MAX_PATH+1];
  1026. if ( !_xMachineAdmin->GetSZParam( bstrPropName,
  1027. awcPropVal,
  1028. sizeof awcPropVal ) )
  1029. {
  1030. sc = E_FAIL;
  1031. }
  1032. else
  1033. {
  1034. BSTR pPropVal = SysAllocString( awcPropVal );
  1035. if ( !pPropVal )
  1036. {
  1037. sc = E_OUTOFMEMORY;
  1038. }
  1039. else
  1040. {
  1041. *pbstrVal = pPropVal;
  1042. }
  1043. }
  1044. }
  1045. CATCH( CException, e )
  1046. {
  1047. sc = e.GetErrorCode();
  1048. }
  1049. END_CATCH
  1050. UNTRANSLATE_EXCEPTIONS;
  1051. if ( FAILED(sc) )
  1052. {
  1053. odmDebugOut(( DEB_ERROR, "GetSZProperty Failed: %x\n", sc ));
  1054. SetErrorInfo( sc );
  1055. }
  1056. return sc;
  1057. }
  1058. //+---------------------------------------------------------------------------
  1059. //
  1060. // Member: CMachineAdm::Pause, public
  1061. //
  1062. // Synopsis: Pauses cisvc service
  1063. //
  1064. // Returns: S_OK upon success, othervalues upon failure
  1065. //
  1066. // History: 10-08-98 kitmanh created
  1067. //
  1068. //----------------------------------------------------------------------------
  1069. STDMETHODIMP CMachineAdm::Pause()
  1070. {
  1071. SCODE sc = S_OK;
  1072. CLock lock(_mtx);
  1073. TRANSLATE_EXCEPTIONS;
  1074. TRY
  1075. {
  1076. SafeForScripting();
  1077. Initialize();
  1078. _xMachineAdmin->PauseCI();
  1079. }
  1080. CATCH( CException, e )
  1081. {
  1082. sc = e.GetErrorCode();
  1083. }
  1084. END_CATCH
  1085. UNTRANSLATE_EXCEPTIONS;
  1086. if ( FAILED(sc) )
  1087. {
  1088. odmDebugOut(( DEB_ERROR, "Pause cisvc Failed: %x\n", sc ));
  1089. SetErrorInfo( sc );
  1090. }
  1091. return sc;
  1092. }
  1093. //+---------------------------------------------------------------------------
  1094. //
  1095. // Member: CMachineAdm::Continue, public
  1096. //
  1097. // Synopsis: Continues cisvc service
  1098. //
  1099. // Returns: S_OK upon success, othervalues upon failure
  1100. //
  1101. // History: 09-08-98 kitmanh created
  1102. //
  1103. //----------------------------------------------------------------------------
  1104. STDMETHODIMP CMachineAdm::Continue()
  1105. {
  1106. SCODE sc = S_OK;
  1107. CLock lock(_mtx);
  1108. TRANSLATE_EXCEPTIONS;
  1109. TRY
  1110. {
  1111. SafeForScripting();
  1112. Initialize();
  1113. _xMachineAdmin->StartCI();
  1114. }
  1115. CATCH( CException, e )
  1116. {
  1117. sc = e.GetErrorCode();
  1118. }
  1119. END_CATCH
  1120. UNTRANSLATE_EXCEPTIONS;
  1121. if ( FAILED(sc) )
  1122. {
  1123. odmDebugOut(( DEB_ERROR, "Start cisvc Failed: %x\n", sc ));
  1124. SetErrorInfo( sc );
  1125. }
  1126. return sc;
  1127. }
  1128. //+---------------------------------------------------------------------------
  1129. //
  1130. // Member: CMachineAdm::SafeForScripting, public
  1131. //
  1132. // Synopsis: determines if it is safe to invoke this method from a given client site.
  1133. //
  1134. // Arguments: none.
  1135. //
  1136. // Returns: E_ACCESSDENIED if not safe to run, else S_OK
  1137. //
  1138. // History: 9/10/98 mohamedn created
  1139. //
  1140. //----------------------------------------------------------------------------
  1141. void CMachineAdm::SafeForScripting()
  1142. {
  1143. SCODE sc = S_OK;
  1144. if ( m_spUnkSite || m_dwSafety )
  1145. {
  1146. Win4Assert( m_spUnkSite );
  1147. XInterface<IUnknown> xpunkSite;
  1148. sc = GetSite( IID_IUnknown, xpunkSite.GetQIPointer() ); // m_spUnkSite
  1149. if ( FAILED(sc) )
  1150. {
  1151. odmDebugOut(( DEB_ERROR, "GetSite Failed sc: %x, m_spUnkSite: %x, punkSite:%x, m_dwSafety:%x\n", sc, m_spUnkSite, xpunkSite.GetPointer() , m_dwSafety ));
  1152. THROW( CException( E_ACCESSDENIED ) );
  1153. }
  1154. else
  1155. {
  1156. Win4Assert( !xpunkSite.IsNull() );
  1157. if ( m_dwSafety && LocalZoneCheck(xpunkSite.GetPointer()) != S_OK)
  1158. {
  1159. odmDebugOut(( DEB_ERROR, "LocalZoneCheck() Failed, Access denied\n" ));
  1160. THROW( CException( E_ACCESSDENIED ) );
  1161. }
  1162. }
  1163. }
  1164. }
  1165. //+---------------------------------------------------------------------------
  1166. //
  1167. // Member: CMachineAdm::IUnknown_QueryService, private
  1168. //
  1169. // Synopsis: determines if it is safe to invoke this method from a given client site.
  1170. //
  1171. // Arguments: [punk] -- site's IUnkown
  1172. // [guidService] -- sp guid
  1173. // [riid] -- interface to query for.
  1174. // [ppvOut] -- out param, contaiing found interface
  1175. //
  1176. // Returns: S_OK upon success, failure codes otherwise.
  1177. //
  1178. // History: 9/10/98 mohamedn created
  1179. //
  1180. //----------------------------------------------------------------------------
  1181. HRESULT CMachineAdm::IUnknown_QueryService(IUnknown* punk, REFGUID guidService, REFIID riid, void **ppvOut)
  1182. {
  1183. HRESULT hres;
  1184. XInterface<IServiceProvider> xPsp;
  1185. *ppvOut = NULL;
  1186. if (!punk)
  1187. return E_FAIL;
  1188. hres = punk->QueryInterface(IID_IServiceProvider, xPsp.GetQIPointer() );
  1189. if ( SUCCEEDED(hres) )
  1190. {
  1191. hres = xPsp->QueryService(guidService, riid, ppvOut);
  1192. }
  1193. return hres;
  1194. }
  1195. //+---------------------------------------------------------------------------
  1196. //
  1197. // Member: CMachineAdm::GetHTMLDoc2, private
  1198. //
  1199. // Synopsis: determines if it is safe to invoke this method from a given client site.
  1200. //
  1201. // Arguments: [punk] -- site's IUnknown
  1202. // [ppHtmlDoc] -- out param to htm doc
  1203. //
  1204. // Returns: S_OK upon success, failure codes otherwise.
  1205. //
  1206. // History: 9/10/98 mohamedn created
  1207. //
  1208. //----------------------------------------------------------------------------
  1209. HRESULT CMachineAdm::GetHTMLDoc2(IUnknown *punk, IHTMLDocument2 **ppHtmlDoc)
  1210. {
  1211. HRESULT hr = E_NOINTERFACE;
  1212. *ppHtmlDoc = NULL;
  1213. // The window.external, jscript "new ActiveXObject" and the <OBJECT> tag
  1214. // don't take us down the same road.
  1215. XInterface<IOleClientSite> xClientSite;
  1216. hr = punk->QueryInterface(IID_IOleClientSite, xClientSite.GetQIPointer());
  1217. if (SUCCEEDED(hr))
  1218. {
  1219. // <OBJECT> tag path
  1220. XInterface<IOleContainer> xContainer;
  1221. hr = xClientSite->GetContainer(xContainer.GetPPointer());
  1222. if (SUCCEEDED(hr))
  1223. {
  1224. hr = xContainer->QueryInterface(IID_IHTMLDocument2, (void **)ppHtmlDoc);
  1225. }
  1226. if (FAILED(hr))
  1227. {
  1228. // window.external path
  1229. XInterface<IWebBrowser2> xWebBrowser2;
  1230. hr = IUnknown_QueryService(xClientSite.GetPointer(), SID_SWebBrowserApp, IID_IHTMLDocument2, xWebBrowser2.GetQIPointer() );
  1231. if (SUCCEEDED(hr))
  1232. {
  1233. XInterface<IDispatch> xDispatch;
  1234. hr = xWebBrowser2->get_Document(xDispatch.GetPPointer());
  1235. if (SUCCEEDED(hr))
  1236. {
  1237. hr = xDispatch->QueryInterface(IID_IHTMLDocument2, (void **)ppHtmlDoc);
  1238. }
  1239. }
  1240. }
  1241. }
  1242. else
  1243. {
  1244. // jscript path
  1245. hr = IUnknown_QueryService(punk, SID_SContainerDispatch, IID_IHTMLDocument2, (void **)ppHtmlDoc);
  1246. }
  1247. Win4Assert( FAILED(hr) || (*ppHtmlDoc) );
  1248. return hr;
  1249. }
  1250. //+---------------------------------------------------------------------------
  1251. //
  1252. // Member: CMachineAdm::LocalZoneCheckPath, private
  1253. //
  1254. // Synopsis: determines if it is safe to invoke this method from a given client site.
  1255. //
  1256. // Arguments: [pbstrPath] -- out param. Path of htm page.
  1257. //
  1258. // Returns: S_OK upon success, failure codes otherwise.
  1259. //
  1260. // History: 9/10/98 mohamedn created
  1261. //
  1262. //----------------------------------------------------------------------------
  1263. HRESULT CMachineAdm::LocalZoneCheckPath(LPCWSTR pbstrPath)
  1264. {
  1265. HRESULT hr = E_ACCESSDENIED;
  1266. if (pbstrPath)
  1267. {
  1268. XInterface<IInternetSecurityManager> xSecMgr;
  1269. if (SUCCEEDED(CoCreateInstance(CLSID_InternetSecurityManager,
  1270. NULL, CLSCTX_INPROC_SERVER,
  1271. IID_IInternetSecurityManager,
  1272. xSecMgr.GetQIPointer())))
  1273. {
  1274. DWORD dwZoneID = URLZONE_UNTRUSTED;
  1275. if (SUCCEEDED(xSecMgr->MapUrlToZone(pbstrPath, &dwZoneID, 0)))
  1276. {
  1277. if (dwZoneID == URLZONE_LOCAL_MACHINE)
  1278. hr = S_OK;
  1279. }
  1280. }
  1281. }
  1282. else
  1283. {
  1284. hr = E_INVALIDARG;
  1285. }
  1286. return hr;
  1287. }
  1288. //+---------------------------------------------------------------------------
  1289. //
  1290. // Member: CMachineAdm::LocalZoneCheck, private
  1291. //
  1292. // Synopsis: determines if it is safe to invoke this method from a given client site.
  1293. //
  1294. // Arguments: [punkSite] -- site's IUnknown.
  1295. //
  1296. // Returns: S_OK upon success, failure codes otherwise.
  1297. //
  1298. // History: 9/10/98 mohamedn created
  1299. //
  1300. //----------------------------------------------------------------------------
  1301. HRESULT CMachineAdm::LocalZoneCheck(IUnknown *punkSite)
  1302. {
  1303. // Return S_FALSE if we don't have a host site since we have no way of doing a
  1304. // security check. This is as far as VB 5.0 apps get.
  1305. if (!punkSite)
  1306. return S_FALSE;
  1307. // Try to use the URL from the document to zone check
  1308. XInterface<IHTMLDocument2> xHtmlDoc;
  1309. HRESULT hr = E_ACCESSDENIED;
  1310. if (SUCCEEDED(GetHTMLDoc2(punkSite, xHtmlDoc.GetPPointer()) ))
  1311. {
  1312. Win4Assert(xHtmlDoc.GetPointer());
  1313. BSTR bstrPath;
  1314. if ( SUCCEEDED( xHtmlDoc->get_URL(&bstrPath) ))
  1315. {
  1316. hr = LocalZoneCheckPath( bstrPath );
  1317. SysFreeString(bstrPath);
  1318. }
  1319. }
  1320. return hr;
  1321. }