[SECARSP-267] Implement policy collector
[platform/core/security/suspicious-activity-monitor.git] / device-agent / daemon / dpm / policy_enforce.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 /**
7  * @file   policy_enforce.h
8  * @brief  Policy group agregator
9  * @date   Created Jul 01, 2016
10  * @author Mail to: <A HREF="mailto:a.volkov@samsung.com">Aleksey Volkov, a.volkov@samsung.com</A>
11  */
12
13 #ifndef POLICY_ENFORCE_H
14 #define POLICY_ENFORCE_H
15
16 #include <string>
17 #include <map>
18 #include <unistd.h>
19 #include <jsoncpp/json/value.h>
20
21 namespace dpm
22 {
23
24 /**
25  * @typedef IPolicy
26  */
27 class IPolicy;
28 using IPolicyPtr = IPolicy*;
29
30 /**
31  * @typedef PolicyMap
32  * @brief Map of policy appliers instances
33  */
34 using PolicyMap = std::map<std::string, IPolicyPtr>;
35
36 /**
37  * @class PolicyEnforce
38  * @brief Parses Policy Config xml string and apply policy groups to related parsers
39  */
40 class PolicyEnforce
41 {
42 public:
43     /**
44      * @brief Return enum type for PolicyEnforce errors and policy appliers
45      */
46     enum class Result {
47         SUCCESS = 0,    /**< Success result */
48         ERROR_PARSING,  /**< json data parsing error */
49         ERROR_TYPE,     /**< Invalid policy type */
50         ERROR_DATA,     /**< Empty or invalid policy data array */
51         ERROR_DPM,      /**< Error recived from DPM modules */
52         ERROR_UNKNOWN,  /**< Other errors */
53     };
54
55     /**
56      * @brief Singleton instance recieving method
57      * @return Link to PolicyEnforce instance
58      */
59     static PolicyEnforce& GetInstance();
60
61     /**
62      * @brief Register policy applier object instance for defined policy
63      * @param policy_name [in] name of the policy
64      * @param policy_applier [in] pointer to the applier instance
65      */
66     void registerPolicy(const std::string& policy_name, IPolicyPtr policy_applier);
67
68     /**
69      * @brief Parse policy and apply policy nodes to related policy appliers instances
70      * @param policy [in] JSON string with policy configuration
71      * @return Error code
72      */
73     Result applyPolicy(const std::string& jsonString);
74
75     /**
76      * @brief Parse policy and receive policy states
77      * @param policy [in/out] JSON object with policy configuration
78      * @return Error code
79      */
80     Result getStates(Json::Value& policy);
81
82 private:
83     /**
84      * @brief Constructor
85      */
86     PolicyEnforce();
87     /**
88      * @brief Copy constructor
89      */
90     PolicyEnforce(const PolicyEnforce&) = delete;
91
92     /**
93      * @brief Destructor
94      */
95     virtual ~PolicyEnforce();
96
97     /**
98      * @brief Copy operator
99      */
100     PolicyEnforce& operator=(const PolicyEnforce&) = delete;
101
102     PolicyMap m_policy_map;
103
104     uid_t this_user;
105     uid_t dpm_user;
106 };
107
108 } //namespace dpm
109
110 #endif // POLICY_ENFORCE_H