]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
homed: replace "already_activated" boolean parameter by a flags value
authorLennart Poettering <lennart@poettering.net>
Sun, 17 Oct 2021 07:42:15 +0000 (09:42 +0200)
committerLennart Poettering <lennart@poettering.net>
Sun, 17 Oct 2021 20:20:05 +0000 (22:20 +0200)
This is mostly preparation for further defined flags to be added in
later PRs/commits.

No change in behaviour just the flagsification.

src/home/homework-cifs.c
src/home/homework-cifs.h
src/home/homework-directory.c
src/home/homework-directory.h
src/home/homework-fscrypt.c
src/home/homework-fscrypt.h
src/home/homework-luks.c
src/home/homework-luks.h
src/home/homework.c
src/home/homework.h

index 62625ab8672e511c1ecbd799123ff99d94136959..e3b4b3e01e11cac449d1e06de689f77106d8556f 100644 (file)
 
 int home_setup_cifs(
                 UserRecord *h,
-                bool already_activated,
+                HomeSetupFlags flags,
                 HomeSetup *setup) {
 
         assert(h);
         assert(setup);
         assert(user_record_storage(h) == USER_CIFS);
 
-        if (already_activated)
+        if (FLAGS_SET(flags, HOME_SETUP_ALREADY_ACTIVATED))
                 setup->root_fd = open(user_record_home_directory(h), O_RDONLY|O_CLOEXEC|O_DIRECTORY|O_NOFOLLOW);
         else {
                 bool mounted = false;
@@ -117,7 +117,7 @@ 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, false, &setup);
+        r = home_setup_cifs(h, 0, &setup);
         if (r < 0)
                 return r;
 
@@ -160,7 +160,7 @@ 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, false, &setup);
+        r = home_setup_cifs(h, 0, &setup);
         if (r < 0)
                 return r;
 
index 6bba2c951a9937c82ee67055c37b38b3f44a03bc..820b95e1dbe50b3a5f626166243667bdb0d01243 100644 (file)
@@ -4,7 +4,7 @@
 #include "homework.h"
 #include "user-record.h"
 
-int home_setup_cifs(UserRecord *h, bool already_activated, HomeSetup *setup);
+int home_setup_cifs(UserRecord *h, HomeSetupFlags flags, HomeSetup *setup);
 
 int home_activate_cifs(UserRecord *h, PasswordCache *cache, UserRecord **ret_home);
 
index 4e978d2328d8de8e1c291439d5c4474be3d79664..c36b99ff2b0fbe8ee1a66fa4e6a3b1b44fa42c04 100644 (file)
@@ -13,7 +13,7 @@
 #include "tmpfile-util.h"
 #include "umask-util.h"
 
