summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2016-09-06 16:12:33 +0200
committerThomas Haller <thaller@redhat.com>2016-09-06 16:12:33 +0200
commitad3c8a0d4e2b4aee07b59c3923169d02e29297ea (patch)
treebb9d0b21be588bb43117680d85fe002db7eab0fe
parent2724ec53b707cda982264b6604f959f998572ea6 (diff)
parent814784aa46004023739ccb29bc806d1abfb63bb2 (diff)
libnm: merge branch 'th/empty-cloned-mac-address-rh1372799'
https://bugzilla.redhat.com/show_bug.cgi?id=1372799
-rw-r--r--clients/tui/nmt-mac-entry.c3
-rw-r--r--libnm-core/nm-setting-8021x.c17
-rw-r--r--libnm-core/nm-utils.c19
-rw-r--r--shared/nm-utils/nm-macros-internal.h16
4 files changed, 39 insertions, 16 deletions
diff --git a/clients/tui/nmt-mac-entry.c b/clients/tui/nmt-mac-entry.c
index da7f55fac1..b954d2e0c9 100644
--- a/clients/tui/nmt-mac-entry.c
+++ b/clients/tui/nmt-mac-entry.c
@@ -201,7 +201,8 @@ nmt_mac_entry_get_property (GObject *object,
g_value_set_int (value, priv->mac_length);
break;
case PROP_MAC_ADDRESS:
- g_value_set_string (value, nmt_newt_entry_get_text (NMT_NEWT_ENTRY (object)));
+ g_value_set_string (value,
+ nm_str_not_empty (nmt_newt_entry_get_text (NMT_NEWT_ENTRY (object))));
break;
case PROP_ENTRY_TYPE:
g_value_set_int (value, priv->entry_type);
diff --git a/libnm-core/nm-setting-8021x.c b/libnm-core/nm-setting-8021x.c
index aa9d461969..12dc5a62a4 100644
--- a/libnm-core/nm-setting-8021x.c
+++ b/libnm-core/nm-setting-8021x.c
@@ -2915,15 +2915,6 @@ set_cert_prop_helper (const GValue *value, const char *prop_name, GError **error
return bytes;
}
-static char *
-_g_value_dup_string_not_empty (const GValue *value)
-{
- const gchar *str;
-
- str = g_value_get_string (value);
- return str && str[0] ? g_strdup (str) : NULL;
-}
-
static void
set_property (GObject *object, guint prop_id,
const GValue *value, GParamSpec *pspec)
@@ -2964,7 +2955,7 @@ set_property (GObject *object, guint prop_id,
break;
case PROP_SUBJECT_MATCH:
g_free (priv->subject_match);
- priv->subject_match = _g_value_dup_string_not_empty (value);
+ priv->subject_match = nm_strdup_not_empty (g_value_get_string (value));
break;
case PROP_ALTSUBJECT_MATCHES:
g_slist_free_full (priv->altsubject_matches, g_free);
@@ -2972,7 +2963,7 @@ set_property (GObject *object, guint prop_id,
break;
case PROP_DOMAIN_SUFFIX_MATCH:
g_free (priv->domain_suffix_match);
- priv->domain_suffix_match = _g_value_dup_string_not_empty (value);
+ priv->domain_suffix_match = nm_strdup_not_empty (g_value_get_string (value));
break;
case PROP_CLIENT_CERT:
if (priv->client_cert)
@@ -3018,7 +3009,7 @@ set_property (GObject *object, guint prop_id,
break;
case PROP_PHASE2_SUBJECT_MATCH:
g_free (priv->phase2_subject_match);
- priv->phase2_subject_match = _g_value_dup_string_not_empty (value);
+ priv->phase2_subject_match = nm_strdup_not_empty (g_value_get_string (value));
break;
case PROP_PHASE2_ALTSUBJECT_MATCHES:
g_slist_free_full (priv->phase2_altsubject_matches, g_free);
@@ -3026,7 +3017,7 @@ set_property (GObject *object, guint prop_id,
break;
case PROP_PHASE2_DOMAIN_SUFFIX_MATCH:
g_free (priv->phase2_domain_suffix_match);
- priv->phase2_domain_suffix_match = _g_value_dup_string_not_empty (value);
+ priv->phase2_domain_suffix_match = nm_strdup_not_empty (g_value_get_string (value));
break;
case PROP_PHASE2_CLIENT_CERT:
if (priv->phase2_client_cert)
diff --git a/libnm-core/nm-utils.c b/libnm-core/nm-utils.c
index a31a91906f..df75d56557 100644
--- a/libnm-core/nm-utils.c
+++ b/libnm-core/nm-utils.c
@@ -3425,7 +3425,22 @@ _nm_utils_hwaddr_cloned_data_synth (NMSetting *setting,
"cloned-mac-address",
&addr,
NULL);
- return addr ? g_variant_new_string (addr) : NULL;
+
+ /* Before introducing the extended "cloned-mac-address" (and its D-Bus
+ * field "assigned-mac-address"), libnm's _nm_utils_hwaddr_to_dbus()
+ * would drop invalid values as it was unable to serialize them.
+ *
+ * Now, we would like to send invalid values as "assigned-mac-address"
+ * over D-Bus and let the server reject them.
+ *
+ * However, clients used to set the cloned-mac-address property
+ * to "" and it just worked as the value was not serialized in
+ * an ill form.
+ *
+ * To preserve that behavior, seralize "" as NULL.
+ */
+
+ return addr && addr[0] ? g_variant_new_string (addr) : NULL;
}
gboolean
@@ -3443,7 +3458,7 @@ _nm_utils_hwaddr_cloned_data_set (NMSetting *setting,
g_object_set (setting,
"cloned-mac-address",
- g_variant_get_string (value, NULL),
+ nm_str_not_empty (g_variant_get_string (value, NULL)),
NULL);
return TRUE;
}
diff --git a/shared/nm-utils/nm-macros-internal.h b/shared/nm-utils/nm-macros-internal.h
index 73075c6816..c66cb53954 100644
--- a/shared/nm-utils/nm-macros-internal.h
+++ b/shared/nm-utils/nm-macros-internal.h
@@ -302,6 +302,22 @@ _NM_IN_STRSET_streq (const char *x, const char *s)
/*****************************************************************************/
+#define nm_str_not_empty(str) \
+ ({ \
+ /* implemented as macro to preserve constness */ \
+ typeof (str) __str = (str); \
+ _nm_unused const char *__str_type_check = __str; \
+ ((__str && __str[0]) ? __str : ((char *) NULL)); \
+ })
+
+static inline char *
+nm_strdup_not_empty (const char *str)
+{
+ return str && str[0] ? g_strdup (str) : NULL;
+}
+
+/*****************************************************************************/
+
#define NM_PRINT_FMT_QUOTED(cond, prefix, str, suffix, str_else) \
(cond) ? (prefix) : "", \
(cond) ? (str) : (str_else), \