chore: apply some linter recommendations.
This commit is contained in:
parent
3b6b50cf63
commit
984cf28e61
37 changed files with 125 additions and 126 deletions
|
|
@ -38,9 +38,9 @@ func (b ReAttach) Apply(opt *Option, profile string) (string, error) {
|
|||
|
||||
if strings.Contains(profile, "attach_disconnected") {
|
||||
insert = "@{att} = /att/" + opt.Name + "/\n"
|
||||
profile = strings.Replace(profile,
|
||||
profile = strings.ReplaceAll(profile,
|
||||
"attach_disconnected",
|
||||
"attach_disconnected,attach_disconnected.path=@{att}", -1,
|
||||
"attach_disconnected,attach_disconnected.path=@{att}",
|
||||
)
|
||||
|
||||
old := "include if exists <local/" + opt.Name + ">"
|
||||
|
|
|
|||
|
|
@ -20,13 +20,13 @@ var (
|
|||
Builders = map[string]Builder{}
|
||||
)
|
||||
|
||||
// Main directive interface
|
||||
// Builder main directive interface
|
||||
type Builder interface {
|
||||
prebuild.BaseInterface
|
||||
Apply(opt *Option, profile string) (string, error)
|
||||
}
|
||||
|
||||
// Builder options
|
||||
// Option for a builder
|
||||
type Option struct {
|
||||
Name string
|
||||
File *paths.Path
|
||||
|
|
|
|||
|
|
@ -54,7 +54,7 @@ func (b Userspace) Apply(opt *Option, profile string) (string, error) {
|
|||
matches := regAttachments.FindAllString(profile, -1)
|
||||
if len(matches) > 0 {
|
||||
att := f.GetDefaultProfile().GetAttachments()
|
||||
strheader := strings.Replace(matches[0], tokATTACHMENT, att, -1)
|
||||
strheader := strings.ReplaceAll(matches[0], tokATTACHMENT, att)
|
||||
return regAttachments.ReplaceAllLiteralString(profile, strheader), nil
|
||||
}
|
||||
return profile, nil
|
||||
|
|
|
|||
|
|
@ -18,9 +18,9 @@ import (
|
|||
)
|
||||
|
||||
const (
|
||||
nilABI uint = 0
|
||||
nilVer float64 = 0.0
|
||||
usage = `aa-prebuild [-h] [--complain | --enforce] [--full] [--abi 3|4] [--version V] [--file FILE]
|
||||
nilABI = 0
|
||||
nilVer = 0.0
|
||||
usage = `aa-prebuild [-h] [--complain | --enforce] [--full] [--abi 3|4] [--version V] [--file FILE]
|
||||
|
||||
Prebuild apparmor.d profiles for a given distribution and apply
|
||||
internal built-in directives.
|
||||
|
|
@ -41,7 +41,7 @@ var (
|
|||
complain bool
|
||||
enforce bool
|
||||
full bool
|
||||
abi uint
|
||||
abi int
|
||||
version float64
|
||||
file string
|
||||
)
|
||||
|
|
@ -55,8 +55,8 @@ func init() {
|
|||
flag.BoolVar(&complain, "complain", false, "Set complain flag on all profiles.")
|
||||
flag.BoolVar(&enforce, "e", false, "Set enforce flag on all profiles.")
|
||||
flag.BoolVar(&enforce, "enforce", false, "Set enforce flag on all profiles.")
|
||||
flag.UintVar(&abi, "a", nilABI, "Target apparmor ABI.")
|
||||
flag.UintVar(&abi, "abi", nilABI, "Target apparmor ABI.")
|
||||
flag.IntVar(&abi, "a", nilABI, "Target apparmor ABI.")
|
||||
flag.IntVar(&abi, "abi", nilABI, "Target apparmor ABI.")
|
||||
flag.Float64Var(&version, "v", nilVer, "Target apparmor version.")
|
||||
flag.Float64Var(&version, "version", nilVer, "Target apparmor version.")
|
||||
flag.StringVar(&file, "F", "", "Only prebuild a given file.")
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ var (
|
|||
regDirective = regexp.MustCompile(`(?m).*` + Keyword + `([a-z]*)( .*)?`)
|
||||
)
|
||||
|
||||
// Main directive interface
|
||||
// Directive main interface
|
||||
type Directive interface {
|
||||
prebuild.BaseInterface
|
||||
Apply(opt *Option, profile string) (string, error)
|
||||
|
|
@ -39,7 +39,7 @@ func Usage() string {
|
|||
return res
|
||||
}
|
||||
|
||||
// Directive options
|
||||
// Option for the directive
|
||||
type Option struct {
|
||||
Name string
|
||||
ArgMap map[string]string
|
||||
|
|
@ -83,7 +83,7 @@ func (o *Option) cleanKeyword(input string) string {
|
|||
return reg.ReplaceAllString(input, "")
|
||||
}
|
||||
|
||||
// Check if the directive is inline or if it is a paragraph
|
||||
// IsInline checks if either the directive is in one line or if it is a paragraph
|
||||
func (o *Option) IsInline() bool {
|
||||
inline := true
|
||||
tmp := strings.Split(o.Raw, Keyword)
|
||||
|
|
@ -106,7 +106,7 @@ func Run(file *paths.Path, profile string) (string, error) {
|
|||
opt := NewOption(file, match)
|
||||
drtv, ok := Directives[opt.Name]
|
||||
if !ok {
|
||||
return "", fmt.Errorf("Unknown directive '%s' in %s", opt.Name, opt.File)
|
||||
return "", fmt.Errorf("unknown directive '%s' in %s", opt.Name, opt.File)
|
||||
}
|
||||
profile, err = drtv.Apply(opt, profile)
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -61,32 +61,32 @@ func (d Dbus) Apply(opt *Option, profile string) (string, error) {
|
|||
generatedDbus := r.String()
|
||||
lenDbus := len(generatedDbus)
|
||||
generatedDbus = generatedDbus[:lenDbus-1]
|
||||
profile = strings.Replace(profile, opt.Raw, generatedDbus, -1)
|
||||
profile = strings.ReplaceAll(profile, opt.Raw, generatedDbus)
|
||||
return profile, nil
|
||||
}
|
||||
|
||||
func (d Dbus) sanityCheck(opt *Option) (string, error) {
|
||||
if len(opt.ArgList) < 1 {
|
||||
return "", fmt.Errorf("Unknown dbus action: %s in %s", opt.Name, opt.File)
|
||||
return "", fmt.Errorf("unknown dbus action: %s in %s", opt.Name, opt.File)
|
||||
}
|
||||
action := opt.ArgList[0]
|
||||
if action != "own" && action != "talk" && action != "common" {
|
||||
return "", fmt.Errorf("Unknown dbus action: %s in %s", opt.Name, opt.File)
|
||||
return "", fmt.Errorf("unknown dbus action: %s in %s", opt.Name, opt.File)
|
||||
}
|
||||
|
||||
if _, present := opt.ArgMap["name"]; !present {
|
||||
return "", fmt.Errorf("Missing name for 'dbus: %s' in %s", action, opt.File)
|
||||
return "", fmt.Errorf("missing name for 'dbus: %s' in %s", action, opt.File)
|
||||
}
|
||||
if _, present := opt.ArgMap["bus"]; !present {
|
||||
return "", fmt.Errorf("Missing bus for '%s' in %s", opt.ArgMap["name"], opt.File)
|
||||
return "", fmt.Errorf("missing bus for '%s' in %s", opt.ArgMap["name"], opt.File)
|
||||
}
|
||||
if _, present := opt.ArgMap["label"]; !present && action == "talk" {
|
||||
return "", fmt.Errorf("Missing label for '%s' in %s", opt.ArgMap["name"], opt.File)
|
||||
return "", fmt.Errorf("missing label for '%s' in %s", opt.ArgMap["name"], opt.File)
|
||||
}
|
||||
|
||||
// Set default values
|
||||
if _, present := opt.ArgMap["path"]; !present {
|
||||
opt.ArgMap["path"] = "/" + strings.Replace(opt.ArgMap["name"], ".", "/", -1) + "{,/**}"
|
||||
opt.ArgMap["path"] = "/" + strings.ReplaceAll(opt.ArgMap["name"], ".", "/") + "{,/**}"
|
||||
}
|
||||
opt.ArgMap["name"] += "{,.*}"
|
||||
return action, nil
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ func init() {
|
|||
|
||||
func (d Exec) Apply(opt *Option, profileRaw string) (string, error) {
|
||||
if len(opt.ArgList) == 0 {
|
||||
return "", fmt.Errorf("No profile to exec")
|
||||
return "", fmt.Errorf("no profile to exec")
|
||||
}
|
||||
transition := "Px"
|
||||
transitions := []string{"P", "U", "p", "u", "PU", "pu"}
|
||||
|
|
@ -70,5 +70,5 @@ func (d Exec) Apply(opt *Option, profileRaw string) (string, error) {
|
|||
rules = rules.Sort()
|
||||
new := rules.String()
|
||||
new = new[:len(new)-1]
|
||||
return strings.Replace(profileRaw, opt.Raw, new, -1), nil
|
||||
return strings.ReplaceAll(profileRaw, opt.Raw, new), nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -59,7 +59,7 @@ func filter(only bool, opt *Option, profile string) (string, error) {
|
|||
}
|
||||
|
||||
if opt.IsInline() {
|
||||
profile = strings.Replace(profile, opt.Raw, "", -1)
|
||||
profile = strings.ReplaceAll(profile, opt.Raw, "")
|
||||
} else {
|
||||
regRemoveParagraph := regexp.MustCompile(`(?s)` + opt.Raw + `\n.*?\n\n`)
|
||||
profile = regRemoveParagraph.ReplaceAllString(profile, "")
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ func init() {
|
|||
|
||||
func (s Stack) Apply(opt *Option, profile string) (string, error) {
|
||||
if len(opt.ArgList) == 0 {
|
||||
return "", fmt.Errorf("No profile to stack")
|
||||
return "", fmt.Errorf("no profile to stack")
|
||||
}
|
||||
t := opt.ArgList[0]
|
||||
if t != "X" {
|
||||
|
|
@ -58,7 +58,7 @@ func (s Stack) Apply(opt *Option, profile string) (string, error) {
|
|||
stackedProfile := prebuild.RootApparmord.Join(name).MustReadFileAsString()
|
||||
m := regRules.FindStringSubmatch(stackedProfile)
|
||||
if len(m) < 2 {
|
||||
return "", fmt.Errorf("No profile found in %s", name)
|
||||
return "", fmt.Errorf("no profile found in %s", name)
|
||||
}
|
||||
stackedRules := m[1]
|
||||
stackedRules = regCleanStakedRules.Replace(stackedRules)
|
||||
|
|
@ -68,9 +68,9 @@ func (s Stack) Apply(opt *Option, profile string) (string, error) {
|
|||
// Insert the stacked profile at the end of the current profile, remove the stack directive
|
||||
m := regEndOfRules.FindStringSubmatch(profile)
|
||||
if len(m) <= 1 {
|
||||
return "", fmt.Errorf("No end of rules found in %s", opt.File)
|
||||
return "", fmt.Errorf("no end of rules found in %s", opt.File)
|
||||
}
|
||||
profile = strings.Replace(profile, m[0], res+m[0], -1)
|
||||
profile = strings.Replace(profile, opt.Raw, "", -1)
|
||||
profile = strings.ReplaceAll(profile, m[0], res+m[0])
|
||||
profile = strings.ReplaceAll(profile, opt.Raw, "")
|
||||
return profile, nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,13 +8,13 @@ import "github.com/roddhjav/apparmor.d/pkg/paths"
|
|||
|
||||
var (
|
||||
// AppArmor ABI version
|
||||
ABI uint = 0
|
||||
ABI = 0
|
||||
|
||||
// AppArmor version
|
||||
Version float64 = 4.0
|
||||
Version = 4.0
|
||||
|
||||
// Pkgname is the name of the package
|
||||
Pkgname string = "apparmor.d"
|
||||
Pkgname = "apparmor.d"
|
||||
|
||||
// Root is the root directory for the build (default: .build)
|
||||
Root *paths.Path = paths.New(".build")
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ import (
|
|||
"github.com/roddhjav/apparmor.d/pkg/paths"
|
||||
)
|
||||
|
||||
// Default content of debian/apparmor.d.hide. Whonix has special addition.
|
||||
// Hide is the default content of debian/apparmor.d.hide. Whonix has special addition.
|
||||
var Hide = `# This file is generated by "make", all edit will be lost.
|
||||
|
||||
/etc/apparmor.d/usr.bin.firefox
|
||||
|
|
@ -55,7 +55,7 @@ type DebianHider struct {
|
|||
path *paths.Path
|
||||
}
|
||||
|
||||
// Initialize the file with content from Hide
|
||||
// Init initializes the file with content from Hide
|
||||
func (d DebianHider) Init() error {
|
||||
return d.path.WriteFile([]byte(Hide))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -67,13 +67,13 @@ func getDistribution() string {
|
|||
if id == "ubuntu" {
|
||||
return id
|
||||
}
|
||||
id_like := Release["ID_LIKE"]
|
||||
idLike := Release["ID_LIKE"]
|
||||
for main, based := range supportedDists {
|
||||
if main == id || main == id_like {
|
||||
if main == id || main == idLike {
|
||||
return main
|
||||
} else if slices.Contains(based, id) {
|
||||
return main
|
||||
} else if slices.Contains(based, id_like) {
|
||||
} else if slices.Contains(based, idLike) {
|
||||
return main
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ var (
|
|||
Tasks = map[string]Task{}
|
||||
)
|
||||
|
||||
// Main directive interface
|
||||
// Task main directive interface
|
||||
type Task interface {
|
||||
prebuild.BaseInterface
|
||||
Apply() ([]string, error)
|
||||
|
|
|
|||
|
|
@ -39,8 +39,8 @@ func (p FullSystemPolicy) Apply() ([]string, error) {
|
|||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
out = strings.Replace(out, "@{p_systemd}=unconfined", "@{p_systemd}=systemd", -1)
|
||||
out = strings.Replace(out, "@{p_systemd_user}=unconfined", "@{p_systemd_user}=systemd-user", -1)
|
||||
out = strings.ReplaceAll(out, "@{p_systemd}=unconfined", "@{p_systemd}=systemd")
|
||||
out = strings.ReplaceAll(out, "@{p_systemd_user}=unconfined", "@{p_systemd_user}=systemd-user")
|
||||
if err := path.WriteFile([]byte(out)); err != nil {
|
||||
return res, err
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue