mirror of
https://github.com/profanity-im/profanity.git
synced 2025-01-03 14:57:42 -05:00
Merge remote-tracking branch 'tsenart/passwords-on-accounts-file'
Conflicts: src/config/accounts.c
This commit is contained in:
parent
9101f1ea26
commit
3d7087959d
@ -20,6 +20,7 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <assert.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
@ -67,6 +68,7 @@ typedef struct cmd_t {
|
|||||||
|
|
||||||
typedef char*(*autocompleter)(char*, int*);
|
typedef char*(*autocompleter)(char*, int*);
|
||||||
|
|
||||||
|
static char * _ask_password(void);
|
||||||
static void _update_presence(const resource_presence_t presence,
|
static void _update_presence(const resource_presence_t presence,
|
||||||
const char * const show, gchar **args);
|
const char * const show, gchar **args);
|
||||||
static gboolean _cmd_set_boolean_preference(gchar *arg, struct cmd_help_t help,
|
static gboolean _cmd_set_boolean_preference(gchar *arg, struct cmd_help_t help,
|
||||||
@ -1311,13 +1313,6 @@ _cmd_connect(gchar **args, struct cmd_help_t help)
|
|||||||
char *lower = g_utf8_strdown(user, -1);
|
char *lower = g_utf8_strdown(user, -1);
|
||||||
char *jid;
|
char *jid;
|
||||||
|
|
||||||
status_bar_get_password();
|
|
||||||
status_bar_refresh();
|
|
||||||
char passwd[21];
|
|
||||||
inp_block();
|
|
||||||
inp_get_password(passwd);
|
|
||||||
inp_non_block();
|
|
||||||
|
|
||||||
ProfAccount *account = accounts_get_account(lower);
|
ProfAccount *account = accounts_get_account(lower);
|
||||||
if (account != NULL) {
|
if (account != NULL) {
|
||||||
if (account->resource != NULL) {
|
if (account->resource != NULL) {
|
||||||
@ -1325,12 +1320,18 @@ _cmd_connect(gchar **args, struct cmd_help_t help)
|
|||||||
} else {
|
} else {
|
||||||
jid = strdup(account->jid);
|
jid = strdup(account->jid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (account->password == NULL) {
|
||||||
|
account->password = _ask_password();
|
||||||
|
}
|
||||||
cons_show("Connecting with account %s as %s", account->name, jid);
|
cons_show("Connecting with account %s as %s", account->name, jid);
|
||||||
conn_status = jabber_connect_with_account(account, passwd);
|
conn_status = jabber_connect_with_account(account);
|
||||||
} else {
|
} else {
|
||||||
|
char *passwd = _ask_password();
|
||||||
jid = strdup(lower);
|
jid = strdup(lower);
|
||||||
cons_show("Connecting as %s", jid);
|
cons_show("Connecting as %s", jid);
|
||||||
conn_status = jabber_connect_with_details(jid, passwd, altdomain);
|
conn_status = jabber_connect_with_details(jid, passwd, altdomain);
|
||||||
|
free(passwd);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (conn_status == JABBER_DISCONNECTED) {
|
if (conn_status == JABBER_DISCONNECTED) {
|
||||||
@ -3443,6 +3444,20 @@ _cmd_xa(gchar **args, struct cmd_help_t help)
|
|||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// helper function that asks the user for a password and saves it in passwd
|
||||||
|
|
||||||
|
static char *
|
||||||
|
_ask_password(void) {
|
||||||
|
char *passwd = malloc(sizeof(char) * 21);
|
||||||
|
status_bar_get_password();
|
||||||
|
status_bar_refresh();
|
||||||
|
inp_block();
|
||||||
|
inp_get_password(passwd);
|
||||||
|
inp_non_block();
|
||||||
|
|
||||||
|
return passwd;
|
||||||
|
}
|
||||||
|
|
||||||
// helper function for status change commands
|
// helper function for status change commands
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -39,10 +39,12 @@ static GKeyFile *accounts;
|
|||||||
static Autocomplete all_ac;
|
static Autocomplete all_ac;
|
||||||
static Autocomplete enabled_ac;
|
static Autocomplete enabled_ac;
|
||||||
|
|
||||||
|
// used to rename account (copies properties to new account)
|
||||||
static gchar *string_keys[] = {
|
static gchar *string_keys[] = {
|
||||||
"jid",
|
"jid",
|
||||||
"server",
|
"server",
|
||||||
"resource",
|
"resource",
|
||||||
|
"password",
|
||||||
"presence.last",
|
"presence.last",
|
||||||
"presence.login",
|
"presence.login",
|
||||||
"muc.service",
|
"muc.service",
|
||||||
@ -193,6 +195,14 @@ accounts_get_account(const char * const name)
|
|||||||
_save_accounts();
|
_save_accounts();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
gchar *password = g_key_file_get_string(accounts, name, "password", NULL);
|
||||||
|
if (password != NULL) {
|
||||||
|
account->password = strdup(password);
|
||||||
|
g_free(password);
|
||||||
|
} else {
|
||||||
|
account->password = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
account->enabled = g_key_file_get_boolean(accounts, name, "enabled", NULL);
|
account->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);
|
||||||
@ -281,6 +291,7 @@ accounts_free_account(ProfAccount *account)
|
|||||||
FREE_SET_NULL(account->name);
|
FREE_SET_NULL(account->name);
|
||||||
FREE_SET_NULL(account->jid);
|
FREE_SET_NULL(account->jid);
|
||||||
FREE_SET_NULL(account->resource);
|
FREE_SET_NULL(account->resource);
|
||||||
|
FREE_SET_NULL(account->password);
|
||||||
FREE_SET_NULL(account->server);
|
FREE_SET_NULL(account->server);
|
||||||
FREE_SET_NULL(account->last_presence);
|
FREE_SET_NULL(account->last_presence);
|
||||||
FREE_SET_NULL(account->login_presence);
|
FREE_SET_NULL(account->login_presence);
|
||||||
@ -341,6 +352,7 @@ accounts_rename(const char * const account_name, const char * const new_name)
|
|||||||
g_key_file_set_integer(accounts, new_name, "priority.dnd",
|
g_key_file_set_integer(accounts, new_name, "priority.dnd",
|
||||||
g_key_file_get_boolean(accounts, account_name, "priority.dnd", NULL));
|
g_key_file_get_boolean(accounts, account_name, "priority.dnd", NULL));
|
||||||
|
|
||||||
|
// copy other string properties
|
||||||
int i;
|
int i;
|
||||||
for (i = 0; i < ARRAY_SIZE(string_keys); i++) {
|
for (i = 0; i < ARRAY_SIZE(string_keys); i++) {
|
||||||
char *value = g_key_file_get_string(accounts, account_name, string_keys[i], NULL);
|
char *value = g_key_file_get_string(accounts, account_name, string_keys[i], NULL);
|
||||||
|
@ -28,6 +28,7 @@
|
|||||||
typedef struct prof_account_t {
|
typedef struct prof_account_t {
|
||||||
gchar *name;
|
gchar *name;
|
||||||
gchar *jid;
|
gchar *jid;
|
||||||
|
gchar *password;
|
||||||
gchar *resource;
|
gchar *resource;
|
||||||
gchar *server;
|
gchar *server;
|
||||||
gchar *last_presence;
|
gchar *last_presence;
|
||||||
|
@ -801,6 +801,9 @@ cons_show_account(ProfAccount *account)
|
|||||||
cons_show ("enabled : FALSE");
|
cons_show ("enabled : FALSE");
|
||||||
}
|
}
|
||||||
cons_show ("jid : %s", account->jid);
|
cons_show ("jid : %s", account->jid);
|
||||||
|
if (account->password != NULL) {
|
||||||
|
cons_show ("password : [redacted]");
|
||||||
|
}
|
||||||
if (account->resource != NULL) {
|
if (account->resource != NULL) {
|
||||||
cons_show ("resource : %s", account->resource);
|
cons_show ("resource : %s", account->resource);
|
||||||
}
|
}
|
||||||
|
@ -108,21 +108,20 @@ jabber_init(const int disable_tls)
|
|||||||
}
|
}
|
||||||
|
|
||||||
jabber_conn_status_t
|
jabber_conn_status_t
|
||||||
jabber_connect_with_account(const ProfAccount * const account,
|
jabber_connect_with_account(const ProfAccount * const account)
|
||||||
const char * const passwd)
|
|
||||||
{
|
{
|
||||||
assert(account != NULL);
|
assert(account != NULL);
|
||||||
assert(passwd != NULL);
|
|
||||||
|
|
||||||
log_info("Connecting using account: %s", account->name);
|
log_info("Connecting using account: %s", account->name);
|
||||||
|
|
||||||
// save account name and password for reconnect
|
// save account name and password for reconnect
|
||||||
saved_account.name = strdup(account->name);
|
saved_account.name = strdup(account->name);
|
||||||
saved_account.passwd = strdup(passwd);
|
saved_account.passwd = strdup(account->password);
|
||||||
|
|
||||||
// connect with fulljid
|
// connect with fulljid
|
||||||
Jid *jidp = jid_create_from_bare_and_resource(account->jid, account->resource);
|
Jid *jidp = jid_create_from_bare_and_resource(account->jid, account->resource);
|
||||||
jabber_conn_status_t result = _jabber_connect(jidp->fulljid, passwd, account->server);
|
jabber_conn_status_t result =
|
||||||
|
_jabber_connect(jidp->fulljid, account->password, account->server);
|
||||||
jid_destroy(jidp);
|
jid_destroy(jidp);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
@ -78,8 +78,7 @@ typedef struct disco_identity_t {
|
|||||||
void jabber_init(const int disable_tls);
|
void jabber_init(const int disable_tls);
|
||||||
jabber_conn_status_t jabber_connect_with_details(const char * const jid,
|
jabber_conn_status_t jabber_connect_with_details(const char * const jid,
|
||||||
const char * const passwd, const char * const altdomain);
|
const char * const passwd, const char * const altdomain);
|
||||||
jabber_conn_status_t jabber_connect_with_account(const ProfAccount * const account,
|
jabber_conn_status_t jabber_connect_with_account(const ProfAccount * const account);
|
||||||
const char * const passwd);
|
|
||||||
void jabber_disconnect(void);
|
void jabber_disconnect(void);
|
||||||
void jabber_shutdown(void);
|
void jabber_shutdown(void);
|
||||||
void jabber_process_events(void);
|
void jabber_process_events(void);
|
||||||
|
Loading…
Reference in New Issue
Block a user