Back to index

glibc  2.9
getresuid.c
Go to the documentation of this file.
00001 /* Copyright (C) 1998,2000,2002,2003,2005,2006 Free Software Foundation, Inc.
00002    This file is part of the GNU C Library.
00003 
00004    The GNU C Library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Lesser General Public
00006    License as published by the Free Software Foundation; either
00007    version 2.1 of the License, or (at your option) any later version.
00008 
00009    The GNU C Library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Lesser General Public License for more details.
00013 
00014    You should have received a copy of the GNU Lesser General Public
00015    License along with the GNU C Library; if not, write to the Free
00016    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00017    02111-1307 USA.  */
00018 
00019 #include <errno.h>
00020 #include <unistd.h>
00021 #include <sys/types.h>
00022 
00023 #include <linux/posix_types.h>
00024 
00025 #include <sysdep.h>
00026 #include <sys/syscall.h>
00027 #include <bp-checks.h>
00028 
00029 #include <kernel-features.h>
00030 
00031 #ifdef __NR_getresuid
00032 
00033 # ifdef __NR_getresuid32
00034 #  if __ASSUME_32BITUIDS == 0
00035 /* This variable is shared with all files that need to check for 32bit
00036    uids.  */
00037 extern int __libc_missing_32bit_uids;
00038 #  endif
00039 # endif /* __NR_getresuid32 */
00040 
00041 int
00042 __getresuid (uid_t *ruid, uid_t *euid, uid_t *suid)
00043 {
00044 # if __ASSUME_32BITUIDS > 0
00045   return INLINE_SYSCALL (getresuid32, 3, CHECK_1 (ruid),
00046                       CHECK_1 (euid), CHECK_1 (suid));
00047 # else
00048   __kernel_uid_t k_ruid, k_euid, k_suid;
00049   int result;
00050 #  ifdef __NR_getresuid32
00051   if (__libc_missing_32bit_uids <= 0)
00052     {
00053       int r;
00054       int saved_errno = errno;
00055 
00056       r = INLINE_SYSCALL (getresuid32, 3, CHECK_1 (ruid),
00057                        CHECK_1 (euid), CHECK_1 (suid));
00058       if (r == 0 || errno != ENOSYS)
00059        return r;
00060 
00061       __set_errno (saved_errno);
00062       __libc_missing_32bit_uids = 1;
00063     }
00064 #  endif /* __NR_getresuid32 */
00065 
00066   result = INLINE_SYSCALL (getresuid, 3, __ptrvalue (&k_ruid),
00067                         __ptrvalue (&k_euid), __ptrvalue (&k_suid));
00068 
00069   if (result == 0)
00070     {
00071       *ruid = (uid_t) k_ruid;
00072       *euid = (uid_t) k_euid;
00073       *suid = (uid_t) k_suid;
00074     }
00075 
00076   return result;
00077 # endif
00078 }
00079 libc_hidden_def (__getresuid)
00080 weak_alias (__getresuid, getresuid)
00081 
00082 #else
00083 # include <posix/getresuid.c>
00084 #endif