diff options
| author | Michael Biebl <biebl@debian.org> | 2016-01-20 16:26:51 +0100 |
|---|---|---|
| committer | Michael Biebl <biebl@debian.org> | 2016-01-20 16:26:51 +0100 |
| commit | 494f296a3baab08522617b24b1f126d8f9a17502 (patch) | |
| tree | c8ef32fb0dd1c4ff35a0b38e787abb58692de0cd /src/settings/plugins/keyfile | |
| parent | 54f6333410ffd570e62717d9e77c5c987175e397 (diff) | |
Imported Upstream version 1.1.90 upstream/1.1.90
Diffstat (limited to 'src/settings/plugins/keyfile')
18 files changed, 290 insertions, 563 deletions
diff --git a/src/settings/plugins/keyfile/Makefile.am b/src/settings/plugins/keyfile/Makefile.am index 919b0805..ddcd15b2 100644 --- a/src/settings/plugins/keyfile/Makefile.am +++ b/src/settings/plugins/keyfile/Makefile.am @@ -5,15 +5,14 @@ SUBDIRS = . tests AM_CPPFLAGS = \ -I$(top_srcdir)/src \ -I$(top_srcdir)/src/settings \ - -I$(top_srcdir)/include \ - -I$(top_builddir)/include \ + -I$(top_srcdir)/shared \ + -I$(top_builddir)/shared \ -I$(top_srcdir)/libnm-core \ -I$(top_builddir)/libnm-core \ -DG_LOG_DOMAIN=\""NetworkManager-keyfile"\" \ - -DNETWORKMANAGER_COMPILATION \ + -DNETWORKMANAGER_COMPILATION=NM_NETWORKMANAGER_COMPILATION_INSIDE_DAEMON \ -DNM_VERSION_MAX_ALLOWED=NM_VERSION_NEXT_STABLE \ $(GLIB_CFLAGS) \ - $(DBUS_CFLAGS) \ -DNMCONFDIR=\"$(nmconfdir)\" noinst_LTLIBRARIES = \ @@ -28,8 +27,7 @@ libkeyfile_io_la_SOURCES = \ writer.c \ writer.h \ utils.c \ - utils.h \ - common.h + utils.h libkeyfile_io_la_LIBADD = $(GLIB_LIBS) diff --git a/src/settings/plugins/keyfile/Makefile.in b/src/settings/plugins/keyfile/Makefile.in index 1514768b..9c078ca4 100644 --- a/src/settings/plugins/keyfile/Makefile.in +++ b/src/settings/plugins/keyfile/Makefile.in @@ -246,7 +246,6 @@ BLUEZ5_LIBS = @BLUEZ5_LIBS@ CC = @CC@ CCDEPMODE = @CCDEPMODE@ CFLAGS = @CFLAGS@ -CKDB_PATH = @CKDB_PATH@ CODE_COVERAGE_CFLAGS = @CODE_COVERAGE_CFLAGS@ CODE_COVERAGE_ENABLED = @CODE_COVERAGE_ENABLED@ CODE_COVERAGE_LDFLAGS = @CODE_COVERAGE_LDFLAGS@ @@ -258,8 +257,6 @@ CXXDEPMODE = @CXXDEPMODE@ CXXFLAGS = @CXXFLAGS@ CYGPATH_W = @CYGPATH_W@ DBUS_CFLAGS = @DBUS_CFLAGS@ -DBUS_GLIB_100_CFLAGS = @DBUS_GLIB_100_CFLAGS@ -DBUS_GLIB_100_LIBS = @DBUS_GLIB_100_LIBS@ DBUS_LIBS = @DBUS_LIBS@ DBUS_SYS_DIR = @DBUS_SYS_DIR@ DEFS = @DEFS@ @@ -269,6 +266,7 @@ DHCPCD_PATH = @DHCPCD_PATH@ DISTRO_NETWORK_SERVICE = @DISTRO_NETWORK_SERVICE@ DLLTOOL = @DLLTOOL@ DNSMASQ_PATH = @DNSMASQ_PATH@ +DNSSEC_TRIGGER_SCRIPT = @DNSSEC_TRIGGER_SCRIPT@ DSYMUTIL = @DSYMUTIL@ DUMPBIN = @DUMPBIN@ ECHO_C = @ECHO_C@ @@ -323,16 +321,13 @@ INTROSPECTION_MAKEFILE = @INTROSPECTION_MAKEFILE@ INTROSPECTION_SCANNER = @INTROSPECTION_SCANNER@ INTROSPECTION_TYPELIBDIR = @INTROSPECTION_TYPELIBDIR@ IPTABLES_PATH = @IPTABLES_PATH@ -IWMX_SDK_CFLAGS = @IWMX_SDK_CFLAGS@ -IWMX_SDK_LIBS = @IWMX_SDK_LIBS@ KERNEL_FIRMWARE_DIR = @KERNEL_FIRMWARE_DIR@ LCOV = @LCOV@ LD = @LD@ LDFLAGS = @LDFLAGS@ +LIBAUDIT_CFLAGS = @LIBAUDIT_CFLAGS@ +LIBAUDIT_LIBS = @LIBAUDIT_LIBS@ LIBDL = @LIBDL@ -LIBGCRYPT_CFLAGS = @LIBGCRYPT_CFLAGS@ -LIBGCRYPT_CONFIG = @LIBGCRYPT_CONFIG@ -LIBGCRYPT_LIBS = @LIBGCRYPT_LIBS@ LIBICONV = @LIBICONV@ LIBINTL = @LIBINTL@ LIBM = @LIBM@ @@ -369,6 +364,8 @@ NEWT_LIBS = @NEWT_LIBS@ NM = @NM@ NMEDIT = @NMEDIT@ NM_CONFIG_DEFAULT_AUTH_POLKIT_TEXT = @NM_CONFIG_DEFAULT_AUTH_POLKIT_TEXT@ +NM_CONFIG_DEFAULT_LOGGING_AUDIT_TEXT = @NM_CONFIG_DEFAULT_LOGGING_AUDIT_TEXT@ +NM_CONFIG_LOGGING_BACKEND_DEFAULT_TEXT = @NM_CONFIG_LOGGING_BACKEND_DEFAULT_TEXT@ NM_MAJOR_VERSION = @NM_MAJOR_VERSION@ NM_MICRO_VERSION = @NM_MICRO_VERSION@ NM_MINOR_VERSION = @NM_MINOR_VERSION@ @@ -397,7 +394,6 @@ POLKIT_LIBS = @POLKIT_LIBS@ POSUB = @POSUB@ PPPD_PATH = @PPPD_PATH@ PPPD_PLUGIN_DIR = @PPPD_PLUGIN_DIR@ -PPPOE_PATH = @PPPOE_PATH@ QT_CFLAGS = @QT_CFLAGS@ QT_LIBS = @QT_LIBS@ RANLIB = @RANLIB@ @@ -412,6 +408,8 @@ SYSTEMD_200_CFLAGS = @SYSTEMD_200_CFLAGS@ SYSTEMD_200_LIBS = @SYSTEMD_200_LIBS@ SYSTEMD_INHIBIT_CFLAGS = @SYSTEMD_INHIBIT_CFLAGS@ SYSTEMD_INHIBIT_LIBS = @SYSTEMD_INHIBIT_LIBS@ +SYSTEMD_JOURNAL_CFLAGS = @SYSTEMD_JOURNAL_CFLAGS@ +SYSTEMD_JOURNAL_LIBS = @SYSTEMD_JOURNAL_LIBS@ SYSTEMD_LOGIN_CFLAGS = @SYSTEMD_LOGIN_CFLAGS@ SYSTEMD_LOGIN_LIBS = @SYSTEMD_LOGIN_LIBS@ SYSTEM_CA_PATH = @SYSTEM_CA_PATH@ @@ -472,6 +470,7 @@ mkdir_p = @mkdir_p@ nmbinary = @nmbinary@ nmconfdir = @nmconfdir@ nmdatadir = @nmdatadir@ +nmlibdir = @nmlibdir@ nmrundir = @nmrundir@ nmstatedir = @nmstatedir@ oldincludedir = @oldincludedir@ @@ -479,6 +478,7 @@ pdfdir = @pdfdir@ prefix = @prefix@ program_transform_name = @program_transform_name@ psdir = @psdir@ +runstatedir = @runstatedir@ sbindir = @sbindir@ sharedstatedir = @sharedstatedir@ srcdir = @srcdir@ @@ -498,15 +498,14 @@ SUBDIRS = . tests AM_CPPFLAGS = \ -I$(top_srcdir)/src \ -I$(top_srcdir)/src/settings \ - -I$(top_srcdir)/include \ - -I$(top_builddir)/include \ + -I$(top_srcdir)/shared \ + -I$(top_builddir)/shared \ -I$(top_srcdir)/libnm-core \ -I$(top_builddir)/libnm-core \ -DG_LOG_DOMAIN=\""NetworkManager-keyfile"\" \ - -DNETWORKMANAGER_COMPILATION \ + -DNETWORKMANAGER_COMPILATION=NM_NETWORKMANAGER_COMPILATION_INSIDE_DAEMON \ -DNM_VERSION_MAX_ALLOWED=NM_VERSION_NEXT_STABLE \ $(GLIB_CFLAGS) \ - $(DBUS_CFLAGS) \ -DNMCONFDIR=\"$(nmconfdir)\" noinst_LTLIBRARIES = \ @@ -521,8 +520,7 @@ libkeyfile_io_la_SOURCES = \ writer.c \ writer.h \ utils.c \ - utils.h \ - common.h + utils.h libkeyfile_io_la_LIBADD = $(GLIB_LIBS) diff --git a/src/settings/plugins/keyfile/common.h b/src/settings/plugins/keyfile/common.h deleted file mode 100644 index 86fe0028..00000000 --- a/src/settings/plugins/keyfile/common.h +++ /dev/null @@ -1,32 +0,0 @@ -/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */ -/* NetworkManager system settings service - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - * (C) Copyright 2008 - 2013 Red Hat, Inc. - */ - -#ifndef __COMMON_H__ -#define __COMMON_H__ - -#include <glib.h> - -#define KEYFILE_PLUGIN_NAME "keyfile" -#define KEYFILE_PLUGIN_INFO "(c) 2007 - 2015 Red Hat, Inc. To report bugs please use the NetworkManager mailing list." - -#define KEYFILE_DIR NMCONFDIR "/system-connections" - -#endif /* __COMMON_H__ */ - diff --git a/src/settings/plugins/keyfile/nm-keyfile-connection.c b/src/settings/plugins/keyfile/nm-keyfile-connection.c index 8fb94302..c217de68 100644 --- a/src/settings/plugins/keyfile/nm-keyfile-connection.c +++ b/src/settings/plugins/keyfile/nm-keyfile-connection.c @@ -27,12 +27,13 @@ #include <nm-setting-connection.h> #include <nm-utils.h> -#include "nm-system-config-interface.h" -#include "nm-dbus-glib-types.h" +#include "nm-default.h" +#include "nm-settings-plugin.h" #include "nm-keyfile-connection.h" #include "reader.h" #include "writer.h" -#include "common.h" +#include "utils.h" +#include "nm-logging.h" G_DEFINE_TYPE (NMKeyfileConnection, nm_keyfile_connection, NM_TYPE_SETTINGS_CONNECTION) @@ -88,6 +89,7 @@ nm_keyfile_connection_new (NMConnection *source, static void commit_changes (NMSettingsConnection *connection, + NMSettingsConnectionCommitReason commit_reason, NMSettingsConnectionCommitFunc callback, gpointer user_data) { @@ -96,6 +98,8 @@ commit_changes (NMSettingsConnection *connection, if (!nm_keyfile_plugin_write_connection (NM_CONNECTION (connection), nm_settings_connection_get_filename (connection), + NM_FLAGS_ALL (commit_reason, NM_SETTINGS_CONNECTION_COMMIT_REASON_USER_ACTION + | NM_SETTINGS_CONNECTION_COMMIT_REASON_ID_CHANGED), &path, &error)) { callback (connection, error, user_data); @@ -104,10 +108,28 @@ commit_changes (NMSettingsConnection *connection, } /* Update the filename if it changed */ - if (path) + if ( path + && g_strcmp0 (path, nm_settings_connection_get_filename (connection)) != 0) { + gs_free char *old_path = g_strdup (nm_settings_connection_get_filename (connection)); + nm_settings_connection_set_filename (connection, path); + if (old_path) { + nm_log_info (LOGD_SETTINGS, "keyfile: update "NM_KEYFILE_CONNECTION_LOG_FMT" and rename from \"%s\"", + NM_KEYFILE_CONNECTION_LOG_ARG (connection), + old_path); + } else { + nm_log_info (LOGD_SETTINGS, "keyfile: update "NM_KEYFILE_CONNECTION_LOG_FMT" and persist connection", + NM_KEYFILE_CONNECTION_LOG_ARG (connection)); + } + } else { + nm_log_info (LOGD_SETTINGS, "keyfile: update "NM_KEYFILE_CONNECTION_LOG_FMT, + NM_KEYFILE_CONNECTION_LOG_ARG (connection)); + } + + g_free (path); NM_SETTINGS_CONNECTION_CLASS (nm_keyfile_connection_parent_class)->commit_changes (connection, + commit_reason, callback, user_data); } diff --git a/src/settings/plugins/keyfile/plugin.c b/src/settings/plugins/keyfile/plugin.c index 7f21e71e..e352e523 100644 --- a/src/settings/plugins/keyfile/plugin.c +++ b/src/settings/plugins/keyfile/plugin.c @@ -27,62 +27,51 @@ #include <string.h> #include <gmodule.h> -#include <glib.h> #include <glib/gstdio.h> -#include <gio/gio.h> #include <nm-connection.h> #include <nm-setting.h> #include <nm-setting-connection.h> #include <nm-utils.h> -#include <nm-config.h> -#include <nm-logging.h> +#include "nm-config.h" +#include "nm-default.h" #include "nm-core-internal.h" #include "plugin.h" -#include "nm-system-config-interface.h" +#include "nm-settings-plugin.h" #include "nm-keyfile-connection.h" #include "writer.h" -#include "common.h" #include "utils.h" -#include "gsystem-local-alloc.h" -static char *plugin_get_hostname (SCPluginKeyfile *plugin); -static void system_config_interface_init (NMSystemConfigInterface *system_config_interface_class); +static void settings_plugin_interface_init (NMSettingsPluginInterface *plugin_iface); -G_DEFINE_TYPE_EXTENDED (SCPluginKeyfile, sc_plugin_keyfile, G_TYPE_OBJECT, 0, - G_IMPLEMENT_INTERFACE (NM_TYPE_SYSTEM_CONFIG_INTERFACE, - system_config_interface_init)) +G_DEFINE_TYPE_EXTENDED (SettingsPluginKeyfile, settings_plugin_keyfile, G_TYPE_OBJECT, 0, + G_IMPLEMENT_INTERFACE (NM_TYPE_SETTINGS_PLUGIN, + settings_plugin_interface_init)) -#define SC_PLUGIN_KEYFILE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), SC_TYPE_PLUGIN_KEYFILE, SCPluginKeyfilePrivate)) +#define SETTINGS_PLUGIN_KEYFILE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), SETTINGS_TYPE_PLUGIN_KEYFILE, SettingsPluginKeyfilePrivate)) typedef struct { GHashTable *connections; /* uuid::connection */ gboolean initialized; GFileMonitor *monitor; - guint monitor_id; + gulong monitor_id; - const char *conf_file; - GFileMonitor *conf_file_monitor; - guint conf_file_monitor_id; - - char *hostname; - - gboolean disposed; -} SCPluginKeyfilePrivate; + NMConfig *config; +} SettingsPluginKeyfilePrivate; static void connection_removed_cb (NMSettingsConnection *obj, gpointer user_data) { - g_hash_table_remove (SC_PLUGIN_KEYFILE_GET_PRIVATE (user_data)->connections, + g_hash_table_remove (SETTINGS_PLUGIN_KEYFILE_GET_PRIVATE (user_data)->connections, nm_connection_get_uuid (NM_CONNECTION (obj))); } /* Monitoring */ static void -remove_connection (SCPluginKeyfile *self, NMKeyfileConnection *connection) +remove_connection (SettingsPluginKeyfile *self, NMKeyfileConnection *connection) { gboolean removed; @@ -93,7 +82,7 @@ remove_connection (SCPluginKeyfile *self, NMKeyfileConnection *connection) /* Removing from the hash table should drop the last reference */ g_object_ref (connection); g_signal_handlers_disconnect_by_func (connection, connection_removed_cb, self); - removed = g_hash_table_remove (SC_PLUGIN_KEYFILE_GET_PRIVATE (self)->connections, + removed = g_hash_table_remove (SETTINGS_PLUGIN_KEYFILE_GET_PRIVATE (self)->connections, nm_connection_get_uuid (NM_CONNECTION (connection))); nm_settings_connection_signal_remove (NM_SETTINGS_CONNECTION (connection)); g_object_unref (connection); @@ -102,9 +91,9 @@ remove_connection (SCPluginKeyfile *self, NMKeyfileConnection *connection) } static NMKeyfileConnection * -find_by_path (SCPluginKeyfile *self, const char *path) +find_by_path (SettingsPluginKeyfile *self, const char *path) { - SCPluginKeyfilePrivate *priv = SC_PLUGIN_KEYFILE_GET_PRIVATE (self); + SettingsPluginKeyfilePrivate *priv = SETTINGS_PLUGIN_KEYFILE_GET_PRIVATE (self); GHashTableIter iter; NMSettingsConnection *candidate = NULL; @@ -150,7 +139,7 @@ find_by_path (SCPluginKeyfile *self, const char *path) * Returns: the updated connection. * */ static NMKeyfileConnection * -update_connection (SCPluginKeyfile *self, +update_connection (SettingsPluginKeyfile *self, NMConnection *source, const char *full_path, NMKeyfileConnection *connection, @@ -158,7 +147,7 @@ update_connection (SCPluginKeyfile *self, GHashTable *protected_connections, GError **error) { - SCPluginKeyfilePrivate *priv = SC_PLUGIN_KEYFILE_GET_PRIVATE (self); + SettingsPluginKeyfilePrivate *priv = SETTINGS_PLUGIN_KEYFILE_GET_PRIVATE (self); NMKeyfileConnection *connection_new; NMKeyfileConnection *connection_by_uuid; GError *local = NULL; @@ -274,7 +263,7 @@ update_connection (SCPluginKeyfile *self, if (!source) { /* Only raise the signal if we were called without source, i.e. if we read the connection from file. * Otherwise, we were called by add_connection() which does not expect the signal. */ - g_signal_emit_by_name (self, NM_SYSTEM_CONFIG_INTERFACE_CONNECTION_ADDED, connection_new); + g_signal_emit_by_name (self, NM_SETTINGS_PLUGIN_CONNECTION_ADDED, connection_new); } return connection_new; } @@ -287,8 +276,8 @@ dir_changed (GFileMonitor *monitor, GFileMonitorEvent event_type, gpointer user_data) { - NMSystemConfigInterface *config = NM_SYSTEM_CONFIG_INTERFACE (user_data); - SCPluginKeyfile *self = SC_PLUGIN_KEYFILE (config); + NMSettingsPlugin *config = NM_SETTINGS_PLUGIN (user_data); + SettingsPluginKeyfile *self = SETTINGS_PLUGIN_KEYFILE (config); NMKeyfileConnection *connection; char *full_path; gboolean exists; @@ -307,12 +296,12 @@ dir_changed (GFileMonitor *monitor, switch (event_type) { case G_FILE_MONITOR_EVENT_DELETED: if (!exists && connection) - remove_connection (SC_PLUGIN_KEYFILE (config), connection); + remove_connection (SETTINGS_PLUGIN_KEYFILE (config), connection); break; case G_FILE_MONITOR_EVENT_CREATED: case G_FILE_MONITOR_EVENT_CHANGES_DONE_HINT: if (exists) - update_connection (SC_PLUGIN_KEYFILE (config), NULL, full_path, connection, TRUE, NULL, NULL); + update_connection (SETTINGS_PLUGIN_KEYFILE (config), NULL, full_path, connection, TRUE, NULL, NULL); break; default: break; @@ -322,51 +311,30 @@ dir_changed (GFileMonitor *monitor, } static void -conf_file_changed (GFileMonitor *monitor, - GFile *file, - GFile *other_file, - GFileMonitorEvent event_type, - gpointer data) +config_changed_cb (NMConfig *config, + NMConfigData *config_data, + NMConfigChangeFlags changes, + NMConfigData *old_data, + SettingsPluginKeyfile *self) { - SCPluginKeyfile *self = SC_PLUGIN_KEYFILE (data); - SCPluginKeyfilePrivate *priv = SC_PLUGIN_KEYFILE_GET_PRIVATE (self); - char *tmp; - - switch (event_type) { - case G_FILE_MONITOR_EVENT_DELETED: - case G_FILE_MONITOR_EVENT_CREATED: - case G_FILE_MONITOR_EVENT_CHANGES_DONE_HINT: - g_signal_emit_by_name (self, NM_SYSTEM_CONFIG_INTERFACE_UNMANAGED_SPECS_CHANGED); - - /* hostname */ - tmp = plugin_get_hostname (self); - if ((tmp && !priv->hostname) - || (!tmp && priv->hostname) - || (priv->hostname && tmp && strcmp (priv->hostname, tmp))) { - - g_free (priv->hostname); - priv->hostname = tmp; - tmp = NULL; - g_object_notify (G_OBJECT (self), NM_SYSTEM_CONFIG_INTERFACE_HOSTNAME); - } + gs_free char *old_value = NULL, *new_value = NULL; - g_free (tmp); + old_value = nm_config_data_get_value (old_data, NM_CONFIG_KEYFILE_GROUP_KEYFILE, NM_CONFIG_KEYFILE_KEY_KEYFILE_UNMANAGED_DEVICES, NM_CONFIG_GET_VALUE_TYPE_SPEC); + new_value = nm_config_data_get_value (config_data, NM_CONFIG_KEYFILE_GROUP_KEYFILE, NM_CONFIG_KEYFILE_KEY_KEYFILE_UNMANAGED_DEVICES, NM_CONFIG_GET_VALUE_TYPE_SPEC); - break; - default: - break; - } + if (g_strcmp0 (old_value, new_value) != 0) + g_signal_emit_by_name (self, NM_SETTINGS_PLUGIN_UNMANAGED_SPECS_CHANGED); } static void -setup_monitoring (NMSystemConfigInterface *config) +setup_monitoring (NMSettingsPlugin *config) { - SCPluginKeyfilePrivate *priv = SC_PLUGIN_KEYFILE_GET_PRIVATE (config); + SettingsPluginKeyfilePrivate *priv = SETTINGS_PLUGIN_KEYFILE_GET_PRIVATE (config); GFile *file; GFileMonitor *monitor; if (nm_config_get_monitor_connection_files (nm_config_get ())) { - file = g_file_new_for_path (KEYFILE_DIR); + file = g_file_new_for_path (nm_keyfile_plugin_get_path ()); monitor = g_file_monitor_directory (file, G_FILE_MONITOR_NONE, NULL, NULL); g_object_unref (file); @@ -376,16 +344,10 @@ setup_monitoring (NMSystemConfigInterface *config) } } - if (priv->conf_file) { - file = g_file_new_for_path (priv->conf_file); - monitor = g_file_monitor_file (file, G_FILE_MONITOR_NONE, NULL, NULL); - g_object_unref (file); - - if (monitor) { - priv->conf_file_monitor_id = g_signal_connect (monitor, "changed", G_CALLBACK (conf_file_changed), config); - priv->conf_file_monitor = monitor; - } - } + g_signal_connect (G_OBJECT (priv->config), + NM_CONFIG_SIGNAL_CONFIG_CHANGED, + G_CALLBACK (config_changed_cb), + config); } static GHashTable * @@ -426,10 +388,10 @@ _sort_paths (const char **f1, const char **f2, GHashTable *paths) } static void -read_connections (NMSystemConfigInterface *config) +read_connections (NMSettingsPlugin *config) { - SCPluginKeyfile *self = SC_PLUGIN_KEYFILE (config); - SCPluginKeyfilePrivate *priv = SC_PLUGIN_KEYFILE_GET_PRIVATE (self); + SettingsPluginKeyfile *self = SETTINGS_PLUGIN_KEYFILE (config); + SettingsPluginKeyfilePrivate *priv = SETTINGS_PLUGIN_KEYFILE_GET_PRIVATE (self); GDir *dir; GError *error = NULL; const char *item; @@ -441,10 +403,10 @@ read_connections (NMSystemConfigInterface *config) GPtrArray *filenames; GHashTable *paths; - dir = g_dir_open (KEYFILE_DIR, 0, &error); + dir = g_dir_open (nm_keyfile_plugin_get_path (), 0, &error); if (!dir) { nm_log_warn (LOGD_SETTINGS, "keyfile: cannot read directory '%s': (%d) %s", - KEYFILE_DIR, + nm_keyfile_plugin_get_path (), error ? error->code : -1, error && error->message ? error->message : "(unknown)"); g_clear_error (&error); @@ -457,7 +419,7 @@ read_connections (NMSystemConfigInterface *config) while ((item = g_dir_read_name (dir))) { if (nm_keyfile_plugin_utils_should_ignore_file (item)) continue; - g_ptr_array_add (filenames, g_build_filename (KEYFILE_DIR, item, NULL)); + g_ptr_array_add (filenames, g_build_filename (nm_keyfile_plugin_get_path (), item, NULL)); } g_dir_close (dir); @@ -499,9 +461,9 @@ read_connections (NMSystemConfigInterface *config) /* Plugin */ static GSList * -get_connections (NMSystemConfigInterface *config) +get_connections (NMSettingsPlugin *config) { - SCPluginKeyfilePrivate *priv = SC_PLUGIN_KEYFILE_GET_PRIVATE (config); + SettingsPluginKeyfilePrivate *priv = SETTINGS_PLUGIN_KEYFILE_GET_PRIVATE (config); if (!priv->initialized) { setup_monitoring (config); @@ -512,14 +474,14 @@ get_connections (NMSystemConfigInterface *config) } static gboolean -load_connection (NMSystemConfigInterface *config, +load_connection (NMSettingsPlugin *config, const char *filename) { - SCPluginKeyfile *self = SC_PLUGIN_KEYFILE (config); + SettingsPluginKeyfile *self = SETTINGS_PLUGIN_KEYFILE (config); NMKeyfileConnection *connection; - int dir_len = strlen (KEYFILE_DIR); + int dir_len = strlen (nm_keyfile_plugin_get_path ()); - if ( strncmp (filename, KEYFILE_DIR, dir_len) != 0 + if ( strncmp (filename, nm_keyfile_plugin_get_path (), dir_len) != 0 || filename[dir_len] != '/' || strchr (filename + dir_len + 1, '/') != NULL) return FALSE; @@ -533,157 +495,46 @@ load_connection (NMSystemConfigInterface *config, } static void -reload_connections (NMSystemConfigInterface *config) +reload_connections (NMSettingsPlugin *config) { read_connections (config); } static NMSettingsConnection * -add_connection (NMSystemConfigInterface *config, +add_connection (NMSettingsPlugin *config, NMConnection *connection, gboolean save_to_disk, GError **error) { - SCPluginKeyfile *self = SC_PLUGIN_KEYFILE (config); + SettingsPluginKeyfile *self = SETTINGS_PLUGIN_KEYFILE (config); gs_free char *path = NULL; if (save_to_disk) { - if (!nm_keyfile_plugin_write_connection (connection, NULL, &path, error)) + if (!nm_keyfile_plugin_write_connection (connection, NULL, FALSE, &path, error)) return NULL; } return NM_SETTINGS_CONNECTION (update_connection (self, connection, path, NULL, FALSE, NULL, error)); } -static gboolean -parse_key_file_allow_none (SCPluginKeyfilePrivate *priv, - GKeyFile *key_file, - GError **error) -{ - gboolean ret = FALSE; - GError *local_error = NULL; - - if (!g_key_file_load_from_file (key_file, priv->conf_file, G_KEY_FILE_NONE, &local_error)) { - if (g_error_matches (local_error, G_FILE_ERROR, G_FILE_ERROR_NOENT)) - g_clear_error (&local_error); - else { - g_propagate_prefixed_error (error, local_error, - "Error parsing file '%s': ", - priv->conf_file); - goto out; - } - } - ret = TRUE; - - out: - return ret; -} - static GSList * -get_unmanaged_specs (NMSystemConfigInterface *config) -{ - SCPluginKeyfilePrivate *priv = SC_PLUGIN_KEYFILE_GET_PRIVATE (config); - GKeyFile *key_file; - GSList *specs = NULL; - GError *error = NULL; - - if (!priv->conf_file) - return NULL; - - key_file = nm_config_create_keyfile (); - if (parse_key_file_allow_none (priv, key_file, &error)) - specs = nm_config_get_device_match_spec (key_file, NM_CONFIG_KEYFILE_GROUP_KEYFILE, "unmanaged-devices", NULL); - - if (error) { - nm_log_warn (LOGD_SETTINGS, "keyfile: error getting unmanaged specs: %s", error->message); - g_error_free (error); - } - g_key_file_free (key_file); - - return specs; -} - -static char * -plugin_get_hostname (SCPluginKeyfile *plugin) -{ - SCPluginKeyfilePrivate *priv = SC_PLUGIN_KEYFILE_GET_PRIVATE (plugin); - GKeyFile *key_file; - char *hostname = NULL; - GError *error = NULL; - - if (!priv->conf_file) - return NULL; - - key_file = g_key_file_new (); - if (!parse_key_file_allow_none (priv, key_file, &error)) - goto out; - - hostname = g_key_file_get_value (key_file, NM_CONFIG_KEYFILE_GROUP_KEYFILE, "hostname", NULL); - - out: - if (error) { - nm_log_warn (LOGD_SETTINGS, "keyfile: error getting hostname: %s", error->message); - g_error_free (error); - } - if (key_file) - g_key_file_free (key_file); - - return hostname; -} - -static gboolean -plugin_set_hostname (SCPluginKeyfile *plugin, const char *hostname) +get_unmanaged_specs (NMSettingsPlugin *config) { - gboolean ret = FALSE; - SCPluginKeyfilePrivate *priv = SC_PLUGIN_KEYFILE_GET_PRIVATE (plugin); - GKeyFile *key_file = NULL; - GError *error = NULL; - char *data = NULL; - gsize len; - - if (!priv->conf_file) { - g_set_error (&error, G_IO_ERROR, G_IO_ERROR_FAILED, - "Error saving hostname: no config file"); - goto out; - } - - g_free (priv->hostname); - priv->hostname = g_strdup (hostname); - - key_file = g_key_file_new (); - if (!parse_key_file_allow_none (priv, key_file, &error)) - goto out; - - g_key_file_set_string (key_file, NM_CONFIG_KEYFILE_GROUP_KEYFILE, "hostname", hostname); - - data = g_key_file_to_data (key_file, &len, &error); - if (!data) - goto out; - - if (!g_file_set_contents (priv->conf_file, data, len, &error)) { - g_prefix_error (&error, "Error saving hostname: "); - goto out; - } - - ret = TRUE; - - out: - if (error) { - nm_log_warn (LOGD_SETTINGS, "keyfile: error setting hostname: %s", error->message); - g_error_free (error); - } - g_free (data); - if (key_file) - g_key_file_free (key_file); - - return ret; + SettingsPluginKeyfilePrivate *priv = SETTINGS_PLUGIN_KEYFILE_GET_PRIVATE (config); + gs_free char *value = NULL; + + value = nm_config_data_get_value (nm_config_get_data (priv->config), + NM_CONFIG_KEYFILE_GROUP_KEYFILE, + NM_CONFIG_KEYFILE_KEY_KEYFILE_UNMANAGED_DEVICES, + NM_CONFIG_GET_VALUE_TYPE_SPEC); + return nm_match_spec_split (value); } /* GObject */ static void -sc_plugin_keyfile_init (SCPluginKeyfile *plugin) +settings_plugin_keyfile_init (SettingsPluginKeyfile *plugin) { - SCPluginKeyfilePrivate *priv = SC_PLUGIN_KEYFILE_GET_PRIVATE (plugin); + SettingsPluginKeyfilePrivate *priv = SETTINGS_PLUGIN_KEYFILE_GET_PRIVATE (plugin); priv->connections = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref); } @@ -693,18 +544,14 @@ get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) { switch (prop_id) { - case NM_SYSTEM_CONFIG_INTERFACE_PROP_NAME: + case NM_SETTINGS_PLUGIN_PROP_NAME: g_value_set_string (value, KEYFILE_PLUGIN_NAME); break; - case NM_SYSTEM_CONFIG_INTERFACE_PROP_INFO: + case NM_SETTINGS_PLUGIN_PROP_INFO: g_value_set_string (value, KEYFILE_PLUGIN_INFO); break; - case NM_SYSTEM_CONFIG_INTERFACE_PROP_CAPABILITIES: - g_value_set_uint (value, NM_SYSTEM_CONFIG_INTERFACE_CAP_MODIFY_CONNECTIONS | - NM_SYSTEM_CONFIG_INTERFACE_CAP_MODIFY_HOSTNAME); - break; - case NM_SYSTEM_CONFIG_INTERFACE_PROP_HOSTNAME: - g_value_set_string (value, SC_PLUGIN_KEYFILE_GET_PRIVATE (object)->hostname); + case NM_SETTINGS_PLUGIN_PROP_CAPABILITIES: + g_value_set_uint (value, NM_SETTINGS_PLUGIN_CAP_MODIFY_CONNECTIONS); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); @@ -716,15 +563,7 @@ static void set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) { - const char *hostname; - switch (prop_id) { - case NM_SYSTEM_CONFIG_INTERFACE_PROP_HOSTNAME: - hostname = g_value_get_string (value); - if (hostname && strlen (hostname) < 1) - hostname = NULL; - plugin_set_hostname (SC_PLUGIN_KEYFILE (object), hostname); - break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; @@ -732,97 +571,81 @@ set_property (GObject *object, guint prop_id, } static void -dispose (GObject *object) +constructed (GObject *object) { - SCPluginKeyfilePrivate *priv = SC_PLUGIN_KEYFILE_GET_PRIVATE (object); - - if (priv->disposed) - goto out; + SettingsPluginKeyfilePrivate *priv = SETTINGS_PLUGIN_KEYFILE_GET_PRIVATE (object); + + priv->config = g_object_ref (nm_config_get ()); + if (nm_config_data_has_value (nm_config_get_data_orig (priv->config), + NM_CONFIG_KEYFILE_GROUP_KEYFILE, + NM_CONFIG_KEYFILE_KEY_KEYFILE_HOSTNAME, + NM_CONFIG_GET_VALUE_RAW)) + nm_log_warn (LOGD_SETTINGS, "keyfile: 'hostname' option is deprecated and has no effect"); +} - priv->disposed = TRUE; +static void +dispose (GObject *object) +{ + SettingsPluginKeyfilePrivate *priv = SETTINGS_PLUGIN_KEYFILE_GET_PRIVATE (object); if (priv->monitor) { - if (priv->monitor_id) - g_signal_handler_disconnect (priv->monitor, priv->monitor_id); + nm_clear_g_signal_handler (priv->monitor, &priv->monitor_id); g_file_monitor_cancel (priv->monitor); - g_object_unref (priv->monitor); - } - - if (priv->conf_file_monitor) { - if (priv->conf_file_monitor_id) - g_signal_handler_disconnect (priv->conf_file_monitor, priv->conf_file_monitor_id); - - g_file_monitor_cancel (priv->conf_file_monitor); - g_object_unref (priv->conf_file_monitor); + g_clear_object (&priv->monitor); } - g_free (priv->hostname); - if (priv->connections) { g_hash_table_destroy (priv->connections); priv->connections = NULL; } -out: - G_OBJECT_CLASS (sc_plugin_keyfile_parent_class)->dispose (object); + if (priv->config) { + g_signal_handlers_disconnect_by_func (priv->config, config_changed_cb, object); + g_clear_object (&priv->config); + } + + G_OBJECT_CLASS (settings_plugin_keyfile_parent_class)->dispose (object); } static void -sc_plugin_keyfile_class_init (SCPluginKeyfileClass *req_class) +settings_plugin_keyfile_class_init (SettingsPluginKeyfileClass *req_class) { GObjectClass *object_class = G_OBJECT_CLASS (req_class); - g_type_class_add_private (req_class, sizeof (SCPluginKeyfilePrivate)); + g_type_class_add_private (req_class, sizeof (SettingsPluginKeyfilePrivate)); + object_class->constructed = constructed; object_class->dispose = dispose; object_class->get_property = get_property; object_class->set_property = set_property; g_object_class_override_property (object_class, - NM_SYSTEM_CONFIG_INTERFACE_PROP_NAME, - NM_SYSTEM_CONFIG_INTERFACE_NAME); - - g_object_class_override_property (object_class, - NM_SYSTEM_CONFIG_INTERFACE_PROP_INFO, - NM_SYSTEM_CONFIG_INTERFACE_INFO); + NM_SETTINGS_PLUGIN_PROP_NAME, + NM_SETTINGS_PLUGIN_NAME); g_object_class_override_property (object_class, - NM_SYSTEM_CONFIG_INTERFACE_PROP_CAPABILITIES, - NM_SYSTEM_CONFIG_INTERFACE_CAPABILITIES); + NM_SETTINGS_PLUGIN_PROP_INFO, + NM_SETTINGS_PLUGIN_INFO); g_object_class_override_property (object_class, - NM_SYSTEM_CONFIG_INTERFACE_PROP_HOSTNAME, - NM_SYSTEM_CONFIG_INTERFACE_HOSTNAME); + NM_SETTINGS_PLUGIN_PROP_CAPABILITIES, + NM_SETTINGS_PLUGIN_CAPABILITIES); } static void -system_config_interface_init (NMSystemConfigInterface *system_config_interface_class) +settings_plugin_interface_init (NMSettingsPluginInterface *plugin_iface) { /* interface implementation */ - system_config_interface_class->get_connections = get_connections; - system_config_interface_class->load_connection = load_connection; - system_config_interface_class->reload_connections = reload_connections; - system_config_interface_class->add_connection = add_connection; - system_config_interface_class->get_unmanaged_specs = get_unmanaged_specs; + plugin_iface->get_connections = get_connections; + plugin_iface->load_connection = load_connection; + plugin_iface->reload_connections = reload_connections; + plugin_iface->add_connection = add_connection; + plugin_iface->get_unmanaged_specs = get_unmanaged_specs; } GObject * nm_settings_keyfile_plugin_new (void) { - static SCPluginKeyfile *singleton = NULL; - SCPluginKeyfilePrivate *priv; - - if (!singleton) { - singleton = SC_PLUGIN_KEYFILE (g_object_new (SC_TYPE_PLUGIN_KEYFILE, NULL)); - priv = SC_PLUGIN_KEYFILE_GET_PRIVATE (singleton); - - priv->conf_file = nm_config_data_get_config_main_file (nm_config_get_data (nm_config_get ())); - - /* plugin_set_hostname() has to be called *after* priv->conf_file is set */ - priv->hostname = plugin_get_hostname (singleton); - } else - g_object_ref (singleton); - - return G_OBJECT (singleton); + return g_object_new (SETTINGS_TYPE_PLUGIN_KEYFILE, NULL); } diff --git a/src/settings/plugins/keyfile/plugin.h b/src/settings/plugins/keyfile/plugin.h index 48579785..07403270 100644 --- a/src/settings/plugins/keyfile/plugin.h +++ b/src/settings/plugins/keyfile/plugin.h @@ -22,24 +22,24 @@ #ifndef _PLUGIN_H_ #define _PLUGIN_H_ -#include <glib-object.h> +#include "nm-default.h" -#define SC_TYPE_PLUGIN_KEYFILE (sc_plugin_keyfile_get_type ()) -#define SC_PLUGIN_KEYFILE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), SC_TYPE_PLUGIN_KEYFILE, SCPluginKeyfile)) -#define SC_PLUGIN_KEYFILE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), SC_TYPE_PLUGIN_KEYFILE, SCPluginKeyfileClass)) -#define SC_IS_PLUGIN_KEYFILE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), SC_TYPE_PLUGIN_KEYFILE)) -#define SC_IS_PLUGIN_KEYFILE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), SC_TYPE_PLUGIN_KEYFILE)) -#define SC_PLUGIN_KEYFILE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), SC_TYPE_PLUGIN_KEYFILE, SCPluginKeyfileClass)) +#define SETTINGS_TYPE_PLUGIN_KEYFILE (settings_plugin_keyfile_get_type ()) +#define SETTINGS_PLUGIN_KEYFILE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), SETTINGS_TYPE_PLUGIN_KEYFILE, SettingsPluginKeyfile)) +#define SETTINGS_PLUGIN_KEYFILE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), SETTINGS_TYPE_PLUGIN_KEYFILE, SettingsPluginKeyfileClass)) +#define SETTINGS_IS_PLUGIN_KEYFILE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), SETTINGS_TYPE_PLUGIN_KEYFILE)) +#define SETTINGS_IS_PLUGIN_KEYFILE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), SETTINGS_TYPE_PLUGIN_KEYFILE)) +#define SETTINGS_PLUGIN_KEYFILE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), SETTINGS_TYPE_PLUGIN_KEYFILE, SettingsPluginKeyfileClass)) typedef struct { GObject parent; -} SCPluginKeyfile; +} SettingsPluginKeyfile; typedef struct { GObjectClass parent; -} SCPluginKeyfileClass; +} SettingsPluginKeyfileClass; -GType sc_plugin_keyfile_get_type (void); +GType settings_plugin_keyfile_get_type (void); GObject *nm_settings_keyfile_plugin_new (void); diff --git a/src/settings/plugins/keyfile/reader.c b/src/settings/plugins/keyfile/reader.c index bd08c17d..1c984a16 100644 --- a/src/settings/plugins/keyfile/reader.c +++ b/src/settings/plugins/keyfile/reader.c @@ -25,7 +25,7 @@ #include "reader.h" -#include "nm-logging.h" +#include "nm-default.h" #include "nm-keyfile-internal.h" #include "NetworkManagerUtils.h" diff --git a/src/settings/plugins/keyfile/reader.h b/src/settings/plugins/keyfile/reader.h index 55819630..a8021cb7 100644 --- a/src/settings/plugins/keyfile/reader.h +++ b/src/settings/plugins/keyfile/reader.h @@ -22,9 +22,10 @@ #ifndef _KEYFILE_PLUGIN_READER_H #define _KEYFILE_PLUGIN_READER_H -#include <glib.h> #include <nm-connection.h> +#include "nm-default.h" + NMConnection *nm_keyfile_plugin_connection_from_file (const char *filename, GError **error); #endif /* _KEYFILE_PLUGIN_READER_H */ diff --git a/src/settings/plugins/keyfile/tests/Makefile.am b/src/settings/plugins/keyfile/tests/Makefile.am index cbe3f73b..4d85f09a 100644 --- a/src/settings/plugins/keyfile/tests/Makefile.am +++ b/src/settings/plugins/keyfile/tests/Makefile.am @@ -5,18 +5,17 @@ SUBDIRS=keyfiles @GNOME_CODE_COVERAGE_RULES@ AM_CPPFLAGS = \ - -I$(top_srcdir)/include \ - -I$(top_builddir)/include \ + -I$(top_srcdir)/shared \ + -I$(top_builddir)/shared \ -I$(top_srcdir)/libnm-core \ -I$(top_builddir)/libnm-core \ -I$(top_srcdir)/src \ -I$(top_srcdir)/src/settings \ -I$(srcdir)/../ \ $(GLIB_CFLAGS) \ - $(DBUS_CFLAGS) \ $(CODE_COVERAGE_CFLAGS) \ -DG_LOG_DOMAIN=\""NetworkManager-keyfile"\" \ - -DNETWORKMANAGER_COMPILATION \ + -DNETWORKMANAGER_COMPILATION=NM_NETWORKMANAGER_COMPILATION_INSIDE_DAEMON \ -DNM_VERSION_MAX_ALLOWED=NM_VERSION_NEXT_STABLE \ -DTEST_KEYFILES_DIR=\"$(abs_srcdir)/keyfiles\" \ -DTEST_SCRATCH_DIR=\"$(abs_builddir)/keyfiles\" \ @@ -32,7 +31,6 @@ test_keyfile_SOURCES = \ test_keyfile_LDADD = \ $(top_builddir)/src/libNetworkManager.la \ - $(DBUS_LIBS) \ $(CODE_COVERAGE_LDFLAGS) @VALGRIND_RULES@ diff --git a/src/settings/plugins/keyfile/tests/Makefile.in b/src/settings/plugins/keyfile/tests/Makefile.in index 6dfaf110..7577df57 100644 --- a/src/settings/plugins/keyfile/tests/Makefile.in +++ b/src/settings/plugins/keyfile/tests/Makefile.in @@ -122,7 +122,7 @@ test_keyfile_OBJECTS = $(am_test_keyfile_OBJECTS) am__DEPENDENCIES_1 = @ENABLE_TESTS_TRUE@test_keyfile_DEPENDENCIES = \ @ENABLE_TESTS_TRUE@ $(top_builddir)/src/libNetworkManager.la \ -@ENABLE_TESTS_TRUE@ $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) +@ENABLE_TESTS_TRUE@ $(am__DEPENDENCIES_1) AM_V_lt = $(am__v_lt_@AM_V@) am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@) am__v_lt_0 = --silent @@ -450,7 +450,6 @@ BLUEZ5_LIBS = @BLUEZ5_LIBS@ CC = @CC@ CCDEPMODE = @CCDEPMODE@ CFLAGS = @CFLAGS@ -CKDB_PATH = @CKDB_PATH@ CODE_COVERAGE_CFLAGS = @CODE_COVERAGE_CFLAGS@ CODE_COVERAGE_ENABLED = @CODE_COVERAGE_ENABLED@ CODE_COVERAGE_LDFLAGS = @CODE_COVERAGE_LDFLAGS@ @@ -462,8 +461,6 @@ CXXDEPMODE = @CXXDEPMODE@ CXXFLAGS = @CXXFLAGS@ CYGPATH_W = @CYGPATH_W@ DBUS_CFLAGS = @DBUS_CFLAGS@ -DBUS_GLIB_100_CFLAGS = @DBUS_GLIB_100_CFLAGS@ -DBUS_GLIB_100_LIBS = @DBUS_GLIB_100_LIBS@ DBUS_LIBS = @DBUS_LIBS@ DBUS_SYS_DIR = @DBUS_SYS_DIR@ DEFS = @DEFS@ @@ -473,6 +470,7 @@ DHCPCD_PATH = @DHCPCD_PATH@ DISTRO_NETWORK_SERVICE = @DISTRO_NETWORK_SERVICE@ DLLTOOL = @DLLTOOL@ DNSMASQ_PATH = @DNSMASQ_PATH@ +DNSSEC_TRIGGER_SCRIPT = @DNSSEC_TRIGGER_SCRIPT@ DSYMUTIL = @DSYMUTIL@ DUMPBIN = @DUMPBIN@ ECHO_C = @ECHO_C@ @@ -527,16 +525,13 @@ INTROSPECTION_MAKEFILE = @INTROSPECTION_MAKEFILE@ INTROSPECTION_SCANNER = @INTROSPECTION_SCANNER@ INTROSPECTION_TYPELIBDIR = @INTROSPECTION_TYPELIBDIR@ IPTABLES_PATH = @IPTABLES_PATH@ -IWMX_SDK_CFLAGS = @IWMX_SDK_CFLAGS@ -IWMX_SDK_LIBS = @IWMX_SDK_LIBS@ KERNEL_FIRMWARE_DIR = @KERNEL_FIRMWARE_DIR@ LCOV = @LCOV@ LD = @LD@ LDFLAGS = @LDFLAGS@ +LIBAUDIT_CFLAGS = @LIBAUDIT_CFLAGS@ +LIBAUDIT_LIBS = @LIBAUDIT_LIBS@ LIBDL = @LIBDL@ -LIBGCRYPT_CFLAGS = @LIBGCRYPT_CFLAGS@ -LIBGCRYPT_CONFIG = @LIBGCRYPT_CONFIG@ -LIBGCRYPT_LIBS = @LIBGCRYPT_LIBS@ LIBICONV = @LIBICONV@ LIBINTL = @LIBINTL@ LIBM = @LIBM@ @@ -573,6 +568,8 @@ NEWT_LIBS = @NEWT_LIBS@ NM = @NM@ NMEDIT = @NMEDIT@ NM_CONFIG_DEFAULT_AUTH_POLKIT_TEXT = @NM_CONFIG_DEFAULT_AUTH_POLKIT_TEXT@ +NM_CONFIG_DEFAULT_LOGGING_AUDIT_TEXT = @NM_CONFIG_DEFAULT_LOGGING_AUDIT_TEXT@ +NM_CONFIG_LOGGING_BACKEND_DEFAULT_TEXT = @NM_CONFIG_LOGGING_BACKEND_DEFAULT_TEXT@ NM_MAJOR_VERSION = @NM_MAJOR_VERSION@ NM_MICRO_VERSION = @NM_MICRO_VERSION@ NM_MINOR_VERSION = @NM_MINOR_VERSION@ @@ -601,7 +598,6 @@ POLKIT_LIBS = @POLKIT_LIBS@ POSUB = @POSUB@ PPPD_PATH = @PPPD_PATH@ PPPD_PLUGIN_DIR = @PPPD_PLUGIN_DIR@ -PPPOE_PATH = @PPPOE_PATH@ QT_CFLAGS = @QT_CFLAGS@ QT_LIBS = @QT_LIBS@ RANLIB = @RANLIB@ @@ -616,6 +612,8 @@ SYSTEMD_200_CFLAGS = @SYSTEMD_200_CFLAGS@ SYSTEMD_200_LIBS = @SYSTEMD_200_LIBS@ SYSTEMD_INHIBIT_CFLAGS = @SYSTEMD_INHIBIT_CFLAGS@ SYSTEMD_INHIBIT_LIBS = @SYSTEMD_INHIBIT_LIBS@ +SYSTEMD_JOURNAL_CFLAGS = @SYSTEMD_JOURNAL_CFLAGS@ +SYSTEMD_JOURNAL_LIBS = @SYSTEMD_JOURNAL_LIBS@ SYSTEMD_LOGIN_CFLAGS = @SYSTEMD_LOGIN_CFLAGS@ SYSTEMD_LOGIN_LIBS = @SYSTEMD_LOGIN_LIBS@ SYSTEM_CA_PATH = @SYSTEM_CA_PATH@ @@ -676,6 +674,7 @@ mkdir_p = @mkdir_p@ nmbinary = @nmbinary@ nmconfdir = @nmconfdir@ nmdatadir = @nmdatadir@ +nmlibdir = @nmlibdir@ nmrundir = @nmrundir@ nmstatedir = @nmstatedir@ oldincludedir = @oldincludedir@ @@ -683,6 +682,7 @@ pdfdir = @pdfdir@ prefix = @prefix@ program_transform_name = @program_transform_name@ psdir = @psdir@ +runstatedir = @runstatedir@ sbindir = @sbindir@ sharedstatedir = @sharedstatedir@ srcdir = @srcdir@ @@ -700,18 +700,17 @@ with_resolvconf = @with_resolvconf@ with_valgrind = @with_valgrind@ @ENABLE_TESTS_TRUE@SUBDIRS = keyfiles @ENABLE_TESTS_TRUE@AM_CPPFLAGS = \ -@ENABLE_TESTS_TRUE@ -I$(top_srcdir)/include \ -@ENABLE_TESTS_TRUE@ -I$(top_builddir)/include \ +@ENABLE_TESTS_TRUE@ -I$(top_srcdir)/shared \ +@ENABLE_TESTS_TRUE@ -I$(top_builddir)/shared \ @ENABLE_TESTS_TRUE@ -I$(top_srcdir)/libnm-core \ @ENABLE_TESTS_TRUE@ -I$(top_builddir)/libnm-core \ @ENABLE_TESTS_TRUE@ -I$(top_srcdir)/src \ @ENABLE_TESTS_TRUE@ -I$(top_srcdir)/src/settings \ @ENABLE_TESTS_TRUE@ -I$(srcdir)/../ \ @ENABLE_TESTS_TRUE@ $(GLIB_CFLAGS) \ -@ENABLE_TESTS_TRUE@ $(DBUS_CFLAGS) \ @ENABLE_TESTS_TRUE@ $(CODE_COVERAGE_CFLAGS) \ @ENABLE_TESTS_TRUE@ -DG_LOG_DOMAIN=\""NetworkManager-keyfile"\" \ -@ENABLE_TESTS_TRUE@ -DNETWORKMANAGER_COMPILATION \ +@ENABLE_TESTS_TRUE@ -DNETWORKMANAGER_COMPILATION=NM_NETWORKMANAGER_COMPILATION_INSIDE_DAEMON \ @ENABLE_TESTS_TRUE@ -DNM_VERSION_MAX_ALLOWED=NM_VERSION_NEXT_STABLE \ @ENABLE_TESTS_TRUE@ -DTEST_KEYFILES_DIR=\"$(abs_srcdir)/keyfiles\" \ @ENABLE_TESTS_TRUE@ -DTEST_SCRATCH_DIR=\"$(abs_builddir)/keyfiles\" \ @@ -725,7 +724,6 @@ with_valgrind = @with_valgrind@ @ENABLE_TESTS_TRUE@test_keyfile_LDADD = \ @ENABLE_TESTS_TRUE@ $(top_builddir)/src/libNetworkManager.la \ -@ENABLE_TESTS_TRUE@ $(DBUS_LIBS) \ @ENABLE_TESTS_TRUE@ $(CODE_COVERAGE_LDFLAGS) all: all-recursive diff --git a/src/settings/plugins/keyfile/tests/keyfiles/ATT_Data_Connect_Plain b/src/settings/plugins/keyfile/tests/keyfiles/ATT_Data_Connect_Plain index 902b8427..11e1ec6f 100644 --- a/src/settings/plugins/keyfile/tests/keyfiles/ATT_Data_Connect_Plain +++ b/src/settings/plugins/keyfile/tests/keyfiles/ATT_Data_Connect_Plain @@ -15,6 +15,9 @@ password=CINGULAR1 apn=ISP.CINGULAR network-id=24005 pin=2345 +device-id=da812de91eec16620b06cd0ca5cbc7ea25245222 +sim-id=89148000000060671234 +sim-operator-id=310260 [serial] baud=115200 diff --git a/src/settings/plugins/keyfile/tests/keyfiles/Makefile.in b/src/settings/plugins/keyfile/tests/keyfiles/Makefile.in index 33d0e0c5..56f0735f 100644 --- a/src/settings/plugins/keyfile/tests/keyfiles/Makefile.in +++ b/src/settings/plugins/keyfile/tests/keyfiles/Makefile.in @@ -146,7 +146,6 @@ BLUEZ5_LIBS = @BLUEZ5_LIBS@ CC = @CC@ CCDEPMODE = @CCDEPMODE@ CFLAGS = @CFLAGS@ -CKDB_PATH = @CKDB_PATH@ CODE_COVERAGE_CFLAGS = @CODE_COVERAGE_CFLAGS@ CODE_COVERAGE_ENABLED = @CODE_COVERAGE_ENABLED@ CODE_COVERAGE_LDFLAGS = @CODE_COVERAGE_LDFLAGS@ @@ -158,8 +157,6 @@ CXXDEPMODE = @CXXDEPMODE@ CXXFLAGS = @CXXFLAGS@ CYGPATH_W = @CYGPATH_W@ DBUS_CFLAGS = @DBUS_CFLAGS@ -DBUS_GLIB_100_CFLAGS = @DBUS_GLIB_100_CFLAGS@ -DBUS_GLIB_100_LIBS = @DBUS_GLIB_100_LIBS@ DBUS_LIBS = @DBUS_LIBS@ DBUS_SYS_DIR = @DBUS_SYS_DIR@ DEFS = @DEFS@ @@ -169,6 +166,7 @@ DHCPCD_PATH = @DHCPCD_PATH@ DISTRO_NETWORK_SERVICE = @DISTRO_NETWORK_SERVICE@ DLLTOOL = @DLLTOOL@ DNSMASQ_PATH = @DNSMASQ_PATH@ +DNSSEC_TRIGGER_SCRIPT = @DNSSEC_TRIGGER_SCRIPT@ DSYMUTIL = @DSYMUTIL@ DUMPBIN = @DUMPBIN@ ECHO_C = @ECHO_C@ @@ -223,16 +221,13 @@ INTROSPECTION_MAKEFILE = @INTROSPECTION_MAKEFILE@ INTROSPECTION_SCANNER = @INTROSPECTION_SCANNER@ INTROSPECTION_TYPELIBDIR = @INTROSPECTION_TYPELIBDIR@ IPTABLES_PATH = @IPTABLES_PATH@ -IWMX_SDK_CFLAGS = @IWMX_SDK_CFLAGS@ -IWMX_SDK_LIBS = @IWMX_SDK_LIBS@ KERNEL_FIRMWARE_DIR = @KERNEL_FIRMWARE_DIR@ LCOV = @LCOV@ LD = @LD@ LDFLAGS = @LDFLAGS@ +LIBAUDIT_CFLAGS = @LIBAUDIT_CFLAGS@ +LIBAUDIT_LIBS = @LIBAUDIT_LIBS@ LIBDL = @LIBDL@ -LIBGCRYPT_CFLAGS = @LIBGCRYPT_CFLAGS@ -LIBGCRYPT_CONFIG = @LIBGCRYPT_CONFIG@ -LIBGCRYPT_LIBS = @LIBGCRYPT_LIBS@ LIBICONV = @LIBICONV@ LIBINTL = @LIBINTL@ LIBM = @LIBM@ @@ -269,6 +264,8 @@ NEWT_LIBS = @NEWT_LIBS@ NM = @NM@ NMEDIT = @NMEDIT@ NM_CONFIG_DEFAULT_AUTH_POLKIT_TEXT = @NM_CONFIG_DEFAULT_AUTH_POLKIT_TEXT@ +NM_CONFIG_DEFAULT_LOGGING_AUDIT_TEXT = @NM_CONFIG_DEFAULT_LOGGING_AUDIT_TEXT@ +NM_CONFIG_LOGGING_BACKEND_DEFAULT_TEXT = @NM_CONFIG_LOGGING_BACKEND_DEFAULT_TEXT@ NM_MAJOR_VERSION = @NM_MAJOR_VERSION@ NM_MICRO_VERSION = @NM_MICRO_VERSION@ NM_MINOR_VERSION = @NM_MINOR_VERSION@ @@ -297,7 +294,6 @@ POLKIT_LIBS = @POLKIT_LIBS@ POSUB = @POSUB@ PPPD_PATH = @PPPD_PATH@ PPPD_PLUGIN_DIR = @PPPD_PLUGIN_DIR@ -PPPOE_PATH = @PPPOE_PATH@ QT_CFLAGS = @QT_CFLAGS@ QT_LIBS = @QT_LIBS@ RANLIB = @RANLIB@ @@ -312,6 +308,8 @@ SYSTEMD_200_CFLAGS = @SYSTEMD_200_CFLAGS@ SYSTEMD_200_LIBS = @SYSTEMD_200_LIBS@ SYSTEMD_INHIBIT_CFLAGS = @SYSTEMD_INHIBIT_CFLAGS@ SYSTEMD_INHIBIT_LIBS = @SYSTEMD_INHIBIT_LIBS@ +SYSTEMD_JOURNAL_CFLAGS = @SYSTEMD_JOURNAL_CFLAGS@ +SYSTEMD_JOURNAL_LIBS = @SYSTEMD_JOURNAL_LIBS@ SYSTEMD_LOGIN_CFLAGS = @SYSTEMD_LOGIN_CFLAGS@ SYSTEMD_LOGIN_LIBS = @SYSTEMD_LOGIN_LIBS@ SYSTEM_CA_PATH = @SYSTEM_CA_PATH@ @@ -372,6 +370,7 @@ mkdir_p = @mkdir_p@ nmbinary = @nmbinary@ nmconfdir = @nmconfdir@ nmdatadir = @nmdatadir@ +nmlibdir = @nmlibdir@ nmrundir = @nmrundir@ nmstatedir = @nmstatedir@ oldincludedir = @oldincludedir@ @@ -379,6 +378,7 @@ pdfdir = @pdfdir@ prefix = @prefix@ program_transform_name = @program_transform_name@ psdir = @psdir@ +runstatedir = @runstatedir@ sbindir = @sbindir@ sharedstatedir = @sharedstatedir@ srcdir = @srcdir@ diff --git a/src/settings/plugins/keyfile/tests/keyfiles/Test_Bridge_Main b/src/settings/plugins/keyfile/tests/keyfiles/Test_Bridge_Main index 3b9fcb28..fc9fd8f8 100644 --- a/src/settings/plugins/keyfile/tests/keyfiles/Test_Bridge_Main +++ b/src/settings/plugins/keyfile/tests/keyfiles/Test_Bridge_Main @@ -11,6 +11,7 @@ priority=32744 hello-time=7 max-age=39 ageing-time=235352 +multicast-snooping=false [ipv4] method=auto diff --git a/src/settings/plugins/keyfile/tests/test-keyfile.c b/src/settings/plugins/keyfile/tests/test-keyfile.c index 785ad4cb..250bad36 100644 --- a/src/settings/plugins/keyfile/tests/test-keyfile.c +++ b/src/settings/plugins/keyfile/tests/test-keyfile.c @@ -29,7 +29,7 @@ #include <sys/socket.h> #include "nm-core-internal.h" -#include "nm-logging.h" +#include "nm-default.h" #include "reader.h" #include "writer.h" @@ -1882,153 +1882,43 @@ test_read_gsm_connection (void) NMSettingConnection *s_con; NMSettingSerial *s_serial; NMSettingGsm *s_gsm; - NMSettingBluetooth *s_bluetooth; GError *error = NULL; - const char *tmp; - NMSettingSerialParity parity; - const char *expected_id = "AT&T Data Connect"; - const char *expected_apn = "ISP.CINGULAR"; - const char *expected_username = "ISP@CINGULARGPRS.COM"; - const char *expected_password = "CINGULAR1"; - const char *expected_network_id = "24005"; - const char *expected_pin = "2345"; + gboolean success; - connection = nm_keyfile_plugin_connection_from_file (TEST_GSM_FILE, NULL); - ASSERT (connection != NULL, - "connection-read", "failed to read %s", TEST_GSM_FILE); + connection = nm_keyfile_plugin_connection_from_file (TEST_GSM_FILE, &error); + g_assert_no_error (error); + g_assert (connection); - ASSERT (nm_connection_verify (connection, &error), - "connection-verify", "failed to verify %s: %s", TEST_GSM_FILE, error->message); + success = nm_connection_verify (connection, &error); + g_assert_no_error (error); + g_assert (success); /* ===== CONNECTION SETTING ===== */ - s_con = nm_connection_get_setting_connection (connection); - ASSERT (s_con != NULL, - "connection-verify-connection", "failed to verify %s: missing %s setting", - TEST_GSM_FILE, - NM_SETTING_CONNECTION_SETTING_NAME); - - /* ID */ - tmp = nm_setting_connection_get_id (s_con); - ASSERT (tmp != NULL, - "connection-verify-connection", "failed to verify %s: missing %s / %s key", - TEST_GSM_FILE, - NM_SETTING_CONNECTION_SETTING_NAME, - NM_SETTING_CONNECTION_ID); - ASSERT (strcmp (tmp, expected_id) == 0, - "connection-verify-connection", "failed to verify %s: unexpected %s / %s key value", - TEST_GSM_FILE, - NM_SETTING_CONNECTION_SETTING_NAME, - NM_SETTING_CONNECTION_ID); - - tmp = nm_setting_connection_get_connection_type (s_con); - ASSERT (tmp != NULL, - "connection-verify-connection", "failed to verify %s: missing %s / %s key", - TEST_GSM_FILE, - NM_SETTING_CONNECTION_SETTING_NAME, - NM_SETTING_CONNECTION_ID); - ASSERT (strcmp (tmp, NM_SETTING_GSM_SETTING_NAME) == 0, - "connection-verify-connection", "failed to verify %s: unexpected %s / %s key value", - TEST_GSM_FILE, - NM_SETTING_CONNECTION_SETTING_NAME, - NM_SETTING_CONNECTION_TYPE); + g_assert (s_con); + g_assert_cmpstr (nm_setting_connection_get_id (s_con), ==, "AT&T Data Connect"); + g_assert_cmpstr (nm_setting_connection_get_connection_type (s_con), ==, NM_SETTING_GSM_SETTING_NAME); /* ===== BLUETOOTH SETTING ===== */ - /* Plain GSM, so no BT setting expected */ - s_bluetooth = nm_connection_get_setting_bluetooth (connection); - ASSERT (s_bluetooth == NULL, - "connection-verify-bt", "unexpected %s setting", - TEST_GSM_FILE, - NM_SETTING_BLUETOOTH_SETTING_NAME); + g_assert (nm_connection_get_setting_bluetooth (connection) == NULL); /* ===== GSM SETTING ===== */ - s_gsm = nm_connection_get_setting_gsm (connection); - ASSERT (s_gsm != NULL, - "connection-verify-gsm", "failed to verify %s: missing %s setting", - TEST_GSM_FILE, - NM_SETTING_GSM_SETTING_NAME); - - /* APN */ - tmp = nm_setting_gsm_get_apn (s_gsm); - ASSERT (tmp != NULL, - "connection-verify-gsm", "failed to verify %s: missing %s / %s key", - TEST_GSM_FILE, - NM_SETTING_GSM_SETTING_NAME, - NM_SETTING_GSM_APN); - ASSERT (strcmp (tmp, expected_apn) == 0, - "connection-verify-gsm", "failed to verify %s: unexpected %s / %s key value", - TEST_GSM_FILE, - NM_SETTING_GSM_SETTING_NAME, - NM_SETTING_GSM_APN); - - /* Username */ - tmp = nm_setting_gsm_get_username (s_gsm); - ASSERT (tmp != NULL, - "connection-verify-gsm", "failed to verify %s: missing %s / %s key", - TEST_GSM_FILE, - NM_SETTING_GSM_SETTING_NAME, - NM_SETTING_GSM_USERNAME); - ASSERT (strcmp (tmp, expected_username) == 0, - "connection-verify-gsm", "failed to verify %s: unexpected %s / %s key value", - TEST_GSM_FILE, - NM_SETTING_GSM_SETTING_NAME, - NM_SETTING_GSM_USERNAME); - - /* Password */ - tmp = nm_setting_gsm_get_password (s_gsm); - ASSERT (tmp != NULL, - "connection-verify-gsm", "failed to verify %s: missing %s / %s key", - TEST_GSM_FILE, - NM_SETTING_GSM_SETTING_NAME, - NM_SETTING_GSM_PASSWORD); - ASSERT (strcmp (tmp, expected_password) == 0, - "connection-verify-gsm", "failed to verify %s: unexpected %s / %s key value", - TEST_GSM_FILE, - NM_SETTING_GSM_SETTING_NAME, - NM_SETTING_GSM_PASSWORD); - - /* Network ID */ - tmp = nm_setting_gsm_get_network_id (s_gsm); - ASSERT (tmp != NULL, - "connection-verify-gsm", "failed to verify %s: missing %s / %s key", - TEST_GSM_FILE, - NM_SETTING_GSM_SETTING_NAME, - NM_SETTING_GSM_NETWORK_ID); - ASSERT (strcmp (tmp, expected_network_id) == 0, - "connection-verify-gsm", "failed to verify %s: unexpected %s / %s key value", - TEST_GSM_FILE, - NM_SETTING_GSM_SETTING_NAME, - NM_SETTING_GSM_NETWORK_ID); - - /* PIN */ - tmp = nm_setting_gsm_get_pin (s_gsm); - ASSERT (tmp != NULL, - "connection-verify-gsm", "failed to verify %s: missing %s / %s key", - TEST_GSM_FILE, - NM_SETTING_GSM_SETTING_NAME, - NM_SETTING_GSM_PIN); - ASSERT (strcmp (tmp, expected_pin) == 0, - "connection-verify-gsm", "failed to verify %s: unexpected %s / %s key value", - TEST_GSM_FILE, - NM_SETTING_GSM_SETTING_NAME, - NM_SETTING_GSM_PIN); + g_assert (s_gsm); + g_assert_cmpstr (nm_setting_gsm_get_apn (s_gsm), ==, "ISP.CINGULAR"); + g_assert_cmpstr (nm_setting_gsm_get_username (s_gsm), ==, "ISP@CINGULARGPRS.COM"); + g_assert_cmpstr (nm_setting_gsm_get_password (s_gsm), ==, "CINGULAR1"); + g_assert_cmpstr (nm_setting_gsm_get_network_id (s_gsm), ==, "24005"); + g_assert_cmpstr (nm_setting_gsm_get_pin (s_gsm), ==, "2345"); + g_assert_cmpstr (nm_setting_gsm_get_device_id (s_gsm), ==, "da812de91eec16620b06cd0ca5cbc7ea25245222"); + g_assert_cmpstr (nm_setting_gsm_get_sim_id (s_gsm), ==, "89148000000060671234"); + g_assert_cmpstr (nm_setting_gsm_get_sim_operator_id (s_gsm), ==, "310260"); /* ===== SERIAL SETTING ===== */ - s_serial = nm_connection_get_setting_serial (connection); - ASSERT (s_serial != NULL, - "connection-verify-serial", "failed to verify %s: missing %s setting", - TEST_GSM_FILE, - NM_SETTING_SERIAL_SETTING_NAME); - - parity = nm_setting_serial_get_parity (s_serial); - ASSERT (parity == NM_SETTING_SERIAL_PARITY_ODD, - "connection-verify-serial", "failed to verify %s: unexpected %s / %s key value", - TEST_GSM_FILE, - NM_SETTING_SERIAL_SETTING_NAME, - NM_SETTING_SERIAL_PARITY); + g_assert (s_serial); + g_assert_cmpint (nm_setting_serial_get_parity (s_serial), ==, NM_SETTING_SERIAL_PARITY_ODD); g_object_unref (connection); } @@ -2087,22 +1977,23 @@ test_write_gsm_connection (void) NM_SETTING_GSM_PIN, "123456", NM_SETTING_GSM_NETWORK_ID, "254098", NM_SETTING_GSM_HOME_ONLY, TRUE, + NM_SETTING_GSM_DEVICE_ID, "da812de91eec16620b06cd0ca5cbc7ea25245222", + NM_SETTING_GSM_SIM_ID, "89148000000060671234", + NM_SETTING_GSM_SIM_OPERATOR_ID, "310260", NULL); /* Write out the connection */ owner_uid = geteuid (); owner_grp = getegid (); success = nm_keyfile_plugin_write_test_connection (connection, TEST_SCRATCH_DIR, owner_uid, owner_grp, &testfile, &error); - ASSERT (success == TRUE, - "connection-write", "failed to write keyfile: %s", - error ? error->message : "(none)"); - - ASSERT (testfile != NULL, - "connection-write", "didn't get keyfile name back after writing connection"); + g_assert_no_error (error); + g_assert (success); + g_assert (testfile != NULL); /* Read the connection back in and compare it to the one we just wrote out */ - reread = nm_keyfile_plugin_connection_from_file (testfile, NULL); - ASSERT (reread != NULL, "connection-write", "failed to re-read test connection"); + reread = nm_keyfile_plugin_connection_from_file (testfile, &error); + g_assert_no_error (error); + g_assert (reread); nmtst_assert_connection_equals (connection, TRUE, reread, FALSE); @@ -2821,6 +2712,7 @@ test_read_bridge_main (void) g_assert_cmpuint (nm_setting_bridge_get_hello_time (s_bridge), ==, 7); g_assert_cmpuint (nm_setting_bridge_get_max_age (s_bridge), ==, 39); g_assert_cmpuint (nm_setting_bridge_get_ageing_time (s_bridge), ==, 235352); + g_assert_cmpuint (nm_setting_bridge_get_multicast_snooping (s_bridge), ==, FALSE); g_object_unref (connection); } diff --git a/src/settings/plugins/keyfile/utils.c b/src/settings/plugins/keyfile/utils.c index 4809c642..48795ffb 100644 --- a/src/settings/plugins/keyfile/utils.c +++ b/src/settings/plugins/keyfile/utils.c @@ -20,15 +20,16 @@ #include "config.h" -#include <glib.h> #include <stdlib.h> #include <string.h> -#include "gsystem-local-alloc.h" +#include "nm-default.h" #include "utils.h" #include <nm-setting-wired.h> #include <nm-setting-wireless.h> #include <nm-setting-wireless-security.h> +#include "nm-config.h" +#define NM_CONFIG_KEYFILE_PATH_DEFAULT NMCONFDIR "/system-connections" static const char temp_letters[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; @@ -146,3 +147,23 @@ nm_keyfile_plugin_utils_escape_filename (const char *filename) return g_string_free (str, FALSE);; } +/*****************************************************************************/ + +const char * +nm_keyfile_plugin_get_path (void) +{ + static char *path = NULL; + + if (G_UNLIKELY (!path)) { + path = nm_config_data_get_value (NM_CONFIG_GET_DATA_ORIG, + NM_CONFIG_KEYFILE_GROUP_KEYFILE, + NM_CONFIG_KEYFILE_KEY_KEYFILE_PATH, + NM_CONFIG_GET_VALUE_STRIP | NM_CONFIG_GET_VALUE_NO_EMPTY); + if (!path) + path = g_strdup (""NM_CONFIG_KEYFILE_PATH_DEFAULT""); + } + return path; +} + +/*****************************************************************************/ + diff --git a/src/settings/plugins/keyfile/utils.h b/src/settings/plugins/keyfile/utils.h index d0862284..0b2b6f4e 100644 --- a/src/settings/plugins/keyfile/utils.h +++ b/src/settings/plugins/keyfile/utils.h @@ -21,9 +21,12 @@ #ifndef _UTILS_H_ #define _UTILS_H_ -#include <glib.h> +#include "nm-default.h" #include "NetworkManagerUtils.h" +#define KEYFILE_PLUGIN_NAME "keyfile" +#define KEYFILE_PLUGIN_INFO "(c) 2007 - 2015 Red Hat, Inc. To report bugs please use the NetworkManager mailing list." + #define NM_KEYFILE_CONNECTION_LOG_PATH(path) str_if_set (path,"in-memory") #define NM_KEYFILE_CONNECTION_LOG_FMT "%s (%s,\"%s\")" #define NM_KEYFILE_CONNECTION_LOG_ARG(con) NM_KEYFILE_CONNECTION_LOG_PATH (nm_settings_connection_get_filename ((NMSettingsConnection *) (con))), nm_connection_get_uuid ((NMConnection *) (con)), nm_connection_get_id ((NMConnection *) (con)) @@ -34,5 +37,7 @@ gboolean nm_keyfile_plugin_utils_should_ignore_file (const char *filename); char *nm_keyfile_plugin_utils_escape_filename (const char *filename); +const char *nm_keyfile_plugin_get_path (void); + #endif /* _UTILS_H_ */ diff --git a/src/settings/plugins/keyfile/writer.c b/src/settings/plugins/keyfile/writer.c index b6a8786d..db00b061 100644 --- a/src/settings/plugins/keyfile/writer.c +++ b/src/settings/plugins/keyfile/writer.c @@ -27,15 +27,11 @@ #include <errno.h> #include <string.h> -#include "nm-glib-compat.h" - -#include "nm-logging.h" +#include "nm-default.h" #include "writer.h" -#include "common.h" #include "utils.h" #include "nm-keyfile-internal.h" - typedef struct { const char *keyfile_dir; } WriteInfo; @@ -233,17 +229,18 @@ _internal_write_connection (NMConnection *connection, uid_t owner_uid, pid_t owner_grp, const char *existing_path, + gboolean force_rename, char **out_path, GError **error) { GKeyFile *key_file; - char *data; + gs_free char *data = NULL; gsize len; - gboolean success = FALSE; - char *path; + gs_free char *path = NULL; const char *id; WriteInfo info = { 0 }; GError *local_err = NULL; + int errsv; g_return_val_if_fail (!out_path || !*out_path, FALSE); g_return_val_if_fail (keyfile_dir && keyfile_dir[0] == '/', FALSE); @@ -267,7 +264,7 @@ _internal_write_connection (NMConnection *connection, /* If we have existing file path, use it. Else generate one from * connection's ID. */ - if (existing_path != NULL) { + if (existing_path != NULL && !force_rename) { path = g_strdup (existing_path); } else { char *filename_escaped = nm_keyfile_plugin_utils_escape_filename (id); @@ -312,8 +309,7 @@ _internal_write_connection (NMConnection *connection, /* this really should not happen, we tried hard to find an unused name... bail out. */ g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_FAILED, "could not find suitable keyfile file name (%s already used)", path); - g_free (path); - goto out; + return FALSE; } /* Both our preferred path based on connection id and id-uuid are taken. * Fallback to @existing_path */ @@ -331,49 +327,49 @@ _internal_write_connection (NMConnection *connection, g_file_set_contents (path, data, len, &local_err); if (local_err) { g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_FAILED, - "%s.%d: error writing to file '%s': %s", __FILE__, __LINE__, + "error writing to file '%s': %s", path, local_err->message); g_error_free (local_err); - g_free (path); - goto out; + return FALSE; } if (chown (path, owner_uid, owner_grp) < 0) { + errsv = errno; g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_FAILED, - "%s.%d: error chowning '%s': %d", __FILE__, __LINE__, - path, errno); + "error chowning '%s': %s (%d)", + path, g_strerror (errsv), errsv); unlink (path); - } else { - if (chmod (path, S_IRUSR | S_IWUSR) < 0) { - g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_FAILED, - "%s.%d: error setting permissions on '%s': %d", __FILE__, - __LINE__, path, errno); - unlink (path); - } else { - if (out_path && g_strcmp0 (existing_path, path)) { - *out_path = path; /* pass path out to caller */ - path = NULL; - } - success = TRUE; - } + return FALSE; } - g_free (path); -out: - g_free (data); - return success; + if (chmod (path, S_IRUSR | S_IWUSR) < 0) { + errsv = errno; + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_FAILED, + "error setting permissions on '%s': %s (%d)", + path, g_strerror (errsv), errsv); + unlink (path); + return FALSE; + } + + if (out_path && g_strcmp0 (existing_path, path)) { + *out_path = path; /* pass path out to caller */ + path = NULL; + } + return TRUE; } gboolean nm_keyfile_plugin_write_connection (NMConnection *connection, const char *existing_path, + gboolean force_rename, char **out_path, GError **error) { return _internal_write_connection (connection, - KEYFILE_DIR, + nm_keyfile_plugin_get_path (), 0, 0, existing_path, + force_rename, out_path, error); } @@ -390,6 +386,7 @@ nm_keyfile_plugin_write_test_connection (NMConnection *connection, keyfile_dir, owner_uid, owner_grp, NULL, + FALSE, out_path, error); } diff --git a/src/settings/plugins/keyfile/writer.h b/src/settings/plugins/keyfile/writer.h index 8b08812d..25f44e94 100644 --- a/src/settings/plugins/keyfile/writer.h +++ b/src/settings/plugins/keyfile/writer.h @@ -22,11 +22,13 @@ #ifndef _KEYFILE_PLUGIN_WRITER_H #define _KEYFILE_PLUGIN_WRITER_H -#include <glib.h> #include <nm-connection.h> +#include "nm-default.h" + gboolean nm_keyfile_plugin_write_connection (NMConnection *connection, const char *existing_path, + gboolean force_rename, char **out_path, GError **error); |