2f2e1a
diff --git libselinux-2.5/ChangeLog libselinux-2.5/ChangeLog
2f2e1a
index 24673dd..41507e4 100644
2f2e1a
--- libselinux-2.5/ChangeLog
2f2e1a
+++ libselinux-2.5/ChangeLog
2f2e1a
@@ -1,3 +1,20 @@
2f2e1a
+	* Handle NULL pcre study data, from Stephen Smalley.
2f2e1a
+	* Fix in tree compilation of utils that depend on libsepol, from Laurent Bigonville.
2f2e1a
+	* Clarify is_selinux_mls_enabled() description, from David King.
2f2e1a
+	* Explain how to free policy type from selinux_getpolicytype(), from David King.
2f2e1a
+	* Compare absolute pathname in matchpathcon -V, from Petr Lautrbach.
2f2e1a
+	* Add selinux_snapperd_contexts_path(), from Petr Lautrbach.
2f2e1a
+	* Modify audit2why analyze function to use loaded policy, from Joshua Brindle.
2f2e1a
+	* Sort object files for deterministic linking order, from Laurent Bigonville.
2f2e1a
+	* Respect CC and PKG_CONFIG environment variable, from Julien Pivotto.
2f2e1a
+	* Avoid mounting /proc outside of selinux_init_load_policy(), from Stephen Smalley.
2f2e1a
+	* Fix multiple spelling errors, from Laurent Bigonville.
2f2e1a
+	* Fix typo in sefcontext_compile.8, from Petr Lautrbach and Milos Malik
2f2e1a
+	* Fix location of selinuxfs mount point, from Dan Walsh.
2f2e1a
+	* Only mount /proc if necessary, from Stephen Smalley.
2f2e1a
+	* procattr: return einval for <= 0 pid args, from Daniel Cashman.
2f2e1a
+	* procattr: return error on invalid pid_t input, from Daniel Cashman.
2f2e1a
+
2f2e1a
 2.5 2016-02-23
2f2e1a
 	* selinux_restorecon.3 man page corrections, from Richard Haines.
2f2e1a
 	* Add selinux_restorecon function, from Richard Haines.
2f2e1a
diff --git libselinux-2.5/Makefile libselinux-2.5/Makefile
2f2e1a
index 6142b60..bdf9de8 100644
2f2e1a
--- libselinux-2.5/Makefile
2f2e1a
+++ libselinux-2.5/Makefile
2f2e1a
@@ -1,4 +1,4 @@
2f2e1a
-SUBDIRS = src include utils man
2f2e1a
+SUBDIRS = src include utils man golang
2f2e1a
 
2f2e1a
 DISABLE_AVC ?= n
2f2e1a
 DISABLE_SETRANS ?= n
2f2e1a
diff --git libselinux-2.5/golang/Makefile libselinux-2.5/golang/Makefile
2f2e1a
new file mode 100644
2f2e1a
index 0000000..b75677b
2f2e1a
--- /dev/null
2f2e1a
+++ libselinux-2.5/golang/Makefile
2f2e1a
@@ -0,0 +1,22 @@
2f2e1a
+# Installation directories.
2f2e1a
+PREFIX ?= $(DESTDIR)/usr
2f2e1a
+LIBDIR ?= $(DESTDIR)/usr/lib
2f2e1a
+GODIR ?= $(LIBDIR)/golang/src/pkg/github.com/selinux
2f2e1a
+all:
2f2e1a
+
2f2e1a
+install: 
2f2e1a
+	[ -d $(GODIR) ] || mkdir -p $(GODIR)
2f2e1a
+	install -m 644 selinux.go $(GODIR)
2f2e1a
+
2f2e1a
+test:
2f2e1a
+	@mkdir selinux
2f2e1a
+	@cp selinux.go selinux
2f2e1a
+	GOPATH=$(pwd) go run test.go 
2f2e1a
+	@rm -rf selinux
2f2e1a
+
2f2e1a
+clean:
2f2e1a
+	@rm -f *~
2f2e1a
+	@rm -rf selinux
2f2e1a
+indent:
2f2e1a
+
2f2e1a
+relabel:
2f2e1a
diff --git libselinux-2.5/golang/selinux.go libselinux-2.5/golang/selinux.go
2f2e1a
new file mode 100644
2f2e1a
index 0000000..34bf6bb
2f2e1a
--- /dev/null
2f2e1a
+++ libselinux-2.5/golang/selinux.go
2f2e1a
@@ -0,0 +1,412 @@
2f2e1a
+package selinux
2f2e1a
+
2f2e1a
+/*
2f2e1a
+ The selinux package is a go bindings to libselinux required to add selinux
2f2e1a
+ support to docker.
2f2e1a
+
2f2e1a
+ Author Dan Walsh <dwalsh@redhat.com>
2f2e1a
+
2f2e1a
+ Used some ideas/code from the go-ini packages https://github.com/vaughan0
2f2e1a
+ By Vaughan Newton
2f2e1a
+*/
2f2e1a
+
2f2e1a
+// #cgo pkg-config: libselinux
2f2e1a
+// #include <selinux/selinux.h>
2f2e1a
+// #include <stdlib.h>
2f2e1a
+import "C"
2f2e1a
+import (
2f2e1a
+	"bufio"
2f2e1a
+	"crypto/rand"
2f2e1a
+	"encoding/binary"
2f2e1a
+	"fmt"
2f2e1a
+	"io"
2f2e1a
+	"os"
2f2e1a
+	"path"
2f2e1a
+	"path/filepath"
2f2e1a
+	"regexp"
2f2e1a
+	"strings"
2f2e1a
+	"unsafe"
2f2e1a
+)
2f2e1a
+
2f2e1a
+var (
2f2e1a
+	assignRegex = regexp.MustCompile(`^([^=]+)=(.*)$`)
2f2e1a
+	mcsList     = make(map[string]bool)
2f2e1a
+)
2f2e1a
+
2f2e1a
+func Matchpathcon(path string, mode os.FileMode) (string, error) {
2f2e1a
+	var con C.security_context_t
2f2e1a
+	var scon string
2f2e1a
+	rc, err := C.matchpathcon(C.CString(path), C.mode_t(mode), &con)
2f2e1a
+	if rc == 0 {
2f2e1a
+		scon = C.GoString(con)
2f2e1a
+		C.free(unsafe.Pointer(con))
2f2e1a
+	}
2f2e1a
+	return scon, err
2f2e1a
+}
2f2e1a
+
2f2e1a
+func Setfilecon(path, scon string) (int, error) {
2f2e1a
+	rc, err := C.lsetfilecon(C.CString(path), C.CString(scon))
2f2e1a
+	return int(rc), err
2f2e1a
+}
2f2e1a
+
2f2e1a
+func Getfilecon(path string) (string, error) {
2f2e1a
+	var scon C.security_context_t
2f2e1a
+	var fcon string
2f2e1a
+	rc, err := C.lgetfilecon(C.CString(path), &scon)
2f2e1a
+	if rc >= 0 {
2f2e1a
+		fcon = C.GoString(scon)
2f2e1a
+		err = nil
2f2e1a
+	}
2f2e1a
+	return fcon, err
2f2e1a
+}
2f2e1a
+
2f2e1a
+func Setfscreatecon(scon string) (int, error) {
2f2e1a
+	var (
2f2e1a
+		rc  C.int
2f2e1a
+		err error
2f2e1a
+	)
2f2e1a
+	if scon != "" {
2f2e1a
+		rc, err = C.setfscreatecon(C.CString(scon))
2f2e1a
+	} else {
2f2e1a
+		rc, err = C.setfscreatecon(nil)
2f2e1a
+	}
2f2e1a
+	return int(rc), err
2f2e1a
+}
2f2e1a
+
2f2e1a
+func Getfscreatecon() (string, error) {
2f2e1a
+	var scon C.security_context_t
2f2e1a
+	var fcon string
2f2e1a
+	rc, err := C.getfscreatecon(&scon)
2f2e1a
+	if rc >= 0 {
2f2e1a
+		fcon = C.GoString(scon)
2f2e1a
+		err = nil
2f2e1a
+		C.freecon(scon)
2f2e1a
+	}
2f2e1a
+	return fcon, err
2f2e1a
+}
2f2e1a
+
2f2e1a
+func Getcon() string {
2f2e1a
+	var pcon C.security_context_t
2f2e1a
+	C.getcon(&pcon)
2f2e1a
+	scon := C.GoString(pcon)
2f2e1a
+	C.freecon(pcon)
2f2e1a
+	return scon
2f2e1a
+}
2f2e1a
+
2f2e1a
+func Getpidcon(pid int) (string, error) {
2f2e1a
+	var pcon C.security_context_t
2f2e1a
+	var scon string
2f2e1a
+	rc, err := C.getpidcon(C.pid_t(pid), &pcon)
2f2e1a
+	if rc >= 0 {
2f2e1a
+		scon = C.GoString(pcon)
2f2e1a
+		C.freecon(pcon)
2f2e1a
+		err = nil
2f2e1a
+	}
2f2e1a
+	return scon, err
2f2e1a
+}
2f2e1a
+
2f2e1a
+func Getpeercon(socket int) (string, error) {
2f2e1a
+	var pcon C.security_context_t
2f2e1a
+	var scon string
2f2e1a
+	rc, err := C.getpeercon(C.int(socket), &pcon)
2f2e1a
+	if rc >= 0 {
2f2e1a
+		scon = C.GoString(pcon)
2f2e1a
+		C.freecon(pcon)
2f2e1a
+		err = nil
2f2e1a
+	}
2f2e1a
+	return scon, err
2f2e1a
+}
2f2e1a
+
2f2e1a
+func Setexeccon(scon string) error {
2f2e1a
+	var val *C.char
2f2e1a
+	if !SelinuxEnabled() {
2f2e1a
+		return nil
2f2e1a
+	}
2f2e1a
+	if scon != "" {
2f2e1a
+		val = C.CString(scon)
2f2e1a
+	} else {
2f2e1a
+		val = nil
2f2e1a
+	}
2f2e1a
+	_, err := C.setexeccon(val)
2f2e1a
+	return err
2f2e1a
+}
2f2e1a
+
2f2e1a
+type Context struct {
2f2e1a
+	con []string
2f2e1a
+}
2f2e1a
+
2f2e1a
+func (c *Context) SetUser(user string) {
2f2e1a
+	c.con[0] = user
2f2e1a
+}
2f2e1a
+func (c *Context) GetUser() string {
2f2e1a
+	return c.con[0]
2f2e1a
+}
2f2e1a
+func (c *Context) SetRole(role string) {
2f2e1a
+	c.con[1] = role
2f2e1a
+}
2f2e1a
+func (c *Context) GetRole() string {
2f2e1a
+	return c.con[1]
2f2e1a
+}
2f2e1a
+func (c *Context) SetType(setype string) {
2f2e1a
+	c.con[2] = setype
2f2e1a
+}
2f2e1a
+func (c *Context) GetType() string {
2f2e1a
+	return c.con[2]
2f2e1a
+}
2f2e1a
+func (c *Context) SetLevel(mls string) {
2f2e1a
+	c.con[3] = mls
2f2e1a
+}
2f2e1a
+func (c *Context) GetLevel() string {
2f2e1a
+	return c.con[3]
2f2e1a
+}
2f2e1a
+func (c *Context) Get() string {
2f2e1a
+	return strings.Join(c.con, ":")
2f2e1a
+}
2f2e1a
+func (c *Context) Set(scon string) {
2f2e1a
+	c.con = strings.SplitN(scon, ":", 4)
2f2e1a
+}
2f2e1a
+func NewContext(scon string) Context {
2f2e1a
+	var con Context
2f2e1a
+	con.Set(scon)
2f2e1a
+	return con
2f2e1a
+}
2f2e1a
+
2f2e1a
+func SelinuxEnabled() bool {
2f2e1a
+	b := C.is_selinux_enabled()
2f2e1a
+	if b > 0 {
2f2e1a
+		return true
2f2e1a
+	}
2f2e1a
+	return false
2f2e1a
+}
2f2e1a
+
2f2e1a
+const (
2f2e1a
+	Enforcing  = 1
2f2e1a
+	Permissive = 0
2f2e1a
+	Disabled   = -1
2f2e1a
+)
2f2e1a
+
2f2e1a
+func SelinuxGetEnforce() int {
2f2e1a
+	return int(C.security_getenforce())
2f2e1a
+}
2f2e1a
+
2f2e1a
+func SelinuxGetEnforceMode() int {
2f2e1a
+	var enforce C.int
2f2e1a
+	C.selinux_getenforcemode(&enforce)
2f2e1a
+	return int(enforce)
2f2e1a
+}
2f2e1a
+
2f2e1a
+func mcsAdd(mcs string) {
2f2e1a
+	mcsList[mcs] = true
2f2e1a
+}
2f2e1a
+
2f2e1a
+func mcsDelete(mcs string) {
2f2e1a
+	mcsList[mcs] = false
2f2e1a
+}
2f2e1a
+
2f2e1a
+func mcsExists(mcs string) bool {
2f2e1a
+	return mcsList[mcs]
2f2e1a
+}
2f2e1a
+
2f2e1a
+func IntToMcs(id int, catRange uint32) string {
2f2e1a
+	if (id < 1) || (id > 523776) {
2f2e1a
+		return ""
2f2e1a
+	}
2f2e1a
+
2f2e1a
+	SETSIZE := int(catRange)
2f2e1a
+	TIER := SETSIZE
2f2e1a
+
2f2e1a
+	ORD := id
2f2e1a
+	for ORD > TIER {
2f2e1a
+		ORD = ORD - TIER
2f2e1a
+		TIER -= 1
2f2e1a
+	}
2f2e1a
+	TIER = SETSIZE - TIER
2f2e1a
+	ORD = ORD + TIER
2f2e1a
+	return fmt.Sprintf("s0:c%d,c%d", TIER, ORD)
2f2e1a
+}
2f2e1a
+
2f2e1a
+func uniqMcs(catRange uint32) string {
2f2e1a
+	var n uint32
2f2e1a
+	var c1, c2 uint32
2f2e1a
+	var mcs string
2f2e1a
+	for {
2f2e1a
+		binary.Read(rand.Reader, binary.LittleEndian, &n)
2f2e1a
+		c1 = n % catRange
2f2e1a
+		binary.Read(rand.Reader, binary.LittleEndian, &n)
2f2e1a
+		c2 = n % catRange
2f2e1a
+		if c1 == c2 {
2f2e1a
+			continue
2f2e1a
+		} else {
2f2e1a
+			if c1 > c2 {
2f2e1a
+				t := c1
2f2e1a
+				c1 = c2
2f2e1a
+				c2 = t
2f2e1a
+			}
2f2e1a
+		}
2f2e1a
+		mcs = fmt.Sprintf("s0:c%d,c%d", c1, c2)
2f2e1a
+		if mcsExists(mcs) {
2f2e1a
+			continue
2f2e1a
+		}
2f2e1a
+		mcsAdd(mcs)
2f2e1a
+		break
2f2e1a
+	}
2f2e1a
+	return mcs
2f2e1a
+}
2f2e1a
+func freeContext(processLabel string) {
2f2e1a
+	var scon Context
2f2e1a
+	scon = NewContext(processLabel)
2f2e1a
+	mcsDelete(scon.GetLevel())
2f2e1a
+}
2f2e1a
+
2f2e1a
+func GetLxcContexts() (processLabel string, fileLabel string) {
2f2e1a
+	var val, key string
2f2e1a
+	var bufin *bufio.Reader
2f2e1a
+	if !SelinuxEnabled() {
2f2e1a
+		return
2f2e1a
+	}
2f2e1a
+	lxcPath := C.GoString(C.selinux_lxc_contexts_path())
2f2e1a
+	fileLabel = "system_u:object_r:svirt_sandbox_file_t:s0"
2f2e1a
+	processLabel = "system_u:system_r:svirt_lxc_net_t:s0"
2f2e1a
+
2f2e1a
+	in, err := os.Open(lxcPath)
2f2e1a
+	if err != nil {
2f2e1a
+		goto exit
2f2e1a
+	}
2f2e1a
+
2f2e1a
+	defer in.Close()
2f2e1a
+	bufin = bufio.NewReader(in)
2f2e1a
+
2f2e1a
+	for done := false; !done; {
2f2e1a
+		var line string
2f2e1a
+		if line, err = bufin.ReadString('\n'); err != nil {
2f2e1a
+			if err == io.EOF {
2f2e1a
+				done = true
2f2e1a
+			} else {
2f2e1a
+				goto exit
2f2e1a
+			}
2f2e1a
+		}
2f2e1a
+		line = strings.TrimSpace(line)
2f2e1a
+		if len(line) == 0 {
2f2e1a
+			// Skip blank lines
2f2e1a
+			continue
2f2e1a
+		}
2f2e1a
+		if line[0] == ';' || line[0] == '#' {
2f2e1a
+			// Skip comments
2f2e1a
+			continue
2f2e1a
+		}
2f2e1a
+		if groups := assignRegex.FindStringSubmatch(line); groups != nil {
2f2e1a
+			key, val = strings.TrimSpace(groups[1]), strings.TrimSpace(groups[2])
2f2e1a
+			if key == "process" {
2f2e1a
+				processLabel = strings.Trim(val, "\"")
2f2e1a
+			}
2f2e1a
+			if key == "file" {
2f2e1a
+				fileLabel = strings.Trim(val, "\"")
2f2e1a
+			}
2f2e1a
+		}
2f2e1a
+	}
2f2e1a
+exit:
2f2e1a
+	var scon Context
2f2e1a
+	mcs := IntToMcs(os.Getpid(), 1024)
2f2e1a
+	scon = NewContext(processLabel)
2f2e1a
+	scon.SetLevel(mcs)
2f2e1a
+	processLabel = scon.Get()
2f2e1a
+	scon = NewContext(fileLabel)
2f2e1a
+	scon.SetLevel(mcs)
2f2e1a
+	fileLabel = scon.Get()
2f2e1a
+	return processLabel, fileLabel
2f2e1a
+}
2f2e1a
+
2f2e1a
+func CopyLevel(src, dest string) (string, error) {
2f2e1a
+	if !SelinuxEnabled() {
2f2e1a
+		return "", nil
2f2e1a
+	}
2f2e1a
+	if src == "" {
2f2e1a
+		return "", nil
2f2e1a
+	}
2f2e1a
+	rc, err := C.security_check_context(C.CString(src))
2f2e1a
+	if rc != 0 {
2f2e1a
+		return "", err
2f2e1a
+	}
2f2e1a
+	rc, err = C.security_check_context(C.CString(dest))
2f2e1a
+	if rc != 0 {
2f2e1a
+		return "", err
2f2e1a
+	}
2f2e1a
+	scon := NewContext(src)
2f2e1a
+	tcon := NewContext(dest)
2f2e1a
+	tcon.SetLevel(scon.GetLevel())
2f2e1a
+	return tcon.Get(), nil
2f2e1a
+}
2f2e1a
+
2f2e1a
+func RestoreCon(fpath string, recurse bool) error {
2f2e1a
+	var flabel string
2f2e1a
+	var err error
2f2e1a
+	var fs os.FileInfo
2f2e1a
+
2f2e1a
+	if !SelinuxEnabled() {
2f2e1a
+		return nil
2f2e1a
+	}
2f2e1a
+
2f2e1a
+	if recurse {
2f2e1a
+		var paths []string
2f2e1a
+		var err error
2f2e1a
+
2f2e1a
+		if paths, err = filepath.Glob(path.Join(fpath, "**", "*")); err != nil {
2f2e1a
+			return fmt.Errorf("Unable to find directory %v: %v", fpath, err)
2f2e1a
+		}
2f2e1a
+
2f2e1a
+		for _, fpath := range paths {
2f2e1a
+			if err = RestoreCon(fpath, false); err != nil {
2f2e1a
+				return fmt.Errorf("Unable to restore selinux context for %v: %v", fpath, err)
2f2e1a
+			}
2f2e1a
+		}
2f2e1a
+		return nil
2f2e1a
+	}
2f2e1a
+	if fs, err = os.Stat(fpath); err != nil {
2f2e1a
+		return fmt.Errorf("Unable stat %v: %v", fpath, err)
2f2e1a
+	}
2f2e1a
+
2f2e1a
+	if flabel, err = Matchpathcon(fpath, fs.Mode()); flabel == "" {
2f2e1a
+		return fmt.Errorf("Unable to get context for %v: %v", fpath, err)
2f2e1a
+	}
2f2e1a
+
2f2e1a
+	if rc, err := Setfilecon(fpath, flabel); rc != 0 {
2f2e1a
+		return fmt.Errorf("Unable to set selinux context for %v: %v", fpath, err)
2f2e1a
+	}
2f2e1a
+
2f2e1a
+	return nil
2f2e1a
+}
2f2e1a
+
2f2e1a
+func Test() {
2f2e1a
+	var plabel, flabel string
2f2e1a
+	if !SelinuxEnabled() {
2f2e1a
+		return
2f2e1a
+	}
2f2e1a
+
2f2e1a
+	plabel, flabel = GetLxcContexts()
2f2e1a
+	fmt.Println(plabel)
2f2e1a
+	fmt.Println(flabel)
2f2e1a
+	freeContext(plabel)
2f2e1a
+	plabel, flabel = GetLxcContexts()
2f2e1a
+	fmt.Println(plabel)
2f2e1a
+	fmt.Println(flabel)
2f2e1a
+	freeContext(plabel)
2f2e1a
+	if SelinuxEnabled() {
2f2e1a
+		fmt.Println("Enabled")
2f2e1a
+	} else {
2f2e1a
+		fmt.Println("Disabled")
2f2e1a
+	}
2f2e1a
+	fmt.Println("getenforce ", SelinuxGetEnforce())
2f2e1a
+	fmt.Println("getenforcemode ", SelinuxGetEnforceMode())
2f2e1a
+	flabel, _ = Matchpathcon("/home/dwalsh/.emacs", 0)
2f2e1a
+	fmt.Println(flabel)
2f2e1a
+	pid := os.Getpid()
2f2e1a
+	fmt.Printf("PID:%d MCS:%s\n", pid, IntToMcs(pid, 1023))
2f2e1a
+	fmt.Println(Getcon())
2f2e1a
+	fmt.Println(Getfilecon("/etc/passwd"))
2f2e1a
+	fmt.Println(Getpidcon(1))
2f2e1a
+	Setfscreatecon("unconfined_u:unconfined_r:unconfined_t:s0")
2f2e1a
+	fmt.Println(Getfscreatecon())
2f2e1a
+	Setfscreatecon("")
2f2e1a
+	fmt.Println(Getfscreatecon())
2f2e1a
+	fmt.Println(Getpidcon(1))
2f2e1a
+}
2f2e1a
diff --git libselinux-2.5/golang/test.go libselinux-2.5/golang/test.go
2f2e1a
new file mode 100644
2f2e1a
index 0000000..fed6de8
2f2e1a
--- /dev/null
2f2e1a
+++ libselinux-2.5/golang/test.go
2f2e1a
@@ -0,0 +1,9 @@
2f2e1a
+package main
2f2e1a
+
2f2e1a
+import (
2f2e1a
+	"./selinux"
2f2e1a
+)
2f2e1a
+
2f2e1a
+func main() {
2f2e1a
+	selinux.Test()
2f2e1a
+}
73af03
diff --git libselinux-2.5/include/selinux/av_permissions.h libselinux-2.5/include/selinux/av_permissions.h
73af03
index c1269af..631f027 100644
73af03
--- libselinux-2.5/include/selinux/av_permissions.h
73af03
+++ libselinux-2.5/include/selinux/av_permissions.h
73af03
@@ -876,6 +876,8 @@
73af03
 #define NSCD__SHMEMHOST                           0x00000080UL
73af03
 #define NSCD__GETSERV                             0x00000100UL
73af03
 #define NSCD__SHMEMSERV                           0x00000200UL
73af03
+#define NSCD__GETNETGRP                           0x00000400UL
73af03
+#define NSCD__SHMEMNETGRP                         0x00000800UL
73af03
 #define ASSOCIATION__SENDTO                       0x00000001UL
73af03
 #define ASSOCIATION__RECVFROM                     0x00000002UL
73af03
 #define ASSOCIATION__SETCONTEXT                   0x00000004UL
2f2e1a
diff --git libselinux-2.5/include/selinux/selinux.h libselinux-2.5/include/selinux/selinux.h
2f2e1a
index 2262086..3d8673f 100644
2f2e1a
--- libselinux-2.5/include/selinux/selinux.h
2f2e1a
+++ libselinux-2.5/include/selinux/selinux.h
2f2e1a
@@ -544,6 +544,7 @@ extern const char *selinux_lxc_contexts_path(void);
2f2e1a
 extern const char *selinux_x_context_path(void);
2f2e1a
 extern const char *selinux_sepgsql_context_path(void);
2f2e1a
 extern const char *selinux_openssh_contexts_path(void);
2f2e1a
+extern const char *selinux_snapperd_contexts_path(void);
2f2e1a
 extern const char *selinux_systemd_contexts_path(void);
2f2e1a
 extern const char *selinux_contexts_path(void);
2f2e1a
 extern const char *selinux_securetty_types_path(void);
2f2e1a
diff --git libselinux-2.5/man/man3/avc_add_callback.3 libselinux-2.5/man/man3/avc_add_callback.3
2f2e1a
index dbfe72d..bdbbadf 100644
2f2e1a
--- libselinux-2.5/man/man3/avc_add_callback.3
2f2e1a
+++ libselinux-2.5/man/man3/avc_add_callback.3
2f2e1a
@@ -57,7 +57,7 @@ and will cause any SID to match.
2f2e1a
 .I callback
2f2e1a
 is the callback function provided by the userspace object manager.  The
2f2e1a
 .I event
2f2e1a
-argument indicates the security event which occured; the remaining arguments
2f2e1a
+argument indicates the security event which occurred; the remaining arguments
2f2e1a
 are interpreted according to the event as described below.  The return value
2f2e1a
 of the callback should be zero on success, \-1 on error with
2f2e1a
 .I errno
2f2e1a
@@ -175,7 +175,7 @@ If the userspace AVC is running in threaded mode, callbacks registered via
2f2e1a
 may be executed in the context of the netlink handler thread.  This will likely introduce synchronization issues requiring the use of locks.  See
2f2e1a
 .BR avc_init (3).
2f2e1a
 
2f2e1a
-Support for dynamic revocation and retained permissions is mostly unimplemented in the SELinux kernel module.  The only security event that currently gets excercised is
2f2e1a
+Support for dynamic revocation and retained permissions is mostly unimplemented in the SELinux kernel module.  The only security event that currently gets exercised is
2f2e1a
 .BR AVC_CALLBACK_RESET .
2f2e1a
 .
2f2e1a
 .SH "AUTHOR"
2f2e1a
diff --git libselinux-2.5/man/man3/avc_has_perm.3 libselinux-2.5/man/man3/avc_has_perm.3
2f2e1a
index 7353952..3e9fca8 100644
2f2e1a
--- libselinux-2.5/man/man3/avc_has_perm.3
2f2e1a
+++ libselinux-2.5/man/man3/avc_has_perm.3
2f2e1a
@@ -108,7 +108,7 @@ for the first time.
2f2e1a
 Using an uninitialized structure will produce undefined behavior.
2f2e1a
 .
2f2e1a
 .SH "RETURN VALUE"
2f2e1a
-If requested permissions are granted, zero is returned.  If requested permissions are denied or an error occured, \-1 is returned and
2f2e1a
+If requested permissions are granted, zero is returned.  If requested permissions are denied or an error occurred, \-1 is returned and
2f2e1a
 .I errno
2f2e1a
 is set appropriately.
2f2e1a
 
2f2e1a
diff --git libselinux-2.5/man/man3/is_selinux_enabled.3 libselinux-2.5/man/man3/is_selinux_enabled.3
2f2e1a
index f02052c..df62c22 100644
2f2e1a
--- libselinux-2.5/man/man3/is_selinux_enabled.3
2f2e1a
+++ libselinux-2.5/man/man3/is_selinux_enabled.3
2f2e1a
@@ -3,7 +3,7 @@
2f2e1a
 is_selinux_enabled \- check whether SELinux is enabled
2f2e1a
 .
2f2e1a
 .SH "NAME"
2f2e1a
-is_selinux_mls_enabled \- check whether SELinux is enabled for (Multi Level Securty) MLS 
2f2e1a
+is_selinux_mls_enabled \- check whether SELinux is enabled for (Multi Level Security) MLS
2f2e1a
 .
2f2e1a
 .SH "SYNOPSIS"
2f2e1a
 .B #include <selinux/selinux.h>
2f2e1a
@@ -18,7 +18,9 @@ returns 1 if SELinux is running or 0 if it is not.
2f2e1a
 On error, \-1 is returned.
2f2e1a
 
2f2e1a
 .BR is_selinux_mls_enabled ()
2f2e1a
-returns 1 if SELinux is running in MLS mode or 0 if it is not. 
2f2e1a
+returns 1 if SELinux is capable of running in MLS mode or 0 if it is not. To
2f2e1a
+determine the policy in use on the system, use
2f2e1a
+.BR selinux_getpolicytype (3).
2f2e1a
 .
2f2e1a
 .SH "SEE ALSO"
2f2e1a
 .BR selinux "(8)"
2f2e1a
diff --git libselinux-2.5/man/man3/security_disable.3 libselinux-2.5/man/man3/security_disable.3
2f2e1a
index c75ce0d..072923c 100644
2f2e1a
--- libselinux-2.5/man/man3/security_disable.3
2f2e1a
+++ libselinux-2.5/man/man3/security_disable.3
2f2e1a
@@ -12,7 +12,7 @@ security_disable \- disable the SELinux kernel code at runtime
2f2e1a
 disables the SELinux kernel code, unregisters selinuxfs from
2f2e1a
 .IR /proc/filesystems ,
2f2e1a
 and then unmounts
2f2e1a
-.IR /selinux .
2f2e1a
+.IR /sys/fs/selinux .
2f2e1a
 .sp
2f2e1a
 This function can only be called at runtime and prior to the initial policy
2f2e1a
 load. After the initial policy load, the SELinux kernel code cannot be disabled,
2f2e1a
diff --git libselinux-2.5/man/man3/selinux_getpolicytype.3 libselinux-2.5/man/man3/selinux_getpolicytype.3
2f2e1a
index c947e2c..b219d42 100644
2f2e1a
--- libselinux-2.5/man/man3/selinux_getpolicytype.3
2f2e1a
+++ libselinux-2.5/man/man3/selinux_getpolicytype.3
2f2e1a
@@ -13,7 +13,10 @@ Reads the contents of the
2f2e1a
 .I /etc/selinux/config
2f2e1a
 file to determine the SELinux policy used on the system, and sets
2f2e1a
 .I \%policytype
2f2e1a
-accordinly.
2f2e1a
+accordingly. Free
2f2e1a
+.I \%policytype
2f2e1a
+with
2f2e1a
+.BR free (3).
2f2e1a
 .
