chiark / gitweb /
gnupg2 (2.1.18-8~deb9u1) stretch; urgency=medium
[gnupg2.git] / debian / patches / 0016-gpg-Print-a-warning-on-Tor-problems.patch
1 From: Werner Koch <wk@gnupg.org>
2 Date: Tue, 24 Jan 2017 20:45:31 +0100
3 Subject: gpg: Print a warning on Tor problems.
4
5 * dirmngr/ks-engine-hkp.c (tor_not_running_p): New.
6 (map_host): Call that to print a warning.
7 (handle_send_request_error): Ditto and avoid marking the host dead.
8 Also print a tor_config_problem warning.  Add arg CTRL; adjust callers
9 to pass that new arg.
10 * g10/call-dirmngr.c (ks_status_cb): Detect and print the new
11 warnings.
12
13 Signed-off-by: Werner Koch <wk@gnupg.org>
14 (cherry picked from commit 770b75a746836773909af25ccb9b480e61cea677)
15 ---
16  dirmngr/ks-engine-hkp.c | 60 ++++++++++++++++++++++++++++++++++++-------------
17  g10/call-dirmngr.c      | 26 ++++++++++++++++++++-
18  2 files changed, 70 insertions(+), 16 deletions(-)
19
20 diff --git a/dirmngr/ks-engine-hkp.c b/dirmngr/ks-engine-hkp.c
21 index dad83efcd..858cd2f26 100644
22 --- a/dirmngr/ks-engine-hkp.c
23 +++ b/dirmngr/ks-engine-hkp.c
24 @@ -278,6 +278,31 @@ arecords_is_pool (dns_addrinfo_t aibuf)
25  }
26  
27  
28 +/* Print a warninng iff Tor is not running but Tor has been requested.
29 + * Also return true if it is not running.  */
30 +static int
31 +tor_not_running_p (ctrl_t ctrl)
32 +{
33 +  assuan_fd_t sock;
34 +
35 +  if (!opt.use_tor)
36 +    return 0;
37 +
38 +  sock = assuan_sock_connect_byname (NULL, 0, 0, NULL, ASSUAN_SOCK_TOR);
39 +  if (sock != ASSUAN_INVALID_FD)
40 +    {
41 +      assuan_sock_close (sock);
42 +      return 0;
43 +    }
44 +
45 +  log_info ("(it seems Tor is not running)\n");
46 +  dirmngr_status (ctrl, "WARNING", "tor_not_running 0",
47 +                  "Tor is enabled but the local Tor daemon"
48 +                  " seems to be down", NULL);
49 +  return 1;
50 +}
51 +
52 +
53  /* Add the host AI under the NAME into the HOSTTABLE.  If PORT is not
54     zero, it specifies which port to use to talk to the host.  If NAME
55     specifies a pool (as indicated by IS_POOL), update the given
56 @@ -475,6 +500,8 @@ map_host (ctrl_t ctrl, const char *name, const char *srvtag, int force_reselect,
57            if (err)
58              {
59                xfree (reftbl);
60 +              if (gpg_err_code (err) == GPG_ERR_ECONNREFUSED)
61 +                tor_not_running_p (ctrl);
62                return err;
63              }
64  
65 @@ -1180,13 +1207,13 @@ send_request (ctrl_t ctrl, const char *request, const char *hostportstr,
66  }
67  
68  
69 -/* Helper to evaluate the error code ERR form a send_request() call
70 +/* Helper to evaluate the error code ERR from a send_request() call
71     with REQUEST.  The function returns true if the caller shall try
72     again.  TRIES_LEFT points to a variable to track the number of
73     retries; this function decrements it and won't return true if it is
74     down to zero. */
75  static int
76 -handle_send_request_error (gpg_error_t err, const char *request,
77 +handle_send_request_error (ctrl_t ctrl, gpg_error_t err, const char *request,
78                             unsigned int *tries_left)
79  {
80    int retry = 0;
81 @@ -1197,16 +1224,9 @@ handle_send_request_error (gpg_error_t err, const char *request,
82    switch (gpg_err_code (err))
83      {
84      case GPG_ERR_ECONNREFUSED:
85 -      if (opt.use_tor)
86 -        {
87 -          assuan_fd_t sock;
88 -
89 -          sock = assuan_sock_connect_byname (NULL, 0, 0, NULL, ASSUAN_SOCK_TOR);
90 -          if (sock == ASSUAN_INVALID_FD)
91 -            log_info ("(it seems Tor is not running)\n");
92 -          else
93 -            assuan_sock_close (sock);
94 -        }
95 +      if (tor_not_running_p (ctrl))
96 +        break; /* A retry does not make sense.  */
97 +      /* Okay: Tor is up or --use-tor is not used.  */
98        /*FALLTHRU*/
99      case GPG_ERR_ENETUNREACH:
100      case GPG_ERR_ENETDOWN:
101 @@ -1224,6 +1244,16 @@ handle_send_request_error (gpg_error_t err, const char *request,
102          }
103        break;
104  
105 +    case GPG_ERR_EACCES:
106 +      if (opt.use_tor)
107 +        {
108 +          log_info ("(Tor configuration problem)\n");
109 +          dirmngr_status (ctrl, "WARNING", "tor_config_problem 0",
110 +                          "Please check that the \"SocksPort\" flag "
111 +                          "\"IPv6Traffic\" is set in torrc", NULL);
112 +        }
113 +      break;
114 +
115      default:
116        break;
117      }
118 @@ -1334,7 +1364,7 @@ ks_hkp_search (ctrl_t ctrl, parsed_uri_t uri, const char *pattern,
119    /* Send the request.  */
120    err = send_request (ctrl, request, hostport, httphost, httpflags,
121                        NULL, NULL, &fp, r_http_status);
122 -  if (handle_send_request_error (err, request, &tries))
123 +  if (handle_send_request_error (ctrl, err, request, &tries))
124      {
125        reselect = 1;
126        goto again;
127 @@ -1468,7 +1498,7 @@ ks_hkp_get (ctrl_t ctrl, parsed_uri_t uri, const char *keyspec, estream_t *r_fp)
128    /* Send the request.  */
129    err = send_request (ctrl, request, hostport, httphost, httpflags,
130                        NULL, NULL, &fp, NULL);
131 -  if (handle_send_request_error (err, request, &tries))
132 +  if (handle_send_request_error (ctrl, err, request, &tries))
133      {
134        reselect = 1;
135        goto again;
136 @@ -1577,7 +1607,7 @@ ks_hkp_put (ctrl_t ctrl, parsed_uri_t uri, const void *data, size_t datalen)
137    /* Send the request.  */
138    err = send_request (ctrl, request, hostport, httphost, 0,
139                        put_post_cb, &parm, &fp, NULL);
140 -  if (handle_send_request_error (err, request, &tries))
141 +  if (handle_send_request_error (ctrl, err, request, &tries))
142      {
143        reselect = 1;
144        goto again;
145 diff --git a/g10/call-dirmngr.c b/g10/call-dirmngr.c
146 index 4be9da117..2f2ba982e 100644
147 --- a/g10/call-dirmngr.c
148 +++ b/g10/call-dirmngr.c
149 @@ -374,7 +374,8 @@ ks_status_cb (void *opaque, const char *line)
150  {
151    struct ks_status_parm_s *parm = opaque;
152    gpg_error_t err = 0;
153 -  const char *s;
154 +  const char *s, *s2;
155 +  const char *warn;
156  
157    if ((s = has_leading_keyword (line, parm->keyword? parm->keyword : "SOURCE")))
158      {
159 @@ -385,6 +386,29 @@ ks_status_cb (void *opaque, const char *line)
160              err = gpg_error_from_syserror ();
161          }
162      }
163 +  else if ((s = has_leading_keyword (line, "WARNING")))
164 +    {
165 +      if ((s2 = has_leading_keyword (s, "tor_not_running")))
166 +        warn = _("Tor is not running");
167 +      else if ((s2 = has_leading_keyword (s, "tor_config_problem")))
168 +        warn = _("Tor is not properly configured");
169 +      else
170 +        warn = NULL;
171 +
172 +      if (warn)
173 +        {
174 +          log_info (_("WARNING: %s\n"), warn);
175 +          if (s2)
176 +            {
177 +              while (*s2 && !spacep (s2))
178 +                s2++;
179 +              while (*s2 && spacep (s2))
180 +                s2++;
181 +              if (*s2)
182 +                print_further_info ("%s", s2);
183 +            }
184 +        }
185 +    }
186  
187    return err;
188  }