Don't enable mount namespace code when the config file is missing or empty 28/162328/3
authorRafal Krypa <r.krypa@samsung.com>
Thu, 30 Nov 2017 08:38:45 +0000 (09:38 +0100)
committerRafal Krypa <r.krypa@samsung.com>
Thu, 30 Nov 2017 12:16:04 +0000 (13:16 +0100)
Function isMountNamespaceEnabled will read the privilege-mount.list config
file and return false when reading of that file fails or when it doesn't
contain any proper configuration entries.

Change-Id: I20fabefde1523e204c02e5ab8eb8bbdd532a8b4f
Signed-off-by: Rafal Krypa <r.krypa@samsung.com>
src/common/mount-namespace.cpp

index 63f9dc6..88266c5 100644 (file)
@@ -25,6 +25,7 @@
 
 #include <pwd.h>
 #include <sys/mount.h>
+#include <sys/stat.h>
 #include <sys/types.h>
 #include <fcntl.h>
 #include <unistd.h>
@@ -120,7 +121,25 @@ std::string getUserAppMountPointPath(uid_t uid, const std::string &appName)
 bool isMountNamespaceEnabled(void)
 {
     auto getStatus = []() -> bool {
-        return (access(SELF_MOUNT_NAMESPACE.c_str(), F_OK) != -1) ? true : false;
+        try {
+            if (access(SELF_MOUNT_NAMESPACE.c_str(), F_OK) == -1)
+                return false;
+
+            struct stat st;
+            if (stat(Config::PRIVILEGE_MOUNT_LIST_FILE.c_str(), &st) == -1)
+                return false;
+            if (st.st_size == 0)
+                return false;
+
+            // File exists and is not empty.
+            // Let's check if it contains any relevant configuration entries.
+            if (getPrivilegePathMap(getuid()).empty())
+                return false;
+        } catch (...) {
+            return false;
+        }
+
+        return true;
     };
 
     static bool isMountNamespaceEnabled = getStatus();