uid.c 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /*
  2. * Copyright 2001-2018 The OpenSSL Project Authors. All Rights Reserved.
  3. *
  4. * Licensed under the Apache License 2.0 (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(OPENSSL_SYS_WIN32) || defined(OPENSSL_SYS_VXWORKS) || defined(OPENSSL_SYS_UEFI)
  12. int OPENSSL_issetugid(void)
  13. {
  14. return 0;
  15. }
  16. #elif defined(__OpenBSD__) || (defined(__FreeBSD__) && __FreeBSD__ > 2) || defined(__DragonFly__)
  17. # include <unistd.h>
  18. int OPENSSL_issetugid(void)
  19. {
  20. return issetugid();
  21. }
  22. #else
  23. # include <unistd.h>
  24. # include <sys/types.h>
  25. # if defined(__GLIBC__) && defined(__GLIBC_PREREQ)
  26. # if __GLIBC_PREREQ(2, 16)
  27. # include <sys/auxv.h>
  28. # define OSSL_IMPLEMENT_GETAUXVAL
  29. # endif
  30. # endif
  31. int OPENSSL_issetugid(void)
  32. {
  33. # ifdef OSSL_IMPLEMENT_GETAUXVAL
  34. return getauxval(AT_SECURE) != 0;
  35. # else
  36. return getuid() != geteuid() || getgid() != getegid();
  37. # endif
  38. }
  39. #endif