home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / unix / volume4 / uumail3 / part1 / uux.c < prev   
C/C++ Source or Header  |  1986-11-30  |  4KB  |  139 lines

  1. /*
  2.  * a "fake" uux to replace the realone to allow uumail to intercept
  3.  * mail at sites that mail not be able to recompile their mailers
  4.  * Called via "uux - system!rmail user" from, normally, /bin/mail.
  5. ***************************************************************************
  6. This work in its current form is Copyright 1986 Stan Barber
  7. with the exception of opath, gethostname and the original getpath which
  8. as far as I know are in the Public Domain. This software may be distributed
  9. freely as long as no profit is made from such distribution and this notice
  10. is reproducted in whole.
  11. ***************************************************************************
  12. This software is provided on an "as is" basis with no guarantee of 
  13. usefulness or correctness of operation for any purpose, intended or
  14. otherwise. The author is in no way liable for this software's performance
  15. or any damage it may cause to any data of any kind anywhere.
  16. ***************************************************************************
  17.  * $Log:    uux.c,v $
  18.  * Revision 3.0  86/03/14  12:05:06  sob
  19.  * Release of 3/15/86 --- 3rd Release
  20.  * 
  21.  * Revision 1.6  86/03/14  11:57:51  sob
  22.  * 
  23.  * 
  24.  * Revision 1.5  86/03/11  11:29:17  sob
  25.  * Added Copyright Notice
  26.  * 
  27.  * Revision 1.4  86/02/17  18:07:48  sob
  28.  * Moved REALUUX and UUMAIL definitions to the makefile
  29.  * 
  30.  * Revision 1.3  86/02/17  17:58:15  sob
  31.  * Small syntax problem
  32.  * 
  33.  * Revision 1.2  86/02/17  17:55:45  sob
  34.  * Corrected to remove parens from destbuf.
  35.  * 
  36.  * Revision 1.1  86/02/17  17:45:10  sob
  37.  * Initial revision
  38.  * 
  39.  *
  40.  */
  41.  
  42. #define _DEFINE
  43.  
  44. #include "uuconf.h"
  45. static char rcsid[] = "$Header: uux.c,v 3.0 86/03/14 12:05:06 sob RELEASE_3 $";
  46.  
  47. extern FILE *popen();
  48. extern char *index();
  49. extern struct passwd *getpwnam();
  50.  
  51. char sysbuf[BUFSIZ];
  52. char destbuf[BUFSIZ];
  53.  
  54. main(argc, argv)
  55. int argc;
  56. char **argv;
  57. {
  58.     char *command;
  59.     struct passwd *pwd;
  60.     char cmd[BUFSIZ];
  61.     char *system = sysbuf;
  62.     char **psystem = &system;
  63.     FILE *netf;
  64.     int c;
  65.  
  66.     if ((argc != 4) || strcmp("-", argv[1]))  /* look for form 
  67.                             of uux command */
  68.         realuux(argv);    
  69.  
  70.     strcpy(sysbuf, argv[2]);    /* save destination system */
  71.  
  72.     if ((command = index(sysbuf, '!')) == NULL)
  73.         realuux(argv);     
  74.     *command++ = 0;
  75.     if (strcmp("rmail", command))    /* look for rmail in command */
  76.         realuux(argv);        
  77.  
  78.     mystrcpy(destbuf, argv[3]);      /*save destination path */
  79.                     /* but get rid of parens */
  80.     /* become UUCP */
  81.     setpwent();
  82.     pwd = getpwnam("uucp");
  83.     if (pwd == NULL) {
  84.         fprintf(stderr, "Can't suid to \"uucp\" in %s\n", REALUUX);
  85.         exit(1);    /* sigh */
  86.     }
  87.     endpwent();
  88.     setuid(pwd->pw_uid);
  89.  
  90.     /* send the mail to uumail */
  91.     sprintf(cmd, "uumail %s!%s", UUMAIL, sysbuf,destbuf);
  92.     if ((netf = popen(cmd, "w")) == NULL)
  93.         exit(EX_TEMPFAIL);    /* failure */
  94.  
  95.     /* send the actual mail */
  96.     while ((c = getchar()) != EOF)
  97.         putc(c, netf);
  98.     fflush(netf);
  99.     exit (pclose(netf)?1:0);    /* causes mail to do the right thing */
  100. }
  101.  
  102. realuux(argv)
  103. char **argv;
  104. {
  105.     int pid, sts;
  106.  
  107.     /* running suid root.  become us again */
  108.     setuid(getuid());
  109.  
  110.         if ((pid = fork()) == -1) {
  111.                 fprintf(stderr, "uux: can't create proc for %s\n",REALUUX);
  112.                 exit(1);
  113.         }
  114.         if (pid) {
  115.                 while (wait(&sts) != pid) {
  116.                         if (wait(&sts)==-1)
  117.                                 exit(1);
  118.                 }
  119.                 exit(sts?1:0);
  120.         }
  121.     execv(REALUUX, argv);
  122.     fprintf(stderr, "uux: can't exec %s\n",REALUUX);
  123.     exit (1);
  124. }
  125.  
  126. /* remove parens for t and put what's left in s */
  127. mystrcpy(s,t)
  128. char * s, *t;
  129. {
  130.     int x;
  131.     while (x = *t++){
  132.         if ((x == '(') || (x == ')'))
  133.             continue;
  134.         *s++ = x;
  135.     }
  136.     
  137.     *s = x;
  138. }
  139.