feat(aa): be more verbose on rule.Merge

This commit is contained in:
Alexandre Pujol 2024-06-25 20:10:12 +01:00
parent 880f0ef37e
commit 7c006dee0a
No known key found for this signature in database
GPG Key ID: C5469996F0DF68EC
11 changed files with 69 additions and 29 deletions

View File

@ -79,10 +79,6 @@ func newBaseFromLog(log map[string]string) Base {
}
}
func (r Base) Merge(other Rule) bool {
return false
}
func (r *Base) merge(other Base) bool {
if other.Comment != "" {
r.Comment += " " + other.Comment

View File

@ -35,3 +35,7 @@ func (r *Hat) Compare(other Rule) int {
o, _ := other.(*Hat)
return compare(r.Name, o.Name)
}
func (r *Hat) Merge(other Rule) bool {
return false // Never merge hat blocks
}

View File

@ -77,3 +77,7 @@ func (r *Capability) Compare(other Rule) int {
}
return r.Qualifier.Compare(o.Qualifier)
}
func (r *Capability) Merge(other Rule) bool {
return false // Never merge capabilities
}

View File

@ -99,3 +99,7 @@ func (r *ChangeProfile) Compare(other Rule) int {
}
return r.Qualifier.Compare(o.Qualifier)
}
func (r *ChangeProfile) Merge(other Rule) bool {
return false // Never merge change_profile
}

View File

@ -242,3 +242,7 @@ func (r *Link) Compare(other Rule) int {
}
return r.Qualifier.Compare(o.Qualifier)
}
func (r *Link) Merge(other Rule) bool {
return false // Never merge link
}

View File

@ -140,3 +140,7 @@ func (r *Network) Compare(other Rule) int {
}
return r.Qualifier.Compare(o.Qualifier)
}
func (r *Network) Merge(other Rule) bool {
return false // Never merge network
}

View File

@ -79,3 +79,7 @@ func (r *PivotRoot) Compare(other Rule) int {
}
return r.Qualifier.Compare(o.Qualifier)
}
func (r *PivotRoot) Merge(other Rule) bool {
return false // Never merge pivot root
}

View File

@ -49,6 +49,10 @@ func (r *Comment) Compare(other Rule) int {
return 0 // Comments are always equal to each other as they are not compared
}
func (r *Comment) Merge(other Rule) bool {
return false // Never merge comments
}
type Abi struct {
Base
Path string
@ -101,6 +105,10 @@ func (r *Abi) Compare(other Rule) int {
return compare(r.IsMagic, o.IsMagic)
}
func (r *Abi) Merge(other Rule) bool {
return false // Never merge abi
}
type Alias struct {
Base
Path string
@ -145,6 +153,10 @@ func (r *Alias) Compare(other Rule) int {
return compare(r.RewrittenPath, o.RewrittenPath)
}
func (r *Alias) Merge(other Rule) bool {
return false // Never merge alias
}
type Include struct {
Base
IfExists bool
@ -218,6 +230,10 @@ func (r *Include) Compare(other Rule) int {
return compare(r.IfExists, o.IfExists)
}
func (r *Include) Merge(other Rule) bool {
return false // Never merge include
}
type Variable struct {
Base
Name string

View File

@ -66,6 +66,17 @@ func (r *Ptrace) Validate() error {
return nil
}
func (r *Ptrace) Compare(other Rule) int {
o, _ := other.(*Ptrace)
if res := compare(r.Access, o.Access); res != 0 {
return res
}
if res := compare(r.Peer, o.Peer); res != 0 {
return res
}
return r.Qualifier.Compare(o.Qualifier)
}
func (r *Ptrace) Merge(other Rule) bool {
o, _ := other.(*Ptrace)
@ -79,14 +90,3 @@ func (r *Ptrace) Merge(other Rule) bool {
}
return false
}
func (r *Ptrace) Compare(other Rule) int {
o, _ := other.(*Ptrace)
if res := compare(r.Access, o.Access); res != 0 {
return res
}
if res := compare(r.Peer, o.Peer); res != 0 {
return res
}
return r.Qualifier.Compare(o.Qualifier)
}

View File

@ -80,3 +80,7 @@ func (r *Rlimit) Compare(other Rule) int {
}
return compare(r.Value, o.Value)
}
func (r *Rlimit) Merge(other Rule) bool {
return false // Never merge rlimit
}

View File

@ -89,6 +89,20 @@ func (r *Signal) Validate() error {
return nil
}
func (r *Signal) Compare(other Rule) int {
o, _ := other.(*Signal)
if res := compare(r.Access, o.Access); res != 0 {
return res
}
if res := compare(r.Set, o.Set); res != 0 {
return res
}
if res := compare(r.Peer, o.Peer); res != 0 {
return res
}
return r.Qualifier.Compare(o.Qualifier)
}
func (r *Signal) Merge(other Rule) bool {
o, _ := other.(*Signal)
@ -107,17 +121,3 @@ func (r *Signal) Merge(other Rule) bool {
}
return false
}
func (r *Signal) Compare(other Rule) int {
o, _ := other.(*Signal)
if res := compare(r.Access, o.Access); res != 0 {
return res
}
if res := compare(r.Set, o.Set); res != 0 {
return res
}
if res := compare(r.Peer, o.Peer); res != 0 {
return res
}
return r.Qualifier.Compare(o.Qualifier)
}