]> diplodocus.org Git - nmh/blob - docs/historical/mh-jun-1982/support/aliascheck.c
Remove final traces of TMA support
[nmh] / docs / historical / mh-jun-1982 / support / aliascheck.c
1 #ifdef COMMENT
2 Proprietary Rand Corporation, 1981.
3 Further distribution of this software
4 subject to the terms of the Rand
5 license agreement.
6 #endif
7
8 /*
9 * aliascheck(name) will return an indication of whether name is
10 * a valid alias from AliasFile. The return values are:
11 *
12 * 1 -> yes
13 * 0 -> no
14 * -1 -> an error in the alias file
15 */
16
17 #include <stdio.h>
18 #include <ctype.h>
19 char *AliasFile = "/etc/MailAliases";
20
21 char *
22 parse(ptr, buf)
23 register char *ptr;
24 char *buf;
25 {
26 register char *cp = buf;
27
28 while(isalnum(*ptr) || *ptr == '/' || *ptr == '-' ||
29 *ptr == '.' || *ptr == '*')
30 *cp++ = *ptr++;
31 *cp = 0;
32 if(cp == buf)
33 return 0;
34 return buf;
35 }
36
37
38 aliascheck(name)
39 char *name;
40 {
41 register char *pp;
42 char line[256], pbuf[64];
43 register FILE *a;
44
45 if((a = fopen(AliasFile, "r")) == NULL)
46 return -1;
47 while(fgets(line, sizeof line, a)) {
48 if(line[0] == ';' || line[0] == '\n') /* Comment Line */
49 continue;
50 if((pp = parse(line, pbuf)) == NULL) {
51 fclose(a);
52 return -1;
53 }
54 if(aleq(name, pp)) {
55 fclose(a);
56 return 1;
57 }
58 }
59 fclose(a);
60 return 0;
61 }
62
63
64 aleq(string, aliasent)
65 register char *string, *aliasent;
66 {
67 register int c;
68
69 while(c = *string++)
70 if(*aliasent == '*')
71 return 1;
72 else if((c|040) != (*aliasent|040))
73 return(0);
74 else
75 aliasent++;
76 return *aliasent == 0 || *aliasent == '*';
77 }