home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume22 / auth-utils / part01 / util / setuid.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-04-29  |  576 b   |  23 lines

  1. /* setuid version 1.0, 4/20/90. */
  2.  
  3. #include <stdio.h>
  4. #include <pwd.h>
  5.  
  6. main(argc,argv)
  7. int argc;
  8. char *argv[];
  9. {
  10.  struct passwd pwm;
  11.  struct passwd *pw = &pwm;
  12.  
  13.  if (argc < 3)
  14.    { fputs("Usage: setuid username program [ arg ... ]\n",stderr); exit(1); }
  15.  if ((sscanf(argv[1],"%d",&pw->pw_uid) < 1) && (!(pw = getpwnam(argv[1]))))
  16.    { fprintf(stderr,"setuid: fatal: user %s unknown\n",argv[1]); exit(2); }
  17.  if (setuid(pw->pw_uid) == -1)
  18.    { perror("setuid: fatal: cannot setuid"); exit(3); }
  19.  execvp(argv[2],argv + 2);
  20.  perror("setuid: fatal: cannot execute");
  21.  exit(4);
  22. }
  23.