comparison mcabber/mcabber/main.c @ 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 fc7a758ebbde
children cf08c3b630af
comparison
equal deleted inserted replaced
2171:46d1182d45be 2172:06669fc1810c
401 } 401 }
402 402
403 /* If no password is stored, we ask for it before entering 403 /* If no password is stored, we ask for it before entering
404 ncurses mode -- unless the username is unknown. */ 404 ncurses mode -- unless the username is unknown. */
405 if (settings_opt_get("jid") && !settings_opt_get("password")) { 405 if (settings_opt_get("jid") && !settings_opt_get("password")) {
406 char *pwd = ask_password("your Jabber password"); 406 if (settings_opt_get("password_eval")) {
407 settings_set(SETTINGS_TYPE_OPTION, "password", pwd); 407 FILE *outfp = popen(settings_opt_get("password_eval"), "r");
408 g_free(pwd); 408 if (outfp == NULL) {
409 scr_log_print(LPRINT_NORMAL, "** ERROR: Failed to execute password_eval command.");
410 exit(EXIT_FAILURE);
411 }
412 #define MAX_PWD 100
413 char pwd[MAX_PWD+1];
414 char *read_pwd = fgets(pwd, MAX_PWD, outfp);
415 if (read_pwd == NULL) {
416 scr_log_print(LPRINT_NORMAL, "** ERROR: Failed to read from password_eval command.");
417 exit(EXIT_FAILURE);
418 }
419 int res = pclose(outfp);
420 if (res != 0) {
421 scr_log_print(LPRINT_NORMAL, "** ERROR: Password evaluation command exited with error %d.", res);
422 exit(EXIT_FAILURE);
423 }
424
425 // strip trailing whitespaces and newlines
426 size_t i = 0;
427 while (i < MAX_PWD && !isspace(pwd[i])) {
428 i++;
429 }
430 pwd[i] = '\0';
431
432 settings_set(SETTINGS_TYPE_OPTION, "password", pwd);
433 } else {
434 char *pwd = ask_password("your Jabber password");
435 settings_set(SETTINGS_TYPE_OPTION, "password", pwd);
436 g_free(pwd);
437 }
409 } 438 }
410 439
411 /* Initialize PGP system 440 /* Initialize PGP system
412 We do it before ncurses initialization because we may need to request 441 We do it before ncurses initialization because we may need to request
413 a passphrase. */ 442 a passphrase. */