]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
cryptenroll: Clean up includes
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Wed, 21 May 2025 14:34:29 +0000 (16:34 +0200)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 21 May 2025 16:41:12 +0000 (01:41 +0900)
Split out of #37344.

17 files changed:
src/cryptenroll/cryptenroll-fido2.c
src/cryptenroll/cryptenroll-fido2.h
src/cryptenroll/cryptenroll-list.c
src/cryptenroll/cryptenroll-list.h
src/cryptenroll/cryptenroll-password.c
src/cryptenroll/cryptenroll-password.h
src/cryptenroll/cryptenroll-pkcs11.c
src/cryptenroll/cryptenroll-pkcs11.h
src/cryptenroll/cryptenroll-recovery.c
src/cryptenroll/cryptenroll-recovery.h
src/cryptenroll/cryptenroll-tpm2.c
src/cryptenroll/cryptenroll-tpm2.h
src/cryptenroll/cryptenroll-wipe.c
src/cryptenroll/cryptenroll-wipe.h
src/cryptenroll/cryptenroll.c
src/cryptenroll/cryptenroll.h
src/cryptenroll/meson.build

index f412aac928b0039a8b4ca7e54505341e9596cd1b..e1b8561dd25f992809bc7b78f28795e0f6ba8b88 100644 (file)
@@ -1,17 +1,18 @@
 /* SPDX-License-Identifier: LGPL-2.1-or-later */
 
+#include "alloc-util.h"
 #include "ask-password-api.h"
 #include "cryptenroll-fido2.h"
 #include "cryptsetup-fido2.h"
+#include "cryptsetup-util.h"
 #include "fido2-util.h"
 #include "glyph-util.h"
 #include "hexdecoct.h"
 #include "iovec-util.h"
 #include "json-util.h"
 #include "libfido2-util.h"
-#include "memory-util.h"
 #include "pretty-print.h"
