From 2b09dd75497c1714714dd5ab8ac2f9c7be11918b Mon Sep 17 00:00:00 2001 From: Eric Allman Date: Sat, 21 Aug 1993 14:23:00 -0800 Subject: [PATCH] more NeXT portability changes; use initgroups when reading .forward files SCCS-vsn: usr.sbin/sendmail/src/conf.h 8.25 SCCS-vsn: usr.sbin/sendmail/src/deliver.c 8.15 SCCS-vsn: usr.sbin/sendmail/src/conf.c 8.23 SCCS-vsn: usr.sbin/sendmail/src/alias.c 8.10 --- usr/src/usr.sbin/sendmail/src/alias.c | 33 +++++++++++++++++++------ usr/src/usr.sbin/sendmail/src/conf.c | 14 +++-------- usr/src/usr.sbin/sendmail/src/conf.h | 19 +++++++++++++- usr/src/usr.sbin/sendmail/src/deliver.c | 6 +---- 4 files changed, 49 insertions(+), 23 deletions(-) diff --git a/usr/src/usr.sbin/sendmail/src/alias.c b/usr/src/usr.sbin/sendmail/src/alias.c index 7254790d75..6c90d4fa28 100644 --- a/usr/src/usr.sbin/sendmail/src/alias.c +++ b/usr/src/usr.sbin/sendmail/src/alias.c @@ -10,7 +10,7 @@ # include #ifndef lint -static char sccsid[] = "@(#)alias.c 8.9 (Berkeley) %G%"; +static char sccsid[] = "@(#)alias.c 8.10 (Berkeley) %G%"; #endif /* not lint */ @@ -673,6 +673,7 @@ forward(user, sendq, e) #ifdef HASSETREUID register ADDRESS *ca; uid_t saveduid, uid; + gid_t savedgid, gid; #endif if (tTd(27, 1)) @@ -696,9 +697,15 @@ forward(user, sendq, e) #ifdef HASSETREUID ca = getctladdr(user); if (ca != NULL) + { uid = ca->q_uid; + gid = ca->q_gid; + } else + { uid = DefUid; + gid = DefGid; + } #endif for (pp = ForwardPath; pp != NULL; pp = ep) @@ -720,8 +727,16 @@ forward(user, sendq, e) #ifdef HASSETREUID saveduid = geteuid(); - if (saveduid == 0 && uid != 0) - (void) setreuid(0, uid); + savedgid = getegid(); + if (saveduid == 0) + { + if (ca != NULL) + initgroups(ca->ca_user, gid); + else if (gid != 0) + setgid(gid); + if (uid != 0) + (void) setreuid(0, uid); + } #endif if (tTd(27, 9)) @@ -730,10 +745,14 @@ forward(user, sendq, e) err = include(buf, TRUE, user, sendq, e); #ifdef HASSETREUID - if (saveduid == 0 && uid != 0) - if (setreuid(-1, 0) < 0 || setreuid(RealUid, 0) < 0) - syserr("setreuid(%d, 0) failure (real=%d, eff=%d)", - RealUid, getuid(), geteuid()); + if (saveduid == 0) + { + if (uid != 0) + if (setreuid(-1, 0) < 0 || setreuid(RealUid, 0) < 0) + syserr("setreuid(%d, 0) failure (real=%d, eff=%d)", + RealUid, getuid(), geteuid()); + setgid(savedgid); + } #endif if (tTd(27, 9)) diff --git a/usr/src/usr.sbin/sendmail/src/conf.c b/usr/src/usr.sbin/sendmail/src/conf.c index 89edd5ae09..c51c19f672 100644 --- a/usr/src/usr.sbin/sendmail/src/conf.c +++ b/usr/src/usr.sbin/sendmail/src/conf.c @@ -7,7 +7,7 @@ */ #ifndef lint -static char sccsid[] = "@(#)conf.c 8.22 (Berkeley) %G%"; +static char sccsid[] = "@(#)conf.c 8.23 (Berkeley) %G%"; #endif /* not lint */ # include "sendmail.h" @@ -1264,12 +1264,6 @@ vsprintf(s, fmt, ap) ** Puts the filesystem block size into bsize. */ -#ifndef HASSTATFS -# if defined(BSD4_4) || defined(__osf__) -# define HASSTATFS -# endif -#endif - #ifdef HASSTATFS # undef HASUSTAT #endif @@ -1279,10 +1273,10 @@ vsprintf(s, fmt, ap) #endif #ifdef HASSTATFS -# if defined(sgi) || defined(apollo) || defined(_SCO_unix_) +# if defined(IRIX) || defined(apollo) || defined(_SCO_unix_) # include # else -# if (defined(sun) && !defined(BSD)) || defined(__hpux) || defined(_CONVEX_SOURCE) +# if (defined(sun) && !defined(BSD)) || defined(__hpux) || defined(_CONVEX_SOURCE) || defined(NeXT) # include # else # include @@ -1319,7 +1313,7 @@ freespace(dir, bsize) # if defined(HASUSTAT) if (stat(dir, &statbuf) == 0 && ustat(statbuf.st_dev, &fs) == 0) # else -# if defined(sgi) || defined(apollo) +# if defined(IRIX) || defined(apollo) if (statfs(dir, &fs, sizeof fs, 0) == 0) # else # if defined(ultrix) diff --git a/usr/src/usr.sbin/sendmail/src/conf.h b/usr/src/usr.sbin/sendmail/src/conf.h index 2911e52af3..af9e717799 100644 --- a/usr/src/usr.sbin/sendmail/src/conf.h +++ b/usr/src/usr.sbin/sendmail/src/conf.h @@ -5,7 +5,7 @@ * * %sccs.include.redist.c% * - * @(#)conf.h 8.24 (Berkeley) %G% + * @(#)conf.h 8.25 (Berkeley) %G% */ /* @@ -84,6 +84,7 @@ ** Per-Operating System defines */ + /* ** HP-UX -- tested for 8.07 */ @@ -91,6 +92,7 @@ # ifdef __hpux # define SYSTEM5 1 /* include all the System V defines */ # define HASINITGROUPS 1 /* has initgroups(3) call */ +# define HASSTATFS 1 /* has the statfs(2) syscall */ # define HASSETREUID 1 /* has setreuid(2) call */ # define setreuid(r, e) setresuid(r, e, -1) # define LA_TYPE LA_FLOAT @@ -98,6 +100,7 @@ # undef IDENTPROTO # endif + /* ** IBM AIX 3.x -- actually tested for 3.2.3 */ @@ -107,6 +110,7 @@ # define FORK fork /* no vfork primitive available */ # endif + /* ** Silicon Graphics IRIX ** @@ -116,6 +120,7 @@ # ifdef IRIX # define HASSETREUID 1 /* has setreuid(2) call */ # define HASINITGROUPS 1 /* has initgroups(3) call */ +# define HASSTATFS 1 /* has the statfs(2) syscall */ # define FORK fork /* no vfork primitive available */ # define setpgid BSDsetpgrp # define GIDSET_T gid_t @@ -156,6 +161,7 @@ # endif #endif + /* ** Digital Ultrix 4.2A or 4.3 ** @@ -175,11 +181,13 @@ # undef IDENTPROTO #endif + /* ** OSF/1 (tested on Alpha) */ #ifdef __osf__ +# define HASSTATFS 1 /* has the statfs(2) syscall */ # define HASUNSETENV 1 /* has unsetenv(3) call */ # define HASSETREUID 1 /* has setreuid(2) call */ # define HASINITGROUPS 1 /* has initgroups(3) call */ @@ -187,6 +195,7 @@ # define LA_TYPE LA_INT #endif + /* ** NeXTstep */ @@ -195,6 +204,7 @@ # define HASINITGROUPS 1 /* has initgroups(3) call */ # define HASFLOCK 1 /* has flock(2) call */ # define NEEDGETOPT 1 /* need a replacement for getopt(3) */ +# define HASSTATFS 1 /* has the statfs(2) syscall */ # define sleep sleepX # define setpgid setpgrp # ifndef LA_TYPE @@ -209,12 +219,14 @@ typedef int pid_t; # endif #endif + /* ** 4.4 BSD */ #ifdef BSD4_4 # define HASUNSETENV 1 /* has unsetenv(3) call */ +# define HASSTATFS 1 /* has the statfs(2) syscall */ # include # define ERRLIST_PREDEFINED /* don't declare sys_errlist */ # ifndef LA_TYPE @@ -222,6 +234,7 @@ typedef int pid_t; # endif #endif + /* ** 4.3 BSD -- this is for very old systems ** @@ -242,6 +255,7 @@ typedef int pid_t; # endif #endif + /* ** SCO Unix */ @@ -255,6 +269,7 @@ typedef int pid_t; # define LA_TYPE LA_ZERO #endif + /* ** ConvexOS 11.0 and later */ @@ -269,6 +284,7 @@ typedef int pid_t; # undef IDENTPROTO #endif + /* ** RISC/os 4.51 ** @@ -283,6 +299,7 @@ typedef int pid_t; # define _PATH_UNIX "/unix" #endif + /* ** Linux 0.99pl10 and above... ** From Karl London . diff --git a/usr/src/usr.sbin/sendmail/src/deliver.c b/usr/src/usr.sbin/sendmail/src/deliver.c index 2f56b6e099..4bad577eb3 100644 --- a/usr/src/usr.sbin/sendmail/src/deliver.c +++ b/usr/src/usr.sbin/sendmail/src/deliver.c @@ -7,7 +7,7 @@ */ #ifndef lint -static char sccsid[] = "@(#)deliver.c 8.14 (Berkeley) %G%"; +static char sccsid[] = "@(#)deliver.c 8.15 (Berkeley) %G%"; #endif /* not lint */ #include "sendmail.h" @@ -1122,13 +1122,11 @@ tryhost: { if (ctladdr == NULL || ctladdr->q_uid == 0) { - (void) setgid(DefGid); (void) initgroups(DefUser, DefGid); (void) setuid(DefUid); } else { - (void) setgid(ctladdr->q_gid); (void) initgroups(ctladdr->q_ruser? ctladdr->q_ruser: ctladdr->q_user, ctladdr->q_gid); @@ -1938,12 +1936,10 @@ mailfile(filename, ctladdr, e) { if (ctladdr->q_uid == 0) { - (void) setgid(DefGid); (void) initgroups(DefUser, DefGid); } else { - (void) setgid(ctladdr->q_gid); (void) initgroups(ctladdr->q_ruser ? ctladdr->q_ruser : ctladdr->q_user, ctladdr->q_gid); -- 2.20.1