1eceb6c
diff --git libselinux-2.4/Makefile libselinux-2.4/Makefile
13a8a0f
index 6142b60..bdf9de8 100644
1eceb6c
--- libselinux-2.4/Makefile
1eceb6c
+++ libselinux-2.4/Makefile
99813aa
@@ -1,4 +1,4 @@
99813aa
-SUBDIRS = src include utils man
99813aa
+SUBDIRS = src include utils man golang
99813aa
 
99813aa
 DISABLE_AVC ?= n
99813aa
 DISABLE_SETRANS ?= n
1eceb6c
diff --git libselinux-2.4/golang/Makefile libselinux-2.4/golang/Makefile
99813aa
new file mode 100644
2492943
index 0000000..b75677b
99813aa
--- /dev/null
1eceb6c
+++ libselinux-2.4/golang/Makefile
2492943
@@ -0,0 +1,22 @@
99813aa
+# Installation directories.
99813aa
+PREFIX ?= $(DESTDIR)/usr
ee8c867
+LIBDIR ?= $(DESTDIR)/usr/lib
ee8c867
+GODIR ?= $(LIBDIR)/golang/src/pkg/github.com/selinux
99813aa
+all:
99813aa
+
99813aa
+install: 
99813aa
+	[ -d $(GODIR) ] || mkdir -p $(GODIR)
99813aa
+	install -m 644 selinux.go $(GODIR)
99813aa
+
99813aa
+test:
2492943
+	@mkdir selinux
2492943
+	@cp selinux.go selinux
2492943
+	GOPATH=$(pwd) go run test.go 
2492943
+	@rm -rf selinux
99813aa
+
99813aa
+clean:
2492943
+	@rm -f *~
2492943
+	@rm -rf selinux
99813aa
+indent:
99813aa
+
99813aa
+relabel:
1eceb6c
diff --git libselinux-2.4/golang/selinux.go libselinux-2.4/golang/selinux.go
99813aa
new file mode 100644
820aece
index 0000000..34bf6bb
99813aa
--- /dev/null
1eceb6c
+++ libselinux-2.4/golang/selinux.go
820aece
@@ -0,0 +1,412 @@
99813aa
+package selinux
99813aa
+
99813aa
+/*
99813aa
+ The selinux package is a go bindings to libselinux required to add selinux
99813aa
+ support to docker.
99813aa
+
99813aa
+ Author Dan Walsh <dwalsh@redhat.com>
99813aa
+
99813aa
+ Used some ideas/code from the go-ini packages https://github.com/vaughan0
99813aa
+ By Vaughan Newton
99813aa
+*/
99813aa
+
99813aa
+// #cgo pkg-config: libselinux
99813aa
+// #include <selinux/selinux.h>
99813aa
+// #include <stdlib.h>
99813aa
+import "C"
99813aa
+import (
820aece
+	"bufio"
99813aa
+	"crypto/rand"
820aece
+	"encoding/binary"
99813aa
+	"fmt"
99813aa
+	"io"
99813aa
+	"os"
820aece
+	"path"
820aece
+	"path/filepath"
820aece
+	"regexp"
99813aa
+	"strings"
820aece
+	"unsafe"
99813aa
+)
99813aa
+
99813aa
+var (
820aece
+	assignRegex = regexp.MustCompile(`^([^=]+)=(.*)$`)
820aece
+	mcsList     = make(map[string]bool)
99813aa
+)
99813aa
+
820aece
+func Matchpathcon(path string, mode os.FileMode) (string, error) {
99813aa
+	var con C.security_context_t
99813aa
+	var scon string
820aece
+	rc, err := C.matchpathcon(C.CString(path), C.mode_t(mode), &con)
99813aa
+	if rc == 0 {
99813aa
+		scon = C.GoString(con)
99813aa
+		C.free(unsafe.Pointer(con))
99813aa
+	}
99813aa
+	return scon, err
99813aa
+}
99813aa
+
820aece
+func Setfilecon(path, scon string) (int, error) {
820aece
+	rc, err := C.lsetfilecon(C.CString(path), C.CString(scon))
99813aa
+	return int(rc), err
99813aa
+}
99813aa
+
2492943
+func Getfilecon(path string) (string, error) {
2492943
+	var scon C.security_context_t
2492943
+	var fcon string
820aece
+	rc, err := C.lgetfilecon(C.CString(path), &scon)
820aece
+	if rc >= 0 {
820aece
+		fcon = C.GoString(scon)
2492943
+		err = nil
2492943
+	}
2492943
+	return fcon, err
2492943
+}
2492943
+
2492943
+func Setfscreatecon(scon string) (int, error) {
2492943
+	var (
820aece
+		rc  C.int
2492943
+		err error
2492943
+	)
820aece
+	if scon != "" {
2492943
+		rc, err = C.setfscreatecon(C.CString(scon))
2492943
+	} else {
2492943
+		rc, err = C.setfscreatecon(nil)
2492943
+	}
2492943
+	return int(rc), err
2492943
+}
2492943
+
2492943
+func Getfscreatecon() (string, error) {
2492943
+	var scon C.security_context_t
2492943
+	var fcon string
820aece
+	rc, err := C.getfscreatecon(&scon)
820aece
+	if rc >= 0 {
820aece
+		fcon = C.GoString(scon)
2492943
+		err = nil
2492943
+		C.freecon(scon)
2492943
+	}
2492943
+	return fcon, err
2492943
+}
2492943
+
820aece
+func Getcon() string {
2492943
+	var pcon C.security_context_t
2492943
+	C.getcon(&pcon)
2492943
+	scon := C.GoString(pcon)
2492943
+	C.freecon(pcon)
2492943
+	return scon
2492943
+}
2492943
+
2492943
+func Getpidcon(pid int) (string, error) {
2492943
+	var pcon C.security_context_t
2492943
+	var scon string
2492943
+	rc, err := C.getpidcon(C.pid_t(pid), &pcon)
820aece
+	if rc >= 0 {
2492943
+		scon = C.GoString(pcon)
2492943
+		C.freecon(pcon)
2492943
+		err = nil
2492943
+	}
2492943
+	return scon, err
2492943
+}
2492943
+
2492943
+func Getpeercon(socket int) (string, error) {
2492943
+	var pcon C.security_context_t
2492943
+	var scon string
2492943
+	rc, err := C.getpeercon(C.int(socket), &pcon)
820aece
+	if rc >= 0 {
2492943
+		scon = C.GoString(pcon)
2492943
+		C.freecon(pcon)
2492943
+		err = nil
2492943
+	}
2492943
+	return scon, err
2492943
+}
2492943
+
820aece
+func Setexeccon(scon string) error {
99813aa
+	var val *C.char
820aece
+	if !SelinuxEnabled() {
820aece
+		return nil
99813aa
+	}
99813aa
+	if scon != "" {
99813aa
+		val = C.CString(scon)
99813aa
+	} else {
99813aa
+		val = nil
99813aa
+	}
820aece
+	_, err := C.setexeccon(val)
820aece
+	return err
99813aa
+}
99813aa
+
99813aa
+type Context struct {
99813aa
+	con []string
99813aa
+}
820aece
+
820aece
+func (c *Context) SetUser(user string) {
820aece
+	c.con[0] = user
99813aa
+}
820aece
+func (c *Context) GetUser() string {
99813aa
+	return c.con[0]
99813aa
+}
820aece
+func (c *Context) SetRole(role string) {
820aece
+	c.con[1] = role
99813aa
+}
820aece
+func (c *Context) GetRole() string {
99813aa
+	return c.con[1]
99813aa
+}
820aece
+func (c *Context) SetType(setype string) {
820aece
+	c.con[2] = setype
99813aa
+}
820aece
+func (c *Context) GetType() string {
99813aa
+	return c.con[2]
99813aa
+}
820aece
+func (c *Context) SetLevel(mls string) {
820aece
+	c.con[3] = mls
99813aa
+}
820aece
+func (c *Context) GetLevel() string {
99813aa
+	return c.con[3]
99813aa
+}
820aece
+func (c *Context) Get() string {
820aece
+	return strings.Join(c.con, ":")
99813aa
+}
99813aa
+func (c *Context) Set(scon string) {
820aece
+	c.con = strings.SplitN(scon, ":", 4)
99813aa
+}
820aece
+func NewContext(scon string) Context {
99813aa
+	var con Context
99813aa
+	con.Set(scon)
99813aa
+	return con
99813aa
+}
99813aa
+
820aece
+func SelinuxEnabled() bool {
99813aa
+	b := C.is_selinux_enabled()
99813aa
+	if b > 0 {
820aece
+		return true
99813aa
+	}
99813aa
+	return false
99813aa
+}
99813aa
+
99813aa
+const (
820aece
+	Enforcing  = 1
99813aa
+	Permissive = 0
820aece
+	Disabled   = -1
99813aa
+)
99813aa
+
820aece
+func SelinuxGetEnforce() int {
99813aa
+	return int(C.security_getenforce())
99813aa
+}
99813aa
+
820aece
+func SelinuxGetEnforceMode() int {
99813aa
+	var enforce C.int
99813aa
+	C.selinux_getenforcemode(&enforce)
99813aa
+	return int(enforce)
99813aa
+}
99813aa
+
820aece
+func mcsAdd(mcs string) {
820aece
+	mcsList[mcs] = true
99813aa
+}
99813aa
+
820aece
+func mcsDelete(mcs string) {
820aece
+	mcsList[mcs] = false
99813aa
+}
99813aa
+
820aece
+func mcsExists(mcs string) bool {
820aece
+	return mcsList[mcs]
99813aa
+}
99813aa
+
820aece
+func IntToMcs(id int, catRange uint32) string {
820aece
+	if (id < 1) || (id > 523776) {
820aece
+		return ""
820aece
+	}
ee8c867
+
820aece
+	SETSIZE := int(catRange)
820aece
+	TIER := SETSIZE
ee8c867
+
820aece
+	ORD := id
820aece
+	for ORD > TIER {
820aece
+		ORD = ORD - TIER
820aece
+		TIER -= 1
ee8c867
+	}
820aece
+	TIER = SETSIZE - TIER
820aece
+	ORD = ORD + TIER
820aece
+	return fmt.Sprintf("s0:c%d,c%d", TIER, ORD)
ee8c867
+}
ee8c867
+
820aece
+func uniqMcs(catRange uint32) string {
99813aa
+	var n uint32
820aece
+	var c1, c2 uint32
99813aa
+	var mcs string
820aece
+	for {
99813aa
+		binary.Read(rand.Reader, binary.LittleEndian, &n)
99813aa
+		c1 = n % catRange
99813aa
+		binary.Read(rand.Reader, binary.LittleEndian, &n)
99813aa
+		c2 = n % catRange
99813aa
+		if c1 == c2 {
99813aa
+			continue
99813aa
+		} else {
99813aa
+			if c1 > c2 {
99813aa
+				t := c1
99813aa
+				c1 = c2
99813aa
+				c2 = t
99813aa
+			}
99813aa
+		}
99813aa
+		mcs = fmt.Sprintf("s0:c%d,c%d", c1, c2)
820aece
+		if mcsExists(mcs) {
99813aa
+			continue
99813aa
+		}
820aece
+		mcsAdd(mcs)
99813aa
+		break
99813aa
+	}
99813aa
+	return mcs
99813aa
+}
820aece
+func freeContext(processLabel string) {
99813aa
+	var scon Context
820aece
+	scon = NewContext(processLabel)
820aece
+	mcsDelete(scon.GetLevel())
99813aa
+}
99813aa
+
820aece
+func GetLxcContexts() (processLabel string, fileLabel string) {
99813aa
+	var val, key string
99813aa
+	var bufin *bufio.Reader
820aece
+	if !SelinuxEnabled() {
99813aa
+		return
99813aa
+	}
820aece
+	lxcPath := C.GoString(C.selinux_lxc_contexts_path())
820aece
+	fileLabel = "system_u:object_r:svirt_sandbox_file_t:s0"
820aece
+	processLabel = "system_u:system_r:svirt_lxc_net_t:s0"
99813aa
+
820aece
+	in, err := os.Open(lxcPath)
99813aa
+	if err != nil {
99813aa
+		goto exit
99813aa
+	}
99813aa
+
99813aa
+	defer in.Close()
99813aa
+	bufin = bufio.NewReader(in)
99813aa
+
99813aa
+	for done := false; !done; {
99813aa
+		var line string
99813aa
+		if line, err = bufin.ReadString('\n'); err != nil {
99813aa
+			if err == io.EOF {
99813aa
+				done = true
99813aa
+			} else {
99813aa
+				goto exit
99813aa
+			}
99813aa
+		}
99813aa
+		line = strings.TrimSpace(line)
99813aa
+		if len(line) == 0 {
99813aa
+			// Skip blank lines
99813aa
+			continue
99813aa
+		}
99813aa
+		if line[0] == ';' || line[0] == '#' {
99813aa
+			// Skip comments
99813aa
+			continue
99813aa
+		}
99813aa
+		if groups := assignRegex.FindStringSubmatch(line); groups != nil {
99813aa
+			key, val = strings.TrimSpace(groups[1]), strings.TrimSpace(groups[2])
99813aa
+			if key == "process" {
820aece
+				processLabel = strings.Trim(val, "\"")
99813aa
+			}
99813aa
+			if key == "file" {
820aece
+				fileLabel = strings.Trim(val, "\"")
99813aa
+			}
99813aa
+		}
99813aa
+	}
99813aa
+exit:
99813aa
+	var scon Context
820aece
+	mcs := IntToMcs(os.Getpid(), 1024)
820aece
+	scon = NewContext(processLabel)
820aece
+	scon.SetLevel(mcs)
820aece
+	processLabel = scon.Get()
820aece
+	scon = NewContext(fileLabel)
820aece
+	scon.SetLevel(mcs)
820aece
+	fileLabel = scon.Get()
820aece
+	return processLabel, fileLabel
820aece
+}
820aece
+
820aece
+func CopyLevel(src, dest string) (string, error) {
820aece
+	if !SelinuxEnabled() {
99813aa
+		return "", nil
99813aa
+	}
99813aa
+	if src == "" {
99813aa
+		return "", nil
99813aa
+	}
99813aa
+	rc, err := C.security_check_context(C.CString(src))
99813aa
+	if rc != 0 {
99813aa
+		return "", err
99813aa
+	}
99813aa
+	rc, err = C.security_check_context(C.CString(dest))
99813aa
+	if rc != 0 {
99813aa
+		return "", err
99813aa
+	}
820aece
+	scon := NewContext(src)
820aece
+	tcon := NewContext(dest)
820aece
+	tcon.SetLevel(scon.GetLevel())
99813aa
+	return tcon.Get(), nil
99813aa
+}
99813aa
+
820aece
+func RestoreCon(fpath string, recurse bool) error {
820aece
+	var flabel string
820aece
+	var err error
820aece
+	var fs os.FileInfo
820aece
+
820aece
+	if !SelinuxEnabled() {
820aece
+		return nil
820aece
+	}
820aece
+
820aece
+	if recurse {
820aece
+		var paths []string
820aece
+		var err error
820aece
+
820aece
+		if paths, err = filepath.Glob(path.Join(fpath, "**", "*")); err != nil {
820aece
+			return fmt.Errorf("Unable to find directory %v: %v", fpath, err)
820aece
+		}
820aece
+
820aece
+		for _, fpath := range paths {
820aece
+			if err = RestoreCon(fpath, false); err != nil {
820aece
+				return fmt.Errorf("Unable to restore selinux context for %v: %v", fpath, err)
820aece
+			}
820aece
+		}
820aece
+		return nil
820aece
+	}
820aece
+	if fs, err = os.Stat(fpath); err != nil {
820aece
+		return fmt.Errorf("Unable stat %v: %v", fpath, err)
820aece
+	}
820aece
+
820aece
+	if flabel, err = Matchpathcon(fpath, fs.Mode()); flabel == "" {
820aece
+		return fmt.Errorf("Unable to get context for %v: %v", fpath, err)
820aece
+	}
820aece
+
820aece
+	if rc, err := Setfilecon(fpath, flabel); rc != 0 {
820aece
+		return fmt.Errorf("Unable to set selinux context for %v: %v", fpath, err)
820aece
+	}
820aece
+
820aece
+	return nil
820aece
+}
820aece
+
99813aa
+func Test() {
820aece
+	var plabel, flabel string
820aece
+	if !SelinuxEnabled() {
99813aa
+		return
99813aa
+	}
99813aa
+
820aece
+	plabel, flabel = GetLxcContexts()
99813aa
+	fmt.Println(plabel)
99813aa
+	fmt.Println(flabel)
820aece
+	freeContext(plabel)
820aece
+	plabel, flabel = GetLxcContexts()
99813aa
+	fmt.Println(plabel)
99813aa
+	fmt.Println(flabel)
820aece
+	freeContext(plabel)
820aece
+	if SelinuxEnabled() {
99813aa
+		fmt.Println("Enabled")
99813aa
+	} else {
99813aa
+		fmt.Println("Disabled")
99813aa
+	}
820aece
+	fmt.Println("getenforce ", SelinuxGetEnforce())
820aece
+	fmt.Println("getenforcemode ", SelinuxGetEnforceMode())
820aece
+	flabel, _ = Matchpathcon("/home/dwalsh/.emacs", 0)
99813aa
+	fmt.Println(flabel)
ee8c867
+	pid := os.Getpid()
820aece
+	fmt.Printf("PID:%d MCS:%s\n", pid, IntToMcs(pid, 1023))
2492943
+	fmt.Println(Getcon())
2492943
+	fmt.Println(Getfilecon("/etc/passwd"))
2492943
+	fmt.Println(Getpidcon(1))
2492943
+	Setfscreatecon("unconfined_u:unconfined_r:unconfined_t:s0")
2492943
+	fmt.Println(Getfscreatecon())
2492943
+	Setfscreatecon("")
2492943
+	fmt.Println(Getfscreatecon())
2492943
+	fmt.Println(Getpidcon(1))
2492943
+}
1eceb6c
diff --git libselinux-2.4/golang/test.go libselinux-2.4/golang/test.go
2492943
new file mode 100644
2492943
index 0000000..fed6de8
2492943
--- /dev/null
1eceb6c
+++ libselinux-2.4/golang/test.go
2492943
@@ -0,0 +1,9 @@
2492943
+package main
2492943
+
2492943
+import (
2492943
+	"./selinux"
2492943
+)
2492943
+
2492943
+func main() {
2492943
+	selinux.Test()
99813aa
+}
1eceb6c
diff --git libselinux-2.4/include/selinux/selinux.h libselinux-2.4/include/selinux/selinux.h
aa0f5b6
index d0eb5c6..4beb170 100644
1eceb6c
--- libselinux-2.4/include/selinux/selinux.h
1eceb6c
+++ libselinux-2.4/include/selinux/selinux.h
aa0f5b6
@@ -543,6 +543,7 @@ extern const char *selinux_virtual_image_context_path(void);
aa0f5b6
 extern const char *selinux_lxc_contexts_path(void);
