| 1 | #![forbid(unsafe_code)] |
| 2 | #![cfg_attr(not(feature = "unstable-remote-sudoers"), allow(unused_imports))] |
| 3 | |
| 4 | //! Code that checks (and in the future: lists) permissions in the sudoers file |
| 5 | |
| 6 | mod astrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/; |
| 7 | mod ast_namesrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast_names/; |
| 8 | mod basic_parserrust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/; |
| 9 | mod char_streamrust-analyzer cargo sudo-rs 0.2.14 sudoers/char_stream/; |
| 10 | mod entryrust-analyzer cargo sudo-rs 0.2.14 sudoers/entry/; |
| 11 | mod tokensrust-analyzer cargo sudo-rs 0.2.14 sudoers/tokens/; |
| 12 | |
| 13 | 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/::{HashMaprust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/HashMap#, HashSetrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/HashSet#}; |
| 14 | 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#; |
| 15 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/; |
| 16 | use 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/; |
| 17 | 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#, PathBufrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/PathBuf#}; |
| 18 | |
| 19 | 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/::{is_valid_executablerust-analyzer cargo sudo-rs 0.2.14 common/resolve/is_valid_executable()., resolve_pathrust-analyzer cargo sudo-rs 0.2.14 common/resolve/resolve_path().}; |
| 20 | use craterust-analyzer cargo sudo-rs 0.2.14 crate/::defaultsrust-analyzer cargo sudo-rs 0.2.14 defaults/; |
| 21 | use craterust-analyzer cargo sudo-rs 0.2.14 crate/::logrust-analyzer cargo sudo-rs 0.2.14 log/::auth_warnrust-analyzer cargo sudo-rs 0.2.14 log/auth_warn!; |
| 22 | use craterust-analyzer cargo sudo-rs 0.2.14 crate/::systemrust-analyzer cargo sudo-rs 0.2.14 system/::interfacerust-analyzer cargo sudo-rs 0.2.14 system/interface/::{GroupIdrust-analyzer cargo sudo-rs 0.2.14 system/interface/GroupId#, UnixGrouprust-analyzer cargo sudo-rs 0.2.14 system/interface/UnixGroup#, UnixUserrust-analyzer cargo sudo-rs 0.2.14 system/interface/UnixUser#, UserIdrust-analyzer cargo sudo-rs 0.2.14 system/interface/UserId#}; |
| 23 | use craterust-analyzer cargo sudo-rs 0.2.14 crate/::systemrust-analyzer cargo sudo-rs 0.2.14 system/::{selfrust-analyzer cargo sudo-rs 0.2.14 system/, auditrust-analyzer cargo sudo-rs 0.2.14 system/audit/}; |
| 24 | use astrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/::*; |
| 25 | use tokensrust-analyzer cargo sudo-rs 0.2.14 sudoers/tokens/::*; |
| 26 | |
| 27 | pub type Settingsrust-analyzer cargo sudo-rs 0.2.14 sudoers/Settings# = defaultsrust-analyzer cargo sudo-rs 0.2.14 defaults/::Settingsrust-analyzer cargo sudo-rs 0.2.14 defaults/Settings#; |
| 28 | pub use basic_parserrust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/::Spanrust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/Span#; |
| 29 | |
| 30 | /// How many nested include files do we allow? |
| 31 | const INCLUDE_LIMITrust-analyzer cargo sudo-rs 0.2.14 sudoers/INCLUDE_LIMIT.: u8 = 128; |
| 32 | |
| 33 | /// Export some necessary symbols from modules |
| 34 | pub struct Errorrust-analyzer cargo sudo-rs 0.2.14 sudoers/Error# { |
| 35 | pub sourcerust-analyzer cargo sudo-rs 0.2.14 sudoers/Error#source.: 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#>, |
| 36 | pub locationrust-analyzer cargo sudo-rs 0.2.14 sudoers/Error#location.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<basic_parserrust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/::Spanrust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/Span#>, |
| 37 | pub messagerust-analyzer cargo sudo-rs 0.2.14 sudoers/Error#message.: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, |
| 38 | } |
| 39 | |
| 40 | /// A "Customiser" represents a "Defaults" setting that has 'late binding'; i.e. |
| 41 | /// cannot be determined simply by reading a sudoers configuration. This is used |
| 42 | /// for Defaults@host, Defaults:user, Defaults>runas and Defaults!cmd. |
| 43 | /// |
| 44 | /// I.e. the Setting modifications in the second part of the tuple only apply for |
| 45 | /// items explicitly matched by the first part of the tuple. |
| 46 | type Customiserrust-analyzer cargo sudo-rs 0.2.14 sudoers/Customiser#<Scope> = (Scope, Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<defaultsrust-analyzer cargo sudo-rs 0.2.14 defaults/::SettingsModifierrust-analyzer cargo sudo-rs 0.2.14 defaults/SettingsModifier#>); |
| 47 | |
| 48 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default:)] |
| 49 | pub struct Sudoersrust-analyzer cargo sudo-rs 0.2.14 sudoers/Sudoers# { |
| 50 | rulesrust-analyzer cargo sudo-rs 0.2.14 sudoers/Sudoers#rules.: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<PermissionSpecrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/PermissionSpec#>, |
| 51 | aliasesrust-analyzer cargo sudo-rs 0.2.14 sudoers/Sudoers#aliases.: AliasTablerust-analyzer cargo sudo-rs 0.2.14 sudoers/AliasTable#, |
| 52 | settingsrust-analyzer cargo sudo-rs 0.2.14 sudoers/Sudoers#settings.: Settingsrust-analyzer cargo sudo-rs 0.2.14 sudoers/Settings#, |
| 53 | customisersrust-analyzer cargo sudo-rs 0.2.14 sudoers/Sudoers#customisers.: CustomiserTablerust-analyzer cargo sudo-rs 0.2.14 sudoers/CustomiserTable#, |
| 54 | } |
| 55 | |
| 56 | /// A structure that represents what the user wants to do |
| 57 | pub struct Requestrust-analyzer cargo sudo-rs 0.2.14 sudoers/Request#<'a, User: UnixUserrust-analyzer cargo sudo-rs 0.2.14 system/interface/UnixUser#, Group: UnixGrouprust-analyzer cargo sudo-rs 0.2.14 system/interface/UnixGroup#> { |
| 58 | pub userrust-analyzer cargo sudo-rs 0.2.14 sudoers/Request#user.: &'a User, |
| 59 | pub grouprust-analyzer cargo sudo-rs 0.2.14 sudoers/Request#group.: &'a Group, |
| 60 | pub commandrust-analyzer cargo sudo-rs 0.2.14 sudoers/Request#command.: &'a Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#, |
| 61 | pub argumentsrust-analyzer cargo sudo-rs 0.2.14 sudoers/Request#arguments.: &'a [OsStringrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/OsString#], |
| 62 | } |
| 63 | |
| 64 | pub struct ListRequestrust-analyzer cargo sudo-rs 0.2.14 sudoers/ListRequest#<'a, User: UnixUserrust-analyzer cargo sudo-rs 0.2.14 system/interface/UnixUser#, Group: UnixGrouprust-analyzer cargo sudo-rs 0.2.14 system/interface/UnixGroup#> { |
| 65 | pub inspected_userrust-analyzer cargo sudo-rs 0.2.14 sudoers/ListRequest#inspected_user.: &'a User, |
| 66 | pub target_userrust-analyzer cargo sudo-rs 0.2.14 sudoers/ListRequest#target_user.: &'a User, |
| 67 | pub target_grouprust-analyzer cargo sudo-rs 0.2.14 sudoers/ListRequest#target_group.: &'a Group, |
| 68 | } |
| 69 | |
| 70 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default:)] |
| 71 | #[cfg_attr(test, derive(Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:))] |
| 72 | pub struct Judgementrust-analyzer cargo sudo-rs 0.2.14 sudoers/Judgement# { |
| 73 | flagsrust-analyzer cargo sudo-rs 0.2.14 sudoers/Judgement#flags.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Tagrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Tag#>, |
| 74 | settingsrust-analyzer cargo sudo-rs 0.2.14 sudoers/Judgement#settings.: Settingsrust-analyzer cargo sudo-rs 0.2.14 sudoers/Settings#, |
| 75 | } |
| 76 | |
| 77 | mod policyrust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/; |
| 78 | |
| 79 | pub use policyrust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/::{AuthenticatingUserrust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/AuthenticatingUser#, Authenticationrust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/Authentication#, Authorizationrust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/Authorization#, DirChangerust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/DirChange#, Restrictionsrust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/Restrictions#}; |
| 80 | |
| 81 | pub use selfrust-analyzer cargo sudo-rs 0.2.14 sudoers/::entryrust-analyzer cargo sudo-rs 0.2.14 sudoers/entry/::Entryrust-analyzer cargo sudo-rs 0.2.14 sudoers/entry/Entry#; |
| 82 | |
| 83 | type MatchedCommandrust-analyzer cargo sudo-rs 0.2.14 sudoers/MatchedCommand#<'a> = (Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&'a RunAsrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/RunAs#>, (Tagrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Tag#, &'a Specrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Spec#<Commandrust-analyzer cargo sudo-rs 0.2.14 sudoers/tokens/Command#>)); |
| 84 | |
| 85 | /// This function takes a file argument for a sudoers file and processes it. |
| 86 | impl Sudoersrust-analyzer cargo sudo-rs 0.2.14 sudoers/Sudoers# { |
| 87 | pub fn openrust-analyzer cargo sudo-rs 0.2.14 sudoers/impl#[Sudoers]open().(path: impl AsRefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#<Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#>) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(Sudoersrust-analyzer cargo sudo-rs 0.2.14 sudoers/Sudoers#, Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Errorrust-analyzer cargo sudo-rs 0.2.14 sudoers/Error#>), 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#> { |
| 88 | let sudoers = open_sudoersrust-analyzer cargo sudo-rs 0.2.14 sudoers/open_sudoers().(path.as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#as_ref().())?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 89 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(analyzerust-analyzer cargo sudo-rs 0.2.14 sudoers/analyze().(path.as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#as_ref().(), sudoers)) |
| 90 | } |
| 91 | |
| 92 | pub fn readrust-analyzer cargo sudo-rs 0.2.14 sudoers/impl#[Sudoers]read().<R: iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Readrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Read#, P: AsRefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#<Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#>>( |
| 93 | reader: R, |
| 94 | path: P, |
| 95 | ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(Sudoersrust-analyzer cargo sudo-rs 0.2.14 sudoers/Sudoers#, Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Errorrust-analyzer cargo sudo-rs 0.2.14 sudoers/Error#>), 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#> { |
| 96 | let sudoers = read_sudoersrust-analyzer cargo sudo-rs 0.2.14 sudoers/read_sudoers().(reader)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 97 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(analyzerust-analyzer cargo sudo-rs 0.2.14 sudoers/analyze().(path.as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#as_ref().(), sudoers)) |
| 98 | } |
| 99 | |
| 100 | fn specify_host_user_runasrust-analyzer cargo sudo-rs 0.2.14 sudoers/impl#[Sudoers]specify_host_user_runas().<User: UnixUserrust-analyzer cargo sudo-rs 0.2.14 system/interface/UnixUser# + PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#<User>>( |
| 101 | &mut self, |
| 102 | hostname: &systemrust-analyzer cargo sudo-rs 0.2.14 system/::Hostnamerust-analyzer cargo sudo-rs 0.2.14 system/Hostname#, |
| 103 | requesting_user: &User, |
| 104 | target_user: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&User>, |
| 105 | ) { |
| 106 | let customisers = stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::memrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/::takerust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/take().(&mut self.customisersrust-analyzer cargo sudo-rs 0.2.14 sudoers/Sudoers#customisers..non_cmndrust-analyzer cargo sudo-rs 0.2.14 sudoers/CustomiserTable#non_cmnd.); |
| 107 | |
| 108 | let host_matcher = &match_tokenrust-analyzer cargo sudo-rs 0.2.14 sudoers/match_token().(hostname); |
| 109 | let host_aliases = get_aliasesrust-analyzer cargo sudo-rs 0.2.14 sudoers/get_aliases().(&self.aliasesrust-analyzer cargo sudo-rs 0.2.14 sudoers/Sudoers#aliases..hostrust-analyzer cargo sudo-rs 0.2.14 sudoers/AliasTable#host., host_matcher); |
| 110 | |
| 111 | let user_matcher = &match_userrust-analyzer cargo sudo-rs 0.2.14 sudoers/match_user().(requesting_user); |
| 112 | let user_aliases = get_aliasesrust-analyzer cargo sudo-rs 0.2.14 sudoers/get_aliases().(&self.aliasesrust-analyzer cargo sudo-rs 0.2.14 sudoers/Sudoers#aliases..userrust-analyzer cargo sudo-rs 0.2.14 sudoers/AliasTable#user., user_matcher); |
| 113 | |
| 114 | let runas_matcher_aliases = target_user.maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(|target_user| { |
| 115 | let runas_matcher = match_userrust-analyzer cargo sudo-rs 0.2.14 sudoers/match_user().(target_user); |
| 116 | let runas_aliases = get_aliasesrust-analyzer cargo sudo-rs 0.2.14 sudoers/get_aliases().(&self.aliasesrust-analyzer cargo sudo-rs 0.2.14 sudoers/Sudoers#aliases..runasrust-analyzer cargo sudo-rs 0.2.14 sudoers/AliasTable#runas., &runas_matcher); |
| 117 | |
| 118 | (runas_matcher, runas_aliases) |
| 119 | }); |
| 120 | |
| 121 | let match_scope = |scope| match scope { |
| 122 | ConfigScoperust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/ConfigScope#::Genericrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/ConfigScope#Generic# => true, |
| 123 | ConfigScoperust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/ConfigScope#::Hostrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/ConfigScope#Host#(list) => find_itemrust-analyzer cargo sudo-rs 0.2.14 sudoers/find_item().(&list, host_matcher, &host_aliases).is_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some().(), |
| 124 | ConfigScoperust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/ConfigScope#::Userrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/ConfigScope#User#(list) => find_itemrust-analyzer cargo sudo-rs 0.2.14 sudoers/find_item().(&list, user_matcher, &user_aliases).is_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some().(), |
| 125 | ConfigScoperust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/ConfigScope#::RunAsrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/ConfigScope#RunAs#(list) => { |
| 126 | runas_matcher_aliases |
| 127 | .as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_ref().() |
| 128 | .is_some_andrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some_and().(|(runas_matcher, runas_aliases)| { |
| 129 | find_itemrust-analyzer cargo sudo-rs 0.2.14 sudoers/find_item().(&list, runas_matcher, runas_aliases).is_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some().() |
| 130 | }) |
| 131 | } |
| 132 | ConfigScoperust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/ConfigScope#::Commandrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/ConfigScope#Command#(_list) => { |
| 133 | unreachablerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/unreachable!!("command-specific defaults are filtered out") |
| 134 | } |
| 135 | }; |
| 136 | |
| 137 | for (scope, modifiers) in customisers { |
| 138 | if match_scope(scope) { |
| 139 | for modifier in modifiers { |
| 140 | modifier(&mut self.settingsrust-analyzer cargo sudo-rs 0.2.14 sudoers/Sudoers#settings.); |
| 141 | } |
| 142 | } |
| 143 | } |
| 144 | } |
| 145 | |
| 146 | fn specify_commandrust-analyzer cargo sudo-rs 0.2.14 sudoers/impl#[Sudoers]specify_command().(&mut self, command: &Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#, arguments: &[OsStringrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/OsString#]) { |
| 147 | let customisers = stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::memrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/::takerust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/take().(&mut self.customisersrust-analyzer cargo sudo-rs 0.2.14 sudoers/Sudoers#customisers..cmndrust-analyzer cargo sudo-rs 0.2.14 sudoers/CustomiserTable#cmnd.); |
| 148 | |
| 149 | let cmnd_matcher = &match_commandrust-analyzer cargo sudo-rs 0.2.14 sudoers/match_command().((command, arguments)); |
| 150 | let cmnd_aliases = get_aliasesrust-analyzer cargo sudo-rs 0.2.14 sudoers/get_aliases().(&self.aliasesrust-analyzer cargo sudo-rs 0.2.14 sudoers/Sudoers#aliases..cmndrust-analyzer cargo sudo-rs 0.2.14 sudoers/AliasTable#cmnd., cmnd_matcher); |
| 151 | |
| 152 | for (scope, modifiers) in customisers { |
| 153 | if find_itemrust-analyzer cargo sudo-rs 0.2.14 sudoers/find_item().(&scope, cmnd_matcher, &cmnd_aliases).is_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some().() { |
| 154 | for modifier in modifiers { |
| 155 | modifier(&mut self.settingsrust-analyzer cargo sudo-rs 0.2.14 sudoers/Sudoers#settings.); |
| 156 | } |
| 157 | } |
| 158 | } |
| 159 | } |
| 160 | |
| 161 | pub fn checkrust-analyzer cargo sudo-rs 0.2.14 sudoers/impl#[Sudoers]check().<User: UnixUserrust-analyzer cargo sudo-rs 0.2.14 system/interface/UnixUser# + PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#<User>, Group: UnixGrouprust-analyzer cargo sudo-rs 0.2.14 system/interface/UnixGroup#>( |
| 162 | &mut self, |
| 163 | am_user: &User, |
| 164 | on_host: &systemrust-analyzer cargo sudo-rs 0.2.14 system/::Hostnamerust-analyzer cargo sudo-rs 0.2.14 system/Hostname#, |
| 165 | request: Requestrust-analyzer cargo sudo-rs 0.2.14 sudoers/Request#<User, Group>, |
| 166 | ) -> Judgementrust-analyzer cargo sudo-rs 0.2.14 sudoers/Judgement# { |
| 167 | self.specify_host_user_runasrust-analyzer cargo sudo-rs 0.2.14 sudoers/impl#[Sudoers]specify_host_user_runas().(on_host, am_user, Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(request.userrust-analyzer cargo sudo-rs 0.2.14 sudoers/Request#user.)); |
| 168 | self.specify_commandrust-analyzer cargo sudo-rs 0.2.14 sudoers/impl#[Sudoers]specify_command().(request.commandrust-analyzer cargo sudo-rs 0.2.14 sudoers/Request#command., request.argumentsrust-analyzer cargo sudo-rs 0.2.14 sudoers/Request#arguments.); |
| 169 | |
| 170 | // exception: if user is root or does not switch users, NOPASSWD is implied |
| 171 | let skip_passwd = |
| 172 | am_user.is_rootrust-analyzer cargo sudo-rs 0.2.14 system/interface/UnixUser#is_root().() || (request.userrust-analyzer cargo sudo-rs 0.2.14 sudoers/Request#user. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq().am_user && in_grouprust-analyzer cargo sudo-rs 0.2.14 sudoers/in_group().(am_user, request.grouprust-analyzer cargo sudo-rs 0.2.14 sudoers/Request#group.)); |
| 173 | |
| 174 | let mut flags = check_permissionrust-analyzer cargo sudo-rs 0.2.14 sudoers/check_permission().(self, am_user, on_host, request); |
| 175 | if let 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# { authenticaterust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Tag#authenticate., .. }) = flags.as_mutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_mut().() { |
| 176 | if skip_passwd { |
| 177 | *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().authenticate = Authenticaterust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Authenticate#::Nopasswdrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Authenticate#Nopasswd#; |
| 178 | } |
| 179 | } |
| 180 | |
| 181 | Judgementrust-analyzer cargo sudo-rs 0.2.14 sudoers/Judgement# { |
| 182 | flagsrust-analyzer cargo sudo-rs 0.2.14 sudoers/Judgement#flags., |
| 183 | settingsrust-analyzer cargo sudo-rs 0.2.14 sudoers/Judgement#settings.: self.settingsrust-analyzer cargo sudo-rs 0.2.14 sudoers/Sudoers#settings..clonerust-analyzer cargo sudo-rs 0.2.14 defaults/impl#[Settings][Clone]clone().(), |
| 184 | } |
| 185 | } |
| 186 | |
| 187 | pub fn check_list_permissionrust-analyzer cargo sudo-rs 0.2.14 sudoers/impl#[Sudoers]check_list_permission().<User: UnixUserrust-analyzer cargo sudo-rs 0.2.14 system/interface/UnixUser# + PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#<User>, Group: UnixGrouprust-analyzer cargo sudo-rs 0.2.14 system/interface/UnixGroup#>( |
| 188 | &mut self, |
| 189 | invoking_user: &User, |
| 190 | hostname: &systemrust-analyzer cargo sudo-rs 0.2.14 system/::Hostnamerust-analyzer cargo sudo-rs 0.2.14 system/Hostname#, |
| 191 | request: ListRequestrust-analyzer cargo sudo-rs 0.2.14 sudoers/ListRequest#<User, Group>, |
| 192 | ) -> Authorizationrust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/Authorization# { |
| 193 | let skip_passwd; |
| 194 | let mut flags = if request.inspected_userrust-analyzer cargo sudo-rs 0.2.14 sudoers/ListRequest#inspected_user. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]ne().invoking_user { |
| 195 | skip_passwd = invoking_user.is_rootrust-analyzer cargo sudo-rs 0.2.14 system/interface/UnixUser#is_root().(); |
| 196 | |
| 197 | self.checkrust-analyzer cargo sudo-rs 0.2.14 sudoers/impl#[Sudoers]check().( |
| 198 | invoking_user, |
| 199 | hostname, |
| 200 | Requestrust-analyzer cargo sudo-rs 0.2.14 sudoers/Request# { |
| 201 | userrust-analyzer cargo sudo-rs 0.2.14 sudoers/Request#user.: request.inspected_userrust-analyzer cargo sudo-rs 0.2.14 sudoers/ListRequest#inspected_user., |
| 202 | grouprust-analyzer cargo sudo-rs 0.2.14 sudoers/Request#group.: &request.inspected_userrust-analyzer cargo sudo-rs 0.2.14 sudoers/ListRequest#inspected_user..grouprust-analyzer cargo sudo-rs 0.2.14 system/interface/UnixUser#group().(), |
| 203 | commandrust-analyzer cargo sudo-rs 0.2.14 sudoers/Request#command.: 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().("list"), |
| 204 | argumentsrust-analyzer cargo sudo-rs 0.2.14 sudoers/Request#arguments.: &[], |
| 205 | }, |
| 206 | ) |
| 207 | .flagsrust-analyzer cargo sudo-rs 0.2.14 sudoers/Judgement#flags. |
| 208 | .orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]or().(invoking_user.is_rootrust-analyzer cargo sudo-rs 0.2.14 system/interface/UnixUser#is_root().().thenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core bool/impl#[bool]then().(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().)) |
| 209 | } else { |
| 210 | skip_passwd = invoking_user.is_rootrust-analyzer cargo sudo-rs 0.2.14 system/interface/UnixUser#is_root().() |
| 211 | || (request.target_userrust-analyzer cargo sudo-rs 0.2.14 sudoers/ListRequest#target_user. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq().invoking_user |
| 212 | && in_grouprust-analyzer cargo sudo-rs 0.2.14 sudoers/in_group().(invoking_user, request.target_grouprust-analyzer cargo sudo-rs 0.2.14 sudoers/ListRequest#target_group.)); |
| 213 | |
| 214 | self.matching_user_specsrust-analyzer cargo sudo-rs 0.2.14 sudoers/impl#[Sudoers]matching_user_specs().(invoking_user, hostname) |
| 215 | .flattenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#flatten().() |
| 216 | .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|(_, (tag, _))| tag) |
| 217 | .max_by_keyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#max_by_key().(|tag| !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().tag.needs_passwdrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/impl#[Tag]needs_passwd().()) |
| 218 | }; |
| 219 | |
| 220 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(tag) = flags.as_mutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_mut().() { |
| 221 | if skip_passwd { |
| 222 | 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#; |
| 223 | } |
| 224 | |
| 225 | Authorizationrust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/Authorization#::Allowedrust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/Authorization#Allowed#(self.settingsrust-analyzer cargo sudo-rs 0.2.14 sudoers/Sudoers#settings..to_authrust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/impl#[`crate::defaults::Settings`]to_auth().(tag), ()) |
| 226 | } else { |
| 227 | Authorizationrust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/Authorization#::Forbiddenrust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/Authorization#Forbidden# |
| 228 | } |
| 229 | } |
| 230 | |
| 231 | pub fn check_validate_permissionrust-analyzer cargo sudo-rs 0.2.14 sudoers/impl#[Sudoers]check_validate_permission().<User: UnixUserrust-analyzer cargo sudo-rs 0.2.14 system/interface/UnixUser# + PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#<User>>( |
| 232 | &mut self, |
| 233 | invoking_user: &User, |
| 234 | hostname: &systemrust-analyzer cargo sudo-rs 0.2.14 system/::Hostnamerust-analyzer cargo sudo-rs 0.2.14 system/Hostname#, |
| 235 | ) -> Authorizationrust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/Authorization# { |
| 236 | self.specify_host_user_runasrust-analyzer cargo sudo-rs 0.2.14 sudoers/impl#[Sudoers]specify_host_user_runas().(hostname, invoking_user, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#); |
| 237 | |
| 238 | // exception: if user is root, NOPASSWD is implied |
| 239 | let skip_passwd = invoking_user.is_rootrust-analyzer cargo sudo-rs 0.2.14 system/interface/UnixUser#is_root().(); |
| 240 | |
| 241 | let mut flags = self |
| 242 | .matching_user_specsrust-analyzer cargo sudo-rs 0.2.14 sudoers/impl#[Sudoers]matching_user_specs().(invoking_user, hostname) |
| 243 | .flattenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#flatten().() |
| 244 | .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|(_, (tag, _))| tag) |
| 245 | .max_by_keyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#max_by_key().(|tag| tag.needs_passwdrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/impl#[Tag]needs_passwd().()); |
| 246 | |
| 247 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(tag) = flags.as_mutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_mut().() { |
| 248 | if skip_passwd { |
| 249 | 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#; |
| 250 | } |
| 251 | |
| 252 | Authorizationrust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/Authorization#::Allowedrust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/Authorization#Allowed#(self.settingsrust-analyzer cargo sudo-rs 0.2.14 sudoers/Sudoers#settings..to_authrust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/impl#[`crate::defaults::Settings`]to_auth().(tag), ()) |
| 253 | } else { |
| 254 | Authorizationrust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/Authorization#::Forbiddenrust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/Authorization#Forbidden# |
| 255 | } |
| 256 | } |
| 257 | |
| 258 | /// returns `User_Spec`s that match `invoking_user` and `hostname` |
| 259 | /// |
| 260 | /// it also distributes `Tag_Spec`s across the `Cmnd_Spec` list of each `User_Spec` |
| 261 | /// |
| 262 | /// the outer iterator are the `User_Spec`s; the inner iterator are the `Cmnd_Spec`s of |
| 263 | /// said `User_Spec`s |
| 264 | fn matching_user_specsrust-analyzer cargo sudo-rs 0.2.14 sudoers/impl#[Sudoers]matching_user_specs().<'a, User: UnixUserrust-analyzer cargo sudo-rs 0.2.14 system/interface/UnixUser# + PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#<User>>( |
| 265 | &'a self, |
| 266 | invoking_user: &'a User, |
| 267 | hostname: &'a systemrust-analyzer cargo sudo-rs 0.2.14 system/::Hostnamerust-analyzer cargo sudo-rs 0.2.14 system/Hostname#, |
| 268 | ) -> impl Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#<Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item# = impl Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#<Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item# = MatchedCommandrust-analyzer cargo sudo-rs 0.2.14 sudoers/MatchedCommand#<'a>>> { |
| 269 | let Selfrust-analyzer cargo sudo-rs 0.2.14 sudoers/impl#[Sudoers] { rulesrust-analyzer cargo sudo-rs 0.2.14 sudoers/Sudoers#rules., aliasesrust-analyzer cargo sudo-rs 0.2.14 sudoers/Sudoers#aliases., .. } = self; |
| 270 | let user_aliases = get_aliasesrust-analyzer cargo sudo-rs 0.2.14 sudoers/get_aliases().(&aliases.userrust-analyzer cargo sudo-rs 0.2.14 sudoers/AliasTable#user., &match_userrust-analyzer cargo sudo-rs 0.2.14 sudoers/match_user().(invoking_user)); |
| 271 | let host_aliases = get_aliasesrust-analyzer cargo sudo-rs 0.2.14 sudoers/get_aliases().(&aliases.hostrust-analyzer cargo sudo-rs 0.2.14 sudoers/AliasTable#host., &match_tokenrust-analyzer cargo sudo-rs 0.2.14 sudoers/match_token().(hostname)); |
| 272 | |
| 273 | rules |
| 274 | .iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().() |
| 275 | .filter_maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#filter_map().(move |sudo| { |
| 276 | find_itemrust-analyzer cargo sudo-rs 0.2.14 sudoers/find_item().(&sudo.usersrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/PermissionSpec#users., &match_userrust-analyzer cargo sudo-rs 0.2.14 sudoers/match_user().(invoking_user), &user_aliases)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][Try]branch().; |
| 277 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(&sudo.permissionsrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/PermissionSpec#permissions.) |
| 278 | }) |
| 279 | .flattenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#flatten().() |
| 280 | .filter_maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#filter_map().(move |(hosts, runas_cmds)| { |
| 281 | find_itemrust-analyzer cargo sudo-rs 0.2.14 sudoers/find_item().(hosts, &match_tokenrust-analyzer cargo sudo-rs 0.2.14 sudoers/match_token().(hostname), &host_aliases)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][Try]branch().; |
| 282 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(distribute_tagsrust-analyzer cargo sudo-rs 0.2.14 sudoers/distribute_tags().(runas_cmds)) |
| 283 | }) |
| 284 | } |
| 285 | |
| 286 | pub fn matching_entriesrust-analyzer cargo sudo-rs 0.2.14 sudoers/impl#[Sudoers]matching_entries().<'a, User: UnixUserrust-analyzer cargo sudo-rs 0.2.14 system/interface/UnixUser# + PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#<User>>( |
| 287 | &'a self, |
| 288 | invoking_user: &'a User, |
| 289 | hostname: &'a systemrust-analyzer cargo sudo-rs 0.2.14 system/::Hostnamerust-analyzer cargo sudo-rs 0.2.14 system/Hostname#, |
| 290 | ) -> impl Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#<Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item# = Entryrust-analyzer cargo sudo-rs 0.2.14 sudoers/entry/Entry#<'a>> { |
| 291 | let user_specs = self.matching_user_specsrust-analyzer cargo sudo-rs 0.2.14 sudoers/impl#[Sudoers]matching_user_specs().(invoking_user, hostname); |
| 292 | |
| 293 | user_specs.flat_maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#flat_map().(|cmd_specs| group_cmd_specs_per_runasrust-analyzer cargo sudo-rs 0.2.14 sudoers/group_cmd_specs_per_runas().(cmd_specs, &self.aliasesrust-analyzer cargo sudo-rs 0.2.14 sudoers/Sudoers#aliases..cmndrust-analyzer cargo sudo-rs 0.2.14 sudoers/AliasTable#cmnd.)) |
| 294 | } |
| 295 | |
| 296 | pub(craterust-analyzer cargo sudo-rs 0.2.14 crate/) fn visudo_editor_pathrust-analyzer cargo sudo-rs 0.2.14 sudoers/impl#[Sudoers]visudo_editor_path().<User: UnixUserrust-analyzer cargo sudo-rs 0.2.14 system/interface/UnixUser# + PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#<User>>( |
| 297 | mut self, |
| 298 | on_host: &systemrust-analyzer cargo sudo-rs 0.2.14 system/::Hostnamerust-analyzer cargo sudo-rs 0.2.14 system/Hostname#, |
| 299 | am_user: &User, |
| 300 | target_user: &User, |
| 301 | ) -> 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#, 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#>)> { |
| 302 | self.specify_host_user_runasrust-analyzer cargo sudo-rs 0.2.14 sudoers/impl#[Sudoers]specify_host_user_runas().(on_host, am_user, Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(target_user)); |
| 303 | |
| 304 | select_editorrust-analyzer cargo sudo-rs 0.2.14 sudoers/select_editor().(&self.settingsrust-analyzer cargo sudo-rs 0.2.14 sudoers/Sudoers#settings., self.settingsrust-analyzer cargo sudo-rs 0.2.14 sudoers/Sudoers#settings..env_editorrust-analyzer cargo sudo-rs 0.2.14 defaults/impl#[Settings]env_editor().()) |
| 305 | } |
| 306 | } |
| 307 | |
| 308 | /// Retrieve the chosen editor from a settings object, filtering based on whether the |
| 309 | /// environment is trusted (sudoedit) or maybe less so (visudo) |
| 310 | fn select_editorrust-analyzer cargo sudo-rs 0.2.14 sudoers/select_editor().(settings: &Settingsrust-analyzer cargo sudo-rs 0.2.14 sudoers/Settings#, trusted_env: bool) -> 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#, 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#>)> { |
| 311 | let blessed_editors = settings.editorrust-analyzer cargo sudo-rs 0.2.14 defaults/impl#[Settings]editor().(); |
| 312 | |
| 313 | let is_whitelisted = |path: &Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#| -> bool { |
| 314 | trusted_env || blessed_editors.splitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]split().(':').anyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#any().(|x| 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().(x) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq().path) |
| 315 | }; |
| 316 | |
| 317 | // find editor in environment, if possible |
| 318 | |
| 319 | for key in ["SUDO_EDITOR", "VISUAL", "EDITOR"] { |
| 320 | if let Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(editor_env) = 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/::varrust-analyzer cargo std https://github.com/rust-lang/rust/library/std env/var().(key) { |
| 321 | let mut arguments = editor_env.splitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]split().(' '); |
| 322 | |
| 323 | let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(editor) = arguments.nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/iter/impl#[`Split<'a, P>`][Iterator]next().().maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(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().) else { |
| 324 | continue; |
| 325 | }; |
| 326 | let arguments = arguments.maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(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().).collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 327 | |
| 328 | let editor = if is_valid_executablerust-analyzer cargo sudo-rs 0.2.14 common/resolve/is_valid_executable().(&editor) { |
| 329 | editor |
| 330 | } else if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(editor) = resolve_pathrust-analyzer cargo sudo-rs 0.2.14 common/resolve/resolve_path().( |
| 331 | &editor, |
| 332 | &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/::varrust-analyzer cargo std https://github.com/rust-lang/rust/library/std env/var().("PATH").unwrap_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap_or().(craterust-analyzer cargo sudo-rs 0.2.14 crate/::sudorust-analyzer cargo sudo-rs 0.2.14 sudo/::PATH_DEFAULTrust-analyzer cargo sudo-rs 0.2.14 sudo/env/environment/PATH_DEFAULT..to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()), |
| 333 | ) { |
| 334 | editor |
| 335 | } else { |
| 336 | continue; |
| 337 | }; |
| 338 | |
| 339 | if is_whitelisted(&editor) { |
| 340 | return Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((editor, arguments)); |
| 341 | } |
| 342 | } |
| 343 | } |
| 344 | |
| 345 | // no acceptable editor found in environment, fallback on config |
| 346 | |
| 347 | for editor in blessed_editors.splitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]split().(':') { |
| 348 | let editor = 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().(editor); |
| 349 | if is_valid_executablerust-analyzer cargo sudo-rs 0.2.14 common/resolve/is_valid_executable().(&editor) { |
| 350 | return Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((editor, vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![])); |
| 351 | } |
| 352 | } |
| 353 | |
| 354 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# |
| 355 | } |
| 356 | |
| 357 | // a `take_while` variant that does not consume the first non-matching item |
| 358 | fn peeking_take_whilerust-analyzer cargo sudo-rs 0.2.14 sudoers/peeking_take_while().<'a, T>( |
| 359 | iter: &'a mut stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/::Peekablerust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/peekable/Peekable#<impl Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#<Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item# = T>>, |
| 360 | pred: impl Fnrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/Fn#(&T) -> bool + 'a, |
| 361 | ) -> impl Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#<Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item# = T> + 'a { |
| 362 | stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/::from_fnrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/sources/from_fn/from_fn().(move || iter.next_ifrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/peekable/impl#[`Peekable<I>`]next_if().(&pred)) |
| 363 | } |
| 364 | |
| 365 | fn group_cmd_specs_per_runasrust-analyzer cargo sudo-rs 0.2.14 sudoers/group_cmd_specs_per_runas().<'a>( |
| 366 | cmnd_specs: impl Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#<Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item# = (Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&'a RunAsrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/RunAs#>, (Tagrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Tag#, &'a Specrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Spec#<Commandrust-analyzer cargo sudo-rs 0.2.14 sudoers/tokens/Command#>))>, |
| 367 | cmnd_aliases: &'a VecOrdrust-analyzer cargo sudo-rs 0.2.14 sudoers/VecOrd#<Defrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Def#<Commandrust-analyzer cargo sudo-rs 0.2.14 sudoers/tokens/Command#>>, |
| 368 | ) -> impl Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#<Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item# = Entryrust-analyzer cargo sudo-rs 0.2.14 sudoers/entry/Entry#<'a>> { |
| 369 | // `distribute_tags` will have given every spec a reference to the "runas specification" |
| 370 | // that applies to it. The output of sudo --list splits the CmndSpec list based on that: |
| 371 | // every line only has a single "runas" specifier. So we need to combine them for that. |
| 372 | // |
| 373 | // But sudo --list also outputs lines that are from different lines in the sudoers file on |
| 374 | // different lines in the output of sudo --list, so we cannot compare "by value". Luckily, |
| 375 | // once a RunAs is parsed, it will have a unique identifier in the form of its address. |
| 376 | let origin = |runas: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&RunAsrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/RunAs#>| runas.maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(|r| r as *const _); |
| 377 | |
| 378 | let mut cmnd_specs = cmnd_specs.peekablerust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#peekable().(); |
| 379 | |
| 380 | stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/::from_fnrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/sources/from_fn/from_fn().(move || { |
| 381 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(&(cur_runas, _)) = cmnd_specs.peekrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/peekable/impl#[`Peekable<I>`]peek().() { |
| 382 | let specs = peeking_take_whilerust-analyzer cargo sudo-rs 0.2.14 sudoers/peeking_take_while().(&mut cmnd_specs, |&(runas, _)| { |
| 383 | origin(runas) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq().origin(cur_runas) |
| 384 | }); |
| 385 | |
| 386 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Entryrust-analyzer cargo sudo-rs 0.2.14 sudoers/entry/Entry#::newrust-analyzer cargo sudo-rs 0.2.14 sudoers/entry/impl#[`Entry<'a>`]new().( |
| 387 | cur_runas, |
| 388 | specs.maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|x| x.1).collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(), |
| 389 | cmnd_aliases, |
| 390 | )) |
| 391 | } else { |
| 392 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# |
| 393 | } |
| 394 | }) |
| 395 | } |
| 396 | |
| 397 | fn read_sudoersrust-analyzer cargo sudo-rs 0.2.14 sudoers/read_sudoers().<R: iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Readrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Read#>(mut reader: R) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<basic_parserrust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/::Parsedrust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/Parsed#<Sudorust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Sudo#>>> { |
| 398 | // it's a bit frustrating that BufReader.chars() does not exist |
| 399 | let mut buffer = Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]new().(); |
| 400 | reader.read_to_stringrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Read#read_to_string().(&mut buffer)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 401 | |
| 402 | use basic_parserrust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/::parse_linesrust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/parse_lines().; |
| 403 | use char_streamrust-analyzer cargo sudo-rs 0.2.14 sudoers/char_stream/::*; |
| 404 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(parse_linesrust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/parse_lines().(&mut CharStreamrust-analyzer cargo sudo-rs 0.2.14 sudoers/char_stream/CharStream#::newrust-analyzer cargo sudo-rs 0.2.14 sudoers/char_stream/impl#[`CharStream<'a>`]new().(&buffer))) |
| 405 | } |
| 406 | |
| 407 | fn open_sudoersrust-analyzer cargo sudo-rs 0.2.14 sudoers/open_sudoers().(path: &Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<basic_parserrust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/::Parsedrust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/Parsed#<Sudorust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Sudo#>>> { |
| 408 | let source = auditrust-analyzer cargo sudo-rs 0.2.14 system/audit/::secure_open_sudoersrust-analyzer cargo sudo-rs 0.2.14 system/audit/secure_open_sudoers().(path)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 409 | read_sudoersrust-analyzer cargo sudo-rs 0.2.14 sudoers/read_sudoers().(source) |
| 410 | } |
| 411 | |
| 412 | #[cfg(feature = "unstable-remote-sudoers")] |
| 413 | fn open_remote_sudoers(path: &Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<basic_parserrust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/::Parsedrust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/Parsed#<Sudorust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Sudo#>>> { |
| 414 | let source = auditrust-analyzer cargo sudo-rs 0.2.14 system/audit/::secure_open_remote_sudoers(path)?; |
| 415 | read_sudoersrust-analyzer cargo sudo-rs 0.2.14 sudoers/read_sudoers().(source) |
| 416 | } |
| 417 | |
| 418 | // note: trying to DRY using GAT's is tempting but doesn't make the code any shorter |
| 419 | |
| 420 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default:)] |
| 421 | struct AliasTablerust-analyzer cargo sudo-rs 0.2.14 sudoers/AliasTable# { |
| 422 | userrust-analyzer cargo sudo-rs 0.2.14 sudoers/AliasTable#user.: VecOrdrust-analyzer cargo sudo-rs 0.2.14 sudoers/VecOrd#<Defrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Def#<UserSpecifierrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/UserSpecifier#>>, |
| 423 | hostrust-analyzer cargo sudo-rs 0.2.14 sudoers/AliasTable#host.: VecOrdrust-analyzer cargo sudo-rs 0.2.14 sudoers/VecOrd#<Defrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Def#<Hostnamerust-analyzer cargo sudo-rs 0.2.14 sudoers/tokens/Hostname#>>, |
| 424 | cmndrust-analyzer cargo sudo-rs 0.2.14 sudoers/AliasTable#cmnd.: VecOrdrust-analyzer cargo sudo-rs 0.2.14 sudoers/VecOrd#<Defrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Def#<Commandrust-analyzer cargo sudo-rs 0.2.14 sudoers/tokens/Command#>>, |
| 425 | runasrust-analyzer cargo sudo-rs 0.2.14 sudoers/AliasTable#runas.: VecOrdrust-analyzer cargo sudo-rs 0.2.14 sudoers/VecOrd#<Defrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Def#<UserSpecifierrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/UserSpecifier#>>, |
| 426 | } |
| 427 | |
| 428 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default:)] |
| 429 | struct CustomiserTablerust-analyzer cargo sudo-rs 0.2.14 sudoers/CustomiserTable# { |
| 430 | non_cmndrust-analyzer cargo sudo-rs 0.2.14 sudoers/CustomiserTable#non_cmnd.: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Customiserrust-analyzer cargo sudo-rs 0.2.14 sudoers/Customiser#<ConfigScoperust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/ConfigScope#>>, |
| 431 | cmndrust-analyzer cargo sudo-rs 0.2.14 sudoers/CustomiserTable#cmnd.: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Customiserrust-analyzer cargo sudo-rs 0.2.14 sudoers/Customiser#<SpecListrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/SpecList#<Commandrust-analyzer cargo sudo-rs 0.2.14 sudoers/tokens/Command#>>>, |
| 432 | } |
| 433 | |
| 434 | /// A vector with a list defining the order in which it needs to be processed |
| 435 | struct VecOrdrust-analyzer cargo sudo-rs 0.2.14 sudoers/VecOrd#<T>(Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<usize>, Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<T>); |
| 436 | |
| 437 | impl<T> Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default# for VecOrdrust-analyzer cargo sudo-rs 0.2.14 sudoers/VecOrd#<T> { |
| 438 | fn defaultrust-analyzer cargo sudo-rs 0.2.14 sudoers/impl#[`VecOrd<T>`][Default]default().() -> Selfrust-analyzer cargo sudo-rs 0.2.14 sudoers/impl#[`VecOrd<T>`][Default] { |
| 439 | VecOrdrust-analyzer cargo sudo-rs 0.2.14 sudoers/VecOrd#(Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::defaultrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`][Default]default().(), Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::defaultrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`][Default]default().()) |
| 440 | } |
| 441 | } |
| 442 | |
| 443 | impl<T> VecOrdrust-analyzer cargo sudo-rs 0.2.14 sudoers/VecOrd#<T> { |
| 444 | fn iterrust-analyzer cargo sudo-rs 0.2.14 sudoers/impl#[`VecOrd<T>`]iter().(&self) -> impl DoubleEndedIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/double_ended/DoubleEndedIterator#<Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item# = &T> + Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone# { |
| 445 | self.0rust-analyzer cargo sudo-rs 0.2.14 sudoers/VecOrd#0..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().(|&i| &self.1rust-analyzer cargo sudo-rs 0.2.14 sudoers/VecOrd#1.[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().i]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().) |
| 446 | } |
| 447 | } |
| 448 | |
| 449 | /// Check if the user `am_user` is allowed to run `cmdline` on machine `on_host` as the requested |
| 450 | /// user/group. Not that in the sudoers file, later permissions override earlier restrictions. |
| 451 | /// The `cmdline` argument should already be ready to essentially feed to an exec() call; or be |
| 452 | /// a special command like 'sudoedit'. |
| 453 | // This code is structure to allow easily reading the 'happy path'; i.e. as soon as something |
| 454 | // doesn't match, we escape using the '?' mechanism. |
| 455 | fn check_permissionrust-analyzer cargo sudo-rs 0.2.14 sudoers/check_permission().<User: UnixUserrust-analyzer cargo sudo-rs 0.2.14 system/interface/UnixUser# + PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#<User>, Group: UnixGrouprust-analyzer cargo sudo-rs 0.2.14 system/interface/UnixGroup#>( |
| 456 | sudoers: &Sudoersrust-analyzer cargo sudo-rs 0.2.14 sudoers/Sudoers#, |
| 457 | am_user: &User, |
| 458 | on_host: &systemrust-analyzer cargo sudo-rs 0.2.14 system/::Hostnamerust-analyzer cargo sudo-rs 0.2.14 system/Hostname#, |
| 459 | request: Requestrust-analyzer cargo sudo-rs 0.2.14 sudoers/Request#<User, Group>, |
| 460 | ) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Tagrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Tag#> { |
| 461 | let cmdline = (request.commandrust-analyzer cargo sudo-rs 0.2.14 sudoers/Request#command., request.argumentsrust-analyzer cargo sudo-rs 0.2.14 sudoers/Request#arguments.); |
| 462 | |
| 463 | let aliases = &sudoers.aliasesrust-analyzer cargo sudo-rs 0.2.14 sudoers/Sudoers#aliases.; |
| 464 | let cmnd_aliases = get_aliasesrust-analyzer cargo sudo-rs 0.2.14 sudoers/get_aliases().(&aliases.cmndrust-analyzer cargo sudo-rs 0.2.14 sudoers/AliasTable#cmnd., &match_commandrust-analyzer cargo sudo-rs 0.2.14 sudoers/match_command().(cmdline)); |
| 465 | let runas_user_aliases = get_aliasesrust-analyzer cargo sudo-rs 0.2.14 sudoers/get_aliases().(&aliases.runasrust-analyzer cargo sudo-rs 0.2.14 sudoers/AliasTable#runas., &match_userrust-analyzer cargo sudo-rs 0.2.14 sudoers/match_user().(request.userrust-analyzer cargo sudo-rs 0.2.14 sudoers/Request#user.)); |
| 466 | let runas_group_aliases = get_aliasesrust-analyzer cargo sudo-rs 0.2.14 sudoers/get_aliases().(&aliases.runasrust-analyzer cargo sudo-rs 0.2.14 sudoers/AliasTable#runas., &match_group_aliasrust-analyzer cargo sudo-rs 0.2.14 sudoers/match_group_alias().(request.grouprust-analyzer cargo sudo-rs 0.2.14 sudoers/Request#group.)); |
| 467 | |
| 468 | let matching_user_specs = sudoers.matching_user_specsrust-analyzer cargo sudo-rs 0.2.14 sudoers/impl#[Sudoers]matching_user_specs().(am_user, on_host).flattenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#flatten().(); |
| 469 | |
| 470 | let allowed_commands = matching_user_specs.filter_maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#filter_map().(|(runas, cmdspec)| { |
| 471 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(RunAsrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/RunAs# { usersrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/RunAs#users., groupsrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/RunAs#groups. }) = runas { |
| 472 | let stays_in_group = in_grouprust-analyzer cargo sudo-rs 0.2.14 sudoers/in_group().(request.userrust-analyzer cargo sudo-rs 0.2.14 sudoers/Request#user., request.grouprust-analyzer cargo sudo-rs 0.2.14 sudoers/Request#group.); |
| 473 | if request.userrust-analyzer cargo sudo-rs 0.2.14 sudoers/Request#user. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]ne().am_user || (stays_in_group && !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().users.is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]is_empty().()) { |
| 474 | find_itemrust-analyzer cargo sudo-rs 0.2.14 sudoers/find_item().(users, &match_userrust-analyzer cargo sudo-rs 0.2.14 sudoers/match_user().(request.userrust-analyzer cargo sudo-rs 0.2.14 sudoers/Request#user.), &runas_user_aliases)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][Try]branch(). |
| 475 | } |
| 476 | if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().stays_in_group { |
| 477 | find_itemrust-analyzer cargo sudo-rs 0.2.14 sudoers/find_item().(groups, &match_grouprust-analyzer cargo sudo-rs 0.2.14 sudoers/match_group().(request.grouprust-analyzer cargo sudo-rs 0.2.14 sudoers/Request#group.), &runas_group_aliases)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][Try]branch(). |
| 478 | } |
| 479 | } else if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().(request.userrust-analyzer cargo sudo-rs 0.2.14 sudoers/Request#user..is_rootrust-analyzer cargo sudo-rs 0.2.14 system/interface/UnixUser#is_root().() && in_grouprust-analyzer cargo sudo-rs 0.2.14 sudoers/in_group().(request.userrust-analyzer cargo sudo-rs 0.2.14 sudoers/Request#user., request.grouprust-analyzer cargo sudo-rs 0.2.14 sudoers/Request#group.)) { |
| 480 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][Try]branch().; |
| 481 | } |
| 482 | |
| 483 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(cmdspec) |
| 484 | }); |
| 485 | |
| 486 | find_itemrust-analyzer cargo sudo-rs 0.2.14 sudoers/find_item().(allowed_commands, &match_commandrust-analyzer cargo sudo-rs 0.2.14 sudoers/match_command().(cmdline), &cmnd_aliases) |
| 487 | } |
| 488 | |
| 489 | /// Process a raw parsed AST bit of RunAs + Command specifications: |
| 490 | /// - RunAs specifications distribute over the commands that follow (until overridden) |
| 491 | /// - Tags accumulate over the entire line |
| 492 | fn distribute_tagsrust-analyzer cargo sudo-rs 0.2.14 sudoers/distribute_tags().( |
| 493 | runas_cmds: &[(Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<RunAsrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/RunAs#>, CommandSpecrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/CommandSpec#)], |
| 494 | ) -> impl Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#<Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item# = (Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&RunAsrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/RunAs#>, (Tagrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Tag#, &Specrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Spec#<Commandrust-analyzer cargo sudo-rs 0.2.14 sudoers/tokens/Command#>))> { |
| 495 | runas_cmds.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().scanrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#scan().( |
| 496 | (Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default#::defaultrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/impl#[Tag][Default]default().()), |
| 497 | |(last_runas, tag), (runas, CommandSpecrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/CommandSpec#(mods, cmd))| { |
| 498 | *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().last_runas = runas.as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_ref().().orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]or().(*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().last_runas); |
| 499 | for f in mods { |
| 500 | f(tag); |
| 501 | } |
| 502 | |
| 503 | let this_tag = match cmd { |
| 504 | Qualifiedrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Qualified#::Allowrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Qualified#Allow#(Metarust-analyzer cargo sudo-rs 0.2.14 sudoers/tokens/Meta#::Allrust-analyzer cargo sudo-rs 0.2.14 sudoers/tokens/Meta#All#) if tag.envrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Tag#env. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#ne().EnvironmentControlrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/EnvironmentControl#::Nosetenvrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/EnvironmentControl#Nosetenv# => Tagrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Tag# { |
| 505 | // "ALL" has an implicit "SETENV" that doesn't distribute |
| 506 | envrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Tag#env.: EnvironmentControlrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/EnvironmentControl#::Setenvrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/EnvironmentControl#Setenv#, |
| 507 | ..tag.clonerust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/impl#[Tag][Clone]clone().() |
| 508 | }, |
| 509 | _ => tag.clonerust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/impl#[Tag][Clone]clone().(), |
| 510 | }; |
| 511 | |
| 512 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().last_runas, (this_tag, cmd))) |
| 513 | }, |
| 514 | ) |
| 515 | } |
| 516 | |
| 517 | /// A type to represent positive or negative association with an alias; i.e. if a key maps to true, |
| 518 | /// the alias affirms membership, if a key maps to false, the alias denies membership; if a key |
| 519 | /// isn't present membership is affirmed nor denied |
| 520 | type FoundAliasesrust-analyzer cargo sudo-rs 0.2.14 sudoers/FoundAliases# = HashMaprust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/HashMap#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, bool>; |
| 521 | |
| 522 | /// Find an item matching a certain predicate in an collection (optionally attributed) list of |
| 523 | /// identifiers; identifiers can be directly identifying, wildcards, and can either be positive or |
| 524 | /// negative (i.e. preceeded by an even number of exclamation marks in the sudoers file) |
| 525 | fn find_itemrust-analyzer cargo sudo-rs 0.2.14 sudoers/find_item().<'a, Predicate, Iter, T: 'a>( |
| 526 | items: Iter, |
| 527 | matches: &Predicate, |
| 528 | aliases: &FoundAliasesrust-analyzer cargo sudo-rs 0.2.14 sudoers/FoundAliases#, |
| 529 | ) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<<Iter::Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#Item# as WithInforust-analyzer cargo sudo-rs 0.2.14 sudoers/WithInfo#>::Inforust-analyzer cargo sudo-rs 0.2.14 sudoers/WithInfo#Info#> |
| 530 | where |
| 531 | Predicate: Fnrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/Fn#(&T) -> bool, |
| 532 | Iter: IntoIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#, |
| 533 | Iter::Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#Item#: WithInforust-analyzer cargo sudo-rs 0.2.14 sudoers/WithInfo#<Itemrust-analyzer cargo sudo-rs 0.2.14 sudoers/WithInfo#Item# = &'a Specrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Spec#<T>>, |
| 534 | { |
| 535 | let mut result = Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#; |
| 536 | for item in items { |
| 537 | let (judgement, who) = match item.as_innerrust-analyzer cargo sudo-rs 0.2.14 sudoers/WithInfo#as_inner().() { |
| 538 | Qualifiedrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Qualified#::Forbidrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Qualified#Forbid#(x) => (false, x), |
| 539 | Qualifiedrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Qualified#::Allowrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Qualified#Allow#(x) => (true, x), |
| 540 | }; |
| 541 | let info = || item.into_inforust-analyzer cargo sudo-rs 0.2.14 sudoers/WithInfo#into_info().(); |
| 542 | match who { |
| 543 | Metarust-analyzer cargo sudo-rs 0.2.14 sudoers/tokens/Meta#::Allrust-analyzer cargo sudo-rs 0.2.14 sudoers/tokens/Meta#All# => result = judgement.thenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core bool/impl#[bool]then().(info), |
| 544 | Metarust-analyzer cargo sudo-rs 0.2.14 sudoers/tokens/Meta#::Onlyrust-analyzer cargo sudo-rs 0.2.14 sudoers/tokens/Meta#Only#(ident) if matches(ident) => result = judgement.thenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core bool/impl#[bool]then().(info), |
| 545 | Metarust-analyzer cargo sudo-rs 0.2.14 sudoers/tokens/Meta#::Aliasrust-analyzer cargo sudo-rs 0.2.14 sudoers/tokens/Meta#Alias#(id) if aliases.contains_keyrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]contains_key().(id) => { |
| 546 | result = if aliases[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().id]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index(). { |
| 547 | judgement.thenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core bool/impl#[bool]then().(info) |
| 548 | } else { |
| 549 | // in this case, an explicit negation in the alias applies |
| 550 | (!rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().judgement).thenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core bool/impl#[bool]then().(info) |
| 551 | } |
| 552 | } |
| 553 | _ => {} |
| 554 | }; |
| 555 | } |
| 556 | |
| 557 | result |
| 558 | } |
| 559 | |
| 560 | /// A interface to access optional "satellite data" |
| 561 | trait WithInforust-analyzer cargo sudo-rs 0.2.14 sudoers/WithInfo# { |
| 562 | type Itemrust-analyzer cargo sudo-rs 0.2.14 sudoers/WithInfo#Item#; |
| 563 | type Inforust-analyzer cargo sudo-rs 0.2.14 sudoers/WithInfo#Info#; |
| 564 | fn as_innerrust-analyzer cargo sudo-rs 0.2.14 sudoers/WithInfo#as_inner().(&self) -> Self::Itemrust-analyzer cargo sudo-rs 0.2.14 sudoers/WithInfo#Item#; |
| 565 | fn into_inforust-analyzer cargo sudo-rs 0.2.14 sudoers/WithInfo#into_info().(self) -> Self::Inforust-analyzer cargo sudo-rs 0.2.14 sudoers/WithInfo#Info#; |
| 566 | } |
| 567 | |
| 568 | /// A specific interface for `Spec<T>` --- we can't make a generic one; |
| 569 | /// A `Spec<T>` does not contain any additional information. |
| 570 | impl<'a, T> WithInforust-analyzer cargo sudo-rs 0.2.14 sudoers/WithInfo# for &'a Specrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Spec#<T> { |
| 571 | type Itemrust-analyzer cargo sudo-rs 0.2.14 sudoers/impl#[`&'a Qualified<Meta<T>>`][WithInfo]Item# = &'a Specrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Spec#<T>; |
| 572 | type Inforust-analyzer cargo sudo-rs 0.2.14 sudoers/impl#[`&'a Qualified<Meta<T>>`][WithInfo]Info# = (); |
| 573 | fn as_innerrust-analyzer cargo sudo-rs 0.2.14 sudoers/impl#[`&'a Qualified<Meta<T>>`][WithInfo]as_inner().(&self) -> &'a Specrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Spec#<T> { |
| 574 | self |
| 575 | } |
| 576 | fn into_inforust-analyzer cargo sudo-rs 0.2.14 sudoers/impl#[`&'a Qualified<Meta<T>>`][WithInfo]into_info().(self) {} |
| 577 | } |
| 578 | |
| 579 | /// A commandspec can be "tagged" |
| 580 | impl<'a> WithInforust-analyzer cargo sudo-rs 0.2.14 sudoers/WithInfo# for (Tagrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Tag#, &'a Specrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Spec#<Commandrust-analyzer cargo sudo-rs 0.2.14 sudoers/tokens/Command#>) { |
| 581 | type Itemrust-analyzer cargo sudo-rs 0.2.14 sudoers/impl#[`(Tag, &'a Qualified<Meta<(glob::Pattern, Args)>>)`][WithInfo]Item# = &'a Specrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Spec#<Commandrust-analyzer cargo sudo-rs 0.2.14 sudoers/tokens/Command#>; |
| 582 | type Inforust-analyzer cargo sudo-rs 0.2.14 sudoers/impl#[`(Tag, &'a Qualified<Meta<(glob::Pattern, Args)>>)`][WithInfo]Info# = Tagrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Tag#; |
| 583 | fn as_innerrust-analyzer cargo sudo-rs 0.2.14 sudoers/impl#[`(Tag, &'a Qualified<Meta<(glob::Pattern, Args)>>)`][WithInfo]as_inner().(&self) -> &'a Specrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Spec#<Commandrust-analyzer cargo sudo-rs 0.2.14 sudoers/tokens/Command#> { |
| 584 | self.1 |
| 585 | } |
| 586 | fn into_inforust-analyzer cargo sudo-rs 0.2.14 sudoers/impl#[`(Tag, &'a Qualified<Meta<(glob::Pattern, Args)>>)`][WithInfo]into_info().(self) -> Tagrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Tag# { |
| 587 | self.0 |
| 588 | } |
| 589 | } |
| 590 | |
| 591 | /// Now follow a collection of functions used as closures for `find_item` |
| 592 | fn match_userrust-analyzer cargo sudo-rs 0.2.14 sudoers/match_user().(user: &impl UnixUserrust-analyzer cargo sudo-rs 0.2.14 system/interface/UnixUser#) -> impl Fnrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/Fn#(&UserSpecifierrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/UserSpecifier#) -> bool + '_ { |
| 593 | move |spec| match spec { |
| 594 | UserSpecifierrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/UserSpecifier#::Userrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/UserSpecifier#User#(id) => match_identifierrust-analyzer cargo sudo-rs 0.2.14 sudoers/match_identifier().(user, id), |
| 595 | UserSpecifierrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/UserSpecifier#::Grouprust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/UserSpecifier#Group#(Identifierrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Identifier#::Namerust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Identifier#Name#(name)) => user.in_group_by_namerust-analyzer cargo sudo-rs 0.2.14 system/interface/UnixUser#in_group_by_name().(name.as_cstrrust-analyzer cargo sudo-rs 0.2.14 common/string/impl#[SudoString]as_cstr().()), |
| 596 | UserSpecifierrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/UserSpecifier#::Grouprust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/UserSpecifier#Group#(Identifierrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Identifier#::IDrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Identifier#ID#(num)) => user.in_group_by_gidrust-analyzer cargo sudo-rs 0.2.14 system/interface/UnixUser#in_group_by_gid().(GroupIdrust-analyzer cargo sudo-rs 0.2.14 system/interface/GroupId#::newrust-analyzer cargo sudo-rs 0.2.14 system/interface/impl#[GroupId]new().(*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().num)), |
| 597 | // nonunix-groups, netgroups, etc. are not implemented |
| 598 | UserSpecifierrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/UserSpecifier#::NonunixGrouprust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/UserSpecifier#NonunixGroup#(group) => { |
| 599 | match group { |
| 600 | Identifierrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Identifier#::Namerust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Identifier#Name#(name) => auth_warnrust-analyzer cargo sudo-rs 0.2.14 log/auth_warn!!("warning: non-unix group {name} was ignored"), |
| 601 | Identifierrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Identifier#::IDrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Identifier#ID#(num) => auth_warnrust-analyzer cargo sudo-rs 0.2.14 log/auth_warn!!("warning: non-unix group #{num} was ignored"), |
| 602 | } |
| 603 | |
| 604 | false |
| 605 | } |
| 606 | } |
| 607 | } |
| 608 | |
| 609 | fn in_grouprust-analyzer cargo sudo-rs 0.2.14 sudoers/in_group().(user: &impl UnixUserrust-analyzer cargo sudo-rs 0.2.14 system/interface/UnixUser#, group: &impl UnixGrouprust-analyzer cargo sudo-rs 0.2.14 system/interface/UnixGroup#) -> bool { |
| 610 | user.in_group_by_gidrust-analyzer cargo sudo-rs 0.2.14 system/interface/UnixUser#in_group_by_gid().(group.as_gidrust-analyzer cargo sudo-rs 0.2.14 system/interface/UnixGroup#as_gid().()) |
| 611 | } |
| 612 | |
| 613 | fn match_grouprust-analyzer cargo sudo-rs 0.2.14 sudoers/match_group().(group: &impl UnixGrouprust-analyzer cargo sudo-rs 0.2.14 system/interface/UnixGroup#) -> impl Fnrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/Fn#(&Identifierrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Identifier#) -> bool + '_ { |
| 614 | move |id| match id { |
| 615 | Identifierrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Identifier#::IDrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Identifier#ID#(num) => group.as_gidrust-analyzer cargo sudo-rs 0.2.14 system/interface/UnixGroup#as_gid().() rust-analyzer cargo sudo-rs 0.2.14 system/interface/impl#[GroupId][`PartialEq<Self>`]eq().==rust-analyzer cargo sudo-rs 0.2.14 system/interface/impl#[GroupId][`PartialEq<Self>`]eq(). rust-analyzer cargo sudo-rs 0.2.14 system/interface/impl#[GroupId][`PartialEq<Self>`]eq().GroupIdrust-analyzer cargo sudo-rs 0.2.14 system/interface/GroupId#::newrust-analyzer cargo sudo-rs 0.2.14 system/interface/impl#[GroupId]new().(*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().num), |
| 616 | Identifierrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Identifier#::Namerust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Identifier#Name#(name) => group.try_as_namerust-analyzer cargo sudo-rs 0.2.14 system/interface/UnixGroup#try_as_name().().is_some_andrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some_and().(|s| name rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq().s), |
| 617 | } |
| 618 | } |
| 619 | |
| 620 | fn match_group_aliasrust-analyzer cargo sudo-rs 0.2.14 sudoers/match_group_alias().(group: &impl UnixGrouprust-analyzer cargo sudo-rs 0.2.14 system/interface/UnixGroup#) -> impl Fnrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/Fn#(&UserSpecifierrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/UserSpecifier#) -> bool + '_ { |
| 621 | move |spec| match spec { |
| 622 | UserSpecifierrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/UserSpecifier#::Userrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/UserSpecifier#User#(ident) => match_grouprust-analyzer cargo sudo-rs 0.2.14 sudoers/match_group().(group)(ident), |
| 623 | /* the parser does not allow this, but can happen due to Runas_Alias, |
| 624 | * see https://github.com/trifectatechfoundation/sudo-rs/issues/13 */ |
| 625 | _ => { |
| 626 | auth_warnrust-analyzer cargo sudo-rs 0.2.14 log/auth_warn!!("warning: ignoring %group syntax in runas_alias for checking sudo -g"); |
| 627 | false |
| 628 | } |
| 629 | } |
| 630 | } |
| 631 | |
| 632 | fn match_tokenrust-analyzer cargo sudo-rs 0.2.14 sudoers/match_token().<T: basic_parserrust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/::Tokenrust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/Token# + stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::opsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/::Derefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/Deref#<Targetrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/Deref#Target# = Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>>( |
| 633 | text: &str, |
| 634 | ) -> impl Fnrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/Fn#(&T) -> bool + '_ { |
| 635 | move |token| token.as_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]as_str().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq().text |
| 636 | } |
| 637 | |
| 638 | fn match_commandrust-analyzer cargo sudo-rs 0.2.14 sudoers/match_command().<'a>((cmd, args): (&'a Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#, &'a [OsStringrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/OsString#])) -> impl Fnrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/Fn#(&Commandrust-analyzer cargo sudo-rs 0.2.14 sudoers/tokens/Command#) -> bool + 'a { |
| 639 | let opts = globrust-analyzer cargo glob 0.3.3 crate/::MatchOptionsrust-analyzer cargo glob 0.3.3 MatchOptions# { |
| 640 | require_literal_separatorrust-analyzer cargo glob 0.3.3 MatchOptions#require_literal_separator.: true, |
| 641 | ..globrust-analyzer cargo glob 0.3.3 crate/::MatchOptionsrust-analyzer cargo glob 0.3.3 MatchOptions#::newrust-analyzer cargo glob 0.3.3 impl#[MatchOptions]new().() |
| 642 | }; |
| 643 | move |(cmdpat, argpat)| { |
| 644 | cmdpat.matches_path_withrust-analyzer cargo glob 0.3.3 impl#[Pattern]matches_path_with().(cmd, opts) |
| 645 | && match argpat { |
| 646 | Argsrust-analyzer cargo sudo-rs 0.2.14 sudoers/tokens/Args#::Prefixrust-analyzer cargo sudo-rs 0.2.14 sudoers/tokens/Args#Prefix#(vec) => args.starts_withrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]starts_with().(vec), |
| 647 | Argsrust-analyzer cargo sudo-rs 0.2.14 sudoers/tokens/Args#::Exactrust-analyzer cargo sudo-rs 0.2.14 sudoers/tokens/Args#Exact#(vec) => args rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq().vec.as_refrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/impl#[`Box<T, A>`][`AsRef<T>`]as_ref().(), |
| 648 | } |
| 649 | } |
| 650 | } |
| 651 | |
| 652 | /// Find all the aliases that a object is a member of; this requires [sanitize_alias_table] to have run first; |
| 653 | /// I.e. this function should not be "pub". |
| 654 | fn get_aliasesrust-analyzer cargo sudo-rs 0.2.14 sudoers/get_aliases().<Predicate, T>(table: &VecOrdrust-analyzer cargo sudo-rs 0.2.14 sudoers/VecOrd#<Defrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Def#<T>>, pred: &Predicate) -> FoundAliasesrust-analyzer cargo sudo-rs 0.2.14 sudoers/FoundAliases# |
| 655 | where |
| 656 | Predicate: Fnrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/Fn#(&T) -> bool, |
| 657 | { |
| 658 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/::oncerust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/sources/once/once().; |
| 659 | let all = Qualifiedrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Qualified#::Allowrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Qualified#Allow#(Metarust-analyzer cargo sudo-rs 0.2.14 sudoers/tokens/Meta#::Allrust-analyzer cargo sudo-rs 0.2.14 sudoers/tokens/Meta#All#); |
| 660 | |
| 661 | let mut set = HashMaprust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/HashMap#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V>`]new().(); |
| 662 | for Defrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Def#(id, list) in table.iterrust-analyzer cargo sudo-rs 0.2.14 sudoers/impl#[`VecOrd<T>`]iter().() { |
| 663 | if find_itemrust-analyzer cargo sudo-rs 0.2.14 sudoers/find_item().(list, &pred, &set).is_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some().() { |
| 664 | set.insertrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]insert().(id.clonerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][Clone]clone().(), true); |
| 665 | } else if find_itemrust-analyzer cargo sudo-rs 0.2.14 sudoers/find_item().(oncerust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/sources/once/once().(&all).chainrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#chain().(list), &pred, &set).is_nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_none().() { |
| 666 | // the item wasn't found even if we prepend ALL to the list of definitions; that means |
| 667 | // it is explicitly excluded by the alias definition. |
| 668 | set.insertrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]insert().(id.clonerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][Clone]clone().(), false); |
| 669 | } |
| 670 | } |
| 671 | |
| 672 | set |
| 673 | } |
| 674 | |
| 675 | /// Code to map an ast::Identifier to the UnixUser trait |
| 676 | fn match_identifierrust-analyzer cargo sudo-rs 0.2.14 sudoers/match_identifier().(user: &impl UnixUserrust-analyzer cargo sudo-rs 0.2.14 system/interface/UnixUser#, ident: &astrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/::Identifierrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Identifier#) -> bool { |
| 677 | match ident { |
| 678 | Identifierrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Identifier#::Namerust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Identifier#Name#(name) => user.has_namerust-analyzer cargo sudo-rs 0.2.14 system/interface/UnixUser#has_name().(name), |
| 679 | Identifierrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Identifier#::IDrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Identifier#ID#(num) => user.has_uidrust-analyzer cargo sudo-rs 0.2.14 system/interface/UnixUser#has_uid().(UserIdrust-analyzer cargo sudo-rs 0.2.14 system/interface/UserId#::newrust-analyzer cargo sudo-rs 0.2.14 system/interface/impl#[UserId]new().(*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().num)), |
| 680 | } |
| 681 | } |
| 682 | |
| 683 | /// Process a sudoers-parsing file into a workable AST |
| 684 | fn analyzerust-analyzer cargo sudo-rs 0.2.14 sudoers/analyze().( |
| 685 | path: &Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#, |
| 686 | sudoers: impl IntoIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#<Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#Item# = basic_parserrust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/::Parsedrust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/Parsed#<Sudorust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Sudo#>>, |
| 687 | ) -> (Sudoersrust-analyzer cargo sudo-rs 0.2.14 sudoers/Sudoers#, Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Errorrust-analyzer cargo sudo-rs 0.2.14 sudoers/Error#>) { |
| 688 | use craterust-analyzer cargo sudo-rs 0.2.14 crate/::commonrust-analyzer cargo sudo-rs 0.2.14 common/::{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.}; |
| 689 | use Directiverust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Directive#::*; |
| 690 | |
| 691 | let mut result: Sudoersrust-analyzer cargo sudo-rs 0.2.14 sudoers/Sudoers# = 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().(); |
| 692 | |
| 693 | /// The IncludeState allows to tell whether including new files is allowed. |
| 694 | /// There are two situations: |
| 695 | /// - inclusion is forbidden (as when the @socket directive is used) |
| 696 | /// - inclusion is allowed but we need to ensure we didn't go beyond the limit |
| 697 | #[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:)] |
| 698 | #[repr(u32)] |
| 699 | enum IncludeStaterust-analyzer cargo sudo-rs 0.2.14 sudoers/IncludeState# { |
| 700 | #[cfg(feature = "unstable-remote-sudoers")] |
| 701 | Forbidden = HARDENED_ENUM_VALUE_0rust-analyzer cargo sudo-rs 0.2.14 common/HARDENED_ENUM_VALUE_0., |
| 702 | Allowedrust-analyzer cargo sudo-rs 0.2.14 sudoers/IncludeState#Allowed#(u8) = HARDENED_ENUM_VALUE_1rust-analyzer cargo sudo-rs 0.2.14 common/HARDENED_ENUM_VALUE_1., |
| 703 | } |
| 704 | |
| 705 | impl IncludeStaterust-analyzer cargo sudo-rs 0.2.14 sudoers/IncludeState# { |
| 706 | #[inline] |
| 707 | fn incrust-analyzer cargo sudo-rs 0.2.14 sudoers/impl#[IncludeState]inc().(&mut self) -> &mut Selfrust-analyzer cargo sudo-rs 0.2.14 sudoers/impl#[IncludeState] { |
| 708 | #[cfg_attr( |
| 709 | not(feature = "unstable-remote-sudoers"), |
| 710 | allow(irrefutable_let_patterns) |
| 711 | )] |
| 712 | if let IncludeStaterust-analyzer cargo sudo-rs 0.2.14 sudoers/IncludeState#::Allowedrust-analyzer cargo sudo-rs 0.2.14 sudoers/IncludeState#Allowed#(x) = self { |
| 713 | *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().x rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u8][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u8][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u8][`AddAssign<Self>`]add_assign().1; |
| 714 | } |
| 715 | self |
| 716 | } |
| 717 | |
| 718 | #[inline] |
| 719 | fn limit_reachedrust-analyzer cargo sudo-rs 0.2.14 sudoers/impl#[IncludeState]limit_reached().(&self) -> bool { |
| 720 | match self { |
| 721 | #[cfg(feature = "unstable-remote-sudoers")] |
| 722 | IncludeStaterust-analyzer cargo sudo-rs 0.2.14 sudoers/IncludeState#::Forbidden => true, |
| 723 | IncludeStaterust-analyzer cargo sudo-rs 0.2.14 sudoers/IncludeState#::Allowedrust-analyzer cargo sudo-rs 0.2.14 sudoers/IncludeState#Allowed#(x) => *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().x rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialOrd<Self>`]ge().>=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialOrd<Self>`]ge(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialOrd<Self>`]ge().INCLUDE_LIMITrust-analyzer cargo sudo-rs 0.2.14 sudoers/INCLUDE_LIMIT., |
| 724 | } |
| 725 | } |
| 726 | } |
| 727 | |
| 728 | /// The directive that produced the inclusion. |
| 729 | #[repr(u32)] |
| 730 | enum IncludeDirectiverust-analyzer cargo sudo-rs 0.2.14 sudoers/IncludeDirective# { |
| 731 | Includerust-analyzer cargo sudo-rs 0.2.14 sudoers/IncludeDirective#Include# = HARDENED_ENUM_VALUE_0rust-analyzer cargo sudo-rs 0.2.14 common/HARDENED_ENUM_VALUE_0., |
| 732 | IncludeDirrust-analyzer cargo sudo-rs 0.2.14 sudoers/IncludeDirective#IncludeDir# = HARDENED_ENUM_VALUE_1rust-analyzer cargo sudo-rs 0.2.14 common/HARDENED_ENUM_VALUE_1., |
| 733 | #[cfg(feature = "unstable-remote-sudoers")] |
| 734 | Remote = HARDENED_ENUM_VALUE_2rust-analyzer cargo sudo-rs 0.2.14 common/HARDENED_ENUM_VALUE_2., |
| 735 | } |
| 736 | |
| 737 | 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 IncludeDirectiverust-analyzer cargo sudo-rs 0.2.14 sudoers/IncludeDirective# { |
| 738 | fn fmtrust-analyzer cargo sudo-rs 0.2.14 sudoers/impl#[IncludeDirective][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# { |
| 739 | let s = match self { |
| 740 | IncludeDirectiverust-analyzer cargo sudo-rs 0.2.14 sudoers/IncludeDirective#::Includerust-analyzer cargo sudo-rs 0.2.14 sudoers/IncludeDirective#Include# => "@include", |
| 741 | IncludeDirectiverust-analyzer cargo sudo-rs 0.2.14 sudoers/IncludeDirective#::IncludeDirrust-analyzer cargo sudo-rs 0.2.14 sudoers/IncludeDirective#IncludeDir# => "@includedir", |
| 742 | #[cfg(feature = "unstable-remote-sudoers")] |
| 743 | IncludeDirectiverust-analyzer cargo sudo-rs 0.2.14 sudoers/IncludeDirective#::Remote => "@socket", |
| 744 | }; |
| 745 | writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(f, "{s}") |
| 746 | } |
| 747 | } |
| 748 | |
| 749 | fn resolve_relativerust-analyzer cargo sudo-rs 0.2.14 sudoers/resolve_relative().(base: &Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#, path: impl AsRefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#<Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#>) -> PathBufrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/PathBuf# { |
| 750 | if path.as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#as_ref().().is_relativerust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]is_relative().() { |
| 751 | // there should always be a parent since we start with /etc/sudoers, and make every other path |
| 752 | // absolute based on previous inputs; not having a parent is therefore a serious bug |
| 753 | base.parentrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]parent().() |
| 754 | .expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]expect().("invalid hardcoded path in sudo-rs") |
| 755 | .joinrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]join().(path) |
| 756 | } else { |
| 757 | path.as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#as_ref().().intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().() |
| 758 | } |
| 759 | } |
| 760 | |
| 761 | fn includerust-analyzer cargo sudo-rs 0.2.14 sudoers/include().( |
| 762 | cfg: &mut Sudoersrust-analyzer cargo sudo-rs 0.2.14 sudoers/Sudoers#, |
| 763 | parent: &Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#, |
| 764 | span: Spanrust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/Span#, |
| 765 | path: &Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#, |
| 766 | diagnostics: &mut Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Errorrust-analyzer cargo sudo-rs 0.2.14 sudoers/Error#>, |
| 767 | include_state: &mut IncludeStaterust-analyzer cargo sudo-rs 0.2.14 sudoers/IncludeState#, |
| 768 | include_source: IncludeDirectiverust-analyzer cargo sudo-rs 0.2.14 sudoers/IncludeDirective#, |
| 769 | ) { |
| 770 | // IncludeState::limit_reached() will also detect forbidden includes |
| 771 | if include_state.limit_reachedrust-analyzer cargo sudo-rs 0.2.14 sudoers/impl#[IncludeState]limit_reached().() { |
| 772 | let message = match include_state { |
| 773 | IncludeStaterust-analyzer cargo sudo-rs 0.2.14 sudoers/IncludeState#::Allowedrust-analyzer cargo sudo-rs 0.2.14 sudoers/IncludeState#Allowed#(_) => { |
| 774 | formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("include file limit reached opening '{}'", path.displayrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]display().()) |
| 775 | } |
| 776 | #[cfg(feature = "unstable-remote-sudoers")] |
| 777 | IncludeStaterust-analyzer cargo sudo-rs 0.2.14 sudoers/IncludeState#::Forbidden => { |
| 778 | formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("{} forbidden at this stage", include_source) |
| 779 | } |
| 780 | }; |
| 781 | diagnostics.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(Errorrust-analyzer cargo sudo-rs 0.2.14 sudoers/Error# { |
| 782 | sourcerust-analyzer cargo sudo-rs 0.2.14 sudoers/Error#source.: Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(parent.to_ownedrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path][ToOwned]to_owned().()), |
| 783 | locationrust-analyzer cargo sudo-rs 0.2.14 sudoers/Error#location.: Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(span), |
| 784 | messagerust-analyzer cargo sudo-rs 0.2.14 sudoers/Error#message., |
| 785 | }); |
| 786 | } else { |
| 787 | let (res, next_state, kind) = match include_source { |
| 788 | #[cfg(feature = "unstable-remote-sudoers")] |
| 789 | IncludeDirectiverust-analyzer cargo sudo-rs 0.2.14 sudoers/IncludeDirective#::Remote => ( |
| 790 | open_remote_sudoers(path), |
| 791 | &mut IncludeStaterust-analyzer cargo sudo-rs 0.2.14 sudoers/IncludeState#::Forbidden, |
| 792 | "socket", |
| 793 | ), |
| 794 | _ => (open_sudoersrust-analyzer cargo sudo-rs 0.2.14 sudoers/open_sudoers().(path), include_state.incrust-analyzer cargo sudo-rs 0.2.14 sudoers/impl#[IncludeState]inc().(), "file"), |
| 795 | }; |
| 796 | |
| 797 | match res { |
| 798 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(subsudoer) => processrust-analyzer cargo sudo-rs 0.2.14 sudoers/process().(cfg, path, subsudoer, diagnostics, next_state), |
| 799 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(e) => { |
| 800 | let message = if e.kindrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/impl#[Error]kind().() rust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/impl#[ErrorKind][`PartialEq<Self>`]eq().==rust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/impl#[ErrorKind][`PartialEq<Self>`]eq(). rust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/impl#[ErrorKind][`PartialEq<Self>`]eq().iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::ErrorKindrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/ErrorKind#::NotFoundrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/ErrorKind#NotFound# { |
| 801 | // improve the error message in this case |
| 802 | formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("cannot open sudoers {} '{}'", kind, path.displayrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]display().()) |
| 803 | } else { |
| 804 | e.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().() |
| 805 | }; |
| 806 | |
| 807 | diagnostics.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(Errorrust-analyzer cargo sudo-rs 0.2.14 sudoers/Error# { |
| 808 | sourcerust-analyzer cargo sudo-rs 0.2.14 sudoers/Error#source.: Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(parent.to_ownedrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path][ToOwned]to_owned().()), |
| 809 | locationrust-analyzer cargo sudo-rs 0.2.14 sudoers/Error#location.: Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(span), |
| 810 | messagerust-analyzer cargo sudo-rs 0.2.14 sudoers/Error#message., |
| 811 | }) |
| 812 | } |
| 813 | } |
| 814 | } |
| 815 | } |
| 816 | |
| 817 | fn processrust-analyzer cargo sudo-rs 0.2.14 sudoers/process().( |
| 818 | cfg: &mut Sudoersrust-analyzer cargo sudo-rs 0.2.14 sudoers/Sudoers#, |
| 819 | cur_path: &Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#, |
| 820 | sudoers: impl IntoIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#<Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#Item# = basic_parserrust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/::Parsedrust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/Parsed#<Sudorust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Sudo#>>, |
| 821 | diagnostics: &mut Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Errorrust-analyzer cargo sudo-rs 0.2.14 sudoers/Error#>, |
| 822 | include_state: &mut IncludeStaterust-analyzer cargo sudo-rs 0.2.14 sudoers/IncludeState#, |
| 823 | ) { |
| 824 | for item in sudoers { |
| 825 | match item { |
| 826 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(line) => match line { |
| 827 | Sudorust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Sudo#::LineCommentrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Sudo#LineComment# => {} |
| 828 | |
| 829 | Sudorust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Sudo#::Specrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Sudo#Spec#(permission) => { |
| 830 | diagnostics.extendrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Extend<T>`]extend().(get_ignored_tagsrust-analyzer cargo sudo-rs 0.2.14 sudoers/get_ignored_tags().(&permission).maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|span| Errorrust-analyzer cargo sudo-rs 0.2.14 sudoers/Error# { |
| 831 | sourcerust-analyzer cargo sudo-rs 0.2.14 sudoers/Error#source.: Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(cur_path.to_ownedrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path][ToOwned]to_owned().()), |
| 832 | locationrust-analyzer cargo sudo-rs 0.2.14 sudoers/Error#location.: Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(span), |
| 833 | messagerust-analyzer cargo sudo-rs 0.2.14 sudoers/Error#message.: "this tag is ignored by sudo-rs".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), |
| 834 | })); |
| 835 | cfg.rulesrust-analyzer cargo sudo-rs 0.2.14 sudoers/Sudoers#rules..pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(permission); |
| 836 | } |
| 837 | |
| 838 | Sudorust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Sudo#::Declrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Sudo#Decl#(HostAliasrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Directive#HostAlias#(mut def)) => cfg.aliasesrust-analyzer cargo sudo-rs 0.2.14 sudoers/Sudoers#aliases..hostrust-analyzer cargo sudo-rs 0.2.14 sudoers/AliasTable#host..1rust-analyzer cargo sudo-rs 0.2.14 sudoers/VecOrd#1..appendrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]append().(&mut def), |
| 839 | Sudorust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Sudo#::Declrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Sudo#Decl#(UserAliasrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Directive#UserAlias#(mut def)) => cfg.aliasesrust-analyzer cargo sudo-rs 0.2.14 sudoers/Sudoers#aliases..userrust-analyzer cargo sudo-rs 0.2.14 sudoers/AliasTable#user..1rust-analyzer cargo sudo-rs 0.2.14 sudoers/VecOrd#1..appendrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]append().(&mut def), |
| 840 | Sudorust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Sudo#::Declrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Sudo#Decl#(RunasAliasrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Directive#RunasAlias#(mut def)) => cfg.aliasesrust-analyzer cargo sudo-rs 0.2.14 sudoers/Sudoers#aliases..runasrust-analyzer cargo sudo-rs 0.2.14 sudoers/AliasTable#runas..1rust-analyzer cargo sudo-rs 0.2.14 sudoers/VecOrd#1..appendrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]append().(&mut def), |
| 841 | Sudorust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Sudo#::Declrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Sudo#Decl#(CmndAliasrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Directive#CmndAlias#(mut def)) => cfg.aliasesrust-analyzer cargo sudo-rs 0.2.14 sudoers/Sudoers#aliases..cmndrust-analyzer cargo sudo-rs 0.2.14 sudoers/AliasTable#cmnd..1rust-analyzer cargo sudo-rs 0.2.14 sudoers/VecOrd#1..appendrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]append().(&mut def), |
| 842 | |
| 843 | Sudorust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Sudo#::Declrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Sudo#Decl#(Defaultsrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Directive#Defaults#(params, scope)) => { |
| 844 | if let ConfigScoperust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/ConfigScope#::Commandrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/ConfigScope#Command#(specs) = scope { |
| 845 | cfg.customisersrust-analyzer cargo sudo-rs 0.2.14 sudoers/Sudoers#customisers..cmndrust-analyzer cargo sudo-rs 0.2.14 sudoers/CustomiserTable#cmnd..pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(( |
| 846 | specs |
| 847 | .into_iterrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][IntoIterator]into_iter().() |
| 848 | .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|spec| { |
| 849 | spec.maprust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/impl#[`Qualified<Meta<T>>`]map().(|simple_command| { |
| 850 | (simple_command, Argsrust-analyzer cargo sudo-rs 0.2.14 sudoers/tokens/Args#::Prefixrust-analyzer cargo sudo-rs 0.2.14 sudoers/tokens/Args#Prefix#(Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#::defaultrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/impl#[`Box<[T]>`][Default]default().())) |
| 851 | }) |
| 852 | }) |
| 853 | .collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(), |
| 854 | params, |
| 855 | )); |
| 856 | } else { |
| 857 | cfg.customisersrust-analyzer cargo sudo-rs 0.2.14 sudoers/Sudoers#customisers..non_cmndrust-analyzer cargo sudo-rs 0.2.14 sudoers/CustomiserTable#non_cmnd..pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().((scope, params)); |
| 858 | } |
| 859 | } |
| 860 | |
| 861 | Sudorust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Sudo#::Includerust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Sudo#Include#(path, span) => includerust-analyzer cargo sudo-rs 0.2.14 sudoers/include().( |
| 862 | cfg, |
| 863 | cur_path, |
| 864 | span, |
| 865 | &resolve_relativerust-analyzer cargo sudo-rs 0.2.14 sudoers/resolve_relative().(cur_path, path), |
| 866 | diagnostics, |
| 867 | include_state, |
| 868 | IncludeDirectiverust-analyzer cargo sudo-rs 0.2.14 sudoers/IncludeDirective#::Includerust-analyzer cargo sudo-rs 0.2.14 sudoers/IncludeDirective#Include#, |
| 869 | ), |
| 870 | |
| 871 | #[cfg(feature = "unstable-remote-sudoers")] |
| 872 | Sudorust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Sudo#::Remote(path, span) => { |
| 873 | let socket_path = Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#::new(&path); |
| 874 | if socket_path.is_relative() { |
| 875 | diagnostics.push(Errorrust-analyzer cargo sudo-rs 0.2.14 sudoers/Error# { |
| 876 | source: Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(cur_path.to_owned()), |
| 877 | location: Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(span), |
| 878 | message: formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!( |
| 879 | "cannot open socket {path}: path must be absolute" |
| 880 | ), |
| 881 | }); |
| 882 | } else { |
| 883 | includerust-analyzer cargo sudo-rs 0.2.14 sudoers/include().( |
| 884 | cfg, |
| 885 | cur_path, |
| 886 | span, |
| 887 | socket_path, |
| 888 | diagnostics, |
| 889 | include_state, |
| 890 | IncludeDirectiverust-analyzer cargo sudo-rs 0.2.14 sudoers/IncludeDirective#::Remote, |
| 891 | ); |
| 892 | } |
| 893 | } |
| 894 | |
| 895 | Sudorust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Sudo#::IncludeDirrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Sudo#IncludeDir#(path, span) => { |
| 896 | if path.containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]contains().("%h") { |
| 897 | diagnostics.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(Errorrust-analyzer cargo sudo-rs 0.2.14 sudoers/Error# { |
| 898 | sourcerust-analyzer cargo sudo-rs 0.2.14 sudoers/Error#source.: Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(cur_path.to_ownedrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path][ToOwned]to_owned().()), |
| 899 | locationrust-analyzer cargo sudo-rs 0.2.14 sudoers/Error#location.: Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(span), |
| 900 | messagerust-analyzer cargo sudo-rs 0.2.14 sudoers/Error#message.: formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!( |
| 901 | "cannot open sudoers file {path}: \ |
| 902 | percent escape %h in includedir is unsupported" |
| 903 | ), |
| 904 | }); |
| 905 | continue; |
| 906 | } |
| 907 | |
| 908 | let path = resolve_relativerust-analyzer cargo sudo-rs 0.2.14 sudoers/resolve_relative().(cur_path, path); |
| 909 | let Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(files) = stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/::read_dirrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/read_dir().(&path) else { |
| 910 | diagnostics.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(Errorrust-analyzer cargo sudo-rs 0.2.14 sudoers/Error# { |
| 911 | sourcerust-analyzer cargo sudo-rs 0.2.14 sudoers/Error#source.: Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(cur_path.to_ownedrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path][ToOwned]to_owned().()), |
| 912 | locationrust-analyzer cargo sudo-rs 0.2.14 sudoers/Error#location.: Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(span), |
| 913 | messagerust-analyzer cargo sudo-rs 0.2.14 sudoers/Error#message.: formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("cannot open sudoers file {}", path.displayrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]display().()), |
| 914 | }); |
| 915 | continue; |
| 916 | }; |
| 917 | let mut safe_files = files |
| 918 | .filter_maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#filter_map().(|direntry| { |
| 919 | let path = direntry.okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]ok().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][Try]branch()..pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/impl#[DirEntry]path().(); |
| 920 | let text = path.file_namerust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]file_name().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][Try]branch()..to_strrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/impl#[OsStr]to_str().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][Try]branch().; |
| 921 | if text.ends_withrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]ends_with().('~') || text.containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]contains().('.') { |
| 922 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# |
| 923 | } else { |
| 924 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(path) |
| 925 | } |
| 926 | }) |
| 927 | .collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>(); |
| 928 | safe_files.sortrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc slice/impl#[`[T]`]sort().(); |
| 929 | for file in safe_files { |
| 930 | includerust-analyzer cargo sudo-rs 0.2.14 sudoers/include().( |
| 931 | cfg, |
| 932 | cur_path, |
| 933 | span, |
| 934 | file.as_refrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[PathBuf][`AsRef<Path>`]as_ref().(), |
| 935 | diagnostics, |
| 936 | include_state, |
| 937 | IncludeDirectiverust-analyzer cargo sudo-rs 0.2.14 sudoers/IncludeDirective#::IncludeDirrust-analyzer cargo sudo-rs 0.2.14 sudoers/IncludeDirective#IncludeDir#, |
| 938 | ) |
| 939 | } |
| 940 | } |
| 941 | }, |
| 942 | |
| 943 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(basic_parserrust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/::Statusrust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/Status#::Fatalrust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/Status#Fatal#(pos, message)) => diagnostics.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(Errorrust-analyzer cargo sudo-rs 0.2.14 sudoers/Error# { |
| 944 | sourcerust-analyzer cargo sudo-rs 0.2.14 sudoers/Error#source.: Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(cur_path.to_ownedrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path][ToOwned]to_owned().()), |
| 945 | locationrust-analyzer cargo sudo-rs 0.2.14 sudoers/Error#location.: Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(pos), |
| 946 | messagerust-analyzer cargo sudo-rs 0.2.14 sudoers/Error#message., |
| 947 | }), |
| 948 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(_) => panicrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/panic!!("internal parser error"), |
| 949 | } |
| 950 | } |
| 951 | } |
| 952 | |
| 953 | fn get_ignored_tagsrust-analyzer cargo sudo-rs 0.2.14 sudoers/get_ignored_tags().( |
| 954 | PermissionSpecrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/PermissionSpec# { permissionsrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/PermissionSpec#permissions., .. }: &PermissionSpecrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/PermissionSpec#, |
| 955 | ) -> impl Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#<Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item# = Spanrust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/Span#> + '_ { |
| 956 | permissions |
| 957 | .iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().() |
| 958 | .flat_maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#flat_map().(|(_host, runas_cmds)| runas_cmds) |
| 959 | .flat_maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#flat_map().(|(_runas, CommandSpecrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/CommandSpec#(tags, _cmd))| tags) |
| 960 | .flat_maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#flat_map().(|modifier| { |
| 961 | let mut tag = 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().(); |
| 962 | modifier(&mut tag); |
| 963 | tag.ignoredrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Tag#ignored. |
| 964 | }) |
| 965 | } |
| 966 | |
| 967 | let mut diagnostics = vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![]; |
| 968 | processrust-analyzer cargo sudo-rs 0.2.14 sudoers/process().( |
| 969 | &mut result, |
| 970 | path, |
| 971 | sudoers, |
| 972 | &mut diagnostics, |
| 973 | &mut IncludeStaterust-analyzer cargo sudo-rs 0.2.14 sudoers/IncludeState#::Allowedrust-analyzer cargo sudo-rs 0.2.14 sudoers/IncludeState#Allowed#(0), |
| 974 | ); |
| 975 | |
| 976 | let alias = &mut result.aliasesrust-analyzer cargo sudo-rs 0.2.14 sudoers/Sudoers#aliases.; |
| 977 | alias.userrust-analyzer cargo sudo-rs 0.2.14 sudoers/AliasTable#user..0rust-analyzer cargo sudo-rs 0.2.14 sudoers/VecOrd#0. = sanitize_alias_tablerust-analyzer cargo sudo-rs 0.2.14 sudoers/sanitize_alias_table().(&alias.userrust-analyzer cargo sudo-rs 0.2.14 sudoers/AliasTable#user..1rust-analyzer cargo sudo-rs 0.2.14 sudoers/VecOrd#1., &mut diagnostics); |
| 978 | alias.hostrust-analyzer cargo sudo-rs 0.2.14 sudoers/AliasTable#host..0rust-analyzer cargo sudo-rs 0.2.14 sudoers/VecOrd#0. = sanitize_alias_tablerust-analyzer cargo sudo-rs 0.2.14 sudoers/sanitize_alias_table().(&alias.hostrust-analyzer cargo sudo-rs 0.2.14 sudoers/AliasTable#host..1rust-analyzer cargo sudo-rs 0.2.14 sudoers/VecOrd#1., &mut diagnostics); |
| 979 | alias.cmndrust-analyzer cargo sudo-rs 0.2.14 sudoers/AliasTable#cmnd..0rust-analyzer cargo sudo-rs 0.2.14 sudoers/VecOrd#0. = sanitize_alias_tablerust-analyzer cargo sudo-rs 0.2.14 sudoers/sanitize_alias_table().(&alias.cmndrust-analyzer cargo sudo-rs 0.2.14 sudoers/AliasTable#cmnd..1rust-analyzer cargo sudo-rs 0.2.14 sudoers/VecOrd#1., &mut diagnostics); |
| 980 | alias.runasrust-analyzer cargo sudo-rs 0.2.14 sudoers/AliasTable#runas..0rust-analyzer cargo sudo-rs 0.2.14 sudoers/VecOrd#0. = sanitize_alias_tablerust-analyzer cargo sudo-rs 0.2.14 sudoers/sanitize_alias_table().(&alias.runasrust-analyzer cargo sudo-rs 0.2.14 sudoers/AliasTable#runas..1rust-analyzer cargo sudo-rs 0.2.14 sudoers/VecOrd#1., &mut diagnostics); |
| 981 | |
| 982 | (result, diagnostics) |
| 983 | } |
| 984 | |
| 985 | /// Alias definition inin a Sudoers file can come in any order; and aliases can refer to other aliases, etc. |
| 986 | /// It is much easier if they are presented in a "definitional order" (i.e. aliases that use other aliases occur later) |
| 987 | /// At the same time, this is a good place to detect problems in the aliases, such as unknown aliases and cycles. |
| 988 | fn sanitize_alias_tablerust-analyzer cargo sudo-rs 0.2.14 sudoers/sanitize_alias_table().<T>(table: &Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Defrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Def#<T>>, diagnostics: &mut Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Errorrust-analyzer cargo sudo-rs 0.2.14 sudoers/Error#>) -> Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<usize> { |
| 989 | fn remqualifyrust-analyzer cargo sudo-rs 0.2.14 sudoers/remqualify().<U>(item: &Qualifiedrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Qualified#<U>) -> &U { |
| 990 | match item { |
| 991 | Qualifiedrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Qualified#::Allowrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Qualified#Allow#(x) => x, |
| 992 | Qualifiedrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Qualified#::Forbidrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Qualified#Forbid#(x) => x, |
| 993 | } |
| 994 | } |
| 995 | |
| 996 | // perform a topological sort (hattip [email protected]) to produce a derangement |
| 997 | struct Visitorrust-analyzer cargo sudo-rs 0.2.14 sudoers/Visitor#<'a, T> { |
| 998 | seenrust-analyzer cargo sudo-rs 0.2.14 sudoers/Visitor#seen.: HashSetrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/HashSet#<usize>, |
| 999 | tablerust-analyzer cargo sudo-rs 0.2.14 sudoers/Visitor#table.: &'a Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Defrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Def#<T>>, |
| 1000 | orderrust-analyzer cargo sudo-rs 0.2.14 sudoers/Visitor#order.: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<usize>, |
| 1001 | diagnosticsrust-analyzer cargo sudo-rs 0.2.14 sudoers/Visitor#diagnostics.: &'a mut Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Errorrust-analyzer cargo sudo-rs 0.2.14 sudoers/Error#>, |
| 1002 | } |
| 1003 | |
| 1004 | impl<T> Visitorrust-analyzer cargo sudo-rs 0.2.14 sudoers/Visitor#<'_, T> { |
| 1005 | fn complainrust-analyzer cargo sudo-rs 0.2.14 sudoers/impl#[`Visitor<'_, T>`]complain().(&mut self, text: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#) { |
| 1006 | self.diagnosticsrust-analyzer cargo sudo-rs 0.2.14 sudoers/Visitor#diagnostics..pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(Errorrust-analyzer cargo sudo-rs 0.2.14 sudoers/Error# { |
| 1007 | sourcerust-analyzer cargo sudo-rs 0.2.14 sudoers/Error#source.: Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, |
| 1008 | locationrust-analyzer cargo sudo-rs 0.2.14 sudoers/Error#location.: Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, |
| 1009 | messagerust-analyzer cargo sudo-rs 0.2.14 sudoers/Error#message.: text, |
| 1010 | }) |
| 1011 | } |
| 1012 | |
| 1013 | fn visitrust-analyzer cargo sudo-rs 0.2.14 sudoers/impl#[`Visitor<'_, T>`]visit().(&mut self, pos: usize) { |
| 1014 | if self.seenrust-analyzer cargo sudo-rs 0.2.14 sudoers/Visitor#seen..insertrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S, A>`]insert().(pos) { |
| 1015 | let Defrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Def#(_, members) = &self.tablerust-analyzer cargo sudo-rs 0.2.14 sudoers/Visitor#table.[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().pos]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().; |
| 1016 | for elem in members { |
| 1017 | let Metarust-analyzer cargo sudo-rs 0.2.14 sudoers/tokens/Meta#::Aliasrust-analyzer cargo sudo-rs 0.2.14 sudoers/tokens/Meta#Alias#(name) = remqualifyrust-analyzer cargo sudo-rs 0.2.14 sudoers/remqualify().(elem) else { |
| 1018 | continue; |
| 1019 | }; |
| 1020 | let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(dependency) = self.tablerust-analyzer cargo sudo-rs 0.2.14 sudoers/Visitor#table..iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().positionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/iter/impl#[`Iter<'a, T>`][Iterator]position().(|Defrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Def#(id, _)| id rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq().name) |
| 1021 | else { |
| 1022 | self.complainrust-analyzer cargo sudo-rs 0.2.14 sudoers/impl#[`Visitor<'_, T>`]complain().(formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("undefined alias: '{name}'")); |
| 1023 | continue; |
| 1024 | }; |
| 1025 | self.visitrust-analyzer cargo sudo-rs 0.2.14 sudoers/impl#[`Visitor<'_, T>`]visit().(dependency); |
| 1026 | } |
| 1027 | self.orderrust-analyzer cargo sudo-rs 0.2.14 sudoers/Visitor#order..pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(pos); |
| 1028 | } else if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().self.orderrust-analyzer cargo sudo-rs 0.2.14 sudoers/Visitor#order..containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]contains().(&pos) { |
| 1029 | let Defrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Def#(id, _) = &self.tablerust-analyzer cargo sudo-rs 0.2.14 sudoers/Visitor#table.[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().pos]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().; |
| 1030 | self.complainrust-analyzer cargo sudo-rs 0.2.14 sudoers/impl#[`Visitor<'_, T>`]complain().(formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("recursive alias: '{id}'")); |
| 1031 | } |
| 1032 | } |
| 1033 | } |
| 1034 | |
| 1035 | let mut visitor = Visitorrust-analyzer cargo sudo-rs 0.2.14 sudoers/Visitor# { |
| 1036 | seenrust-analyzer cargo sudo-rs 0.2.14 sudoers/Visitor#seen.: HashSetrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/HashSet#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T>`]new().(), |
| 1037 | tablerust-analyzer cargo sudo-rs 0.2.14 sudoers/Visitor#table., |
| 1038 | orderrust-analyzer cargo sudo-rs 0.2.14 sudoers/Visitor#order.: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::with_capacityrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]with_capacity().(table.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().()), |
| 1039 | diagnosticsrust-analyzer cargo sudo-rs 0.2.14 sudoers/Visitor#diagnostics., |
| 1040 | }; |
| 1041 | |
| 1042 | let mut dupe = HashSetrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/HashSet#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T>`]new().(); |
| 1043 | for (i, Defrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Def#(name, _)) in table.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().enumeraterust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#enumerate().() { |
| 1044 | if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().dupe.insertrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S, A>`]insert().(name) { |
| 1045 | visitor.complainrust-analyzer cargo sudo-rs 0.2.14 sudoers/impl#[`Visitor<'_, T>`]complain().(formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("multiple occurrences of '{name}'")); |
| 1046 | } else { |
| 1047 | visitor.visitrust-analyzer cargo sudo-rs 0.2.14 sudoers/impl#[`Visitor<'_, T>`]visit().(i); |
| 1048 | } |
| 1049 | } |
| 1050 | |
| 1051 | visitor.orderrust-analyzer cargo sudo-rs 0.2.14 sudoers/Visitor#order. |
| 1052 | } |
| 1053 | |
| 1054 | #[cfg(test)] |
| 1055 | mod testrust-analyzer cargo sudo-rs 0.2.14 sudoers/test/; |