Fix module loading, #174360. s-s-d now changes group when changing user, #174362.

This commit is contained in:
Roy Marples 2007-04-13 06:43:00 +00:00
parent 1f7770af7b
commit 824e9577e7
2 changed files with 40 additions and 24 deletions

View File

@ -1,11 +1,16 @@
# ChangeLog for Gentoo System Intialization ("rc") scripts # ChangeLog for Gentoo System Intialization ("rc") scripts
# Copyright 1999-2007 Gentoo Foundation; Distributed under the GPLv2 # Copyright 1999-2007 Gentoo Foundation; Distributed under the GPLv2
13 Apr 2007; Roy Marples <uberlord@gentoo.org>:
Fix module loading, #174360.
s-s-d now changes group when changing user, #174362.
* baselayout-2.0.0_alpha1 (11 Apr 2007) * baselayout-2.0.0_alpha1 (11 Apr 2007)
07 Apr 2007; Mike Frysinger <vapier@gentoo.org>: 07 Apr 2007; Mike Frysinger <vapier@gentoo.org>:
"modules-update" -> "update-modules". "modules-update" -> "update-modules".
05 Apr 2007; Roy Marples <uberlord@gentoo.org>: 05 Apr 2007; Roy Marples <uberlord@gentoo.org>:

View File

@ -562,28 +562,35 @@ int main (int argc, char **argv)
break; break;
case 'c': /* --chuid <username>|<uid> */ case 'c': /* --chuid <username>|<uid> */
/* we copy the string just in case we need the
* argument later. */
{ {
char *p = optarg; char *p = optarg;
char *cu = strsep (&p, ":"); char *cu = strsep (&p, ":");
struct passwd *pw = NULL;
changeuser = strdup (cu); changeuser = strdup (cu);
if (sscanf (cu, "%d", &tid) != 1) { if (sscanf (cu, "%d", &tid) != 1)
struct passwd *pw = getpwnam (cu); pw = getpwnam (cu);
if (! pw) else
eerrorx ("%s: user `%s' not found", progname, cu); pw = getpwuid (tid);
ch_uid = pw->pw_uid;
} else if (! pw)
ch_uid = tid; eerrorx ("%s: user `%s' not found", progname, cu);
ch_uid = pw->pw_uid;
if (! ch_gid)
ch_gid = pw->pw_gid;
if (p) { if (p) {
struct group *gr = NULL;
char *cg = strsep (&p, ":"); char *cg = strsep (&p, ":");
if (sscanf (cg, "%d", &tid) != 1) {
struct group *gr = getgrnam (cg); if (sscanf (cg, "%d", &tid) != 1)
if (! gr) gr = getgrnam (cg);
eerrorx ("%s: group `%s' not found", progname, cg); else
ch_gid = gr->gr_gid; gr = getgrgid (tid);
} else
ch_gid = tid; if (! gr)
eerrorx ("%s: group `%s' not found", progname, cg);
ch_gid = gr->gr_gid;
} }
} }
break; break;
@ -593,13 +600,18 @@ int main (int argc, char **argv)
break; break;
case 'g': /* --group <group>|<gid> */ case 'g': /* --group <group>|<gid> */
if (sscanf (optarg, "%d", &tid) != 1) { {
struct group *gr = getgrnam (optarg); struct group *gr = getgrnam (optarg);
if (sscanf (optarg, "%d", &tid) != 1)
gr = getgrnam (optarg);
else
gr = getgrgid (tid);
if (! gr) if (! gr)
eerrorx ("%s: group `%s' not found", progname, optarg); eerrorx ("%s: group `%s' not found", progname, optarg);
ch_gid = gr->gr_gid; ch_gid = gr->gr_gid;
} else }
ch_gid = tid;
break; break;
case 'm': /* --make-pidfile */ case 'm': /* --make-pidfile */
@ -821,11 +833,10 @@ int main (int argc, char **argv)
eerrorx ("%s: pam error: %s", progname, pam_strerror(pamh, pamr)); eerrorx ("%s: pam error: %s", progname, pam_strerror(pamh, pamr));
#endif #endif
if ((ch_gid) && setgid(ch_gid)) if (ch_gid && setgid (ch_gid))
eerrorx ("%s: unable to set groupid to %d", progname, ch_gid); eerrorx ("%s: unable to set groupid to %d", progname, ch_gid);
if (changeuser && ch_gid) if (changeuser && initgroups (changeuser, ch_gid))
if (initgroups (changeuser, ch_gid)) eerrorx ("%s: initgroups (%s, %d)", progname, changeuser, ch_gid);
eerrorx ("%s: initgroups (%s, %d)", progname, changeuser, ch_gid);
if (ch_uid && setuid (ch_uid)) if (ch_uid && setuid (ch_uid))
eerrorx ("%s: unable to set userid to %d", progname, ch_uid); eerrorx ("%s: unable to set userid to %d", progname, ch_uid);
else { else {