uid.c 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /*
  2. * Copyright 2001-2021 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__) || (defined(__GLIBC__) && defined(__FreeBSD_kernel__))
  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. # elif defined(__ANDROID_API__)
  31. /* see https://developer.android.google.cn/ndk/guides/cpu-features */
  32. # if __ANDROID_API__ >= 18
  33. # include <sys/auxv.h>
  34. # define OSSL_IMPLEMENT_GETAUXVAL
  35. # endif
  36. # endif
  37. int OPENSSL_issetugid(void)
  38. {
  39. # ifdef OSSL_IMPLEMENT_GETAUXVAL
  40. return getauxval(AT_SECURE) != 0;
  41. # else
  42. return getuid() != geteuid() || getgid() != getegid();
  43. # endif
  44. }
  45. #endif