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.

253 lines
4.5 KiB

  1. /*++
  2. Copyright (c) 1993 Microsoft Corporation
  3. Module Name:
  4. context.c
  5. Abstract:
  6. SSP Context.
  7. Author:
  8. Cliff Van Dyke (CliffV) 29-Jun-1993
  9. Environment: User Mode
  10. Revision History:
  11. --*/
  12. #ifdef BLDR_KERNEL_RUNTIME
  13. #include <bootdefs.h>
  14. #endif
  15. #include <security.h>
  16. #include <ntlmsspi.h>
  17. #include <crypt.h>
  18. #include <cred.h>
  19. #include <context.h>
  20. #include <debug.h>
  21. #include <string.h>
  22. #include <memory.h>
  23. PSSP_CONTEXT
  24. SspContextReferenceContext(
  25. IN PCtxtHandle ContextHandle,
  26. IN BOOLEAN RemoveContext
  27. )
  28. /*++
  29. Routine Description:
  30. This routine references the Context if it is valid.
  31. The caller may optionally request that the Context be
  32. removed from the list of valid Contexts - preventing future
  33. requests from finding this Context.
  34. Arguments:
  35. ContextHandle - Points to the ContextHandle of the Context
  36. to be referenced.
  37. RemoveContext - This boolean value indicates whether the caller
  38. wants the Context to be removed from the list
  39. of Contexts. TRUE indicates the Context is to be removed.
  40. FALSE indicates the Context is not to be removed.
  41. Return Value:
  42. NULL - the Context was not found.
  43. Otherwise - returns a pointer to the referenced Context.
  44. --*/
  45. {
  46. PSSP_CONTEXT Context;
  47. //
  48. // Sanity check
  49. //
  50. if ( ContextHandle->dwLower != 0 ) {
  51. return NULL;
  52. }
  53. Context = (PSSP_CONTEXT) ContextHandle->dwUpper;
  54. SspPrint(( SSP_MISC, "StartTime=%lx Interval=%lx\n", Context->StartTime,
  55. Context->Interval));
  56. #if 0
  57. // timeout is broken, so don't check it
  58. if ( SspTimeHasElapsed( Context->StartTime,
  59. Context->Interval ) ) {
  60. SspPrint(( SSP_API, "Context 0x%lx has timed out.\n",
  61. ContextHandle->dwUpper ));
  62. return NULL;
  63. }
  64. #endif
  65. Context->References++;
  66. return Context;
  67. }
  68. void
  69. SspContextDereferenceContext(
  70. PSSP_CONTEXT Context
  71. )
  72. /*++
  73. Routine Description:
  74. This routine decrements the specified Context's reference count.
  75. If the reference count drops to zero, then the Context is deleted
  76. Arguments:
  77. Context - Points to the Context to be dereferenced.
  78. Return Value:
  79. None.
  80. --*/
  81. {
  82. //
  83. // Decrement the reference count
  84. //
  85. ASSERT( Context->References >= 1 );
  86. Context->References--;
  87. //
  88. // If the count dropped to zero, then run-down the Context
  89. //
  90. if (Context->References == 0) {
  91. if (Context->Credential != NULL) {
  92. SspCredentialDereferenceCredential(Context->Credential);
  93. Context->Credential = NULL;
  94. }
  95. SspPrint(( SSP_API_MORE, "Deleting Context 0x%lx\n",
  96. Context ));
  97. if (Context->Rc4Key != NULL)
  98. {
  99. SspFree(Context->Rc4Key);
  100. }
  101. SspFree( Context );
  102. }
  103. return;
  104. }
  105. PSSP_CONTEXT
  106. SspContextAllocateContext(
  107. )
  108. /*++
  109. Routine Description:
  110. This routine allocates the security context block and initializes it.
  111. Arguments:
  112. Return Value:
  113. NULL -- Not enough memory to allocate context.
  114. otherwise -- pointer to allocated and referenced context.
  115. --*/
  116. {
  117. PSSP_CONTEXT Context;
  118. //
  119. // Allocate a Context block and initialize it.
  120. //
  121. Context = (SSP_CONTEXT *) SspAlloc (sizeof(SSP_CONTEXT) );
  122. if ( Context == NULL ) {
  123. return NULL;
  124. }
  125. Context->References = 1;
  126. Context->NegotiateFlags = 0;
  127. Context->State = IdleState;
  128. //
  129. // Timeout this context.
  130. //
  131. Context->StartTime = SspTicks();
  132. Context->Interval = NTLMSSP_MAX_LIFETIME;
  133. Context->Rc4Key = NULL;
  134. SspPrint(( SSP_API_MORE, "Added Context 0x%lx\n", Context ));
  135. return Context;
  136. }
  137. TimeStamp
  138. SspContextGetTimeStamp(
  139. IN PSSP_CONTEXT Context,
  140. IN BOOLEAN GetExpirationTime
  141. )
  142. /*++
  143. Routine Description:
  144. Get the Start time or Expiration time for the specified context.
  145. Arguments:
  146. Context - Pointer to the context to query
  147. GetExpirationTime - If TRUE return the expiration time.
  148. Otherwise, return the start time for the context.
  149. Return Value:
  150. Returns the requested time as a local time.
  151. --*/
  152. {
  153. TimeStamp ReturnValue;
  154. if ( GetExpirationTime ) {
  155. if (Context->Interval == 0xffffffff) {
  156. ReturnValue.LowPart = 0xffffffff;
  157. } else {
  158. ReturnValue.LowPart = Context->StartTime + Context->Interval;
  159. }
  160. } else {
  161. ReturnValue.LowPart = Context->StartTime;
  162. }
  163. ReturnValue.HighPart = 0;
  164. return ReturnValue;
  165. }