Debian Codegraph @

src/system/interface.rs

raw symbols SCIP
1 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::{ffirust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/::CStrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ffi/c_str/CStr#, fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Displayrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Display#, numrust-analyzer cargo std https://github.com/rust-lang/rust/library/std num/::ParseIntErrorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/error/ParseIntError#, strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/::FromStrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/traits/FromStr#};
2
3 /// Represents a group ID in the system.
4 ///
5 /// `GroupId` is transparent because the memory mapping should stay the same as the underlying
6 /// type, so we can safely cast as a pointer.
7 /// See the implementation in `system::mod::set_target_user`.
8 #[repr(transparent)]
9 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:, PartialOrdrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd:, Ordrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ord:, Hashrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/macros/Hash:)]
10 pub struct GroupIdrust-analyzer cargo sudo-rs 0.2.14 system/interface/GroupId#(libcrust-analyzer cargo libc 0.2.186 crate/::gid_trust-analyzer cargo libc 0.2.186 unix/gid_t#);
11
12 /// Represents a user ID in the system.
13 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:, PartialOrdrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd:, Ordrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ord:, Hashrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/macros/Hash:)]
14 pub struct UserIdrust-analyzer cargo sudo-rs 0.2.14 system/interface/UserId#(libcrust-analyzer cargo libc 0.2.186 crate/::uid_trust-analyzer cargo libc 0.2.186 unix/uid_t#);
15
16 /// Represents a process ID in the system.
17 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:, PartialOrdrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd:, Ordrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ord:, Hashrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/macros/Hash:)]
18 pub struct ProcessIdrust-analyzer cargo sudo-rs 0.2.14 system/interface/ProcessId#(libcrust-analyzer cargo libc 0.2.186 crate/::pid_trust-analyzer cargo libc 0.2.186 unix/pid_t#);
19
20 /// Represents a device ID in the system.
21 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:, PartialOrdrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd:, Ordrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ord:, Hashrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/macros/Hash:)]
22 pub struct DeviceIdrust-analyzer cargo sudo-rs 0.2.14 system/interface/DeviceId#(libcrust-analyzer cargo libc 0.2.186 crate/::dev_trust-analyzer cargo libc 0.2.186 unix/linux_like/linux/dev_t#);
23
24 impl GroupIdrust-analyzer cargo sudo-rs 0.2.14 system/interface/GroupId# {
25 pub fn newrust-analyzer cargo sudo-rs 0.2.14 system/interface/impl#[GroupId]new().(id: libcrust-analyzer cargo libc 0.2.186 crate/::gid_trust-analyzer cargo libc 0.2.186 unix/gid_t#) -> Selfrust-analyzer cargo sudo-rs 0.2.14 system/interface/impl#[GroupId] {
26 Selfrust-analyzer cargo sudo-rs 0.2.14 system/interface/impl#[GroupId](id)
27 }
28
29 pub fn innerrust-analyzer cargo sudo-rs 0.2.14 system/interface/impl#[GroupId]inner().(&self) -> libcrust-analyzer cargo libc 0.2.186 crate/::gid_trust-analyzer cargo libc 0.2.186 unix/gid_t# {
30 self.0rust-analyzer cargo sudo-rs 0.2.14 system/interface/GroupId#0.
31 }
32 }
33
34 impl UserIdrust-analyzer cargo sudo-rs 0.2.14 system/interface/UserId# {
35 pub fn newrust-analyzer cargo sudo-rs 0.2.14 system/interface/impl#[UserId]new().(id: libcrust-analyzer cargo libc 0.2.186 crate/::uid_trust-analyzer cargo libc 0.2.186 unix/uid_t#) -> Selfrust-analyzer cargo sudo-rs 0.2.14 system/interface/impl#[UserId] {
36 Selfrust-analyzer cargo sudo-rs 0.2.14 system/interface/impl#[UserId](id)
37 }
38
39 pub fn innerrust-analyzer cargo sudo-rs 0.2.14 system/interface/impl#[UserId]inner().(&self) -> libcrust-analyzer cargo libc 0.2.186 crate/::uid_trust-analyzer cargo libc 0.2.186 unix/uid_t# {
40 self.0rust-analyzer cargo sudo-rs 0.2.14 system/interface/UserId#0.
41 }
42
43 pub const ROOTrust-analyzer cargo sudo-rs 0.2.14 system/interface/impl#[UserId]ROOT.: Selfrust-analyzer cargo sudo-rs 0.2.14 system/interface/impl#[UserId] = Selfrust-analyzer cargo sudo-rs 0.2.14 system/interface/impl#[UserId](0);
44 }
45
46 impl ProcessIdrust-analyzer cargo sudo-rs 0.2.14 system/interface/ProcessId# {
47 pub fn newrust-analyzer cargo sudo-rs 0.2.14 system/interface/impl#[ProcessId]new().(id: libcrust-analyzer cargo libc 0.2.186 crate/::pid_trust-analyzer cargo libc 0.2.186 unix/pid_t#) -> Selfrust-analyzer cargo sudo-rs 0.2.14 system/interface/impl#[ProcessId] {
48 Selfrust-analyzer cargo sudo-rs 0.2.14 system/interface/impl#[ProcessId](id)
49 }
50
51 pub fn innerrust-analyzer cargo sudo-rs 0.2.14 system/interface/impl#[ProcessId]inner().(&self) -> libcrust-analyzer cargo libc 0.2.186 crate/::pid_trust-analyzer cargo libc 0.2.186 unix/pid_t# {
52 self.0rust-analyzer cargo sudo-rs 0.2.14 system/interface/ProcessId#0.
53 }
54
55 pub fn is_validrust-analyzer cargo sudo-rs 0.2.14 system/interface/impl#[ProcessId]is_valid().(&self) -> bool {
56 self.0rust-analyzer cargo sudo-rs 0.2.14 system/interface/ProcessId#0. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialEq<Self>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialEq<Self>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialEq<Self>`]ne().0
57 }
58 }
59
60 impl DeviceIdrust-analyzer cargo sudo-rs 0.2.14 system/interface/DeviceId# {
61 pub fn newrust-analyzer cargo sudo-rs 0.2.14 system/interface/impl#[DeviceId]new().(id: libcrust-analyzer cargo libc 0.2.186 crate/::dev_trust-analyzer cargo libc 0.2.186 unix/linux_like/linux/dev_t#) -> Selfrust-analyzer cargo sudo-rs 0.2.14 system/interface/impl#[DeviceId] {
62 Selfrust-analyzer cargo sudo-rs 0.2.14 system/interface/impl#[DeviceId](id)
63 }
64
65 pub fn innerrust-analyzer cargo sudo-rs 0.2.14 system/interface/impl#[DeviceId]inner().(&self) -> libcrust-analyzer cargo libc 0.2.186 crate/::dev_trust-analyzer cargo libc 0.2.186 unix/linux_like/linux/dev_t# {
66 self.0rust-analyzer cargo sudo-rs 0.2.14 system/interface/DeviceId#0.
67 }
68 }
69
70 impl Displayrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Display# for GroupIdrust-analyzer cargo sudo-rs 0.2.14 system/interface/GroupId# {
71 fn fmtrust-analyzer cargo sudo-rs 0.2.14 system/interface/impl#[GroupId][Display]fmt().(&self, f: &mut stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Formatterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Formatter#<'_>) -> stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Result# {
72 writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(f, "{}", self.0rust-analyzer cargo sudo-rs 0.2.14 system/interface/GroupId#0.)
73 }
74 }
75
76 impl Displayrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Display# for UserIdrust-analyzer cargo sudo-rs 0.2.14 system/interface/UserId# {
77 fn fmtrust-analyzer cargo sudo-rs 0.2.14 system/interface/impl#[UserId][Display]fmt().(&self, f: &mut stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Formatterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Formatter#<'_>) -> stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Result# {
78 writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(f, "{}", self.0rust-analyzer cargo sudo-rs 0.2.14 system/interface/UserId#0.)
79 }
80 }
81
82 impl Displayrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Display# for ProcessIdrust-analyzer cargo sudo-rs 0.2.14 system/interface/ProcessId# {
83 fn fmtrust-analyzer cargo sudo-rs 0.2.14 system/interface/impl#[ProcessId][Display]fmt().(&self, f: &mut stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Formatterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Formatter#<'_>) -> stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Result# {
84 writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(f, "{}", self.0rust-analyzer cargo sudo-rs 0.2.14 system/interface/ProcessId#0.)
85 }
86 }
87
88 impl Displayrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Display# for DeviceIdrust-analyzer cargo sudo-rs 0.2.14 system/interface/DeviceId# {
89 fn fmtrust-analyzer cargo sudo-rs 0.2.14 system/interface/impl#[DeviceId][Display]fmt().(&self, f: &mut stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Formatterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Formatter#<'_>) -> stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Result# {
90 writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(f, "{}", self.0rust-analyzer cargo sudo-rs 0.2.14 system/interface/DeviceId#0.)
91 }
92 }
93
94 impl FromStrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/traits/FromStr# for GroupIdrust-analyzer cargo sudo-rs 0.2.14 system/interface/GroupId# {
95 type Errrust-analyzer cargo sudo-rs 0.2.14 system/interface/impl#[GroupId][FromStr]Err# = ParseIntErrorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/error/ParseIntError#;
96
97 fn from_strrust-analyzer cargo sudo-rs 0.2.14 system/interface/impl#[GroupId][FromStr]from_str().(s: &str) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Selfrust-analyzer cargo sudo-rs 0.2.14 system/interface/impl#[GroupId][FromStr], Selfrust-analyzer cargo sudo-rs 0.2.14 system/interface/impl#[GroupId][FromStr]::Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/traits/FromStr#Err#> {
98 s.parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().::<libcrust-analyzer cargo libc 0.2.186 crate/::gid_trust-analyzer cargo libc 0.2.186 unix/gid_t#>().maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map().(GroupIdrust-analyzer cargo sudo-rs 0.2.14 system/interface/GroupId#::newrust-analyzer cargo sudo-rs 0.2.14 system/interface/impl#[GroupId]new().)
99 }
100 }
101
102 impl FromStrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/traits/FromStr# for UserIdrust-analyzer cargo sudo-rs 0.2.14 system/interface/UserId# {
103 type Errrust-analyzer cargo sudo-rs 0.2.14 system/interface/impl#[UserId][FromStr]Err# = ParseIntErrorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/error/ParseIntError#;
104
105 fn from_strrust-analyzer cargo sudo-rs 0.2.14 system/interface/impl#[UserId][FromStr]from_str().(s: &str) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Selfrust-analyzer cargo sudo-rs 0.2.14 system/interface/impl#[UserId][FromStr], Selfrust-analyzer cargo sudo-rs 0.2.14 system/interface/impl#[UserId][FromStr]::Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/traits/FromStr#Err#> {
106 s.parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().::<libcrust-analyzer cargo libc 0.2.186 crate/::uid_trust-analyzer cargo libc 0.2.186 unix/uid_t#>().maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map().(UserIdrust-analyzer cargo sudo-rs 0.2.14 system/interface/UserId#::newrust-analyzer cargo sudo-rs 0.2.14 system/interface/impl#[UserId]new().)
107 }
108 }
109
110 /// This trait/module is here to not make this crate independent (at the present time) in the idiosyncrasies of user representation details
111 /// (which we may decide over time), as well as to make explicit what functionality a user-representation must have; this
112 /// interface is not set in stone and "easy" to change.
113 pub trait UnixUserrust-analyzer cargo sudo-rs 0.2.14 system/interface/UnixUser# {
114 fn has_namerust-analyzer cargo sudo-rs 0.2.14 system/interface/UnixUser#has_name().(&self, _name: &str) -> bool;
115 fn has_uidrust-analyzer cargo sudo-rs 0.2.14 system/interface/UnixUser#has_uid().(&self, _uid: UserIdrust-analyzer cargo sudo-rs 0.2.14 system/interface/UserId#) -> bool;
116 fn is_rootrust-analyzer cargo sudo-rs 0.2.14 system/interface/UnixUser#is_root().(&self) -> bool;
117 fn in_group_by_namerust-analyzer cargo sudo-rs 0.2.14 system/interface/UnixUser#in_group_by_name().(&self, _name: &CStrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ffi/c_str/CStr#) -> bool;
118 fn in_group_by_gidrust-analyzer cargo sudo-rs 0.2.14 system/interface/UnixUser#in_group_by_gid().(&self, _gid: GroupIdrust-analyzer cargo sudo-rs 0.2.14 system/interface/GroupId#) -> bool;
119
120 type Grouprust-analyzer cargo sudo-rs 0.2.14 system/interface/UnixUser#Group#: UnixGrouprust-analyzer cargo sudo-rs 0.2.14 system/interface/UnixGroup#;
121 fn grouprust-analyzer cargo sudo-rs 0.2.14 system/interface/UnixUser#group().(&self) -> Self::Grouprust-analyzer cargo sudo-rs 0.2.14 system/interface/UnixUser#Group#;
122 }
123
124 pub trait UnixGrouprust-analyzer cargo sudo-rs 0.2.14 system/interface/UnixGroup# {
125 fn as_gidrust-analyzer cargo sudo-rs 0.2.14 system/interface/UnixGroup#as_gid().(&self) -> GroupIdrust-analyzer cargo sudo-rs 0.2.14 system/interface/GroupId#;
126 fn try_as_namerust-analyzer cargo sudo-rs 0.2.14 system/interface/UnixGroup#try_as_name().(&self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&str>;
127 }
128
129 impl UnixUserrust-analyzer cargo sudo-rs 0.2.14 system/interface/UnixUser# for superrust-analyzer cargo sudo-rs 0.2.14 system/::Userrust-analyzer cargo sudo-rs 0.2.14 system/User# {
130 fn has_namerust-analyzer cargo sudo-rs 0.2.14 system/interface/impl#[`super::User`][UnixUser]has_name().(&self, name: &str) -> bool {
131 self.namerust-analyzer cargo sudo-rs 0.2.14 system/User#name. rust-analyzer cargo sudo-rs 0.2.14 common/string/impl#[SudoString][`PartialEq<&str>`]eq().==rust-analyzer cargo sudo-rs 0.2.14 common/string/impl#[SudoString][`PartialEq<&str>`]eq(). rust-analyzer cargo sudo-rs 0.2.14 common/string/impl#[SudoString][`PartialEq<&str>`]eq().name
132 }
133 fn has_uidrust-analyzer cargo sudo-rs 0.2.14 system/interface/impl#[`super::User`][UnixUser]has_uid().(&self, uid: UserIdrust-analyzer cargo sudo-rs 0.2.14 system/interface/UserId#) -> bool {
134 self.uidrust-analyzer cargo sudo-rs 0.2.14 system/User#uid. rust-analyzer cargo sudo-rs 0.2.14 system/interface/impl#[UserId][`PartialEq<Self>`]eq().==rust-analyzer cargo sudo-rs 0.2.14 system/interface/impl#[UserId][`PartialEq<Self>`]eq(). rust-analyzer cargo sudo-rs 0.2.14 system/interface/impl#[UserId][`PartialEq<Self>`]eq().uid
135 }
136 fn is_rootrust-analyzer cargo sudo-rs 0.2.14 system/interface/impl#[`super::User`][UnixUser]is_root().(&self) -> bool {
137 self.has_uidrust-analyzer cargo sudo-rs 0.2.14 system/interface/impl#[`super::User`][UnixUser]has_uid().(UserIdrust-analyzer cargo sudo-rs 0.2.14 system/interface/UserId#::ROOTrust-analyzer cargo sudo-rs 0.2.14 system/interface/impl#[UserId]ROOT.)
138 }
139 fn in_group_by_namerust-analyzer cargo sudo-rs 0.2.14 system/interface/impl#[`super::User`][UnixUser]in_group_by_name().(&self, name_c: &CStrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ffi/c_str/CStr#) -> bool {
140 if let Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(group)) = superrust-analyzer cargo sudo-rs 0.2.14 system/::Grouprust-analyzer cargo sudo-rs 0.2.14 system/Group#::from_namerust-analyzer cargo sudo-rs 0.2.14 system/impl#[Group]from_name().(name_c) {
141 self.in_group_by_gidrust-analyzer cargo sudo-rs 0.2.14 system/interface/impl#[`super::User`][UnixUser]in_group_by_gid().(group.gidrust-analyzer cargo sudo-rs 0.2.14 system/Group#gid.)
142 } else {
143 false
144 }
145 }
146 fn in_group_by_gidrust-analyzer cargo sudo-rs 0.2.14 system/interface/impl#[`super::User`][UnixUser]in_group_by_gid().(&self, gid: GroupIdrust-analyzer cargo sudo-rs 0.2.14 system/interface/GroupId#) -> bool {
147 self.groupsrust-analyzer cargo sudo-rs 0.2.14 system/User#groups..containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]contains().(&gid)
148 }
149 type Grouprust-analyzer cargo sudo-rs 0.2.14 system/interface/impl#[`super::User`][UnixUser]Group# = superrust-analyzer cargo sudo-rs 0.2.14 system/::Grouprust-analyzer cargo sudo-rs 0.2.14 system/Group#;
150 fn grouprust-analyzer cargo sudo-rs 0.2.14 system/interface/impl#[`super::User`][UnixUser]group().(&self) -> superrust-analyzer cargo sudo-rs 0.2.14 system/::Grouprust-analyzer cargo sudo-rs 0.2.14 system/Group# {
151 Selfrust-analyzer cargo sudo-rs 0.2.14 system/interface/impl#[`super::User`][UnixUser]::Grouprust-analyzer cargo sudo-rs 0.2.14 system/interface/UnixUser#Group# {
152 gidrust-analyzer cargo sudo-rs 0.2.14 system/Group#gid.: self.gidrust-analyzer cargo sudo-rs 0.2.14 system/User#gid.,
153 namerust-analyzer cargo sudo-rs 0.2.14 system/Group#name.: Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#,
154 }
155 }
156 }
157
158 impl UnixGrouprust-analyzer cargo sudo-rs 0.2.14 system/interface/UnixGroup# for superrust-analyzer cargo sudo-rs 0.2.14 system/::Grouprust-analyzer cargo sudo-rs 0.2.14 system/Group# {
159 fn as_gidrust-analyzer cargo sudo-rs 0.2.14 system/interface/impl#[`super::Group`][UnixGroup]as_gid().(&self) -> GroupIdrust-analyzer cargo sudo-rs 0.2.14 system/interface/GroupId# {
160 self.gidrust-analyzer cargo sudo-rs 0.2.14 system/Group#gid.
161 }
162 fn try_as_namerust-analyzer cargo sudo-rs 0.2.14 system/interface/impl#[`super::Group`][UnixGroup]try_as_name().(&self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&str> {
163 self.namerust-analyzer cargo sudo-rs 0.2.14 system/Group#name..as_derefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_deref().()
164 }
165 }
166
167 #[cfg(test)]
168 mod testrust-analyzer cargo sudo-rs 0.2.14 system/interface/test/ {
169 use superrust-analyzer cargo sudo-rs 0.2.14 system/interface/::*;
170 use craterust-analyzer cargo sudo-rs 0.2.14 crate/::systemrust-analyzer cargo sudo-rs 0.2.14 system/::{Grouprust-analyzer cargo sudo-rs 0.2.14 system/Group#, ROOT_GROUP_NAMErust-analyzer cargo sudo-rs 0.2.14 system/ROOT_GROUP_NAME., Userrust-analyzer cargo sudo-rs 0.2.14 system/User#};
171 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::ffirust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/::CStringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc ffi/c_str/CString#;
172
173 fn test_userrust-analyzer cargo sudo-rs 0.2.14 system/interface/test/test_user().(user: impl UnixUserrust-analyzer cargo sudo-rs 0.2.14 system/interface/UnixUser#, name_c: &CStrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ffi/c_str/CStr#) {
174 let name = name_c.to_strrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ffi/c_str/impl#[CStr]to_str().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
175 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(user.has_namerust-analyzer cargo sudo-rs 0.2.14 system/interface/UnixUser#has_name().(name));
176 if user.has_namerust-analyzer cargo sudo-rs 0.2.14 system/interface/UnixUser#has_name().("root") {
177 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(user.in_group_by_namerust-analyzer cargo sudo-rs 0.2.14 system/interface/UnixUser#in_group_by_name().(CStringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc ffi/c_str/CString#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc ffi/c_str/impl#[CString]new().(ROOT_GROUP_NAMErust-analyzer cargo sudo-rs 0.2.14 system/ROOT_GROUP_NAME.).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().().as_c_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc ffi/c_str/impl#[CString]as_c_str().()));
178 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(user.is_rootrust-analyzer cargo sudo-rs 0.2.14 system/interface/UnixUser#is_root().());
179 } else {
180 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(user.in_group_by_namerust-analyzer cargo sudo-rs 0.2.14 system/interface/UnixUser#in_group_by_name().(name_c));
181 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(!rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().user.is_rootrust-analyzer cargo sudo-rs 0.2.14 system/interface/UnixUser#is_root().());
182 }
183 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(user.is_rootrust-analyzer cargo sudo-rs 0.2.14 system/interface/UnixUser#is_root().(), name == "root");
184 }
185
186 fn test_grouprust-analyzer cargo sudo-rs 0.2.14 system/interface/test/test_group().(group: impl UnixGrouprust-analyzer cargo sudo-rs 0.2.14 system/interface/UnixGroup#, name: &str) {
187 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(name == ROOT_GROUP_NAMErust-analyzer cargo sudo-rs 0.2.14 system/ROOT_GROUP_NAME., group.as_gidrust-analyzer cargo sudo-rs 0.2.14 system/interface/UnixGroup#as_gid().() == GroupIdrust-analyzer cargo sudo-rs 0.2.14 system/interface/GroupId#::newrust-analyzer cargo sudo-rs 0.2.14 system/interface/impl#[GroupId]new().(0));
188 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(group.try_as_namerust-analyzer cargo sudo-rs 0.2.14 system/interface/UnixGroup#try_as_name().(), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(name));
189 }
190
191 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
192 fn test_unix_userrust-analyzer cargo sudo-rs 0.2.14 system/interface/test/test_unix_user().() {
193 let user = |name| Userrust-analyzer cargo sudo-rs 0.2.14 system/User#::from_namerust-analyzer cargo sudo-rs 0.2.14 system/impl#[User]from_name().(name).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
194 test_userrust-analyzer cargo sudo-rs 0.2.14 system/interface/test/test_user().(user(c"root"), c"root");
195 test_userrust-analyzer cargo sudo-rs 0.2.14 system/interface/test/test_user().(user(c"daemon"), c"daemon");
196 }
197
198 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
199 fn test_unix_grouprust-analyzer cargo sudo-rs 0.2.14 system/interface/test/test_unix_group().() {
200 let group = |name| Grouprust-analyzer cargo sudo-rs 0.2.14 system/Group#::from_namerust-analyzer cargo sudo-rs 0.2.14 system/impl#[Group]from_name().(name).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
201 let root_group_cstr = CStringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc ffi/c_str/CString#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc ffi/c_str/impl#[CString]new().(ROOT_GROUP_NAMErust-analyzer cargo sudo-rs 0.2.14 system/ROOT_GROUP_NAME.).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
202 test_grouprust-analyzer cargo sudo-rs 0.2.14 system/interface/test/test_group().(group(root_group_cstr.as_c_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc ffi/c_str/impl#[CString]as_c_str().()), ROOT_GROUP_NAMErust-analyzer cargo sudo-rs 0.2.14 system/ROOT_GROUP_NAME.);
203 test_grouprust-analyzer cargo sudo-rs 0.2.14 system/interface/test/test_group().(group(c"daemon"), "daemon");
204 }
205 }