]>
diplodocus.org Git - nmh/blob - uip/conflict.c
3 * conflict.c -- check for conflicts in mail system
7 * This code is Copyright (c) 2002, by the authors of nmh. See the
8 * COPYRIGHT file in the root directory of the nmh distribution for
9 * complete copyright information.
14 #include <h/aliasbr.h>
21 * maximum number of directories that can
22 * be specified using -search switch.
27 * Add space for group names, 100 at a time
31 static struct swit switches
[] = {
35 { "search directory", 0 },
43 static char *mail
= NULL
;
44 static char *dirs
[NDIRS
];
45 static FILE *out
= NULL
;
47 extern struct aka
*akahead
;
48 extern struct home
*homehead
;
53 void alias_files (int, char **);
54 void pwd_names (void);
55 void grp_names (void);
56 void grp_members (void);
58 void maildrops (void);
65 main (int argc
, char **argv
)
68 char *cp
, **argp
, **arguments
;
69 char buf
[BUFSIZ
], *akv
[50];
72 setlocale(LC_ALL
, "");
74 invo_name
= r1bindex (argv
[0], '/');
76 /* foil search of user profile/context */
77 if (context_foil (NULL
) == -1)
81 arguments
= getarguments (invo_name
, argc
, argv
, 0);
84 while ((cp
= *argp
++)) {
86 switch (smatch (++cp
, switches
)) {
88 ambigsw (cp
, switches
);
91 adios (NULL
, "-%s unknown", cp
);
94 snprintf (buf
, sizeof(buf
), "%s [switches] [aliasfiles ...]",
96 print_help (buf
, switches
, 0);
99 print_version(invo_name
);
103 if (!(cp
= *argp
++) || *cp
== '-')
104 adios (NULL
, "missing argument to %s", argp
[-2]);
106 adios (NULL
, "mail to one address only");
112 if (!(cp
= *argp
++) || *cp
== '-')
113 adios (NULL
, "missing argument to %s", argp
[-2]);
115 adios (NULL
, "more than %d directories", NDIRS
);
124 akv
[akp
++] = AliasFile
;
131 alias_files (akp
, akv
);
148 alias_files (int akp
, char **akv
)
152 for (i
= 0; i
< akp
; i
++)
153 if ((err
= alias (akv
[i
])) != AK_OK
) {
155 fprintf (out
, "aliasing error in %s - %s\n", akv
[i
], akerror (err
));
159 fprintf (out
, "alias file %s is ok\n", akv
[i
]);
167 register struct home
*hm
, *lm
;
169 for (hm
= homehead
; hm
; hm
= hm
->h_next
)
170 for (lm
= hm
->h_next
; lm
; lm
= lm
->h_next
)
171 if (strcmp (hm
->h_name
, lm
->h_name
) == 0) {
173 fprintf (out
, "duplicate user %s(uid=%d)\n",
174 lm
->h_name
, (int) lm
->h_uid
);
178 if (!hit
&& out
&& !mail
)
179 fprintf (out
, "no duplicate users\n");
186 int numgroups
, maxgroups
;
191 /* allocate space NGRPS at a time */
194 grps
= (char **) mh_xmalloc((size_t) (maxgroups
* sizeof(*grps
)));
197 while ((gr
= getgrent ())) {
198 for (i
= 0; i
< numgroups
; i
++)
199 if (!strcmp (grps
[i
], gr
->gr_name
)) {
201 fprintf (out
, "duplicate group %s(gid=%d)\n",
202 gr
->gr_name
, (int) gr
->gr_gid
);
206 if (i
>= numgroups
) {
207 if (numgroups
>= maxgroups
) {
209 grps
= (char **) mh_xrealloc(grps
,
210 (size_t) (maxgroups
* sizeof(*grps
)));
212 grps
[numgroups
++] = getcpy (gr
->gr_name
);
217 for (i
= 0; i
< numgroups
; i
++)
221 if (!hit
&& out
&& !mail
)
222 fprintf (out
, "no duplicate groups\n");
229 register int hit
= 0;
230 register char **cp
, **dp
;
231 register struct group
*gr
;
232 register struct home
*hm
;
235 while ((gr
= getgrent ())) {
236 for (cp
= gr
->gr_mem
; *cp
; cp
++) {
237 for (hm
= homehead
; hm
; hm
= hm
->h_next
)
238 if (!strcmp (*cp
, hm
->h_name
))
242 fprintf (out
, "group %s(gid=%d) has unknown member %s\n",
243 gr
->gr_name
, (int) gr
->gr_gid
, *cp
);
249 for (dp
= cp
+ 1; *dp
; dp
++)
250 if (strcmp (*cp
, *dp
) == 0) {
252 fprintf (out
, "group %s(gid=%d) has duplicate member %s\n",
253 gr
->gr_name
, (int) gr
->gr_gid
, *cp
);
260 for (hm
= homehead
; hm
; hm
= hm
->h_next
)
261 if (hm
->h_ngrps
> NGROUPS_MAX
) {
263 fprintf (out
, "user %s is a member of %d groups (max %d)\n",
264 hm
->h_name
, hm
->h_ngrps
, NGROUPS_MAX
);
268 if (!hit
&& out
&& !mail
)
269 fprintf (out
, "all group members accounted for\n");
275 { /* -DRAND not implemented at most places */
276 register int hit
= 0;
277 register struct home
*hm
;
279 for (hm
= homehead
; hm
; hm
= hm
->h_next
)
280 if (getgrgid (hm
->h_gid
) == NULL
) {
282 fprintf (out
, "user %s(uid=%d) has unknown group-id %d\n",
283 hm
->h_name
, (int) hm
->h_uid
, (int) hm
->h_gid
);
287 if (!hit
&& out
&& !mail
)
288 fprintf (out
, "all group-id users accounted for\n");
297 if (mmdfldir
&& *mmdfldir
)
299 if (uucpldir
&& *uucpldir
)
301 for (i
= 0; dirs
[i
]; i
++)
309 register int hit
= 0;
310 register struct dirent
*dp
;
311 register DIR *dd
= opendir (drop
);
315 fprintf (out
, "unable to open maildrop area %s\n", drop
);
319 while ((dp
= readdir (dd
)))
320 if (dp
->d_name
[0] != '.' && !check (dp
->d_name
)) {
323 "there is a maildrop for the unknown user %s in %s\n",
329 if (!hit
&& out
&& !mail
)
330 fprintf (out
, "all maildrops accounted for in %s\n", drop
);
337 register struct home
*hm
;
339 for (hm
= homehead
; hm
; hm
= hm
->h_next
)
340 if (!strcmp (s
, hm
->h_name
))
354 if (pipe (pd
) == NOTOK
)
355 adios ("pipe", "unable to");
359 adios ("fork", "unable to");
367 if ((fd
= open ("/dev/null", O_WRONLY
)) != NOTOK
)
372 execlp (mailproc
, r1bindex (mailproc
, '/'),
373 mail
, "-subject", invo_name
, NULL
);
374 adios (mailproc
, "unable to exec ");
378 out
= fdopen (pd
[1], "w");
379 fprintf (out
, "%s: the following is suspicious\n\n",
387 * UCI specific stuff for conflict
390 /* taken from <grpldr.h> */
392 #define GLDRS "/admin/etc/GroupLeaders"
399 int setglent (), endglent ();
400 struct grpldr
*getglent (), *getglnam ();
403 /* taken from the getglent() routines */
407 static FILE *glp
= NULL
;
408 static char line
[BUFSIZ
+1];
409 static struct grpldr grpldr
;
410 static char *gl_ldr
[MAXGLS
+ 1];
415 glp
= fopen (GLDRS
, "r");
419 return (glp
!= NULL
);
432 struct grpldr
*getglent () {
436 if (glp
== NULL
&& !setglent ())
438 if ((cp
= fgets (line
, BUFSIZ
, glp
)) == NULL
)
442 grpldr
.gl_ldr
= q
= gl_ldr
;
445 while (*cp
&& !isspace (*cp
))
447 while (*cp
&& isspace (*cp
))
451 if (q
< gl_ldr
+ MAXGLS
)
461 struct grpldr
*getglnam (name
)
464 register struct grpldr
*gl
= NULL
;
467 while (gl
= getglent ())
468 if (strcmp (name
, gl
->gl_name
) == 0)
479 register struct grpldr
*gl
;
483 while (gl
= getglent ()) {
484 if (getgrnam (gl
->gl_name
) == NULL
) {
486 fprintf (out
, "unknown group %s in group leaders file\n",
490 for (gp
= 0; gldrs
[gp
]; gp
++)
491 if (strcmp (gldrs
[gp
], gl
->gl_name
) == 0) {
493 fprintf (out
, "duplicate group %s in group leaders file\n",
498 if (gldrs
[gp
] == NULL
)
500 gldrs
[gp
++] = getcpy (gl
->gl_name
);
505 fprintf (out
, "more than %d groups in group leaders file%s\n",
506 " (time to recompile)", NGRPS
- 1);
512 for (gp
= 0; gldrs
[gp
]; gp
++)
515 if (!hit
&& out
&& !mail
)
516 fprintf (out
, "all groups in group leaders file accounted for\n");
521 register int hit
= 0;
524 register struct grpldr
*gl
;
527 while (gl
= getglent ())
528 for (cp
= gl
->gl_ldr
; *cp
; cp
++) {
531 fprintf (out
, "group %s has unknown leader %s\n",
536 for (dp
= cp
+ 1; *dp
; dp
++)
537 if (strcmp (*cp
, *dp
) == 0) {
539 fprintf (out
, "group %s had duplicate leader %s\n",
546 if (!hit
&& out
&& !mail
)
547 fprintf (out
, "all group leaders accounted for\n");