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.

232 lines
6.4 KiB

  1. /*++
  2. Copyright (c) 1990 Microsoft Corporation
  3. Module Name:
  4. ELFRPC.C
  5. Abstract:
  6. This file contains the routines that handle the RPC calls to the
  7. Eventlog service via the Elf APIs.
  8. Author:
  9. Rajen Shah (rajens) 16-Jul-1991
  10. Revision History:
  11. 15-Feb-1995 MarkBl
  12. Unlink the ElfHandle *prior* to unlinking the module. Otherwise,
  13. if another thread happens to coincidentally be in the routine
  14. FindModuleStrucFromAtom, it's not going to get a hit for the
  15. module atom.
  16. 18-May-1994 Danl
  17. IELF_HANDLE_rundown: If the eventlog has been shutdown, then
  18. we want to skip the code in this routine because most of the
  19. resources will have been free'd.
  20. 31-Jan-1994 Danl
  21. IELF_HANDLE_rundown: Notifiee structure was being free'd and then
  22. referenced when it's handle was removed from the list. Now this
  23. is fixed so it advances to the next Notifiee in the list BEFORE the
  24. buffer is free'd.
  25. --*/
  26. //
  27. // INCLUDES
  28. //
  29. #include <eventp.h>
  30. extern DWORD ElState;
  31. VOID
  32. IELF_HANDLE_rundown(
  33. IELF_HANDLE ElfHandle
  34. )
  35. /*++
  36. Routine Description:
  37. This routine is called by the server RPC runtime to run down a
  38. Context Handle and to free any allocated data. It also does all
  39. the work for ElfrCloseEL.
  40. It has to undo whatever was done in ElfrOpenEventLog in terms of
  41. allocating memory.
  42. Arguments:
  43. None.
  44. Return Value:
  45. --*/
  46. {
  47. PLOGMODULE pModule;
  48. NTSTATUS Status;
  49. PNOTIFIEE Notifiee;
  50. PNOTIFIEE NotifieeToDelete;
  51. //
  52. // Generate an Audit if neccessary
  53. //
  54. ElfpCloseAudit(L"EventLog", ElfHandle);
  55. //
  56. // If the eventlog service is stopped or in the process of
  57. // stopping, then we just want to ignore this rundown and return.
  58. //
  59. // Note, we don't bother calling GetElState() because that uses
  60. // a critical section which may not exist anymore as the
  61. // eventlog service has been shutdown.
  62. //
  63. // The eventlog isn't designed to be shutdown (except when the
  64. // system is shutdown), so it isn't real good at cleaning up
  65. // its resources.
  66. //
  67. if (ElState == STOPPING || ElState == STOPPED)
  68. {
  69. ELF_LOG1(HANDLE,
  70. "IELF_HANDLE_rundown: Skipping rundown since ElState is %ws\n",
  71. (ElState == STOPPING ? L"STOPPING" :
  72. L"STOPPED"));
  73. return;
  74. }
  75. ELF_LOG1(HANDLE,
  76. "IELF_HANDLE_rundown: Run down context handle %#x\n",
  77. ElfHandle);
  78. if (ElfHandle->Signature != ELF_CONTEXTHANDLE_SIGN)
  79. {
  80. ELF_LOG0(ERROR,
  81. "IELF_HANDLE_rundown: Invalid context handle in rundown routine\n");
  82. return;
  83. }
  84. pModule = FindModuleStrucFromAtom(ElfHandle->Atom);
  85. //
  86. // This shouldn't ever happen. It means that a handle got created
  87. // and its module went away without the handle getting closed.
  88. //
  89. if (!pModule)
  90. {
  91. ELF_LOG1(ERROR,
  92. "IELF_HANDLE_rundown: Could not find module for atom %d on close\n",
  93. ElfHandle->Atom);
  94. return;
  95. }
  96. UnlinkContextHandle(ElfHandle); // Unlink it from the linked list
  97. //
  98. // If this handle was for a backup module, then we need to
  99. // close the file and clean up the data structures. The standard logs
  100. // (Application, Security, and System) are never freed.
  101. //
  102. if (ElfHandle->Flags & ELF_LOG_HANDLE_BACKUP_LOG)
  103. {
  104. ELF_LOG0(HANDLE,
  105. "IELF_HANDLE_rundown: Handle was for a backup log\n");
  106. Status = ElfpCloseLogFile(pModule->LogFile, ELF_LOG_CLOSE_BACKUP);
  107. UnlinkLogModule(pModule);
  108. DeleteAtom(pModule->ModuleAtom);
  109. ElfpFreeBuffer(pModule->ModuleName);
  110. //
  111. // ElfpCloseLogFile decrements the RefCount.
  112. //
  113. if (pModule->LogFile->RefCount == 0)
  114. {
  115. ELF_LOG1(HANDLE,
  116. "IELF_HANDLE_rundown: RefCount for LogFile %ws is 0 -- unlinking\n",
  117. pModule->LogFile->LogFileName->Buffer);
  118. UnlinkLogFile(pModule->LogFile);
  119. RtlDeleteResource ( &pModule->LogFile->Resource );
  120. RtlDeleteSecurityObject(&pModule->LogFile->Sd);
  121. ElfpFreeBuffer(pModule->LogFile->LogFileName);
  122. ElfpFreeBuffer(pModule->LogFile->LogModuleName);
  123. ElfpFreeBuffer(pModule->LogFile);
  124. }
  125. ElfpFreeBuffer(pModule);
  126. }
  127. else
  128. {
  129. ELF_LOG0(HANDLE,
  130. "IELF_HANDLE_rundown: Handle was not for a backup log\n");
  131. //
  132. // See if this handle had an ElfChangeNotify outstanding and if so,
  133. // remove it from the list. ElfChangeNotify can't be called with a
  134. // handle to a backup file.
  135. //
  136. //
  137. // Get exclusive access to the log file. This will ensure no one
  138. // else is accessing the file.
  139. //
  140. RtlAcquireResourceExclusive(&pModule->LogFile->Resource,
  141. TRUE); // Wait until available
  142. //
  143. // Walk the linked list and remove any entries for this handle
  144. //
  145. Notifiee = CONTAINING_RECORD(pModule->LogFile->Notifiees.Flink,
  146. struct _NOTIFIEE,
  147. Next);
  148. while (Notifiee->Next.Flink != pModule->LogFile->Notifiees.Flink)
  149. {
  150. //
  151. // If it's for this handle, remove it from the list
  152. //
  153. if (Notifiee->Handle == ElfHandle)
  154. {
  155. ELF_LOG0(HANDLE,
  156. "IELF_HANDLE_rundown: Deleting a ChangeNotify request for handle\n");
  157. RemoveEntryList(&Notifiee->Next);
  158. NtClose(Notifiee->Event);
  159. NotifieeToDelete = Notifiee;
  160. Notifiee = CONTAINING_RECORD(Notifiee->Next.Flink,
  161. struct _NOTIFIEE,
  162. Next);
  163. ElfpFreeBuffer(NotifieeToDelete);
  164. }
  165. else
  166. {
  167. Notifiee = CONTAINING_RECORD(Notifiee->Next.Flink,
  168. struct _NOTIFIEE,
  169. Next);
  170. }
  171. }
  172. //
  173. // Free the resource
  174. //
  175. RtlReleaseResource ( &pModule->LogFile->Resource );
  176. }
  177. ElfpFreeBuffer(ElfHandle); // Free the context-handle structure
  178. return;
  179. }