NetworkManager-openconnect /etc/nm-openconnect/openconnect.ini

Grant Williamson traxtopel at gmail.com
Thu Jun 8 02:29:39 PDT 2023


The following patch allows for the addition of arguments through a
system file. The patch looks for a file named "openconnect.ini" in the
"/etc/nm-openconnect/" directory. If the file exists, it reads its
contents and searches for a line that starts with "ARGS=". If such a
line is found, it extracts the arguments and adds them to the
/usr/sbin/openconnect that is spawn during connecting.

This patch probably needs need some tlc.

diff -ur NetworkManager-openconnect-1.2.10.orig/src/nm-openconnect-service.c
NetworkManager-openconnect-1.2.10/src/nm-openconnect-service.c
--- NetworkManager-openconnect-1.2.10.orig/src/nm-openconnect-service.c
2023-05-10 12:10:35.000000000 +0200
+++ NetworkManager-openconnect-1.2.10/src/nm-openconnect-service.c
2023-06-08 11:06:26.306545502 +0200
@@ -41,6 +41,7 @@
 #include <pwd.h>
 #include <grp.h>
 #include <locale.h>
+#include <glib.h>

 #include "nm-utils/nm-shared-utils.h"
 #include "nm-utils/nm-vpn-plugin-macros.h"
@@ -581,6 +582,37 @@
  g_ptr_array_add (openconnect_argv, (gpointer) "--verbose");
  }

+  // Allow for arguments to be added via a system file
+  char systemCommand[MAX_ARGS_LENGTH];
+  FILE *file = fopen("/etc/nm-openconnect/openconnect.ini", "r");
+  if (file != NULL) {
+    char args[MAX_ARGS_LENGTH];
+    while (fgets(args, sizeof(args), file)) {
+      if (strncmp(args, "ARGS=", 5) == 0) {
+        memmove(args, args + 5, strlen(args) - 5 + 1);
+        break;
+      }
+    }
+    fclose(file);
+    if (strlen(args) > 0) {
+      char *quoteStart = strchr(args, '\"');
+      if (quoteStart != NULL) {
+        char *quoteEnd = strchr(quoteStart + 1, '\"');
+        if (quoteEnd != NULL) {
+            memmove(quoteStart, quoteStart + 1, quoteEnd - quoteStart);
+            quoteEnd[-1] = '\0';
+        }
+      }
+      char *token;  // Declaration of 'token'
+      char *delimiter = " ";  // Delimiter for strtok
+      token = strtok(args, delimiter);
+      while (token != NULL) {
+        g_ptr_array_add (openconnect_argv, token);
+        token = strtok(NULL, delimiter);
+      }
+    }
+  }
+
  g_ptr_array_add (openconnect_argv, NULL);

  if (!g_spawn_async_with_pipes (NULL, (char **) openconnect_argv->pdata, NULL,
diff -ur NetworkManager-openconnect-1.2.10.orig/src/nm-openconnect-service.h
NetworkManager-openconnect-1.2.10/src/nm-openconnect-service.h
--- NetworkManager-openconnect-1.2.10.orig/src/nm-openconnect-service.h
2019-08-06 13:34:19.000000000 +0200
+++ NetworkManager-openconnect-1.2.10/src/nm-openconnect-service.h
2023-06-08 11:05:33.871183932 +0200
@@ -31,6 +31,7 @@
 #define NM_IS_OPENCONNECT_PLUGIN(obj)
(G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_OPENCONNECT_PLUGIN))
 #define NM_IS_OPENCONNECT_PLUGIN_CLASS(klass)
(G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_OPENCONNECT_PLUGIN))
 #define NM_OPENCONNECT_PLUGIN_GET_CLASS(obj)
(G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_OPENCONNECT_PLUGIN,
NMOpenconnectPluginClass))
+#define MAX_ARGS_LENGTH 1024

 typedef struct {
  NMVpnServicePlugin parent;



More information about the openconnect-devel mailing list