[git] ADNS-g10 - branch, master, updated. adns-1.4-g10-6-3-g56eef0a

by Werner Koch cvs at cvs.gnupg.org
Tue Oct 20 14:52:19 CEST 2015


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "ADNS migrated to autotools/libtool".

The branch, master has been updated
       via  56eef0afa4c01d2352f8b671a9b22405dc8119db (commit)
       via  cd40bf7477fa0f245235910ed177bbcafb7cd287 (commit)
      from  eaf33fc56b3cdf5f2f52d95c6ed1d3277e281cc8 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 56eef0afa4c01d2352f8b671a9b22405dc8119db
Author: Werner Koch <wk at gnupg.org>
Date:   Tue Oct 20 14:48:23 2015 +0200

    Add flag adns_if_tormode to provide a basic TOR mode.
    
    * src/adns.h (adns_if_tormode): New.
    * src/query.c (adns_submit): For a VC in tormode.
    (adns_submit_reverse_any): Ditto.
    (adns_synchronous): Ditto.
    * src/event.c (use_socks_p, socks_connect): New.  Based on code from
    Libassuan.
    (adns__tcp_tryconnect): Move setnonblock after the init of ADDR.  Call
    socks_connect if needed.
    
    * client/adh-opts.c (global_options): Add "--use-tor"
    (ov_tormode): New.
    * client/adnshost.h (ov_tormode): New declaration.
    * client/adh-query.c (ensure_adns_init): Enable TOR mode uf OV_TORMODE
    is set.
    --
    
    This patch has the problem that connecting to the TOR server and more
    important establishing the TOR connection will block.  Changing this
    would require quite some report of the TCP code in ADNS.
    
    In fact it has always been the case that when falling back to TCP mode
    and the connect would have blocked the connection won't be established
    but times outs.  There is no retry code for if connect returns with
    EWOULDBLOCK or EINPROGRESS.
    
    To test the code this command can be used.
    
      adnshost --config 'nameserver 8.8.8.8' --use-tor NAME
    
    Signed-off-by: Werner Koch <wk at gnupg.org>

diff --git a/client/adh-opts.c b/client/adh-opts.c
index 5bb7273..5797b6c 100644
--- a/client/adh-opts.c
+++ b/client/adh-opts.c
@@ -27,7 +27,7 @@
 
 #include "adnshost.h"
 
-int ov_env=1, ov_pipe=0, ov_asynch=0;
+int ov_env=1, ov_pipe=0, ov_asynch=0, ov_tormode = 0;
 int ov_verbose= 0;
 adns_rrtype ov_type= adns_r_none;
 int ov_search=0, ov_qc_query=0, ov_qc_anshost=0, ov_qc_cname=1;
@@ -43,6 +43,8 @@ static const struct optioninfo global_options[]= {
     "f", "pipe",           &ov_pipe, 1 },
   { ot_flag,             "Allow answers to be reordered",
     "a", "asynch",         &ov_asynch, 1 },
