refractor(aa): move profile specific method to the profile struct.
This commit is contained in:
parent
120db93396
commit
2923df2a73
3 changed files with 89 additions and 63 deletions
|
|
@ -5,6 +5,8 @@
|
|||
package aa
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"sort"
|
||||
"strings"
|
||||
)
|
||||
|
||||
|
|
@ -28,8 +30,29 @@ func (r Rules) String() string {
|
|||
return renderTemplate("rules", r)
|
||||
}
|
||||
|
||||
// Sort the rules in a profile.
|
||||
// Follow: https://apparmor.pujol.io/development/guidelines/#guidelines
|
||||
func (r Rules) Sort() {
|
||||
sort.Slice(r, func(i, j int) bool {
|
||||
typeOfI := reflect.TypeOf(r[i])
|
||||
typeOfJ := reflect.TypeOf(r[j])
|
||||
if typeOfI != typeOfJ {
|
||||
valueOfI := typeToValue(typeOfI)
|
||||
valueOfJ := typeToValue(typeOfJ)
|
||||
if typeOfI == reflect.TypeOf((*Include)(nil)) && r[i].(*Include).IfExists {
|
||||
valueOfI = "include_if_exists"
|
||||
}
|
||||
if typeOfJ == reflect.TypeOf((*Include)(nil)) && r[j].(*Include).IfExists {
|
||||
valueOfJ = "include_if_exists"
|
||||
}
|
||||
return ruleWeights[valueOfI] < ruleWeights[valueOfJ]
|
||||
}
|
||||
return r[i].Less(r[j])
|
||||
})
|
||||
}
|
||||
|
||||
type RuleBase struct {
|
||||
IsLineRule bool
|
||||
Comment string
|
||||
NoNewPrivs bool
|
||||
FileInherit bool
|
||||
|
|
@ -67,6 +90,7 @@ func newRuleFromLog(log map[string]string) RuleBase {
|
|||
}
|
||||
|
||||
return RuleBase{
|
||||
IsLineRule: false,
|
||||
Comment: msg,
|
||||
NoNewPrivs: noNewPrivs,
|
||||
FileInherit: fileInherit,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue