-// $Id: secure-mount.c 2403 2006-11-24 23:06:08Z dhozac $ --*- c++ -*--
+// $Id: secure-mount.c,v 1.24 2005/03/24 12:45:06 ensc Exp $ --*- c++ -*--
// Copyright (C) 2003 Enrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
//
#include <sys/wait.h>
#include <libgen.h>
#include <signal.h>
-#include <stdlib.h>
#define ENSC_WRAPPERS_FCNTL 1
#define ENSC_WRAPPERS_UNISTD 1
return false;
}
-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) return false;
- else if ((mnt->flag & (MS_BIND|MS_MOVE))) 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)
{
if (!secureChdir(mnt->dst, opt))
return false;
- if (canHandleInternal(mnt)) {
+ if (mnt->flag & (MS_BIND|MS_MOVE)) {
+ 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;
}
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, ',');
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;
} while (*ptr!='\0');
- info->data = data;
return true;
}
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;
- }
+ else if (strcmp(info->type, "devpts")==0) info->mask |= MS_NODEV;
if (col) *col = err_col;
if (!transformOptionList(info,col)) return prFAIL;
.src = 0,
.dst = 0,
.type = 0,
- .flag = MS_NODEV,
+ .flag = 0,
.xflag = 0,
.data = 0,
};
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;
}