-int home_setup_directory(UserRecord *h, bool already_activated, HomeSetup *setup) {
+int home_setup_directory(UserRecord *h, HomeSetup *setup) {
         assert(h);
         assert(setup);
 
@@ -44,7 +44,7 @@ int home_activate_directory(
         assert_se(hdo = user_record_home_directory(h));
         hd = strdupa_safe(hdo);
 
-        r = home_setup(h, false, cache, &setup, &header_home);
+        r = home_setup(h, 0, cache, &setup, &header_home);
         if (r < 0)
                 return r;
 
@@ -192,7 +192,7 @@ int home_create_directory_or_subvolume(UserRecord *h, UserRecord **ret_home) {
 
 int home_resize_directory(
                 UserRecord *h,
-                bool already_activated,
+                HomeSetupFlags flags,
                 PasswordCache *cache,
                 HomeSetup *setup,
                 UserRecord **ret_home) {
@@ -205,7 +205,7 @@ int home_resize_directory(
         assert(ret_home);
         assert(IN_SET(user_record_storage(h), USER_DIRECTORY, USER_SUBVOLUME, USER_FSCRYPT));
 
-        r = home_setup(h, already_activated, cache, setup, NULL);
+        r = home_setup(h, flags, cache, setup, NULL);
         if (r < 0)
                 return r;
 
index 9f7e1470e275a07356a6b2d2360b55f493165a3e..fb1980c1f7f0a1d6640c5838854f29a01e5e8121 100644 (file)
@@ -4,7 +4,7 @@
 #include "homework.h"
 #include "user-record.h"
 
-int home_setup_directory(UserRecord *h, bool already_activated, HomeSetup *setup);
+int home_setup_directory(UserRecord *h, HomeSetup *setup);
 int home_activate_directory(UserRecord *h, PasswordCache *cache, UserRecord **ret_home);
 int home_create_directory_or_subvolume(UserRecord *h, UserRecord **ret_home);
-int home_resize_directory(UserRecord *h, bool already_activated, PasswordCache *cache, HomeSetup *setup, UserRecord **ret_home);
+int home_resize_directory(UserRecord *h, HomeSetupFlags flags, PasswordCache *cache, HomeSetup *setup, UserRecord **ret_home);
index 002b0b49b7ba383ba50869db5e7ec24fba9214a6..37903b8fff6303197c3ee33209467023fced4fda 100644 (file)
@@ -280,7 +280,6 @@ static int fscrypt_setup(
 
 int home_setup_fscrypt(
                 UserRecord *h,
-                bool already_activated,
                 PasswordCache *cache,
                 HomeSetup *setup) {
 
index becf4650a43d66f2747cb9f29f4217b885e57053..d8e0b8a2d13515fa2071fbd147a17258382a0e11 100644 (file)
@@ -4,7 +4,7 @@
 #include "homework.h"
 #include "user-record.h"
 
-int home_setup_fscrypt(UserRecord *h, bool already_activated, PasswordCache *cache, HomeSetup *setup);
+int home_setup_fscrypt(UserRecord *h, PasswordCache *cache, HomeSetup *setup);
 int home_create_fscrypt(UserRecord *h, char **effective_passwords, UserRecord **ret_home);
 
 int home_passwd_fscrypt(UserRecord *h, HomeSetup *setup, PasswordCache *cache, char **effective_passwords);
index f302ee5f0bcfb6e8fb09e07e87e6e319cbe250ac..7185b68ef5abb3e287b5fbdd65b1dfb3daec3d43 100644 (file)
@@ -1100,7 +1100,7 @@ static int lock_image_fd(int image_fd, const char *ip) {
 
 int home_setup_luks(
                 UserRecord *h,
-                bool already_activated,
+                HomeSetupFlags flags,
                 const char *force_image_path,
                 PasswordCache *cache,
                 HomeSetup *setup,
@@ -1129,7 +1129,7 @@ int home_setup_luks(
         if (r < 0)
                 return r;
 
-        if (already_activated) {
+        if (FLAGS_SET(flags, HOME_SETUP_ALREADY_ACTIVATED)) {
                 struct loop_info64 info;
                 const char *n;
 
@@ -1387,7 +1387,7 @@ int home_activate_luks(
 
         r = home_setup_luks(
                         h,
-                        false,
+                        0,
                         NULL,
                         cache,
                         &setup,
@@ -2701,7 +2701,7 @@ static int apply_resize_partition(int fd, sd_id128_t disk_uuids, struct fdisk_ta
 
 int home_resize_luks(
                 UserRecord *h,
-                bool already_activated,
+                HomeSetupFlags flags,
                 PasswordCache *cache,
                 HomeSetup *setup,
                 UserRecord **ret_home) {
@@ -2797,7 +2797,7 @@ int home_resize_luks(
                 new_image_size = new_image_size_rounded;
         }
 
-        r = home_setup_luks(h, already_activated, whole_disk, cache, setup, &header_home);
+        r = home_setup_luks(h, flags, whole_disk, cache, setup, &header_home);
         if (r < 0)
                 return r;
 
@@ -2852,7 +2852,7 @@ int home_resize_luks(
         resize_type = can_resize_fs(setup->root_fd, old_fs_size, new_fs_size);
         if (resize_type < 0)
                 return resize_type;
-        if (resize_type == CAN_RESIZE_OFFLINE && already_activated)
+        if (resize_type == CAN_RESIZE_OFFLINE && FLAGS_SET(flags, HOME_SETUP_ALREADY_ACTIVATED))
                 return log_error_errno(SYNTHETIC_ERRNO(ETXTBSY), "File systems of this type can only be resized offline, but is currently online.");
 
         log_info("Ready to resize image size %s → %s, partition size %s → %s, file system size %s → %s.",
index 770aa552e0a1e9230ed53424fe2656e091832c7c..1225adafdc46f82773db13abe8b9d6bfff32e639 100644 (file)
@@ -5,7 +5,7 @@
 #include "homework.h"
 #include "user-record.h"
 
-int home_setup_luks(UserRecord *h, bool already_activated, const char *force_image_path, PasswordCache *cache, HomeSetup *setup, UserRecord **ret_luks_home);
+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_deactivate_luks(UserRecord *h);
@@ -17,7 +17,7 @@ int home_create_luks(UserRecord *h, PasswordCache *cache, char **effective_passw
 
 int home_get_state_luks(UserRecord *h, HomeSetup *setup);
 
-int home_resize_luks(UserRecord *h, bool already_activated, PasswordCache *cache, HomeSetup *setup, UserRecord **ret_home);
+int home_resize_luks(UserRecord *h, HomeSetupFlags flags, PasswordCache *cache, HomeSetup *setup, UserRecord **ret_home);
 
 int home_passwd_luks(UserRecord *h, HomeSetup *setup, PasswordCache *cache, char **effective_passwords);
 
index 820cafd3bd47396b61c124b0d23bd65af0808c42..01286220cb9799d7c77abf45c8e81626e530ee7d 100644 (file)
@@ -370,7 +370,7 @@ int home_setup_done(HomeSetup *setup) {
 
 int home_setup(
                 UserRecord *h,
-                bool already_activated,
+                HomeSetupFlags flags,
                 PasswordCache *cache,
                 HomeSetup *setup,
                 UserRecord **ret_header_home) {
@@ -387,25 +387,25 @@ int home_setup(
 
         /* Makes a home directory accessible (through the root_fd file descriptor, not by path!). */
 
-        if (!already_activated) /* If we set up the directory, we should also drop caches once we are done */
+        if (!FLAGS_SET(flags, HOME_SETUP_ALREADY_ACTIVATED)) /* If we set up the directory, we should also drop caches once we are done */
                 setup->do_drop_caches = setup->do_drop_caches || user_record_drop_caches(h);
 
         switch (user_record_storage(h)) {
 
         case USER_LUKS:
-                return home_setup_luks(h, already_activated, NULL, cache, setup, ret_header_home);
+                return home_setup_luks(h, flags, NULL, cache, setup, ret_header_home);
 
         case USER_SUBVOLUME:
         case USER_DIRECTORY:
-                r = home_setup_directory(h, already_activated, setup);
+                r = home_setup_directory(h, setup);
                 break;
 
         case USER_FSCRYPT:
-                r = home_setup_fscrypt(h, already_activated, cache, setup);
+                r = home_setup_fscrypt(h, cache, setup);
                 break;
 
         case USER_CIFS:
-                r = home_setup_cifs(h, already_activated, setup);
+                r = home_setup_cifs(h, flags, setup);
                 break;
 
         default:
@@ -1373,7 +1373,7 @@ static int home_remove(UserRecord *h) {
         return 0;
 }
 
-static int home_validate_update(UserRecord *h, HomeSetup *setup) {
+static int home_validate_update(UserRecord *h, HomeSetup *setup, HomeSetupFlags *flags) {
         bool has_mount = false;
         int r;
 
@@ -1421,6 +1421,9 @@ static int home_validate_update(UserRecord *h, HomeSetup *setup) {
                 assert_not_reached();
         }
 
+        if (flags)
+                SET_FLAG(*flags, HOME_SETUP_ALREADY_ACTIVATED, has_mount);
+
         return has_mount; /* return true if the home record is already active */
 }
 
@@ -1428,7 +1431,7 @@ static int home_update(UserRecord *h, UserRecord **ret) {
         _cleanup_(user_record_unrefp) UserRecord *new_home = NULL, *header_home = NULL, *embedded_home = NULL;
         _cleanup_(home_setup_done) HomeSetup setup = HOME_SETUP_INIT;
         _cleanup_(password_cache_free) PasswordCache cache = {};
-        bool already_activated = false;
+        HomeSetupFlags flags = 0;
         int r;
 
         assert(h);
@@ -1439,13 +1442,11 @@ static int home_update(UserRecord *h, UserRecord **ret) {
                 return r;
         assert(r > 0); /* Insist that a password was verified */
 
-        r = home_validate_update(h, &setup);
+        r = home_validate_update(h, &setup, &flags);
         if (r < 0)
                 return r;
 
-        already_activated = r > 0;
-
-        r = home_setup(h, already_activated, &cache, &setup, &header_home);
+        r = home_setup(h, flags, &cache, &setup, &header_home);
         if (r < 0)
                 return r;
 
@@ -1482,7 +1483,7 @@ static int home_update(UserRecord *h, UserRecord **ret) {
 static int home_resize(UserRecord *h, UserRecord **ret) {
         _cleanup_(home_setup_done) HomeSetup setup = HOME_SETUP_INIT;
         _cleanup_(password_cache_free) PasswordCache cache = {};
-        bool already_activated = false;
+        HomeSetupFlags flags = 0;
         int r;
 
         assert(h);
@@ -1496,21 +1497,19 @@ static int home_resize(UserRecord *h, UserRecord **ret) {
                 return r;
         assert(r > 0); /* Insist that a password was verified */
 
-        r = home_validate_update(h, &setup);
+        r = home_validate_update(h, &setup, &flags);
         if (r < 0)
                 return r;
 
-        already_activated = r > 0;
-
         switch (user_record_storage(h)) {
 
         case USER_LUKS:
-                return home_resize_luks(h, already_activated, &cache, &setup, ret);
+                return home_resize_luks(h, flags, &cache, &setup, ret);
 
         case USER_DIRECTORY:
         case USER_SUBVOLUME:
         case USER_FSCRYPT:
-                return home_resize_directory(h, already_activated, &cache, &setup, ret);
+                return home_resize_directory(h, flags, &cache, &setup, ret);
 
         default:
                 return log_error_errno(SYNTHETIC_ERRNO(ENOTTY), "Resizing home directories of type '%s' currently not supported.", user_storage_to_string(user_record_storage(h)));
@@ -1522,7 +1521,7 @@ static int home_passwd(UserRecord *h, UserRecord **ret_home) {
         _cleanup_(strv_free_erasep) char **effective_passwords = NULL;
         _cleanup_(home_setup_done) HomeSetup setup = HOME_SETUP_INIT;
         _cleanup_(password_cache_free) PasswordCache cache = {};
-        bool already_activated = false;
+        HomeSetupFlags flags = 0;
         int r;
 
         assert(h);
@@ -1535,13 +1534,11 @@ static int home_passwd(UserRecord *h, UserRecord **ret_home) {
         if (r < 0)
                 return r;
 
-        r = home_validate_update(h, &setup);
+        r = home_validate_update(h, &setup, &flags);
         if (r < 0)
                 return r;
 
-        already_activated = r > 0;
-
-        r = home_setup(h, already_activated, &cache, &setup, &header_home);
+        r = home_setup(h, flags, &cache, &setup, &header_home);
         if (r < 0)
                 return r;
 
@@ -1597,7 +1594,7 @@ static int home_inspect(UserRecord *h, UserRecord **ret_home) {
         _cleanup_(user_record_unrefp) UserRecord *header_home = NULL, *new_home = NULL;
         _cleanup_(home_setup_done) HomeSetup setup = HOME_SETUP_INIT;
         _cleanup_(password_cache_free) PasswordCache cache = {};
-        bool already_activated = false;
+        HomeSetupFlags flags = 0;
         int r;
 
         assert(h);
@@ -1607,13 +1604,11 @@ static int home_inspect(UserRecord *h, UserRecord **ret_home) {
         if (r < 0)
                 return r;
 
-        r = home_validate_update(h, &setup);
+        r = home_validate_update(h, &setup, &flags);
         if (r < 0)
                 return r;
 
-        already_activated = r > 0;
-
-        r = home_setup(h, already_activated, &cache, &setup, &header_home);
+        r = home_setup(h, flags, &cache, &setup, &header_home);
         if (r < 0)
                 return r;
 
index 1bb985a44d2b1b8081ca19c7d397667b9c4c984c..9331452e3ea9241b5068fe316a5bf4e0126f6bea 100644 (file)
@@ -54,9 +54,14 @@ void password_cache_free(PasswordCache *cache);
                 .partition_size = UINT64_MAX,           \
         }
 
+/* Various flags for the operation of setting up a home directory */
+typedef enum HomeSetupFlags {
+        HOME_SETUP_ALREADY_ACTIVATED = 1 << 0, /* Open an already activated home, rather than activate it afresh */
+} HomeSetupFlags;
+
 int home_setup_done(HomeSetup *setup);
 
-int home_setup(UserRecord *h, bool already_activated, PasswordCache *cache, HomeSetup *setup, UserRecord **ret_header_home);
+int home_setup(UserRecord *h, HomeSetupFlags flags, PasswordCache *cache, HomeSetup *setup, UserRecord **ret_header_home);
 
 int home_refresh(UserRecord *h, HomeSetup *setup, UserRecord *header_home, PasswordCache *cache, struct statfs *ret_statfs, UserRecord **ret_new_home);