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.

399 lines
8.4 KiB

  1. //---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1995
  5. //
  6. // File: cOrganization.cxx
  7. //
  8. // Contents: Organization object
  9. //
  10. // History: 11-1-95 krishnag Created.
  11. //
  12. //----------------------------------------------------------------------------
  13. #include "ldap.hxx"
  14. #pragma hdrstop
  15. struct _propmap
  16. {
  17. LPTSTR pszADsProp;
  18. LPTSTR pszLDAPProp;
  19. } aOrgPropMapping[] =
  20. { // { TEXT("Description"), TEXT("description") }, // does not exist in NTDS???
  21. { TEXT("LocalityName"), TEXT("l") },
  22. // { TEXT("PostalAddress"), TEXT("postalAddress") },
  23. // { TEXT("TelephoneNumber"), TEXT("telephoneNumber") },
  24. { TEXT("FaxNumber"), TEXT("facsimileTelephoneNumber") }
  25. // { TEXT("SeeAlso"), TEXT("seeAlso") }
  26. };
  27. // Class CLDAPOrganization
  28. // IADsExtension::PrivateGetIDsOfNames()/Invoke(), Operate() not included
  29. DEFINE_IADsExtension_Implementation(CLDAPOrganization)
  30. DEFINE_IPrivateDispatch_Implementation(CLDAPOrganization)
  31. DEFINE_DELEGATING_IDispatch_Implementation(CLDAPOrganization)
  32. DEFINE_CONTAINED_IADs_Implementation(CLDAPOrganization)
  33. DEFINE_CONTAINED_IADsPutGet_Implementation(CLDAPOrganization, aOrgPropMapping)
  34. CLDAPOrganization::CLDAPOrganization():
  35. _pUnkOuter(NULL),
  36. _pADs(NULL),
  37. _fDispInitialized(FALSE),
  38. _pDispMgr(NULL)
  39. {
  40. ENLIST_TRACKING(CLDAPOrganization);
  41. }
  42. HRESULT
  43. CLDAPOrganization::CreateOrganization(
  44. IUnknown *pUnkOuter,
  45. REFIID riid,
  46. void **ppvObj
  47. )
  48. {
  49. HRESULT hr = S_OK;
  50. CLDAPOrganization FAR * pOrganization = NULL;
  51. IADs FAR * pADs = NULL;
  52. CAggregateeDispMgr FAR * pDispMgr = NULL;
  53. //
  54. // our extension object only works in a provider (aggregator) environment
  55. // environment
  56. //
  57. ASSERT(pUnkOuter);
  58. ASSERT(ppvObj);
  59. ASSERT(IsEqualIID(riid, IID_IUnknown));
  60. pOrganization = new CLDAPOrganization();
  61. if (pOrganization == NULL) {
  62. hr = E_OUTOFMEMORY;
  63. BAIL_ON_FAILURE(hr);
  64. }
  65. //
  66. // Ref Count = 1 from object tracker
  67. //
  68. //
  69. // CAggregateeDispMgr to handle
  70. // IADsExtension::PrivateGetIDsOfNames()/PrivatInovke()
  71. //
  72. pDispMgr = new CAggregateeDispMgr;
  73. if (pDispMgr == NULL) {
  74. hr = E_OUTOFMEMORY;
  75. BAIL_ON_FAILURE(hr);
  76. }
  77. pOrganization->_pDispMgr = pDispMgr;
  78. hr = pDispMgr->LoadTypeInfoEntry(
  79. LIBID_ADs,
  80. IID_IADsO,
  81. (IADsO *)pOrganization,
  82. DISPID_REGULAR
  83. );
  84. BAIL_ON_FAILURE(hr);
  85. //
  86. // Store the pointer to the pUnkOuter object to delegate all IUnknown
  87. // calls to the aggregator AND DO NOT add ref this pointer
  88. //
  89. pOrganization->_pUnkOuter = pUnkOuter;
  90. //
  91. // Ccache pADs Pointer to delegate all IDispatch calls to
  92. // the aggregator. But release immediately to avoid the aggregatee
  93. // having a reference count on the aggregator -> cycle ref counting
  94. //
  95. hr = pUnkOuter->QueryInterface(
  96. IID_IADs,
  97. (void **)&pADs
  98. );
  99. //
  100. // Our spec stated extesnion writers can expect the aggregator in our
  101. // provider ot support IDispatch. If not, major bug.
  102. //
  103. ASSERT(SUCCEEDED(hr));
  104. pADs->Release(); // see doc above pUnkOuter->QI
  105. pOrganization->_pADs = pADs;
  106. //
  107. // pass non-delegating IUnknown back to the aggregator
  108. //
  109. *ppvObj = (INonDelegatingUnknown FAR *) pOrganization;
  110. RRETURN(hr);
  111. error:
  112. if (pOrganization)
  113. delete pOrganization;
  114. *ppvObj = NULL;
  115. RRETURN(hr);
  116. }
  117. CLDAPOrganization::~CLDAPOrganization( )
  118. {
  119. //
  120. // You should never have to AddRef pointers
  121. // except for the real pointers that are
  122. // issued out.
  123. //
  124. delete _pDispMgr;
  125. }
  126. STDMETHODIMP
  127. CLDAPOrganization::QueryInterface(
  128. REFIID iid,
  129. LPVOID FAR* ppv
  130. )
  131. {
  132. HRESULT hr = S_OK;
  133. hr = _pUnkOuter->QueryInterface(iid,ppv);
  134. RRETURN(hr);
  135. }
  136. STDMETHODIMP
  137. CLDAPOrganization::NonDelegatingQueryInterface(
  138. REFIID iid,
  139. LPVOID FAR* ppv
  140. )
  141. {
  142. ASSERT(ppv);
  143. if (IsEqualIID(iid, IID_IADsO))
  144. {
  145. *ppv = (IADsO FAR *) this;
  146. } else if (IsEqualIID(iid, IID_IADsExtension)) {
  147. *ppv = (IADsExtension FAR *) this;
  148. } else if (IsEqualIID(iid, IID_IUnknown)) {
  149. //
  150. // probably not needed since our 3rd party extension does not stand
  151. // alone and provider does not ask for this, but to be safe
  152. //
  153. *ppv = (INonDelegatingUnknown FAR *) this;
  154. } else {
  155. *ppv = NULL;
  156. return E_NOINTERFACE;
  157. }
  158. //
  159. // Delegating AddRef to aggregator for IADsExtesnion and.
  160. // AddRef on itself for IPrivateUnknown. (both tested.)
  161. //
  162. ((IUnknown *) (*ppv)) -> AddRef();
  163. return S_OK;
  164. }
  165. STDMETHODIMP
  166. CLDAPOrganization::ADSIInitializeObject(
  167. THIS_ BSTR lpszUserName,
  168. BSTR lpszPassword,
  169. long lnReserved
  170. )
  171. {
  172. CCredentials NewCredentials(lpszUserName, lpszPassword, lnReserved);
  173. _Credentials = NewCredentials;
  174. RRETURN(S_OK);
  175. }
  176. STDMETHODIMP CLDAPOrganization::get_Description(THIS_ BSTR FAR* retval)
  177. {
  178. GET_PROPERTY_BSTR((IADsO *)this,Description);
  179. }
  180. STDMETHODIMP CLDAPOrganization::put_Description(THIS_ BSTR bstrDescription)
  181. {
  182. PUT_PROPERTY_BSTR((IADsO *)this,Description);
  183. }
  184. STDMETHODIMP CLDAPOrganization::get_LocalityName(THIS_ BSTR FAR* retval)
  185. {
  186. GET_PROPERTY_BSTR((IADsO *)this,LocalityName);
  187. }
  188. STDMETHODIMP CLDAPOrganization::put_LocalityName(THIS_ BSTR bstrLocalityName)
  189. {
  190. PUT_PROPERTY_BSTR((IADsO *)this,LocalityName);
  191. }
  192. STDMETHODIMP CLDAPOrganization::get_PostalAddress(THIS_ BSTR FAR* retval)
  193. {
  194. GET_PROPERTY_BSTR((IADsO *)this,PostalAddress);
  195. }
  196. STDMETHODIMP CLDAPOrganization::put_PostalAddress(THIS_ BSTR bstrPostalAddress)
  197. {
  198. PUT_PROPERTY_BSTR((IADsO *)this,PostalAddress);
  199. }
  200. STDMETHODIMP CLDAPOrganization::get_TelephoneNumber(THIS_ BSTR FAR* retval)
  201. {
  202. GET_PROPERTY_BSTR((IADsO *)this,TelephoneNumber);
  203. }
  204. STDMETHODIMP CLDAPOrganization::put_TelephoneNumber(THIS_ BSTR bstrTelephoneNumber)
  205. {
  206. PUT_PROPERTY_BSTR((IADsO *)this,TelephoneNumber);
  207. }
  208. STDMETHODIMP CLDAPOrganization::get_FaxNumber(THIS_ BSTR FAR* retval)
  209. {
  210. GET_PROPERTY_BSTR((IADsO *)this,FaxNumber);
  211. }
  212. STDMETHODIMP CLDAPOrganization::put_FaxNumber(THIS_ BSTR bstrFaxNumber)
  213. {
  214. PUT_PROPERTY_BSTR((IADsO *)this,FaxNumber);
  215. }
  216. STDMETHODIMP CLDAPOrganization::get_SeeAlso(THIS_ VARIANT FAR* retval)
  217. {
  218. GET_PROPERTY_VARIANT((IADsO *)this,SeeAlso);
  219. }
  220. STDMETHODIMP CLDAPOrganization::put_SeeAlso(THIS_ VARIANT vSeeAlso)
  221. {
  222. PUT_PROPERTY_VARIANT((IADsO *)this,SeeAlso);
  223. }
  224. STDMETHODIMP
  225. CLDAPOrganization::ADSIInitializeDispatchManager(
  226. long dwExtensionId
  227. )
  228. {
  229. HRESULT hr = S_OK;
  230. if (_fDispInitialized) {
  231. RRETURN(E_FAIL);
  232. }
  233. hr = _pDispMgr->InitializeDispMgr(dwExtensionId);
  234. if (SUCCEEDED(hr)) {
  235. _fDispInitialized = TRUE;
  236. }
  237. RRETURN(hr);
  238. }
  239. STDMETHODIMP
  240. CLDAPOrganization::ADSIReleaseObject()
  241. {
  242. delete this;
  243. RRETURN(S_OK);
  244. }
  245. //
  246. // IADsExtension::Operate()
  247. //
  248. STDMETHODIMP
  249. CLDAPOrganization::Operate(
  250. THIS_ DWORD dwCode,
  251. VARIANT varData1,
  252. VARIANT varData2,
  253. VARIANT varData3
  254. )
  255. {
  256. HRESULT hr = S_OK;
  257. switch (dwCode) {
  258. case ADS_EXT_INITCREDENTIALS:
  259. hr = InitCredentials(
  260. &varData1,
  261. &varData2,
  262. &varData3
  263. );
  264. break;
  265. default:
  266. hr = E_FAIL;
  267. break;
  268. }
  269. RRETURN(hr);
  270. }
  271. HRESULT
  272. CLDAPOrganization::InitCredentials(
  273. VARIANT * pvarUserName,
  274. VARIANT * pvarPassword,
  275. VARIANT * pvarFlags
  276. )
  277. {
  278. BSTR bstrUser = NULL;
  279. BSTR bstrPwd = NULL;
  280. DWORD dwFlags = 0;
  281. ASSERT(V_VT(pvarUserName) == VT_BSTR);
  282. ASSERT(V_VT(pvarPassword) == VT_BSTR);
  283. ASSERT(V_VT(pvarFlags) == VT_I4);
  284. bstrUser = V_BSTR(pvarUserName);
  285. bstrPwd = V_BSTR(pvarPassword);
  286. dwFlags = V_I4(pvarFlags);
  287. CCredentials NewCredentials(bstrUser, bstrPwd, dwFlags);
  288. _Credentials = NewCredentials;
  289. RRETURN(S_OK);
  290. }