psss / rpms / libselinux

Forked from rpms/libselinux 5 years ago
Clone
4546044
diff --exclude-from=exclude -N -u -r nsalibselinux/include/selinux/av_permissions.h libselinux-2.0.47/include/selinux/av_permissions.h
c4aa29e
--- nsalibselinux/include/selinux/av_permissions.h	2007-11-15 15:52:46.000000000 -0500
4546044
+++ libselinux-2.0.47/include/selinux/av_permissions.h	2008-01-11 10:55:14.000000000 -0500
c4aa29e
@@ -900,6 +900,8 @@
c4aa29e
 #define PACKET__SEND                              0x00000001UL
c4aa29e
 #define PACKET__RECV                              0x00000002UL
c4aa29e
 #define PACKET__RELABELTO                         0x00000004UL
c4aa29e
+#define PACKET__FLOW_IN                           0x00000008UL
c4aa29e
+#define PACKET__FLOW_OUT                          0x00000010UL
c4aa29e
 #define KEY__VIEW                                 0x00000001UL
c4aa29e
 #define KEY__READ                                 0x00000002UL
c4aa29e
 #define KEY__WRITE                                0x00000004UL
4546044
diff --exclude-from=exclude -N -u -r nsalibselinux/src/audit2why.c libselinux-2.0.47/src/audit2why.c
831e63b
--- nsalibselinux/src/audit2why.c	1969-12-31 19:00:00.000000000 -0500
c633d69
+++ libselinux-2.0.47/src/audit2why.c	2008-01-22 16:23:59.000000000 -0500
2f233df
@@ -0,0 +1,460 @@
831e63b
+#include <unistd.h>
831e63b
+#include <stdlib.h>
831e63b
+#include <ctype.h>
831e63b
+#include <errno.h>
831e63b
+#include <getopt.h>
831e63b
+#include <limits.h>
831e63b
+#include <sepol/sepol.h>
831e63b
+#include <sepol/policydb/services.h>
831e63b
+#include <Python.h>
831e63b
+#include <selinux/selinux.h>
831e63b
+
831e63b
+#define UNKNOWN -1
831e63b
+#define BADSCON -2
831e63b
+#define BADTCON -3
831e63b
+#define BADTCLASS -4
831e63b
+#define BADPERM -5
831e63b
+#define BADCOMPUTE -6
831e63b
+#define NOPOLICY -7
831e63b
+#define ALLOW 0
831e63b
+#define DONTAUDIT 1
831e63b
+#define TERULE 2
831e63b
+#define BOOLEAN 3
831e63b
+#define CONSTRAINT 4
831e63b
+#define RBAC 5
831e63b
+
831e63b
+struct boolean_t {
831e63b
+	char *name;
831e63b
+	int active;
831e63b
+};
831e63b
+
831e63b
+static struct boolean_t **boollist = NULL;
831e63b
+static int boolcnt = 0;
831e63b
+
831e63b
+struct avc_t {
831e63b
+	sepol_handle_t *handle;
831e63b
+	policydb_t policydb;
831e63b
+	sepol_security_id_t ssid;
831e63b
+	sepol_security_id_t tsid;
831e63b
+	sepol_security_class_t tclass;
831e63b
+	sepol_access_vector_t av;
831e63b
+};
831e63b
+
831e63b
+static struct avc_t *avc = NULL;
831e63b
+
831e63b
+static sidtab_t sidtab;
831e63b
+
831e63b
+static int load_booleans(const sepol_bool_t * boolean,
831e63b
+			 void *arg __attribute__ ((__unused__)))
831e63b
+{
831e63b
+	boollist[boolcnt] =
831e63b
+	    (struct boolean_t *)malloc(sizeof(struct boolean_t));
831e63b
+	boollist[boolcnt]->name = strdup(sepol_bool_get_name(boolean));
831e63b
+	boollist[boolcnt]->active = sepol_bool_get_value(boolean);
831e63b
+	boolcnt++;
831e63b
+	return 0;
831e63b
+}
831e63b
+
831e63b
+static int check_booleans(struct avc_t *avc, struct boolean_t ***bools)
831e63b
+{
831e63b
+	char errormsg[PATH_MAX];
831e63b
+	struct sepol_av_decision avd;
831e63b
+	unsigned int reason;
831e63b
+	int rc;
831e63b
+	int i;
831e63b
+	sepol_bool_key_t *key = NULL;
831e63b
+	sepol_bool_t *boolean = NULL;
831e63b
+	int fcnt = 0;
831e63b
+	int *foundlist = calloc(boolcnt, sizeof(int));
831e63b
+	if (!foundlist) {
831e63b
+		PyErr_SetString( PyExc_MemoryError, "Out of memory\n");
831e63b
+		return fcnt;
831e63b
+	}
831e63b
+	for (i = 0; i < boolcnt; i++) {
831e63b
+		char *name = boollist[i]->name;
831e63b
+		int active = boollist[i]->active;
831e63b
+		rc = sepol_bool_key_create(avc->handle, name, &key);
831e63b
+		if (rc < 0) {
831e63b
+			PyErr_SetString( PyExc_RuntimeError, 
831e63b
+					 "Could not create boolean key.\n");
831e63b
+			break;
831e63b
+		}
831e63b
+		rc = sepol_bool_query(avc->handle,
831e63b
+				      (sepol_policydb_t *) & avc->policydb,
831e63b
+				      key, &boolean);
831e63b
+
831e63b
+		if (rc < 0) {
831e63b
+			snprintf(errormsg, sizeof(errormsg), 
831e63b
+				 "Could not find boolean %s.\n", name);
831e63b
+			PyErr_SetString( PyExc_RuntimeError, errormsg);
831e63b
+			break;
831e63b
+		}
831e63b
+
831e63b
+		sepol_bool_set_value(boolean, !active);
831e63b
+
831e63b
+		rc = sepol_bool_set(avc->handle,
831e63b
+				    (sepol_policydb_t *) & avc->policydb,
831e63b
+				    key, boolean);
831e63b
+		if (rc < 0) {
831e63b
+			snprintf(errormsg, sizeof(errormsg), 
831e63b
+				 "Could not set boolean data %s.\n", name);
831e63b
+			PyErr_SetString( PyExc_RuntimeError, errormsg);
831e63b
+			break;
831e63b
+		}
831e63b
+
831e63b
+		/* Reproduce the computation. */
831e63b
+		rc = sepol_compute_av_reason(avc->ssid, avc->tsid, avc->tclass,
831e63b
+					     avc->av, &avd, &reason);
831e63b
+		if (rc < 0) {
831e63b
+			snprintf(errormsg, sizeof(errormsg), 
831e63b
+				 "Error during access vector computation, skipping...");
831e63b
+			PyErr_SetString( PyExc_RuntimeError, errormsg);
831e63b
+
831e63b
+			sepol_bool_free(boolean);
831e63b
+			break;
831e63b
+		} else {
831e63b
+			if (!reason) {
831e63b
+				foundlist[fcnt] = i;
831e63b
+				fcnt++;
831e63b
+			}
831e63b
+			sepol_bool_set_value((sepol_bool_t *) boolean, active);
831e63b
+			rc = sepol_bool_set(avc->handle,
831e63b
+					    (sepol_policydb_t *) & avc->
831e63b
+					    policydb, key,
831e63b
+					    (sepol_bool_t *) boolean);
831e63b
+			if (rc < 0) {
831e63b
+				snprintf(errormsg, sizeof(errormsg), 
831e63b
+					 "Could not set boolean data %s.\n",
831e63b
+					 name);
831e63b
+			
831e63b
+				PyErr_SetString( PyExc_RuntimeError, errormsg);
831e63b
+				break;
831e63b
+			}
831e63b
+		}
831e63b
+		sepol_bool_free(boolean);
831e63b
+		sepol_bool_key_free(key);
831e63b
+		key = NULL;
831e63b
+		boolean = NULL;
831e63b
+	}
831e63b
+	if (key)
831e63b
+		sepol_bool_key_free(key);
831e63b
+
831e63b
+	if (boolean)
831e63b
+		sepol_bool_free(boolean);
831e63b
+
831e63b
+	if (fcnt > 0) {
831e63b
+		*bools = (struct boolean_t **)
831e63b
+			calloc(sizeof(struct boolean_t), fcnt + 1);
831e63b
+		struct boolean_t *b = (struct boolean_t *) *bools;
831e63b
+		for (i = 0; i < fcnt; i++) {
831e63b
+			int ctr = foundlist[i];
831e63b
+			b[i].name = strdup(boollist[ctr]->name);
831e63b
+			b[i].active = !boollist[ctr]->active;
831e63b
+		}
831e63b
+	}
831e63b
+	free(foundlist);
831e63b
+	return fcnt;
831e63b
+}
831e63b
+
831e63b
+static PyObject *finish(PyObject *self __attribute__((unused)), PyObject *args) {
831e63b
+	PyObject *result = 0;
831e63b
+  
831e63b
+	if (PyArg_ParseTuple(args,(char *)":finish")) {
831e63b
+		int i = 0;
831e63b
+		for (i = 0; i < boolcnt; i++) {
831e63b
+			free(boollist[i]->name);
831e63b
+			free(boollist[i]);
831e63b
+		}
831e63b
+		free(boollist);
831e63b
+		sepol_sidtab_shutdown(&sidtab);
831e63b
+		sepol_sidtab_destroy(&sidtab);
831e63b
+		policydb_destroy(&avc->policydb);
831e63b
+		sepol_handle_destroy(avc->handle);
831e63b
+		free(avc);
831e63b
+		avc = NULL;
831e63b
+		boollist = NULL;
831e63b
+		boolcnt = 0;
831e63b
+	  
831e63b
+		/* Boilerplate to return "None" */
831e63b
+		Py_RETURN_NONE;
831e63b
+	}
831e63b
+	return result;
831e63b
+}
831e63b
+
831e63b
+
831e63b
+static int __policy_init(const char *init_path)
831e63b
+{
831e63b
+	FILE *fp;
831e63b
+	int vers = 0;
831e63b
+	char path[PATH_MAX];
831e63b
+	char errormsg[PATH_MAX];
831e63b
+	struct policy_file pf;
831e63b
+	int rc;
831e63b
+	unsigned int cnt;
831e63b
+
831e63b
+	if (init_path) {
831e63b
+		strncpy(path, init_path, PATH_MAX);
831e63b
+		fp = fopen(path, "r");
831e63b
+		if (!fp) {
831e63b
+			snprintf(errormsg, sizeof(errormsg), 
831e63b
+				 "unable to open %s:  %s\n",
831e63b
+				 path, strerror(errno));
831e63b
+			PyErr_SetString( PyExc_ValueError, errormsg);
831e63b
+			return 0;    // trigger exception
831e63b
+		}
831e63b
+	} else {
831e63b
+		vers = security_policyvers();
831e63b
+		if (vers < 0) {
831e63b
+			snprintf(errormsg, sizeof(errormsg), 
831e63b
+				 "Could not get policy version:  %s\n",
831e63b
+				 strerror(errno));
831e63b
+			PyErr_SetString( PyExc_ValueError, errormsg);
831e63b
+			return 1;
831e63b
+		}
831e63b
+		snprintf(path, PATH_MAX, "%s.%d",
831e63b
+			 selinux_binary_policy_path(), vers);
831e63b
+		fp = fopen(path, "r");
831e63b
+		while (!fp && errno == ENOENT && --vers) {
831e63b
+			snprintf(path, PATH_MAX, "%s.%d",
831e63b
+				 selinux_binary_policy_path(), vers);
831e63b
+			fp = fopen(path, "r");
831e63b
+		}
831e63b
+		if (!fp) {
831e63b
+			snprintf(errormsg, sizeof(errormsg), 
831e63b
+				 "unable to open %s.%d:  %s\n",
831e63b
+				 selinux_binary_policy_path(),
831e63b
+				 security_policyvers(), strerror(errno));
831e63b
+			PyErr_SetString( PyExc_ValueError, errormsg);
831e63b
+			return 1;
831e63b
+		}
831e63b
+	}
831e63b
+
831e63b
+	avc = calloc(sizeof(struct avc_t), 1);
831e63b
+	if (!avc) {
831e63b
+		PyErr_SetString( PyExc_MemoryError, "Out of memory\n");
831e63b
+		return 1;
831e63b
+	}
831e63b
+
831e63b
+	/* Set up a policydb directly so that we can mutate it later
831e63b
+	   for booleans and user settings.  Otherwise we would just use
831e63b
+	   sepol_set_policydb_from_file() here. */
831e63b
+	pf.fp = fp;
831e63b
+	pf.type = PF_USE_STDIO;
831e63b
+	if (policydb_init(&avc->policydb)) {
831e63b
+		snprintf(errormsg, sizeof(errormsg), 
831e63b
+			 "policydb_init failed: %s\n", strerror(errno));
831e63b
+		PyErr_SetString( PyExc_RuntimeError, errormsg);
831e63b
+		fclose(fp);
831e63b
+		return 1;
831e63b
+	}
831e63b
+	if (policydb_read(&avc->policydb, &pf, 0)) {
831e63b
+		snprintf(errormsg, sizeof(errormsg), 
831e63b
+			 "invalid binary policy %s\n", path);
831e63b
+		PyErr_SetString( PyExc_ValueError, errormsg);
831e63b
+		fclose(fp);
831e63b
+		return 1;
831e63b
+	}
831e63b
+	fclose(fp);
831e63b
+	sepol_set_policydb(&avc->policydb);
831e63b
+	if (!init_path) {
831e63b
+		/* If they didn't specify a full path of a binary policy file,
831e63b
+		   then also try loading any boolean settings and user
831e63b
+		   definitions from the active locations.  Otherwise,
831e63b
+		   they can use genpolbools and genpolusers to build a
831e63b
+		   binary policy file that includes any desired settings
831e63b
+		   and then apply audit2why -p to the resulting file. 
831e63b
+		   Errors are non-fatal as such settings are optional. */
831e63b
+		sepol_debug(0);
831e63b
+		(void)sepol_genbools_policydb(&avc->policydb,
831e63b
+					      selinux_booleans_path());
831e63b
+		(void)sepol_genusers_policydb(&avc->policydb,
831e63b
+					      selinux_users_path());
831e63b
+	}
831e63b
+	avc->handle = sepol_handle_create();
831e63b
+
831e63b
+	rc = sepol_bool_count(avc->handle,
831e63b
+			      (sepol_policydb_t *) & avc->policydb, &cnt);
831e63b
+	if (rc < 0) {
831e63b
+		PyErr_SetString( PyExc_RuntimeError, "unable to get bool count\n");
831e63b
+		return 1;
831e63b
+	}
831e63b
+
831e63b
+	boollist = calloc(cnt, sizeof(struct boolean_t));
831e63b
+	if (!boollist) {
831e63b
+		PyErr_SetString( PyExc_MemoryError, "Out of memory\n");
831e63b
+		return 1;
831e63b
+	}
831e63b
+
831e63b
+	sepol_bool_iterate(avc->handle,
831e63b
+			   (const sepol_policydb_t *)&avc->policydb,
831e63b
+			   load_booleans, (void *)NULL);
831e63b
+
831e63b
+	/* Initialize the sidtab for subsequent use by sepol_context_to_sid
831e63b
+	   and sepol_compute_av_reason. */
831e63b
+	rc = sepol_sidtab_init(&sidtab);
831e63b
+	if (rc < 0) {
831e63b
+		PyErr_SetString( PyExc_RuntimeError, "unable to init sidtab\n");
831e63b
+		free(boollist);
831e63b
+		return 1;
831e63b
+	}
831e63b
+	sepol_set_sidtab(&sidtab);
831e63b
+	return 0;
831e63b
+}
831e63b
+
831e63b
+static PyObject *init(PyObject *self __attribute__((unused)), PyObject *args) {
831e63b
+  int result;
831e63b
+  char *init_path=NULL;
831e63b
+  if (PyArg_ParseTuple(args,(char *)"|s:policy_init",&init_path)) 
831e63b
+	  result = __policy_init(init_path);
831e63b
+  return Py_BuildValue("i", result);
831e63b
+}
831e63b
+
831e63b
+#define RETURN(X) \
2f233df
+	PyTuple_SetItem(result, 0, Py_BuildValue("i", X));	\
831e63b
+	return result;						
831e63b
+
831e63b
+static PyObject *analyze(PyObject *self __attribute__((unused)) , PyObject *args) {
831e63b
+	security_context_t scon; 
831e63b
+	security_context_t tcon;
831e63b
+	char *tclassstr; 
831e63b
+	PyObject *listObj;
831e63b
+	PyObject *strObj;
831e63b
+	int numlines;
831e63b
+	struct boolean_t **bools;
831e63b
+	unsigned int reason;
831e63b
+	sepol_security_id_t ssid, tsid;
831e63b
+	sepol_security_class_t tclass;
831e63b
+	sepol_access_vector_t perm, av;
831e63b
+	struct sepol_av_decision avd;
831e63b
+	int rc;
831e63b
+	int i=0;
2f233df
+	PyObject *result = PyTuple_New(2);
831e63b
+	if (!result) return NULL;
831e63b
+	Py_INCREF(Py_None);
2f233df
+	PyTuple_SetItem(result, 1, Py_None);
831e63b
+
831e63b
+	if (!PyArg_ParseTuple(args,(char *)"sssO!:audit2why",&scon,&tcon,&tclassstr,&PyList_Type, &listObj)) 
831e63b
+		return NULL;
831e63b
+  
831e63b
+	/* get the number of lines passed to us */
831e63b
+	numlines = PyList_Size(listObj);
831e63b
+
831e63b
+	/* should raise an error here. */
831e63b
+	if (numlines < 0)	return NULL; /* Not a list */
831e63b
+
831e63b
+	if (!avc) {
831e63b
+		RETURN(NOPOLICY)
831e63b
+	}
831e63b
+
831e63b
+	rc = sepol_context_to_sid(scon, strlen(scon) + 1, &ssid);
831e63b
+	if (rc < 0) {
831e63b
+		RETURN(BADSCON)
831e63b
+	}
831e63b
+	rc = sepol_context_to_sid(tcon, strlen(tcon) + 1, &tsid);
831e63b
+	if (rc < 0) {
831e63b
+		RETURN(BADTCON)
831e63b
+	}
831e63b
+	tclass = string_to_security_class(tclassstr);
831e63b
+	if (!tclass) {
831e63b
+		RETURN(BADTCLASS)
831e63b
+	}
831e63b
+	/* Convert the permission list to an AV. */
831e63b
+	av = 0;
831e63b
+
831e63b
+	/* iterate over items of the list, grabbing strings, and parsing
831e63b
+	   for numbers */
831e63b
+	for (i=0; i
831e63b
+		char *permstr;
831e63b
+
831e63b
+		/* grab the string object from the next element of the list */
831e63b
+		strObj = PyList_GetItem(listObj, i); /* Can't fail */
831e63b
+		
831e63b
+		/* make it a string */
831e63b
+		permstr = PyString_AsString( strObj );
831e63b
+		
831e63b
+		perm = string_to_av_perm(tclass, permstr);
831e63b
+		if (!perm) {
831e63b
+			RETURN(BADPERM)
831e63b
+		}
831e63b
+		av |= perm;
831e63b
+	}
831e63b
+
831e63b
+	/* Reproduce the computation. */
831e63b
+	rc = sepol_compute_av_reason(ssid, tsid, tclass, av, &avd, &reason);
831e63b
+	if (rc < 0) {
831e63b
+		RETURN(BADCOMPUTE)
831e63b
+	}
831e63b
+
831e63b
+	if (!reason) {
831e63b
+		RETURN(ALLOW)
831e63b
+	}
831e63b
+	if (reason & SEPOL_COMPUTEAV_TE) {
831e63b
+		avc->ssid = ssid;
831e63b
+		avc->tsid = tsid;
831e63b
+		avc->tclass = tclass;
831e63b
+		avc->av = av;
831e63b
+		if (check_booleans(avc, &bools) == 0) {
831e63b
+			if (av & ~avd.auditdeny) {
831e63b
+				RETURN(DONTAUDIT)
831e63b
+			} else {
831e63b
+				RETURN(TERULE)
831e63b
+			}
831e63b
+		} else {
2f233df
+			PyTuple_SetItem(result, 0, Py_BuildValue("i", BOOLEAN));
831e63b
+			struct boolean_t *b=(struct boolean_t *) bools;
831e63b
+			int len=0;
831e63b
+			while (b->name) {
831e63b
+				len++; b++;
831e63b
+			}
831e63b
+			b = (struct boolean_t *) bools;
2f233df
+			PyObject *boollist = PyTuple_New(len);
831e63b
+			len=0;
831e63b
+			while(b->name) {
2f233df
+				PyObject *bool = Py_BuildValue("(si)", b->name, b->active);
2f233df
+				PyTuple_SetItem(boollist, len++, bool);
831e63b
+				b++;
831e63b
+			}
831e63b
+			free(bools);
2f233df
+			PyTuple_SetItem(result, 1, boollist);
831e63b
+			return result;
831e63b
+		}
831e63b
+	}
831e63b
+
831e63b
+	if (reason & SEPOL_COMPUTEAV_CONS) {
831e63b
+		RETURN(CONSTRAINT);
831e63b
+	}
831e63b
+
831e63b
+	if (reason & SEPOL_COMPUTEAV_RBAC) {
831e63b
+		RETURN(RBAC)
831e63b
+	}
831e63b
+        RETURN(BADCOMPUTE)
831e63b
+}
831e63b
+
831e63b
+static PyMethodDef audit2whyMethods[] = {
831e63b
+    {"init",  init, METH_VARARGS,
831e63b
+     "Initialize policy database."},
831e63b
+    {"analyze",  analyze, METH_VARARGS,
831e63b
+     "Analyze AVC."},
831e63b
+    {"finish",  finish, METH_VARARGS,
831e63b
+     "Finish using policy, free memory."},
831e63b
+    {NULL, NULL, 0, NULL}        /* Sentinel */
831e63b
+};
831e63b
+
831e63b
+PyMODINIT_FUNC
831e63b
+initaudit2why(void)
831e63b
+{
831e63b
+	PyObject *m = Py_InitModule("audit2why", audit2whyMethods);
831e63b
+	PyModule_AddIntConstant(m,"UNKNOWN", UNKNOWN);
831e63b
+	PyModule_AddIntConstant(m,"BADSCON", BADSCON);
831e63b
+	PyModule_AddIntConstant(m,"BADTCON", BADTCON);
831e63b
+	PyModule_AddIntConstant(m,"BADTCLASS", BADTCLASS);
831e63b
+	PyModule_AddIntConstant(m,"BADPERM", BADPERM);
831e63b
+	PyModule_AddIntConstant(m,"BADCOMPUTE", BADCOMPUTE);
831e63b
+	PyModule_AddIntConstant(m,"NOPOLICY", NOPOLICY);
831e63b
+	PyModule_AddIntConstant(m,"ALLOW", ALLOW);
831e63b
+	PyModule_AddIntConstant(m,"DONTAUDIT", DONTAUDIT);
831e63b
+	PyModule_AddIntConstant(m,"TERULE", TERULE);
831e63b
+	PyModule_AddIntConstant(m,"BOOLEAN", BOOLEAN);
831e63b
+	PyModule_AddIntConstant(m,"CONSTRAINT", CONSTRAINT);
831e63b
+	PyModule_AddIntConstant(m,"RBAC", RBAC);
831e63b
+}
4546044
diff --exclude-from=exclude -N -u -r nsalibselinux/src/Makefile libselinux-2.0.47/src/Makefile
4546044
--- nsalibselinux/src/Makefile	2008-01-11 10:52:37.000000000 -0500
c633d69
+++ libselinux-2.0.47/src/Makefile	2008-01-23 14:19:11.000000000 -0500
831e63b
@@ -18,6 +18,7 @@
831e63b
 SWIGSO=_selinux.so
