diff --git a/.bazelrc b/.bazelrc index 4e7d6983..18be82bb 100644 --- a/.bazelrc +++ b/.bazelrc @@ -6,6 +6,9 @@ build --copt=-Wno-error=deprecated-declarations build --per_file_copt=.*\.mm\$@-std=c++17 build --cxxopt=-std=c++17 +build --copt=-DSANTA_OPEN_SOURCE=1 +build --cxxopt=-DSANTA_OPEN_SOURCE=1 + build:asan --strip=never build:asan --copt="-Wno-macro-redefined" build:asan --copt="-D_FORTIFY_SOURCE=0" diff --git a/Source/santactl/Commands/SNTCommandPrintLog.mm b/Source/santactl/Commands/SNTCommandPrintLog.mm index d561a33b..ff10a432 100644 --- a/Source/santactl/Commands/SNTCommandPrintLog.mm +++ b/Source/santactl/Commands/SNTCommandPrintLog.mm @@ -111,7 +111,9 @@ REGISTER_COMMAND_NAME(@"printlog") } std::string json; - MessageToJsonString(santaMsg, &json, options); + if (!MessageToJsonString(santaMsg, &json, options).ok()) { + LOGE(@"Unable to convert message to JSON in file: '%@'", path); + } std::cout << json; } diff --git a/Source/santad/BUILD b/Source/santad/BUILD index 8f732d0a..ef865217 100644 --- a/Source/santad/BUILD +++ b/Source/santad/BUILD @@ -440,6 +440,7 @@ objc_library( "//Source/common:santa_cc_proto_library_wrapper", "//Source/santad/Logs/EndpointSecurity/Writers/FSSpool:fsspool", "//Source/santad/Logs/EndpointSecurity/Writers/FSSpool:fsspool_log_batch_writer", + "@com_google_absl//absl/strings", ], ) diff --git a/Source/santad/Logs/EndpointSecurity/Writers/Spool.mm b/Source/santad/Logs/EndpointSecurity/Writers/Spool.mm index 91a4ea00..36173a28 100644 --- a/Source/santad/Logs/EndpointSecurity/Writers/Spool.mm +++ b/Source/santad/Logs/EndpointSecurity/Writers/Spool.mm @@ -16,6 +16,7 @@ #import "Source/common/SNTLogging.h" #include "Source/common/santa_proto_include_wrapper.h" +#include "absl/strings/string_view.h" static const char *kTypeGoogleApisComPrefix = "type.googleapis.com/"; @@ -42,7 +43,7 @@ Spool::Spool(dispatch_queue_t q, dispatch_source_t timer_source, std::string_vie void (^write_complete_f)(void), void (^flush_task_complete_f)(void)) : q_(q), timer_source_(timer_source), - spool_writer_(base_dir, max_spool_disk_size), + spool_writer_(absl::string_view(base_dir.data(), base_dir.length()), max_spool_disk_size), log_batch_writer_(&spool_writer_, max_spool_batch_size), write_complete_f_(write_complete_f), flush_task_complete_f_(flush_task_complete_f) { @@ -100,7 +101,11 @@ void Spool::Write(std::vector &&bytes) { // Manually pack an `Any` with a pre-serialized SantaMessage google::protobuf::Any any; +#if SANTA_OPEN_SOURCE any.set_value(moved_bytes.data(), moved_bytes.size()); +#else + any.set_value(absl::string_view((const char*)moved_bytes.data(), moved_bytes.size())); +#endif any.set_type_url(type_url_); auto status = log_batch_writer_.WriteMessage(any); diff --git a/Source/santad/Logs/EndpointSecurity/Writers/SpoolTest.mm b/Source/santad/Logs/EndpointSecurity/Writers/SpoolTest.mm index 6579fb6e..0977b684 100644 --- a/Source/santad/Logs/EndpointSecurity/Writers/SpoolTest.mm +++ b/Source/santad/Logs/EndpointSecurity/Writers/SpoolTest.mm @@ -36,9 +36,6 @@ class SpoolPeer : public Spool { } // namespace santa::santad::logs::endpoint_security::writers -using ::fsspool::FsSpoolLogBatchWriter; -using ::fsspool::FsSpoolWriter; -using santa::santad::logs::endpoint_security::writers::Spool; using santa::santad::logs::endpoint_security::writers::SpoolPeer; @interface SpoolTest : XCTestCase