keyfile: merge branch 'th/keyfile-rename-bgo772463'

https://bugzilla.gnome.org/show_bug.cgi?id=772463
This commit is contained in:
Thomas Haller
2016-10-06 20:41:38 +02:00
32 changed files with 433 additions and 455 deletions

View File

@@ -384,16 +384,16 @@ libNetworkManager_la_SOURCES = \
settings/nm-settings.c \ settings/nm-settings.c \
settings/nm-settings.h \ settings/nm-settings.h \
\ \
settings/plugins/keyfile/nm-keyfile-connection.c \ settings/plugins/keyfile/nms-keyfile-connection.c \
settings/plugins/keyfile/nm-keyfile-connection.h \ settings/plugins/keyfile/nms-keyfile-connection.h \
settings/plugins/keyfile/plugin.c \ settings/plugins/keyfile/nms-keyfile-plugin.c \
settings/plugins/keyfile/plugin.h \ settings/plugins/keyfile/nms-keyfile-plugin.h \
settings/plugins/keyfile/reader.c \ settings/plugins/keyfile/nms-keyfile-reader.c \
settings/plugins/keyfile/reader.h \ settings/plugins/keyfile/nms-keyfile-reader.h \
settings/plugins/keyfile/utils.c \ settings/plugins/keyfile/nms-keyfile-utils.c \
settings/plugins/keyfile/utils.h \ settings/plugins/keyfile/nms-keyfile-utils.h \
settings/plugins/keyfile/writer.c \ settings/plugins/keyfile/nms-keyfile-writer.c \
settings/plugins/keyfile/writer.h \ settings/plugins/keyfile/nms-keyfile-writer.h \
\ \
supplicant-manager/nm-supplicant-config.c \ supplicant-manager/nm-supplicant-config.c \
supplicant-manager/nm-supplicant-config.h \ supplicant-manager/nm-supplicant-config.h \

View File

@@ -14,7 +14,7 @@ AM_CPPFLAGS = \
-I$(top_builddir)/shared \ -I$(top_builddir)/shared \
-I${top_builddir}/libnm-core \ -I${top_builddir}/libnm-core \
-I${top_srcdir}/libnm-core \ -I${top_srcdir}/libnm-core \
-DG_LOG_DOMAIN=\""NetworkManager-adsl"\" \ -DG_LOG_DOMAIN=\""NetworkManager"\" \
-DNETWORKMANAGER_COMPILATION=NM_NETWORKMANAGER_COMPILATION_INSIDE_DAEMON \ -DNETWORKMANAGER_COMPILATION=NM_NETWORKMANAGER_COMPILATION_INSIDE_DAEMON \
$(GUDEV_CFLAGS) $(GUDEV_CFLAGS)

View File

@@ -16,7 +16,7 @@ AM_CPPFLAGS = \
-I$(top_builddir)/shared \ -I$(top_builddir)/shared \
-I${top_builddir}/libnm-core \ -I${top_builddir}/libnm-core \
-I${top_srcdir}/libnm-core \ -I${top_srcdir}/libnm-core \
-DG_LOG_DOMAIN=\""NetworkManager-bluetooth"\" \ -DG_LOG_DOMAIN=\""NetworkManager"\" \
-DNETWORKMANAGER_COMPILATION=NM_NETWORKMANAGER_COMPILATION_INSIDE_DAEMON \ -DNETWORKMANAGER_COMPILATION=NM_NETWORKMANAGER_COMPILATION_INSIDE_DAEMON \
$(GLIB_CFLAGS) $(GLIB_CFLAGS)

View File

@@ -15,7 +15,7 @@ AM_CPPFLAGS = \
-I$(top_builddir)/shared \ -I$(top_builddir)/shared \
-I${top_builddir}/libnm-core \ -I${top_builddir}/libnm-core \
-I${top_srcdir}/libnm-core \ -I${top_srcdir}/libnm-core \
-DG_LOG_DOMAIN=\""NetworkManager-team"\" \ -DG_LOG_DOMAIN=\""NetworkManager"\" \
-DNETWORKMANAGER_COMPILATION=NM_NETWORKMANAGER_COMPILATION_INSIDE_DAEMON \ -DNETWORKMANAGER_COMPILATION=NM_NETWORKMANAGER_COMPILATION_INSIDE_DAEMON \
$(GLIB_CFLAGS) $(GLIB_CFLAGS)

View File

@@ -18,7 +18,7 @@ AM_CPPFLAGS = \
-I$(top_builddir)/shared \ -I$(top_builddir)/shared \
-I${top_builddir}/libnm-core \ -I${top_builddir}/libnm-core \
-I${top_srcdir}/libnm-core \ -I${top_srcdir}/libnm-core \
-DG_LOG_DOMAIN=\""NetworkManager-wifi"\" \ -DG_LOG_DOMAIN=\""NetworkManager"\" \
-DNETWORKMANAGER_COMPILATION=NM_NETWORKMANAGER_COMPILATION_INSIDE_DAEMON \ -DNETWORKMANAGER_COMPILATION=NM_NETWORKMANAGER_COMPILATION_INSIDE_DAEMON \
$(GLIB_CFLAGS) $(GLIB_CFLAGS)

View File

@@ -8,7 +8,7 @@ AM_CPPFLAGS = \
-I$(top_srcdir)/src \ -I$(top_srcdir)/src \
-I$(top_srcdir)/src/devices/wifi \ -I$(top_srcdir)/src/devices/wifi \
-I$(top_builddir)/src \ -I$(top_builddir)/src \
-DG_LOG_DOMAIN=\""NetworkManager-wifi"\" \ -DG_LOG_DOMAIN=\""NetworkManager"\" \
-DNETWORKMANAGER_COMPILATION=NM_NETWORKMANAGER_COMPILATION_INSIDE_DAEMON \ -DNETWORKMANAGER_COMPILATION=NM_NETWORKMANAGER_COMPILATION_INSIDE_DAEMON \
$(GLIB_CFLAGS) $(GLIB_CFLAGS)

View File

@@ -15,7 +15,7 @@ AM_CPPFLAGS = \
-I$(top_builddir)/shared \ -I$(top_builddir)/shared \
-I${top_srcdir}/libnm-core \ -I${top_srcdir}/libnm-core \
-I${top_builddir}/libnm-core \ -I${top_builddir}/libnm-core \
-DG_LOG_DOMAIN=\""NetworkManager-wwan"\" \ -DG_LOG_DOMAIN=\""NetworkManager"\" \
-DNETWORKMANAGER_COMPILATION=NM_NETWORKMANAGER_COMPILATION_INSIDE_DAEMON \ -DNETWORKMANAGER_COMPILATION=NM_NETWORKMANAGER_COMPILATION_INSIDE_DAEMON \
$(GLIB_CFLAGS) \ $(GLIB_CFLAGS) \
$(LIBSYSTEMD_CFLAGS) \ $(LIBSYSTEMD_CFLAGS) \

View File

@@ -69,7 +69,7 @@
#include "nm-auth-utils.h" #include "nm-auth-utils.h"
#include "nm-auth-subject.h" #include "nm-auth-subject.h"
#include "nm-session-monitor.h" #include "nm-session-monitor.h"
#include "plugins/keyfile/plugin.h" #include "plugins/keyfile/nms-keyfile-plugin.h"
#include "nm-agent-manager.h" #include "nm-agent-manager.h"
#include "nm-config.h" #include "nm-config.h"
#include "nm-audit-manager.h" #include "nm-audit-manager.h"
@@ -798,10 +798,9 @@ find_plugin (GSList *list, const char *pname)
static void static void
add_keyfile_plugin (NMSettings *self) add_keyfile_plugin (NMSettings *self)
{ {
gs_unref_object GObject *keyfile_plugin = NULL; gs_unref_object NMSKeyfilePlugin *keyfile_plugin = NULL;
keyfile_plugin = nm_settings_keyfile_plugin_new (); keyfile_plugin = nms_keyfile_plugin_new ();
g_assert (keyfile_plugin);
if (!add_plugin (self, NM_SETTINGS_PLUGIN (keyfile_plugin))) if (!add_plugin (self, NM_SETTINGS_PLUGIN (keyfile_plugin)))
g_return_if_reached (); g_return_if_reached ();
} }

View File

@@ -20,7 +20,7 @@ AM_CPPFLAGS = \
-I$(top_builddir)/libnm-core \ -I$(top_builddir)/libnm-core \
-DNETWORKMANAGER_COMPILATION=NM_NETWORKMANAGER_COMPILATION_INSIDE_DAEMON \ -DNETWORKMANAGER_COMPILATION=NM_NETWORKMANAGER_COMPILATION_INSIDE_DAEMON \
$(GLIB_CFLAGS) \ $(GLIB_CFLAGS) \
-DG_LOG_DOMAIN=\""NetworkManager-ibft"\" \ -DG_LOG_DOMAIN=\""NetworkManager"\" \
-DSYSCONFDIR=\"$(sysconfdir)\" \ -DSYSCONFDIR=\"$(sysconfdir)\" \
-DSBINDIR=\"$(sbindir)\" -DSBINDIR=\"$(sbindir)\"

View File

@@ -15,7 +15,7 @@ AM_CPPFLAGS = \
-I$(top_srcdir)/src/platform \ -I$(top_srcdir)/src/platform \
-I$(top_srcdir)/src/settings \ -I$(top_srcdir)/src/settings \
-I$(srcdir)/../ \ -I$(srcdir)/../ \
-DG_LOG_DOMAIN=\""NetworkManager-ibft"\" \ -DG_LOG_DOMAIN=\""NetworkManager"\" \
-DNETWORKMANAGER_COMPILATION=NM_NETWORKMANAGER_COMPILATION_INSIDE_DAEMON \ -DNETWORKMANAGER_COMPILATION=NM_NETWORKMANAGER_COMPILATION_INSIDE_DAEMON \
-DTEST_IBFT_DIR=\"$(abs_srcdir)\" \ -DTEST_IBFT_DIR=\"$(abs_srcdir)\" \
-DTEST_SCRATCH_DIR=\"$(abs_builddir)/\" -DTEST_SCRATCH_DIR=\"$(abs_builddir)/\"

View File

@@ -50,7 +50,7 @@ AM_CPPFLAGS = \
-DNETWORKMANAGER_COMPILATION=NM_NETWORKMANAGER_COMPILATION_INSIDE_DAEMON \ -DNETWORKMANAGER_COMPILATION=NM_NETWORKMANAGER_COMPILATION_INSIDE_DAEMON \
$(GLIB_CFLAGS) \ $(GLIB_CFLAGS) \
$(NSS_CFLAGS) \ $(NSS_CFLAGS) \
-DG_LOG_DOMAIN=\""NetworkManager-ifcfg-rh"\" \ -DG_LOG_DOMAIN=\""NetworkManager"\" \
-DSYSCONFDIR=\"$(sysconfdir)\" \ -DSYSCONFDIR=\"$(sysconfdir)\" \
-DSBINDIR=\"$(sbindir)\" -DSBINDIR=\"$(sbindir)\"

View File

@@ -17,7 +17,7 @@ AM_CPPFLAGS = \
-I$(top_srcdir)/src/platform \ -I$(top_srcdir)/src/platform \
-I$(top_srcdir)/src/settings \ -I$(top_srcdir)/src/settings \
-I$(srcdir)/../ \ -I$(srcdir)/../ \
-DG_LOG_DOMAIN=\""NetworkManager-ifcfg-rh"\" \ -DG_LOG_DOMAIN=\""NetworkManager"\" \
-DNETWORKMANAGER_COMPILATION=NM_NETWORKMANAGER_COMPILATION_INSIDE_DAEMON \ -DNETWORKMANAGER_COMPILATION=NM_NETWORKMANAGER_COMPILATION_INSIDE_DAEMON \
-DTEST_IFCFG_DIR=\"$(abs_srcdir)\" \ -DTEST_IFCFG_DIR=\"$(abs_srcdir)\" \
-DTEST_SCRATCH_DIR=\"$(abs_builddir)/\" \ -DTEST_SCRATCH_DIR=\"$(abs_builddir)/\" \

View File

@@ -10,7 +10,7 @@ AM_CPPFLAGS = \
-I$(top_builddir)/shared \ -I$(top_builddir)/shared \
-I$(top_srcdir)/libnm-core \ -I$(top_srcdir)/libnm-core \
-I$(top_builddir)/libnm-core \ -I$(top_builddir)/libnm-core \
-DG_LOG_DOMAIN=\""NetworkManager-ifnet"\" \ -DG_LOG_DOMAIN=\""NetworkManager"\" \
-DNETWORKMANAGER_COMPILATION=NM_NETWORKMANAGER_COMPILATION_INSIDE_DAEMON \ -DNETWORKMANAGER_COMPILATION=NM_NETWORKMANAGER_COMPILATION_INSIDE_DAEMON \
$(GLIB_CFLAGS) \ $(GLIB_CFLAGS) \
-DSYSCONFDIR=\"$(sysconfdir)\" -DSYSCONFDIR=\"$(sysconfdir)\"

View File

@@ -13,7 +13,7 @@ AM_CPPFLAGS= \
-I$(top_srcdir)/src \ -I$(top_srcdir)/src \
-I$(top_srcdir)/src/settings \ -I$(top_srcdir)/src/settings \
-I$(top_srcdir)/src/platform \ -I$(top_srcdir)/src/platform \
-DG_LOG_DOMAIN=\""NetworkManager-ifnet"\" \ -DG_LOG_DOMAIN=\""NetworkManager"\" \
-DNETWORKMANAGER_COMPILATION=NM_NETWORKMANAGER_COMPILATION_INSIDE_DAEMON \ -DNETWORKMANAGER_COMPILATION=NM_NETWORKMANAGER_COMPILATION_INSIDE_DAEMON \
$(CHECK_CFLAGS) \ $(CHECK_CFLAGS) \
$(GLIB_CFLAGS) \ $(GLIB_CFLAGS) \

View File

@@ -9,7 +9,7 @@ AM_CPPFLAGS = \
-I$(top_builddir)/shared \ -I$(top_builddir)/shared \
-I$(top_srcdir)/libnm-core \ -I$(top_srcdir)/libnm-core \
-I$(top_builddir)/libnm-core \ -I$(top_builddir)/libnm-core \
-DG_LOG_DOMAIN=\""NetworkManager-ifupdown"\" \ -DG_LOG_DOMAIN=\""NetworkManager"\" \
-DNETWORKMANAGER_COMPILATION=NM_NETWORKMANAGER_COMPILATION_INSIDE_DAEMON \ -DNETWORKMANAGER_COMPILATION=NM_NETWORKMANAGER_COMPILATION_INSIDE_DAEMON \
$(GLIB_CFLAGS) \ $(GLIB_CFLAGS) \
$(GUDEV_CFLAGS) \ $(GUDEV_CFLAGS) \

View File

@@ -10,7 +10,7 @@ AM_CPPFLAGS = \
-I$(top_srcdir)/src \ -I$(top_srcdir)/src \
-I$(top_srcdir)/src/settings \ -I$(top_srcdir)/src/settings \
-I$(srcdir)/../ \ -I$(srcdir)/../ \
-DG_LOG_DOMAIN=\""NetworkManager-ifupdown"\" \ -DG_LOG_DOMAIN=\""NetworkManager"\" \
-DNETWORKMANAGER_COMPILATION=NM_NETWORKMANAGER_COMPILATION_INSIDE_DAEMON \ -DNETWORKMANAGER_COMPILATION=NM_NETWORKMANAGER_COMPILATION_INSIDE_DAEMON \
$(GLIB_CFLAGS) \ $(GLIB_CFLAGS) \
-DTEST_ENI_DIR=\"$(abs_srcdir)\" -DTEST_ENI_DIR=\"$(abs_srcdir)\"

View File

@@ -1,48 +1 @@
SUBDIRS = . tests SUBDIRS = tests
@GNOME_CODE_COVERAGE_RULES@
AM_CPPFLAGS = \
-I$(top_srcdir)/src \
-I$(top_srcdir)/src/settings \
-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=NM_NETWORKMANAGER_COMPILATION_INSIDE_DAEMON \
$(GLIB_CFLAGS) \
-DNMCONFDIR=\"$(nmconfdir)\"
noinst_LTLIBRARIES = \
libkeyfile-io.la \
libnm-settings-plugin-keyfile.la
##### I/O library for testcases #####
libkeyfile_io_la_SOURCES = \
reader.c \
reader.h \
writer.c \
writer.h \
utils.c \
utils.h
libkeyfile_io_la_LIBADD = $(GLIB_LIBS)
#####################################
libnm_settings_plugin_keyfile_la_SOURCES = \
nm-keyfile-connection.c \
nm-keyfile-connection.h \
plugin.c \
plugin.h
libnm_settings_plugin_keyfile_la_LIBADD = \
libkeyfile-io.la
keyfiledir=$(sysconfdir)/NetworkManager/system-connections
install-data-hook:
$(mkinstalldirs) -m 0755 $(DESTDIR)$(keyfiledir)

View File

@@ -1,48 +0,0 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/* NetworkManager system settings service - keyfile plugin
*
* 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.
*
* Copyright (C) 2008 Novell, Inc.
* Copyright (C) 2008 - 2012 Red Hat, Inc.
*/
#ifndef __NETWORKMANAGER_KEYFILE_CONNECTION_H__
#define __NETWORKMANAGER_KEYFILE_CONNECTION_H__
#include <nm-settings-connection.h>
#define NM_TYPE_KEYFILE_CONNECTION (nm_keyfile_connection_get_type ())
#define NM_KEYFILE_CONNECTION(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_KEYFILE_CONNECTION, NMKeyfileConnection))
#define NM_KEYFILE_CONNECTION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_KEYFILE_CONNECTION, NMKeyfileConnectionClass))
#define NM_IS_KEYFILE_CONNECTION(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_KEYFILE_CONNECTION))
#define NM_IS_KEYFILE_CONNECTION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_KEYFILE_CONNECTION))
#define NM_KEYFILE_CONNECTION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_KEYFILE_CONNECTION, NMKeyfileConnectionClass))
typedef struct {
NMSettingsConnection parent;
} NMKeyfileConnection;
typedef struct {
NMSettingsConnectionClass parent;
} NMKeyfileConnectionClass;
GType nm_keyfile_connection_get_type (void);
NMKeyfileConnection *nm_keyfile_connection_new (NMConnection *source,
const char *filename,
GError **error);
#endif /* __NETWORKMANAGER_KEYFILE_CONNECTION_H__ */

View File

@@ -21,6 +21,8 @@
#include "nm-default.h" #include "nm-default.h"
#include "nms-keyfile-connection.h"
#include <string.h> #include <string.h>
#include <glib/gstdio.h> #include <glib/gstdio.h>
@@ -29,17 +31,99 @@
#include "nm-utils.h" #include "nm-utils.h"
#include "nm-settings-plugin.h" #include "nm-settings-plugin.h"
#include "nm-keyfile-connection.h"
#include "reader.h"
#include "writer.h"
#include "utils.h"
G_DEFINE_TYPE (NMKeyfileConnection, nm_keyfile_connection, NM_TYPE_SETTINGS_CONNECTION) #include "nms-keyfile-reader.h"
#include "nms-keyfile-writer.h"
#include "nms-keyfile-utils.h"
NMKeyfileConnection * /*****************************************************************************/
nm_keyfile_connection_new (NMConnection *source,
const char *full_path, struct _NMSKeyfileConnection {
GError **error) NMSettingsConnection parent;
};
struct _NMSKeyfileConnectionClass {
NMSettingsConnectionClass parent;
};
G_DEFINE_TYPE (NMSKeyfileConnection, nms_keyfile_connection, NM_TYPE_SETTINGS_CONNECTION)
/*****************************************************************************/
static void
commit_changes (NMSettingsConnection *connection,
NMSettingsConnectionCommitReason commit_reason,
NMSettingsConnectionCommitFunc callback,
gpointer user_data)
{
char *path = NULL;
GError *error = NULL;
if (!nms_keyfile_writer_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);
g_clear_error (&error);
return;
}
/* Update the filename if it changed */
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 "NMS_KEYFILE_CONNECTION_LOG_FMT" and rename from \"%s\"",
NMS_KEYFILE_CONNECTION_LOG_ARG (connection),
old_path);
} else {
nm_log_info (LOGD_SETTINGS, "keyfile: update "NMS_KEYFILE_CONNECTION_LOG_FMT" and persist connection",
NMS_KEYFILE_CONNECTION_LOG_ARG (connection));
}
} else {
nm_log_info (LOGD_SETTINGS, "keyfile: update "NMS_KEYFILE_CONNECTION_LOG_FMT,
NMS_KEYFILE_CONNECTION_LOG_ARG (connection));
}
g_free (path);
NM_SETTINGS_CONNECTION_CLASS (nms_keyfile_connection_parent_class)->commit_changes (connection,
commit_reason,
callback,
user_data);
}
static void
do_delete (NMSettingsConnection *connection,
NMSettingsConnectionDeleteFunc callback,
gpointer user_data)
{
const char *path;
path = nm_settings_connection_get_filename (connection);
if (path)
g_unlink (path);
NM_SETTINGS_CONNECTION_CLASS (nms_keyfile_connection_parent_class)->delete (connection,
callback,
user_data);
}
/*****************************************************************************/
static void
nms_keyfile_connection_init (NMSKeyfileConnection *connection)
{
}
NMSKeyfileConnection *
nms_keyfile_connection_new (NMConnection *source,
const char *full_path,
GError **error)
{ {
GObject *object; GObject *object;
NMConnection *tmp; NMConnection *tmp;
@@ -52,7 +136,7 @@ nm_keyfile_connection_new (NMConnection *source,
if (source) if (source)
tmp = g_object_ref (source); tmp = g_object_ref (source);
else { else {
tmp = nm_keyfile_plugin_connection_from_file (full_path, error); tmp = nms_keyfile_reader_from_file (full_path, error);
if (!tmp) if (!tmp)
return NULL; return NULL;
@@ -68,7 +152,7 @@ nm_keyfile_connection_new (NMConnection *source,
update_unsaved = FALSE; update_unsaved = FALSE;
} }
object = (GObject *) g_object_new (NM_TYPE_KEYFILE_CONNECTION, object = (GObject *) g_object_new (NMS_TYPE_KEYFILE_CONNECTION,
NM_SETTINGS_CONNECTION_FILENAME, full_path, NM_SETTINGS_CONNECTION_FILENAME, full_path,
NULL); NULL);
@@ -83,85 +167,14 @@ nm_keyfile_connection_new (NMConnection *source,
} }
g_object_unref (tmp); g_object_unref (tmp);
return (NMKeyfileConnection *) object; return (NMSKeyfileConnection *) object;
} }
static void static void
commit_changes (NMSettingsConnection *connection, nms_keyfile_connection_class_init (NMSKeyfileConnectionClass *keyfile_connection_class)
NMSettingsConnectionCommitReason commit_reason,
NMSettingsConnectionCommitFunc callback,
gpointer user_data)
{
char *path = NULL;
GError *error = NULL;
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);
g_clear_error (&error);
return;
}
/* Update the filename if it changed */
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);
}
static void
do_delete (NMSettingsConnection *connection,
NMSettingsConnectionDeleteFunc callback,
gpointer user_data)
{
const char *path;
path = nm_settings_connection_get_filename (connection);
if (path)
g_unlink (path);
NM_SETTINGS_CONNECTION_CLASS (nm_keyfile_connection_parent_class)->delete (connection,
callback,
user_data);
}
/* GObject */
static void
nm_keyfile_connection_init (NMKeyfileConnection *connection)
{
}
static void
nm_keyfile_connection_class_init (NMKeyfileConnectionClass *keyfile_connection_class)
{ {
NMSettingsConnectionClass *settings_class = NM_SETTINGS_CONNECTION_CLASS (keyfile_connection_class); NMSettingsConnectionClass *settings_class = NM_SETTINGS_CONNECTION_CLASS (keyfile_connection_class);
/* Virtual methods */
settings_class->commit_changes = commit_changes; settings_class->commit_changes = commit_changes;
settings_class->delete = do_delete; settings_class->delete = do_delete;
} }

View File

@@ -0,0 +1,43 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/* NetworkManager system settings service - keyfile plugin
*
* 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.
*
* Copyright (C) 2008 Novell, Inc.
* Copyright (C) 2008 - 2012 Red Hat, Inc.
*/
#ifndef __NMS_KEYFILE_CONNECTION_H__
#define __NMS_KEYFILE_CONNECTION_H__
#include <nm-settings-connection.h>
#define NMS_TYPE_KEYFILE_CONNECTION (nms_keyfile_connection_get_type ())
#define NMS_KEYFILE_CONNECTION(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NMS_TYPE_KEYFILE_CONNECTION, NMSKeyfileConnection))
#define NMS_KEYFILE_CONNECTION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NMS_TYPE_KEYFILE_CONNECTION, NMSKeyfileConnectionClass))
#define NMS_IS_KEYFILE_CONNECTION(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NMS_TYPE_KEYFILE_CONNECTION))
#define NMS_IS_KEYFILE_CONNECTION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NMS_TYPE_KEYFILE_CONNECTION))
#define NMS_KEYFILE_CONNECTION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NMS_TYPE_KEYFILE_CONNECTION, NMSKeyfileConnectionClass))
typedef struct _NMSKeyfileConnection NMSKeyfileConnection;
typedef struct _NMSKeyfileConnectionClass NMSKeyfileConnectionClass;
GType nms_keyfile_connection_get_type (void);
NMSKeyfileConnection *nms_keyfile_connection_new (NMConnection *source,
const char *filename,
GError **error);
#endif /* __NMS_KEYFILE_CONNECTION_H__ */

View File

