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.

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