1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
//! [](https://crates.io/crates/sudo/)
//! [](https://docs.rs/sudo)
//!
//! 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.
use crate Root;
use crate User;
/// Cross platform representation of the state the current program running
/// This checks whether the current process is running as sudo or not.
/// Returns the RunningAs enum as result
/// # Examples
/// ```rust
/// use is_sudo::RunningAs;
/// let running_as = is_sudo::check();
/// match running_as {
/// RunningAs::Root => println!("Running as root"),
/// RunningAs::User => println!("Running as user"),
/// }
/// ```
// Use windows-rs crate to check admin permission in windows
/// This checks whether the current process is running as admin(root) or not.
/// Returns the RunningAs enum as result
/// # Examples
/// ```rust
/// use is_sudo::RunningAs;
/// let running_as = is_sudo::check();
/// match running_as {
/// RunningAs::Root => println!("Running as root"),
/// RunningAs::User => println!("Running as user"),
/// }
/// ```