2023-09-25 01:06:07 +02:00
|
|
|
// apparmor.d - Full set of apparmor profiles
|
2024-02-07 00:16:21 +01:00
|
|
|
// Copyright (C) 2021-2024 Alexandre Pujol <alexandre@pujol.io>
|
2023-09-25 01:06:07 +02:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
|
|
|
|
|
|
|
package aa
|
|
|
|
|
2024-06-20 00:22:49 +02:00
|
|
|
import "fmt"
|
|
|
|
|
2024-05-30 21:56:53 +02:00
|
|
|
const PIVOTROOT Kind = "pivot_root"
|
2024-04-23 22:26:09 +02:00
|
|
|
|
2023-09-25 01:06:07 +02:00
|
|
|
type PivotRoot struct {
|
2024-06-25 20:50:27 +02:00
|
|
|
Base
|
2023-09-25 01:06:07 +02:00
|
|
|
Qualifier
|
|
|
|
OldRoot string
|
|
|
|
NewRoot string
|
|
|
|
TargetProfile string
|
|
|
|
}
|
|
|
|
|
2024-06-20 00:22:49 +02:00
|
|
|
func newPivotRoot(q Qualifier, rule rule) (Rule, error) {
|
|
|
|
newroot, target := "", ""
|
|
|
|
r := rule.GetSlice()
|
|
|
|
if len(r) > 0 {
|
|
|
|
if r[0] != tokARROW {
|
|
|
|
newroot = r[0]
|
|
|
|
r = r[1:]
|
|
|
|
}
|
|
|
|
if len(r) == 2 {
|
|
|
|
if r[0] != tokARROW {
|
|
|
|
return nil, fmt.Errorf("missing '%s' in rule: %s", tokARROW, rule)
|
|
|
|
}
|
|
|
|
target = r[1]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return &PivotRoot{
|
2024-06-25 20:50:27 +02:00
|
|
|
Base: newBase(rule),
|
2024-06-20 00:22:49 +02:00
|
|
|
Qualifier: q,
|
|
|
|
OldRoot: rule.GetValuesAsString("oldroot"),
|
|
|
|
NewRoot: newroot,
|
|
|
|
TargetProfile: target,
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
2024-04-19 23:43:02 +02:00
|
|
|
func newPivotRootFromLog(log map[string]string) Rule {
|
2023-09-25 01:06:07 +02:00
|
|
|
return &PivotRoot{
|
2024-06-25 20:50:27 +02:00
|
|
|
Base: newBaseFromLog(log),
|
2024-04-15 00:58:34 +02:00
|
|
|
Qualifier: newQualifierFromLog(log),
|
2023-11-27 20:21:43 +01:00
|
|
|
OldRoot: log["srcname"],
|
|
|
|
NewRoot: log["name"],
|
|
|
|
TargetProfile: "",
|
2023-09-25 01:06:07 +02:00
|
|
|
}
|
|
|
|
}
|
2023-09-25 01:09:11 +02:00
|
|
|
|
2024-06-25 20:56:36 +02:00
|
|
|
func (r *PivotRoot) Kind() Kind {
|
|
|
|
return PIVOTROOT
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *PivotRoot) Constraint() constraint {
|
|
|
|
return blockKind
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *PivotRoot) String() string {
|
|
|
|
return renderTemplate(r.Kind(), r)
|
|
|
|
}
|
|
|
|
|
2024-05-25 23:36:39 +02:00
|
|
|
func (r *PivotRoot) Validate() error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2024-06-19 19:34:58 +02:00
|
|
|
func (r *PivotRoot) Compare(other Rule) int {
|
2023-09-25 01:09:11 +02:00
|
|
|
o, _ := other.(*PivotRoot)
|
2024-06-19 19:34:58 +02:00
|
|
|
if res := compare(r.OldRoot, o.OldRoot); res != 0 {
|
|
|
|
return res
|
2023-09-25 01:09:11 +02:00
|
|
|
}
|
2024-06-19 19:34:58 +02:00
|
|
|
if res := compare(r.NewRoot, o.NewRoot); res != 0 {
|
|
|
|
return res
|
2024-04-15 00:58:34 +02:00
|
|
|
}
|
2024-06-19 19:34:58 +02:00
|
|
|
if res := compare(r.TargetProfile, o.TargetProfile); res != 0 {
|
|
|
|
return res
|
2024-04-15 00:58:34 +02:00
|
|
|
}
|
2024-06-19 19:34:58 +02:00
|
|
|
return r.Qualifier.Compare(o.Qualifier)
|
2023-09-25 01:09:11 +02:00
|
|
|
}
|
2024-06-25 21:10:12 +02:00
|
|
|
|
|
|
|
func (r *PivotRoot) Merge(other Rule) bool {
|
|
|
|
return false // Never merge pivot root
|
|
|
|
}
|