+2008-01-22 Guillem Jover <guillem@debian.org>
+
+ * 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 <hertzog@debian.org>
* scripts/dpkg-genchanges.pl, scripts/dpkg-gencontrol.pl,
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 <hertzog@debian.org> Tue, 22 Jan 2008 18:15:42 +0100
dpkg (1.14.16.2) unstable; urgency=low
*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)
{
main(int argc, char **argv)
{
int devnull_fd = -1;
+ gid_t rgid;
+ uid_t ruid;
#ifdef HAVE_TIOCNOTTY
int tty_fd = -1;
#endif
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) {