All of lore.kernel.org
 help / color / mirror / Atom feed
From: Daniel J Walsh <dwalsh@redhat.com>
To: SE Linux <selinux@tycho.nsa.gov>
Subject: This patch fixes the exception handling in libselinux-python bindings
Date: Mon, 18 May 2009 14:10:18 -0400	[thread overview]
Message-ID: <4A11A48A.1020307@redhat.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 114 bytes --]

Basically we need to search for all interfaces that return an int and 
set those up as python exception handlers.

[-- Attachment #2: libselinux_python_exception.patch --]
[-- Type: text/plain, Size: 3514 bytes --]

--- nsalibselinux/src/selinuxswig.i	2009-03-12 08:48:48.000000000 -0400
+++ libselinux-2.0.81/src/selinuxswig.i	2009-05-18 14:04:07.000000000 -0400
@@ -4,11 +4,14 @@
 
 %module selinux
 %{
-	#include "selinux/selinux.h"
 	#include "../include/selinux/avc.h"
-	#include "../include/selinux/selinux.h"
-	#include "../include/selinux/get_default_type.h"
+	#include "../include/selinux/av_permissions.h"
+	#include "../include/selinux/context.h"
+	#include "../include/selinux/flask.h"
 	#include "../include/selinux/get_context_list.h"
+	#include "../include/selinux/get_default_type.h"
+	#include "../include/selinux/label.h"
+	#include "../include/selinux/selinux.h"
 %}
 %apply int *OUTPUT { int *enforce };
 %apply int *OUTPUT { size_t * };
@@ -55,8 +58,11 @@
 %ignore avc_netlink_release_fd;
 %ignore avc_netlink_check_nb;
 
-%include "../include/selinux/selinux.h"
 %include "../include/selinux/avc.h"
-%include "../include/selinux/get_default_type.h"
+%include "../include/selinux/av_permissions.h"
+%include "../include/selinux/context.h"
+%include "../include/selinux/flask.h"
 %include "../include/selinux/get_context_list.h"
-
+%include "../include/selinux/get_default_type.h"
+%include "../include/selinux/label.h"
+%include "../include/selinux/selinux.h"
--- nsalibselinux/src/Makefile	2009-03-06 14:41:45.000000000 -0500
+++ libselinux-2.0.81/src/Makefile	2009-05-18 14:04:07.000000000 -0400
@@ -82,6 +82,9 @@
 	$(CC) $(CFLAGS) $(LDFLAGS) -shared -o $@ $^ -ldl -L$(LIBDIR) -Wl,-soname,$(LIBSO),-z,defs,-z,relro
 	ln -sf $@ $(TARGET) 
 
+selinuxswig_exception.i: ../include/selinux/selinux.h
+	sh exception.sh > $@ 
+
 audit2why.lo: audit2why.c
 	$(CC) $(CFLAGS) -I$(PYINC) -fPIC -DSHARED -c -o $@ $<
 
@@ -100,8 +103,8 @@
 $(SWIGRUBYCOUT): $(SWIGRUBYIF)
 	$(SWIGRUBY) $^
 
-swigify: $(SWIGIF)
-	$(SWIG) $^
+swigify: $(SWIGIF) selinuxswig_exception.i
+	$(SWIG) $<
 
 install: all 
 	test -d $(LIBDIR) || install -m 755 -d $(LIBDIR)
@@ -124,7 +127,7 @@
 	/sbin/restorecon $(SHLIBDIR)/$(LIBSO)
 
 clean: 
-	-rm -f $(OBJS) $(LOBJS) $(LIBA) $(LIBSO) $(SWIGLOBJ) $(SWIGSO) $(TARGET) $(AUDIT2WHYSO) *.o *.lo *~
+	-rm -f $(OBJS) $(LOBJS) $(LIBA) $(LIBSO) $(SWIGLOBJ) $(SWIGSO) $(TARGET) $(AUDIT2WHYSO) *.o *.lo *~ selinuxswig_exception.i
 
 distclean: clean
 	rm -f $(GENERATED) $(SWIGFILES)
--- nsalibselinux/src/exception.sh	1969-12-31 19:00:00.000000000 -0500
+++ libselinux-2.0.81/src/exception.sh	2009-05-18 14:04:07.000000000 -0400
@@ -0,0 +1,12 @@
+function except() {
+echo "
+%exception $1 {
+  \$action 
+  if (result < 0) {
+     PyErr_SetFromErrno(PyExc_OSError);
+     return NULL;
+  }
+}
+"
+}
+for i in `grep "extern *int" ../include/selinux/selinux.h | awk '{ print $3 }' | cut -d '(' -f 1`; do except $i ; done 
--- nsalibselinux/src/selinuxswig_python.i	2009-03-06 14:41:45.000000000 -0500
+++ libselinux-2.0.81/src/selinuxswig_python.i	2009-05-18 14:04:07.000000000 -0400
@@ -21,6 +21,15 @@
                              map(restorecon, [os.path.join(dirname, fname)
                                               for fname in fnames]), None)
 
+def copytree(src, dest):
+    """ An SELinux-friendly shutil.copytree method """
+    shutil.copytree(src, dest)
+    restorecon(dest, recursive=True)
+
+def install(src, dest):
+    """ An SELinux-friendly shutil.move method """
+    shutil.move(src, dest)
+    restorecon(dest, recursive=True)
 %}
 
 /* security_get_boolean_names() typemap */
@@ -150,4 +159,5 @@
 	free($1);
 }
 
+%include "selinuxswig_exception.i"
 %include "selinuxswig.i"

             reply	other threads:[~2009-05-18 18:10 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-05-18 18:10 Daniel J Walsh [this message]
2009-05-19 16:16 ` This patch fixes the exception handling in libselinux-python bindings Chad Sellers
2009-05-19 17:35   ` Daniel J Walsh
2009-06-18 14:23     ` Joshua Brindle
2009-06-18 19:41       ` Daniel J Walsh
     [not found] <C6A74D22.A99BD%csellers@tresys.com>
2009-08-12 18:34 ` Daniel J Walsh
2009-09-16 19:18   ` Joshua Brindle
2009-09-16 19:35     ` Joshua Brindle
     [not found]       ` <4AB15164.1020507@redhat.com>
2009-09-24  0:56         ` Joshua Brindle
2009-09-24 18:16           ` Joshua Brindle
2009-09-24 19:19             ` Joshua Brindle
2009-09-28 19:07               ` Daniel J Walsh
2009-09-28 20:10                 ` Joshua Brindle
2010-01-08 15:32                 ` Stephen Smalley
2010-01-08 20:06                   ` Stephen Smalley
2010-01-08 20:19                     ` Stephen Smalley
2010-01-08 20:40                       ` Daniel J Walsh
2010-01-08 20:52                         ` Joshua Brindle
2010-02-08 21:10                           ` Caleb Case
2010-03-06 23:23                             ` Joshua Brindle

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4A11A48A.1020307@redhat.com \
    --to=dwalsh@redhat.com \
    --cc=selinux@tycho.nsa.gov \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.