@@ -21,7 +21,7 @@
#include "nm-default.h" #include "nm-default.h"
#include "plugin.h" #include "nms-keyfile-plugin.h"
#include <sys/stat.h> #include <sys/stat.h>
#include <unistd.h> #include <unistd.h>
@@ -38,9 +38,10 @@
#include "nm-core-internal.h" #include "nm-core-internal.h"
#include "nm-settings-plugin.h" #include "nm-settings-plugin.h"
#include "nm-keyfile-connection.h"
#include "writer.h" #include "nms-keyfile-connection.h"
#include "utils.h" #include "nms-keyfile-writer.h"
#include "nms-keyfile-utils.h"
/*****************************************************************************/ /*****************************************************************************/
@@ -52,49 +53,59 @@ typedef struct {
gulong monitor_id; gulong monitor_id;
NMConfig *config; NMConfig *config;
} SettingsPluginKeyfilePrivate; } NMSKeyfilePluginPrivate;
struct _SettingsPluginKeyfile { struct _NMSKeyfilePlugin {
GObject parent; GObject parent;
SettingsPluginKeyfilePrivate _priv; NMSKeyfilePluginPrivate _priv;
}; };
struct _SettingsPluginKeyfileClass { struct _NMSKeyfilePluginClass {
GObjectClass parent; GObjectClass parent;
}; };
static void settings_plugin_interface_init (NMSettingsPluginInterface *plugin_iface); static void settings_plugin_interface_init (NMSettingsPluginInterface *plugin_iface);
G_DEFINE_TYPE_EXTENDED (SettingsPluginKeyfile, settings_plugin_keyfile, G_TYPE_OBJECT, 0, G_DEFINE_TYPE_EXTENDED (NMSKeyfilePlugin, nms_keyfile_plugin, G_TYPE_OBJECT, 0,
G_IMPLEMENT_INTERFACE (NM_TYPE_SETTINGS_PLUGIN, G_IMPLEMENT_INTERFACE (NM_TYPE_SETTINGS_PLUGIN,
settings_plugin_interface_init)) settings_plugin_interface_init))
#define SETTINGS_PLUGIN_KEYFILE_GET_PRIVATE(self) _NM_GET_PRIVATE (self, SettingsPluginKeyfile, SETTINGS_IS_PLUGIN_KEYFILE) #define NMS_KEYFILE_PLUGIN_GET_PRIVATE(self) _NM_GET_PRIVATE (self, NMSKeyfilePlugin, NMS_IS_KEYFILE_PLUGIN)
/*****************************************************************************/
#define _NMLOG_PREFIX_NAME "keyfile"
#define _NMLOG_DOMAIN LOGD_SETTINGS
#define _NMLOG(level, ...) \
nm_log ((level), _NMLOG_DOMAIN, \
"%s" _NM_UTILS_MACRO_FIRST (__VA_ARGS__), \
_NMLOG_PREFIX_NAME": " \
_NM_UTILS_MACRO_REST (__VA_ARGS__))
/*****************************************************************************/ /*****************************************************************************/
static void static void
connection_removed_cb (NMSettingsConnection *obj, gpointer user_data) connection_removed_cb (NMSettingsConnection *obj, gpointer user_data)
{ {
g_hash_table_remove (SETTINGS_PLUGIN_KEYFILE_GET_PRIVATE ((SettingsPluginKeyfile *) user_data)->connections, g_hash_table_remove (NMS_KEYFILE_PLUGIN_GET_PRIVATE ((NMSKeyfilePlugin *) user_data)->connections,
nm_connection_get_uuid (NM_CONNECTION (obj))); nm_connection_get_uuid (NM_CONNECTION (obj)));
} }
/* Monitoring */ /* Monitoring */
static void static void
remove_connection (SettingsPluginKeyfile *self, NMKeyfileConnection *connection) remove_connection (NMSKeyfilePlugin *self, NMSKeyfileConnection *connection)
{ {
gboolean removed; gboolean removed;
g_return_if_fail (connection != NULL); g_return_if_fail (connection != NULL);
nm_log_info (LOGD_SETTINGS, "keyfile: removed " NM_KEYFILE_CONNECTION_LOG_FMT, NM_KEYFILE_CONNECTION_LOG_ARG (connection)); _LOGI ("removed " NMS_KEYFILE_CONNECTION_LOG_FMT, NMS_KEYFILE_CONNECTION_LOG_ARG (connection));
/* Removing from the hash table should drop the last reference */ /* Removing from the hash table should drop the last reference */
g_object_ref (connection); g_object_ref (connection);
g_signal_handlers_disconnect_by_func (connection, connection_removed_cb, self); g_signal_handlers_disconnect_by_func (connection, connection_removed_cb, self);
removed = g_hash_table_remove (SETTINGS_PLUGIN_KEYFILE_GET_PRIVATE (self)->connections, removed = g_hash_table_remove (NMS_KEYFILE_PLUGIN_GET_PRIVATE (self)->connections,
nm_connection_get_uuid (NM_CONNECTION (connection))); nm_connection_get_uuid (NM_CONNECTION (connection)));
nm_settings_connection_signal_remove (NM_SETTINGS_CONNECTION (connection)); nm_settings_connection_signal_remove (NM_SETTINGS_CONNECTION (connection));
g_object_unref (connection); g_object_unref (connection);
@@ -102,10 +113,10 @@ remove_connection (SettingsPluginKeyfile *self, NMKeyfileConnection *connection)
g_return_if_fail (removed); g_return_if_fail (removed);
} }
static NMKeyfileConnection * static NMSKeyfileConnection *
find_by_path (SettingsPluginKeyfile *self, const char *path) find_by_path (NMSKeyfilePlugin *self, const char *path)
{ {
SettingsPluginKeyfilePrivate *priv = SETTINGS_PLUGIN_KEYFILE_GET_PRIVATE (self); NMSKeyfilePluginPrivate *priv = NMS_KEYFILE_PLUGIN_GET_PRIVATE (self);
GHashTableIter iter; GHashTableIter iter;
NMSettingsConnection *candidate = NULL; NMSettingsConnection *candidate = NULL;
@@ -114,7 +125,7 @@ find_by_path (SettingsPluginKeyfile *self, const char *path)
g_hash_table_iter_init (&iter, priv->connections); g_hash_table_iter_init (&iter, priv->connections);
while (g_hash_table_iter_next (&iter, NULL, (gpointer) &candidate)) { while (g_hash_table_iter_next (&iter, NULL, (gpointer) &candidate)) {
if (g_strcmp0 (path, nm_settings_connection_get_filename (candidate)) == 0) if (g_strcmp0 (path, nm_settings_connection_get_filename (candidate)) == 0)
return NM_KEYFILE_CONNECTION (candidate); return NMS_KEYFILE_CONNECTION (candidate);
} }
return NULL; return NULL;
} }
@@ -150,18 +161,18 @@ find_by_path (SettingsPluginKeyfile *self, const char *path)
* *
* Returns: the updated connection. * Returns: the updated connection.
* */ * */
static NMKeyfileConnection * static NMSKeyfileConnection *
update_connection (SettingsPluginKeyfile *self, update_connection (NMSKeyfilePlugin *self,
NMConnection *source, NMConnection *source,
const char *full_path, const char *full_path,
NMKeyfileConnection *connection, NMSKeyfileConnection *connection,
gboolean protect_existing_connection, gboolean protect_existing_connection,
GHashTable *protected_connections, GHashTable *protected_connections,
GError **error) GError **error)
{ {
SettingsPluginKeyfilePrivate *priv = SETTINGS_PLUGIN_KEYFILE_GET_PRIVATE (self); NMSKeyfilePluginPrivate *priv = NMS_KEYFILE_PLUGIN_GET_PRIVATE (self);
NMKeyfileConnection *connection_new; NMSKeyfileConnection *connection_new;
NMKeyfileConnection *connection_by_uuid; NMSKeyfileConnection *connection_by_uuid;
GError *local = NULL; GError *local = NULL;
const char *uuid; const char *uuid;
@@ -169,15 +180,15 @@ update_connection (SettingsPluginKeyfile *self,
g_return_val_if_fail (full_path || source, NULL); g_return_val_if_fail (full_path || source, NULL);
if (full_path) if (full_path)
nm_log_dbg (LOGD_SETTINGS, "keyfile: loading from file \"%s\"...", full_path); _LOGD ("loading from file \"%s\"...", full_path);
connection_new = nm_keyfile_connection_new (source, full_path, &local); connection_new = nms_keyfile_connection_new (source, full_path, &local);
if (!connection_new) { if (!connection_new) {
/* Error; remove the connection */ /* Error; remove the connection */
if (source) if (source)
nm_log_warn (LOGD_SETTINGS, "keyfile: error creating connection %s: %s", nm_connection_get_uuid (source), local->message); _LOGW ("error creating connection %s: %s", nm_connection_get_uuid (source), local->message);
else else
nm_log_warn (LOGD_SETTINGS, "keyfile: error loading connection from file %s: %s", full_path, local->message); _LOGW ("error loading connection from file %s: %s", full_path, local->message);
if ( connection if ( connection
&& !protect_existing_connection && !protect_existing_connection
&& (!protected_connections || !g_hash_table_contains (protected_connections, connection))) && (!protected_connections || !g_hash_table_contains (protected_connections, connection)))
@@ -194,12 +205,12 @@ update_connection (SettingsPluginKeyfile *self,
if ( (protect_existing_connection && connection_by_uuid != NULL) if ( (protect_existing_connection && connection_by_uuid != NULL)
|| (protected_connections && g_hash_table_contains (protected_connections, connection))) { || (protected_connections && g_hash_table_contains (protected_connections, connection))) {
NMKeyfileConnection *conflicting = (protect_existing_connection && connection_by_uuid != NULL) ? connection_by_uuid : connection; NMSKeyfileConnection *conflicting = (protect_existing_connection && connection_by_uuid != NULL) ? connection_by_uuid : connection;
if (source) if (source)
nm_log_warn (LOGD_SETTINGS, "keyfile: cannot update protected "NM_KEYFILE_CONNECTION_LOG_FMT" connection due to conflicting UUID %s", NM_KEYFILE_CONNECTION_LOG_ARG (conflicting), uuid); _LOGW ("cannot update protected "NMS_KEYFILE_CONNECTION_LOG_FMT" connection due to conflicting UUID %s", NMS_KEYFILE_CONNECTION_LOG_ARG (conflicting), uuid);
else else
nm_log_warn (LOGD_SETTINGS, "keyfile: cannot load %s due to conflicting UUID for "NM_KEYFILE_CONNECTION_LOG_FMT, full_path, NM_KEYFILE_CONNECTION_LOG_ARG (conflicting)); _LOGW ("cannot load %s due to conflicting UUID for "NMS_KEYFILE_CONNECTION_LOG_FMT, full_path, NMS_KEYFILE_CONNECTION_LOG_ARG (conflicting));
g_object_unref (connection_new); g_object_unref (connection_new);
g_set_error_literal (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_FAILED, g_set_error_literal (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_FAILED,
"Cannot update protected connection due to conflicting UUID"); "Cannot update protected connection due to conflicting UUID");
@@ -215,9 +226,9 @@ update_connection (SettingsPluginKeyfile *self,
&& ( (!connection && protect_existing_connection) && ( (!connection && protect_existing_connection)
|| (protected_connections && g_hash_table_contains (protected_connections, connection_by_uuid)))) { || (protected_connections && g_hash_table_contains (protected_connections, connection_by_uuid)))) {
if (source) if (source)
nm_log_warn (LOGD_SETTINGS, "keyfile: cannot update connection due to conflicting UUID for "NM_KEYFILE_CONNECTION_LOG_FMT, NM_KEYFILE_CONNECTION_LOG_ARG (connection_by_uuid)); _LOGW ("cannot update connection due to conflicting UUID for "NMS_KEYFILE_CONNECTION_LOG_FMT, NMS_KEYFILE_CONNECTION_LOG_ARG (connection_by_uuid));
else else
nm_log_warn (LOGD_SETTINGS, "keyfile: cannot load %s due to conflicting UUID for "NM_KEYFILE_CONNECTION_LOG_FMT, full_path, NM_KEYFILE_CONNECTION_LOG_ARG (connection_by_uuid)); _LOGW ("cannot load %s due to conflicting UUID for "NMS_KEYFILE_CONNECTION_LOG_FMT, full_path, NMS_KEYFILE_CONNECTION_LOG_ARG (connection_by_uuid));
g_object_unref (connection_new); g_object_unref (connection_new);
g_set_error_literal (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_FAILED, g_set_error_literal (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_FAILED,
"Skip updating protected connection during reload"); "Skip updating protected connection during reload");
@@ -235,17 +246,17 @@ update_connection (SettingsPluginKeyfile *self,
NM_SETTING_COMPARE_FLAG_IGNORE_NOT_SAVED_SECRETS)) { NM_SETTING_COMPARE_FLAG_IGNORE_NOT_SAVED_SECRETS)) {
/* Nothing to do... except updating the path. */ /* Nothing to do... except updating the path. */
if (old_path && g_strcmp0 (old_path, full_path) != 0) if (old_path && g_strcmp0 (old_path, full_path) != 0)
nm_log_info (LOGD_SETTINGS, "keyfile: rename \"%s\" to "NM_KEYFILE_CONNECTION_LOG_FMT" without other changes", old_path, NM_KEYFILE_CONNECTION_LOG_ARG (connection_new)); _LOGI ("rename \"%s\" to "NMS_KEYFILE_CONNECTION_LOG_FMT" without other changes", old_path, NMS_KEYFILE_CONNECTION_LOG_ARG (connection_new));
} else { } else {
/* An existing connection changed. */ /* An existing connection changed. */
if (source) if (source)
nm_log_info (LOGD_SETTINGS, "keyfile: update "NM_KEYFILE_CONNECTION_LOG_FMT" from %s", NM_KEYFILE_CONNECTION_LOG_ARG (connection_new), NM_KEYFILE_CONNECTION_LOG_PATH (old_path)); _LOGI ("update "NMS_KEYFILE_CONNECTION_LOG_FMT" from %s", NMS_KEYFILE_CONNECTION_LOG_ARG (connection_new), NMS_KEYFILE_CONNECTION_LOG_PATH (old_path));
else if (!g_strcmp0 (old_path, nm_settings_connection_get_filename (NM_SETTINGS_CONNECTION (connection_new)))) else if (!g_strcmp0 (old_path, nm_settings_connection_get_filename (NM_SETTINGS_CONNECTION (connection_new))))
nm_log_info (LOGD_SETTINGS, "keyfile: update "NM_KEYFILE_CONNECTION_LOG_FMT, NM_KEYFILE_CONNECTION_LOG_ARG (connection_new)); _LOGI ("update "NMS_KEYFILE_CONNECTION_LOG_FMT, NMS_KEYFILE_CONNECTION_LOG_ARG (connection_new));
else if (old_path) else if (old_path)
nm_log_info (LOGD_SETTINGS, "keyfile: rename \"%s\" to "NM_KEYFILE_CONNECTION_LOG_FMT, old_path, NM_KEYFILE_CONNECTION_LOG_ARG (connection_new)); _LOGI ("rename \"%s\" to "NMS_KEYFILE_CONNECTION_LOG_FMT, old_path, NMS_KEYFILE_CONNECTION_LOG_ARG (connection_new));
else else
nm_log_info (LOGD_SETTINGS, "keyfile: update and persist "NM_KEYFILE_CONNECTION_LOG_FMT, NM_KEYFILE_CONNECTION_LOG_ARG (connection_new)); _LOGI ("update and persist "NMS_KEYFILE_CONNECTION_LOG_FMT, NMS_KEYFILE_CONNECTION_LOG_ARG (connection_new));
if (!nm_settings_connection_replace_settings (NM_SETTINGS_CONNECTION (connection_by_uuid), if (!nm_settings_connection_replace_settings (NM_SETTINGS_CONNECTION (connection_by_uuid),
NM_CONNECTION (connection_new), NM_CONNECTION (connection_new),
@@ -263,9 +274,9 @@ update_connection (SettingsPluginKeyfile *self,
return connection_by_uuid; return connection_by_uuid;
} else { } else {
if (source) if (source)
nm_log_info (LOGD_SETTINGS, "keyfile: add connection "NM_KEYFILE_CONNECTION_LOG_FMT, NM_KEYFILE_CONNECTION_LOG_ARG (connection_new)); _LOGI ("add connection "NMS_KEYFILE_CONNECTION_LOG_FMT, NMS_KEYFILE_CONNECTION_LOG_ARG (connection_new));
else else
nm_log_info (LOGD_SETTINGS, "keyfile: new connection "NM_KEYFILE_CONNECTION_LOG_FMT, NM_KEYFILE_CONNECTION_LOG_ARG (connection_new)); _LOGI ("new connection "NMS_KEYFILE_CONNECTION_LOG_FMT, NMS_KEYFILE_CONNECTION_LOG_ARG (connection_new));
g_hash_table_insert (priv->connections, g_strdup (uuid), connection_new); g_hash_table_insert (priv->connections, g_strdup (uuid), connection_new);
g_signal_connect (connection_new, NM_SETTINGS_CONNECTION_REMOVED, g_signal_connect (connection_new, NM_SETTINGS_CONNECTION_REMOVED,
@@ -289,31 +300,31 @@ dir_changed (GFileMonitor *monitor,
gpointer user_data) gpointer user_data)
{ {
NMSettingsPlugin *config = NM_SETTINGS_PLUGIN (user_data); NMSettingsPlugin *config = NM_SETTINGS_PLUGIN (user_data);
SettingsPluginKeyfile *self = SETTINGS_PLUGIN_KEYFILE (config); NMSKeyfilePlugin *self = NMS_KEYFILE_PLUGIN (config);
NMKeyfileConnection *connection; NMSKeyfileConnection *connection;
char *full_path; char *full_path;
gboolean exists; gboolean exists;
full_path = g_file_get_path (file); full_path = g_file_get_path (file);
if (nm_keyfile_plugin_utils_should_ignore_file (full_path)) { if (nms_keyfile_utils_should_ignore_file (full_path)) {
g_free (full_path); g_free (full_path);
return; return;
} }
exists = g_file_test (full_path, G_FILE_TEST_EXISTS); exists = g_file_test (full_path, G_FILE_TEST_EXISTS);
nm_log_dbg (LOGD_SETTINGS, "dir_changed(%s) = %d; file %s", full_path, event_type, exists ? "exists" : "does not exist"); _LOGD ("dir_changed(%s) = %d; file %s", full_path, event_type, exists ? "exists" : "does not exist");
connection = find_by_path (self, full_path); connection = find_by_path (self, full_path);
switch (event_type) { switch (event_type) {
case G_FILE_MONITOR_EVENT_DELETED: case G_FILE_MONITOR_EVENT_DELETED:
if (!exists && connection) if (!exists && connection)
remove_connection (SETTINGS_PLUGIN_KEYFILE (config), connection); remove_connection (NMS_KEYFILE_PLUGIN (config), connection);
break; break;
case G_FILE_MONITOR_EVENT_CREATED: case G_FILE_MONITOR_EVENT_CREATED:
case G_FILE_MONITOR_EVENT_CHANGES_DONE_HINT: case G_FILE_MONITOR_EVENT_CHANGES_DONE_HINT:
if (exists) if (exists)
update_connection (SETTINGS_PLUGIN_KEYFILE (config), NULL, full_path, connection, TRUE, NULL, NULL); update_connection (NMS_KEYFILE_PLUGIN (config), NULL, full_path, connection, TRUE, NULL, NULL);
break; break;
default: default:
break; break;
@@ -327,7 +338,7 @@ config_changed_cb (NMConfig *config,
NMConfigData *config_data, NMConfigData *config_data,
NMConfigChangeFlags changes, NMConfigChangeFlags changes,
NMConfigData *old_data, NMConfigData *old_data,
SettingsPluginKeyfile *self) NMSKeyfilePlugin *self)
{ {
gs_free char *old_value = NULL, *new_value = NULL; gs_free char *old_value = NULL, *new_value = NULL;
@@ -341,12 +352,12 @@ config_changed_cb (NMConfig *config,
static void static void
setup_monitoring (NMSettingsPlugin *config) setup_monitoring (NMSettingsPlugin *config)
{ {
SettingsPluginKeyfilePrivate *priv = SETTINGS_PLUGIN_KEYFILE_GET_PRIVATE ((SettingsPluginKeyfile *) config); NMSKeyfilePluginPrivate *priv = NMS_KEYFILE_PLUGIN_GET_PRIVATE ((NMSKeyfilePlugin *) config);
GFile *file; GFile *file;
GFileMonitor *monitor; GFileMonitor *monitor;
if (nm_config_get_monitor_connection_files (nm_config_get ())) { if (nm_config_get_monitor_connection_files (priv->config)) {
file = g_file_new_for_path (nm_keyfile_plugin_get_path ()); file = g_file_new_for_path (nms_keyfile_utils_get_path ());
monitor = g_file_monitor_directory (file, G_FILE_MONITOR_NONE, NULL, NULL); monitor = g_file_monitor_directory (file, G_FILE_MONITOR_NONE, NULL, NULL);
g_object_unref (file); g_object_unref (file);
@@ -366,7 +377,7 @@ static GHashTable *
_paths_from_connections (GHashTable *connections) _paths_from_connections (GHashTable *connections)
{ {
GHashTableIter iter; GHashTableIter iter;
NMKeyfileConnection *connection; NMSKeyfileConnection *connection;
GHashTable *paths = g_hash_table_new (g_str_hash, g_str_equal); GHashTable *paths = g_hash_table_new (g_str_hash, g_str_equal);
g_hash_table_iter_init (&iter, connections); g_hash_table_iter_init (&iter, connections);
@@ -402,23 +413,23 @@ _sort_paths (const char **f1, const char **f2, GHashTable *paths)
static void static void
read_connections (NMSettingsPlugin *config) read_connections (NMSettingsPlugin *config)
{ {
SettingsPluginKeyfile *self = SETTINGS_PLUGIN_KEYFILE (config); NMSKeyfilePlugin *self = NMS_KEYFILE_PLUGIN (config);
SettingsPluginKeyfilePrivate *priv = SETTINGS_PLUGIN_KEYFILE_GET_PRIVATE (self); NMSKeyfilePluginPrivate *priv = NMS_KEYFILE_PLUGIN_GET_PRIVATE (self);
GDir *dir; GDir *dir;
GError *error = NULL; GError *error = NULL;
const char *item; const char *item;
GHashTable *alive_connections; GHashTable *alive_connections;
GHashTableIter iter; GHashTableIter iter;
NMKeyfileConnection *connection; NMSKeyfileConnection *connection;
GPtrArray *dead_connections = NULL; GPtrArray *dead_connections = NULL;
guint i; guint i;
GPtrArray *filenames; GPtrArray *filenames;
GHashTable *paths; GHashTable *paths;
dir = g_dir_open (nm_keyfile_plugin_get_path (), 0, &error); dir = g_dir_open (nms_keyfile_utils_get_path (), 0, &error);
if (!dir) { if (!dir) {
nm_log_warn (LOGD_SETTINGS, "keyfile: cannot read directory '%s': %s", _LOGW ("cannot read directory '%s': %s",
nm_keyfile_plugin_get_path (), nms_keyfile_utils_get_path (),
error->message); error->message);
g_clear_error (&error); g_clear_error (&error);
return; return;
@@ -428,9 +439,9 @@ read_connections (NMSettingsPlugin *config)
filenames = g_ptr_array_new_with_free_func (g_free); filenames = g_ptr_array_new_with_free_func (g_free);
while ((item = g_dir_read_name (dir))) { while ((item = g_dir_read_name (dir))) {
if (nm_keyfile_plugin_utils_should_ignore_file (item)) if (nms_keyfile_utils_should_ignore_file (item))
continue; continue;
g_ptr_array_add (filenames, g_build_filename (nm_keyfile_plugin_get_path (), item, NULL)); g_ptr_array_add (filenames, g_build_filename (nms_keyfile_utils_get_path (), item, NULL));
} }
g_dir_close (dir); g_dir_close (dir);
@@ -474,7 +485,7 @@ read_connections (NMSettingsPlugin *config)
static GSList * static GSList *
get_connections (NMSettingsPlugin *config) get_connections (NMSettingsPlugin *config)
{ {
SettingsPluginKeyfilePrivate *priv = SETTINGS_PLUGIN_KEYFILE_GET_PRIVATE ((SettingsPluginKeyfile *) config); NMSKeyfilePluginPrivate *priv = NMS_KEYFILE_PLUGIN_GET_PRIVATE ((NMSKeyfilePlugin *) config);
if (!priv->initialized) { if (!priv->initialized) {
setup_monitoring (config); setup_monitoring (config);
@@ -488,16 +499,16 @@ static gboolean
load_connection (NMSettingsPlugin *config, load_connection (NMSettingsPlugin *config,
const char *filename) const char *filename)
{ {
SettingsPluginKeyfile *self = SETTINGS_PLUGIN_KEYFILE ((SettingsPluginKeyfile *) config); NMSKeyfilePlugin *self = NMS_KEYFILE_PLUGIN ((NMSKeyfilePlugin *) config);
NMKeyfileConnection *connection; NMSKeyfileConnection *connection;
int dir_len = strlen (nm_keyfile_plugin_get_path ()); int dir_len = strlen (nms_keyfile_utils_get_path ());
if ( strncmp (filename, nm_keyfile_plugin_get_path (), dir_len) != 0 if ( strncmp (filename, nms_keyfile_utils_get_path (), dir_len) != 0
|| filename[dir_len] != '/' || filename[dir_len] != '/'
|| strchr (filename + dir_len + 1, '/') != NULL) || strchr (filename + dir_len + 1, '/') != NULL)
return FALSE; return FALSE;
if (nm_keyfile_plugin_utils_should_ignore_file (filename + dir_len + 1)) if (nms_keyfile_utils_should_ignore_file (filename + dir_len + 1))
return FALSE; return FALSE;
connection = update_connection (self, NULL, filename, find_by_path (self, filename), TRUE, NULL, NULL); connection = update_connection (self, NULL, filename, find_by_path (self, filename), TRUE, NULL, NULL);
@@ -517,11 +528,11 @@ add_connection (NMSettingsPlugin *config,
gboolean save_to_disk, gboolean save_to_disk,
GError **error) GError **error)
{ {
SettingsPluginKeyfile *self = SETTINGS_PLUGIN_KEYFILE (config); NMSKeyfilePlugin *self = NMS_KEYFILE_PLUGIN (config);
gs_free char *path = NULL; gs_free char *path = NULL;
if (save_to_disk) { if (save_to_disk) {
if (!nm_keyfile_plugin_write_connection (connection, NULL, FALSE, &path, error)) if (!nms_keyfile_writer_connection (connection, NULL, FALSE, &path, error))
return NULL; return NULL;
} }
return NM_SETTINGS_CONNECTION (update_connection (self, connection, path, NULL, FALSE, NULL, error)); return NM_SETTINGS_CONNECTION (update_connection (self, connection, path, NULL, FALSE, NULL, error));
@@ -530,7 +541,7 @@ add_connection (NMSettingsPlugin *config,
static GSList * static GSList *
get_unmanaged_specs (NMSettingsPlugin *config) get_unmanaged_specs (NMSettingsPlugin *config)
{ {
SettingsPluginKeyfilePrivate *priv = SETTINGS_PLUGIN_KEYFILE_GET_PRIVATE ((SettingsPluginKeyfile *) config); NMSKeyfilePluginPrivate *priv = NMS_KEYFILE_PLUGIN_GET_PRIVATE ((NMSKeyfilePlugin *) config);
gs_free char *value = NULL; gs_free char *value = NULL;
value = nm_config_data_get_value (nm_config_get_data (priv->config), value = nm_config_data_get_value (nm_config_get_data (priv->config),
@@ -548,10 +559,10 @@ get_property (GObject *object, guint prop_id,
{ {
switch (prop_id) { switch (prop_id) {
case NM_SETTINGS_PLUGIN_PROP_NAME: case NM_SETTINGS_PLUGIN_PROP_NAME:
g_value_set_string (value, KEYFILE_PLUGIN_NAME); g_value_set_string (value, NMS_KEYFILE_PLUGIN_NAME);
break; break;
case NM_SETTINGS_PLUGIN_PROP_INFO: case NM_SETTINGS_PLUGIN_PROP_INFO:
g_value_set_string (value, KEYFILE_PLUGIN_INFO); g_value_set_string (value, NMS_KEYFILE_PLUGIN_INFO);
break; break;
case NM_SETTINGS_PLUGIN_PROP_CAPABILITIES: case NM_SETTINGS_PLUGIN_PROP_CAPABILITIES:
g_value_set_uint (value, NM_SETTINGS_PLUGIN_CAP_MODIFY_CONNECTIONS); g_value_set_uint (value, NM_SETTINGS_PLUGIN_CAP_MODIFY_CONNECTIONS);
@@ -565,36 +576,38 @@ get_property (GObject *object, guint prop_id,
/*****************************************************************************/ /*****************************************************************************/
static void static void
settings_plugin_keyfile_init (SettingsPluginKeyfile *plugin) nms_keyfile_plugin_init (NMSKeyfilePlugin *plugin)
{ {
SettingsPluginKeyfilePrivate *priv = SETTINGS_PLUGIN_KEYFILE_GET_PRIVATE (plugin); NMSKeyfilePluginPrivate *priv = NMS_KEYFILE_PLUGIN_GET_PRIVATE (plugin);
priv->config = g_object_ref (nm_config_get ());
priv->connections = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref); priv->connections = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref);
} }
static void static void
constructed (GObject *object) constructed (GObject *object)
{ {
SettingsPluginKeyfilePrivate *priv = SETTINGS_PLUGIN_KEYFILE_GET_PRIVATE ((SettingsPluginKeyfile *) object); NMSKeyfilePluginPrivate *priv = NMS_KEYFILE_PLUGIN_GET_PRIVATE ((NMSKeyfilePlugin *) object);
G_OBJECT_CLASS (nms_keyfile_plugin_parent_class)->constructed (object);
priv->config = g_object_ref (nm_config_get ());
if (nm_config_data_has_value (nm_config_get_data_orig (priv->config), if (nm_config_data_has_value (nm_config_get_data_orig (priv->config),
NM_CONFIG_KEYFILE_GROUP_KEYFILE, NM_CONFIG_KEYFILE_GROUP_KEYFILE,
NM_CONFIG_KEYFILE_KEY_KEYFILE_HOSTNAME, NM_CONFIG_KEYFILE_KEY_KEYFILE_HOSTNAME,
NM_CONFIG_GET_VALUE_RAW)) NM_CONFIG_GET_VALUE_RAW))
nm_log_warn (LOGD_SETTINGS, "keyfile: 'hostname' option is deprecated and has no effect"); _LOGW ("'hostname' option is deprecated and has no effect");
} }
GObject * NMSKeyfilePlugin *
nm_settings_keyfile_plugin_new (void) nms_keyfile_plugin_new (void)
{ {
return g_object_new (SETTINGS_TYPE_PLUGIN_KEYFILE, NULL); return g_object_new (NMS_TYPE_KEYFILE_PLUGIN, NULL);
} }
static void static void
dispose (GObject *object) dispose (GObject *object)
{ {
SettingsPluginKeyfilePrivate *priv = SETTINGS_PLUGIN_KEYFILE_GET_PRIVATE ((SettingsPluginKeyfile *) object); NMSKeyfilePluginPrivate *priv = NMS_KEYFILE_PLUGIN_GET_PRIVATE ((NMSKeyfilePlugin *) object);
if (priv->monitor) { if (priv->monitor) {
nm_clear_g_signal_handler (priv->monitor, &priv->monitor_id); nm_clear_g_signal_handler (priv->monitor, &priv->monitor_id);
@@ -613,11 +626,11 @@ dispose (GObject *object)
g_clear_object (&priv->config); g_clear_object (&priv->config);
} }
G_OBJECT_CLASS (settings_plugin_keyfile_parent_class)->dispose (object); G_OBJECT_CLASS (nms_keyfile_plugin_parent_class)->dispose (object);
} }
static void static void
settings_plugin_keyfile_class_init (SettingsPluginKeyfileClass *req_class) nms_keyfile_plugin_class_init (NMSKeyfilePluginClass *req_class)
{ {
GObjectClass *object_class = G_OBJECT_CLASS (req_class); GObjectClass *object_class = G_OBJECT_CLASS (req_class);

View File

@@ -0,0 +1,39 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/* NetworkManager system settings service - keyfile plugin
*
* 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.
*
* Copyright (C) 2008 Novell, Inc.
* Copyright (C) 2008 - 2011 Red Hat, Inc.
*/
#ifndef __NMS_KEYFILE_PLUGIN_H__
#define __NMS_KEYFILE_PLUGIN_H__
#define NMS_TYPE_KEYFILE_PLUGIN (nms_keyfile_plugin_get_type ())
#define NMS_KEYFILE_PLUGIN(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NMS_TYPE_KEYFILE_PLUGIN, NMSKeyfilePlugin))
#define NMS_KEYFILE_PLUGIN_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NMS_TYPE_KEYFILE_PLUGIN, NMSKeyfilePluginClass))
#define NMS_IS_KEYFILE_PLUGIN(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NMS_TYPE_KEYFILE_PLUGIN))
#define NMS_IS_KEYFILE_PLUGIN_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NMS_TYPE_KEYFILE_PLUGIN))
#define NMS_KEYFILE_PLUGIN_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NMS_TYPE_KEYFILE_PLUGIN, NMSKeyfilePluginClass))
typedef struct _NMSKeyfilePlugin NMSKeyfilePlugin;
typedef struct _NMSKeyfilePluginClass NMSKeyfilePluginClass;
GType nms_keyfile_plugin_get_type (void);
NMSKeyfilePlugin *nms_keyfile_plugin_new (void);
#endif /* __NMS_KEYFILE_PLUGIN_H__ */

View File

@@ -20,14 +20,17 @@
#include "nm-default.h" #include "nm-default.h"
#include "nms-keyfile-reader.h"
#include <sys/stat.h> #include <sys/stat.h>
#include <string.h> #include <string.h>
#include "reader.h"
#include "nm-keyfile-internal.h" #include "nm-keyfile-internal.h"
#include "NetworkManagerUtils.h" #include "NetworkManagerUtils.h"
/*****************************************************************************/
static const char * static const char *
_fmt_warn (const char *group, NMSetting *setting, const char *property_name, const char *message, char **out_message) _fmt_warn (const char *group, NMSetting *setting, const char *property_name, const char *message, char **out_message)
{ {
@@ -86,7 +89,7 @@ _handler_read (GKeyFile *keyfile,
} }
NMConnection * NMConnection *
nm_keyfile_plugin_connection_from_file (const char *filename, GError **error) nms_keyfile_reader_from_file (const char *filename, GError **error)
{ {
GKeyFile *key_file; GKeyFile *key_file;
struct stat statbuf; struct stat statbuf;

View File

@@ -19,11 +19,11 @@
* Copyright (C) 2008 Red Hat, Inc. * Copyright (C) 2008 Red Hat, Inc.
*/ */
#ifndef _KEYFILE_PLUGIN_READER_H #ifndef __NMS_KEYFILE_READER_H__
#define _KEYFILE_PLUGIN_READER_H #define __NMS_KEYFILE_READER_H__
#include <nm-connection.h> #include <nm-connection.h>
NMConnection *nm_keyfile_plugin_connection_from_file (const char *filename, GError **error); NMConnection *nms_keyfile_reader_from_file (const char *filename, GError **error);
#endif /* _KEYFILE_PLUGIN_READER_H */ #endif /* __NMS_KEYFILE_READER_H__ */

View File

@@ -20,10 +20,11 @@
#include "nm-default.h" #include "nm-default.h"
#include "nms-keyfile-utils.h"
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include "utils.h"
#include "nm-setting-wired.h" #include "nm-setting-wired.h"
#include "nm-setting-wireless.h" #include "nm-setting-wireless.h"
#include "nm-setting-wireless-security.h" #include "nm-setting-wireless-security.h"
@@ -31,6 +32,8 @@
#define NM_CONFIG_KEYFILE_PATH_DEFAULT NMCONFDIR "/system-connections" #define NM_CONFIG_KEYFILE_PATH_DEFAULT NMCONFDIR "/system-connections"
/*****************************************************************************/
static const char temp_letters[] = static const char temp_letters[] =
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
@@ -87,7 +90,7 @@ check_suffix (const char *base, const char *tag)
#define DER_TAG ".der" #define DER_TAG ".der"
gboolean gboolean
nm_keyfile_plugin_utils_should_ignore_file (const char *filename) nms_keyfile_utils_should_ignore_file (const char *filename)
{ {
gs_free char *base = NULL; gs_free char *base = NULL;
@@ -111,7 +114,7 @@ nm_keyfile_plugin_utils_should_ignore_file (const char *filename)
} }
char * char *
nm_keyfile_plugin_utils_escape_filename (const char *filename) nms_keyfile_utils_escape_filename (const char *filename)
{ {
GString *str; GString *str;
const char *f = filename; const char *f = filename;
@@ -150,7 +153,7 @@ nm_keyfile_plugin_utils_escape_filename (const char *filename)
/*****************************************************************************/ /*****************************************************************************/
const char * const char *
nm_keyfile_plugin_get_path (void) nms_keyfile_utils_get_path (void)
{ {
static char *path = NULL; static char *path = NULL;
@@ -165,5 +168,3 @@ nm_keyfile_plugin_get_path (void)
return path; return path;
} }
/*****************************************************************************/

View File

@@ -0,0 +1,41 @@
/* -*- 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 2010-2016 Red Hat, Inc.
*/
#ifndef __NMS_KEYFILE_UTILS_H__
#define __NMS_KEYFILE_UTILS_H__
#include "NetworkManagerUtils.h"
#define NMS_KEYFILE_PLUGIN_NAME "keyfile"
#define NMS_KEYFILE_PLUGIN_INFO "(c) 2007 - 2016 Red Hat, Inc. To report bugs please use the NetworkManager mailing list."
#define NMS_KEYFILE_CONNECTION_LOG_PATH(path) ((path) ?: "in-memory")
#define NMS_KEYFILE_CONNECTION_LOG_FMT "%s (%s,\"%s\")"
#define NMS_KEYFILE_CONNECTION_LOG_ARG(con) NMS_KEYFILE_CONNECTION_LOG_PATH (nm_settings_connection_get_filename ((NMSettingsConnection *) (con))), nm_connection_get_uuid ((NMConnection *) (con)), nm_connection_get_id ((NMConnection *) (con))
#define NMS_KEYFILE_CONNECTION_LOG_FMTD "%s (%s,\"%s\",%p)"
#define NMS_KEYFILE_CONNECTION_LOG_ARGD(con) NMS_KEYFILE_CONNECTION_LOG_PATH (nm_settings_connection_get_filename ((NMSettingsConnection *) (con))), nm_connection_get_uuid ((NMConnection *) (con)), nm_connection_get_id ((NMConnection *) (con)), (con)
gboolean nms_keyfile_utils_should_ignore_file (const char *filename);
char *nms_keyfile_utils_escape_filename (const char *filename);
const char *nms_keyfile_utils_get_path (void);
#endif /* __NMS_KEYFILE_UTILS_H__ */

View File

@@ -21,20 +21,25 @@
#include "nm-default.h" #include "nm-default.h"
#include "nms-keyfile-writer.h"
#include <stdlib.h> #include <stdlib.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <unistd.h> #include <unistd.h>
#include <errno.h> #include <errno.h>
#include <string.h> #include <string.h>
#include "writer.h"
#include "utils.h"
#include "nm-keyfile-internal.h" #include "nm-keyfile-internal.h"
#include "nms-keyfile-utils.h"
/*****************************************************************************/
typedef struct { typedef struct {
const char *keyfile_dir; const char *keyfile_dir;
} WriteInfo; } WriteInfo;
/*****************************************************************************/
static gboolean static gboolean
write_cert_key_file (const char *path, write_cert_key_file (const char *path,
@@ -262,7 +267,7 @@ _internal_write_connection (NMConnection *connection,
if (existing_path != NULL && !force_rename) { if (existing_path != NULL && !force_rename) {
path = g_strdup (existing_path); path = g_strdup (existing_path);
} else { } else {
char *filename_escaped = nm_keyfile_plugin_utils_escape_filename (id); char *filename_escaped = nms_keyfile_utils_escape_filename (id);
path = g_build_filename (keyfile_dir, filename_escaped, NULL); path = g_build_filename (keyfile_dir, filename_escaped, NULL);
g_free (filename_escaped); g_free (filename_escaped);
@@ -288,7 +293,7 @@ _internal_write_connection (NMConnection *connection,
else else
filename = g_strdup_printf ("%s-%s-%u", id, nm_connection_get_uuid (connection), i); filename = g_strdup_printf ("%s-%s-%u", id, nm_connection_get_uuid (connection), i);
filename_escaped = nm_keyfile_plugin_utils_escape_filename (filename); filename_escaped = nms_keyfile_utils_escape_filename (filename);
g_free (path); g_free (path);
path = g_strdup_printf ("%s/%s", keyfile_dir, filename_escaped); path = g_strdup_printf ("%s/%s", keyfile_dir, filename_escaped);
@@ -351,14 +356,14 @@ out:
} }
gboolean gboolean
nm_keyfile_plugin_write_connection (NMConnection *connection, nms_keyfile_writer_connection (NMConnection *connection,
const char *existing_path, const char *existing_path,
gboolean force_rename, gboolean force_rename,
char **out_path, char **out_path,
GError **error) GError **error)
{ {
return _internal_write_connection (connection, return _internal_write_connection (connection,
nm_keyfile_plugin_get_path (), nms_keyfile_utils_get_path (),
0, 0, 0, 0,
existing_path, existing_path,
force_rename, force_rename,
@@ -367,12 +372,12 @@ nm_keyfile_plugin_write_connection (NMConnection *connection,
} }
gboolean gboolean
nm_keyfile_plugin_write_test_connection (NMConnection *connection, nms_keyfile_writer_test_connection (NMConnection *connection,
const char *keyfile_dir, const char *keyfile_dir,
uid_t owner_uid, uid_t owner_uid,
pid_t owner_grp, pid_t owner_grp,
char **out_path, char **out_path,
GError **error) GError **error)
{ {
return _internal_write_connection (connection, return _internal_write_connection (connection,
keyfile_dir, keyfile_dir,

View File

@@ -19,22 +19,22 @@
* Copyright (C) 2008 - 2011 Red Hat, Inc. * Copyright (C) 2008 - 2011 Red Hat, Inc.
*/ */
#ifndef _KEYFILE_PLUGIN_WRITER_H #ifndef __NMS_KEYFILE_WRITER_H__
#define _KEYFILE_PLUGIN_WRITER_H #define __NMS_KEYFILE_WRITER_H__
#include <nm-connection.h> #include <nm-connection.h>
gboolean nm_keyfile_plugin_write_connection (NMConnection *connection, gboolean nms_keyfile_writer_connection (NMConnection *connection,
const char *existing_path, const char *existing_path,
gboolean force_rename, gboolean force_rename,
char **out_path,
GError **error);
gboolean nms_keyfile_writer_test_connection (NMConnection *connection,
const char *keyfile_dir,
uid_t owner_uid,
pid_t owner_grp,
char **out_path, char **out_path,
GError **error); GError **error);
gboolean nm_keyfile_plugin_write_test_connection (NMConnection *connection, #endif /* __NMS_KEYFILE_WRITER_H__ */
const char *keyfile_dir,
uid_t owner_uid,
pid_t owner_grp,
char **out_path,
GError **error);
#endif /* _KEYFILE_PLUGIN_WRITER_H */

View File

@@ -1,39 +0,0 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/* NetworkManager system settings service - keyfile plugin
*
* 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.
*
* Copyright (C) 2008 Novell, Inc.
* Copyright (C) 2008 - 2011 Red Hat, Inc.
*/
#ifndef __NMKF_PLUGIN_H__
#define __NMKF_PLUGIN_H__
#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 _SettingsPluginKeyfile SettingsPluginKeyfile;
typedef struct _SettingsPluginKeyfileClass SettingsPluginKeyfileClass;
GType settings_plugin_keyfile_get_type (void);
GObject *nm_settings_keyfile_plugin_new (void);
#endif /* __NMKF_PLUGIN_H__ */

View File

@@ -14,7 +14,7 @@ AM_CPPFLAGS = \
-I$(srcdir)/../ \ -I$(srcdir)/../ \
$(GLIB_CFLAGS) \ $(GLIB_CFLAGS) \
$(CODE_COVERAGE_CFLAGS) \ $(CODE_COVERAGE_CFLAGS) \
-DG_LOG_DOMAIN=\""NetworkManager-keyfile"\" \ -DG_LOG_DOMAIN=\""NetworkManager"\" \
-DNETWORKMANAGER_COMPILATION=NM_NETWORKMANAGER_COMPILATION_INSIDE_DAEMON \ -DNETWORKMANAGER_COMPILATION=NM_NETWORKMANAGER_COMPILATION_INSIDE_DAEMON \
-DTEST_KEYFILES_DIR=\"$(abs_srcdir)/keyfiles\" \ -DTEST_KEYFILES_DIR=\"$(abs_srcdir)/keyfiles\" \
-DTEST_SCRATCH_DIR=\"$(abs_builddir)/keyfiles\" \ -DTEST_SCRATCH_DIR=\"$(abs_builddir)/keyfiles\" \
@@ -23,10 +23,7 @@ AM_CPPFLAGS = \
noinst_PROGRAMS = test-keyfile noinst_PROGRAMS = test-keyfile
test_keyfile_SOURCES = \ test_keyfile_SOURCES = \
test-keyfile.c \ test-keyfile.c
../reader.c \
../writer.c \
../utils.c
test_keyfile_LDADD = \ test_keyfile_LDADD = \
$(top_builddir)/src/libNetworkManager.la \ $(top_builddir)/src/libNetworkManager.la \

View File

@@ -30,9 +30,9 @@
#include "nm-core-internal.h" #include "nm-core-internal.h"
#include "reader.h" #include "nms-keyfile-reader.h"
#include "writer.h" #include "nms-keyfile-writer.h"
#include "utils.h" #include "nms-keyfile-utils.h"
#include "nm-test-utils-core.h" #include "nm-test-utils-core.h"
@@ -69,7 +69,7 @@ keyfile_read_connection_from_file (const char *filename)
g_assert (filename); g_assert (filename);
connection = nm_keyfile_plugin_connection_from_file (filename, &error); connection = nms_keyfile_reader_from_file (filename, &error);
g_assert_no_error (error); g_assert_no_error (error);
nmtst_assert_connection_verifies_without_normalization (connection); nmtst_assert_connection_verifies_without_normalization (connection);
@@ -89,7 +89,7 @@ assert_reread (NMConnection *connection, gboolean normalize_connection, const ch
g_assert (NM_IS_CONNECTION (connection)); g_assert (NM_IS_CONNECTION (connection));
g_assert (testfile && testfile[0]); g_assert (testfile && testfile[0]);
reread = nm_keyfile_plugin_connection_from_file (testfile, p_error); reread = nms_keyfile_reader_from_file (testfile, p_error);
g_assert_no_error (error); g_assert_no_error (error);
g_assert (NM_IS_CONNECTION (reread)); g_assert (NM_IS_CONNECTION (reread));
@@ -127,7 +127,7 @@ write_test_connection (NMConnection *connection, char **testfile)
owner_uid = geteuid (); owner_uid = geteuid ();
owner_grp = getegid (); owner_grp = getegid ();
success = nm_keyfile_plugin_write_test_connection (connection, TEST_SCRATCH_DIR, owner_uid, owner_grp, testfile, p_error); success = nms_keyfile_writer_test_connection (connection, TEST_SCRATCH_DIR, owner_uid, owner_grp, testfile, p_error);
g_assert_no_error (error); g_assert_no_error (error);
g_assert (success); g_assert (success);
g_assert (*testfile && (*testfile)[0]); g_assert (*testfile && (*testfile)[0]);
@@ -204,7 +204,7 @@ test_read_valid_wired_connection (void)
"*ipv6.routes*semicolon at the end*routes1*"); "*ipv6.routes*semicolon at the end*routes1*");
g_test_expect_message ("NetworkManager", G_LOG_LEVEL_INFO, g_test_expect_message ("NetworkManager", G_LOG_LEVEL_INFO,
"*ipv6.route*semicolon at the end*route6*"); "*ipv6.route*semicolon at the end*route6*");
connection = nm_keyfile_plugin_connection_from_file (TEST_KEYFILES_DIR "/Test_Wired_Connection", NULL); connection = nms_keyfile_reader_from_file (TEST_KEYFILES_DIR "/Test_Wired_Connection", NULL);
g_test_assert_expected_messages (); g_test_assert_expected_messages ();
g_assert (connection); g_assert (connection);
@@ -465,7 +465,7 @@ test_read_ip6_wired_connection (void)
gs_free_error GError *error = NULL; gs_free_error GError *error = NULL;
gboolean success; gboolean success;
connection = nm_keyfile_plugin_connection_from_file (TEST_KEYFILES_DIR "/Test_Wired_Connection_IP6", NULL); connection = nms_keyfile_reader_from_file (TEST_KEYFILES_DIR "/Test_Wired_Connection_IP6", NULL);
g_assert (connection); g_assert (connection);
success = nm_connection_verify (connection, &error); success = nm_connection_verify (connection, &error);
g_assert_no_error (error); g_assert_no_error (error);
@@ -576,7 +576,7 @@ test_read_wired_mac_case (void)
"*ipv4.addresses*semicolon at the end*addresses2*"); "*ipv4.addresses*semicolon at the end*addresses2*");
g_test_expect_message ("NetworkManager", G_LOG_LEVEL_INFO, g_test_expect_message ("NetworkManager", G_LOG_LEVEL_INFO,
"*ipv6.routes*semicolon at the end*routes1*"); "*ipv6.routes*semicolon at the end*routes1*");
connection = nm_keyfile_plugin_connection_from_file (TEST_KEYFILES_DIR "/Test_Wired_Connection_MAC_Case", NULL); connection = nms_keyfile_reader_from_file (TEST_KEYFILES_DIR "/Test_Wired_Connection_MAC_Case", NULL);
g_test_assert_expected_messages (); g_test_assert_expected_messages ();
g_assert (connection); g_assert (connection);
success = nm_connection_verify (connection, &error); success = nm_connection_verify (connection, &error);
@@ -608,7 +608,7 @@ test_read_mac_old_format (void)
char expected_mac[ETH_ALEN] = { 0x00, 0x11, 0xaa, 0xbb, 0xcc, 0x55 }; char expected_mac[ETH_ALEN] = { 0x00, 0x11, 0xaa, 0xbb, 0xcc, 0x55 };
char expected_cloned_mac[ETH_ALEN] = { 0x00, 0x16, 0xaa, 0xbb, 0xcc, 0xfe }; char expected_cloned_mac[ETH_ALEN] = { 0x00, 0x16, 0xaa, 0xbb, 0xcc, 0xfe };
connection = nm_keyfile_plugin_connection_from_file (TEST_KEYFILES_DIR "/Test_MAC_Old_Format", &error); connection = nms_keyfile_reader_from_file (TEST_KEYFILES_DIR "/Test_MAC_Old_Format", &error);
g_assert_no_error (error); g_assert_no_error (error);
g_assert (connection); g_assert (connection);
@@ -642,7 +642,7 @@ test_read_mac_ib_old_format (void)
0x77, 0x88, 0x99, 0x01, 0x12, 0x23, 0x34, 0x45, 0x56, 0x67, 0x78, 0x89, 0x77, 0x88, 0x99, 0x01, 0x12, 0x23, 0x34, 0x45, 0x56, 0x67, 0x78, 0x89,
0x90 }; 0x90 };
connection = nm_keyfile_plugin_connection_from_file (TEST_KEYFILES_DIR "/Test_MAC_IB_Old_Format", &error); connection = nms_keyfile_reader_from_file (TEST_KEYFILES_DIR "/Test_MAC_IB_Old_Format", &error);
g_assert_no_error (error); g_assert_no_error (error);
g_assert (connection); g_assert (connection);
@@ -671,7 +671,7 @@ test_read_valid_wireless_connection (void)
const guint8 expected_bssid[ETH_ALEN] = { 0x00, 0x1a, 0x33, 0x44, 0x99, 0x82 }; const guint8 expected_bssid[ETH_ALEN] = { 0x00, 0x1a, 0x33, 0x44, 0x99, 0x82 };
gboolean success; gboolean success;
connection = nm_keyfile_plugin_connection_from_file (TEST_KEYFILES_DIR "/Test_Wireless_Connection", NULL); connection = nms_keyfile_reader_from_file (TEST_KEYFILES_DIR "/Test_Wireless_Connection", NULL);
g_assert (connection); g_assert (connection);
success = nm_connection_verify (connection, &error); success = nm_connection_verify (connection, &error);
g_assert_no_error (error); g_assert_no_error (error);
@@ -775,7 +775,7 @@ test_read_string_ssid (void)
const char *expected_ssid = "blah blah ssid 1234"; const char *expected_ssid = "blah blah ssid 1234";
gboolean success; gboolean success;
connection = nm_keyfile_plugin_connection_from_file (TEST_KEYFILES_DIR "/Test_String_SSID", NULL); connection = nms_keyfile_reader_from_file (TEST_KEYFILES_DIR "/Test_String_SSID", NULL);
g_assert (connection); g_assert (connection);
success = nm_connection_verify (connection, &error); success = nm_connection_verify (connection, &error);
g_assert_no_error (error); g_assert_no_error (error);
@@ -859,7 +859,7 @@ test_read_intlist_ssid (void)
gsize ssid_len; gsize ssid_len;
const char *expected_ssid = "blah1234"; const char *expected_ssid = "blah1234";
connection = nm_keyfile_plugin_connection_from_file (TEST_KEYFILES_DIR "/Test_Intlist_SSID", &error); connection = nms_keyfile_reader_from_file (TEST_KEYFILES_DIR "/Test_Intlist_SSID", &error);
g_assert_no_error (error); g_assert_no_error (error);
g_assert (connection); g_assert (connection);
@@ -952,7 +952,7 @@ test_read_intlike_ssid (void)
gsize ssid_len; gsize ssid_len;
const char *expected_ssid = "101"; const char *expected_ssid = "101";
connection = nm_keyfile_plugin_connection_from_file (TEST_KEYFILES_DIR "/Test_Intlike_SSID", &error); connection = nms_keyfile_reader_from_file (TEST_KEYFILES_DIR "/Test_Intlike_SSID", &error);
g_assert_no_error (error); g_assert_no_error (error);
g_assert (connection); g_assert (connection);
@@ -983,7 +983,7 @@ test_read_intlike_ssid_2 (void)
gsize ssid_len; gsize ssid_len;
const char *expected_ssid = "11;12;13;"; const char *expected_ssid = "11;12;13;";
connection = nm_keyfile_plugin_connection_from_file (TEST_KEYFILES_DIR "/Test_Intlike_SSID_2", &error); connection = nms_keyfile_reader_from_file (TEST_KEYFILES_DIR "/Test_Intlike_SSID_2", &error);
g_assert_no_error (error); g_assert_no_error (error);
g_assert (connection); g_assert (connection);
@@ -1132,7 +1132,7 @@ test_read_bt_dun_connection (void)
const guint8 expected_bdaddr[ETH_ALEN] = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55 }; const guint8 expected_bdaddr[ETH_ALEN] = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55 };
gboolean success; gboolean success;
connection = nm_keyfile_plugin_connection_from_file (TEST_KEYFILES_DIR "/ATT_Data_Connect_BT", NULL); connection = nms_keyfile_reader_from_file (TEST_KEYFILES_DIR "/ATT_Data_Connect_BT", NULL);
g_assert (connection); g_assert (connection);
success = nm_connection_verify (connection, &error); success = nm_connection_verify (connection, &error);
g_assert_no_error (error); g_assert_no_error (error);
@@ -1235,7 +1235,7 @@ test_read_gsm_connection (void)
gs_free_error GError *error = NULL; gs_free_error GError *error = NULL;
gboolean success; gboolean success;
connection = nm_keyfile_plugin_connection_from_file (TEST_KEYFILES_DIR "/ATT_Data_Connect_Plain", &error); connection = nms_keyfile_reader_from_file (TEST_KEYFILES_DIR "/ATT_Data_Connect_Plain", &error);
g_assert_no_error (error); g_assert_no_error (error);
g_assert (connection); g_assert (connection);
@@ -1340,7 +1340,7 @@ test_read_wired_8021x_tls_blob_connection (void)
"*<warn> * keyfile: 802-1x.client-cert: certificate or key file '/CASA/dcbw/Desktop/certinfra/client.pem' does not exist*"); "*<warn> * keyfile: 802-1x.client-cert: certificate or key file '/CASA/dcbw/Desktop/certinfra/client.pem' does not exist*");
g_test_expect_message ("NetworkManager", G_LOG_LEVEL_MESSAGE, g_test_expect_message ("NetworkManager", G_LOG_LEVEL_MESSAGE,
"*<warn> * keyfile: 802-1x.private-key: certificate or key file '/CASA/dcbw/Desktop/certinfra/client.pem' does not exist*"); "*<warn> * keyfile: 802-1x.private-key: certificate or key file '/CASA/dcbw/Desktop/certinfra/client.pem' does not exist*");
connection = nm_keyfile_plugin_connection_from_file (TEST_KEYFILES_DIR "/Test_Wired_TLS_Blob", &error); connection = nms_keyfile_reader_from_file (TEST_KEYFILES_DIR "/Test_Wired_TLS_Blob", &error);
g_assert_no_error (error); g_assert_no_error (error);
g_assert (connection); g_assert (connection);
success = nm_connection_verify (connection, &error); success = nm_connection_verify (connection, &error);
@@ -1399,7 +1399,7 @@ test_read_wired_8021x_tls_bad_path_connection (void)
g_test_expect_message ("NetworkManager", G_LOG_LEVEL_MESSAGE, g_test_expect_message ("NetworkManager", G_LOG_LEVEL_MESSAGE,
"*does not exist*"); "*does not exist*");
connection = nm_keyfile_plugin_connection_from_file (TEST_KEYFILES_DIR "/Test_Wired_TLS_Path_Missing", &error); connection = nms_keyfile_reader_from_file (TEST_KEYFILES_DIR "/Test_Wired_TLS_Path_Missing", &error);
g_test_assert_expected_messages (); g_test_assert_expected_messages ();
g_assert_no_error (error); g_assert_no_error (error);
g_assert (connection); g_assert (connection);
@@ -1457,7 +1457,7 @@ test_read_wired_8021x_tls_old_connection (void)
"*<warn> * keyfile: 802-1x.client-cert: certificate or key file '/CASA/dcbw/Desktop/certinfra/client.pem' does not exist*"); "*<warn> * keyfile: 802-1x.client-cert: certificate or key file '/CASA/dcbw/Desktop/certinfra/client.pem' does not exist*");
g_test_expect_message ("NetworkManager", G_LOG_LEVEL_MESSAGE, g_test_expect_message ("NetworkManager", G_LOG_LEVEL_MESSAGE,
"*<warn> * keyfile: 802-1x.private-key: certificate or key file '/CASA/dcbw/Desktop/certinfra/client.pem' does not exist*"); "*<warn> * keyfile: 802-1x.private-key: certificate or key file '/CASA/dcbw/Desktop/certinfra/client.pem' does not exist*");
connection = nm_keyfile_plugin_connection_from_file (TEST_KEYFILES_DIR "/Test_Wired_TLS_Old", &error); connection = nms_keyfile_reader_from_file (TEST_KEYFILES_DIR "/Test_Wired_TLS_Old", &error);
g_assert_no_error (error); g_assert_no_error (error);
g_assert (connection); g_assert (connection);
success = nm_connection_verify (connection, &error); success = nm_connection_verify (connection, &error);
@@ -1503,7 +1503,7 @@ test_read_wired_8021x_tls_new_connection (void)
char *tmp2; char *tmp2;
gboolean success; gboolean success;
connection = nm_keyfile_plugin_connection_from_file (TEST_KEYFILES_DIR "/Test_Wired_TLS_New", &error); connection = nms_keyfile_reader_from_file (TEST_KEYFILES_DIR "/Test_Wired_TLS_New", &error);
g_assert_no_error (error); g_assert_no_error (error);
g_assert (connection); g_assert (connection);
success = nm_connection_verify (connection, &error); success = nm_connection_verify (connection, &error);
@@ -1645,7 +1645,7 @@ test_write_wired_8021x_tls_connection_path (void)
write_test_connection (connection, &testfile); write_test_connection (connection, &testfile);
/* Read the connection back in and compare it to the one we just wrote out */ /* Read the connection back in and compare it to the one we just wrote out */
reread = nm_keyfile_plugin_connection_from_file (testfile, &error); reread = nms_keyfile_reader_from_file (testfile, &error);
if (!reread) { if (!reread) {
g_assert (error); g_assert (error);
g_warning ("Failed to re-read test connection: %s", error->message); g_warning ("Failed to re-read test connection: %s", error->message);
@@ -1753,7 +1753,7 @@ test_write_wired_8021x_tls_connection_blob (void)
g_assert (g_file_test (new_priv_key, G_FILE_TEST_EXISTS)); g_assert (g_file_test (new_priv_key, G_FILE_TEST_EXISTS));
/* Read the connection back in and compare it to the one we just wrote out */ /* Read the connection back in and compare it to the one we just wrote out */
reread = nm_keyfile_plugin_connection_from_file (testfile, &error); reread = nms_keyfile_reader_from_file (testfile, &error);
if (!reread) { if (!reread) {
g_assert (error); g_assert (error);
g_warning ("Failed to re-read test connection: %s", error->message); g_warning ("Failed to re-read test connection: %s", error->message);
@@ -1800,7 +1800,7 @@ test_read_infiniband_connection (void)
const char *expected_uuid = "4e80a56d-c99f-4aad-a6dd-b449bc398c57"; const char *expected_uuid = "4e80a56d-c99f-4aad-a6dd-b449bc398c57";
gboolean success; gboolean success;
connection = nm_keyfile_plugin_connection_from_file (TEST_KEYFILES_DIR "/Test_InfiniBand_Connection", &error); connection = nms_keyfile_reader_from_file (TEST_KEYFILES_DIR "/Test_InfiniBand_Connection", &error);
g_assert_no_error (error); g_assert_no_error (error);
g_assert (connection); g_assert (connection);
success = nm_connection_verify (connection, &error); success = nm_connection_verify (connection, &error);
@@ -1886,7 +1886,7 @@ test_read_bridge_main (void)
const char *expected_uuid = "8f061643-fe41-4d4c-a8d9-097d26e2ad3a"; const char *expected_uuid = "8f061643-fe41-4d4c-a8d9-097d26e2ad3a";
gboolean success; gboolean success;
connection = nm_keyfile_plugin_connection_from_file (TEST_KEYFILES_DIR "/Test_Bridge_Main", &error); connection = nms_keyfile_reader_from_file (TEST_KEYFILES_DIR "/Test_Bridge_Main", &error);
g_assert_no_error (error); g_assert_no_error (error);
g_assert (connection); g_assert (connection);
success = nm_connection_verify (connection, &error); success = nm_connection_verify (connection, &error);
@@ -1983,7 +1983,7 @@ test_read_bridge_component (void)
const char *expected_uuid = "d7b4f96c-c45e-4298-bef8-f48574f8c1c0"; const char *expected_uuid = "d7b4f96c-c45e-4298-bef8-f48574f8c1c0";
gboolean success; gboolean success;
connection = nm_keyfile_plugin_connection_from_file (TEST_KEYFILES_DIR "/Test_Bridge_Component", &error); connection = nms_keyfile_reader_from_file (TEST_KEYFILES_DIR "/Test_Bridge_Component", &error);
g_assert_no_error (error); g_assert_no_error (error);
g_assert (connection); g_assert (connection);
success = nm_connection_verify (connection, &error); success = nm_connection_verify (connection, &error);
@@ -2073,7 +2073,7 @@ test_read_new_wired_group_name (void)
gs_free_error GError *error = NULL; gs_free_error GError *error = NULL;
gboolean success; gboolean success;
connection = nm_keyfile_plugin_connection_from_file (TEST_KEYFILES_DIR"/Test_New_Wired_Group_Name", &error); connection = nms_keyfile_reader_from_file (TEST_KEYFILES_DIR"/Test_New_Wired_Group_Name", &error);
g_assert_no_error (error); g_assert_no_error (error);
g_assert (connection); g_assert (connection);
success = nm_connection_verify (connection, &error); success = nm_connection_verify (connection, &error);
@@ -2155,7 +2155,7 @@ test_read_new_wireless_group_names (void)
gs_free_error GError *error = NULL; gs_free_error GError *error = NULL;
gboolean success; gboolean success;
connection = nm_keyfile_plugin_connection_from_file (TEST_KEYFILES_DIR"/Test_New_Wireless_Group_Names", &error); connection = nms_keyfile_reader_from_file (TEST_KEYFILES_DIR"/Test_New_Wireless_Group_Names", &error);
g_assert_no_error (error); g_assert_no_error (error);
g_assert (connection); g_assert (connection);
success = nm_connection_verify (connection, &error); success = nm_connection_verify (connection, &error);
@@ -2262,7 +2262,7 @@ test_read_missing_vlan_setting (void)
gs_free_error GError *error = NULL; gs_free_error GError *error = NULL;
gboolean success; gboolean success;
connection = nm_keyfile_plugin_connection_from_file (TEST_KEYFILES_DIR"/Test_Missing_Vlan_Setting", &error); connection = nms_keyfile_reader_from_file (TEST_KEYFILES_DIR"/Test_Missing_Vlan_Setting", &error);
g_assert_no_error (error); g_assert_no_error (error);
g_assert (connection); g_assert (connection);
success = nm_connection_verify (connection, &error); success = nm_connection_verify (connection, &error);
@@ -2284,7 +2284,7 @@ test_read_missing_vlan_flags (void)
gs_free_error GError *error = NULL; gs_free_error GError *error = NULL;
gboolean success; gboolean success;
connection = nm_keyfile_plugin_connection_from_file (TEST_KEYFILES_DIR"/Test_Missing_Vlan_Flags", &error); connection = nms_keyfile_reader_from_file (TEST_KEYFILES_DIR"/Test_Missing_Vlan_Flags", &error);
g_assert_no_error (error); g_assert_no_error (error);
g_assert (connection); g_assert (connection);
success = nm_connection_verify (connection, &error); success = nm_connection_verify (connection, &error);
@@ -2307,7 +2307,7 @@ test_read_missing_id_uuid (void)
gs_free_error GError *error = NULL; gs_free_error GError *error = NULL;
gboolean success; gboolean success;
connection = nm_keyfile_plugin_connection_from_file (TEST_KEYFILES_DIR"/Test_Missing_ID_UUID", &error); connection = nms_keyfile_reader_from_file (TEST_KEYFILES_DIR"/Test_Missing_ID_UUID", &error);
g_assert_no_error (error); g_assert_no_error (error);
g_assert (connection); g_assert (connection);
success = nm_connection_verify (connection, &error); success = nm_connection_verify (connection, &error);
@@ -2411,7 +2411,7 @@ test_read_enum_property (void)
gs_free_error GError *error = NULL; gs_free_error GError *error = NULL;
gboolean success; gboolean success;
connection = nm_keyfile_plugin_connection_from_file (TEST_KEYFILES_DIR"/Test_Enum_Property", &error); connection = nms_keyfile_reader_from_file (TEST_KEYFILES_DIR"/Test_Enum_Property", &error);
g_assert_no_error (error); g_assert_no_error (error);
g_assert (connection); g_assert (connection);
success = nm_connection_verify (connection, &error); success = nm_connection_verify (connection, &error);
@@ -2471,7 +2471,7 @@ test_read_flags_property (void)
gs_free_error GError *error = NULL; gs_free_error GError *error = NULL;
gboolean success; gboolean success;
connection = nm_keyfile_plugin_connection_from_file (TEST_KEYFILES_DIR"/Test_Flags_Property", &error); connection = nms_keyfile_reader_from_file (TEST_KEYFILES_DIR"/Test_Flags_Property", &error);
g_assert_no_error (error); g_assert_no_error (error);
g_assert (connection); g_assert (connection);
success = nm_connection_verify (connection, &error); success = nm_connection_verify (connection, &error);
@@ -2530,18 +2530,18 @@ _escape_filename (const char *filename, gboolean would_be_ignored)
g_assert (filename && filename[0]); g_assert (filename && filename[0]);
if (!!would_be_ignored != !!nm_keyfile_plugin_utils_should_ignore_file (filename)) { if (!!would_be_ignored != !!nms_keyfile_utils_should_ignore_file (filename)) {
if (would_be_ignored) if (would_be_ignored)
g_error ("We expect filename \"%s\" to be ignored, but it isn't", filename); g_error ("We expect filename \"%s\" to be ignored, but it isn't", filename);
else else
g_error ("We expect filename \"%s\" not to be ignored, but it is", filename); g_error ("We expect filename \"%s\" not to be ignored, but it is", filename);
} }
esc = nm_keyfile_plugin_utils_escape_filename (filename); esc = nms_keyfile_utils_escape_filename (filename);
g_assert (esc && esc[0]); g_assert (esc && esc[0]);
g_assert (!strchr (esc, '/')); g_assert (!strchr (esc, '/'));
if (nm_keyfile_plugin_utils_should_ignore_file (esc)) if (nms_keyfile_utils_should_ignore_file (esc))
g_error ("Escaping filename \"%s\" yielded \"%s\", but this is ignored", filename, esc); g_error ("Escaping filename \"%s\" yielded \"%s\", but this is ignored", filename, esc);
} }

View File

@@ -1,42 +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 2010 Red Hat, Inc.
*/
#ifndef _UTILS_H_
#define _UTILS_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) ((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))
#define NM_KEYFILE_CONNECTION_LOG_FMTD "%s (%s,\"%s\",%p)"
#define NM_KEYFILE_CONNECTION_LOG_ARGD(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)), (con)
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_ */