2 ** conflict.c -- check for conflicts in mail system
4 ** This code is Copyright (c) 2002, by the authors of nmh. See the
5 ** COPYRIGHT file in the root directory of the nmh distribution for
6 ** complete copyright information.
11 #include <h/aliasbr.h>
18 ** maximum number of directories that can
19 ** be specified using -search switch.
24 ** Add space for group names, 100 at a time
28 static struct swit switches[] = {
32 { "search directory", 0 },
40 static char *mail = NULL;
41 static char *dirs[NDIRS];
42 static FILE *out = NULL;
44 extern struct aka *akahead;
45 extern struct home *homehead;
50 void alias_files (int, char **);
51 void pwd_names (void);
52 void grp_names (void);
53 void grp_members (void);
55 void maildrops (void);
62 main (int argc, char **argv)
65 char *cp, **argp, **arguments;
66 char buf[BUFSIZ], *akv[50];
69 setlocale(LC_ALL, "");
71 invo_name = r1bindex (argv[0], '/');
73 /* foil search of user profile/context */
74 if (context_foil (NULL) == -1)
78 arguments = getarguments (invo_name, argc, argv, 0);
81 while ((cp = *argp++)) {
83 switch (smatch (++cp, switches)) {
85 ambigsw (cp, switches);
88 adios (NULL, "-%s unknown", cp);
91 snprintf (buf, sizeof(buf), "%s [switches] [aliasfiles ...]",
93 print_help (buf, switches, 0);
96 print_version(invo_name);
100 if (!(cp = *argp++) || *cp == '-')
101 adios (NULL, "missing argument to %s", argp[-2]);
103 adios (NULL, "mail to one address only");
109 if (!(cp = *argp++) || *cp == '-')
110 adios (NULL, "missing argument to %s", argp[-2]);
112 adios (NULL, "more than %d directories", NDIRS);
121 akv[akp++] = AliasFile;
128 alias_files (akp, akv);
145 alias_files (int akp, char **akv)
149 for (i = 0; i < akp; i++)
150 if ((err = alias (akv[i])) != AK_OK) {
152 fprintf (out, "aliasing error in %s - %s\n", akv[i], akerror (err));
153 } else if (out && !mail)
154 fprintf (out, "alias file %s is ok\n", akv[i]);
162 register struct home *hm, *lm;
164 for (hm = homehead; hm; hm = hm->h_next)
165 for (lm = hm->h_next; lm; lm = lm->h_next)
166 if (strcmp (hm->h_name, lm->h_name) == 0) {
168 fprintf (out, "duplicate user %s(uid=%d)\n",
169 lm->h_name, (int) lm->h_uid);
173 if (!hit && out && !mail)
174 fprintf (out, "no duplicate users\n");
181 int numgroups, maxgroups;
186 /* allocate space NGRPS at a time */
189 grps = (char **) mh_xmalloc((size_t) (maxgroups * sizeof(*grps)));
192 while ((gr = getgrent ())) {
193 for (i = 0; i < numgroups; i++)
194 if (!strcmp (grps[i], gr->gr_name)) {
196 fprintf (out, "duplicate group %s(gid=%d)\n",
197 gr->gr_name, (int) gr->gr_gid);
201 if (i >= numgroups) {
202 if (numgroups >= maxgroups) {
204 grps = (char **) mh_xrealloc(grps,
205 (size_t) (maxgroups * sizeof(*grps)));
207 grps[numgroups++] = getcpy (gr->gr_name);
212 for (i = 0; i < numgroups; i++)
216 if (!hit && out && !mail)
217 fprintf (out, "no duplicate groups\n");
224 register int hit = 0;
225 register char **cp, **dp;
226 register struct group *gr;
227 register struct home *hm;
230 while ((gr = getgrent ())) {
231 for (cp = gr->gr_mem; *cp; cp++) {
232 for (hm = homehead; hm; hm = hm->h_next)
233 if (!strcmp (*cp, hm->h_name))
237 fprintf (out, "group %s(gid=%d) has unknown member %s\n",
238 gr->gr_name, (int) gr->gr_gid, *cp);
244 for (dp = cp + 1; *dp; dp++)
245 if (strcmp (*cp, *dp) == 0) {
247 fprintf (out, "group %s(gid=%d) has duplicate member %s\n",
248 gr->gr_name, (int) gr->gr_gid, *cp);
255 for (hm = homehead; hm; hm = hm->h_next)
256 if (hm->h_ngrps > NGROUPS_MAX) {
258 fprintf (out, "user %s is a member of %d groups (max %d)\n",
259 hm->h_name, hm->h_ngrps, NGROUPS_MAX);
263 if (!hit && out && !mail)
264 fprintf (out, "all group members accounted for\n");
270 { /* -DRAND not implemented at most places */
271 register int hit = 0;
272 register struct home *hm;
274 for (hm = homehead; hm; hm = hm->h_next)
275 if (getgrgid (hm->h_gid) == NULL) {
277 fprintf (out, "user %s(uid=%d) has unknown group-id %d\n",
278 hm->h_name, (int) hm->h_uid, (int) hm->h_gid);
282 if (!hit && out && !mail)
283 fprintf (out, "all group-id users accounted for\n");
292 if (mmdfldir && *mmdfldir)
294 if (uucpldir && *uucpldir)
296 for (i = 0; dirs[i]; i++)
304 register int hit = 0;
305 register struct dirent *dp;
306 register DIR *dd = opendir (drop);
310 fprintf (out, "unable to open maildrop area %s\n", drop);
314 while ((dp = readdir (dd)))
315 if (dp->d_name[0] != '.' && !check (dp->d_name)) {
317 fprintf (out, "there is a maildrop for the unknown user %s in %s\n",
323 if (!hit && out && !mail)
324 fprintf (out, "all maildrops accounted for in %s\n", drop);
331 register struct home *hm;
333 for (hm = homehead; hm; hm = hm->h_next)
334 if (!strcmp (s, hm->h_name))
348 if (pipe (pd) == NOTOK)
349 adios ("pipe", "unable to");
353 adios ("fork", "unable to");
361 if ((fd = open ("/dev/null", O_WRONLY)) != NOTOK)
366 execlp (mailproc, r1bindex (mailproc, '/'),
367 mail, "-subject", invo_name, NULL);
368 adios (mailproc, "unable to exec ");
372 out = fdopen (pd[1], "w");
373 fprintf (out, "%s: the following is suspicious\n\n",
381 ** UCI specific stuff for conflict
384 /* taken from <grpldr.h> */
386 #define GLDRS "/admin/etc/GroupLeaders"
393 int setglent (), endglent ();
394 struct grpldr *getglent (), *getglnam ();
397 /* taken from the getglent() routines */
401 static FILE *glp = NULL;
402 static char line[BUFSIZ+1];
403 static struct grpldr grpldr;
404 static char *gl_ldr[MAXGLS + 1];
409 glp = fopen (GLDRS, "r");
413 return (glp != NULL);
426 struct grpldr *getglent () {
427 register char *cp, **q;
429 if (glp == NULL && !setglent ())
431 if ((cp = fgets (line, BUFSIZ, glp)) == NULL)
435 grpldr.gl_ldr = q = gl_ldr;
438 while (*cp && !isspace (*cp))
440 while (*cp && isspace (*cp))
444 if (q < gl_ldr + MAXGLS)
454 struct grpldr *getglnam (name)
457 register struct grpldr *gl = NULL;
460 while (gl = getglent ())
461 if (strcmp (name, gl->gl_name) == 0)
469 register int gp, hit = 0;
471 register struct grpldr *gl;
475 while (gl = getglent ()) {
476 if (getgrnam (gl->gl_name) == NULL) {
478 fprintf (out, "unknown group %s in group leaders file\n",
482 for (gp = 0; gldrs[gp]; gp++)
483 if (strcmp (gldrs[gp], gl->gl_name) == 0) {
485 fprintf (out, "duplicate group %s in group leaders file\n",
490 if (gldrs[gp] == NULL)
492 gldrs[gp++] = getcpy (gl->gl_name);
496 fprintf (out, "more than %d groups in group leaders file%s\n",
497 " (time to recompile)", NGRPS - 1);
503 for (gp = 0; gldrs[gp]; gp++)
506 if (!hit && out && !mail)
507 fprintf (out, "all groups in group leaders file accounted for\n");
512 register int hit = 0;
513 register char **cp, **dp;
514 register struct grpldr *gl;
517 while (gl = getglent ())
518 for (cp = gl->gl_ldr; *cp; cp++) {
521 fprintf (out, "group %s has unknown leader %s\n",
526 for (dp = cp + 1; *dp; dp++)
527 if (strcmp (*cp, *dp) == 0) {
529 fprintf (out, "group %s had duplicate leader %s\n",
536 if (!hit && out && !mail)
537 fprintf (out, "all group leaders accounted for\n");