From f1d57487be5ec6c5b2d1e2e7556c3761251127f3 Mon Sep 17 00:00:00 2001 From: Daniel Dizdarevic Date: Mon, 8 May 2023 18:16:06 +0200 Subject: [PATCH] Catch CTRL+C and CTRL+D in password prompts --- src/ldaptool/search/config.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/ldaptool/search/config.py b/src/ldaptool/search/config.py index 50a0fc9..6ccda45 100644 --- a/src/ldaptool/search/config.py +++ b/src/ldaptool/search/config.py @@ -229,7 +229,11 @@ class Config: """ if realm.account is None: raise RuntimeError("Can't get password without acccount - should use kerberos instead") - if self.password_manager: - return self.password_manager.get_password(realm.password_name) - return getpass.getpass(f"Enter password for {realm.password_name}: ") + try: + if self.password_manager: + return self.password_manager.get_password(realm.password_name) + + return getpass.getpass(f"Enter password for {realm.password_name}: ") + except (KeyboardInterrupt, EOFError): + raise SystemExit("Password prompt / retrieval aborted")