# Check if we're building with SELinux support.
if test "x$have_selinux" = xyes; then
AC_DEFINE(HAVE_SELINUX,1,[SELinux support])
+
+ # See if we have the libaudit library
+ AC_CHECK_LIB(audit, audit_log_avc,
+ have_libaudit=yes, have_libaudit=no)
+ if test "x$have_libaudit" = xyes; then
+ AC_DEFINE(HAVE_LIBAUDIT,1,[SELinux libaudit support])
+ fi
+ AC_SUBST(have_libaudit)
fi
AC_SUBST(have_selinux)
all-nscd-modules := $(nscd-modules) selinux
ifeq (yes,$(have-selinux))
+ifeq (yes,$(have-libaudit))
+libaudit = -laudit
+endif
+
nscd-modules += selinux
-selinux-LIBS := -lselinux
+selinux-LIBS := -lselinux $(libaudit)
endif
LDLIBS-nscd = $(selinux-LIBS)
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
+#include "config.h"
#include <error.h>
#include <errno.h>
#include <libintl.h>
#include <selinux/avc.h>
#include <selinux/flask.h>
#include <selinux/selinux.h>
+#ifdef HAVE_LIBAUDIT
+#include <libaudit.h>
+#endif
#include "dbg_log.h"
#include "selinux.h"
/* Thread to listen for SELinux status changes via netlink. */
static pthread_t avc_notify_thread;
+#ifdef HAVE_LIBAUDIT
+/* Prototype for supporting the audit daemon */
+static void log_callback (const char *fmt, ...);
+#endif
+
/* Prototypes for AVC callback functions. */
static void *avc_create_thread (void (*run) (void));
static void avc_stop_thread (void *thread);
/* AVC callback structures for use in avc_init. */
static const struct avc_log_callback log_cb =
{
+#ifdef HAVE_LIBAUDIT
+ .func_log = log_callback,
+#else
.func_log = dbg_log,
+#endif
.func_audit = NULL
};
static const struct avc_thread_callback thread_cb =
.func_free_lock = avc_free_lock
};
+#ifdef HAVE_LIBAUDIT
+/* The audit system's netlink socket descriptor */
+static int audit_fd = -1;
+
+/* When an avc denial occurs, log it to audit system */
+static void
+log_callback (const char *fmt, ...)
+{
+ va_list ap;
+
+ va_start (ap, fmt);
+ audit_log_avc (audit_fd, AUDIT_USER_AVC, fmt, ap);
+ va_end (ap);
+}
+
+/* Initialize the connection to the audit system */
+static void
+audit_init (void)
+{
+ audit_fd = audit_open ();
+ if (audit_fd < 0)
+ dbg_log (_("Failed opening connection to the audit subsystem"));
+}
+#endif /* HAVE_LIBAUDIT */
/* Determine if we are running on an SELinux kernel. Set selinux_enabled
to the result. */
error (EXIT_FAILURE, errno, _("Failed to start AVC"));
else
dbg_log (_("Access Vector Cache (AVC) started"));
+#ifdef HAVE_LIBAUDIT
+ audit_init ();
+#endif
}
nscd_avc_destroy (void)
{
avc_destroy ();
+#ifdef HAVE_LIBAUDIT
+ audit_close (audit_fd);
+#endif
}
#endif /* HAVE_SELINUX */