Debian Codegraph @

src/privdrop.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/::{CStringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc ffi/c_str/CString#, OsStrrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/OsStr#, OsStringrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/OsString#};
2 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::osrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/::unixrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/unix/::ffirust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/unix/ffi/::OsStrExtrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/unix/ffi/os_str/OsStrExt#;
3 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/::{Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#, PathBufrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/PathBuf#};
4
5 use nixrust-analyzer cargo nix 0.31.3 crate/::unistdrust-analyzer cargo nix 0.31.3 unistd/;
6
7 use superrust-analyzer cargo privdrop 0.5.4 crate/::errorsrust-analyzer cargo privdrop 0.5.4 errors/::*;
8
9 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
10 fn test_privdroprust-analyzer cargo privdrop 0.5.4 privdrop/test_privdrop().() {
11 if unistdrust-analyzer cargo nix 0.31.3 unistd/::geteuidrust-analyzer cargo nix 0.31.3 unistd/geteuid().().is_rootrust-analyzer cargo nix 0.31.3 unistd/impl#[Uid]is_root().() {
12 PrivDroprust-analyzer cargo privdrop 0.5.4 privdrop/PrivDrop#::defaultrust-analyzer cargo privdrop 0.5.4 privdrop/impl#[PrivDrop][Default]default().()
13 .chrootrust-analyzer cargo privdrop 0.5.4 privdrop/impl#[PrivDrop]chroot().("/var/empty")
14 .userrust-analyzer cargo privdrop 0.5.4 privdrop/impl#[PrivDrop]user().("nobody")
15 .applyrust-analyzer cargo privdrop 0.5.4 privdrop/impl#[PrivDrop]apply().()
16 .unwrap_or_elserust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap_or_else().(|e| panicrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/panic!!("Failed to drop privileges: {}", e));
17 } else {
18 eprintlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/eprintln!!("Test was skipped because it needs to be run as root.");
19 }
20 }
21
22 /// `PrivDrop` structure
23 ///
24 /// # Example
25 /// ```ignore
26 /// privdrop::PrivDrop::default()
27 /// .chroot("/var/empty")
28 /// .user("nobody")
29 /// .apply()
30 /// .unwrap_or_else(|e| { panic!("Failed to drop privileges: {}", e) });
31 /// ```
32 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default:, Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:)]
33 pub struct PrivDroprust-analyzer cargo privdrop 0.5.4 privdrop/PrivDrop# {
34 chrootrust-analyzer cargo privdrop 0.5.4 privdrop/PrivDrop#chroot.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<PathBufrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/PathBuf#>,
35 userrust-analyzer cargo privdrop 0.5.4 privdrop/PrivDrop#user.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<OsStringrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/OsString#>,
36 grouprust-analyzer cargo privdrop 0.5.4 privdrop/PrivDrop#group.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<OsStringrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/OsString#>,
37 group_listrust-analyzer cargo privdrop 0.5.4 privdrop/PrivDrop#group_list.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<OsStringrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/OsString#>>,
38 include_default_supplementary_groupsrust-analyzer cargo privdrop 0.5.4 privdrop/PrivDrop#include_default_supplementary_groups.: bool,
39 fallback_to_ids_if_names_are_numericrust-analyzer cargo privdrop 0.5.4 privdrop/PrivDrop#fallback_to_ids_if_names_are_numeric.: bool,
40 }
41
42 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default:, Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:)]
43 struct UserIdsrust-analyzer cargo privdrop 0.5.4 privdrop/UserIds# {
44 uidrust-analyzer cargo privdrop 0.5.4 privdrop/UserIds#uid.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<libcrust-analyzer cargo libc 0.2.189 crate/::uid_trust-analyzer cargo libc 0.2.189 unix/uid_t#>,
45 gidrust-analyzer cargo privdrop 0.5.4 privdrop/UserIds#gid.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<libcrust-analyzer cargo libc 0.2.189 crate/::gid_trust-analyzer cargo libc 0.2.189 unix/gid_t#>,
46 group_listrust-analyzer cargo privdrop 0.5.4 privdrop/UserIds#group_list.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<libcrust-analyzer cargo libc 0.2.189 crate/::gid_trust-analyzer cargo libc 0.2.189 unix/gid_t#>>,
47 }
48
49 impl PrivDroprust-analyzer cargo privdrop 0.5.4 privdrop/PrivDrop# {
50 /// chroot() to a specific directory before switching to a non-root user
51 pub fn chrootrust-analyzer cargo privdrop 0.5.4 privdrop/impl#[PrivDrop]chroot().<T: AsRefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#<Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#>>(mut self, path: T) -> Selfrust-analyzer cargo privdrop 0.5.4 privdrop/impl#[PrivDrop] {
52 self.chrootrust-analyzer cargo privdrop 0.5.4 privdrop/PrivDrop#chroot. = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(path.as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#as_ref().().to_ownedrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path][ToOwned]to_owned().());
53 self
54 }
55
56 /// Set the name of a user to switch to
57 pub fn userrust-analyzer cargo privdrop 0.5.4 privdrop/impl#[PrivDrop]user().<S: AsRefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#<OsStrrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/OsStr#>>(mut self, user: S) -> Selfrust-analyzer cargo privdrop 0.5.4 privdrop/impl#[PrivDrop] {
58 self.userrust-analyzer cargo privdrop 0.5.4 privdrop/PrivDrop#user. = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(user.as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#as_ref().().to_ownedrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/impl#[OsStr][ToOwned]to_owned().());
59 self
60 }
61
62 /// Set a group name to switch to, if different from the primary group of the user
63 pub fn grouprust-analyzer cargo privdrop 0.5.4 privdrop/impl#[PrivDrop]group().<S: AsRefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#<OsStrrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/OsStr#>>(mut self, group: S) -> Selfrust-analyzer cargo privdrop 0.5.4 privdrop/impl#[PrivDrop] {
64 self.grouprust-analyzer cargo privdrop 0.5.4 privdrop/PrivDrop#group. = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(group.as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#as_ref().().to_ownedrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/impl#[OsStr][ToOwned]to_owned().());
65 self
66 }
67
68 /// Include default supplementary groups
69 pub fn include_default_supplementary_groupsrust-analyzer cargo privdrop 0.5.4 privdrop/impl#[PrivDrop]include_default_supplementary_groups().(mut self) -> Selfrust-analyzer cargo privdrop 0.5.4 privdrop/impl#[PrivDrop] {
70 self.include_default_supplementary_groupsrust-analyzer cargo privdrop 0.5.4 privdrop/PrivDrop#include_default_supplementary_groups. = true;
71 self
72 }
73
74 /// If a name is not found, try to parse it as a numeric identifier
75 pub fn fallback_to_ids_if_names_are_numericrust-analyzer cargo privdrop 0.5.4 privdrop/impl#[PrivDrop]fallback_to_ids_if_names_are_numeric().(mut self) -> Selfrust-analyzer cargo privdrop 0.5.4 privdrop/impl#[PrivDrop] {
76 self.fallback_to_ids_if_names_are_numericrust-analyzer cargo privdrop 0.5.4 privdrop/PrivDrop#fallback_to_ids_if_names_are_numeric. = true;
77 self
78 }
79
80 /// Set the full list of groups to switch to
81 pub fn group_listrust-analyzer cargo privdrop 0.5.4 privdrop/impl#[PrivDrop]group_list().<S: AsRefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#<OsStrrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/OsStr#>>(mut self, group_list: &[S]) -> Selfrust-analyzer cargo privdrop 0.5.4 privdrop/impl#[PrivDrop] {
82 self.group_listrust-analyzer cargo privdrop 0.5.4 privdrop/PrivDrop#group_list. = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(group_list.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|x| x.as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#as_ref().().to_ownedrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/impl#[OsStr][ToOwned]to_owned().()).collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().());
83 self
84 }
85
86 /// Apply the changes
87 pub fn applyrust-analyzer cargo privdrop 0.5.4 privdrop/impl#[PrivDrop]apply().(self) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), PrivDropErrorrust-analyzer cargo privdrop 0.5.4 errors/PrivDropError#> {
88 Selfrust-analyzer cargo privdrop 0.5.4 privdrop/impl#[PrivDrop]::preloadrust-analyzer cargo privdrop 0.5.4 privdrop/impl#[PrivDrop]preload().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
89 let ids = self.lookup_idsrust-analyzer cargo privdrop 0.5.4 privdrop/impl#[PrivDrop]lookup_ids().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
90 self.do_chrootrust-analyzer cargo privdrop 0.5.4 privdrop/impl#[PrivDrop]do_chroot().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch()..do_idchangerust-analyzer cargo privdrop 0.5.4 privdrop/impl#[PrivDrop]do_idchange().(ids)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
91 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(())
92 }
93
94 fn preloadrust-analyzer cargo privdrop 0.5.4 privdrop/impl#[PrivDrop]preload().() -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), PrivDropErrorrust-analyzer cargo privdrop 0.5.4 errors/PrivDropError#> {
95 let c_locale = 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().("C").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
96 unsafe {
97 libcrust-analyzer cargo libc 0.2.189 crate/::strerrorrust-analyzer cargo libc 0.2.189 strerror().(1);
98 libcrust-analyzer cargo libc 0.2.189 crate/::setlocalerust-analyzer cargo libc 0.2.189 setlocale().(libcrust-analyzer cargo libc 0.2.189 crate/::LC_CTYPErust-analyzer cargo libc 0.2.189 unix/linux_like/LC_CTYPE., c_locale.as_ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ffi/c_str/impl#[CStr]as_ptr().());
99 libcrust-analyzer cargo libc 0.2.189 crate/::setlocalerust-analyzer cargo libc 0.2.189 setlocale().(libcrust-analyzer cargo libc 0.2.189 crate/::LC_COLLATErust-analyzer cargo libc 0.2.189 unix/linux_like/LC_COLLATE., c_locale.as_ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ffi/c_str/impl#[CStr]as_ptr().());
100 let mut now: libcrust-analyzer cargo libc 0.2.189 crate/::time_trust-analyzer cargo libc 0.2.189 unix/linux_like/linux/gnu/b64/time_t# = 0;
101 libcrust-analyzer cargo libc 0.2.189 crate/::timerust-analyzer cargo libc 0.2.189 time().(&mut now);
102 libcrust-analyzer cargo libc 0.2.189 crate/::localtimerust-analyzer cargo libc 0.2.189 localtime().(&now);
103 }
104 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(())
105 }
106
107 fn uidcheckrust-analyzer cargo privdrop 0.5.4 privdrop/impl#[PrivDrop]uidcheck().() -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), PrivDropErrorrust-analyzer cargo privdrop 0.5.4 errors/PrivDropError#> {
108 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().unistdrust-analyzer cargo nix 0.31.3 unistd/::geteuidrust-analyzer cargo nix 0.31.3 unistd/geteuid().().is_rootrust-analyzer cargo nix 0.31.3 unistd/impl#[Uid]is_root().() {
109 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(PrivDropErrorrust-analyzer cargo privdrop 0.5.4 errors/PrivDropError#::fromrust-analyzer cargo privdrop 0.5.4 errors/impl#[PrivDropError][`From<(ErrorKind, &'static str)>`]from().((
110 ErrorKindrust-analyzer cargo privdrop 0.5.4 errors/ErrorKind#::SysErrorrust-analyzer cargo privdrop 0.5.4 errors/ErrorKind#SysError#,
111 "Starting this application requires root privileges",
112 )))
113 } else {
114 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(())
115 }
116 }
117
118 fn do_chrootrust-analyzer cargo privdrop 0.5.4 privdrop/impl#[PrivDrop]do_chroot().(mut self) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Selfrust-analyzer cargo privdrop 0.5.4 privdrop/impl#[PrivDrop], PrivDropErrorrust-analyzer cargo privdrop 0.5.4 errors/PrivDropError#> {
119 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(chroot) = self.chrootrust-analyzer cargo privdrop 0.5.4 privdrop/PrivDrop#chroot..takerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]take().() {
120 Selfrust-analyzer cargo privdrop 0.5.4 privdrop/impl#[PrivDrop]::uidcheckrust-analyzer cargo privdrop 0.5.4 privdrop/impl#[PrivDrop]uidcheck().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
121 unistdrust-analyzer cargo nix 0.31.3 unistd/::chdirrust-analyzer cargo nix 0.31.3 unistd/chdir().(&chroot)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
122 unistdrust-analyzer cargo nix 0.31.3 unistd/::chrootrust-analyzer cargo nix 0.31.3 unistd/chroot().(&chroot)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
123 unistdrust-analyzer cargo nix 0.31.3 unistd/::chdirrust-analyzer cargo nix 0.31.3 unistd/chdir().("/")?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().
124 }
125 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(self)
126 }
127
128 fn lookup_userrust-analyzer cargo privdrop 0.5.4 privdrop/impl#[PrivDrop]lookup_user().(
129 user: &OsStrrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/OsStr#,
130 fallback_to_ids_if_names_are_numeric: bool,
131 ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<UserIdsrust-analyzer cargo privdrop 0.5.4 privdrop/UserIds#, PrivDropErrorrust-analyzer cargo privdrop 0.5.4 errors/PrivDropError#> {
132 let username = 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().(user.as_bytesrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/unix/ffi/os_str/impl#[OsStr][OsStrExt]as_bytes().())
133 .map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|_| PrivDropErrorrust-analyzer cargo privdrop 0.5.4 errors/PrivDropError#::fromrust-analyzer cargo privdrop 0.5.4 errors/impl#[PrivDropError][`From<(ErrorKind, &'static str)>`]from().((ErrorKindrust-analyzer cargo privdrop 0.5.4 errors/ErrorKind#::SysErrorrust-analyzer cargo privdrop 0.5.4 errors/ErrorKind#SysError#, "Invalid username")))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
134 let mut pwd = unsafe { stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::memrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/::zeroedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/zeroed().::<libcrust-analyzer cargo libc 0.2.189 crate/::passwdrust-analyzer cargo libc 0.2.189 unix/linux_like/linux_l4re_shared/passwd#>() };
135 let mut pwbuf = vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![0; 4096];
136 let mut pwent = stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/::null_mutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/null_mut().::<libcrust-analyzer cargo libc 0.2.189 crate/::passwdrust-analyzer cargo libc 0.2.189 unix/linux_like/linux_l4re_shared/passwd#>();
137 let ret = unsafe {
138 libcrust-analyzer cargo libc 0.2.189 crate/::getpwnam_rrust-analyzer cargo libc 0.2.189 getpwnam_r().(
139 username.as_ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ffi/c_str/impl#[CStr]as_ptr().(),
140 &mut pwd,
141 pwbuf.as_mut_ptrrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]as_mut_ptr().(),
142 pwbuf.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(),
143 &mut pwent,
144 )
145 };
146
147 if ret 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 || pwent.is_nullrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/mut_ptr/impl#[`*mut T`]is_null().() {
148 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().fallback_to_ids_if_names_are_numeric {
149 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(PrivDropErrorrust-analyzer cargo privdrop 0.5.4 errors/PrivDropError#::fromrust-analyzer cargo privdrop 0.5.4 errors/impl#[PrivDropError][`From<(ErrorKind, &'static str)>`]from().((ErrorKindrust-analyzer cargo privdrop 0.5.4 errors/ErrorKind#::SysErrorrust-analyzer cargo privdrop 0.5.4 errors/ErrorKind#SysError#, "User not found")));
150 }
151 let user_str = user.to_strrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/impl#[OsStr]to_str().().ok_or_elserust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]ok_or_else().(|| {
152 PrivDropErrorrust-analyzer cargo privdrop 0.5.4 errors/PrivDropError#::fromrust-analyzer cargo privdrop 0.5.4 errors/impl#[PrivDropError][`From<(ErrorKind, &'static str)>`]from().((
153 ErrorKindrust-analyzer cargo privdrop 0.5.4 errors/ErrorKind#::SysErrorrust-analyzer cargo privdrop 0.5.4 errors/ErrorKind#SysError#,
154 "User not found and username is not a valid number",
155 ))
156 })?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
157 let uid = user_str.parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().().map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|_| {
158 PrivDropErrorrust-analyzer cargo privdrop 0.5.4 errors/PrivDropError#::fromrust-analyzer cargo privdrop 0.5.4 errors/impl#[PrivDropError][`From<(ErrorKind, &'static str)>`]from().((
159 ErrorKindrust-analyzer cargo privdrop 0.5.4 errors/ErrorKind#::SysErrorrust-analyzer cargo privdrop 0.5.4 errors/ErrorKind#SysError#,
160 "User not found and username is not a valid number",
161 ))
162 })?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
163 return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(UserIdsrust-analyzer cargo privdrop 0.5.4 privdrop/UserIds# {
164 uidrust-analyzer cargo privdrop 0.5.4 privdrop/UserIds#uid.: Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(uid),
165 gidrust-analyzer cargo privdrop 0.5.4 privdrop/UserIds#gid.: Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#,
166 group_listrust-analyzer cargo privdrop 0.5.4 privdrop/UserIds#group_list.: Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#,
167 });
168 }
169
170 let uid = unsafe { *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/Deref#deref().pwent }.pw_uidrust-analyzer cargo libc 0.2.189 unix/linux_like/linux_l4re_shared/passwd#pw_uid.;
171 let gid = unsafe { *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/Deref#deref().pwent }.pw_gidrust-analyzer cargo libc 0.2.189 unix/linux_like/linux_l4re_shared/passwd#pw_gid.;
172
173 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(UserIdsrust-analyzer cargo privdrop 0.5.4 privdrop/UserIds# {
174 uidrust-analyzer cargo privdrop 0.5.4 privdrop/UserIds#uid.: Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(uid),
175 gidrust-analyzer cargo privdrop 0.5.4 privdrop/UserIds#gid.: Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(gid),
176 group_listrust-analyzer cargo privdrop 0.5.4 privdrop/UserIds#group_list.: Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#,
177 })
178 }
179
180 fn default_group_listrust-analyzer cargo privdrop 0.5.4 privdrop/impl#[PrivDrop]default_group_list().(
181 user: &OsStrrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/OsStr#,
182 gid: libcrust-analyzer cargo libc 0.2.189 crate/::gid_trust-analyzer cargo libc 0.2.189 unix/gid_t#,
183 ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<libcrust-analyzer cargo libc 0.2.189 crate/::gid_trust-analyzer cargo libc 0.2.189 unix/gid_t#>>, PrivDropErrorrust-analyzer cargo privdrop 0.5.4 errors/PrivDropError#> {
184 let username = 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().(user.as_bytesrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/unix/ffi/os_str/impl#[OsStr][OsStrExt]as_bytes().())
185 .map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|_| PrivDropErrorrust-analyzer cargo privdrop 0.5.4 errors/PrivDropError#::fromrust-analyzer cargo privdrop 0.5.4 errors/impl#[PrivDropError][`From<(ErrorKind, &'static str)>`]from().((ErrorKindrust-analyzer cargo privdrop 0.5.4 errors/ErrorKind#::SysErrorrust-analyzer cargo privdrop 0.5.4 errors/ErrorKind#SysError#, "Invalid username")))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
186 let mut groups = vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![0; 256];
187 let mut ngroups = groups.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().() as _;
188 let ret = unsafe {
189 libcrust-analyzer cargo libc 0.2.189 crate/::getgrouplistrust-analyzer cargo libc 0.2.189 getgrouplist().(
190 username.as_ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ffi/c_str/impl#[CStr]as_ptr().(),
191 gid as _,
192 groups.as_mut_ptrrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]as_mut_ptr().(),
193 &mut ngroups,
194 )
195 };
196 if ret rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialEq<Self>`]eq().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][Neg]neg().1 {
197 return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#);
198 }
199 groups.truncaterust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]truncate().(ngroups as _);
200 let mut groups_ = Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::with_capacityrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]with_capacity().(groups.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().());
201 for group in groups {
202 groups_.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(group as _);
203 }
204 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#(groups_))
205 }
206
207 fn lookup_grouprust-analyzer cargo privdrop 0.5.4 privdrop/impl#[PrivDrop]lookup_group().(
208 group: &OsStrrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/OsStr#,
209 fallback_to_ids_if_names_are_numeric: bool,
210 ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<libcrust-analyzer cargo libc 0.2.189 crate/::gid_trust-analyzer cargo libc 0.2.189 unix/gid_t#, PrivDropErrorrust-analyzer cargo privdrop 0.5.4 errors/PrivDropError#> {
211 let groupname = 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().(group.as_bytesrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/unix/ffi/os_str/impl#[OsStr][OsStrExt]as_bytes().())
212 .map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|_| PrivDropErrorrust-analyzer cargo privdrop 0.5.4 errors/PrivDropError#::fromrust-analyzer cargo privdrop 0.5.4 errors/impl#[PrivDropError][`From<(ErrorKind, &'static str)>`]from().((ErrorKindrust-analyzer cargo privdrop 0.5.4 errors/ErrorKind#::SysErrorrust-analyzer cargo privdrop 0.5.4 errors/ErrorKind#SysError#, "Invalid group name")))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
213
214 let mut grp = unsafe { stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::memrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/::zeroedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/zeroed().::<libcrust-analyzer cargo libc 0.2.189 crate/::grouprust-analyzer cargo libc 0.2.189 unix/group#>() };
215 let mut grbuf = vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![0; 4096];
216 let mut grent = stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/::null_mutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/null_mut().::<libcrust-analyzer cargo libc 0.2.189 crate/::grouprust-analyzer cargo libc 0.2.189 unix/group#>();
217 let ret = unsafe {
218 libcrust-analyzer cargo libc 0.2.189 crate/::getgrnam_rrust-analyzer cargo libc 0.2.189 getgrnam_r().(
219 groupname.as_ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ffi/c_str/impl#[CStr]as_ptr().(),
220 &mut grp,
221 grbuf.as_mut_ptrrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]as_mut_ptr().(),
222 grbuf.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(),
223 &mut grent,
224 )
225 };
226
227 if ret 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 || grent.is_nullrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/mut_ptr/impl#[`*mut T`]is_null().() {
228 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().fallback_to_ids_if_names_are_numeric {
229 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(PrivDropErrorrust-analyzer cargo privdrop 0.5.4 errors/PrivDropError#::fromrust-analyzer cargo privdrop 0.5.4 errors/impl#[PrivDropError][`From<(ErrorKind, &'static str)>`]from().((
230 ErrorKindrust-analyzer cargo privdrop 0.5.4 errors/ErrorKind#::SysErrorrust-analyzer cargo privdrop 0.5.4 errors/ErrorKind#SysError#,
231 "Group not found",
232 )));
233 }
234 let group_str = group.to_strrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/impl#[OsStr]to_str().().ok_or_elserust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]ok_or_else().(|| {
235 PrivDropErrorrust-analyzer cargo privdrop 0.5.4 errors/PrivDropError#::fromrust-analyzer cargo privdrop 0.5.4 errors/impl#[PrivDropError][`From<(ErrorKind, &'static str)>`]from().((
236 ErrorKindrust-analyzer cargo privdrop 0.5.4 errors/ErrorKind#::SysErrorrust-analyzer cargo privdrop 0.5.4 errors/ErrorKind#SysError#,
237 "Group not found and group is not a valid number",
238 ))
239 })?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
240 let gid: libcrust-analyzer cargo libc 0.2.189 crate/::gid_trust-analyzer cargo libc 0.2.189 unix/gid_t# = group_str.parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().().map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|_| {
241 PrivDropErrorrust-analyzer cargo privdrop 0.5.4 errors/PrivDropError#::fromrust-analyzer cargo privdrop 0.5.4 errors/impl#[PrivDropError][`From<(ErrorKind, &'static str)>`]from().((
242 ErrorKindrust-analyzer cargo privdrop 0.5.4 errors/ErrorKind#::SysErrorrust-analyzer cargo privdrop 0.5.4 errors/ErrorKind#SysError#,
243 "Group not found and group is not a valid number",
244 ))
245 })?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
246 return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(gid);
247 }
248
249 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(unsafe { *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/Deref#deref().grent }.gr_gidrust-analyzer cargo libc 0.2.189 unix/group#gr_gid.)
250 }
251
252 fn lookup_idsrust-analyzer cargo privdrop 0.5.4 privdrop/impl#[PrivDrop]lookup_ids().(&self) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<UserIdsrust-analyzer cargo privdrop 0.5.4 privdrop/UserIds#, PrivDropErrorrust-analyzer cargo privdrop 0.5.4 errors/PrivDropError#> {
253 let mut ids = UserIdsrust-analyzer cargo privdrop 0.5.4 privdrop/UserIds#::defaultrust-analyzer cargo privdrop 0.5.4 privdrop/impl#[UserIds][Default]default().();
254
255 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(ref user) = self.userrust-analyzer cargo privdrop 0.5.4 privdrop/PrivDrop#user. {
256 ids = PrivDroprust-analyzer cargo privdrop 0.5.4 privdrop/PrivDrop#::lookup_userrust-analyzer cargo privdrop 0.5.4 privdrop/impl#[PrivDrop]lookup_user().(user, self.fallback_to_ids_if_names_are_numericrust-analyzer cargo privdrop 0.5.4 privdrop/PrivDrop#fallback_to_ids_if_names_are_numeric.)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
257 }
258
259 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(ref group) = self.grouprust-analyzer cargo privdrop 0.5.4 privdrop/PrivDrop#group. {
260 ids.gidrust-analyzer cargo privdrop 0.5.4 privdrop/UserIds#gid. = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(PrivDroprust-analyzer cargo privdrop 0.5.4 privdrop/PrivDrop#::lookup_grouprust-analyzer cargo privdrop 0.5.4 privdrop/impl#[PrivDrop]lookup_group().(
261 group,
262 self.fallback_to_ids_if_names_are_numericrust-analyzer cargo privdrop 0.5.4 privdrop/PrivDrop#fallback_to_ids_if_names_are_numeric.,
263 )?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().);
264 }
265
266 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(ref group_list) = self.group_listrust-analyzer cargo privdrop 0.5.4 privdrop/PrivDrop#group_list. {
267 let mut groups = Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::with_capacityrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]with_capacity().(group_list.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().());
268 for group in group_list {
269 groups.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(PrivDroprust-analyzer cargo privdrop 0.5.4 privdrop/PrivDrop#::lookup_grouprust-analyzer cargo privdrop 0.5.4 privdrop/impl#[PrivDrop]lookup_group().(
270 group,
271 self.fallback_to_ids_if_names_are_numericrust-analyzer cargo privdrop 0.5.4 privdrop/PrivDrop#fallback_to_ids_if_names_are_numeric.,
272 )?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().);
273 }
274 ids.group_listrust-analyzer cargo privdrop 0.5.4 privdrop/UserIds#group_list. = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(groups);
275 }
276
277 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(ids)
278 }
279
280 fn do_idchangerust-analyzer cargo privdrop 0.5.4 privdrop/impl#[PrivDrop]do_idchange().(&self, ids: UserIdsrust-analyzer cargo privdrop 0.5.4 privdrop/UserIds#) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), PrivDropErrorrust-analyzer cargo privdrop 0.5.4 errors/PrivDropError#> {
281 Selfrust-analyzer cargo privdrop 0.5.4 privdrop/impl#[PrivDrop]::uidcheckrust-analyzer cargo privdrop 0.5.4 privdrop/impl#[PrivDrop]uidcheck().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
282
283 let mut groups = vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![];
284 if self.include_default_supplementary_groupsrust-analyzer cargo privdrop 0.5.4 privdrop/PrivDrop#include_default_supplementary_groups. {
285 if let (Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(user), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(gid)) = (&self.userrust-analyzer cargo privdrop 0.5.4 privdrop/PrivDrop#user., ids.gidrust-analyzer cargo privdrop 0.5.4 privdrop/UserIds#gid.) {
286 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(group_list) = Selfrust-analyzer cargo privdrop 0.5.4 privdrop/impl#[PrivDrop]::default_group_listrust-analyzer cargo privdrop 0.5.4 privdrop/impl#[PrivDrop]default_group_list().(user, gid)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch(). {
287 groups.extendrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Extend<T>`]extend().(group_list);
288 }
289 } else {
290 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(PrivDropErrorrust-analyzer cargo privdrop 0.5.4 errors/PrivDropError#::fromrust-analyzer cargo privdrop 0.5.4 errors/impl#[PrivDropError][`From<(ErrorKind, &'static str)>`]from().((
291 ErrorKindrust-analyzer cargo privdrop 0.5.4 errors/ErrorKind#::SysErrorrust-analyzer cargo privdrop 0.5.4 errors/ErrorKind#SysError#,
292 "Unable to determine default supplementary groups without a user name and a base gid",
293 )));
294 }
295 }
296 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(ref group_list) = ids.group_listrust-analyzer cargo privdrop 0.5.4 privdrop/UserIds#group_list. {
297 groups.extendrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Extend<T>`]extend().(group_list.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().clonedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#cloned().());
298 }
299 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(gid) = ids.gidrust-analyzer cargo privdrop 0.5.4 privdrop/UserIds#gid. {
300 groups.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(gid);
301 let mut unique_groups = vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![];
302 for group in groups {
303 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().unique_groups.containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]contains().(&group) {
304 unique_groups.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(group);
305 }
306 }
307 if unsafe { libcrust-analyzer cargo libc 0.2.189 crate/::setgroupsrust-analyzer cargo libc 0.2.189 setgroups().(unique_groups.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().() as _, unique_groups.as_ptrrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]as_ptr().()) } 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 {
308 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(PrivDropErrorrust-analyzer cargo privdrop 0.5.4 errors/PrivDropError#::fromrust-analyzer cargo privdrop 0.5.4 errors/impl#[PrivDropError][`From<(ErrorKind, &'static str)>`]from().((
309 ErrorKindrust-analyzer cargo privdrop 0.5.4 errors/ErrorKind#::SysErrorrust-analyzer cargo privdrop 0.5.4 errors/ErrorKind#SysError#,
310 "Unable to revoke supplementary groups",
311 )));
312 }
313 unistdrust-analyzer cargo nix 0.31.3 unistd/::setgidrust-analyzer cargo nix 0.31.3 unistd/setgid().(unistdrust-analyzer cargo nix 0.31.3 unistd/::Gidrust-analyzer cargo nix 0.31.3 unistd/Gid#::from_rawrust-analyzer cargo nix 0.31.3 unistd/impl#[Gid]from_raw().(gid))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
314 }
315 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(uid) = ids.uidrust-analyzer cargo privdrop 0.5.4 privdrop/UserIds#uid. {
316 unistdrust-analyzer cargo nix 0.31.3 unistd/::setuidrust-analyzer cargo nix 0.31.3 unistd/setuid().(unistdrust-analyzer cargo nix 0.31.3 unistd/::Uidrust-analyzer cargo nix 0.31.3 unistd/Uid#::from_rawrust-analyzer cargo nix 0.31.3 unistd/impl#[Uid]from_raw().(uid))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().
317 }
318 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(())
319 }
320 }