-#include "random-util.h"
+#include "string-util.h"
 
 int load_volume_key_fido2(
                 struct crypt_device *cd,
@@ -20,6 +21,7 @@ int load_volume_key_fido2(
                 void *ret_vk,
                 size_t *ret_vks) {
 
+#if HAVE_LIBFIDO2
         _cleanup_(erase_and_freep) void *decrypted_key = NULL;
         _cleanup_(erase_and_freep) char *passphrase = NULL;
         size_t decrypted_key_size;
@@ -63,6 +65,9 @@ int load_volume_key_fido2(
                 return log_error_errno(r, "Unlocking via FIDO2 device failed: %m");
 
         return r;
+#else
+        return log_debug_errno(SYNTHETIC_ERRNO(EOPNOTSUPP), "FIDO2 unlocking not supported.");
+#endif
 }
 
 int enroll_fido2(
@@ -74,6 +79,7 @@ int enroll_fido2(
                 const char *salt_file,
                 bool parameters_in_header) {
 
+#if HAVE_LIBFIDO2
         _cleanup_(iovec_done_erase) struct iovec salt = {};
         _cleanup_(erase_and_freep) void *secret = NULL;
         _cleanup_(erase_and_freep) char *base64_encoded = NULL;
@@ -202,4 +208,7 @@ int enroll_fido2(
 
         log_info("New FIDO2 token enrolled as key slot %i.", keyslot);
         return keyslot;
+#else
+        return log_debug_errno(SYNTHETIC_ERRNO(EOPNOTSUPP), "FIDO2 key enrollment not supported.");
+#endif
 }
index 0eb2a95e737082daa3d3417cb665495a6bfddc09..931ce94ac84631e99cbf77e293ae1fbf266a9d9f 100644 (file)
@@ -1,24 +1,7 @@
 /* SPDX-License-Identifier: LGPL-2.1-or-later */
 #pragma once
 
-#include <sys/types.h>
+#include "forward.h"
 
-#include "cryptsetup-util.h"
-#include "libfido2-util.h"
-#include "log.h"
-
-#if HAVE_LIBFIDO2
 int load_volume_key_fido2(struct crypt_device *cd, const char *cd_node, const char *device, void *ret_vk, size_t *ret_vks);
 int enroll_fido2(struct crypt_device *cd, const struct iovec *volume_key, const char *device, Fido2EnrollFlags lock_with, int cred_alg, const char *salt_file, bool parameters_in_header);
-
-#else
-static inline int load_volume_key_fido2(struct crypt_device *cd, const char *cd_node, const char *device, void *ret_vk, size_t *ret_vks) {
-        return log_debug_errno(SYNTHETIC_ERRNO(EOPNOTSUPP),
-                               "FIDO2 unlocking not supported.");
-}
-
-static inline int enroll_fido2(struct crypt_device *cd, const struct iovec *volume_key, const char *device, Fido2EnrollFlags lock_with, int cred_alg, const char *salt_file, bool parameters_in_header) {
-        return log_debug_errno(SYNTHETIC_ERRNO(EOPNOTSUPP),
-                               "FIDO2 key enrollment not supported.");
-}
-#endif
index 91f9dd72c2c8bc8c3223c0d867182cf4fa67d26d..32e8c9cf2a32be3b91db5500479fd87ebe31f0d9 100644 (file)
@@ -2,8 +2,10 @@
 
 #include "sd-json.h"
 
+#include "alloc-util.h"
 #include "cryptenroll.h"
 #include "cryptenroll-list.h"
+#include "cryptsetup-util.h"
 #include "format-table.h"
 #include "json-util.h"
 #include "log.h"
index d322988f799793128fe65ed9869d2eab3fccc69e..40270bfeea488b8a1e885c3a710e629ec0c105f3 100644 (file)
@@ -1,6 +1,6 @@
 /* SPDX-License-Identifier: LGPL-2.1-or-later */
 #pragma once
 
-#include "cryptsetup-util.h"
+#include "forward.h"
 
 int list_enrolled(struct crypt_device *cd);
index 078e37900d08939130bb5e0796bf819e3c5d6779..8c7e38b82cc0bbb933860b1ebb86b881555a39e8 100644 (file)
@@ -1,14 +1,16 @@
 /* SPDX-License-Identifier: LGPL-2.1-or-later */
 
+#include "alloc-util.h"
 #include "ask-password-api.h"
 #include "cryptenroll-password.h"
+#include "cryptsetup-util.h"
 #include "env-util.h"
 #include "errno-util.h"
 #include "escape.h"
 #include "iovec-util.h"
 #include "log.h"
-#include "memory-util.h"
 #include "password-quality-util.h"
+#include "string-util.h"
 #include "strv.h"
 
 int load_volume_key_password(
index 4eaf48acba7b96abc6ce19508053ccbf0c3b1e5a..f83e6274692181634fce38f996fc92c4260e1165 100644 (file)
@@ -1,9 +1,7 @@
 /* SPDX-License-Identifier: LGPL-2.1-or-later */
 #pragma once
 
-#include <sys/types.h>
-
-#include "cryptsetup-util.h"
+#include "forward.h"
 
 int load_volume_key_password(struct crypt_device *cd, const char* cd_node, void *ret_vk, size_t *ret_vks);
 int enroll_password(struct crypt_device *cd, const struct iovec *volume_key);
index f59a48984841b6cb0a899f7f5f0bf397959d0052..b6465b915c2d507022f7215dfdeb974252a778b1 100644 (file)
@@ -1,12 +1,14 @@
 /* SPDX-License-Identifier: LGPL-2.1-or-later */
 
+#include "alloc-util.h"
 #include "cryptenroll-pkcs11.h"
+#include "cryptsetup-util.h"
 #include "hexdecoct.h"
 #include "json-util.h"
-#include "memory-util.h"
 #include "openssl-util.h"
 #include "pkcs11-util.h"
 
+#if HAVE_P11KIT && HAVE_OPENSSL
 static int uri_set_private_class(const char *uri, char **ret_uri) {
         _cleanup_(sym_p11_kit_uri_freep) P11KitUri *p11kit_uri = NULL;
         _cleanup_free_ char *private_uri = NULL;
@@ -30,12 +32,10 @@ static int uri_set_private_class(const char *uri, char **ret_uri) {
         *ret_uri = TAKE_PTR(private_uri);
         return 0;
 }
+#endif
 
-int enroll_pkcs11(
-                struct crypt_device *cd,
-                const struct iovec *volume_key,
-                const char *uri) {
-
+int enroll_pkcs11(struct crypt_device *cd, const struct iovec *volume_key,const char *uri) {
+#if HAVE_P11KIT && HAVE_OPENSSL
         _cleanup_(erase_and_freep) void *decrypted_key = NULL;
         _cleanup_(erase_and_freep) char *base64_encoded = NULL;
         _cleanup_(sd_json_variant_unrefp) sd_json_variant *v = NULL;
@@ -112,4 +112,7 @@ int enroll_pkcs11(
 
         log_info("New PKCS#11 token enrolled as key slot %i.", keyslot);
         return keyslot;
+#else
+        return log_debug_errno(SYNTHETIC_ERRNO(EOPNOTSUPP), "PKCS#11 key enrollment not supported.");
+#endif
 }
index 64b7361c55e0846ae6f333fc126daf61781cbb7c..3d5d1e30228d7f490b4394876211cf8559251500 100644 (file)
@@ -1,16 +1,6 @@
 /* SPDX-License-Identifier: LGPL-2.1-or-later */
 #pragma once
 
-#include <sys/types.h>
+#include "forward.h"
 
-#include "cryptsetup-util.h"
-#include "log.h"
-
-#if HAVE_P11KIT && HAVE_OPENSSL
 int enroll_pkcs11(struct crypt_device *cd, const struct iovec *volume_key, const char *uri);
-#else
-static inline int enroll_pkcs11(struct crypt_device *cd, const struct iovec *volume_key, const char *uri) {
-        return log_debug_errno(SYNTHETIC_ERRNO(EOPNOTSUPP),
-                               "PKCS#11 key enrollment not supported.");
-}
-#endif
index 715e1c73879959bd78f249d4ab0424e69728cccd..f9a588da26a3eaef343564fc14fb9e4adb38b76e 100644 (file)
@@ -1,15 +1,15 @@
 /* SPDX-License-Identifier: LGPL-2.1-or-later */
 
+#include "alloc-util.h"
 #include "ansi-color.h"
 #include "cryptenroll-recovery.h"
+#include "cryptsetup-util.h"
 #include "glyph-util.h"
 #include "iovec-util.h"
 #include "json-util.h"
 #include "log.h"
-#include "memory-util.h"
 #include "qrcode-util.h"
 #include "recovery-key.h"
-#include "terminal-util.h"
 
 int enroll_recovery(
                 struct crypt_device *cd,
index 3134d3d1485b357d2296e5973f13b7b5811b686f..c8a947ca3bbf1ec00625e0e9b00d2fef3dea8268 100644 (file)
@@ -1,8 +1,6 @@
 /* SPDX-License-Identifier: LGPL-2.1-or-later */
 #pragma once
 
-#include <sys/types.h>
-
-#include "cryptsetup-util.h"
+#include "forward.h"
 
 int enroll_recovery(struct crypt_device *cd, const struct iovec *volume_key);
index fd03fecc62911ef61048c7a66256de8460bdee9f..48f08e15d2c01033a7562b6770ac9c8a42455742 100644 (file)
@@ -6,17 +6,19 @@
 #include "ask-password-api.h"
 #include "cryptenroll-tpm2.h"
 #include "cryptsetup-tpm2.h"
+#include "cryptsetup-util.h"
 #include "env-util.h"
 #include "errno-util.h"
-#include "fileio.h"
 #include "hexdecoct.h"
 #include "json-util.h"
 #include "log.h"
 #include "memory-util.h"
 #include "random-util.h"
 #include "sha256.h"
+#include "strv.h"
 #include "tpm2-util.h"
 
+#if HAVE_TPM2
 static int search_policy_hash(
                 struct crypt_device *cd,
                 const struct iovec policy_hash[],
@@ -164,6 +166,7 @@ static int get_pin(char **ret_pin_str, TPM2Flags *ret_flags) {
 
         return 0;
 }
+#endif
 
 int load_volume_key_tpm2(
                 struct crypt_device *cd,
@@ -172,6 +175,7 @@ int load_volume_key_tpm2(
                 void *ret_vk,
                 size_t *ret_vks) {
 
+#if HAVE_TPM2
         _cleanup_(iovec_done_erase) struct iovec decrypted_key = {};
         _cleanup_(erase_and_freep) char *passphrase = NULL;
         ssize_t passphrase_size;
@@ -279,6 +283,9 @@ int load_volume_key_tpm2(
                 return log_error_errno(r, "Unlocking via TPM2 device failed: %m");
 
         return r;
+#else
+        return log_debug_errno(SYNTHETIC_ERRNO(EOPNOTSUPP), "TPM2 unlocking not supported.");
+#endif
 }
 
 int enroll_tpm2(struct crypt_device *cd,
@@ -296,6 +303,7 @@ int enroll_tpm2(struct crypt_device *cd,
                 const char *pcrlock_path,
                 int *ret_slot_to_wipe) {
 
+#if HAVE_TPM2
         _cleanup_(sd_json_variant_unrefp) sd_json_variant *v = NULL, *signature_json = NULL;
         _cleanup_(erase_and_freep) char *base64_encoded = NULL;
         _cleanup_(iovec_done) struct iovec srk = {}, pubkey = {};
@@ -605,4 +613,7 @@ int enroll_tpm2(struct crypt_device *cd,
 
         *ret_slot_to_wipe = slot_to_wipe;
         return keyslot;
+#else
+        return log_debug_errno(SYNTHETIC_ERRNO(EOPNOTSUPP), "TPM2 key enrollment not supported.");
+#endif
 }
index efc93f1770e4833e151085e6b23cf9e64ea1908e..079da9271e649b1475067287f5ebe9b0cf774d7b 100644 (file)
@@ -1,23 +1,7 @@
 /* SPDX-License-Identifier: LGPL-2.1-or-later */
 #pragma once
 
-#include <sys/types.h>
+#include "forward.h"
 
-#include "cryptsetup-util.h"
-#include "log.h"
-#include "tpm2-util.h"
-
-#if HAVE_TPM2
 int load_volume_key_tpm2(struct crypt_device *cd, const char *cd_node, const char *device, void *ret_vk, size_t *ret_vks);
 int enroll_tpm2(struct crypt_device *cd, const struct iovec *volume_key, const char *device, uint32_t seal_key_handle, const char *device_key, Tpm2PCRValue *hash_pcr_values, size_t n_hash_pcr_values, const char *pubkey_path, bool load_pcr_pubkey, uint32_t pubkey_pcr_mask, const char *signature_path, bool use_pin, const char *pcrlock_path, int *ret_slot_to_wipe);
-#else
-static inline int load_volume_key_tpm2(struct crypt_device *cd, const char *cd_node, const char *device, void *ret_vk, size_t *ret_vks) {
-        return log_debug_errno(SYNTHETIC_ERRNO(EOPNOTSUPP),
-                               "TPM2 unlocking not supported.");
-}
-
-static inline int enroll_tpm2(struct crypt_device *cd, const struct iovec *volume_key, const char *device, uint32_t seal_key_handle, const char *device_key, Tpm2PCRValue *hash_pcr_values, size_t n_hash_pcr_values, const char *pubkey_path, bool load_pcr_pubkey, uint32_t pubkey_pcr_mask, const char *signature_path, bool use_pin, const char *pcrlock_path, int *ret_slot_to_wipe) {
-        return log_debug_errno(SYNTHETIC_ERRNO(EOPNOTSUPP),
-                               "TPM2 key enrollment not supported.");
-}
-#endif
index 05f862dafdd2cf150d265441333f1e3ec8c4bc56..1ae92bf91b8fbf9e80676f600dc9f59a66965cc4 100644 (file)
@@ -1,12 +1,11 @@
 /* SPDX-License-Identifier: LGPL-2.1-or-later */
 
-#include "sd-json.h"
-
+#include "alloc-util.h"
 #include "cryptenroll.h"
 #include "cryptenroll-wipe.h"
+#include "cryptsetup-util.h"
 #include "json-util.h"
 #include "log.h"
-#include "memory-util.h"
 #include "parse-util.h"
 #include "set.h"
 #include "sort-util.h"
index 5bcd78391a91ba11cffd2dabd3a55a06d2ec8fbf..d2679c306a2a486e353befd2ffe64a7cb4669165 100644 (file)
@@ -1,8 +1,9 @@
 /* SPDX-License-Identifier: LGPL-2.1-or-later */
 #pragma once
 
-#include "cryptenroll.h"
-#include "cryptsetup-util.h"
+#include "forward.h"
+
+typedef enum WipeScope WipeScope;
 
 int wipe_slots(struct crypt_device *cd,
                const int explicit_slots[],
index 51e9b705916bdc1cbb872198b2652e05fd30a0c6..2f20af7e52035365024561a6db6c0d1c082525ee 100644 (file)
@@ -3,7 +3,8 @@
 #include <getopt.h>
 #include <sys/mman.h>
 
-#include "ask-password-api.h"
+#include "sd-device.h"
+
 #include "blockdev-list.h"
 #include "blockdev-util.h"
 #include "build.h"
 #include "cryptenroll-tpm2.h"
 #include "cryptenroll-wipe.h"
 #include "cryptsetup-util.h"
-#include "devnum-util.h"
-#include "env-util.h"
-#include "escape.h"
 #include "extract-word.h"
 #include "fileio.h"
 #include "libfido2-util.h"
+#include "log.h"
 #include "main-func.h"
-#include "memory-util.h"
 #include "pager.h"
 #include "parse-argument.h"
 #include "parse-util.h"
-#include "path-util.h"
 #include "pkcs11-util.h"
 #include "pretty-print.h"
 #include "string-table.h"
-#include "strv.h"
-#include "terminal-util.h"
+#include "string-util.h"
 #include "tpm2-pcr.h"
+#include "tpm2-util.h"
 
 static EnrollType arg_enroll_type = _ENROLL_TYPE_INVALID;
 static char *arg_unlock_keyfile = NULL;
index 08ded3e0e85b2d311021b7f66252712ff8d830f2..6a2f36c36aa40622ba452583699d7241620a2b10 100644 (file)
@@ -1,7 +1,7 @@
 /* SPDX-License-Identifier: LGPL-2.1-or-later */
 #pragma once
 
-#include <errno.h>
+#include "forward.h"
 
 typedef enum EnrollType {
         ENROLL_PASSWORD,
index 902d91cb9431375d478431640ba3a9b5fcce9e2d..488ceea14d1effb2df82acc3a08fded7b19af319 100644 (file)
@@ -5,25 +5,16 @@ if conf.get('HAVE_LIBCRYPTSETUP') != 1
 endif
 
 systemd_cryptenroll_sources = files(
+        'cryptenroll.c',
+        'cryptenroll-fido2.c',
         'cryptenroll-list.c',
         'cryptenroll-password.c',
+        'cryptenroll-pkcs11.c',
         'cryptenroll-recovery.c',
+        'cryptenroll-tpm2.c',
         'cryptenroll-wipe.c',
-        'cryptenroll.c',
 )
 
-if conf.get('HAVE_P11KIT') == 1 and conf.get('HAVE_OPENSSL') == 1
-        systemd_cryptenroll_sources += files('cryptenroll-pkcs11.c')
-endif
-
-if conf.get('HAVE_LIBFIDO2') == 1
-        systemd_cryptenroll_sources += files('cryptenroll-fido2.c')
-endif
-
-if conf.get('HAVE_TPM2') == 1
-        systemd_cryptenroll_sources += files('cryptenroll-tpm2.c')
-endif
-
 executables += [
         executable_template + {
                 'name' : 'systemd-cryptenroll',