|
@@ -39,7 +39,12 @@ var (
|
|
|
|
|
|
type SELinuxContext map[string]string
|
|
|
|
|
|
-func GetSelinuxMountPoint() string {
|
|
|
+// SetDisabled disables selinux support for the package
|
|
|
+func SetDisabled() {
|
|
|
+ selinuxEnabled, selinuxEnabledChecked = false, true
|
|
|
+}
|
|
|
+
|
|
|
+func getSelinuxMountPoint() string {
|
|
|
if selinuxfs != "unknown" {
|
|
|
return selinuxfs
|
|
|
}
|
|
@@ -70,15 +75,15 @@ func SelinuxEnabled() bool {
|
|
|
return selinuxEnabled
|
|
|
}
|
|
|
selinuxEnabledChecked = true
|
|
|
- if fs := GetSelinuxMountPoint(); fs != "" {
|
|
|
- if con, _ := Getcon(); con != "kernel" {
|
|
|
+ if fs := getSelinuxMountPoint(); fs != "" {
|
|
|
+ if con, _ := getcon(); con != "kernel" {
|
|
|
selinuxEnabled = true
|
|
|
}
|
|
|
}
|
|
|
return selinuxEnabled
|
|
|
}
|
|
|
|
|
|
-func ReadConfig(target string) (value string) {
|
|
|
+func readConfig(target string) (value string) {
|
|
|
var (
|
|
|
val, key string
|
|
|
bufin *bufio.Reader
|
|
@@ -119,8 +124,8 @@ func ReadConfig(target string) (value string) {
|
|
|
return ""
|
|
|
}
|
|
|
|
|
|
-func GetSELinuxPolicyRoot() string {
|
|
|
- return selinuxDir + ReadConfig(selinuxTypeTag)
|
|
|
+func getSELinuxPolicyRoot() string {
|
|
|
+ return selinuxDir + readConfig(selinuxTypeTag)
|
|
|
}
|
|
|
|
|
|
func readCon(name string) (string, error) {
|
|
@@ -140,15 +145,6 @@ func Setfilecon(path string, scon string) error {
|
|
|
return system.Lsetxattr(path, xattrNameSelinux, []byte(scon), 0)
|
|
|
}
|
|
|
|
|
|
-func Getfilecon(path string) (string, error) {
|
|
|
- var scon []byte
|
|
|
-
|
|
|
- cnt, err := syscall.Getxattr(path, xattrNameSelinux, scon)
|
|
|
- scon = make([]byte, cnt)
|
|
|
- cnt, err = syscall.Getxattr(path, xattrNameSelinux, scon)
|
|
|
- return string(scon), err
|
|
|
-}
|
|
|
-
|
|
|
func Setfscreatecon(scon string) error {
|
|
|
return writeCon("/proc/self/attr/fscreate", scon)
|
|
|
}
|
|
@@ -157,7 +153,7 @@ func Getfscreatecon() (string, error) {
|
|
|
return readCon("/proc/self/attr/fscreate")
|
|
|
}
|
|
|
|
|
|
-func Getcon() (string, error) {
|
|
|
+func getcon() (string, error) {
|
|
|
return readCon("/proc/self/attr/current")
|
|
|
}
|
|
|
|
|
@@ -188,7 +184,7 @@ func writeCon(name string, val string) error {
|
|
|
}
|
|
|
|
|
|
func Setexeccon(scon string) error {
|
|
|
- return writeCon(fmt.Sprintf("/proc/self/task/%d/attr/exec", syscall.Gettid()), scon)
|
|
|
+ return writeCon(fmt.Sprintf("/proc/self/task/%d/attr/exec", system.Gettid()), scon)
|
|
|
}
|
|
|
|
|
|
func (c SELinuxContext) Get() string {
|
|
@@ -224,7 +220,7 @@ func SelinuxGetEnforce() int {
|
|
|
}
|
|
|
|
|
|
func SelinuxGetEnforceMode() int {
|
|
|
- switch ReadConfig(selinuxTag) {
|
|
|
+ switch readConfig(selinuxTag) {
|
|
|
case "enforcing":
|
|
|
return Enforcing
|
|
|
case "permissive":
|
|
@@ -296,13 +292,6 @@ func uniqMcs(catRange uint32) string {
|
|
|
return mcs
|
|
|
}
|
|
|
|
|
|
-func FreeContext(con string) {
|
|
|
- if con != "" {
|
|
|
- scon := NewContext(con)
|
|
|
- mcsDelete(scon["level"])
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
func GetLxcContexts() (processLabel string, fileLabel string) {
|
|
|
var (
|
|
|
val, key string
|
|
@@ -312,7 +301,7 @@ func GetLxcContexts() (processLabel string, fileLabel string) {
|
|
|
if !SelinuxEnabled() {
|
|
|
return "", ""
|
|
|
}
|
|
|
- lxcPath := fmt.Sprintf("%s/contexts/lxc_contexts", GetSELinuxPolicyRoot())
|
|
|
+ lxcPath := fmt.Sprintf("%s/contexts/lxc_contexts", getSELinuxPolicyRoot())
|
|
|
in, err := os.Open(lxcPath)
|
|
|
if err != nil {
|
|
|
return "", ""
|