Skip to main content

privasserted

Function privasserted 

Source
pub fn privasserted() -> bool
Expand description

Port of privasserted() from Src/utils.c:7607.

“Check whether the shell is running with privileges in effect. This is the case if EITHER the euid is zero, OR (if the system supports POSIX.1e (POSIX.6) capability sets) the process’ Effective or Inheritable capability sets are non-empty.”

if (!geteuid()) return 1;
#ifdef HAVE_CAP_GET_PROC
    cap_t caps = cap_get_proc();
    if (caps) {
        cap_flag_value_t val;
        for (cap_value_t cap = 0;
             !cap_get_flag(caps, cap, CAP_EFFECTIVE, &val); cap++)
            if (val && cap != CAP_WAKE_ALARM) {
                cap_free(caps);
                return 1;
            }
    }
    cap_free(caps);
#endif
    return 0;

The previous Rust port checked getuid() != geteuid() which is the SUID-binary detection, not the “running with privileges” check. The capability-set inspection requires libcap (gated behind the libcap feature in crate::ported::modules::cap); without it, only the euid==0 path is exercised — same as the C #else arm when HAVE_CAP_GET_PROC isn’t defined.