about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorWill Song <incertia9474@gmail.com>2015-01-12 22:23:36 -0600
committerWill Song <incertia9474@gmail.com>2015-01-12 22:23:36 -0600
commitc2758616d8fcf92de139f519e027713f4dc1c937 (patch)
treee1e64ea40a55dd3cd4962d281496616f4d5ad5b4 /src
parent844cd2dda713458d10c1db323cdb76aed0d9b46b (diff)
downloadprofani-tty-c2758616d8fcf92de139f519e027713f4dc1c937.tar.gz
eval_password code is now in cmd_connect so that it can be changed
without clearing it. eval_password errors are also now ignored, along
with pclosing the popened eval_password.
Diffstat (limited to 'src')
-rw-r--r--src/command/commands.c15
-rw-r--r--src/config/accounts.c10
2 files changed, 14 insertions, 11 deletions
diff --git a/src/command/commands.c b/src/command/commands.c
index 3647bb22..2b7136f2 100644
--- a/src/command/commands.c
+++ b/src/command/commands.c
@@ -130,7 +130,20 @@ cmd_connect(gchar **args, struct cmd_help_t help)
         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);
+                    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);
diff --git a/src/config/accounts.c b/src/config/accounts.c
index 01609888..d86fe3af 100644
--- a/src/config/accounts.c
+++ b/src/config/accounts.c
@@ -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);