uid.c 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /*
  2. * Copyright 2001-2018 The OpenSSL Project Authors. All Rights Reserved.
  3. *
  4. * Licensed under the OpenSSL license (the "License"). You may not use
  5. * this file except in compliance with the License. You can obtain a copy
  6. * in the file LICENSE in the source distribution or at
  7. * https://www.openssl.org/source/license.html
  8. */
  9. #include <openssl/crypto.h>
  10. #include <openssl/opensslconf.h>
  11. #if defined(__OpenBSD__) || (defined(__FreeBSD__) && __FreeBSD__ > 2) || defined(__DragonFly__)
  12. # include OPENSSL_UNISTD
  13. int OPENSSL_issetugid(void)
  14. {
  15. return issetugid();
  16. }
  17. #elif defined(OPENSSL_SYS_WIN32) || defined(OPENSSL_SYS_VXWORKS) || defined(OPENSSL_SYS_UEFI)
  18. int OPENSSL_issetugid(void)
  19. {
  20. return 0;
  21. }
  22. #else
  23. # include OPENSSL_UNISTD
  24. # include <sys/types.h>
  25. # if defined(__GLIBC__) && defined(__GLIBC_PREREQ)
  26. # if __GLIBC_PREREQ(2, 16)
  27. # include <sys/auxv.h>
  28. # endif
  29. # endif
  30. int OPENSSL_issetugid(void)
  31. {
  32. # ifdef AT_SECURE
  33. return getauxval(AT_SECURE) != 0;
  34. # else
  35. return getuid() != geteuid() || getgid() != getegid();
  36. # endif
  37. }
  38. #endif