zkey: Store volume type property all uppercase

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 <ifranzki@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
This commit is contained in:
Ingo Franzki
2019-03-22 10:53:34 +01:00
committed by Jan Höppner
parent a9f4ae2db3
commit 94227b44d5
3 changed files with 33 additions and 5 deletions

View File

@@ -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;

View File

@@ -9,6 +9,7 @@
* it under the terms of the MIT license. See LICENSE for details.
*/
#include <ctype.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
@@ -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
*

View File

@@ -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);