Convert ServiceImpl namespace to a class
[platform/core/security/security-manager.git] / src / common / include / service_impl.h
1 /*
2  *  Copyright (c) 2014-2015 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  *  Contact: Rafal Krypa <r.krypa@samsung.com>
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        service_impl.h
20  * @author      Rafal Krypa <r.krypa@samsung.com>
21  * @brief       Implementation of the service methods
22  */
23
24 #ifndef _SECURITY_MANAGER_SERVICE_IMPL_
25 #define _SECURITY_MANAGER_SERVICE_IMPL_
26
27 #include <unistd.h>
28 #include <sys/types.h>
29
30 #include <unordered_set>
31
32 #include "security-manager.h"
33
34 namespace SecurityManager {
35
36 class ServiceImpl {
37 private:
38     static uid_t getGlobalUserId(void);
39
40     static void checkGlobalUser(uid_t &uid, std::string &cynaraUserStr);
41
42     static bool isSubDir(const char *parent, const char *subdir);
43
44     static bool getUserAppDir(const uid_t &uid, std::string &userAppDir);
45
46     static bool installRequestAuthCheck(const app_inst_req &req, uid_t uid, bool &isCorrectPath, std::string &appPath);
47
48     static bool getZoneId(std::string &zoneId);
49
50 public:
51     ServiceImpl();
52     virtual ~ServiceImpl();
53
54     /**
55     * Process application installation request.
56     *
57     * @param[in] req installation request
58     * @param[in] uid id of the requesting user
59     * @param[in] isSlave Indicates if function should be called under slave mode
60     *
61     * @return API return code, as defined in protocols.h
62     */
63     int appInstall(const app_inst_req &req, uid_t uid, bool isSlave);
64
65     /**
66     * Process application uninstallation request.
67     *
68     * @param[in] req uninstallation request
69     * @param[in] uid id of the requesting user
70     * @param[in] isSlave Indicates if function should be called under slave mode
71     *
72     * @return API return code, as defined in protocols.h
73     */
74     int appUninstall(const std::string &appId, uid_t uid, bool isSlave);
75
76     /**
77     * Process package id query.
78     * Retrieves the package id associated with given application id.
79     *
80     * @param[in] appId application identifier
81     * @param[out] pkgId returned package identifier
82     *
83     * @return API return code, as defined in protocols.h
84     */
85     int getPkgId(const std::string &appId, std::string &pkgId);
86
87     /**
88     * Process query for supplementary groups allowed for the application.
89     * For given appId and uid, calculate allowed privileges that give
90     * direct access to file system resources. For each permission Cynara will be
91     * queried.
92     * Returns set of group ids that are permitted.
93     *
94     * @param[in]  appId application identifier
95     * @param[in]  uid id of the requesting user
96     * @param[in]  pid id of the requesting process (to construct Cynara session id)
97     * @param[in]  isSlave Indicates if function should be called under slave mode
98     * @param[out] gids returned set of allowed group ids
99     *
100     * @return API return code, as defined in protocols.h
101     */
102     int getAppGroups(const std::string &appId, uid_t uid, pid_t pid, bool isSlave,
103             std::unordered_set<gid_t> &gids);
104
105     /**
106     * Process user adding request.
107     *
108     * @param[in] uidAdded uid of newly created user
109     * @param[in] userType type of newly created user
110     * @param[in] uid uid of requesting user
111     * @param[in] isSlave Indicates if function should be called under slave mode
112     *
113     * @return API return code, as defined in protocols.h
114     */
115     int userAdd(uid_t uidAdded, int userType, uid_t uid, bool isSlave);
116
117     /**
118     * Process user deletion request.
119     *
120     * @param[in] uidDeleted uid of removed user
121     * @param[in] uid uid of requesting user
122     * @param[in] isSlave Indicates if function should be called under slave mode
123     *
124     * @return API return code, as defined in protocols.h
125     */
126     int userDelete(uid_t uidDeleted, uid_t uid, bool isSlave);
127
128     /**
129     * Update policy in Cynara - proper privilege: http://tizen.org/privilege/systemsettings.admin
130     * is needed for this to succeed
131     *
132     * @param[in] policyEntries vector of policy chunks with instructions
133     * @param[in] uid identifier of requesting user
134     * @param[in] pid PID of requesting process
135     * @param[in] smackLabel smack label of requesting app
136     *
137     * @return API return code, as defined in protocols.h
138     */
139
140     int policyUpdate(const std::vector<policy_entry> &policyEntries, uid_t uid, pid_t pid, const std::string &smackLabel);
141     /**
142     * Fetch all configured privileges from user configurable bucket.
143     * Depending on forAdmin value: personal user policies or admin enforced
144     * policies are returned.
145     *
146     * @param[in] forAdmin determines if user is asking as ADMIN or not
147     * @param[in] filter filter for limiting the query
148     * @param[in] uid identifier of queried user
149     * @param[in] pid PID of requesting process
150     * @param[out] policyEntries vector of policy entries with result
151     *
152     * @return API return code, as defined in protocols.h
153     */
154     int getConfiguredPolicy(bool forAdmin, const policy_entry &filter, uid_t uid, pid_t pid, const std::string &smackLabel, std::vector<policy_entry> &policyEntries);
155
156     /**
157     * Fetch all privileges for all apps installed for specific user.
158     *
159     * @param[in] forAdmin determines if user is asking as ADMIN or not
160     * @param[in] filter filter for limiting the query
161     * @param[in] uid identifier of queried user
162     * @param[in] pid PID of requesting process
163     * @param[out] policyEntries vector of policy entries with result
164     *
165     * @return API return code, as defined in protocols.h
166     */
167     int getPolicy(const policy_entry &filter, uid_t uid, pid_t pid, const std::string &smackLabel, std::vector<policy_entry> &policyEntries);
168
169     /**
170     * Process getting policy descriptions list.
171     *
172     * @param[in] descriptions empty vector for descriptions strings
173     *
174     * @return API return code, as defined in protocols.h
175     */
176     int policyGetDesc(std::vector<std::string> &descriptions);
177
178     /**
179      * Process getting privileges mappings from one version to another.
180      *
181      * @param[in] version_from version to be mapped from
182      * @param[in] version_to version to be mapped to
183      * @param[in] privileges vector of privileges to be mapped
184      * @param[out] mappings mappings of given privileges
185      */
186     int getPrivilegesMappings(const std::string &version_from,
187                               const std::string &version_to,
188                               const std::vector<std::string> &privileges,
189                               std::vector<std::string> &mappings);
190
191     /**
192      * Process getting resources group list.
193      *
194      * @param[out] groups empty vector for group strings
195      *
196      * @return API return code, as defined in protocols.h
197      */
198     int policyGetGroups(std::vector<std::string> &groups);
199 };
200 } /* namespace SecurityManager */
201
202 #endif /* _SECURITY_MANAGER_SERVICE_IMPL_ */