aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAndreas Steffen <andreas.steffen@strongswan.org>2009-10-13 17:02:29 +0200
committerAndreas Steffen <andreas.steffen@strongswan.org>2009-10-13 17:02:29 +0200
commit247794827e8ac7b7aa5f9dd8eb36d5f35e067e0d (patch)
treeeb44066129b05c38d1604dad729f542d26acf34a /src
parent4c8bb47abdec968a7c242f7f2b002428eb82d97c (diff)
downloadstrongswan-247794827e8ac7b7aa5f9dd8eb36d5f35e067e0d.tar.bz2
strongswan-247794827e8ac7b7aa5f9dd8eb36d5f35e067e0d.tar.xz
move SQL-based pool functionality to new attr-sql libstrongswan plugin
Diffstat (limited to 'src')
-rw-r--r--src/charon/plugins/sql/Makefile.am9
-rw-r--r--src/charon/plugins/sql/sql_plugin.c10
-rw-r--r--src/checksum/Makefile.am4
-rw-r--r--src/libstrongswan/Makefile.am4
-rw-r--r--src/libstrongswan/plugins/attr_sql/Makefile.am15
-rw-r--r--src/libstrongswan/plugins/attr_sql/attr_sql_plugin.c87
-rw-r--r--src/libstrongswan/plugins/attr_sql/attr_sql_plugin.h47
-rw-r--r--src/libstrongswan/plugins/attr_sql/pool.c (renamed from src/charon/plugins/sql/pool.c)4
-rw-r--r--src/libstrongswan/plugins/attr_sql/sql_attribute.c (renamed from src/charon/plugins/sql/sql_attribute.c)17
-rw-r--r--src/libstrongswan/plugins/attr_sql/sql_attribute.h (renamed from src/charon/plugins/sql/sql_attribute.h)0
10 files changed, 169 insertions, 28 deletions
diff --git a/src/charon/plugins/sql/Makefile.am b/src/charon/plugins/sql/Makefile.am
index c6a382c4e..60135bf08 100644
--- a/src/charon/plugins/sql/Makefile.am
+++ b/src/charon/plugins/sql/Makefile.am
@@ -5,11 +5,8 @@ AM_CFLAGS = -rdynamic \
-DPLUGINS=\""${libstrongswan_plugins}\""
plugin_LTLIBRARIES = libstrongswan-sql.la
-libstrongswan_sql_la_SOURCES = sql_plugin.h sql_plugin.c \
- sql_config.h sql_config.c sql_cred.h sql_cred.c \
- sql_attribute.h sql_attribute.c sql_logger.h sql_logger.c
+libstrongswan_sql_la_SOURCES = \
+ sql_plugin.h sql_plugin.c sql_config.h sql_config.c \
+ sql_cred.h sql_cred.c sql_logger.h sql_logger.c
libstrongswan_sql_la_LDFLAGS = -module -avoid-version
-ipsec_PROGRAMS = pool
-pool_SOURCES = pool.c
-pool_LDADD = $(top_builddir)/src/libstrongswan/libstrongswan.la
diff --git a/src/charon/plugins/sql/sql_plugin.c b/src/charon/plugins/sql/sql_plugin.c
index 05cdad559..e2e410a8a 100644
--- a/src/charon/plugins/sql/sql_plugin.c
+++ b/src/charon/plugins/sql/sql_plugin.c
@@ -18,7 +18,6 @@
#include <daemon.h>
#include "sql_config.h"
#include "sql_cred.h"
-#include "sql_attribute.h"
#include "sql_logger.h"
typedef struct private_sql_plugin_t private_sql_plugin_t;
@@ -49,11 +48,6 @@ struct private_sql_plugin_t {
sql_cred_t *cred;
/**
- * CFG attributes
- */
- sql_attribute_t *attribute;
-
- /**
* bus listener/logger
*/
sql_logger_t *logger;
@@ -67,10 +61,8 @@ static void destroy(private_sql_plugin_t *this)
charon->backends->remove_backend(charon->backends, &this->config->backend);
charon->credentials->remove_set(charon->credentials, &this->cred->set);
charon->bus->remove_listener(charon->bus, &this->logger->listener);
- lib->attributes->remove_provider(lib->attributes, &this->attribute->provider);
this->config->destroy(this->config);
this->cred->destroy(this->cred);
- this->attribute->destroy(this->attribute);
this->logger->destroy(this->logger);
this->db->destroy(this->db);
free(this);
@@ -104,10 +96,8 @@ plugin_t *plugin_create()
}
this->config = sql_config_create(this->db);
this->cred = sql_cred_create(this->db);
- this->attribute = sql_attribute_create(this->db);
this->logger = sql_logger_create(this->db);
- lib->attributes->add_provider(lib->attributes, &this->attribute->provider);
charon->backends->add_backend(charon->backends, &this->config->backend);
charon->credentials->add_set(charon->credentials, &this->cred->set);
charon->bus->add_listener(charon->bus, &this->logger->listener);
diff --git a/src/checksum/Makefile.am b/src/checksum/Makefile.am
index 7a8a7a3ca..d0413e64e 100644
--- a/src/checksum/Makefile.am
+++ b/src/checksum/Makefile.am
@@ -29,8 +29,8 @@ if USE_TOOLS
libs += $(top_builddir)/src/scepclient/.libs/scepclient
endif
-if USE_SQL
- libs += $(top_builddir)/src/charon/plugins/sql/.libs/pool
+if USE_ATTR_SQL
+ libs += $(top_builddir)/src/libstrongswan/plugins/attr_sql/.libs/pool
endif
checksum.c : checksum_builder $(libs)
diff --git a/src/libstrongswan/Makefile.am b/src/libstrongswan/Makefile.am
index b95658857..d8d027e8e 100644
--- a/src/libstrongswan/Makefile.am
+++ b/src/libstrongswan/Makefile.am
@@ -200,6 +200,10 @@ if USE_SQLITE
SUBDIRS += plugins/sqlite
endif
+if USE_ATTR_SQL
+ SUBDIRS += plugins/attr_sql
+endif
+
if USE_PADLOCK
SUBDIRS += plugins/padlock
endif
diff --git a/src/libstrongswan/plugins/attr_sql/Makefile.am b/src/libstrongswan/plugins/attr_sql/Makefile.am
new file mode 100644
index 000000000..5be310abf
--- /dev/null
+++ b/src/libstrongswan/plugins/attr_sql/Makefile.am
@@ -0,0 +1,15 @@
+
+INCLUDES = -I$(top_srcdir)/src/libstrongswan
+
+AM_CFLAGS = -rdynamic \
+ -DPLUGINS=\""${libstrongswan_plugins}\""
+
+plugin_LTLIBRARIES = libstrongswan-attr-sql.la
+libstrongswan_attr_sql_la_SOURCES = \
+ attr_sql_plugin.h attr_sql_plugin.c \
+ sql_attribute.h sql_attribute.c
+libstrongswan_attr_sql_la_LDFLAGS = -module -avoid-version
+
+ipsec_PROGRAMS = pool
+pool_SOURCES = pool.c
+pool_LDADD = $(top_builddir)/src/libstrongswan/libstrongswan.la
diff --git a/src/libstrongswan/plugins/attr_sql/attr_sql_plugin.c b/src/libstrongswan/plugins/attr_sql/attr_sql_plugin.c
new file mode 100644
index 000000000..cb57af8a5
--- /dev/null
+++ b/src/libstrongswan/plugins/attr_sql/attr_sql_plugin.c
@@ -0,0 +1,87 @@
+/*
+ * 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 "attr_sql_plugin.h"
+#include "sql_attribute.h"
+
+typedef struct private_attr_sql_plugin_t private_attr_sql_plugin_t;
+
+/**
+ * private data of attr_sql plugin
+ */
+struct private_attr_sql_plugin_t {
+
+ /**
+ * implements plugin interface
+ */
+ attr_sql_plugin_t public;
+
+ /**
+ * database connection instance
+ */
+ database_t *db;
+
+ /**
+ * configuration attributes
+ */
+ sql_attribute_t *attribute;
+
+};
+
+/**
+ * Implementation of plugin_t.destroy
+ */
+static void destroy(private_attr_sql_plugin_t *this)
+{
+ lib->attributes->remove_provider(lib->attributes, &this->attribute->provider);
+ this->attribute->destroy(this->attribute);
+ this->db->destroy(this->db);
+ free(this);
+}
+
+/*
+ * see header file
+ */
+plugin_t *plugin_create()
+{
+ char *uri;
+ private_attr_sql_plugin_t *this;
+
+ uri = lib->settings->get_str(lib->settings, "libstrongswan.plugins.attr-sql.database", NULL);
+ if (!uri)
+ {
+ DBG1("attr-sql plugin: database URI not set");
+ return NULL;
+ }
+
+ this = malloc_thing(private_attr_sql_plugin_t);
+
+ this->public.plugin.destroy = (void(*)(plugin_t*))destroy;
+
+ this->db = lib->db->create(lib->db, uri);
+ if (!this->db)
+ {
+ DBG1("attr-sql plugin failed to connect to database");
+ free(this);
+ return NULL;
+ }
+ this->attribute = sql_attribute_create(this->db);
+ lib->attributes->add_provider(lib->attributes, &this->attribute->provider);
+
+ return &this->public.plugin;
+}
+
diff --git a/src/libstrongswan/plugins/attr_sql/attr_sql_plugin.h b/src/libstrongswan/plugins/attr_sql/attr_sql_plugin.h
new file mode 100644
index 000000000..3a7b8428b
--- /dev/null
+++ b/src/libstrongswan/plugins/attr_sql/attr_sql_plugin.h
@@ -0,0 +1,47 @@
+/*
+ * 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.
+ */
+
+/**
+ * @defgroup sql sql
+ * @ingroup cplugins
+ *
+ * @defgroup sql_plugin sql_plugin
+ * @{ @ingroup sql
+ */
+
+#ifndef ATTR_SQL_PLUGIN_H_
+#define ATTR_SQL_PLUGIN_H_
+
+#include <plugins/plugin.h>
+
+typedef struct attr_sql_plugin_t attr_sql_plugin_t;
+
+/**
+ * SQL database attribute configuration plugin
+ */
+struct attr_sql_plugin_t {
+
+ /**
+ * implements plugin interface
+ */
+ plugin_t plugin;
+};
+
+/**
+ * Create a sql_plugin instance.
+ */
+plugin_t *plugin_create();
+
+#endif /** ATTR_SQL_PLUGIN_H_ @}*/
diff --git a/src/charon/plugins/sql/pool.c b/src/libstrongswan/plugins/attr_sql/pool.c
index 68c2dac48..f4ccbd1fa 100644
--- a/src/charon/plugins/sql/pool.c
+++ b/src/libstrongswan/plugins/attr_sql/pool.c
@@ -623,10 +623,10 @@ int main(int argc, char *argv[])
exit(SS_RC_INITIALIZATION_FAILED);
}
- uri = lib->settings->get_str(lib->settings, "charon.plugins.sql.database", NULL);
+ uri = lib->settings->get_str(lib->settings, "libstrongswan.plugins.attr-sql.database", NULL);
if (!uri)
{
- fprintf(stderr, "database URI charon.plugins.sql.database not set.\n");
+ fprintf(stderr, "database URI libstrongswan.plugins.attr-sql.database not set.\n");
exit(SS_RC_INITIALIZATION_FAILED);
}
db = lib->db->create(lib->db, uri);
diff --git a/src/charon/plugins/sql/sql_attribute.c b/src/libstrongswan/plugins/attr_sql/sql_attribute.c
index 9045f7739..405351653 100644
--- a/src/charon/plugins/sql/sql_attribute.c
+++ b/src/libstrongswan/plugins/attr_sql/sql_attribute.c
@@ -13,11 +13,12 @@
* for more details.
*/
-#include "sql_attribute.h"
-
#include <time.h>
-#include <daemon.h>
+#include <debug.h>
+#include <library.h>
+
+#include "sql_attribute.h"
typedef struct private_sql_attribute_t private_sql_attribute_t;
@@ -126,8 +127,8 @@ static host_t* check_lease(private_sql_attribute_t *this, char *name,
host = host_create_from_chunk(AF_UNSPEC, address, 0);
if (host)
{
- DBG1(DBG_CFG, "acquired existing lease "
- "for address %H in pool '%s'", host, name);
+ DBG1("acquired existing lease for address %H in pool '%s'",
+ host, name);
return host;
}
}
@@ -201,13 +202,13 @@ static host_t* get_lease(private_sql_attribute_t *this, char *name,
host = host_create_from_chunk(AF_UNSPEC, address, 0);
if (host)
{
- DBG1(DBG_CFG, "acquired new lease "
- "for address %H in pool '%s'", host, name);
+ DBG1("acquired new lease for address %H in pool '%s'",
+ host, name);
return host;
}
}
}
- DBG1(DBG_CFG, "no available address found in pool '%s'", name);
+ DBG1("no available address found in pool '%s'", name);
return NULL;
}
diff --git a/src/charon/plugins/sql/sql_attribute.h b/src/libstrongswan/plugins/attr_sql/sql_attribute.h
index 27a39651b..27a39651b 100644
--- a/src/charon/plugins/sql/sql_attribute.h
+++ b/src/libstrongswan/plugins/attr_sql/sql_attribute.h