2
0
mirror of https://gitlab.com/apparmor/apparmor synced 2025-08-31 06:16:03 +00:00

- Modified configure to require --with-perl/python/ruby/etc

to enable the compilation of those SWIG wrappers.
- Put together a perl usage example
This commit is contained in:
Matt Barringer
2007-07-11 01:08:06 +00:00
parent c6d5ebc7b6
commit 1fa3516397
8 changed files with 254 additions and 4488 deletions

View File

@@ -8,15 +8,43 @@ AC_PROG_YACC
AC_PATH_PROG([SWIG], [swig])
AC_PATH_PROG([PYTHON], [python])
AM_CONDITIONAL(HAVE_PYTHON, test "x${PYTHON}" != "x")
AM_PATH_PYTHON
AC_MSG_CHECKING(Checking for Python)
AC_ARG_WITH(python,
[ --with-python enable the python wrapper [[default=no]]],
[AC_MSG_RESULT($withval)], [AC_MSG_RESULT(no)])
if test "$with_python" = "yes"; then
sinclude(m4/ac_python_devel.m4)
AC_PYTHON_DEVEL
AM_PATH_PYTHON
fi
AC_PATH_PROG([PERL], [perl])
AM_CONDITIONAL(HAVE_PERL, test "x${PERL}" != "x")
AC_MSG_CHECKING(Checking for perl)
AC_ARG_WITH(perl,
[ --with-perl enable the perl wrapper [[default=no]]],
[AC_MSG_RESULT($withval)], [AC_MSG_RESULT(no)])
if test "$with_perl" = "yes"; then
AC_PATH_PROG(PERL, perl, no)
if test x$PERL = xno; then
enable_perl=no
else
perl_includedir="`$PERL -e 'use Config; print $Config{archlib}'`/CORE"
AC_CHECK_FILE($perl_includedir/perl.h, enable_perl=yes, enable_perl=no)
fi
fi
AC_PATH_PROG([RUBY], [ruby])
AM_CONDITIONAL(HAVE_RUBY, test "x${RUBY}" != "x")
AC_MSG_CHECKING(Checking for ruby)
AC_ARG_WITH(ruby,
[ --with-ruby enable the ruby wrapper [[default=no]]],
[AC_MSG_RESULT($withval)], [AC_MSG_RESULT(no)])
if test "$with_ruby" = "yes"; then
AC_PATH_PROG([RUBY], [ruby])
fi
AM_CONDITIONAL(HAVE_PYTHON, test x$with_python = xyes)
AM_CONDITIONAL(HAVE_PERL, test x$with_perl = xyes)
AM_CONDITIONAL(HAVE_RUBY, test x$with_ruby = xyes)
AC_HEADER_STDC
AC_CHECK_HEADERS(unistd.h stdint.h)

View File

