Merge pull request #5002 from crosbymichael/rhatdan-selinux
Improve selinux label handling
This commit is contained in:
commit
c05f329be8
3 changed files with 17 additions and 17 deletions
|
@ -6,7 +6,7 @@ func GenLabels(options string) (string, string, error) {
|
||||||
return "", "", nil
|
return "", "", nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func FormatMountLabel(src string, MountLabel string) string {
|
func FormatMountLabel(src string, mountLabel string) string {
|
||||||
return src
|
return src
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,12 +10,15 @@ import (
|
||||||
|
|
||||||
func GenLabels(options string) (string, string, error) {
|
func GenLabels(options string) (string, string, error) {
|
||||||
processLabel, mountLabel := selinux.GetLxcContexts()
|
processLabel, mountLabel := selinux.GetLxcContexts()
|
||||||
var err error
|
|
||||||
if processLabel == "" { // SELinux is disabled
|
if processLabel == "" { // SELinux is disabled
|
||||||
return "", "", err
|
return "", "", nil
|
||||||
}
|
}
|
||||||
s := strings.Fields(options)
|
|
||||||
l := len(s)
|
var (
|
||||||
|
err error
|
||||||
|
s = strings.Fields(options)
|
||||||
|
l = len(s)
|
||||||
|
)
|
||||||
if l > 0 {
|
if l > 0 {
|
||||||
pcon := selinux.NewContext(processLabel)
|
pcon := selinux.NewContext(processLabel)
|
||||||
for i := 0; i < l; i++ {
|
for i := 0; i < l; i++ {
|
||||||
|
@ -28,19 +31,16 @@ func GenLabels(options string) (string, string, error) {
|
||||||
return processLabel, mountLabel, err
|
return processLabel, mountLabel, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func FormatMountLabel(src string, MountLabel string) string {
|
func FormatMountLabel(src string, mountLabel string) string {
|
||||||
var mountLabel string
|
if mountLabel != "" {
|
||||||
if src != "" {
|
switch src {
|
||||||
mountLabel = src
|
case "":
|
||||||
if MountLabel != "" {
|
src = fmt.Sprintf("%s,context=%s", src, mountLabel)
|
||||||
mountLabel = fmt.Sprintf("%s,context=\"%s\"", mountLabel, MountLabel)
|
default:
|
||||||
}
|
src = fmt.Sprintf("context=%s", mountLabel)
|
||||||
} else {
|
|
||||||
if MountLabel != "" {
|
|
||||||
mountLabel = fmt.Sprintf("context=\"%s\"", MountLabel)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return mountLabel
|
return src
|
||||||
}
|
}
|
||||||
|
|
||||||
func SetProcessLabel(processLabel string) error {
|
func SetProcessLabel(processLabel string) error {
|
||||||
|
|
|
@ -312,7 +312,7 @@ func GetLxcContexts() (processLabel string, fileLabel string) {
|
||||||
if !SelinuxEnabled() {
|
if !SelinuxEnabled() {
|
||||||
return "", ""
|
return "", ""
|
||||||
}
|
}
|
||||||
lxcPath := fmt.Sprintf("%s/content/lxc_contexts", GetSELinuxPolicyRoot())
|
lxcPath := fmt.Sprintf("%s/contexts/lxc_contexts", GetSELinuxPolicyRoot())
|
||||||
in, err := os.Open(lxcPath)
|
in, err := os.Open(lxcPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", ""
|
return "", ""
|
||||||
|
|
Loading…
Reference in a new issue