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.

376 lines
8.8 KiB

  1. //---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1995
  5. //
  6. // File: cenumdom.cxx
  7. //
  8. // Contents: NDS Object Enumeration Code
  9. //
  10. // CNDSTreeEnum::CNDSTreeEnum()
  11. // CNDSTreeEnum::CNDSTreeEnum
  12. // CNDSTreeEnum::EnumObjects
  13. // CNDSTreeEnum::EnumObjects
  14. //
  15. // History:
  16. //----------------------------------------------------------------------------
  17. #include "NDS.hxx"
  18. #pragma hdrstop
  19. //+---------------------------------------------------------------------------
  20. //
  21. // Function: CNDSEnumVariant::Create
  22. //
  23. // Synopsis:
  24. //
  25. // Arguments: [pCollection]
  26. // [ppEnumVariant]
  27. //
  28. // Returns: HRESULT
  29. //
  30. // Modifies:
  31. //
  32. // History: 01-30-95 krishnag Created.
  33. //
  34. //----------------------------------------------------------------------------
  35. HRESULT
  36. CNDSTreeEnum::Create(
  37. CNDSTreeEnum FAR* FAR* ppenumvariant,
  38. BSTR ADsPath,
  39. VARIANT var,
  40. CCredentials& Credentials
  41. )
  42. {
  43. HRESULT hr = NOERROR;
  44. CNDSTreeEnum FAR* penumvariant = NULL;
  45. WCHAR szObjectFullName[MAX_PATH];
  46. WCHAR szObjectClassName[MAX_PATH];
  47. LPWSTR pszNDSPath = NULL;
  48. DWORD dwModificationTime = 0L;
  49. DWORD dwNumberOfEntries = 0L;
  50. DWORD dwStatus = 0L;
  51. *ppenumvariant = NULL;
  52. penumvariant = new CNDSTreeEnum();
  53. if (!penumvariant) {
  54. hr = E_OUTOFMEMORY;
  55. BAIL_ON_FAILURE(hr);
  56. }
  57. hr = ADsAllocString( ADsPath, &penumvariant->_ADsPath);
  58. BAIL_ON_FAILURE(hr);
  59. hr = BuildNDSFilterArray(
  60. var,
  61. (LPBYTE *)&penumvariant->_pNdsFilterList
  62. );
  63. if (FAILED(hr)) {
  64. penumvariant->_pNdsFilterList = NULL;
  65. }
  66. /*
  67. hr = ObjectTypeList::CreateObjectTypeList(
  68. var,
  69. &penumvariant->_pObjList
  70. );
  71. BAIL_ON_FAILURE(hr);
  72. */
  73. penumvariant->_Credentials = Credentials;
  74. *ppenumvariant = penumvariant;
  75. hr = BuildNDSPathFromADsPath(
  76. ADsPath,
  77. &pszNDSPath
  78. );
  79. BAIL_ON_FAILURE(hr);
  80. dwStatus = ADsNwNdsOpenObject(
  81. pszNDSPath,
  82. Credentials,
  83. &penumvariant->_hObject,
  84. szObjectFullName,
  85. szObjectClassName,
  86. &dwModificationTime,
  87. &dwNumberOfEntries
  88. );
  89. if (dwStatus) {
  90. hr = HRESULT_FROM_WIN32(GetLastError());
  91. BAIL_ON_FAILURE(hr);
  92. }
  93. if (pszNDSPath) {
  94. FreeADsStr(pszNDSPath);
  95. }
  96. RRETURN(hr);
  97. error:
  98. delete penumvariant;
  99. *ppenumvariant = NULL;
  100. if (pszNDSPath) {
  101. FreeADsStr(pszNDSPath);
  102. }
  103. RRETURN_EXP_IF_ERR(hr);
  104. }
  105. CNDSTreeEnum::CNDSTreeEnum():
  106. _ADsPath(NULL)
  107. {
  108. _pObjList = NULL;
  109. _dwObjectReturned = 0;
  110. _dwObjectCurrentEntry = 0;
  111. _dwObjectTotal = 0;
  112. _hObject = NULL;
  113. _hOperationData = NULL;
  114. _lpObjects = NULL;
  115. _pNdsFilterList = NULL;
  116. _fSchemaReturned = NULL;
  117. _bNoMore = FALSE;
  118. }
  119. CNDSTreeEnum::~CNDSTreeEnum()
  120. {
  121. if (_pNdsFilterList) {
  122. FreeFilterList((LPBYTE)_pNdsFilterList);
  123. }
  124. }
  125. HRESULT
  126. CNDSTreeEnum::EnumGenericObjects(
  127. ULONG cElements,
  128. VARIANT FAR* pvar,
  129. ULONG FAR* pcElementFetched
  130. )
  131. {
  132. HRESULT hr = S_OK;
  133. IDispatch *pDispatch = NULL;
  134. DWORD i = 0;
  135. while (i < cElements) {
  136. hr = GetGenObject(&pDispatch);
  137. if (hr == S_FALSE) {
  138. break;
  139. }
  140. VariantInit(&pvar[i]);
  141. pvar[i].vt = VT_DISPATCH;
  142. pvar[i].pdispVal = pDispatch;
  143. (*pcElementFetched)++;
  144. i++;
  145. }
  146. return(hr);
  147. }
  148. HRESULT
  149. CNDSTreeEnum::GetGenObject(
  150. IDispatch ** ppDispatch
  151. )
  152. {
  153. HRESULT hr = S_OK;
  154. DWORD dwStatus = 0L;
  155. LPNDS_OBJECT_INFO lpCurrentObject = NULL;
  156. IADs * pADs = NULL;
  157. *ppDispatch = NULL;
  158. if (!_hOperationData || (_dwObjectCurrentEntry == _dwObjectReturned)) {
  159. if (_hOperationData) {
  160. dwStatus = NwNdsFreeBuffer(_hOperationData);
  161. _hOperationData = NULL;
  162. _lpObjects = NULL;
  163. }
  164. _dwObjectCurrentEntry = 0;
  165. _dwObjectReturned = 0;
  166. //
  167. // Insert NDS code in here
  168. //
  169. if (_bNoMore) {
  170. RRETURN(S_FALSE);
  171. }
  172. dwStatus = NwNdsListSubObjects(
  173. _hObject,
  174. MAX_CACHE_SIZE,
  175. &_dwObjectReturned,
  176. _pNdsFilterList,
  177. &_hOperationData
  178. );
  179. if ((dwStatus != ERROR_SUCCESS) && (dwStatus != WN_NO_MORE_ENTRIES)) {
  180. hr = HRESULT_FROM_WIN32(GetLastError());
  181. BAIL_ON_FAILURE(hr);
  182. }
  183. if (dwStatus == WN_NO_MORE_ENTRIES) {
  184. _bNoMore = TRUE;
  185. }
  186. dwStatus = NwNdsGetObjectListFromBuffer(
  187. _hOperationData,
  188. &_dwObjectReturned,
  189. NULL,
  190. &_lpObjects
  191. );
  192. if (dwStatus != ERROR_SUCCESS) {
  193. hr = HRESULT_FROM_WIN32(GetLastError());
  194. }
  195. BAIL_ON_FAILURE(hr);
  196. }
  197. //
  198. // Now send back the current object
  199. //
  200. lpCurrentObject = _lpObjects + _dwObjectCurrentEntry;
  201. hr = CNDSGenObject::CreateGenericObject(
  202. _ADsPath,
  203. lpCurrentObject->szObjectName,
  204. lpCurrentObject->szObjectClass,
  205. _Credentials,
  206. ADS_OBJECT_BOUND,
  207. IID_IADs,
  208. (void **)&pADs
  209. );
  210. BAIL_ON_FAILURE(hr);
  211. //
  212. // InstantiateDerivedObject should addref this pointer for us.
  213. //
  214. hr = InstantiateDerivedObject(
  215. pADs,
  216. _Credentials,
  217. IID_IDispatch,
  218. (void **)ppDispatch
  219. );
  220. if (FAILED(hr)) {
  221. hr = pADs->QueryInterface(
  222. IID_IDispatch,
  223. (void **)ppDispatch
  224. );
  225. BAIL_ON_FAILURE(hr);
  226. }
  227. _dwObjectCurrentEntry++;
  228. error:
  229. //
  230. // GetGenObject returns only S_FALSE
  231. //
  232. if (FAILED(hr)) {
  233. hr = S_FALSE;
  234. }
  235. //
  236. // Free the intermediate pADs pointer.
  237. //
  238. if (pADs) {
  239. pADs->Release();
  240. }
  241. RRETURN_EXP_IF_ERR(hr);
  242. }
  243. //+---------------------------------------------------------------------------
  244. //
  245. // Function: CNDSTreeEnum::Next
  246. //
  247. // Synopsis: Returns cElements number of requested NetOle objects in the
  248. // array supplied in pvar.
  249. //
  250. // Arguments: [cElements] -- The number of elements requested by client
  251. // [pvar] -- ptr to array of VARIANTs to for return objects
  252. // [pcElementFetched] -- if non-NULL, then number of elements
  253. // -- actually returned is placed here
  254. //
  255. // Returns: HRESULT -- S_OK if number of elements requested are returned
  256. // -- S_FALSE if number of elements is < requested
  257. //
  258. // Modifies:
  259. //
  260. // History: 11-3-95 krishnag Created.
  261. //
  262. //----------------------------------------------------------------------------
  263. STDMETHODIMP
  264. CNDSTreeEnum::Next(
  265. ULONG cElements,
  266. VARIANT FAR* pvar,
  267. ULONG FAR* pcElementFetched
  268. )
  269. {
  270. ULONG cElementFetched = 0;
  271. HRESULT hr = S_OK;
  272. hr = EnumGenericObjects(
  273. cElements,
  274. pvar,
  275. &cElementFetched
  276. );
  277. if (pcElementFetched) {
  278. *pcElementFetched = cElementFetched;
  279. }
  280. RRETURN_EXP_IF_ERR(hr);
  281. }
  282. HRESULT
  283. CNDSTreeEnum::EnumSchema(
  284. ULONG cElements,
  285. VARIANT FAR* pvar,
  286. ULONG FAR* pcElementFetched
  287. )
  288. {
  289. HRESULT hr = S_OK;
  290. IDispatch *pDispatch = NULL;
  291. if ( _fSchemaReturned )
  292. RRETURN(S_FALSE);
  293. if ( cElements > 0 )
  294. {
  295. hr = CNDSSchema::CreateSchema(
  296. _ADsPath,
  297. TEXT("Schema"),
  298. _Credentials,
  299. ADS_OBJECT_BOUND,
  300. IID_IDispatch,
  301. (void **)&pDispatch
  302. );
  303. if ( hr == S_OK )
  304. {
  305. VariantInit(&pvar[0]);
  306. pvar[0].vt = VT_DISPATCH;
  307. pvar[0].pdispVal = pDispatch;
  308. (*pcElementFetched)++;
  309. _fSchemaReturned = TRUE;
  310. }
  311. }
  312. RRETURN(hr);
  313. }