apparmor/libraries/libapparmor
Arkadiusz Miśkiewicz 757cc25163 libapparmor: raise exception in python bindings when something fails
Current libapparmor python bindings are very "unpythonic". Also lack
ability to access "why" information in case of failure.

In python when something fail the normal behaviour is exception
to occur. In case of apparmor functions die silently and require
user to verify returned value.

And here comes second problem. In C api when return value is -1
(and the same value is returned in python API) we can access errno
to get information why this occured. Unfortunately in python there
is no way to access the same information.  Pythonic way of accessing
errno is via exception (which is never raised in python bindings
currently).

So the patch adds exceptions on failures. First %exception creates
a wrapper that swig adds to each function listed below. Empty %exception
causes that the rest of code (beside listed functions) won't be wrapped.

How this works? Example on apparmor disabled system:

Before:
>>> LibAppArmor.aa_change_hat(hat, random.randint(1, sys.maxint))
-1

After:
>>> LibAppArmor.aa_change_hat(hat, random.randint(1, sys.maxint))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
OSError: [Errno 22] Invalid argument

so pythonic way of accessing "why":
>>> try:
...     LibAppArmor.aa_change_hat(hat, random.randint(1, sys.maxint))
... except OSError, e:
...     print e.errno
...
22

Signed-off-by: Arkadiusz Miśkiewicz <arekm@maven.pl>
Acked-by: Steve Beattie <steve@nxnw.org>
2014-03-07 11:54:12 -08:00
..
doc fix broken URLs in various utils/*.pod files. 2013-09-19 21:17:39 +02:00
include libapparmor: move public headers to separate directory 2014-01-06 14:08:55 -08:00
m4 Subject: libapparmor - use python-config if it exists when configuring 2013-01-29 15:21:47 -08:00
src libapparmor: fix missing symbol adjustment from previous commit. 2014-03-01 16:19:11 -08:00
swig libapparmor: raise exception in python bindings when something fails 2014-03-07 11:54:12 -08:00
testsuite libapparmor: move public headers to separate directory 2014-01-06 14:08:55 -08:00
AUTHORS libraries/libapparmor/: more license cleanups, adjust my email address 2011-02-23 14:02:45 -08:00
autogen.sh libapparmor: require libtoolize instead of libtool 2014-01-03 15:13:26 -08:00
ChangeLog move libapparmor into the libraries directory 2008-05-19 22:48:31 +00:00
configure.ac libapparmor: move public headers to separate directory 2014-01-06 14:08:55 -08:00
COPYING.LGPL move libapparmor into the libraries directory 2008-05-19 22:48:31 +00:00
INSTALL move libapparmor into the libraries directory 2008-05-19 22:48:31 +00:00
libapparmor1.spec Bump versioning to AppArmor 2.5 2010-03-10 23:07:29 -08:00
Makefile.am libapparmor: move public headers to separate directory 2014-01-06 14:08:55 -08:00
NEWS move libapparmor into the libraries directory 2008-05-19 22:48:31 +00:00
README update the bugtracker link in the libapparmor README 2014-02-24 22:44:32 +01:00

What little documentation exists is in src/aalogparse.h.

Please file bugs using https://bugs.launchpad.net/apparmor/+filebug