#include "eventlog.h"
-LIST_ENTRY EventSourceListHead;
+LIST_ENTRY LogHandleListHead;
/* FUNCTIONS ****************************************************************/
{
RPC_STATUS Status;
- InitializeListHead(&EventSourceListHead);
+ InitializeListHead(&LogHandleListHead);
Status = RpcServerUseProtseqEpW(L"ncacn_np", 20, L"\\pipe\\EventLog", NULL);
if (Status != RPC_S_OK)
return 0;
}
-PEVENTSOURCE ElfCreateEventLogHandle(LPCWSTR Name, BOOL Create)
+PLOGHANDLE ElfCreateEventLogHandle(LPCWSTR Name, BOOL Create)
{
- PEVENTSOURCE lpEventSource;
+ PLOGHANDLE lpLogHandle;
PLOGFILE currentLogFile = NULL;
INT i, LogsActive;
+ PEVENTSOURCE pEventSource;
- lpEventSource = HeapAlloc(GetProcessHeap(), 0, sizeof(EVENTSOURCE)
+ DPRINT("ElfCreateEventLogHandle(Name: %S)\n", Name);
+
+ lpLogHandle = HeapAlloc(GetProcessHeap(), 0, sizeof(LOGHANDLE)
+ ((wcslen(Name) + 1) * sizeof(WCHAR)));
- if (!lpEventSource)
+ if (!lpLogHandle)
{
DPRINT1("Failed to allocate Heap!\n");
return NULL;
}
- wcscpy(lpEventSource->szName, Name);
+ wcscpy(lpLogHandle->szName, Name);
/* Get the number of Log Files the EventLog service found */
LogsActive = LogfListItemCount();
/* If Creating, default to the Application Log in case we fail, as documented on MSDN */
if (Create == TRUE)
- lpEventSource->LogFile = LogfListItemByName(L"Application");
- else
- lpEventSource->LogFile = NULL;
+ {
+ pEventSource = GetEventSourceByName(Name);
+ DPRINT("EventSource: %p\n", pEventSource);
+ if (pEventSource)
+ {
+ DPRINT("EventSource LogFile: %p\n", pEventSource->LogFile);
+ lpLogHandle->LogFile = pEventSource->LogFile;
+ }
+ else
+ {
+ DPRINT("EventSource LogFile: Application log file\n");
+ lpLogHandle->LogFile = LogfListItemByName(L"Application");
+ }
- for (i = 1; i <= LogsActive; i++)
+ DPRINT("LogHandle LogFile: %p\n", lpLogHandle->LogFile);
+ }
+ else
{
- currentLogFile = LogfListItemByIndex(i);
+ lpLogHandle->LogFile = NULL;
- if (_wcsicmp(Name, currentLogFile->LogName) == 0)
+ for (i = 1; i <= LogsActive; i++)
{
- lpEventSource->LogFile = LogfListItemByIndex(i);
- lpEventSource->CurrentRecord = LogfGetOldestRecord(lpEventSource->LogFile);
- break;
+ currentLogFile = LogfListItemByIndex(i);
+
+ if (_wcsicmp(Name, currentLogFile->LogName) == 0)
+ {
+ lpLogHandle->LogFile = LogfListItemByIndex(i);
+ lpLogHandle->CurrentRecord = LogfGetOldestRecord(lpLogHandle->LogFile);
+ break;
+ }
}
}
- if (!lpEventSource->LogFile)
+ if (!lpLogHandle->LogFile)
goto Cleanup;
- /* Append service record */
- InsertTailList(&EventSourceListHead, &lpEventSource->EventSourceListEntry);
+ /* Append log handle */
+ InsertTailList(&LogHandleListHead, &lpLogHandle->LogHandleListEntry);
- return lpEventSource;
+ return lpLogHandle;
Cleanup:
- HeapFree(GetProcessHeap(), 0, lpEventSource);
+ HeapFree(GetProcessHeap(), 0, lpLogHandle);
return NULL;
}
-PEVENTSOURCE ElfGetEventLogSourceEntryByHandle(IELF_HANDLE EventLogHandle)
+PLOGHANDLE ElfGetLogHandleEntryByHandle(IELF_HANDLE EventLogHandle)
{
- PEVENTSOURCE CurrentEventSource;
+ PLOGHANDLE lpLogHandle;
- if (IsListEmpty(&EventSourceListHead))
+ if (IsListEmpty(&LogHandleListHead))
{
return NULL;
}
- CurrentEventSource = CONTAINING_RECORD((PEVENTSOURCE)EventLogHandle, EVENTSOURCE, EventSourceListEntry);
- return CurrentEventSource;
+ lpLogHandle = CONTAINING_RECORD((PLOGHANDLE)EventLogHandle, LOGHANDLE, LogHandleListEntry);
+
+ return lpLogHandle;
}
BOOL ElfDeleteEventLogHandle(IELF_HANDLE EventLogHandle)
{
- PEVENTSOURCE lpEventSource = (PEVENTSOURCE)EventLogHandle;
- if (!ElfGetEventLogSourceEntryByHandle(lpEventSource))
+ PLOGHANDLE lpLogHandle = (PLOGHANDLE)EventLogHandle;
+ if (!ElfGetLogHandleEntryByHandle(lpLogHandle))
{
return FALSE;
}
- RemoveEntryList(&lpEventSource->EventSourceListEntry);
- HeapFree(GetProcessHeap(),0,lpEventSource);
+ RemoveEntryList(&lpLogHandle->LogHandleListEntry);
+ HeapFree(GetProcessHeap(),0,lpLogHandle);
return TRUE;
}
IELF_HANDLE LogHandle,
DWORD *NumberOfRecords)
{
- PEVENTSOURCE lpEventSource;
+ PLOGHANDLE lpLogHandle;
- lpEventSource = ElfGetEventLogSourceEntryByHandle(LogHandle);
- if (!lpEventSource)
+ lpLogHandle = ElfGetLogHandleEntryByHandle(LogHandle);
+ if (!lpLogHandle)
{
return STATUS_INVALID_HANDLE;
}
- *NumberOfRecords = lpEventSource->LogFile->Header.CurrentRecordNumber;
+ *NumberOfRecords = lpLogHandle->LogFile->Header.CurrentRecordNumber;
return STATUS_SUCCESS;
}
IELF_HANDLE LogHandle,
DWORD *OldestRecordNumber)
{
- PEVENTSOURCE lpEventSource;
+ PLOGHANDLE lpLogHandle;
- lpEventSource = ElfGetEventLogSourceEntryByHandle(LogHandle);
- if (!lpEventSource)
+ lpLogHandle = ElfGetLogHandleEntryByHandle(LogHandle);
+ if (!lpLogHandle)
{
return STATUS_INVALID_HANDLE;
}
}
*OldestRecordNumber = 0;
- *OldestRecordNumber = LogfGetOldestRecord(lpEventSource->LogFile);
+ *OldestRecordNumber = LogfGetOldestRecord(lpLogHandle->LogFile);
return STATUS_SUCCESS;
}
DWORD MinorVersion,
IELF_HANDLE *LogHandle)
{
+ DPRINT1("ElfrRegisterEventSourceW()\n");
+
if ((MajorVersion != 1) || (MinorVersion != 1))
return STATUS_INVALID_PARAMETER;
if (RegModuleName->Length > 0)
return STATUS_INVALID_PARAMETER;
+ DPRINT1("ModuleName: %S\n", ModuleName->Buffer);
+
/*FIXME: UNCServerName must specify the server or empty for local */
/*FIXME: Must verify that caller has write access */
DWORD *NumberOfBytesRead,
DWORD *MinNumberOfBytesNeeded)
{
- PEVENTSOURCE lpEventSource;
+ PLOGHANDLE lpLogHandle;
DWORD dwError;
DWORD RecordNumber;
- lpEventSource = ElfGetEventLogSourceEntryByHandle(LogHandle);
- if (!lpEventSource)
+ lpLogHandle = ElfGetLogHandleEntryByHandle(LogHandle);
+ if (!lpLogHandle)
{
return STATUS_INVALID_HANDLE;
}
/* If sequential read, retrieve the CurrentRecord from this log handle */
if (ReadFlags & EVENTLOG_SEQUENTIAL_READ)
{
- RecordNumber = lpEventSource->CurrentRecord;
+ RecordNumber = lpLogHandle->CurrentRecord;
}
else
{
RecordNumber = RecordOffset;
}
- dwError = LogfReadEvent(lpEventSource->LogFile, ReadFlags, &RecordNumber,
+ dwError = LogfReadEvent(lpLogHandle->LogFile, ReadFlags, &RecordNumber,
NumberOfBytesToRead, Buffer, NumberOfBytesRead, MinNumberOfBytesNeeded);
/* Update the handles CurrentRecord if success*/
if (dwError == ERROR_SUCCESS)
{
- lpEventSource->CurrentRecord = RecordNumber;
+ lpLogHandle->CurrentRecord = RecordNumber;
}
return I_RpcMapWin32Status(dwError);
{
USHORT i;
PBYTE LogBuffer;
- PEVENTSOURCE lpEventSource;
+ PLOGHANDLE lpLogHandle;
DWORD lastRec;
DWORD recSize;
DWORD dwStringsSize = 0;
WCHAR *lpStrings;
int pos = 0;
- lpEventSource = ElfGetEventLogSourceEntryByHandle(LogHandle);
- if (!lpEventSource)
+ lpLogHandle = ElfGetLogHandleEntryByHandle(LogHandle);
+ if (!lpLogHandle)
{
return STATUS_INVALID_HANDLE;
}
return STATUS_INVALID_PARAMETER;
}
- lastRec = LogfGetCurrentRecord(lpEventSource->LogFile);
+ lastRec = LogfGetCurrentRecord(lpLogHandle->LogFile);
for (i = 0; i < NumStrings; i++)
{
EventType,
EventCategory,
EventID,
- lpEventSource->szName,
+ lpLogHandle->szName,
ComputerName->Buffer,
sizeof(UserSID),
&UserSID,
DataSize,
Data);
- dwError = LogfWriteData(lpEventSource->LogFile, recSize, LogBuffer);
+ dwError = LogfWriteData(lpLogHandle->LogFile, recSize, LogBuffer);
if (!dwError)
{
- DPRINT1("ERROR WRITING TO EventLog %S\n",lpEventSource->LogFile->FileName);
+ DPRINT1("ERROR WRITING TO EventLog %S\n", lpLogHandle->LogFile->FileName);
}
LogfFreeRecord(LogBuffer);