]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
homework: split out password cache logic into its own .c/.h file
authorLennart Poettering <lennart@poettering.net>
Tue, 2 Nov 2021 22:03:17 +0000 (23:03 +0100)
committerLennart Poettering <lennart@poettering.net>
Fri, 12 Nov 2021 23:22:16 +0000 (00:22 +0100)
Preparation for extending it further down the line.

src/home/homework-password-cache.c [new file with mode: 0644]
src/home/homework-password-cache.h [new file with mode: 0644]
src/home/homework.c
src/home/homework.h
src/home/meson.build

diff --git a/src/home/homework-password-cache.c b/src/home/homework-password-cache.c
new file mode 100644 (file)
index 0000000..87d90c9
--- /dev/null
@@ -0,0 +1,11 @@
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+
+#include "homework-password-cache.h"
+
+void password_cache_free(PasswordCache *cache) {
+        if (!cache)
+                return;
+
+        cache->pkcs11_passwords = strv_free_erase(cache->pkcs11_passwords);
+        cache->fido2_passwords = strv_free_erase(cache->fido2_passwords);
+}
diff --git a/src/home/homework-password-cache.h b/src/home/homework-password-cache.h
new file mode 100644 (file)
index 0000000..6b4de15
--- /dev/null
@@ -0,0 +1,21 @@
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+#pragma once
+
+#include "strv.h"
+#include "user-record.h"
+
+typedef struct PasswordCache {
+        /* 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);
+}
index c9b1734492c2a6fca0f1dd33516332507f7b99ba..65066a5156bab1cf179af3dbc14cb48159e73529 100644 (file)
 /* Make sure a bad password always results in a 3s delay, no matter what */
 #define BAD_PASSWORD_DELAY_USEC (3 * USEC_PER_SEC)
 
-void password_cache_free(PasswordCache *cache) {
-        if (!cache)
-                return;
-
-        cache->pkcs11_passwords = strv_free_erase(cache->pkcs11_passwords);
-        cache->fido2_passwords = strv_free_erase(cache->fido2_passwords);
-}
-
 int user_record_authenticate(
                 UserRecord *h,
                 UserRecord *secret,
index d7ad6fbdfaa88c81d0f723c24d45c371c8d12ed6..053def6360073cc14c237072820d278291cbf548 100644 (file)
@@ -6,8 +6,8 @@
 
 #include "sd-id128.h"
 
+#include "homework-password-cache.h"
 #include "loop-util.h"
-#include "strv.h"
 #include "user-record.h"
 #include "user-record-util.h"
 
@@ -43,22 +43,6 @@ typedef struct HomeSetup {
         char *temporary_image_path;
 } HomeSetup;
 
-typedef struct PasswordCache {
-        /* 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,                          \
index 53a387fd973a6d1d0ac95d01d986df4db79a988b..439eabc9bf18507a9d2376361cb44e57c309dcd9 100644 (file)
@@ -16,6 +16,8 @@ systemd_homework_sources = files('''
         homework-luks.h
         homework-mount.c
         homework-mount.h
+        homework-password-cache.c
+        homework-password-cache.h
         homework-pkcs11.h
         homework-quota.c
         homework-quota.h