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.

189 lines
4.3 KiB

  1. /*++
  2. Copyright (c) 1991 Microsoft Corporation
  3. Module Name:
  4. crserver.c
  5. Abstract:
  6. Local Security Authority - Server Cipher Routines
  7. These routines interface the LSA server side with the Cipher
  8. Routines. They perform RPC-style memory allocation.
  9. Author:
  10. Scott Birrell (ScottBi) December 13, 1991
  11. Environment:
  12. Revision History:
  13. --*/
  14. #include <lsapch2.h>
  15. NTSTATUS
  16. LsapCrServerGetSessionKey(
  17. IN LSAPR_HANDLE ObjectHandle,
  18. OUT PLSAP_CR_CIPHER_KEY *SessionKey
  19. )
  20. /*++
  21. Routine Description:
  22. This function obtains the Session Key, allocates an Cipher Key
  23. structure and returns the key.
  24. Arguments:
  25. ObjectHandle - Handle from an LsaOpen<ObjectType> call.
  26. SessionKey - Receives a pointer to a structure containing the
  27. Session Key in which the memory has been allocated via
  28. MIDL_user_allocate().
  29. Return Value:
  30. NTSTATUS - Standard Nt Result Code
  31. STATUS_INSUFFICIENT_RESOURCES - Insufficient system resources
  32. (e.g memory) to complete the call.
  33. --*/
  34. {
  35. NTSTATUS Status;
  36. PLSAP_CR_CIPHER_KEY OutputSessionKey = NULL;
  37. ULONG OutputSessionKeyBufferLength;
  38. //
  39. // Allocate memory for the Session Key buffer and LSAP_CR_CIPHER_KEY
  40. // structure.
  41. //
  42. OutputSessionKeyBufferLength = sizeof (USER_SESSION_KEY);
  43. OutputSessionKey = MIDL_user_allocate(
  44. OutputSessionKeyBufferLength +
  45. sizeof (LSAP_CR_CIPHER_KEY)
  46. );
  47. if (OutputSessionKey == NULL) {
  48. Status = STATUS_INSUFFICIENT_RESOURCES;
  49. goto ServerGetSessionKeyError;
  50. }
  51. //
  52. // Fill in the Cipher key structure, making the buffer point to
  53. // just beyond the header.
  54. //
  55. OutputSessionKey->Length = OutputSessionKeyBufferLength;
  56. OutputSessionKey->MaximumLength = OutputSessionKeyBufferLength;
  57. OutputSessionKey->Buffer = (PUCHAR) (OutputSessionKey + 1);
  58. Status = RtlGetUserSessionKeyServer(
  59. ObjectHandle,
  60. (PUSER_SESSION_KEY) OutputSessionKey->Buffer
  61. );
  62. if (!NT_SUCCESS(Status)) {
  63. //
  64. // It is better to clear here.
  65. //
  66. MIDL_user_free(OutputSessionKey);
  67. OutputSessionKey = NULL;
  68. goto ServerGetSessionKeyError;
  69. }
  70. ServerGetSessionKeyFinish:
  71. *SessionKey = OutputSessionKey;
  72. return(Status);
  73. ServerGetSessionKeyError:
  74. goto ServerGetSessionKeyFinish;
  75. }
  76. NTSTATUS
  77. LsapCrServerGetSessionKeySafe(
  78. IN LSAPR_HANDLE ObjectHandle,
  79. IN LSAP_DB_OBJECT_TYPE_ID ObjectTypeId,
  80. OUT PLSAP_CR_CIPHER_KEY *SessionKey
  81. )
  82. /*++
  83. Routine Description:
  84. This function obtains the Session Key, allocates an Cipher Key
  85. structure and returns the key.
  86. Same a LsapCrServerGetSessionKey except the ObjectHandle is verified
  87. the LsapCrServerGetSessionKey version of this routine shouldn't exist.
  88. That routine calls down into the kernel. Such a call can call back up to the
  89. LSA and lock locks. Since LsapCrServerGetSessionKey doesn't validate the
  90. handle, the caller must have done that. All such callers lock LSA locks.
  91. That's bound to be a deadlock.
  92. Arguments:
  93. ObjectHandle - Handle from an LsaOpen<ObjectType> call.
  94. ObjectTypeId - Type of ObjectHandle.
  95. SessionKey - Receives a pointer to a structure containing the
  96. Session Key in which the memory has been allocated via
  97. MIDL_user_allocate().
  98. Return Value:
  99. NTSTATUS - Standard Nt Result Code
  100. STATUS_INSUFFICIENT_RESOURCES - Insufficient system resources
  101. (e.g memory) to complete the call.
  102. --*/
  103. {
  104. NTSTATUS Status;
  105. //
  106. // Verify that the handle is valid.
  107. //
  108. Status = LsapDbVerifyHandle( ObjectHandle, 0, ObjectTypeId, TRUE );
  109. if (NT_SUCCESS(Status)) {
  110. //
  111. // Get the session key.
  112. //
  113. Status = LsapCrServerGetSessionKey( ObjectHandle,
  114. SessionKey );
  115. //
  116. // Dereference the handle
  117. //
  118. (VOID) LsapDbDereferenceHandle( ObjectHandle, TRUE );
  119. }
  120. return Status;
  121. }