seteuid.c 776 B

12345678910111213141516171819202122232425262728293031323334353637383940
  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. #define _GNU_SOURCE
  7. #include <unistd.h>
  8. #include <stdio.h>
  9. #include <errno.h>
  10. #include <pwd.h>
  11. #include <sys/types.h>
  12. #include <sys/syscall.h>
  13. libc_hidden_proto(seteuid)
  14. libc_hidden_proto(setresuid)
  15. libc_hidden_proto(setreuid)
  16. int seteuid(uid_t uid)
  17. {
  18. int result;
  19. if (uid == (uid_t) ~0)
  20. {
  21. __set_errno (EINVAL);
  22. return -1;
  23. }
  24. #ifdef __NR_setresuid
  25. result = setresuid(-1, uid, -1);
  26. if (result == -1 && errno == ENOSYS)
  27. /* Will also set the saved user ID if euid != uid,
  28. * making it impossible to switch back...*/
  29. #endif
  30. result = setreuid(-1, uid);
  31. return result;
  32. }
  33. libc_hidden_def(seteuid)