pub fn requires_secure_execution() -> bool
Expand description
Returns whether the running executable requires secure execution.
This property is relevant for code that might be executed as part of a set-user-ID or set-group-ID binary or similar.
Quoting the glibc manual pages:
The GNU-specific
secure_getenv()
function is just likegetenv()
except that it returnsNULL
in cases where “secure execution” is required.The
secure_getenv()
function is intended for use in general-purpose libraries to avoid vulnerabilities that could occur if set-user-ID or set-group-ID programs accidentally trusted the environment.
Quoting the OpenBSD manual pages:
In particular, it is wise to use [this property] to determine if a pathname returned from a
getenv()
call may safely be used toopen()
the specified file.
How this function determines this property depends on the target_os
value.
-
If
target_os
is one oflinux
orandroid
, theAT_SECURE
value fromgetauxval
is used. Seegetauxval(3)
for details. -
Otherwise, if
target_os
is one ofmacos
,ios
,watchos
,tvos
,visionos
,dragonfly
,freebsd
,illumos
,netbsd
,openbsd
, orsolaris
, the return value ofissetugid
is used.The behavior of this function differs between operating systems, but it is always defined to be used for this purpose. See for example the manual pages of OpenBSD and FreeBSD.
Note that, on FreeBSD and other operating systems using the same model, the return value of
issetugid
can change at runtime. But this function always caches the result when it is called for the first time. -
Otherwise, if
cfg(unix)
, this function always returnstrue
. As of this writing, this affects the followingtarget_os
values:aix
,emscripten
,espidf
,fuchsia
,haiku
,horizon
,hurd
,l4re
,nto
,nuttx
,redox
,rtems
,vita
, andvxworks
-
Otherwise, this function always returns
false
. As of this writing, this affects the followingtarget_os
values:cuda
,hermit
,psp
,solid_asp3
,teeos
,trusty
,uefi
,wasi
,windows
,xous
, andzkvm