use prepared env for calling BORG_PASSCOMMAND, fixes #3050

This commit is contained in:
Thomas Waldmann 2017-09-23 20:04:47 +02:00
parent ba941b0801
commit 6a6fd31804
1 changed files with 4 additions and 1 deletions

View File

@ -23,6 +23,7 @@ from ..helpers import yes
from ..helpers import get_keys_dir, get_security_dir from ..helpers import get_keys_dir, get_security_dir
from ..helpers import get_limited_unpacker from ..helpers import get_limited_unpacker
from ..helpers import bin_to_hex from ..helpers import bin_to_hex
from ..helpers import prepare_subprocess_env
from ..item import Key, EncryptedKey from ..item import Key, EncryptedKey
from ..platform import SaveFile from ..platform import SaveFile
@ -425,8 +426,10 @@ class Passphrase(str):
def env_passcommand(cls, default=None): def env_passcommand(cls, default=None):
passcommand = os.environ.get('BORG_PASSCOMMAND', None) passcommand = os.environ.get('BORG_PASSCOMMAND', None)
if passcommand is not None: if passcommand is not None:
# passcommand is a system command (not inside pyinstaller env)
env = prepare_subprocess_env(system=True)
try: try:
passphrase = subprocess.check_output(shlex.split(passcommand), universal_newlines=True) passphrase = subprocess.check_output(shlex.split(passcommand), universal_newlines=True, env=env)
except (subprocess.CalledProcessError, FileNotFoundError) as e: except (subprocess.CalledProcessError, FileNotFoundError) as e:
raise PasscommandFailure(e) raise PasscommandFailure(e)
return cls(passphrase.rstrip('\n')) return cls(passphrase.rstrip('\n'))