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.

375 lines
8.1 KiB

  1. //----------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1996
  5. //
  6. // File: cuser.cxx
  7. //
  8. // Contents: Host user object code
  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. } aUserPropMapping[] =
  20. {
  21. { TEXT("BadLoginCount"), TEXT("badPwdCount") },
  22. { TEXT("LastLogin"), TEXT("lastLogon") },
  23. { TEXT("LastLogoff"), TEXT("lastLogoff") },
  24. { TEXT("LastFailedLogin"), TEXT("badPasswordTime") },
  25. { TEXT("PasswordLastChanged"), TEXT("pwdLastSet") },
  26. { TEXT("Description"), TEXT("description") },
  27. { TEXT("Division"), TEXT("division") },
  28. { TEXT("Department"), TEXT("department") },
  29. { TEXT("EmployeeID"), TEXT("employeeID") },
  30. { TEXT("FullName"), TEXT("displayName") },
  31. { TEXT("FirstName"), TEXT("givenName") },
  32. { TEXT("LastName"), TEXT("sn") },
  33. { TEXT("OtherName"), TEXT("middleName") },
  34. { TEXT("NamePrefix"), TEXT("personalTitle") },
  35. { TEXT("NameSuffix"), TEXT("generationQualifier") },
  36. { TEXT("Title"), TEXT("title") },
  37. { TEXT("Manager"), TEXT("manager") },
  38. { TEXT("TelephoneNumber"), TEXT("telephoneNumber") },
  39. { TEXT("TelephoneHome"), TEXT("homePhone") },
  40. { TEXT("TelephoneMobile"), TEXT("mobile") },
  41. { TEXT("TelephonePager"), TEXT("pager") },
  42. { TEXT("FaxNumber"), TEXT("facsimileTelephoneNumber") },
  43. { TEXT("OfficeLocations"), TEXT("physicalDeliveryOfficeName") },
  44. { TEXT("PostalAddresses"), TEXT("postalAddress") },
  45. { TEXT("PostalCodes"), TEXT("postalCode") },
  46. { TEXT("SeeAlso"), TEXT("seeAlso") },
  47. { TEXT("AccountExpirationDate"), TEXT("accountExpires") },
  48. { TEXT("LoginHours"), TEXT("logonHours") },
  49. { TEXT("LoginWorkstations"), TEXT("userWorkstations") },
  50. { TEXT("MaxStorage"), TEXT("maxStorage") },
  51. { TEXT("EmailAddress"), TEXT("mail") },
  52. { TEXT("HomeDirectory"), TEXT("homeDirectory") },
  53. { TEXT("Profile"), TEXT("profilePath") },
  54. { TEXT("LoginScript"), TEXT("scriptPath") },
  55. { TEXT("Picture"), TEXT("thumbnailPhoto") },
  56. { TEXT("HomePage"), TEXT("wWWHomePage") }
  57. };
  58. DWORD dwNumUserPropMapping = sizeof(aUserPropMapping)/sizeof(_propmap);
  59. // Class CLDAPUser
  60. DEFINE_IPrivateDispatch_Implementation(CLDAPUser)
  61. // IADsExtension::PrivateGetIDsOfNames()/Invoke(), Operate() not included
  62. DEFINE_IADsExtension_Implementation(CLDAPUser)
  63. DEFINE_DELEGATING_IDispatch_Implementation(CLDAPUser)
  64. DEFINE_CONTAINED_IADs_Implementation(CLDAPUser)
  65. DEFINE_CONTAINED_IADsPutGet_Implementation(CLDAPUser,aUserPropMapping)
  66. CLDAPUser::CLDAPUser():
  67. _pUnkOuter(NULL),
  68. _pADs(NULL),
  69. _fDispInitialized(FALSE),
  70. _pDispMgr(NULL)
  71. {
  72. ENLIST_TRACKING(CLDAPUser);
  73. }
  74. HRESULT
  75. CLDAPUser::CreateUser(
  76. IUnknown *pUnkOuter,
  77. REFIID riid,
  78. void **ppvObj
  79. )
  80. {
  81. HRESULT hr = S_OK;
  82. CLDAPUser FAR * pUser = NULL;
  83. IADs FAR * pADs = NULL;
  84. CAggregateeDispMgr FAR * pDispMgr = NULL;
  85. //
  86. // our extension object only works in a provider (aggregator) environment
  87. // environment
  88. //
  89. ASSERT(pUnkOuter);
  90. ASSERT(ppvObj);
  91. ASSERT(IsEqualIID(riid, IID_IUnknown));
  92. pUser = new CLDAPUser();
  93. if (pUser == NULL) {
  94. hr = E_OUTOFMEMORY;
  95. BAIL_ON_FAILURE(hr);
  96. }
  97. //
  98. // Ref Count = 1 from object tracker
  99. //
  100. //
  101. // CAggregateeDispMgr to handle
  102. // IADsExtension::PrivateGetIDsOfNames()/PrivatInovke()
  103. //
  104. pDispMgr = new CAggregateeDispMgr;
  105. if (pDispMgr == NULL) {
  106. hr = E_OUTOFMEMORY;
  107. BAIL_ON_FAILURE(hr);
  108. }
  109. pUser->_pDispMgr = pDispMgr;
  110. hr = pDispMgr->LoadTypeInfoEntry(
  111. LIBID_ADs,
  112. IID_IADsUser,
  113. (IADsUser *)pUser,
  114. DISPID_REGULAR
  115. );
  116. BAIL_ON_FAILURE(hr);
  117. //
  118. // Store the pointer to the pUnkOuter object to delegate all IUnknown
  119. // calls to the aggregator AND DO NOT add ref this pointer
  120. //
  121. pUser->_pUnkOuter = pUnkOuter;
  122. //
  123. // Ccache pADs Pointer to delegate all IDispatch calls to
  124. // the aggregator. But release immediately to avoid the aggregatee
  125. // having a reference count on the aggregator -> cycle ref counting
  126. //
  127. hr = pUnkOuter->QueryInterface(
  128. IID_IADs,
  129. (void **)&pADs
  130. );
  131. //
  132. // Our spec stated extesnion writers can expect the aggregator in our
  133. // provider ot support IDispatch. If not, major bug.
  134. //
  135. ASSERT(SUCCEEDED(hr));
  136. pADs->Release(); // see doc above pUnkOuter->QI
  137. pUser->_pADs = pADs;
  138. //
  139. // pass non-delegating IUnknown back to the aggregator
  140. //
  141. *ppvObj = (INonDelegatingUnknown FAR *) pUser;
  142. RRETURN(hr);
  143. error:
  144. //
  145. // do NOT clean up dispMgr here. Iff created, cleaned up Once inside pUser
  146. //
  147. if (pUser)
  148. delete pUser;
  149. *ppvObj = NULL;
  150. RRETURN(hr);
  151. }
  152. STDMETHODIMP
  153. CLDAPUser::ADSIInitializeObject(
  154. THIS_ BSTR lpszUserName,
  155. BSTR lpszPassword,
  156. long lnReserved
  157. )
  158. {
  159. CCredentials NewCredentials(lpszUserName, lpszPassword, lnReserved);
  160. _Credentials = NewCredentials;
  161. RRETURN(S_OK);
  162. }
  163. CLDAPUser::~CLDAPUser( )
  164. {
  165. //
  166. // Remember that the aggregatee has no reference counts to
  167. // decrement.
  168. //
  169. delete _pDispMgr;
  170. }
  171. STDMETHODIMP
  172. CLDAPUser::QueryInterface(
  173. REFIID iid,
  174. LPVOID FAR* ppv
  175. )
  176. {
  177. HRESULT hr = S_OK;
  178. hr = _pUnkOuter->QueryInterface(iid,ppv);
  179. RRETURN(hr);
  180. }
  181. STDMETHODIMP
  182. CLDAPUser::NonDelegatingQueryInterface(
  183. REFIID iid,
  184. LPVOID FAR* ppv
  185. )
  186. {
  187. ASSERT(ppv);
  188. if (IsEqualIID(iid, IID_IADsUser)) {
  189. *ppv = (IADsUser FAR *) this;
  190. } else if (IsEqualIID(iid, IID_IADsExtension)) {
  191. *ppv = (IADsExtension FAR *) this;
  192. } else if (IsEqualIID(iid, IID_IUnknown)) {
  193. //
  194. // probably not needed since our 3rd party extension does not stand
  195. // alone and provider does not ask for this, but to be safe
  196. //
  197. *ppv = (INonDelegatingUnknown FAR *) this;
  198. } else {
  199. *ppv = NULL;
  200. return E_NOINTERFACE;
  201. }
  202. //
  203. // Delegating AddRef to aggregator for IADsExtesnion and IADsUser.
  204. // AddRef on itself for IPrivateUnknown. (both tested.)
  205. //
  206. ((IUnknown *) (*ppv)) -> AddRef();
  207. return S_OK;
  208. }
  209. STDMETHODIMP
  210. CLDAPUser::ADSIInitializeDispatchManager(
  211. long dwExtensionId
  212. )
  213. {
  214. HRESULT hr = S_OK;
  215. if (_fDispInitialized) {
  216. RRETURN(E_FAIL);
  217. }
  218. hr = _pDispMgr->InitializeDispMgr(dwExtensionId);
  219. if (SUCCEEDED(hr)) {
  220. _fDispInitialized = TRUE;
  221. }
  222. RRETURN(hr);
  223. }
  224. STDMETHODIMP
  225. CLDAPUser::ADSIReleaseObject()
  226. {
  227. delete this;
  228. RRETURN(S_OK);
  229. }
  230. //
  231. // IADsExtension::Operate()
  232. //
  233. STDMETHODIMP
  234. CLDAPUser::Operate(
  235. THIS_ DWORD dwCode,
  236. VARIANT varData1,
  237. VARIANT varData2,
  238. VARIANT varData3
  239. )
  240. {
  241. HRESULT hr = S_OK;
  242. switch (dwCode) {
  243. case ADS_EXT_INITCREDENTIALS:
  244. hr = InitCredentials(
  245. &varData1,
  246. &varData2,
  247. &varData3
  248. );
  249. break;
  250. default:
  251. hr = E_FAIL;
  252. break;
  253. }
  254. RRETURN(hr);
  255. }
  256. HRESULT
  257. CLDAPUser::InitCredentials(
  258. VARIANT * pvarUserName,
  259. VARIANT * pvarPassword,
  260. VARIANT * pvarFlags
  261. )
  262. {
  263. BSTR bstrUser = NULL;
  264. BSTR bstrPwd = NULL;
  265. DWORD dwFlags = 0;
  266. ASSERT(V_VT(pvarUserName) == VT_BSTR);
  267. ASSERT(V_VT(pvarPassword) == VT_BSTR);
  268. ASSERT(V_VT(pvarFlags) == VT_I4);
  269. bstrUser = V_BSTR(pvarUserName);
  270. bstrPwd = V_BSTR(pvarPassword);
  271. dwFlags = V_I4(pvarFlags);
  272. CCredentials NewCredentials(bstrUser, bstrPwd, dwFlags);
  273. _Credentials = NewCredentials;
  274. RRETURN(S_OK);
  275. }