From 519f8cd6c9fbbea83a1a07617b21e5247608037c Mon Sep 17 00:00:00 2001 From: Dan Williams Date: Mon, 27 Oct 2008 17:07:42 +0000 Subject: [PATCH] 2008-10-27 Dan Williams * libnm-util/libnm-util.ver libnm-util/nm-setting-connection.c libnm-util/nm-setting-connection.h - Add a 'read-only' property that indicates the connection cannot be modified * system-settings/plugins/ifcfg-fedora/reader.c system-settings/plugins/ifcfg-suse/parser.c system-settings/plugins/ifupdown/parser.c - These plugins are read-only at the moment * system-settings/plugins/keyfile/reader.c system-settings/plugins/keyfile/writer.c - Read-only shouldn't get saved out to files or read in from them git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@4227 4912f4e0-d625-0410-9fb7-b9a5a253dbdc --- ChangeLog | 17 +++++++++++++ libnm-util/libnm-util.ver | 1 + libnm-util/nm-setting-connection.c | 24 +++++++++++++++++++ libnm-util/nm-setting-connection.h | 4 +++- system-settings/plugins/ifcfg-fedora/reader.c | 8 +++++++ system-settings/plugins/ifcfg-suse/parser.c | 1 + system-settings/plugins/ifupdown/parser.c | 1 + system-settings/plugins/keyfile/reader.c | 6 +++++ system-settings/plugins/keyfile/writer.c | 5 ++++ 9 files changed, 66 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 46f775cc3c..7808442ec1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,20 @@ +2008-10-27 Dan Williams + + * libnm-util/libnm-util.ver + libnm-util/nm-setting-connection.c + libnm-util/nm-setting-connection.h + - Add a 'read-only' property that indicates the connection cannot be + modified + + * system-settings/plugins/ifcfg-fedora/reader.c + system-settings/plugins/ifcfg-suse/parser.c + system-settings/plugins/ifupdown/parser.c + - These plugins are read-only at the moment + + * system-settings/plugins/keyfile/reader.c + system-settings/plugins/keyfile/writer.c + - Read-only shouldn't get saved out to files or read in from them + 2008-10-27 Tambet Ingo * src/nm-device-ethernet.c (nm_device_ethernet_get_speed): Implement diff --git a/libnm-util/libnm-util.ver b/libnm-util/libnm-util.ver index 17ad171125..32b5e2da77 100644 --- a/libnm-util/libnm-util.ver +++ b/libnm-util/libnm-util.ver @@ -54,6 +54,7 @@ global: nm_setting_connection_get_connection_type; nm_setting_connection_get_autoconnect; nm_setting_connection_get_timestamp; + nm_setting_connection_get_read_only; nm_setting_duplicate; nm_setting_enumerate_values; nm_setting_from_hash; diff --git a/libnm-util/nm-setting-connection.c b/libnm-util/nm-setting-connection.c index bb27f630ea..422d8e8c14 100644 --- a/libnm-util/nm-setting-connection.c +++ b/libnm-util/nm-setting-connection.c @@ -72,6 +72,7 @@ typedef struct { char *type; gboolean autoconnect; guint64 timestamp; + gboolean read_only; } NMSettingConnectionPrivate; enum { @@ -81,6 +82,7 @@ enum { PROP_TYPE, PROP_AUTOCONNECT, PROP_TIMESTAMP, + PROP_READ_ONLY, LAST_PROP }; @@ -130,6 +132,14 @@ nm_setting_connection_get_timestamp (NMSettingConnection *setting) return NM_SETTING_CONNECTION_GET_PRIVATE (setting)->timestamp; } +gboolean +nm_setting_connection_get_read_only (NMSettingConnection *setting) +{ + g_return_val_if_fail (NM_IS_SETTING_CONNECTION (setting), TRUE); + + return NM_SETTING_CONNECTION_GET_PRIVATE (setting)->read_only; +} + static gint find_setting_by_name (gconstpointer a, gconstpointer b) { @@ -241,6 +251,9 @@ set_property (GObject *object, guint prop_id, case PROP_TIMESTAMP: priv->timestamp = g_value_get_uint64 (value); break; + case PROP_READ_ONLY: + priv->read_only = g_value_get_boolean (value); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; @@ -269,6 +282,9 @@ get_property (GObject *object, guint prop_id, case PROP_TIMESTAMP: g_value_set_uint64 (value, nm_setting_connection_get_timestamp (setting)); break; + case PROP_READ_ONLY: + g_value_set_boolean (value, nm_setting_connection_get_read_only (setting)); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; @@ -329,4 +345,12 @@ nm_setting_connection_class_init (NMSettingConnectionClass *setting_class) "Connection timestamp", 0, G_MAXUINT64, 0, G_PARAM_READWRITE | NM_SETTING_PARAM_SERIALIZE | NM_SETTING_PARAM_FUZZY_IGNORE)); + + g_object_class_install_property + (object_class, PROP_READ_ONLY, + g_param_spec_boolean (NM_SETTING_CONNECTION_READ_ONLY, + "Read-Only", + "Read-Only", + FALSE, + G_PARAM_READWRITE | NM_SETTING_PARAM_SERIALIZE | NM_SETTING_PARAM_FUZZY_IGNORE)); } diff --git a/libnm-util/nm-setting-connection.h b/libnm-util/nm-setting-connection.h index 16ff4e4c09..04157da824 100644 --- a/libnm-util/nm-setting-connection.h +++ b/libnm-util/nm-setting-connection.h @@ -58,6 +58,7 @@ GQuark nm_setting_connection_error_quark (void); #define NM_SETTING_CONNECTION_TYPE "type" #define NM_SETTING_CONNECTION_AUTOCONNECT "autoconnect" #define NM_SETTING_CONNECTION_TIMESTAMP "timestamp" +#define NM_SETTING_CONNECTION_READ_ONLY "read-only" typedef struct { NMSetting parent; @@ -69,12 +70,13 @@ typedef struct { GType nm_setting_connection_get_type (void); -NMSetting *nm_setting_connection_new (void); +NMSetting * nm_setting_connection_new (void); const char *nm_setting_connection_get_id (NMSettingConnection *setting); const char *nm_setting_connection_get_uuid (NMSettingConnection *setting); const char *nm_setting_connection_get_connection_type (NMSettingConnection *setting); gboolean nm_setting_connection_get_autoconnect (NMSettingConnection *setting); guint64 nm_setting_connection_get_timestamp (NMSettingConnection *setting); +gboolean nm_setting_connection_get_read_only (NMSettingConnection *setting); G_END_DECLS diff --git a/system-settings/plugins/ifcfg-fedora/reader.c b/system-settings/plugins/ifcfg-fedora/reader.c index 75713e2001..26c1bb7f2b 100644 --- a/system-settings/plugins/ifcfg-fedora/reader.c +++ b/system-settings/plugins/ifcfg-fedora/reader.c @@ -899,6 +899,7 @@ connection_from_file (const char *filename, GError **error) { NMConnection *connection = NULL; + NMSettingConnection *s_con; shvarFile *parsed; char *type; char *nmc = NULL; @@ -987,6 +988,13 @@ connection_from_file (const char *filename, g_free (type); + /* We don't write connections yet */ + if (connection) { + s_con = (NMSettingConnection *) nm_connection_get_setting (connection, NM_TYPE_SETTING_CONNECTION); + if (s_con) + g_object_set (s_con, NM_SETTING_CONNECTION_READ_ONLY, TRUE, NULL); + } + /* Don't bother reading the connection fully if it's unmanaged */ if (!connection || *ignored) goto done; diff --git a/system-settings/plugins/ifcfg-suse/parser.c b/system-settings/plugins/ifcfg-suse/parser.c index 72460a8eec..0bd7e4f465 100644 --- a/system-settings/plugins/ifcfg-suse/parser.c +++ b/system-settings/plugins/ifcfg-suse/parser.c @@ -86,6 +86,7 @@ make_connection_setting (shvarFile *file, g_object_set (s_con, NM_SETTING_CONNECTION_ID, str, NM_SETTING_CONNECTION_TYPE, type, + NM_SETTING_CONNECTION_READ_ONLY, TRUE, NULL); g_free (str); diff --git a/system-settings/plugins/ifupdown/parser.c b/system-settings/plugins/ifupdown/parser.c index 713dd6c39d..224f397975 100644 --- a/system-settings/plugins/ifupdown/parser.c +++ b/system-settings/plugins/ifupdown/parser.c @@ -557,6 +557,7 @@ ifupdown_update_connection_from_if_block(NMConnection *connection, NM_SETTING_CONNECTION_TYPE, type, NM_SETTING_CONNECTION_ID, idstr, NM_SETTING_CONNECTION_UUID, uuid, + NM_SETTING_CONNECTION_READ_ONLY, TRUE, NULL); g_free (uuid); diff --git a/system-settings/plugins/keyfile/reader.c b/system-settings/plugins/keyfile/reader.c index 2702bff18f..86cd8d325e 100644 --- a/system-settings/plugins/keyfile/reader.c +++ b/system-settings/plugins/keyfile/reader.c @@ -9,6 +9,7 @@ #include #include #include +#include #include #include @@ -341,6 +342,11 @@ read_one_setting_value (NMSetting *setting, if (secret && !info->secrets) return; + /* Don't read the NMSettingConnection object's 'read-only' property */ + if ( NM_IS_SETTING_CONNECTION (setting) + && !strcmp (key, NM_SETTING_CONNECTION_READ_ONLY)) + return; + /* IPv4 addresses and VPN properties don't have the exact key name */ if (NM_IS_SETTING_IP4_CONFIG (setting) && !strcmp (key, NM_SETTING_IP4_CONFIG_ADDRESSES)) check_for_key = FALSE; diff --git a/system-settings/plugins/keyfile/writer.c b/system-settings/plugins/keyfile/writer.c index 48e21afc23..c80feedd28 100644 --- a/system-settings/plugins/keyfile/writer.c +++ b/system-settings/plugins/keyfile/writer.c @@ -198,6 +198,11 @@ write_setting_value (NMSetting *setting, if (!strcmp (key, NM_SETTING_NAME)) return; + /* Don't write the NMSettingConnection object's 'read-only' property */ + if ( NM_IS_SETTING_CONNECTION (setting) + && !strcmp (key, NM_SETTING_CONNECTION_READ_ONLY)) + return; + if (type == G_TYPE_STRING) { const char *str;