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

Defined functions

main defined in line 38; never used

Defined variables

Debug defined in line 35; used 1 times
  • in line 59
Errors defined in line 30; used 2 times
ExitStat defined in line 29; used 1 times
LineNo defined in line 27; used 4 times
Mailer defined in line 32; never used
NextMailer defined in line 33; never used
SccsId defined in line 16; never used
To defined in line 28; never used
aliases defined in line 24; used 6 times
copyright defined in line 12; never used
dirbuf defined in line 25; used 4 times
pagbuf defined in line 26; used 4 times
Last modified: 1996-10-25
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 2846
Valid CSS Valid XHTML 1.0 Strict