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.

329 lines
6.3 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 "ldap.hxx"
  14. #pragma hdrstop
  15. // Class CLDAPGroup
  16. struct _propmap
  17. {
  18. LPTSTR pszADsProp;
  19. LPTSTR pszLDAPProp;
  20. } aGroupPropMapping[] =
  21. {
  22. { TEXT("Description"), TEXT("description") },
  23. };
  24. // IADsExtension::PrivateGetIDsOfNames()/Invoke(), Operate() not included
  25. DEFINE_IADsExtension_Implementation(CLDAPGroup)
  26. DEFINE_IPrivateDispatch_Implementation(CLDAPGroup)
  27. DEFINE_DELEGATING_IDispatch_Implementation(CLDAPGroup)
  28. DEFINE_CONTAINED_IADs_Implementation(CLDAPGroup)
  29. DEFINE_CONTAINED_IADsPutGet_Implementation(CLDAPGroup, aGroupPropMapping)
  30. CLDAPGroup::CLDAPGroup():
  31. _pUnkOuter(NULL),
  32. _pADs(NULL),
  33. _fDispInitialized(FALSE),
  34. _pDispMgr(NULL),
  35. _dwServerType(SERVER_TYPE_UNKNOWN)
  36. {
  37. ENLIST_TRACKING(CLDAPGroup);
  38. }
  39. HRESULT
  40. CLDAPGroup::CreateGroup(
  41. IUnknown *pUnkOuter,
  42. REFIID riid,
  43. void **ppvObj
  44. )
  45. {
  46. HRESULT hr = S_OK;
  47. CLDAPGroup FAR * pGroup = NULL;
  48. IADs FAR * pADs = NULL;
  49. CAggregateeDispMgr FAR * pDispMgr = NULL;
  50. //
  51. // our extension object only works in a provider (aggregator) environment
  52. // environment
  53. //
  54. ASSERT(pUnkOuter);
  55. ASSERT(ppvObj);
  56. ASSERT(IsEqualIID(riid, IID_IUnknown));
  57. pGroup = new CLDAPGroup();
  58. if (pGroup == NULL) {
  59. hr = E_OUTOFMEMORY;
  60. BAIL_ON_FAILURE(hr);
  61. }
  62. //
  63. // Ref Count = 1 from object tracker
  64. //
  65. //
  66. // CAggregateeDispMgr to handle
  67. // IADsExtension::PrivateGetIDsOfNames()/PrivatInovke()
  68. //
  69. pDispMgr = new CAggregateeDispMgr;
  70. if (pDispMgr == NULL) {
  71. hr = E_OUTOFMEMORY;
  72. BAIL_ON_FAILURE(hr);
  73. }
  74. pGroup->_pDispMgr = pDispMgr;
  75. hr = pDispMgr->LoadTypeInfoEntry(
  76. LIBID_ADs,
  77. IID_IADsGroup,
  78. (IADsGroup *)pGroup,
  79. DISPID_REGULAR
  80. );
  81. BAIL_ON_FAILURE(hr);
  82. //
  83. // Store the pointer to the pUnkOuter object to delegate all IUnknown
  84. // calls to the aggregator AND DO NOT add ref this pointer
  85. //
  86. pGroup->_pUnkOuter = pUnkOuter;
  87. //
  88. // Ccache pADs Pointer to delegate all IDispatch calls to
  89. // the aggregator. But release immediately to avoid the aggregatee
  90. // having a reference count on the aggregator -> cycle ref counting
  91. //
  92. hr = pUnkOuter->QueryInterface(
  93. IID_IADs,
  94. (void **)&pADs
  95. );
  96. //
  97. // Our spec stated extesnion writers can expect the aggregator in our
  98. // provider ot support IDispatch. If not, major bug.
  99. //
  100. ASSERT(SUCCEEDED(hr));
  101. pADs->Release(); // see doc above pUnkOuter->QI
  102. pGroup->_pADs = pADs;
  103. //
  104. // pass non-delegating IUnknown back to the aggregator
  105. //
  106. *ppvObj = (INonDelegatingUnknown FAR *) pGroup;
  107. RRETURN(hr);
  108. error:
  109. if (pGroup)
  110. delete pGroup;
  111. *ppvObj = NULL;
  112. RRETURN(hr);
  113. }
  114. CLDAPGroup::~CLDAPGroup( )
  115. {
  116. //
  117. // Remember that the aggregatee has no reference counts to
  118. // decrement.
  119. //
  120. delete _pDispMgr;
  121. }
  122. STDMETHODIMP
  123. CLDAPGroup::QueryInterface(
  124. REFIID iid,
  125. LPVOID FAR* ppv
  126. )
  127. {
  128. HRESULT hr = S_OK;
  129. hr = _pUnkOuter->QueryInterface(iid,ppv);
  130. RRETURN(hr);
  131. }
  132. STDMETHODIMP
  133. CLDAPGroup::NonDelegatingQueryInterface(
  134. REFIID iid,
  135. LPVOID FAR* ppv
  136. )
  137. {
  138. ASSERT(ppv);
  139. if (IsEqualIID(iid, IID_IADsGroup))
  140. {
  141. *ppv = (IADsGroup FAR *) this;
  142. } else if (IsEqualIID(iid, IID_IADsExtension)) {
  143. *ppv = (IADsExtension FAR *) this;
  144. } else if (IsEqualIID(iid, IID_IUnknown)) {
  145. //
  146. // probably not needed since our 3rd party extension does not stand
  147. // alone and provider does not ask for this, but to be safe
  148. //
  149. *ppv = (INonDelegatingUnknown FAR *) this;
  150. } else {
  151. *ppv = NULL;
  152. return E_NOINTERFACE;
  153. }
  154. //
  155. // Delegating AddRef to aggregator for IADsExtesnion and IADsGroup.
  156. // AddRef on itself for IPrivateUnknown. (both tested.)
  157. //
  158. ((IUnknown *) (*ppv)) -> AddRef();
  159. return S_OK;
  160. }
  161. STDMETHODIMP
  162. CLDAPGroup::ADSIInitializeObject(
  163. THIS_ BSTR lpszUserName,
  164. BSTR lpszPassword,
  165. long lnReserved
  166. )
  167. {
  168. CCredentials NewCredentials(lpszUserName, lpszPassword, lnReserved);
  169. _Credentials = NewCredentials;
  170. RRETURN(S_OK);
  171. }
  172. STDMETHODIMP
  173. CLDAPGroup::ADSIInitializeDispatchManager(
  174. long dwExtensionId
  175. )
  176. {
  177. HRESULT hr = S_OK;
  178. if (_fDispInitialized) {
  179. RRETURN(E_FAIL);
  180. }
  181. hr = _pDispMgr->InitializeDispMgr(dwExtensionId);
  182. if (SUCCEEDED(hr)) {
  183. _fDispInitialized = TRUE;
  184. }
  185. RRETURN(hr);
  186. }
  187. STDMETHODIMP
  188. CLDAPGroup::ADSIReleaseObject()
  189. {
  190. delete this;
  191. RRETURN(S_OK);
  192. }
  193. //
  194. // IADsExtension::Operate()
  195. //
  196. STDMETHODIMP
  197. CLDAPGroup::Operate(
  198. THIS_ DWORD dwCode,
  199. VARIANT varData1,
  200. VARIANT varData2,
  201. VARIANT varData3
  202. )
  203. {
  204. HRESULT hr = S_OK;
  205. switch (dwCode) {
  206. case ADS_EXT_INITCREDENTIALS:
  207. hr = InitCredentials(
  208. &varData1,
  209. &varData2,
  210. &varData3
  211. );
  212. break;
  213. default:
  214. hr = E_FAIL;
  215. break;
  216. }
  217. RRETURN(hr);
  218. }
  219. HRESULT
  220. CLDAPGroup::InitCredentials(
  221. VARIANT * pvarUserName,
  222. VARIANT * pvarPassword,
  223. VARIANT * pvarFlags
  224. )
  225. {
  226. BSTR bstrUser = NULL;
  227. BSTR bstrPwd = NULL;
  228. DWORD dwFlags = 0;
  229. ASSERT(V_VT(pvarUserName) == VT_BSTR);
  230. ASSERT(V_VT(pvarPassword) == VT_BSTR);
  231. ASSERT(V_VT(pvarFlags) == VT_I4);
  232. bstrUser = V_BSTR(pvarUserName);
  233. bstrPwd = V_BSTR(pvarPassword);
  234. dwFlags = V_I4(pvarFlags);
  235. CCredentials NewCredentials(bstrUser, bstrPwd, dwFlags);
  236. _Credentials = NewCredentials;
  237. RRETURN(S_OK);
  238. }