chore(aa): minor cosmetic of the rule interface.
This commit is contained in:
parent
86b2f74a24
commit
191c72fcb6
20 changed files with 62 additions and 62 deletions
|
|
@ -20,8 +20,8 @@ func (r *All) Kind() Kind {
|
||||||
return ALL
|
return ALL
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *All) Constraint() constraint {
|
func (r *All) Constraint() Constraint {
|
||||||
return blockKind
|
return BlockRule
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *All) String() string {
|
func (r *All) String() string {
|
||||||
|
|
|
||||||
|
|
@ -19,8 +19,8 @@ func (p *Hat) Kind() Kind {
|
||||||
return HAT
|
return HAT
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Hat) Constraint() constraint {
|
func (p *Hat) Constraint() Constraint {
|
||||||
return blockKind
|
return BlockRule
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Hat) String() string {
|
func (p *Hat) String() string {
|
||||||
|
|
|
||||||
|
|
@ -55,8 +55,8 @@ func (r *Capability) Kind() Kind {
|
||||||
return CAPABILITY
|
return CAPABILITY
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Capability) Constraint() constraint {
|
func (r *Capability) Constraint() Constraint {
|
||||||
return blockKind
|
return BlockRule
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Capability) String() string {
|
func (r *Capability) String() string {
|
||||||
|
|
|
||||||
|
|
@ -71,8 +71,8 @@ func (r *ChangeProfile) Kind() Kind {
|
||||||
return CHANGEPROFILE
|
return CHANGEPROFILE
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *ChangeProfile) Constraint() constraint {
|
func (r *ChangeProfile) Constraint() Constraint {
|
||||||
return blockKind
|
return BlockRule
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *ChangeProfile) String() string {
|
func (r *ChangeProfile) String() string {
|
||||||
|
|
|
||||||
|
|
@ -78,8 +78,8 @@ func (r *Dbus) Kind() Kind {
|
||||||
return DBUS
|
return DBUS
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Dbus) Constraint() constraint {
|
func (r *Dbus) Constraint() Constraint {
|
||||||
return blockKind
|
return BlockRule
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Dbus) String() string {
|
func (r *Dbus) String() string {
|
||||||
|
|
|
||||||
|
|
@ -107,8 +107,8 @@ func (r *File) Kind() Kind {
|
||||||
return FILE
|
return FILE
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *File) Constraint() constraint {
|
func (r *File) Constraint() Constraint {
|
||||||
return blockKind
|
return BlockRule
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *File) String() string {
|
func (r *File) String() string {
|
||||||
|
|
@ -213,8 +213,8 @@ func (r *Link) Kind() Kind {
|
||||||
return LINK
|
return LINK
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Link) Constraint() constraint {
|
func (r *Link) Constraint() Constraint {
|
||||||
return blockKind
|
return BlockRule
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Link) String() string {
|
func (r *Link) String() string {
|
||||||
|
|
|
||||||
|
|
@ -49,8 +49,8 @@ func (r *IOUring) Kind() Kind {
|
||||||
return IOURING
|
return IOURING
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *IOUring) Constraint() constraint {
|
func (r *IOUring) Constraint() Constraint {
|
||||||
return blockKind
|
return BlockRule
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *IOUring) String() string {
|
func (r *IOUring) String() string {
|
||||||
|
|
|
||||||
|
|
@ -124,8 +124,8 @@ func (r *Mount) Kind() Kind {
|
||||||
return MOUNT
|
return MOUNT
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Mount) Constraint() constraint {
|
func (r *Mount) Constraint() Constraint {
|
||||||
return blockKind
|
return BlockRule
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Mount) String() string {
|
func (r *Mount) String() string {
|
||||||
|
|
@ -206,8 +206,8 @@ func (r *Umount) Kind() Kind {
|
||||||
return UMOUNT
|
return UMOUNT
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Umount) Constraint() constraint {
|
func (r *Umount) Constraint() Constraint {
|
||||||
return blockKind
|
return BlockRule
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Umount) String() string {
|
func (r *Umount) String() string {
|
||||||
|
|
@ -285,8 +285,8 @@ func (r *Remount) Kind() Kind {
|
||||||
return REMOUNT
|
return REMOUNT
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Remount) Constraint() constraint {
|
func (r *Remount) Constraint() Constraint {
|
||||||
return blockKind
|
return BlockRule
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Remount) String() string {
|
func (r *Remount) String() string {
|
||||||
|
|
|
||||||
|
|
@ -77,8 +77,8 @@ func (r *Mqueue) Kind() Kind {
|
||||||
return MQUEUE
|
return MQUEUE
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Mqueue) Constraint() constraint {
|
func (r *Mqueue) Constraint() Constraint {
|
||||||
return blockKind
|
return BlockRule
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Mqueue) String() string {
|
func (r *Mqueue) String() string {
|
||||||
|
|
|
||||||
|
|
@ -103,8 +103,8 @@ func (r *Network) Kind() Kind {
|
||||||
return NETWORK
|
return NETWORK
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Network) Constraint() constraint {
|
func (r *Network) Constraint() Constraint {
|
||||||
return blockKind
|
return BlockRule
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Network) String() string {
|
func (r *Network) String() string {
|
||||||
|
|
|
||||||
|
|
@ -188,7 +188,7 @@ func parseParagraph(input string) (Rules, error) {
|
||||||
|
|
||||||
res = append(res, rrr...)
|
res = append(res, rrr...)
|
||||||
for _, r := range res {
|
for _, r := range res {
|
||||||
if r.Constraint() == preambleKind {
|
if r.Constraint() == PreambleRule {
|
||||||
return nil, fmt.Errorf("Rule not allowed in block: %s", r)
|
return nil, fmt.Errorf("Rule not allowed in block: %s", r)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -588,7 +588,7 @@ func (f *AppArmorProfileFile) parsePreamble(preamble string) error {
|
||||||
f.Preamble = append(f.Preamble, commaRules...)
|
f.Preamble = append(f.Preamble, commaRules...)
|
||||||
|
|
||||||
for _, r := range f.Preamble {
|
for _, r := range f.Preamble {
|
||||||
if r.Constraint() == blockKind {
|
if r.Constraint() == BlockRule {
|
||||||
f.Preamble = nil
|
f.Preamble = nil
|
||||||
return fmt.Errorf("Rule not allowed in preamble: %s", r)
|
return fmt.Errorf("Rule not allowed in preamble: %s", r)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -54,8 +54,8 @@ func (r *PivotRoot) Kind() Kind {
|
||||||
return PIVOTROOT
|
return PIVOTROOT
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *PivotRoot) Constraint() constraint {
|
func (r *PivotRoot) Constraint() Constraint {
|
||||||
return blockKind
|
return BlockRule
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *PivotRoot) String() string {
|
func (r *PivotRoot) String() string {
|
||||||
|
|
|
||||||
|
|
@ -33,8 +33,8 @@ func (r *Comment) Kind() Kind {
|
||||||
return COMMENT
|
return COMMENT
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Comment) Constraint() constraint {
|
func (r *Comment) Constraint() Constraint {
|
||||||
return anyKind
|
return AnyRule
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Comment) String() string {
|
func (r *Comment) String() string {
|
||||||
|
|
@ -85,8 +85,8 @@ func (r *Abi) Kind() Kind {
|
||||||
return ABI
|
return ABI
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Abi) Constraint() constraint {
|
func (r *Abi) Constraint() Constraint {
|
||||||
return preambleKind
|
return PreambleRule
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Abi) String() string {
|
func (r *Abi) String() string {
|
||||||
|
|
@ -133,8 +133,8 @@ func (r *Alias) Kind() Kind {
|
||||||
return ALIAS
|
return ALIAS
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Alias) Constraint() constraint {
|
func (r *Alias) Constraint() Constraint {
|
||||||
return preambleKind
|
return PreambleRule
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Alias) String() string {
|
func (r *Alias) String() string {
|
||||||
|
|
@ -200,8 +200,8 @@ func (r *Include) Kind() Kind {
|
||||||
return INCLUDE
|
return INCLUDE
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Include) Constraint() constraint {
|
func (r *Include) Constraint() Constraint {
|
||||||
return anyKind
|
return AnyRule
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Include) String() string {
|
func (r *Include) String() string {
|
||||||
|
|
@ -272,8 +272,8 @@ func (r *Variable) Kind() Kind {
|
||||||
return VARIABLE
|
return VARIABLE
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Variable) Constraint() constraint {
|
func (r *Variable) Constraint() Constraint {
|
||||||
return preambleKind
|
return PreambleRule
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Variable) String() string {
|
func (r *Variable) String() string {
|
||||||
|
|
|
||||||
|
|
@ -73,8 +73,8 @@ func (p *Profile) Kind() Kind {
|
||||||
return PROFILE
|
return PROFILE
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Profile) Constraint() constraint {
|
func (p *Profile) Constraint() Constraint {
|
||||||
return blockKind
|
return BlockRule
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Profile) String() string {
|
func (p *Profile) String() string {
|
||||||
|
|
|
||||||
|
|
@ -51,8 +51,8 @@ func (r *Ptrace) Kind() Kind {
|
||||||
return PTRACE
|
return PTRACE
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Ptrace) Constraint() constraint {
|
func (r *Ptrace) Constraint() Constraint {
|
||||||
return blockKind
|
return BlockRule
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Ptrace) String() string {
|
func (r *Ptrace) String() string {
|
||||||
|
|
|
||||||
|
|
@ -55,8 +55,8 @@ func (r *Rlimit) Kind() Kind {
|
||||||
return RLIMIT
|
return RLIMIT
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Rlimit) Constraint() constraint {
|
func (r *Rlimit) Constraint() Constraint {
|
||||||
return blockKind
|
return BlockRule
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Rlimit) String() string {
|
func (r *Rlimit) String() string {
|
||||||
|
|
|
||||||
|
|
@ -13,12 +13,12 @@ import (
|
||||||
|
|
||||||
type requirement map[string][]string
|
type requirement map[string][]string
|
||||||
|
|
||||||
type constraint uint
|
type Constraint uint
|
||||||
|
|
||||||
const (
|
const (
|
||||||
anyKind constraint = iota // The rule can be found in either preamble or profile
|
AnyRule Constraint = iota // The rule can be found in either preamble or profile
|
||||||
preambleKind // The rule can only be found in the preamble
|
PreambleRule // The rule can only be found in the preamble
|
||||||
blockKind // The rule can only be found in a profile
|
BlockRule // The rule can only be found in a profile
|
||||||
)
|
)
|
||||||
|
|
||||||
// Kind represents an AppArmor rule kind.
|
// Kind represents an AppArmor rule kind.
|
||||||
|
|
@ -37,12 +37,12 @@ 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() Kind // Kind of the rule
|
||||||
Constraint() constraint
|
Constraint() Constraint // Where the rule can be found (preamble, profile, any)
|
||||||
String() string
|
String() string // Render the rule as a string
|
||||||
Validate() error
|
Validate() error // Validate the rule. Return an error if the rule is invalid
|
||||||
Compare(other Rule) int
|
Compare(other Rule) int // Compare two rules. Return 0 if they are identical
|
||||||
Merge(other Rule) bool
|
Merge(other Rule) bool // Merge rules of same kind together. Return true if merged
|
||||||
}
|
}
|
||||||
|
|
||||||
type Rules []Rule
|
type Rules []Rule
|
||||||
|
|
|
||||||
|
|
@ -71,8 +71,8 @@ func (r *Signal) Kind() Kind {
|
||||||
return SIGNAL
|
return SIGNAL
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Signal) Constraint() constraint {
|
func (r *Signal) Constraint() Constraint {
|
||||||
return blockKind
|
return BlockRule
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Signal) String() string {
|
func (r *Signal) String() string {
|
||||||
|
|
|
||||||
|
|
@ -74,8 +74,8 @@ func (r *Unix) Kind() Kind {
|
||||||
return UNIX
|
return UNIX
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Unix) Constraint() constraint {
|
func (r *Unix) Constraint() Constraint {
|
||||||
return blockKind
|
return BlockRule
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Unix) String() string {
|
func (r *Unix) String() string {
|
||||||
|
|
|
||||||
|
|
@ -46,8 +46,8 @@ func (r *Userns) Kind() Kind {
|
||||||
return USERNS
|
return USERNS
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Userns) Constraint() constraint {
|
func (r *Userns) Constraint() Constraint {
|
||||||
return blockKind
|
return BlockRule
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Userns) String() string {
|
func (r *Userns) String() string {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue