mirror of
https://github.com/winfsp/winfsp.git
synced 2025-04-22 16:33:02 -05:00
dll: FspEventLogRegister, FspEventLogUnregister
This commit is contained in:
parent
12db7cf9dc
commit
9addfa5899
@ -19,6 +19,8 @@
|
||||
#include <stdarg.h>
|
||||
#include "eventlog/eventlog.h"
|
||||
|
||||
#define FSP_EVENTLOG_NAME LIBRARY_NAME
|
||||
|
||||
static HANDLE FspEventLogHandle;
|
||||
static INIT_ONCE FspEventLogInitOnce = INIT_ONCE_STATIC_INIT;
|
||||
static BOOL WINAPI FspEventLogRegisterEventSource(
|
||||
@ -68,6 +70,54 @@ FSP_API VOID FspEventLogV(ULONG Type, PWSTR Format, va_list ap)
|
||||
static BOOL WINAPI FspEventLogRegisterEventSource(
|
||||
PINIT_ONCE InitOnce, PVOID Parameter, PVOID *Context)
|
||||
{
|
||||
FspEventLogHandle = RegisterEventSourceW(0, L"" LIBRARY_NAME);
|
||||
FspEventLogHandle = RegisterEventSourceW(0, L"" FSP_EVENTLOG_NAME);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
NTSTATUS FspEventLogRegister(VOID)
|
||||
{
|
||||
extern HINSTANCE DllInstance;
|
||||
WCHAR Path[MAX_PATH];
|
||||
DWORD RegResult, DwordValue;
|
||||
HKEY RegKey;
|
||||
|
||||
if (0 == GetModuleFileNameW(DllInstance, Path, MAX_PATH))
|
||||
return FspNtStatusFromWin32(GetLastError());
|
||||
|
||||
RegResult = RegCreateKeyExW(
|
||||
HKEY_LOCAL_MACHINE, L"SYSTEM\\CurrentControlSet\\Services\\EventLog\\System\\" FSP_EVENTLOG_NAME,
|
||||
0, 0, 0, KEY_ALL_ACCESS, 0, &RegKey, 0);
|
||||
if (ERROR_SUCCESS != RegResult)
|
||||
return FspNtStatusFromWin32(RegResult);
|
||||
|
||||
RegResult = RegSetValueExW(RegKey,
|
||||
L"EventMessageFile", 0, REG_SZ, (PVOID)Path, (lstrlenW(Path) + 1) * sizeof(WCHAR));
|
||||
if (ERROR_SUCCESS != RegResult)
|
||||
goto close_and_exit;
|
||||
|
||||
DwordValue = EVENTLOG_INFORMATION_TYPE | EVENTLOG_WARNING_TYPE | EVENTLOG_ERROR_TYPE;
|
||||
RegResult = RegSetValueExW(RegKey,
|
||||
L"TypesSupported", 0, REG_DWORD, (PVOID)&DwordValue, sizeof DwordValue);
|
||||
if (ERROR_SUCCESS != RegResult)
|
||||
goto close_and_exit;
|
||||
|
||||
RegCloseKey(RegKey);
|
||||
|
||||
return STATUS_SUCCESS;
|
||||
|
||||
close_and_exit:
|
||||
RegCloseKey(RegKey);
|
||||
return FspNtStatusFromWin32(RegResult);
|
||||
}
|
||||
|
||||
NTSTATUS FspEventLogUnregister(VOID)
|
||||
{
|
||||
DWORD RegResult;
|
||||
|
||||
RegResult = RegDeleteTreeW(
|
||||
HKEY_LOCAL_MACHINE, L"SYSTEM\\CurrentControlSet\\Services\\EventLog\\System\\" FSP_EVENTLOG_NAME);
|
||||
if (ERROR_SUCCESS != RegResult && ERROR_FILE_NOT_FOUND != RegResult)
|
||||
return FspNtStatusFromWin32(RegResult);
|
||||
|
||||
return STATUS_SUCCESS;
|
||||
}
|
||||
|
@ -467,7 +467,11 @@ NTSTATUS FspFsctlUnregister(VOID)
|
||||
DWORD LastError;
|
||||
NTSTATUS Result;
|
||||
|
||||
ScmHandle = OpenSCManagerW(0, 0, 0);
|
||||
ScmHandle = OpenSCManagerW(0, 0, SC_MANAGER_CREATE_SERVICE);
|
||||
/*
|
||||
* The SC_MANAGER_CREATE_SERVICE access right is not strictly needed here,
|
||||
* but we use it to enforce admin rights.
|
||||
*/
|
||||
if (0 == ScmHandle)
|
||||
{
|
||||
Result = FspNtStatusFromWin32(GetLastError());
|
||||
|
@ -57,10 +57,15 @@ HRESULT WINAPI DllRegisterServer(VOID)
|
||||
if (!NT_SUCCESS(Result))
|
||||
goto exit;
|
||||
|
||||
/* ignore errors below; these are non-critical */
|
||||
|
||||
Result = FspNpRegister();
|
||||
FspDebugLog("FspNpRegister = %lx\n", Result);
|
||||
if (!NT_SUCCESS(Result))
|
||||
goto exit;
|
||||
|
||||
Result = FspEventLogRegister();
|
||||
FspDebugLog("FspEventLogRegister = %lx\n", Result);
|
||||
|
||||
Result = STATUS_SUCCESS;
|
||||
|
||||
exit:
|
||||
return NT_SUCCESS(Result) ? S_OK : 0x80040201/*SELFREG_E_CLASS*/;
|
||||
@ -70,19 +75,20 @@ HRESULT WINAPI DllUnregisterServer(VOID)
|
||||
{
|
||||
NTSTATUS Result;
|
||||
|
||||
Result = FspNpUnregister();
|
||||
FspDebugLog("FspNpUnregister = %lx\n", Result);
|
||||
if (!NT_SUCCESS(Result))
|
||||
goto exit;
|
||||
|
||||
Result = FspFsctlUnregister();
|
||||
FspDebugLog("FspFsctlUnregister = %lx\n", Result);
|
||||
if (!NT_SUCCESS(Result))
|
||||
{
|
||||
/* roll back network provider unregistration if possible */
|
||||
FspNpRegister();
|
||||
goto exit;
|
||||
}
|
||||
|
||||
/* ignore errors below; these are non-critical */
|
||||
|
||||
Result = FspNpUnregister();
|
||||
FspDebugLog("FspNpUnregister = %lx\n", Result);
|
||||
|
||||
Result = FspEventLogUnregister();
|
||||
FspDebugLog("FspEventLogUnregister = %lx\n", Result);
|
||||
|
||||
Result = STATUS_SUCCESS;
|
||||
|
||||
exit:
|
||||
return NT_SUCCESS(Result) ? S_OK : 0x80040201/*SELFREG_E_CLASS*/;
|
||||
|
@ -114,4 +114,7 @@ NTSTATUS FspFsctlUnregister(VOID);
|
||||
NTSTATUS FspNpRegister(VOID);
|
||||
NTSTATUS FspNpUnregister(VOID);
|
||||
|
||||
NTSTATUS FspEventLogRegister(VOID);
|
||||
NTSTATUS FspEventLogUnregister(VOID);
|
||||
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user