Use auth_cfg_t.replace_value where appropriate.
authorTobias Brunner <tobias@strongswan.org>
Fri, 13 Apr 2012 13:47:25 +0000 (15:47 +0200)
committerTobias Brunner <tobias@strongswan.org>
Mon, 16 Apr 2012 11:44:27 +0000 (13:44 +0200)
src/libcharon/sa/authenticators/eap_authenticator.c
src/libcharon/sa/tasks/ike_auth.c

index c85a45f..7284dfc 100644 (file)
@@ -218,23 +218,15 @@ static eap_payload_t* server_initiate_eap(private_eap_authenticator_t *this,
  */
 static void replace_eap_identity(private_eap_authenticator_t *this)
 {
-       enumerator_t *enumerator;
-       auth_rule_t rule;
+       identification_t *eap_identity;
        auth_cfg_t *cfg;
-       void *ptr;
 
+       eap_identity = this->eap_identity->clone(this->eap_identity);
        cfg = this->ike_sa->get_auth_cfg(this->ike_sa, FALSE);
-       enumerator = cfg->create_enumerator(cfg);
-       while (enumerator->enumerate(enumerator, &rule, &ptr))
+       if (!cfg->replace_value(cfg, AUTH_RULE_EAP_IDENTITY, eap_identity))
        {
-               if (rule == AUTH_RULE_EAP_IDENTITY)
-               {
-                       cfg->replace(cfg, enumerator, AUTH_RULE_EAP_IDENTITY,
-                                                this->eap_identity->clone(this->eap_identity));
-                       break;
-               }
+               eap_identity->destroy(eap_identity);
        }
-       enumerator->destroy(enumerator);
 }
 
 /**
index 1ef2162..ae8ef0a 100644 (file)
@@ -424,24 +424,11 @@ METHOD(task_t, build_i, status_t,
                }
                else if (idi->get_type(idi) == ID_ANY)
                {       /* ID_ANY is invalid as IDi, use local IP address instead */
-                       enumerator_t *enumerator;
-                       auth_rule_t rule;
                        host_t *me;
-                       void *data;
 
                        me = this->ike_sa->get_my_host(this->ike_sa);
                        idi = identification_create_from_sockaddr(me->get_sockaddr(me));
-                       enumerator = cfg->create_enumerator(cfg);
-                       while (enumerator->enumerate(enumerator, &rule, &data))
-                       {
-                               if (rule == AUTH_RULE_IDENTITY)
-                               {
-                                       cfg->replace(cfg, enumerator, AUTH_RULE_IDENTITY,
-                                                                idi);
-                                       break;
-                               }
-                       }
-                       enumerator->destroy(enumerator);
+                       cfg->replace_value(cfg, AUTH_RULE_IDENTITY, idi);
                }
                this->ike_sa->set_my_id(this->ike_sa, idi->clone(idi));
                id_payload = id_payload_create_from_identification(ID_INITIATOR, idi);