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.

256 lines
4.8 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. _fmemset(Context->Rc4Key, 0, sizeof(RC4_KEYSTRUCT));
  100. SspFree(Context->Rc4Key);
  101. }
  102. SspFree( Context );
  103. }
  104. return;
  105. }
  106. PSSP_CONTEXT
  107. SspContextAllocateContext(
  108. )
  109. /*++
  110. Routine Description:
  111. This routine allocates the security context block and initializes it.
  112. Arguments:
  113. Return Value:
  114. NULL -- Not enough memory to allocate context.
  115. otherwise -- pointer to allocated and referenced context.
  116. --*/
  117. {
  118. PSSP_CONTEXT Context;
  119. //
  120. // Allocate a Context block and initialize it.
  121. //
  122. Context = (SSP_CONTEXT *) SspAlloc (sizeof(SSP_CONTEXT) );
  123. if ( Context == NULL ) {
  124. return NULL;
  125. }
  126. _fmemset(Context, 0, sizeof(SSP_CONTEXT) );
  127. Context->References = 1;
  128. Context->NegotiateFlags = 0;
  129. Context->State = IdleState;
  130. //
  131. // Timeout this context.
  132. //
  133. Context->StartTime = SspTicks();
  134. Context->Interval = NTLMSSP_MAX_LIFETIME;
  135. Context->Rc4Key = NULL;
  136. SspPrint(( SSP_API_MORE, "Added Context 0x%lx\n", Context ));
  137. return Context;
  138. }
  139. TimeStamp
  140. SspContextGetTimeStamp(
  141. IN PSSP_CONTEXT Context,
  142. IN BOOLEAN GetExpirationTime
  143. )
  144. /*++
  145. Routine Description:
  146. Get the Start time or Expiration time for the specified context.
  147. Arguments:
  148. Context - Pointer to the context to query
  149. GetExpirationTime - If TRUE return the expiration time.
  150. Otherwise, return the start time for the context.
  151. Return Value:
  152. Returns the requested time as a local time.
  153. --*/
  154. {
  155. TimeStamp ReturnValue;
  156. if ( GetExpirationTime ) {
  157. if (Context->Interval == 0xffffffff) {
  158. ReturnValue.LowPart = 0xffffffff;
  159. } else {
  160. ReturnValue.LowPart = Context->StartTime + Context->Interval;
  161. }
  162. } else {
  163. ReturnValue.LowPart = Context->StartTime;
  164. }
  165. ReturnValue.HighPart = 0;
  166. return ReturnValue;
  167. }