831e63b
 SWIGFILES=$(SWIGSO) selinux.py 
831e63b
 LIBSO=$(TARGET).$(LIBVERSION)
831e63b
+AUDIT2WHYSO=audit2why.so
831e63b
 
831e63b
 ifeq ($(DISABLE_AVC),y)
831e63b
 	UNUSED_SRCS+=avc.c avc_internal.c avc_sidtab.c mapping.c stringrep.c checkAccess.c
831e63b
@@ -28,7 +29,7 @@
831e63b
 ifeq ($(DISABLE_RPM),y)
831e63b
 	UNUSED_SRCS+=rpm.c
831e63b
 endif
831e63b
-SRCS= $(filter-out $(UNUSED_SRCS), $(filter-out $(SWIGCOUT),$(wildcard *.c)))
831e63b
+SRCS= $(filter-out $(UNUSED_SRCS), $(filter-out audit2why.c $(SWIGCOUT),$(wildcard *.c)))
831e63b
 
831e63b
 OBJS= $(patsubst %.c,%.o,$(SRCS))
831e63b
 LOBJS= $(patsubst %.c,%.lo,$(SRCS))
831e63b
@@ -47,7 +48,7 @@
831e63b
 
831e63b
 all: $(LIBA) $(LIBSO) 
831e63b
 
