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.

236 lines
4.9 KiB

  1. //+-----------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (c) Microsoft Corporation 1992 - 1997
  6. //
  7. // File: ntlm.c
  8. //
  9. // Contents: ntlm kernel-mode functions
  10. //
  11. //
  12. // History: 3/17/94 MikeSw Created
  13. // 12/15/97 AdamBa Modified from private\lsa\client\ssp
  14. //
  15. //------------------------------------------------------------------------
  16. #include <rdrssp.h>
  17. KSPIN_LOCK NtlmLock;
  18. PKernelContext pNtlmList;
  19. BOOLEAN NtlmInitialized = FALSE;
  20. //+-------------------------------------------------------------------------
  21. //
  22. // Function: NtlmInitialize
  23. //
  24. // Synopsis: initializes the NTLM package functions
  25. //
  26. // Effects:
  27. //
  28. // Arguments:
  29. //
  30. // Requires:
  31. //
  32. // Returns:
  33. //
  34. // Notes:
  35. //
  36. //
  37. //--------------------------------------------------------------------------
  38. SECURITY_STATUS SEC_ENTRY
  39. NtlmInitialize(void)
  40. {
  41. KeInitializeSpinLock(&NtlmLock);
  42. pNtlmList = NULL;
  43. return(STATUS_SUCCESS);
  44. }
  45. #if 0
  46. //+-------------------------------------------------------------------------
  47. //
  48. // Function: NtlmGetToken
  49. //
  50. // Synopsis: returns the token from a context
  51. //
  52. // Effects:
  53. //
  54. // Arguments:
  55. //
  56. // Requires:
  57. //
  58. // Returns:
  59. //
  60. // Notes:
  61. //
  62. //--------------------------------------------------------------------------
  63. SECURITY_STATUS SEC_ENTRY
  64. NtlmGetToken( ULONG ulContext,
  65. PHANDLE phToken,
  66. PACCESS_TOKEN * pAccessToken)
  67. {
  68. PKernelContext pContext;
  69. NTSTATUS Status;
  70. PAGED_CODE();
  71. pContext = (PKernelContext) ulContext;
  72. if (pContext == NULL)
  73. {
  74. DebugLog((DEB_ERROR,"Invalid handle 0x%x\n", ulContext));
  75. return(SEC_E_INVALID_HANDLE);
  76. }
  77. // Now, after all that checking, let's actually try and set the
  78. // thread impersonation token.
  79. if (phToken != NULL)
  80. {
  81. *phToken = pContext->TokenHandle;
  82. }
  83. if (pAccessToken != NULL)
  84. {
  85. if (pContext->TokenHandle != NULL)
  86. {
  87. if (pContext->AccessToken == NULL)
  88. {
  89. Status = ObReferenceObjectByHandle(
  90. pContext->TokenHandle,
  91. TOKEN_IMPERSONATE,
  92. NULL,
  93. KeGetPreviousMode(),
  94. (PVOID *) &pContext->AccessToken,
  95. NULL // no handle information
  96. );
  97. if (!NT_SUCCESS(Status))
  98. {
  99. return(Status);
  100. }
  101. }
  102. }
  103. *pAccessToken = pContext->AccessToken;
  104. }
  105. return(STATUS_SUCCESS);
  106. }
  107. #endif
  108. //+-------------------------------------------------------------------------
  109. //
  110. // Function: NtlmInitKernelContext
  111. //
  112. // Synopsis: Initializes a kernel context with the session key
  113. // and possible token handle.
  114. //
  115. // Effects:
  116. //
  117. // Arguments:
  118. //
  119. // Requires:
  120. //
  121. // Returns:
  122. //
  123. // Notes:
  124. //
  125. //
  126. //--------------------------------------------------------------------------
  127. SECURITY_STATUS
  128. NtlmInitKernelContext(
  129. IN PUCHAR UserSessionKey,
  130. IN PUCHAR LanmanSessionKey,
  131. IN HANDLE TokenHandle,
  132. OUT PCtxtHandle ContextHandle
  133. )
  134. {
  135. PKernelContext pContext;
  136. KIRQL OldIrql;
  137. if (!NtlmInitialized) {
  138. NtlmInitialize();
  139. NtlmInitialized = TRUE;
  140. }
  141. pContext = AllocContextRec();
  142. if (!pContext)
  143. {
  144. return(SEC_E_INSUFFICIENT_MEMORY);
  145. }
  146. RtlCopyMemory(
  147. pContext->UserSessionKey,
  148. UserSessionKey,
  149. MSV1_0_USER_SESSION_KEY_LENGTH
  150. );
  151. RtlCopyMemory(
  152. pContext->LanmanSessionKey,
  153. LanmanSessionKey,
  154. MSV1_0_LANMAN_SESSION_KEY_LENGTH
  155. );
  156. pContext->TokenHandle = TokenHandle;
  157. pContext->AccessToken = NULL;
  158. pContext->pPrev = NULL;
  159. ContextHandle->dwLower = (ULONG_PTR) pContext;
  160. ContextHandle->dwUpper = 0;
  161. //
  162. // Add it to the client record
  163. //
  164. AddKernelContext(&pNtlmList, &NtlmLock, pContext);
  165. return(STATUS_SUCCESS);
  166. }
  167. //+-------------------------------------------------------------------------
  168. //
  169. // Function: NtlmDeleteKernelContext
  170. //
  171. // Synopsis: Deletes a kernel context from the list of contexts
  172. //
  173. // Effects:
  174. //
  175. // Arguments:
  176. //
  177. // Requires:
  178. //
  179. // Returns:
  180. //
  181. // Notes:
  182. //
  183. //
  184. //--------------------------------------------------------------------------
  185. SECURITY_STATUS
  186. NtlmDeleteKernelContext( PCtxtHandle ContextHandle)
  187. {
  188. SECURITY_STATUS scRet;
  189. scRet = DeleteKernelContext(
  190. &pNtlmList,
  191. &NtlmLock,
  192. (PKernelContext) ContextHandle->dwLower );
  193. return(scRet);
  194. }