Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1090 lines
24 KiB

  1. //---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1995
  5. //
  6. // File: ccomp.cxx
  7. //
  8. // Contents:
  9. //
  10. // History: 11-1-96 t-ptam Created.
  11. //
  12. //----------------------------------------------------------------------------
  13. #include "NWCOMPAT.hxx"
  14. #pragma hdrstop
  15. DEFINE_IDispatch_ExtMgr_Implementation(CNWCOMPATComputer)
  16. DEFINE_IADs_TempImplementation(CNWCOMPATComputer)
  17. DEFINE_IADs_PutGetImplementation(CNWCOMPATComputer, ComputerClass,gdwComputerTableSize)
  18. DEFINE_IADsPropertyList_Implementation(CNWCOMPATComputer, ComputerClass, gdwComputerTableSize)
  19. //----------------------------------------------------------------------------
  20. //
  21. // Function: CNWCOMPATComputer::CNWCOMPATComputer
  22. //
  23. // Synopsis:
  24. //
  25. //----------------------------------------------------------------------------
  26. CNWCOMPATComputer::CNWCOMPATComputer():
  27. _pDispMgr(NULL),
  28. _pExtMgr(NULL),
  29. _pPropertyCache(NULL)
  30. {
  31. VariantInit(&_vFilter);
  32. ENLIST_TRACKING(CNWCOMPATComputer);
  33. }
  34. //----------------------------------------------------------------------------
  35. //
  36. // Function: CNWCOMPATComputer::~CNWCOMPATComputer
  37. //
  38. // Synopsis:
  39. //
  40. //----------------------------------------------------------------------------
  41. CNWCOMPATComputer::~CNWCOMPATComputer( )
  42. {
  43. if (_pExtMgr) {
  44. delete _pExtMgr; // created last, destroyed first
  45. }
  46. if (_pDispMgr)
  47. delete _pDispMgr;
  48. if (_pPropertyCache)
  49. delete _pPropertyCache;
  50. VariantClear(&_vFilter);
  51. }
  52. //----------------------------------------------------------------------------
  53. //
  54. // Function: CNWCOMPATComputer::CreateComputer
  55. //
  56. // Synopsis:
  57. //
  58. //----------------------------------------------------------------------------
  59. HRESULT
  60. CNWCOMPATComputer::CreateComputer(
  61. BSTR bstrParent,
  62. BSTR bstrComputerName,
  63. DWORD dwObjectState,
  64. REFIID riid,
  65. void **ppvObj
  66. )
  67. {
  68. CNWCOMPATComputer FAR * pComputer = NULL;
  69. HRESULT hr = S_OK;
  70. hr = AllocateComputerObject(
  71. &pComputer
  72. );
  73. BAIL_ON_FAILURE(hr);
  74. hr = pComputer->InitializeCoreObject(
  75. bstrParent,
  76. bstrComputerName,
  77. L"computer",
  78. COMPUTER_SCHEMA_NAME,
  79. CLSID_NWCOMPATComputer,
  80. dwObjectState
  81. );
  82. BAIL_ON_FAILURE(hr);
  83. hr = pComputer->QueryInterface(riid, ppvObj);
  84. BAIL_ON_FAILURE(hr);
  85. pComputer->Release();
  86. hr = pComputer->_pExtMgr->FinalInitializeExtensions();
  87. BAIL_ON_FAILURE(hr);
  88. RRETURN(hr);
  89. error:
  90. delete pComputer;
  91. RRETURN_EXP_IF_ERR(hr);
  92. }
  93. //----------------------------------------------------------------------------
  94. //
  95. // Function:
  96. //
  97. // Synopsis:
  98. //
  99. //----------------------------------------------------------------------------
  100. STDMETHODIMP
  101. CNWCOMPATComputer::QueryInterface(
  102. REFIID iid,
  103. LPVOID FAR* ppv
  104. )
  105. {
  106. if (!ppv) {
  107. RRETURN(E_POINTER);
  108. }
  109. //
  110. // Query.
  111. //
  112. if (IsEqualIID(iid, IID_IUnknown))
  113. {
  114. *ppv = (IADsComputer FAR *) this;
  115. }
  116. else if (IsEqualIID(iid, IID_IADsComputer))
  117. {
  118. *ppv = (IADsComputer FAR *) this;
  119. }
  120. else if (IsEqualIID(iid, IID_IADsContainer))
  121. {
  122. *ppv = (IADsContainer FAR *) this;
  123. }
  124. else if (IsEqualIID(iid, IID_IADs))
  125. {
  126. *ppv = (IADsComputer FAR *) this;
  127. }
  128. else if (IsEqualIID(iid, IID_IDispatch))
  129. {
  130. *ppv = (IADsComputer FAR *) this;
  131. }
  132. else if (IsEqualIID(iid, IID_ISupportErrorInfo))
  133. {
  134. *ppv = (ISupportErrorInfo FAR *) this;
  135. }
  136. else if (IsEqualIID(iid, IID_IADsComputerOperations))
  137. {
  138. *ppv = (IADsComputerOperations FAR *) this;
  139. }
  140. else if (IsEqualIID(iid, IID_IADsPropertyList))
  141. {
  142. *ppv = (IADsPropertyList FAR *) this;
  143. }
  144. else if (_pExtMgr)
  145. {
  146. RRETURN( _pExtMgr->QueryInterface(iid, ppv));
  147. }
  148. else
  149. {
  150. *ppv = NULL;
  151. return E_NOINTERFACE;
  152. }
  153. AddRef();
  154. return NOERROR;
  155. }
  156. //
  157. // ISupportErrorInfo method
  158. //
  159. STDMETHODIMP
  160. CNWCOMPATComputer::InterfaceSupportsErrorInfo(
  161. THIS_ REFIID riid
  162. )
  163. {
  164. if (IsEqualIID(riid, IID_IADs) ||
  165. IsEqualIID(riid, IID_IADsComputer) ||
  166. IsEqualIID(riid, IID_IADsComputerOperations) ||
  167. IsEqualIID(riid, IID_IADsContainer) ||
  168. IsEqualIID(riid, IID_IADsPropertyList)) {
  169. RRETURN(S_OK);
  170. } else {
  171. RRETURN(S_FALSE);
  172. }
  173. }
  174. //
  175. // IADsContainer methods
  176. //
  177. //----------------------------------------------------------------------------
  178. //
  179. // Function: CNWCOMPATComputer::get_Count
  180. //
  181. // Synopsis:
  182. //
  183. //----------------------------------------------------------------------------
  184. STDMETHODIMP
  185. CNWCOMPATComputer::get_Count(long FAR* retval)
  186. {
  187. //
  188. // Too expensive to implement in term of computer execution time.
  189. //
  190. RRETURN_EXP_IF_ERR(E_NOTIMPL);
  191. }
  192. //----------------------------------------------------------------------------
  193. //
  194. // Function: CNWCOMPATComputer::get_Filter
  195. //
  196. // Synopsis:
  197. //
  198. //----------------------------------------------------------------------------
  199. STDMETHODIMP
  200. CNWCOMPATComputer::get_Filter(THIS_ VARIANT FAR* pVar)
  201. {
  202. HRESULT hr;
  203. VariantInit(pVar);
  204. hr = VariantCopy(pVar, &_vFilter);
  205. RRETURN_EXP_IF_ERR(hr);
  206. }
  207. //----------------------------------------------------------------------------
  208. //
  209. // Function: CNWCOMPATComputer::put_Filter
  210. //
  211. // Synopsis:
  212. //
  213. //----------------------------------------------------------------------------
  214. STDMETHODIMP
  215. CNWCOMPATComputer::put_Filter(THIS_ VARIANT Var)
  216. {
  217. HRESULT hr;
  218. hr = VariantCopy(&_vFilter, &Var);
  219. RRETURN_EXP_IF_ERR(hr);
  220. }
  221. STDMETHODIMP
  222. CNWCOMPATComputer::put_Hints(THIS_ VARIANT Var)
  223. {
  224. RRETURN_EXP_IF_ERR( E_NOTIMPL);
  225. }
  226. STDMETHODIMP
  227. CNWCOMPATComputer::get_Hints(THIS_ VARIANT FAR* pVar)
  228. {
  229. RRETURN_EXP_IF_ERR(E_NOTIMPL);
  230. }
  231. //----------------------------------------------------------------------------
  232. //
  233. // Function: CNWCOMPATComputer::GetObject
  234. //
  235. // Synopsis:
  236. //
  237. //----------------------------------------------------------------------------
  238. STDMETHODIMP
  239. CNWCOMPATComputer::GetObject(
  240. THIS_ BSTR ClassName,
  241. BSTR RelativeName,
  242. IDispatch * FAR* ppObject
  243. )
  244. {
  245. WCHAR szBuffer[MAX_PATH];
  246. HRESULT hr = S_OK;
  247. if (!RelativeName || !*RelativeName) {
  248. RRETURN_EXP_IF_ERR(E_ADS_UNKNOWN_OBJECT);
  249. }
  250. memset(szBuffer, 0, sizeof(szBuffer));
  251. wcscpy(szBuffer, _ADsPath);
  252. wcscat(szBuffer, L"/");
  253. wcscat(szBuffer, RelativeName);
  254. if (ClassName && *ClassName) {
  255. wcscat(szBuffer,L",");
  256. wcscat(szBuffer, ClassName);
  257. }
  258. hr = ::GetObject(
  259. szBuffer,
  260. (LPVOID *)ppObject
  261. );
  262. BAIL_ON_FAILURE(hr);
  263. error:
  264. RRETURN_EXP_IF_ERR(hr);
  265. }
  266. //----------------------------------------------------------------------------
  267. //
  268. // Function: CNWCOMPATComputer::get__NewEnum
  269. //
  270. // Synopsis:
  271. //
  272. //----------------------------------------------------------------------------
  273. STDMETHODIMP
  274. CNWCOMPATComputer::get__NewEnum(THIS_ IUnknown * FAR* retval)
  275. {
  276. HRESULT hr;
  277. IEnumVARIANT * penum = NULL;
  278. if (!retval) {
  279. RRETURN_EXP_IF_ERR(E_POINTER);
  280. }
  281. *retval = NULL;
  282. hr = CNWCOMPATComputerEnum::Create(
  283. (CNWCOMPATComputerEnum **)&penum,
  284. _ADsPath,
  285. _Name,
  286. _vFilter
  287. );
  288. BAIL_ON_FAILURE(hr);
  289. hr = penum->QueryInterface(
  290. IID_IUnknown,
  291. (VOID FAR* FAR*)retval
  292. );
  293. BAIL_ON_FAILURE(hr);
  294. if (penum) {
  295. penum->Release();
  296. }
  297. RRETURN(NOERROR);
  298. error:
  299. if (penum) {
  300. delete penum;
  301. }
  302. RRETURN_EXP_IF_ERR(hr);
  303. }
  304. //----------------------------------------------------------------------------
  305. //
  306. // Function: CNWCOMPATComputer::Create
  307. //
  308. // Synopsis:
  309. //
  310. //----------------------------------------------------------------------------
  311. STDMETHODIMP
  312. CNWCOMPATComputer::Create(
  313. THIS_ BSTR ClassName,
  314. BSTR RelativeName,
  315. IDispatch * FAR* ppObject
  316. )
  317. {
  318. ULONG ObjectType = 0;
  319. HRESULT hr = S_OK;
  320. POBJECTINFO pObjectInfo = NULL;
  321. //
  322. // Translate ClassName into object type.
  323. //
  324. hr = GetObjectType(
  325. gpFilters,
  326. gdwMaxFilters,
  327. ClassName,
  328. (PDWORD)&ObjectType
  329. );
  330. BAIL_ON_FAILURE(hr);
  331. //
  332. // Build object info structure.
  333. //
  334. hr = BuildObjectInfo(
  335. _ADsPath,
  336. RelativeName,
  337. &pObjectInfo
  338. );
  339. BAIL_ON_FAILURE(hr);
  340. //
  341. // Create the object.
  342. //
  343. switch (ObjectType) {
  344. case NWCOMPAT_USER_ID:
  345. hr = CNWCOMPATUser::CreateUser(
  346. _ADsPath,
  347. NWCOMPAT_COMPUTER_ID,
  348. _Name,
  349. RelativeName,
  350. ADS_OBJECT_UNBOUND,
  351. IID_IDispatch,
  352. (void **)ppObject
  353. );
  354. BAIL_ON_FAILURE(hr);
  355. break;
  356. case NWCOMPAT_GROUP_ID:
  357. hr = CNWCOMPATGroup::CreateGroup(
  358. _ADsPath,
  359. NWCOMPAT_COMPUTER_ID,
  360. _Name,
  361. RelativeName,
  362. ADS_OBJECT_UNBOUND,
  363. IID_IDispatch,
  364. (void **)ppObject
  365. );
  366. BAIL_ON_FAILURE(hr);
  367. break;
  368. case NWCOMPAT_PRINTER_ID:
  369. hr = NWApiCreatePrinter(
  370. pObjectInfo
  371. );
  372. BAIL_ON_FAILURE(hr);
  373. hr = CNWCOMPATPrintQueue::CreatePrintQueue(
  374. _ADsPath,
  375. pObjectInfo->ComponentArray[1],
  376. ADS_OBJECT_BOUND,
  377. IID_IDispatch,
  378. (void **)ppObject
  379. );
  380. BAIL_ON_FAILURE(hr);
  381. break;
  382. default:
  383. hr = E_ADS_SCHEMA_VIOLATION;
  384. BAIL_ON_FAILURE(hr);
  385. }
  386. error:
  387. FreeObjectInfo(pObjectInfo);
  388. RRETURN_EXP_IF_ERR(hr);
  389. }
  390. //----------------------------------------------------------------------------
  391. //
  392. // Function: CNWCOMPATComputer::Delete
  393. //
  394. // Synopsis:
  395. //
  396. //----------------------------------------------------------------------------
  397. STDMETHODIMP
  398. CNWCOMPATComputer::Delete(
  399. THIS_ BSTR bstrClassName,
  400. BSTR bstrRelativeName)
  401. {
  402. ULONG ObjectType = 0;
  403. POBJECTINFO pObjectInfo = NULL;
  404. HRESULT hr = S_OK;
  405. //
  406. // Translate ClassName into object type.
  407. //
  408. hr = GetObjectType(
  409. gpFilters,
  410. gdwMaxFilters,
  411. bstrClassName,
  412. (PDWORD)&ObjectType
  413. );
  414. BAIL_ON_FAILURE(hr);
  415. //
  416. // Build object info structure.
  417. //
  418. hr = BuildObjectInfo(
  419. _ADsPath,
  420. bstrRelativeName,
  421. &pObjectInfo
  422. );
  423. BAIL_ON_FAILURE(hr);
  424. //
  425. // Delete the object.
  426. //
  427. switch (ObjectType) {
  428. case NWCOMPAT_USER_ID:
  429. hr = NWApiDeleteUser(
  430. pObjectInfo
  431. );
  432. BAIL_ON_FAILURE(hr);
  433. break;
  434. case NWCOMPAT_GROUP_ID:
  435. hr = NWApiDeleteGroup(
  436. pObjectInfo
  437. );
  438. BAIL_ON_FAILURE(hr);
  439. break;
  440. case NWCOMPAT_PRINTER_ID:
  441. hr = NWApiDeletePrinter(
  442. pObjectInfo
  443. );
  444. BAIL_ON_FAILURE(hr);
  445. break;
  446. default:
  447. hr = E_ADS_UNKNOWN_OBJECT;
  448. BAIL_ON_FAILURE(hr);
  449. }
  450. error:
  451. FreeObjectInfo(pObjectInfo);
  452. RRETURN_EXP_IF_ERR(hr);
  453. }
  454. //----------------------------------------------------------------------------
  455. //
  456. // Function: CNWCOMPATComputer::CopyHere
  457. //
  458. // Synopsis:
  459. //
  460. //----------------------------------------------------------------------------
  461. STDMETHODIMP
  462. CNWCOMPATComputer::CopyHere(
  463. THIS_ BSTR SourceName,
  464. BSTR NewName,
  465. IDispatch * FAR* ppObject
  466. )
  467. {
  468. RRETURN_EXP_IF_ERR(E_NOTIMPL);
  469. }
  470. //----------------------------------------------------------------------------
  471. //
  472. // Function: CNWCOMPATComputer::MoveHere
  473. //
  474. // Synopsis:
  475. //
  476. //----------------------------------------------------------------------------
  477. STDMETHODIMP
  478. CNWCOMPATComputer::MoveHere(
  479. THIS_ BSTR SourceName,
  480. BSTR NewName,
  481. IDispatch * FAR* ppObject
  482. )
  483. {
  484. RRETURN_EXP_IF_ERR(E_NOTIMPL);
  485. }
  486. //
  487. // IADs methods
  488. //
  489. //----------------------------------------------------------------------------
  490. //
  491. // Function: CNWCOMPATComputer::SetInfo
  492. //
  493. // Synopsis:
  494. //
  495. //----------------------------------------------------------------------------
  496. STDMETHODIMP
  497. CNWCOMPATComputer::SetInfo(THIS)
  498. {
  499. RRETURN_EXP_IF_ERR(E_NOTIMPL);
  500. }
  501. //----------------------------------------------------------------------------
  502. //
  503. // Function: CNWCOMPATComputer::GetInfo
  504. //
  505. // Synopsis:
  506. //
  507. //----------------------------------------------------------------------------
  508. STDMETHODIMP
  509. CNWCOMPATComputer::GetInfo(THIS)
  510. {
  511. _pPropertyCache->flushpropcache();
  512. RRETURN(GetInfo(
  513. TRUE,
  514. COMP_WILD_CARD_ID
  515. ));
  516. }
  517. //
  518. // IADsComputer methods
  519. //
  520. //----------------------------------------------------------------------------
  521. //
  522. // Function: CNWCOMPATComputer::AllocateComputerObject
  523. //
  524. // Synopsis:
  525. //
  526. //----------------------------------------------------------------------------
  527. HRESULT
  528. CNWCOMPATComputer::AllocateComputerObject(
  529. CNWCOMPATComputer ** ppComputer
  530. )
  531. {
  532. CNWCOMPATComputer FAR * pComputer = NULL;
  533. CAggregatorDispMgr FAR * pDispMgr = NULL;
  534. CADsExtMgr FAR * pExtensionMgr = NULL;
  535. CPropertyCache FAR * pPropertyCache = NULL;
  536. HRESULT hr = S_OK;
  537. //
  538. // Allocate memory for a computer object.
  539. //
  540. pComputer = new CNWCOMPATComputer();
  541. if (pComputer == NULL) {
  542. hr = E_OUTOFMEMORY;
  543. }
  544. BAIL_ON_FAILURE(hr);
  545. //
  546. // Create a Dispatch Manager object.
  547. //
  548. pDispMgr = new CAggregatorDispMgr;
  549. if (pDispMgr == NULL) {
  550. hr = E_OUTOFMEMORY;
  551. }
  552. BAIL_ON_FAILURE(hr);
  553. //
  554. // Load type info.
  555. //
  556. hr = LoadTypeInfoEntry(
  557. pDispMgr,
  558. LIBID_ADs,
  559. IID_IADsComputer,
  560. (IADsComputer *)pComputer,
  561. DISPID_REGULAR
  562. );
  563. BAIL_ON_FAILURE(hr);
  564. hr = LoadTypeInfoEntry(
  565. pDispMgr,
  566. LIBID_ADs,
  567. IID_IADsContainer,
  568. (IADsContainer *)pComputer,
  569. DISPID_NEWENUM
  570. );
  571. BAIL_ON_FAILURE(hr);
  572. hr = LoadTypeInfoEntry(
  573. pDispMgr,
  574. LIBID_ADs,
  575. IID_IADsPropertyList,
  576. (IADsPropertyList *)pComputer,
  577. DISPID_VALUE
  578. );
  579. BAIL_ON_FAILURE(hr);
  580. //
  581. // Create property cache
  582. //
  583. hr = CPropertyCache::createpropertycache(
  584. ComputerClass,
  585. gdwComputerTableSize,
  586. (CCoreADsObject *)pComputer,
  587. &pPropertyCache
  588. );
  589. BAIL_ON_FAILURE(hr);
  590. pDispMgr->RegisterPropertyCache(
  591. pPropertyCache
  592. );
  593. hr = ADSILoadExtensionManager(
  594. COMPUTER_CLASS_NAME,
  595. (IADsComputer *) pComputer,
  596. pDispMgr,
  597. &pExtensionMgr
  598. );
  599. BAIL_ON_FAILURE(hr);
  600. pComputer->_pPropertyCache = pPropertyCache;
  601. pComputer->_pDispMgr = pDispMgr;
  602. pComputer->_pExtMgr = pExtensionMgr;
  603. *ppComputer = pComputer;
  604. RRETURN(hr);
  605. error:
  606. //
  607. // Note: pComputer->_pPropertyCache & pComputer->_pDispMgr are NULL
  608. //
  609. if (pComputer)
  610. delete pComputer;
  611. if (pPropertyCache)
  612. delete pPropertyCache;
  613. if (pDispMgr)
  614. delete pDispMgr;
  615. if (pExtensionMgr)
  616. delete pExtensionMgr;
  617. RRETURN(hr);
  618. }
  619. //----------------------------------------------------------------------------
  620. //
  621. // Function: CNWCOMPATComputer::CreateObject
  622. //
  623. // Synopsis:
  624. //
  625. //----------------------------------------------------------------------------
  626. HRESULT
  627. CNWCOMPATComputer::CreateObject(
  628. )
  629. {
  630. RRETURN(S_OK);
  631. }
  632. //----------------------------------------------------------------------------
  633. //
  634. // Function: CNWCOMPATComputer::GetInfo
  635. //
  636. // Synopsis:
  637. //
  638. //----------------------------------------------------------------------------
  639. STDMETHODIMP
  640. CNWCOMPATComputer::GetInfo(
  641. BOOL fExplicit,
  642. DWORD dwPropertyID
  643. )
  644. {
  645. HRESULT hr = S_OK;
  646. HRESULT hrTemp = S_OK;
  647. NWCONN_HANDLE hConn = NULL;
  648. if (GetObjectState() == ADS_OBJECT_UNBOUND) {
  649. RRETURN_EXP_IF_ERR(E_ADS_OBJECT_UNBOUND);
  650. }
  651. //
  652. // Get a handle to the bindery this computer object represents.
  653. //
  654. hr = NWApiGetBinderyHandle(
  655. &hConn,
  656. _Name
  657. );
  658. BAIL_ON_FAILURE(hr);
  659. //
  660. // Fill in all property caches with values - explicit, or return the
  661. // indicated property - implicit.
  662. //
  663. if (fExplicit) {
  664. hr = ExplicitGetInfo(hConn, fExplicit);
  665. BAIL_ON_FAILURE(hr);
  666. }
  667. else {
  668. hr = ImplicitGetInfo(hConn, dwPropertyID, fExplicit);
  669. BAIL_ON_FAILURE(hr);
  670. }
  671. error:
  672. if (hConn) {
  673. hrTemp = NWApiReleaseBinderyHandle(hConn);
  674. }
  675. RRETURN_EXP_IF_ERR(hr);
  676. }
  677. //----------------------------------------------------------------------------
  678. //
  679. // Function: CNWCOMPATComputer::ExplicitGetInfo
  680. //
  681. // Synopsis:
  682. //
  683. //----------------------------------------------------------------------------
  684. HRESULT
  685. CNWCOMPATComputer::ExplicitGetInfo(
  686. NWCONN_HANDLE hConn,
  687. BOOL fExplicit
  688. )
  689. {
  690. HRESULT hr = S_OK;
  691. hr = GetProperty_Addresses(hConn, fExplicit);
  692. BAIL_ON_FAILURE(hr);
  693. hr = GetProperty_OperatingSystem(fExplicit);
  694. BAIL_ON_FAILURE(hr);
  695. hr = GetProperty_OperatingSystemVersion(hConn, fExplicit);
  696. BAIL_ON_FAILURE(hr);
  697. error:
  698. RRETURN(hr);
  699. }
  700. //----------------------------------------------------------------------------
  701. //
  702. // Function: CNWCOMPATComputer::ImplicitGetInfo
  703. //
  704. // Synopsis:
  705. //
  706. //----------------------------------------------------------------------------
  707. HRESULT
  708. CNWCOMPATComputer::ImplicitGetInfo(
  709. NWCONN_HANDLE hConn,
  710. DWORD dwPropertyID,
  711. BOOL fExplicit
  712. )
  713. {
  714. HRESULT hr = S_OK;
  715. switch (dwPropertyID) {
  716. case COMP_ADDRESSES_ID:
  717. hr = GetProperty_Addresses(hConn, fExplicit);
  718. break;
  719. case COMP_OPERATINGSYSTEM_ID:
  720. hr = GetProperty_OperatingSystem(fExplicit);
  721. break;
  722. case COMP_OPERATINGSYSTEMVERSION_ID:
  723. hr = GetProperty_OperatingSystemVersion(hConn, fExplicit);
  724. break;
  725. }
  726. RRETURN(hr);
  727. }
  728. //----------------------------------------------------------------------------
  729. //
  730. // Function: CNWCOMPATComputer::GetProperty_Addresses
  731. //
  732. // Synopsis:
  733. //
  734. //----------------------------------------------------------------------------
  735. HRESULT
  736. CNWCOMPATComputer::GetProperty_Addresses(
  737. NWCONN_HANDLE hConn,
  738. BOOL fExplicit
  739. )
  740. {
  741. //
  742. // We don't (and have never) supported retrieving the NetAddresses property
  743. // under NWCOMPAT, because of limitations in the property cache. We don't support
  744. // it in the WinNT provider, either. Since we've never supported it, this is
  745. // really a feature request, not a bug. Given the general consensus not to add
  746. // new features to the NWCOMPAT provider unless it is customer-requested, I'm
  747. // #ifdef'ing out this code (since it doesn't serve any useful purpose, since it
  748. // never puts anything in the cache), and changing the corresponding
  749. // get_/put_NetAddresses functions in ccgi.cxx to reflect
  750. // E_ADS_PROPERTY_NOT_SUPPORTED. I'm leaving this code in place in case we do
  751. // get a feature request for this, so we can use it as a start.
  752. //
  753. #if 0
  754. BSTR bstrBuffer = NULL;
  755. DWORD dwNumSegment;
  756. HRESULT hr = S_OK;
  757. LP_RPLY_SGMT_LST lpReplySegment = NULL;
  758. LP_RPLY_SGMT_LST lpTemp = NULL; // Used by DELETE_LIST macro below
  759. LPWSTR lpszBuffer = NULL;
  760. VARIANT vData;
  761. //
  762. // Get ADDRESSES.
  763. //
  764. hr = NWApiGetProperty(
  765. _Name,
  766. NW_PROP_NET_ADDRESS,
  767. OT_FILE_SERVER,
  768. hConn,
  769. &lpReplySegment,
  770. &dwNumSegment
  771. );
  772. BAIL_ON_FAILURE(hr);
  773. //
  774. // Put the addresses obtained in the format described in spec.
  775. //
  776. hr = NWApiConvertToAddressFormat(
  777. lpReplySegment,
  778. &lpszBuffer
  779. );
  780. BAIL_ON_FAILURE(hr);
  781. bstrBuffer = SysAllocString(lpszBuffer);
  782. if (!bstrBuffer) {
  783. hr = E_OUTOFMEMORY;
  784. BAIL_ON_FAILURE(hr);
  785. }
  786. //
  787. // for now, Addresses is treated as a BSTR Variant instead of a
  788. // variant array of bstr, as described in the spec.
  789. //
  790. VariantInit(&vData);
  791. V_VT(&vData) = VT_BSTR;
  792. V_BSTR(&vData) = bstrBuffer;
  793. //
  794. // Unmarshall.
  795. //
  796. //
  797. // KrishnaG figure out how we're going to map this property
  798. //
  799. //
  800. // UM_PUT_VARIANT_PROPERTY(vData, _pGenInfo, Addresses, FALSE);
  801. //
  802. VariantClear(&vData);
  803. error:
  804. if (lpReplySegment) {
  805. DELETE_LIST(lpReplySegment);
  806. }
  807. if (lpszBuffer) {
  808. FreeADsMem(lpszBuffer);
  809. }
  810. RRETURN(hr);
  811. #else
  812. RRETURN(S_OK);
  813. #endif
  814. }
  815. //----------------------------------------------------------------------------
  816. //
  817. // Function: CNWCOMPATComputer::GetProperty_OperatingSystem
  818. //
  819. // Synopsis:
  820. //
  821. //----------------------------------------------------------------------------
  822. HRESULT
  823. CNWCOMPATComputer::GetProperty_OperatingSystem(
  824. BOOL fExplicit
  825. )
  826. {
  827. HRESULT hr = S_OK;
  828. //
  829. // As far as I can determine, Bindery does not provide a means of
  830. // retrieving the operating system in use on the server, only the OS
  831. // version (probably because when Bindery was designed, it only
  832. // ran on one OS, NetWare). So we just assign the computer an OS
  833. // name of "NW3Compat".
  834. //
  835. hr = SetLPTSTRPropertyInCache(
  836. _pPropertyCache,
  837. TEXT("OperatingSystem"),
  838. bstrComputerOperatingSystem,
  839. fExplicit
  840. );
  841. RRETURN(hr);
  842. }
  843. //----------------------------------------------------------------------------
  844. //
  845. // Function: CNWCOMPATComputer::GetProperty_OperatingSystemVersion
  846. //
  847. // Synopsis:
  848. //
  849. //----------------------------------------------------------------------------
  850. HRESULT
  851. CNWCOMPATComputer::GetProperty_OperatingSystemVersion(
  852. NWCONN_HANDLE hConn,
  853. BOOL fExplicit
  854. )
  855. {
  856. LPWSTR pszBuffer = NULL;
  857. CHAR ch;
  858. HRESULT hr = S_OK;
  859. VERSION_INFO VersionInfo;
  860. //
  861. // Get Version Information of a bindery.
  862. //
  863. hr = NWApiGetFileServerVersionInfo(
  864. hConn,
  865. &VersionInfo
  866. );
  867. if (SUCCEEDED(hr)) {
  868. //
  869. // Put Version & SubVersion in X.X format.
  870. //
  871. pszBuffer = (LPWSTR) AllocADsMem(
  872. (OS_VERSION_NUM_CHAR+1) * sizeof(WCHAR)
  873. );
  874. if (!pszBuffer) {
  875. hr = E_OUTOFMEMORY;
  876. BAIL_ON_FAILURE(hr);
  877. }
  878. wsprintf(
  879. pszBuffer,
  880. L"%i.%02i",
  881. (WORD) VersionInfo.Version,
  882. (WORD) VersionInfo.SubVersion
  883. );
  884. //
  885. // Unmarshall.
  886. //
  887. hr = SetLPTSTRPropertyInCache(
  888. _pPropertyCache,
  889. TEXT("OperatingSystemVersion"),
  890. pszBuffer,
  891. fExplicit
  892. );
  893. BAIL_ON_FAILURE(hr);
  894. }
  895. //
  896. // not a problem if NWApiGetFileServerVersionInfo failed, we
  897. // just ignore the property and go on
  898. //
  899. hr = S_OK;
  900. error:
  901. if (pszBuffer) {
  902. FreeADsMem(pszBuffer);
  903. }
  904. RRETURN(hr);
  905. }
  906. STDMETHODIMP
  907. CNWCOMPATComputer::Status(
  908. IDispatch * FAR * ppObject
  909. )
  910. {
  911. RRETURN_EXP_IF_ERR(E_NOTIMPL);
  912. }
  913. STDMETHODIMP
  914. CNWCOMPATComputer::Shutdown(
  915. VARIANT_BOOL bReboot
  916. )
  917. {
  918. RRETURN_EXP_IF_ERR(E_NOTIMPL);
  919. }