Default to user/group root for services and check for errors

This is a refactor of getuser() and getgroup() so that they always
return a valid user, and group, for all normal use-cases.  When an
error occurs we now handle it properly in service_fork() so as to
not attempt to start services with an invalid user/group setting
as root.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
Joachim Wiberg committed 2025-12-31 23:29:28 +01:00
1 parent 21753e26dd
commit d0176612c9
2 files changed
+50 -4

No files matched your search

+12
View File
@@ -556,6 +556,18 @@ static pid_t service_fork(svc_t *svc)
#else
int uid = getuser(svc->username, &home);
int gid = getgroup(svc->group);
/* Check for invalid user/group - fail rather than silent fallback */
if (uid < 0) {
err(1, "%s: user '%s' not found, cannot start service",
svc_ident(svc, NULL, 0), svc->username);
return -1;
}
if (gid < 0) {
err(1, "%s: group '%s' not found, cannot start service",
svc_ident(svc, NULL, 0), svc->group);
return -1;
}
#endif
sched_yield();