summary refs log tree commit diff
path: root/clients/common
diff options
context:
space:
mode:
authorMichael Biebl <biebl@debian.org>2016-01-20 16:26:51 +0100
committerMichael Biebl <biebl@debian.org>2016-01-20 16:26:51 +0100
commit494f296a3baab08522617b24b1f126d8f9a17502 (patch)
treec8ef32fb0dd1c4ff35a0b38e787abb58692de0cd /clients/common
parent54f6333410ffd570e62717d9e77c5c987175e397 (diff)
Imported Upstream version 1.1.90 upstream/1.1.90
Diffstat (limited to 'clients/common')
-rw-r--r--clients/common/nm-polkit-listener.c4
-rw-r--r--clients/common/nm-polkit-listener.h4
-rw-r--r--clients/common/nm-secret-agent-simple.c22
-rw-r--r--clients/common/nm-vpn-helpers.c189
-rw-r--r--clients/common/nm-vpn-helpers.h7
5 files changed, 38 insertions, 188 deletions
diff --git a/clients/common/nm-polkit-listener.c b/clients/common/nm-polkit-listener.c
index c1c7c908..9646374e 100644
--- a/clients/common/nm-polkit-listener.c
+++ b/clients/common/nm-polkit-listener.c
@@ -36,10 +36,8 @@
 #include <string.h>
 #include <stdio.h>
 #include <stdlib.h>
-#include <glib.h>
-#include <glib/gi18n-lib.h>
 
-#include "nm-glib-compat.h"
+#include "nm-default.h"
 #include "nm-polkit-listener.h"
 
 G_DEFINE_TYPE (NMPolkitListener, nm_polkit_listener, POLKIT_AGENT_TYPE_LISTENER)
diff --git a/clients/common/nm-polkit-listener.h b/clients/common/nm-polkit-listener.h
index 3cd75019..22c436c1 100644
--- a/clients/common/nm-polkit-listener.h
+++ b/clients/common/nm-polkit-listener.h
@@ -19,11 +19,11 @@
 #ifndef __NM_POLKIT_LISTENER_H__
 #define __NM_POLKIT_LISTENER_H__
 
-#include <glib.h>
-
 #define POLKIT_AGENT_I_KNOW_API_IS_SUBJECT_TO_CHANGE
 #include <polkitagent/polkitagent.h>
 
+#include "nm-default.h"
+
 G_BEGIN_DECLS
 
 #define NM_TYPE_POLKIT_LISTENER            (nm_polkit_listener_get_type ())
diff --git a/clients/common/nm-secret-agent-simple.c b/clients/common/nm-secret-agent-simple.c
index 6cb6c58d..233e1409 100644
--- a/clients/common/nm-secret-agent-simple.c
+++ b/clients/common/nm-secret-agent-simple.c
@@ -32,13 +32,11 @@
 #include "config.h"
 
 #include <string.h>
-#include <stdlib.h>
-#include <errno.h>
-#include <glib/gi18n-lib.h>
 
 #include <NetworkManager.h>
-#include <nm-core-internal.h>
+#include <nm-vpn-service-plugin.h>
 
+#include "nm-default.h"
 #include "nm-vpn-helpers.h"
 #include "nm-secret-agent-simple.h"
 
