Debian Codegraph @

src/sudoers/ast_names.rs

raw symbols SCIP
1 //! This module contains user-friendly names for the various items in the AST, to report in case they are missing
2
3 pub trait UserFriendly {
4 const DESCRIPTION: &'static str;
5 }
6
7 // this is in a submodule so it can be switched off and replaced by a blanket implementation for test-cases
8 #[cfg(not(test))]
9 mod names {
10 use super::*;
11 use crate::defaults;
12 use crate::sudoers::ast::*;
13 use crate::sudoers::tokens;
14
15 impl UserFriendly for tokens::DigitsU32 {
16 const DESCRIPTION: &'static str = "number";
17 }
18
19 impl UserFriendly for tokens::Numeric {
20 const DESCRIPTION: &'static str = "nonnegative number";
21 }
22
23 impl UserFriendly for Identifier {
24 const DESCRIPTION: &'static str = "identifier";
25 }
26
27 impl<T: UserFriendly> UserFriendly for Vec<T> {
28 const DESCRIPTION: &'static str = T::DESCRIPTION;
29 }
30
31 impl<T: UserFriendly> UserFriendly for tokens::Meta<T> {
32 const DESCRIPTION: &'static str = T::DESCRIPTION;
33 }
34
35 impl<T: UserFriendly> UserFriendly for Qualified<T> {
36 const DESCRIPTION: &'static str = T::DESCRIPTION;
37 }
38
39 impl UserFriendly for tokens::Command {
40 const DESCRIPTION: &'static str = "path to binary (or sudoedit)";
41 }
42
43 impl UserFriendly for tokens::SimpleCommand {
44 const DESCRIPTION: &'static str = "path to binary (or sudoedit)";
45 }
46
47 impl UserFriendly
48 for (
49 SpecList<tokens::Hostname>,
50 Vec<(Option<RunAs>, CommandSpec)>,
51 )
52 {
53 const DESCRIPTION: &'static str = tokens::Hostname::DESCRIPTION;
54 }
55
56 impl UserFriendly for (Option<RunAs>, CommandSpec) {
57 const DESCRIPTION: &'static str = "(users:groups) specification";
58 }
59
60 // this can never happen, as parse<Sudo> always succeeds
61 impl UserFriendly for Sudo {
62 const DESCRIPTION: &'static str = "nothing";
63 }
64
65 impl UserFriendly for UserSpecifier {
66 const DESCRIPTION: &'static str = "user";
67 }
68 impl UserFriendly for tokens::Username {
69 const DESCRIPTION: &'static str = "user";
70 }
71
72 impl UserFriendly for tokens::Hostname {
73 const DESCRIPTION: &'static str = "host name";
74 }
75
76 impl UserFriendly for tokens::QuotedStringParameter {
77 const DESCRIPTION: &'static str = "non-empty string";
78 }
79
80 impl UserFriendly for tokens::QuotedIncludePath {
81 const DESCRIPTION: &'static str = "non-empty string";
82 }
83
84 impl UserFriendly for tokens::StringParameter {
85 const DESCRIPTION: &'static str = tokens::QuotedStringParameter::DESCRIPTION;
86 }
87
88 impl UserFriendly for tokens::IncludePath {
89 const DESCRIPTION: &'static str = "path to file";
90 }
91
92 impl UserFriendly for tokens::AliasName {
93 const DESCRIPTION: &'static str = "alias name";
94 }
95
96 impl UserFriendly for tokens::DefaultName {
97 const DESCRIPTION: &'static str = "configuration option";
98 }
99
100 impl UserFriendly for tokens::EnvVar {
101 const DESCRIPTION: &'static str = "environment variable";
102 }
103
104 impl UserFriendly for CommandSpec {
105 const DESCRIPTION: &'static str = tokens::Command::DESCRIPTION;
106 }
107
108 impl UserFriendly for tokens::ChDir {
109 const DESCRIPTION: &'static str = "directory or '*'";
110 }
111
112 impl UserFriendly for defaults::SettingsModifier {
113 const DESCRIPTION: &'static str = "parameter";
114 }
115
116 impl<T> UserFriendly for Def<T> {
117 const DESCRIPTION: &'static str = "alias definition";
118 }
119
120 impl<T: UserFriendly> UserFriendly for tokens::Unquoted<T> {
121 const DESCRIPTION: &'static str = T::DESCRIPTION;
122 }
123 }
124
125 #[cfg(test)]
126 impl<T: super::basic_parser::Parse> UserFriendly for T {
127 const DESCRIPTION: &'static str = "elem";
128 }