Map System subdomains to System 38/89338/2
authorKyungwook Tak <k.tak@samsung.com>
Fri, 23 Sep 2016 06:32:07 +0000 (15:32 +0900)
committerDong Sun Lee <ds73.lee@samsung.com>
Mon, 26 Sep 2016 01:40:34 +0000 (18:40 -0700)
e.g., System::Privileged -> System
This is for sharing data between system services regardless subdomain
like System::Privileged which has special subdomain label for onlycap

Change-Id: Ibd6f99c8ced3b7bbb3ba3da6e7bd7ee39cd2bfe2
Signed-off-by: Kyungwook Tak <k.tak@samsung.com>
src/manager/main/socket-2-id-mockup.cpp
src/manager/main/socket-2-id-wrapper.cpp
src/manager/main/socket-2-id.cpp
src/manager/main/socket-2-id.h

index 6b21a32..222976d 100644 (file)
@@ -68,6 +68,8 @@ int Socket2Id::translate(int sock, std::string &result)
        if (0 > getPkgIdFromSmack(smack, pkgId))
                return -1;
 
+       mapToDomainLabel(pkgId);
+
        result = std::move(pkgId);
        return 0;
 }
index 3d30c4b..2eb9f36 100644 (file)
@@ -81,6 +81,8 @@ int Socket2Id::translate(int sock, std::string &result)
                pkgId = "/" + smack;
        }
 
+       mapToDomainLabel(pkgId);
+
        result = pkgId;
        m_stringMap.emplace(std::move(smack), std::move(pkgId));
        return 0;
index a9efe1b..b6f43c0 100644 (file)
@@ -70,6 +70,18 @@ int Socket2Id::getCredentialsFromSocket(int sock, std::string &res)
        return assignToString(result, length, res);
 }
 
+void Socket2Id::mapToDomainLabel(std::string &label)
+{
+       static const std::string subdomainSep = "::";
+       static const auto systemLabelLen = strlen(OWNER_ID_SYSTEM);
+
+       if (label.length() > systemLabelLen + subdomainSep.length() &&
+               label.compare(0, systemLabelLen, OWNER_ID_SYSTEM) == 0 &&
+               label.compare(systemLabelLen, subdomainSep.length(), subdomainSep) == 0) {
+               label = OWNER_ID_SYSTEM;
+       }
+}
+
 void Socket2Id::resetCache()
 {
        m_stringMap.clear();
index afa863a..3e970c2 100644 (file)
@@ -36,6 +36,7 @@ public:
 
 private:
        int getCredentialsFromSocket(int sock, std::string &res);
+       void mapToDomainLabel(std::string &label);
 
        typedef std::map<std::string, std::string> StringMap;
        StringMap m_stringMap;