2 * Copyright (c) 2000 - 2015 Samsung Electronics Co., Ltd All Rights Reserved
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 * @file socket-2-id-wrapper.cpp
18 * @author Bartlomiej Grzelewski (b.grzelewski@samsung.com)
23 #include <security-manager.h>
25 #include <dpl/log/log.h>
26 #include <protocols.h>
27 #include <socket-2-id.h>
31 int Socket2Id::getPkgIdFromSmack(const std::string &smack, std::string &pkgId) {
33 // Conversion from smack label to pkgId should be done
34 // by security-manager. Current version of security-manager
35 // does not support this feature yet.
37 static const std::string SMACK_PREFIX_APPID = "User::App::";
40 LogError("Smack is empty. Connection will be rejected");
44 if (smack.compare(0, SMACK_PREFIX_APPID.size(), SMACK_PREFIX_APPID)) {
46 LogDebug("Smack: " << smack << " Was translated to owner id: " << pkgId);
50 std::string appId = smack.substr(SMACK_PREFIX_APPID.size(), std::string::npos);
54 if (0 > security_manager_get_app_pkgid(&pkg, appId.c_str())) {
55 LogError("Error in security_manager_get_app_pkgid");
60 LogError("PkgId could not be NULL");
66 LogDebug("Smack: " << smack << " Was translated to owner id: " << pkgId);
70 int Socket2Id::translate(int sock, std::string &result) {
73 if (0 > getCredentialsFromSocket(sock, smack)) {
77 StringMap::iterator it = m_stringMap.find(smack);
79 if (it != m_stringMap.end()) {
85 if (0 > getPkgIdFromSmack(smack, pkgId)) {
90 m_stringMap.emplace(std::move(smack), std::move(pkgId));