diff options
author | Andreas Steffen <andreas.steffen@strongswan.org> | 2009-12-16 12:31:41 +0100 |
---|---|---|
committer | Andreas Steffen <andreas.steffen@strongswan.org> | 2009-12-16 12:31:41 +0100 |
commit | a461e20dd89988f3d619e9019ba1712e80d36211 (patch) | |
tree | 79a84b3cdeee6062250c814fc6556bdb4d452ba9 | |
parent | b75002bc955e7a1489c5c2dd75f452ca057b9b1b (diff) | |
download | strongswan-a461e20dd89988f3d619e9019ba1712e80d36211.tar.bz2 strongswan-a461e20dd89988f3d619e9019ba1712e80d36211.tar.xz |
provide attributes from SQL database
-rw-r--r-- | src/charon/plugins/sql/mysql.sql | 6 | ||||
-rw-r--r-- | src/charon/plugins/sql/sqlite.sql | 6 | ||||
-rw-r--r-- | src/charon/sa/tasks/ike_config.c | 6 | ||||
-rw-r--r-- | src/libstrongswan/plugins/attr_sql/sql_attribute.c | 22 | ||||
-rw-r--r-- | testing/hosts/default/etc/ipsec.d/tables.sql | 7 |
5 files changed, 44 insertions, 3 deletions
diff --git a/src/charon/plugins/sql/mysql.sql b/src/charon/plugins/sql/mysql.sql index 412abc715..1a01394b6 100644 --- a/src/charon/plugins/sql/mysql.sql +++ b/src/charon/plugins/sql/mysql.sql @@ -187,6 +187,12 @@ CREATE TABLE leases ( PRIMARY KEY (`id`) ); +DROP TABLE IF EXISTS attributes; +CREATE TABLE attributes ( + `id` int(10) unsigned NOT NULL auto_increment, + `type` int(10) unsigned NOT NULL, + `value` varbinary(16) NOT NULL +); DROP TABLE IF EXISTS ike_sas; CREATE TABLE ike_sas ( diff --git a/src/charon/plugins/sql/sqlite.sql b/src/charon/plugins/sql/sqlite.sql index f8bac1fcf..53d64dc34 100644 --- a/src/charon/plugins/sql/sqlite.sql +++ b/src/charon/plugins/sql/sqlite.sql @@ -192,6 +192,12 @@ CREATE TABLE leases ( released INTEGER NOT NULL ); +DROP TABLE IF EXISTS attributes; +CREATE TABLE attributes ( + id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, + type INTEGER NOT NULL, + value BLOB NOT NULL +); DROP TABLE IF EXISTS ike_sas; CREATE TABLE ike_sas ( diff --git a/src/charon/sa/tasks/ike_config.c b/src/charon/sa/tasks/ike_config.c index b1c133a4e..f010439fe 100644 --- a/src/charon/sa/tasks/ike_config.c +++ b/src/charon/sa/tasks/ike_config.c @@ -207,7 +207,7 @@ static void process_payloads(private_ike_config_t *this, message_t *message) attributes = cp->create_attribute_enumerator(cp); while (attributes->enumerate(attributes, &ca)) { - DBG2(DBG_IKE, "processing %N config attribute", + DBG2(DBG_IKE, "processing %N attribute", configuration_attribute_type_names, ca->get_type(ca)); process_attribute(this, ca); } @@ -260,7 +260,7 @@ static status_t build_i(private_ike_config_t *this, message_t *message) entry_t *entry; /* create configuration attribute */ - DBG2(DBG_IKE, "building %N config attribute", + DBG2(DBG_IKE, "building %N attribute", configuration_attribute_type_names, type); ca = configuration_attribute_create_value(type, data); if (!cp) @@ -380,6 +380,8 @@ static status_t build_r(private_ike_config_t *this, message_t *message) { cp = cp_payload_create_type(CFG_REPLY); } + DBG2(DBG_IKE, "building %N attribute", + configuration_attribute_type_names, type); cp->add_attribute(cp, configuration_attribute_create_value(type, value)); } diff --git a/src/libstrongswan/plugins/attr_sql/sql_attribute.c b/src/libstrongswan/plugins/attr_sql/sql_attribute.c index 2dd909981..3440872f8 100644 --- a/src/libstrongswan/plugins/attr_sql/sql_attribute.c +++ b/src/libstrongswan/plugins/attr_sql/sql_attribute.c @@ -324,6 +324,26 @@ static bool release_address(private_sql_attribute_t *this, } /** + * Implementation of sql_attribute_t.create_attribute_enumerator + */ +static enumerator_t* create_attribute_enumerator(private_sql_attribute_t *this, + identification_t *id, host_t *vip) +{ + if (vip) + { + enumerator_t *enumerator; + + enumerator = this->db->query(this->db, + "SELECT type, value FROM attributes ", DB_INT, DB_BLOB); + if (enumerator) + { + return enumerator; + } + } + return enumerator_create_empty(); +} + +/** * Implementation of sql_attribute_t.destroy */ static void destroy(private_sql_attribute_t *this) @@ -341,7 +361,7 @@ sql_attribute_t *sql_attribute_create(database_t *db) this->public.provider.acquire_address = (host_t*(*)(attribute_provider_t *this, char*, identification_t *, host_t *))acquire_address; this->public.provider.release_address = (bool(*)(attribute_provider_t *this, char*,host_t *, identification_t*))release_address; - this->public.provider.create_attribute_enumerator = (enumerator_t*(*)(attribute_provider_t*, identification_t *id, host_t *host))enumerator_create_empty; + this->public.provider.create_attribute_enumerator = (enumerator_t*(*)(attribute_provider_t*, identification_t *id, host_t *host))create_attribute_enumerator; this->public.destroy = (void(*)(sql_attribute_t*))destroy; this->db = db; diff --git a/testing/hosts/default/etc/ipsec.d/tables.sql b/testing/hosts/default/etc/ipsec.d/tables.sql index 269709542..a7c5f1d81 100644 --- a/testing/hosts/default/etc/ipsec.d/tables.sql +++ b/testing/hosts/default/etc/ipsec.d/tables.sql @@ -183,6 +183,13 @@ CREATE TABLE leases ( released INTEGER NOT NULL ); +DROP TABLE IF EXISTS attributes; +CREATE TABLE attributes ( + id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, + type INTEGER NOT NULL, + value BLOB NOT NULL +); + DROP TABLE IF EXISTS ike_sas; CREATE TABLE ike_sas ( local_spi BLOB NOT NULL PRIMARY KEY, |