Skip to content

Commit b707ef2

Browse files
hreineckeigaw
authored andcommitted
linux: add nvme_lookup_keyring()
Add a function to lookup a keyring by its description. Signed-off-by: Hannes Reinecke <[email protected]> [dwagner: - pass in command line option to dependency requirement argument - drop log message, find_key_by_type_and_desc sets errno] Signed-off-by: Daniel Wagner <[email protected]>
1 parent 81fe208 commit b707ef2

6 files changed

Lines changed: 51 additions & 0 deletions

File tree

meson.build

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,15 @@ endif
9898
conf.set('CONFIG_OPENSSL', openssl_dep.found(),
9999
description: 'Is OpenSSL/LibreSSL available?')
100100

101+
if get_option('keyutils').disabled()
102+
keyutils_dep = dependency('', required: false)
103+
else
104+
keyutils_dep = dependency('libkeyutils',
105+
required : get_option('keyutils'))
106+
endif
107+
conf.set('CONFIG_KEYUTILS', keyutils_dep.found(),
108+
description: 'Is libkeyutils available?')
109+
101110
if get_option('libdbus').disabled()
102111
libdbus_dep = dependency('', required: false)
103112
else

meson_options.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ option('python', type : 'feature', value: 'auto', description : 'Generate libnvm
1111
option('openssl', type : 'feature', value: 'auto', description : 'OpenSSL support')
1212
option('libdbus', type : 'feature', value: 'disabled', description : 'libdbus support')
1313
option('json-c', type : 'feature', value: 'auto', description : 'JSON support')
14+
option('keyutils', type: 'feature', value: 'auto', description: 'keyutils support')

src/libnvme.map

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# SPDX-License-Identifier: LGPL-2.1-or-later
22

3+
LIBNVME_1_4 {
4+
global:
5+
nvme_lookup_keyring;
6+
};
7+
38
LIBNVME_1_3 {
49
global:
510
nvme_ctrl_is_unique_discovery_ctrl;

src/meson.build

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ endif
3232
deps = [
3333
json_c_dep,
3434
openssl_dep,
35+
keyutils_dep,
3536
]
3637

3738
mi_deps = [

src/nvme/linux.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@
2828
#endif
2929
#endif
3030

31+
#ifdef CONFIG_KEYUTILS
32+
#include <keyutils.h>
33+
#endif
34+
3135
#include <ccan/endian/endian.h>
3236

3337
#include "linux.h"
@@ -638,3 +642,23 @@ int nvme_gen_dhchap_key(char *hostnqn, enum nvme_hmac_alg hmac,
638642
return err;
639643
}
640644
#endif /* !CONFIG_OPENSSL_3 */
645+
646+
#ifdef CONFIG_KEYUTILS
647+
long nvme_lookup_keyring(const char *keyring)
648+
{
649+
key_serial_t keyring_id;
650+
651+
keyring_id = find_key_by_type_and_desc("keyring", keyring, 0);
652+
if (keyring_id < 0)
653+
return 0;
654+
return keyring_id;
655+
}
656+
#else
657+
long nvme_lookup_keyring(const char *keyring)
658+
{
659+
nvme_msg(NULL, LOG_ERR, "key operations not supported; "\
660+
"recompile with keyutils support.\n");
661+
errno = ENOTSUP;
662+
return 0;
663+
}
664+
#endif

src/nvme/linux.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,4 +194,15 @@ int nvme_gen_dhchap_key(char *hostnqn, enum nvme_hmac_alg hmac,
194194
unsigned int key_len, unsigned char *secret,
195195
unsigned char *key);
196196

197+
/**
198+
* nvme_lookup_keyring() - Lookup keyring serial number
199+
* @keyring: Keyring name
200+
*
201+
* Looks up the serial number of the keyring @keyring.
202+
*
203+
* Return: The key serial number of the keyring
204+
* or 0 with errno set otherwise.
205+
*/
206+
long nvme_lookup_keyring(const char *keyring);
207+
197208
#endif /* _LIBNVME_LINUX_H */

0 commit comments

Comments
 (0)