From 8b235097cbd11d728c07b966cf131aa7133ce5a9 Mon Sep 17 00:00:00 2001 From: markus schnalke Date: Mon, 26 Mar 2012 14:00:09 +0200 Subject: [PATCH] Removed conflict(8), because checking passwd, /var/mail, etc. is not our job. Conflict did check for: - duplicate users - duplicate groups - existence of group members - valid group ids - orphaned maildrops ... and by the way for valid format of alias files. The latter task can be covered by ali(1) without address arguments. All the other tasks have nothing to do with the MUA. Actually, most of them can be covered with shell one-liners. --- man/Makefile.in | 2 +- man/ali.man1 | 1 + man/conflict.man8 | 81 ------------ man/mh-alias.man5 | 2 +- man/mh-chart.man1 | 11 -- man/mmh-intro.man7 | 1 - uip/Makefile.in | 7 +- uip/conflict.c | 366 ---------------------------------------------------- 8 files changed, 5 insertions(+), 466 deletions(-) delete mode 100644 man/conflict.man8 delete mode 100644 uip/conflict.c diff --git a/man/Makefile.in b/man/Makefile.in index 47742c2..aab86f4 100644 --- a/man/Makefile.in +++ b/man/Makefile.in @@ -59,7 +59,7 @@ MAN5SRC = mh-alias. mh-format. mh-mail. mh-profile. mh-tailor. MAN7SRC = mmh-intro. mh-draft. mh-sequence. -MAN8SRC = ap. conflict. dp. fmtdump. post. +MAN8SRC = ap. dp. fmtdump. post. MAN1 = $(MAN1SRC:.=.$(manext1)) MAN5 = $(MAN5SRC:.=.$(manext5)) diff --git a/man/ali.man1 b/man/ali.man1 index b0d4712..480c363 100644 --- a/man/ali.man1 +++ b/man/ali.man1 @@ -26,6 +26,7 @@ It creates a list of addresses for those and writes that list on standard output. If no arguments are given, .B ali outputs all alias entries. +This can be used to check the format of the alias file for validity. .PP By default, when an aliases expands to multiple addresses, the addresses are separated by commas and printed on as few lines as possible. If the diff --git a/man/conflict.man8 b/man/conflict.man8 deleted file mode 100644 index ff2246c..0000000 --- a/man/conflict.man8 +++ /dev/null @@ -1,81 +0,0 @@ -.\" -.\" %nmhwarning% -.\" -.TH CONFLICT %manext8% "%nmhdate%" MH.6.8 [%nmhversion%] -.SH NAME -conflict \- search for alias/password conflicts -.SH SYNOPSIS -.HP 5 -.na -.B conflict -.RB [ \-search -.IR directory ] -.RB [ \-mail -.IR name ] -.RB [ \-version ] -.RB [ \-help ] -.RI [ aliasfiles -\&...] -.ad -.SH DESCRIPTION -.B Conflict -is a program that checks to see if the interface between -.B nmh -and the transport system is in good shape -.PP -.B Conflict -also checks for maildrops in %mailspool% which do not -belong to a valid user. It assumes that no user name will start with -`.', and thus ignores files in %mailspool% which begin with `.'. It also -checks for entries in the -.BR group (5) -file which do not belong -to a valid user, and for users who do not have a valid group number. -In addition duplicate users and groups are noted. -.PP -If the -.B \-mail -.I name -switch is used, then the results will be sent -to the specified -.IR name . -Otherwise, the results are sent to the standard output. -.PP -The -.B \-search -.I directory -switch can be used to search directories -other than %mailspool% and to report anomalies in those directories. -The -.B \-search -.I directory -switch can appear more than one time in an -invocation to -.BR conflict . -.PP -.B Conflict -should be run under -.BR cron (8), -or whenever system accounting takes place. - -.SH FILES -.fc ^ ~ -.nf -.ta \w'%etcdir%/ExtraBigFileName 'u -^/etc/passwd~^List of users -^/etc/group~^List of groups -^%bindir%/mhmail~^Program to send mail -^%mailspool%/~^Directory of mail drops -.fi - -.SH "PROFILE COMPONENTS" -None - -.SH "SEE ALSO" -mh\-alias(5) - -.SH "DEFAULTS" -None - -.SH CONTEXT -None diff --git a/man/mh-alias.man5 b/man/mh-alias.man5 index 597b155..39609f4 100644 --- a/man/mh-alias.man5 +++ b/man/mh-alias.man5 @@ -235,7 +235,7 @@ None .fi .SH "SEE ALSO" -ali(1), send(1), group(5), passwd(5), conflict(8), post(8) +ali(1), send(1), group(5), passwd(5), post(8) .SH CONTEXT None diff --git a/man/mh-chart.man1 b/man/mh-chart.man1 index 5e8a703..ef5a939 100644 --- a/man/mh-chart.man1 +++ b/man/mh-chart.man1 @@ -66,17 +66,6 @@ mh-chart \- Chart of nmh Commands .RB [ \-help ] .HP 5 -.B conflict -.RB [ \-search -.IR directory ] -.RB [ \-mail -.IR name ] -.RB [ \-version ] -.RB [ \-help ] -.RI [ aliasfiles -\&...] - -.HP 5 .B dist .RI [ +folder ] .RI [ msgs ] diff --git a/man/mmh-intro.man7 b/man/mmh-intro.man7 index dd356ed..5cd77a3 100644 --- a/man/mmh-intro.man7 +++ b/man/mmh-intro.man7 @@ -223,7 +223,6 @@ commands: ^whatnow(1)~^\- prompting front\-end for send .sp ^ap(8)~^\- parse addresses 822\-style -^conflict(8)~^\- search for alias/password conflicts ^dp(8)~^\- parse dates 822\-style ^fmtdump(8)~^\- decode \fImmh\fP format files ^post(8)~^\- deliver a message diff --git a/uip/Makefile.in b/uip/Makefile.in index e592a25..9c2d390 100644 --- a/uip/Makefile.in +++ b/uip/Makefile.in @@ -47,7 +47,7 @@ SETGID_MAIL = @SETGID_MAIL@ $(COMPILE) $< # commands to build -CMDS = ali anno burst comp conflict dist flist folder forw mmh mark \ +CMDS = ali anno burst comp dist flist folder forw mmh mark \ mhbuild mhl \ mhlist mhmail mhparam mhpath mhshow mhstore msgchk new packf pick \ print-mimetype prompter rcvdist rcvpack rcvstore refile repl rmf \ @@ -64,7 +64,7 @@ SCMDS = inc # source files SRCS = ali.c aliasbr.c anno.c ap.c burst.c comp.c \ - conflict.c dist.c distsbr.c dp.c dropsbr.c flist.c fmtdump.c \ + dist.c distsbr.c dp.c dropsbr.c flist.c fmtdump.c \ folder.c forw.c inc.c mmh.sh mark.c md5.c mhbuild.c \ mhcachesbr.c mhfree.c mhl.c mhlist.c mhlistsbr.c \ mhmail.c mhmisc.c mhoutsbr.c mhparam.c mhparse.c \ @@ -102,9 +102,6 @@ burst: burst.o $(LOCALLIBS) comp: comp.o whatnowproc.o $(LOCALLIBS) $(LINK) comp.o whatnowproc.o $(LINKLIBS) -conflict: conflict.o aliasbr.o $(LOCALLIBS) - $(LINK) conflict.o aliasbr.o $(LINKLIBS) - dist: dist.o whatnowproc.o $(LOCALLIBS) $(LINK) dist.o whatnowproc.o $(LINKLIBS) diff --git a/uip/conflict.c b/uip/conflict.c deleted file mode 100644 index 3670e8e..0000000 --- a/uip/conflict.c +++ /dev/null @@ -1,366 +0,0 @@ -/* -** conflict.c -- check for conflicts in mail system -** -** This code is Copyright (c) 2002, by the authors of nmh. See the -** COPYRIGHT file in the root directory of the nmh distribution for -** complete copyright information. -*/ - -#include -#include -#include -#include -#include -#include - -/* -** maximum number of directories that can -** be specified using -search switch. -*/ -#define NDIRS 100 - -/* -** Add space for group names, 100 at a time -*/ -#define NGRPS 100 - -static struct swit switches[] = { -#define MAILSW 0 - { "mail name", 0 }, -#define SERCHSW 1 - { "search directory", 0 }, -#define VERSIONSW 2 - { "version", 0 }, -#define HELPSW 3 - { "help", 0 }, - { NULL, 0 } -}; - -static char *mail = NULL; -static char *dirs[NDIRS]; -static FILE *out = NULL; - -extern struct aka *akahead; -extern struct home *homehead; - -/* -** prototypes -*/ -void alias_files(int, char **); -void pwd_names(void); -void grp_names(void); -void grp_members(void); -void grp_ids(void); -void maildrops(void); -void mdrop(char *); -int check(char *); -void setup(void); - - -int -main(int argc, char **argv) -{ - int akp = 0, dp = 0; - char *cp, **argp, **arguments; - char buf[BUFSIZ], *akv[50]; - -#ifdef LOCALE - setlocale(LC_ALL, ""); -#endif - invo_name = mhbasename(argv[0]); - - /* foil search of user profile/context */ - if (context_foil(NULL) == -1) - done(1); - - arguments = getarguments(invo_name, argc, argv, 0); - argp = arguments; - - while ((cp = *argp++)) { - if (*cp == '-') { - switch (smatch(++cp, switches)) { - case AMBIGSW: - ambigsw(cp, switches); - done(1); - case UNKWNSW: - adios(NULL, "-%s unknown", cp); - - case HELPSW: - snprintf(buf, sizeof(buf), "%s [switches] [aliasfiles ...]", invo_name); - print_help(buf, switches, 0); - done(1); - case VERSIONSW: - print_version(invo_name); - done(1); - - case MAILSW: - if (!(cp = *argp++) || *cp == '-') - adios(NULL, "missing argument to %s", - argp[-2]); - if (mail) - adios(NULL, "mail to one address only"); - else - mail = cp; - continue; - - case SERCHSW: - if (!(cp = *argp++) || *cp == '-') - adios(NULL, "missing argument to %s", - argp[-2]); - if (dp >= NDIRS) - adios(NULL, "more than %d directories", - NDIRS); - dirs[dp++] = cp; - continue; - } - } - akv[akp++] = cp; - } - - if (!homehead) - init_pw(); - if (!mail) - out = stdout; - dirs[dp] = NULL; - - alias_files(akp, akv); - pwd_names(); - grp_names(); - grp_members(); - grp_ids(); - maildrops(); - - done(0); - return 1; -} - - -void -alias_files(int akp, char **akv) -{ - register int i, err; - - for (i = 0; i < akp; i++) - if ((err = alias(akv[i])) != AK_OK) { - setup(); - fprintf(out, "aliasing error in %s - %s\n", akv[i], - akerror(err)); - } else if (out && !mail) - fprintf(out, "alias file %s is ok\n", akv[i]); -} - - -void -pwd_names(void) -{ - int hit = 0; - register struct home *hm, *lm; - - for (hm = homehead; hm; hm = hm->h_next) - for (lm = hm->h_next; lm; lm = lm->h_next) - if (strcmp(hm->h_name, lm->h_name) == 0) { - setup(); - fprintf(out, "duplicate user %s(uid=%d)\n", - lm->h_name, (int) lm->h_uid); - hit++; - } - - if (!hit && out && !mail) - fprintf(out, "no duplicate users\n"); -} - - -void -grp_names(void) -{ - int numgroups, maxgroups; - int i, hit = 0; - char **grps; - struct group *gr; - - /* allocate space NGRPS at a time */ - numgroups = 0; - maxgroups = NGRPS; - grps = (char **) mh_xmalloc((size_t) (maxgroups * sizeof(*grps))); - - setgrent(); - while ((gr = getgrent())) { - for (i = 0; i < numgroups; i++) - if (strcmp(grps[i], gr->gr_name)==0) { - setup(); - fprintf(out, "duplicate group %s(gid=%d)\n", - gr->gr_name, (int) gr->gr_gid); - hit++; - break; - } - if (i >= numgroups) { - if (numgroups >= maxgroups) { - maxgroups += NGRPS; - grps = (char **) mh_xrealloc(grps, - (size_t) (maxgroups * sizeof(*grps))); - } - grps[numgroups++] = getcpy(gr->gr_name); - } - } - endgrent(); - - for (i = 0; i < numgroups; i++) - free(grps[i]); - free(grps); - - if (!hit && out && !mail) - fprintf(out, "no duplicate groups\n"); -} - - -void -grp_members(void) -{ - register int hit = 0; - register char **cp, **dp; - register struct group *gr; - register struct home *hm; - - setgrent(); - while ((gr = getgrent())) { - for (cp = gr->gr_mem; *cp; cp++) { - for (hm = homehead; hm; hm = hm->h_next) - if (strcmp(*cp, hm->h_name)==0) - break; - if (hm == NULL) { - setup(); - fprintf(out, "group %s(gid=%d) has unknown member %s\n", gr->gr_name, (int) gr->gr_gid, *cp); - hit++; - } else { - hm->h_ngrps++; - } - - for (dp = cp + 1; *dp; dp++) - if (strcmp(*cp, *dp) == 0) { - setup(); - fprintf(out, "group %s(gid=%d) has duplicate member %s\n", gr->gr_name, (int) gr->gr_gid, *cp); - hit++; - } - } - } - endgrent(); - - for (hm = homehead; hm; hm = hm->h_next) - if (hm->h_ngrps > NGROUPS_MAX) { - setup(); - fprintf(out, "user %s is a member of %d groups (max %d)\n", - hm->h_name, hm->h_ngrps, NGROUPS_MAX); - hit++; - } - - if (!hit && out && !mail) - fprintf(out, "all group members accounted for\n"); -} - - -void -grp_ids(void) -{ /* -DRAND not implemented at most places */ - register int hit = 0; - register struct home *hm; - - for (hm = homehead; hm; hm = hm->h_next) - if (getgrgid(hm->h_gid) == NULL) { - setup(); - fprintf(out, "user %s(uid=%d) has unknown group-id %d\n", hm->h_name, (int) hm->h_uid, (int) hm->h_gid); - hit++; - } - - if (!hit && out && !mail) - fprintf(out, "all group-id users accounted for\n"); -} - - -void -maildrops(void) -{ - register int i; - - mdrop(mailspool); - for (i = 0; dirs[i]; i++) - mdrop(dirs[i]); -} - - -void -mdrop(char *drop) -{ - register int hit = 0; - register struct dirent *dp; - register DIR *dd = opendir(drop); - - if (!dd) { - setup(); - fprintf(out, "unable to open maildrop area %s\n", drop); - return; - } - - while ((dp = readdir(dd))) - if (dp->d_name[0] != '.' && !check(dp->d_name)) { - setup(); - fprintf(out, "there is a maildrop for the unknown user %s in %s\n", dp->d_name, drop); - hit++; - } - - closedir(dd); - if (!hit && out && !mail) - fprintf(out, "all maildrops accounted for in %s\n", drop); -} - - -int -check(char *s) -{ - register struct home *hm; - - for (hm = homehead; hm; hm = hm->h_next) - if (strcmp(s, hm->h_name)==0) - return 1; - return 0; -} - -void -setup(void) -{ - int fd, pd[2]; - - if (out) - return; - - if (mail) { - if (pipe(pd) == NOTOK) - adios("pipe", "unable to"); - - switch (fork()) { - case NOTOK: - adios("fork", "unable to"); - - case OK: - close(pd[1]); - if (pd[0] != 0) { - dup2(pd[0], 0); - close(pd[0]); - } - if ((fd = open("/dev/null", O_WRONLY)) - != NOTOK) - if (fd != 1) { - dup2(fd, 1); - close(fd); - } - execlp("mhmail", "mhmail", - mail, "-subject", invo_name, - NULL); - adios("mhmail", "unable to exec "); - - default: - close(pd[0]); - out = fdopen(pd[1], "w"); - fprintf(out, "%s: the following is suspicious\n\n", invo_name); - } - } -} -- 1.7.10.4