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.

437 lines
9.5 KiB

  1. //---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1996
  5. //
  6. // File: cgroups.cxx
  7. //
  8. // Contents: Group object
  9. //
  10. // History: July-18-1996 yihsins Migrated.
  11. //
  12. //----------------------------------------------------------------------------
  13. #include "ldap.hxx"
  14. #pragma hdrstop
  15. //
  16. // Class CLDAPGroupCollection
  17. //
  18. DEFINE_IDispatch_Implementation(CLDAPGroupCollection)
  19. //----------------------------------------------------------------------------
  20. //
  21. // Function:
  22. //
  23. // Synopsis:
  24. //
  25. //----------------------------------------------------------------------------
  26. CLDAPGroupCollection::CLDAPGroupCollection():
  27. _Parent(NULL),
  28. _ADsPath(NULL),
  29. _GroupName(NULL),
  30. _pDispMgr(NULL),
  31. _pIDirObj(NULL),
  32. _fRangeRetrieval(FALSE)
  33. {
  34. VariantInit(&_vMembers);
  35. VariantInit(&_vFilter);
  36. ENLIST_TRACKING(CLDAPGroupCollection);
  37. }
  38. //----------------------------------------------------------------------------
  39. //
  40. // Function:
  41. //
  42. // Synopsis:
  43. //
  44. //----------------------------------------------------------------------------
  45. HRESULT
  46. CLDAPGroupCollection::CreateGroupCollection(
  47. BSTR Parent,
  48. BSTR ADsPath,
  49. BSTR GroupName,
  50. VARIANT *pvMembers,
  51. CCredentials& Credentials,
  52. IADs *pIADs,
  53. REFIID riid,
  54. BOOL fRangeRetrieval,
  55. void **ppvObj
  56. )
  57. {
  58. CLDAPGroupCollection FAR * pGroup = NULL;
  59. HRESULT hr = S_OK;
  60. hr = AllocateGroupCollectionObject(
  61. Credentials,
  62. &pGroup
  63. );
  64. BAIL_ON_FAILURE(hr);
  65. pGroup->_fRangeRetrieval = fRangeRetrieval;
  66. hr = ADsAllocString( Parent , &pGroup->_Parent);
  67. BAIL_ON_FAILURE(hr);
  68. hr = ADsAllocString(GroupName, &pGroup->_GroupName);
  69. BAIL_ON_FAILURE(hr);
  70. hr = ADsAllocString(ADsPath, &pGroup->_ADsPath);
  71. BAIL_ON_FAILURE(hr);
  72. hr = VariantCopy( &(pGroup->_vMembers), pvMembers );
  73. BAIL_ON_FAILURE(hr);
  74. hr = pIADs->QueryInterface(
  75. IID_IDirectoryObject,
  76. (void **)&(pGroup->_pIDirObj)
  77. );
  78. BAIL_ON_FAILURE(hr);
  79. hr = pGroup->QueryInterface(riid, ppvObj);
  80. BAIL_ON_FAILURE(hr);
  81. pGroup->Release();
  82. RRETURN(hr);
  83. error:
  84. if (pGroup->_pIDirObj) {
  85. pGroup->_pIDirObj->Release();
  86. pGroup->_pIDirObj = NULL;
  87. }
  88. *ppvObj = NULL;
  89. delete pGroup;
  90. RRETURN_EXP_IF_ERR(hr);
  91. }
  92. //----------------------------------------------------------------------------
  93. //
  94. // Function:
  95. //
  96. // Synopsis:
  97. //
  98. //----------------------------------------------------------------------------
  99. CLDAPGroupCollection::~CLDAPGroupCollection( )
  100. {
  101. VariantClear( &_vMembers );
  102. VariantClear( &_vFilter );
  103. if (_ADsPath) {
  104. ADsFreeString(_ADsPath);
  105. }
  106. if (_GroupName) {
  107. ADsFreeString(_GroupName);
  108. }
  109. if (_Parent) {
  110. ADsFreeString(_Parent);
  111. }
  112. if (_pIDirObj) {
  113. _pIDirObj->Release();
  114. }
  115. delete _pDispMgr;
  116. }
  117. //----------------------------------------------------------------------------
  118. //
  119. // Function:
  120. //
  121. // Synopsis:
  122. //
  123. //----------------------------------------------------------------------------
  124. STDMETHODIMP
  125. CLDAPGroupCollection::QueryInterface(
  126. REFIID iid,
  127. LPVOID FAR* ppv
  128. )
  129. {
  130. if (ppv == NULL) {
  131. RRETURN(E_POINTER);
  132. }
  133. if (IsEqualIID(iid, IID_IUnknown))
  134. {
  135. *ppv = (IADsMembers FAR *) this;
  136. }
  137. else if (IsEqualIID(iid, IID_IADsMembers))
  138. {
  139. *ppv = (IADsMembers FAR *) this;
  140. }
  141. else if (IsEqualIID(iid, IID_IDispatch))
  142. {
  143. *ppv = (IADsMembers FAR *) this;
  144. }
  145. else if (IsEqualIID(iid, IID_ISupportErrorInfo))
  146. {
  147. *ppv = (ISupportErrorInfo FAR *) this;
  148. }
  149. else
  150. {
  151. *ppv = NULL;
  152. return E_NOINTERFACE;
  153. }
  154. AddRef();
  155. return NOERROR;
  156. }
  157. //----------------------------------------------------------------------------
  158. //
  159. // Function:
  160. //
  161. // Synopsis:
  162. //
  163. //----------------------------------------------------------------------------
  164. STDMETHODIMP
  165. CLDAPGroupCollection::InterfaceSupportsErrorInfo(
  166. THIS_ REFIID riid
  167. )
  168. {
  169. if (IsEqualIID(riid, IID_IADsMembers)) {
  170. RRETURN(S_OK);
  171. } else {
  172. RRETURN(S_FALSE);
  173. }
  174. }
  175. //----------------------------------------------------------------------------
  176. //
  177. // Function:
  178. //
  179. // Synopsis:
  180. //
  181. //----------------------------------------------------------------------------
  182. STDMETHODIMP
  183. CLDAPGroupCollection::get_Count(
  184. long FAR* retval
  185. )
  186. {
  187. HRESULT hr = S_OK;
  188. long lLBound = 0;
  189. long lUBound = 0;
  190. long lCount = 0;
  191. unsigned long ulFetch = 0;
  192. IEnumVARIANT *pEnum = NULL;
  193. IUnknown *pUnk = NULL;
  194. VARIANT vVar;
  195. //
  196. // If we used range retrieval we need to actually enumerate
  197. // all the entries before we can get the correct count.
  198. //
  199. if (!_fRangeRetrieval) {
  200. if (V_VT(&_vMembers) == VT_BSTR) {
  201. *retval = 1;
  202. }else if (V_VT(&_vMembers) == (VT_ARRAY|VT_VARIANT)){
  203. hr = SafeArrayGetLBound(V_ARRAY(&_vMembers),
  204. 1,
  205. (long FAR *)&lLBound
  206. );
  207. BAIL_ON_FAILURE(hr);
  208. hr = SafeArrayGetUBound(V_ARRAY(&_vMembers),
  209. 1,
  210. (long FAR *)&lUBound
  211. );
  212. BAIL_ON_FAILURE(hr);
  213. *retval = lUBound - lLBound + 1;
  214. }else {
  215. hr = E_INVALIDARG;
  216. BAIL_ON_FAILURE(hr);
  217. }
  218. }
  219. else {
  220. //
  221. // Need to go through all the results.
  222. //
  223. VariantInit(&vVar);
  224. hr = get__NewEnum(&pUnk);
  225. BAIL_ON_FAILURE(hr);
  226. hr = pUnk->QueryInterface(IID_IEnumVARIANT, (void **) &pEnum);
  227. BAIL_ON_FAILURE(hr);
  228. while(hr == S_OK) {
  229. hr = pEnum->Next(1, &vVar, &ulFetch);
  230. VariantClear(&vVar);
  231. BAIL_ON_FAILURE(hr);
  232. lCount += ulFetch;
  233. }
  234. *retval = lCount;
  235. }
  236. error:
  237. if (pEnum) {
  238. pEnum->Release();
  239. }
  240. if (pUnk) {
  241. pUnk->Release();
  242. }
  243. if (hr == S_FALSE) {
  244. hr = S_OK;
  245. }
  246. RRETURN_EXP_IF_ERR(hr);
  247. }
  248. //----------------------------------------------------------------------------
  249. //
  250. // Function:
  251. //
  252. // Synopsis:
  253. //
  254. //----------------------------------------------------------------------------
  255. STDMETHODIMP
  256. CLDAPGroupCollection::get_Filter(
  257. THIS_ VARIANT FAR* pVar
  258. )
  259. {
  260. HRESULT hr;
  261. VariantInit(pVar);
  262. hr = VariantCopy(pVar, &_vFilter);
  263. RRETURN_EXP_IF_ERR(hr);
  264. }
  265. //----------------------------------------------------------------------------
  266. //
  267. // Function:
  268. //
  269. // Synopsis:
  270. //
  271. //----------------------------------------------------------------------------
  272. STDMETHODIMP
  273. CLDAPGroupCollection::put_Filter(
  274. THIS_ VARIANT Var
  275. )
  276. {
  277. HRESULT hr;
  278. hr = VariantCopy(&_vFilter, &Var);
  279. RRETURN_EXP_IF_ERR(hr);
  280. }
  281. //----------------------------------------------------------------------------
  282. //
  283. // Function:
  284. //
  285. // Synopsis:
  286. //
  287. //----------------------------------------------------------------------------
  288. STDMETHODIMP
  289. CLDAPGroupCollection::get__NewEnum(
  290. THIS_ IUnknown * FAR* retval
  291. )
  292. {
  293. HRESULT hr;
  294. IUnknown FAR* punkEnum=NULL;
  295. IEnumVARIANT * penum = NULL;
  296. *retval = NULL;
  297. hr = CLDAPGroupCollectionEnum::Create(
  298. (CLDAPGroupCollectionEnum **)&penum,
  299. _Parent,
  300. _ADsPath,
  301. _GroupName,
  302. _vMembers,
  303. _vFilter,
  304. _Credentials,
  305. _pIDirObj,
  306. _fRangeRetrieval
  307. );
  308. BAIL_ON_FAILURE(hr);
  309. hr = penum->QueryInterface(
  310. IID_IUnknown,
  311. (VOID FAR* FAR*)retval
  312. );
  313. BAIL_ON_FAILURE(hr);
  314. if (penum) {
  315. penum->Release();
  316. }
  317. RRETURN(NOERROR);
  318. error:
  319. if (penum) {
  320. delete penum;
  321. }
  322. RRETURN_EXP_IF_ERR(hr);
  323. }
  324. //----------------------------------------------------------------------------
  325. //
  326. // Function:
  327. //
  328. // Synopsis:
  329. //
  330. //----------------------------------------------------------------------------
  331. HRESULT
  332. CLDAPGroupCollection::AllocateGroupCollectionObject(
  333. CCredentials& Credentials,
  334. CLDAPGroupCollection ** ppGroup
  335. )
  336. {
  337. CLDAPGroupCollection FAR * pGroup = NULL;
  338. CDispatchMgr FAR * pDispMgr = NULL;
  339. HRESULT hr = S_OK;
  340. pGroup = new CLDAPGroupCollection();
  341. if (pGroup == NULL) {
  342. hr = E_OUTOFMEMORY;
  343. }
  344. BAIL_ON_FAILURE(hr);
  345. pDispMgr = new CDispatchMgr;
  346. if (pDispMgr == NULL) {
  347. hr = E_OUTOFMEMORY;
  348. }
  349. BAIL_ON_FAILURE(hr);
  350. hr = LoadTypeInfoEntry(
  351. pDispMgr,
  352. LIBID_ADs,
  353. IID_IADsMembers,
  354. (IADsMembers *)pGroup,
  355. DISPID_NEWENUM
  356. );
  357. BAIL_ON_FAILURE(hr);
  358. pGroup->_Credentials = Credentials;
  359. pGroup->_pDispMgr = pDispMgr;
  360. *ppGroup = pGroup;
  361. RRETURN(hr);
  362. error:
  363. if (pGroup) {
  364. delete pGroup;
  365. }
  366. if (pDispMgr) {
  367. delete pDispMgr;
  368. }
  369. RRETURN_EXP_IF_ERR(hr);
  370. }
  371.