Accept NULL identities passed to peer config enumeration
[strongswan.git] / src / libcharon / config / backend_manager.c
index 7b69eda..c84da25 100644 (file)
@@ -96,6 +96,11 @@ static ike_cfg_match_t get_ike_match(ike_cfg_t *cand, host_t *me, host_t *other)
                {
                        match += MATCH_ANY;
                }
                {
                        match += MATCH_ANY;
                }
+               else
+               {
+                       me_cand->destroy(me_cand);
+                       return MATCH_NONE;
+               }
                me_cand->destroy(me_cand);
        }
        else
                me_cand->destroy(me_cand);
        }
        else
@@ -119,6 +124,11 @@ static ike_cfg_match_t get_ike_match(ike_cfg_t *cand, host_t *me, host_t *other)
                {
                        match += MATCH_ANY;
                }
                {
                        match += MATCH_ANY;
                }
+               else
+               {
+                       other_cand->destroy(other_cand);
+                       return MATCH_NONE;
+               }
                other_cand->destroy(other_cand);
        }
        else
                other_cand->destroy(other_cand);
        }
        else
@@ -150,7 +160,7 @@ METHOD(backend_manager_t, get_ike_cfg, ike_cfg_t*,
        while (enumerator->enumerate(enumerator, (void**)&current))
        {
                match = get_ike_match(current, me, other);
        while (enumerator->enumerate(enumerator, (void**)&current))
        {
                match = get_ike_match(current, me, other);
-
+               DBG3(DBG_CFG, "ike config match: %d (%H %H)", match, me, other);
                if (match)
                {
                        DBG2(DBG_CFG, "  candidate: %s...%s, prio %d",
                if (match)
                {
                        DBG2(DBG_CFG, "  candidate: %s...%s, prio %d",
@@ -185,9 +195,12 @@ static id_match_t get_peer_match(identification_t *id,
        auth_cfg_t *auth;
        identification_t *candidate;
        id_match_t match = ID_MATCH_NONE;
        auth_cfg_t *auth;
        identification_t *candidate;
        id_match_t match = ID_MATCH_NONE;
+       chunk_t data;
 
        if (!id)
        {
 
        if (!id)
        {
+               DBG3(DBG_CFG, "peer config match %s: %d (%N)",
+                        local ? "local" : "remote", ID_MATCH_ANY, id_type_names, ID_ANY);
                return ID_MATCH_ANY;
        }
 
                return ID_MATCH_ANY;
        }
 
@@ -211,6 +224,10 @@ static id_match_t get_peer_match(identification_t *id,
                }
        }
        enumerator->destroy(enumerator);
                }
        }
        enumerator->destroy(enumerator);
+
+       data = id->get_encoding(id);
+       DBG3(DBG_CFG, "peer config match %s: %d (%N -> %#B)",
+                match, id_type_names, id->get_type(id), &data);
        return match;
 }
 
        return match;
 }
 
@@ -345,6 +362,7 @@ METHOD(backend_manager_t, create_peer_cfg_enumerator, enumerator_t*,
                match_peer_me = get_peer_match(my_id, cfg, TRUE);
                match_peer_other = get_peer_match(other_id, cfg, FALSE);
                match_ike = get_ike_match(cfg->get_ike_cfg(cfg), me, other);
                match_peer_me = get_peer_match(my_id, cfg, TRUE);
                match_peer_other = get_peer_match(other_id, cfg, FALSE);
                match_ike = get_ike_match(cfg->get_ike_cfg(cfg), me, other);
+               DBG3(DBG_CFG, "ike config match: %d (%H %H)", match_ike, me, other);
 
                if (match_peer_me && match_peer_other && match_ike)
                {
 
                if (match_peer_me && match_peer_other && match_ike)
                {