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",
103 adios(NULL, "mail to one address only");
109 if (!(cp = *argp++) || *cp == '-')
110 adios(NULL, "missing argument to %s",
113 adios(NULL, "more than %d directories",
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],
154 } else if (out && !mail)
155 fprintf(out, "alias file %s is ok\n", akv[i]);
163 register struct home *hm, *lm;
165 for (hm = homehead; hm; hm = hm->h_next)
166 for (lm = hm->h_next; lm; lm = lm->h_next)
167 if (strcmp(hm->h_name, lm->h_name) == 0) {
169 fprintf(out, "duplicate user %s(uid=%d)\n",
170 lm->h_name, (int) lm->h_uid);
174 if (!hit && out && !mail)
175 fprintf(out, "no duplicate users\n");
182 int numgroups, maxgroups;
187 /* allocate space NGRPS at a time */
190 grps = (char **) mh_xmalloc((size_t) (maxgroups * sizeof(*grps)));
193 while ((gr = getgrent())) {
194 for (i = 0; i < numgroups; i++)
195 if (!strcmp(grps[i], gr->gr_name)) {
197 fprintf(out, "duplicate group %s(gid=%d)\n",
198 gr->gr_name, (int) gr->gr_gid);
202 if (i >= numgroups) {
203 if (numgroups >= maxgroups) {
205 grps = (char **) mh_xrealloc(grps,
206 (size_t) (maxgroups * sizeof(*grps)));
208 grps[numgroups++] = getcpy(gr->gr_name);
213 for (i = 0; i < numgroups; i++)
217 if (!hit && out && !mail)
218 fprintf(out, "no duplicate groups\n");
225 register int hit = 0;
226 register char **cp, **dp;
227 register struct group *gr;
228 register struct home *hm;
231 while ((gr = getgrent())) {
232 for (cp = gr->gr_mem; *cp; cp++) {
233 for (hm = homehead; hm; hm = hm->h_next)
234 if (!strcmp(*cp, hm->h_name))
238 fprintf(out, "group %s(gid=%d) has unknown member %s\n", 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", gr->gr_name, (int) gr->gr_gid, *cp);
254 for (hm = homehead; hm; hm = hm->h_next)
255 if (hm->h_ngrps > NGROUPS_MAX) {
257 fprintf(out, "user %s is a member of %d groups (max %d)\n",
258 hm->h_name, hm->h_ngrps, NGROUPS_MAX);
262 if (!hit && out && !mail)
263 fprintf(out, "all group members accounted for\n");
269 { /* -DRAND not implemented at most places */
270 register int hit = 0;
271 register struct home *hm;
273 for (hm = homehead; hm; hm = hm->h_next)
274 if (getgrgid(hm->h_gid) == NULL) {
276 fprintf(out, "user %s(uid=%d) has unknown group-id %d\n", hm->h_name, (int) hm->h_uid, (int) hm->h_gid);
280 if (!hit && out && !mail)
281 fprintf(out, "all group-id users accounted for\n");
290 if (mmdfldir && *mmdfldir)
292 if (uucpldir && *uucpldir)
294 for (i = 0; dirs[i]; i++)
302 register int hit = 0;
303 register struct dirent *dp;
304 register DIR *dd = opendir(drop);
308 fprintf(out, "unable to open maildrop area %s\n", drop);
312 while ((dp = readdir(dd)))
313 if (dp->d_name[0] != '.' && !check(dp->d_name)) {
315 fprintf(out, "there is a maildrop for the unknown user %s in %s\n", dp->d_name, drop);
320 if (!hit && out && !mail)
321 fprintf(out, "all maildrops accounted for in %s\n", drop);
328 register struct home *hm;
330 for (hm = homehead; hm; hm = hm->h_next)
331 if (!strcmp(s, hm->h_name))
345 if (pipe(pd) == NOTOK)
346 adios("pipe", "unable to");
350 adios("fork", "unable to");
358 if ((fd = open("/dev/null", O_WRONLY))
364 execlp(mailproc, mhbasename(mailproc),
365 mail, "-subject", invo_name,
367 adios(mailproc, "unable to exec ");
371 out = fdopen(pd[1], "w");
372 fprintf(out, "%s: the following is suspicious\n\n", invo_name);
379 ** UCI specific stuff for conflict
382 /* taken from <grpldr.h> */
384 #define GLDRS "/admin/etc/GroupLeaders"
391 int setglent(), endglent();
392 struct grpldr *getglent(), *getglnam();
395 /* taken from the getglent() routines */
399 static FILE *glp = NULL;
400 static char line[BUFSIZ+1];
401 static struct grpldr grpldr;
402 static char *gl_ldr[MAXGLS + 1];
407 glp = fopen(GLDRS, "r");
411 return (glp != NULL);
424 struct grpldr *getglent() {
425 register char *cp, **q;
427 if (glp == NULL && !setglent())
429 if ((cp = fgets(line, BUFSIZ, glp)) == NULL)
433 grpldr.gl_ldr = q = gl_ldr;
436 while (*cp && !isspace(*cp))
438 while (*cp && isspace(*cp))
442 if (q < gl_ldr + MAXGLS)
452 struct grpldr *getglnam(name)
455 register struct grpldr *gl = NULL;
458 while (gl = getglent())
459 if (strcmp(name, gl->gl_name) == 0)
467 register int gp, hit = 0;
469 register struct grpldr *gl;
473 while (gl = getglent()) {
474 if (getgrnam(gl->gl_name) == NULL) {
476 fprintf(out, "unknown group %s in group leaders file\n",
480 for (gp = 0; gldrs[gp]; gp++)
481 if (strcmp(gldrs[gp], gl->gl_name) == 0) {
483 fprintf(out, "duplicate group %s in group leaders file\n", gl->gl_name);
487 if (gldrs[gp] == NULL)
489 gldrs[gp++] = getcpy(gl->gl_name);
493 fprintf(out, "more than %d groups in group leaders file (time to recompile)\n", NGRPS - 1);
499 for (gp = 0; gldrs[gp]; gp++)
502 if (!hit && out && !mail)
503 fprintf(out, "all groups in group leaders file accounted for\n");
508 register int hit = 0;
509 register char **cp, **dp;
510 register struct grpldr *gl;
513 while (gl = getglent())
514 for (cp = gl->gl_ldr; *cp; cp++) {
517 fprintf(out, "group %s has unknown leader %s\n", gl->gl_name, *cp);
521 for (dp = cp + 1; *dp; dp++)
522 if (strcmp(*cp, *dp) == 0) {
524 fprintf(out, "group %s had duplicate leader %s\n", gl->gl_name, *cp);
530 if (!hit && out && !mail)
531 fprintf(out, "all group leaders accounted for\n");