From: Holger Weiss Date: Tue, 31 Jul 2007 14:47:04 +0000 (+0000) Subject: Read the response to an SMTP QUIT command before closing the socket X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=0616123167c4a3e928df6605249d94f8197666d8;p=nagiosplug.git 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 --- diff --git a/plugins/check_smtp.c b/plugins/check_smtp.c index a7a0783..8d392cc 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) {