diff --git a/src/home/homework-cifs.c b/src/home/homework-cifs.c index e3b4b3e01e..3ac99f20ed 100644 --- a/src/home/homework-cifs.c +++ b/src/home/homework-cifs.c @@ -99,16 +99,17 @@ int home_setup_cifs( int home_activate_cifs( UserRecord *h, + HomeSetup *setup, PasswordCache *cache, UserRecord **ret_home) { - _cleanup_(home_setup_done) HomeSetup setup = HOME_SETUP_INIT; _cleanup_(user_record_unrefp) UserRecord *new_home = NULL; const char *hdo, *hd; int r; assert(h); assert(user_record_storage(h) == USER_CIFS); + assert(setup); assert(ret_home); if (!h->cifs_service) @@ -117,21 +118,21 @@ int home_activate_cifs( assert_se(hdo = user_record_home_directory(h)); hd = strdupa_safe(hdo); /* copy the string out, since it might change later in the home record object */ - r = home_setup_cifs(h, 0, &setup); + r = home_setup_cifs(h, 0, setup); if (r < 0) return r; - r = home_refresh(h, &setup, NULL, cache, NULL, &new_home); + r = home_refresh(h, setup, NULL, cache, NULL, &new_home); if (r < 0) return r; - setup.root_fd = safe_close(setup.root_fd); + setup->root_fd = safe_close(setup->root_fd); r = home_move_mount(NULL, hd); if (r < 0) return r; - setup.undo_mount = false; + setup->undo_mount = false; log_info("Everything completed."); @@ -139,8 +140,7 @@ int home_activate_cifs( return 1; } -int home_create_cifs(UserRecord *h, UserRecord **ret_home) { - _cleanup_(home_setup_done) HomeSetup setup = HOME_SETUP_INIT; +int home_create_cifs(UserRecord *h, HomeSetup *setup, UserRecord **ret_home) { _cleanup_(user_record_unrefp) UserRecord *new_home = NULL; _cleanup_(closedirp) DIR *d = NULL; _cleanup_close_ int copy = -1; @@ -148,6 +148,7 @@ int home_create_cifs(UserRecord *h, UserRecord **ret_home) { assert(h); assert(user_record_storage(h) == USER_CIFS); + assert(setup); assert(ret_home); if (!h->cifs_service) @@ -160,11 +161,11 @@ int home_create_cifs(UserRecord *h, UserRecord **ret_home) { return log_error_errno(errno, "Unable to detect whether /sbin/mount.cifs exists: %m"); } - r = home_setup_cifs(h, 0, &setup); + r = home_setup_cifs(h, 0, setup); if (r < 0) return r; - copy = fcntl(setup.root_fd, F_DUPFD_CLOEXEC, 3); + copy = fcntl(setup->root_fd, F_DUPFD_CLOEXEC, 3); if (copy < 0) return -errno; @@ -178,11 +179,11 @@ int home_create_cifs(UserRecord *h, UserRecord **ret_home) { if (errno != 0) return log_error_errno(errno, "Failed to detect if CIFS directory is empty: %m"); - r = home_populate(h, setup.root_fd); + r = home_populate(h, setup->root_fd); if (r < 0) return r; - r = home_sync_and_statfs(setup.root_fd, NULL); + r = home_sync_and_statfs(setup->root_fd, NULL); if (r < 0) return r; diff --git a/src/home/homework-cifs.h b/src/home/homework-cifs.h index 820b95e1db..dda1e0b876 100644 --- a/src/home/homework-cifs.h +++ b/src/home/homework-cifs.h @@ -6,6 +6,6 @@ int home_setup_cifs(UserRecord *h, HomeSetupFlags flags, HomeSetup *setup); -int home_activate_cifs(UserRecord *h, PasswordCache *cache, UserRecord **ret_home); +int home_activate_cifs(UserRecord *h, HomeSetup *setup, PasswordCache *cache, UserRecord **ret_home); -int home_create_cifs(UserRecord *h, UserRecord **ret_home); +int home_create_cifs(UserRecord *h, HomeSetup *setup, UserRecord **ret_home); diff --git a/src/home/homework-directory.c b/src/home/homework-directory.c index c36b99ff2b..b95896d45b 100644 --- a/src/home/homework-directory.c +++ b/src/home/homework-directory.c @@ -26,16 +26,17 @@ int home_setup_directory(UserRecord *h, HomeSetup *setup) { int home_activate_directory( UserRecord *h, + HomeSetup *setup, PasswordCache *cache, UserRecord **ret_home) { _cleanup_(user_record_unrefp) UserRecord *new_home = NULL, *header_home = NULL; - _cleanup_(home_setup_done) HomeSetup setup = HOME_SETUP_INIT; const char *hdo, *hd, *ipo, *ip; int r; assert(h); assert(IN_SET(user_record_storage(h), USER_DIRECTORY, USER_SUBVOLUME, USER_FSCRYPT)); + assert(setup); assert(ret_home); assert_se(ipo = user_record_image_path(h)); @@ -44,15 +45,15 @@ int home_activate_directory( assert_se(hdo = user_record_home_directory(h)); hd = strdupa_safe(hdo); - r = home_setup(h, 0, cache, &setup, &header_home); + r = home_setup(h, 0, cache, setup, &header_home); if (r < 0) return r; - r = home_refresh(h, &setup, header_home, cache, NULL, &new_home); + r = home_refresh(h, setup, header_home, cache, NULL, &new_home); if (r < 0) return r; - setup.root_fd = safe_close(setup.root_fd); + setup->root_fd = safe_close(setup->root_fd); /* Create mount point to mount over if necessary */ if (!path_equal(ip, hd)) diff --git a/src/home/homework-directory.h b/src/home/homework-directory.h index fb1980c1f7..98b1804774 100644 --- a/src/home/homework-directory.h +++ b/src/home/homework-directory.h @@ -5,6 +5,6 @@ #include "user-record.h" int home_setup_directory(UserRecord *h, HomeSetup *setup); -int home_activate_directory(UserRecord *h, PasswordCache *cache, UserRecord **ret_home); +int home_activate_directory(UserRecord *h, HomeSetup *setup, PasswordCache *cache, UserRecord **ret_home); int home_create_directory_or_subvolume(UserRecord *h, UserRecord **ret_home); int home_resize_directory(UserRecord *h, HomeSetupFlags flags, PasswordCache *cache, HomeSetup *setup, UserRecord **ret_home); diff --git a/src/home/homework-luks.c b/src/home/homework-luks.c index 3e893d7b83..4464296c96 100644 --- a/src/home/homework-luks.c +++ b/src/home/homework-luks.c @@ -1391,11 +1391,11 @@ static void print_size_summary(uint64_t host_size, uint64_t encrypted_size, stru int home_activate_luks( UserRecord *h, + HomeSetup *setup, PasswordCache *cache, UserRecord **ret_home) { _cleanup_(user_record_unrefp) UserRecord *new_home = NULL, *luks_home_record = NULL; - _cleanup_(home_setup_done) HomeSetup setup = HOME_SETUP_INIT; uint64_t host_size, encrypted_size; const char *hdo, *hd; struct statfs sfs; @@ -1403,6 +1403,7 @@ int home_activate_luks( assert(h); assert(user_record_storage(h) == USER_LUKS); + assert(setup); assert(ret_home); r = dlopen_cryptsetup(); @@ -1412,33 +1413,33 @@ int home_activate_luks( assert_se(hdo = user_record_home_directory(h)); hd = strdupa_safe(hdo); /* copy the string out, since it might change later in the home record object */ - r = home_get_state_luks(h, &setup); + r = home_get_state_luks(h, setup); if (r < 0) return r; if (r > 0) - return log_error_errno(SYNTHETIC_ERRNO(EEXIST), "Device mapper device %s already exists, refusing.", setup.dm_node); + return log_error_errno(SYNTHETIC_ERRNO(EEXIST), "Device mapper device %s already exists, refusing.", setup->dm_node); r = home_setup_luks( h, 0, NULL, cache, - &setup, + setup, &luks_home_record); if (r < 0) return r; - r = block_get_size_by_fd(setup.loop->fd, &host_size); + r = block_get_size_by_fd(setup->loop->fd, &host_size); if (r < 0) return log_error_errno(r, "Failed to get loopback block device size: %m"); - r = block_get_size_by_path(setup.dm_node, &encrypted_size); + r = block_get_size_by_path(setup->dm_node, &encrypted_size); if (r < 0) return log_error_errno(r, "Failed to get LUKS block device size: %m"); r = home_refresh( h, - &setup, + setup, luks_home_record, cache, &sfs, @@ -1446,28 +1447,28 @@ int home_activate_luks( if (r < 0) return r; - r = home_extend_embedded_identity(new_home, h, &setup); + r = home_extend_embedded_identity(new_home, h, setup); if (r < 0) return r; - setup.root_fd = safe_close(setup.root_fd); + setup->root_fd = safe_close(setup->root_fd); r = home_move_mount(user_record_user_name_and_realm(h), hd); if (r < 0) return r; - setup.undo_mount = false; - setup.do_offline_fitrim = false; + setup->undo_mount = false; + setup->do_offline_fitrim = false; - loop_device_relinquish(setup.loop); + loop_device_relinquish(setup->loop); - r = sym_crypt_deactivate_by_name(NULL, setup.dm_name, CRYPT_DEACTIVATE_DEFERRED); + r = sym_crypt_deactivate_by_name(NULL, setup->dm_name, CRYPT_DEACTIVATE_DEFERRED); if (r < 0) log_warning_errno(r, "Failed to relinquish DM device, ignoring: %m"); - setup.undo_dm = false; - setup.do_offline_fallocate = false; - setup.do_mark_clean = false; + setup->undo_dm = false; + setup->do_offline_fallocate = false; + setup->do_mark_clean = false; log_info("Everything completed."); diff --git a/src/home/homework-luks.h b/src/home/homework-luks.h index 1225adafdc..5345170ac5 100644 --- a/src/home/homework-luks.h +++ b/src/home/homework-luks.h @@ -7,7 +7,7 @@ int home_setup_luks(UserRecord *h, HomeSetupFlags flags, const char *force_image_path, PasswordCache *cache, HomeSetup *setup, UserRecord **ret_luks_home); -int home_activate_luks(UserRecord *h, PasswordCache *cache, UserRecord **ret_home); +int home_activate_luks(UserRecord *h, HomeSetup *setup, PasswordCache *cache, UserRecord **ret_home); int home_deactivate_luks(UserRecord *h); int home_trim_luks(UserRecord *h); diff --git a/src/home/homework.c b/src/home/homework.c index 01286220cb..78ca979fae 100644 --- a/src/home/homework.c +++ b/src/home/homework.c @@ -759,8 +759,9 @@ int home_refresh( } static int home_activate(UserRecord *h, UserRecord **ret_home) { - _cleanup_(password_cache_free) PasswordCache cache = {}; + _cleanup_(home_setup_done) HomeSetup setup = HOME_SETUP_INIT; _cleanup_(user_record_unrefp) UserRecord *new_home = NULL; + _cleanup_(password_cache_free) PasswordCache cache = {}; int r; assert(h); @@ -791,7 +792,7 @@ static int home_activate(UserRecord *h, UserRecord **ret_home) { switch (user_record_storage(h)) { case USER_LUKS: - r = home_activate_luks(h, &cache, &new_home); + r = home_activate_luks(h, &setup, &cache, &new_home); if (r < 0) return r; @@ -800,14 +801,14 @@ static int home_activate(UserRecord *h, UserRecord **ret_home) { case USER_SUBVOLUME: case USER_DIRECTORY: case USER_FSCRYPT: - r = home_activate_directory(h, &cache, &new_home); + r = home_activate_directory(h, &setup, &cache, &new_home); if (r < 0) return r; break; case USER_CIFS: - r = home_activate_cifs(h, &cache, &new_home); + r = home_activate_cifs(h, &setup, &cache, &new_home); if (r < 0) return r; @@ -1163,6 +1164,7 @@ static int determine_default_storage(UserStorage *ret) { static int home_create(UserRecord *h, UserRecord **ret_home) { _cleanup_(strv_free_erasep) char **effective_passwords = NULL; + _cleanup_(home_setup_done) HomeSetup setup = HOME_SETUP_INIT; _cleanup_(user_record_unrefp) UserRecord *new_home = NULL; _cleanup_(password_cache_free) PasswordCache cache = {}; UserStorage new_storage = _USER_STORAGE_INVALID; @@ -1238,7 +1240,7 @@ static int home_create(UserRecord *h, UserRecord **ret_home) { break; case USER_CIFS: - r = home_create_cifs(h, &new_home); + r = home_create_cifs(h, &setup, &new_home); break; default: