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.

1212 lines
26 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_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. _pPropertyCache(NULL),
  29. _hConn(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 (_pDispMgr)
  44. delete _pDispMgr;
  45. if (_pPropertyCache)
  46. delete _pPropertyCache;
  47. if (_hConn) {
  48. NWApiReleaseBinderyHandle(_hConn);
  49. }
  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. CCredentials &Credentials,
  64. DWORD dwObjectState,
  65. REFIID riid,
  66. void **ppvObj
  67. )
  68. {
  69. CNWCOMPATComputer FAR * pComputer = NULL;
  70. HRESULT hr = S_OK;
  71. hr = AllocateComputerObject(
  72. &pComputer
  73. );
  74. BAIL_ON_FAILURE(hr);
  75. hr = pComputer->InitializeCoreObject(
  76. bstrParent,
  77. bstrComputerName,
  78. L"computer",
  79. COMPUTER_SCHEMA_NAME,
  80. CLSID_NWCOMPATComputer,
  81. dwObjectState
  82. );
  83. BAIL_ON_FAILURE(hr);
  84. pComputer->_Credentials = Credentials;
  85. hr = pComputer->QueryInterface(riid, ppvObj);
  86. BAIL_ON_FAILURE(hr);
  87. pComputer->Release();
  88. RRETURN(hr);
  89. error:
  90. delete pComputer;
  91. NW_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
  145. {
  146. *ppv = NULL;
  147. return E_NOINTERFACE;
  148. }
  149. AddRef();
  150. return NOERROR;
  151. }
  152. //
  153. // ISupportErrorInfo method
  154. //
  155. STDMETHODIMP
  156. CNWCOMPATComputer::InterfaceSupportsErrorInfo(
  157. THIS_ REFIID riid
  158. )
  159. {
  160. if (IsEqualIID(riid, IID_IADs) ||
  161. IsEqualIID(riid, IID_IADsComputer) ||
  162. IsEqualIID(riid, IID_IADsComputerOperations) ||
  163. IsEqualIID(riid, IID_IADsContainer) ||
  164. IsEqualIID(riid, IID_IADsPropertyList)) {
  165. RRETURN(S_OK);
  166. } else {
  167. RRETURN(S_FALSE);
  168. }
  169. }
  170. //
  171. // IADsContainer methods
  172. //
  173. //----------------------------------------------------------------------------
  174. //
  175. // Function: CNWCOMPATComputer::get_Count
  176. //
  177. // Synopsis:
  178. //
  179. //----------------------------------------------------------------------------
  180. STDMETHODIMP
  181. CNWCOMPATComputer::get_Count(long FAR* retval)
  182. {
  183. //
  184. // Too expensive to implement in term of computer execution time.
  185. //
  186. NW_RRETURN_EXP_IF_ERR(E_NOTIMPL);
  187. }
  188. //----------------------------------------------------------------------------
  189. //
  190. // Function: CNWCOMPATComputer::get_Filter
  191. //
  192. // Synopsis:
  193. //
  194. //----------------------------------------------------------------------------
  195. STDMETHODIMP
  196. CNWCOMPATComputer::get_Filter(THIS_ VARIANT FAR* pVar)
  197. {
  198. HRESULT hr;
  199. VariantInit(pVar);
  200. hr = VariantCopy(pVar, &_vFilter);
  201. NW_RRETURN_EXP_IF_ERR(hr);
  202. }
  203. //----------------------------------------------------------------------------
  204. //
  205. // Function: CNWCOMPATComputer::put_Filter
  206. //
  207. // Synopsis:
  208. //
  209. //----------------------------------------------------------------------------
  210. STDMETHODIMP
  211. CNWCOMPATComputer::put_Filter(THIS_ VARIANT Var)
  212. {
  213. HRESULT hr;
  214. hr = VariantCopy(&_vFilter, &Var);
  215. NW_RRETURN_EXP_IF_ERR(hr);
  216. }
  217. STDMETHODIMP
  218. CNWCOMPATComputer::put_Hints(THIS_ VARIANT Var)
  219. {
  220. NW_RRETURN_EXP_IF_ERR( E_NOTIMPL);
  221. }
  222. STDMETHODIMP
  223. CNWCOMPATComputer::get_Hints(THIS_ VARIANT FAR* pVar)
  224. {
  225. NW_RRETURN_EXP_IF_ERR(E_NOTIMPL);
  226. }
  227. //----------------------------------------------------------------------------
  228. //
  229. // Function: CNWCOMPATComputer::GetObject
  230. //
  231. // Synopsis:
  232. //
  233. //----------------------------------------------------------------------------
  234. STDMETHODIMP
  235. CNWCOMPATComputer::GetObject(
  236. THIS_ BSTR ClassName,
  237. BSTR RelativeName,
  238. IDispatch * FAR* ppObject
  239. )
  240. {
  241. WCHAR szBuffer[MAX_PATH];
  242. HRESULT hr = S_OK;
  243. if (!RelativeName || !*RelativeName) {
  244. NW_RRETURN_EXP_IF_ERR(E_ADS_UNKNOWN_OBJECT);
  245. }
  246. wcscpy(szBuffer, _ADsPath);
  247. wcscat(szBuffer, L"/");
  248. wcscat(szBuffer, RelativeName);
  249. if (ClassName && *ClassName) {
  250. wcscat(szBuffer,L",");
  251. wcscat(szBuffer, ClassName);
  252. }
  253. hr = ::GetObject(
  254. szBuffer,
  255. _Credentials,
  256. (LPVOID *)ppObject
  257. );
  258. BAIL_ON_FAILURE(hr);
  259. error:
  260. NW_RRETURN_EXP_IF_ERR(hr);
  261. }
  262. //----------------------------------------------------------------------------
  263. //
  264. // Function: CNWCOMPATComputer::get__NewEnum
  265. //
  266. // Synopsis:
  267. //
  268. //----------------------------------------------------------------------------
  269. STDMETHODIMP
  270. CNWCOMPATComputer::get__NewEnum(THIS_ IUnknown * FAR* retval)
  271. {
  272. HRESULT hr;
  273. IEnumVARIANT * penum = NULL;
  274. if (!retval) {
  275. NW_RRETURN_EXP_IF_ERR(E_POINTER);
  276. }
  277. *retval = NULL;
  278. hr = CNWCOMPATComputerEnum::Create(
  279. (CNWCOMPATComputerEnum **)&penum,
  280. _ADsPath,
  281. _Name,
  282. _Credentials,
  283. _vFilter
  284. );
  285. BAIL_ON_FAILURE(hr);
  286. hr = penum->QueryInterface(
  287. IID_IUnknown,
  288. (VOID FAR* FAR*)retval
  289. );
  290. BAIL_ON_FAILURE(hr);
  291. if (penum) {
  292. penum->Release();
  293. }
  294. RRETURN(NOERROR);
  295. error:
  296. if (penum) {
  297. delete penum;
  298. }
  299. NW_RRETURN_EXP_IF_ERR(hr);
  300. }
  301. //----------------------------------------------------------------------------
  302. //
  303. // Function: CNWCOMPATComputer::Create
  304. //
  305. // Synopsis:
  306. //
  307. //----------------------------------------------------------------------------
  308. STDMETHODIMP
  309. CNWCOMPATComputer::Create(
  310. THIS_ BSTR ClassName,
  311. BSTR RelativeName,
  312. IDispatch * FAR* ppObject
  313. )
  314. {
  315. ULONG ObjectType = 0;
  316. HRESULT hr = S_OK;
  317. POBJECTINFO pObjectInfo = NULL;
  318. //
  319. // Translate ClassName into object type.
  320. //
  321. hr = GetObjectType(
  322. gpFilters,
  323. gdwMaxFilters,
  324. ClassName,
  325. (PDWORD)&ObjectType
  326. );
  327. BAIL_ON_FAILURE(hr);
  328. //
  329. // Build object info structure.
  330. //
  331. hr = BuildObjectInfo(
  332. _ADsPath,
  333. RelativeName,
  334. &pObjectInfo
  335. );
  336. BAIL_ON_FAILURE(hr);
  337. //
  338. // Create the object.
  339. //
  340. switch (ObjectType) {
  341. case NWCOMPAT_USER_ID:
  342. hr = CNWCOMPATUser::CreateUser(
  343. _ADsPath,
  344. NWCOMPAT_COMPUTER_ID,
  345. _Name,
  346. RelativeName,
  347. _Credentials,
  348. ADS_OBJECT_UNBOUND,
  349. IID_IDispatch,
  350. (void **)ppObject
  351. );
  352. BAIL_ON_FAILURE(hr);
  353. break;
  354. case NWCOMPAT_GROUP_ID:
  355. hr = CNWCOMPATGroup::CreateGroup(
  356. _ADsPath,
  357. NWCOMPAT_COMPUTER_ID,
  358. _Name,
  359. RelativeName,
  360. _Credentials,
  361. ADS_OBJECT_UNBOUND,
  362. IID_IDispatch,
  363. (void **)ppObject
  364. );
  365. BAIL_ON_FAILURE(hr);
  366. break;
  367. case NWCOMPAT_PRINTER_ID:
  368. hr = NWApiCreatePrinter(
  369. pObjectInfo,
  370. _Credentials
  371. );
  372. BAIL_ON_FAILURE(hr);
  373. hr = CNWCOMPATPrintQueue::CreatePrintQueue(
  374. _ADsPath,
  375. pObjectInfo->ComponentArray[1],
  376. _Credentials,
  377. ADS_OBJECT_BOUND,
  378. IID_IDispatch,
  379. (void **)ppObject
  380. );
  381. BAIL_ON_FAILURE(hr);
  382. break;
  383. default:
  384. hr = E_ADS_UNKNOWN_OBJECT;
  385. BAIL_ON_FAILURE(hr);
  386. }
  387. error:
  388. FreeObjectInfo(pObjectInfo);
  389. NW_RRETURN_EXP_IF_ERR(hr);
  390. }
  391. //----------------------------------------------------------------------------
  392. //
  393. // Function: CNWCOMPATComputer::Delete
  394. //
  395. // Synopsis:
  396. //
  397. //----------------------------------------------------------------------------
  398. STDMETHODIMP
  399. CNWCOMPATComputer::Delete(
  400. THIS_ BSTR bstrClassName,
  401. BSTR bstrRelativeName)
  402. {
  403. ULONG ObjectType = 0;
  404. POBJECTINFO pObjectInfo = NULL;
  405. HRESULT hr = S_OK;
  406. //
  407. // Translate ClassName into object type.
  408. //
  409. hr = GetObjectType(
  410. gpFilters,
  411. gdwMaxFilters,
  412. bstrClassName,
  413. (PDWORD)&ObjectType
  414. );
  415. BAIL_ON_FAILURE(hr);
  416. //
  417. // Build object info structure.
  418. //
  419. hr = BuildObjectInfo(
  420. _ADsPath,
  421. bstrRelativeName,
  422. &pObjectInfo
  423. );
  424. BAIL_ON_FAILURE(hr);
  425. //
  426. // Delete the object.
  427. //
  428. switch (ObjectType) {
  429. case NWCOMPAT_USER_ID:
  430. hr = NWApiDeleteUser(
  431. pObjectInfo,
  432. _Credentials
  433. );
  434. BAIL_ON_FAILURE(hr);
  435. break;
  436. case NWCOMPAT_GROUP_ID:
  437. hr = NWApiDeleteGroup(
  438. pObjectInfo,
  439. _Credentials
  440. );
  441. BAIL_ON_FAILURE(hr);
  442. break;
  443. case NWCOMPAT_PRINTER_ID:
  444. hr = NWApiDeletePrinter(
  445. pObjectInfo,
  446. _Credentials
  447. );
  448. BAIL_ON_FAILURE(hr);
  449. break;
  450. default:
  451. hr = E_ADS_UNKNOWN_OBJECT;
  452. BAIL_ON_FAILURE(hr);
  453. }
  454. error:
  455. FreeObjectInfo(pObjectInfo);
  456. NW_RRETURN_EXP_IF_ERR(hr);
  457. }
  458. //----------------------------------------------------------------------------
  459. //
  460. // Function: CNWCOMPATComputer::CopyHere
  461. //
  462. // Synopsis:
  463. //
  464. //----------------------------------------------------------------------------
  465. STDMETHODIMP
  466. CNWCOMPATComputer::CopyHere(
  467. THIS_ BSTR SourceName,
  468. BSTR NewName,
  469. IDispatch * FAR* ppObject
  470. )
  471. {
  472. NW_RRETURN_EXP_IF_ERR(E_NOTIMPL);
  473. }
  474. //----------------------------------------------------------------------------
  475. //
  476. // Function: CNWCOMPATComputer::MoveHere
  477. //
  478. // Synopsis:
  479. //
  480. //----------------------------------------------------------------------------
  481. STDMETHODIMP
  482. CNWCOMPATComputer::MoveHere(
  483. THIS_ BSTR SourceName,
  484. BSTR NewName,
  485. IDispatch * FAR* ppObject
  486. )
  487. {
  488. POBJECTINFO pObjectInfoSource = NULL;
  489. POBJECTINFO pObjectInfoTarget = NULL;
  490. NWCONN_HANDLE hConn = NULL;
  491. DWORD dwResumeId = 0xffffffff;
  492. BSTR pADsPathTarget = NULL;
  493. HRESULT hr = S_OK;
  494. // Bindery only supports renames, not moves
  495. if (!NewName)
  496. BAIL_ON_FAILURE(hr = E_NOTIMPL);
  497. //
  498. // Build object info structure.
  499. //
  500. hr = BuildObjectInfo(
  501. SourceName,
  502. &pObjectInfoSource
  503. );
  504. BAIL_ON_FAILURE(hr);
  505. hr = BuildObjectInfo(
  506. _ADsPath,
  507. NewName,
  508. &pObjectInfoTarget
  509. );
  510. BAIL_ON_FAILURE(hr);
  511. // Can't rename to a child or parent, or to a different bindery
  512. if ( (pObjectInfoSource->NumComponents != 2) || (pObjectInfoTarget->NumComponents != 2) )
  513. BAIL_ON_FAILURE(hr = E_INVALIDARG);
  514. if (_wcsicmp(pObjectInfoSource->ComponentArray[0], pObjectInfoTarget->ComponentArray[0]))
  515. BAIL_ON_FAILURE(hr = E_INVALIDARG);
  516. //
  517. // Rename the object. We need to know the object type, but this unfortunately isn't
  518. // passed to us, unlike Delete. So we try to validate the object as each type until
  519. // we hit one that works.
  520. //
  521. hr = NWApiGetBinderyHandle(
  522. &hConn,
  523. pObjectInfoSource->ComponentArray[0],
  524. _Credentials);
  525. BAIL_ON_FAILURE(hr);
  526. // Netware wants the names uppercase
  527. _wcsupr(pObjectInfoSource->ComponentArray[1]);
  528. _wcsupr(pObjectInfoTarget->ComponentArray[1]);
  529. // Is object a User?
  530. hr = NWApiValidateObject(
  531. hConn,
  532. OT_USER,
  533. pObjectInfoSource->ComponentArray[1],
  534. &dwResumeId
  535. );
  536. if (SUCCEEDED(hr)) {
  537. hr = NWApiRenameObject(
  538. pObjectInfoSource,
  539. pObjectInfoTarget,
  540. OT_USER,
  541. _Credentials
  542. );
  543. BAIL_ON_FAILURE(hr);
  544. }
  545. else {
  546. // Is object a Group?
  547. hr = NWApiValidateObject(
  548. hConn,
  549. OT_USER_GROUP,
  550. pObjectInfoSource->ComponentArray[1],
  551. &dwResumeId
  552. );
  553. if (SUCCEEDED(hr)) {
  554. hr = NWApiRenameObject(
  555. pObjectInfoSource,
  556. pObjectInfoTarget,
  557. OT_USER_GROUP,
  558. _Credentials
  559. );
  560. BAIL_ON_FAILURE(hr);
  561. }
  562. else {
  563. // Is object a Print Queue?
  564. hr = NWApiValidateObject(
  565. hConn,
  566. OT_PRINT_QUEUE,
  567. pObjectInfoSource->ComponentArray[1],
  568. &dwResumeId
  569. );
  570. if (SUCCEEDED(hr)) {
  571. hr = NWApiRenameObject(
  572. pObjectInfoSource,
  573. pObjectInfoTarget,
  574. OT_PRINT_QUEUE,
  575. _Credentials
  576. );
  577. BAIL_ON_FAILURE(hr);
  578. }
  579. else {
  580. // No such object, or not a type that we support
  581. hr = E_ADS_UNKNOWN_OBJECT;
  582. BAIL_ON_FAILURE(hr);
  583. }
  584. }
  585. }
  586. // get the IDispatch pointer
  587. if (ppObject) {
  588. hr = BuildADsPath(
  589. _ADsPath,
  590. NewName,
  591. &pADsPathTarget
  592. );
  593. BAIL_ON_FAILURE(hr);
  594. hr = ::GetObject(
  595. pADsPathTarget,
  596. _Credentials,
  597. (LPVOID *)ppObject
  598. );
  599. BAIL_ON_FAILURE(hr);
  600. }
  601. error:
  602. if (pADsPathTarget)
  603. ADsFreeString(pADsPathTarget);
  604. NWApiReleaseBinderyHandle(hConn);
  605. FreeObjectInfo(pObjectInfoSource);
  606. FreeObjectInfo(pObjectInfoTarget);
  607. NW_RRETURN_EXP_IF_ERR(hr);
  608. }
  609. //
  610. // IADs methods
  611. //
  612. //----------------------------------------------------------------------------
  613. //
  614. // Function: CNWCOMPATComputer::SetInfo
  615. //
  616. // Synopsis:
  617. //
  618. //----------------------------------------------------------------------------
  619. STDMETHODIMP
  620. CNWCOMPATComputer::SetInfo(THIS)
  621. {
  622. //
  623. // BUGBUG - should this be changed to E_NOTSUPPORTED if it is verified that
  624. // no properties on this object can be set.
  625. //
  626. NW_RRETURN_EXP_IF_ERR(E_NOTIMPL);
  627. }
  628. //----------------------------------------------------------------------------
  629. //
  630. // Function: CNWCOMPATComputer::GetInfo
  631. //
  632. // Synopsis:
  633. //
  634. //----------------------------------------------------------------------------
  635. STDMETHODIMP
  636. CNWCOMPATComputer::GetInfo(THIS)
  637. {
  638. _pPropertyCache->flushpropcache();
  639. RRETURN(GetInfo(
  640. TRUE,
  641. COMP_WILD_CARD_ID
  642. ));
  643. }
  644. //
  645. // IADsComputer methods
  646. //
  647. //----------------------------------------------------------------------------
  648. //
  649. // Function: CNWCOMPATComputer::AllocateComputerObject
  650. //
  651. // Synopsis:
  652. //
  653. //----------------------------------------------------------------------------
  654. HRESULT
  655. CNWCOMPATComputer::AllocateComputerObject(
  656. CNWCOMPATComputer ** ppComputer
  657. )
  658. {
  659. CNWCOMPATComputer FAR * pComputer = NULL;
  660. CDispatchMgr FAR * pDispMgr = NULL;
  661. CPropertyCache FAR * pPropertyCache = NULL;
  662. HRESULT hr = S_OK;
  663. //
  664. // Allocate memory for a computer object.
  665. //
  666. pComputer = new CNWCOMPATComputer();
  667. if (pComputer == NULL) {
  668. hr = E_OUTOFMEMORY;
  669. }
  670. BAIL_ON_FAILURE(hr);
  671. //
  672. // Create a Dispatch Manager object.
  673. //
  674. pDispMgr = new CDispatchMgr;
  675. if (pDispMgr == NULL) {
  676. hr = E_OUTOFMEMORY;
  677. }
  678. BAIL_ON_FAILURE(hr);
  679. //
  680. // Load type info.
  681. //
  682. hr = LoadTypeInfoEntry(
  683. pDispMgr,
  684. LIBID_ADs,
  685. IID_IADsComputer,
  686. (IADsComputer *)pComputer,
  687. DISPID_REGULAR
  688. );
  689. BAIL_ON_FAILURE(hr);
  690. hr = LoadTypeInfoEntry(
  691. pDispMgr,
  692. LIBID_ADs,
  693. IID_IADsContainer,
  694. (IADsContainer *)pComputer,
  695. DISPID_NEWENUM
  696. );
  697. BAIL_ON_FAILURE(hr);
  698. hr = LoadTypeInfoEntry(
  699. pDispMgr,
  700. LIBID_ADs,
  701. IID_IADsPropertyList,
  702. (IADsPropertyList *)pComputer,
  703. DISPID_VALUE
  704. );
  705. BAIL_ON_FAILURE(hr);
  706. //
  707. // Create property cache
  708. //
  709. hr = CPropertyCache::createpropertycache(
  710. ComputerClass,
  711. gdwComputerTableSize,
  712. (CCoreADsObject *)pComputer,
  713. &pPropertyCache
  714. );
  715. BAIL_ON_FAILURE(hr);
  716. pComputer->_pPropertyCache = pPropertyCache;
  717. pComputer->_pDispMgr = pDispMgr;
  718. *ppComputer = pComputer;
  719. RRETURN(hr);
  720. error:
  721. //
  722. // Note: pComputer->_pPropertyCache & pComputer->_pDispMgr are NULL
  723. //
  724. if (pComputer)
  725. delete pComputer;
  726. if (pPropertyCache)
  727. delete pPropertyCache;
  728. if (pDispMgr)
  729. delete pDispMgr;
  730. RRETURN(hr);
  731. }
  732. //----------------------------------------------------------------------------
  733. //
  734. // Function: CNWCOMPATComputer::CreateObject
  735. //
  736. // Synopsis:
  737. //
  738. //----------------------------------------------------------------------------
  739. HRESULT
  740. CNWCOMPATComputer::CreateObject(
  741. )
  742. {
  743. RRETURN(S_OK);
  744. }
  745. //----------------------------------------------------------------------------
  746. //
  747. // Function: CNWCOMPATComputer::GetInfo
  748. //
  749. // Synopsis:
  750. //
  751. //----------------------------------------------------------------------------
  752. STDMETHODIMP
  753. CNWCOMPATComputer::GetInfo(
  754. BOOL fExplicit,
  755. DWORD dwPropertyID
  756. )
  757. {
  758. HRESULT hr = S_OK;
  759. if (GetObjectState() == ADS_OBJECT_UNBOUND) {
  760. NW_RRETURN_EXP_IF_ERR(E_ADS_OBJECT_UNBOUND);
  761. }
  762. //
  763. // Get a handle to the bindery this computer object represents,
  764. // if we haven't previously obtained one
  765. //
  766. if (!_hConn)
  767. {
  768. hr = NWApiGetBinderyHandle(
  769. &_hConn,
  770. _Name,
  771. _Credentials
  772. );
  773. BAIL_ON_FAILURE(hr);
  774. }
  775. //
  776. // Fill in all property caches with values - explicit, or return the
  777. // indicated property - implicit.
  778. //
  779. if (fExplicit) {
  780. hr = ExplicitGetInfo(_hConn, fExplicit);
  781. BAIL_ON_FAILURE(hr);
  782. }
  783. else {
  784. hr = ImplicitGetInfo(_hConn, dwPropertyID, fExplicit);
  785. BAIL_ON_FAILURE(hr);
  786. }
  787. error:
  788. NW_RRETURN_EXP_IF_ERR(hr);
  789. }
  790. //----------------------------------------------------------------------------
  791. //
  792. // Function: CNWCOMPATComputer::ExplicitGetInfo
  793. //
  794. // Synopsis:
  795. //
  796. //----------------------------------------------------------------------------
  797. HRESULT
  798. CNWCOMPATComputer::ExplicitGetInfo(
  799. NWCONN_HANDLE hConn,
  800. BOOL fExplicit
  801. )
  802. {
  803. HRESULT hr = S_OK;
  804. hr = GetProperty_Addresses(hConn, fExplicit);
  805. if (hr == E_ADS_PROPERTY_NOT_FOUND) {
  806. // not a real failure, we ignore it and treat it as a missing attrib
  807. hr = S_OK;
  808. }
  809. BAIL_ON_FAILURE(hr);
  810. hr = GetProperty_OperatingSystem(fExplicit);
  811. if (hr == E_ADS_PROPERTY_NOT_FOUND) {
  812. // not a real failure, we ignore it and treat it as a missing attrib
  813. hr = S_OK;
  814. }
  815. BAIL_ON_FAILURE(hr);
  816. hr = GetProperty_OperatingSystemVersion(hConn, fExplicit);
  817. if (hr == E_ADS_PROPERTY_NOT_FOUND) {
  818. // not a real failure, we ignore it and treat it as a missing attrib
  819. hr = S_OK;
  820. }
  821. BAIL_ON_FAILURE(hr);
  822. error:
  823. RRETURN(hr);
  824. }
  825. //----------------------------------------------------------------------------
  826. //
  827. // Function: CNWCOMPATComputer::ImplicitGetInfo
  828. //
  829. // Synopsis:
  830. //
  831. //----------------------------------------------------------------------------
  832. HRESULT
  833. CNWCOMPATComputer::ImplicitGetInfo(
  834. NWCONN_HANDLE hConn,
  835. DWORD dwPropertyID,
  836. BOOL fExplicit
  837. )
  838. {
  839. HRESULT hr = S_OK;
  840. switch (dwPropertyID) {
  841. case COMP_ADDRESSES_ID:
  842. hr = GetProperty_Addresses(hConn, fExplicit);
  843. break;
  844. case COMP_OPERATINGSYSTEM_ID:
  845. hr = GetProperty_OperatingSystem(fExplicit);
  846. break;
  847. case COMP_OPERATINGSYSTEMVERSION_ID:
  848. hr = GetProperty_OperatingSystemVersion(hConn, fExplicit);
  849. break;
  850. }
  851. RRETURN(hr);
  852. }
  853. //----------------------------------------------------------------------------
  854. //
  855. // Function: CNWCOMPATComputer::GetProperty_Addresses
  856. //
  857. // Synopsis:
  858. //
  859. //----------------------------------------------------------------------------
  860. HRESULT
  861. CNWCOMPATComputer::GetProperty_Addresses(
  862. NWCONN_HANDLE hConn,
  863. BOOL fExplicit
  864. )
  865. {
  866. BSTR bstrBuffer = NULL;
  867. DWORD dwNumSegment;
  868. HRESULT hr = S_OK;
  869. LP_RPLY_SGMT_LST lpReplySegment = NULL;
  870. LP_RPLY_SGMT_LST lpTemp = NULL; // Used by DELETE_LIST macro below
  871. LPWSTR lpszBuffer = NULL;
  872. VARIANT vData;
  873. //
  874. // Get ADDRESSES.
  875. //
  876. hr = NWApiGetProperty(
  877. _Name,
  878. NW_PROP_NET_ADDRESS,
  879. OT_FILE_SERVER,
  880. hConn,
  881. &lpReplySegment,
  882. &dwNumSegment
  883. );
  884. BAIL_ON_FAILURE(hr);
  885. //
  886. // Put the addresses obtained in the format described in spec.
  887. //
  888. hr = NWApiConvertToAddressFormat(
  889. lpReplySegment,
  890. &lpszBuffer
  891. );
  892. BAIL_ON_FAILURE(hr);
  893. bstrBuffer = SysAllocString(lpszBuffer);
  894. if (!bstrBuffer) {
  895. hr = E_OUTOFMEMORY;
  896. BAIL_ON_FAILURE(hr);
  897. }
  898. //
  899. // BUGBUG - for now, Addresses is treated as a BSTR Variant instead of a
  900. // variant array of bstr, as described in the spec.
  901. //
  902. VariantInit(&vData);
  903. V_VT(&vData) = VT_BSTR;
  904. V_BSTR(&vData) = bstrBuffer;
  905. //
  906. // Unmarshall.
  907. //
  908. //
  909. // BugBug - KrishnaG figure out how we're going to map this property
  910. //
  911. //
  912. // UM_PUT_VARIANT_PROPERTY(vData, _pGenInfo, Addresses, FALSE);
  913. //
  914. VariantClear(&vData);
  915. error:
  916. if (lpReplySegment) {
  917. DELETE_LIST(lpReplySegment);
  918. }
  919. if (lpszBuffer) {
  920. FreeADsMem(lpszBuffer);
  921. }
  922. RRETURN(hr);
  923. }
  924. //----------------------------------------------------------------------------
  925. //
  926. // Function: CNWCOMPATComputer::GetProperty_OperatingSystem
  927. //
  928. // Synopsis:
  929. //
  930. //----------------------------------------------------------------------------
  931. HRESULT
  932. CNWCOMPATComputer::GetProperty_OperatingSystem(
  933. BOOL fExplicit
  934. )
  935. {
  936. HRESULT hr = S_OK;
  937. //
  938. // BUGBUG - bstrComputerOperatingSystem is HARDCODED.
  939. //
  940. hr = SetLPTSTRPropertyInCache(
  941. _pPropertyCache,
  942. TEXT("OperatingSystem"),
  943. bstrComputerOperatingSystem,
  944. fExplicit
  945. );
  946. RRETURN(hr);
  947. }
  948. //----------------------------------------------------------------------------
  949. //
  950. // Function: CNWCOMPATComputer::GetProperty_OperatingSystemVersion
  951. //
  952. // Synopsis:
  953. //
  954. //----------------------------------------------------------------------------
  955. HRESULT
  956. CNWCOMPATComputer::GetProperty_OperatingSystemVersion(
  957. NWCONN_HANDLE hConn,
  958. BOOL fExplicit
  959. )
  960. {
  961. LPWSTR pszBuffer = NULL;
  962. CHAR ch;
  963. HRESULT hr = S_OK;
  964. NW_VERSION_INFO VersionInfo;
  965. //
  966. // Get Version Information of a bindery.
  967. //
  968. hr = NWApiGetFileServerVersionInfo(
  969. hConn,
  970. &VersionInfo
  971. );
  972. BAIL_ON_FAILURE(hr);
  973. //
  974. // Put Version & SubVersion in X.X format.
  975. //
  976. pszBuffer = (LPWSTR) AllocADsMem(
  977. (OS_VERSION_NUM_CHAR+1) * sizeof(WCHAR)
  978. );
  979. if (!pszBuffer) {
  980. hr = E_OUTOFMEMORY;
  981. BAIL_ON_FAILURE(hr);
  982. }
  983. wsprintf(
  984. pszBuffer,
  985. L"%i.%02i",
  986. (WORD) VersionInfo.Version,
  987. (WORD) VersionInfo.SubVersion
  988. );
  989. //
  990. // Unmarshall.
  991. //
  992. hr = SetLPTSTRPropertyInCache(
  993. _pPropertyCache,
  994. TEXT("OperatingSystemVersion"),
  995. pszBuffer,
  996. fExplicit
  997. );
  998. error:
  999. if (pszBuffer) {
  1000. FreeADsMem(pszBuffer);
  1001. }
  1002. RRETURN(hr);
  1003. }
  1004. STDMETHODIMP
  1005. CNWCOMPATComputer::Status(
  1006. IDispatch * FAR * ppObject
  1007. )
  1008. {
  1009. NW_RRETURN_EXP_IF_ERR(E_NOTIMPL);
  1010. }
  1011. STDMETHODIMP
  1012. CNWCOMPATComputer::Shutdown(
  1013. VARIANT_BOOL bReboot
  1014. )
  1015. {
  1016. NW_RRETURN_EXP_IF_ERR(E_NOTIMPL);
  1017. }