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);
147 alias_files (int akp, char **akv)
151 for (i = 0; i < akp; i++)
152 if ((err = alias (akv[i])) != AK_OK) {
154 fprintf (out, "aliasing error in %s - %s\n", akv[i], akerror (err));
158 fprintf (out, "alias file %s is ok\n", akv[i]);
166 register struct home *hm, *lm;
168 for (hm = homehead; hm; hm = hm->h_next)
169 for (lm = hm->h_next; lm; lm = lm->h_next)
170 if (strcmp (hm->h_name, lm->h_name) == 0) {
172 fprintf (out, "duplicate user %s(uid=%d)\n",
173 lm->h_name, (int) lm->h_uid);
177 if (!hit && out && !mail)
178 fprintf (out, "no duplicate users\n");
185 int numgroups, maxgroups;
190 /* allocate space NGRPS at a time */
193 grps = (char **) mh_xmalloc((size_t) (maxgroups * sizeof(*grps)));
196 while ((gr = getgrent ())) {
197 for (i = 0; i < numgroups; i++)
198 if (!strcmp (grps[i], gr->gr_name)) {
200 fprintf (out, "duplicate group %s(gid=%d)\n",
201 gr->gr_name, (int) gr->gr_gid);
205 if (i >= numgroups) {
206 if (numgroups >= maxgroups) {
208 grps = (char **) mh_xrealloc(grps,
209 (size_t) (maxgroups * sizeof(*grps)));
211 grps[numgroups++] = getcpy (gr->gr_name);
216 for (i = 0; i < numgroups; i++)
220 if (!hit && out && !mail)
221 fprintf (out, "no duplicate groups\n");
228 register int hit = 0;
229 register char **cp, **dp;
230 register struct group *gr;
231 register struct home *hm;
234 while ((gr = getgrent ())) {
235 for (cp = gr->gr_mem; *cp; cp++) {
236 for (hm = homehead; hm; hm = hm->h_next)
237 if (!strcmp (*cp, hm->h_name))
241 fprintf (out, "group %s(gid=%d) has unknown member %s\n",
242 gr->gr_name, (int) gr->gr_gid, *cp);
248 for (dp = cp + 1; *dp; dp++)
249 if (strcmp (*cp, *dp) == 0) {
251 fprintf (out, "group %s(gid=%d) has duplicate member %s\n",
252 gr->gr_name, (int) gr->gr_gid, *cp);
259 for (hm = homehead; hm; hm = hm->h_next)
260 if (hm->h_ngrps > NGROUPS_MAX) {
262 fprintf (out, "user %s is a member of %d groups (max %d)\n",
263 hm->h_name, hm->h_ngrps, NGROUPS_MAX);
267 if (!hit && out && !mail)
268 fprintf (out, "all group members accounted for\n");
274 { /* -DRAND not implemented at most places */
275 register int hit = 0;
276 register struct home *hm;
278 for (hm = homehead; hm; hm = hm->h_next)
279 if (getgrgid (hm->h_gid) == NULL) {
281 fprintf (out, "user %s(uid=%d) has unknown group-id %d\n",
282 hm->h_name, (int) hm->h_uid, (int) hm->h_gid);
286 if (!hit && out && !mail)
287 fprintf (out, "all group-id users accounted for\n");
296 if (mmdfldir && *mmdfldir)
298 if (uucpldir && *uucpldir)
300 for (i = 0; dirs[i]; i++)
308 register int hit = 0;
309 register struct dirent *dp;
310 register DIR *dd = opendir (drop);
314 fprintf (out, "unable to open maildrop area %s\n", drop);
318 while ((dp = readdir (dd)))
319 if (dp->d_name[0] != '.' && !check (dp->d_name)) {
322 "there is a maildrop for the unknown user %s in %s\n",
328 if (!hit && out && !mail)
329 fprintf (out, "all maildrops accounted for in %s\n", drop);
336 register struct home *hm;
338 for (hm = homehead; hm; hm = hm->h_next)
339 if (!strcmp (s, hm->h_name))
353 if (pipe (pd) == NOTOK)
354 adios ("pipe", "unable to");
358 adios ("fork", "unable to");
366 if ((fd = open ("/dev/null", O_WRONLY)) != NOTOK)
371 execlp (mailproc, r1bindex (mailproc, '/'),
372 mail, "-subject", invo_name, NULL);
373 adios (mailproc, "unable to exec ");
377 out = fdopen (pd[1], "w");
378 fprintf (out, "%s: the following is suspicious\n\n",
386 * UCI specific stuff for conflict
389 /* taken from <grpldr.h> */
391 #define GLDRS "/admin/etc/GroupLeaders"
398 int setglent (), endglent ();
399 struct grpldr *getglent (), *getglnam ();
402 /* taken from the getglent() routines */
406 static FILE *glp = NULL;
407 static char line[BUFSIZ+1];
408 static struct grpldr grpldr;
409 static char *gl_ldr[MAXGLS + 1];
414 glp = fopen (GLDRS, "r");
418 return (glp != NULL);
431 struct grpldr *getglent () {
435 if (glp == NULL && !setglent ())
437 if ((cp = fgets (line, BUFSIZ, glp)) == NULL)
441 grpldr.gl_ldr = q = gl_ldr;
444 while (*cp && !isspace (*cp))
446 while (*cp && isspace (*cp))
450 if (q < gl_ldr + MAXGLS)
460 struct grpldr *getglnam (name)
463 register struct grpldr *gl = NULL;
466 while (gl = getglent ())
467 if (strcmp (name, gl->gl_name) == 0)
478 register struct grpldr *gl;
482 while (gl = getglent ()) {
483 if (getgrnam (gl->gl_name) == NULL) {
485 fprintf (out, "unknown group %s in group leaders file\n",
489 for (gp = 0; gldrs[gp]; gp++)
490 if (strcmp (gldrs[gp], gl->gl_name) == 0) {
492 fprintf (out, "duplicate group %s in group leaders file\n",
497 if (gldrs[gp] == NULL)
499 gldrs[gp++] = getcpy (gl->gl_name);
504 fprintf (out, "more than %d groups in group leaders file%s\n",
505 " (time to recompile)", NGRPS - 1);
511 for (gp = 0; gldrs[gp]; gp++)
514 if (!hit && out && !mail)
515 fprintf (out, "all groups in group leaders file accounted for\n");
520 register int hit = 0;
523 register struct grpldr *gl;
526 while (gl = getglent ())
527 for (cp = gl->gl_ldr; *cp; cp++) {
530 fprintf (out, "group %s has unknown leader %s\n",
535 for (dp = cp + 1; *dp; dp++)
536 if (strcmp (*cp, *dp) == 0) {
538 fprintf (out, "group %s had duplicate leader %s\n",
545 if (!hit && out && !mail)
546 fprintf (out, "all group leaders accounted for\n");