From 7b7a89d37947b4cf893d0d3b23fcd4f3f10b96d9 Mon Sep 17 00:00:00 2001 From: Andrej Shadura Date: Wed, 5 Sep 2018 10:33:52 +0200 Subject: Import Upstream version 1.3 --- 9bind.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 9bind.c (limited to '9bind.c') diff --git a/9bind.c b/9bind.c new file mode 100644 index 0000000..620d092 --- /dev/null +++ b/9bind.c @@ -0,0 +1,45 @@ +/* © 2008 sqweek + * See COPYING for details. + */ +#include +#include +#include +#include + +#include +#include + +int +main(int argc, char **argv) +{ + char *old = NULL, *new = NULL; + struct stat stbuf; + + while (*++argv) { + if (!old) { + old = *argv; + } else if (!new) { + new = *argv; + } else { + errx(1, "%s: too many arguments", *argv); + } + } + + if (!old || !new) { + errx(1, "usage: 9bind old new"); + } + + /* Make sure mount exists, is writable, and not sticky */ + if (stat(new, &stbuf) || access(new, W_OK)) { + err(1, "%s", new); + } + if (stbuf.st_mode & S_ISVTX) { + errx(1, "%s: refusing to bind over sticky directory", new); + } + + if (mount(old, new, NULL, MS_BIND, NULL)) { + err(1, "mount"); + } + + return 0; +} -- cgit v1.2.3