Skip to content

Commit 2bd057d

Browse files
committed
supervise-daemon: always call setgroups, defaulting to count = 0
services started by init don't get any supplementary groups, but anything started from a shell would inherit the groups, causing inconsistent behaviour we can either clear all groups, or always initalize root's groups. since other init systems does not initialize anything, including us at boot, let's just always clear them unconditionally
1 parent 6e6afa1 commit 2bd057d

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

src/supervise-daemon/supervise-daemon.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ RC_NORETURN static void child_process(char *exec, char **argv)
384384
char start_time_string[20];
385385
FILE *fp;
386386
gid_t group_buf[32], *group_list = group_buf;
387-
int group_count = ARRAY_SIZE(group_buf);
387+
int group_count = 0;
388388

389389
#ifdef HAVE_PAM
390390
pam_handle_t *pamh = NULL;
@@ -445,10 +445,14 @@ RC_NORETURN static void child_process(char *exec, char **argv)
445445
}
446446
#endif
447447

448-
if (changeuser && getgrouplist(changeuser, gid, group_list, &group_count) < 0) {
449-
group_list = xmalloc(group_count * sizeof(*group_list));
450-
if (getgrouplist(changeuser, gid, group_list, &group_count) < 0)
451-
eerrorx("%s: getgrouplist(%s, %"PRIuMAX")", applet, changeuser, (uintmax_t)gid);
448+
if (changeuser) {
449+
/* getgrouplist is a stupid api. */
450+
group_count = ARRAY_SIZE(group_buf);
451+
if (getgrouplist(changeuser, gid, group_list, &group_count) < 0) {
452+
group_list = xmalloc(group_count * sizeof(*group_list));
453+
if (getgrouplist(changeuser, gid, group_list, &group_count) < 0)
454+
eerrorx("%s: getgrouplist(%s, %"PRIuMAX")", applet, changeuser, (uintmax_t)gid);
455+
}
452456
}
453457

454458
/* Close any fd's to the passwd database */
@@ -462,7 +466,7 @@ RC_NORETURN static void child_process(char *exec, char **argv)
462466

463467
if (gid && setgid(gid))
464468
eerrorx("%s: unable to set groupid to %"PRIuMAX, applet, (uintmax_t)gid);
465-
if (changeuser && setgroups(group_count, group_list) < 0)
469+
if (setgroups(group_count, group_list) < 0)
466470
eerrorx("%s: setgroups() failed", applet);
467471
if (group_list != group_buf)
468472
free(group_list);

0 commit comments

Comments
 (0)