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.

393 lines
8.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. IID_IADsMembers,
  66. (void **)ppMembers
  67. );
  68. RRETURN_EXP_IF_ERR(hr);
  69. }
  70. //----------------------------------------------------------------------------
  71. //
  72. // Function: CNWCOMPATGroup::IsMember
  73. //
  74. // Synopsis:
  75. //
  76. //----------------------------------------------------------------------------
  77. STDMETHODIMP
  78. CNWCOMPATGroup::IsMember(
  79. THIS_ BSTR bstrMember,
  80. VARIANT_BOOL FAR* bMember
  81. )
  82. {
  83. IADsMembers FAR * pMembers = NULL;
  84. IUnknown FAR * pUnknown = NULL;
  85. IEnumVARIANT FAR * pEnumVar = NULL;
  86. DWORD i = 0;
  87. HRESULT hr = S_OK;
  88. VARIANT_BOOL fMember = FALSE;
  89. VARIANT VariantArray[10];
  90. BOOL fContinue = TRUE;
  91. ULONG cElementFetched = 0;
  92. hr = Members(
  93. &pMembers
  94. );
  95. BAIL_ON_FAILURE(hr);
  96. hr = pMembers->get__NewEnum(
  97. &pUnknown
  98. );
  99. BAIL_ON_FAILURE(hr);
  100. hr = pUnknown->QueryInterface(
  101. IID_IEnumVARIANT,
  102. (void **)&pEnumVar
  103. );
  104. BAIL_ON_FAILURE(hr);
  105. while (fContinue) {
  106. IADs *pObject ;
  107. hr = pEnumVar->Next(
  108. 10,
  109. VariantArray,
  110. &cElementFetched
  111. );
  112. if (hr == S_FALSE) {
  113. fContinue = FALSE;
  114. //
  115. // Reset hr to S_OK, we want to return success
  116. //
  117. hr = S_OK;
  118. }
  119. fMember = (VARIANT_BOOL)VerifyIfMember(
  120. bstrMember,
  121. VariantArray,
  122. cElementFetched
  123. );
  124. if (fMember) {
  125. fContinue = FALSE;
  126. }
  127. for (i = 0; i < cElementFetched; i++ ) {
  128. IDispatch *pDispatch = NULL;
  129. pDispatch = VariantArray[i].pdispVal;
  130. pDispatch->Release();
  131. }
  132. memset(VariantArray, 0, sizeof(VARIANT)*10);
  133. }
  134. error:
  135. *bMember = fMember? VARIANT_TRUE : VARIANT_FALSE;
  136. if (pEnumVar) {
  137. pEnumVar->Release();
  138. }
  139. if (pUnknown) {
  140. pUnknown->Release();
  141. }
  142. if (pMembers) {
  143. pMembers->Release();
  144. }
  145. RRETURN_EXP_IF_ERR(hr);
  146. }
  147. BOOL
  148. VerifyIfMember(
  149. BSTR bstrMember,
  150. VARIANT * VariantArray,
  151. ULONG cElementFetched
  152. )
  153. {
  154. DWORD i = 0;
  155. HRESULT hr = S_OK;
  156. IADs FAR * pObject = NULL;
  157. IDispatch FAR * pDispatch = NULL;
  158. for (i = 0; i < cElementFetched; i++ ) {
  159. IDispatch *pDispatch = NULL;
  160. BSTR bstrName = NULL;
  161. pDispatch = VariantArray[i].pdispVal;
  162. hr = pDispatch->QueryInterface(
  163. IID_IADs,
  164. (VOID **) &pObject
  165. );
  166. BAIL_ON_FAILURE(hr);
  167. hr = pObject->get_ADsPath(&bstrName);
  168. BAIL_ON_FAILURE(hr);
  169. if (!_wcsicmp(bstrName, bstrMember)) {
  170. SysFreeString(bstrName);
  171. bstrName = NULL;
  172. pObject->Release();
  173. return(TRUE);
  174. }
  175. SysFreeString(bstrName);
  176. bstrName = NULL;
  177. pObject->Release();
  178. }
  179. error:
  180. return(FALSE);
  181. }
  182. //----------------------------------------------------------------------------
  183. //
  184. // Function: CNWCOMPATGroup::Add
  185. //
  186. // Synopsis:
  187. //
  188. //----------------------------------------------------------------------------
  189. STDMETHODIMP
  190. CNWCOMPATGroup::Add(
  191. THIS_ BSTR bstrNewItem
  192. )
  193. {
  194. HRESULT hr = S_OK;
  195. HRESULT hrTemp = S_OK;
  196. NWCONN_HANDLE hConn = NULL;
  197. POBJECTINFO pObjectInfo = NULL;
  198. //
  199. // Fill in pObjectInfo with appropriate data.
  200. //
  201. hr = BuildObjectInfo(
  202. bstrNewItem,
  203. &pObjectInfo
  204. );
  205. BAIL_ON_FAILURE(hr);
  206. //
  207. // Validate input name is a user.
  208. //
  209. if (pObjectInfo->NumComponents != 2) {
  210. hr = E_ADS_BAD_PATHNAME;
  211. BAIL_ON_FAILURE(hr);
  212. }
  213. //
  214. // Make sure that the user that we're attempting to
  215. // add resides on the server of this group
  216. //
  217. if (_wcsicmp(pObjectInfo->ComponentArray[0], _ServerName)) {
  218. hr = E_ADS_BAD_PARAMETER;
  219. BAIL_ON_FAILURE(hr);
  220. }
  221. //
  222. // Obtain a handle to the bindery that bstrNewItem resides on.
  223. //
  224. hr = NWApiGetBinderyHandle(
  225. &hConn,
  226. pObjectInfo->ComponentArray[0]
  227. );
  228. BAIL_ON_FAILURE(hr);
  229. //
  230. // Add the member to the group.
  231. //
  232. hr = NWApiAddGroupMember(
  233. hConn,
  234. _Name,
  235. pObjectInfo->ComponentArray[1]
  236. );
  237. BAIL_ON_FAILURE(hr);
  238. error:
  239. if (hConn) {
  240. hrTemp = NWApiReleaseBinderyHandle(hConn);
  241. }
  242. if (pObjectInfo) {
  243. FreeObjectInfo(pObjectInfo);
  244. }
  245. RRETURN_EXP_IF_ERR(hr);
  246. }
  247. //----------------------------------------------------------------------------
  248. //
  249. // Function: CNWCOMPATGroup::Remove
  250. //
  251. // Synopsis:
  252. //
  253. //----------------------------------------------------------------------------
  254. STDMETHODIMP
  255. CNWCOMPATGroup::Remove(
  256. THIS_ BSTR bstrItemToBeRemoved
  257. )
  258. {
  259. HRESULT hr = S_OK;
  260. HRESULT hrTemp = S_OK;
  261. NWCONN_HANDLE hConn = NULL;
  262. POBJECTINFO pObjectInfo = NULL;
  263. //
  264. // Fill in pObjectInfo with appropriate data.
  265. //
  266. hr = BuildObjectInfo(
  267. bstrItemToBeRemoved,
  268. &pObjectInfo
  269. );
  270. BAIL_ON_FAILURE(hr);
  271. //
  272. // Validate input name is a user.
  273. //
  274. if (pObjectInfo->NumComponents != 2) {
  275. hr = E_ADS_BAD_PATHNAME;
  276. BAIL_ON_FAILURE(hr);
  277. }
  278. //
  279. // Make sure that the user that we're attempting to
  280. // delete resides on the server of this group
  281. //
  282. if (_wcsicmp(pObjectInfo->ComponentArray[0], _ServerName)) {
  283. hr = E_ADS_BAD_PARAMETER;
  284. BAIL_ON_FAILURE(hr);
  285. }
  286. //
  287. // Obtain a handle to the bindery that bstrNewItem resides on.
  288. //
  289. hr = NWApiGetBinderyHandle(
  290. &hConn,
  291. pObjectInfo->ComponentArray[0]
  292. );
  293. BAIL_ON_FAILURE(hr);
  294. //
  295. // Remove the member from the group.
  296. //
  297. hr = NWApiRemoveGroupMember(
  298. hConn,
  299. _Name,
  300. pObjectInfo->ComponentArray[1]
  301. );
  302. BAIL_ON_FAILURE(hr);
  303. error:
  304. if (hConn) {
  305. hrTemp = NWApiReleaseBinderyHandle(hConn);
  306. }
  307. if (pObjectInfo) {
  308. FreeObjectInfo(pObjectInfo);
  309. }
  310. RRETURN_EXP_IF_ERR(hr);
  311. }