Skip to content

Commit 40230e6

Browse files
dwsuseigaw
authored andcommitted
linux: only return the description of a key
keyctl_describe returns a string of format: %s;%d;%d;%08x;%s where the arguments are: key type name, key UID, key GID, key permissions mask and key description. The key description will not contain any semicolons. The last entry contains the description which is what nvme_describe_key_serial promisses to return. Signed-off-by: Daniel Wagner <[email protected]>
1 parent 9e6e8dd commit 40230e6

1 file changed

Lines changed: 14 additions & 4 deletions

File tree

src/nvme/linux.c

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1203,11 +1203,21 @@ long nvme_lookup_keyring(const char *keyring)
12031203

12041204
char *nvme_describe_key_serial(long key_id)
12051205
{
1206-
char *desc;
1206+
_cleanup_free_ char *str = NULL;
1207+
char *last;
12071208

1208-
if (keyctl_describe_alloc(key_id, &desc) < 0)
1209-
desc = NULL;
1210-
return desc;
1209+
if (keyctl_describe_alloc(key_id, &str) < 0)
1210+
return NULL;
1211+
1212+
last = strrchr(str, ';');
1213+
if (!last)
1214+
return NULL;
1215+
1216+
last++;
1217+
if (strlen(last) == 0)
1218+
return NULL;
1219+
1220+
return strdup(last);
12111221
}
12121222

12131223
long nvme_lookup_key(const char *type, const char *identity)

0 commit comments

Comments
 (0)