s!/etc/slackware-release!/etc/slackware-version! (reported by bubulak)
[util-vserver.git] / util-vserver / src / secure-mount.c
index 37baa3c..c3a2b48 100644 (file)
@@ -54,6 +54,7 @@
 #include <signal.h>
 
 #define ENSC_WRAPPERS_FCNTL    1
+#define ENSC_WRAPPERS_UNISTD   1
 #include <wrappers.h>
 
 #define MNTPOINT       "/etc"
@@ -398,6 +399,27 @@ secureChdir(char const *dir, struct Options const *opt)
 }
 
 static bool
+canHandleInternal(struct MountInfo const *mnt)
+{
+  static char const *  FS[] = {
+    "tmpfs", "sysfs", "proc", "sockfs", "pipefs", "futexfs",
+    "inotifyfs", "devpts", "ext3", "ext2", "ramfs",
+    "hugetlbfs", "usbfs", "binfmt_misc",
+    0
+  };
+  char const **                i;
+  
+  if (mnt!=0)                                  return false;
+  else if ((mnt->flag & (MS_BIND|MS_MOVE))!=0) return true;
+  else if (mnt->type==0)                       return false;
+
+  for (i=FS+0; *i!=0; ++i)
+    if (strcmp(mnt->type, *i)==0) return true;
+
+  return false;
+}
+
+static bool
 mountSingle(struct MountInfo const *mnt, struct Options const *opt)
 {
   assert(mnt->dst!=0);
@@ -405,10 +427,13 @@ mountSingle(struct MountInfo const *mnt, struct Options const *opt)
   if (!secureChdir(mnt->dst, opt))
     return false;
 
-  if (mnt->flag & (MS_BIND|MS_MOVE)) {
+  if (canHandleInternal(mnt)) {
+    unsigned long      flag = mnt->flag;
+    if ((flag & MS_NODEV)!=0) flag |= MS_NODEV;
+    
     if (mount(mnt->src, ".",
              mnt->type ? mnt->type : "",
-             mnt->flag,  mnt->data)==-1) {
+             flag,  mnt->data)==-1) {
       perror("secure-mount: mount()");
       return false;
     }
@@ -490,12 +515,17 @@ static enum {prDOIT, prFAIL, prIGNORE}
   info->data = buf;
   MOVE_TO_NEXT_FIELD(buf, true);
 
-  if (strcmp(info->type, "swap")==0) return prIGNORE;
-  if (strcmp(info->type, "none")==0) info->type = 0;
-
   info->flag  = MS_NODEV;
   info->mask  = 0;
   info->xflag = 0;
+
+  if      (strcmp(info->type, "swap")  ==0) return prIGNORE;
+  else if (strcmp(info->type, "none")  ==0) info->type  = 0;
+  else if (strcmp(info->type, "devpts")==0) {
+    info->mask |=  MS_NODEV;
+    info->flag &= ~MS_NODEV;
+  }
+
   if (col) *col = err_col;
   if (!transformOptionList(info,col)) return prFAIL;
   if (info->xflag & XFLAG_NOAUTO)     return prIGNORE;
@@ -515,7 +545,7 @@ showFstabPosition(int fd, char const *fname, size_t line_nr, size_t col_nr)
   buf[len++] = ':';
   len += utilvserver_fmt_uint(buf+len, col_nr);
   WRITE_STR(fd, fname);
-  write(fd, buf, len);
+  Vwrite(fd, buf, len);
 }
 
 
@@ -567,7 +597,7 @@ mountFstab(struct Options const *opt)
        case prIGNORE   :  break;
        case prDOIT     : {
          bool          is_rootfs = (strcmp(mnt.dst, "/")==0);
-         chdir("/");
+         Echdir("/");
          if (( is_rootfs && opt->rootfs==rfsNO) ||
              (!is_rootfs && opt->rootfs==rfsONLY)) { /* ignore the entry */ }
          else if (!mountSingle(&mnt, opt)) {