+  { ot_flag,             "Run over TOR",
+    0, "use-tor",          &ov_tormode, 1 },
 
   { ot_desconly, "answer/error output format and destination (see below):" },
   { ot_value,            "Answers to stdout, errors as messages to stderr (default)",
diff --git a/client/adh-query.c b/client/adh-query.c
index b5cfad7..a2fb4f5 100644
--- a/client/adh-query.c
+++ b/client/adh-query.c
@@ -9,20 +9,20 @@
  *    Copyright (C) 1999-2000,2003,2006  Tony Finch
  *    Copyright (C) 1991 Massachusetts Institute of Technology
  *  (See the file INSTALL for full details.)
- *  
+ *
  *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
  *  the Free Software Foundation; either version 2, or (at your option)
  *  any later version.
- *  
+ *
  *  This program is distributed in the hope that it will be useful,
  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  *  GNU General Public License for more details.
- *  
+ *
  *  You should have received a copy of the GNU General Public License
  *  along with this program; if not, write to the Free Software Foundation,
- *  Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 
+ *  Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  */
 
 #include "adnshost.h"
@@ -35,15 +35,15 @@ static unsigned long idcounter;
 /* inet_aton implementation.  [Taken from the adns 1.0 W32 port.
    Copyright (C) 2000, 2004 Jarle (jgaa) Aase <jgaa at jgaa.com>] */
 #ifdef HAVE_W32_SYSTEM
-static int 
+static int
 inet_aton (const char *cp, struct in_addr *inp)
 {
   if (!cp || !*cp || !inp)
     {
       errno = EINVAL;
-      return -1; 
+      return -1;
     }
-  
+
   if (!strcmp(cp, "255.255.255.255"))
     {
       /*  Although this is a valid address, the old inet_addr fucntion
@@ -51,7 +51,7 @@ inet_aton (const char *cp, struct in_addr *inp)
         inp->s_addr = INADDR_NONE;
         return 0;
     }
-  
+
   inp->s_addr = inet_addr (cp);
   return (inp->s_addr == INADDR_NONE) ? -1 : 0;
 }
@@ -61,7 +61,7 @@ inet_aton (const char *cp, struct in_addr *inp)
 void ensure_adns_init(void) {
   adns_initflags initflags;
   int r;
-  
+
   if (ads) return;
 
 #ifndef HAVE_W32_SYSTEM
@@ -70,6 +70,7 @@ void ensure_adns_init(void) {
 
   initflags= adns_if_noautosys|adns_if_nosigpipe|ov_verbose;
   if (!ov_env) initflags |= adns_if_noenv;
+  if (ov_tormode) initflags |= adns_if_tormode;
 
   if (config_text) {
     r= adns_init_strcfg(&ads, initflags, stderr, config_text);
@@ -86,7 +87,7 @@ void type_info(adns_rrtype type, const char **typename_r,
 	       const void *datap, char **data_r) {
   static char buf[12];
   adns_status st;
-  
+
   st= adns_rr_info(type, typename_r, 0,0, datap,data_r);
   if (st == adns_s_nomemory) sysfail("adns_rr_info failed",ENOMEM);
   assert(!st);
@@ -99,10 +100,10 @@ void type_info(adns_rrtype type, const char **typename_r,
 static void prep_query(struct query_node **qun_r, int *quflags_r) {
   struct query_node *qun;
   char idbuf[20];
-  
+
   if (ov_pipe && !ads) usageerr("-f/--pipe not consistent with domains on command line");
   ensure_adns_init();
-  
+
   qun= malloc(sizeof(*qun));
   qun->pqfr= ov_pqfr;
   if (ov_id) {
@@ -121,10 +122,10 @@ static void prep_query(struct query_node **qun_r, int *quflags_r) {
     (ov_qc_anshost ? adns_qf_quoteok_anshost : 0) |
     (ov_qc_cname ? 0 : adns_qf_quoteok_cname) |
     ov_cname,
-    
+
   *qun_r= qun;
 }
-  
+
 void of_ptr(const struct optioninfo *oi, const char *arg, const char *arg2) {
   struct query_node *qun;
   int quflags, r;
@@ -200,7 +201,7 @@ static void print_withspace(const char *str) {
 static void print_ttl(struct query_node *qun, adns_answer *answer) {
   unsigned long ttl;
   time_t now;
-  
+
   switch (qun->pqfr.ttl) {
   case tm_none:
     return;
@@ -262,7 +263,7 @@ static void print_status(adns_status st, struct query_node *qun, adns_answer *an
 static void print_dnsfail(adns_status st, struct query_node *qun, adns_answer *answer) {
   int r;
   const char *typename, *statusstring;
-  
+
   if (ov_format == fmt_inline) {
     if (fputs("; failed ",stdout) == EOF) outerr();
     print_status(st,qun,answer);
@@ -283,7 +284,7 @@ static void print_dnsfail(adns_status st, struct query_node *qun, adns_answer *a
   }
   if (r == EOF) sysfail("write error message to stderr",errno);
 }
-    
+
 void query_done(struct query_node *qun, adns_answer *answer) {
   adns_status st;
   int rrn, nrrs;
diff --git a/client/adnshost.h b/client/adnshost.h
index 876b021..f83d1e8 100644
--- a/client/adnshost.h
+++ b/client/adnshost.h
@@ -8,20 +8,20 @@
  *    Copyright (C) 1999-2000,2003,2006  Tony Finch
  *    Copyright (C) 1991 Massachusetts Institute of Technology
  *  (See the file INSTALL for full details.)
- *  
+ *
  *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
  *  the Free Software Foundation; either version 2, or (at your option)
  *  any later version.
- *  
+ *
  *  This program is distributed in the hope that it will be useful,
  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  *  GNU General Public License for more details.
- *  
+ *
  *  You should have received a copy of the GNU General Public License
  *  along with this program; if not, write to the Free Software Foundation,
- *  Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 
+ *  Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  */
 
 #ifndef ADNSHOST_H_INCLUDED
@@ -78,7 +78,7 @@ struct perqueryflags_remember {
   int ttl;
 };
 
-extern int ov_env, ov_pipe, ov_asynch;
+extern int ov_env, ov_pipe, ov_asynch, ov_tormode;
 extern int ov_verbose;
 extern adns_rrtype ov_type;
 extern int ov_search, ov_qc_query, ov_qc_anshost, ov_qc_cname;
diff --git a/src/adns.h b/src/adns.h
index feb7cb1..6ed9a97 100644
--- a/src/adns.h
+++ b/src/adns.h
@@ -92,7 +92,8 @@ typedef enum { /* In general, or together the desired flags: */
  adns_if_eintr=       0x0020,/* allow _wait and _synchronous to return EINTR */
  adns_if_nosigpipe=   0x0040,/* applic has SIGPIPE ignored, do not protect */
  adns_if_checkc_entex=0x0100,/* consistency checks on entry/exit to adns fns */
- adns_if_checkc_freq= 0x0300 /* consistency checks very frequently (slow!) */
+ adns_if_checkc_freq= 0x0300,/* consistency checks very frequently (slow!) */
+ adns_if_tormode=     0x1000 /* route all trafic via TOR.  */
 } adns_initflags;
 
 typedef enum { /* In general, or together the desired flags: */
diff --git a/src/event.c b/src/event.c
index 6a88f98..8aae3af 100644
--- a/src/event.c
+++ b/src/event.c
@@ -9,6 +9,7 @@
  *    Copyright (C) 1997-2000,2003,2006  Ian Jackson
  *    Copyright (C) 1999-2000,2003,2006  Tony Finch
  *    Copyright (C) 1991 Massachusetts Institute of Technology
+ *    Copyright (C) 2015 g10 Code GmbH
  *  (See the file INSTALL for full details.)
  *
  *  This program is free software; you can redistribute it and/or modify
@@ -96,6 +97,177 @@ static void tcp_broken_events(adns_state ads) {
   ads->tcpstate= server_disconnected;
 }
 
+
+/* Return true if SOCKS shall be used.  This is the case if
+   adns_if_tormode is set and the desired address is not the loopback
+   address.  */
+static int
+use_socks_p (adns_state ads, const struct sockaddr *addr)
+{
+  if (!(ads->iflags & adns_if_tormode))
+    return 0;
+  else if (addr->sa_family == AF_INET6)
+    {
+      const struct sockaddr_in6 *addr_in6 = (struct sockaddr_in6 *)addr;
+      const unsigned char *s;
+      int i;
+
+      s = (unsigned char *)&addr_in6->sin6_addr.s6_addr;
+      if (s[15] != 1)
+        return 1;   /* Last octet is not 1 - not the loopback address.  */
+      for (i=0; i < 15; i++, s++)
+        if (*s)
+          return 1; /* Non-zero octet found - not the loopback address.  */
+
+      return 0; /* This is the loopback address.  */
+    }
+  else if (addr->sa_family == AF_INET)
+    {
+      const struct sockaddr_in *addr_in = (struct sockaddr_in *)addr;
+
+      if (*(unsigned char*)&addr_in->sin_addr.s_addr == 127)
+        return 0; /* Loopback (127.0.0.0/8) */
+
+      return 1;
+    }
+  else
+    return 0;
+}
+
+
+/* Connect to TOR using the SOCKS5 protocol.  We assume that the
+   connection to the SOCKS proxy (TOR server) does not block; if it
+   would block we return and the the usual retry logic of the caller
+   kicks in.  */
+static int
+socks_connect (adns_state ads, int fd,
+               const struct sockaddr *addr, socklen_t length)
+{
+  int ret;
+  struct sockaddr_in  proxyaddr_in;
+  struct sockaddr *proxyaddr;
+  size_t proxyaddrlen;
+  struct sockaddr_in6 *addr_in6;
+  struct sockaddr_in  *addr_in;
+  unsigned char buffer[22];
+  size_t buflen;
+
+  memset (&proxyaddr_in, 0, sizeof proxyaddr_in);
+
+  /* Connect to local host.  */
+  /* Fixme: First try to use IPv6.  */
+  proxyaddr_in.sin_family = AF_INET;
+  proxyaddr_in.sin_port = htons (9050);
+  proxyaddr_in.sin_addr.s_addr = htonl (INADDR_LOOPBACK);
+  proxyaddr = (struct sockaddr *)&proxyaddr_in;
+  proxyaddrlen = sizeof proxyaddr_in;
+  ret = adns__sock_connect(fd, proxyaddr, proxyaddrlen);
+  if (ret)
+    return ret;
+
+  /* Negotiate method.  */
+  buffer[0] = 5; /* RFC-1928 VER field.  */
+  buffer[1] = 1; /* NMETHODS */
+  buffer[2] = 0; /* Method: No authentication required. */
+  adns__sigpipe_protect(ads);
+  ret = adns__sock_write(fd, buffer, 3);
+  adns__sigpipe_unprotect(ads);
+  if (ret != 3)
+    {
+      if (ret >= 0)
+        errno = EIO;
+      return -1;
+    }
+  ret = adns__sock_read(fd, buffer, 2);
+  if (ret < 0)
+    return ret;
+  if (ret != 2 || buffer[0] != 5 || buffer[1] != 0 )
+    {
+      /* Socks server returned wrong version or does not support our
+         requested method.  */
+      errno = ENOTSUP; /* Fixme: Is there a better errno? */
+      return -1;
+    }
+
+  /* Send request details (rfc-1928, 4).  */
+  buffer[0] = 5; /* VER  */
+  buffer[1] = 1; /* CMD = CONNECT  */
+  buffer[2] = 0; /* RSV  */
+  if (addr->sa_family == AF_INET6)
+    {
+      addr_in6 = (struct sockaddr_in6 *)addr;
+
+      buffer[3] = 4; /* ATYP = IPv6 */
+      memcpy (buffer+ 4, &addr_in6->sin6_addr.s6_addr, 16); /* DST.ADDR */
+      memcpy (buffer+20, &addr_in6->sin6_port, 2);          /* DST.PORT */
+      buflen = 22;
+    }
+  else
+    {
+      addr_in = (struct sockaddr_in *)addr;
+
+      buffer[3] = 1; /* ATYP = IPv4 */
+      memcpy (buffer+4, &addr_in->sin_addr.s_addr, 4); /* DST.ADDR */
+      memcpy (buffer+8, &addr_in->sin_port, 2);        /* DST.PORT */
+      buflen = 10;
+    }
+  adns__sigpipe_protect(ads);
+  ret = adns__sock_write(fd, buffer, buflen);
+  adns__sigpipe_unprotect(ads);
+  if (ret != buflen)
+    {
+      if (ret >= 0)
+        errno = EIO;
+      return -1;
+    }
+  ret = adns__sock_read(fd, buffer, buflen);
+  if (ret < 0)
+    return ret;
+  if (ret != buflen || buffer[0] != 5 || buffer[2] != 0 )
+    {
+      /* Socks server returned wrong version or the reserved field is
+         not zero.  */
+      errno = EPROTO;
+      return -1;
+    }
+  if (buffer[1])
+    {
+      switch (buffer[1])
+        {
+        case 0x01: /* general SOCKS server failure.  */
+          errno = ENETDOWN;
+          break;
+        case 0x02: /* connection not allowed by ruleset.  */
+          errno = EACCES;
+          break;
+        case 0x03: /* Network unreachable */
+          errno = ENETUNREACH;
+          break;
+        case 0x04: /* Host unreachable */
+          errno = EHOSTUNREACH;
+          break;
+        case 0x05: /* Connection refused */
+          errno = ECONNREFUSED;
+          break;
+        case 0x06: /* TTL expired */
+          errno = ETIMEDOUT;
+          break;
+        case 0x08: /* Address type not supported */
+          errno = EPROTONOSUPPORT;
+          break;
+        case 0x07: /* Command not supported */
+        default:
+          errno = ENOTSUP; /* Fixme: Is there a better errno? */
+        }
+      return -1;
+    }
+  /* FIXME: We have not way to store the actual address used by the
+     server.  */
+
+  return 0;
+}
+
+
 void adns__tcp_tryconnect(adns_state ads, struct timeval now) {
   int r, fd, tries;
   struct sockaddr_in addr;
@@ -127,21 +299,41 @@ void adns__tcp_tryconnect(adns_state ads, struct timeval now) {
       adns__diag(ads,-1,0,"cannot create TCP socket: %s",strerror(errno));
       return;
     }
-    r= adns__setnonblock(ads,fd);
-    if (r) {
-      adns__diag(ads,-1,0,"cannot make TCP socket nonblocking:"
-		 " %s",strerror(r));
-      adns__sock_close(fd);
-      return;
-    }
     memset(&addr,0,sizeof(addr));
     addr.sin_family= AF_INET;
     addr.sin_port= htons(DNS_PORT);
     addr.sin_addr= ads->servers[ads->tcpserver].addr;
-    r= adns__sock_connect(fd,(const struct sockaddr*)&addr,sizeof(addr));
+    if (use_socks_p(ads, (const struct sockaddr*)&addr))
+      {
+        r= socks_connect(ads, fd,(const struct sockaddr*)&addr,sizeof(addr));
+        if (!r)
+          {
+            r= adns__setnonblock(ads,fd);
+            if (r) {
+              adns__diag(ads,-1,0,"cannot make TCP socket nonblocking:"
+                         " %s",strerror(r));
+              adns__sock_close(fd);
+              return;
+            }
+          }
+      }
+    else
+      {
+        r= adns__setnonblock(ads,fd);
+        if (r) {
+          adns__diag(ads,-1,0,"cannot make TCP socket nonblocking:"
+                     " %s",strerror(r));
+          adns__sock_close(fd);
+          return;
+        }
+        r= adns__sock_connect(fd,(const struct sockaddr*)&addr,sizeof(addr));
+      }
     ads->tcpsocket= fd;
     ads->tcpstate= server_connecting;
-    if (r==0) { tcp_connected(ads,now); return; }
+    if (r==0) {
+      tcp_connected(ads,now);
+      return;
+    }
     if (errno == EWOULDBLOCK || errno == EINPROGRESS) {
       ads->tcptimeout= now;
       timevaladd(&ads->tcptimeout,TCPCONNMS);
diff --git a/src/internal.h b/src/internal.h
index c3aa213..6bc0702 100644
--- a/src/internal.h
+++ b/src/internal.h
@@ -277,7 +277,7 @@ struct adns__query {
    *        too big for UDP /             UDP timeout  \  \ send via UDP
    *        send via TCP   /              more retries  \  \
    *        when conn'd   /                  desired     \  \
-   *                     |     	       	       	       	  |  |
+   *        or TOR-mode  |     	       	       	       	  |  |
    *                     v				  |  v
    *              +-----------+         	    	+-------------+
    *              | tcpw/tcpw | ________                | tosend/udpw |
diff --git a/src/query.c b/src/query.c
index 948b5d3..c719bad 100644
--- a/src/query.c
+++ b/src/query.c
@@ -222,12 +222,15 @@ int adns_submit(adns_state ads,
 
   adns__consistency(ads,0,cc_entex);
 
+  if ((ads->iflags & adns_if_tormode))
+    flags |= adns_qf_usevc;
+
   typei= adns__findtype(type);
   if (!typei) return ENOSYS;
 
   r= gettimeofday(&now,0); if (r) goto x_errno;
   qu= query_alloc(ads,typei,type,flags,now); if (!qu) goto x_errno;
-  
+
   qu->ctx.ext= context;
   qu->ctx.callback= 0;
   memset(&qu->ctx.info,0,sizeof(qu->ctx.info));
@@ -287,6 +290,8 @@ int adns_submit_reverse_any(adns_state ads,
   int r, lreq;
 
   flags &= ~adns_qf_search;
+  if ((ads->iflags & adns_if_tormode))
+    flags |= adns_qf_usevc;
 
   if (addr->sa_family != AF_INET) return ENOSYS;
   iaddr= (const unsigned char*)
@@ -315,6 +320,10 @@ int adns_submit_reverse(adns_state ads,
 			void *context,
 			adns_query *query_r) {
   if (type != adns_r_ptr && type != adns_r_ptr_raw) return EINVAL;
+
+  if ((ads->iflags & adns_if_tormode))
+    flags |= adns_qf_usevc;
+
   return adns_submit_reverse_any(ads,addr,"in-addr.arpa",
 				 type,flags,context,query_r);
 }
@@ -326,7 +335,10 @@ int adns_synchronous(adns_state ads,
 		     adns_answer **answer_r) {
   adns_query qu;
   int r;
-  
+
+  if ((ads->iflags & adns_if_tormode))
+    flags |= adns_qf_usevc;
+
   r= adns_submit(ads,owner,type,flags,0,&qu);
   if (r) return r;
 

commit cd40bf7477fa0f245235910ed177bbcafb7cd287
Author: Werner Koch <wk at gnupg.org>
Date:   Tue Oct 20 08:24:36 2015 +0200

    Silence compiler warnings.
    
    * regress/hplayback.c (Q_vb): Remove unused var r.
    * src/event.c (tcp_close): Remove unused var serv.
    * src/reply.c (adns__procdgram): Remove unused var arstart.
    * src/internal.h (GET_W, GTE_L): Do not return arg tv; it is not used.
    --
    
    Also remove some trailing white space.
    
    Signed-off-by: Werner Koch <wk at gnupg.org>

diff --git a/regress/hplayback.c b/regress/hplayback.c
index 594f7e6..f8d920c 100644
--- a/regress/hplayback.c
+++ b/regress/hplayback.c
@@ -140,7 +140,7 @@ static void Ppollfds(struct pollfd *fds, int nfds) {
   for (i=0; i<nfds; i++) {
     Pstring("{fd=","{fd= in pollfds");
     fds->fd= strtoul(vb2.buf+vb2.used,&ep,10);
-    vb2.used= ep - (char*)vb2.buf;    
+    vb2.used= ep - (char*)vb2.buf;
     Pstring(", events=",", events= in pollfds");
     fds->events= Ppollfdevents();
     Pstring(", revents=",", revents= in pollfds");
@@ -194,11 +194,10 @@ static int Pbytes(byte *buf, int maxlen) {
   }
 }
 void Q_vb(void) {
-  int r;
   const char *nl;
   Tensurerecordfile();
   if (!adns__vbuf_ensure(&vb2,vb.used+2)) Tnomem();
-  r= fread(vb2.buf,1,vb.used+2,Tinputfile);
+  fread(vb2.buf,1,vb.used+2,Tinputfile);
   if (feof(Tinputfile)) {
     fprintf(stderr,"adns test harness: input ends prematurely; program did:\n %.*s\n",
            vb.used,vb.buf);
@@ -241,9 +240,9 @@ int Hselect(	int max , fd_set *rfds , fd_set *wfds , fd_set *efds , struct timev
   r= strtoul(vb2.buf+8,&ep,10);
   if (*ep && *ep!=' ') Psyntax("return value not E* or positive number");
   vb2.used= ep - (char*)vb2.buf;
-	Parg("rfds"); Pfdset(rfds,max); 
-	Parg("wfds"); Pfdset(wfds,max); 
-	Parg("efds"); Pfdset(efds,max); 
+	Parg("rfds"); Pfdset(rfds,max);
+	Parg("wfds"); Pfdset(wfds,max);
+	Parg("efds"); Pfdset(efds,max);
  assert(vb2.used <= amtread);
  if (vb2.used != amtread) Psyntax("junk at end of line");
  P_updatetime();
@@ -273,7 +272,7 @@ int Hpoll(	struct pollfd *fds , int nfds , int timeout 	) {
   r= strtoul(vb2.buf+6,&ep,10);
   if (*ep && *ep!=' ') Psyntax("return value not E* or positive number");
   vb2.used= ep - (char*)vb2.buf;
-        Parg("fds"); Ppollfds(fds,nfds); 
+        Parg("fds"); Ppollfds(fds,nfds);
  assert(vb2.used <= amtread);
  if (vb2.used != amtread) Psyntax("junk at end of line");
  P_updatetime();
@@ -283,8 +282,8 @@ int Hpoll(	struct pollfd *fds , int nfds , int timeout 	) {
 int Hsocket(	int domain , int type , int protocol 	) {
  int r, amtread;
  char *ep;
-	Tmust("socket","domain",domain==AF_INET); 
-  Tmust("socket","type",type==SOCK_STREAM || type==SOCK_DGRAM); 
+	Tmust("socket","domain",domain==AF_INET);
+  Tmust("socket","type",type==SOCK_STREAM || type==SOCK_DGRAM);
  Qsocket(	 type 	);
  if (!adns__vbuf_ensure(&vb2,1000)) Tnomem();
  fgets(vb2.buf,vb2.avail,Tinputfile); Pcheckinput();
@@ -312,13 +311,13 @@ int Hsocket(	int domain , int type , int protocol 	) {
 }
 int Hfcntl(	int fd , int cmd , ... 	) {
  int r, amtread;
-	va_list al; long arg; 
+	va_list al; long arg;
   Tmust("fcntl","cmd",cmd==F_SETFL || cmd==F_GETFL);
   if (cmd == F_SETFL) {
     va_start(al,cmd); arg= va_arg(al,long); va_end(al);
   } else {
     arg= 0;
-  } 
+  }
  Qfcntl(	fd , cmd , arg 	);
  if (!adns__vbuf_ensure(&vb2,1000)) Tnomem();
  fgets(vb2.buf,vb2.avail,Tinputfile); Pcheckinput();
@@ -469,7 +468,7 @@ int Hclose(	int fd 	) {
 int Hsendto(	int fd , const void *msg , int msglen , unsigned int flags , const struct sockaddr *addr , int addrlen 	) {
  int r, amtread;
  char *ep;
-	Tmust("sendto","flags",flags==0); 
+	Tmust("sendto","flags",flags==0);
  Qsendto(	fd , msg , msglen , addr , addrlen 	);
  if (!adns__vbuf_ensure(&vb2,1000)) Tnomem();
  fgets(vb2.buf,vb2.avail,Tinputfile); Pcheckinput();
@@ -497,8 +496,8 @@ int Hsendto(	int fd , const void *msg , int msglen , unsigned int flags , const
 }
 int Hrecvfrom(	int fd , void *buf , int buflen , unsigned int flags , struct sockaddr *addr , int *addrlen 	) {
  int r, amtread;
-	Tmust("recvfrom","flags",flags==0); 
-	Tmust("recvfrom","*addrlen",*addrlen>=sizeof(struct sockaddr_in)); 
+	Tmust("recvfrom","flags",flags==0);
+	Tmust("recvfrom","*addrlen",*addrlen>=sizeof(struct sockaddr_in));
  Qrecvfrom(	fd , buflen , *addrlen 	);
  if (!adns__vbuf_ensure(&vb2,1000)) Tnomem();
  fgets(vb2.buf,vb2.avail,Tinputfile); Pcheckinput();
@@ -519,10 +518,10 @@ int Hrecvfrom(	int fd , void *buf , int buflen , unsigned int flags , struct soc
   if (memcmp(vb2.buf+10,"OK",2)) Psyntax("success/fail not E* or OK");
   vb2.used= 10+2;
   r= 0;
-	Parg("addr"); Paddr(addr,addrlen); 
+	Parg("addr"); Paddr(addr,addrlen);
  assert(vb2.used <= amtread);
  if (vb2.used != amtread) Psyntax("junk at end of line");
-	r= Pbytes(buf,buflen); 
+	r= Pbytes(buf,buflen);
  P_updatetime();
  return r;
 }
@@ -550,7 +549,7 @@ int Hread(	int fd , void *buf , size_t buflen 	) {
   r= 0;
  assert(vb2.used <= amtread);
  if (vb2.used != amtread) Psyntax("junk at end of line");
-	r= Pbytes(buf,buflen); 
+	r= Pbytes(buf,buflen);
  P_updatetime();
  return r;
 }
diff --git a/src/event.c b/src/event.c
index 2bf689e..6a88f98 100644
--- a/src/event.c
+++ b/src/event.c
@@ -10,20 +10,20 @@
  *    Copyright (C) 1999-2000,2003,2006  Tony Finch
  *    Copyright (C) 1991 Massachusetts Institute of Technology
  *  (See the file INSTALL for full details.)
- *  
+ *
  *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
  *  the Free Software Foundation; either version 2, or (at your option)
  *  any later version.
- *  
+ *
  *  This program is distributed in the hope that it will be useful,
  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  *  GNU General Public License for more details.
- *  
+ *
  *  You should have received a copy of the GNU General Public License
  *  along with this program; if not, write to the Free Software Foundation,
- *  Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 
+ *  Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  */
 
 #include <errno.h>
@@ -45,9 +45,6 @@
 /* TCP connection management. */
 
 static void tcp_close(adns_state ads) {
-  int serv;
-  
-  serv= ads->tcpserver;
   adns__sock_close(ads->tcpsocket);
   ads->tcpsocket= -1;
   ads->tcprecv.used= ads->tcprecv_skip= ads->tcpsend.used= 0;
@@ -56,7 +53,7 @@ static void tcp_close(adns_state ads) {
 void adns__tcp_broken(adns_state ads, const char *what, const char *why) {
   int serv;
   adns_query qu;
-  
+
   assert(ads->tcpstate == server_connecting || ads->tcpstate == server_ok);
   serv= ads->tcpserver;
   if (what) adns__warn(ads,serv,0,"TCP connection failed: %s: %s",what,why);
@@ -74,7 +71,7 @@ void adns__tcp_broken(adns_state ads, const char *what, const char *why) {
 
 static void tcp_connected(adns_state ads, struct timeval now) {
   adns_query qu, nqu;
-  
+
   adns__debug(ads,ads->tcpserver,0,"TCP connected");
   ads->tcpstate= server_ok;
   for (qu= ads->tcpw.head; qu && ads->tcpstate == server_ok; qu= nqu) {
@@ -86,7 +83,7 @@ static void tcp_connected(adns_state ads, struct timeval now) {
 
 static void tcp_broken_events(adns_state ads) {
   adns_query qu, nqu;
-  
+
   assert(ads->tcpstate == server_broken);
   for (qu= ads->tcpw.head; qu; qu= nqu) {
     nqu= qu->next;
@@ -115,7 +112,7 @@ void adns__tcp_tryconnect(adns_state ads, struct timeval now) {
     default:
       abort();
     }
-    
+
     assert(!ads->tcpsend.used);
     assert(!ads->tcprecv.used);
     assert(!ads->tcprecv_skip);
@@ -180,7 +177,7 @@ static void inter_immed(struct timeval **tv_io, struct timeval *tvbuf) {
 
   timerclear(rbuf);
 }
-    
+
 static void inter_maxto(struct timeval **tv_io, struct timeval *tvbuf,
 			struct timeval maxto) {
   struct timeval *rbuf;
@@ -217,7 +214,7 @@ static void timeouts_queue(adns_state ads, int act,
 			   struct timeval **tv_io, struct timeval *tvbuf,
 			   struct timeval now, struct query_queue *queue) {
   adns_query qu, nqu;
-  
+
   for (qu= queue->head; qu; qu= nqu) {
     nqu= qu->next;
     if (!timercmp(&now,&qu->timeout,>)) {
@@ -341,7 +338,7 @@ int adns_processreadable(adns_state ads, int fd, const struct timeval *now) {
   int want, dgramlen, r, udpaddrlen, serv, old_skip;
   byte udpbuf[DNS_MAXUDP];
   struct sockaddr_in udpaddr;
-  
+
   adns__consistency(ads,0,cc_entex);
 
   switch (ads->tcpstate) {
@@ -441,7 +438,7 @@ xit:
 
 int adns_processwriteable(adns_state ads, int fd, const struct timeval *now) {
   int r;
-  
+
   adns__consistency(ads,0,cc_entex);
 
   switch (ads->tcpstate) {
@@ -495,7 +492,7 @@ xit:
   adns__consistency(ads,0,cc_entex);
   return r;
 }
-  
+
 int adns_processexceptional(adns_state ads, int fd,
 			    const struct timeval *now) {
   adns__consistency(ads,0,cc_entex);
@@ -522,7 +519,7 @@ static void fd_event(adns_state ads, int fd,
 				 const struct timeval *now),
 		     struct timeval now, int *r_r) {
   int r;
-  
+
   if (!(revent & pollflag)) return;
   if (fds && !(fd<maxfd && FD_ISSET(fd,fds))) return;
   r= func(ads,fd,&now);
@@ -566,7 +563,7 @@ void adns_beforeselect(adns_state ads, int *maxfd_io, fd_set *readfds_io,
   struct timeval tv_nowbuf;
   struct pollfd pollfds[MAX_POLLFDS];
   int i, fd, maxfd, npollfds;
-  
+
   adns__consistency(ads,0,cc_entex);
 
   if (tv_mod && (!*tv_mod || (*tv_mod)->tv_sec || (*tv_mod)->tv_usec)) {
@@ -620,7 +617,7 @@ void adns_globalsystemfailure(adns_state ads) {
 
   while (ads->udpw.head) adns__query_fail(ads->udpw.head, adns_s_systemfail);
   while (ads->tcpw.head) adns__query_fail(ads->tcpw.head, adns_s_systemfail);
-  
+
   switch (ads->tcpstate) {
   case server_connecting:
   case server_ok:
@@ -699,7 +696,7 @@ int adns_wait(adns_state ads,
   int r, maxfd, rsel;
   fd_set readfds, writefds, exceptfds;
   struct timeval tvbuf, *tvp;
-  
+
   adns__consistency(ads,*query_io,cc_entex);
   for (;;) {
     r= adns__internal_check(ads,query_io,answer_r,context_r);
@@ -731,7 +728,7 @@ int adns_check(adns_state ads,
 	       void **context_r) {
   struct timeval now;
   int r;
-  
+
   adns__consistency(ads,*query_io,cc_entex);
   r= gettimeofday(&now,0);
   if (!r) adns__autosys(ads,now);
diff --git a/src/internal.h b/src/internal.h
index a2e8c43..c3aa213 100644
--- a/src/internal.h
+++ b/src/internal.h
@@ -759,13 +759,13 @@ static inline int errno_resources(int e) { return e==ENOMEM || e==ENOBUFS; }
 
 #define GETIL_B(cb) (((dgram)[(cb)++]) & 0x0ff)
 #define GET_B(cb,tv) ((tv)= GETIL_B((cb)))
-#define GET_W(cb,tv) ((tv)=0,(tv)|=(GETIL_B((cb))<<8), (tv)|=GETIL_B(cb), (tv))
+#define GET_W(cb,tv) ((tv)=0,(tv)|=(GETIL_B((cb))<<8), (tv)|=GETIL_B(cb))
 #define GET_L(cb,tv) ( (tv)=0,				\
 		       (tv)|=(GETIL_B((cb))<<24),	\
 		       (tv)|=(GETIL_B((cb))<<16),	\
 		       (tv)|=(GETIL_B((cb))<<8),	\
-		       (tv)|=GETIL_B(cb),		\
-		       (tv) )
+		       (tv)|=GETIL_B(cb)		\
+		      )
 
 
 
diff --git a/src/query.c b/src/query.c
index d09702e..948b5d3 100644
--- a/src/query.c
+++ b/src/query.c
@@ -10,20 +10,20 @@
  *    Copyright (C) 1999-2000,2003,2006  Tony Finch
  *    Copyright (C) 1991 Massachusetts Institute of Technology
  *  (See the file INSTALL for full details.)
- *  
+ *
  *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
  *  the Free Software Foundation; either version 2, or (at your option)
  *  any later version.
- *  
+ *
  *  This program is distributed in the hope that it will be useful,
  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  *  GNU General Public License for more details.
- *  
+ *
  *  You should have received a copy of the GNU General Public License
  *  along with this program; if not, write to the Free Software Foundation,
- *  Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 
+ *  Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  */
 
 #include "internal.h"
@@ -41,11 +41,11 @@ static adns_query query_alloc(adns_state ads,
 			      adns_queryflags flags, struct timeval now) {
   /* Allocate a virgin query and return it. */
   adns_query qu;
-  
+
   qu= malloc(sizeof(*qu));  if (!qu) return 0;
   qu->answer= malloc(sizeof(*qu->answer));
   if (!qu->answer) { free(qu); return 0; }
-  
+
   qu->ads= ads;
   qu->state= query_tosend;
   qu->back= qu->next= qu->parent= 0;
@@ -100,11 +100,11 @@ static void query_submit(adns_state ads, adns_query qu,
 
   qu->query_dgram= malloc(qu->vb.used);
   if (!qu->query_dgram) { adns__query_fail(qu,adns_s_nomemory); return; }
-  
+
   qu->id= id;
   qu->query_dglen= qu->vb.used;
   memcpy(qu->query_dgram,qu->vb.buf,qu->vb.used);
-  
+
   adns__query_send(qu,now);
 }
 
@@ -121,7 +121,7 @@ adns_status adns__internal_submit(adns_state ads, adns_query *query_r,
 
   memcpy(&qu->ctx,ctx,sizeof(qu->ctx));
   query_submit(ads,qu, typei,qumsg_vb,id,flags,now);
-  
+
   return adns_s_ok;
 }
 
@@ -153,7 +153,7 @@ static void query_simple(adns_state ads, adns_query qu,
 void adns__search_next(adns_state ads, adns_query qu, struct timeval now) {
   const char *nextentry;
   adns_status stat;
-  
+
   if (qu->search_doneabs<0) {
     nextentry= 0;
     qu->search_doneabs= 1;
@@ -237,7 +237,7 @@ int adns_submit(adns_state ads,
   ol= strlen(owner);
   if (!ol) { stat= adns_s_querydomaininvalid; goto x_adnsfail; }
   if (ol>DNS_MAXDOMAIN+1) { stat= adns_s_querydomaintoolong; goto x_adnsfail; }
-				 
+
   if (ol>=1 && owner[ol-1]=='.' && (ol<2 || owner[ol-2]!='\\')) {
     flags &= ~adns_qf_search;
     qu->flags= flags;
@@ -349,7 +349,7 @@ static void *alloc_common(adns_query qu, size_t sz) {
 
 void *adns__alloc_interim(adns_query qu, size_t sz) {
   void *rv;
-  
+
   sz= MEM_ROUND(sz);
   rv= alloc_common(qu,sz);
   if (!rv) return 0;
@@ -359,7 +359,7 @@ void *adns__alloc_interim(adns_query qu, size_t sz) {
 
 void *adns__alloc_preserved(adns_query qu, size_t sz) {
   void *rv;
-  
+
   sz= MEM_ROUND(sz);
   rv= adns__alloc_interim(qu,sz);
   if (!rv) return 0;
@@ -380,7 +380,7 @@ void adns__transfer_interim(adns_query from, adns_query to,
 
   assert(!to->final_allocspace);
   assert(!from->final_allocspace);
-  
+
   LIST_UNLINK(from->allocations,an);
   LIST_LINK_TAIL(to->allocations,an);
 
@@ -490,17 +490,17 @@ static void makefinal_query(adns_query qu) {
   qu->final_allocspace= (byte*)ans + MEM_ROUND(sizeof(*ans));
   adns__makefinal_str(qu,&ans->cname);
   adns__makefinal_str(qu,&ans->owner);
-  
+
   if (ans->nrrs) {
     adns__makefinal_block(qu, &ans->rrs.untyped, ans->nrrs*ans->rrsz);
 
     for (rrn=0; rrn<ans->nrrs; rrn++)
       qu->typei->makefinal(qu, ans->rrs.bytes + rrn*ans->rrsz);
   }
-  
+
   free_query_allocs(qu);
   return;
-  
+
  x_nomem:
   qu->preserved_allocd= 0;
   qu->answer->cname= 0;
@@ -573,7 +573,7 @@ void adns__makefinal_str(adns_query qu, char **strp) {
   l= strlen(before)+1;
   after= adns__alloc_final(qu,l);
   memcpy(after,before,l);
-  *strp= after;  
+  *strp= after;
 }
 
 void adns__makefinal_block(adns_query qu, void **blpp, size_t sz) {
diff --git a/src/reply.c b/src/reply.c
index 64b41d7..68087c1 100644
--- a/src/reply.c
+++ b/src/reply.c
@@ -8,33 +8,33 @@
  *    Copyright (C) 1999-2000,2003,2006  Tony Finch
  *    Copyright (C) 1991 Massachusetts Institute of Technology
  *  (See the file INSTALL for full details.)
- *  
+ *
  *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
  *  the Free Software Foundation; either version 2, or (at your option)
  *  any later version.
- *  
+ *
  *  This program is distributed in the hope that it will be useful,
  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  *  GNU General Public License for more details.
- *  
+ *
  *  You should have received a copy of the GNU General Public License
  *  along with this program; if not, write to the Free Software Foundation,
- *  Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 
+ *  Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  */
 
 #include <stdlib.h>
 
 #include "internal.h"
-    
+
 void adns__procdgram(adns_state ads, const byte *dgram, int dglen,
 		     int serv, int viatcp, struct timeval now) {
   int cbyte, rrstart, wantedrrs, rri, foundsoa, foundns, cname_here;
   int id, f1, f2, qdcount, ancount, nscount, arcount;
   int flg_ra, flg_rd, flg_tc, flg_qr, opcode;
   int rrtype, rrclass, rdlength, rdstart;
-  int anstart, nsstart, arstart;
+  int anstart, nsstart;
   int ownermatched, l, nrrs;
   unsigned long ttl, soattl;
   const typeinfo *typei;
@@ -44,7 +44,7 @@ void adns__procdgram(adns_state ads, const byte *dgram, int dglen,
   vbuf tempvb;
   byte *newquery, *rrsdata;
   parseinfo pai;
-  
+
   if (dglen<DNS_HDRSIZE) {
     adns__diag(ads,serv,0,"received datagram"
 	       " too short for message header (%d)",dglen);
@@ -68,7 +68,7 @@ void adns__procdgram(adns_state ads, const byte *dgram, int dglen,
   rcode= (f2&0x0f);
 
   cname_here= 0;
-  
+
   if (!flg_qr) {
     adns__diag(ads,serv,0,"server sent us a query, not a response");
     return;
@@ -80,7 +80,7 @@ void adns__procdgram(adns_state ads, const byte *dgram, int dglen,
   }
 
   qu= 0;
-  /* See if we can find the relevant query, or leave qu=0 otherwise ... */   
+  /* See if we can find the relevant query, or leave qu=0 otherwise ... */
 
   if (qdcount == 1) {
     for (qu= viatcp ? ads->tcpw.head : ads->udpw.head; qu; qu= nqu) {
@@ -105,7 +105,7 @@ void adns__procdgram(adns_state ads, const byte *dgram, int dglen,
       else LIST_UNLINK(ads->udpw,qu);
     }
   }
-  
+
   /* If we're going to ignore the packet, we return as soon as we have
    * failed the query (if any) and printed the warning message (if
    * any).
@@ -155,9 +155,8 @@ void adns__procdgram(adns_state ads, const byte *dgram, int dglen,
 
   /* We're definitely going to do something with this packet and this
    * query now. */
-  
+
   anstart= qu->query_dglen;
-  arstart= -1;
 
   /* Now, take a look at the answer section, and see if it is complete.
    * If it has any CNAMEs we stuff them in the answer.
@@ -241,7 +240,7 @@ void adns__procdgram(adns_state ads, const byte *dgram, int dglen,
    * which we could use.
    */
   if (flg_tc) goto x_truncated;
-  
+
   nsstart= cbyte;
 
   if (!wantedrrs) {
@@ -266,7 +265,7 @@ void adns__procdgram(adns_state ads, const byte *dgram, int dglen,
       if (rrtype == adns_r_soa_raw) { foundsoa= 1; soattl= ttl; break; }
       else if (rrtype == adns_r_ns_raw) { foundns= 1; }
     }
-    
+
     if (rcode == rcode_nxdomain) {
       /* We still wanted to look for the SOA so we could find the TTL. */
       adns__update_expires(qu,soattl,now);
@@ -360,29 +359,29 @@ void adns__procdgram(adns_state ads, const byte *dgram, int dglen,
   return;
 
  x_truncated:
-  
+
   if (!flg_tc) {
     adns__diag(ads,serv,qu,"server sent datagram which points outside itself");
     adns__query_fail(qu,adns_s_invalidresponse);
     return;
   }
   qu->flags |= adns_qf_usevc;
-  
+
  x_restartquery:
   if (qu->cname_dgram) {
     st= adns__mkquery_frdgram(qu->ads,&qu->vb,&qu->id,
 			      qu->cname_dgram,qu->cname_dglen,qu->cname_begin,
 			      qu->answer->type, qu->flags);
     if (st) { adns__query_fail(qu,st); return; }
-    
+
     newquery= realloc(qu->query_dgram,qu->vb.used);
     if (!newquery) { adns__query_fail(qu,adns_s_nomemory); return; }
-    
+
     qu->query_dgram= newquery;
     qu->query_dglen= qu->vb.used;
     memcpy(newquery,qu->vb.buf,qu->vb.used);
   }
-  
+
   if (qu->state == query_tcpw) qu->state= query_tosend;
   qu->retries= 0;
   adns__reset_preserved(qu);

-----------------------------------------------------------------------

Summary of changes:
 client/adh-opts.c   |   4 +-
 client/adh-query.c  |  35 ++++----
 client/adnshost.h   |  10 +--
 regress/hplayback.c |  33 ++++---
 src/adns.h          |   3 +-
 src/event.c         | 249 +++++++++++++++++++++++++++++++++++++++++++++-------
 src/internal.h      |   8 +-
 src/query.c         |  52 ++++++-----
 src/reply.c         |  37 ++++----
 9 files changed, 317 insertions(+), 114 deletions(-)


hooks/post-receive
-- 
ADNS migrated to autotools/libtool
http://git.gnupg.org




More information about the Gnupg-commits mailing list