2 * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
4 * Contact: Rafal Krypa <r.krypa@samsung.com>
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
10 * http://www.apache.org/licenses/LICENSE-2.0
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
20 * @file master-req.cpp
21 * @author Lukasz Kostyra <l.kostyra@samsung.com>
22 * @brief Definitions of master request calls
25 #include "master-req.h"
27 #include <dpl/serialization.h>
29 #include "message-buffer.h"
30 #include "connection.h"
32 namespace SecurityManager {
35 int CynaraPolicyUpdate(const std::string &appId, const std::string &uidstr,
36 const std::vector<std::string> &oldPkgPrivileges,
37 const std::vector<std::string> &newPkgPrivileges)
40 MessageBuffer sendBuf, retBuf;
41 Serialization::Serialize(sendBuf,
42 static_cast<int>(MasterSecurityModuleCall::CYNARA_UPDATE_POLICY));
43 Serialization::Serialize(sendBuf, appId);
44 Serialization::Serialize(sendBuf, uidstr);
45 Serialization::Serialize(sendBuf, oldPkgPrivileges);
46 Serialization::Serialize(sendBuf, newPkgPrivileges);
47 ret = sendToServer(MASTER_SERVICE_SOCKET, sendBuf.Pop(), retBuf);
48 if (ret == SECURITY_MANAGER_API_SUCCESS)
49 Deserialization::Deserialize(retBuf, ret);
54 int CynaraUserInit(const uid_t uidAdded, int userType)
57 MessageBuffer sendBuf, retBuf;
58 Serialization::Serialize(sendBuf,
59 static_cast<int>(MasterSecurityModuleCall::CYNARA_USER_INIT));
60 Serialization::Serialize(sendBuf, uidAdded);
61 Serialization::Serialize(sendBuf, userType);
62 ret = sendToServer(MASTER_SERVICE_SOCKET, sendBuf.Pop(), retBuf);
63 if (ret == SECURITY_MANAGER_API_SUCCESS)
64 Deserialization::Deserialize(retBuf, ret);
69 int CynaraUserRemove(const uid_t uidDeleted)
72 MessageBuffer sendBuf, retBuf;
73 Serialization::Serialize(sendBuf,
74 static_cast<int>(MasterSecurityModuleCall::CYNARA_USER_REMOVE));
75 Serialization::Serialize(sendBuf, uidDeleted);
76 ret = sendToServer(MASTER_SERVICE_SOCKET, sendBuf.Pop(), retBuf);
77 if (ret == SECURITY_MANAGER_API_SUCCESS)
78 Deserialization::Deserialize(retBuf, ret);
83 int SmackInstallRules(const std::string &appId, const std::string &pkgId,
84 const std::vector<std::string> &pkgContents)
87 MessageBuffer sendBuf, retBuf;
88 Serialization::Serialize(sendBuf,
89 static_cast<int>(MasterSecurityModuleCall::SMACK_INSTALL_RULES));
90 Serialization::Serialize(sendBuf, appId);
91 Serialization::Serialize(sendBuf, pkgId);
92 Serialization::Serialize(sendBuf, pkgContents);
93 ret = sendToServer(MASTER_SERVICE_SOCKET, sendBuf.Pop(), retBuf);
94 if (ret == SECURITY_MANAGER_API_SUCCESS)
95 Deserialization::Deserialize(retBuf, ret);
100 int SmackUninstallRules(const std::string &appId, const std::string &pkgId,
101 const std::vector<std::string> &pkgContents, const bool removePkg)
104 MessageBuffer sendBuf, retBuf;
105 Serialization::Serialize(sendBuf,
106 static_cast<int>(MasterSecurityModuleCall::SMACK_UNINSTALL_RULES));
107 Serialization::Serialize(sendBuf, appId);
108 Serialization::Serialize(sendBuf, pkgId);
109 Serialization::Serialize(sendBuf, pkgContents);
110 Serialization::Serialize(sendBuf, removePkg);
111 ret = sendToServer(MASTER_SERVICE_SOCKET, sendBuf.Pop(), retBuf);
112 if (ret == SECURITY_MANAGER_API_SUCCESS)
113 Deserialization::Deserialize(retBuf, ret);
118 // Following three requests are just forwarded security-manager API calls
119 // these do not access Privilege DB, so all can be forwarded to Master
120 int PolicyUpdate(const std::vector<policy_entry> &policyEntries, uid_t uid, pid_t pid,
121 const std::string &smackLabel)
124 MessageBuffer sendBuf, retBuf;
125 Serialization::Serialize(sendBuf,
126 static_cast<int>(MasterSecurityModuleCall::POLICY_UPDATE));
127 Serialization::Serialize(sendBuf, policyEntries);
128 Serialization::Serialize(sendBuf, uid);
129 Serialization::Serialize(sendBuf, pid);
130 Serialization::Serialize(sendBuf, smackLabel);
132 ret = sendToServer(MASTER_SERVICE_SOCKET, sendBuf.Pop(), retBuf);
133 if (ret == SECURITY_MANAGER_API_SUCCESS)
134 Deserialization::Deserialize(retBuf, ret);
139 int GetConfiguredPolicy(bool forAdmin, const policy_entry &filter, uid_t uid, pid_t pid,
140 const std::string &smackLabel, std::vector<policy_entry> &policyEntries)
143 MessageBuffer sendBuf, retBuf;
144 Serialization::Serialize(sendBuf,
145 static_cast<int>(MasterSecurityModuleCall::GET_CONFIGURED_POLICY));
146 Serialization::Serialize(sendBuf, forAdmin);
147 Serialization::Serialize(sendBuf, filter);
148 Serialization::Serialize(sendBuf, uid);
149 Serialization::Serialize(sendBuf, pid);
150 Serialization::Serialize(sendBuf, smackLabel);
152 ret = sendToServer(MASTER_SERVICE_SOCKET, sendBuf.Pop(), retBuf);
153 if (ret == SECURITY_MANAGER_API_SUCCESS) {
154 Deserialization::Deserialize(retBuf, ret);
155 if (ret == SECURITY_MANAGER_API_SUCCESS)
156 Deserialization::Deserialize(retBuf, policyEntries);
162 int GetPolicy(const policy_entry &filter, uid_t uid, pid_t pid, const std::string &smackLabel,
163 std::vector<policy_entry> &policyEntries)
166 MessageBuffer sendBuf, retBuf;
167 Serialization::Serialize(sendBuf,
168 static_cast<int>(MasterSecurityModuleCall::GET_POLICY));
169 Serialization::Serialize(sendBuf, filter);
170 Serialization::Serialize(sendBuf, uid);
171 Serialization::Serialize(sendBuf, pid);
172 Serialization::Serialize(sendBuf, smackLabel);
174 ret = sendToServer(MASTER_SERVICE_SOCKET, sendBuf.Pop(), retBuf);
175 if (ret == SECURITY_MANAGER_API_SUCCESS) {
176 Deserialization::Deserialize(retBuf, ret);
177 if (ret == SECURITY_MANAGER_API_SUCCESS)
178 Deserialization::Deserialize(retBuf, policyEntries);
184 int PolicyGetDesc(std::vector<std::string> &descriptions)
187 MessageBuffer sendBuf, retBuf;
188 Serialization::Serialize(sendBuf,
189 static_cast<int>(MasterSecurityModuleCall::POLICY_GET_DESC));
191 ret = sendToServer(MASTER_SERVICE_SOCKET, sendBuf.Pop(), retBuf);
192 if (ret == SECURITY_MANAGER_API_SUCCESS) {
193 Deserialization::Deserialize(retBuf, ret);
194 if (ret == SECURITY_MANAGER_API_SUCCESS)
195 Deserialization::Deserialize(retBuf, descriptions);
201 } // namespace MasterReq
202 } // namespace SecurityManager