]> git.pld-linux.org Git - packages/sendmail.git/blob - sendmail-ipv6.patch
- ooops - left from tests...
[packages/sendmail.git] / sendmail-ipv6.patch
1 diff -Nur sendmail-8.9.3/cf/m4/proto.m4 sendmail-8.9.3.pld/cf/m4/proto.m4
2 --- sendmail-8.9.3/cf/m4/proto.m4       Wed Feb  3 00:21:30 1999
3 +++ sendmail-8.9.3.pld/cf/m4/proto.m4   Wed Feb 10 18:11:17 1999
4 @@ -1111,6 +1111,7 @@
5  ifdef(`_RBL_', `dnl
6  # DNS based IP address spam lists
7  R$*                    $: $&{client_addr}
8 +R::ffff:$-.$-.$-.$-    $: $(host $4.$3.$2.$1._RBL_. $: OK $)
9  R$-.$-.$-.$-           $: $(host $4.$3.$2.$1._RBL_. $: OK $)
10  ROK                    $@ OK
11  R$+                    $#error $@ 5.7.1 $: "Mail from " $&{client_addr} " refused by blackhole site _RBL_"',
12 diff -Nur sendmail-8.9.3/src/conf.c sendmail-8.9.3.pld/src/conf.c
13 --- sendmail-8.9.3/src/conf.c   Wed Jan 27 01:15:52 1999
14 +++ sendmail-8.9.3.pld/src/conf.c       Wed Feb 10 18:11:17 1999
15 @@ -4085,6 +4085,33 @@
16  }
17  
18  #endif
19 +/*
20 +**  SM_GETHOSTBYNAME2 -- Wrapper for gethostbyname() with IPv6 support
21 +**
22 +**  Most modern resolver libraries (BIND 8.1.x, glibc 2.1.x) will already
23 +**  return an AF_INET6 hostent if RES_USE_INET6 is set in _res.options.
24 +**  They usually try something like gethostbyname2(name, AF_INET6) and,
25 +**  if that fails, return the result of gethostbyname2(name, AF_INET).
26 +**
27 +**  IPv6 code elsewhere should have set RES_USE_INET6 if it is defined.
28 +**  If it isn't defined, we simulate that behavior ourself.
29 +**
30 +**  You can *not* assume that the hostent returned will only be AF_INET.
31 +*/
32 +struct hostent *
33 +sm_gethostbyname2(name)
34 +       char *name;
35 +{
36 +#if NETINET6 && !defined(RES_USE_INET6)
37 +       struct hostent *h;
38 +
39 +       h = gethostbyname2(name, AF_INET6);
40 +       if (h)
41 +               return h;
42 +#endif
43 +       return gethostbyname(name);
44 +}
45 +
46  \f/*
47  **  SM_GETHOSTBY{NAME,ADDR} -- compatibility routines for gethostbyXXX
48  **
49 @@ -4123,7 +4150,7 @@
50  
51         if (tTd(61, 10))
52                 printf("gethostbyname(%s)... ", name);
53 -       h = gethostbyname(name);
54 +       h = sm_gethostbyname2(name);
55         if (h == NULL)
56         {
57                 if (tTd(61, 10))
58 @@ -4147,7 +4174,7 @@
59                         {
60                                 if (tTd(61, 10))
61                                         printf("gethostbyname(%s)... ", hbuf);
62 -                               h = gethostbyname(hbuf);
63 +                               h = sm_gethostbyname2(hbuf);
64                         }
65                 }
66         }
67 @@ -4301,7 +4328,12 @@
68                         hp = sm_gethostbyaddr((char *) &sa->sin.sin_addr,
69                                 sizeof(sa->sin.sin_addr), sa->sa.sa_family);
70                         break;
71 -
72 +#if INET6
73 +               case AF_INET6:
74 +                       hp = sm_gethostbyaddr((char *) &sa->sin6.sin6_addr,
75 +                               sizeof(sa->sin6.sin6_addr), sa->sa.sa_family);
76 +                       break;
77 +#endif                                                 
78                 default:
79  #if _FFR_LOG_UNSUPPORTED_FAMILIES
80                         /* XXX: Give warning about unsupported family */
81 @@ -4378,6 +4410,104 @@
82  # include <net/if.h>
83  #endif
84  
85 +#if defined(__linux__) && NETINET6
86 +
87 +/*
88 + *  This is a terrible, linux-specific kludge.  In linux-2.1.105 at least,
89 + *  there is no way to get IPv6 addresses via SIOCGIFCONF.  You can
90 + *  set them, but not retrieve them.  I haven't seen a standard way
91 + *  to retrieve the list yet.  If you use the /proc/net/if_inet6 file,
92 + *  you can get a list of them in a format like this:
93 + *
94 + *     00000000000000000000000000000001 01 80 10 80       lo
95 + *     fe800000000000000000006097df4915 02 0a 20 80     eth0
96 + *     fe80000000000000026097fffedf4915 02 0a 20 80     eth0
97 + */
98 +void
99 +load_if_names6()
100 +{
101 +       static FILE     *fp = NULL;
102 +       char             ip_addr[256];
103 +       static int       s = -1;
104 +
105 +       if (tTd(0, 40))
106 +               printf( "linux load_if_names6() kludge...\n" );
107 +
108 +       if (s != -1)
109 +               close(s);
110 +       s = socket(AF_INET6, SOCK_DGRAM, 0);
111 +       if (s == -1)
112 +               return;
113 +
114 +       if (fp)
115 +               (void) fclose( fp );
116 +       fp = fopen( "/proc/net/if_inet6", "r" );
117 +       if (fp)
118 +           {
119 +               SOCKADDR                 sa;
120 +               struct in6_addr         *in6 = &sa.sin6.sin6_addr;
121 +               char                     devname[10];
122 +               int                      plen, scope, dad_status, if_idx;
123 +
124 +               while( fscanf( fp,
125 +                   "%4x%4x%4x%4x%4x%4x%4x%4x %02x %02x %02x %02x %s\n",
126 +                   &in6->s6_addr16[0], &in6->s6_addr16[1],
127 +                   &in6->s6_addr16[2], &in6->s6_addr16[3],
128 +                   &in6->s6_addr16[4], &in6->s6_addr16[5],
129 +                   &in6->s6_addr16[6], &in6->s6_addr16[7],
130 +                   &if_idx, &plen, &scope, &dad_status, devname) != EOF)
131 +                   {
132 +                       struct hostent *hp;
133 +                       int i;
134 +                       struct ifreq ifrf;
135 +
136 +                       for (i = 0; i < 8; i++)
137 +                               in6->s6_addr16[i] = ntohs( in6->s6_addr16[i] );
138 +                       sa.sa.sa_family = AF_INET6;
139 +
140 +                       /* save IP address in text from */
141 +                       (void) snprintf(ip_addr, sizeof ip_addr, "[%.*s]",
142 +                               sizeof ip_addr - 3, anynet_ntoa( &sa ) );
143 +
144 +                       if (tTd(0, 40))
145 +                               printf("%s\n\ta.k.a.: %s\n", devname, ip_addr );
146 +
147 +                       if (!wordinclass(ip_addr, 'w'))
148 +                               setclass('w', ip_addr);
149 +
150 +                       bzero(&ifrf, sizeof( ifrf ));
151 +                       strncpy(ifrf.ifr_name, devname, sizeof(ifrf.ifr_name));
152 +                       ioctl(s, SIOCGIFFLAGS, (char *) &ifrf);
153 +                       if (tTd(0, 41))
154 +                               printf("\tflags: %x\n", ifrf.ifr_flags);
155 +
156 +                       /* skip "loopback" interface "lo" */
157 +                       if (bitset(IFF_LOOPBACK, ifrf.ifr_flags))
158 +                               continue;
159 +                       
160 +                       /*
161 +                        * If we skip the loopback interfaces, then
162 +                        * <draft-ietf-ngtrans-6bone-routing-01.txt>
163 +                        * would tend to indicate that we should skip
164 +                        * the link-local prefix (FE80::/10) as well.
165 +                        */
166 +                       if ((ntohs(*(in6->s6_addr16)) & 0xFFC0) == 0xFE80)
167 +                               continue;
168 +
169 +                       (void) add_hostnames( &sa );
170 +                   }
171 +
172 +               (void) fclose(fp);
173 +               fp = NULL;
174 +           }
175 +
176 +       close(s);
177 +
178 +       return;
179 +}
180 +
181 +#endif
182 +
183  void
184  load_if_names()
185  {
186 @@ -4386,7 +4516,9 @@
187         int i;
188         struct ifconf ifc;
189         int numifs;
190 -
191 +#if NETINET6
192 +       load_if_names6();
193 +#endif    
194         s = socket(AF_INET, SOCK_DGRAM, 0);
195         if (s == -1)
196                 return;
197 @@ -4768,6 +4900,9 @@
198  #if NETINET
199         "NETINET",
200  #endif
201 +#if NETINET6
202 +       "NETINET6",
203 +#endif 
204  #if NETINFO
205         "NETINFO",
206  #endif
207 diff -Nur sendmail-8.9.3/src/conf.h sendmail-8.9.3.pld/src/conf.h
208 --- sendmail-8.9.3/src/conf.h   Fri Jan 29 00:28:34 1999
209 +++ sendmail-8.9.3.pld/src/conf.h       Wed Feb 10 18:11:17 1999
210 @@ -84,6 +84,10 @@
211  #  define NETINET      1       /* include internet support */
212  # endif
213  
214 +# ifndef NETINET6
215 +#  define NETINET6     0       /* dont include IPv6 support */
216 +# endif
217 +
218  # ifndef NETISO
219  #  define NETISO       0       /* do not include ISO socket support */
220  # endif
221 @@ -1307,6 +1311,14 @@
222  # endif
223  # include <sys/sysmacros.h>
224  # undef atol                   /* wounded in <stdlib.h> */
225 +# if NETINET6
226 +#  if !((__GLIBC__ == 2) && (__GLIBC_MINOR__ == 1))    /*  Native in 2.2.x  */
227 +#    include   <linux/in6.h>   /* IPv6 support */
228 +#  endif
229 +#  ifdef __GLIBC__
230 +#   undef      IPPROTO_ICMPV6  /* linux #defines, glibc enums  */
231 +#  endif
232 +# endif
233  #endif
234  
235  
236 diff -Nur sendmail-8.9.3/src/daemon.c sendmail-8.9.3.pld/src/daemon.c
237 --- sendmail-8.9.3/src/daemon.c Tue Jan 26 05:00:16 1999
238 +++ sendmail-8.9.3.pld/src/daemon.c     Wed Feb 10 18:11:17 1999
239 @@ -135,7 +135,17 @@
240                         DaemonAddr.sin.sin_addr.s_addr = INADDR_ANY;
241                 port = DaemonAddr.sin.sin_port;
242                 break;
243 -
244 +#if NETINET6
245 +         case AF_INET6:
246 +               /*
247 +                *  We should look up and handle the INADDR_ANY situation
248 +                *      for IPv6, but since it is usually all-zeros and
249 +                *      that is what we're checking for, it doesn't have
250 +                *      a high priority.
251 +                */
252 +               port = DaemonAddr.sin6.sin6_port;
253 +               break;
254 +#endif
255           default:
256                 /* unknown protocol */
257                 port = 0;
258 @@ -160,7 +170,11 @@
259           case AF_INET:
260                 DaemonAddr.sin.sin_port = port;
261                 break;
262 -
263 +#if NETINET6
264 +         case AF_INET6:
265 +               DaemonAddr.sin6.sin6_port = port;
266 +               break;
267 +#endif
268           default:
269                 /* unknown protocol */
270                 break;
271 @@ -603,6 +617,12 @@
272                                 break;
273  # endif
274  
275 +# if NETINET6
276 +                         case AF_INET6:
277 +                               socksize = sizeof DaemonAddr.sin6;
278 +                               break;
279 +# endif
280 +
281  # if NETISO
282                           case AF_ISO:
283                                 socksize = sizeof DaemonAddr.siso;
284 @@ -703,6 +723,10 @@
285                         else if (strcasecmp(v, "inet") == 0)
286                                 DaemonAddr.sa.sa_family = AF_INET;
287  #endif
288 +#if NETINET6
289 +                       else if (strcasecmp(v, "inet6") == 0)
290 +                               DaemonAddr.sa.sa_family = AF_INET6;
291 +#endif
292  #if NETISO
293                         else if (strcasecmp(v, "iso") == 0)
294                                 DaemonAddr.sa.sa_family = AF_ISO;
295 @@ -739,6 +763,27 @@
296                                 break;
297  #endif
298  
299 +#if NETINET6
300 +                         case AF_INET6:
301 +                               if (isascii(*v) && isdigit(*v))
302 +                                    (void) inet_pton(
303 +                                       DaemonAddr.sa.sa_family, v,
304 +                                       &DaemonAddr.sin6.sin6_addr);
305 +                               else
306 +                               {
307 +                                   register struct hostent *hp;
308 +
309 +                                   hp = sm_gethostbyname(v);
310 +                                   if (hp == NULL)
311 +                                       syserr("554 host \"%s\" unknown", v);
312 +                                   else
313 +                                       bcopy(hp->h_addr,
314 +                                               &DaemonAddr.sin6.sin6_addr,
315 +                                               IN6ADDRSZ);
316 +                               }
317 +                               break;
318 +#endif
319 +
320                           default:
321                                 syserr("554 Address= option unsupported for family %d",
322                                         DaemonAddr.sa.sa_family);
323 @@ -770,6 +815,22 @@
324                                 break;
325  #endif
326  
327 +#if NETINET6
328 +                         case AF_INET6:
329 +                               if (isascii(*v) && isdigit(*v))
330 +                                   DaemonAddr.sin6.sin6_port = htons(atoi(v));
331 +                               else
332 +                               {
333 +                                   register struct servent *sp;
334 +
335 +                                   sp = getservbyname(v, "tcp");
336 +                                   if (sp == NULL)
337 +                                       syserr("554 service \"%s\" unknown", v);
338 +                                   else
339 +                                       DaemonAddr.sin6.sin6_port = sp->s_port;
340 +                               }
341 +                               break;
342 +#endif
343  #if NETISO
344                           case AF_ISO:
345                                 /* assume two byte transport selector */
346 @@ -968,6 +1029,35 @@
347                         break;
348  #endif
349  
350 +#if NETINET6
351 +                 case AF_INET6:
352 +                 {
353 +                       /*
354 +                        *  IPv4-mapped IPv6 prefix --  ::ffff:0
355 +                        */
356 +                       static u_char mapbuf[ IN6ADDRSZ ] =
357 +                           { 0,0,0,0, 0,0,0,0, 0,0,0xFF,0xFF, 0,0,0,0 };
358 +                       u_char *a = (u_char *) hp->h_addr;
359 +
360 +                       /*
361 +                        *  Some platforms may try to connect to IPv4-mapped
362 +                        *      IPv6 addresses via IPv6 connections, which
363 +                        *      won't work in many cases.  If we detect that,
364 +                        *      avoid it by changing the address family.
365 +                        */
366 +                       if (bcmp( mapbuf, a, IN6ADDRSZ - INADDRSZ ))
367 +                               bcopy(a, &addr.sin6.sin6_addr, IN6ADDRSZ);
368 +                       else
369 +                       {
370 +                               bcopy(a + IN6ADDRSZ - INADDRSZ,
371 +                                       &addr.sin.sin_addr,
372 +                                       INADDRSZ);
373 +                               addr.sa.sa_family = AF_INET;
374 +                       }
375 +                       break;
376 +                 }
377 +#endif
378 +
379                   default:
380                         if (hp->h_length > sizeof addr.sa.sa_data)
381                         {
382 @@ -1012,6 +1102,13 @@
383                 break;
384  #endif
385  
386 +#if NETINET6
387 +         case AF_INET6:
388 +               addr.sin6.sin6_port = port;
389 +               addrlen = sizeof (struct sockaddr_in6);
390 +               break;
391 +#endif
392 +
393  #if NETISO
394           case AF_ISO:
395                 /* assume two byte transport selector */
396 @@ -1157,6 +1254,14 @@
397                                 break;
398  #endif
399  
400 +#if NETINET6
401 +                         case AF_INET6:
402 +                               bcopy(hp->h_addr_list[addrno++],
403 +                                     &addr.sin6.sin6_addr,
404 +                                     IN6ADDRSZ);
405 +                               break;
406 +#endif
407 +
408                           default:
409                                 bcopy(hp->h_addr_list[addrno++],
410                                         addr.sa.sa_data,
411 @@ -1295,6 +1400,34 @@
412                 if (hp->h_addrtype == AF_INET)
413                         return bcmp(ha, (char *) &sa->sin.sin_addr, hp->h_length);
414                 break;
415 +#if NETINET6
416 +         case AF_INET6:
417 +         {
418 +               u_char *a = (u_char *) &sa->sin6.sin6_addr;
419 +               /*
420 +                *  Straight binary comparison
421 +                */
422 +               if (hp->h_addrtype == AF_INET6)
423 +                       return bcmp( ha, a, hp->h_length);
424 +
425 +               /*
426 +                *  If IPv4-mapped IPv6 address, compare the IPv4 section
427 +                */
428 +               if (hp->h_addrtype == AF_INET)
429 +               {
430 +                       /*
431 +                        *  IPv4-mapped IPv6 prefix --  ::ffff:0
432 +                        */
433 +                       static u_char mapbuf[ IN6ADDRSZ ] =
434 +                           { 0,0,0,0, 0,0,0,0, 0,0,0xFF,0xFF, 0,0,0,0 };
435 +
436 +                       if (!bcmp( mapbuf, a, IN6ADDRSZ - INADDRSZ ))
437 +                           return bcmp(a + IN6ADDRSZ - INADDRSZ, ha, INADDRSZ);
438 +                       return -1;
439 +               }
440 +               break;
441 +         }
442 +#endif
443  
444         }
445         return -1;
446 @@ -2049,6 +2182,12 @@
447                 return inet_ntoa(sap->sin.sin_addr);
448  #endif
449  
450 +#if NETINET6
451 +         case AF_INET6:
452 +               return (char *) inet_ntop( sap->sa.sa_family,
453 +                       &sap->sin6.sin6_addr, buf, sizeof( buf ));
454 +#endif
455 +
456  #if NETLINK
457           case AF_LINK:
458                 snprintf(buf, sizeof buf, "[LINK: %s]",
459 @@ -2106,6 +2245,14 @@
460                 hp = sm_gethostbyaddr((char *) &sap->sin.sin_addr,
461                         INADDRSZ,
462                         AF_INET);
463 +               break;
464 +#endif
465 +
466 +#if NETINET6
467 +         case AF_INET6:
468 +               hp = sm_gethostbyaddr((char *) &sap->sin6.sin6_addr,
469 +                       IN6ADDRSZ,
470 +                       AF_INET6);
471                 break;
472  #endif
473  
474 diff -Nur sendmail-8.9.3/src/main.c sendmail-8.9.3.pld/src/main.c
475 --- sendmail-8.9.3/src/main.c   Sun Jan 10 00:31:13 1999
476 +++ sendmail-8.9.3.pld/src/main.c       Wed Feb 10 18:11:17 1999
477 @@ -457,6 +457,9 @@
478  # ifdef RES_NOALIASES
479         _res.options |= RES_NOALIASES;
480  # endif
481 +# if NETINET6 && defined(RES_USE_INET6)
482 +       _res.options |= RES_USE_INET6;
483 +# endif
484  #endif
485  
486         errno = 0;
487 @@ -1513,10 +1516,20 @@
488                         define(macid("{client_name}", NULL), RealHostName, &BlankEnvelope);
489                 define(macid("{client_addr}", NULL),
490                        newstr(anynet_ntoa(&RealHostAddr)), &BlankEnvelope);
491 -               if (RealHostAddr.sa.sa_family == AF_INET)
492 +               switch( RealHostAddr.sa.sa_family )
493 +               {
494 +                   case AF_INET:
495                         snprintf(pbuf, sizeof pbuf, "%d", RealHostAddr.sin.sin_port);
496 -               else
497 +                       break;
498 +#if    NETINET6
499 +                   case AF_INET6:
500 +                       snprintf(pbuf, sizeof pbuf, "%d", RealHostAddr.sin6.sin6_port);
501 +                       break;
502 +#endif
503 +                   default:
504                         snprintf(pbuf, sizeof pbuf, "0");
505 +                       break;
506 +               }
507                 define(macid("{client_port}", NULL), newstr(pbuf), &BlankEnvelope);
508  
509                 /* initialize maps now for check_relay ruleset */
510 diff -Nur sendmail-8.9.3/src/sendmail.h sendmail-8.9.3.pld/src/sendmail.h
511 --- sendmail-8.9.3/src/sendmail.h       Wed Jan 27 01:15:52 1999
512 +++ sendmail-8.9.3.pld/src/sendmail.h   Wed Feb 10 18:11:17 1999
513 @@ -55,6 +55,10 @@
514  # if NETINET
515  # include <netinet/in.h>
516  # endif
517 +# if NETINET6
518 +/* There is no host-independet location (yet). See conf.h */ 
519 +# endif
520 +
521  # if NETISO
522  # include <netiso/iso.h>
523  # endif
524 @@ -1035,6 +1039,9 @@
525  #endif
526  #if NETINET
527         struct sockaddr_in      sin;    /* INET family */
528 +#endif
529 +#if NETINET6
530 +       struct sockaddr_in6     sin6;   /* INET/IPv6 */
531  #endif
532  #if NETISO
533         struct sockaddr_iso     siso;   /* ISO family */
This page took 0.151385 seconds and 3 git commands to generate.