summaryrefslogtreecommitdiff
path: root/src/libcharon/plugins/sql/sql_config.c
diff options
context:
space:
mode:
authorRené Mayrhofer <rene@mayrhofer.eu.org>2011-03-05 09:29:19 +0100
committerRené Mayrhofer <rene@mayrhofer.eu.org>2011-03-05 09:29:19 +0100
commit365e71f706b40c32173fa06c6feaac48c1527520 (patch)
tree54fa72a914d18c9430eaa54f3de4a2d4419198af /src/libcharon/plugins/sql/sql_config.c
parent5d7669b7b3563c50b3c86903e0a49373d597b8a0 (diff)
parent568905f488e63e28778f87ac0e38d845f45bae79 (diff)
downloadvyos-strongswan-365e71f706b40c32173fa06c6feaac48c1527520.tar.gz
vyos-strongswan-365e71f706b40c32173fa06c6feaac48c1527520.zip
Fixed merge, don't know why this didn't happen automatically - maybe a leftover from the svn->git conversion
Diffstat (limited to 'src/libcharon/plugins/sql/sql_config.c')
-rw-r--r--src/libcharon/plugins/sql/sql_config.c188
1 files changed, 188 insertions, 0 deletions
diff --git a/src/libcharon/plugins/sql/sql_config.c b/src/libcharon/plugins/sql/sql_config.c
index a47d93f7b..0ca481bb9 100644
--- a/src/libcharon/plugins/sql/sql_config.c
+++ b/src/libcharon/plugins/sql/sql_config.c
@@ -1,5 +1,9 @@
/*
* Copyright (C) 2006-2008 Martin Willi
+<<<<<<< HEAD
+=======
+ * Copyright (C) 2010 Andreas Steffen
+>>>>>>> upstream/4.5.1
* Hochschule fuer Technik Rapperswil
*
* This program is free software; you can redistribute it and/or modify it
@@ -38,13 +42,21 @@ struct private_sql_config_t {
};
/**
+<<<<<<< HEAD
* forward declaration
+=======
+ * Forward declaration
+>>>>>>> upstream/4.5.1
*/
static peer_cfg_t *build_peer_cfg(private_sql_config_t *this, enumerator_t *e,
identification_t *me, identification_t *other);
/**
+<<<<<<< HEAD
* build a traffic selector from a SQL query
+=======
+ * Build a traffic selector from an SQL query
+>>>>>>> upstream/4.5.1
*/
static traffic_selector_t *build_traffic_selector(private_sql_config_t *this,
enumerator_t *e, bool *local)
@@ -119,6 +131,7 @@ static void add_traffic_selectors(private_sql_config_t *this,
}
/**
+<<<<<<< HEAD
* build a Child configuration from a SQL query
*/
static child_cfg_t *build_child_cfg(private_sql_config_t *this, enumerator_t *e)
@@ -129,14 +142,70 @@ static child_cfg_t *build_child_cfg(private_sql_config_t *this, enumerator_t *e)
if (e->enumerate(e, &id, &name, &lifetime, &rekeytime, &jitter,
&updown, &hostaccess, &mode, &dpd, &close, &ipcomp))
+=======
+ * Add ESP proposals to a child config
+ */
+static void add_esp_proposals(private_sql_config_t *this,
+ child_cfg_t *child, int id)
+{
+ enumerator_t *e;
+ proposal_t *proposal;
+ char *prop;
+ bool use_default = TRUE;
+
+ e = this->db->query(this->db,
+ "SELECT proposal "
+ "FROM proposals JOIN child_config_proposal ON id = prop "
+ "WHERE child_cfg = ? ORDER BY prio",
+ DB_INT, id, DB_TEXT);
+ if (e)
+ {
+ while (e->enumerate(e, &prop))
+ {
+ proposal = proposal_create_from_string(PROTO_ESP, prop);
+ if (!proposal)
+ {
+ DBG1(DBG_CFG, "could not create ESP proposal from '%s'", prop);
+ break;
+ }
+ child->add_proposal(child, proposal);
+ use_default = FALSE;
+ }
+ e->destroy(e);
+ }
+ if (use_default)
+ {
+ child->add_proposal(child, proposal_create_default(PROTO_ESP));
+ }
+}
+
+/**
+ * Build a child config from an SQL query
+ */
+static child_cfg_t *build_child_cfg(private_sql_config_t *this, enumerator_t *e)
+{
+ int id, lifetime, rekeytime, jitter, hostaccess, mode, ipcomp, reqid;
+ int start, dpd, close;
+ char *name, *updown;
+ child_cfg_t *child_cfg;
+
+ if (e->enumerate(e, &id, &name, &lifetime, &rekeytime, &jitter, &updown,
+ &hostaccess, &mode, &start, &dpd, &close, &ipcomp, &reqid))
+>>>>>>> upstream/4.5.1
{
lifetime_cfg_t lft = {
.time = { .life = lifetime, .rekey = rekeytime, .jitter = jitter }
};
child_cfg = child_cfg_create(name, &lft, updown, hostaccess, mode,
+<<<<<<< HEAD
dpd, close, ipcomp, 0, 0, NULL, NULL);
/* TODO: read proposal from db */
child_cfg->add_proposal(child_cfg, proposal_create_default(PROTO_ESP));
+=======
+ start, dpd, close, ipcomp, 0, reqid,
+ NULL, NULL, 0);
+ add_esp_proposals(this, child_cfg, id);
+>>>>>>> upstream/4.5.1
add_traffic_selectors(this, child_cfg, id);
return child_cfg;
}
@@ -152,6 +221,7 @@ static void add_child_cfgs(private_sql_config_t *this, peer_cfg_t *peer, int id)
child_cfg_t *child_cfg;
e = this->db->query(this->db,
+<<<<<<< HEAD
"SELECT id, name, lifetime, rekeytime, jitter, "
"updown, hostaccess, mode, dpd_action, close_action, ipcomp "
"FROM child_configs JOIN peer_config_child_config ON id = child_cfg "
@@ -159,6 +229,15 @@ static void add_child_cfgs(private_sql_config_t *this, peer_cfg_t *peer, int id)
DB_INT, id,
DB_INT, DB_TEXT, DB_INT, DB_INT, DB_INT,
DB_TEXT, DB_INT, DB_INT, DB_INT, DB_INT, DB_INT);
+=======
+ "SELECT id, name, lifetime, rekeytime, jitter, updown, hostaccess, "
+ "mode, start_action, dpd_action, close_action, ipcomp, reqid "
+ "FROM child_configs JOIN peer_config_child_config ON id = child_cfg "
+ "WHERE peer_cfg = ?",
+ DB_INT, id,
+ DB_INT, DB_TEXT, DB_INT, DB_INT, DB_INT, DB_TEXT, DB_INT,
+ DB_INT, DB_INT, DB_INT, DB_INT, DB_INT, DB_INT);
+>>>>>>> upstream/4.5.1
if (e)
{
while ((child_cfg = build_child_cfg(this, e)))
@@ -170,29 +249,85 @@ static void add_child_cfgs(private_sql_config_t *this, peer_cfg_t *peer, int id)
}
/**
+<<<<<<< HEAD
* build a ike configuration from a SQL query
+=======
+ * Add IKE proposals to an IKE config
+ */
+static void add_ike_proposals(private_sql_config_t *this,
+ ike_cfg_t *ike_cfg, int id)
+{
+ enumerator_t *e;
+ proposal_t *proposal;
+ char *prop;
+ bool use_default = TRUE;
+
+ e = this->db->query(this->db,
+ "SELECT proposal "
+ "FROM proposals JOIN ike_config_proposal ON id = prop "
+ "WHERE ike_cfg = ? ORDER BY prio",
+ DB_INT, id, DB_TEXT);
+ if (e)
+ {
+ while (e->enumerate(e, &prop))
+ {
+ proposal = proposal_create_from_string(PROTO_IKE, prop);
+ if (!proposal)
+ {
+ DBG1(DBG_CFG, "could not create IKE proposal from '%s'", prop);
+ break;
+ }
+ ike_cfg->add_proposal(ike_cfg, proposal);
+ use_default = FALSE;
+ }
+ e->destroy(e);
+ }
+ if (use_default)
+ {
+ ike_cfg->add_proposal(ike_cfg, proposal_create_default(PROTO_IKE));
+ }
+}
+
+/**
+ * Build an IKE config from an SQL query
+>>>>>>> upstream/4.5.1
*/
static ike_cfg_t *build_ike_cfg(private_sql_config_t *this, enumerator_t *e,
host_t *my_host, host_t *other_host)
{
+<<<<<<< HEAD
int certreq, force_encap;
char *local, *remote;
while (e->enumerate(e, &certreq, &force_encap, &local, &remote))
+=======
+ int id, certreq, force_encap;
+ char *local, *remote;
+
+ while (e->enumerate(e, &id, &certreq, &force_encap, &local, &remote))
+>>>>>>> upstream/4.5.1
{
ike_cfg_t *ike_cfg;
ike_cfg = ike_cfg_create(certreq, force_encap,
local, IKEV2_UDP_PORT, remote, IKEV2_UDP_PORT);
+<<<<<<< HEAD
/* TODO: read proposal from db */
ike_cfg->add_proposal(ike_cfg, proposal_create_default(PROTO_IKE));
+=======
+ add_ike_proposals(this, ike_cfg, id);
+>>>>>>> upstream/4.5.1
return ike_cfg;
}
return NULL;
}
/**
+<<<<<<< HEAD
* Query a IKE config by its id
+=======
+ * Query an IKE config by its id
+>>>>>>> upstream/4.5.1
*/
static ike_cfg_t* get_ike_cfg_by_id(private_sql_config_t *this, int id)
{
@@ -200,10 +335,17 @@ static ike_cfg_t* get_ike_cfg_by_id(private_sql_config_t *this, int id)
ike_cfg_t *ike_cfg = NULL;
e = this->db->query(this->db,
+<<<<<<< HEAD
"SELECT certreq, force_encap, local, remote "
"FROM ike_configs WHERE id = ?",
DB_INT, id,
DB_INT, DB_INT, DB_TEXT, DB_TEXT);
+=======
+ "SELECT id, certreq, force_encap, local, remote "
+ "FROM ike_configs WHERE id = ?",
+ DB_INT, id,
+ DB_INT, DB_INT, DB_INT, DB_TEXT, DB_TEXT);
+>>>>>>> upstream/4.5.1
if (e)
{
ike_cfg = build_ike_cfg(this, e, NULL, NULL);
@@ -246,7 +388,11 @@ static peer_cfg_t *get_peer_cfg_by_id(private_sql_config_t *this, int id)
}
/**
+<<<<<<< HEAD
* build a peer configuration from a SQL query
+=======
+ * Build a peer config from an SQL query
+>>>>>>> upstream/4.5.1
*/
static peer_cfg_t *build_peer_cfg(private_sql_config_t *this, enumerator_t *e,
identification_t *me, identification_t *other)
@@ -325,10 +471,15 @@ static peer_cfg_t *build_peer_cfg(private_sql_config_t *this, enumerator_t *e,
return NULL;
}
+<<<<<<< HEAD
/**
* implements backend_t.get_peer_cfg_by_name.
*/
static peer_cfg_t *get_peer_cfg_by_name(private_sql_config_t *this, char *name)
+=======
+METHOD(backend_t, get_peer_cfg_by_name, peer_cfg_t*,
+ private_sql_config_t *this, char *name)
+>>>>>>> upstream/4.5.1
{
enumerator_t *e;
peer_cfg_t *peer_cfg = NULL;
@@ -398,11 +549,16 @@ static void ike_enumerator_destroy(ike_enumerator_t *this)
free(this);
}
+<<<<<<< HEAD
/**
* Implementation of backend_t.create_ike_cfg_enumerator.
*/
static enumerator_t* create_ike_cfg_enumerator(private_sql_config_t *this,
host_t *me, host_t *other)
+=======
+METHOD(backend_t, create_ike_cfg_enumerator, enumerator_t*,
+ private_sql_config_t *this, host_t *me, host_t *other)
+>>>>>>> upstream/4.5.1
{
ike_enumerator_t *e = malloc_thing(ike_enumerator_t);
@@ -414,9 +570,15 @@ static enumerator_t* create_ike_cfg_enumerator(private_sql_config_t *this,
e->public.destroy = (void*)ike_enumerator_destroy;
e->inner = this->db->query(this->db,
+<<<<<<< HEAD
"SELECT certreq, force_encap, local, remote "
"FROM ike_configs",
DB_INT, DB_INT, DB_TEXT, DB_TEXT);
+=======
+ "SELECT id, certreq, force_encap, local, remote "
+ "FROM ike_configs",
+ DB_INT, DB_INT, DB_INT, DB_TEXT, DB_TEXT);
+>>>>>>> upstream/4.5.1
if (!e->inner)
{
free(e);
@@ -466,12 +628,17 @@ static void peer_enumerator_destroy(peer_enumerator_t *this)
free(this);
}
+<<<<<<< HEAD
/**
* Implementation of backend_t.create_peer_cfg_enumerator.
*/
static enumerator_t* create_peer_cfg_enumerator(private_sql_config_t *this,
identification_t *me,
identification_t *other)
+=======
+METHOD(backend_t, create_peer_cfg_enumerator, enumerator_t*,
+ private_sql_config_t *this, identification_t *me, identification_t *other)
+>>>>>>> upstream/4.5.1
{
peer_enumerator_t *e = malloc_thing(peer_enumerator_t);
@@ -508,10 +675,15 @@ static enumerator_t* create_peer_cfg_enumerator(private_sql_config_t *this,
return &e->public;
}
+<<<<<<< HEAD
/**
* Implementation of sql_config_t.destroy.
*/
static void destroy(private_sql_config_t *this)
+=======
+METHOD(sql_config_t, destroy, void,
+ private_sql_config_t *this)
+>>>>>>> upstream/4.5.1
{
free(this);
}
@@ -521,6 +693,7 @@ static void destroy(private_sql_config_t *this)
*/
sql_config_t *sql_config_create(database_t *db)
{
+<<<<<<< HEAD
private_sql_config_t *this = malloc_thing(private_sql_config_t);
this->public.backend.create_peer_cfg_enumerator = (enumerator_t*(*)(backend_t*, identification_t *me, identification_t *other))create_peer_cfg_enumerator;
@@ -529,6 +702,21 @@ sql_config_t *sql_config_create(database_t *db)
this->public.destroy = (void(*)(sql_config_t*))destroy;
this->db = db;
+=======
+ private_sql_config_t *this;
+
+ INIT(this,
+ .public = {
+ .backend = {
+ .create_peer_cfg_enumerator = _create_peer_cfg_enumerator,
+ .create_ike_cfg_enumerator = _create_ike_cfg_enumerator,
+ .get_peer_cfg_by_name = _get_peer_cfg_by_name,
+ },
+ .destroy = _destroy,
+ },
+ .db = db
+ );
+>>>>>>> upstream/4.5.1
return &this->public;
}