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>
#include <pwd.h>
#include <sys/mount.h>
+#include <sys/stat.h>
#include <sys/types.h>
#include <fcntl.h>
#include <unistd.h>
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();