1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
|
#
# Patch managed by http://www.mn-logistik.de/unsupported/pxa250/patcher
#
--- libetpan/src/Makefile.in~gnutls 2005-03-10 10:11:30.000000000 +0100
+++ libetpan/src/Makefile.in 2005-03-11 21:43:10.975597607 +0100
@@ -15,7 +15,7 @@
VERSINFO = @API_VERSION@
CC = @CC@
-LDFLAGS = @LIBS@ @SSLLIBS@ @LDFLAGS@ @DBLIB@
+LDFLAGS = @LIBS@ @SSLLIBS@ @LDFLAGS@ @DBLIB@ @GNUTLSLIBS@
SUBLIBS = data-types/libdata-types.la \
low-level/liblow-level.la \
--- libetpan/src/data-types/mailstream_ssl.c~gnutls 2005-03-10 10:11:30.000000000 +0100
+++ libetpan/src/data-types/mailstream_ssl.c 2005-03-11 21:44:56.373673788 +0100
@@ -61,7 +61,12 @@
/* mailstream_low, ssl */
#ifdef USE_SSL
+#ifndef USE_GNUTLS
#include <openssl/ssl.h>
+#else
+#include <errno.h>
+#include <gnutls/openssl.h>
+#endif
#ifdef LIBETPAN_REENTRANT
#include <pthread.h>
#endif
@@ -85,9 +90,9 @@
#ifdef USE_SSL
static int mailstream_low_ssl_close(mailstream_low * s);
static ssize_t mailstream_low_ssl_read(mailstream_low * s,
- void * buf, size_t count);
+ void * buf, size_t count);
static ssize_t mailstream_low_ssl_write(mailstream_low * s,
- const void * buf, size_t count);
+ const void * buf, size_t count);
static void mailstream_low_ssl_free(mailstream_low * s);
static int mailstream_low_ssl_get_fd(mailstream_low * s);
@@ -113,10 +118,10 @@
SSL_CTX * tmp_ctx;
int fd_flags;
int old_fd_flags;
-
+
#ifdef LIBETPAN_REENTRANT
pthread_mutex_lock(&ssl_lock);
-#endif
+#endif
if (!ssl_init_done) {
SSL_library_init();
ssl_init_done = 1;
@@ -124,35 +129,37 @@
#ifdef LIBETPAN_REENTRANT
pthread_mutex_unlock(&ssl_lock);
#endif
-
+
tmp_ctx = SSL_CTX_new(TLSv1_client_method());
if (tmp_ctx == NULL)
goto err;
-
+
ssl_conn = (SSL *) SSL_new(tmp_ctx);
if (ssl_conn == NULL)
goto free_ctx;
-
+
if (SSL_set_fd(ssl_conn, fd) == 0)
goto free_ssl_conn;
-
+
+#ifndef USE_GNUTLS
SSL_set_read_ahead(ssl_conn, 1);
-
+#endif
+
r = SSL_connect(ssl_conn);
if (r <= 0)
goto free_ssl_conn;
-
+
fd_flags = fcntl(fd, F_GETFL, 0);
old_fd_flags = fd_flags;
fd_flags |= O_NDELAY;
r = fcntl(fd, F_SETFL, fd_flags);
if (r < 0)
goto free_ssl_conn;
-
+
ssl_data = malloc(sizeof(* ssl_data));
if (ssl_data == NULL)
goto reset_fd_flags;
-
+
ssl_data->fd = fd;
ssl_data->ssl_conn = ssl_conn;
ssl_data->ssl_ctx = tmp_ctx;
@@ -241,52 +248,101 @@
}
static ssize_t mailstream_low_ssl_read(mailstream_low * s,
- void * buf, size_t count)
+ void * buf, size_t count)
{
struct mailstream_ssl_data * ssl_data;
int r;
ssl_data = (struct mailstream_ssl_data *) s->data;
-
+
while (1) {
int ssl_r;
fd_set fds_read;
+#ifndef USE_GNUTLS
struct timeval timeout;
-
+#else
+ fd_set fds_excp;
+
+ {
+ struct timeval timeout2;
+ timeout2 = mailstream_network_delay;
+
+ FD_ZERO(&fds_read);
+ FD_SET(ssl_data->fd, &fds_read);
+ FD_ZERO(&fds_excp);
+ FD_SET(ssl_data->fd, &fds_excp);
+ r = select(ssl_data->fd + 1, &fds_read, NULL, &fds_excp, &timeout2);
+ if (r==0) {
+ return -1;
+ }
+ if (FD_ISSET(ssl_data->fd, &fds_excp))
+ return -1;
+ if (!FD_ISSET(ssl_data->fd, &fds_read))
+ return 0;
+ }
+#endif
r = SSL_read(ssl_data->ssl_conn, buf, count);
- if (r > 0)
+ if (r > 0) {
return r;
-
+ }
+#ifdef USE_GNUTLS
+ if (errno!=EAGAIN&&errno!=EWOULDBLOCK) {
+ return r;
+ }
+#else
ssl_r = SSL_get_error(ssl_data->ssl_conn, r);
switch (ssl_r) {
case SSL_ERROR_NONE:
return r;
-
+
case SSL_ERROR_ZERO_RETURN:
return r;
-
+
case SSL_ERROR_WANT_READ:
timeout = mailstream_network_delay;
-
+
FD_ZERO(&fds_read);
FD_SET(ssl_data->fd, &fds_read);
r = select(ssl_data->fd + 1, &fds_read, NULL, NULL, &timeout);
if (r == 0)
return -1;
break;
-
+
default:
return r;
}
+#endif
}
}
static ssize_t mailstream_low_ssl_write(mailstream_low * s,
- const void * buf, size_t count)
+ const void * buf, size_t count)
{
struct mailstream_ssl_data * ssl_data;
ssl_data = (struct mailstream_ssl_data *) s->data;
+#ifdef USE_GNUTLS
+ {
+ fd_set fds_write;
+ fd_set fds_excp;
+ struct timeval timeout;
+ int r;
+
+ timeout = mailstream_network_delay;
+
+ FD_ZERO(&fds_write);
+ FD_SET(ssl_data->fd, &fds_write);
+ FD_ZERO(&fds_excp);
+ FD_SET(ssl_data->fd, &fds_excp);
+ r = select(ssl_data->fd + 1, NULL, &fds_write, &fds_excp, &timeout);
+ if (r == 0)
+ return -1;
+ if (FD_ISSET(ssl_data->fd, &fds_excp))
+ return -1;
+ if (!FD_ISSET(ssl_data->fd, &fds_write))
+ return 0;
+ }
+#endif
return SSL_write(ssl_data->ssl_conn, buf, count);
}
#endif
|