2f2e1a
 .SH "RETURN VALUE"
2f2e1a
 On success, zero is returned.
2f2e1a
diff --git libselinux-2.5/man/man3/selinux_status_open.3 libselinux-2.5/man/man3/selinux_status_open.3
2f2e1a
index f779dd9..2d44be5 100644
2f2e1a
--- libselinux-2.5/man/man3/selinux_status_open.3
2f2e1a
+++ libselinux-2.5/man/man3/selinux_status_open.3
2f2e1a
@@ -23,7 +23,7 @@ without invocation of system calls
2f2e1a
 .SH "DESCRIPTION"
2f2e1a
 Linux 2.6.37 or later provides a SELinux kernel status page; being mostly
2f2e1a
 placed on
2f2e1a
-.I /selinux/status
2f2e1a
+.I /sys/fs/selinux/status
2f2e1a
 entry. It enables userspace applications to mmap this page with read-only
2f2e1a
 mode, then it informs some status without system call invocations.
2f2e1a
 .sp
2f2e1a
@@ -38,7 +38,7 @@ without system-call invocation or worker thread for monitoring.
2f2e1a
 .BR selinux_status_open ()
2f2e1a
 tries to
2f2e1a
 .BR open (2)
2f2e1a
-.I /selinux/status
2f2e1a
+.I /sys/fs/selinux/status
2f2e1a
 and
2f2e1a
 .BR mmap (2)
2f2e1a
 it in read-only mode. The file-descriptor and pointer to the page shall
2f2e1a
diff --git libselinux-2.5/man/man8/avcstat.8 libselinux-2.5/man/man8/avcstat.8
2f2e1a
index 204687d..2c4bce1 100644
2f2e1a
--- libselinux-2.5/man/man8/avcstat.8
2f2e1a
+++ libselinux-2.5/man/man8/avcstat.8
2f2e1a
@@ -25,7 +25,7 @@ Display the cumulative values.
2f2e1a
 .TP
2f2e1a
 .B \-f
2f2e1a
 Specifies the location of the AVC statistics file, defaulting to
2f2e1a
-.IR /selinux/avc/cache_stats .
2f2e1a
+.IR /sys/fs/selinux/avc/cache_stats .
2f2e1a
 .
2f2e1a
 .SH AUTHOR
2f2e1a
 This manual page was written by Dan Walsh <dwalsh@redhat.com>.
2f2e1a
diff --git libselinux-2.5/man/man8/sefcontext_compile.8 libselinux-2.5/man/man8/sefcontext_compile.8
2f2e1a
index b77ff3a..4eae173 100644
2f2e1a
--- libselinux-2.5/man/man8/sefcontext_compile.8
2f2e1a
+++ libselinux-2.5/man/man8/sefcontext_compile.8
2f2e1a
@@ -13,14 +13,14 @@ sefcontext_compile \- compile file context regular expression files
2f2e1a
 .SH "DESCRIPTION"
2f2e1a
 .B sefcontext_compile
2f2e1a
 is used to compile file context regular expressions into
2f2e1a
-.BR prce (3)
2f2e1a
+.BR pcre (3)
2f2e1a
 format.
2f2e1a
 .sp
2f2e1a
 The compiled file is used by libselinux file labeling functions.
2f2e1a
 .sp
2f2e1a
 By default
2f2e1a
 .B sefcontext_compile
2f2e1a
-writes the compiled prce file with the
2f2e1a
+writes the compiled pcre file with the
2f2e1a
 .B .bin
2f2e1a
 suffix appended (e.g. \fIinputfile\fB.bin\fR).
2f2e1a
 .SH OPTIONS
2f2e1a
diff --git libselinux-2.5/man/man8/selinux.8 libselinux-2.5/man/man8/selinux.8
2f2e1a
index 6f1034b..c9f188c 100644
2f2e1a
--- libselinux-2.5/man/man8/selinux.8
2f2e1a
+++ libselinux-2.5/man/man8/selinux.8
2f2e1a
@@ -91,11 +91,13 @@ This manual page was written by Dan Walsh <dwalsh@redhat.com>.
2f2e1a
 .BR sepolicy (8),
2f2e1a
 .BR system-config-selinux (8),
2f2e1a
 .BR togglesebool (8),
2f2e1a
-.BR restorecon (8),
2f2e1a
 .BR fixfiles (8),
2f2e1a
+.BR restorecon (8),
2f2e1a
 .BR setfiles (8),
2f2e1a
 .BR semanage (8),
2f2e1a
-.BR sepolicy(8)
2f2e1a
+.BR sepolicy(8),
2f2e1a
+.BR seinfo(8),
2f2e1a
+.BR sesearch(8)
2f2e1a
 
2f2e1a
 Every confined service on the system has a man page in the following format:
2f2e1a
 .br
2f2e1a
diff --git libselinux-2.5/src/Makefile libselinux-2.5/src/Makefile
2f2e1a
index d0021ae..d94163e 100644
2f2e1a
--- libselinux-2.5/src/Makefile
2f2e1a
+++ libselinux-2.5/src/Makefile
2f2e1a
@@ -5,6 +5,7 @@ PYTHON ?= python
2f2e1a
 PYPREFIX ?= $(notdir $(PYTHON))
2f2e1a
 RUBY ?= ruby
2f2e1a
 RUBYPREFIX ?= $(notdir $(RUBY))
2f2e1a
+PKG_CONFIG ?= pkg-config
2f2e1a
 
2f2e1a
 # Installation directories.
2f2e1a
 PREFIX ?= $(DESTDIR)/usr
2f2e1a
@@ -12,11 +13,11 @@ LIBDIR ?= $(PREFIX)/lib
2f2e1a
 SHLIBDIR ?= $(DESTDIR)/lib
2f2e1a
 INCLUDEDIR ?= $(PREFIX)/include
2f2e1a
 PYLIBVER ?= $(shell $(PYTHON) -c 'import sys;print("python%d.%d" % sys.version_info[0:2])')
2f2e1a
-PYINC ?= $(shell pkg-config --cflags $(PYPREFIX))
2f2e1a
+PYINC ?= $(shell $(PKG_CONFIG) --cflags $(PYPREFIX))
2f2e1a
 PYLIBDIR ?= $(LIBDIR)/$(PYLIBVER)
2f2e1a
 RUBYLIBVER ?= $(shell $(RUBY) -e 'print RUBY_VERSION.split(".")[0..1].join(".")')
2f2e1a
 RUBYPLATFORM ?= $(shell $(RUBY) -e 'print RUBY_PLATFORM')
2f2e1a
-RUBYINC ?= $(shell pkg-config --cflags ruby)
2f2e1a
+RUBYINC ?= $(shell $(PKG_CONFIG) --cflags ruby)
2f2e1a
 RUBYINSTALL ?= $(LIBDIR)/ruby/site_ruby/$(RUBYLIBVER)/$(RUBYPLATFORM)
2f2e1a
 LIBBASE ?= $(shell basename $(LIBDIR))
2f2e1a
 
2f2e1a
@@ -48,7 +49,7 @@ ifeq ($(DISABLE_BOOL),y)
2f2e1a
 endif
2f2e1a
 
2f2e1a
 GENERATED=$(SWIGCOUT) $(SWIGRUBYCOUT) selinuxswig_python_exception.i
2f2e1a
-SRCS= $(filter-out $(UNUSED_SRCS) $(GENERATED) audit2why.c, $(wildcard *.c))
2f2e1a
+SRCS= $(filter-out $(UNUSED_SRCS) $(GENERATED) audit2why.c, $(sort $(wildcard *.c)))
2f2e1a
 
2f2e1a
 MAX_STACK_SIZE=32768
2f2e1a
 
2f2e1a
diff --git libselinux-2.5/src/audit2why.c libselinux-2.5/src/audit2why.c
73af03
index 12745b3..7aca3f0 100644
2f2e1a
--- libselinux-2.5/src/audit2why.c
2f2e1a
+++ libselinux-2.5/src/audit2why.c
73af03
@@ -206,7 +206,7 @@ static int __policy_init(const char *init_path)
73af03
 				 "unable to open %s:  %s\n",
73af03
 				 path, strerror(errno));
73af03
 			PyErr_SetString( PyExc_ValueError, errormsg);
73af03
-			return 1;
73af03
+			return -1;
73af03
 		}
73af03
 	} else {
73af03
 		const char *curpolicy = selinux_current_policy_path();
73af03
@@ -215,7 +215,7 @@ static int __policy_init(const char *init_path)
73af03
 			snprintf(errormsg, sizeof(errormsg),
73af03
 				 "You must specify the -p option with the path to the policy file.\n");
73af03
 			PyErr_SetString( PyExc_ValueError, errormsg);
73af03
-			return 1;
73af03
+			return -1;
73af03
 		}
73af03
 		fp = fopen(curpolicy, "r");
73af03
 		if (!fp) {
73af03
@@ -224,7 +224,7 @@ static int __policy_init(const char *init_path)
73af03
 				 curpolicy,
73af03
 				 strerror(errno));
73af03
 			PyErr_SetString( PyExc_ValueError, errormsg);
73af03
-			return 1;
73af03
+			return -1;
73af03
 		}
73af03
 	}
73af03
 
73af03
@@ -232,7 +232,7 @@ static int __policy_init(const char *init_path)
73af03
 	if (!avc) {
73af03
 		PyErr_SetString( PyExc_MemoryError, "Out of memory\n");
73af03
 		fclose(fp);
73af03
-		return 1;
73af03
+		return -1;
73af03
 	}
73af03
 
