/[baselayout]/trunk/src/start-stop-daemon.c
Gentoo

Diff of /trunk/src/start-stop-daemon.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 2577 Revision 2586
560 case 'b': /* --background */ 560 case 'b': /* --background */
561 background = true; 561 background = true;
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 else
574 pw = getpwuid (tid);
575
573 if (! pw) 576 if (! pw)
574 eerrorx ("%s: user `%s' not found", progname, cu); 577 eerrorx ("%s: user `%s' not found", progname, cu);
575 ch_uid = pw->pw_uid; 578 ch_uid = pw->pw_uid;
576 } else 579 if (! ch_gid)
577 ch_uid = tid; 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, ":");
585
580 if (sscanf (cg, "%d", &tid) != 1) { 586 if (sscanf (cg, "%d", &tid) != 1)
581 struct group *gr = getgrnam (cg); 587 gr = getgrnam (cg);
588 else
589 gr = getgrgid (tid);
590
582 if (! gr) 591 if (! gr)
583 eerrorx ("%s: group `%s' not found", progname, cg); 592 eerrorx ("%s: group `%s' not found", progname, cg);
584 ch_gid = gr->gr_gid; 593 ch_gid = gr->gr_gid;
585 } else
586 ch_gid = tid;
587 } 594 }
588 } 595 }
589 break; 596 break;
590 597
591 case 'd': /* --chdir /new/dir */ 598 case 'd': /* --chdir /new/dir */
592 ch_dir = optarg; 599 ch_dir = optarg;
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 */
606 makepidfile = true; 618 makepidfile = true;
607 break; 619 break;
819 pamr = pam_open_session (pamh, PAM_SILENT); 831 pamr = pam_open_session (pamh, PAM_SILENT);
820 if (pamr != PAM_SUCCESS) 832 if (pamr != PAM_SUCCESS)
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)
827 if (initgroups (changeuser, ch_gid)) 838 if (changeuser && initgroups (changeuser, ch_gid))
828 eerrorx ("%s: initgroups (%s, %d)", progname, changeuser, ch_gid); 839 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 {
832 struct passwd *passwd = getpwuid (ch_uid); 843 struct passwd *passwd = getpwuid (ch_uid);
833 if (passwd) { 844 if (passwd) {

Legend:
Removed from v.2577  
changed lines
  Added in v.2586

  ViewVC Help
Powered by ViewVC 1.1.20