|
|
1.1 root 1: /* conflict.c - the new conflict */
2:
3: #include "../h/mh.h"
4: #include "../h/aliasbr.h"
5: #include <stdio.h>
6: #include "../zotnet/mts.h"
7: #include <grp.h>
8: #include <pwd.h>
9: #ifndef BSD42
10: #include <sys/types.h>
11: #ifndef SYS5
12: #include <ndir.h>
13: #else SYS5
14: #include <dir.h>
15: #endif SYS5
16: #else BSD42
17: #include <sys/param.h>
18: #include <sys/dir.h>
19: #endif BSD42
20:
21:
22: #define NDIRS 100
23: #define NGRPS 100
24:
25: /* */
26:
27: static struct swit switches[] = {
28: #define MAILSW 0
29: "mail name", 0,
30:
31: #define SERCHSW 1
32: "search directory", 0,
33:
34: #define HELPSW 2
35: "help", 4,
36:
37: NULL, NULL
38: };
39:
40: /* */
41:
42: static char *mail = NULL;
43:
44: static char *dirs[NDIRS];
45:
46: static FILE * out = NULL;
47:
48:
49: extern struct aka *akahead;
50: extern struct home *homehead;
51:
52:
53: struct group *getgrent (),*getgrgid();
54:
55: /* */
56:
57: /* ARGSUSED */
58:
59: main (argc, argv)
60: int argc;
61: char *argv[];
62: {
63: int akp = 0,
64: dp = 0;
65: char *cp,
66: **argp = argv + 1,
67: buf[80],
68: *akv[50];
69:
70: invo_name = r1bindex (argv[0], '/');
71: m_foil (NULLCP);
72: mts_init (invo_name);
73:
74: /* */
75:
76: while (cp = *argp++) {
77: if (*cp == '-')
78: switch (smatch (++cp, switches)) {
79: case AMBIGSW:
80: ambigsw (cp, switches);
81: done (1);
82: case UNKWNSW:
83: adios (NULLCP, "-%s unknown", cp);
84: case HELPSW:
85: (void) sprintf (buf, "%s [switches] [aliasfiles ...]",
86: invo_name);
87: help (buf, switches);
88: done (1);
89:
90: case MAILSW:
91: if (!(cp = *argp++) || *cp == '-')
92: adios (NULLCP, "missing argument to %s", argp[-2]);
93: if (mail)
94: adios (NULLCP, "mail to one address only");
95: else
96: mail = cp;
97: continue;
98:
99: case SERCHSW:
100: if (!(cp = *argp++) || *cp == '-')
101: adios (NULLCP, "missing argument to %s", argp[-2]);
102: if (dp >= NDIRS)
103: adios (NULLCP, "more than %d directories", NDIRS);
104: dirs[dp++] = cp;
105: continue;
106: }
107: akv[akp++] = cp;
108: }
109:
110: /* */
111:
112: if (akp == 0)
113: akv[akp++] = AliasFile;
114: if (!homehead)
115: init_pw ();
116: if (!mail)
117: out = stdout;
118: dirs[dp] = NULL;
119:
120: alias_files (akp, akv);
121: pwd_names ();
122: grp_names ();
123: grp_members ();
124: grp_ids ();
125: #ifdef UCI
126: ldr_names ();
127: ldr_ship ();
128: #endif UCI
129: maildrops ();
130:
131: done (0);
132: }
133:
134: /* */
135:
136: alias_files (akp, akv)
137: int akp;
138: register char **akv;
139: {
140: register int i;
141:
142: for (i = 0; i < akp; i++)
143: if ((i = alias (akv[i])) != AK_OK) {
144: setup ();
145: fprintf (out, "aliasing error in %s - %s\n", akv[i], akerror (i));
146: }
147: else
148: if (out && !mail)
149: fprintf (out, "alias file %s is ok\n", akv[i]);
150: }
151:
152: /* */
153:
154: pwd_names () {
155: int hit = 0;
156: register struct home *hm,
157: *lm;
158:
159: for (hm = homehead; hm; hm = hm -> h_next)
160: for (lm = hm -> h_next; lm; lm = lm -> h_next)
161: if (strcmp (hm -> h_name, lm -> h_name) == 0) {
162: setup ();
163: fprintf (out, "duplicate user %s(uid=%d)\n",
164: lm -> h_name, lm -> h_uid);
165: hit++;
166: }
167:
168: if (!hit && out && !mail)
169: fprintf (out, "no duplicate users\n");
170: }
171:
172:
173: grp_names () {
174: register int gp,
175: hit = 0;
176: char *grps[NGRPS];
177: register struct group *gr;
178:
179: grps[0] = NULL;
180: (void) setgrent ();
181: while (gr = getgrent ()) {
182: for (gp = 0; grps[gp]; gp++)
183: if (strcmp (grps[gp], gr -> gr_name) == 0) {
184: setup ();
185: fprintf (out, "duplicate group %s(gid=%d)\n",
186: gr -> gr_name, gr -> gr_gid);
187: hit++;
188: break;
189: }
190: if (grps[gp] == NULL)
191: if (gp < NGRPS) {
192: grps[gp++] = getcpy (gr -> gr_name);
193: grps[gp] = NULL;
194: }
195: else {
196: setup ();
197: fprintf (out, "more than %d groups (time to recompile)\n",
198: NGRPS - 1);
199: hit++;
200: }
201: }
202: (void) endgrent ();
203:
204: for (gp = 0; grps[gp]; gp++)
205: free (grps[gp]);
206:
207: if (!hit && out && !mail)
208: fprintf (out, "no duplicate groups\n");
209: }
210:
211: /* */
212:
213: grp_members () {
214: register int hit = 0;
215: register char **cp,
216: **dp;
217: register struct group *gr;
218: register struct home *hm;
219:
220: (void) setgrent ();
221: while (gr = getgrent ())
222: for (cp = gr -> gr_mem; *cp; cp++) {
223: for (hm = homehead; hm; hm = hm -> h_next)
224: if (!strcmp (*cp, hm -> h_name))
225: break;
226: if (hm == NULL) {
227: setup ();
228: fprintf (out, "group %s(gid=%d) has unknown member %s\n",
229: gr -> gr_name, gr -> gr_gid, *cp);
230: hit++;
231: }
232: #ifdef BSD42
233: else
234: hm -> h_ngrps++;
235: #endif BSD42
236:
237: for (dp = cp + 1; *dp; dp++)
238: if (strcmp (*cp, *dp) == 0) {
239: setup ();
240: fprintf (out, "group %s(gid=%d) has duplicate member %s\n",
241: gr -> gr_name, gr -> gr_gid, *cp);
242: hit++;
243: }
244: }
245: (void) endgrent ();
246:
247: #ifdef BSD42
248: for (hm = homehead; hm; hm = hm -> h_next)
249: if (hm -> h_ngrps > NGROUPS) {
250: setup ();
251: fprintf (out, "user %s is a member of %d groups (max %d)",
252: hm -> h_name, hm -> h_ngrps, NGROUPS);
253: hit++;
254: }
255: #endif BSD42
256:
257: if (!hit && out && !mail)
258: fprintf (out, "all group members accounted for\n");
259: }
260:
261:
262: grp_ids () { /* -DRAND not implemented at most places */
263: register int hit = 0;
264: register struct home *hm;
265:
266: for (hm = homehead; hm; hm = hm -> h_next)
267: if (getgrgid (hm -> h_gid) == NULL) {
268: setup ();
269: fprintf (out, "user %s(uid=%d) has unknown group-id %d\n",
270: hm -> h_name, hm -> h_uid, hm -> h_gid);
271: hit++;
272: }
273:
274: if (!hit && out && !mail)
275: fprintf (out, "all group-id users accounted for\n");
276: }
277:
278: /* */
279:
280: maildrops ()
281: {
282: register int i;
283:
284: if (mmdfldir && *mmdfldir)
285: mdrop (mmdfldir);
286: if (uucpldir && *uucpldir)
287: mdrop (uucpldir);
288: for (i = 0; dirs[i]; i++)
289: mdrop (dirs[i]);
290: }
291:
292:
293: mdrop(drop)
294: register char *drop;
295: {
296: register int hit = 0;
297: register struct direct *dp;
298: register DIR *dd = opendir (drop);
299:
300: if (!dd) {
301: setup ();
302: fprintf (out, "unable to open maildrop area %s\n", drop);
303: return;
304: }
305:
306: while (dp = readdir (dd))
307: if (dp -> d_name[0] != '.' && !check (dp ->d_name)) {
308: setup ();
309: fprintf (out,
310: "there is a maildrop for the unknown user %s in %s\n",
311: dp -> d_name, drop);
312: hit++;
313: }
314:
315: closedir (dd);
316: if (!hit && out && !mail)
317: fprintf (out, "all maildrops accounted for in %s\n", drop);
318: }
319:
320:
321: /* */
322:
323: int check (s)
324: register char *s;
325: {
326: register struct home *hm;
327:
328: for (hm = homehead; hm; hm = hm -> h_next)
329: if (!strcmp (s, hm -> h_name))
330: return 1;
331: return 0;
332: }
333:
334: /* */
335:
336: setup () {
337: int fd,
338: pd[2];
339:
340: if (out)
341: return;
342:
343: if (mail) {
344: if (pipe (pd) == NOTOK)
345: adios ("pipe", "unable to");
346:
347: switch (fork ()) {
348: case NOTOK:
349: adios ("fork", "unable to");
350:
351: case OK:
352: (void) close (pd[1]);
353: if (pd[0] != 0) {
354: (void) dup2 (pd[0], 0);
355: (void) close (pd[0]);
356: }
357: if ((fd = open ("/dev/null", 1)) != NOTOK)
358: if (fd != 1) {
359: (void) dup2 (fd, 1);
360: (void) close (fd);
361: }
362: execlp (mailproc, r1bindex (mailproc, '/'),
363: mail, "-subject", invo_name, NULLCP);
364: adios (mailproc, "unable to exec ");
365:
366: default:
367: (void) close (pd[0]);
368: out = fdopen (pd[1], "w");
369: fprintf (out, "%s: the following is suspicious\n\n",
370: invo_name);
371: }
372: }
373: }
374:
375: /* */
376:
377: #ifdef UCI
378: /* UCI specific stuff for conflict */
379:
380: /* taken from <grpldr.h> */
381:
382: #define GLDRS "/admin/etc/GroupLeaders"
383:
384: struct grpldr {
385: char *gl_name;
386: char **gl_ldr;
387: };
388:
389: int setglent (), endglent ();
390: struct grpldr *getglent (), *getglnam ();
391:
392:
393: /* taken from the getglent() routines */
394:
395: #include <ctype.h>
396:
397: #define MAXGLS 100
398:
399:
400: static FILE *glp = NULL;
401: static char line[BUFSIZ+1];
402: static struct grpldr grpldr;
403: static char *gl_ldr[MAXGLS + 1];
404:
405: /* */
406:
407: setglent() {
408: if (glp == NULL)
409: glp = fopen (GLDRS, "r");
410: else
411: rewind (glp);
412:
413: return (glp != NULL);
414: }
415:
416:
417: endglent() {
418: if (glp != NULL) {
419: (void) fclose (glp);
420: glp = NULL;
421: }
422:
423: return 1;
424: }
425:
426: /* */
427:
428: struct grpldr *getglent () {
429: register char *cp,
430: **q;
431:
432: if (glp == NULL && !setglent ())
433: return NULL;
434: if ((cp = fgets (line, BUFSIZ, glp)) == NULL)
435: return NULL;
436:
437: grpldr.gl_name = cp;
438: grpldr.gl_ldr = q = gl_ldr;
439:
440: while (*cp) {
441: while (*cp && !isspace (*cp))
442: cp++;
443: while (*cp && isspace (*cp))
444: *cp++ = NULL;
445: if (*cp == NULL)
446: break;
447: if (q < gl_ldr + MAXGLS)
448: *q++ = cp;
449: else
450: break;
451: }
452: *q = NULL;
453:
454: return (&grpldr);
455: }
456:
457: /* */
458:
459: struct grpldr *getglnam (name)
460: char *name;
461: {
462: register struct grpldr *gl = NULL;
463:
464: (void) setglent ();
465: while (gl = getglent ())
466: if (strcmp (name, gl -> gl_name) == 0)
467: break;
468: (void) endglent ();
469:
470: return gl;
471: }
472:
473: /* */
474:
475: ldr_names () {
476: register int gp,
477: hit = 0;
478: char *gldrs[NGRPS];
479: register struct grpldr *gl;
480:
481: gldrs[0] = NULL;
482: (void) setglent ();
483: while (gl = getglent ()) {
484: if (getgrnam (gl -> gl_name) == NULL) {
485: setup ();
486: fprintf (out, "unknown group %s in group leaders file\n",
487: gl -> gl_name);
488: hit++;
489: }
490: for (gp = 0; gldrs[gp]; gp++)
491: if (strcmp (gldrs[gp], gl -> gl_name) == 0) {
492: setup ();
493: fprintf (out, "duplicate group %s in group leaders file\n",
494: gl -> gl_name);
495: hit++;
496: break;
497: }
498: if (gldrs[gp] == NULL)
499: if (gp < NGRPS) {
500: gldrs[gp++] = getcpy (gl -> gl_name);
501: gldrs[gp] = NULL;
502: }
503: else {
504: setup ();
505: fprintf (out, "more than %d groups in group leaders file%s\n",
506: " (time to recompile)", NGRPS - 1);
507: hit++;
508: }
509: }
510: (void) endglent ();
511:
512: for (gp = 0; gldrs[gp]; gp++)
513: free (gldrs[gp]);
514:
515: if (!hit && out && !mail)
516: fprintf (out, "all groups in group leaders file accounted for\n");
517: }
518:
519:
520: ldr_ship () {
521: register int hit = 0;
522: register char **cp,
523: **dp;
524: register struct grpldr *gl;
525:
526: (void) setglent ();
527: while (gl = getglent ())
528: for (cp = gl -> gl_ldr; *cp; cp++) {
529: if (!check (*cp)) {
530: setup ();
531: fprintf (out, "group %s has unknown leader %s\n",
532: gl -> gl_name, *cp);
533: hit++;
534: }
535:
536: for (dp = cp + 1; *dp; dp++)
537: if (strcmp (*cp, *dp) == 0) {
538: setup ();
539: fprintf (out, "group %s had duplicate leader %s\n",
540: gl -> gl_name, *cp);
541: hit++;
542: }
543: }
544: (void) endglent ();
545:
546: if (!hit && out && !mail)
547: fprintf (out, "all group leaders accounted for\n");
548: }
549: #endif UCI
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.