a632dc7
diff -up libselinux-2.0.96/man/man3/security_setenforce.3.rhat libselinux-2.0.96/man/man3/security_setenforce.3
a632dc7
--- libselinux-2.0.96/man/man3/security_setenforce.3.rhat	2010-09-22 17:14:11.000000000 -0400
a632dc7
+++ libselinux-2.0.96/man/man3/security_setenforce.3	2010-09-22 17:11:58.000000000 -0400
a632dc7
@@ -1 +1 @@
a632dc7
-.so security_getenforce.3
a632dc7
+.so man3/security_getenforce.3
a632dc7
diff -up libselinux-2.0.96/man/man8/selinuxconlist.8.rhat libselinux-2.0.96/man/man8/selinuxconlist.8
a632dc7
--- libselinux-2.0.96/man/man8/selinuxconlist.8.rhat	2010-08-04 15:21:39.000000000 -0400
a632dc7
+++ libselinux-2.0.96/man/man8/selinuxconlist.8	2010-08-04 15:21:39.000000000 -0400
792921f
@@ -0,0 +1,18 @@
792921f
+.TH "selinuxconlist" "1" "7 May 2008" "dwalsh@redhat.com" "SELinux Command Line documentation"
792921f
+.SH "NAME"
792921f
+selinuxconlist \- list all SELinux context reachable for user
792921f
+.SH "SYNOPSIS"
792921f
+.B selinuxconlist [-l level] user [context]
792921f
+
792921f
+.SH "DESCRIPTION"
792921f
+.B selinuxconlist
792921f
+reports the list of context reachable for user from the current context or specified context
792921f
+
792921f
+.B \-l level
792921f
+mcs/mls level
792921f
+
792921f
+.SH AUTHOR	
792921f
+This manual page was written by Dan Walsh <dwalsh@redhat.com>.
792921f
+
792921f
+.SH "SEE ALSO"
792921f
+secon(8), selinuxdefcon(8)
a632dc7
diff -up libselinux-2.0.96/man/man8/selinuxdefcon.8.rhat libselinux-2.0.96/man/man8/selinuxdefcon.8
a632dc7
--- libselinux-2.0.96/man/man8/selinuxdefcon.8.rhat	2010-08-04 15:21:39.000000000 -0400
a632dc7
+++ libselinux-2.0.96/man/man8/selinuxdefcon.8	2010-08-04 15:21:39.000000000 -0400
4ed79e3
@@ -0,0 +1,24 @@
792921f
+.TH "selinuxdefcon" "1" "7 May 2008" "dwalsh@redhat.com" "SELinux Command Line documentation"
792921f
+.SH "NAME"
4ed79e3
+selinuxdefcon \- report default SELinux context for user 
792921f
+
792921f
+.SH "SYNOPSIS"
995afc0
+.B selinuxdefcon [-l level] user fromcon
792921f
+
792921f
+.SH "DESCRIPTION"
4ed79e3
+.B selinuxdefcon
995afc0
+reports the default context for the specified user from the specified context
792921f
+
792921f
+.B \-l level
792921f
+mcs/mls level
792921f
+
4ed79e3
+.SH EXAMPLE
4ed79e3
+# selinuxdefcon jsmith system_u:system_r:sshd_t:s0
4ed79e3
+.br
4ed79e3
+unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023
4ed79e3
+
792921f
+.SH AUTHOR	
792921f
+This manual page was written by Dan Walsh <dwalsh@redhat.com>.
792921f
+
792921f
+.SH "SEE ALSO"
792921f
+secon(8), selinuxconlist(8)
a632dc7
diff -up libselinux-2.0.96/src/audit2why.c.rhat libselinux-2.0.96/src/audit2why.c
a632dc7
--- libselinux-2.0.96/src/audit2why.c.rhat	2010-06-16 08:03:39.000000000 -0400
a632dc7
+++ libselinux-2.0.96/src/audit2why.c	2010-08-04 15:21:39.000000000 -0400
5abec27
@@ -1,3 +1,6 @@
5abec27
+/* Workaround for http://bugs.python.org/issue4835 */
5abec27
+#define SIZEOF_SOCKET_T SIZEOF_INT
5abec27
+
5abec27
 #include <Python.h>
