58 |
strncpy(serv, he->h_name, SERVER_LEN - 1); |
strncpy(serv, he->h_name, SERVER_LEN - 1); |
59 |
|
|
60 |
log_info(LOG_SERVER, serv); |
log_info(LOG_SERVER, serv); |
61 |
|
|
62 |
#ifdef SSL_TLS |
#ifdef SSL_TLS |
63 |
if (protocol != SSL_DISABLED) { |
if (protocol != SSL_DISABLED) { |
64 |
ssl_init(protocol); |
ssl_init(protocol); |
70 |
#ifdef SSL_TLS |
#ifdef SSL_TLS |
71 |
} |
} |
72 |
#endif |
#endif |
73 |
|
|
74 |
|
|
75 |
return 0; |
return 0; |
76 |
} |
} |
85 |
int e; |
int e; |
86 |
SSL_CTX *ctx; |
SSL_CTX *ctx; |
87 |
SSL_METHOD *method = NULL; |
SSL_METHOD *method = NULL; |
88 |
|
|
89 |
SSL_library_init(); |
SSL_library_init(); |
90 |
|
|
91 |
switch (protocol) { |
switch (protocol) { |
92 |
case SSL_SSL_V2: |
case SSL_SSL_V2: |
93 |
method = SSLv2_client_method(); |
method = SSLv2_client_method(); |
99 |
method = TLSv1_client_method(); |
method = TLSv1_client_method(); |
100 |
break; |
break; |
101 |
} |
} |
102 |
|
|
103 |
if (!(ctx = SSL_CTX_new(method))) |
if (!(ctx = SSL_CTX_new(method))) |
104 |
return ERROR_SSL; |
return ERROR_SSL; |
105 |
|
|
106 |
if (!(ssl = SSL_new(ctx))) |
if (!(ssl = SSL_new(ctx))) |
107 |
return ERROR_SSL; |
return ERROR_SSL; |
108 |
|
|
109 |
SSL_set_fd(ssl, sock); |
SSL_set_fd(ssl, sock); |
110 |
|
|
111 |
e = SSL_connect(ssl); |
e = SSL_connect(ssl); |
112 |
|
|
113 |
if (e <= 0) { |
if (e <= 0) { |
114 |
error("imapfilter: initiating SSL connection; %s", |
error("imapfilter: initiating SSL connection; %s", |
115 |
ERR_error_string(e, NULL)); |
ERR_error_string(e, NULL)); |
116 |
return ERROR_SSL; |
return ERROR_SSL; |
117 |
} |
} |
|
|
|
118 |
SSL_CTX_free(ctx); |
SSL_CTX_free(ctx); |
119 |
|
|
120 |
return 0; |
return 0; |
131 |
if (ssl) { |
if (ssl) { |
132 |
SSL_shutdown(ssl); |
SSL_shutdown(ssl); |
133 |
SSL_free(ssl); |
SSL_free(ssl); |
|
ssl = NULL; |
|
134 |
} |
} |
135 |
#endif |
#endif |
136 |
|
|
171 |
else |
else |
172 |
#endif |
#endif |
173 |
e = read(sock, buf, RESPONSE_BUF - 1); |
e = read(sock, buf, RESPONSE_BUF - 1); |
174 |
|
|
175 |
fcntl(sock, F_SETFL, flags); |
fcntl(sock, F_SETFL, flags); |
176 |
|
|
177 |
#ifdef SSL_TLS |
#ifdef SSL_TLS |
181 |
ERR_error_string(e, NULL)); |
ERR_error_string(e, NULL)); |
182 |
} else |
} else |
183 |
#endif |
#endif |
184 |
if(e == -1) |
if (e == -1) |
185 |
fatal(ERROR_NETWORK, "imapfilter: reading data; %s", |
fatal(ERROR_NETWORK, "imapfilter: reading data; %s", |
186 |
strerror(errno)); |
strerror(errno)); |
187 |
|
|
188 |
return 0; |
return 0; |
189 |
} |
} |
|
|
|
190 |
fcntl(sock, F_SETFL, flags); |
fcntl(sock, F_SETFL, flags); |
191 |
|
|
192 |
fatal(ERROR_NETWORK, "imapfilter: waiting input from socket; %s\n", |
fatal(ERROR_NETWORK, "imapfilter: waiting input from socket; %s\n", |
215 |
if (write(sock, data, strlen(data)) == -1) |
if (write(sock, data, strlen(data)) == -1) |
216 |
fatal(ERROR_NETWORK, "imapfilter: sending data; %s", |
fatal(ERROR_NETWORK, "imapfilter: sending data; %s", |
217 |
strerror(errno)); |
strerror(errno)); |
218 |
|
|
219 |
return 0; |
return 0; |
220 |
} |
} |
|
|
|