831e63b
-pywrap: all $(SWIGSO)
831e63b
+pywrap: all $(SWIGSO) $(AUDIT2WHYSO)
831e63b
 
831e63b
 $(LIBA):  $(OBJS)
831e63b
 	$(AR) rcs $@ $^
831e63b
@@ -63,6 +64,12 @@
831e63b
 	$(CC) $(CFLAGS) $(LDFLAGS) -shared -o $@ $^ -ldl -L$(LIBDIR) -Wl,-soname,$(LIBSO),-z,defs,-z,relro
831e63b
 	ln -sf $@ $(TARGET) 
831e63b
 
831e63b
+audit2why.lo: audit2why.c
831e63b
+	$(CC) $(CFLAGS) -I$(PYINC) -fPIC -DSHARED -c -o $@ $<
831e63b
+
831e63b
+$(AUDIT2WHYSO): audit2why.lo
831e63b
+	$(CC) $(CFLAGS) $(LDFLAGS) -shared -o $@ $^ -L. -lselinux ${LIBDIR}/libsepol.a -L$(LIBDIR) -Wl,-soname,$@
831e63b
+
831e63b
 %.o:  %.c policy.h
831e63b
 	$(CC) $(CFLAGS) $(TLSFLAGS) -c -o $@ $<
831e63b
 
