mirror of
https://github.com/roddhjav/apparmor.d.git
synced 2024-12-29 00:16:31 +01:00
68 lines
1.3 KiB
Go
68 lines
1.3 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 prepare
|
||
|
|
||
|
import (
|
||
|
"fmt"
|
||
|
"os"
|
||
|
|
||
|
"github.com/roddhjav/apparmor.d/pkg/prebuild"
|
||
|
"github.com/roddhjav/apparmor.d/pkg/util"
|
||
|
)
|
||
|
|
||
|
const ext = ".apparmor.d"
|
||
|
|
||
|
type Overwrite struct {
|
||
|
prebuild.Base
|
||
|
OneFile bool
|
||
|
}
|
||
|
|
||
|
func init() {
|
||
|
RegisterTask(&Overwrite{
|
||
|
Base: prebuild.Base{
|
||
|
Keyword: "overwrite",
|
||
|
Msg: "Overwrite dummy upstream profiles",
|
||
|
},
|
||
|
OneFile: false,
|
||
|
})
|
||
|
}
|
||
|
|
||
|
func (p Overwrite) Apply() ([]string, error) {
|
||
|
res := []string{}
|
||
|
if prebuild.ABI == 3 {
|
||
|
return res, nil
|
||
|
}
|
||
|
|
||
|
disableDir := prebuild.RootApparmord.Join("disable")
|
||
|
if err := disableDir.Mkdir(); err != nil {
|
||
|
return res, err
|
||
|
}
|
||
|
|
||
|
path := prebuild.DistDir.Join("overwrite")
|
||
|
if !path.Exist() {
|
||
|
return res, fmt.Errorf("%s not found", path)
|
||
|
}
|
||
|
for _, name := range util.MustReadFileAsLines(path) {
|
||
|
origin := prebuild.RootApparmord.Join(name)
|
||
|
dest := prebuild.RootApparmord.Join(name + ext)
|
||
|
if !dest.Exist() && p.OneFile {
|
||
|
continue
|
||
|
}
|
||
|
if err := origin.Rename(dest); err != nil {
|
||
|
|
||
|
return res, err
|
||
|
}
|
||
|
originRel, err := origin.RelFrom(dest)
|
||
|
if err != nil {
|
||
|
return res, err
|
||
|
}
|
||
|
if err := os.Symlink(originRel.String(), disableDir.Join(name).String()); err != nil {
|
||
|
return res, err
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return res, nil
|
||
|
}
|