ADD_APIX_LIBRARY(manager manager.cpp
manager_impl.cpp)
-FILE(GLOB MANAGER_TESTS "tests/*.cpp")
+FILE(GLOB MANAGER_TESTS "tests/m*.cpp")
+ADD_APIX_TEST(${MANAGER_TESTS})
IF(DEFINED GBS_BUILD)
- FILE(GLOB TIZEN_POLICYD_TESTS "tests/tizen/*.cpp")
+ FILE(GLOB POLICYD_TESTS "tests/p*.cpp")
+ ADD_APIX_TEST(${POLICYD_TESTS})
ENDIF(DEFINED GBS_BUILD)
-
-ADD_APIX_TEST(${MANAGER_TESTS})
--- /dev/null
+/*
+ * Copyright (c) 2019 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 <gtest/gtest.h>
+
+#include <osquery_manager.h>
+
+#include <osquery/logger.h>
+
+#include <policyd/core/policy-manager.h>
+
+using namespace osquery;
+
+class PolicydTests : public testing::Test {};
+
+TEST_F(PolicydTests, select) {
+ std::string query = "SELECT * FROM policy";
+ auto rows = OsqueryManager::execute(query);
+ EXPECT_TRUE(rows.size() > 0);
+
+ LOG(INFO) << "[Test] policy table rows:";
+ for (auto& r : rows) {
+ LOG(INFO) << "\t name: " << r["name"];
+ LOG(INFO) << "\t value: " << r["value"];
+ }
+
+ query = "SELECT * FROM policy WHERE name = 'bluetooth'";
+ rows = OsqueryManager::execute(query);
+
+ LOG(INFO) << "[Test] policy table rows with where clause:";
+ for (auto& r : rows) {
+ LOG(INFO) << "\t name: " << r["name"];
+ LOG(INFO) << "\t value: " << r["value"];
+ }
+
+ EXPECT_EQ(rows.size(), 1);
+}
+
+TEST_F(PolicydTests, update) {
+ auto& manager = policyd::PolicyManager::Instance();
+ manager.enroll("admin", 0);
+
+ std::string query = "SELECT * FROM policy WHERE name = 'bluetooth'";
+ auto rows = OsqueryManager::execute(query);
+ /// Initial policy value
+ EXPECT_EQ(rows[0]["value"], std::to_string(1));
+
+ query = "UPDATE policy SET value = '3' WHERE name = 'bluetooth'";
+ rows = OsqueryManager::execute(query);
+ EXPECT_EQ(rows.size(), 0);
+
+ query = "SELECT * FROM policy WHERE name = 'bluetooth'";
+ rows = OsqueryManager::execute(query);
+ /// Initial policy value
+ EXPECT_EQ(rows[0]["value"], std::to_string(3));
+
+ manager.disenroll("admin", 0);
+}
+++ /dev/null
-/*
- * Copyright (c) 2019 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 <gtest/gtest.h>
-
-#include <osquery_manager.h>
-
-#include <osquery/logger.h>
-
-#include <policyd/core/policy-manager.h>
-
-using namespace osquery;
-
-class PolicydTests : public testing::Test {};
-
-TEST_F(PolicydTests, select) {
- std::string query = "SELECT * FROM policy";
- auto rows = OsqueryManager::execute(query);
- EXPECT_TRUE(rows.size() > 0);
-
- LOG(INFO) << "[Test] policy table rows:";
- for (auto& r : rows) {
- LOG(INFO) << "\t name: " << r["name"];
- LOG(INFO) << "\t value: " << r["value"];
- }
-
- query = "SELECT * FROM policy WHERE name = 'bluetooth'";
- rows = OsqueryManager::execute(query);
-
- LOG(INFO) << "[Test] policy table rows with where clause:";
- for (auto& r : rows) {
- LOG(INFO) << "\t name: " << r["name"];
- LOG(INFO) << "\t value: " << r["value"];
- }
-
- EXPECT_EQ(rows.size(), 1);
-}
-
-TEST_F(PolicydTests, update) {
- auto& manager = policyd::PolicyManager::Instance();
- manager.enroll("admin", 0);
-
- std::string query = "SELECT * FROM policy WHERE name = 'bluetooth'";
- auto rows = OsqueryManager::execute(query);
- /// Initial policy value
- EXPECT_EQ(rows[0]["value"], std::to_string(1));
-
- query = "UPDATE policy SET value = '3' WHERE name = 'bluetooth'";
- rows = OsqueryManager::execute(query);
- EXPECT_EQ(rows.size(), 0);
-
- query = "SELECT * FROM policy WHERE name = 'bluetooth'";
- rows = OsqueryManager::execute(query);
- /// Initial policy value
- EXPECT_EQ(rows[0]["value"], std::to_string(3));
-
- manager.disenroll("admin", 0);
-}
* See the License for the specific language governing permissions and
* limitations under the License
*/
-/*
- * @file bluetooth_policy.cpp
- * @author Sangwan Kwon (sangwan.kwon@samsung.com)
- * @brief Implementation of bluetooth_policy table
- */
#include <string>
#include <memory>
#include <osquery/logger.h>
#include <osquery/tables.h>
-#include <policyd/core/policy-manager.h>
-
-using namespace policyd;
+#include <policyd/api.h>
namespace osquery {
namespace tables {
QueryData genPolicy(QueryContext& context) try {
- auto& manager = PolicyManager::Instance();
-
QueryData results;
if (context.constraints["name"].exists(EQUALS)) { /// where clause
auto names = context.constraints["name"].getAll(EQUALS);
for (const auto& name : names) {
- auto ret = manager.get(name);
+ auto ret = policyd::API::Get(name);
Row r;
r["name"] = TEXT(name);
results.emplace_back(std::move(r));
}
} else { /// select *;
- auto policies = manager.getAll();
+ auto policies = policyd::API::GetAll();
for (auto& policy : policies) {
Row r;
r["name"] = TEXT(policy.first);
std::string name = document[0].GetString();
int value = std::stoi(document[1].GetString());
- /// TODO(Sangwan): Get admin name from policyd
- auto& manager = PolicyManager::Instance();
- manager.set(name, PolicyValue(value), "admin");
+ policyd::API::Admin::Set(name, policyd::PolicyValue(value));
Row r;
r["status"] = "success";
#include <gtest/gtest.h>
-#include <policyd/core/policy-manager.h>
+#include <policyd/api.h>
class PolicyTests : public testing::Test {};
-using namespace policyd;
-
TEST_F(PolicyTests, get_all) {
- auto& manager = PolicyManager::Instance();
- auto policies = manager.getAll();
+ auto policies = policyd::API::GetAll();
EXPECT_TRUE(policies.size() > 0);
}
--- /dev/null
+/*
+ * Copyright (c) 2019 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 <policyd/sdk/policy-value.h>
+
+#include <string>
+#include <unordered_map>
+
+namespace policyd {
+
+struct API {
+ static PolicyValue Get(const std::string& policy);
+ static std::unordered_map<std::string, PolicyValue> GetAll();
+
+ struct Admin {
+ static void Set(const std::string& policy, const PolicyValue& value);
+
+ static void Enroll(const std::string& admin, uid_t uid);
+ static void Disenroll(const std::string& admin, uid_t uid);
+ };
+};
+
+} // namespace policyd
# limitations under the License.
#
-ADD_POLICYD_LIBRARY(policyd_core policy-manager.cpp
+ADD_POLICYD_LIBRARY(policyd_core api.cpp
+ policy-manager.cpp
policy-loader.cpp
policy-storage.cpp
logger.cpp)
--- /dev/null
+/*
+ * Copyright (c) 2019 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 <policyd/api.h>
+
+#include "policy-manager.h"
+
+namespace policyd {
+
+PolicyValue API::Get(const std::string& policy)
+{
+ return PolicyManager::Instance().get(policy);
+}
+
+std::unordered_map<std::string, PolicyValue> API::GetAll()
+{
+ return PolicyManager::Instance().getAll();
+}
+
+void API::Admin::Set(const std::string& policy, const PolicyValue& value)
+{
+ // TODO(Sangwan): Get admin name from peer PID
+ PolicyManager::Instance().set(policy, value, "admin");
+}
+
+void API::Admin::Enroll(const std::string& admin, uid_t uid)
+{
+ PolicyManager::Instance().enroll(admin, uid);
+}
+
+void API::Admin::Disenroll(const std::string& admin, uid_t uid)
+{
+ PolicyManager::Instance().disenroll(admin, uid);
+}
+
+} // namespace policyd