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.

364 lines
7.4 KiB

  1. //---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1995
  5. //
  6. // File: cggi.cxx
  7. //
  8. // Contents: This file contains the Group Object's
  9. // GeneralInformation Functional Set.
  10. //
  11. // History: Jan-29-1996 t-ptam(PatrickT) Created.
  12. //
  13. //----------------------------------------------------------------------------
  14. #include "NWCOMPAT.hxx"
  15. #pragma hdrstop
  16. BOOL
  17. VerifyIfMember(
  18. BSTR bstrMember,
  19. VARIANT * VariantArray,
  20. ULONG cElementFetched
  21. );
  22. //
  23. // Class CNWCOMPATGroup
  24. //
  25. //----------------------------------------------------------------------------
  26. //
  27. // Function: CNWCOMPATGroup::get_Description
  28. //
  29. // Synopsis:
  30. //
  31. //----------------------------------------------------------------------------
  32. STDMETHODIMP CNWCOMPATGroup::get_Description(THIS_ BSTR FAR* retval)
  33. {
  34. GET_PROPERTY_BSTR((IADsGroup *)this, Description);
  35. }
  36. //----------------------------------------------------------------------------
  37. //
  38. // Function: CNWCOMPATGroup::put_Description
  39. //
  40. // Synopsis:
  41. //
  42. //----------------------------------------------------------------------------
  43. STDMETHODIMP CNWCOMPATGroup::put_Description(THIS_ BSTR bstrDescription)
  44. {
  45. PUT_PROPERTY_BSTR((IADsGroup *)this, Description);
  46. }
  47. //----------------------------------------------------------------------------
  48. //
  49. // Function: CNWCOMPATGroup::Members
  50. //
  51. // Synopsis:
  52. //
  53. //----------------------------------------------------------------------------
  54. STDMETHODIMP
  55. CNWCOMPATGroup::Members(
  56. THIS_ IADsMembers FAR* FAR* ppMembers
  57. )
  58. {
  59. HRESULT hr;
  60. hr = CNWCOMPATGroupCollection::CreateGroupCollection(
  61. _Parent,
  62. _ParentType,
  63. _ServerName,
  64. _Name,
  65. _Credentials,
  66. IID_IADsMembers,
  67. (void **)ppMembers
  68. );
  69. NW_RRETURN_EXP_IF_ERR(hr);
  70. }
  71. //----------------------------------------------------------------------------
  72. //
  73. // Function: CNWCOMPATGroup::IsMember
  74. //
  75. // Synopsis:
  76. //
  77. //----------------------------------------------------------------------------
  78. STDMETHODIMP
  79. CNWCOMPATGroup::IsMember(
  80. THIS_ BSTR bstrMember,
  81. VARIANT_BOOL FAR* bMember
  82. )
  83. {
  84. IADsMembers FAR * pMembers = NULL;
  85. IUnknown FAR * pUnknown = NULL;
  86. IEnumVARIANT FAR * pEnumVar = NULL;
  87. DWORD i = 0;
  88. HRESULT hr = S_OK;
  89. VARIANT_BOOL fMember = FALSE;
  90. VARIANT VariantArray[10];
  91. BOOL fContinue = TRUE;
  92. ULONG cElementFetched = 0;
  93. hr = Members(
  94. &pMembers
  95. );
  96. BAIL_ON_FAILURE(hr);
  97. hr = pMembers->get__NewEnum(
  98. &pUnknown
  99. );
  100. BAIL_ON_FAILURE(hr);
  101. hr = pUnknown->QueryInterface(
  102. IID_IEnumVARIANT,
  103. (void **)&pEnumVar
  104. );
  105. BAIL_ON_FAILURE(hr);
  106. while (fContinue) {
  107. IADs *pObject ;
  108. hr = pEnumVar->Next(
  109. 10,
  110. VariantArray,
  111. &cElementFetched
  112. );
  113. if (hr == S_FALSE) {
  114. fContinue = FALSE;
  115. //
  116. // Reset hr to S_OK, we want to return success
  117. //
  118. hr = S_OK;
  119. }
  120. fMember = (VARIANT_BOOL)VerifyIfMember(
  121. bstrMember,
  122. VariantArray,
  123. cElementFetched
  124. );
  125. if (fMember) {
  126. fContinue = FALSE;
  127. }
  128. for (i = 0; i < cElementFetched; i++ ) {
  129. IDispatch *pDispatch = NULL;
  130. pDispatch = VariantArray[i].pdispVal;
  131. pDispatch->Release();
  132. }
  133. memset(VariantArray, 0, sizeof(VARIANT)*10);
  134. }
  135. error:
  136. *bMember = fMember? VARIANT_TRUE : VARIANT_FALSE;
  137. if (pEnumVar) {
  138. pEnumVar->Release();
  139. }
  140. if (pUnknown) {
  141. pUnknown->Release();
  142. }
  143. if (pMembers) {
  144. pMembers->Release();
  145. }
  146. NW_RRETURN_EXP_IF_ERR(hr);
  147. }
  148. BOOL
  149. VerifyIfMember(
  150. BSTR bstrMember,
  151. VARIANT * VariantArray,
  152. ULONG cElementFetched
  153. )
  154. {
  155. DWORD i = 0;
  156. HRESULT hr = S_OK;
  157. IADs FAR * pObject = NULL;
  158. IDispatch FAR * pDispatch = NULL;
  159. for (i = 0; i < cElementFetched; i++ ) {
  160. IDispatch *pDispatch = NULL;
  161. BSTR bstrName = NULL;
  162. pDispatch = VariantArray[i].pdispVal;
  163. hr = pDispatch->QueryInterface(
  164. IID_IADs,
  165. (VOID **) &pObject
  166. );
  167. BAIL_ON_FAILURE(hr);
  168. hr = pObject->get_ADsPath(&bstrName);
  169. BAIL_ON_FAILURE(hr);
  170. if (!_wcsicmp(bstrName, bstrMember)) {
  171. SysFreeString(bstrName);
  172. bstrName = NULL;
  173. pObject->Release();
  174. return(TRUE);
  175. }
  176. SysFreeString(bstrName);
  177. bstrName = NULL;
  178. pObject->Release();
  179. }
  180. error:
  181. return(FALSE);
  182. }
  183. //----------------------------------------------------------------------------
  184. //
  185. // Function: CNWCOMPATGroup::Add
  186. //
  187. // Synopsis:
  188. //
  189. //----------------------------------------------------------------------------
  190. STDMETHODIMP
  191. CNWCOMPATGroup::Add(
  192. THIS_ BSTR bstrNewItem
  193. )
  194. {
  195. HRESULT hr = S_OK;
  196. POBJECTINFO pObjectInfo = NULL;
  197. //
  198. // Fill in pObjectInfo with appropriate data.
  199. //
  200. hr = BuildObjectInfo(
  201. bstrNewItem,
  202. &pObjectInfo
  203. );
  204. BAIL_ON_FAILURE(hr);
  205. //
  206. // Validate input name is a user.
  207. //
  208. if (pObjectInfo->NumComponents != 2) {
  209. hr = E_ADS_BAD_PATHNAME;
  210. BAIL_ON_FAILURE(hr);
  211. }
  212. //
  213. // Make sure that the user that we're attempting to
  214. // add resides on the server of this group
  215. //
  216. if (_wcsicmp(pObjectInfo->ComponentArray[0], _ServerName)) {
  217. hr = E_ADS_BAD_PARAMETER;
  218. BAIL_ON_FAILURE(hr);
  219. }
  220. //
  221. // Add the member to the group.
  222. //
  223. hr = NWApiAddGroupMember(
  224. _hConn,
  225. _Name,
  226. pObjectInfo->ComponentArray[1]
  227. );
  228. BAIL_ON_FAILURE(hr);
  229. error:
  230. if (pObjectInfo) {
  231. FreeObjectInfo(pObjectInfo);
  232. }
  233. NW_RRETURN_EXP_IF_ERR(hr);
  234. }
  235. //----------------------------------------------------------------------------
  236. //
  237. // Function: CNWCOMPATGroup::Remove
  238. //
  239. // Synopsis:
  240. //
  241. //----------------------------------------------------------------------------
  242. STDMETHODIMP
  243. CNWCOMPATGroup::Remove(
  244. THIS_ BSTR bstrItemToBeRemoved
  245. )
  246. {
  247. HRESULT hr = S_OK;
  248. POBJECTINFO pObjectInfo = NULL;
  249. //
  250. // Fill in pObjectInfo with appropriate data.
  251. //
  252. hr = BuildObjectInfo(
  253. bstrItemToBeRemoved,
  254. &pObjectInfo
  255. );
  256. BAIL_ON_FAILURE(hr);
  257. //
  258. // Validate input name is a user.
  259. //
  260. if (pObjectInfo->NumComponents != 2) {
  261. hr = E_ADS_BAD_PATHNAME;
  262. BAIL_ON_FAILURE(hr);
  263. }
  264. //
  265. // Make sure that the user that we're attempting to
  266. // delete resides on the server of this group
  267. //
  268. if (_wcsicmp(pObjectInfo->ComponentArray[0], _ServerName)) {
  269. hr = E_ADS_BAD_PARAMETER;
  270. BAIL_ON_FAILURE(hr);
  271. }
  272. //
  273. // Remove the member from the group.
  274. //
  275. hr = NWApiRemoveGroupMember(
  276. _hConn,
  277. _Name,
  278. pObjectInfo->ComponentArray[1]
  279. );
  280. BAIL_ON_FAILURE(hr);
  281. error:
  282. if (pObjectInfo) {
  283. FreeObjectInfo(pObjectInfo);
  284. }
  285. NW_RRETURN_EXP_IF_ERR(hr);
  286. }