158275Smckusick /* 2*60986Sbostic * Copyright (c) 1993 3*60986Sbostic * The Regents of the University of California. All rights reserved. 458275Smckusick * 558275Smckusick * %sccs.include.redist.c% 658275Smckusick */ 758275Smckusick 858275Smckusick #if defined(LIBC_SCCS) && !defined(lint) 9*60986Sbostic static char sccsid[] = "@(#)setregid.c 8.1 (Berkeley) 06/02/93"; 1058275Smckusick #endif /* LIBC_SCCS and not lint */ 1158275Smckusick 1258275Smckusick #include <sys/types.h> 1358275Smckusick #include <errno.h> 1458275Smckusick 1558275Smckusick int setregid(rgid,egid)1658275Smckusicksetregid(rgid, egid) 1758275Smckusick gid_t rgid, egid; 1858275Smckusick { 1958275Smckusick static gid_t savedgid = -1; 2058275Smckusick 2158275Smckusick if (savedgid == -1) 2258275Smckusick savedgid = getegid(); 2358275Smckusick /* 2458275Smckusick * we assume that the intent here is to be able to 2558275Smckusick * get back rgid priviledge. So we make sure that 2658275Smckusick * we will be able to do so, but do not actually 2758275Smckusick * set the rgid. 2858275Smckusick */ 2958275Smckusick if (rgid != -1 && rgid != getgid() && rgid != savedgid) { 3058275Smckusick errno = EPERM; 3158275Smckusick return (-1); 3258275Smckusick } 3358275Smckusick if (egid != -1 && setegid(egid) < 0) 3458275Smckusick return (-1); 3558275Smckusick return (0); 3658275Smckusick } 37