homed: return the correct error if an image file is not present when we try to activate it

We already return BUS_ERROR_HOME_ABSENT when we detect the image being
absent before we fork off the homework worker. Let's also return the
same error if the homework process notices the same condition while
actually doing something.

This mostly fixes a race, that the same condition seen at different
points in time results in the same errors.
This commit is contained in:
Lennart Poettering
2025-02-20 17:34:02 +01:00
parent 6828cc112a
commit 2cf95e5178
2 changed files with 5 additions and 2 deletions
+2
View File
@@ -689,6 +689,8 @@ static int convert_worker_errno(Home *h, int e, sd_bus_error *error) {
return sd_bus_error_setf(error, BUS_ERROR_HOME_CANT_AUTHENTICATE, "Home %s has no password or other authentication mechanism defined.", h->user_name);
case -EADDRINUSE:
return sd_bus_error_setf(error, BUS_ERROR_HOME_IN_USE, "Home %s is currently being used elsewhere.", h->user_name);
case -ENETUNREACH:
return sd_bus_error_setf(error, BUS_ERROR_HOME_ABSENT, "Backing storage for %s currently absent.", h->user_name);
}
return 0;
+3 -2
View File
@@ -926,7 +926,7 @@ static int home_activate(UserRecord *h, UserRecord **ret_home) {
if (r < 0)
return r;
if (r == USER_TEST_ABSENT)
return log_error_errno(SYNTHETIC_ERRNO(ENOENT), "Image path %s is missing, refusing.", user_record_image_path(h));
return log_error_errno(SYNTHETIC_ERRNO(ENETUNREACH), "Image path %s is missing, refusing.", user_record_image_path(h));
switch (user_record_storage(h)) {
@@ -1596,7 +1596,7 @@ static int home_validate_update(UserRecord *h, HomeSetup *setup, HomeSetupFlags
if (r < 0)
return r;
if (r == USER_TEST_ABSENT)
return log_error_errno(SYNTHETIC_ERRNO(ENOENT), "Image path %s does not exist", user_record_image_path(h));
return log_error_errno(SYNTHETIC_ERRNO(ENETUNREACH), "Image path %s does not exist", user_record_image_path(h));
switch (user_record_storage(h)) {
@@ -2092,6 +2092,7 @@ static int run(int argc, char *argv[]) {
* ENOSPC → not enough disk space for operation
* EKEYREVOKED → user record has not suitable hashed password or pkcs#11 entry, we cannot authenticate
* EADDRINUSE → home image is already used elsewhere (lock taken)
* ENETUNREACH → backing storage is currently not (image is ENOENT, or AF_UNIX socket to connect to is ENOENT)
*/
if (streq(argv[1], "activate"))