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.

290 lines
5.8 KiB

  1. //---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1995
  5. //
  6. // File: cgroup.cxx
  7. //
  8. // Contents: Group object
  9. //
  10. // History: 11-1-95 krishnag Created.
  11. //
  12. //----------------------------------------------------------------------------
  13. #include "nds.hxx"
  14. #pragma hdrstop
  15. struct _propmap
  16. {
  17. LPTSTR pszADsProp;
  18. LPTSTR pszNDSProp;
  19. } aGroupPropMapping[] =
  20. {
  21. { TEXT("Description"), TEXT("Description") },
  22. };
  23. // Class CNDSGroup
  24. DEFINE_IDispatch_Implementation(CNDSGroup)
  25. DEFINE_CONTAINED_IADs_Implementation(CNDSGroup)
  26. DEFINE_CONTAINED_IDirectoryObject_Implementation(CNDSGroup)
  27. DEFINE_CONTAINED_IDirectorySearch_Implementation(CNDSGroup)
  28. DEFINE_CONTAINED_IDirectorySchemaMgmt_Implementation(CNDSGroup)
  29. DEFINE_CONTAINED_IADsPropertyList_Implementation(CNDSGroup)
  30. DEFINE_CONTAINED_IADsPutGet_Implementation(CNDSGroup, aGroupPropMapping)
  31. CNDSGroup::CNDSGroup():
  32. _pADs(NULL),
  33. _pDSObject(NULL),
  34. _pDSSearch(NULL),
  35. _pDSSchemaMgmt(NULL),
  36. _pADsPropList(NULL),
  37. _pDispMgr(NULL)
  38. {
  39. ENLIST_TRACKING(CNDSGroup);
  40. }
  41. HRESULT
  42. CNDSGroup::CreateGroup(
  43. IADs * pADs,
  44. CCredentials& Credentials,
  45. REFIID riid,
  46. void **ppvObj
  47. )
  48. {
  49. CNDSGroup FAR * pGroup = NULL;
  50. HRESULT hr = S_OK;
  51. hr = AllocateGroupObject(pADs, Credentials, &pGroup);
  52. BAIL_ON_FAILURE(hr);
  53. hr = pGroup->QueryInterface(riid, ppvObj);
  54. BAIL_ON_FAILURE(hr);
  55. pGroup->Release();
  56. RRETURN(hr);
  57. error:
  58. delete pGroup;
  59. RRETURN_EXP_IF_ERR(hr);
  60. }
  61. CNDSGroup::~CNDSGroup( )
  62. {
  63. if (_pADs) {
  64. _pADs->Release();
  65. }
  66. if (_pDSObject) {
  67. _pDSObject->Release();
  68. }
  69. if (_pDSSearch) {
  70. _pDSSearch->Release();
  71. }
  72. if (_pDSSchemaMgmt) {
  73. _pDSSchemaMgmt->Release();
  74. }
  75. if (_pADsPropList) {
  76. _pADsPropList->Release();
  77. }
  78. delete _pDispMgr;
  79. }
  80. STDMETHODIMP
  81. CNDSGroup::QueryInterface(
  82. REFIID iid,
  83. LPVOID FAR* ppv
  84. )
  85. {
  86. if (ppv == NULL) {
  87. RRETURN(E_POINTER);
  88. }
  89. if (IsEqualIID(iid, IID_IUnknown))
  90. {
  91. *ppv = (IADsGroup FAR *) this;
  92. }
  93. else if (IsEqualIID(iid, IID_IADsGroup))
  94. {
  95. *ppv = (IADsGroup FAR *) this;
  96. }
  97. else if (IsEqualIID(iid, IID_IADs))
  98. {
  99. *ppv = (IADsGroup FAR *) this;
  100. }
  101. else if (IsEqualIID(iid, IID_IDispatch))
  102. {
  103. *ppv = (IADsGroup FAR *) this;
  104. }
  105. else if (IsEqualIID(iid, IID_ISupportErrorInfo))
  106. {
  107. *ppv = (ISupportErrorInfo FAR *) this;
  108. }
  109. else if (IsEqualIID(iid, IID_IDirectoryObject))
  110. {
  111. *ppv = (IDirectoryObject FAR *) this;
  112. }
  113. else if (IsEqualIID(iid, IID_IDirectorySearch))
  114. {
  115. *ppv = (IDirectorySearch FAR *) this;
  116. }
  117. else if (IsEqualIID(iid, IID_IADsPropertyList) && _pADsPropList)
  118. {
  119. *ppv = (IADsPropertyList FAR *) this;
  120. }
  121. else if (IsEqualIID(iid, IID_IDirectorySchemaMgmt))
  122. {
  123. *ppv = (IDirectorySchemaMgmt FAR *) this;
  124. }
  125. else
  126. {
  127. *ppv = NULL;
  128. return E_NOINTERFACE;
  129. }
  130. AddRef();
  131. return NOERROR;
  132. }
  133. HRESULT
  134. CNDSGroup::AllocateGroupObject(
  135. IADs *pADs,
  136. CCredentials& Credentials,
  137. CNDSGroup ** ppGroup
  138. )
  139. {
  140. CNDSGroup FAR * pGroup = NULL;
  141. CDispatchMgr FAR * pDispMgr = NULL;
  142. HRESULT hr = S_OK;
  143. IDirectoryObject * pDSObject = NULL;
  144. IDirectorySearch * pDSSearch = NULL;
  145. IDirectorySchemaMgmt * pDSSchemaMgmt = NULL;
  146. IADsPropertyList * pADsPropList = NULL;
  147. pGroup = new CNDSGroup();
  148. if (pGroup == NULL) {
  149. hr = E_OUTOFMEMORY;
  150. }
  151. BAIL_ON_FAILURE(hr);
  152. pDispMgr = new CDispatchMgr;
  153. if (pDispMgr == NULL) {
  154. hr = E_OUTOFMEMORY;
  155. }
  156. BAIL_ON_FAILURE(hr);
  157. hr = LoadTypeInfoEntry(
  158. pDispMgr,
  159. LIBID_ADs,
  160. IID_IADsGroup,
  161. (IADsGroup *)pGroup,
  162. DISPID_REGULAR
  163. );
  164. BAIL_ON_FAILURE(hr);
  165. hr = LoadTypeInfoEntry(
  166. pDispMgr,
  167. LIBID_ADs,
  168. IID_IADsPropertyList,
  169. (IADsPropertyList *)pGroup,
  170. DISPID_VALUE
  171. );
  172. BAIL_ON_FAILURE(hr);
  173. hr = pADs->QueryInterface(
  174. IID_IDirectoryObject,
  175. (void **)&pDSObject
  176. );
  177. BAIL_ON_FAILURE(hr);
  178. pGroup->_pDSObject = pDSObject;
  179. hr = pADs->QueryInterface(
  180. IID_IDirectorySearch,
  181. (void **)&pDSSearch
  182. );
  183. BAIL_ON_FAILURE(hr);
  184. pGroup->_pDSSearch = pDSSearch;
  185. hr = pADs->QueryInterface(
  186. IID_IDirectorySchemaMgmt,
  187. (void **)&pDSSchemaMgmt
  188. );
  189. BAIL_ON_FAILURE(hr);
  190. pGroup->_pDSSchemaMgmt = pDSSchemaMgmt;
  191. hr = pADs->QueryInterface(
  192. IID_IADsPropertyList,
  193. (void **)&pADsPropList
  194. );
  195. BAIL_ON_FAILURE(hr);
  196. pGroup->_pADsPropList = pADsPropList;
  197. //
  198. // Store the pointer to the internal generic object
  199. // AND add ref this pointer
  200. //
  201. pGroup->_pADs = pADs;
  202. pADs->AddRef();
  203. pGroup->_Credentials = Credentials;
  204. pGroup->_pDispMgr = pDispMgr;
  205. *ppGroup = pGroup;
  206. RRETURN(hr);
  207. error:
  208. delete pDispMgr;
  209. delete pGroup;
  210. *ppGroup = NULL;
  211. RRETURN(hr);
  212. }
  213. /* ISupportErrorInfo methods */
  214. STDMETHODIMP
  215. CNDSGroup::InterfaceSupportsErrorInfo(
  216. THIS_ REFIID riid
  217. )
  218. {
  219. if (IsEqualIID(riid, IID_IADs) ||
  220. #if 0
  221. IsEqualIID(riid, IID_IDirectoryObject) ||
  222. IsEqualIID(riid, IID_IDirectorySearch) ||
  223. IsEqualIID(riid, IID_IDirectorySchemaMgmt) ||
  224. #endif
  225. IsEqualIID(riid, IID_IADsGroup) ||
  226. IsEqualIID(riid, IID_IADsPropertyList)) {
  227. RRETURN(S_OK);
  228. } else {
  229. RRETURN(S_FALSE);
  230. }
  231. }
  232.