# HG changeset patch # User Christian Burkert # Date 1435489090 -7200 # Node ID 06669fc1810c1afa306ffcf5b99ae6f33a8ac79b # Parent 46d1182d45be958313a50583915e74c4e5406186 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. diff -r 46d1182d45be -r 06669fc1810c mcabber/mcabber/main.c --- 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 diff -r 46d1182d45be -r 06669fc1810c mcabber/mcabberrc.example --- 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