mirror of
https://github.com/sshuttle/sshuttle.git
synced 2025-01-07 06:29:01 +01:00
Print PF rules used.
Also support multiline debug output better.
This commit is contained in:
parent
2b235331d0
commit
e63e121354
@ -7,9 +7,17 @@ verbose = 0
|
|||||||
|
|
||||||
|
|
||||||
def log(s):
|
def log(s):
|
||||||
|
global logprefix
|
||||||
try:
|
try:
|
||||||
sys.stdout.flush()
|
sys.stdout.flush()
|
||||||
sys.stderr.write(logprefix + s)
|
if s.find("\n") != -1:
|
||||||
|
prefix = logprefix
|
||||||
|
s = s.rstrip("\n")
|
||||||
|
for line in s.split("\n"):
|
||||||
|
sys.stderr.write(prefix + line + "\n")
|
||||||
|
prefix = "---> "
|
||||||
|
else:
|
||||||
|
sys.stderr.write(logprefix + s)
|
||||||
sys.stderr.flush()
|
sys.stderr.flush()
|
||||||
except IOError:
|
except IOError:
|
||||||
# this could happen if stderr gets forcibly disconnected, eg. because
|
# this could happen if stderr gets forcibly disconnected, eg. because
|
||||||
|
@ -7,7 +7,7 @@ import subprocess as ssubprocess
|
|||||||
from fcntl import ioctl
|
from fcntl import ioctl
|
||||||
from ctypes import c_char, c_uint8, c_uint16, c_uint32, Union, Structure, \
|
from ctypes import c_char, c_uint8, c_uint16, c_uint32, Union, Structure, \
|
||||||
sizeof, addressof, memmove
|
sizeof, addressof, memmove
|
||||||
from sshuttle.helpers import debug1, debug2, Fatal, family_to_string
|
from sshuttle.helpers import debug1, debug2, debug3, Fatal, family_to_string
|
||||||
from sshuttle.methods import BaseMethod
|
from sshuttle.methods import BaseMethod
|
||||||
|
|
||||||
|
|
||||||
@ -215,6 +215,7 @@ class Method(BaseMethod):
|
|||||||
rules = b'\n'.join(tables + translating_rules + filtering_rules) \
|
rules = b'\n'.join(tables + translating_rules + filtering_rules) \
|
||||||
+ b'\n'
|
+ b'\n'
|
||||||
assert isinstance(rules, bytes)
|
assert isinstance(rules, bytes)
|
||||||
|
debug3("rules:\n" + rules.decode("ASCII"))
|
||||||
|
|
||||||
pf_status = pfctl('-s all')[0]
|
pf_status = pfctl('-s all')[0]
|
||||||
if b'\nrdr-anchor "sshuttle" all\n' not in pf_status:
|
if b'\nrdr-anchor "sshuttle" all\n' not in pf_status:
|
||||||
|
@ -11,12 +11,28 @@ import sshuttle.helpers
|
|||||||
@patch('sshuttle.helpers.sys.stderr')
|
@patch('sshuttle.helpers.sys.stderr')
|
||||||
def test_log(mock_stderr, mock_stdout):
|
def test_log(mock_stderr, mock_stdout):
|
||||||
sshuttle.helpers.log("message")
|
sshuttle.helpers.log("message")
|
||||||
|
sshuttle.helpers.log("message 1\n")
|
||||||
|
sshuttle.helpers.log("message 2\nline2\nline3\n")
|
||||||
|
sshuttle.helpers.log("message 3\nline2\nline3")
|
||||||
assert mock_stdout.mock_calls == [
|
assert mock_stdout.mock_calls == [
|
||||||
call.flush(),
|
call.flush(),
|
||||||
|
call.flush(),
|
||||||
|
call.flush(),
|
||||||
|
call.flush(),
|
||||||
]
|
]
|
||||||
assert mock_stderr.mock_calls == [
|
assert mock_stderr.mock_calls == [
|
||||||
call.write('prefix: message'),
|
call.write('prefix: message'),
|
||||||
call.flush(),
|
call.flush(),
|
||||||
|
call.write('prefix: message 1\n'),
|
||||||
|
call.flush(),
|
||||||
|
call.write('prefix: message 2\n'),
|
||||||
|
call.write('---> line2\n'),
|
||||||
|
call.write('---> line3\n'),
|
||||||
|
call.flush(),
|
||||||
|
call.write('prefix: message 3\n'),
|
||||||
|
call.write('---> line2\n'),
|
||||||
|
call.write('---> line3\n'),
|
||||||
|
call.flush(),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
@ -104,6 +104,7 @@ def pfctl(args, stdin=None):
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
@patch('sshuttle.helpers.verbose', new=3)
|
||||||
@patch('sshuttle.methods.pf.sys.platform', 'darwin')
|
@patch('sshuttle.methods.pf.sys.platform', 'darwin')
|
||||||
@patch('sshuttle.methods.pf.pfctl')
|
@patch('sshuttle.methods.pf.pfctl')
|
||||||
@patch('sshuttle.methods.pf.ioctl')
|
@patch('sshuttle.methods.pf.ioctl')
|
||||||
|
Loading…
Reference in New Issue
Block a user