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.

310 lines
8.0 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1997.
  5. //
  6. // File: credapi.c
  7. //
  8. // Contents: Credential related API
  9. //
  10. // Classes:
  11. //
  12. // Functions:
  13. //
  14. // History: 2-24-97 RichardW Created
  15. //
  16. //----------------------------------------------------------------------------
  17. #include "xtcbpkg.h"
  18. //+---------------------------------------------------------------------------
  19. //
  20. // Function: XtcbAcceptCredentials
  21. //
  22. // Synopsis: Accept credentials stored during a prior logon session.
  23. //
  24. // Arguments: [LogonType] -- Type of logon
  25. // [UserName] -- name logged on with
  26. // [PrimaryCred] -- Primary credential data
  27. // [SupplementalCreds] -- supplemental credential data
  28. //
  29. // History: 2-19-97 RichardW Created
  30. //
  31. // Notes:
  32. //
  33. //----------------------------------------------------------------------------
  34. SECURITY_STATUS SEC_ENTRY
  35. XtcbAcceptCredentials(
  36. IN SECURITY_LOGON_TYPE LogonType,
  37. IN PUNICODE_STRING UserName,
  38. IN PSECPKG_PRIMARY_CRED PrimaryCred,
  39. IN PSECPKG_SUPPLEMENTAL_CRED SupplementalCreds)
  40. {
  41. PXTCB_CREDS Creds ;
  42. DebugLog(( DEB_TRACE_CALLS, "AcceptCredentials( %d, %ws, ...)\n",
  43. LogonType, UserName->Buffer ));
  44. Creds = XtcbCreateCreds( &PrimaryCred->LogonId );
  45. if ( Creds )
  46. {
  47. return SEC_E_OK ;
  48. }
  49. return SEC_E_INSUFFICIENT_MEMORY ;
  50. }
  51. //+---------------------------------------------------------------------------
  52. //
  53. // Function: XtcbAcquireCredentialsHandle
  54. //
  55. // Synopsis: Acquire a handle representing the user.
  56. //
  57. // Arguments: [psPrincipal] -- claimed name of user
  58. // [fCredentials] -- credential use
  59. // [pLogonID] -- logon id of the calling thread
  60. // [pvAuthData] -- provided auth data pointer (unmapped)
  61. // [pvGetKeyFn] -- function in calling process for key data
  62. // [pvGetKeyArgument] -- argument to be passed
  63. // [pdwHandle] -- returned handle
  64. // [ptsExpiry] -- expiration time
  65. //
  66. // History: 2-19-97 RichardW Created
  67. //
  68. // Notes:
  69. //
  70. //----------------------------------------------------------------------------
  71. SECURITY_STATUS SEC_ENTRY
  72. XtcbAcquireCredentialsHandle(
  73. PSECURITY_STRING psPrincipal,
  74. ULONG fCredentials,
  75. PLUID pLogonId,
  76. PVOID pvAuthData,
  77. PVOID pvGetKeyFn,
  78. PVOID pvGetKeyArgument,
  79. PLSA_SEC_HANDLE pCredHandle,
  80. PTimeStamp ptsExpiry)
  81. {
  82. PXTCB_CREDS Creds;
  83. PXTCB_CRED_HANDLE Handle ;
  84. SECPKG_CLIENT_INFO Info ;
  85. PSEC_WINNT_AUTH_IDENTITY AuthData ;
  86. DebugLog(( DEB_TRACE_CALLS, "AcquireCredentialsHandle(..., %x:%x, %x, ...)\n",
  87. pLogonId->HighPart, pLogonId->LowPart,
  88. pvAuthData ));
  89. Creds = NULL ;
  90. if ( pvAuthData == NULL )
  91. {
  92. if ( (pLogonId->LowPart == 0) && (pLogonId->HighPart == 0) )
  93. {
  94. LsaTable->GetClientInfo( &Info );
  95. *pLogonId = Info.LogonId ;
  96. }
  97. Creds = XtcbFindCreds( pLogonId, TRUE );
  98. if ( !Creds )
  99. {
  100. //
  101. // Time to create credentials for this user
  102. //
  103. Creds = XtcbCreateCreds( pLogonId );
  104. if ( !Creds )
  105. {
  106. return SEC_E_INSUFFICIENT_MEMORY ;
  107. }
  108. if ( Creds->Pac == NULL )
  109. {
  110. Creds->Pac = XtcbCreatePacForCaller();
  111. }
  112. }
  113. }
  114. else
  115. {
  116. return SEC_E_UNKNOWN_CREDENTIALS ;
  117. }
  118. Handle = XtcbAllocateCredHandle( Creds );
  119. XtcbDerefCreds( Creds );
  120. *pCredHandle = (LSA_SEC_HANDLE) Handle ;
  121. *ptsExpiry = XtcbNever ;
  122. if ( Handle )
  123. {
  124. Handle->Usage = fCredentials ;
  125. return SEC_E_OK ;
  126. }
  127. else
  128. {
  129. return SEC_E_INSUFFICIENT_MEMORY ;
  130. }
  131. }
  132. //+---------------------------------------------------------------------------
  133. //
  134. // Function: XtcbQueryCredentialsAttributes
  135. //
  136. // Synopsis: Return information about credentials
  137. //
  138. // Arguments: [dwCredHandle] -- Handle to check
  139. // [dwAttribute] -- attribute to return
  140. // [Buffer] -- Buffer to fill with attribute
  141. //
  142. // History: 2-20-97 RichardW Created
  143. //
  144. // Notes:
  145. //
  146. //----------------------------------------------------------------------------
  147. SECURITY_STATUS
  148. SEC_ENTRY
  149. XtcbQueryCredentialsAttributes(
  150. LSA_SEC_HANDLE CredHandle,
  151. ULONG dwAttribute,
  152. PVOID Buffer)
  153. {
  154. NTSTATUS Status ;
  155. PXTCB_CRED_HANDLE Handle ;
  156. SecPkgCredentials_NamesW Names;
  157. DebugLog(( DEB_TRACE_CALLS, "QueryCredentialsAttribute( %p, %d, ... )\n",
  158. CredHandle, dwAttribute ));
  159. Handle = (PXTCB_CRED_HANDLE) CredHandle ;
  160. #if DBG
  161. if ( Handle->Check != XTCB_CRED_HANDLE_CHECK )
  162. {
  163. return SEC_E_INVALID_HANDLE ;
  164. }
  165. #endif
  166. //
  167. // We only know about one credential attribute right now:
  168. //
  169. if ( dwAttribute != SECPKG_CRED_ATTR_NAMES )
  170. {
  171. return SEC_E_UNSUPPORTED_FUNCTION ;
  172. }
  173. Status = SEC_E_UNSUPPORTED_FUNCTION ;
  174. return Status ;
  175. }
  176. //+---------------------------------------------------------------------------
  177. //
  178. // Function: XtcbFreeCredentialsHandle
  179. //
  180. // Synopsis: Dereferences a credential handle from AcquireCredHandle
  181. //
  182. // Arguments: [dwHandle] --
  183. //
  184. // History: 2-20-97 RichardW Created
  185. //
  186. // Notes:
  187. //
  188. //----------------------------------------------------------------------------
  189. SECURITY_STATUS
  190. SEC_ENTRY
  191. XtcbFreeCredentialsHandle(
  192. LSA_SEC_HANDLE CredHandle
  193. )
  194. {
  195. PXTCB_CRED_HANDLE Handle ;
  196. DebugLog(( DEB_TRACE_CALLS, "FreeCredentialsHandle( %p )\n", CredHandle ));
  197. Handle = (PXTCB_CRED_HANDLE) CredHandle ;
  198. if ( Handle->Check == XTCB_CRED_HANDLE_CHECK )
  199. {
  200. XtcbDerefCredHandle( Handle );
  201. return SEC_E_OK ;
  202. }
  203. return( SEC_E_INVALID_HANDLE );
  204. }
  205. //+---------------------------------------------------------------------------
  206. //
  207. // Function: XtcbLogonTerminated
  208. //
  209. // Synopsis: Called when the logon session has terminated (all tokens closed)
  210. //
  211. // Arguments: [pLogonId] -- Logon session that has terminated
  212. //
  213. // History: 2-20-97 RichardW Created
  214. //
  215. // Notes:
  216. //
  217. //----------------------------------------------------------------------------
  218. VOID
  219. SEC_ENTRY
  220. XtcbLogonTerminated(PLUID pLogonId)
  221. {
  222. PXTCB_CREDS Creds ;
  223. DebugLog(( DEB_TRACE_CALLS, "LogonTerminated( %x:%x )\n",
  224. pLogonId->HighPart, pLogonId->LowPart ));
  225. Creds = XtcbFindCreds( pLogonId, FALSE );
  226. if ( Creds )
  227. {
  228. Creds->Flags |= XTCB_CRED_TERMINATED ;
  229. XtcbDerefCreds( Creds );
  230. }
  231. return;
  232. }
  233. //+---------------------------------------------------------------------------
  234. //
  235. // Function: XtcbGetUserInfo
  236. //
  237. // Synopsis: Return information about a user to the LSA
  238. //
  239. // Arguments: [pLogonId] --
  240. // [fFlags] --
  241. // [ppUserInfo] --
  242. //
  243. // History: 2-20-97 RichardW Created
  244. //
  245. // Notes:
  246. //
  247. //----------------------------------------------------------------------------
  248. SECURITY_STATUS
  249. SEC_ENTRY
  250. XtcbGetUserInfo( PLUID pLogonId,
  251. ULONG fFlags,
  252. PSecurityUserData * ppUserInfo)
  253. {
  254. PSecurityUserData pInfo ;
  255. PXTCB_CREDS Creds ;
  256. SECURITY_STATUS Status ;
  257. DebugLog(( DEB_TRACE_CALLS, "GetUserInfo( %x:%x, %x, ...)\n",
  258. pLogonId->HighPart, pLogonId->LowPart, fFlags ));
  259. return SEC_E_UNSUPPORTED_FUNCTION ;
  260. }