X-Git-Url: http://git.linux-vserver.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=util-vserver%2Fsrc%2Fsecure-mount.c;h=7a48ff3e893889ab1135530fc7ec0c820e5c09f0;hb=fa621d5c89d5b57979be7cda3cb0cd5ca9732631;hp=34af02f4fad1581ce64e900ef9fdfeb07417e2fb;hpb=4dbf87141db7f6533058d9995593221b6a8f5ceb;p=util-vserver.git diff --git a/util-vserver/src/secure-mount.c b/util-vserver/src/secure-mount.c index 34af02f..7a48ff3 100644 --- a/util-vserver/src/secure-mount.c +++ b/util-vserver/src/secure-mount.c @@ -48,6 +48,7 @@ #include #include #include +#include #define MNTPOINT "/etc" @@ -77,6 +78,7 @@ struct Options { #define OPTION_FSTAB 1027 #define OPTION_CHROOT 1028 #define OPTION_SECURE 1029 +#define OPTION_RBIND 1030 static struct option const CMDLINE_OPTIONS[] = { @@ -88,15 +90,21 @@ CMDLINE_OPTIONS[] = { { "fstab", required_argument, 0, OPTION_FSTAB }, { "chroot", required_argument, 0, OPTION_CHROOT }, { "secure", no_argument, 0, OPTION_SECURE }, + { "rbind", no_argument, 0, OPTION_RBIND }, { 0, 0, 0, 0 } }; +#ifndef MS_REC +# define MS_REC 0x4000 +#endif + static struct FstabOptions { char const * const opt; unsigned long const or_flag; unsigned long const and_flag; bool const is_dflt; } const FSTAB_OPTIONS[] = { + { "rbind", MS_BIND|MS_REC, ~0, false }, { "bind", MS_BIND, ~0, false }, { "move", MS_MOVE, ~0, false }, #if 0 @@ -119,10 +127,12 @@ static struct FstabOptions { static void showHelp(int fd, char const *cmd, int res) { + VSERVER_DECLARE_CMD(cmd); + WRITE_MSG(fd, "Usage: "); WRITE_STR(fd, cmd); WRITE_MSG(fd, - " [--help] [--version] [--bind] [--move] [-t ] [-n]\n" + " [--help] [--version] [--bind] [--move] [--rbind] [-t ] [-n]\n" " [--mtab ] [--fstab ] [--chroot ] \n" " [--secure] -a|([-o ] [--] )\n\n" "Executes mount-operations in the given chroot-dir: it assumes sources in the\n" @@ -370,7 +380,7 @@ mountSingle(struct MountInfo const *mnt, struct Options const *opt) } } - if (mnt->flags&MS_BIND) { + if (mnt->flags & (MS_BIND|MS_MOVE)) { if (mount(mnt->src, ".", mnt->type ? mnt->type : "", mnt->flags, mnt->data)==-1) { @@ -549,16 +559,17 @@ int main(int argc, char *argv[]) }; struct Options opt = { - .mtab = "/etc/mtab", - .fstab = "/etc/fstab", - .rootdir = 0, - .ignore_mtab = false, - .mount_all = false, - .is_secure = false, - - .cur_rootdir_fd = open("/", O_RDONLY|O_DIRECTORY) + .mtab = "/etc/mtab", + .fstab = "/etc/fstab", + .rootdir = 0, + .ignore_mtab = false, + .mount_all = false, + .is_secure = false, + .cur_rootdir_fd = -1 }; + opt.cur_rootdir_fd = open("/", O_RDONLY|O_DIRECTORY); + if (opt.cur_rootdir_fd==-1) { perror("open(\"/\")"); return EXIT_FAILURE; @@ -575,6 +586,7 @@ int main(int argc, char *argv[]) case 'n' : opt.ignore_mtab = true; break; case 'a' : opt.mount_all = true; break; case 'o' : mnt.data = optarg; break; + case OPTION_RBIND : mnt.flags |= MS_REC; /*@fallthrough@*/ case OPTION_BIND : mnt.flags |= MS_BIND; break; case OPTION_MOVE : mnt.flags |= MS_MOVE; break; case OPTION_MTAB : opt.mtab = optarg; break;