vici: Return authentication rounds with unique names
authorMartin Willi <martin@revosec.ch>
Fri, 27 Feb 2015 13:28:47 +0000 (14:28 +0100)
committerMartin Willi <martin@revosec.ch>
Wed, 18 Mar 2015 12:59:14 +0000 (13:59 +0100)
To simplify handling of authentication rounds in dictionaries/hashtables on the
client side, we assign unique names to each authentication round when listing
connection.

src/libcharon/plugins/vici/vici_query.c
src/swanctl/commands/list_conns.c

index 7e4e241..84fc23c 100644 (file)
@@ -508,11 +508,14 @@ static void build_auth_cfgs(peer_cfg_t *peer_cfg, bool local, vici_builder_t *b)
                certificate_t *cert;
                char *str;
        } v;
+       char buf[32];
+       int i = 0;
 
        enumerator = peer_cfg->create_auth_cfg_enumerator(peer_cfg, local);
        while (enumerator->enumerate(enumerator, &auth))
        {
-               b->begin_section(b, local ? "local" : "remote");
+               snprintf(buf, sizeof(buf), "%s-%d", local ? "local" : "remote", ++i);
+               b->begin_section(b, buf);
 
                rules = auth->create_enumerator(auth);
                while (rules->enumerate(rules, &rule, &v))
index 31ab9c4..019c888 100644 (file)
@@ -103,7 +103,7 @@ CALLBACK(conn_sn, int,
        {
                return vici_parse_cb(res, children_sn, NULL, NULL, NULL);
        }
-       if (streq(name, "local") || streq(name, "remote"))
+       if (strpfx(name, "local") || strpfx(name, "remote"))
        {
                hashtable_t *auth;
 
@@ -112,7 +112,8 @@ CALLBACK(conn_sn, int,
                if (ret == 0)
                {
                        printf("  %s %s authentication:\n",
-                               name, auth->get(auth, "class") ?: "unspecified");
+                               strpfx(name, "local") ? "local" : "remote",
+                               auth->get(auth, "class") ?: "unspecified");
                        if (auth->get(auth, "id"))
                        {
                                printf("    id: %s\n", auth->get(auth, "id"));