From: Lennart Poettering Date: Sun, 17 Oct 2021 07:42:15 +0000 (+0200) Subject: homed: replace "already_activated" boolean parameter by a flags value X-Git-Tag: v250-rc1~488 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=e1df968b334d2185ddfb0412135e439fe70578d0;p=thirdparty%2Fsystemd.git homed: replace "already_activated" boolean parameter by a flags value This is mostly preparation for further defined flags to be added in later PRs/commits. No change in behaviour just the flagsification. --- diff --git a/src/home/homework-cifs.c b/src/home/homework-cifs.c index 62625ab8672..e3b4b3e01e1 100644 --- a/src/home/homework-cifs.c +++ b/src/home/homework-cifs.c @@ -14,14 +14,14 @@ 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; diff --git a/src/home/homework-cifs.h b/src/home/homework-cifs.h index 6bba2c951a9..820b95e1dbe 100644 --- a/src/home/homework-cifs.h +++ b/src/home/homework-cifs.h @@ -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); diff --git a/src/home/homework-directory.c b/src/home/homework-directory.c index 4e978d2328d..c36b99ff2b0 100644 --- a/src/home/homework-directory.c +++ b/src/home/homework-directory.c @@ -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; diff --git a/src/home/homework-directory.h b/src/home/homework-directory.h index 9f7e1470e27..fb1980c1f7f 100644 --- a/src/home/homework-directory.h +++ b/src/home/homework-directory.h @@ -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); diff --git a/src/home/homework-fscrypt.c b/src/home/homework-fscrypt.c index 002b0b49b7b..37903b8fff6 100644 --- a/src/home/homework-fscrypt.c +++ b/src/home/homework-fscrypt.c @@ -280,7 +280,6 @@ static int fscrypt_setup( int home_setup_fscrypt( UserRecord *h, - bool already_activated, PasswordCache *cache, HomeSetup *setup) { diff --git a/src/home/homework-fscrypt.h b/src/home/homework-fscrypt.h index becf4650a43..d8e0b8a2d13 100644 --- a/src/home/homework-fscrypt.h +++ b/src/home/homework-fscrypt.h @@ -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); diff --git a/src/home/homework-luks.c b/src/home/homework-luks.c index f302ee5f0bc..7185b68ef5a 100644 --- a/src/home/homework-luks.c +++ b/src/home/homework-luks.c @@ -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.", diff --git a/src/home/homework-luks.h b/src/home/homework-luks.h index 770aa552e0a..1225adafdc4 100644 --- a/src/home/homework-luks.h +++ b/src/home/homework-luks.h @@ -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); diff --git a/src/home/homework.c b/src/home/homework.c index 820cafd3bd4..01286220cb9 100644 --- a/src/home/homework.c +++ b/src/home/homework.c @@ -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; diff --git a/src/home/homework.h b/src/home/homework.h index 1bb985a44d2..9331452e3ea 100644 --- a/src/home/homework.h +++ b/src/home/homework.h @@ -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);