]> www.infradead.org Git - users/dwmw2/openconnect.git/commitdiff
Move localname setter to openconnect_vpninfo_new
authorJan-Michael Brummer <jan-michael.brummer1@volkswagen.de>
Wed, 11 Jun 2025 13:41:51 +0000 (15:41 +0200)
committerJan-Michael Brummer <jan-michael.brummer1@volkswagen.de>
Tue, 2 Sep 2025 13:21:17 +0000 (15:21 +0200)
Currently localname was only set for CLI version and thus
every application making use of openconnect_vpninfo_new had localhost
as default name. This can cause issues with e.g. PAN and thus
move it to this function to ensure every consumer is safe.

Signed-off-by: Jan-Michael Brummer <jan-michael.brummer1@volkswagen.de>
library.c
main.c

index 2bf6eb961690805fe89d7b76a44866781d04fe5c..5185f03522aa4f4b1d3e019f6643148810e7eacc 100644 (file)
--- a/library.c
+++ b/library.c
@@ -54,6 +54,7 @@ struct openconnect_info *openconnect_vpninfo_new(const char *useragent,
 #ifdef HAVE_ICONV
        char *charset = nl_langinfo(CODESET);
 #endif
+       char hostname[256] = {'\0'};
 
        if (!vpninfo)
                return NULL;
@@ -216,6 +217,22 @@ struct openconnect_info *openconnect_vpninfo_new(const char *useragent,
        vpninfo->sso_browser_mode = NULL;
        vpninfo->verbose = PRG_TRACE;
        vpninfo->cbdata = privdata ? : vpninfo;
+
+       if (gethostname(hostname, sizeof(hostname)) == 0 && hostname[0]) {
+               char *localname;
+
+               localname = openconnect_legacy_to_utf8(vpninfo, hostname);
+               if (localname == hostname)
+                       vpninfo->localname = strdup(hostname);
+               else
+                       vpninfo->localname = localname;
+       } else {
+               vpninfo->localname = strdup("localhost");
+       }
+
+       if (!vpninfo->localname)
+               goto err;
+
        vpninfo->validate_peer_cert = validate_peer_cert;
        vpninfo->write_new_config = write_new_config;
        vpninfo->process_auth_form = process_auth_form;
@@ -236,8 +253,6 @@ struct openconnect_info *openconnect_vpninfo_new(const char *useragent,
                        goto err;
        }
 #endif
-       if (!(vpninfo->localname = strdup("localhost")))
-               goto err;
        if (!(vpninfo->useragent = openconnect_create_useragent(useragent)))
                goto err;
        openconnect_set_reported_os(vpninfo, NULL);
diff --git a/main.c b/main.c
index 9ea9618e4f85c322defe642e2ec61761e98cc2ff..9c048be7ef97d8118ccbf9537bcae4ce090cd7e0 100644 (file)
--- a/main.c
+++ b/main.c
@@ -48,7 +48,6 @@
 #include <wtypes.h>
 #include <wincon.h>
 #else
-#include <sys/utsname.h>
 #include <pwd.h>
 #include <termios.h>
 #endif
@@ -1796,7 +1795,6 @@ int main(int argc, char *argv[])
 #endif
 #ifndef _WIN32
        struct sigaction sa;
-       struct utsname utsbuf;
 #endif
 
 #ifdef ENABLE_NLS
@@ -1875,10 +1873,6 @@ int main(int argc, char *argv[])
        vpninfo->use_tun_script = 0;
        vpninfo->uid = getuid();
        vpninfo->gid = getgid();
-
-       if (!uname(&utsbuf)) {
-               openconnect_set_localname(vpninfo, utsbuf.nodename);
-       }
 #endif
 
        while ((opt = next_option(argc, argv, &config_arg))) {