linux-um archives
 help / color / mirror / Atom feed
From: Goetz Bock <bock+uml@blacknet.de>
To: user-mode-linux-devel@lists.sourceforge.net
Subject: [uml-devel] username support for jail_uml
Date: Sun, 30 May 2004 03:53:00 +0200	[thread overview]
Message-ID: <20040530015300.GB450@shell.blacknet.de> (raw)

Hi all,

I've written included patch to add support for usernames/groups and gids
to jail_uml. The default group/gid is hardcoded to 99 (=nobody on my
system).

Cu,
    Goetz.

diff -ur tools/jail/jail_uml.c tools-bn/jail/jail_uml.c
--- tools/jail/jail_uml.c	2003-01-22 18:46:36.000000000 +0100
+++ tools-bn/jail/jail_uml.c	2004-05-30 03:43:17.000000000 +0200
@@ -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 @@
 
   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 @@
     exit(1);
   }
 
+  if(setgid(gid)){
+    perror("setgid");
+    exit(1);
+  }
   if(setuid(uid)){
     perror("setuid");
     exit(1);


-------------------------------------------------------
This SF.Net email is sponsored by: Oracle 10g
Get certified on the hottest thing ever to hit the market... Oracle 10g. 
Take an Oracle 10g class now, and we'll give you the exam FREE.
http://ads.osdn.com/?ad_id=3149&alloc_id=8166&op=click
_______________________________________________
User-mode-linux-devel mailing list
User-mode-linux-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel

                 reply	other threads:[~2004-05-30  1:52 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20040530015300.GB450@shell.blacknet.de \
    --to=bock+uml@blacknet.de \
    --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