summaryrefslogtreecommitdiff
path: root/debian/patches/gpg0001-utils-settrans-improve-chroot-functionality.patch
blob: b28faa3796c1bef597a909ea6f7093e5ba85faa5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
From 2e4fecd33b97db7e028f69e78f80e85e953250b4 Mon Sep 17 00:00:00 2001
From: Justus Winter <4winter@informatik.uni-hamburg.de>
Date: Fri, 15 Jan 2016 18:56:25 +0100
Subject: [PATCH hurd 1/2] utils/settrans: improve --chroot functionality

Add an option '--chroot-chdir' to settrans and make it chdir to this
directory before executing the target program.

* utils/fakeroot.sh: Simplify using the new option.
* utils/remap.sh: Likewise.
* utils/settrans.c (OPT_CHROOT_CHDIR): New constant.
(options): New option 'chroot-chdir'.
(main): Handle new option.
---
 utils/fakeroot.sh | 15 ++++++---------
 utils/remap.sh    | 14 ++++++--------
 utils/settrans.c  | 16 +++++++++++++++-
 3 files changed, 27 insertions(+), 18 deletions(-)

diff --git a/utils/fakeroot.sh b/utils/fakeroot.sh
index 6993365..90b436c 100644
--- a/utils/fakeroot.sh
+++ b/utils/fakeroot.sh
@@ -54,12 +54,9 @@ 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/fakeauth \
-     /bin/sh -c 'cd "$1" || exit ; shift ; exec "$@"' \
-     "$1" "$PWD" "$@" \
-     -- / /hurd/fakeroot
+# We exec settrans, which execs the "fakeauth" command in the chroot
+# context provided by /hurd/fakeroot.
+exec /bin/settrans \
+     --chroot /bin/fakeauth "$@" -- \
+     --chroot-chdir "$PWD" \
+     / /hurd/fakeroot
diff --git a/utils/remap.sh b/utils/remap.sh
index f24ed0e..3bc6680 100644
--- a/utils/remap.sh
+++ b/utils/remap.sh
@@ -57,11 +57,9 @@ 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 "$1" || exit ; shift ; exec "$@"' \
-     "$1" "$PWD" "$@" \
-     -- / /hurd/remap $MAPPED
+# We exec settrans, which execs the target command in the chroot
+# context provided by /hurd/remap.
+exec /bin/settrans \
+     --chroot "$@" -- \
+     --chroot-chdir "$PWD" \
+     / /hurd/remap $MAPPED
diff --git a/utils/settrans.c b/utils/settrans.c
index cd40c56..7e7db0b 100644
--- a/utils/settrans.c
+++ b/utils/settrans.c
@@ -45,6 +45,8 @@ const char *argp_program_version = STANDARD_HURD_VERSION (settrans);
 #define _STRINGIFY(arg) #arg
 #define STRINGIFY(arg) _STRINGIFY (arg)
 
+#define OPT_CHROOT_CHDIR	-1
+
 static struct argp_option options[] =
 {
   {"active",      'a', 0, 0, "Start TRANSLATOR and set it as NODE's active translator" },
@@ -65,6 +67,9 @@ static struct argp_option options[] =
   {"chroot",      'C', 0, 0,
    "Instead of setting the node's translator, take following arguments up to"
    " `--' and run that command chroot'd to the translated node."},
+  {"chroot-chdir",      OPT_CHROOT_CHDIR, "DIR", 0,
+   "Change to DIR before running the chrooted command.  "
+   "DIR must be an absolute path."},
 
   {0,0,0,0, "When setting the passive translator, if there's an active translator:"},
   {"goaway",      'g', 0, 0, "Ask the active translator to go away"},
@@ -114,6 +119,7 @@ main(int argc, char *argv[])
   int excl = 0;
   int timeout = DEFAULT_TIMEOUT * 1000; /* ms */
   char **chroot_command = 0;
+  char *chroot_chdir = "/";
 
   /* Parse our options...  */
   error_t parse_opt (int key, char *arg, struct argp_state *state)
@@ -183,6 +189,14 @@ main(int argc, char *argv[])
 	  argp_error (state, "--chroot command must be terminated with `--'");
 	  return EINVAL;
 
+	case OPT_CHROOT_CHDIR:
+	  if (strcmp (chroot_chdir, "/") != 0)
+	    argp_error (state, "--chroot-chdir given twice");
+	  if (arg[0] != '/')
+	    argp_error (state, "--chroot-chdir must be absolute");
+	  chroot_chdir = arg;
+	  break;
+
 	case 'c': lookup_flags |= O_CREAT; break;
 	case 'L': lookup_flags &= ~O_NOTRANS; break;
 
@@ -341,7 +355,7 @@ main(int argc, char *argv[])
 	  if (setcrdir (root))
 	    error (7, errno, "cannot install root port");
 	  mach_port_deallocate (mach_task_self (), root);
-	  if (chdir ("/"))
+	  if (chdir (chroot_chdir))
 	    error (8, errno, "cannot chdir to new root");
 
 	  execvp (chroot_command[0], chroot_command);
-- 
2.1.4