1
0
mirror of https://github.com/profanity-im/profanity.git synced 2025-01-03 14:57:42 -05:00

Merge remote-tracking branch 'incertia/eval_pass-fixes'

This commit is contained in:
James Booth 2015-01-14 00:28:58 +00:00
commit e79302bf0e
3 changed files with 22 additions and 14 deletions

View File

@ -84,7 +84,6 @@ gboolean
cmd_connect(gchar **args, struct cmd_help_t help)
{
gboolean result = FALSE;
char *def = prefs_get_string(PREF_DEFAULT_ACCOUNT);
jabber_conn_status_t conn_status = jabber_get_connection_status();
@ -94,6 +93,7 @@ cmd_connect(gchar **args, struct cmd_help_t help)
} else {
gchar *opt_keys[] = { "server", "port", NULL };
gboolean parsed;
char *def = prefs_get_string(PREF_DEFAULT_ACCOUNT);
GHashTable *options = parse_options(&args[args[0] ? 1 : 0], opt_keys, &parsed);
if (!parsed) {
@ -124,13 +124,32 @@ cmd_connect(gchar **args, struct cmd_help_t help)
return TRUE;
}
}
g_free(def);
char *lower = g_utf8_strdown(user, -1);
char *jid;
ProfAccount *account = accounts_get_account(lower);
if (account != NULL) {
jid = account_create_full_jid(account);
if (account->password == NULL && account->eval_password == NULL) {
if(account->eval_password){
// Evaluate as shell command to retrieve password
GString *cmd = g_string_append(g_string_new(account->eval_password), " 2>/dev/null");
FILE *stream = popen(cmd->str, "r");
if(stream){
// Limit to READ_BUF_SIZE bytes to prevent overflows in the case of a poorly chosen command
account->password = g_malloc(READ_BUF_SIZE);
if(!account->password){
log_error("Failed to allocate enough memory to read eval_password output");
return TRUE;
}
account->password = fgets(account->password, READ_BUF_SIZE, stream);
pclose(stream);
} else {
log_error("popen failed when running eval_password.");
}
g_string_free(cmd, TRUE);
} else if (!account->password) {
account->password = ui_ask_password();
}
cons_show("Connecting with account %s as %s", account->name, jid);
@ -159,8 +178,6 @@ cmd_connect(gchar **args, struct cmd_help_t help)
result = TRUE;
}
g_free(def);
return result;
}

View File

@ -226,16 +226,6 @@ accounts_get_account(const char * const name)
gchar *password = g_key_file_get_string(accounts, name, "password", NULL);
gchar *eval_password = g_key_file_get_string(accounts, name, "eval_password", NULL);
// Evaluate as shell command to retrieve password
if (eval_password != NULL) {
FILE *stream = popen(eval_password, "r");
// Limit to READ_BUF_SIZE bytes to prevent overflows in the case of a poorly chosen command
password = g_malloc(READ_BUF_SIZE);
gchar *result = fgets(password, READ_BUF_SIZE, stream);
if (result != NULL) {
password = result;
}
}
gboolean enabled = g_key_file_get_boolean(accounts, name, "enabled", NULL);
gchar *server = g_key_file_get_string(accounts, name, "server", NULL);

View File

@ -61,6 +61,7 @@ void cmd_rooms_uses_account_default_when_no_arg(void **state)
account->name = NULL;
account->jid = NULL;
account->password = NULL;
account->eval_password = NULL;
account->resource = NULL;
account->server = NULL;
account->last_presence = NULL;