Prepare libcynara-creds-dbus for implementation
[platform/core/security/cynara.git] / src / helpers / creds-dbus / creds-dbus.cpp
1 /*
2  *  Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  *  Licensed under the Apache License, Version 2.0 (the "License");
5  *  you may not use this file except in compliance with the License.
6  *  You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  *  Unless required by applicable law or agreed to in writing, software
11  *  distributed under the License is distributed on an "AS IS" BASIS,
12  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  *  See the License for the specific language governing permissions and
14  *  limitations under the License
15  */
16 /*
17  * @file        creds-dbus.cpp
18  * @author      Radoslaw Bartosiak <r.bartosiak@samsung.com>
19  * @author      Aleksander Zdyb <a.zdyb@partner.samsung.com>
20  * @author      Lukasz Wojciechowski <l.wojciechow@partner.samsung.com>
21  * @version     1.0
22  * @brief       Implementation of external libcynara-creds-dbus API
23  */
24
25
26 #include <attributes/attributes.h>
27
28 #include <creds-dbus-inner.h>
29
30 #include <cynara-client-error.h>
31 #include <cynara-creds-commons.h>
32 #include <cynara-creds-dbus.h>
33
34 CYNARA_API
35 int cynara_creds_dbus_get_client(DBusConnection *connection, const char *uniqueName,
36                                  enum cynara_client_creds method, char **client) {
37     if (connection == nullptr || uniqueName == nullptr || client == nullptr)
38         return CYNARA_API_INVALID_PARAM;
39
40     switch (method) {
41         case cynara_client_creds::CLIENT_METHOD_SMACK:
42             return getClientSmackLabel(connection, uniqueName, client);
43         case cynara_client_creds::CLIENT_METHOD_PID:
44             return getClientPid(connection, uniqueName, client);
45         default:
46             return CYNARA_API_METHOD_NOT_SUPPORTED;
47     }
48 }
49
50 CYNARA_API
51 int cynara_creds_dbus_get_user(DBusConnection *connection, const char *uniqueName,
52                                enum cynara_user_creds method, char **user) {
53     if (connection == nullptr || uniqueName == nullptr || user == nullptr)
54         return CYNARA_API_INVALID_PARAM;
55
56     switch (method) {
57         case cynara_user_creds::USER_METHOD_UID:
58             return getUserId(connection, uniqueName, user);
59         case cynara_user_creds::USER_METHOD_GID:
60             return getUserGid(connection, uniqueName, user);
61         default:
62             return CYNARA_API_METHOD_NOT_SUPPORTED;
63     }
64 }
65
66 CYNARA_API
67 int cynara_creds_dbus_get_pid(DBusConnection *connection, const char *uniqueName, pid_t *pid) {
68     if (connection == nullptr || uniqueName == nullptr)
69         return CYNARA_API_INVALID_PARAM;
70
71     return getPid(connection, uniqueName, pid);
72 }