73af03
 	/* Set up a policydb directly so that we can mutate it later
73af03
@@ -244,7 +244,7 @@ static int __policy_init(const char *init_path)
73af03
 			 "policydb_init failed: %s\n", strerror(errno));
73af03
 		PyErr_SetString( PyExc_RuntimeError, errormsg);
73af03
 		fclose(fp);
73af03
-		return 1;
73af03
+		return -1;
73af03
 	}
73af03
 	sepol_policy_file_set_fp(pf, fp);	
73af03
 	if (sepol_policydb_read(avc->policydb, pf)) {
73af03
@@ -252,7 +252,7 @@ static int __policy_init(const char *init_path)
73af03
 			 "invalid binary policy %s\n", path);
73af03
 		PyErr_SetString( PyExc_ValueError, errormsg);
73af03
 		fclose(fp);
73af03
-		return 1;
73af03
+		return -1;
73af03
 	}
73af03
 	fclose(fp);
73af03
 	sepol_set_policydb(&avc->policydb->p);
73af03
@@ -264,13 +264,13 @@ static int __policy_init(const char *init_path)
73af03
 			      avc->policydb, &cnt);
73af03
 	if (rc < 0) {
73af03
 		PyErr_SetString( PyExc_RuntimeError, "unable to get bool count\n");
73af03
-		return 1;
73af03
+		return -1;
73af03
 	}
73af03
 
73af03
 	boollist = calloc(cnt, sizeof(*boollist));
73af03
 	if (!boollist) {
73af03
 		PyErr_SetString( PyExc_MemoryError, "Out of memory\n");
73af03
-		return 1;
73af03
+		return -1;
73af03
 	}
73af03
 
73af03
 	sepol_bool_iterate(avc->handle, avc->policydb,
73af03
@@ -282,7 +282,7 @@ static int __policy_init(const char *init_path)
73af03
 	if (rc < 0) {
73af03
 		PyErr_SetString( PyExc_RuntimeError, "unable to init sidtab\n");
73af03
 		free(boollist);
73af03
-		return 1;
73af03
+		return -1;
73af03
 	}
73af03
 	sepol_set_sidtab(&sidtab);
73af03
 	return 0;
73af03
@@ -298,6 +298,8 @@ static PyObject *init(PyObject *self __attribute__((unused)), PyObject *args) {
73af03
   if (!PyArg_ParseTuple(args,(char *)"|s:policy_init",&init_path))
73af03
     return NULL;
73af03
   result = __policy_init(init_path);
73af03
+  if (result == -1)
73af03
+    return NULL;
73af03
   return Py_BuildValue("i", result);
73af03
 }
73af03
 
73af03
@@ -343,8 +345,8 @@ static PyObject *analyze(PyObject *self __attribute__((unused)) , PyObject *args
2f2e1a
 	if (rc < 0)
2f2e1a
 		RETURN(BADTCON)
2f2e1a
 
2f2e1a
-	tclass = string_to_security_class(tclassstr);
2f2e1a
-	if (!tclass)
2f2e1a
+	rc = sepol_string_to_security_class(tclassstr, &tclass);
2f2e1a
+	if (rc < 0)
2f2e1a
 		RETURN(BADTCLASS)
2f2e1a
 
2f2e1a
 	/* Convert the permission list to an AV. */
