]>
git.ipfire.org Git - thirdparty/systemd.git/blob - src/home/homework-password-cache.c
1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
3 #include "homework-password-cache.h"
4 #include "keyring-util.h"
5 #include "missing_syscall.h"
6 #include "user-record.h"
8 void password_cache_free(PasswordCache
*cache
) {
12 cache
->pkcs11_passwords
= strv_free_erase(cache
->pkcs11_passwords
);
13 cache
->fido2_passwords
= strv_free_erase(cache
->fido2_passwords
);
16 void password_cache_load_keyring(UserRecord
*h
, PasswordCache
*cache
) {
17 _cleanup_(erase_and_freep
) void *p
= NULL
;
18 _cleanup_free_
char *name
= NULL
;
27 /* Loads the password we need to for automatic resizing from the kernel keyring */
29 name
= strjoin("homework-user-", h
->user_name
);
31 return (void) log_oom();
33 serial
= request_key("user", name
, NULL
, 0);
35 return (void) log_debug_errno(errno
, "Failed to request key '%s', ignoring: %m", name
);
37 r
= keyring_read(serial
, &p
, &sz
);
39 return (void) log_debug_errno(r
, "Failed to read keyring key '%s', ignoring: %m", name
);
42 return (void) log_debug_errno(SYNTHETIC_ERRNO(EINVAL
), "Cached password contains embedded NUL byte, ignoring.");
46 return (void) log_oom();
48 strv
[0] = TAKE_PTR(p
); /* Note that keyring_read() will NUL terminate implicitly, hence we don't have
49 * to NUL terminate manually here: it's a valid string. */
52 strv_free_erase(cache
->keyring_passswords
);
53 cache
->keyring_passswords
= strv
;
55 log_debug("Successfully acquired home key from kernel keyring.");