From 54ae6b8b73b8c4228aedaa420e910d042ca67b55 Mon Sep 17 00:00:00 2001 From: Kushagra K Date: Mon, 4 Nov 2019 14:03:48 +0530 Subject: [PATCH 01/16] DF191023-00350:[Secure option] file secure option application request (PIE, etc) Change-Id: I65bbebeb5b6f8399dce4bc622c7a59b5963540ce Reviewed-by: Himanshu Maithani Signed-off-by: Hyotaek Shim --- Makefile.am | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/Makefile.am b/Makefile.am index bbf8203..9f2c98d 100644 --- a/Makefile.am +++ b/Makefile.am @@ -31,6 +31,9 @@ AM_LDFLAGS = \ -pthread \ -lexpat +BIN_CPPFLAGS = -fPIE +BIN_LDFLAGS = -pie + SED_PROCESS = \ $(AM_V_GEN)$(MKDIR_P) $(dir $@) && $(SED) \ -e 's,@VERSION\@,$(VERSION),g' \ @@ -82,7 +85,8 @@ EXTRA_src_libdbuspolicy1_la_DEPENDENCIES = ${top_srcdir}/src/libdbuspolicy1.sym dbuspolicy_serializer_SOURCES =\ src/dbuspolicy_serializer.cpp -dbuspolicy_serializer_CFLAGS="-Isrc/internal/include $(AM_CFLAGS)" +dbuspolicy_serializer_CPPFLAGS = $(AM_CPPFLAGS) $(BIN_CPPFLAGS) +dbuspolicy_serializer_LDFLAGS = $(BIN_LDFLAGS) # dbuspolicy_serializer_LDFLAGS = $(AM_LDFLAGS) \ # -version-info $(LIBDBUSPOLICY1_CURRENT):$(LIBDBUSPOLICY1_REVISION):$(LIBDBUSPOLICY1_AGE) \ @@ -103,7 +107,8 @@ dbuspolicy_serializerdir = /bin/ dbuspolicy_printer_SOURCES =\ src/dbuspolicy_printer.cpp -dbuspolicy_printer_CFLAGS="-Isrc/internal/include $(AM_CFLAGS)" +dbuspolicy_printer_CPPFLAGS = $(AM_CPPFLAGS) $(BIN_CPPFLAGS) +dbuspolicy_printer_LDFLAGS = $(BIN_LDFLAGS) dbuspolicy_printer_LDADD = src/libinternal.la \ $(CYNARA_LIBS) \ @@ -115,7 +120,8 @@ EXTRA_dbuspolicy_printer_DEPENDENCIES = ${top_srcdir}/src/libdbuspolicy1.sym dbuspolicy_finder_SOURCES =\ src/dbuspolicy_finder.cpp -dbuspolicy_finder_CFLAGS="-Isrc/internal/include $(AM_CFLAGS)" +dbuspolicy_finder_CPPFLAGS = $(AM_CPPFLAGS) $(BIN_CPPFLAGS) +dbuspolicy_finder_LDFLAGS = $(BIN_LDFLAGS) dbuspolicy_finder_LDADD = src/libinternal.la \ $(CYNARA_LIBS) \ -- 2.7.4 From c9c0b00d9b6a45484c66bdb3f40352351814ee9a Mon Sep 17 00:00:00 2001 From: "sanghyeok.oh" Date: Tue, 31 Dec 2019 10:52:06 +0900 Subject: [PATCH 02/16] Remove warning for GCC-9 Change-Id: Iefda0c2fafd09efe06ab3d8d73f593e3de406e7a Signed-off-by: sanghyeok.oh --- src/dbus_daemon.c | 4 ++-- src/libdbuspolicy1.cpp | 10 +++++++--- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/dbus_daemon.c b/src/dbus_daemon.c index 23234de..6959284 100644 --- a/src/dbus_daemon.c +++ b/src/dbus_daemon.c @@ -138,7 +138,7 @@ static int bus_acquire_name(int fd, const char *name) item = cmd->items; item->type = KDBUS_ITEM_NAME; item->size = KDBUS_ITEM_HEADER_SIZE + strlen(name) + 1; - strncpy(item->str, name, strlen(name) + 1); + memcpy(item->str, name, strlen(name) + 1); /* * Employ the command on the connection owner file descriptor. @@ -223,7 +223,7 @@ int main(int argc, char* argv[]) if (fd < 0) return -1; - while (server_names[j] != '\0') { + while (server_names[j]) { if (bus_acquire_name(fd, server_names[j])) return -1; j++; diff --git a/src/libdbuspolicy1.cpp b/src/libdbuspolicy1.cpp index 1c8f2c3..2e53479 100644 --- a/src/libdbuspolicy1.cpp +++ b/src/libdbuspolicy1.cpp @@ -69,15 +69,19 @@ struct udesc { { uid = uid_; gid = gid_; - if (label_) - strncpy(label, label_, strlen(label_) + 1); + if (label_) { + if (sizeof(label) > strlen(label_)) + memcpy(label, label_, strlen(label_) + 1); + else + LOGE("Error: failed to strcpy, length of label(%s) exceed 255", label_); + } } private: std::once_flag init_once_done; void init_once() { - char buf[1024]; + char buf[256]; int attr_fd; int r; -- 2.7.4 From b8099d58e61720f2c0612aef43d74c1d9f101a7d Mon Sep 17 00:00:00 2001 From: "sanghyeok.oh" Date: Thu, 27 Feb 2020 15:33:22 +0900 Subject: [PATCH 03/16] coverity: Fix coverity issue constexpr function should return LiteralType Coverity: #1050604 Parse warning constexpr_return_not_constant Change-Id: I608c84748dc515778bf96c6b65e59f1e389359c3 --- src/libdbuspolicy1.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libdbuspolicy1.cpp b/src/libdbuspolicy1.cpp index 2e53479..027f385 100644 --- a/src/libdbuspolicy1.cpp +++ b/src/libdbuspolicy1.cpp @@ -316,7 +316,7 @@ DBUSPOLICY1_EXPORT void* dbuspolicy1_init(const char *bus_path) // helper functions namespace { -constexpr kconn *KCONN(void *config) { return static_cast(config); } +kconn *KCONN(void *config) { return static_cast(config); } /* * This function prepares contents of info.names() for initialization of MatchItems. -- 2.7.4 From dd569bc52ec74de77b78b6d744e405f3e4c6ad7c Mon Sep 17 00:00:00 2001 From: Gaurav Gupta Date: Mon, 17 Feb 2020 11:08:45 +0530 Subject: [PATCH 04/16] Fix memleak issue reported by Dexter tool. Change-Id: I24e2d2d6b6ecb3e3daf0edd94fe67866f369e87a --- src/internal/xml_parser.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/internal/xml_parser.cpp b/src/internal/xml_parser.cpp index 62d8372..dba29ff 100644 --- a/src/internal/xml_parser.cpp +++ b/src/internal/xml_parser.cpp @@ -223,16 +223,20 @@ std::unique_ptr file2str(const char *filename) { } if (fseek(fp, 0, SEEK_END)) { + fclose(fp); throw std::runtime_error(std::string("Failed to fseek end of file").c_str()); } long fsize = ftell(fp); if (fsize < 0) { + fclose(fp); throw std::runtime_error(std::string("Failed to ftell").c_str()); } if (fsize > (MAX_CONF_SIZE)) { + fclose(fp); throw std::runtime_error(std::string("File size over ").append(std::to_string(MAX_CONF_SIZE)).append("Bytes").c_str()); } if (fseek(fp, 0, SEEK_SET)) { + fclose(fp); throw std::runtime_error(std::string("Failed to fseek beginning of file").c_str()); } -- 2.7.4 From 0a3ba72cc2532650afe3485b0a2b77739faefcec Mon Sep 17 00:00:00 2001 From: Adrian Szyndela Date: Thu, 9 Apr 2020 09:05:50 +0200 Subject: [PATCH 05/16] tests: test multiple includedirs directive This adds a test which checks if the files in all the directories specified in all the directives are parsed. It breaks the checks during building as it exposes a bug. The subsequent commit fixes the bug. Change-Id: I020246138586357717dbee73617182f79176eac9 --- Makefile.am | 5 +++- src/test-libdbuspolicy1-multiple-includedirs.cpp | 35 ++++++++++++++++++++++ .../another-system.d/some-service.conf | 12 ++++++++ .../default_deny/system-multiple-includedirs.conf | 20 +++++++++++++ tests/default_deny/system.d/some-service.conf | 15 ++++++++++ .../yet-another-system.d/some-service.conf | 12 ++++++++ 6 files changed, 98 insertions(+), 1 deletion(-) create mode 100644 src/test-libdbuspolicy1-multiple-includedirs.cpp create mode 100644 tests/default_deny/another-system.d/some-service.conf create mode 100644 tests/default_deny/system-multiple-includedirs.conf create mode 100644 tests/default_deny/system.d/some-service.conf create mode 100644 tests/default_deny/yet-another-system.d/some-service.conf diff --git a/Makefile.am b/Makefile.am index 9f2c98d..aad84e6 100644 --- a/Makefile.am +++ b/Makefile.am @@ -150,7 +150,8 @@ TESTS = src/test-libdbuspolicy1-ownership \ src/test-libdbuspolicy1-access-deny-gdi \ src/test-libdbuspolicy1-send_destination_prefix-deny \ src/test-libdbuspolicy1-send_destination_prefix-deny-gdi \ - src/test-serializer + src/test-serializer \ + src/test-libdbuspolicy1-multiple-includedirs check_PROGRAMS = $(TESTS) @@ -167,6 +168,7 @@ src_test_libdbuspolicy1_access_deny_gdi_SOURCES = src/test-libdbuspolicy1-access src_test_libdbuspolicy1_send_destination_prefix_deny_SOURCES = src/test-libdbuspolicy1-send_destination_prefix-deny.cpp src_test_libdbuspolicy1_send_destination_prefix_deny_gdi_SOURCES = src/test-libdbuspolicy1-send_destination_prefix-deny-gdi.cpp src_test_serializer_SOURCES = src/test-serializer.cpp +src_test_libdbuspolicy1_multiple_includedirs_SOURCES = src/test-libdbuspolicy1-multiple-includedirs.cpp noinst_LTLIBRARIES = src/libinternal.la src_libinternal_la_SOURCES =\ @@ -193,6 +195,7 @@ src_test_libdbuspolicy1_access_deny_gdi_LDADD = $(TESTS_LDADD) src_test_libdbuspolicy1_send_destination_prefix_deny_LDADD = $(TESTS_LDADD) src_test_libdbuspolicy1_send_destination_prefix_deny_gdi_LDADD = $(TESTS_LDADD) src_test_serializer_LDADD = $(TESTS_LDADD) +src_test_libdbuspolicy1_multiple_includedirs_LDADD = $(TESTS_LDADD) if ENABLE_STANDALONE_TESTS noinst_LTLIBRARIES += src/libinternalfortests.la diff --git a/src/test-libdbuspolicy1-multiple-includedirs.cpp b/src/test-libdbuspolicy1-multiple-includedirs.cpp new file mode 100644 index 0000000..abdb0e8 --- /dev/null +++ b/src/test-libdbuspolicy1-multiple-includedirs.cpp @@ -0,0 +1,35 @@ +#include "internal/naive_policy_checker.hpp" +#include "internal/tslog.hpp" + +#include +#include + +ldp_xml_parser::Decision test_destination(const ldp_serialized::StorageBackendSerialized &db, const char *destination) { + KdbusBusNames names; + ldp_xml_parser::MatchItemSend item("ex.ample.interface", "ExampleMember", "/Ex/Ample/Path", + ldp_xml_parser::MessageType::METHOD_CALL, names.addSpaceSeparatedNames(destination)); + + return db.getDecisionItemUser(0, item).getDecision(); +} + +#define tassert(COND) do { if (!(COND)) throw std::runtime_error("test failed: " #COND); } while (0) + +int main() try { + tslog::init(); + + auto &checker = policy_checker_system(); + checker.initDb("tests/default_deny/system-multiple-includedirs.conf"); + + auto &db = checker.getPolicyDb(); + tassert(test_destination(db, "org.tizen.test.allow-me-for-root") == ldp_xml_parser::Decision::ALLOW); + tassert(test_destination(db, "org.tizen.test.deny-me-for-root") == ldp_xml_parser::Decision::DENY); + tassert(test_destination(db, "org.tizen.test.another-allow-me-for-root") == ldp_xml_parser::Decision::ALLOW); + tassert(test_destination(db, "org.tizen.test.another-deny-me-for-root") == ldp_xml_parser::Decision::DENY); + tassert(test_destination(db, "org.tizen.test.yet-another-allow-me-for-root") == ldp_xml_parser::Decision::ALLOW); + tassert(test_destination(db, "org.tizen.test.yet-another-deny-me-for-root") == ldp_xml_parser::Decision::DENY); + + return 0; +} catch (std::runtime_error &e) { + std::cerr << e.what(); + return 1; +} diff --git a/tests/default_deny/another-system.d/some-service.conf b/tests/default_deny/another-system.d/some-service.conf new file mode 100644 index 0000000..fae3d97 --- /dev/null +++ b/tests/default_deny/another-system.d/some-service.conf @@ -0,0 +1,12 @@ + + + + + + + + + + diff --git a/tests/default_deny/system-multiple-includedirs.conf b/tests/default_deny/system-multiple-includedirs.conf new file mode 100644 index 0000000..99a7a2e --- /dev/null +++ b/tests/default_deny/system-multiple-includedirs.conf @@ -0,0 +1,20 @@ + + + + + + + + system-base.conf + + another-system.d + yet-another-system.d + + + diff --git a/tests/default_deny/system.d/some-service.conf b/tests/default_deny/system.d/some-service.conf new file mode 100644 index 0000000..4252922 --- /dev/null +++ b/tests/default_deny/system.d/some-service.conf @@ -0,0 +1,15 @@ + + + + + + + + + + + + + diff --git a/tests/default_deny/yet-another-system.d/some-service.conf b/tests/default_deny/yet-another-system.d/some-service.conf new file mode 100644 index 0000000..4ec24e9 --- /dev/null +++ b/tests/default_deny/yet-another-system.d/some-service.conf @@ -0,0 +1,12 @@ + + + + + + + + + + -- 2.7.4 From 0821d6ca80fe71fdc251580c56cbe4595f6a84f3 Mon Sep 17 00:00:00 2001 From: Adrian Szyndela Date: Thu, 9 Apr 2020 10:01:48 +0200 Subject: [PATCH 06/16] xml-parser: don't clear list of included files in each dir The 'includedir' directives should make the parser include all the files in the directories introduced with the directives. This commit removes clearing of the gathered file list when the directive is encountered. Change-Id: Id14be322e8696bd85ddfbb0ba2360a7b4b5bcda4 --- src/internal/xml_parser.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/internal/xml_parser.cpp b/src/internal/xml_parser.cpp index dba29ff..4bcbb1d 100644 --- a/src/internal/xml_parser.cpp +++ b/src/internal/xml_parser.cpp @@ -284,7 +284,7 @@ void XmlParser::getIncludedFiles(const std::string& parent_dir, const std::strin DIR *dir; struct dirent *ent; const std::string dname = expandPath(parent_dir, incldir); - files.clear(); + if ((dir = opendir(dname.c_str())) != NULL) { while ((ent = readdir(dir)) != NULL) { std::string s(ent->d_name); -- 2.7.4 From 434396148108ae1dad3215ed696e984b9930caaf Mon Sep 17 00:00:00 2001 From: Adrian Szyndela Date: Thu, 9 Apr 2020 12:38:40 +0200 Subject: [PATCH 07/16] finder: improve printing Add actual attribute names to printing instead of printing just "send" or "receive". Change-Id: Ib117847d44a57abbf1fd1217a786c1d2d8b5d218 --- src/dbuspolicy_finder.cpp | 65 +++++++++++++++++++++++++---------------------- 1 file changed, 35 insertions(+), 30 deletions(-) diff --git a/src/dbuspolicy_finder.cpp b/src/dbuspolicy_finder.cpp index f22e4cd..a8edb68 100644 --- a/src/dbuspolicy_finder.cpp +++ b/src/dbuspolicy_finder.cpp @@ -77,43 +77,48 @@ MessageType stringToMessageType(std::string tmp) { } } -std::pair getItemStrings (const ItemSend &) { - return std::make_pair ("send", "send_destination"); +std::string getPrefix(const ItemSend &) { + return "send_"; } -std::pair getItemStrings (const ItemReceive &) { - return std::make_pair ("receive", "receive_sender"); + +std::string getPrefix(const ItemReceive &) { + return "receive_"; +} + +std::string getNameAttr(const ItemSend &) { + return "destination"; +} + +std::string getNameAttr(const ItemReceive &) { + return "sender"; } template void printDecision(const T & item) { bool everything_is_null = true; - const auto strings = getItemStrings(item); + const auto prefix = getPrefix(item); + + auto printAttribute = [&everything_is_null, &prefix](const std::string &attr_name, const std::string &attr_value) { + if (!attr_value.empty()) { + std::cout << " " << prefix << attr_name << "=\"" << attr_value << "\""; + everything_is_null = false; + } + }; + + printAttribute("interface", item.getInterface()); + printAttribute("member", item.getMember()); + printAttribute("path", item.getPath()); + + const auto nameAttr = getNameAttr(item); + if (!item.isNamePrefix()) + printAttribute(nameAttr, item.getName()); + else + printAttribute(nameAttr + "_prefix", item.getName()); - if (!item.getInterface().empty()) { - everything_is_null = false; - std::cout << " " << strings.first << "=\"" << item.getInterface() << "\""; - } - if (!item.getMember().empty()) { - everything_is_null = false; - std::cout << " " << strings.first << "=\"" << item.getMember() << "\""; - } - if (!item.getPath().empty()) { - everything_is_null = false; - std::cout << " " << strings.first << "=\"" << item.getPath() << "\""; - } - if (!item.getName().empty()) { - everything_is_null = false; - std::cout << " " << strings.first << "=\"" << item.getName() << "\""; - } - if (!item.getName().empty() && item.isNamePrefix()) { - everything_is_null = false; - std::cout << " " << strings.second << "=\"" << item.getName() << "\""; - } const auto type_it = std::find_if(types.begin(), types.end(), [&item] (const decltype(types)::value_type & type) { return type.second == item.getType(); } ); - if (type_it != types.end()) { - everything_is_null = false; - std::cout << " type=\"" << type_it->first << "\""; - } + if (type_it != types.end()) + printAttribute("type", type_it->first); + if (everything_is_null) std::cout << '*'; @@ -273,7 +278,7 @@ template void handlePolicy(const std::string & interface, const std int showHelp() { std::cout << "\nUsage:\n" - "dbuspolicy-filter {send|receive|access|own} [options]\n" + "dbuspolicy-finder {send|receive|access|own} [options]\n" "\n" " -c, --configuration {file name} | --session | --system\n" " -e, --explain \tread an error message from standard input and find relevant policy rules\n" -- 2.7.4 From 3c305debe0f6078ef6b9bc5d131f0d0ccd975bed Mon Sep 17 00:00:00 2001 From: Adrian Szyndela Date: Wed, 14 Oct 2020 08:07:10 +0200 Subject: [PATCH 08/16] own_tree: make ordered map, we need it sorted anyway Change-Id: Iaac12479580b1502bc459387b64b7dda12ce9bef --- src/internal/own_tree.cpp | 4 ++-- src/internal/own_tree.hpp | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/internal/own_tree.cpp b/src/internal/own_tree.cpp index 5cc7ead..5eecc06 100644 --- a/src/internal/own_tree.cpp +++ b/src/internal/own_tree.cpp @@ -17,7 +17,7 @@ #include #include #include -#include +#include /** * \file @@ -106,6 +106,6 @@ const DecisionItem &TreeNode::getOwnDecisionItem() const { return __own_decision_item; } -const std::unordered_map> &TreeNode::getChildren() const { +const std::map> &TreeNode::getChildren() const { return __children; } diff --git a/src/internal/own_tree.hpp b/src/internal/own_tree.hpp index 54038d1..b65be39 100644 --- a/src/internal/own_tree.hpp +++ b/src/internal/own_tree.hpp @@ -25,7 +25,7 @@ #include "policy.hpp" #include -#include +#include #include namespace ldp_xml_parser @@ -39,14 +39,14 @@ namespace ldp_xml_parser const std::string &getToken() const; const DecisionItem &getOwnPrefixDecisionItem() const; const DecisionItem &getOwnDecisionItem() const; - const std::unordered_map> &getChildren() const; + const std::map> &getChildren() const; private: DecisionItem prefixBasedDecision() const; std::string __token; // element of dot-separated name DecisionItem __own_prefix_decision_item; DecisionItem __own_decision_item; - std::unordered_map> __children; + std::map> __children; friend class OwnershipTree; }; -- 2.7.4 From e93b24d06c07075453ab611294e74c29fe04e068 Mon Sep 17 00:00:00 2001 From: Adrian Szyndela Date: Tue, 29 Sep 2020 16:56:59 +0200 Subject: [PATCH 09/16] refactoring: hide FB::File from interfaces Hide FB::File from interface of StorageBackendSerialized. This generalizes the StorageBackendSerialized interface. And that allows other implementations. Change-Id: I84631685e6ead50b33e7254c73dfb9af18bb9c4d --- src/internal/storage_backend_serialized.cpp | 31 ++++++++++++---------- src/internal/storage_backend_serialized.hpp | 3 +-- src/libdbuspolicy1.cpp | 1 + src/stest_load_perf.cpp | 6 ++--- src/stest_performance.cpp | 6 ++--- src/test-libdbuspolicy1-access-deny-gdi.cpp | 6 ++--- src/test-libdbuspolicy1-method-gdi.cpp | 5 ++-- src/test-libdbuspolicy1-method.cpp | 1 + src/test-libdbuspolicy1-ownership-deny-gdi.cpp | 3 +-- src/test-libdbuspolicy1-ownership-gdi.cpp | 3 +-- ...buspolicy1-send_destination_prefix-deny-gdi.cpp | 4 +-- src/test-libdbuspolicy1-signal-gdi.cpp | 4 +-- 12 files changed, 32 insertions(+), 41 deletions(-) diff --git a/src/internal/storage_backend_serialized.cpp b/src/internal/storage_backend_serialized.cpp index fa8fe4e..4df4e36 100644 --- a/src/internal/storage_backend_serialized.cpp +++ b/src/internal/storage_backend_serialized.cpp @@ -136,7 +136,7 @@ class StorageBackendSerialized::StorageBackendSerializedImpl { public: bool init(const char *filename, bool verify); - bool init(const FB::File *f); + bool initFromData(const uint8_t *mem, bool verify); bool initFromXML(const char *config_name); void release(); @@ -280,6 +280,19 @@ bool StorageBackendSerialized::StorageBackendSerializedImpl::init(const char *fi return err("mmap"); auto mmapGuard = transaction_guard::makeGuard([&] () { releaseMMap(); }); + + if (!initFromData(mem, verify)) + return false; + + openGuard.dismiss(); + mmapGuard.dismiss(); + + return true; +} + +bool StorageBackendSerialized::StorageBackendSerializedImpl::initFromData(const uint8_t *mem, bool verify) { + assert(nullptr == file); + if (verify) { auto verifier = flatbuffers::Verifier(mem, length); if (!FB::VerifyFileBuffer(verifier) || !FB::FileBufferHasIdentifier(mem)) { @@ -297,20 +310,10 @@ bool StorageBackendSerialized::StorageBackendSerializedImpl::init(const char *fi } } - openGuard.dismiss(); - mmapGuard.dismiss(); - file = GetFile(mem); return file != nullptr; } -bool StorageBackendSerialized::StorageBackendSerializedImpl::init(const FB::File *f) { - assert(nullptr == file); - - file = f; - return true; -} - bool StorageBackendSerialized::StorageBackendSerializedImpl::initFromXML(const char *config_name) { assert(nullptr == file); assert(nullptr == serializer.get()); @@ -322,7 +325,7 @@ bool StorageBackendSerialized::StorageBackendSerializedImpl::initFromXML(const c if (nullptr == data) return false; - return init(FB::GetFile(data)); + return initFromData(data, false); } void StorageBackendSerialized::StorageBackendSerializedImpl::printContent(const bool xml_format) const { @@ -354,8 +357,8 @@ bool StorageBackendSerialized::init(const char *filename, bool verify) { return pimpl->init(filename, verify); } -bool StorageBackendSerialized::init(const FB::File *f) { - return pimpl->init(f); +bool StorageBackendSerialized::initFromData(const uint8_t *serialized_data, bool verify) { + return pimpl->initFromData(serialized_data, verify); } bool StorageBackendSerialized::initFromXML(const char *config_name) { diff --git a/src/internal/storage_backend_serialized.hpp b/src/internal/storage_backend_serialized.hpp index ef40013..cb83b8d 100644 --- a/src/internal/storage_backend_serialized.hpp +++ b/src/internal/storage_backend_serialized.hpp @@ -16,7 +16,6 @@ #pragma once #include "policy.hpp" -#include "fb_generated.h" #include @@ -30,7 +29,7 @@ public: ~StorageBackendSerialized(); bool init(const char *filename, bool verify = false); - bool init(const FB::File *file); + bool initFromData(const uint8_t *serialized_data, bool verify = false); bool initFromXML(const char *config_name); void release(); diff --git a/src/libdbuspolicy1.cpp b/src/libdbuspolicy1.cpp index 027f385..e1975f8 100644 --- a/src/libdbuspolicy1.cpp +++ b/src/libdbuspolicy1.cpp @@ -28,6 +28,7 @@ #include #include #include +#include #include #include #include diff --git a/src/stest_load_perf.cpp b/src/stest_load_perf.cpp index bf45b51..45f5cad 100644 --- a/src/stest_load_perf.cpp +++ b/src/stest_load_perf.cpp @@ -42,7 +42,7 @@ bool run_xml(const char *conf_file) { bool run_xml_plus_fb(const char *conf_file, bool verify) { Serializer serializer; size_t size; - uint8_t *buff = serializer.serialize(conf_file, size); + const uint8_t *buff = serializer.serialize(conf_file, size); if (verify) { auto verifier = flatbuffers::Verifier(buff, size); @@ -52,10 +52,8 @@ bool run_xml_plus_fb(const char *conf_file, bool verify) { } } - const FB::File *file = FB::GetFile(buff); - StorageBackendSerialized storage; - return storage.init(file); + return storage.initFromData(buff); } bool run_fb(const char *conf_file, bool verify) { diff --git a/src/stest_performance.cpp b/src/stest_performance.cpp index bbb60a7..09003e5 100644 --- a/src/stest_performance.cpp +++ b/src/stest_performance.cpp @@ -188,7 +188,7 @@ void run_x_times(std::function func, size_t times) { void run_fb(const char *conf_file, bool verify, size_t count, bool worst) { Serializer serializer; size_t size; - uint8_t *buff = serializer.serialize(conf_file, size); + const uint8_t *buff = serializer.serialize(conf_file, size); if (verify) { auto verifier = flatbuffers::Verifier(buff, size); @@ -198,10 +198,8 @@ void run_fb(const char *conf_file, bool verify, size_t count, bool worst) { } } - const FB::File *file = FB::GetFile(buff); - StorageBackendSerialized storage; - storage.init(file); + storage.initFromData(buff); printf("FLATBUFFERS:\n"); if (!worst) diff --git a/src/test-libdbuspolicy1-access-deny-gdi.cpp b/src/test-libdbuspolicy1-access-deny-gdi.cpp index dbad42a..db4de34 100644 --- a/src/test-libdbuspolicy1-access-deny-gdi.cpp +++ b/src/test-libdbuspolicy1-access-deny-gdi.cpp @@ -153,13 +153,11 @@ bool run_fb(const std::pair access_test) { printf("FLATBUFFERS:\n"); - const FB::File *file_sys = FB::GetFile(buff_sys); - storage_sys.init(file_sys); + storage_sys.initFromData(buff_sys); 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); + storage_ses.initFromData(buff_ses); res &= run_tests_for_bus(storage_ses, policy_checker_session(), session_bus_setup.second, i, passed); } return res; diff --git a/src/test-libdbuspolicy1-method-gdi.cpp b/src/test-libdbuspolicy1-method-gdi.cpp index 3880c40..7350a18 100644 --- a/src/test-libdbuspolicy1-method-gdi.cpp +++ b/src/test-libdbuspolicy1-method-gdi.cpp @@ -126,11 +126,10 @@ bool run_fb() { Serializer serializer; size_t size; - uint8_t *buff = serializer.serialize("tests/default_allow/system.conf", size); - const FB::File *file = FB::GetFile(buff); + const uint8_t *buff = serializer.serialize("tests/default_allow/system.conf", size); StorageBackendSerialized storage; - storage.init(file); + storage.initFromData(buff); printf("FLATBUFFERS:\n"); bool ret = method_test(storage); return ret; diff --git a/src/test-libdbuspolicy1-method.cpp b/src/test-libdbuspolicy1-method.cpp index 2655542..acab322 100644 --- a/src/test-libdbuspolicy1-method.cpp +++ b/src/test-libdbuspolicy1-method.cpp @@ -1,4 +1,5 @@ +#include #include #include #include diff --git a/src/test-libdbuspolicy1-ownership-deny-gdi.cpp b/src/test-libdbuspolicy1-ownership-deny-gdi.cpp index 3d86a31..0427f20 100644 --- a/src/test-libdbuspolicy1-ownership-deny-gdi.cpp +++ b/src/test-libdbuspolicy1-ownership-deny-gdi.cpp @@ -183,9 +183,8 @@ bool run_fb() { size_t size; uint8_t *buff = serializer.serialize("tests/default_deny/system.conf", size); - const FB::File *file = FB::GetFile(buff); StorageBackendSerialized storage; - storage.init(file); + storage.initFromData(buff); printf("FRAMEBUFFERS:\n"); return ownership_test(storage); diff --git a/src/test-libdbuspolicy1-ownership-gdi.cpp b/src/test-libdbuspolicy1-ownership-gdi.cpp index 779ec6c..c7138bb 100644 --- a/src/test-libdbuspolicy1-ownership-gdi.cpp +++ b/src/test-libdbuspolicy1-ownership-gdi.cpp @@ -105,10 +105,9 @@ bool run_fb() { Serializer serializer; size_t size; uint8_t *buff = serializer.serialize("tests/default_allow/system.conf", size); - const FB::File *file = FB::GetFile(buff); StorageBackendSerialized storage; - storage.init(file); + storage.initFromData(buff); printf("FLATBUFFERS:\n"); return ownership_test(storage); } diff --git a/src/test-libdbuspolicy1-send_destination_prefix-deny-gdi.cpp b/src/test-libdbuspolicy1-send_destination_prefix-deny-gdi.cpp index 3c9049b..fc0ac57 100644 --- a/src/test-libdbuspolicy1-send_destination_prefix-deny-gdi.cpp +++ b/src/test-libdbuspolicy1-send_destination_prefix-deny-gdi.cpp @@ -190,10 +190,8 @@ bool run_fb() { size_t size; uint8_t *buff = serializer.serialize("tests/default_deny/system.conf", size); - const FB::File *file = FB::GetFile(buff); - StorageBackendSerialized storage; - storage.init(file); + storage.initFromData(buff); printf("FLATBUFFERS:\n"); return send_prefix_test(storage); diff --git a/src/test-libdbuspolicy1-signal-gdi.cpp b/src/test-libdbuspolicy1-signal-gdi.cpp index d538f6c..0bcdfcb 100644 --- a/src/test-libdbuspolicy1-signal-gdi.cpp +++ b/src/test-libdbuspolicy1-signal-gdi.cpp @@ -85,10 +85,8 @@ bool run_fb() { size_t size; uint8_t *buff = serializer.serialize("tests/default_allow/system.conf", size); - const FB::File *file = FB::GetFile(buff); - StorageBackendSerialized storage; - storage.init(file); + storage.initFromData(buff); printf("FLATBUFFERS:\n"); return signal_test(storage); -- 2.7.4 From ff87bf47fd6d81fd462799b67bc43d8082f6c738 Mon Sep 17 00:00:00 2001 From: Adrian Szyndela Date: Wed, 14 Oct 2020 13:57:10 +0200 Subject: [PATCH 10/16] refactoring: move Serializer to ldp_serializer namespace Change-Id: I75fb678335aee17bcf6c13792f5124da4d0ad422 --- src/dbuspolicy_serializer.cpp | 4 ++-- src/internal/serializer.cpp | 4 +++- src/internal/serializer.hpp | 8 ++++---- src/internal/storage_backend_serialized.cpp | 4 ++-- src/stest_load_perf.cpp | 2 +- src/stest_performance.cpp | 3 ++- src/test-libdbuspolicy1-access-deny-gdi.cpp | 5 ++--- src/test-libdbuspolicy1-method-gdi.cpp | 5 ++--- src/test-libdbuspolicy1-ownership-deny-gdi.cpp | 5 ++--- src/test-libdbuspolicy1-ownership-gdi.cpp | 5 ++--- src/test-libdbuspolicy1-send_destination_prefix-deny-gdi.cpp | 5 ++--- src/test-libdbuspolicy1-signal-gdi.cpp | 5 ++--- src/test-serializer.cpp | 2 +- 13 files changed, 27 insertions(+), 30 deletions(-) diff --git a/src/dbuspolicy_serializer.cpp b/src/dbuspolicy_serializer.cpp index 0b9d788..c6f2bf4 100644 --- a/src/dbuspolicy_serializer.cpp +++ b/src/dbuspolicy_serializer.cpp @@ -34,7 +34,7 @@ static int check(const char *input_filename, const std::string &output_filename) bool ok = false; cout << "Read from: " << input_filename << ", checking " << output_filename << "..." << endl; - ldp_xml_parser::Serializer serializer; + ldp_serializer::Serializer serializer; ostringstream output; serializer.serialize(input_filename, output); @@ -96,7 +96,7 @@ int main(int argc, char *argv[]) return check(input_filename, output_filename); cout << "Read from: " << input_filename << " write to: " << output_filename << endl; - ldp_xml_parser::Serializer serializer; + ldp_serializer::Serializer serializer; ofstream output(output_filename, ofstream::binary); uint8_t *data = serializer.serialize(input_filename, output); diff --git a/src/internal/serializer.cpp b/src/internal/serializer.cpp index f5cee57..4bd1d35 100644 --- a/src/internal/serializer.cpp +++ b/src/internal/serializer.cpp @@ -20,7 +20,9 @@ #include #include -namespace ldp_xml_parser { +using namespace ldp_xml_parser; + +namespace ldp_serializer { std::map decisions_map { { Decision::ANY, FB::Decision_ANY }, diff --git a/src/internal/serializer.hpp b/src/internal/serializer.hpp index f7f5bfd..fc27dad 100644 --- a/src/internal/serializer.hpp +++ b/src/internal/serializer.hpp @@ -26,7 +26,7 @@ #include "storage_backend_xml.hpp" #include "policy_containers.hpp" -namespace ldp_xml_parser +namespace ldp_serializer { enum class SetType : uint8_t { OWN, @@ -55,9 +55,9 @@ namespace ldp_xml_parser template auto get_create_item() -> decltype(type_helper::create_item); - FbOff serialize_tree(const OwnershipTree &tree); - FbOff serialize_tree(const std::shared_ptr &node); - FbOff serialize_decision(const DecisionItem &item); + FbOff serialize_tree(const ldp_xml_parser::OwnershipTree &tree); + FbOff serialize_tree(const std::shared_ptr &node); + FbOff serialize_decision(const ldp_xml_parser::DecisionItem &item); template auto serialize_item(const P &item) -> FbOff::item>; diff --git a/src/internal/storage_backend_serialized.cpp b/src/internal/storage_backend_serialized.cpp index 4df4e36..450949f 100644 --- a/src/internal/storage_backend_serialized.cpp +++ b/src/internal/storage_backend_serialized.cpp @@ -129,7 +129,7 @@ class StorageBackendSerialized::StorageBackendSerializedImpl { size_t length{0}; const FB::File *file{nullptr}; - std::unique_ptr serializer; + std::unique_ptr serializer; void releaseMMap(); void releaseFD(); @@ -318,7 +318,7 @@ bool StorageBackendSerialized::StorageBackendSerializedImpl::initFromXML(const c assert(nullptr == file); assert(nullptr == serializer.get()); - serializer.reset(new ldp_xml_parser::Serializer()); + serializer.reset(new ldp_serializer::Serializer()); size_t serialized_size; uint8_t *data = serializer->serialize(config_name, serialized_size); diff --git a/src/stest_load_perf.cpp b/src/stest_load_perf.cpp index 45f5cad..61b5399 100644 --- a/src/stest_load_perf.cpp +++ b/src/stest_load_perf.cpp @@ -13,8 +13,8 @@ #include #include -using namespace ldp_xml_parser; using namespace ldp_serialized; +using namespace ldp_serializer; enum class Choice { NONE, diff --git a/src/stest_performance.cpp b/src/stest_performance.cpp index 09003e5..594f9f0 100644 --- a/src/stest_performance.cpp +++ b/src/stest_performance.cpp @@ -13,8 +13,9 @@ #include #include -using namespace ldp_xml_parser; using namespace ldp_serialized; +using namespace ldp_serializer; +using namespace ldp_xml_parser; std::map DECISIONS { { Decision::ANY, "ANY" }, diff --git a/src/test-libdbuspolicy1-access-deny-gdi.cpp b/src/test-libdbuspolicy1-access-deny-gdi.cpp index db4de34..ad11668 100644 --- a/src/test-libdbuspolicy1-access-deny-gdi.cpp +++ b/src/test-libdbuspolicy1-access-deny-gdi.cpp @@ -11,7 +11,6 @@ #include using namespace ldp_xml_parser; -using namespace ldp_serialized; struct AccessTest { Decision expected_result; @@ -137,7 +136,7 @@ bool run_policy_db(const std::pair access_test) { bool run_fb(const std::pair access_test) { bool passed = true; int i = 0; - Serializer serializer; + ldp_serializer::Serializer serializer; const auto& system_bus_setup = access_test.first; const auto& session_bus_setup = access_test.second; @@ -149,7 +148,7 @@ bool run_fb(const std::pair access_test) { if (session_bus_setup.first == "") buff_ses = serializer.serialize(session_bus_setup.first.c_str(), size); - StorageBackendSerialized storage_sys, storage_ses; + ldp_serialized::StorageBackendSerialized storage_sys, storage_ses; printf("FLATBUFFERS:\n"); diff --git a/src/test-libdbuspolicy1-method-gdi.cpp b/src/test-libdbuspolicy1-method-gdi.cpp index 7350a18..9bbe0b7 100644 --- a/src/test-libdbuspolicy1-method-gdi.cpp +++ b/src/test-libdbuspolicy1-method-gdi.cpp @@ -8,7 +8,6 @@ #include using namespace ldp_xml_parser; -using namespace ldp_serialized; std::map DECISIONS { {Decision::ANY, "ANY" }, @@ -123,12 +122,12 @@ bool run_policy_db() { } bool run_fb() { - Serializer serializer; + ldp_serializer::Serializer serializer; size_t size; const uint8_t *buff = serializer.serialize("tests/default_allow/system.conf", size); - StorageBackendSerialized storage; + ldp_serialized::StorageBackendSerialized storage; storage.initFromData(buff); printf("FLATBUFFERS:\n"); bool ret = method_test(storage); diff --git a/src/test-libdbuspolicy1-ownership-deny-gdi.cpp b/src/test-libdbuspolicy1-ownership-deny-gdi.cpp index 0427f20..a950220 100644 --- a/src/test-libdbuspolicy1-ownership-deny-gdi.cpp +++ b/src/test-libdbuspolicy1-ownership-deny-gdi.cpp @@ -8,7 +8,6 @@ #include using namespace ldp_xml_parser; -using namespace ldp_serialized; struct OwnershipTest { Decision expected_result; @@ -179,11 +178,11 @@ bool run_policy_db() { } bool run_fb() { - Serializer serializer; + ldp_serializer::Serializer serializer; size_t size; uint8_t *buff = serializer.serialize("tests/default_deny/system.conf", size); - StorageBackendSerialized storage; + ldp_serialized::StorageBackendSerialized storage; storage.initFromData(buff); printf("FRAMEBUFFERS:\n"); diff --git a/src/test-libdbuspolicy1-ownership-gdi.cpp b/src/test-libdbuspolicy1-ownership-gdi.cpp index c7138bb..a2e190c 100644 --- a/src/test-libdbuspolicy1-ownership-gdi.cpp +++ b/src/test-libdbuspolicy1-ownership-gdi.cpp @@ -7,7 +7,6 @@ #include using namespace ldp_xml_parser; -using namespace ldp_serialized; struct OwnershipTest { Decision expected_result; @@ -102,11 +101,11 @@ bool run_policy_db() { } bool run_fb() { - Serializer serializer; + ldp_serializer::Serializer serializer; size_t size; uint8_t *buff = serializer.serialize("tests/default_allow/system.conf", size); - StorageBackendSerialized storage; + ldp_serialized::StorageBackendSerialized storage; storage.initFromData(buff); printf("FLATBUFFERS:\n"); return ownership_test(storage); diff --git a/src/test-libdbuspolicy1-send_destination_prefix-deny-gdi.cpp b/src/test-libdbuspolicy1-send_destination_prefix-deny-gdi.cpp index fc0ac57..dadd224 100644 --- a/src/test-libdbuspolicy1-send_destination_prefix-deny-gdi.cpp +++ b/src/test-libdbuspolicy1-send_destination_prefix-deny-gdi.cpp @@ -8,7 +8,6 @@ #include using namespace ldp_xml_parser; -using namespace ldp_serialized; std::map DECISIONS { { Decision::ANY, "ANY" }, @@ -186,11 +185,11 @@ bool run_policy_db() { } bool run_fb() { - Serializer serializer; + ldp_serializer::Serializer serializer; size_t size; uint8_t *buff = serializer.serialize("tests/default_deny/system.conf", size); - StorageBackendSerialized storage; + ldp_serialized::StorageBackendSerialized storage; storage.initFromData(buff); printf("FLATBUFFERS:\n"); diff --git a/src/test-libdbuspolicy1-signal-gdi.cpp b/src/test-libdbuspolicy1-signal-gdi.cpp index 0bcdfcb..d7127cb 100644 --- a/src/test-libdbuspolicy1-signal-gdi.cpp +++ b/src/test-libdbuspolicy1-signal-gdi.cpp @@ -8,7 +8,6 @@ #include using namespace ldp_xml_parser; -using namespace ldp_serialized; struct SignalTest { Decision expected_result; @@ -81,11 +80,11 @@ bool run_policy_db() { } bool run_fb() { - Serializer serializer; + ldp_serializer::Serializer serializer; size_t size; uint8_t *buff = serializer.serialize("tests/default_allow/system.conf", size); - StorageBackendSerialized storage; + ldp_serialized::StorageBackendSerialized storage; storage.initFromData(buff); printf("FLATBUFFERS:\n"); diff --git a/src/test-serializer.cpp b/src/test-serializer.cpp index 9f8c89e..876ef52 100644 --- a/src/test-serializer.cpp +++ b/src/test-serializer.cpp @@ -317,7 +317,7 @@ std::vector item_access_context_mandatory_test { }; class SerializerTests { - Serializer serializer; + ldp_serializer::Serializer serializer; const FB::File *file; void serialize_xml(const std::string &file_name) { -- 2.7.4 From 8d4d7f2ca856f69f580016824956a022f1541bfb Mon Sep 17 00:00:00 2001 From: Adrian Szyndela Date: Wed, 14 Oct 2020 14:23:00 +0200 Subject: [PATCH 11/16] refactoring: make serialized data const Change-Id: I1e989504323c18754c9117d903ba8f4b951d8377 --- src/dbuspolicy_serializer.cpp | 2 +- src/internal/serializer.cpp | 12 ++++++------ src/internal/serializer.hpp | 6 +++--- src/internal/storage_backend_serialized.cpp | 2 +- src/stest_load_perf.cpp | 2 +- src/stest_performance.cpp | 2 +- src/test-libdbuspolicy1-access-deny-gdi.cpp | 4 ++-- src/test-libdbuspolicy1-method-gdi.cpp | 2 +- src/test-libdbuspolicy1-ownership-deny-gdi.cpp | 2 +- src/test-libdbuspolicy1-ownership-gdi.cpp | 2 +- src/test-libdbuspolicy1-send_destination_prefix-deny-gdi.cpp | 2 +- src/test-libdbuspolicy1-signal-gdi.cpp | 2 +- src/test-serializer.cpp | 3 +-- 13 files changed, 21 insertions(+), 22 deletions(-) diff --git a/src/dbuspolicy_serializer.cpp b/src/dbuspolicy_serializer.cpp index c6f2bf4..b174461 100644 --- a/src/dbuspolicy_serializer.cpp +++ b/src/dbuspolicy_serializer.cpp @@ -99,7 +99,7 @@ int main(int argc, char *argv[]) ldp_serializer::Serializer serializer; ofstream output(output_filename, ofstream::binary); - uint8_t *data = serializer.serialize(input_filename, output); + auto data = serializer.serialize(input_filename, output); if (output.fail()) { cout << "Write FAILED." << endl; diff --git a/src/internal/serializer.cpp b/src/internal/serializer.cpp index 4bd1d35..5595751 100644 --- a/src/internal/serializer.cpp +++ b/src/internal/serializer.cpp @@ -94,7 +94,7 @@ struct Serializer::type_helper { static constexpr auto create_item = &FB::CreateItemAccess; }; -uint8_t* Serializer::serialize(const ldp_xml::StorageBackendXML &db, size_t &size) { +const uint8_t* Serializer::serialize(const ldp_xml::StorageBackendXML &db, size_t &size) { m_db = &db; auto own_set = serialize_set(); @@ -109,13 +109,13 @@ uint8_t* Serializer::serialize(const ldp_xml::StorageBackendXML &db, size_t &siz access_set); m_builder.Finish(file, FB::FileIdentifier()); - uint8_t* buf = m_builder.GetBufferPointer(); + auto buf = m_builder.GetBufferPointer(); size = m_builder.GetSize(); return buf; } -uint8_t* Serializer::serialize(const std::string config_path, size_t &size) { +const uint8_t* Serializer::serialize(const std::string config_path, size_t &size) { tslog::init(tslog::ldp_log_level::DEFAULT); ldp_xml::StorageBackendXML xmlStorage; @@ -127,11 +127,11 @@ uint8_t* Serializer::serialize(const std::string config_path, size_t &size) { return serialize(xmlStorage, size); } -uint8_t *Serializer::serialize(const std::string config_path, std::ostream &output) { +const uint8_t *Serializer::serialize(const std::string config_path, std::ostream &output) { size_t size = 0; - uint8_t *buf = serialize(config_path, size); + auto buf = serialize(config_path, size); - output.write(reinterpret_cast(buf), size); + output.write(reinterpret_cast(buf), size); return buf; } diff --git a/src/internal/serializer.hpp b/src/internal/serializer.hpp index fc27dad..466ceb6 100644 --- a/src/internal/serializer.hpp +++ b/src/internal/serializer.hpp @@ -82,9 +82,9 @@ namespace ldp_serializer -> FbOff::set>; public: Serializer() : m_db(nullptr) {} - uint8_t *serialize(const ldp_xml::StorageBackendXML &db, size_t &size); - uint8_t *serialize(const std::string config_path, size_t &size); - uint8_t *serialize(const std::string config_path, std::ostream &output); + const uint8_t *serialize(const ldp_xml::StorageBackendXML &db, size_t &size); + const uint8_t *serialize(const std::string config_path, size_t &size); + const uint8_t *serialize(const std::string config_path, std::ostream &output); friend class SerializerTests; }; } diff --git a/src/internal/storage_backend_serialized.cpp b/src/internal/storage_backend_serialized.cpp index 450949f..725d488 100644 --- a/src/internal/storage_backend_serialized.cpp +++ b/src/internal/storage_backend_serialized.cpp @@ -321,7 +321,7 @@ bool StorageBackendSerialized::StorageBackendSerializedImpl::initFromXML(const c serializer.reset(new ldp_serializer::Serializer()); size_t serialized_size; - uint8_t *data = serializer->serialize(config_name, serialized_size); + auto data = serializer->serialize(config_name, serialized_size); if (nullptr == data) return false; diff --git a/src/stest_load_perf.cpp b/src/stest_load_perf.cpp index 61b5399..a2ce952 100644 --- a/src/stest_load_perf.cpp +++ b/src/stest_load_perf.cpp @@ -42,7 +42,7 @@ bool run_xml(const char *conf_file) { bool run_xml_plus_fb(const char *conf_file, bool verify) { Serializer serializer; size_t size; - const uint8_t *buff = serializer.serialize(conf_file, size); + auto buff = serializer.serialize(conf_file, size); if (verify) { auto verifier = flatbuffers::Verifier(buff, size); diff --git a/src/stest_performance.cpp b/src/stest_performance.cpp index 594f9f0..15b81c6 100644 --- a/src/stest_performance.cpp +++ b/src/stest_performance.cpp @@ -189,7 +189,7 @@ void run_x_times(std::function func, size_t times) { void run_fb(const char *conf_file, bool verify, size_t count, bool worst) { Serializer serializer; size_t size; - const uint8_t *buff = serializer.serialize(conf_file, size); + auto buff = serializer.serialize(conf_file, size); if (verify) { auto verifier = flatbuffers::Verifier(buff, size); diff --git a/src/test-libdbuspolicy1-access-deny-gdi.cpp b/src/test-libdbuspolicy1-access-deny-gdi.cpp index ad11668..9e97270 100644 --- a/src/test-libdbuspolicy1-access-deny-gdi.cpp +++ b/src/test-libdbuspolicy1-access-deny-gdi.cpp @@ -143,8 +143,8 @@ bool run_fb(const std::pair access_test) { size_t size; - uint8_t *buff_sys = nullptr, *buff_ses = nullptr; - buff_sys = serializer.serialize(system_bus_setup.first.c_str(), size); + auto buff_sys = serializer.serialize(system_bus_setup.first.c_str(), size); + decltype(buff_sys) buff_ses = nullptr; if (session_bus_setup.first == "") buff_ses = serializer.serialize(session_bus_setup.first.c_str(), size); diff --git a/src/test-libdbuspolicy1-method-gdi.cpp b/src/test-libdbuspolicy1-method-gdi.cpp index 9bbe0b7..b52e9fd 100644 --- a/src/test-libdbuspolicy1-method-gdi.cpp +++ b/src/test-libdbuspolicy1-method-gdi.cpp @@ -125,7 +125,7 @@ bool run_fb() { ldp_serializer::Serializer serializer; size_t size; - const uint8_t *buff = serializer.serialize("tests/default_allow/system.conf", size); + auto buff = serializer.serialize("tests/default_allow/system.conf", size); ldp_serialized::StorageBackendSerialized storage; storage.initFromData(buff); diff --git a/src/test-libdbuspolicy1-ownership-deny-gdi.cpp b/src/test-libdbuspolicy1-ownership-deny-gdi.cpp index a950220..3f6817e 100644 --- a/src/test-libdbuspolicy1-ownership-deny-gdi.cpp +++ b/src/test-libdbuspolicy1-ownership-deny-gdi.cpp @@ -180,7 +180,7 @@ bool run_policy_db() { bool run_fb() { ldp_serializer::Serializer serializer; size_t size; - uint8_t *buff = serializer.serialize("tests/default_deny/system.conf", size); + auto buff = serializer.serialize("tests/default_deny/system.conf", size); ldp_serialized::StorageBackendSerialized storage; storage.initFromData(buff); diff --git a/src/test-libdbuspolicy1-ownership-gdi.cpp b/src/test-libdbuspolicy1-ownership-gdi.cpp index a2e190c..5c1ba60 100644 --- a/src/test-libdbuspolicy1-ownership-gdi.cpp +++ b/src/test-libdbuspolicy1-ownership-gdi.cpp @@ -103,7 +103,7 @@ bool run_policy_db() { bool run_fb() { ldp_serializer::Serializer serializer; size_t size; - uint8_t *buff = serializer.serialize("tests/default_allow/system.conf", size); + auto buff = serializer.serialize("tests/default_allow/system.conf", size); ldp_serialized::StorageBackendSerialized storage; storage.initFromData(buff); diff --git a/src/test-libdbuspolicy1-send_destination_prefix-deny-gdi.cpp b/src/test-libdbuspolicy1-send_destination_prefix-deny-gdi.cpp index dadd224..f4cf1aa 100644 --- a/src/test-libdbuspolicy1-send_destination_prefix-deny-gdi.cpp +++ b/src/test-libdbuspolicy1-send_destination_prefix-deny-gdi.cpp @@ -187,7 +187,7 @@ bool run_policy_db() { bool run_fb() { ldp_serializer::Serializer serializer; size_t size; - uint8_t *buff = serializer.serialize("tests/default_deny/system.conf", size); + auto buff = serializer.serialize("tests/default_deny/system.conf", size); ldp_serialized::StorageBackendSerialized storage; storage.initFromData(buff); diff --git a/src/test-libdbuspolicy1-signal-gdi.cpp b/src/test-libdbuspolicy1-signal-gdi.cpp index d7127cb..5da8633 100644 --- a/src/test-libdbuspolicy1-signal-gdi.cpp +++ b/src/test-libdbuspolicy1-signal-gdi.cpp @@ -82,7 +82,7 @@ bool run_policy_db() { bool run_fb() { ldp_serializer::Serializer serializer; size_t size; - uint8_t *buff = serializer.serialize("tests/default_allow/system.conf", size); + auto buff = serializer.serialize("tests/default_allow/system.conf", size); ldp_serialized::StorageBackendSerialized storage; storage.initFromData(buff); diff --git a/src/test-serializer.cpp b/src/test-serializer.cpp index 876ef52..1857988 100644 --- a/src/test-serializer.cpp +++ b/src/test-serializer.cpp @@ -321,9 +321,8 @@ class SerializerTests { const FB::File *file; void serialize_xml(const std::string &file_name) { - uint8_t *buff; size_t size; - buff = serializer.serialize(file_name, size); + auto buff = serializer.serialize(file_name, size); file = FB::GetFile(buff); } -- 2.7.4 From 1d771b309df55689238436b4e9643e29bc328ed3 Mon Sep 17 00:00:00 2001 From: Adrian Szyndela Date: Tue, 27 Oct 2020 09:44:25 +0100 Subject: [PATCH 12/16] refactoring: add size argument to initFromData() Change-Id: I0fea35816cbbb7dc898e495adab73d9c28729bc3 --- src/internal/storage_backend_serialized.cpp | 14 +++++++------- src/internal/storage_backend_serialized.hpp | 2 +- src/stest_load_perf.cpp | 2 +- src/stest_performance.cpp | 2 +- src/test-libdbuspolicy1-access-deny-gdi.cpp | 10 +++++----- src/test-libdbuspolicy1-method-gdi.cpp | 2 +- src/test-libdbuspolicy1-ownership-deny-gdi.cpp | 2 +- src/test-libdbuspolicy1-ownership-gdi.cpp | 2 +- ...est-libdbuspolicy1-send_destination_prefix-deny-gdi.cpp | 2 +- src/test-libdbuspolicy1-signal-gdi.cpp | 2 +- 10 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/internal/storage_backend_serialized.cpp b/src/internal/storage_backend_serialized.cpp index 725d488..a099a1e 100644 --- a/src/internal/storage_backend_serialized.cpp +++ b/src/internal/storage_backend_serialized.cpp @@ -136,7 +136,7 @@ class StorageBackendSerialized::StorageBackendSerializedImpl { public: bool init(const char *filename, bool verify); - bool initFromData(const uint8_t *mem, bool verify); + bool initFromData(const uint8_t *mem, size_t size, bool verify); bool initFromXML(const char *config_name); void release(); @@ -281,7 +281,7 @@ bool StorageBackendSerialized::StorageBackendSerializedImpl::init(const char *fi auto mmapGuard = transaction_guard::makeGuard([&] () { releaseMMap(); }); - if (!initFromData(mem, verify)) + if (!initFromData(mem, length, verify)) return false; openGuard.dismiss(); @@ -290,11 +290,11 @@ bool StorageBackendSerialized::StorageBackendSerializedImpl::init(const char *fi return true; } -bool StorageBackendSerialized::StorageBackendSerializedImpl::initFromData(const uint8_t *mem, bool verify) { +bool StorageBackendSerialized::StorageBackendSerializedImpl::initFromData(const uint8_t *mem, size_t size, bool verify) { assert(nullptr == file); if (verify) { - auto verifier = flatbuffers::Verifier(mem, length); + auto verifier = flatbuffers::Verifier(mem, size); if (!FB::VerifyFileBuffer(verifier) || !FB::FileBufferHasIdentifier(mem)) { char fid[FB::FB_ID_SIZE + 1] = {0, }; strncpy(fid, (const char *)(mem + FB::FB_ID_OFFSET), FB::FB_ID_SIZE); @@ -325,7 +325,7 @@ bool StorageBackendSerialized::StorageBackendSerializedImpl::initFromXML(const c if (nullptr == data) return false; - return initFromData(data, false); + return initFromData(data, serialized_size, false); } void StorageBackendSerialized::StorageBackendSerializedImpl::printContent(const bool xml_format) const { @@ -357,8 +357,8 @@ bool StorageBackendSerialized::init(const char *filename, bool verify) { return pimpl->init(filename, verify); } -bool StorageBackendSerialized::initFromData(const uint8_t *serialized_data, bool verify) { - return pimpl->initFromData(serialized_data, verify); +bool StorageBackendSerialized::initFromData(const uint8_t *serialized_data, size_t length, bool verify) { + return pimpl->initFromData(serialized_data, length, verify); } bool StorageBackendSerialized::initFromXML(const char *config_name) { diff --git a/src/internal/storage_backend_serialized.hpp b/src/internal/storage_backend_serialized.hpp index cb83b8d..4781b87 100644 --- a/src/internal/storage_backend_serialized.hpp +++ b/src/internal/storage_backend_serialized.hpp @@ -29,7 +29,7 @@ public: ~StorageBackendSerialized(); bool init(const char *filename, bool verify = false); - bool initFromData(const uint8_t *serialized_data, bool verify = false); + bool initFromData(const uint8_t *serialized_data, size_t length, bool verify = false); bool initFromXML(const char *config_name); void release(); diff --git a/src/stest_load_perf.cpp b/src/stest_load_perf.cpp index a2ce952..5c30803 100644 --- a/src/stest_load_perf.cpp +++ b/src/stest_load_perf.cpp @@ -53,7 +53,7 @@ bool run_xml_plus_fb(const char *conf_file, bool verify) { } StorageBackendSerialized storage; - return storage.initFromData(buff); + return storage.initFromData(buff, size); } bool run_fb(const char *conf_file, bool verify) { diff --git a/src/stest_performance.cpp b/src/stest_performance.cpp index 15b81c6..47dc8a6 100644 --- a/src/stest_performance.cpp +++ b/src/stest_performance.cpp @@ -200,7 +200,7 @@ void run_fb(const char *conf_file, bool verify, size_t count, bool worst) { } StorageBackendSerialized storage; - storage.initFromData(buff); + storage.initFromData(buff, size); printf("FLATBUFFERS:\n"); if (!worst) diff --git a/src/test-libdbuspolicy1-access-deny-gdi.cpp b/src/test-libdbuspolicy1-access-deny-gdi.cpp index 9e97270..c601408 100644 --- a/src/test-libdbuspolicy1-access-deny-gdi.cpp +++ b/src/test-libdbuspolicy1-access-deny-gdi.cpp @@ -141,22 +141,22 @@ bool run_fb(const std::pair access_test) { const auto& system_bus_setup = access_test.first; const auto& session_bus_setup = access_test.second; - size_t size; + size_t size_sys, size_ses; - auto buff_sys = serializer.serialize(system_bus_setup.first.c_str(), size); + auto buff_sys = serializer.serialize(system_bus_setup.first.c_str(), size_sys); decltype(buff_sys) buff_ses = nullptr; if (session_bus_setup.first == "") - buff_ses = serializer.serialize(session_bus_setup.first.c_str(), size); + buff_ses = serializer.serialize(session_bus_setup.first.c_str(), size_ses); ldp_serialized::StorageBackendSerialized storage_sys, storage_ses; printf("FLATBUFFERS:\n"); - storage_sys.initFromData(buff_sys); + storage_sys.initFromData(buff_sys, size_sys); bool res = run_tests_for_bus(storage_sys, policy_checker_system(), system_bus_setup.second, i, passed); if (buff_ses) { - storage_ses.initFromData(buff_ses); + storage_ses.initFromData(buff_ses, size_ses); res &= run_tests_for_bus(storage_ses, policy_checker_session(), session_bus_setup.second, i, passed); } return res; diff --git a/src/test-libdbuspolicy1-method-gdi.cpp b/src/test-libdbuspolicy1-method-gdi.cpp index b52e9fd..beaece1 100644 --- a/src/test-libdbuspolicy1-method-gdi.cpp +++ b/src/test-libdbuspolicy1-method-gdi.cpp @@ -128,7 +128,7 @@ bool run_fb() { auto buff = serializer.serialize("tests/default_allow/system.conf", size); ldp_serialized::StorageBackendSerialized storage; - storage.initFromData(buff); + storage.initFromData(buff, size); printf("FLATBUFFERS:\n"); bool ret = method_test(storage); return ret; diff --git a/src/test-libdbuspolicy1-ownership-deny-gdi.cpp b/src/test-libdbuspolicy1-ownership-deny-gdi.cpp index 3f6817e..4096d8a 100644 --- a/src/test-libdbuspolicy1-ownership-deny-gdi.cpp +++ b/src/test-libdbuspolicy1-ownership-deny-gdi.cpp @@ -183,7 +183,7 @@ bool run_fb() { auto buff = serializer.serialize("tests/default_deny/system.conf", size); ldp_serialized::StorageBackendSerialized storage; - storage.initFromData(buff); + storage.initFromData(buff, size); printf("FRAMEBUFFERS:\n"); return ownership_test(storage); diff --git a/src/test-libdbuspolicy1-ownership-gdi.cpp b/src/test-libdbuspolicy1-ownership-gdi.cpp index 5c1ba60..c844e0f 100644 --- a/src/test-libdbuspolicy1-ownership-gdi.cpp +++ b/src/test-libdbuspolicy1-ownership-gdi.cpp @@ -106,7 +106,7 @@ bool run_fb() { auto buff = serializer.serialize("tests/default_allow/system.conf", size); ldp_serialized::StorageBackendSerialized storage; - storage.initFromData(buff); + storage.initFromData(buff, size); printf("FLATBUFFERS:\n"); return ownership_test(storage); } diff --git a/src/test-libdbuspolicy1-send_destination_prefix-deny-gdi.cpp b/src/test-libdbuspolicy1-send_destination_prefix-deny-gdi.cpp index f4cf1aa..a0c276a 100644 --- a/src/test-libdbuspolicy1-send_destination_prefix-deny-gdi.cpp +++ b/src/test-libdbuspolicy1-send_destination_prefix-deny-gdi.cpp @@ -190,7 +190,7 @@ bool run_fb() { auto buff = serializer.serialize("tests/default_deny/system.conf", size); ldp_serialized::StorageBackendSerialized storage; - storage.initFromData(buff); + storage.initFromData(buff, size); printf("FLATBUFFERS:\n"); return send_prefix_test(storage); diff --git a/src/test-libdbuspolicy1-signal-gdi.cpp b/src/test-libdbuspolicy1-signal-gdi.cpp index 5da8633..44acae0 100644 --- a/src/test-libdbuspolicy1-signal-gdi.cpp +++ b/src/test-libdbuspolicy1-signal-gdi.cpp @@ -85,7 +85,7 @@ bool run_fb() { auto buff = serializer.serialize("tests/default_allow/system.conf", size); ldp_serialized::StorageBackendSerialized storage; - storage.initFromData(buff); + storage.initFromData(buff, size); printf("FLATBUFFERS:\n"); return signal_test(storage); -- 2.7.4 From 4b97accaaf959355c477bf5bd10c2627d273e807 Mon Sep 17 00:00:00 2001 From: Adrian Szyndela Date: Tue, 27 Oct 2020 10:08:39 +0100 Subject: [PATCH 13/16] refactoring: rename Serializer to SerializerFlatbuffers Change-Id: I52d6c22f44d7730dea221c4b9d81df9b7b3af291 --- Makefile.am | 2 +- src/internal/serializer.hpp | 94 +--------------------- .../{serializer.cpp => serializer_flatbuffers.cpp} | 48 +++++------ src/internal/serializer_flatbuffers.hpp | 93 +++++++++++++++++++++ 4 files changed, 122 insertions(+), 115 deletions(-) rename src/internal/{serializer.cpp => serializer_flatbuffers.cpp} (81%) create mode 100644 src/internal/serializer_flatbuffers.hpp diff --git a/Makefile.am b/Makefile.am index aad84e6..3388f17 100644 --- a/Makefile.am +++ b/Makefile.am @@ -62,7 +62,7 @@ COMMON_SRC =\ src/internal/own_tree.cpp \ src/internal/xml_parser.cpp \ src/internal/tslog.cpp \ - src/internal/serializer.cpp \ + src/internal/serializer_flatbuffers.cpp \ src/internal/print_content.cpp \ src/internal/storage_backend_serialized.cpp \ src/internal/storage_backend_xml.cpp diff --git a/src/internal/serializer.hpp b/src/internal/serializer.hpp index 466ceb6..6f9c2fa 100644 --- a/src/internal/serializer.hpp +++ b/src/internal/serializer.hpp @@ -1,93 +1,7 @@ -/* - * 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. -*/ -#ifndef _SERIALIZER_HPP -#define _SERIALIZER_HPP +#pragma once -#include -#include -#include +#include "serializer_flatbuffers.hpp" -#include "include/flatbuffers/flatbuffers.h" -#include "include/fb_generated.h" - -#include "storage_backend_xml.hpp" -#include "policy_containers.hpp" - -namespace ldp_serializer -{ - enum class SetType : uint8_t { - OWN, - SEND, - RECEIVE, - ACCESS - }; - - template - using FbOff = flatbuffers::Offset; - - class Serializer { - private: - template - struct type_helper; - - const ldp_xml::StorageBackendXML *m_db; - flatbuffers::FlatBufferBuilder m_builder; - - template - auto get_create_set() -> decltype(type_helper::create_set); - template - auto get_create_policy() -> decltype(type_helper::create_policy); - template - auto get_create_policy_pair() -> decltype(type_helper::create_policy_pair); - template - auto get_create_item() -> decltype(type_helper::create_item); - - FbOff serialize_tree(const ldp_xml_parser::OwnershipTree &tree); - FbOff serialize_tree(const std::shared_ptr &node); - FbOff serialize_decision(const ldp_xml_parser::DecisionItem &item); - - template - auto serialize_item(const P &item) -> FbOff::item>; - - template - auto serialize_policy(const T &policy) -> FbOff::policy>; - - template - auto serialize_policy(const std::vector::item>> items) - -> FbOff::policy>; - - template - auto serialize_pair(const long int id, const P policy) - -> FbOff::pair>; - - template - auto serialize_set() -> FbOff::set>; - - template - auto serialize_set(FbOff context_default, - FbOff context_mandatory) - -> FbOff::set>; - public: - Serializer() : m_db(nullptr) {} - const uint8_t *serialize(const ldp_xml::StorageBackendXML &db, size_t &size); - const uint8_t *serialize(const std::string config_path, size_t &size); - const uint8_t *serialize(const std::string config_path, std::ostream &output); - friend class SerializerTests; - }; +namespace ldp_serializer { +using Serializer = SerializerFlatbuffers; } - - -#endif diff --git a/src/internal/serializer.cpp b/src/internal/serializer_flatbuffers.cpp similarity index 81% rename from src/internal/serializer.cpp rename to src/internal/serializer_flatbuffers.cpp index 5595751..b79558a 100644 --- a/src/internal/serializer.cpp +++ b/src/internal/serializer_flatbuffers.cpp @@ -47,7 +47,7 @@ std::map message_type_map { }; template <> -struct Serializer::type_helper { +struct SerializerFlatbuffers::type_helper { typedef struct FB::OwnSet set; typedef struct FB::OwnSetBuilder builder; typedef struct FB::PolicyOwn policy; @@ -58,7 +58,7 @@ struct Serializer::type_helper { }; template <> -struct Serializer::type_helper { +struct SerializerFlatbuffers::type_helper { typedef struct FB::SendSet set; typedef struct FB::SendSetBuilder builder; typedef struct FB::PolicySend policy; @@ -71,7 +71,7 @@ struct Serializer::type_helper { }; template <> -struct Serializer::type_helper { +struct SerializerFlatbuffers::type_helper { typedef struct FB::ReceiveSet set; typedef struct FB::ReceiveSetBuilder builder; typedef struct FB::PolicyReceive policy; @@ -84,7 +84,7 @@ struct Serializer::type_helper { }; template <> -struct Serializer::type_helper { +struct SerializerFlatbuffers::type_helper { typedef struct FB::AccessSet set; typedef struct FB::AccessSetBuilder builder; typedef struct FB::PolicyAccess policy; @@ -94,7 +94,7 @@ struct Serializer::type_helper { static constexpr auto create_item = &FB::CreateItemAccess; }; -const uint8_t* Serializer::serialize(const ldp_xml::StorageBackendXML &db, size_t &size) { +const uint8_t* SerializerFlatbuffers::serialize(const ldp_xml::StorageBackendXML &db, size_t &size) { m_db = &db; auto own_set = serialize_set(); @@ -115,7 +115,7 @@ const uint8_t* Serializer::serialize(const ldp_xml::StorageBackendXML &db, size_ return buf; } -const uint8_t* Serializer::serialize(const std::string config_path, size_t &size) { +const uint8_t* SerializerFlatbuffers::serialize(const std::string config_path, size_t &size) { tslog::init(tslog::ldp_log_level::DEFAULT); ldp_xml::StorageBackendXML xmlStorage; @@ -127,7 +127,7 @@ const uint8_t* Serializer::serialize(const std::string config_path, size_t &size return serialize(xmlStorage, size); } -const uint8_t *Serializer::serialize(const std::string config_path, std::ostream &output) { +const uint8_t *SerializerFlatbuffers::serialize(const std::string config_path, std::ostream &output) { size_t size = 0; auto buf = serialize(config_path, size); @@ -136,33 +136,33 @@ const uint8_t *Serializer::serialize(const std::string config_path, std::ostream } template -auto Serializer::get_create_set() -> decltype(type_helper::create_set) { +auto SerializerFlatbuffers::get_create_set() -> decltype(type_helper::create_set) { return type_helper::create_set; } template -auto Serializer::get_create_policy() -> decltype(type_helper::create_policy) { +auto SerializerFlatbuffers::get_create_policy() -> decltype(type_helper::create_policy) { return type_helper::create_policy; } template -auto Serializer::get_create_policy_pair() -> decltype(type_helper::create_policy_pair) { +auto SerializerFlatbuffers::get_create_policy_pair() -> decltype(type_helper::create_policy_pair) { return type_helper::create_policy_pair; } template -auto Serializer::get_create_item() -> decltype(type_helper::create_item) { +auto SerializerFlatbuffers::get_create_item() -> decltype(type_helper::create_item) { return type_helper::create_item; } -FbOff Serializer::serialize_tree(const OwnershipTree &tree) { +FbOff SerializerFlatbuffers::serialize_tree(const OwnershipTree &tree) { auto tree_item = serialize_tree(tree.getRoot()); auto policy = FB::CreatePolicyOwn(m_builder, tree_item); return policy; } -FbOff Serializer::serialize_tree(const std::shared_ptr &node) { +FbOff SerializerFlatbuffers::serialize_tree(const std::shared_ptr &node) { auto prefix_decision_item = serialize_decision(node->getOwnPrefixDecisionItem()); auto decision_item = serialize_decision(node->getOwnDecisionItem()); @@ -181,14 +181,14 @@ FbOff Serializer::serialize_tree(const std::shared_ptr Serializer::serialize_decision(const DecisionItem &item) { +FbOff SerializerFlatbuffers::serialize_decision(const DecisionItem &item) { return FB::CreateDecisionItem(m_builder, decisions_map[item.getDecision()], m_builder.CreateString(item.getPrivilege())); } template <> -auto Serializer::serialize_item(const ItemAccess &item) -> FbOff { +auto SerializerFlatbuffers::serialize_item(const ItemAccess &item) -> FbOff { auto create_item = get_create_item(); return create_item(m_builder, @@ -199,7 +199,7 @@ auto Serializer::serialize_item(const ItemAccess &item) -> FbOff -auto Serializer::serialize_item(const P &item) -> FbOff::item> { +auto SerializerFlatbuffers::serialize_item(const P &item) -> FbOff::item> { auto create_item = get_create_item(); return create_item(m_builder, serialize_decision(item.getDecision()), @@ -212,20 +212,20 @@ auto Serializer::serialize_item(const P &item) -> FbOff: } template -auto Serializer::serialize_policy(const std::vector::item>> items) +auto SerializerFlatbuffers::serialize_policy(const std::vector::item>> items) -> FbOff::policy> { auto create_policy = get_create_policy(); return create_policy(m_builder, m_builder.CreateVector(items)); } template <> -auto Serializer::serialize_policy(const PolicyOwn &policy) +auto SerializerFlatbuffers::serialize_policy(const PolicyOwn &policy) -> FbOff { return serialize_tree(policy.getTree()); } template <> -auto Serializer::serialize_policy(const PolicySend &policy) +auto SerializerFlatbuffers::serialize_policy(const PolicySend &policy) -> FbOff { std::vector> items; @@ -267,7 +267,7 @@ auto Serializer::serialize_policy(const PolicySend &policy) } template -auto Serializer::serialize_policy(const T &policy) -> FbOff::policy> { +auto SerializerFlatbuffers::serialize_policy(const T &policy) -> FbOff::policy> { std::vector::item>> items; for (const auto &item : policy.getItems()) { @@ -278,14 +278,14 @@ auto Serializer::serialize_policy(const T &policy) -> FbOff -auto Serializer::serialize_pair(const long int id, const P policy) +auto SerializerFlatbuffers::serialize_pair(const long int id, const P policy) -> FbOff::pair> { auto create_policy_pair = get_create_policy_pair(); return create_policy_pair(m_builder, id, serialize_policy(policy)); } template -auto Serializer::serialize_set() -> FbOff::set> { +auto SerializerFlatbuffers::serialize_set() -> FbOff::set> { auto context_default = serialize_policy(m_db->getPolicyContextDefault()); auto context_mandatory = serialize_policy(m_db->getPolicyContextMandatory()); @@ -293,7 +293,7 @@ auto Serializer::serialize_set() -> FbOff::set> { } template <> -auto Serializer::serialize_set(FbOff context_default, +auto SerializerFlatbuffers::serialize_set(FbOff context_default, FbOff context_mandatory) -> FbOff::set> { @@ -301,7 +301,7 @@ auto Serializer::serialize_set(FbOff context_def } template -auto Serializer::serialize_set(FbOff context_default, +auto SerializerFlatbuffers::serialize_set(FbOff context_default, FbOff context_mandatory) -> FbOff::set> { diff --git a/src/internal/serializer_flatbuffers.hpp b/src/internal/serializer_flatbuffers.hpp new file mode 100644 index 0000000..3dbed7d --- /dev/null +++ b/src/internal/serializer_flatbuffers.hpp @@ -0,0 +1,93 @@ +/* + * 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. +*/ +#ifndef _SERIALIZER_HPP +#define _SERIALIZER_HPP + +#include +#include +#include + +#include "include/flatbuffers/flatbuffers.h" +#include "include/fb_generated.h" + +#include "storage_backend_xml.hpp" +#include "policy_containers.hpp" + +namespace ldp_serializer +{ + enum class SetType : uint8_t { + OWN, + SEND, + RECEIVE, + ACCESS + }; + + template + using FbOff = flatbuffers::Offset; + + class SerializerFlatbuffers { + private: + template + struct type_helper; + + const ldp_xml::StorageBackendXML *m_db; + flatbuffers::FlatBufferBuilder m_builder; + + template + auto get_create_set() -> decltype(type_helper::create_set); + template + auto get_create_policy() -> decltype(type_helper::create_policy); + template + auto get_create_policy_pair() -> decltype(type_helper::create_policy_pair); + template + auto get_create_item() -> decltype(type_helper::create_item); + + FbOff serialize_tree(const ldp_xml_parser::OwnershipTree &tree); + FbOff serialize_tree(const std::shared_ptr &node); + FbOff serialize_decision(const ldp_xml_parser::DecisionItem &item); + + template + auto serialize_item(const P &item) -> FbOff::item>; + + template + auto serialize_policy(const T &policy) -> FbOff::policy>; + + template + auto serialize_policy(const std::vector::item>> items) + -> FbOff::policy>; + + template + auto serialize_pair(const long int id, const P policy) + -> FbOff::pair>; + + template + auto serialize_set() -> FbOff::set>; + + template + auto serialize_set(FbOff context_default, + FbOff context_mandatory) + -> FbOff::set>; + public: + SerializerFlatbuffers() : m_db(nullptr) {} + const uint8_t *serialize(const ldp_xml::StorageBackendXML &db, size_t &size); + const uint8_t *serialize(const std::string config_path, size_t &size); + const uint8_t *serialize(const std::string config_path, std::ostream &output); + friend class SerializerTests; + }; +} + + +#endif -- 2.7.4 From 150ff53a07a3d1d94ea74c0c8a01a02fb00001a7 Mon Sep 17 00:00:00 2001 From: Adrian Szyndela Date: Tue, 27 Oct 2020 10:12:22 +0100 Subject: [PATCH 14/16] refactoring: generalize serialized enums conversion Change-Id: Ia1fe8089c03605fe329bc3722bf7d99fe2117b21 --- src/internal/print_content.cpp | 10 +++++----- src/internal/serialized_convert.hpp | 17 ++++++++++++----- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/src/internal/print_content.cpp b/src/internal/print_content.cpp index d65a433..cdded17 100644 --- a/src/internal/print_content.cpp +++ b/src/internal/print_content.cpp @@ -153,16 +153,16 @@ template void printContentItem(std::ostream &stream, const T *item); template <> void printContentItem(std::ostream &stream, const FB::ItemAccess *item) { - print_content_item_access(stream, makeBusAccessType(item->type()), item->uid(), - item->gid(), makeDecisionItem(item->decision())); + print_content_item_access(stream, ldp_serialized::makeBusAccessType(item->type()), item->uid(), + item->gid(), ldp_serialized::makeDecisionItem(item->decision())); } template void printContentItemSR(std::ostream &stream, const boost::string_ref &item_type, const T *item) { auto print_func = (print_content::xml_format ? print_content_item_sr_xml : print_content_item_sr); print_func(stream, item_type, item->name()->c_str(), item->interface()->c_str(), - item->member()->c_str(), item->path()->c_str(), makeMessageType(item->type()), - makeDecisionItem(item->decision()), item->is_name_prefix()); + item->member()->c_str(), item->path()->c_str(), ldp_serialized::makeMessageType(item->type()), + ldp_serialized::makeDecisionItem(item->decision()), item->is_name_prefix()); } template <> void printContentItem(std::ostream &stream, const FB::ItemSend *item) { @@ -182,7 +182,7 @@ void printContentPolicy(std::ostream &stream, const T *policy) { } void printDecisionItem(std::ostream &stream, const FB::DecisionItem *item) { - print_content_decision_item(stream, makeDecision(item->decision()), item->privilege()->c_str()); + print_content_decision_item(stream, ldp_serialized::makeDecision(item->decision()), item->privilege()->c_str()); } void printTreeLevel(std::ostream &stream, const FB::PolicyOwnNode *node, unsigned indent) { diff --git a/src/internal/serialized_convert.hpp b/src/internal/serialized_convert.hpp index f2c134b..de00f2f 100644 --- a/src/internal/serialized_convert.hpp +++ b/src/internal/serialized_convert.hpp @@ -15,21 +15,28 @@ */ #pragma once -#include "include/fb_generated.h" #include "policy.hpp" -inline ldp_xml_parser::Decision makeDecision(FB::Decision d) { +namespace ldp_serialized { + +template +ldp_xml_parser::Decision makeDecision(D d) { return static_cast(d); } -inline ldp_xml_parser::DecisionItem makeDecisionItem(const FB::DecisionItem *di) { +template +inline ldp_xml_parser::DecisionItem makeDecisionItem(const DI *di) { return ldp_xml_parser::DecisionItem(makeDecision(di->decision()), di->privilege()->c_str()); } -inline ldp_xml_parser::BusAccessType makeBusAccessType(FB::BusAccessType type) { +template +ldp_xml_parser::BusAccessType makeBusAccessType(T type) { return static_cast(type); } -inline ldp_xml_parser::MessageType makeMessageType(FB::MessageType type) { +template +ldp_xml_parser::MessageType makeMessageType(T type) { return static_cast(type); } + +} -- 2.7.4 From 077af6b1cd514f9021987513c873704589baeb48 Mon Sep 17 00:00:00 2001 From: Adrian Szyndela Date: Tue, 27 Oct 2020 10:18:52 +0100 Subject: [PATCH 15/16] refactoring: rename StorageBackendSerialized to StorageBackendFlatbuffers Change-Id: I1d6a8e089b31730e7a8e2f54ea0a3b2fe8548401 --- Makefile.am | 2 +- ...ialized.cpp => storage_backend_flatbuffers.cpp} | 64 +++++++++++----------- src/internal/storage_backend_flatbuffers.hpp | 57 +++++++++++++++++++ src/internal/storage_backend_serialized.hpp | 54 +----------------- 4 files changed, 92 insertions(+), 85 deletions(-) rename src/internal/{storage_backend_serialized.cpp => storage_backend_flatbuffers.cpp} (78%) create mode 100644 src/internal/storage_backend_flatbuffers.hpp diff --git a/Makefile.am b/Makefile.am index 3388f17..b52237d 100644 --- a/Makefile.am +++ b/Makefile.am @@ -64,7 +64,7 @@ COMMON_SRC =\ src/internal/tslog.cpp \ src/internal/serializer_flatbuffers.cpp \ src/internal/print_content.cpp \ - src/internal/storage_backend_serialized.cpp \ + src/internal/storage_backend_flatbuffers.cpp \ src/internal/storage_backend_xml.cpp src_libdbuspolicy1_la_SOURCES =\ diff --git a/src/internal/storage_backend_serialized.cpp b/src/internal/storage_backend_flatbuffers.cpp similarity index 78% rename from src/internal/storage_backend_serialized.cpp rename to src/internal/storage_backend_flatbuffers.cpp index a099a1e..b0c6933 100644 --- a/src/internal/storage_backend_serialized.cpp +++ b/src/internal/storage_backend_flatbuffers.cpp @@ -17,7 +17,7 @@ #include "print_content.hpp" #include "serialized_convert.hpp" #include "serializer.hpp" -#include "storage_backend_serialized.hpp" +#include "storage_backend_flatbuffers.hpp" #include "transaction_guard.hpp" #include "tslog.hpp" #include @@ -123,7 +123,7 @@ ldp_xml_parser::DecisionItem getDecisionItemMaybeNull(const T &item, const P *po } // anonymous namespace -class StorageBackendSerialized::StorageBackendSerializedImpl { +class StorageBackendFlatbuffers::StorageBackendFlatbuffersImpl { int fd{-1}; uint8_t *mem{static_cast(MAP_FAILED)}; size_t length{0}; @@ -148,7 +148,7 @@ public: const M *getPolicySet(); }; -ldp_xml_parser::DecisionItem StorageBackendSerialized::StorageBackendSerializedImpl::getDecisionFromSendIndex(const MatchItemSend &item, +ldp_xml_parser::DecisionItem StorageBackendFlatbuffers::StorageBackendFlatbuffersImpl::getDecisionFromSendIndex(const MatchItemSend &item, const FB::PolicySend *policy) { const auto *index = policy->index(); @@ -217,7 +217,7 @@ ldp_xml_parser::DecisionItem StorageBackendSerialized::StorageBackendSerializedI return ldp_xml_parser::DecisionItem(ldp_xml_parser::Decision::ANY); } -void StorageBackendSerialized::StorageBackendSerializedImpl::releaseMMap() { +void StorageBackendFlatbuffers::StorageBackendFlatbuffersImpl::releaseMMap() { assert(MAP_FAILED != mem); assert(0 != length); @@ -228,7 +228,7 @@ void StorageBackendSerialized::StorageBackendSerializedImpl::releaseMMap() { length = 0; } -void StorageBackendSerialized::StorageBackendSerializedImpl::releaseFD() { +void StorageBackendFlatbuffers::StorageBackendFlatbuffersImpl::releaseFD() { assert(-1 != fd); if (close(fd) != 0) @@ -237,7 +237,7 @@ void StorageBackendSerialized::StorageBackendSerializedImpl::releaseFD() { fd = -1; } -void StorageBackendSerialized::StorageBackendSerializedImpl::release() { +void StorageBackendFlatbuffers::StorageBackendFlatbuffersImpl::release() { if (-1 != fd) { // we need to check it, because we may have initialized the storage directly from File * releaseMMap(); releaseFD(); @@ -250,7 +250,7 @@ void StorageBackendSerialized::StorageBackendSerializedImpl::release() { file = nullptr; } -bool StorageBackendSerialized::StorageBackendSerializedImpl::init(const char *filename, bool verify) { +bool StorageBackendFlatbuffers::StorageBackendFlatbuffersImpl::init(const char *filename, bool verify) { assert(nullptr == file); auto err = [filename] (const char *what) { @@ -290,7 +290,7 @@ bool StorageBackendSerialized::StorageBackendSerializedImpl::init(const char *fi return true; } -bool StorageBackendSerialized::StorageBackendSerializedImpl::initFromData(const uint8_t *mem, size_t size, bool verify) { +bool StorageBackendFlatbuffers::StorageBackendFlatbuffersImpl::initFromData(const uint8_t *mem, size_t size, bool verify) { assert(nullptr == file); if (verify) { @@ -314,7 +314,7 @@ bool StorageBackendSerialized::StorageBackendSerializedImpl::initFromData(const return file != nullptr; } -bool StorageBackendSerialized::StorageBackendSerializedImpl::initFromXML(const char *config_name) { +bool StorageBackendFlatbuffers::StorageBackendFlatbuffersImpl::initFromXML(const char *config_name) { assert(nullptr == file); assert(nullptr == serializer.get()); @@ -328,7 +328,7 @@ bool StorageBackendSerialized::StorageBackendSerializedImpl::initFromXML(const c return initFromData(data, serialized_size, false); } -void StorageBackendSerialized::StorageBackendSerializedImpl::printContent(const bool xml_format) const { +void StorageBackendFlatbuffers::StorageBackendFlatbuffersImpl::printContent(const bool xml_format) const { print_content::use_xml_format(xml_format); std::cerr << *file; } @@ -342,7 +342,7 @@ void StorageBackendSerialized::StorageBackendSerializedImpl::printContent(const typedef FB::Policy##T policy_type; \ }; \ template <> \ - auto StorageBackendSerialized::StorageBackendSerializedImpl::getPolicySet() \ + auto StorageBackendFlatbuffers::StorageBackendFlatbuffersImpl::getPolicySet() \ -> const typename type_helper::policy_set_type * { \ assert(file); \ return file->m_##t##_set(); \ @@ -353,43 +353,43 @@ TYPE_HELPER(Send, send) TYPE_HELPER(Receive, receive) TYPE_HELPER(Access, access) -bool StorageBackendSerialized::init(const char *filename, bool verify) { +bool StorageBackendFlatbuffers::init(const char *filename, bool verify) { return pimpl->init(filename, verify); } -bool StorageBackendSerialized::initFromData(const uint8_t *serialized_data, size_t length, bool verify) { +bool StorageBackendFlatbuffers::initFromData(const uint8_t *serialized_data, size_t length, bool verify) { return pimpl->initFromData(serialized_data, length, verify); } -bool StorageBackendSerialized::initFromXML(const char *config_name) { +bool StorageBackendFlatbuffers::initFromXML(const char *config_name) { return pimpl->initFromXML(config_name); } -void StorageBackendSerialized::release() { +void StorageBackendFlatbuffers::release() { pimpl->release(); } -void StorageBackendSerialized::printContent(const bool xml_format) const { +void StorageBackendFlatbuffers::printContent(const bool xml_format) const { pimpl->printContent(xml_format); } template -ldp_xml_parser::DecisionItem StorageBackendSerialized::getDecisionItemContextMandatory(const T &item) const { +ldp_xml_parser::DecisionItem StorageBackendFlatbuffers::getDecisionItemContextMandatory(const T &item) const { return getDecisionItem(item, pimpl->getPolicySet()->context_mandatory()); } template <> -ldp_xml_parser::DecisionItem StorageBackendSerialized::getDecisionItemContextMandatory(const MatchItemSend &item) const { +ldp_xml_parser::DecisionItem StorageBackendFlatbuffers::getDecisionItemContextMandatory(const MatchItemSend &item) const { return pimpl->getDecisionFromSendIndex(item, pimpl->getPolicySet()->context_mandatory()); } template <> -ldp_xml_parser::DecisionItem StorageBackendSerialized::getDecisionItemContextDefault(const MatchItemSend &item) const { +ldp_xml_parser::DecisionItem StorageBackendFlatbuffers::getDecisionItemContextDefault(const MatchItemSend &item) const { return pimpl->getDecisionFromSendIndex(item, pimpl->getPolicySet()->context_default()); } template <> -ldp_xml_parser::DecisionItem StorageBackendSerialized::getDecisionItemUser(uid_t uid, const MatchItemSend &item) const { +ldp_xml_parser::DecisionItem StorageBackendFlatbuffers::getDecisionItemUser(uid_t uid, const MatchItemSend &item) const { auto *policyPair = pimpl->getPolicySet()->user()->LookupByKey(uid); if (nullptr == policyPair) return ldp_xml_parser::Decision::ANY; @@ -397,28 +397,28 @@ ldp_xml_parser::DecisionItem StorageBackendSerialized::getDecisionItemUser(uid_t } template -ldp_xml_parser::DecisionItem StorageBackendSerialized::getDecisionItemContextDefault(const T &item) const { +ldp_xml_parser::DecisionItem StorageBackendFlatbuffers::getDecisionItemContextDefault(const T &item) const { return getDecisionItem(item, pimpl->getPolicySet()->context_default()); } template -ldp_xml_parser::DecisionItem StorageBackendSerialized::getDecisionItemUser(uid_t uid, const T &item) const { +ldp_xml_parser::DecisionItem StorageBackendFlatbuffers::getDecisionItemUser(uid_t uid, const T &item) const { return getDecisionItemMaybeNull(item, pimpl->getPolicySet()->user()->LookupByKey(uid)); } template -ldp_xml_parser::DecisionItem StorageBackendSerialized::getDecisionItemGroup(gid_t gid, const T &item) const { +ldp_xml_parser::DecisionItem StorageBackendFlatbuffers::getDecisionItemGroup(gid_t gid, const T &item) const { return getDecisionItemMaybeNull(item, pimpl->getPolicySet()->group()->LookupByKey(gid)); } template -bool StorageBackendSerialized::existsPolicyForGroup(gid_t gid) const { +bool StorageBackendFlatbuffers::existsPolicyForGroup(gid_t gid) const { return pimpl->getPolicySet()->group()->LookupByKey(gid) != nullptr; } #define T_INSTANTIATION(T) \ - template ldp_xml_parser::DecisionItem StorageBackendSerialized::getDecisionItemContextMandatory(const ldp_xml_parser::MatchItem##T &item) const; \ - template ldp_xml_parser::DecisionItem StorageBackendSerialized::getDecisionItemContextDefault(const ldp_xml_parser::MatchItem##T &item) const; + template ldp_xml_parser::DecisionItem StorageBackendFlatbuffers::getDecisionItemContextMandatory(const ldp_xml_parser::MatchItem##T &item) const; \ + template ldp_xml_parser::DecisionItem StorageBackendFlatbuffers::getDecisionItemContextDefault(const ldp_xml_parser::MatchItem##T &item) const; T_INSTANTIATION(Own) T_INSTANTIATION(Send) @@ -428,9 +428,9 @@ T_INSTANTIATION(Access) #undef T_INSTANTIATION #define T_INSTANTIATION2(T) \ - template ldp_xml_parser::DecisionItem StorageBackendSerialized::getDecisionItemUser(uid_t uid, const ldp_xml_parser::MatchItem##T &item) const; \ - template ldp_xml_parser::DecisionItem StorageBackendSerialized::getDecisionItemGroup(gid_t gid, const ldp_xml_parser::MatchItem##T &item) const; \ - template bool StorageBackendSerialized::existsPolicyForGroup(gid_t) const; + template ldp_xml_parser::DecisionItem StorageBackendFlatbuffers::getDecisionItemUser(uid_t uid, const ldp_xml_parser::MatchItem##T &item) const; \ + template ldp_xml_parser::DecisionItem StorageBackendFlatbuffers::getDecisionItemGroup(gid_t gid, const ldp_xml_parser::MatchItem##T &item) const; \ + template bool StorageBackendFlatbuffers::existsPolicyForGroup(gid_t) const; T_INSTANTIATION2(Own) T_INSTANTIATION2(Send) @@ -438,11 +438,11 @@ T_INSTANTIATION2(Receive) #undef T_INSTANTIATION2 -StorageBackendSerialized::StorageBackendSerialized() - : pimpl{new StorageBackendSerializedImpl} { +StorageBackendFlatbuffers::StorageBackendFlatbuffers() + : pimpl{new StorageBackendFlatbuffersImpl} { } -StorageBackendSerialized::~StorageBackendSerialized() { +StorageBackendFlatbuffers::~StorageBackendFlatbuffers() { pimpl->release(); } diff --git a/src/internal/storage_backend_flatbuffers.hpp b/src/internal/storage_backend_flatbuffers.hpp new file mode 100644 index 0000000..aaba006 --- /dev/null +++ b/src/internal/storage_backend_flatbuffers.hpp @@ -0,0 +1,57 @@ +/* + * 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 "policy.hpp" + +#include + +namespace ldp_serialized { + +class StorageBackendFlatbuffers { + class StorageBackendFlatbuffersImpl; + std::unique_ptr pimpl; +public: + StorageBackendFlatbuffers(); + ~StorageBackendFlatbuffers(); + + bool init(const char *filename, bool verify = false); + bool initFromData(const uint8_t *serialized_data, size_t length, bool verify = false); + bool initFromXML(const char *config_name); + void release(); + + void printContent(const bool xml_format = false) const; + + // Supported template parameters are: + // MatchPolicyOwn, MatchPolicySend, MatchPolicyReceive + // and - only for Contexts - MatchPolicyAccess + template + ldp_xml_parser::DecisionItem getDecisionItemContextMandatory(const T &item) const; + template + ldp_xml_parser::DecisionItem getDecisionItemContextDefault(const T &item) const; + template + ldp_xml_parser::DecisionItem getDecisionItemUser(uid_t uid, const T &item) const; + template + ldp_xml_parser::DecisionItem getDecisionItemGroup(gid_t gid, const T &item) const; + + // This works with T set to MatchItemOwn, MatchItemSend or MatchItemReceive + // This is needed for filtering mapGroups. Check NaivePolicyChecker. + template + bool existsPolicyForGroup(gid_t gid) const; + +}; + +} diff --git a/src/internal/storage_backend_serialized.hpp b/src/internal/storage_backend_serialized.hpp index 4781b87..7755dd3 100644 --- a/src/internal/storage_backend_serialized.hpp +++ b/src/internal/storage_backend_serialized.hpp @@ -1,57 +1,7 @@ -/* - * 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 "policy.hpp" - -#include +#include "storage_backend_flatbuffers.hpp" namespace ldp_serialized { - -class StorageBackendSerialized { - class StorageBackendSerializedImpl; - std::unique_ptr pimpl; -public: - StorageBackendSerialized(); - ~StorageBackendSerialized(); - - bool init(const char *filename, bool verify = false); - bool initFromData(const uint8_t *serialized_data, size_t length, bool verify = false); - bool initFromXML(const char *config_name); - void release(); - - void printContent(const bool xml_format = false) const; - - // Supported template parameters are: - // MatchPolicyOwn, MatchPolicySend, MatchPolicyReceive - // and - only for Contexts - MatchPolicyAccess - template - ldp_xml_parser::DecisionItem getDecisionItemContextMandatory(const T &item) const; - template - ldp_xml_parser::DecisionItem getDecisionItemContextDefault(const T &item) const; - template - ldp_xml_parser::DecisionItem getDecisionItemUser(uid_t uid, const T &item) const; - template - ldp_xml_parser::DecisionItem getDecisionItemGroup(gid_t gid, const T &item) const; - - // This works with T set to MatchItemOwn, MatchItemSend or MatchItemReceive - // This is needed for filtering mapGroups. Check NaivePolicyChecker. - template - bool existsPolicyForGroup(gid_t gid) const; - -}; - +using StorageBackendSerialized = StorageBackendFlatbuffers; } -- 2.7.4 From 68213b1fb461d6c162f1de83d47397907aa78a26 Mon Sep 17 00:00:00 2001 From: Adrian Szyndela Date: Tue, 27 Oct 2020 10:45:15 +0100 Subject: [PATCH 16/16] refactoring: remove unused enum Change-Id: I0ebeb4c599bc05ebe9c92263fd75ccaf8cfd9486 --- src/internal/serializer_flatbuffers.hpp | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/internal/serializer_flatbuffers.hpp b/src/internal/serializer_flatbuffers.hpp index 3dbed7d..10f0c12 100644 --- a/src/internal/serializer_flatbuffers.hpp +++ b/src/internal/serializer_flatbuffers.hpp @@ -28,13 +28,6 @@ namespace ldp_serializer { - enum class SetType : uint8_t { - OWN, - SEND, - RECEIVE, - ACCESS - }; - template using FbOff = flatbuffers::Offset; -- 2.7.4