mirror of
https://github.com/roddhjav/apparmor.d.git
synced 2024-11-15 07:54:17 +01:00
56 lines
1.1 KiB
Go
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 (
|
|
tokALLOW = "allow"
|
|
tokAUDIT = "audit"
|
|
tokDENY = "deny"
|
|
)
|
|
|
|
type constraint uint
|
|
|
|
const (
|
|
anyKind constraint = iota // The rule can be found in either preamble or profile
|
|
preambleKind // The rule can only be found in the preamble
|
|
blockKind // The rule can only be found in a profile
|
|
)
|
|
|
|
// Rule generic interface for all AppArmor rules
|
|
type Rule interface {
|
|
Less(other any) bool
|
|
Equals(other any) bool
|
|
String() string
|
|
Constraint() constraint
|
|
Kind() string
|
|
}
|
|
|
|
type Rules []Rule
|
|
|
|
func (r Rules) String() string {
|
|
return renderTemplate("rules", r)
|
|
}
|
|
|
|
func (r Rules) Get(filter string) Rules {
|
|
res := make(Rules, 0)
|
|
for _, rule := range r {
|
|
if rule.Kind() == filter {
|
|
res = append(res, rule)
|
|
}
|
|
}
|
|
return res
|
|
}
|
|
|
|
func (r Rules) GetVariables() []*Variable {
|
|
res := make([]*Variable, 0)
|
|
for _, rule := range r {
|
|
switch rule.(type) {
|
|
case *Variable:
|
|
res = append(res, rule.(*Variable))
|
|
}
|
|
}
|
|
return res
|
|
}
|