provide attributes from SQL database
authorAndreas Steffen <andreas.steffen@strongswan.org>
Wed, 16 Dec 2009 11:31:41 +0000 (12:31 +0100)
committerAndreas Steffen <andreas.steffen@strongswan.org>
Wed, 16 Dec 2009 11:31:41 +0000 (12:31 +0100)
src/charon/plugins/sql/mysql.sql
src/charon/plugins/sql/sqlite.sql
src/charon/sa/tasks/ike_config.c
src/libstrongswan/plugins/attr_sql/sql_attribute.c
testing/hosts/default/etc/ipsec.d/tables.sql

index 412abc7..1a01394 100644 (file)
@@ -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 (
index f8bac1f..53d64dc 100644 (file)
@@ -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 (
index b1c133a..f010439 100644 (file)
@@ -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));
                }
index 2dd9099..3440872 100644 (file)
@@ -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;
index 2697095..a7c5f1d 100644 (file)
@@ -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,