feat(aa): parse apparmor preamble files.

This commit is contained in:
Alexandre Pujol 2024-05-27 18:55:21 +01:00
parent 2e043d4ec8
commit a99387c323
No known key found for this signature in database
GPG key ID: C5469996F0DF68EC
6 changed files with 710 additions and 8 deletions

View file

@ -153,19 +153,12 @@ func validateValues(rule string, key string, values []string) error {
// Helper function to convert a string to a slice of rule values according to
// the rule requirements as defined in the requirements map.
func toValues(rule string, key string, input string) ([]string, error) {
var sep string
req, ok := requirements[rule][key]
if !ok {
return nil, fmt.Errorf("unrecognized requirement '%s' for rule %s", key, rule)
}
switch {
case strings.Contains(input, ","):
sep = ","
case strings.Contains(input, " "):
sep = " "
}
res := strings.Split(input, sep)
res := tokenToSlice(input)
for idx := range res {
res[idx] = strings.Trim(res[idx], `" `)
if !slices.Contains(req, res[idx]) {