| 1 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::envrust-analyzer cargo std https://github.com/rust-lang/rust/library/std env/; |
| 2 | 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/::OsStringrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/OsString#; |
| 3 | |
| 4 | use craterust-analyzer cargo sudo-rs 0.2.14 crate/::commonrust-analyzer cargo sudo-rs 0.2.14 common/::{Errorrust-analyzer cargo sudo-rs 0.2.14 common/error/Error#, HARDENED_ENUM_VALUE_0rust-analyzer cargo sudo-rs 0.2.14 common/HARDENED_ENUM_VALUE_0., HARDENED_ENUM_VALUE_1rust-analyzer cargo sudo-rs 0.2.14 common/HARDENED_ENUM_VALUE_1., HARDENED_ENUM_VALUE_2rust-analyzer cargo sudo-rs 0.2.14 common/HARDENED_ENUM_VALUE_2.}; |
| 5 | use craterust-analyzer cargo sudo-rs 0.2.14 crate/::execrust-analyzer cargo sudo-rs 0.2.14 exec/::RunOptionsrust-analyzer cargo sudo-rs 0.2.14 exec/RunOptions#; |
| 6 | use craterust-analyzer cargo sudo-rs 0.2.14 crate/::sudorust-analyzer cargo sudo-rs 0.2.14 sudo/::{SudoEditOptionsrust-analyzer cargo sudo-rs 0.2.14 sudo/cli/SudoEditOptions#, SudoListOptionsrust-analyzer cargo sudo-rs 0.2.14 sudo/cli/SudoListOptions#, SudoRunOptionsrust-analyzer cargo sudo-rs 0.2.14 sudo/cli/SudoRunOptions#, SudoValidateOptionsrust-analyzer cargo sudo-rs 0.2.14 sudo/cli/SudoValidateOptions#}; |
| 7 | use craterust-analyzer cargo sudo-rs 0.2.14 crate/::sudoersrust-analyzer cargo sudo-rs 0.2.14 sudoers/::Sudoersrust-analyzer cargo sudo-rs 0.2.14 sudoers/Sudoers#; |
| 8 | use craterust-analyzer cargo sudo-rs 0.2.14 crate/::sudoersrust-analyzer cargo sudo-rs 0.2.14 sudoers/::{DirChangerust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/DirChange#, Restrictionsrust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/Restrictions#}; |
| 9 | 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#, Hostnamerust-analyzer cargo sudo-rs 0.2.14 system/Hostname#, Userrust-analyzer cargo sudo-rs 0.2.14 system/User#, auditrust-analyzer cargo sudo-rs 0.2.14 system/audit/::sudo_callrust-analyzer cargo sudo-rs 0.2.14 system/audit/sudo_call().}; |
| 10 | |
| 11 | use superrust-analyzer cargo sudo-rs 0.2.14 common/::{ |
| 12 | SudoPathrust-analyzer cargo sudo-rs 0.2.14 common/path/SudoPath#, |
| 13 | commandrust-analyzer cargo sudo-rs 0.2.14 common/command/::CommandAndArgumentsrust-analyzer cargo sudo-rs 0.2.14 common/command/CommandAndArguments#, |
| 14 | resolverust-analyzer cargo sudo-rs 0.2.14 common/resolve/::{CurrentUserrust-analyzer cargo sudo-rs 0.2.14 common/resolve/CurrentUser#, resolve_shellrust-analyzer cargo sudo-rs 0.2.14 common/resolve/resolve_shell()., resolve_target_user_and_grouprust-analyzer cargo sudo-rs 0.2.14 common/resolve/resolve_target_user_and_group().}, |
| 15 | }; |
| 16 | |
| 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:)] |
| 18 | pub struct Contextrust-analyzer cargo sudo-rs 0.2.14 common/context/Context# { |
| 19 | // cli options |
| 20 | pub launchrust-analyzer cargo sudo-rs 0.2.14 common/context/Context#launch.: LaunchTyperust-analyzer cargo sudo-rs 0.2.14 common/context/LaunchType#, |
| 21 | pub chdirrust-analyzer cargo sudo-rs 0.2.14 common/context/Context#chdir.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<SudoPathrust-analyzer cargo sudo-rs 0.2.14 common/path/SudoPath#>, |
| 22 | pub commandrust-analyzer cargo sudo-rs 0.2.14 common/context/Context#command.: CommandAndArgumentsrust-analyzer cargo sudo-rs 0.2.14 common/command/CommandAndArguments#, |
| 23 | pub target_userrust-analyzer cargo sudo-rs 0.2.14 common/context/Context#target_user.: Userrust-analyzer cargo sudo-rs 0.2.14 system/User#, |
| 24 | pub target_grouprust-analyzer cargo sudo-rs 0.2.14 common/context/Context#target_group.: Grouprust-analyzer cargo sudo-rs 0.2.14 system/Group#, |
| 25 | pub askpassrust-analyzer cargo sudo-rs 0.2.14 common/context/Context#askpass.: bool, |
| 26 | pub stdinrust-analyzer cargo sudo-rs 0.2.14 common/context/Context#stdin.: bool, |
| 27 | pub bellrust-analyzer cargo sudo-rs 0.2.14 common/context/Context#bell.: bool, |
| 28 | pub backgroundrust-analyzer cargo sudo-rs 0.2.14 common/context/Context#background.: bool, |
| 29 | pub promptrust-analyzer cargo sudo-rs 0.2.14 common/context/Context#prompt.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>, |
| 30 | pub non_interactiverust-analyzer cargo sudo-rs 0.2.14 common/context/Context#non_interactive.: bool, |
| 31 | pub use_session_recordsrust-analyzer cargo sudo-rs 0.2.14 common/context/Context#use_session_records.: bool, |
| 32 | // system |
| 33 | pub hostnamerust-analyzer cargo sudo-rs 0.2.14 common/context/Context#hostname.: Hostnamerust-analyzer cargo sudo-rs 0.2.14 system/Hostname#, |
| 34 | pub current_userrust-analyzer cargo sudo-rs 0.2.14 common/context/Context#current_user.: CurrentUserrust-analyzer cargo sudo-rs 0.2.14 common/resolve/CurrentUser#, |
| 35 | // sudoedit |
| 36 | pub files_to_editrust-analyzer cargo sudo-rs 0.2.14 common/context/Context#files_to_edit.: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<SudoPathrust-analyzer cargo sudo-rs 0.2.14 common/path/SudoPath#>>, |
| 37 | } |
| 38 | |
| 39 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(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:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default:, 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:)] |
| 40 | #[repr(u32)] |
| 41 | pub enum LaunchTyperust-analyzer cargo sudo-rs 0.2.14 common/context/LaunchType# { |
| 42 | #[defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/default:] |
| 43 | Directrust-analyzer cargo sudo-rs 0.2.14 common/context/LaunchType#Direct# = HARDENED_ENUM_VALUE_0rust-analyzer cargo sudo-rs 0.2.14 common/HARDENED_ENUM_VALUE_0., |
| 44 | Shellrust-analyzer cargo sudo-rs 0.2.14 common/context/LaunchType#Shell# = HARDENED_ENUM_VALUE_1rust-analyzer cargo sudo-rs 0.2.14 common/HARDENED_ENUM_VALUE_1., |
| 45 | Loginrust-analyzer cargo sudo-rs 0.2.14 common/context/LaunchType#Login# = HARDENED_ENUM_VALUE_2rust-analyzer cargo sudo-rs 0.2.14 common/HARDENED_ENUM_VALUE_2., |
| 46 | } |
| 47 | |
| 48 | impl Contextrust-analyzer cargo sudo-rs 0.2.14 common/context/Context# { |
| 49 | pub fn from_run_optsrust-analyzer cargo sudo-rs 0.2.14 common/context/impl#[Context]from_run_opts().( |
| 50 | sudo_options: SudoRunOptionsrust-analyzer cargo sudo-rs 0.2.14 sudo/cli/SudoRunOptions#, |
| 51 | policy: &mut Sudoersrust-analyzer cargo sudo-rs 0.2.14 sudoers/Sudoers#, |
| 52 | ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Contextrust-analyzer cargo sudo-rs 0.2.14 common/context/Context#, Errorrust-analyzer cargo sudo-rs 0.2.14 common/error/Error#> { |
| 53 | let hostname = Hostnamerust-analyzer cargo sudo-rs 0.2.14 system/Hostname#::resolverust-analyzer cargo sudo-rs 0.2.14 system/impl#[Hostname]resolve().(); |
| 54 | let current_user = CurrentUserrust-analyzer cargo sudo-rs 0.2.14 common/resolve/CurrentUser#::resolverust-analyzer cargo sudo-rs 0.2.14 common/resolve/impl#[CurrentUser]resolve().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 55 | |
| 56 | let (target_user, target_group) = |
| 57 | resolve_target_user_and_grouprust-analyzer cargo sudo-rs 0.2.14 common/resolve/resolve_target_user_and_group().(&sudo_options.userrust-analyzer cargo sudo-rs 0.2.14 sudo/cli/SudoRunOptions#user., &sudo_options.grouprust-analyzer cargo sudo-rs 0.2.14 sudo/cli/SudoRunOptions#group., ¤t_user)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 58 | |
| 59 | let launch = if sudo_options.loginrust-analyzer cargo sudo-rs 0.2.14 sudo/cli/SudoRunOptions#login. { |
| 60 | LaunchTyperust-analyzer cargo sudo-rs 0.2.14 common/context/LaunchType#::Loginrust-analyzer cargo sudo-rs 0.2.14 common/context/LaunchType#Login# |
| 61 | } else if sudo_options.shellrust-analyzer cargo sudo-rs 0.2.14 sudo/cli/SudoRunOptions#shell. { |
| 62 | LaunchTyperust-analyzer cargo sudo-rs 0.2.14 common/context/LaunchType#::Shellrust-analyzer cargo sudo-rs 0.2.14 common/context/LaunchType#Shell# |
| 63 | } else { |
| 64 | LaunchTyperust-analyzer cargo sudo-rs 0.2.14 common/context/LaunchType#::Directrust-analyzer cargo sudo-rs 0.2.14 common/context/LaunchType#Direct# |
| 65 | }; |
| 66 | |
| 67 | let shell = resolve_shellrust-analyzer cargo sudo-rs 0.2.14 common/resolve/resolve_shell().(launch, ¤t_user, &target_user); |
| 68 | |
| 69 | let override_path = policy.search_pathrust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/impl#[Sudoers]search_path().(&hostname, ¤t_user, &target_user); |
| 70 | |
| 71 | let command = { |
| 72 | let system_path; |
| 73 | |
| 74 | let path = if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(path) = override_path { |
| 75 | path |
| 76 | } else { |
| 77 | system_path = envrust-analyzer cargo std https://github.com/rust-lang/rust/library/std env/::varrust-analyzer cargo std https://github.com/rust-lang/rust/library/std env/var().("PATH").unwrap_or_defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap_or_default().(); |
| 78 | system_path.as_refrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`AsRef<str>`]as_ref().() |
| 79 | }; |
| 80 | |
| 81 | sudo_callrust-analyzer cargo sudo-rs 0.2.14 system/audit/sudo_call().(&target_user, &target_group, || { |
| 82 | CommandAndArgumentsrust-analyzer cargo sudo-rs 0.2.14 common/command/CommandAndArguments#::build_from_argsrust-analyzer cargo sudo-rs 0.2.14 common/command/impl#[CommandAndArguments]build_from_args().(shell, sudo_options.positional_argsrust-analyzer cargo sudo-rs 0.2.14 sudo/cli/SudoRunOptions#positional_args., path) |
| 83 | })?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch(). |
| 84 | }; |
| 85 | |
| 86 | let prompt = sudo_options.promptrust-analyzer cargo sudo-rs 0.2.14 sudo/cli/SudoRunOptions#prompt..or_elserust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]or_else().(|| envrust-analyzer cargo std https://github.com/rust-lang/rust/library/std env/::varrust-analyzer cargo std https://github.com/rust-lang/rust/library/std env/var().("SUDO_PROMPT").okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]ok().()); |
| 87 | |
| 88 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Contextrust-analyzer cargo sudo-rs 0.2.14 common/context/Context# { |
| 89 | hostnamerust-analyzer cargo sudo-rs 0.2.14 common/context/Context#hostname., |
| 90 | commandrust-analyzer cargo sudo-rs 0.2.14 common/context/Context#command., |
| 91 | current_userrust-analyzer cargo sudo-rs 0.2.14 common/context/Context#current_user., |
| 92 | target_userrust-analyzer cargo sudo-rs 0.2.14 common/context/Context#target_user., |
| 93 | target_grouprust-analyzer cargo sudo-rs 0.2.14 common/context/Context#target_group., |
| 94 | use_session_recordsrust-analyzer cargo sudo-rs 0.2.14 common/context/Context#use_session_records.: !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().sudo_options.reset_timestamprust-analyzer cargo sudo-rs 0.2.14 sudo/cli/SudoRunOptions#reset_timestamp., |
| 95 | launchrust-analyzer cargo sudo-rs 0.2.14 common/context/Context#launch., |
| 96 | chdirrust-analyzer cargo sudo-rs 0.2.14 common/context/Context#chdir.: sudo_options.chdirrust-analyzer cargo sudo-rs 0.2.14 sudo/cli/SudoRunOptions#chdir., |
| 97 | askpassrust-analyzer cargo sudo-rs 0.2.14 common/context/Context#askpass.: sudo_options.askpassrust-analyzer cargo sudo-rs 0.2.14 sudo/cli/SudoRunOptions#askpass., |
| 98 | stdinrust-analyzer cargo sudo-rs 0.2.14 common/context/Context#stdin.: sudo_options.stdinrust-analyzer cargo sudo-rs 0.2.14 sudo/cli/SudoRunOptions#stdin., |
| 99 | bellrust-analyzer cargo sudo-rs 0.2.14 common/context/Context#bell.: sudo_options.bellrust-analyzer cargo sudo-rs 0.2.14 sudo/cli/SudoRunOptions#bell., |
| 100 | backgroundrust-analyzer cargo sudo-rs 0.2.14 common/context/Context#background.: sudo_options.backgroundrust-analyzer cargo sudo-rs 0.2.14 sudo/cli/SudoRunOptions#background., |
| 101 | promptrust-analyzer cargo sudo-rs 0.2.14 common/context/Context#prompt., |
| 102 | non_interactiverust-analyzer cargo sudo-rs 0.2.14 common/context/Context#non_interactive.: sudo_options.non_interactiverust-analyzer cargo sudo-rs 0.2.14 sudo/cli/SudoRunOptions#non_interactive., |
| 103 | files_to_editrust-analyzer cargo sudo-rs 0.2.14 common/context/Context#files_to_edit.: vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![], |
| 104 | }) |
| 105 | } |
| 106 | |
| 107 | pub fn from_edit_optsrust-analyzer cargo sudo-rs 0.2.14 common/context/impl#[Context]from_edit_opts().(sudo_options: 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#<Contextrust-analyzer cargo sudo-rs 0.2.14 common/context/Context#, Errorrust-analyzer cargo sudo-rs 0.2.14 common/error/Error#> { |
| 108 | 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#; |
| 109 | let hostname = Hostnamerust-analyzer cargo sudo-rs 0.2.14 system/Hostname#::resolverust-analyzer cargo sudo-rs 0.2.14 system/impl#[Hostname]resolve().(); |
| 110 | let current_user = CurrentUserrust-analyzer cargo sudo-rs 0.2.14 common/resolve/CurrentUser#::resolverust-analyzer cargo sudo-rs 0.2.14 common/resolve/impl#[CurrentUser]resolve().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 111 | |
| 112 | let (target_user, target_group) = |
| 113 | resolve_target_user_and_grouprust-analyzer cargo sudo-rs 0.2.14 common/resolve/resolve_target_user_and_group().(&sudo_options.userrust-analyzer cargo sudo-rs 0.2.14 sudo/cli/SudoEditOptions#user., &sudo_options.grouprust-analyzer cargo sudo-rs 0.2.14 sudo/cli/SudoEditOptions#group., ¤t_user)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 114 | |
| 115 | // resolve file arguments; if something can't be resolved, don't add it to the "edit" list |
| 116 | let resolved_args = sudo_callrust-analyzer cargo sudo-rs 0.2.14 system/audit/sudo_call().(&target_user, &target_group, || { |
| 117 | sudo_options.positional_argsrust-analyzer cargo sudo-rs 0.2.14 sudo/cli/SudoEditOptions#positional_args..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().(|arg| { |
| 118 | let path = 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().(arg); |
| 119 | let absolute_path; |
| 120 | craterust-analyzer cargo sudo-rs 0.2.14 crate/::commonrust-analyzer cargo sudo-rs 0.2.14 common/::resolverust-analyzer cargo sudo-rs 0.2.14 common/resolve/::canonicalize_newfilerust-analyzer cargo sudo-rs 0.2.14 common/resolve/canonicalize_newfile().(if path.is_absoluterust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]is_absolute().() { |
| 121 | path |
| 122 | } else { |
| 123 | absolute_path = 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().(".").joinrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]join().(path); |
| 124 | &absolute_path |
| 125 | }) |
| 126 | .map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|_| arg) |
| 127 | .and_thenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]and_then().(|path| path.into_os_stringrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[PathBuf]into_os_string().().into_stringrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/impl#[OsString]into_string().().map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|_| arg)) |
| 128 | }) |
| 129 | })?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 130 | |
| 131 | let files_to_edit = resolved_args |
| 132 | .clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/map/impl#[`Map<I, F>`][Clone]clone().() |
| 133 | .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|path| path.okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]ok().().maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(SudoPathrust-analyzer cargo sudo-rs 0.2.14 common/path/SudoPath#::from_cli_stringrust-analyzer cargo sudo-rs 0.2.14 common/path/impl#[SudoPath]from_cli_string().)) |
| 134 | .collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 135 | |
| 136 | // if a path resolved to something that isn't in UTF-8, it means it isn't in the sudoers file |
| 137 | // as well and so we treat it "as is" wrt. the policy lookup and fail if the user is allowed |
| 138 | // by the policy to edit that file. this is to prevent leaking information. |
| 139 | let arguments = resolved_args |
| 140 | .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|arg| match arg { |
| 141 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(arg) => OsStringrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/OsString#::fromrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/impl#[OsString][`From<String>`]from().(arg), |
| 142 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(arg) => OsStringrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/OsString#::fromrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/impl#[OsString][`From<&T>`]from().(arg), |
| 143 | }) |
| 144 | .collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 145 | |
| 146 | // TODO: the more Rust way of doing things would be to create an alternative for sudoedit instead; |
| 147 | // but a stringly typed interface feels the most decent thing to do (if we can pull it off) |
| 148 | // since "sudoedit" really is like a builtin command to sudo. We may want to be a bit 'better' than |
| 149 | // ogsudo in the future. |
| 150 | let command = CommandAndArgumentsrust-analyzer cargo sudo-rs 0.2.14 common/command/CommandAndArguments# { |
| 151 | commandrust-analyzer cargo sudo-rs 0.2.14 common/command/CommandAndArguments#command.: 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/::PathBufrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/PathBuf#::fromrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[PathBuf][`From<&T>`]from().("sudoedit"), |
| 152 | argumentsrust-analyzer cargo sudo-rs 0.2.14 common/command/CommandAndArguments#arguments., |
| 153 | ..Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default#::defaultrust-analyzer cargo sudo-rs 0.2.14 common/command/impl#[CommandAndArguments][Default]default().() |
| 154 | }; |
| 155 | |
| 156 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Contextrust-analyzer cargo sudo-rs 0.2.14 common/context/Context# { |
| 157 | hostnamerust-analyzer cargo sudo-rs 0.2.14 common/context/Context#hostname., |
| 158 | commandrust-analyzer cargo sudo-rs 0.2.14 common/context/Context#command., |
| 159 | current_userrust-analyzer cargo sudo-rs 0.2.14 common/context/Context#current_user., |
| 160 | target_userrust-analyzer cargo sudo-rs 0.2.14 common/context/Context#target_user., |
| 161 | target_grouprust-analyzer cargo sudo-rs 0.2.14 common/context/Context#target_group., |
| 162 | use_session_recordsrust-analyzer cargo sudo-rs 0.2.14 common/context/Context#use_session_records.: !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().sudo_options.reset_timestamprust-analyzer cargo sudo-rs 0.2.14 sudo/cli/SudoEditOptions#reset_timestamp., |
| 163 | launchrust-analyzer cargo sudo-rs 0.2.14 common/context/Context#launch.: Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default#::defaultrust-analyzer cargo sudo-rs 0.2.14 common/context/impl#[LaunchType][Default]default().(), |
| 164 | chdirrust-analyzer cargo sudo-rs 0.2.14 common/context/Context#chdir.: sudo_options.chdirrust-analyzer cargo sudo-rs 0.2.14 sudo/cli/SudoEditOptions#chdir., |
| 165 | askpassrust-analyzer cargo sudo-rs 0.2.14 common/context/Context#askpass.: sudo_options.askpassrust-analyzer cargo sudo-rs 0.2.14 sudo/cli/SudoEditOptions#askpass., |
| 166 | stdinrust-analyzer cargo sudo-rs 0.2.14 common/context/Context#stdin.: sudo_options.stdinrust-analyzer cargo sudo-rs 0.2.14 sudo/cli/SudoEditOptions#stdin., |
| 167 | bellrust-analyzer cargo sudo-rs 0.2.14 common/context/Context#bell.: sudo_options.bellrust-analyzer cargo sudo-rs 0.2.14 sudo/cli/SudoEditOptions#bell., |
| 168 | backgroundrust-analyzer cargo sudo-rs 0.2.14 common/context/Context#background.: false, |
| 169 | promptrust-analyzer cargo sudo-rs 0.2.14 common/context/Context#prompt.: sudo_options.promptrust-analyzer cargo sudo-rs 0.2.14 sudo/cli/SudoEditOptions#prompt., |
| 170 | non_interactiverust-analyzer cargo sudo-rs 0.2.14 common/context/Context#non_interactive.: sudo_options.non_interactiverust-analyzer cargo sudo-rs 0.2.14 sudo/cli/SudoEditOptions#non_interactive., |
| 171 | files_to_editrust-analyzer cargo sudo-rs 0.2.14 common/context/Context#files_to_edit., |
| 172 | }) |
| 173 | } |
| 174 | pub fn from_validate_optsrust-analyzer cargo sudo-rs 0.2.14 common/context/impl#[Context]from_validate_opts().(sudo_options: SudoValidateOptionsrust-analyzer cargo sudo-rs 0.2.14 sudo/cli/SudoValidateOptions#) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Contextrust-analyzer cargo sudo-rs 0.2.14 common/context/Context#, Errorrust-analyzer cargo sudo-rs 0.2.14 common/error/Error#> { |
| 175 | let hostname = Hostnamerust-analyzer cargo sudo-rs 0.2.14 system/Hostname#::resolverust-analyzer cargo sudo-rs 0.2.14 system/impl#[Hostname]resolve().(); |
| 176 | let current_user = CurrentUserrust-analyzer cargo sudo-rs 0.2.14 common/resolve/CurrentUser#::resolverust-analyzer cargo sudo-rs 0.2.14 common/resolve/impl#[CurrentUser]resolve().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 177 | let (target_user, target_group) = |
| 178 | resolve_target_user_and_grouprust-analyzer cargo sudo-rs 0.2.14 common/resolve/resolve_target_user_and_group().(&sudo_options.userrust-analyzer cargo sudo-rs 0.2.14 sudo/cli/SudoValidateOptions#user., &sudo_options.grouprust-analyzer cargo sudo-rs 0.2.14 sudo/cli/SudoValidateOptions#group., ¤t_user)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 179 | |
| 180 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Contextrust-analyzer cargo sudo-rs 0.2.14 common/context/Context# { |
| 181 | hostnamerust-analyzer cargo sudo-rs 0.2.14 common/context/Context#hostname., |
| 182 | commandrust-analyzer cargo sudo-rs 0.2.14 common/context/Context#command.: Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default#::defaultrust-analyzer cargo sudo-rs 0.2.14 common/command/impl#[CommandAndArguments][Default]default().(), |
| 183 | current_userrust-analyzer cargo sudo-rs 0.2.14 common/context/Context#current_user., |
| 184 | target_userrust-analyzer cargo sudo-rs 0.2.14 common/context/Context#target_user., |
| 185 | target_grouprust-analyzer cargo sudo-rs 0.2.14 common/context/Context#target_group., |
| 186 | use_session_recordsrust-analyzer cargo sudo-rs 0.2.14 common/context/Context#use_session_records.: !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().sudo_options.reset_timestamprust-analyzer cargo sudo-rs 0.2.14 sudo/cli/SudoValidateOptions#reset_timestamp., |
| 187 | launchrust-analyzer cargo sudo-rs 0.2.14 common/context/Context#launch.: Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default#::defaultrust-analyzer cargo sudo-rs 0.2.14 common/context/impl#[LaunchType][Default]default().(), |
| 188 | chdirrust-analyzer cargo sudo-rs 0.2.14 common/context/Context#chdir.: Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, |
| 189 | askpassrust-analyzer cargo sudo-rs 0.2.14 common/context/Context#askpass.: sudo_options.askpassrust-analyzer cargo sudo-rs 0.2.14 sudo/cli/SudoValidateOptions#askpass., |
| 190 | stdinrust-analyzer cargo sudo-rs 0.2.14 common/context/Context#stdin.: sudo_options.stdinrust-analyzer cargo sudo-rs 0.2.14 sudo/cli/SudoValidateOptions#stdin., |
| 191 | bellrust-analyzer cargo sudo-rs 0.2.14 common/context/Context#bell.: sudo_options.bellrust-analyzer cargo sudo-rs 0.2.14 sudo/cli/SudoValidateOptions#bell., |
| 192 | backgroundrust-analyzer cargo sudo-rs 0.2.14 common/context/Context#background.: false, |
| 193 | promptrust-analyzer cargo sudo-rs 0.2.14 common/context/Context#prompt.: sudo_options.promptrust-analyzer cargo sudo-rs 0.2.14 sudo/cli/SudoValidateOptions#prompt., |
| 194 | non_interactiverust-analyzer cargo sudo-rs 0.2.14 common/context/Context#non_interactive.: sudo_options.non_interactiverust-analyzer cargo sudo-rs 0.2.14 sudo/cli/SudoValidateOptions#non_interactive., |
| 195 | files_to_editrust-analyzer cargo sudo-rs 0.2.14 common/context/Context#files_to_edit.: vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![], |
| 196 | }) |
| 197 | } |
| 198 | |
| 199 | pub fn from_list_optsrust-analyzer cargo sudo-rs 0.2.14 common/context/impl#[Context]from_list_opts().( |
| 200 | sudo_options: SudoListOptionsrust-analyzer cargo sudo-rs 0.2.14 sudo/cli/SudoListOptions#, |
| 201 | policy: &mut Sudoersrust-analyzer cargo sudo-rs 0.2.14 sudoers/Sudoers#, |
| 202 | ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Contextrust-analyzer cargo sudo-rs 0.2.14 common/context/Context#, Errorrust-analyzer cargo sudo-rs 0.2.14 common/error/Error#> { |
| 203 | let hostname = Hostnamerust-analyzer cargo sudo-rs 0.2.14 system/Hostname#::resolverust-analyzer cargo sudo-rs 0.2.14 system/impl#[Hostname]resolve().(); |
| 204 | let current_user = CurrentUserrust-analyzer cargo sudo-rs 0.2.14 common/resolve/CurrentUser#::resolverust-analyzer cargo sudo-rs 0.2.14 common/resolve/impl#[CurrentUser]resolve().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 205 | let (target_user, target_group) = |
| 206 | resolve_target_user_and_grouprust-analyzer cargo sudo-rs 0.2.14 common/resolve/resolve_target_user_and_group().(&sudo_options.userrust-analyzer cargo sudo-rs 0.2.14 sudo/cli/SudoListOptions#user., &sudo_options.grouprust-analyzer cargo sudo-rs 0.2.14 sudo/cli/SudoListOptions#group., ¤t_user)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 207 | |
| 208 | let override_path = policy.search_pathrust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/impl#[Sudoers]search_path().(&hostname, ¤t_user, &target_user); |
| 209 | |
| 210 | let command = if sudo_options.positional_argsrust-analyzer cargo sudo-rs 0.2.14 sudo/cli/SudoListOptions#positional_args..is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]is_empty().() { |
| 211 | Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default#::defaultrust-analyzer cargo sudo-rs 0.2.14 common/command/impl#[CommandAndArguments][Default]default().() |
| 212 | } else { |
| 213 | let system_path; |
| 214 | |
| 215 | let path = if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(path) = override_path { |
| 216 | path |
| 217 | } else { |
| 218 | system_path = envrust-analyzer cargo std https://github.com/rust-lang/rust/library/std env/::varrust-analyzer cargo std https://github.com/rust-lang/rust/library/std env/var().("PATH").unwrap_or_defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap_or_default().(); |
| 219 | system_path.as_refrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`AsRef<str>`]as_ref().() |
| 220 | }; |
| 221 | |
| 222 | sudo_callrust-analyzer cargo sudo-rs 0.2.14 system/audit/sudo_call().(&target_user, &target_group, || { |
| 223 | CommandAndArgumentsrust-analyzer cargo sudo-rs 0.2.14 common/command/CommandAndArguments#::build_from_argsrust-analyzer cargo sudo-rs 0.2.14 common/command/impl#[CommandAndArguments]build_from_args().(Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, sudo_options.positional_argsrust-analyzer cargo sudo-rs 0.2.14 sudo/cli/SudoListOptions#positional_args., path) |
| 224 | })?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch(). |
| 225 | }; |
| 226 | |
| 227 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Contextrust-analyzer cargo sudo-rs 0.2.14 common/context/Context# { |
| 228 | hostnamerust-analyzer cargo sudo-rs 0.2.14 common/context/Context#hostname., |
| 229 | commandrust-analyzer cargo sudo-rs 0.2.14 common/context/Context#command., |
| 230 | current_userrust-analyzer cargo sudo-rs 0.2.14 common/context/Context#current_user., |
| 231 | target_userrust-analyzer cargo sudo-rs 0.2.14 common/context/Context#target_user., |
| 232 | target_grouprust-analyzer cargo sudo-rs 0.2.14 common/context/Context#target_group., |
| 233 | use_session_recordsrust-analyzer cargo sudo-rs 0.2.14 common/context/Context#use_session_records.: !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().sudo_options.reset_timestamprust-analyzer cargo sudo-rs 0.2.14 sudo/cli/SudoListOptions#reset_timestamp., |
| 234 | launchrust-analyzer cargo sudo-rs 0.2.14 common/context/Context#launch.: Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default#::defaultrust-analyzer cargo sudo-rs 0.2.14 common/context/impl#[LaunchType][Default]default().(), |
| 235 | chdirrust-analyzer cargo sudo-rs 0.2.14 common/context/Context#chdir.: Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, |
| 236 | askpassrust-analyzer cargo sudo-rs 0.2.14 common/context/Context#askpass.: sudo_options.askpassrust-analyzer cargo sudo-rs 0.2.14 sudo/cli/SudoListOptions#askpass., |
| 237 | stdinrust-analyzer cargo sudo-rs 0.2.14 common/context/Context#stdin.: sudo_options.stdinrust-analyzer cargo sudo-rs 0.2.14 sudo/cli/SudoListOptions#stdin., |
| 238 | bellrust-analyzer cargo sudo-rs 0.2.14 common/context/Context#bell.: sudo_options.bellrust-analyzer cargo sudo-rs 0.2.14 sudo/cli/SudoListOptions#bell., |
| 239 | backgroundrust-analyzer cargo sudo-rs 0.2.14 common/context/Context#background.: false, |
| 240 | promptrust-analyzer cargo sudo-rs 0.2.14 common/context/Context#prompt.: sudo_options.promptrust-analyzer cargo sudo-rs 0.2.14 sudo/cli/SudoListOptions#prompt., |
| 241 | non_interactiverust-analyzer cargo sudo-rs 0.2.14 common/context/Context#non_interactive.: sudo_options.non_interactiverust-analyzer cargo sudo-rs 0.2.14 sudo/cli/SudoListOptions#non_interactive., |
| 242 | files_to_editrust-analyzer cargo sudo-rs 0.2.14 common/context/Context#files_to_edit.: vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![], |
| 243 | }) |
| 244 | } |
| 245 | |
| 246 | pub(craterust-analyzer cargo sudo-rs 0.2.14 crate/) fn try_as_run_optionsrust-analyzer cargo sudo-rs 0.2.14 common/context/impl#[Context]try_as_run_options().( |
| 247 | &self, |
| 248 | controls: &Restrictionsrust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/Restrictions#, |
| 249 | ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<RunOptionsrust-analyzer cargo sudo-rs 0.2.14 exec/RunOptions#<'_>, Errorrust-analyzer cargo sudo-rs 0.2.14 common/error/Error#> { |
| 250 | // see if the chdir flag is permitted |
| 251 | let chdir = match &controls.chdirrust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/Restrictions#chdir. { |
| 252 | DirChangerust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/DirChange#::Anyrust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/DirChange#Any# => self.chdirrust-analyzer cargo sudo-rs 0.2.14 common/context/Context#chdir..as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_ref().(), |
| 253 | DirChangerust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/DirChange#::Strictrust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/DirChange#Strict#(optdir) => { |
| 254 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(chdir) = &self.chdirrust-analyzer cargo sudo-rs 0.2.14 common/context/Context#chdir. { |
| 255 | 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#::ChDirNotAllowedrust-analyzer cargo sudo-rs 0.2.14 common/error/Error#ChDirNotAllowed# { |
| 256 | chdirrust-analyzer cargo sudo-rs 0.2.14 common/error/Error#ChDirNotAllowed#chdir.: chdir.clonerust-analyzer cargo sudo-rs 0.2.14 common/path/impl#[SudoPath][Clone]clone().(), |
| 257 | commandrust-analyzer cargo sudo-rs 0.2.14 common/error/Error#ChDirNotAllowed#command.: self.commandrust-analyzer cargo sudo-rs 0.2.14 common/context/Context#command..commandrust-analyzer cargo sudo-rs 0.2.14 common/command/CommandAndArguments#command..clonerust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[PathBuf][Clone]clone().(), |
| 258 | }); |
| 259 | } else { |
| 260 | optdir.as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_ref().() |
| 261 | } |
| 262 | } |
| 263 | }; |
| 264 | |
| 265 | // expand tildes in the path with the users home directory |
| 266 | let chdir = chdir |
| 267 | .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(|dir| dir.expand_tilde_in_pathrust-analyzer cargo sudo-rs 0.2.14 common/path/impl#[SudoPath]expand_tilde_in_path().(&self.target_userrust-analyzer cargo sudo-rs 0.2.14 common/context/Context#target_user..namerust-analyzer cargo sudo-rs 0.2.14 system/User#name.)) |
| 268 | .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().; |
| 269 | |
| 270 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(RunOptionsrust-analyzer cargo sudo-rs 0.2.14 exec/RunOptions# { |
| 271 | commandrust-analyzer cargo sudo-rs 0.2.14 exec/RunOptions#command.: if self.commandrust-analyzer cargo sudo-rs 0.2.14 common/context/Context#command..resolvedrust-analyzer cargo sudo-rs 0.2.14 common/command/CommandAndArguments#resolved. { |
| 272 | &self.commandrust-analyzer cargo sudo-rs 0.2.14 common/context/Context#command..commandrust-analyzer cargo sudo-rs 0.2.14 common/command/CommandAndArguments#command. |
| 273 | } else { |
| 274 | 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#(self.commandrust-analyzer cargo sudo-rs 0.2.14 common/context/Context#command..commandrust-analyzer cargo sudo-rs 0.2.14 common/command/CommandAndArguments#command..clonerust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[PathBuf][Clone]clone().())); |
| 275 | }, |
| 276 | argumentsrust-analyzer cargo sudo-rs 0.2.14 exec/RunOptions#arguments.: &self.commandrust-analyzer cargo sudo-rs 0.2.14 common/context/Context#command..argumentsrust-analyzer cargo sudo-rs 0.2.14 common/command/CommandAndArguments#arguments., |
| 277 | arg0rust-analyzer cargo sudo-rs 0.2.14 exec/RunOptions#arg0.: self.commandrust-analyzer cargo sudo-rs 0.2.14 common/context/Context#command..arg0rust-analyzer cargo sudo-rs 0.2.14 common/command/CommandAndArguments#arg0..as_derefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_deref().(), |
| 278 | chdirrust-analyzer cargo sudo-rs 0.2.14 exec/RunOptions#chdir.: chdir.as_derefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_deref().().maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(ToOwnedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/ToOwned#::to_ownedrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path][ToOwned]to_owned().), |
| 279 | is_loginrust-analyzer cargo sudo-rs 0.2.14 exec/RunOptions#is_login.: self.launchrust-analyzer cargo sudo-rs 0.2.14 common/context/Context#launch. rust-analyzer cargo sudo-rs 0.2.14 common/context/impl#[LaunchType][`PartialEq<Self>`]eq().==rust-analyzer cargo sudo-rs 0.2.14 common/context/impl#[LaunchType][`PartialEq<Self>`]eq(). rust-analyzer cargo sudo-rs 0.2.14 common/context/impl#[LaunchType][`PartialEq<Self>`]eq().LaunchTyperust-analyzer cargo sudo-rs 0.2.14 common/context/LaunchType#::Loginrust-analyzer cargo sudo-rs 0.2.14 common/context/LaunchType#Login#, |
| 280 | userrust-analyzer cargo sudo-rs 0.2.14 exec/RunOptions#user.: &self.target_userrust-analyzer cargo sudo-rs 0.2.14 common/context/Context#target_user., |
| 281 | grouprust-analyzer cargo sudo-rs 0.2.14 exec/RunOptions#group.: &self.target_grouprust-analyzer cargo sudo-rs 0.2.14 common/context/Context#target_group., |
| 282 | umaskrust-analyzer cargo sudo-rs 0.2.14 exec/RunOptions#umask.: controls.umaskrust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/Restrictions#umask., |
| 283 | |
| 284 | backgroundrust-analyzer cargo sudo-rs 0.2.14 exec/RunOptions#background.: self.backgroundrust-analyzer cargo sudo-rs 0.2.14 common/context/Context#background., |
| 285 | use_ptyrust-analyzer cargo sudo-rs 0.2.14 exec/RunOptions#use_pty.: controls.use_ptyrust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/Restrictions#use_pty., |
| 286 | noexecrust-analyzer cargo sudo-rs 0.2.14 exec/RunOptions#noexec.: controls.noexecrust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/Restrictions#noexec., |
| 287 | }) |
| 288 | } |
| 289 | } |
| 290 | |
| 291 | #[cfg(test)] |
| 292 | mod testsrust-analyzer cargo sudo-rs 0.2.14 common/context/tests/ { |
| 293 | use craterust-analyzer cargo sudo-rs 0.2.14 crate/::{commonrust-analyzer cargo sudo-rs 0.2.14 common/::resolverust-analyzer cargo sudo-rs 0.2.14 common/resolve/::CurrentUserrust-analyzer cargo sudo-rs 0.2.14 common/resolve/CurrentUser#, sudorust-analyzer cargo sudo-rs 0.2.14 sudo/::SudoActionrust-analyzer cargo sudo-rs 0.2.14 sudo/cli/SudoAction#, systemrust-analyzer cargo sudo-rs 0.2.14 system/::Hostnamerust-analyzer cargo sudo-rs 0.2.14 system/Hostname#}; |
| 294 | |
| 295 | use superrust-analyzer cargo sudo-rs 0.2.14 common/context/::Contextrust-analyzer cargo sudo-rs 0.2.14 common/context/Context#; |
| 296 | |
| 297 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 298 | fn test_build_run_contextrust-analyzer cargo sudo-rs 0.2.14 common/context/tests/test_build_run_context().() { |
| 299 | let mut options = SudoActionrust-analyzer cargo sudo-rs 0.2.14 sudo/cli/SudoAction#::try_parse_fromrust-analyzer cargo sudo-rs 0.2.14 sudo/cli/impl#[SudoAction]try_parse_from().(["sudo", "echo", "hello"]) |
| 300 | .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().() |
| 301 | .try_into_runrust-analyzer cargo sudo-rs 0.2.14 sudo/cli/tests/impl#[SudoAction]try_into_run().() |
| 302 | .okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]ok().() |
| 303 | .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(); |
| 304 | |
| 305 | let current_user = CurrentUserrust-analyzer cargo sudo-rs 0.2.14 common/resolve/CurrentUser#::resolverust-analyzer cargo sudo-rs 0.2.14 common/resolve/impl#[CurrentUser]resolve().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 306 | options.userrust-analyzer cargo sudo-rs 0.2.14 sudo/cli/SudoRunOptions#user. = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(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().()); |
| 307 | |
| 308 | let context = Contextrust-analyzer cargo sudo-rs 0.2.14 common/context/Context#::from_run_optsrust-analyzer cargo sudo-rs 0.2.14 common/context/impl#[Context]from_run_opts().(options, &mut Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default#::defaultrust-analyzer cargo sudo-rs 0.2.14 sudoers/impl#[Sudoers][Default]default().()).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 309 | |
| 310 | if cfgrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/cfg!!(target_os = "linux") { |
| 311 | // this assumes /bin is a symlink on /usr/bin, like it is on modern Debian/Ubuntu |
| 312 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(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..to_strrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]to_str().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(), "/usr/bin/echo"); |
| 313 | } else { |
| 314 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(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..to_strrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]to_str().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(), "/bin/echo"); |
| 315 | } |
| 316 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(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., ["hello"]); |
| 317 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(context.hostnamerust-analyzer cargo sudo-rs 0.2.14 common/context/Context#hostname., Hostnamerust-analyzer cargo sudo-rs 0.2.14 system/Hostname#::resolverust-analyzer cargo sudo-rs 0.2.14 system/impl#[Hostname]resolve().()); |
| 318 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(context.target_userrust-analyzer cargo sudo-rs 0.2.14 common/context/Context#target_user..uidrust-analyzer cargo sudo-rs 0.2.14 system/User#uid., current_user.uidrust-analyzer cargo sudo-rs 0.2.14 system/User#uid.); |
| 319 | } |
| 320 | } |