cli: fix handling 802-1x.password-raw

https://bugzilla.gnome.org/show_bug.cgi?id=782836
This commit is contained in:
Thomas Haller
2017-05-23 13:34:43 +02:00

View File

@@ -1701,11 +1701,12 @@ nmc_util_is_domain (const char *domain)
}
static gboolean
nmc_property_set_byte_array (NMSetting *setting, const char *prop, const char *value, GError **error)
nmc_property_set_bytes (NMSetting *setting, const char *prop, const char *value, GError **error)
{
char **strv = NULL, **iter;
char *val_strip;
gs_free char *val_strip = NULL;
gs_strfreev char **strv = NULL;
const char *delimiters = " \t,";
char **iter;
long int val_int;
GBytes *bytes;
GByteArray *array = NULL;
@@ -1717,30 +1718,33 @@ nmc_property_set_byte_array (NMSetting *setting, const char *prop, const char *v
/* First try hex string in the format of AAbbCCDd */
bytes = nm_utils_hexstr2bin (val_strip);
if (bytes) {
array = g_bytes_unref_to_array (bytes);
if (bytes)
goto done;
}
/* Otherwise, consider the following format: AA b 0xCc D */
strv = nmc_strsplit_set (val_strip, delimiters, 0);
array = g_byte_array_sized_new (g_strv_length (strv));
for (iter = strv; iter && *iter; iter++) {
guint8 v8;
if (!nmc_string_to_int_base (g_strstrip (*iter), 16, TRUE, 0, 255, &val_int)) {
g_set_error (error, 1, 0, _("'%s' is not a valid hex character"), *iter);
g_byte_array_free (array, TRUE);
success = FALSE;
goto done;
}
g_byte_array_append (array, (const guint8 *) &val_int, 1);
v8 = val_int;
g_byte_array_append (array, &v8, 1);
}
bytes = g_byte_array_free_to_bytes (array);
done:
if (success)
g_object_set (setting, prop, array, NULL);
g_object_set (setting, prop, bytes, NULL);
if (bytes)
g_bytes_unref (bytes);
g_strfreev (strv);
if (array)
g_byte_array_free (array, TRUE);
return success;
}
@@ -2076,7 +2080,7 @@ DEFINE_SETTER_PRIV_KEY (_set_fcn_802_1x_phase2_private_key,
static gboolean
_set_fcn_802_1x_password_raw (ARGS_SET_FCN)
{
return nmc_property_set_byte_array (setting, property_info->property_name, value, error);
return nmc_property_set_bytes (setting, property_info->property_name, value, error);
}
static gconstpointer