Add support for IATTR_WRITE.
[util-vserver.git] / src / secure-mount.c
index dab02d2..a76f7a0 100644 (file)
@@ -52,6 +52,7 @@
 #include <sys/wait.h>
 #include <libgen.h>
 #include <signal.h>
+#include <stdlib.h>
 
 #define ENSC_WRAPPERS_FCNTL    1
 #define ENSC_WRAPPERS_UNISTD   1
@@ -69,6 +70,7 @@ struct MountInfo {
     unsigned long      xflag;
     unsigned long      mask;
     char *             data;
+    char *             data_parsed;
 };
 
 struct Options {
@@ -120,7 +122,7 @@ static struct FstabOption {
     unsigned long const        xflag;
     bool const                 is_dflt;
 } const FSTAB_OPTIONS[] = {
-  { "defaults",   0,             (MS_RDONLY|MS_NOSUID|MS_NODEV|MS_NOEXEC|
+  { "defaults",   MS_NODEV,      (MS_RDONLY|MS_NOSUID|MS_NODEV|MS_NOEXEC|
                                  MS_SYNCHRONOUS), 0, false },
   { "rbind",      MS_BIND|MS_REC, MS_BIND|MS_REC,  0, false },
   { "bind",       MS_BIND,        MS_BIND,         0, false },
@@ -277,8 +279,8 @@ updateMtab(struct MountInfo const *mnt, struct Options const *opt)
     goto err0;
   }
 
-  if (flock(fd, LOCK_EX)==-1) {
-    perror("secure-mount: flock()");
+  if (lockf(fd, F_LOCK, 0)==-1) {
+    perror("secure-mount: lockf()");
     goto err1;
   }
 
@@ -430,7 +432,7 @@ mountSingle(struct MountInfo const *mnt, struct Options const *opt)
   if (canHandleInternal(mnt)) {
     if (mount(mnt->src, ".",
              mnt->type ? mnt->type : "",
-             mnt->flag,  mnt->data)==-1) {
+             mnt->flag,  mnt->data_parsed)==-1) {
       perror("secure-mount: mount()");
       return false;
     }
@@ -461,6 +463,8 @@ static bool
 transformOptionList(struct MountInfo *info, size_t UNUSED *col)
 {
   char const *                 ptr = info->data;
+  char *                       data = malloc(strlen(info->data));
+  char *                       dst = data;
 
   do {
     char const *               pos = strchr(ptr, ',');
@@ -475,6 +479,13 @@ transformOptionList(struct MountInfo *info, size_t UNUSED *col)
       info->mask  |=  opt->mask;
       info->xflag |=  opt->xflag;
     }
+    else {
+      if (dst != data)
+        *(dst++) = ',';
+      strncpy(dst, ptr, pos-ptr);
+      dst += pos - ptr;
+      *dst = '\0';
+    }
 
     if (*pos!='\0')
       ptr = pos+1;
@@ -483,6 +494,7 @@ transformOptionList(struct MountInfo *info, size_t UNUSED *col)
 
   } while (*ptr!='\0');
 
+  info->data_parsed = data;
   return true;
 }
 
@@ -645,7 +657,7 @@ int main(int argc, char *argv[])
     .src         = 0,
     .dst         = 0,
     .type        = 0,
-    .flag        = 0,
+    .flag        = MS_NODEV,
     .xflag      = 0,
     .data        = 0,
   };
@@ -685,7 +697,7 @@ int main(int argc, char *argv[])
       default          :
        WRITE_MSG(2, "Try '");
        WRITE_STR(2, argv[0]);
-       WRITE_MSG(2, " --help\" for more information.\n");
+       WRITE_MSG(2, " --help' for more information.\n");
        return EXIT_FAILURE;
        break;
     }