changeset 1313:d1d12a09b04a

Make passphrase entry retries customizable (suggested by Till Maas) Based on a patch provided by Till Maas.
author Mikael Berthe <mikael@lilotux.net>
date Thu, 20 Sep 2007 20:08:59 +0200
parents f4830fada2af
children 248e3f69dd9e
files mcabber/mcabberrc.example mcabber/src/main.c
diffstat 2 files changed, 14 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/mcabber/mcabberrc.example	Tue Sep 18 18:56:57 2007 +0200
+++ b/mcabber/mcabberrc.example	Thu Sep 20 20:08:59 2007 +0200
@@ -55,6 +55,11 @@
 #
 # You can set your PGP passhrase here, although it's NOT advised.
 #set pgp_passphrase = "PGPpassword"
+#
+# If you don't like the default number of passphrase retries (2), you
+# can change it here.  If this number is < 0, mcabber will keep asking
+# until the passphrase is good.
+#pgp_passphrase_retries = 2
 
 # Conference nickname
 # This nickname is used when joining a room, when no nick is explicitly
--- a/mcabber/src/main.c	Tue Sep 18 18:56:57 2007 +0200
+++ b/mcabber/src/main.c	Thu Sep 20 20:08:59 2007 +0200
@@ -284,12 +284,19 @@
   char *p;
   bool pgp_invalid = FALSE;
   bool pgp_agent;
+  int retries;
 
   p = getenv("GPG_AGENT_INFO");
   pgp_agent = (p && strchr(p, ':'));
 
   pk = settings_opt_get("pgp_private_key");
   pp = settings_opt_get("pgp_passphrase");
+
+  if (settings_opt_get("pgp_passphrase_retries"))
+    retries = settings_opt_get_int("pgp_passphrase_retries");
+  else
+    retries = 2;
+
   if (!pk) {
     scr_LogPrint(LPRINT_LOGNORM, "WARNING: unkown PGP private key");
     pgp_invalid = TRUE;
@@ -309,7 +316,7 @@
   if (!pgp_agent && pk && pp && gpg_test_passphrase()) {
     // Let's check the pasphrase
     int i;
-    for (i = 0; i < 2; i++) {
+    for (i = 1; retries < 0 || i <= retries; i++) {
       typed_passwd = ask_password("PGP passphrase"); // Ask again...
       if (typed_passwd) {
         gpg_set_passphrase(typed_passwd);
@@ -319,7 +326,7 @@
       if (!gpg_test_passphrase())
         break; // Ok
     }
-    if (i == 2)
+    if (i > retries)
       pgp_invalid = TRUE;
   }
   if (pgp_invalid)