X-Git-Url: http://git.linux-vserver.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=util-vserver%2Fsrc%2Fsecure-mount.c;h=65f4a54c7a364f485c3bdbd2171109bc1049bd8c;hb=feda714e8feec0c6711f6d68326819e03f16c4b4;hp=5e48430b2621bc5b9fe601135bb2795ce95f2e47;hpb=3dd4243ea30b0f2bdaef525660dd999e5f47cc09;p=util-vserver.git diff --git a/util-vserver/src/secure-mount.c b/util-vserver/src/secure-mount.c index 5e48430..65f4a54 100644 --- a/util-vserver/src/secure-mount.c +++ b/util-vserver/src/secure-mount.c @@ -94,6 +94,10 @@ CMDLINE_OPTIONS[] = { { 0, 0, 0, 0 } }; +#ifndef MS_REC +# define MS_REC 0x4000 +#endif + static struct FstabOptions { char const * const opt; unsigned long const or_flag; @@ -256,23 +260,23 @@ updateMtab(struct MountInfo const *mnt, struct Options const *opt) if (opt->rootdir!=0 && chroot(opt->rootdir)==-1) { - perror("chroot()"); + perror("secure-mount: chroot()"); return -1; } fd=open(opt->mtab, O_CREAT|O_APPEND|O_WRONLY, 0644); - if (fd==-1) perror("open()"); + if (fd==-1) perror("secure-mount: open()"); if (fchroot(opt->cur_rootdir_fd)==-1) { - perror("fchroot()"); + perror("secure-mount: fchroot()"); goto err1; } if (fd==-1) goto err0; if (flock(fd, LOCK_EX)==-1) { - perror("flock()"); + perror("secure-mount: flock()"); goto err1; } @@ -285,7 +289,7 @@ updateMtab(struct MountInfo const *mnt, struct Options const *opt) writeStrX(fd, " ")==-1 || writeStrX(fd, mnt->data ? mnt->data : "defaults")==-1 || writeStrX(fd, " 0 0\n")==-1) { - perror("write()"); + perror("secure-mount: write()"); goto err1; } @@ -328,18 +332,18 @@ callExternalMount(struct MountInfo const *mnt) pid = fork(); if (pid==-1) { - perror("fork()"); + perror("secure-mount: fork()"); return false; } if (pid==0) { execv(mount_prog, const_cast(char **)(argv)); - perror("execv()"); + PERROR_Q("secure-mount: execv", mount_prog); exit(1); } if (wait4(pid, &status, 0, 0)==-1) { - perror("wait4()"); + perror("secure-mount: wait4()"); return false; } @@ -355,7 +359,7 @@ mountSingle(struct MountInfo const *mnt, struct Options const *opt) if (opt->rootdir!=0) { if (chdir(opt->rootdir)==-1) { - perror("chdir()"); + PERROR_Q("secure-mount: chdir", opt->rootdir); return false; } @@ -364,14 +368,14 @@ mountSingle(struct MountInfo const *mnt, struct Options const *opt) if (opt->is_secure) { if (chdirSecure(dir)==-1) { - perror("chdirSecure()"); + PERROR_Q("secure-mount: chdirSecure", dir); return false; } } else { if (*dir!='\0' && chdir(dir)==-1) { - perror("chdir()"); + PERROR_Q("secure-mount: chdir", dir); return false; } } @@ -380,7 +384,7 @@ mountSingle(struct MountInfo const *mnt, struct Options const *opt) if (mount(mnt->src, ".", mnt->type ? mnt->type : "", mnt->flags, mnt->data)==-1) { - perror("mount()"); + perror("secure-mount: mount()"); return false; } } @@ -392,7 +396,7 @@ mountSingle(struct MountInfo const *mnt, struct Options const *opt) if ((mnt->flags&MS_BIND) && opt->rootdir!=0 && (verifyPosition(mnt->src, opt->rootdir, mnt->dst)==-1 || fchroot(opt->cur_rootdir_fd)==-1)) { - perror("verifyPosition/fchroot"); + perror("secure-mount: verifyPosition/fchroot"); // TODO: what is with unmounting? return false; } @@ -485,14 +489,14 @@ mountFstab(struct Options const *opt) assert(opt->fstab!=0); fd = open(opt->fstab, O_RDONLY); if (fd==-1) { - perror("open()"); + perror("secure-mount: open()"); goto err0; } len = lseek(fd, 0, SEEK_END); if (len==-1 || lseek(fd, 0, SEEK_SET)==-1) { - perror("lseek()"); + perror("secure-mount: lseek()"); goto err1; } @@ -501,7 +505,7 @@ mountFstab(struct Options const *opt) char *ptr, *ptrptr; if (read(fd, buf, len+1)!=len) { - perror("read()"); + perror("secure-mount: read()"); goto err1; } buf[len] = '#'; // workaround for broken dietlibc strtok_r() @@ -567,7 +571,7 @@ int main(int argc, char *argv[]) opt.cur_rootdir_fd = open("/", O_RDONLY|O_DIRECTORY); if (opt.cur_rootdir_fd==-1) { - perror("open(\"/\")"); + perror("secure-mount: open(\"/\")"); return EXIT_FAILURE; }