2024-04-15 00:58:34 +02:00
|
|
|
// 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
|
|
|
|
|
|
|
|
import (
|
|
|
|
"slices"
|
2024-05-25 23:21:59 +02:00
|
|
|
)
|
2024-04-23 22:26:09 +02:00
|
|
|
|
|
|
|
const (
|
|
|
|
tokABI = "abi"
|
|
|
|
tokALIAS = "alias"
|
|
|
|
tokINCLUDE = "include"
|
|
|
|
tokIFEXISTS = "if exists"
|
2024-05-25 23:21:59 +02:00
|
|
|
tokVARIABLE = "@{"
|
|
|
|
tokCOMMENT = "#"
|
2024-04-15 00:58:34 +02:00
|
|
|
)
|
|
|
|
|
2024-05-05 00:25:55 +02:00
|
|
|
type Comment struct {
|
|
|
|
RuleBase
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *Comment) Less(other any) bool {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *Comment) Equals(other any) bool {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *Comment) String() string {
|
|
|
|
return renderTemplate("comment", r)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *Comment) IsPreamble() bool {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2024-05-05 00:41:47 +02:00
|
|
|
func (r *Comment) Constraint() constraint {
|
2024-05-05 00:25:55 +02:00
|
|
|
return anyKind
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *Comment) Kind() string {
|
|
|
|
return tokCOMMENT
|
|
|
|
}
|
|
|
|
|
2024-04-15 00:58:34 +02:00
|
|
|
type Abi struct {
|
2024-04-19 23:43:02 +02:00
|
|
|
RuleBase
|
2024-04-15 00:58:34 +02:00
|
|
|
Path string
|
|
|
|
IsMagic bool
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *Abi) Less(other any) bool {
|
|
|
|
o, _ := other.(*Abi)
|
|
|
|
if r.Path != o.Path {
|
|
|
|
return r.Path < o.Path
|
|
|
|
}
|
|
|
|
return r.IsMagic == o.IsMagic
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *Abi) Equals(other any) bool {
|
|
|
|
o, _ := other.(*Abi)
|
|
|
|
return r.Path == o.Path && r.IsMagic == o.IsMagic
|
|
|
|
}
|
|
|
|
|
2024-04-23 22:26:09 +02:00
|
|
|
func (r *Abi) String() string {
|
2024-05-25 23:26:51 +02:00
|
|
|
return renderTemplate(r.Kind(), r)
|
2024-04-23 22:26:09 +02:00
|
|
|
}
|
|
|
|
|
2024-05-05 00:41:47 +02:00
|
|
|
func (r *Abi) Constraint() constraint {
|
|
|
|
return preambleKind
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *Abi) Kind() string {
|
|
|
|
return tokABI
|
|
|
|
}
|
|
|
|
|
2024-04-15 00:58:34 +02:00
|
|
|
type Alias struct {
|
2024-04-19 23:43:02 +02:00
|
|
|
RuleBase
|
2024-04-15 00:58:34 +02:00
|
|
|
Path string
|
|
|
|
RewrittenPath string
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r Alias) Less(other any) bool {
|
|
|
|
o, _ := other.(*Alias)
|
|
|
|
if r.Path != o.Path {
|
|
|
|
return r.Path < o.Path
|
|
|
|
}
|
|
|
|
return r.RewrittenPath < o.RewrittenPath
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r Alias) Equals(other any) bool {
|
|
|
|
o, _ := other.(*Alias)
|
|
|
|
return r.Path == o.Path && r.RewrittenPath == o.RewrittenPath
|
|
|
|
}
|
|
|
|
|
2024-04-23 22:26:09 +02:00
|
|
|
func (r *Alias) String() string {
|
2024-05-25 23:26:51 +02:00
|
|
|
return renderTemplate(r.Kind(), r)
|
2024-04-23 22:26:09 +02:00
|
|
|
}
|
|
|
|
|
2024-05-05 00:41:47 +02:00
|
|
|
func (r *Alias) Constraint() constraint {
|
|
|
|
return preambleKind
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *Alias) Kind() string {
|
|
|
|
return tokALIAS
|
|
|
|
}
|
|
|
|
|
2024-04-15 00:58:34 +02:00
|
|
|
type Include struct {
|
2024-04-19 23:43:02 +02:00
|
|
|
RuleBase
|
2024-04-15 00:58:34 +02:00
|
|
|
IfExists bool
|
|
|
|
Path string
|
|
|
|
IsMagic bool
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *Include) Less(other any) bool {
|
|
|
|
o, _ := other.(*Include)
|
|
|
|
if r.Path == o.Path {
|
|
|
|
return r.Path < o.Path
|
|
|
|
}
|
|
|
|
if r.IsMagic != o.IsMagic {
|
|
|
|
return r.IsMagic
|
|
|
|
}
|
|
|
|
return r.IfExists
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *Include) Equals(other any) bool {
|
|
|
|
o, _ := other.(*Include)
|
|
|
|
return r.Path == o.Path && r.IsMagic == o.IsMagic && r.IfExists == o.IfExists
|
|
|
|
}
|
|
|
|
|
2024-04-23 22:26:09 +02:00
|
|
|
func (r *Include) String() string {
|
2024-05-25 23:26:51 +02:00
|
|
|
return renderTemplate(r.Kind(), r)
|
2024-04-23 22:26:09 +02:00
|
|
|
}
|
|
|
|
|
2024-05-05 00:41:47 +02:00
|
|
|
func (r *Include) Constraint() constraint {
|
|
|
|
return anyKind
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *Include) Kind() string {
|
|
|
|
return tokINCLUDE
|
|
|
|
}
|
|
|
|
|
2024-04-15 00:58:34 +02:00
|
|
|
type Variable struct {
|
2024-04-19 23:43:02 +02:00
|
|
|
RuleBase
|
2024-04-15 00:58:34 +02:00
|
|
|
Name string
|
|
|
|
Values []string
|
2024-04-23 22:18:44 +02:00
|
|
|
Define bool
|
|
|
|
}
|
|
|
|
|
2024-04-19 23:43:02 +02:00
|
|
|
func (r *Variable) Less(other any) bool {
|
|
|
|
o, _ := other.(*Variable)
|
|
|
|
if r.Name != o.Name {
|
|
|
|
return r.Name < o.Name
|
2024-04-15 00:58:34 +02:00
|
|
|
}
|
2024-04-19 23:43:02 +02:00
|
|
|
return len(r.Values) < len(o.Values)
|
2024-04-15 00:58:34 +02:00
|
|
|
}
|
|
|
|
|
2024-04-19 23:43:02 +02:00
|
|
|
func (r *Variable) Equals(other any) bool {
|
|
|
|
o, _ := other.(*Variable)
|
|
|
|
return r.Name == o.Name && slices.Equal(r.Values, o.Values)
|
2024-04-15 00:58:34 +02:00
|
|
|
}
|
2024-04-23 22:26:09 +02:00
|
|
|
|
|
|
|
func (r *Variable) String() string {
|
|
|
|
return renderTemplate("variable", r)
|
|
|
|
}
|
2024-05-05 00:41:47 +02:00
|
|
|
|
|
|
|
func (r *Variable) Constraint() constraint {
|
|
|
|
return preambleKind
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *Variable) Kind() string {
|
|
|
|
return tokVARIABLE
|
|
|
|
}
|