From e56baaffb20f20decccb658accb9f2222ef597f5 Mon Sep 17 00:00:00 2001 From: Eric Allman Date: Fri, 18 Feb 1983 20:43:05 -0800 Subject: [PATCH] Add HELO hostname verification; put in hack to print lots of info if we get an EPERM (Not owner) on a connect. SCCS-mr: usr.sbin/sendmail/src/daemon.c 183, 187 SCCS-vsn: usr.sbin/sendmail/src/daemon.c 3.49 --- usr/src/usr.sbin/sendmail/src/daemon.c | 39 +++++++++++++------------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/usr/src/usr.sbin/sendmail/src/daemon.c b/usr/src/usr.sbin/sendmail/src/daemon.c index b155446c63..680f14580d 100644 --- a/usr/src/usr.sbin/sendmail/src/daemon.c +++ b/usr/src/usr.sbin/sendmail/src/daemon.c @@ -3,7 +3,7 @@ # include #ifndef DAEMON -SCCSID(@(#)daemon.c 3.48 %G% (w/o daemon mode)); +SCCSID(@(#)daemon.c 3.49 %G% (w/o daemon mode)); #else #include @@ -11,7 +11,7 @@ SCCSID(@(#)daemon.c 3.48 %G% (w/o daemon mode)); #include #include -SCCSID(@(#)daemon.c 3.48 %G% (with daemon mode)); +SCCSID(@(#)daemon.c 3.49 %G% (with daemon mode)); /* ** DAEMON.C -- routines to use when running as a daemon. @@ -170,20 +170,16 @@ makeconnection(host, port, outfile, infile) if (host[0] == '[') { - long hid = 0; - int i, j; - register char *p = host; + long hid; + register char *p = index(host, ']'); - for (i = 3; i >= 0 && *p != ']' && *p != '\0'; i--) + if (p != NULL) { - j = 0; - while (isdigit(*++p)) - j = j * 10 + (*p - '0'); - if (*p != (i == 0 ? ']' : '.') || j > 255 || j < 0) - break; - hid |= j << ((3 - i) * 8); + *p = '\0'; + hid = inet_addr(&host[1]); + *p = ']'; } - if (i >= 0 || *p != ']' || *++p != '\0') + if (p == NULL || hid == -1) { usrerr("Invalid numeric domain spec \"%s\"", host); return (EX_NOHOST); @@ -194,7 +190,7 @@ makeconnection(host, port, outfile, infile) { register struct hostent *hp = gethostbyname(host); - if (hp == 0) + if (hp == NULL) return (EX_NOHOST); bmove(hp->h_addr, (char *) &SendmailAddress.sin_addr, hp->h_length); } @@ -251,7 +247,6 @@ makeconnection(host, port, outfile, infile) if (connect(s, &SendmailAddress, sizeof SendmailAddress, 0) < 0) #else NVMUNIX SendmailAddress.sin_family = AF_INET; - /* bind(s, &SendmailAddress, sizeof SendmailAddress, 0); */ if (connect(s, &SendmailAddress, sizeof SendmailAddress, 0) < 0) #endif NVMUNIX { @@ -274,6 +269,12 @@ makeconnection(host, port, outfile, infile) /* there are others, I'm sure..... */ return (EX_TEMPFAIL); + case EPERM: + /* why is this happening? */ + syserr("makeconnection: funny failure, addr=%lx, port=%x", + SendmailAddress.sin_addr.s_addr, SendmailAddress.sin_port); + /* explicit fall-through */ + default: return (EX_UNAVAILABLE); } @@ -303,12 +304,12 @@ myhostname(hostbuf) char hostbuf[]; { extern struct hostent *gethostbyname(); - struct hostent *hent; + struct hostent *hp; gethostname(hostbuf, sizeof hostbuf); - hent = gethostbyname(hostbuf); - if (hent != NULL) - return (hent->h_aliases); + hp = gethostbyname(hostbuf); + if (hp != NULL) + return (hp->h_aliases); else return (NULL); } -- 2.20.1