summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--NEWS4
-rw-r--r--trans/Makefile5
-rw-r--r--trans/remap.c152
-rw-r--r--utils/Makefile6
-rw-r--r--utils/remap.sh64
5 files changed, 226 insertions, 5 deletions
diff --git a/NEWS b/NEWS
index 26cffe1e..ea994a8e 100644
--- a/NEWS
+++ b/NEWS
@@ -7,6 +7,10 @@ consumption problems and race conditions. The system can compile
itself as well as most external applications. The amount of stress
the system can tolerate has increased a lot.
+The new remap translator can be used to create an environment in which
+some paths are redirected, for instance the TCP/IP stack, or /bin/sh,
+etc.
+
The new ftpfs translator can be used to transparently access FTP
servers through the filesystem. Together with the new hostmux
translator, which can invoke host-specific translators like ftpfs,
diff --git a/trans/Makefile b/trans/Makefile
index ff5a6a65..b3210b67 100644
--- a/trans/Makefile
+++ b/trans/Makefile
@@ -20,10 +20,10 @@ dir := trans
makemode := servers
targets = symlink firmlink ifsock magic null fifo new-fifo fwd crash \
- password hello hello-mt streamio fakeroot proxy-defpager
+ password hello hello-mt streamio fakeroot proxy-defpager remap
SRCS = ifsock.c symlink.c magic.c null.c fifo.c new-fifo.c fwd.c \
crash.c firmlink.c password.c hello.c hello-mt.c streamio.c \
- fakeroot.c proxy-defpager.c
+ fakeroot.c proxy-defpager.c remap.c
OBJS = $(SRCS:.c=.o) fsysServer.o ifsockServer.o passwordServer.o \
crashServer.o crash_replyUser.o msgServer.o \
default_pagerServer.o default_pagerUser.o \
@@ -50,6 +50,7 @@ hello-mt magic null ifsock fifo new-fifo firmlink: ../libtrivfs/libtrivfs.a ../l
magic: ../libiohelp/libiohelp.a
hello: ../libtrivfs/libtrivfs.a ../libfshelp/libfshelp.a ../libports/libports.a ../libihash/libihash.a
fakeroot: ../libnetfs/libnetfs.a ../libfshelp/libfshelp.a ../libiohelp/libiohelp.a ../libports/libports.a ../libihash/libihash.a
+remap: ../libtrivfs/libtrivfs.a ../libfshelp/libfshelp.a ../libports/libports.a ../libihash/libihash.a
$(targets): ../libshouldbeinlibc/libshouldbeinlibc.a
$(targets): %: %.o
diff --git a/trans/remap.c b/trans/remap.c
new file mode 100644
index 00000000..5ee01891
--- /dev/null
+++ b/trans/remap.c
@@ -0,0 +1,152 @@
+/* remap -- a translator for changing paths
+ Copyright (C) 2013 Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2, or (at
+ your option) any later version.
+
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
+
+#include <hurd/trivfs.h>
+#include <stddef.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <argp.h>
+#include <error.h>
+#include <string.h>
+
+#include <version.h>
+
+int trivfs_fstype = FSTYPE_MISC;
+int trivfs_fsid = 0;
+int trivfs_support_read = 0;
+int trivfs_support_write = 0;
+int trivfs_support_exec = 0;
+int trivfs_allow_open = 0;
+
+void
+trivfs_modify_stat (struct trivfs_protid *cred, struct stat *st)
+{
+ /* Don't care */
+}
+
+error_t
+trivfs_goaway (struct trivfs_control *cntl, int flags)
+{
+ exit (0);
+}
+
+struct remap
+{
+ char *from;
+ char *to;
+ struct remap *next;
+};
+
+static struct remap *remaps;
+
+error_t
+trivfs_S_dir_lookup (struct trivfs_protid *diruser,
+ mach_port_t reply, mach_msg_type_name_t reply_type,
+ char *filename,
+ int flags,
+ mode_t mode,
+ retry_type *do_retry,
+ char *retry_name,
+ mach_port_t *retry_port,
+ mach_msg_type_name_t *retry_port_type)
+{
+ struct remap *remap;
+
+ if (!diruser)
+ return EOPNOTSUPP;
+
+ for (remap = remaps; remap; remap = remap->next)
+ if (!strcmp (remap->from, filename))
+ {
+#ifdef DEBUG
+ fprintf (stderr,"replacing %s with %s\n", remap->from, remap->to);
+ fflush (stderr);
+#endif
+ filename = remap->to;
+ break;
+ }
+
+ *do_retry = FS_RETRY_REAUTH;
+ *retry_port = getcrdir ();
+ *retry_port_type = MACH_MSG_TYPE_COPY_SEND;
+ strcpy (retry_name, filename);
+
+ return 0;
+}
+
+static error_t
+parse_opt (int key, char *arg, struct argp_state *state)
+{
+ static char *remap_from;
+
+ switch (key)
+ {
+ case ARGP_KEY_ARG:
+
+ /* Skip heading slashes */
+ while (arg[0] == '/')
+ arg++;
+
+ if (!remap_from)
+ /* First of a pair */
+ remap_from = strdup (arg);
+ else
+ {
+ /* Second of a pair */
+ struct remap *remap = malloc (sizeof (*remap));
+ remap->from = remap_from;
+ remap->to = strdup (arg);
+ remap->next = remaps;
+#ifdef DEBUG
+ fprintf (stderr, "adding remap %s->%s\n", remap->from, remap->to);
+#endif
+ remaps = remap;
+ remap_from = NULL;
+ }
+
+ break;
+ }
+ return 0;
+}
+
+const char *argp_program_version = STANDARD_HURD_VERSION (fakeroot);
+
+int
+main (int argc, char **argv)
+{
+ error_t err;
+ mach_port_t bootstrap;
+
+ struct argp argp = { NULL, parse_opt, "[ FROM1 TO1 [ FROM2 TO2 [ ... ] ] ]", "\
+A translator for remapping directories.\v\
+This translator is to be used as a chroot, within which paths point to the\
+same files as the original root, except a given set of paths, which are\
+remapped to given paths." };
+
+ argp_parse (&argp, argc, argv, ARGP_IN_ORDER, 0, 0);
+
+ task_get_bootstrap_port (mach_task_self (), &bootstrap);
+ struct trivfs_control *fsys;
+
+ err = trivfs_startup (bootstrap, 0, 0, 0, 0, 0, &fsys);
+ if (err)
+ error (1, err, "trivfs_startup failed");
+ ports_manage_port_operations_one_thread (fsys->pi.bucket, trivfs_demuxer, 0);
+
+ /*NOTREACHED*/
+ return 0;
+}
diff --git a/utils/Makefile b/utils/Makefile
index 00f6142f..e3bed0bf 100644
--- a/utils/Makefile
+++ b/utils/Makefile
@@ -21,14 +21,14 @@ makemode := utilities
targets = shd ps settrans showtrans syncfs fsysopts \
storeinfo login w uptime ids loginpr sush vmstat portinfo \
devprobe vminfo addauth rmauth unsu setauth ftpcp ftpdir storecat \
- storeread msgport rpctrace mount gcore fakeauth fakeroot
-special-targets = loginpr sush uptime fakeroot
+ storeread msgport rpctrace mount gcore fakeauth fakeroot remap
+special-targets = loginpr sush uptime fakeroot remap
SRCS = shd.c ps.c settrans.c syncfs.c showtrans.c addauth.c rmauth.c \
fsysopts.c storeinfo.c login.c loginpr.sh sush.sh w.c \
uptime.sh psout.c ids.c vmstat.c portinfo.c devprobe.c vminfo.c \
parse.c frobauth.c frobauth-mod.c setauth.c pids.c nonsugid.c \
unsu.c ftpcp.c ftpdir.c storeread.c storecat.c msgport.c \
- rpctrace.c mount.c gcore.c fakeauth.c fakeroot.sh
+ rpctrace.c mount.c gcore.c fakeauth.c fakeroot.sh remap.sh
OBJS = $(filter-out %.sh,$(SRCS:.c=.o))
HURDLIBS = ps ihash store fshelp ports ftpconn shouldbeinlibc
diff --git a/utils/remap.sh b/utils/remap.sh
new file mode 100644
index 00000000..106109e8
--- /dev/null
+++ b/utils/remap.sh
@@ -0,0 +1,64 @@
+#!/bin/sh
+# Execute a command in an environment where some paths are remapped
+#
+# Copyright (C) 2002, 2013 Free Software Foundation, Inc.
+#
+# This file is part of the GNU Hurd.
+#
+# The GNU Hurd is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License as
+# published by the Free Software Foundation; either version 2, or (at
+# your option) any later version.
+#
+# The GNU Hurd is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+#
+
+USAGE="Usage: $0 [OPTION...] [FROM1 TO1 [FROM2 TO2 [...]] -- [COMMAND...]"
+DOC="Execute COMMAND in an environment where some paths are remapped."
+
+while :; do
+ case "$1" in
+ --help|"-?")
+ echo "$USAGE"
+ echo "$DOC"
+ echo ""
+ echo " -?, --help Give this help list"
+ echo " --usage Give a short usage message"
+ echo " -V, --version Print program version"
+ exit 0;;
+ --usage)
+ echo "Usage: $0 [-V?] [--help] [--usage] [--version]"
+ exit 0;;
+ --version|-V)
+ echo "STANDARD_HURD_VERSION_remap_"; exit 0;;
+ --)
+ shift
+ break;;
+ -*)
+ echo 1>&2 "$0: unrecognized option \`$1'"
+ echo 1>&2 "Try \`$0 --help' or \`$0 --usage' for more information";
+ exit 1;;
+ *)
+ MAPPED="$MAPPED $1"
+ break;;
+ esac
+done
+
+if [ $# -eq 0 ]; then
+ set -- ${SHELL:-/bin/sh}
+fi
+
+# We exec settrans, which execs the "fakeauth" command in the chroot context.
+# The `pwd` is evaluated here and now, and that result interpreted inside
+# the shell running under fakeauth to chdir there inside the chroot world.
+# That shell then execs our arguments as a command line.
+exec /bin/settrans --chroot \
+ /bin/sh -c "cd `pwd`; $*" \
+ -- / /hurd/remap $MAPPED