linux-um archives
 help / color / mirror / Atom feed
From: Matt Zimmerman <mdz@debian.org>
To: user-mode-linux-devel@lists.sourceforge.net
Subject: [uml-devel] [PATCH] allow jail_uml to work with a numeric uid
Date: Sat, 26 Feb 2005 09:36:44 -0800	[thread overview]
Message-ID: <20050226173644.GG12439@alcor.net> (raw)

[-- Attachment #1: Type: text/plain, Size: 12 bytes --]


-- 
 - mdz

[-- Attachment #2: Type: message/rfc822, Size: 5091 bytes --]

[-- Attachment #2.1.1: Type: text/plain, Size: 461 bytes --]


On Thu, Dec 02 '04 at 09:51, Matt Zimmerman wrote:
> Could you send your changes as a patch against the current package, rather
> than a new package?

Like this?

Cu,
    Goetz.
-- 
/"\ Goetz Bock at blacknet dot de  --  secure mobile Linux everNETting
\ /       (c) 2004 Creative Commons, Attribution-ShareAlike 2.0 de
 X   [ 1. Use descriptive subjects - 2. Edit a reply for brevity -  ]
/ \  [ 3. Reply to the list - 4. Read the archive *before* you post ]

[-- Attachment #2.1.2: uml-utilities_20040406-1-1bg.diff --]
[-- Type: text/plain, Size: 3084 bytes --]

diff -pruN uml-utilities-20040406-1/debian/changelog uml-utilities-20040406-1bg/debian/changelog
--- uml-utilities-20040406-1/debian/changelog	2004-12-02 19:19:26.000000000 +0100
+++ uml-utilities-20040406-1bg/debian/changelog	2004-12-02 19:20:12.000000000 +0100
@@ -1,3 +1,9 @@
+uml-utilities (20040406-1bg) unstable; urgency=low
+
+  * Patch from Goetz Bock to allow jail_uml to work with a numeric uid
+  
+ -- Goetz Bock <bock@blacknet.de>  Thu,  2 Dec 2004 18:16:23 -0100
+
 uml-utilities (20040406-1) unstable; urgency=low
 
   * New upstream release
diff -pruN uml-utilities-20040406-1/jail/Makefile uml-utilities-20040406-1bg/jail/Makefile
--- uml-utilities-20040406-1/jail/Makefile	2004-12-02 19:19:26.000000000 +0100
+++ uml-utilities-20040406-1bg/jail/Makefile	2004-12-02 19:20:12.000000000 +0100
@@ -1,11 +1,17 @@
-all : jail_uml
+OBJS = jail_uml.o
+BIN = jail_uml
+CFLAGS = -g -Wall
 
-install:
+SBIN_DIR ?= /usr/sbin
 
-jail_uml : jail_uml.c
+all : $(BIN)
 
-# Don't install anything as yet
-install :
+$(BIN) : $(OBJS)
+	$(CC) $(CFLAGS) -o $(BIN) $(OBJS)
 
+install : $(BIN)
+	install -d $(DESTDIR)$(SBIN_DIR)
+	install -s $(BIN) $(DESTDIR)$(SBIN_DIR)
+	
 clean :
-	rm -rf *~ jail_uml cell[0-9]* core* tty_log_cell*
+	rm -rf *~ $(BIN) $(OBJS) cell[0-9]* core* tty_log_cell*
diff -pruN uml-utilities-20040406-1/jail/jail_uml.c uml-utilities-20040406-1bg/jail/jail_uml.c
--- uml-utilities-20040406-1/jail/jail_uml.c	2003-01-22 18:46:36.000000000 +0100
+++ uml-utilities-20040406-1bg/jail/jail_uml.c	2004-12-02 19:20:12.000000000 +0100
@@ -1,18 +1,32 @@
+/* jail a uml into a directory.
+ 
+*/
+
 #include <stdio.h>
 #include <unistd.h>
 #include <errno.h>
+#include <pwd.h>
+#include <grp.h>
+#include <sys/types.h>
 
 static void Usage(void)
 {
-  fprintf(stderr, "Usage : jail_uml jail-directory uid "
+  fprintf(stderr, "Usage : jail_uml jail-directory user "
 	  "uml-command-line ...\n");
+  fprintf(stderr, "    or: jail_uml jail-directory uid "
+	  "uml-command-line ...\n\n");
+  fprintf(stderr, "If the user is not found, it's assumed to be a uid.\n");
   exit(1);
 }
 
 int main(int argc, char **argv)
 {
   char *dir, *end;
-  int uid;
+  char *user;
+  struct passwd *pw;
+  int uid, gid=99;
+  gid_t gidset[1];
+  gidset[0]=gid;
 
   if(geteuid() != 0){
     fprintf(stderr, "jail_uml must be run as root\n");
@@ -21,8 +35,22 @@ int main(int argc, char **argv)
 
   if(argc < 3) Usage();
   dir = argv[1];
-  uid = strtoul(argv[2], &end, 0);
-  if(*end != '\0') Usage();
+  user = argv[2];
+  
+  // get users password information
+  pw = getpwnam (user);
+  if (pw == 0){
+    uid = strtoul(argv[2], &end, 0);
+    if(*end != '\0') Usage();
+    setgroups(1, gidset);
+  } else {
+    // try to init groups
+    initgroups (pw->pw_name, pw->pw_gid); 
+    uid = pw->pw_uid;
+    gid = pw->pw_gid;
+  }
+
+  // if(*end != '\0') Usage();
   argc -= 3;
   argv += 3;
 
@@ -36,6 +64,10 @@ int main(int argc, char **argv)
     exit(1);
   }
 
+  if(setgid(gid)){
+    perror("setgid");
+    exit(1);
+  }
   if(setuid(uid)){
     perror("setuid");
     exit(1);

             reply	other threads:[~2005-02-26 17:36 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-02-26 17:36 Matt Zimmerman [this message]
2005-03-01 18:51 ` [uml-devel] [PATCH] allow jail_uml to work with a numeric uid Jeff Dike

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20050226173644.GG12439@alcor.net \
    --to=mdz@debian.org \
    --cc=user-mode-linux-devel@lists.sourceforge.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox