From b4f37b9e310904d6af7aaa32c2ae7dd9770a0b11 Mon Sep 17 00:00:00 2001 From: Peter Vilim Date: Wed, 7 Jan 2015 00:17:59 -0600 Subject: [PATCH] iofixed --- src/command/command.c | 1 + src/command/commands.c | 24 ++++++++++++++++++------ src/config/accounts.c | 15 +++++++++++++-- src/config/accounts.h | 1 + 4 files changed, 33 insertions(+), 8 deletions(-) diff --git a/src/command/command.c b/src/command/command.c index 618f14a3..e7d8547a 100644 --- a/src/command/command.c +++ b/src/command/command.c @@ -1268,6 +1268,7 @@ cmd_init(void) account_clear_ac = autocomplete_new(); autocomplete_add(account_clear_ac, "password"); + autocomplete_add(account_clear_ac, "eval_password"); autocomplete_add(account_clear_ac, "server"); autocomplete_add(account_clear_ac, "port"); autocomplete_add(account_clear_ac, "otr"); diff --git a/src/command/commands.c b/src/command/commands.c index 0c93143a..eed22ed5 100644 --- a/src/command/commands.c +++ b/src/command/commands.c @@ -340,13 +340,21 @@ cmd_account(gchar **args, struct cmd_help_t help) cons_show("Updated resource for account %s: %s", account_name, value); cons_show(""); } else if (strcmp(property, "password") == 0) { - accounts_set_password(account_name, value); - cons_show("Updated password for account %s", account_name); - cons_show(""); + if(accounts_get_account(account_name)->eval_password != NULL) { + cons_show("Cannot set password when eval_password is set."); + } else { + accounts_set_password(account_name, value); + cons_show("Updated password for account %s", account_name); + cons_show(""); + } } else if (strcmp(property, "eval_password") == 0) { - accounts_set_eval_password(account_name, value); - cons_show("Updated eval_password for account %s", account_name); - cons_show(""); + if(accounts_get_account(account_name)->password != NULL) { + cons_show("Cannot set eval_password when password is set."); + } else { + accounts_set_eval_password(account_name, value); + cons_show("Updated eval_password for account %s", account_name); + cons_show(""); + } } else if (strcmp(property, "muc") == 0) { accounts_set_muc_service(account_name, value); cons_show("Updated muc service for account %s: %s", account_name, value); @@ -431,6 +439,10 @@ cmd_account(gchar **args, struct cmd_help_t help) accounts_clear_password(account_name); cons_show("Removed password for account %s", account_name); cons_show(""); + } else if (strcmp(property, "eval_password") == 0) { + accounts_clear_password(account_name); + cons_show("Removed password for account %s", account_name); + cons_show(""); } else if (strcmp(property, "server") == 0) { accounts_clear_server(account_name); cons_show("Removed server for account %s", account_name); diff --git a/src/config/accounts.c b/src/config/accounts.c index c3478bd5..0ca93ba6 100644 --- a/src/config/accounts.c +++ b/src/config/accounts.c @@ -61,6 +61,7 @@ static gchar *string_keys[] = { "port", "resource", "password", + "eval_password", "presence.last", "presence.login", "muc.service", @@ -227,8 +228,9 @@ 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); if (eval_password != NULL) { - FILE *evaled_password = popen(eval_password, "r"); - fscanf(evaled_password, "%s", password); + FILE *stream = popen(eval_password, "r"); + password = g_malloc(100); + fgets(password, 100, stream); } gboolean enabled = g_key_file_get_boolean(accounts, name, "enabled", NULL); @@ -466,6 +468,15 @@ accounts_clear_password(const char * const account_name) } } +void +accounts_clear_eval_password(const char * const account_name) +{ + if (accounts_account_exists(account_name)) { + g_key_file_remove_key(accounts, account_name, "eval_password", NULL); + _save_accounts(); + } +} + void accounts_clear_server(const char * const account_name) { diff --git a/src/config/accounts.h b/src/config/accounts.h index 09b5d29a..a1dda018 100644 --- a/src/config/accounts.h +++ b/src/config/accounts.h @@ -78,6 +78,7 @@ void accounts_set_priority_all(const char * const account_name, const gint value gint accounts_get_priority_for_presence_type(const char * const account_name, resource_presence_t presence_type); void accounts_clear_password(const char * const account_name); +void accounts_clear_eval_password(const char * const account_name); void accounts_clear_server(const char * const account_name); void accounts_clear_port(const char * const account_name); void accounts_clear_otr(const char * const account_name);