updated sql plugin to respect config changes

This commit is contained in:
Martin Willi
2008-04-15 15:13:53 +00:00
parent 1822ca740b
commit 02e4180e48
3 changed files with 50 additions and 32 deletions
+5 -1
View File
@@ -20,6 +20,8 @@ CREATE TABLE `child_configs` (
`updown` varchar(128) collate utf8_unicode_ci default NULL, `updown` varchar(128) collate utf8_unicode_ci default NULL,
`hostaccess` tinyint(1) unsigned NOT NULL default '0', `hostaccess` tinyint(1) unsigned NOT NULL default '0',
`mode` tinyint(4) unsigned NOT NULL default '1', `mode` tinyint(4) unsigned NOT NULL default '1',
`dpd_action` tinyint(4) unsigned NOT NULL default '0',
`close_action` tinyint(4) unsigned NOT NULL default '0',
PRIMARY KEY (`id`), PRIMARY KEY (`id`),
INDEX (`name`) INDEX (`name`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
@@ -54,6 +56,7 @@ CREATE TABLE `peer_configs` (
`local_id` varchar(64) collate utf8_unicode_ci NOT NULL, `local_id` varchar(64) collate utf8_unicode_ci NOT NULL,
`remote_id` varchar(64) collate utf8_unicode_ci NOT NULL, `remote_id` varchar(64) collate utf8_unicode_ci NOT NULL,
`cert_policy` tinyint(3) unsigned NOT NULL default '1', `cert_policy` tinyint(3) unsigned NOT NULL default '1',
`uniqueid` tinyint(3) unsigned NOT NULL default '0',
`auth_method` tinyint(3) unsigned NOT NULL default '1', `auth_method` tinyint(3) unsigned NOT NULL default '1',
`eap_type` tinyint(3) unsigned NOT NULL default '0', `eap_type` tinyint(3) unsigned NOT NULL default '0',
`eap_vendor` smallint(5) unsigned NOT NULL default '0', `eap_vendor` smallint(5) unsigned NOT NULL default '0',
@@ -64,7 +67,8 @@ CREATE TABLE `peer_configs` (
`overtime` mediumint(8) unsigned NOT NULL default '300', `overtime` mediumint(8) unsigned NOT NULL default '300',
`mobike` tinyint(1) NOT NULL default '1', `mobike` tinyint(1) NOT NULL default '1',
`dpd_delay` mediumint(8) unsigned NOT NULL default '120', `dpd_delay` mediumint(8) unsigned NOT NULL default '120',
`dpd_action` tinyint(3) unsigned NOT NULL default '1', `virtual` varchar(40) default NULL,
`pool` varchar(32) default NULL,
`mediation` tinyint(1) NOT NULL default '0', `mediation` tinyint(1) NOT NULL default '0',
`mediated_by` int(10) unsigned NOT NULL default '0', `mediated_by` int(10) unsigned NOT NULL default '0',
`peer_id` int(10) unsigned NOT NULL default '0', `peer_id` int(10) unsigned NOT NULL default '0',
+39 -29
View File
@@ -125,16 +125,15 @@ static void add_traffic_selectors(private_sql_config_t *this,
*/ */
static child_cfg_t *build_child_cfg(private_sql_config_t *this, enumerator_t *e) static child_cfg_t *build_child_cfg(private_sql_config_t *this, enumerator_t *e)
{ {
int id, lifetime, rekeytime, jitter, hostaccess, mode; int id, lifetime, rekeytime, jitter, hostaccess, mode, dpd, close;
char *name, *updown; char *name, *updown;
child_cfg_t *child_cfg; child_cfg_t *child_cfg;
if (e->enumerate(e, &id, &name, &lifetime, &rekeytime, &jitter, if (e->enumerate(e, &id, &name, &lifetime, &rekeytime, &jitter,
&updown, &hostaccess, &mode)) &updown, &hostaccess, &mode, &dpd, &close))
{ {
child_cfg = child_cfg_create(name, lifetime, rekeytime, jitter, child_cfg = child_cfg_create(name, lifetime, rekeytime, jitter,
updown, hostaccess, mode, updown, hostaccess, mode, dpd, close);
ACTION_NONE, ACTION_NONE);
/* TODO: read proposal from db */ /* TODO: read proposal from db */
child_cfg->add_proposal(child_cfg, proposal_create_default(PROTO_ESP)); child_cfg->add_proposal(child_cfg, proposal_create_default(PROTO_ESP));
add_traffic_selectors(this, child_cfg, id); add_traffic_selectors(this, child_cfg, id);
@@ -153,12 +152,12 @@ static void add_child_cfgs(private_sql_config_t *this, peer_cfg_t *peer, int id)
e = this->db->query(this->db, e = this->db->query(this->db,
"SELECT id, name, lifetime, rekeytime, jitter, " "SELECT id, name, lifetime, rekeytime, jitter, "
"updown, hostaccess, mode " "updown, hostaccess, mode, dpd_action, close_action "
"FROM child_configs JOIN peer_config_child_config ON id = child_cfg " "FROM child_configs JOIN peer_config_child_config ON id = child_cfg "
"WHERE peer_cfg = ?", "WHERE peer_cfg = ?",
DB_INT, id, DB_INT, id,
DB_INT, DB_TEXT, DB_INT, DB_INT, DB_INT, DB_INT, DB_TEXT, DB_INT, DB_INT, DB_INT,
DB_TEXT, DB_INT, DB_INT); DB_TEXT, DB_INT, DB_INT, DB_INT, DB_INT);
if (e) if (e)
{ {
while ((child_cfg = build_child_cfg(this, e))) while ((child_cfg = build_child_cfg(this, e)))
@@ -246,9 +245,10 @@ static peer_cfg_t *get_peer_cfg_by_id(private_sql_config_t *this, int id)
e = this->db->query(this->db, e = this->db->query(this->db,
"SELECT c.id, name, ike_cfg, l.type, l.data, r.type, r.data, " "SELECT c.id, name, ike_cfg, l.type, l.data, r.type, r.data, "
"cert_policy, auth_method, eap_type, eap_vendor, keyingtries, " "cert_policy, uniqueid, auth_method, eap_type, eap_vendor, "
"rekeytime, reauthtime, jitter, overtime, mobike, dpd_delay, " "keyingtries, rekeytime, reauthtime, jitter, overtime, mobike, "
"dpd_action, mediation, mediated_by, COALESCE(p.type, 0), p.data " "dpd_delay, virtual, pool, "
"mediation, mediated_by, COALESCE(p.type, 0), p.data "
"FROM peer_configs AS c " "FROM peer_configs AS c "
"JOIN identities AS l ON local_id = l.id " "JOIN identities AS l ON local_id = l.id "
"JOIN identities AS r ON remote_id = r.id " "JOIN identities AS r ON remote_id = r.id "
@@ -256,9 +256,10 @@ static peer_cfg_t *get_peer_cfg_by_id(private_sql_config_t *this, int id)
"WHERE id = ?", "WHERE id = ?",
DB_INT, id, DB_INT, id,
DB_INT, DB_TEXT, DB_INT, DB_INT, DB_BLOB, DB_INT, DB_BLOB, DB_INT, DB_TEXT, DB_INT, DB_INT, DB_BLOB, DB_INT, DB_BLOB,
DB_INT, DB_INT, DB_INT, DB_INT, DB_INT, DB_INT, DB_INT, DB_INT, DB_INT, DB_INT,
DB_INT, DB_INT, DB_INT, DB_INT, DB_INT, DB_INT, DB_INT, DB_INT, DB_INT, DB_INT, DB_INT, DB_INT,
DB_INT, DB_INT, DB_INT, DB_INT, DB_BLOB); DB_INT, DB_TEXT, DB_TEXT,
DB_INT, DB_INT, DB_INT, DB_BLOB);
if (e) if (e)
{ {
peer_cfg = build_peer_cfg(this, e, NULL, NULL); peer_cfg = build_peer_cfg(this, e, NULL, NULL);
@@ -274,21 +275,23 @@ static peer_cfg_t *build_peer_cfg(private_sql_config_t *this, enumerator_t *e,
identification_t *me, identification_t *other) identification_t *me, identification_t *other)
{ {
int id, ike_cfg, l_type, r_type, int id, ike_cfg, l_type, r_type,
cert_policy, auth_method, eap_type, eap_vendor, keyingtries, cert_policy, uniqueid, auth_method, eap_type, eap_vendor, keyingtries,
rekeytime, reauthtime, jitter, overtime, mobike, dpd_delay, rekeytime, reauthtime, jitter, overtime, mobike, dpd_delay,
dpd_action, mediation, mediated_by, p_type; mediation, mediated_by, p_type;
chunk_t l_data, r_data, p_data; chunk_t l_data, r_data, p_data;
char *name; char *name, *virtual, *pool;
while (e->enumerate(e, while (e->enumerate(e,
&id, &name, &ike_cfg, &l_type, &l_data, &r_type, &r_data, &id, &name, &ike_cfg, &l_type, &l_data, &r_type, &r_data,
&cert_policy, &auth_method, &eap_type, &eap_vendor, &keyingtries, &cert_policy, &uniqueid, &auth_method, &eap_type, &eap_vendor,
&rekeytime, &reauthtime, &jitter, &overtime, &mobike, &dpd_delay, &keyingtries, &rekeytime, &reauthtime, &jitter, &overtime, &mobike,
&dpd_action, &mediation, &mediated_by, &p_type, &p_data)) &dpd_delay, &virtual, &pool,
&mediation, &mediated_by, &p_type, &p_data))
{ {
identification_t *local_id, *remote_id, *peer_id = NULL; identification_t *local_id, *remote_id, *peer_id = NULL;
peer_cfg_t *peer_cfg, *mediated_cfg; peer_cfg_t *peer_cfg, *mediated_cfg;
ike_cfg_t *ike; ike_cfg_t *ike;
host_t *vip = NULL;
local_id = identification_create_from_encoding(l_type, l_data); local_id = identification_create_from_encoding(l_type, l_data);
remote_id = identification_create_from_encoding(r_type, r_data); remote_id = identification_create_from_encoding(r_type, r_data);
@@ -305,14 +308,17 @@ static peer_cfg_t *build_peer_cfg(private_sql_config_t *this, enumerator_t *e,
{ {
peer_id = identification_create_from_encoding(p_type, p_data); peer_id = identification_create_from_encoding(p_type, p_data);
} }
if (virtual)
{
vip = host_create_from_string(virtual, 0);
}
if (ike) if (ike)
{ {
peer_cfg = peer_cfg_create( peer_cfg = peer_cfg_create(
name, 2, ike, local_id, remote_id, cert_policy, UNIQUE_NO, name, 2, ike, local_id, remote_id, cert_policy, uniqueid,
auth_method, eap_type, eap_vendor, keyingtries, auth_method, eap_type, eap_vendor, keyingtries,
rekeytime, reauthtime, jitter, overtime, mobike, rekeytime, reauthtime, jitter, overtime, mobike,
dpd_delay, NULL, NULL, dpd_delay, vip, pool,
mediation, mediated_cfg, peer_id); mediation, mediated_cfg, peer_id);
add_child_cfgs(this, peer_cfg, id); add_child_cfgs(this, peer_cfg, id);
return peer_cfg; return peer_cfg;
@@ -336,9 +342,10 @@ static peer_cfg_t *get_peer_cfg_by_name(private_sql_config_t *this, char *name)
e = this->db->query(this->db, e = this->db->query(this->db,
"SELECT c.id, name, ike_cfg, l.type, l.data, r.type, r.data, " "SELECT c.id, name, ike_cfg, l.type, l.data, r.type, r.data, "
"cert_policy, auth_method, eap_type, eap_vendor, keyingtries, " "cert_policy, uniqueid, auth_method, eap_type, eap_vendor, "
"rekeytime, reauthtime, jitter, overtime, mobike, dpd_delay, " "keyingtries, rekeytime, reauthtime, jitter, overtime, mobike, "
"dpd_action, mediation, mediated_by, COALESCE(p.type, 0), p.data " "dpd_delay, virtual, pool, "
"mediation, mediated_by, COALESCE(p.type, 0), p.data "
"FROM peer_configs AS c " "FROM peer_configs AS c "
"JOIN identities AS l ON local_id = l.id " "JOIN identities AS l ON local_id = l.id "
"JOIN identities AS r ON remote_id = r.id " "JOIN identities AS r ON remote_id = r.id "
@@ -348,7 +355,8 @@ static peer_cfg_t *get_peer_cfg_by_name(private_sql_config_t *this, char *name)
DB_INT, DB_TEXT, DB_INT, DB_INT, DB_BLOB, DB_INT, DB_BLOB, DB_INT, DB_TEXT, DB_INT, DB_INT, DB_BLOB, DB_INT, DB_BLOB,
DB_INT, DB_INT, DB_INT, DB_INT, DB_INT, DB_INT, DB_INT, DB_INT, DB_INT, DB_INT,
DB_INT, DB_INT, DB_INT, DB_INT, DB_INT, DB_INT, DB_INT, DB_INT, DB_INT, DB_INT, DB_INT, DB_INT,
DB_INT, DB_INT, DB_INT, DB_INT, DB_BLOB); DB_INT, DB_TEXT, DB_TEXT,
DB_INT, DB_INT, DB_INT, DB_BLOB);
if (e) if (e)
{ {
peer_cfg = build_peer_cfg(this, e, NULL, NULL); peer_cfg = build_peer_cfg(this, e, NULL, NULL);
@@ -484,9 +492,10 @@ static enumerator_t* create_peer_cfg_enumerator(private_sql_config_t *this,
/* TODO: only get configs whose IDs match exactly or contain wildcards */ /* TODO: only get configs whose IDs match exactly or contain wildcards */
e->inner = this->db->query(this->db, e->inner = this->db->query(this->db,
"SELECT c.id, name, ike_cfg, l.type, l.data, r.type, r.data, " "SELECT c.id, name, ike_cfg, l.type, l.data, r.type, r.data, "
"cert_policy, auth_method, eap_type, eap_vendor, keyingtries, " "cert_policy, uniqueid, auth_method, eap_type, eap_vendor, "
"rekeytime, reauthtime, jitter, overtime, mobike, dpd_delay, " "keyingtries, rekeytime, reauthtime, jitter, overtime, mobike, "
"dpd_action, mediation, mediated_by, COALESCE(p.type, 0), p.data " "dpd_delay, virtual, pool, "
"mediation, mediated_by, COALESCE(p.type, 0), p.data "
"FROM peer_configs AS c " "FROM peer_configs AS c "
"JOIN identities AS l ON local_id = l.id " "JOIN identities AS l ON local_id = l.id "
"JOIN identities AS r ON remote_id = r.id " "JOIN identities AS r ON remote_id = r.id "
@@ -496,7 +505,8 @@ static enumerator_t* create_peer_cfg_enumerator(private_sql_config_t *this,
DB_INT, DB_TEXT, DB_INT, DB_INT, DB_BLOB, DB_INT, DB_BLOB, DB_INT, DB_TEXT, DB_INT, DB_INT, DB_BLOB, DB_INT, DB_BLOB,
DB_INT, DB_INT, DB_INT, DB_INT, DB_INT, DB_INT, DB_INT, DB_INT, DB_INT, DB_INT,
DB_INT, DB_INT, DB_INT, DB_INT, DB_INT, DB_INT, DB_INT, DB_INT, DB_INT, DB_INT, DB_INT, DB_INT,
DB_INT, DB_INT, DB_INT, DB_INT, DB_BLOB); DB_INT, DB_TEXT, DB_TEXT,
DB_INT, DB_INT, DB_INT, DB_BLOB);
if (!e->inner) if (!e->inner)
{ {
free(e); free(e);
+6 -2
View File
@@ -18,7 +18,9 @@ CREATE TABLE child_configs (
jitter INTEGER NOT NULL DEFAULT '60', jitter INTEGER NOT NULL DEFAULT '60',
updown TEXT DEFAULT NULL, updown TEXT DEFAULT NULL,
hostaccess INTEGER NOT NULL DEFAULT '0', hostaccess INTEGER NOT NULL DEFAULT '0',
mode INTEGER NOT NULL DEFAULT '1' mode INTEGER NOT NULL DEFAULT '1',
dpd_action INTEGER NOT NULL DEFAULT '0',
close_action INTEGER NOT NULL DEFAULT '0'
); );
DROP INDEX IF EXISTS child_configs_name; DROP INDEX IF EXISTS child_configs_name;
CREATE INDEX child_configs_name ON child_configs ( CREATE INDEX child_configs_name ON child_configs (
@@ -57,6 +59,7 @@ CREATE TABLE peer_configs (
local_id TEXT NOT NULL, local_id TEXT NOT NULL,
remote_id TEXT NOT NULL, remote_id TEXT NOT NULL,
cert_policy INTEGER NOT NULL DEFAULT '1', cert_policy INTEGER NOT NULL DEFAULT '1',
uniqueid INTEGER NOT NULL DEFAULT '0',
auth_method INTEGER NOT NULL DEFAULT '1', auth_method INTEGER NOT NULL DEFAULT '1',
eap_type INTEGER NOT NULL DEFAULT '0', eap_type INTEGER NOT NULL DEFAULT '0',
eap_vendor INTEGER NOT NULL DEFAULT '0', eap_vendor INTEGER NOT NULL DEFAULT '0',
@@ -67,7 +70,8 @@ CREATE TABLE peer_configs (
overtime INTEGER NOT NULL DEFAULT '300', overtime INTEGER NOT NULL DEFAULT '300',
mobike INTEGER NOT NULL DEFAULT '1', mobike INTEGER NOT NULL DEFAULT '1',
dpd_delay INTEGER NOT NULL DEFAULT '120', dpd_delay INTEGER NOT NULL DEFAULT '120',
dpd_action INTEGER NOT NULL DEFAULT '1', virtual TEXT DEFAULT NULL,
pool TEXT DEFAULT NULL,
mediation INTEGER NOT NULL DEFAULT '0', mediation INTEGER NOT NULL DEFAULT '0',
mediated_by INTEGER NOT NULL DEFAULT '0', mediated_by INTEGER NOT NULL DEFAULT '0',
peer_id INTEGER NOT NULL DEFAULT '0' peer_id INTEGER NOT NULL DEFAULT '0'