home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / misc / volume1 / 8707 / 56 / email.c next >
Encoding:
C/C++ Source or Header  |  1990-07-13  |  818 b   |  56 lines

  1. #include <stdio.h>
  2. #include <pwd.h>
  3.  
  4. main (argc,argv) 
  5.  
  6. int    argc;
  7. char    *argv[];
  8.  
  9. {
  10.     struct    passwd *getpwnam();
  11.     struct    passwd *pwd;
  12.  
  13.     int    c;
  14.     int    eflg,aflg,errflg;
  15.     char    *username;
  16.     char    home[80];
  17.     extern    int    optind;
  18.     extern    char    *optarg;
  19.  
  20.     while ((c = getopt(argc,argv,"iu:")) != EOF)
  21.         switch (c) {
  22.         case 'i':
  23.             aflg++;
  24.             break;
  25.         case 'u':
  26.             username=optarg;
  27.             break;
  28.         case '?':
  29.             eflg++;
  30.             break;
  31.         }
  32.  
  33.         if (errflg) {
  34.         fprintf(stderr,"usage: email -i -u username\n");
  35.         sleep(30);
  36.         exit(2);
  37.         }
  38.  
  39.         if ((pwd = getpwnam(username)) == NULL) {
  40.         fprintf(stderr,"email: unknown username %s\n",username);
  41.         sleep(30);
  42.         exit(3);
  43.         }
  44.     
  45.         setgid(pwd->pw_gid);
  46.         setuid(pwd->pw_uid);
  47.  
  48.         strcpy(home,"HOME=");
  49.         strcat(home,pwd->pw_dir);
  50.         putenv(home);
  51.  
  52.         execl(MAILER,"mail",0);
  53.  
  54.         
  55. }
  56.