11cb0ef41Sopenharmony_ci/* 21cb0ef41Sopenharmony_ci * Copyright 2001-2021 The OpenSSL Project Authors. All Rights Reserved. 31cb0ef41Sopenharmony_ci * 41cb0ef41Sopenharmony_ci * Licensed under the Apache License 2.0 (the "License"). You may not use 51cb0ef41Sopenharmony_ci * this file except in compliance with the License. You can obtain a copy 61cb0ef41Sopenharmony_ci * in the file LICENSE in the source distribution or at 71cb0ef41Sopenharmony_ci * https://www.openssl.org/source/license.html 81cb0ef41Sopenharmony_ci */ 91cb0ef41Sopenharmony_ci 101cb0ef41Sopenharmony_ci#include <openssl/crypto.h> 111cb0ef41Sopenharmony_ci#include <openssl/opensslconf.h> 121cb0ef41Sopenharmony_ci 131cb0ef41Sopenharmony_ci#if defined(OPENSSL_SYS_WIN32) || defined(OPENSSL_SYS_VXWORKS) || defined(OPENSSL_SYS_UEFI) 141cb0ef41Sopenharmony_ci 151cb0ef41Sopenharmony_ciint OPENSSL_issetugid(void) 161cb0ef41Sopenharmony_ci{ 171cb0ef41Sopenharmony_ci return 0; 181cb0ef41Sopenharmony_ci} 191cb0ef41Sopenharmony_ci 201cb0ef41Sopenharmony_ci#elif defined(__OpenBSD__) || (defined(__FreeBSD__) && __FreeBSD__ > 2) || defined(__DragonFly__) || (defined(__GLIBC__) && defined(__FreeBSD_kernel__)) 211cb0ef41Sopenharmony_ci 221cb0ef41Sopenharmony_ci# include <unistd.h> 231cb0ef41Sopenharmony_ci 241cb0ef41Sopenharmony_ciint OPENSSL_issetugid(void) 251cb0ef41Sopenharmony_ci{ 261cb0ef41Sopenharmony_ci return issetugid(); 271cb0ef41Sopenharmony_ci} 281cb0ef41Sopenharmony_ci 291cb0ef41Sopenharmony_ci#else 301cb0ef41Sopenharmony_ci 311cb0ef41Sopenharmony_ci# include <unistd.h> 321cb0ef41Sopenharmony_ci# include <sys/types.h> 331cb0ef41Sopenharmony_ci 341cb0ef41Sopenharmony_ci# if defined(__GLIBC__) && defined(__GLIBC_PREREQ) 351cb0ef41Sopenharmony_ci# if __GLIBC_PREREQ(2, 16) 361cb0ef41Sopenharmony_ci# include <sys/auxv.h> 371cb0ef41Sopenharmony_ci# define OSSL_IMPLEMENT_GETAUXVAL 381cb0ef41Sopenharmony_ci# endif 391cb0ef41Sopenharmony_ci# elif defined(__ANDROID_API__) 401cb0ef41Sopenharmony_ci/* see https://developer.android.google.cn/ndk/guides/cpu-features */ 411cb0ef41Sopenharmony_ci# if __ANDROID_API__ >= 18 421cb0ef41Sopenharmony_ci# include <sys/auxv.h> 431cb0ef41Sopenharmony_ci# define OSSL_IMPLEMENT_GETAUXVAL 441cb0ef41Sopenharmony_ci# endif 451cb0ef41Sopenharmony_ci# endif 461cb0ef41Sopenharmony_ci 471cb0ef41Sopenharmony_ciint OPENSSL_issetugid(void) 481cb0ef41Sopenharmony_ci{ 491cb0ef41Sopenharmony_ci# ifdef OSSL_IMPLEMENT_GETAUXVAL 501cb0ef41Sopenharmony_ci return getauxval(AT_SECURE) != 0; 511cb0ef41Sopenharmony_ci# else 521cb0ef41Sopenharmony_ci return getuid() != geteuid() || getgid() != getegid(); 531cb0ef41Sopenharmony_ci# endif 541cb0ef41Sopenharmony_ci} 551cb0ef41Sopenharmony_ci#endif 56