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.

413 lines
9.0 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1997.
  5. //
  6. // File: usermode.c
  7. //
  8. // Contents: User mode entry points for test package
  9. //
  10. // Classes:
  11. //
  12. // Functions:
  13. //
  14. // History: 2-21-97 RichardW Created
  15. //
  16. //----------------------------------------------------------------------------
  17. #include "xtcbpkg.h"
  18. PSECPKG_DLL_FUNCTIONS UserTable ;
  19. SECPKG_USER_FUNCTION_TABLE XtcbUserTable =
  20. {
  21. XtcbInstanceInit,
  22. XtcbInitUserModeContext,
  23. XtcbMakeSignature,
  24. XtcbVerifySignature,
  25. XtcbSealMessage,
  26. XtcbUnsealMessage,
  27. XtcbGetContextToken,
  28. XtcbQueryContextAttributes,
  29. XtcbCompleteAuthToken,
  30. XtcbDeleteUserModeContext
  31. };
  32. NTSTATUS
  33. SEC_ENTRY
  34. SpUserModeInitialize(
  35. IN ULONG LsaVersion,
  36. OUT PULONG PackageVersion,
  37. OUT PSECPKG_USER_FUNCTION_TABLE * UserFunctionTable,
  38. OUT PULONG pcTables)
  39. {
  40. if (LsaVersion != SECPKG_INTERFACE_VERSION)
  41. {
  42. DebugLog((DEB_ERROR,"Invalid LSA version: %d\n", LsaVersion));
  43. return(STATUS_INVALID_PARAMETER);
  44. }
  45. *PackageVersion = SECPKG_INTERFACE_VERSION ;
  46. *UserFunctionTable = &XtcbUserTable;
  47. *pcTables = 1;
  48. return( STATUS_SUCCESS );
  49. }
  50. NTSTATUS NTAPI
  51. XtcbInstanceInit(
  52. IN ULONG Version,
  53. IN PSECPKG_DLL_FUNCTIONS DllFunctionTable,
  54. OUT PVOID * UserFunctionTable
  55. )
  56. {
  57. NTSTATUS Status = STATUS_SUCCESS;
  58. XtcbUserContextInit();
  59. UserTable = DllFunctionTable ;
  60. return(Status);
  61. }
  62. //+-------------------------------------------------------------------------
  63. //
  64. // Function: XtcbDeleteUserModeContext
  65. //
  66. // Synopsis: Deletes a user mode context by unlinking it and then
  67. // dereferencing it.
  68. //
  69. // Effects:
  70. //
  71. // Arguments: ContextHandle - Lsa context handle of the context to delete
  72. //
  73. // Requires:
  74. //
  75. // Returns: STATUS_SUCCESS on success, STATUS_INVALID_HANDLE if the
  76. // context can't be located
  77. //
  78. // Notes:
  79. //
  80. //
  81. //--------------------------------------------------------------------------
  82. NTSTATUS NTAPI
  83. XtcbDeleteUserModeContext(
  84. IN LSA_SEC_HANDLE ContextHandle
  85. )
  86. {
  87. XtcbDeleteUserContext( ContextHandle );
  88. return( SEC_E_OK );
  89. }
  90. //+-------------------------------------------------------------------------
  91. //
  92. // Function: XtcbInitUserModeContext
  93. //
  94. // Synopsis: Creates a user-mode context from a packed LSA mode context
  95. //
  96. // Effects:
  97. //
  98. // Arguments: ContextHandle - Lsa mode context handle for the context
  99. // PackedContext - A marshalled buffer containing the LSA
  100. // mode context.
  101. //
  102. // Requires:
  103. //
  104. // Returns: STATUS_SUCCESS or STATUS_INSUFFICIENT_RESOURCES
  105. //
  106. // Notes:
  107. //
  108. //
  109. //--------------------------------------------------------------------------
  110. NTSTATUS NTAPI
  111. XtcbInitUserModeContext(
  112. IN LSA_SEC_HANDLE ContextHandle,
  113. IN PSecBuffer PackedContext
  114. )
  115. {
  116. SECURITY_STATUS scRet = SEC_E_INVALID_HANDLE ;
  117. scRet = XtcbAddUserContext( ContextHandle, PackedContext );
  118. if ( NT_SUCCESS( scRet ) )
  119. {
  120. FreeContextBuffer( PackedContext->pvBuffer );
  121. }
  122. return( scRet );
  123. }
  124. //+-------------------------------------------------------------------------
  125. //
  126. // Function: XtcbMakeSignature
  127. //
  128. // Synopsis: Signs a message buffer by calculatinga checksum over all
  129. // the non-read only data buffers and encrypting the checksum
  130. // along with a nonce.
  131. //
  132. // Effects:
  133. //
  134. // Arguments: ContextHandle - Handle of the context to use to sign the
  135. // message.
  136. // QualityOfProtection - Unused flags.
  137. // MessageBuffers - Contains an array of buffers to sign and
  138. // to store the signature.
  139. // MessageSequenceNumber - Sequence number for this message,
  140. // only used in datagram cases.
  141. //
  142. // Requires: STATUS_INVALID_HANDLE - the context could not be found or
  143. // was not configured for message integrity.
  144. // STATUS_INVALID_PARAMETER - the signature buffer could not
  145. // be found.
  146. // STATUS_BUFFER_TOO_SMALL - the signature buffer is too small
  147. // to hold the signature
  148. //
  149. // Returns:
  150. //
  151. // Notes:
  152. //
  153. //
  154. //--------------------------------------------------------------------------
  155. NTSTATUS NTAPI
  156. XtcbMakeSignature(
  157. IN LSA_SEC_HANDLE ContextHandle,
  158. IN ULONG QualityOfProtection,
  159. IN PSecBufferDesc MessageBuffers,
  160. IN ULONG MessageSequenceNumber
  161. )
  162. {
  163. return( SEC_E_UNSUPPORTED_FUNCTION );
  164. }
  165. //+-------------------------------------------------------------------------
  166. //
  167. // Function: XtcbVerifySignature
  168. //
  169. // Synopsis: Verifies a signed message buffer by calculating a checksum over all
  170. // the non-read only data buffers and encrypting the checksum
  171. // along with a nonce.
  172. //
  173. // Effects:
  174. //
  175. // Arguments: ContextHandle - Handle of the context to use to sign the
  176. // message.
  177. // MessageBuffers - Contains an array of signed buffers and
  178. // a signature buffer.
  179. // MessageSequenceNumber - Sequence number for this message,
  180. // only used in datagram cases.
  181. // QualityOfProtection - Unused flags.
  182. //
  183. // Requires: STATUS_INVALID_HANDLE - the context could not be found or
  184. // was not configured for message integrity.
  185. // STATUS_INVALID_PARAMETER - the signature buffer could not
  186. // be found or was too small.
  187. //
  188. // Returns:
  189. //
  190. // Notes:
  191. //
  192. //
  193. //--------------------------------------------------------------------------
  194. NTSTATUS NTAPI
  195. XtcbVerifySignature(
  196. IN LSA_SEC_HANDLE ContextHandle,
  197. IN PSecBufferDesc MessageBuffers,
  198. IN ULONG MessageSequenceNumber,
  199. OUT PULONG QualityOfProtection
  200. )
  201. {
  202. return( SEC_E_UNSUPPORTED_FUNCTION );
  203. }
  204. NTSTATUS NTAPI
  205. XtcbSealMessage(
  206. IN LSA_SEC_HANDLE ContextHandle,
  207. IN ULONG QualityOfProtection,
  208. IN PSecBufferDesc pMessage,
  209. IN ULONG MessageSequenceNumber
  210. )
  211. {
  212. return( SEC_E_CONTEXT_EXPIRED );
  213. }
  214. NTSTATUS NTAPI
  215. XtcbUnsealMessage(
  216. IN LSA_SEC_HANDLE ContextHandle,
  217. IN PSecBufferDesc pMessage,
  218. IN ULONG MessageSequenceNumber,
  219. OUT PULONG QualityOfProtection
  220. )
  221. {
  222. // Output Buffer Types
  223. return( SEC_E_CONTEXT_EXPIRED );
  224. }
  225. //+-------------------------------------------------------------------------
  226. //
  227. // Function: SpGetContextToken
  228. //
  229. // Synopsis: returns a pointer to the token for a server-side context
  230. //
  231. // Effects:
  232. //
  233. // Arguments:
  234. //
  235. // Requires:
  236. //
  237. // Returns:
  238. //
  239. // Notes:
  240. //
  241. //
  242. //--------------------------------------------------------------------------
  243. NTSTATUS NTAPI
  244. XtcbGetContextToken(
  245. IN LSA_SEC_HANDLE ContextHandle,
  246. OUT PHANDLE ImpersonationToken
  247. )
  248. {
  249. PXTCB_USER_CONTEXT Context ;
  250. Context = XtcbFindUserContext( ContextHandle );
  251. if ( Context )
  252. {
  253. *ImpersonationToken = Context->Token ;
  254. return SEC_E_OK ;
  255. }
  256. else
  257. {
  258. return SEC_E_INVALID_HANDLE ;
  259. }
  260. }
  261. //+-------------------------------------------------------------------------
  262. //
  263. // Function: SpQueryContextAttributes
  264. //
  265. // Synopsis: Querys attributes of the specified context
  266. //
  267. // Effects:
  268. //
  269. // Arguments:
  270. //
  271. // Requires:
  272. //
  273. // Returns:
  274. //
  275. // Notes:
  276. //
  277. //
  278. //--------------------------------------------------------------------------
  279. NTSTATUS NTAPI
  280. XtcbQueryContextAttributes(
  281. IN LSA_SEC_HANDLE ContextHandle,
  282. IN ULONG ContextAttribute,
  283. IN OUT PVOID pBuffer
  284. )
  285. {
  286. PXTCB_USER_CONTEXT Context ;
  287. PSecPkgContext_Sizes Sizes ;
  288. PSecPkgContext_NamesW Names ;
  289. PSecPkgContext_Lifespan Lifespan ;
  290. PSecPkgContext_DceInfo DceInfo ;
  291. PSecPkgContext_Authority Authority ;
  292. SECURITY_STATUS Status ;
  293. int len ;
  294. Context = XtcbFindUserContext( ContextHandle );
  295. if ( !Context )
  296. {
  297. return SEC_E_INVALID_HANDLE ;
  298. }
  299. switch ( ContextAttribute )
  300. {
  301. case SECPKG_ATTR_SIZES:
  302. Sizes = (PSecPkgContext_Sizes) pBuffer ;
  303. ZeroMemory( Sizes, sizeof( SecPkgContext_Sizes ) );
  304. Status = SEC_E_OK ;
  305. break;
  306. case SECPKG_ATTR_NAMES:
  307. Status = SEC_E_OK ;
  308. break;
  309. case SECPKG_ATTR_LIFESPAN:
  310. Status = SEC_E_OK ;
  311. break;
  312. default:
  313. Status = SEC_E_UNSUPPORTED_FUNCTION ;
  314. }
  315. return Status ;
  316. }
  317. //+-------------------------------------------------------------------------
  318. //
  319. // Function: SpCompleteAuthToken
  320. //
  321. // Synopsis: Completes a context (in Kerberos case, does nothing)
  322. //
  323. // Effects:
  324. //
  325. // Arguments:
  326. //
  327. // Requires:
  328. //
  329. // Returns:
  330. //
  331. // Notes:
  332. //
  333. //
  334. //--------------------------------------------------------------------------
  335. NTSTATUS
  336. NTAPI
  337. XtcbCompleteAuthToken(
  338. IN LSA_SEC_HANDLE ContextHandle,
  339. IN PSecBufferDesc InputBuffer
  340. )
  341. {
  342. return(STATUS_SUCCESS);
  343. }