From 3361d1ca1b527bc811db543689e77a53f970ca97 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Mon, 18 Oct 2021 15:31:10 +0200 Subject: homework: mae sure PasswordCache is really optional It was supposed to be optional (i.e. there's a reason why we never assert()ed on it), and in many codepaths it is, let's make sure it is everywhere. --- src/home/homework.h | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'src/home/homework.h') diff --git a/src/home/homework.h b/src/home/homework.h index 9331452e3e..5fa4b653e2 100644 --- a/src/home/homework.h +++ b/src/home/homework.h @@ -7,6 +7,7 @@ #include "sd-id128.h" #include "loop-util.h" +#include "strv.h" #include "user-record.h" #include "user-record-util.h" @@ -39,13 +40,21 @@ typedef struct HomeSetup { } HomeSetup; typedef struct PasswordCache { - /* Decoding passwords from security tokens is expensive and typically requires user interaction, hence cache any we already figured out. */ + /* Decoding passwords from security tokens is expensive and typically requires user interaction, + * hence cache any we already figured out. */ char **pkcs11_passwords; char **fido2_passwords; } PasswordCache; void password_cache_free(PasswordCache *cache); +static inline bool password_cache_contains(const PasswordCache *cache, const char *p) { + if (!cache) + return false; + + return strv_contains(cache->pkcs11_passwords, p) || strv_contains(cache->fido2_passwords, p); +} + #define HOME_SETUP_INIT \ { \ .root_fd = -1, \ -- cgit v1.2.1