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.

626 lines
13 KiB

  1. //---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1996
  5. //
  6. // File: cfshare.cxx
  7. //
  8. // Contents: CNWCOMPATFileShare
  9. //
  10. //
  11. // History: 25-Apr-96 t-ptam (Patrick Tam) Created.
  12. //
  13. //----------------------------------------------------------------------------
  14. #include "NWCOMPAT.hxx"
  15. #pragma hdrstop
  16. //
  17. // Macro-ized implementation.
  18. //
  19. DEFINE_IDispatch_Implementation(CNWCOMPATFileShare);
  20. DEFINE_IADs_TempImplementation(CNWCOMPATFileShare);
  21. DEFINE_IADs_PutGetImplementation(CNWCOMPATFileShare, FileShareClass, gdwFileShareTableSize)
  22. DEFINE_IADsPropertyList_Implementation(CNWCOMPATFileShare, FileShareClass, gdwFileShareTableSize)
  23. //----------------------------------------------------------------------------
  24. //
  25. // Function: CNWCOMPATFileShare::CNWCOMPATFileShare
  26. //
  27. // Synopsis:
  28. //
  29. //----------------------------------------------------------------------------
  30. CNWCOMPATFileShare::CNWCOMPATFileShare():
  31. _pDispMgr(NULL),
  32. _pPropertyCache(NULL),
  33. _hConn(NULL)
  34. {
  35. ENLIST_TRACKING(CNWCOMPATFileShare);
  36. }
  37. //----------------------------------------------------------------------------
  38. //
  39. // Function:
  40. //
  41. // Synopsis:
  42. //
  43. //----------------------------------------------------------------------------
  44. CNWCOMPATFileShare::~CNWCOMPATFileShare()
  45. {
  46. delete _pDispMgr;
  47. delete _pPropertyCache;
  48. if (_hConn)
  49. NWApiReleaseBinderyHandle(_hConn);
  50. }
  51. //----------------------------------------------------------------------------
  52. //
  53. // Function: CNWCOMPATFileShare::CreateFileShare
  54. //
  55. // Synopsis:
  56. //
  57. //----------------------------------------------------------------------------
  58. HRESULT
  59. CNWCOMPATFileShare::CreateFileShare(
  60. LPTSTR pszADsParent,
  61. LPTSTR pszShareName,
  62. CCredentials &Credentials,
  63. DWORD dwObjectState,
  64. REFIID riid,
  65. LPVOID * ppvoid
  66. )
  67. {
  68. CNWCOMPATFileShare FAR * pFileShare = NULL;
  69. HRESULT hr = S_OK;
  70. POBJECTINFO pObjectInfo = NULL;
  71. //
  72. // Allocate memory for a FileShare object.
  73. //
  74. hr = AllocateFileShareObject(
  75. &pFileShare
  76. );
  77. BAIL_ON_FAILURE(hr);
  78. //
  79. // Initialize its core object.
  80. //
  81. hr = pFileShare->InitializeCoreObject(
  82. pszADsParent,
  83. pszShareName,
  84. FILESHARE_CLASS_NAME,
  85. FILESHARE_SCHEMA_NAME,
  86. CLSID_NWCOMPATFileShare,
  87. dwObjectState
  88. );
  89. BAIL_ON_FAILURE(hr);
  90. //
  91. // Credentials
  92. //
  93. pFileShare->_Credentials = Credentials;
  94. //
  95. // Componentize ADs name.
  96. //
  97. hr = BuildObjectInfo(
  98. pFileShare->_Parent,
  99. pFileShare->_Name,
  100. &pObjectInfo
  101. );
  102. BAIL_ON_FAILURE(hr);
  103. //
  104. // Get a handle to the bindery this computer object represents.
  105. //
  106. hr = NWApiGetBinderyHandle(
  107. &pFileShare->_hConn,
  108. pObjectInfo->ComponentArray[0],
  109. pFileShare->_Credentials
  110. );
  111. BAIL_ON_FAILURE(hr);
  112. //
  113. // Get interface pointer.
  114. //
  115. hr = pFileShare->QueryInterface(
  116. riid,
  117. (void **)ppvoid
  118. );
  119. BAIL_ON_FAILURE(hr);
  120. pFileShare->Release();
  121. FreeObjectInfo(pObjectInfo);
  122. //
  123. // Return.
  124. //
  125. RRETURN(hr);
  126. error:
  127. if (pObjectInfo)
  128. FreeObjectInfo(pObjectInfo);
  129. delete pFileShare;
  130. NW_RRETURN_EXP_IF_ERR(hr);
  131. }
  132. //----------------------------------------------------------------------------
  133. //
  134. // Function: CNWCOMPATFileShare::QueryInterface
  135. //
  136. // Synopsis:
  137. //
  138. //----------------------------------------------------------------------------
  139. STDMETHODIMP
  140. CNWCOMPATFileShare::QueryInterface(
  141. REFIID riid,
  142. LPVOID FAR* ppvObj
  143. )
  144. {
  145. if(!ppvObj){
  146. RRETURN(E_POINTER);
  147. }
  148. if (IsEqualIID(riid, IID_IUnknown))
  149. {
  150. *ppvObj = this;
  151. }
  152. else if (IsEqualIID(riid, IID_IDispatch))
  153. {
  154. *ppvObj = (IADsFileShare *) this;
  155. }
  156. else if (IsEqualIID(riid, IID_ISupportErrorInfo))
  157. {
  158. *ppvObj = (ISupportErrorInfo FAR *) this;
  159. }
  160. else if (IsEqualIID(riid, IID_IADs))
  161. {
  162. *ppvObj = (IADs FAR *) this;
  163. }
  164. else if (IsEqualIID(riid, IID_IADsFileShare))
  165. {
  166. *ppvObj = (IADsFileShare FAR *) this;
  167. }
  168. else if (IsEqualIID(riid, IID_IADsPropertyList))
  169. {
  170. *ppvObj = (IADsPropertyList FAR *) this;
  171. }
  172. else
  173. {
  174. *ppvObj = NULL;
  175. RRETURN(E_NOINTERFACE);
  176. }
  177. AddRef();
  178. return NOERROR;
  179. }
  180. //
  181. // ISupportErrorInfo method
  182. //
  183. STDMETHODIMP
  184. CNWCOMPATFileShare::InterfaceSupportsErrorInfo(
  185. THIS_ REFIID riid
  186. )
  187. {
  188. if (IsEqualIID(riid, IID_IADs) ||
  189. IsEqualIID(riid, IID_IADsFileShare) ||
  190. IsEqualIID(riid, IID_IADsPropertyList)) {
  191. return S_OK;
  192. } else {
  193. return S_FALSE;
  194. }
  195. }
  196. //----------------------------------------------------------------------------
  197. //
  198. // Function: CNWCOMPATFileShare::SetInfo
  199. //
  200. // Synopsis:
  201. //
  202. //----------------------------------------------------------------------------
  203. STDMETHODIMP
  204. CNWCOMPATFileShare::SetInfo(THIS)
  205. {
  206. NW_RRETURN_EXP_IF_ERR(E_NOTIMPL);
  207. }
  208. //----------------------------------------------------------------------------
  209. //
  210. // Function: CNWCOMPATFileShare::GetInfo
  211. //
  212. // Synopsis:
  213. //
  214. //----------------------------------------------------------------------------
  215. STDMETHODIMP
  216. CNWCOMPATFileShare::GetInfo(THIS)
  217. {
  218. _pPropertyCache->flushpropcache();
  219. RRETURN(GetInfo(
  220. TRUE,
  221. FSHARE_WILD_CARD_ID
  222. ));
  223. }
  224. //----------------------------------------------------------------------------
  225. //
  226. // Function: CNWCOMPATFileShare::AllocateFileShareObject
  227. //
  228. // Synopsis:
  229. //
  230. //----------------------------------------------------------------------------
  231. HRESULT
  232. CNWCOMPATFileShare::AllocateFileShareObject(
  233. CNWCOMPATFileShare **ppFileShare
  234. )
  235. {
  236. CNWCOMPATFileShare FAR * pFileShare = NULL;
  237. CDispatchMgr FAR * pDispMgr = NULL;
  238. HRESULT hr = S_OK;
  239. //
  240. // Allocate memory for a FileShare object.
  241. //
  242. pFileShare = new CNWCOMPATFileShare();
  243. if (pFileShare == NULL) {
  244. hr = E_OUTOFMEMORY;
  245. goto error;
  246. }
  247. //
  248. // Create a Dispatch Manager object.
  249. //
  250. pDispMgr = new CDispatchMgr;
  251. if(pDispMgr == NULL){
  252. hr = E_OUTOFMEMORY;
  253. goto error;
  254. }
  255. //
  256. // Load type info.
  257. //
  258. hr = LoadTypeInfoEntry(
  259. pDispMgr,
  260. LIBID_ADs,
  261. IID_IADsFileShare,
  262. (IADsFileShare *)pFileShare,
  263. DISPID_REGULAR
  264. );
  265. BAIL_ON_FAILURE(hr);
  266. hr = LoadTypeInfoEntry(
  267. pDispMgr,
  268. LIBID_ADs,
  269. IID_IADsPropertyList,
  270. (IADsPropertyList *)pFileShare,
  271. DISPID_VALUE
  272. );
  273. BAIL_ON_FAILURE(hr);
  274. hr = CPropertyCache::createpropertycache(
  275. FileShareClass,
  276. gdwFileShareTableSize,
  277. (CCoreADsObject *)pFileShare,
  278. &(pFileShare ->_pPropertyCache)
  279. );
  280. BAIL_ON_FAILURE(hr);
  281. pFileShare->_pDispMgr = pDispMgr;
  282. *ppFileShare = pFileShare;
  283. RRETURN(hr);
  284. error:
  285. delete pDispMgr;
  286. delete pFileShare;
  287. RRETURN(hr);
  288. }
  289. //----------------------------------------------------------------------------
  290. //
  291. // Function: CNWCOMPATFileShare::GetInfo
  292. //
  293. // Synopsis:
  294. //
  295. //----------------------------------------------------------------------------
  296. STDMETHODIMP
  297. CNWCOMPATFileShare::GetInfo(
  298. BOOL fExplicit,
  299. THIS_ DWORD dwPropertyID
  300. )
  301. {
  302. HRESULT hr = S_OK;
  303. POBJECTINFO pObjectInfo = NULL;
  304. //
  305. // Make sure the object is bound to a tangible resource.
  306. //
  307. if (GetObjectState() == ADS_OBJECT_UNBOUND) {
  308. NW_RRETURN_EXP_IF_ERR(E_ADS_OBJECT_UNBOUND);
  309. }
  310. //
  311. // Componentize ADs name.
  312. //
  313. hr = BuildObjectInfo(
  314. _Parent,
  315. _Name,
  316. &pObjectInfo
  317. );
  318. BAIL_ON_FAILURE(hr);
  319. //
  320. // Fill in all property caches with values - explicit, or return the
  321. // indicated property - implicit.
  322. //
  323. if (fExplicit) {
  324. hr = ExplicitGetInfo(
  325. _hConn,
  326. pObjectInfo,
  327. fExplicit
  328. );
  329. BAIL_ON_FAILURE(hr);
  330. }
  331. else {
  332. hr = ImplicitGetInfo(
  333. _hConn,
  334. pObjectInfo,
  335. dwPropertyID,
  336. fExplicit
  337. );
  338. BAIL_ON_FAILURE(hr);
  339. }
  340. error:
  341. if (pObjectInfo) {
  342. FreeObjectInfo(pObjectInfo);
  343. }
  344. NW_RRETURN_EXP_IF_ERR(hr);
  345. }
  346. //----------------------------------------------------------------------------
  347. //
  348. // Function: CNWCOMPATFileShare::ExplicitGetInfo
  349. //
  350. // Synopsis:
  351. //
  352. //----------------------------------------------------------------------------
  353. HRESULT
  354. CNWCOMPATFileShare::ExplicitGetInfo(
  355. NWCONN_HANDLE hConn,
  356. POBJECTINFO pObjectInfo,
  357. BOOL fExplicit
  358. )
  359. {
  360. HRESULT hr = S_OK;
  361. hr = GetProperty_Description(
  362. fExplicit
  363. );
  364. if (hr == E_ADS_PROPERTY_NOT_FOUND) {
  365. // not a real failure, we ignore it and treat it as a missing attrib
  366. hr = S_OK;
  367. }
  368. BAIL_ON_FAILURE(hr);
  369. hr = GetProperty_HostComputer(
  370. pObjectInfo,
  371. fExplicit
  372. );
  373. if (hr == E_ADS_PROPERTY_NOT_FOUND) {
  374. // not a real failure, we ignore it and treat it as a missing attrib
  375. hr = S_OK;
  376. }
  377. BAIL_ON_FAILURE(hr);
  378. hr = GetProperty_MaxUserCount(
  379. hConn,
  380. fExplicit
  381. );
  382. if (hr == E_ADS_PROPERTY_NOT_FOUND) {
  383. // not a real failure, we ignore it and treat it as a missing attrib
  384. hr = S_OK;
  385. }
  386. BAIL_ON_FAILURE(hr);
  387. error:
  388. RRETURN(hr);
  389. }
  390. //----------------------------------------------------------------------------
  391. //
  392. // Function: CNWCOMPATFileShare::ImplicitGetInfo
  393. //
  394. // Synopsis:
  395. //
  396. //----------------------------------------------------------------------------
  397. HRESULT
  398. CNWCOMPATFileShare::ImplicitGetInfo(
  399. NWCONN_HANDLE hConn,
  400. POBJECTINFO pObjectInfo,
  401. DWORD dwPropertyID,
  402. BOOL fExplicit
  403. )
  404. {
  405. HRESULT hr = S_OK;
  406. switch (dwPropertyID) {
  407. case FSHARE_DESCRIPTION_ID:
  408. hr = GetProperty_Description(
  409. fExplicit
  410. );
  411. break;
  412. case FSHARE_HOSTCOMPUTER_ID:
  413. hr = GetProperty_HostComputer(
  414. pObjectInfo,
  415. fExplicit
  416. );
  417. break;
  418. case FSHARE_MAXUSERCOUNT_ID:
  419. hr = GetProperty_MaxUserCount(
  420. hConn,
  421. fExplicit
  422. );
  423. break;
  424. }
  425. RRETURN(hr);
  426. }
  427. //----------------------------------------------------------------------------
  428. //
  429. // Function: CNWCOMPATFileShare::GetProperty_Description
  430. //
  431. // Synopsis:
  432. //
  433. //----------------------------------------------------------------------------
  434. HRESULT
  435. CNWCOMPATFileShare::GetProperty_Description(
  436. BOOL fExplicit
  437. )
  438. {
  439. HRESULT hr = S_OK;
  440. //
  441. // BUGBUG - bstrFileShareDescription is HARDCODED.
  442. //
  443. hr = SetLPTSTRPropertyInCache(
  444. _pPropertyCache,
  445. TEXT("Description"),
  446. bstrFileShareDescription,
  447. fExplicit
  448. );
  449. RRETURN(hr);
  450. }
  451. //----------------------------------------------------------------------------
  452. //
  453. // Function: CNWCOMPATFileShare::GetProperty_HostComputer
  454. //
  455. // Synopsis:
  456. //
  457. //----------------------------------------------------------------------------
  458. HRESULT
  459. CNWCOMPATFileShare::GetProperty_HostComputer(
  460. POBJECTINFO pObjectInfo,
  461. BOOL fExplicit
  462. )
  463. {
  464. HRESULT hr = S_OK;
  465. WCHAR szBuffer[MAX_PATH];
  466. //
  467. // Build ADs path of Host computer from ObjectInfo.
  468. //
  469. wsprintf(
  470. szBuffer,
  471. L"%s://%s",
  472. pObjectInfo->ProviderName,
  473. pObjectInfo->ComponentArray[0]
  474. );
  475. //
  476. // Unmarshall
  477. //
  478. hr = SetLPTSTRPropertyInCache(_pPropertyCache,
  479. TEXT("HostComputer"),
  480. szBuffer,
  481. fExplicit
  482. );
  483. //
  484. // Return.
  485. //
  486. RRETURN(hr);
  487. }
  488. //----------------------------------------------------------------------------
  489. //
  490. // Function: CNWCOMPATFileShare::GetProperty_MaxUserCount
  491. //
  492. // Synopsis: Note that the Max Number of Connections Supported of the
  493. // FileServer is used. In NetWare, there isn't a per share max valu.
  494. //
  495. //----------------------------------------------------------------------------
  496. HRESULT
  497. CNWCOMPATFileShare::GetProperty_MaxUserCount(
  498. NWCONN_HANDLE hConn,
  499. BOOL fExplicit
  500. )
  501. {
  502. HRESULT hr = S_OK;
  503. DWORD dwTemp = 0;
  504. NW_VERSION_INFO VersionInfo;
  505. //
  506. // Get the Maximum number of connections supported from the Version
  507. // Information of the FileServer.
  508. //
  509. hr = NWApiGetFileServerVersionInfo(
  510. hConn,
  511. &VersionInfo
  512. );
  513. BAIL_ON_FAILURE(hr);
  514. dwTemp = VersionInfo.ConnsSupported;
  515. //
  516. // Unmarshall.
  517. //
  518. hr = SetDWORDPropertyInCache(_pPropertyCache,
  519. TEXT("MaxUserCount"),
  520. dwTemp,
  521. fExplicit
  522. );
  523. //
  524. // Return.
  525. //
  526. error:
  527. RRETURN(hr);
  528. }