73af03
@@ -365,8 +367,8 @@ static PyObject *analyze(PyObject *self __attribute__((unused)) , PyObject *args
2f2e1a
 		permstr = PyString_AsString( strObj );
2f2e1a
 #endif
2f2e1a
 		
2f2e1a
-		perm = string_to_av_perm(tclass, permstr);
2f2e1a
-		if (!perm)
2f2e1a
+		rc = sepol_string_to_av_perm(tclass, permstr, &perm);
2f2e1a
+		if (rc < 0)
2f2e1a
 			RETURN(BADPERM)
2f2e1a
 
2f2e1a
 		av |= perm;
2f2e1a
diff --git libselinux-2.5/src/avc_sidtab.c libselinux-2.5/src/avc_sidtab.c
2f2e1a
index 9669264..c775430 100644
2f2e1a
--- libselinux-2.5/src/avc_sidtab.c
2f2e1a
+++ libselinux-2.5/src/avc_sidtab.c
2f2e1a
@@ -81,6 +81,11 @@ sidtab_context_to_sid(struct sidtab *s,
2f2e1a
 	int hvalue, rc = 0;
2f2e1a
 	struct sidtab_node *cur;
2f2e1a
 
2f2e1a
+	if (! ctx) {
2f2e1a
+		errno=EINVAL;
2f2e1a
+		return -1;
2f2e1a
+	}
2f2e1a
+
2f2e1a
 	*sid = NULL;
2f2e1a
 	hvalue = sidtab_hash(ctx);
2f2e1a
 
73af03
diff --git libselinux-2.5/src/booleans.c libselinux-2.5/src/booleans.c
73af03
index 4b39a28..6a96b4a 100644
73af03
--- libselinux-2.5/src/booleans.c
73af03
+++ libselinux-2.5/src/booleans.c
73af03
@@ -53,6 +53,7 @@ int security_get_boolean_names(char ***names, int *len)
73af03
 	snprintf(path, sizeof path, "%s%s", selinux_mnt, SELINUX_BOOL_DIR);
73af03
 	*len = scandir(path, &namelist, &filename_select, alphasort);
73af03
 	if (*len <= 0) {
73af03
+		errno = ENOENT;
73af03
 		return -1;
73af03
 	}
73af03
 
2f2e1a
diff --git libselinux-2.5/src/canonicalize_context.c libselinux-2.5/src/canonicalize_context.c
2f2e1a
index 7cf3139..364a746 100644
2f2e1a
--- libselinux-2.5/src/canonicalize_context.c
2f2e1a
+++ libselinux-2.5/src/canonicalize_context.c
2f2e1a
@@ -17,6 +17,11 @@ int security_canonicalize_context_raw(const char * con,
2f2e1a
 	size_t size;
2f2e1a
 	int fd, ret;
2f2e1a
 
2f2e1a
+	if (! con) {
2f2e1a
+		errno=EINVAL;
2f2e1a
+		return -1;
2f2e1a
+	}
2f2e1a
+
2f2e1a
 	if (!selinux_mnt) {
2f2e1a
 		errno = ENOENT;
2f2e1a
 		return -1;
2f2e1a
diff --git libselinux-2.5/src/check_context.c libselinux-2.5/src/check_context.c
2f2e1a
index 52063fa..234749c 100644
2f2e1a
--- libselinux-2.5/src/check_context.c
2f2e1a
+++ libselinux-2.5/src/check_context.c
2f2e1a
@@ -14,6 +14,11 @@ int security_check_context_raw(const char * con)
2f2e1a
 	char path[PATH_MAX];
2f2e1a
 	int fd, ret;
2f2e1a
 
2f2e1a
+	if (! con) {
2f2e1a
+		errno=EINVAL;
2f2e1a
+		return -1;
2f2e1a
+	}
2f2e1a
+
2f2e1a
 	if (!selinux_mnt) {
2f2e1a
 		errno = ENOENT;
2f2e1a
 		return -1;
2f2e1a
diff --git libselinux-2.5/src/compute_av.c libselinux-2.5/src/compute_av.c
2f2e1a
index 937e5c3..35ace7f 100644
2f2e1a
--- libselinux-2.5/src/compute_av.c
2f2e1a
+++ libselinux-2.5/src/compute_av.c
2f2e1a
@@ -26,6 +26,11 @@ int security_compute_av_flags_raw(const char * scon,
2f2e1a
 		return -1;
2f2e1a
 	}
2f2e1a
 
2f2e1a
+	if ((! scon) || (! tcon)) {
2f2e1a
+		errno=EINVAL;
2f2e1a
+		return -1;
2f2e1a
+	}
2f2e1a
+
2f2e1a
 	snprintf(path, sizeof path, "%s/access", selinux_mnt);
2f2e1a
 	fd = open(path, O_RDWR);
2f2e1a
 	if (fd < 0)
2f2e1a
diff --git libselinux-2.5/src/compute_create.c libselinux-2.5/src/compute_create.c
2f2e1a
index 9559d42..14a65d1 100644
2f2e1a
--- libselinux-2.5/src/compute_create.c
2f2e1a
+++ libselinux-2.5/src/compute_create.c
2f2e1a
@@ -64,6 +64,11 @@ int security_compute_create_name_raw(const char * scon,
2f2e1a
 		return -1;
2f2e1a
 	}
2f2e1a
 
2f2e1a
+	if ((! scon) || (! tcon)) {
2f2e1a
+		errno=EINVAL;
2f2e1a
+		return -1;
2f2e1a
+	}
2f2e1a
+
2f2e1a
 	snprintf(path, sizeof path, "%s/create", selinux_mnt);
2f2e1a
 	fd = open(path, O_RDWR);
2f2e1a
 	if (fd < 0)
2f2e1a
diff --git libselinux-2.5/src/compute_member.c libselinux-2.5/src/compute_member.c
2f2e1a
index 1fc7e41..065d996 100644
2f2e1a
--- libselinux-2.5/src/compute_member.c
2f2e1a
+++ libselinux-2.5/src/compute_member.c
2f2e1a
@@ -25,6 +25,11 @@ int security_compute_member_raw(const char * scon,
2f2e1a
 		return -1;
2f2e1a
 	}
2f2e1a
 
2f2e1a
+	if ((! scon) || (! tcon)) {
2f2e1a
+		errno=EINVAL;
2f2e1a
+		return -1;
2f2e1a
+	}
2f2e1a
+
2f2e1a
 	snprintf(path, sizeof path, "%s/member", selinux_mnt);
2f2e1a
 	fd = open(path, O_RDWR);
2f2e1a
 	if (fd < 0)
2f2e1a
diff --git libselinux-2.5/src/compute_relabel.c libselinux-2.5/src/compute_relabel.c
2f2e1a
index 4615aee..cc77f36 100644
2f2e1a
--- libselinux-2.5/src/compute_relabel.c
2f2e1a
+++ libselinux-2.5/src/compute_relabel.c
2f2e1a
@@ -25,6 +25,11 @@ int security_compute_relabel_raw(const char * scon,
2f2e1a
 		return -1;
2f2e1a
 	}
2f2e1a
 
2f2e1a
+	if ((! scon) || (! tcon)) {
2f2e1a
+		errno=EINVAL;
2f2e1a
+		return -1;
2f2e1a
+	}
2f2e1a
+
2f2e1a
 	snprintf(path, sizeof path, "%s/relabel", selinux_mnt);
2f2e1a
 	fd = open(path, O_RDWR);
2f2e1a
 	if (fd < 0)
2f2e1a
diff --git libselinux-2.5/src/compute_user.c libselinux-2.5/src/compute_user.c
2f2e1a
index b37c5d3..7703c26 100644
2f2e1a
--- libselinux-2.5/src/compute_user.c
2f2e1a
+++ libselinux-2.5/src/compute_user.c
2f2e1a
@@ -24,6 +24,11 @@ int security_compute_user_raw(const char * scon,
2f2e1a
 		return -1;
2f2e1a
 	}
2f2e1a
 
2f2e1a
+	if (! scon) {
2f2e1a
+		errno=EINVAL;
2f2e1a
+		return -1;
2f2e1a
+	}
2f2e1a
+
2f2e1a
 	snprintf(path, sizeof path, "%s/user", selinux_mnt);
2f2e1a
 	fd = open(path, O_RDWR);
2f2e1a
 	if (fd < 0)
2f2e1a
diff --git libselinux-2.5/src/exception.sh libselinux-2.5/src/exception.sh
2f2e1a
index b7cff7e..a58bf3f 100755
2f2e1a
--- libselinux-2.5/src/exception.sh
2f2e1a
+++ libselinux-2.5/src/exception.sh
2f2e1a
@@ -15,6 +15,6 @@ echo "
2f2e1a
 ;;
2f2e1a
 esac
2f2e1a
 }
2f2e1a
-gcc -x c -c -I../include - -aux-info temp.aux < ../include/selinux/selinux.h
2f2e1a
+${CC:-gcc} -x c -c -I../include - -aux-info temp.aux < ../include/selinux/selinux.h
2f2e1a
 for i in `awk '/<stdin>.*extern int/ { print $6 }' temp.aux`; do except $i ; done 
2f2e1a
 rm -f -- temp.aux -.o
2f2e1a
diff --git libselinux-2.5/src/file_path_suffixes.h libselinux-2.5/src/file_path_suffixes.h
2f2e1a
index d1f9b48..95b228b 100644
2f2e1a
--- libselinux-2.5/src/file_path_suffixes.h
2f2e1a
+++ libselinux-2.5/src/file_path_suffixes.h
2f2e1a
@@ -24,6 +24,7 @@ S_(BINPOLICY, "/policy/policy")
2f2e1a
     S_(VIRTUAL_IMAGE, "/contexts/virtual_image_context")
2f2e1a
     S_(LXC_CONTEXTS, "/contexts/lxc_contexts")
2f2e1a
     S_(OPENSSH_CONTEXTS, "/contexts/openssh_contexts")
2f2e1a
+    S_(SNAPPERD_CONTEXTS, "/contexts/snapperd_contexts")
2f2e1a
     S_(SYSTEMD_CONTEXTS, "/contexts/systemd_contexts")
2f2e1a
     S_(FILE_CONTEXT_SUBS, "/contexts/files/file_contexts.subs")
2f2e1a
     S_(FILE_CONTEXT_SUBS_DIST, "/contexts/files/file_contexts.subs_dist")
2f2e1a
diff --git libselinux-2.5/src/fsetfilecon.c libselinux-2.5/src/fsetfilecon.c
2f2e1a
index 52707d0..0cbe12d 100644
2f2e1a
--- libselinux-2.5/src/fsetfilecon.c
2f2e1a
+++ libselinux-2.5/src/fsetfilecon.c
2f2e1a
@@ -9,8 +9,12 @@
2f2e1a
 
2f2e1a
 int fsetfilecon_raw(int fd, const char * context)
2f2e1a
 {
2f2e1a
-	int rc = fsetxattr(fd, XATTR_NAME_SELINUX, context, strlen(context) + 1,
2f2e1a
-			 0);
2f2e1a
+	int rc;
2f2e1a
+	if (! context) {
2f2e1a
+		errno=EINVAL;
2f2e1a
+		return -1;
2f2e1a
+	}
2f2e1a
+	rc = fsetxattr(fd, XATTR_NAME_SELINUX, context, strlen(context) + 1, 0);
2f2e1a
 	if (rc < 0 && errno == ENOTSUP) {
2f2e1a
 		char * ccontext = NULL;
2f2e1a
 		int err = errno;
2f2e1a
diff --git libselinux-2.5/src/init.c libselinux-2.5/src/init.c
2f2e1a
index 3db4de0..3c687a2 100644
2f2e1a
--- libselinux-2.5/src/init.c
2f2e1a
+++ libselinux-2.5/src/init.c
2f2e1a
@@ -11,7 +11,6 @@
2f2e1a
 #include <sys/vfs.h>
2f2e1a
 #include <stdint.h>
2f2e1a
 #include <limits.h>
2f2e1a
-#include <sys/mount.h>
2f2e1a
 
2f2e1a
 #include "dso.h"
2f2e1a
 #include "policy.h"
2f2e1a
@@ -57,20 +56,15 @@ static int verify_selinuxmnt(const char *mnt)
2f2e1a
 
2f2e1a
 int selinuxfs_exists(void)
2f2e1a
 {
2f2e1a
-	int exists = 0, mnt_rc = 0;
2f2e1a
+	int exists = 0;
2f2e1a
 	FILE *fp = NULL;
2f2e1a
 	char *buf = NULL;
2f2e1a
 	size_t len;
2f2e1a
 	ssize_t num;
2f2e1a
 
2f2e1a
-	mnt_rc = mount("proc", "/proc", "proc", 0, 0);
2f2e1a
-
2f2e1a
 	fp = fopen("/proc/filesystems", "r");
2f2e1a
-	if (!fp) {
2f2e1a
-		exists = 1; /* Fail as if it exists */
2f2e1a
-		goto out;
2f2e1a
-	}
2f2e1a
-
2f2e1a
+	if (!fp)
2f2e1a
+		return 1; /* Fail as if it exists */
2f2e1a
 	__fsetlocking(fp, FSETLOCKING_BYCALLER);
2f2e1a
 
2f2e1a
 	num = getline(&buf, &len, fp);
2f2e1a
@@ -84,14 +78,6 @@ int selinuxfs_exists(void)
2f2e1a
 
2f2e1a
 	free(buf);
2f2e1a
 	fclose(fp);
2f2e1a
-
2f2e1a
-out:
2f2e1a
-#ifndef MNT_DETACH
2f2e1a
-#define MNT_DETACH 2
2f2e1a
-#endif
2f2e1a
-	if (mnt_rc == 0)
2f2e1a
-		umount2("/proc", MNT_DETACH);
2f2e1a
-
2f2e1a
 	return exists;
2f2e1a
 }
2f2e1a
 hidden_def(selinuxfs_exists)
2f2e1a
diff --git libselinux-2.5/src/label_file.c libselinux-2.5/src/label_file.c
2f2e1a
index 071d902..c89bb35 100644
2f2e1a
--- libselinux-2.5/src/label_file.c
2f2e1a
+++ libselinux-2.5/src/label_file.c
2f2e1a
@@ -388,18 +388,21 @@ static int load_mmap(struct selabel_handle *rec, const char *path,
2f2e1a
 			rc = -1;
2f2e1a
 			goto err;
2f2e1a
 		}
2f2e1a
-		spec->lsd.study_data = (void *)mmap_area->next_addr;
2f2e1a
-		spec->lsd.flags |= PCRE_EXTRA_STUDY_DATA;
2f2e1a
-		rc = next_entry(NULL, mmap_area, entry_len);
2f2e1a
-		if (rc < 0)
2f2e1a
-			goto err;
2f2e1a
 
2f2e1a
-		/* Check that study data lengths match. */
2f2e1a
-		rc = pcre_fullinfo(spec->regex, &spec->lsd,
2f2e1a
-				    PCRE_INFO_STUDYSIZE, &len;;
2f2e1a
-		if (rc < 0 || len != entry_len) {
2f2e1a
-			rc = -1;
2f2e1a
-			goto err;
2f2e1a
+		if (entry_len) {
2f2e1a
+			spec->lsd.study_data = (void *)mmap_area->next_addr;
2f2e1a
+			spec->lsd.flags |= PCRE_EXTRA_STUDY_DATA;
2f2e1a
+			rc = next_entry(NULL, mmap_area, entry_len);
2f2e1a
+			if (rc < 0)
2f2e1a
+				goto err;
2f2e1a
+
2f2e1a
+			/* Check that study data lengths match. */
2f2e1a
+			rc = pcre_fullinfo(spec->regex, &spec->lsd,
2f2e1a
+					   PCRE_INFO_STUDYSIZE, &len;;
2f2e1a
+			if (rc < 0 || len != entry_len) {
2f2e1a
+				rc = -1;
2f2e1a
+				goto err;
2f2e1a
+			}
2f2e1a
 		}
2f2e1a
 
2f2e1a
 		data->nspec++;
2f2e1a
diff --git libselinux-2.5/src/label_file.h libselinux-2.5/src/label_file.h
2f2e1a
index 72fed1f..6d1e890 100644
2f2e1a
--- libselinux-2.5/src/label_file.h
2f2e1a
+++ libselinux-2.5/src/label_file.h
2f2e1a
@@ -80,9 +80,12 @@ struct saved_data {
2f2e1a
 
2f2e1a
 static inline pcre_extra *get_pcre_extra(struct spec *spec)
2f2e1a
 {
2f2e1a
-	if (spec->from_mmap)
2f2e1a
-		return &spec->lsd;
2f2e1a
-	else
2f2e1a
+	if (spec->from_mmap) {
2f2e1a
+		if (spec->lsd.study_data)
2f2e1a
+			return &spec->lsd;
2f2e1a
+		else
2f2e1a
+			return NULL;
2f2e1a
+	} else
2f2e1a
 		return spec->sd;
2f2e1a
 }
2f2e1a
 
2f2e1a
diff --git libselinux-2.5/src/load_policy.c libselinux-2.5/src/load_policy.c
2f2e1a
index 21ee58b..4f39fc7 100644
2f2e1a
--- libselinux-2.5/src/load_policy.c
2f2e1a
+++ libselinux-2.5/src/load_policy.c
2f2e1a
@@ -17,6 +17,10 @@
2f2e1a
 #include "policy.h"
2f2e1a
 #include <limits.h>
2f2e1a
 
2f2e1a
+#ifndef MNT_DETACH
2f2e1a
+#define MNT_DETACH 2
2f2e1a
+#endif
2f2e1a
+
2f2e1a
 int security_load_policy(void *data, size_t len)
2f2e1a
 {
2f2e1a
 	char path[PATH_MAX];
2f2e1a
@@ -348,11 +352,6 @@ int selinux_init_load_policy(int *enforce)
2f2e1a
 		fclose(cfg);
2f2e1a
 		free(buf);
2f2e1a
 	}
2f2e1a
-#ifndef MNT_DETACH
2f2e1a
-#define MNT_DETACH 2
2f2e1a
-#endif
2f2e1a
-	if (rc == 0)
2f2e1a
-		umount2("/proc", MNT_DETACH);
2f2e1a
 
2f2e1a
 	/* 
2f2e1a
 	 * Determine the final desired mode.
2f2e1a
@@ -400,11 +399,17 @@ int selinux_init_load_policy(int *enforce)
2f2e1a
 			/* Only emit this error if selinux was not disabled */
2f2e1a
 			fprintf(stderr, "Mount failed for selinuxfs on %s:  %s\n", SELINUXMNT, strerror(errno));
2f2e1a
 		}
2f2e1a
+
2f2e1a
+		if (rc == 0)
2f2e1a
+			umount2("/proc", MNT_DETACH);
2f2e1a
                 
2f2e1a
 		goto noload;
2f2e1a
 	}
2f2e1a
 	set_selinuxmnt(mntpoint);
2f2e1a
 
2f2e1a
+	if (rc == 0)
2f2e1a
+		umount2("/proc", MNT_DETACH);
2f2e1a
+
2f2e1a
 	/*
2f2e1a
 	 * Note:  The following code depends on having selinuxfs 
2f2e1a
 	 * already mounted and selinuxmnt set above.
2f2e1a
diff --git libselinux-2.5/src/lsetfilecon.c libselinux-2.5/src/lsetfilecon.c
2f2e1a
index 1d3b28a..ea6d70b 100644
2f2e1a
--- libselinux-2.5/src/lsetfilecon.c
2f2e1a
+++ libselinux-2.5/src/lsetfilecon.c
2f2e1a
@@ -9,8 +9,13 @@
2f2e1a
 
2f2e1a
 int lsetfilecon_raw(const char *path, const char * context)
2f2e1a
 {
2f2e1a
-	int rc = lsetxattr(path, XATTR_NAME_SELINUX, context, strlen(context) + 1,
2f2e1a
-			 0);
2f2e1a
+	int rc;
2f2e1a
+	if (! context) {
2f2e1a
+		errno=EINVAL;
2f2e1a
+		return -1;
2f2e1a
+	}
2f2e1a
+
2f2e1a
+	rc = lsetxattr(path, XATTR_NAME_SELINUX, context, strlen(context) + 1, 0);
2f2e1a
 	if (rc < 0 && errno == ENOTSUP) {
2f2e1a
 		char * ccontext = NULL;
2f2e1a
 		int err = errno;
2f2e1a
diff --git libselinux-2.5/src/matchpathcon.c libselinux-2.5/src/matchpathcon.c
73af03
index 5b495a0..d92ed79 100644
2f2e1a
--- libselinux-2.5/src/matchpathcon.c
2f2e1a
+++ libselinux-2.5/src/matchpathcon.c
2f2e1a
@@ -2,6 +2,7 @@
2f2e1a
 #include <string.h>
2f2e1a
 #include <errno.h>
2f2e1a
 #include <stdio.h>
2f2e1a
+#include <syslog.h>
2f2e1a
 #include "selinux_internal.h"
2f2e1a
 #include "label_internal.h"
2f2e1a
 #include "callbacks.h"
2f2e1a
@@ -62,7 +63,7 @@ static void
2f2e1a
 {
2f2e1a
 	va_list ap;
2f2e1a
 	va_start(ap, fmt);
2f2e1a
-	vfprintf(stderr, fmt, ap);
2f2e1a
+	vsyslog(LOG_ERR, fmt, ap);
2f2e1a
 	va_end(ap);
2f2e1a
 }
2f2e1a
 
73af03
@@ -361,12 +362,6 @@ int realpath_not_final(const char *name, char *resolved_path)
73af03
 		goto out;
73af03
 	}
73af03
 
73af03
-	/* strip leading // */
73af03
-	while (tmp_path[len] && tmp_path[len] == '/' &&
73af03
-	       tmp_path[len+1] && tmp_path[len+1] == '/') {
73af03
-		tmp_path++;
73af03
-		len++;
73af03
-	}
73af03
 	last_component = strrchr(tmp_path, '/');
73af03
 
73af03
 	if (last_component == tmp_path) {
73af03
@@ -470,6 +465,17 @@ int selinux_file_context_verify(const char *path, mode_t mode)
2f2e1a
 	char * con = NULL;
2f2e1a
 	char * fcontext = NULL;
2f2e1a
 	int rc = 0;
2f2e1a
+	char stackpath[PATH_MAX + 1];
2f2e1a
+	char *p = NULL;
2f2e1a
+
2f2e1a
+	if (S_ISLNK(mode)) {
2f2e1a
+		if (!realpath_not_final(path, stackpath))
2f2e1a
+			path = stackpath;
2f2e1a
+	} else {
2f2e1a
+		p = realpath(path, stackpath);
2f2e1a
+		if (p)
2f2e1a
+			path = p;
2f2e1a
+	}
2f2e1a
 
2f2e1a
 	rc = lgetfilecon_raw(path, &con);
2f2e1a
 	if (rc == -1) {
2f2e1a
diff --git libselinux-2.5/src/procattr.c libselinux-2.5/src/procattr.c
2f2e1a
index 527a0a5..eee4612 100644
2f2e1a
--- libselinux-2.5/src/procattr.c
2f2e1a
+++ libselinux-2.5/src/procattr.c
2f2e1a
@@ -70,9 +70,9 @@ static int openattr(pid_t pid, const char *attr, int flags)
2f2e1a
 	char *path;
2f2e1a
 	pid_t tid;
2f2e1a
 
2f2e1a
-	if (pid > 0)
2f2e1a
+	if (pid > 0) {
2f2e1a
 		rc = asprintf(&path, "/proc/%d/attr/%s", pid, attr);
2f2e1a
-	else {
2f2e1a
+	} else if (pid == 0) {
2f2e1a
 		rc = asprintf(&path, "/proc/thread-self/attr/%s", attr);
2f2e1a
 		if (rc < 0)
2f2e1a
 			return -1;
2f2e1a
@@ -82,6 +82,9 @@ static int openattr(pid_t pid, const char *attr, int flags)
2f2e1a
 		free(path);
2f2e1a
 		tid = gettid();
2f2e1a
 		rc = asprintf(&path, "/proc/self/task/%d/attr/%s", tid, attr);
2f2e1a
+	} else {
2f2e1a
+		errno = EINVAL;
2f2e1a
+		return -1;
2f2e1a
 	}
2f2e1a
 	if (rc < 0)
2f2e1a
 		return -1;
2f2e1a
@@ -303,11 +306,21 @@ static int setprocattrcon(const char * context,
2f2e1a
 #define getpidattr_def(fn, attr) \
2f2e1a
 	int get##fn##_raw(pid_t pid, char **c)	\
2f2e1a
 	{ \
2f2e1a
-		return getprocattrcon_raw(c, pid, #attr); \
2f2e1a
+		if (pid <= 0) { \
2f2e1a
+			errno = EINVAL; \
2f2e1a
+			return -1; \
2f2e1a
+		} else { \
2f2e1a
+			return getprocattrcon_raw(c, pid, #attr); \
2f2e1a
+		} \
2f2e1a
 	} \
2f2e1a
 	int get##fn(pid_t pid, char **c)	\
2f2e1a
 	{ \
2f2e1a
-		return getprocattrcon(c, pid, #attr); \
2f2e1a
+		if (pid <= 0) { \
2f2e1a
+			errno = EINVAL; \
2f2e1a
+			return -1; \
2f2e1a
+		} else { \
2f2e1a
+			return getprocattrcon(c, pid, #attr); \
2f2e1a
+		} \
2f2e1a
 	}
2f2e1a
 
2f2e1a
 all_selfattr_def(con, current)
2f2e1a
diff --git libselinux-2.5/src/selinux_config.c libselinux-2.5/src/selinux_config.c
2f2e1a
index bec5f3b..c519a77 100644
2f2e1a
--- libselinux-2.5/src/selinux_config.c
2f2e1a
+++ libselinux-2.5/src/selinux_config.c
2f2e1a
@@ -50,7 +50,8 @@
2f2e1a
 #define BOOLEAN_SUBS      27
2f2e1a
 #define OPENSSH_CONTEXTS  28
2f2e1a
 #define SYSTEMD_CONTEXTS  29
2f2e1a
-#define NEL               30
2f2e1a
+#define SNAPPERD_CONTEXTS 30
2f2e1a
+#define NEL               31
2f2e1a
 
2f2e1a
 /* Part of one-time lazy init */
2f2e1a
 static pthread_once_t once = PTHREAD_ONCE_INIT;
2f2e1a
@@ -499,6 +500,13 @@ const char *selinux_openssh_contexts_path(void)
2f2e1a
 
2f2e1a
 hidden_def(selinux_openssh_contexts_path)
2f2e1a
 
2f2e1a
+const char *selinux_snapperd_contexts_path(void)
2f2e1a
+{
2f2e1a
+    return get_path(SNAPPERD_CONTEXTS);
2f2e1a
+}
2f2e1a
+
2f2e1a
+hidden_def(selinux_snapperd_contexts_path)
2f2e1a
+
2f2e1a
 const char *selinux_systemd_contexts_path(void)
2f2e1a
 {
2f2e1a
 	return get_path(SYSTEMD_CONTEXTS);
2f2e1a
diff --git libselinux-2.5/src/selinux_internal.h libselinux-2.5/src/selinux_internal.h
2f2e1a
index 46566f6..9b9145c 100644
2f2e1a
--- libselinux-2.5/src/selinux_internal.h
2f2e1a
+++ libselinux-2.5/src/selinux_internal.h
2f2e1a
@@ -84,6 +84,7 @@ hidden_proto(selinux_mkload_policy)
2f2e1a
     hidden_proto(selinux_x_context_path)
2f2e1a
     hidden_proto(selinux_sepgsql_context_path)
2f2e1a
     hidden_proto(selinux_openssh_contexts_path)
2f2e1a
+    hidden_proto(selinux_snapperd_contexts_path)
2f2e1a
     hidden_proto(selinux_systemd_contexts_path)
2f2e1a
     hidden_proto(selinux_path)
2f2e1a
     hidden_proto(selinux_check_passwd_access)
73af03
diff --git libselinux-2.5/src/selinux_restorecon.c libselinux-2.5/src/selinux_restorecon.c
73af03
index 17ed6fe..d2c2402 100644
73af03
--- libselinux-2.5/src/selinux_restorecon.c
73af03
+++ libselinux-2.5/src/selinux_restorecon.c
73af03
@@ -245,25 +245,41 @@ int selinux_restorecon(const char *pathname_orig,
73af03
 	 * realpath of containing dir, then appending last component name.
73af03
 	 */
73af03
 	if (userealpath) {
73af03
-		pathbname = basename((char *)pathname_orig);
73af03
+		char *basename_cpy = strdup(pathname_orig);
73af03
+		if (!basename_cpy)
73af03
+			goto realpatherr;
73af03
+		pathbname = basename(basename_cpy);
73af03
 		if (!strcmp(pathbname, "/") || !strcmp(pathbname, ".") ||
73af03
 					    !strcmp(pathbname, "..")) {
73af03
 			pathname = realpath(pathname_orig, NULL);
73af03
-			if (!pathname)
73af03
+			if (!pathname) {
73af03
+				free(basename_cpy);
73af03
 				goto realpatherr;
73af03
+			}
73af03
 		} else {
73af03
-			pathdname = dirname((char *)pathname_orig);
73af03
+			char *dirname_cpy = strdup(pathname_orig);
73af03
+			if (!dirname_cpy) {
73af03
+				free(basename_cpy);
73af03
+				goto realpatherr;
73af03
+			}
73af03
+			pathdname = dirname(dirname_cpy);
73af03
 			pathdnamer = realpath(pathdname, NULL);
73af03
-			if (!pathdnamer)
73af03
+			free(dirname_cpy);
73af03
+			if (!pathdnamer) {
73af03
+				free(basename_cpy);
73af03
 				goto realpatherr;
73af03
+			}
73af03
 			if (!strcmp(pathdnamer, "/"))
73af03
 				error = asprintf(&pathname, "/%s", pathbname);
73af03
 			else
73af03
 				error = asprintf(&pathname, "%s/%s",
73af03
 						    pathdnamer, pathbname);
73af03
-			if (error < 0)
73af03
+			if (error < 0) {
73af03
+				free(basename_cpy);
73af03
 				goto oom;
73af03
+			}
73af03
 		}
73af03
+		free(basename_cpy);
73af03
 	} else {
73af03
 		pathname = strdup(pathname_orig);
73af03
 		if (!pathname)
73af03
diff --git libselinux-2.5/src/selinuxswig_python.i libselinux-2.5/src/selinuxswig_python.i
73af03
index 8cea18d..592d70c 100644
73af03
--- libselinux-2.5/src/selinuxswig_python.i
73af03
+++ libselinux-2.5/src/selinuxswig_python.i
73af03
@@ -23,7 +23,13 @@ def restorecon(path, recursive=False):
73af03
     except OSError:
73af03
         path = os.path.realpath(os.path.expanduser(path))
73af03
         mode = os.lstat(path)[stat.ST_MODE]
73af03
-        status, context = matchpathcon(path, mode)
73af03
+        try:
73af03
+            status, context = matchpathcon(path, mode)
73af03
+        except OSError as e:
73af03
+            # matchpathcon returns ENOENT when <<none>> in file context
73af03
+            if e.errno != errno.ENOENT:
73af03
+                raise
73af03
+            return
73af03
 
73af03
     if status == 0:
73af03
         try:
2f2e1a
diff --git libselinux-2.5/src/setexecfilecon.c libselinux-2.5/src/setexecfilecon.c
2f2e1a
index e72ba0d..9c821f8 100644
2f2e1a
--- libselinux-2.5/src/setexecfilecon.c
2f2e1a
+++ libselinux-2.5/src/setexecfilecon.c
2f2e1a
@@ -45,7 +45,7 @@ int setexecfilecon(const char *filename, const char *fallback_type)
2f2e1a
 		goto out;
2f2e1a
       out:
2f2e1a
 
2f2e1a
-	if (rc < 0 && security_getenforce() == 0)
2f2e1a
+	if (rc < 0 && security_getenforce() < 1)
2f2e1a
 		rc = 0;
2f2e1a
 
2f2e1a
 	context_free(con);
2f2e1a
diff --git libselinux-2.5/src/setfilecon.c libselinux-2.5/src/setfilecon.c
2f2e1a
index d05969c..3f0200e 100644
2f2e1a
--- libselinux-2.5/src/setfilecon.c
2f2e1a
+++ libselinux-2.5/src/setfilecon.c
2f2e1a
@@ -9,8 +9,12 @@
2f2e1a
 
2f2e1a
 int setfilecon_raw(const char *path, const char * context)
2f2e1a
 {
2f2e1a
-	int rc = setxattr(path, XATTR_NAME_SELINUX, context, strlen(context) + 1,
2f2e1a
-			0);
2f2e1a
+	int rc;
2f2e1a
+	if (! context) {
2f2e1a
+		errno=EINVAL;
2f2e1a
+		return -1;
2f2e1a
+	}
2f2e1a
+	rc = setxattr(path, XATTR_NAME_SELINUX, context, strlen(context) + 1, 0);
2f2e1a
 	if (rc < 0 && errno == ENOTSUP) {
2f2e1a
 		char * ccontext = NULL;
2f2e1a
 		int err = errno;
2f2e1a
diff --git libselinux-2.5/utils/.gitignore libselinux-2.5/utils/.gitignore
2f2e1a
index 060eaab..ed3bf0b 100644
2f2e1a
--- libselinux-2.5/utils/.gitignore
2f2e1a
+++ libselinux-2.5/utils/.gitignore
2f2e1a
@@ -14,7 +14,12 @@ getseuser
2f2e1a
 matchpathcon
2f2e1a
 policyvers
2f2e1a
 sefcontext_compile
2f2e1a
+selabel_digest
2f2e1a
+selabel_lookup
2f2e1a
+selabel_lookup_best_match
2f2e1a
+selabel_partial_match
2f2e1a
 selinux_check_securetty_context
2f2e1a
+selinux_restorecon
2f2e1a
 selinuxenabled
2f2e1a
 selinuxexeccon
2f2e1a
 setenforce
2f2e1a
diff --git libselinux-2.5/utils/Makefile libselinux-2.5/utils/Makefile
2f2e1a
index cf7af52..8497cb4 100644
2f2e1a
--- libselinux-2.5/utils/Makefile
2f2e1a
+++ libselinux-2.5/utils/Makefile
2f2e1a
@@ -3,6 +3,7 @@ PREFIX ?= $(DESTDIR)/usr
2f2e1a
 LIBDIR ?= $(PREFIX)/lib
2f2e1a
 USRBINDIR ?= $(PREFIX)/sbin
2f2e1a
 SBINDIR ?= $(DESTDIR)/sbin
2f2e1a
+INCLUDEDIR ?= $(PREFIX)/include
2f2e1a
 
2f2e1a
 MAX_STACK_SIZE=8192
2f2e1a
 CFLAGS ?= -O -Wall -W -Wundef -Wformat-y2k -Wformat-security -Winit-self -Wmissing-include-dirs \
2f2e1a
@@ -23,7 +24,7 @@ CFLAGS ?= -O -Wall -W -Wundef -Wformat-y2k -Wformat-security -Winit-self -Wmissi
2f2e1a
           -fasynchronous-unwind-tables -fdiagnostics-show-option -funit-at-a-time \
2f2e1a
           -fipa-pure-const -Wno-suggest-attribute=pure -Wno-suggest-attribute=const \
2f2e1a
           -Werror -Wno-aggregate-return -Wno-redundant-decls
2f2e1a
-override CFLAGS += -I../include -D_GNU_SOURCE $(EMFLAGS)
2f2e1a
+override CFLAGS += -I../include -I$(INCLUDEDIR) -D_GNU_SOURCE $(EMFLAGS)
2f2e1a
 LDLIBS += -L../src -lselinux -L$(LIBDIR)
2f2e1a
 
2f2e1a
 TARGETS=$(patsubst %.c,%,$(wildcard *.c))
73af03
diff --git libselinux-2.5/utils/matchpathcon.c libselinux-2.5/utils/matchpathcon.c
73af03
index d1f1348..0288feb 100644
73af03
--- libselinux-2.5/utils/matchpathcon.c
73af03
+++ libselinux-2.5/utils/matchpathcon.c
73af03
@@ -15,7 +15,7 @@
73af03
 static void usage(const char *progname)
73af03
 {
73af03
 	fprintf(stderr,
73af03
-		"usage:  %s [-N] [-n] [-f file_contexts] [ -P policy_root_path ] [-p prefix] [-Vq] path...\n",
73af03
+		"usage:  %s [-V] [-N] [-n] [-m type] [-f file_contexts_file] [-p prefix] [-P policy_root_path] filepath...\n",
73af03
 		progname);
73af03
 	exit(1);
73af03
 }
2f2e1a
diff --git libselinux-2.5/utils/sefcontext_compile.c libselinux-2.5/utils/sefcontext_compile.c
2f2e1a
index d2578b6..fd6fb78 100644
2f2e1a
--- libselinux-2.5/utils/sefcontext_compile.c
2f2e1a
+++ libselinux-2.5/utils/sefcontext_compile.c
2f2e1a
@@ -228,10 +228,13 @@ static int write_binary_file(struct saved_data *data, int fd)
2f2e1a
 		if (len != to_write)
2f2e1a
 			goto err;
2f2e1a
 
2f2e1a
-		/* determine the size of the pcre study info */
2f2e1a
-		rc = pcre_fullinfo(re, sd, PCRE_INFO_STUDYSIZE, &size);
2f2e1a
-		if (rc < 0)
2f2e1a
-			goto err;
2f2e1a
+		if (sd) {
2f2e1a
+			/* determine the size of the pcre study info */
2f2e1a
+			rc = pcre_fullinfo(re, sd, PCRE_INFO_STUDYSIZE, &size);
2f2e1a
+			if (rc < 0)
2f2e1a
+				goto err;
2f2e1a
+		} else
2f2e1a
+			size = 0;
2f2e1a
 
2f2e1a
 		/* write the number of bytes in the pcre study data */
2f2e1a
 		to_write = size;
2f2e1a
@@ -239,10 +242,12 @@ static int write_binary_file(struct saved_data *data, int fd)
2f2e1a
 		if (len != 1)
2f2e1a
 			goto err;
2f2e1a
 
2f2e1a
-		/* write the actual pcre study data as a char array */
2f2e1a
-		len = fwrite(sd->study_data, 1, to_write, bin_file);
2f2e1a
-		if (len != to_write)
2f2e1a
-			goto err;
2f2e1a
+		if (sd) {
2f2e1a
+			/* write the actual pcre study data as a char array */
2f2e1a
+			len = fwrite(sd->study_data, 1, to_write, bin_file);
2f2e1a
+			if (len != to_write)
2f2e1a
+				goto err;
2f2e1a
+		}
2f2e1a
 	}
2f2e1a
 
2f2e1a
 	rc = 0;