mirror of
https://github.com/sshuttle/sshuttle.git
synced 2025-08-09 07:44:56 +02:00
Improve consistency of PATH, environments, and which()
This patch attempts to fix (or aid in debugging) issue #350. sshuttle didn't explicitly search /sbin and /usr/sbin and they may be missing in the user's PATH. If PATH is missing, these folders wouldn't be searched either. There was also a program_exists function which is redundant to which(). This consolidates everything into the helpers.py file. This patch introduces get_path() to return PATH + some extra hardcoded paths. A new get_env() function can be called to create a consistent environment when calling external programs. The new which() wrapper function also ensures we use the same set of paths. If -vv is supplied, messages clearly indicate the programs we are looking for, if they are found, and where we looked if we failed to find them. I haven't tested the changes to ipfw or pf.
This commit is contained in:
@ -4,7 +4,7 @@ from socket import AF_INET, AF_INET6
|
||||
import pytest
|
||||
from mock import Mock, patch, call, ANY
|
||||
from sshuttle.methods import get_method
|
||||
from sshuttle.helpers import Fatal
|
||||
from sshuttle.helpers import Fatal, get_env
|
||||
from sshuttle.methods.pf import FreeBsd, Darwin, OpenBsd
|
||||
|
||||
|
||||
@ -316,7 +316,8 @@ def test_setup_firewall_freebsd(mock_pf_get_dev, mock_ioctl, mock_pfctl,
|
||||
b'to <dns_servers> port 53 keep state\n'),
|
||||
call('-e'),
|
||||
]
|
||||
assert call(['kldload', 'pf']) in mock_subprocess_call.mock_calls
|
||||
assert call(['kldload', 'pf'], env=get_env()) in \
|
||||
mock_subprocess_call.mock_calls
|
||||
mock_pf_get_dev.reset_mock()
|
||||
mock_ioctl.reset_mock()
|
||||
mock_pfctl.reset_mock()
|
||||
|
Reference in New Issue
Block a user