From 2a7fb2bfef928c26a137e4649793feac79ec00b1 Mon Sep 17 00:00:00 2001 From: Guillem Jover Date: Tue, 22 Jan 2008 21:20:49 +0200 Subject: [PATCH] s-s-d: Properly set the supplementary groups on --chuid Set the supplementary groups if the real user or group are different than the ones we should switch to. Closes: #462075 --- ChangeLog | 6 +++++ debian/changelog | 5 +++++ utils/start-stop-daemon.c | 46 +++++++++++++++------------------------ 3 files changed, 28 insertions(+), 29 deletions(-) diff --git a/ChangeLog b/ChangeLog index c7f8e284..245df37c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2008-01-22 Guillem Jover + + * utils/start-stop-daemon.c (gid_in_current_groups): Remove function. + (main): Call initgroups if the real user or group are different than + the ones we should switch to. Call setgid before initgroups. + 2008-01-22 Raphael Hertzog * scripts/dpkg-genchanges.pl, scripts/dpkg-gencontrol.pl, diff --git a/debian/changelog b/debian/changelog index d9e897c6..dbea147a 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,9 +1,14 @@ dpkg (1.14.16.3) UNRELEASED; urgency=low + [ Raphael Hertzog ] * Remove the ":utf8" layer that utf8-encodes already valid utf8. Closes: #462098 * Disable variable substitution in dpkg-genchanges. Closes: #462079, #462089 + [ Guillem Jover ] + * Make start-stop-daemon set the supplementary groups if the real user or + group are different than the ones we should switch to. Closes: #462075 + -- Raphael Hertzog Tue, 22 Jan 2008 18:15:42 +0100 dpkg (1.14.16.2) unstable; urgency=low diff --git a/utils/start-stop-daemon.c b/utils/start-stop-daemon.c index 2a31f730..a59e2409 100644 --- a/utils/start-stop-daemon.c +++ b/utils/start-stop-daemon.c @@ -322,27 +322,6 @@ clear(struct pid_list **list) *list = NULL; } -static int -gid_in_current_groups(gid_t gid) -{ - gid_t *gids; - int i, ngroups; - - ngroups = getgroups(0, NULL); - gids = xmalloc(ngroups * sizeof(gid_t)); - getgroups(ngroups, gids); - - for (i = 0; i < ngroups; i++) { - if (gid == gids[i]) { - free(gids); - return 1; - } - } - - free(gids); - return 0; -} - static void do_help(void) { @@ -1285,6 +1264,8 @@ int main(int argc, char **argv) { int devnull_fd = -1; + gid_t rgid; + uid_t ruid; #ifdef HAVE_TIOCNOTTY int tty_fd = -1; #endif @@ -1413,18 +1394,25 @@ main(int argc, char **argv) if (chdir(changedir) < 0) fatal("Unable to chdir() to %s", changedir); - if (changegroup != NULL && *changegroup != '\0' && - getgid() != (gid_t)runas_gid) { - if (!gid_in_current_groups(runas_gid)) + rgid = getgid(); + ruid = getuid(); + if (changegroup != NULL) { + if (rgid != (gid_t)runas_gid) + if (setgid(runas_gid)) + fatal("Unable to set gid to %d", runas_gid); + + /* We assume that if our real user and group are the same as + * the ones we should switch to, the supplementary groups + * will be already in place. */ + if (rgid != (gid_t)runas_gid || ruid != (uid_t)runas_uid) if (initgroups(changeuser, runas_gid)) fatal("Unable to set initgroups() with gid %d", runas_gid); - if (setgid(runas_gid)) - fatal("Unable to set gid to %d", runas_gid); } - if (changeuser != NULL && getuid() != (uid_t)runas_uid) { - if (setuid(runas_uid)) - fatal("Unable to set uid to %s", changeuser); + if (changeuser != NULL) { + if (ruid != (uid_t)runas_uid) + if (setuid(runas_uid)) + fatal("Unable to set uid to %s", changeuser); } if (background) { -- 2.39.5