4546044
@@ -83,14 +90,16 @@
e1e36a0
 	cd $(LIBDIR) && ln -sf ../../`basename $(SHLIBDIR)`/$(LIBSO) $(TARGET)
e1e36a0
 
e1e36a0
 install-pywrap: pywrap
831e63b
-	test -d $(PYTHONLIBDIR)/site-packages || install -m 755 -d $(PYTHONLIBDIR)/site-packages
e1e36a0
-	install -m 755 $(SWIGFILES) $(PYTHONLIBDIR)/site-packages
c633d69
+	test -d $(PYTHONLIBDIR)/site-packages/selinux || install -m 755 -d $(PYTHONLIBDIR)/site-packages/selinux
831e63b
+	install -m 755 $(SWIGSO) $(PYTHONLIBDIR)/site-packages/selinux
831e63b
+	install -m 755 $(AUDIT2WHYSO) $(PYTHONLIBDIR)/site-packages/selinux
88cc8f8
+	install -m 644  selinux.py $(PYTHONLIBDIR)/site-packages/selinux/__init__.py
e1e36a0
 
e1e36a0
 relabel:
e1e36a0
 	/sbin/restorecon $(SHLIBDIR)/$(LIBSO)
831e63b
 
831e63b
 clean: 
831e63b
-	-rm -f $(OBJS) $(LOBJS) $(LIBA) $(LIBSO) $(SWIGLOBJ) $(SWIGSO) $(TARGET) 
831e63b
+	-rm -f $(OBJS) $(LOBJS) $(LIBA) $(LIBSO) $(SWIGLOBJ) $(SWIGSO) $(TARGET) $(AUDIT2WHYSO) *.o *.lo *~
831e63b
 
