diff --git a/ChangeLog b/ChangeLog index f89e6ea79..eb7e524dd 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,25 @@ +2008-11-03 Dan Williams + + * system-settings/src/main.c + - (add_default_dhcp_connection): make the fallback connection read-only + + * libnm-glib/nm-settings.c + libnm-glib/nm-settings.h + - Add detailed errors + - (impl_exported_connection_update, impl_exported_connection_delete): + return an error if the connection is read-only + + * system-settings/plugins/ifupdown/nm-ifupdown-connection.c + system-settings/plugins/keyfile/nm-keyfile-connection.c + system-settings/src/main.c + - Use more detailed errors + + * system-settings/src/nm-system-config-error.c + system-settings/src/nm-system-config-error.h + system-settings/src/dbus-settings.c + - Remove NM_SYSCONFIG_SETTINGS_ERROR_INVALID_CONNECTION, replaced by + NM_SETTINGS_ERROR_INVALID_CONNECTION + 2008-11-02 Dan Williams * Add license headers to everything in src/ diff --git a/libnm-glib/nm-settings.c b/libnm-glib/nm-settings.c index 482a988aa..da34f0dd3 100644 --- a/libnm-glib/nm-settings.c +++ b/libnm-glib/nm-settings.c @@ -7,6 +7,8 @@ #include "nm-dbus-glib-types.h" +#define NM_TYPE_SETTINGS_ERROR (nm_settings_error_get_type ()) + /** * nm_settings_error_quark: * @@ -24,6 +26,34 @@ nm_settings_error_quark (void) return quark; } +/* This should really be standard. */ +#define ENUM_ENTRY(NAME, DESC) { NAME, "" #NAME "", DESC } + +static GType +nm_settings_error_get_type (void) +{ + static GType etype = 0; + + if (etype == 0) { + static const GEnumValue values[] = { + /* The connection was invalid. */ + ENUM_ENTRY (NM_SETTINGS_ERROR_INVALID_CONNECTION, "InvalidConnection"), + /* The connection is read-only; modifications are not allowed. */ + ENUM_ENTRY (NM_SETTINGS_ERROR_READ_ONLY_CONNECTION, "ReadOnlyConnection"), + /* A bug in the settings service caused the error. */ + ENUM_ENTRY (NM_SETTINGS_ERROR_INTERNAL_ERROR, "InternalError"), + /* Retrieval or request of secrets failed. */ + ENUM_ENTRY (NM_SETTINGS_ERROR_SECRETS_UNAVAILABLE, "SecretsUnavailable"), + /* The request for secrets was canceled. */ + ENUM_ENTRY (NM_SETTINGS_ERROR_SECRETS_REQUEST_CANCELED, "SecretsRequestCanceled"), + { 0, 0, 0 }, + }; + etype = g_enum_register_static ("NMSettingsError", values); + } + return etype; +} + + /* * NMSettings implementation */ @@ -107,6 +137,8 @@ nm_settings_class_init (NMSettingsClass *settings_class) dbus_g_object_type_install_info (G_TYPE_FROM_CLASS (settings_class), &dbus_glib_nm_settings_object_info); + + dbus_g_error_domain_register (NM_SETTINGS_ERROR, NULL, NM_TYPE_SETTINGS_ERROR); } /** @@ -227,12 +259,28 @@ impl_exported_connection_update (NMExportedConnection *connection, DBusGMethodInvocation *context) { GError *err = NULL; - gboolean success; + NMConnection *wrapped; + gboolean success = FALSE; - /* A hack to share the DBusGMethodInvocation with the possible overriders of connection::delete */ - g_object_set_data (G_OBJECT (connection), NM_EXPORTED_CONNECTION_DBUS_METHOD_INVOCATION, context); - success = nm_exported_connection_update (connection, new_settings, &err); - g_object_set_data (G_OBJECT (connection), NM_EXPORTED_CONNECTION_DBUS_METHOD_INVOCATION, NULL); + /* Read-only connections obviously cannot be changed */ + wrapped = nm_exported_connection_get_connection (connection); + if (wrapped) { + NMSettingConnection *s_con; + + s_con = (NMSettingConnection *) nm_connection_get_setting (wrapped, NM_TYPE_SETTING_CONNECTION); + if (s_con && nm_setting_connection_get_read_only (s_con)) { + g_set_error (&err, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_READ_ONLY_CONNECTION, + "%s.%d - Read-only connections may not be modified.", + __FILE__, __LINE__); + } + } + + if (!err) { + /* A hack to share the DBusGMethodInvocation with the possible overriders of connection::update */ + g_object_set_data (G_OBJECT (connection), NM_EXPORTED_CONNECTION_DBUS_METHOD_INVOCATION, context); + success = nm_exported_connection_update (connection, new_settings, &err); + g_object_set_data (G_OBJECT (connection), NM_EXPORTED_CONNECTION_DBUS_METHOD_INVOCATION, NULL); + } if (success) { dbus_g_method_return (context); @@ -249,12 +297,28 @@ impl_exported_connection_delete (NMExportedConnection *connection, DBusGMethodInvocation *context) { GError *err = NULL; - gboolean success; + NMConnection *wrapped; + gboolean success = FALSE; - /* A hack to share the DBusGMethodInvocation with the possible overriders of connection::delete */ - g_object_set_data (G_OBJECT (connection), NM_EXPORTED_CONNECTION_DBUS_METHOD_INVOCATION, context); - success = nm_exported_connection_delete (connection, &err); - g_object_set_data (G_OBJECT (connection), NM_EXPORTED_CONNECTION_DBUS_METHOD_INVOCATION, NULL); + /* Read-only connections obviously cannot be changed */ + wrapped = nm_exported_connection_get_connection (connection); + if (wrapped) { + NMSettingConnection *s_con; + + s_con = (NMSettingConnection *) nm_connection_get_setting (wrapped, NM_TYPE_SETTING_CONNECTION); + if (s_con && nm_setting_connection_get_read_only (s_con)) { + g_set_error (&err, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_READ_ONLY_CONNECTION, + "%s.%d - Read-only connections may not be deleted.", + __FILE__, __LINE__); + } + } + + if (!err) { + /* A hack to share the DBusGMethodInvocation with the possible overriders of connection::delete */ + g_object_set_data (G_OBJECT (connection), NM_EXPORTED_CONNECTION_DBUS_METHOD_INVOCATION, context); + success = nm_exported_connection_delete (connection, &err); + g_object_set_data (G_OBJECT (connection), NM_EXPORTED_CONNECTION_DBUS_METHOD_INVOCATION, NULL); + } if (success) { dbus_g_method_return (context); @@ -276,7 +340,7 @@ impl_exported_connection_get_secrets (NMExportedConnection *connection, GError *error = NULL; if (!NM_IS_EXPORTED_CONNECTION (connection)) { - g_set_error (&error, NM_SETTINGS_ERROR, 1, + g_set_error (&error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, "%s.%d - Invalid connection in ConnectionSettings::GetSecrets.", __FILE__, __LINE__); dbus_g_method_return_error (context, error); @@ -285,7 +349,7 @@ impl_exported_connection_get_secrets (NMExportedConnection *connection, } if (!EXPORTED_CONNECTION_CLASS (connection)->service_get_secrets) { - g_set_error (&error, NM_SETTINGS_ERROR, 1, + g_set_error (&error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_SECRETS_UNAVAILABLE, "%s.%d - Missing implementation for ConnectionSettings::GetSecrets.", __FILE__, __LINE__); dbus_g_method_return_error (context, error); diff --git a/libnm-glib/nm-settings.h b/libnm-glib/nm-settings.h index d1e34f09b..8e45ec641 100644 --- a/libnm-glib/nm-settings.h +++ b/libnm-glib/nm-settings.h @@ -10,9 +10,19 @@ G_BEGIN_DECLS -#define NM_SETTINGS_ERROR nm_settings_error_quark () +typedef enum +{ + NM_SETTINGS_ERROR_INVALID_CONNECTION = 0, + NM_SETTINGS_ERROR_READ_ONLY_CONNECTION, + NM_SETTINGS_ERROR_INTERNAL_ERROR, + NM_SETTINGS_ERROR_SECRETS_UNAVAILABLE, + NM_SETTINGS_ERROR_SECRETS_REQUEST_CANCELED +} NMSettingsError; + +#define NM_SETTINGS_ERROR (nm_settings_error_quark ()) GQuark nm_settings_error_quark (void); + #define NM_TYPE_EXPORTED_CONNECTION (nm_exported_connection_get_type ()) #define NM_EXPORTED_CONNECTION(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_EXPORTED_CONNECTION, NMExportedConnection)) #define NM_EXPORTED_CONNECTION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_EXPORTED_CONNECTION, NMExportedConnectionClass)) diff --git a/system-settings/plugins/ifupdown/nm-ifupdown-connection.c b/system-settings/plugins/ifupdown/nm-ifupdown-connection.c index e86204fb3..cf203e9fc 100644 --- a/system-settings/plugins/ifupdown/nm-ifupdown-connection.c +++ b/system-settings/plugins/ifupdown/nm-ifupdown-connection.c @@ -28,6 +28,7 @@ #include #include #include +#include #include "nm-ifupdown-connection.h" #include "parser.h" @@ -217,8 +218,8 @@ service_get_secrets (NMExportedConnection *exported, setting = nm_connection_get_setting_by_name (connection, setting_name); if (!setting) { - g_set_error (&error, NM_SYSCONFIG_SETTINGS_ERROR, - NM_SYSCONFIG_SETTINGS_ERROR_INVALID_CONNECTION, + g_set_error (&error, NM_SETTINGS_ERROR, + NM_SETTINGS_ERROR_INVALID_CONNECTION, "%s.%d - Connection didn't have requested setting '%s'.", __FILE__, __LINE__, setting_name); PLUGIN_PRINT ("SCPlugin-Ifupdown", "%s", error->message); @@ -231,7 +232,7 @@ service_get_secrets (NMExportedConnection *exported, g_free, (GDestroyNotify) g_hash_table_destroy); if (!settings) { - g_set_error (&error, NM_SETTINGS_ERROR, 0, + g_set_error (&error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INTERNAL_ERROR, "%s.%d - failed to hash setting (OOM?)", __FILE__, __LINE__); dbus_g_method_return_error (context, error); @@ -245,7 +246,7 @@ service_get_secrets (NMExportedConnection *exported, g_hash_table_insert(settings, g_strdup(setting_name), secrets); dbus_g_method_return (context, settings); } else { - g_set_error (&error, NM_SETTINGS_ERROR, 0, + g_set_error (&error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INTERNAL_ERROR, "%s.%d - nm_setting_to_hash failed (OOM?)", __FILE__, __LINE__); dbus_g_method_return_error (context, error); diff --git a/system-settings/plugins/keyfile/nm-keyfile-connection.c b/system-settings/plugins/keyfile/nm-keyfile-connection.c index d2505be9e..f037b2d7a 100644 --- a/system-settings/plugins/keyfile/nm-keyfile-connection.c +++ b/system-settings/plugins/keyfile/nm-keyfile-connection.c @@ -22,6 +22,7 @@ #include #include #include +#include #include #include @@ -131,7 +132,7 @@ extract_secrets (NMKeyfileConnection *exported, tmp = connection_from_file (priv->filename, TRUE); if (!tmp) { - g_set_error (error, NM_SETTINGS_ERROR, 1, + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_SECRETS_UNAVAILABLE, "%s.%d - Could not read secrets from file %s.", __FILE__, __LINE__, priv->filename); return NULL; @@ -140,7 +141,7 @@ extract_secrets (NMKeyfileConnection *exported, setting = nm_connection_get_setting_by_name (tmp, setting_name); if (!setting) { g_object_unref (tmp); - g_set_error (error, NM_SETTINGS_ERROR, 1, + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_SECRETS_UNAVAILABLE, "%s.%d - Could not read secrets from file %s.", __FILE__, __LINE__, priv->filename); return NULL; @@ -171,7 +172,7 @@ service_get_secrets (NMExportedConnection *exported, connection = nm_exported_connection_get_connection (exported); setting = nm_connection_get_setting_by_name (connection, setting_name); if (!setting) { - g_set_error (&error, NM_SETTINGS_ERROR, 1, + g_set_error (&error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, "%s.%d - Connection didn't have requested setting '%s'.", __FILE__, __LINE__, setting_name); goto error; diff --git a/system-settings/src/dbus-settings.c b/system-settings/src/dbus-settings.c index 2e074610c..9e465bc54 100644 --- a/system-settings/src/dbus-settings.c +++ b/system-settings/src/dbus-settings.c @@ -564,11 +564,10 @@ impl_settings_add_connection (NMSysconfigSettings *self, } } else { /* Invalid connection hash */ - err = g_error_new (NM_SYSCONFIG_SETTINGS_ERROR, - NM_SYSCONFIG_SETTINGS_ERROR_INVALID_CONNECTION, - "Invalid connection: '%s' / '%s' invalid: %d", - g_type_name (nm_connection_lookup_setting_type_by_quark (cnfh_error->domain)), - cnfh_error->message, cnfh_error->code); + err = g_error_new (NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, + "Invalid connection: '%s' / '%s' invalid: %d", + g_type_name (nm_connection_lookup_setting_type_by_quark (cnfh_error->domain)), + cnfh_error->message, cnfh_error->code); g_error_free (cnfh_error); } diff --git a/system-settings/src/main.c b/system-settings/src/main.c index 268fcfc35..9286486c5 100644 --- a/system-settings/src/main.c +++ b/system-settings/src/main.c @@ -1,3 +1,4 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */ /* NetworkManager system settings service * * Søren Sandmann @@ -380,6 +381,7 @@ add_default_dhcp_connection (gpointer user_data) NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRED_SETTING_NAME, NM_SETTING_CONNECTION_AUTOCONNECT, TRUE, NM_SETTING_CONNECTION_UUID, uuid, + NM_SETTING_CONNECTION_READ_ONLY, TRUE, NULL); nm_connection_add_setting (wrapped, NM_SETTING (s_con)); diff --git a/system-settings/src/nm-system-config-error.c b/system-settings/src/nm-system-config-error.c index 8c2e5cade..13d47462f 100644 --- a/system-settings/src/nm-system-config-error.c +++ b/system-settings/src/nm-system-config-error.c @@ -43,7 +43,6 @@ nm_sysconfig_settings_error_get_type (void) static const GEnumValue values[] = { ENUM_ENTRY (NM_SYSCONFIG_SETTINGS_ERROR_GENERAL, "GeneralError"), ENUM_ENTRY (NM_SYSCONFIG_SETTINGS_ERROR_NOT_PRIVILEGED, "NotPrivileged"), - ENUM_ENTRY (NM_SYSCONFIG_SETTINGS_ERROR_INVALID_CONNECTION, "InvalidConnection"), ENUM_ENTRY (NM_SYSCONFIG_SETTINGS_ERROR_ADD_NOT_SUPPORTED, "AddNotSupported"), ENUM_ENTRY (NM_SYSCONFIG_SETTINGS_ERROR_UPDATE_NOT_SUPPORTED, "UpdateNotSupported"), ENUM_ENTRY (NM_SYSCONFIG_SETTINGS_ERROR_DELETE_NOT_SUPPORTED, "DeleteNotSupported"), diff --git a/system-settings/src/nm-system-config-error.h b/system-settings/src/nm-system-config-error.h index 3b3a03b97..dbfcfed35 100644 --- a/system-settings/src/nm-system-config-error.h +++ b/system-settings/src/nm-system-config-error.h @@ -28,7 +28,6 @@ enum { NM_SYSCONFIG_SETTINGS_ERROR_GENERAL = 0, NM_SYSCONFIG_SETTINGS_ERROR_NOT_PRIVILEGED, - NM_SYSCONFIG_SETTINGS_ERROR_INVALID_CONNECTION, NM_SYSCONFIG_SETTINGS_ERROR_ADD_NOT_SUPPORTED, NM_SYSCONFIG_SETTINGS_ERROR_UPDATE_NOT_SUPPORTED, NM_SYSCONFIG_SETTINGS_ERROR_DELETE_NOT_SUPPORTED,