]> git.ipfire.org Git - thirdparty/strongswan.git/commitdiff
Added a radattr plugin that prints any received RADIUS notify to console
authorMartin Willi <martin@revosec.ch>
Mon, 27 Feb 2012 14:41:53 +0000 (15:41 +0100)
committerMartin Willi <martin@revosec.ch>
Mon, 5 Mar 2012 17:08:04 +0000 (18:08 +0100)
configure.in
src/libcharon/Makefile.am
src/libcharon/plugins/radattr/Makefile.am [new file with mode: 0644]
src/libcharon/plugins/radattr/radattr_listener.c [new file with mode: 0644]
src/libcharon/plugins/radattr/radattr_listener.h [new file with mode: 0644]
src/libcharon/plugins/radattr/radattr_plugin.c [new file with mode: 0644]
src/libcharon/plugins/radattr/radattr_plugin.h [new file with mode: 0644]

index a463c482640d7579630a9b14a0c3d3defc0afdbd..8bd034260e8efeaa3afa24fc0f142d7a49313a9b 100644 (file)
@@ -191,6 +191,7 @@ ARG_ENABL_SET([certexpire],     [enable CSV export of expiration dates of used c
 ARG_ENABL_SET([led],            [enable plugin to control LEDs on IKEv2 activity using the Linux kernel LED subsystem.])
 ARG_ENABL_SET([duplicheck],     [advanced duplicate checking plugin using liveness checks.])
 ARG_ENABL_SET([coupling],       [enable IKEv2 plugin to couple peer certificates permanently to authentication.])
+ARG_ENABL_SET([radattr],        [enable plugin to inject and process custom RADIUS attributes as IKEv2 client.])
 ARG_ENABL_SET([vstr],           [enforce using the Vstr string library to replace glibc-like printf hooks.])
 ARG_ENABL_SET([monolithic],     [build monolithic version of libstrongswan that includes all enabled plugins. Similarly, the plugins of charon are assembled in libcharon.])
 
@@ -887,6 +888,7 @@ ADD_PLUGIN([certexpire],           [c libcharon])
 ADD_PLUGIN([led],                  [c libcharon])
 ADD_PLUGIN([duplicheck],           [c libcharon])
 ADD_PLUGIN([coupling],             [c libcharon])
+ADD_PLUGIN([radattr],              [c libcharon])
 ADD_PLUGIN([maemo],                [c libcharon])
 ADD_PLUGIN([uci],                  [c libcharon])
 ADD_PLUGIN([addrblock],            [c libcharon])
@@ -973,6 +975,7 @@ AM_CONDITIONAL(USE_CERTEXPIRE, test x$certexpire = xtrue)
 AM_CONDITIONAL(USE_LED, test x$led = xtrue)
 AM_CONDITIONAL(USE_DUPLICHECK, test x$duplicheck = xtrue)
 AM_CONDITIONAL(USE_COUPLING, test x$coupling = xtrue)
+AM_CONDITIONAL(USE_RADATTR, test x$radattr = xtrue)
 AM_CONDITIONAL(USE_EAP_SIM, test x$eap_sim = xtrue)
 AM_CONDITIONAL(USE_EAP_SIM_FILE, test x$eap_sim_file = xtrue)
 AM_CONDITIONAL(USE_EAP_SIM_PCSC, test x$eap_sim_pcsc = xtrue)
@@ -1192,6 +1195,7 @@ AC_OUTPUT(
        src/libcharon/plugins/led/Makefile
        src/libcharon/plugins/duplicheck/Makefile
        src/libcharon/plugins/coupling/Makefile
+       src/libcharon/plugins/radattr/Makefile
        src/libcharon/plugins/android/Makefile
        src/libcharon/plugins/maemo/Makefile
        src/libcharon/plugins/stroke/Makefile
index fba51c662c63c70b9eb4c69eebad996ea61aa421..edb7665c56ef26fd4b82985a8f57458bf52adac3 100644 (file)
@@ -473,6 +473,13 @@ if MONOLITHIC
 endif
 endif
 
+if USE_RADATTR
+  SUBDIRS += plugins/radattr
+if MONOLITHIC
+  libcharon_la_LIBADD += plugins/radattr/libstrongswan-radattr.la
+endif
+endif
+
 if USE_UCI
   SUBDIRS += plugins/uci
 if MONOLITHIC
diff --git a/src/libcharon/plugins/radattr/Makefile.am b/src/libcharon/plugins/radattr/Makefile.am
new file mode 100644 (file)
index 0000000..0ea8df5
--- /dev/null
@@ -0,0 +1,17 @@
+
+INCLUDES = -I$(top_srcdir)/src/libstrongswan -I$(top_srcdir)/src/libhydra \
+       -I$(top_srcdir)/src/libcharon -I$(top_srcdir)/src/libradius
+
+AM_CFLAGS = -rdynamic
+
+if MONOLITHIC
+noinst_LTLIBRARIES = libstrongswan-radattr.la
+else
+libstrongswan_radattr_la_LIBADD = $(top_builddir)/src/libradius/libradius.la
+plugin_LTLIBRARIES = libstrongswan-radattr.la
+endif
+
+libstrongswan_radattr_la_SOURCES = radattr_plugin.h radattr_plugin.c \
+       radattr_listener.h radattr_listener.c
+
+libstrongswan_radattr_la_LDFLAGS = -module -avoid-version
diff --git a/src/libcharon/plugins/radattr/radattr_listener.c b/src/libcharon/plugins/radattr/radattr_listener.c
new file mode 100644 (file)
index 0000000..a99bad2
--- /dev/null
@@ -0,0 +1,118 @@
+/*
+ * Copyright (C) 2012 Martin Willi
+ * Copyright (C) 2012 revosec AG
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.  See <http://www.fsf.org/copyleft/gpl.txt>.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * for more details.
+ */
+
+#include "radattr_listener.h"
+
+#include <daemon.h>
+
+#include <radius_message.h>
+
+typedef struct private_radattr_listener_t private_radattr_listener_t;
+
+/**
+ * Private data of an radattr_listener_t object.
+ */
+struct private_radattr_listener_t {
+
+       /**
+        * Public radattr_listener_t interface.
+        */
+       radattr_listener_t public;
+};
+
+/**
+ * Print RADIUS attributes found in IKE message notifies
+ */
+static void print_radius_attributes(private_radattr_listener_t *this,
+                                                                       message_t *message)
+{
+       radius_attribute_type_t type;
+       enumerator_t *enumerator;
+       notify_payload_t *notify;
+       payload_t *payload;
+       chunk_t data;
+
+       enumerator = message->create_payload_enumerator(message);
+       while (enumerator->enumerate(enumerator, &payload))
+       {
+               if (payload->get_type(payload) == NOTIFY)
+               {
+                       notify = (notify_payload_t*)payload;
+                       if (notify->get_notify_type(notify) == RADIUS_ATTRIBUTE)
+                       {
+                               data = notify->get_notification_data(notify);
+                               if (data.len >= 2)
+                               {
+                                       type = data.ptr[0];
+                                       data = chunk_skip(data, 2);
+                                       if (chunk_printable(data, NULL, 0))
+                                       {
+                                               DBG1(DBG_IKE, "received RADIUS %N: %.*s",
+                                                        radius_attribute_type_names, type,
+                                                        (int)data.len, data.ptr);
+                                       }
+                                       else
+                                       {
+                                               DBG1(DBG_IKE, "received RADIUS %N: %#B",
+                                                        radius_attribute_type_names, type, &data);
+
+                                       }
+                               }
+                       }
+               }
+       }
+       enumerator->destroy(enumerator);
+}
+
+METHOD(listener_t, message, bool,
+       private_radattr_listener_t *this,
+       ike_sa_t *ike_sa, message_t *message, bool incoming)
+{
+       if (ike_sa->supports_extension(ike_sa, EXT_STRONGSWAN) &&
+               message->get_exchange_type(message) == IKE_AUTH)
+       {
+               if (incoming)
+               {
+                       print_radius_attributes(this, message);
+               }
+       }
+       return TRUE;
+}
+
+
+METHOD(radattr_listener_t, destroy, void,
+       private_radattr_listener_t *this)
+{
+       free(this);
+}
+
+/**
+ * See header
+ */
+radattr_listener_t *radattr_listener_create()
+{
+       private_radattr_listener_t *this;
+
+       INIT(this,
+               .public = {
+                       .listener = {
+                               .message = _message,
+                       },
+                       .destroy = _destroy,
+               },
+       );
+
+       return &this->public;
+}
diff --git a/src/libcharon/plugins/radattr/radattr_listener.h b/src/libcharon/plugins/radattr/radattr_listener.h
new file mode 100644 (file)
index 0000000..9a14827
--- /dev/null
@@ -0,0 +1,49 @@
+/*
+ * Copyright (C) 2012 Martin Willi
+ * Copyright (C) 2012 revosec AG
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.  See <http://www.fsf.org/copyleft/gpl.txt>.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * for more details.
+ */
+
+/**
+ * @defgroup radattr_listener radattr_listener
+ * @{ @ingroup
+ */
+
+#ifndef RADATTR_LISTENER_H_
+#define RADATTR_LISTENER_H_
+
+#include <bus/listeners/listener.h>
+
+typedef struct radattr_listener_t radattr_listener_t;
+
+/**
+ * Output received RADIUS attributes, inject custom attributes.
+ */
+struct radattr_listener_t {
+
+       /**
+        * Implements a listener.
+        */
+       listener_t listener;
+
+       /**
+        * Destroy a radattr_listener_t.
+        */
+       void (*destroy)(radattr_listener_t *this);
+};
+
+/**
+ * Create a radattr_listener instance.
+ */
+radattr_listener_t *radattr_listener_create();
+
+#endif /** RADATTR_LISTENER_H_ @}*/
diff --git a/src/libcharon/plugins/radattr/radattr_plugin.c b/src/libcharon/plugins/radattr/radattr_plugin.c
new file mode 100644 (file)
index 0000000..85ea326
--- /dev/null
@@ -0,0 +1,75 @@
+/*
+ * Copyright (C) 2012 Martin Willi
+ * Copyright (C) 2012 revosec AG
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.  See <http://www.fsf.org/copyleft/gpl.txt>.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * for more details.
+ */
+
+#include "radattr_plugin.h"
+
+#include "radattr_listener.h"
+
+#include <daemon.h>
+
+typedef struct private_radattr_plugin_t private_radattr_plugin_t;
+
+/**
+ * private data of radattr plugin
+ */
+struct private_radattr_plugin_t {
+
+       /**
+        * implements plugin interface
+        */
+       radattr_plugin_t public;
+
+       /**
+        * Listener acting on messages
+        */
+       radattr_listener_t *listener;
+};
+
+METHOD(plugin_t, get_name, char*,
+       private_radattr_plugin_t *this)
+{
+       return "radattr";
+}
+
+METHOD(plugin_t, destroy, void,
+       private_radattr_plugin_t *this)
+{
+       charon->bus->remove_listener(charon->bus, &this->listener->listener);
+       this->listener->destroy(this->listener);
+       free(this);
+}
+
+/**
+ * Plugin constructor
+ */
+plugin_t *radattr_plugin_create()
+{
+       private_radattr_plugin_t *this;
+
+       INIT(this,
+               .public = {
+                       .plugin = {
+                               .get_name = _get_name,
+                               .reload = (void*)return_false,
+                               .destroy = _destroy,
+                       },
+               },
+               .listener = radattr_listener_create(),
+       );
+
+       charon->bus->add_listener(charon->bus, &this->listener->listener);
+
+       return &this->public.plugin;
+}
diff --git a/src/libcharon/plugins/radattr/radattr_plugin.h b/src/libcharon/plugins/radattr/radattr_plugin.h
new file mode 100644 (file)
index 0000000..c3bad5a
--- /dev/null
@@ -0,0 +1,42 @@
+/*
+ * Copyright (C) 2012 Martin Willi
+ * Copyright (C) 2012 revosec AG
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.  See <http://www.fsf.org/copyleft/gpl.txt>.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * for more details.
+ */
+
+/**
+ * @defgroup radattr radattr
+ * @ingroup cplugins
+ *
+ * @defgroup radattr_plugin radattr_plugin
+ * @{ @ingroup radattr
+ */
+
+#ifndef RADATTR_PLUGIN_H_
+#define RADATTR_PLUGIN_H_
+
+#include <plugins/plugin.h>
+
+typedef struct radattr_plugin_t radattr_plugin_t;
+
+/**
+ * Plugin to inject/process custom RADIUS attributes.
+ */
+struct radattr_plugin_t {
+
+       /**
+        * implements plugin interface
+        */
+       plugin_t plugin;
+};
+
+#endif /** RADATTR_PLUGIN_H_ @}*/