]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
homework: use HomeSetup in home_create_luks() too
authorLennart Poettering <lennart@poettering.net>
Mon, 25 Oct 2021 13:03:34 +0000 (15:03 +0200)
committerLennart Poettering <lennart@poettering.net>
Thu, 28 Oct 2021 06:17:46 +0000 (08:17 +0200)
We use it for all other LUKS operations these days, and for all
home_create_xyz() calls for other backends, let's use it for the LUKS
backend too.

src/home/homework-luks.c
src/home/homework-luks.h
src/home/homework.c

index e09d40f66b6ca8b88b356e1b76b2b001796e7575..641acaeb32156652e80c3283f1da9fd9508e40ed 100644 (file)
@@ -1992,6 +1992,7 @@ static int home_truncate(
 
 int home_create_luks(
                 UserRecord *h,
+                HomeSetup *setup,
                 const PasswordCache *cache,
                 char **effective_passwords,
                 UserRecord **ret_home) {
@@ -2004,13 +2005,14 @@ int home_create_luks(
         sd_id128_t partition_uuid, fs_uuid, luks_uuid, disk_uuid;
         _cleanup_(loop_device_unrefp) LoopDevice *loop = NULL;
         _cleanup_(sym_crypt_freep) struct crypt_device *cd = NULL;
-        _cleanup_close_ int image_fd = -1, root_fd = -1;
+        _cleanup_close_ int image_fd = -1;
         const char *fstype, *ip;
         struct statfs sfs;
         int r;
 
         assert(h);
         assert(h->storage < 0 || h->storage == USER_LUKS);
+        assert(setup);
         assert(ret_home);
 
         r = dlopen_cryptsetup();
@@ -2256,17 +2258,17 @@ int home_create_luks(
                 goto fail;
         }
 
-        root_fd = open(subdir, O_RDONLY|O_CLOEXEC|O_DIRECTORY|O_NOFOLLOW);
-        if (root_fd < 0) {
+        setup->root_fd = open(subdir, O_RDONLY|O_CLOEXEC|O_DIRECTORY|O_NOFOLLOW);
+        if (setup->root_fd < 0) {
                 r = log_error_errno(errno, "Failed to open user directory in mounted image file: %m");
                 goto fail;
         }
 
-        r = home_populate(h, root_fd);
+        r = home_populate(h, setup->root_fd);
         if (r < 0)
                 goto fail;
 
-        r = home_sync_and_statfs(root_fd, &sfs);
+        r = home_sync_and_statfs(setup->root_fd, &sfs);
         if (r < 0)
                 goto fail;
 
@@ -2296,12 +2298,12 @@ int home_create_luks(
         }
 
         if (user_record_luks_offline_discard(h)) {
-                r = run_fitrim(root_fd);
+                r = run_fitrim(setup->root_fd);
                 if (r < 0)
                         goto fail;
         }
 
-        root_fd = safe_close(root_fd);
+        setup->root_fd = safe_close(setup->root_fd);
 
         r = umount_verbose(LOG_ERR, HOME_RUNTIME_WORK_DIR, UMOUNT_NOFOLLOW);
         if (r < 0)
@@ -2370,7 +2372,7 @@ int home_create_luks(
 
 fail:
         /* Let's close all files before we unmount the file system, to avoid EBUSY */
-        root_fd = safe_close(root_fd);
+        setup->root_fd = safe_close(setup->root_fd);
 
         if (mounted)
                 (void) umount_verbose(LOG_WARNING, HOME_RUNTIME_WORK_DIR, UMOUNT_NOFOLLOW);
index f8d22bb647a0ae44bcf1266d92703b8f7b66b151..1896e3ce6c48a35dc1f6ac4896d07afa6fcaf1eb 100644 (file)
@@ -13,7 +13,7 @@ int home_trim_luks(UserRecord *h);
 
 int home_store_header_identity_luks(UserRecord *h, HomeSetup *setup, UserRecord *old_home);
 
-int home_create_luks(UserRecord *h, const PasswordCache *cache, char **effective_passwords, UserRecord **ret_home);
+int home_create_luks(UserRecord *h, HomeSetup *setup, const PasswordCache *cache, char **effective_passwords, UserRecord **ret_home);
 
 int home_get_state_luks(UserRecord *h, HomeSetup *setup);
 
index 6b60fddc2cf66dcf0deb1fdf35a36dd2766ca01b..170f7f26fb8d8898aa9d7fbe52d36584071bed06 100644 (file)
@@ -1279,7 +1279,7 @@ static int home_create(UserRecord *h, UserRecord **ret_home) {
         switch (user_record_storage(h)) {
 
         case USER_LUKS:
-                r = home_create_luks(h, &cache, effective_passwords, &new_home);
+                r = home_create_luks(h, &setup, &cache, effective_passwords, &new_home);
                 break;
 
         case USER_DIRECTORY: