diff --git a/src/libpsl-native/src/CMakeLists.txt b/src/libpsl-native/src/CMakeLists.txt index 28cb4a7611f..bb2e88e4626 100644 --- a/src/libpsl-native/src/CMakeLists.txt +++ b/src/libpsl-native/src/CMakeLists.txt @@ -21,6 +21,7 @@ add_library(psl-native SHARED createhardlink.cpp createsymlink.cpp followsymlink.cpp - createprocess.cpp) + createprocess.cpp + nativesyslog.cpp) target_include_directories(psl-native PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) diff --git a/src/libpsl-native/src/nativesyslog.cpp b/src/libpsl-native/src/nativesyslog.cpp new file mode 100644 index 00000000000..1445c59a14f --- /dev/null +++ b/src/libpsl-native/src/nativesyslog.cpp @@ -0,0 +1,35 @@ +//! @file nativesyslog.cpp +//! @brief Provides wrappers around the syslog apis to support exporting +//! for PInvoke calls by powershell. +//! These functions are intended only for PowerShell internal use. +#include +#include + +//! @brief Native_SysLog is a wrapper around the syslog api. +//! It explicitly passes the message as a parameter to a %s format +//! string since the message may have arbitray characters that can +//! be misinterpreted as format specifiers. +//! +//! @retval none. +extern "C" void Native_SysLog(int32_t priority, const char* message) +{ + syslog(priority, "%s", message); +} + +//! @brief Native_OpenLog is a wrapper around the openlog, syslog api. +//! it allows passing an ident and facility but uses an explicit +//! option value for consistent logging across powershell instances. +//! +//! @retval none. +extern "C" void Native_OpenLog(const char* ident, int facility) +{ + openlog(ident, LOG_NDELAY | LOG_PID, facility); +} + +//! @brief Native_OpenLog is a wrapper around the closelog, syslog api. +//! +//! @retval none. +extern "C" void Native_CloseLog() +{ + closelog(); +} diff --git a/src/libpsl-native/src/nativesyslog.h b/src/libpsl-native/src/nativesyslog.h new file mode 100644 index 00000000000..71b222fa4de --- /dev/null +++ b/src/libpsl-native/src/nativesyslog.h @@ -0,0 +1,11 @@ +#pragma once + +#include "pal.h" + +PAL_BEGIN_EXTERNC + +void Native_OpenLog(const char* ident, int facility); +void Native_SysLog(int32_t priority, const char* message); +void Native_CloseLog(); + +PAL_END_EXTERNC