1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-12-04 14:46:46 -05:00

Add support for evaluated password

This commit is contained in:
Peter Vilim 2015-01-06 23:00:02 -06:00
parent 99a87a148f
commit 492c548aa6
6 changed files with 65 additions and 9 deletions

View File

@ -931,6 +931,7 @@ static struct cmd_t command_defs[] =
"|xa|dnd : Priority for the specified presence.", "|xa|dnd : Priority for the specified presence.",
"resource : The resource to be used.", "resource : The resource to be used.",
"password : Password for the account, note this is currently stored in plaintext if set.", "password : Password for the account, note this is currently stored in plaintext if set.",
"eval_password : Shell command evaluated to retrieve password for the account. Can be used to retrieve password from keyring.",
"muc : The default MUC chat service to use.", "muc : The default MUC chat service to use.",
"nick : The default nickname to use when joining chat rooms.", "nick : The default nickname to use when joining chat rooms.",
"otr : Override global OTR policy for this account: manual, opportunistic or always.", "otr : Override global OTR policy for this account: manual, opportunistic or always.",
@ -1260,12 +1261,14 @@ cmd_init(void)
autocomplete_add(account_set_ac, "dnd"); autocomplete_add(account_set_ac, "dnd");
autocomplete_add(account_set_ac, "resource"); autocomplete_add(account_set_ac, "resource");
autocomplete_add(account_set_ac, "password"); autocomplete_add(account_set_ac, "password");
autocomplete_add(account_set_ac, "eval_password");
autocomplete_add(account_set_ac, "muc"); autocomplete_add(account_set_ac, "muc");
autocomplete_add(account_set_ac, "nick"); autocomplete_add(account_set_ac, "nick");
autocomplete_add(account_set_ac, "otr"); autocomplete_add(account_set_ac, "otr");
account_clear_ac = autocomplete_new(); account_clear_ac = autocomplete_new();
autocomplete_add(account_clear_ac, "password"); autocomplete_add(account_clear_ac, "password");
autocomplete_add(account_clear_ac, "eval_password");
autocomplete_add(account_clear_ac, "server"); autocomplete_add(account_clear_ac, "server");
autocomplete_add(account_clear_ac, "port"); autocomplete_add(account_clear_ac, "port");
autocomplete_add(account_clear_ac, "otr"); autocomplete_add(account_clear_ac, "otr");

View File

@ -130,7 +130,7 @@ cmd_connect(gchar **args, struct cmd_help_t help)
ProfAccount *account = accounts_get_account(lower); ProfAccount *account = accounts_get_account(lower);
if (account != NULL) { if (account != NULL) {
jid = account_create_full_jid(account); jid = account_create_full_jid(account);
if (account->password == NULL) { if (account->password == NULL && account->eval_password == NULL) {
account->password = ui_ask_password(); account->password = ui_ask_password();
} }
cons_show("Connecting with account %s as %s", account->name, jid); cons_show("Connecting with account %s as %s", account->name, jid);
@ -340,9 +340,21 @@ cmd_account(gchar **args, struct cmd_help_t help)
cons_show("Updated resource for account %s: %s", account_name, value); cons_show("Updated resource for account %s: %s", account_name, value);
cons_show(""); cons_show("");
} else if (strcmp(property, "password") == 0) { } else if (strcmp(property, "password") == 0) {
accounts_set_password(account_name, value); if(accounts_get_account(account_name)->eval_password != NULL) {
cons_show("Updated password for account %s", account_name); cons_show("Cannot set password when eval_password is set.");
cons_show(""); } 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) {
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) { } else if (strcmp(property, "muc") == 0) {
accounts_set_muc_service(account_name, value); accounts_set_muc_service(account_name, value);
cons_show("Updated muc service for account %s: %s", account_name, value); cons_show("Updated muc service for account %s: %s", account_name, value);
@ -427,6 +439,10 @@ cmd_account(gchar **args, struct cmd_help_t help)
accounts_clear_password(account_name); accounts_clear_password(account_name);
cons_show("Removed password for account %s", account_name); cons_show("Removed password for account %s", account_name);
cons_show(""); cons_show("");
} else if (strcmp(property, "eval_password") == 0) {
accounts_clear_eval_password(account_name);
cons_show("Removed eval password for account %s", account_name);
cons_show("");
} else if (strcmp(property, "server") == 0) { } else if (strcmp(property, "server") == 0) {
accounts_clear_server(account_name); accounts_clear_server(account_name);
cons_show("Removed server for account %s", account_name); cons_show("Removed server for account %s", account_name);

View File

@ -43,7 +43,7 @@
ProfAccount* ProfAccount*
account_new(const gchar * const name, const gchar * const jid, account_new(const gchar * const name, const gchar * const jid,
const gchar * const password, gboolean enabled, const gchar * const server, const gchar * const password, const gchar * eval_password, gboolean enabled, const gchar * const server,
int port, const gchar * const resource, const gchar * const last_presence, int port, const gchar * const resource, const gchar * const last_presence,
const gchar * const login_presence, int priority_online, int priority_chat, const gchar * const login_presence, int priority_online, int priority_chat,
int priority_away, int priority_xa, int priority_dnd, int priority_away, int priority_xa, int priority_dnd,
@ -67,6 +67,12 @@ account_new(const gchar * const name, const gchar * const jid,
new_account->password = NULL; new_account->password = NULL;
} }
if (eval_password != NULL) {
new_account->eval_password = strdup(eval_password);
} else {
new_account->eval_password = NULL;
}
new_account->enabled = enabled; new_account->enabled = enabled;
if (server != NULL) { if (server != NULL) {

View File

@ -41,6 +41,7 @@ typedef struct prof_account_t {
gchar *name; gchar *name;
gchar *jid; gchar *jid;
gchar *password; gchar *password;
gchar *eval_password;
gchar *resource; gchar *resource;
gchar *server; gchar *server;
int port; int port;
@ -61,7 +62,7 @@ typedef struct prof_account_t {
} ProfAccount; } ProfAccount;
ProfAccount* account_new(const gchar * const name, const gchar * const jid, ProfAccount* account_new(const gchar * const name, const gchar * const jid,
const gchar * const passord, gboolean enabled, const gchar * const server, const gchar * const passord, const gchar * eval_password, gboolean enabled, const gchar * const server,
int port, const gchar * const resource, const gchar * const last_presence, int port, const gchar * const resource, const gchar * const last_presence,
const gchar * const login_presence, int priority_online, int priority_chat, const gchar * const login_presence, int priority_online, int priority_chat,
int priority_away, int priority_xa, int priority_dnd, int priority_away, int priority_xa, int priority_dnd,

View File

@ -60,6 +60,7 @@ static gchar *string_keys[] = {
"port", "port",
"resource", "resource",
"password", "password",
"eval_password",
"presence.last", "presence.last",
"presence.login", "presence.login",
"muc.service", "muc.service",
@ -224,6 +225,14 @@ accounts_get_account(const char * const name)
} }
gchar *password = g_key_file_get_string(accounts, name, "password", NULL); 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 100 bytes to prevent overflows in the case of a poorly chosen command
password = g_malloc(100);
fgets(password, 100, stream);
}
gboolean enabled = g_key_file_get_boolean(accounts, name, "enabled", NULL); gboolean enabled = g_key_file_get_boolean(accounts, name, "enabled", NULL);
gchar *server = g_key_file_get_string(accounts, name, "server", NULL); gchar *server = g_key_file_get_string(accounts, name, "server", NULL);
@ -278,7 +287,7 @@ accounts_get_account(const char * const name)
g_strfreev(always); g_strfreev(always);
} }
ProfAccount *new_account = account_new(name, jid, password, enabled, ProfAccount *new_account = account_new(name, jid, password, eval_password, enabled,
server, port, resource, last_presence, login_presence, server, port, resource, last_presence, login_presence,
priority_online, priority_chat, priority_away, priority_xa, priority_online, priority_chat, priority_away, priority_xa,
priority_dnd, muc_service, muc_nick, otr_policy, otr_manual, priority_dnd, muc_service, muc_nick, otr_policy, otr_manual,
@ -286,6 +295,7 @@ accounts_get_account(const char * const name)
g_free(jid); g_free(jid);
g_free(password); g_free(password);
g_free(eval_password);
g_free(server); g_free(server);
g_free(resource); g_free(resource);
g_free(last_presence); g_free(last_presence);
@ -441,6 +451,15 @@ accounts_set_password(const char * const account_name, const char * const value)
} }
} }
void
accounts_set_eval_password(const char * const account_name, const char * const value)
{
if (accounts_account_exists(account_name)) {
g_key_file_set_string(accounts, account_name, "eval_password", value);
_save_accounts();
}
}
void void
accounts_clear_password(const char * const account_name) accounts_clear_password(const char * const account_name)
{ {
@ -450,6 +469,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 void
accounts_clear_server(const char * const account_name) accounts_clear_server(const char * const account_name)
{ {

View File

@ -61,6 +61,7 @@ void accounts_set_server(const char * const account_name, const char * const val
void accounts_set_port(const char * const account_name, const int value); void accounts_set_port(const char * const account_name, const int value);
void accounts_set_resource(const char * const account_name, const char * const value); void accounts_set_resource(const char * const account_name, const char * const value);
void accounts_set_password(const char * const account_name, const char * const value); void accounts_set_password(const char * const account_name, const char * const value);
void accounts_set_eval_password(const char * const account_name, const char * const value);
void accounts_set_muc_service(const char * const account_name, const char * const value); void accounts_set_muc_service(const char * const account_name, const char * const value);
void accounts_set_muc_nick(const char * const account_name, const char * const value); void accounts_set_muc_nick(const char * const account_name, const char * const value);
void accounts_set_otr_policy(const char * const account_name, const char * const value); void accounts_set_otr_policy(const char * const account_name, const char * const value);
@ -77,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, gint accounts_get_priority_for_presence_type(const char * const account_name,
resource_presence_t presence_type); resource_presence_t presence_type);
void accounts_clear_password(const char * const account_name); 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_server(const char * const account_name);
void accounts_clear_port(const char * const account_name); void accounts_clear_port(const char * const account_name);
void accounts_clear_otr(const char * const account_name); void accounts_clear_otr(const char * const account_name);