aa0f5b6
 extern const char *selinux_x_context_path(void);
aa0f5b6
 extern const char *selinux_sepgsql_context_path(void);
aa0f5b6
+extern const char *selinux_openssh_contexts_path(void);
aa0f5b6
 extern const char *selinux_systemd_contexts_path(void);
aa0f5b6
 extern const char *selinux_contexts_path(void);
aa0f5b6
 extern const char *selinux_securetty_types_path(void);
1eceb6c
diff --git libselinux-2.4/man/man3/getfscreatecon.3 libselinux-2.4/man/man3/getfscreatecon.3
13a8a0f
index e348d3b..8cc4df5 100644
1eceb6c
--- libselinux-2.4/man/man3/getfscreatecon.3
1eceb6c
+++ libselinux-2.4/man/man3/getfscreatecon.3
2492943
@@ -49,6 +49,11 @@ Signal handlers that perform a
2492943
 must take care to
2492943
 save, reset, and restore the fscreate context to avoid unexpected behavior.
2492943
 .
2492943
+
2492943
+.br
2492943
+.B Note:
2492943
+Contexts are thread specific.
2492943
+
2492943
 .SH "RETURN VALUE"
2492943
 On error \-1 is returned.
2492943
 On success 0 is returned.
1eceb6c
diff --git libselinux-2.4/man/man3/getkeycreatecon.3 libselinux-2.4/man/man3/getkeycreatecon.3
13a8a0f
index 4d70f10..b51008d 100644
1eceb6c
--- libselinux-2.4/man/man3/getkeycreatecon.3
1eceb6c
+++ libselinux-2.4/man/man3/getkeycreatecon.3
2492943
@@ -48,6 +48,10 @@ Signal handlers that perform a
2492943
 .BR setkeycreatecon ()
2492943
 must take care to
2492943
 save, reset, and restore the keycreate context to avoid unexpected behavior.
2492943
+
2492943
+.br
2492943
+.B Note:
2492943
+Contexts are thread specific.
2492943
 .
2492943
 .SH "RETURN VALUE"
2492943
 On error \-1 is returned.
1eceb6c
diff --git libselinux-2.4/man/man3/getsockcreatecon.3 libselinux-2.4/man/man3/getsockcreatecon.3
13a8a0f
index 4dd8f30..26086d9 100644
1eceb6c
--- libselinux-2.4/man/man3/getsockcreatecon.3
1eceb6c
+++ libselinux-2.4/man/man3/getsockcreatecon.3
2492943
@@ -49,6 +49,11 @@ Signal handlers that perform a
2492943
 must take care to
2492943
 save, reset, and restore the sockcreate context to avoid unexpected behavior.
2492943
 .
2492943
+
2492943
+.br
2492943
+.B Note:
2492943
+Contexts are thread specific.
2492943
+
2492943
 .SH "RETURN VALUE"
2492943
 On error \-1 is returned.
2492943
 On success 0 is returned.
1eceb6c
diff --git libselinux-2.4/man/man8/selinux.8 libselinux-2.4/man/man8/selinux.8
1eceb6c
index 9e3bdc4..fd20363 100644
1eceb6c
--- libselinux-2.4/man/man8/selinux.8
1eceb6c
+++ libselinux-2.4/man/man8/selinux.8
aa0f5b6
@@ -91,11 +91,13 @@ This manual page was written by Dan Walsh <dwalsh@redhat.com>.
aa0f5b6
 .BR sepolicy (8),
aa0f5b6
 .BR system-config-selinux (8),
aa0f5b6
 .BR togglesebool (8),
aa0f5b6
-.BR restorecon (8),
aa0f5b6
 .BR fixfiles (8),
aa0f5b6
+.BR restorecon (8),
aa0f5b6
 .BR setfiles (8),
aa0f5b6
 .BR semanage (8),
aa0f5b6
-.BR sepolicy(8)
aa0f5b6
+.BR sepolicy(8),
aa0f5b6
+.BR seinfo(8),
aa0f5b6
+.BR sesearch(8)
aa0f5b6
 
aa0f5b6
 Every confined service on the system has a man page in the following format:
aa0f5b6
 .br
1eceb6c
diff --git libselinux-2.4/src/Makefile libselinux-2.4/src/Makefile
1eceb6c
index 82cb6ed..ccc2699 100644
1eceb6c
--- libselinux-2.4/src/Makefile
1eceb6c
+++ libselinux-2.4/src/Makefile
13a8a0f
@@ -111,7 +111,7 @@ $(LIBA): $(OBJS)
5f9e314
 	$(RANLIB) $@
5f9e314
 
5f9e314
 $(LIBSO): $(LOBJS)
5f9e314
-	$(CC) $(CFLAGS) -shared -o $@ $^ -lpcre -ldl $(LDFLAGS) -L$(LIBDIR) -Wl,-soname,$(LIBSO),-z,defs,-z,relro
5f9e314
+	$(CC) $(CFLAGS) -shared -o $@ $^ -lpcre -llzma -ldl $(LDFLAGS) -L$(LIBDIR) -Wl,-soname,$(LIBSO),-z,defs,-z,relro
5f9e314
 	ln -sf $@ $(TARGET) 
5f9e314
 
5f9e314
 $(LIBPC): $(LIBPC).in ../VERSION
1eceb6c
diff --git libselinux-2.4/src/avc.c libselinux-2.4/src/avc.c
1eceb6c
index 2bd7d13..b1ec57f 100644
1eceb6c
--- libselinux-2.4/src/avc.c
1eceb6c
+++ libselinux-2.4/src/avc.c
1eceb6c
@@ -288,7 +288,7 @@ void avc_av_stats(void)
1eceb6c
 
1eceb6c
 	avc_release_lock(avc_lock);
1eceb6c
 
1eceb6c
-	avc_log(SELINUX_INFO, "%s:  %d AV entries and %d/%d buckets used, "
1eceb6c
+	avc_log(SELINUX_INFO, "%s:  %u AV entries and %d/%d buckets used, "
1eceb6c
 		"longest chain length %d\n", avc_prefix,
1eceb6c
 		avc_cache.active_nodes,
1eceb6c
 		slots_used, AVC_CACHE_SLOTS, max_chain_len);
1eceb6c
@@ -471,7 +471,7 @@ static int avc_insert(security_id_t ssid, security_id_t tsid,
1eceb6c
 
1eceb6c
 	if (ae->avd.seqno < avc_cache.latest_notif) {
1eceb6c
 		avc_log(SELINUX_WARNING,
1eceb6c
-			"%s:  seqno %d < latest_notif %d\n", avc_prefix,
1eceb6c
+			"%s:  seqno %u < latest_notif %u\n", avc_prefix,
1eceb6c
 			ae->avd.seqno, avc_cache.latest_notif);
1eceb6c
 		errno = EAGAIN;
1eceb6c
 		rc = -1;
1eceb6c
diff --git libselinux-2.4/src/avc_internal.c libselinux-2.4/src/avc_internal.c
1eceb6c
index f735e73..be94857 100644
1eceb6c
--- libselinux-2.4/src/avc_internal.c
1eceb6c
+++ libselinux-2.4/src/avc_internal.c
1eceb6c
@@ -125,14 +125,14 @@ static int avc_netlink_receive(char *buf, unsigned buflen, int blocking)
1eceb6c
 
1eceb6c
 	if (nladdrlen != sizeof nladdr) {
1eceb6c
 		avc_log(SELINUX_WARNING,
1eceb6c
-			"%s:  warning: netlink address truncated, len %d?\n",
1eceb6c
+			"%s:  warning: netlink address truncated, len %u?\n",
1eceb6c
 			avc_prefix, nladdrlen);
1eceb6c
 		return -1;
1eceb6c
 	}
1eceb6c
 
1eceb6c
 	if (nladdr.nl_pid) {
1eceb6c
 		avc_log(SELINUX_WARNING,
1eceb6c
-			"%s:  warning: received spoofed netlink packet from: %d\n",
1eceb6c
+			"%s:  warning: received spoofed netlink packet from: %u\n",
1eceb6c
 			avc_prefix, nladdr.nl_pid);
1eceb6c
 		return -1;
1eceb6c
 	}
1eceb6c
@@ -197,7 +197,7 @@ static int avc_netlink_process(char *buf)
1eceb6c
 	case SELNL_MSG_POLICYLOAD:{
1eceb6c
 		struct selnl_msg_policyload *msg = NLMSG_DATA(nlh);
1eceb6c
 		avc_log(SELINUX_INFO,
1eceb6c
-			"%s:  received policyload notice (seqno=%d)\n",
1eceb6c
+			"%s:  received policyload notice (seqno=%u)\n",
1eceb6c
 			avc_prefix, msg->seqno);
1eceb6c
 		rc = avc_ss_reset(msg->seqno);
1eceb6c
 		if (rc < 0) {
1eceb6c
diff --git libselinux-2.4/src/avc_sidtab.c libselinux-2.4/src/avc_sidtab.c
1eceb6c
index 52f21df..c775430 100644
1eceb6c
--- libselinux-2.4/src/avc_sidtab.c
1eceb6c
+++ libselinux-2.4/src/avc_sidtab.c
ee8c867
@@ -81,6 +81,11 @@ sidtab_context_to_sid(struct sidtab *s,
ee8c867
 	int hvalue, rc = 0;
ee8c867
 	struct sidtab_node *cur;
ee8c867
 
ee8c867
+	if (! ctx) {
ee8c867
+		errno=EINVAL;
ee8c867
+		return -1;
ee8c867
+	}
ee8c867
+
ee8c867
 	*sid = NULL;
ee8c867
 	hvalue = sidtab_hash(ctx);
ee8c867
 
1eceb6c
@@ -124,7 +129,7 @@ void sidtab_sid_stats(struct sidtab *h, char *buf, int buflen)
1eceb6c
 	}
1eceb6c
 
1eceb6c
 	snprintf(buf, buflen,
1eceb6c
-		 "%s:  %d SID entries and %d/%d buckets used, longest "
1eceb6c
+		 "%s:  %u SID entries and %d/%d buckets used, longest "
1eceb6c
 		 "chain length %d\n", avc_prefix, h->nel, slots_used,
1eceb6c
 		 SIDTAB_SIZE, max_chain_len);
1eceb6c
 }
1eceb6c
diff --git libselinux-2.4/src/canonicalize_context.c libselinux-2.4/src/canonicalize_context.c
13a8a0f
index 7cf3139..364a746 100644
1eceb6c
--- libselinux-2.4/src/canonicalize_context.c
1eceb6c
+++ libselinux-2.4/src/canonicalize_context.c
13a8a0f
@@ -17,6 +17,11 @@ int security_canonicalize_context_raw(const char * con,
ee8c867
 	size_t size;
ee8c867
 	int fd, ret;
ee8c867
 
ee8c867
+	if (! con) {
ee8c867
+		errno=EINVAL;
ee8c867
+		return -1;
ee8c867
+	}
ee8c867
+
ee8c867
 	if (!selinux_mnt) {
ee8c867
 		errno = ENOENT;
ee8c867
 		return -1;
1eceb6c
diff --git libselinux-2.4/src/check_context.c libselinux-2.4/src/check_context.c
13a8a0f
index 52063fa..234749c 100644
1eceb6c
--- libselinux-2.4/src/check_context.c
1eceb6c
+++ libselinux-2.4/src/check_context.c
13a8a0f
@@ -14,6 +14,11 @@ int security_check_context_raw(const char * con)
ee8c867
 	char path[PATH_MAX];
ee8c867
 	int fd, ret;
ee8c867
 
ee8c867
+	if (! con) {
ee8c867
+		errno=EINVAL;
ee8c867
+		return -1;
ee8c867
+	}
ee8c867
+
ee8c867
 	if (!selinux_mnt) {
ee8c867
 		errno = ENOENT;
ee8c867
 		return -1;
1eceb6c
diff --git libselinux-2.4/src/compute_av.c libselinux-2.4/src/compute_av.c
13a8a0f
index 937e5c3..35ace7f 100644
1eceb6c
--- libselinux-2.4/src/compute_av.c
1eceb6c
+++ libselinux-2.4/src/compute_av.c
13a8a0f
@@ -26,6 +26,11 @@ int security_compute_av_flags_raw(const char * scon,
ee8c867
 		return -1;
ee8c867
 	}
ee8c867
 
ee8c867
+	if ((! scon) || (! tcon)) {
ee8c867
+		errno=EINVAL;
ee8c867
+		return -1;
ee8c867
+	}
ee8c867
+
ee8c867
 	snprintf(path, sizeof path, "%s/access", selinux_mnt);
ee8c867
 	fd = open(path, O_RDWR);
ee8c867
 	if (fd < 0)
1eceb6c
diff --git libselinux-2.4/src/compute_create.c libselinux-2.4/src/compute_create.c
13a8a0f
index 9559d42..14a65d1 100644
1eceb6c
--- libselinux-2.4/src/compute_create.c
1eceb6c
+++ libselinux-2.4/src/compute_create.c
13a8a0f
@@ -64,6 +64,11 @@ int security_compute_create_name_raw(const char * scon,
ee8c867
 		return -1;
ee8c867
 	}
ee8c867
 
ee8c867
+	if ((! scon) || (! tcon)) {
ee8c867
+		errno=EINVAL;
ee8c867
+		return -1;
ee8c867
+	}
ee8c867
+
ee8c867
 	snprintf(path, sizeof path, "%s/create", selinux_mnt);
ee8c867
 	fd = open(path, O_RDWR);
ee8c867
 	if (fd < 0)
1eceb6c
diff --git libselinux-2.4/src/compute_member.c libselinux-2.4/src/compute_member.c
13a8a0f
index 1fc7e41..065d996 100644
1eceb6c
--- libselinux-2.4/src/compute_member.c
1eceb6c
+++ libselinux-2.4/src/compute_member.c
13a8a0f
@@ -25,6 +25,11 @@ int security_compute_member_raw(const char * scon,
ee8c867
 		return -1;
ee8c867
 	}
ee8c867
 
ee8c867
+	if ((! scon) || (! tcon)) {
ee8c867
+		errno=EINVAL;
ee8c867
+		return -1;
ee8c867
+	}
ee8c867
+
ee8c867
 	snprintf(path, sizeof path, "%s/member", selinux_mnt);
ee8c867
 	fd = open(path, O_RDWR);
ee8c867
 	if (fd < 0)
1eceb6c
diff --git libselinux-2.4/src/compute_relabel.c libselinux-2.4/src/compute_relabel.c
13a8a0f
index 4615aee..cc77f36 100644
1eceb6c
--- libselinux-2.4/src/compute_relabel.c
1eceb6c
+++ libselinux-2.4/src/compute_relabel.c
13a8a0f
@@ -25,6 +25,11 @@ int security_compute_relabel_raw(const char * scon,
ee8c867
 		return -1;
ee8c867
 	}
ee8c867
 
ee8c867
+	if ((! scon) || (! tcon)) {
ee8c867
+		errno=EINVAL;
ee8c867
+		return -1;
ee8c867
+	}
ee8c867
+
ee8c867
 	snprintf(path, sizeof path, "%s/relabel", selinux_mnt);
ee8c867
 	fd = open(path, O_RDWR);
ee8c867
 	if (fd < 0)
1eceb6c
diff --git libselinux-2.4/src/compute_user.c libselinux-2.4/src/compute_user.c
13a8a0f
index b37c5d3..7703c26 100644
1eceb6c
--- libselinux-2.4/src/compute_user.c
1eceb6c
+++ libselinux-2.4/src/compute_user.c
13a8a0f
@@ -24,6 +24,11 @@ int security_compute_user_raw(const char * scon,
ee8c867
 		return -1;
ee8c867
 	}
ee8c867
 
ee8c867
+	if (! scon) {
ee8c867
+		errno=EINVAL;
ee8c867
+		return -1;
ee8c867
+	}
ee8c867
+
ee8c867
 	snprintf(path, sizeof path, "%s/user", selinux_mnt);
ee8c867
 	fd = open(path, O_RDWR);
ee8c867
 	if (fd < 0)
1eceb6c
diff --git libselinux-2.4/src/file_path_suffixes.h libselinux-2.4/src/file_path_suffixes.h
aa0f5b6
index 3c92424..d1f9b48 100644
1eceb6c
--- libselinux-2.4/src/file_path_suffixes.h
1eceb6c
+++ libselinux-2.4/src/file_path_suffixes.h
aa0f5b6
@@ -23,6 +23,7 @@ S_(BINPOLICY, "/policy/policy")
aa0f5b6
     S_(VIRTUAL_DOMAIN, "/contexts/virtual_domain_context")
aa0f5b6
     S_(VIRTUAL_IMAGE, "/contexts/virtual_image_context")
aa0f5b6
     S_(LXC_CONTEXTS, "/contexts/lxc_contexts")
aa0f5b6
+    S_(OPENSSH_CONTEXTS, "/contexts/openssh_contexts")
aa0f5b6
     S_(SYSTEMD_CONTEXTS, "/contexts/systemd_contexts")
aa0f5b6
     S_(FILE_CONTEXT_SUBS, "/contexts/files/file_contexts.subs")
aa0f5b6
     S_(FILE_CONTEXT_SUBS_DIST, "/contexts/files/file_contexts.subs_dist")
1eceb6c
diff --git libselinux-2.4/src/fsetfilecon.c libselinux-2.4/src/fsetfilecon.c
13a8a0f
index 52707d0..0cbe12d 100644
1eceb6c
--- libselinux-2.4/src/fsetfilecon.c
1eceb6c
+++ libselinux-2.4/src/fsetfilecon.c
7e1165a
@@ -9,8 +9,12 @@
7e1165a
 
ed9898e
 int fsetfilecon_raw(int fd, const char * context)
7e1165a
 {
7e1165a
-	int rc = fsetxattr(fd, XATTR_NAME_SELINUX, context, strlen(context) + 1,
7e1165a
-			 0);
7e1165a
+	int rc;
7e1165a
+	if (! context) {
7e1165a
+		errno=EINVAL;
7e1165a
+		return -1;
7e1165a
+	}
7e1165a
+	rc = fsetxattr(fd, XATTR_NAME_SELINUX, context, strlen(context) + 1, 0);
7e1165a
 	if (rc < 0 && errno == ENOTSUP) {
ed9898e
 		char * ccontext = NULL;
7e1165a
 		int err = errno;
1eceb6c
diff --git libselinux-2.4/src/label_android_property.c libselinux-2.4/src/label_android_property.c
1eceb6c
index b00eb07..5e1b76e 100644
1eceb6c
--- libselinux-2.4/src/label_android_property.c
1eceb6c
+++ libselinux-2.4/src/label_android_property.c
1eceb6c
@@ -101,7 +101,7 @@ static int process_line(struct selabel_handle *rec,
1eceb6c
 	items = sscanf(line_buf, "%255s %255s", prop, context);
1eceb6c
 	if (items != 2) {
1eceb6c
 		selinux_log(SELINUX_WARNING,
1eceb6c
-			    "%s:  line %d is missing fields, skipping\n", path,
1eceb6c
+			    "%s:  line %u is missing fields, skipping\n", path,
1eceb6c
 			    lineno);
1eceb6c
 		return 0;
1eceb6c
 	}
1eceb6c
@@ -111,7 +111,7 @@ static int process_line(struct selabel_handle *rec,
1eceb6c
 		spec_arr[nspec].property_key = strdup(prop);
1eceb6c
 		if (!spec_arr[nspec].property_key) {
1eceb6c
 			selinux_log(SELINUX_WARNING,
1eceb6c
-				    "%s:  out of memory at line %d on prop %s\n",
1eceb6c
+				    "%s:  out of memory at line %u on prop %s\n",
1eceb6c
 				    path, lineno, prop);
1eceb6c
 			return -1;
1eceb6c
 
1eceb6c
@@ -120,7 +120,7 @@ static int process_line(struct selabel_handle *rec,
1eceb6c
 		spec_arr[nspec].lr.ctx_raw = strdup(context);
1eceb6c
 		if (!spec_arr[nspec].lr.ctx_raw) {
1eceb6c
 			selinux_log(SELINUX_WARNING,
1eceb6c
-				    "%s:  out of memory at line %d on context %s\n",
1eceb6c
+				    "%s:  out of memory at line %u on context %s\n",
1eceb6c
 				    path, lineno, context);
1eceb6c
 			return -1;
1eceb6c
 		}
1eceb6c
diff --git libselinux-2.4/src/label_db.c libselinux-2.4/src/label_db.c
1eceb6c
index 999dd46..1b48735 100644
1eceb6c
--- libselinux-2.4/src/label_db.c
1eceb6c
+++ libselinux-2.4/src/label_db.c
1eceb6c
@@ -105,12 +105,12 @@ process_line(const char *path, char *line_buf, unsigned int line_num,
1eceb6c
 	 *   <object class> <object name> <security context>
1eceb6c
 	 */
1eceb6c
 	type = key = context = temp = NULL;
1eceb6c
-	items = sscanf(line_buf, "%as %as %as %as",
1eceb6c
+	items = sscanf(line_buf, "%ms %ms %ms %ms",
1eceb6c
 		       &type, &key, &context, &temp);
1eceb6c
 	if (items != 3) {
1eceb6c
 		if (items > 0)
1eceb6c
 			selinux_log(SELINUX_WARNING,
1eceb6c
-				    "%s:  line %d has invalid format, skipped",
1eceb6c
+				    "%s:  line %u has invalid format, skipped",
1eceb6c
 				    path, line_num);
1eceb6c
 		goto skip;
1eceb6c
 	}
1eceb6c
@@ -146,7 +146,7 @@ process_line(const char *path, char *line_buf, unsigned int line_num,
1eceb6c
 		spec->type = SELABEL_DB_DATATYPE;
1eceb6c
 	else {
1eceb6c
 		selinux_log(SELINUX_WARNING,
1eceb6c
-			    "%s:  line %d has invalid object type %s\n",
1eceb6c
+			    "%s:  line %u has invalid object type %s\n",
1eceb6c
 			    path, line_num, type);
1eceb6c
 		goto skip;
1eceb6c
 	}
1eceb6c
diff --git libselinux-2.4/src/label_file.c libselinux-2.4/src/label_file.c
1eceb6c
index 8e7b288..2a43310 100644
1eceb6c
--- libselinux-2.4/src/label_file.c
1eceb6c
+++ libselinux-2.4/src/label_file.c
1eceb6c
@@ -170,10 +170,10 @@ static int process_line(struct selabel_handle *rec,
1eceb6c
 	/* Skip comment lines and empty lines. */
1eceb6c
 	if (*buf_p == '#' || *buf_p == 0)
1eceb6c
 		return 0;
1eceb6c
-	items = sscanf(line_buf, "%as %as %as", &regex, &type, &context);
1eceb6c
+	items = sscanf(line_buf, "%ms %ms %ms", &regex, &type, &context);
1eceb6c
 	if (items < 2) {
1eceb6c
 		COMPAT_LOG(SELINUX_WARNING,
1eceb6c
-			    "%s:  line %d is missing fields, skipping\n", path,
1eceb6c
+			    "%s:  line %u is missing fields, skipping\n", path,
1eceb6c
 			    lineno);
1eceb6c
 		if (items == 1)
1eceb6c
 			free(regex);
1eceb6c
@@ -204,7 +204,7 @@ static int process_line(struct selabel_handle *rec,
1eceb6c
 	spec_arr[nspec].stem_id = find_stem_from_spec(data, regex);
1eceb6c
 	spec_arr[nspec].regex_str = regex;
1eceb6c
 	if (rec->validating && compile_regex(data, &spec_arr[nspec], &errbuf)) {
1eceb6c
-		COMPAT_LOG(SELINUX_WARNING, "%s:  line %d has invalid regex %s:  %s\n",
1eceb6c
+		COMPAT_LOG(SELINUX_WARNING, "%s:  line %u has invalid regex %s:  %s\n",
1eceb6c
 			   path, lineno, regex, (errbuf ? errbuf : "out of memory"));
1eceb6c
 	}
1eceb6c
 
1eceb6c
@@ -214,7 +214,7 @@ static int process_line(struct selabel_handle *rec,
1eceb6c
 	if (type) {
1eceb6c
 		mode_t mode = string_to_mode(type);
1eceb6c
 		if (mode == (mode_t)-1) {
1eceb6c
-			COMPAT_LOG(SELINUX_WARNING, "%s:  line %d has invalid file type %s\n",
1eceb6c
+			COMPAT_LOG(SELINUX_WARNING, "%s:  line %u has invalid file type %s\n",
1eceb6c
 				   path, lineno, type);
1eceb6c
 			mode = 0;
1eceb6c
 		}
1eceb6c
diff --git libselinux-2.4/src/label_media.c libselinux-2.4/src/label_media.c
1eceb6c
index 227785f..a09486b 100644
1eceb6c
--- libselinux-2.4/src/label_media.c
1eceb6c
+++ libselinux-2.4/src/label_media.c
1eceb6c
@@ -44,10 +44,10 @@ static int process_line(const char *path, char *line_buf, int pass,
1eceb6c
 	/* Skip comment lines and empty lines. */
1eceb6c
 	if (*buf_p == '#' || *buf_p == 0)
1eceb6c
 		return 0;
1eceb6c
-	items = sscanf(line_buf, "%as %as ", &key, &context);
1eceb6c
+	items = sscanf(line_buf, "%ms %ms ", &key, &context);
1eceb6c
 	if (items < 2) {
1eceb6c
 		selinux_log(SELINUX_WARNING,
1eceb6c
-			  "%s:  line %d is missing fields, skipping\n", path,
1eceb6c
+			  "%s:  line %u is missing fields, skipping\n", path,
1eceb6c
 			  lineno);
1eceb6c
 		if (items == 1)
1eceb6c
 			free(key);
1eceb6c
diff --git libselinux-2.4/src/label_x.c libselinux-2.4/src/label_x.c
1eceb6c
index 896ef02..8435b76 100644
1eceb6c
--- libselinux-2.4/src/label_x.c
1eceb6c
+++ libselinux-2.4/src/label_x.c
1eceb6c
@@ -46,10 +46,10 @@ static int process_line(const char *path, char *line_buf, int pass,
1eceb6c
 	/* Skip comment lines and empty lines. */
1eceb6c
 	if (*buf_p == '#' || *buf_p == 0)
1eceb6c
 		return 0;
1eceb6c
-	items = sscanf(line_buf, "%as %as %as ", &type, &key, &context);
1eceb6c
+	items = sscanf(line_buf, "%ms %ms %ms ", &type, &key, &context);
1eceb6c
 	if (items < 3) {
1eceb6c
 		selinux_log(SELINUX_WARNING,
1eceb6c
-			    "%s:  line %d is missing fields, skipping\n", path,
1eceb6c
+			    "%s:  line %u is missing fields, skipping\n", path,
1eceb6c
 			    lineno);
1eceb6c
 		if (items > 0)
1eceb6c
 			free(type);
1eceb6c
@@ -76,7 +76,7 @@ static int process_line(const char *path, char *line_buf, int pass,
1eceb6c
 			data->spec_arr[data->nspec].type = SELABEL_X_POLYSELN;
1eceb6c
 		else {
1eceb6c
 			selinux_log(SELINUX_WARNING,
1eceb6c
-				    "%s:  line %d has invalid object type %s\n",
1eceb6c
+				    "%s:  line %u has invalid object type %s\n",
1eceb6c
 				    path, lineno, type);
1eceb6c
 			return 0;
1eceb6c
 		}
1eceb6c
diff --git libselinux-2.4/src/load_policy.c libselinux-2.4/src/load_policy.c
1eceb6c
index 21ee58b..d28dfa7 100644
1eceb6c
--- libselinux-2.4/src/load_policy.c
1eceb6c
+++ libselinux-2.4/src/load_policy.c
5f9e314
@@ -16,6 +16,82 @@
5f9e314
 #include <dlfcn.h>
5f9e314
 #include "policy.h"
5f9e314
 #include <limits.h>
5f9e314
+#include <lzma.h>
5f9e314
+
5f9e314
+static char *lzmaread(int fd, size_t *rsize) {
5f9e314
+	int capacity = 64*1024;
5f9e314
+	char *buf = NULL;
5f9e314
+	int tmpsize = 8 * 1024;
5f9e314
+	unsigned char tmp[tmpsize];
5f9e314
+	unsigned char tmp_out[tmpsize];
5f9e314
+	size_t size = 0;
5f9e314
+	lzma_stream strm = LZMA_STREAM_INIT;
5f9e314
+	lzma_action action = LZMA_RUN;
5f9e314
+	lzma_ret ret;
5f9e314
+	
5f9e314
+	FILE *stream = fdopen (fd, "r");
5f9e314
+	if (!stream) {
5f9e314
+		return NULL;
5f9e314
+	}
5f9e314
+	ret = lzma_stream_decoder(&strm, UINT64_MAX,
5f9e314
+				  LZMA_CONCATENATED);
5f9e314
+	
5f9e314
+	strm.avail_in = 0;
5f9e314
+	strm.next_out = tmp_out;
5f9e314
+	strm.avail_out = tmpsize;
5f9e314
+	
5f9e314
+	buf = (char *) malloc (capacity);
5f9e314
+	if (!buf)
5f9e314
+		goto err;
5f9e314
+	
5f9e314
+	while (1) {
5f9e314
+		if (strm.avail_in == 0) {
5f9e314
+			strm.next_in = tmp;
5f9e314
+			strm.avail_in = fread(tmp, 1, tmpsize, stream);
5f9e314
+			
5f9e314
+			if (ferror(stream)) {
5f9e314
+				// POSIX says that fread() sets errno if
5f9e314
+				// an error occurred. ferror() doesn't
5f9e314
+				// touch errno.
5f9e314
+				goto err;
5f9e314
+			}
5f9e314
+			if (feof(stream)) action = LZMA_FINISH;
5f9e314
+		}
5f9e314
+		
5f9e314
+		ret = lzma_code(&strm, action);
5f9e314
+		
5f9e314
+		// Write and check write error before checking decoder error.
5f9e314
+		// This way as much data as possible gets written to output
5f9e314
+		// even if decoder detected an error.
5f9e314
+		if (strm.avail_out == 0 || ret != LZMA_OK) {
5f9e314
+			const size_t num =  tmpsize - strm.avail_out;
5f9e314
+			if (num > capacity) {
5f9e314
+				buf = (char*) realloc (buf, size*2);
5f9e314
+				capacity = size;
5f9e314
+			}
5f9e314
+			memcpy (buf+size, tmp_out, num);
5f9e314
+			capacity -= num;
5f9e314
+			size += num;
5f9e314
+			strm.next_out = tmp_out;
5f9e314
+			strm.avail_out = tmpsize;
5f9e314
+		}
5f9e314
+		if (ret != LZMA_OK) {
5f9e314
+			if (ret == LZMA_STREAM_END) {
5f9e314
+				break;
5f9e314
+			} else {
5f9e314
+				goto err;
5f9e314
+			}
5f9e314
+		}
5f9e314
+	}
5f9e314
+	*rsize = size;
5f9e314
+	
5f9e314
+	goto exit;
5f9e314
+err:
5f9e314
+	free(buf); buf = NULL;
5f9e314
+exit:
5f9e314
+	lzma_end(&strm;;
5f9e314
+	return buf;
5f9e314
+}
5f9e314
 
5f9e314
 int security_load_policy(void *data, size_t len)
5f9e314
 {
5f9e314
@@ -55,7 +131,7 @@ int selinux_mkload_policy(int preservebools)
5f9e314
 	struct stat sb;
5f9e314
 	struct utsname uts;
5f9e314
 	size_t size;
5f9e314
-	void *map, *data;
5f9e314
+	void *map = NULL, *data=NULL;
5f9e314
 	int fd, rc = -1, prot;
5f9e314
 	sepol_policydb_t *policydb;
5f9e314
 	sepol_policy_file_t *pf;
5f9e314
@@ -181,24 +257,28 @@ checkbool:
5f9e314
 		goto dlclose;
5f9e314
 	}
5f9e314
 
5f9e314
-	if (fstat(fd, &sb) < 0) {
5f9e314
-		fprintf(stderr,
5f9e314
-			"SELinux:  Could not stat policy file %s:  %s\n",
5f9e314
-			path, strerror(errno));
5f9e314
-		goto close;
5f9e314
-	}
5f9e314
-
5f9e314
-	prot = PROT_READ;
5f9e314
-	if (setlocaldefs || preservebools)
5f9e314
-		prot |= PROT_WRITE;
5f9e314
+	data = lzmaread(fd,&size);
5f9e314
 
5f9e314
-	size = sb.st_size;
5f9e314
-	data = map = mmap(NULL, size, prot, MAP_PRIVATE, fd, 0);
5f9e314
-	if (map == MAP_FAILED) {
5f9e314
-		fprintf(stderr,
5f9e314
-			"SELinux:  Could not map policy file %s:  %s\n",
5f9e314
+	if (!data) {
5f9e314
+		if (fstat(fd, &sb) < 0) {
5f9e314
+			fprintf(stderr,
5f9e314
+				"SELinux:  Could not stat policy file %s:  %s\n",
5f9e314
 			path, strerror(errno));
5f9e314
-		goto close;
5f9e314
+			goto close;
5f9e314
+		}
5f9e314
+		
5f9e314
+		prot = PROT_READ;
5f9e314
+		if (setlocaldefs || preservebools)
5f9e314
+			prot |= PROT_WRITE;
5f9e314
+		
5f9e314
+		size = sb.st_size;
5f9e314
+		data = map = mmap(NULL, size, prot, MAP_PRIVATE, fd, 0);
5f9e314
+		if (map == MAP_FAILED) {
5f9e314
+			fprintf(stderr,
5f9e314
+				"SELinux:  Could not map policy file %s:  %s\n",
5f9e314
+				path, strerror(errno));
5f9e314
+			goto close;
5f9e314
+		}
5f9e314
 	}
5f9e314
 
5f9e314
 	if (vers > kernvers && usesepol) {
5f9e314
@@ -210,6 +290,8 @@ checkbool:
5f9e314
 			goto unmap;
5f9e314
 		}
5f9e314
 		policy_file_set_mem(pf, data, size);
5f9e314
+		if (!map)
5f9e314
+			free(data);
5f9e314
 		if (policydb_read(policydb, pf)) {
5f9e314
 			policy_file_free(pf);
5f9e314
 			policydb_free(policydb);
5f9e314
@@ -223,7 +305,8 @@ checkbool:
5f9e314
 				path);
5f9e314
 			policy_file_free(pf);
5f9e314
 			policydb_free(policydb);
5f9e314
-			munmap(map, sb.st_size);
5f9e314
+			if (map)
5f9e314
+				munmap(map, sb.st_size);
5f9e314
 			close(fd);
5f9e314
 			vers--;
5f9e314
 			goto search;
5f9e314
@@ -275,7 +358,7 @@ checkbool:
5f9e314
 #endif
5f9e314
 	}
5f9e314
 
5f9e314
-
5f9e314
+	
5f9e314
 	rc = security_load_policy(data, size);
5f9e314
 	
5f9e314
 	if (rc)
5f9e314
@@ -286,7 +369,8 @@ checkbool:
5f9e314
       unmap:
5f9e314
 	if (data != map)
5f9e314
 		free(data);
5f9e314
-	munmap(map, sb.st_size);
5f9e314
+	if (map)
5f9e314
+		munmap(map, sb.st_size);
5f9e314
       close:
5f9e314
 	close(fd);
5f9e314
       dlclose:
1eceb6c
diff --git libselinux-2.4/src/lsetfilecon.c libselinux-2.4/src/lsetfilecon.c
13a8a0f
index 1d3b28a..ea6d70b 100644
1eceb6c
--- libselinux-2.4/src/lsetfilecon.c
1eceb6c
+++ libselinux-2.4/src/lsetfilecon.c
7e1165a
@@ -9,8 +9,13 @@
e61de3d
 
ed9898e
 int lsetfilecon_raw(const char *path, const char * context)
e61de3d
 {
e61de3d
-	int rc = lsetxattr(path, XATTR_NAME_SELINUX, context, strlen(context) + 1,
7e1165a
-			 0);
e61de3d
+	int rc;
e61de3d
+	if (! context) {
e61de3d
+		errno=EINVAL;
e61de3d
+		return -1;
e61de3d
+	}
e61de3d
+
7e1165a
+	rc = lsetxattr(path, XATTR_NAME_SELINUX, context, strlen(context) + 1, 0);
e61de3d
 	if (rc < 0 && errno == ENOTSUP) {
ed9898e
 		char * ccontext = NULL;
7e1165a
 		int err = errno;
1eceb6c
diff --git libselinux-2.4/src/matchpathcon.c libselinux-2.4/src/matchpathcon.c
1eceb6c
index 3b96b1d..3868711 100644
1eceb6c
--- libselinux-2.4/src/matchpathcon.c
1eceb6c
+++ libselinux-2.4/src/matchpathcon.c
495b754
@@ -2,6 +2,7 @@
974a6e4
 #include <string.h>
974a6e4
 #include <errno.h>
974a6e4
 #include <stdio.h>
974a6e4
+#include <syslog.h>
974a6e4
 #include "selinux_internal.h"
974a6e4
 #include "label_internal.h"
974a6e4
 #include "callbacks.h"
495b754
@@ -62,7 +63,7 @@ static void
974a6e4
 {
974a6e4
 	va_list ap;
974a6e4
 	va_start(ap, fmt);
974a6e4
-	vfprintf(stderr, fmt, ap);
974a6e4
+	vsyslog(LOG_ERR, fmt, ap);
974a6e4
 	va_end(ap);
974a6e4
 }
b5b41bc
 
1eceb6c
@@ -541,7 +542,7 @@ int compat_validate(struct selabel_handle *rec,
1eceb6c
 		if (rc < 0) {
1eceb6c
 			if (lineno) {
1eceb6c
 				COMPAT_LOG(SELINUX_WARNING,
1eceb6c
-					    "%s: line %d has invalid context %s\n",
1eceb6c
+					    "%s: line %u has invalid context %s\n",
1eceb6c
 						path, lineno, *ctx);
1eceb6c
 			} else {
1eceb6c
 				COMPAT_LOG(SELINUX_WARNING,
1eceb6c
diff --git libselinux-2.4/src/selinux_config.c libselinux-2.4/src/selinux_config.c
aa0f5b6
index 30e9dc7..1bfe500 100644
1eceb6c
--- libselinux-2.4/src/selinux_config.c
1eceb6c
+++ libselinux-2.4/src/selinux_config.c
aa0f5b6
@@ -50,8 +50,9 @@
aa0f5b6
 #define FILE_CONTEXT_SUBS_DIST 25
aa0f5b6
 #define LXC_CONTEXTS      26
aa0f5b6
 #define BOOLEAN_SUBS      27
aa0f5b6
-#define SYSTEMD_CONTEXTS  28
aa0f5b6
-#define NEL               29
aa0f5b6
+#define OPENSSH_CONTEXTS  28
aa0f5b6
+#define SYSTEMD_CONTEXTS  29
aa0f5b6
+#define NEL               30
aa0f5b6
 
aa0f5b6
 /* Part of one-time lazy init */
aa0f5b6
 static pthread_once_t once = PTHREAD_ONCE_INIT;
aa0f5b6
@@ -493,6 +494,13 @@ const char *selinux_lxc_contexts_path(void)
aa0f5b6
 
aa0f5b6
 hidden_def(selinux_lxc_contexts_path)
aa0f5b6
 
aa0f5b6
+const char *selinux_openssh_contexts_path(void)
aa0f5b6
+{
aa0f5b6
+    return get_path(OPENSSH_CONTEXTS);
aa0f5b6
+}
aa0f5b6
+
aa0f5b6
+hidden_def(selinux_openssh_contexts_path)
aa0f5b6
+
aa0f5b6
 const char *selinux_systemd_contexts_path(void)
aa0f5b6
 {
aa0f5b6
 	return get_path(SYSTEMD_CONTEXTS);
1eceb6c
diff --git libselinux-2.4/src/selinux_internal.h libselinux-2.4/src/selinux_internal.h
aa0f5b6
index afb2170..fe8eb67 100644
1eceb6c
--- libselinux-2.4/src/selinux_internal.h
1eceb6c
+++ libselinux-2.4/src/selinux_internal.h
aa0f5b6
@@ -82,6 +82,7 @@ hidden_proto(selinux_mkload_policy)
aa0f5b6
     hidden_proto(selinux_customizable_types_path)
aa0f5b6
     hidden_proto(selinux_media_context_path)
aa0f5b6
     hidden_proto(selinux_x_context_path)
aa0f5b6
+    hidden_proto(selinux_openssh_contexts_path)
aa0f5b6
     hidden_proto(selinux_sepgsql_context_path)
aa0f5b6
     hidden_proto(selinux_systemd_contexts_path)
aa0f5b6
     hidden_proto(selinux_path)
1eceb6c
diff --git libselinux-2.4/src/setfilecon.c libselinux-2.4/src/setfilecon.c
13a8a0f
index d05969c..3f0200e 100644
1eceb6c
--- libselinux-2.4/src/setfilecon.c
1eceb6c
+++ libselinux-2.4/src/setfilecon.c
7e1165a
@@ -9,8 +9,12 @@
7e1165a
 
ed9898e
 int setfilecon_raw(const char *path, const char * context)
7e1165a
 {
7e1165a
-	int rc = setxattr(path, XATTR_NAME_SELINUX, context, strlen(context) + 1,
7e1165a
-			0);
7e1165a
+	int rc;
7e1165a
+	if (! context) {
7e1165a
+		errno=EINVAL;
7e1165a
+		return -1;
7e1165a
+	}
7e1165a
+	rc = setxattr(path, XATTR_NAME_SELINUX, context, strlen(context) + 1, 0);
7e1165a
 	if (rc < 0 && errno == ENOTSUP) {
ed9898e
 		char * ccontext = NULL;
7e1165a
 		int err = errno;
1eceb6c
diff --git libselinux-2.4/utils/sefcontext_compile.c libselinux-2.4/utils/sefcontext_compile.c
1eceb6c
index 504699d..adb2b0c 100644
1eceb6c
--- libselinux-2.4/utils/sefcontext_compile.c
1eceb6c
+++ libselinux-2.4/utils/sefcontext_compile.c
1eceb6c
@@ -73,7 +73,7 @@ static int process_file(struct saved_data *data, const char *filename)
1eceb6c
 		spec->lr.ctx_raw = context;
1eceb6c
 		spec->mode = string_to_mode(mode);
1eceb6c
 		if (spec->mode == (mode_t)-1) {
1eceb6c
-			fprintf(stderr, "%s: line %d has invalid file type %s\n",
1eceb6c
+			fprintf(stderr, "%s: line %u has invalid file type %s\n",
1eceb6c
 				regex, line_num + 1, mode);
1eceb6c
 			spec->mode = 0;
1eceb6c
 		}
1eceb6c
diff --git libselinux-2.4/utils/togglesebool.c libselinux-2.4/utils/togglesebool.c
1eceb6c
index ad0d2a2..309f83b 100644
1eceb6c
--- libselinux-2.4/utils/togglesebool.c
1eceb6c
+++ libselinux-2.4/utils/togglesebool.c
1eceb6c
@@ -86,7 +86,7 @@ int main(int argc, char **argv)
1eceb6c
 					       argv[i], pwd->pw_name);
1eceb6c
 				else
1eceb6c
 					syslog(LOG_NOTICE,
1eceb6c
-					       "The %s policy boolean was toggled by uid:%d",
1eceb6c
+					       "The %s policy boolean was toggled by uid:%u",
1eceb6c
 					       argv[i], getuid());
aa0f5b6
 
1eceb6c
 			}