2008-11-03 Dan Williams <dcbw@redhat.com>
authorDan Williams <dcbw@redhat.com>
Mon, 3 Nov 2008 22:32:49 +0000 (22:32 +0000)
committerDan Williams <dcbw@redhat.com>
Mon, 3 Nov 2008 22:32:49 +0000 (22:32 +0000)
* 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

git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@4254 4912f4e0-d625-0410-9fb7-b9a5a253dbdc

ChangeLog
libnm-glib/nm-settings.c
libnm-glib/nm-settings.h
system-settings/plugins/ifupdown/nm-ifupdown-connection.c
system-settings/plugins/keyfile/nm-keyfile-connection.c
system-settings/src/dbus-settings.c
system-settings/src/main.c
system-settings/src/nm-system-config-error.c
system-settings/src/nm-system-config-error.h

index f89e6ea..eb7e524 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,25 @@
+2008-11-03  Dan Williams  <dcbw@redhat.com>
+
+       * 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  <dcbw@redhat.com>
 
        * Add license headers to everything in src/
index 482a988..da34f0d 100644 (file)
@@ -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;
+
+       /* 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__);
+               }
+       }
 
-       /* 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);
+       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;
+
+       /* 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__);
+               }
+       }
 
-       /* 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 (!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);
index d1e34f0..8e45ec6 100644 (file)
 
 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))
index e86204f..cf203e9 100644 (file)
@@ -28,6 +28,7 @@
 #include <nm-setting-wireless-security.h>
 #include <nm-system-config-interface.h>
 #include <nm-system-config-error.h>
+#include <nm-settings.h>
 #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);
index d2505be..f037b2d 100644 (file)
@@ -22,6 +22,7 @@
 #include <string.h>
 #include <glib/gstdio.h>
 #include <NetworkManager.h>
+#include <nm-settings.h>
 #include <nm-setting-connection.h>
 #include <nm-utils.h>
 
@@ -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;
index 2e07461..9e465bc 100644 (file)
@@ -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);
        }
 
index 268fcfc..9286486 100644 (file)
@@ -1,3 +1,4 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
 /* NetworkManager system settings service
  *
  * Søren Sandmann <sandmann@daimi.au.dk>
@@ -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));
index 8c2e5ca..13d4746 100644 (file)
@@ -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"),
index 3b3a03b..dbfcfed 100644 (file)
@@ -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,