| 1 | use craterust-analyzer cargo sudo-rs 0.2.14 crate/::{pamrust-analyzer cargo sudo-rs 0.2.14 pam/::PamErrorrust-analyzer cargo sudo-rs 0.2.14 pam/error/PamError#, systemrust-analyzer cargo sudo-rs 0.2.14 system/::Hostnamerust-analyzer cargo sudo-rs 0.2.14 system/Hostname#}; |
| 2 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::{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#, fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/, 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#}; |
| 3 | |
| 4 | use superrust-analyzer cargo sudo-rs 0.2.14 common/::{SudoPathrust-analyzer cargo sudo-rs 0.2.14 common/path/SudoPath#, SudoStringrust-analyzer cargo sudo-rs 0.2.14 common/string/SudoString#}; |
| 5 | |
| 6 | #[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:)] |
| 7 | pub enum Errorrust-analyzer cargo sudo-rs 0.2.14 common/error/Error# { |
| 8 | Silentrust-analyzer cargo sudo-rs 0.2.14 common/error/Error#Silent#, |
| 9 | NotAllowedrust-analyzer cargo sudo-rs 0.2.14 common/error/Error#NotAllowed# { |
| 10 | usernamerust-analyzer cargo sudo-rs 0.2.14 common/error/Error#NotAllowed#username.: SudoStringrust-analyzer cargo sudo-rs 0.2.14 common/string/SudoString#, |
| 11 | commandrust-analyzer cargo sudo-rs 0.2.14 common/error/Error#NotAllowed#command.: Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#<'static, str>, |
| 12 | hostnamerust-analyzer cargo sudo-rs 0.2.14 common/error/Error#NotAllowed#hostname.: Hostnamerust-analyzer cargo sudo-rs 0.2.14 system/Hostname#, |
| 13 | other_userrust-analyzer cargo sudo-rs 0.2.14 common/error/Error#NotAllowed#other_user.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<SudoStringrust-analyzer cargo sudo-rs 0.2.14 common/string/SudoString#>, |
| 14 | }, |
| 15 | SelfCheckSetuidrust-analyzer cargo sudo-rs 0.2.14 common/error/Error#SelfCheckSetuid#, |
| 16 | SelfCheckNoNewPrivsrust-analyzer cargo sudo-rs 0.2.14 common/error/Error#SelfCheckNoNewPrivs#, |
| 17 | CommandNotFoundrust-analyzer cargo sudo-rs 0.2.14 common/error/Error#CommandNotFound#(PathBufrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/PathBuf#), |
| 18 | InvalidCommandrust-analyzer cargo sudo-rs 0.2.14 common/error/Error#InvalidCommand#(PathBufrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/PathBuf#), |
| 19 | ChDirNotAllowedrust-analyzer cargo sudo-rs 0.2.14 common/error/Error#ChDirNotAllowed# { |
| 20 | chdirrust-analyzer cargo sudo-rs 0.2.14 common/error/Error#ChDirNotAllowed#chdir.: SudoPathrust-analyzer cargo sudo-rs 0.2.14 common/path/SudoPath#, |
| 21 | commandrust-analyzer cargo sudo-rs 0.2.14 common/error/Error#ChDirNotAllowed#command.: PathBufrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/PathBuf#, |
| 22 | }, |
| 23 | UserNotFoundrust-analyzer cargo sudo-rs 0.2.14 common/error/Error#UserNotFound#(Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#), |
| 24 | GroupNotFoundrust-analyzer cargo sudo-rs 0.2.14 common/error/Error#GroupNotFound#(Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#), |
| 25 | Authorizationrust-analyzer cargo sudo-rs 0.2.14 common/error/Error#Authorization#(Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#), |
| 26 | InteractionRequiredrust-analyzer cargo sudo-rs 0.2.14 common/error/Error#InteractionRequired#, |
| 27 | EnvironmentVarrust-analyzer cargo sudo-rs 0.2.14 common/error/Error#EnvironmentVar#(Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>), |
| 28 | Configurationrust-analyzer cargo sudo-rs 0.2.14 common/error/Error#Configuration#(Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#), |
| 29 | Optionsrust-analyzer cargo sudo-rs 0.2.14 common/error/Error#Options#(Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#), |
| 30 | Pamrust-analyzer cargo sudo-rs 0.2.14 common/error/Error#Pam#(PamErrorrust-analyzer cargo sudo-rs 0.2.14 pam/error/PamError#), |
| 31 | Iorust-analyzer cargo sudo-rs 0.2.14 common/error/Error#Io#(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#>, stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Error#), |
| 32 | MaxAuthAttemptsrust-analyzer cargo sudo-rs 0.2.14 common/error/Error#MaxAuthAttempts#(u16), |
| 33 | PathValidationrust-analyzer cargo sudo-rs 0.2.14 common/error/Error#PathValidation#(PathBufrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/PathBuf#), |
| 34 | StringValidationrust-analyzer cargo sudo-rs 0.2.14 common/error/Error#StringValidation#(Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#), |
| 35 | #[cfg(feature = "apparmor")] |
| 36 | AppArmorrust-analyzer cargo sudo-rs 0.2.14 common/error/Error#AppArmor#(Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Error#), |
| 37 | } |
| 38 | |
| 39 | impl fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Displayrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Display# for Errorrust-analyzer cargo sudo-rs 0.2.14 common/error/Error# { |
| 40 | fn fmtrust-analyzer cargo sudo-rs 0.2.14 common/error/impl#[Error][Display]fmt().(&self, f: &mut fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Formatterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Formatter#<'_>) -> fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Result# { |
| 41 | match self { |
| 42 | Errorrust-analyzer cargo sudo-rs 0.2.14 common/error/Error#::Silentrust-analyzer cargo sudo-rs 0.2.14 common/error/Error#Silent# => Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()), |
| 43 | Errorrust-analyzer cargo sudo-rs 0.2.14 common/error/Error#::NotAllowedrust-analyzer cargo sudo-rs 0.2.14 common/error/Error#NotAllowed# { |
| 44 | usernamerust-analyzer cargo sudo-rs 0.2.14 common/error/Error#NotAllowed#username., |
| 45 | commandrust-analyzer cargo sudo-rs 0.2.14 common/error/Error#NotAllowed#command., |
| 46 | hostnamerust-analyzer cargo sudo-rs 0.2.14 common/error/Error#NotAllowed#hostname., |
| 47 | other_userrust-analyzer cargo sudo-rs 0.2.14 common/error/Error#NotAllowed#other_user., |
| 48 | } => { |
| 49 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(other_user) = other_user { |
| 50 | xlat_writerust-analyzer cargo sudo-rs 0.2.14 gettext/xlat_write!!( |
| 51 | f, |
| 52 | "Sorry, user {user} is not allowed to execute '{command}' as {other_user} on {hostname}.", |
| 53 | user = username, |
| 54 | command = command, |
| 55 | other_user = other_user, |
| 56 | hostname = hostname, |
| 57 | ) |
| 58 | } else { |
| 59 | xlat_writerust-analyzer cargo sudo-rs 0.2.14 gettext/xlat_write!!( |
| 60 | f, |
| 61 | "Sorry, user {user} may not run {command} on {hostname}.", |
| 62 | user = username, |
| 63 | command = command, |
| 64 | hostname = hostname, |
| 65 | ) |
| 66 | } |
| 67 | } |
| 68 | Errorrust-analyzer cargo sudo-rs 0.2.14 common/error/Error#::SelfCheckSetuidrust-analyzer cargo sudo-rs 0.2.14 common/error/Error#SelfCheckSetuid# => { |
| 69 | xlat_writerust-analyzer cargo sudo-rs 0.2.14 gettext/xlat_write!!(f, "sudo must be owned by uid 0 and have the setuid bit set") |
| 70 | } |
| 71 | Errorrust-analyzer cargo sudo-rs 0.2.14 common/error/Error#::SelfCheckNoNewPrivsrust-analyzer cargo sudo-rs 0.2.14 common/error/Error#SelfCheckNoNewPrivs# => { |
| 72 | xlat_writerust-analyzer cargo sudo-rs 0.2.14 gettext/xlat_write!!( |
| 73 | f, |
| 74 | "The \"no new privileges\" flag is set, which prevents sudo from running as root.\n\ |
| 75 | If sudo is running in a container, you may need to adjust the container \ |
| 76 | configuration to disable the flag." |
| 77 | ) |
| 78 | } |
| 79 | Errorrust-analyzer cargo sudo-rs 0.2.14 common/error/Error#::CommandNotFoundrust-analyzer cargo sudo-rs 0.2.14 common/error/Error#CommandNotFound#(p) => { |
| 80 | xlat_writerust-analyzer cargo sudo-rs 0.2.14 gettext/xlat_write!!(f, "'{path}': command not found", path = p.displayrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]display().()) |
| 81 | } |
| 82 | Errorrust-analyzer cargo sudo-rs 0.2.14 common/error/Error#::InvalidCommandrust-analyzer cargo sudo-rs 0.2.14 common/error/Error#InvalidCommand#(p) => { |
| 83 | xlat_writerust-analyzer cargo sudo-rs 0.2.14 gettext/xlat_write!!(f, "'{path}': invalid command", path = p.displayrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]display().()) |
| 84 | } |
| 85 | Errorrust-analyzer cargo sudo-rs 0.2.14 common/error/Error#::UserNotFoundrust-analyzer cargo sudo-rs 0.2.14 common/error/Error#UserNotFound#(u) => xlat_writerust-analyzer cargo sudo-rs 0.2.14 gettext/xlat_write!!(f, "user '{user}' not found", user = u), |
| 86 | Errorrust-analyzer cargo sudo-rs 0.2.14 common/error/Error#::GroupNotFoundrust-analyzer cargo sudo-rs 0.2.14 common/error/Error#GroupNotFound#(g) => xlat_writerust-analyzer cargo sudo-rs 0.2.14 gettext/xlat_write!!(f, "group '{group}' not found", group = g), |
| 87 | Errorrust-analyzer cargo sudo-rs 0.2.14 common/error/Error#::Authorizationrust-analyzer cargo sudo-rs 0.2.14 common/error/Error#Authorization#(u) => { |
| 88 | // TRANSLATORS: This is a well-known quote, try to preserve it in translation. |
| 89 | xlat_writerust-analyzer cargo sudo-rs 0.2.14 gettext/xlat_write!!(f, "I'm sorry {user}. I'm afraid I can't do that", user = u) |
| 90 | } |
| 91 | Errorrust-analyzer cargo sudo-rs 0.2.14 common/error/Error#::InteractionRequiredrust-analyzer cargo sudo-rs 0.2.14 common/error/Error#InteractionRequired# => xlat_writerust-analyzer cargo sudo-rs 0.2.14 gettext/xlat_write!!(f, "interactive authentication is required"), |
| 92 | Errorrust-analyzer cargo sudo-rs 0.2.14 common/error/Error#::EnvironmentVarrust-analyzer cargo sudo-rs 0.2.14 common/error/Error#EnvironmentVar#(vs) => { |
| 93 | xlat_writerust-analyzer cargo sudo-rs 0.2.14 gettext/xlat_write!!( |
| 94 | f, |
| 95 | "you are not allowed to set the following environment variables:" |
| 96 | )?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 97 | let mut sep = ""; |
| 98 | for v in vs { |
| 99 | writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(f, "{sep} {v}")?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 100 | sep = ","; |
| 101 | } |
| 102 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 103 | } |
| 104 | Errorrust-analyzer cargo sudo-rs 0.2.14 common/error/Error#::Configurationrust-analyzer cargo sudo-rs 0.2.14 common/error/Error#Configuration#(e) => writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(f, "{e}"), |
| 105 | Errorrust-analyzer cargo sudo-rs 0.2.14 common/error/Error#::Optionsrust-analyzer cargo sudo-rs 0.2.14 common/error/Error#Options#(e) => writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(f, "{e}"), |
| 106 | Errorrust-analyzer cargo sudo-rs 0.2.14 common/error/Error#::Pamrust-analyzer cargo sudo-rs 0.2.14 common/error/Error#Pam#(e) => writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(f, "{e}"), |
| 107 | Errorrust-analyzer cargo sudo-rs 0.2.14 common/error/Error#::Iorust-analyzer cargo sudo-rs 0.2.14 common/error/Error#Io#(location, e) => { |
| 108 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(path) = location { |
| 109 | xlat_writerust-analyzer cargo sudo-rs 0.2.14 gettext/xlat_write!!( |
| 110 | f, |
| 111 | "cannot execute '{path}': {error}", |
| 112 | path = path.displayrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]display().(), |
| 113 | error = e |
| 114 | ) |
| 115 | } else { |
| 116 | xlat_writerust-analyzer cargo sudo-rs 0.2.14 gettext/xlat_write!!(f, "IO error: {error}", error = e) |
| 117 | } |
| 118 | } |
| 119 | Errorrust-analyzer cargo sudo-rs 0.2.14 common/error/Error#::MaxAuthAttemptsrust-analyzer cargo sudo-rs 0.2.14 common/error/Error#MaxAuthAttempts#(num) => { |
| 120 | xlat_writerust-analyzer cargo sudo-rs 0.2.14 gettext/xlat_write!!( |
| 121 | f, |
| 122 | "maximum {num} incorrect authentication attempts", |
| 123 | num = num |
| 124 | ) |
| 125 | } |
| 126 | Errorrust-analyzer cargo sudo-rs 0.2.14 common/error/Error#::ChDirNotAllowedrust-analyzer cargo sudo-rs 0.2.14 common/error/Error#ChDirNotAllowed# { chdirrust-analyzer cargo sudo-rs 0.2.14 common/error/Error#ChDirNotAllowed#chdir., commandrust-analyzer cargo sudo-rs 0.2.14 common/error/Error#ChDirNotAllowed#command. } => xlat_writerust-analyzer cargo sudo-rs 0.2.14 gettext/xlat_write!!( |
| 127 | f, |
| 128 | "you are not allowed to use '--chdir {path}' with '{command}'", |
| 129 | path = chdir.displayrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]display().(), |
| 130 | command = command.displayrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]display().() |
| 131 | ), |
| 132 | Errorrust-analyzer cargo sudo-rs 0.2.14 common/error/Error#::StringValidationrust-analyzer cargo sudo-rs 0.2.14 common/error/Error#StringValidation#(string) => { |
| 133 | writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!( |
| 134 | f, |
| 135 | "{}: {string:?}", |
| 136 | xlatrust-analyzer cargo sudo-rs 0.2.14 gettext/xlat!!("Unexpected null character in input") |
| 137 | ) |
| 138 | } |
| 139 | Errorrust-analyzer cargo sudo-rs 0.2.14 common/error/Error#::PathValidationrust-analyzer cargo sudo-rs 0.2.14 common/error/Error#PathValidation#(path) => { |
| 140 | writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!( |
| 141 | f, |
| 142 | "{}: {path:?}", |
| 143 | xlatrust-analyzer cargo sudo-rs 0.2.14 gettext/xlat!!("Unexpected null character in input") |
| 144 | ) |
| 145 | } |
| 146 | #[cfg(feature = "apparmor")] |
| 147 | Errorrust-analyzer cargo sudo-rs 0.2.14 common/error/Error#::AppArmorrust-analyzer cargo sudo-rs 0.2.14 common/error/Error#AppArmor#(profile, e) => { |
| 148 | xlat_writerust-analyzer cargo sudo-rs 0.2.14 gettext/xlat_write!!( |
| 149 | f, |
| 150 | "unable to change AppArmor profile to {profile}: {error}", |
| 151 | profile = profile, |
| 152 | error = e |
| 153 | ) |
| 154 | } |
| 155 | } |
| 156 | } |
| 157 | } |
| 158 | |
| 159 | impl Fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/From#<PamErrorrust-analyzer cargo sudo-rs 0.2.14 pam/error/PamError#> for Errorrust-analyzer cargo sudo-rs 0.2.14 common/error/Error# { |
| 160 | fn fromrust-analyzer cargo sudo-rs 0.2.14 common/error/impl#[Error][`From<PamError>`]from().(err: PamErrorrust-analyzer cargo sudo-rs 0.2.14 pam/error/PamError#) -> Selfrust-analyzer cargo sudo-rs 0.2.14 common/error/impl#[Error][`From<PamError>`] { |
| 161 | Errorrust-analyzer cargo sudo-rs 0.2.14 common/error/Error#::Pamrust-analyzer cargo sudo-rs 0.2.14 common/error/Error#Pam#(err) |
| 162 | } |
| 163 | } |
| 164 | |
| 165 | impl Fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/From#<stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Error#> for Errorrust-analyzer cargo sudo-rs 0.2.14 common/error/Error# { |
| 166 | fn fromrust-analyzer cargo sudo-rs 0.2.14 common/error/impl#[Error][`From<std::io::Error>`]from().(err: stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Error#) -> Selfrust-analyzer cargo sudo-rs 0.2.14 common/error/impl#[Error][`From<std::io::Error>`] { |
| 167 | Errorrust-analyzer cargo sudo-rs 0.2.14 common/error/Error#::Iorust-analyzer cargo sudo-rs 0.2.14 common/error/Error#Io#(Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, err) |
| 168 | } |
| 169 | } |
| 170 | |
| 171 | impl Errorrust-analyzer cargo sudo-rs 0.2.14 common/error/Error# { |
| 172 | /// Returns `true` if the error is [`Silent`]. |
| 173 | /// |
| 174 | /// [`Silent`]: Error::Silent |
| 175 | #[must_use] |
| 176 | pub fn is_silentrust-analyzer cargo sudo-rs 0.2.14 common/error/impl#[Error]is_silent().(&self) -> bool { |
| 177 | matchesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/matches!!(self, Selfrust-analyzer cargo sudo-rs 0.2.14 common/error/impl#[Error]::Silentrust-analyzer cargo sudo-rs 0.2.14 common/error/Error#Silent#) |
| 178 | } |
| 179 | } |