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