| 1 | //! Data types and traits that represent what the "terms and conditions" are after a successful |
| 2 | //! permission check. |
| 3 | //! |
| 4 | //! The trait definitions can be part of some global crate in the future, if we support more |
| 5 | //! than just the sudoers file. |
| 6 | |
| 7 | use superrust-analyzer cargo sudo-rs 0.2.14 sudoers/::{Judgementrust-analyzer cargo sudo-rs 0.2.14 sudoers/Judgement#, Sudoersrust-analyzer cargo sudo-rs 0.2.14 sudoers/Sudoers#}; |
| 8 | use craterust-analyzer cargo sudo-rs 0.2.14 crate/::commonrust-analyzer cargo sudo-rs 0.2.14 common/::{ |
| 9 | 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., SudoPathrust-analyzer cargo sudo-rs 0.2.14 common/path/SudoPath#, |
| 10 | }; |
| 11 | use craterust-analyzer cargo sudo-rs 0.2.14 crate/::execrust-analyzer cargo sudo-rs 0.2.14 exec/::Umaskrust-analyzer cargo sudo-rs 0.2.14 exec/Umask#; |
| 12 | use craterust-analyzer cargo sudo-rs 0.2.14 crate/::sudoersrust-analyzer cargo sudo-rs 0.2.14 sudoers/::astrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/::{ExecControlrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/ExecControl#, Tagrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Tag#}; |
| 13 | use craterust-analyzer cargo sudo-rs 0.2.14 crate/::systemrust-analyzer cargo sudo-rs 0.2.14 system/::{Hostnamerust-analyzer cargo sudo-rs 0.2.14 system/Hostname#, Userrust-analyzer cargo sudo-rs 0.2.14 system/User#}; |
| 14 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::collectionsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/::HashSetrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/HashSet#; |
| 15 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::timerust-analyzer cargo std https://github.com/rust-lang/rust/library/std time/::Durationrust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/Duration#; |
| 16 | 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#, 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#}; |
| 17 | |
| 18 | #[must_use] |
| 19 | #[cfg_attr(test, derive(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:))] |
| 20 | #[repr(u32)] |
| 21 | pub enum Authorizationrust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/Authorization#<T = ()> { |
| 22 | Allowedrust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/Authorization#Allowed#(Authenticationrust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/Authentication#, T) = HARDENED_ENUM_VALUE_0rust-analyzer cargo sudo-rs 0.2.14 common/HARDENED_ENUM_VALUE_0., |
| 23 | Forbiddenrust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/Authorization#Forbidden# = HARDENED_ENUM_VALUE_1rust-analyzer cargo sudo-rs 0.2.14 common/HARDENED_ENUM_VALUE_1., |
| 24 | } |
| 25 | |
| 26 | #[cfg_attr(test, derive(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:))] |
| 27 | #[must_use] |
| 28 | pub struct Authenticationrust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/Authentication# { |
| 29 | pub must_authenticaterust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/Authentication#must_authenticate.: bool, |
| 30 | pub credentialrust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/Authentication#credential.: AuthenticatingUserrust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/AuthenticatingUser#, |
| 31 | pub allowed_attemptsrust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/Authentication#allowed_attempts.: u16, |
| 32 | pub prior_validityrust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/Authentication#prior_validity.: Durationrust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/Duration#, |
| 33 | pub pwfeedbackrust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/Authentication#pwfeedback.: bool, |
| 34 | pub password_timeoutrust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/Authentication#password_timeout.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Durationrust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/Duration#>, |
| 35 | pub noninteractive_authrust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/Authentication#noninteractive_auth.: bool, |
| 36 | } |
| 37 | |
| 38 | impl superrust-analyzer cargo sudo-rs 0.2.14 sudoers/::Settingsrust-analyzer cargo sudo-rs 0.2.14 sudoers/Settings# { |
| 39 | pub(superrust-analyzer cargo sudo-rs 0.2.14 sudoers/) fn to_authrust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/impl#[`crate::defaults::Settings`]to_auth().(&self, tag: &Tagrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Tag#) -> Authenticationrust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/Authentication# { |
| 40 | Authenticationrust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/Authentication# { |
| 41 | must_authenticaterust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/Authentication#must_authenticate.: tag.needs_passwdrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/impl#[Tag]needs_passwd().(), |
| 42 | allowed_attemptsrust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/Authentication#allowed_attempts.: self.passwd_triesrust-analyzer cargo sudo-rs 0.2.14 defaults/impl#[Settings]passwd_tries().().try_intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`TryInto<U>`]try_into().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), |
| 43 | prior_validityrust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/Authentication#prior_validity.: Durationrust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/Duration#::from_secsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/impl#[Duration]from_secs().(self.timestamp_timeoutrust-analyzer cargo sudo-rs 0.2.14 defaults/impl#[Settings]timestamp_timeout().()), |
| 44 | pwfeedbackrust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/Authentication#pwfeedback.: self.pwfeedbackrust-analyzer cargo sudo-rs 0.2.14 defaults/impl#[Settings]pwfeedback().(), |
| 45 | password_timeoutrust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/Authentication#password_timeout.: match self.passwd_timeoutrust-analyzer cargo sudo-rs 0.2.14 defaults/impl#[Settings]passwd_timeout().() { |
| 46 | 0 => Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, |
| 47 | timeout => Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Durationrust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/Duration#::from_secsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/impl#[Duration]from_secs().(timeout)), |
| 48 | }, |
| 49 | noninteractive_authrust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/Authentication#noninteractive_auth.: self.noninteractive_authrust-analyzer cargo sudo-rs 0.2.14 defaults/impl#[Settings]noninteractive_auth().(), |
| 50 | credentialrust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/Authentication#credential.: if self.rootpwrust-analyzer cargo sudo-rs 0.2.14 defaults/impl#[Settings]rootpw().() { |
| 51 | AuthenticatingUserrust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/AuthenticatingUser#::Rootrust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/AuthenticatingUser#Root# |
| 52 | } else if self.targetpwrust-analyzer cargo sudo-rs 0.2.14 defaults/impl#[Settings]targetpw().() { |
| 53 | AuthenticatingUserrust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/AuthenticatingUser#::TargetUserrust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/AuthenticatingUser#TargetUser# |
| 54 | } else { |
| 55 | AuthenticatingUserrust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/AuthenticatingUser#::InvokingUserrust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/AuthenticatingUser#InvokingUser# |
| 56 | }, |
| 57 | } |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | #[must_use] |
| 62 | #[cfg_attr(test, derive(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:))] |
| 63 | pub struct Restrictionsrust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/Restrictions#<'a> { |
| 64 | pub use_ptyrust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/Restrictions#use_pty.: bool, |
| 65 | pub trust_environmentrust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/Restrictions#trust_environment.: bool, |
| 66 | pub noexecrust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/Restrictions#noexec.: bool, |
| 67 | pub env_keeprust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/Restrictions#env_keep.: &'a HashSetrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/HashSet#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>, |
| 68 | pub env_checkrust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/Restrictions#env_check.: &'a HashSetrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/HashSet#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>, |
| 69 | pub chdirrust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/Restrictions#chdir.: DirChangerust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/DirChange#, |
| 70 | pub pathrust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/Restrictions#path.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&'a str>, |
| 71 | pub umaskrust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/Restrictions#umask.: Umaskrust-analyzer cargo sudo-rs 0.2.14 exec/Umask#, |
| 72 | #[cfg(feature = "apparmor")] |
| 73 | pub apparmor_profilerust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/Restrictions#apparmor_profile.: 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#>, |
| 74 | } |
| 75 | |
| 76 | #[must_use] |
| 77 | #[cfg_attr(test, derive(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:))] |
| 78 | #[repr(u32)] |
| 79 | pub enum DirChangerust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/DirChange# { |
| 80 | Strictrust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/DirChange#Strict#(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#>) = HARDENED_ENUM_VALUE_0rust-analyzer cargo sudo-rs 0.2.14 common/HARDENED_ENUM_VALUE_0., |
| 81 | Anyrust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/DirChange#Any# = HARDENED_ENUM_VALUE_1rust-analyzer cargo sudo-rs 0.2.14 common/HARDENED_ENUM_VALUE_1., |
| 82 | } |
| 83 | |
| 84 | #[cfg_attr(test, derive(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:))] |
| 85 | #[repr(u32)] |
| 86 | pub enum AuthenticatingUserrust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/AuthenticatingUser# { |
| 87 | InvokingUserrust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/AuthenticatingUser#InvokingUser# = HARDENED_ENUM_VALUE_0rust-analyzer cargo sudo-rs 0.2.14 common/HARDENED_ENUM_VALUE_0., |
| 88 | Rootrust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/AuthenticatingUser#Root# = HARDENED_ENUM_VALUE_1rust-analyzer cargo sudo-rs 0.2.14 common/HARDENED_ENUM_VALUE_1., |
| 89 | TargetUserrust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/AuthenticatingUser#TargetUser# = HARDENED_ENUM_VALUE_2rust-analyzer cargo sudo-rs 0.2.14 common/HARDENED_ENUM_VALUE_2., |
| 90 | } |
| 91 | |
| 92 | impl Judgementrust-analyzer cargo sudo-rs 0.2.14 sudoers/Judgement# { |
| 93 | pub fn authorizationrust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/impl#[Judgement]authorization().(&self) -> Authorizationrust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/Authorization#<Restrictionsrust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/Restrictions#<'_>> { |
| 94 | // NOTE: we should add conditional compilation to the DSL; this avoids getting |
| 95 | // an unused warning message |
| 96 | #[cfg(not(feature = "apparmor"))] |
| 97 | let _ = &self.settings.apparmor_profile(); |
| 98 | |
| 99 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(tag) = &self.flagsrust-analyzer cargo sudo-rs 0.2.14 sudoers/Judgement#flags. { |
| 100 | Authorizationrust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/Authorization#::Allowedrust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/Authorization#Allowed#( |
| 101 | self.settingsrust-analyzer cargo sudo-rs 0.2.14 sudoers/Judgement#settings..to_authrust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/impl#[`crate::defaults::Settings`]to_auth().(tag), |
| 102 | Restrictionsrust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/Restrictions# { |
| 103 | use_ptyrust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/Restrictions#use_pty.: self.settingsrust-analyzer cargo sudo-rs 0.2.14 sudoers/Judgement#settings..use_ptyrust-analyzer cargo sudo-rs 0.2.14 defaults/impl#[Settings]use_pty().(), |
| 104 | trust_environmentrust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/Restrictions#trust_environment.: match tag.envrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Tag#env. { |
| 105 | superrust-analyzer cargo sudo-rs 0.2.14 sudoers/::EnvironmentControlrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/EnvironmentControl#::Implicitrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/EnvironmentControl#Implicit# => self.settingsrust-analyzer cargo sudo-rs 0.2.14 sudoers/Judgement#settings..setenvrust-analyzer cargo sudo-rs 0.2.14 defaults/impl#[Settings]setenv().(), |
| 106 | superrust-analyzer cargo sudo-rs 0.2.14 sudoers/::EnvironmentControlrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/EnvironmentControl#::Setenvrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/EnvironmentControl#Setenv# => true, |
| 107 | superrust-analyzer cargo sudo-rs 0.2.14 sudoers/::EnvironmentControlrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/EnvironmentControl#::Nosetenvrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/EnvironmentControl#Nosetenv# => false, |
| 108 | }, |
| 109 | noexecrust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/Restrictions#noexec.: match tag.noexecrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Tag#noexec. { |
| 110 | ExecControlrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/ExecControl#::Implicitrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/ExecControl#Implicit# => self.settingsrust-analyzer cargo sudo-rs 0.2.14 sudoers/Judgement#settings..noexecrust-analyzer cargo sudo-rs 0.2.14 defaults/impl#[Settings]noexec().(), |
| 111 | ExecControlrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/ExecControl#::Execrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/ExecControl#Exec# => false, |
| 112 | ExecControlrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/ExecControl#::Noexecrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/ExecControl#Noexec# => true, |
| 113 | }, |
| 114 | env_keeprust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/Restrictions#env_keep.: self.settingsrust-analyzer cargo sudo-rs 0.2.14 sudoers/Judgement#settings..env_keeprust-analyzer cargo sudo-rs 0.2.14 defaults/impl#[Settings]env_keep().(), |
| 115 | env_checkrust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/Restrictions#env_check.: self.settingsrust-analyzer cargo sudo-rs 0.2.14 sudoers/Judgement#settings..env_checkrust-analyzer cargo sudo-rs 0.2.14 defaults/impl#[Settings]env_check().(), |
| 116 | chdirrust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/Restrictions#chdir.: match tag.cwdrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Tag#cwd..clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][Clone]clone().().or_elserust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]or_else().(|| { |
| 117 | // a `runcwd` default acts as the working directory when no explicit CWD was set |
| 118 | self.settingsrust-analyzer cargo sudo-rs 0.2.14 sudoers/Judgement#settings. |
| 119 | .runcwdrust-analyzer cargo sudo-rs 0.2.14 defaults/impl#[Settings]runcwd().() |
| 120 | .and_thenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]and_then().(|s| superrust-analyzer cargo sudo-rs 0.2.14 sudoers/::basic_parserrust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/::Tokenrust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/Token#::constructrust-analyzer cargo sudo-rs 0.2.14 sudoers/tokens/impl#[ChDir][Token]construct().(s.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()).okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]ok().()) |
| 121 | }) { |
| 122 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => DirChangerust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/DirChange#::Strictrust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/DirChange#Strict#(Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#), |
| 123 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(superrust-analyzer cargo sudo-rs 0.2.14 sudoers/::ChDirrust-analyzer cargo sudo-rs 0.2.14 sudoers/tokens/ChDir#::Anyrust-analyzer cargo sudo-rs 0.2.14 sudoers/tokens/ChDir#Any#) => DirChangerust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/DirChange#::Anyrust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/DirChange#Any#, |
| 124 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(superrust-analyzer cargo sudo-rs 0.2.14 sudoers/::ChDirrust-analyzer cargo sudo-rs 0.2.14 sudoers/tokens/ChDir#::Pathrust-analyzer cargo sudo-rs 0.2.14 sudoers/tokens/ChDir#Path#(path)) => DirChangerust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/DirChange#::Strictrust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/DirChange#Strict#(Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(path)), |
| 125 | }, |
| 126 | pathrust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/Restrictions#path.: self.settingsrust-analyzer cargo sudo-rs 0.2.14 sudoers/Judgement#settings..secure_pathrust-analyzer cargo sudo-rs 0.2.14 defaults/impl#[Settings]secure_path().(), |
| 127 | umaskrust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/Restrictions#umask.: { |
| 128 | let mask = self |
| 129 | .settingsrust-analyzer cargo sudo-rs 0.2.14 sudoers/Judgement#settings. |
| 130 | .umaskrust-analyzer cargo sudo-rs 0.2.14 defaults/impl#[Settings]umask().() |
| 131 | .try_intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`TryInto<U>`]try_into().() |
| 132 | .expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("the umask parser should have prevented overflow"); |
| 133 | if mask rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialEq<Self>`]eq().0o777 { |
| 134 | Umaskrust-analyzer cargo sudo-rs 0.2.14 exec/Umask#::Preserverust-analyzer cargo sudo-rs 0.2.14 exec/Umask#Preserve# |
| 135 | } else if self.settingsrust-analyzer cargo sudo-rs 0.2.14 sudoers/Judgement#settings..umask_overriderust-analyzer cargo sudo-rs 0.2.14 defaults/impl#[Settings]umask_override().() { |
| 136 | Umaskrust-analyzer cargo sudo-rs 0.2.14 exec/Umask#::Overriderust-analyzer cargo sudo-rs 0.2.14 exec/Umask#Override#(mask) |
| 137 | } else { |
| 138 | Umaskrust-analyzer cargo sudo-rs 0.2.14 exec/Umask#::Extendrust-analyzer cargo sudo-rs 0.2.14 exec/Umask#Extend#(mask) |
| 139 | } |
| 140 | }, |
| 141 | #[cfg(feature = "apparmor")] |
| 142 | apparmor_profilerust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/Restrictions#apparmor_profile.: tag |
| 143 | .apparmor_profilerust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Tag#apparmor_profile. |
| 144 | .as_derefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_deref().() |
| 145 | .orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]or().(self.settingsrust-analyzer cargo sudo-rs 0.2.14 sudoers/Judgement#settings..apparmor_profilerust-analyzer cargo sudo-rs 0.2.14 defaults/impl#[Settings]apparmor_profile().()) |
| 146 | .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(|x| x.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()), |
| 147 | }, |
| 148 | ) |
| 149 | } else { |
| 150 | Authorizationrust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/Authorization#::Forbiddenrust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/Authorization#Forbidden# |
| 151 | } |
| 152 | } |
| 153 | |
| 154 | pub(craterust-analyzer cargo sudo-rs 0.2.14 crate/) fn preferred_editorrust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/impl#[Judgement]preferred_editor().(&self) -> (PathBufrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/PathBuf#, Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<OsStringrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/OsString#>) { |
| 155 | // if no editor could be selected, fall back to /bin/vi; |
| 156 | // note that /bin/vi is also likely to have been tried as part of |
| 157 | // the "editor" setting, so this is a last-resort |
| 158 | superrust-analyzer cargo sudo-rs 0.2.14 sudoers/::select_editorrust-analyzer cargo sudo-rs 0.2.14 sudoers/select_editor().(&self.settingsrust-analyzer cargo sudo-rs 0.2.14 sudoers/Judgement#settings., true) |
| 159 | .unwrap_or_elserust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or_else().(|| (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().("/usr/bin/vi"), vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![])) |
| 160 | } |
| 161 | } |
| 162 | |
| 163 | impl Sudoersrust-analyzer cargo sudo-rs 0.2.14 sudoers/Sudoers# { |
| 164 | pub fn search_pathrust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/impl#[Sudoers]search_path().( |
| 165 | &mut self, |
| 166 | on_host: &Hostnamerust-analyzer cargo sudo-rs 0.2.14 system/Hostname#, |
| 167 | current_user: &Userrust-analyzer cargo sudo-rs 0.2.14 system/User#, |
| 168 | target_user: &Userrust-analyzer cargo sudo-rs 0.2.14 system/User#, |
| 169 | ) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&str> { |
| 170 | self.specify_host_user_runasrust-analyzer cargo sudo-rs 0.2.14 sudoers/impl#[Sudoers]specify_host_user_runas().(on_host, current_user, Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(target_user)); |
| 171 | self.settingsrust-analyzer cargo sudo-rs 0.2.14 sudoers/Sudoers#settings..secure_pathrust-analyzer cargo sudo-rs 0.2.14 defaults/impl#[Settings]secure_path().() |
| 172 | } |
| 173 | } |
| 174 | |
| 175 | #[cfg(test)] |
| 176 | mod testrust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/test/ { |
| 177 | use superrust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/::*; |
| 178 | use craterust-analyzer cargo sudo-rs 0.2.14 crate/::sudoersrust-analyzer cargo sudo-rs 0.2.14 sudoers/::{ |
| 179 | astrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/::{Authenticaterust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Authenticate#, Tagrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Tag#}, |
| 180 | tokensrust-analyzer cargo sudo-rs 0.2.14 sudoers/tokens/::ChDirrust-analyzer cargo sudo-rs 0.2.14 sudoers/tokens/ChDir#, |
| 181 | }; |
| 182 | |
| 183 | impl Judgementrust-analyzer cargo sudo-rs 0.2.14 sudoers/Judgement# { |
| 184 | fn mod_flagrust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/test/impl#[Judgement]mod_flag().(&mut self, mut modify: impl FnMutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnMut#(&mut Tagrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Tag#)) { |
| 185 | let mut tag: Tagrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Tag# = self.flagsrust-analyzer cargo sudo-rs 0.2.14 sudoers/Judgement#flags..clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][Clone]clone().().unwrap_or_defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or_default().(); |
| 186 | modify(&mut tag); |
| 187 | self.flagsrust-analyzer cargo sudo-rs 0.2.14 sudoers/Judgement#flags. = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(tag); |
| 188 | } |
| 189 | } |
| 190 | |
| 191 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 192 | fn authority_xlat_testrust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/test/authority_xlat_test().() { |
| 193 | let mut judge: Judgementrust-analyzer cargo sudo-rs 0.2.14 sudoers/Judgement# = Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default#::defaultrust-analyzer cargo sudo-rs 0.2.14 sudoers/impl#[Judgement][Default]default().(); |
| 194 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(judge.authorizationrust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/impl#[Judgement]authorization().(), Authorizationrust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/Authorization#::Forbiddenrust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/Authorization#Forbidden#); |
| 195 | judge.mod_flagrust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/test/impl#[Judgement]mod_flag().(|tag| tag.authenticaterust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Tag#authenticate. = Authenticaterust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Authenticate#::Passwdrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Authenticate#Passwd#); |
| 196 | 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, restrictions) = judge.authorizationrust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/impl#[Judgement]authorization().() else { |
| 197 | panicrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/panic!!(); |
| 198 | }; |
| 199 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 200 | auth, |
| 201 | Authenticationrust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/Authentication# { |
| 202 | must_authenticaterust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/Authentication#must_authenticate.: true, |
| 203 | allowed_attemptsrust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/Authentication#allowed_attempts.: 3, |
| 204 | prior_validityrust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/Authentication#prior_validity.: Durationrust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/Duration#::from_secsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/impl#[Duration]from_secs().(15 *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Mul<Self>`]mul(). 60), |
| 205 | credentialrust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/Authentication#credential.: AuthenticatingUserrust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/AuthenticatingUser#::InvokingUserrust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/AuthenticatingUser#InvokingUser#, |
| 206 | pwfeedbackrust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/Authentication#pwfeedback.: true, |
| 207 | noninteractive_authrust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/Authentication#noninteractive_auth.: false, |
| 208 | password_timeoutrust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/Authentication#password_timeout.: Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Durationrust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/Duration#::from_secsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/impl#[Duration]from_secs().(300)), |
| 209 | }, |
| 210 | ); |
| 211 | |
| 212 | let mut judge = judge.clonerust-analyzer cargo sudo-rs 0.2.14 sudoers/impl#[Judgement][Clone]clone().(); |
| 213 | judge.mod_flagrust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/test/impl#[Judgement]mod_flag().(|tag| tag.authenticaterust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Tag#authenticate. = Authenticaterust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Authenticate#::Nopasswdrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Authenticate#Nopasswd#); |
| 214 | 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, restrictions2) = judge.authorizationrust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/impl#[Judgement]authorization().() else { |
| 215 | panicrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/panic!!(); |
| 216 | }; |
| 217 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 218 | auth, |
| 219 | Authenticationrust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/Authentication# { |
| 220 | must_authenticaterust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/Authentication#must_authenticate.: false, |
| 221 | allowed_attemptsrust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/Authentication#allowed_attempts.: 3, |
| 222 | prior_validityrust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/Authentication#prior_validity.: Durationrust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/Duration#::from_secsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/impl#[Duration]from_secs().(15 *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Mul<Self>`]mul(). 60), |
| 223 | credentialrust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/Authentication#credential.: AuthenticatingUserrust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/AuthenticatingUser#::InvokingUserrust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/AuthenticatingUser#InvokingUser#, |
| 224 | pwfeedbackrust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/Authentication#pwfeedback.: true, |
| 225 | noninteractive_authrust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/Authentication#noninteractive_auth.: false, |
| 226 | password_timeoutrust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/Authentication#password_timeout.: Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Durationrust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/Duration#::from_secsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/impl#[Duration]from_secs().(300)), |
| 227 | }, |
| 228 | ); |
| 229 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(restrictions, restrictions2); |
| 230 | } |
| 231 | |
| 232 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 233 | fn chdir_testrust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/test/chdir_test().() { |
| 234 | let mut judge = Judgementrust-analyzer cargo sudo-rs 0.2.14 sudoers/Judgement# { |
| 235 | flagsrust-analyzer cargo sudo-rs 0.2.14 sudoers/Judgement#flags.: Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Tagrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Tag#::defaultrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/impl#[Tag][Default]default().()), |
| 236 | ..Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default#::defaultrust-analyzer cargo sudo-rs 0.2.14 sudoers/impl#[Judgement][Default]default().() |
| 237 | }; |
| 238 | fn chdirrust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/test/chdir().(judge: &mut Judgementrust-analyzer cargo sudo-rs 0.2.14 sudoers/Judgement#) -> DirChangerust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/DirChange# { |
| 239 | let Authorizationrust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/Authorization#::Allowedrust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/Authorization#Allowed#(_, ctl) = judge.authorizationrust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/impl#[Judgement]authorization().() else { |
| 240 | panicrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/panic!!() |
| 241 | }; |
| 242 | ctl.chdirrust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/Restrictions#chdir. |
| 243 | } |
| 244 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(chdirrust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/test/chdir().(&mut judge), DirChangerust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/DirChange#::Strictrust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/DirChange#Strict#(Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#)); |
| 245 | judge.mod_flagrust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/test/impl#[Judgement]mod_flag().(|tag| tag.cwdrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Tag#cwd. = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(ChDirrust-analyzer cargo sudo-rs 0.2.14 sudoers/tokens/ChDir#::Anyrust-analyzer cargo sudo-rs 0.2.14 sudoers/tokens/ChDir#Any#)); |
| 246 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(chdirrust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/test/chdir().(&mut judge), DirChangerust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/DirChange#::Anyrust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/DirChange#Any#); |
| 247 | judge.mod_flagrust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/test/impl#[Judgement]mod_flag().(|tag| tag.cwdrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Tag#cwd. = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(ChDirrust-analyzer cargo sudo-rs 0.2.14 sudoers/tokens/ChDir#::Pathrust-analyzer cargo sudo-rs 0.2.14 sudoers/tokens/ChDir#Path#("/usr".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()))); |
| 248 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(chdirrust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/test/chdir().(&mut judge), (DirChangerust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/DirChange#::Strictrust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/DirChange#Strict#(Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("/usr".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().())))); |
| 249 | judge.mod_flagrust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/test/impl#[Judgement]mod_flag().(|tag| tag.cwdrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Tag#cwd. = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(ChDirrust-analyzer cargo sudo-rs 0.2.14 sudoers/tokens/ChDir#::Pathrust-analyzer cargo sudo-rs 0.2.14 sudoers/tokens/ChDir#Path#("/bin".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()))); |
| 250 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(chdirrust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/test/chdir().(&mut judge), (DirChangerust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/DirChange#::Strictrust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/DirChange#Strict#(Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("/bin".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().())))); |
| 251 | } |
| 252 | } |