/[monit]/monit/protocols/smtp.c
ViewVC logotype

Diff of /monit/protocols/smtp.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.22 by martinp, Mon Sep 26 19:23:06 2005 UTC revision 1.23 by hauk, Wed Oct 19 00:50:38 2005 UTC
# Line 34  Line 34 
34  #include "protocol.h"  #include "protocol.h"
35    
36  /**  /**
37   *  Check the server for greeting code 220 and then send QUIT and  *  Check the server for greeting code 220 and then send QUIT and
38   *  check for code 221. If alive return TRUE, else, return FALSE.   *  check for code 221. If alive return TRUE, else, return FALSE.
39   *   *
40   *  @author Jan-Henrik Haukeland, <hauk@tildeslash.com>   *  @author Jan-Henrik Haukeland, <hauk@tildeslash.com>
# Line 45  Line 45 
45   *  @file   *  @file
46   */   */
47  int check_smtp(Socket_T s) {  int check_smtp(Socket_T s) {
48      
49    int status;    int status;
   char separator;  
50    char buf[STRLEN];    char buf[STRLEN];
51      
52    ASSERT(s);    ASSERT(s);
53      
54    /* Read (multiline) SMTP greeting */    if(!socket_readln(s, buf, sizeof(buf))) {
55    do {      log("SMTP: error receiving data -- %s\n", STRERROR);
56      if(socket_readln(s, buf, sizeof(buf)) <= 0) {      return FALSE;
57        log("SMTP: error receiving data -- %s\n", STRERROR);    }
58        return FALSE;    
59      }    Util_chomp(buf);
60      Util_chomp(buf);    
61      sscanf(buf, "%d%c%*s", &status, &separator);    sscanf(buf, "%d%*s", &status);
62      if(status != 220) {    if(status != 220) {
63        log("SMTP error: %s\n", buf);      log("SMTP error: %s\n", buf);
64        return FALSE;      return FALSE;
65      }    }
66    } while(separator == '-');    
67      /* Clear any extra data read from the server, such as banners */
68      socket_reset(s);
69        
70    /* Terminate the session */    /* Terminate the session */
71    if(socket_print(s, "QUIT\r\n") < 0) {    if(socket_print(s, "QUIT\r\n") < 0) {
72      log("SMTP: error sending data -- %s\n", STRERROR);      log("SMTP: error sending data -- %s\n", STRERROR);
73      return FALSE;      return FALSE;
74    }    }
75      
76    /* Check the reply */    /* Check the reply */
77    do {    if(socket_readln(s, buf, sizeof(buf)) <= 0) {
78      if(socket_readln(s, buf, sizeof(buf)) <= 0) {      log("SMTP: error receiving data -- %s\n", STRERROR);
79        log("SMTP: error receiving data -- %s\n", STRERROR);      return FALSE;
80        return FALSE;    }
81      }    
82      Util_chomp(buf);    Util_chomp(buf);
83      sscanf(buf, "%d%c%*s", &status, &separator);    
84      if(status != 221) {    sscanf(buf, "%d%*s", &status);
85        log("SMTP error: %s\n", buf);    if(status != 221) {
86        return FALSE;      log("SMTP error: %s\n", buf);
87      }      return FALSE;
88    } while(separator == '-');    }
89      
90    return TRUE;    return TRUE;
91        
92  }  }

Legend:
Removed from v.1.22  
changed lines
  Added in v.1.23

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26