This patch fixes the exception handling in libselinux-python bindings
Basically we need to search for all interfaces that return an int and set those up as python exception handlers.
src/selinuxswig.i +12 -6
@@ -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"
src/Makefile +6 -3
@@ -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)
src/exception.sh +12 -0
@@ -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
src/selinuxswig_python.i +10 -0
@@ -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"
Quoted 2 lines · Daniel J Walsh
Basically we need to search for all interfaces that return an int and set those up as python exception handlers.
I presume this supercedes the patch submitted on March 4 titled "Patch to python bindings" which used a single generic exception handler. Is that correct? Why the switch from a generic exception handler to a shell script to generate lots of specific exception handlers?
Thanks,
Chad
--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
Quoted 10 lines · Chad Sellers
Quoted 2 lines · Daniel J Walsh
Basically we need to search for all interfaces that return an int and set those up as python exception handlers.
I presume this supercedes the patch submitted on March 4 titled "Patch to python bindings" which used a single generic exception handler. Is that correct? Why the switch from a generic exception handler to a shell script to generate lots of specific exception handlers?
Quoted 8 lines
Thanks,
Chad--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
Yes, that patch caused certain interfaces to not work if they did not return int.
--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
Quoted 16 lines · Daniel J Walsh
Quoted 15 lines · Chad Sellers
Quoted 2 lines · Daniel J Walsh
Basically we need to search for all interfaces that return an int and set those up as python exception handlers.
I presume this supercedes the patch submitted on March 4 titled "Patch to python bindings" which used a single generic exception handler. Is that correct? Why the switch from a generic exception handler to a shell script
to generate lots of specific exception handlers?Thanks,
Chad
Quoted 8 lines
Quoted 5 lines
--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with
the words "unsubscribe selinux" without quotes as the message.Yes, that patch caused certain interfaces to not work if they did not return int.
This doesn't strike me as the best way to handle it. Assuming all functions that return an int returns it as a return code is a little overzealous. For example selinux_file_context_cmp() returns 1, 0, -1 for comparison. It is only not included in the exception.sh output by accident it appears (it is defined as int selinux_file_context_cmp(...) rather than extern int.
Which brings up the next point, there are a handful of functions in selinux.h that don't have extern which means exception handlers aren't made for them.
--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
Quoted 27 lines · Joshua Brindle
Quoted 17 lines · Daniel J Walsh
Quoted 16 lines · Chad Sellers
Quoted 2 lines · Daniel J Walsh
Basically we need to search for all interfaces that return an int and set those up as python exception handlers.
I presume this supercedes the patch submitted on March 4 titled "Patch to
python bindings" which used a single generic exception handler. Is that correct? Why the switch from a generic exception handler to a shell script
to generate lots of specific exception handlers?Thanks,
ChadQuoted 8 lines
Quoted 5 lines
--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with
the words "unsubscribe selinux" without quotes as the message.Yes, that patch caused certain interfaces to not work if they did not return int.
Quoted 7 lines
This doesn't strike me as the best way to handle it. Assuming all functions that return an int returns it as a return code is a little overzealous. For example
selinux_file_context_cmp()returns 1, 0, -1 for comparison. It is only not included in theexception.shoutput by accident it appears (it is defined as intselinux_file_context_cmp(...)rather than extern int.
I am willing to accept better ideas. Admittedly this is a hack, but I have not seen a bug since implementing. I guess we should tell python when we have exceptions to the rule, like selinux_file_context_cmp
Quoted 9 lines
Which brings up the next point, there are a handful of functions in
selinux.hthat don't have extern which means exception handlers aren't made for them.--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with
the words "unsubscribe selinux" without quotes as the message.
--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.