feat(aa): add new formatting methods to the rule interface.
This commit is contained in:
parent
d9bbdb77fa
commit
8b24f3521d
2 changed files with 44 additions and 9 deletions
|
|
@ -13,10 +13,8 @@ type Base struct {
|
||||||
Comment string
|
Comment string
|
||||||
NoNewPrivs bool
|
NoNewPrivs bool
|
||||||
FileInherit bool
|
FileInherit bool
|
||||||
Prefix string
|
|
||||||
Padding string
|
|
||||||
Suffix string
|
|
||||||
Optional bool
|
Optional bool
|
||||||
|
Paddings []string
|
||||||
}
|
}
|
||||||
|
|
||||||
func newBase(rule rule) Base {
|
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 {
|
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 != "" {
|
if other.Comment != "" {
|
||||||
r.Comment += " " + other.Comment
|
r.Comment += " " + other.Comment
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (r Base) addLine(other Rule) bool {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
type Qualifier struct {
|
type Qualifier struct {
|
||||||
Audit bool
|
Audit bool
|
||||||
AccessType string
|
AccessType string
|
||||||
|
|
@ -109,3 +121,22 @@ func (r Qualifier) Compare(o Qualifier) int {
|
||||||
func (r Qualifier) Equal(o Qualifier) bool {
|
func (r Qualifier) Equal(o Qualifier) bool {
|
||||||
return r.Audit == o.Audit && r.AccessType == o.AccessType
|
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},
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -37,12 +37,16 @@ func (k Kind) Tok() string {
|
||||||
|
|
||||||
// Rule generic interface for all AppArmor rules
|
// Rule generic interface for all AppArmor rules
|
||||||
type Rule interface {
|
type Rule interface {
|
||||||
Kind() Kind // Kind of the rule
|
Kind() Kind // Kind of the rule
|
||||||
Constraint() Constraint // Where the rule can be found (preamble, profile, any)
|
Constraint() Constraint // Where the rule can be found (preamble, profile, any)
|
||||||
String() string // Render the rule as a string
|
String() string // Render the rule as a string
|
||||||
Validate() error // Validate the rule. Return an error if the rule is invalid
|
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
|
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
|
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
|
type Rules []Rule
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue