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>
17 ** maximum number of directories that can
18 ** be specified using -search switch.
23 ** Add space for group names, 100 at a time
27 static struct swit switches[] = {
31 { "search directory", 0 },
39 static char *mail = NULL;
40 static char *dirs[NDIRS];
41 static FILE *out = NULL;
43 extern struct aka *akahead;
44 extern struct home *homehead;
49 void alias_files(int, char **);
52 void grp_members(void);
61 main(int argc, char **argv)
64 char *cp, **argp, **arguments;
65 char buf[BUFSIZ], *akv[50];
68 setlocale(LC_ALL, "");
70 invo_name = mhbasename(argv[0]);
72 /* foil search of user profile/context */
73 if (context_foil(NULL) == -1)
76 arguments = getarguments(invo_name, argc, argv, 0);
79 while ((cp = *argp++)) {
81 switch (smatch(++cp, switches)) {
83 ambigsw(cp, switches);
86 adios(NULL, "-%s unknown", cp);
89 snprintf(buf, sizeof(buf), "%s [switches] [aliasfiles ...]", invo_name);
90 print_help(buf, switches, 0);
93 print_version(invo_name);
97 if (!(cp = *argp++) || *cp == '-')
98 adios(NULL, "missing argument to %s",
101 adios(NULL, "mail to one address only");
107 if (!(cp = *argp++) || *cp == '-')
108 adios(NULL, "missing argument to %s",
111 adios(NULL, "more than %d directories",
126 alias_files(akp, akv);
139 alias_files(int akp, char **akv)
143 for (i = 0; i < akp; i++)
144 if ((err = alias(akv[i])) != AK_OK) {
146 fprintf(out, "aliasing error in %s - %s\n", akv[i],
148 } else if (out && !mail)
149 fprintf(out, "alias file %s is ok\n", akv[i]);
157 register struct home *hm, *lm;
159 for (hm = homehead; hm; hm = hm->h_next)
160 for (lm = hm->h_next; lm; lm = lm->h_next)
161 if (strcmp(hm->h_name, lm->h_name) == 0) {
163 fprintf(out, "duplicate user %s(uid=%d)\n",
164 lm->h_name, (int) lm->h_uid);
168 if (!hit && out && !mail)
169 fprintf(out, "no duplicate users\n");
176 int numgroups, maxgroups;
181 /* allocate space NGRPS at a time */
184 grps = (char **) mh_xmalloc((size_t) (maxgroups * sizeof(*grps)));
187 while ((gr = getgrent())) {
188 for (i = 0; i < numgroups; i++)
189 if (strcmp(grps[i], gr->gr_name)==0) {
191 fprintf(out, "duplicate group %s(gid=%d)\n",
192 gr->gr_name, (int) gr->gr_gid);
196 if (i >= numgroups) {
197 if (numgroups >= maxgroups) {
199 grps = (char **) mh_xrealloc(grps,
200 (size_t) (maxgroups * sizeof(*grps)));
202 grps[numgroups++] = getcpy(gr->gr_name);
207 for (i = 0; i < numgroups; i++)
211 if (!hit && out && !mail)
212 fprintf(out, "no duplicate groups\n");
219 register int hit = 0;
220 register char **cp, **dp;
221 register struct group *gr;
222 register struct home *hm;
225 while ((gr = getgrent())) {
226 for (cp = gr->gr_mem; *cp; cp++) {
227 for (hm = homehead; hm; hm = hm->h_next)
228 if (strcmp(*cp, hm->h_name)==0)
232 fprintf(out, "group %s(gid=%d) has unknown member %s\n", gr->gr_name, (int) gr->gr_gid, *cp);
238 for (dp = cp + 1; *dp; dp++)
239 if (strcmp(*cp, *dp) == 0) {
241 fprintf(out, "group %s(gid=%d) has duplicate member %s\n", gr->gr_name, (int) gr->gr_gid, *cp);
248 for (hm = homehead; hm; hm = hm->h_next)
249 if (hm->h_ngrps > NGROUPS_MAX) {
251 fprintf(out, "user %s is a member of %d groups (max %d)\n",
252 hm->h_name, hm->h_ngrps, NGROUPS_MAX);
256 if (!hit && out && !mail)
257 fprintf(out, "all group members accounted for\n");
263 { /* -DRAND not implemented at most places */
264 register int hit = 0;
265 register struct home *hm;
267 for (hm = homehead; hm; hm = hm->h_next)
268 if (getgrgid(hm->h_gid) == NULL) {
270 fprintf(out, "user %s(uid=%d) has unknown group-id %d\n", hm->h_name, (int) hm->h_uid, (int) hm->h_gid);
274 if (!hit && out && !mail)
275 fprintf(out, "all group-id users accounted for\n");
285 for (i = 0; dirs[i]; i++)
293 register int hit = 0;
294 register struct dirent *dp;
295 register DIR *dd = opendir(drop);
299 fprintf(out, "unable to open maildrop area %s\n", drop);
303 while ((dp = readdir(dd)))
304 if (dp->d_name[0] != '.' && !check(dp->d_name)) {
306 fprintf(out, "there is a maildrop for the unknown user %s in %s\n", dp->d_name, drop);
311 if (!hit && out && !mail)
312 fprintf(out, "all maildrops accounted for in %s\n", drop);
319 register struct home *hm;
321 for (hm = homehead; hm; hm = hm->h_next)
322 if (strcmp(s, hm->h_name)==0)
336 if (pipe(pd) == NOTOK)
337 adios("pipe", "unable to");
341 adios("fork", "unable to");
349 if ((fd = open("/dev/null", O_WRONLY))
355 execlp(mailproc, mhbasename(mailproc),
356 mail, "-subject", invo_name,
358 adios(mailproc, "unable to exec ");
362 out = fdopen(pd[1], "w");
363 fprintf(out, "%s: the following is suspicious\n\n", invo_name);