Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/netbsd-1-5]: src/gnu/dist/sendmail/sendmail Pull up revisions 1.5-1.8 (r...
details: https://anonhg.NetBSD.org/src/rev/0bbe1724d258
branches: netbsd-1-5
changeset: 490794:0bbe1724d258
user: he <he%NetBSD.org@localhost>
date: Fri Mar 09 17:50:18 2001 +0000
description:
Pull up revisions 1.5-1.8 (requested by itojun):
Upgrade to sendmail 8.11.3.
diffstat:
gnu/dist/sendmail/sendmail/daemon.c | 665 ++++++++++++++++++++++++-----------
1 files changed, 449 insertions(+), 216 deletions(-)
diffs (truncated from 1081 to 300 lines):
diff -r 5fcb4698fdba -r 0bbe1724d258 gnu/dist/sendmail/sendmail/daemon.c
--- a/gnu/dist/sendmail/sendmail/daemon.c Fri Mar 09 17:50:16 2001 +0000
+++ b/gnu/dist/sendmail/sendmail/daemon.c Fri Mar 09 17:50:18 2001 +0000
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1998-2000 Sendmail, Inc. and its suppliers.
+ * Copyright (c) 1998-2001 Sendmail, Inc. and its suppliers.
* All rights reserved.
* Copyright (c) 1983, 1995-1997 Eric P. Allman. All rights reserved.
* Copyright (c) 1988, 1993
@@ -16,9 +16,9 @@
#ifndef lint
# ifdef DAEMON
-static char id[] = "@(#)Id: daemon.c,v 8.401.4.14 2000/07/14 04:15:00 gshapiro Exp (with daemon mode)";
+static char id[] = "@(#)Id: daemon.c,v 8.401.4.51 2001/02/23 18:57:27 geir Exp (with daemon mode)";
# else /* DAEMON */
-static char id[] = "@(#)Id: daemon.c,v 8.401.4.14 2000/07/14 04:15:00 gshapiro Exp (without daemon mode)";
+static char id[] = "@(#)Id: daemon.c,v 8.401.4.51 2001/02/23 18:57:27 geir Exp (without daemon mode)";
# endif /* DAEMON */
#endif /* ! lint */
@@ -39,6 +39,10 @@
#if DAEMON
+# if STARTTLS
+# include <openssl/rand.h>
+# endif /* STARTTLS */
+
# include <sys/time.h>
# if IP_SRCROUTE && NETINET
@@ -158,8 +162,6 @@
# endif /* NETUNIX */
extern ENVELOPE BlankEnvelope;
-#define D(x,idx) x[idx]
-
for (idx = 0; idx < ndaemons; idx++)
{
@@ -167,6 +169,7 @@
Daemons[idx].d_firsttime = TRUE;
Daemons[idx].d_refuse_connections_until = (time_t) 0;
}
+
/*
** Try to actually open the connection.
*/
@@ -174,9 +177,11 @@
if (tTd(15, 1))
{
for (idx = 0; idx < ndaemons; idx++)
+ {
dprintf("getrequests: daemon %s: port %d\n",
Daemons[idx].d_name,
ntohs(Daemons[idx].d_port));
+ }
}
/* get a socket for the SMTP connection */
@@ -221,68 +226,126 @@
bool control = FALSE;
int save_errno;
int pipefd[2];
+ time_t timenow;
+# if STARTTLS
+ long seed;
+# endif /* STARTTLS */
+ extern bool refuseconnections __P((char *, ENVELOPE *, int));
/* see if we are rejecting connections */
(void) blocksignal(SIGALRM);
+ timenow = curtime();
+
+ /*
+ ** Use ConnRateThrottle only if the
+ ** last pass was for a connection
+ */
+
+ if (ConnRateThrottle > 0 && curdaemon >= 0)
+ {
+ static int conncnt = 0;
+ static time_t lastconn = 0;
+
+ if (timenow != lastconn)
+ {
+ lastconn = timenow;
+ conncnt = 1;
+ }
+ else if (++conncnt > ConnRateThrottle)
+ {
+ /* sleep to flatten out connection load */
+ sm_setproctitle(TRUE, e,
+ "deferring connections: %d per second",
+ ConnRateThrottle);
+ if (LogLevel >= 9)
+ sm_syslog(LOG_INFO, NOQID,
+ "deferring connections: %d per second",
+ ConnRateThrottle);
+ (void) sleep(1);
+ }
+ }
+
for (idx = 0; idx < ndaemons; idx++)
{
- if (curtime() < Daemons[idx].d_refuse_connections_until)
+ if (timenow < Daemons[idx].d_refuse_connections_until)
+ continue;
+ if (bitnset(D_DISABLE, Daemons[idx].d_flags))
continue;
if (refuseconnections(Daemons[idx].d_name, e, idx))
{
if (Daemons[idx].d_socket >= 0)
{
- /* close socket so peer fails quickly */
- (void) close(Daemons[idx].d_socket);
- Daemons[idx].d_socket = -1;
+ /* close socket so peer fails quickly */
+ (void) close(Daemons[idx].d_socket);
+ Daemons[idx].d_socket = -1;
}
/* refuse connections for next 15 seconds */
- Daemons[idx].d_refuse_connections_until = curtime() + 15;
+ Daemons[idx].d_refuse_connections_until = timenow + 15;
}
else if (Daemons[idx].d_socket < 0 ||
Daemons[idx].d_firsttime)
{
- if (!Daemons[idx].d_firsttime && LogLevel >= 9)
- sm_syslog(LOG_INFO, NOQID,
- "accepting connections again for daemon %s",
- Daemons[idx].d_name);
-
- /* arrange to (re)open the socket if needed */
- (void) opendaemonsocket(&Daemons[idx], FALSE);
- Daemons[idx].d_firsttime = FALSE;
+ if (!Daemons[idx].d_firsttime && LogLevel >= 9)
+ sm_syslog(LOG_INFO, NOQID,
+ "accepting connections again for daemon %s",
+ Daemons[idx].d_name);
+
+ /* arrange to (re)open the socket if needed */
+ (void) opendaemonsocket(&Daemons[idx], FALSE);
+ Daemons[idx].d_firsttime = FALSE;
}
}
- if (curtime() >= last_disk_space_check)
+ if (timenow >= last_disk_space_check)
{
+ bool logged = FALSE;
+
if (!enoughdiskspace(MinBlocksFree + 1, FALSE))
{
- if (!bitnset(D_ETRNONLY, Daemons[idx].d_flags))
+ for (idx = 0; idx < ndaemons; idx++)
{
- /* log only if not logged before */
- if (LogLevel >= 9)
- sm_syslog(LOG_INFO, NOQID,
- "rejecting new messages: min free: %d",
- MinBlocksFree);
- sm_setproctitle(TRUE, e,
- "rejecting new messages: min free: %d",
- MinBlocksFree);
- setbitn(D_ETRNONLY, Daemons[idx].d_flags);
+ if (!bitnset(D_ETRNONLY, Daemons[idx].d_flags))
+ {
+ /* log only if not logged before */
+ if (!logged)
+ {
+ if (LogLevel >= 9)
+ sm_syslog(LOG_INFO, NOQID,
+ "rejecting new messages: min free: %ld",
+ MinBlocksFree);
+ logged = TRUE;
+ sm_setproctitle(TRUE, e,
+ "rejecting new messages: min free: %ld",
+ MinBlocksFree);
+ }
+ setbitn(D_ETRNONLY, Daemons[idx].d_flags);
+ }
}
}
- else if (bitnset(D_ETRNONLY, Daemons[idx].d_flags))
+ else
{
- /* log only if not logged before */
- if (LogLevel >= 9)
- sm_syslog(LOG_INFO, NOQID,
- "accepting new messages (again)");
- /* title will be set below */
- clrbitn(D_ETRNONLY, Daemons[idx].d_flags);
+ for (idx = 0; idx < ndaemons; idx++)
+ {
+ if (bitnset(D_ETRNONLY, Daemons[idx].d_flags))
+ {
+ /* log only if not logged before */
+ if (!logged)
+ {
+ if (LogLevel >= 9)
+ sm_syslog(LOG_INFO, NOQID,
+ "accepting new messages (again)");
+ logged = TRUE;
+ }
+
+ /* title will be set below */
+ clrbitn(D_ETRNONLY, Daemons[idx].d_flags);
+ }
+ }
}
/* only check disk space once a minute */
- last_disk_space_check = curtime() + 60;
+ last_disk_space_check = timenow + 60;
}
# if XDEBUG
@@ -323,6 +386,7 @@
for (;;)
{
+ bool setproc = FALSE;
int highest = -1;
fd_set readfds;
struct timeval timeout;
@@ -334,10 +398,13 @@
/* wait for a connection */
if (Daemons[idx].d_socket >= 0)
{
- if (!bitnset(D_ETRNONLY, Daemons[idx].d_flags))
+ if (!setproc &&
+ !bitnset(D_ETRNONLY,
+ Daemons[idx].d_flags))
{
sm_setproctitle(TRUE, e,
"accepting connections");
+ setproc = TRUE;
}
if (Daemons[idx].d_socket > highest)
highest = Daemons[idx].d_socket;
@@ -359,6 +426,7 @@
** to 5 seconds (so it might get reopened soon),
** otherwise (all sockets open) 60.
*/
+
idx = 0;
while (idx < ndaemons && Daemons[idx].d_socket >= 0)
idx++;
@@ -371,8 +439,12 @@
t = select(highest + 1, FDSET_CAST &readfds,
NULL, NULL, &timeout);
+
+
if (DoQueueRun)
(void) runqueue(TRUE, FALSE);
+
+ curdaemon = -1;
if (t <= 0)
{
timedout = TRUE;
@@ -381,7 +453,6 @@
control = FALSE;
errno = 0;
- curdaemon = -1;
/* look "round-robin" for an active socket */
if ((idx = olddaemon + 1) >= ndaemons)
@@ -392,9 +463,29 @@
FD_ISSET(Daemons[idx].d_socket, &readfds))
{
lotherend = Daemons[idx].d_socksize;
+ memset(&RealHostAddr, '\0',
+ sizeof RealHostAddr);
t = accept(Daemons[idx].d_socket,
(struct sockaddr *)&RealHostAddr,
&lotherend);
+
+ /*
+ ** If remote side closes before
+ ** accept() finishes, sockaddr
+ ** might not be fully filled in.
+ */
+
+ if (t >= 0 &&
+ (lotherend == 0 ||
+# ifdef BSD4_4_SOCKADDR
+ RealHostAddr.sa.sa_len == 0 ||
+# endif /* BSD4_4_SOCKADDR */
+ RealHostAddr.sa.sa_family != Daemons[idx].d_addr.sa.sa_family))
+ {
+ (void) close(t);
+ t = -1;
+ errno = EINVAL;
+ }
Home |
Main Index |
Thread Index |
Old Index