| 1 | use superrust-analyzer cargo sudo-rs 0.2.14 sudoers/::ast_namesrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast_names/::UserFriendlyrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast_names/UserFriendly#; |
| 2 | use superrust-analyzer cargo sudo-rs 0.2.14 sudoers/::basic_parserrust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/::*; |
| 3 | use superrust-analyzer cargo sudo-rs 0.2.14 sudoers/::tokensrust-analyzer cargo sudo-rs 0.2.14 sudoers/tokens/::*; |
| 4 | use craterust-analyzer cargo sudo-rs 0.2.14 crate/::commonrust-analyzer cargo sudo-rs 0.2.14 common/::SudoStringrust-analyzer cargo sudo-rs 0.2.14 common/string/SudoString#; |
| 5 | use craterust-analyzer cargo sudo-rs 0.2.14 crate/::commonrust-analyzer cargo sudo-rs 0.2.14 common/::{ |
| 6 | 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., HARDENED_ENUM_VALUE_3rust-analyzer cargo sudo-rs 0.2.14 common/HARDENED_ENUM_VALUE_3., |
| 7 | HARDENED_ENUM_VALUE_4rust-analyzer cargo sudo-rs 0.2.14 common/HARDENED_ENUM_VALUE_4., HARDENED_ENUM_VALUE_5rust-analyzer cargo sudo-rs 0.2.14 common/HARDENED_ENUM_VALUE_5., |
| 8 | }; |
| 9 | use craterust-analyzer cargo sudo-rs 0.2.14 crate/::defaultsrust-analyzer cargo sudo-rs 0.2.14 defaults/; |
| 10 | |
| 11 | /// The Sudoers file allows negating items with the exclamation mark. |
| 12 | #[cfg_attr(test, derive(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:))] |
| 13 | #[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:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:)] |
| 14 | #[repr(u32)] |
| 15 | pub enum Qualifiedrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Qualified#<T> { |
| 16 | Allowrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Qualified#Allow#(T) = HARDENED_ENUM_VALUE_0rust-analyzer cargo sudo-rs 0.2.14 common/HARDENED_ENUM_VALUE_0., |
| 17 | Forbidrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Qualified#Forbid#(T) = HARDENED_ENUM_VALUE_1rust-analyzer cargo sudo-rs 0.2.14 common/HARDENED_ENUM_VALUE_1., |
| 18 | } |
| 19 | |
| 20 | /// Type aliases; many items can be replaced by ALL, aliases, and negated. |
| 21 | pub type Specrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Spec#<T> = Qualifiedrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Qualified#<Metarust-analyzer cargo sudo-rs 0.2.14 sudoers/tokens/Meta#<T>>; |
| 22 | pub type SpecListrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/SpecList#<T> = Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Specrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Spec#<T>>; |
| 23 | |
| 24 | /// A generic mapping function (only used for turning `Spec<SimpleCommand>` into `Spec<Command>`) |
| 25 | impl<T> Specrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Spec#<T> { |
| 26 | pub fn maprust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/impl#[`Qualified<Meta<T>>`]map().<U>(self, f: impl Fnrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/Fn#(T) -> U) -> Specrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Spec#<U> { |
| 27 | let transform = |meta| match meta { |
| 28 | Metarust-analyzer cargo sudo-rs 0.2.14 sudoers/tokens/Meta#::Allrust-analyzer cargo sudo-rs 0.2.14 sudoers/tokens/Meta#All# => Metarust-analyzer cargo sudo-rs 0.2.14 sudoers/tokens/Meta#::Allrust-analyzer cargo sudo-rs 0.2.14 sudoers/tokens/Meta#All#, |
| 29 | Metarust-analyzer cargo sudo-rs 0.2.14 sudoers/tokens/Meta#::Aliasrust-analyzer cargo sudo-rs 0.2.14 sudoers/tokens/Meta#Alias#(alias) => Metarust-analyzer cargo sudo-rs 0.2.14 sudoers/tokens/Meta#::Aliasrust-analyzer cargo sudo-rs 0.2.14 sudoers/tokens/Meta#Alias#(alias), |
| 30 | Metarust-analyzer cargo sudo-rs 0.2.14 sudoers/tokens/Meta#::Onlyrust-analyzer cargo sudo-rs 0.2.14 sudoers/tokens/Meta#Only#(x) => Metarust-analyzer cargo sudo-rs 0.2.14 sudoers/tokens/Meta#::Onlyrust-analyzer cargo sudo-rs 0.2.14 sudoers/tokens/Meta#Only#(f(x)), |
| 31 | }; |
| 32 | |
| 33 | match self { |
| 34 | Qualifiedrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Qualified#::Allowrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Qualified#Allow#(x) => Qualifiedrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Qualified#::Allowrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Qualified#Allow#(transform(x)), |
| 35 | Qualifiedrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Qualified#::Forbidrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Qualified#Forbid#(x) => Qualifiedrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Qualified#::Forbidrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Qualified#Forbid#(transform(x)), |
| 36 | } |
| 37 | } |
| 38 | } |
| 39 | |
| 40 | /// An identifier is a name or a #number |
| 41 | #[cfg_attr(test, derive(Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:))] |
| 42 | #[repr(u32)] |
| 43 | pub enum Identifierrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Identifier# { |
| 44 | Namerust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Identifier#Name#(SudoStringrust-analyzer cargo sudo-rs 0.2.14 common/string/SudoString#) = HARDENED_ENUM_VALUE_0rust-analyzer cargo sudo-rs 0.2.14 common/HARDENED_ENUM_VALUE_0., |
| 45 | IDrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Identifier#ID#(u32) = HARDENED_ENUM_VALUE_1rust-analyzer cargo sudo-rs 0.2.14 common/HARDENED_ENUM_VALUE_1., |
| 46 | } |
| 47 | |
| 48 | /// A userspecifier is either a username, or a (non-unix) group name, or netgroup |
| 49 | #[cfg_attr(test, derive(Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:))] |
| 50 | #[repr(u32)] |
| 51 | pub enum UserSpecifierrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/UserSpecifier# { |
| 52 | Userrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/UserSpecifier#User#(Identifierrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Identifier#) = HARDENED_ENUM_VALUE_0rust-analyzer cargo sudo-rs 0.2.14 common/HARDENED_ENUM_VALUE_0., |
| 53 | Grouprust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/UserSpecifier#Group#(Identifierrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Identifier#) = HARDENED_ENUM_VALUE_1rust-analyzer cargo sudo-rs 0.2.14 common/HARDENED_ENUM_VALUE_1., |
| 54 | NonunixGrouprust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/UserSpecifier#NonunixGroup#(Identifierrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Identifier#) = HARDENED_ENUM_VALUE_2rust-analyzer cargo sudo-rs 0.2.14 common/HARDENED_ENUM_VALUE_2., |
| 55 | } |
| 56 | |
| 57 | /// The RunAs specification consists of a (possibly empty) list of userspecifiers, followed by a (possibly empty) list of groups. |
| 58 | pub struct RunAsrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/RunAs# { |
| 59 | pub usersrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/RunAs#users.: SpecListrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/SpecList#<UserSpecifierrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/UserSpecifier#>, |
| 60 | pub groupsrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/RunAs#groups.: SpecListrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/SpecList#<Identifierrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Identifier#>, |
| 61 | } |
| 62 | |
| 63 | // `sudo -l l` calls this the `authenticate` option |
| 64 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy:, Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:)] |
| 65 | #[cfg_attr(test, derive(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:))] |
| 66 | #[repr(u32)] |
| 67 | pub enum Authenticaterust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Authenticate# { |
| 68 | #[defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/default:] |
| 69 | Nonerust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Authenticate#None# = HARDENED_ENUM_VALUE_0rust-analyzer cargo sudo-rs 0.2.14 common/HARDENED_ENUM_VALUE_0., |
| 70 | // PASSWD: |
| 71 | Passwdrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Authenticate#Passwd# = HARDENED_ENUM_VALUE_1rust-analyzer cargo sudo-rs 0.2.14 common/HARDENED_ENUM_VALUE_1., |
| 72 | // NOPASSWD: |
| 73 | Nopasswdrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Authenticate#Nopasswd# = HARDENED_ENUM_VALUE_2rust-analyzer cargo sudo-rs 0.2.14 common/HARDENED_ENUM_VALUE_2., |
| 74 | } |
| 75 | |
| 76 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy:, Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:)] |
| 77 | #[cfg_attr(test, derive(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:))] |
| 78 | #[repr(u32)] |
| 79 | pub enum EnvironmentControlrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/EnvironmentControl# { |
| 80 | #[defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/default:] |
| 81 | Implicitrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/EnvironmentControl#Implicit# = HARDENED_ENUM_VALUE_0rust-analyzer cargo sudo-rs 0.2.14 common/HARDENED_ENUM_VALUE_0., |
| 82 | // PASSWD: |
| 83 | Setenvrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/EnvironmentControl#Setenv# = HARDENED_ENUM_VALUE_1rust-analyzer cargo sudo-rs 0.2.14 common/HARDENED_ENUM_VALUE_1., |
| 84 | // NOPASSWD: |
| 85 | Nosetenvrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/EnvironmentControl#Nosetenv# = HARDENED_ENUM_VALUE_2rust-analyzer cargo sudo-rs 0.2.14 common/HARDENED_ENUM_VALUE_2., |
| 86 | } |
| 87 | |
| 88 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy:, Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:)] |
| 89 | #[cfg_attr(test, derive(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:))] |
| 90 | #[repr(u32)] |
| 91 | pub enum ExecControlrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/ExecControl# { |
| 92 | #[defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/default:] |
| 93 | Implicitrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/ExecControl#Implicit# = HARDENED_ENUM_VALUE_0rust-analyzer cargo sudo-rs 0.2.14 common/HARDENED_ENUM_VALUE_0., |
| 94 | // PASSWD: |
| 95 | Execrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/ExecControl#Exec# = HARDENED_ENUM_VALUE_1rust-analyzer cargo sudo-rs 0.2.14 common/HARDENED_ENUM_VALUE_1., |
| 96 | // NOPASSWD: |
| 97 | Noexecrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/ExecControl#Noexec# = HARDENED_ENUM_VALUE_2rust-analyzer cargo sudo-rs 0.2.14 common/HARDENED_ENUM_VALUE_2., |
| 98 | } |
| 99 | |
| 100 | /// Commands in /etc/sudoers can have attributes attached to them, such as NOPASSWD, NOEXEC, ... |
| 101 | #[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:, Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:)] |
| 102 | #[cfg_attr(test, derive(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:))] |
| 103 | pub struct Tagrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Tag# { |
| 104 | pub(superrust-analyzer cargo sudo-rs 0.2.14 sudoers/) authenticaterust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Tag#authenticate.: Authenticaterust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Authenticate#, |
| 105 | pub(superrust-analyzer cargo sudo-rs 0.2.14 sudoers/) cwdrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Tag#cwd.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<ChDirrust-analyzer cargo sudo-rs 0.2.14 sudoers/tokens/ChDir#>, |
| 106 | pub(superrust-analyzer cargo sudo-rs 0.2.14 sudoers/) envrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Tag#env.: EnvironmentControlrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/EnvironmentControl#, |
| 107 | pub(superrust-analyzer cargo sudo-rs 0.2.14 sudoers/) apparmor_profilerust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Tag#apparmor_profile.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>, |
| 108 | pub(superrust-analyzer cargo sudo-rs 0.2.14 sudoers/) noexecrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Tag#noexec.: ExecControlrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/ExecControl#, |
| 109 | pub(superrust-analyzer cargo sudo-rs 0.2.14 sudoers/) ignoredrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Tag#ignored.: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Spanrust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/Span#>, |
| 110 | } |
| 111 | |
| 112 | impl Tagrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Tag# { |
| 113 | pub fn needs_passwdrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/impl#[Tag]needs_passwd().(&self) -> bool { |
| 114 | matchesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/matches!!(self.authenticaterust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Tag#authenticate., Authenticaterust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Authenticate#::Nonerust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Authenticate#None# | Authenticaterust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Authenticate#::Passwdrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Authenticate#Passwd#) |
| 115 | } |
| 116 | } |
| 117 | |
| 118 | /// Commands with attached attributes. |
| 119 | pub struct CommandSpecrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/CommandSpec#(pub Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Modifierrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Modifier#>, pub Specrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Spec#<Commandrust-analyzer cargo sudo-rs 0.2.14 sudoers/tokens/Command#>); |
| 120 | |
| 121 | /// The main AST object for one sudoer-permission line |
| 122 | type PairVecrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/PairVec#<A, B> = Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<(A, Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<B>)>; |
| 123 | |
| 124 | pub struct PermissionSpecrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/PermissionSpec# { |
| 125 | pub usersrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/PermissionSpec#users.: SpecListrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/SpecList#<UserSpecifierrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/UserSpecifier#>, |
| 126 | pub permissionsrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/PermissionSpec#permissions.: PairVecrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/PairVec#<SpecListrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/SpecList#<Hostnamerust-analyzer cargo sudo-rs 0.2.14 sudoers/tokens/Hostname#>, (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#)>, |
| 127 | } |
| 128 | |
| 129 | pub type Defsrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Defs#<T> = 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>>; |
| 130 | pub struct Defrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Def#<T>(pub Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, pub SpecListrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/SpecList#<T>); |
| 131 | |
| 132 | /// AST object for directive specifications (aliases, arguments, etc) |
| 133 | #[repr(u32)] |
| 134 | pub enum Directiverust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Directive# { |
| 135 | UserAliasrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Directive#UserAlias#(Defsrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Defs#<UserSpecifierrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/UserSpecifier#>) = HARDENED_ENUM_VALUE_0rust-analyzer cargo sudo-rs 0.2.14 common/HARDENED_ENUM_VALUE_0., |
| 136 | HostAliasrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Directive#HostAlias#(Defsrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Defs#<Hostnamerust-analyzer cargo sudo-rs 0.2.14 sudoers/tokens/Hostname#>) = HARDENED_ENUM_VALUE_1rust-analyzer cargo sudo-rs 0.2.14 common/HARDENED_ENUM_VALUE_1., |
| 137 | CmndAliasrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Directive#CmndAlias#(Defsrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Defs#<Commandrust-analyzer cargo sudo-rs 0.2.14 sudoers/tokens/Command#>) = HARDENED_ENUM_VALUE_2rust-analyzer cargo sudo-rs 0.2.14 common/HARDENED_ENUM_VALUE_2., |
| 138 | RunasAliasrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Directive#RunasAlias#(Defsrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Defs#<UserSpecifierrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/UserSpecifier#>) = HARDENED_ENUM_VALUE_3rust-analyzer cargo sudo-rs 0.2.14 common/HARDENED_ENUM_VALUE_3., |
| 139 | Defaultsrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Directive#Defaults#(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#>, ConfigScoperust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/ConfigScope#) = HARDENED_ENUM_VALUE_4rust-analyzer cargo sudo-rs 0.2.14 common/HARDENED_ENUM_VALUE_4., |
| 140 | } |
| 141 | |
| 142 | /// AST object for the 'context' (host, user, cmnd, runas) of a Defaults directive |
| 143 | #[repr(u32)] |
| 144 | pub enum ConfigScoperust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/ConfigScope# { |
| 145 | // "Defaults entries are parsed in the following order: |
| 146 | // generic, host and user Defaults first, then runas Defaults and finally command defaults." |
| 147 | Genericrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/ConfigScope#Generic# = HARDENED_ENUM_VALUE_0rust-analyzer cargo sudo-rs 0.2.14 common/HARDENED_ENUM_VALUE_0., |
| 148 | Hostrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/ConfigScope#Host#(SpecListrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/SpecList#<Hostnamerust-analyzer cargo sudo-rs 0.2.14 sudoers/tokens/Hostname#>) = HARDENED_ENUM_VALUE_1rust-analyzer cargo sudo-rs 0.2.14 common/HARDENED_ENUM_VALUE_1., |
| 149 | Userrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/ConfigScope#User#(SpecListrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/SpecList#<UserSpecifierrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/UserSpecifier#>) = HARDENED_ENUM_VALUE_2rust-analyzer cargo sudo-rs 0.2.14 common/HARDENED_ENUM_VALUE_2., |
| 150 | RunAsrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/ConfigScope#RunAs#(SpecListrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/SpecList#<UserSpecifierrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/UserSpecifier#>) = HARDENED_ENUM_VALUE_3rust-analyzer cargo sudo-rs 0.2.14 common/HARDENED_ENUM_VALUE_3., |
| 151 | Commandrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/ConfigScope#Command#(SpecListrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/SpecList#<SimpleCommandrust-analyzer cargo sudo-rs 0.2.14 sudoers/tokens/SimpleCommand#>) = HARDENED_ENUM_VALUE_4rust-analyzer cargo sudo-rs 0.2.14 common/HARDENED_ENUM_VALUE_4., |
| 152 | } |
| 153 | |
| 154 | /// The Sudoers file can contain permissions and directives |
| 155 | #[repr(u32)] |
| 156 | pub enum Sudorust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Sudo# { |
| 157 | Specrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Sudo#Spec#(PermissionSpecrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/PermissionSpec#) = HARDENED_ENUM_VALUE_0rust-analyzer cargo sudo-rs 0.2.14 common/HARDENED_ENUM_VALUE_0., |
| 158 | Declrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Sudo#Decl#(Directiverust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Directive#) = HARDENED_ENUM_VALUE_1rust-analyzer cargo sudo-rs 0.2.14 common/HARDENED_ENUM_VALUE_1., |
| 159 | Includerust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Sudo#Include#(Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, Spanrust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/Span#) = HARDENED_ENUM_VALUE_2rust-analyzer cargo sudo-rs 0.2.14 common/HARDENED_ENUM_VALUE_2., |
| 160 | IncludeDirrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Sudo#IncludeDir#(Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, Spanrust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/Span#) = HARDENED_ENUM_VALUE_3rust-analyzer cargo sudo-rs 0.2.14 common/HARDENED_ENUM_VALUE_3., |
| 161 | #[cfg(feature = "unstable-remote-sudoers")] |
| 162 | Remote(Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, Spanrust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/Span#) = HARDENED_ENUM_VALUE_4rust-analyzer cargo sudo-rs 0.2.14 common/HARDENED_ENUM_VALUE_4., |
| 163 | LineCommentrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Sudo#LineComment# = HARDENED_ENUM_VALUE_5rust-analyzer cargo sudo-rs 0.2.14 common/HARDENED_ENUM_VALUE_5., |
| 164 | } |
| 165 | |
| 166 | /// grammar: |
| 167 | /// ```text |
| 168 | /// identifier = name |
| 169 | /// | #<numerical id> |
| 170 | /// ``` |
| 171 | impl Parserust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/Parse# for Identifierrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Identifier# { |
| 172 | fn parserust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/impl#[Identifier][Parse]parse().(stream: &mut CharStreamrust-analyzer cargo sudo-rs 0.2.14 sudoers/char_stream/CharStream#) -> Parsedrust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/Parsed#<Selfrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/impl#[Identifier][Parse]> { |
| 173 | if stream.eat_charrust-analyzer cargo sudo-rs 0.2.14 sudoers/char_stream/impl#[`CharStream<'a>`]eat_char().('#') { |
| 174 | let DigitsU32rust-analyzer cargo sudo-rs 0.2.14 sudoers/tokens/DigitsU32#(guid) = expect_nonterminalrust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/expect_nonterminal().(stream)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 175 | makerust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/make().(Identifierrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Identifier#::IDrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Identifier#ID#(guid)) |
| 176 | } else { |
| 177 | let Usernamerust-analyzer cargo sudo-rs 0.2.14 sudoers/tokens/Username#(name) = try_nonterminalrust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/try_nonterminal().(stream)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 178 | makerust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/make().(Identifierrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Identifier#::Namerust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Identifier#Name#(name)) |
| 179 | } |
| 180 | } |
| 181 | } |
| 182 | |
| 183 | impl Manyrust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/Many# for Identifierrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Identifier# {} |
| 184 | |
| 185 | /// grammar: |
| 186 | /// ```text |
| 187 | /// qualified<T> = T | "!", qualified<T> |
| 188 | /// ``` |
| 189 | /// |
| 190 | /// This computes the correct negation with multiple exclamation marks in the parsing stage so we |
| 191 | /// are not bothered by it later. |
| 192 | impl<T: Parserust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/Parse# + UserFriendlyrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast_names/UserFriendly#> Parserust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/Parse# for Qualifiedrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Qualified#<T> { |
| 193 | fn parserust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/impl#[`Qualified<T>`][Parse]parse().(stream: &mut CharStreamrust-analyzer cargo sudo-rs 0.2.14 sudoers/char_stream/CharStream#) -> Parsedrust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/Parsed#<Selfrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/impl#[`Qualified<T>`][Parse]> { |
| 194 | if is_syntaxrust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/is_syntax().('!', stream)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch(). { |
| 195 | let mut neg = true; |
| 196 | while is_syntaxrust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/is_syntax().('!', stream)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch(). { |
| 197 | neg = !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().neg; |
| 198 | } |
| 199 | let ident = expect_nonterminalrust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/expect_nonterminal().(stream)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 200 | if neg { |
| 201 | makerust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/make().(Qualifiedrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Qualified#::Forbidrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Qualified#Forbid#(ident)) |
| 202 | } else { |
| 203 | makerust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/make().(Qualifiedrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Qualified#::Allowrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Qualified#Allow#(ident)) |
| 204 | } |
| 205 | } else { |
| 206 | let ident = try_nonterminalrust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/try_nonterminal().(stream)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 207 | makerust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/make().(Qualifiedrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Qualified#::Allowrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Qualified#Allow#(ident)) |
| 208 | } |
| 209 | } |
| 210 | } |
| 211 | |
| 212 | impl<T: Manyrust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/Many#> Manyrust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/Many# for Qualifiedrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Qualified#<T> { |
| 213 | const SEPrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/impl#[`Qualified<T>`][Many]SEP.: char = T::SEPrust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/Many#SEP.; |
| 214 | const LIMITrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/impl#[`Qualified<T>`][Many]LIMIT.: usize = T::LIMITrust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/Many#LIMIT.; |
| 215 | } |
| 216 | |
| 217 | /// Helper function for parsing `Meta<T>` things where T is not a token |
| 218 | fn parse_metarust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/parse_meta().<T: Parserust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/Parse#>( |
| 219 | stream: &mut CharStreamrust-analyzer cargo sudo-rs 0.2.14 sudoers/char_stream/CharStream#, |
| 220 | embed: impl FnOncerust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnOnce#(SudoStringrust-analyzer cargo sudo-rs 0.2.14 common/string/SudoString#) -> T, |
| 221 | ) -> Parsedrust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/Parsed#<Metarust-analyzer cargo sudo-rs 0.2.14 sudoers/tokens/Meta#<T>> { |
| 222 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(meta) = try_nonterminalrust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/try_nonterminal().(stream)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch(). { |
| 223 | makerust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/make().(match meta { |
| 224 | Metarust-analyzer cargo sudo-rs 0.2.14 sudoers/tokens/Meta#::Allrust-analyzer cargo sudo-rs 0.2.14 sudoers/tokens/Meta#All# => Metarust-analyzer cargo sudo-rs 0.2.14 sudoers/tokens/Meta#::Allrust-analyzer cargo sudo-rs 0.2.14 sudoers/tokens/Meta#All#, |
| 225 | Metarust-analyzer cargo sudo-rs 0.2.14 sudoers/tokens/Meta#::Aliasrust-analyzer cargo sudo-rs 0.2.14 sudoers/tokens/Meta#Alias#(alias) => Metarust-analyzer cargo sudo-rs 0.2.14 sudoers/tokens/Meta#::Aliasrust-analyzer cargo sudo-rs 0.2.14 sudoers/tokens/Meta#Alias#(alias), |
| 226 | Metarust-analyzer cargo sudo-rs 0.2.14 sudoers/tokens/Meta#::Onlyrust-analyzer cargo sudo-rs 0.2.14 sudoers/tokens/Meta#Only#(Usernamerust-analyzer cargo sudo-rs 0.2.14 sudoers/tokens/Username#(name)) => Metarust-analyzer cargo sudo-rs 0.2.14 sudoers/tokens/Meta#::Onlyrust-analyzer cargo sudo-rs 0.2.14 sudoers/tokens/Meta#Only#(embed(name)), |
| 227 | }) |
| 228 | } else { |
| 229 | makerust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/make().(Metarust-analyzer cargo sudo-rs 0.2.14 sudoers/tokens/Meta#::Onlyrust-analyzer cargo sudo-rs 0.2.14 sudoers/tokens/Meta#Only#(T::parserust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/Parse#parse().(stream)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().)) |
| 230 | } |
| 231 | } |
| 232 | |
| 233 | /// Since Identifier is not a token, add the parser for `Meta<Identifier>` |
| 234 | impl Parserust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/Parse# for Metarust-analyzer cargo sudo-rs 0.2.14 sudoers/tokens/Meta#<Identifierrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Identifier#> { |
| 235 | fn parserust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/impl#[`Meta<Identifier>`][Parse]parse().(stream: &mut CharStreamrust-analyzer cargo sudo-rs 0.2.14 sudoers/char_stream/CharStream#) -> Parsedrust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/Parsed#<Selfrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/impl#[`Meta<Identifier>`][Parse]> { |
| 236 | parse_metarust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/parse_meta().(stream, Identifierrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Identifier#::Namerust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Identifier#Name#) |
| 237 | } |
| 238 | } |
| 239 | |
| 240 | /// grammar: |
| 241 | /// ```text |
| 242 | /// userspec = identifier |
| 243 | /// | %identifier |
| 244 | /// | %:identifier |
| 245 | /// | +netgroup |
| 246 | /// ``` |
| 247 | impl Parserust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/Parse# for UserSpecifierrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/UserSpecifier# { |
| 248 | fn parserust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/impl#[UserSpecifier][Parse]parse().(stream: &mut CharStreamrust-analyzer cargo sudo-rs 0.2.14 sudoers/char_stream/CharStream#) -> Parsedrust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/Parsed#<Selfrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/impl#[UserSpecifier][Parse]> { |
| 249 | fn parse_userrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/parse_user().(stream: &mut CharStreamrust-analyzer cargo sudo-rs 0.2.14 sudoers/char_stream/CharStream#) -> Parsedrust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/Parsed#<UserSpecifierrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/UserSpecifier#> { |
| 250 | let userspec = if stream.eat_charrust-analyzer cargo sudo-rs 0.2.14 sudoers/char_stream/impl#[`CharStream<'a>`]eat_char().('%') { |
| 251 | let ctor = if stream.eat_charrust-analyzer cargo sudo-rs 0.2.14 sudoers/char_stream/impl#[`CharStream<'a>`]eat_char().(':') { |
| 252 | UserSpecifierrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/UserSpecifier#::NonunixGrouprust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/UserSpecifier#NonunixGroup# |
| 253 | } else { |
| 254 | UserSpecifierrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/UserSpecifier#::Grouprust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/UserSpecifier#Group# |
| 255 | }; |
| 256 | // in this case we must fail 'hard', since input has been consumed |
| 257 | ctor(expect_nonterminalrust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/expect_nonterminal().(stream)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().) |
| 258 | } else if stream.eat_charrust-analyzer cargo sudo-rs 0.2.14 sudoers/char_stream/impl#[`CharStream<'a>`]eat_char().('+') { |
| 259 | // TODO Netgroups |
| 260 | unrecoverablerust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/unrecoverable!!(stream, "netgroups are not supported yet"); |
| 261 | } else { |
| 262 | // in this case we must fail 'softly', since no input has been consumed yet |
| 263 | UserSpecifierrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/UserSpecifier#::Userrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/UserSpecifier#User#(try_nonterminalrust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/try_nonterminal().(stream)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().) |
| 264 | }; |
| 265 | |
| 266 | makerust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/make().(userspec) |
| 267 | } |
| 268 | |
| 269 | // if we see a quote, first parse the quoted text as a token and then |
| 270 | // re-parse whatever we found inside; this is a lazy solution but it works |
| 271 | if stream.eat_charrust-analyzer cargo sudo-rs 0.2.14 sudoers/char_stream/impl#[`CharStream<'a>`]eat_char().('"') { |
| 272 | let begin_pos = stream.get_posrust-analyzer cargo sudo-rs 0.2.14 sudoers/char_stream/impl#[`CharStream<'a>`]get_pos().(); |
| 273 | let Unquotedrust-analyzer cargo sudo-rs 0.2.14 sudoers/tokens/Unquoted#(text, _): Unquotedrust-analyzer cargo sudo-rs 0.2.14 sudoers/tokens/Unquoted#<Usernamerust-analyzer cargo sudo-rs 0.2.14 sudoers/tokens/Username#> = expect_nonterminalrust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/expect_nonterminal().(stream)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 274 | let result = parse_userrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/parse_user().(&mut CharStreamrust-analyzer cargo sudo-rs 0.2.14 sudoers/char_stream/CharStream#::new_with_posrust-analyzer cargo sudo-rs 0.2.14 sudoers/char_stream/impl#[`CharStream<'a>`]new_with_pos().(&text, begin_pos))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 275 | expect_syntaxrust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/expect_syntax().('"', stream)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 276 | |
| 277 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(result) |
| 278 | } else { |
| 279 | parse_userrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/parse_user().(stream) |
| 280 | } |
| 281 | } |
| 282 | } |
| 283 | |
| 284 | impl Manyrust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/Many# for UserSpecifierrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/UserSpecifier# {} |
| 285 | |
| 286 | /// UserSpecifier is not a token, implement the parser for `Meta<UserSpecifier>` |
| 287 | impl Parserust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/Parse# for Metarust-analyzer cargo sudo-rs 0.2.14 sudoers/tokens/Meta#<UserSpecifierrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/UserSpecifier#> { |
| 288 | fn parserust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/impl#[`Meta<UserSpecifier>`][Parse]parse().(stream: &mut CharStreamrust-analyzer cargo sudo-rs 0.2.14 sudoers/char_stream/CharStream#) -> Parsedrust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/Parsed#<Selfrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/impl#[`Meta<UserSpecifier>`][Parse]> { |
| 289 | parse_metarust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/parse_meta().(stream, |name| UserSpecifierrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/UserSpecifier#::Userrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/UserSpecifier#User#(Identifierrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Identifier#::Namerust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Identifier#Name#(name))) |
| 290 | } |
| 291 | } |
| 292 | |
| 293 | /// grammar: |
| 294 | /// ```text |
| 295 | /// runas = "(", userlist, (":", grouplist?)?, ")" |
| 296 | /// ``` |
| 297 | impl Parserust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/Parse# for RunAsrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/RunAs# { |
| 298 | fn parserust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/impl#[RunAs][Parse]parse().(stream: &mut CharStreamrust-analyzer cargo sudo-rs 0.2.14 sudoers/char_stream/CharStream#) -> Parsedrust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/Parsed#<Selfrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/impl#[RunAs][Parse]> { |
| 299 | try_syntaxrust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/try_syntax().('(', stream)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 300 | let users = try_nonterminalrust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/try_nonterminal().(stream).unwrap_or_defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap_or_default().(); |
| 301 | let groups = mayberust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/maybe().(try_syntaxrust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/try_syntax().(':', stream).and_thenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]and_then().(|_| try_nonterminalrust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/try_nonterminal().(stream)))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch(). |
| 302 | .unwrap_or_defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or_default().(); |
| 303 | expect_syntaxrust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/expect_syntax().(')', stream)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 304 | |
| 305 | makerust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/make().(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. }) |
| 306 | } |
| 307 | } |
| 308 | |
| 309 | /// Implementing the trait Parse for `Meta<flag>`. Wrapped in an own object to avoid |
| 310 | /// conflicting with a potential future generic parse definition for [Meta]. |
| 311 | /// |
| 312 | /// The reason for combining a parser for these two unrelated categories is that this is one spot |
| 313 | /// where the sudoer grammar isn't nicely LL(1); so at the same place where "NOPASSWD" can appear, |
| 314 | /// we could also see "ALL". |
| 315 | struct MetaOrTagrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/MetaOrTag#(Metarust-analyzer cargo sudo-rs 0.2.14 sudoers/tokens/Meta#<Modifierrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Modifier#>); |
| 316 | |
| 317 | /// A `Modifier` is something that updates the `Tag`. |
| 318 | pub type Modifierrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Modifier# = Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#<dyn Fnrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/Fn#(&mut Tagrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Tag#)>; |
| 319 | |
| 320 | // note: at present, "ALL" can be distinguished from a tag using a lookup of 1, since no tag starts with an "A"; but this feels like hanging onto |
| 321 | // the parseability by a thread (although the original sudo also has some ugly parts, like 'sha224' being an illegal user name). |
| 322 | // to be more general, we impl Parse for Meta<Tag> so a future tag like "AFOOBAR" can be added with no problem |
| 323 | |
| 324 | impl Parserust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/Parse# for MetaOrTagrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/MetaOrTag# { |
| 325 | fn parserust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/impl#[MetaOrTag][Parse]parse().(stream: &mut CharStreamrust-analyzer cargo sudo-rs 0.2.14 sudoers/char_stream/CharStream#) -> Parsedrust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/Parsed#<Selfrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/impl#[MetaOrTag][Parse]> { |
| 326 | use Metarust-analyzer cargo sudo-rs 0.2.14 sudoers/tokens/Meta#::*; |
| 327 | |
| 328 | let start_pos = stream.get_posrust-analyzer cargo sudo-rs 0.2.14 sudoers/char_stream/impl#[`CharStream<'a>`]get_pos().(); |
| 329 | let AliasNamerust-analyzer cargo sudo-rs 0.2.14 sudoers/tokens/AliasName#(keyword) = try_nonterminalrust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/try_nonterminal().(stream)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 330 | |
| 331 | let mut switch = |modifier: fn(&mut Tagrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Tag#)| { |
| 332 | expect_syntaxrust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/expect_syntax().(':', stream)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 333 | makerust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/make().(Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/impl#[`Box<T>`]new().(modifier)) |
| 334 | }; |
| 335 | |
| 336 | let result: Modifierrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Modifier# = match keyword.as_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]as_str().() { |
| 337 | "EXEC" => switch(|tag| tag.noexecrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Tag#noexec. = ExecControlrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/ExecControl#::Execrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/ExecControl#Exec#)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch()., |
| 338 | "NOEXEC" => switch(|tag| tag.noexecrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Tag#noexec. = ExecControlrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/ExecControl#::Noexecrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/ExecControl#Noexec#)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch()., |
| 339 | |
| 340 | "SETENV" => switch(|tag| tag.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#)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch()., |
| 341 | "NOSETENV" => switch(|tag| tag.envrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Tag#env. = EnvironmentControlrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/EnvironmentControl#::Nosetenvrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/EnvironmentControl#Nosetenv#)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch()., |
| 342 | "PASSWD" => switch(|tag| tag.authenticaterust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Tag#authenticate. = Authenticaterust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Authenticate#::Passwdrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Authenticate#Passwd#)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch()., |
| 343 | "NOPASSWD" => switch(|tag| tag.authenticaterust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Tag#authenticate. = Authenticaterust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Authenticate#::Nopasswdrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Authenticate#Nopasswd#)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch()., |
| 344 | |
| 345 | "CWD" => { |
| 346 | expect_syntaxrust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/expect_syntax().('=', stream)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 347 | let path: ChDirrust-analyzer cargo sudo-rs 0.2.14 sudoers/tokens/ChDir# = expect_nonterminalrust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/expect_nonterminal().(stream)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 348 | Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/impl#[`Box<T>`]new().(move |tag| tag.cwdrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Tag#cwd. = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(path.clonerust-analyzer cargo sudo-rs 0.2.14 sudoers/tokens/impl#[ChDir][Clone]clone().())) |
| 349 | } |
| 350 | |
| 351 | // we do not support these, and that should make sudo-rs "fail safe" |
| 352 | spec @ ("INTERCEPT" | "CHROOT" | "TIMEOUT" | "NOTBEFORE" | "NOTAFTER") => { |
| 353 | unrecoverablerust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/unrecoverable!!( |
| 354 | pos = start_pos, |
| 355 | stream, |
| 356 | "{spec} is not supported by sudo-rs" |
| 357 | ) |
| 358 | } |
| 359 | "ROLE" | "TYPE" => unrecoverablerust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/unrecoverable!!( |
| 360 | pos = start_pos, |
| 361 | stream, |
| 362 | "SELinux role based access control is not yet supported by sudo-rs" |
| 363 | ), |
| 364 | |
| 365 | // this is less fatal |
| 366 | "LOG_INPUT" | "NOLOG_INPUT" | "LOG_OUTPUT" | "NOLOG_OUTPUT" | "MAIL" | "NOMAIL" |
| 367 | | "FOLLOW" => { |
| 368 | let ignored_location = Spanrust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/Span# { |
| 369 | startrust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/Span#start.: start_pos, |
| 370 | endrust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/Span#end.: stream.get_posrust-analyzer cargo sudo-rs 0.2.14 sudoers/char_stream/impl#[`CharStream<'a>`]get_pos().(), |
| 371 | }; |
| 372 | expect_syntaxrust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/expect_syntax().(':', stream)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 373 | Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/impl#[`Box<T>`]new().(move |tag| tag.ignoredrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Tag#ignored..pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(ignored_location)) |
| 374 | } |
| 375 | |
| 376 | // 'NOFOLLOW' and 'NOINTERCEPT' are the default behaviour. |
| 377 | "NOFOLLOW" | "NOINTERCEPT" => switch(|_| {})?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch()., |
| 378 | |
| 379 | "APPARMOR_PROFILE" => { |
| 380 | expect_syntaxrust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/expect_syntax().('=', stream)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 381 | let StringParameterrust-analyzer cargo sudo-rs 0.2.14 sudoers/tokens/StringParameter#(profile) = expect_nonterminalrust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/expect_nonterminal().(stream)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 382 | Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/impl#[`Box<T>`]new().(move |tag| tag.apparmor_profilerust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Tag#apparmor_profile. = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(profile.clonerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][Clone]clone().())) |
| 383 | } |
| 384 | |
| 385 | "ALL" => return makerust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/make().(MetaOrTagrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/MetaOrTag#(Allrust-analyzer cargo sudo-rs 0.2.14 sudoers/tokens/Meta#All#)), |
| 386 | alias => { |
| 387 | if is_syntaxrust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/is_syntax().('=', stream)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch(). { |
| 388 | unrecoverablerust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/unrecoverable!!(pos = start_pos, stream, "unsupported modifier '{}'", alias); |
| 389 | } else { |
| 390 | return makerust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/make().(MetaOrTagrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/MetaOrTag#(Aliasrust-analyzer cargo sudo-rs 0.2.14 sudoers/tokens/Meta#Alias#(alias.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()))); |
| 391 | } |
| 392 | } |
| 393 | }; |
| 394 | |
| 395 | makerust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/make().(MetaOrTagrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/MetaOrTag#(Onlyrust-analyzer cargo sudo-rs 0.2.14 sudoers/tokens/Meta#Only#(result))) |
| 396 | } |
| 397 | } |
| 398 | |
| 399 | /// grammar: |
| 400 | /// ```text |
| 401 | /// commandspec = [tag modifiers]*, command |
| 402 | /// ``` |
| 403 | impl Parserust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/Parse# for CommandSpecrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/CommandSpec# { |
| 404 | fn parserust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/impl#[CommandSpec][Parse]parse().(stream: &mut CharStreamrust-analyzer cargo sudo-rs 0.2.14 sudoers/char_stream/CharStream#) -> Parsedrust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/Parsed#<Selfrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/impl#[CommandSpec][Parse]> { |
| 405 | use Qualifiedrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Qualified#::Allowrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Qualified#Allow#; |
| 406 | let mut tags = vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![]; |
| 407 | while let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(MetaOrTagrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/MetaOrTag#(keyword)) = try_nonterminalrust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/try_nonterminal().(stream)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch(). { |
| 408 | match keyword { |
| 409 | Metarust-analyzer cargo sudo-rs 0.2.14 sudoers/tokens/Meta#::Onlyrust-analyzer cargo sudo-rs 0.2.14 sudoers/tokens/Meta#Only#(modifier) => tags.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(modifier), |
| 410 | Metarust-analyzer cargo sudo-rs 0.2.14 sudoers/tokens/Meta#::Allrust-analyzer cargo sudo-rs 0.2.14 sudoers/tokens/Meta#All# => return makerust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/make().(CommandSpecrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/CommandSpec#(tags, 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#))), |
| 411 | Metarust-analyzer cargo sudo-rs 0.2.14 sudoers/tokens/Meta#::Aliasrust-analyzer cargo sudo-rs 0.2.14 sudoers/tokens/Meta#Alias#(name) => return makerust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/make().(CommandSpecrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/CommandSpec#(tags, Allowrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Qualified#Allow#(Metarust-analyzer cargo sudo-rs 0.2.14 sudoers/tokens/Meta#::Aliasrust-analyzer cargo sudo-rs 0.2.14 sudoers/tokens/Meta#Alias#(name)))), |
| 412 | } |
| 413 | if tags.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().Identifierrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Identifier#::LIMITrust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/Many#LIMIT. { |
| 414 | unrecoverablerust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/unrecoverable!!(stream, "too many tags for command specifier") |
| 415 | } |
| 416 | } |
| 417 | |
| 418 | let cmd: Specrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Spec#<Commandrust-analyzer cargo sudo-rs 0.2.14 sudoers/tokens/Command#> = expect_nonterminalrust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/expect_nonterminal().(stream)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 419 | |
| 420 | makerust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/make().(CommandSpecrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/CommandSpec#(tags, cmd)) |
| 421 | } |
| 422 | } |
| 423 | |
| 424 | /// Parsing for a tuple of hostname, runas specifier and commandspec. |
| 425 | /// grammar: |
| 426 | /// ```text |
| 427 | /// (host,runas,commandspec) = hostlist, "=", [runas?, commandspec]+ |
| 428 | /// ``` |
| 429 | impl Parserust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/Parse# for (SpecListrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/SpecList#<Hostnamerust-analyzer cargo sudo-rs 0.2.14 sudoers/tokens/Hostname#>, Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<(Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<RunAsrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/RunAs#>, CommandSpecrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/CommandSpec#)>) { |
| 430 | fn parserust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/impl#[`(Vec<Qualified<Meta<Hostname>>>, Vec<(Option<RunAs>, CommandSpec)>)`][Parse]parse().(stream: &mut CharStreamrust-analyzer cargo sudo-rs 0.2.14 sudoers/char_stream/CharStream#) -> Parsedrust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/Parsed#<Selfrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/impl#[`(Vec<Qualified<Meta<Hostname>>>, Vec<(Option<RunAs>, CommandSpec)>)`][Parse]> { |
| 431 | let hosts = try_nonterminalrust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/try_nonterminal().(stream)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 432 | expect_syntaxrust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/expect_syntax().('=', stream)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 433 | let runas_cmds = expect_nonterminalrust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/expect_nonterminal().(stream)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 434 | |
| 435 | makerust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/make().((hosts, runas_cmds)) |
| 436 | } |
| 437 | } |
| 438 | |
| 439 | /// A hostname, runas specifier, commandspec combination can occur multiple times in a single |
| 440 | /// sudoer line (separated by ":") |
| 441 | impl Manyrust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/Many# for (SpecListrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/SpecList#<Hostnamerust-analyzer cargo sudo-rs 0.2.14 sudoers/tokens/Hostname#>, Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<(Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<RunAsrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/RunAs#>, CommandSpecrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/CommandSpec#)>) { |
| 442 | const SEPrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/impl#[`(Vec<Qualified<Meta<Hostname>>>, Vec<(Option<RunAs>, CommandSpec)>)`][Many]SEP.: char = ':'; |
| 443 | } |
| 444 | |
| 445 | /// Parsing for a tuple of hostname, runas specifier and commandspec. |
| 446 | /// grammar: |
| 447 | /// ```text |
| 448 | /// (runas,commandspec) = runas?, commandspec |
| 449 | /// ``` |
| 450 | impl Parserust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/Parse# for (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#) { |
| 451 | fn parserust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/impl#[`(Option<RunAs>, CommandSpec)`][Parse]parse().(stream: &mut CharStreamrust-analyzer cargo sudo-rs 0.2.14 sudoers/char_stream/CharStream#) -> Parsedrust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/Parsed#<Selfrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/impl#[`(Option<RunAs>, CommandSpec)`][Parse]> { |
| 452 | let 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#> = try_nonterminalrust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/try_nonterminal().(stream)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 453 | let cmd = if runas.is_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some().() { |
| 454 | expect_nonterminalrust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/expect_nonterminal().(stream)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch(). |
| 455 | } else { |
| 456 | try_nonterminalrust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/try_nonterminal().(stream)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch(). |
| 457 | }; |
| 458 | |
| 459 | makerust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/make().((runas, cmd)) |
| 460 | } |
| 461 | } |
| 462 | |
| 463 | /// A runas specifier, commandspec combination can occur multiple times in a single |
| 464 | /// sudoer line (separated by ","); there is some ambiguity in the original grammar: |
| 465 | /// commands can also occur multiple times; we parse that here as if they have an omitted |
| 466 | /// "runas" specifier (which has to be placed correctly during the AST analysis phase) |
| 467 | impl Manyrust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/Many# for (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#) {} |
| 468 | |
| 469 | /// Directives such as "Defaults" and "HostAlias" also could be parsed as part of a |
| 470 | /// UserSpecifier list. We need to detect to give a parse error in cases where the syntax |
| 471 | /// seems to suggest they are used in that manner. |
| 472 | /// Technically, "Defaults@host" is also a valid username, but the logic can disambiguate |
| 473 | /// those cases clearly. E.g. "Defaults@host1,host2 secure_path=/bin/sh" is technically |
| 474 | /// ambiguous but it can be parsed. Time flies like an arrow, fruit flies like a banana. |
| 475 | impl Directiverust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Directive# { |
| 476 | fn could_be_usernamerust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/impl#[Directive]could_be_username().(&self) -> bool { |
| 477 | matchesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/matches!!( |
| 478 | self, |
| 479 | Selfrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/impl#[Directive]::Defaultsrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Directive#Defaults#(_, ConfigScoperust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/ConfigScope#::Genericrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/ConfigScope#Generic#) |
| 480 | | Selfrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/impl#[Directive]::UserAliasrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Directive#UserAlias#(_) |
| 481 | | Selfrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/impl#[Directive]::HostAliasrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Directive#HostAlias#(_) |
| 482 | | Selfrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/impl#[Directive]::CmndAliasrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Directive#CmndAlias#(_) |
| 483 | | Selfrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/impl#[Directive]::RunasAliasrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Directive#RunasAlias#(_) |
| 484 | ) |
| 485 | } |
| 486 | } |
| 487 | |
| 488 | /// grammar: |
| 489 | /// ```text |
| 490 | /// sudo = permissionspec |
| 491 | /// | Keyword_Alias identifier = identifier_list |
| 492 | /// | Defaults (name [+-]?= ...)+ |
| 493 | /// ``` |
| 494 | /// There is a syntactical ambiguity in the sudoer Directive and Permission specifications, so we |
| 495 | /// have to parse them 'together' and do a delayed decision on which category we are in. |
| 496 | impl Parserust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/Parse# for Sudorust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Sudo# { |
| 497 | // note: original sudo would reject: |
| 498 | // "User_Alias, user machine = command" |
| 499 | // but accept: |
| 500 | // "user, User_Alias machine = command"; this does the same |
| 501 | fn parserust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/impl#[Sudo][Parse]parse().(stream: &mut CharStreamrust-analyzer cargo sudo-rs 0.2.14 sudoers/char_stream/CharStream#) -> Parsedrust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/Parsed#<Sudorust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Sudo#> { |
| 502 | if stream.eat_charrust-analyzer cargo sudo-rs 0.2.14 sudoers/char_stream/impl#[`CharStream<'a>`]eat_char().('@') { |
| 503 | return parse_includerust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/parse_include().(stream); |
| 504 | } |
| 505 | |
| 506 | // the existence of "#include" forces us to handle lines that start with #<ID> explicitly |
| 507 | if stream.peekrust-analyzer cargo sudo-rs 0.2.14 sudoers/char_stream/impl#[`CharStream<'a>`]peek().() 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().Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#('#') { |
| 508 | return if let Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(ident) = try_nonterminalrust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/try_nonterminal().::<Identifierrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Identifier#>(stream) { |
| 509 | let first_user = 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#::Onlyrust-analyzer cargo sudo-rs 0.2.14 sudoers/tokens/Meta#Only#(UserSpecifierrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/UserSpecifier#::Userrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/UserSpecifier#User#(ident))); |
| 510 | let users = if is_syntaxrust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/is_syntax().(',', stream)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch(). { |
| 511 | // parse the rest of the userlist and add the already-parsed user in front |
| 512 | let mut rest = expect_nonterminalrust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/expect_nonterminal().::<SpecListrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/SpecList#<_>>(stream)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 513 | rest.insertrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]insert().(0, first_user); |
| 514 | rest |
| 515 | } else { |
| 516 | vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![first_user] |
| 517 | }; |
| 518 | // no need to check get_directive as no other directive starts with # |
| 519 | let permissions = expect_nonterminalrust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/expect_nonterminal().(stream)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 520 | makerust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/make().(Sudorust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Sudo#::Specrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Sudo#Spec#(PermissionSpecrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/PermissionSpec# { usersrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/PermissionSpec#users., permissionsrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/PermissionSpec#permissions. })) |
| 521 | } else { |
| 522 | // the failed "try_nonterminal::<Identifier>" will have consumed the '#' |
| 523 | // the most ignominious part of sudoers: having to parse bits of comments |
| 524 | parse_includerust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/parse_include().(stream).or_elserust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]or_else().(|_| { |
| 525 | stream.skip_to_newlinerust-analyzer cargo sudo-rs 0.2.14 sudoers/char_stream/impl#[`CharStream<'a>`]skip_to_newline().(); |
| 526 | makerust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/make().(Sudorust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Sudo#::LineCommentrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Sudo#LineComment#) |
| 527 | }) |
| 528 | }; |
| 529 | } |
| 530 | |
| 531 | let start_state = stream.clonerust-analyzer cargo sudo-rs 0.2.14 sudoers/char_stream/impl#[`CharStream<'a>`][Clone]clone().(); |
| 532 | if stream.peekrust-analyzer cargo sudo-rs 0.2.14 sudoers/char_stream/impl#[`CharStream<'a>`]peek().() 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().Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#('"') { |
| 533 | // a quoted userlist follows; this forces us to read a userlist |
| 534 | let users = expect_nonterminalrust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/expect_nonterminal().(stream)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 535 | let permissions = expect_nonterminalrust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/expect_nonterminal().(stream)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 536 | makerust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/make().(Sudorust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Sudo#::Specrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Sudo#Spec#(PermissionSpecrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/PermissionSpec# { usersrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/PermissionSpec#users., permissionsrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/PermissionSpec#permissions. })) |
| 537 | } else if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(users) = mayberust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/maybe().(try_nonterminalrust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/try_nonterminal().::<SpecListrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/SpecList#<_>>(stream))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch(). { |
| 538 | // this could be the start of a Defaults or Alias definition, so distinguish. |
| 539 | // element 1 always exists (parse_list fails on an empty list) |
| 540 | let key = &users[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().0]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().; |
| 541 | let start_pos = start_state.get_posrust-analyzer cargo sudo-rs 0.2.14 sudoers/char_stream/impl#[`CharStream<'a>`]get_pos().(); |
| 542 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(directive) = mayberust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/maybe().(get_directiverust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/get_directive().(key, stream, start_state))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch(). { |
| 543 | if users.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne().1 && directive.could_be_usernamerust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/impl#[Directive]could_be_username().() { |
| 544 | // this is here to guard against User_Alias,foo ALIAS=def being accepted |
| 545 | unrecoverablerust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/unrecoverable!!(pos = start_pos, stream, "ambiguous syntax"); |
| 546 | } |
| 547 | makerust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/make().(Sudorust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Sudo#::Declrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Sudo#Decl#(directive)) |
| 548 | } else { |
| 549 | let permissions = expect_nonterminalrust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/expect_nonterminal().(stream)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 550 | makerust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/make().(Sudorust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Sudo#::Specrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Sudo#Spec#(PermissionSpecrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/PermissionSpec# { usersrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/PermissionSpec#users., permissionsrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/PermissionSpec#permissions. })) |
| 551 | } |
| 552 | } else { |
| 553 | // this will leave whatever could not be parsed on the input stream |
| 554 | makerust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/make().(Sudorust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Sudo#::LineCommentrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Sudo#LineComment#) |
| 555 | } |
| 556 | } |
| 557 | } |
| 558 | |
| 559 | /// Parse the include/include dir part that comes after the '#' or '@' prefix symbol |
| 560 | fn parse_includerust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/parse_include().(stream: &mut CharStreamrust-analyzer cargo sudo-rs 0.2.14 sudoers/char_stream/CharStream#) -> Parsedrust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/Parsed#<Sudorust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Sudo#> { |
| 561 | fn get_pathrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/get_path().(stream: &mut CharStreamrust-analyzer cargo sudo-rs 0.2.14 sudoers/char_stream/CharStream#, key_pos: (usize, usize)) -> Parsedrust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/Parsed#<(Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, Spanrust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/Span#)> { |
| 562 | let path = if stream.eat_charrust-analyzer cargo sudo-rs 0.2.14 sudoers/char_stream/impl#[`CharStream<'a>`]eat_char().('"') { |
| 563 | let QuotedIncludePathrust-analyzer cargo sudo-rs 0.2.14 sudoers/tokens/QuotedIncludePath#(path) = expect_nonterminalrust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/expect_nonterminal().(stream)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 564 | expect_syntaxrust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/expect_syntax().('"', stream)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 565 | path |
| 566 | } else { |
| 567 | let value_pos = stream.get_posrust-analyzer cargo sudo-rs 0.2.14 sudoers/char_stream/impl#[`CharStream<'a>`]get_pos().(); |
| 568 | let IncludePathrust-analyzer cargo sudo-rs 0.2.14 sudoers/tokens/IncludePath#(path) = expect_nonterminalrust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/expect_nonterminal().(stream)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 569 | if stream.peekrust-analyzer cargo sudo-rs 0.2.14 sudoers/char_stream/impl#[`CharStream<'a>`]peek().() 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().Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#('\n') { |
| 570 | unrecoverablerust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/unrecoverable!!( |
| 571 | pos = value_pos, |
| 572 | stream, |
| 573 | "use quotes around filenames or escape whitespace" |
| 574 | ) |
| 575 | } |
| 576 | path |
| 577 | }; |
| 578 | makerust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/make().(( |
| 579 | path, |
| 580 | Spanrust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/Span# { |
| 581 | startrust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/Span#start.: key_pos, |
| 582 | endrust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/Span#end.: stream.get_posrust-analyzer cargo sudo-rs 0.2.14 sudoers/char_stream/impl#[`CharStream<'a>`]get_pos().(), |
| 583 | }, |
| 584 | )) |
| 585 | } |
| 586 | |
| 587 | let key_pos = stream.get_posrust-analyzer cargo sudo-rs 0.2.14 sudoers/char_stream/impl#[`CharStream<'a>`]get_pos().(); |
| 588 | let result = match try_nonterminalrust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/try_nonterminal().(stream)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch(). { |
| 589 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Usernamerust-analyzer cargo sudo-rs 0.2.14 sudoers/tokens/Username#(key)) if key rust-analyzer cargo sudo-rs 0.2.14 common/string/impl#[SudoString][`PartialEq<&str>`]eq().==rust-analyzer cargo sudo-rs 0.2.14 common/string/impl#[SudoString][`PartialEq<&str>`]eq(). rust-analyzer cargo sudo-rs 0.2.14 common/string/impl#[SudoString][`PartialEq<&str>`]eq()."include" => { |
| 590 | let (path, span) = get_pathrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/get_path().(stream, key_pos)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 591 | 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) |
| 592 | } |
| 593 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Usernamerust-analyzer cargo sudo-rs 0.2.14 sudoers/tokens/Username#(key)) if key rust-analyzer cargo sudo-rs 0.2.14 common/string/impl#[SudoString][`PartialEq<&str>`]eq().==rust-analyzer cargo sudo-rs 0.2.14 common/string/impl#[SudoString][`PartialEq<&str>`]eq(). rust-analyzer cargo sudo-rs 0.2.14 common/string/impl#[SudoString][`PartialEq<&str>`]eq()."includedir" => { |
| 594 | let (path, span) = get_pathrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/get_path().(stream, key_pos)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 595 | 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) |
| 596 | } |
| 597 | #[cfg(feature = "unstable-remote-sudoers")] |
| 598 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Usernamerust-analyzer cargo sudo-rs 0.2.14 sudoers/tokens/Username#(key)) if key == "socket" => { |
| 599 | let (path, span) = get_pathrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/get_path().(stream, key_pos)?; |
| 600 | Sudorust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Sudo#::Remote(path, span) |
| 601 | } |
| 602 | _ => unrecoverablerust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/unrecoverable!!(pos = key_pos, stream, "unknown directive"), |
| 603 | }; |
| 604 | |
| 605 | makerust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/make().(result) |
| 606 | } |
| 607 | |
| 608 | fn is_reserved_aliasrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/is_reserved_alias().(name: &str) -> bool { |
| 609 | matchesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/matches!!( |
| 610 | name, |
| 611 | "ALL" | "CHROOT" | "CWD" | "NOTAFTER" | "NOTBEFORE" | "ROLE" | "TIMEOUT" | "TYPE" |
| 612 | ) |
| 613 | } |
| 614 | |
| 615 | /// grammar: |
| 616 | /// ```text |
| 617 | /// name = definition [ : name = definition [ : ... ] ] |
| 618 | /// ``` |
| 619 | /// |
| 620 | impl<T> Parserust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/Parse# for Defrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Def#<T> |
| 621 | where |
| 622 | T: UserFriendlyrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast_names/UserFriendly#, |
| 623 | Metarust-analyzer cargo sudo-rs 0.2.14 sudoers/tokens/Meta#<T>: Parserust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/Parse# + Manyrust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/Many#, |
| 624 | { |
| 625 | fn parserust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/impl#[`Def<T>`][Parse]parse().(stream: &mut CharStreamrust-analyzer cargo sudo-rs 0.2.14 sudoers/char_stream/CharStream#) -> Parsedrust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/Parsed#<Selfrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/impl#[`Def<T>`][Parse]> { |
| 626 | let begin_pos = stream.get_posrust-analyzer cargo sudo-rs 0.2.14 sudoers/char_stream/impl#[`CharStream<'a>`]get_pos().(); |
| 627 | let AliasNamerust-analyzer cargo sudo-rs 0.2.14 sudoers/tokens/AliasName#(name) = try_nonterminalrust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/try_nonterminal().(stream)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 628 | if is_reserved_aliasrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/is_reserved_alias().(&name) { |
| 629 | unrecoverablerust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/unrecoverable!!( |
| 630 | pos = begin_pos, |
| 631 | stream, |
| 632 | "reserved word {} used as an alias name", |
| 633 | name |
| 634 | ); |
| 635 | } |
| 636 | expect_syntaxrust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/expect_syntax().('=', stream)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 637 | |
| 638 | makerust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/make().(Defrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Def#(name, expect_nonterminalrust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/expect_nonterminal().(stream)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().)) |
| 639 | } |
| 640 | } |
| 641 | |
| 642 | impl<T> Manyrust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/Many# for Defrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Def#<T> { |
| 643 | const SEPrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/impl#[`Def<T>`][Many]SEP.: char = ':'; |
| 644 | } |
| 645 | |
| 646 | // NOTE: This function is a bit of a hack, since it relies on the fact that all directives |
| 647 | // occur in the spot of a username, and are of a form that would otherwise be a legal user name. |
| 648 | // I.e. after a valid username has been parsed, we check if it isn't actually a valid start of a |
| 649 | // directive. A more robust solution would be to use the approach taken by the `MetaOrTag` above. |
| 650 | |
| 651 | fn get_directiverust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/get_directive().<'a>( |
| 652 | perhaps_keyword: &Specrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Spec#<UserSpecifierrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/UserSpecifier#>, |
| 653 | stream: &mut CharStreamrust-analyzer cargo sudo-rs 0.2.14 sudoers/char_stream/CharStream#<'a>, |
| 654 | begin_state: CharStreamrust-analyzer cargo sudo-rs 0.2.14 sudoers/char_stream/CharStream#<'a>, |
| 655 | ) -> Parsedrust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/Parsed#<Directiverust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Directive#> { |
| 656 | use superrust-analyzer cargo sudo-rs 0.2.14 sudoers/::astrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/::Directiverust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Directive#::*; |
| 657 | use superrust-analyzer cargo sudo-rs 0.2.14 sudoers/::astrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/::Metarust-analyzer cargo sudo-rs 0.2.14 sudoers/tokens/Meta#::*; |
| 658 | use superrust-analyzer cargo sudo-rs 0.2.14 sudoers/::astrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/::Qualifiedrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Qualified#::*; |
| 659 | use superrust-analyzer cargo sudo-rs 0.2.14 sudoers/::astrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/::UserSpecifierrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/UserSpecifier#::*; |
| 660 | let Allowrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Qualified#Allow#(Onlyrust-analyzer cargo sudo-rs 0.2.14 sudoers/tokens/Meta#Only#(Userrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/UserSpecifier#User#(Identifierrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Identifier#::Namerust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Identifier#Name#(keyword)))) = perhaps_keyword else { |
| 661 | return rejectrust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/reject().(); |
| 662 | }; |
| 663 | |
| 664 | let begin_pos = begin_state.get_posrust-analyzer cargo sudo-rs 0.2.14 sudoers/char_stream/impl#[`CharStream<'a>`]get_pos().(); |
| 665 | |
| 666 | match keyword.as_strrust-analyzer cargo sudo-rs 0.2.14 common/string/impl#[SudoString]as_str().() { |
| 667 | "User_Alias" => makerust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/make().(UserAliasrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Directive#UserAlias#(expect_nonterminalrust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/expect_nonterminal().(stream)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().)), |
| 668 | "Host_Alias" => makerust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/make().(HostAliasrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Directive#HostAlias#(expect_nonterminalrust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/expect_nonterminal().(stream)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().)), |
| 669 | "Cmnd_Alias" | "Cmd_Alias" => makerust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/make().(CmndAliasrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Directive#CmndAlias#(expect_nonterminalrust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/expect_nonterminal().(stream)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().)), |
| 670 | "Runas_Alias" => makerust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/make().(RunasAliasrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Directive#RunasAlias#(expect_nonterminalrust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/expect_nonterminal().(stream)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().)), |
| 671 | _ if keyword.starts_withrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]starts_with().("Defaults") => { |
| 672 | // HACK #1: no space is allowed between "Defaults" and '!>@:'. The below avoids having to |
| 673 | // add "Defaults!" etc as separate tokens; but relying on positional information during |
| 674 | // parsing is of course, cheating. |
| 675 | // HACK #2: '@' can be part of a username, so it will already have been parsed; |
| 676 | // an acceptable hostname is subset of an acceptable username, so that's actually OK. |
| 677 | // This resolves an ambiguity in the grammar similarly to how MetaOrTag does that. |
| 678 | const DEFAULTS_LENrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/DEFAULTS_LEN.: usize = "Defaults".lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]len().(); |
| 679 | let allow_scope_modifier = keyword[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().DEFAULTS_LENrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/DEFAULTS_LEN...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFrom#]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()..starts_withrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]starts_with().('@') |
| 680 | || (stream.get_posrust-analyzer cargo sudo-rs 0.2.14 sudoers/char_stream/impl#[`CharStream<'a>`]get_pos().().0 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().begin_pos.0 |
| 681 | && stream.get_posrust-analyzer cargo sudo-rs 0.2.14 sudoers/char_stream/impl#[`CharStream<'a>`]get_pos().().1 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().begin_pos.1 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().DEFAULTS_LENrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/DEFAULTS_LEN.); |
| 682 | |
| 683 | let scope = if allow_scope_modifier { |
| 684 | if keyword[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().DEFAULTS_LENrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/DEFAULTS_LEN...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFrom#]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()..starts_withrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]starts_with().('@') { |
| 685 | // Backtrack and start parsing following the '@' sign |
| 686 | *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().stream = begin_state; |
| 687 | stream.advancerust-analyzer cargo sudo-rs 0.2.14 sudoers/char_stream/impl#[`CharStream<'a>`]advance().(DEFAULTS_LENrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/DEFAULTS_LEN. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().1); |
| 688 | skip_trailing_whitespacerust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/skip_trailing_whitespace().(stream)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 689 | |
| 690 | ConfigScoperust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/ConfigScope#::Hostrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/ConfigScope#Host#(expect_nonterminalrust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/expect_nonterminal().(stream)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().) |
| 691 | } else if is_syntaxrust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/is_syntax().(':', stream)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch(). { |
| 692 | ConfigScoperust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/ConfigScope#::Userrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/ConfigScope#User#(expect_nonterminalrust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/expect_nonterminal().(stream)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().) |
| 693 | } else if is_syntaxrust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/is_syntax().('!', stream)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch(). { |
| 694 | ConfigScoperust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/ConfigScope#::Commandrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/ConfigScope#Command#(expect_nonterminalrust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/expect_nonterminal().(stream)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().) |
| 695 | } else if is_syntaxrust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/is_syntax().('>', stream)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch(). { |
| 696 | ConfigScoperust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/ConfigScope#::RunAsrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/ConfigScope#RunAs#(expect_nonterminalrust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/expect_nonterminal().(stream)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().) |
| 697 | } else { |
| 698 | ConfigScoperust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/ConfigScope#::Genericrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/ConfigScope#Generic# |
| 699 | } |
| 700 | } else { |
| 701 | ConfigScoperust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/ConfigScope#::Genericrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/ConfigScope#Generic# |
| 702 | }; |
| 703 | |
| 704 | makerust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/make().(Defaultsrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Directive#Defaults#(expect_nonterminalrust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/expect_nonterminal().(stream)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch()., scope)) |
| 705 | } |
| 706 | _ => rejectrust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/reject().(), |
| 707 | } |
| 708 | } |
| 709 | |
| 710 | /// grammar: |
| 711 | /// ```text |
| 712 | /// parameter = name [+-]?= ... |
| 713 | /// ``` |
| 714 | impl Parserust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/Parse# for defaultsrust-analyzer cargo sudo-rs 0.2.14 defaults/::SettingsModifierrust-analyzer cargo sudo-rs 0.2.14 defaults/SettingsModifier# { |
| 715 | fn parserust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/impl#[`Box<dyn FnOnce(&mut defaults::Settings) + 'static>`][Parse]parse().(stream: &mut CharStreamrust-analyzer cargo sudo-rs 0.2.14 sudoers/char_stream/CharStream#) -> Parsedrust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/Parsed#<Selfrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/impl#[`Box<dyn FnOnce(&mut defaults::Settings) + 'static>`][Parse]> { |
| 716 | let id_pos = stream.get_posrust-analyzer cargo sudo-rs 0.2.14 sudoers/char_stream/impl#[`CharStream<'a>`]get_pos().(); |
| 717 | |
| 718 | // Parse multiple entries enclosed in quotes (for list-like Defaults-settings) |
| 719 | let parse_vars = |stream: &mut CharStreamrust-analyzer cargo sudo-rs 0.2.14 sudoers/char_stream/CharStream#| -> Parsedrust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/Parsed#<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>> { |
| 720 | if stream.eat_charrust-analyzer cargo sudo-rs 0.2.14 sudoers/char_stream/impl#[`CharStream<'a>`]eat_char().('"') { |
| 721 | let mut result = Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]new().(); |
| 722 | while let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(EnvVarrust-analyzer cargo sudo-rs 0.2.14 sudoers/tokens/EnvVar#(name)) = try_nonterminalrust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/try_nonterminal().(stream)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch(). { |
| 723 | if is_syntaxrust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/is_syntax().('=', stream)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch(). { |
| 724 | let StringParameterrust-analyzer cargo sudo-rs 0.2.14 sudoers/tokens/StringParameter#(value) = expect_nonterminalrust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/expect_nonterminal().(stream)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 725 | result.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(name rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`Add<&str>`]add().+rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`Add<&str>`]add(). rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`Add<&str>`]add()."=" rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Add#add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Add#add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Add#add().&value); |
| 726 | } else { |
| 727 | result.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(name); |
| 728 | } |
| 729 | if result.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().Identifierrust-analyzer cargo sudo-rs 0.2.14 sudoers/ast/Identifier#::LIMITrust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/Many#LIMIT. { |
| 730 | unrecoverablerust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/unrecoverable!!(stream, "environment variable list too long") |
| 731 | } |
| 732 | } |
| 733 | expect_syntaxrust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/expect_syntax().('"', stream)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 734 | if result.is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]is_empty().() { |
| 735 | unrecoverablerust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/unrecoverable!!(stream, "empty string not allowed"); |
| 736 | } |
| 737 | |
| 738 | makerust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/make().(result) |
| 739 | } else { |
| 740 | let EnvVarrust-analyzer cargo sudo-rs 0.2.14 sudoers/tokens/EnvVar#(name) = expect_nonterminalrust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/expect_nonterminal().(stream)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 741 | if is_syntaxrust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/is_syntax().('=', stream)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch(). { |
| 742 | unrecoverablerust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/unrecoverable!!(stream, "double quotes are required for VAR=value pairs") |
| 743 | } else { |
| 744 | makerust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/make().(vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![name]) |
| 745 | } |
| 746 | } |
| 747 | }; |
| 748 | |
| 749 | // Parse the remainder of a list variable |
| 750 | let list_items = |
| 751 | |mode: defaultsrust-analyzer cargo sudo-rs 0.2.14 defaults/::ListModerust-analyzer cargo sudo-rs 0.2.14 defaults/ListMode#, name: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, cfg: defaultsrust-analyzer cargo sudo-rs 0.2.14 defaults/::SettingKindrust-analyzer cargo sudo-rs 0.2.14 defaults/SettingKind#, stream: &mut _| { |
| 752 | expect_syntaxrust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/expect_syntax().('=', stream)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 753 | let defaultsrust-analyzer cargo sudo-rs 0.2.14 defaults/::SettingKindrust-analyzer cargo sudo-rs 0.2.14 defaults/SettingKind#::Listrust-analyzer cargo sudo-rs 0.2.14 defaults/SettingKind#List#(checker) = cfg else { |
| 754 | unrecoverablerust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/unrecoverable!!(pos = id_pos, stream, "{name} is not a list parameter"); |
| 755 | }; |
| 756 | |
| 757 | makerust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/make().(checker(mode, parse_vars(stream)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().)) |
| 758 | }; |
| 759 | |
| 760 | // Parse a text parameter |
| 761 | let text_item = |stream: &mut CharStreamrust-analyzer cargo sudo-rs 0.2.14 sudoers/char_stream/CharStream#| { |
| 762 | if stream.eat_charrust-analyzer cargo sudo-rs 0.2.14 sudoers/char_stream/impl#[`CharStream<'a>`]eat_char().('"') { |
| 763 | let QuotedStringParameterrust-analyzer cargo sudo-rs 0.2.14 sudoers/tokens/QuotedStringParameter#(text) = expect_nonterminalrust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/expect_nonterminal().(stream)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 764 | expect_syntaxrust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/expect_syntax().('"', stream)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 765 | makerust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/make().(text) |
| 766 | } else { |
| 767 | let StringParameterrust-analyzer cargo sudo-rs 0.2.14 sudoers/tokens/StringParameter#(name) = expect_nonterminalrust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/expect_nonterminal().(stream)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 768 | makerust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/make().(name) |
| 769 | } |
| 770 | }; |
| 771 | |
| 772 | if is_syntaxrust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/is_syntax().('!', stream)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch(). { |
| 773 | let value_pos = stream.get_posrust-analyzer cargo sudo-rs 0.2.14 sudoers/char_stream/impl#[`CharStream<'a>`]get_pos().(); |
| 774 | let DefaultNamerust-analyzer cargo sudo-rs 0.2.14 sudoers/tokens/DefaultName#(name) = expect_nonterminalrust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/expect_nonterminal().(stream)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 775 | let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(modifier) = defaultsrust-analyzer cargo sudo-rs 0.2.14 defaults/::negaterust-analyzer cargo sudo-rs 0.2.14 defaults/negate().(&name) else { |
| 776 | if defaultsrust-analyzer cargo sudo-rs 0.2.14 defaults/::setrust-analyzer cargo sudo-rs 0.2.14 defaults/set().(&name).is_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some().() { |
| 777 | unrecoverablerust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/unrecoverable!!( |
| 778 | pos = value_pos, |
| 779 | stream, |
| 780 | "'{name}' cannot be used in a boolean context" |
| 781 | ); |
| 782 | } else { |
| 783 | unrecoverablerust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/unrecoverable!!(pos = value_pos, stream, "unknown setting: '{name}'"); |
| 784 | } |
| 785 | }; |
| 786 | |
| 787 | makerust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/make().(modifier) |
| 788 | } else { |
| 789 | let DefaultNamerust-analyzer cargo sudo-rs 0.2.14 sudoers/tokens/DefaultName#(name) = try_nonterminalrust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/try_nonterminal().(stream)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 790 | let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(cfg) = defaultsrust-analyzer cargo sudo-rs 0.2.14 defaults/::setrust-analyzer cargo sudo-rs 0.2.14 defaults/set().(&name) else { |
| 791 | unrecoverablerust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/unrecoverable!!(pos = id_pos, stream, "unknown setting: '{name}'"); |
| 792 | }; |
| 793 | |
| 794 | if is_syntaxrust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/is_syntax().('+', stream)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch(). { |
| 795 | list_items(defaultsrust-analyzer cargo sudo-rs 0.2.14 defaults/::ListModerust-analyzer cargo sudo-rs 0.2.14 defaults/ListMode#::Addrust-analyzer cargo sudo-rs 0.2.14 defaults/ListMode#Add#, name, cfg, stream) |
| 796 | } else if is_syntaxrust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/is_syntax().('-', stream)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch(). { |
| 797 | list_items(defaultsrust-analyzer cargo sudo-rs 0.2.14 defaults/::ListModerust-analyzer cargo sudo-rs 0.2.14 defaults/ListMode#::Delrust-analyzer cargo sudo-rs 0.2.14 defaults/ListMode#Del#, name, cfg, stream) |
| 798 | } else if is_syntaxrust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/is_syntax().('=', stream)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch(). { |
| 799 | let value_pos = stream.get_posrust-analyzer cargo sudo-rs 0.2.14 sudoers/char_stream/impl#[`CharStream<'a>`]get_pos().(); |
| 800 | match cfg { |
| 801 | defaultsrust-analyzer cargo sudo-rs 0.2.14 defaults/::SettingKindrust-analyzer cargo sudo-rs 0.2.14 defaults/SettingKind#::Flagrust-analyzer cargo sudo-rs 0.2.14 defaults/SettingKind#Flag#(_) => { |
| 802 | unrecoverablerust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/unrecoverable!!(stream, "can't assign to boolean setting '{name}'") |
| 803 | } |
| 804 | defaultsrust-analyzer cargo sudo-rs 0.2.14 defaults/::SettingKindrust-analyzer cargo sudo-rs 0.2.14 defaults/SettingKind#::Integerrust-analyzer cargo sudo-rs 0.2.14 defaults/SettingKind#Integer#(checker) => { |
| 805 | let Numericrust-analyzer cargo sudo-rs 0.2.14 sudoers/tokens/Numeric#(denotation) = expect_nonterminalrust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/expect_nonterminal().(stream)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 806 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(modifier) = checker(&denotation) { |
| 807 | makerust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/make().(modifier) |
| 808 | } else { |
| 809 | unrecoverablerust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/unrecoverable!!( |
| 810 | pos = value_pos, |
| 811 | stream, |
| 812 | "'{denotation}' is not a valid value for {name}" |
| 813 | ); |
| 814 | } |
| 815 | } |
| 816 | defaultsrust-analyzer cargo sudo-rs 0.2.14 defaults/::SettingKindrust-analyzer cargo sudo-rs 0.2.14 defaults/SettingKind#::Listrust-analyzer cargo sudo-rs 0.2.14 defaults/SettingKind#List#(checker) => { |
| 817 | let items = parse_vars(stream)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 818 | |
| 819 | makerust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/make().(checker(defaultsrust-analyzer cargo sudo-rs 0.2.14 defaults/::ListModerust-analyzer cargo sudo-rs 0.2.14 defaults/ListMode#::Setrust-analyzer cargo sudo-rs 0.2.14 defaults/ListMode#Set#, items)) |
| 820 | } |
| 821 | defaultsrust-analyzer cargo sudo-rs 0.2.14 defaults/::SettingKindrust-analyzer cargo sudo-rs 0.2.14 defaults/SettingKind#::Textrust-analyzer cargo sudo-rs 0.2.14 defaults/SettingKind#Text#(checker) => { |
| 822 | let text = text_item(stream)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 823 | let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(modifier) = checker(&text) else { |
| 824 | unrecoverablerust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/unrecoverable!!( |
| 825 | pos = value_pos, |
| 826 | stream, |
| 827 | "'{text}' is not a valid value for {name}" |
| 828 | ); |
| 829 | }; |
| 830 | makerust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/make().(modifier) |
| 831 | } |
| 832 | } |
| 833 | } else { |
| 834 | let defaultsrust-analyzer cargo sudo-rs 0.2.14 defaults/::SettingKindrust-analyzer cargo sudo-rs 0.2.14 defaults/SettingKind#::Flagrust-analyzer cargo sudo-rs 0.2.14 defaults/SettingKind#Flag#(modifier) = cfg else { |
| 835 | unrecoverablerust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/unrecoverable!!(pos = id_pos, stream, "'{name}' is not a boolean setting"); |
| 836 | }; |
| 837 | |
| 838 | makerust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/make().(modifier) |
| 839 | } |
| 840 | } |
| 841 | } |
| 842 | } |
| 843 | |
| 844 | impl Manyrust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/Many# for defaultsrust-analyzer cargo sudo-rs 0.2.14 defaults/::SettingsModifierrust-analyzer cargo sudo-rs 0.2.14 defaults/SettingsModifier# {} |