1e1051a39Sopenharmony_ci/*
2e1051a39Sopenharmony_ci * Copyright 2001-2021 The OpenSSL Project Authors. All Rights Reserved.
3e1051a39Sopenharmony_ci *
4e1051a39Sopenharmony_ci * Licensed under the Apache License 2.0 (the "License").  You may not use
5e1051a39Sopenharmony_ci * this file except in compliance with the License.  You can obtain a copy
6e1051a39Sopenharmony_ci * in the file LICENSE in the source distribution or at
7e1051a39Sopenharmony_ci * https://www.openssl.org/source/license.html
8e1051a39Sopenharmony_ci */
9e1051a39Sopenharmony_ci
10e1051a39Sopenharmony_ci#include <openssl/crypto.h>
11e1051a39Sopenharmony_ci#include <openssl/opensslconf.h>
12e1051a39Sopenharmony_ci
13e1051a39Sopenharmony_ci#if defined(OPENSSL_SYS_WIN32) || defined(OPENSSL_SYS_VXWORKS) || defined(OPENSSL_SYS_UEFI)
14e1051a39Sopenharmony_ci
15e1051a39Sopenharmony_ciint OPENSSL_issetugid(void)
16e1051a39Sopenharmony_ci{
17e1051a39Sopenharmony_ci    return 0;
18e1051a39Sopenharmony_ci}
19e1051a39Sopenharmony_ci
20e1051a39Sopenharmony_ci#elif defined(__OpenBSD__) || (defined(__FreeBSD__) && __FreeBSD__ > 2) || defined(__DragonFly__) || (defined(__GLIBC__) && defined(__FreeBSD_kernel__))
21e1051a39Sopenharmony_ci
22e1051a39Sopenharmony_ci# include <unistd.h>
23e1051a39Sopenharmony_ci
24e1051a39Sopenharmony_ciint OPENSSL_issetugid(void)
25e1051a39Sopenharmony_ci{
26e1051a39Sopenharmony_ci    return issetugid();
27e1051a39Sopenharmony_ci}
28e1051a39Sopenharmony_ci
29e1051a39Sopenharmony_ci#else
30e1051a39Sopenharmony_ci
31e1051a39Sopenharmony_ci# include <unistd.h>
32e1051a39Sopenharmony_ci# include <sys/types.h>
33e1051a39Sopenharmony_ci
34e1051a39Sopenharmony_ci# if defined(__GLIBC__) && defined(__GLIBC_PREREQ)
35e1051a39Sopenharmony_ci#  if __GLIBC_PREREQ(2, 16)
36e1051a39Sopenharmony_ci#   include <sys/auxv.h>
37e1051a39Sopenharmony_ci#   define OSSL_IMPLEMENT_GETAUXVAL
38e1051a39Sopenharmony_ci#  endif
39e1051a39Sopenharmony_ci# elif defined(__ANDROID_API__)
40e1051a39Sopenharmony_ci/* see https://developer.android.google.cn/ndk/guides/cpu-features */
41e1051a39Sopenharmony_ci#  if __ANDROID_API__ >= 18
42e1051a39Sopenharmony_ci#   include <sys/auxv.h>
43e1051a39Sopenharmony_ci#   define OSSL_IMPLEMENT_GETAUXVAL
44e1051a39Sopenharmony_ci#  endif
45e1051a39Sopenharmony_ci# endif
46e1051a39Sopenharmony_ci
47e1051a39Sopenharmony_ciint OPENSSL_issetugid(void)
48e1051a39Sopenharmony_ci{
49e1051a39Sopenharmony_ci# ifdef OSSL_IMPLEMENT_GETAUXVAL
50e1051a39Sopenharmony_ci    return getauxval(AT_SECURE) != 0;
51e1051a39Sopenharmony_ci# else
52e1051a39Sopenharmony_ci    return getuid() != geteuid() || getgid() != getegid();
53e1051a39Sopenharmony_ci# endif
54e1051a39Sopenharmony_ci}
55e1051a39Sopenharmony_ci#endif
56