mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-02-06 00:00:30 +01:00
keyfile: be chattier, especially about parsing errors
This should help people debug issues with keyfile not recognizing files since it'll actually print out something when it fails to parse stuff. Also logs changes, new connections, and deletions.
This commit is contained in:
parent
a33c3330be
commit
c40d79ae97
7 changed files with 243 additions and 188 deletions
|
|
@ -23,7 +23,8 @@ libnm_settings_plugin_keyfile_la_CPPFLAGS = \
|
|||
$(DBUS_CFLAGS) \
|
||||
-DSYSCONFDIR=\"$(sysconfdir)\" \
|
||||
-DG_DISABLE_DEPRECATED \
|
||||
-DKEYFILE_DIR=\""$(keyfiledir)"\"
|
||||
-DKEYFILE_DIR=\""$(keyfiledir)"\" \
|
||||
-DKEYFILE_PLUGIN_NAME=\""keyfile"\"
|
||||
|
||||
libnm_settings_plugin_keyfile_la_LDFLAGS = -module -avoid-version
|
||||
libnm_settings_plugin_keyfile_la_LIBADD = \
|
||||
|
|
|
|||
|
|
@ -40,6 +40,7 @@
|
|||
#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"
|
||||
|
|
@ -986,108 +987,126 @@ read_vpn_secrets (GKeyFile *file, NMSettingVPN *s_vpn)
|
|||
}
|
||||
|
||||
NMConnection *
|
||||
connection_from_file (const char *filename)
|
||||
connection_from_file (const char *filename, GError **error)
|
||||
{
|
||||
GKeyFile *key_file;
|
||||
struct stat statbuf;
|
||||
gboolean bad_owner, bad_permissions;
|
||||
NMConnection *connection = NULL;
|
||||
GError *err = NULL;
|
||||
NMSettingConnection *s_con;
|
||||
NMSettingBluetooth *s_bt;
|
||||
NMSetting *setting;
|
||||
gchar **groups;
|
||||
gsize length;
|
||||
int i;
|
||||
gboolean vpn_secrets = FALSE;
|
||||
const char *ctype, *tmp;
|
||||
GError *verify_error = NULL;
|
||||
|
||||
if (stat (filename, &statbuf) != 0 || !S_ISREG (statbuf.st_mode))
|
||||
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,
|
||||
"File did not exist or was not a regular file");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
bad_owner = getuid () != statbuf.st_uid;
|
||||
bad_permissions = statbuf.st_mode & 0077;
|
||||
|
||||
if (bad_owner || bad_permissions) {
|
||||
g_warning ("Ignoring insecure configuration file '%s'", filename);
|
||||
g_set_error (error,
|
||||
NM_SETTINGS_INTERFACE_ERROR,
|
||||
NM_SETTINGS_INTERFACE_ERROR_INTERNAL_ERROR,
|
||||
"File permissions (%o) or owner (%d) were insecure",
|
||||
statbuf.st_mode, statbuf.st_uid);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
key_file = g_key_file_new ();
|
||||
if (g_key_file_load_from_file (key_file, filename, G_KEY_FILE_NONE, &err)) {
|
||||
NMSettingConnection *s_con;
|
||||
NMSettingBluetooth *s_bt;
|
||||
NMSetting *setting;
|
||||
gchar **groups;
|
||||
gsize length;
|
||||
int i;
|
||||
gboolean vpn_secrets = FALSE;
|
||||
const char *ctype, *tmp;
|
||||
if (!g_key_file_load_from_file (key_file, filename, G_KEY_FILE_NONE, error))
|
||||
goto out;
|
||||
|
||||
connection = nm_connection_new ();
|
||||
connection = nm_connection_new ();
|
||||
|
||||
groups = g_key_file_get_groups (key_file, &length);
|
||||
for (i = 0; i < length; i++) {
|
||||
/* Only read out secrets when needed */
|
||||
if (!strcmp (groups[i], VPN_SECRETS_GROUP)) {
|
||||
vpn_secrets = TRUE;
|
||||
continue;
|
||||
}
|
||||
|
||||
setting = read_setting (key_file, groups[i]);
|
||||
if (setting)
|
||||
nm_connection_add_setting (connection, setting);
|
||||
groups = g_key_file_get_groups (key_file, &length);
|
||||
for (i = 0; i < length; i++) {
|
||||
/* Only read out secrets when needed */
|
||||
if (!strcmp (groups[i], VPN_SECRETS_GROUP)) {
|
||||
vpn_secrets = TRUE;
|
||||
continue;
|
||||
}
|
||||
|
||||
/* Make sure that we have the base device type setting even if
|
||||
* the keyfile didn't include it, which can happen when the base
|
||||
* device type setting is all default values (like ethernet).
|
||||
*/
|
||||
s_con = (NMSettingConnection *) nm_connection_get_setting (connection, NM_TYPE_SETTING_CONNECTION);
|
||||
if (s_con) {
|
||||
ctype = nm_setting_connection_get_connection_type (s_con);
|
||||
setting = nm_connection_get_setting_by_name (connection, ctype);
|
||||
if (ctype) {
|
||||
gboolean add_serial = FALSE;
|
||||
NMSetting *new_setting = NULL;
|
||||
|
||||
if (!setting && !strcmp (ctype, NM_SETTING_WIRED_SETTING_NAME))
|
||||
new_setting = nm_setting_wired_new ();
|
||||
else if (!strcmp (ctype, NM_SETTING_BLUETOOTH_SETTING_NAME)) {
|
||||
s_bt = (NMSettingBluetooth *) nm_connection_get_setting (connection, NM_TYPE_SETTING_BLUETOOTH);
|
||||
if (s_bt) {
|
||||
tmp = nm_setting_bluetooth_get_connection_type (s_bt);
|
||||
if (tmp && !strcmp (tmp, NM_SETTING_BLUETOOTH_TYPE_DUN))
|
||||
add_serial = TRUE;
|
||||
}
|
||||
} else if (!strcmp (ctype, NM_SETTING_GSM_SETTING_NAME))
|
||||
add_serial = TRUE;
|
||||
else if (!strcmp (ctype, NM_SETTING_CDMA_SETTING_NAME))
|
||||
add_serial = TRUE;
|
||||
|
||||
/* Bluetooth DUN, GSM, and CDMA connections require a serial setting */
|
||||
if (add_serial && !nm_connection_get_setting (connection, NM_TYPE_SETTING_SERIAL))
|
||||
new_setting = nm_setting_serial_new ();
|
||||
|
||||
if (new_setting)
|
||||
nm_connection_add_setting (connection, new_setting);
|
||||
}
|
||||
}
|
||||
|
||||
/* Serial connections require a PPP setting too */
|
||||
if (nm_connection_get_setting (connection, NM_TYPE_SETTING_SERIAL)) {
|
||||
if (!nm_connection_get_setting (connection, NM_TYPE_SETTING_PPP))
|
||||
nm_connection_add_setting (connection, nm_setting_ppp_new ());
|
||||
}
|
||||
|
||||
/* Handle vpn secrets after the 'vpn' setting was read */
|
||||
if (vpn_secrets) {
|
||||
NMSettingVPN *s_vpn;
|
||||
|
||||
s_vpn = (NMSettingVPN *) nm_connection_get_setting (connection, NM_TYPE_SETTING_VPN);
|
||||
if (s_vpn)
|
||||
read_vpn_secrets (key_file, s_vpn);
|
||||
}
|
||||
|
||||
g_strfreev (groups);
|
||||
} else {
|
||||
g_warning ("Error parsing file '%s': %s", filename, err->message);
|
||||
g_error_free (err);
|
||||
setting = read_setting (key_file, groups[i]);
|
||||
if (setting)
|
||||
nm_connection_add_setting (connection, setting);
|
||||
}
|
||||
|
||||
g_key_file_free (key_file);
|
||||
/* Make sure that we have the base device type setting even if
|
||||
* the keyfile didn't include it, which can happen when the base
|
||||
* device type setting is all default values (like ethernet).
|
||||
*/
|
||||
s_con = (NMSettingConnection *) nm_connection_get_setting (connection, NM_TYPE_SETTING_CONNECTION);
|
||||
if (s_con) {
|
||||
ctype = nm_setting_connection_get_connection_type (s_con);
|
||||
setting = nm_connection_get_setting_by_name (connection, ctype);
|
||||
if (ctype) {
|
||||
gboolean add_serial = FALSE;
|
||||
NMSetting *new_setting = NULL;
|
||||
|
||||
if (!setting && !strcmp (ctype, NM_SETTING_WIRED_SETTING_NAME))
|
||||
new_setting = nm_setting_wired_new ();
|
||||
else if (!strcmp (ctype, NM_SETTING_BLUETOOTH_SETTING_NAME)) {
|
||||
s_bt = (NMSettingBluetooth *) nm_connection_get_setting (connection, NM_TYPE_SETTING_BLUETOOTH);
|
||||
if (s_bt) {
|
||||
tmp = nm_setting_bluetooth_get_connection_type (s_bt);
|
||||
if (tmp && !strcmp (tmp, NM_SETTING_BLUETOOTH_TYPE_DUN))
|
||||
add_serial = TRUE;
|
||||
}
|
||||
} else if (!strcmp (ctype, NM_SETTING_GSM_SETTING_NAME))
|
||||
add_serial = TRUE;
|
||||
else if (!strcmp (ctype, NM_SETTING_CDMA_SETTING_NAME))
|
||||
add_serial = TRUE;
|
||||
|
||||
/* Bluetooth DUN, GSM, and CDMA connections require a serial setting */
|
||||
if (add_serial && !nm_connection_get_setting (connection, NM_TYPE_SETTING_SERIAL))
|
||||
new_setting = nm_setting_serial_new ();
|
||||
|
||||
if (new_setting)
|
||||
nm_connection_add_setting (connection, new_setting);
|
||||
}
|
||||
}
|
||||
|
||||
/* Serial connections require a PPP setting too */
|
||||
if (nm_connection_get_setting (connection, NM_TYPE_SETTING_SERIAL)) {
|
||||
if (!nm_connection_get_setting (connection, NM_TYPE_SETTING_PPP))
|
||||
nm_connection_add_setting (connection, nm_setting_ppp_new ());
|
||||
}
|
||||
|
||||
/* Handle vpn secrets after the 'vpn' setting was read */
|
||||
if (vpn_secrets) {
|
||||
NMSettingVPN *s_vpn;
|
||||
|
||||
s_vpn = (NMSettingVPN *) nm_connection_get_setting (connection, NM_TYPE_SETTING_VPN);
|
||||
if (s_vpn)
|
||||
read_vpn_secrets (key_file, s_vpn);
|
||||
}
|
||||
|
||||
g_strfreev (groups);
|
||||
|
||||
/* Verify the connection */
|
||||
if (!nm_connection_verify (connection, &verify_error)) {
|
||||
g_set_error (error,
|
||||
NM_SETTINGS_INTERFACE_ERROR,
|
||||
NM_SETTINGS_INTERFACE_ERROR_INTERNAL_ERROR,
|
||||
"invalid or missing connection property '%s'",
|
||||
(verify_error && verify_error->message) ? verify_error->message : "(unknown)");
|
||||
g_clear_error (&verify_error);
|
||||
g_object_unref (connection);
|
||||
connection = NULL;
|
||||
}
|
||||
|
||||
out:
|
||||
g_key_file_free (key_file);
|
||||
return connection;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,6 +27,6 @@
|
|||
#include <glib.h>
|
||||
#include <nm-connection.h>
|
||||
|
||||
NMConnection *connection_from_file (const char *filename);
|
||||
NMConnection *connection_from_file (const char *filename, GError **error);
|
||||
|
||||
#endif /* _KEYFILE_PLUGIN_READER_H */
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@
|
|||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Copyright (C) 2008 Novell, Inc.
|
||||
* Copyright (C) 2008 Red Hat, Inc.
|
||||
* Copyright (C) 2008 - 2010 Red Hat, Inc.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
|
|
@ -26,6 +26,7 @@
|
|||
#include <nm-utils.h>
|
||||
#include <nm-settings-connection-interface.h>
|
||||
|
||||
#include "nm-system-config-interface.h"
|
||||
#include "nm-dbus-glib-types.h"
|
||||
#include "nm-keyfile-connection.h"
|
||||
#include "reader.h"
|
||||
|
|
@ -53,13 +54,55 @@ enum {
|
|||
};
|
||||
|
||||
NMKeyfileConnection *
|
||||
nm_keyfile_connection_new (const char *filename)
|
||||
nm_keyfile_connection_new (const char *filename, GError **error)
|
||||
{
|
||||
GObject *object;
|
||||
NMKeyfileConnectionPrivate *priv;
|
||||
NMSettingConnection *s_con;
|
||||
NMConnection *tmp;
|
||||
|
||||
g_return_val_if_fail (filename != NULL, NULL);
|
||||
|
||||
return (NMKeyfileConnection *) g_object_new (NM_TYPE_KEYFILE_CONNECTION,
|
||||
NM_KEYFILE_CONNECTION_FILENAME, filename,
|
||||
NULL);
|
||||
tmp = connection_from_file (filename, error);
|
||||
if (!tmp)
|
||||
return NULL;
|
||||
|
||||
object = (GObject *) g_object_new (NM_TYPE_KEYFILE_CONNECTION,
|
||||
NM_KEYFILE_CONNECTION_FILENAME, filename,
|
||||
NULL);
|
||||
if (!object) {
|
||||
g_object_unref (tmp);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
priv = NM_KEYFILE_CONNECTION_GET_PRIVATE (object);
|
||||
g_assert (priv->filename);
|
||||
|
||||
/* Update our settings with what was read from the file */
|
||||
nm_sysconfig_connection_update (NM_SYSCONFIG_CONNECTION (object), tmp, FALSE, NULL);
|
||||
g_object_unref (tmp);
|
||||
|
||||
/* if for some reason the connection didn't have a UUID, add one */
|
||||
s_con = (NMSettingConnection *) nm_connection_get_setting (NM_CONNECTION (object), NM_TYPE_SETTING_CONNECTION);
|
||||
if (s_con && !nm_setting_connection_get_uuid (s_con)) {
|
||||
GError *write_error = NULL;
|
||||
char *uuid;
|
||||
|
||||
uuid = nm_utils_uuid_generate ();
|
||||
g_object_set (s_con, NM_SETTING_CONNECTION_UUID, uuid, NULL);
|
||||
g_free (uuid);
|
||||
|
||||
if (!write_connection (NM_CONNECTION (object), KEYFILE_DIR, 0, 0, NULL, &write_error)) {
|
||||
PLUGIN_WARN (KEYFILE_PLUGIN_NAME,
|
||||
"Couldn't update connection %s with a UUID: (%d) %s",
|
||||
nm_setting_connection_get_id (s_con),
|
||||
write_error ? write_error->code : -1,
|
||||
(write_error && write_error->message) ? write_error->message : "(unknown)");
|
||||
g_propagate_error (error, write_error);
|
||||
}
|
||||
}
|
||||
|
||||
return NM_KEYFILE_CONNECTION (object);
|
||||
}
|
||||
|
||||
const char *
|
||||
|
|
@ -122,56 +165,6 @@ nm_keyfile_connection_init (NMKeyfileConnection *connection)
|
|||
{
|
||||
}
|
||||
|
||||
static GObject *
|
||||
constructor (GType type,
|
||||
guint n_construct_params,
|
||||
GObjectConstructParam *construct_params)
|
||||
{
|
||||
GObject *object;
|
||||
NMKeyfileConnectionPrivate *priv;
|
||||
NMSettingConnection *s_con;
|
||||
NMConnection *tmp;
|
||||
|
||||
object = G_OBJECT_CLASS (nm_keyfile_connection_parent_class)->constructor (type, n_construct_params, construct_params);
|
||||
|
||||
if (!object)
|
||||
return NULL;
|
||||
|
||||
priv = NM_KEYFILE_CONNECTION_GET_PRIVATE (object);
|
||||
|
||||
g_assert (priv->filename);
|
||||
|
||||
tmp = connection_from_file (priv->filename);
|
||||
if (!tmp) {
|
||||
g_object_unref (object);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
nm_sysconfig_connection_update (NM_SYSCONFIG_CONNECTION (object), tmp, FALSE, NULL);
|
||||
g_object_unref (tmp);
|
||||
|
||||
/* if for some reason the connection didn't have a UUID, add one */
|
||||
s_con = (NMSettingConnection *) nm_connection_get_setting (NM_CONNECTION (object), NM_TYPE_SETTING_CONNECTION);
|
||||
if (s_con && !nm_setting_connection_get_uuid (s_con)) {
|
||||
GError *error = NULL;
|
||||
char *uuid;
|
||||
|
||||
uuid = nm_utils_uuid_generate ();
|
||||
g_object_set (s_con, NM_SETTING_CONNECTION_UUID, uuid, NULL);
|
||||
g_free (uuid);
|
||||
|
||||
if (!write_connection (NM_CONNECTION (object), KEYFILE_DIR, 0, 0, NULL, &error)) {
|
||||
g_warning ("Couldn't update connection %s with a UUID: (%d) %s",
|
||||
nm_setting_connection_get_id (s_con),
|
||||
error ? error->code : 0,
|
||||
(error && error->message) ? error->message : "unknown");
|
||||
g_error_free (error);
|
||||
}
|
||||
}
|
||||
|
||||
return object;
|
||||
}
|
||||
|
||||
static void
|
||||
finalize (GObject *object)
|
||||
{
|
||||
|
|
@ -225,7 +218,6 @@ nm_keyfile_connection_class_init (NMKeyfileConnectionClass *keyfile_connection_c
|
|||
g_type_class_add_private (keyfile_connection_class, sizeof (NMKeyfileConnectionPrivate));
|
||||
|
||||
/* Virtual methods */
|
||||
object_class->constructor = constructor;
|
||||
object_class->set_property = set_property;
|
||||
object_class->get_property = get_property;
|
||||
object_class->finalize = finalize;
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ typedef struct {
|
|||
|
||||
GType nm_keyfile_connection_get_type (void);
|
||||
|
||||
NMKeyfileConnection *nm_keyfile_connection_new (const char *filename);
|
||||
NMKeyfileConnection *nm_keyfile_connection_new (const char *filename, GError **error);
|
||||
|
||||
const char *nm_keyfile_connection_get_filename (NMKeyfileConnection *self);
|
||||
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@
|
|||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Copyright (C) 2008 Novell, Inc.
|
||||
* Copyright (C) 2008 Red Hat, Inc.
|
||||
* Copyright (C) 2008 - 2010 Red Hat, Inc.
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
|
|
@ -40,7 +40,7 @@
|
|||
#include "writer.h"
|
||||
|
||||
#define KEYFILE_PLUGIN_NAME "keyfile"
|
||||
#define KEYFILE_PLUGIN_INFO "(c) 2007 - 2008 Red Hat, Inc. To report bugs please use the NetworkManager mailing list."
|
||||
#define KEYFILE_PLUGIN_INFO "(c) 2007 - 2010 Red Hat, Inc. To report bugs please use the NetworkManager mailing list."
|
||||
|
||||
#define CONF_FILE SYSCONFDIR "/NetworkManager/NetworkManager.conf"
|
||||
#define OLD_CONF_FILE SYSCONFDIR "/NetworkManager/nm-system-settings.conf"
|
||||
|
|
@ -74,31 +74,49 @@ read_connections (NMSystemConfigInterface *config)
|
|||
{
|
||||
SCPluginKeyfilePrivate *priv = SC_PLUGIN_KEYFILE_GET_PRIVATE (config);
|
||||
GDir *dir;
|
||||
GError *err = NULL;
|
||||
GError *error = NULL;
|
||||
const char *item;
|
||||
|
||||
dir = g_dir_open (KEYFILE_DIR, 0, &err);
|
||||
if (dir) {
|
||||
const char *item;
|
||||
|
||||
while ((item = g_dir_read_name (dir))) {
|
||||
NMKeyfileConnection *connection;
|
||||
char *full_path;
|
||||
|
||||
full_path = g_build_filename (KEYFILE_DIR, item, NULL);
|
||||
connection = nm_keyfile_connection_new (full_path);
|
||||
if (connection) {
|
||||
g_hash_table_insert (priv->hash,
|
||||
(gpointer) nm_keyfile_connection_get_filename (connection),
|
||||
connection);
|
||||
}
|
||||
g_free (full_path);
|
||||
}
|
||||
|
||||
g_dir_close (dir);
|
||||
} else {
|
||||
g_warning ("Can not read directory '%s': %s", KEYFILE_DIR, err->message);
|
||||
g_error_free (err);
|
||||
dir = g_dir_open (KEYFILE_DIR, 0, &error);
|
||||
if (!dir) {
|
||||
PLUGIN_WARN (KEYFILE_PLUGIN_NAME, "Cannot read directory '%s': (%d) %s",
|
||||
KEYFILE_DIR,
|
||||
error ? error->code : -1,
|
||||
error && error->message ? error->message : "(unknown)");
|
||||
g_clear_error (&error);
|
||||
return;
|
||||
}
|
||||
|
||||
while ((item = g_dir_read_name (dir))) {
|
||||
NMKeyfileConnection *connection;
|
||||
char *full_path;
|
||||
|
||||
full_path = g_build_filename (KEYFILE_DIR, item, NULL);
|
||||
PLUGIN_PRINT (KEYFILE_PLUGIN_NAME, "parsing %s ... ", item);
|
||||
connection = nm_keyfile_connection_new (full_path, &error);
|
||||
if (connection) {
|
||||
NMSettingConnection *s_con;
|
||||
const char *cid;
|
||||
|
||||
s_con = (NMSettingConnection *) nm_connection_get_setting (NM_CONNECTION (connection), NM_TYPE_SETTING_CONNECTION);
|
||||
g_assert (s_con);
|
||||
|
||||
cid = nm_setting_connection_get_id (s_con);
|
||||
g_assert (cid);
|
||||
|
||||
g_hash_table_insert (priv->hash,
|
||||
(gpointer) nm_keyfile_connection_get_filename (connection),
|
||||
connection);
|
||||
|
||||
PLUGIN_PRINT (KEYFILE_PLUGIN_NAME, " read connection '%s'", cid);
|
||||
} else {
|
||||
PLUGIN_PRINT (KEYFILE_PLUGIN_NAME, " error: %s",
|
||||
(error && error->message) ? error->message : "(unknown)");
|
||||
g_clear_error (&error);
|
||||
}
|
||||
g_free (full_path);
|
||||
}
|
||||
g_dir_close (dir);
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
|
|
@ -147,17 +165,33 @@ update_connection_settings (NMKeyfileConnection *orig,
|
|||
|
||||
/* Monitoring */
|
||||
|
||||
static void
|
||||
remove_connection (SCPluginKeyfile *self,
|
||||
NMKeyfileConnection *connection,
|
||||
const char *name)
|
||||
{
|
||||
g_return_if_fail (connection != NULL);
|
||||
g_return_if_fail (name != NULL);
|
||||
|
||||
/* Removing from the hash table should drop the last reference */
|
||||
g_object_ref (connection);
|
||||
g_hash_table_remove (SC_PLUGIN_KEYFILE_GET_PRIVATE (self)->hash, name);
|
||||
g_signal_emit_by_name (connection, "removed");
|
||||
g_object_unref (connection);
|
||||
}
|
||||
|
||||
static void
|
||||
dir_changed (GFileMonitor *monitor,
|
||||
GFile *file,
|
||||
GFile *other_file,
|
||||
GFileMonitorEvent event_type,
|
||||
gpointer user_data)
|
||||
GFile *file,
|
||||
GFile *other_file,
|
||||
GFileMonitorEvent event_type,
|
||||
gpointer user_data)
|
||||
{
|
||||
NMSystemConfigInterface *config = NM_SYSTEM_CONFIG_INTERFACE (user_data);
|
||||
SCPluginKeyfilePrivate *priv = SC_PLUGIN_KEYFILE_GET_PRIVATE (config);
|
||||
char *name;
|
||||
NMKeyfileConnection *connection;
|
||||
GError *error = NULL;
|
||||
|
||||
name = g_file_get_path (file);
|
||||
connection = g_hash_table_lookup (priv->hash, name);
|
||||
|
|
@ -165,27 +199,32 @@ dir_changed (GFileMonitor *monitor,
|
|||
switch (event_type) {
|
||||
case G_FILE_MONITOR_EVENT_DELETED:
|
||||
if (connection) {
|
||||
/* Removing from the hash table should drop the last reference */
|
||||
g_object_ref (connection);
|
||||
g_hash_table_remove (priv->hash, name);
|
||||
g_signal_emit_by_name (connection, "removed");
|
||||
g_object_unref (connection);
|
||||
PLUGIN_PRINT (KEYFILE_PLUGIN_NAME, "removed %s.", name);
|
||||
remove_connection (SC_PLUGIN_KEYFILE (config), connection, name);
|
||||
}
|
||||
break;
|
||||
case G_FILE_MONITOR_EVENT_CREATED:
|
||||
case G_FILE_MONITOR_EVENT_CHANGES_DONE_HINT:
|
||||
PLUGIN_PRINT (KEYFILE_PLUGIN_NAME, "updating %s", name);
|
||||
|
||||
if (connection) {
|
||||
/* Update */
|
||||
NMKeyfileConnection *tmp;
|
||||
|
||||
tmp = (NMKeyfileConnection *) nm_keyfile_connection_new (name);
|
||||
tmp = nm_keyfile_connection_new (name, &error);
|
||||
if (tmp) {
|
||||
update_connection_settings (connection, tmp);
|
||||
g_object_unref (tmp);
|
||||
} else {
|
||||
/* Error; remove the connection */
|
||||
PLUGIN_PRINT (KEYFILE_PLUGIN_NAME, " error: %s",
|
||||
(error && error->message) ? error->message : "(unknown)");
|
||||
g_clear_error (&error);
|
||||
remove_connection (SC_PLUGIN_KEYFILE (config), connection, name);
|
||||
}
|
||||
} else {
|
||||
/* New */
|
||||
connection = nm_keyfile_connection_new (name);
|
||||
connection = nm_keyfile_connection_new (name, &error);
|
||||
if (connection) {
|
||||
NMSettingConnection *s_con;
|
||||
const char *connection_uuid;
|
||||
|
|
@ -234,6 +273,10 @@ dir_changed (GFileMonitor *monitor,
|
|||
connection);
|
||||
g_signal_emit_by_name (config, NM_SYSTEM_CONFIG_INTERFACE_CONNECTION_ADDED, connection);
|
||||
}
|
||||
} else {
|
||||
PLUGIN_PRINT (KEYFILE_PLUGIN_NAME, " error: %s",
|
||||
(error && error->message) ? error->message : "(unknown)");
|
||||
g_clear_error (&error);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
|
|
|||
|
|
@ -85,7 +85,7 @@ test_read_valid_wired_connection (void)
|
|||
NMIP6Address *ip6_addr;
|
||||
NMIP6Route *ip6_route;
|
||||
|
||||
connection = connection_from_file (TEST_WIRED_FILE);
|
||||
connection = connection_from_file (TEST_WIRED_FILE, NULL);
|
||||
ASSERT (connection != NULL,
|
||||
"connection-read", "failed to read %s", TEST_WIRED_FILE);
|
||||
|
||||
|
|
@ -587,7 +587,7 @@ test_write_wired_connection (void)
|
|||
const char *address2_gw = "1.2.1.1";
|
||||
const char *route1 = "10.10.10.2";
|
||||
const char *route1_nh = "10.10.10.1";
|
||||
const char *route2 = "0.0.0.0";
|
||||
const char *route2 = "1.1.1.1";
|
||||
const char *route2_nh = "1.2.1.1";
|
||||
const char *dns6_1 = "1::cafe";
|
||||
const char *dns6_2 = "2::cafe";
|
||||
|
|
@ -595,7 +595,7 @@ test_write_wired_connection (void)
|
|||
const char *address6_2 = "dcba::beef";
|
||||
const char *route6_1 = "1:2:3:4:5:6:7:8";
|
||||
const char *route6_1_nh = "8:7:6:5:4:3:2:1";
|
||||
const char *route6_2 = "::";
|
||||
const char *route6_2 = "2001::1000";
|
||||
const char *route6_2_nh = "2001::1111";
|
||||
guint64 timestamp = 0x12345678L;
|
||||
|
||||
|
|
@ -704,7 +704,7 @@ test_write_wired_connection (void)
|
|||
"connection-write", "didn't get keyfile name back after writing connection");
|
||||
|
||||
/* Read the connection back in and compare it to the one we just wrote out */
|
||||
reread = connection_from_file (testfile);
|
||||
reread = connection_from_file (testfile, NULL);
|
||||
ASSERT (reread != NULL, "connection-write", "failed to re-read test connection");
|
||||
|
||||
ASSERT (nm_connection_compare (connection, reread, NM_SETTING_COMPARE_FLAG_EXACT) == TRUE,
|
||||
|
|
@ -737,7 +737,7 @@ test_read_ip6_wired_connection (void)
|
|||
const char *expected6_gw1 = "abcd:1234:ffff::cdd1";
|
||||
NMIP6Address *ip6_addr;
|
||||
|
||||
connection = connection_from_file (TEST_WIRED_IP6_FILE);
|
||||
connection = connection_from_file (TEST_WIRED_IP6_FILE, NULL);
|
||||
ASSERT (connection != NULL,
|
||||
"connection-read", "failed to read %s", TEST_WIRED_IP6_FILE);
|
||||
|
||||
|
|
@ -964,7 +964,7 @@ test_write_ip6_wired_connection (void)
|
|||
"connection-write", "didn't get keyfile name back after writing connection");
|
||||
|
||||
/* Read the connection back in and compare it to the one we just wrote out */
|
||||
reread = connection_from_file (testfile);
|
||||
reread = connection_from_file (testfile, NULL);
|
||||
ASSERT (reread != NULL, "connection-write", "failed to re-read test connection");
|
||||
|
||||
ASSERT (nm_connection_compare (connection, reread, NM_SETTING_COMPARE_FLAG_EXACT) == TRUE,
|
||||
|
|
@ -993,7 +993,7 @@ test_read_wired_mac_case (void)
|
|||
const char *expected_id = "Test Wired Connection MAC Case";
|
||||
const char *expected_uuid = "4e80a56d-c99f-4aad-a6dd-b449bc398c57";
|
||||
|
||||
connection = connection_from_file (TEST_WIRED_MAC_CASE_FILE);
|
||||
connection = connection_from_file (TEST_WIRED_MAC_CASE_FILE, NULL);
|
||||
ASSERT (connection != NULL,
|
||||
"connection-read", "failed to read %s", TEST_WIRED_MAC_CASE_FILE);
|
||||
|
||||
|
|
@ -1079,7 +1079,7 @@ test_read_valid_wireless_connection (void)
|
|||
const guint64 expected_timestamp = 1226604314;
|
||||
guint64 timestamp;
|
||||
|
||||
connection = connection_from_file (TEST_WIRELESS_FILE);
|
||||
connection = connection_from_file (TEST_WIRELESS_FILE, NULL);
|
||||
ASSERT (connection != NULL,
|
||||
"connection-read", "failed to read %s", TEST_WIRELESS_FILE);
|
||||
|
||||
|
|
@ -1282,7 +1282,7 @@ test_write_wireless_connection (void)
|
|||
"connection-write", "didn't get keyfile name back after writing connection");
|
||||
|
||||
/* Read the connection back in and compare it to the one we just wrote out */
|
||||
reread = connection_from_file (testfile);
|
||||
reread = connection_from_file (testfile, NULL);
|
||||
ASSERT (reread != NULL, "connection-write", "failed to re-read test connection");
|
||||
|
||||
ASSERT (nm_connection_compare (connection, reread, NM_SETTING_COMPARE_FLAG_EXACT) == TRUE,
|
||||
|
|
@ -1317,7 +1317,7 @@ test_read_bt_dun_connection (void)
|
|||
const char *expected_username = "ISP@CINGULARGPRS.COM";
|
||||
const char *expected_password = "CINGULAR1";
|
||||
|
||||
connection = connection_from_file (TEST_BT_DUN_FILE);
|
||||
connection = connection_from_file (TEST_BT_DUN_FILE, NULL);
|
||||
ASSERT (connection != NULL,
|
||||
"connection-read", "failed to read %s", TEST_BT_DUN_FILE);
|
||||
|
||||
|
|
@ -1567,7 +1567,7 @@ test_write_bt_dun_connection (void)
|
|||
"connection-write", "didn't get keyfile name back after writing connection");
|
||||
|
||||
/* Read the connection back in and compare it to the one we just wrote out */
|
||||
reread = connection_from_file (testfile);
|
||||
reread = connection_from_file (testfile, NULL);
|
||||
ASSERT (reread != NULL, "connection-write", "failed to re-read test connection");
|
||||
|
||||
ASSERT (nm_connection_compare (connection, reread, NM_SETTING_COMPARE_FLAG_EXACT) == TRUE,
|
||||
|
|
@ -1601,7 +1601,7 @@ test_read_gsm_connection (void)
|
|||
const char *expected_network_id = "24005";
|
||||
const char *expected_pin = "2345";
|
||||
|
||||
connection = connection_from_file (TEST_GSM_FILE);
|
||||
connection = connection_from_file (TEST_GSM_FILE, NULL);
|
||||
ASSERT (connection != NULL,
|
||||
"connection-read", "failed to read %s", TEST_GSM_FILE);
|
||||
|
||||
|
|
@ -1829,7 +1829,7 @@ test_write_gsm_connection (void)
|
|||
"connection-write", "didn't get keyfile name back after writing connection");
|
||||
|
||||
/* Read the connection back in and compare it to the one we just wrote out */
|
||||
reread = connection_from_file (testfile);
|
||||
reread = connection_from_file (testfile, NULL);
|
||||
ASSERT (reread != NULL, "connection-write", "failed to re-read test connection");
|
||||
|
||||
ASSERT (nm_connection_compare (connection, reread, NM_SETTING_COMPARE_FLAG_EXACT) == TRUE,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue