+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/
#include "nm-dbus-glib-types.h"
+#define NM_TYPE_SETTINGS_ERROR (nm_settings_error_get_type ())
+
/**
* nm_settings_error_quark:
*
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
*/
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);
}
/**
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);
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);
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);
}
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);
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))
#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"
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);
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);
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);
#include <string.h>
#include <glib/gstdio.h>
#include <NetworkManager.h>
+#include <nm-settings.h>
#include <nm-setting-connection.h>
#include <nm-utils.h>
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;
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;
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;
}
} 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);
}
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/* NetworkManager system settings service
*
* Søren Sandmann <sandmann@daimi.au.dk>
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));
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"),
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,