Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
sshuttle
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
pub
sshuttle
Commits
a266e7a8
Unverified
Commit
a266e7a8
authored
Oct 19, 2020
by
Brian May
Committed by
GitHub
Oct 19, 2020
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #545 from skuhl/avoid-touching-etc-hosts
Only write /etc/hosts when necessary.
parents
1dbf2163
e1106a33
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
8 additions
and
5 deletions
+8
-5
firewall.py
sshuttle/firewall.py
+7
-4
test_firewall.py
tests/client/test_firewall.py
+1
-1
No files found.
sshuttle/firewall.py
View file @
a266e7a8
...
@@ -47,7 +47,10 @@ def rewrite_etc_hosts(hostmap, port):
...
@@ -47,7 +47,10 @@ def rewrite_etc_hosts(hostmap, port):
os
.
rename
(
tmpname
,
HOSTSFILE
)
os
.
rename
(
tmpname
,
HOSTSFILE
)
def
restore_etc_hosts
(
port
):
def
restore_etc_hosts
(
hostmap
,
port
):
# Only restore if we added hosts to /etc/hosts previously.
if
len
(
hostmap
)
>
0
:
debug2
(
'firewall manager: undoing /etc/hosts changes.
\n
'
)
rewrite_etc_hosts
({},
port
)
rewrite_etc_hosts
({},
port
)
...
@@ -275,8 +278,8 @@ def main(method_name, syslog):
...
@@ -275,8 +278,8 @@ def main(method_name, syslog):
debug2
(
'An error occurred, ignoring it.'
)
debug2
(
'An error occurred, ignoring it.'
)
try
:
try
:
debug2
(
'firewall manager: undoing /etc/hosts changes.
\n
'
)
# debug2() message printed in restore_etc_hosts() function.
restore_etc_hosts
(
port_v6
or
port_v4
)
restore_etc_hosts
(
hostmap
,
port_v6
or
port_v4
)
except
BaseException
:
except
BaseException
:
try
:
try
:
debug1
(
"firewall manager: "
debug1
(
"firewall manager: "
...
...
tests/client/test_firewall.py
View file @
a266e7a8
...
@@ -55,7 +55,7 @@ def test_rewrite_etc_hosts(tmpdir):
...
@@ -55,7 +55,7 @@ def test_rewrite_etc_hosts(tmpdir):
assert
line
==
""
assert
line
==
""
with
patch
(
'sshuttle.firewall.HOSTSFILE'
,
new
=
str
(
new_hosts
)):
with
patch
(
'sshuttle.firewall.HOSTSFILE'
,
new
=
str
(
new_hosts
)):
sshuttle
.
firewall
.
restore_etc_hosts
(
10
)
sshuttle
.
firewall
.
restore_etc_hosts
(
hostmap
,
10
)
assert
orig_hosts
.
computehash
()
==
new_hosts
.
computehash
()
assert
orig_hosts
.
computehash
()
==
new_hosts
.
computehash
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment