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.

286 lines
7.1 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. _pDSAttrMgmt(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(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 (_pDSAttrMgmt) {
  119. _pDSAttrMgmt->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_IADsPropertyList))
  149. {
  150. *ppv = (IADsPropertyList FAR *) this;
  151. }
  152. else if (IsEqualIID(iid, IID_IDirectoryObject))
  153. {
  154. *ppv = (IDirectoryObject FAR *) this;
  155. }
  156. else if (IsEqualIID(iid, IID_IDirectorySearch))
  157. {
  158. *ppv = (IDirectorySearch FAR *) this;
  159. }
  160. else if (IsEqualIID(iid, IID_IDirectorySchemaMgmt))
  161. {
  162. *ppv = (IDirectorySchemaMgmt FAR *) this;
  163. }
  164. else
  165. {
  166. *ppv = NULL;
  167. return E_NOINTERFACE;
  168. }
  169. AddRef();
  170. return NOERROR;
  171. }
  172. HRESULT
  173. CNDSUser::AllocateUserObject(
  174. IADs * pADs,
  175. CCredentials& Credentials,
  176. CNDSUser ** ppUser
  177. )
  178. {
  179. CNDSUser FAR * pUser = NULL;
  180. CDispatchMgr FAR * pDispMgr = NULL;
  181. HRESULT hr = S_OK;
  182. IDirectoryObject * pDSObject = NULL;
  183. IDirectorySearch * pDSSearch = NULL;
  184. IDirectorySchemaMgmt * pDSAttrMgmt = NULL;
  185. IADsPropertyList * pADsPropList = NULL;
  186. pUser = new CNDSUser();
  187. if (pUser == NULL) {
  188. hr = E_OUTOFMEMORY;
  189. }
  190. BAIL_ON_FAILURE(hr);
  191. pDispMgr = new CDispatchMgr;
  192. if (pDispMgr == NULL) {
  193. hr = E_OUTOFMEMORY;
  194. }
  195. BAIL_ON_FAILURE(hr);
  196. hr = LoadTypeInfoEntry(
  197. pDispMgr,
  198. LIBID_ADs,
  199. IID_IADsUser,
  200. (IADsUser *)pUser,
  201. DISPID_REGULAR
  202. );
  203. BAIL_ON_FAILURE(hr);
  204. hr = pADs->QueryInterface(
  205. IID_IDirectoryObject,
  206. (void **)&pDSObject
  207. );
  208. BAIL_ON_FAILURE(hr);
  209. pUser->_pDSObject = pDSObject;
  210. hr = pADs->QueryInterface(
  211. IID_IADsPropertyList,
  212. (void **)&pADsPropList
  213. );
  214. BAIL_ON_FAILURE(hr);
  215. pUser->_pADsPropList = pADsPropList;
  216. hr = pADs->QueryInterface(
  217. IID_IDirectorySearch,
  218. (void **)&pDSSearch
  219. );
  220. BAIL_ON_FAILURE(hr);
  221. pUser->_pDSSearch = pDSSearch;
  222. hr = pADs->QueryInterface(
  223. IID_IDirectorySchemaMgmt,
  224. (void **)&pDSAttrMgmt
  225. );
  226. BAIL_ON_FAILURE(hr);
  227. pUser->_pDSAttrMgmt = pDSAttrMgmt;
  228. //
  229. // Store the pointer to the internal generic object
  230. // AND add ref this pointer
  231. //
  232. pUser->_pADs = pADs;
  233. pADs->AddRef();
  234. pUser->_Credentials = Credentials;
  235. pUser->_pDispMgr = pDispMgr;
  236. *ppUser = pUser;
  237. RRETURN(hr);
  238. error:
  239. delete pDispMgr;
  240. delete pUser;
  241. *ppUser = NULL;
  242. RRETURN(hr);
  243. }