56b2aa
diff -up libselinux-2.0.14/src/fsetfilecon.c.swig libselinux-2.0.14/src/fsetfilecon.c
56b2aa
--- libselinux-2.0.14/src/fsetfilecon.c.swig	2007-09-25 17:34:07.000000000 -0400
56b2aa
+++ libselinux-2.0.14/src/fsetfilecon.c	2007-09-25 17:35:17.000000000 -0400
56b2aa
@@ -13,7 +13,7 @@ int fsetfilecon_raw(int fd, security_con
56b2aa
 			 0);
56b2aa
 }
56b2aa
 
56b2aa
-hidden_def(setfilecon_raw)
56b2aa
+hidden_def(fsetfilecon_raw)
56b2aa
 
56b2aa
 int fsetfilecon(int fd, security_context_t context)
56b2aa
 {
56b2aa
diff -up libselinux-2.0.14/src/selinuxswig.i.swig libselinux-2.0.14/src/selinuxswig.i
56b2aa
--- libselinux-2.0.14/src/selinuxswig.i.swig	2007-09-13 09:17:31.000000000 -0400
56b2aa
+++ libselinux-2.0.14/src/selinuxswig.i	2007-09-13 09:17:31.000000000 -0400
4fd227
@@ -1,7 +1,9 @@
4fd227
-/* Author: Dan Walsh
4fd227
+/* Authors: Dan Walsh
4fd227
+ *          James Athey
4fd227
  *
4fd227
  * Copyright (C) 2004-2005 Red Hat
4fd227
- * 
4fd227
+ * Copyright (C) 2007 Tresys Technology, LLC
4fd227
+ *
4fd227
  *  This library is free software; you can redistribute it and/or
4fd227
  *  modify it under the terms of the GNU Lesser General Public
4fd227
  *  License as published by the Free Software Foundation; either
4fd227
@@ -17,207 +19,47 @@
4fd227
  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
4fd227
  */
4fd227
 
4fd227
-
4fd227
 %module selinux
4fd227
 %{
4fd227
 	#include "selinux/selinux.h"
4fd227
-	#include "selinux/get_context_list.h"
4fd227
 %}
4fd227
-%apply int *OUTPUT { int * };
4fd227
+%apply int *OUTPUT { int *enforce };
4fd227
 %apply int *OUTPUT { size_t * };
4fd227
 
4fd227
-%typemap(in, numinputs=0) security_context_t *(security_context_t temp=NULL) {
4fd227
-	$1 = &tem;;
4fd227
-}
4fd227
-%typemap(argout) security_context_t * (char *temp=NULL) {
4fd227
-	if (*$1)
4fd227
-		temp = *$1;
4fd227
-	else
4fd227
-		temp = "";
4fd227
-	$result = SWIG_Python_AppendOutput($result, PyString_FromString(temp));
4fd227
-}
4fd227
-
4fd227
-%typemap(in) security_context_t {
4fd227
-	$1 = (security_context_t)PyString_AsString($input);
4fd227
-}
4fd227
-
4fd227
 %typedef unsigned mode_t;
4fd227
 
4fd227
-%include "../include/selinux/get_context_list.h"
4fd227
-
4fd227
-extern int is_selinux_enabled(void);
4fd227
-extern int is_selinux_mls_enabled(void);
4fd227
-extern void freecon(security_context_t con);
4fd227
-extern void freeconary(security_context_t * con);
4fd227
-extern int getcon(security_context_t *con);
4fd227
-extern int setcon(security_context_t con);
4fd227
-extern int getpidcon(int pid, security_context_t *con);
4fd227
-extern int getprevcon(security_context_t *con);
4fd227
-extern int getexeccon(security_context_t *con);
4fd227
-extern int setexeccon(security_context_t con);
4fd227
-extern int getfscreatecon(security_context_t *con);
4fd227
-extern int setfscreatecon(security_context_t context);
4fd227
-extern int getkeycreatecon(security_context_t *con);
4fd227
-extern int setkeycreatecon(security_context_t context);
4fd227
-extern int getsockcreatecon(security_context_t *con);
4fd227
-extern int setsockcreatecon(security_context_t context);
4fd227
-extern int getfilecon(const char *path, security_context_t *con);
4fd227
-extern int lgetfilecon(const char *path, security_context_t *con);
4fd227
-extern int fgetfilecon(int fd, security_context_t *con);
4fd227
-extern int setfilecon(const char *path, security_context_t con);
4fd227
-extern int lsetfilecon(const char *path, security_context_t con);
4fd227
-extern int fsetfilecon(int fd, security_context_t con);
4fd227
-extern int getpeercon(int fd, security_context_t *con);
4fd227
-extern int selinux_mkload_policy(int preservebools);
4fd227
-extern int selinux_init_load_policy(int *enforce);
4fd227
-extern int security_set_boolean_list(size_t boolcnt, 
4fd227
-				     SELboolean *boollist, 
4fd227
-				     int permanent);
4fd227
-extern int security_load_booleans(char *path);
4fd227
-extern int security_check_context(security_context_t con);
4fd227
-extern int security_canonicalize_context(security_context_t con,
4fd227
-					 security_context_t *canoncon);
4fd227
-extern int security_getenforce(void);
4fd227
-extern int security_setenforce(int value);
4fd227
-extern int security_policyvers(void);
4fd227
-extern int security_get_boolean_names(char ***names, int *len);
4fd227
-extern int security_get_boolean_pending(const char *name);
4fd227
-extern int security_get_boolean_active(const char *name);
4fd227
-extern int security_set_boolean(const char *name, int value);
4fd227
-extern int security_commit_booleans(void);
4fd227
-
4fd227
-/* Set flags controlling operation of matchpathcon_init or matchpathcon. */
4fd227
-#define MATCHPATHCON_BASEONLY 1 /* Only process the base file_contexts file. */
4fd227
-#define MATCHPATHCON_NOTRANS  2 /* Do not perform any context translation. */
4fd227
-extern void set_matchpathcon_flags(unsigned int flags);
4fd227
-extern int matchpathcon_init(const char *path);
4fd227
-extern int matchpathcon(const char *path,
4fd227
-			mode_t mode,
4fd227
-			security_context_t *con);
4fd227
-
4fd227
-extern int matchpathcon_init_prefix(const char *path,
4fd227
-				    const char *prefix);
4fd227
-extern void matchpathcon_fini(void);
4fd227
-
4fd227
-
4fd227
-extern int matchmediacon(const char *media,
4fd227
-		 security_context_t *con);
4fd227
-
4fd227
-extern int selinux_getenforcemode(int *enforce);
4fd227
-extern const char *selinux_policy_root(void);
4fd227
-extern const char *selinux_binary_policy_path(void);
4fd227
-extern const char *selinux_failsafe_context_path(void);
4fd227
-extern const char *selinux_removable_context_path(void);
4fd227
-extern const char *selinux_default_context_path(void);
4fd227
-extern const char *selinux_user_contexts_path(void);
4fd227
-extern const char *selinux_file_context_path(void);
4fd227
-extern const char *selinux_file_context_homedir_path(void);
4fd227
-extern const char *selinux_file_context_local_path(void);
4fd227
-extern const char *selinux_homedir_context_path(void);
4fd227
-extern const char *selinux_media_context_path(void);
4fd227
-extern const char *selinux_contexts_path(void);
4fd227
-extern const char *selinux_securetty_types_path(void);
4fd227
-extern const char *selinux_booleans_path(void);
4fd227
-extern const char *selinux_customizable_types_path(void);
4fd227
-extern const char *selinux_users_path(void);
4fd227
-extern const char *selinux_usersconf_path(void);
4fd227
-extern const char *selinux_translations_path(void);
4fd227
-extern const char *selinux_netfilter_context_path(void);
4fd227
-extern const char *selinux_path(void);
4fd227
-#extern int selinux_check_passwd_access(access_vector_t requested);
4fd227
-#extern int checkPasswdAccess(access_vector_t requested);
4fd227
-
4fd227
-extern int selinux_check_securetty_context(security_context_t tty_context);
4fd227
-void set_selinuxmnt(char *mnt);
4fd227
-
4fd227
-#ifdef SWIGpython
4fd227
-// This tells SWIG to treat char ** as a special case
4fd227
-%typemap(in) char ** {
4fd227
-  /* Check if is a list */
4fd227
-  if (PyList_Check($input)) {
4fd227
-    int size = PyList_Size($input);
4fd227
-    int i = 0;
4fd227
-    $1 = (char **) malloc((size+1)*sizeof(char *));
4fd227
-    if ($1 == NULL) {
4fd227
-	PyErr_SetString(PyExc_MemoryError,"Out of memory");
4fd227
-	return NULL;
4fd227
-    }
4fd227
-    for (i = 0; i < size; i++) {
4fd227
-      PyObject *o = PyList_GetItem($input,i);
4fd227
-      if (PyString_Check(o))
4fd227
-	$1[i] = PyString_AsString(PyList_GetItem($input,i));
4fd227
-      else {
4fd227
-	PyErr_SetString(PyExc_TypeError,"list must contain strings");
4fd227
-	free($1);
4fd227
-	return NULL;
4fd227
-      }
4fd227
-    }
4fd227
-    $1[i] = 0;
4fd227
-  } else {
4fd227
-    PyErr_SetString(PyExc_TypeError,"not a list");
4fd227
-    return NULL;
4fd227
-  }
4fd227
+%typemap(in, numinputs=0) (char ***names, int *len) (char **temp1, int temp2) {
4fd227
+	$1 = &temp1;
4fd227
+	$2 = &temp2;
4fd227
 }
4fd227
-#endif
4fd227
 
4fd227
-%typemap(in) char * const [] {
4fd227
-	int i, size;
4fd227
-	PyObject * s;
4fd227
-
4fd227
-	if (!PySequence_Check($input)) {
4fd227
-		PyErr_SetString(PyExc_ValueError, "Expected a sequence");
4fd227
-		return NULL;
4fd227
-	}
4fd227
-
4fd227
-	size = PySequence_Size($input);
4fd227
-	
4fd227
-	$1 = (char**) malloc(size + 1);
4fd227
-
4fd227
-	for(i = 0; i < size; i++) {
4fd227
-		if (!PyString_Check(PySequence_GetItem($input, i))) {
4fd227
-			PyErr_SetString(PyExc_ValueError, "Sequence must contain only strings");
4fd227
-			return NULL;
4fd227
+%typemap(freearg) (char ***names, int *len) {
4fd227
+	int i;
4fd227
+	if (*$1) {
4fd227
+		for (i = 0; i < *$2; i++) {
4fd227
+			free((*$1)[i]);
4fd227
 		}
4fd227
+		free(*$1);
4fd227
 	}
4fd227
-		
4fd227
-	for(i = 0; i < size; i++) {
4fd227
-		s = PySequence_GetItem($input, i);
4fd227
-		$1[i] = (char*) malloc(PyString_Size(s) + 1);
4fd227
-		strcpy($1[i], PyString_AsString(s));
4fd227
-	}
4fd227
-	$1[size] = NULL;
4fd227
-}
4fd227
-
4fd227
-%typemap(freearg,match="in") char * const [] {
4fd227
-	int i = 0;
4fd227
-	while($1[i]) {
4fd227
-		free($1[i]);
4fd227
-		i++;
4fd227
-	}
4fd227
-	free($1);
4fd227
 }
4fd227
 
4fd227
-extern int rpm_execcon(unsigned int verified,
4fd227
-		       const char *filename,
4fd227
-		       char *const argv[], char *const envp[]);
4fd227
-
4fd227
-extern int is_context_customizable (security_context_t scontext);
4fd227
-
4fd227
-extern int selinux_trans_to_raw_context(char *trans, 
4fd227
-					security_context_t *rawp);
4fd227
-extern int selinux_raw_to_trans_context(char *raw, 
4fd227
-					security_context_t *transp);
4fd227
-
4fd227
-%typemap(in, numinputs=0) char **(char *temp=NULL) {
4fd227
+%typemap(in, numinputs=0) (security_context_t **) (security_context_t *temp) {
4fd227
 	$1 = &tem;;
4fd227
 }
4fd227
 
4fd227
-%typemap(argout) char ** {
4fd227
-	$result = SWIG_Python_AppendOutput($result, PyString_FromString(*$1));
4fd227
+%typemap(freearg) (security_context_t **) {
4fd227
+	if (*$1) freeconary(*$1);
4fd227
 }
4fd227
-extern int selinux_getpolicytype(char **enforce);
4fd227
-extern int getseuserbyname(const char *linuxuser, char **seuser, char **level);
4fd227
 
4fd227
-int selinux_file_context_cmp(const security_context_t a, const security_context_t b);
4fd227
-int selinux_file_context_verify(const char *path, mode_t mode);
4fd227
-int selinux_lsetfilecon_default(const char *path);
4fd227
+/* Ignore functions that don't make sense when wrapped */
4fd227
+%ignore freecon;
4fd227
+%ignore freeconary;
4fd227
+
4fd227
+/* Ignore functions that take a function pointer as an argument */
4fd227
+%ignore set_matchpathcon_printf;
4fd227
+%ignore set_matchpathcon_invalidcon;
4fd227
+%ignore set_matchpathcon_canoncon;
4fd227
+
4fd227
+%include "../include/selinux/selinux.h"
4fd227
+%include "../include/selinux/get_default_type.h"
4fd227
+%include "../include/selinux/get_context_list.h"
56b2aa
diff -up /dev/null libselinux-2.0.14/src/selinuxswig_python.i
56b2aa
--- /dev/null	2007-09-21 05:53:11.538007738 -0400
56b2aa
+++ libselinux-2.0.14/src/selinuxswig_python.i	2007-09-13 09:17:31.000000000 -0400
4fd227
@@ -0,0 +1,138 @@
4fd227
+/* Author: James Athey
4fd227
+ *
4fd227
+ * Copyright (C) 2007 Tresys Technology, LLC
4fd227
+ *
4fd227
+ *  This library is free software; you can redistribute it and/or
4fd227
+ *  modify it under the terms of the GNU Lesser General Public
4fd227
+ *  License as published by the Free Software Foundation; either
4fd227
+ *  version 2.1 of the License, or (at your option) any later version.
4fd227
+ *
4fd227
+ *  This library is distributed in the hope that it will be useful,
4fd227
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
4fd227
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
4fd227
+ *  Lesser General Public License for more details.
4fd227
+ *
4fd227
+ *  You should have received a copy of the GNU Lesser General Public
4fd227
+ *  License along with this library; if not, write to the Free Software
4fd227
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
4fd227
+ */
4fd227
+
4fd227
+%module selinux
4fd227
+%{
4fd227
+	#include "selinux/selinux.h"
4fd227
+%}
4fd227
+
4fd227
+/* security_get_boolean_names() typemap */
4fd227
+%typemap(argout) (char ***names, int *len) {
4fd227
+	PyObject* list = PyList_New(*$2);
4fd227
+	int i;
4fd227
+	for (i = 0; i < *$2; i++) {
4fd227
+		PyList_SetItem(list, i, PyString_FromString((*$1)[i]));
4fd227
+	}
4fd227
+	$result = SWIG_Python_AppendOutput($result, list);
4fd227
+}
4fd227
+
4fd227
+/* Makes security_compute_user() return a Python list of contexts */
4fd227
+%typemap(argout) (security_context_t **con) {
4fd227
+	PyObject* plist;
4fd227
+	int i, len = 0;
4fd227
+	
4fd227
+	if (*$1) {
4fd227
+		while((*$1)[len])
4fd227
+			len++;
4fd227
+		plist = PyList_New(len);
4fd227
+		for (i = 0; i < len; i++) {
4fd227
+			PyList_SetItem(plist, i, PyString_FromString((*$1)[i]));
4fd227
+		}
4fd227
+	} else {
4fd227
+		plist = PyList_New(0);
4fd227
+	}
4fd227
+
4fd227
+	$result = SWIG_Python_AppendOutput($result, plist);
4fd227
+}
4fd227
+
4fd227
+/* Makes functions in get_context_list.h return a Python list of contexts */
4fd227
+%typemap(argout) (security_context_t **list) {
4fd227
+	PyObject* plist;
4fd227
+	int i;
4fd227
+	
4fd227
+	if (*$1) {
4fd227
+		plist = PyList_New(result);
4fd227
+		for (i = 0; i < result; i++) {
4fd227
+			PyList_SetItem(plist, i, PyString_FromString((*$1)[i]));
4fd227
+		}
4fd227
+	} else {
4fd227
+		plist = PyList_New(0);
4fd227
+	}
4fd227
+	/* Only return the Python list, don't need to return the length anymore */
4fd227
+	$result = plist;
4fd227
+}
4fd227
+
4fd227
+%typemap(in,noblock=1,numinputs=0) security_context_t * (security_context_t temp = 0) {
4fd227
+	$1 = &tem;;
4fd227
+}
4fd227
+%typemap(freearg,match="in") security_context_t * "";
4fd227
+%typemap(argout,noblock=1) security_context_t * {
4fd227
+	if (*$1) {
4fd227
+		%append_output(SWIG_FromCharPtr(*$1));
4fd227
+		freecon(*$1);
4fd227
+	}
4fd227
+	else {
4fd227
+		Py_INCREF(Py_None);
4fd227
+		%append_output(Py_None);
4fd227
+	}
4fd227
+}
4fd227
+
4fd227
+%typemap(in,noblock=1,numinputs=0) char ** (char * temp = 0) {
4fd227
+	$1 = &tem;;
4fd227
+}
4fd227
+%typemap(freearg,match="in") char ** "";
4fd227
+%typemap(argout,noblock=1) char ** {
4fd227
+	if (*$1) {
4fd227
+		%append_output(SWIG_FromCharPtr(*$1));
4fd227
+		free(*$1);
4fd227
+	}
4fd227
+	else {
4fd227
+		Py_INCREF(Py_None);
4fd227
+		%append_output(Py_None);
4fd227
+	}
4fd227
+}
4fd227
+
4fd227
+%typemap(in) char * const [] {
4fd227
+	int i, size;
4fd227
+	PyObject * s;
4fd227
+
4fd227
+	if (!PySequence_Check($input)) {
4fd227
+		PyErr_SetString(PyExc_ValueError, "Expected a sequence");
4fd227
+		return NULL;
4fd227
+	}
4fd227
+
4fd227
+	size = PySequence_Size($input);
4fd227
+	
4fd227
+	$1 = (char**) malloc(size + 1);
4fd227
+
4fd227
+	for(i = 0; i < size; i++) {
4fd227
+		if (!PyString_Check(PySequence_GetItem($input, i))) {
4fd227
+			PyErr_SetString(PyExc_ValueError, "Sequence must contain only strings");
4fd227
+			return NULL;
4fd227
+		}
4fd227
+	}
4fd227
+		
4fd227
+	for(i = 0; i < size; i++) {
4fd227
+		s = PySequence_GetItem($input, i);
4fd227
+		$1[i] = (char*) malloc(PyString_Size(s) + 1);
4fd227
+		strcpy($1[i], PyString_AsString(s));
4fd227
+	}
4fd227
+	$1[size] = NULL;
4fd227
+}
4fd227
+
4fd227
+%typemap(freearg,match="in") char * const [] {
4fd227
+	int i = 0;
4fd227
+	while($1[i]) {
4fd227
+		free($1[i]);
4fd227
+		i++;
4fd227
+	}
4fd227
+	free($1);
4fd227
+}
4fd227
+
4fd227
+%include "selinuxswig.i"
ad08b4
diff -up libselinux-2.0.14/src/Makefile.swig libselinux-2.0.14/src/Makefile
ad08b4
--- libselinux-2.0.14/src/Makefile.swig	2007-09-27 10:33:38.000000000 -0400
ad08b4
+++ libselinux-2.0.14/src/Makefile	2007-09-27 10:30:26.000000000 -0400
ad08b4
@@ -12,7 +12,7 @@ LIBVERSION = 1
ad08b4
 
ad08b4
 LIBA=libselinux.a 
ad08b4
 TARGET=libselinux.so
ad08b4
-SWIGIF= selinuxswig.i
ad08b4
+SWIGIF= selinuxswig_python.i
ad08b4
 SWIGCOUT= selinuxswig_wrap.c
ad08b4
 SWIGLOBJ:= $(patsubst %.c,%.lo,$(SWIGCOUT)) 
ad08b4
 SWIGSO=_selinux.so
56b2aa
diff -up libselinux-2.0.14/Makefile.swig libselinux-2.0.14/Makefile
56b2aa
--- libselinux-2.0.14/Makefile.swig	2007-09-13 09:17:31.000000000 -0400
56b2aa
+++ libselinux-2.0.14/Makefile	2007-09-13 09:17:31.000000000 -0400
56b2aa
@@ -2,7 +2,7 @@ all: 
4fd227
 	$(MAKE) -C src 
4fd227
 	$(MAKE) -C utils
4fd227
 
4fd227
-swigify: 
4fd227
+swigify: all
4fd227
 	$(MAKE) -C src swigify
4fd227
 
4fd227
 pywrap: