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);
125 alias_files(akp, akv);
142 alias_files(int akp, char **akv)
146 for (i = 0; i < akp; i++)
147 if ((err = alias(akv[i])) != AK_OK) {
149 fprintf(out, "aliasing error in %s - %s\n", akv[i],
151 } else if (out && !mail)
152 fprintf(out, "alias file %s is ok\n", akv[i]);
160 register struct home *hm, *lm;
162 for (hm = homehead; hm; hm = hm->h_next)
163 for (lm = hm->h_next; lm; lm = lm->h_next)
164 if (strcmp(hm->h_name, lm->h_name) == 0) {
166 fprintf(out, "duplicate user %s(uid=%d)\n",
167 lm->h_name, (int) lm->h_uid);
171 if (!hit && out && !mail)
172 fprintf(out, "no duplicate users\n");
179 int numgroups, maxgroups;
184 /* allocate space NGRPS at a time */
187 grps = (char **) mh_xmalloc((size_t) (maxgroups * sizeof(*grps)));
190 while ((gr = getgrent())) {
191 for (i = 0; i < numgroups; i++)
192 if (!strcmp(grps[i], gr->gr_name)) {
194 fprintf(out, "duplicate group %s(gid=%d)\n",
195 gr->gr_name, (int) gr->gr_gid);
199 if (i >= numgroups) {
200 if (numgroups >= maxgroups) {
202 grps = (char **) mh_xrealloc(grps,
203 (size_t) (maxgroups * sizeof(*grps)));
205 grps[numgroups++] = getcpy(gr->gr_name);
210 for (i = 0; i < numgroups; i++)
214 if (!hit && out && !mail)
215 fprintf(out, "no duplicate groups\n");
222 register int hit = 0;
223 register char **cp, **dp;
224 register struct group *gr;
225 register struct home *hm;
228 while ((gr = getgrent())) {
229 for (cp = gr->gr_mem; *cp; cp++) {
230 for (hm = homehead; hm; hm = hm->h_next)
231 if (!strcmp(*cp, hm->h_name))
235 fprintf(out, "group %s(gid=%d) has unknown member %s\n", gr->gr_name, (int) gr->gr_gid, *cp);
241 for (dp = cp + 1; *dp; dp++)
242 if (strcmp(*cp, *dp) == 0) {
244 fprintf(out, "group %s(gid=%d) has duplicate member %s\n", gr->gr_name, (int) gr->gr_gid, *cp);
251 for (hm = homehead; hm; hm = hm->h_next)
252 if (hm->h_ngrps > NGROUPS_MAX) {
254 fprintf(out, "user %s is a member of %d groups (max %d)\n",
255 hm->h_name, hm->h_ngrps, NGROUPS_MAX);
259 if (!hit && out && !mail)
260 fprintf(out, "all group members accounted for\n");
266 { /* -DRAND not implemented at most places */
267 register int hit = 0;
268 register struct home *hm;
270 for (hm = homehead; hm; hm = hm->h_next)
271 if (getgrgid(hm->h_gid) == NULL) {
273 fprintf(out, "user %s(uid=%d) has unknown group-id %d\n", hm->h_name, (int) hm->h_uid, (int) hm->h_gid);
277 if (!hit && out && !mail)
278 fprintf(out, "all group-id users accounted for\n");
287 if (mmdfldir && *mmdfldir)
289 if (uucpldir && *uucpldir)
291 for (i = 0; dirs[i]; i++)
299 register int hit = 0;
300 register struct dirent *dp;
301 register DIR *dd = opendir(drop);
305 fprintf(out, "unable to open maildrop area %s\n", drop);
309 while ((dp = readdir(dd)))
310 if (dp->d_name[0] != '.' && !check(dp->d_name)) {
312 fprintf(out, "there is a maildrop for the unknown user %s in %s\n", dp->d_name, drop);
317 if (!hit && out && !mail)
318 fprintf(out, "all maildrops accounted for in %s\n", drop);
325 register struct home *hm;
327 for (hm = homehead; hm; hm = hm->h_next)
328 if (!strcmp(s, hm->h_name))
342 if (pipe(pd) == NOTOK)
343 adios("pipe", "unable to");
347 adios("fork", "unable to");
355 if ((fd = open("/dev/null", O_WRONLY))
361 execlp(mailproc, mhbasename(mailproc),
362 mail, "-subject", invo_name,
364 adios(mailproc, "unable to exec ");
368 out = fdopen(pd[1], "w");
369 fprintf(out, "%s: the following is suspicious\n\n", invo_name);
376 ** UCI specific stuff for conflict
379 /* taken from <grpldr.h> */
381 #define GLDRS "/admin/etc/GroupLeaders"
388 int setglent(), endglent();
389 struct grpldr *getglent(), *getglnam();
392 /* taken from the getglent() routines */
396 static FILE *glp = NULL;
397 static char line[BUFSIZ+1];
398 static struct grpldr grpldr;
399 static char *gl_ldr[MAXGLS + 1];
404 glp = fopen(GLDRS, "r");
408 return (glp != NULL);
421 struct grpldr *getglent() {
422 register char *cp, **q;
424 if (glp == NULL && !setglent())
426 if ((cp = fgets(line, BUFSIZ, glp)) == NULL)
430 grpldr.gl_ldr = q = gl_ldr;
433 while (*cp && !isspace(*cp))
435 while (*cp && isspace(*cp))
439 if (q < gl_ldr + MAXGLS)
449 struct grpldr *getglnam(name)
452 register struct grpldr *gl = NULL;
455 while (gl = getglent())
456 if (strcmp(name, gl->gl_name) == 0)
464 register int gp, hit = 0;
466 register struct grpldr *gl;
470 while (gl = getglent()) {
471 if (getgrnam(gl->gl_name) == NULL) {
473 fprintf(out, "unknown group %s in group leaders file\n",
477 for (gp = 0; gldrs[gp]; gp++)
478 if (strcmp(gldrs[gp], gl->gl_name) == 0) {
480 fprintf(out, "duplicate group %s in group leaders file\n", gl->gl_name);
484 if (gldrs[gp] == NULL)
486 gldrs[gp++] = getcpy(gl->gl_name);
490 fprintf(out, "more than %d groups in group leaders file (time to recompile)\n", NGRPS - 1);
496 for (gp = 0; gldrs[gp]; gp++)
499 if (!hit && out && !mail)
500 fprintf(out, "all groups in group leaders file accounted for\n");
505 register int hit = 0;
506 register char **cp, **dp;
507 register struct grpldr *gl;
510 while (gl = getglent())
511 for (cp = gl->gl_ldr; *cp; cp++) {
514 fprintf(out, "group %s has unknown leader %s\n", gl->gl_name, *cp);
518 for (dp = cp + 1; *dp; dp++)
519 if (strcmp(*cp, *dp) == 0) {
521 fprintf(out, "group %s had duplicate leader %s\n", gl->gl_name, *cp);
527 if (!hit && out && !mail)
528 fprintf(out, "all group leaders accounted for\n");