2005-06-01 21:57:52 +00:00
|
|
|
/*
|
2002-06-25 21:10:14 +00:00
|
|
|
* PROJECT: ReactOS kernel
|
2006-03-04 17:04:42 +00:00
|
|
|
* LICENSE: GPL - See COPYING in the top level directory
|
2002-06-25 21:10:14 +00:00
|
|
|
* FILE: services/eventlog/eventlog.c
|
|
|
|
* PURPOSE: Event logging service
|
2006-03-04 17:04:42 +00:00
|
|
|
* COPYRIGHT: Copyright 2002 Eric Kohl
|
|
|
|
* Copyright 2005 Saveliy Tretiakov
|
2002-06-25 21:10:14 +00:00
|
|
|
*/
|
|
|
|
|
2006-06-30 14:53:24 +00:00
|
|
|
/* INCLUDES *****************************************************************/
|
2002-06-25 21:10:14 +00:00
|
|
|
|
|
|
|
#include "eventlog.h"
|
|
|
|
|
2014-01-13 12:46:06 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <netevent.h>
|
|
|
|
|
2013-12-21 13:45:16 +00:00
|
|
|
#define NDEBUG
|
|
|
|
#include <debug.h>
|
|
|
|
|
2006-06-30 14:53:24 +00:00
|
|
|
/* GLOBALS ******************************************************************/
|
2002-06-25 21:10:14 +00:00
|
|
|
|
2010-02-20 12:59:53 +00:00
|
|
|
static VOID CALLBACK ServiceMain(DWORD, LPWSTR *);
|
|
|
|
static WCHAR ServiceName[] = L"EventLog";
|
|
|
|
static SERVICE_TABLE_ENTRYW ServiceTable[2] =
|
2005-06-01 21:57:52 +00:00
|
|
|
{
|
2010-02-20 12:59:53 +00:00
|
|
|
{ ServiceName, ServiceMain },
|
2007-05-03 07:47:12 +00:00
|
|
|
{ NULL, NULL }
|
2005-06-01 21:57:52 +00:00
|
|
|
};
|
2002-06-25 21:10:14 +00:00
|
|
|
|
2010-03-14 12:26:49 +00:00
|
|
|
SERVICE_STATUS ServiceStatus;
|
|
|
|
SERVICE_STATUS_HANDLE ServiceStatusHandle;
|
|
|
|
|
2007-05-03 07:47:12 +00:00
|
|
|
BOOL onLiveCD = FALSE; // On livecd events will go to debug output only
|
2005-09-20 07:58:28 +00:00
|
|
|
HANDLE MyHeap = NULL;
|
2006-06-30 14:53:24 +00:00
|
|
|
|
|
|
|
/* FUNCTIONS ****************************************************************/
|
2006-06-29 17:36:04 +00:00
|
|
|
|
2010-03-14 12:26:49 +00:00
|
|
|
static VOID
|
|
|
|
UpdateServiceStatus(DWORD dwState)
|
|
|
|
{
|
|
|
|
ServiceStatus.dwServiceType = SERVICE_WIN32_OWN_PROCESS;
|
|
|
|
ServiceStatus.dwCurrentState = dwState;
|
|
|
|
ServiceStatus.dwControlsAccepted = 0;
|
|
|
|
ServiceStatus.dwWin32ExitCode = 0;
|
|
|
|
ServiceStatus.dwServiceSpecificExitCode = 0;
|
|
|
|
ServiceStatus.dwCheckPoint = 0;
|
|
|
|
|
|
|
|
if (dwState == SERVICE_START_PENDING ||
|
|
|
|
dwState == SERVICE_STOP_PENDING ||
|
|
|
|
dwState == SERVICE_PAUSE_PENDING ||
|
|
|
|
dwState == SERVICE_CONTINUE_PENDING)
|
|
|
|
ServiceStatus.dwWaitHint = 10000;
|
|
|
|
else
|
|
|
|
ServiceStatus.dwWaitHint = 0;
|
|
|
|
|
|
|
|
SetServiceStatus(ServiceStatusHandle,
|
|
|
|
&ServiceStatus);
|
|
|
|
}
|
|
|
|
|
2010-02-20 12:59:53 +00:00
|
|
|
static DWORD WINAPI
|
|
|
|
ServiceControlHandler(DWORD dwControl,
|
|
|
|
DWORD dwEventType,
|
|
|
|
LPVOID lpEventData,
|
|
|
|
LPVOID lpContext)
|
|
|
|
{
|
2010-03-14 12:26:49 +00:00
|
|
|
DPRINT("ServiceControlHandler() called\n");
|
|
|
|
|
|
|
|
switch (dwControl)
|
|
|
|
{
|
|
|
|
case SERVICE_CONTROL_STOP:
|
|
|
|
DPRINT(" SERVICE_CONTROL_STOP received\n");
|
2011-12-04 10:53:43 +00:00
|
|
|
|
|
|
|
LogfReportEvent(EVENTLOG_INFORMATION_TYPE,
|
|
|
|
0,
|
|
|
|
EVENT_EventlogStopped, 0, NULL, 0, NULL);
|
|
|
|
|
|
|
|
|
2011-08-15 20:55:07 +00:00
|
|
|
/* Stop listening to incoming RPC messages */
|
|
|
|
RpcMgmtStopServerListening(NULL);
|
2010-03-14 12:26:49 +00:00
|
|
|
UpdateServiceStatus(SERVICE_STOPPED);
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
|
|
|
|
case SERVICE_CONTROL_PAUSE:
|
|
|
|
DPRINT(" SERVICE_CONTROL_PAUSE received\n");
|
|
|
|
UpdateServiceStatus(SERVICE_PAUSED);
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
|
|
|
|
case SERVICE_CONTROL_CONTINUE:
|
|
|
|
DPRINT(" SERVICE_CONTROL_CONTINUE received\n");
|
|
|
|
UpdateServiceStatus(SERVICE_RUNNING);
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
|
|
|
|
case SERVICE_CONTROL_INTERROGATE:
|
|
|
|
DPRINT(" SERVICE_CONTROL_INTERROGATE received\n");
|
|
|
|
SetServiceStatus(ServiceStatusHandle,
|
|
|
|
&ServiceStatus);
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
|
|
|
|
case SERVICE_CONTROL_SHUTDOWN:
|
|
|
|
DPRINT(" SERVICE_CONTROL_SHUTDOWN received\n");
|
2011-12-04 10:53:43 +00:00
|
|
|
|
|
|
|
LogfReportEvent(EVENTLOG_INFORMATION_TYPE,
|
|
|
|
0,
|
|
|
|
EVENT_EventlogStopped, 0, NULL, 0, NULL);
|
|
|
|
|
2010-03-14 12:26:49 +00:00
|
|
|
UpdateServiceStatus(SERVICE_STOPPED);
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
|
|
|
|
default :
|
2013-03-14 16:51:39 +00:00
|
|
|
DPRINT1(" Control %lu received\n", dwControl);
|
2010-03-14 12:26:49 +00:00
|
|
|
return ERROR_CALL_NOT_IMPLEMENTED;
|
|
|
|
}
|
2010-02-20 12:59:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static DWORD
|
|
|
|
ServiceInit(VOID)
|
2002-06-25 21:10:14 +00:00
|
|
|
{
|
2005-09-20 07:58:28 +00:00
|
|
|
HANDLE hThread;
|
|
|
|
|
|
|
|
hThread = CreateThread(NULL,
|
|
|
|
0,
|
|
|
|
(LPTHREAD_START_ROUTINE)
|
|
|
|
PortThreadRoutine,
|
|
|
|
NULL,
|
|
|
|
0,
|
|
|
|
NULL);
|
2007-05-03 07:47:12 +00:00
|
|
|
|
|
|
|
if (!hThread)
|
2010-02-20 12:59:53 +00:00
|
|
|
{
|
2007-05-03 07:47:12 +00:00
|
|
|
DPRINT("Can't create PortThread\n");
|
2010-02-20 12:59:53 +00:00
|
|
|
return GetLastError();
|
|
|
|
}
|
2007-05-03 07:47:12 +00:00
|
|
|
else
|
|
|
|
CloseHandle(hThread);
|
|
|
|
|
2005-09-20 07:58:28 +00:00
|
|
|
hThread = CreateThread(NULL,
|
|
|
|
0,
|
|
|
|
(LPTHREAD_START_ROUTINE)
|
|
|
|
RpcThreadRoutine,
|
|
|
|
NULL,
|
|
|
|
0,
|
|
|
|
NULL);
|
|
|
|
|
2007-05-03 07:47:12 +00:00
|
|
|
if (!hThread)
|
2010-02-20 12:59:53 +00:00
|
|
|
{
|
2007-05-03 07:47:12 +00:00
|
|
|
DPRINT("Can't create RpcThread\n");
|
2010-02-20 12:59:53 +00:00
|
|
|
return GetLastError();
|
|
|
|
}
|
2007-05-03 07:47:12 +00:00
|
|
|
else
|
|
|
|
CloseHandle(hThread);
|
2010-02-20 12:59:53 +00:00
|
|
|
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-05-10 20:19:14 +00:00
|
|
|
static VOID
|
|
|
|
ReportProductInfoEvent(VOID)
|
|
|
|
{
|
|
|
|
OSVERSIONINFOW versionInfo;
|
|
|
|
WCHAR szBuffer[512];
|
|
|
|
DWORD dwLength;
|
|
|
|
HKEY hKey;
|
|
|
|
DWORD dwValueLength;
|
|
|
|
DWORD dwType;
|
|
|
|
LONG lResult = ERROR_SUCCESS;
|
|
|
|
|
|
|
|
ZeroMemory(&versionInfo, sizeof(OSVERSIONINFO));
|
|
|
|
versionInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
|
|
|
|
|
|
|
|
/* Get version information */
|
|
|
|
if (!GetVersionExW(&versionInfo))
|
|
|
|
return;
|
|
|
|
|
|
|
|
ZeroMemory(szBuffer, 512 * sizeof(WCHAR));
|
|
|
|
|
|
|
|
/* Write version into the buffer */
|
|
|
|
dwLength = swprintf(szBuffer,
|
|
|
|
L"%lu.%lu",
|
|
|
|
versionInfo.dwMajorVersion,
|
|
|
|
versionInfo.dwMinorVersion) + 1;
|
|
|
|
|
|
|
|
/* Write build number into the buffer */
|
|
|
|
dwLength += swprintf(&szBuffer[dwLength],
|
|
|
|
L"%lu",
|
|
|
|
versionInfo.dwBuildNumber) + 1;
|
|
|
|
|
|
|
|
/* Write service pack info into the buffer */
|
|
|
|
wcscpy(&szBuffer[dwLength], versionInfo.szCSDVersion);
|
|
|
|
dwLength += wcslen(versionInfo.szCSDVersion) + 1;
|
|
|
|
|
|
|
|
/* 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);
|
|
|
|
if (lResult == ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
dwValueLength = 512 - dwLength;
|
|
|
|
lResult = RegQueryValueEx(hKey,
|
|
|
|
L"CurrentType",
|
|
|
|
NULL,
|
|
|
|
&dwType,
|
|
|
|
(LPBYTE)&szBuffer[dwLength],
|
|
|
|
&dwValueLength);
|
|
|
|
|
|
|
|
RegCloseKey(hKey);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Log the product information */
|
|
|
|
LogfReportEvent(EVENTLOG_INFORMATION_TYPE,
|
|
|
|
0,
|
|
|
|
EVENT_EventLogProductInfo,
|
|
|
|
4,
|
|
|
|
szBuffer,
|
|
|
|
0,
|
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-02-20 12:59:53 +00:00
|
|
|
static VOID CALLBACK
|
|
|
|
ServiceMain(DWORD argc,
|
|
|
|
LPWSTR *argv)
|
|
|
|
{
|
|
|
|
DWORD dwError;
|
|
|
|
|
|
|
|
UNREFERENCED_PARAMETER(argc);
|
|
|
|
UNREFERENCED_PARAMETER(argv);
|
|
|
|
|
|
|
|
DPRINT("ServiceMain() called\n");
|
|
|
|
|
|
|
|
ServiceStatusHandle = RegisterServiceCtrlHandlerExW(ServiceName,
|
|
|
|
ServiceControlHandler,
|
|
|
|
NULL);
|
|
|
|
if (!ServiceStatusHandle)
|
|
|
|
{
|
|
|
|
dwError = GetLastError();
|
|
|
|
DPRINT1("RegisterServiceCtrlHandlerW() failed! (Error %lu)\n", dwError);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-03-14 12:26:49 +00:00
|
|
|
UpdateServiceStatus(SERVICE_START_PENDING);
|
2010-02-20 12:59:53 +00:00
|
|
|
|
|
|
|
dwError = ServiceInit();
|
|
|
|
if (dwError != ERROR_SUCCESS)
|
|
|
|
{
|
2010-03-14 12:26:49 +00:00
|
|
|
DPRINT("Service stopped (dwError: %lu\n", dwError);
|
|
|
|
UpdateServiceStatus(SERVICE_START_PENDING);
|
2010-02-20 12:59:53 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-03-14 12:26:49 +00:00
|
|
|
DPRINT("Service started\n");
|
|
|
|
UpdateServiceStatus(SERVICE_RUNNING);
|
2011-05-01 13:35:51 +00:00
|
|
|
|
2011-05-10 20:19:14 +00:00
|
|
|
ReportProductInfoEvent();
|
|
|
|
|
2011-05-01 13:35:51 +00:00
|
|
|
LogfReportEvent(EVENTLOG_INFORMATION_TYPE,
|
|
|
|
0,
|
2011-05-10 20:19:14 +00:00
|
|
|
EVENT_EventlogStarted,
|
|
|
|
0,
|
|
|
|
NULL,
|
|
|
|
0,
|
|
|
|
NULL);
|
2010-02-20 12:59:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
DPRINT("ServiceMain() done\n");
|
2005-09-20 07:58:28 +00:00
|
|
|
}
|
2002-06-25 21:10:14 +00:00
|
|
|
|
2010-02-20 12:59:53 +00:00
|
|
|
|
2011-04-30 22:33:53 +00:00
|
|
|
PLOGFILE LoadLogFile(HKEY hKey, WCHAR * LogName)
|
2005-09-20 07:58:28 +00:00
|
|
|
{
|
2007-05-03 07:47:12 +00:00
|
|
|
DWORD MaxValueLen, ValueLen, Type, ExpandedLen;
|
|
|
|
WCHAR *Buf = NULL, *Expanded = NULL;
|
|
|
|
LONG Result;
|
2012-01-16 23:23:29 +00:00
|
|
|
PLOGFILE pLogf = NULL;
|
|
|
|
UNICODE_STRING FileName;
|
|
|
|
NTSTATUS Status;
|
2007-05-03 07:47:12 +00:00
|
|
|
|
|
|
|
DPRINT("LoadLogFile: %S\n", LogName);
|
|
|
|
|
|
|
|
RegQueryInfoKey(hKey, NULL, NULL, NULL, NULL, NULL, NULL,
|
|
|
|
NULL, NULL, &MaxValueLen, NULL, NULL);
|
|
|
|
|
|
|
|
Buf = HeapAlloc(MyHeap, 0, MaxValueLen);
|
|
|
|
if (!Buf)
|
|
|
|
{
|
|
|
|
DPRINT1("Can't allocate heap!\n");
|
2011-04-30 22:33:53 +00:00
|
|
|
return NULL;
|
2007-05-03 07:47:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ValueLen = MaxValueLen;
|
|
|
|
|
|
|
|
Result = RegQueryValueEx(hKey,
|
|
|
|
L"File",
|
|
|
|
NULL,
|
|
|
|
&Type,
|
|
|
|
(LPBYTE) Buf,
|
|
|
|
&ValueLen);
|
|
|
|
if (Result != ERROR_SUCCESS)
|
|
|
|
{
|
2013-03-14 16:51:39 +00:00
|
|
|
DPRINT1("RegQueryValueEx failed: %lu\n", GetLastError());
|
2007-05-03 07:47:12 +00:00
|
|
|
HeapFree(MyHeap, 0, Buf);
|
2011-04-30 22:33:53 +00:00
|
|
|
return NULL;
|
2007-05-03 07:47:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (Type != REG_EXPAND_SZ && Type != REG_SZ)
|
|
|
|
{
|
|
|
|
DPRINT1("%S\\File - value of wrong type %x.\n", LogName, Type);
|
|
|
|
HeapFree(MyHeap, 0, Buf);
|
2011-04-30 22:33:53 +00:00
|
|
|
return NULL;
|
2007-05-03 07:47:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ExpandedLen = ExpandEnvironmentStrings(Buf, NULL, 0);
|
|
|
|
Expanded = HeapAlloc(MyHeap, 0, ExpandedLen * sizeof(WCHAR));
|
|
|
|
if (!Expanded)
|
|
|
|
{
|
|
|
|
DPRINT1("Can't allocate heap!\n");
|
|
|
|
HeapFree(MyHeap, 0, Buf);
|
2011-04-30 22:33:53 +00:00
|
|
|
return NULL;
|
2007-05-03 07:47:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ExpandEnvironmentStrings(Buf, Expanded, ExpandedLen);
|
|
|
|
|
2012-01-16 23:23:29 +00:00
|
|
|
if (!RtlDosPathNameToNtPathName_U(Expanded, &FileName,
|
|
|
|
NULL, NULL))
|
|
|
|
{
|
|
|
|
DPRINT1("Can't convert path!\n");
|
|
|
|
HeapFree(MyHeap, 0, Expanded);
|
|
|
|
HeapFree(MyHeap, 0, Buf);
|
|
|
|
return NULL;
|
|
|
|
}
|
2007-05-03 07:47:12 +00:00
|
|
|
|
2012-01-16 23:23:29 +00:00
|
|
|
DPRINT("%S -> %S\n", Buf, Expanded);
|
2007-05-03 07:47:12 +00:00
|
|
|
|
2012-01-28 20:15:41 +00:00
|
|
|
Status = LogfCreate(&pLogf, LogName, &FileName, TRUE, FALSE);
|
2012-01-16 23:23:29 +00:00
|
|
|
if (!NT_SUCCESS(Status))
|
2007-05-03 07:47:12 +00:00
|
|
|
{
|
2012-01-16 23:23:29 +00:00
|
|
|
DPRINT1("Failed to create %S! (Status %08lx)\n", Expanded, Status);
|
2007-05-03 07:47:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
HeapFree(MyHeap, 0, Buf);
|
|
|
|
HeapFree(MyHeap, 0, Expanded);
|
2011-04-30 22:33:53 +00:00
|
|
|
return pLogf;
|
2006-06-30 14:53:24 +00:00
|
|
|
}
|
2007-05-03 07:47:12 +00:00
|
|
|
|
2006-06-30 14:53:24 +00:00
|
|
|
BOOL LoadLogFiles(HKEY eventlogKey)
|
|
|
|
{
|
2007-05-03 07:47:12 +00:00
|
|
|
LONG result;
|
|
|
|
DWORD MaxLognameLen, LognameLen;
|
|
|
|
WCHAR *Buf = NULL;
|
|
|
|
INT i;
|
2011-04-30 22:33:53 +00:00
|
|
|
PLOGFILE pLogFile;
|
2007-05-03 07:47:12 +00:00
|
|
|
|
|
|
|
RegQueryInfoKey(eventlogKey,
|
|
|
|
NULL, NULL, NULL, NULL,
|
|
|
|
&MaxLognameLen,
|
|
|
|
NULL, NULL, NULL, NULL, NULL, NULL);
|
|
|
|
|
|
|
|
MaxLognameLen++;
|
|
|
|
|
|
|
|
Buf = HeapAlloc(MyHeap, 0, MaxLognameLen * sizeof(WCHAR));
|
|
|
|
|
|
|
|
if (!Buf)
|
|
|
|
{
|
|
|
|
DPRINT1("Error: can't allocate heap!\n");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
i = 0;
|
|
|
|
LognameLen = MaxLognameLen;
|
|
|
|
|
|
|
|
while (RegEnumKeyEx(eventlogKey,
|
|
|
|
i,
|
|
|
|
Buf,
|
|
|
|
&LognameLen,
|
|
|
|
NULL, NULL, NULL, NULL) == ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
HKEY SubKey;
|
|
|
|
|
|
|
|
DPRINT("%S\n", Buf);
|
|
|
|
|
|
|
|
result = RegOpenKeyEx(eventlogKey, Buf, 0, KEY_ALL_ACCESS, &SubKey);
|
|
|
|
if (result != ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
DPRINT1("Failed to open %S key.\n", Buf);
|
|
|
|
HeapFree(MyHeap, 0, Buf);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2011-04-30 22:33:53 +00:00
|
|
|
pLogFile = LoadLogFile(SubKey, Buf);
|
|
|
|
if (pLogFile != NULL)
|
|
|
|
{
|
2007-05-03 07:47:12 +00:00
|
|
|
DPRINT("Loaded %S\n", Buf);
|
2011-04-30 22:33:53 +00:00
|
|
|
LoadEventSources(SubKey, pLogFile);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
DPRINT1("Failed to load %S\n", Buf);
|
|
|
|
}
|
2007-05-03 07:47:12 +00:00
|
|
|
|
|
|
|
RegCloseKey(SubKey);
|
|
|
|
LognameLen = MaxLognameLen;
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
|
|
|
HeapFree(MyHeap, 0, Buf);
|
|
|
|
return TRUE;
|
2006-06-30 14:53:24 +00:00
|
|
|
}
|
2006-03-04 17:04:42 +00:00
|
|
|
|
2008-05-08 18:26:15 +00:00
|
|
|
INT wmain()
|
2006-06-30 14:53:24 +00:00
|
|
|
{
|
2007-05-03 07:47:12 +00:00
|
|
|
WCHAR LogPath[MAX_PATH];
|
|
|
|
INT RetCode = 0;
|
|
|
|
LONG result;
|
|
|
|
HKEY elogKey;
|
|
|
|
|
|
|
|
LogfListInitialize();
|
2011-04-30 22:33:53 +00:00
|
|
|
InitEventSourceList();
|
2007-05-03 07:47:12 +00:00
|
|
|
|
|
|
|
MyHeap = HeapCreate(0, 1024 * 256, 0);
|
|
|
|
|
|
|
|
if (!MyHeap)
|
|
|
|
{
|
|
|
|
DPRINT1("FATAL ERROR, can't create heap.\n");
|
|
|
|
RetCode = 1;
|
|
|
|
goto bye_bye;
|
|
|
|
}
|
|
|
|
|
|
|
|
GetWindowsDirectory(LogPath, MAX_PATH);
|
|
|
|
|
|
|
|
if (GetDriveType(LogPath) == DRIVE_CDROM)
|
|
|
|
{
|
|
|
|
DPRINT("LiveCD detected\n");
|
|
|
|
onLiveCD = TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
result = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
|
|
|
|
L"SYSTEM\\CurrentControlSet\\Services\\EventLog",
|
|
|
|
0,
|
|
|
|
KEY_ALL_ACCESS,
|
|
|
|
&elogKey);
|
|
|
|
|
|
|
|
if (result != ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
DPRINT1("Fatal error: can't open eventlog registry key.\n");
|
|
|
|
RetCode = 1;
|
|
|
|
goto bye_bye;
|
|
|
|
}
|
|
|
|
|
|
|
|
LoadLogFiles(elogKey);
|
|
|
|
}
|
|
|
|
|
|
|
|
StartServiceCtrlDispatcher(ServiceTable);
|
|
|
|
|
|
|
|
bye_bye:
|
|
|
|
LogfCloseAll();
|
|
|
|
|
|
|
|
if (MyHeap)
|
|
|
|
HeapDestroy(MyHeap);
|
|
|
|
|
|
|
|
return RetCode;
|
2002-06-25 21:10:14 +00:00
|
|
|
}
|
|
|
|
|
2007-05-03 07:47:12 +00:00
|
|
|
VOID EventTimeToSystemTime(DWORD EventTime, SYSTEMTIME * pSystemTime)
|
2005-09-20 07:58:28 +00:00
|
|
|
{
|
2007-05-03 07:47:12 +00:00
|
|
|
SYSTEMTIME st1970 = { 1970, 1, 0, 1, 0, 0, 0, 0 };
|
|
|
|
FILETIME ftLocal;
|
|
|
|
union
|
|
|
|
{
|
|
|
|
FILETIME ft;
|
|
|
|
ULONGLONG ll;
|
|
|
|
} u1970, uUCT;
|
|
|
|
|
|
|
|
uUCT.ft.dwHighDateTime = 0;
|
|
|
|
uUCT.ft.dwLowDateTime = EventTime;
|
|
|
|
SystemTimeToFileTime(&st1970, &u1970.ft);
|
|
|
|
uUCT.ll = uUCT.ll * 10000000 + u1970.ll;
|
|
|
|
FileTimeToLocalFileTime(&uUCT.ft, &ftLocal);
|
|
|
|
FileTimeToSystemTime(&ftLocal, pSystemTime);
|
2005-09-20 07:58:28 +00:00
|
|
|
}
|
2002-06-25 21:10:14 +00:00
|
|
|
|
2011-12-25 00:57:16 +00:00
|
|
|
VOID SystemTimeToEventTime(SYSTEMTIME * pSystemTime, DWORD * pEventTime)
|
|
|
|
{
|
|
|
|
SYSTEMTIME st1970 = { 1970, 1, 0, 1, 0, 0, 0, 0 };
|
|
|
|
union
|
|
|
|
{
|
|
|
|
FILETIME ft;
|
|
|
|
ULONGLONG ll;
|
|
|
|
} Time, u1970;
|
|
|
|
|
|
|
|
SystemTimeToFileTime(pSystemTime, &Time.ft);
|
|
|
|
SystemTimeToFileTime(&st1970, &u1970.ft);
|
|
|
|
*pEventTime = (DWORD)((Time.ll - u1970.ll) / 10000000ull);
|
|
|
|
}
|
|
|
|
|
2008-12-24 12:14:30 +00:00
|
|
|
VOID PRINT_HEADER(PEVENTLOGHEADER header)
|
2005-09-20 07:58:28 +00:00
|
|
|
{
|
2013-03-14 16:51:39 +00:00
|
|
|
DPRINT("HeaderSize = %lu\n", header->HeaderSize);
|
2007-05-03 07:47:12 +00:00
|
|
|
DPRINT("Signature = 0x%x\n", header->Signature);
|
2013-03-14 16:51:39 +00:00
|
|
|
DPRINT("MajorVersion = %lu\n", header->MajorVersion);
|
|
|
|
DPRINT("MinorVersion = %lu\n", header->MinorVersion);
|
|
|
|
DPRINT("StartOffset = %lu\n", header->StartOffset);
|
2008-12-24 12:14:30 +00:00
|
|
|
DPRINT("EndOffset = 0x%x\n", header->EndOffset);
|
2013-03-14 16:51:39 +00:00
|
|
|
DPRINT("CurrentRecordNumber = %lu\n", header->CurrentRecordNumber);
|
|
|
|
DPRINT("OldestRecordNumber = %lu\n", header->OldestRecordNumber);
|
2008-12-24 12:14:30 +00:00
|
|
|
DPRINT("MaxSize = 0x%x\n", header->MaxSize);
|
|
|
|
DPRINT("Retention = 0x%x\n", header->Retention);
|
2013-03-14 16:51:39 +00:00
|
|
|
DPRINT("EndHeaderSize = %lu\n", header->EndHeaderSize);
|
2007-05-03 07:47:12 +00:00
|
|
|
DPRINT("Flags: ");
|
2008-12-24 12:14:30 +00:00
|
|
|
if (header->Flags & ELF_LOGFILE_HEADER_DIRTY) DPRINT("ELF_LOGFILE_HEADER_DIRTY");
|
|
|
|
if (header->Flags & ELF_LOGFILE_HEADER_WRAP) DPRINT("| ELF_LOGFILE_HEADER_WRAP ");
|
2012-01-05 23:03:40 +00:00
|
|
|
if (header->Flags & ELF_LOGFILE_LOGFULL_WRITTEN) DPRINT("| ELF_LOGFILE_LOGFULL_WRITTEN ");
|
2008-12-24 12:14:30 +00:00
|
|
|
if (header->Flags & ELF_LOGFILE_ARCHIVE_SET) DPRINT("| ELF_LOGFILE_ARCHIVE_SET ");
|
2007-05-03 07:47:12 +00:00
|
|
|
DPRINT("\n");
|
2005-09-20 07:58:28 +00:00
|
|
|
}
|
2002-06-25 21:10:14 +00:00
|
|
|
|
2005-09-20 07:58:28 +00:00
|
|
|
VOID PRINT_RECORD(PEVENTLOGRECORD pRec)
|
|
|
|
{
|
2007-05-03 07:47:12 +00:00
|
|
|
UINT i;
|
|
|
|
WCHAR *str;
|
|
|
|
SYSTEMTIME time;
|
|
|
|
|
2013-03-14 16:51:39 +00:00
|
|
|
DPRINT("Length = %lu\n", pRec->Length);
|
2007-05-03 07:47:12 +00:00
|
|
|
DPRINT("Reserved = 0x%x\n", pRec->Reserved);
|
2013-03-14 16:51:39 +00:00
|
|
|
DPRINT("RecordNumber = %lu\n", pRec->RecordNumber);
|
2007-05-03 07:47:12 +00:00
|
|
|
|
|
|
|
EventTimeToSystemTime(pRec->TimeGenerated, &time);
|
2013-03-14 16:51:39 +00:00
|
|
|
DPRINT("TimeGenerated = %hu.%hu.%hu %hu:%hu:%hu\n",
|
2007-05-03 07:47:12 +00:00
|
|
|
time.wDay, time.wMonth, time.wYear,
|
|
|
|
time.wHour, time.wMinute, time.wSecond);
|
|
|
|
|
|
|
|
EventTimeToSystemTime(pRec->TimeWritten, &time);
|
2013-03-14 16:51:39 +00:00
|
|
|
DPRINT("TimeWritten = %hu.%hu.%hu %hu:%hu:%hu\n",
|
2007-05-03 07:47:12 +00:00
|
|
|
time.wDay, time.wMonth, time.wYear,
|
|
|
|
time.wHour, time.wMinute, time.wSecond);
|
|
|
|
|
2013-03-14 16:51:39 +00:00
|
|
|
DPRINT("EventID = %lu\n", pRec->EventID);
|
2007-05-03 07:47:12 +00:00
|
|
|
|
|
|
|
switch (pRec->EventType)
|
|
|
|
{
|
|
|
|
case EVENTLOG_ERROR_TYPE:
|
|
|
|
DPRINT("EventType = EVENTLOG_ERROR_TYPE\n");
|
|
|
|
break;
|
|
|
|
case EVENTLOG_WARNING_TYPE:
|
|
|
|
DPRINT("EventType = EVENTLOG_WARNING_TYPE\n");
|
|
|
|
break;
|
|
|
|
case EVENTLOG_INFORMATION_TYPE:
|
|
|
|
DPRINT("EventType = EVENTLOG_INFORMATION_TYPE\n");
|
|
|
|
break;
|
|
|
|
case EVENTLOG_AUDIT_SUCCESS:
|
|
|
|
DPRINT("EventType = EVENTLOG_AUDIT_SUCCESS\n");
|
|
|
|
break;
|
|
|
|
case EVENTLOG_AUDIT_FAILURE:
|
|
|
|
DPRINT("EventType = EVENTLOG_AUDIT_FAILURE\n");
|
|
|
|
break;
|
|
|
|
default:
|
2013-03-14 16:51:39 +00:00
|
|
|
DPRINT("EventType = %hu\n", pRec->EventType);
|
2007-05-03 07:47:12 +00:00
|
|
|
}
|
|
|
|
|
2013-03-14 16:51:39 +00:00
|
|
|
DPRINT("NumStrings = %hu\n", pRec->NumStrings);
|
|
|
|
DPRINT("EventCategory = %hu\n", pRec->EventCategory);
|
2007-05-03 07:47:12 +00:00
|
|
|
DPRINT("ReservedFlags = 0x%x\n", pRec->ReservedFlags);
|
2013-03-14 16:51:39 +00:00
|
|
|
DPRINT("ClosingRecordNumber = %lu\n", pRec->ClosingRecordNumber);
|
|
|
|
DPRINT("StringOffset = %lu\n", pRec->StringOffset);
|
|
|
|
DPRINT("UserSidLength = %lu\n", pRec->UserSidLength);
|
|
|
|
DPRINT("UserSidOffset = %lu\n", pRec->UserSidOffset);
|
|
|
|
DPRINT("DataLength = %lu\n", pRec->DataLength);
|
|
|
|
DPRINT("DataOffset = %lu\n", pRec->DataOffset);
|
2007-05-03 07:47:12 +00:00
|
|
|
|
|
|
|
DPRINT("SourceName: %S\n", (WCHAR *) (((PBYTE) pRec) + sizeof(EVENTLOGRECORD)));
|
|
|
|
|
|
|
|
i = (lstrlenW((WCHAR *) (((PBYTE) pRec) + sizeof(EVENTLOGRECORD))) + 1) *
|
|
|
|
sizeof(WCHAR);
|
|
|
|
|
|
|
|
DPRINT("ComputerName: %S\n", (WCHAR *) (((PBYTE) pRec) + sizeof(EVENTLOGRECORD) + i));
|
|
|
|
|
|
|
|
if (pRec->StringOffset < pRec->Length && pRec->NumStrings)
|
|
|
|
{
|
|
|
|
DPRINT("Strings:\n");
|
|
|
|
str = (WCHAR *) (((PBYTE) pRec) + pRec->StringOffset);
|
|
|
|
for (i = 0; i < pRec->NumStrings; i++)
|
|
|
|
{
|
2013-03-14 16:51:39 +00:00
|
|
|
DPRINT("[%u] %S\n", i, str);
|
2007-05-03 07:47:12 +00:00
|
|
|
str = str + lstrlenW(str) + 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-14 16:51:39 +00:00
|
|
|
DPRINT("Length2 = %lu\n", *(PDWORD) (((PBYTE) pRec) + pRec->Length - 4));
|
2005-09-20 07:58:28 +00:00
|
|
|
}
|