Debian Codegraph @

src/sudo/pipeline/list.rs

raw symbols SCIP
1 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::{
2 borrowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/::Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#,
3 ffirust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/::{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#},
4 opsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/::ControlFlowrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/control_flow/ControlFlow#,
5 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#,
6 };
7
8 use craterust-analyzer cargo sudo-rs 0.2.14 crate/::{
9 commonrust-analyzer cargo sudo-rs 0.2.14 common/::{Contextrust-analyzer cargo sudo-rs 0.2.14 common/context/Context#, DisplayOsStrrust-analyzer cargo sudo-rs 0.2.14 common/DisplayOsStr#, Errorrust-analyzer cargo sudo-rs 0.2.14 common/error/Error#},
10 sudorust-analyzer cargo sudo-rs 0.2.14 sudo/::clirust-analyzer cargo sudo-rs 0.2.14 sudo/cli/::SudoListOptionsrust-analyzer cargo sudo-rs 0.2.14 sudo/cli/SudoListOptions#,
11 sudoersrust-analyzer cargo sudo-rs 0.2.14 sudoers/::{Authorizationrust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/Authorization#, ListRequestrust-analyzer cargo sudo-rs 0.2.14 sudoers/ListRequest#, Requestrust-analyzer cargo sudo-rs 0.2.14 sudoers/Request#, Sudoersrust-analyzer cargo sudo-rs 0.2.14 sudoers/Sudoers#},
12 systemrust-analyzer cargo sudo-rs 0.2.14 system/::Userrust-analyzer cargo sudo-rs 0.2.14 system/User#,
13 };
14
15 use superrust-analyzer cargo sudo-rs 0.2.14 sudo/pipeline/::auth_and_update_record_filerust-analyzer cargo sudo-rs 0.2.14 sudo/pipeline/auth_and_update_record_file().;
16
17 pub(in craterust-analyzer cargo sudo-rs 0.2.14 crate/::sudorust-analyzer cargo sudo-rs 0.2.14 sudo/) fn run_listrust-analyzer cargo sudo-rs 0.2.14 sudo/pipeline/list/run_list().(cmd_opts: SudoListOptionsrust-analyzer cargo sudo-rs 0.2.14 sudo/cli/SudoListOptions#) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), Errorrust-analyzer cargo sudo-rs 0.2.14 common/error/Error#> {
18 let verbose_list_mode = cmd_opts.listrust-analyzer cargo sudo-rs 0.2.14 sudo/cli/SudoListOptions#list..is_verboserust-analyzer cargo sudo-rs 0.2.14 sudo/cli/impl#[List]is_verbose().();
19 let other_user = cmd_opts
20 .other_userrust-analyzer cargo sudo-rs 0.2.14 sudo/cli/SudoListOptions#other_user.
21 .as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_ref().()
22 .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(|username| {
23 Userrust-analyzer cargo sudo-rs 0.2.14 system/User#::from_namerust-analyzer cargo sudo-rs 0.2.14 system/impl#[User]from_name().(username.as_cstrrust-analyzer cargo sudo-rs 0.2.14 common/string/impl#[SudoString]as_cstr().())?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().
24 .ok_or_elserust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]ok_or_else().(|| Errorrust-analyzer cargo sudo-rs 0.2.14 common/error/Error#::UserNotFoundrust-analyzer cargo sudo-rs 0.2.14 common/error/Error#UserNotFound#(username.clonerust-analyzer cargo sudo-rs 0.2.14 common/string/impl#[SudoString][Clone]clone().().intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()))
25 })
26 .transposerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<Result<T, E>>`]transpose().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
27
28 let original_command = cmd_opts.positional_argsrust-analyzer cargo sudo-rs 0.2.14 sudo/cli/SudoListOptions#positional_args..firstrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]first().().clonedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<&T>`]cloned().();
29
30 let mut sudoers = superrust-analyzer cargo sudo-rs 0.2.14 sudo/pipeline/::read_sudoersrust-analyzer cargo sudo-rs 0.2.14 sudo/pipeline/read_sudoers().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
31
32 let context = Contextrust-analyzer cargo sudo-rs 0.2.14 common/context/Context#::from_list_optsrust-analyzer cargo sudo-rs 0.2.14 common/context/impl#[Context]from_list_opts().(cmd_opts, &mut sudoers)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
33
34 if auth_invoking_userrust-analyzer cargo sudo-rs 0.2.14 sudo/pipeline/list/auth_invoking_user().(&context, &mut sudoers, &original_command, &other_user)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch()..is_breakrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/control_flow/impl#[`ControlFlow<B, C>`]is_break().() {
35 return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(());
36 }
37
38 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(original_command) = original_command {
39 check_sudo_command_permsrust-analyzer cargo sudo-rs 0.2.14 sudo/pipeline/list/check_sudo_command_perms().(&original_command, context, &other_user, &mut sudoers)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
40 } else {
41 let inspected_user = other_user.as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_ref().().unwrap_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or().(&context.current_userrust-analyzer cargo sudo-rs 0.2.14 common/context/Context#current_user.);
42 let mut matching_entries = sudoers
43 .matching_entriesrust-analyzer cargo sudo-rs 0.2.14 sudoers/impl#[Sudoers]matching_entries().(inspected_user, &context.hostnamerust-analyzer cargo sudo-rs 0.2.14 common/context/Context#hostname.)
44 .peekablerust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#peekable().();
45
46 if matching_entries.peekrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/peekable/impl#[`Peekable<I>`]peek().().is_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some().() {
47 xlat_printlnrust-analyzer cargo sudo-rs 0.2.14 gettext/xlat_println!!(
48 "User {user} may run the following commands on {hostname}:",
49 user = inspected_user.namerust-analyzer cargo sudo-rs 0.2.14 system/User#name.,
50 hostname = context.hostnamerust-analyzer cargo sudo-rs 0.2.14 common/context/Context#hostname.
51 );
52
53 for entry in matching_entries {
54 if verbose_list_mode {
55 let entry = entry.verboserust-analyzer cargo sudo-rs 0.2.14 sudoers/entry/impl#[`Entry<'a>`]verbose().();
56 println_ignore_io_errorrust-analyzer cargo sudo-rs 0.2.14 macros/println_ignore_io_error!!("{entry}");
57 } else {
58 println_ignore_io_errorrust-analyzer cargo sudo-rs 0.2.14 macros/println_ignore_io_error!!("{entry}");
59 }
60 }
61 } else {
62 xlat_printlnrust-analyzer cargo sudo-rs 0.2.14 gettext/xlat_println!!(
63 "User {user} is not allowed to run sudo on {hostname}.",
64 user = inspected_user.namerust-analyzer cargo sudo-rs 0.2.14 system/User#name.,
65 hostname = context.hostnamerust-analyzer cargo sudo-rs 0.2.14 common/context/Context#hostname.,
66 );
67 }
68 }
69
70 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(())
71 }
72
73 fn auth_invoking_userrust-analyzer cargo sudo-rs 0.2.14 sudo/pipeline/list/auth_invoking_user().(
74 context: &Contextrust-analyzer cargo sudo-rs 0.2.14 common/context/Context#,
75 sudoers: &mut Sudoersrust-analyzer cargo sudo-rs 0.2.14 sudoers/Sudoers#,
76 original_command: &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#>,
77 other_user: &Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Userrust-analyzer cargo sudo-rs 0.2.14 system/User#>,
78 ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<ControlFlowrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/control_flow/ControlFlow#<(), ()>, Errorrust-analyzer cargo sudo-rs 0.2.14 common/error/Error#> {
79 let inspected_user = other_user.as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_ref().().unwrap_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or().(&context.current_userrust-analyzer cargo sudo-rs 0.2.14 common/context/Context#current_user.);
80
81 let list_request = ListRequestrust-analyzer cargo sudo-rs 0.2.14 sudoers/ListRequest# {
82 inspected_userrust-analyzer cargo sudo-rs 0.2.14 sudoers/ListRequest#inspected_user.,
83 target_userrust-analyzer cargo sudo-rs 0.2.14 sudoers/ListRequest#target_user.: &context.target_userrust-analyzer cargo sudo-rs 0.2.14 common/context/Context#target_user.,
84 target_grouprust-analyzer cargo sudo-rs 0.2.14 sudoers/ListRequest#target_group.: &context.target_grouprust-analyzer cargo sudo-rs 0.2.14 common/context/Context#target_group.,
85 };
86 match sudoers.check_list_permissionrust-analyzer cargo sudo-rs 0.2.14 sudoers/impl#[Sudoers]check_list_permission().(&*rust-analyzer cargo sudo-rs 0.2.14 common/resolve/impl#[CurrentUser][Deref]deref().context.current_userrust-analyzer cargo sudo-rs 0.2.14 common/context/Context#current_user., &context.hostnamerust-analyzer cargo sudo-rs 0.2.14 common/context/Context#hostname., list_request) {
87 Authorizationrust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/Authorization#::Allowedrust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/Authorization#Allowed#(auth, ()) => {
88 auth_and_update_record_filerust-analyzer cargo sudo-rs 0.2.14 sudo/pipeline/auth_and_update_record_file().(context, auth)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
89 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(ControlFlowrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/control_flow/ControlFlow#::Continuerust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/control_flow/ControlFlow#Continue#(()))
90 }
91
92 Authorizationrust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/Authorization#::Forbiddenrust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/Authorization#Forbidden# => {
93 let command = if other_user.is_nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_none().() {
94 "sudo".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()
95 } else {
96 format_list_commandrust-analyzer cargo sudo-rs 0.2.14 sudo/pipeline/list/format_list_command().(original_command)
97 };
98
99 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(Errorrust-analyzer cargo sudo-rs 0.2.14 common/error/Error#::NotAllowedrust-analyzer cargo sudo-rs 0.2.14 common/error/Error#NotAllowed# {
100 usernamerust-analyzer cargo sudo-rs 0.2.14 common/error/Error#NotAllowed#username.: context.current_userrust-analyzer cargo sudo-rs 0.2.14 common/context/Context#current_user..namerust-analyzer cargo sudo-rs 0.2.14 system/User#name..clonerust-analyzer cargo sudo-rs 0.2.14 common/string/impl#[SudoString][Clone]clone().(),
101 commandrust-analyzer cargo sudo-rs 0.2.14 common/error/Error#NotAllowed#command.,
102 hostnamerust-analyzer cargo sudo-rs 0.2.14 common/error/Error#NotAllowed#hostname.: context.hostnamerust-analyzer cargo sudo-rs 0.2.14 common/context/Context#hostname..clonerust-analyzer cargo sudo-rs 0.2.14 system/impl#[Hostname][Clone]clone().(),
103 other_userrust-analyzer cargo sudo-rs 0.2.14 common/error/Error#NotAllowed#other_user.: other_user.as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_ref().().maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(|user| &user.namerust-analyzer cargo sudo-rs 0.2.14 system/User#name.).clonedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<&T>`]cloned().(),
104 })
105 }
106 }
107 }
108
109 fn check_sudo_command_permsrust-analyzer cargo sudo-rs 0.2.14 sudo/pipeline/list/check_sudo_command_perms().(
110 original_command: &OsStrrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/OsStr#,
111 context: Contextrust-analyzer cargo sudo-rs 0.2.14 common/context/Context#,
112 other_user: &Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Userrust-analyzer cargo sudo-rs 0.2.14 system/User#>,
113 sudoers: &mut Sudoersrust-analyzer cargo sudo-rs 0.2.14 sudoers/Sudoers#,
114 ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), Errorrust-analyzer cargo sudo-rs 0.2.14 common/error/Error#> {
115 let user = other_user.as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_ref().().unwrap_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or().(&context.current_userrust-analyzer cargo sudo-rs 0.2.14 common/context/Context#current_user.);
116
117 let request = Requestrust-analyzer cargo sudo-rs 0.2.14 sudoers/Request# {
118 userrust-analyzer cargo sudo-rs 0.2.14 sudoers/Request#user.: &context.target_userrust-analyzer cargo sudo-rs 0.2.14 common/context/Context#target_user.,
119 grouprust-analyzer cargo sudo-rs 0.2.14 sudoers/Request#group.: &context.target_grouprust-analyzer cargo sudo-rs 0.2.14 common/context/Context#target_group.,
120 commandrust-analyzer cargo sudo-rs 0.2.14 sudoers/Request#command.: &context.commandrust-analyzer cargo sudo-rs 0.2.14 common/context/Context#command..commandrust-analyzer cargo sudo-rs 0.2.14 common/command/CommandAndArguments#command.,
121 argumentsrust-analyzer cargo sudo-rs 0.2.14 sudoers/Request#arguments.: &context.commandrust-analyzer cargo sudo-rs 0.2.14 common/context/Context#command..argumentsrust-analyzer cargo sudo-rs 0.2.14 common/command/CommandAndArguments#arguments.,
122 };
123
124 let judgement = sudoers.checkrust-analyzer cargo sudo-rs 0.2.14 sudoers/impl#[Sudoers]check().(user, &context.hostnamerust-analyzer cargo sudo-rs 0.2.14 common/context/Context#hostname., request);
125
126 if let Authorizationrust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/Authorization#::Forbiddenrust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/Authorization#Forbidden# = judgement.authorizationrust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/impl#[Judgement]authorization().() {
127 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(Errorrust-analyzer cargo sudo-rs 0.2.14 common/error/Error#::Silentrust-analyzer cargo sudo-rs 0.2.14 common/error/Error#Silent#);
128 } else {
129 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().context.commandrust-analyzer cargo sudo-rs 0.2.14 common/context/Context#command..resolvedrust-analyzer cargo sudo-rs 0.2.14 common/command/CommandAndArguments#resolved. {
130 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(Errorrust-analyzer cargo sudo-rs 0.2.14 common/error/Error#::CommandNotFoundrust-analyzer cargo sudo-rs 0.2.14 common/error/Error#CommandNotFound#(context.commandrust-analyzer cargo sudo-rs 0.2.14 common/context/Context#command..commandrust-analyzer cargo sudo-rs 0.2.14 common/command/CommandAndArguments#command.));
131 }
132 let command_is_relative_path = original_command.as_encoded_bytesrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/impl#[OsStr]as_encoded_bytes().().containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]contains().(&b'/')
133 && !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]new().(&original_command).is_absoluterust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]is_absolute().();
134 let command = if command_is_relative_path {
135 original_command
136 } else {
137 let resolved_command = &context.commandrust-analyzer cargo sudo-rs 0.2.14 common/context/Context#command..commandrust-analyzer cargo sudo-rs 0.2.14 common/command/CommandAndArguments#command.;
138 resolved_command.as_os_strrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]as_os_str().()
139 };
140
141 if context.commandrust-analyzer cargo sudo-rs 0.2.14 common/context/Context#command..argumentsrust-analyzer cargo sudo-rs 0.2.14 common/command/CommandAndArguments#arguments..is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]is_empty().() {
142 println_ignore_io_errorrust-analyzer cargo sudo-rs 0.2.14 macros/println_ignore_io_error!!("{}", DisplayOsStrrust-analyzer cargo sudo-rs 0.2.14 common/DisplayOsStr#(command));
143 } else {
144 println_ignore_io_errorrust-analyzer cargo sudo-rs 0.2.14 macros/println_ignore_io_error!!(
145 "{} {}",
146 DisplayOsStrrust-analyzer cargo sudo-rs 0.2.14 common/DisplayOsStr#(command),
147 DisplayOsStrrust-analyzer cargo sudo-rs 0.2.14 common/DisplayOsStr#(&context.commandrust-analyzer cargo sudo-rs 0.2.14 common/context/Context#command..argumentsrust-analyzer cargo sudo-rs 0.2.14 common/command/CommandAndArguments#arguments..joinrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc slice/impl#[`[T]`]join().(OsStrrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/OsStr#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/impl#[OsStr]new().(" "))),
148 );
149 }
150 }
151
152 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(())
153 }
154
155 fn format_list_commandrust-analyzer cargo sudo-rs 0.2.14 sudo/pipeline/list/format_list_command().(original_command: &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#>) -> Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#<'static, str> {
156 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(original_command) = original_command {
157 formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("list {}", DisplayOsStrrust-analyzer cargo sudo-rs 0.2.14 common/DisplayOsStr#(original_command)).intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()
158 } else {
159 "list".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()
160 }
161 }