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-mockup.cpp
18 * @author Bartlomiej Grzelewski (b.grzelewski@samsung.com)
21 #include <sys/smack.h>
22 #include <sys/types.h>
23 #include <sys/socket.h>
25 #include <security-manager.h>
27 #include <dpl/log/log.h>
28 #include <protocols.h>
29 #include <socket-2-id.h>
34 int getCredentialsFromSocket(int sock, std::string &res) {
35 std::vector<char> result(1);
38 if ((0 > getsockopt(sock, SOL_SOCKET, SO_PEERSEC, result.data(), &length))
41 LogError("getsockopt failed");
45 result.resize(length);
47 if (0 > getsockopt(sock, SOL_SOCKET, SO_PEERSEC, result.data(), &length)) {
48 LogError("getsockopt failed");
52 result.push_back('\0');
57 int getPkgIdFromSmack(const std::string &smack, std::string &pkgId) {
62 } // namespace anonymous
65 int Socket2Id::translate(int sock, std::string &result) {
69 if (0 > getCredentialsFromSocket(sock, smack)) {
73 if (0 > getPkgIdFromSmack(smack, pkgId)) {
81 void Socket2Id::resetCache() {