* [uml-devel] username support for jail_uml
@ 2004-05-30 1:53 Goetz Bock
0 siblings, 0 replies; only message in thread
From: Goetz Bock @ 2004-05-30 1:53 UTC (permalink / raw)
To: user-mode-linux-devel
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
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2004-05-30 1:52 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-05-30 1:53 [uml-devel] username support for jail_uml Goetz Bock
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox