seteuid.c 750 B

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