From c6e814513540d865390434f973f865a6867d8789 Mon Sep 17 00:00:00 2001 From: Michael Martin Date: Fri, 21 Nov 2008 15:40:47 +0000 Subject: [PATCH] - Added EventSource structure for keeping track of EventLog Source name and associated Log File. - Added and Implemented ElfCreateEventLogHandle and ElfDeleteEventLogHandle. svn path=/trunk/; revision=37519 --- reactos/base/services/eventlog/eventlog.h | 5 ++ reactos/base/services/eventlog/rpc.c | 95 +++++++++++++++++++++++ 2 files changed, 100 insertions(+) diff --git a/reactos/base/services/eventlog/eventlog.h b/reactos/base/services/eventlog/eventlog.h index 532fe214c5d..2c12add58d8 100644 --- a/reactos/base/services/eventlog/eventlog.h +++ b/reactos/base/services/eventlog/eventlog.h @@ -94,6 +94,11 @@ typedef struct LIST_ENTRY ListEntry; } LOGFILE, *PLOGFILE; +typedef struct +{ + PLOGFILE LogFile; + WCHAR *Name; +} EVENTSOURCE, *PEVENTSOURCE; /* file.c */ VOID LogfListInitialize(VOID); diff --git a/reactos/base/services/eventlog/rpc.c b/reactos/base/services/eventlog/rpc.c index 7893957f00a..96657bfa241 100644 --- a/reactos/base/services/eventlog/rpc.c +++ b/reactos/base/services/eventlog/rpc.c @@ -41,6 +41,101 @@ DWORD STDCALL RpcThreadRoutine(LPVOID lpParameter) return 0; } +IELF_HANDLE ElfCreateEventLogHandle(WCHAR *Name) +{ + PEVENTSOURCE EventSourceHandle; + PLOGFILE currentLogFile = NULL; + HKEY hLogSourceNameKey = NULL; + WCHAR *SourceNameRegKey = NULL; + DWORD dwError, dwSize; + INT i, LogsActive; + + EventSourceHandle = HeapAlloc(GetProcessHeap(), 0, sizeof(EVENTSOURCE)); + if (!EventSourceHandle) + { + DPRINT1("Failed to allocate Heap!\n"); + return NULL; + } + + EventSourceHandle->Name = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY ,(wcslen(Name) + 1) * sizeof(WCHAR)); + if (!EventSourceHandle->Name) + { + HeapFree(GetProcessHeap(),0, EventSourceHandle); + DPRINT1("Failed to allocate Heap!\n"); + return NULL; + } + + wcscpy(EventSourceHandle->Name, Name); + + /* Get the number of Log Files the EventLog service found */ + LogsActive = LogfListItemCount(); + if (LogsActive == 0) + { + DPRINT1("EventLog service reports no log files!\n"); + goto Cleanup; + } + + /* Default to the Application Log, as documented on MSDN */ + EventSourceHandle->LogFile = LogfListItemByName(L"Application"); + + for (i = 1; i <= LogsActive; i++) + { + currentLogFile = LogfListItemByIndex(i); + //DPRINT1("LogFile = %S\n",currentLogFile->LogName); + + dwSize = 90; + dwSize += (wcslen(currentLogFile->LogName) + 3) * sizeof(WCHAR); + dwSize += (wcslen(Name) + 1) * sizeof(WCHAR); + + SourceNameRegKey = HeapAlloc(GetProcessHeap(), 0, dwSize); + + wcscpy(SourceNameRegKey, L"SYSTEM\\CurrentControlSet\\Services\\EventLog\\"); + wcsncat(SourceNameRegKey, currentLogFile->LogName, wcslen(currentLogFile->LogName)); + wcsncat(SourceNameRegKey, L"\\",2); + wcsncat(SourceNameRegKey, Name, wcslen(Name)); + + dwError = RegOpenKeyExW(HKEY_LOCAL_MACHINE, + SourceNameRegKey, + 0, + KEY_READ, + &hLogSourceNameKey); + + HeapFree(GetProcessHeap(), 0, SourceNameRegKey); + + if (dwError == ERROR_SUCCESS) + { + EventSourceHandle->LogFile = currentLogFile; + break; + } + } + + /* If hLogSourceRegKey is NULL */ + if (!hLogSourceNameKey) + { + DPRINT1("Could not find subkey %S under any of the eventlog logfiles in registry. Using default of Application.\n",Name); + } + + if (hLogSourceNameKey) RegCloseKey(hLogSourceNameKey); + + return EventSourceHandle; + +Cleanup: + HeapFree(GetProcessHeap(), 0, EventSourceHandle->Name); + HeapFree(GetProcessHeap(), 0, EventSourceHandle); + return NULL; +} + +BOOL ElfDeleteEventLogHandle(IELF_HANDLE EventLogHandle) +{ + PEVENTSOURCE pHandle = (PEVENTSOURCE) EventLogHandle; + + if (pHandle->LogFile->Header.Signature != LOGFILE_SIGNATURE) + return FALSE; + + HeapFree(GetProcessHeap(),0,pHandle->Name); + HeapFree(GetProcessHeap(),0,pHandle); + return TRUE; +} /* Function 0 */ NTSTATUS ElfrClearELFW(