Back to index

glibc  2.9
setegid.c
Go to the documentation of this file.
00001 /* Copyright (C) 1995-1998,2000,2002,2003,2004,2006
00002        Free Software Foundation, Inc.
00003    This file is part of the GNU C Library.
00004 
00005    The GNU C Library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Lesser General Public
00007    License as published by the Free Software Foundation; either
00008    version 2.1 of the License, or (at your option) any later version.
00009 
00010    The GNU C Library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Lesser General Public License for more details.
00014 
00015    You should have received a copy of the GNU Lesser General Public
00016    License along with the GNU C Library; if not, write to the Free
00017    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00018    02111-1307 USA.  */
00019 
00020 #include <errno.h>
00021 #include <unistd.h>
00022 #include <setxid.h>
00023 #include <kernel-features.h>
00024 
00025 
00026 #ifdef __NR_setresgid
00027 extern int __setresgid (uid_t rgid, uid_t egid, uid_t sgid);
00028 #endif
00029 
00030 int
00031 setegid (gid)
00032      gid_t gid;
00033 {
00034   int result;
00035 
00036   if (gid == (gid_t) ~0)
00037     {
00038       __set_errno (EINVAL);
00039       return -1;
00040     }
00041 
00042 #if __ASSUME_32BITUIDS > 0
00043   result = INLINE_SETXID_SYSCALL (setresgid32, 3, -1, gid, -1);
00044 #else
00045   /* First try the syscall.  */
00046 # ifdef __NR_setresgid
00047   result = __setresgid (-1, gid, -1);
00048 #  if __ASSUME_SETRESGID_SYSCALL > 0
00049   if (0)
00050 #  else
00051   if (result == -1 && errno == ENOSYS)
00052 #  endif
00053     /* No system call available.  Use emulation.  This may not work
00054        since `setregid' also sets the saved user ID when GID is not
00055        equal to the real user ID, making it impossible to switch back.  */
00056 # endif
00057     result = __setregid (-1, gid);
00058 #endif
00059 
00060   return result;
00061 }
00062 libc_hidden_def (setegid)