831e63b
 distclean: clean
831e63b
 	rm -f $(SWIGCOUT) $(SWIGFILES)
4546044
diff --exclude-from=exclude -N -u -r nsalibselinux/src/matchpathcon.c libselinux-2.0.47/src/matchpathcon.c
39606ee
--- nsalibselinux/src/matchpathcon.c	2007-09-28 09:48:58.000000000 -0400
4546044
+++ libselinux-2.0.47/src/matchpathcon.c	2008-01-11 10:55:14.000000000 -0500
71cd138
@@ -2,6 +2,7 @@
71cd138
 #include <string.h>
71cd138
 #include <errno.h>
71cd138
 #include <stdio.h>
71cd138
+#include <syslog.h>
71cd138
 #include "selinux_internal.h"
71cd138
 #include "label_internal.h"
71cd138
 #include "callbacks.h"
0fa749d
@@ -57,7 +58,7 @@
71cd138
 {
71cd138
 	va_list ap;
71cd138
 	va_start(ap, fmt);
71cd138
-	vfprintf(stderr, fmt, ap);
0fa749d
+	vsyslog(LOG_ERR, fmt, ap);
71cd138
 	va_end(ap);
71cd138
 }
71cd138
 
4546044
diff --exclude-from=exclude -N -u -r nsalibselinux/src/selinuxswig.i libselinux-2.0.47/src/selinuxswig.i
c633d69
--- nsalibselinux/src/selinuxswig.i	2008-01-23 14:36:29.000000000 -0500
4546044
+++ libselinux-2.0.47/src/selinuxswig.i	2008-01-11 10:55:14.000000000 -0500
c633d69
@@ -14,6 +14,7 @@
8054023
 
8054023
 %typedef unsigned mode_t;
c633d69
 %typedef unsigned pid_t;
c633d69
+%typedef char * security_context_t;
8054023
 
8054023
 %typemap(in, numinputs=0) (char ***names, int *len) (char **temp1, int temp2) {
8054023
 	$1 = &temp1;