@@ -0,0 +1,193 @@
AC_DEFUN([AC_PYTHON_DEVEL],[
#
# Allow the use of a (user set) custom python version
#
AC_ARG_VAR([PYTHON_VERSION],[The installed Python
version to use, for example '2.3'. This string
will be appended to the Python interpreter
canonical name.])
AC_PATH_PROG([PYTHON],[python[$PYTHON_VERSION]])
if test -z "$PYTHON"; then
AC_MSG_ERROR([Cannot find python$PYTHON_VERSION in your system path])
PYTHON_VERSION=""
fi
#
# Check for a version of Python >= 2.1.0
#
AC_MSG_CHECKING([for a version of Python >= '2.1.0'])
ac_supports_python_ver=`$PYTHON -c "import sys, string; \
ver = string.split(sys.version)[[0]]; \
print ver >= '2.1.0'"`
if test "$ac_supports_python_ver" != "True"; then
if test -z "$PYTHON_NOVERSIONCHECK"; then
AC_MSG_RESULT([no])
AC_MSG_FAILURE([
This version of the AC@&t@_PYTHON_DEVEL macro
doesn't work properly with versions of Python before
2.1.0. You may need to re-run configure, setting the
variables PYTHON_CPPFLAGS, PYTHON_LDFLAGS, PYTHON_SITE_PKG,
PYTHON_EXTRA_LIBS and PYTHON_EXTRA_LDFLAGS by hand.
Moreover, to disable this check, set PYTHON_NOVERSIONCHECK
to something else than an empty string.
])
else
AC_MSG_RESULT([skip at user request])
fi
else
AC_MSG_RESULT([yes])
fi
#
# if the macro parameter ``version'' is set, honour it
#
if test -n "$1"; then
AC_MSG_CHECKING([for a version of Python $1])
ac_supports_python_ver=`$PYTHON -c "import sys, string; \
ver = string.split(sys.version)[[0]]; \
print ver $1"`
if test "$ac_supports_python_ver" = "True"; then
AC_MSG_RESULT([yes])
else
AC_MSG_RESULT([no])
AC_MSG_ERROR([this package requires Python $1.
If you have it installed, but it isn't the default Python
interpreter in your system path, please pass the PYTHON_VERSION
variable to configure. See ``configure --help'' for reference.
])
PYTHON_VERSION=""
fi
fi
#
# Check if you have distutils, else fail
#
AC_MSG_CHECKING([for the distutils Python package])
ac_distutils_result=`$PYTHON -c "import distutils" 2>&1`
if test -z "$ac_distutils_result"; then
AC_MSG_RESULT([yes])
else
AC_MSG_RESULT([no])
AC_MSG_ERROR([cannot import Python module "distutils".
Please check your Python installation. The error was:
$ac_distutils_result])
PYTHON_VERSION=""
fi
#
# Check for Python include path
#
AC_MSG_CHECKING([for Python include path])
if test -z "$PYTHON_CPPFLAGS"; then
python_path=`$PYTHON -c "import distutils.sysconfig; \
print distutils.sysconfig.get_python_inc();"`
if test -n "${python_path}"; then
python_path="-I$python_path"
fi
PYTHON_CPPFLAGS=$python_path
fi
AC_MSG_RESULT([$PYTHON_CPPFLAGS])
AC_SUBST([PYTHON_CPPFLAGS])
#
# Check for Python library path
#
AC_MSG_CHECKING([for Python library path])
if test -z "$PYTHON_LDFLAGS"; then
# (makes two attempts to ensure we've got a version number
# from the interpreter)
py_version=`$PYTHON -c "from distutils.sysconfig import *; \
from string import join; \
print join(get_config_vars('VERSION'))"`
if test "$py_version" == "[None]"; then
if test -n "$PYTHON_VERSION"; then
py_version=$PYTHON_VERSION
else
py_version=`$PYTHON -c "import sys; \
print sys.version[[:3]]"`
fi
fi
PYTHON_LDFLAGS=`$PYTHON -c "from distutils.sysconfig import *; \
from string import join; \
print '-L' + get_python_lib(0,1), \
'-lpython';"`$py_version
fi
AC_MSG_RESULT([$PYTHON_LDFLAGS])
AC_SUBST([PYTHON_LDFLAGS])
#
# Check for site packages
#
AC_MSG_CHECKING([for Python site-packages path])
if test -z "$PYTHON_SITE_PKG"; then
PYTHON_SITE_PKG=`$PYTHON -c "import distutils.sysconfig; \
print distutils.sysconfig.get_python_lib(0,0);"`
fi
AC_MSG_RESULT([$PYTHON_SITE_PKG])
AC_SUBST([PYTHON_SITE_PKG])
#
# libraries which must be linked in when embedding
#
AC_MSG_CHECKING(python extra libraries)
if test -z "$PYTHON_EXTRA_LIBS"; then
PYTHON_EXTRA_LIBS=`$PYTHON -c "import distutils.sysconfig; \
conf = distutils.sysconfig.get_config_var; \
print conf('LOCALMODLIBS'), conf('LIBS')"`
fi
AC_MSG_RESULT([$PYTHON_EXTRA_LIBS])
AC_SUBST(PYTHON_EXTRA_LIBS)
#
# linking flags needed when embedding
#
AC_MSG_CHECKING(python extra linking flags)
if test -z "$PYTHON_EXTRA_LDFLAGS"; then
PYTHON_EXTRA_LDFLAGS=`$PYTHON -c "import distutils.sysconfig; \
conf = distutils.sysconfig.get_config_var; \
print conf('LINKFORSHARED')"`
fi
AC_MSG_RESULT([$PYTHON_EXTRA_LDFLAGS])
AC_SUBST(PYTHON_EXTRA_LDFLAGS)
#
# final check to see if everything compiles alright
#
AC_MSG_CHECKING([consistency of all components of python development environment])
AC_LANG_PUSH([C])
# save current global flags
LIBS="$ac_save_LIBS $PYTHON_LDFLAGS"
CPPFLAGS="$ac_save_CPPFLAGS $PYTHON_CPPFLAGS"
AC_TRY_LINK([
#include <Python.h>
],[
Py_Initialize();
],[pythonexists=yes],[pythonexists=no])
AC_MSG_RESULT([$pythonexists])
if test ! "$pythonexists" = "yes"; then
AC_MSG_ERROR([
Could not link test program to Python. Maybe the main Python library has been
installed in some non-standard library path. If so, pass it to configure,
via the LDFLAGS environment variable.
Example: ./configure LDFLAGS="-L/usr/non-standard-path/python/lib"
============================================================================
ERROR!
You probably have to install the development version of the Python package
for your distribution. The exact name of this package varies among them.
============================================================================
])
PYTHON_VERSION=""
fi
AC_LANG_POP
# turn back to default flags
CPPFLAGS="$ac_save_CPPFLAGS"
LIBS="$ac_save_LIBS"
#
# all done!
#
])

