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.

601 lines
14 KiB

  1. //---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1996
  5. //
  6. // File: cenumcom.cxx
  7. //
  8. // Contents: NetWare 3.12 Path Object code
  9. //
  10. // CNWCOMPATComputerEnum::
  11. // CNWCOMPATComputerEnum::
  12. // CNWCOMPATComputerEnum::
  13. // CNWCOMPATComputerEnum::
  14. //
  15. // History:
  16. //----------------------------------------------------------------------------
  17. #include "NWCOMPAT.hxx"
  18. #pragma hdrstop
  19. //+---------------------------------------------------------------------------
  20. //
  21. // Function: CNWCOMPATEnumVariant::Create
  22. //
  23. // Synopsis:
  24. //
  25. // Arguments:
  26. //
  27. //
  28. // Returns: HRESULT
  29. //
  30. // Modifies:
  31. //
  32. // History: 01-30-95 t-ptam Created.
  33. //
  34. //----------------------------------------------------------------------------
  35. HRESULT
  36. CNWCOMPATComputerEnum::Create(
  37. CNWCOMPATComputerEnum FAR* FAR* ppenumvariant,
  38. BSTR ADsPath,
  39. BSTR ComputerName,
  40. CCredentials &Credentials,
  41. VARIANT var
  42. )
  43. {
  44. HRESULT hr = NOERROR;
  45. CNWCOMPATComputerEnum FAR* penumvariant = NULL;
  46. *ppenumvariant = NULL;
  47. //
  48. // Allocate memory for an enumerator.
  49. //
  50. penumvariant = new CNWCOMPATComputerEnum();
  51. if (!penumvariant) {
  52. hr = E_OUTOFMEMORY;
  53. BAIL_ON_FAILURE(hr);
  54. }
  55. //
  56. // Save protected values.
  57. //
  58. hr = ADsAllocString(ADsPath, &penumvariant->_ADsPath);
  59. BAIL_ON_FAILURE(hr);
  60. hr = ADsAllocString( ComputerName, &penumvariant->_ComputerName);
  61. BAIL_ON_FAILURE(hr);
  62. penumvariant->_Credentials = Credentials;
  63. hr = NWApiGetBinderyHandle(
  64. &penumvariant->_hConn,
  65. ComputerName,
  66. Credentials
  67. );
  68. BAIL_ON_FAILURE(hr);
  69. //
  70. // Make object list.
  71. //
  72. hr = ObjectTypeList::CreateObjectTypeList(
  73. var,
  74. &penumvariant->_pObjList
  75. );
  76. BAIL_ON_FAILURE(hr);
  77. //
  78. // Return.
  79. //
  80. *ppenumvariant = penumvariant;
  81. RRETURN(hr);
  82. error:
  83. delete penumvariant;
  84. NW_RRETURN_EXP_IF_ERR(hr);
  85. }
  86. //----------------------------------------------------------------------------
  87. //
  88. // Function: CNWCOMPATComputerEnum::CNWCOMPATComputerEnum
  89. //
  90. // Synopsis:
  91. //
  92. //----------------------------------------------------------------------------
  93. CNWCOMPATComputerEnum::CNWCOMPATComputerEnum():
  94. _ComputerName(NULL),
  95. _ADsPath(NULL)
  96. {
  97. _hConn = NULL;
  98. _pObjList = NULL;
  99. _dwUserResumeObjectID = 0xffffffff;
  100. _dwGroupResumeObjectID = 0xffffffff;
  101. _dwPrinterResumeObjectID = 0xffffffff;
  102. _fFileServiceOnce = FALSE;
  103. }
  104. //----------------------------------------------------------------------------
  105. //
  106. // Function: CNWCOMPATComputerEnum::~CNWCOMPATComputerEnum
  107. //
  108. // Synopsis:
  109. //
  110. //----------------------------------------------------------------------------
  111. CNWCOMPATComputerEnum::~CNWCOMPATComputerEnum()
  112. {
  113. if (_ComputerName)
  114. SysFreeString(_ComputerName);
  115. if (_ADsPath)
  116. SysFreeString(_ADsPath);
  117. if (_pObjList)
  118. delete _pObjList;
  119. if (_hConn)
  120. NWApiReleaseBinderyHandle(_hConn);
  121. }
  122. //----------------------------------------------------------------------------
  123. //
  124. // Function: CNWCOMPATComputerEnum::EnumObjects
  125. //
  126. // Synopsis:
  127. //
  128. //----------------------------------------------------------------------------
  129. HRESULT
  130. CNWCOMPATComputerEnum::EnumObjects(
  131. DWORD ObjectType,
  132. ULONG cElements,
  133. VARIANT FAR * pvar,
  134. ULONG FAR * pcElementFetched
  135. )
  136. {
  137. switch (ObjectType) {
  138. case NWCOMPAT_USER_ID:
  139. return(EnumUsers( cElements, pvar, pcElementFetched));
  140. case NWCOMPAT_GROUP_ID:
  141. return(EnumGroups( cElements, pvar, pcElementFetched));
  142. case NWCOMPAT_SERVICE_ID:
  143. return(EnumFileServices(cElements, pvar, pcElementFetched));
  144. case NWCOMPAT_PRINTER_ID:
  145. return(EnumPrinters(cElements, pvar, pcElementFetched));
  146. default:
  147. return(S_FALSE);
  148. }
  149. }
  150. //----------------------------------------------------------------------------
  151. //
  152. // Function: CNWCOMPATComputerEnum::EnumObjects
  153. //
  154. // Synopsis:
  155. //
  156. //----------------------------------------------------------------------------
  157. HRESULT
  158. CNWCOMPATComputerEnum::EnumObjects(
  159. ULONG cElements,
  160. VARIANT FAR* pvar,
  161. ULONG FAR* pcElementFetched
  162. )
  163. {
  164. DWORD i;
  165. ULONG cRequested = 0;
  166. ULONG cFetchedByPath = 0;
  167. ULONG cTotalFetched = 0;
  168. VARIANT FAR* pPathvar = pvar;
  169. HRESULT hr = S_OK;
  170. DWORD ObjectType;
  171. for (i = 0; i < cElements; i++) {
  172. VariantInit(&pvar[i]);
  173. }
  174. cRequested = cElements;
  175. while (SUCCEEDED(_pObjList->GetCurrentObject(&ObjectType)) &&
  176. ((hr = EnumObjects(
  177. ObjectType,
  178. cRequested,
  179. pPathvar,
  180. &cFetchedByPath)) == S_FALSE )) {
  181. pPathvar += cFetchedByPath;
  182. cRequested -= cFetchedByPath;
  183. cTotalFetched += cFetchedByPath;
  184. cFetchedByPath = 0;
  185. if (FAILED(_pObjList->Next())){
  186. if (pcElementFetched)
  187. *pcElementFetched = cTotalFetched;
  188. return(ResultFromScode(S_FALSE));
  189. }
  190. }
  191. if (pcElementFetched) {
  192. *pcElementFetched = cTotalFetched + cFetchedByPath;
  193. }
  194. RRETURN(hr);
  195. }
  196. //----------------------------------------------------------------------------
  197. //
  198. // Function: CNWCOMPATComputerEnum::EnumUsers
  199. //
  200. // Synopsis:
  201. //
  202. //----------------------------------------------------------------------------
  203. HRESULT
  204. CNWCOMPATComputerEnum::EnumUsers(
  205. ULONG cElements,
  206. VARIANT FAR* pvar,
  207. ULONG FAR* pcElementFetched
  208. )
  209. {
  210. HRESULT hr = S_OK;
  211. IDispatch *pDispatch = NULL;
  212. DWORD i = 0;
  213. while (i < cElements) {
  214. hr = GetUserObject(&pDispatch);
  215. if (hr == S_FALSE) {
  216. break;
  217. }
  218. VariantInit(&pvar[i]);
  219. pvar[i].vt = VT_DISPATCH;
  220. pvar[i].pdispVal = pDispatch;
  221. (*pcElementFetched)++;
  222. i++;
  223. }
  224. RRETURN_ENUM_STATUS(hr);
  225. }
  226. //----------------------------------------------------------------------------
  227. //
  228. // Function: CNWCOMPATComputerEnum::GetUserObject
  229. //
  230. // Synopsis:
  231. //
  232. //----------------------------------------------------------------------------
  233. HRESULT
  234. CNWCOMPATComputerEnum::GetUserObject(
  235. IDispatch ** ppDispatch
  236. )
  237. {
  238. HRESULT hr = S_OK;
  239. LPTSTR pszObjectName = NULL;
  240. *ppDispatch = NULL;
  241. hr = NWApiObjectEnum(
  242. _hConn,
  243. OT_USER,
  244. &pszObjectName,
  245. &_dwUserResumeObjectID
  246. );
  247. BAIL_ON_FAILURE(hr);
  248. //
  249. // Now send back the current object
  250. //
  251. hr = CNWCOMPATUser::CreateUser(
  252. _ADsPath,
  253. NWCOMPAT_COMPUTER_ID,
  254. _ComputerName,
  255. pszObjectName,
  256. _Credentials,
  257. ADS_OBJECT_BOUND,
  258. IID_IDispatch,
  259. (void **)ppDispatch
  260. );
  261. BAIL_ON_FAILURE(hr);
  262. error:
  263. if (pszObjectName) {
  264. FreeADsStr(pszObjectName);
  265. }
  266. RRETURN_ENUM_STATUS(hr);
  267. }
  268. //----------------------------------------------------------------------------
  269. //
  270. // Function: CNWCOMPATComputerEnum::EnumGroups
  271. //
  272. // Synopsis:
  273. //
  274. //----------------------------------------------------------------------------
  275. HRESULT
  276. CNWCOMPATComputerEnum::EnumGroups(
  277. ULONG cElements,
  278. VARIANT FAR* pvar,
  279. ULONG FAR* pcElementFetched
  280. )
  281. {
  282. HRESULT hr = S_OK;
  283. IDispatch *pDispatch = NULL;
  284. DWORD i = 0;
  285. while (i < cElements) {
  286. hr = GetGroupObject(&pDispatch);
  287. if (hr == S_FALSE) {
  288. break;
  289. }
  290. VariantInit(&pvar[i]);
  291. pvar[i].vt = VT_DISPATCH;
  292. pvar[i].pdispVal = pDispatch;
  293. (*pcElementFetched)++;
  294. i++;
  295. }
  296. RRETURN_ENUM_STATUS(hr);
  297. }
  298. //----------------------------------------------------------------------------
  299. //
  300. // Function: CNWCOMPATComputerEnum::GetGroupObject
  301. //
  302. // Synopsis:
  303. //
  304. //----------------------------------------------------------------------------
  305. HRESULT
  306. CNWCOMPATComputerEnum::GetGroupObject(
  307. IDispatch ** ppDispatch
  308. )
  309. {
  310. HRESULT hr = S_OK;
  311. LPTSTR pszObjectName = NULL;
  312. *ppDispatch = NULL;
  313. hr = NWApiObjectEnum(
  314. _hConn,
  315. OT_USER_GROUP,
  316. &pszObjectName,
  317. &_dwGroupResumeObjectID
  318. );
  319. BAIL_ON_FAILURE(hr);
  320. //
  321. // Now send back the current ovbject
  322. //
  323. hr = CNWCOMPATGroup::CreateGroup(
  324. _ADsPath,
  325. NWCOMPAT_COMPUTER_ID,
  326. _ComputerName,
  327. pszObjectName,
  328. _Credentials,
  329. ADS_OBJECT_BOUND,
  330. IID_IDispatch,
  331. (void **)ppDispatch
  332. );
  333. BAIL_ON_FAILURE(hr);
  334. error:
  335. if (pszObjectName) {
  336. FreeADsStr(pszObjectName);
  337. }
  338. RRETURN_ENUM_STATUS(hr);
  339. }
  340. //----------------------------------------------------------------------------
  341. //
  342. // Function: CNWCOMPATComputerEnum::EnumFileServices
  343. //
  344. // Synopsis:
  345. //
  346. //----------------------------------------------------------------------------
  347. HRESULT
  348. CNWCOMPATComputerEnum::EnumFileServices(
  349. ULONG cElements,
  350. VARIANT FAR* pvar,
  351. ULONG FAR* pcElementFetched
  352. )
  353. {
  354. HRESULT hr = S_OK;
  355. IDispatch *pDispatch = NULL;
  356. DWORD i = 0;
  357. while (i < cElements) {
  358. hr = GetFileServiceObject(&pDispatch);
  359. if (hr == S_FALSE) {
  360. break;
  361. }
  362. VariantInit(&pvar[i]);
  363. pvar[i].vt = VT_DISPATCH;
  364. pvar[i].pdispVal = pDispatch;
  365. (*pcElementFetched)++;
  366. i++;
  367. }
  368. RRETURN_ENUM_STATUS(hr);
  369. }
  370. //----------------------------------------------------------------------------
  371. //
  372. // Function: CNWCOMPATComputerEnum::GetFileServiceObject
  373. //
  374. // Synopsis:
  375. //
  376. //----------------------------------------------------------------------------
  377. HRESULT
  378. CNWCOMPATComputerEnum::GetFileServiceObject(
  379. IDispatch ** ppDispatch
  380. )
  381. {
  382. HRESULT hr = S_OK;
  383. //
  384. // This is a NetWare provider specific condition. Since a FileService
  385. // object on a bindery (computer) is the bindery itself, therefore there is
  386. // always one FileService object only. And therefore this function is
  387. // called only once.
  388. //
  389. if (!_fFileServiceOnce) {
  390. _fFileServiceOnce = TRUE;
  391. //
  392. // Create a file service object with the Hard coded name.
  393. //
  394. hr = CNWCOMPATFileService::CreateFileService(
  395. _ADsPath,
  396. _ComputerName,
  397. bstrNWFileServiceName,
  398. _Credentials,
  399. ADS_OBJECT_BOUND,
  400. IID_IDispatch,
  401. (void **)ppDispatch
  402. );
  403. RRETURN_ENUM_STATUS(hr);
  404. }
  405. else {
  406. RRETURN(S_FALSE);
  407. }
  408. }
  409. //----------------------------------------------------------------------------
  410. //
  411. // Function: CNWCOMPATComputerEnum::EnumPrinters
  412. //
  413. // Synopsis:
  414. //
  415. //----------------------------------------------------------------------------
  416. HRESULT
  417. CNWCOMPATComputerEnum::EnumPrinters(
  418. ULONG cElements,
  419. VARIANT FAR* pvar,
  420. ULONG FAR* pcElementFetched
  421. )
  422. {
  423. HRESULT hr = S_OK;
  424. IDispatch *pDispatch = NULL;
  425. DWORD i = 0;
  426. while (i < cElements) {
  427. hr = GetPrinterObject(&pDispatch);
  428. if (hr == S_FALSE) {
  429. break;
  430. }
  431. VariantInit(&pvar[i]);
  432. pvar[i].vt = VT_DISPATCH;
  433. pvar[i].pdispVal = pDispatch;
  434. (*pcElementFetched)++;
  435. i++;
  436. }
  437. RRETURN_ENUM_STATUS(hr);
  438. }
  439. //----------------------------------------------------------------------------
  440. //
  441. // Function: CNWCOMPATComputerEnum::GetPrinterObject
  442. //
  443. // Synopsis:
  444. //
  445. //----------------------------------------------------------------------------
  446. HRESULT
  447. CNWCOMPATComputerEnum::GetPrinterObject(
  448. IDispatch ** ppDispatch
  449. )
  450. {
  451. HRESULT hr = S_OK;
  452. LPTSTR pszObjectName;
  453. *ppDispatch = NULL;
  454. hr = NWApiObjectEnum(
  455. _hConn,
  456. OT_PRINT_QUEUE,
  457. &pszObjectName,
  458. &_dwPrinterResumeObjectID
  459. );
  460. BAIL_ON_FAILURE(hr);
  461. //
  462. // Now send back the current ovbject
  463. //
  464. hr = CNWCOMPATPrintQueue::CreatePrintQueue(
  465. _ADsPath,
  466. pszObjectName,
  467. _Credentials,
  468. ADS_OBJECT_BOUND,
  469. IID_IDispatch,
  470. (void **)ppDispatch
  471. );
  472. BAIL_ON_FAILURE(hr);
  473. error:
  474. if (pszObjectName) {
  475. FreeADsStr(pszObjectName);
  476. }
  477. RRETURN_ENUM_STATUS(hr);
  478. }
  479. //+---------------------------------------------------------------------------
  480. //
  481. // Function: CNWCOMPATComputerEnum::Next
  482. //
  483. // Synopsis: Returns cElements number of requested ADs objects in the
  484. // array supplied in pvar.
  485. //
  486. // Arguments: [cElements] -- The number of elements requested by client
  487. // [pvar] -- ptr to array of VARIANTs to for return objects
  488. // [pcElementFetched] -- if non-NULL, then number of elements
  489. // -- actually returned is placed here
  490. //
  491. // Returns: HRESULT -- S_OK if number of elements requested are returned
  492. // -- S_FALSE if number of elements is < requested
  493. //
  494. // Modifies:
  495. //
  496. // History: 11-3-95 krishnag Created.
  497. //
  498. //----------------------------------------------------------------------------
  499. STDMETHODIMP
  500. CNWCOMPATComputerEnum::Next(
  501. ULONG cElements,
  502. VARIANT FAR* pvar,
  503. ULONG FAR* pcElementFetched
  504. )
  505. {
  506. ULONG cElementFetched = 0;
  507. HRESULT hr = S_OK;
  508. hr = EnumObjects(
  509. cElements,
  510. pvar,
  511. &cElementFetched
  512. );
  513. if (pcElementFetched) {
  514. *pcElementFetched = cElementFetched;
  515. }
  516. NW_RRETURN_EXP_IF_ERR(hr);
  517. }