From: Daan De Meyer Date: Wed, 21 May 2025 11:49:13 +0000 (+0200) Subject: home: Clean up includes X-Git-Tag: v258-rc1~554 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=572c1fe6859ce0d7354d34e095a793c708b5c457;p=thirdparty%2Fsystemd.git home: Clean up includes Split out of #37344. --- diff --git a/src/home/home-util.c b/src/home/home-util.c index b695c5a49dd..1e9d120a18b 100644 --- a/src/home/home-util.c +++ b/src/home/home-util.c @@ -2,17 +2,22 @@ #include +#include "sd-bus.h" + #include "alloc-util.h" #include "dns-domain.h" #include "fd-util.h" +#include "hash-funcs.h" #include "home-util.h" -#include "libcrypt-util.h" -#include "memory-util.h" #include "path-util.h" #include "string-util.h" #include "strv.h" +#include "user-record.h" #include "user-util.h" +/* This should be 83% right now, i.e. 100 of (100 + 20). Let's protect us against accidental changes. */ +assert_cc(USER_DISK_SIZE_DEFAULT_PERCENT == 83U); + DEFINE_HASH_OPS_FULL(blob_fd_hash_ops, char, path_hash_func, path_compare, free, void, close_fd_ptr); bool suitable_user_name(const char *name) { diff --git a/src/home/home-util.h b/src/home/home-util.h index f8472cb7c86..425ad7be631 100644 --- a/src/home/home-util.h +++ b/src/home/home-util.h @@ -1,13 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include - -#include "sd-bus.h" - -#include "hash-funcs.h" -#include "time-util.h" -#include "user-record.h" +#include "forward.h" /* Flags supported by UpdateEx() */ #define SD_HOMED_UPDATE_OFFLINE (UINT64_C(1) << 0) @@ -25,9 +19,6 @@ * rebalancing. */ #define USER_DISK_SIZE_DEFAULT_PERCENT ((unsigned) ((100 * REBALANCE_WEIGHT_DEFAULT) / (REBALANCE_WEIGHT_DEFAULT + REBALANCE_WEIGHT_BACKING))) -/* This should be 83% right now, i.e. 100 of (100 + 20). Let's protect us against accidental changes. */ -assert_cc(USER_DISK_SIZE_DEFAULT_PERCENT == 83U); - extern const struct hash_ops blob_fd_hash_ops; bool suitable_user_name(const char *name); diff --git a/src/home/homectl-fido2.c b/src/home/homectl-fido2.c index 1b89e588906..2c44d00324e 100644 --- a/src/home/homectl-fido2.c +++ b/src/home/homectl-fido2.c @@ -1,14 +1,8 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ -#if HAVE_LIBFIDO2 -#include -#endif - #include "alloc-util.h" -#include "ask-password-api.h" #include "errno-util.h" #include "fido2-util.h" -#include "format-table.h" #include "hexdecoct.h" #include "homectl-fido2.h" #include "homectl-pkcs11.h" @@ -16,10 +10,7 @@ #include "json-util.h" #include "libcrypt-util.h" #include "libfido2-util.h" -#include "locale-util.h" #include "log.h" -#include "memory-util.h" -#include "random-util.h" #include "string-util.h" #include "strv.h" diff --git a/src/home/homectl-fido2.h b/src/home/homectl-fido2.h index 2ced71c97aa..840dd79d197 100644 --- a/src/home/homectl-fido2.h +++ b/src/home/homectl-fido2.h @@ -1,8 +1,6 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include "sd-json.h" - -#include "libfido2-util.h" +#include "forward.h" int identity_add_fido2_parameters(sd_json_variant **v, const char *device, Fido2EnrollFlags lock_with, int cred_alg); diff --git a/src/home/homectl-pkcs11.c b/src/home/homectl-pkcs11.c index c80cfc52161..12037a667de 100644 --- a/src/home/homectl-pkcs11.c +++ b/src/home/homectl-pkcs11.c @@ -1,14 +1,15 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ +#include "sd-json.h" + #include "errno-util.h" -#include "format-table.h" #include "hexdecoct.h" #include "homectl-pkcs11.h" #include "libcrypt-util.h" #include "log.h" -#include "memory-util.h" #include "openssl-util.h" #include "pkcs11-util.h" +#include "string-util.h" #include "strv.h" int identity_add_token_pin(sd_json_variant **v, const char *pin) { @@ -145,7 +146,10 @@ static int add_pkcs11_encrypted_key( return 0; } +#endif + int identity_add_pkcs11_key_data(sd_json_variant **v, const char *uri) { +#if HAVE_P11KIT _cleanup_(erase_and_freep) void *decrypted_key = NULL, *saved_key = NULL; _cleanup_(erase_and_freep) char *pin = NULL; size_t decrypted_key_size, saved_key_size; @@ -191,6 +195,7 @@ int identity_add_pkcs11_key_data(sd_json_variant **v, const char *uri) { return r; return 0; -} - +#else + return log_error_errno(SYNTHETIC_ERRNO(EOPNOTSUPP), "PKCS#11 tokens not supported on this build."); #endif +} diff --git a/src/home/homectl-pkcs11.h b/src/home/homectl-pkcs11.h index ffe0bd90fbc..cee12b49eda 100644 --- a/src/home/homectl-pkcs11.h +++ b/src/home/homectl-pkcs11.h @@ -1,19 +1,10 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include "sd-json.h" - -#include "log.h" +#include "forward.h" int identity_add_token_pin(sd_json_variant **v, const char *pin); - -#if HAVE_P11KIT int identity_add_pkcs11_key_data(sd_json_variant **v, const char *token_uri); -#else -static inline int identity_add_pkcs11_key_data(sd_json_variant **v, const char *token_uri) { - return log_error_errno(SYNTHETIC_ERRNO(EOPNOTSUPP), "PKCS#11 tokens not supported on this build."); -} -#endif int list_pkcs11_tokens(void); int find_pkcs11_token_auto(char **ret); diff --git a/src/home/homectl-recovery-key.c b/src/home/homectl-recovery-key.c index bb4a01f8959..ad1850d0564 100644 --- a/src/home/homectl-recovery-key.c +++ b/src/home/homectl-recovery-key.c @@ -9,10 +9,8 @@ #include "log.h" #include "memory-util.h" #include "qrcode-util.h" -#include "random-util.h" #include "recovery-key.h" #include "strv.h" -#include "terminal-util.h" static int add_privileged(sd_json_variant **v, const char *hashed) { _cleanup_(sd_json_variant_unrefp) sd_json_variant *e = NULL, *w = NULL, *l = NULL; diff --git a/src/home/homectl-recovery-key.h b/src/home/homectl-recovery-key.h index 387ae64df5f..5a48f5fec10 100644 --- a/src/home/homectl-recovery-key.h +++ b/src/home/homectl-recovery-key.h @@ -1,6 +1,6 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include "sd-json.h" +#include "forward.h" int identity_add_recovery_key(sd_json_variant **v); diff --git a/src/home/homectl.c b/src/home/homectl.c index 8c220666528..ea5e27bfa95 100644 --- a/src/home/homectl.c +++ b/src/home/homectl.c @@ -13,15 +13,16 @@ #include "cap-list.h" #include "capability-util.h" #include "cgroup-util.h" -#include "copy.h" #include "creds-util.h" #include "dirent-util.h" #include "dns-domain.h" #include "env-util.h" +#include "errno-util.h" #include "extract-word.h" #include "fd-util.h" #include "fileio.h" #include "format-table.h" +#include "format-util.h" #include "fs-util.h" #include "glyph-util.h" #include "hashmap.h" @@ -34,7 +35,6 @@ #include "libfido2-util.h" #include "locale-util.h" #include "main-func.h" -#include "memory-util.h" #include "openssl-util.h" #include "pager.h" #include "parse-argument.h" @@ -49,8 +49,12 @@ #include "process-util.h" #include "recurse-dir.h" #include "rlimit-util.h" -#include "rm-rf.h" +#include "runtime-scope.h" +#include "stat-util.h" +#include "string-util.h" +#include "strv.h" #include "terminal-util.h" +#include "time-util.h" #include "uid-classification.h" #include "user-record.h" #include "user-record-password-quality.h" diff --git a/src/home/homed-bus.c b/src/home/homed-bus.c index 5ea50ca66c1..2491a887fec 100644 --- a/src/home/homed-bus.c +++ b/src/home/homed-bus.c @@ -1,11 +1,15 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ +#include "sd-bus.h" +#include "sd-json.h" + #include "alloc-util.h" #include "fd-util.h" +#include "hashmap.h" #include "home-util.h" #include "homed-bus.h" #include "stat-util.h" -#include "strv.h" +#include "user-record.h" int bus_message_read_secret(sd_bus_message *m, UserRecord **ret, sd_bus_error *error) { _cleanup_(sd_json_variant_unrefp) sd_json_variant *v = NULL, *full = NULL; diff --git a/src/home/homed-bus.h b/src/home/homed-bus.h index c7e11efdfb0..4adb60e8a26 100644 --- a/src/home/homed-bus.h +++ b/src/home/homed-bus.h @@ -1,11 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include "sd-bus.h" -#include "sd-json.h" - -#include "hashmap.h" -#include "user-record.h" +#include "forward.h" int bus_message_read_secret(sd_bus_message *m, UserRecord **ret, sd_bus_error *error); int bus_message_read_home_record(sd_bus_message *m, UserRecordLoadFlags flags, UserRecord **ret, sd_bus_error *error); diff --git a/src/home/homed-conf.c b/src/home/homed-conf.c index 87b3e8cd845..b1e71b7dbc6 100644 --- a/src/home/homed-conf.c +++ b/src/home/homed-conf.c @@ -1,9 +1,10 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #include "conf-parser.h" -#include "constants.h" #include "home-util.h" #include "homed-conf.h" +#include "string-util.h" +#include "user-record.h" int manager_parse_config_file(Manager *m) { diff --git a/src/home/homed-conf.h b/src/home/homed-conf.h index 1defaa998b6..093dfeff76f 100644 --- a/src/home/homed-conf.h +++ b/src/home/homed-conf.h @@ -1,8 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include "conf-parser.h" -#include "homed-manager.h" +#include "homed-forward.h" int manager_parse_config_file(Manager *m); diff --git a/src/home/homed-forward.h b/src/home/homed-forward.h new file mode 100644 index 00000000000..3672b163d68 --- /dev/null +++ b/src/home/homed-forward.h @@ -0,0 +1,9 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +#pragma once + +#include "conf-parser-forward.h" /* IWYU pragma: export */ +#include "forward.h" /* IWYU pragma: export */ + +typedef struct Manager Manager; +typedef struct Home Home; +typedef struct Operation Operation; diff --git a/src/home/homed-gperf.gperf b/src/home/homed-gperf.gperf index d5b798a411c..b96a4f167ae 100644 --- a/src/home/homed-gperf.gperf +++ b/src/home/homed-gperf.gperf @@ -7,6 +7,7 @@ _Pragma("GCC diagnostic ignored \"-Wzero-as-null-pointer-constant\"") #include #include "conf-parser.h" #include "homed-conf.h" +#include "homed-manager.h" %} struct ConfigPerfItem; %null_strings diff --git a/src/home/homed-home-bus.c b/src/home/homed-home-bus.c index 732f6d5e9a9..bec95aea6d3 100644 --- a/src/home/homed-home-bus.c +++ b/src/home/homed-home-bus.c @@ -1,18 +1,23 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ -#include +#include "sd-bus.h" +#include "sd-event.h" #include "alloc-util.h" #include "bus-common-errors.h" +#include "bus-object.h" #include "bus-polkit.h" #include "fd-util.h" #include "format-util.h" +#include "hashmap.h" #include "home-util.h" #include "homed-bus.h" #include "homed-home.h" #include "homed-home-bus.h" #include "homed-manager.h" +#include "homed-operation.h" #include "log.h" +#include "string-util.h" #include "strv.h" #include "user-record-util.h" #include "user-util.h" diff --git a/src/home/homed-home-bus.h b/src/home/homed-home-bus.h index 8d4ddf909f3..da784daa9a3 100644 --- a/src/home/homed-home-bus.h +++ b/src/home/homed-home-bus.h @@ -1,10 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include "sd-bus.h" - -#include "bus-object.h" -#include "homed-home.h" +#include "homed-forward.h" int bus_home_get_record_json(Home *h, sd_bus_message *message, char **ret, bool *ret_incomplete); diff --git a/src/home/homed-home.c b/src/home/homed-home.c index 58a8ffff833..2d292163d09 100644 --- a/src/home/homed-home.c +++ b/src/home/homed-home.c @@ -4,6 +4,8 @@ #include #include +#include "sd-bus.h" + #include "blockdev-util.h" #include "btrfs-util.h" #include "build-path.h" @@ -17,29 +19,30 @@ #include "fd-util.h" #include "fileio.h" #include "filesystems.h" -#include "fs-util.h" +#include "format-util.h" #include "glyph-util.h" #include "home-util.h" #include "homed-home.h" #include "homed-home-bus.h" #include "homed-manager.h" +#include "homed-operation.h" #include "json-util.h" #include "log.h" #include "memfd-util.h" -#include "missing_magic.h" #include "missing_mman.h" #include "mkdir.h" +#include "ordered-set.h" #include "parse-util.h" #include "path-util.h" #include "process-util.h" #include "quota-util.h" #include "resize-fs.h" #include "rm-rf.h" -#include "set.h" #include "signal-util.h" #include "stat-util.h" #include "string-table.h" #include "strv.h" +#include "time-util.h" #include "uid-classification.h" #include "user-record.h" #include "user-record-password-quality.h" diff --git a/src/home/homed-home.h b/src/home/homed-home.h index 7d29e554a33..8fcdca32ce4 100644 --- a/src/home/homed-home.h +++ b/src/home/homed-home.h @@ -1,15 +1,10 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include "hashmap.h" -#include "homed-operation.h" -#include "list.h" -#include "ordered-set.h" +#include "forward.h" +#include "homed-forward.h" #include "pidref.h" #include "stat-util.h" -#include "user-record.h" - -typedef struct Manager Manager; typedef enum HomeState { HOME_UNFIXATED, /* home exists, but local record does not */ diff --git a/src/home/homed-manager-bus.c b/src/home/homed-manager-bus.c index 2280cb77688..77b8ed92ee1 100644 --- a/src/home/homed-manager-bus.c +++ b/src/home/homed-manager-bus.c @@ -1,21 +1,30 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ -#include +#include +#include + +#include "sd-bus.h" +#include "sd-event.h" #include "alloc-util.h" #include "bus-common-errors.h" #include "bus-message-util.h" +#include "bus-object.h" #include "bus-polkit.h" #include "fileio.h" #include "format-util.h" #include "home-util.h" #include "homed-bus.h" #include "homed-home-bus.h" +#include "homed-home.h" #include "homed-manager.h" #include "homed-manager-bus.h" +#include "homed-operation.h" #include "log.h" #include "openssl-util.h" #include "path-util.h" +#include "set.h" +#include "string-util.h" #include "strv.h" #include "user-record-sign.h" #include "user-record-util.h" diff --git a/src/home/homed-manager-bus.h b/src/home/homed-manager-bus.h index 56aca18b7d7..4ba561ea347 100644 --- a/src/home/homed-manager-bus.h +++ b/src/home/homed-manager-bus.h @@ -1,6 +1,6 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include "bus-object.h" +#include "homed-forward.h" extern const BusObjectImplementation manager_object; diff --git a/src/home/homed-manager.c b/src/home/homed-manager.c index 5575662ca62..511bc81707e 100644 --- a/src/home/homed-manager.c +++ b/src/home/homed-manager.c @@ -1,54 +1,62 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #include +#include #include #include #include #include +#include #include #include #include +#include "sd-bus.h" +#include "sd-event.h" +#include "sd-gpt.h" #include "sd-id128.h" +#include "alloc-util.h" #include "btrfs-util.h" #include "bus-common-errors.h" #include "bus-error.h" #include "bus-log-control-api.h" -#include "bus-polkit.h" +#include "bus-object.h" #include "clean-ipc.h" #include "common-signal.h" #include "conf-files.h" #include "device-util.h" #include "dirent-util.h" +#include "errno-util.h" #include "fd-util.h" +#include "fdset.h" #include "fileio.h" #include "format-util.h" #include "fs-util.h" #include "glyph-util.h" -#include "gpt.h" #include "home-util.h" #include "homed-conf.h" #include "homed-home.h" -#include "homed-home-bus.h" #include "homed-manager.h" #include "homed-manager-bus.h" +#include "homed-operation.h" #include "homed-varlink.h" -#include "io-util.h" -#include "missing_fs.h" #include "mkdir.h" #include "notify-recv.h" #include "openssl-util.h" -#include "process-util.h" +#include "ordered-set.h" #include "quota-util.h" #include "random-util.h" #include "resize-fs.h" #include "rm-rf.h" -#include "socket-util.h" +#include "set.h" +#include "siphash24.h" #include "sort-util.h" #include "stat-util.h" +#include "string-util.h" #include "strv.h" #include "sync-util.h" +#include "time-util.h" #include "tmpfile-util.h" #include "udev-util.h" #include "user-record.h" diff --git a/src/home/homed-manager.h b/src/home/homed-manager.h index f8490a56399..fe1041e01e5 100644 --- a/src/home/homed-manager.h +++ b/src/home/homed-manager.h @@ -3,13 +3,8 @@ #include -#include "sd-bus.h" -#include "sd-device.h" -#include "sd-event.h" -#include "sd-varlink.h" - -#include "hashmap.h" -#include "homed-home.h" +#include "homed-forward.h" +#include "user-record.h" /* The LUKS free disk space rebalancing logic goes through this state machine */ typedef enum RebalanceState { diff --git a/src/home/homed-operation.c b/src/home/homed-operation.c index ba6e602828c..c40d8025e3a 100644 --- a/src/home/homed-operation.c +++ b/src/home/homed-operation.c @@ -1,9 +1,12 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ +#include "sd-bus.h" + #include "alloc-util.h" #include "fd-util.h" #include "homed-operation.h" #include "log.h" +#include "user-record.h" Operation *operation_new(OperationType type, sd_bus_message *m) { Operation *o; diff --git a/src/home/homed-operation.h b/src/home/homed-operation.h index e190e8e9704..9bb7aba59a2 100644 --- a/src/home/homed-operation.h +++ b/src/home/homed-operation.h @@ -1,9 +1,9 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include "sd-bus.h" +#include "sd-bus-protocol.h" -#include "user-record.h" +#include "homed-forward.h" typedef enum OperationType { OPERATION_ACQUIRE, /* enqueued on AcquireHome() */ diff --git a/src/home/homed-varlink.c b/src/home/homed-varlink.c index e3a748e2512..92e59922587 100644 --- a/src/home/homed-varlink.c +++ b/src/home/homed-varlink.c @@ -1,10 +1,15 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ -#include "format-util.h" +#include "sd-varlink.h" + #include "group-record.h" +#include "hashmap.h" +#include "homed-home.h" +#include "homed-manager.h" #include "homed-varlink.h" #include "json-util.h" #include "log.h" +#include "string-util.h" #include "strv.h" #include "user-record.h" #include "user-record-util.h" diff --git a/src/home/homed-varlink.h b/src/home/homed-varlink.h index 9bfea3a448b..90c2f55256c 100644 --- a/src/home/homed-varlink.h +++ b/src/home/homed-varlink.h @@ -1,7 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include "homed-manager.h" +#include "homed-forward.h" int vl_method_get_user_record(sd_varlink *link, sd_json_variant *parameters, sd_varlink_method_flags_t flags, void *userdata); int vl_method_get_group_record(sd_varlink *link, sd_json_variant *parameters, sd_varlink_method_flags_t flags, void *userdata); diff --git a/src/home/homed.c b/src/home/homed.c index 652e32ec7c1..bb319925d03 100644 --- a/src/home/homed.c +++ b/src/home/homed.c @@ -1,9 +1,11 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #include -#include + +#include "sd-event.h" #include "bus-log-control-api.h" +#include "bus-object.h" #include "daemon-util.h" #include "homed-manager.h" #include "homed-manager-bus.h" diff --git a/src/home/homework-blob.c b/src/home/homework-blob.c index b9c71b56e73..6cd38fca5e5 100644 --- a/src/home/homework-blob.c +++ b/src/home/homework-blob.c @@ -1,24 +1,25 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ +#include + +#include "alloc-util.h" #include "copy.h" #include "fd-util.h" -#include "fileio.h" #include "format-util.h" #include "fs-util.h" +#include "hashmap.h" #include "home-util.h" -#include "homework.h" #include "homework-blob.h" #include "install-file.h" #include "log.h" -#include "macro.h" -#include "path-util.h" #include "recurse-dir.h" #include "rm-rf.h" #include "sha256.h" -#include "string-util.h" +#include "stat-util.h" #include "tmpfile-util.h" -#include "umask-util.h" -#include "utf8.h" +#include "user-record-util.h" +#include "user-record.h" +#include "user-util.h" static int copy_one_blob( int src_fd, diff --git a/src/home/homework-blob.h b/src/home/homework-blob.h index fbe6c82cd4f..4d345d10b75 100644 --- a/src/home/homework-blob.h +++ b/src/home/homework-blob.h @@ -2,7 +2,7 @@ #pragma once -#include "user-record.h" +#include "homework-forward.h" int home_reconcile_blob_dirs(UserRecord *h, int root_fd, int reconciled); diff --git a/src/home/homework-cifs.c b/src/home/homework-cifs.c index 6c18472d581..d04f65a3f82 100644 --- a/src/home/homework-cifs.c +++ b/src/home/homework-cifs.c @@ -2,20 +2,24 @@ #include -#include "dirent-util.h" +#include "alloc-util.h" +#include "env-util.h" #include "fd-util.h" -#include "fileio.h" #include "format-util.h" #include "fs-util.h" +#include "homework.h" #include "homework-cifs.h" #include "homework-mount.h" #include "log.h" #include "memfd-util.h" -#include "mkdir.h" #include "mount-util.h" +#include "path-util.h" #include "process-util.h" #include "stat-util.h" +#include "string-util.h" #include "strv.h" +#include "user-record-util.h" +#include "user-record.h" int home_setup_cifs( UserRecord *h, diff --git a/src/home/homework-cifs.h b/src/home/homework-cifs.h index af8c466629a..9945335b3b2 100644 --- a/src/home/homework-cifs.h +++ b/src/home/homework-cifs.h @@ -1,8 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include "homework.h" -#include "user-record.h" +#include "homework-forward.h" int home_setup_cifs(UserRecord *h, HomeSetupFlags flags, HomeSetup *setup); diff --git a/src/home/homework-directory.c b/src/home/homework-directory.c index e471a4a92af..65ead3ffd37 100644 --- a/src/home/homework-directory.c +++ b/src/home/homework-directory.c @@ -3,6 +3,7 @@ #include #include "btrfs-util.h" +#include "errno-util.h" #include "fd-util.h" #include "homework-blob.h" #include "homework-directory.h" @@ -11,10 +12,13 @@ #include "log.h" #include "mkdir.h" #include "mount-util.h" -#include "path-util.h" +#include "homework.h" #include "rm-rf.h" +#include "string-util.h" #include "tmpfile-util.h" #include "umask-util.h" +#include "user-record-util.h" +#include "user-record.h" #include "user-util.h" int home_setup_directory(UserRecord *h, HomeSetup *setup) { diff --git a/src/home/homework-directory.h b/src/home/homework-directory.h index fe03e5deb19..fe51748e45c 100644 --- a/src/home/homework-directory.h +++ b/src/home/homework-directory.h @@ -1,8 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include "homework.h" -#include "user-record.h" +#include "homework-forward.h" int home_setup_directory(UserRecord *h, HomeSetup *setup); int home_activate_directory(UserRecord *h, HomeSetupFlags flags, HomeSetup *setup, PasswordCache *cache, UserRecord **ret_home); diff --git a/src/home/homework-fido2.c b/src/home/homework-fido2.c index 483487aecc6..bbd38c58b1d 100644 --- a/src/home/homework-fido2.c +++ b/src/home/homework-fido2.c @@ -1,13 +1,12 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ -#include - #include "hexdecoct.h" #include "homework-fido2.h" #include "libfido2-util.h" #include "log.h" #include "memory-util.h" #include "strv.h" +#include "user-record.h" int fido2_use_token( UserRecord *h, @@ -15,6 +14,7 @@ int fido2_use_token( const Fido2HmacSalt *salt, char **ret) { +#if HAVE_LIBFIDO2 _cleanup_(erase_and_freep) void *hmac = NULL; size_t hmac_size; Fido2EnrollFlags flags = 0; @@ -72,4 +72,7 @@ int fido2_use_token( return log_error_errno(ss, "Failed to base64 encode HMAC secret: %m"); return 0; +#else + return log_error_errno(SYNTHETIC_ERRNO(EOPNOTSUPP), "FIDO2 token support not available."); +#endif } diff --git a/src/home/homework-fido2.h b/src/home/homework-fido2.h index a1dcba2d86c..d4355700a14 100644 --- a/src/home/homework-fido2.h +++ b/src/home/homework-fido2.h @@ -1,6 +1,6 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include "user-record.h" +#include "homework-forward.h" int fido2_use_token(UserRecord *h, UserRecord *secret, const Fido2HmacSalt *salt, char **ret); diff --git a/src/home/homework-forward.h b/src/home/homework-forward.h new file mode 100644 index 00000000000..21871d4deb1 --- /dev/null +++ b/src/home/homework-forward.h @@ -0,0 +1,9 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +#pragma once + +#include "forward.h" /* IWYU pragma: export */ + +typedef enum HomeSetupFlags HomeSetupFlags; + +typedef struct PasswordCache PasswordCache; +typedef struct HomeSetup HomeSetup; diff --git a/src/home/homework-fscrypt.c b/src/home/homework-fscrypt.c index 663138988a9..9debaf943af 100644 --- a/src/home/homework-fscrypt.c +++ b/src/home/homework-fscrypt.c @@ -1,20 +1,26 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ +#include #include #include #include +#include +#include #include +#include "alloc-util.h" #include "errno-util.h" #include "fd-util.h" +#include "format-util.h" #include "hexdecoct.h" #include "homework-fscrypt.h" #include "homework-mount.h" +#include "homework-password-cache.h" #include "homework-quota.h" +#include "homework.h" #include "keyring-util.h" #include "log.h" #include "memory-util.h" -#include "missing_fs.h" #include "missing_keyctl.h" #include "missing_syscall.h" #include "mkdir.h" @@ -26,8 +32,11 @@ #include "random-util.h" #include "rm-rf.h" #include "stdio-util.h" +#include "string-util.h" #include "strv.h" #include "tmpfile-util.h" +#include "user-record-util.h" +#include "user-record.h" #include "user-util.h" #include "xattr-util.h" diff --git a/src/home/homework-fscrypt.h b/src/home/homework-fscrypt.h index 289e9d86fb1..fb93242e1a8 100644 --- a/src/home/homework-fscrypt.h +++ b/src/home/homework-fscrypt.h @@ -1,8 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include "homework.h" -#include "user-record.h" +#include "homework-forward.h" int home_setup_fscrypt(UserRecord *h, HomeSetup *setup, const PasswordCache *cache); diff --git a/src/home/homework-luks.c b/src/home/homework-luks.c index 75632f5d474..dc510eb1f5f 100644 --- a/src/home/homework-luks.c +++ b/src/home/homework-luks.c @@ -5,7 +5,6 @@ #include #include #include - #if HAVE_VALGRIND_MEMCHECK_H #include #endif @@ -13,47 +12,56 @@ #include "sd-daemon.h" #include "sd-device.h" #include "sd-event.h" +#include "sd-gpt.h" #include "sd-id128.h" #include "blkid-util.h" #include "blockdev-util.h" #include "btrfs-util.h" #include "chattr-util.h" +#include "cryptsetup-util.h" #include "device-util.h" #include "devnum-util.h" -#include "dm-util.h" +#include "dissect-image.h" #include "env-util.h" #include "errno-util.h" #include "fd-util.h" #include "fdisk-util.h" #include "fileio.h" #include "filesystems.h" +#include "format-util.h" #include "fs-util.h" #include "fsck-util.h" #include "glyph-util.h" -#include "gpt.h" #include "home-util.h" +#include "homework.h" #include "homework-blob.h" #include "homework-luks.h" #include "homework-mount.h" +#include "homework-password-cache.h" #include "io-util.h" #include "json-util.h" #include "keyring-util.h" +#include "loop-util.h" #include "memory-util.h" #include "missing_magic.h" +#include "missing_syscall.h" #include "mkdir.h" #include "mkfs-util.h" -#include "mount-util.h" #include "openssl-util.h" #include "parse-util.h" #include "path-util.h" #include "process-util.h" #include "random-util.h" #include "resize-fs.h" +#include "string-util.h" #include "strv.h" #include "sync-util.h" +#include "time-util.h" #include "tmpfile-util.h" #include "udev-util.h" +#include "user-record-util.h" +#include "user-record.h" #include "user-util.h" /* Round down to the nearest 4K size. Given that newer hardware generally prefers 4K sectors, let's align our @@ -3913,3 +3921,17 @@ int home_auto_shrink_luks(UserRecord *h, HomeSetup *setup, PasswordCache *cache) return 1; } + +uint64_t luks_volume_key_size_convert(struct crypt_device *cd) { + int k; + + assert(cd); + + /* Convert the "int" to uint64_t, which we usually use for byte sizes stored on disk. */ + + k = sym_crypt_get_volume_key_size(cd); + if (k <= 0) + return UINT64_MAX; + + return (uint64_t) k; +} diff --git a/src/home/homework-luks.h b/src/home/homework-luks.h index 0218de8ccdb..b9c5054a134 100644 --- a/src/home/homework-luks.h +++ b/src/home/homework-luks.h @@ -1,9 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include "cryptsetup-util.h" -#include "homework.h" -#include "user-record.h" +#include "homework-forward.h" int home_setup_luks(UserRecord *h, HomeSetupFlags flags, const char *force_image_path, HomeSetup *setup, PasswordCache *cache, UserRecord **ret_luks_home); @@ -26,19 +24,7 @@ int home_unlock_luks(UserRecord *h, HomeSetup *setup, const PasswordCache *cache int home_auto_shrink_luks(UserRecord *h, HomeSetup *setup, PasswordCache *cache); -static inline uint64_t luks_volume_key_size_convert(struct crypt_device *cd) { - int k; - - assert(cd); - - /* Convert the "int" to uint64_t, which we usually use for byte sizes stored on disk. */ - - k = sym_crypt_get_volume_key_size(cd); - if (k <= 0) - return UINT64_MAX; - - return (uint64_t) k; -} +uint64_t luks_volume_key_size_convert(struct crypt_device *cd); int run_fitrim(int root_fd); int run_fallocate(int backing_fd, const struct stat *st); diff --git a/src/home/homework-mount.c b/src/home/homework-mount.c index 356f5fb8b61..2b340ce54cb 100644 --- a/src/home/homework-mount.c +++ b/src/home/homework-mount.c @@ -1,17 +1,17 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #include +#include #include #include "alloc-util.h" +#include "errno-util.h" #include "fd-util.h" #include "format-util.h" #include "glyph-util.h" -#include "home-util.h" #include "homework.h" #include "homework-mount.h" #include "log.h" -#include "missing_syscall.h" #include "mkdir.h" #include "mount-util.h" #include "namespace-util.h" diff --git a/src/home/homework-mount.h b/src/home/homework-mount.h index 615b7d36e7a..8f5244717d0 100644 --- a/src/home/homework-mount.h +++ b/src/home/homework-mount.h @@ -1,8 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include -#include +#include "homework-forward.h" int home_mount_node(const char *node, const char *fstype, bool discard, unsigned long flags, const char *extra_mount_options); int home_unshare_and_mkdir(void); diff --git a/src/home/homework-password-cache.c b/src/home/homework-password-cache.c index 5ffe717e2eb..cd497b46e7b 100644 --- a/src/home/homework-password-cache.c +++ b/src/home/homework-password-cache.c @@ -5,6 +5,7 @@ #include "keyring-util.h" #include "log.h" #include "missing_syscall.h" +#include "string-util.h" #include "user-record.h" void password_cache_free(PasswordCache *cache) { diff --git a/src/home/homework-password-cache.h b/src/home/homework-password-cache.h index e2d86eb9393..a4b156a2e48 100644 --- a/src/home/homework-password-cache.h +++ b/src/home/homework-password-cache.h @@ -1,8 +1,8 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once +#include "homework-forward.h" #include "strv.h" -#include "user-record.h" typedef struct PasswordCache { /* The volume key from the kernel keyring */ diff --git a/src/home/homework-pkcs11.c b/src/home/homework-pkcs11.c index 42e4976bfb7..626473d2c91 100644 --- a/src/home/homework-pkcs11.c +++ b/src/home/homework-pkcs11.c @@ -1,11 +1,18 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ +#if HAVE_P11KIT + #include "alloc-util.h" #include "hexdecoct.h" #include "homework-pkcs11.h" #include "log.h" #include "pkcs11-util.h" #include "strv.h" +#include "user-record.h" + +void pkcs11_callback_data_release(struct pkcs11_callback_data *data) { + erase_and_free(data->decrypted_password); +} int pkcs11_callback( CK_FUNCTION_LIST *m, @@ -102,3 +109,5 @@ decrypt: return 1; } + +#endif diff --git a/src/home/homework-pkcs11.h b/src/home/homework-pkcs11.h index fd1d0b7714f..197e789c27b 100644 --- a/src/home/homework-pkcs11.h +++ b/src/home/homework-pkcs11.h @@ -2,9 +2,8 @@ #pragma once #if HAVE_P11KIT -#include "memory-util.h" +#include "homework-forward.h" #include "pkcs11-util.h" -#include "user-record.h" struct pkcs11_callback_data { UserRecord *user_record; @@ -13,9 +12,7 @@ struct pkcs11_callback_data { char *decrypted_password; }; -static inline void pkcs11_callback_data_release(struct pkcs11_callback_data *data) { - erase_and_free(data->decrypted_password); -} +void pkcs11_callback_data_release(struct pkcs11_callback_data *data); int pkcs11_callback(CK_FUNCTION_LIST *m, CK_SESSION_HANDLE session, CK_SLOT_ID slot_id, const CK_SLOT_INFO *slot_info, const CK_TOKEN_INFO *token_info, P11KitUri *uri, void *userdata); #endif diff --git a/src/home/homework-quota.c b/src/home/homework-quota.c index e2b43afbeac..5d256c5dcdd 100644 --- a/src/home/homework-quota.c +++ b/src/home/homework-quota.c @@ -1,16 +1,17 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #include -#include "blockdev-util.h" #include "btrfs-util.h" #include "errno-util.h" #include "fd-util.h" #include "format-util.h" #include "homework-quota.h" #include "log.h" +#include "memory-util.h" #include "missing_magic.h" #include "quota-util.h" #include "stat-util.h" +#include "user-record.h" #include "user-util.h" int home_update_quota_btrfs(UserRecord *h, int fd, const char *path) { diff --git a/src/home/homework-quota.h b/src/home/homework-quota.h index a03510c75e2..9e6b85ffd60 100644 --- a/src/home/homework-quota.h +++ b/src/home/homework-quota.h @@ -1,7 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include "user-record.h" +#include "homework-forward.h" int home_update_quota_btrfs(UserRecord *h, int fd, const char *path); int home_update_quota_classic(UserRecord *h, int fd, const char *path); diff --git a/src/home/homework.c b/src/home/homework.c index 8af0847c78f..d26d4529e55 100644 --- a/src/home/homework.c +++ b/src/home/homework.c @@ -1,6 +1,6 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ -#include +#include #include #include "sd-daemon.h" @@ -9,36 +9,44 @@ #include "bus-unit-util.h" #include "chown-recursive.h" #include "copy.h" +#include "cryptsetup-util.h" #include "env-util.h" +#include "errno-util.h" #include "fd-util.h" #include "fileio.h" #include "filesystems.h" #include "format-util.h" -#include "fs-util.h" +#include "hashmap.h" #include "home-util.h" +#include "homework-fido2.h" +#include "homework-password-cache.h" +#include "homework-pkcs11.h" #include "homework.h" #include "homework-blob.h" #include "homework-cifs.h" #include "homework-directory.h" -#include "homework-fido2.h" #include "homework-fscrypt.h" #include "homework-luks.h" #include "homework-mount.h" -#include "homework-pkcs11.h" #include "json-util.h" #include "libcrypt-util.h" +#include "loop-util.h" #include "main-func.h" #include "memory-util.h" #include "missing_magic.h" +#include "missing_syscall.h" #include "mount-util.h" -#include "parse-util.h" #include "path-util.h" #include "recovery-key.h" #include "rm-rf.h" #include "stat-util.h" +#include "string-util.h" #include "strv.h" #include "sync-util.h" +#include "time-util.h" #include "tmpfile-util.h" +#include "user-record.h" +#include "user-record-util.h" #include "user-util.h" #include "virt.h" diff --git a/src/home/homework.h b/src/home/homework.h index 138483bbc64..abd1c482da8 100644 --- a/src/home/homework.h +++ b/src/home/homework.h @@ -1,17 +1,12 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include +#include #include "sd-id128.h" -#include "cryptsetup-util.h" -#include "homework-password-cache.h" -#include "loop-util.h" -#include "missing_fs.h" +#include "homework-forward.h" #include "missing_keyctl.h" -#include "missing_syscall.h" -#include "user-record.h" #include "user-record-util.h" typedef struct HomeSetup { diff --git a/src/home/meson.build b/src/home/meson.build index c549adf79d7..94c26ef0882 100644 --- a/src/home/meson.build +++ b/src/home/meson.build @@ -23,24 +23,19 @@ systemd_homed_extract_sources = files( ) systemd_homework_sources = files( + 'homework.c', 'homework-blob.c', 'homework-cifs.c', 'homework-directory.c', + 'homework-fido2.c', 'homework-fscrypt.c', 'homework-luks.c', 'homework-mount.c', 'homework-password-cache.c', + 'homework-pkcs11.c', 'homework-quota.c', - 'homework.c', ) -if conf.get('HAVE_P11KIT') == 1 - systemd_homework_sources += files('homework-pkcs11.c') -endif -if conf.get('HAVE_LIBFIDO2') == 1 - systemd_homework_sources += files('homework-fido2.c') -endif - homed_gperf_c = custom_target( 'homed-gperf.c', input : 'homed-gperf.gperf', diff --git a/src/home/pam_systemd_home.c b/src/home/pam_systemd_home.c index 3bf6ffbae84..78cd06b8e80 100644 --- a/src/home/pam_systemd_home.c +++ b/src/home/pam_systemd_home.c @@ -1,5 +1,6 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ +#include #include #include #include @@ -10,16 +11,15 @@ #include "bus-common-errors.h" #include "bus-locator.h" #include "bus-util.h" -#include "errno-util.h" #include "fd-util.h" #include "home-util.h" #include "locale-util.h" -#include "log.h" -#include "memory-util.h" #include "pam-util.h" #include "parse-util.h" #include "path-util.h" +#include "string-util.h" #include "strv.h" +#include "time-util.h" #include "user-record.h" #include "user-record-util.h" #include "user-util.h" diff --git a/src/home/test-homed-regression-31896.c b/src/home/test-homed-regression-31896.c index 1530a2f22b9..46c578da894 100644 --- a/src/home/test-homed-regression-31896.c +++ b/src/home/test-homed-regression-31896.c @@ -1,5 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ +#include "sd-bus.h" + #include "bus-locator.h" #include "main-func.h" #include "tests.h" diff --git a/src/home/user-record-password-quality.c b/src/home/user-record-password-quality.c index 4e480b16d24..844c42c52b2 100644 --- a/src/home/user-record-password-quality.c +++ b/src/home/user-record-password-quality.c @@ -1,15 +1,17 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ +#include "sd-bus.h" + #include "alloc-util.h" #include "bus-common-errors.h" #include "errno-util.h" -#include "home-util.h" #include "libcrypt-util.h" #include "log.h" #include "password-quality-util.h" +#include "string-util.h" #include "strv.h" +#include "user-record.h" #include "user-record-password-quality.h" -#include "user-record-util.h" #if HAVE_PASSWDQC || HAVE_PWQUALITY diff --git a/src/home/user-record-password-quality.h b/src/home/user-record-password-quality.h index 41473aabde4..b76092113cd 100644 --- a/src/home/user-record-password-quality.h +++ b/src/home/user-record-password-quality.h @@ -1,8 +1,6 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include "sd-bus.h" - -#include "user-record.h" +#include "forward.h" int user_record_check_password_quality(UserRecord *hr, UserRecord *secret, sd_bus_error *error); diff --git a/src/home/user-record-sign.c b/src/home/user-record-sign.c index 1f0bc88e417..367ab38330a 100644 --- a/src/home/user-record-sign.c +++ b/src/home/user-record-sign.c @@ -1,15 +1,11 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ -#include - #include "alloc-util.h" -#include "fd-util.h" -#include "fileio.h" #include "json-util.h" #include "log.h" -#include "memstream-util.h" #include "openssl-util.h" #include "user-record-sign.h" +#include "user-record.h" static int user_record_signable_json(UserRecord *ur, char **ret) { _cleanup_(user_record_unrefp) UserRecord *reduced = NULL; diff --git a/src/home/user-record-sign.h b/src/home/user-record-sign.h index 87c6813e928..350e7457660 100644 --- a/src/home/user-record-sign.h +++ b/src/home/user-record-sign.h @@ -3,7 +3,7 @@ #include -#include "user-record.h" +#include "forward.h" int user_record_sign(UserRecord *ur, EVP_PKEY *private_key, UserRecord **ret); diff --git a/src/home/user-record-util.c b/src/home/user-record-util.c index 13c7675faf4..fdc99e1c4f0 100644 --- a/src/home/user-record-util.c +++ b/src/home/user-record-util.c @@ -1,23 +1,29 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #include +#include +#include "sd-bus.h" #include "sd-json.h" #include "alloc-util.h" #include "errno-util.h" #include "fd-util.h" +#include "group-record.h" +#include "hashmap.h" #include "home-util.h" -#include "id128-util.h" #include "json-util.h" #include "libcrypt-util.h" #include "log.h" -#include "memory-util.h" #include "mountpoint-util.h" #include "path-util.h" #include "recovery-key.h" #include "sha256.h" #include "stat-util.h" +#include "string-util.h" +#include "strv.h" +#include "time-util.h" +#include "user-record.h" #include "user-record-util.h" #include "user-util.h" diff --git a/src/home/user-record-util.h b/src/home/user-record-util.h index 4268396b905..31961184a8b 100644 --- a/src/home/user-record-util.h +++ b/src/home/user-record-util.h @@ -1,10 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include "sd-bus.h" - -#include "group-record.h" -#include "user-record.h" +#include "forward.h" /* We intentionally use snake_case instead of the usual camelCase here to further * reduce the chance of collision with a field any legitimate user record may ever