Merge branch 'attr-migrate'

Migrates the attribute framework and associated plugins from libhydra back
to libcharon. libcharon is the only user of this framework since pluto is gone.
With these changes, we can pass the full IKE_SA state to attribute providers
and handlers, bringing more flexibility to these plugins.
This commit is contained in:
Martin Willi 2015-02-04 11:38:58 +01:00
commit 88a06a3596
78 changed files with 382 additions and 1266 deletions

View File

@ -257,7 +257,6 @@ ARG_ENABL_SET([maemo], [enable Maemo specific plugin.])
ARG_ENABL_SET([radattr], [enable plugin to inject and process custom RADIUS attributes as IKEv2 client.])
ARG_ENABL_SET([systime-fix], [enable plugin to handle cert lifetimes with invalid system time gracefully.])
ARG_ENABL_SET([test-vectors], [enable plugin providing crypto test vectors.])
ARG_ENABL_SET([unit-tester], [enable unit tests on IKEv2 daemon startup.])
ARG_DISBL_SET([updown], [disable updown firewall script plugin.])
# programs/components
ARG_ENABL_SET([aikgen], [enable AIK generator.])
@ -1256,8 +1255,8 @@ ADD_PLUGIN([winhttp], [s charon pki scripts])
ADD_PLUGIN([soup], [s charon pki scripts nm cmd])
ADD_PLUGIN([mysql], [s charon pool manager medsrv attest])
ADD_PLUGIN([sqlite], [s charon pool manager medsrv attest])
ADD_PLUGIN([attr], [h charon])
ADD_PLUGIN([attr-sql], [h charon])
ADD_PLUGIN([attr], [c charon])
ADD_PLUGIN([attr-sql], [c charon])
ADD_PLUGIN([load-tester], [c charon])
ADD_PLUGIN([kernel-libipsec], [c charon cmd])
ADD_PLUGIN([kernel-wfp], [c charon])
@ -1265,7 +1264,7 @@ ADD_PLUGIN([kernel-iph], [c charon])
ADD_PLUGIN([kernel-pfkey], [h charon starter nm cmd])
ADD_PLUGIN([kernel-pfroute], [h charon starter nm cmd])
ADD_PLUGIN([kernel-netlink], [h charon starter nm cmd])
ADD_PLUGIN([resolve], [h charon cmd])
ADD_PLUGIN([resolve], [c charon cmd])
ADD_PLUGIN([socket-default], [c charon nm cmd])
ADD_PLUGIN([socket-dynamic], [c charon cmd])
ADD_PLUGIN([socket-win], [c charon])
@ -1326,7 +1325,6 @@ ADD_PLUGIN([maemo], [c charon])
ADD_PLUGIN([uci], [c charon])
ADD_PLUGIN([addrblock], [c charon])
ADD_PLUGIN([unity], [c charon])
ADD_PLUGIN([unit-tester], [c charon])
AC_SUBST(charon_plugins)
AC_SUBST(starter_plugins)
@ -1419,7 +1417,6 @@ AM_CONDITIONAL(USE_DNSCERT, test x$dnscert = xtrue)
AM_CONDITIONAL(USE_IPSECKEY, test x$ipseckey = xtrue)
AM_CONDITIONAL(USE_UPDOWN, test x$updown = xtrue)
AM_CONDITIONAL(USE_DHCP, test x$dhcp = xtrue)
AM_CONDITIONAL(USE_UNIT_TESTS, test x$unit_tester = xtrue)
AM_CONDITIONAL(USE_LOAD_TESTER, test x$load_tester = xtrue)
AM_CONDITIONAL(USE_HA, test x$ha = xtrue)
AM_CONDITIONAL(USE_KERNEL_LIBIPSEC, test x$kernel_libipsec = xtrue)
@ -1481,15 +1478,15 @@ AM_CONDITIONAL(USE_SOCKET_WIN, test x$socket_win = xtrue)
AM_CONDITIONAL(USE_FARP, test x$farp = xtrue)
AM_CONDITIONAL(USE_ADDRBLOCK, test x$addrblock = xtrue)
AM_CONDITIONAL(USE_UNITY, test x$unity = xtrue)
AM_CONDITIONAL(USE_RESOLVE, test x$resolve = xtrue)
AM_CONDITIONAL(USE_ATTR, test x$attr = xtrue)
AM_CONDITIONAL(USE_ATTR_SQL, test x$attr_sql = xtrue)
# hydra plugins
# ---------------
AM_CONDITIONAL(USE_ATTR, test x$attr = xtrue)
AM_CONDITIONAL(USE_ATTR_SQL, test x$attr_sql = xtrue)
AM_CONDITIONAL(USE_KERNEL_NETLINK, test x$kernel_netlink = xtrue)
AM_CONDITIONAL(USE_KERNEL_PFKEY, test x$kernel_pfkey = xtrue)
AM_CONDITIONAL(USE_KERNEL_PFROUTE, test x$kernel_pfroute = xtrue)
AM_CONDITIONAL(USE_RESOLVE, test x$resolve = xtrue)
# other options
# ---------------
@ -1649,12 +1646,9 @@ AC_CONFIG_FILES([
src/libstrongswan/plugins/test_vectors/Makefile
src/libstrongswan/tests/Makefile
src/libhydra/Makefile
src/libhydra/plugins/attr/Makefile
src/libhydra/plugins/attr_sql/Makefile
src/libhydra/plugins/kernel_netlink/Makefile
src/libhydra/plugins/kernel_pfkey/Makefile
src/libhydra/plugins/kernel_pfroute/Makefile
src/libhydra/plugins/resolve/Makefile
src/libhydra/tests/Makefile
src/libipsec/Makefile
src/libsimaka/Makefile
@ -1748,8 +1742,11 @@ AC_CONFIG_FILES([
src/libcharon/plugins/vici/ruby/Makefile
src/libcharon/plugins/updown/Makefile
src/libcharon/plugins/dhcp/Makefile
src/libcharon/plugins/unit_tester/Makefile
src/libcharon/plugins/load_tester/Makefile
src/libcharon/plugins/resolve/Makefile
src/libcharon/plugins/attr/Makefile
src/libcharon/plugins/attr_sql/Makefile
src/libcharon/tests/Makefile
src/stroke/Makefile
src/ipsec/Makefile
src/starter/Makefile

View File

@ -18,7 +18,6 @@
#include "nm_creds.h"
#include "nm_handler.h"
#include <hydra.h>
#include <daemon.h>
#include <processing/jobs/callback_job.h>
@ -97,7 +96,8 @@ static void nm_backend_deinit()
g_object_unref(this->plugin);
}
lib->credmgr->remove_set(lib->credmgr, &this->creds->set);
hydra->attributes->remove_handler(hydra->attributes, &this->handler->handler);
charon->attributes->remove_handler(charon->attributes,
&this->handler->handler);
this->creds->destroy(this->creds);
this->handler->destroy(this->handler);
free(this);
@ -130,7 +130,7 @@ static bool nm_backend_init()
this->plugin = nm_strongswan_plugin_new(this->creds, this->handler);
nm_backend = this;
hydra->attributes->add_handler(hydra->attributes, &this->handler->handler);
charon->attributes->add_handler(charon->attributes, &this->handler->handler);
lib->credmgr->add_set(lib->credmgr, &this->creds->set);
if (!this->plugin)
{

View File

@ -41,7 +41,7 @@ struct private_nm_handler_t {
};
METHOD(attribute_handler_t, handle, bool,
private_nm_handler_t *this, identification_t *server,
private_nm_handler_t *this, ike_sa_t *ike_sa,
configuration_attribute_type_t type, chunk_t data)
{
linked_list_t *list;
@ -92,7 +92,7 @@ static bool enumerate_dns(enumerator_t *this,
}
METHOD(attribute_handler_t, create_attribute_enumerator, enumerator_t*,
private_nm_handler_t *this, identification_t *server, linked_list_t *vips)
private_nm_handler_t *this, ike_sa_t *ike_sa, linked_list_t *vips)
{
if (vips->get_count(vips))
{
@ -185,4 +185,3 @@ nm_handler_t *nm_handler_create()
return &this->public;
}

View File

@ -36,7 +36,7 @@ struct private_android_attr_t {
};
METHOD(attribute_handler_t, handle, bool,
private_android_attr_t *this, identification_t *server,
private_android_attr_t *this, ike_sa_t *ike_sa,
configuration_attribute_type_t type, chunk_t data)
{
vpnservice_builder_t *builder;
@ -67,7 +67,7 @@ METHOD(attribute_handler_t, handle, bool,
}
METHOD(attribute_handler_t, release, void,
private_android_attr_t *this, identification_t *server,
private_android_attr_t *this, ike_sa_t *ike_sa,
configuration_attribute_type_t type, chunk_t data)
{
/* DNS servers cannot be removed from an existing TUN device */
@ -92,7 +92,7 @@ METHOD(enumerator_t, enumerate_dns4, bool,
}
METHOD(attribute_handler_t, create_attribute_enumerator, enumerator_t*,
private_android_attr_t *this, identification_t *server, linked_list_t *vips)
private_android_attr_t *this, ike_sa_t *ike_sa, linked_list_t *vips)
{
enumerator_t *enumerator;
@ -129,4 +129,3 @@ android_attr_t *android_attr_create()
return &this->public;
}

View File

@ -425,15 +425,15 @@ static bool charonservice_register(plugin_t *plugin, plugin_feature_t *feature,
{
this->net_handler = android_net_create();
lib->credmgr->add_set(lib->credmgr, &this->creds->set);
hydra->attributes->add_handler(hydra->attributes,
&this->attr->handler);
charon->attributes->add_handler(charon->attributes,
&this->attr->handler);
}
else
{
this->net_handler->destroy(this->net_handler);
lib->credmgr->remove_set(lib->credmgr, &this->creds->set);
hydra->attributes->remove_handler(hydra->attributes,
&this->attr->handler);
charon->attributes->remove_handler(charon->attributes,
&this->attr->handler);
if (this->service)
{
this->service->destroy(this->service);

View File

@ -3,6 +3,10 @@ include $(CLEAR_VARS)
# copy-n-paste from Makefile.am
libcharon_la_SOURCES := \
attributes/attributes.c attributes/attributes.h \
attributes/attribute_provider.h attributes/attribute_handler.h \
attributes/attribute_manager.c attributes/attribute_manager.h \
attributes/mem_pool.c attributes/mem_pool.h \
bus/bus.c bus/bus.h \
bus/listeners/listener.h \
bus/listeners/logger.h \

View File

@ -1,6 +1,10 @@
ipseclib_LTLIBRARIES = libcharon.la
libcharon_la_SOURCES = \
attributes/attributes.c attributes/attributes.h \
attributes/attribute_provider.h attributes/attribute_handler.h \
attributes/attribute_manager.c attributes/attribute_manager.h \
attributes/mem_pool.c attributes/mem_pool.h \
bus/bus.c bus/bus.h \
bus/listeners/listener.h \
bus/listeners/logger.h \
@ -596,13 +600,6 @@ if MONOLITHIC
endif
endif
if USE_UNIT_TESTS
SUBDIRS += plugins/unit_tester
if MONOLITHIC
libcharon_la_LIBADD += plugins/unit_tester/libstrongswan-unit-tester.la
endif
endif
if USE_XAUTH_GENERIC
SUBDIRS += plugins/xauth_generic
if MONOLITHIC
@ -630,3 +627,29 @@ if MONOLITHIC
libcharon_la_LIBADD += plugins/xauth_noauth/libstrongswan-xauth-noauth.la
endif
endif
if USE_RESOLVE
SUBDIRS += plugins/resolve
if MONOLITHIC
libcharon_la_LIBADD += plugins/resolve/libstrongswan-resolve.la
endif
endif
if USE_ATTR
SUBDIRS += plugins/attr
if MONOLITHIC
libcharon_la_LIBADD += plugins/attr/libstrongswan-attr.la
endif
endif
if USE_ATTR_SQL
SUBDIRS += plugins/attr_sql
if MONOLITHIC
libcharon_la_LIBADD += plugins/attr_sql/libstrongswan-attr-sql.la
endif
endif
if MONOLITHIC
SUBDIRS += .
endif
SUBDIRS += tests

View File

@ -21,14 +21,14 @@
#ifndef ATTRIBUTE_HANDLER_H_
#define ATTRIBUTE_HANDLER_H_
typedef struct attribute_handler_t attribute_handler_t;
#include <sa/ike_sa.h>
#include <utils/chunk.h>
#include <utils/identification.h>
#include <collections/linked_list.h>
#include "attributes.h"
typedef struct attribute_handler_t attribute_handler_t;
/**
* Interface to handle configuration payload attributes.
*/
@ -40,12 +40,12 @@ struct attribute_handler_t {
* After receiving a configuration attriubte, it is passed to each
* attribute handler until it is handled.
*
* @param server server from which the attribute was received
* @param ike_sa IKE_SA under which attribute is received
* @param type type of configuration attribute to handle
* @param data associated attribute data
* @return TRUE if attribute handled
*/
bool (*handle)(attribute_handler_t *this, identification_t *server,
bool (*handle)(attribute_handler_t *this, ike_sa_t *ike_sa,
configuration_attribute_type_t type, chunk_t data);
/**
@ -54,19 +54,23 @@ struct attribute_handler_t {
* A handler that handle()d an attribute gets a call to release() when the
* connection gets closed. Depending on the implementation, this is required
* to remove the attribute.
*
* @param ike_sa IKE_SA which releases attribute
* @param type type of configuration attribute to release
* @param data associated attribute data
*/
void (*release)(attribute_handler_t *this, identification_t *server,
void (*release)(attribute_handler_t *this, ike_sa_t *ike_sa,
configuration_attribute_type_t type, chunk_t data);
/**
* Enumerate attributes to request from a server.
*
* @param server server identity to request attributes from
* @param ike_sa IKE_SA to request attributes for
* @param vips list of virtual IPs (host_t*) we are requesting
* @return enumerator (configuration_attribute_type_t, chunk_t)
*/
enumerator_t* (*create_attribute_enumerator)(attribute_handler_t *this,
identification_t *server, linked_list_t *vips);
ike_sa_t *ike_sa, linked_list_t *vips);
};
#endif /** ATTRIBUTE_HANDLER_H_ @}*/

View File

@ -53,15 +53,15 @@ struct private_attribute_manager_t {
typedef struct {
/** attribute group pools */
linked_list_t *pools;
/** server/peer identity */
identification_t *id;
/** associated IKE_SA */
ike_sa_t *ike_sa;
/** requesting/assigned virtual IPs */
linked_list_t *vips;
} enum_data_t;
METHOD(attribute_manager_t, acquire_address, host_t*,
private_attribute_manager_t *this, linked_list_t *pools,
identification_t *id, host_t *requested)
ike_sa_t *ike_sa, host_t *requested)
{
enumerator_t *enumerator;
attribute_provider_t *current;
@ -71,7 +71,7 @@ METHOD(attribute_manager_t, acquire_address, host_t*,
enumerator = this->providers->create_enumerator(this->providers);
while (enumerator->enumerate(enumerator, &current))
{
host = current->acquire_address(current, pools, id, requested);
host = current->acquire_address(current, pools, ike_sa, requested);
if (host)
{
break;
@ -85,7 +85,7 @@ METHOD(attribute_manager_t, acquire_address, host_t*,
METHOD(attribute_manager_t, release_address, bool,
private_attribute_manager_t *this, linked_list_t *pools, host_t *address,
identification_t *id)
ike_sa_t *ike_sa)
{
enumerator_t *enumerator;
attribute_provider_t *current;
@ -95,7 +95,7 @@ METHOD(attribute_manager_t, release_address, bool,
enumerator = this->providers->create_enumerator(this->providers);
while (enumerator->enumerate(enumerator, &current))
{
if (current->release_address(current, pools, address, id))
if (current->release_address(current, pools, address, ike_sa))
{
found = TRUE;
break;
@ -114,18 +114,18 @@ static enumerator_t *responder_enum_create(attribute_provider_t *provider,
enum_data_t *data)
{
return provider->create_attribute_enumerator(provider, data->pools,
data->id, data->vips);
data->ike_sa, data->vips);
}
METHOD(attribute_manager_t, create_responder_enumerator, enumerator_t*,
private_attribute_manager_t *this, linked_list_t *pools,
identification_t *id, linked_list_t *vips)
ike_sa_t *ike_sa, linked_list_t *vips)
{
enum_data_t *data;
INIT(data,
.pools = pools,
.id = id,
.ike_sa = ike_sa,
.vips = vips,
);
this->lock->read_lock(this->lock);
@ -153,7 +153,7 @@ METHOD(attribute_manager_t, remove_provider, void,
}
METHOD(attribute_manager_t, handle, attribute_handler_t*,
private_attribute_manager_t *this, identification_t *server,
private_attribute_manager_t *this, ike_sa_t *ike_sa,
attribute_handler_t *handler, configuration_attribute_type_t type,
chunk_t data)
{
@ -166,7 +166,7 @@ METHOD(attribute_manager_t, handle, attribute_handler_t*,
enumerator = this->handlers->create_enumerator(this->handlers);
while (enumerator->enumerate(enumerator, &current))
{
if (current == handler && current->handle(current, server, type, data))
if (current == handler && current->handle(current, ike_sa, type, data))
{
handled = current;
break;
@ -178,7 +178,7 @@ METHOD(attribute_manager_t, handle, attribute_handler_t*,
enumerator = this->handlers->create_enumerator(this->handlers);
while (enumerator->enumerate(enumerator, &current))
{
if (current->handle(current, server, type, data))
if (current->handle(current, ike_sa, type, data))
{
handled = current;
break;
@ -198,7 +198,7 @@ METHOD(attribute_manager_t, handle, attribute_handler_t*,
METHOD(attribute_manager_t, release, void,
private_attribute_manager_t *this, attribute_handler_t *handler,
identification_t *server, configuration_attribute_type_t type, chunk_t data)
ike_sa_t *ike_sa, configuration_attribute_type_t type, chunk_t data)
{
enumerator_t *enumerator;
attribute_handler_t *current;
@ -209,7 +209,7 @@ METHOD(attribute_manager_t, release, void,
{
if (current == handler)
{
current->release(current, server, type, data);
current->release(current, ike_sa, type, data);
break;
}
}
@ -231,8 +231,8 @@ typedef struct {
enumerator_t *outer;
/** inner enumerator over current handlers attributes */
enumerator_t *inner;
/** server ID we want attributes for */
identification_t *id;
/** IKE_SA to request attributes for */
ike_sa_t *ike_sa;
/** virtual IPs we are requesting along with attriubutes */
linked_list_t *vips;
} initiator_enumerator_t;
@ -254,7 +254,7 @@ static bool initiator_enumerate(initiator_enumerator_t *this,
}
DESTROY_IF(this->inner);
this->inner = this->handler->create_attribute_enumerator(this->handler,
this->id, this->vips);
this->ike_sa, this->vips);
}
/* inject the handler as additional attribute */
*handler = this->handler;
@ -273,7 +273,7 @@ static void initiator_destroy(initiator_enumerator_t *this)
}
METHOD(attribute_manager_t, create_initiator_enumerator, enumerator_t*,
private_attribute_manager_t *this, identification_t *id, linked_list_t *vips)
private_attribute_manager_t *this, ike_sa_t *ike_sa, linked_list_t *vips)
{
initiator_enumerator_t *enumerator;
@ -285,7 +285,7 @@ METHOD(attribute_manager_t, create_initiator_enumerator, enumerator_t*,
.destroy = (void*)initiator_destroy,
},
.this = this,
.id = id,
.ike_sa = ike_sa,
.vips = vips,
.outer = this->handlers->create_enumerator(this->handlers),
);
@ -345,4 +345,3 @@ attribute_manager_t *attribute_manager_create()
return &this->public;
}

View File

@ -24,6 +24,8 @@
#include "attribute_provider.h"
#include "attribute_handler.h"
#include <sa/ike_sa.h>
typedef struct attribute_manager_t attribute_manager_t;
/**
@ -40,12 +42,12 @@ struct attribute_manager_t {
* Acquire a virtual IP address to assign to a peer.
*
* @param pools list of pool names (char*) to acquire from
* @param id peer identity to get address forua
* @param ike_sa associated IKE_SA for which an address is requested
* @param requested IP in configuration request
* @return allocated address, NULL to serve none
*/
host_t* (*acquire_address)(attribute_manager_t *this,
linked_list_t *pool, identification_t *id,
linked_list_t *pool, ike_sa_t *ike_sa,
host_t *requested);
/**
@ -53,23 +55,23 @@ struct attribute_manager_t {
*
* @param pools list of pool names (char*) to release to
* @param address address to release
* @param id peer identity to get address for
* @param ike_sa associated IKE_SA for which an address is released
* @return TRUE if address released to pool
*/
bool (*release_address)(attribute_manager_t *this,
linked_list_t *pools, host_t *address,
identification_t *id);
ike_sa_t *ike_sa);
/**
* Create an enumerator over attributes to hand out to a peer.
*
* @param pool list of pools names (char*) to query attributes from
* @param id peer identity to hand out attributes to
* @param ike_sa associated IKE_SA for which attributes are requested
* @param vip list of virtual IPs (host_t*) to assign to peer
* @return enumerator (configuration_attribute_type_t, chunk_t)
*/
enumerator_t* (*create_responder_enumerator)(attribute_manager_t *this,
linked_list_t *pool, identification_t *id,
linked_list_t *pool, ike_sa_t *ike_sa,
linked_list_t *vips);
/**
@ -90,38 +92,37 @@ struct attribute_manager_t {
/**
* Handle a configuration attribute by passing them to the handlers.
*
* @param server server from which the attribute was received
* @param ike_sa associated IKE_SA to handle an attribute for
* @param handler handler we requested the attribute for, if any
* @param type type of configuration attribute
* @param data associated attribute data
* @return handler which handled this attribute, NULL if none
*/
attribute_handler_t* (*handle)(attribute_manager_t *this,
identification_t *server, attribute_handler_t *handler,
ike_sa_t *ike_sa, attribute_handler_t *handler,
configuration_attribute_type_t type, chunk_t data);
/**
* Release an attribute previously handle()d by a handler.
*
* @param handler handler returned by handle() for this attribute
* @param ike_sa associated IKE_SA to release an attribute for
* @param server server from which the attribute was received
* @param type type of attribute to release
* @param data associated attribute data
*/
void (*release)(attribute_manager_t *this, attribute_handler_t *handler,
identification_t *server,
configuration_attribute_type_t type,
ike_sa_t *ike_sa, configuration_attribute_type_t type,
chunk_t data);
/**
* Create an enumerator over attributes to request from server.
*
* @param id server identity to hand out attributes to
* @param ike_sa associated IKE_SA to request attributes for
* @param vip list of virtual IPs (host_t*) going to request
* @return enumerator (attribute_handler_t, ca_type_t, chunk_t)
*/
enumerator_t* (*create_initiator_enumerator)(attribute_manager_t *this,
identification_t *id, linked_list_t *vips);
ike_sa_t *ike_sa, linked_list_t *vips);
/**
* Register an attribute handler to the manager.

View File

@ -21,8 +21,8 @@
#ifndef ATTRIBUTE_PROVIDER_H_
#define ATTRIBUTE_PROVIDER_H_
#include <sa/ike_sa.h>
#include <networking/host.h>
#include <utils/identification.h>
#include <collections/linked_list.h>
typedef struct attribute_provider_t attribute_provider_t;
@ -36,35 +36,35 @@ struct attribute_provider_t {
* Acquire a virtual IP address to assign to a peer.
*
* @param pools list of pool names (char*) to acquire from
* @param id peer ID
* @param ike_sa associated IKE_SA to assign address over
* @param requested IP in configuration request
* @return allocated address, NULL to serve none
*/
host_t* (*acquire_address)(attribute_provider_t *this,
linked_list_t *pools, identification_t *id,
linked_list_t *pools, ike_sa_t *ike_sa,
host_t *requested);
/**
* Release a previously acquired address.
*
* @param pools list of pool names (char*) to release to
* @param address address to release
* @param id peer ID
* @param ike_sa IKE_SA to release address for
* @return TRUE if the address has been released by the provider
*/
bool (*release_address)(attribute_provider_t *this,
linked_list_t *pools, host_t *address,
identification_t *id);
ike_sa_t *ike_sa);
/**
* Create an enumerator over attributes to hand out to a peer.
*
* @param pool list of pools names (char*) to query attributes from
* @param id peer ID
* @param ike_sa IKE_SA to request attributes for
* @param vip list of virtual IPs (host_t*) to assign to peer
* @return enumerator (configuration_attribute_type_t, chunk_t)
*/
enumerator_t* (*create_attribute_enumerator)(attribute_provider_t *this,
linked_list_t *pools, identification_t *id,
linked_list_t *pools, ike_sa_t *ike_sa,
linked_list_t *vips);
};

View File

@ -477,6 +477,7 @@ static void destroy(private_daemon_t *this)
/* make sure the cache is clear before unloading plugins */
lib->credmgr->flush_cache(lib->credmgr, CERT_ANY);
lib->plugins->unload(lib->plugins);
DESTROY_IF(this->public.attributes);
DESTROY_IF(this->kernel_handler);
DESTROY_IF(this->public.traps);
DESTROY_IF(this->public.shunts);
@ -644,6 +645,7 @@ private_daemon_t *daemon_create()
.ref = 1,
);
charon = &this->public;
this->public.attributes = attribute_manager_create();
this->public.controller = controller_create();
this->public.eap = eap_manager_create();
this->public.xauth = xauth_manager_create();

View File

@ -19,6 +19,9 @@
/**
* @defgroup libcharon libcharon
*
* @defgroup attributes attributes
* @ingroup libcharon
*
* @defgroup bus bus
* @ingroup libcharon
*
@ -152,6 +155,7 @@
typedef struct daemon_t daemon_t;
#include <attributes/attribute_manager.h>
#include <network/sender.h>
#include <network/receiver.h>
#include <network/socket_manager.h>
@ -245,6 +249,11 @@ struct daemon_t {
*/
receiver_t *receiver;
/**
* Manager for IKE configuration attributes
*/
attribute_manager_t *attributes;
/**
* The signaling bus.
*/

View File

@ -128,7 +128,7 @@ static bool set_dns_server(private_android_dns_handler_t *this, int index,
}
METHOD(attribute_handler_t, handle, bool,
private_android_dns_handler_t *this, identification_t *id,
private_android_dns_handler_t *this, ike_sa_t *ike_sa,
configuration_attribute_type_t type, chunk_t data)
{
switch (type)
@ -158,7 +158,7 @@ METHOD(attribute_handler_t, handle, bool,
}
METHOD(attribute_handler_t, release, void,
private_android_dns_handler_t *this, identification_t *server,
private_android_dns_handler_t *this, ike_sa_t *ike_sa,
configuration_attribute_type_t type, chunk_t data)
{
if (type == INTERNAL_IP4_DNS)
@ -192,7 +192,7 @@ METHOD(enumerator_t, enumerate_dns, bool,
}
METHOD(attribute_handler_t, create_attribute_enumerator, enumerator_t *,
private_android_dns_handler_t *this, identification_t *id,
private_android_dns_handler_t *this, ike_sa_t *ike_sa,
linked_list_t *vips)
{
enumerator_t *enumerator;
@ -232,4 +232,3 @@ android_dns_handler_t *android_dns_handler_create()
return &this->public;
}

View File

@ -16,7 +16,6 @@
#include "android_dns_plugin.h"
#include "android_dns_handler.h"
#include <hydra.h>
#include <daemon.h>
typedef struct private_android_dns_plugin_t private_android_dns_plugin_t;
@ -51,13 +50,13 @@ static bool plugin_cb(private_android_dns_plugin_t *this,
{
if (reg)
{
hydra->attributes->add_handler(hydra->attributes,
&this->handler->handler);
charon->attributes->add_handler(charon->attributes,
&this->handler->handler);
}
else
{
hydra->attributes->remove_handler(hydra->attributes,
&this->handler->handler);
charon->attributes->remove_handler(charon->attributes,
&this->handler->handler);
}
return TRUE;
}

View File

@ -1,6 +1,7 @@
AM_CPPFLAGS = \
-I$(top_srcdir)/src/libstrongswan \
-I$(top_srcdir)/src/libhydra
-I$(top_srcdir)/src/libhydra \
-I$(top_srcdir)/src/libcharon
AM_CFLAGS = \
$(PLUGIN_CFLAGS)

View File

@ -16,7 +16,7 @@
#include "attr_plugin.h"
#include "attr_provider.h"
#include <hydra.h>
#include <daemon.h>
typedef struct private_attr_plugin_t private_attr_plugin_t;
@ -50,13 +50,13 @@ static bool plugin_cb(private_attr_plugin_t *this,
{
if (reg)
{
hydra->attributes->add_provider(hydra->attributes,
&this->provider->provider);
charon->attributes->add_provider(charon->attributes,
&this->provider->provider);
}
else
{
hydra->attributes->remove_provider(hydra->attributes,
&this->provider->provider);
charon->attributes->remove_provider(charon->attributes,
&this->provider->provider);
}
return TRUE;
}

View File

@ -15,7 +15,7 @@
/**
* @defgroup attr attr
* @ingroup hplugins
* @ingroup cplugins
*
* @defgroup attr_plugin attr_plugin
* @{ @ingroup attr

View File

@ -18,7 +18,7 @@
#include <time.h>
#include <hydra.h>
#include <daemon.h>
#include <utils/debug.h>
#include <collections/linked_list.h>
#include <threading/rwlock.h>
@ -78,7 +78,7 @@ static bool attr_enum_filter(void *null, attribute_entry_t **in,
METHOD(attribute_provider_t, create_attribute_enumerator, enumerator_t*,
private_attr_provider_t *this, linked_list_t *pools,
identification_t *id, linked_list_t *vips)
ike_sa_t *ike_sa, linked_list_t *vips)
{
if (vips->get_count(vips))
{

View File

@ -1,6 +1,7 @@
AM_CPPFLAGS = \
-I$(top_srcdir)/src/libstrongswan \
-I$(top_srcdir)/src/libhydra
-I$(top_srcdir)/src/libhydra \
-I$(top_srcdir)/src/libcharon
AM_CFLAGS = \
$(PLUGIN_CFLAGS)

View File

@ -14,7 +14,7 @@
* for more details.
*/
#include <hydra.h>
#include <daemon.h>
#include <utils/debug.h>
#include <plugins/plugin_feature.h>
@ -75,13 +75,13 @@ static bool open_database(private_attr_sql_plugin_t *this,
return FALSE;
}
this->attribute = sql_attribute_create(this->db);
hydra->attributes->add_provider(hydra->attributes,
&this->attribute->provider);
charon->attributes->add_provider(charon->attributes,
&this->attribute->provider);
}
else
{
hydra->attributes->remove_provider(hydra->attributes,
&this->attribute->provider);
charon->attributes->remove_provider(charon->attributes,
&this->attribute->provider);
this->attribute->destroy(this->attribute);
this->db->destroy(this->db);
}

View File

@ -15,7 +15,7 @@
/**
* @defgroup attr_sql attr_sql
* @ingroup hplugins
* @ingroup cplugins
*
* @defgroup sql_plugin sql_plugin
* @{ @ingroup attr_sql

View File

@ -46,11 +46,14 @@ struct private_sql_attribute_t {
/**
* lookup/insert an identity
*/
static u_int get_identity(private_sql_attribute_t *this, identification_t *id)
static u_int get_identity(private_sql_attribute_t *this, ike_sa_t *ike_sa)
{
identification_t *id;
enumerator_t *e;
u_int row;
id = ike_sa->get_other_eap_id(ike_sa);
this->db->transaction(this->db, TRUE);
/* look for peer identity in the identities table */
e = this->db->query(this->db,
@ -243,7 +246,7 @@ static host_t* get_lease(private_sql_attribute_t *this, char *name,
}
METHOD(attribute_provider_t, acquire_address, host_t*,
private_sql_attribute_t *this, linked_list_t *pools, identification_t *id,
private_sql_attribute_t *this, linked_list_t *pools, ike_sa_t *ike_sa,
host_t *requested)
{
enumerator_t *enumerator;
@ -252,7 +255,7 @@ METHOD(attribute_provider_t, acquire_address, host_t*,
char *name;
int family;
identity = get_identity(this, id);
identity = get_identity(this, ike_sa);
if (identity)
{
family = requested->get_family(requested);
@ -296,7 +299,7 @@ METHOD(attribute_provider_t, acquire_address, host_t*,
METHOD(attribute_provider_t, release_address, bool,
private_sql_attribute_t *this, linked_list_t *pools, host_t *address,
identification_t *id)
ike_sa_t *ike_sa)
{
enumerator_t *enumerator;
u_int pool, timeout;
@ -338,7 +341,7 @@ METHOD(attribute_provider_t, release_address, bool,
}
METHOD(attribute_provider_t, create_attribute_enumerator, enumerator_t*,
private_sql_attribute_t *this, linked_list_t *pools, identification_t *id,
private_sql_attribute_t *this, linked_list_t *pools, ike_sa_t *ike_sa,
linked_list_t *vips)
{
enumerator_t *attr_enumerator = NULL;
@ -350,9 +353,9 @@ METHOD(attribute_provider_t, create_attribute_enumerator, enumerator_t*,
char *name;
/* in a first step check for attributes that match name and id */
if (id)
if (ike_sa)
{
u_int identity = get_identity(this, id);
u_int identity = get_identity(this, ike_sa);
pool_enumerator = pools->create_enumerator(pools);
while (pool_enumerator->enumerate(pool_enumerator, &name))

View File

@ -18,7 +18,6 @@
#include "dhcp_plugin.h"
#include <hydra.h>
#include <daemon.h>
#include <plugins/plugin_feature.h>
@ -69,13 +68,13 @@ static bool plugin_cb(private_dhcp_plugin_t *this,
return FALSE;
}
this->provider = dhcp_provider_create(this->socket);
hydra->attributes->add_provider(hydra->attributes,
&this->provider->provider);
charon->attributes->add_provider(charon->attributes,
&this->provider->provider);
}
else
{
hydra->attributes->remove_provider(hydra->attributes,
&this->provider->provider);
charon->attributes->remove_provider(charon->attributes,
&this->provider->provider);
this->provider->destroy(this->provider);
this->socket->destroy(this->socket);
}

View File

@ -66,10 +66,11 @@ static uintptr_t hash_transaction(dhcp_transaction_t *transaction)
METHOD(attribute_provider_t, acquire_address, host_t*,
private_dhcp_provider_t *this, linked_list_t *pools,
identification_t *id, host_t *requested)
ike_sa_t *ike_sa, host_t *requested)
{
dhcp_transaction_t *transaction, *old;
enumerator_t *enumerator;
identification_t *id;
char *pool;
host_t *vip = NULL;
@ -77,6 +78,7 @@ METHOD(attribute_provider_t, acquire_address, host_t*,
{
return NULL;
}
id = ike_sa->get_other_eap_id(ike_sa);
enumerator = pools->create_enumerator(pools);
while (enumerator->enumerate(enumerator, &pool))
{
@ -104,10 +106,11 @@ METHOD(attribute_provider_t, acquire_address, host_t*,
METHOD(attribute_provider_t, release_address, bool,
private_dhcp_provider_t *this, linked_list_t *pools,
host_t *address, identification_t *id)
host_t *address, ike_sa_t *ike_sa)
{
dhcp_transaction_t *transaction;
enumerator_t *enumerator;
identification_t *id;
bool found = FALSE;
char *pool;
@ -115,6 +118,7 @@ METHOD(attribute_provider_t, release_address, bool,
{
return FALSE;
}
id = ike_sa->get_other_eap_id(ike_sa);
enumerator = pools->create_enumerator(pools);
while (enumerator->enumerate(enumerator, &pool))
{
@ -139,11 +143,12 @@ METHOD(attribute_provider_t, release_address, bool,
}
METHOD(attribute_provider_t, create_attribute_enumerator, enumerator_t*,
private_dhcp_provider_t *this, linked_list_t *pools, identification_t *id,
private_dhcp_provider_t *this, linked_list_t *pools, ike_sa_t *ike_sa,
linked_list_t *vips)
{
dhcp_transaction_t *transaction = NULL;
enumerator_t *enumerator;
identification_t *id;
host_t *vip;
if (pools->find_first(pools, (linked_list_match_t)streq,
@ -152,6 +157,7 @@ METHOD(attribute_provider_t, create_attribute_enumerator, enumerator_t*,
return NULL;
}
id = ike_sa->get_other_eap_id(ike_sa);
this->mutex->lock(this->mutex);
enumerator = vips->create_enumerator(vips);
while (enumerator->enumerate(enumerator, &vip))

View File

@ -26,7 +26,7 @@
#include <radius_client.h>
#include <radius_config.h>
#include <hydra.h>
#include <daemon.h>
#include <threading/rwlock.h>
#include <processing/jobs/callback_job.h>
#include <processing/jobs/delete_ike_sa_job.h>
@ -218,13 +218,13 @@ static bool plugin_cb(private_eap_radius_plugin_t *this,
{
charon->bus->add_listener(charon->bus, &this->forward->listener);
}
hydra->attributes->add_provider(hydra->attributes,
&this->provider->provider);
charon->attributes->add_provider(charon->attributes,
&this->provider->provider);
}
else
{
hydra->attributes->remove_provider(hydra->attributes,
&this->provider->provider);
charon->attributes->remove_provider(charon->attributes,
&this->provider->provider);
if (this->forward)
{
charon->bus->remove_listener(charon->bus, &this->forward->listener);

View File

@ -311,19 +311,13 @@ METHOD(listener_t, ike_rekey, bool,
METHOD(attribute_provider_t, acquire_address, host_t*,
private_eap_radius_provider_t *this, linked_list_t *pools,
identification_t *id, host_t *requested)
ike_sa_t *ike_sa, host_t *requested)
{
enumerator_t *enumerator;
host_t *addr = NULL;
ike_sa_t *ike_sa;
uintptr_t sa;
char *name;
ike_sa = charon->bus->get_sa(charon->bus);
if (!ike_sa)
{
return NULL;
}
sa = ike_sa->get_unique_id(ike_sa);
enumerator = pools->create_enumerator(pools);
@ -348,19 +342,13 @@ METHOD(attribute_provider_t, acquire_address, host_t*,
METHOD(attribute_provider_t, release_address, bool,
private_eap_radius_provider_t *this, linked_list_t *pools, host_t *address,
identification_t *id)
ike_sa_t *ike_sa)
{
enumerator_t *enumerator;
host_t *found = NULL;
ike_sa_t *ike_sa;
uintptr_t sa;
char *name;
ike_sa = charon->bus->get_sa(charon->bus);
if (!ike_sa)
{
return FALSE;
}
sa = ike_sa->get_unique_id(ike_sa);
enumerator = pools->create_enumerator(pools);
@ -428,18 +416,12 @@ METHOD(enumerator_t, attribute_destroy, void,
METHOD(attribute_provider_t, create_attribute_enumerator, enumerator_t*,
private_eap_radius_provider_t *this, linked_list_t *pools,
identification_t *id, linked_list_t *vips)
ike_sa_t *ike_sa, linked_list_t *vips)
{
attribute_enumerator_t *enumerator;
attr_t *attr;
ike_sa_t *ike_sa;
uintptr_t sa;
ike_sa = charon->bus->get_sa(charon->bus);
if (!ike_sa)
{
return NULL;
}
sa = ike_sa->get_unique_id(ike_sa);
INIT(enumerator,

View File

@ -170,7 +170,7 @@ static bool responsible_for(private_ha_attribute_t *this, int bit)
}
METHOD(attribute_provider_t, acquire_address, host_t*,
private_ha_attribute_t *this, linked_list_t *pools, identification_t *id,
private_ha_attribute_t *this, linked_list_t *pools, ike_sa_t *ike_sa,
host_t *requested)
{
enumerator_t *enumerator;
@ -233,7 +233,7 @@ METHOD(attribute_provider_t, acquire_address, host_t*,
METHOD(attribute_provider_t, release_address, bool,
private_ha_attribute_t *this, linked_list_t *pools, host_t *address,
identification_t *id)
ike_sa_t *ike_sa)
{
enumerator_t *enumerator;
pool_t *pool;

View File

@ -25,7 +25,6 @@
#include "ha_attribute.h"
#include <daemon.h>
#include <hydra.h>
#include <config/child_cfg.h>
typedef struct private_ha_plugin_t private_ha_plugin_t;
@ -108,13 +107,13 @@ static bool plugin_cb(private_ha_plugin_t *this,
charon->bus->add_listener(charon->bus, &this->segments->listener);
charon->bus->add_listener(charon->bus, &this->ike->listener);
charon->bus->add_listener(charon->bus, &this->child->listener);
hydra->attributes->add_provider(hydra->attributes,
&this->attr->provider);
charon->attributes->add_provider(charon->attributes,
&this->attr->provider);
}
else
{
hydra->attributes->remove_provider(hydra->attributes,
&this->attr->provider);
charon->attributes->remove_provider(charon->attributes,
&this->attr->provider);
charon->bus->remove_listener(charon->bus, &this->segments->listener);
charon->bus->remove_listener(charon->bus, &this->ike->listener);
charon->bus->remove_listener(charon->bus, &this->child->listener);
@ -224,4 +223,3 @@ plugin_t *ha_plugin_create()
return &this->public.plugin;
}

View File

@ -169,7 +169,7 @@ static bool manage_dns(int family, chunk_t data, bool add)
}
METHOD(attribute_handler_t, handle, bool,
private_osx_attr_handler_t *this, identification_t *id,
private_osx_attr_handler_t *this, ike_sa_t *ike_sa,
configuration_attribute_type_t type, chunk_t data)
{
switch (type)
@ -182,7 +182,7 @@ METHOD(attribute_handler_t, handle, bool,
}
METHOD(attribute_handler_t, release, void,
private_osx_attr_handler_t *this, identification_t *server,
private_osx_attr_handler_t *this, ike_sa_t *ike_sa,
configuration_attribute_type_t type, chunk_t data)
{
switch (type)
@ -206,7 +206,7 @@ METHOD(enumerator_t, enumerate_dns, bool,
}
METHOD(attribute_handler_t, create_attribute_enumerator, enumerator_t *,
private_osx_attr_handler_t *this, identification_t *id,
private_osx_attr_handler_t *this, ike_sa_t *ike_sa,
linked_list_t *vips)
{
enumerator_t *enumerator;

View File

@ -16,7 +16,6 @@
#include "osx_attr_plugin.h"
#include "osx_attr_handler.h"
#include <hydra.h>
#include <daemon.h>
typedef struct private_osx_attr_plugin_t private_osx_attr_plugin_t;
@ -51,13 +50,13 @@ static bool plugin_cb(private_osx_attr_plugin_t *this,
{
if (reg)
{
hydra->attributes->add_handler(hydra->attributes,
&this->handler->handler);
charon->attributes->add_handler(charon->attributes,
&this->handler->handler);
}
else
{
hydra->attributes->remove_handler(hydra->attributes,
&this->handler->handler);
charon->attributes->remove_handler(charon->attributes,
&this->handler->handler);
}
return TRUE;
}

View File

@ -1,6 +1,7 @@
AM_CPPFLAGS = \
-I$(top_srcdir)/src/libstrongswan \
-I$(top_srcdir)/src/libhydra \
-I$(top_srcdir)/src/libcharon \
-DRESOLV_CONF=\"${resolv_conf}\"
AM_CFLAGS = \

View File

@ -185,9 +185,10 @@ static bool invoke_resolvconf(private_resolve_handler_t *this,
}
METHOD(attribute_handler_t, handle, bool,
private_resolve_handler_t *this, identification_t *server,
private_resolve_handler_t *this, ike_sa_t *ike_sa,
configuration_attribute_type_t type, chunk_t data)
{
identification_t *server;
host_t *addr;
bool handled;
@ -208,6 +209,7 @@ METHOD(attribute_handler_t, handle, bool,
DESTROY_IF(addr);
return FALSE;
}
server = ike_sa->get_other_id(ike_sa);
this->mutex->lock(this->mutex);
if (this->use_resolvconf)
@ -229,9 +231,10 @@ METHOD(attribute_handler_t, handle, bool,
}
METHOD(attribute_handler_t, release, void,
private_resolve_handler_t *this, identification_t *server,
private_resolve_handler_t *this, ike_sa_t *ike_sa,
configuration_attribute_type_t type, chunk_t data)
{
identification_t *server;
host_t *addr;
int family;
@ -247,6 +250,7 @@ METHOD(attribute_handler_t, release, void,
return;
}
addr = host_create_from_chunk(family, data, 0);
server = ike_sa->get_other_id(ike_sa);
this->mutex->lock(this->mutex);
if (this->use_resolvconf)
@ -319,7 +323,7 @@ static bool has_host_family(linked_list_t *list, int family)
}
METHOD(attribute_handler_t, create_attribute_enumerator, enumerator_t*,
private_resolve_handler_t *this, identification_t *server,
private_resolve_handler_t *this, ike_sa_t *ike_sa,
linked_list_t *vips)
{
attribute_enumerator_t *enumerator;
@ -374,4 +378,3 @@ resolve_handler_t *resolve_handler_create()
return &this->public;
}

View File

@ -16,7 +16,7 @@
#include "resolve_plugin.h"
#include "resolve_handler.h"
#include <hydra.h>
#include <daemon.h>
typedef struct private_resolve_plugin_t private_resolve_plugin_t;
@ -50,13 +50,13 @@ static bool plugin_cb(private_resolve_plugin_t *this,
{
if (reg)
{
hydra->attributes->add_handler(hydra->attributes,
&this->handler->handler);
charon->attributes->add_handler(charon->attributes,
&this->handler->handler);
}
else
{
hydra->attributes->remove_handler(hydra->attributes,
&this->handler->handler);
charon->attributes->remove_handler(charon->attributes,
&this->handler->handler);
}
return TRUE;
}
@ -99,4 +99,3 @@ plugin_t *resolve_plugin_create()
return &this->public.plugin;
}

View File

@ -120,11 +120,14 @@ static host_t *find_addr(private_stroke_attribute_t *this, linked_list_t *pools,
}
METHOD(attribute_provider_t, acquire_address, host_t*,
private_stroke_attribute_t *this, linked_list_t *pools, identification_t *id,
private_stroke_attribute_t *this, linked_list_t *pools, ike_sa_t *ike_sa,
host_t *requested)
{
identification_t *id;
host_t *addr;
id = ike_sa->get_other_eap_id(ike_sa);
this->lock->read_lock(this->lock);
addr = find_addr(this, pools, id, requested, MEM_POOL_EXISTING);
@ -144,13 +147,16 @@ METHOD(attribute_provider_t, acquire_address, host_t*,
METHOD(attribute_provider_t, release_address, bool,
private_stroke_attribute_t *this, linked_list_t *pools, host_t *address,
identification_t *id)
ike_sa_t *ike_sa)
{
enumerator_t *enumerator;
identification_t *id;
mem_pool_t *pool;
bool found = FALSE;
char *name;
id = ike_sa->get_other_eap_id(ike_sa);
enumerator = pools->create_enumerator(pools);
this->lock->read_lock(this->lock);
while (enumerator->enumerate(enumerator, &name))
@ -197,9 +203,8 @@ static bool attr_filter(void *lock, host_t **in,
METHOD(attribute_provider_t, create_attribute_enumerator, enumerator_t*,
private_stroke_attribute_t *this, linked_list_t *pools,
identification_t *id, linked_list_t *vips)
ike_sa_t *ike_sa, linked_list_t *vips)
{
ike_sa_t *ike_sa;
peer_cfg_t *peer_cfg;
enumerator_t *enumerator;
attributes_t *attr;
@ -413,4 +418,3 @@ stroke_attribute_t *stroke_attribute_create()
return &this->public;
}

View File

@ -94,10 +94,9 @@ static bool attr_filter(void *lock, host_t **in,
}
METHOD(attribute_handler_t, create_attribute_enumerator, enumerator_t*,
private_stroke_handler_t *this, identification_t *server,
private_stroke_handler_t *this, ike_sa_t *ike_sa,
linked_list_t *vips)
{
ike_sa_t *ike_sa;
peer_cfg_t *peer_cfg;
enumerator_t *enumerator;
attributes_t *attr;

View File

@ -24,7 +24,6 @@
#include <unistd.h>
#include <errno.h>
#include <hydra.h>
#include <daemon.h>
#include "stroke_config.h"
@ -747,8 +746,10 @@ METHOD(stroke_socket_t, destroy, void,
lib->credmgr->remove_set(lib->credmgr, &this->ca->set);
lib->credmgr->remove_set(lib->credmgr, &this->cred->set);
charon->backends->remove_backend(charon->backends, &this->config->backend);
hydra->attributes->remove_provider(hydra->attributes, &this->attribute->provider);
hydra->attributes->remove_handler(hydra->attributes, &this->handler->handler);
charon->attributes->remove_provider(charon->attributes,
&this->attribute->provider);
charon->attributes->remove_handler(charon->attributes,
&this->handler->handler);
charon->bus->remove_listener(charon->bus, &this->counter->listener);
this->cred->destroy(this->cred);
this->ca->destroy(this->ca);
@ -790,8 +791,10 @@ stroke_socket_t *stroke_socket_create()
lib->credmgr->add_set(lib->credmgr, &this->ca->set);
lib->credmgr->add_set(lib->credmgr, &this->cred->set);
charon->backends->add_backend(charon->backends, &this->config->backend);
hydra->attributes->add_provider(hydra->attributes, &this->attribute->provider);
hydra->attributes->add_handler(hydra->attributes, &this->handler->handler);
charon->attributes->add_provider(charon->attributes,
&this->attribute->provider);
charon->attributes->add_handler(charon->attributes,
&this->handler->handler);
charon->bus->add_listener(charon->bus, &this->counter->listener);
max_concurrent = lib->settings->get_int(lib->settings,

View File

@ -1,26 +0,0 @@
AM_CPPFLAGS = \
-I$(top_srcdir)/src/libstrongswan \
-I$(top_srcdir)/src/libhydra \
-I$(top_srcdir)/src/libcharon
AM_CFLAGS = \
$(PLUGIN_CFLAGS)
if MONOLITHIC
noinst_LTLIBRARIES = libstrongswan-unit-tester.la
else
plugin_LTLIBRARIES = libstrongswan-unit-tester.la
endif
libstrongswan_unit_tester_la_SOURCES = \
unit_tester.c unit_tester.h tests.h \
tests/test_auth_info.c \
tests/test_curl.c \
tests/test_mysql.c \
tests/test_sqlite.c \
tests/test_cert.c \
tests/test_med_db.c \
tests/test_pool.c \
tests/test_agent.c
libstrongswan_unit_tester_la_LDFLAGS = -module -avoid-version

View File

@ -1,67 +0,0 @@
/*
* Copyright (C) 2008 Martin Willi
* Hochschule fuer Technik Rapperswil
*
* 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 <library.h>
#include <daemon.h>
/*******************************************************************************
* SSH agent signature creation and verification
******************************************************************************/
bool test_agent()
{
char *path;
chunk_t sig, data = chunk_from_chars(0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08);
private_key_t *private;
public_key_t *public;
path = getenv("SSH_AUTH_SOCK");
if (!path)
{
DBG1(DBG_CFG, "ssh-agent not found.");
return FALSE;
}
private = lib->creds->create(lib->creds, CRED_PRIVATE_KEY, KEY_RSA,
BUILD_AGENT_SOCKET, path, BUILD_END);
if (!private)
{
return FALSE;
}
if (!private->sign(private, SIGN_RSA_EMSA_PKCS1_SHA1, data, &sig))
{
return FALSE;
}
public = private->get_public_key(private);
if (!public)
{
return FALSE;;
}
if (!public->verify(public, SIGN_RSA_EMSA_PKCS1_SHA1, data, sig))
{
return FALSE;
}
free(sig.ptr);
data.ptr[1] = 0x01; /* fake it */
if (public->verify(public, SIGN_RSA_EMSA_PKCS1_SHA1, data, sig))
{
return FALSE;
}
private->destroy(private);
public->destroy(public);
return TRUE;
}

View File

@ -1,140 +0,0 @@
/*
* Copyright (C) 2007 Martin Willi
* Hochschule fuer Technik Rapperswil
*
* 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 <daemon.h>
#include <library.h>
#include <credentials/auth_cfg.h>
static chunk_t certchunk = chunk_from_chars(
0x30,0x82,0x02,0xfa,0x30,0x82,0x01,0xe2,0xa0,0x03,0x02,0x01,0x02,0x02,0x10,0x5a,
0xf2,0x65,0xae,0x78,0xff,0x23,0xde,0xf7,0xa6,0xa3,0x94,0x8c,0x3f,0xa0,0xc1,0x30,
0x0d,0x06,0x09,0x2a,0x86,0x48,0x86,0xf7,0x0d,0x01,0x01,0x05,0x05,0x00,0x30,0x39,
0x31,0x0b,0x30,0x09,0x06,0x03,0x55,0x04,0x06,0x13,0x02,0x43,0x48,0x31,0x19,0x30,
0x17,0x06,0x03,0x55,0x04,0x0a,0x13,0x10,0x4c,0x69,0x6e,0x75,0x78,0x20,0x73,0x74,
0x72,0x6f,0x6e,0x67,0x53,0x77,0x61,0x6e,0x31,0x0f,0x30,0x0d,0x06,0x03,0x55,0x04,
0x03,0x13,0x06,0x6d,0x61,0x72,0x74,0x69,0x6e,0x30,0x1e,0x17,0x0d,0x30,0x37,0x30,
0x34,0x32,0x37,0x30,0x37,0x31,0x34,0x32,0x36,0x5a,0x17,0x0d,0x31,0x32,0x30,0x34,
0x32,0x35,0x30,0x37,0x31,0x34,0x32,0x36,0x5a,0x30,0x39,0x31,0x0b,0x30,0x09,0x06,
0x03,0x55,0x04,0x06,0x13,0x02,0x43,0x48,0x31,0x19,0x30,0x17,0x06,0x03,0x55,0x04,
0x0a,0x13,0x10,0x4c,0x69,0x6e,0x75,0x78,0x20,0x73,0x74,0x72,0x6f,0x6e,0x67,0x53,
0x77,0x61,0x6e,0x31,0x0f,0x30,0x0d,0x06,0x03,0x55,0x04,0x03,0x13,0x06,0x6d,0x61,
0x72,0x74,0x69,0x6e,0x30,0x82,0x01,0x22,0x30,0x0d,0x06,0x09,0x2a,0x86,0x48,0x86,
0xf7,0x0d,0x01,0x01,0x01,0x05,0x00,0x03,0x82,0x01,0x0f,0x00,0x30,0x82,0x01,0x0a,
0x02,0x82,0x01,0x01,0x00,0xd7,0xb9,0xba,0x4d,0xe2,0x3b,0x3d,0x35,0x7a,0x3f,0x88,
0x67,0x95,0xe7,0xfd,0x9f,0xe9,0x0a,0x0d,0x79,0x3a,0x9e,0x21,0x8f,0xcb,0xe4,0x67,
0x24,0xae,0x0c,0xda,0xb3,0xcc,0xec,0x36,0xb4,0xa8,0x4d,0xf1,0x3d,0xad,0xe4,0x8c,
0x63,0x92,0x54,0xb7,0xb2,0x02,0xa2,0x00,0x62,0x8b,0x04,0xac,0xa0,0x17,0xad,0x17,
0x9a,0x05,0x0d,0xd7,0xb3,0x08,0x02,0xc5,0x26,0xcf,0xdd,0x05,0x42,0xfc,0x13,0x6d,
0x9f,0xb1,0xf3,0x4f,0x82,0x1d,0xef,0x01,0xc9,0x91,0xea,0x37,0x1b,0x79,0x28,0xfa,
0xbf,0x9f,0xb3,0xeb,0x82,0x4f,0x10,0xc6,0x4b,0xa4,0x08,0xf7,0x8e,0xf2,0x00,0xea,
0x04,0x97,0x80,0x9f,0x65,0x86,0xde,0x6b,0xc7,0xda,0x83,0xfc,0xad,0x4a,0xaf,0x52,
0x8b,0x4d,0x33,0xee,0x49,0x87,0x2f,0x3b,0x60,0x45,0x66,0x8f,0xe6,0x89,0xcc,0xb1,
0x92,0x02,0x17,0x2b,0x7b,0x8e,0x90,0x47,0x84,0x84,0x59,0x95,0x81,0xd8,0xe0,0xf3,
0x87,0xe0,0x04,0x09,0xfd,0xcc,0x3a,0x21,0x34,0xfa,0xec,0xbe,0xf5,0x9c,0xcf,0x55,
0x80,0x7b,0xe3,0x75,0x9d,0x36,0x68,0xab,0x83,0xe3,0xad,0x01,0x53,0x0d,0x8a,0x9a,
0xa6,0xb0,0x15,0xc9,0xc5,0xf8,0x9b,0x51,0x32,0xcf,0x97,0x6c,0xfe,0x4a,0x56,0x3c,
0xc8,0x8f,0x4a,0x70,0x23,0x4f,0xf6,0xf7,0xe6,0x9f,0x09,0xcd,0x8f,0xea,0x20,0x7d,
0x34,0xc0,0xc5,0xc0,0x34,0x06,0x6f,0x8b,0xeb,0x04,0x54,0x3f,0x0e,0xcd,0xe2,0x85,
0xab,0x94,0x3e,0x91,0x6c,0x18,0x6f,0x96,0x5d,0xf2,0x8b,0x10,0xe9,0x90,0x43,0xb0,
0x61,0x52,0xac,0xcf,0x75,0x02,0x03,0x01,0x00,0x01,0x30,0x0d,0x06,0x09,0x2a,0x86,
0x48,0x86,0xf7,0x0d,0x01,0x01,0x05,0x05,0x00,0x03,0x82,0x01,0x01,0x00,0x09,0x63,
0x42,0xad,0xe5,0xa3,0xf6,0xc9,0x5d,0x08,0xf2,0x78,0x7b,0xeb,0x8a,0xef,0x50,0x00,
0xc8,0xeb,0xe9,0x26,0x94,0xcb,0x84,0x10,0x7e,0x42,0x6b,0x86,0x38,0x57,0xa6,0x02,
0x98,0x5a,0x2c,0x8f,0x44,0x32,0x1b,0x97,0x8c,0x7e,0x4b,0xd8,0xe8,0xe8,0x0f,0x4a,
0xb9,0x31,0x9f,0xf6,0x9f,0x0e,0x67,0x26,0x05,0x2a,0x99,0x14,0x35,0x41,0x47,0x9a,
0xfa,0x12,0x94,0x0b,0xe9,0x27,0x7c,0x71,0x20,0xd7,0x8d,0x3b,0x97,0x19,0x2d,0x15,
0xff,0xa4,0xf3,0x89,0x8d,0x29,0x5f,0xf6,0x3f,0x93,0xaf,0x78,0x61,0xe4,0xe1,0x2e,
0x75,0xc1,0x2c,0xc4,0x76,0x95,0x19,0xf8,0x37,0xdc,0xd8,0x00,0x7a,0x3c,0x0f,0x49,
0x2e,0x88,0x09,0x16,0xb3,0x92,0x33,0xdf,0x77,0x83,0x4f,0xb5,0x9e,0x30,0x8c,0x48,
0x1d,0xd8,0x84,0xfb,0xf1,0xb9,0xa0,0xbe,0x25,0xff,0x4c,0xeb,0xef,0x2b,0xcd,0xfa,
0x0b,0x94,0x66,0x3b,0x28,0x08,0x3f,0x3a,0xda,0x41,0xd0,0x6b,0xab,0x5e,0xbb,0x8a,
0x9f,0xdc,0x98,0x3e,0x59,0x37,0x48,0xbe,0x69,0xde,0x85,0x82,0xf2,0x53,0x8b,0xe4,
0x44,0xe4,0x71,0x91,0x14,0x85,0x0e,0x1e,0x79,0xdd,0x62,0xf5,0xdc,0x25,0x89,0xab,
0x50,0x5b,0xaa,0xae,0xe3,0x64,0x6a,0x23,0x34,0xd7,0x30,0xe2,0x2a,0xc8,0x81,0x0c,
0xec,0xd2,0x31,0xc6,0x1e,0xb6,0xc0,0x57,0xd9,0xe1,0x14,0x06,0x9b,0xf8,0x51,0x69,
0x47,0xf0,0x9c,0xcd,0x69,0xef,0x8e,0x5f,0x62,0xda,0x10,0xf7,0x3c,0x6d,0x0f,0x33,
0xec,0x6f,0xfd,0x94,0x07,0x16,0x41,0x32,0x06,0xa4,0xe1,0x08,0x31,0x87,
);
/*******************************************************************************
* auth info test
******************************************************************************/
bool test_auth_cfg()
{
auth_cfg_t *auth = auth_cfg_create(), *auth2;
certificate_t *c1, *c2;
enumerator_t *enumerator;
int round = 0;
void *value;
auth_rule_t type;
c1 = lib->creds->create(lib->creds, CRED_CERTIFICATE, CERT_X509,
BUILD_BLOB_ASN1_DER, certchunk,
BUILD_END);
if (!c1)
{
return FALSE;
}
auth->add(auth, AUTH_RULE_SUBJECT_CERT, c1->get_ref(c1));
c2 = auth->get(auth, AUTH_RULE_SUBJECT_CERT);
if (!c2)
{
return FALSE;
}
if (!c1->equals(c1, c2))
{
return FALSE;
}
enumerator = auth->create_enumerator(auth);
while (enumerator->enumerate(enumerator, &type, &value))
{
round++;
if (round == 1 && type == AUTH_RULE_SUBJECT_CERT && value == c1)
{
continue;
}
return FALSE;
}
enumerator->destroy(enumerator);
auth2 = auth_cfg_create();
auth2->add(auth2, AUTH_RULE_CA_CERT, c1->get_ref(c1));
auth2->merge(auth2, auth, FALSE);
round = 0;
enumerator = auth2->create_enumerator(auth2);
while (enumerator->enumerate(enumerator, &type, &value))
{
round++;
if (round == 1 && type == AUTH_RULE_CA_CERT && value == c1)
{
continue;
}
if (round == 2 && type == AUTH_RULE_SUBJECT_CERT && value == c1)
{
continue;
}
return FALSE;
}
enumerator->destroy(enumerator);
auth->destroy(auth);
auth2->destroy(auth2);
c1->destroy(c1);
return TRUE;
}

View File

@ -1,108 +0,0 @@
/*
* Copyright (C) 2008 Martin Willi
* Hochschule fuer Technik Rapperswil
*
* 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 <library.h>
#include <daemon.h>
#include <credentials/certificates/x509.h>
/*******************************************************************************
* X509 certificate generation and parsing
******************************************************************************/
bool test_cert_x509()
{
private_key_t *ca_key, *peer_key;
public_key_t *public;
certificate_t *ca_cert, *peer_cert, *parsed;
identification_t *issuer, *subject;
u_int32_t serial = htonl(0);
chunk_t encoding;
issuer = identification_create_from_string("CN=CA, OU=Test, O=strongSwan");
subject = identification_create_from_string("CN=Peer, OU=Test, O=strongSwan");
ca_key = lib->creds->create(lib->creds, CRED_PRIVATE_KEY, KEY_RSA,
BUILD_KEY_SIZE, 1024, BUILD_END);
peer_key = lib->creds->create(lib->creds, CRED_PRIVATE_KEY, KEY_RSA,
BUILD_KEY_SIZE, 1024, BUILD_END);
if (!ca_key)
{
return FALSE;
}
ca_cert = lib->creds->create(lib->creds, CRED_CERTIFICATE, CERT_X509,
BUILD_SIGNING_KEY, ca_key,
BUILD_SUBJECT, issuer,
BUILD_SERIAL, chunk_from_thing(serial),
BUILD_X509_FLAG, X509_CA,
BUILD_END);
if (!ca_cert)
{
return FALSE;
}
ca_cert->get_encoding(ca_cert, CERT_ASN1_DER, &encoding);
parsed = lib->creds->create(lib->creds, CRED_CERTIFICATE, CERT_X509,
BUILD_BLOB_ASN1_DER, encoding,
BUILD_END);
chunk_free(&encoding);
if (!parsed)
{
return FALSE;
}
if (!parsed->issued_by(parsed, ca_cert, NULL))
{
return FALSE;
}
parsed->destroy(parsed);
serial = htonl(ntohl(serial) + 1);
public = peer_key->get_public_key(peer_key);
peer_cert = lib->creds->create(lib->creds, CRED_CERTIFICATE, CERT_X509,
BUILD_SIGNING_KEY, ca_key,
BUILD_SIGNING_CERT, ca_cert,
BUILD_PUBLIC_KEY, public,
BUILD_SUBJECT, subject,
BUILD_SERIAL, chunk_from_thing(serial),
BUILD_END);
public->destroy(public);
if (!peer_cert)
{
return FALSE;
}
peer_cert->get_encoding(peer_cert, CERT_ASN1_DER, &encoding);
parsed = lib->creds->create(lib->creds, CRED_CERTIFICATE, CERT_X509,
BUILD_BLOB_ASN1_DER, encoding,
BUILD_END);
chunk_free(&encoding);
if (!parsed)
{
return FALSE;
}
if (!parsed->issued_by(parsed, ca_cert, NULL))
{
return FALSE;
}
parsed->destroy(parsed);
ca_cert->destroy(ca_cert);
ca_key->destroy(ca_key);
peer_cert->destroy(peer_cert);
peer_key->destroy(peer_key);
issuer->destroy(issuer);
subject->destroy(subject);
return TRUE;
}

View File

@ -1,44 +0,0 @@
/*
* Copyright (C) 2007 Martin Willi
* Hochschule fuer Technik Rapperswil
*
* 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 <daemon.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>
/*******************************************************************************
* curl get test
******************************************************************************/
bool test_curl_get()
{
chunk_t chunk;
if (lib->fetcher->fetch(lib->fetcher, "http://www.strongswan.org",
&chunk, FETCH_END) != SUCCESS)
{
return FALSE;
}
free(chunk.ptr);
if (lib->fetcher->fetch(lib->fetcher, "http://www.google.com",
&chunk, FETCH_END) != SUCCESS)
{
return FALSE;
}
free(chunk.ptr);
return TRUE;
}

View File

@ -1,54 +0,0 @@
/*
* Copyright (C) 2008 Martin Willi
* Hochschule fuer Technik Rapperswil
*
* 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 <library.h>
#include <daemon.h>
#include <collections/enumerator.h>
#include <unistd.h>
/*******************************************************************************
* fetch public key from mediation database
******************************************************************************/
bool test_med_db()
{
chunk_t found, keyid = chunk_from_chars(
0xed,0x90,0xe6,0x4f,0xec,0xa2,0x1f,0x4b,
0x68,0x97,0x99,0x24,0x22,0xe0,0xde,0x21,
0xb9,0xd6,0x26,0x29
);
identification_t *id;
enumerator_t *enumerator;
public_key_t *public;
auth_cfg_t *auth;
bool good = FALSE;
id = identification_create_from_encoding(ID_KEY_ID, keyid);
enumerator = lib->credmgr->create_public_enumerator(lib->credmgr,
KEY_ANY, id, NULL);
while (enumerator->enumerate(enumerator, &public, &auth))
{
good = public->get_fingerprint(public, KEYID_PUBKEY_SHA1, &found);
if (good)
{
good = chunk_equals(id->get_encoding(id), found);
}
}
enumerator->destroy(enumerator);
id->destroy(id);
return good;
}

View File

@ -1,89 +0,0 @@
/*
* Copyright (C) 2008 Martin Willi
* Hochschule fuer Technik Rapperswil
*
* 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 <library.h>
#include <daemon.h>
#include <collections/enumerator.h>
/*******************************************************************************
* mysql simple test
******************************************************************************/
bool test_mysql()
{
database_t *db;
char *txt = "I'm a superduper test";
chunk_t data = chunk_from_chars(0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08);
int row;
chunk_t qdata;
char *qtxt;
bool good = FALSE;
enumerator_t *enumerator;
db = lib->db->create(lib->db, "mysql://testuser:testpass@localhost/test");
if (!db)
{
return FALSE;
}
if (db->execute(db, NULL, "CREATE TABLE test ("
"id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, "
"txt TEXT, data BLOB)") < 0)
{
return FALSE;
}
if (db->execute(db, &row, "INSERT INTO test (txt, data) VALUES (?,?)",
DB_TEXT, txt, DB_BLOB, data) < 0)
{
return FALSE;
}
if (row != 1)
{
return FALSE;
}
enumerator = db->query(db, "SELECT txt, data FROM test WHERE id = ?",
DB_INT, row,
DB_TEXT, DB_BLOB);
if (!enumerator)
{
return FALSE;
}
while (enumerator->enumerate(enumerator, &qtxt, &qdata))
{
if (good)
{ /* only one row */
good = FALSE;
break;
}
if (streq(qtxt, txt) && chunk_equals(data, qdata))
{
good = TRUE;
}
}
enumerator->destroy(enumerator);
if (!good)
{
return FALSE;
}
if (db->execute(db, NULL, "DELETE FROM test WHERE id = ?", DB_INT, row) != 1)
{
return FALSE;
}
if (db->execute(db, NULL, "DROP TABLE test") < 0)
{
return FALSE;
}
db->destroy(db);
return TRUE;
}

View File

@ -1,100 +0,0 @@
/*
* Copyright (C) 2008 Martin Willi
* Hochschule fuer Technik Rapperswil
*
* 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 <time.h>
#include <library.h>
#include <threading/thread.h>
#include <hydra.h>
#define ALLOCS 1000
#define THREADS 20
static void* testing(void *thread)
{
int i;
host_t *addr[ALLOCS];
identification_t *id[ALLOCS];
linked_list_t *pools;
/* prepare identities */
for (i = 0; i < ALLOCS; i++)
{
char buf[256];
snprintf(buf, sizeof(buf), "%d-%d@strongswan.org", (uintptr_t)thread, i);
id[i] = identification_create_from_string(buf);
}
pools = linked_list_create();
pools->insert_last(pools, "test");
/* allocate addresses */
for (i = 0; i < ALLOCS; i++)
{
addr[i] = hydra->attributes->acquire_address(hydra->attributes,
pools, id[i], NULL);
if (!addr[i])
{
pools->destroy(pools);
return (void*)FALSE;
}
}
/* release addresses */
for (i = 0; i < ALLOCS; i++)
{
hydra->attributes->release_address(hydra->attributes,
pools, addr[i], id[i]);
}
pools->destroy(pools);
/* cleanup */
for (i = 0; i < ALLOCS; i++)
{
addr[i]->destroy(addr[i]);
id[i]->destroy(id[i]);
}
return (void*)TRUE;
}
/*******************************************************************************
* SQL pool performance test
******************************************************************************/
bool test_pool()
{
thread_t *threads[THREADS];
uintptr_t i;
for (i = 0; i < THREADS; i++)
{
if (!(threads[i] = thread_create((thread_main_t)testing, (void*)i)))
{
return FALSE;
}
}
for (i = 0; i < THREADS; i++)
{
bool *res = threads[i]->join(threads[i]);
if (!res)
{
return FALSE;
}
}
return TRUE;
}

View File

@ -1,93 +0,0 @@
/*
* Copyright (C) 2008 Martin Willi
* Hochschule fuer Technik Rapperswil
*
* 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 <library.h>
#include <daemon.h>
#include <collections/enumerator.h>
#include <unistd.h>
#define DBFILE "/tmp/strongswan-test.db"
/*******************************************************************************
* sqlite simple test
******************************************************************************/
bool test_sqlite()
{
database_t *db;
char *txt = "I'm a superduper test";
chunk_t data = chunk_from_chars(0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08);
int row;
chunk_t qdata;
char *qtxt;
bool good = FALSE;
enumerator_t *enumerator;
db = lib->db->create(lib->db, "sqlite://" DBFILE);
if (!db)
{
return FALSE;
}
if (db->execute(db, NULL, "CREATE TABLE test (txt TEXT, data BLOB)") < 0)
{
return FALSE;
}
if (db->execute(db, &row, "INSERT INTO test (txt, data) VALUES (?,?)",
DB_TEXT, txt, DB_BLOB, data) < 0)
{
return FALSE;
}
if (row != 1)
{
return FALSE;
}
enumerator = db->query(db, "SELECT txt, data FROM test WHERE oid = ?",
DB_INT, row,
DB_TEXT, DB_BLOB);
if (!enumerator)
{
return FALSE;
}
while (enumerator->enumerate(enumerator, &qtxt, &qdata))
{
if (good)
{ /* only one row */
good = FALSE;
break;
}
if (streq(qtxt, txt) && chunk_equals(data, qdata))
{
good = TRUE;
}
}
enumerator->destroy(enumerator);
if (!good)
{
return FALSE;
}
if (db->execute(db, NULL, "DELETE FROM test WHERE oid = ?", DB_INT, row) != 1)
{
return FALSE;
}
if (db->execute(db, NULL, "DROP TABLE test") < 0)
{
return FALSE;
}
db->destroy(db);
unlink(DBFILE);
return TRUE;
}

View File

@ -1,152 +0,0 @@
/*
* Copyright (C) 2013 Tobias Brunner
* Copyright (C) 2007 Martin Willi
* Hochschule fuer Technik Rapperswil
*
* 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 "unit_tester.h"
#include <daemon.h>
typedef struct private_unit_tester_t private_unit_tester_t;
typedef struct unit_test_t unit_test_t;
typedef enum test_status_t test_status_t;
/**
* private data of unit_tester
*/
struct private_unit_tester_t {
/**
* public functions
*/
unit_tester_t public;
};
struct unit_test_t {
/**
* name of the test
*/
char *name;
/**
* test function
*/
bool (*test)(void);
/**
* run the test?
*/
bool enabled;
};
#undef DEFINE_TEST
#define DEFINE_TEST(name, function, enabled) bool function();
#include <plugins/unit_tester/tests.h>
#undef DEFINE_TEST
#define DEFINE_TEST(name, function, enabled) {name, function, enabled},
static unit_test_t tests[] = {
#include <plugins/unit_tester/tests.h>
};
static void run_tests(private_unit_tester_t *this)
{
int i, run = 0, failed = 0, success = 0, skipped = 0;
DBG1(DBG_CFG, "running unit tests, %d tests registered",
sizeof(tests)/sizeof(unit_test_t));
for (i = 0; i < sizeof(tests)/sizeof(unit_test_t); i++)
{
if (tests[i].enabled)
{
run++;
if (tests[i].test())
{
DBG1(DBG_CFG, "test '%s' successful", tests[i].name);
success++;
}
else
{
DBG1(DBG_CFG, "test '%s' failed", tests[i].name);
failed++;
}
}
else
{
DBG1(DBG_CFG, "test '%s' disabled", tests[i].name);
skipped++;
}
}
DBG1(DBG_CFG, "%d/%d tests successful (%d failed, %d disabled)",
success, run, failed, skipped);
}
METHOD(plugin_t, get_name, char*,
private_unit_tester_t *this)
{
return "unit-tester";
}
/**
* We currently don't depend explicitly on any plugin features. But in case
* activated tests depend on such features we at least try to run them in plugin
* order.
*/
static bool plugin_cb(private_unit_tester_t *this,
plugin_feature_t *feature, bool reg, void *cb_data)
{
if (reg)
{
run_tests(this);
}
return TRUE;
}
METHOD(plugin_t, get_features, int,
private_unit_tester_t *this, plugin_feature_t *features[])
{
static plugin_feature_t f[] = {
PLUGIN_CALLBACK((plugin_feature_callback_t)plugin_cb, NULL),
PLUGIN_PROVIDE(CUSTOM, "unit-tester"),
};
*features = f;
return countof(f);
}
METHOD(plugin_t, destroy, void,
private_unit_tester_t *this)
{
free(this);
}
/*
* see header file
*/
plugin_t *unit_tester_plugin_create()
{
private_unit_tester_t *this;
INIT(this,
.public = {
.plugin = {
.get_name = _get_name,
.get_features = _get_features,
.destroy = _destroy,
},
},
);
return &this->public.plugin;
}

View File

@ -1,44 +0,0 @@
/*
* Copyright (C) 2007 Martin Willi
* Hochschule fuer Technik Rapperswil
*
* 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 unit_tester unit_tester
* @{ @ingroup cplugins
*/
#ifndef UNIT_TESTER_H_
#define UNIT_TESTER_H_
#include <plugins/plugin.h>
typedef struct unit_tester_t unit_tester_t;
/**
* Unit testing plugin.
*
* The unit testing plugin runs tests on plugin initialization. Tests are
* defined in tests.h using the DEFINE_TEST macro. Implementation of the
* tests is done in the tests folder. Each test has uses a function which
* returns TRUE for success or FALSE for failure.
*/
struct unit_tester_t {
/**
* Implements the plugin interface.
*/
plugin_t plugin;
};
#endif /** UNIT_TESTER_H_ @}*/

View File

@ -317,7 +317,7 @@ static bool remove_exclude(private_unity_handler_t *this, chunk_t data)
}
METHOD(attribute_handler_t, handle, bool,
private_unity_handler_t *this, identification_t *id,
private_unity_handler_t *this, ike_sa_t *ike_sa,
configuration_attribute_type_t type, chunk_t data)
{
switch (type)
@ -332,7 +332,7 @@ METHOD(attribute_handler_t, handle, bool,
}
METHOD(attribute_handler_t, release, void,
private_unity_handler_t *this, identification_t *server,
private_unity_handler_t *this, ike_sa_t *ike_sa,
configuration_attribute_type_t type, chunk_t data)
{
switch (type)
@ -380,10 +380,9 @@ METHOD(enumerator_t, enumerate_attributes, bool,
}
METHOD(attribute_handler_t, create_attribute_enumerator, enumerator_t *,
unity_handler_t *this, identification_t *id, linked_list_t *vips)
unity_handler_t *this, ike_sa_t *ike_sa, linked_list_t *vips)
{
attribute_enumerator_t *enumerator;
ike_sa_t *ike_sa;
ike_sa = charon->bus->get_sa(charon->bus);
if (!ike_sa || ike_sa->get_version(ike_sa) != IKEV1 ||

View File

@ -19,7 +19,6 @@
#include "unity_provider.h"
#include <daemon.h>
#include <hydra.h>
typedef struct private_unity_plugin_t private_unity_plugin_t;
@ -63,19 +62,19 @@ static bool plugin_cb(private_unity_plugin_t *this,
{
if (reg)
{
hydra->attributes->add_handler(hydra->attributes,
&this->handler->handler);
hydra->attributes->add_provider(hydra->attributes,
&this->provider->provider);
charon->attributes->add_handler(charon->attributes,
&this->handler->handler);
charon->attributes->add_provider(charon->attributes,
&this->provider->provider);
charon->bus->add_listener(charon->bus, &this->narrower->listener);
}
else
{
charon->bus->remove_listener(charon->bus, &this->narrower->listener);
hydra->attributes->remove_handler(hydra->attributes,
&this->handler->handler);
hydra->attributes->remove_provider(hydra->attributes,
&this->provider->provider);
charon->attributes->remove_handler(charon->attributes,
&this->handler->handler);
charon->attributes->remove_provider(charon->attributes,
&this->provider->provider);
}
return TRUE;

View File

@ -135,19 +135,17 @@ static bool use_ts(traffic_selector_t *ts)
}
METHOD(attribute_provider_t, create_attribute_enumerator, enumerator_t*,
private_unity_provider_t *this, linked_list_t *pools, identification_t *id,
private_unity_provider_t *this, linked_list_t *pools, ike_sa_t *ike_sa,
linked_list_t *vips)
{
attribute_enumerator_t *attr_enum;
enumerator_t *enumerator;
linked_list_t *list, *current;
traffic_selector_t *ts;
ike_sa_t *ike_sa;
peer_cfg_t *peer_cfg;
child_cfg_t *child_cfg;
ike_sa = charon->bus->get_sa(charon->bus);
if (!ike_sa || ike_sa->get_version(ike_sa) != IKEV1 ||
if (ike_sa->get_version(ike_sa) != IKEV1 ||
!ike_sa->supports_extension(ike_sa, EXT_CISCO_UNITY) ||
!vips->get_count(vips))
{

View File

@ -62,19 +62,13 @@ static void attributes_destroy(attributes_t *this)
}
METHOD(attribute_handler_t, handle, bool,
private_updown_handler_t *this, identification_t *server,
private_updown_handler_t *this, ike_sa_t *ike_sa,
configuration_attribute_type_t type, chunk_t data)
{
attributes_t *current, *attr = NULL;
enumerator_t *enumerator;
ike_sa_t *ike_sa;
host_t *host;
ike_sa = charon->bus->get_sa(charon->bus);
if (!ike_sa)
{
return FALSE;
}
switch (type)
{
case INTERNAL_IP4_DNS:
@ -117,12 +111,11 @@ METHOD(attribute_handler_t, handle, bool,
}
METHOD(attribute_handler_t, release, void,
private_updown_handler_t *this, identification_t *server,
private_updown_handler_t *this, ike_sa_t *ike_sa,
configuration_attribute_type_t type, chunk_t data)
{
attributes_t *attr;
enumerator_t *enumerator, *servers;
ike_sa_t *ike_sa;
host_t *host;
bool found = FALSE;
int family;
@ -139,43 +132,39 @@ METHOD(attribute_handler_t, release, void,
return;
}
ike_sa = charon->bus->get_sa(charon->bus);
if (ike_sa)
this->lock->write_lock(this->lock);
enumerator = this->attrs->create_enumerator(this->attrs);
while (enumerator->enumerate(enumerator, &attr))
{
this->lock->write_lock(this->lock);
enumerator = this->attrs->create_enumerator(this->attrs);
while (enumerator->enumerate(enumerator, &attr))
if (attr->id == ike_sa->get_unique_id(ike_sa))
{
if (attr->id == ike_sa->get_unique_id(ike_sa))
servers = attr->dns->create_enumerator(attr->dns);
while (servers->enumerate(servers, &host))
{
servers = attr->dns->create_enumerator(attr->dns);
while (servers->enumerate(servers, &host))
if (host->get_family(host) == family &&
chunk_equals(data, host->get_address(host)))
{
if (host->get_family(host) == family &&
chunk_equals(data, host->get_address(host)))
{
attr->dns->remove_at(attr->dns, servers);
host->destroy(host);
found = TRUE;
break;
}
}
servers->destroy(servers);
if (attr->dns->get_count(attr->dns) == 0)
{
this->attrs->remove_at(this->attrs, enumerator);
attributes_destroy(attr);
attr->dns->remove_at(attr->dns, servers);
host->destroy(host);
found = TRUE;
break;
}
}
if (found)
servers->destroy(servers);
if (attr->dns->get_count(attr->dns) == 0)
{
this->attrs->remove_at(this->attrs, enumerator);
attributes_destroy(attr);
break;
}
}
enumerator->destroy(enumerator);
this->lock->unlock(this->lock);
if (found)
{
break;
}
}
enumerator->destroy(enumerator);
this->lock->unlock(this->lock);
}
METHOD(updown_handler_t, create_dns_enumerator, enumerator_t*,

View File

@ -18,7 +18,6 @@
#include "updown_handler.h"
#include <daemon.h>
#include <hydra.h>
typedef struct private_updown_plugin_t private_updown_plugin_t;
@ -61,8 +60,8 @@ static bool plugin_cb(private_updown_plugin_t *this,
"%s.plugins.updown.dns_handler", FALSE, lib->ns))
{
this->handler = updown_handler_create();
hydra->attributes->add_handler(hydra->attributes,
&this->handler->handler);
charon->attributes->add_handler(charon->attributes,
&this->handler->handler);
}
this->listener = updown_listener_create(this->handler);
charon->bus->add_listener(charon->bus, &this->listener->listener);
@ -74,8 +73,8 @@ static bool plugin_cb(private_updown_plugin_t *this,
if (this->handler)
{
this->handler->destroy(this->handler);
hydra->attributes->remove_handler(hydra->attributes,
&this->handler->handler);
charon->attributes->remove_handler(charon->attributes,
&this->handler->handler);
}
}
return TRUE;

View File

@ -122,11 +122,14 @@ static host_t *find_addr(private_vici_attribute_t *this, linked_list_t *pools,
}
METHOD(attribute_provider_t, acquire_address, host_t*,
private_vici_attribute_t *this, linked_list_t *pools, identification_t *id,
private_vici_attribute_t *this, linked_list_t *pools, ike_sa_t *ike_sa,
host_t *requested)
{
identification_t *id;
host_t *addr;
id = ike_sa->get_other_eap_id(ike_sa);
this->lock->read_lock(this->lock);
addr = find_addr(this, pools, id, requested, MEM_POOL_EXISTING);
@ -146,13 +149,16 @@ METHOD(attribute_provider_t, acquire_address, host_t*,
METHOD(attribute_provider_t, release_address, bool,
private_vici_attribute_t *this, linked_list_t *pools, host_t *address,
identification_t *id)
ike_sa_t *ike_sa)
{
enumerator_t *enumerator;
identification_t *id;
bool found = FALSE;
pool_t *pool;
char *name;
id = ike_sa->get_other_eap_id(ike_sa);
this->lock->read_lock(this->lock);
enumerator = pools->create_enumerator(pools);
@ -259,7 +265,7 @@ static bool have_vips_from_pool(mem_pool_t *pool, linked_list_t *vips)
METHOD(attribute_provider_t, create_attribute_enumerator, enumerator_t*,
private_vici_attribute_t *this, linked_list_t *pools,
identification_t *id, linked_list_t *vips)
ike_sa_t *ike_sa, linked_list_t *vips)
{
enumerator_t *enumerator;
nested_data_t *data;

View File

@ -23,7 +23,6 @@
#include "vici_logger.h"
#include <library.h>
#include <hydra.h>
#include <daemon.h>
typedef struct private_vici_plugin_t private_vici_plugin_t;
@ -104,8 +103,8 @@ static bool register_vici(private_vici_plugin_t *this,
charon->backends->add_backend(charon->backends,
&this->config->backend);
hydra->attributes->add_provider(hydra->attributes,
&this->attrs->provider);
charon->attributes->add_provider(charon->attributes,
&this->attrs->provider);
charon->bus->add_logger(charon->bus, &this->logger->logger);
return TRUE;
}
@ -114,8 +113,8 @@ static bool register_vici(private_vici_plugin_t *this,
else
{
charon->bus->remove_logger(charon->bus, &this->logger->logger);
hydra->attributes->remove_provider(hydra->attributes,
&this->attrs->provider);
charon->attributes->remove_provider(charon->attributes,
&this->attrs->provider);
charon->backends->remove_backend(charon->backends,
&this->config->backend);

View File

@ -2346,8 +2346,8 @@ METHOD(ike_sa_t, destroy, void,
{
if (entry.handler)
{
hydra->attributes->release(hydra->attributes, entry.handler,
this->other_id, entry.type, entry.data);
charon->attributes->release(charon->attributes, entry.handler,
&this->public, entry.type, entry.data);
}
free(entry.data.ptr);
}
@ -2372,12 +2372,11 @@ METHOD(ike_sa_t, destroy, void,
if (this->peer_cfg)
{
linked_list_t *pools;
identification_t *id;
id = get_other_eap_id(this);
pools = linked_list_create_from_enumerator(
this->peer_cfg->create_pool_enumerator(this->peer_cfg));
hydra->attributes->release_address(hydra->attributes, pools, vip, id);
charon->attributes->release_address(charon->attributes,
pools, vip, &this->public);
pools->destroy(pools);
}
vip->destroy(vip);

View File

@ -16,7 +16,6 @@
#include "mode_config.h"
#include <daemon.h>
#include <hydra.h>
#include <encoding/payloads/cp_payload.h>
typedef struct private_mode_config_t private_mode_config_t;
@ -136,9 +135,8 @@ static void handle_attribute(private_mode_config_t *this,
enumerator->destroy(enumerator);
/* and pass it to the handle function */
handler = hydra->attributes->handle(hydra->attributes,
this->ike_sa->get_other_id(this->ike_sa), handler,
ca->get_type(ca), ca->get_chunk(ca));
handler = charon->attributes->handle(charon->attributes,
this->ike_sa, handler, ca->get_type(ca), ca->get_chunk(ca));
this->ike_sa->add_configuration_attribute(this->ike_sa,
handler, ca->get_type(ca), ca->get_chunk(ca));
}
@ -326,9 +324,8 @@ static status_t build_request(private_mode_config_t *this, message_t *message)
enumerator->destroy(enumerator);
}
enumerator = hydra->attributes->create_initiator_enumerator(
hydra->attributes,
this->ike_sa->get_other_id(this->ike_sa), vips);
enumerator = charon->attributes->create_initiator_enumerator(
charon->attributes, this->ike_sa, vips);
while (enumerator->enumerate(enumerator, &handler, &type, &data))
{
add_attribute(this, cp, type, data, handler);
@ -372,12 +369,12 @@ static status_t build_set(private_mode_config_t *this, message_t *message)
{
pools = linked_list_create_with_items(name, NULL);
/* try IPv4, then IPv6 */
found = hydra->attributes->acquire_address(hydra->attributes,
pools, id, any4);
found = charon->attributes->acquire_address(charon->attributes,
pools, this->ike_sa, any4);
if (!found)
{
found = hydra->attributes->acquire_address(hydra->attributes,
pools, id, any6);
found = charon->attributes->acquire_address(charon->attributes,
pools, this->ike_sa, any6);
}
pools->destroy(pools);
if (found)
@ -398,8 +395,8 @@ static status_t build_set(private_mode_config_t *this, message_t *message)
/* query registered providers for additional attributes to include */
pools = linked_list_create_from_enumerator(
config->create_pool_enumerator(config));
enumerator = hydra->attributes->create_responder_enumerator(
hydra->attributes, pools, id, this->vips);
enumerator = charon->attributes->create_responder_enumerator(
charon->attributes, pools, this->ike_sa, this->vips);
while (enumerator->enumerate(enumerator, &type, &value))
{
add_attribute(this, cp, type, value, NULL);
@ -489,8 +486,8 @@ static status_t build_reply(private_mode_config_t *this, message_t *message)
/* query all pools until we get an address */
DBG1(DBG_IKE, "peer requested virtual IP %H", requested);
found = hydra->attributes->acquire_address(hydra->attributes,
pools, id, requested);
found = charon->attributes->acquire_address(charon->attributes,
pools, this->ike_sa, requested);
if (found)
{
DBG1(DBG_IKE, "assigning virtual IP %H to peer '%Y'", found, id);
@ -509,8 +506,8 @@ static status_t build_reply(private_mode_config_t *this, message_t *message)
charon->bus->assign_vips(charon->bus, this->ike_sa, TRUE);
/* query registered providers for additional attributes to include */
enumerator = hydra->attributes->create_responder_enumerator(
hydra->attributes, pools, id, vips);
enumerator = charon->attributes->create_responder_enumerator(
charon->attributes, pools, this->ike_sa, vips);
while (enumerator->enumerate(enumerator, &type, &value))
{
cp->add_attribute(cp,

View File

@ -17,7 +17,6 @@
#include "ike_config.h"
#include <daemon.h>
#include <hydra.h>
#include <encoding/payloads/cp_payload.h>
typedef struct private_ike_config_t private_ike_config_t;
@ -127,9 +126,8 @@ static void handle_attribute(private_ike_config_t *this,
enumerator->destroy(enumerator);
/* and pass it to the handle function */
handler = hydra->attributes->handle(hydra->attributes,
this->ike_sa->get_other_id(this->ike_sa), handler,
ca->get_type(ca), ca->get_chunk(ca));
handler = charon->attributes->handle(charon->attributes,
this->ike_sa, handler, ca->get_type(ca), ca->get_chunk(ca));
this->ike_sa->add_configuration_attribute(this->ike_sa,
handler, ca->get_type(ca), ca->get_chunk(ca));
}
@ -274,9 +272,8 @@ METHOD(task_t, build_i, status_t,
enumerator->destroy(enumerator);
}
enumerator = hydra->attributes->create_initiator_enumerator(
hydra->attributes,
this->ike_sa->get_other_id(this->ike_sa), vips);
enumerator = charon->attributes->create_initiator_enumerator(
charon->attributes, this->ike_sa, vips);
while (enumerator->enumerate(enumerator, &handler, &type, &data))
{
configuration_attribute_t *ca;
@ -352,8 +349,8 @@ METHOD(task_t, build_r, status_t,
/* query all pools until we get an address */
DBG1(DBG_IKE, "peer requested virtual IP %H", requested);
found = hydra->attributes->acquire_address(hydra->attributes,
pools, id, requested);
found = charon->attributes->acquire_address(charon->attributes,
pools, this->ike_sa, requested);
if (found)
{
DBG1(DBG_IKE, "assigning virtual IP %H to peer '%Y'", found, id);
@ -398,8 +395,8 @@ METHOD(task_t, build_r, status_t,
}
/* query registered providers for additional attributes to include */
enumerator = hydra->attributes->create_responder_enumerator(
hydra->attributes, pools, id, vips);
enumerator = charon->attributes->create_responder_enumerator(
charon->attributes, pools, this->ike_sa, vips);
while (enumerator->enumerate(enumerator, &type, &value))
{
if (!cp)

1
src/libcharon/tests/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
libcharon_tests

View File

@ -0,0 +1,21 @@
TESTS = libcharon_tests
check_PROGRAMS = $(TESTS)
libcharon_tests_SOURCES = \
suites/test_mem_pool.c \
libcharon_tests.h libcharon_tests.c
libcharon_tests_CFLAGS = \
-I$(top_srcdir)/src/libcharon \
-I$(top_srcdir)/src/libhydra \
-I$(top_srcdir)/src/libstrongswan \
-I$(top_srcdir)/src/libstrongswan/tests \
@COVERAGE_CFLAGS@
libcharon_tests_LDFLAGS = @COVERAGE_LDFLAGS@
libcharon_tests_LDADD = \
$(top_builddir)/src/libcharon/libcharon.la \
$(top_builddir)/src/libhydra/libhydra.la \
$(top_builddir)/src/libstrongswan/libstrongswan.la \
$(top_builddir)/src/libstrongswan/tests/libtest.la

View File

@ -0,0 +1,56 @@
/*
* Copyright (C) 2014 Martin Willi
* Copyright (C) 2014 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 <test_runner.h>
#include <hydra.h>
#include <daemon.h>
/* declare test suite constructors */
#define TEST_SUITE(x) test_suite_t* x();
#define TEST_SUITE_DEPEND(x, ...) TEST_SUITE(x)
#include "libcharon_tests.h"
#undef TEST_SUITE
#undef TEST_SUITE_DEPEND
static test_configuration_t tests[] = {
#define TEST_SUITE(x) \
{ .suite = x, },
#define TEST_SUITE_DEPEND(x, type, args) \
{ .suite = x, .feature = PLUGIN_DEPENDS(type, args) },
#include "libcharon_tests.h"
{ .suite = NULL, }
};
static bool test_runner_init(bool init)
{
if (init)
{
libhydra_init();
libcharon_init();
}
else
{
lib->processor->set_threads(lib->processor, 0);
lib->processor->cancel(lib->processor);
libcharon_deinit();
libhydra_deinit();
}
return TRUE;
}
int main(int argc, char *argv[])
{
return test_runner_run("libcharon", tests, test_runner_init);
}

View File

@ -1,6 +1,6 @@
/*
* Copyright (C) 2007 Martin Willi
* Hochschule fuer Technik Rapperswil
* Copyright (C) 2014 Martin Willi
* Copyright (C) 2014 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
@ -13,18 +13,4 @@
* for more details.
*/
/**
* @defgroup tests tests
* @{ @ingroup unit_tester
*/
DEFINE_TEST("auth cfg", test_auth_cfg, FALSE)
DEFINE_TEST("CURL get", test_curl_get, FALSE)
DEFINE_TEST("MySQL operations", test_mysql, FALSE)
DEFINE_TEST("SQLite operations", test_sqlite, FALSE)
DEFINE_TEST("X509 certificate", test_cert_x509, FALSE)
DEFINE_TEST("Mediation database key fetch", test_med_db, FALSE)
DEFINE_TEST("IP pool", test_pool, FALSE)
DEFINE_TEST("SSH agent", test_agent, FALSE)
/** @}*/
TEST_SUITE(mem_pool_suite_create)

View File

@ -4,10 +4,6 @@ include $(CLEAR_VARS)
# copy-n-paste from Makefile.am
libhydra_la_SOURCES := \
hydra.c hydra.h \
attributes/attributes.c attributes/attributes.h \
attributes/attribute_provider.h attributes/attribute_handler.h \
attributes/attribute_manager.c attributes/attribute_manager.h \
attributes/mem_pool.c attributes/mem_pool.h \
kernel/kernel_interface.c kernel/kernel_interface.h \
kernel/kernel_ipsec.c kernel/kernel_ipsec.h \
kernel/kernel_net.c kernel/kernel_net.h \
@ -17,8 +13,6 @@ LOCAL_SRC_FILES := $(filter %.c,$(libhydra_la_SOURCES))
# adding the plugin source files
LOCAL_SRC_FILES += $(call add_plugin, attr)
LOCAL_SRC_FILES += $(call add_plugin, kernel-pfkey)
LOCAL_SRC_FILES += $(call add_plugin, kernel-netlink)
@ -42,4 +36,3 @@ LOCAL_PRELINK_MODULE := false
LOCAL_SHARED_LIBRARIES += libstrongswan
include $(BUILD_SHARED_LIBRARY)

View File

@ -2,10 +2,6 @@ ipseclib_LTLIBRARIES = libhydra.la
libhydra_la_SOURCES = \
hydra.c hydra.h \
attributes/attributes.c attributes/attributes.h \
attributes/attribute_provider.h attributes/attribute_handler.h \
attributes/attribute_manager.c attributes/attribute_manager.h \
attributes/mem_pool.c attributes/mem_pool.h \
kernel/kernel_interface.c kernel/kernel_interface.h \
kernel/kernel_ipsec.c kernel/kernel_ipsec.h \
kernel/kernel_net.c kernel/kernel_net.h \
@ -37,20 +33,6 @@ else
SUBDIRS = .
endif
if USE_ATTR
SUBDIRS += plugins/attr
if MONOLITHIC
libhydra_la_LIBADD += plugins/attr/libstrongswan-attr.la
endif
endif
if USE_ATTR_SQL
SUBDIRS += plugins/attr_sql
if MONOLITHIC
libhydra_la_LIBADD += plugins/attr_sql/libstrongswan-attr-sql.la
endif
endif
if USE_KERNEL_PFKEY
SUBDIRS += plugins/kernel_pfkey
if MONOLITHIC
@ -72,13 +54,6 @@ if MONOLITHIC
endif
endif
if USE_RESOLVE
SUBDIRS += plugins/resolve
if MONOLITHIC
libhydra_la_LIBADD += plugins/resolve/libstrongswan-resolve.la
endif
endif
if MONOLITHIC
SUBDIRS += .
endif

View File

@ -57,7 +57,6 @@ void libhydra_deinit()
return;
}
this->public.attributes->destroy(this->public.attributes);
this->public.kernel_interface->destroy(this->public.kernel_interface);
free(this);
hydra = NULL;
@ -78,9 +77,6 @@ bool libhydra_init()
}
INIT(this,
.public = {
.attributes = attribute_manager_create(),
},
.ref = 1,
);
hydra = &this->public;

View File

@ -16,9 +16,6 @@
/**
* @defgroup libhydra libhydra
*
* @defgroup attributes attributes
* @ingroup libhydra
*
* @defgroup hkernel kernel
* @ingroup libhydra
*
@ -34,7 +31,6 @@
typedef struct hydra_t hydra_t;
#include <attributes/attribute_manager.h>
#include <kernel/kernel_interface.h>
#include <library.h>
@ -44,11 +40,6 @@ typedef struct hydra_t hydra_t;
*/
struct hydra_t {
/**
* manager for payload attributes
*/
attribute_manager_t *attributes;
/**
* kernel interface to communicate with kernel
*/

View File

@ -3,7 +3,6 @@ TESTS = hydra_tests
check_PROGRAMS = $(TESTS)
hydra_tests_SOURCES = \
suites/test_mem_pool.c \
hydra_tests.h hydra_tests.c
hydra_tests_CFLAGS = \

View File

@ -12,5 +12,3 @@
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*/
TEST_SUITE(mem_pool_suite_create)

View File

@ -11,11 +11,13 @@ pool.o : $(top_builddir)/config.status
AM_CPPFLAGS = \
-I$(top_srcdir)/src/libstrongswan \
-I$(top_srcdir)/src/libhydra \
-I$(top_srcdir)/src/libcharon \
-DPLUGINS=\""${pool_plugins}\""
pool_LDADD = \
$(top_builddir)/src/libstrongswan/libstrongswan.la \
$(top_builddir)/src/libhydra/libhydra.la
$(top_builddir)/src/libhydra/libhydra.la \
$(top_builddir)/src/libcharon/libcharon.la
endif USE_ATTR_SQL