On Apr 04 12:10 AM, David Woodhouse wrote:
> I'd probably be inclined to suggest we should accept whatever comes
> last. We don't reject multiple '--server xxx' options, do we? It allows
> the value in the config file to be overridden on the command line.

Here is an updated version of the patch that always takes the last
argument without a corresponding --option (if there is such an argument
present) as the server URL regardless of any previous options.

Max

>From fa9c058ed259e2d76fe35c993b155e6bd6c49f50 Mon Sep 17 00:00:00 2001
From: Max Rees <[email protected]>
Date: Mon, 2 Apr 2018 01:28:16 -0400
Subject: [PATCH] Allow specifying server in configuration file

This allows the configuration file to have an entry of the form:
server https://server[:port][/group]
similar to the CLI invocation.

Signed-off-by: Max Rees <[email protected]>
---
 main.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/main.c b/main.c
index d09efd5..7d41811 100644
--- a/main.c
+++ b/main.c
@@ -187,6 +187,7 @@ enum {
        OPT_HTTP_AUTH,
        OPT_LOCAL_HOSTNAME,
        OPT_PROTOCOL,
+       OPT_SERVER,
        OPT_PASSTOS,
 };
 
@@ -269,6 +270,7 @@ static const struct option long_options[] = {
        OPTION("dump-http-traffic", 0, OPT_DUMP_HTTP),
        OPTION("no-system-trust", 0, OPT_NO_SYSTEM_TRUST),
        OPTION("protocol", 1, OPT_PROTOCOL),
+       OPTION("server", 1, OPT_SERVER),
 #ifdef OPENCONNECT_GNUTLS
        OPTION("gnutls-debug", 1, OPT_GNUTLS_DEBUG),
 #endif
@@ -1164,6 +1166,10 @@ int main(int argc, char **argv)
                        if (openconnect_set_protocol(vpninfo, config_arg))
                                exit(1);
                        break;
+               case OPT_SERVER:
+                       if (openconnect_parse_url(vpninfo, config_arg))
+                               exit(1);
+                       break;
                case OPT_JUNIPER:
                        fprintf(stderr, "WARNING: Juniper Network Connect 
support is experimental.\n");
                        fprintf(stderr, "It will probably be superseded by 
Junos Pulse support.\n");
@@ -1457,7 +1463,7 @@ int main(int argc, char **argv)
        if (optind < argc - 1) {
                fprintf(stderr, _("Too many arguments on command line\n"));
                usage();
-       } else if (optind > argc - 1) {
+       } else if (optind > argc - 1 && !vpninfo->hostname) {
                fprintf(stderr, _("No server specified\n"));
                usage();
        }
@@ -1513,7 +1519,10 @@ int main(int argc, char **argv)
        if (config_lookup_host(vpninfo, argv[optind]))
                exit(1);
 
-       if (!vpninfo->hostname) {
+       /* The last argument without a corresponding --option is taken
+        * to be the server URL and overrides any --server option on the
+        * command line or from a --config */
+       if (!vpninfo->hostname || optind < argc) {
                char *url = strdup(argv[optind]);
 
                if (openconnect_parse_url(vpninfo, url))
-- 
2.15.0


_______________________________________________
openconnect-devel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/openconnect-devel

Reply via email to