2014-03-06 15:39:17 -05:00
|
|
|
// +build apparmor,linux,amd64
|
2014-03-06 15:04:51 -05:00
|
|
|
|
2014-03-05 14:59:31 -05:00
|
|
|
package apparmor
|
|
|
|
|
2014-03-06 14:10:58 -05:00
|
|
|
// #cgo LDFLAGS: -lapparmor
|
|
|
|
// #include <sys/apparmor.h>
|
|
|
|
// #include <stdlib.h>
|
|
|
|
import "C"
|
2014-03-05 14:59:31 -05:00
|
|
|
import (
|
|
|
|
"io/ioutil"
|
2014-04-13 10:20:04 -04:00
|
|
|
"os"
|
2014-03-06 14:10:58 -05:00
|
|
|
"unsafe"
|
2014-03-05 14:59:31 -05:00
|
|
|
)
|
|
|
|
|
2014-03-05 15:27:31 -05:00
|
|
|
func IsEnabled() bool {
|
2014-04-13 10:20:04 -04:00
|
|
|
if _, err := os.Stat("/sys/kernel/security/apparmor"); err == nil {
|
|
|
|
buf, err := ioutil.ReadFile("/sys/module/apparmor/parameters/enabled")
|
|
|
|
return err == nil && len(buf) > 1 && buf[0] == 'Y'
|
|
|
|
}
|
|
|
|
return false
|
2014-03-05 14:59:31 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func ApplyProfile(pid int, name string) error {
|
2014-04-09 06:22:17 -04:00
|
|
|
if name == "" {
|
2014-03-05 15:27:31 -05:00
|
|
|
return nil
|
2014-03-05 14:59:31 -05:00
|
|
|
}
|
|
|
|
|
2014-03-06 14:10:58 -05:00
|
|
|
cName := C.CString(name)
|
|
|
|
defer C.free(unsafe.Pointer(cName))
|
2014-03-05 14:59:31 -05:00
|
|
|
|
2014-03-06 14:10:58 -05:00
|
|
|
if _, err := C.aa_change_onexec(cName); err != nil {
|
2014-03-05 14:59:31 -05:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|