core: improve messages about unknown users and groups
$ sudo build/systemd-run --uid=asdf whoami $ journalctl -e (whoami)[1007784]: run-p1007782-i5200512.service: Failed to determine user credentials: No such process (whoami)[1007784]: run-p1007782-i5200512.service: Failed at step USER spawning /usr/sbin/whoami: No such process systemd[1]: run-p1007782-i5200512.service: Main process exited, code=exited, status=217/USER systemd[1]: run-p1007782-i5200512.service: Failed with result 'exit-code'. Now: (whoami)[1013204]: run-p1013202-i5205932.service: Failed to determine credentials for user 'asdf': Unknown user (whoami)[1013204]: run-p1013202-i5205932.service: Failed at step USER spawning /usr/sbin/whoami: Invalid argument systemd[1]: run-p1013202-i5205932.service: Main process exited, code=exited, status=217/USER systemd[1]: run-p1013202-i5205932.service: Failed with result 'exit-code'.
This commit is contained in:
+11
-4
@@ -2087,8 +2087,11 @@ static int build_environment(
|
||||
assert(!c->user);
|
||||
|
||||
r = get_fixed_user("root", /* prefer_nss = */ false, &username, NULL, NULL, &home, &shell);
|
||||
if (r < 0)
|
||||
return log_debug_errno(r, "Failed to determine user credentials for root: %m");
|
||||
if (r < 0) {
|
||||
log_debug_errno(r, "Failed to determine credentials for user root: %s",
|
||||
STRERROR_USER(r));
|
||||
return ERRNO_IS_NEG_BAD_ACCOUNT(r) ? -EINVAL : r; /* Suppress confusing errno */
|
||||
}
|
||||
}
|
||||
|
||||
bool set_user_login_env = exec_context_get_set_login_environment(c);
|
||||
@@ -5265,7 +5268,9 @@ int exec_invoke(
|
||||
&username, &uid, &gid, &pwent_home, &shell);
|
||||
if (r < 0) {
|
||||
*exit_status = EXIT_USER;
|
||||
return log_error_errno(r, "Failed to determine user credentials: %m");
|
||||
log_error_errno(r, "Failed to determine credentials for user '%s': %s",
|
||||
u, STRERROR_USER(r));
|
||||
return ERRNO_IS_NEG_BAD_ACCOUNT(r) ? -EINVAL : r; /* Suppress confusing errno */
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5273,7 +5278,9 @@ int exec_invoke(
|
||||
r = get_fixed_group(context->group, &groupname, &gid);
|
||||
if (r < 0) {
|
||||
*exit_status = EXIT_GROUP;
|
||||
return log_error_errno(r, "Failed to determine group credentials: %m");
|
||||
log_error_errno(r, "Failed to determine credentials for group '%s': %s",
|
||||
u, STRERROR_GROUP(r));
|
||||
return ERRNO_IS_NEG_BAD_ACCOUNT(r) ? -EINVAL : r; /* Suppress confusing errno */
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+6
-2
@@ -348,7 +348,9 @@ static int scope_enter_start_chown(Scope *s) {
|
||||
|
||||
r = get_user_creds(&user, &uid, &gid, NULL, NULL, 0);
|
||||
if (r < 0) {
|
||||
log_unit_error_errno(UNIT(s), r, "Failed to resolve user \"%s\": %m", user);
|
||||
log_unit_error_errno(UNIT(s), r,
|
||||
"Failed to resolve user '%s': %s",
|
||||
user, STRERROR_USER(r));
|
||||
_exit(EXIT_USER);
|
||||
}
|
||||
}
|
||||
@@ -358,7 +360,9 @@ static int scope_enter_start_chown(Scope *s) {
|
||||
|
||||
r = get_group_creds(&group, &gid, 0);
|
||||
if (r < 0) {
|
||||
log_unit_error_errno(UNIT(s), r, "Failed to resolve group \"%s\": %m", group);
|
||||
log_unit_error_errno(UNIT(s), r,
|
||||
"Failed to resolve group '%s': %s",
|
||||
group, STRERROR_GROUP(r));
|
||||
_exit(EXIT_GROUP);
|
||||
}
|
||||
}
|
||||
|
||||
+6
-2
@@ -2056,7 +2056,9 @@ static int socket_chown(Socket *s, PidRef *ret_pid) {
|
||||
|
||||
r = get_user_creds(&user, &uid, &gid, NULL, NULL, 0);
|
||||
if (r < 0) {
|
||||
log_unit_error_errno(UNIT(s), r, "Failed to resolve user %s: %m", user);
|
||||
log_unit_error_errno(UNIT(s), r,
|
||||
"Failed to resolve user '%s': %s",
|
||||
user, STRERROR_USER(r));
|
||||
_exit(EXIT_USER);
|
||||
}
|
||||
}
|
||||
@@ -2066,7 +2068,9 @@ static int socket_chown(Socket *s, PidRef *ret_pid) {
|
||||
|
||||
r = get_group_creds(&group, &gid, 0);
|
||||
if (r < 0) {
|
||||
log_unit_error_errno(UNIT(s), r, "Failed to resolve group %s: %m", group);
|
||||
log_unit_error_errno(UNIT(s), r,
|
||||
"Failed to resolve group '%s': %s",
|
||||
group, STRERROR_GROUP(r));
|
||||
_exit(EXIT_GROUP);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user