2024-03-26 00:34:14 +01: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 prepare
|
|
|
|
|
|
|
|
import (
|
2024-04-28 01:36:16 +02:00
|
|
|
"github.com/roddhjav/apparmor.d/pkg/paths"
|
2024-10-02 17:22:46 +02:00
|
|
|
"github.com/roddhjav/apparmor.d/pkg/prebuild"
|
2024-03-26 00:34:14 +01:00
|
|
|
"github.com/roddhjav/apparmor.d/pkg/util"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Synchronise struct {
|
2024-10-02 17:22:46 +02:00
|
|
|
prebuild.Base
|
|
|
|
Path string
|
2024-03-26 00:34:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
RegisterTask(&Synchronise{
|
2024-10-02 17:22:46 +02:00
|
|
|
Base: prebuild.Base{
|
2024-03-26 00:34:14 +01:00
|
|
|
Keyword: "synchronise",
|
|
|
|
Msg: "Initialize a new clean apparmor.d build directory",
|
|
|
|
},
|
2024-10-02 17:22:46 +02:00
|
|
|
Path: "",
|
2024-03-26 00:34:14 +01:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p Synchronise) Apply() ([]string, error) {
|
|
|
|
res := []string{}
|
2024-10-02 17:22:46 +02:00
|
|
|
dirs := paths.PathList{prebuild.RootApparmord, prebuild.Root.Join("root"), prebuild.Root.Join("systemd")}
|
2024-03-26 00:34:14 +01:00
|
|
|
for _, dir := range dirs {
|
|
|
|
if err := dir.RemoveAll(); err != nil {
|
|
|
|
return res, err
|
|
|
|
}
|
|
|
|
}
|
2024-10-02 17:22:46 +02:00
|
|
|
if p.Path == "" {
|
|
|
|
for _, name := range []string{"apparmor.d", "root"} {
|
|
|
|
if err := util.CopyTo(paths.New(name), prebuild.Root.Join(name)); err != nil {
|
|
|
|
return res, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
file := paths.New(p.Path)
|
|
|
|
destination, err := file.RelFrom(paths.New("apparmor.d"))
|
|
|
|
if err != nil {
|
|
|
|
return res, err
|
|
|
|
}
|
|
|
|
destination = prebuild.RootApparmord.JoinPath(destination)
|
|
|
|
if err := destination.Parent().MkdirAll(); err != nil {
|
|
|
|
return res, err
|
|
|
|
}
|
|
|
|
if err := file.CopyTo(destination); err != nil {
|
2024-03-26 00:34:14 +01:00
|
|
|
return res, err
|
|
|
|
}
|
2024-10-02 17:22:46 +02:00
|
|
|
res = append(res, destination.String())
|
2024-03-26 00:34:14 +01:00
|
|
|
}
|
|
|
|
return res, nil
|
|
|
|
}
|