allow jail_uml to work with a numeric uid
PATCH 1/1 allow jail_uml to work with a numeric uid
Signature · 2 lines
-- - mdz
Quoted 2 lines · Matt Zimmerman
Could you send your changes as a patch against the current package, rather than a new package?
Like this?
Cu,
Goetz.
Signature · 4 lines
/"\ 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 ]
debian/changelog +6 -0
@@ -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 <[email protected]> Thu, 2 Dec 2004 18:16:23 -0100 + uml-utilities (20040406-1) unstable; urgency=low * New upstream release
jail/Makefile +12 -6
@@ -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*
jail/jail_uml.c +36 -4
@@ -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 );
Jeff Dike
AppliedApplied, thanks.
Jeff
-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users. Discover which products truly live up to the hype. Start reading now.
http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click
_______________________________________________
User-mode-linux-devel mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel