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.

185 lines
4.0 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. goto ServerGetSessionKeyError;
  64. }
  65. OutputSessionKey->Length = OutputSessionKey->MaximumLength =
  66. OutputSessionKeyBufferLength;
  67. ServerGetSessionKeyFinish:
  68. *SessionKey = OutputSessionKey;
  69. return(Status);
  70. ServerGetSessionKeyError:
  71. goto ServerGetSessionKeyFinish;
  72. }
  73. NTSTATUS
  74. LsapCrServerGetSessionKeySafe(
  75. IN LSAPR_HANDLE ObjectHandle,
  76. IN LSAP_DB_OBJECT_TYPE_ID ObjectTypeId,
  77. OUT PLSAP_CR_CIPHER_KEY *SessionKey
  78. )
  79. /*++
  80. Routine Description:
  81. This function obtains the Session Key, allocates an Cipher Key
  82. structure and returns the key.
  83. Same a LsapCrServerGetSessionKey except the ObjectHandle is verified
  84. the LsapCrServerGetSessionKey version of this routine shouldn't exist.
  85. That routine calls down into the kernel. Such a call can call back up to the
  86. LSA and lock locks. Since LsapCrServerGetSessionKey doesn't validate the
  87. handle, the caller must have done that. All such callers lock LSA locks.
  88. That's bound to be a deadlock.
  89. Arguments:
  90. ObjectHandle - Handle from an LsaOpen<ObjectType> call.
  91. ObjectTypeId - Type of ObjectHandle.
  92. SessionKey - Receives a pointer to a structure containing the
  93. Session Key in which the memory has been allocated via
  94. MIDL_user_allocate().
  95. Return Value:
  96. NTSTATUS - Standard Nt Result Code
  97. STATUS_INSUFFICIENT_RESOURCES - Insufficient system resources
  98. (e.g memory) to complete the call.
  99. --*/
  100. {
  101. NTSTATUS Status;
  102. //
  103. // Verify that the handle is valid.
  104. //
  105. Status = LsapDbVerifyHandle( ObjectHandle, 0, ObjectTypeId, TRUE );
  106. if (NT_SUCCESS(Status)) {
  107. //
  108. // Get the session key.
  109. //
  110. Status = LsapCrServerGetSessionKey( ObjectHandle,
  111. SessionKey );
  112. //
  113. // Dereference the handle
  114. //
  115. (VOID) LsapDbDereferenceHandle( ObjectHandle );
  116. }
  117. return Status;
  118. }