seteuid.c 1008 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /*
  2. * Copyright (C) 2000-2006 Erik Andersen <andersen@uclibc.org>
  3. *
  4. * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
  5. */
  6. #include <unistd.h>
  7. #include <stdio.h>
  8. #include <errno.h>
  9. #include <pwd.h>
  10. #include <sys/types.h>
  11. #include <sys/syscall.h>
  12. #if !defined __UCLIBC_LINUX_SPECIFIC__
  13. #undef __NR_setresuid
  14. #undef __NR_setresuid32
  15. #endif
  16. /* libc_hidden_proto(seteuid) */
  17. #if (defined __NR_setresuid || defined __NR_setresuid32) && defined __USE_GNU
  18. /* libc_hidden_proto(setresuid) */
  19. #endif
  20. /* libc_hidden_proto(setreuid) */
  21. int seteuid(uid_t uid)
  22. {
  23. int result;
  24. if (uid == (uid_t) ~0)
  25. {
  26. __set_errno (EINVAL);
  27. return -1;
  28. }
  29. #if (defined __NR_setresuid || defined __NR_setresuid32) && defined __USE_GNU
  30. result = setresuid(-1, uid, -1);
  31. if (result == -1 && errno == ENOSYS)
  32. /* Will also set the saved user ID if euid != uid,
  33. * making it impossible to switch back...*/
  34. #endif
  35. result = setreuid(-1, uid);
  36. return result;
  37. }
  38. libc_hidden_def(seteuid)