2 * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd All Rights Reserved
4 * Contact: Bartlomiej Grzelewski <b.grzelewski@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
18 * Security Manager library header
21 * @file client-security-manager.cpp
22 * @author Pawel Polawski (p.polawski@samsung.com)
24 * @brief This file contain client side implementation of security-manager API
30 #include <dpl/log/log.h>
31 #include <dpl/exception.h>
33 #include <message-buffer.h>
34 #include <client-common.h>
35 #include <protocols.h>
37 #include <security-manager.h>
38 #include <security-server.h>
42 int security_manager_app_inst_req_new(app_inst_req **pp_req)
45 return SECURITY_MANAGER_ERROR_INPUT_PARAM;
48 *pp_req = new app_inst_req;
49 } catch (std::bad_alloc& ex) {
50 return SECURITY_MANAGER_ERROR_MEMORY;
54 return SECURITY_MANAGER_SUCCESS;
58 void security_manager_app_inst_req_free(app_inst_req *p_req)
64 int security_manager_app_inst_req_set_app_id(app_inst_req *p_req, const char *app_id)
66 if (!p_req || !app_id)
67 return SECURITY_MANAGER_ERROR_INPUT_PARAM;
69 p_req->appId = app_id;
71 return SECURITY_MANAGER_SUCCESS;
75 int security_manager_app_inst_req_set_pkg_id(app_inst_req *p_req, const char *pkg_id)
77 if (!p_req || !pkg_id)
78 return SECURITY_MANAGER_ERROR_INPUT_PARAM;
80 p_req->pkgId = pkg_id;
82 return SECURITY_MANAGER_SUCCESS;
86 int security_manager_app_inst_req_add_allowed_user(app_inst_req *p_req, const uid_t user_id)
89 return SECURITY_MANAGER_ERROR_INPUT_PARAM;
91 p_req->allowedUsers.push_back(user_id);
93 return SECURITY_MANAGER_SUCCESS;
97 int security_manager_app_inst_req_add_privilege(app_inst_req *p_req, const char *privilege)
99 if (!p_req || !privilege)
100 return SECURITY_MANAGER_ERROR_INPUT_PARAM;
102 p_req->privileges.push_back(privilege);
104 return SECURITY_MANAGER_SUCCESS;
108 int security_manager_app_inst_req_add_path(app_inst_req *p_req, const char *path, const int path_type)
110 if (!p_req || !path || (path_type < 0) || (path_type >= SECURITY_MANAGER_ENUM_END))
111 return SECURITY_MANAGER_ERROR_INPUT_PARAM;
113 p_req->appPaths.push_back(std::make_pair(path, path_type));
115 return SECURITY_MANAGER_SUCCESS;
119 int security_manager_app_install(const app_inst_req *p_req)
121 using namespace SecurityServer;
122 MessageBuffer send, recv;
124 LogDebug("app_install() called");
126 return try_catch([&] {
127 //checking parameters
129 return SECURITY_MANAGER_ERROR_INPUT_PARAM;
130 if (p_req->appId.empty() || p_req->pkgId.empty())
131 return SECURITY_MANAGER_ERROR_REQ_NOT_COMPLETE;
133 //put data into buffer
134 Serialization::Serialize(send, (int)SecurityModuleCall::APP_INSTALL);
135 Serialization::Serialize(send, p_req->appId);
136 Serialization::Serialize(send, p_req->pkgId);
137 Serialization::Serialize(send, p_req->allowedUsers);
138 Serialization::Serialize(send, p_req->privileges);
139 Serialization::Serialize(send, p_req->appPaths);
141 //send buffer to server
142 int retval = sendToServer(SERVICE_SOCKET_INSTALLER, send.Pop(), recv);
143 if (retval != SECURITY_SERVER_API_SUCCESS) {
144 LogDebug("Error in sendToServer. Error code: " << retval);
145 return SECURITY_MANAGER_ERROR_UNKNOWN;
148 //receive response from server
149 Deserialization::Deserialize(recv, retval);
150 if (retval != SECURITY_SERVER_API_SUCCESS)
151 return SECURITY_MANAGER_ERROR_UNKNOWN;
153 return SECURITY_MANAGER_SUCCESS;;
158 int security_manager_app_uninstall(const app_inst_req *p_req)
160 using namespace SecurityServer;
161 MessageBuffer send, recv;
163 LogDebug("app_uninstall() called");
165 return try_catch([&] {
166 //checking parameters
168 return SECURITY_MANAGER_ERROR_INPUT_PARAM;
169 if (p_req->appId.empty())
170 return SECURITY_MANAGER_ERROR_REQ_NOT_COMPLETE;
172 //put data into buffer
173 Serialization::Serialize(send, (int)SecurityModuleCall::APP_UNINSTALL);
174 Serialization::Serialize(send, p_req->appId);
176 //send buffer to server
177 int retval = sendToServer(SERVICE_SOCKET_INSTALLER, send.Pop(), recv);
178 if (retval != SECURITY_SERVER_API_SUCCESS) {
179 LogDebug("Error in sendToServer. Error code: " << retval);
180 return SECURITY_MANAGER_ERROR_UNKNOWN;
183 //receive response from server
184 Deserialization::Deserialize(recv, retval);
185 if (retval != SECURITY_SERVER_API_SUCCESS)
186 return SECURITY_MANAGER_ERROR_UNKNOWN;
188 return SECURITY_MANAGER_SUCCESS;;