From: Michael Poole Date: Sat, 15 May 2004 14:50:09 +0000 (+0000) Subject: Fix uid bug in chroot wrapper. X-Git-Url: http://git.pk910.de/?p=ircu2.10.12-pk.git;a=commitdiff_plain;h=00783dd429d696c7e8f82956aad3db01c6c736ea Fix uid bug in chroot wrapper. Fix calculation of "generation" in version.c.SH. git-svn-id: file:///home/klmitch/undernet-ircu/undernet-ircu-svn/ircu2/trunk@1050 c9e4aea6-c8fd-4c43-8297-357d70d61c8c --- diff --git a/ChangeLog b/ChangeLog index 4a7b932..59f1ad4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2004-05-15 Kevin L Mitchell + + [Original ChangeLog date: 2003-11-22 -MDP] + + * tools/wrapper.c: commit uid on chroot fix from ubra + + * ircd/version.c.SH: fix generation generation + 2004-05-15 Isomer [Original ChangeLog date: 2003-11-23 -MDP] diff --git a/ircd/version.c.SH b/ircd/version.c.SH index c4f1804..2b65dc8 100644 --- a/ircd/version.c.SH +++ b/ircd/version.c.SH @@ -4,7 +4,7 @@ srcdir=$1 if test -r version.c then - generation=`sed -n 's/^char \*generation = \"\(.*\)\";/\1/p' < version.c` + generation=`sed -n 's/^const char \*generation = \"\(.*\)\";/\1/p' < version.c` if test ! "$generation" ; then generation=0; fi else generation=0 diff --git a/tools/wrapper.c b/tools/wrapper.c index cd26ae1..448598e 100644 --- a/tools/wrapper.c +++ b/tools/wrapper.c @@ -1,5 +1,4 @@ /* -** IRC - Internet Relay Chat, tools/wrapper.c ** Copyright (C) 2000 by Kevin L. Mitchell ** ** This program is free software; you can redistribute it and/or modify @@ -48,6 +47,9 @@ #endif #endif +/*fix for change uid/gid with chroot #ubra 08/02/03*/ +int uid, gid; + /* * Set the hard and soft limits for maximum file descriptors. */ @@ -79,14 +81,16 @@ change_root(char *root) /* * Change the user and group ids--including supplementary groups!--as * appropriate. + * + * fix for change uid/gid with chroot #ubra 08/02/03 + * old change_user() got splited into get_user() and set_user() */ int -change_user(char *user, char *group) +get_user(char *user, char *group) { struct passwd *pwd; struct group *grp; char *tmp; - int uid, gid; /* Track down a struct passwd describing the desired user */ uid = strtol(user, &tmp, 10); /* was the user given as a number? */ @@ -112,6 +116,11 @@ change_user(char *user, char *group) if (initgroups(pwd->pw_name, gid)) /* initialize supplementary groups */ return -1; + return 0; /* success! */ +} + +int +set_user(void) { if (setgid(gid)) /* change our current group */ return -1; if (setuid(uid)) /* change our current user */ @@ -183,6 +192,13 @@ main(int argc, char **argv) return 1; } + if(user) /* get the selected user account uid/gid*/ + if (get_user(user, group)) { + perror(prog); + return 1; + } + + if (root) /* change root directories */ if (change_root(root)) { perror(prog); @@ -190,7 +206,7 @@ main(int argc, char **argv) } if (user) /* change to selected user account */ - if (change_user(user, group)) { + if (set_user()) { perror(prog); return 1; }