2014-03-05 19:59:31 +00:00
|
|
|
package apparmor
|
|
|
|
|
2014-03-06 19:10:58 +00:00
|
|
|
// #cgo LDFLAGS: -lapparmor
|
|
|
|
// #include <sys/apparmor.h>
|
|
|
|
// #include <stdlib.h>
|
|
|
|
import "C"
|
2014-03-05 19:59:31 +00:00
|
|
|
import (
|
|
|
|
"io/ioutil"
|
2014-03-06 19:10:58 +00:00
|
|
|
"unsafe"
|
2014-03-05 19:59:31 +00:00
|
|
|
)
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2014-03-06 19:10:58 +00:00
|
|
|
cName := C.CString(name)
|
|
|
|
defer C.free(unsafe.Pointer(cName))
|
2014-03-05 19:59:31 +00:00
|
|
|
|
2014-03-06 19:10:58 +00:00
|
|
|
if _, err := C.aa_change_onexec(cName); err != nil {
|
2014-03-05 19:59:31 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|