From 94227b44d5e5538b221b7f33ae6e627b86d07593 Mon Sep 17 00:00:00 2001 From: Ingo Franzki Date: Fri, 22 Mar 2019 10:53:34 +0100 Subject: [PATCH] zkey: Store volume type property all uppercase MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The volume type of a secure key is not really case sensitive, but for better usability store and display it in uppercase always, regardless in whatever case it was specified. Signed-off-by: Ingo Franzki Signed-off-by: Jan Höppner --- zkey/keystore.c | 7 ++++--- zkey/properties.c | 28 ++++++++++++++++++++++++++-- zkey/properties.h | 3 +++ 3 files changed, 33 insertions(+), 5 deletions(-) diff --git a/zkey/keystore.c b/zkey/keystore.c index 9a2507c5..ff5563ca 100644 --- a/zkey/keystore.c +++ b/zkey/keystore.c @@ -1617,7 +1617,8 @@ static int _keystore_create_info_file(struct keystore *keystore, rc = -EINVAL; goto out; } - rc = properties_set(key_props, PROP_NAME_VOLUME_TYPE, volume_type); + rc = properties_set2(key_props, PROP_NAME_VOLUME_TYPE, volume_type, + true); if (rc != 0) { warnx("Invalid characters in volume-type"); goto out; @@ -1989,8 +1990,8 @@ int keystore_change_key(struct keystore *keystore, const char *name, goto out; } - rc = properties_set(key_props, PROP_NAME_VOLUME_TYPE, - volume_type); + rc = properties_set2(key_props, PROP_NAME_VOLUME_TYPE, + volume_type, true); if (rc != 0) { warnx("Invalid characters in volume-type"); goto out; diff --git a/zkey/properties.c b/zkey/properties.c index c20e51b7..147bcc5c 100644 --- a/zkey/properties.c +++ b/zkey/properties.c @@ -9,6 +9,7 @@ * it under the terms of the MIT license. See LICENSE for details. */ +#include #include #include #include @@ -183,14 +184,16 @@ static struct property *properties_find(struct properties *properties, * @param[in] properties the properties object * @param[in] name the name of the property * @param[in] value the value of the property + * @param[in] uppercase if true the value is set all uppercase * * @returns 0 on success, * -EINVAL if the name or value contains invalid characters */ -int properties_set(struct properties *properties, - const char *name, const char *value) +int properties_set2(struct properties *properties, + const char *name, const char *value, bool uppercase) { struct property *property; + int i; util_assert(properties != NULL, "Internal error: properties is NULL"); util_assert(name != NULL, "Internal error: name is NULL"); @@ -211,9 +214,30 @@ int properties_set(struct properties *properties, property->value = util_strdup(value); util_list_add_tail(&properties->list, property); } + if (uppercase) { + for (i = 0; property->value[i] != '\0'; i++) + property->value[i] = toupper(property->value[i]); + } + return 0; } +/** + * Adds or updates a property + * + * @param[in] properties the properties object + * @param[in] name the name of the property + * @param[in] value the value of the property + * + * @returns 0 on success, + * -EINVAL if the name or value contains invalid characters + */ +int properties_set(struct properties *properties, + const char *name, const char *value) +{ + return properties_set2(properties, name, value, false); +} + /** * Gets a property * diff --git a/zkey/properties.h b/zkey/properties.h index 234948ec..f2c8a158 100644 --- a/zkey/properties.h +++ b/zkey/properties.h @@ -23,6 +23,9 @@ void properties_free(struct properties *properties); int properties_set(struct properties *properties, const char *name, const char *value); +int properties_set2(struct properties *properties, + const char *name, const char *value, bool uppercase); + char *properties_get(struct properties *properties, const char *name); int properties_remove(struct properties *properties, const char *name);