[PATCH] Support default path for importing openvpn configuration file



Hi,

Generally the openvpn configuration file set the ca, cert and key file
without the absolute path, and
the openvpn could find these file in the same path of the
configuration file. Just run this:

# openvpn --config Client-config.ovpn

openvpn works fine. Client-config.ovpn, ca.crt client.crt and
client.key in the same directory.

And when I import the openvpn configuration file, the
nm-connection-editor couldn't set the ca, cert and key file.

This patch will works for it.


Sincerely Yours,

Bin Li

http://cn.opensuse.org
--- import-export.c.orig	2008-09-16 10:53:41.000000000 +0800
+++ import-export.c	2008-10-24 12:02:34.000000000 +0800
@@ -61,9 +61,10 @@
                   const char *tag,
                   const char *key,
                   GHashTable *hash,
+                  const char *path,
                   char **leftover)
 {
-	char *tmp, *file, *unquoted, *p;
+	char *tmp, *file, *unquoted, *p, *full_path;
 	gboolean quoted = FALSE;
 
 	if (leftover)
@@ -77,6 +78,12 @@
 	if (!strlen (file))
 		goto out;
 
+	/* If file isn't an absolute file name, add the default path */
+	if (!g_path_is_absolute (file)) {
+		full_path = g_strdup_printf ("%s/%s", path, file);
+		file = full_path;
+	}
+
 	/* Simple unquote */
 	if ((file[0] == '"') || (file[0] == '\'')) {
 		quoted = TRUE;
@@ -108,6 +115,8 @@
 
 out:
 	g_free (tmp);
+	if (full_path)
+		g_free (full_path);
 	return TRUE;
 }
 
@@ -162,6 +171,7 @@
 	gboolean have_client = FALSE, have_remote = FALSE;
 	gboolean have_pass = FALSE, have_sk = FALSE;
 	const char *ctype = NULL;
+	char *default_path;
 
 	connection = nm_connection_new ();
 	s_con = NM_SETTING_CONNECTION (nm_setting_connection_new ());
@@ -170,6 +180,10 @@
 	s_vpn = NM_SETTING_VPN (nm_setting_vpn_new ());
 	s_vpn->service_type = g_strdup (NM_DBUS_SERVICE_OPENVPN);
 
+	/* Get the default path for ca, cert, key file, these files maybe
+	 * in same path with the configuration file */
+	default_path = g_path_get_dirname (path);
+
 	s_con->id = g_path_get_basename (path);
 	last_dot = strrchr (s_con->id, '.');
 	if (last_dot)
@@ -252,17 +266,17 @@
 			continue;
 		}
 
-		if (handle_path_item (*line, CA_TAG, NM_OPENVPN_KEY_CA, s_vpn->data, NULL))
+		if (handle_path_item (*line, CA_TAG, NM_OPENVPN_KEY_CA, s_vpn->data, default_path, NULL))
 			continue;
 
-		if (handle_path_item (*line, CERT_TAG, NM_OPENVPN_KEY_CERT, s_vpn->data, NULL))
+		if (handle_path_item (*line, CERT_TAG, NM_OPENVPN_KEY_CERT, s_vpn->data, default_path, NULL))
 			continue;
 
-		if (handle_path_item (*line, KEY_TAG, NM_OPENVPN_KEY_KEY, s_vpn->data, NULL))
+		if (handle_path_item (*line, KEY_TAG, NM_OPENVPN_KEY_KEY, s_vpn->data, default_path, NULL))
 			continue;
 
 		if (handle_path_item (*line, SECRET_TAG, NM_OPENVPN_KEY_STATIC_KEY,
-		                      s_vpn->data, &leftover)) {
+		                      s_vpn->data, default_path, &leftover)) {
 			handle_direction ("secret",
 			                  NM_OPENVPN_KEY_STATIC_KEY_DIRECTION,
 			                  leftover,
@@ -271,7 +285,7 @@
 		}
 
 		if (handle_path_item (*line, TLS_AUTH_TAG, NM_OPENVPN_KEY_TA,
-		                      s_vpn->data, &leftover)) {
+		                      s_vpn->data, default_path, &leftover)) {
 			handle_direction ("tls-auth",
 			                  NM_OPENVPN_KEY_TA_DIR,
 			                  leftover,


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]