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.

318 lines
7.8 KiB

  1. //---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1995
  5. //
  6. // File: cuser.cxx
  7. //
  8. // Contents: Host user object code
  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. } aUserPropMapping[] =
  20. {
  21. //{ TEXT("BadLoginCount"), TEXT("badPwdCount") },
  22. { TEXT("LastLogin"), TEXT("Last Login Time") },
  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("Full Name") },
  31. { TEXT("FirstName"), TEXT("Given Name") },
  32. { TEXT("LastName"), TEXT("Surname") },
  33. //{ TEXT("OtherName"), TEXT("middleName") },
  34. //{ TEXT("NamePrefix"), TEXT("personalTitle") },
  35. { TEXT("NameSuffix"), TEXT("Generational Qualifier") },
  36. { TEXT("Title"), TEXT("Title") },
  37. //{ TEXT("Manager"), TEXT("manager") },
  38. { TEXT("TelephoneNumber"), TEXT("Telephone Number") },
  39. //{ TEXT("TelephoneHome"), TEXT("homePhone") },
  40. //{ TEXT("TelephoneMobile"), TEXT("mobile") },
  41. //{ TEXT("TelephonePager"), TEXT("pager") },
  42. { TEXT("FaxNumber"), TEXT("Facsimile Telephone Number") },
  43. { TEXT("OfficeLocations"), TEXT("Physical Delivery Office Name") },
  44. { TEXT("PostalAddresses"), TEXT("Postal Address") },
  45. { TEXT("PostalCodes"), TEXT("Postal Code") },
  46. { TEXT("SeeAlso"), TEXT("See Also") },
  47. //{ TEXT("AccountExpirationDate"), TEXT("accountExpires") },
  48. { TEXT("LoginHours"), TEXT("Login Allowed Time Map") },
  49. //{ TEXT("LoginWorkstations"), TEXT("logonWorkstation") },
  50. //{ TEXT("MaxStorage"), TEXT("maxStorage") },
  51. { TEXT("PasswordExpirationDate"), TEXT("Password Expiration Time") },
  52. { TEXT("PasswordMinimumLength"), TEXT("Password Minimum Length") },
  53. { TEXT("RequireUniquePassword"), TEXT("Password Unique Required") },
  54. { TEXT("EmailAddress"), TEXT("Email Address") },
  55. { TEXT("HomeDirectory"), TEXT("Home Directory") },
  56. { TEXT("Languages"), TEXT("Language") },
  57. { TEXT("Profile"), TEXT("Profile") },
  58. { TEXT("PasswordRequired"), TEXT("Password Required") },
  59. { TEXT("AccountDisabled"), TEXT("Login Disabled") },
  60. { TEXT("GraceLoginsAllowed"), TEXT("Login Grace Limit") },
  61. { TEXT("GraceLoginsRemaining"), TEXT("Login Grace Remaining") },
  62. { TEXT("LoginScript"), TEXT("Login Script") }
  63. //{ TEXT("HomePage"), TEXT("url") }
  64. };
  65. DWORD dwNumUserPropMapping = sizeof(aUserPropMapping)/sizeof(_propmap);
  66. // Class CNDSUser
  67. DEFINE_IDispatch_Implementation(CNDSUser)
  68. DEFINE_CONTAINED_IADs_Implementation(CNDSUser)
  69. DEFINE_CONTAINED_IDirectoryObject_Implementation(CNDSUser)
  70. DEFINE_CONTAINED_IDirectorySearch_Implementation(CNDSUser)
  71. DEFINE_CONTAINED_IDirectorySchemaMgmt_Implementation(CNDSUser)
  72. DEFINE_CONTAINED_IADsPropertyList_Implementation(CNDSUser)
  73. DEFINE_CONTAINED_IADsPutGet_Implementation(CNDSUser,aUserPropMapping)
  74. CNDSUser::CNDSUser():
  75. _pADs(NULL),
  76. _pDSObject(NULL),
  77. _pDSSearch(NULL),
  78. _pDSSchemaMgmt(NULL),
  79. _pDispMgr(NULL),
  80. _pADsPropList(NULL)
  81. {
  82. ENLIST_TRACKING(CNDSUser);
  83. }
  84. HRESULT
  85. CNDSUser::CreateUser(
  86. IADs *pADs,
  87. CCredentials& Credentials,
  88. REFIID riid,
  89. void **ppvObj
  90. )
  91. {
  92. CNDSUser FAR * pUser = NULL;
  93. HRESULT hr = S_OK;
  94. hr = AllocateUserObject(pADs, Credentials, &pUser);
  95. BAIL_ON_FAILURE(hr);
  96. hr = pUser->QueryInterface(riid, ppvObj);
  97. BAIL_ON_FAILURE(hr);
  98. pUser->Release();
  99. RRETURN(hr);
  100. error:
  101. delete pUser;
  102. RRETURN_EXP_IF_ERR(hr);
  103. }
  104. CNDSUser::~CNDSUser( )
  105. {
  106. if (_pADs) {
  107. _pADs->Release();
  108. }
  109. if (_pDSObject) {
  110. _pDSObject->Release();
  111. }
  112. if (_pDSSearch) {
  113. _pDSSearch->Release();
  114. }
  115. if (_pADsPropList) {
  116. _pADsPropList->Release();
  117. }
  118. if (_pDSSchemaMgmt) {
  119. _pDSSchemaMgmt->Release();
  120. }
  121. delete _pDispMgr;
  122. }
  123. STDMETHODIMP
  124. CNDSUser::QueryInterface(
  125. REFIID iid,
  126. LPVOID FAR* ppv
  127. )
  128. {
  129. if (ppv == NULL) {
  130. RRETURN(E_POINTER);
  131. }
  132. if (IsEqualIID(iid, IID_IUnknown))
  133. {
  134. *ppv = (IADsUser FAR *) this;
  135. }
  136. else if (IsEqualIID(iid, IID_IADsUser))
  137. {
  138. *ppv = (IADsUser FAR *) this;
  139. }
  140. else if (IsEqualIID(iid, IID_IADs))
  141. {
  142. *ppv = (IADsUser FAR *) this;
  143. }
  144. else if (IsEqualIID(iid, IID_IDispatch))
  145. {
  146. *ppv = (IADsUser FAR *) this;
  147. }
  148. else if (IsEqualIID(iid, IID_ISupportErrorInfo))
  149. {
  150. *ppv = (ISupportErrorInfo FAR *) this;
  151. }
  152. else if (IsEqualIID(iid, IID_IADsPropertyList))
  153. {
  154. *ppv = (IADsPropertyList FAR *) this;
  155. }
  156. else if (IsEqualIID(iid, IID_IDirectoryObject))
  157. {
  158. *ppv = (IDirectoryObject FAR *) this;
  159. }
  160. else if (IsEqualIID(iid, IID_IDirectorySearch))
  161. {
  162. *ppv = (IDirectorySearch FAR *) this;
  163. }
  164. else if (IsEqualIID(iid, IID_IDirectorySchemaMgmt))
  165. {
  166. *ppv = (IDirectorySchemaMgmt FAR *) this;
  167. }
  168. else
  169. {
  170. *ppv = NULL;
  171. return E_NOINTERFACE;
  172. }
  173. AddRef();
  174. return NOERROR;
  175. }
  176. HRESULT
  177. CNDSUser::AllocateUserObject(
  178. IADs * pADs,
  179. CCredentials& Credentials,
  180. CNDSUser ** ppUser
  181. )
  182. {
  183. CNDSUser FAR * pUser = NULL;
  184. CDispatchMgr FAR * pDispMgr = NULL;
  185. HRESULT hr = S_OK;
  186. IDirectoryObject * pDSObject = NULL;
  187. IDirectorySearch * pDSSearch = NULL;
  188. IDirectorySchemaMgmt * pDSSchemaMgmt = NULL;
  189. IADsPropertyList * pADsPropList = NULL;
  190. pUser = new CNDSUser();
  191. if (pUser == NULL) {
  192. hr = E_OUTOFMEMORY;
  193. }
  194. BAIL_ON_FAILURE(hr);
  195. pDispMgr = new CDispatchMgr;
  196. if (pDispMgr == NULL) {
  197. hr = E_OUTOFMEMORY;
  198. }
  199. BAIL_ON_FAILURE(hr);
  200. hr = LoadTypeInfoEntry(
  201. pDispMgr,
  202. LIBID_ADs,
  203. IID_IADsUser,
  204. (IADsUser *)pUser,
  205. DISPID_REGULAR
  206. );
  207. BAIL_ON_FAILURE(hr);
  208. hr = LoadTypeInfoEntry(
  209. pDispMgr,
  210. LIBID_ADs,
  211. IID_IADsPropertyList,
  212. (IADsPropertyList *)pUser,
  213. DISPID_VALUE
  214. );
  215. BAIL_ON_FAILURE(hr);
  216. hr = pADs->QueryInterface(
  217. IID_IDirectoryObject,
  218. (void **)&pDSObject
  219. );
  220. BAIL_ON_FAILURE(hr);
  221. pUser->_pDSObject = pDSObject;
  222. hr = pADs->QueryInterface(
  223. IID_IADsPropertyList,
  224. (void **)&pADsPropList
  225. );
  226. BAIL_ON_FAILURE(hr);
  227. pUser->_pADsPropList = pADsPropList;
  228. hr = pADs->QueryInterface(
  229. IID_IDirectorySearch,
  230. (void **)&pDSSearch
  231. );
  232. BAIL_ON_FAILURE(hr);
  233. pUser->_pDSSearch = pDSSearch;
  234. hr = pADs->QueryInterface(
  235. IID_IDirectorySchemaMgmt,
  236. (void **)&pDSSchemaMgmt
  237. );
  238. BAIL_ON_FAILURE(hr);
  239. pUser->_pDSSchemaMgmt = pDSSchemaMgmt;
  240. //
  241. // Store the pointer to the internal generic object
  242. // AND add ref this pointer
  243. //
  244. pUser->_pADs = pADs;
  245. pADs->AddRef();
  246. pUser->_Credentials = Credentials;
  247. pUser->_pDispMgr = pDispMgr;
  248. *ppUser = pUser;
  249. RRETURN(hr);
  250. error:
  251. delete pDispMgr;
  252. delete pUser;
  253. *ppUser = NULL;
  254. RRETURN(hr);
  255. }
  256. /* ISupportErrorInfo method */
  257. STDMETHODIMP
  258. CNDSUser::InterfaceSupportsErrorInfo(
  259. THIS_ REFIID riid
  260. )
  261. {
  262. if (IsEqualIID(riid, IID_IADs) ||
  263. IsEqualIID(riid, IID_IADsUser) ||
  264. IsEqualIID(riid, IID_IADsPropertyList)) {
  265. RRETURN(S_OK);
  266. } else {
  267. RRETURN(S_FALSE);
  268. }
  269. }