changeset 2172:06669fc1810c

Add support for using external password managers I wrote the attached patch to enable to usage of password stores like pass with mcabber to avoid putting plain passwords into the config file.
author Christian Burkert <post@cburkert.de>
date Sun, 28 Jun 2015 12:58:10 +0200
parents 46d1182d45be
children cf08c3b630af
files mcabber/mcabber/main.c mcabber/mcabberrc.example
diffstat 2 files changed, 37 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/mcabber/mcabber/main.c	Sun Feb 15 17:07:05 2015 +0100
+++ b/mcabber/mcabber/main.c	Sun Jun 28 12:58:10 2015 +0200
@@ -403,9 +403,38 @@
   /* If no password is stored, we ask for it before entering
      ncurses mode -- unless the username is unknown. */
   if (settings_opt_get("jid") && !settings_opt_get("password")) {
-    char *pwd = ask_password("your Jabber password");
-    settings_set(SETTINGS_TYPE_OPTION, "password", pwd);
-    g_free(pwd);
+    if (settings_opt_get("password_eval")) {
+      FILE *outfp = popen(settings_opt_get("password_eval"), "r");
+      if (outfp == NULL) {
+        scr_log_print(LPRINT_NORMAL, "** ERROR: Failed to execute password_eval command.");
+        exit(EXIT_FAILURE);
+      }
+#define MAX_PWD 100
+      char pwd[MAX_PWD+1];
+      char *read_pwd = fgets(pwd, MAX_PWD, outfp);
+      if (read_pwd == NULL) {
+        scr_log_print(LPRINT_NORMAL, "** ERROR: Failed to read from password_eval command.");
+        exit(EXIT_FAILURE);
+      }
+      int res = pclose(outfp);
+      if (res != 0) {
+        scr_log_print(LPRINT_NORMAL, "** ERROR: Password evaluation command exited with error %d.", res);
+        exit(EXIT_FAILURE);
+      }
+
+      // strip trailing whitespaces and newlines
+      size_t i = 0;
+      while (i < MAX_PWD && !isspace(pwd[i])) {
+        i++;
+      }
+      pwd[i] = '\0';
+
+      settings_set(SETTINGS_TYPE_OPTION, "password", pwd);
+    } else {
+      char *pwd = ask_password("your Jabber password");
+      settings_set(SETTINGS_TYPE_OPTION, "password", pwd);
+      g_free(pwd);
+    }
   }
 
   /* Initialize PGP system
--- a/mcabber/mcabberrc.example	Sun Feb 15 17:07:05 2015 +0100
+++ b/mcabber/mcabberrc.example	Sun Jun 28 12:58:10 2015 +0200
@@ -12,6 +12,11 @@
 # enclose it with quotes: set password = " example password "
 #set password = yourpassword
 
+# Read password from output of the given command.
+# This is a way to use password managers like 'pass' in order
+# to avoid writing plain passwords into config files.
+#set password_eval = "your command"
+
 # You can provide a server name if you want mcabber to connect
 # to a specific server.
 #set server = your.jabber.server