ADD_POLICYD_LIBRARY(policyd_core api.cpp
policy-manager.cpp
policy-loader.cpp
- policy-storage.cpp
- logger.cpp)
+ policy-storage.cpp)
FILE(GLOB SDK_TESTS "tests/*.cpp")
ADD_POLICYD_TEST(${SDK_TESTS})
+++ /dev/null
-/*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License
- */
-
-#include "logger.h"
-
-#include <klay/audit/dlog-sink.h>
-
-namespace policyd {
-
-std::unique_ptr<audit::LogSink> Logger::logSink = nullptr;
-std::once_flag Logger::flag;
-
-audit::LogSink* Logger::GetLogSink(const std::string& tag)
-{
- std::call_once(flag, [&]() {
- auto dlogSink = new audit::DlogLogSink(tag);
- logSink.reset(dynamic_cast<audit::LogSink*>(dlogSink));
- });
-
- return logSink.get();
-}
-
-} // namespace policyd
+++ /dev/null
-/*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License
- */
-
-#pragma once
-
-#include <klay/audit/logger.h>
-
-#include <memory>
-#include <mutex>
-
-#define VIST Logger::GetLogSink("VIST")
-
-namespace policyd {
-
-class Logger {
-public:
- static audit::LogSink* GetLogSink(const std::string& tag);
-
-private:
- static std::unique_ptr<audit::LogSink> logSink;
- static std::once_flag flag;
-};
-
-} // namespace policyd
#include "policy-manager.h"
#include "policy-loader.h"
-#include "logger.h"
+
+#include <vist/common/audit/logger.h>
#include <klay/filesystem.h>
*/
#include "policy-storage.h"
-#include "logger.h"
+
+#include <vist/common/audit/logger.h>
#include <klay/db/column.h>
#include <klay/db/query-builder.h>
#include "query.h"
-#include "ipc/client.h"
+#include <vist/common/ipc/client.h>
+#include <vist/common/audit/logger.h>
namespace {
const std::string SOCK_ADDR = "/tmp/.vist";
Rows Query::Execute(const std::string& statement)
{
+ INFO(VIST_CLIENT, "Query execution: " << statement);
auto& client = ipc::Client::Instance(SOCK_ADDR);
return client->methodCall<Rows>("Vist::query", statement);
#include <gtest/gtest.h>
-#include <osquery/logger.h>
-
#include "../virtual-table.h"
#include "../schema/time.h"
#include "../schema/policy.h"
#include "../schema/processes.h"
-using namespace osquery;
+#include <vist/common/audit/logger.h>
+
using namespace vist;
using namespace vist::schema;
result.seconds = time.at(&Time::seconds);
/// Once query execution
- LOG(INFO) << "[Test] time table:";
- LOG(INFO) << "\t hour: " << result.hour;
- LOG(INFO) << "\t minutes: " << result.minutes;
- LOG(INFO) << "\t seconds: " << result.seconds;
+ INFO(VIST_CLIENT, "[Test] time table:");
+ INFO(VIST_CLIENT, "\t hour: " << result.hour);
+ INFO(VIST_CLIENT, "\t minutes: " << result.minutes);
+ INFO(VIST_CLIENT, "\t seconds: " << result.seconds);
/// Each query execution
- LOG(INFO) << "[Test] time table:";
- LOG(INFO) << "\t hour: " << VirtualRow<Time>().at(&Time::hour);
- LOG(INFO) << "\t minutes: " << VirtualRow<Time>().at(&Time::minutes);
- LOG(INFO) << "\t seconds: " << VirtualRow<Time>().at(&Time::seconds);
+ INFO(VIST_CLIENT, "[Test] time table:");
+ INFO(VIST_CLIENT, "\t hour: " << VirtualRow<Time>().at(&Time::hour));
+ INFO(VIST_CLIENT, "\t minutes: " << VirtualRow<Time>().at(&Time::minutes));
+ INFO(VIST_CLIENT, "\t seconds: " << VirtualRow<Time>().at(&Time::seconds));
EXPECT_NE(result.hour, -1);
EXPECT_NE(result.minutes, -1);
result.seconds = time[&Time::seconds];
/// Once query execution
- LOG(INFO) << "[Test] time table:";
- LOG(INFO) << "\t hour: " << result.hour;
- LOG(INFO) << "\t minutes: " << result.minutes;
- LOG(INFO) << "\t seconds: " << result.seconds;
+ INFO(VIST_CLIENT, "[Test] time table:");
+ INFO(VIST_CLIENT, "\t hour: " << result.hour);
+ INFO(VIST_CLIENT, "\t minutes: " << result.minutes);
+ INFO(VIST_CLIENT, "\t seconds: " << result.seconds);
EXPECT_NE(result.hour, -1);
EXPECT_NE(result.minutes, -1);
result.on_disk = p.at(&Processes::on_disk);
result.parent = p.at(&Processes::parent);
- LOG(INFO) << "[Test] Processes table:";
- LOG(INFO) << "\t pid: " << result.pid;
- LOG(INFO) << "\t name: " << result.name;
- LOG(INFO) << "\t path: " << result.path;
- LOG(INFO) << "\t cmdline: " << result.cmdline;
- LOG(INFO) << "\t uid: " << result.uid;
- LOG(INFO) << "\t gid: " << result.gid;
- LOG(INFO) << "\t euid: " << result.euid;
- LOG(INFO) << "\t egid: " << result.egid;
- LOG(INFO) << "\t on_disk: " << result.on_disk;
- LOG(INFO) << "\t parent: " << result.parent;
+ INFO(VIST_CLIENT, "[Test] Processes table:");
+ INFO(VIST_CLIENT, "\t pid: " << result.pid);
+ INFO(VIST_CLIENT, "\t name: " << result.name);
+ INFO(VIST_CLIENT, "\t path: " << result.path);
+ INFO(VIST_CLIENT, "\t cmdline: " << result.cmdline);
+ INFO(VIST_CLIENT, "\t uid: " << result.uid);
+ INFO(VIST_CLIENT, "\t gid: " << result.gid);
+ INFO(VIST_CLIENT, "\t euid: " << result.euid);
+ INFO(VIST_CLIENT, "\t egid: " << result.egid);
+ INFO(VIST_CLIENT, "\t on_disk: " << result.on_disk);
+ INFO(VIST_CLIENT, "\t parent: " << result.parent);
}
}
for(const auto& row : table) {
Policy policy = { row[&Policy::name], row[&Policy::value] };
- LOG(INFO) << "[Test] Policy table:";
- LOG(INFO) << "\t name: " << policy.name;
- LOG(INFO) << "\t value: " << policy.value;
+ INFO(VIST_CLIENT, "[Test] Policy table:");
+ INFO(VIST_CLIENT, "\t name: " << policy.name);
+ INFO(VIST_CLIENT, "\t value: " << policy.value);
}
}
#include "schema/policy.h"
#include "schema/processes.h"
-#include <osquery/logger.h>
+#include <vist/common/audit/logger.h>
#include <tsqb.hxx>
std::string value = this->data.at(key);
if (value.empty()) {
- LOG(ERROR) << "The value of key[" << key << "] is not exist.";
+ ERROR(VIST, "The value of key[" << key << "] is not exist.");
return Member();
}
try {
return boost::lexical_cast<Member>(value);
} catch (...) {
- LOG(ERROR) << "Failed to casting [key]: " << key;
+ ERROR(VIST, "Failed to casting [key]: " << key);
return Member();
}
}
# See the License for the specific language governing permissions and
# limitations under the License
-FILE(GLOB IPC_TESTS "ipc/tests/*.cpp")
-ADD_VIST_TEST(${IPC_TESTS})
+FILE(GLOB COMMON_TESTS "ipc/tests/*.cpp")
+ADD_VIST_TEST(${COMMON_TESTS})
--- /dev/null
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License
+ */
+
+#pragma once
+
+#include <klay/audit/logger.h>
+#include <klay/audit/dlog-sink.h>
+
+#include <memory>
+
+#define VIST vist::Logger::Instance()
+#define VIST_CLIENT vist::Logger::ClientInstance()
+
+namespace vist {
+
+class Logger final {
+public:
+ Logger(const Logger&) = delete;
+ Logger& operator=(const Logger&) = delete;
+
+ Logger(Logger&&) = default;
+ Logger& operator=(Logger&&) = default;
+
+ static klay::LogSink* Instance()
+ {
+ static Logger instance("VIST");
+ return &instance.logSink;
+ }
+
+ static klay::LogSink* ClientInstance()
+ {
+ static Logger instance("VIST_CLIENT");
+ return &instance.logSink;
+ }
+
+private:
+ explicit Logger(const std::string& tag) : logSink(tag) {}
+ ~Logger() = default;
+
+ klay::DlogLogSink logSink;
+};
+
+} // namespace vist
*/
#include "vist.h"
-#include "ipc/server.h"
+
+#include <vist/common/ipc/server.h>
+#include <vist/common/audit/logger.h>
#include <stdexcept>
-#include <osquery/registry.h>
+#include <osquery/registry_interface.h>
#include <osquery/sql.h>
-#include <osquery/status.h>
#define QUERY_RET_TYPE std::vector<std::map<std::string, std::string>>
void Vist::start()
{
+ INFO(VIST, "Vist daemon starts.");
auto& server = ipc::Server::Instance(SOCK_ADDR);
server->expose(this, "", (QUERY_RET_TYPE)(Vist::query)(std::string));