Added all of the MH sources, including RCS files, in
[mmh] / docs / historical / mh-6.8.5 / uip / RCS / conflict.c,v
1 head    2.9;
2 access;
3 symbols;
4 locks; strict;
5 comment @ * @;
6
7
8 2.9
9 date    92.12.15.00.07.52;      author jromine; state Exp;
10 branches;
11 next    2.8;
12
13 2.8
14 date    92.11.13.16.56.02;      author jromine; state Exp;
15 branches;
16 next    2.7;
17
18 2.7
19 date    92.11.04.00.40.56;      author jromine; state Exp;
20 branches;
21 next    2.6;
22
23 2.6
24 date    92.10.30.05.53.28;      author jromine; state Exp;
25 branches;
26 next    2.5;
27
28 2.5
29 date    92.05.19.21.06.30;      author jromine; state Exp;
30 branches;
31 next    2.4;
32
33 2.4
34 date    92.02.03.16.35.26;      author jromine; state Exp;
35 branches;
36 next    2.3;
37
38 2.3
39 date    92.01.31.22.07.50;      author jromine; state Exp;
40 branches;
41 next    2.2;
42
43 2.2
44 date    90.04.05.14.57.02;      author sources; state Exp;
45 branches;
46 next    2.1;
47
48 2.1
49 date    90.01.30.11.11.41;      author sources; state Exp;
50 branches;
51 next    2.0;
52
53 2.0
54 date    89.11.17.15.57.52;      author sources; state Exp;
55 branches;
56 next    1.1;
57
58 1.1
59 date    89.06.26.14.36.38;      author sources; state Exp;
60 branches;
61 next    ;
62
63
64 desc
65 @@
66
67
68 2.9
69 log
70 @convex fixup
71 @
72 text
73 @/* conflict.c - the new conflict */
74 #ifndef lint
75 static char ident[] = "@@(#)$Id: conflict.c,v 2.8 1992/11/13 16:56:02 jromine Exp jromine $";
76 #endif  /* lint */
77
78 #include "../h/mh.h"
79 #include "../h/aliasbr.h"
80 #include "../h/local.h"
81 #include <stdio.h>
82 #include "../zotnet/mts.h"
83 #include <grp.h>
84 #include <pwd.h>
85 #ifdef LOCALE
86 #include        <locale.h>
87 #endif
88
89 #define NDIRS   100
90 #define NGRPS   100
91
92 /* \f */
93
94 static struct swit switches[] = {
95 #define MAILSW  0
96     "mail name", 0,
97
98 #define SERCHSW 1
99     "search directory", 0,
100
101 #define HELPSW  2
102     "help", 4,
103
104     NULL, 0
105 };
106
107 /* \f */
108
109 static  char   *mail = NULL;
110
111 static  char   *dirs[NDIRS];
112
113 static  FILE * out = NULL;
114
115
116 extern struct aka  *akahead;
117 extern struct home *homehead;
118
119
120 #if !defined(__STDC__) && !defined(__stdc__)    /* __stdc__ for convex */
121 struct  group *getgrent (), *getgrgid();
122 #endif /* !__STDC__ */
123
124 /* \f */
125
126 /* ARGSUSED */
127
128 main (argc, argv)
129 int     argc;
130 char   *argv[];
131 {
132     int     akp = 0,
133             dp = 0;
134     char   *cp,
135           **argp = argv + 1,
136             buf[80],
137            *akv[50];
138
139 #ifdef LOCALE
140         setlocale(LC_ALL, "");
141 #endif
142     invo_name = r1bindex (argv[0], '/');
143     m_foil (NULLCP);
144     mts_init (invo_name);
145
146 /* \f */
147
148     while (cp = *argp++) {
149         if (*cp == '-')
150             switch (smatch (++cp, switches)) {
151                 case AMBIGSW: 
152                     ambigsw (cp, switches);
153                     done (1);
154                 case UNKWNSW: 
155                     adios (NULLCP, "-%s unknown", cp);
156                 case HELPSW: 
157                     (void) sprintf (buf, "%s [switches] [aliasfiles ...]",
158                             invo_name);
159                     help (buf, switches);
160                     done (1);
161
162                 case MAILSW: 
163                     if (!(cp = *argp++) || *cp == '-')
164                         adios (NULLCP, "missing argument to %s", argp[-2]);
165                     if (mail)
166                         adios (NULLCP, "mail to one address only");
167                     else
168                         mail = cp;
169                     continue;
170
171                 case SERCHSW: 
172                     if (!(cp = *argp++) || *cp == '-')
173                         adios (NULLCP, "missing argument to %s", argp[-2]);
174                     if (dp >= NDIRS)
175                         adios (NULLCP, "more than %d directories", NDIRS);
176                     dirs[dp++] = cp;
177                     continue;
178             }
179         akv[akp++] = cp;
180     }
181
182 /* \f */
183
184     if (akp == 0)
185         akv[akp++] = AliasFile;
186     if (!homehead)
187         init_pw ();
188     if (!mail)
189         out = stdout;
190     dirs[dp] = NULL;
191
192     alias_files (akp, akv);
193     pwd_names ();
194     grp_names ();
195     grp_members ();
196     grp_ids ();
197 #ifdef  UCI
198     ldr_names ();
199     ldr_ship ();
200 #endif  /* UCI */
201     maildrops ();
202
203     done (0);
204 }
205
206 /* \f */
207
208 alias_files (akp, akv)
209 int     akp;
210 register char   **akv;
211 {
212     register int    i, err;
213
214     for (i = 0; i < akp; i++)
215         if ((err = alias (akv[i])) != AK_OK) {
216             setup ();
217             fprintf (out, "aliasing error in %s - %s\n", akv[i], akerror (err));
218         }
219         else
220             if (out && !mail)
221                 fprintf (out, "alias file %s is ok\n", akv[i]);
222 }
223
224 /* \f */
225
226 pwd_names () {
227     int     hit = 0;
228     register struct home   *hm,
229                            *lm;
230
231     for (hm = homehead; hm; hm = hm -> h_next)
232         for (lm = hm -> h_next; lm; lm = lm -> h_next)
233             if (strcmp (hm -> h_name, lm -> h_name) == 0) {
234                 setup ();
235                 fprintf (out, "duplicate user %s(uid=%d)\n",
236                         lm -> h_name, lm -> h_uid);
237                 hit++;
238             }
239
240     if (!hit && out && !mail)
241         fprintf (out, "no duplicate users\n");
242 }
243
244
245 grp_names () {
246     register int    gp,
247                     hit = 0;
248     char   *grps[NGRPS];
249     register struct group  *gr;
250
251     grps[0] = NULL;
252     (void) setgrent ();
253     while (gr = getgrent ()) {
254         for (gp = 0; grps[gp]; gp++)
255             if (strcmp (grps[gp], gr -> gr_name) == 0) {
256                 setup ();
257                 fprintf (out, "duplicate group %s(gid=%d)\n",
258                         gr -> gr_name, gr -> gr_gid);
259                 hit++;
260                 break;
261             }
262         if (grps[gp] == NULL)
263             if (gp < NGRPS) {
264                 grps[gp++] = getcpy (gr -> gr_name);
265                 grps[gp] = NULL;
266             }
267             else {
268                 setup ();
269                 fprintf (out, "more than %d groups (time to recompile)\n",
270                         NGRPS - 1);
271                 hit++;
272             }
273     }
274     (void) endgrent ();
275
276     for (gp = 0; grps[gp]; gp++)
277         free (grps[gp]);
278
279     if (!hit && out && !mail)
280         fprintf (out, "no duplicate groups\n");
281 }
282
283 /* \f */
284
285 grp_members () {
286     register int    hit = 0;
287     register char **cp,
288                   **dp;
289     register struct group  *gr;
290     register struct home   *hm;
291
292     (void) setgrent ();
293     while (gr = getgrent ())
294         for (cp = gr -> gr_mem; *cp; cp++) {
295             for (hm = homehead; hm; hm = hm -> h_next)
296                 if (!strcmp (*cp, hm -> h_name))
297                     break;
298             if (hm == NULL) {
299                 setup ();
300                 fprintf (out, "group %s(gid=%d) has unknown member %s\n",
301                         gr -> gr_name, gr -> gr_gid, *cp);
302                 hit++;
303             }
304 #ifdef  BSD42
305             else
306                 hm -> h_ngrps++;
307 #endif  /* BSD42 */
308
309             for (dp = cp + 1; *dp; dp++)
310                 if (strcmp (*cp, *dp) == 0) {
311                     setup ();
312                     fprintf (out, "group %s(gid=%d) has duplicate member %s\n",
313                             gr -> gr_name, gr -> gr_gid, *cp);
314                     hit++;
315                 }
316         }
317     (void) endgrent ();
318
319 #ifdef  BSD42
320     for (hm = homehead; hm; hm = hm -> h_next)
321         if (hm -> h_ngrps > NGROUPS) {
322             setup ();
323             fprintf (out, "user %s is a member of %d groups (max %d)",
324                     hm -> h_name, hm -> h_ngrps, NGROUPS);
325             hit++;
326         }
327 #endif  /* BSD42 */
328
329     if (!hit && out && !mail)
330         fprintf (out, "all group members accounted for\n");
331 }
332
333
334 grp_ids () {            /* -DRAND not implemented at most places */
335     register int    hit = 0;
336     register struct home   *hm;
337
338     for (hm = homehead; hm; hm = hm -> h_next)
339         if (getgrgid (hm -> h_gid) == NULL) {
340             setup ();
341             fprintf (out, "user %s(uid=%d) has unknown group-id %d\n",
342                     hm -> h_name, hm -> h_uid, hm -> h_gid);
343             hit++;
344         }
345
346     if (!hit && out && !mail)
347         fprintf (out, "all group-id users accounted for\n");
348 }
349
350 /* \f */
351
352 maildrops () 
353 {
354     register int    i;
355
356     if (mmdfldir && *mmdfldir)
357         mdrop (mmdfldir);
358     if (uucpldir && *uucpldir)
359         mdrop (uucpldir);
360     for (i = 0; dirs[i]; i++)
361         mdrop (dirs[i]);
362 }
363
364
365 mdrop(drop)
366 register char *drop;
367 {
368     register int    hit = 0;
369 #ifdef SYS5DIR
370     register struct dirent *dp;
371 #else   /*  SYS5DIR */
372     register struct direct *dp;
373 #endif  /* SYS5DIR */
374     register DIR *dd = opendir (drop);
375
376     if (!dd) {
377         setup ();
378         fprintf (out, "unable to open maildrop area %s\n", drop);
379         return;
380     }
381
382     while (dp = readdir (dd))
383         if (dp -> d_name[0] != '.' && !check (dp ->d_name)) {
384             setup ();
385             fprintf (out,
386                     "there is a maildrop for the unknown user %s in %s\n",
387                     dp -> d_name, drop);
388             hit++;
389         }
390
391     closedir (dd);
392     if (!hit && out && !mail)
393         fprintf (out, "all maildrops accounted for in %s\n", drop);
394 }
395
396
397 /* \f */
398
399 int     check (s)
400 register char   *s;
401 {
402     register struct home *hm;
403
404     for (hm = homehead; hm; hm = hm -> h_next)
405         if (!strcmp (s, hm -> h_name))
406             return 1;
407     return 0;
408 }
409
410 /* \f */
411
412 setup () {
413     int     fd,
414             pd[2];
415
416     if (out)
417         return;
418
419     if (mail) {
420         if (pipe (pd) == NOTOK)
421             adios ("pipe", "unable to");
422
423         switch (fork ()) {
424             case NOTOK: 
425                 adios ("fork", "unable to");
426
427             case OK: 
428                 (void) close (pd[1]);
429                 if (pd[0] != 0) {
430                     (void) dup2 (pd[0], 0);
431                     (void) close (pd[0]);
432                 }
433                 if ((fd = open ("/dev/null", 1)) != NOTOK)
434                     if (fd != 1) {
435                         (void) dup2 (fd, 1);
436                         (void) close (fd);
437                     }
438                 execlp (mailproc, r1bindex (mailproc, '/'),
439                         mail, "-subject", invo_name, NULLCP);
440                 adios (mailproc, "unable to exec ");
441
442             default: 
443                 (void) close (pd[0]);
444                 out = fdopen (pd[1], "w");
445                 fprintf (out, "%s: the following is suspicious\n\n",
446                         invo_name);
447         }
448     }
449 }
450
451 /* \f */
452
453 #ifdef  UCI
454 /* UCI specific stuff for conflict */
455
456 /* taken from <grpldr.h> */
457
458 #define GLDRS   "/admin/etc/GroupLeaders"
459
460 struct grpldr {
461     char *gl_name;
462     char **gl_ldr;
463 };
464
465 int     setglent (), endglent ();
466 struct grpldr *getglent (), *getglnam ();
467
468
469 /* taken from the getglent() routines */
470
471 #include <ctype.h>
472
473 #define MAXGLS  100
474
475
476 static FILE *glp = NULL;
477 static char line[BUFSIZ+1];
478 static struct grpldr grpldr;
479 static char *gl_ldr[MAXGLS + 1];
480
481 /* \f */
482
483 setglent() {
484     if (glp == NULL)
485         glp = fopen (GLDRS, "r");
486     else
487         rewind (glp);
488
489     return (glp != NULL);
490 }
491
492
493 endglent() {
494     if (glp != NULL) {
495         (void) fclose (glp);
496         glp = NULL;
497     }
498
499     return 1;
500 }
501
502 /* \f */
503
504 struct grpldr  *getglent () {
505     register char  *cp,
506                   **q;
507
508     if (glp == NULL && !setglent ())
509         return NULL;
510     if ((cp = fgets (line, BUFSIZ, glp)) == NULL)
511         return NULL;
512
513     grpldr.gl_name = cp;
514     grpldr.gl_ldr = q = gl_ldr;
515
516     while (*cp) {
517         while (*cp && !isspace (*cp))
518             cp++;
519         while (*cp && isspace (*cp))
520             *cp++ = '\0';
521         if (*cp == '\0')
522             break;
523         if (q < gl_ldr + MAXGLS)
524             *q++ = cp;
525         else
526             break;
527     }
528     *q = NULL;
529
530     return (&grpldr);
531 }
532
533 /* \f */
534
535 struct grpldr  *getglnam (name)
536 char   *name;
537 {
538     register struct grpldr  *gl = NULL;
539
540     (void) setglent ();
541     while (gl = getglent ())
542         if (strcmp (name, gl -> gl_name) == 0)
543             break;
544     (void) endglent ();
545
546     return gl;
547 }
548
549 /* \f */
550
551 ldr_names () {
552     register int     gp,
553                      hit = 0;
554     char   *gldrs[NGRPS];
555     register struct grpldr  *gl;
556
557     gldrs[0] = NULL;
558     (void) setglent ();
559     while (gl = getglent ()) {
560         if (getgrnam (gl -> gl_name) == NULL) {
561             setup ();
562             fprintf (out, "unknown group %s in group leaders file\n",
563                     gl -> gl_name);
564             hit++;
565         }
566         for (gp = 0; gldrs[gp]; gp++)
567             if (strcmp (gldrs[gp], gl -> gl_name) == 0) {
568                 setup ();
569                 fprintf (out, "duplicate group %s in group leaders file\n",
570                         gl -> gl_name);
571                 hit++;
572                 break;
573             }
574         if (gldrs[gp] == NULL)
575             if (gp < NGRPS) {
576                 gldrs[gp++] = getcpy (gl -> gl_name);
577                 gldrs[gp] = NULL;
578             }
579             else {
580                 setup ();
581                 fprintf (out, "more than %d groups in group leaders file%s\n",
582                         " (time to recompile)", NGRPS - 1);
583                 hit++;
584             }
585     }
586     (void) endglent ();
587
588     for (gp = 0; gldrs[gp]; gp++)
589         free (gldrs[gp]);
590
591     if (!hit && out && !mail)
592         fprintf (out, "all groups in group leaders file accounted for\n");
593 }
594
595
596 ldr_ship () {
597     register int     hit = 0;
598     register char  **cp,
599                    **dp;
600     register struct grpldr  *gl;
601
602     (void) setglent ();
603     while (gl = getglent ())
604         for (cp = gl -> gl_ldr; *cp; cp++) {
605             if (!check (*cp)) {
606                 setup ();
607                 fprintf (out, "group %s has unknown leader %s\n",
608                         gl -> gl_name, *cp);
609                 hit++;
610             }
611
612             for (dp = cp + 1; *dp; dp++)
613                 if (strcmp (*cp, *dp) == 0) {
614                     setup ();
615                     fprintf (out, "group %s had duplicate leader %s\n",
616                             gl -> gl_name, *cp);
617                     hit++;
618                 }
619         }
620     (void) endglent ();
621
622     if (!hit && out && !mail)
623         fprintf (out, "all group leaders accounted for\n");
624 }
625 #endif  /* UCI */
626 @
627
628
629 2.8
630 log
631 @don't include stdlib, it's included by strings.h (via mh.h)
632 @
633 text
634 @d3 2
635 a4 2
636 static char ident[] = "@@(#)$Id: conflict.c,v 2.7 1992/11/04 00:40:56 jromine Exp jromine $";
637 #endif  lint
638 d48 2
639 a49 2
640 #ifndef __STDC__
641 struct  group *getgrent (),*getgrgid();
642 d128 1
643 a128 1
644 #endif  UCI
645 d235 1
646 a235 1
647 #endif  BSD42
648 d255 1
649 a255 1
650 #endif  BSD42
651 d299 1
652 a299 1
653 #else  SYS5DIR
654 d301 1
655 a301 1
656 #endif SYS5DIR
657 d553 1
658 a553 1
659 #endif  UCI
660 @
661
662
663 2.7
664 log
665 @LOCALE
666 _putenv
667 @
668 text
669 @d3 1
670 a3 1
671 static char ident[] = "@@(#)$Id: conflict.c,v 2.6 1992/10/30 05:53:28 jromine Exp jromine $";
672 a15 4
673 #ifdef _AIX     /* Need declaration of free() */
674 #include <stdlib.h>
675 #endif
676
677 @
678
679
680 2.6
681 log
682 @#ifdef around putenv decl in <stdlib.h>
683 @
684 text
685 @d3 1
686 a3 1
687 static char ident[] = "@@(#)$Id: conflict.c,v 2.5 1992/05/19 21:06:30 jromine Exp jromine $";
688 d13 3
689 a16 1
690 #define putenv  _putenv
691 a17 1
692 #undef  putenv
693 d71 3
694 @
695
696
697 2.5
698 log
699 @AIX
700 @
701 text
702 @d3 1
703 a3 1
704 static char ident[] = "@@(#)$Id: conflict.c,v 2.4 1992/02/03 16:35:26 jromine Exp jromine $";
705 d14 1
706 d16 1
707 @
708
709
710 2.4
711 log
712 @fix
713 @
714 text
715 @d3 1
716 a3 1
717 static char ident[] = "@@(#)$Id: conflict.c,v 2.3 1992/01/31 22:07:50 jromine Exp jromine $";
718 d33 1
719 a33 1
720     NULL, NULL
721 d446 2
722 a447 2
723             *cp++ = NULL;
724         if (*cp == NULL)
725 @
726
727
728 2.3
729 log
730 @kerberos
731 @
732 text
733 @d3 1
734 a3 1
735 static char ident[] = "@@(#)$Id: conflict.c,v 2.2 1990/04/05 14:57:02 sources Exp jromine $";
736 d49 1
737 d51 1
738 @
739
740
741 2.2
742 log
743 @add ID
744 @
745 text
746 @d3 1
747 a3 1
748 static char ident[] = "@@(#)$Id:$";
749 d13 3
750 @
751
752
753 2.1
754 log
755 @bug fix
756 @
757 text
758 @d2 3
759 @
760
761
762 2.0
763 log
764 @changes for SUN40 shared libraries and NNTP under bbc
765 @
766 text
767 @d130 1
768 a130 1
769     register int    i;
770 d133 1
771 a133 1
772         if ((i = alias (akv[i])) != AK_OK) {
773 d135 1
774 a135 1
775             fprintf (out, "aliasing error in %s - %s\n", akv[i], akerror (i));
776 @
777
778
779 1.1
780 log
781 @Initial revision
782 @
783 text
784 @d287 3
785 d291 1
786 @