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.

802 lines
18 KiB

  1. //---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1995
  5. //
  6. // File: cfserv.cxx
  7. //
  8. // Contents:
  9. //
  10. // History: April 19, 1996 t-ptam (Patrick Tam) Created.
  11. //
  12. //----------------------------------------------------------------------------
  13. #include "nwcompat.hxx"
  14. #pragma hdrstop
  15. //
  16. // Marco-ized Implementation.
  17. //
  18. DEFINE_IDispatch_Implementation(CNWCOMPATFileService);
  19. DEFINE_IADs_TempImplementation(CNWCOMPATFileService);
  20. DEFINE_IADs_PutGetImplementation(CNWCOMPATFileService, FileServiceClass,gdwFileServiceTableSize);
  21. DEFINE_IADsPropertyList_Implementation(CNWCOMPATFileService, FileServiceClass, gdwFileServiceTableSize);
  22. //
  23. // class CNWCOMPATFileService methods
  24. //
  25. //----------------------------------------------------------------------------
  26. //
  27. // Function: CNWCOMPATFileService::CNWCOMPATFileService
  28. //
  29. // Synopsis:
  30. //
  31. //----------------------------------------------------------------------------
  32. CNWCOMPATFileService::CNWCOMPATFileService():
  33. _pDispMgr(NULL),
  34. _ServerName(NULL),
  35. _pPropertyCache(NULL),
  36. _hConn(NULL)
  37. {
  38. ENLIST_TRACKING(CNWCOMPATFileService);
  39. }
  40. //----------------------------------------------------------------------------
  41. //
  42. // Function: CNWCOMPATFileService::~CNWCOMPATFileService
  43. //
  44. // Synopsis:
  45. //
  46. //----------------------------------------------------------------------------
  47. CNWCOMPATFileService::~CNWCOMPATFileService()
  48. {
  49. delete _pDispMgr;
  50. ADSFREESTRING(_ServerName);
  51. delete _pPropertyCache;
  52. if (_hConn)
  53. NWApiReleaseBinderyHandle(_hConn);
  54. }
  55. //----------------------------------------------------------------------------
  56. //
  57. // Function: CNWCOMPATFileService::CreateFileService
  58. //
  59. // Synopsis:
  60. //
  61. //----------------------------------------------------------------------------
  62. HRESULT
  63. CNWCOMPATFileService::CreateFileService(
  64. LPTSTR pszADsParent,
  65. LPTSTR pszServerName,
  66. LPTSTR pszFileServiceName,
  67. CCredentials &Credentials,
  68. DWORD dwObjectState,
  69. REFIID riid,
  70. void **ppvObj
  71. )
  72. {
  73. CNWCOMPATFileService FAR * pFileService = NULL;
  74. HRESULT hr = S_OK;
  75. hr = AllocateFileServiceObject(
  76. &pFileService
  77. );
  78. BAIL_ON_FAILURE(hr);
  79. hr = pFileService->InitializeCoreObject(
  80. pszADsParent,
  81. pszFileServiceName,
  82. TEXT("FileService"),
  83. FILESERVICE_SCHEMA_NAME,
  84. CLSID_NWCOMPATFileService,
  85. dwObjectState
  86. );
  87. BAIL_ON_FAILURE(hr);
  88. hr = ADsAllocString( pszServerName , &pFileService->_ServerName);
  89. BAIL_ON_FAILURE(hr);
  90. pFileService->_Credentials = Credentials;
  91. //
  92. // Get a handle to the bindery this computer object represents.
  93. //
  94. hr = NWApiGetBinderyHandle(
  95. &pFileService->_hConn,
  96. pFileService->_ServerName,
  97. pFileService->_Credentials
  98. );
  99. BAIL_ON_FAILURE(hr);
  100. hr = pFileService->QueryInterface(
  101. riid,
  102. ppvObj
  103. );
  104. BAIL_ON_FAILURE(hr);
  105. pFileService->Release();
  106. RRETURN(hr);
  107. error:
  108. delete pFileService;
  109. NW_RRETURN_EXP_IF_ERR(hr);
  110. }
  111. //----------------------------------------------------------------------------
  112. //
  113. // Function: CNWCOMPATFileService::AllocateFileServiceObject
  114. //
  115. // Synopsis:
  116. //
  117. //----------------------------------------------------------------------------
  118. HRESULT
  119. CNWCOMPATFileService::AllocateFileServiceObject(
  120. CNWCOMPATFileService ** ppFileService
  121. )
  122. {
  123. CDispatchMgr FAR *pDispMgr = NULL;
  124. CNWCOMPATFileService FAR *pFileService = NULL;
  125. HRESULT hr = S_OK;
  126. //
  127. // Allocate memory for a FileService object.
  128. //
  129. pFileService = new CNWCOMPATFileService();
  130. if (pFileService == NULL) {
  131. hr = E_OUTOFMEMORY;
  132. }
  133. BAIL_ON_FAILURE(hr);
  134. //
  135. // Create a Dispatch Manager object.
  136. //
  137. pDispMgr = new CDispatchMgr;
  138. if (pDispMgr == NULL) {
  139. hr = E_OUTOFMEMORY;
  140. }
  141. BAIL_ON_FAILURE(hr);
  142. //
  143. // Load type info.
  144. //
  145. hr = LoadTypeInfoEntry(
  146. pDispMgr,
  147. LIBID_ADs,
  148. IID_IADsFileService,
  149. (IADsFileService *)pFileService,
  150. DISPID_REGULAR
  151. );
  152. BAIL_ON_FAILURE(hr);
  153. hr = LoadTypeInfoEntry(
  154. pDispMgr,
  155. LIBID_ADs,
  156. IID_IADsFileServiceOperations,
  157. (IADsFileServiceOperations *)pFileService,
  158. DISPID_REGULAR
  159. );
  160. BAIL_ON_FAILURE(hr);
  161. hr = LoadTypeInfoEntry(
  162. pDispMgr,
  163. LIBID_ADs,
  164. IID_IADsContainer,
  165. (IADsContainer *)pFileService,
  166. DISPID_NEWENUM
  167. );
  168. BAIL_ON_FAILURE(hr);
  169. hr = LoadTypeInfoEntry(
  170. pDispMgr,
  171. LIBID_ADs,
  172. IID_IADsPropertyList,
  173. (IADsPropertyList *)pFileService,
  174. DISPID_VALUE
  175. );
  176. BAIL_ON_FAILURE(hr);
  177. //
  178. // Return.
  179. //
  180. hr = CPropertyCache::createpropertycache(
  181. FileServiceClass,
  182. gdwFileServiceTableSize,
  183. (CCoreADsObject *)pFileService,
  184. &(pFileService->_pPropertyCache)
  185. );
  186. BAIL_ON_FAILURE(hr);
  187. pFileService->_pDispMgr = pDispMgr;
  188. *ppFileService = pFileService;
  189. RRETURN(hr);
  190. error:
  191. delete pDispMgr;
  192. delete pFileService;
  193. RRETURN(hr);
  194. }
  195. //----------------------------------------------------------------------------
  196. //
  197. // Function: CNWCOMPATFileService::QueryInterface
  198. //
  199. // Synopsis:
  200. //
  201. //----------------------------------------------------------------------------
  202. STDMETHODIMP
  203. CNWCOMPATFileService::QueryInterface(
  204. REFIID riid,
  205. LPVOID FAR* ppvObj
  206. )
  207. {
  208. if (ppvObj == NULL) {
  209. RRETURN(E_POINTER);
  210. }
  211. if (IsEqualIID(riid, IID_IUnknown))
  212. {
  213. *ppvObj = (IADsFileService FAR *) this;
  214. }
  215. else if (IsEqualIID(riid, IID_IDispatch))
  216. {
  217. *ppvObj = (IADsFileService FAR *) this;
  218. }
  219. else if (IsEqualIID(riid, IID_ISupportErrorInfo))
  220. {
  221. *ppvObj = (ISupportErrorInfo FAR *) this;
  222. }
  223. else if (IsEqualIID(riid, IID_IADs))
  224. {
  225. *ppvObj = (IADsFileService FAR *) this;
  226. }
  227. else if (IsEqualIID(riid, IID_IADsPropertyList))
  228. {
  229. *ppvObj = (IADsPropertyList FAR *) this;
  230. }
  231. else if (IsEqualIID(riid, IID_IADsService)) {
  232. *ppvObj = (IADsFileService FAR *) this;
  233. }
  234. else if (IsEqualIID(riid, IID_IADsFileService))
  235. {
  236. *ppvObj = (IADsFileService FAR *) this;
  237. }
  238. else if (IsEqualIID(riid, IID_IADsServiceOperations))
  239. {
  240. *ppvObj = (IADsFileServiceOperations FAR *)this;
  241. }
  242. else if (IsEqualIID(riid, IID_IADsFileServiceOperations))
  243. {
  244. *ppvObj = (IADsFileServiceOperations FAR *)this;
  245. }
  246. else if (IsEqualIID(riid, IID_IADsContainer))
  247. {
  248. *ppvObj = (IADsContainer FAR *) this;
  249. }
  250. else
  251. {
  252. *ppvObj = NULL;
  253. return E_NOINTERFACE;
  254. }
  255. AddRef();
  256. return NOERROR;
  257. }
  258. //
  259. // ISupportErrorInfo method
  260. //
  261. STDMETHODIMP
  262. CNWCOMPATFileService::InterfaceSupportsErrorInfo(
  263. THIS_ REFIID riid
  264. )
  265. {
  266. if (IsEqualIID(riid, IID_IADs) ||
  267. IsEqualIID(riid, IID_IADsContainer) ||
  268. IsEqualIID(riid, IID_IADsService) ||
  269. IsEqualIID(riid, IID_IADsServiceOperations) ||
  270. IsEqualIID(riid, IID_IADsFileService) ||
  271. IsEqualIID(riid, IID_IADsFileServiceOperations) ||
  272. IsEqualIID(riid, IID_IADsPropertyList)) {
  273. RRETURN(S_OK);
  274. } else {
  275. RRETURN(S_FALSE);
  276. }
  277. }
  278. //----------------------------------------------------------------------------
  279. //
  280. // Function: CNWCOMPATFileService::get_Count
  281. //
  282. // Synopsis:
  283. //
  284. //----------------------------------------------------------------------------
  285. STDMETHODIMP
  286. CNWCOMPATFileService::get_Count(long FAR* retval)
  287. {
  288. //
  289. // Too expensive to implement in term of computer execution time.
  290. //
  291. NW_RRETURN_EXP_IF_ERR(E_NOTIMPL);
  292. }
  293. //----------------------------------------------------------------------------
  294. //
  295. // Function: CNWCOMPATFileService::get_Filter
  296. //
  297. // Synopsis:
  298. //
  299. //----------------------------------------------------------------------------
  300. STDMETHODIMP
  301. CNWCOMPATFileService::get_Filter(THIS_ VARIANT FAR* pVar)
  302. {
  303. //
  304. // BUGBUG - Filter doesn't make sense on a FileService container. Since it
  305. // can only contain FileShares. Am I right?
  306. //
  307. NW_RRETURN_EXP_IF_ERR(E_NOTIMPL);
  308. }
  309. //----------------------------------------------------------------------------
  310. //
  311. // Function: CNWCOMPATFileService::put_Filter
  312. //
  313. // Synopsis:
  314. //
  315. //----------------------------------------------------------------------------
  316. STDMETHODIMP
  317. CNWCOMPATFileService::put_Filter(THIS_ VARIANT Var)
  318. {
  319. //
  320. // BUGBUG - Filter doesn't make sense on a FileService container. Since it
  321. // can only contain FileShares. Am I right?
  322. //
  323. NW_RRETURN_EXP_IF_ERR(E_NOTIMPL);
  324. }
  325. STDMETHODIMP
  326. CNWCOMPATFileService::put_Hints(THIS_ VARIANT Var)
  327. {
  328. NW_RRETURN_EXP_IF_ERR( E_NOTIMPL);
  329. }
  330. STDMETHODIMP
  331. CNWCOMPATFileService::get_Hints(THIS_ VARIANT FAR* pVar)
  332. {
  333. NW_RRETURN_EXP_IF_ERR(E_NOTIMPL);
  334. }
  335. //----------------------------------------------------------------------------
  336. //
  337. // Function: CNWCOMPATFileService::GetObject
  338. //
  339. // Synopsis:
  340. //
  341. //----------------------------------------------------------------------------
  342. STDMETHODIMP
  343. CNWCOMPATFileService::GetObject(
  344. THIS_ BSTR ClassName,
  345. BSTR RelativeName,
  346. IDispatch * FAR* ppObject
  347. )
  348. {
  349. //
  350. // Will be implemented by Krishna on the WinNT side and be cloned
  351. // by me afterward.
  352. //
  353. NW_RRETURN_EXP_IF_ERR(E_NOTIMPL);
  354. }
  355. //----------------------------------------------------------------------------
  356. //
  357. // Function: CNWCOMPATFileService::get__NewEnum
  358. //
  359. // Synopsis:
  360. //
  361. //----------------------------------------------------------------------------
  362. STDMETHODIMP
  363. CNWCOMPATFileService::get__NewEnum(THIS_ IUnknown * FAR* retval)
  364. {
  365. HRESULT hr = S_OK;
  366. IEnumVARIANT * pEnum = NULL;
  367. *retval = NULL;
  368. hr = CNWCOMPATFileServiceEnum::Create(
  369. (CNWCOMPATFileServiceEnum **) &pEnum,
  370. _ADsPath,
  371. _ServerName,
  372. _Credentials
  373. );
  374. BAIL_ON_FAILURE(hr);
  375. hr = pEnum->QueryInterface(
  376. IID_IUnknown,
  377. (VOID FAR* FAR*) retval
  378. );
  379. BAIL_ON_FAILURE(hr);
  380. if (pEnum) {
  381. pEnum->Release();
  382. }
  383. RRETURN(NOERROR);
  384. error:
  385. delete pEnum;
  386. NW_RRETURN_EXP_IF_ERR(hr);
  387. }
  388. //----------------------------------------------------------------------------
  389. //
  390. // Function: CNWCOMPATFileService::Create
  391. //
  392. // Synopsis:
  393. //
  394. //----------------------------------------------------------------------------
  395. STDMETHODIMP
  396. CNWCOMPATFileService::Create(
  397. THIS_ BSTR ClassName,
  398. BSTR RelativeName,
  399. IDispatch * FAR* ppObject
  400. )
  401. {
  402. NW_RRETURN_EXP_IF_ERR(E_NOTIMPL);
  403. }
  404. //----------------------------------------------------------------------------
  405. //
  406. // Function: CNWCOMPATFileService::Delete
  407. //
  408. // Synopsis:
  409. //
  410. //----------------------------------------------------------------------------
  411. STDMETHODIMP
  412. CNWCOMPATFileService::Delete(
  413. THIS_ BSTR bstrClassName,
  414. BSTR bstrRelativeName)
  415. {
  416. NW_RRETURN_EXP_IF_ERR(E_NOTIMPL);
  417. }
  418. //----------------------------------------------------------------------------
  419. //
  420. // Function: CNWCOMPATFileService::CopyHere
  421. //
  422. // Synopsis:
  423. //
  424. //----------------------------------------------------------------------------
  425. STDMETHODIMP
  426. CNWCOMPATFileService::CopyHere(
  427. THIS_ BSTR SourceName,
  428. BSTR NewName,
  429. IDispatch * FAR* ppObject
  430. )
  431. {
  432. NW_RRETURN_EXP_IF_ERR(E_NOTIMPL);
  433. }
  434. //----------------------------------------------------------------------------
  435. //
  436. // Function: CNWCOMPATFileService::MoveHere
  437. //
  438. // Synopsis:
  439. //
  440. //----------------------------------------------------------------------------
  441. STDMETHODIMP
  442. CNWCOMPATFileService::MoveHere(
  443. THIS_ BSTR SourceName,
  444. BSTR NewName,
  445. IDispatch * FAR* ppObject
  446. )
  447. {
  448. NW_RRETURN_EXP_IF_ERR(E_NOTIMPL);
  449. }
  450. //----------------------------------------------------------------------------
  451. //
  452. // Function: CNWCOMPATFileService::SetInfo
  453. //
  454. // Synopsis:
  455. //
  456. //----------------------------------------------------------------------------
  457. STDMETHODIMP
  458. CNWCOMPATFileService::SetInfo(THIS)
  459. {
  460. NW_RRETURN_EXP_IF_ERR(E_NOTIMPL);
  461. }
  462. //----------------------------------------------------------------------------
  463. //
  464. // Function: CNWCOMPATFileService::GetInfo
  465. //
  466. // Synopsis:
  467. //
  468. //----------------------------------------------------------------------------
  469. STDMETHODIMP
  470. CNWCOMPATFileService::GetInfo(THIS)
  471. {
  472. _pPropertyCache->flushpropcache();
  473. RRETURN(GetInfo(
  474. TRUE,
  475. FSERV_WILD_CARD_ID
  476. ));
  477. }
  478. //----------------------------------------------------------------------------
  479. //
  480. // Function: CNWCOMPATFileService::GetInfo
  481. //
  482. // Synopsis:
  483. //
  484. //----------------------------------------------------------------------------
  485. STDMETHODIMP
  486. CNWCOMPATFileService::GetInfo(
  487. THIS_ BOOL fExplicit,
  488. DWORD dwPropertyID
  489. )
  490. {
  491. HRESULT hr = S_OK;
  492. POBJECTINFO pObjectInfo = NULL;
  493. //
  494. // Make sure the object is bound to a tangible resource.
  495. //
  496. if (GetObjectState() == ADS_OBJECT_UNBOUND) {
  497. NW_RRETURN_EXP_IF_ERR(E_ADS_OBJECT_UNBOUND);
  498. }
  499. //
  500. // Componentize ADs name.
  501. //
  502. hr = BuildObjectInfo(
  503. _Parent,
  504. _Name,
  505. &pObjectInfo
  506. );
  507. BAIL_ON_FAILURE(hr);
  508. //
  509. // Fill in all property caches with values - explicit, or return the
  510. // indicated property - implicit.
  511. //
  512. if (fExplicit) {
  513. hr = ExplicitGetInfo(
  514. _hConn,
  515. pObjectInfo,
  516. fExplicit
  517. );
  518. BAIL_ON_FAILURE(hr);
  519. }
  520. else {
  521. hr = ImplicitGetInfo(
  522. _hConn,
  523. pObjectInfo,
  524. dwPropertyID,
  525. fExplicit
  526. );
  527. BAIL_ON_FAILURE(hr);
  528. }
  529. error:
  530. if (pObjectInfo) {
  531. FreeObjectInfo(pObjectInfo);
  532. }
  533. NW_RRETURN_EXP_IF_ERR(hr);
  534. }
  535. //----------------------------------------------------------------------------
  536. //
  537. // Function: CNWCOMPATFileService::ExplicitGetInfo
  538. //
  539. // Synopsis:
  540. //
  541. //----------------------------------------------------------------------------
  542. HRESULT
  543. CNWCOMPATFileService::ExplicitGetInfo(
  544. NWCONN_HANDLE hConn,
  545. POBJECTINFO pObjectInfo,
  546. BOOL fExplicit
  547. )
  548. {
  549. HRESULT hr = S_OK;
  550. //
  551. // Get GeneralInfo.
  552. //
  553. hr = GetProperty_MaxUserCount(
  554. hConn,
  555. fExplicit
  556. );
  557. if (hr == E_ADS_PROPERTY_NOT_FOUND) {
  558. // not a real failure, we ignore it and treat it as a missing attrib
  559. hr = S_OK;
  560. }
  561. BAIL_ON_FAILURE(hr);
  562. //
  563. // Get Configuration.
  564. //
  565. hr = GetProperty_HostComputer(
  566. pObjectInfo,
  567. fExplicit
  568. );
  569. if (hr == E_ADS_PROPERTY_NOT_FOUND) {
  570. // not a real failure, we ignore it and treat it as a missing attrib
  571. hr = S_OK;
  572. }
  573. BAIL_ON_FAILURE(hr);
  574. error:
  575. RRETURN(hr);
  576. }
  577. //----------------------------------------------------------------------------
  578. //
  579. // Function: CNWCOMPATFileService::ImplicitGetInfo
  580. //
  581. // Synopsis:
  582. //
  583. //----------------------------------------------------------------------------
  584. HRESULT
  585. CNWCOMPATFileService::ImplicitGetInfo(
  586. NWCONN_HANDLE hConn,
  587. POBJECTINFO pObjectInfo,
  588. DWORD dwPropertyID,
  589. BOOL fExplicit
  590. )
  591. {
  592. HRESULT hr = S_OK;
  593. switch (dwPropertyID) {
  594. case FSERV_MAXUSERCOUNT_ID:
  595. hr = GetProperty_MaxUserCount(
  596. hConn,
  597. fExplicit
  598. );
  599. break;
  600. case FSERV_HOSTCOMPUTER_ID:
  601. hr = GetProperty_HostComputer(
  602. pObjectInfo,
  603. fExplicit
  604. );
  605. break;
  606. }
  607. RRETURN(hr);
  608. }
  609. //----------------------------------------------------------------------------
  610. //
  611. // Function: CNWCOMPATFileService::GetProperty_MaxUserCount
  612. //
  613. // Synopsis:
  614. //
  615. //----------------------------------------------------------------------------
  616. HRESULT
  617. CNWCOMPATFileService::GetProperty_MaxUserCount(
  618. NWCONN_HANDLE hConn,
  619. BOOL fExplicit
  620. )
  621. {
  622. HRESULT hr = S_OK;
  623. DWORD dwTemp = 0;
  624. NW_VERSION_INFO VersionInfo;
  625. //
  626. // Get the Maximum number of connections supported from the Version
  627. // Information of the FileServer.
  628. //
  629. hr = NWApiGetFileServerVersionInfo(
  630. hConn,
  631. &VersionInfo
  632. );
  633. BAIL_ON_FAILURE(hr);
  634. dwTemp = VersionInfo.ConnsSupported;
  635. //
  636. // Unmarshall.
  637. //
  638. hr = SetDWORDPropertyInCache(_pPropertyCache,
  639. TEXT("MaxUserCount"),
  640. (DWORD)dwTemp,
  641. fExplicit
  642. );
  643. //
  644. // Return.
  645. //
  646. error:
  647. RRETURN(hr);
  648. }
  649. //----------------------------------------------------------------------------
  650. //
  651. // Function: CNWCOMPATFileService::GetProperty_HostComputer
  652. //
  653. // Synopsis:
  654. //
  655. //----------------------------------------------------------------------------
  656. HRESULT
  657. CNWCOMPATFileService::GetProperty_HostComputer(
  658. POBJECTINFO pObjectInfo,
  659. BOOL fExplicit
  660. )
  661. {
  662. HRESULT hr = S_OK;
  663. WCHAR szBuffer[MAX_PATH];
  664. //
  665. // Build ADs path of Host computer from ObjectInfo.
  666. //
  667. wsprintf(
  668. szBuffer,
  669. L"%s://%s",
  670. pObjectInfo->ProviderName,
  671. pObjectInfo->ComponentArray[0]
  672. );
  673. //
  674. // Unmarshall
  675. //
  676. hr = SetLPTSTRPropertyInCache(
  677. _pPropertyCache,
  678. TEXT("HostComputer"),
  679. szBuffer,
  680. fExplicit
  681. );
  682. //
  683. // Return.
  684. //
  685. RRETURN(hr);
  686. }