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.

1526 lines
34 KiB

  1. //---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1995
  5. //
  6. // File: cfpnwsrv.cxx
  7. //
  8. // Contents: Contains methods for the following objects
  9. // CFPNWFileService and CFPNWFileServiceGeneralInfo.
  10. //
  11. //
  12. // History: 12/11/95 ramv (Ram Viswanathan) Created.
  13. //
  14. //----------------------------------------------------------------------------
  15. #include "winnt.hxx"
  16. #pragma hdrstop
  17. #define INITGUID
  18. //
  19. // class CFPNWFileService methods
  20. //
  21. DEFINE_IDispatch_ExtMgr_Implementation(CFPNWFileService);
  22. DEFINE_IADsExtension_ExtMgr_Implementation(CFPNWFileService);
  23. DEFINE_IADs_TempImplementation(CFPNWFileService);
  24. CFPNWFileService::CFPNWFileService()
  25. {
  26. _pDispMgr = NULL;
  27. _pExtMgr = NULL;
  28. _pService = NULL;
  29. _pCFileSharesEnumVar = NULL;
  30. _pszServerName = NULL;
  31. _pPropertyCache = NULL;
  32. ENLIST_TRACKING(CFPNWFileService);
  33. VariantInit(&_vFilter);
  34. return;
  35. }
  36. CFPNWFileService::~CFPNWFileService()
  37. {
  38. if(_pService){
  39. _pService->Release();
  40. }
  41. if (_pServiceOps) {
  42. _pServiceOps->Release();
  43. }
  44. delete _pExtMgr; // created last, destroyed first
  45. delete _pDispMgr;
  46. if(_pszServerName){
  47. FreeADsStr(_pszServerName);
  48. }
  49. VariantClear(&_vFilter);
  50. delete _pPropertyCache;
  51. return;
  52. }
  53. //+---------------------------------------------------------------------------
  54. //
  55. // Function: CFPNWFileService::CreateFileService
  56. //
  57. // Synopsis: Static function used to create a FileService object. This
  58. // will be called by BindToObject
  59. //
  60. // Arguments: [ppFPNWFileService] -- Ptr to a ptr to a new Service object.
  61. //
  62. // Returns: HRESULT.
  63. //
  64. // Modifies:
  65. //
  66. // History: 12-11-95 RamV Created.
  67. //
  68. //----------------------------------------------------------------------------
  69. HRESULT
  70. CFPNWFileService::CreateFileService(LPTSTR pszADsParent,
  71. DWORD dwParentId,
  72. LPTSTR pszDomainName,
  73. LPTSTR pszServerName,
  74. LPTSTR pszFileServiceName,
  75. DWORD dwObjectState,
  76. REFIID riid,
  77. CWinNTCredentials& Credentials,
  78. LPVOID * ppvoid
  79. )
  80. {
  81. CFPNWFileService FAR * pCFPNWFileService = NULL;
  82. HRESULT hr = S_OK;
  83. //
  84. // Create the FileService Object
  85. //
  86. hr = AllocateFileServiceObject(&pCFPNWFileService);
  87. BAIL_ON_FAILURE(hr);
  88. ADsAssert(pCFPNWFileService->_pDispMgr);
  89. hr = pCFPNWFileService->InitializeCoreObject(pszADsParent,
  90. pszFileServiceName,
  91. FILESERVICE_CLASS_NAME,
  92. FPNW_FILESERVICE_SCHEMA_NAME,
  93. CLSID_FPNWFileService,
  94. dwObjectState);
  95. //
  96. // note that no class fileservice is defined
  97. //
  98. BAIL_ON_FAILURE(hr);
  99. pCFPNWFileService->_Credentials = Credentials;
  100. hr = pCFPNWFileService->_Credentials.Ref(pszServerName,
  101. pszDomainName, dwParentId);
  102. BAIL_ON_FAILURE(hr);
  103. hr = CWinNTService::Create(pszADsParent,
  104. pszDomainName,
  105. pszServerName,
  106. pszFileServiceName,
  107. dwObjectState,
  108. IID_IADsService,
  109. pCFPNWFileService->_Credentials,
  110. (void **)(&(pCFPNWFileService->_pService)));
  111. BAIL_ON_FAILURE(hr);
  112. hr = (pCFPNWFileService->_pService)->QueryInterface(
  113. IID_IADsServiceOperations,
  114. (void **)&(pCFPNWFileService->_pServiceOps));
  115. BAIL_ON_FAILURE(hr);
  116. pCFPNWFileService->_pszServerName =
  117. AllocADsStr(pszServerName);
  118. if(!(pCFPNWFileService->_pszServerName)){
  119. hr = E_OUTOFMEMORY;
  120. goto error;
  121. }
  122. pCFPNWFileService->_Credentials = Credentials;
  123. hr = pCFPNWFileService->_Credentials.RefServer(pszServerName);
  124. BAIL_ON_FAILURE(hr);
  125. //
  126. // Load ext mgr and extensions
  127. //
  128. hr = ADSILoadExtensionManager(
  129. FILESERVICE_CLASS_NAME,
  130. (IADsFileService *) pCFPNWFileService,
  131. pCFPNWFileService->_pDispMgr,
  132. Credentials,
  133. &pCFPNWFileService->_pExtMgr
  134. );
  135. BAIL_ON_FAILURE(hr);
  136. ADsAssert(pCFPNWFileService->_pExtMgr);
  137. // check if the call is from UMI
  138. if(Credentials.GetFlags() & ADS_AUTH_RESERVED) {
  139. //
  140. // we do not pass riid to InitUmiObject below. This is because UMI object
  141. // does not support IDispatch. There are several places in ADSI code where
  142. // riid passed into this function is defaulted to IID_IDispatch -
  143. // IADsContainer::Create for example. To handle these cases, we always
  144. // request IID_IUnknown from the UMI object. Subsequent code within UMI
  145. // will QI for the appropriate interface.
  146. //
  147. if(3 == pCFPNWFileService->_dwNumComponents) {
  148. pCFPNWFileService->_CompClasses[0] = L"Domain";
  149. pCFPNWFileService->_CompClasses[1] = L"Computer";
  150. pCFPNWFileService->_CompClasses[2] = L"FileService";
  151. }
  152. else
  153. BAIL_ON_FAILURE(hr = UMI_E_FAIL);
  154. hr = pCFPNWFileService->InitUmiObject(
  155. pCFPNWFileService->_Credentials,
  156. FPNWFileServiceClass,
  157. gdwFPNWFileServiceTableSize,
  158. pCFPNWFileService->_pPropertyCache,
  159. (IUnknown *) (INonDelegatingUnknown *) pCFPNWFileService,
  160. pCFPNWFileService->_pExtMgr,
  161. IID_IUnknown,
  162. ppvoid
  163. );
  164. BAIL_ON_FAILURE(hr);
  165. //
  166. // UMI object was created and the interface was obtained successfully.
  167. // UMI object now has a reference to the inner unknown of IADs, since
  168. // the call to Release() below is not going to be made in this case.
  169. //
  170. RRETURN(hr);
  171. }
  172. hr = pCFPNWFileService->QueryInterface(riid, (void **)ppvoid);
  173. BAIL_ON_FAILURE(hr);
  174. pCFPNWFileService->Release();
  175. RRETURN(hr);
  176. error:
  177. delete pCFPNWFileService;
  178. RRETURN (hr);
  179. }
  180. HRESULT
  181. CFPNWFileService::AllocateFileServiceObject(
  182. CFPNWFileService ** ppFileService
  183. )
  184. {
  185. CFPNWFileService FAR * pFileService = NULL;
  186. HRESULT hr = S_OK;
  187. pFileService = new CFPNWFileService();
  188. if (pFileService == NULL) {
  189. hr = E_OUTOFMEMORY;
  190. }
  191. BAIL_ON_FAILURE(hr);
  192. pFileService->_pDispMgr = new CAggregatorDispMgr;
  193. if (pFileService->_pDispMgr == NULL) {
  194. hr = E_OUTOFMEMORY;
  195. }
  196. BAIL_ON_FAILURE(hr);
  197. hr = LoadTypeInfoEntry(pFileService->_pDispMgr,
  198. LIBID_ADs,
  199. IID_IADsFileService,
  200. (IADsFileService *)pFileService,
  201. DISPID_REGULAR);
  202. BAIL_ON_FAILURE(hr);
  203. hr = LoadTypeInfoEntry(pFileService->_pDispMgr,
  204. LIBID_ADs,
  205. IID_IADsContainer,
  206. (IADsContainer *)pFileService,
  207. DISPID_NEWENUM);
  208. BAIL_ON_FAILURE(hr);
  209. hr = LoadTypeInfoEntry(pFileService->_pDispMgr,
  210. LIBID_ADs,
  211. IID_IADsPropertyList,
  212. (IADsPropertyList *)pFileService,
  213. DISPID_VALUE);
  214. BAIL_ON_FAILURE(hr);
  215. hr = CPropertyCache::createpropertycache(
  216. FPNWFileServiceClass,
  217. gdwFPNWFileServiceTableSize,
  218. (CCoreADsObject *)pFileService,
  219. &(pFileService->_pPropertyCache)
  220. );
  221. BAIL_ON_FAILURE(hr);
  222. (pFileService->_pDispMgr)->RegisterPropertyCache(
  223. pFileService->_pPropertyCache
  224. );
  225. *ppFileService = pFileService;
  226. RRETURN(hr);
  227. error:
  228. //
  229. // direct memeber assignement assignement at pt of creation, so
  230. // do NOT delete _pPropertyCache or _pDisMgr here to avoid attempt
  231. // of deletion again in pPrintJob destructor and AV
  232. //
  233. delete pFileService;
  234. RRETURN_EXP_IF_ERR(hr);
  235. }
  236. /* IUnknown methods for file service object */
  237. //----------------------------------------------------------------------------
  238. // Function: QueryInterface
  239. //
  240. // Synopsis: If this object is aggregated within another object, then
  241. // all calls will delegate to the outer object. Otherwise, the
  242. // non-delegating QI is called
  243. //
  244. // Arguments:
  245. //
  246. // iid interface requested
  247. // ppInterface Returns pointer to interface requested. NULL if interface
  248. // is not supported.
  249. //
  250. // Returns: S_OK on success. Error code otherwise.
  251. //
  252. // Modifies: *ppInterface to return interface pointer
  253. //
  254. //----------------------------------------------------------------------------
  255. STDMETHODIMP CFPNWFileService::QueryInterface(
  256. REFIID iid,
  257. LPVOID *ppInterface
  258. )
  259. {
  260. if(_pUnkOuter != NULL)
  261. RRETURN(_pUnkOuter->QueryInterface(
  262. iid,
  263. ppInterface
  264. ));
  265. RRETURN(NonDelegatingQueryInterface(
  266. iid,
  267. ppInterface
  268. ));
  269. }
  270. //----------------------------------------------------------------------------
  271. // Function: AddRef
  272. //
  273. // Synopsis: IUnknown::AddRef. If this object is aggregated within
  274. // another, all calls will delegate to the outer object.
  275. // Otherwise, the non-delegating AddRef is called
  276. //
  277. // Arguments:
  278. //
  279. // None
  280. //
  281. // Returns: New reference count
  282. //
  283. // Modifies: Nothing
  284. //
  285. //----------------------------------------------------------------------------
  286. STDMETHODIMP_(ULONG) CFPNWFileService::AddRef(void)
  287. {
  288. if(_pUnkOuter != NULL)
  289. RRETURN(_pUnkOuter->AddRef());
  290. RRETURN(NonDelegatingAddRef());
  291. }
  292. //----------------------------------------------------------------------------
  293. // Function: Release
  294. //
  295. // Synopsis: IUnknown::Release. If this object is aggregated within
  296. // another, all calls will delegate to the outer object.
  297. // Otherwise, the non-delegating Release is called
  298. //
  299. // Arguments:
  300. //
  301. // None
  302. //
  303. // Returns: New reference count
  304. //
  305. // Modifies: Nothing
  306. //
  307. //----------------------------------------------------------------------------
  308. STDMETHODIMP_(ULONG) CFPNWFileService::Release(void)
  309. {
  310. if(_pUnkOuter != NULL)
  311. RRETURN(_pUnkOuter->Release());
  312. RRETURN(NonDelegatingRelease());
  313. }
  314. //----------------------------------------------------------------------------
  315. STDMETHODIMP
  316. CFPNWFileService::NonDelegatingQueryInterface(REFIID riid, LPVOID FAR* ppvObj)
  317. {
  318. HRESULT hr = S_OK;
  319. if(!ppvObj){
  320. RRETURN(E_POINTER);
  321. }
  322. if (IsEqualIID(riid, IID_IUnknown))
  323. {
  324. *ppvObj = (IADsFileService *)this;
  325. }
  326. else if (IsEqualIID(riid, IID_IDispatch))
  327. {
  328. *ppvObj = (IADsFileService *)this;
  329. }
  330. else if (IsEqualIID(riid, IID_ISupportErrorInfo))
  331. {
  332. *ppvObj = (ISupportErrorInfo FAR *) this;
  333. }
  334. else if (IsEqualIID(riid, IID_IADs))
  335. {
  336. *ppvObj = (IADsFileService FAR *) this;
  337. }
  338. else if (IsEqualIID(riid, IID_IADsFileService))
  339. {
  340. *ppvObj = (IADsFileService FAR *) this;
  341. }
  342. else if (IsEqualIID(riid, IID_IADsFileServiceOperations))
  343. {
  344. *ppvObj = (IADsFileServiceOperations FAR *) this;
  345. }
  346. else if (IsEqualIID(riid, IID_IADsService))
  347. {
  348. *ppvObj = (IADsService FAR *) this;
  349. }
  350. else if (IsEqualIID(riid, IID_IADsServiceOperations))
  351. {
  352. *ppvObj = (IADsServiceOperations FAR *) this;
  353. }
  354. else if (IsEqualIID(riid, IID_IADsContainer))
  355. {
  356. *ppvObj = (IADsContainer FAR *) this;
  357. }
  358. else if( (_pDispatch != NULL) &&
  359. IsEqualIID(riid, IID_IADsExtension) )
  360. {
  361. *ppvObj = (IADsExtension *) this;
  362. }
  363. else if (_pExtMgr)
  364. {
  365. RRETURN( _pExtMgr->QueryInterface(riid, ppvObj));
  366. }
  367. else
  368. {
  369. *ppvObj = NULL;
  370. RRETURN(E_NOINTERFACE);
  371. }
  372. ((LPUNKNOWN)*ppvObj)->AddRef();
  373. RRETURN(S_OK);
  374. }
  375. /* ISupportErrorInfo method */
  376. STDMETHODIMP
  377. CFPNWFileService::InterfaceSupportsErrorInfo(
  378. THIS_ REFIID riid
  379. )
  380. {
  381. if (IsEqualIID(riid, IID_IADs) ||
  382. IsEqualIID(riid, IID_IADsService) ||
  383. IsEqualIID(riid, IID_IADsFileService) ||
  384. IsEqualIID(riid, IID_IADsServiceOperations) ||
  385. IsEqualIID(riid, IID_IADsFileServiceOperations) ||
  386. IsEqualIID(riid, IID_IADsContainer)) {
  387. RRETURN(S_OK);
  388. } else {
  389. RRETURN(S_FALSE);
  390. }
  391. }
  392. //+---------------------------------------------------------------------------
  393. //
  394. // Function: SetInfo
  395. //
  396. // Synopsis:
  397. //
  398. // Arguments: void
  399. //
  400. // Returns: HRESULT.
  401. //
  402. // Modifies:
  403. //
  404. // History: RamV Created
  405. //----------------------------------------------------------------------------
  406. STDMETHODIMP
  407. CFPNWFileService::SetInfo(THIS)
  408. {
  409. HRESULT hr;
  410. IADsService * pADsService = NULL;
  411. ADsAssert(_pService);
  412. hr = _pService->SetInfo();
  413. BAIL_IF_ERROR(hr);
  414. hr = SetFPNWServerInfo();
  415. BAIL_IF_ERROR(hr);
  416. if(SUCCEEDED(hr))
  417. _pPropertyCache->ClearModifiedFlags();
  418. cleanup:
  419. RRETURN_EXP_IF_ERR(hr);
  420. }
  421. //+---------------------------------------------------------------------------
  422. //
  423. // Function: GetInfo
  424. //
  425. // Synopsis:
  426. //
  427. // Arguments: void
  428. //
  429. // Returns: HRESULT.
  430. //
  431. // Modifies:
  432. //
  433. // History: 12/11/95 RamV Created
  434. //
  435. //----------------------------------------------------------------------------
  436. STDMETHODIMP
  437. CFPNWFileService::GetInfo(THIS)
  438. {
  439. HRESULT hr =S_OK;
  440. _pPropertyCache->flushpropcache();
  441. hr = GetInfo(1, TRUE);
  442. if(FAILED(hr))
  443. RRETURN_EXP_IF_ERR(hr);
  444. hr = GetInfo(2,TRUE);
  445. RRETURN_EXP_IF_ERR(hr);
  446. }
  447. STDMETHODIMP
  448. CFPNWFileService::ImplicitGetInfo(THIS)
  449. {
  450. HRESULT hr =S_OK;
  451. hr = GetInfo(1, FALSE);
  452. if(FAILED(hr))
  453. RRETURN_EXP_IF_ERR(hr);
  454. hr = GetInfo(2,FALSE);
  455. RRETURN_EXP_IF_ERR(hr);
  456. }
  457. STDMETHODIMP
  458. CFPNWFileService::GetInfo(THIS_ DWORD dwApiLevel, BOOL fExplicit)
  459. {
  460. HRESULT hr =S_OK;
  461. DWORD dwErrCode;
  462. switch(dwApiLevel){
  463. case 1:
  464. ADsAssert(_pService);
  465. hr = _pService->GetInfo();
  466. BAIL_IF_ERROR(hr);
  467. break;
  468. case 2:
  469. hr = GetFPNWServerInfo(fExplicit);
  470. BAIL_IF_ERROR(hr);
  471. break;
  472. default:
  473. ADsAssert(FALSE);
  474. break;
  475. }
  476. cleanup:
  477. RRETURN (hr);
  478. }
  479. HRESULT
  480. CFPNWFileService::SetFPNWServerInfo(THIS)
  481. {
  482. PNWSERVERINFO pServerInfo = NULL;
  483. HRESULT hr = S_OK;
  484. DWORD dwErrorCode;
  485. LPTSTR pszDescription = NULL;
  486. //
  487. // Do a GetInfo to first get all the information in this server.
  488. //
  489. //
  490. // only level 1 is valid
  491. //
  492. dwErrorCode = ADsNwServerGetInfo(_pszServerName,
  493. 1,
  494. &pServerInfo);
  495. hr = HRESULT_FROM_WIN32(dwErrorCode);
  496. BAIL_IF_ERROR(hr);
  497. hr = GetLPTSTRPropertyFromCache(_pPropertyCache,
  498. TEXT("Description"),
  499. &pszDescription );
  500. if(SUCCEEDED(hr)){
  501. pServerInfo->lpDescription = pszDescription;
  502. }
  503. dwErrorCode = ADsNwServerSetInfo(_pszServerName,
  504. 1,
  505. pServerInfo);
  506. hr = HRESULT_FROM_WIN32(dwErrorCode);
  507. BAIL_IF_ERROR(hr);
  508. cleanup:
  509. if(pServerInfo){
  510. ADsNwApiBufferFree(pServerInfo);
  511. }
  512. if(pszDescription){
  513. FreeADsStr(pszDescription);
  514. }
  515. RRETURN_EXP_IF_ERR(hr);
  516. }
  517. HRESULT
  518. CFPNWFileService::GetFPNWServerInfo(THIS_ BOOL fExplicit)
  519. {
  520. //
  521. // here we do a NwServerGetInfo on level1 and then unmarshall the
  522. // comment field into description
  523. //
  524. DWORD dwErrorCode;
  525. PNWSERVERINFO pServerInfo =NULL;
  526. HRESULT hr;
  527. //
  528. // only level 1 is valid
  529. //
  530. dwErrorCode = ADsNwServerGetInfo(_pszServerName,
  531. 1,
  532. &pServerInfo);
  533. hr = HRESULT_FROM_WIN32(dwErrorCode);
  534. BAIL_IF_ERROR(hr);
  535. //
  536. // unmarshall the info into the Description field
  537. //
  538. ADsAssert(pServerInfo);
  539. hr = SetLPTSTRPropertyInCache(_pPropertyCache,
  540. TEXT("Description"),
  541. pServerInfo->lpDescription,
  542. fExplicit
  543. );
  544. hr = SetLPTSTRPropertyInCache(_pPropertyCache,
  545. TEXT("HostComputer"),
  546. _Parent,
  547. fExplicit
  548. );
  549. hr = SetDWORDPropertyInCache(_pPropertyCache,
  550. TEXT("MaxUserCount"),
  551. (DWORD)-1,
  552. fExplicit
  553. );
  554. hr = SetLPTSTRPropertyInCache(
  555. _pPropertyCache,
  556. TEXT("Name"),
  557. _Name,
  558. fExplicit
  559. );
  560. hr = S_OK;
  561. cleanup:
  562. if(pServerInfo){
  563. ADsNwApiBufferFree(pServerInfo);
  564. }
  565. RRETURN_EXP_IF_ERR(hr);
  566. }
  567. STDMETHODIMP
  568. CFPNWFileService::Get(
  569. THIS_ BSTR bstrName,
  570. VARIANT FAR* pvProp
  571. )
  572. {
  573. HRESULT hr = S_OK;
  574. hr = GenericGetPropertyManager(
  575. _pPropertyCache,
  576. bstrName,
  577. pvProp
  578. );
  579. if(FAILED(hr)){
  580. hr= _pService->Get(bstrName, pvProp );
  581. }
  582. RRETURN_EXP_IF_ERR(hr);
  583. }
  584. STDMETHODIMP
  585. CFPNWFileService::Put(
  586. THIS_ BSTR bstrName,
  587. VARIANT vProp
  588. )
  589. {
  590. HRESULT hr = S_OK;
  591. hr = GenericPutPropertyManager(
  592. _pPropertyCache,
  593. FPNWFileServiceClass,
  594. gdwFPNWFileServiceTableSize,
  595. bstrName,
  596. vProp
  597. );
  598. if(FAILED(hr)){
  599. hr= _pService->Put(bstrName, vProp );
  600. }
  601. RRETURN_EXP_IF_ERR(hr);
  602. }
  603. //
  604. // IADsService Methods
  605. //
  606. /* IADsContainer methods */
  607. STDMETHODIMP
  608. CFPNWFileService::get_Count(long * retval)
  609. {
  610. RRETURN_EXP_IF_ERR(E_NOTIMPL);
  611. }
  612. STDMETHODIMP
  613. CFPNWFileService::get_Filter(THIS_ VARIANT * pVar)
  614. {
  615. HRESULT hr;
  616. VariantInit(pVar);
  617. hr = VariantCopy(pVar, &_vFilter);
  618. RRETURN_EXP_IF_ERR(hr);
  619. }
  620. STDMETHODIMP
  621. CFPNWFileService::put_Filter(THIS_ VARIANT Var)
  622. {
  623. HRESULT hr;
  624. hr = VariantCopy(&_vFilter, &Var);
  625. RRETURN_EXP_IF_ERR(hr);
  626. }
  627. STDMETHODIMP
  628. CFPNWFileService::put_Hints(THIS_ VARIANT Var)
  629. {
  630. RRETURN_EXP_IF_ERR( E_NOTIMPL);
  631. }
  632. STDMETHODIMP
  633. CFPNWFileService::get_Hints(THIS_ VARIANT FAR* pVar)
  634. {
  635. RRETURN_EXP_IF_ERR(E_NOTIMPL);
  636. }
  637. STDMETHODIMP
  638. CFPNWFileService::GetObject(THIS_ BSTR ClassName,
  639. BSTR RelativeName,
  640. IDispatch * FAR* ppObject
  641. )
  642. {
  643. HRESULT hr;
  644. DWORD dwObjectType;
  645. POBJECTINFO pObjectInfo = NULL;
  646. hr = GetObjectType(gpFilters,
  647. gdwMaxFilters,
  648. ClassName,
  649. (PDWORD)&dwObjectType);
  650. BAIL_IF_ERROR(hr);
  651. if(dwObjectType != WINNT_FILESHARE_ID){
  652. //
  653. // trying to create an invalid object at this level
  654. //
  655. hr = E_FAIL;
  656. goto error;
  657. }
  658. hr = BuildObjectInfo(_ADsPath,
  659. RelativeName,
  660. &pObjectInfo);
  661. BAIL_ON_FAILURE(hr);
  662. hr = ValidateObject(dwObjectType,
  663. pObjectInfo,
  664. _Credentials);
  665. BAIL_ON_FAILURE(hr);
  666. //
  667. // The only object that has a file service as a container is
  668. // a file share object
  669. //
  670. hr = CFPNWFileShare::Create(_ADsPath,
  671. pObjectInfo->ComponentArray[1],
  672. pObjectInfo->ComponentArray[2],
  673. RelativeName,
  674. ADS_OBJECT_UNBOUND,
  675. IID_IDispatch,
  676. _Credentials,
  677. (void**)ppObject);
  678. BAIL_ON_FAILURE(hr);
  679. error:
  680. cleanup:
  681. FreeObjectInfo(pObjectInfo);
  682. RRETURN_EXP_IF_ERR(hr);
  683. }
  684. STDMETHODIMP
  685. CFPNWFileService::get__NewEnum(THIS_ IUnknown * FAR* retval)
  686. {
  687. HRESULT hr = S_OK;
  688. CFPNWFileSharesEnumVar *pCFileSharesEnumVar = NULL;
  689. if(!retval){
  690. RRETURN_EXP_IF_ERR(E_POINTER);
  691. }
  692. *retval = NULL;
  693. hr = CFPNWFileSharesEnumVar::Create(_pszServerName,
  694. _ADsPath,
  695. &pCFileSharesEnumVar,
  696. _vFilter,
  697. _Credentials);
  698. BAIL_ON_FAILURE(hr);
  699. ADsAssert(pCFileSharesEnumVar);
  700. _pCFileSharesEnumVar = pCFileSharesEnumVar;
  701. hr = _pCFileSharesEnumVar->QueryInterface(IID_IUnknown,
  702. (void **)retval);
  703. BAIL_ON_FAILURE(hr);
  704. _pCFileSharesEnumVar->Release();
  705. RRETURN(hr);
  706. error:
  707. delete pCFileSharesEnumVar;
  708. _pCFileSharesEnumVar = NULL;
  709. RRETURN_EXP_IF_ERR(hr);
  710. }
  711. STDMETHODIMP
  712. CFPNWFileService::Create(
  713. THIS_ BSTR ClassName,
  714. BSTR RelativeName,
  715. IDispatch * FAR* ppObject
  716. )
  717. {
  718. DWORD dwObjectType = 0;
  719. HRESULT hr = S_OK;
  720. POBJECTINFO pObjectInfo = NULL;
  721. hr = GetObjectType(gpFilters,
  722. gdwMaxFilters,
  723. ClassName,
  724. (PDWORD)&dwObjectType);
  725. BAIL_IF_ERROR(hr);
  726. if(!(dwObjectType == WINNT_FILESHARE_ID ||
  727. dwObjectType == WINNT_FPNW_FILESHARE_ID)){
  728. //
  729. // trying to create an invalid object at this level
  730. //
  731. hr = E_FAIL;
  732. goto error;
  733. }
  734. hr = BuildObjectInfo(_ADsPath,
  735. RelativeName,
  736. &pObjectInfo);
  737. BAIL_ON_FAILURE(hr);
  738. hr = ValidateObject(dwObjectType,
  739. pObjectInfo,
  740. _Credentials);
  741. if(SUCCEEDED(hr)){
  742. hr = E_ADS_OBJECT_EXISTS;
  743. goto error;
  744. }
  745. //
  746. // The only object that has a file service as a container is
  747. // a file share object
  748. hr = CFPNWFileShare::Create(_ADsPath,
  749. pObjectInfo->ComponentArray[1],
  750. pObjectInfo->ComponentArray[2],
  751. RelativeName,
  752. ADS_OBJECT_UNBOUND,
  753. IID_IDispatch,
  754. _Credentials,
  755. (void**)ppObject);
  756. BAIL_ON_FAILURE(hr);
  757. error:
  758. cleanup:
  759. FreeObjectInfo(pObjectInfo);
  760. RRETURN_EXP_IF_ERR(hr);
  761. }
  762. STDMETHODIMP
  763. CFPNWFileService::Delete(THIS_ BSTR Type,
  764. BSTR SourceName
  765. )
  766. {
  767. HRESULT hr;
  768. DWORD dwObjectType = 0;
  769. POBJECTINFO pObjectInfo = NULL;
  770. // Check to make sure the input parameters are valid
  771. if (Type == NULL || SourceName == NULL) {
  772. RRETURN_EXP_IF_ERR(E_ADS_BAD_PARAMETER);
  773. }
  774. hr = GetObjectType(gpFilters,
  775. gdwMaxFilters,
  776. Type,
  777. (PDWORD)&dwObjectType);
  778. BAIL_IF_ERROR(hr);
  779. if(dwObjectType != WINNT_FILESHARE_ID){
  780. //
  781. // trying to delete an invalid object at this level
  782. //
  783. hr = E_FAIL;
  784. goto cleanup;
  785. }
  786. hr = BuildObjectInfo(_ADsPath,
  787. SourceName,
  788. &pObjectInfo);
  789. BAIL_IF_ERROR(hr);
  790. hr = FPNWDeleteFileShare(pObjectInfo);
  791. cleanup:
  792. FreeObjectInfo(pObjectInfo);
  793. RRETURN_EXP_IF_ERR(hr);
  794. }
  795. STDMETHODIMP
  796. CFPNWFileService::CopyHere(THIS_ BSTR SourceName,
  797. BSTR NewName,
  798. IDispatch * FAR* ppObject
  799. )
  800. {
  801. RRETURN_EXP_IF_ERR(E_NOTIMPL);
  802. }
  803. STDMETHODIMP
  804. CFPNWFileService::MoveHere(THIS_ BSTR SourceName,
  805. BSTR NewName,
  806. IDispatch * FAR* ppObject
  807. )
  808. {
  809. RRETURN_EXP_IF_ERR(E_NOTIMPL);
  810. }
  811. /* IADsFSFileServiceGeneralInfo methods */
  812. STDMETHODIMP
  813. CFPNWFileService::get_Description(THIS_ BSTR FAR* retval)
  814. {
  815. GET_PROPERTY_BSTR((IADsFileService *)this, Description);
  816. }
  817. STDMETHODIMP
  818. CFPNWFileService::put_Description(THIS_ BSTR bstrDescription)
  819. {
  820. PUT_PROPERTY_BSTR((IADsFileService *)this, Description);
  821. }
  822. STDMETHODIMP
  823. CFPNWFileService::get_MaxUserCount(THIS_ long FAR* retval)
  824. {
  825. //
  826. // here -1 signifies no limit
  827. //
  828. if(!retval){
  829. RRETURN_EXP_IF_ERR(E_POINTER);
  830. }
  831. *retval = -1;
  832. RRETURN(S_OK);
  833. }
  834. STDMETHODIMP CFPNWFileService::put_MaxUserCount(THIS_ long lMaxUserCount)
  835. {
  836. RRETURN_EXP_IF_ERR(E_ADS_PROPERTY_NOT_SUPPORTED);
  837. }
  838. STDMETHODIMP
  839. CFPNWFileService::Sessions(THIS_ IADsCollection ** ppSessions)
  840. {
  841. //
  842. // The session collection object is created and it is passed the server
  843. // name. It uses this to create the session object
  844. //
  845. HRESULT hr = S_OK;
  846. CFPNWSessionsCollection * pSessionsCollection = NULL;
  847. if(!ppSessions){
  848. RRETURN_EXP_IF_ERR(E_POINTER);
  849. }
  850. hr = CFPNWSessionsCollection::Create(_ADsPath,
  851. _Credentials,
  852. &pSessionsCollection);
  853. BAIL_IF_ERROR(hr);
  854. hr = pSessionsCollection->QueryInterface(IID_IADsCollection,
  855. (void **) ppSessions);
  856. BAIL_IF_ERROR(hr);
  857. pSessionsCollection->Release();
  858. cleanup:
  859. if(FAILED(hr)){
  860. delete pSessionsCollection;
  861. }
  862. RRETURN_EXP_IF_ERR(hr);
  863. }
  864. STDMETHODIMP
  865. CFPNWFileService::Resources(THIS_ IADsCollection FAR* FAR* ppResources)
  866. {
  867. //
  868. // The resource collection object is created and it is passed the server
  869. // name. It uses this to create the resource object
  870. //
  871. HRESULT hr = S_OK;
  872. CFPNWResourcesCollection * pResourcesCollection = NULL;
  873. if(!ppResources){
  874. RRETURN_EXP_IF_ERR(E_POINTER);
  875. }
  876. hr = CFPNWResourcesCollection::Create(_ADsPath,
  877. NULL,
  878. _Credentials,
  879. &pResourcesCollection);
  880. BAIL_IF_ERROR(hr);
  881. hr = pResourcesCollection->QueryInterface(IID_IADsCollection,
  882. (void **) ppResources);
  883. BAIL_IF_ERROR(hr);
  884. pResourcesCollection->Release();
  885. cleanup:
  886. if(FAILED(hr)){
  887. delete pResourcesCollection;
  888. }
  889. RRETURN_EXP_IF_ERR(hr);
  890. }
  891. STDMETHODIMP
  892. CFPNWFileService::get_HostComputer(THIS_ BSTR FAR* retval)
  893. {
  894. HRESULT hr;
  895. hr = _pService->get_HostComputer(retval);
  896. RRETURN_EXP_IF_ERR(hr);
  897. }
  898. STDMETHODIMP
  899. CFPNWFileService::put_HostComputer(THIS_ BSTR bstrHostComputer)
  900. {
  901. HRESULT hr;
  902. hr = _pService->put_HostComputer(bstrHostComputer);
  903. RRETURN_EXP_IF_ERR(hr);
  904. }
  905. STDMETHODIMP
  906. CFPNWFileService::get_DisplayName(THIS_ BSTR FAR* retval)
  907. {
  908. HRESULT hr;
  909. hr = _pService->get_DisplayName(retval);
  910. RRETURN_EXP_IF_ERR(hr);
  911. }
  912. STDMETHODIMP
  913. CFPNWFileService::put_DisplayName(THIS_ BSTR bstrDisplayName)
  914. {
  915. HRESULT hr;
  916. hr = _pService->put_DisplayName(bstrDisplayName);
  917. RRETURN_EXP_IF_ERR(hr);
  918. }
  919. STDMETHODIMP
  920. CFPNWFileService::get_Version(THIS_ BSTR FAR* retval)
  921. {
  922. HRESULT hr;
  923. hr = _pService->get_Version(retval);
  924. RRETURN_EXP_IF_ERR(hr);
  925. }
  926. STDMETHODIMP
  927. CFPNWFileService::put_Version(THIS_ BSTR bstrVersion)
  928. {
  929. HRESULT hr;
  930. hr = _pService->put_Version(bstrVersion);
  931. RRETURN_EXP_IF_ERR(hr);
  932. }
  933. STDMETHODIMP
  934. CFPNWFileService::get_ServiceType(THIS_ long FAR* retval)
  935. {
  936. HRESULT hr;
  937. hr = _pService->get_ServiceType(retval);
  938. RRETURN_EXP_IF_ERR(hr);
  939. }
  940. STDMETHODIMP
  941. CFPNWFileService::put_ServiceType(THIS_ long lServiceType)
  942. {
  943. HRESULT hr;
  944. hr = _pService->put_ServiceType(lServiceType);
  945. RRETURN_EXP_IF_ERR(hr);
  946. }
  947. STDMETHODIMP
  948. CFPNWFileService::get_StartType(THIS_ LONG FAR* retval)
  949. {
  950. HRESULT hr;
  951. hr = _pService->get_StartType(retval);
  952. RRETURN_EXP_IF_ERR(hr);
  953. }
  954. STDMETHODIMP
  955. CFPNWFileService::put_StartType(THIS_ LONG lStartType)
  956. {
  957. HRESULT hr;
  958. hr = _pService->put_StartType(lStartType);
  959. RRETURN_EXP_IF_ERR(hr);
  960. }
  961. STDMETHODIMP
  962. CFPNWFileService::get_Path(THIS_ BSTR FAR* retval)
  963. {
  964. HRESULT hr;
  965. hr = _pService->get_Path(retval);
  966. RRETURN_EXP_IF_ERR(hr);
  967. }
  968. STDMETHODIMP
  969. CFPNWFileService::put_Path(THIS_ BSTR bstrPath)
  970. {
  971. HRESULT hr;
  972. hr = _pService->put_Path(bstrPath);
  973. RRETURN_EXP_IF_ERR(hr);
  974. }
  975. STDMETHODIMP
  976. CFPNWFileService::get_StartupParameters(THIS_ BSTR FAR* retval)
  977. {
  978. HRESULT hr;
  979. hr = _pService->get_StartupParameters(retval);
  980. RRETURN_EXP_IF_ERR(hr);
  981. }
  982. STDMETHODIMP
  983. CFPNWFileService::put_StartupParameters(THIS_ BSTR bstrStartupParameters)
  984. {
  985. HRESULT hr;
  986. hr = _pService->put_StartupParameters(bstrStartupParameters);
  987. RRETURN_EXP_IF_ERR(hr);
  988. }
  989. STDMETHODIMP
  990. CFPNWFileService::get_ErrorControl(THIS_ LONG FAR* retval)
  991. {
  992. HRESULT hr;
  993. hr = _pService->get_ErrorControl(retval);
  994. RRETURN_EXP_IF_ERR(hr);
  995. }
  996. STDMETHODIMP
  997. CFPNWFileService::put_ErrorControl(THIS_ LONG lErrorControl)
  998. {
  999. HRESULT hr;
  1000. hr = _pService->put_ErrorControl(lErrorControl);
  1001. RRETURN_EXP_IF_ERR(hr);
  1002. }
  1003. STDMETHODIMP
  1004. CFPNWFileService::get_LoadOrderGroup(THIS_ BSTR FAR* retval)
  1005. {
  1006. HRESULT hr;
  1007. hr = _pService->get_LoadOrderGroup(retval);
  1008. RRETURN_EXP_IF_ERR(hr);
  1009. }
  1010. STDMETHODIMP
  1011. CFPNWFileService::put_LoadOrderGroup(THIS_ BSTR bstrLoadOrderGroup)
  1012. {
  1013. HRESULT hr;
  1014. hr = _pService->put_LoadOrderGroup(bstrLoadOrderGroup);
  1015. RRETURN_EXP_IF_ERR(hr);
  1016. }
  1017. STDMETHODIMP
  1018. CFPNWFileService::get_ServiceAccountName(THIS_ BSTR FAR* retval)
  1019. {
  1020. HRESULT hr;
  1021. hr = _pService->get_ServiceAccountName(retval);
  1022. RRETURN_EXP_IF_ERR(hr);
  1023. }
  1024. STDMETHODIMP
  1025. CFPNWFileService::put_ServiceAccountName(THIS_ BSTR bstrServiceAccountName)
  1026. {
  1027. HRESULT hr;
  1028. hr = _pService->put_ServiceAccountName(bstrServiceAccountName);
  1029. RRETURN_EXP_IF_ERR(hr);
  1030. }
  1031. STDMETHODIMP
  1032. CFPNWFileService::get_ServiceAccountPath(THIS_ BSTR FAR* retval)
  1033. {
  1034. HRESULT hr;
  1035. hr = _pService->get_ServiceAccountPath(retval);
  1036. RRETURN_EXP_IF_ERR(hr);
  1037. }
  1038. STDMETHODIMP
  1039. CFPNWFileService::put_ServiceAccountPath(THIS_ BSTR bstrServiceAccountName)
  1040. {
  1041. HRESULT hr;
  1042. hr = _pService->put_ServiceAccountPath(bstrServiceAccountName);
  1043. RRETURN_EXP_IF_ERR(hr);
  1044. }
  1045. STDMETHODIMP
  1046. CFPNWFileService::get_Dependencies(THIS_ VARIANT FAR* retval)
  1047. {
  1048. HRESULT hr;
  1049. hr = _pService->get_Dependencies(retval);
  1050. RRETURN_EXP_IF_ERR(hr);
  1051. }
  1052. STDMETHODIMP
  1053. CFPNWFileService::put_Dependencies(THIS_ VARIANT vDependencies)
  1054. {
  1055. HRESULT hr;
  1056. hr = _pService->put_Dependencies(vDependencies);
  1057. RRETURN_EXP_IF_ERR(hr);
  1058. }
  1059. STDMETHODIMP
  1060. CFPNWFileService::SetPassword(THIS_ BSTR bstrNewPassword)
  1061. {
  1062. HRESULT hr;
  1063. hr = _pServiceOps->SetPassword(bstrNewPassword);
  1064. RRETURN_EXP_IF_ERR(hr);
  1065. }
  1066. //+---------------------------------------------------------------------------
  1067. //
  1068. // Function: CFPNWFileService::Start
  1069. //
  1070. // Synopsis: Attempts to start the service specified in _bstrServiceName on
  1071. // the server named in _bstrPath.
  1072. //
  1073. // Arguments:
  1074. //
  1075. // Returns: HRESULT.
  1076. //
  1077. // Modifies:
  1078. //
  1079. // History: 01/04/96 RamV Created
  1080. //
  1081. // Notes:
  1082. //----------------------------------------------------------------------------
  1083. STDMETHODIMP
  1084. CFPNWFileService::Start(THIS)
  1085. {
  1086. HRESULT hr;
  1087. hr = _pServiceOps->Start();
  1088. RRETURN_EXP_IF_ERR(hr);
  1089. }
  1090. //+---------------------------------------------------------------------------
  1091. //
  1092. // Function: CFPNWFileService::Stop
  1093. //
  1094. // Synopsis: Attempts to stop the service specified in _bstrServiceName on
  1095. // the server named in _bstrPath.
  1096. //
  1097. // Arguments:
  1098. //
  1099. // Returns: HRESULT.
  1100. //
  1101. // Modifies:
  1102. //
  1103. // History: 01/04/96 RamV Created
  1104. //
  1105. //----------------------------------------------------------------------------
  1106. STDMETHODIMP
  1107. CFPNWFileService::Stop(THIS)
  1108. {
  1109. HRESULT hr;
  1110. hr = _pServiceOps->Stop();
  1111. RRETURN_EXP_IF_ERR(hr);
  1112. }
  1113. //+---------------------------------------------------------------------------
  1114. //
  1115. // Function: CFPNWFileService::Pause
  1116. //
  1117. // Synopsis: Attempts to pause the service named _bstrServiceName on the
  1118. // server named in _bstrPath.
  1119. //
  1120. // Arguments:
  1121. //
  1122. // Returns: HRESULT.
  1123. //
  1124. // Modifies:
  1125. //
  1126. // History: 01-04-96 RamV Created
  1127. //
  1128. //----------------------------------------------------------------------------
  1129. STDMETHODIMP
  1130. CFPNWFileService::Pause(THIS)
  1131. {
  1132. HRESULT hr;
  1133. hr = _pServiceOps->Pause();
  1134. RRETURN_EXP_IF_ERR(hr);
  1135. }
  1136. //+---------------------------------------------------------------------------
  1137. //
  1138. // Function: CFPNWFileService::Continue
  1139. //
  1140. // Synopsis: Attempts to "unpause" the service specified in _bstrServiceName
  1141. // on the server named in _bstrPath.
  1142. //
  1143. // Arguments:
  1144. //
  1145. // Returns: HRESULT.
  1146. //
  1147. // Modifies:
  1148. //
  1149. // History: 01/04/96 RamV Created
  1150. //
  1151. //----------------------------------------------------------------------------
  1152. STDMETHODIMP
  1153. CFPNWFileService::Continue(THIS)
  1154. {
  1155. HRESULT hr;
  1156. hr = _pServiceOps->Continue();
  1157. RRETURN_EXP_IF_ERR(hr);
  1158. }
  1159. STDMETHODIMP
  1160. CFPNWFileService::get_Status(THIS_ long FAR* plStatusCode)
  1161. {
  1162. HRESULT hr;
  1163. hr = _pServiceOps->get_Status(plStatusCode);
  1164. RRETURN_EXP_IF_ERR(hr);
  1165. }
  1166. STDMETHODIMP
  1167. CFPNWFileService::GetEx(
  1168. THIS_ BSTR bstrName,
  1169. VARIANT FAR* pvProp
  1170. )
  1171. {
  1172. HRESULT hr = S_OK;
  1173. hr = GenericGetExPropertyManager(
  1174. ADS_OBJECT_BOUND,
  1175. _pPropertyCache,
  1176. bstrName,
  1177. pvProp
  1178. );
  1179. if(FAILED(hr)){
  1180. hr= _pService->GetEx(bstrName, pvProp );
  1181. }
  1182. RRETURN_EXP_IF_ERR(hr);
  1183. }
  1184. STDMETHODIMP
  1185. CFPNWFileService::PutEx(
  1186. THIS_ long lnControlCode,
  1187. BSTR bstrName,
  1188. VARIANT vProp
  1189. )
  1190. {
  1191. HRESULT hr = S_OK;
  1192. hr = GenericPutExPropertyManager(
  1193. _pPropertyCache,
  1194. FPNWFileServiceClass,
  1195. gdwFPNWFileServiceTableSize,
  1196. bstrName,
  1197. vProp
  1198. );
  1199. if(FAILED(hr)){
  1200. hr= _pService->PutEx(lnControlCode, bstrName, vProp );
  1201. }
  1202. RRETURN_EXP_IF_ERR(hr);
  1203. }