Skip to content

Commit

Permalink
Merge pull request #435 from pmorie/selinux-doc
Browse files Browse the repository at this point in the history
Add godoc for selinux package
  • Loading branch information
Mrunal Patel committed Mar 6, 2015
2 parents 074441b + 4fc2922 commit 83663f8
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions selinux/selinux.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ var (
spaceRegex = regexp.MustCompile(`^([^=]+) (.*)$`)
mcsList = make(map[string]bool)
selinuxfs = "unknown"
selinuxEnabled = false
selinuxEnabledChecked = false
selinuxEnabled = false // Stores whether selinux is currently enabled
selinuxEnabledChecked = false // Stores whether selinux enablement has been checked or established yet
)

type SELinuxContext map[string]string
Expand All @@ -48,6 +48,11 @@ func SetDisabled() {
selinuxEnabled, selinuxEnabledChecked = false, true
}

// getSelinuxMountPoint returns the path to the mountpoint of an selinuxfs
// filesystem or an empty string if no mountpoint is found. Selinuxfs is
// a proc-like pseudo-filesystem that exposes the selinux policy API to
// processes. The existence of an selinuxfs mount is used to determine
// whether selinux is currently enabled or not.
func getSelinuxMountPoint() string {
if selinuxfs != "unknown" {
return selinuxfs
Expand All @@ -74,6 +79,7 @@ func getSelinuxMountPoint() string {
return selinuxfs
}

// SelinuxEnabled returns whether selinux is currently enabled.
func SelinuxEnabled() bool {
if selinuxEnabledChecked {
return selinuxEnabled
Expand Down Expand Up @@ -145,11 +151,12 @@ func readCon(name string) (string, error) {
return val, err
}

// Setfilecon sets the SELinux label for this path or returns an error.
func Setfilecon(path string, scon string) error {
return system.Lsetxattr(path, xattrNameSelinux, []byte(scon), 0)
}

// Return the SELinux label for this path
// Getfilecon returns the SELinux label for this path or returns an error.
func Getfilecon(path string) (string, error) {
con, err := system.Lgetxattr(path, xattrNameSelinux)
return string(con), err
Expand All @@ -163,11 +170,12 @@ func Getfscreatecon() (string, error) {
return readCon(fmt.Sprintf("/proc/self/task/%d/attr/fscreate", syscall.Gettid()))
}

// Return the SELinux label of the current process thread.
// Getcon returns the SELinux label of the current process thread, or an error.
func Getcon() (string, error) {
return readCon(fmt.Sprintf("/proc/self/task/%d/attr/current", syscall.Gettid()))
}

// Getpidcon returns the SELinux label of the given pid, or an error.
func Getpidcon(pid int) (string, error) {
return readCon(fmt.Sprintf("/proc/%d/attr/current", pid))
}
Expand Down

0 comments on commit 83663f8

Please sign in to comment.