]> granicus.if.org Git - mutt/commitdiff
A while ago I posted a similar patch which is necessary as when mutt
authorPatrick Welche <prlw1@cam.ac.uk>
Mon, 29 Dec 2003 11:37:41 +0000 (11:37 +0000)
committerPatrick Welche <prlw1@cam.ac.uk>
Mon, 29 Dec 2003 11:37:41 +0000 (11:37 +0000)
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.

m4/gssapi.m4
mutt_sasl.c

index 5c01b8111560b860035a06b73ef3d75c45f9621d..e8451eaaf58d4502098c0f560a87814cef6074d0 100644 (file)
@@ -6,7 +6,7 @@ dnl Search for a GSSAPI implementation in the standard locations plus PREFIX,
 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"
index bd9074ff9645737919bf893c0c1700174d58cf9e..329f42e65bd255aacca3cabaf959a312c2d7d7a3 100644 (file)
 #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 mutt_sasl_conn_write (CONNECTION* conn, const char* buf,
 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 @@ int mutt_sasl_client_new (CONNECTION* conn, sasl_conn_t** saslconn)
 {
   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 @@ int mutt_sasl_client_new (CONNECTION* conn, sasl_conn_t** saslconn)
 
 #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;
   }