]>
Commit | Line | Data |
---|---|---|
6c357dee AF |
1 | diff -ruN --exclude *.orig --exclude configure cyrus-imapd-2.0.12.orig/acconfig.h cyrus-imapd-2.0.12/acconfig.h |
2 | --- cyrus-imapd-2.0.12.orig/acconfig.h Thu Apr 26 17:10:59 2001 | |
3 | +++ cyrus-imapd-2.0.12/acconfig.h Thu Apr 26 17:11:37 2001 | |
4 | @@ -111,6 +111,12 @@ | |
5 | /* do we have rlim_t? */ | |
6 | #undef HAVE_RLIM_T | |
7 | ||
8 | +/* is IPv6 enabled? */ | |
9 | +#undef INET6 | |
10 | + | |
11 | +/* Define if you have ss_family in struct sockaddr_storage. */ | |
12 | +#undef HAVE_SS_FAMILY | |
13 | + | |
14 | @BOTTOM@ | |
15 | ||
16 | #ifndef __GNUC__ | |
17 | diff -ruN --exclude *.orig --exclude configure cyrus-imapd-2.0.12.orig/aclocal.m4 cyrus-imapd-2.0.12/aclocal.m4 | |
18 | --- cyrus-imapd-2.0.12.orig/aclocal.m4 Mon Feb 19 20:57:39 2001 | |
19 | +++ cyrus-imapd-2.0.12/aclocal.m4 Thu Apr 26 17:11:37 2001 | |
20 | @@ -264,3 +264,71 @@ | |
21 | AC_SUBST(LIB_UCDSNMP) | |
22 | ]) | |
23 | ||
24 | +dnl See whether we can use IPv6 related functions | |
25 | +AC_DEFUN(IPv6_CHECK_FUNC, [ | |
26 | +changequote(, )dnl | |
27 | +ac_tr_lib=HAVE_`echo $1 | sed -e 's/[^a-zA-Z0-9_]/_/g' \ | |
28 | + -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'` | |
29 | +changequote([, ])dnl | |
30 | +AC_CHECK_FUNC($1, [dnl | |
31 | + AC_DEFINE_UNQUOTED($ac_tr_lib) | |
32 | + ac_cv_lib_socket_$1=no | |
33 | + ac_cv_lib_inet6_$1=no | |
34 | +], [dnl | |
35 | + AC_CHECK_LIB(socket, $1, [dnl | |
36 | + AC_DEFINE_UNQUOTED($ac_tr_lib) | |
37 | + LIBS="$LIBS -lsocket" | |
38 | + ac_cv_lib_inet6_$1=no | |
39 | + ], [dnl | |
40 | + AC_MSG_CHECKING([whether your system has IPv6 directory]) | |
41 | + AC_CACHE_VAL(ipv6_cv_dir, [dnl | |
42 | + for ipv6_cv_dir in /usr/local/v6 /usr/inet6 no; do | |
43 | + if test $ipv6_cv_dir = no -o -d $ipv6_cv_dir; then | |
44 | + break | |
45 | + fi | |
46 | + done])dnl | |
47 | + AC_MSG_RESULT($ipv6_cv_dir) | |
48 | + if test $ipv6_cv_dir = no; then | |
49 | + ac_cv_lib_inet6_$1=no | |
50 | + else | |
51 | + if test x$ipv6_libinet6 = x; then | |
52 | + ipv6_libinet6=no | |
53 | + SAVELDFLAGS="$LDFLAGS" | |
54 | + LDFLAGS="$LDFLAGS -L$ipv6_cv_dir/lib" | |
55 | + fi | |
56 | + AC_CHECK_LIB(inet6, $1, [dnl | |
57 | + AC_DEFINE_UNQUOTED($ac_tr_lib) | |
58 | + if test $ipv6_libinet6 = no; then | |
59 | + ipv6_libinet6=yes | |
60 | + LIBS="$LIBS -linet6" | |
61 | + fi],)dnl | |
62 | + if test $ipv6_libinet6 = no; then | |
63 | + LDFLAGS="$SAVELDFLAGS" | |
64 | + fi | |
65 | + fi])dnl | |
66 | +])dnl | |
67 | +if test $ac_cv_func_$1 = yes -o $ac_cv_lib_socket_$1 = yes \ | |
68 | + -o $ac_cv_lib_inet6_$1 = yes | |
69 | +then | |
70 | + ipv6_cv_$1=yes | |
71 | + ifelse([$2], , :, [$2]) | |
72 | +else | |
73 | + ipv6_cv_$1=no | |
74 | + ifelse([$3], , :, [$3]) | |
75 | +fi]) | |
76 | + | |
77 | +dnl See whether we have ss_family in sockaddr_storage | |
78 | +AC_DEFUN(IPv6_CHECK_SS_FAMILY, [ | |
79 | +AC_MSG_CHECKING([whether you have ss_family in struct sockaddr_storage]) | |
80 | +AC_CACHE_VAL(ipv6_cv_ss_family, [dnl | |
81 | +AC_TRY_COMPILE([#include <sys/types.h> | |
82 | +#include <sys/socket.h>], | |
83 | + [struct sockaddr_storage ss; int i = ss.ss_family;], | |
84 | + [ipv6_cv_ss_family=yes], [ipv6_cv_ss_family=no])])dnl | |
85 | +if test $ipv6_cv_ss_family = yes; then | |
86 | + ifelse([$1], , AC_DEFINE(HAVE_SS_FAMILY), [$1]) | |
87 | +else | |
88 | + ifelse([$2], , :, [$2]) | |
89 | +fi | |
90 | +AC_MSG_RESULT($ipv6_cv_ss_family)]) | |
91 | + | |
92 | diff -ruN --exclude *.orig --exclude configure cyrus-imapd-2.0.12.orig/config.h.in cyrus-imapd-2.0.12/config.h.in | |
93 | --- cyrus-imapd-2.0.12.orig/config.h.in Mon Feb 19 20:57:39 2001 | |
94 | +++ cyrus-imapd-2.0.12/config.h.in Thu Apr 26 17:11:37 2001 | |
95 | @@ -128,6 +128,12 @@ | |
96 | /* do we have rlim_t? */ | |
97 | #undef HAVE_RLIM_T | |
98 | ||
99 | +/* is IPv6 enabled? */ | |
100 | +#undef INET6 | |
101 | + | |
102 | +/* Define if you have ss_family in struct sockaddr_storage. */ | |
103 | +#undef HAVE_SS_FAMILY | |
104 | + | |
105 | /* Define if you have the ftruncate function. */ | |
106 | #undef HAVE_FTRUNCATE | |
107 | ||
108 | diff -ruN --exclude *.orig --exclude configure cyrus-imapd-2.0.12.orig/configure.in cyrus-imapd-2.0.12/configure.in | |
109 | --- cyrus-imapd-2.0.12.orig/configure.in Thu Apr 26 17:10:59 2001 | |
110 | +++ cyrus-imapd-2.0.12/configure.in Thu Apr 26 17:11:37 2001 | |
111 | @@ -725,6 +725,15 @@ | |
112 | ||
113 | LIBS="$LIBS ${LIB_SOCKET}" | |
114 | ||
115 | +AC_ARG_ENABLE(ipv6, [ --disable-ipv6 Don't compile in IPv6 support], | |
116 | + ipv6="$enableval", ipv6="yes") | |
117 | +if test "$ipv6" != "yes"; then | |
118 | + AC_MSG_RESULT(IPv6 support is disabled) | |
119 | +else | |
120 | + IPv6_CHECK_FUNC(getaddrinfo, AC_DEFINE(INET6)) | |
121 | + IPv6_CHECK_SS_FAMILY() | |
122 | +fi | |
123 | + | |
124 | # Figure out what directories we're linking against. | |
125 | # Lots of fun for the whole family. | |
126 | # This probably chokes on anything with spaces in it. | |
127 | diff -ruN --exclude *.orig --exclude configure cyrus-imapd-2.0.12.orig/imap/fud.c cyrus-imapd-2.0.12/imap/fud.c | |
128 | --- cyrus-imapd-2.0.12.orig/imap/fud.c Thu Apr 26 17:10:59 2001 | |
129 | +++ cyrus-imapd-2.0.12/imap/fud.c Thu Apr 26 17:11:37 2001 | |
130 | @@ -83,12 +83,21 @@ | |
131 | extern char *optarg; | |
132 | ||
133 | /* forward decls */ | |
134 | +#ifdef INET6 | |
135 | +int handle_request(const char *who, const char *name, | |
136 | + struct sockaddr_storage sfrom); | |
137 | + | |
138 | +void send_reply(struct sockaddr_storage sfrom, int status, | |
139 | + const char *user, const char *mbox, | |
140 | + int numrecent, time_t lastread, time_t lastarrived); | |
141 | +#else | |
142 | int handle_request(const char *who, const char *name, | |
143 | struct sockaddr_in sfrom); | |
144 | ||
145 | void send_reply(struct sockaddr_in sfrom, int status, | |
146 | const char *user, const char *mbox, | |
147 | int numrecent, time_t lastread, time_t lastarrived); | |
148 | +#endif | |
149 | ||
150 | int soc; | |
151 | ||
152 | @@ -104,7 +113,11 @@ | |
153 | ||
154 | int begin_handling(void) | |
155 | { | |
156 | +#ifdef INET6 | |
157 | + struct sockaddr_storage sfrom; | |
158 | +#else | |
159 | struct sockaddr_in sfrom; | |
160 | +#endif | |
161 | socklen_t sfromsiz = sizeof(sfrom); | |
162 | int r; | |
163 | char buf[MAXLOGNAME + MAX_MAILBOX_NAME + 1]; | |
164 | @@ -190,8 +203,13 @@ | |
165 | shut_down(0); | |
166 | } | |
167 | ||
168 | +#ifdef INET6 | |
169 | +int handle_request(const char *who, const char *name, | |
170 | + struct sockaddr_storage sfrom) | |
171 | +#else | |
172 | int handle_request(const char *who, const char *name, | |
173 | struct sockaddr_in sfrom) | |
174 | +#endif | |
175 | { | |
176 | int r; | |
177 | struct mailbox mailbox; | |
178 | @@ -277,9 +295,15 @@ | |
179 | } | |
180 | ||
181 | void | |
182 | +#ifdef INET6 | |
183 | +send_reply(struct sockaddr_storage sfrom, int status, | |
184 | + const char *user, const char *mbox, | |
185 | + int numrecent, time_t lastread, time_t lastarrived) | |
186 | +#else | |
187 | send_reply(struct sockaddr_in sfrom, int status, | |
188 | const char *user, const char *mbox, | |
189 | int numrecent, time_t lastread, time_t lastarrived) | |
190 | +#endif | |
191 | { | |
192 | char buf[MAX_MAILBOX_PATH + 16 + 9]; | |
193 | int siz; | |
194 | diff -ruN --exclude *.orig --exclude configure cyrus-imapd-2.0.12.orig/imap/imapd.c cyrus-imapd-2.0.12/imap/imapd.c | |
195 | --- cyrus-imapd-2.0.12.orig/imap/imapd.c Thu Apr 26 17:10:59 2001 | |
196 | +++ cyrus-imapd-2.0.12/imap/imapd.c Thu Apr 26 17:18:32 2001 | |
197 | @@ -93,6 +93,15 @@ | |
198 | #include "tls.h" | |
199 | #endif /* HAVE_SSL */ | |
200 | ||
201 | +#ifdef INET6 | |
202 | +#ifndef NI_WITHSCOPEID | |
203 | +#define NI_WITHSCOPEID 0 | |
204 | +#endif | |
205 | +#ifndef HAVE_SS_FAMILY | |
206 | +#define ss_family __ss_family | |
207 | +#endif | |
208 | +#endif | |
209 | + | |
210 | extern int optind; | |
211 | extern char *optarg; | |
212 | extern int errno; | |
213 | @@ -102,7 +111,11 @@ | |
214 | ||
215 | /* per-user/session state */ | |
216 | struct protstream *imapd_out, *imapd_in; | |
217 | +#ifdef INET6 | |
218 | +static char imapd_clienthost[NI_MAXHOST*2+1] = "[local]"; | |
219 | +#else | |
220 | static char imapd_clienthost[250] = "[local]"; | |
221 | +#endif | |
222 | static time_t imapd_logtime; | |
223 | static int imapd_logfd = -1; | |
224 | char *imapd_userid; | |
225 | @@ -457,7 +470,12 @@ | |
226 | int timeout; | |
227 | sasl_security_properties_t *secprops = NULL; | |
228 | sasl_external_properties_t extprops; | |
229 | +#ifdef INET6 | |
230 | + struct sockaddr_storage imapd_localaddr, imapd_remoteaddr; | |
231 | + char hbuf[NI_MAXHOST]; | |
232 | +#else | |
233 | struct sockaddr_in imapd_localaddr, imapd_remoteaddr; | |
234 | +#endif | |
235 | int imapd_haveaddr = 0; | |
236 | ||
237 | signals_poll(); | |
238 | @@ -493,6 +511,28 @@ | |
239 | ||
240 | /* Find out name of client host */ | |
241 | salen = sizeof(imapd_remoteaddr); | |
242 | +#ifdef INET6 | |
243 | + if (getpeername(0, (struct sockaddr *)&imapd_remoteaddr, &salen) == 0 && | |
244 | + (imapd_remoteaddr.ss_family == AF_INET || | |
245 | + imapd_remoteaddr.ss_family == AF_INET6)) { | |
246 | + if (getnameinfo((struct sockaddr *)&imapd_remoteaddr, salen, | |
247 | + hbuf, sizeof(hbuf), NULL, 0, NI_NAMEREQD) == 0) { | |
248 | + strncpy(imapd_clienthost, hbuf, sizeof(hbuf)); | |
249 | + } | |
250 | + else { | |
251 | + imapd_clienthost[0] = '\0'; | |
252 | + } | |
253 | + getnameinfo((struct sockaddr *)&imapd_remoteaddr, salen, hbuf, | |
254 | + sizeof(hbuf), NULL, 0, NI_NUMERICHOST | NI_WITHSCOPEID); | |
255 | + strcat(imapd_clienthost, "["); | |
256 | + strcat(imapd_clienthost, hbuf); | |
257 | + strcat(imapd_clienthost, "]"); | |
258 | + salen = sizeof(imapd_localaddr); | |
259 | + if (getsockname(0, (struct sockaddr *)&imapd_localaddr, &salen) == 0) { | |
260 | + imapd_haveaddr = 1; | |
261 | + } | |
262 | + } | |
263 | +#else | |
264 | if (getpeername(0, (struct sockaddr *)&imapd_remoteaddr, &salen) == 0 && | |
265 | imapd_remoteaddr.sin_family == AF_INET) { | |
266 | hp = gethostbyaddr((char *)&imapd_remoteaddr.sin_addr, | |
267 | @@ -511,6 +551,7 @@ | |
268 | imapd_haveaddr = 1; | |
269 | } | |
270 | } | |
271 | +#endif | |
272 | ||
273 | /* create the SASL connection */ | |
274 | if (sasl_server_new("imap", config_servername, | |
275 | diff -ruN --exclude *.orig --exclude configure cyrus-imapd-2.0.12.orig/imap/lmtpengine.c cyrus-imapd-2.0.12/imap/lmtpengine.c | |
276 | --- cyrus-imapd-2.0.12.orig/imap/lmtpengine.c Thu Apr 26 17:10:59 2001 | |
277 | +++ cyrus-imapd-2.0.12/imap/lmtpengine.c Thu Apr 26 17:11:38 2001 | |
278 | @@ -85,6 +85,15 @@ | |
279 | ||
280 | #define RCPT_GROW 30 | |
281 | ||
282 | +#ifdef INET6 | |
283 | +#ifndef NI_WITHSCOPEID | |
284 | +#define NI_WITHSCOPEID 0 | |
285 | +#endif | |
286 | +#ifndef HAVE_SS_FAMILY | |
287 | +#define ss_family __ss_family | |
288 | +#endif | |
289 | +#endif | |
290 | + | |
291 | /* data per message */ | |
292 | struct Header { | |
293 | char *name; | |
294 | @@ -965,7 +974,11 @@ | |
295 | int r; | |
296 | char *err; | |
297 | ||
298 | +#ifdef INET6 | |
299 | + struct sockaddr_storage localaddr, remoteaddr; | |
300 | +#else | |
301 | struct sockaddr_in localaddr, remoteaddr; | |
302 | +#endif | |
303 | socklen_t salen; | |
304 | ||
305 | sasl_conn_t *conn = NULL; | |
306 | @@ -977,6 +990,9 @@ | |
307 | 1: did AUTH */ | |
308 | char *authuser = NULL; | |
309 | struct auth_state *authstate = NULL; | |
310 | +#ifdef INET6 | |
311 | + char hbuf[NI_MAXHOST]; | |
312 | +#endif | |
313 | ||
314 | msg_new(&msg); | |
315 | if (sasl_server_new("lmtp", NULL, NULL, NULL, 0, &conn) != SASL_OK) { | |
316 | @@ -994,7 +1010,13 @@ | |
317 | /* determine who we're talking to */ | |
318 | salen = sizeof(remoteaddr); | |
319 | r = getpeername(fd, (struct sockaddr *)&remoteaddr, &salen); | |
320 | - if (!r && remoteaddr.sin_family == AF_INET) { | |
321 | + if (!r && | |
322 | +#ifdef INET6 | |
323 | + (remoteaddr.ss_family == AF_INET || remoteaddr.ss_family == AF_INET6) | |
324 | +#else | |
325 | + remoteaddr.sin_family == AF_INET | |
326 | +#endif | |
327 | + ) { | |
328 | /* connected to an internet socket */ | |
329 | ||
330 | salen = sizeof(localaddr); | |
331 | @@ -1006,9 +1028,16 @@ | |
332 | fatal("can't get local addr", EC_SOFTWARE); | |
333 | } | |
334 | ||
335 | +#ifdef INET6 | |
336 | + getnameinfo((struct sockaddr *)&remoteaddr, salen, hbuf, sizeof(hbuf), | |
337 | + NULL, 0, NI_NUMERICHOST | NI_WITHSCOPEID); | |
338 | + syslog(LOG_DEBUG, "connection from [%s]%s", hbuf, | |
339 | + func->preauth ? " preauth'd as postman" : ""); | |
340 | +#else | |
341 | syslog(LOG_DEBUG, "connection from [%s]%s", | |
342 | inet_ntoa(remoteaddr.sin_addr), | |
343 | func->preauth ? " preauth'd as postman" : ""); | |
344 | +#endif | |
345 | } else { | |
346 | /* we're not connected to a internet socket! */ | |
347 | func->preauth = 1; | |
348 | @@ -1139,20 +1168,37 @@ | |
349 | ||
350 | if (in) { free(in); in = NULL; } | |
351 | if (out) { free(out); out = NULL; } | |
352 | +#ifdef INET6 | |
353 | + if (remoteaddr.ss_family == AF_INET || | |
354 | + remoteaddr.ss_family == AF_INET6) | |
355 | + getnameinfo((struct sockaddr *)&remoteaddr, salen, | |
356 | + hbuf, sizeof(hbuf), NULL, 0, | |
357 | + NI_NUMERICHOST | NI_WITHSCOPEID); | |
358 | + else | |
359 | + strcpy(hbuf, "[unix socket]"); | |
360 | +#endif | |
361 | if ((r != SASL_OK) && (r != SASL_CONTINUE)) { | |
362 | if (errstr) { | |
363 | syslog(LOG_ERR, "badlogin: %s %s %s [%s]", | |
364 | +#ifdef INET6 | |
365 | + hbuf, | |
366 | +#else | |
367 | remoteaddr.sin_family == AF_INET ? | |
368 | inet_ntoa(remoteaddr.sin_addr) : | |
369 | "[unix socket]", | |
370 | +#endif | |
371 | mech, | |
372 | sasl_errstring(r, NULL, NULL), | |
373 | errstr); | |
374 | } else { | |
375 | syslog(LOG_ERR, "badlogin: %s %s %s", | |
376 | +#ifdef INET6 | |
377 | + hbuf, | |
378 | +#else | |
379 | remoteaddr.sin_family == AF_INET ? | |
380 | inet_ntoa(remoteaddr.sin_addr) : | |
381 | "[unix socket]", | |
382 | +#endif | |
383 | mech, | |
384 | sasl_errstring(r, NULL, NULL)); | |
385 | } | |
386 | @@ -1173,9 +1219,13 @@ | |
387 | VARIABLE_AUTH, hash_simple(mech), | |
388 | VARIABLE_LISTEND); | |
389 | syslog(LOG_NOTICE, "login: %s %s %s %s", | |
390 | +#ifdef INET6 | |
391 | + hbuf, | |
392 | +#else | |
393 | remoteaddr.sin_family == AF_INET ? | |
394 | inet_ntoa(remoteaddr.sin_addr) : | |
395 | "[unix socket]", | |
396 | +#endif | |
397 | user, mech, "User logged in"); | |
398 | ||
399 | authenticated += 2; | |
400 | @@ -1595,18 +1645,59 @@ | |
401 | free(host); | |
402 | host = xstrdup(config_servername); | |
403 | } else { | |
404 | +#ifdef INET6 | |
405 | + struct addrinfo hints, *res0 = NULL, *res; | |
406 | + int err; | |
407 | +#else | |
408 | struct hostent *hp; | |
409 | struct sockaddr_in addr; | |
410 | struct servent *service; | |
411 | +#endif | |
412 | char *p; | |
413 | ||
414 | +#ifdef INET6 | |
415 | + if (*host == '[' && (p = strchr(host + 1, ']')) != NULL && | |
416 | + (*++p == '\0' || *p == ':')) { | |
417 | + host++; | |
418 | + *(p - 1) = '\0'; | |
419 | + if (*p != ':') | |
420 | + p = NULL; | |
421 | + } else | |
422 | + p = strchr(host, ':'); | |
423 | +#else | |
424 | p = strchr(host, ':'); | |
425 | +#endif | |
426 | if (p) { | |
427 | *p++ = '\0'; | |
428 | } else { | |
429 | p = "lmtp"; | |
430 | } | |
431 | ||
432 | +#ifdef INET6 | |
433 | + memset(&hints, 0, sizeof(hints)); | |
434 | + hints.ai_family = PF_UNSPEC; | |
435 | + hints.ai_socktype = SOCK_STREAM; | |
436 | + err = getaddrinfo(host, p, &hints, &res0); | |
437 | + if (err) { | |
438 | + syslog(LOG_ERR, "getaddrinfo(%s, %s) failed: %s", | |
439 | + host, p, gai_strerror(err)); | |
440 | + goto donesock; | |
441 | + } | |
442 | + for (res = res0; res; res = res->ai_next) { | |
443 | + sock = socket(res->ai_family, res->ai_socktype, res->ai_protocol); | |
444 | + if (sock < 0) | |
445 | + continue; | |
446 | + if (connect(sock, res->ai_addr, res->ai_addrlen) >= 0) | |
447 | + break; | |
448 | + close(sock); | |
449 | + sock = -1; | |
450 | + } | |
451 | + freeaddrinfo(res0); | |
452 | + if (sock < 0) { | |
453 | + syslog(LOG_ERR, "connect(%s:%s) failed: %m", host, p); | |
454 | + goto donesock; | |
455 | + } | |
456 | +#else | |
457 | if ((hp = gethostbyname(host)) == NULL) { | |
458 | syslog(LOG_ERR, "gethostbyname(%s) failed", host); | |
459 | goto donesock; | |
460 | @@ -1636,6 +1727,7 @@ | |
461 | syslog(LOG_ERR, "connect(%s:%s) failed: %m", host, p); | |
462 | goto donesock; | |
463 | } | |
464 | +#endif | |
465 | } | |
466 | ||
467 | donesock: | |
468 | diff -ruN --exclude *.orig --exclude configure cyrus-imapd-2.0.12.orig/imap/pop3d.c cyrus-imapd-2.0.12/imap/pop3d.c | |
469 | --- cyrus-imapd-2.0.12.orig/imap/pop3d.c Thu Apr 26 17:10:59 2001 | |
470 | +++ cyrus-imapd-2.0.12/imap/pop3d.c Thu Apr 26 17:11:38 2001 | |
471 | @@ -93,6 +93,15 @@ | |
472 | #endif /* HAVE_KRB */ | |
473 | static int kflag = 0; | |
474 | ||
475 | +#ifdef INET6 | |
476 | +#ifndef NI_WITHSCOPEID | |
477 | +#define NI_WITHSCOPEID 0 | |
478 | +#endif | |
479 | +#ifndef HAVE_SS_FAMILY | |
480 | +#define ss_family __ss_family | |
481 | +#endif | |
482 | +#endif | |
483 | + | |
484 | extern int optind; | |
485 | extern char *optarg; | |
486 | extern int opterr; | |
487 | @@ -109,9 +118,17 @@ | |
488 | ||
489 | char *popd_userid = 0; | |
490 | struct mailbox *popd_mailbox = 0; | |
491 | +#ifdef INET6 | |
492 | +struct sockaddr_storage popd_localaddr, popd_remoteaddr; | |
493 | +#else | |
494 | struct sockaddr_in popd_localaddr, popd_remoteaddr; | |
495 | +#endif | |
496 | int popd_haveaddr = 0; | |
497 | +#ifdef INET6 | |
498 | +char popd_clienthost[NI_MAXHOST*2+1] = "[local]"; | |
499 | +#else | |
500 | char popd_clienthost[250] = "[local]"; | |
501 | +#endif | |
502 | struct protstream *popd_out, *popd_in; | |
503 | unsigned popd_exists = 0; | |
504 | unsigned popd_highest; | |
505 | @@ -209,6 +226,9 @@ | |
506 | struct hostent *hp; | |
507 | int timeout; | |
508 | sasl_security_properties_t *secprops=NULL; | |
509 | +#ifdef INET6 | |
510 | + char hbuf[NI_MAXHOST]; | |
511 | +#endif | |
512 | ||
513 | signals_poll(); | |
514 | ||
515 | @@ -239,6 +259,28 @@ | |
516 | ||
517 | /* Find out name of client host */ | |
518 | salen = sizeof(popd_remoteaddr); | |
519 | +#ifdef INET6 | |
520 | + if (getpeername(0, (struct sockaddr *)&popd_remoteaddr, &salen) == 0 && | |
521 | + (popd_remoteaddr.ss_family == AF_INET || | |
522 | + popd_remoteaddr.ss_family == AF_INET6)) { | |
523 | + if (getnameinfo((struct sockaddr *)&popd_remoteaddr, salen, | |
524 | + hbuf, sizeof(hbuf), NULL, 0, NI_NAMEREQD) == 0) { | |
525 | + strncpy(popd_clienthost, hbuf, sizeof(hbuf)); | |
526 | + } | |
527 | + else { | |
528 | + popd_clienthost[0] = '\0'; | |
529 | + } | |
530 | + getnameinfo((struct sockaddr *)&popd_remoteaddr, salen, hbuf, | |
531 | + sizeof(hbuf), NULL, 0, NI_NUMERICHOST | NI_WITHSCOPEID); | |
532 | + strcat(popd_clienthost, "["); | |
533 | + strcat(popd_clienthost, hbuf); | |
534 | + strcat(popd_clienthost, "]"); | |
535 | + salen = sizeof(popd_localaddr); | |
536 | + if (getsockname(0, (struct sockaddr *)&popd_localaddr, &salen) == 0) { | |
537 | + popd_haveaddr = 1; | |
538 | + } | |
539 | + } | |
540 | +#else | |
541 | if (getpeername(0, (struct sockaddr *)&popd_remoteaddr, &salen) == 0 && | |
542 | popd_remoteaddr.sin_family == AF_INET) { | |
543 | hp = gethostbyaddr((char *)&popd_remoteaddr.sin_addr, | |
544 | @@ -257,6 +299,7 @@ | |
545 | popd_haveaddr = 1; | |
546 | } | |
547 | } | |
548 | +#endif | |
549 | ||
550 | /* other params should be filled in */ | |
551 | if (sasl_server_new("pop", config_servername, NULL, | |
552 | diff -ruN --exclude *.orig --exclude configure cyrus-imapd-2.0.12.orig/imap/pop3proxyd.c cyrus-imapd-2.0.12/imap/pop3proxyd.c | |
553 | --- cyrus-imapd-2.0.12.orig/imap/pop3proxyd.c Thu Apr 26 17:10:59 2001 | |
554 | +++ cyrus-imapd-2.0.12/imap/pop3proxyd.c Thu Apr 26 17:11:38 2001 | |
555 | @@ -91,6 +91,15 @@ | |
556 | #endif /* HAVE_KRB */ | |
557 | static int kflag = 0; | |
558 | ||
559 | +#ifdef INET6 | |
560 | +#ifndef NI_WITHSCOPEID | |
561 | +#define NI_WITHSCOPEID 0 | |
562 | +#endif | |
563 | +#ifndef HAVE_SS_FAMILY | |
564 | +#define ss_family __ss_family | |
565 | +#endif | |
566 | +#endif | |
567 | + | |
568 | extern int optind; | |
569 | extern char *optarg; | |
570 | extern int opterr; | |
571 | @@ -106,9 +115,17 @@ | |
572 | sasl_conn_t *popd_saslconn; /* the sasl connection context */ | |
573 | ||
574 | char *popd_userid = 0; | |
575 | +#ifdef INET6 | |
576 | +struct sockaddr_storage popd_localaddr, popd_remoteaddr; | |
577 | +#else | |
578 | struct sockaddr_in popd_localaddr, popd_remoteaddr; | |
579 | +#endif | |
580 | int popd_haveaddr = 0; | |
581 | +#ifdef INET6 | |
582 | +char popd_clienthost[NI_MAXHOST*2+1] = "[local]"; | |
583 | +#else | |
584 | char popd_clienthost[250] = "[local]"; | |
585 | +#endif | |
586 | struct protstream *popd_out, *popd_in; | |
587 | int popd_starttls_done = 0; | |
588 | int popd_auth_done = 0; | |
589 | @@ -193,6 +210,9 @@ | |
590 | struct hostent *hp; | |
591 | int timeout; | |
592 | sasl_security_properties_t *secprops=NULL; | |
593 | +#ifdef INET6 | |
594 | + char hbuf[NI_MAXHOST]; | |
595 | +#endif | |
596 | ||
597 | signals_poll(); | |
598 | ||
599 | @@ -221,6 +241,28 @@ | |
600 | ||
601 | /* Find out name of client host */ | |
602 | salen = sizeof(popd_remoteaddr); | |
603 | +#ifdef INET6 | |
604 | + if (getpeername(0, (struct sockaddr *)&popd_remoteaddr, &salen) == 0 && | |
605 | + (popd_remoteaddr.ss_family == AF_INET || | |
606 | + popd_remoteaddr.ss_family == AF_INET6)) { | |
607 | + if (getnameinfo((struct sockaddr *)&popd_remoteaddr, salen, | |
608 | + hbuf, sizeof(hbuf), NULL, 0, NI_NAMEREQD) == 0) { | |
609 | + strncpy(popd_clienthost, hbuf, sizeof(hbuf)); | |
610 | + } | |
611 | + else { | |
612 | + popd_clienthost[0] = '\0'; | |
613 | + } | |
614 | + getnameinfo((struct sockaddr *)&popd_remoteaddr, salen, hbuf, | |
615 | + sizeof(hbuf), NULL, 0, NI_NUMERICHOST | NI_WITHSCOPEID); | |
616 | + strcat(popd_clienthost, "["); | |
617 | + strcat(popd_clienthost, hbuf); | |
618 | + strcat(popd_clienthost, "]"); | |
619 | + salen = sizeof(popd_localaddr); | |
620 | + if (getsockname(0, (struct sockaddr *)&popd_localaddr, &salen) == 0) { | |
621 | + popd_haveaddr = 1; | |
622 | + } | |
623 | + } | |
624 | +#else | |
625 | if (getpeername(0, (struct sockaddr *)&popd_remoteaddr, &salen) == 0 && | |
626 | popd_remoteaddr.sin_family == AF_INET) { | |
627 | hp = gethostbyaddr((char *)&popd_remoteaddr.sin_addr, | |
628 | @@ -239,6 +281,7 @@ | |
629 | popd_haveaddr = 1; | |
630 | } | |
631 | } | |
632 | +#endif | |
633 | ||
634 | /* other params should be filled in */ | |
635 | if (sasl_server_new("pop", config_servername, NULL, | |
636 | @@ -1023,11 +1066,19 @@ | |
637 | { | |
638 | int r; | |
639 | sasl_security_properties_t *secprops = NULL; | |
640 | +#ifdef INET6 | |
641 | + struct sockaddr *saddr_l = | |
642 | + (struct sockaddr *) malloc(sizeof(struct sockaddr_storage)); | |
643 | + struct sockaddr *saddr_r = | |
644 | + (struct sockaddr *) malloc(sizeof(struct sockaddr_storage)); | |
645 | + socklen_t addrsize = sizeof(struct sockaddr_storage); | |
646 | +#else | |
647 | struct sockaddr_in *saddr_l = | |
648 | (struct sockaddr_in *) malloc(sizeof(struct sockaddr_in)); | |
649 | struct sockaddr_in *saddr_r = | |
650 | (struct sockaddr_in *) malloc(sizeof(struct sockaddr_in)); | |
651 | socklen_t addrsize = sizeof(struct sockaddr_in); | |
652 | +#endif | |
653 | sasl_callback_t *cb; | |
654 | char buf[2048]; | |
655 | char optstr[128]; | |
656 | @@ -1064,7 +1115,11 @@ | |
657 | r = sasl_setprop(backend_saslconn, SASL_IP_REMOTE, saddr_r); | |
658 | if (r != SASL_OK) return r; | |
659 | ||
660 | +#ifdef INET6 | |
661 | + addrsize=sizeof(struct sockaddr_storage); | |
662 | +#else | |
663 | addrsize=sizeof(struct sockaddr_in); | |
664 | +#endif | |
665 | if (getsockname(backend_sock, (struct sockaddr *)saddr_l,&addrsize)!=0) | |
666 | return SASL_FAIL; | |
667 | r = sasl_setprop(backend_saslconn, SASL_IP_LOCAL, saddr_l); | |
668 | @@ -1136,8 +1191,12 @@ | |
669 | ||
670 | static void openproxy(void) | |
671 | { | |
672 | +#ifdef INET6 | |
673 | + struct addrinfo hints, *res0 = NULL, *res; | |
674 | +#else | |
675 | struct hostent *hp; | |
676 | struct sockaddr_in sin; | |
677 | +#endif | |
678 | char inboxname[MAX_MAILBOX_PATH]; | |
679 | int r; | |
680 | char *server; | |
681 | @@ -1148,6 +1207,28 @@ | |
682 | r = mboxlist_lookup(inboxname, &server, NULL, NULL); | |
683 | if (!r) fatal("couldn't find backend server", EC_CONFIG); | |
684 | ||
685 | +#ifdef INET6 | |
686 | + memset(&hints, 0, sizeof(hints)); | |
687 | + hints.ai_family = PF_UNSPEC; | |
688 | + hints.ai_socktype = SOCK_STREAM; | |
689 | + if (getaddrinfo(server, "110", &hints, &res0)) | |
690 | + fatal("getaddrinfo failed", EC_CONFIG); | |
691 | + for (res = res0; res; res = res->ai_next) { | |
692 | + backend_sock = socket(res->ai_family, res->ai_socktype, | |
693 | + res->ai_protocol); | |
694 | + if (backend_sock < 0) | |
695 | + continue; | |
696 | + if (connect(backend_sock, res->ai_addr, res->ai_addrlen) >= 0) | |
697 | + break; | |
698 | + close(backend_sock); | |
699 | + backend_sock = -1; | |
700 | + } | |
701 | + freeaddrinfo(res0); | |
702 | + if (backend_sock < 0) { | |
703 | + syslog(LOG_ERR, "connect() failed: %m"); | |
704 | + fatal("connect failed", 1); | |
705 | + } | |
706 | +#else | |
707 | hp = gethostbyname(server); | |
708 | if (!hp) fatal("gethostbyname failed", EC_CONFIG); | |
709 | sin.sin_family = AF_INET; | |
710 | @@ -1162,6 +1243,7 @@ | |
711 | syslog(LOG_ERR, "connect() failed: %m"); | |
712 | fatal("connect failed", 1); | |
713 | } | |
714 | +#endif | |
715 | ||
716 | backend_in = prot_new(backend_sock, 0); | |
717 | backend_out = prot_new(backend_sock, 1); | |
718 | diff -ruN --exclude *.orig --exclude configure cyrus-imapd-2.0.12.orig/imap/proxyd.c cyrus-imapd-2.0.12/imap/proxyd.c | |
719 | --- cyrus-imapd-2.0.12.orig/imap/proxyd.c Thu Apr 26 17:10:59 2001 | |
720 | +++ cyrus-imapd-2.0.12/imap/proxyd.c Thu Apr 26 17:11:38 2001 | |
721 | @@ -93,6 +93,15 @@ | |
722 | #include "pushstats.h" | |
723 | #include "telemetry.h" | |
724 | ||
725 | +#ifdef INET6 | |
726 | +#ifndef NI_WITHSCOPEID | |
727 | +#define NI_WITHSCOPEID 0 | |
728 | +#endif | |
729 | +#ifndef HAVE_SS_FAMILY | |
730 | +#define ss_family __ss_family | |
731 | +#endif | |
732 | +#endif | |
733 | + | |
734 | /* PROXY STUFF */ | |
735 | /* we want a list of our outgoing connections here and which one we're | |
736 | currently piping */ | |
737 | @@ -103,7 +112,11 @@ | |
738 | ||
739 | struct backend { | |
740 | char *hostname; | |
741 | +#ifdef INET6 | |
742 | + struct sockaddr_storage addr; | |
743 | +#else | |
744 | struct sockaddr_in addr; | |
745 | +#endif | |
746 | int sock; | |
747 | struct prot_waitevent *timeout; | |
748 | ||
749 | @@ -155,9 +168,17 @@ | |
750 | char *proxyd_userid; | |
751 | struct auth_state *proxyd_authstate = 0; | |
752 | int proxyd_userisadmin; | |
753 | +#ifdef INET6 | |
754 | +struct sockaddr_storage proxyd_localaddr, proxyd_remoteaddr; | |
755 | +#else | |
756 | struct sockaddr_in proxyd_localaddr, proxyd_remoteaddr; | |
757 | +#endif | |
758 | int proxyd_haveaddr = 0; | |
759 | +#ifdef INET6 | |
760 | +char proxyd_clienthost[NI_MAXHOST*2+1] = "[local]"; | |
761 | +#else | |
762 | char proxyd_clienthost[250] = "[local]"; | |
763 | +#endif | |
764 | struct protstream *proxyd_out, *proxyd_in; | |
765 | time_t proxyd_logtime; | |
766 | static char shutdownfilename[1024]; | |
767 | @@ -552,11 +573,19 @@ | |
768 | { | |
769 | int r; | |
770 | sasl_security_properties_t *secprops = NULL; | |
771 | +#ifdef INET6 | |
772 | + struct sockaddr *saddr_l = | |
773 | + (struct sockaddr *) malloc(sizeof(struct sockaddr_storage)); | |
774 | + struct sockaddr *saddr_r = | |
775 | + (struct sockaddr *) malloc(sizeof(struct sockaddr_storage)); | |
776 | + socklen_t addrsize = sizeof(struct sockaddr_storage); | |
777 | +#else | |
778 | struct sockaddr_in *saddr_l = | |
779 | (struct sockaddr_in *) malloc(sizeof(struct sockaddr_in)); | |
780 | struct sockaddr_in *saddr_r = | |
781 | (struct sockaddr_in *) malloc(sizeof(struct sockaddr_in)); | |
782 | socklen_t addrsize = sizeof(struct sockaddr_in); | |
783 | +#endif | |
784 | sasl_callback_t *cb; | |
785 | char mytag[128]; | |
786 | char buf[2048]; | |
787 | @@ -594,7 +623,11 @@ | |
788 | r = sasl_setprop(s->saslconn, SASL_IP_REMOTE, saddr_r); | |
789 | ||
790 | if (r == SASL_OK) { | |
791 | +#ifdef INET6 | |
792 | + addrsize=sizeof(struct sockaddr_storage); | |
793 | +#else | |
794 | addrsize=sizeof(struct sockaddr_in); | |
795 | +#endif | |
796 | if (getsockname(s->sock, (struct sockaddr *)saddr_l,&addrsize)!=0) | |
797 | return SASL_FAIL; | |
798 | r = sasl_setprop(s->saslconn, SASL_IP_LOCAL, saddr_l); | |
799 | @@ -754,11 +787,14 @@ | |
800 | } | |
801 | ||
802 | if (!ret) { | |
803 | +#ifndef INET6 | |
804 | struct hostent *hp; | |
805 | +#endif | |
806 | ||
807 | ret = xmalloc(sizeof(struct backend)); | |
808 | memset(ret, 0, sizeof(struct backend)); | |
809 | ret->hostname = xstrdup(server); | |
810 | +#ifndef INET6 | |
811 | if ((hp = gethostbyname(server)) == NULL) { | |
812 | syslog(LOG_ERR, "gethostbyname(%s) failed: %m", server); | |
813 | free(ret); | |
814 | @@ -767,15 +803,45 @@ | |
815 | ret->addr.sin_family = AF_INET; | |
816 | memcpy(&ret->addr.sin_addr, hp->h_addr, hp->h_length); | |
817 | ret->addr.sin_port = htons(143); | |
818 | +#endif | |
819 | ||
820 | ret->timeout = NULL; | |
821 | } | |
822 | ||
823 | if (!ret->timeout) { | |
824 | /* need to (re)establish connection to server or create one */ | |
825 | - int sock; | |
826 | + int sock = -1; | |
827 | int r; | |
828 | - | |
829 | +#ifdef INET6 | |
830 | + int err; | |
831 | + struct addrinfo hints, *res0 = NULL, *res; | |
832 | + | |
833 | + memset(&hints, 0, sizeof(hints)); | |
834 | + hints.ai_family = PF_UNSPEC; | |
835 | + hints.ai_socktype = SOCK_STREAM; | |
836 | + err = getaddrinfo(server, "143", &hints, &res0); | |
837 | + if (err) { | |
838 | + syslog(LOG_ERR, "getaddrinfo(%s) failed: %s", | |
839 | + server, gai_strerror(err)); | |
840 | + free(ret); | |
841 | + return NULL; | |
842 | + } | |
843 | + for (res = res0; res; res = res->ai_next) { | |
844 | + sock = socket(res->ai_family, res->ai_socktype, res->ai_protocol); | |
845 | + if (sock < 0) | |
846 | + continue; | |
847 | + if (connect(sock, res->ai_addr, res->ai_addrlen) >= 0) | |
848 | + break; | |
849 | + close(sock); | |
850 | + sock = -1; | |
851 | + } | |
852 | + freeaddrinfo(res0); | |
853 | + if (sock < 0) { | |
854 | + syslog(LOG_ERR, "connect(%s) failed: %m", server); | |
855 | + free(ret); | |
856 | + return NULL; | |
857 | + } | |
858 | +#else | |
859 | if ((sock = socket(AF_INET, SOCK_STREAM, 0)) < 0) { | |
860 | syslog(LOG_ERR, "socket() failed: %m"); | |
861 | free(ret); | |
862 | @@ -787,6 +853,7 @@ | |
863 | free(ret); | |
864 | return NULL; | |
865 | } | |
866 | +#endif | |
867 | ||
868 | ret->in = prot_new(sock, 0); | |
869 | ret->out = prot_new(sock, 1); | |
870 | @@ -1043,6 +1110,9 @@ | |
871 | int timeout; | |
872 | sasl_security_properties_t *secprops = NULL; | |
873 | sasl_external_properties_t extprops; | |
874 | +#ifdef INET6 | |
875 | + char hbuf[NI_MAXHOST]; | |
876 | +#endif | |
877 | ||
878 | signals_poll(); | |
879 | ||
880 | @@ -1079,6 +1149,29 @@ | |
881 | ||
882 | /* Find out name of client host */ | |
883 | salen = sizeof(proxyd_remoteaddr); | |
884 | +#ifdef INET6 | |
885 | + if (getpeername(0, (struct sockaddr *)&proxyd_remoteaddr, &salen) == 0 && | |
886 | + (proxyd_remoteaddr.ss_family == AF_INET || | |
887 | + proxyd_remoteaddr.ss_family == AF_INET6)) { | |
888 | + if (getnameinfo((struct sockaddr *)&proxyd_remoteaddr, salen, | |
889 | + hbuf, sizeof(hbuf), NULL, 0, NI_NAMEREQD) == 0) { | |
890 | + strncpy(proxyd_clienthost, hbuf, sizeof(hbuf)); | |
891 | + } | |
892 | + else { | |
893 | + proxyd_clienthost[0] = '\0'; | |
894 | + } | |
895 | + getnameinfo((struct sockaddr *)&proxyd_remoteaddr, salen, hbuf, | |
896 | + sizeof(hbuf), NULL, 0, NI_NUMERICHOST | NI_WITHSCOPEID); | |
897 | + strcat(proxyd_clienthost, "["); | |
898 | + strcat(proxyd_clienthost, hbuf); | |
899 | + strcat(proxyd_clienthost, "]"); | |
900 | + salen = sizeof(proxyd_localaddr); | |
901 | + if (getsockname(0, (struct sockaddr *)&proxyd_localaddr, | |
902 | + &salen) == 0) { | |
903 | + proxyd_haveaddr = 1; | |
904 | + } | |
905 | + } | |
906 | +#else | |
907 | if (getpeername(0, (struct sockaddr *)&proxyd_remoteaddr, &salen) == 0 && | |
908 | proxyd_remoteaddr.sin_family == AF_INET) { | |
909 | hp = gethostbyaddr((char *)&proxyd_remoteaddr.sin_addr, | |
910 | @@ -1098,6 +1191,7 @@ | |
911 | proxyd_haveaddr = 1; | |
912 | } | |
913 | } | |
914 | +#endif | |
915 | ||
916 | /* create the SASL connection */ | |
917 | /* Make a SASL connection and setup some properties for it */ | |
918 | diff -ruN --exclude *.orig --exclude configure cyrus-imapd-2.0.12.orig/imtest/imtest.c cyrus-imapd-2.0.12/imtest/imtest.c | |
919 | --- cyrus-imapd-2.0.12.orig/imtest/imtest.c Thu Apr 26 17:10:59 2001 | |
920 | +++ cyrus-imapd-2.0.12/imtest/imtest.c Thu Apr 26 17:11:38 2001 | |
921 | @@ -571,13 +571,23 @@ | |
922 | * Initialize SASL and set necessary options | |
923 | */ | |
924 | ||
925 | +#ifdef INET6 | |
926 | +static int init_sasl(char *serverFQDN, char *port, int minssf, int maxssf) | |
927 | +#else | |
928 | static int init_sasl(char *serverFQDN, int port, int minssf, int maxssf) | |
929 | +#endif | |
930 | { | |
931 | int saslresult; | |
932 | sasl_security_properties_t *secprops=NULL; | |
933 | +#ifdef INET6 | |
934 | + socklen_t addrsize=sizeof(struct sockaddr_storage); | |
935 | + struct sockaddr *saddr_l=malloc(sizeof(struct sockaddr_storage)); | |
936 | + struct sockaddr *saddr_r=malloc(sizeof(struct sockaddr_storage)); | |
937 | +#else | |
938 | socklen_t addrsize=sizeof(struct sockaddr_in); | |
939 | struct sockaddr_in *saddr_l=malloc(sizeof(struct sockaddr_in)); | |
940 | struct sockaddr_in *saddr_r=malloc(sizeof(struct sockaddr_in)); | |
941 | +#endif | |
942 | ||
943 | /* attempt to start sasl */ | |
944 | saslresult=sasl_client_init(callbacks); | |
945 | @@ -607,7 +617,11 @@ | |
946 | if (sasl_setprop(conn, SASL_IP_REMOTE, saddr_r)!=SASL_OK) | |
947 | return IMTEST_FAIL; | |
948 | ||
949 | +#ifdef INET6 | |
950 | + addrsize=sizeof(struct sockaddr_storage); | |
951 | +#else | |
952 | addrsize=sizeof(struct sockaddr_in); | |
953 | +#endif | |
954 | if (getsockname(sock,(struct sockaddr *)saddr_l,&addrsize)!=0) | |
955 | return IMTEST_FAIL; | |
956 | ||
957 | @@ -852,6 +866,37 @@ | |
958 | } | |
959 | ||
960 | /* initialize the network */ | |
961 | +#ifdef INET6 | |
962 | +int init_net(char *serverFQDN, char *port) | |
963 | +{ | |
964 | + struct addrinfo hints, *res0 = NULL, *res; | |
965 | + int err; | |
966 | + | |
967 | + memset(&hints, 0, sizeof(hints)); | |
968 | + hints.ai_family = PF_UNSPEC; | |
969 | + hints.ai_socktype = SOCK_STREAM; | |
970 | + hints.ai_flags = AI_CANONNAME; | |
971 | + if ((err = getaddrinfo(serverFQDN, port, &hints, &res0)) != 0) { | |
972 | + fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(err)); | |
973 | + return IMTEST_FAIL; | |
974 | + } | |
975 | + if (res0->ai_canonname) | |
976 | + strncpy(serverFQDN, res0->ai_canonname, 1023); | |
977 | + for (res = res0; res; res = res->ai_next) { | |
978 | + sock = socket(res->ai_family, res->ai_socktype, res->ai_protocol); | |
979 | + if (sock < 0) | |
980 | + continue; | |
981 | + if (connect(sock, res->ai_addr, res->ai_addrlen) >= 0) | |
982 | + break; | |
983 | + close(sock); | |
984 | + sock = -1; | |
985 | + } | |
986 | + freeaddrinfo(res0); | |
987 | + if (sock < 0) { | |
988 | + perror("connect"); | |
989 | + return IMTEST_FAIL; | |
990 | + } | |
991 | +#else | |
992 | int init_net(char *serverFQDN, int port) | |
993 | { | |
994 | struct sockaddr_in addr; | |
995 | @@ -876,6 +921,7 @@ | |
996 | perror("connect"); | |
997 | return IMTEST_FAIL; | |
998 | } | |
999 | +#endif | |
1000 | ||
1001 | return IMTEST_OK; | |
1002 | } | |
1003 | @@ -1179,7 +1225,9 @@ | |
1004 | char *tls_keyfile=""; | |
1005 | char *port = "imap"; | |
1006 | struct servent *serv; | |
1007 | +#ifndef INET6 | |
1008 | int servport; | |
1009 | +#endif | |
1010 | int run_stress_test=0; | |
1011 | int dotls=0; | |
1012 | int server_supports_tls; | |
1013 | @@ -1243,6 +1291,15 @@ | |
1014 | /* last arg is server name */ | |
1015 | strncpy(servername, argv[optind], 1023); | |
1016 | ||
1017 | +#ifdef INET6 | |
1018 | + if (init_net(servername, port) != IMTEST_OK) { | |
1019 | + imtest_fatal("Network initialization"); | |
1020 | + } | |
1021 | + | |
1022 | + if (init_sasl(servername, port, minssf, maxssf) != IMTEST_OK) { | |
1023 | + imtest_fatal("SASL initialization"); | |
1024 | + } | |
1025 | +#else | |
1026 | /* map port -> num */ | |
1027 | serv = getservbyname(port, "tcp"); | |
1028 | if (serv == NULL) { | |
1029 | @@ -1258,6 +1315,7 @@ | |
1030 | if (init_sasl(servername, servport, minssf, maxssf) != IMTEST_OK) { | |
1031 | imtest_fatal("SASL initialization"); | |
1032 | } | |
1033 | +#endif | |
1034 | ||
1035 | /* set up the prot layer */ | |
1036 | pin = prot_new(sock, 0); | |
1037 | diff -ruN --exclude *.orig --exclude configure cyrus-imapd-2.0.12.orig/lib/imclient.c cyrus-imapd-2.0.12/lib/imclient.c | |
1038 | --- cyrus-imapd-2.0.12.orig/lib/imclient.c Sat Feb 17 21:19:40 2001 | |
1039 | +++ cyrus-imapd-2.0.12/lib/imclient.c Thu Apr 26 17:11:38 2001 | |
1040 | @@ -213,13 +213,39 @@ | |
1041 | const char *port, | |
1042 | sasl_callback_t *cbs) | |
1043 | { | |
1044 | - int s; | |
1045 | + int s = -1; | |
1046 | +#ifdef INET6 | |
1047 | + struct addrinfo hints, *res0 = NULL, *res; | |
1048 | + int err; | |
1049 | +#else | |
1050 | struct hostent *hp; | |
1051 | struct servent *sp; | |
1052 | struct sockaddr_in addr; | |
1053 | +#endif | |
1054 | static struct imclient zeroimclient; | |
1055 | int saslresult; | |
1056 | ||
1057 | +#ifdef INET6 | |
1058 | + if (!port) | |
1059 | + port = "143"; | |
1060 | + memset(&hints, 0, sizeof(hints)); | |
1061 | + hints.ai_family = PF_UNSPEC; | |
1062 | + hints.ai_socktype = SOCK_STREAM; | |
1063 | + hints.ai_flags = AI_CANONNAME; | |
1064 | + if (getaddrinfo(host, port, &hints, &res0)) | |
1065 | + return -1; | |
1066 | + for (res = res0; res; res = res->ai_next) { | |
1067 | + s = socket(res->ai_family, res->ai_socktype, res->ai_protocol); | |
1068 | + if (s < 0) | |
1069 | + continue; | |
1070 | + if (connect(s, res->ai_addr, res->ai_addrlen) >= 0) | |
1071 | + break; | |
1072 | + close(s); | |
1073 | + s = -1; | |
1074 | + } | |
1075 | + if (s < 0) | |
1076 | + return errno; | |
1077 | +#else | |
1078 | hp = gethostbyname(host); | |
1079 | if (!hp) return -1; | |
1080 | ||
1081 | @@ -242,13 +268,20 @@ | |
1082 | if (connect(s, (struct sockaddr *)&addr, sizeof(addr)) == -1) { | |
1083 | return errno; | |
1084 | } | |
1085 | +#endif | |
1086 | /* nonblock(s, 1); */ | |
1087 | *imclient = (struct imclient *)xmalloc(sizeof(struct imclient)); | |
1088 | **imclient = zeroimclient; | |
1089 | (*imclient)->fd = s; | |
1090 | (*imclient)->saslconn = NULL; | |
1091 | (*imclient)->saslcompleted = 0; | |
1092 | +#ifdef INET6 | |
1093 | + (*imclient)->servername = xstrdup(res0->ai_canonname ? | |
1094 | + res0->ai_canonname : host); | |
1095 | + freeaddrinfo(res0); | |
1096 | +#else | |
1097 | (*imclient)->servername = xstrdup(hp->h_name); | |
1098 | +#endif | |
1099 | (*imclient)->outptr = (*imclient)->outstart = (*imclient)->outbuf; | |
1100 | (*imclient)->outleft = (*imclient)->maxplain = sizeof((*imclient)->outbuf); | |
1101 | imclient_addcallback(*imclient, | |
1102 | diff -ruN --exclude *.orig --exclude configure cyrus-imapd-2.0.12.orig/master/master.c cyrus-imapd-2.0.12/master/master.c | |
1103 | --- cyrus-imapd-2.0.12.orig/master/master.c Thu Apr 26 17:10:59 2001 | |
1104 | +++ cyrus-imapd-2.0.12/master/master.c Thu Apr 26 17:11:38 2001 | |
1105 | @@ -241,6 +241,22 @@ | |
1106 | return port; | |
1107 | } | |
1108 | ||
1109 | +char *parse_host(char *listen) | |
1110 | +{ | |
1111 | + char *cp; | |
1112 | + | |
1113 | + /* do we have a hostname, or IP number? */ | |
1114 | + /* XXX are brackets necessary, like for IPv6 later? */ | |
1115 | + if (*listen == '[') { | |
1116 | + listen++; /* skip first bracket */ | |
1117 | + if ((cp = strrchr(listen,']')) != NULL) { | |
1118 | + *cp = '\0'; | |
1119 | + } | |
1120 | + } | |
1121 | + return listen; | |
1122 | +} | |
1123 | + | |
1124 | +#ifndef INET6 | |
1125 | /* set sin_port accordingly. return of 0 indicates failure. */ | |
1126 | int resolve_port(char *port, struct service *s, struct sockaddr_in *sin) | |
1127 | { | |
1128 | @@ -265,21 +281,14 @@ | |
1129 | int resolve_host(struct service *s, struct sockaddr_in *sin) | |
1130 | { | |
1131 | struct hostent *hp; | |
1132 | - char *cp; | |
1133 | + char *listen_addr; | |
1134 | ||
1135 | - /* do we have a hostname, or IP number? */ | |
1136 | - /* XXX are brackets necessary, like for IPv6 later? */ | |
1137 | - if (*s->listen == '[') { | |
1138 | - s->listen++; /* skip first bracket */ | |
1139 | - if ((cp = strrchr(s->listen,']')) != NULL) { | |
1140 | - *cp = '\0'; | |
1141 | - } | |
1142 | - } | |
1143 | - sin->sin_addr.s_addr = inet_addr(s->listen); | |
1144 | + listen_addr = parse_host(s->listen); | |
1145 | + sin->sin_addr.s_addr = inet_addr(listen_addr); | |
1146 | if ((sin->sin_addr.s_addr == INADDR_NONE) || (sin->sin_addr.s_addr == 0)) { | |
1147 | /* looks like it isn't an IP address, so look up the host */ | |
1148 | - if ((hp = gethostbyname(s->listen)) == 0) { | |
1149 | - syslog(LOG_INFO, "host not found: %s", s->listen); | |
1150 | + if ((hp = gethostbyname(listen_addr)) == 0) { | |
1151 | + syslog(LOG_INFO, "host not found: %s", listen_addr); | |
1152 | s->exec = NULL; | |
1153 | return 0; | |
1154 | } | |
1155 | @@ -297,17 +306,146 @@ | |
1156 | } | |
1157 | return 1; | |
1158 | } | |
1159 | +#endif | |
1160 | ||
1161 | void service_create(struct service *s) | |
1162 | { | |
1163 | +#ifdef INET6 | |
1164 | + struct service service0, service; | |
1165 | + struct addrinfo hints, *res0, *res; | |
1166 | + struct sockaddr_storage sin; | |
1167 | + int error, nsocket = 0; | |
1168 | + char *listen_addr; | |
1169 | +#else | |
1170 | struct sockaddr_in sin; | |
1171 | - struct sockaddr_un sunsock; | |
1172 | struct sockaddr *sa; | |
1173 | + int salen; | |
1174 | +#endif | |
1175 | + struct sockaddr_un sunsock; | |
1176 | mode_t oldumask; | |
1177 | - int on = 1, salen; | |
1178 | + int on = 1; | |
1179 | int r; | |
1180 | char *port; | |
1181 | ||
1182 | +#ifdef INET6 | |
1183 | + if (s->socket > 0) | |
1184 | + return; /* service is already activated */ | |
1185 | + | |
1186 | + if (s->listen[0] == '/') { /* unix socket */ | |
1187 | + res0 = (struct addrinfo *)malloc(sizeof(struct addrinfo)); | |
1188 | + if (!res0) | |
1189 | + fatal("out of memory", EX_UNAVAILABLE); | |
1190 | + memset(res0, 0, sizeof(struct addrinfo)); | |
1191 | + res0->ai_flags = AI_PASSIVE; | |
1192 | + res0->ai_family = PF_UNIX; | |
1193 | + res0->ai_socktype = SOCK_STREAM; | |
1194 | + res0->ai_addr = (struct sockaddr *)&sunsock; | |
1195 | + res0->ai_addrlen = sizeof(sunsock.sun_family) + strlen(s->listen) + 1; | |
1196 | +#ifdef SIN6_LEN | |
1197 | + res0->ai_addrlen += sizeof(sunsock.sun_len); | |
1198 | + sunsock.sun_len = res0->ai_addrlen; | |
1199 | +#endif | |
1200 | + sunsock.sun_family = AF_UNIX; | |
1201 | + strcpy(sunsock.sun_path, s->listen); | |
1202 | + unlink(s->listen); | |
1203 | + } else { /* inet socket */ | |
1204 | + memset(&hints, 0, sizeof(hints)); | |
1205 | + hints.ai_flags = AI_PASSIVE; | |
1206 | + hints.ai_family = PF_UNSPEC; | |
1207 | + if (!strcmp(s->proto, "tcp")) | |
1208 | + hints.ai_socktype = SOCK_STREAM; | |
1209 | + else if (!strcmp(s->proto, "udp")) | |
1210 | + hints.ai_socktype = SOCK_DGRAM; | |
1211 | + else { | |
1212 | + syslog(LOG_INFO, "invalid proto '%s', disabling %s", | |
1213 | + s->proto, s->name); | |
1214 | + s->exec = NULL; | |
1215 | + return; | |
1216 | + } | |
1217 | + if ((port = parse_listen(s->listen)) == NULL) { | |
1218 | + /* s->listen IS the port */ | |
1219 | + port = s->listen; | |
1220 | + listen_addr = NULL; | |
1221 | + } else { | |
1222 | + /* s->listen is now just the address */ | |
1223 | + listen_addr = parse_host(s->listen); | |
1224 | + if (*listen_addr == '\0') | |
1225 | + listen_addr = NULL; | |
1226 | + } | |
1227 | + error = getaddrinfo(listen_addr, port, &hints, &res0); | |
1228 | + if (error) { | |
1229 | + syslog(LOG_INFO, "%s, disabling %s", gai_strerror(error), s->name); | |
1230 | + s->exec = NULL; | |
1231 | + return; | |
1232 | + } | |
1233 | + } | |
1234 | + | |
1235 | + memcpy(&service0, s, sizeof(struct service)); | |
1236 | + | |
1237 | + for (res = res0; res; res = res->ai_next) { | |
1238 | + if (s->socket > 0) { | |
1239 | + memcpy(&service, &service0, sizeof(struct service)); | |
1240 | + s = &service; | |
1241 | + } | |
1242 | + | |
1243 | + s->socket = socket(res->ai_family, res->ai_socktype, res->ai_protocol); | |
1244 | + if (s->socket < 0) | |
1245 | + continue; | |
1246 | + | |
1247 | + /* allow reuse of address */ | |
1248 | + setsockopt(s->socket, SOL_SOCKET, SO_REUSEADDR, | |
1249 | + (void *) &on, sizeof(on)); | |
1250 | + | |
1251 | +#if defined(IPV6_BINDV6ONLY) && !(defined(__FreeBSD__) && __FreeBSD__ < 3) | |
1252 | + if (res->ai_family == AF_INET6) | |
1253 | + setsockopt(s->socket, IPPROTO_IPV6, IPV6_BINDV6ONLY, | |
1254 | + (void *) &on, sizeof(on)); | |
1255 | +#endif | |
1256 | + | |
1257 | + oldumask = umask((mode_t) 0); /* for linux */ | |
1258 | + r = bind(s->socket, res->ai_addr, res->ai_addrlen); | |
1259 | + umask(oldumask); | |
1260 | + if (r < 0) { | |
1261 | + close(s->socket); | |
1262 | + s->socket = -1; | |
1263 | + continue; | |
1264 | + } | |
1265 | + | |
1266 | + if (s->listen[0] == '/') { /* unix socket */ | |
1267 | + /* for DUX, where this isn't the default. | |
1268 | + (harmlessly fails on some systems) */ | |
1269 | + chmod(s->listen, (mode_t) 0777); | |
1270 | + } | |
1271 | + | |
1272 | + if (listen(s->socket, listen_queue_backlog) < 0) { | |
1273 | + syslog(LOG_ERR, "unable to listen to %s socket: %m", s->name); | |
1274 | + close(s->socket); | |
1275 | + s->socket = -1; | |
1276 | + continue; | |
1277 | + } | |
1278 | + | |
1279 | + s->ready_workers = 0; | |
1280 | + | |
1281 | + get_statsock(s->stat); | |
1282 | + | |
1283 | + if (s == &service) { | |
1284 | + if (nservices == allocservices) { | |
1285 | + Services = realloc(Services, | |
1286 | + (allocservices+=5) * sizeof(struct service)); | |
1287 | + if (!Services) fatal("out of memory", EX_UNAVAILABLE); | |
1288 | + } | |
1289 | + memcpy(&Services[nservices++], s, sizeof(struct service)); | |
1290 | + } | |
1291 | + nsocket++; | |
1292 | + } | |
1293 | + if (res0) | |
1294 | + freeaddrinfo(res0); | |
1295 | + if (nsocket <= 0) { | |
1296 | + syslog(LOG_ERR, "unable to create %s listener socket: %m", s->name); | |
1297 | + s->exec = NULL; | |
1298 | + return; | |
1299 | + } | |
1300 | +#else | |
1301 | memset(&sin, 0, sizeof(sin)); | |
1302 | ||
1303 | if (s->listen[0] == '/') { /* unix socket */ | |
1304 | @@ -379,6 +517,7 @@ | |
1305 | s->ready_workers = 0; | |
1306 | ||
1307 | get_statsock(s->stat); | |
1308 | +#endif | |
1309 | } | |
1310 | ||
1311 | void run_startup(char **cmd) | |
1312 | diff -ruN --exclude *.orig --exclude configure cyrus-imapd-2.0.12.orig/master/service.c cyrus-imapd-2.0.12/master/service.c | |
1313 | --- cyrus-imapd-2.0.12.orig/master/service.c Thu Apr 26 17:10:59 2001 | |
1314 | +++ cyrus-imapd-2.0.12/master/service.c Thu Apr 26 17:11:38 2001 | |
1315 | @@ -95,12 +95,16 @@ | |
1316 | static int libwrap_ask(struct request_info *r, int fd) | |
1317 | { | |
1318 | int a; | |
1319 | +#ifdef INET6 | |
1320 | + struct sockaddr_storage sin; | |
1321 | +#else | |
1322 | struct sockaddr_in sin; | |
1323 | +#endif | |
1324 | socklen_t len = sizeof(sin); | |
1325 | ||
1326 | /* is this a connection from the local host? */ | |
1327 | if (getpeername(fd, (struct sockaddr *) &sin, &len) == 0) { | |
1328 | - if (sin.sin_family == AF_UNIX) { | |
1329 | + if (((struct sockaddr *)&sin)->sa_family == AF_UNIX) { | |
1330 | return 1; | |
1331 | } | |
1332 | } | |
1333 | diff -ruN --exclude *.orig --exclude configure cyrus-imapd-2.0.12.orig/timsieved/timsieved.c cyrus-imapd-2.0.12/timsieved/timsieved.c | |
1334 | --- cyrus-imapd-2.0.12.orig/timsieved/timsieved.c Mon Feb 19 19:05:22 2001 | |
1335 | +++ cyrus-imapd-2.0.12/timsieved/timsieved.c Thu Apr 26 17:11:38 2001 | |
1336 | @@ -81,19 +81,36 @@ | |
1337 | ||
1338 | #include "auth.h" | |
1339 | ||
1340 | +#ifdef INET6 | |
1341 | +#ifndef NI_WITHSCOPEID | |
1342 | +#define NI_WITHSCOPEID 0 | |
1343 | +#endif | |
1344 | +#ifndef HAVE_SS_FAMILY | |
1345 | +#define ss_family __ss_family | |
1346 | +#endif | |
1347 | +#endif | |
1348 | ||
1349 | sasl_conn_t *sieved_saslconn; /* the sasl connection context */ | |
1350 | ||
1351 | struct auth_state *sieved_authstate = 0; | |
1352 | ||
1353 | +#ifdef INET6 | |
1354 | +struct sockaddr_storage sieved_localaddr; | |
1355 | +struct sockaddr_storage sieved_remoteaddr; | |
1356 | +#else | |
1357 | struct sockaddr_in sieved_localaddr; | |
1358 | struct sockaddr_in sieved_remoteaddr; | |
1359 | +#endif | |
1360 | ||
1361 | struct protstream *sieved_out; | |
1362 | struct protstream *sieved_in; | |
1363 | ||
1364 | int sieved_haveaddr = 0; | |
1365 | +#ifdef INET6 | |
1366 | +char sieved_clienthost[NI_MAXHOST*2+1] = "[local]"; | |
1367 | +#else | |
1368 | char sieved_clienthost[250] = "[local]"; | |
1369 | +#endif | |
1370 | ||
1371 | int sieved_userisadmin; | |
1372 | ||
1373 | @@ -231,6 +248,9 @@ | |
1374 | int timeout; | |
1375 | int secflags = 0; | |
1376 | sasl_security_properties_t *secprops = NULL; | |
1377 | +#ifdef INET6 | |
1378 | + char hbuf[NI_MAXHOST]; | |
1379 | +#endif | |
1380 | ||
1381 | /* set up the prot streams */ | |
1382 | sieved_in = prot_new(0, 0); | |
1383 | @@ -248,6 +268,28 @@ | |
1384 | ||
1385 | /* Find out name of client host */ | |
1386 | salen = sizeof(sieved_remoteaddr); | |
1387 | +#ifdef INET6 | |
1388 | + if (getpeername(0, (struct sockaddr *)&sieved_remoteaddr, &salen) == 0 && | |
1389 | + (sieved_remoteaddr.ss_family == AF_INET || | |
1390 | + sieved_remoteaddr.ss_family == AF_INET6)) { | |
1391 | + if (getnameinfo((struct sockaddr *)&sieved_remoteaddr, salen, | |
1392 | + hbuf, sizeof(hbuf), NULL, 0, NI_NAMEREQD) == 0) { | |
1393 | + strncpy(sieved_clienthost, hbuf, sizeof(hbuf)); | |
1394 | + } | |
1395 | + else { | |
1396 | + sieved_clienthost[0] = '\0'; | |
1397 | + } | |
1398 | + getnameinfo((struct sockaddr *)&sieved_remoteaddr, salen, hbuf, | |
1399 | + sizeof(hbuf), NULL, 0, NI_NUMERICHOST | NI_WITHSCOPEID); | |
1400 | + strcat(sieved_clienthost, "["); | |
1401 | + strcat(sieved_clienthost, hbuf); | |
1402 | + strcat(sieved_clienthost, "]"); | |
1403 | + salen = sizeof(sieved_localaddr); | |
1404 | + if (getsockname(0, (struct sockaddr *)&sieved_localaddr, &salen) == 0) { | |
1405 | + sieved_haveaddr = 1; | |
1406 | + } | |
1407 | + } | |
1408 | +#else | |
1409 | if (getpeername(0, (struct sockaddr *)&sieved_remoteaddr, &salen) == 0 && | |
1410 | sieved_remoteaddr.sin_family == AF_INET) { | |
1411 | if ((hp = gethostbyaddr((char *)&sieved_remoteaddr.sin_addr, | |
1412 | @@ -266,6 +308,7 @@ | |
1413 | sieved_haveaddr = 1; | |
1414 | } | |
1415 | } | |
1416 | +#endif | |
1417 | ||
1418 | /* set the SASL allocation functions */ | |
1419 | sasl_set_alloc((sasl_malloc_t *) &xmalloc, |