aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorTobias Brunner <tobias@strongswan.org>2012-04-13 15:46:23 +0200
committerTobias Brunner <tobias@strongswan.org>2012-04-16 13:44:27 +0200
commit68cca941cf15bc24d1b23935a1935a13c42e3c78 (patch)
tree5369996e5a28f28dd918c86cf88e9f64bfccf020 /src
parent4b32bde48ef02775b3fb00c4ccfeef8bb929cea2 (diff)
downloadstrongswan-68cca941cf15bc24d1b23935a1935a13c42e3c78.tar.bz2
strongswan-68cca941cf15bc24d1b23935a1935a13c42e3c78.tar.xz
Added a simple method to replace the value of a rule in auth_cfg_t.
Diffstat (limited to 'src')
-rw-r--r--src/libstrongswan/credentials/auth_cfg.c95
-rw-r--r--src/libstrongswan/credentials/auth_cfg.h11
2 files changed, 74 insertions, 32 deletions
diff --git a/src/libstrongswan/credentials/auth_cfg.c b/src/libstrongswan/credentials/auth_cfg.c
index 4b5dbbcf7..e490b80b8 100644
--- a/src/libstrongswan/credentials/auth_cfg.c
+++ b/src/libstrongswan/credentials/auth_cfg.c
@@ -1,6 +1,6 @@
/*
+ * Copyright (C) 2008-2012 Tobias Brunner
* Copyright (C) 2007-2009 Martin Willi
- * Copyright (C) 2008 Tobias Brunner
* Hochschule fuer Technik Rapperswil
*
* This program is free software; you can redistribute it and/or modify it
@@ -177,6 +177,44 @@ static void destroy_entry_value(entry_t *entry)
}
/**
+ * Replace the type and value of the given entry.
+ */
+static void replace_entry(entry_t *entry, auth_rule_t type, va_list args)
+{
+ destroy_entry_value(entry);
+ entry->type = type;
+ switch (type)
+ {
+ case AUTH_RULE_AUTH_CLASS:
+ case AUTH_RULE_EAP_TYPE:
+ case AUTH_RULE_EAP_VENDOR:
+ case AUTH_RULE_CRL_VALIDATION:
+ case AUTH_RULE_OCSP_VALIDATION:
+ case AUTH_RULE_RSA_STRENGTH:
+ case AUTH_RULE_ECDSA_STRENGTH:
+ /* integer type */
+ entry->value = (void*)(uintptr_t)va_arg(args, u_int);
+ break;
+ case AUTH_RULE_IDENTITY:
+ case AUTH_RULE_EAP_IDENTITY:
+ case AUTH_RULE_AAA_IDENTITY:
+ case AUTH_RULE_GROUP:
+ case AUTH_RULE_CA_CERT:
+ case AUTH_RULE_IM_CERT:
+ case AUTH_RULE_SUBJECT_CERT:
+ case AUTH_RULE_CERT_POLICY:
+ case AUTH_HELPER_IM_CERT:
+ case AUTH_HELPER_SUBJECT_CERT:
+ case AUTH_HELPER_IM_HASH_URL:
+ case AUTH_HELPER_SUBJECT_HASH_URL:
+ case AUTH_HELPER_REVOCATION_CERT:
+ /* pointer type */
+ entry->value = va_arg(args, void*);
+ break;
+ }
+}
+
+/**
* Implementation of auth_cfg_t.replace.
*/
static void replace(private_auth_cfg_t *this, entry_enumerator_t *enumerator,
@@ -187,40 +225,34 @@ static void replace(private_auth_cfg_t *this, entry_enumerator_t *enumerator,
va_list args;
va_start(args, type);
+ replace_entry(enumerator->current, type, args);
+ va_end(args);
+ }
+}
- destroy_entry_value(enumerator->current);
- enumerator->current->type = type;
- switch (type)
+METHOD(auth_cfg_t, replace_value, bool,
+ private_auth_cfg_t *this, auth_rule_t type, ...)
+{
+ enumerator_t *enumerator;
+ entry_t *entry;
+ bool found = FALSE;
+
+ enumerator = this->entries->create_enumerator(this->entries);
+ while (enumerator->enumerate(enumerator, &entry))
+ {
+ if (type == entry->type)
{
- case AUTH_RULE_AUTH_CLASS:
- case AUTH_RULE_EAP_TYPE:
- case AUTH_RULE_EAP_VENDOR:
- case AUTH_RULE_CRL_VALIDATION:
- case AUTH_RULE_OCSP_VALIDATION:
- case AUTH_RULE_RSA_STRENGTH:
- case AUTH_RULE_ECDSA_STRENGTH:
- /* integer type */
- enumerator->current->value = (void*)(uintptr_t)va_arg(args, u_int);
- break;
- case AUTH_RULE_IDENTITY:
- case AUTH_RULE_EAP_IDENTITY:
- case AUTH_RULE_AAA_IDENTITY:
- case AUTH_RULE_GROUP:
- case AUTH_RULE_CA_CERT:
- case AUTH_RULE_IM_CERT:
- case AUTH_RULE_SUBJECT_CERT:
- case AUTH_RULE_CERT_POLICY:
- case AUTH_HELPER_IM_CERT:
- case AUTH_HELPER_SUBJECT_CERT:
- case AUTH_HELPER_IM_HASH_URL:
- case AUTH_HELPER_SUBJECT_HASH_URL:
- case AUTH_HELPER_REVOCATION_CERT:
- /* pointer type */
- enumerator->current->value = va_arg(args, void*);
- break;
+ va_list args;
+
+ va_start(args, type);
+ replace_entry(entry, type, args);
+ va_end(args);
+ found = TRUE;
+ break;
}
- va_end(args);
}
+ enumerator->destroy(enumerator);
+ return found;
}
METHOD(auth_cfg_t, get, void*,
@@ -883,6 +915,7 @@ auth_cfg_t *auth_cfg_create()
.get = _get,
.create_enumerator = _create_enumerator,
.replace = (void(*)(auth_cfg_t*,enumerator_t*,auth_rule_t,...))replace,
+ .replace_value = _replace_value,
.complies = _complies,
.merge = (void(*)(auth_cfg_t*,auth_cfg_t*,bool))merge,
.purge = _purge,
diff --git a/src/libstrongswan/credentials/auth_cfg.h b/src/libstrongswan/credentials/auth_cfg.h
index f29b01bd5..79ca95820 100644
--- a/src/libstrongswan/credentials/auth_cfg.h
+++ b/src/libstrongswan/credentials/auth_cfg.h
@@ -1,6 +1,6 @@
/*
+ * Copyright (C) 2008-2012 Tobias Brunner
* Copyright (C) 2007-2009 Martin Willi
- * Copyright (C) 2008 Tobias Brunner
* Hochschule fuer Technik Rapperswil
*
* This program is free software; you can redistribute it and/or modify it
@@ -182,6 +182,15 @@ struct auth_cfg_t {
auth_rule_t rule, ...);
/**
+ * Replace the value of the first rule with the given type.
+ *
+ * @param rule rule type
+ * @param ... associated value to rule
+ * @return TRUE if the rule was found and the value replaced
+ */
+ bool (*replace_value)(auth_cfg_t *this, auth_rule_t rule, ...);
+
+ /**
* Check if a used config fulfills a set of configured constraints.
*
* @param constraints required authorization rules