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