diff --git a/configure.ac b/configure.ac index ac391c603..db2881578 100644 --- a/configure.ac +++ b/configure.ac @@ -521,7 +521,6 @@ system-settings/plugins/ifcfg-rh/tests/Makefile system-settings/plugins/ifcfg-rh/tests/network-scripts/Makefile system-settings/plugins/ifcfg-suse/Makefile system-settings/plugins/keyfile/Makefile -system-settings/plugins/keyfile/io/Makefile system-settings/plugins/keyfile/tests/Makefile system-settings/plugins/keyfile/tests/keyfiles/Makefile cli/Makefile diff --git a/system-settings/plugins/keyfile/Makefile.am b/system-settings/plugins/keyfile/Makefile.am index a49b51b2c..1c1fd4a7d 100644 --- a/system-settings/plugins/keyfile/Makefile.am +++ b/system-settings/plugins/keyfile/Makefile.am @@ -1,36 +1,49 @@ -SUBDIRS=io tests +SUBDIRS=. tests INCLUDES = \ -I$(top_srcdir)/src/system-settings \ -I$(top_srcdir)/include \ -I$(top_srcdir)/libnm-util \ - -I$(top_srcdir)/libnm-glib \ - -I$(top_srcdir)/system-settings/plugins/keyfile/io + -I$(top_srcdir)/libnm-glib pkglib_LTLIBRARIES = libnm-settings-plugin-keyfile.la +noinst_LTLIBRARIES = libkeyfile-io.la + +libkeyfile_io_la_SOURCES = \ + reader.c \ + reader.h \ + writer.c \ + writer.h \ + errors.c \ + common.h + +libkeyfile_io_la_CPPFLAGS = \ + $(GLIB_CFLAGS) \ + $(DBUS_CFLAGS) \ + -DSYSCONFDIR=\"$(sysconfdir)\" \ + -DG_DISABLE_DEPRECATED + +libkeyfile_io_la_LIBADD = $(GLIB_LIBS) + libnm_settings_plugin_keyfile_la_SOURCES = \ nm-keyfile-connection.c \ nm-keyfile-connection.h \ plugin.c \ plugin.h -keyfiledir=$(sysconfdir)/NetworkManager/system-connections - libnm_settings_plugin_keyfile_la_CPPFLAGS = \ $(GLIB_CFLAGS) \ $(GMODULE_CFLAGS) \ $(DBUS_CFLAGS) \ -DSYSCONFDIR=\"$(sysconfdir)\" \ - -DG_DISABLE_DEPRECATED \ - -DKEYFILE_DIR=\""$(keyfiledir)"\" \ - -DKEYFILE_PLUGIN_NAME=\""keyfile"\" + -DG_DISABLE_DEPRECATED libnm_settings_plugin_keyfile_la_LDFLAGS = -module -avoid-version libnm_settings_plugin_keyfile_la_LIBADD = \ $(top_builddir)/libnm-util/libnm-util.la \ $(top_builddir)/libnm-glib/libnm-glib.la \ - $(top_builddir)/system-settings/plugins/keyfile/io/libkeyfile-io.la \ + libkeyfile-io.la \ $(GLIB_LIBS) \ $(GMODULE_LIBS) \ $(DBUS_LIBS) \ diff --git a/system-settings/plugins/keyfile/common.h b/system-settings/plugins/keyfile/common.h new file mode 100644 index 000000000..7d94a7053 --- /dev/null +++ b/system-settings/plugins/keyfile/common.h @@ -0,0 +1,37 @@ +/* -*- 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 - 2010 Red Hat, Inc. + */ + +#ifndef __COMMON_H__ +#define __COMMON_H__ + +#include + +#define KEYFILE_PLUGIN_NAME "keyfile" +#define KEYFILE_PLUGIN_INFO "(c) 2007 - 2010 Red Hat, Inc. To report bugs please use the NetworkManager mailing list." + +#define KEYFILE_DIR SYSCONFDIR "/NetworkManager/system-connections" + +#define VPN_SECRETS_GROUP "vpn-secrets" + +#define KEYFILE_PLUGIN_ERROR (keyfile_plugin_error_quark ()) +GQuark keyfile_plugin_error_quark (void); + +#endif /* __COMMON_H__ */ + diff --git a/system-settings/plugins/keyfile/errors.c b/system-settings/plugins/keyfile/errors.c new file mode 100644 index 000000000..e2e97690f --- /dev/null +++ b/system-settings/plugins/keyfile/errors.c @@ -0,0 +1,35 @@ +/* -*- 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 - 2010 Red Hat, Inc. + */ + +#include +#include "common.h" + +GQuark +keyfile_plugin_error_quark (void) +{ + static GQuark error_quark = 0; + + if (G_UNLIKELY (error_quark == 0)) + error_quark = g_quark_from_static_string ("keyfile-plugin-error-quark"); + + return error_quark; +} + + diff --git a/system-settings/plugins/keyfile/io/Makefile.am b/system-settings/plugins/keyfile/io/Makefile.am deleted file mode 100644 index 9333c5097..000000000 --- a/system-settings/plugins/keyfile/io/Makefile.am +++ /dev/null @@ -1,20 +0,0 @@ -INCLUDES = \ - -I$(top_srcdir)/system-settings/src \ - -I$(top_srcdir)/include \ - -I$(top_srcdir)/libnm-util \ - -I$(top_srcdir)/libnm-glib - -noinst_LTLIBRARIES = libkeyfile-io.la - -libkeyfile_io_la_SOURCES = \ - reader.h \ - reader.c \ - writer.h \ - writer.c - -libkeyfile_io_la_CPPFLAGS = \ - $(GLIB_CFLAGS) \ - $(DBUS_CFLAGS) - -libkeyfile_io_la_LIBADD = $(GLIB_LIBS) - diff --git a/system-settings/plugins/keyfile/nm-keyfile-connection.c b/system-settings/plugins/keyfile/nm-keyfile-connection.c index 2d234fd5d..3c27a54c7 100644 --- a/system-settings/plugins/keyfile/nm-keyfile-connection.c +++ b/system-settings/plugins/keyfile/nm-keyfile-connection.c @@ -31,6 +31,7 @@ #include "nm-keyfile-connection.h" #include "reader.h" #include "writer.h" +#include "common.h" static NMSettingsConnectionInterface *parent_settings_connection_iface; diff --git a/system-settings/plugins/keyfile/plugin.c b/system-settings/plugins/keyfile/plugin.c index f48edbeb4..27ae0a06f 100644 --- a/system-settings/plugins/keyfile/plugin.c +++ b/system-settings/plugins/keyfile/plugin.c @@ -38,9 +38,7 @@ #include "nm-system-config-interface.h" #include "nm-keyfile-connection.h" #include "writer.h" - -#define KEYFILE_PLUGIN_NAME "keyfile" -#define KEYFILE_PLUGIN_INFO "(c) 2007 - 2010 Red Hat, Inc. To report bugs please use the NetworkManager mailing list." +#include "common.h" #define CONF_FILE SYSCONFDIR "/NetworkManager/NetworkManager.conf" #define OLD_CONF_FILE SYSCONFDIR "/NetworkManager/nm-system-settings.conf" diff --git a/system-settings/plugins/keyfile/io/reader.c b/system-settings/plugins/keyfile/reader.c similarity index 98% rename from system-settings/plugins/keyfile/io/reader.c rename to system-settings/plugins/keyfile/reader.c index 55ef12706..8a81df0df 100644 --- a/system-settings/plugins/keyfile/io/reader.c +++ b/system-settings/plugins/keyfile/reader.c @@ -40,10 +40,10 @@ #include #include #include -#include #include "nm-dbus-glib-types.h" #include "reader.h" +#include "common.h" static gboolean read_array_of_uint (GKeyFile *file, @@ -1004,9 +1004,7 @@ connection_from_file (const char *filename, GError **error) GError *verify_error = NULL; if (stat (filename, &statbuf) != 0 || !S_ISREG (statbuf.st_mode)) { - g_set_error_literal (error, - NM_SETTINGS_INTERFACE_ERROR, - NM_SETTINGS_INTERFACE_ERROR_INTERNAL_ERROR, + g_set_error_literal (error, KEYFILE_PLUGIN_ERROR, 0, "File did not exist or was not a regular file"); return NULL; } @@ -1015,9 +1013,7 @@ connection_from_file (const char *filename, GError **error) bad_permissions = statbuf.st_mode & 0077; if (bad_owner || bad_permissions) { - g_set_error (error, - NM_SETTINGS_INTERFACE_ERROR, - NM_SETTINGS_INTERFACE_ERROR_INTERNAL_ERROR, + g_set_error (error, KEYFILE_PLUGIN_ERROR, 0, "File permissions (%o) or owner (%d) were insecure", statbuf.st_mode, statbuf.st_uid); return NULL; @@ -1096,9 +1092,7 @@ connection_from_file (const char *filename, GError **error) /* Verify the connection */ if (!nm_connection_verify (connection, &verify_error)) { - g_set_error (error, - NM_SETTINGS_INTERFACE_ERROR, - NM_SETTINGS_INTERFACE_ERROR_INTERNAL_ERROR, + g_set_error (error, KEYFILE_PLUGIN_ERROR, 0, "invalid or missing connection property '%s'", (verify_error && verify_error->message) ? verify_error->message : "(unknown)"); g_clear_error (&verify_error); diff --git a/system-settings/plugins/keyfile/io/reader.h b/system-settings/plugins/keyfile/reader.h similarity index 96% rename from system-settings/plugins/keyfile/io/reader.h rename to system-settings/plugins/keyfile/reader.h index 0982c8704..357271549 100644 --- a/system-settings/plugins/keyfile/io/reader.h +++ b/system-settings/plugins/keyfile/reader.h @@ -22,8 +22,6 @@ #ifndef _KEYFILE_PLUGIN_READER_H #define _KEYFILE_PLUGIN_READER_H -#define VPN_SECRETS_GROUP "vpn-secrets" - #include #include diff --git a/system-settings/plugins/keyfile/tests/Makefile.am b/system-settings/plugins/keyfile/tests/Makefile.am index a0af14b26..af7666786 100644 --- a/system-settings/plugins/keyfile/tests/Makefile.am +++ b/system-settings/plugins/keyfile/tests/Makefile.am @@ -4,7 +4,7 @@ INCLUDES = \ -I$(top_srcdir)/include \ -I$(top_srcdir)/libnm-util \ -I$(top_srcdir)/libnm-glib \ - -I$(top_srcdir)/system-settings/plugins/keyfile/io + -I$(top_srcdir)/system-settings/plugins/keyfile noinst_PROGRAMS = test-keyfile @@ -18,7 +18,7 @@ test_keyfile_CPPFLAGS = \ -DTEST_SCRATCH_DIR=\"$(abs_builddir)/keyfiles\" test_keyfile_LDADD = \ - $(top_builddir)/system-settings/plugins/keyfile/io/libkeyfile-io.la \ + $(top_builddir)/system-settings/plugins/keyfile/libkeyfile-io.la \ $(top_builddir)/libnm-glib/libnm-glib.la \ $(top_builddir)/libnm-util/libnm-util.la \ $(DBUS_LIBS) diff --git a/system-settings/plugins/keyfile/io/writer.c b/system-settings/plugins/keyfile/writer.c similarity index 98% rename from system-settings/plugins/keyfile/io/writer.c rename to system-settings/plugins/keyfile/writer.c index 7bba71e68..13dfb1793 100644 --- a/system-settings/plugins/keyfile/io/writer.c +++ b/system-settings/plugins/keyfile/writer.c @@ -36,11 +36,10 @@ #include #include #include -#include #include "nm-dbus-glib-types.h" #include "writer.h" -#include "reader.h" +#include "common.h" static gboolean write_array_of_uint (GKeyFile *file, @@ -667,18 +666,14 @@ write_connection (NMConnection *connection, g_file_set_contents (path, data, len, error); if (chown (path, owner_uid, owner_grp) < 0) { - g_set_error (error, - NM_SETTINGS_INTERFACE_ERROR, - NM_SETTINGS_INTERFACE_ERROR_INTERNAL_ERROR, + g_set_error (error, KEYFILE_PLUGIN_ERROR, 0, "%s.%d: error chowning '%s': %d", __FILE__, __LINE__, path, errno); unlink (path); } else { err = chmod (path, S_IRUSR | S_IWUSR); if (err) { - g_set_error (error, - NM_SETTINGS_INTERFACE_ERROR, - NM_SETTINGS_INTERFACE_ERROR_INTERNAL_ERROR, + g_set_error (error, KEYFILE_PLUGIN_ERROR, 0, "%s.%d: error setting permissions on '%s': %d", __FILE__, __LINE__, path, errno); unlink (path); diff --git a/system-settings/plugins/keyfile/io/writer.h b/system-settings/plugins/keyfile/writer.h similarity index 100% rename from system-settings/plugins/keyfile/io/writer.h rename to system-settings/plugins/keyfile/writer.h