home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / mail / mmdf / mmdf-IIb.43 / uip / other / malias.c < prev    next >
Encoding:
C/C++ Source or Header  |  1987-05-19  |  2.5 KB  |  118 lines

  1. #include "util.h"
  2. #include "mmdf.h"
  3. #include "ch.h"
  4. #include "dm.h"
  5. #include <pwd.h>
  6.  
  7. extern char *index();
  8. extern char *rindex();
  9. extern char *multcat();
  10. extern struct passwd *getpwmid();
  11.  
  12. main (argc, argv)
  13. int argc;
  14. char *argv[];
  15. {
  16.     register int     i;
  17.     register char    *key;
  18.  
  19.     mmdf_init (argv[0]);
  20.     for (i=1; i < argc; i++) {
  21.         key = multcat (argv[i], "-outbound", (char *)0);
  22.         if (do_arg(key) == 0)
  23.             if (do_arg(argv[i]) == 0)
  24.                 printf ("no aliases for '%s'\n", argv[i]);
  25.         free (key);
  26.     }
  27.     exit(0);
  28. }
  29.  
  30. do_arg(arg)
  31. register char *arg;
  32. {
  33.     char    buf[LINESIZE];
  34.     char    alstr[LINESIZE];
  35.     register char    *p, *q;
  36.     FILE    *fp;
  37.     int    ret;
  38.     int     flags;
  39.  
  40.     if ((ret = aliasfetch(TRUE, arg, buf, &flags)) != OK) {
  41.         if (ret == MAYBE) {
  42.             printf("%s: Nameserver timeout\n");
  43.             return(0);
  44.         }
  45.         if (getpwmid (arg) != NULL) {
  46.             printf ("%s is a user\n", arg);
  47.             return(1);
  48.         }
  49.         return(0);
  50.     }
  51.  
  52.     strcpy(alstr, arg);
  53.     if (((flags & AL_PUBLIC) != AL_PUBLIC) && (getuid() != 0)) {
  54.         printf("%s is a private alias\n", alstr);
  55.         return(1);
  56.     }
  57.     if ((flags & AL_NOBYPASS) != AL_NOBYPASS)
  58.         strcat(alstr, " (bypassable)");
  59.     if( buf[0] == '~' ) {
  60.         printf("%s is a non-recursive alias: %s\n",
  61.             alstr, buf);
  62.         return(1);
  63.     }
  64.     if (index (buf, ',') != 0 && strindex (":include:", buf) < 0
  65.         && index (buf, '<') == 0 && index (buf, '|') == 0)
  66.     {
  67.         printf ("%s is list of aliases: %s\n", alstr, buf);
  68.         return(1);
  69.     }
  70.     if (((p = index (buf, '@')) == 0) && (index (buf, '/') == 0))
  71.     {
  72.         printf ("%s has alias %s\n", alstr, buf);
  73.         return(1);
  74.     }
  75.  
  76.     /* Assume if multiple entries, that     */
  77.     /* only the first one is used.        */
  78.     if ((q= index (buf, ',')) != 0)
  79.         *q = '\0';
  80.     if (p) {
  81.         *p++ = '\0';
  82.         if (ch_h2chan (p, 1)  != (Chan *) OK) {
  83.             printf ("%s is a list expanded on machine %s\n",
  84.                     alstr, p);
  85.             return(1);
  86.         }
  87.     } else
  88.         p = buf;
  89.     if ((p = index (buf, '/')) == 0) {
  90.         printf ("bad format for alias '%s': value '%s'\n",
  91.                 alstr, buf);
  92.         return(1);
  93.     }
  94.     if ((q = index (buf, '|')) != 0) {
  95.         *q++ = '\0';
  96.         printf ("%s is a pipe alias which runs %s as user %s\n",
  97.                 alstr, q, buf[0] ? buf : "root");
  98.         return(1);
  99.     }
  100.     if (index (buf, '<') == 0 && strindex (":include:", buf) < 0)
  101.     {
  102.         *p++ = '\0';
  103.         printf ("mail for %s is filed in %s as user %s\n",
  104.                 alstr, p, buf[0] ? buf : "root");
  105.         return(1);
  106.     }
  107.     printf ("%s expands to contents of list file %s:\n", 
  108.         alstr, p);
  109.     if ((fp = fopen (p, "r")) == NULL) {
  110.         printf ("unable to open file %s\n", p);
  111.         return(1);
  112.     }
  113.     while (fgets (buf, LINESIZE, fp) != NULL)
  114.         printf ("%s", buf);
  115.     fclose (fp);
  116.     return(1);
  117. }
  118.