diff options
author | Holger Weiss <hweiss@users.sourceforge.net> | 2007-07-31 14:47:04 +0000 |
---|---|---|
committer | Holger Weiss <hweiss@users.sourceforge.net> | 2007-07-31 14:47:04 +0000 |
commit | 0616123167c4a3e928df6605249d94f8197666d8 (patch) | |
tree | fff21a79c28426df8657a0af9955535f7fbd49c4 /plugins/check_smtp.c | |
parent | d18b8f5d9451b65700b9260d418bd5d245318b2c (diff) | |
download | monitoring-plugins-0616123167c4a3e928df6605249d94f8197666d8.tar.gz |
Read the response to an SMTP QUIT command before closing the socket
(noted by Dieter Hendricks on nagiosplug-help@)
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@1769 f882894a-f735-0410-b71e-b25c423dba1c
Diffstat (limited to 'plugins/check_smtp.c')
-rw-r--r-- | plugins/check_smtp.c | 31 |
1 files changed, 28 insertions, 3 deletions
diff --git a/plugins/check_smtp.c b/plugins/check_smtp.c index a7a07838..8d392cc6 100644 --- a/plugins/check_smtp.c +++ b/plugins/check_smtp.c @@ -74,6 +74,7 @@ int process_arguments (int, char **); int validate_arguments (void); void print_help (void); void print_usage (void); +void smtp_quit(void); int my_close(void); #include "regex.h" @@ -258,7 +259,7 @@ main (int argc, char **argv) if(use_ssl && ! supports_tls){ printf(_("WARNING - TLS not supported by server\n")); - send (sd, SMTP_QUIT, strlen (SMTP_QUIT), 0); + smtp_quit(); return STATE_WARNING; } @@ -270,7 +271,7 @@ main (int argc, char **argv) recv(sd,buffer, MAX_INPUT_BUFFER-1, 0); /* wait for it */ if (!strstr (buffer, server_expect)) { printf (_("Server does not support STARTTLS\n")); - send (sd, SMTP_QUIT, strlen (SMTP_QUIT), 0); + smtp_quit(); return STATE_UNKNOWN; } result = np_net_ssl_init(sd); @@ -460,7 +461,7 @@ main (int argc, char **argv) } /* tell the server we're done */ - my_send (SMTP_QUIT, strlen (SMTP_QUIT)); + smtp_quit(); /* finally close the connection */ close (sd); @@ -704,6 +705,30 @@ validate_arguments (void) } +void +smtp_quit(void) +{ + int bytes; + + my_send(SMTP_QUIT, strlen(SMTP_QUIT)); + if (verbose) + printf(_("sent %s\n"), "QUIT"); + + /* read the response but don't care about problems */ + bytes = my_recv(buffer, MAXBUF - 1); + if (verbose) { + if (bytes < 0) + printf(_("recv() failed after QUIT.")); + else if (bytes == 0) + printf(_("Connection reset by peer.")); + else { + buffer[bytes] = '\0'; + printf(_("received %s\n"), buffer); + } + } +} + + int my_close (void) { |