mirror of
https://github.com/reactos/reactos.git
synced 2025-01-05 22:12:46 +00:00
Read configuration from registry
svn path=/trunk/; revision=22712
This commit is contained in:
parent
5d1d716b06
commit
df5296300e
4 changed files with 164 additions and 49 deletions
|
@ -7,25 +7,25 @@
|
||||||
* Copyright 2005 Saveliy Tretiakov
|
* Copyright 2005 Saveliy Tretiakov
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/* INCLUDES *****************************************************************/
|
||||||
|
|
||||||
#include "eventlog.h"
|
#include "eventlog.h"
|
||||||
|
|
||||||
VOID CALLBACK ServiceMain(DWORD argc, LPTSTR *argv);
|
/* GLOBALS ******************************************************************/
|
||||||
|
|
||||||
|
VOID CALLBACK ServiceMain(DWORD argc, LPTSTR *argv);
|
||||||
SERVICE_TABLE_ENTRY ServiceTable[2] =
|
SERVICE_TABLE_ENTRY ServiceTable[2] =
|
||||||
{
|
{
|
||||||
{L"EventLog", (LPSERVICE_MAIN_FUNCTION)ServiceMain},
|
{L"EventLog", (LPSERVICE_MAIN_FUNCTION)ServiceMain},
|
||||||
{NULL, NULL}
|
{NULL, NULL}
|
||||||
};
|
};
|
||||||
|
|
||||||
/* GLOBAL VARIABLES */
|
|
||||||
HANDLE MyHeap = NULL;
|
HANDLE MyHeap = NULL;
|
||||||
PLOGFILE SystemLog = NULL;
|
|
||||||
PLOGFILE ApplicationLog = NULL;
|
|
||||||
PLOGFILE SecurityLog = NULL;
|
|
||||||
BOOL onLiveCD = FALSE; // On livecd events will go to debug output only
|
BOOL onLiveCD = FALSE; // On livecd events will go to debug output only
|
||||||
|
|
||||||
extern CRITICAL_SECTION LogListCs;
|
extern CRITICAL_SECTION LogListCs;
|
||||||
|
extern PLOGFILE LogListHead;
|
||||||
|
|
||||||
|
/* FUNCTIONS ****************************************************************/
|
||||||
|
|
||||||
VOID CALLBACK ServiceMain(DWORD argc, LPTSTR *argv)
|
VOID CALLBACK ServiceMain(DWORD argc, LPTSTR *argv)
|
||||||
{
|
{
|
||||||
|
@ -56,24 +56,147 @@ VOID CALLBACK ServiceMain(DWORD argc, LPTSTR *argv)
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BOOL LoadLogFile(HKEY hKey, WCHAR *LogName)
|
||||||
|
{
|
||||||
|
DWORD MaxValueLen, ValueLen, Type, ExpandedLen;
|
||||||
|
WCHAR *Buf = NULL, *Expanded = NULL;
|
||||||
|
LONG Result;
|
||||||
|
BOOL ret = FALSE;
|
||||||
|
PLOGFILE pLogf;
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
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());
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
if(Type != REG_EXPAND_SZ && Type != REG_SZ)
|
||||||
|
{
|
||||||
|
DPRINT1("%S\\File - value of wrong type %x.\n", LogName, Type);
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
|
ExpandedLen = ExpandEnvironmentStrings(Buf, NULL, 0);
|
||||||
|
Expanded = HeapAlloc(MyHeap, 0, ExpandedLen*sizeof(WCHAR));
|
||||||
|
|
||||||
|
if(!Expanded)
|
||||||
|
{
|
||||||
|
DPRINT1("Can't allocate heap!\n");
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
|
ExpandEnvironmentStrings(Buf, Expanded, ExpandedLen);
|
||||||
|
|
||||||
|
DPRINT("%S -> %S\n", Buf, Expanded);
|
||||||
|
|
||||||
|
pLogf = LogfCreate(LogName, Expanded);
|
||||||
|
|
||||||
|
if(pLogf == NULL)
|
||||||
|
{
|
||||||
|
DPRINT1("Failed to create %S!\n", Expanded);
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = TRUE;
|
||||||
|
|
||||||
|
cleanup:
|
||||||
|
HeapFree(MyHeap, 0, Buf);
|
||||||
|
if(Expanded) HeapFree(MyHeap, 0, Expanded);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOL LoadLogFiles(HKEY eventlogKey)
|
||||||
|
{
|
||||||
|
LONG result;
|
||||||
|
DWORD MaxLognameLen, LognameLen;
|
||||||
|
WCHAR *Buf = NULL;
|
||||||
|
BOOL ret = FALSE;
|
||||||
|
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 ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!LoadLogFile(SubKey, Buf))
|
||||||
|
DPRINT1("Failed to load %S\n", Buf);
|
||||||
|
else DPRINT("Loaded %S\n", Buf);
|
||||||
|
|
||||||
|
RegCloseKey(SubKey);
|
||||||
|
LognameLen=MaxLognameLen;
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = TRUE;
|
||||||
|
|
||||||
|
cleanup:
|
||||||
|
HeapFree(MyHeap, 0, Buf);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
INT main()
|
||||||
{
|
{
|
||||||
WCHAR LogPath[MAX_PATH];
|
WCHAR LogPath[MAX_PATH];
|
||||||
|
PLOGFILE pLogf;
|
||||||
|
INT RetCode = 0;
|
||||||
|
LONG result;
|
||||||
|
HKEY elogKey;
|
||||||
|
|
||||||
|
InitializeCriticalSection(&LogListCs);
|
||||||
|
|
||||||
MyHeap = HeapCreate(0, 1024*256, 0);
|
MyHeap = HeapCreate(0, 1024*256, 0);
|
||||||
|
|
||||||
if(MyHeap==NULL)
|
if(MyHeap==NULL)
|
||||||
{
|
{
|
||||||
DbgPrint("EventLog: FATAL ERROR, can't create heap.\n");
|
DPRINT1("FATAL ERROR, can't create heap.\n");
|
||||||
return 1;
|
RetCode = 1;
|
||||||
|
goto bye_bye;
|
||||||
}
|
}
|
||||||
|
|
||||||
InitializeCriticalSection(&LogListCs);
|
|
||||||
|
|
||||||
/*
|
|
||||||
This will be fixed in near future
|
|
||||||
*/
|
|
||||||
|
|
||||||
GetWindowsDirectory(LogPath, MAX_PATH);
|
GetWindowsDirectory(LogPath, MAX_PATH);
|
||||||
if(GetDriveType(LogPath) == DRIVE_CDROM)
|
if(GetDriveType(LogPath) == DRIVE_CDROM)
|
||||||
{
|
{
|
||||||
|
@ -82,38 +205,34 @@ int main(int argc, char *argv[])
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
lstrcat(LogPath, L"\\system32\\config\\SysEvent.evt");
|
result = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
|
||||||
|
L"SYSTEM\\CurrentControlSet\\Services\\EventLog",
|
||||||
SystemLog = LogfCreate(L"System", LogPath);
|
0,
|
||||||
|
KEY_ALL_ACCESS,
|
||||||
if(SystemLog == NULL)
|
&elogKey);
|
||||||
|
|
||||||
|
if(result != ERROR_SUCCESS)
|
||||||
{
|
{
|
||||||
DbgPrint("EventLog: FATAL ERROR, can't create %S\n", LogPath);
|
DPRINT1("Fatal error: can't open eventlog registry key.\n");
|
||||||
HeapDestroy(MyHeap);
|
RetCode = 1;
|
||||||
return 1;
|
goto bye_bye;
|
||||||
}
|
|
||||||
|
|
||||||
GetWindowsDirectory(LogPath, MAX_PATH);
|
|
||||||
lstrcat(LogPath, L"\\system32\\config\\AppEvent.evt");
|
|
||||||
|
|
||||||
ApplicationLog = LogfCreate(L"Application", LogPath);
|
|
||||||
|
|
||||||
if(ApplicationLog == NULL)
|
|
||||||
{
|
|
||||||
DbgPrint("EventLog: FATAL ERROR, can't create %S\n", LogPath);
|
|
||||||
HeapDestroy(MyHeap);
|
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LoadLogFiles(elogKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
StartServiceCtrlDispatcher(ServiceTable);
|
StartServiceCtrlDispatcher(ServiceTable);
|
||||||
|
|
||||||
|
bye_bye:
|
||||||
LogfClose(SystemLog);
|
|
||||||
DeleteCriticalSection(&LogListCs);
|
DeleteCriticalSection(&LogListCs);
|
||||||
HeapDestroy(MyHeap);
|
|
||||||
|
// Close all log files.
|
||||||
|
for(pLogf = LogListHead; pLogf; pLogf = ((PLOGFILE)pLogf)->Next)
|
||||||
|
LogfClose(pLogf);
|
||||||
|
|
||||||
|
if(MyHeap) HeapDestroy(MyHeap);
|
||||||
|
|
||||||
return 0;
|
return RetCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
VOID EventTimeToSystemTime(DWORD EventTime,
|
VOID EventTimeToSystemTime(DWORD EventTime,
|
||||||
|
@ -238,6 +357,3 @@ VOID PRINT_RECORD(PEVENTLOGRECORD pRec)
|
||||||
|
|
||||||
DPRINT("Length2=%d\n", *(PDWORD)(((PBYTE)pRec)+pRec->Length-4));
|
DPRINT("Length2=%d\n", *(PDWORD)(((PBYTE)pRec)+pRec->Length-4));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
#define __EVENTLOG_H__
|
#define __EVENTLOG_H__
|
||||||
|
|
||||||
#define WIN32_NO_STATUS
|
#define WIN32_NO_STATUS
|
||||||
|
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#include <lpctypes.h>
|
#include <lpctypes.h>
|
||||||
#include <lpcfuncs.h>
|
#include <lpcfuncs.h>
|
||||||
|
|
|
@ -300,7 +300,7 @@ PLOGFILE LogfListItemByName(WCHAR *Name)
|
||||||
EnterCriticalSection(&LogListCs);
|
EnterCriticalSection(&LogListCs);
|
||||||
|
|
||||||
for(Item = LogListHead; Item; Item = (PLOGFILE)Item->Next)
|
for(Item = LogListHead; Item; Item = (PLOGFILE)Item->Next)
|
||||||
if(Item->LogName && lstrcmpW(Item->LogName, Name)==0)
|
if(Item->LogName && lstrcmpi(Item->LogName, Name)==0)
|
||||||
{
|
{
|
||||||
Ret = Item;
|
Ret = Item;
|
||||||
break;
|
break;
|
||||||
|
@ -319,7 +319,7 @@ INT LogfListItemIndexByName(WCHAR *Name)
|
||||||
EnterCriticalSection(&LogListCs);
|
EnterCriticalSection(&LogListCs);
|
||||||
|
|
||||||
for(Item = LogListHead; Item; i++, Item = (PLOGFILE)Item->Next)
|
for(Item = LogListHead; Item; i++, Item = (PLOGFILE)Item->Next)
|
||||||
if(Item->LogName && lstrcmpW(Item->LogName, Name)==0)
|
if(Item->LogName && lstrcmpi(Item->LogName, Name)==0)
|
||||||
{
|
{
|
||||||
ret = i;
|
ret = i;
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -15,7 +15,6 @@
|
||||||
|
|
||||||
HANDLE ConnectPortHandle = NULL;
|
HANDLE ConnectPortHandle = NULL;
|
||||||
HANDLE MessagePortHandle = NULL;
|
HANDLE MessagePortHandle = NULL;
|
||||||
extern PLOGFILE SystemLog;
|
|
||||||
extern HANDLE MyHeap;
|
extern HANDLE MyHeap;
|
||||||
extern BOOL onLiveCD;
|
extern BOOL onLiveCD;
|
||||||
|
|
||||||
|
@ -125,10 +124,10 @@ NTSTATUS ProcessPortMessage(VOID)
|
||||||
NTSTATUS Status;
|
NTSTATUS Status;
|
||||||
PLOGFILE SystemLog = NULL;
|
PLOGFILE SystemLog = NULL;
|
||||||
|
|
||||||
DPRINT1("ProcessPortMessage() called\n");
|
DPRINT("ProcessPortMessage() called\n");
|
||||||
|
|
||||||
Status = STATUS_SUCCESS;
|
|
||||||
|
|
||||||
|
SystemLog = LogfListItemByName(L"System");
|
||||||
|
|
||||||
while(TRUE)
|
while(TRUE)
|
||||||
{
|
{
|
||||||
Status = NtReplyWaitReceivePort(
|
Status = NtReplyWaitReceivePort(
|
||||||
|
@ -217,4 +216,3 @@ NTSTATUS ProcessPortMessage(VOID)
|
||||||
}
|
}
|
||||||
return Status;
|
return Status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue