mirror of
https://github.com/roddhjav/apparmor.d.git
synced 2025-02-07 02:35:06 +01:00
chore: cosmetic & fix.
This commit is contained in:
parent
72107dcfff
commit
54fdf38861
3 changed files with 32 additions and 14 deletions
|
@ -6,24 +6,21 @@ package aa
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"slices"
|
"slices"
|
||||||
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
tokABI = "abi"
|
tokABI = "abi"
|
||||||
tokALIAS = "alias"
|
tokALIAS = "alias"
|
||||||
tokINCLUDE = "include"
|
tokINCLUDE = "include"
|
||||||
tokIFEXISTS = "if exists"
|
tokIFEXISTS = "if exists"
|
||||||
|
tokVARIABLE = "@{"
|
||||||
|
tokCOMMENT = "#"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Comment struct {
|
type Comment struct {
|
||||||
RuleBase
|
RuleBase
|
||||||
}
|
}
|
||||||
|
|
||||||
func newCommentFromRule(rule rule) (Rule, error) {
|
|
||||||
base := newRuleFromRule(rule)
|
|
||||||
base.IsLineRule = true
|
|
||||||
return &Comment{RuleBase: base}, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *Comment) Less(other any) bool {
|
func (r *Comment) Less(other any) bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
@ -152,8 +149,6 @@ type Variable struct {
|
||||||
Define bool
|
Define bool
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *Variable) Less(other any) bool {
|
func (r *Variable) Less(other any) bool {
|
||||||
o, _ := other.(*Variable)
|
o, _ := other.(*Variable)
|
||||||
if r.Name != o.Name {
|
if r.Name != o.Name {
|
||||||
|
|
|
@ -62,6 +62,17 @@ func (r Rules) GetVariables() []*Variable {
|
||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (r Rules) GetIncludes() []*Include {
|
||||||
|
res := make([]*Include, 0)
|
||||||
|
for _, rule := range r {
|
||||||
|
switch rule.(type) {
|
||||||
|
case *Include:
|
||||||
|
res = append(res, rule.(*Include))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return res
|
||||||
|
}
|
||||||
|
|
||||||
// Must is a helper that wraps a call to a function returning (any, error) and
|
// Must is a helper that wraps a call to a function returning (any, error) and
|
||||||
// panics if the error is non-nil.
|
// panics if the error is non-nil.
|
||||||
func Must[T any](v T, err error) T {
|
func Must[T any](v T, err error) T {
|
||||||
|
|
|
@ -8,7 +8,6 @@ import (
|
||||||
"embed"
|
"embed"
|
||||||
"fmt"
|
"fmt"
|
||||||
"reflect"
|
"reflect"
|
||||||
"slices"
|
|
||||||
"strings"
|
"strings"
|
||||||
"text/template"
|
"text/template"
|
||||||
)
|
)
|
||||||
|
@ -36,11 +35,23 @@ var (
|
||||||
|
|
||||||
// The apparmor templates
|
// The apparmor templates
|
||||||
tmpl = generateTemplates([]string{
|
tmpl = generateTemplates([]string{
|
||||||
"apparmor", tokPROFILE, "rules", // Global templates
|
// Global templates
|
||||||
tokINCLUDE, tokRLIMIT, tokCAPABILITY, tokNETWORK,
|
"apparmor",
|
||||||
tokMOUNT, tokPIVOTROOT, tokCHANGEPROFILE, tokSIGNAL,
|
tokPROFILE,
|
||||||
tokPTRACE, tokUNIX, tokUSERNS, tokIOURING,
|
"rules",
|
||||||
tokDBUS, "file", "variable",
|
|
||||||
|
// Preamble templates
|
||||||
|
tokABI,
|
||||||
|
tokALIAS,
|
||||||
|
tokINCLUDE,
|
||||||
|
"variable",
|
||||||
|
"comment",
|
||||||
|
|
||||||
|
// Rules templates
|
||||||
|
tokALL, tokRLIMIT, tokUSERNS, tokCAPABILITY, tokNETWORK,
|
||||||
|
tokMOUNT, tokREMOUNT, tokUMOUNT, tokPIVOTROOT, tokCHANGEPROFILE,
|
||||||
|
tokMQUEUE, tokIOURING, tokUNIX, tokPTRACE, tokSIGNAL, tokDBUS,
|
||||||
|
tokFILE, tokLINK,
|
||||||
})
|
})
|
||||||
|
|
||||||
// convert apparmor requested mask to apparmor access mode
|
// convert apparmor requested mask to apparmor access mode
|
||||||
|
@ -72,6 +83,7 @@ var (
|
||||||
"unix",
|
"unix",
|
||||||
"dbus",
|
"dbus",
|
||||||
"file",
|
"file",
|
||||||
|
"link",
|
||||||
"profile",
|
"profile",
|
||||||
"include_if_exists",
|
"include_if_exists",
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue