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;
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;
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;
#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);
#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);
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;
int home_resize_directory(
UserRecord *h,
- bool already_activated,
+ HomeSetupFlags flags,
PasswordCache *cache,
HomeSetup *setup,
UserRecord **ret_home) {
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;
#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);
int home_setup_fscrypt(
UserRecord *h,
- bool already_activated,
PasswordCache *cache,
HomeSetup *setup) {
#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);
int home_setup_luks(
UserRecord *h,
- bool already_activated,
+ HomeSetupFlags flags,
const char *force_image_path,
PasswordCache *cache,
HomeSetup *setup,
if (r < 0)
return r;
- if (already_activated) {
+ if (FLAGS_SET(flags, HOME_SETUP_ALREADY_ACTIVATED)) {
struct loop_info64 info;
const char *n;
r = home_setup_luks(
h,
- false,
+ 0,
NULL,
cache,
&setup,
int home_resize_luks(
UserRecord *h,
- bool already_activated,
+ HomeSetupFlags flags,
PasswordCache *cache,
HomeSetup *setup,
UserRecord **ret_home) {
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;
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.",
#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);
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);
int home_setup(
UserRecord *h,
- bool already_activated,
+ HomeSetupFlags flags,
PasswordCache *cache,
HomeSetup *setup,
UserRecord **ret_header_home) {
/* 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:
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;
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 */
}
_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);
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;
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);
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)));
_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);
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;
_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);
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;
.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);