Rule management added.
[platform/core/security/suspicious-activity-monitor.git] / daemon / audit / rule_manager.h
1 /**
2  * Samsung Ukraine R&D Center (SRK under a contract between)
3  * LLC "Samsung Electronics Co", Ltd (Seoul, Republic of Korea)
4  * Copyright (C) 2018 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *     http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License
17  */
18 /**
19  * @file   rule_manager.h
20  * @brief  Audit rule manager (class for parsing and applying audit rules)
21  * @date   Created Apr 04, 2018
22  * @author Mail to: <A HREF="mailto:i.metelytsia@samsung.com">Iurii Metelytsia, i.metelytsia@samsung.com</A>
23  */
24
25 #ifndef RULE_MANAGER_H
26 #define RULE_MANAGER_H
27
28 #include <string>
29 #include <vector>
30
31 #include <audit-trail/audit-trail.h>
32 #include <audit-trail/rule.h>
33
34 #include <jsoncpp/json/value.h>
35 #include <jsoncpp/json/reader.h>
36 #include <jsoncpp/json/writer.h>
37
38 #include "rule.h"
39
40 namespace audit
41 {
42
43 /**
44  * @typedef AuditRules
45  * @brief Array of audit rules handles
46  */
47 using AuditRules = std::vector<audit_rule_h>;
48
49 /**
50  * @class RuleManager
51  * @brief Class for parsing and applying audit rules
52  */
53 class RuleManager final
54 {
55     /**
56      * @brief Audit rules iteration callback
57      * @details Called from audit_trail_foreach_rule for each audit rule
58      * @param handle [in] audit rule handle
59      * @param user_data [in] pointer to user defined data
60      */
61     friend void ruleCallback(audit_rule_h handle, void* user_data);
62
63 public:
64     /**
65      * @brief Singleton instance recieving method
66      * @return Link to AuditRuleManager instance
67      */
68     static RuleManager& GetInstance();
69
70     /**
71      * @brief Get all existing rules
72      * @return All existing rules as Json
73      */
74     Json::Value getRulesAsJson();
75
76     /**
77      * @brief Update all existing rules
78      * @param rules [in] rules to apply
79      * @return true/false
80      */
81     bool updateRules(const Json::Value& rules);
82
83 private:
84     /**
85      * @brief Constructor
86      */
87     RuleManager();
88     /**
89      * @brief Copy constructor
90      */
91     RuleManager(const RuleManager&) = delete;
92     RuleManager(const RuleManager&&) = delete;
93
94     /**
95      * @brief Destructor
96      */
97     ~RuleManager();
98
99     /**
100      * @brief Copy operator
101      */
102     RuleManager& operator=(const RuleManager&) = delete;
103     RuleManager& operator=(const RuleManager&&) = delete;
104
105     /**
106      * @brief Get all existing rules
107      * @return Array of audit rules handles
108      */
109     AuditRules getRules();
110
111     audit_trail_h m_audit_trail;
112 };
113
114 } //namespace audit
115
116 #endif // RULE_MANAGER_H