swanctl: Allow passing a custom config file for each --load* command
Mainly for debugging, but could also be used to e.g. use a separate file for connections and secrets.
This commit is contained in:
@@ -31,8 +31,8 @@ static int load_all(vici_conn_t *conn)
|
|||||||
bool clear = FALSE, noprompt = FALSE;
|
bool clear = FALSE, noprompt = FALSE;
|
||||||
command_format_options_t format = COMMAND_FORMAT_NONE;
|
command_format_options_t format = COMMAND_FORMAT_NONE;
|
||||||
settings_t *cfg;
|
settings_t *cfg;
|
||||||
|
char *arg, *file = SWANCTL_CONF;
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
char *arg;
|
|
||||||
|
|
||||||
while (TRUE)
|
while (TRUE)
|
||||||
{
|
{
|
||||||
@@ -52,6 +52,9 @@ static int load_all(vici_conn_t *conn)
|
|||||||
case 'r':
|
case 'r':
|
||||||
format |= COMMAND_FORMAT_RAW;
|
format |= COMMAND_FORMAT_RAW;
|
||||||
continue;
|
continue;
|
||||||
|
case 'f':
|
||||||
|
file = arg;
|
||||||
|
continue;
|
||||||
case EOF:
|
case EOF:
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@@ -60,10 +63,10 @@ static int load_all(vici_conn_t *conn)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
cfg = settings_create(SWANCTL_CONF);
|
cfg = settings_create(file);
|
||||||
if (!cfg)
|
if (!cfg)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "parsing '%s' failed\n", SWANCTL_CONF);
|
fprintf(stderr, "parsing '%s' failed\n", file);
|
||||||
return EINVAL;
|
return EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -104,6 +107,7 @@ static void __attribute__ ((constructor))reg()
|
|||||||
{"noprompt", 'n', 0, "do not prompt for passwords"},
|
{"noprompt", 'n', 0, "do not prompt for passwords"},
|
||||||
{"raw", 'r', 0, "dump raw response message"},
|
{"raw", 'r', 0, "dump raw response message"},
|
||||||
{"pretty", 'P', 0, "dump raw response message in pretty print"},
|
{"pretty", 'P', 0, "dump raw response message in pretty print"},
|
||||||
|
{"file", 'f', 1, "custom path to swanctl.conf"},
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -310,7 +310,7 @@ static int load_authorities(vici_conn_t *conn)
|
|||||||
{
|
{
|
||||||
command_format_options_t format = COMMAND_FORMAT_NONE;
|
command_format_options_t format = COMMAND_FORMAT_NONE;
|
||||||
settings_t *cfg;
|
settings_t *cfg;
|
||||||
char *arg;
|
char *arg, *file = SWANCTL_CONF;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
while (TRUE)
|
while (TRUE)
|
||||||
@@ -325,6 +325,9 @@ static int load_authorities(vici_conn_t *conn)
|
|||||||
case 'r':
|
case 'r':
|
||||||
format |= COMMAND_FORMAT_RAW;
|
format |= COMMAND_FORMAT_RAW;
|
||||||
continue;
|
continue;
|
||||||
|
case 'f':
|
||||||
|
file = arg;
|
||||||
|
continue;
|
||||||
case EOF:
|
case EOF:
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@@ -333,10 +336,10 @@ static int load_authorities(vici_conn_t *conn)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
cfg = settings_create(SWANCTL_CONF);
|
cfg = settings_create(file);
|
||||||
if (!cfg)
|
if (!cfg)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "parsing '%s' failed\n", SWANCTL_CONF);
|
fprintf(stderr, "parsing '%s' failed\n", file);
|
||||||
return EINVAL;
|
return EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -360,6 +363,7 @@ static void __attribute__ ((constructor))reg()
|
|||||||
{"help", 'h', 0, "show usage information"},
|
{"help", 'h', 0, "show usage information"},
|
||||||
{"raw", 'r', 0, "dump raw response message"},
|
{"raw", 'r', 0, "dump raw response message"},
|
||||||
{"pretty", 'P', 0, "dump raw response message in pretty print"},
|
{"pretty", 'P', 0, "dump raw response message in pretty print"},
|
||||||
|
{"file", 'f', 1, "custom path to swanctl.conf"},
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -425,7 +425,7 @@ static int load_conns(vici_conn_t *conn)
|
|||||||
{
|
{
|
||||||
command_format_options_t format = COMMAND_FORMAT_NONE;
|
command_format_options_t format = COMMAND_FORMAT_NONE;
|
||||||
settings_t *cfg;
|
settings_t *cfg;
|
||||||
char *arg;
|
char *arg, *file = SWANCTL_CONF;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
while (TRUE)
|
while (TRUE)
|
||||||
@@ -440,6 +440,9 @@ static int load_conns(vici_conn_t *conn)
|
|||||||
case 'r':
|
case 'r':
|
||||||
format |= COMMAND_FORMAT_RAW;
|
format |= COMMAND_FORMAT_RAW;
|
||||||
continue;
|
continue;
|
||||||
|
case 'f':
|
||||||
|
file = arg;
|
||||||
|
continue;
|
||||||
case EOF:
|
case EOF:
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@@ -448,10 +451,10 @@ static int load_conns(vici_conn_t *conn)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
cfg = settings_create(SWANCTL_CONF);
|
cfg = settings_create(file);
|
||||||
if (!cfg)
|
if (!cfg)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "parsing '%s' failed\n", SWANCTL_CONF);
|
fprintf(stderr, "parsing '%s' failed\n", file);
|
||||||
return EINVAL;
|
return EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -474,6 +477,7 @@ static void __attribute__ ((constructor))reg()
|
|||||||
{"help", 'h', 0, "show usage information"},
|
{"help", 'h', 0, "show usage information"},
|
||||||
{"raw", 'r', 0, "dump raw response message"},
|
{"raw", 'r', 0, "dump raw response message"},
|
||||||
{"pretty", 'P', 0, "dump raw response message in pretty print"},
|
{"pretty", 'P', 0, "dump raw response message in pretty print"},
|
||||||
|
{"file", 'f', 1, "custom path to swanctl.conf"},
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -946,7 +946,7 @@ static int load_creds(vici_conn_t *conn)
|
|||||||
bool clear = FALSE, noprompt = FALSE;
|
bool clear = FALSE, noprompt = FALSE;
|
||||||
command_format_options_t format = COMMAND_FORMAT_NONE;
|
command_format_options_t format = COMMAND_FORMAT_NONE;
|
||||||
settings_t *cfg;
|
settings_t *cfg;
|
||||||
char *arg;
|
char *arg, *file = SWANCTL_CONF;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
while (TRUE)
|
while (TRUE)
|
||||||
@@ -967,6 +967,9 @@ static int load_creds(vici_conn_t *conn)
|
|||||||
case 'r':
|
case 'r':
|
||||||
format |= COMMAND_FORMAT_RAW;
|
format |= COMMAND_FORMAT_RAW;
|
||||||
continue;
|
continue;
|
||||||
|
case 'f':
|
||||||
|
file = arg;
|
||||||
|
continue;
|
||||||
case EOF:
|
case EOF:
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@@ -975,10 +978,10 @@ static int load_creds(vici_conn_t *conn)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
cfg = settings_create(SWANCTL_CONF);
|
cfg = settings_create(file);
|
||||||
if (!cfg)
|
if (!cfg)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "parsing '%s' failed\n", SWANCTL_CONF);
|
fprintf(stderr, "parsing '%s' failed\n", file);
|
||||||
return EINVAL;
|
return EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1003,6 +1006,7 @@ static void __attribute__ ((constructor))reg()
|
|||||||
{"noprompt", 'n', 0, "do not prompt for passwords"},
|
{"noprompt", 'n', 0, "do not prompt for passwords"},
|
||||||
{"raw", 'r', 0, "dump raw response message"},
|
{"raw", 'r', 0, "dump raw response message"},
|
||||||
{"pretty", 'P', 0, "dump raw response message in pretty print"},
|
{"pretty", 'P', 0, "dump raw response message in pretty print"},
|
||||||
|
{"file", 'f', 1, "custom path to swanctl.conf"},
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -251,7 +251,7 @@ static int load_pools(vici_conn_t *conn)
|
|||||||
{
|
{
|
||||||
command_format_options_t format = COMMAND_FORMAT_NONE;
|
command_format_options_t format = COMMAND_FORMAT_NONE;
|
||||||
settings_t *cfg;
|
settings_t *cfg;
|
||||||
char *arg;
|
char *arg, *file = SWANCTL_CONF;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
while (TRUE)
|
while (TRUE)
|
||||||
@@ -266,6 +266,9 @@ static int load_pools(vici_conn_t *conn)
|
|||||||
case 'r':
|
case 'r':
|
||||||
format |= COMMAND_FORMAT_RAW;
|
format |= COMMAND_FORMAT_RAW;
|
||||||
continue;
|
continue;
|
||||||
|
case 'f':
|
||||||
|
file = arg;
|
||||||
|
continue;
|
||||||
case EOF:
|
case EOF:
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@@ -274,10 +277,10 @@ static int load_pools(vici_conn_t *conn)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
cfg = settings_create(SWANCTL_CONF);
|
cfg = settings_create(file);
|
||||||
if (!cfg)
|
if (!cfg)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "parsing '%s' failed\n", SWANCTL_CONF);
|
fprintf(stderr, "parsing '%s' failed\n", file);
|
||||||
return EINVAL;
|
return EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -300,6 +303,7 @@ static void __attribute__ ((constructor))reg()
|
|||||||
{"help", 'h', 0, "show usage information"},
|
{"help", 'h', 0, "show usage information"},
|
||||||
{"raw", 'r', 0, "dump raw response message"},
|
{"raw", 'r', 0, "dump raw response message"},
|
||||||
{"pretty", 'P', 0, "dump raw response message in pretty print"},
|
{"pretty", 'P', 0, "dump raw response message in pretty print"},
|
||||||
|
{"file", 'f', 1, "custom path to swanctl.conf"},
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user