[EVENTLOG]

- Update code source files headers.
- Use explicit unicode functions for RegOpen/Query/SetXXX and safe-string APIs.
- Use GetSystemWindowsDirectoryW where needed instead of GetWindowsDirectoryW (TS-safe).
- Fix some variable names & types.
- Improve some DPRINTs.

svn path=/trunk/; revision=73034
This commit is contained in:
Hermès Bélusca-Maïto 2016-10-25 23:32:20 +00:00
parent 496573473b
commit 34a06851d3
6 changed files with 244 additions and 253 deletions

View file

@ -1,17 +1,16 @@
/*
* PROJECT: ReactOS kernel
* LICENSE: GPL - See COPYING in the top level directory
* FILE: base/services/eventlog/eventlog.c
* PURPOSE: Event logging service
* COPYRIGHT: Copyright 2002 Eric Kohl
* Copyright 2005 Saveliy Tretiakov
* Hermes Belusca-Maito
* PROJECT: ReactOS EventLog Service
* LICENSE: GPL - See COPYING in the top level directory
* FILE: base/services/eventlog/eventlog.c
* PURPOSE: Event logging service
* COPYRIGHT: Copyright 2002 Eric Kohl
* Copyright 2005 Saveliy Tretiakov
* Hermes Belusca-Maito
*/
/* INCLUDES *****************************************************************/
#include "eventlog.h"
#include <stdio.h>
#include <netevent.h>
@ -200,20 +199,20 @@ ReportProductInfoEvent(VOID)
cchRemain++;
/* Read 'CurrentType' from the registry and write it into the buffer */
lResult = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion",
0,
KEY_QUERY_VALUE,
&hKey);
lResult = RegOpenKeyExW(HKEY_LOCAL_MACHINE,
L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion",
0,
KEY_QUERY_VALUE,
&hKey);
if (lResult == ERROR_SUCCESS)
{
dwValueLength = cchRemain;
lResult = RegQueryValueEx(hKey,
L"CurrentType",
NULL,
&dwType,
(LPBYTE)str,
&dwValueLength);
lResult = RegQueryValueExW(hKey,
L"CurrentType",
NULL,
&dwType,
(LPBYTE)str,
&dwValueLength);
RegCloseKey(hKey);
}
@ -289,7 +288,7 @@ LoadLogFile(HKEY hKey, PWSTR LogName)
ULONG ulMaxSize, ulRetention;
NTSTATUS Status;
DPRINT("LoadLogFile: %S\n", LogName);
DPRINT("LoadLogFile: `%S'\n", LogName);
Result = RegQueryInfoKeyW(hKey, NULL, NULL, NULL, NULL, NULL, NULL,
NULL, NULL, &MaxValueLen, NULL, NULL);
@ -346,7 +345,7 @@ LoadLogFile(HKEY hKey, PWSTR LogName)
ValueLen);
if (Result != ERROR_SUCCESS)
{
DPRINT1("RegSetValueEx failed: %lu\n", Result);
DPRINT1("RegSetValueExW failed: %lu\n", Result);
HeapFree(GetProcessHeap(), 0, Buf);
return NULL;
}
@ -431,8 +430,8 @@ LoadLogFiles(HKEY eventlogKey)
{
LONG Result;
DWORD MaxLognameLen, LognameLen;
PWSTR Buf = NULL;
DWORD dwIndex;
PWSTR Buf = NULL;
PLOGFILE pLogFile;
Result = RegQueryInfoKeyW(eventlogKey, NULL, NULL, NULL, NULL, &MaxLognameLen,
@ -464,7 +463,7 @@ LoadLogFiles(HKEY eventlogKey)
DPRINT("%S\n", Buf);
Result = RegOpenKeyEx(eventlogKey, Buf, 0, KEY_ALL_ACCESS, &SubKey);
Result = RegOpenKeyExW(eventlogKey, Buf, 0, KEY_ALL_ACCESS, &SubKey);
if (Result != ERROR_SUCCESS)
{
DPRINT1("Failed to open %S key.\n", Buf);
@ -496,15 +495,15 @@ LoadLogFiles(HKEY eventlogKey)
int wmain(int argc, WCHAR* argv[])
{
WCHAR LogPath[MAX_PATH];
INT RetCode = 0;
LONG Result;
HKEY elogKey;
WCHAR LogPath[MAX_PATH];
LogfListInitialize();
InitEventSourceList();
GetWindowsDirectoryW(LogPath, MAX_PATH);
GetSystemWindowsDirectoryW(LogPath, ARRAYSIZE(LogPath));
if (GetDriveTypeW(LogPath) == DRIVE_CDROM)
{
@ -513,12 +512,11 @@ int wmain(int argc, WCHAR* argv[])
}
else
{
Result = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
L"SYSTEM\\CurrentControlSet\\Services\\EventLog",
0,
KEY_ALL_ACCESS,
&elogKey);
Result = RegOpenKeyExW(HKEY_LOCAL_MACHINE,
L"SYSTEM\\CurrentControlSet\\Services\\EventLog",
0,
KEY_ALL_ACCESS,
&elogKey);
if (Result != ERROR_SUCCESS)
{
DPRINT1("Fatal error: cannot open eventlog registry key.\n");
@ -532,7 +530,7 @@ int wmain(int argc, WCHAR* argv[])
EventLogSource = GetEventSourceByName(L"EventLog");
if (!EventLogSource)
{
DPRINT1("No EventLog source available, the EventLog service will not be able to log its own events.\n");
DPRINT1("The 'EventLog' source is unavailable. The EventLog service will not be able to log its own events.\n");
}
StartServiceCtrlDispatcher(ServiceTable);

View file

@ -1,9 +1,9 @@
/*
* PROJECT: ReactOS kernel
* LICENSE: GPL - See COPYING in the top level directory
* FILE: base/services/eventlog/eventlog.h
* PURPOSE: Event logging service
* COPYRIGHT: Copyright 2005 Saveliy Tretiakov
* PROJECT: ReactOS EventLog Service
* LICENSE: GPL - See COPYING in the top level directory
* FILE: base/services/eventlog/eventlog.h
* PURPOSE: Precompiled Header for the Event logging service
* COPYRIGHT: Copyright 2005 Saveliy Tretiakov
*/
#ifndef __EVENTLOG_H__
@ -145,13 +145,9 @@ GetEventSourceByName(LPCWSTR Name);
/* file.c */
VOID LogfListInitialize(VOID);
DWORD LogfListItemCount(VOID);
PLOGFILE LogfListItemByIndex(DWORD Index);
PLOGFILE LogfListItemByName(LPCWSTR Name);
// DWORD LogfListItemIndexByName(WCHAR * Name);
@ -195,19 +191,19 @@ LogfClose(PLOGFILE LogFile,
VOID LogfCloseAll(VOID);
PEVENTLOGRECORD
LogfAllocAndBuildNewRecord(PULONG lpRecSize,
ULONG Time,
USHORT wType,
USHORT wCategory,
ULONG dwEventId,
PCWSTR SourceName,
PCWSTR ComputerName,
ULONG dwSidLength,
PSID lpUserSid,
USHORT wNumStrings,
PWSTR lpStrings,
ULONG dwDataSize,
PVOID lpRawData);
LogfAllocAndBuildNewRecord(PSIZE_T pRecSize,
ULONG Time,
USHORT wType,
USHORT wCategory,
ULONG dwEventId,
PCWSTR SourceName,
PCWSTR ComputerName,
ULONG dwSidLength,
PSID pUserSid,
USHORT wNumStrings,
PWSTR pStrings,
ULONG dwDataSize,
PVOID pRawData);
static __inline void LogfFreeRecord(PEVENTLOGRECORD Record)
{
@ -219,9 +215,9 @@ LogfReportEvent(USHORT wType,
USHORT wCategory,
ULONG dwEventId,
USHORT wNumStrings,
PWSTR lpStrings,
PWSTR pStrings,
ULONG dwDataSize,
PVOID lpRawData);
PVOID pRawData);
/* logport.c */

View file

@ -1,9 +1,9 @@
/*
* PROJECT: ReactOS kernel
* LICENSE: GPL - See COPYING in the top level directory
* FILE: base/services/eventlog/eventsource.c
* PURPOSE: Event logging service
* COPYRIGHT: Copyright 2011 Eric Kohl
* PROJECT: ReactOS EventLog Service
* LICENSE: GPL - See COPYING in the top level directory
* FILE: base/services/eventlog/eventsource.c
* PURPOSE: Event log sources support
* COPYRIGHT: Copyright 2011 Eric Kohl
*/
/* INCLUDES *****************************************************************/
@ -176,15 +176,15 @@ LoadEventSources(HKEY hKey,
}
/* Save the list of sources in the registry */
Result = RegSetValueEx(hKey,
L"Sources",
0,
REG_MULTI_SZ,
(LPBYTE)SourceList,
(MaxValueLen - cchRemaining + 1) * sizeof(WCHAR));
Result = RegSetValueExW(hKey,
L"Sources",
0,
REG_MULTI_SZ,
(LPBYTE)SourceList,
(MaxValueLen - cchRemaining + 1) * sizeof(WCHAR));
if (Result != ERROR_SUCCESS)
{
DPRINT1("RegSetValueEx failed: %lu\n", Result);
DPRINT1("RegSetValueExW failed: %lu\n", Result);
}
if (SourceList)

View file

@ -1,17 +1,16 @@
/*
* PROJECT: ReactOS kernel
* LICENSE: GPL - See COPYING in the top level directory
* FILE: base/services/eventlog/file.c
* PURPOSE: Event logging service
* COPYRIGHT: Copyright 2005 Saveliy Tretiakov
* Michael Martin
* Hermes Belusca-Maito
* PROJECT: ReactOS EventLog Service
* LICENSE: GPL - See COPYING in the top level directory
* FILE: base/services/eventlog/file.c
* PURPOSE: Event log file support wrappers
* COPYRIGHT: Copyright 2005 Saveliy Tretiakov
* Michael Martin
* Hermes Belusca-Maito
*/
/* INCLUDES ******************************************************************/
#include "eventlog.h"
#include <ndk/iofuncs.h>
#include <ndk/kefuncs.h>
@ -1086,7 +1085,7 @@ LogfCreate(PLOGFILE* LogFile,
}
if (LogName)
StringCchCopy(pLogFile->LogName, LogNameLen, LogName);
StringCchCopyW(pLogFile->LogName, LogNameLen, LogName);
pLogFile->FileName = RtlAllocateHeap(GetProcessHeap(),
HEAP_ZERO_MEMORY,
@ -1099,9 +1098,9 @@ LogfCreate(PLOGFILE* LogFile,
goto Quit;
}
StringCchCopy(pLogFile->FileName,
/*wcslen(FileName->Buffer) + 1*/ (FileName->Length + sizeof(UNICODE_NULL)) / sizeof(WCHAR),
FileName->Buffer);
StringCchCopyW(pLogFile->FileName,
/*wcslen(FileName->Buffer) + 1*/ (FileName->Length + sizeof(UNICODE_NULL)) / sizeof(WCHAR),
FileName->Buffer);
pLogFile->OffsetInfo = RtlAllocateHeap(GetProcessHeap(),
HEAP_ZERO_MEMORY,
@ -2128,57 +2127,57 @@ Done:
PEVENTLOGRECORD
LogfAllocAndBuildNewRecord(PULONG lpRecSize,
ULONG Time,
USHORT wType,
USHORT wCategory,
ULONG dwEventId,
PCWSTR SourceName,
PCWSTR ComputerName,
ULONG dwSidLength,
PSID lpUserSid,
USHORT wNumStrings,
PWSTR lpStrings,
ULONG dwDataSize,
PVOID lpRawData)
LogfAllocAndBuildNewRecord(PSIZE_T pRecSize,
ULONG Time,
USHORT wType,
USHORT wCategory,
ULONG dwEventId,
PCWSTR SourceName,
PCWSTR ComputerName,
ULONG dwSidLength,
PSID pUserSid,
USHORT wNumStrings,
PWSTR pStrings,
ULONG dwDataSize,
PVOID pRawData)
{
DWORD dwRecSize;
SIZE_T RecSize;
PBYTE Buffer;
PEVENTLOGRECORD pRec;
PWSTR str;
UINT i, pos;
SIZE_T SourceNameLen, ComputerNameLen, StringLen;
PBYTE Buffer;
SourceNameLen = (SourceName ? wcslen(SourceName) : 0) + 1;
ComputerNameLen = (ComputerName ? wcslen(ComputerName) : 0) + 1;
dwRecSize = sizeof(EVENTLOGRECORD) + (SourceNameLen + ComputerNameLen) * sizeof(WCHAR);
RecSize = sizeof(EVENTLOGRECORD) + (SourceNameLen + ComputerNameLen) * sizeof(WCHAR);
/* Align on DWORD boundary for the SID */
dwRecSize = ROUND_UP(dwRecSize, sizeof(ULONG));
RecSize = ROUND_UP(RecSize, sizeof(ULONG));
dwRecSize += dwSidLength;
RecSize += dwSidLength;
/* Add the sizes for the strings array */
ASSERT((lpStrings == NULL && wNumStrings == 0) ||
(lpStrings != NULL && wNumStrings >= 0));
for (i = 0, str = lpStrings; i < wNumStrings; i++)
ASSERT((pStrings == NULL && wNumStrings == 0) ||
(pStrings != NULL && wNumStrings >= 0));
for (i = 0, str = pStrings; i < wNumStrings; i++)
{
StringLen = wcslen(str) + 1; // str must be != NULL
dwRecSize += StringLen * sizeof(WCHAR);
RecSize += StringLen * sizeof(WCHAR);
str += StringLen;
}
/* Add the data size */
dwRecSize += dwDataSize;
RecSize += dwDataSize;
/* Align on DWORD boundary for the full structure */
dwRecSize = ROUND_UP(dwRecSize, sizeof(ULONG));
RecSize = ROUND_UP(RecSize, sizeof(ULONG));
/* Size of the trailing 'Length' member */
dwRecSize += sizeof(ULONG);
RecSize += sizeof(ULONG);
Buffer = RtlAllocateHeap(GetProcessHeap(), HEAP_ZERO_MEMORY, dwRecSize);
Buffer = RtlAllocateHeap(GetProcessHeap(), HEAP_ZERO_MEMORY, RecSize);
if (!Buffer)
{
DPRINT1("Cannot allocate heap!\n");
@ -2186,7 +2185,7 @@ LogfAllocAndBuildNewRecord(PULONG lpRecSize,
}
pRec = (PEVENTLOGRECORD)Buffer;
pRec->Length = dwRecSize;
pRec->Length = RecSize;
pRec->Reserved = LOGFILE_SIGNATURE;
/*
@ -2211,10 +2210,10 @@ LogfAllocAndBuildNewRecord(PULONG lpRecSize,
pos = sizeof(EVENTLOGRECORD);
if (SourceName)
StringCchCopy((PWSTR)(Buffer + pos), SourceNameLen, SourceName);
StringCchCopyW((PWSTR)(Buffer + pos), SourceNameLen, SourceName);
pos += SourceNameLen * sizeof(WCHAR);
if (ComputerName)
StringCchCopy((PWSTR)(Buffer + pos), ComputerNameLen, ComputerName);
StringCchCopyW((PWSTR)(Buffer + pos), ComputerNameLen, ComputerName);
pos += ComputerNameLen * sizeof(WCHAR);
/* Align on DWORD boundary for the SID */
@ -2224,17 +2223,17 @@ LogfAllocAndBuildNewRecord(PULONG lpRecSize,
pRec->UserSidOffset = 0;
if (dwSidLength)
{
RtlCopyMemory(Buffer + pos, lpUserSid, dwSidLength);
RtlCopyMemory(Buffer + pos, pUserSid, dwSidLength);
pRec->UserSidLength = dwSidLength;
pRec->UserSidOffset = pos;
pos += dwSidLength;
}
pRec->StringOffset = pos;
for (i = 0, str = lpStrings; i < wNumStrings; i++)
for (i = 0, str = pStrings; i < wNumStrings; i++)
{
StringLen = wcslen(str) + 1; // str must be != NULL
StringCchCopy((PWSTR)(Buffer + pos), StringLen, str);
StringCchCopyW((PWSTR)(Buffer + pos), StringLen, str);
str += StringLen;
pos += StringLen * sizeof(WCHAR);
}
@ -2244,7 +2243,7 @@ LogfAllocAndBuildNewRecord(PULONG lpRecSize,
pRec->DataOffset = 0;
if (dwDataSize)
{
RtlCopyMemory(Buffer + pos, lpRawData, dwDataSize);
RtlCopyMemory(Buffer + pos, pRawData, dwDataSize);
pRec->DataLength = dwDataSize;
pRec->DataOffset = pos;
pos += dwDataSize;
@ -2254,9 +2253,9 @@ LogfAllocAndBuildNewRecord(PULONG lpRecSize,
pos = ROUND_UP(pos, sizeof(ULONG));
/* Initialize the trailing 'Length' member */
*((PDWORD) (Buffer + pos)) = dwRecSize;
*((PDWORD)(Buffer + pos)) = RecSize;
*lpRecSize = dwRecSize;
*pRecSize = RecSize;
return pRec;
}
@ -2265,17 +2264,17 @@ LogfReportEvent(USHORT wType,
USHORT wCategory,
ULONG dwEventId,
USHORT wNumStrings,
PWSTR lpStrings,
PWSTR pStrings,
ULONG dwDataSize,
PVOID lpRawData)
PVOID pRawData)
{
NTSTATUS Status;
WCHAR szComputerName[MAX_COMPUTERNAME_LENGTH + 1];
DWORD dwComputerNameLength = MAX_COMPUTERNAME_LENGTH + 1;
PEVENTLOGRECORD logBuffer;
PEVENTLOGRECORD LogBuffer;
LARGE_INTEGER SystemTime;
ULONG Time;
DWORD recSize;
SIZE_T RecSize;
if (!EventLogSource)
return;
@ -2288,7 +2287,7 @@ LogfReportEvent(USHORT wType,
NtQuerySystemTime(&SystemTime);
RtlTimeToSecondsSince1970(&SystemTime, &Time);
logBuffer = LogfAllocAndBuildNewRecord(&recSize,
LogBuffer = LogfAllocAndBuildNewRecord(&RecSize,
Time,
wType,
wCategory,
@ -2298,16 +2297,16 @@ LogfReportEvent(USHORT wType,
0,
NULL,
wNumStrings,
lpStrings,
pStrings,
dwDataSize,
lpRawData);
pRawData);
Status = LogfWriteRecord(EventLogSource->LogFile, recSize, logBuffer);
Status = LogfWriteRecord(EventLogSource->LogFile, RecSize, LogBuffer);
if (!NT_SUCCESS(Status))
{
DPRINT1("ERROR WRITING TO EventLog %S (Status 0x%08lx)\n",
EventLogSource->LogFile->FileName, Status);
DPRINT1("ERROR writing to event log `%S' (Status 0x%08lx)\n",
EventLogSource->LogFile->LogName, Status);
}
LogfFreeRecord(logBuffer);
LogfFreeRecord(LogBuffer);
}

View file

@ -1,16 +1,15 @@
/*
* PROJECT: ReactOS kernel
* LICENSE: GPL - See COPYING in the top level directory
* FILE: base/services/eventlog/logport.c
* PURPOSE: Event logging service
* COPYRIGHT: Copyright 2002 Eric Kohl
* Copyright 2005 Saveliy Tretiakov
* PROJECT: ReactOS EventLog Service
* LICENSE: GPL - See COPYING in the top level directory
* FILE: base/services/eventlog/logport.c
* PURPOSE: LPC Port Interface support
* COPYRIGHT: Copyright 2002 Eric Kohl
* Copyright 2005 Saveliy Tretiakov
*/
/* INCLUDES *****************************************************************/
#include "eventlog.h"
#include <ndk/lpcfuncs.h>
#define NDEBUG
@ -46,10 +45,10 @@ NTSTATUS WINAPI PortThreadRoutine(PVOID Param)
NTSTATUS InitLogPort(VOID)
{
OBJECT_ATTRIBUTES ObjectAttributes;
UNICODE_STRING PortName;
PORT_MESSAGE Request;
NTSTATUS Status;
UNICODE_STRING PortName;
OBJECT_ATTRIBUTES ObjectAttributes;
PORT_MESSAGE Request;
ConnectPortHandle = NULL;
MessagePortHandle = NULL;
@ -105,12 +104,12 @@ ByeBye:
NTSTATUS ProcessPortMessage(VOID)
{
NTSTATUS Status;
IO_ERROR_LPC Request;
PIO_ERROR_LOG_MESSAGE Message;
ULONG Time;
PEVENTLOGRECORD pRec;
DWORD dwRecSize;
NTSTATUS Status;
SIZE_T RecSize;
PLOGFILE SystemLog = NULL;
WCHAR szComputerName[MAX_COMPUTERNAME_LENGTH + 1];
DWORD dwComputerNameLength = MAX_COMPUTERNAME_LENGTH + 1;
@ -160,7 +159,7 @@ NTSTATUS ProcessPortMessage(VOID)
// TODO: Log more information??
pRec = LogfAllocAndBuildNewRecord(
&dwRecSize,
&RecSize,
Time,
Message->Type,
Message->EntryData.EventCategory,
@ -180,7 +179,7 @@ NTSTATUS ProcessPortMessage(VOID)
return STATUS_NO_MEMORY;
}
DPRINT("dwRecSize = %d\n", dwRecSize);
DPRINT("RecSize = %d\n", RecSize);
DPRINT("\n --- EVENTLOG RECORD ---\n");
PRINT_RECORD(pRec);
@ -188,10 +187,10 @@ NTSTATUS ProcessPortMessage(VOID)
if (!onLiveCD && SystemLog)
{
Status = LogfWriteRecord(SystemLog, dwRecSize, pRec);
Status = LogfWriteRecord(SystemLog, RecSize, pRec);
if (!NT_SUCCESS(Status))
{
DPRINT1("ERROR WRITING TO EventLog %S (Status 0x%08lx)\n",
DPRINT1("ERROR writing to event log `%S' (Status 0x%08lx)\n",
SystemLog->FileName, Status);
}
}

View file

@ -1,11 +1,11 @@
/*
* PROJECT: ReactOS kernel
* LICENSE: GPL - See COPYING in the top level directory
* FILE: base/services/eventlog/rpc.c
* PURPOSE: Event logging service
* COPYRIGHT: Copyright 2005 Saveliy Tretiakov
* Copyright 2008 Michael Martin
* Copyright 2010-2011 Eric Kohl
* PROJECT: ReactOS EventLog Service
* LICENSE: GPL - See COPYING in the top level directory
* FILE: base/services/eventlog/rpc.c
* PURPOSE: RPC Port Interface support
* COPYRIGHT: Copyright 2005 Saveliy Tretiakov
* Copyright 2008 Michael Martin
* Copyright 2010-2011 Eric Kohl
*/
/* INCLUDES *****************************************************************/
@ -55,26 +55,26 @@ ElfCreateEventLogHandle(PLOGHANDLE* LogHandle,
BOOLEAN Create)
{
NTSTATUS Status = STATUS_SUCCESS;
PLOGHANDLE lpLogHandle;
PLOGHANDLE pLogHandle;
PLOGFILE currentLogFile = NULL;
DWORD i, LogsActive;
PEVENTSOURCE pEventSource;
DPRINT("ElfCreateEventLogHandle(Name: %wZ)\n", LogName);
DPRINT("ElfCreateEventLogHandle(%wZ)\n", LogName);
*LogHandle = NULL;
i = (LogName->Length + sizeof(UNICODE_NULL)) / sizeof(WCHAR);
lpLogHandle = HeapAlloc(GetProcessHeap(),
HEAP_ZERO_MEMORY,
FIELD_OFFSET(LOGHANDLE, szName[i]));
if (!lpLogHandle)
pLogHandle = HeapAlloc(GetProcessHeap(),
HEAP_ZERO_MEMORY,
FIELD_OFFSET(LOGHANDLE, szName[i]));
if (!pLogHandle)
{
DPRINT1("Failed to allocate Heap!\n");
return STATUS_NO_MEMORY;
}
StringCchCopy(lpLogHandle->szName, i, LogName->Buffer);
StringCchCopyW(pLogHandle->szName, i, LogName->Buffer);
/* Get the number of Log Files the EventLog service found */
// NOTE: We could just as well loop only once within the list of logs
@ -95,19 +95,19 @@ ElfCreateEventLogHandle(PLOGHANDLE* LogHandle,
if (pEventSource)
{
DPRINT("EventSource LogFile: %p\n", pEventSource->LogFile);
lpLogHandle->LogFile = pEventSource->LogFile;
pLogHandle->LogFile = pEventSource->LogFile;
}
else
{
DPRINT("EventSource LogFile: Application log file\n");
lpLogHandle->LogFile = LogfListItemByName(L"Application");
pLogHandle->LogFile = LogfListItemByName(L"Application");
}
DPRINT("LogHandle LogFile: %p\n", lpLogHandle->LogFile);
DPRINT("LogHandle LogFile: %p\n", pLogHandle->LogFile);
}
else
{
lpLogHandle->LogFile = NULL;
pLogHandle->LogFile = NULL;
for (i = 1; i <= LogsActive; i++)
{
@ -115,16 +115,16 @@ ElfCreateEventLogHandle(PLOGHANDLE* LogHandle,
if (_wcsicmp(LogName->Buffer, currentLogFile->LogName) == 0)
{
lpLogHandle->LogFile = currentLogFile;
pLogHandle->LogFile = currentLogFile;
break;
}
}
/* Use the application log if the desired log does not exist */
if (lpLogHandle->LogFile == NULL)
if (pLogHandle->LogFile == NULL)
{
lpLogHandle->LogFile = LogfListItemByName(L"Application");
if (lpLogHandle->LogFile == NULL)
pLogHandle->LogFile = LogfListItemByName(L"Application");
if (pLogHandle->LogFile == NULL)
{
DPRINT1("Application log is missing!\n");
Status = STATUS_UNSUCCESSFUL;
@ -133,22 +133,22 @@ ElfCreateEventLogHandle(PLOGHANDLE* LogHandle,
}
/* Reset the current record */
lpLogHandle->CurrentRecord = 0;
pLogHandle->CurrentRecord = 0;
}
if (!lpLogHandle->LogFile)
if (!pLogHandle->LogFile)
Status = STATUS_UNSUCCESSFUL;
Done:
if (NT_SUCCESS(Status))
{
/* Append log handle */
InsertTailList(&LogHandleListHead, &lpLogHandle->LogHandleListEntry);
*LogHandle = lpLogHandle;
InsertTailList(&LogHandleListHead, &pLogHandle->LogHandleListEntry);
*LogHandle = pLogHandle;
}
else
{
HeapFree(GetProcessHeap(), 0, lpLogHandle);
HeapFree(GetProcessHeap(), 0, pLogHandle);
}
return Status;
@ -160,21 +160,23 @@ ElfCreateBackupLogHandle(PLOGHANDLE* LogHandle,
PUNICODE_STRING FileName)
{
NTSTATUS Status = STATUS_SUCCESS;
PLOGHANDLE lpLogHandle;
PLOGHANDLE pLogHandle;
DPRINT("ElfCreateBackupLogHandle(FileName: %wZ)\n", FileName);
DPRINT("ElfCreateBackupLogHandle(%wZ)\n", FileName);
*LogHandle = NULL;
lpLogHandle = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(LOGHANDLE));
if (lpLogHandle == NULL)
pLogHandle = HeapAlloc(GetProcessHeap(),
HEAP_ZERO_MEMORY,
sizeof(LOGHANDLE));
if (pLogHandle == NULL)
{
DPRINT1("Failed to allocate Heap!\n");
return STATUS_NO_MEMORY;
}
/* Create the log file */
Status = LogfCreate(&lpLogHandle->LogFile,
Status = LogfCreate(&pLogHandle->LogFile,
NULL,
FileName,
0,
@ -188,21 +190,21 @@ ElfCreateBackupLogHandle(PLOGHANDLE* LogHandle,
}
/* Set the backup flag */
lpLogHandle->Flags |= LOG_HANDLE_BACKUP_FILE;
pLogHandle->Flags |= LOG_HANDLE_BACKUP_FILE;
/* Reset the current record */
lpLogHandle->CurrentRecord = 0;
pLogHandle->CurrentRecord = 0;
Done:
if (NT_SUCCESS(Status))
{
/* Append log handle */
InsertTailList(&LogHandleListHead, &lpLogHandle->LogHandleListEntry);
*LogHandle = lpLogHandle;
InsertTailList(&LogHandleListHead, &pLogHandle->LogHandleListEntry);
*LogHandle = pLogHandle;
}
else
{
HeapFree(GetProcessHeap(), 0, lpLogHandle);
HeapFree(GetProcessHeap(), 0, pLogHandle);
}
return Status;
@ -213,18 +215,18 @@ static PLOGHANDLE
ElfGetLogHandleEntryByHandle(IELF_HANDLE EventLogHandle)
{
PLIST_ENTRY CurrentEntry;
PLOGHANDLE lpLogHandle;
PLOGHANDLE pLogHandle;
CurrentEntry = LogHandleListHead.Flink;
while (CurrentEntry != &LogHandleListHead)
{
lpLogHandle = CONTAINING_RECORD(CurrentEntry,
LOGHANDLE,
LogHandleListEntry);
pLogHandle = CONTAINING_RECORD(CurrentEntry,
LOGHANDLE,
LogHandleListEntry);
CurrentEntry = CurrentEntry->Flink;
if (lpLogHandle == EventLogHandle)
return lpLogHandle;
if (pLogHandle == EventLogHandle)
return pLogHandle;
}
return NULL;
@ -234,16 +236,16 @@ ElfGetLogHandleEntryByHandle(IELF_HANDLE EventLogHandle)
static NTSTATUS
ElfDeleteEventLogHandle(PIELF_HANDLE LogHandle)
{
PLOGHANDLE lpLogHandle;
PLOGHANDLE pLogHandle;
lpLogHandle = ElfGetLogHandleEntryByHandle(*LogHandle);
if (!lpLogHandle)
pLogHandle = ElfGetLogHandleEntryByHandle(*LogHandle);
if (!pLogHandle)
return STATUS_INVALID_HANDLE;
RemoveEntryList(&lpLogHandle->LogHandleListEntry);
LogfClose(lpLogHandle->LogFile, FALSE);
RemoveEntryList(&pLogHandle->LogHandleListEntry);
LogfClose(pLogHandle->LogFile, FALSE);
HeapFree(GetProcessHeap(), 0, lpLogHandle);
HeapFree(GetProcessHeap(), 0, pLogHandle);
*LogHandle = NULL;
@ -257,19 +259,19 @@ ElfrClearELFW(
IELF_HANDLE LogHandle,
PRPC_UNICODE_STRING BackupFileName)
{
PLOGHANDLE lpLogHandle;
PLOGHANDLE pLogHandle;
DPRINT("ElfrClearELFW()\n");
lpLogHandle = ElfGetLogHandleEntryByHandle(LogHandle);
if (!lpLogHandle)
pLogHandle = ElfGetLogHandleEntryByHandle(LogHandle);
if (!pLogHandle)
return STATUS_INVALID_HANDLE;
/* Fail, if the log file is a backup file */
if (lpLogHandle->Flags & LOG_HANDLE_BACKUP_FILE)
if (pLogHandle->Flags & LOG_HANDLE_BACKUP_FILE)
return STATUS_INVALID_HANDLE;
return LogfClearFile(lpLogHandle->LogFile,
return LogfClearFile(pLogHandle->LogFile,
(PUNICODE_STRING)BackupFileName);
}
@ -280,15 +282,15 @@ ElfrBackupELFW(
IELF_HANDLE LogHandle,
PRPC_UNICODE_STRING BackupFileName)
{
PLOGHANDLE lpLogHandle;
PLOGHANDLE pLogHandle;
DPRINT("ElfrBackupELFW()\n");
lpLogHandle = ElfGetLogHandleEntryByHandle(LogHandle);
if (!lpLogHandle)
pLogHandle = ElfGetLogHandleEntryByHandle(LogHandle);
if (!pLogHandle)
return STATUS_INVALID_HANDLE;
return LogfBackupFile(lpLogHandle->LogFile,
return LogfBackupFile(pLogHandle->LogFile,
(PUNICODE_STRING)BackupFileName);
}
@ -317,25 +319,25 @@ ElfrNumberOfRecords(
IELF_HANDLE LogHandle,
PULONG NumberOfRecords)
{
PLOGHANDLE lpLogHandle;
PLOGFILE lpLogFile;
PLOGHANDLE pLogHandle;
PLOGFILE pLogFile;
DPRINT("ElfrNumberOfRecords()\n");
lpLogHandle = ElfGetLogHandleEntryByHandle(LogHandle);
if (!lpLogHandle)
pLogHandle = ElfGetLogHandleEntryByHandle(LogHandle);
if (!pLogHandle)
return STATUS_INVALID_HANDLE;
if (!NumberOfRecords)
return STATUS_INVALID_PARAMETER;
lpLogFile = lpLogHandle->LogFile;
pLogFile = pLogHandle->LogFile;
DPRINT("Oldest: %lu Current: %lu\n",
lpLogFile->Header.OldestRecordNumber,
lpLogFile->Header.CurrentRecordNumber);
pLogFile->Header.OldestRecordNumber,
pLogFile->Header.CurrentRecordNumber);
if (lpLogFile->Header.OldestRecordNumber == 0)
if (pLogFile->Header.OldestRecordNumber == 0)
{
/* OldestRecordNumber == 0 when the log is empty */
*NumberOfRecords = 0;
@ -343,8 +345,8 @@ ElfrNumberOfRecords(
else
{
/* The log contains events */
*NumberOfRecords = lpLogFile->Header.CurrentRecordNumber -
lpLogFile->Header.OldestRecordNumber;
*NumberOfRecords = pLogFile->Header.CurrentRecordNumber -
pLogFile->Header.OldestRecordNumber;
}
return STATUS_SUCCESS;
@ -357,16 +359,16 @@ ElfrOldestRecord(
IELF_HANDLE LogHandle,
PULONG OldestRecordNumber)
{
PLOGHANDLE lpLogHandle;
PLOGHANDLE pLogHandle;
lpLogHandle = ElfGetLogHandleEntryByHandle(LogHandle);
if (!lpLogHandle)
pLogHandle = ElfGetLogHandleEntryByHandle(LogHandle);
if (!pLogHandle)
return STATUS_INVALID_HANDLE;
if (!OldestRecordNumber)
return STATUS_INVALID_PARAMETER;
*OldestRecordNumber = lpLogHandle->LogFile->Header.OldestRecordNumber;
*OldestRecordNumber = pLogHandle->LogFile->Header.OldestRecordNumber;
return STATUS_SUCCESS;
}
@ -477,11 +479,11 @@ ElfrReadELW(
PULONG MinNumberOfBytesNeeded)
{
NTSTATUS Status;
PLOGHANDLE lpLogHandle;
PLOGHANDLE pLogHandle;
ULONG RecordNumber;
lpLogHandle = ElfGetLogHandleEntryByHandle(LogHandle);
if (!lpLogHandle)
pLogHandle = ElfGetLogHandleEntryByHandle(LogHandle);
if (!pLogHandle)
return STATUS_INVALID_HANDLE;
if (!Buffer)
@ -490,14 +492,14 @@ ElfrReadELW(
/* If sequential read, retrieve the CurrentRecord from this log handle */
if (ReadFlags & EVENTLOG_SEQUENTIAL_READ)
{
RecordNumber = lpLogHandle->CurrentRecord;
RecordNumber = pLogHandle->CurrentRecord;
}
else // (ReadFlags & EVENTLOG_SEEK_READ)
{
RecordNumber = RecordOffset;
}
Status = LogfReadEvents(lpLogHandle->LogFile,
Status = LogfReadEvents(pLogHandle->LogFile,
ReadFlags,
&RecordNumber,
NumberOfBytesToRead,
@ -509,7 +511,7 @@ ElfrReadELW(
/* Update the handle's CurrentRecord if success */
if (NT_SUCCESS(Status))
{
lpLogHandle->CurrentRecord = RecordNumber;
pLogHandle->CurrentRecord = RecordNumber;
}
return Status;
@ -536,16 +538,16 @@ ElfrIntReportEventW(
PULONG TimeWritten)
{
NTSTATUS Status;
PLOGHANDLE lpLogHandle;
PLOGHANDLE pLogHandle;
PEVENTLOGRECORD LogBuffer;
USHORT i;
ULONG recSize;
SIZE_T RecSize;
ULONG dwStringsSize = 0;
ULONG dwUserSidLength = 0;
PWSTR lpStrings, str;
lpLogHandle = ElfGetLogHandleEntryByHandle(LogHandle);
if (!lpLogHandle)
pLogHandle = ElfGetLogHandleEntryByHandle(LogHandle);
if (!pLogHandle)
return STATUS_INVALID_HANDLE;
/* Flags must be 0 */
@ -606,14 +608,14 @@ ElfrIntReportEventW(
if (UserSID)
dwUserSidLength = FIELD_OFFSET(SID, SubAuthority[UserSID->SubAuthorityCount]);
LogBuffer = LogfAllocAndBuildNewRecord(&recSize,
LogBuffer = LogfAllocAndBuildNewRecord(&RecSize,
Time,
EventType,
EventCategory,
EventID,
(SourceName && SourceName->Buffer)
? SourceName->Buffer
: lpLogHandle->szName,
: pLogHandle->szName,
ComputerName->Buffer,
dwUserSidLength,
UserSID,
@ -622,11 +624,11 @@ ElfrIntReportEventW(
DataSize,
Data);
Status = LogfWriteRecord(lpLogHandle->LogFile, recSize, LogBuffer);
Status = LogfWriteRecord(pLogHandle->LogFile, RecSize, LogBuffer);
if (!NT_SUCCESS(Status))
{
DPRINT1("ERROR WRITING TO EventLog %S (Status 0x%08lx)\n",
lpLogHandle->LogFile->FileName, Status);
DPRINT1("ERROR writing to event log `%S' (Status 0x%08lx)\n",
pLogHandle->LogFile->LogName, Status);
}
if (NT_SUCCESS(Status))
@ -689,8 +691,8 @@ ElfrClearELFA(
IELF_HANDLE LogHandle,
PRPC_STRING BackupFileName)
{
UNICODE_STRING BackupFileNameW;
NTSTATUS Status;
UNICODE_STRING BackupFileNameW;
Status = RtlAnsiStringToUnicodeString(&BackupFileNameW,
(PANSI_STRING)BackupFileName,
@ -713,8 +715,8 @@ ElfrBackupELFA(
IELF_HANDLE LogHandle,
PRPC_STRING BackupFileName)
{
UNICODE_STRING BackupFileNameW;
NTSTATUS Status;
UNICODE_STRING BackupFileNameW;
Status = RtlAnsiStringToUnicodeString(&BackupFileNameW,
(PANSI_STRING)BackupFileName,
@ -741,8 +743,8 @@ ElfrOpenELA(
ULONG MinorVersion,
PIELF_HANDLE LogHandle)
{
UNICODE_STRING ModuleNameW;
NTSTATUS Status;
UNICODE_STRING ModuleNameW;
if ((MajorVersion != 1) || (MinorVersion != 1))
return STATUS_INVALID_PARAMETER;
@ -777,8 +779,8 @@ ElfrRegisterEventSourceA(
ULONG MinorVersion,
PIELF_HANDLE LogHandle)
{
UNICODE_STRING ModuleNameW;
NTSTATUS Status;
UNICODE_STRING ModuleNameW;
Status = RtlAnsiStringToUnicodeString(&ModuleNameW,
(PANSI_STRING)ModuleName,
@ -823,8 +825,8 @@ ElfrOpenBELA(
ULONG MinorVersion,
PIELF_HANDLE LogHandle)
{
UNICODE_STRING BackupFileNameW;
NTSTATUS Status;
UNICODE_STRING BackupFileNameW;
DPRINT("ElfrOpenBELA(%Z)\n", BackupFileName);
@ -868,11 +870,11 @@ ElfrReadELA(
PULONG MinNumberOfBytesNeeded)
{
NTSTATUS Status;
PLOGHANDLE lpLogHandle;
PLOGHANDLE pLogHandle;
ULONG RecordNumber;
lpLogHandle = ElfGetLogHandleEntryByHandle(LogHandle);
if (!lpLogHandle)
pLogHandle = ElfGetLogHandleEntryByHandle(LogHandle);
if (!pLogHandle)
return STATUS_INVALID_HANDLE;
if (!Buffer)
@ -881,14 +883,14 @@ ElfrReadELA(
/* If sequential read, retrieve the CurrentRecord from this log handle */
if (ReadFlags & EVENTLOG_SEQUENTIAL_READ)
{
RecordNumber = lpLogHandle->CurrentRecord;
RecordNumber = pLogHandle->CurrentRecord;
}
else // (ReadFlags & EVENTLOG_SEEK_READ)
{
RecordNumber = RecordOffset;
}
Status = LogfReadEvents(lpLogHandle->LogFile,
Status = LogfReadEvents(pLogHandle->LogFile,
ReadFlags,
&RecordNumber,
NumberOfBytesToRead,
@ -900,7 +902,7 @@ ElfrReadELA(
/* Update the handle's CurrentRecord if success */
if (NT_SUCCESS(Status))
{
lpLogHandle->CurrentRecord = RecordNumber;
pLogHandle->CurrentRecord = RecordNumber;
}
return Status;
@ -925,9 +927,9 @@ ElfrReportEventA(
PULONG RecordNumber,
PULONG TimeWritten)
{
NTSTATUS Status = STATUS_SUCCESS;
UNICODE_STRING ComputerNameW;
PUNICODE_STRING *StringsArrayW = NULL;
NTSTATUS Status = STATUS_SUCCESS;
USHORT i;
DPRINT("ElfrReportEventA(%hu)\n", NumStrings);
@ -1009,13 +1011,10 @@ Done:
{
for (i = 0; i < NumStrings; i++)
{
if (StringsArrayW[i] != NULL)
if ((StringsArrayW[i] != NULL) && (StringsArrayW[i]->Buffer))
{
if (StringsArrayW[i]->Buffer)
{
RtlFreeUnicodeString(StringsArrayW[i]);
HeapFree(GetProcessHeap(), 0, StringsArrayW[i]);
}
RtlFreeUnicodeString(StringsArrayW[i]);
HeapFree(GetProcessHeap(), 0, StringsArrayW[i]);
}
}
@ -1068,10 +1067,10 @@ ElfrGetLogInformation(
PULONG pcbBytesNeeded)
{
NTSTATUS Status = STATUS_SUCCESS;
PLOGHANDLE lpLogHandle;
PLOGHANDLE pLogHandle;
lpLogHandle = ElfGetLogHandleEntryByHandle(LogHandle);
if (!lpLogHandle)
pLogHandle = ElfGetLogHandleEntryByHandle(LogHandle);
if (!pLogHandle)
return STATUS_INVALID_HANDLE;
switch (InfoLevel)
@ -1110,10 +1109,10 @@ NTSTATUS
ElfrFlushEL(
IELF_HANDLE LogHandle)
{
PLOGHANDLE lpLogHandle;
PLOGHANDLE pLogHandle;
lpLogHandle = ElfGetLogHandleEntryByHandle(LogHandle);
if (!lpLogHandle)
pLogHandle = ElfGetLogHandleEntryByHandle(LogHandle);
if (!pLogHandle)
return STATUS_INVALID_HANDLE;
UNIMPLEMENTED;