View File

@@ -1,9 +1,9 @@
if HAVE_PERL
PERL_MAKEFILE = Makefile.perl
WRAPPER_SOURCES = libaalogparse_wrap.c AppArmorLogRecordParser.pm
if HAVE_PERL
all-local: .build-stamp
.build-stamp: $(WRAPPER_SOURCES) $(PERL_MAKEFILE)
@@ -24,10 +24,11 @@ clean-local: $(PERL_MAKEFILE)
$(PERL_MAKEFILE): Makefile.PL
$(PERL) Makefile.PL VERSION="0.1" OBJECT="../../src/.libs/libaalogparse.so libaalogparse_wrap.o" CCFLAGS="-I../../src -D_REENTRANT -D_GNU_SOURCE -DTHREADS_HAVE_PIDS -fno-strict-aliasing -pipe -Wdeclaration-after-statement" OPTIMIZE="$(CFLAGS) -shared -I$(includedir) -D_REENTRANT -D_GNU_SOURCE -DTHREADS_HAVE_PIDS -fno-strict-aliasing -pipe -Wdeclaration-after-statement"
endif
$(WRAPPER_SOURCES): ../SWIG/*.i
$(SWIG) -perl -I../../src -I../SWIG -o libaalogparse_wrap.c libaalogparse.i
endif
EXTRA_DIST = Makefile.PL $(WRAPPER_SOURCES) examples/*.pl

View File

@@ -0,0 +1,15 @@
require AppArmorLogRecordParser;
$msg = "type=APPARMOR msg=audit(1168662182.495:58): PERMITTING r access to /home/matt/projects/change_hat_test/test (test_hat(27871) profile /home/matt/projects/change_hat_test/test_hat active null-complain-profile)";
my($test) = AppArmorLogRecordParser::parse_record($msg);
if (AppArmorLogRecordParser::aa_log_record::swig_event_get($test) == $AppArmorLogRecordParser::AA_RECORD_ALLOWED )
{
print "AA_RECORD_ALLOWED\n";
}
print "Audit ID: " . AppArmorLogRecordParser::aa_log_record::swig_audit_id_get($test) . "\n";
print "PID: " . AppArmorLogRecordParser::aa_log_record::swig_pid_get($test) . "\n";
AppArmorLogRecordParser::free_record($test);

View File

@@ -1,126 +0,0 @@
# This file was created automatically by SWIG 1.3.29.
# Don't modify this file, modify the SWIG interface instead.
# This file is compatible with both classic and new-style classes.
import _AppArmorLogRecordParser
import new
new_instancemethod = new.instancemethod
def _swig_setattr_nondynamic(self,class_type,name,value,static=1):
if (name == "thisown"): return self.this.own(value)
if (name == "this"):
if type(value).__name__ == 'PySwigObject':
self.__dict__[name] = value
return
method = class_type.__swig_setmethods__.get(name,None)
if method: return method(self,value)
if (not static) or hasattr(self,name):
self.__dict__[name] = value
else:
raise AttributeError("You cannot add attributes to %s" % self)
def _swig_setattr(self,class_type,name,value):
return _swig_setattr_nondynamic(self,class_type,name,value,0)
def _swig_getattr(self,class_type,name):
if (name == "thisown"): return self.this.own()
method = class_type.__swig_getmethods__.get(name,None)
if method: return method(self)
raise AttributeError,name
def _swig_repr(self):
try: strthis = "proxy of " + self.this.__repr__()
except: strthis = ""
return "<%s.%s; %s >" % (self.__class__.__module__, self.__class__.__name__, strthis,)
import types
try:
_object = types.ObjectType
_newclass = 1
except AttributeError:
class _object : pass
_newclass = 0
del types
AA_RECORD_EXEC_MMAP = _AppArmorLogRecordParser.AA_RECORD_EXEC_MMAP
AA_RECORD_READ = _AppArmorLogRecordParser.AA_RECORD_READ
AA_RECORD_WRITE = _AppArmorLogRecordParser.AA_RECORD_WRITE
AA_RECORD_EXEC = _AppArmorLogRecordParser.AA_RECORD_EXEC
AA_RECORD_LINK = _AppArmorLogRecordParser.AA_RECORD_LINK
AA_RECORD_SYNTAX_V1 = _AppArmorLogRecordParser.AA_RECORD_SYNTAX_V1
AA_RECORD_SYNTAX_V2 = _AppArmorLogRecordParser.AA_RECORD_SYNTAX_V2
AA_RECORD_SYNTAX_UNKNOWN = _AppArmorLogRecordParser.AA_RECORD_SYNTAX_UNKNOWN
AA_RECORD_INVALID = _AppArmorLogRecordParser.AA_RECORD_INVALID
AA_RECORD_ERROR = _AppArmorLogRecordParser.AA_RECORD_ERROR
AA_RECORD_AUDIT = _AppArmorLogRecordParser.AA_RECORD_AUDIT
AA_RECORD_ALLOWED = _AppArmorLogRecordParser.AA_RECORD_ALLOWED
AA_RECORD_DENIED = _AppArmorLogRecordParser.AA_RECORD_DENIED
AA_RECORD_HINT = _AppArmorLogRecordParser.AA_RECORD_HINT
AA_RECORD_STATUS = _AppArmorLogRecordParser.AA_RECORD_STATUS
class aa_log_record(_object):
__swig_setmethods__ = {}
__setattr__ = lambda self, name, value: _swig_setattr(self, aa_log_record, name, value)
__swig_getmethods__ = {}
__getattr__ = lambda self, name: _swig_getattr(self, aa_log_record, name)
__repr__ = _swig_repr
__swig_setmethods__["version"] = _AppArmorLogRecordParser.aa_log_record_version_set
__swig_getmethods__["version"] = _AppArmorLogRecordParser.aa_log_record_version_get
if _newclass:version = property(_AppArmorLogRecordParser.aa_log_record_version_get, _AppArmorLogRecordParser.aa_log_record_version_set)
__swig_setmethods__["event"] = _AppArmorLogRecordParser.aa_log_record_event_set
__swig_getmethods__["event"] = _AppArmorLogRecordParser.aa_log_record_event_get
if _newclass:event = property(_AppArmorLogRecordParser.aa_log_record_event_get, _AppArmorLogRecordParser.aa_log_record_event_set)
__swig_setmethods__["pid"] = _AppArmorLogRecordParser.aa_log_record_pid_set
__swig_getmethods__["pid"] = _AppArmorLogRecordParser.aa_log_record_pid_get
if _newclass:pid = property(_AppArmorLogRecordParser.aa_log_record_pid_get, _AppArmorLogRecordParser.aa_log_record_pid_set)
__swig_setmethods__["task"] = _AppArmorLogRecordParser.aa_log_record_task_set
__swig_getmethods__["task"] = _AppArmorLogRecordParser.aa_log_record_task_get
if _newclass:task = property(_AppArmorLogRecordParser.aa_log_record_task_get, _AppArmorLogRecordParser.aa_log_record_task_set)
__swig_setmethods__["bitmask"] = _AppArmorLogRecordParser.aa_log_record_bitmask_set
__swig_getmethods__["bitmask"] = _AppArmorLogRecordParser.aa_log_record_bitmask_get
if _newclass:bitmask = property(_AppArmorLogRecordParser.aa_log_record_bitmask_get, _AppArmorLogRecordParser.aa_log_record_bitmask_set)
__swig_setmethods__["operation"] = _AppArmorLogRecordParser.aa_log_record_operation_set
__swig_getmethods__["operation"] = _AppArmorLogRecordParser.aa_log_record_operation_get
if _newclass:operation = property(_AppArmorLogRecordParser.aa_log_record_operation_get, _AppArmorLogRecordParser.aa_log_record_operation_set)
__swig_setmethods__["denied_mask"] = _AppArmorLogRecordParser.aa_log_record_denied_mask_set
__swig_getmethods__["denied_mask"] = _AppArmorLogRecordParser.aa_log_record_denied_mask_get
if _newclass:denied_mask = property(_AppArmorLogRecordParser.aa_log_record_denied_mask_get, _AppArmorLogRecordParser.aa_log_record_denied_mask_set)
__swig_setmethods__["requested_mask"] = _AppArmorLogRecordParser.aa_log_record_requested_mask_set
__swig_getmethods__["requested_mask"] = _AppArmorLogRecordParser.aa_log_record_requested_mask_get
if _newclass:requested_mask = property(_AppArmorLogRecordParser.aa_log_record_requested_mask_get, _AppArmorLogRecordParser.aa_log_record_requested_mask_set)
__swig_setmethods__["profile"] = _AppArmorLogRecordParser.aa_log_record_profile_set
__swig_getmethods__["profile"] = _AppArmorLogRecordParser.aa_log_record_profile_get
if _newclass:profile = property(_AppArmorLogRecordParser.aa_log_record_profile_get, _AppArmorLogRecordParser.aa_log_record_profile_set)
__swig_setmethods__["name"] = _AppArmorLogRecordParser.aa_log_record_name_set
__swig_getmethods__["name"] = _AppArmorLogRecordParser.aa_log_record_name_get
if _newclass:name = property(_AppArmorLogRecordParser.aa_log_record_name_get, _AppArmorLogRecordParser.aa_log_record_name_set)
__swig_setmethods__["name2"] = _AppArmorLogRecordParser.aa_log_record_name2_set
__swig_getmethods__["name2"] = _AppArmorLogRecordParser.aa_log_record_name2_get
if _newclass:name2 = property(_AppArmorLogRecordParser.aa_log_record_name2_get, _AppArmorLogRecordParser.aa_log_record_name2_set)
__swig_setmethods__["attribute"] = _AppArmorLogRecordParser.aa_log_record_attribute_set
__swig_getmethods__["attribute"] = _AppArmorLogRecordParser.aa_log_record_attribute_get
if _newclass:attribute = property(_AppArmorLogRecordParser.aa_log_record_attribute_get, _AppArmorLogRecordParser.aa_log_record_attribute_set)
__swig_setmethods__["parent"] = _AppArmorLogRecordParser.aa_log_record_parent_set
__swig_getmethods__["parent"] = _AppArmorLogRecordParser.aa_log_record_parent_get
if _newclass:parent = property(_AppArmorLogRecordParser.aa_log_record_parent_get, _AppArmorLogRecordParser.aa_log_record_parent_set)
__swig_setmethods__["magic_token"] = _AppArmorLogRecordParser.aa_log_record_magic_token_set
__swig_getmethods__["magic_token"] = _AppArmorLogRecordParser.aa_log_record_magic_token_get
if _newclass:magic_token = property(_AppArmorLogRecordParser.aa_log_record_magic_token_get, _AppArmorLogRecordParser.aa_log_record_magic_token_set)
__swig_setmethods__["info"] = _AppArmorLogRecordParser.aa_log_record_info_set
__swig_getmethods__["info"] = _AppArmorLogRecordParser.aa_log_record_info_get
if _newclass:info = property(_AppArmorLogRecordParser.aa_log_record_info_get, _AppArmorLogRecordParser.aa_log_record_info_set)
__swig_setmethods__["active_hat"] = _AppArmorLogRecordParser.aa_log_record_active_hat_set
__swig_getmethods__["active_hat"] = _AppArmorLogRecordParser.aa_log_record_active_hat_get
if _newclass:active_hat = property(_AppArmorLogRecordParser.aa_log_record_active_hat_get, _AppArmorLogRecordParser.aa_log_record_active_hat_set)
def __init__(self, *args):
this = _AppArmorLogRecordParser.new_aa_log_record(*args)
try: self.this.append(this)
except: self.this = this
__swig_destroy__ = _AppArmorLogRecordParser.delete_aa_log_record
__del__ = lambda self : None;
aa_log_record_swigregister = _AppArmorLogRecordParser.aa_log_record_swigregister
aa_log_record_swigregister(aa_log_record)
parse_record = _AppArmorLogRecordParser.parse_record
free_record = _AppArmorLogRecordParser.free_record

View File

@@ -1,9 +1,9 @@
if HAVE_PYTHON
BUILT_SOURCES = aalogrecordparse_wrap.c
SWIG_SOURCES = ../SWIG/libaalogparse.i
if HAVE_PYTHON
pkgpython_PYTHON = AppArmorLogRecordParser.py
pkgpyexec_LTLIBRARIES = _aalogrecordparse.la
_aalogrecordparse_la_SOURCES = aalogrecordparse_wrap.c $(SWIG_SOURCES)
@@ -11,8 +11,7 @@ _aalogrecordparse_la_CPPFLAGS = $(SWIG_PYTHON_CFLAGS) -I$(top_srcdir)/src -I/usr
_aalogrecordparse_la_LDFLAGS = -module
_aalogrecordparse_la_LIBADD = ../../src/.libs/libaalogparse.so
endif
aalogrecordparse_wrap.c: $(SWIG_SOURCES)
$(SWIG) -python -I$(top_srcdir)/src -o $@ $<
endif

File diff suppressed because it is too large Load Diff

View File

@@ -1,11 +1,11 @@
if HAVE_RUBY
RUBY_MAKEFILE = Makefile.ruby
WRAPPER_FILES = AppArmorLogRecordParser_wrap.* AppArmorLogRecordParser.so extension.mak .build-stamp
BUILT_SOURCES = AppArmorLogRecordParser_wrap.c
if HAVE_RUBY
all-local: .build-stamp
.build-stamp: AppArmorLogRecordParser_wrap.c
@@ -15,10 +15,10 @@ all-local: .build-stamp
install-exec-local: .build-stamp
make -f $(RUBY_MAKEFILE) install
endif
AppArmorLogRecordParser_wrap.c: ../SWIG/*.i
$(SWIG) -ruby -I../SWIG -I../../src -o ./AppArmorLogRecordParser_wrap.c libaalogparse.i
endif
EXTRA_DIST = extconf.rb $(BUILT_SOURCES) examples/*.rb