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> &privileges)
39 MessageBuffer sendBuf, retBuf;
41 Serialization::Serialize(sendBuf,
42 static_cast<int>(MasterSecurityModuleCall::CYNARA_UPDATE_POLICY),
43 appId, uidstr, privileges);
45 ret = sendToServer(MASTER_SERVICE_SOCKET, sendBuf.Pop(), retBuf);
46 if (ret == SECURITY_MANAGER_API_SUCCESS)
47 Deserialization::Deserialize(retBuf, ret);
52 int CynaraUserInit(const uid_t uidAdded, int userType)
55 MessageBuffer sendBuf, retBuf;
57 Serialization::Serialize(sendBuf,
58 static_cast<int>(MasterSecurityModuleCall::CYNARA_USER_INIT),
61 ret = sendToServer(MASTER_SERVICE_SOCKET, sendBuf.Pop(), retBuf);
62 if (ret == SECURITY_MANAGER_API_SUCCESS)
63 Deserialization::Deserialize(retBuf, ret);
68 int CynaraUserRemove(const uid_t uidDeleted)
71 MessageBuffer sendBuf, retBuf;
73 Serialization::Serialize(sendBuf,
74 static_cast<int>(MasterSecurityModuleCall::CYNARA_USER_REMOVE),
77 ret = sendToServer(MASTER_SERVICE_SOCKET, sendBuf.Pop(), retBuf);
78 if (ret == SECURITY_MANAGER_API_SUCCESS)
79 Deserialization::Deserialize(retBuf, ret);
84 int SmackInstallRules(const std::string &appId, const std::string &pkgId,
85 const std::vector<std::string> &pkgContents)
88 MessageBuffer sendBuf, retBuf;
89 Serialization::Serialize(sendBuf,
90 static_cast<int>(MasterSecurityModuleCall::SMACK_INSTALL_RULES),
91 appId, pkgId, 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;
106 Serialization::Serialize(sendBuf,
107 static_cast<int>(MasterSecurityModuleCall::SMACK_UNINSTALL_RULES),
108 appId, pkgId, pkgContents, removePkg);
110 ret = sendToServer(MASTER_SERVICE_SOCKET, sendBuf.Pop(), retBuf);
111 if (ret == SECURITY_MANAGER_API_SUCCESS)
112 Deserialization::Deserialize(retBuf, ret);
117 // Following three requests are just forwarded security-manager API calls
118 // these do not access Privilege DB, so all can be forwarded to Master
119 int PolicyUpdate(const std::vector<policy_entry> &policyEntries, uid_t uid, pid_t pid,
120 const std::string &smackLabel)
123 MessageBuffer sendBuf, retBuf;
125 Serialization::Serialize(sendBuf,
126 static_cast<int>(MasterSecurityModuleCall::POLICY_UPDATE),
127 policyEntries, uid, pid, smackLabel);
129 ret = sendToServer(MASTER_SERVICE_SOCKET, sendBuf.Pop(), retBuf);
130 if (ret == SECURITY_MANAGER_API_SUCCESS)
131 Deserialization::Deserialize(retBuf, ret);
136 int GetConfiguredPolicy(bool forAdmin, const policy_entry &filter, uid_t uid, pid_t pid,
137 const std::string &smackLabel, std::vector<policy_entry> &policyEntries)
140 MessageBuffer sendBuf, retBuf;
142 Serialization::Serialize(sendBuf,
143 static_cast<int>(MasterSecurityModuleCall::GET_CONFIGURED_POLICY),
144 forAdmin, filter, uid, pid, smackLabel);
146 ret = sendToServer(MASTER_SERVICE_SOCKET, sendBuf.Pop(), retBuf);
147 if (ret == SECURITY_MANAGER_API_SUCCESS) {
148 Deserialization::Deserialize(retBuf, ret);
149 if (ret == SECURITY_MANAGER_API_SUCCESS)
150 Deserialization::Deserialize(retBuf, policyEntries);
156 int GetPolicy(const policy_entry &filter, uid_t uid, pid_t pid, const std::string &smackLabel,
157 std::vector<policy_entry> &policyEntries)
160 MessageBuffer sendBuf, retBuf;
162 Serialization::Serialize(sendBuf,
163 static_cast<int>(MasterSecurityModuleCall::GET_POLICY),
164 filter, uid, pid, smackLabel);
166 ret = sendToServer(MASTER_SERVICE_SOCKET, sendBuf.Pop(), retBuf);
167 if (ret == SECURITY_MANAGER_API_SUCCESS) {
168 Deserialization::Deserialize(retBuf, ret);
169 if (ret == SECURITY_MANAGER_API_SUCCESS)
170 Deserialization::Deserialize(retBuf, policyEntries);
176 int PolicyGetDesc(std::vector<std::string> &descriptions)
179 MessageBuffer sendBuf, retBuf;
181 Serialization::Serialize(sendBuf,
182 static_cast<int>(MasterSecurityModuleCall::POLICY_GET_DESC));
184 ret = sendToServer(MASTER_SERVICE_SOCKET, sendBuf.Pop(), retBuf);
185 if (ret == SECURITY_MANAGER_API_SUCCESS) {
186 Deserialization::Deserialize(retBuf, ret);
187 if (ret == SECURITY_MANAGER_API_SUCCESS)
188 Deserialization::Deserialize(retBuf, descriptions);
194 } // namespace MasterReq
195 } // namespace SecurityManager