Don't put empty lines in generated Smack policy 76/104776/4
authorRafal Krypa <r.krypa@samsung.com>
Wed, 14 Dec 2016 08:49:12 +0000 (09:49 +0100)
committerGerrit Code Review <gerrit@review.vlan103.tizen.org>
Tue, 27 Dec 2016 11:06:10 +0000 (03:06 -0800)
Empty lines in Smack policy are invalid. In most cases we get away with
them as kernel manages to filter them out and ignore.
There are however some nasty corner cases causing kernel to reject policy
with an empty line.

This change removes the cause for empty lines appearing in policy, updates
existing policy and modifies policy generation code to skip empty lines
by default, if they appear in policy templates again.

Change-Id: Id875523d2269ff8466898e9bef9b2a0b81387378
Signed-off-by: Rafal Krypa <r.krypa@samsung.com>
policy/pkg-rules-template.smack
policy/updates/update-policy-to-v5.sh [new file with mode: 0755]
src/common/smack-rules.cpp

index 0ec8b1d8f8772f1c02c42e7a6e73fbce50b21266..53cd419710cddae5fe4e292eb2c8db9964532e56 100644 (file)
@@ -7,4 +7,3 @@ System::Privileged ~PATH_SHARED_RO~ rwxat
 User ~PATH_RW~ rwxat
 User ~PATH_RO~ rwxat
 User ~PATH_SHARED_RO~ rwxat
-
diff --git a/policy/updates/update-policy-to-v5.sh b/policy/updates/update-policy-to-v5.sh
new file mode 100755 (executable)
index 0000000..d2b5d97
--- /dev/null
@@ -0,0 +1,9 @@
+#!/bin/sh -e
+
+export PATH=/sbin:/usr/sbin:/bin:/usr/bin
+
+. /etc/tizen-platform.conf
+
+systemctl stop security-manager.service security-manager.socket
+sed -r '/^\s*$/d' -i $TZ_SYS_VAR/security-manager/rules/* $TZ_SYS_VAR/security-manager/rules-merged/*
+systemctl start security-manager.service security-manager.socket
index 3629afbfe88ab1de5709b7de5dc0d37795503db0..a3207e40234107808dcaebf1de292f1035a01bed 100644 (file)
@@ -183,9 +183,9 @@ void SmackRules::addFromTemplateFile(
         ThrowMsg(SmackException::FileError, "Cannot open rules template file: " << templatePath);
     }
 
-    while (std::getline(templateRulesFile, line)) {
-        templateRules.push_back(line);
-    }
+    while (std::getline(templateRulesFile, line))
+        if (!line.empty())
+            templateRules.push_back(line);
 
     if (templateRulesFile.bad()) {
         LogError("Error reading template file: " << templatePath);