xref: /freebsd/crypto/openssl/crypto/uid.c (revision b077aed33b7b6aefca7b17ddb250cf521f938613)
1e71b7053SJung-uk Kim /*
29a3ae0cdSJung-uk Kim  * Copyright 2001-2021 The OpenSSL Project Authors. All Rights Reserved.
35740a5e3SKris Kennaway  *
4*b077aed3SPierre Pronchery  * Licensed under the Apache License 2.0 (the "License").  You may not use
5e71b7053SJung-uk Kim  * this file except in compliance with the License.  You can obtain a copy
6e71b7053SJung-uk Kim  * in the file LICENSE in the source distribution or at
7e71b7053SJung-uk Kim  * https://www.openssl.org/source/license.html
85740a5e3SKris Kennaway  */
95740a5e3SKris Kennaway 
105740a5e3SKris Kennaway #include <openssl/crypto.h>
115c87c606SMark Murray #include <openssl/opensslconf.h>
125740a5e3SKris Kennaway 
13da327cd2SJung-uk Kim #if defined(OPENSSL_SYS_WIN32) || defined(OPENSSL_SYS_VXWORKS) || defined(OPENSSL_SYS_UEFI)
14da327cd2SJung-uk Kim 
OPENSSL_issetugid(void)15da327cd2SJung-uk Kim int OPENSSL_issetugid(void)
16da327cd2SJung-uk Kim {
17da327cd2SJung-uk Kim     return 0;
18da327cd2SJung-uk Kim }
19da327cd2SJung-uk Kim 
20b2bf0c7eSJung-uk Kim #elif defined(__OpenBSD__) || (defined(__FreeBSD__) && __FreeBSD__ > 2) || defined(__DragonFly__) || (defined(__GLIBC__) && defined(__FreeBSD_kernel__))
215740a5e3SKris Kennaway 
22*b077aed3SPierre Pronchery # include <unistd.h>
235740a5e3SKris Kennaway 
OPENSSL_issetugid(void)245740a5e3SKris Kennaway int OPENSSL_issetugid(void)
255740a5e3SKris Kennaway {
265740a5e3SKris Kennaway     return issetugid();
275740a5e3SKris Kennaway }
285740a5e3SKris Kennaway 
295740a5e3SKris Kennaway #else
305740a5e3SKris Kennaway 
31*b077aed3SPierre Pronchery # include <unistd.h>
325740a5e3SKris Kennaway # include <sys/types.h>
335740a5e3SKris Kennaway 
34e71b7053SJung-uk Kim # if defined(__GLIBC__) && defined(__GLIBC_PREREQ)
35e71b7053SJung-uk Kim #  if __GLIBC_PREREQ(2, 16)
36e71b7053SJung-uk Kim #   include <sys/auxv.h>
376935a639SJung-uk Kim #   define OSSL_IMPLEMENT_GETAUXVAL
38e71b7053SJung-uk Kim #  endif
399a3ae0cdSJung-uk Kim # elif defined(__ANDROID_API__)
409a3ae0cdSJung-uk Kim /* see https://developer.android.google.cn/ndk/guides/cpu-features */
419a3ae0cdSJung-uk Kim #  if __ANDROID_API__ >= 18
429a3ae0cdSJung-uk Kim #   include <sys/auxv.h>
439a3ae0cdSJung-uk Kim #   define OSSL_IMPLEMENT_GETAUXVAL
449a3ae0cdSJung-uk Kim #  endif
45e71b7053SJung-uk Kim # endif
46e71b7053SJung-uk Kim 
OPENSSL_issetugid(void)475740a5e3SKris Kennaway int OPENSSL_issetugid(void)
485740a5e3SKris Kennaway {
496935a639SJung-uk Kim # ifdef OSSL_IMPLEMENT_GETAUXVAL
50e71b7053SJung-uk Kim     return getauxval(AT_SECURE) != 0;
51e71b7053SJung-uk Kim # else
52e71b7053SJung-uk Kim     return getuid() != geteuid() || getgid() != getegid();
53e71b7053SJung-uk Kim # endif
545740a5e3SKris Kennaway }
555740a5e3SKris Kennaway #endif
56