@@ -357,23 +355,9 @@ get_vpn_secret_flags (NMSettingVpn *s_vpn, const char *secret_name)
 {
 	NMSettingSecretFlags flags = NM_SETTING_SECRET_FLAG_NONE;
 	GHashTable *vpn_data;
-	char *flag_name;
-	const char *val;
-	unsigned long tmp;
 
 	g_object_get (s_vpn, NM_SETTING_VPN_DATA, &vpn_data, NULL);
-
-	flag_name = g_strdup_printf ("%s-flags", secret_name);
-
-	/* Try new flags value first */
-	val = g_hash_table_lookup (vpn_data, flag_name);
-	if (val) {
-		errno = 0;
-		tmp = strtoul (val, NULL, 10);
-		if (errno == 0 && tmp <= NM_SETTING_SECRET_FLAGS_ALL)
-			flags = (NMSettingSecretFlags) tmp;
-	}
-	g_free (flag_name);
+	nm_vpn_service_plugin_get_secret_flags (vpn_data, secret_name, &flags);
 	g_hash_table_unref (vpn_data);
 
 	return flags;
diff --git a/clients/common/nm-vpn-helpers.c b/clients/common/nm-vpn-helpers.c
index 370e128c..36e8e6b2 100644
--- a/clients/common/nm-vpn-helpers.c
+++ b/clients/common/nm-vpn-helpers.c
@@ -26,184 +26,53 @@
 #include "config.h"
 
 #include <string.h>
-#include <glib.h>
 #include <gmodule.h>
-#include <glib/gi18n-lib.h>
-
-#include <NetworkManager.h>
 
+#include "nm-default.h"
 #include "nm-utils.h"
 #include "nm-vpn-helpers.h"
-#include "nm-glib-compat.h"
-
-#define VPN_NAME_FILES_DIR NMCONFDIR "/VPN"
-#define DEFAULT_DIR_LIB    NMLIBDIR"/VPN"
-
-static gboolean plugins_loaded = FALSE;
-static GHashTable *plugins_hash = NULL;
-static GSList *plugins_list = NULL;
 
+#include "nm-macros-internal.h"
 
-GQuark nm_vpn_error_quark (void);
-G_DEFINE_QUARK (NM_VPN_ERROR, nm_vpn_error)
-#define NM_VPN_ERROR nm_vpn_error_quark ()
-#define NM_VPN_ERROR_GENERIC 0
+static gboolean plugins_loaded;
+static GSList *plugins = NULL;
 
 NMVpnEditorPlugin *
-nm_vpn_get_plugin_by_service (const char *service)
+nm_vpn_get_plugin_by_service (const char *service, GError **error)
 {
-	NMVpnEditorPlugin *plugin;
-	const char *str;
-	char *tmp = NULL;
+	NMVpnEditorPlugin *plugin = NULL;
+	NMVpnPluginInfo *plugin_info;
+	char *type = NULL;
 
 	g_return_val_if_fail (service != NULL, NULL);
+	g_return_val_if_fail (error == NULL || *error == NULL, NULL);
 
 	if (G_UNLIKELY (!plugins_loaded))
-		nm_vpn_get_plugins (NULL);
-
-	if (!plugins_hash)
-		return NULL;
-
-	if (g_str_has_prefix (service, NM_DBUS_SERVICE))
-		str = service;
-	else
-		str = tmp = g_strdup_printf ("%s.%s", NM_DBUS_SERVICE, service);
-
-	plugin = g_hash_table_lookup (plugins_hash, str);
-	g_free (tmp);
-
+		nm_vpn_get_plugins ();
+
+	if (!g_str_has_prefix (service, NM_DBUS_INTERFACE))
+		service = type = g_strdup_printf ("%s.%s", NM_DBUS_INTERFACE, service);
+
+	plugin_info = nm_vpn_plugin_info_list_find_by_service (plugins, service);
+	if (plugin_info) {
+		plugin = nm_vpn_plugin_info_get_editor_plugin (plugin_info);
+		if (!plugin)
+			plugin = nm_vpn_plugin_info_load_editor_plugin (plugin_info, error);
+	} else
+		g_set_error_literal (error, NM_VPN_PLUGIN_ERROR, NM_VPN_PLUGIN_ERROR_FAILED,
+		                     _("could not get VPN plugin info"));
+	g_free (type);
 	return plugin;
 }
 
 GSList *
-nm_vpn_get_plugins (GError **error)
+nm_vpn_get_plugins (void)
 {
-	GDir *dir;
-	const char *f;
-	GHashTableIter iter;
-	NMVpnEditorPlugin *plugin;
-
-	if (error)
-		g_return_val_if_fail (*error == NULL, NULL);
-
 	if (G_LIKELY (plugins_loaded))
-		return plugins_list;
-
+		return plugins;
 	plugins_loaded = TRUE;
-
-	dir = g_dir_open (VPN_NAME_FILES_DIR, 0, NULL);
-	if (!dir) {
-		g_set_error (error, NM_VPN_ERROR, NM_VPN_ERROR_GENERIC, "Couldn't read VPN .name files directory " VPN_NAME_FILES_DIR ".");
-		return NULL;
-	}
-
-	plugins_hash = g_hash_table_new_full (g_str_hash, g_str_equal,
-	                                      (GDestroyNotify) g_free, (GDestroyNotify) g_object_unref);
-
-	while ((f = g_dir_read_name (dir))) {
-		char *path = NULL, *service = NULL;
-		char *so_path = NULL, *so_name = NULL;
-		GKeyFile *keyfile = NULL;
-		GModule *module = NULL;
-		NMVpnEditorPluginFactory factory = NULL;
-
-		if (!g_str_has_suffix (f, ".name"))
-			continue;
-
-		path = g_strdup_printf ("%s/%s", VPN_NAME_FILES_DIR, f);
-
-		keyfile = g_key_file_new ();
-		if (!g_key_file_load_from_file (keyfile, path, 0, NULL))
-			goto next;
-
-		service = g_key_file_get_string (keyfile, "VPN Connection", "service", NULL);
-		if (!service)
-			goto next;
-
-		so_path = g_key_file_get_string (keyfile,  "libnm", "plugin", NULL);
-		if (!so_path)
-			goto next;
-
-		if (g_path_is_absolute (so_path))
-			module = g_module_open (so_path, G_MODULE_BIND_LAZY | G_MODULE_BIND_LOCAL);
-
-		if (!module) {
-			/* Remove any path and extension components, then reconstruct path
-			 * to the SO in LIBDIR
-			 */
-			so_name = g_path_get_basename (so_path);
-			g_free (so_path);
-			so_path = g_strdup_printf ("%s/NetworkManager/%s", NMLIBDIR, so_name);
-			g_free (so_name);
-
-			module = g_module_open (so_path, G_MODULE_BIND_LAZY | G_MODULE_BIND_LOCAL);
-			if (!module) {
-				g_clear_error (error);
-				g_set_error (error, NM_VPN_ERROR, NM_VPN_ERROR_GENERIC, "Cannot load the VPN plugin which provides the "
-				             "service '%s'.", service);
-				goto next;
-			}
-		}
-
-		if (g_module_symbol (module, "nm_vpn_editor_plugin_factory", (gpointer) &factory)) {
-			GError *factory_error = NULL;
-			gboolean success = FALSE;
-
-			plugin = factory (&factory_error);
-			if (plugin) {
-				char *plug_name = NULL, *plug_service = NULL;
-
-				/* Validate plugin properties */
-				g_object_get (G_OBJECT (plugin),
-				              NM_VPN_EDITOR_PLUGIN_NAME, &plug_name,
-				              NM_VPN_EDITOR_PLUGIN_SERVICE, &plug_service,
-				              NULL);
-				if (!plug_name || !strlen (plug_name)) {
-					g_clear_error (error);
-					g_set_error (error, NM_VPN_ERROR, NM_VPN_ERROR_GENERIC, "cannot load VPN plugin in '%s': missing plugin name", 
-					             g_module_name (module));
-				} else if (!plug_service || strcmp (plug_service, service)) {
-					g_clear_error (error);
-					g_set_error (error, NM_VPN_ERROR, NM_VPN_ERROR_GENERIC, "cannot load VPN plugin in '%s': invalid service name", 
-					             g_module_name (module));
-				} else {
-					/* Success! */
-					g_object_set_data_full (G_OBJECT (plugin), "gmodule", module,
-					                        (GDestroyNotify) g_module_close);
-					g_hash_table_insert (plugins_hash, g_strdup (service), plugin);
-					success = TRUE;
-				}
-				g_free (plug_name);
-				g_free (plug_service);
-			} else {
-				g_clear_error (error);
-				g_set_error (error, NM_VPN_ERROR, NM_VPN_ERROR_GENERIC, "cannot load VPN plugin in '%s': %s", 
-				             g_module_name (module), g_module_error ());
-			}
-
-			if (!success)
-				g_module_close (module);
-		} else {
-			g_clear_error (error);
-			g_set_error (error, NM_VPN_ERROR, NM_VPN_ERROR_GENERIC, "cannot locate nm_vpn_editor_plugin_factory() in '%s': %s", 
-			             g_module_name (module), g_module_error ());
-			g_module_close (module);
-		}
-
-	next:
-		g_free (so_path);
-		g_free (service);
-		g_key_file_free (keyfile);
-		g_free (path);
-	}
-	g_dir_close (dir);
-
-	/* Copy hash to list */
-	g_hash_table_iter_init (&iter, plugins_hash);
-	while (g_hash_table_iter_next (&iter, NULL, (gpointer *) &plugin))
-		plugins_list = g_slist_prepend (plugins_list, plugin);
-
-	return plugins_list;
+	plugins = nm_vpn_plugin_info_list_load ();
+	return plugins;
 }
 
 gboolean
@@ -220,11 +89,11 @@ nm_vpn_supports_ipv6 (NMConnection *connection)
 	service_type = nm_setting_vpn_get_service_type (s_vpn);
 	g_return_val_if_fail (service_type != NULL, FALSE);
 
-	plugin = nm_vpn_get_plugin_by_service (service_type);
+	plugin = nm_vpn_get_plugin_by_service (service_type, NULL);
 	g_return_val_if_fail (plugin != NULL, FALSE);
 
 	capabilities = nm_vpn_editor_plugin_get_capabilities (plugin);
-	return (capabilities & NM_VPN_EDITOR_PLUGIN_CAPABILITY_IPV6) != 0;
+	return NM_FLAGS_HAS (capabilities, NM_VPN_EDITOR_PLUGIN_CAPABILITY_IPV6);
 }
 
 const VpnPasswordName *
diff --git a/clients/common/nm-vpn-helpers.h b/clients/common/nm-vpn-helpers.h
index 6b3396ef..4f8d2194 100644
--- a/clients/common/nm-vpn-helpers.h
+++ b/clients/common/nm-vpn-helpers.h
@@ -19,19 +19,18 @@
 #ifndef __NM_VPN_HELPERS_H__
 #define __NM_VPN_HELPERS_H__
 
-#include <glib.h>
 #include <NetworkManager.h>
 
-#include <nm-vpn-editor-plugin.h>
+#include "nm-default.h"
 
 struct {
 	const char *name;
 	const char *ui_name;
 } typedef VpnPasswordName;
 
-GSList *nm_vpn_get_plugins (GError **error);
+GSList *nm_vpn_get_plugins (void);
 
-NMVpnEditorPlugin *nm_vpn_get_plugin_by_service (const char *service);
+NMVpnEditorPlugin *nm_vpn_get_plugin_by_service (const char *service, GError **error);
 
 gboolean nm_vpn_supports_ipv6 (NMConnection *connection);