Author: dgorbachev
Date: Thu May 3 11:47:12 2007
New Revision: 26626
URL:
http://svn.reactos.org/svn/reactos?rev=26626&view=rev
Log:
- Fix a bug in "close all log files" code.
- Replace custom list functions by RTL ones.
- Fix indentation.
Modified:
trunk/reactos/base/services/eventlog/eventlog.c
trunk/reactos/base/services/eventlog/eventlog.h
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 (original)
+++ trunk/reactos/base/services/eventlog/eventlog.c Thu May 3 11:47:12 2007
@@ -13,21 +13,20 @@
/* GLOBALS ******************************************************************/
-VOID CALLBACK ServiceMain(DWORD argc, LPTSTR *argv);
+VOID CALLBACK ServiceMain(DWORD argc, LPTSTR * argv);
+
SERVICE_TABLE_ENTRY ServiceTable[2] =
{
- {L"EventLog", (LPSERVICE_MAIN_FUNCTION)ServiceMain},
- {NULL, NULL}
+ { L"EventLog", (LPSERVICE_MAIN_FUNCTION) ServiceMain },
+ { NULL, NULL }
};
+BOOL onLiveCD = FALSE; // On livecd events will go to debug output only
HANDLE MyHeap = NULL;
-BOOL onLiveCD = FALSE; // On livecd events will go to debug output only
-extern CRITICAL_SECTION LogListCs;
-extern PLOGFILE LogListHead;
/* FUNCTIONS ****************************************************************/
-VOID CALLBACK ServiceMain(DWORD argc, LPTSTR *argv)
+VOID CALLBACK ServiceMain(DWORD argc, LPTSTR * argv)
{
HANDLE hThread;
@@ -38,11 +37,13 @@
NULL,
0,
NULL);
-
- if(!hThread) DPRINT("Can't create PortThread\n");
- else CloseHandle(hThread);
-
- #ifdef RPC_ENABLED
+
+ if (!hThread)
+ DPRINT("Can't create PortThread\n");
+ else
+ CloseHandle(hThread);
+
+#ifdef RPC_ENABLED
hThread = CreateThread(NULL,
0,
(LPTHREAD_START_ROUTINE)
@@ -51,306 +52,318 @@
0,
NULL);
- if(!hThread) DPRINT("Can't create RpcThread\n");
- else CloseHandle(hThread);
- #endif
-}
-
-BOOL LoadLogFile(HKEY hKey, WCHAR *LogName)
-{
- DWORD MaxValueLen, ValueLen, Type, ExpandedLen;
- WCHAR *Buf = NULL, *Expanded = NULL;
- LONG Result;
- BOOL ret = TRUE;
- PLOGFILE pLogf;
-
- 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");
- return FALSE;
- }
-
- ValueLen = MaxValueLen;
-
- Result = RegQueryValueEx(hKey, L"File",
- NULL,
- &Type,
- (LPBYTE)Buf,
- &ValueLen);
-
- if(Result != ERROR_SUCCESS)
- {
- DPRINT1("RegQueryValueEx failed: %d\n", GetLastError());
- HeapFree(MyHeap, 0, Buf);
- return FALSE;
- }
- if(Type != REG_EXPAND_SZ && Type != REG_SZ)
- {
- DPRINT1("%S\\File - value of wrong type %x.\n", LogName, Type);
- HeapFree(MyHeap, 0, Buf);
- return FALSE;
- }
-
- ExpandedLen = ExpandEnvironmentStrings(Buf, NULL, 0);
- Expanded = HeapAlloc(MyHeap, 0, ExpandedLen*sizeof(WCHAR));
-
- if(!Expanded)
- {
- DPRINT1("Can't allocate heap!\n");
- HeapFree(MyHeap, 0, Buf);
- return FALSE;
- }
-
- ExpandEnvironmentStrings(Buf, Expanded, ExpandedLen);
-
- DPRINT("%S -> %S\n", Buf, Expanded);
-
- pLogf = LogfCreate(LogName, Expanded);
-
- if(pLogf == NULL)
- {
- DPRINT1("Failed to create %S!\n", Expanded);
- ret = FALSE;
- }
-
- HeapFree(MyHeap, 0, Buf);
- HeapFree(MyHeap, 0, Expanded);
- return ret;
-}
-
+ if (!hThread)
+ DPRINT("Can't create RpcThread\n");
+ else
+ CloseHandle(hThread);
+#endif
+}
+
+BOOL LoadLogFile(HKEY hKey, WCHAR * LogName)
+{
+ DWORD MaxValueLen, ValueLen, Type, ExpandedLen;
+ WCHAR *Buf = NULL, *Expanded = NULL;
+ LONG Result;
+ BOOL ret = TRUE;
+ PLOGFILE pLogf;
+
+ 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");
+ return FALSE;
+ }
+
+ ValueLen = MaxValueLen;
+
+ Result = RegQueryValueEx(hKey,
+ L"File",
+ NULL,
+ &Type,
+ (LPBYTE) Buf,
+ &ValueLen);
+
+ if (Result != ERROR_SUCCESS)
+ {
+ DPRINT1("RegQueryValueEx failed: %d\n", GetLastError());
+ HeapFree(MyHeap, 0, Buf);
+ return FALSE;
+ }
+
+ if (Type != REG_EXPAND_SZ && Type != REG_SZ)
+ {
+ DPRINT1("%S\\File - value of wrong type %x.\n", LogName, Type);
+ HeapFree(MyHeap, 0, Buf);
+ return FALSE;
+ }
+
+ ExpandedLen = ExpandEnvironmentStrings(Buf, NULL, 0);
+ Expanded = HeapAlloc(MyHeap, 0, ExpandedLen * sizeof(WCHAR));
+
+ if (!Expanded)
+ {
+ DPRINT1("Can't allocate heap!\n");
+ HeapFree(MyHeap, 0, Buf);
+ return FALSE;
+ }
+
+ ExpandEnvironmentStrings(Buf, Expanded, ExpandedLen);
+
+ DPRINT("%S -> %S\n", Buf, Expanded);
+
+ pLogf = LogfCreate(LogName, Expanded);
+
+ if (pLogf == NULL)
+ {
+ DPRINT1("Failed to create %S!\n", Expanded);
+ ret = FALSE;
+ }
+
+ HeapFree(MyHeap, 0, Buf);
+ HeapFree(MyHeap, 0, Expanded);
+ return ret;
+}
+
BOOL LoadLogFiles(HKEY eventlogKey)
{
- LONG result;
- DWORD MaxLognameLen, LognameLen;
- WCHAR *Buf = NULL;
- INT i;
-
- 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;
- }
-
- if(!LoadLogFile(SubKey, Buf))
- DPRINT1("Failed to load %S\n", Buf);
- else DPRINT("Loaded %S\n", Buf);
-
- RegCloseKey(SubKey);
- LognameLen=MaxLognameLen;
- i++;
- }
-
- HeapFree(MyHeap, 0, Buf);
- return TRUE;
+ LONG result;
+ DWORD MaxLognameLen, LognameLen;
+ WCHAR *Buf = NULL;
+ INT i;
+
+ 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;
+ }
+
+ if (!LoadLogFile(SubKey, Buf))
+ DPRINT1("Failed to load %S\n", Buf);
+ else
+ DPRINT("Loaded %S\n", Buf);
+
+ RegCloseKey(SubKey);
+ LognameLen = MaxLognameLen;
+ i++;
+ }
+
+ HeapFree(MyHeap, 0, Buf);
+ return TRUE;
}
INT main()
{
- WCHAR LogPath[MAX_PATH];
- PLOGFILE pLogf;
- INT RetCode = 0;
- LONG result;
- HKEY elogKey;
-
- InitializeCriticalSection(&LogListCs);
-
- MyHeap = HeapCreate(0, 1024*256, 0);
-
- if(MyHeap==NULL)
- {
- 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:
- // Close all log files.
- for(pLogf = LogListHead; pLogf; pLogf = ((PLOGFILE)pLogf)->Next)
- LogfClose(pLogf);
-
- DeleteCriticalSection(&LogListCs);
-
- if(MyHeap) HeapDestroy(MyHeap);
-
- return RetCode;
-}
-
-VOID EventTimeToSystemTime(DWORD EventTime,
- SYSTEMTIME *pSystemTime)
-{
- 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);
-}
-
-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 = (Time.ll - u1970.ll) / 10000000;
+ WCHAR LogPath[MAX_PATH];
+ INT RetCode = 0;
+ LONG result;
+ HKEY elogKey;
+
+ LogfListInitialize();
+
+ 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;
+}
+
+VOID EventTimeToSystemTime(DWORD EventTime, SYSTEMTIME * pSystemTime)
+{
+ 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);
+}
+
+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 = (Time.ll - u1970.ll) / 10000000;
}
VOID PRINT_HEADER(PFILE_HEADER header)
{
- DPRINT("SizeOfHeader=%d\n",header->SizeOfHeader);
- DPRINT("Signature=0x%x\n",header->Signature);
- DPRINT("MajorVersion=%d\n",header->MajorVersion);
- DPRINT("MinorVersion=%d\n",header->MinorVersion);
- DPRINT("FirstRecordOffset=%d\n",header->FirstRecordOffset);
- DPRINT("EofOffset=0x%x\n",header->EofOffset);
- DPRINT("NextRecord=%d\n",header->NextRecord);
- DPRINT("OldestRecord=%d\n",header->OldestRecord);
- DPRINT("unknown1=0x%x\n",header->unknown1);
- DPRINT("unknown2=0x%x\n",header->unknown2);
- DPRINT("SizeOfHeader2=%d\n",header->SizeOfHeader2);
- DPRINT("Flags: ");
- if(header->Flags & LOGFILE_FLAG1)DPRINT("LOGFILE_FLAG1 ");
- if(header->Flags & LOGFILE_FLAG2)DPRINT("| LOGFILE_FLAG2 ");
- if(header->Flags & LOGFILE_FLAG3)DPRINT("| LOGFILE_FLAG3 ");
- if(header->Flags & LOGFILE_FLAG4)DPRINT("| LOGFILE_FLAG4");
- DPRINT("\n");
+ DPRINT("SizeOfHeader = %d\n", header->SizeOfHeader);
+ DPRINT("Signature = 0x%x\n", header->Signature);
+ DPRINT("MajorVersion = %d\n", header->MajorVersion);
+ DPRINT("MinorVersion = %d\n", header->MinorVersion);
+ DPRINT("FirstRecordOffset = %d\n", header->FirstRecordOffset);
+ DPRINT("EofOffset = 0x%x\n", header->EofOffset);
+ DPRINT("NextRecord = %d\n", header->NextRecord);
+ DPRINT("OldestRecord = %d\n", header->OldestRecord);
+ DPRINT("unknown1 = 0x%x\n", header->unknown1);
+ DPRINT("unknown2 = 0x%x\n", header->unknown2);
+ DPRINT("SizeOfHeader2 = %d\n", header->SizeOfHeader2);
+ DPRINT("Flags: ");
+ if (header->Flags & LOGFILE_FLAG1) DPRINT("LOGFILE_FLAG1 ");
+ if (header->Flags & LOGFILE_FLAG2) DPRINT("| LOGFILE_FLAG2 ");
+ if (header->Flags & LOGFILE_FLAG3) DPRINT("| LOGFILE_FLAG3 ");
+ if (header->Flags & LOGFILE_FLAG4) DPRINT("| LOGFILE_FLAG4");
+ DPRINT("\n");
}
VOID PRINT_RECORD(PEVENTLOGRECORD pRec)
{
- UINT i;
- WCHAR *str;
- SYSTEMTIME time;
-
- DPRINT("Length=%d\n", pRec->Length );
- DPRINT("Reserved=0x%x\n", pRec->Reserved );
- DPRINT("RecordNumber=%d\n", pRec->RecordNumber );
-
- EventTimeToSystemTime(pRec->TimeGenerated, &time);
- DPRINT("TimeGenerated=%d.%d.%d %d:%d:%d\n",
- time.wDay, time.wMonth, time.wYear,
- time.wHour, time.wMinute, time.wSecond);
-
- EventTimeToSystemTime(pRec->TimeWritten, &time);
- DPRINT("TimeWritten=%d.%d.%d %d:%d:%d\n",
- time.wDay, time.wMonth, time.wYear,
- time.wHour, time.wMinute, time.wSecond);
-
- DPRINT("EventID=%d\n", pRec->EventID );
-
- 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:
- DPRINT("EventType = %x\n");
- }
-
- DPRINT("NumStrings=%d\n", pRec->NumStrings );
- DPRINT("EventCategory=%d\n", pRec->EventCategory);
- DPRINT("ReservedFlags=0x%x\n", pRec->ReservedFlags);
- DPRINT("ClosingRecordNumber=%d\n", pRec->ClosingRecordNumber);
- DPRINT("StringOffset=%d\n", pRec->StringOffset);
- DPRINT("UserSidLength=%d\n", pRec->UserSidLength);
- DPRINT("UserSidOffset=%d\n", pRec->UserSidOffset);
- DPRINT("DataLength=%d\n", pRec->DataLength);
- DPRINT("DataOffset=%d\n", pRec->DataOffset);
-
- 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++)
- {
- DPRINT("[%d] %S\n", i, str);
- str = str+lstrlenW(str)+1;
- }
- }
-
- DPRINT("Length2=%d\n", *(PDWORD)(((PBYTE)pRec)+pRec->Length-4));
-}
+ UINT i;
+ WCHAR *str;
+ SYSTEMTIME time;
+
+ DPRINT("Length = %d\n", pRec->Length);
+ DPRINT("Reserved = 0x%x\n", pRec->Reserved);
+ DPRINT("RecordNumber = %d\n", pRec->RecordNumber);
+
+ EventTimeToSystemTime(pRec->TimeGenerated, &time);
+ DPRINT("TimeGenerated = %d.%d.%d %d:%d:%d\n",
+ time.wDay, time.wMonth, time.wYear,
+ time.wHour, time.wMinute, time.wSecond);
+
+ EventTimeToSystemTime(pRec->TimeWritten, &time);
+ DPRINT("TimeWritten = %d.%d.%d %d:%d:%d\n",
+ time.wDay, time.wMonth, time.wYear,
+ time.wHour, time.wMinute, time.wSecond);
+
+ DPRINT("EventID = %d\n", pRec->EventID);
+
+ 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:
+ DPRINT("EventType = %x\n");
+ }
+
+ DPRINT("NumStrings = %d\n", pRec->NumStrings);
+ DPRINT("EventCategory = %d\n", pRec->EventCategory);
+ DPRINT("ReservedFlags = 0x%x\n", pRec->ReservedFlags);
+ DPRINT("ClosingRecordNumber = %d\n", pRec->ClosingRecordNumber);
+ DPRINT("StringOffset = %d\n", pRec->StringOffset);
+ DPRINT("UserSidLength = %d\n", pRec->UserSidLength);
+ DPRINT("UserSidOffset = %d\n", pRec->UserSidOffset);
+ DPRINT("DataLength = %d\n", pRec->DataLength);
+ DPRINT("DataOffset = %d\n", pRec->DataOffset);
+
+ 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++)
+ {
+ DPRINT("[%d] %S\n", i, str);
+ str = str + lstrlenW(str) + 1;
+ }
+ }
+
+ DPRINT("Length2 = %d\n", *(PDWORD) (((PBYTE) pRec) + pRec->Length -
4));
+}
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 (original)
+++ trunk/reactos/base/services/eventlog/eventlog.h Thu May 3 11:47:12 2007
@@ -3,10 +3,9 @@
* LICENSE: GPL - See COPYING in the top level directory
* FILE: services/eventlog/eventlog.h
* PURPOSE: Event logging service
- * COPYRIGHT: Copyright 2005 Saveliy Tretiakov
+ * COPYRIGHT: Copyright 2005 Saveliy Tretiakov
*/
-
-
+
#ifndef __EVENTLOG_H__
#define __EVENTLOG_H__
@@ -23,7 +22,6 @@
#include <pseh/pseh.h>
#include "eventlogrpc_s.h"
-
typedef struct _IO_ERROR_LPC
{
PORT_MESSAGE Header;
@@ -36,8 +34,7 @@
/*
* Our file format will be compatible with NT's
*/
-
-#define LOGFILE_SIGNATURE 0x654c664c
+#define LOGFILE_SIGNATURE 0x654c664c
/*
* FIXME
@@ -48,63 +45,68 @@
#define LOGFILE_FLAG3 4
#define LOGFILE_FLAG4 8
-typedef struct {
- DWORD SizeOfHeader;
- DWORD Signature;
- DWORD MajorVersion;
- DWORD MinorVersion;
- DWORD FirstRecordOffset;
- DWORD EofOffset;
- DWORD NextRecord;
- DWORD OldestRecord;
- DWORD unknown1;
- DWORD Flags;
- DWORD unknown2;
- DWORD SizeOfHeader2;
+typedef struct
+{
+ DWORD SizeOfHeader;
+ DWORD Signature;
+ DWORD MajorVersion;
+ DWORD MinorVersion;
+ DWORD FirstRecordOffset;
+ DWORD EofOffset;
+ DWORD NextRecord;
+ DWORD OldestRecord;
+ DWORD unknown1;
+ DWORD Flags;
+ DWORD unknown2;
+ DWORD SizeOfHeader2;
} FILE_HEADER, *PFILE_HEADER;
-typedef struct {
- DWORD Size1;
- DWORD Ones; // Must be 0x11111111
- DWORD Twos; // Must be 0x22222222
- DWORD Threes; // Must be 0x33333333
- DWORD Fours; // Must be 0x44444444
- DWORD StartOffset;
- DWORD EndOffset;
- DWORD NextRecordNumber;
- DWORD OldestRecordNumber;
- DWORD Size2;
+typedef struct
+{
+ DWORD Size1;
+ DWORD Ones; // Must be 0x11111111
+ DWORD Twos; // Must be 0x22222222
+ DWORD Threes; // Must be 0x33333333
+ DWORD Fours; // Must be 0x44444444
+ DWORD StartOffset;
+ DWORD EndOffset;
+ DWORD NextRecordNumber;
+ DWORD OldestRecordNumber;
+ DWORD Size2;
} EOF_RECORD, *PEOF_RECORD;
-typedef struct {
- ULONG EventNumber;
- ULONG EventOffset;
+typedef struct
+{
+ ULONG EventNumber;
+ ULONG EventOffset;
} EVENT_OFFSET_INFO, *PEVENT_OFFSET_INFO;
-typedef struct {
- HANDLE hFile;
- FILE_HEADER Header;
- WCHAR *LogName;
- WCHAR *FileName;
+typedef struct
+{
+ HANDLE hFile;
+ FILE_HEADER Header;
+ WCHAR *LogName;
+ WCHAR *FileName;
CRITICAL_SECTION cs;
- PEVENT_OFFSET_INFO OffsetInfo;
- ULONG OffsetInfoSize;
- ULONG OffsetInfoNext;
- PVOID Next;
- PVOID Prev;
+ PEVENT_OFFSET_INFO OffsetInfo;
+ ULONG OffsetInfoSize;
+ ULONG OffsetInfoNext;
+ LIST_ENTRY ListEntry;
} LOGFILE, *PLOGFILE;
/* file.c */
-PLOGFILE LogfListHead();
+VOID LogfListInitialize(VOID);
-INT LogfListItemCount();
+PLOGFILE LogfListHead(VOID);
+
+INT LogfListItemCount(VOID);
PLOGFILE LogfListItemByIndex(INT Index);
-PLOGFILE LogfListItemByName(WCHAR *Name);
+PLOGFILE LogfListItemByName(WCHAR * Name);
-INT LogfListItemIndexByName(WCHAR *Name);
+INT LogfListItemIndexByName(WCHAR * Name);
VOID LogfListAddItem(PLOGFILE Item);
@@ -115,17 +117,19 @@
DWORD RecordNumber,
DWORD BufSize,
PBYTE Buffer,
- DWORD *BytesRead,
- DWORD *BytesNeeded);
+ DWORD * BytesRead,
+ DWORD * BytesNeeded);
BOOL LogfWriteData(PLOGFILE LogFile,
- DWORD BufSize,
- PBYTE Buffer);
+ DWORD BufSize,
+ PBYTE Buffer);
-PLOGFILE LogfCreate(WCHAR *LogName,
- WCHAR *FileName);
+PLOGFILE LogfCreate(WCHAR * LogName,
+ WCHAR * FileName);
VOID LogfClose(PLOGFILE LogFile);
+
+VOID LogfCloseAll(VOID);
BOOL LogfInitializeNew(PLOGFILE LogFile);
@@ -134,25 +138,25 @@
DWORD LogfGetOldestRecord(PLOGFILE LogFile);
ULONG LogfOffsetByNumber(PLOGFILE LogFile,
- DWORD RecordNumber);
+ DWORD RecordNumber);
-BOOL LogfAddOffsetInformation(PLOGFILE LogFile,
- ULONG ulNumber,
- ULONG ulOffset);
+BOOL LogfAddOffsetInformation(PLOGFILE LogFile,
+ ULONG ulNumber,
+ ULONG ulOffset);
PBYTE LogfAllocAndBuildNewRecord(LPDWORD lpRecSize,
- DWORD dwRecordNumber,
- WORD wType,
- WORD wCategory,
- DWORD dwEventId,
- LPCWSTR SourceName,
- LPCWSTR ComputerName,
- DWORD dwSidLength,
- PSID lpUserSid,
- WORD wNumStrings,
- WCHAR *lpStrings,
- DWORD dwDataSize,
- LPVOID lpRawData);
+ DWORD dwRecordNumber,
+ WORD wType,
+ WORD wCategory,
+ DWORD dwEventId,
+ LPCWSTR SourceName,
+ LPCWSTR ComputerName,
+ DWORD dwSidLength,
+ PSID lpUserSid,
+ WORD wNumStrings,
+ WCHAR * lpStrings,
+ DWORD dwDataSize,
+ LPVOID lpRawData);
void __inline LogfFreeRecord(LPVOID Rec);
@@ -161,11 +165,11 @@
VOID PRINT_RECORD(PEVENTLOGRECORD pRec);
-VOID EventTimeToSystemTime(DWORD EventTime,
- SYSTEMTIME *SystemTime);
+VOID EventTimeToSystemTime(DWORD EventTime,
+ SYSTEMTIME * SystemTime);
-VOID SystemTimeToEventTime(SYSTEMTIME *pSystemTime,
- DWORD *pEventTime);
+VOID SystemTimeToEventTime(SYSTEMTIME * pSystemTime,
+ DWORD * pEventTime);
/* logport.c */
NTSTATUS STDCALL PortThreadRoutine(PVOID Param);
@@ -177,6 +181,4 @@
/* rpc.c */
DWORD STDCALL RpcThreadRoutine(LPVOID lpParameter);
-
-#endif /* __EVENTLOG_H__ */
-
+#endif /* __EVENTLOG_H__ */
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 (original)
+++ trunk/reactos/base/services/eventlog/file.c Thu May 3 11:47:12 2007
@@ -6,265 +6,261 @@
* COPYRIGHT: Copyright 2005 Saveliy Tretiakov
*/
+/* INCLUDES *****************************************************************/
+
#include "eventlog.h"
-PLOGFILE LogListHead = NULL;
-CRITICAL_SECTION LogListCs;
+/* GLOBALS ******************************************************************/
+
+static LIST_ENTRY LogFileListHead;
+static CRITICAL_SECTION LogFileListCs;
extern HANDLE MyHeap;
+/* FUNCTIONS ****************************************************************/
+
BOOL LogfInitializeNew(PLOGFILE LogFile)
{
DWORD dwWritten;
- EOF_RECORD EofRec;
+ EOF_RECORD EofRec;
ZeroMemory(&LogFile->Header, sizeof(FILE_HEADER));
- SetFilePointer(LogFile->hFile, 0, NULL, FILE_BEGIN);
- SetEndOfFile(LogFile->hFile);
-
- LogFile->Header.SizeOfHeader = sizeof(FILE_HEADER);
- LogFile->Header.SizeOfHeader2 = sizeof(FILE_HEADER);
- LogFile->Header.FirstRecordOffset = sizeof(FILE_HEADER);
- LogFile->Header.EofOffset = sizeof(FILE_HEADER);
- LogFile->Header.MajorVersion = MAJORVER;
- LogFile->Header.MinorVersion = MINORVER;
- LogFile->Header.NextRecord = 1;
-
- LogFile->Header.Signature = LOGFILE_SIGNATURE;
- if(!WriteFile(LogFile->hFile,
- &LogFile->Header,
- sizeof(FILE_HEADER),
- &dwWritten,
- NULL))
- {
- DPRINT1("WriteFile failed:%d!\n", GetLastError());
- return FALSE;
- }
-
- EofRec.Ones = 0x11111111;
- EofRec.Twos = 0x22222222;
- EofRec.Threes = 0x33333333;
- EofRec.Fours = 0x44444444;
- EofRec.Size1 = sizeof(EOF_RECORD);
- EofRec.Size2 = sizeof(EOF_RECORD);
- EofRec.NextRecordNumber = LogFile->Header.NextRecord;
- EofRec.OldestRecordNumber = LogFile->Header.OldestRecord;
- EofRec.StartOffset = LogFile->Header.FirstRecordOffset;
- EofRec.EndOffset = LogFile->Header.EofOffset;
-
- if(!WriteFile(LogFile->hFile,
- &EofRec,
- sizeof(EOF_RECORD),
- &dwWritten,
- NULL))
- {
- DPRINT1("WriteFile failed:%d!\n", GetLastError());
- return FALSE;
- }
-
- if(!FlushFileBuffers(LogFile->hFile))
- {
- DPRINT1("FlushFileBuffers failed:%d!\n", GetLastError());
- return FALSE;
- }
+ SetFilePointer(LogFile->hFile, 0, NULL, FILE_BEGIN);
+ SetEndOfFile(LogFile->hFile);
+
+ LogFile->Header.SizeOfHeader = sizeof(FILE_HEADER);
+ LogFile->Header.SizeOfHeader2 = sizeof(FILE_HEADER);
+ LogFile->Header.FirstRecordOffset = sizeof(FILE_HEADER);
+ LogFile->Header.EofOffset = sizeof(FILE_HEADER);
+ LogFile->Header.MajorVersion = MAJORVER;
+ LogFile->Header.MinorVersion = MINORVER;
+ LogFile->Header.NextRecord = 1;
+
+ LogFile->Header.Signature = LOGFILE_SIGNATURE;
+ if (!WriteFile(LogFile->hFile,
+ &LogFile->Header,
+ sizeof(FILE_HEADER),
+ &dwWritten,
+ NULL))
+ {
+ DPRINT1("WriteFile failed:%d!\n", GetLastError());
+ return FALSE;
+ }
+
+ EofRec.Ones = 0x11111111;
+ EofRec.Twos = 0x22222222;
+ EofRec.Threes = 0x33333333;
+ EofRec.Fours = 0x44444444;
+ EofRec.Size1 = sizeof(EOF_RECORD);
+ EofRec.Size2 = sizeof(EOF_RECORD);
+ EofRec.NextRecordNumber = LogFile->Header.NextRecord;
+ EofRec.OldestRecordNumber = LogFile->Header.OldestRecord;
+ EofRec.StartOffset = LogFile->Header.FirstRecordOffset;
+ EofRec.EndOffset = LogFile->Header.EofOffset;
+
+ if (!WriteFile(LogFile->hFile,
+ &EofRec,
+ sizeof(EOF_RECORD),
+ &dwWritten,
+ NULL))
+ {
+ DPRINT1("WriteFile failed:%d!\n", GetLastError());
+ return FALSE;
+ }
+
+ if (!FlushFileBuffers(LogFile->hFile))
+ {
+ DPRINT1("FlushFileBuffers failed:%d!\n", GetLastError());
+ return FALSE;
+ }
return TRUE;
}
BOOL LogfInitializeExisting(PLOGFILE LogFile)
{
- DWORD dwRead;
- DWORD dwRecordsNumber = 0;
- DWORD dwRecSize, dwRecSign, dwFilePointer;
- PDWORD pdwRecSize2;
- PEVENTLOGRECORD RecBuf;
-
- if(SetFilePointer(LogFile->hFile, 0, NULL, FILE_BEGIN) ==
- INVALID_SET_FILE_POINTER)
- {
- DPRINT1("SetFilePointer failed! %d\n", GetLastError());
- return FALSE;
- }
-
- if(!ReadFile(LogFile->hFile,
- &LogFile->Header,
- sizeof(FILE_HEADER),
- &dwRead, NULL))
- {
- DPRINT1("ReadFile failed! %d\n", GetLastError());
- return FALSE;
- }
-
- if(dwRead != sizeof(FILE_HEADER))
- {
- DPRINT("EventLog: Invalid file %S.\n", LogFile->FileName);
- return LogfInitializeNew(LogFile);
- }
-
- if(LogFile->Header.SizeOfHeader != sizeof(FILE_HEADER) ||
- LogFile->Header.SizeOfHeader2 != sizeof(FILE_HEADER))
- {
- DPRINT("EventLog: Invalid header size in %S.\n", LogFile->FileName);
- return LogfInitializeNew(LogFile);
- }
-
- if(LogFile->Header.Signature != LOGFILE_SIGNATURE)
+ DWORD dwRead;
+ DWORD dwRecordsNumber = 0;
+ DWORD dwRecSize, dwRecSign, dwFilePointer;
+ PDWORD pdwRecSize2;
+ PEVENTLOGRECORD RecBuf;
+
+ if (SetFilePointer(LogFile->hFile, 0, NULL, FILE_BEGIN) ==
+ INVALID_SET_FILE_POINTER)
+ {
+ DPRINT1("SetFilePointer failed! %d\n", GetLastError());
+ return FALSE;
+ }
+
+ if (!ReadFile(LogFile->hFile,
+ &LogFile->Header,
+ sizeof(FILE_HEADER),
+ &dwRead,
+ NULL))
+ {
+ DPRINT1("ReadFile failed! %d\n", GetLastError());
+ return FALSE;
+ }
+
+ if (dwRead != sizeof(FILE_HEADER))
+ {
+ DPRINT("EventLog: Invalid file %S.\n", LogFile->FileName);
+ return LogfInitializeNew(LogFile);
+ }
+
+ if (LogFile->Header.SizeOfHeader != sizeof(FILE_HEADER) ||
+ LogFile->Header.SizeOfHeader2 != sizeof(FILE_HEADER))
+ {
+ DPRINT("EventLog: Invalid header size in %S.\n",
LogFile->FileName);
+ return LogfInitializeNew(LogFile);
+ }
+
+ if (LogFile->Header.Signature != LOGFILE_SIGNATURE)
{
DPRINT("EventLog: Invalid signature %x in %S.\n",
- LogFile->Header.Signature,
- LogFile->FileName);
+ LogFile->Header.Signature, LogFile->FileName);
return LogfInitializeNew(LogFile);
}
- if(LogFile->Header.EofOffset > GetFileSize(LogFile->hFile, NULL)+1)
- {
+ if (LogFile->Header.EofOffset > GetFileSize(LogFile->hFile, NULL) + 1)
+ {
DPRINT("EventLog: Invalid eof offset %x in %S.\n",
- LogFile->Header.EofOffset,
- LogFile->FileName);
+ LogFile->Header.EofOffset, LogFile->FileName);
return LogfInitializeNew(LogFile);
- }
-
- for(;;)
- {
- dwFilePointer = SetFilePointer(LogFile->hFile,
- 0,
- NULL,
- FILE_CURRENT);
-
- if(dwFilePointer == INVALID_SET_FILE_POINTER)
- {
- DPRINT1("SetFilePointer failed! %d\n", GetLastError());
- return FALSE;
- }
-
- if(!ReadFile(LogFile->hFile,
- &dwRecSize,
- sizeof(dwRecSize),
- &dwRead,
- NULL))
- {
- DPRINT1("ReadFile failed! %d\n", GetLastError());
- return FALSE;
- }
-
- if(dwRead != sizeof(dwRecSize))
- break;
-
- if(!ReadFile(LogFile->hFile,
- &dwRecSign,
- sizeof(dwRecSign),
- &dwRead,
- NULL))
- {
- DPRINT1("ReadFile() failed! %d\n", GetLastError());
- return FALSE;
- }
-
- if(dwRead != sizeof(dwRecSize))
- break;
-
- if(dwRecSign != LOGFILE_SIGNATURE ||
- dwRecSize + dwFilePointer > GetFileSize(LogFile->hFile, NULL)+1 ||
- dwRecSize < sizeof(EVENTLOGRECORD))
- {
- break;
- }
-
- if(SetFilePointer(LogFile->hFile,
- -((LONG)sizeof(DWORD)*2),
- NULL,
- FILE_CURRENT) == INVALID_SET_FILE_POINTER)
- {
- DPRINT1("SetFilePointer() failed! %d", GetLastError());
- return FALSE;
- }
-
- RecBuf = (PEVENTLOGRECORD) HeapAlloc(MyHeap, 0, dwRecSize);
-
- if(!RecBuf)
- {
- DPRINT1("Can't allocate heap!\n");
- return FALSE;
- }
-
- if(!ReadFile(LogFile->hFile,
- RecBuf,
- dwRecSize,
- &dwRead,
- NULL))
- {
- DPRINT1("ReadFile() failed! %d\n", GetLastError());
- HeapFree(MyHeap, 0, RecBuf);
- return FALSE;
- }
-
- if(dwRead != dwRecSize)
- {
- HeapFree(MyHeap, 0, RecBuf);
- break;
- }
-
- pdwRecSize2 = (PDWORD)(((PBYTE)RecBuf)+dwRecSize-4);
- if(*pdwRecSize2 != dwRecSize)
- {
- DPRINT1("Invalid size2 of record %d (%x) in %s\n",
- dwRecordsNumber,
- *pdwRecSize2,
- LogFile->LogName);
- HeapFree(MyHeap, 0, RecBuf);
- break;
- }
-
- dwRecordsNumber++;
-
- if(!LogfAddOffsetInformation(LogFile, RecBuf->RecordNumber, dwFilePointer))
- {
- DPRINT1("LogfAddOffsetInformation() failed!\n");
- HeapFree(MyHeap, 0, RecBuf);
- return FALSE;
- }
-
- HeapFree(MyHeap, 0, RecBuf);
- }//for(;;)
-
- LogFile->Header.NextRecord = dwRecordsNumber+1;
- LogFile->Header.OldestRecord = dwRecordsNumber ? 1 : 0; //FIXME
-
- if(!SetFilePointer(LogFile->hFile, 0, NULL, FILE_CURRENT) ==
- INVALID_SET_FILE_POINTER)
- {
- DPRINT1("SetFilePointer() failed! %d\n", GetLastError());
- return FALSE;
- }
-
- if(!WriteFile(LogFile->hFile,
- &LogFile->Header,
- sizeof(FILE_HEADER),
- &dwRead,
- NULL))
- {
- DPRINT1("WriteFile failed! %d\n", GetLastError());
- return FALSE;
- }
-
- if(!FlushFileBuffers(LogFile->hFile))
- {
- DPRINT1("FlushFileBuffers failed! %d\n", GetLastError());
- return FALSE;
- }
-
- return TRUE;
-}
-
-PLOGFILE LogfCreate(WCHAR *LogName,
- WCHAR *FileName)
+ }
+
+ for (;;)
+ {
+ dwFilePointer = SetFilePointer(LogFile->hFile, 0, NULL, FILE_CURRENT);
+
+ if (dwFilePointer == INVALID_SET_FILE_POINTER)
+ {
+ DPRINT1("SetFilePointer failed! %d\n", GetLastError());
+ return FALSE;
+ }
+
+ if (!ReadFile(LogFile->hFile,
+ &dwRecSize,
+ sizeof(dwRecSize),
+ &dwRead,
+ NULL))
+ {
+ DPRINT1("ReadFile failed! %d\n", GetLastError());
+ return FALSE;
+ }
+
+ if (dwRead != sizeof(dwRecSize))
+ break;
+
+ if (!ReadFile(LogFile->hFile,
+ &dwRecSign,
+ sizeof(dwRecSign),
+ &dwRead,
+ NULL))
+ {
+ DPRINT1("ReadFile() failed! %d\n", GetLastError());
+ return FALSE;
+ }
+
+ if (dwRead != sizeof(dwRecSize))
+ break;
+
+ if (dwRecSign != LOGFILE_SIGNATURE ||
+ dwRecSize + dwFilePointer > GetFileSize(LogFile->hFile, NULL) + 1 ||
+ dwRecSize < sizeof(EVENTLOGRECORD))
+ {
+ break;
+ }
+
+ if (SetFilePointer(LogFile->hFile,
+ -((LONG) sizeof(DWORD) * 2),
+ NULL,
+ FILE_CURRENT) == INVALID_SET_FILE_POINTER)
+ {
+ DPRINT1("SetFilePointer() failed! %d", GetLastError());
+ return FALSE;
+ }
+
+ RecBuf = (PEVENTLOGRECORD) HeapAlloc(MyHeap, 0, dwRecSize);
+
+ if (!RecBuf)
+ {
+ DPRINT1("Can't allocate heap!\n");
+ return FALSE;
+ }
+
+ if (!ReadFile(LogFile->hFile, RecBuf, dwRecSize, &dwRead, NULL))
+ {
+ DPRINT1("ReadFile() failed! %d\n", GetLastError());
+ HeapFree(MyHeap, 0, RecBuf);
+ return FALSE;
+ }
+
+ if (dwRead != dwRecSize)
+ {
+ HeapFree(MyHeap, 0, RecBuf);
+ break;
+ }
+
+ pdwRecSize2 = (PDWORD) (((PBYTE) RecBuf) + dwRecSize - 4);
+
+ if (*pdwRecSize2 != dwRecSize)
+ {
+ DPRINT1("Invalid size2 of record %d (%x) in %s\n",
+ dwRecordsNumber, *pdwRecSize2, LogFile->LogName);
+ HeapFree(MyHeap, 0, RecBuf);
+ break;
+ }
+
+ dwRecordsNumber++;
+
+ if (!LogfAddOffsetInformation(LogFile,
+ RecBuf->RecordNumber,
+ dwFilePointer))
+ {
+ DPRINT1("LogfAddOffsetInformation() failed!\n");
+ HeapFree(MyHeap, 0, RecBuf);
+ return FALSE;
+ }
+
+ HeapFree(MyHeap, 0, RecBuf);
+ } // for(;;)
+
+ LogFile->Header.NextRecord = dwRecordsNumber + 1;
+ LogFile->Header.OldestRecord = dwRecordsNumber ? 1 : 0; // FIXME
+
+ if (!SetFilePointer(LogFile->hFile, 0, NULL, FILE_CURRENT) ==
+ INVALID_SET_FILE_POINTER)
+ {
+ DPRINT1("SetFilePointer() failed! %d\n", GetLastError());
+ return FALSE;
+ }
+
+ if (!WriteFile(LogFile->hFile,
+ &LogFile->Header,
+ sizeof(FILE_HEADER),
+ &dwRead,
+ NULL))
+ {
+ DPRINT1("WriteFile failed! %d\n", GetLastError());
+ return FALSE;
+ }
+
+ if (!FlushFileBuffers(LogFile->hFile))
+ {
+ DPRINT1("FlushFileBuffers failed! %d\n", GetLastError());
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+PLOGFILE LogfCreate(WCHAR * LogName, WCHAR * FileName)
{
PLOGFILE LogFile;
- BOOL bResult, bCreateNew = FALSE;
-
- LogFile = (LOGFILE*) HeapAlloc(MyHeap,
- HEAP_ZERO_MEMORY,
- sizeof(LOGFILE));
- if(!LogFile)
+ BOOL bResult, bCreateNew = FALSE;
+
+ LogFile = (LOGFILE *) HeapAlloc(MyHeap, HEAP_ZERO_MEMORY, sizeof(LOGFILE));
+ if (!LogFile)
{
DPRINT1("Can't allocate heap!\n");
return NULL;
@@ -275,207 +271,243 @@
FILE_SHARE_READ,
NULL,
OPEN_ALWAYS,
- FILE_ATTRIBUTE_NORMAL |
- FILE_FLAG_RANDOM_ACCESS,
+ FILE_ATTRIBUTE_NORMAL | FILE_FLAG_RANDOM_ACCESS,
NULL);
- if(LogFile->hFile == INVALID_HANDLE_VALUE)
- {
- DPRINT1("Can't create file %S.\n", FileName);
+ if (LogFile->hFile == INVALID_HANDLE_VALUE)
+ {
+ DPRINT1("Can't create file %S.\n", FileName);
HeapFree(MyHeap, 0, LogFile);
- return NULL;
- }
-
- bCreateNew = (GetLastError() == ERROR_ALREADY_EXISTS) ? FALSE : TRUE;
-
- LogFile->LogName = (WCHAR*) HeapAlloc(MyHeap,
- HEAP_ZERO_MEMORY,
- (lstrlenW(LogName)+1)*sizeof(WCHAR));
-
- if(LogFile->LogName) lstrcpyW(LogFile->LogName, LogName);
- else
- {
- DPRINT1("Can't allocate heap\n");
- HeapFree(MyHeap, 0, LogFile);
- return NULL;
- }
-
- LogFile->FileName = (WCHAR*) HeapAlloc(MyHeap,
- HEAP_ZERO_MEMORY,
- (lstrlenW(FileName)+1)*sizeof(WCHAR));
-
- if(LogFile->FileName) lstrcpyW(LogFile->FileName, FileName);
- else
- {
- DPRINT1("Can't allocate heap\n");
- goto fail;
- }
-
- LogFile->OffsetInfo = (PEVENT_OFFSET_INFO)
- HeapAlloc(MyHeap, HEAP_ZERO_MEMORY, sizeof(EVENT_OFFSET_INFO)*64);
-
- if(!LogFile->OffsetInfo)
- {
- DPRINT1("Can't allocate heap\n");
- goto fail;
- }
-
- LogFile->OffsetInfoSize = 64;
-
- if(bCreateNew)
- bResult = LogfInitializeNew(LogFile);
- else bResult = LogfInitializeExisting(LogFile);
-
- if(!bResult) goto fail;
+ return NULL;
+ }
+
+ bCreateNew = (GetLastError() == ERROR_ALREADY_EXISTS) ? FALSE : TRUE;
+
+ LogFile->LogName =
+ (WCHAR *) HeapAlloc(MyHeap,
+ HEAP_ZERO_MEMORY,
+ (lstrlenW(LogName) + 1) * sizeof(WCHAR));
+
+ if (LogFile->LogName)
+ lstrcpyW(LogFile->LogName, LogName);
+ else
+ {
+ DPRINT1("Can't allocate heap\n");
+ HeapFree(MyHeap, 0, LogFile);
+ return NULL;
+ }
+
+ LogFile->FileName =
+ (WCHAR *) HeapAlloc(MyHeap,
+ HEAP_ZERO_MEMORY,
+ (lstrlenW(FileName) + 1) * sizeof(WCHAR));
+
+ if (LogFile->FileName)
+ lstrcpyW(LogFile->FileName, FileName);
+ else
+ {
+ DPRINT1("Can't allocate heap\n");
+ goto fail;
+ }
+
+ LogFile->OffsetInfo =
+ (PEVENT_OFFSET_INFO) HeapAlloc(MyHeap,
+ HEAP_ZERO_MEMORY,
+ sizeof(EVENT_OFFSET_INFO) * 64);
+
+ if (!LogFile->OffsetInfo)
+ {
+ DPRINT1("Can't allocate heap\n");
+ goto fail;
+ }
+
+ LogFile->OffsetInfoSize = 64;
+
+ if (bCreateNew)
+ bResult = LogfInitializeNew(LogFile);
+ else
+ bResult = LogfInitializeExisting(LogFile);
+
+ if (!bResult)
+ goto fail;
InitializeCriticalSection(&LogFile->cs);
LogfListAddItem(LogFile);
return LogFile;
-fail:
- if(LogFile)
- {
- if(LogFile->OffsetInfo) HeapFree(MyHeap, 0, LogFile->OffsetInfo);
- if(LogFile->FileName) HeapFree(MyHeap, 0, LogFile->FileName);
- if(LogFile->LogName) HeapFree(MyHeap, 0, LogFile->LogName);
- HeapFree(MyHeap, 0, LogFile);
- }
- return NULL;
+ fail:
+ if (LogFile)
+ {
+ if (LogFile->OffsetInfo)
+ HeapFree(MyHeap, 0, LogFile->OffsetInfo);
+
+ if (LogFile->FileName)
+ HeapFree(MyHeap, 0, LogFile->FileName);
+
+ if (LogFile->LogName)
+ HeapFree(MyHeap, 0, LogFile->LogName);
+
+ HeapFree(MyHeap, 0, LogFile);
+ }
+
+ return NULL;
}
VOID LogfClose(PLOGFILE LogFile)
{
- if(LogFile == NULL)
- return;
+ if (LogFile == NULL)
+ return;
EnterCriticalSection(&LogFile->cs);
FlushFileBuffers(LogFile->hFile);
CloseHandle(LogFile->hFile);
-
LogfListRemoveItem(LogFile);
+
DeleteCriticalSection(&LogFile->cs);
HeapFree(MyHeap, 0, LogFile->LogName);
HeapFree(MyHeap, 0, LogFile->FileName);
- HeapFree(MyHeap, 0, LogFile->OffsetInfo);
+ HeapFree(MyHeap, 0, LogFile->OffsetInfo);
HeapFree(MyHeap, 0, LogFile);
return;
}
-PLOGFILE LogfListItemByName(WCHAR *Name)
-{
- PLOGFILE Item, Ret = NULL;
-
- EnterCriticalSection(&LogListCs);
-
- for(Item = LogListHead; Item; Item = (PLOGFILE)Item->Next)
- if(Item->LogName && lstrcmpi(Item->LogName, Name)==0)
- {
- Ret = Item;
+VOID LogfCloseAll(VOID)
+{
+ while (!IsListEmpty(&LogFileListHead))
+ {
+ LogfClose(LogfListHead());
+ }
+
+ DeleteCriticalSection(&LogFileListCs);
+}
+
+VOID LogfListInitialize(VOID)
+{
+ InitializeCriticalSection(&LogFileListCs);
+ InitializeListHead(&LogFileListHead);
+}
+
+PLOGFILE LogfListHead(VOID)
+{
+ return CONTAINING_RECORD(LogFileListHead.Flink, LOGFILE, ListEntry);
+}
+
+PLOGFILE LogfListItemByName(WCHAR * Name)
+{
+ PLIST_ENTRY CurrentEntry;
+ PLOGFILE Result = NULL;
+
+ EnterCriticalSection(&LogFileListCs);
+
+ CurrentEntry = LogFileListHead.Flink;
+ while (CurrentEntry != &LogFileListHead)
+ {
+ PLOGFILE Item = CONTAINING_RECORD(CurrentEntry,
+ LOGFILE,
+ ListEntry);
+
+ if (Item->LogName && !lstrcmpi(Item->LogName, Name))
+ {
+ Result = Item;
break;
}
- LeaveCriticalSection(&LogListCs);
- return Ret;
-}
-
-/* index starting from 1 */
-INT LogfListItemIndexByName(WCHAR *Name)
-{
- PLOGFILE Item;
- INT ret = 0, i = 1;
-
- EnterCriticalSection(&LogListCs);
-
- for(Item = LogListHead; Item; i++, Item = (PLOGFILE)Item->Next)
- if(Item->LogName && lstrcmpi(Item->LogName, Name)==0)
- {
- ret = i;
+ CurrentEntry = CurrentEntry->Flink;
+ }
+
+ LeaveCriticalSection(&LogFileListCs);
+ return Result;
+}
+
+/* Index starting from 1 */
+INT LogfListItemIndexByName(WCHAR * Name)
+{
+ PLIST_ENTRY CurrentEntry;
+ INT Result = 0;
+ INT i = 1;
+
+ EnterCriticalSection(&LogFileListCs);
+
+ CurrentEntry = LogFileListHead.Flink;
+ while (CurrentEntry != &LogFileListHead)
+ {
+ PLOGFILE Item = CONTAINING_RECORD(CurrentEntry,
+ LOGFILE,
+ ListEntry);
+
+ if (Item->LogName && !lstrcmpi(Item->LogName, Name))
+ {
+ Result = i;
break;
}
- LeaveCriticalSection(&LogListCs);
- return ret;
-}
-
-/* index starting from 1 */
+ CurrentEntry = CurrentEntry->Flink;
+ i++;
+ }
+
+ LeaveCriticalSection(&LogFileListCs);
+ return Result;
+}
+
+/* Index starting from 1 */
PLOGFILE LogfListItemByIndex(INT Index)
{
+ PLIST_ENTRY CurrentEntry;
+ PLOGFILE Result = NULL;
INT i = 1;
- PLOGFILE Item = LogListHead;
-
- EnterCriticalSection(&LogListCs);
- for(; Item && i<Index; Item = (PLOGFILE)Item->Next, i++);
- LeaveCriticalSection(&LogListCs);
-
- return Item;
+
+ EnterCriticalSection(&LogFileListCs);
+
+ CurrentEntry = LogFileListHead.Flink;
+ while (CurrentEntry != &LogFileListHead)
+ {
+ if (i == Index)
+ {
+ Result = CONTAINING_RECORD(CurrentEntry, LOGFILE, ListEntry);
+ break;
+ }
+
+ CurrentEntry = CurrentEntry->Flink;
+ i++;
+ }
+
+ LeaveCriticalSection(&LogFileListCs);
+ return Result;
}
INT LogfListItemCount()
{
- PLOGFILE Item = LogListHead;
+ PLIST_ENTRY CurrentEntry;
INT i = 0;
- EnterCriticalSection(&LogListCs);
- while(Item)
- {
- i++;
- Item = (PLOGFILE) Item->Next;
- }
- LeaveCriticalSection(&LogListCs);
-
+ EnterCriticalSection(&LogFileListCs);
+
+ CurrentEntry = LogFileListHead.Flink;
+ while (CurrentEntry != &LogFileListHead)
+ {
+ CurrentEntry = CurrentEntry->Flink;
+ i++;
+ }
+
+ LeaveCriticalSection(&LogFileListCs);
return i;
}
VOID LogfListAddItem(PLOGFILE Item)
{
- EnterCriticalSection(&LogListCs);
-
- if(LogListHead)
- {
- PLOGFILE List = LogListHead;
-
- while(List->Next)
- List = (PLOGFILE)List->Next;
-
- Item->Prev = (PVOID)List;
- Item->Next = NULL;
- List->Next = Item;
- }
- else
- {
- Item->Next = NULL;
- Item->Prev = NULL;
- LogListHead = Item;
- }
-
- LeaveCriticalSection(&LogListCs);
+ EnterCriticalSection(&LogFileListCs);
+ InsertTailList(&LogFileListHead, &Item->ListEntry);
+ LeaveCriticalSection(&LogFileListCs);
}
VOID LogfListRemoveItem(PLOGFILE Item)
{
- PLOGFILE prev = (PLOGFILE)Item->Prev;
- PLOGFILE next = (PLOGFILE)Item->Next;
-
- EnterCriticalSection(&LogListCs);
-
- if(prev && next)
- {
- prev->Next = next;
- next->Prev = prev;
- }
- else if(next)
- {
- LogListHead = next;
- next->Prev = NULL;
- }
- else if(prev) prev->Next = NULL;
- else LogListHead = NULL;
-
- LeaveCriticalSection(&LogListCs);
-
+ EnterCriticalSection(&LogFileListCs);
+ RemoveEntryList(&Item->ListEntry);
+ LeaveCriticalSection(&LogFileListCs);
}
BOOL LogfReadEvent(PLOGFILE LogFile,
@@ -483,383 +515,391 @@
DWORD RecordNumber,
DWORD BufSize,
PBYTE Buffer,
- DWORD *BytesRead,
- DWORD *BytesNeeded)
-{
- DWORD dwOffset, dwRead, dwRecSize;
- DWORD dwBufferUsage = 0, dwRecNum;
-
- if(Flags & EVENTLOG_FORWARDS_READ &&
- Flags & EVENTLOG_BACKWARDS_READ)
- {
- return FALSE;
- }
-
- if(!(Flags & EVENTLOG_FORWARDS_READ) &&
- !(Flags & EVENTLOG_BACKWARDS_READ))
- {
- return FALSE;
- }
-
- if(!Buffer || !BytesRead || !BytesNeeded)
- {
- return FALSE;
- }
-
- dwRecNum = RecordNumber;
- EnterCriticalSection(&LogFile->cs);
- dwOffset = LogfOffsetByNumber(LogFile, dwRecNum);
-
- if(!dwOffset)
- {
- LeaveCriticalSection(&LogFile->cs);
- return FALSE;
- }
-
- if(SetFilePointer(LogFile->hFile, dwOffset, NULL, FILE_BEGIN)
- == INVALID_SET_FILE_POINTER)
- {
- DPRINT1("SetFilePointer() failed! %d\n", GetLastError());
- LeaveCriticalSection(&LogFile->cs);
- return FALSE;
- }
-
- if(!ReadFile(LogFile->hFile, &dwRecSize, sizeof(DWORD), &dwRead, NULL))
- {
- DPRINT1("ReadFile() failed! %d\n", GetLastError());
- LeaveCriticalSection(&LogFile->cs);
- return FALSE;
- }
-
- if(dwRecSize > BufSize)
- {
- *BytesRead = 0;
- *BytesNeeded = dwRecSize;
- SetLastError(ERROR_INSUFFICIENT_BUFFER);
- LeaveCriticalSection(&LogFile->cs);
- return FALSE;
- }
-
- if(SetFilePointer(LogFile->hFile,
- -((LONG)sizeof(DWORD)),
- NULL,
- FILE_CURRENT) == INVALID_SET_FILE_POINTER)
- {
- DPRINT1("SetFilePointer() failed! %d\n", GetLastError());
- LeaveCriticalSection(&LogFile->cs);
- return FALSE;
- }
-
- if(!ReadFile(LogFile->hFile, Buffer, dwRecSize, &dwRead, NULL))
- {
- DPRINT1("ReadFile() failed! %d\n", GetLastError());
- LeaveCriticalSection(&LogFile->cs);
- return FALSE;
- }
-
- dwBufferUsage+=dwRead;
-
- while(dwBufferUsage<BufSize)
- {
- if(Flags & EVENTLOG_FORWARDS_READ)
- dwRecNum++;
- else dwRecNum--;
-
- dwOffset = LogfOffsetByNumber(LogFile, dwRecNum);
- if(!dwOffset) break;
-
- if(SetFilePointer(LogFile->hFile, dwOffset, NULL, FILE_BEGIN)
- == INVALID_SET_FILE_POINTER)
- {
- DPRINT1("SetFilePointer() failed! %d\n", GetLastError());
- LeaveCriticalSection(&LogFile->cs);
- return FALSE;
- }
-
- if(!ReadFile(LogFile->hFile, &dwRecSize, sizeof(DWORD), &dwRead, NULL))
- {
- DPRINT1("ReadFile() failed! %d\n", GetLastError());
- LeaveCriticalSection(&LogFile->cs);
- return FALSE;
- }
-
- if(dwBufferUsage+dwRecSize>BufSize)break;
-
- if(SetFilePointer(LogFile->hFile,
- -((LONG)sizeof(DWORD)),
- NULL,
- FILE_CURRENT) == INVALID_SET_FILE_POINTER)
- {
- DPRINT1("SetFilePointer() failed! %d\n", GetLastError());
- LeaveCriticalSection(&LogFile->cs);
- return FALSE;
- }
-
- if(!ReadFile(LogFile->hFile,
- Buffer+dwBufferUsage,
- dwRecSize,
- &dwRead,
- NULL))
- {
- DPRINT1("ReadFile() failed! %d\n", GetLastError());
- LeaveCriticalSection(&LogFile->cs);
- return FALSE;
- }
-
- dwBufferUsage+=dwRead;
- }
-
- *BytesRead = dwBufferUsage;
- LeaveCriticalSection(&LogFile->cs);
- return TRUE;
-}
-
-BOOL LogfWriteData(PLOGFILE LogFile,
- DWORD BufSize,
- PBYTE Buffer)
-{
- DWORD dwWritten;
- SYSTEMTIME st;
- EOF_RECORD EofRec;
-
- if(!Buffer)
- {
- return FALSE;
- }
-
- GetSystemTime(&st);
- SystemTimeToEventTime(&st, &((PEVENTLOGRECORD)Buffer)->TimeWritten);
-
- EnterCriticalSection(&LogFile->cs);
-
- if(SetFilePointer(LogFile->hFile,
- LogFile->Header.EofOffset,
- NULL, FILE_BEGIN) == INVALID_SET_FILE_POINTER)
- {
- DPRINT1("SetFilePointer() failed! %d\n", GetLastError());
- LeaveCriticalSection(&LogFile->cs);
- return FALSE;
- }
-
- if(!WriteFile(LogFile->hFile, Buffer, BufSize, &dwWritten, NULL))
- {
- DPRINT1("WriteFile() failed! %d\n", GetLastError());
- LeaveCriticalSection(&LogFile->cs);
- return FALSE;
- }
-
- if(!LogfAddOffsetInformation(LogFile,
- LogFile->Header.NextRecord,
- LogFile->Header.EofOffset))
- {
- LeaveCriticalSection(&LogFile->cs);
- return FALSE;
- }
-
- LogFile->Header.NextRecord++;
- LogFile->Header.EofOffset += dwWritten;
-
- if(LogFile->Header.OldestRecord == 0)
- LogFile->Header.OldestRecord = 1;
-
- EofRec.Ones = 0x11111111;
- EofRec.Twos = 0x22222222;
- EofRec.Threes = 0x33333333;
- EofRec.Fours = 0x44444444;
- EofRec.Size1 = sizeof(EOF_RECORD);
- EofRec.Size2 = sizeof(EOF_RECORD);
- EofRec.NextRecordNumber = LogFile->Header.NextRecord;
- EofRec.OldestRecordNumber = LogFile->Header.OldestRecord;
- EofRec.StartOffset = LogFile->Header.FirstRecordOffset;
- EofRec.EndOffset = LogFile->Header.EofOffset;
-
- if(!WriteFile(LogFile->hFile,
- &EofRec,
- sizeof(EOF_RECORD),
- &dwWritten, NULL))
- {
- DPRINT1("WriteFile() failed! %d\n", GetLastError());
- LeaveCriticalSection(&LogFile->cs);
- return FALSE;
- }
-
- if(SetFilePointer(LogFile->hFile, 0, NULL, FILE_BEGIN)
- == INVALID_SET_FILE_POINTER)
- {
- DPRINT1("SetFilePointer() failed! %d\n", GetLastError());
- LeaveCriticalSection(&LogFile->cs);
- return FALSE;
- }
-
- if(!WriteFile(LogFile->hFile,
- &LogFile->Header,
- sizeof(FILE_HEADER),
- &dwWritten,
- NULL))
- {
- DPRINT1("WriteFile failed! LastError = %d\n", GetLastError());
- LeaveCriticalSection(&LogFile->cs);
- return FALSE;
- }
-
- if(!FlushFileBuffers(LogFile->hFile))
- {
- LeaveCriticalSection(&LogFile->cs);
- DPRINT1("FlushFileBuffers() failed! %d\n", GetLastError());
- return FALSE;
- }
-
- LeaveCriticalSection(&LogFile->cs);
- return TRUE;
-}
-
-ULONG LogfOffsetByNumber(PLOGFILE LogFile,
- DWORD RecordNumber)
+ DWORD * BytesRead,
+ DWORD * BytesNeeded)
+{
+ DWORD dwOffset, dwRead, dwRecSize;
+ DWORD dwBufferUsage = 0, dwRecNum;
+
+ if (Flags & EVENTLOG_FORWARDS_READ && Flags &
EVENTLOG_BACKWARDS_READ)
+ return FALSE;
+
+ if (!(Flags & EVENTLOG_FORWARDS_READ) && !(Flags &
EVENTLOG_BACKWARDS_READ))
+ return FALSE;
+
+ if (!Buffer || !BytesRead || !BytesNeeded)
+ return FALSE;
+
+ dwRecNum = RecordNumber;
+ EnterCriticalSection(&LogFile->cs);
+ dwOffset = LogfOffsetByNumber(LogFile, dwRecNum);
+
+ if (!dwOffset)
+ {
+ LeaveCriticalSection(&LogFile->cs);
+ return FALSE;
+ }
+
+ if (SetFilePointer(LogFile->hFile, dwOffset, NULL, FILE_BEGIN) ==
+ INVALID_SET_FILE_POINTER)
+ {
+ DPRINT1("SetFilePointer() failed! %d\n", GetLastError());
+ LeaveCriticalSection(&LogFile->cs);
+ return FALSE;
+ }
+
+ if (!ReadFile(LogFile->hFile, &dwRecSize, sizeof(DWORD), &dwRead, NULL))
+ {
+ DPRINT1("ReadFile() failed! %d\n", GetLastError());
+ LeaveCriticalSection(&LogFile->cs);
+ return FALSE;
+ }
+
+ if (dwRecSize > BufSize)
+ {
+ *BytesRead = 0;
+ *BytesNeeded = dwRecSize;
+ SetLastError(ERROR_INSUFFICIENT_BUFFER);
+ LeaveCriticalSection(&LogFile->cs);
+ return FALSE;
+ }
+
+ if (SetFilePointer(LogFile->hFile,
+ -((LONG) sizeof(DWORD)),
+ NULL,
+ FILE_CURRENT) == INVALID_SET_FILE_POINTER)
+ {
+ DPRINT1("SetFilePointer() failed! %d\n", GetLastError());
+ LeaveCriticalSection(&LogFile->cs);
+ return FALSE;
+ }
+
+ if (!ReadFile(LogFile->hFile, Buffer, dwRecSize, &dwRead, NULL))
+ {
+ DPRINT1("ReadFile() failed! %d\n", GetLastError());
+ LeaveCriticalSection(&LogFile->cs);
+ return FALSE;
+ }
+
+ dwBufferUsage += dwRead;
+
+ while (dwBufferUsage < BufSize)
+ {
+ if (Flags & EVENTLOG_FORWARDS_READ)
+ dwRecNum++;
+ else
+ dwRecNum--;
+
+ dwOffset = LogfOffsetByNumber(LogFile, dwRecNum);
+ if (!dwOffset)
+ break;
+
+ if (SetFilePointer(LogFile->hFile, dwOffset, NULL, FILE_BEGIN) ==
+ INVALID_SET_FILE_POINTER)
+ {
+ DPRINT1("SetFilePointer() failed! %d\n", GetLastError());
+ LeaveCriticalSection(&LogFile->cs);
+ return FALSE;
+ }
+
+ if (!ReadFile(LogFile->hFile,
+ &dwRecSize,
+ sizeof(DWORD),
+ &dwRead,
+ NULL))
+ {
+ DPRINT1("ReadFile() failed! %d\n", GetLastError());
+ LeaveCriticalSection(&LogFile->cs);
+ return FALSE;
+ }
+
+ if (dwBufferUsage + dwRecSize > BufSize)
+ break;
+
+ if (SetFilePointer(LogFile->hFile,
+ -((LONG) sizeof(DWORD)),
+ NULL,
+ FILE_CURRENT) == INVALID_SET_FILE_POINTER)
+ {
+ DPRINT1("SetFilePointer() failed! %d\n", GetLastError());
+ LeaveCriticalSection(&LogFile->cs);
+ return FALSE;
+ }
+
+ if (!ReadFile(LogFile->hFile,
+ Buffer + dwBufferUsage,
+ dwRecSize,
+ &dwRead,
+ NULL))
+ {
+ DPRINT1("ReadFile() failed! %d\n", GetLastError());
+ LeaveCriticalSection(&LogFile->cs);
+ return FALSE;
+ }
+
+ dwBufferUsage += dwRead;
+ }
+
+ *BytesRead = dwBufferUsage;
+ LeaveCriticalSection(&LogFile->cs);
+ return TRUE;
+}
+
+BOOL LogfWriteData(PLOGFILE LogFile, DWORD BufSize, PBYTE Buffer)
+{
+ DWORD dwWritten;
+ SYSTEMTIME st;
+ EOF_RECORD EofRec;
+
+ if (!Buffer)
+ return FALSE;
+
+ GetSystemTime(&st);
+ SystemTimeToEventTime(&st, &((PEVENTLOGRECORD) Buffer)->TimeWritten);
+
+ EnterCriticalSection(&LogFile->cs);
+
+ if (SetFilePointer(LogFile->hFile,
+ LogFile->Header.EofOffset,
+ NULL,
+ FILE_BEGIN) == INVALID_SET_FILE_POINTER)
+ {
+ DPRINT1("SetFilePointer() failed! %d\n", GetLastError());
+ LeaveCriticalSection(&LogFile->cs);
+ return FALSE;
+ }
+
+ if (!WriteFile(LogFile->hFile, Buffer, BufSize, &dwWritten, NULL))
+ {
+ DPRINT1("WriteFile() failed! %d\n", GetLastError());
+ LeaveCriticalSection(&LogFile->cs);
+ return FALSE;
+ }
+
+ if (!LogfAddOffsetInformation(LogFile,
+ LogFile->Header.NextRecord,
+ LogFile->Header.EofOffset))
+ {
+ LeaveCriticalSection(&LogFile->cs);
+ return FALSE;
+ }
+
+ LogFile->Header.NextRecord++;
+ LogFile->Header.EofOffset += dwWritten;
+
+ if (LogFile->Header.OldestRecord == 0)
+ LogFile->Header.OldestRecord = 1;
+
+ EofRec.Ones = 0x11111111;
+ EofRec.Twos = 0x22222222;
+ EofRec.Threes = 0x33333333;
+ EofRec.Fours = 0x44444444;
+ EofRec.Size1 = sizeof(EOF_RECORD);
+ EofRec.Size2 = sizeof(EOF_RECORD);
+ EofRec.NextRecordNumber = LogFile->Header.NextRecord;
+ EofRec.OldestRecordNumber = LogFile->Header.OldestRecord;
+ EofRec.StartOffset = LogFile->Header.FirstRecordOffset;
+ EofRec.EndOffset = LogFile->Header.EofOffset;
+
+ if (!WriteFile(LogFile->hFile,
+ &EofRec,
+ sizeof(EOF_RECORD),
+ &dwWritten,
+ NULL))
+ {
+ DPRINT1("WriteFile() failed! %d\n", GetLastError());
+ LeaveCriticalSection(&LogFile->cs);
+ return FALSE;
+ }
+
+ if (SetFilePointer(LogFile->hFile, 0, NULL, FILE_BEGIN) ==
+ INVALID_SET_FILE_POINTER)
+ {
+ DPRINT1("SetFilePointer() failed! %d\n", GetLastError());
+ LeaveCriticalSection(&LogFile->cs);
+ return FALSE;
+ }
+
+ if (!WriteFile(LogFile->hFile,
+ &LogFile->Header,
+ sizeof(FILE_HEADER),
+ &dwWritten,
+ NULL))
+ {
+ DPRINT1("WriteFile failed! LastError = %d\n", GetLastError());
+ LeaveCriticalSection(&LogFile->cs);
+ return FALSE;
+ }
+
+ if (!FlushFileBuffers(LogFile->hFile))
+ {
+ LeaveCriticalSection(&LogFile->cs);
+ DPRINT1("FlushFileBuffers() failed! %d\n", GetLastError());
+ return FALSE;
+ }
+
+ LeaveCriticalSection(&LogFile->cs);
+ return TRUE;
+}
+
+ULONG LogfOffsetByNumber(PLOGFILE LogFile, DWORD RecordNumber)
+
/* Returns 0 if nothing found. */
{
- DWORD i;
- for(i = 0; i < LogFile->OffsetInfoNext; i++)
- if(LogFile->OffsetInfo[i].EventNumber == RecordNumber)
- return LogFile->OffsetInfo[i].EventOffset;
- return 0;
+ DWORD i;
+
+ for (i = 0; i < LogFile->OffsetInfoNext; i++)
+ {
+ if (LogFile->OffsetInfo[i].EventNumber == RecordNumber)
+ return LogFile->OffsetInfo[i].EventOffset;
+ }
+ return 0;
}
DWORD LogfGetOldestRecord(PLOGFILE LogFile)
{
- return LogFile->Header.OldestRecord;
-}
-
-BOOL LogfAddOffsetInformation(PLOGFILE LogFile,
- ULONG ulNumber,
- ULONG ulOffset)
-{
- LPVOID NewOffsetInfo;
-
- if(LogFile->OffsetInfoNext == LogFile->OffsetInfoSize)
- {
- NewOffsetInfo = HeapReAlloc(MyHeap,
- HEAP_ZERO_MEMORY,
- LogFile->OffsetInfo,
- (LogFile->OffsetInfoSize+64)*
- sizeof(EVENT_OFFSET_INFO));
- if(!NewOffsetInfo)
- {
- DPRINT1("Can't reallocate heap.\n");
- return FALSE;
- }
-
- LogFile->OffsetInfo = (PEVENT_OFFSET_INFO)NewOffsetInfo;
- LogFile->OffsetInfoSize+=64;
- }
-
- LogFile->OffsetInfo[LogFile->OffsetInfoNext].EventNumber = ulNumber;
- LogFile->OffsetInfo[LogFile->OffsetInfoNext].EventOffset = ulOffset;
- LogFile->OffsetInfoNext++;
-
- return TRUE;
+ return LogFile->Header.OldestRecord;
+}
+
+BOOL LogfAddOffsetInformation(PLOGFILE LogFile, ULONG ulNumber, ULONG ulOffset)
+{
+ LPVOID NewOffsetInfo;
+
+ if (LogFile->OffsetInfoNext == LogFile->OffsetInfoSize)
+ {
+ NewOffsetInfo = HeapReAlloc(MyHeap,
+ HEAP_ZERO_MEMORY,
+ LogFile->OffsetInfo,
+ (LogFile->OffsetInfoSize + 64) *
+ sizeof(EVENT_OFFSET_INFO));
+
+ if (!NewOffsetInfo)
+ {
+ DPRINT1("Can't reallocate heap.\n");
+ return FALSE;
+ }
+
+ LogFile->OffsetInfo = (PEVENT_OFFSET_INFO) NewOffsetInfo;
+ LogFile->OffsetInfoSize += 64;
+ }
+
+ LogFile->OffsetInfo[LogFile->OffsetInfoNext].EventNumber = ulNumber;
+ LogFile->OffsetInfo[LogFile->OffsetInfoNext].EventOffset = ulOffset;
+ LogFile->OffsetInfoNext++;
+
+ return TRUE;
}
PBYTE LogfAllocAndBuildNewRecord(LPDWORD lpRecSize,
- DWORD dwRecordNumber,
- WORD wType,
- WORD wCategory,
- DWORD dwEventId,
- LPCWSTR SourceName,
- LPCWSTR ComputerName,
- DWORD dwSidLength,
- PSID lpUserSid,
- WORD wNumStrings,
- WCHAR *lpStrings,
- DWORD dwDataSize,
- LPVOID lpRawData)
-{
- DWORD dwRecSize;
- PEVENTLOGRECORD pRec;
- SYSTEMTIME SysTime;
- WCHAR *str;
- UINT i, pos, nStrings;
- PBYTE Buffer;
-
- dwRecSize = sizeof(EVENTLOGRECORD) + (lstrlenW(ComputerName) +
- lstrlenW(SourceName) + 2)*sizeof(WCHAR);
-
- if(dwRecSize % 4 != 0) dwRecSize += 4 - (dwRecSize % 4);
- dwRecSize += dwSidLength;
-
- for(i = 0, str = lpStrings; i < wNumStrings; i++)
- {
- dwRecSize += (lstrlenW(str)+1)*sizeof(WCHAR);
- str += lstrlenW(str)+1;
- }
-
- dwRecSize += dwDataSize;
- if(dwRecSize % 4 != 0) dwRecSize += 4 - (dwRecSize % 4);
- dwRecSize+=4;
-
- Buffer = (BYTE*) HeapAlloc(MyHeap, HEAP_ZERO_MEMORY, dwRecSize);
- if(!Buffer)
- {
- DPRINT1("Can't allocate heap!\n");
- return NULL;
- }
-
- pRec = (PEVENTLOGRECORD)Buffer;
- pRec->Length = dwRecSize;
- pRec->Reserved = LOGFILE_SIGNATURE;
- pRec->RecordNumber = dwRecordNumber;
-
- GetSystemTime(&SysTime);
- SystemTimeToEventTime(&SysTime, &pRec->TimeGenerated);
- SystemTimeToEventTime(&SysTime, &pRec->TimeWritten);
-
- pRec->EventID = dwEventId;
- pRec->EventType = wType;
- pRec->NumStrings = wNumStrings;
- pRec->EventCategory = wCategory;
-
- pos = sizeof(EVENTLOGRECORD);
-
- lstrcpyW((WCHAR*)(Buffer+pos), SourceName);
- pos+=(lstrlenW(SourceName)+1)*sizeof(WCHAR);
- lstrcpyW((WCHAR*)(Buffer+pos), ComputerName);
- pos+=(lstrlenW(ComputerName)+1)*sizeof(WCHAR);
-
- pRec->UserSidOffset = pos;
- if(dwSidLength)
- {
- if(pos % 4 != 0) pos += 4 - (pos % 4);
- CopyMemory(Buffer+pos, lpUserSid, dwSidLength);
- pRec->UserSidLength = dwSidLength;
- pRec->UserSidOffset = pos;
- pos+=dwSidLength;
- }
-
- pRec->StringOffset = pos;
- for(i = 0, str = lpStrings, nStrings = 0; i < wNumStrings; i++)
- {
- lstrcpyW((WCHAR*)(Buffer+pos), str);
- pos += (lstrlenW(str)+1)*sizeof(WCHAR);
- str += lstrlenW(str)+1;
- nStrings++;
- }
- pRec->NumStrings = nStrings;
-
- pRec->DataOffset = pos;
- if(dwDataSize)
- {
- pRec->DataLength = dwDataSize;
- CopyMemory(Buffer+pos, lpRawData, dwDataSize);
- pos += dwDataSize;
- }
-
- if(pos % 4 != 0) pos += 4 - (pos % 4);
- *((PDWORD)(Buffer+pos)) = dwRecSize;
-
- *lpRecSize = dwRecSize;
- return Buffer;
+ DWORD dwRecordNumber,
+ WORD wType,
+ WORD wCategory,
+ DWORD dwEventId,
+ LPCWSTR SourceName,
+ LPCWSTR ComputerName,
+ DWORD dwSidLength,
+ PSID lpUserSid,
+ WORD wNumStrings,
+ WCHAR * lpStrings,
+ DWORD dwDataSize,
+ LPVOID lpRawData)
+{
+ DWORD dwRecSize;
+ PEVENTLOGRECORD pRec;
+ SYSTEMTIME SysTime;
+ WCHAR *str;
+ UINT i, pos, nStrings;
+ PBYTE Buffer;
+
+ dwRecSize =
+ sizeof(EVENTLOGRECORD) + (lstrlenW(ComputerName) +
+ lstrlenW(SourceName) + 2) * sizeof(WCHAR);
+
+ if (dwRecSize % 4 != 0)
+ dwRecSize += 4 - (dwRecSize % 4);
+
+ dwRecSize += dwSidLength;
+
+ for (i = 0, str = lpStrings; i < wNumStrings; i++)
+ {
+ dwRecSize += (lstrlenW(str) + 1) * sizeof(WCHAR);
+ str += lstrlenW(str) + 1;
+ }
+
+ dwRecSize += dwDataSize;
+ if (dwRecSize % 4 != 0)
+ dwRecSize += 4 - (dwRecSize % 4);
+
+ dwRecSize += 4;
+
+ Buffer = (BYTE *) HeapAlloc(MyHeap, HEAP_ZERO_MEMORY, dwRecSize);
+
+ if (!Buffer)
+ {
+ DPRINT1("Can't allocate heap!\n");
+ return NULL;
+ }
+
+ pRec = (PEVENTLOGRECORD) Buffer;
+ pRec->Length = dwRecSize;
+ pRec->Reserved = LOGFILE_SIGNATURE;
+ pRec->RecordNumber = dwRecordNumber;
+
+ GetSystemTime(&SysTime);
+ SystemTimeToEventTime(&SysTime, &pRec->TimeGenerated);
+ SystemTimeToEventTime(&SysTime, &pRec->TimeWritten);
+
+ pRec->EventID = dwEventId;
+ pRec->EventType = wType;
+ pRec->NumStrings = wNumStrings;
+ pRec->EventCategory = wCategory;
+
+ pos = sizeof(EVENTLOGRECORD);
+
+ lstrcpyW((WCHAR *) (Buffer + pos), SourceName);
+ pos += (lstrlenW(SourceName) + 1) * sizeof(WCHAR);
+ lstrcpyW((WCHAR *) (Buffer + pos), ComputerName);
+ pos += (lstrlenW(ComputerName) + 1) * sizeof(WCHAR);
+
+ pRec->UserSidOffset = pos;
+ if (dwSidLength)
+ {
+ if (pos % 4 != 0)
+ pos += 4 - (pos % 4);
+ CopyMemory(Buffer + pos, lpUserSid, dwSidLength);
+ pRec->UserSidLength = dwSidLength;
+ pRec->UserSidOffset = pos;
+ pos += dwSidLength;
+ }
+
+ pRec->StringOffset = pos;
+ for (i = 0, str = lpStrings, nStrings = 0; i < wNumStrings; i++)
+ {
+ lstrcpyW((WCHAR *) (Buffer + pos), str);
+ pos += (lstrlenW(str) + 1) * sizeof(WCHAR);
+ str += lstrlenW(str) + 1;
+ nStrings++;
+ }
+ pRec->NumStrings = nStrings;
+
+ pRec->DataOffset = pos;
+ if (dwDataSize)
+ {
+ pRec->DataLength = dwDataSize;
+ CopyMemory(Buffer + pos, lpRawData, dwDataSize);
+ pos += dwDataSize;
+ }
+
+ if (pos % 4 != 0)
+ pos += 4 - (pos % 4);
+
+ *((PDWORD) (Buffer + pos)) = dwRecSize;
+
+ *lpRecSize = dwRecSize;
+ return Buffer;
}
void __inline LogfFreeRecord(LPVOID Rec)
{
- HeapFree(MyHeap, 0, Rec);
-}
+ HeapFree(MyHeap, 0, Rec);
+}
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 (original)
+++ trunk/reactos/base/services/eventlog/logport.c Thu May 3 11:47:12 2007
@@ -23,20 +23,18 @@
NTSTATUS STDCALL PortThreadRoutine(PVOID Param)
{
NTSTATUS Status = STATUS_SUCCESS;
-
+
Status = InitLogPort();
- if(!NT_SUCCESS(Status))
+ if (!NT_SUCCESS(Status))
return Status;
- while(NT_SUCCESS(Status))
- {
+ while (NT_SUCCESS(Status))
Status = ProcessPortMessage();
- }
- if(ConnectPortHandle != NULL)
+ if (ConnectPortHandle != NULL)
NtClose(ConnectPortHandle);
- if(MessagePortHandle != NULL)
+ if (MessagePortHandle != NULL)
NtClose(MessagePortHandle);
return Status;
@@ -48,47 +46,36 @@
UNICODE_STRING PortName;
PORT_MESSAGE Request;
NTSTATUS Status;
-
+
ConnectPortHandle = NULL;
MessagePortHandle = NULL;
RtlInitUnicodeString(&PortName, L"\\ErrorLogPort");
- InitializeObjectAttributes(
- &ObjectAttributes,
- &PortName,
- 0,
- NULL,
- NULL);
+ InitializeObjectAttributes(&ObjectAttributes, &PortName, 0, NULL, NULL);
- Status = NtCreatePort(
- &ConnectPortHandle,
- &ObjectAttributes,
- 0,
- 0x100,
- 0x2000);
-
- if(!NT_SUCCESS(Status))
+ Status = NtCreatePort(&ConnectPortHandle,
+ &ObjectAttributes,
+ 0,
+ 0x100,
+ 0x2000);
+
+ if (!NT_SUCCESS(Status))
{
DPRINT1("NtCreatePort() failed (Status %lx)\n", Status);
goto ByeBye;
}
Status = NtListenPort(ConnectPortHandle, &Request);
-
- if(!NT_SUCCESS(Status))
+
+ if (!NT_SUCCESS(Status))
{
DPRINT1("NtListenPort() failed (Status %lx)\n", Status);
goto ByeBye;
}
- Status = NtAcceptConnectPort(
- &MessagePortHandle,
- ConnectPortHandle,
- NULL,
- TRUE,
- NULL,
- NULL);
-
+ Status = NtAcceptConnectPort(&MessagePortHandle, ConnectPortHandle,
+ NULL, TRUE, NULL, NULL);
+
if (!NT_SUCCESS(Status))
{
DPRINT1("NtAcceptConnectPort() failed (Status %lx)\n", Status);
@@ -102,42 +89,40 @@
goto ByeBye;
}
-ByeBye:
+ ByeBye:
if (!NT_SUCCESS(Status))
{
- if(ConnectPortHandle != NULL)
+ if (ConnectPortHandle != NULL)
NtClose(ConnectPortHandle);
- if(MessagePortHandle != NULL)
+ if (MessagePortHandle != NULL)
NtClose(MessagePortHandle);
}
return Status;
}
-
NTSTATUS ProcessPortMessage(VOID)
{
IO_ERROR_LPC Request;
PIO_ERROR_LOG_MESSAGE Message;
- PEVENTLOGRECORD pRec;
+ PEVENTLOGRECORD pRec;
ULONG ulRecNum;
DWORD dwRecSize;
NTSTATUS Status;
- PLOGFILE SystemLog = NULL;
-
+ PLOGFILE SystemLog = NULL;
+
DPRINT("ProcessPortMessage() called\n");
- SystemLog = LogfListItemByName(L"System");
-
- while(TRUE)
+ SystemLog = LogfListItemByName(L"System");
+
+ while (TRUE)
{
- Status = NtReplyWaitReceivePort(
- MessagePortHandle,
- 0,
- NULL,
- &Request.Header);
-
- if(!NT_SUCCESS(Status))
+ Status = NtReplyWaitReceivePort(MessagePortHandle,
+ 0,
+ NULL,
+ &Request.Header);
+
+ if (!NT_SUCCESS(Status))
{
DPRINT1("NtReplyWaitReceivePort() failed (Status %lx)\n", Status);
break;
@@ -145,58 +130,58 @@
DPRINT("Received message\n");
- if(Request.Header.u2.s2.Type == LPC_PORT_CLOSED)
+ if (Request.Header.u2.s2.Type == LPC_PORT_CLOSED)
{
DPRINT("Port closed\n");
return STATUS_SUCCESS;
}
-
- if(Request.Header.u2.s2.Type == LPC_REQUEST)
+
+ if (Request.Header.u2.s2.Type == LPC_REQUEST)
{
DPRINT("Received request\n");
}
else if (Request.Header.u2.s2.Type == LPC_DATAGRAM)
{
DPRINT("Received datagram\n");
- Message = (PIO_ERROR_LOG_MESSAGE)&Request.Message;
- ulRecNum = SystemLog ? SystemLog->Header.NextRecord : 0;
+ Message = (PIO_ERROR_LOG_MESSAGE) & Request.Message;
+ ulRecNum = SystemLog ? SystemLog->Header.NextRecord : 0;
- pRec = (PEVENTLOGRECORD)LogfAllocAndBuildNewRecord(&dwRecSize,
- ulRecNum,
- Message->Type,
- Message->EntryData.EventCategory,
- Message->EntryData.ErrorCode,
- (WCHAR*)(((PBYTE)Message)+Message->DriverNameOffset),
- L"MyComputer", /* FIXME */
- 0,
- NULL,
- Message->EntryData.NumberOfStrings,
- (WCHAR*)(((PBYTE)Message)+Message->EntryData.StringOffset),
- Message->EntryData.DumpDataSize,
- (LPVOID)(((PBYTE)Message)
- +sizeof(IO_ERROR_LOG_PACKET)-sizeof(ULONG)));
+ pRec = (PEVENTLOGRECORD) LogfAllocAndBuildNewRecord(&dwRecSize,
+ ulRecNum, Message->Type, Message->EntryData.EventCategory,
+ Message->EntryData.ErrorCode,
+ (WCHAR *) (((PBYTE) Message) + Message->DriverNameOffset),
+ L"MyComputer", /* FIXME */
+ 0,
+ NULL,
+ Message->EntryData.NumberOfStrings,
+ (WCHAR *) (((PBYTE) Message) + Message->EntryData.StringOffset),
+ Message->EntryData.DumpDataSize,
+ (LPVOID) (((PBYTE) Message) + sizeof(IO_ERROR_LOG_PACKET) -
+ sizeof(ULONG)));
- if(pRec == NULL)
- {
- DPRINT("LogfAllocAndBuildNewRecord failed!\n");
- return STATUS_NO_MEMORY;
- }
-
- DPRINT("dwRecSize = %d\n", dwRecSize);
-
- DPRINT("\n --- EVENTLOG RECORD ---\n");
- PRINT_RECORD(pRec);
- DPRINT("\n");
-
- if(!onLiveCD && SystemLog)
- {
- if(!LogfWriteData(SystemLog, dwRecSize, (PBYTE)pRec))
- DPRINT("LogfWriteData failed!\n");
- else DPRINT("Data written to Log!\n");
- }
+ if (pRec == NULL)
+ {
+ DPRINT("LogfAllocAndBuildNewRecord failed!\n");
+ return STATUS_NO_MEMORY;
+ }
- LogfFreeRecord(pRec);
+ DPRINT("dwRecSize = %d\n", dwRecSize);
+
+ DPRINT("\n --- EVENTLOG RECORD ---\n");
+ PRINT_RECORD(pRec);
+ DPRINT("\n");
+
+ if (!onLiveCD && SystemLog)
+ {
+ if (!LogfWriteData(SystemLog, dwRecSize, (PBYTE) pRec))
+ DPRINT("LogfWriteData failed!\n");
+ else
+ DPRINT("Data written to Log!\n");
+ }
+
+ LogfFreeRecord(pRec);
}
}
+
return 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 (original)
+++ trunk/reactos/base/services/eventlog/rpc.c Thu May 3 11:47:12 2007
@@ -5,38 +5,40 @@
* PURPOSE: Event logging service
* COPYRIGHT: Copyright 2005 Saveliy Tretiakov
*/
-
+
+/* INCLUDES *****************************************************************/
+
#include "eventlog.h"
#ifdef RPC_ENABLED
+/* FUNCTIONS ****************************************************************/
+
DWORD STDCALL RpcThreadRoutine(LPVOID lpParameter)
{
RPC_STATUS Status;
- Status = RpcServerUseProtseqEpW(L"ncacn_np",
- 20,
- L"\\pipe\\EventLog",
- NULL);
- if(Status != RPC_S_OK)
+ Status = RpcServerUseProtseqEpW(L"ncacn_np", 20,
L"\\pipe\\EventLog", NULL);
+ if (Status != RPC_S_OK)
{
DPRINT("RpcServerUseProtseqEpW() failed (Status %lx)\n", Status);
return 0;
}
+
#ifdef _MSC_VER
Status = RpcServerRegisterIf(eventlog_v0_0_s_ifspec, NULL, NULL);
#else
Status = RpcServerRegisterIf(eventlog_ServerIfHandle, NULL, NULL);
#endif
-
- if(Status != RPC_S_OK)
+
+ if (Status != RPC_S_OK)
{
DPRINT("RpcServerRegisterIf() failed (Status %lx)\n", Status);
return 0;
}
Status = RpcServerListen(1, RPC_C_LISTEN_MAX_CALLS_DEFAULT, FALSE);
-
- if(Status != RPC_S_OK)
+
+ if (Status != RPC_S_OK)
{
DPRINT("RpcServerListen() failed (Status %lx)\n", Status);
}
@@ -45,35 +47,35 @@
}
/* Function 0 */
-NTSTATUS ElfrClearELFW(
- /* [in] */ LOGHANDLE Handle,
- /* [in] */ PUNICODE_STRING BackupName)
-{
- DPRINT("UNIMPLEMENTED");
+NTSTATUS ElfrClearELFW(
+ /* [in] */ LOGHANDLE Handle,
+ /* [in] */ PUNICODE_STRING BackupName)
+{
+ DPRINT("UNIMPLEMENTED");
return STATUS_NOT_IMPLEMENTED;
}
/* Function 1 */
-NTSTATUS ElfrBackupELFW(
- /* [in] */ LOGHANDLE Handle,
- /* [in] */ PUNICODE_STRING BackupName)
-{
- DPRINT("UNIMPLEMENTED");
- return STATUS_NOT_IMPLEMENTED;
-}
-
-
+NTSTATUS ElfrBackupELFW(
+ /* [in] */ LOGHANDLE Handle,
+ /* [in] */ PUNICODE_STRING BackupName)
+{
+ DPRINT("UNIMPLEMENTED");
+ return STATUS_NOT_IMPLEMENTED;
+}
+
+
/* Function 2 */
-NTSTATUS ElfrCloseEL(
+NTSTATUS ElfrCloseEL(
/* [out][in] */ PLOGHANDLE Handle)
{
DPRINT("UNIMPLEMENTED");
return STATUS_NOT_IMPLEMENTED;
}
-
+
/* Function 3 */
-NTSTATUS ElfrDeregisterEventSource(
+NTSTATUS ElfrDeregisterEventSource(
/* [out][in] */ PLOGHANDLE Handle)
{
DPRINT("UNIMPLEMENTED");
@@ -82,9 +84,9 @@
/* Function 4 */
-NTSTATUS ElfrNumberOfRecords(
- /* [in] */ LOGHANDLE Handle,
- /* [out] */ long __RPC_FAR *NumberOfRecords)
+NTSTATUS ElfrNumberOfRecords(
+ /* [in] */ LOGHANDLE Handle,
+ /* [out] */ long __RPC_FAR * NumberOfRecords)
{
DPRINT("UNIMPLEMENTED");
return STATUS_NOT_IMPLEMENTED;
@@ -92,9 +94,9 @@
/* Function 5 */
-NTSTATUS ElfrOldestRecord(
- /* [in] */ LOGHANDLE LogHandle,
- /* [out] */ long __RPC_FAR *OldestRecNumber)
+NTSTATUS ElfrOldestRecord(
+ /* [in] */ LOGHANDLE LogHandle,
+ /* [out] */ long __RPC_FAR * OldestRecNumber)
{
DPRINT("EventLogGetOldestRec UNIMPLEMENTED\n");
return STATUS_NOT_IMPLEMENTED;
@@ -102,7 +104,7 @@
/* Function 6 */
-NTSTATUS ElfrChangeNotify( void)
+NTSTATUS ElfrChangeNotify(void)
{
DPRINT("EventLogChangeNotify UNIMPLEMENTED\n");
return STATUS_NOT_IMPLEMENTED;
@@ -110,39 +112,39 @@
/* Function 7 */
-NTSTATUS ElfrOpenELW(
- /* [unique][in] */ LPWSTR ServerName,
- /* [in] */ PUNICODE_STRING FileName,
- /* [in] */ PUNICODE_STRING NullStr,
- /* [in] */ long MajorVer,
- /* [in] */ long MinorVer,
+NTSTATUS ElfrOpenELW(
+ /* [unique][in] */ LPWSTR ServerName,
+ /* [in] */ PUNICODE_STRING FileName,
+ /* [in] */ PUNICODE_STRING NullStr,
+ /* [in] */ long MajorVer,
+ /* [in] */ long MinorVer,
/* [out] */ PLOGHANDLE Handle)
{
DPRINT("EventLogOpenW UNIMPLEMENTED\n");
return STATUS_NOT_IMPLEMENTED;
}
-
+
/* Function 8 */
-NTSTATUS ElfrRegisterEventSourceW(
- /* [unique][in] */ LPWSTR ServerName,
- /* [in] */ PUNICODE_STRING LogName,
- /* [in] */ PUNICODE_STRING NullStr,
- /* [in] */ long MajorVer,
- /* [in] */ long MinorVer,
+NTSTATUS ElfrRegisterEventSourceW(
+ /* [unique][in] */ LPWSTR ServerName,
+ /* [in] */ PUNICODE_STRING LogName,
+ /* [in] */ PUNICODE_STRING NullStr,
+ /* [in] */ long MajorVer,
+ /* [in] */ long MinorVer,
/* [out] */ PLOGHANDLE Handle)
{
DPRINT("EventLogRegSrcW UNIMPLEMENTED\n");
return STATUS_NOT_IMPLEMENTED;
}
-
+
/* Function 9 */
-NTSTATUS ElfrOpenBELW(
- /* [unique][in] */ LPWSTR ServerName,
- /* [in] */ PUNICODE_STRING BackupName,
- /* [in] */ long MajorVer,
- /* [in] */ long MinorVer,
+NTSTATUS ElfrOpenBELW(
+ /* [unique][in] */ LPWSTR ServerName,
+ /* [in] */ PUNICODE_STRING BackupName,
+ /* [in] */ long MajorVer,
+ /* [in] */ long MinorVer,
/* [out] */ PLOGHANDLE Handle)
{
DPRINT("EventLogOpenBackupW UNIMPLEMENTED\n");
@@ -151,14 +153,14 @@
/* Function 10 */
-NTSTATUS ElfrReadELW(
- /* [in] */ LOGHANDLE Handle,
- /* [in] */ long Flags,
- /* [in] */ long Offset,
- /* [in] */ long BufSize,
- /* [size_is][out] */ unsigned char __RPC_FAR *Buffer,
- /* [out] */ long __RPC_FAR *BytesRead,
- /* [out] */ long __RPC_FAR *BytesNeeded)
+NTSTATUS ElfrReadELW(
+ /* [in] */ LOGHANDLE Handle,
+ /* [in] */ long Flags,
+ /* [in] */ long Offset,
+ /* [in] */ long BufSize,
+ /* [size_is][out] */unsigned char __RPC_FAR * Buffer,
+ /* [out] */ long __RPC_FAR * BytesRead,
+ /* [out] */ long __RPC_FAR * BytesNeeded)
{
DPRINT("EventLogReadW UNIMPLEMENTED\n");
return STATUS_NOT_IMPLEMENTED;
@@ -166,31 +168,31 @@
/* Function 11 */
-NTSTATUS ElfrReportEventW(
- /* [in] */ LOGHANDLE Handle,
- /* [in] */ long Time,
- /* [in] */ short Type,
- /* [in] */ short Category,
- /* [in] */ long ID,
- /* [in] */ short NumStrings,
- /* [in] */ long DataSize,
- /* [in] */ PUNICODE_STRING ComputerName,
- /* [unique][in] */ unsigned char __RPC_FAR *SID,
- /* [unique][size_is][in] */ PUNICODE_STRING __RPC_FAR Strings[ ],
- /* [unique][size_is][in] */ unsigned char __RPC_FAR *Data,
- /* [in] */ short Flags,
- /* [unique][out][in] */ long __RPC_FAR *unknown1,
- /* [unique][out][in] */ long __RPC_FAR *unknown2)
+NTSTATUS ElfrReportEventW(
+ /* [in] */ LOGHANDLE Handle,
+ /* [in] */ long Time,
+ /* [in] */ short Type,
+ /* [in] */ short Category,
+ /* [in] */ long ID,
+ /* [in] */ short NumStrings,
+ /* [in] */ long DataSize,
+ /* [in] */ PUNICODE_STRING ComputerName,
+ /* [unique][in] */ unsigned char __RPC_FAR * SID,
+ /* [unique][size_is][in] */ PUNICODE_STRING __RPC_FAR Strings[],
+ /* [unique][size_is][in] */ unsigned char __RPC_FAR * Data,
+ /* [in] */ short Flags,
+ /* [unique][out][in] */ long __RPC_FAR * unknown1,
+ /* [unique][out][in] */ long __RPC_FAR * unknown2)
{
DPRINT("EventLogReportEventW UNIMPLEMENTED\n");
return STATUS_NOT_IMPLEMENTED;
}
-
+
/* Function 12 */
-NTSTATUS ElfrClearELFA(
- /* [in] */ LOGHANDLE Handle,
- /* [unique][in] */ PANSI_STRING BackupName)
+NTSTATUS ElfrClearELFA(
+ /* [in] */ LOGHANDLE Handle,
+ /* [unique][in] */ PANSI_STRING BackupName)
{
DPRINT("EventLogClearA UNIMPLEMENTED\n");
return STATUS_NOT_IMPLEMENTED;
@@ -198,9 +200,9 @@
/* Function 13 */
-NTSTATUS ElfrBackupELFA(
- /* [in] */ LOGHANDLE Handle,
- /* [in] */ PANSI_STRING BackupName)
+NTSTATUS ElfrBackupELFA(
+ /* [in] */ LOGHANDLE Handle,
+ /* [in] */ PANSI_STRING BackupName)
{
DPRINT("EventLogBackupA UNIMPLEMENTED\n");
return STATUS_NOT_IMPLEMENTED;
@@ -208,51 +210,46 @@
/* Function 14 */
-NTSTATUS ElfrOpenELA(
- /* [unique][in] */ LPSTR ServerName,
- /* [in] */ PANSI_STRING LogName,
- /* [in] */ PANSI_STRING NullStr,
- /* [in] */ long MajorVer,
- /* [in] */ long MinorVer,
- /* [out] */ PLOGHANDLE Handle)
-{
- UNICODE_STRING logname = {0}, servername={0}, StrNull = {0};
- NTSTATUS status;
-
- if(LogName && !RtlCreateUnicodeStringFromAsciiz(&logname, LogName))
- {
- return STATUS_NO_MEMORY;
- }
-
- if(ServerName &&
- !RtlCreateUnicodeStringFromAsciiz(&servername, ServerName))
- {
+NTSTATUS ElfrOpenELA(
+ /* [unique][in] */ LPSTR ServerName,
+ /* [in] */ PANSI_STRING LogName,
+ /* [in] */ PANSI_STRING NullStr,
+ /* [in] */ long MajorVer,
+ /* [in] */ long MinorVer,
+ /* [out] */ PLOGHANDLE Handle)
+{
+ UNICODE_STRING logname = { 0 }, servername = { 0 }, StrNull = { 0 };
+ NTSTATUS status;
+
+ if (LogName && !RtlCreateUnicodeStringFromAsciiz(&logname, LogName))
+ {
+ return STATUS_NO_MEMORY;
+ }
+
+ if (ServerName &&
+ !RtlCreateUnicodeStringFromAsciiz(&servername, ServerName))
+ {
RtlFreeUnicodeString(&logname);
- return STATUS_NO_MEMORY;
- }
-
- status = EventLogOpenW(
- servername.Buffer,
- logname.Buffer,
- StrNull,
- MajorVer,
- MinorVer,
- Handle);
-
- RtlFreeUnicodeString(&servername);
- RtlFreeUnicodeString(&logname);
+ return STATUS_NO_MEMORY;
+ }
+
+ status = EventLogOpenW(servername.Buffer, logname.Buffer,
+ StrNull, MajorVer, MinorVer, Handle);
+
+ RtlFreeUnicodeString(&servername);
+ RtlFreeUnicodeString(&logname);
return status;
}
/* Function 15 */
-NTSTATUS ElfrRegisterEventSourceA(
- /* [unique][in] */ LPSTR ServerName,
- /* [in] */ PANSI_STRING LogName,
- /* [in] */ PANSI_STRING NullStr,
- /* [in] */ long MajorVer,
- /* [in] */ long MinorVer,
+NTSTATUS ElfrRegisterEventSourceA(
+ /* [unique][in] */ LPSTR ServerName,
+ /* [in] */ PANSI_STRING LogName,
+ /* [in] */ PANSI_STRING NullStr,
+ /* [in] */ long MajorVer,
+ /* [in] */ long MinorVer,
/* [out] */ PLOGHANDLE Handle)
{
DPRINT("EventLogRegSrcA UNIMPLEMENTED\n");
@@ -261,11 +258,11 @@
/* Function 16 */
-NTSTATUS ElfrOpenBELA(
- /* [unique][in] */ LPSTR ServerName,
- /* [in] */ PANSI_STRING BakckupName,
- /* [in] */ long MajorVer,
- /* [in] */ long MinorVer,
+NTSTATUS ElfrOpenBELA(
+ /* [unique][in] */ LPSTR ServerName,
+ /* [in] */ PANSI_STRING BakckupName,
+ /* [in] */ long MajorVer,
+ /* [in] */ long MinorVer,
/* [out] */ PLOGHANDLE Handle)
{
DPRINT("EventLogOpenBackupA UNIMPLEMENTED\n");
@@ -274,14 +271,14 @@
/* Function 17 */
-NTSTATUS ElfrReadELA(
- /* [in] */ LOGHANDLE Handle,
- /* [in] */ long Flags,
- /* [in] */ long Offset,
- /* [in] */ long BufSize,
- /* [size_is][out] */ unsigned char __RPC_FAR *Buffer,
- /* [out] */ long __RPC_FAR *BytesRead,
- /* [out] */ long __RPC_FAR *BytesNeeded)
+NTSTATUS ElfrReadELA(
+ /* [in] */ LOGHANDLE Handle,
+ /* [in] */ long Flags,
+ /* [in] */ long Offset,
+ /* [in] */ long BufSize,
+ /* [size_is][out] */unsigned char __RPC_FAR * Buffer,
+ /* [out] */ long __RPC_FAR * BytesRead,
+ /* [out] */ long __RPC_FAR * BytesNeeded)
{
DPRINT("EventLogReadA UNIMPLEMENTED\n");
return STATUS_NOT_IMPLEMENTED;
@@ -289,21 +286,21 @@
/* Function 18 */
-NTSTATUS ElfrReportEventA(
- /* [in] */ LOGHANDLE Handle,
- /* [in] */ long Time,
- /* [in] */ short Type,
- /* [in] */ short Category,
- /* [in] */ long ID,
- /* [in] */ short NumStrings,
- /* [in] */ long DataSize,
- /* [in] */ PANSI_STRING ComputerName,
- /* [unique][in] */ unsigned char __RPC_FAR *SID,
- /* [unique][size_is][in] */ PANSI_STRING __RPC_FAR Strings[ ],
- /* [unique][size_is][in] */ unsigned char __RPC_FAR *Data,
- /* [in] */ short Flags,
- /* [unique][out][in] */ long __RPC_FAR *unknown1,
- /* [unique][out][in] */ long __RPC_FAR *unknown2)
+NTSTATUS ElfrReportEventA(
+ /* [in] */ LOGHANDLE Handle,
+ /* [in] */ long Time,
+ /* [in] */ short Type,
+ /* [in] */ short Category,
+ /* [in] */ long ID,
+ /* [in] */ short NumStrings,
+ /* [in] */ long DataSize,
+ /* [in] */ PANSI_STRING ComputerName,
+ /* [unique][in] */ unsigned char __RPC_FAR * SID,
+ /* [unique][size_is][in] */ PANSI_STRING __RPC_FAR Strings[],
+ /* [unique][size_is][in] */ unsigned char __RPC_FAR * Data,
+ /* [in] */ short Flags,
+ /* [unique][out][in] */ long __RPC_FAR * unknown1,
+ /* [unique][out][in] */ long __RPC_FAR * unknown2)
{
DPRINT("EventLogReportEventA UNIMPLEMENTED\n");
return STATUS_NOT_IMPLEMENTED;
@@ -311,15 +308,15 @@
/* Function 19 */
-NTSTATUS ElfrRegisterClusterSvc( void)
+NTSTATUS ElfrRegisterClusterSvc(void)
{
DPRINT("EventLogRegisterClusterSvc UNIMPLEMENTED\n");
return STATUS_NOT_IMPLEMENTED;
}
-
-
+
+
/* Function 20 */
-NTSTATUS ElfrDeregisterClusterSvc( void)
+NTSTATUS ElfrDeregisterClusterSvc(void)
{
DPRINT("EventLogDeregisterClusterSvc UNIMPLEMENTED\n");
return STATUS_NOT_IMPLEMENTED;
@@ -327,7 +324,7 @@
/* Function 21 */
-NTSTATUS ElfrWriteClusterEvents( void)
+NTSTATUS ElfrWriteClusterEvents(void)
{
DPRINT("EventLogWriteClusterEvents UNIMPLEMENTED\n");
return STATUS_NOT_IMPLEMENTED;
@@ -335,12 +332,12 @@
/* Function 22 */
-NTSTATUS ElfrGetLogInformation(
- /* [in] */ LOGHANDLE Handle,
- /* [in] */ long InfoLevel,
- /* [size_is][out] */ unsigned char __RPC_FAR *Buffer,
- /* [in] */ long BufSize,
- /* [out] */ long __RPC_FAR *BytesNeeded)
+NTSTATUS ElfrGetLogInformation(
+ /* [in] */ LOGHANDLE Handle,
+ /* [in] */ long InfoLevel,
+ /* [size_is][out] */unsigned char __RPC_FAR * Buffer,
+ /* [in] */ long BufSize,
+ /* [out] */ long __RPC_FAR * BytesNeeded)
{
DPRINT("EventLogGetInfo UNIMPLEMENTED\n");
return STATUS_NOT_IMPLEMENTED;
@@ -348,26 +345,23 @@
/* Function 23 */
-NTSTATUS ElfrFlushEL(
- /* [in] */ LOGHANDLE Handle)
+NTSTATUS ElfrFlushEL(
+ /* [in] */ LOGHANDLE Handle)
{
DbgPrint("EventLogFlush UNIMPLEMENTED\n");
return STATUS_NOT_IMPLEMENTED;
}
#else
-void func(handle_t h){}
-#endif // RPC_ENABLED
-
-void __RPC_FAR * __RPC_USER midl_user_allocate(size_t len)
+void func(handle_t h) { }
+#endif // RPC_ENABLED
+
+void __RPC_FAR *__RPC_USER midl_user_allocate(size_t len)
{
return HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, len);
}
-
void __RPC_USER midl_user_free(void __RPC_FAR * ptr)
{
HeapFree(GetProcessHeap(), 0, ptr);
}
-
-