refactoring: remove duplicate db access method 58/199158/8
authorAdrian Szyndela <adrian.s@samsung.com>
Fri, 1 Feb 2019 08:27:34 +0000 (09:27 +0100)
committerAdrian Szyndela <adrian.s@samsung.com>
Tue, 12 Feb 2019 14:49:23 +0000 (15:49 +0100)
This removes duplicated db access method from naive_policy_checker.
Additionally, friend declaration is removed for DbAdapter,
the access method made public, and code that uses removed method is reworked.

Change-Id: Ifac510e13ba0001390c25d5584c7500c89d665be

src/internal/internal.cpp
src/internal/naive_policy_checker.cpp
src/internal/naive_policy_checker.hpp
src/internal/policy.cpp
src/internal/policy.hpp
src/internal/xml_parser.hpp

index f142cca..d38f277 100755 (executable)
@@ -66,7 +66,7 @@ void __internal_init_flush_logs()
 
 void __internal_init_sup_group(bool bus_type, uid_t uid, gid_t gid)
 {
-       static_parser().updateGroupPolicy(bus_type, uid, gid);
+       policy_checker().updateGroupDb(bus_type, uid, gid);
 }
 
 void __internal_enter()
index e9add38..e1ef7c0 100755 (executable)
@@ -115,12 +115,17 @@ DecisionItem NaivePolicyChecker::checkGroupPolicies(const NaivePolicyDb& policy_
        return Decision::ANY;
 }
 
+void NaivePolicyChecker::updateGroupDb(bool bus_type, uid_t uid, gid_t gid)
+{
+       getPolicyDb(bus_type).initializeGroups(uid, gid);
+}
+
 void NaivePolicyChecker::clearDb(bool bus_type)
 {
-       m_bus_db[bus_type].clear();
+       getPolicyDb(bus_type).clear();
 }
 
 void NaivePolicyChecker::printContent(const bool bus_type)
 {
-       db(bus_type).printContent();
+       getPolicyDb(bus_type).printContent();
 }
index a1b0cdc..5dc5355 100644 (file)
@@ -38,13 +38,6 @@ namespace ldp_xml_parser
                /** Policy databases for system and session bus */
                NaivePolicyDb m_bus_db[2];
 
-               /** Retrieves policy db
-                * \param[in] type Type of database (system/session bus)
-                * \return Returns reference to chosen bus policy db
-                * \ingroup Implementation
-                */
-               NaivePolicyDb& getPolicyDb(bool type);
-
                /** Parses delivered decision. In case of Decision::CHECK calls cynara.
                 * \param[in] decision Decision from checkers
                 * \param[in] uid User id
@@ -85,18 +78,20 @@ namespace ldp_xml_parser
                                                gid_t gid,
                                                const T& item);
 
-               /** Provides db handle for parsing purposes
+       public:
+               /** Retrieves policy db
+                * \param[in] type Type of database (system/session bus)
+                * \return Returns reference to chosen bus policy db
                 */
-               inline NaivePolicyDb &db(bool sessionBus) { return m_bus_db[sessionBus]; }
-
-               friend class DbAdapter; // give adapters access to db()
+               NaivePolicyDb& getPolicyDb(bool type);
 
-       public:
                /** Clears all db data, useful for reloading configuration
                 * during testing.
                 */
                void clearDb(bool bus_type);
 
+               void updateGroupDb(bool bus_type, uid_t uid, gid_t gid);
+
                /** Prints to stderr the structures and the amount of their memory */
                void printContent(const bool bus_type);
 
index 6b73ddf..0530194 100755 (executable)
@@ -155,7 +155,7 @@ void DbAdapter::parseRule(const char *name, const char **attr)
                parseRuleAttribute(attr[i], attr[i + 1]);
        }
 
-       __builder.generateItem(policy_checker().db(curr_bus), policy_type, policy_type_value);
+       __builder.generateItem(policy_checker().getPolicyDb(curr_bus), policy_type, policy_type_value);
 }
 
 void DbAdapter::parseRuleAttribute(const char *name, const char *value)
@@ -197,11 +197,6 @@ void DbAdapter::parseRuleAttribute(const char *name, const char *value)
                __builder.addMessageType(__str_to_message_type(value));
 }
 
-void DbAdapter::updateGroupDb(bool bus, uid_t uid, gid_t gid)
-{
-       policy_checker().db(bus).initializeGroups(uid, gid);
-}
-
 DecisionItem::DecisionItem(Decision decision, const char* privilege)
        : __decision(decision)
 {
index 19781d2..e0d852a 100755 (executable)
@@ -305,7 +305,6 @@ namespace ldp_xml_parser
        public:
                void parsePolicy(bool bus, const char **attr);
                void parseRule(const char *name, const char **attr);
-               void updateGroupDb(bool bus, uid_t uid, gid_t gid);
        };
 }
 #endif
index 2369c61..d309afd 100755 (executable)
@@ -35,10 +35,6 @@ namespace ldp_xml_parser
                /** Parses given config file for declared bus type */
                int parsePolicy(bool bus, const std::string& fname);
 
-               void updateGroupPolicy(bool bus, uid_t uid, gid_t gid) {
-                       __adapter.updateGroupDb(bus, uid, gid);
-               }
-
                void elementStart(const char *el, const char **attr);
 
                void elementEnd(const char *el);