Windows NT 4.0 source code leak
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.

146 lines
2.6 KiB

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