|
9 | 9 | from sshuttle.helpers import debug1, debug2, Fatal
|
10 | 10 | from sshuttle.methods import get_auto_method, get_method
|
11 | 11 |
|
12 |
| -hostmap = {} |
13 | 12 | HOSTSFILE = '/etc/hosts'
|
14 | 13 |
|
15 | 14 |
|
16 |
| -def rewrite_etc_hosts(port): |
| 15 | +def rewrite_etc_hosts(hostmap, port): |
17 | 16 | BAKFILE = '%s.sbak' % HOSTSFILE
|
18 | 17 | APPEND = '# sshuttle-firewall-%d AUTOCREATED' % port
|
19 | 18 | old_content = ''
|
@@ -48,9 +47,7 @@ def rewrite_etc_hosts(port):
|
48 | 47 |
|
49 | 48 |
|
50 | 49 | def restore_etc_hosts(port):
|
51 |
| - global hostmap |
52 |
| - hostmap = {} |
53 |
| - rewrite_etc_hosts(port) |
| 50 | + rewrite_etc_hosts({}, port) |
54 | 51 |
|
55 | 52 |
|
56 | 53 | # Isolate function that needs to be replaced for tests
|
@@ -87,6 +84,7 @@ def setup_daemon():
|
87 | 84 | # are hopefully harmless.
|
88 | 85 | def main(method_name, syslog):
|
89 | 86 | stdin, stdout = setup_daemon()
|
| 87 | + hostmap = {} |
90 | 88 |
|
91 | 89 | debug1('firewall manager: Starting firewall with Python version %s\n'
|
92 | 90 | % platform.python_version())
|
@@ -222,7 +220,7 @@ def main(method_name, syslog):
|
222 | 220 | (name, ip) = line[5:].strip().split(',', 1)
|
223 | 221 | hostmap[name] = ip
|
224 | 222 | debug2('firewall manager: setting up /etc/hosts.\n')
|
225 |
| - rewrite_etc_hosts(port_v6 or port_v4) |
| 223 | + rewrite_etc_hosts(hostmap, port_v6 or port_v4) |
226 | 224 | elif line:
|
227 | 225 | if not method.firewall_command(line):
|
228 | 226 | raise Fatal('firewall: expected command, got %r' % line)
|
|
0 commit comments