#sudo #root #process-running #administrator #unix #windows

is_sudo

Checks whether the process is running as root/sudo/admin permission in Windows and Unix systems

1 unstable release

0.0.1 Aug 6, 2022

#19 in #process-running

MIT license

8KB
91 lines

Is_sudo

Checks if program is running as sudo in unix systems, or using admin permission in windows.

Usage

use is_sudo::check;
use is_sudo::RunningAs;

fn main() {
    let running_as: RunningAs = is_sudo::check();

    match running_as {
        RunningAs::Root => println!("Running as root"),
        RunningAs::User => println!("Running as user"),
    }
}

lib.rs:

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, it is not tested.

Dependencies

~47–355KB