1: /*
   2: **  Sendmail
   3: **  Copyright (c) 1983  Eric P. Allman
   4: **  Berkeley, California
   5: **
   6: **  Copyright (c) 1983 Regents of the University of California.
   7: **  All rights reserved.  The Berkeley software License Agreement
   8: **  specifies the terms and conditions for redistribution.
   9: */
  10: 
  11: #ifndef lint
  12: char copyright[] =
  13: "@(#) Copyright (c) 1980 Regents of the University of California.\n\
  14:  All rights reserved.\n";
  15: #endif not lint
  16: 
  17: #ifndef lint
  18: static char SccsId[] = "@(#)newaliases.c	5.1 (Berkeley) 6/7/85";
  19: #endif not lint
  20: 
  21: # include <stdio.h>
  22: # include <ctype.h>
  23: # include "sendmail.h"
  24: 
  25: static  char SccsId[] = "@(#)newaliases.c	5.1	6/7/85";
  26: 
  27: typedef struct { char *dptr; int dsize; } datum;
  28: char *aliases = ALIASFILE;
  29: char dirbuf[100];
  30: char pagbuf[100];
  31: int LineNo;
  32: char *To;
  33: int ExitStat;
  34: int Errors;
  35: HDR *Header;
  36: struct mailer *Mailer[MAXMAILERS+1];
  37: int NextMailer = 0;
  38: # ifdef DEBUG
  39: int Debug;
  40: # endif DEBUG
  41: 
  42: main(argc, argv)
  43:     int argc;
  44:     char *argv[];
  45: {
  46:     int f;
  47:     char line[BUFSIZ];
  48:     register char *p;
  49:     char *p2;
  50:     char *rhs;
  51:     int naliases, bytes, longest;
  52:     datum key, content;
  53:     bool skipping;
  54:     ADDRESS al, bl;
  55:     extern char *prescan();
  56:     extern ADDRESS *parse();
  57:     bool contin;
  58:     char *cffile = "/usr/lib/sendmail.cf";
  59: 
  60: # ifdef DEBUG
  61:     if (argc > 1 && strcmp(argv[1], "-T") == 0)
  62:     {
  63:         Debug = 100;
  64:         argc--;
  65:         argv++;
  66:     }
  67: # endif DEBUG
  68:     if (argc > 1)
  69:         aliases = argv[1];
  70:     if (argc > 2)
  71:         cffile = argv[2];
  72:     readcf(cffile);
  73: 
  74:     (void) strcpy(dirbuf, aliases);
  75:     (void) strcat(dirbuf, ".dir");
  76:     (void) strcpy(pagbuf, aliases);
  77:     (void) strcat(pagbuf, ".pag");
  78:     f = creat(dirbuf, 0666);
  79:     if (f < 0) {
  80:         perror(dirbuf);
  81:         exit(1);
  82:     }
  83:     (void) close(f);
  84:     f = creat(pagbuf, 0666);
  85:     if (f < 0) {
  86:         perror(pagbuf);
  87:         exit(1);
  88:     }
  89:     (void) close(f);
  90:     if (dbminit(aliases) < 0)
  91:         exit(1);
  92:     if (freopen(aliases, "r", stdin) == 0) {
  93:         perror(aliases);
  94:         exit(1);
  95:     }
  96: 
  97:     /* read and interpret lines */
  98:     LineNo = 0;
  99:     naliases = 0;
 100:     bytes = 0;
 101:     longest = 0;
 102:     skipping = FALSE;
 103:     while (fgets(line, sizeof (line), stdin) != NULL)
 104:     {
 105:         LineNo++;
 106:         switch (line[0])
 107:         {
 108:           case '#':
 109:           case '\n':
 110:           case '\0':
 111:             skipping = FALSE;
 112:             continue;
 113: 
 114:           case ' ':
 115:           case '\t':
 116:             if (!skipping)
 117:                 usrerr("Non-continuation line starts with space");
 118:             skipping = TRUE;
 119:             continue;
 120:         }
 121:         skipping = FALSE;
 122: 
 123:         /* process the LHS */
 124:         for (p = line; *p != '\0' && *p != ':' && *p != '\n'; p++)
 125:             continue;
 126:         if (*p == '\0' || *p == '\n')
 127:         {
 128:          syntaxerr:
 129:             usrerr("missing colon");
 130:             continue;
 131:         }
 132:         *p++ = '\0';
 133:         if (parse(line, &al, 1) == NULL)
 134:         {
 135:             *--p = ':';
 136:             goto syntaxerr;
 137:         }
 138:         rhs = p;
 139:         contin = FALSE;
 140:         for (;;)
 141:         {
 142:             register char c;
 143: 
 144:             /* do parsing & compression of addresses */
 145:             c = *p;
 146:             while (c != '\0')
 147:             {
 148:                 p2 = p;
 149:                 while (*p != '\n' && *p != ',' && *p != '\0')
 150:                     p++;
 151:                 c = *p;
 152:                 *p++ = '\0';
 153:                 if (*p2 == '\0')
 154:                 {
 155:                     p[-1] = c;
 156:                     continue;
 157:                 }
 158:                 parse(p2, &bl, -1);
 159:                 contin = (c == ',');
 160:                 p[-1] = c;
 161:                 while (isspace(*p))
 162:                     p++;
 163:             }
 164: 
 165:             /* see if there should be a continuation line */
 166:             if (!contin)
 167:                 break;
 168: 
 169:             /* read continuation line */
 170:             p--;
 171:             if (fgets(p, sizeof line - (p - line), stdin) == NULL)
 172:                 break;
 173:             LineNo++;
 174: 
 175:             if (!isspace(*p))
 176:                 usrerr("continuation line missing");
 177:         }
 178:         if (al.q_mailer != MN_LOCAL)
 179:         {
 180:             usrerr("cannot alias non-local names");
 181:             continue;
 182:         }
 183:         naliases++;
 184:         key.dsize = strlen(al.q_user) + 1;
 185:         key.dptr = al.q_user;
 186:         content.dsize = strlen(rhs) + 1;
 187:         if (content.dsize > longest)
 188:             longest = content.dsize;
 189:         content.dptr = rhs;
 190:         bytes += key.dsize + content.dsize;
 191:         if (store(key, content), 0)
 192:         /* if (f = store(key, content)) */
 193:             usrerr("Dbm internal error return %d from store\n", f);
 194:     }
 195:     fprintf(stderr, "%d aliases, %d bytes, longest %d bytes, %d errors\n",
 196:         naliases, bytes, longest, Errors);
 197: 
 198:     exit(ExitStat);
 199: }
 200: 
 201: usrerr(fmt, a, b, c, d, e)
 202:     char *fmt;
 203: {
 204:     Errors++;
 205:     fprintf(stderr, "line %d: ", LineNo);
 206:     fprintf(stderr, fmt, a, b, c, d, e);
 207:     fprintf(stderr, "\n");
 208:     return (-1);
 209: }
 210: 
 211: syserr(fmt, a, b, c, d, e)
 212:     char *fmt;
 213: {
 214:     return (usrerr(fmt, a, b, c, d, e));
 215: }

Defined functions

main defined in line 42; never used

Defined variables

Debug defined in line 39; used 2 times
Errors defined in line 34; used 2 times
ExitStat defined in line 33; used 1 times
LineNo defined in line 31; used 4 times
Mailer defined in line 36; never used
NextMailer defined in line 37; never used
SccsId defined in line 25; never used
To defined in line 32; never used
aliases defined in line 28; used 6 times
copyright defined in line 12; never used
dirbuf defined in line 29; used 4 times
pagbuf defined in line 30; used 4 times
Last modified: 1985-11-11
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 1195
Valid CSS Valid XHTML 1.0 Strict