mirror of
https://github.com/roddhjav/apparmor.d.git
synced 2024-11-14 23:43:56 +01:00
feat(aa): add new formatting methods to the rule interface.
This commit is contained in:
parent
d9bbdb77fa
commit
8b24f3521d
@ -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},
|
||||
)
|
||||
}
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user