mirror of
https://github.com/sshuttle/sshuttle.git
synced 2025-04-21 09:48:51 +02:00
Make hostwatch locale-independent (#379)
* Make hostwatch locale-independent See #377: hostwatch used to call netstat and parse the result, without setting the locale. The problem is converting the binary output to a unicode string, as the locale may be utf-8, latin-1, or literally anything. Setting the locale to C avoids this issue, as netstat's source strings to not use non-ASCII characters. * Break line, check all other invocations
This commit is contained in:
parent
23516ebd71
commit
6ad4473c87
@ -220,6 +220,7 @@ class FirewallClient:
|
|||||||
if argv[0] == 'su':
|
if argv[0] == 'su':
|
||||||
sys.stderr.write('[local su] ')
|
sys.stderr.write('[local su] ')
|
||||||
self.p = ssubprocess.Popen(argv, stdout=s1, preexec_fn=setup)
|
self.p = ssubprocess.Popen(argv, stdout=s1, preexec_fn=setup)
|
||||||
|
# No env: Talking to `FirewallClient.start`, which has no i18n.
|
||||||
e = None
|
e = None
|
||||||
break
|
break
|
||||||
except OSError as e:
|
except OSError as e:
|
||||||
|
@ -125,9 +125,14 @@ def _check_dns(hostname):
|
|||||||
|
|
||||||
def _check_netstat():
|
def _check_netstat():
|
||||||
debug2(' > netstat\n')
|
debug2(' > netstat\n')
|
||||||
|
env = {
|
||||||
|
'PATH': os.environ['PATH'],
|
||||||
|
'LC_ALL': "C",
|
||||||
|
}
|
||||||
argv = ['netstat', '-n']
|
argv = ['netstat', '-n']
|
||||||
try:
|
try:
|
||||||
p = ssubprocess.Popen(argv, stdout=ssubprocess.PIPE, stderr=null)
|
p = ssubprocess.Popen(argv, stdout=ssubprocess.PIPE, stderr=null,
|
||||||
|
env=env)
|
||||||
content = p.stdout.read().decode("ASCII")
|
content = p.stdout.read().decode("ASCII")
|
||||||
p.wait()
|
p.wait()
|
||||||
except OSError:
|
except OSError:
|
||||||
@ -145,10 +150,15 @@ def _check_smb(hostname):
|
|||||||
global _smb_ok
|
global _smb_ok
|
||||||
if not _smb_ok:
|
if not _smb_ok:
|
||||||
return
|
return
|
||||||
argv = ['smbclient', '-U', '%', '-L', hostname]
|
|
||||||
debug2(' > smb: %s\n' % hostname)
|
debug2(' > smb: %s\n' % hostname)
|
||||||
|
env = {
|
||||||
|
'PATH': os.environ['PATH'],
|
||||||
|
'LC_ALL': "C",
|
||||||
|
}
|
||||||
|
argv = ['smbclient', '-U', '%', '-L', hostname]
|
||||||
try:
|
try:
|
||||||
p = ssubprocess.Popen(argv, stdout=ssubprocess.PIPE, stderr=null)
|
p = ssubprocess.Popen(argv, stdout=ssubprocess.PIPE, stderr=null,
|
||||||
|
env=env)
|
||||||
lines = p.stdout.readlines()
|
lines = p.stdout.readlines()
|
||||||
p.wait()
|
p.wait()
|
||||||
except OSError:
|
except OSError:
|
||||||
@ -203,10 +213,15 @@ def _check_nmb(hostname, is_workgroup, is_master):
|
|||||||
global _nmb_ok
|
global _nmb_ok
|
||||||
if not _nmb_ok:
|
if not _nmb_ok:
|
||||||
return
|
return
|
||||||
argv = ['nmblookup'] + ['-M'] * is_master + ['--', hostname]
|
|
||||||
debug2(' > n%d%d: %s\n' % (is_workgroup, is_master, hostname))
|
debug2(' > n%d%d: %s\n' % (is_workgroup, is_master, hostname))
|
||||||
|
env = {
|
||||||
|
'PATH': os.environ['PATH'],
|
||||||
|
'LC_ALL': "C",
|
||||||
|
}
|
||||||
|
argv = ['nmblookup'] + ['-M'] * is_master + ['--', hostname]
|
||||||
try:
|
try:
|
||||||
p = ssubprocess.Popen(argv, stdout=ssubprocess.PIPE, stderr=null)
|
p = ssubprocess.Popen(argv, stdout=ssubprocess.PIPE, stderr=null,
|
||||||
|
env=env)
|
||||||
lines = p.stdout.readlines()
|
lines = p.stdout.readlines()
|
||||||
rv = p.wait()
|
rv = p.wait()
|
||||||
except OSError:
|
except OSError:
|
||||||
|
@ -106,6 +106,7 @@ def _sysctl_set(name, val):
|
|||||||
argv = ['sysctl', '-w', '%s=%s' % (name, val)]
|
argv = ['sysctl', '-w', '%s=%s' % (name, val)]
|
||||||
debug1('>> %s\n' % ' '.join(argv))
|
debug1('>> %s\n' % ' '.join(argv))
|
||||||
return ssubprocess.call(argv, stdout=open(os.devnull, 'w'))
|
return ssubprocess.call(argv, stdout=open(os.devnull, 'w'))
|
||||||
|
# No env: No output. (Or error that won't be parsed.)
|
||||||
|
|
||||||
|
|
||||||
_changedctls = []
|
_changedctls = []
|
||||||
@ -139,6 +140,7 @@ def ipfw(*args):
|
|||||||
argv = ['ipfw', '-q'] + list(args)
|
argv = ['ipfw', '-q'] + list(args)
|
||||||
debug1('>> %s\n' % ' '.join(argv))
|
debug1('>> %s\n' % ' '.join(argv))
|
||||||
rv = ssubprocess.call(argv)
|
rv = ssubprocess.call(argv)
|
||||||
|
# No env: No output. (Or error that won't be parsed.)
|
||||||
if rv:
|
if rv:
|
||||||
raise Fatal('%r returned %d' % (argv, rv))
|
raise Fatal('%r returned %d' % (argv, rv))
|
||||||
|
|
||||||
@ -147,6 +149,7 @@ def ipfw_noexit(*args):
|
|||||||
argv = ['ipfw', '-q'] + list(args)
|
argv = ['ipfw', '-q'] + list(args)
|
||||||
debug1('>> %s\n' % ' '.join(argv))
|
debug1('>> %s\n' % ' '.join(argv))
|
||||||
ssubprocess.call(argv)
|
ssubprocess.call(argv)
|
||||||
|
# No env: No output. (Or error that won't be parsed.)
|
||||||
|
|
||||||
|
|
||||||
class Method(BaseMethod):
|
class Method(BaseMethod):
|
||||||
|
@ -179,6 +179,7 @@ class FreeBsd(Generic):
|
|||||||
|
|
||||||
def enable(self):
|
def enable(self):
|
||||||
returncode = ssubprocess.call(['kldload', 'pf'])
|
returncode = ssubprocess.call(['kldload', 'pf'])
|
||||||
|
# No env: No output.
|
||||||
super(FreeBsd, self).enable()
|
super(FreeBsd, self).enable()
|
||||||
if returncode == 0:
|
if returncode == 0:
|
||||||
_pf_context['loaded_by_sshuttle'] = True
|
_pf_context['loaded_by_sshuttle'] = True
|
||||||
@ -188,6 +189,7 @@ class FreeBsd(Generic):
|
|||||||
if _pf_context['loaded_by_sshuttle'] and \
|
if _pf_context['loaded_by_sshuttle'] and \
|
||||||
_pf_context['started_by_sshuttle'] == 0:
|
_pf_context['started_by_sshuttle'] == 0:
|
||||||
ssubprocess.call(['kldunload', 'pf'])
|
ssubprocess.call(['kldunload', 'pf'])
|
||||||
|
# No env: No output.
|
||||||
|
|
||||||
def add_anchors(self, anchor):
|
def add_anchors(self, anchor):
|
||||||
status = pfctl('-s all')[0]
|
status = pfctl('-s all')[0]
|
||||||
|
@ -133,6 +133,7 @@ def connect(ssh_cmd, rhostport, python, stderr, options):
|
|||||||
debug2('executing: %r\n' % argv)
|
debug2('executing: %r\n' % argv)
|
||||||
p = ssubprocess.Popen(argv, stdin=s1a, stdout=s1b, preexec_fn=setup,
|
p = ssubprocess.Popen(argv, stdin=s1a, stdout=s1b, preexec_fn=setup,
|
||||||
close_fds=True, stderr=stderr)
|
close_fds=True, stderr=stderr)
|
||||||
|
# No env: Would affect the entire sshuttle.
|
||||||
os.close(s1a)
|
os.close(s1a)
|
||||||
os.close(s1b)
|
os.close(s1b)
|
||||||
s2.sendall(content)
|
s2.sendall(content)
|
||||||
|
Loading…
Reference in New Issue
Block a user