mnt: add original_uid to directories created as new root by nsjail
authorRobert Swiecki <robert@swiecki.net>
Wed, 16 May 2018 13:50:31 +0000 (15:50 +0200)
committerRobert Swiecki <robert@swiecki.net>
Wed, 16 May 2018 13:50:31 +0000 (15:50 +0200)
mnt.cc

diff --git a/mnt.cc b/mnt.cc
index 4186022..a6cd103 100644 (file)
--- a/mnt.cc
+++ b/mnt.cc
@@ -287,28 +287,45 @@ static std::unique_ptr<std::string> getDir(nsjconf_t* nsjconf, const char* name)
        std::unique_ptr<std::string> dir(new std::string);
 
        dir->assign("/run/user/")
-           .append(std::to_string(nsjconf->orig_uid))
            .append("/nsjail.")
+           .append(std::to_string(nsjconf->orig_uid))
+           .append(".")
            .append(name);
        if (mkdirAndTest(*dir)) {
                return dir;
        }
-       dir->assign("/tmp/nsjail.").append(name);
+       dir->assign("/tmp/nsjail.")
+           .append(std::to_string(nsjconf->orig_uid))
+           .append(".")
+           .append(name);
        if (mkdirAndTest(*dir)) {
                return dir;
        }
        const char* tmp = getenv("TMPDIR");
        if (tmp) {
-               dir->assign(tmp).append("/").append("nsjail.").append(name);
+               dir->assign(tmp)
+                   .append("/")
+                   .append("nsjail.")
+                   .append(std::to_string(nsjconf->orig_uid))
+                   .append(".")
+                   .append(name);
                if (mkdirAndTest(*dir)) {
                        return dir;
                }
        }
-       dir->assign("/dev/shm/nsjail.").append(name);
+       dir->assign("/dev/shm/nsjail.")
+           .append(std::to_string(nsjconf->orig_uid))
+           .append(".")
+           .append(name);
        if (mkdirAndTest(*dir)) {
                return dir;
        }
-       dir->assign("/tmp/nsjail.").append(name).append(".").append(std::to_string(util::rnd64()));
+       dir->assign("/tmp/nsjail.")
+           .append(std::to_string(nsjconf->orig_uid))
+           .append(".")
+           .append(name)
+           .append(".")
+           .append(std::to_string(util::rnd64()));
        if (mkdirAndTest(*dir)) {
                return dir;
        }