Re: [RFC 1/8] key: add l_key_search
Denis Kenzior <[email protected]> Tue, 22 Nov 2022 10:43:42 -0600
| Newsgroups | dev.linux.lists.ell |
|---|---|
| Message-ID | <[email protected]> |
Hi James,
On 11/18/22 15:16, James Prestwood wrote:
> Search for a key by type, keyring name, and description. Returns the
> key ID or an error if not found.
> ---
> ell/ell.sym | 1 +
> ell/key.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++
> ell/key.h | 3 +++
> 3 files changed, 50 insertions(+)
>
<snip>
> @@ -283,6 +303,32 @@ static bool setup_internal_keyring(void)
> return true;
> }
>
> +LIB_EXPORT int32_t l_key_search(enum l_key_type type, const char *keyring,
How likely are we to search some custom keyring? Wouldn't we generally be
searching a user/default user session keyrings?
> + const char *description)
> +{
> + long keyring_id;
> + long key_id;
> +
> + if (unlikely((size_t)type >= L_ARRAY_SIZE(key_type_names)))
> + return -EINVAL;
> +
> + if (unlikely(!keyring || !description))
> + return -EINVAL;
> +
> + /* Find the ID of the keyring */
> + keyring_id = kernel_key_request("keyring", keyring);
> + if (keyring_id < 0)
> + return -ENOENT;
> +
> + /* Search for the key by type/description */
> + key_id = kernel_key_search(keyring_id, key_type_names[type],
> + description);
> + if (key_id < 0)
> + return -ENOENT;
> +
> + return key_id;
> +}
> +
> LIB_EXPORT struct l_key *l_key_new(enum l_key_type type, const void *payload,
> size_t payload_length)
> {
Regards,
-Denis