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;
42 Serialization::Serialize(sendBuf,
43 static_cast<int>(MasterSecurityModuleCall::CYNARA_UPDATE_POLICY),
44 appId, uidstr, oldPkgPrivileges, newPkgPrivileges);
46 ret = sendToServer(MASTER_SERVICE_SOCKET, sendBuf.Pop(), retBuf);
47 if (ret == SECURITY_MANAGER_API_SUCCESS)
48 Deserialization::Deserialize(retBuf, ret);
53 int CynaraUserInit(const uid_t uidAdded, int userType)
56 MessageBuffer sendBuf, retBuf;
58 Serialization::Serialize(sendBuf,
59 static_cast<int>(MasterSecurityModuleCall::CYNARA_USER_INIT),
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;
74 Serialization::Serialize(sendBuf,
75 static_cast<int>(MasterSecurityModuleCall::CYNARA_USER_REMOVE),
78 ret = sendToServer(MASTER_SERVICE_SOCKET, sendBuf.Pop(), retBuf);
79 if (ret == SECURITY_MANAGER_API_SUCCESS)
80 Deserialization::Deserialize(retBuf, ret);
85 int SmackInstallRules(const std::string &appId, const std::string &pkgId,
86 const std::vector<std::string> &pkgContents)
89 MessageBuffer sendBuf, retBuf;
90 Serialization::Serialize(sendBuf,
91 static_cast<int>(MasterSecurityModuleCall::SMACK_INSTALL_RULES),
92 appId, pkgId, pkgContents);
94 ret = sendToServer(MASTER_SERVICE_SOCKET, sendBuf.Pop(), retBuf);
95 if (ret == SECURITY_MANAGER_API_SUCCESS)
96 Deserialization::Deserialize(retBuf, ret);
101 int SmackUninstallRules(const std::string &appId, const std::string &pkgId,
102 const std::vector<std::string> &pkgContents, const bool removePkg)
105 MessageBuffer sendBuf, retBuf;
107 Serialization::Serialize(sendBuf,
108 static_cast<int>(MasterSecurityModuleCall::SMACK_UNINSTALL_RULES),
109 appId, pkgId, pkgContents, 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;
126 Serialization::Serialize(sendBuf,
127 static_cast<int>(MasterSecurityModuleCall::POLICY_UPDATE),
128 policyEntries, uid, pid, smackLabel);
130 ret = sendToServer(MASTER_SERVICE_SOCKET, sendBuf.Pop(), retBuf);
131 if (ret == SECURITY_MANAGER_API_SUCCESS)
132 Deserialization::Deserialize(retBuf, ret);
137 int GetConfiguredPolicy(bool forAdmin, const policy_entry &filter, uid_t uid, pid_t pid,
138 const std::string &smackLabel, std::vector<policy_entry> &policyEntries)
141 MessageBuffer sendBuf, retBuf;
143 Serialization::Serialize(sendBuf,
144 static_cast<int>(MasterSecurityModuleCall::GET_CONFIGURED_POLICY),
145 forAdmin, filter, uid, pid, smackLabel);
147 ret = sendToServer(MASTER_SERVICE_SOCKET, sendBuf.Pop(), retBuf);
148 if (ret == SECURITY_MANAGER_API_SUCCESS) {
149 Deserialization::Deserialize(retBuf, ret);
150 if (ret == SECURITY_MANAGER_API_SUCCESS)
151 Deserialization::Deserialize(retBuf, policyEntries);
157 int GetPolicy(const policy_entry &filter, uid_t uid, pid_t pid, const std::string &smackLabel,
158 std::vector<policy_entry> &policyEntries)
161 MessageBuffer sendBuf, retBuf;
163 Serialization::Serialize(sendBuf,
164 static_cast<int>(MasterSecurityModuleCall::GET_POLICY),
165 filter, uid, pid, smackLabel);
167 ret = sendToServer(MASTER_SERVICE_SOCKET, sendBuf.Pop(), retBuf);
168 if (ret == SECURITY_MANAGER_API_SUCCESS) {
169 Deserialization::Deserialize(retBuf, ret);
170 if (ret == SECURITY_MANAGER_API_SUCCESS)
171 Deserialization::Deserialize(retBuf, policyEntries);
177 int PolicyGetDesc(std::vector<std::string> &descriptions)
180 MessageBuffer sendBuf, retBuf;
182 Serialization::Serialize(sendBuf,
183 static_cast<int>(MasterSecurityModuleCall::POLICY_GET_DESC));
185 ret = sendToServer(MASTER_SERVICE_SOCKET, sendBuf.Pop(), retBuf);
186 if (ret == SECURITY_MANAGER_API_SUCCESS) {
187 Deserialization::Deserialize(retBuf, ret);
188 if (ret == SECURITY_MANAGER_API_SUCCESS)
189 Deserialization::Deserialize(retBuf, descriptions);
195 } // namespace MasterReq
196 } // namespace SecurityManager