keyfile: clean up directory structure

The IO library was in io/ because I was too lazy to find autotools'
SUBDIRS rules at the time and that you could use '.' for the current
directory.  Fix that and use its own error defines instead of
the system settings service.  Clean up a for more things for good
measure too (like KEYFILE_DIR, etc).
This commit is contained in:
Dan Williams
2010-09-16 17:39:06 -05:00
parent c40d79ae97
commit 7f4a7a62c4
12 changed files with 105 additions and 55 deletions

View File

@@ -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

View File

@@ -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) \

View File

@@ -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 <glib.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."
#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__ */

View File

@@ -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 <glib.h>
#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;
}

View File

@@ -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)

View File

@@ -31,6 +31,7 @@
#include "nm-keyfile-connection.h"
#include "reader.h"
#include "writer.h"
#include "common.h"
static NMSettingsConnectionInterface *parent_settings_connection_iface;

View File

@@ -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"

View File

@@ -40,10 +40,10 @@
#include <arpa/inet.h>
#include <netinet/ether.h>
#include <string.h>
#include <nm-settings-interface.h>
#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);

View File

@@ -22,8 +22,6 @@
#ifndef _KEYFILE_PLUGIN_READER_H
#define _KEYFILE_PLUGIN_READER_H
#define VPN_SECRETS_GROUP "vpn-secrets"
#include <glib.h>
#include <nm-connection.h>

View File

@@ -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)

View File

@@ -36,11 +36,10 @@
#include <string.h>
#include <arpa/inet.h>
#include <netinet/ether.h>
#include <nm-settings-interface.h>
#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);