Crate sudo2

Source
Expand description

crates.io docs.rs

Detect if you are running as root, restart self with sudo if needed or setup uid zero when running with the SUID flag set.

§Requirements

  • The sudo program is required to be installed and setup correctly on the target system.
  • Linux or Mac OS X tested
    • It should work on *BSD. However, you can also create an Escalate builder with doas as the wrapper should you prefer that.

Structs§

Escalate

Enums§

RunningAs
Cross platform representation of the state the current program running

Functions§

builder
Alias for Escalate::builder() to quickly create a new sudo Escalate builder
doas
Similar to escalate_if_needed, but with doas as the wrapper
escalate_if_needed
Restart your program with sudo if the user is not privileged enough.
escalate_with_env
Restart your program with sudo and if the user is not privileged enough. Inherit all environment variables.
pkexec
Similar to escalate_if_needed, but with pkexec as the wrapper
running_as_root
Returns true if binary is already running as root.
running_as_suid
Returns true if binary is already running as suid.
with_env
Escalate privileges while maintaining RUST_BACKTRACE and selected environment variables (or none).
with_env_wildcards
Escalate privileges while maintaining RUST_BACKTRACE and selected environment variables that matches given wildcard (or none).