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 **);
53 void grp_members(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 = mhbasename(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 ...]", invo_name);
92 print_help(buf, switches, 0);
95 print_version(invo_name);
99 if (!(cp = *argp++) || *cp == '-')
100 adios(NULL, "missing argument to %s", argp[-2]);
102 adios(NULL, "mail to one address only");
108 if (!(cp = *argp++) || *cp == '-')
109 adios(NULL, "missing argument to %s", argp[-2]);
111 adios(NULL, "more than %d directories", NDIRS);
120 akv[akp++] = AliasFile;
127 alias_files(akp, akv);
144 alias_files(int akp, char **akv)
148 for (i = 0; i < akp; i++)
149 if ((err = alias(akv[i])) != AK_OK) {
151 fprintf(out, "aliasing error in %s - %s\n", akv[i],
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", gr->gr_name, (int) gr->gr_gid, *cp);
243 for (dp = cp + 1; *dp; dp++)
244 if (strcmp(*cp, *dp) == 0) {
246 fprintf(out, "group %s(gid=%d) has duplicate member %s\n", gr->gr_name, (int) gr->gr_gid, *cp);
253 for (hm = homehead; hm; hm = hm->h_next)
254 if (hm->h_ngrps > NGROUPS_MAX) {
256 fprintf(out, "user %s is a member of %d groups (max %d)\n",
257 hm->h_name, hm->h_ngrps, NGROUPS_MAX);
261 if (!hit && out && !mail)
262 fprintf(out, "all group members accounted for\n");
268 { /* -DRAND not implemented at most places */
269 register int hit = 0;
270 register struct home *hm;
272 for (hm = homehead; hm; hm = hm->h_next)
273 if (getgrgid(hm->h_gid) == NULL) {
275 fprintf(out, "user %s(uid=%d) has unknown group-id %d\n", hm->h_name, (int) hm->h_uid, (int) hm->h_gid);
279 if (!hit && out && !mail)
280 fprintf(out, "all group-id users accounted for\n");
289 if (mmdfldir && *mmdfldir)
291 if (uucpldir && *uucpldir)
293 for (i = 0; dirs[i]; i++)
301 register int hit = 0;
302 register struct dirent *dp;
303 register DIR *dd = opendir(drop);
307 fprintf(out, "unable to open maildrop area %s\n", drop);
311 while ((dp = readdir(dd)))
312 if (dp->d_name[0] != '.' && !check(dp->d_name)) {
314 fprintf(out, "there is a maildrop for the unknown user %s in %s\n", dp->d_name, drop);
319 if (!hit && out && !mail)
320 fprintf(out, "all maildrops accounted for in %s\n", drop);
327 register struct home *hm;
329 for (hm = homehead; hm; hm = hm->h_next)
330 if (!strcmp(s, hm->h_name))
344 if (pipe(pd) == NOTOK)
345 adios("pipe", "unable to");
349 adios("fork", "unable to");
357 if ((fd = open("/dev/null", O_WRONLY))
363 execlp(mailproc, mhbasename(mailproc),
364 mail, "-subject", invo_name,
366 adios(mailproc, "unable to exec ");
370 out = fdopen(pd[1], "w");
371 fprintf(out, "%s: the following is suspicious\n\n", invo_name);
378 ** UCI specific stuff for conflict
381 /* taken from <grpldr.h> */
383 #define GLDRS "/admin/etc/GroupLeaders"
390 int setglent(), endglent();
391 struct grpldr *getglent(), *getglnam();
394 /* taken from the getglent() routines */
398 static FILE *glp = NULL;
399 static char line[BUFSIZ+1];
400 static struct grpldr grpldr;
401 static char *gl_ldr[MAXGLS + 1];
406 glp = fopen(GLDRS, "r");
410 return (glp != NULL);
423 struct grpldr *getglent() {
424 register char *cp, **q;
426 if (glp == NULL && !setglent())
428 if ((cp = fgets(line, BUFSIZ, glp)) == NULL)
432 grpldr.gl_ldr = q = gl_ldr;
435 while (*cp && !isspace(*cp))
437 while (*cp && isspace(*cp))
441 if (q < gl_ldr + MAXGLS)
451 struct grpldr *getglnam(name)
454 register struct grpldr *gl = NULL;
457 while (gl = getglent())
458 if (strcmp(name, gl->gl_name) == 0)
466 register int gp, hit = 0;
468 register struct grpldr *gl;
472 while (gl = getglent()) {
473 if (getgrnam(gl->gl_name) == NULL) {
475 fprintf(out, "unknown group %s in group leaders file\n",
479 for (gp = 0; gldrs[gp]; gp++)
480 if (strcmp(gldrs[gp], gl->gl_name) == 0) {
482 fprintf(out, "duplicate group %s in group leaders file\n", gl->gl_name);
486 if (gldrs[gp] == NULL)
488 gldrs[gp++] = getcpy(gl->gl_name);
492 fprintf(out, "more than %d groups in group leaders file (time to recompile)\n", NGRPS - 1);
498 for (gp = 0; gldrs[gp]; gp++)
501 if (!hit && out && !mail)
502 fprintf(out, "all groups in group leaders file accounted for\n");
507 register int hit = 0;
508 register char **cp, **dp;
509 register struct grpldr *gl;
512 while (gl = getglent())
513 for (cp = gl->gl_ldr; *cp; cp++) {
516 fprintf(out, "group %s has unknown leader %s\n", gl->gl_name, *cp);
520 for (dp = cp + 1; *dp; dp++)
521 if (strcmp(*cp, *dp) == 0) {
523 fprintf(out, "group %s had duplicate leader %s\n", gl->gl_name, *cp);
529 if (!hit && out && !mail)
530 fprintf(out, "all group leaders accounted for\n");