home: when adding a binding for a user record, use common code for determining automatic image path
Make use of the new user_record_build_image_path() helper the previous commit added to share some code. Also, let's make sure we update all parsed-out fields with the new data from the binding, so that the parsed-out fields are definitely up-to-date.
This commit is contained in:
@@ -921,12 +921,6 @@ static int home_create(UserRecord *h, UserRecord **ret_home) {
|
||||
GID_INVALID);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to change storage type to LUKS: %m");
|
||||
|
||||
if (!h->image_path_auto) {
|
||||
h->image_path_auto = strjoin("/home/", user_record_user_name_and_realm(h), new_storage == USER_LUKS ? ".home" : ".homedir");
|
||||
if (!h->image_path_auto)
|
||||
return log_oom();
|
||||
}
|
||||
}
|
||||
|
||||
r = user_record_test_image_path_and_warn(h);
|
||||
|
||||
@@ -276,7 +276,7 @@ int user_record_add_binding(
|
||||
|
||||
_cleanup_(json_variant_unrefp) JsonVariant *new_binding_entry = NULL, *binding = NULL;
|
||||
char smid[SD_ID128_STRING_MAX], partition_uuids[37], luks_uuids[37], fs_uuids[37];
|
||||
_cleanup_free_ char *ip = NULL, *hd = NULL;
|
||||
_cleanup_free_ char *ip = NULL, *hd = NULL, *ip_auto = NULL, *lc = NULL, *lcm = NULL, *fst = NULL;
|
||||
sd_id128_t mid;
|
||||
int r;
|
||||
|
||||
@@ -294,6 +294,10 @@ int user_record_add_binding(
|
||||
ip = strdup(image_path);
|
||||
if (!ip)
|
||||
return -ENOMEM;
|
||||
} else if (!h->image_path && storage >= 0) {
|
||||
r = user_record_build_image_path(storage, user_record_user_name_and_realm(h), &ip_auto);
|
||||
if (r < 0)
|
||||
return r;
|
||||
}
|
||||
|
||||
if (home_directory) {
|
||||
@@ -302,6 +306,24 @@ int user_record_add_binding(
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
if (file_system_type) {
|
||||
fst = strdup(file_system_type);
|
||||
if (!fst)
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
if (luks_cipher) {
|
||||
lc = strdup(luks_cipher);
|
||||
if (!lc)
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
if (luks_cipher_mode) {
|
||||
lcm = strdup(luks_cipher_mode);
|
||||
if (!lcm)
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
r = json_build(&new_binding_entry,
|
||||
JSON_BUILD_OBJECT(
|
||||
JSON_BUILD_PAIR_CONDITION(!!image_path, "imagePath", JSON_BUILD_STRING(image_path)),
|
||||
@@ -348,6 +370,8 @@ int user_record_add_binding(
|
||||
|
||||
if (ip)
|
||||
free_and_replace(h->image_path, ip);
|
||||
if (ip_auto)
|
||||
free_and_replace(h->image_path_auto, ip_auto);
|
||||
|
||||
if (!sd_id128_is_null(partition_uuid))
|
||||
h->partition_uuid = partition_uuid;
|
||||
@@ -358,11 +382,22 @@ int user_record_add_binding(
|
||||
if (!sd_id128_is_null(fs_uuid))
|
||||
h->file_system_uuid = fs_uuid;
|
||||
|
||||
if (lc)
|
||||
free_and_replace(h->luks_cipher, lc);
|
||||
if (lcm)
|
||||
free_and_replace(h->luks_cipher_mode, lcm);
|
||||
if (luks_volume_key_size != UINT64_MAX)
|
||||
h->luks_volume_key_size = luks_volume_key_size;
|
||||
|
||||
if (fst)
|
||||
free_and_replace(h->file_system_type, fst);
|
||||
if (hd)
|
||||
free_and_replace(h->home_directory, hd);
|
||||
|
||||
if (uid_is_valid(uid))
|
||||
h->uid = uid;
|
||||
if (gid_is_valid(gid))
|
||||
h->gid = gid;
|
||||
|
||||
h->mask |= USER_RECORD_BINDING;
|
||||
return 1;
|
||||
|
||||
Reference in New Issue
Block a user