5abec27
 #include <unistd.h>
5abec27
 #include <stdlib.h>
a632dc7
@@ -255,6 +258,8 @@ static int __policy_init(const char *ini
4235807
 	fclose(fp);
4235807
 	sepol_set_policydb(&avc->policydb->p);
4235807
 	avc->handle = sepol_handle_create();
4235807
+	/* Turn off messages */
4235807
+	sepol_msg_set_callback(avc->handle, NULL, NULL);
4235807
 
4235807
 	rc = sepol_bool_count(avc->handle,
4235807
 			      avc->policydb, &cnt);
a632dc7
@@ -287,8 +292,10 @@ static int __policy_init(const char *ini
5abec27
 static PyObject *init(PyObject *self __attribute__((unused)), PyObject *args) {
5abec27
   int result;
5abec27
   char *init_path=NULL;
5abec27
-  if (PyArg_ParseTuple(args,(char *)"|s:policy_init",&init_path)) 
5abec27
-	  result = __policy_init(init_path);
4235807
+  if (!PyArg_ParseTuple(args,(char *)"|s:policy_init",&init_path)) {
4235807
+    return NULL;
5abec27
+  }
5abec27
+  result = __policy_init(init_path);
5abec27
   return Py_BuildValue("i", result);
5abec27
 }
5abec27
 
a632dc7
@@ -353,7 +360,11 @@ static PyObject *analyze(PyObject *self 
5abec27
 		strObj = PyList_GetItem(listObj, i); /* Can't fail */
5abec27
 		
5abec27
 		/* make it a string */
5abec27
+#if PY_MAJOR_VERSION >= 3
4235807
+		permstr = _PyUnicode_AsString( strObj );
5abec27
+#else
5abec27
 		permstr = PyString_AsString( strObj );
5abec27
+#endif
5abec27
 		
5abec27
 		perm = string_to_av_perm(tclass, permstr);
5abec27
 		if (!perm) {
a632dc7
@@ -423,10 +434,39 @@ static PyMethodDef audit2whyMethods[] = 
5abec27
     {NULL, NULL, 0, NULL}        /* Sentinel */
5abec27
 };
5abec27
 
5abec27
+#if PY_MAJOR_VERSION >= 3
5abec27
+/* Module-initialization logic specific to Python 3 */
5abec27
+struct module_state {
5abec27
+	/* empty for now */
5abec27
+};
5abec27
+static struct PyModuleDef moduledef = {
5abec27
+	PyModuleDef_HEAD_INIT,
5abec27
+	"audit2why",
5abec27
+	NULL,
5abec27
+	sizeof(struct module_state),
5abec27
+	audit2whyMethods,
5abec27
+	NULL,
5abec27
+	NULL,
5abec27
+	NULL,
5abec27
+	NULL
5abec27
+};
5abec27
+
5abec27
+PyMODINIT_FUNC
5abec27
+PyInit_audit2why(void)
5abec27
+#else
5abec27
 PyMODINIT_FUNC
5abec27
 initaudit2why(void)
5abec27
+#endif
5abec27
 {
5abec27
-	PyObject *m = Py_InitModule("audit2why", audit2whyMethods);
5abec27
+	PyObject *m;
5abec27
+#if PY_MAJOR_VERSION >= 3
5abec27
+	m = PyModule_Create(&moduledef);
5abec27
+	if (m == NULL) {
5abec27
+		return NULL;
5abec27
+	}
5abec27
+#else
5abec27
+	m  = Py_InitModule("audit2why", audit2whyMethods);
5abec27
+#endif
5abec27
 	PyModule_AddIntConstant(m,"UNKNOWN", UNKNOWN);
5abec27
 	PyModule_AddIntConstant(m,"BADSCON", BADSCON);
5abec27
 	PyModule_AddIntConstant(m,"BADTCON", BADTCON);
a632dc7
@@ -440,4 +480,8 @@ initaudit2why(void)
5abec27
 	PyModule_AddIntConstant(m,"BOOLEAN", BOOLEAN);
5abec27
 	PyModule_AddIntConstant(m,"CONSTRAINT", CONSTRAINT);
5abec27
 	PyModule_AddIntConstant(m,"RBAC", RBAC);
5abec27
+
5abec27
+#if PY_MAJOR_VERSION >= 3
5abec27
+	return m;
5abec27
+#endif
5abec27
 }
a632dc7
diff -up libselinux-2.0.96/src/callbacks.c.rhat libselinux-2.0.96/src/callbacks.c
a632dc7
--- libselinux-2.0.96/src/callbacks.c.rhat	2010-06-16 08:03:39.000000000 -0400
a632dc7
+++ libselinux-2.0.96/src/callbacks.c	2010-08-04 15:21:39.000000000 -0400
a632dc7
@@ -16,6 +16,7 @@ default_selinux_log(int type __attribute
ee77868
 {
d0a06b2
 	int rc;
d0a06b2
 	va_list ap;
d0a06b2
+	if (is_selinux_enabled() == 0) return 0;
d0a06b2
 	va_start(ap, fmt);
d0a06b2
 	rc = vfprintf(stderr, fmt, ap);
d0a06b2
 	va_end(ap);
a632dc7
diff -up libselinux-2.0.96/src/get_context_list.c.rhat libselinux-2.0.96/src/get_context_list.c
a632dc7
--- libselinux-2.0.96/src/get_context_list.c.rhat	2010-06-16 08:03:39.000000000 -0400
a632dc7
+++ libselinux-2.0.96/src/get_context_list.c	2010-08-04 15:21:39.000000000 -0400
a632dc7
@@ -286,7 +286,6 @@ static int get_failsafe_context(const ch
159f7d2
 	if (buf[plen - 1] == '\n')
159f7d2
 		buf[plen - 1] = 0;
159f7d2
 
159f7d2
-      retry:
159f7d2
 	nlen = strlen(user) + 1 + plen + 1;
159f7d2
 	*newcon = malloc(nlen);
159f7d2
 	if (!(*newcon))
a632dc7
@@ -306,10 +305,6 @@ static int get_failsafe_context(const ch
159f7d2
 	if (security_check_context(*newcon) && errno != ENOENT) {
159f7d2
 		free(*newcon);
159f7d2
 		*newcon = 0;
159f7d2
-		if (strcmp(user, SELINUX_DEFAULTUSER)) {
159f7d2
-			user = SELINUX_DEFAULTUSER;
159f7d2
-			goto retry;
159f7d2
-		}
159f7d2
 		return -1;
159f7d2
 	}
159f7d2
 
a632dc7
@@ -418,13 +413,8 @@ int get_ordered_context_list(const char 
159f7d2
 
159f7d2
 	/* Determine the set of reachable contexts for the user. */
159f7d2
 	rc = security_compute_user(fromcon, user, &reachable);
159f7d2
-	if (rc < 0) {
159f7d2
-		/* Retry with the default SELinux user identity. */
159f7d2
-		user = SELINUX_DEFAULTUSER;
159f7d2
-		rc = security_compute_user(fromcon, user, &reachable);
159f7d2
-		if (rc < 0)
159f7d2
-			goto failsafe;
159f7d2
-	}
159f7d2
+	if (rc < 0)
159f7d2
+		goto failsafe;
159f7d2
 	nreach = 0;
159f7d2
 	for (ptr = reachable; *ptr; ptr++)
159f7d2
 		nreach++;
a632dc7
diff -up libselinux-2.0.96/src/Makefile.rhat libselinux-2.0.96/src/Makefile
a632dc7
--- libselinux-2.0.96/src/Makefile.rhat	2010-06-16 08:03:39.000000000 -0400
a632dc7
+++ libselinux-2.0.96/src/Makefile	2010-08-04 15:21:39.000000000 -0400
5abec27
@@ -1,9 +1,10 @@
5abec27
 # Installation directories.
5abec27
+PYTHON ?= python
5abec27
 PREFIX ?= $(DESTDIR)/usr
5abec27
 LIBDIR ?= $(PREFIX)/lib
5abec27
 SHLIBDIR ?= $(DESTDIR)/lib
5abec27
 INCLUDEDIR ?= $(PREFIX)/include
5abec27
-PYLIBVER ?= $(shell python -c 'import sys;print "python%d.%d" % sys.version_info[0:2]')
5abec27
+PYLIBVER ?= $(shell $(PYTHON) -c 'import sys;print("python%d.%d" % sys.version_info[0:2])')
5abec27
 PYINC ?= /usr/include/$(PYLIBVER)
5abec27
 PYLIB ?= /usr/lib/$(PYLIBVER)
5abec27
 PYTHONLIBDIR ?= $(LIBDIR)/$(PYLIBVER)
a632dc7
@@ -23,13 +24,13 @@ SWIGIF= selinuxswig_python.i selinuxswig
5abec27
 SWIGRUBYIF= selinuxswig_ruby.i
5abec27
 SWIGCOUT= selinuxswig_wrap.c
5abec27
 SWIGRUBYCOUT= selinuxswig_ruby_wrap.c
5abec27
-SWIGLOBJ:= $(patsubst %.c,%.lo,$(SWIGCOUT)) 
5abec27
+SWIGLOBJ:= $(patsubst %.c,$(PYPREFIX)%.lo,$(SWIGCOUT)) 
5abec27
 SWIGRUBYLOBJ:= $(patsubst %.c,%.lo,$(SWIGRUBYCOUT)) 
5abec27
-SWIGSO=_selinux.so
5abec27
+SWIGSO=$(PYPREFIX)_selinux.so
5abec27
 SWIGFILES=$(SWIGSO) selinux.py selinuxswig_python_exception.i
5abec27
 SWIGRUBYSO=_rubyselinux.so
5abec27
 LIBSO=$(TARGET).$(LIBVERSION)
5abec27
-AUDIT2WHYSO=audit2why.so
5abec27
+AUDIT2WHYSO=$(PYPREFIX)audit2why.so
5abec27
 
5abec27
 ifeq ($(DISABLE_AVC),y)
5abec27
 	UNUSED_SRCS+=avc.c avc_internal.c avc_sidtab.c mapping.c stringrep.c checkAccess.c
a632dc7
@@ -91,10 +92,10 @@ $(LIBPC): $(LIBPC).in
5abec27
 selinuxswig_python_exception.i: ../include/selinux/selinux.h
5abec27
 	bash exception.sh > $@ 
5abec27
 
5abec27
-audit2why.lo: audit2why.c
5abec27
+$(PYPREFIX)audit2why.lo: audit2why.c
5abec27
 	$(CC) $(CFLAGS) -I$(PYINC) -fPIC -DSHARED -c -o $@ $<
5abec27
 
5abec27
-$(AUDIT2WHYSO): audit2why.lo
5abec27
+$(AUDIT2WHYSO): $(PYPREFIX)audit2why.lo
5abec27
 	$(CC) $(CFLAGS) $(LDFLAGS) -shared -o $@ $^ -L. -lselinux ${LIBDIR}/libsepol.a -L$(LIBDIR) -Wl,-soname,$@
5abec27
 
5abec27
 %.o:  %.c policy.h
a632dc7
@@ -123,8 +124,8 @@ install: all 
5abec27
 
5abec27
 install-pywrap: pywrap
5abec27
 	test -d $(PYTHONLIBDIR)/site-packages/selinux || install -m 755 -d $(PYTHONLIBDIR)/site-packages/selinux
5abec27
-	install -m 755 $(SWIGSO) $(PYTHONLIBDIR)/site-packages/selinux
5abec27
-	install -m 755 $(AUDIT2WHYSO) $(PYTHONLIBDIR)/site-packages/selinux
5abec27
+	install -m 755 $(SWIGSO) $(PYTHONLIBDIR)/site-packages/selinux/_selinux.so
5abec27
+	install -m 755 $(AUDIT2WHYSO) $(PYTHONLIBDIR)/site-packages/selinux/audit2why.so
5abec27
 	install -m 644  selinux.py $(PYTHONLIBDIR)/site-packages/selinux/__init__.py
5abec27
 
5abec27
 install-rubywrap: rubywrap
a632dc7
diff -up libselinux-2.0.96/src/matchpathcon.c.rhat libselinux-2.0.96/src/matchpathcon.c
a632dc7
--- libselinux-2.0.96/src/matchpathcon.c.rhat	2010-06-16 08:03:39.000000000 -0400
a632dc7
+++ libselinux-2.0.96/src/matchpathcon.c	2010-08-04 15:21:39.000000000 -0400
974a6e4
@@ -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"
a632dc7
@@ -57,7 +58,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
 
a632dc7
diff -up libselinux-2.0.96/src/selinuxswig_python.i.rhat libselinux-2.0.96/src/selinuxswig_python.i
a632dc7
--- libselinux-2.0.96/src/selinuxswig_python.i.rhat	2010-06-16 08:03:39.000000000 -0400
a632dc7
+++ libselinux-2.0.96/src/selinuxswig_python.i	2010-08-23 10:27:44.000000000 -0400
a632dc7
@@ -45,7 +45,7 @@ def install(src, dest):
5abec27
 	PyObject* list = PyList_New(*$2);
5abec27
 	int i;
5abec27
 	for (i = 0; i < *$2; i++) {
5abec27
-		PyList_SetItem(list, i, PyString_FromString((*$1)[i]));
5abec27
+		PyList_SetItem(list, i, PyBytes_FromString((*$1)[i]));
5abec27
 	}
5abec27
 	$result = SWIG_Python_AppendOutput($result, list);
5abec27
 }
a632dc7
@@ -74,7 +74,9 @@ def install(src, dest):
5abec27
 			len++;
5abec27
 		plist = PyList_New(len);
5abec27
 		for (i = 0; i < len; i++) {
5abec27
-			PyList_SetItem(plist, i, PyString_FromString((*$1)[i]));
5abec27
+			PyList_SetItem(plist, i, 
5abec27
+                                       PyBytes_FromString((*$1)[i])
5abec27
+                                       );
5abec27
 		}
5abec27
 	} else {
5abec27
 		plist = PyList_New(0);
a632dc7
@@ -91,7 +93,9 @@ def install(src, dest):
5abec27
 	if (*$1) {
5abec27
 		plist = PyList_New(result);
5abec27
 		for (i = 0; i < result; i++) {
5abec27
-			PyList_SetItem(plist, i, PyString_FromString((*$1)[i]));
5abec27
+			PyList_SetItem(plist, i, 
5abec27
+                                       PyBytes_FromString((*$1)[i])
5abec27
+                                       );
5abec27
 		}
5abec27
 	} else {
5abec27
 		plist = PyList_New(0);
a632dc7
@@ -144,16 +148,20 @@ def install(src, dest):
5abec27
 	$1 = (char**) malloc(size + 1);
5abec27
 
5abec27
 	for(i = 0; i < size; i++) {
5abec27
-		if (!PyString_Check(PySequence_GetItem($input, i))) {
5abec27
-			PyErr_SetString(PyExc_ValueError, "Sequence must contain only strings");
5abec27
+		if (!PyBytes_Check(PySequence_GetItem($input, i))) {
5abec27
+			PyErr_SetString(PyExc_ValueError, "Sequence must contain only bytes");
5abec27
+
5abec27
 			return NULL;
5abec27
 		}
5abec27
+
5abec27
 	}
5abec27
 		
5abec27
 	for(i = 0; i < size; i++) {
5abec27
 		s = PySequence_GetItem($input, i);
5abec27
-		$1[i] = (char*) malloc(PyString_Size(s) + 1);
5abec27
-		strcpy($1[i], PyString_AsString(s));
5abec27
+
5abec27
+		$1[i] = (char*) malloc(PyBytes_Size(s) + 1);
5abec27
+		strcpy($1[i], PyBytes_AsString(s));
5abec27
+
5abec27
 	}
5abec27
 	$1[size] = NULL;
5abec27
 }