apparmor.d/pkg/aa/pivot_root.go
Alexandre Pujol 4cbacc186c
feat(aa): rule interface: replace less & equal by the compare method.
- set a new alphabet order to sort AARE based string.
- unify compare function for all rules
- handle some special sort order, eg: base include
2024-06-19 18:34:58 +01:00

56 lines
1.1 KiB
Go

// apparmor.d - Full set of apparmor profiles
// Copyright (C) 2021-2024 Alexandre Pujol <alexandre@pujol.io>
// SPDX-License-Identifier: GPL-2.0-only
package aa
const PIVOTROOT Kind = "pivot_root"
type PivotRoot struct {
RuleBase
Qualifier
OldRoot string
NewRoot string
TargetProfile string
}
func newPivotRootFromLog(log map[string]string) Rule {
return &PivotRoot{
RuleBase: newRuleFromLog(log),
Qualifier: newQualifierFromLog(log),
OldRoot: log["srcname"],
NewRoot: log["name"],
TargetProfile: "",
}
}
func (r *PivotRoot) Validate() error {
return nil
}
func (r *PivotRoot) Compare(other Rule) int {
o, _ := other.(*PivotRoot)
if res := compare(r.OldRoot, o.OldRoot); res != 0 {
return res
}
if res := compare(r.NewRoot, o.NewRoot); res != 0 {
return res
}
if res := compare(r.TargetProfile, o.TargetProfile); res != 0 {
return res
}
return r.Qualifier.Compare(o.Qualifier)
}
func (r *PivotRoot) String() string {
return renderTemplate(r.Kind(), r)
}
func (r *PivotRoot) Constraint() constraint {
return blockKind
}
func (r *PivotRoot) Kind() Kind {
return PIVOTROOT
}