From ef79713eb6edfea9834fae3506b31dc81d6493e8 Mon Sep 17 00:00:00 2001 From: Dan Travison Date: Tue, 17 Oct 2017 13:11:53 -0700 Subject: [PATCH 1/2] Add exports for syslog api. --- src/libpsl-native/src/CMakeLists.txt | 3 ++- src/libpsl-native/src/nativesyslog.cpp | 17 +++++++++++++++++ src/libpsl-native/src/nativesyslog.h | 11 +++++++++++ 3 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 src/libpsl-native/src/nativesyslog.cpp create mode 100644 src/libpsl-native/src/nativesyslog.h 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..35a9d30a19d --- /dev/null +++ b/src/libpsl-native/src/nativesyslog.cpp @@ -0,0 +1,17 @@ +#include +#include + +extern "C" void Native_SysLog(int32_t priority, const char* message) +{ + syslog(priority, "%s", message); +} + +extern "C" void Native_OpenLog(const char* ident, int facility) +{ + openlog(ident, LOG_NDELAY | LOG_PID, facility); +} + +extern "C" void Native_CloseLog() +{ + closelog(); +} \ No newline at end of file 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 From 03817bccc4de703ddf93e61838c0a44940686bcf Mon Sep 17 00:00:00 2001 From: Dan Travison Date: Wed, 18 Oct 2017 10:07:02 -0700 Subject: [PATCH 2/2] Address PR feedback - comments and new line at EOF --- src/libpsl-native/src/nativesyslog.cpp | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/libpsl-native/src/nativesyslog.cpp b/src/libpsl-native/src/nativesyslog.cpp index 35a9d30a19d..1445c59a14f 100644 --- a/src/libpsl-native/src/nativesyslog.cpp +++ b/src/libpsl-native/src/nativesyslog.cpp @@ -1,17 +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(); -} \ No newline at end of file +}