Service backend implementation for getting policies levels
[platform/core/security/security-manager.git] / src / common / include / service_impl.h
1 /*
2  *  Copyright (c) 2014 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 namespace ServiceImpl {
36
37 /**
38  * Process application installation request.
39  *
40  * @param[in] req installation request
41  * @param[in] uid id of the requesting user
42  *
43  * @return API return code, as defined in protocols.h
44  */
45 int appInstall(const app_inst_req &req, uid_t uid);
46
47 /**
48  * Process application uninstallation request.
49  *
50  * @param[in] req uninstallation request
51  * @param[in] uid id of the requesting user
52  *
53  * @return API return code, as defined in protocols.h
54  */
55 int appUninstall(const std::string &appId, uid_t uid);
56
57 /**
58  * Process package id query.
59  * Retrieves the package id associated with given application id.
60  *
61  * @param[in] appId application identifier
62  * @param[out] pkgId returned package identifier
63  *
64  * @return API return code, as defined in protocols.h
65  */
66 int getPkgId(const std::string &appId, std::string &pkgId);
67
68 /**
69  * Process query for supplementary groups allowed for the application.
70  * For given appId and uid, calculate allowed privileges that give
71  * direct access to file system resources. For each permission Cynara will be
72  * queried.
73  * Returns set of group ids that are permitted.
74  *
75  * @param[in]  appId application identifier
76  * @param[in]  uid id of the requesting user
77  * @param[in]  pid id of the requesting process (to construct Cynara session id)
78  * @param[out] gids returned set of allowed group ids
79  *
80  * @return API return code, as defined in protocols.h
81  */
82 int getAppGroups(const std::string &appId, uid_t uid, pid_t pid, std::unordered_set<gid_t> &gids);
83
84 /**
85  * Process user adding request.
86  *
87  * @param[in] uidAdded uid of newly created user
88  * @param[in] userType type of newly created user
89  * @param[in] uid uid of requesting user
90  *
91  * @return API return code, as defined in protocols.h
92  */
93 int userAdd(uid_t uidAdded, int userType, uid_t uid);
94
95 /**
96  * Process user deletion request.
97  *
98  * @param[in] uidDeleted uid of removed user
99  * @param[in] uid uid of requesting user
100  *
101  * @return API return code, as defined in protocols.h
102  */
103 int userDelete(uid_t uidDeleted, uid_t uid);
104
105 /**
106  * Update policy in Cynara - proper privilege: http://tizen.org/privilege/systemsettings.admin
107  * is needed for this to succeed
108  *
109  * @param[in] policyEntries vector of policy chunks with instructions
110  * @param[in] uid identifier of requesting user
111  * @param[in] pid PID of requesting process
112  * @param[in] smackLabel smack label of requesting app
113  *
114  * @return API return code, as defined in protocols.h
115  */
116
117 int policyUpdate(const std::vector<policy_entry> &policyEntries, uid_t uid, pid_t pid, const std::string &smackLabel);
118 /**
119  * Fetch all configured privileges from user configurable bucket.
120  * Depending on forAdmin value: personal user policies or admin enforced
121  * policies are returned.
122  *
123  * @param[in] forAdmin determines if user is asking as ADMIN or not
124  * @param[in] filter filter for limiting the query
125  * @param[in] uid identifier of queried user
126  * @param[in] pid PID of requesting process
127  * @param[out] policyEntries vector of policy entries with result
128  *
129  * @return API return code, as defined in protocols.h
130  */
131 int getConfiguredPolicy(bool forAdmin, const policy_entry &filter, uid_t uid, pid_t pid, const std::string &smackLabel, std::vector<policy_entry> &policyEntries);
132
133 /**
134  * Fetch all privileges for all apps installed for specific user.
135  *
136  * @param[in] forAdmin determines if user is asking as ADMIN or not
137  * @param[in] filter filter for limiting the query
138  * @param[in] uid identifier of queried user
139  * @param[in] pid PID of requesting process
140  * @param[out] policyEntries vector of policy entries with result
141  *
142  * @return API return code, as defined in protocols.h
143  */
144 int getPolicy(const policy_entry &filter, uid_t uid, pid_t pid, const std::string &smackLabel, std::vector<policy_entry> &policyEntries);
145
146 /**
147  * Process getting policy descriptions list.
148  *
149  * @param[in] descriptions empty vector for descriptions strings
150  *
151  * @return API return code, as defined in protocols.h
152  */
153 int policyGetDesc(std::vector<std::string> &descriptions);
154
155 } /* namespace ServiceImpl */
156 } /* namespace SecurityManager */
157
158 #endif /* _SECURITY_MANAGER_SERVICE_IMPL_ */