]> diplodocus.org Git - nmh/blob - docs/historical/mh-jun-1982/progs/conflict.c
Fixed inc(1) and %(me) to not obey Local-Mailbox profile component.
[nmh] / docs / historical / mh-jun-1982 / progs / conflict.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 #include <stdio.h>
9 #include <ctype.h>
10 #include <pwd.h>
11 #include <grp.h>
12 #include <sys/types.h>
13 #include <sys/dir.h>
14 #include "../mh.h"
15 #include <mailsys.h>
16
17 char *AliasFile = MAILALIASES;
18 char *Password = "/etc/passwd";
19 char *MailDir = MAILDROP;
20
21 char *termptr;
22 char *malloc();
23
24 struct mailname {
25 struct mailname *m_next;
26 char *m_name;
27 int m_seen;
28 } users, bad;
29
30
31 char *parse(ptr, buf)
32 register char *ptr;
33 char *buf;
34 {
35 register char *cp;
36
37 cp = buf;
38 while(isspace(*ptr) || *ptr == ',' || *ptr == ':')
39 ptr++;
40 while(isalnum(*ptr) || *ptr == '/' || *ptr == '-' || *ptr == '.')
41 *cp++ = *ptr++;
42 if(cp == buf) {
43 switch(*ptr) {
44 case '<':
45 case '*':
46 case '=':
47 *cp++ = *ptr++;
48 }
49 }
50 *cp = 0;
51 if(cp == buf)
52 return 0;
53 termptr = ptr;
54 return buf;
55 }
56
57
58 char *mail = 0;
59 FILE *out;
60 int donecd = 0;
61
62 main(argc, argv)
63 int argc;
64 char *argv[];
65 {
66 register char *cp, **cpp;
67 register struct mailname *lp;
68 register struct group *gp;
69 struct direct dir;
70 char line[256], pbuf[64];
71 FILE *a;
72 struct group *getgrent();
73
74 invo_name = argv[0];
75 if(argc == 3 && strcmp(argv[1], "-mail") == 0)
76 mail = argv[2];
77 if(!mail)
78 out = stdout;
79 if((a = fopen(Password, "r")) == NULL) {
80 om();
81 fprintf(out, "Can't open password file ");
82 perror(Password);
83 done(1);
84 }
85 while(fgets(line, sizeof line, a)) {
86 if(line[0] == '\n' || line[0] == ';')
87 continue;
88 cp = parse(line, pbuf);
89 addu(cp, &users);
90 }
91 VOID fclose(a);
92 if((a = fopen(AliasFile, "r")) == NULL) {
93 om();
94 fprintf(out, "Can't open alias file: %s\n", AliasFile);
95 donecd = 1;
96 } else {
97 while(fgets(line, sizeof line, a)) {
98 if(line[0] == '\n' || line[0] == ';')
99 continue;
100 cp = parse(line, pbuf);
101 if(check(cp, 0)) {
102 addu(line, &bad);
103 donecd = 1;
104 }
105 }
106 VOID fclose(a);
107 if(donecd < 1) {
108 if(out)
109 fprintf(out, "No Alias Inconsistencies.\n");
110 } else {
111 om();
112 fprintf(out, "%s :: %s Collisions:\n",
113 Password, AliasFile);
114 fprintf(out, "Colliding alias lines:\n");
115 for(lp = bad.m_next; lp; lp = lp->m_next)
116 fprintf(out, "%s", lp->m_name);
117 donecd = 1;
118 }
119 }
120 while(gp = getgrent()) {
121 for(cpp = gp->gr_mem; *cpp; cpp++)
122 if(!check(*cpp, 1)) {
123 om();
124 fprintf(out, "Group: %s--User: %s not in /etc/passwd\n",
125 gp->gr_name, *cpp);
126 donecd = 2;
127 }
128 }
129 if(donecd < 2 && out)
130 fprintf(out, "No extraneous group entries.\n");
131 #ifdef RAND
132 for(lp = users.m_next; lp; lp = lp->m_next)
133 if(lp->m_seen == 0) {
134 om();
135 fprintf(out, "User: %s not in a group.\n", lp->m_name);
136 donecd = 3;
137 }
138 if(donecd < 3 && out)
139 fprintf(out, "No Users not in any group.\n");
140 #endif
141 if((a = fopen(MailDir, "r")) == NULL) {
142 om();
143 fprintf(out, "Can't open mail directory: %s\n", MailDir);
144 donecd = 4;
145 } else {
146 while(fread((char *)&dir, sizeof dir, 1, a)) {
147 if( dir.d_ino == 0
148 || dir.d_name[0] == '.'
149 )
150 continue;
151 if(!check(dir.d_name, 0)) {
152 om();
153 fprintf(out, "Mail drop: %s--Nonexistent user.\n",
154 dir.d_name);
155 donecd = 4;
156 }
157 }
158 VOID fclose(a);
159 }
160 if(donecd < 4 && out)
161 fprintf(out, "No Extra mail drops.\n");
162
163 done(donecd);
164 }
165
166
167 addu(name, list)
168 char *name;
169 struct mailname *list;
170 {
171 register struct mailname *mp;
172 char *getcpy();
173
174 for(mp = list; mp->m_next; mp = mp->m_next)
175 ;
176 mp->m_next = (struct mailname *) malloc(sizeof *mp->m_next);
177 mp = mp->m_next;
178 mp->m_next = 0;
179 mp->m_name = getcpy(name);
180 }
181
182 check(name, mark)
183 char *name;
184 int mark;
185 {
186 register struct mailname *mp;
187
188 for(mp = users.m_next; mp; mp = mp->m_next)
189 if(uleq(name, mp->m_name)) {
190 if(mark)
191 mp->m_seen = 1;
192 return 1;
193 }
194 return 0;
195 }
196
197
198 om()
199 {
200 int pipes[2], child;
201
202 if(out)
203 return;
204 if(mail) {
205 VOID pipe(pipes);
206 out = fdopen(pipes[1], "w");
207 if((child = fork()) == -1) {
208 fprintf(stderr, "Conflict: no forks!\n");
209 done(1);
210 }
211 if(child == 0) {
212 VOID close(pipes[1]);
213 VOID close(0);
214 VOID dup(pipes[0]);
215 VOID close(pipes[0]);
216 execl("/bin/mail", "mail", mail, 0);
217 execl("/usr/bin/mail", "mail", mail, 0);
218 perror("mail");
219 done(1);
220 }
221 fprintf(out, "Conflict: "