2 * Copyright (c) 2015 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #include <cynara-creds-gdbus.h>
18 #include <cynara-session.h>
19 #include <app_manager.h>
20 #include <package_manager.h>
22 #include "PeerCreds.h"
24 ctx::Credentials::Credentials(char *pkgId, char *cli, char *sess, char *usr) :
32 ctx::Credentials::~Credentials()
40 bool ctx::peer_creds::get(GDBusConnection *connection, const char *uniqueName, const char *cookie, ctx::Credentials **creds)
44 char *packageId = NULL;
49 int err = cynara_creds_gdbus_get_pid(connection, uniqueName, &pid);
50 IF_FAIL_RETURN_TAG(err == CYNARA_API_SUCCESS, false, _E, "Peer credentialing failed");
52 session = cynara_session_from_pid(pid);
53 IF_FAIL_CATCH_TAG(session, _E, "Peer credentialing failed");
55 err = cynara_creds_gdbus_get_client(connection, uniqueName, CLIENT_METHOD_DEFAULT, &client);
56 IF_FAIL_CATCH_TAG(err == CYNARA_API_SUCCESS, _E, "Peer credentialing failed");
58 err = cynara_creds_gdbus_get_user(connection, uniqueName, USER_METHOD_DEFAULT, &user);
59 IF_FAIL_CATCH_TAG(err == CYNARA_API_SUCCESS, _E, "Peer credentialing failed");
61 app_manager_get_app_id(pid, &app_id);
62 package_manager_get_package_id_by_app_id(app_id, &packageId);
63 _D("AppId: %s, PackageId: %s", app_id, packageId);
66 *creds = new(std::nothrow) Credentials(packageId, client, session, user);
67 IF_FAIL_CATCH_TAG(*creds, _E, "Memory allocation failed");