diff options
author | Yves-Alexis Perez <corsac@debian.org> | 2014-07-11 07:23:31 +0200 |
---|---|---|
committer | Yves-Alexis Perez <corsac@debian.org> | 2014-07-11 07:23:31 +0200 |
commit | 81c63b0eed39432878f78727f60a1e7499645199 (patch) | |
tree | 82387d8fecd1c20788fd8bd784a9b0bde091fb6b /src/libstrongswan/credentials/sets | |
parent | c5ebfc7b9c16551fe825dc1d79c3f7e2f096f6c9 (diff) | |
download | vyos-strongswan-81c63b0eed39432878f78727f60a1e7499645199.tar.gz vyos-strongswan-81c63b0eed39432878f78727f60a1e7499645199.zip |
Imported Upstream version 5.2.0
Diffstat (limited to 'src/libstrongswan/credentials/sets')
-rw-r--r-- | src/libstrongswan/credentials/sets/cert_cache.c | 1 | ||||
-rw-r--r-- | src/libstrongswan/credentials/sets/mem_cred.c | 76 |
2 files changed, 73 insertions, 4 deletions
diff --git a/src/libstrongswan/credentials/sets/cert_cache.c b/src/libstrongswan/credentials/sets/cert_cache.c index e8f0e7ec0..563f4bdd5 100644 --- a/src/libstrongswan/credentials/sets/cert_cache.c +++ b/src/libstrongswan/credentials/sets/cert_cache.c @@ -16,7 +16,6 @@ #include "cert_cache.h" #include <time.h> -#include <sched.h> #include <library.h> #include <threading/rwlock.h> diff --git a/src/libstrongswan/credentials/sets/mem_cred.c b/src/libstrongswan/credentials/sets/mem_cred.c index b8da3f620..d8f568d36 100644 --- a/src/libstrongswan/credentials/sets/mem_cred.c +++ b/src/libstrongswan/credentials/sets/mem_cred.c @@ -307,8 +307,25 @@ METHOD(credential_set_t, create_private_enumerator, enumerator_t*, METHOD(mem_cred_t, add_key, void, private_mem_cred_t *this, private_key_t *key) { + enumerator_t *enumerator; + private_key_t *current; + this->lock->write_lock(this->lock); + + enumerator = this->keys->create_enumerator(this->keys); + while (enumerator->enumerate(enumerator, ¤t)) + { + if (current->equals(current, key)) + { + this->keys->remove_at(this->keys, enumerator); + current->destroy(current); + break; + } + } + enumerator->destroy(enumerator); + this->keys->insert_first(this->keys, key); + this->lock->unlock(this->lock); } @@ -334,6 +351,44 @@ static void shared_entry_destroy(shared_entry_t *entry) } /** + * Check if two shared key entries equal + */ +static bool shared_entry_equals(shared_entry_t *a, shared_entry_t *b) +{ + enumerator_t *e1, *e2; + identification_t *id1, *id2; + bool equals = TRUE; + + if (a->shared->get_type(a->shared) != b->shared->get_type(b->shared)) + { + return FALSE; + } + if (!chunk_equals(a->shared->get_key(a->shared), + b->shared->get_key(b->shared))) + { + return FALSE; + } + if (a->owners->get_count(a->owners) != b->owners->get_count(b->owners)) + { + return FALSE; + } + e1 = a->owners->create_enumerator(a->owners); + e2 = b->owners->create_enumerator(b->owners); + while (e1->enumerate(e1, &id1) && e2->enumerate(e2, &id2)) + { + if (!id1->equals(id1, id2)) + { + equals = FALSE; + break; + } + } + e1->destroy(e1); + e2->destroy(e2); + + return equals; +} + +/** * Data for the shared_key enumerator */ typedef struct { @@ -435,15 +490,30 @@ METHOD(credential_set_t, create_shared_enumerator, enumerator_t*, METHOD(mem_cred_t, add_shared_list, void, private_mem_cred_t *this, shared_key_t *shared, linked_list_t* owners) { - shared_entry_t *entry; + shared_entry_t *current, *new; + enumerator_t *enumerator; - INIT(entry, + INIT(new, .shared = shared, .owners = owners, ); this->lock->write_lock(this->lock); - this->shared->insert_first(this->shared, entry); + + enumerator = this->shared->create_enumerator(this->shared); + while (enumerator->enumerate(enumerator, ¤t)) + { + if (shared_entry_equals(current, new)) + { + this->shared->remove_at(this->shared, enumerator); + shared_entry_destroy(current); + break; + } + } + enumerator->destroy(enumerator); + + this->shared->insert_first(this->shared, new); + this->lock->unlock(this->lock); } |