summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2019-02-21 10:45:20 +0100
committerThomas Haller <thaller@redhat.com>2019-02-22 14:04:13 +0100
commit0e7e8adc128737a75f9515b4929ad607c49a491e (patch)
tree075e26d0ebd47c6bda7d30b22602e606915f37f4
parent3059a30da9707055ca14d24f50469f7427901caf (diff)
downloadNetworkManager-0e7e8adc128737a75f9515b4929ad607c49a491e.tar.gz
cli: rework NM_SETTING_802_1X_PASSWORD_RAW property functions to operate on generic GBytes
Rework the explicit implementation of NM_SETTING_802_1X_PASSWORD_RAW handling to generically handle GBytes properties. Note that the NM_SETTING_802_1X_PASSWORD_RAW setter accepts a legacy format where hex-words are separated by space. I don't think we want to support this format for new options. So, there are two possibilities: 1) either leave _set_fcn_802_1x_password_raw() as-is, with the special handling. 2) interpret a property-data gobject_bytes.legacy_format. 1) seems to make more sense, because there is only one such property, and we won't use this for new properties. However let's do 2), because it shows nicely the two styles side-by-side. In other words, let's password-raw also be a _pt_gobject_bytes typed property, with some special legacy handling. Instead, of having it an entirely separate property type (with a different setter implementation). I think it's better to have the parts where they differ pushed down (the "stack") as much as possible.
-rw-r--r--clients/common/nm-meta-setting-desc.c46
-rw-r--r--clients/common/nm-meta-setting-desc.h3
2 files changed, 32 insertions, 17 deletions
diff --git a/clients/common/nm-meta-setting-desc.c b/clients/common/nm-meta-setting-desc.c
index c112343aeb..fd19be594c 100644
--- a/clients/common/nm-meta-setting-desc.c
+++ b/clients/common/nm-meta-setting-desc.c
@@ -1941,25 +1941,36 @@ nmc_util_is_domain (const char *domain)
}
static gboolean
-nmc_property_set_bytes (NMSetting *setting, const char *prop, const char *value, GError **error)
+_set_fcn_gobject_bytes (ARGS_SET_FCN)
{
- gs_free char *val_strip = NULL;
+ gs_free char *val_strip_free = NULL;
gs_free const char **strv = NULL;
+ const char *val_strip;
const char **iter;
gs_unref_bytes GBytes *bytes = NULL;
GByteArray *array;
nm_assert (!error || !*error);
- val_strip = g_strstrip (g_strdup (value));
+ val_strip = nm_strstrip_avoid_copy (value, &val_strip_free);
/* First try hex string in the format of AAbbCCDd */
bytes = nm_utils_hexstr2bin (val_strip);
if (bytes)
goto done;
+ if ( !property_info->property_typ_data
+ || !property_info->property_typ_data->subtype.gobject_bytes.legacy_format) {
+ if (value && value[0]) {
+ g_set_error_literal (error, 1, 0, _("not a valid hex-string"));
+ return FALSE;
+ }
+ /* accept the emtpy word to reset the property to %NULL. */
+ goto done;
+ }
+
/* Otherwise, consider the following format: AA b 0xCc D */
- strv = nm_utils_strsplit_set (val_strip, " \t", FALSE);
+ strv = nm_utils_strsplit_set (value, " \t", FALSE);
array = g_byte_array_sized_new (NM_PTRARRAY_LEN (strv));
for (iter = strv; iter && *iter; iter++) {
int v;
@@ -1977,7 +1988,7 @@ nmc_property_set_bytes (NMSetting *setting, const char *prop, const char *value,
bytes = g_byte_array_free_to_bytes (array);
done:
- g_object_set (setting, prop, bytes, NULL);
+ g_object_set (setting, property_info->property_name, bytes, NULL);
return TRUE;
}
@@ -2094,14 +2105,16 @@ _get_fcn_802_1x_phase2_client_cert (ARGS_GET_FCN)
}
static gconstpointer
-_get_fcn_802_1x_password_raw (ARGS_GET_FCN)
+_get_fcn_gobject_bytes (ARGS_GET_FCN)
{
- NMSetting8021x *s_8021X = NM_SETTING_802_1X (setting);
+ gs_unref_bytes GBytes *bytes = NULL;
char *str;
RETURN_UNSUPPORTED_GET_TYPE ();
- str = bytes_to_string (nm_setting_802_1x_get_password_raw (s_8021X));
+ g_object_get (setting, property_info->property_name, &bytes, NULL);
+
+ str = bytes_to_string (bytes);
NM_SET_OUT (out_is_default, !str || !str[0]);
RETURN_STR_TO_FREE (str);
}
@@ -2319,12 +2332,6 @@ DEFINE_SETTER_PRIV_KEY (_set_fcn_802_1x_phase2_private_key,
nm_setting_802_1x_get_phase2_private_key_password,
nm_setting_802_1x_set_phase2_private_key)
-static gboolean
-_set_fcn_802_1x_password_raw (ARGS_SET_FCN)
-{
- return nmc_property_set_bytes (setting, property_info->property_name, value, error);
-}
-
static gconstpointer
_get_fcn_bond_options (ARGS_GET_FCN)
{
@@ -5047,6 +5054,11 @@ static const NMMetaPropertyType _pt_gobject_mtu = {
.set_fcn = _set_fcn_gobject_mtu,
};
+static const NMMetaPropertyType _pt_gobject_bytes = {
+ .get_fcn = _get_fcn_gobject_bytes,
+ .set_fcn = _set_fcn_gobject_bytes,
+};
+
static const NMMetaPropertyType _pt_gobject_mac = {
.get_fcn = _get_fcn_gobject,
.set_fcn = _set_fcn_gobject_mac,
@@ -5342,9 +5354,9 @@ static const NMMetaPropertyInfo *const property_infos_802_1X[] = {
"(with optional 0x/0X prefix, and optional leading 0).\n\n"
"Examples: ab0455a6ea3a74C2\n"
" ab 4 55 0xa6 ea 3a 74 C2\n"),
- .property_type = DEFINE_PROPERTY_TYPE (
- .get_fcn = _get_fcn_802_1x_password_raw,
- .set_fcn = _set_fcn_802_1x_password_raw,
+ .property_type = &_pt_gobject_bytes,
+ .property_typ_data = DEFINE_PROPERTY_TYP_DATA_SUBTYPE (gobject_bytes,
+ .legacy_format = TRUE,
),
),
PROPERTY_INFO_WITH_DESC (NM_SETTING_802_1X_PASSWORD_RAW_FLAGS,
diff --git a/clients/common/nm-meta-setting-desc.h b/clients/common/nm-meta-setting-desc.h
index 7129870a25..e3f9d230ee 100644
--- a/clients/common/nm-meta-setting-desc.h
+++ b/clients/common/nm-meta-setting-desc.h
@@ -269,6 +269,9 @@ struct _NMMetaPropertyTypData {
const char *(*validate_fcn) (const char *value, char **out_to_free, GError **error);
} gobject_string;
struct {
+ bool legacy_format:1;
+ } gobject_bytes;
+ struct {
guint32 (*get_fcn) (NMSetting *setting);
} mtu;
struct {