Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 174362
Collapse All | Expand All

(-)src/start-stop-daemon.c (-23 / +34 lines)
Lines 562-589 Link Here
562
				break;
562
				break;
563
563
564
			case 'c':  /* --chuid <username>|<uid> */
564
			case 'c':  /* --chuid <username>|<uid> */
565
				/* we copy the string just in case we need the
566
				 * argument later. */
567
				{
565
				{
568
					char *p = optarg;
566
					char *p = optarg;
569
					char *cu = strsep (&p, ":");
567
					char *cu = strsep (&p, ":");
568
					struct passwd *pw = NULL;
569
570
					changeuser = strdup (cu);
570
					changeuser = strdup (cu);
571
					if (sscanf (cu, "%d", &tid) != 1) {
571
					if (sscanf (cu, "%d", &tid) != 1)
572
						struct passwd *pw = getpwnam (cu);
572
						pw = getpwnam (cu);
573
						if (! pw)
573
					else
574
							eerrorx ("%s: user `%s' not found", progname, cu);
574
						pw = getpwuid (tid);
575
						ch_uid = pw->pw_uid;
575
576
					} else
576
					if (! pw)
577
						ch_uid = tid;
577
						eerrorx ("%s: user `%s' not found", progname, cu);
578
					ch_uid = pw->pw_uid;
579
					if (! ch_gid)
580
						ch_gid = pw->pw_gid;
581
578
					if (p) {
582
					if (p) {
583
						struct group *gr = NULL;
579
						char *cg = strsep (&p, ":");
584
						char *cg = strsep (&p, ":");
580
						if (sscanf (cg, "%d", &tid) != 1) {
585
581
							struct group *gr = getgrnam (cg);
586
						if (sscanf (cg, "%d", &tid) != 1)
582
							if (! gr)
587
							gr = getgrnam (cg);
583
								eerrorx ("%s: group `%s' not found", progname, cg);
588
						else
584
							ch_gid = gr->gr_gid;
589
							gr = getgrgid (tid);
585
						} else
590
586
							ch_gid = tid;
591
						if (! gr)
592
							eerrorx ("%s: group `%s' not found", progname, cg);
593
						ch_gid = gr->gr_gid;
587
					}
594
					}
588
				}
595
				}
589
				break;
596
				break;
Lines 593-605 Link Here
593
				break;
600
				break;
594
601
595
			case 'g':  /* --group <group>|<gid> */
602
			case 'g':  /* --group <group>|<gid> */
596
				if (sscanf (optarg, "%d", &tid) != 1) {
603
				{
597
					struct group *gr = getgrnam (optarg);
604
					struct group *gr = getgrnam (optarg);
605
606
					if (sscanf (optarg, "%d", &tid) != 1)
607
						gr = getgrnam (optarg);
608
					else
609
						gr = getgrgid (tid);
610
598
					if (! gr)
611
					if (! gr)
599
						eerrorx ("%s: group `%s' not found", progname, optarg);
612
						eerrorx ("%s: group `%s' not found", progname, optarg);
600
					ch_gid = gr->gr_gid;
613
					ch_gid = gr->gr_gid;
601
				} else
614
				}
602
					ch_gid = tid;
603
				break;
615
				break;
604
616
605
			case 'm':  /* --make-pidfile */
617
			case 'm':  /* --make-pidfile */
Lines 821-831 Link Here
821
			eerrorx ("%s: pam error: %s", progname, pam_strerror(pamh, pamr));
833
			eerrorx ("%s: pam error: %s", progname, pam_strerror(pamh, pamr));
822
#endif
834
#endif
823
835
824
		if ((ch_gid) && setgid(ch_gid))
836
		if (ch_gid && setgid (ch_gid))
825
			eerrorx ("%s: unable to set groupid to %d", progname, ch_gid);
837
			eerrorx ("%s: unable to set groupid to %d", progname, ch_gid);
826
		if (changeuser && ch_gid)
838
		if (changeuser && initgroups (changeuser, ch_gid))
827
			if (initgroups (changeuser, ch_gid))
839
			eerrorx ("%s: initgroups (%s, %d)", progname, changeuser, ch_gid);
828
				eerrorx ("%s: initgroups (%s, %d)", progname, changeuser, ch_gid);
829
		if (ch_uid && setuid (ch_uid))
840
		if (ch_uid && setuid (ch_uid))
830
			eerrorx ("%s: unable to set userid to %d", progname, ch_uid);
841
			eerrorx ("%s: unable to set userid to %d", progname, ch_uid);
831
		else {
842
		else {

Return to bug 174362