NetworkManager r4013 - in trunk: . introspection libnm-glib libnm-util system-settings/plugins/ifcfg-fedora system-settings/plugins/ifcfg-suse system-settings/plugins/keyfile system-settings/src
- From: dcbw svn gnome org
- To: svn-commits-list gnome org
- Subject: NetworkManager r4013 - in trunk: . introspection libnm-glib libnm-util system-settings/plugins/ifcfg-fedora system-settings/plugins/ifcfg-suse system-settings/plugins/keyfile system-settings/src
- Date: Wed, 27 Aug 2008 02:57:21 +0000 (UTC)
Author: dcbw
Date: Wed Aug 27 02:57:21 2008
New Revision: 4013
URL: http://svn.gnome.org/viewvc/NetworkManager?rev=4013&view=rev
Log:
2008-08-26 Dan Williams <dcbw redhat com>
Add connection UUIDs, since connection names can be changed, and since
old-style connection IDs could change over the life of the connection. The
UUID should be assigned at connection creation time, be stable for a given
connection, and should be unique among all connections for a given settings
service.
* configure.in
libnm-util/Makefile.am
- Require libuuid
* introspection/nm-exported-connection.xml
- Remove "GetID" method
* libnm-glib/nm-dbus-connection.c
libnm-glib/nm-settings.c
libnm-glib/nm-settings.h
- Remove id-related stuff
* libnm-util/nm-utils.c
libnm-util/nm-utils.h
libnm-util/libnm-util.ver
- (nm_utils_uuid_generate, nm_utils_uuid_generate_from_string): Add
utility functions to generate UUIDs
* libnm-util/nm-setting-connection.c
libnm-util/nm-setting-connection.h
- Add 'uuid' member to the connection setting
- (verify): require valid 'uuid' for a valid connection
* system-settings/plugins/ifcfg-fedora/nm-ifcfg-connection.c
system-settings/plugins/ifcfg-fedora/reader.c
system-settings/plugins/ifcfg-suse/nm-suse-connection.c
system-settings/plugins/ifcfg-suse/parser.c
system-settings/plugins/keyfile/nm-keyfile-connection.c
system-settings/src/main.c
- Remove id-related stuff
- Give connections UUIDs where needed
Modified:
trunk/ChangeLog
trunk/configure.in
trunk/introspection/nm-exported-connection.xml
trunk/libnm-glib/nm-dbus-connection.c
trunk/libnm-glib/nm-settings.c
trunk/libnm-glib/nm-settings.h
trunk/libnm-util/Makefile.am
trunk/libnm-util/libnm-util.ver
trunk/libnm-util/nm-setting-connection.c
trunk/libnm-util/nm-setting-connection.h
trunk/libnm-util/nm-utils.c
trunk/libnm-util/nm-utils.h
trunk/system-settings/plugins/ifcfg-fedora/nm-ifcfg-connection.c
trunk/system-settings/plugins/ifcfg-fedora/reader.c
trunk/system-settings/plugins/ifcfg-suse/nm-suse-connection.c
trunk/system-settings/plugins/ifcfg-suse/parser.c
trunk/system-settings/plugins/keyfile/nm-keyfile-connection.c
trunk/system-settings/src/main.c
Modified: trunk/configure.in
==============================================================================
--- trunk/configure.in (original)
+++ trunk/configure.in Wed Aug 27 02:57:21 2008
@@ -243,6 +243,10 @@
AC_SUBST(LIBNL_CFLAGS)
AC_SUBST(LIBNL_LIBS)
+PKG_CHECK_MODULES(UUID, uuid)
+AC_SUBST(UUID_CFLAGS)
+AC_SUBST(UUID_LIBS)
+
PKG_CHECK_MODULES(POLKIT, polkit-dbus)
##### Find out the version of PolicyKit we're using
Modified: trunk/introspection/nm-exported-connection.xml
==============================================================================
--- trunk/introspection/nm-exported-connection.xml (original)
+++ trunk/introspection/nm-exported-connection.xml Wed Aug 27 02:57:21 2008
@@ -6,38 +6,27 @@
<tp:docstring>
Represents a single network connection configuration.
</tp:docstring>
- <method name="GetID">
+
+ <method name="Update">
+ <tp:docstring>
+ Update the connection.
+ </tp:docstring>
+ <annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_exported_connection_update"/>
+ <annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
+ <arg name="properties" type="a{sa{sv}}" direction="in">
<tp:docstring>
- Obtain the ID of this connection.
+ New connection properties.
</tp:docstring>
- <annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_exported_connection_get_id"/>
- <arg name="id" type="s" direction="out">
- <tp:docstring>
- The ID of this connection.
- </tp:docstring>
- </arg>
+ </arg>
</method>
- <method name="Update">
- <tp:docstring>
- Update the connection.
- </tp:docstring>
- <annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_exported_connection_update"/>
+ <method name="Delete">
+ <tp:docstring>
+ Delete the connection.
+ </tp:docstring>
+ <annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_exported_connection_delete"/>
<annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
- <arg name="properties" type="a{sa{sv}}" direction="in">
- <tp:docstring>
- New connection properties.
- </tp:docstring>
- </arg>
- </method>
-
- <method name="Delete">
- <tp:docstring>
- Delete the connection.
- </tp:docstring>
- <annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_exported_connection_delete"/>
- <annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
- </method>
+ </method>
<method name="GetSettings">
<tp:docstring>
Modified: trunk/libnm-glib/nm-dbus-connection.c
==============================================================================
--- trunk/libnm-glib/nm-dbus-connection.c (original)
+++ trunk/libnm-glib/nm-dbus-connection.c Wed Aug 27 02:57:21 2008
@@ -52,12 +52,6 @@
return nm_connection_to_hash (nm_exported_connection_get_connection (exported));
}
-static const char *
-get_id (NMExportedConnection *exported)
-{
- return NM_DBUS_CONNECTION_GET_PRIVATE (exported)->path;
-}
-
static void
get_secrets (NMExportedConnection *connection,
const gchar *setting_name,
@@ -279,7 +273,6 @@
object_class->finalize = finalize;
connection_class->get_settings = get_settings;
- connection_class->get_id = get_id;
connection_class->get_secrets = get_secrets;
connection_class->update = update;
connection_class->delete = delete;
Modified: trunk/libnm-glib/nm-settings.c
==============================================================================
--- trunk/libnm-glib/nm-settings.c (original)
+++ trunk/libnm-glib/nm-settings.c Wed Aug 27 02:57:21 2008
@@ -145,9 +145,6 @@
* NMExportedConnection implementation
*/
-static gboolean impl_exported_connection_get_id (NMExportedConnection *connection,
- gchar **id,
- GError **error);
static gboolean impl_exported_connection_get_settings (NMExportedConnection *connection,
GHashTable **settings,
GError **error);
@@ -205,43 +202,6 @@
NULL);
}
-const char *
-nm_exported_connection_get_id (NMExportedConnection *connection)
-{
- NMExportedConnectionPrivate *priv;
- NMSettingConnection *s_con;
-
- g_return_val_if_fail (NM_IS_EXPORTED_CONNECTION (connection), NULL);
-
- priv = NM_EXPORTED_CONNECTION_GET_PRIVATE (connection);
- if (EXPORTED_CONNECTION_CLASS (connection)->get_id)
- return EXPORTED_CONNECTION_CLASS (connection)->get_id (connection);
-
- s_con = (NMSettingConnection *) nm_connection_get_setting (priv->wrapped, NM_TYPE_SETTING_CONNECTION);
- if (NM_IS_SETTING_CONNECTION (s_con))
- return s_con->id;
-
- return NULL;
-}
-
-static gboolean
-impl_exported_connection_get_id (NMExportedConnection *connection,
- gchar **id,
- GError **error)
-{
- g_return_val_if_fail (NM_IS_EXPORTED_CONNECTION (connection), FALSE);
-
- *id = g_strdup (nm_exported_connection_get_id (connection));
- if (!*id) {
- g_set_error (error, NM_SETTINGS_ERROR, 1,
- "%s.%d - Could not get connection ID.",
- __FILE__, __LINE__);
- return FALSE;
- }
-
- return TRUE;
-}
-
static gboolean
impl_exported_connection_get_settings (NMExportedConnection *connection,
GHashTable **settings,
@@ -406,7 +366,6 @@
object_class->get_property = get_property;
object_class->dispose = nm_exported_connection_dispose;
- exported_connection_class->get_id = NULL;
exported_connection_class->get_settings = NULL;
exported_connection_class->get_secrets = NULL;
Modified: trunk/libnm-glib/nm-settings.h
==============================================================================
--- trunk/libnm-glib/nm-settings.h (original)
+++ trunk/libnm-glib/nm-settings.h Wed Aug 27 02:57:21 2008
@@ -32,13 +32,12 @@
GObjectClass parent_class;
/* virtual methods */
- const gchar *(* get_id) (NMExportedConnection *connection);
- GHashTable * (* get_settings) (NMExportedConnection *connection);
- void (* get_secrets) (NMExportedConnection *connection,
- const gchar *setting_name,
- const gchar **hints,
- gboolean request_new,
- DBusGMethodInvocation *context);
+ GHashTable * (*get_settings) (NMExportedConnection *connection);
+ void (*get_secrets) (NMExportedConnection *connection,
+ const gchar *setting_name,
+ const gchar **hints,
+ gboolean request_new,
+ DBusGMethodInvocation *context);
gboolean (*update) (NMExportedConnection *connection,
GHashTable *new_settings,
@@ -62,8 +61,6 @@
NMConnection *nm_exported_connection_get_connection (NMExportedConnection *connection);
-const char *nm_exported_connection_get_id (NMExportedConnection *connection);
-
gboolean nm_exported_connection_update (NMExportedConnection *connection,
GHashTable *new_settings,
GError **err);
Modified: trunk/libnm-util/Makefile.am
==============================================================================
--- trunk/libnm-util/Makefile.am (original)
+++ trunk/libnm-util/Makefile.am Wed Aug 27 02:57:21 2008
@@ -2,10 +2,11 @@
lib_LTLIBRARIES=libnm-util.la
-libnm_util_la_CPPFLAGS = \
- $(GLIB_CFLAGS) \
- $(DBUS_CFLAGS) \
- -DDBUS_API_SUBJECT_TO_CHANGE \
+libnm_util_la_CPPFLAGS = \
+ $(GLIB_CFLAGS) \
+ $(DBUS_CFLAGS) \
+ $(UUID_CFLAGS) \
+ -DDBUS_API_SUBJECT_TO_CHANGE \
-DG_DISABLE_DEPRECATED
libnm_util_include_HEADERS = \
@@ -49,7 +50,7 @@
nm-utils.c \
$(libnm_util_include_HEADERS)
-libnm_util_la_LIBADD = $(GLIB_LIBS) $(DBUS_LIBS)
+libnm_util_la_LIBADD = $(GLIB_LIBS) $(DBUS_LIBS) $(UUID_LIBS)
libnm_util_la_LDFLAGS = -Wl,--version-script=$(srcdir)/libnm-util.ver
Modified: trunk/libnm-util/libnm-util.ver
==============================================================================
--- trunk/libnm-util/libnm-util.ver (original)
+++ trunk/libnm-util/libnm-util.ver Wed Aug 27 02:57:21 2008
@@ -120,6 +120,8 @@
nm_utils_string_in_list;
nm_utils_string_list_contains;
nm_utils_string_slist_validate;
+ nm_utils_uuid_generate;
+ nm_utils_uuid_generate_from_string;
local:
*;
};
Modified: trunk/libnm-util/nm-setting-connection.c
==============================================================================
--- trunk/libnm-util/nm-setting-connection.c (original)
+++ trunk/libnm-util/nm-setting-connection.c Wed Aug 27 02:57:21 2008
@@ -67,6 +67,7 @@
enum {
PROP_0,
PROP_ID,
+ PROP_UUID,
PROP_TYPE,
PROP_AUTOCONNECT,
PROP_TIMESTAMP,
@@ -107,6 +108,20 @@
return FALSE;
}
+ if (!self->uuid) {
+ g_set_error (error,
+ NM_SETTING_CONNECTION_ERROR,
+ NM_SETTING_CONNECTION_ERROR_MISSING_PROPERTY,
+ NM_SETTING_CONNECTION_UUID);
+ return FALSE;
+ } else if (!strlen (self->uuid)) {
+ g_set_error (error,
+ NM_SETTING_CONNECTION_ERROR,
+ NM_SETTING_CONNECTION_ERROR_INVALID_PROPERTY,
+ NM_SETTING_CONNECTION_UUID);
+ return FALSE;
+ }
+
if (!self->type) {
g_set_error (error,
NM_SETTING_CONNECTION_ERROR,
@@ -145,6 +160,7 @@
NMSettingConnection *self = NM_SETTING_CONNECTION (object);
g_free (self->id);
+ g_free (self->uuid);
g_free (self->type);
G_OBJECT_CLASS (nm_setting_connection_parent_class)->finalize (object);
@@ -161,6 +177,10 @@
g_free (setting->id);
setting->id = g_value_dup_string (value);
break;
+ case PROP_UUID:
+ g_free (setting->uuid);
+ setting->uuid = g_value_dup_string (value);
+ break;
case PROP_TYPE:
g_free (setting->type);
setting->type = g_value_dup_string (value);
@@ -187,6 +207,9 @@
case PROP_ID:
g_value_set_string (value, setting->id);
break;
+ case PROP_UUID:
+ g_value_set_string (value, setting->uuid);
+ break;
case PROP_TYPE:
g_value_set_string (value, setting->type);
break;
@@ -224,6 +247,14 @@
G_PARAM_READWRITE | NM_SETTING_PARAM_SERIALIZE | NM_SETTING_PARAM_FUZZY_IGNORE));
g_object_class_install_property
+ (object_class, PROP_UUID,
+ g_param_spec_string (NM_SETTING_CONNECTION_UUID,
+ "UUID",
+ "Universally unique connection identifier",
+ NULL,
+ G_PARAM_READWRITE | NM_SETTING_PARAM_SERIALIZE | NM_SETTING_PARAM_FUZZY_IGNORE));
+
+ g_object_class_install_property
(object_class, PROP_TYPE,
g_param_spec_string (NM_SETTING_CONNECTION_TYPE,
"Type",
Modified: trunk/libnm-util/nm-setting-connection.h
==============================================================================
--- trunk/libnm-util/nm-setting-connection.h (original)
+++ trunk/libnm-util/nm-setting-connection.h Wed Aug 27 02:57:21 2008
@@ -54,6 +54,7 @@
GQuark nm_setting_connection_error_quark (void);
#define NM_SETTING_CONNECTION_ID "id"
+#define NM_SETTING_CONNECTION_UUID "uuid"
#define NM_SETTING_CONNECTION_TYPE "type"
#define NM_SETTING_CONNECTION_AUTOCONNECT "autoconnect"
#define NM_SETTING_CONNECTION_TIMESTAMP "timestamp"
@@ -62,6 +63,7 @@
NMSetting parent;
char *id;
+ char *uuid;
char *type;
gboolean autoconnect;
guint64 timestamp;
Modified: trunk/libnm-util/nm-utils.c
==============================================================================
--- trunk/libnm-util/nm-utils.c (original)
+++ trunk/libnm-util/nm-utils.c Wed Aug 27 02:57:21 2008
@@ -35,11 +35,14 @@
#include <glib.h>
#include <glib-object.h>
#include <dbus/dbus-glib.h>
+#include <uuid/uuid.h>
+
#include "nm-utils.h"
#include "NetworkManager.h"
#include "nm-dbus-glib-types.h"
#include "nm-setting-ip4-config.h"
#include "nm-setting-ip6-config.h"
+#include "crypto.h"
struct EncodingTriplet
{
@@ -1105,3 +1108,51 @@
g_value_take_boxed (value, dns);
}
+
+char *
+nm_utils_uuid_generate (void)
+{
+ uuid_t uuid;
+ char *buf;
+
+ buf = g_malloc0 (37);
+ uuid_generate_random (uuid);
+ uuid_unparse_lower (uuid, &buf[0]);
+ return buf;
+}
+
+char *
+nm_utils_uuid_generate_from_string (const char *s)
+{
+ GError *error = NULL;
+ uuid_t *uuid;
+ char *buf = NULL;
+
+ if (!crypto_init (&error)) {
+ nm_warning ("error initializing crypto: (%d) %s",
+ error ? error->code : 0,
+ error ? error->message : "unknown");
+ if (error)
+ g_error_free (error);
+ return NULL;
+ }
+
+ uuid = g_malloc0 (sizeof (uuid));
+ if (!crypto_md5_hash (NULL, 0, s, strlen (s), (char *) uuid, sizeof (uuid), &error)) {
+ nm_warning ("error generating UUID: (%d) %s",
+ error ? error->code : 0,
+ error ? error->message : "unknown");
+ if (error)
+ g_error_free (error);
+ goto out;
+ }
+
+ buf = g_malloc0 (37);
+ uuid_unparse_lower (*uuid, &buf[0]);
+
+out:
+ g_free (uuid);
+ crypto_deinit ();
+ return buf;
+}
+
Modified: trunk/libnm-util/nm-utils.h
==============================================================================
--- trunk/libnm-util/nm-utils.h (original)
+++ trunk/libnm-util/nm-utils.h Wed Aug 27 02:57:21 2008
@@ -196,4 +196,7 @@
GSList *nm_utils_ip6_dns_from_gvalue (const GValue *value);
void nm_utils_ip6_dns_to_gvalue (GSList *list, GValue *value);
+char *nm_utils_uuid_generate (void);
+char *nm_utils_uuid_generate_from_string (const char *s);
+
#endif /* NM_UTILS_H */
Modified: trunk/system-settings/plugins/ifcfg-fedora/nm-ifcfg-connection.c
==============================================================================
--- trunk/system-settings/plugins/ifcfg-fedora/nm-ifcfg-connection.c (original)
+++ trunk/system-settings/plugins/ifcfg-fedora/nm-ifcfg-connection.c Wed Aug 27 02:57:21 2008
@@ -318,12 +318,6 @@
return nm_connection_to_hash (nm_exported_connection_get_connection (exported));
}
-static const char *
-get_id (NMExportedConnection *exported)
-{
- return NM_IFCFG_CONNECTION_GET_PRIVATE (exported)->filename;
-}
-
static gboolean
update (NMExportedConnection *exported, GHashTable *new_settings, GError **error)
{
@@ -448,7 +442,6 @@
object_class->finalize = finalize;
connection_class->get_settings = get_settings;
- connection_class->get_id = get_id;
connection_class->update = update;
connection_class->delete = delete;
Modified: trunk/system-settings/plugins/ifcfg-fedora/reader.c
==============================================================================
--- trunk/system-settings/plugins/ifcfg-fedora/reader.c (original)
+++ trunk/system-settings/plugins/ifcfg-fedora/reader.c Wed Aug 27 02:57:21 2008
@@ -111,6 +111,8 @@
s_con->type = g_strdup (type);
+ s_con->uuid = nm_utils_uuid_generate_from_string (ifcfg->fileName);
+
/* Be somewhat conservative about autoconnect */
if (svTrueValue (ifcfg, "ONBOOT", FALSE))
s_con->autoconnect = TRUE;
Modified: trunk/system-settings/plugins/ifcfg-suse/nm-suse-connection.c
==============================================================================
--- trunk/system-settings/plugins/ifcfg-suse/nm-suse-connection.c (original)
+++ trunk/system-settings/plugins/ifcfg-suse/nm-suse-connection.c Wed Aug 27 02:57:21 2008
@@ -100,12 +100,6 @@
return nm_connection_to_hash (nm_exported_connection_get_connection (exported));
}
-static const char *
-get_id (NMExportedConnection *exported)
-{
- return NM_SUSE_CONNECTION_GET_PRIVATE (exported)->filename;
-}
-
static gboolean
update (NMExportedConnection *exported,
GHashTable *new_settings,
@@ -165,7 +159,6 @@
object_class->finalize = finalize;
connection_class->get_settings = get_settings;
- connection_class->get_id = get_id;
connection_class->update = update;
connection_class->delete = delete;
}
Modified: trunk/system-settings/plugins/ifcfg-suse/parser.c
==============================================================================
--- trunk/system-settings/plugins/ifcfg-suse/parser.c (original)
+++ trunk/system-settings/plugins/ifcfg-suse/parser.c Wed Aug 27 02:57:21 2008
@@ -64,7 +64,7 @@
static NMSetting *
make_connection_setting (shvarFile *file,
- const char *iface,
+ const char *iface,
const char *type,
const char *suggested)
{
@@ -85,6 +85,8 @@
s_con->type = g_strdup (type);
+ s_con->uuid = nm_utils_uuid_generate_from_string (file->fileName);
+
str = svGetValue (file, "STARTMODE");
if (str && !g_ascii_strcasecmp (str, "manual"))
s_con->autoconnect = FALSE;
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 Wed Aug 27 02:57:21 2008
@@ -3,6 +3,9 @@
#include <string.h>
#include <glib/gstdio.h>
#include <NetworkManager.h>
+#include <nm-setting-connection.h>
+#include <nm-utils.h>
+
#include "nm-keyfile-connection.h"
#include "reader.h"
#include "writer.h"
@@ -46,12 +49,6 @@
return nm_connection_to_hash (nm_exported_connection_get_connection (exported));
}
-static const char *
-get_id (NMExportedConnection *exported)
-{
- return NM_KEYFILE_CONNECTION_GET_PRIVATE (exported)->filename;
-}
-
static gboolean
update (NMExportedConnection *exported,
GHashTable *new_settings,
@@ -95,6 +92,7 @@
GObject *object;
NMKeyfileConnectionPrivate *priv;
NMConnection *wrapped;
+ NMSettingConnection *s_con;
object = G_OBJECT_CLASS (nm_keyfile_connection_parent_class)->constructor (type, n_construct_params, construct_params);
@@ -112,6 +110,20 @@
if (!wrapped)
goto err;
+ /* if for some reason the connection didn't have a UUID, add one */
+ s_con = (NMSettingConnection *) nm_connection_get_setting (wrapped, NM_TYPE_SETTING_CONNECTION);
+ if (s_con && !s_con->uuid) {
+ GError *error = NULL;
+
+ s_con->uuid = nm_utils_uuid_generate ();
+ if (!write_connection (wrapped, &error)) {
+ g_warning ("Couldn't update connection %s with a UUID: (%d) %s",
+ s_con->id, error ? error->code : 0,
+ error ? error->message : "unknown");
+ g_error_free (error);
+ }
+ }
+
g_object_set (object, NM_EXPORTED_CONNECTION_CONNECTION, wrapped, NULL);
g_object_unref (wrapped);
@@ -181,7 +193,6 @@
object_class->finalize = finalize;
connection_class->get_settings = get_settings;
- connection_class->get_id = get_id;
connection_class->update = update;
connection_class->delete = delete;
Modified: trunk/system-settings/src/main.c
==============================================================================
--- trunk/system-settings/src/main.c (original)
+++ trunk/system-settings/src/main.c Wed Aug 27 02:57:21 2008
@@ -40,6 +40,7 @@
#include <nm-setting-wired.h>
#include <nm-setting-pppoe.h>
#include <nm-settings.h>
+#include <nm-utils.h>
#include <NetworkManager.h>
#include "dbus-settings.h"
@@ -365,6 +366,7 @@
s_con->id = g_strdup_printf (_("Auto %s"), info->iface);
s_con->type = g_strdup (NM_SETTING_WIRED_SETTING_NAME);
s_con->autoconnect = TRUE;
+ s_con->uuid = nm_utils_uuid_generate ();
nm_connection_add_setting (wrapped, NM_SETTING (s_con));
g_message ("Adding default connection '%s' for %s", s_con->id, info->udi);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]