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.

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