seteuid.c 851 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  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. libc_hidden_proto(seteuid)
  13. #if defined __NR_setresuid || defined __NR_setresuid32
  14. libc_hidden_proto(setresuid)
  15. #endif
  16. libc_hidden_proto(setreuid)
  17. int seteuid(uid_t uid)
  18. {
  19. int result;
  20. if (uid == (uid_t) ~0)
  21. {
  22. __set_errno (EINVAL);
  23. return -1;
  24. }
  25. #if defined __NR_setresuid || defined __NR_setresuid32
  26. result = setresuid(-1, uid, -1);
  27. if (result == -1 && errno == ENOSYS)
  28. /* Will also set the saved user ID if euid != uid,
  29. * making it impossible to switch back...*/
  30. #endif
  31. result = setreuid(-1, uid);
  32. return result;
  33. }
  34. libc_hidden_def(seteuid)