diff --git a/src/dll/eventlog.c b/src/dll/eventlog.c index e50d06db..a409b702 100644 --- a/src/dll/eventlog.c +++ b/src/dll/eventlog.c @@ -19,6 +19,8 @@ #include #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; +} diff --git a/src/dll/fsctl.c b/src/dll/fsctl.c index 885a4101..87dd9fab 100644 --- a/src/dll/fsctl.c +++ b/src/dll/fsctl.c @@ -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()); diff --git a/src/dll/library.c b/src/dll/library.c index ab63664e..82dfa28c 100644 --- a/src/dll/library.c +++ b/src/dll/library.c @@ -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*/; diff --git a/src/dll/library.h b/src/dll/library.h index c71c3f63..113840b8 100644 --- a/src/dll/library.h +++ b/src/dll/library.h @@ -114,4 +114,7 @@ NTSTATUS FspFsctlUnregister(VOID); NTSTATUS FspNpRegister(VOID); NTSTATUS FspNpUnregister(VOID); +NTSTATUS FspEventLogRegister(VOID); +NTSTATUS FspEventLogUnregister(VOID); + #endif