Adjust security_server_app_has_privilege to Tizen 3.0 model.
[platform/core/security/security-manager.git] / src / server / client / client-app-permissions.cpp
1 /*
2  *  Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  *  Contact: Bartlomiej Grzelewski <b.grzelewski@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        client-app-permissions.cpp
20  * @author      Pawel Polawski (pawel.polawski@partner.samsung.com)
21  * @version     1.0
22  * @brief       This file contains implementation of
23  *              security_server_app_has_privilege function
24  */
25
26
27 #include <dpl/log/log.h>
28 #include <dpl/exception.h>
29
30 #include <message-buffer.h>
31 #include <client-common.h>
32 #include <protocols.h>
33
34 #include <privilege-control.h>
35 #include <security-server.h>
36
37 SECURITY_SERVER_API
38 int security_server_app_has_privilege(const char *app_label,
39                                       app_type_t app_type,
40                                       const char *privilege_name,
41                                       int *result)
42 {
43     using namespace SecurityServer;
44     MessageBuffer send, recv;
45
46     LogDebug("security_server_app_has_privilege() called");
47
48     try {
49         if ((NULL == app_label) || (strlen(app_label) == 0)) {
50             LogError("app_id is NULL or empty");
51             return SECURITY_SERVER_API_ERROR_INPUT_PARAM;
52         }
53         if ((NULL == privilege_name) || (strlen(privilege_name) == 0)) {
54             LogError("privilege_name is NULL or empty");
55             return SECURITY_SERVER_API_ERROR_INPUT_PARAM;
56         }
57         if (NULL == result) {
58             LogError("result is NULL");
59             return SECURITY_SERVER_API_ERROR_INPUT_PARAM;
60         }
61
62         LogDebug("app_label: " << app_label);
63         LogDebug("app_type: " << static_cast<int>(app_type));
64         LogDebug("privilege_name: " << privilege_name);
65
66         //put data into buffer
67         Serialization::Serialize(send, static_cast<int>(PrivilegeCheckHdrs::CHECK_GIVEN_APP));
68         Serialization::Serialize(send, std::string(app_label));
69         Serialization::Serialize(send, static_cast<int>(app_type));
70         Serialization::Serialize(send, std::string(privilege_name));
71
72         //send buffer to server
73         int apiResult = sendToServer(SERVICE_SOCKET_APP_PRIVILEGE_BY_NAME, send.Pop(), recv);
74         if (apiResult != SECURITY_SERVER_API_SUCCESS) {
75             LogError("Error in sendToServer. Error code: " << apiResult);
76             return apiResult;
77         }
78
79         //receive response from server
80         Deserialization::Deserialize(recv, apiResult);
81         if (apiResult == SECURITY_SERVER_API_SUCCESS) {
82             Deserialization::Deserialize(recv, *result);
83         }
84         return apiResult;
85
86     } catch (MessageBuffer::Exception::Base &e) {
87         LogError("SecurityServer::MessageBuffer::Exception " << e.DumpToString());
88     } catch (std::exception &e) {
89         LogError("STD exception " << e.what());
90     } catch (...) {
91         LogError("Unknown exception occured");
92     }
93
94     return SECURITY_SERVER_API_ERROR_UNKNOWN;
95 }