[modules/vault] fix copy of wrong password

- fix bad errors (missing "show" in pass command)
- pass in whole environment (otherwise clipboard doesn't work)
- generate lambda to avoid late binding

fixes #593
This commit is contained in:
tobi-wan-kenobi 2020-05-28 20:58:56 +02:00
parent 8cdc84871f
commit ebd98663c6

View file

@ -32,6 +32,9 @@ import util.cli
import util.popup import util.popup
def generate_callback(callback, path, name):
return lambda: callback(os.path.join(path, name))
def build_menu(parent, current_directory, callback): def build_menu(parent, current_directory, callback):
with os.scandir(current_directory) as it: with os.scandir(current_directory) as it:
for entry in it: for entry in it:
@ -41,7 +44,7 @@ def build_menu(parent, current_directory, callback):
name = entry.name[: entry.name.rfind(".")] name = entry.name[: entry.name.rfind(".")]
parent.add_menuitem( parent.add_menuitem(
name, name,
callback=lambda: callback(os.path.join(current_directory, name)), callback=generate_callback(callback, current_directory, name),
) )
else: else:
@ -79,10 +82,12 @@ class Module(core.module.Module):
secret_name = secret_name.replace(self.__path, "") # remove common path secret_name = secret_name.replace(self.__path, "") # remove common path
if self.__timer: if self.__timer:
self.__timer.cancel() self.__timer.cancel()
env = os.environ
env["PASSWORD_STORE_CLIP_TIME"] = str(self.__duration)
res = util.cli.execute( res = util.cli.execute(
"pass -c {}".format(secret_name), "pass show -c {}".format(secret_name),
wait=False, wait=False,
env={"PASSWORD_STORE_CLIP_TIME": self.__duration}, env=env,
) )
self.__timer = threading.Timer(self.__duration, self.__reset) self.__timer = threading.Timer(self.__duration, self.__reset)
self.__timer.start() self.__timer.start()