1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
4 #include <linux/fscrypt.h>
5 #include <sys/keyctl.h>
9 #include "homework-forward.h"
10 #include "user-record-util.h"
12 typedef struct HomeSetup
{
13 char *dm_name
; /* "home-<username>" */
14 char *dm_node
; /* "/dev/mapper/home-<username>" */
17 struct crypt_device
*crypt_device
;
20 sd_id128_t found_partition_uuid
;
21 sd_id128_t found_luks_uuid
;
22 sd_id128_t found_fs_uuid
;
24 uint8_t fscrypt_key_descriptor
[FS_KEY_DESCRIPTOR_SIZE
];
27 size_t volume_key_size
;
29 key_serial_t key_serial
;
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;
36 bool do_drop_caches
:1;
38 uint64_t partition_offset
;
39 uint64_t partition_size
;
41 char *mount_suffix
; /* The directory to use as home dir is this path below /run/systemd/user-home-mount */
43 char *temporary_image_path
;
46 #define HOME_SETUP_INIT \
50 .partition_offset = UINT64_MAX, \
51 .partition_size = UINT64_MAX, \
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 */
60 HOME_SETUP_CIFS_MKDIR
= 1 << 1, /* Create CIFS subdir when missing */
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 */
70 int home_setup_done(HomeSetup
*setup
);
72 int home_setup_undo_mount(HomeSetup
*setup
, int level
);
73 int home_setup_undo_dm(HomeSetup
*setup
, int level
);
75 int keyring_unlink(key_serial_t k
);
77 int home_setup(UserRecord
*h
, HomeSetupFlags flags
, HomeSetup
*setup
, PasswordCache
*cache
, UserRecord
**ret_header_home
);
79 int home_refresh(UserRecord
*h
, HomeSetupFlags flags
, HomeSetup
*setup
, UserRecord
*header_home
, PasswordCache
*cache
, struct statfs
*ret_statfs
, UserRecord
**ret_new_home
);
81 int home_maybe_shift_uid(UserRecord
*h
, HomeSetupFlags flags
, HomeSetup
*setup
);
82 int home_populate(UserRecord
*h
, int dir_fd
);
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
);
88 int user_record_authenticate(UserRecord
*h
, UserRecord
*secret
, PasswordCache
*cache
, bool strict_verify
);
90 int home_sync_and_statfs(int root_fd
, struct statfs
*ret
);
92 #define HOME_RUNTIME_WORK_DIR "/run/systemd/user-home-mount"