<<< Date Index >>>     <<< Thread Index >>>

ipv6 broken



A while ago I posted a similar patch which is necessary as when mutt
tries to connect to an imap server over ipv6 it stores the address
in a sockaddr which may not be large enough to hold the ipv6 address.
At the time, we wondered about autoconfigurating things, however, on
reflection, the code with USE_SASL2 already assumes things about
the existence of getnameinfo etc, so I don't think that checks for
getnameinfo or replacement functions are necessary.

Thoughts?

Cheers,

Patrick
Index: mutt_sasl.c
===================================================================
RCS file: /home/roessler/cvs/mutt/mutt_sasl.c,v
retrieving revision 3.4
diff -u -r3.4 mutt_sasl.c
--- mutt_sasl.c 11 Sep 2003 16:59:54 -0000      3.4
+++ mutt_sasl.c 28 Dec 2003 00:20:37 -0000
@@ -32,6 +32,50 @@
 #include <sys/socket.h>
 #include <netinet/in.h>
 
+#ifdef USE_SASL2
+static int getnameinfo_err(int ret)
+{
+  int err;
+  dprint (1, (debugfile, "getnameinfo: "));
+  switch(ret)
+  {
+     case EAI_AGAIN:
+       dprint (1, (debugfile, "The name could not be resolved at this time.  
Future attempts may succeed.\n"));
+       err=SASL_TRYAGAIN;
+       break;
+     case EAI_BADFLAGS:
+       dprint (1, (debugfile, "The flags had an invalid value.\n"));
+       err=SASL_BADPARAM;
+       break;
+     case EAI_FAIL:
+       dprint (1, (debugfile, "A non-recoverable error occurred.\n"));
+       err=SASL_FAIL;
+       break;
+     case EAI_FAMILY:
+       dprint (1, (debugfile, "The address family was not recognized or the 
address length was invalid for the specified family.\n"));
+       err=SASL_BADPROT;
+       break;
+     case EAI_MEMORY:
+       dprint (1, (debugfile, "There was a memory allocation failure.\n"));
+       err=SASL_NOMEM;
+       break;
+     case EAI_NONAME:
+       dprint (1, (debugfile, "The name does not resolve for the supplied 
parameters.  NI_NAMEREQD is set and the host's name cannot be located, or both 
nodename and servname were null.\n"));
+       err=SASL_FAIL; /* no real equivalent */
+       break;
+     case EAI_SYSTEM:
+       dprint (1, (debugfile, "A system error occurred.  The error code can be 
found in errno(%d,%s)).\n",errno,strerror(errno)));
+       err=SASL_FAIL; /* no real equivalent */
+       break;
+     default:
+       dprint (1, (debugfile, "Unknown error %d\n",ret));
+       err=SASL_FAIL; /* no real equivalent */
+       break;
+  }
+  return err;
+}
+#endif
+
 /* arbitrary. SASL will probably use a smaller buffer anyway. OTOH it's
  * been a while since I've had access to an SASL server which negotiated
  * a protection buffer. */ 
@@ -64,15 +108,18 @@
 static int iptostring(const struct sockaddr *addr, socklen_t addrlen,
                      char *out, unsigned outlen) {
     char hbuf[NI_MAXHOST], pbuf[NI_MAXSERV];
+    int ret;
     
     if(!addr || !out) return SASL_BADPARAM;
 
-    getnameinfo(addr, addrlen, hbuf, sizeof(hbuf), pbuf, sizeof(pbuf),
-                NI_NUMERICHOST |
+    ret=getnameinfo(addr, addrlen, hbuf, sizeof(hbuf), pbuf, sizeof(pbuf),
+                   NI_NUMERICHOST |
 #ifdef NI_WITHSCOPEID
-               NI_WITHSCOPEID |
+                  NI_WITHSCOPEID |
 #endif
-               NI_NUMERICSERV);
+                  NI_NUMERICSERV);
+    if(ret)
+      return getnameinfo_err(ret);
 
     if(outlen < strlen(hbuf) + strlen(pbuf) + 2)
         return SASL_BUFOVER;
@@ -124,7 +171,7 @@
 {
   sasl_security_properties_t secprops;
 #ifdef USE_SASL2
-  struct sockaddr local, remote;
+  struct sockaddr_storage local, remote;
   socklen_t size;
   char iplocalport[IP_PORT_BUFLEN], ipremoteport[IP_PORT_BUFLEN];
 #else
@@ -151,23 +198,23 @@
 
 #ifdef USE_SASL2
   size = sizeof (local);
-  if (getsockname (conn->fd, &local, &size)){
+  if (getsockname (conn->fd, (struct sockaddr *)&local, &size)){
     dprint (1, (debugfile, "mutt_sasl_client_new: getsockname for local 
failed\n"));
     return -1;
   }
   else 
-  if (iptostring(&local, size, iplocalport, IP_PORT_BUFLEN) != SASL_OK){
+  if (iptostring((struct sockaddr *)&local, local.ss_len, iplocalport, 
IP_PORT_BUFLEN) != SASL_OK){
     dprint (1, (debugfile, "mutt_sasl_client_new: iptostring for local 
failed\n"));
     return -1;
   }
   
   size = sizeof (remote);
-  if (getpeername (conn->fd, &remote, &size)){
+  if (getpeername (conn->fd, (struct sockaddr *)&remote, &size)){
     dprint (1, (debugfile, "mutt_sasl_client_new: getsockname for remote 
failed\n"));
     return -1;
   }
   else 
-  if (iptostring(&remote, size, ipremoteport, IP_PORT_BUFLEN) != SASL_OK){
+  if (iptostring((struct sockaddr *)&remote, remote.ss_len, ipremoteport, 
IP_PORT_BUFLEN) != SASL_OK){
     dprint (1, (debugfile, "mutt_sasl_client_new: iptostring for remote 
failed\n"));
     return -1;
   }
Index: m4/gssapi.m4
===================================================================
RCS file: /home/roessler/cvs/mutt/m4/gssapi.m4,v
retrieving revision 3.1
diff -u -r3.1 gssapi.m4
--- m4/gssapi.m4        18 Jun 2002 09:52:13 -0000      3.1
+++ m4/gssapi.m4        28 Dec 2003 00:20:41 -0000
@@ -6,7 +6,7 @@
 dnl if it is set and not "yes".
 dnl Defines GSSAPI_CFLAGS and GSSAPI_LIBS if found.
 dnl Defines GSSAPI_IMPL to "Heimdal", "MIT", or "OldMIT", or "none" if not 
found
-AC_DEFUN(MUTT_AM_PATH_GSSAPI,
+AC_DEFUN([MUTT_AM_PATH_GSSAPI],
 [
   GSSAPI_PREFIX=[$]$1
   GSSAPI_IMPL="none"