Author: hbelusca
Date: Tue Oct 25 23:32:20 2016
New Revision: 73034
URL:
http://svn.reactos.org/svn/reactos?rev=73034&view=rev
Log:
[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.
Modified:
trunk/reactos/base/services/eventlog/eventlog.c
trunk/reactos/base/services/eventlog/eventlog.h
trunk/reactos/base/services/eventlog/eventsource.c
trunk/reactos/base/services/eventlog/file.c
trunk/reactos/base/services/eventlog/logport.c
trunk/reactos/base/services/eventlog/rpc.c
Modified: trunk/reactos/base/services/eventlog/eventlog.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/services/eventlog/eve…
==============================================================================
--- trunk/reactos/base/services/eventlog/eventlog.c [iso-8859-1] (original)
+++ trunk/reactos/base/services/eventlog/eventlog.c [iso-8859-1] Tue Oct 25 23:32:20 2016
@@ -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 @@
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 @@
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 @@
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 @@
{
LONG Result;
DWORD MaxLognameLen, LognameLen;
+ DWORD dwIndex;
PWSTR Buf = NULL;
- DWORD dwIndex;
PLOGFILE pLogFile;
Result = RegQueryInfoKeyW(eventlogKey, NULL, NULL, NULL, NULL, &MaxLognameLen,
@@ -464,7 +463,7 @@
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 @@
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 @@
}
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 @@
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);
Modified: trunk/reactos/base/services/eventlog/eventlog.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/services/eventlog/eve…
==============================================================================
--- trunk/reactos/base/services/eventlog/eventlog.h [iso-8859-1] (original)
+++ trunk/reactos/base/services/eventlog/eventlog.h [iso-8859-1] Tue Oct 25 23:32:20 2016
@@ -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 @@
/* file.c */
VOID LogfListInitialize(VOID);
-
DWORD LogfListItemCount(VOID);
-
PLOGFILE LogfListItemByIndex(DWORD Index);
-
PLOGFILE LogfListItemByName(LPCWSTR Name);
-
// DWORD LogfListItemIndexByName(WCHAR * Name);
@@ -195,19 +191,19 @@
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 @@
USHORT wCategory,
ULONG dwEventId,
USHORT wNumStrings,
- PWSTR lpStrings,
+ PWSTR pStrings,
ULONG dwDataSize,
- PVOID lpRawData);
+ PVOID pRawData);
/* logport.c */
Modified: trunk/reactos/base/services/eventlog/eventsource.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/services/eventlog/eve…
==============================================================================
--- trunk/reactos/base/services/eventlog/eventsource.c [iso-8859-1] (original)
+++ trunk/reactos/base/services/eventlog/eventsource.c [iso-8859-1] Tue Oct 25 23:32:20
2016
@@ -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 @@
}
/* 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)
Modified: trunk/reactos/base/services/eventlog/file.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/services/eventlog/fil…
==============================================================================
--- trunk/reactos/base/services/eventlog/file.c [iso-8859-1] (original)
+++ trunk/reactos/base/services/eventlog/file.c [iso-8859-1] Tue Oct 25 23:32:20 2016
@@ -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 @@
}
if (LogName)
- StringCchCopy(pLogFile->LogName, LogNameLen, LogName);
+ StringCchCopyW(pLogFile->LogName, LogNameLen, LogName);
pLogFile->FileName = RtlAllocateHeap(GetProcessHeap(),
HEAP_ZERO_MEMORY,
@@ -1099,9 +1098,9 @@
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 @@
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)
-{
- DWORD dwRecSize;
+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)
+{
+ 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));
-
- dwRecSize += dwSidLength;
+ RecSize = ROUND_UP(RecSize, sizeof(ULONG));
+
+ 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);
-
- Buffer = RtlAllocateHeap(GetProcessHeap(), HEAP_ZERO_MEMORY, dwRecSize);
+ RecSize += sizeof(ULONG);
+
+ Buffer = RtlAllocateHeap(GetProcessHeap(), HEAP_ZERO_MEMORY, RecSize);
if (!Buffer)
{
DPRINT1("Cannot allocate heap!\n");
@@ -2186,7 +2185,7 @@
}
pRec = (PEVENTLOGRECORD)Buffer;
- pRec->Length = dwRecSize;
+ pRec->Length = RecSize;
pRec->Reserved = LOGFILE_SIGNATURE;
/*
@@ -2211,10 +2210,10 @@
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 @@
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 @@
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 @@
pos = ROUND_UP(pos, sizeof(ULONG));
/* Initialize the trailing 'Length' member */
- *((PDWORD) (Buffer + pos)) = dwRecSize;
-
- *lpRecSize = dwRecSize;
+ *((PDWORD)(Buffer + pos)) = RecSize;
+
+ *pRecSize = RecSize;
return pRec;
}
@@ -2265,17 +2264,17 @@
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 @@
NtQuerySystemTime(&SystemTime);
RtlTimeToSecondsSince1970(&SystemTime, &Time);
- logBuffer = LogfAllocAndBuildNewRecord(&recSize,
+ LogBuffer = LogfAllocAndBuildNewRecord(&RecSize,
Time,
wType,
wCategory,
@@ -2298,16 +2297,16 @@
0,
NULL,
wNumStrings,
- lpStrings,
+ pStrings,
dwDataSize,
- lpRawData);
-
- Status = LogfWriteRecord(EventLogSource->LogFile, recSize, logBuffer);
+ pRawData);
+
+ Status = LogfWriteRecord(EventLogSource->LogFile, RecSize, LogBuffer);
if (!NT_SUCCESS(Status))
{
- DPRINT1("ERROR WRITING TO EventLog %S (Status 0x%08lx)\n",
- EventLogSource->LogFile->FileName, Status);
- }
-
- LogfFreeRecord(logBuffer);
+ DPRINT1("ERROR writing to event log `%S' (Status 0x%08lx)\n",
+ EventLogSource->LogFile->LogName, Status);
+ }
+
+ LogfFreeRecord(LogBuffer);
}
Modified: trunk/reactos/base/services/eventlog/logport.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/services/eventlog/log…
==============================================================================
--- trunk/reactos/base/services/eventlog/logport.c [iso-8859-1] (original)
+++ trunk/reactos/base/services/eventlog/logport.c [iso-8859-1] Tue Oct 25 23:32:20 2016
@@ -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 InitLogPort(VOID)
{
+ NTSTATUS Status;
+ UNICODE_STRING PortName;
OBJECT_ATTRIBUTES ObjectAttributes;
- UNICODE_STRING PortName;
PORT_MESSAGE Request;
- NTSTATUS Status;
ConnectPortHandle = NULL;
MessagePortHandle = NULL;
@@ -105,12 +104,12 @@
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 @@
// TODO: Log more information??
pRec = LogfAllocAndBuildNewRecord(
- &dwRecSize,
+ &RecSize,
Time,
Message->Type,
Message->EntryData.EventCategory,
@@ -180,7 +179,7 @@
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 @@
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);
}
}
Modified: trunk/reactos/base/services/eventlog/rpc.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/services/eventlog/rpc…
==============================================================================
--- trunk/reactos/base/services/eventlog/rpc.c [iso-8859-1] (original)
+++ trunk/reactos/base/services/eventlog/rpc.c [iso-8859-1] Tue Oct 25 23:32:20 2016
@@ -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 @@
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 @@
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 @@
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 @@
}
/* Reset the current record */
- lpLogHandle->CurrentRecord = 0;
- }
-
- if (!lpLogHandle->LogFile)
+ pLogHandle->CurrentRecord = 0;
+ }
+
+ 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 @@
PUNICODE_STRING FileName)
{
NTSTATUS Status = STATUS_SUCCESS;
- PLOGHANDLE lpLogHandle;
-
- DPRINT("ElfCreateBackupLogHandle(FileName: %wZ)\n", FileName);
+ PLOGHANDLE pLogHandle;
+
+ 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 @@
}
/* 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 @@
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 @@
static NTSTATUS
ElfDeleteEventLogHandle(PIELF_HANDLE LogHandle)
{
- PLOGHANDLE lpLogHandle;
-
- lpLogHandle = ElfGetLogHandleEntryByHandle(*LogHandle);
- if (!lpLogHandle)
+ PLOGHANDLE pLogHandle;
+
+ pLogHandle = ElfGetLogHandleEntryByHandle(*LogHandle);
+ if (!pLogHandle)
return STATUS_INVALID_HANDLE;
- RemoveEntryList(&lpLogHandle->LogHandleListEntry);
- LogfClose(lpLogHandle->LogFile, FALSE);
-
- HeapFree(GetProcessHeap(), 0, lpLogHandle);
+ RemoveEntryList(&pLogHandle->LogHandleListEntry);
+ LogfClose(pLogHandle->LogFile, FALSE);
+
+ HeapFree(GetProcessHeap(), 0, pLogHandle);
*LogHandle = NULL;
@@ -257,19 +259,19 @@
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 @@
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 @@
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);
-
- if (lpLogFile->Header.OldestRecordNumber == 0)
+ pLogFile->Header.OldestRecordNumber,
+ pLogFile->Header.CurrentRecordNumber);
+
+ if (pLogFile->Header.OldestRecordNumber == 0)
{
/* OldestRecordNumber == 0 when the log is empty */
*NumberOfRecords = 0;
@@ -343,8 +345,8 @@
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 @@
IELF_HANDLE LogHandle,
PULONG OldestRecordNumber)
{
- PLOGHANDLE lpLogHandle;
-
- lpLogHandle = ElfGetLogHandleEntryByHandle(LogHandle);
- if (!lpLogHandle)
+ PLOGHANDLE pLogHandle;
+
+ 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 @@
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 @@
/* 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 @@
/* Update the handle's CurrentRecord if success */
if (NT_SUCCESS(Status))
{
- lpLogHandle->CurrentRecord = RecordNumber;
+ pLogHandle->CurrentRecord = RecordNumber;
}
return Status;
@@ -536,16 +538,16 @@
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 @@
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 @@
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 @@
IELF_HANDLE LogHandle,
PRPC_STRING BackupFileName)
{
+ NTSTATUS Status;
UNICODE_STRING BackupFileNameW;
- NTSTATUS Status;
Status = RtlAnsiStringToUnicodeString(&BackupFileNameW,
(PANSI_STRING)BackupFileName,
@@ -713,8 +715,8 @@
IELF_HANDLE LogHandle,
PRPC_STRING BackupFileName)
{
+ NTSTATUS Status;
UNICODE_STRING BackupFileNameW;
- NTSTATUS Status;
Status = RtlAnsiStringToUnicodeString(&BackupFileNameW,
(PANSI_STRING)BackupFileName,
@@ -741,8 +743,8 @@
ULONG MinorVersion,
PIELF_HANDLE LogHandle)
{
+ NTSTATUS Status;
UNICODE_STRING ModuleNameW;
- NTSTATUS Status;
if ((MajorVersion != 1) || (MinorVersion != 1))
return STATUS_INVALID_PARAMETER;
@@ -777,8 +779,8 @@
ULONG MinorVersion,
PIELF_HANDLE LogHandle)
{
+ NTSTATUS Status;
UNICODE_STRING ModuleNameW;
- NTSTATUS Status;
Status = RtlAnsiStringToUnicodeString(&ModuleNameW,
(PANSI_STRING)ModuleName,
@@ -823,8 +825,8 @@
ULONG MinorVersion,
PIELF_HANDLE LogHandle)
{
+ NTSTATUS Status;
UNICODE_STRING BackupFileNameW;
- NTSTATUS Status;
DPRINT("ElfrOpenBELA(%Z)\n", BackupFileName);
@@ -868,11 +870,11 @@
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 @@
/* 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 @@
/* Update the handle's CurrentRecord if success */
if (NT_SUCCESS(Status))
{
- lpLogHandle->CurrentRecord = RecordNumber;
+ pLogHandle->CurrentRecord = RecordNumber;
}
return Status;
@@ -925,9 +927,9 @@
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 @@
{
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 @@
PULONG pcbBytesNeeded)
{
NTSTATUS Status = STATUS_SUCCESS;
- PLOGHANDLE lpLogHandle;
-
- lpLogHandle = ElfGetLogHandleEntryByHandle(LogHandle);
- if (!lpLogHandle)
+ PLOGHANDLE pLogHandle;
+
+ pLogHandle = ElfGetLogHandleEntryByHandle(LogHandle);
+ if (!pLogHandle)
return STATUS_INVALID_HANDLE;
switch (InfoLevel)
@@ -1110,10 +1109,10 @@
ElfrFlushEL(
IELF_HANDLE LogHandle)
{
- PLOGHANDLE lpLogHandle;
-
- lpLogHandle = ElfGetLogHandleEntryByHandle(LogHandle);
- if (!lpLogHandle)
+ PLOGHANDLE pLogHandle;
+
+ pLogHandle = ElfGetLogHandleEntryByHandle(LogHandle);
+ if (!pLogHandle)
return STATUS_INVALID_HANDLE;
UNIMPLEMENTED;