]>
Commit | Line | Data |
---|---|---|
db9ecf05 | 1 | /* SPDX-License-Identifier: LGPL-2.1-or-later */ |
70a5db58 LP |
2 | #pragma once |
3 | ||
4 | #include <linux/fs.h> | |
5 | #include <sys/vfs.h> | |
6 | ||
7 | #include "sd-id128.h" | |
8 | ||
9 | #include "loop-util.h" | |
3361d1ca | 10 | #include "strv.h" |
70a5db58 LP |
11 | #include "user-record.h" |
12 | #include "user-record-util.h" | |
13 | ||
14 | typedef struct HomeSetup { | |
15 | char *dm_name; | |
16 | char *dm_node; | |
17 | ||
18 | LoopDevice *loop; | |
19 | struct crypt_device *crypt_device; | |
20 | int root_fd; | |
28a7f106 | 21 | int image_fd; |
70a5db58 LP |
22 | sd_id128_t found_partition_uuid; |
23 | sd_id128_t found_luks_uuid; | |
24 | sd_id128_t found_fs_uuid; | |
25 | ||
26 | uint8_t fscrypt_key_descriptor[FS_KEY_DESCRIPTOR_SIZE]; | |
27 | ||
28 | void *volume_key; | |
29 | size_t volume_key_size; | |
30 | ||
baa41cee LP |
31 | bool undo_dm:1; |
32 | bool undo_mount:1; /* Whether to unmount /run/systemd/user-home-mount */ | |
33 | bool do_offline_fitrim:1; | |
34 | bool do_offline_fallocate:1; | |
35 | bool do_mark_clean:1; | |
36 | bool do_drop_caches:1; | |
70a5db58 LP |
37 | |
38 | uint64_t partition_offset; | |
39 | uint64_t partition_size; | |
bf15879b LP |
40 | |
41 | char *mount_suffix; /* The directory to use as home dir is this path below /run/systemd/user-home-mount */ | |
70a5db58 LP |
42 | } HomeSetup; |
43 | ||
7b78db28 | 44 | typedef struct PasswordCache { |
3361d1ca LP |
45 | /* Decoding passwords from security tokens is expensive and typically requires user interaction, |
46 | * hence cache any we already figured out. */ | |
7b78db28 LP |
47 | char **pkcs11_passwords; |
48 | char **fido2_passwords; | |
49 | } PasswordCache; | |
50 | ||
51 | void password_cache_free(PasswordCache *cache); | |
52 | ||
3361d1ca LP |
53 | static inline bool password_cache_contains(const PasswordCache *cache, const char *p) { |
54 | if (!cache) | |
55 | return false; | |
56 | ||
57 | return strv_contains(cache->pkcs11_passwords, p) || strv_contains(cache->fido2_passwords, p); | |
58 | } | |
59 | ||
70a5db58 LP |
60 | #define HOME_SETUP_INIT \ |
61 | { \ | |
62 | .root_fd = -1, \ | |
28a7f106 | 63 | .image_fd = -1, \ |
70a5db58 LP |
64 | .partition_offset = UINT64_MAX, \ |
65 | .partition_size = UINT64_MAX, \ | |
66 | } | |
67 | ||
e1df968b LP |
68 | /* Various flags for the operation of setting up a home directory */ |
69 | typedef enum HomeSetupFlags { | |
70 | HOME_SETUP_ALREADY_ACTIVATED = 1 << 0, /* Open an already activated home, rather than activate it afresh */ | |
bf15879b LP |
71 | |
72 | /* CIFS backend: */ | |
73 | HOME_SETUP_CIFS_MKDIR = 1 << 1, /* Create CIFS subdir when missing */ | |
e1df968b LP |
74 | } HomeSetupFlags; |
75 | ||
66aa51f8 | 76 | int home_setup_done(HomeSetup *setup); |
70a5db58 | 77 | |
e1df968b | 78 | int home_setup(UserRecord *h, HomeSetupFlags flags, PasswordCache *cache, HomeSetup *setup, UserRecord **ret_header_home); |
70a5db58 | 79 | |
7b78db28 | 80 | int home_refresh(UserRecord *h, HomeSetup *setup, UserRecord *header_home, PasswordCache *cache, struct statfs *ret_statfs, UserRecord **ret_new_home); |
70a5db58 | 81 | |
cf5115f6 | 82 | int home_maybe_shift_uid(UserRecord *h, HomeSetup *setup); |
70a5db58 LP |
83 | int home_populate(UserRecord *h, int dir_fd); |
84 | ||
7b78db28 | 85 | int home_load_embedded_identity(UserRecord *h, int root_fd, UserRecord *header_home, UserReconcileMode mode, PasswordCache *cache, UserRecord **ret_embedded_home, UserRecord **ret_new_home); |
70a5db58 LP |
86 | int home_store_embedded_identity(UserRecord *h, int root_fd, uid_t uid, UserRecord *old_home); |
87 | int home_extend_embedded_identity(UserRecord *h, UserRecord *used, HomeSetup *setup); | |
88 | ||
7b78db28 | 89 | int user_record_authenticate(UserRecord *h, UserRecord *secret, PasswordCache *cache, bool strict_verify); |
70a5db58 LP |
90 | |
91 | int home_sync_and_statfs(int root_fd, struct statfs *ret); | |
498abadb LP |
92 | |
93 | #define HOME_RUNTIME_WORK_DIR "/run/systemd/user-home-mount" |