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.

145 lines
2.9 KiB

  1. //+-----------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (c) Microsoft Corporation 1992 - 1997
  6. //
  7. // File: context.cxx
  8. //
  9. // Contents: context kernel-mode functions
  10. //
  11. //
  12. // History: 3/17/94 MikeSw Created
  13. // 12/15/97 AdamBa Modified from private\lsa\client\ssp
  14. //
  15. //------------------------------------------------------------------------
  16. #include <rdrssp.h>
  17. //+-------------------------------------------------------------------------
  18. //
  19. // Function: DeleteKernelContext
  20. //
  21. // Synopsis: Deletes a kernel context
  22. //
  23. // Effects: Frees memory, closes token handle.
  24. //
  25. // Arguments:
  26. //
  27. // Requires:
  28. //
  29. // Returns:
  30. //
  31. // Notes:
  32. //
  33. //--------------------------------------------------------------------------
  34. SECURITY_STATUS
  35. DeleteKernelContext(PKernelContext * ppList,
  36. PKSPIN_LOCK pslLock,
  37. PKernelContext pContext)
  38. {
  39. KIRQL OldIrql;
  40. //
  41. // First, find the record, then unlink the record from the list,
  42. // and fix up pointers.
  43. //
  44. KeAcquireSpinLock(pslLock, &OldIrql);
  45. if (!pContext)
  46. {
  47. KeReleaseSpinLock(pslLock, OldIrql);
  48. return(SEC_E_INVALID_HANDLE);
  49. }
  50. //
  51. // Now unlink from the list
  52. //
  53. if (pContext->pPrev)
  54. {
  55. pContext->pPrev->pNext = pContext->pNext;
  56. }
  57. else
  58. {
  59. *ppList = pContext->pNext;
  60. }
  61. if (pContext->pNext)
  62. {
  63. pContext->pNext->pPrev = pContext->pPrev;
  64. }
  65. //
  66. // copy out the package-specific context to return.
  67. // We are done with the list so we can release the spin lock
  68. //
  69. KeReleaseSpinLock(pslLock, OldIrql);
  70. if (pContext->TokenHandle != NULL)
  71. {
  72. NtClose(pContext->TokenHandle);
  73. }
  74. if (pContext->AccessToken != NULL)
  75. {
  76. ObDereferenceObject(pContext->AccessToken);
  77. }
  78. // And, finally, return the context record to our pool:
  79. FreeContextRec(pContext);
  80. return(STATUS_SUCCESS);
  81. }
  82. //+-------------------------------------------------------------------------
  83. //
  84. // Function: AddKernelContext
  85. //
  86. // Synopsis:
  87. //
  88. // Effects:
  89. //
  90. // Arguments:
  91. //
  92. // Requires:
  93. //
  94. // Returns:
  95. //
  96. // Notes:
  97. //
  98. //--------------------------------------------------------------------------
  99. void
  100. AddKernelContext( PKernelContext * ppList,
  101. PKSPIN_LOCK pslLock,
  102. PKernelContext pContext)
  103. {
  104. KIRQL OldIrql;
  105. KeAcquireSpinLock(pslLock, &OldIrql);
  106. pContext->pNext = *ppList;
  107. if (pContext->pNext)
  108. {
  109. pContext->pNext->pPrev = pContext;
  110. }
  111. pContext->pPrev = NULL;
  112. *ppList = pContext;
  113. KeReleaseSpinLock(pslLock, OldIrql);
  114. }