From d916f0ca45550d1a61ddab875c93099e683c94ed Mon Sep 17 00:00:00 2001 From: Eric Allman Date: Sun, 19 Oct 1980 00:50:03 -0800 Subject: [PATCH] cleanup for dbm stuff: Error => Errors; move local host detection into parse; misc cleanup SCCS-vsn: usr.sbin/sendmail/src/version.c 1.7 SCCS-vsn: usr.sbin/sendmail/src/err.c 1.4 SCCS-vsn: usr.sbin/sendmail/src/alias.c 1.5 SCCS-vsn: usr.sbin/sendmail/src/sendmail.h 1.6 SCCS-vsn: usr.sbin/sendmail/src/parseaddr.c 1.5 SCCS-vsn: usr.sbin/sendmail/src/main.c 1.11 SCCS-vsn: usr.sbin/sendmail/src/deliver.c 1.7 --- usr/src/usr.sbin/sendmail/src/alias.c | 72 ++++++++++++++--------- usr/src/usr.sbin/sendmail/src/deliver.c | 31 ++-------- usr/src/usr.sbin/sendmail/src/err.c | 14 ++--- usr/src/usr.sbin/sendmail/src/main.c | 6 +- usr/src/usr.sbin/sendmail/src/parseaddr.c | 40 ++++++++++++- usr/src/usr.sbin/sendmail/src/sendmail.h | 5 +- usr/src/usr.sbin/sendmail/src/version.c | 2 +- 7 files changed, 101 insertions(+), 69 deletions(-) diff --git a/usr/src/usr.sbin/sendmail/src/alias.c b/usr/src/usr.sbin/sendmail/src/alias.c index 2503bcfa44..2461935903 100644 --- a/usr/src/usr.sbin/sendmail/src/alias.c +++ b/usr/src/usr.sbin/sendmail/src/alias.c @@ -3,7 +3,7 @@ # include # include "dlvrmail.h" -static char SccsId[] = "@(#)alias.c 1.4 %G%"; +static char SccsId[] = "@(#)alias.c 1.5 %G%"; /* ** ALIAS -- Compute aliases. @@ -25,7 +25,6 @@ static char SccsId[] = "@(#)alias.c 1.4 %G%"; ** ** Defined Constants: ** MAXRCRSN -- the maximum recursion depth. -** ALIASFILE -- the pathname of the alias file. ** ** Called By: ** main @@ -52,13 +51,12 @@ static char SccsId[] = "@(#)alias.c 1.4 %G%"; */ -# define ALIASFILE "/usr/lib/mailaliases" # define MAXRCRSN 10 #ifdef DBM typedef struct {char *dptr; int dsize;} datum; datum lhs, rhs; -datum fetch(); +extern datum fetch(); #endif DBM alias() @@ -168,28 +166,6 @@ alias() } if (q != NULL) { -#else DBM - /* - ** Scan SendQ - ** We pass through the queue several times. Didalias tells - ** us if we took some alias on this pass through the queue; - ** when it goes false at the top of the loop we don't have - ** to scan any more. - */ - - do - { - didalias = FALSE; - /* Scan SendQ for that canonical form. */ - for (q = &SendQ; (q = nxtinq(q)) != NULL; ) - { - lhs.dptr = q -> q_paddr; - lhs.dsize = strlen(lhs.dptr)+1; - rhs = fetch(lhs); - p = rhs.dptr; - if (p != NULL) - { -#endif /* ** Match on Alias. ** Deliver to the target list. @@ -211,9 +187,49 @@ alias() } } } while (didalias); -#ifndef DBM fclose(af); -#endif +#else DBM + /* + ** Scan SendQ + ** We only have to do this once, since anything we alias + ** two is being put at the end of the queue we are + ** scanning. + */ + + for (q = &SendQ; (q = nxtinq(q)) != NULL; ) + { + /* only alias local users */ + if (q->q_mailer != &Mailer[0]) + continue; + + /* create a key for fetch */ + lhs.dptr = q->q_user; + lhs.dsize = strlen(q->q_user) + 1; + lhs.dptr = line; + rhs = fetch(lhs); + + /* find this alias? */ + p = rhs.dptr; + if (p == NULL) + continue; + + /* + ** Match on Alias. + ** Deliver to the target list. + ** Remove the alias from the send queue + ** and put it on the Alias queue. + */ + +# ifdef DEBUG + if (Debug) + printf("%s (%s, %s) aliased to %s\n", + q->q_paddr, q->q_host, q->q_user, p); +# endif + tkoffq(q, &SendQ); + putonq(q, &AliasQ); + sendto(p, 1); + } +#endif DBM } /* ** FORWARD -- Try to forward mail diff --git a/usr/src/usr.sbin/sendmail/src/deliver.c b/usr/src/usr.sbin/sendmail/src/deliver.c index f6dc68d969..eecaf81cca 100644 --- a/usr/src/usr.sbin/sendmail/src/deliver.c +++ b/usr/src/usr.sbin/sendmail/src/deliver.c @@ -6,7 +6,7 @@ # include # endif LOG -static char SccsId[] = "@(#)deliver.c 1.6 %G%"; +static char SccsId[] = "@(#)deliver.c 1.7 %G%"; /* ** DELIVER -- Deliver a message to a particular address. @@ -81,7 +81,7 @@ deliver(to, editfcn) m = to->q_mailer; user = to->q_user; host = to->q_host; - Error = 0; + Errors = 0; errno = 0; # ifdef DEBUG if (Debug) @@ -288,7 +288,7 @@ deliver(to, editfcn) ** none. ** ** Side Effects: -** Error may be set. +** Errors may be incremented. ** ExitStat may be set. ** ** Called By: @@ -314,7 +314,7 @@ giveresponse(stat, force, m) statmsg = "ok"; else { - Error++; + Errors++; if (statmsg == NULL && m->m_badstat != 0) { stat = m->m_badstat; @@ -505,29 +505,6 @@ recipient(a, targetq) printf("recipient(%s)\n", To); # endif DEBUG - /* - ** Don't go to the net if already on the target host. - ** This is important on the berkeley network, since - ** it get confused if we ask to send to ourselves. - ** For nets like the ARPANET, we probably will have - ** the local list set to NULL to simplify testing. - ** The canonical representation of the name is also set - ** to be just the local name so the duplicate letter - ** suppression algorithm will work. - */ - - if ((pvp = m->m_local) != NULL) - { - while (*pvp != NULL) - { - if (strcmp(*pvp++, a->q_host) == 0) - { - a->q_mailer = m = &Mailer[0]; - break; - } - } - } - /* ** Look up this person in the recipient list. If they ** are there already, return, otherwise continue. diff --git a/usr/src/usr.sbin/sendmail/src/err.c b/usr/src/usr.sbin/sendmail/src/err.c index 6d86dd3ed1..80905b8658 100644 --- a/usr/src/usr.sbin/sendmail/src/err.c +++ b/usr/src/usr.sbin/sendmail/src/err.c @@ -4,10 +4,10 @@ # include # endif LOG -static char SccsId[] = "@(#)err.c 1.3 %G%"; +static char SccsId[] = "@(#)err.c 1.4 %G%"; /* -** ERR -- Print error message. +** SYSERR -- Print error message. ** ** Prints an error message via printf to the diagnostic ** output. If LOG is defined, it logs it also. @@ -20,8 +20,8 @@ static char SccsId[] = "@(#)err.c 1.3 %G%"; ** -1 always ** ** Side Effects: -** Sets Error. -** Sets ExitStat. +** increments Errors. +** sets ExitStat. */ /*VARARGS1*/ @@ -44,7 +44,7 @@ syserr(fmt, a, b, c, d, e) sprintf(p, ": error %d", errno); } printf("delivermail: %s\n", errbuf); - Error++; + Errors++; /* determine exit status if not already set */ if (ExitStat == EX_OK) @@ -73,7 +73,7 @@ syserr(fmt, a, b, c, d, e) ** -1 ** ** Side Effects: -** sets Error. +** increments Errors. */ /*VARARGS1*/ @@ -85,7 +85,7 @@ usrerr(fmt, a, b, c, d, e) if (SuprErrs) return; - Error++; + Errors++; if (To != NULL) printf("%s... ", To); printf(fmt, a, b, c, d, e); diff --git a/usr/src/usr.sbin/sendmail/src/main.c b/usr/src/usr.sbin/sendmail/src/main.c index 7b692fc041..7efde7852b 100644 --- a/usr/src/usr.sbin/sendmail/src/main.c +++ b/usr/src/usr.sbin/sendmail/src/main.c @@ -6,7 +6,7 @@ # include # endif LOG -static char SccsId[] = "@(#)main.c 1.10 %G%"; +static char SccsId[] = "@(#)main.c 1.11 %G%"; /* ** DELIVERMAIL -- Deliver mail to a set of destinations @@ -114,8 +114,8 @@ bool ForceMail; /* mail even if already sent a copy */ bool MeToo; /* send to the sender also if in a group expansion */ bool SaveFrom; /* save From lines on the front of messages */ bool IgnrDot; /* if set, ignore dot when collecting mail */ -bool Error; /* set if errors */ bool SuprErrs; /* supress errors if set */ +int Errors; /* count of errors */ char InFileName[] = "/tmp/mailtXXXXXX"; char Transcript[] = "/tmp/mailxXXXXXX"; addrq From; /* the from person */ @@ -376,7 +376,7 @@ main(argc, argv) } /* if we have had errors sofar, drop out now */ - if (Error && ExitStat == EX_OK) + if (Errors > 0 && ExitStat == EX_OK) ExitStat = EX_USAGE; if (ExitStat != EX_OK) finis(); diff --git a/usr/src/usr.sbin/sendmail/src/parseaddr.c b/usr/src/usr.sbin/sendmail/src/parseaddr.c index d897dbdc9b..d3149710ea 100644 --- a/usr/src/usr.sbin/sendmail/src/parseaddr.c +++ b/usr/src/usr.sbin/sendmail/src/parseaddr.c @@ -2,7 +2,7 @@ # include # include "dlvrmail.h" -static char SccsId[] = "@(#)parseaddr.c 1.4 %G%"; +static char SccsId[] = "@(#)parseaddr.c 1.5 %G%"; /* ** PARSE -- Parse an address @@ -61,6 +61,7 @@ parse(addr, a, copyf) bool got_one; extern char *prescan(); extern char *xalloc(); + char **pvp; /* ** Initialize and prescan address. @@ -205,6 +206,43 @@ parse(addr, a, copyf) a->q_host = buf; a->q_user = q; } + + /* + ** Don't go to the net if already on the target host. + ** This is important on the berkeley network, since + ** it get confused if we ask to send to ourselves. + ** For nets like the ARPANET, we probably will have + ** the local list set to NULL to simplify testing. + ** The canonical representation of the name is also set + ** to be just the local name so the duplicate letter + ** suppression algorithm will work. + */ + + if ((pvp = a->q_mailer->m_local) != NULL) + { + while (*pvp != NULL) + { + auto char buf2[MAXNAME]; + + strcpy(buf2, a->q_host); + if (!flagset(P_HST_UPPER, t->p_flags)) + makelower(buf2); + if (strcmp(*pvp++, buf2) == 0) + { + strcpy(buf2, a->q_user); + p = a->q_paddr; + if (parse(buf2, a, -1) == NULL) + { + To = addr; + return (NULL); + } + To = a->q_paddr = p; + break; + } + } + } + + /* make copies if specified */ if (copyf >= 0) { p = xalloc((unsigned) strlen(a->q_host) + 1); diff --git a/usr/src/usr.sbin/sendmail/src/sendmail.h b/usr/src/usr.sbin/sendmail/src/sendmail.h index 538bdc0034..70b456c447 100644 --- a/usr/src/usr.sbin/sendmail/src/sendmail.h +++ b/usr/src/usr.sbin/sendmail/src/sendmail.h @@ -3,7 +3,7 @@ ** ** Most of these are actually allocated in globals.c ** -** @(#)sendmail.h 1.5 %G% +** @(#)sendmail.h 1.6 %G% */ @@ -20,6 +20,7 @@ # define MAXFIELD 2500 /* maximum total length of a header field */ # define MAXPV 15 /* maximum # of parms to mailers */ # define MAXHOP 30 /* maximum value of HopCount */ +# define ALIASFILE "/usr/lib/aliases" /* location of alias file */ @@ -120,10 +121,10 @@ extern bool WriteBack; /* write back response on error */ extern bool NoAlias; /* if set, don't do any aliasing */ extern bool ForceMail; /* if set, mail even if already got a copy */ extern bool MeToo; /* send to the sender also */ -extern bool Error; /* set if errors */ extern bool UseMsgId; /* put msg-id's in all msgs [conf.c] */ extern bool IgnrDot; /* don't let dot end messages */ extern bool SaveFrom; /* save leading "From" lines */ +extern int Errors; /* set if errors */ extern int ExitStat; /* exit status code */ extern char InFileName[]; /* input file name */ extern char Transcript[]; /* the transcript file name */ diff --git a/usr/src/usr.sbin/sendmail/src/version.c b/usr/src/usr.sbin/sendmail/src/version.c index b50b3b72d2..44c9cdb802 100644 --- a/usr/src/usr.sbin/sendmail/src/version.c +++ b/usr/src/usr.sbin/sendmail/src/version.c @@ -1 +1 @@ -char Version[] = "@(#)Delivermail version 1.6 of %G%"; +char Version[] = "@(#)Delivermail version 1.7 of %G%"; -- 2.20.1