2014-03-05 19:59:31 +00:00
|
|
|
package apparmor
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"io/ioutil"
|
|
|
|
"os"
|
|
|
|
)
|
|
|
|
|
2014-03-05 20:27:31 +00:00
|
|
|
func IsEnabled() bool {
|
2014-03-05 19:59:31 +00:00
|
|
|
buf, err := ioutil.ReadFile("/sys/module/apparmor/parameters/enabled")
|
2014-03-05 20:27:31 +00:00
|
|
|
return err == nil && len(buf) > 1 && buf[0] == 'Y'
|
2014-03-05 19:59:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func ApplyProfile(pid int, name string) error {
|
2014-03-05 20:27:31 +00:00
|
|
|
if !IsEnabled() || name == "" {
|
|
|
|
return nil
|
2014-03-05 19:59:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
f, err := os.OpenFile(fmt.Sprintf("/proc/%d/attr/current", pid), os.O_WRONLY, 0)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
defer f.Close()
|
|
|
|
|
|
|
|
if _, err := fmt.Fprintf(f, "changeprofile %s", name); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|