Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1034 lines
26 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. hr = MakeUncName(_pszServerName, szUncServerName);
  594. BAIL_IF_ERROR(hr);
  595. //
  596. // Fill the ShareInfo2 structure
  597. //
  598. ShareInfo2.shi2_netname = _pszShareName;
  599. ShareInfo2.shi2_type = STYPE_DISKTREE;
  600. hr = GetLPTSTRPropertyFromCache(_pPropertyCache,
  601. TEXT("Path"),
  602. &pszPath);
  603. if(SUCCEEDED(hr)){
  604. ShareInfo2.shi2_path = pszPath;
  605. } else {
  606. ShareInfo2.shi2_path = _T("");
  607. }
  608. hr = GetLPTSTRPropertyFromCache(_pPropertyCache,
  609. TEXT("Description"),
  610. &pszDescription);
  611. if(SUCCEEDED(hr)){
  612. ShareInfo2.shi2_remark = pszDescription;
  613. } else {
  614. ShareInfo2.shi2_remark = TEXT("");
  615. }
  616. hr = GetDWORDPropertyFromCache(_pPropertyCache,
  617. TEXT("MaxUserCount"),
  618. &dwMaxUserCount);
  619. if(SUCCEEDED(hr)){
  620. ShareInfo2.shi2_max_uses = dwMaxUserCount;
  621. } else {
  622. ShareInfo2.shi2_max_uses = -1; // unlimited
  623. }
  624. ShareInfo2.shi2_permissions = ACCESS_ALL & ~ ACCESS_PERM;
  625. ShareInfo2.shi2_current_uses = 0;
  626. ShareInfo2.shi2_passwd = NULL;
  627. nasStatus = NetShareAdd(szUncServerName,
  628. 2,
  629. (LPBYTE )&ShareInfo2,
  630. &dwParmErr);
  631. if(nasStatus != NERR_Success){
  632. #if DBG
  633. FileShareDebugOut((DEB_TRACE,
  634. "NetShareAdd : parameter %ld unknown\n",
  635. dwParmErr));
  636. #endif
  637. hr = HRESULT_FROM_WIN32(nasStatus);
  638. goto cleanup;
  639. } else{
  640. hr = S_OK;
  641. }
  642. cleanup:
  643. if(pszPath){
  644. FreeADsStr(pszPath);
  645. }
  646. if(pszDescription){
  647. FreeADsStr(pszDescription);
  648. }
  649. RRETURN(hr);
  650. }
  651. STDMETHODIMP
  652. CWinNTFileShare::get_CurrentUserCount(THIS_ LONG FAR* retval)
  653. {
  654. GET_PROPERTY_LONG((IADsFileShare *)this, CurrentUserCount);
  655. }
  656. STDMETHODIMP
  657. CWinNTFileShare::get_Description(THIS_ BSTR FAR* retval)
  658. {
  659. GET_PROPERTY_BSTR((IADsFileShare *)this, Description);
  660. }
  661. STDMETHODIMP
  662. CWinNTFileShare::put_Description(THIS_ BSTR bstrDescription)
  663. {
  664. PUT_PROPERTY_BSTR((IADsFileShare *)this, Description);
  665. }
  666. STDMETHODIMP
  667. CWinNTFileShare::get_HostComputer(THIS_ BSTR FAR* retval)
  668. {
  669. HRESULT hr;
  670. POBJECTINFO pObjectInfo = NULL;
  671. TCHAR szComputerName[MAX_PATH];
  672. if(!retval){
  673. RRETURN_EXP_IF_ERR(E_ADS_BAD_PARAMETER);
  674. }
  675. hr = BuildObjectInfo(_Parent, &pObjectInfo);
  676. BAIL_ON_FAILURE(hr);
  677. hr = BuildComputerFromObjectInfo(pObjectInfo,
  678. szComputerName);
  679. BAIL_ON_FAILURE(hr);
  680. hr = ADsAllocString(szComputerName, retval);
  681. error:
  682. FreeObjectInfo(pObjectInfo);
  683. RRETURN_EXP_IF_ERR(hr);
  684. }
  685. STDMETHODIMP
  686. CWinNTFileShare::put_HostComputer(THIS_ BSTR bstrHostComputer)
  687. {
  688. RRETURN_EXP_IF_ERR(E_ADS_PROPERTY_NOT_SUPPORTED);
  689. }
  690. STDMETHODIMP
  691. CWinNTFileShare::get_Path(THIS_ BSTR FAR* retval)
  692. {
  693. GET_PROPERTY_BSTR((IADsFileShare *)this, Path);
  694. }
  695. STDMETHODIMP
  696. CWinNTFileShare::put_Path(THIS_ BSTR bstrPath)
  697. {
  698. //
  699. // note that path can be set only prior to creation
  700. // of the object. It cannot be changed later.
  701. //
  702. if(GetObjectState() == ADS_OBJECT_UNBOUND){
  703. PUT_PROPERTY_BSTR((IADsFileShare *)this, Path);
  704. } else {
  705. RRETURN_EXP_IF_ERR(E_ADS_PROPERTY_NOT_SUPPORTED);
  706. }
  707. }
  708. STDMETHODIMP
  709. CWinNTFileShare::get_MaxUserCount(THIS_ LONG FAR* retval)
  710. {
  711. GET_PROPERTY_LONG((IADsFileShare *)this, MaxUserCount);
  712. }
  713. STDMETHODIMP
  714. CWinNTFileShare::put_MaxUserCount(THIS_ LONG lMaxUserCount)
  715. {
  716. PUT_PROPERTY_LONG((IADsFileShare *)this, MaxUserCount);
  717. }
  718. HRESULT
  719. CWinNTFileShare::MarshallAndSet(LPSHARE_INFO_2 lpShareInfo2)
  720. {
  721. HRESULT hr = S_OK;
  722. LPTSTR pszDescription = NULL;
  723. LPTSTR pszPath = NULL;
  724. DWORD dwValue;
  725. TCHAR szUncServerName[MAX_PATH];
  726. NET_API_STATUS nasStatus;
  727. DWORD dwParmErr;
  728. hr = MakeUncName(_pszServerName,
  729. szUncServerName);
  730. BAIL_IF_ERROR(hr);
  731. hr = GetLPTSTRPropertyFromCache(
  732. _pPropertyCache,
  733. TEXT("Description"),
  734. &pszDescription
  735. );
  736. if(SUCCEEDED(hr)){
  737. lpShareInfo2->shi2_remark = pszDescription;
  738. }
  739. hr = GetLPTSTRPropertyFromCache(
  740. _pPropertyCache,
  741. TEXT("Path"),
  742. &pszPath
  743. );
  744. //
  745. // pszPath should not be NULL - sanity check to catch prefix issue.
  746. //
  747. if(SUCCEEDED(hr) && pszPath) {
  748. #ifdef WIN95
  749. if (_wcsicmp(lpShareInfo2->shi2_path, pszPath) ) {
  750. #else
  751. if (CompareStringW(
  752. LOCALE_SYSTEM_DEFAULT,
  753. NORM_IGNORECASE,
  754. lpShareInfo2->shi2_path,
  755. -1,
  756. pszPath,
  757. -1
  758. ) != CSTR_EQUAL ) {
  759. #endif
  760. // trying to change the path which is not allowed
  761. hr = (E_ADS_PROPERTY_NOT_SUPPORTED);
  762. BAIL_IF_ERROR(hr);
  763. }
  764. lpShareInfo2->shi2_path = pszPath;
  765. }
  766. hr = GetDWORDPropertyFromCache(
  767. _pPropertyCache,
  768. TEXT("MaxUserCount"),
  769. &dwValue
  770. );
  771. if(SUCCEEDED(hr)){
  772. lpShareInfo2->shi2_max_uses = dwValue;
  773. }
  774. //
  775. // you ignore earlier errors, why? because these errors were raised
  776. // due to internal cached values being invalid.
  777. //
  778. hr = S_OK;
  779. //
  780. // Do the SetInfo now that you have all info
  781. //
  782. nasStatus = NetShareSetInfo(szUncServerName,
  783. _pszShareName,
  784. 2,
  785. (LPBYTE)lpShareInfo2,
  786. &dwParmErr);
  787. if(nasStatus != NERR_Success){
  788. #if DBG
  789. FileShareDebugOut((DEB_TRACE,
  790. "NetShareSetInfo : parameter %ld unknown\n", dwParmErr));
  791. #endif
  792. hr = HRESULT_FROM_WIN32(nasStatus);
  793. }
  794. cleanup:
  795. if(pszDescription)
  796. FreeADsStr(pszDescription);
  797. if(pszPath)
  798. FreeADsStr(pszPath);
  799. RRETURN_EXP_IF_ERR(hr);
  800. }
  801. //
  802. // helper functions
  803. //
  804. HRESULT
  805. WinNTDeleteFileShare(POBJECTINFO pObjectInfo)
  806. {
  807. HRESULT hr = S_OK;
  808. NET_API_STATUS nasStatus = NERR_Success;
  809. TCHAR szUncServerName[MAX_PATH];
  810. hr = MakeUncName(pObjectInfo->ComponentArray[1],
  811. szUncServerName);
  812. BAIL_IF_ERROR(hr);
  813. nasStatus = NetShareDel(szUncServerName,
  814. pObjectInfo->ComponentArray[3],
  815. 0);
  816. cleanup:
  817. if(FAILED(hr)){
  818. RRETURN(hr);
  819. }
  820. if(nasStatus != NERR_Success){
  821. RRETURN(HRESULT_FROM_WIN32(nasStatus));
  822. }
  823. else{
  824. RRETURN(S_OK);
  825. }
  826. }