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.

258 lines
5.2 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. _pDSAttrMgmt(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(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 (_pDSAttrMgmt) {
  73. _pDSAttrMgmt->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_IDirectoryObject))
  106. {
  107. *ppv = (IDirectoryObject FAR *) this;
  108. }
  109. else if (IsEqualIID(iid, IID_IDirectorySearch))
  110. {
  111. *ppv = (IDirectorySearch FAR *) this;
  112. }
  113. else if (IsEqualIID(iid, IID_IADsPropertyList) && _pADsPropList)
  114. {
  115. *ppv = (IADsPropertyList FAR *) this;
  116. }
  117. else if (IsEqualIID(iid, IID_IDirectorySchemaMgmt))
  118. {
  119. *ppv = (IDirectorySchemaMgmt FAR *) this;
  120. }
  121. else
  122. {
  123. *ppv = NULL;
  124. return E_NOINTERFACE;
  125. }
  126. AddRef();
  127. return NOERROR;
  128. }
  129. HRESULT
  130. CNDSGroup::AllocateGroupObject(
  131. IADs *pADs,
  132. CCredentials& Credentials,
  133. CNDSGroup ** ppGroup
  134. )
  135. {
  136. CNDSGroup FAR * pGroup = NULL;
  137. CDispatchMgr FAR * pDispMgr = NULL;
  138. HRESULT hr = S_OK;
  139. IDirectoryObject * pDSObject = NULL;
  140. IDirectorySearch * pDSSearch = NULL;
  141. IDirectorySchemaMgmt * pDSAttrMgmt = NULL;
  142. IADsPropertyList * pADsPropList = NULL;
  143. pGroup = new CNDSGroup();
  144. if (pGroup == NULL) {
  145. hr = E_OUTOFMEMORY;
  146. }
  147. BAIL_ON_FAILURE(hr);
  148. pDispMgr = new CDispatchMgr;
  149. if (pDispMgr == NULL) {
  150. hr = E_OUTOFMEMORY;
  151. }
  152. BAIL_ON_FAILURE(hr);
  153. hr = LoadTypeInfoEntry(
  154. pDispMgr,
  155. LIBID_ADs,
  156. IID_IADsGroup,
  157. (IADsGroup *)pGroup,
  158. DISPID_REGULAR
  159. );
  160. BAIL_ON_FAILURE(hr);
  161. hr = LoadTypeInfoEntry(
  162. pDispMgr,
  163. LIBID_ADs,
  164. IID_IADsPropertyList,
  165. (IADsPropertyList *)pGroup,
  166. DISPID_VALUE
  167. );
  168. BAIL_ON_FAILURE(hr);
  169. hr = pADs->QueryInterface(
  170. IID_IDirectoryObject,
  171. (void **)&pDSObject
  172. );
  173. BAIL_ON_FAILURE(hr);
  174. pGroup->_pDSObject = pDSObject;
  175. hr = pADs->QueryInterface(
  176. IID_IDirectorySearch,
  177. (void **)&pDSSearch
  178. );
  179. BAIL_ON_FAILURE(hr);
  180. pGroup->_pDSSearch = pDSSearch;
  181. hr = pADs->QueryInterface(
  182. IID_IDirectorySchemaMgmt,
  183. (void **)&pDSAttrMgmt
  184. );
  185. BAIL_ON_FAILURE(hr);
  186. pGroup->_pDSAttrMgmt = pDSAttrMgmt;
  187. hr = pADs->QueryInterface(
  188. IID_IADsPropertyList,
  189. (void **)&pADsPropList
  190. );
  191. BAIL_ON_FAILURE(hr);
  192. pGroup->_pADsPropList = pADsPropList;
  193. //
  194. // Store the pointer to the internal generic object
  195. // AND add ref this pointer
  196. //
  197. pGroup->_pADs = pADs;
  198. pADs->AddRef();
  199. pGroup->_Credentials = Credentials;
  200. pGroup->_pDispMgr = pDispMgr;
  201. *ppGroup = pGroup;
  202. RRETURN(hr);
  203. error:
  204. delete pDispMgr;
  205. delete pGroup;
  206. *ppGroup = NULL;
  207. RRETURN(hr);
  208. }