|
|
1.1 root 1: /*
2: * Copyright (c) 1983 Eric P. Allman
3: * Copyright (c) 1988 Regents of the University of California.
4: * All rights reserved.
5: *
6: * Redistribution and use in source and binary forms are permitted provided
7: * that: (1) source distributions retain this entire copyright notice and
8: * comment, and (2) distributions including binaries display the following
9: * acknowledgement: ``This product includes software developed by the
10: * University of California, Berkeley and its contributors'' in the
11: * documentation or other materials provided with the distribution and in
12: * all advertising materials mentioning features or use of this software.
13: * Neither the name of the University nor the names of its contributors may
14: * be used to endorse or promote products derived from this software without
15: * specific prior written permission.
16: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
17: * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
18: * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
19: */
20:
21: #ifndef lint
22: char copyright[] =
23: "@(#) Copyright (c) 1988 Regents of the University of California.\n\
24: All rights reserved.\n";
25: #endif /* not lint */
26:
27: #ifndef lint
28: static char sccsid[] = "@(#)newaliases.c 5.4 (Berkeley) 6/1/90";
29: #endif /* not lint */
30:
31: # include <stdio.h>
32: # include <ctype.h>
33: # include "sendmail.h"
34: # include "pathnames.h"
35:
36: static char SccsId[] = "@(#)newaliases.c 5.4 6/1/90";
37:
38: typedef struct { char *dptr; int dsize; } datum;
39: char *aliases = ALIASFILE;
40: char dirbuf[100];
41: char pagbuf[100];
42: int LineNo;
43: char *To;
44: int ExitStat;
45: int Errors;
46: HDR *Header;
47: struct mailer *Mailer[MAXMAILERS+1];
48: int NextMailer = 0;
49: # ifdef DEBUG
50: int Debug;
51: # endif DEBUG
52:
53: main(argc, argv)
54: int argc;
55: char *argv[];
56: {
57: int f;
58: char line[BUFSIZ];
59: register char *p;
60: char *p2;
61: char *rhs;
62: int naliases, bytes, longest;
63: datum key, content;
64: bool skipping;
65: ADDRESS al, bl;
66: extern char *prescan();
67: extern ADDRESS *parse();
68: bool contin;
69: char *cffile = _PATH_SENDMAILCF;
70:
71: # ifdef DEBUG
72: if (argc > 1 && strcmp(argv[1], "-T") == 0)
73: {
74: Debug = 100;
75: argc--;
76: argv++;
77: }
78: # endif DEBUG
79: if (argc > 1)
80: aliases = argv[1];
81: if (argc > 2)
82: cffile = argv[2];
83: readcf(cffile);
84:
85: (void) strcpy(dirbuf, aliases);
86: (void) strcat(dirbuf, ".dir");
87: (void) strcpy(pagbuf, aliases);
88: (void) strcat(pagbuf, ".pag");
89: f = creat(dirbuf, 0666);
90: if (f < 0) {
91: perror(dirbuf);
92: exit(1);
93: }
94: (void) close(f);
95: f = creat(pagbuf, 0666);
96: if (f < 0) {
97: perror(pagbuf);
98: exit(1);
99: }
100: (void) close(f);
101: if (dbminit(aliases) < 0)
102: exit(1);
103: if (freopen(aliases, "r", stdin) == 0) {
104: perror(aliases);
105: exit(1);
106: }
107:
108: /* read and interpret lines */
109: LineNo = 0;
110: naliases = 0;
111: bytes = 0;
112: longest = 0;
113: skipping = FALSE;
114: while (fgets(line, sizeof (line), stdin) != NULL)
115: {
116: LineNo++;
117: switch (line[0])
118: {
119: case '#':
120: case '\n':
121: case '\0':
122: skipping = FALSE;
123: continue;
124:
125: case ' ':
126: case '\t':
127: if (!skipping)
128: usrerr("Non-continuation line starts with space");
129: skipping = TRUE;
130: continue;
131: }
132: skipping = FALSE;
133:
134: /* process the LHS */
135: for (p = line; *p != '\0' && *p != ':' && *p != '\n'; p++)
136: continue;
137: if (*p == '\0' || *p == '\n')
138: {
139: syntaxerr:
140: usrerr("missing colon");
141: continue;
142: }
143: *p++ = '\0';
144: if (parse(line, &al, 1) == NULL)
145: {
146: *--p = ':';
147: goto syntaxerr;
148: }
149: rhs = p;
150: contin = FALSE;
151: for (;;)
152: {
153: register char c;
154:
155: /* do parsing & compression of addresses */
156: c = *p;
157: while (c != '\0')
158: {
159: p2 = p;
160: while (*p != '\n' && *p != ',' && *p != '\0')
161: p++;
162: c = *p;
163: *p++ = '\0';
164: if (*p2 == '\0')
165: {
166: p[-1] = c;
167: continue;
168: }
169: parse(p2, &bl, -1);
170: contin = (c == ',');
171: p[-1] = c;
172: while (isspace(*p))
173: p++;
174: }
175:
176: /* see if there should be a continuation line */
177: if (!contin)
178: break;
179:
180: /* read continuation line */
181: p--;
182: if (fgets(p, sizeof line - (p - line), stdin) == NULL)
183: break;
184: LineNo++;
185:
186: if (!isspace(*p))
187: usrerr("continuation line missing");
188: }
189: if (al.q_mailer != MN_LOCAL)
190: {
191: usrerr("cannot alias non-local names");
192: continue;
193: }
194: naliases++;
195: key.dsize = strlen(al.q_user) + 1;
196: key.dptr = al.q_user;
197: content.dsize = strlen(rhs) + 1;
198: if (content.dsize > longest)
199: longest = content.dsize;
200: content.dptr = rhs;
201: bytes += key.dsize + content.dsize;
202: if (store(key, content), 0)
203: /* if (f = store(key, content)) */
204: usrerr("Dbm internal error return %d from store\n", f);
205: }
206: fprintf(stderr, "%d aliases, %d bytes, longest %d bytes, %d errors\n",
207: naliases, bytes, longest, Errors);
208:
209: exit(ExitStat);
210: }
211:
212: usrerr(fmt, a, b, c, d, e)
213: char *fmt;
214: {
215: Errors++;
216: fprintf(stderr, "line %d: ", LineNo);
217: fprintf(stderr, fmt, a, b, c, d, e);
218: fprintf(stderr, "\n");
219: return (-1);
220: }
221:
222: syserr(fmt, a, b, c, d, e)
223: char *fmt;
224: {
225: return (usrerr(fmt, a, b, c, d, e));
226: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.