New upstream version 2.2

This commit is contained in:
Jan Wagner 2016-11-30 12:36:55 +01:00
parent ea115afa68
commit c845af032a
101 changed files with 4649 additions and 22969 deletions

View file

@ -59,10 +59,6 @@ enum {
#define SMTP_STARTTLS "STARTTLS\r\n"
#define SMTP_AUTH_LOGIN "AUTH LOGIN\r\n"
#ifndef HOST_MAX_BYTES
#define HOST_MAX_BYTES 255
#endif
#define EHLO_SUPPORTS_STARTTLS 1
int process_arguments (int, char **);
@ -128,6 +124,7 @@ main (int argc, char **argv)
char *cmd_str = NULL;
char *helocmd = NULL;
char *error_msg = "";
char *server_response = NULL;
struct timeval tv;
/* Catch pipe errors in read/write - sometimes occurs when writing QUIT */
@ -189,21 +186,9 @@ main (int argc, char **argv)
printf (_("recv() failed\n"));
return STATE_WARNING;
}
else {
if (verbose)
printf ("%s", buffer);
/* strip the buffer of carriage returns */
strip (buffer);
/* make sure we find the response we are looking for */
if (!strstr (buffer, server_expect)) {
if (server_port == SMTP_PORT)
printf (_("Invalid SMTP response received from host: %s\n"), buffer);
else
printf (_("Invalid SMTP response received from host on port %d: %s\n"),
server_port, buffer);
return STATE_WARNING;
}
}
/* save connect return (220 hostname ..) for later use */
xasprintf(&server_response, "%s", buffer);
/* send the HELO/EHLO command */
send(sd, helocmd, strlen(helocmd), 0);
@ -231,7 +216,7 @@ main (int argc, char **argv)
send(sd, SMTP_STARTTLS, strlen(SMTP_STARTTLS), 0);
recvlines(buffer, MAX_INPUT_BUFFER); /* wait for it */
if (!strstr (buffer, server_expect)) {
if (!strstr (buffer, SMTP_EXPECT)) {
printf (_("Server does not support STARTTLS\n"));
smtp_quit();
return STATE_UNKNOWN;
@ -239,8 +224,8 @@ main (int argc, char **argv)
result = np_net_ssl_init(sd);
if(result != STATE_OK) {
printf (_("CRITICAL - Cannot create SSL context.\n"));
np_net_ssl_cleanup();
close(sd);
np_net_ssl_cleanup();
return STATE_CRITICAL;
} else {
ssl_established = 1;
@ -276,6 +261,7 @@ main (int argc, char **argv)
# ifdef USE_OPENSSL
if ( check_cert ) {
result = np_net_ssl_check_cert(days_till_exp_warn, days_till_exp_crit);
smtp_quit();
my_close();
return result;
}
@ -283,6 +269,24 @@ main (int argc, char **argv)
}
#endif
if (verbose)
printf ("%s", buffer);
/* save buffer for later use */
xasprintf(&server_response, "%s%s", server_response, buffer);
/* strip the buffer of carriage returns */
strip (server_response);
/* make sure we find the droids we are looking for */
if (!strstr (server_response, server_expect)) {
if (server_port == SMTP_PORT)
printf (_("Invalid SMTP response received from host: %s\n"), server_response);
else
printf (_("Invalid SMTP response received from host on port %d: %s\n"),
server_port, server_response);
return STATE_WARNING;
}
if (send_mail_from) {
my_send(cmd_str, strlen(cmd_str));
if (recvlines(buffer, MAX_INPUT_BUFFER) >= 1 && verbose)
@ -581,11 +585,6 @@ process_arguments (int argc, char **argv)
usage4 (_("Timeout interval must be a positive integer"));
}
break;
case 'S':
/* starttls */
use_ssl = TRUE;
use_ehlo = TRUE;
break;
case 'D':
/* Check SSL cert validity */
#ifdef USE_OPENSSL
@ -607,9 +606,14 @@ process_arguments (int argc, char **argv)
days_till_exp_warn = atoi (optarg);
}
check_cert = TRUE;
ignore_send_quit_failure = TRUE;
#else
usage (_("SSL support not available - install OpenSSL and recompile"));
#endif
case 'S':
/* starttls */
use_ssl = TRUE;
use_ehlo = TRUE;
break;
case '4':
address_family = AF_INET;
@ -623,10 +627,10 @@ process_arguments (int argc, char **argv)
break;
case 'V': /* version */
print_revision (progname, NP_VERSION);
exit (STATE_OK);
exit (STATE_UNKNOWN);
case 'h': /* help */
print_help ();
exit (STATE_OK);
exit (STATE_UNKNOWN);
case '?': /* help */
usage5 ();
}
@ -763,10 +767,12 @@ recvlines(char *buf, size_t bufsize)
int
my_close (void)
{
int result;
result = close(sd);
#ifdef HAVE_SSL
np_net_ssl_cleanup();
np_net_ssl_cleanup();
#endif
return close(sd);
return result;
}