]> git.ipfire.org Git - thirdparty/strongswan.git/commitdiff
swanctl: Allow passing a custom config file for each --load* command
authorTobias Brunner <tobias@strongswan.org>
Mon, 28 May 2018 15:19:22 +0000 (17:19 +0200)
committerTobias Brunner <tobias@strongswan.org>
Tue, 11 Sep 2018 16:14:45 +0000 (18:14 +0200)
Mainly for debugging, but could also be used to e.g. use a separate file
for connections and secrets.

src/swanctl/commands/load_all.c
src/swanctl/commands/load_authorities.c
src/swanctl/commands/load_conns.c
src/swanctl/commands/load_creds.c
src/swanctl/commands/load_pools.c

index 0010ce140862f888d5c846194a72ea27e0b85277..26f043a6a080df02c9c32d03882c6330a28baa10 100644 (file)
@@ -31,8 +31,8 @@ static int load_all(vici_conn_t *conn)
        bool clear = FALSE, noprompt = FALSE;
        command_format_options_t format = COMMAND_FORMAT_NONE;
        settings_t *cfg;
+       char *arg, *file = SWANCTL_CONF;
        int ret = 0;
-       char *arg;
 
        while (TRUE)
        {
@@ -52,6 +52,9 @@ static int load_all(vici_conn_t *conn)
                        case 'r':
                                format |= COMMAND_FORMAT_RAW;
                                continue;
+                       case 'f':
+                               file = arg;
+                               continue;
                        case EOF:
                                break;
                        default:
@@ -60,10 +63,10 @@ static int load_all(vici_conn_t *conn)
                break;
        }
 
-       cfg = settings_create(SWANCTL_CONF);
+       cfg = settings_create(file);
        if (!cfg)
        {
-               fprintf(stderr, "parsing '%s' failed\n", SWANCTL_CONF);
+               fprintf(stderr, "parsing '%s' failed\n", file);
                return EINVAL;
        }
 
@@ -104,6 +107,7 @@ static void __attribute__ ((constructor))reg()
                        {"noprompt",    'n', 0, "do not prompt for passwords"},
                        {"raw",                 'r', 0, "dump raw response message"},
                        {"pretty",              'P', 0, "dump raw response message in pretty print"},
+                       {"file",                'f', 1, "custom path to swanctl.conf"},
                }
        });
 }
index d82c0f98e249f07de6dda66eaa2ee227872f5c6e..61682a386d82d4a4bc9d7575864ca4d5183dc79c 100644 (file)
@@ -310,7 +310,7 @@ static int load_authorities(vici_conn_t *conn)
 {
        command_format_options_t format = COMMAND_FORMAT_NONE;
        settings_t *cfg;
-       char *arg;
+       char *arg, *file = SWANCTL_CONF;
        int ret;
 
        while (TRUE)
@@ -325,6 +325,9 @@ static int load_authorities(vici_conn_t *conn)
                        case 'r':
                                format |= COMMAND_FORMAT_RAW;
                                continue;
+                       case 'f':
+                               file = arg;
+                               continue;
                        case EOF:
                                break;
                        default:
@@ -333,10 +336,10 @@ static int load_authorities(vici_conn_t *conn)
                break;
        }
 
-       cfg = settings_create(SWANCTL_CONF);
+       cfg = settings_create(file);
        if (!cfg)
        {
-               fprintf(stderr, "parsing '%s' failed\n", SWANCTL_CONF);
+               fprintf(stderr, "parsing '%s' failed\n", file);
                return EINVAL;
        }
 
@@ -360,6 +363,7 @@ static void __attribute__ ((constructor))reg()
                        {"help",                'h', 0, "show usage information"},
                        {"raw",                 'r', 0, "dump raw response message"},
                        {"pretty",              'P', 0, "dump raw response message in pretty print"},
+                       {"file",                'f', 1, "custom path to swanctl.conf"},
                }
        });
 }
index 0518ef54fccdb20f303d9ffa17d2eedac898486a..dad03945d588ca7fe671ee0c373615a8a6866f71 100644 (file)
@@ -425,7 +425,7 @@ static int load_conns(vici_conn_t *conn)
 {
        command_format_options_t format = COMMAND_FORMAT_NONE;
        settings_t *cfg;
-       char *arg;
+       char *arg, *file = SWANCTL_CONF;
        int ret;
 
        while (TRUE)
@@ -440,6 +440,9 @@ static int load_conns(vici_conn_t *conn)
                        case 'r':
                                format |= COMMAND_FORMAT_RAW;
                                continue;
+                       case 'f':
+                               file = arg;
+                               continue;
                        case EOF:
                                break;
                        default:
@@ -448,10 +451,10 @@ static int load_conns(vici_conn_t *conn)
                break;
        }
 
-       cfg = settings_create(SWANCTL_CONF);
+       cfg = settings_create(file);
        if (!cfg)
        {
-               fprintf(stderr, "parsing '%s' failed\n", SWANCTL_CONF);
+               fprintf(stderr, "parsing '%s' failed\n", file);
                return EINVAL;
        }
 
@@ -474,6 +477,7 @@ static void __attribute__ ((constructor))reg()
                        {"help",                'h', 0, "show usage information"},
                        {"raw",                 'r', 0, "dump raw response message"},
                        {"pretty",              'P', 0, "dump raw response message in pretty print"},
+                       {"file",                'f', 1, "custom path to swanctl.conf"},
                }
        });
 }
index 63a3bdcf88069574aedf4bdb6fbcb9bde2b96cdd..a9e352f7e34dbdf0b883448ab3ccad57a86b092a 100644 (file)
@@ -946,7 +946,7 @@ static int load_creds(vici_conn_t *conn)
        bool clear = FALSE, noprompt = FALSE;
        command_format_options_t format = COMMAND_FORMAT_NONE;
        settings_t *cfg;
-       char *arg;
+       char *arg, *file = SWANCTL_CONF;
        int ret;
 
        while (TRUE)
@@ -967,6 +967,9 @@ static int load_creds(vici_conn_t *conn)
                        case 'r':
                                format |= COMMAND_FORMAT_RAW;
                                continue;
+                       case 'f':
+                               file = arg;
+                               continue;
                        case EOF:
                                break;
                        default:
@@ -975,10 +978,10 @@ static int load_creds(vici_conn_t *conn)
                break;
        }
 
-       cfg = settings_create(SWANCTL_CONF);
+       cfg = settings_create(file);
        if (!cfg)
        {
-               fprintf(stderr, "parsing '%s' failed\n", SWANCTL_CONF);
+               fprintf(stderr, "parsing '%s' failed\n", file);
                return EINVAL;
        }
 
@@ -1003,6 +1006,7 @@ static void __attribute__ ((constructor))reg()
                        {"noprompt",    'n', 0, "do not prompt for passwords"},
                        {"raw",                 'r', 0, "dump raw response message"},
                        {"pretty",              'P', 0, "dump raw response message in pretty print"},
+                       {"file",                'f', 1, "custom path to swanctl.conf"},
                }
        });
 }
index feb8d3a5211357cda2af18925de9f7ead6b73248..ec9508efb50c0d3f5808718c0efc85f5155cd26b 100644 (file)
@@ -251,7 +251,7 @@ static int load_pools(vici_conn_t *conn)
 {
        command_format_options_t format = COMMAND_FORMAT_NONE;
        settings_t *cfg;
-       char *arg;
+       char *arg, *file = SWANCTL_CONF;
        int ret;
 
        while (TRUE)
@@ -266,6 +266,9 @@ static int load_pools(vici_conn_t *conn)
                        case 'r':
                                format |= COMMAND_FORMAT_RAW;
                                continue;
+                       case 'f':
+                               file = arg;
+                               continue;
                        case EOF:
                                break;
                        default:
@@ -274,10 +277,10 @@ static int load_pools(vici_conn_t *conn)
                break;
        }
 
-       cfg = settings_create(SWANCTL_CONF);
+       cfg = settings_create(file);
        if (!cfg)
        {
-               fprintf(stderr, "parsing '%s' failed\n", SWANCTL_CONF);
+               fprintf(stderr, "parsing '%s' failed\n", file);
                return EINVAL;
        }
 
@@ -300,6 +303,7 @@ static void __attribute__ ((constructor))reg()
                        {"help",                'h', 0, "show usage information"},
                        {"raw",                 'r', 0, "dump raw response message"},
                        {"pretty",              'P', 0, "dump raw response message in pretty print"},
+                       {"file",                'f', 1, "custom path to swanctl.conf"},
                }
        });
 }