chiark / gitweb /
Import gnupg2_2.1.17-3.debian.tar.bz2
[gnupg2.git] / debian / patches / 0019-dirmngr-Make-sure-Tor-mode-is-also-set-for-DNS-on-SI.patch
1 From: Werner Koch <wk@gnupg.org>
2 Date: Tue, 3 Jan 2017 12:03:28 +0100
3 Subject: dirmngr: Make sure Tor mode is also set for DNS on SIGHUP.
4
5 * dirmngr/dns-stuff.c (enable_dns_tormode): Always succeed.
6 (reload_dns_stuff): Reset tor port.
7 * dirmngr/dirmngr.c (set_tor_mode): Also enable Tor mode for DNS.
8 (main): Remove warning that Tor mode may not fully work.
9 * dirmngr/server.c (cmd_dns_cert): Remove explicit Tor for DNS
10 initialization.
11 * dirmngr/t-dns-stuff.c (main): Remove option --new-circuit and error
12 checking for enable_dns_tormode.
13 --
14
15 This patch also resets the port on SIGHUP so that after starting Tor
16 SIGHUP is sufficient to use Tor.  Without the SIGHUP and when not
17 using the Tor browser Dirmngr would keep on trying the Tor browser
18 port.
19
20 Signed-off-by: Werner Koch <wk@gnupg.org>
21 (cherry picked from commit 969512401603639e4467ede7d892f1b02582c2c9)
22 ---
23  dirmngr/dirmngr.c     | 10 +++-------
24  dirmngr/dns-stuff.c   | 12 +++++++-----
25  dirmngr/dns-stuff.h   |  6 +++---
26  dirmngr/server.c      |  7 -------
27  dirmngr/t-dns-stuff.c | 16 +---------------
28  5 files changed, 14 insertions(+), 37 deletions(-)
29
30 diff --git a/dirmngr/dirmngr.c b/dirmngr/dirmngr.c
31 index 0b8bb02e6..5abfe78c6 100644
32 --- a/dirmngr/dirmngr.c
33 +++ b/dirmngr/dirmngr.c
34 @@ -474,6 +474,9 @@ set_tor_mode (void)
35  {
36    if (opt.use_tor)
37      {
38 +      /* Enable Tor mode and when called again force a new curcuit
39 +       * (e.g. on SIGHUP).  */
40 +      enable_dns_tormode (1);
41        if (assuan_sock_set_flag (ASSUAN_INVALID_FD, "tor-mode", 1))
42          {
43            log_error ("error enabling Tor mode: %s\n", strerror (errno));
44 @@ -912,13 +915,6 @@ main (int argc, char **argv)
45    log_info ("NOTE: this is a development version!\n");
46  #endif
47  
48 -  if (opt.use_tor)
49 -    {
50 -      log_info ("WARNING: ***************************************\n");
51 -      log_info ("WARNING: Tor mode (--use-tor) MAY NOT FULLY WORK!\n");
52 -      log_info ("WARNING: ***************************************\n");
53 -    }
54 -
55    /* Print a warning if an argument looks like an option.  */
56    if (!opt.quiet && !(pargs.flags & ARGPARSE_FLAG_STOP_SEEN))
57      {
58 diff --git a/dirmngr/dns-stuff.c b/dirmngr/dns-stuff.c
59 index cf8cefb2e..e32e1e3e1 100644
60 --- a/dirmngr/dns-stuff.c
61 +++ b/dirmngr/dns-stuff.c
62 @@ -199,9 +199,9 @@ recursive_resolver_p (void)
63  }
64  
65  
66 -/* Sets the module in Tor mode.  Returns 0 is this is possible or an
67 -   error code.  */
68 -gpg_error_t
69 +/* Puts this module eternally into Tor mode.  When called agained with
70 + * NEW_CIRCUIT request a new TOR circuit for the next DNS query.  */
71 +void
72  enable_dns_tormode (int new_circuit)
73  {
74    if (!*tor_socks_user || new_circuit)
75 @@ -215,7 +215,6 @@ enable_dns_tormode (int new_circuit)
76        counter++;
77      }
78    tor_mode = 1;
79 -  return 0;
80  }
81  
82  
83 @@ -548,7 +547,10 @@ reload_dns_stuff (int force)
84        libdns_reinit_pending = 0;
85      }
86    else
87 -    libdns_reinit_pending = 1;
88 +    {
89 +      libdns_reinit_pending = 1;
90 +      libdns_tor_port = 0;  /* Start again with the default port.  */
91 +    }
92  #else
93    (void)force;
94  #endif
95 diff --git a/dirmngr/dns-stuff.h b/dirmngr/dns-stuff.h
96 index 0a4a4de2f..eb7fe7246 100644
97 --- a/dirmngr/dns-stuff.h
98 +++ b/dirmngr/dns-stuff.h
99 @@ -113,9 +113,9 @@ void enable_recursive_resolver (int yes);
100  /* Return true iff the recursive resolver is used.  */
101  int recursive_resolver_p (void);
102  
103 -/* Calling this function switches the DNS code into Tor mode if
104 -   possibe.  Return 0 on success.  */
105 -gpg_error_t enable_dns_tormode (int new_circuit);
106 +/* Put this module eternally into Tor mode.  When called agained with
107 + * NEW_CIRCUIT request a new TOR circuit for the next DNS query.  */
108 +void enable_dns_tormode (int new_circuit);
109  
110  /* Change the default IP address of the nameserver to IPADDR.  The
111     address needs to be a numerical IP address and will be used for the
112 diff --git a/dirmngr/server.c b/dirmngr/server.c
113 index a785238dc..28c2cd428 100644
114 --- a/dirmngr/server.c
115 +++ b/dirmngr/server.c
116 @@ -709,13 +709,6 @@ cmd_dns_cert (assuan_context_t ctx, char *line)
117          }
118      }
119  
120 -  if (opt.use_tor && (err = enable_dns_tormode (0)))
121 -    {
122 -      /* Tor mode is requested but the DNS code can't enable it.  */
123 -      assuan_set_error (ctx, err, "error enabling Tor mode");
124 -      goto leave;
125 -    }
126 -
127    if (pka_mode || dane_mode)
128      {
129        char *domain;     /* Points to mbox.  */
130 diff --git a/dirmngr/t-dns-stuff.c b/dirmngr/t-dns-stuff.c
131 index b087b5ead..bc4ca9a51 100644
132 --- a/dirmngr/t-dns-stuff.c
133 +++ b/dirmngr/t-dns-stuff.c
134 @@ -51,7 +51,6 @@ main (int argc, char **argv)
135    gpg_error_t err;
136    int any_options = 0;
137    int opt_tor = 0;
138 -  int opt_new_circuit = 0;
139    int opt_cert = 0;
140    int opt_srv = 0;
141    int opt_bracket = 0;
142 @@ -103,11 +102,6 @@ main (int argc, char **argv)
143            opt_tor = 1;
144            argc--; argv++;
145          }
146 -      else if (!strcmp (*argv, "--new-circuit"))
147 -        {
148 -          opt_new_circuit = 1;
149 -          argc--; argv++;
150 -        }
151        else if (!strcmp (*argv, "--standard-resolver"))
152          {
153            enable_standard_resolver (1);
154 @@ -171,15 +165,7 @@ main (int argc, char **argv)
155    init_sockets ();
156  
157    if (opt_tor)
158 -    {
159 -      err = enable_dns_tormode (opt_new_circuit);
160 -      if (err)
161 -        {
162 -          fprintf (stderr, "error switching into Tor mode: %s\n",
163 -                   gpg_strerror (err));
164 -          exit (1);
165 -        }
166 -    }
167 +    enable_dns_tormode (0);
168  
169    if (opt_cert)
170      {