diff --git a/pkg/aa/base.go b/pkg/aa/base.go index 6e40e46d..96746652 100644 --- a/pkg/aa/base.go +++ b/pkg/aa/base.go @@ -13,10 +13,8 @@ type Base struct { Comment string NoNewPrivs bool FileInherit bool - Prefix string - Padding string - Suffix string Optional bool + Paddings []string } func newBase(rule rule) Base { @@ -79,13 +77,27 @@ func newBaseFromLog(log map[string]string) Base { } } +func (r Base) Padding(i int) string { + if i >= len(r.Paddings) { + return "" + } + return r.Paddings[i] +} + func (r *Base) merge(other Base) bool { + r.NoNewPrivs = r.NoNewPrivs || other.NoNewPrivs + r.FileInherit = r.FileInherit || other.FileInherit + r.Optional = r.Optional || other.Optional if other.Comment != "" { r.Comment += " " + other.Comment } return true } +func (r Base) addLine(other Rule) bool { + return false +} + type Qualifier struct { Audit bool AccessType string @@ -109,3 +121,22 @@ func (r Qualifier) Compare(o Qualifier) int { func (r Qualifier) Equal(o Qualifier) bool { return r.Audit == o.Audit && r.AccessType == o.AccessType } + +func (r Qualifier) getLenAudit() int { + return length("audit", r.Audit) +} + +func (r Qualifier) getLenAccess() int { + lenAccess := 0 + if r.AccessType != "" { + lenAccess = length("", r.AccessType) + } + return lenAccess +} + +func (r Qualifier) setPaddings(max []int) []string { + return setPaddings(max, + []string{"audit", ""}, + []any{r.Audit, r.AccessType}, + ) +} diff --git a/pkg/aa/rules.go b/pkg/aa/rules.go index 077a6506..8ab469aa 100644 --- a/pkg/aa/rules.go +++ b/pkg/aa/rules.go @@ -37,12 +37,16 @@ func (k Kind) Tok() string { // Rule generic interface for all AppArmor rules type Rule interface { - Kind() Kind // Kind of the rule - Constraint() Constraint // Where the rule can be found (preamble, profile, any) - String() string // Render the rule as a string - Validate() error // Validate the rule. Return an error if the rule is invalid - Compare(other Rule) int // Compare two rules. Return 0 if they are identical - Merge(other Rule) bool // Merge rules of same kind together. Return true if merged + Kind() Kind // Kind of the rule + Constraint() Constraint // Where the rule can be found (preamble, profile, any) + String() string // Render the rule as a string + Validate() error // Validate the rule. Return an error if the rule is invalid + Compare(other Rule) int // Compare two rules. Return 0 if they are identical + Merge(other Rule) bool // Merge rules of same kind together. Return true if merged + Padding(i int) string // Padding for rule items at index i + Lengths() []int // Length of each item in the rule + setPaddings(max []int) // Set paddings for each item in the rule + addLine(other Rule) bool // Check either a new line should be added before the rule } type Rules []Rule