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));
156 fprintf (out, "alias file %s is ok\n", akv[i]);
164 register struct home *hm, *lm;
166 for (hm = homehead; hm; hm = hm->h_next)
167 for (lm = hm->h_next; lm; lm = lm->h_next)
168 if (strcmp (hm->h_name, lm->h_name) == 0) {
170 fprintf (out, "duplicate user %s(uid=%d)\n",
171 lm->h_name, (int) lm->h_uid);
175 if (!hit && out && !mail)
176 fprintf (out, "no duplicate users\n");
183 int numgroups, maxgroups;
188 /* allocate space NGRPS at a time */
191 grps = (char **) mh_xmalloc((size_t) (maxgroups * sizeof(*grps)));
194 while ((gr = getgrent ())) {
195 for (i = 0; i < numgroups; i++)
196 if (!strcmp (grps[i], gr->gr_name)) {
198 fprintf (out, "duplicate group %s(gid=%d)\n",
199 gr->gr_name, (int) gr->gr_gid);
203 if (i >= numgroups) {
204 if (numgroups >= maxgroups) {
206 grps = (char **) mh_xrealloc(grps,
207 (size_t) (maxgroups * sizeof(*grps)));
209 grps[numgroups++] = getcpy (gr->gr_name);
214 for (i = 0; i < numgroups; i++)
218 if (!hit && out && !mail)
219 fprintf (out, "no duplicate groups\n");
226 register int hit = 0;
227 register char **cp, **dp;
228 register struct group *gr;
229 register struct home *hm;
232 while ((gr = getgrent ())) {
233 for (cp = gr->gr_mem; *cp; cp++) {
234 for (hm = homehead; hm; hm = hm->h_next)
235 if (!strcmp (*cp, hm->h_name))
239 fprintf (out, "group %s(gid=%d) has unknown member %s\n",
240 gr->gr_name, (int) gr->gr_gid, *cp);
246 for (dp = cp + 1; *dp; dp++)
247 if (strcmp (*cp, *dp) == 0) {
249 fprintf (out, "group %s(gid=%d) has duplicate member %s\n",
250 gr->gr_name, (int) gr->gr_gid, *cp);
257 for (hm = homehead; hm; hm = hm->h_next)
258 if (hm->h_ngrps > NGROUPS_MAX) {
260 fprintf (out, "user %s is a member of %d groups (max %d)\n",
261 hm->h_name, hm->h_ngrps, NGROUPS_MAX);
265 if (!hit && out && !mail)
266 fprintf (out, "all group members accounted for\n");
272 { /* -DRAND not implemented at most places */
273 register int hit = 0;
274 register struct home *hm;
276 for (hm = homehead; hm; hm = hm->h_next)
277 if (getgrgid (hm->h_gid) == NULL) {
279 fprintf (out, "user %s(uid=%d) has unknown group-id %d\n",
280 hm->h_name, (int) hm->h_uid, (int) hm->h_gid);
284 if (!hit && out && !mail)
285 fprintf (out, "all group-id users accounted for\n");
294 if (mmdfldir && *mmdfldir)
296 if (uucpldir && *uucpldir)
298 for (i = 0; dirs[i]; i++)
306 register int hit = 0;
307 register struct dirent *dp;
308 register DIR *dd = opendir (drop);
312 fprintf (out, "unable to open maildrop area %s\n", drop);
316 while ((dp = readdir (dd)))
317 if (dp->d_name[0] != '.' && !check (dp->d_name)) {
320 "there is a maildrop for the unknown user %s in %s\n",
326 if (!hit && out && !mail)
327 fprintf (out, "all maildrops accounted for in %s\n", drop);
334 register struct home *hm;
336 for (hm = homehead; hm; hm = hm->h_next)
337 if (!strcmp (s, hm->h_name))
351 if (pipe (pd) == NOTOK)
352 adios ("pipe", "unable to");
356 adios ("fork", "unable to");
364 if ((fd = open ("/dev/null", O_WRONLY)) != NOTOK)
369 execlp (mailproc, r1bindex (mailproc, '/'),
370 mail, "-subject", invo_name, NULL);
371 adios (mailproc, "unable to exec ");
375 out = fdopen (pd[1], "w");
376 fprintf (out, "%s: the following is suspicious\n\n",
384 * UCI specific stuff for conflict
387 /* taken from <grpldr.h> */
389 #define GLDRS "/admin/etc/GroupLeaders"
396 int setglent (), endglent ();
397 struct grpldr *getglent (), *getglnam ();
400 /* taken from the getglent() routines */
404 static FILE *glp = NULL;
405 static char line[BUFSIZ+1];
406 static struct grpldr grpldr;
407 static char *gl_ldr[MAXGLS + 1];
412 glp = fopen (GLDRS, "r");
416 return (glp != NULL);
429 struct grpldr *getglent () {
433 if (glp == NULL && !setglent ())
435 if ((cp = fgets (line, BUFSIZ, glp)) == NULL)
439 grpldr.gl_ldr = q = gl_ldr;
442 while (*cp && !isspace (*cp))
444 while (*cp && isspace (*cp))
448 if (q < gl_ldr + MAXGLS)
458 struct grpldr *getglnam (name)
461 register struct grpldr *gl = NULL;
464 while (gl = getglent ())
465 if (strcmp (name, gl->gl_name) == 0)
473 register int gp, hit = 0;
475 register struct grpldr *gl;
479 while (gl = getglent ()) {
480 if (getgrnam (gl->gl_name) == NULL) {
482 fprintf (out, "unknown group %s in group leaders file\n",
486 for (gp = 0; gldrs[gp]; gp++)
487 if (strcmp (gldrs[gp], gl->gl_name) == 0) {
489 fprintf (out, "duplicate group %s in group leaders file\n",
494 if (gldrs[gp] == NULL)
496 gldrs[gp++] = getcpy (gl->gl_name);
501 fprintf (out, "more than %d groups in group leaders file%s\n",
502 " (time to recompile)", NGRPS - 1);
508 for (gp = 0; gldrs[gp]; gp++)
511 if (!hit && out && !mail)
512 fprintf (out, "all groups in group leaders file accounted for\n");
517 register int hit = 0;
518 register char **cp, **dp;
519 register struct grpldr *gl;
522 while (gl = getglent ())
523 for (cp = gl->gl_ldr; *cp; cp++) {
526 fprintf (out, "group %s has unknown leader %s\n",
531 for (dp = cp + 1; *dp; dp++)
532 if (strcmp (*cp, *dp) == 0) {
534 fprintf (out, "group %s had duplicate leader %s\n",
541 if (!hit && out && !mail)
542 fprintf (out, "all group leaders accounted for\n");