]>
Commit | Line | Data |
---|---|---|
1 | /* SPDX-License-Identifier: LGPL-2.1-or-later */ | |
2 | #pragma once | |
3 | ||
4 | #include <linux/fscrypt.h> | |
5 | #include <sys/keyctl.h> | |
6 | ||
7 | #include "sd-id128.h" | |
8 | ||
9 | #include "homework-forward.h" | |
10 | #include "user-record-util.h" | |
11 | ||
12 | typedef struct HomeSetup { | |
13 | char *dm_name; /* "home-<username>" */ | |
14 | char *dm_node; /* "/dev/mapper/home-<username>" */ | |
15 | ||
16 | LoopDevice *loop; | |
17 | struct crypt_device *crypt_device; | |
18 | int root_fd; | |
19 | int image_fd; | |
20 | sd_id128_t found_partition_uuid; | |
21 | sd_id128_t found_luks_uuid; | |
22 | sd_id128_t found_fs_uuid; | |
23 | ||
24 | uint8_t fscrypt_key_descriptor[FS_KEY_DESCRIPTOR_SIZE]; | |
25 | ||
26 | void *volume_key; | |
27 | size_t volume_key_size; | |
28 | ||
29 | key_serial_t key_serial; | |
30 | ||
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; | |
37 | ||
38 | uint64_t partition_offset; | |
39 | uint64_t partition_size; | |
40 | ||
41 | char *mount_suffix; /* The directory to use as home dir is this path below /run/systemd/user-home-mount */ | |
42 | ||
43 | char *temporary_image_path; | |
44 | } HomeSetup; | |
45 | ||
46 | #define HOME_SETUP_INIT \ | |
47 | { \ | |
48 | .root_fd = -EBADF, \ | |
49 | .image_fd = -EBADF, \ | |
50 | .partition_offset = UINT64_MAX, \ | |
51 | .partition_size = UINT64_MAX, \ | |
52 | .key_serial = -1, \ | |
53 | } | |
54 | ||
55 | /* Various flags for the operation of setting up a home directory */ | |
56 | typedef enum HomeSetupFlags { | |
57 | HOME_SETUP_ALREADY_ACTIVATED = 1 << 0, /* Open an already activated home, rather than activate it afresh */ | |
58 | ||
59 | /* CIFS backend: */ | |
60 | HOME_SETUP_CIFS_MKDIR = 1 << 1, /* Create CIFS subdir when missing */ | |
61 | ||
62 | /* Applies only for resize operations */ | |
63 | HOME_SETUP_RESIZE_DONT_SYNC_IDENTITIES = 1 << 2, /* Don't sync identity records into home and LUKS header */ | |
64 | HOME_SETUP_RESIZE_MINIMIZE = 1 << 3, /* Shrink to minimal size */ | |
65 | HOME_SETUP_RESIZE_DONT_GROW = 1 << 4, /* If the resize would grow, gracefully terminate operation */ | |
66 | HOME_SETUP_RESIZE_DONT_SHRINK = 1 << 5, /* If the resize would shrink, gracefully terminate operation */ | |
67 | HOME_SETUP_RESIZE_DONT_UNDO = 1 << 6, /* Leave loopback/DM device context open after successful operation */ | |
68 | } HomeSetupFlags; | |
69 | ||
70 | int home_setup_done(HomeSetup *setup); | |
71 | ||
72 | int home_setup_undo_mount(HomeSetup *setup, int level); | |
73 | int home_setup_undo_dm(HomeSetup *setup, int level); | |
74 | ||
75 | int keyring_unlink(key_serial_t k); | |
76 | ||
77 | int home_setup(UserRecord *h, HomeSetupFlags flags, HomeSetup *setup, PasswordCache *cache, UserRecord **ret_header_home); | |
78 | ||
79 | int home_refresh(UserRecord *h, HomeSetupFlags flags, HomeSetup *setup, UserRecord *header_home, PasswordCache *cache, struct statfs *ret_statfs, UserRecord **ret_new_home); | |
80 | ||
81 | int home_maybe_shift_uid(UserRecord *h, HomeSetupFlags flags, HomeSetup *setup); | |
82 | int home_populate(UserRecord *h, int dir_fd); | |
83 | ||
84 | 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); | |
85 | int home_store_embedded_identity(UserRecord *h, int root_fd, UserRecord *old_home); | |
86 | int home_extend_embedded_identity(UserRecord *h, UserRecord *used, HomeSetup *setup); | |
87 | ||
88 | int user_record_authenticate(UserRecord *h, UserRecord *secret, PasswordCache *cache, bool strict_verify); | |
89 | ||
90 | int home_sync_and_statfs(int root_fd, struct statfs *ret); | |
91 | ||
92 | #define HOME_RUNTIME_WORK_DIR "/run/systemd/user-home-mount" |