qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] -chroot and -su options.
@ 2008-03-04  0:28 Rob Landley
  2008-03-04 11:22 ` Edgar E. Iglesias
  2008-03-14 16:06 ` Anderson Lizardo
  0 siblings, 2 replies; 8+ messages in thread
From: Rob Landley @ 2008-03-04  0:28 UTC (permalink / raw)
  To: qemu-devel

Quick and dirty patch to teach qemu application emulation how to chroot (and
drop privs), so you don't have to pollute a target filesystem with host code,
and/or figure out how to build qemu static in order to run a dynamic binary.

diff --git a/linux-user/main.c b/linux-user/main.c
index 124b98c..b010fd2 100644
--- a/linux-user/main.c
+++ b/linux-user/main.c
@@ -1905,6 +1905,10 @@ void usage(void)
            "-cpu model        select CPU (-cpu ? for list)\n"
            "-drop-ld-preload  drop LD_PRELOAD for target process\n"
            "\n"
+           "Root options:\n"
+           "-chroot dir       chroot to dir\n"
+           "-su uid:gid       set numeric user and group IDs\n"
+           "\n"
            "Debug options:\n"
            "-d options   activate log (logfile=%s)\n"
            "-p pagesize  set the host page size to 'pagesize'\n"
@@ -2011,6 +2015,28 @@ int main(int argc, char **argv)
             drop_ld_preload = 1;
         } else if (!strcmp(r, "strace")) {
             do_strace = 1;
+        } else if (!strcmp(r, "chroot")) {
+            if (chdir(argv[optind++]) || chroot(".")) {
+                fprintf(stderr, "Can't chroot to '%s' (are you root?)\n",
+                    argv[--optind]);
+                _exit(1);
+            }
+        } else if (!strcmp(r, "su")) {
+            int temp;
+            char *gid = strchr(argv[optind], ':');
+            if (gid) {
+                temp = atoi(++gid);
+                if (setresgid(temp, temp, temp)) {
+                    fprintf(stderr, "Can't set gid to %d (are you root?)\n",
+                        temp);
+                    _exit(1);
+                }
+           }
+           temp = atoi(argv[optind++]);
+           if (setresuid(temp, temp, temp)) {
+               fprintf(stderr, "Can't set uid to %d (are you root?)\n", temp);
+               _exit(1);
+           }
         } else
         {
             usage();

-- 
"One of my most productive days was throwing away 1000 lines of code."
  - Ken Thompson.

^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2008-03-14 16:06 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-03-04  0:28 [Qemu-devel] [PATCH] -chroot and -su options Rob Landley
2008-03-04 11:22 ` Edgar E. Iglesias
2008-03-05  6:51   ` Rob Landley
2008-03-05  7:54     ` Edgar E. Iglesias
2008-03-06  6:47       ` Rob Landley
2008-03-14 14:08         ` Edgar E. Iglesias
2008-03-14 15:26           ` Rob Landley
2008-03-14 16:06 ` Anderson Lizardo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).