shared: merge branch 'th/shared-bgo767697'
https://bugzilla.gnome.org/show_bug.cgi?id=767697
This commit is contained in:
@@ -28,7 +28,7 @@
|
||||
#include "nm-dispatcher-utils.h"
|
||||
#include "nm-dispatcher-api.h"
|
||||
|
||||
#include "nm-test-utils.h"
|
||||
#include "nm-utils/nm-test-utils.h"
|
||||
|
||||
/*******************************************/
|
||||
|
||||
|
@@ -52,7 +52,7 @@ libnm_core_headers = \
|
||||
$(core)/nm-vpn-plugin-info.h
|
||||
|
||||
libnm_core_private_headers = \
|
||||
$(top_builddir)/shared/nm-shared-utils.h \
|
||||
$(top_builddir)/shared/nm-utils/nm-shared-utils.h \
|
||||
$(core)/crypto.h \
|
||||
$(core)/nm-connection-private.h \
|
||||
$(core)/nm-core-internal.h \
|
||||
@@ -64,7 +64,7 @@ libnm_core_private_headers = \
|
||||
$(core)/nm-utils-private.h
|
||||
|
||||
libnm_core_sources = \
|
||||
$(top_builddir)/shared/nm-shared-utils.c \
|
||||
$(top_builddir)/shared/nm-utils/nm-shared-utils.c \
|
||||
$(core_build)/nm-core-enum-types.c \
|
||||
$(core)/crypto.c \
|
||||
$(core)/nm-connection.c \
|
||||
|
@@ -26,7 +26,7 @@
|
||||
|
||||
#include "nm-property-compare.h"
|
||||
|
||||
#include "nm-test-utils.h"
|
||||
#include "nm-utils/nm-test-utils.h"
|
||||
|
||||
static void
|
||||
compare_ints (void)
|
||||
|
@@ -33,7 +33,7 @@
|
||||
#include "nm-errors.h"
|
||||
#include "nm-core-internal.h"
|
||||
|
||||
#include "nm-test-utils.h"
|
||||
#include "nm-utils/nm-test-utils.h"
|
||||
|
||||
#if 0
|
||||
static const char *pem_rsa_key_begin = "-----BEGIN RSA PRIVATE KEY-----";
|
||||
|
@@ -62,7 +62,7 @@
|
||||
|
||||
#include "test-general-enums.h"
|
||||
|
||||
#include "nm-test-utils.h"
|
||||
#include "nm-utils/nm-test-utils.h"
|
||||
|
||||
/* When passing a "bool" typed argument to a variadic function that
|
||||
* expects a gboolean, the compiler will promote the integer type
|
||||
|
@@ -28,7 +28,7 @@
|
||||
#include "nm-setting-wired.h"
|
||||
#include "nm-setting-8021x.h"
|
||||
|
||||
#include "nm-test-utils.h"
|
||||
#include "nm-utils/nm-test-utils.h"
|
||||
|
||||
|
||||
#define TEST_WIRED_TLS_CA_CERT TEST_CERT_DIR"/test-ca-cert.pem"
|
||||
|
@@ -38,7 +38,7 @@
|
||||
#include "nm-utils.h"
|
||||
#include "nm-core-internal.h"
|
||||
|
||||
#include "nm-test-utils.h"
|
||||
#include "nm-utils/nm-test-utils.h"
|
||||
|
||||
#define TEST_NEED_SECRETS_EAP_TLS_CA_CERT TEST_CERT_DIR "/test_ca_cert.pem"
|
||||
#define TEST_NEED_SECRETS_EAP_TLS_CLIENT_CERT TEST_CERT_DIR "/test_key_and_cert.pem"
|
||||
|
@@ -27,7 +27,7 @@
|
||||
#include "nm-setting-connection.h"
|
||||
#include "nm-setting-8021x.h"
|
||||
|
||||
#include "nm-test-utils.h"
|
||||
#include "nm-utils/nm-test-utils.h"
|
||||
|
||||
static void
|
||||
compare_blob_data (const char *test,
|
||||
|
@@ -26,7 +26,7 @@
|
||||
#include "nm-setting-connection.h"
|
||||
#include "nm-errors.h"
|
||||
|
||||
#include "nm-test-utils.h"
|
||||
#include "nm-utils/nm-test-utils.h"
|
||||
|
||||
static void
|
||||
create_bond_connection (NMConnection **con, NMSettingBond **s_bond)
|
||||
|
@@ -28,7 +28,7 @@
|
||||
#include "nm-connection.h"
|
||||
#include "nm-errors.h"
|
||||
|
||||
#include "nm-test-utils.h"
|
||||
#include "nm-utils/nm-test-utils.h"
|
||||
|
||||
#define DCB_FLAGS_ALL (NM_SETTING_DCB_FLAG_ENABLE | \
|
||||
NM_SETTING_DCB_FLAG_ADVERTISE | \
|
||||
|
@@ -38,7 +38,7 @@
|
||||
#include "nm-setting-wireless.h"
|
||||
#include "nm-setting-wireless-security.h"
|
||||
|
||||
#include "nm-test-utils.h"
|
||||
#include "nm-utils/nm-test-utils.h"
|
||||
|
||||
static void
|
||||
test_defaults (GType type, const char *name)
|
||||
|
@@ -62,7 +62,7 @@ nodist_libnm_util_include_HEADERS = \
|
||||
nm-utils-enum-types.h
|
||||
|
||||
libnm_util_la_private_headers = \
|
||||
$(top_builddir)/shared/nm-shared-utils.h \
|
||||
$(top_builddir)/shared/nm-utils/nm-shared-utils.h \
|
||||
crypto.h \
|
||||
nm-dbus-glib-types.h \
|
||||
nm-gvaluearray-compat.h \
|
||||
@@ -71,7 +71,7 @@ libnm_util_la_private_headers = \
|
||||
nm-utils-private.h
|
||||
|
||||
libnm_util_la_csources = \
|
||||
$(top_builddir)/shared/nm-shared-utils.c \
|
||||
$(top_builddir)/shared/nm-utils/nm-shared-utils.c \
|
||||
crypto.c \
|
||||
nm-connection.c \
|
||||
nm-param-spec-specialized.c \
|
||||
|
@@ -31,7 +31,7 @@
|
||||
#include "crypto.h"
|
||||
#include "nm-utils.h"
|
||||
|
||||
#include "nm-test-utils.h"
|
||||
#include "nm-utils/nm-test-utils.h"
|
||||
|
||||
#if 0
|
||||
static const char *pem_rsa_key_begin = "-----BEGIN RSA PRIVATE KEY-----";
|
||||
|
@@ -47,7 +47,7 @@
|
||||
#include "nm-utils.h"
|
||||
#include "nm-dbus-glib-types.h"
|
||||
|
||||
#include "nm-test-utils.h"
|
||||
#include "nm-utils/nm-test-utils.h"
|
||||
|
||||
static void
|
||||
vpn_check_func (const char *key, const char *value, gpointer user_data)
|
||||
|
@@ -37,7 +37,7 @@
|
||||
#include "nm-setting-pppoe.h"
|
||||
#include "nm-setting-vpn.h"
|
||||
|
||||
#include "nm-test-utils.h"
|
||||
#include "nm-utils/nm-test-utils.h"
|
||||
|
||||
#define TEST_NEED_SECRETS_EAP_TLS_CA_CERT TEST_CERT_DIR "/test_ca_cert.pem"
|
||||
#define TEST_NEED_SECRETS_EAP_TLS_CLIENT_CERT TEST_CERT_DIR "/test_key_and_cert.pem"
|
||||
|
@@ -27,7 +27,7 @@
|
||||
#include "nm-setting-connection.h"
|
||||
#include "nm-setting-8021x.h"
|
||||
|
||||
#include "nm-test-utils.h"
|
||||
#include "nm-utils/nm-test-utils.h"
|
||||
|
||||
static void
|
||||
compare_blob_data (const char *test,
|
||||
|
@@ -27,7 +27,7 @@
|
||||
#include "nm-default.h"
|
||||
#include "nm-setting-dcb.h"
|
||||
|
||||
#include "nm-test-utils.h"
|
||||
#include "nm-utils/nm-test-utils.h"
|
||||
|
||||
#define DCB_FLAGS_ALL (NM_SETTING_DCB_FLAG_ENABLE | \
|
||||
NM_SETTING_DCB_FLAG_ADVERTISE | \
|
||||
|
@@ -38,7 +38,7 @@
|
||||
#include "nm-setting-wireless.h"
|
||||
#include "nm-setting-wireless-security.h"
|
||||
|
||||
#include "nm-test-utils.h"
|
||||
#include "nm-utils/nm-test-utils.h"
|
||||
|
||||
static void
|
||||
test_defaults (GType type, const char *name)
|
||||
|
@@ -1312,5 +1312,5 @@ nm_vpn_service_plugin_initable_iface_init (GInitableIface *iface)
|
||||
/* this header is intended to be copied to users of nm_vpn_editor_plugin_call(),
|
||||
* to simplify invocation of generic functions. Include it here, to complile
|
||||
* the code. */
|
||||
#include "nm-vpn-editor-plugin-call.h"
|
||||
#include "nm-utils/nm-vpn-editor-plugin-call.h"
|
||||
|
||||
|
@@ -39,3 +39,27 @@ test_secret_agent_SOURCES = \
|
||||
$(top_builddir)/shared/nm-test-libnm-utils.h \
|
||||
test-secret-agent.c
|
||||
endif
|
||||
|
||||
###############################################################################
|
||||
|
||||
noinst_LTLIBRARIES = \
|
||||
libnm-vpn-plugin-utils-test.la
|
||||
|
||||
libnm_vpn_plugin_utils_test_la_SOURCES = \
|
||||
$(top_srcdir)/shared/nm-utils/nm-vpn-plugin-utils.c \
|
||||
$(top_srcdir)/shared/nm-utils/nm-vpn-plugin-utils.h \
|
||||
$(NULL)
|
||||
|
||||
libnm_vpn_plugin_utils_test_la_CFLAGS = \
|
||||
$(GLIB_CFLAGS) \
|
||||
-I$(top_srcdir)/shared \
|
||||
-I$(top_srcdir)/libnm-core \
|
||||
-I$(top_srcdir)/libnm \
|
||||
$(NULL)
|
||||
|
||||
libnm_vpn_plugin_utils_test_la_LIBADD = \
|
||||
$(GLIB_LIBS) \
|
||||
$(NULL)
|
||||
|
||||
###############################################################################
|
||||
|
||||
|
@@ -140,7 +140,7 @@ libnm/nm-remote-settings.c
|
||||
libnm/nm-vpn-plugin-old.c
|
||||
libnm/nm-vpn-service-plugin.c
|
||||
policy/org.freedesktop.NetworkManager.policy.in.in
|
||||
shared/nm-shared-utils.c
|
||||
shared/nm-utils/nm-shared-utils.c
|
||||
src/NetworkManagerUtils.c
|
||||
src/main.c
|
||||
src/main-utils.c
|
||||
|
@@ -6,6 +6,7 @@ vpn-daemons/openvpn
|
||||
vpn-daemons/pptp
|
||||
vpn-daemons/vpnc
|
||||
contrib/fedora/rpm/
|
||||
shared/nm-vpn-editor-plugin-call.h
|
||||
shared/nm-utils/nm-vpn-editor-plugin-call.h
|
||||
shared/nm-utils/nm-vpn-plugin-utils.c
|
||||
# https://bugs.launchpad.net/intltool/+bug/1117944
|
||||
sub/policy/org.freedesktop.NetworkManager.policy.in
|
||||
|
@@ -1,16 +1,19 @@
|
||||
EXTRA_DIST = \
|
||||
gsystem-local-alloc.h \
|
||||
nm-utils/gsystem-local-alloc.h \
|
||||
nm-utils/nm-glib.h \
|
||||
nm-utils/nm-macros-internal.h \
|
||||
nm-utils/nm-shared-utils.c \
|
||||
nm-utils/nm-shared-utils.h \
|
||||
nm-utils/nm-test-utils.h \
|
||||
nm-utils/nm-vpn-editor-plugin-call.h \
|
||||
nm-utils/nm-vpn-plugin-utils.c \
|
||||
nm-utils/nm-vpn-plugin-utils.h \
|
||||
nm-common-macros.h \
|
||||
nm-dbus-compat.h \
|
||||
nm-default.h \
|
||||
nm-glib.h \
|
||||
nm-macros-internal.h \
|
||||
nm-shared-utils.c \
|
||||
nm-shared-utils.h \
|
||||
nm-test-libnm-utils.h \
|
||||
nm-test-utils.h \
|
||||
nm-test-utils-impl.c \
|
||||
nm-version-macros.h.in \
|
||||
nm-vpn-editor-plugin-call.h
|
||||
$(NULL)
|
||||
|
||||
CLEANFILES=nm-version.h
|
||||
|
@@ -98,11 +98,9 @@ _nm_g_return_if_fail_warning (const char *log_domain,
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
#include "nm-glib.h"
|
||||
#include "nm-utils/nm-macros-internal.h"
|
||||
#include "nm-version.h"
|
||||
#include "gsystem-local-alloc.h"
|
||||
#include "nm-macros-internal.h"
|
||||
#include "nm-shared-utils.h"
|
||||
#include "nm-utils/nm-shared-utils.h"
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
|
@@ -20,7 +20,7 @@
|
||||
|
||||
#include "NetworkManager.h"
|
||||
|
||||
#include "nm-test-utils.h"
|
||||
#include "nm-utils/nm-test-utils.h"
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
|
@@ -24,6 +24,8 @@
|
||||
#include <gio/gio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "gsystem-local-alloc.h"
|
||||
|
||||
#ifdef __clang__
|
||||
|
||||
#undef G_GNUC_BEGIN_IGNORE_DEPRECATIONS
|
@@ -24,6 +24,8 @@
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "nm-glib.h"
|
||||
|
||||
/********************************************************/
|
||||
|
||||
#define _nm_packed __attribute__ ((packed))
|
@@ -32,7 +32,6 @@
|
||||
#include <NetworkManager.h>
|
||||
|
||||
/* we make use of other internal header files, you need those too. */
|
||||
#include "gsystem-local-alloc.h"
|
||||
#include "nm-macros-internal.h"
|
||||
|
||||
/*****************************************************************************/
|
130
shared/nm-utils/nm-vpn-plugin-utils.c
Normal file
130
shared/nm-utils/nm-vpn-plugin-utils.c
Normal file
@@ -0,0 +1,130 @@
|
||||
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||
|
||||
/*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
* Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Copyright 2016 Red Hat, Inc.
|
||||
*/
|
||||
|
||||
#include "nm-default.h"
|
||||
|
||||
#include "nm-vpn-plugin-utils.h"
|
||||
|
||||
#include <dlfcn.h>
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
NMVpnEditor *
|
||||
nm_vpn_plugin_utils_load_editor (const char *module_name,
|
||||
const char *factory_name,
|
||||
NMVpnPluginUtilsEditorFactory editor_factory,
|
||||
NMVpnEditorPlugin *editor_plugin,
|
||||
NMConnection *connection,
|
||||
gpointer user_data,
|
||||
GError **error)
|
||||
|
||||
{
|
||||
static struct {
|
||||
gpointer factory;
|
||||
void *dl_module;
|
||||
char *module_name;
|
||||
char *factory_name;
|
||||
} cached = { 0 };
|
||||
NMVpnEditor *editor;
|
||||
|
||||
g_return_val_if_fail (module_name && g_path_is_absolute (module_name), NULL);
|
||||
g_return_val_if_fail (factory_name && factory_name[0], NULL);
|
||||
g_return_val_if_fail (editor_factory, NULL);
|
||||
g_return_val_if_fail (NM_IS_VPN_EDITOR_PLUGIN (editor_plugin), NULL);
|
||||
g_return_val_if_fail (NM_IS_CONNECTION (connection), NULL);
|
||||
g_return_val_if_fail (!error || !*error, NULL);
|
||||
|
||||
/* we really expect this function to be called with unchanging @module_name
|
||||
* and @factory_name. And we only want to load the module once, hence it would
|
||||
* be more complicated to accept changing @module_name/@factory_name arguments.
|
||||
*
|
||||
* The reason for only loading once is that due to glib types, we cannot create a
|
||||
* certain type-name more then once, so loading the same module or another version
|
||||
* of the same module will fail horribly as both try to create a GType with the same
|
||||
* name.
|
||||
*
|
||||
* Only support loading once, any future calls will reuse the handle. To simplify
|
||||
* that, we enforce that the @factory_name and @module_name is the same. */
|
||||
if (cached.factory) {
|
||||
g_return_val_if_fail (cached.dl_module, NULL);
|
||||
g_return_val_if_fail (cached.factory_name && nm_streq0 (cached.factory_name, factory_name), NULL);
|
||||
g_return_val_if_fail (cached.module_name && nm_streq0 (cached.module_name, module_name), NULL);
|
||||
} else {
|
||||
gpointer factory;
|
||||
void *dl_module;
|
||||
|
||||
dl_module = dlopen (module_name, RTLD_LAZY | RTLD_LOCAL);
|
||||
if (!dl_module) {
|
||||
if (!g_file_test (module_name, G_FILE_TEST_EXISTS)) {
|
||||
g_set_error (error,
|
||||
G_FILE_ERROR,
|
||||
G_FILE_ERROR_NOENT,
|
||||
_("missing plugin file \"%s\""), module_name);
|
||||
return NULL;
|
||||
}
|
||||
g_set_error (error,
|
||||
NM_CONNECTION_ERROR,
|
||||
NM_CONNECTION_ERROR_FAILED,
|
||||
_("cannot load editor plugin: %s"), dlerror ());
|
||||
return NULL;
|
||||
}
|
||||
|
||||
factory = dlsym (dl_module, factory_name);
|
||||
if (!factory) {
|
||||
g_set_error (error,
|
||||
NM_CONNECTION_ERROR,
|
||||
NM_CONNECTION_ERROR_FAILED,
|
||||
_("cannot load factory %s from plugin: %s"),
|
||||
factory_name, dlerror ());
|
||||
dlclose (dl_module);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* we cannot ever unload the module because it creates glib types, which
|
||||
* cannot be unregistered.
|
||||
*
|
||||
* Thus we just leak the dl_module handle indefinitely. */
|
||||
cached.factory = factory;
|
||||
cached.dl_module = dl_module;
|
||||
cached.module_name = g_strdup (module_name);
|
||||
cached.factory_name = g_strdup (factory_name);
|
||||
}
|
||||
|
||||
editor = editor_factory (cached.factory,
|
||||
editor_plugin,
|
||||
connection,
|
||||
user_data,
|
||||
error);
|
||||
if (!editor) {
|
||||
if (error && !*error ) {
|
||||
g_set_error_literal (error,
|
||||
NM_CONNECTION_ERROR,
|
||||
NM_CONNECTION_ERROR_FAILED,
|
||||
_("unknown error creating editor instance"));
|
||||
g_return_val_if_reached (NULL);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
g_return_val_if_fail (NM_IS_VPN_EDITOR (editor), NULL);
|
||||
return editor;
|
||||
}
|
||||
|
42
shared/nm-utils/nm-vpn-plugin-utils.h
Normal file
42
shared/nm-utils/nm-vpn-plugin-utils.h
Normal file
@@ -0,0 +1,42 @@
|
||||
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||
|
||||
/*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
* Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Copyright 2016 Red Hat, Inc.
|
||||
*/
|
||||
|
||||
#ifndef __NM_VPN_PLUGIN_UTILS_H__
|
||||
#define __NM_VPN_PLUGIN_UTILS_H__
|
||||
|
||||
#include <NetworkManager.h>
|
||||
|
||||
typedef NMVpnEditor *(NMVpnPluginUtilsEditorFactory) (gpointer factory,
|
||||
NMVpnEditorPlugin *editor_plugin,
|
||||
NMConnection *connection,
|
||||
gpointer user_data,
|
||||
GError **error);
|
||||
|
||||
NMVpnEditor *nm_vpn_plugin_utils_load_editor (const char *module_name,
|
||||
const char *factory_name,
|
||||
NMVpnPluginUtilsEditorFactory editor_factory,
|
||||
NMVpnEditorPlugin *editor_plugin,
|
||||
NMConnection *connection,
|
||||
gpointer user_data,
|
||||
GError **error);
|
||||
|
||||
#endif /* __NM_VPN_PLUGIN_UTILS_H__ */
|
||||
|
@@ -26,7 +26,7 @@
|
||||
|
||||
#define _NMTST_INSIDE_CORE 1
|
||||
|
||||
#include "nm-test-utils.h"
|
||||
#include "nm-utils/nm-test-utils.h"
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
|
Reference in New Issue
Block a user