diff options
author | Martin Willi <martin@strongswan.org> | 2008-05-13 07:24:53 +0000 |
---|---|---|
committer | Martin Willi <martin@strongswan.org> | 2008-05-13 07:24:53 +0000 |
commit | 5373f2a64208a742af06c38206a5febf7af612e0 (patch) | |
tree | 4c0dd5e4744ec16056f13eb1981f7a5f641cf681 /src/charon/plugins/sql/sql_attribute.c | |
parent | ef31d1161d414e8acc916f9878501aa5c25400a3 (diff) | |
download | strongswan-5373f2a64208a742af06c38206a5febf7af612e0.tar.bz2 strongswan-5373f2a64208a742af06c38206a5febf7af612e0.tar.xz |
fixed lookup for expired leases
initializing database if in inconsistent state
Diffstat (limited to 'src/charon/plugins/sql/sql_attribute.c')
-rw-r--r-- | src/charon/plugins/sql/sql_attribute.c | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/src/charon/plugins/sql/sql_attribute.c b/src/charon/plugins/sql/sql_attribute.c index 7c26d1281..2007d94ab 100644 --- a/src/charon/plugins/sql/sql_attribute.c +++ b/src/charon/plugins/sql/sql_attribute.c @@ -141,13 +141,14 @@ static host_t* create_lease(private_sql_attribute_t *this, */ this->mutex->lock(this->mutex); - /* find an address which has outdated leases only */ + /* find an address which has outdated leases only. The HAVING clause filters + * out leases which are active (released = NULL) or not expired */ e = this->db->query(this->db, "SELECT pool, address, released, timeout FROM leases " "JOIN pools ON leases.pool = pools.id " "WHERE name = ? " - "GROUP BY address HAVING released IS NOT NULL " - "AND MAX(released) < (? + timeout) LIMIT 1", + "GROUP BY address HAVING COUNT(released) = COUNT(*) " + "AND MAX(released) < (? - timeout) LIMIT 1", DB_TEXT, name, DB_UINT, time(NULL), DB_UINT, DB_BLOB, DB_UINT, DB_UINT); @@ -276,6 +277,11 @@ sql_attribute_t *sql_attribute_create(database_t *db) this->db = db; this->mutex = mutex_create(MUTEX_DEFAULT); + /* close any "online" leases in the case we crashed */ + this->db->execute(this->db, NULL, + "UPDATE leases SET released = ? WHERE released IS NULL", + DB_UINT, time(NULL)); + return &this->public; } |