NetworkManager r4254 - in trunk: . libnm-glib system-settings/plugins/ifupdown system-settings/plugins/keyfile system-settings/src



Author: dcbw
Date: Mon Nov  3 22:32:49 2008
New Revision: 4254
URL: http://svn.gnome.org/viewvc/NetworkManager?rev=4254&view=rev

Log:
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



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

Modified: trunk/libnm-glib/nm-settings.c
==============================================================================
--- trunk/libnm-glib/nm-settings.c	(original)
+++ trunk/libnm-glib/nm-settings.c	Mon Nov  3 22:32:49 2008
@@ -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 @@
 	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 @@
 
 	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 @@
 						   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 @@
 						   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 @@
 	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 @@
 	}
 
 	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);

Modified: trunk/libnm-glib/nm-settings.h
==============================================================================
--- trunk/libnm-glib/nm-settings.h	(original)
+++ trunk/libnm-glib/nm-settings.h	Mon Nov  3 22:32:49 2008
@@ -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))

Modified: trunk/system-settings/plugins/ifupdown/nm-ifupdown-connection.c
==============================================================================
--- trunk/system-settings/plugins/ifupdown/nm-ifupdown-connection.c	(original)
+++ trunk/system-settings/plugins/ifupdown/nm-ifupdown-connection.c	Mon Nov  3 22:32:49 2008
@@ -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 @@
 	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 @@
 							    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 @@
 			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);

Modified: trunk/system-settings/plugins/keyfile/nm-keyfile-connection.c
==============================================================================
--- trunk/system-settings/plugins/keyfile/nm-keyfile-connection.c	(original)
+++ trunk/system-settings/plugins/keyfile/nm-keyfile-connection.c	Mon Nov  3 22:32:49 2008
@@ -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 @@
 
 	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 @@
 	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 @@
 	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;

Modified: trunk/system-settings/src/dbus-settings.c
==============================================================================
--- trunk/system-settings/src/dbus-settings.c	(original)
+++ trunk/system-settings/src/dbus-settings.c	Mon Nov  3 22:32:49 2008
@@ -564,11 +564,10 @@
 		}
 	} 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);
 	}
 

Modified: trunk/system-settings/src/main.c
==============================================================================
--- trunk/system-settings/src/main.c	(original)
+++ trunk/system-settings/src/main.c	Mon Nov  3 22:32:49 2008
@@ -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 @@
 		      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));

Modified: trunk/system-settings/src/nm-system-config-error.c
==============================================================================
--- trunk/system-settings/src/nm-system-config-error.c	(original)
+++ trunk/system-settings/src/nm-system-config-error.c	Mon Nov  3 22:32:49 2008
@@ -43,7 +43,6 @@
 		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"),

Modified: trunk/system-settings/src/nm-system-config-error.h
==============================================================================
--- trunk/system-settings/src/nm-system-config-error.h	(original)
+++ trunk/system-settings/src/nm-system-config-error.h	Mon Nov  3 22:32:49 2008
@@ -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,



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]