Merge pull request #809 from zbuc/pfctl_errhandling

Better error handling/reporting for pfctl failures on OS X
This commit is contained in:
Maximilian Hils 2015-11-04 21:32:12 +01:00
commit fb463f50ed

View File

@ -19,8 +19,17 @@ class Resolver(object):
def original_addr(self, csock):
peer = csock.getpeername()
stxt = subprocess.check_output(self.STATECMD, stderr=subprocess.STDOUT)
if "sudo: a password is required" in stxt:
try:
stxt = subprocess.check_output(self.STATECMD, stderr=subprocess.STDOUT)
except subprocess.CalledProcessError, e:
if "sudo: a password is required" in e.output:
insufficient_priv = True
else:
raise RuntimeError("Error getting pfctl state: " + repr(e))
else:
insufficient_priv = "sudo: a password is required" in stxt
if insufficient_priv:
raise RuntimeError(
"Insufficient privileges to access pfctl. "
"See http://mitmproxy.org/doc/transparent/osx.html for details.")