2 ** Copyright 1998 - 2002 Double Precision, Inc. See COPYING for
3 ** distribution information.
22 static const char rcsid[]="$Id: changeuidgid.c,v 1.2 2003/01/05 04:01:17 mrsam Exp $";
24 void libmail_changegroup(gid_t gid)
33 if ( getuid() == 0 && setgroups(1, &gid) )
41 void libmail_changeuidgid(uid_t uid, gid_t gid)
43 libmail_changegroup(gid);
51 void libmail_changeusername(const char *uname, const gid_t *forcegrp)
57 /* uname might be a pointer returned from a previous called to getpw(),
58 ** and libc has a problem getting it back.
60 char *p=malloc(strlen(uname)+1);
70 if ((pw=getpwnam(p)) == 0)
80 if ( !forcegrp ) forcegrp= &pw->pw_gid;
84 if ( setgid( changegid ))
91 if ( getuid() == 0 && initgroups(pw->pw_name, changegid) )
98 if ( getuid() == 0 && setgroups(1, &changegid) )
106 if (setuid(changeuid))