~ubuntu-branches/ubuntu/saucy/monit/saucy-proposed

« back to all changes in this revision

Viewing changes to src/protocols/lmtp.c

  • Committer: Package Import Robot
  • Author(s): Sergey B Kirpichev
  • Date: 2012-09-10 14:20:52 UTC
  • mfrom: (1.1.17)
  • Revision ID: package-import@ubuntu.com-20120910142052-7hnet3ghuk10dwwm
Tags: 1:5.5-1
* Bunch of config snippets (debian/monitrc.d/*)
* Imported Upstream version 5.5
* Unfuzz patches
* Add Forwarded: dep3 headers

Show diffs side-by-side

added added

removed removed

Lines of Context:
36
36
 
37
37
 
38
38
static int do_send(Socket_T socket, char *msg) {
39
 
        
 
39
 
40
40
        if(socket_write(socket, msg, strlen(msg)) < 0) {
41
41
                socket_setError(socket, "LMTP: error sending data -- %s\n", STRERROR);
42
42
                return FALSE;
43
43
        }
44
 
        
 
44
 
45
45
        return TRUE;
46
 
        
 
46
 
47
47
}
48
48
 
49
49
 
50
50
static int expect(Socket_T socket, int expect, int log) {
51
 
        
 
51
 
52
52
        int status;
53
53
        char buf[STRLEN];
54
 
        
 
54
 
55
55
        if(!socket_readln(socket, buf, STRLEN)) {
56
56
                socket_setError(socket, "LMTP: error receiving data -- %s\n", STRERROR);
57
57
                return FALSE;
58
58
        }
59
 
        
 
59
 
60
60
        Str_chomp(buf);
61
 
        
 
61
 
62
62
        sscanf(buf, "%d%*s", &status);
63
63
        if(status != expect) {
64
64
                if(log) 
65
65
                        socket_setError(socket, "LMTP error: %s\n", buf);
66
66
                return FALSE;
67
67
        }
68
 
        
 
68
 
69
69
        return TRUE;
70
 
        
 
70
 
71
71
}
72
72
 
73
73
 
81
81
 *  @file
82
82
 */
83
83
int check_lmtp(Socket_T socket) {
84
 
    
 
84
 
85
85
  ASSERT(socket);
86
 
  
 
86
 
87
87
  if(!expect(socket, 220, TRUE))
88
88
    return FALSE;
89
 
  
 
89
 
90
90
  if (!(do_send(socket, "LHLO localhost\r\n") && expect(socket, 250, TRUE)))
91
91
      return FALSE;
92
92
 
93
93
  if(!(do_send(socket, "QUIT\r\n") && expect(socket, 221, TRUE)))
94
94
    return FALSE;
95
 
    
 
95
 
96
96
  return TRUE;
97
 
  
 
97
 
98
98
}
99
99
 
100
100