* @author Bartlomiej Grzelewski (b.grzelewski@samsung.com)
* @version 1.0
*/
-#include <sys/smack.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-
-#include <security-manager.h>
+#include <string>
#include <dpl/log/log.h>
#include <protocols.h>
#include <socket-2-id.h>
namespace CKM {
-namespace {
-int getCredentialsFromSocket(int sock, std::string &res) {
- std::vector<char> result(1);
- socklen_t length = 1;
+int Socket2Id::getPkgIdFromSmack(const std::string &smack, std::string &pkgId) {
+ static const std::string SMACK_PREFIX_APPID = "User::App::";
- if ((0 > getsockopt(sock, SOL_SOCKET, SO_PEERSEC, result.data(), &length))
- && errno != ERANGE)
- {
- LogError("getsockopt failed");
+ if (smack.empty()) {
+ LogError("Smack is empty. Connection will be rejected");
return -1;
}
- result.resize(length);
+ if (smack.compare(0, SMACK_PREFIX_APPID.size(), SMACK_PREFIX_APPID)) {
+ pkgId = "/" + smack;
+ LogDebug("Smack: " << smack << " Was translated to owner id: " << pkgId);
+ return 0;
+ }
+
+ std::string appId = smack.substr(SMACK_PREFIX_APPID.size(), std::string::npos);
- if (0 > getsockopt(sock, SOL_SOCKET, SO_PEERSEC, result.data(), &length)) {
- LogError("getsockopt failed");
+ if (appId.empty()) {
+ LogError("After conversion (smack->pkgId) pkgId is empty. Label: " << appId);
return -1;
}
- result.push_back('\0');
- res = result.data();
- return 0;
-}
-
-int getPkgIdFromSmack(const std::string &smack, std::string &pkgId) {
- pkgId = smack;
+ pkgId = std::move(appId);
+ LogDebug("Smack: " << smack << " Was translated to owner id: " << pkgId);
return 0;
}
-} // namespace anonymous
-
-
int Socket2Id::translate(int sock, std::string &result) {
std::string smack;
std::string pkgId;
return -1;
}
- result = pkgId;
+ result = std::move(pkgId);
return 0;
}
-void Socket2Id::resetCache() {
- m_stringMap.clear();
-}
-
} // namespace CKM