Annotation of 42BSD/usr.lib/sendmail/aux/newaliases.c, revision 1.1.1.1

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

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.