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.

1510 lines
35 KiB

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