#include <iostream>
#include <fstream>
-#include "internal/internal.h"
#include "internal/serializer.hpp"
#include "internal/naive_policy_checker.hpp"
#include "dbuspolicy1/libdbuspolicy1.h"
int main(int argc, char *argv[])
{
- BusType bus_type = BusType::SYSTEM_BUS;
bool need_input_filename = true;
std::string output_filename;
- std::string input_filename;
+ const char *input_filename = system_bus_conf_file_primary();
int c;
while (1) {
switch(c) {
case 0:
if (option_index == 1)
- bus_type = BusType::SESSION_BUS;
+ input_filename = session_bus_conf_file_primary();
need_input_filename = false;
break;
case 'o':
print_help(argv[0]);
return 1;
}
- } else {
- switch (bus_type) {
- case BusType::SYSTEM_BUS:
- input_filename = system_bus_conf_file_primary();
- break;
- case BusType::SESSION_BUS:
- input_filename = session_bus_conf_file_primary();
- break;
- }
}
if (output_filename.empty())
- output_filename = input_filename + ".serialized";
+ output_filename = std::string(input_filename) + ".serialized";
cout << "Read from: " << input_filename << " write to: " << output_filename << endl;
ldp_xml_parser::Serializer serializer;
+++ /dev/null
-/*
- * Copyright (c) 2015 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.
-*/
-
-
-/**
- \defgroup Implementation Implementation
- Internal implementation of policy.
- */
-/**
- * \file
- * \ingroup Implementation
- */
-#ifndef _LIBDBUSPOLICY1_INTERNAL_H_
-#define _LIBDBUSPOLICY1_INTERNAL_H_
-
-typedef enum {
- SYSTEM_BUS = 0,
- SESSION_BUS = 1
-} BusType;
-
-#endif
DCL_NODESTRUCT_GLOBAL(ldp_xml_parser::NaivePolicyChecker, policy_checker_system)
DCL_NODESTRUCT_GLOBAL(ldp_xml_parser::NaivePolicyChecker, policy_checker_session)
-inline ldp_xml_parser::NaivePolicyChecker &policy_checker(BusType bus_type) {
- if (SESSION_BUS == bus_type)
- return policy_checker_session();
- return policy_checker_system();
-}
-
#endif
#include "type_list.h"
#include "bus_names_array.hpp"
-#include "internal.h"
#include <boost/utility/string_ref.hpp>
#include <string>
*/
#include "include/fb_generated.h"
#include "include/flatbuffers/flatbuffers.h"
-#include "internal.h"
#include "naive_policy_checker.hpp"
#include "serializer.hpp"
#include "tslog.hpp"
using ldp_xml_parser::MatchItemReceive;
using ldp_xml_parser::MatchItemOwn;
+typedef enum {
+ SYSTEM_BUS = 0,
+ SESSION_BUS = 1
+} BusType;
+
struct kconn {
KdbusConnection conn;
BusType bus_type;
static std::once_flag init_once_db[2];
static std::once_flag init_once_conn[2];
+inline ldp_xml_parser::NaivePolicyChecker &policy_checker(BusType bus_type) {
+ if (SESSION_BUS == bus_type)
+ return policy_checker_session();
+ return policy_checker_system();
+}
+
extern "C" void __dbuspolicy1_change_creds(uid_t uid, gid_t gid, const char* label)
{
g_udesc.uid = uid;
#include "internal/include/fb_generated.h"
-#include "internal/internal.h"
#include "internal/naive_policy_checker.hpp"
#include "internal/policy.hpp"
#include "internal/serializer.hpp"
#include "internal/storage_backend_serialized.hpp"
#include "internal/tslog.hpp"
#include "libdbuspolicy1-private.h"
-#include <dbuspolicy1/libdbuspolicy1.h>
#include <getopt.h>
#include <iostream>
#include <map>
#include "internal/include/fb_generated.h"
-#include "internal/internal.h"
#include "internal/naive_policy_checker.hpp"
#include "internal/policy.hpp"
#include "internal/serializer.hpp"
}
template <typename DB>
-bool run_tests_for_bus(const DB &db, const BusType bus_type, const std::vector<AccessTest>& test_setup, int& i, bool& passed) {
-
+bool run_tests_for_bus(const DB &db, NaivePolicyChecker &checker, const std::vector<AccessTest>& test_setup, int& i, bool& passed) {
for (const auto& test : test_setup) {
- auto &checker = policy_checker(bus_type);
-
checker.updateGroupDb(test.user, test.group);
const auto &gids = *checker.getGroups<MatchItemAccess>(test.user, test.group);
const auto& system_bus_setup = access_test.first;
const auto& session_bus_setup = access_test.second;
- policy_checker_system().initDb(system_bus_setup.first.c_str());
+ auto &checker_system = policy_checker_system();
+ auto &checker_session = policy_checker_session();
+
+ checker_system.initDb(system_bus_setup.first.c_str());
if (session_bus_setup.first != "") {
- policy_checker_session().initDb(session_bus_setup.first.c_str());
+ checker_session.initDb(session_bus_setup.first.c_str());
}
- auto *sys_db = &policy_checker_system().getPolicyDb();
- auto *ses_db = &policy_checker_session().getPolicyDb();
-
printf("POLICY_DB:\n");
- return run_tests_for_bus(*sys_db, SYSTEM_BUS, system_bus_setup.second, i, passed) &&
- run_tests_for_bus(*ses_db, SESSION_BUS, session_bus_setup.second, i, passed);
+ return run_tests_for_bus(checker_system.getPolicyDb(), checker_system, system_bus_setup.second, i, passed) &&
+ run_tests_for_bus(checker_session.getPolicyDb(), checker_session, session_bus_setup.second, i, passed);
}
bool run_fb(const std::pair<TestBusSetup, TestBusSetup> access_test) {
const FB::File *file_sys = FB::GetFile(buff_sys);
storage_sys.init(file_sys);
- bool res = run_tests_for_bus(storage_sys, SYSTEM_BUS, system_bus_setup.second, i, passed);
+ bool res = run_tests_for_bus(storage_sys, policy_checker_system(), system_bus_setup.second, i, passed);
if (buff_ses) {
const FB::File *file_ses = FB::GetFile(buff_ses);
storage_ses.init(file_ses);
- res &= run_tests_for_bus(storage_ses, SESSION_BUS, session_bus_setup.second, i, passed);
+ res &= run_tests_for_bus(storage_ses, policy_checker_session(), session_bus_setup.second, i, passed);
}
return res;
}
-#include "internal/internal.h"
#include "internal/naive_policy_checker.hpp"
#include "internal/tslog.hpp"
#include <dbuspolicy1/libdbuspolicy1.h>
DECISIONS[t->expected_result], DECISIONS[result]);
}
-void run_tests_for_bus(BusType bus_type, const std::vector<AccessTest>& test_setup, int& i, bool& passed) {
+void run_tests_for_bus(ldp_xml_parser::NaivePolicyChecker &checker, const std::vector<AccessTest>& test_setup, int& i, bool& passed) {
for (const auto& test : test_setup) {
- auto &checker = policy_checker(bus_type);
checker.updateGroupDb(test.user, test.group);
auto decision = checker.check(bus_owner, test.user, test.group, test.label);
if (decision != test.expected_result) {
policy_checker_session().initDb(session_bus_setup.first.c_str());
}
- run_tests_for_bus(SYSTEM_BUS, system_bus_setup.second, i, passed);
- run_tests_for_bus(SESSION_BUS, session_bus_setup.second, i, passed);
+ run_tests_for_bus(policy_checker_system(), system_bus_setup.second, i, passed);
+ run_tests_for_bus(policy_checker_session(), session_bus_setup.second, i, passed);
}
return passed;
}
#include "internal/include/fb_generated.h"
-#include "internal/internal.h"
#include "internal/naive_policy_checker.hpp"
#include "internal/policy.hpp"
#include "internal/serializer.hpp"