Generate distinct Smack labels for appId and pkgId 42/35042/10
authorRafal Krypa <r.krypa@samsung.com>
Fri, 27 Feb 2015 16:37:22 +0000 (17:37 +0100)
committerRafal Krypa <r.krypa@samsung.com>
Mon, 2 Mar 2015 15:19:55 +0000 (16:19 +0100)
Stop hard-wiring Smack labels to "User".
Proper unique labels will be generated:
- "User::App::$appid" for appId
- "User::Pkg::$pkgid" for pkgId

Generated rules are also validated against Smack restrictions for labels.
This imposes the following limitations on appId and pkgId values:
- length up to 244 characters (255 minus prefix length)
- non-printable ASCII characters and space are not allowed
- other prohibited characters: slash, backslash, single quote, double quote

Change-Id: Ib60b1f6fae785919542b2e749bceabbea0b9a89b
Signed-off-by: Rafal Krypa <r.krypa@samsung.com>
src/common/smack-labels.cpp

index feef9f7..0294a42 100644 (file)
@@ -168,20 +168,32 @@ void setupCorrectPath(const std::string &pkgId, const std::string &appId, const
 
 std::string generateAppNameFromLabel(const std::string &label)
 {
-    //TODO: Fix when a label generating mechanism is ready
-    return label;
+    static const char prefix[] = "User::App::";
+
+    if (label.compare(0, sizeof(prefix) - 1, prefix))
+        ThrowMsg(SmackException::InvalidLabel, "Cannot extract appId from Smack label " << label);
+
+    return label.substr(sizeof(prefix) - 1);
 }
 
 std::string generateAppLabel(const std::string &appId)
 {
-    (void) appId;
-    return "User";
+    std::string label = "User::App::" + appId;
+
+    if (smack_label_length(label.c_str()) <= 0)
+        ThrowMsg(SmackException::InvalidLabel, "Invalid Smack label generated from appId " << appId);
+
+    return label;
 }
 
 std::string generatePkgLabel(const std::string &pkgId)
 {
-    (void) pkgId;
-    return "User";
+    std::string label = "User::Pkg::" + pkgId;
+
+    if (smack_label_length(label.c_str()) <= 0)
+        ThrowMsg(SmackException::InvalidLabel, "Invalid Smack label generated from pkgId " << pkgId);
+
+    return label;
 }
 
 } // namespace SmackLabels