Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions src/start-stop-daemon/start-stop-daemon.c
Original file line number Diff line number Diff line change
Expand Up @@ -892,7 +892,7 @@ int main(int argc, char **argv)
/* Child process - lets go! */
if (pid == 0) {
gid_t group_buf[32], *group_list = group_buf;
int group_count = ARRAY_SIZE(group_buf);
int group_count = 0;
pid_t mypid = getpid();
close(pipefd[0]); /* Close the read end of the pipe. */
umask(numask);
Expand Down Expand Up @@ -950,10 +950,13 @@ int main(int argc, char **argv)
applet, pam_strerror(pamh, pamr));
}
#endif
if (changeuser && getgrouplist(changeuser, gid, group_list, &group_count) < 0) {
group_list = xmalloc(group_count * sizeof(*group_list));
if (getgrouplist(changeuser, gid, group_list, &group_count) < 0)
eerrorx("%s: getgrouplist(%s, %"PRIuMAX")", applet, changeuser, (uintmax_t)gid);
if (changeuser) {
group_count = ARRAY_SIZE(group_buf);
if (getgrouplist(changeuser, gid, group_list, &group_count) < 0) {
group_list = xmalloc(group_count * sizeof(*group_list));
if (getgrouplist(changeuser, gid, group_list, &group_count) < 0)
eerrorx("%s: getgrouplist(%s, %"PRIuMAX")", applet, changeuser, (uintmax_t)gid);
}
}

/* Close any fd's to the passwd database */
Expand All @@ -980,7 +983,7 @@ int main(int argc, char **argv)
if (gid && setgid(gid))
eerrorx("%s: unable to set groupid to %"PRIuMAX,
applet, (uintmax_t)gid);
if (changeuser && setgroups(group_count, group_list))
if (setgroups(group_count, group_list))
eerrorx("%s: setgroups() failed", applet);
if (group_list != group_buf)
free(group_list);
Expand Down
16 changes: 10 additions & 6 deletions src/supervise-daemon/supervise-daemon.c
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ RC_NORETURN static void child_process(char *exec, char **argv)
char start_time_string[20];
FILE *fp;
gid_t group_buf[32], *group_list = group_buf;
int group_count = ARRAY_SIZE(group_buf);
int group_count = 0;

#ifdef HAVE_PAM
pam_handle_t *pamh = NULL;
Expand Down Expand Up @@ -445,10 +445,14 @@ RC_NORETURN static void child_process(char *exec, char **argv)
}
#endif

if (changeuser && getgrouplist(changeuser, gid, group_list, &group_count) < 0) {
group_list = xmalloc(group_count * sizeof(*group_list));
if (getgrouplist(changeuser, gid, group_list, &group_count) < 0)
eerrorx("%s: getgrouplist(%s, %"PRIuMAX")", applet, changeuser, (uintmax_t)gid);
if (changeuser) {
/* getgrouplist is a stupid api. */
group_count = ARRAY_SIZE(group_buf);
if (getgrouplist(changeuser, gid, group_list, &group_count) < 0) {
group_list = xmalloc(group_count * sizeof(*group_list));
if (getgrouplist(changeuser, gid, group_list, &group_count) < 0)
eerrorx("%s: getgrouplist(%s, %"PRIuMAX")", applet, changeuser, (uintmax_t)gid);
}
}

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

if (gid && setgid(gid))
eerrorx("%s: unable to set groupid to %"PRIuMAX, applet, (uintmax_t)gid);
if (changeuser && setgroups(group_count, group_list) < 0)
if (setgroups(group_count, group_list) < 0)
eerrorx("%s: setgroups() failed", applet);
if (group_list != group_buf)
free(group_list);
Expand Down
Loading