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.

177 lines
4.5 KiB

  1. /*++
  2. Copyright (c) 1989-1997 Microsoft Corporation
  3. Module Name:
  4. userkey.c
  5. Abstract:
  6. Implentation of the functions that get and generate user session keys
  7. RtlCalculateUserSessionKeyLm
  8. RtlCalculateUserSessionKeyNt
  9. Author:
  10. David Chalmers (Davidc) 10-21-91
  11. Revision History:
  12. Adam Barr (AdamBa) 12-15-97
  13. Modified from private\security\lsa\crypt\dll
  14. --*/
  15. #include <rdrssp.h>
  16. //
  17. // Define this if you want to know all about user session keys
  18. //
  19. // #define DEBUG_USER_SESSION_KEYS
  20. //
  21. // Define the user session key that represents an error.
  22. // This value will be generated by other parts of the system on failure.
  23. // We will check for it in our query code and return an error if it's found.
  24. //
  25. USER_SESSION_KEY ErrorSessionKey = { 0, 0, 0, 0, 0, 0, 0, 0,
  26. 0, 0, 0, 0, 0, 0, 0, 0
  27. };
  28. NTSTATUS
  29. RtlCalculateUserSessionKeyLm(
  30. IN PLM_RESPONSE LmResponse,
  31. IN PLM_OWF_PASSWORD LmOwfPassword,
  32. OUT PUSER_SESSION_KEY UserSessionKey)
  33. /*++
  34. Routine Description:
  35. Takes the passed Response and OwfPassword and generates a UserSessionKey.
  36. The current implementation takes the one-way-function of the OwfPassword
  37. and returns this as the key.
  38. Arguments:
  39. LmResponse - The response sent during session setup.
  40. LmOwfPassword - The hashed version of the user's password.
  41. Return Values:
  42. STATUS_SUCCESS - The function was completed successfully.
  43. The UserSessionKey is in UserSessionKey.
  44. STATUS_UNSUCCESSFUL - Something failed. The UserSessionKey is undefined.
  45. --*/
  46. {
  47. NTSTATUS Status;
  48. NT_PASSWORD NtPassword;
  49. //
  50. // Make the Owf password look like an NT password
  51. //
  52. NtPassword.Buffer = (PWSTR)LmOwfPassword; // We can do this cast because we
  53. // know the OWF routine treats this
  54. // pointer as a byte pointer.
  55. NtPassword.Length = sizeof(*LmOwfPassword);
  56. NtPassword.MaximumLength = sizeof(*LmOwfPassword);
  57. //
  58. // Calculate the OWF of the OwfPassword
  59. //
  60. ASSERT(sizeof(NT_OWF_PASSWORD) == sizeof(*UserSessionKey));
  61. Status = RtlCalculateNtOwfPassword( &NtPassword,
  62. (PNT_OWF_PASSWORD)UserSessionKey
  63. );
  64. if (!NT_SUCCESS(Status)) {
  65. KdPrint(("RtlCalculateUserSessionKeyLm : OWF calculation failed, status = 0x%lx\n", Status));
  66. return(Status);
  67. }
  68. //
  69. // Check if we've generated the error session key
  70. //
  71. if (RtlCompareMemory(UserSessionKey, &ErrorSessionKey,
  72. sizeof(*UserSessionKey)) == sizeof(*UserSessionKey)) {
  73. #ifdef DEBUG_USER_SESSION_KEYS
  74. KdPrint(("RtlCalculateSessionKeyLm - generated error session key, modifying it\n"));
  75. #endif
  76. //
  77. // Move away from the error session key
  78. //
  79. UserSessionKey->data[0].data[0] ++;
  80. ASSERT(RtlCompareMemory(UserSessionKey, &ErrorSessionKey,
  81. sizeof(*UserSessionKey)) != sizeof(*UserSessionKey));
  82. }
  83. #ifdef DEBUG_USER_SESSION_KEYS
  84. KdPrint(("RtlCalculateUserSessionKeyLm : Key = 0x%lx : %lx : %lx : %lx\n",
  85. ((PULONG)UserSessionKey)[0], ((PULONG)UserSessionKey)[1],
  86. ((PULONG)UserSessionKey)[2], ((PULONG)UserSessionKey)[3]));
  87. #endif
  88. return(STATUS_SUCCESS);
  89. UNREFERENCED_PARAMETER(LmResponse);
  90. }
  91. NTSTATUS
  92. RtlCalculateUserSessionKeyNt(
  93. IN PNT_RESPONSE NtResponse,
  94. IN PNT_OWF_PASSWORD NtOwfPassword,
  95. OUT PUSER_SESSION_KEY UserSessionKey)
  96. /*++
  97. Routine Description:
  98. Takes the passed Response and OwfPassword and generates a UserSessionKey.
  99. Arguments:
  100. NtResponse - The response sent during session setup.
  101. NtOwfPassword - The hashed version of the user's password.
  102. Return Values:
  103. STATUS_SUCCESS - The function was completed successfully.
  104. The UserSessionKey is in UserSessionKey.
  105. STATUS_UNSUCCESSFUL - Something failed. The UserSessionKey is undefined.
  106. --*/
  107. {
  108. // Just call the LM version
  109. ASSERT(sizeof(NT_RESPONSE) == sizeof(LM_RESPONSE));
  110. ASSERT(sizeof(NT_OWF_PASSWORD) == sizeof(LM_OWF_PASSWORD));
  111. return(RtlCalculateUserSessionKeyLm((PLM_RESPONSE)NtResponse,
  112. (PLM_OWF_PASSWORD)NtOwfPassword,
  113. UserSessionKey));
  114. }