| 1 | use superrust-analyzer cargo sudo-rs 0.2.14 sudo/pipeline/::superrust-analyzer cargo sudo-rs 0.2.14 sudo/::clirust-analyzer cargo sudo-rs 0.2.14 sudo/cli/::SudoEditOptionsrust-analyzer cargo sudo-rs 0.2.14 sudo/cli/SudoEditOptions#; |
| 2 | use craterust-analyzer cargo sudo-rs 0.2.14 crate/::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#}; |
| 3 | use craterust-analyzer cargo sudo-rs 0.2.14 crate/::logrust-analyzer cargo sudo-rs 0.2.14 log/::{user_errorrust-analyzer cargo sudo-rs 0.2.14 log/user_error!, user_inforust-analyzer cargo sudo-rs 0.2.14 log/user_info!}; |
| 4 | use craterust-analyzer cargo sudo-rs 0.2.14 crate/::sudoersrust-analyzer cargo sudo-rs 0.2.14 sudoers/::Authorizationrust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/Authorization#; |
| 5 | use craterust-analyzer cargo sudo-rs 0.2.14 crate/::systemrust-analyzer cargo sudo-rs 0.2.14 system/::auditrust-analyzer cargo sudo-rs 0.2.14 system/audit/; |
| 6 | |
| 7 | pub fn run_editrust-analyzer cargo sudo-rs 0.2.14 sudo/pipeline/edit/run_edit().(edit_opts: SudoEditOptionsrust-analyzer cargo sudo-rs 0.2.14 sudo/cli/SudoEditOptions#) -> 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#> { |
| 8 | let policy = 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().; |
| 9 | |
| 10 | let context = Contextrust-analyzer cargo sudo-rs 0.2.14 common/context/Context#::from_edit_optsrust-analyzer cargo sudo-rs 0.2.14 common/context/impl#[Context]from_edit_opts().(edit_opts)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 11 | |
| 12 | let policy = superrust-analyzer cargo sudo-rs 0.2.14 sudo/pipeline/::judgerust-analyzer cargo sudo-rs 0.2.14 sudo/pipeline/judge().(policy, &context)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 13 | |
| 14 | let Authorizationrust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/Authorization#::Allowedrust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/Authorization#Allowed#(auth, _controls) = policy.authorizationrust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/impl#[Judgement]authorization().() else { |
| 15 | 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#::Authorizationrust-analyzer cargo sudo-rs 0.2.14 common/error/Error#Authorization#(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..to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().())); |
| 16 | }; |
| 17 | |
| 18 | let mut pam_context = 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().(&context, auth)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 19 | |
| 20 | let mut opened_files = 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().(context.files_to_editrust-analyzer cargo sudo-rs 0.2.14 common/context/Context#files_to_edit..lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().()); |
| 21 | for (path, arg) in context.files_to_editrust-analyzer cargo sudo-rs 0.2.14 common/context/Context#files_to_edit..iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().ziprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#zip().(&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.) { |
| 22 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(path) = path { |
| 23 | match auditrust-analyzer cargo sudo-rs 0.2.14 system/audit/::secure_open_for_sudoeditrust-analyzer cargo sudo-rs 0.2.14 system/audit/secure_open_for_sudoedit().( |
| 24 | path, |
| 25 | &context.current_userrust-analyzer cargo sudo-rs 0.2.14 common/context/Context#current_user., |
| 26 | &context.target_userrust-analyzer cargo sudo-rs 0.2.14 common/context/Context#target_user., |
| 27 | &context.target_grouprust-analyzer cargo sudo-rs 0.2.14 common/context/Context#target_group., |
| 28 | ) { |
| 29 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(file) => opened_files.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().((path, file)), |
| 30 | // ErrorKind::FilesystemLoop was only stabilized in 1.83 |
| 31 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(error) if error.raw_os_errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/impl#[Error]raw_os_error().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#eq().Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(libcrust-analyzer cargo libc 0.2.186 crate/::ELOOPrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/gnu/b64/x86_64/ELOOP.) => { |
| 32 | user_errorrust-analyzer cargo sudo-rs 0.2.14 log/user_error!!( |
| 33 | "{path}: editing symbolic links is not permitted", |
| 34 | path = DisplayOsStrrust-analyzer cargo sudo-rs 0.2.14 common/DisplayOsStr#(arg), |
| 35 | ) |
| 36 | } |
| 37 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(error) => { |
| 38 | user_errorrust-analyzer cargo sudo-rs 0.2.14 log/user_error!!( |
| 39 | "error opening {path}: {error}", |
| 40 | path = DisplayOsStrrust-analyzer cargo sudo-rs 0.2.14 common/DisplayOsStr#(arg), |
| 41 | error = error, |
| 42 | ) |
| 43 | } |
| 44 | } |
| 45 | } else { |
| 46 | user_errorrust-analyzer cargo sudo-rs 0.2.14 log/user_error!!("invalid path: {path}", path = DisplayOsStrrust-analyzer cargo sudo-rs 0.2.14 common/DisplayOsStr#(arg)); |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | if opened_files.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne().context.files_to_editrust-analyzer cargo sudo-rs 0.2.14 common/context/Context#files_to_edit..lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().() { |
| 51 | user_inforust-analyzer cargo sudo-rs 0.2.14 log/user_info!!("please address the problems and try again"); |
| 52 | 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#); |
| 53 | } |
| 54 | |
| 55 | // run command and return corresponding exit code |
| 56 | let command_exit_reason = { |
| 57 | superrust-analyzer cargo sudo-rs 0.2.14 sudo/pipeline/::log_command_executionrust-analyzer cargo sudo-rs 0.2.14 sudo/pipeline/log_command_execution().(&context); |
| 58 | |
| 59 | let editor = policy.preferred_editorrust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/impl#[Judgement]preferred_editor().(); |
| 60 | |
| 61 | craterust-analyzer cargo sudo-rs 0.2.14 crate/::sudorust-analyzer cargo sudo-rs 0.2.14 sudo/::editrust-analyzer cargo sudo-rs 0.2.14 sudo/edit/::edit_filesrust-analyzer cargo sudo-rs 0.2.14 sudo/edit/edit_files().(editor, opened_files) |
| 62 | }; |
| 63 | |
| 64 | pam_context.close_sessionrust-analyzer cargo sudo-rs 0.2.14 pam/impl#[PamContext]close_session().(); |
| 65 | |
| 66 | match command_exit_reason?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch()..exit_processrust-analyzer cargo sudo-rs 0.2.14 exec/impl#[ExitReason]exit_process().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch(). {} |
| 67 | } |