diff -urp postfix-2.8.5.orig/src/smtpd/smtpd_check.c postfix-2.8.5/src/smtpd/smtpd_check.c --- postfix-2.8.5.orig/src/smtpd/smtpd_check.c 2011-06-16 02:31:35.000000000 +0900 +++ postfix-2.8.5/src/smtpd/smtpd_check.c 2011-09-03 07:12:28.000000000 +0900 @@ -204,6 +204,7 @@ #include #include #include +#include /* DNS library. */ @@ -3578,6 +3579,7 @@ static int generic_checks(SMTPD_STATE *s ARGV *list; int found; int saved_recursion = state->recursion++; + VSTRING *buf; if (msg_verbose) msg_info(">>> START %s RESTRICTIONS <<<", reply_class); @@ -3673,8 +3675,35 @@ static int generic_checks(SMTPD_STATE *s smtpd_check_reject(state, MAIL_ERROR_SOFTWARE, 451, "4.3.5", "Server configuration error")); - } else - sleep(atoi(*++cpp)); + } else { + /* sleep(atoi(*++cpp)); */ + int sleep_time = atoi(*++cpp); + int i; + for ( i = 0; i < sleep_time; i++ ) { + /* sleep( 1 ); */ + if ( ! read_wait(state->client->fd, 1) ) { /* read enabled */ + int ch = VSTREAM_GETC(state->client); + if (vstream_feof(state->client) || vstream_ferror(state->client)) { /* lost connection */ + vstream_ungetc(state->client, ch); + buf = vstring_alloc(100); + vstring_sprintf(buf, "lost connection after %d sec", i); + log_whatsup(state, "sleep", STR(buf)); + vstring_free(buf); + status = SMTPD_CHECK_REJECT; /* finish immediately if lost connection */ + break; + } + else { /* pipelining */ + vstream_ungetc(state->client, ch); + buf = vstring_alloc(100); + vstring_sprintf(buf, "pipelining after %d sec", i); + log_whatsup(state, "sleep", STR(buf)); + vstring_free(buf); + sleep( sleep_time - i ); + break; + } + } + } + } } else if (strcasecmp(name, REJECT_PLAINTEXT_SESSION) == 0) { status = reject_plaintext_session(state); }