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)
77 arguments = getarguments(invo_name, argc, argv, 0);
80 while ((cp = *argp++)) {
82 switch (smatch(++cp, switches)) {
84 ambigsw(cp, switches);
87 adios(NULL, "-%s unknown", cp);
90 snprintf(buf, sizeof(buf), "%s [switches] [aliasfiles ...]", invo_name);
91 print_help(buf, switches, 0);
94 print_version(invo_name);
98 if (!(cp = *argp++) || *cp == '-')
99 adios(NULL, "missing argument to %s",
102 adios(NULL, "mail to one address only");
108 if (!(cp = *argp++) || *cp == '-')
109 adios(NULL, "missing argument to %s",
112 adios(NULL, "more than %d directories",
127 alias_files(akp, akv);
140 alias_files(int akp, char **akv)
144 for (i = 0; i < akp; i++)
145 if ((err = alias(akv[i])) != AK_OK) {
147 fprintf(out, "aliasing error in %s - %s\n", akv[i],
149 } else if (out && !mail)
150 fprintf(out, "alias file %s is ok\n", akv[i]);
158 register struct home *hm, *lm;
160 for (hm = homehead; hm; hm = hm->h_next)
161 for (lm = hm->h_next; lm; lm = lm->h_next)
162 if (strcmp(hm->h_name, lm->h_name) == 0) {
164 fprintf(out, "duplicate user %s(uid=%d)\n",
165 lm->h_name, (int) lm->h_uid);
169 if (!hit && out && !mail)
170 fprintf(out, "no duplicate users\n");
177 int numgroups, maxgroups;
182 /* allocate space NGRPS at a time */
185 grps = (char **) mh_xmalloc((size_t) (maxgroups * sizeof(*grps)));
188 while ((gr = getgrent())) {
189 for (i = 0; i < numgroups; i++)
190 if (strcmp(grps[i], gr->gr_name)==0) {
192 fprintf(out, "duplicate group %s(gid=%d)\n",
193 gr->gr_name, (int) gr->gr_gid);
197 if (i >= numgroups) {
198 if (numgroups >= maxgroups) {
200 grps = (char **) mh_xrealloc(grps,
201 (size_t) (maxgroups * sizeof(*grps)));
203 grps[numgroups++] = getcpy(gr->gr_name);
208 for (i = 0; i < numgroups; i++)
212 if (!hit && out && !mail)
213 fprintf(out, "no duplicate groups\n");
220 register int hit = 0;
221 register char **cp, **dp;
222 register struct group *gr;
223 register struct home *hm;
226 while ((gr = getgrent())) {
227 for (cp = gr->gr_mem; *cp; cp++) {
228 for (hm = homehead; hm; hm = hm->h_next)
229 if (strcmp(*cp, hm->h_name)==0)
233 fprintf(out, "group %s(gid=%d) has unknown member %s\n", gr->gr_name, (int) gr->gr_gid, *cp);
239 for (dp = cp + 1; *dp; dp++)
240 if (strcmp(*cp, *dp) == 0) {
242 fprintf(out, "group %s(gid=%d) has duplicate member %s\n", gr->gr_name, (int) gr->gr_gid, *cp);
249 for (hm = homehead; hm; hm = hm->h_next)
250 if (hm->h_ngrps > NGROUPS_MAX) {
252 fprintf(out, "user %s is a member of %d groups (max %d)\n",
253 hm->h_name, hm->h_ngrps, NGROUPS_MAX);
257 if (!hit && out && !mail)
258 fprintf(out, "all group members accounted for\n");
264 { /* -DRAND not implemented at most places */
265 register int hit = 0;
266 register struct home *hm;
268 for (hm = homehead; hm; hm = hm->h_next)
269 if (getgrgid(hm->h_gid) == NULL) {
271 fprintf(out, "user %s(uid=%d) has unknown group-id %d\n", hm->h_name, (int) hm->h_uid, (int) hm->h_gid);
275 if (!hit && out && !mail)
276 fprintf(out, "all group-id users accounted for\n");
286 for (i = 0; dirs[i]; i++)
294 register int hit = 0;
295 register struct dirent *dp;
296 register DIR *dd = opendir(drop);
300 fprintf(out, "unable to open maildrop area %s\n", drop);
304 while ((dp = readdir(dd)))
305 if (dp->d_name[0] != '.' && !check(dp->d_name)) {
307 fprintf(out, "there is a maildrop for the unknown user %s in %s\n", dp->d_name, drop);
312 if (!hit && out && !mail)
313 fprintf(out, "all maildrops accounted for in %s\n", drop);
320 register struct home *hm;
322 for (hm = homehead; hm; hm = hm->h_next)
323 if (strcmp(s, hm->h_name)==0)
337 if (pipe(pd) == NOTOK)
338 adios("pipe", "unable to");
342 adios("fork", "unable to");
350 if ((fd = open("/dev/null", O_WRONLY))
356 execlp(mailproc, mhbasename(mailproc),
357 mail, "-subject", invo_name,
359 adios(mailproc, "unable to exec ");
363 out = fdopen(pd[1], "w");
364 fprintf(out, "%s: the following is suspicious\n\n", invo_name);