pub fn requires_secure_execution() -> boolExpand 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 returnsNULLin 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_osis one oflinuxorandroid, theAT_SECUREvalue fromgetauxvalis used. Seegetauxval(3)for details. -
Otherwise, if
target_osis one ofmacos,ios,watchos,tvos,visionos,dragonfly,freebsd,illumos,netbsd,openbsd, orsolaris, the return value ofissetugidis 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
issetugidcan 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_osvalues: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_osvalues:cuda,hermit,psp,solid_asp3,teeos,trusty,uefi,wasi,windows,xous, andzkvm