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.

1031 lines
25 KiB

  1. //--------------------------------------------------------------------------/
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1996
  5. //
  6. // File: cfshare.cxx
  7. //
  8. // Contents: Contains methods for the following objects
  9. // CWinNTFileShare, CWinNTFileShareGeneralInfo
  10. //
  11. //
  12. // History: 02/15/96 ramv (Ram Viswanathan) Created.
  13. //
  14. //----------------------------------------------------------------------------
  15. #include "winnt.hxx"
  16. #pragma hdrstop
  17. #define INITGUID
  18. #if DBG
  19. DECLARE_INFOLEVEL(FileShare );
  20. DECLARE_DEBUG( FileShare);
  21. #define FileShareDebugOut(x) FileShareInlineDebugOut x
  22. #endif
  23. DEFINE_IDispatch_ExtMgr_Implementation(CWinNTFileShare);
  24. DEFINE_IADsExtension_ExtMgr_Implementation(CWinNTFileShare);
  25. DEFINE_IADs_TempImplementation(CWinNTFileShare);
  26. DEFINE_IADs_PutGetImplementation(CWinNTFileShare,FileShareClass, gdwFileShareTableSize);
  27. DEFINE_IADsPropertyList_Implementation(CWinNTFileShare, FileShareClass, gdwFileShareTableSize)
  28. CWinNTFileShare::CWinNTFileShare()
  29. {
  30. _pDispMgr = NULL;
  31. _pExtMgr = NULL;
  32. _pszShareName = NULL;
  33. _pPropertyCache = NULL;
  34. _pszServerName = NULL;
  35. ENLIST_TRACKING(CWinNTFileShare);
  36. return;
  37. }
  38. CWinNTFileShare::~CWinNTFileShare()
  39. {
  40. delete _pExtMgr; // created last, destroyed first
  41. delete _pDispMgr;
  42. if(_pszShareName){
  43. FreeADsStr(_pszShareName);
  44. }
  45. if(_pszServerName){
  46. FreeADsStr(_pszServerName);
  47. }
  48. delete _pPropertyCache;
  49. return;
  50. }
  51. //+---------------------------------------------------------------------------
  52. //
  53. // Function: CWinNTFileShare::Create
  54. //
  55. // Synopsis: Static function used to create a FileShare object. This
  56. // will be called by EnumFileShares::Next
  57. //
  58. // Arguments: [ppWinNTFileShare] -- Ptr to a ptr to a new FileShare object.
  59. //
  60. // Returns: HRESULT.
  61. //
  62. // Modifies:
  63. //
  64. // History: 12-11-95 RamV Created.
  65. //
  66. //----------------------------------------------------------------------------
  67. HRESULT
  68. CWinNTFileShare::Create(LPTSTR pszADsParent,
  69. LPTSTR pszServerName,
  70. LPTSTR pszServiceName,
  71. LPTSTR pszShareName,
  72. DWORD dwObject,
  73. REFIID riid,
  74. CWinNTCredentials& Credentials,
  75. LPVOID * ppvoid
  76. )
  77. {
  78. CWinNTFileShare FAR * pCWinNTFileShare = NULL;
  79. HRESULT hr;
  80. //
  81. // Create the FileShare Object
  82. //
  83. hr = AllocateFileShareObject(pszADsParent,
  84. pszServerName,
  85. pszServiceName,
  86. pszShareName,
  87. &pCWinNTFileShare );
  88. BAIL_ON_FAILURE(hr);
  89. ADsAssert(pCWinNTFileShare->_pDispMgr);
  90. hr = pCWinNTFileShare->InitializeCoreObject(pszADsParent,
  91. pszShareName,
  92. FILESHARE_CLASS_NAME,
  93. FILESHARE_SCHEMA_NAME,
  94. CLSID_WinNTFileShare,
  95. dwObject);
  96. BAIL_ON_FAILURE(hr);
  97. pCWinNTFileShare->_Credentials = Credentials;
  98. hr = pCWinNTFileShare->_Credentials.RefServer(pszServerName);
  99. BAIL_ON_FAILURE(hr);
  100. //
  101. // Load ext mgr and extensions
  102. //
  103. hr = ADSILoadExtensionManager(
  104. FILESHARE_CLASS_NAME,
  105. (IADs *) pCWinNTFileShare,
  106. pCWinNTFileShare->_pDispMgr,
  107. Credentials,
  108. &pCWinNTFileShare->_pExtMgr
  109. );
  110. BAIL_ON_FAILURE(hr);
  111. ADsAssert(pCWinNTFileShare->_pExtMgr);
  112. // check if the call is from UMI
  113. if(Credentials.GetFlags() & ADS_AUTH_RESERVED) {
  114. //
  115. // we do not pass riid to InitUmiObject below. This is because UMI object
  116. // does not support IDispatch. There are several places in ADSI code where
  117. // riid passed into this function is defaulted to IID_IDispatch -
  118. // IADsContainer::Create for example. To handle these cases, we always
  119. // request IID_IUnknown from the UMI object. Subsequent code within UMI
  120. // will QI for the appropriate interface.
  121. //
  122. if(4 == pCWinNTFileShare->_dwNumComponents) {
  123. pCWinNTFileShare->_CompClasses[0] = L"Domain";
  124. pCWinNTFileShare->_CompClasses[1] = L"Computer";
  125. pCWinNTFileShare->_CompClasses[2] = L"FileService";
  126. pCWinNTFileShare->_CompClasses[3] = L"FileShare";
  127. }
  128. else if(3 == pCWinNTFileShare->_dwNumComponents) {
  129. pCWinNTFileShare->_CompClasses[0] = L"Computer";
  130. pCWinNTFileShare->_CompClasses[1] = L"FileService";
  131. pCWinNTFileShare->_CompClasses[2] = L"FileShare";
  132. }
  133. else
  134. BAIL_ON_FAILURE(hr = UMI_E_FAIL);
  135. hr = pCWinNTFileShare->InitUmiObject(
  136. pCWinNTFileShare->_Credentials,
  137. FileShareClass,
  138. gdwFileShareTableSize,
  139. pCWinNTFileShare->_pPropertyCache,
  140. (IUnknown *) (INonDelegatingUnknown *) pCWinNTFileShare,
  141. pCWinNTFileShare->_pExtMgr,
  142. IID_IUnknown,
  143. ppvoid
  144. );
  145. BAIL_ON_FAILURE(hr);
  146. //
  147. // UMI object was created and the interface was obtained successfully.
  148. // UMI object now has a reference to the inner unknown of IADs, since
  149. // the call to Release() below is not going to be made in this case.
  150. //
  151. RRETURN(hr);
  152. }
  153. hr = pCWinNTFileShare->QueryInterface(riid, (void **)ppvoid);
  154. BAIL_ON_FAILURE(hr);
  155. pCWinNTFileShare->Release();
  156. RRETURN(hr);
  157. error:
  158. delete pCWinNTFileShare;
  159. RRETURN (hr);
  160. }
  161. HRESULT
  162. CWinNTFileShare::AllocateFileShareObject(LPTSTR pszADsParent,
  163. LPTSTR pszServerName,
  164. LPTSTR pszServiceName,
  165. LPTSTR pszShareName,
  166. CWinNTFileShare ** ppFileShare
  167. )
  168. {
  169. CWinNTFileShare * pCWinNTFileShare = NULL;
  170. HRESULT hr;
  171. //
  172. // Create the FileShare Object
  173. //
  174. pCWinNTFileShare = new CWinNTFileShare();
  175. if (pCWinNTFileShare == NULL) {
  176. hr = E_OUTOFMEMORY;
  177. goto error;
  178. }
  179. pCWinNTFileShare->_pDispMgr = new CAggregatorDispMgr;
  180. if(pCWinNTFileShare ->_pDispMgr == NULL){
  181. hr = E_OUTOFMEMORY;
  182. goto error;
  183. }
  184. hr = LoadTypeInfoEntry(pCWinNTFileShare->_pDispMgr,
  185. LIBID_ADs,
  186. IID_IADsFileShare,
  187. (IADsFileShare *)pCWinNTFileShare,
  188. DISPID_REGULAR );
  189. BAIL_ON_FAILURE(hr);
  190. hr = LoadTypeInfoEntry(pCWinNTFileShare->_pDispMgr,
  191. LIBID_ADs,
  192. IID_IADsPropertyList,
  193. (IADsPropertyList *)pCWinNTFileShare,
  194. DISPID_VALUE );
  195. BAIL_ON_FAILURE(hr);
  196. pCWinNTFileShare->_pszServerName =
  197. AllocADsStr(pszServerName);
  198. if(!(pCWinNTFileShare->_pszServerName)){
  199. hr = E_OUTOFMEMORY;
  200. goto error;
  201. }
  202. pCWinNTFileShare->_pszShareName =
  203. AllocADsStr(pszShareName);
  204. if(!(pCWinNTFileShare->_pszShareName)){
  205. hr = E_OUTOFMEMORY;
  206. goto error;
  207. }
  208. hr = CPropertyCache::createpropertycache(
  209. FileShareClass,
  210. gdwFileShareTableSize,
  211. (CCoreADsObject *)pCWinNTFileShare,
  212. &(pCWinNTFileShare ->_pPropertyCache)
  213. );
  214. BAIL_ON_FAILURE(hr);
  215. (pCWinNTFileShare->_pDispMgr)->RegisterPropertyCache(
  216. pCWinNTFileShare->_pPropertyCache
  217. );
  218. *ppFileShare = pCWinNTFileShare;
  219. RRETURN(hr);
  220. error:
  221. //
  222. // direct memeber assignement assignement at pt of creation, so
  223. // do NOT delete _pPropertyCache or _pDisMgr here to avoid attempt
  224. // of deletion again in pPrintJob destructor and AV
  225. //
  226. delete pCWinNTFileShare;
  227. RRETURN (hr);
  228. }
  229. /* IUnknown methods for FileShare object */
  230. //----------------------------------------------------------------------------
  231. // Function: QueryInterface
  232. //
  233. // Synopsis: If this object is aggregated within another object, then
  234. // all calls will delegate to the outer object. Otherwise, the
  235. // non-delegating QI is called
  236. //
  237. // Arguments:
  238. //
  239. // iid interface requested
  240. // ppInterface Returns pointer to interface requested. NULL if interface
  241. // is not supported.
  242. //
  243. // Returns: S_OK on success. Error code otherwise.
  244. //
  245. // Modifies: *ppInterface to return interface pointer
  246. //
  247. //----------------------------------------------------------------------------
  248. STDMETHODIMP CWinNTFileShare::QueryInterface(
  249. REFIID iid,
  250. LPVOID *ppInterface
  251. )
  252. {
  253. if(_pUnkOuter != NULL)
  254. RRETURN(_pUnkOuter->QueryInterface(
  255. iid,
  256. ppInterface
  257. ));
  258. RRETURN(NonDelegatingQueryInterface(
  259. iid,
  260. ppInterface
  261. ));
  262. }
  263. //----------------------------------------------------------------------------
  264. // Function: AddRef
  265. //
  266. // Synopsis: IUnknown::AddRef. If this object is aggregated within
  267. // another, all calls will delegate to the outer object.
  268. // Otherwise, the non-delegating AddRef is called
  269. //
  270. // Arguments:
  271. //
  272. // None
  273. //
  274. // Returns: New reference count
  275. //
  276. // Modifies: Nothing
  277. //
  278. //----------------------------------------------------------------------------
  279. STDMETHODIMP_(ULONG) CWinNTFileShare::AddRef(void)
  280. {
  281. if(_pUnkOuter != NULL)
  282. RRETURN(_pUnkOuter->AddRef());
  283. RRETURN(NonDelegatingAddRef());
  284. }
  285. //----------------------------------------------------------------------------
  286. // Function: Release
  287. //
  288. // Synopsis: IUnknown::Release. If this object is aggregated within
  289. // another, all calls will delegate to the outer object.
  290. // Otherwise, the non-delegating Release is called
  291. //
  292. // Arguments:
  293. //
  294. // None
  295. //
  296. // Returns: New reference count
  297. //
  298. // Modifies: Nothing
  299. //
  300. //----------------------------------------------------------------------------
  301. STDMETHODIMP_(ULONG) CWinNTFileShare::Release(void)
  302. {
  303. if(_pUnkOuter != NULL)
  304. RRETURN(_pUnkOuter->Release());
  305. RRETURN(NonDelegatingRelease());
  306. }
  307. //----------------------------------------------------------------------------
  308. STDMETHODIMP
  309. CWinNTFileShare::NonDelegatingQueryInterface(REFIID riid, LPVOID FAR* ppvObj)
  310. {
  311. HRESULT hr = S_OK;
  312. if(!ppvObj){
  313. RRETURN(E_POINTER);
  314. }
  315. if (IsEqualIID(riid, IID_IUnknown))
  316. {
  317. *ppvObj = (IADs *) this;
  318. }
  319. else if (IsEqualIID(riid, IID_IDispatch))
  320. {
  321. *ppvObj = (IADs *)this;
  322. }
  323. else if (IsEqualIID(riid, IID_ISupportErrorInfo))
  324. {
  325. *ppvObj = (ISupportErrorInfo FAR *) this;
  326. }
  327. else if (IsEqualIID(riid, IID_IADsPropertyList))
  328. {
  329. *ppvObj = (IADsPropertyList *)this;
  330. }
  331. else if (IsEqualIID(riid, IID_IADs))
  332. {
  333. *ppvObj = (IADs FAR *) this;
  334. }
  335. else if (IsEqualIID(riid, IID_IADsFileShare))
  336. {
  337. *ppvObj = (IADsFileShare FAR *) this;
  338. }
  339. else if( (_pDispatch != NULL) &&
  340. IsEqualIID(riid, IID_IADsExtension) )
  341. {
  342. *ppvObj = (IADsExtension *) this;
  343. }
  344. else if (_pExtMgr)
  345. {
  346. RRETURN( _pExtMgr->QueryInterface(riid, ppvObj));
  347. }
  348. else
  349. {
  350. *ppvObj = NULL;
  351. RRETURN(E_NOINTERFACE);
  352. }
  353. ((LPUNKNOWN)*ppvObj)->AddRef();
  354. RRETURN(S_OK);
  355. }
  356. /* ISupportErrorInfo method */
  357. STDMETHODIMP
  358. CWinNTFileShare::InterfaceSupportsErrorInfo(
  359. THIS_ REFIID riid
  360. )
  361. {
  362. if (IsEqualIID(riid, IID_IADs) ||
  363. IsEqualIID(riid, IID_IADsFileShare) ||
  364. IsEqualIID(riid, IID_IADsPropertyList)) {
  365. return S_OK;
  366. } else {
  367. return S_FALSE;
  368. }
  369. }
  370. //+-----------------------------------------------------------------
  371. //
  372. // Function: SetInfo
  373. //
  374. // Synopsis: SetInfo on actual FileShare
  375. //
  376. // Arguments: void
  377. //
  378. // Returns: HRESULT.
  379. //
  380. // Modifies:
  381. //
  382. // History: 02/08/96 RamV Created
  383. //----------------------------------------------------------------------------
  384. STDMETHODIMP
  385. CWinNTFileShare::SetInfo(THIS)
  386. {
  387. NET_API_STATUS nasStatus;
  388. LPSHARE_INFO_2 lpShareInfo2 = NULL;
  389. HRESULT hr = S_OK;
  390. TCHAR szUncServerName[MAX_PATH];
  391. BOOL fNewFileShare = FALSE;
  392. if (GetObjectState() == ADS_OBJECT_UNBOUND) {
  393. hr = WinNTAddFileShare();
  394. BAIL_IF_ERROR(hr);
  395. SetObjectState(ADS_OBJECT_BOUND);
  396. fNewFileShare = TRUE;
  397. }
  398. //
  399. // First get the information and modify only those fields which
  400. // have been changed by user
  401. //
  402. hr = MakeUncName(_pszServerName, szUncServerName);
  403. BAIL_IF_ERROR(hr);
  404. nasStatus = NetShareGetInfo(szUncServerName,
  405. _pszShareName,
  406. 2,
  407. (LPBYTE *)&lpShareInfo2);
  408. if (nasStatus != NERR_Success || !lpShareInfo2){
  409. hr = HRESULT_FROM_WIN32(nasStatus);
  410. goto cleanup;
  411. }
  412. hr = MarshallAndSet(lpShareInfo2);
  413. BAIL_IF_ERROR(hr);
  414. if(SUCCEEDED(hr))
  415. _pPropertyCache->ClearModifiedFlags();
  416. cleanup:
  417. if (FAILED(hr) && fNewFileShare) {
  418. //
  419. // Try and delete the fileshare as the SetInfo as a
  420. // whole failed but the create part was successful.
  421. //
  422. nasStatus = NetShareDel(
  423. szUncServerName,
  424. _pszShareName,
  425. 0
  426. );
  427. }
  428. if(lpShareInfo2)
  429. NetApiBufferFree(lpShareInfo2);
  430. RRETURN_EXP_IF_ERR(hr);
  431. }
  432. STDMETHODIMP
  433. CWinNTFileShare::GetInfo(THIS_ DWORD dwApiLevel, BOOL fExplicit)
  434. {
  435. HRESULT hr = S_OK;
  436. switch(dwApiLevel){
  437. case 1:
  438. hr = GetLevel1Info(fExplicit);
  439. BAIL_IF_ERROR(hr);
  440. break;
  441. case 2:
  442. hr = GetLevel2Info(fExplicit);
  443. BAIL_IF_ERROR(hr);
  444. break;
  445. default:
  446. //
  447. // we should not be here
  448. //
  449. ADsAssert(FALSE);
  450. break;
  451. }
  452. cleanup:
  453. RRETURN_EXP_IF_ERR (hr);
  454. }
  455. STDMETHODIMP
  456. CWinNTFileShare::GetInfo(THIS)
  457. {
  458. RRETURN(GetInfo(2,TRUE));
  459. }
  460. STDMETHODIMP
  461. CWinNTFileShare::ImplicitGetInfo(THIS)
  462. {
  463. RRETURN(GetInfo(2,FALSE));
  464. }
  465. //
  466. // helper functions for GetInfo and SetInfo
  467. //
  468. HRESULT
  469. CWinNTFileShare::GetLevel2Info(THIS_ BOOL fExplicit)
  470. {
  471. //
  472. // here we do a NetShareGetInfo on level 2 and unmarshall the relevant
  473. // fields
  474. //
  475. NET_API_STATUS nasStatus;
  476. LPSHARE_INFO_2 lpShareInfo2 = NULL;
  477. HRESULT hr;
  478. TCHAR szUncServerName[MAX_PATH];
  479. POBJECTINFO pObjectInfo = NULL;
  480. TCHAR szComputerPath[MAX_PATH];
  481. hr = MakeUncName(_pszServerName, szUncServerName);
  482. BAIL_IF_ERROR(hr);
  483. nasStatus = NetShareGetInfo(szUncServerName,
  484. _pszShareName,
  485. 2,
  486. (LPBYTE *)&lpShareInfo2);
  487. if (nasStatus != NERR_Success || !lpShareInfo2){
  488. hr = HRESULT_FROM_WIN32(nasStatus);
  489. goto cleanup;
  490. }
  491. //
  492. // unmarshall the info
  493. //
  494. hr = BuildObjectInfo(_Parent, &pObjectInfo);
  495. BAIL_IF_ERROR(hr);
  496. hr = BuildComputerFromObjectInfo(pObjectInfo,
  497. szComputerPath);
  498. BAIL_IF_ERROR(hr);
  499. hr = SetLPTSTRPropertyInCache(_pPropertyCache,
  500. TEXT("HostComputer"),
  501. szComputerPath,
  502. fExplicit
  503. );
  504. hr = SetLPTSTRPropertyInCache(_pPropertyCache,
  505. TEXT("Description"),
  506. lpShareInfo2->shi2_remark,
  507. fExplicit
  508. );
  509. hr = SetLPTSTRPropertyInCache(_pPropertyCache,
  510. TEXT("Path"),
  511. lpShareInfo2->shi2_path,
  512. fExplicit
  513. );
  514. hr = SetDWORDPropertyInCache(_pPropertyCache,
  515. TEXT("CurrentUserCount"),
  516. lpShareInfo2->shi2_current_uses,
  517. fExplicit
  518. );
  519. hr = SetDWORDPropertyInCache(_pPropertyCache,
  520. TEXT("MaxUserCount"),
  521. lpShareInfo2->shi2_max_uses,
  522. fExplicit
  523. );
  524. hr = SetLPTSTRPropertyInCache(
  525. _pPropertyCache,
  526. TEXT("Name"),
  527. _Name,
  528. fExplicit
  529. );
  530. cleanup:
  531. if(lpShareInfo2){
  532. NetApiBufferFree(lpShareInfo2);
  533. }
  534. FreeObjectInfo(pObjectInfo);
  535. RRETURN(hr);
  536. }
  537. HRESULT
  538. CWinNTFileShare::GetLevel1Info(THIS_ BOOL fExplicit)
  539. {
  540. //
  541. // here we do a NetShareGetInfo on level 1 and unmarshall the relevant
  542. // fields
  543. //
  544. NET_API_STATUS nasStatus;
  545. LPSHARE_INFO_1 lpShareInfo1 = NULL;
  546. HRESULT hr;
  547. TCHAR szUncServerName[MAX_PATH];
  548. POBJECTINFO pObjectInfo = NULL;
  549. TCHAR szComputerPath[MAX_PATH];
  550. hr = MakeUncName(_pszServerName, szUncServerName);
  551. BAIL_IF_ERROR(hr);
  552. nasStatus = NetShareGetInfo(szUncServerName,
  553. _pszShareName,
  554. 1,
  555. (LPBYTE *)&lpShareInfo1);
  556. if (nasStatus != NERR_Success || !lpShareInfo1){
  557. hr = HRESULT_FROM_WIN32(nasStatus);
  558. goto cleanup;
  559. }
  560. //
  561. // unmarshall the info
  562. //
  563. //
  564. // unmarshall the info
  565. //
  566. hr = BuildObjectInfo(_Parent, &pObjectInfo);
  567. BAIL_IF_ERROR(hr);
  568. hr = BuildComputerFromObjectInfo(pObjectInfo,
  569. szComputerPath);
  570. BAIL_IF_ERROR(hr);
  571. hr = SetLPTSTRPropertyInCache(_pPropertyCache,
  572. TEXT("HostComputer"),
  573. szComputerPath,
  574. fExplicit
  575. );
  576. cleanup:
  577. if(lpShareInfo1)
  578. NetApiBufferFree(lpShareInfo1);
  579. FreeObjectInfo(pObjectInfo);
  580. RRETURN(hr);
  581. }
  582. HRESULT
  583. CWinNTFileShare::WinNTAddFileShare(void)
  584. {
  585. TCHAR szUncServerName[MAX_ADS_PATH];
  586. NET_API_STATUS nasStatus;
  587. SHARE_INFO_2 ShareInfo2;
  588. DWORD dwParmErr;
  589. DWORD dwMaxUserCount;
  590. LPTSTR pszPath = NULL;
  591. LPTSTR pszDescription = NULL;
  592. HRESULT hr = S_OK;
  593. MakeUncName(_pszServerName, szUncServerName);
  594. //
  595. // Fill the ShareInfo2 structure
  596. //
  597. ShareInfo2.shi2_netname = _pszShareName;
  598. ShareInfo2.shi2_type = STYPE_DISKTREE;
  599. hr = GetLPTSTRPropertyFromCache(_pPropertyCache,
  600. TEXT("Path"),
  601. &pszPath);
  602. if(SUCCEEDED(hr)){
  603. ShareInfo2.shi2_path = pszPath;
  604. }
  605. hr = GetLPTSTRPropertyFromCache(_pPropertyCache,
  606. TEXT("Description"),
  607. &pszDescription);
  608. if(SUCCEEDED(hr)){
  609. ShareInfo2.shi2_remark = pszDescription;
  610. } else {
  611. ShareInfo2.shi2_remark = TEXT("");
  612. }
  613. hr = GetDWORDPropertyFromCache(_pPropertyCache,
  614. TEXT("MaxUserCount"),
  615. &dwMaxUserCount);
  616. if(SUCCEEDED(hr)){
  617. ShareInfo2.shi2_max_uses = dwMaxUserCount;
  618. } else {
  619. ShareInfo2.shi2_max_uses = -1; // unlimited
  620. }
  621. ShareInfo2.shi2_permissions = ACCESS_ALL & ~ ACCESS_PERM;
  622. ShareInfo2.shi2_current_uses = 0;
  623. ShareInfo2.shi2_passwd = NULL;
  624. nasStatus = NetShareAdd(szUncServerName,
  625. 2,
  626. (LPBYTE )&ShareInfo2,
  627. &dwParmErr);
  628. if(nasStatus != NERR_Success){
  629. #if DBG
  630. FileShareDebugOut((DEB_TRACE,
  631. "NetShareAdd : parameter %ld unknown\n",
  632. dwParmErr));
  633. #endif
  634. hr = HRESULT_FROM_WIN32(nasStatus);
  635. goto cleanup;
  636. } else{
  637. hr = S_OK;
  638. }
  639. cleanup:
  640. if(pszPath){
  641. FreeADsStr(pszPath);
  642. }
  643. if(pszDescription){
  644. FreeADsStr(pszDescription);
  645. }
  646. RRETURN(hr);
  647. }
  648. STDMETHODIMP
  649. CWinNTFileShare::get_CurrentUserCount(THIS_ LONG FAR* retval)
  650. {
  651. GET_PROPERTY_LONG((IADsFileShare *)this, CurrentUserCount);
  652. }
  653. STDMETHODIMP
  654. CWinNTFileShare::get_Description(THIS_ BSTR FAR* retval)
  655. {
  656. GET_PROPERTY_BSTR((IADsFileShare *)this, Description);
  657. }
  658. STDMETHODIMP
  659. CWinNTFileShare::put_Description(THIS_ BSTR bstrDescription)
  660. {
  661. PUT_PROPERTY_BSTR((IADsFileShare *)this, Description);
  662. }
  663. STDMETHODIMP
  664. CWinNTFileShare::get_HostComputer(THIS_ BSTR FAR* retval)
  665. {
  666. HRESULT hr;
  667. POBJECTINFO pObjectInfo = NULL;
  668. TCHAR szComputerName[MAX_PATH];
  669. if(!retval){
  670. RRETURN_EXP_IF_ERR(E_ADS_BAD_PARAMETER);
  671. }
  672. hr = BuildObjectInfo(_Parent, &pObjectInfo);
  673. BAIL_ON_FAILURE(hr);
  674. hr = BuildComputerFromObjectInfo(pObjectInfo,
  675. szComputerName);
  676. BAIL_ON_FAILURE(hr);
  677. hr = ADsAllocString(szComputerName, retval);
  678. error:
  679. FreeObjectInfo(pObjectInfo);
  680. RRETURN_EXP_IF_ERR(hr);
  681. }
  682. STDMETHODIMP
  683. CWinNTFileShare::put_HostComputer(THIS_ BSTR bstrHostComputer)
  684. {
  685. RRETURN_EXP_IF_ERR(E_ADS_PROPERTY_NOT_SUPPORTED);
  686. }
  687. STDMETHODIMP
  688. CWinNTFileShare::get_Path(THIS_ BSTR FAR* retval)
  689. {
  690. GET_PROPERTY_BSTR((IADsFileShare *)this, Path);
  691. }
  692. STDMETHODIMP
  693. CWinNTFileShare::put_Path(THIS_ BSTR bstrPath)
  694. {
  695. //
  696. // note that path can be set only prior to creation
  697. // of the object. It cannot be changed later.
  698. //
  699. if(GetObjectState() == ADS_OBJECT_UNBOUND){
  700. PUT_PROPERTY_BSTR((IADsFileShare *)this, Path);
  701. } else {
  702. RRETURN_EXP_IF_ERR(E_ADS_PROPERTY_NOT_SUPPORTED);
  703. }
  704. }
  705. STDMETHODIMP
  706. CWinNTFileShare::get_MaxUserCount(THIS_ LONG FAR* retval)
  707. {
  708. GET_PROPERTY_LONG((IADsFileShare *)this, MaxUserCount);
  709. }
  710. STDMETHODIMP
  711. CWinNTFileShare::put_MaxUserCount(THIS_ LONG lMaxUserCount)
  712. {
  713. PUT_PROPERTY_LONG((IADsFileShare *)this, MaxUserCount);
  714. }
  715. HRESULT
  716. CWinNTFileShare::MarshallAndSet(LPSHARE_INFO_2 lpShareInfo2)
  717. {
  718. HRESULT hr = S_OK;
  719. LPTSTR pszDescription = NULL;
  720. LPTSTR pszPath = NULL;
  721. DWORD dwValue;
  722. TCHAR szUncServerName[MAX_PATH];
  723. NET_API_STATUS nasStatus;
  724. DWORD dwParmErr;
  725. hr = MakeUncName(_pszServerName,
  726. szUncServerName);
  727. BAIL_IF_ERROR(hr);
  728. hr = GetLPTSTRPropertyFromCache(
  729. _pPropertyCache,
  730. TEXT("Description"),
  731. &pszDescription
  732. );
  733. if(SUCCEEDED(hr)){
  734. lpShareInfo2->shi2_remark = pszDescription;
  735. }
  736. hr = GetLPTSTRPropertyFromCache(
  737. _pPropertyCache,
  738. TEXT("Path"),
  739. &pszPath
  740. );
  741. //
  742. // pszPath should not be NULL - sanity check to catch prefix issue.
  743. //
  744. if(SUCCEEDED(hr) && pszPath) {
  745. #ifdef WIN95
  746. if (_wcsicmp(lpShareInfo2->shi2_path, pszPath) ) {
  747. #else
  748. if (CompareStringW(
  749. LOCALE_SYSTEM_DEFAULT,
  750. NORM_IGNORECASE,
  751. lpShareInfo2->shi2_path,
  752. -1,
  753. pszPath,
  754. -1
  755. ) != CSTR_EQUAL ) {
  756. #endif
  757. // trying to change the path which is not allowed
  758. hr = (E_ADS_PROPERTY_NOT_SUPPORTED);
  759. BAIL_IF_ERROR(hr);
  760. }
  761. lpShareInfo2->shi2_path = pszPath;
  762. }
  763. hr = GetDWORDPropertyFromCache(
  764. _pPropertyCache,
  765. TEXT("MaxUserCount"),
  766. &dwValue
  767. );
  768. if(SUCCEEDED(hr)){
  769. lpShareInfo2->shi2_max_uses = dwValue;
  770. }
  771. //
  772. // you ignore earlier errors, why? because these errors were raised
  773. // due to internal cached values being invalid.
  774. //
  775. hr = S_OK;
  776. //
  777. // Do the SetInfo now that you have all info
  778. //
  779. nasStatus = NetShareSetInfo(szUncServerName,
  780. _pszShareName,
  781. 2,
  782. (LPBYTE)lpShareInfo2,
  783. &dwParmErr);
  784. if(nasStatus != NERR_Success){
  785. #if DBG
  786. FileShareDebugOut((DEB_TRACE,
  787. "NetShareSetInfo : parameter %ld unknown\n", dwParmErr));
  788. #endif
  789. hr = HRESULT_FROM_WIN32(nasStatus);
  790. }
  791. cleanup:
  792. if(pszDescription)
  793. FreeADsStr(pszDescription);
  794. if(pszPath)
  795. FreeADsStr(pszPath);
  796. RRETURN_EXP_IF_ERR(hr);
  797. }
  798. //
  799. // helper functions
  800. //
  801. HRESULT
  802. WinNTDeleteFileShare(POBJECTINFO pObjectInfo)
  803. {
  804. HRESULT hr = S_OK;
  805. NET_API_STATUS nasStatus;
  806. TCHAR szUncServerName[MAX_ADS_PATH];
  807. hr = MakeUncName(pObjectInfo->ComponentArray[1],
  808. szUncServerName);
  809. BAIL_IF_ERROR(hr);
  810. nasStatus = NetShareDel(szUncServerName,
  811. pObjectInfo->ComponentArray[3],
  812. 0);
  813. cleanup:
  814. if(FAILED(hr)){
  815. RRETURN(hr);
  816. }
  817. if(nasStatus != NERR_Success){
  818. RRETURN(HRESULT_FROM_WIN32(nasStatus));
  819. }
  820. else{
  821. RRETURN(S_OK);
  822. }
  823. }