seteuid.c 626 B

1234567891011121314151617181920212223242526272829303132
  1. #define setresuid __setresuid
  2. #define setreuid __setreuid
  3. #define _GNU_SOURCE
  4. #include <unistd.h>
  5. #include <stdio.h>
  6. #include <errno.h>
  7. #include <pwd.h>
  8. #include <sys/types.h>
  9. #include <sys/syscall.h>
  10. int attribute_hidden __seteuid(uid_t uid)
  11. {
  12. int result;
  13. if (uid == (uid_t) ~0)
  14. {
  15. __set_errno (EINVAL);
  16. return -1;
  17. }
  18. #ifdef __NR_setresuid
  19. result = setresuid(-1, uid, -1);
  20. if (result == -1 && errno == ENOSYS)
  21. /* Will also set the saved user ID if euid != uid,
  22. * making it impossible to switch back...*/
  23. #endif
  24. result = setreuid(-1, uid);
  25. return result;
  26. }
  27. strong_alias(__seteuid,seteuid)