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.
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
10 * g10/call-dirmngr.c (ks_status_cb): Detect and print the new
13 Signed-off-by: Werner Koch <wk@gnupg.org>
14 (cherry picked from commit 770b75a746836773909af25ccb9b480e61cea677)
16 dirmngr/ks-engine-hkp.c | 60 ++++++++++++++++++++++++++++++++++++-------------
17 g10/call-dirmngr.c | 26 ++++++++++++++++++++-
18 2 files changed, 70 insertions(+), 16 deletions(-)
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)
28 +/* Print a warninng iff Tor is not running but Tor has been requested.
29 + * Also return true if it is not running. */
31 +tor_not_running_p (ctrl_t ctrl)
38 + sock = assuan_sock_connect_byname (NULL, 0, 0, NULL, ASSUAN_SOCK_TOR);
39 + if (sock != ASSUAN_INVALID_FD)
41 + assuan_sock_close (sock);
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);
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,
60 + if (gpg_err_code (err) == GPG_ERR_ECONNREFUSED)
61 + tor_not_running_p (ctrl);
65 @@ -1180,13 +1207,13 @@ send_request (ctrl_t ctrl, const char *request, const char *hostportstr,
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
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)
81 @@ -1197,16 +1224,9 @@ handle_send_request_error (gpg_error_t err, const char *request,
82 switch (gpg_err_code (err))
84 case GPG_ERR_ECONNREFUSED:
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");
93 - assuan_sock_close (sock);
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. */
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,
105 + case GPG_ERR_EACCES:
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);
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))
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))
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))
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)
151 struct ks_status_parm_s *parm = opaque;
154 + const char *s, *s2;
157 if ((s = has_leading_keyword (line, parm->keyword? parm->keyword : "SOURCE")))
159 @@ -385,6 +386,29 @@ ks_status_cb (void *opaque, const char *line)
160 err = gpg_error_from_syserror ();
163 + else if ((s = has_leading_keyword (line, "WARNING")))
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");
174 + log_info (_("WARNING: %s\n"), warn);
177 + while (*s2 && !spacep (s2))
179 + while (*s2 && spacep (s2))
182 + print_further_info ("%s", s2);