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