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.

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