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.

214 lines
6.0 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. ASSERT(ElfHandle != gElfSecurityHandle);
  79. if (ElfHandle->Signature != ELF_CONTEXTHANDLE_SIGN)
  80. {
  81. ELF_LOG0(ERROR,
  82. "IELF_HANDLE_rundown: Invalid context handle in rundown routine\n");
  83. return;
  84. }
  85. pModule = FindModuleStrucFromAtom(ElfHandle->Atom);
  86. //
  87. // This shouldn't ever happen. It means that a handle got created
  88. // and its module went away without the handle getting closed.
  89. //
  90. if (!pModule)
  91. {
  92. ELF_LOG1(ERROR,
  93. "IELF_HANDLE_rundown: Could not find module for atom %d on close\n",
  94. ElfHandle->Atom);
  95. return;
  96. }
  97. UnlinkContextHandle(ElfHandle); // Unlink it from the linked list
  98. //
  99. // If this handle was for a backup module, then we need to
  100. // close the file and clean up the data structures. The standard logs
  101. // (Application, Security, and System) are never freed.
  102. //
  103. if (ElfHandle->Flags & ELF_LOG_HANDLE_BACKUP_LOG)
  104. {
  105. ELF_LOG0(HANDLE,
  106. "IELF_HANDLE_rundown: Handle was for a backup log\n");
  107. Status = ElfpCloseLogFile(pModule->LogFile, ELF_LOG_CLOSE_BACKUP, TRUE);
  108. UnlinkLogModule(pModule);
  109. DeleteAtom(pModule->ModuleAtom);
  110. ElfpFreeBuffer(pModule->ModuleName);
  111. ElfpFreeBuffer(pModule);
  112. }
  113. else
  114. {
  115. ELF_LOG0(HANDLE,
  116. "IELF_HANDLE_rundown: Handle was not for a backup log\n");
  117. //
  118. // See if this handle had an ElfChangeNotify outstanding and if so,
  119. // remove it from the list. ElfChangeNotify can't be called with a
  120. // handle to a backup file.
  121. //
  122. //
  123. // Get exclusive access to the log file. This will ensure no one
  124. // else is accessing the file.
  125. //
  126. RtlAcquireResourceExclusive(&pModule->LogFile->Resource,
  127. TRUE); // Wait until available
  128. //
  129. // Walk the linked list and remove any entries for this handle
  130. //
  131. Notifiee = CONTAINING_RECORD(pModule->LogFile->Notifiees.Flink,
  132. struct _NOTIFIEE,
  133. Next);
  134. while (Notifiee->Next.Flink != pModule->LogFile->Notifiees.Flink)
  135. {
  136. //
  137. // If it's for this handle, remove it from the list
  138. //
  139. if (Notifiee->Handle == ElfHandle)
  140. {
  141. ELF_LOG0(HANDLE,
  142. "IELF_HANDLE_rundown: Deleting a ChangeNotify request for handle\n");
  143. RemoveEntryList(&Notifiee->Next);
  144. NtClose(Notifiee->Event);
  145. NotifieeToDelete = Notifiee;
  146. Notifiee = CONTAINING_RECORD(Notifiee->Next.Flink,
  147. struct _NOTIFIEE,
  148. Next);
  149. ElfpFreeBuffer(NotifieeToDelete);
  150. }
  151. else
  152. {
  153. Notifiee = CONTAINING_RECORD(Notifiee->Next.Flink,
  154. struct _NOTIFIEE,
  155. Next);
  156. }
  157. }
  158. //
  159. // Free the resource
  160. //
  161. RtlReleaseResource ( &pModule->LogFile->Resource );
  162. }
  163. ElfpFreeBuffer(ElfHandle); // Free the context-handle structure
  164. return;
  165. }