accepting stroke initiation by a name of a child_cfg
[strongswan.git] / src / charon / config / backends / local_backend.c
index e3449fe..be6fc92 100644 (file)
@@ -171,20 +171,38 @@ static peer_cfg_t *get_peer_cfg(private_local_backend_t *this,
 static peer_cfg_t *get_peer_cfg_by_name(private_local_backend_t *this,
                                                                                char *name)
 {
-       iterator_t *iterator;
+       iterator_t *i1, *i2;
        peer_cfg_t *current, *found = NULL;
+       child_cfg_t *child;
        
-       iterator = this->cfgs->create_iterator(this->cfgs, TRUE);
-       while (iterator->iterate(iterator, (void**)&current))
+       i1 = this->cfgs->create_iterator(this->cfgs, TRUE);
+       while (i1->iterate(i1, (void**)&current))
        {
+               /* compare peer_cfgs name first */
                if (streq(current->get_name(current), name))
                {
                        found = current;
                        found->get_ref(found);
                        break;
                }
+               /* compare all child_cfg names otherwise */
+               i2 = current->create_child_cfg_iterator(current);
+               while (i2->iterate(i2, (void**)&child))
+               {
+                       if (streq(child->get_name(child), name))
+                       {
+                               found = current;
+                               found->get_ref(found);
+                               break;
+                       }
+               }
+               i2->destroy(i2);
+               if (found)
+               {
+                       break;
+               }
        }
-       iterator->destroy(iterator);
+       i1->destroy(i1);
        return found;
 }
 
@@ -224,8 +242,8 @@ local_backend_t *local_backend_create(void)
        
        this->public.backend.get_ike_cfg = (ike_cfg_t*(*)(backend_t*, host_t *, host_t *))get_ike_cfg;
        this->public.backend.get_peer_cfg = (peer_cfg_t*(*)(backend_t*, identification_t *, identification_t *))get_peer_cfg;
-       this->public.backend.get_peer_cfg_by_name = (peer_cfg_t*(*)(backend_t*, char *))get_peer_cfg_by_name;
-    this->public.create_peer_cfg_iterator = (iterator_t*(*)(local_backend_t*))create_peer_cfg_iterator;
+       this->public.create_peer_cfg_iterator = (iterator_t*(*)(local_backend_t*))create_peer_cfg_iterator;
+       this->public.get_peer_cfg_by_name = (peer_cfg_t*(*)(local_backend_t*, char *))get_peer_cfg_by_name;
     this->public.add_peer_cfg = (void(*)(local_backend_t*, peer_cfg_t *))add_peer_cfg;
     this->public.destroy = (void(*)(local_backend_t*))destroy;