#include <signal.h>
#define ENSC_WRAPPERS_FCNTL 1
+#define ENSC_WRAPPERS_UNISTD 1
#include <wrappers.h>
#define MNTPOINT "/etc"
char const * type;
unsigned long flag;
unsigned long xflag;
+ unsigned long mask;
char * data;
};
if (mnt->flag & MS_BIND) argv[idx++] = "--bind";
else if (mnt->flag & MS_MOVE) argv[idx++] = "--move";
- if (mnt->data &&
+ argv[idx++] = "-o";
+ if (mnt->data && *mnt->data &&
strcmp(mnt->data, "defaults")!=0) {
- argv[idx++] = "-o";
- argv[idx++] = mnt->data;
+ if (mnt->mask & MS_NODEV)
+ argv[idx++] = mnt->data;
+ else {
+ char * tmp = alloca(strlen(mnt->data) + sizeof("nodev,"));
+ strcpy(tmp, "nodev,");
+ strcat(tmp, mnt->data);
+ argv[idx++] = tmp;
+ }
}
+ else
+ argv[idx++] = "nodev";
if (mnt->type) {
argv[idx++] = "-t";
}
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);
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;
}
if (opt!=0) {
info->flag &= ~opt->mask;
info->flag |= opt->flag;
+ info->mask |= opt->mask;
info->xflag |= opt->xflag;
}
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;
+ }
- info->flag = 0;
- info->xflag = 0;
if (col) *col = err_col;
if (!transformOptionList(info,col)) return prFAIL;
if (info->xflag & XFLAG_NOAUTO) return prIGNORE;
buf[len++] = ':';
len += utilvserver_fmt_uint(buf+len, col_nr);
WRITE_STR(fd, fname);
- write(fd, buf, len);
+ Vwrite(fd, buf, len);
}
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)) {