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);
141 alias_files(int akp, char **akv)
145 for (i = 0; i < akp; i++)
146 if ((err = alias(akv[i])) != AK_OK) {
148 fprintf(out, "aliasing error in %s - %s\n", akv[i],
150 } else if (out && !mail)
151 fprintf(out, "alias file %s is ok\n", akv[i]);
159 register struct home *hm, *lm;
161 for (hm = homehead; hm; hm = hm->h_next)
162 for (lm = hm->h_next; lm; lm = lm->h_next)
163 if (strcmp(hm->h_name, lm->h_name) == 0) {
165 fprintf(out, "duplicate user %s(uid=%d)\n",
166 lm->h_name, (int) lm->h_uid);
170 if (!hit && out && !mail)
171 fprintf(out, "no duplicate users\n");
178 int numgroups, maxgroups;
183 /* allocate space NGRPS at a time */
186 grps = (char **) mh_xmalloc((size_t) (maxgroups * sizeof(*grps)));
189 while ((gr = getgrent())) {
190 for (i = 0; i < numgroups; i++)
191 if (strcmp(grps[i], gr->gr_name)==0) {
193 fprintf(out, "duplicate group %s(gid=%d)\n",
194 gr->gr_name, (int) gr->gr_gid);
198 if (i >= numgroups) {
199 if (numgroups >= maxgroups) {
201 grps = (char **) mh_xrealloc(grps,
202 (size_t) (maxgroups * sizeof(*grps)));
204 grps[numgroups++] = getcpy(gr->gr_name);
209 for (i = 0; i < numgroups; i++)
213 if (!hit && out && !mail)
214 fprintf(out, "no duplicate groups\n");
221 register int hit = 0;
222 register char **cp, **dp;
223 register struct group *gr;
224 register struct home *hm;
227 while ((gr = getgrent())) {
228 for (cp = gr->gr_mem; *cp; cp++) {
229 for (hm = homehead; hm; hm = hm->h_next)
230 if (strcmp(*cp, hm->h_name)==0)
234 fprintf(out, "group %s(gid=%d) has unknown member %s\n", gr->gr_name, (int) gr->gr_gid, *cp);
240 for (dp = cp + 1; *dp; dp++)
241 if (strcmp(*cp, *dp) == 0) {
243 fprintf(out, "group %s(gid=%d) has duplicate member %s\n", gr->gr_name, (int) gr->gr_gid, *cp);
250 for (hm = homehead; hm; hm = hm->h_next)
251 if (hm->h_ngrps > NGROUPS_MAX) {
253 fprintf(out, "user %s is a member of %d groups (max %d)\n",
254 hm->h_name, hm->h_ngrps, NGROUPS_MAX);
258 if (!hit && out && !mail)
259 fprintf(out, "all group members accounted for\n");
265 { /* -DRAND not implemented at most places */
266 register int hit = 0;
267 register struct home *hm;
269 for (hm = homehead; hm; hm = hm->h_next)
270 if (getgrgid(hm->h_gid) == NULL) {
272 fprintf(out, "user %s(uid=%d) has unknown group-id %d\n", hm->h_name, (int) hm->h_uid, (int) hm->h_gid);
276 if (!hit && out && !mail)
277 fprintf(out, "all group-id users accounted for\n");
287 for (i = 0; dirs[i]; i++)
295 register int hit = 0;
296 register struct dirent *dp;
297 register DIR *dd = opendir(drop);
301 fprintf(out, "unable to open maildrop area %s\n", drop);
305 while ((dp = readdir(dd)))
306 if (dp->d_name[0] != '.' && !check(dp->d_name)) {
308 fprintf(out, "there is a maildrop for the unknown user %s in %s\n", dp->d_name, drop);
313 if (!hit && out && !mail)
314 fprintf(out, "all maildrops accounted for in %s\n", drop);
321 register struct home *hm;
323 for (hm = homehead; hm; hm = hm->h_next)
324 if (strcmp(s, hm->h_name)==0)
338 if (pipe(pd) == NOTOK)
339 adios("pipe", "unable to");
343 adios("fork", "unable to");
351 if ((fd = open("/dev/null", O_WRONLY))
357 execlp(mailproc, mhbasename(mailproc),
358 mail, "-subject", invo_name,
360 adios(mailproc, "unable to exec ");
364 out = fdopen(pd[1], "w");
365 fprintf(out, "%s: the following is suspicious\n\n", invo_name);