mirror of
https://git.jabber.space/devs/cproof.git
synced 2026-07-26 22:16:22 +00:00
Add option for legacy authentication
New options: /connect <account> [auth default|legacy] /account <account> set auth default|legacy Fixes #1236.
This commit is contained in:
@@ -134,8 +134,10 @@ connection_shutdown(void)
|
||||
|
||||
jabber_conn_status_t
|
||||
connection_connect(const char *const jid, const char *const passwd, const char *const altdomain, int port,
|
||||
const char *const tls_policy)
|
||||
const char *const tls_policy, const char *const auth_policy)
|
||||
{
|
||||
long flags;
|
||||
|
||||
assert(jid != NULL);
|
||||
assert(passwd != NULL);
|
||||
|
||||
@@ -175,15 +177,35 @@ connection_connect(const char *const jid, const char *const passwd, const char *
|
||||
xmpp_conn_set_jid(conn.xmpp_conn, jid);
|
||||
xmpp_conn_set_pass(conn.xmpp_conn, passwd);
|
||||
|
||||
flags = xmpp_conn_get_flags(conn.xmpp_conn);
|
||||
|
||||
if (!tls_policy || (g_strcmp0(tls_policy, "force") == 0)) {
|
||||
xmpp_conn_set_flags(conn.xmpp_conn, XMPP_CONN_FLAG_MANDATORY_TLS);
|
||||
flags |= XMPP_CONN_FLAG_MANDATORY_TLS;
|
||||
} else if (g_strcmp0(tls_policy, "trust") == 0) {
|
||||
xmpp_conn_set_flags(conn.xmpp_conn, XMPP_CONN_FLAG_MANDATORY_TLS);
|
||||
xmpp_conn_set_flags(conn.xmpp_conn, XMPP_CONN_FLAG_TRUST_TLS);
|
||||
flags |= XMPP_CONN_FLAG_MANDATORY_TLS;
|
||||
flags |= XMPP_CONN_FLAG_TRUST_TLS;
|
||||
} else if (g_strcmp0(tls_policy, "disable") == 0) {
|
||||
xmpp_conn_set_flags(conn.xmpp_conn, XMPP_CONN_FLAG_DISABLE_TLS);
|
||||
flags |= XMPP_CONN_FLAG_DISABLE_TLS;
|
||||
} else if (g_strcmp0(tls_policy, "legacy") == 0) {
|
||||
xmpp_conn_set_flags(conn.xmpp_conn, XMPP_CONN_FLAG_LEGACY_SSL);
|
||||
flags |= XMPP_CONN_FLAG_LEGACY_SSL;
|
||||
}
|
||||
|
||||
if (auth_policy && (g_strcmp0(auth_policy, "legacy") == 0)) {
|
||||
flags |= XMPP_CONN_FLAG_LEGACY_AUTH;
|
||||
}
|
||||
|
||||
xmpp_conn_set_flags(conn.xmpp_conn, flags);
|
||||
|
||||
/* Print debug logs that can help when users share the logs */
|
||||
if (flags != 0) {
|
||||
log_debug("Connecting with flags (0x%lx):", flags);
|
||||
#define LOG_FLAG_IF_SET(name) if (flags & name) { log_debug(" " #name); }
|
||||
LOG_FLAG_IF_SET(XMPP_CONN_FLAG_MANDATORY_TLS);
|
||||
LOG_FLAG_IF_SET(XMPP_CONN_FLAG_TRUST_TLS);
|
||||
LOG_FLAG_IF_SET(XMPP_CONN_FLAG_DISABLE_TLS);
|
||||
LOG_FLAG_IF_SET(XMPP_CONN_FLAG_LEGACY_SSL);
|
||||
LOG_FLAG_IF_SET(XMPP_CONN_FLAG_LEGACY_AUTH);
|
||||
#undef LOG_FLAG_IF_SET
|
||||
}
|
||||
|
||||
#ifdef HAVE_LIBMESODE
|
||||
|
||||
@@ -43,7 +43,7 @@ void connection_shutdown(void);
|
||||
void connection_check_events(void);
|
||||
|
||||
jabber_conn_status_t connection_connect(const char *const fulljid, const char *const passwd, const char *const altdomain, int port,
|
||||
const char *const tls_policy);
|
||||
const char *const tls_policy, const char *const auth_policy);
|
||||
void connection_disconnect(void);
|
||||
void connection_set_disconnected(void);
|
||||
|
||||
|
||||
@@ -79,6 +79,7 @@ static struct {
|
||||
char *altdomain;
|
||||
int port;
|
||||
char *tls_policy;
|
||||
char *auth_policy;
|
||||
} saved_details;
|
||||
|
||||
typedef enum {
|
||||
@@ -135,7 +136,8 @@ session_connect_with_account(const ProfAccount *const account)
|
||||
account->password,
|
||||
account->server,
|
||||
account->port,
|
||||
account->tls_policy);
|
||||
account->tls_policy,
|
||||
account->auth_policy);
|
||||
free(jid);
|
||||
|
||||
return result;
|
||||
@@ -143,7 +145,7 @@ session_connect_with_account(const ProfAccount *const account)
|
||||
|
||||
jabber_conn_status_t
|
||||
session_connect_with_details(const char *const jid, const char *const passwd, const char *const altdomain,
|
||||
const int port, const char *const tls_policy)
|
||||
const int port, const char *const tls_policy, const char *const auth_policy)
|
||||
{
|
||||
assert(jid != NULL);
|
||||
assert(passwd != NULL);
|
||||
@@ -169,6 +171,11 @@ session_connect_with_details(const char *const jid, const char *const passwd, co
|
||||
} else {
|
||||
saved_details.tls_policy = NULL;
|
||||
}
|
||||
if (auth_policy) {
|
||||
saved_details.auth_policy = strdup(auth_policy);
|
||||
} else {
|
||||
saved_details.auth_policy = NULL;
|
||||
}
|
||||
|
||||
// use 'profanity' when no resourcepart in provided jid
|
||||
Jid *jidp = jid_create(jid);
|
||||
@@ -191,7 +198,8 @@ session_connect_with_details(const char *const jid, const char *const passwd, co
|
||||
passwd,
|
||||
saved_details.altdomain,
|
||||
saved_details.port,
|
||||
saved_details.tls_policy);
|
||||
saved_details.tls_policy,
|
||||
saved_details.auth_policy);
|
||||
}
|
||||
|
||||
void
|
||||
@@ -292,7 +300,7 @@ session_login_success(gboolean secured)
|
||||
// logged in without account, use details to create new account
|
||||
} else {
|
||||
log_debug("Connection handler: logged in with jid: %s", saved_details.name);
|
||||
accounts_add(saved_details.name, saved_details.altdomain, saved_details.port, saved_details.tls_policy);
|
||||
accounts_add(saved_details.name, saved_details.altdomain, saved_details.port, saved_details.tls_policy, saved_details.auth_policy);
|
||||
accounts_set_jid(saved_details.name, saved_details.jid);
|
||||
|
||||
saved_account.name = strdup(saved_details.name);
|
||||
@@ -511,7 +519,7 @@ _session_reconnect(void)
|
||||
}
|
||||
|
||||
log_debug("Attempting reconnect with account %s", account->name);
|
||||
connection_connect(jid, saved_account.passwd, account->server, account->port, account->tls_policy);
|
||||
connection_connect(jid, saved_account.passwd, account->server, account->port, account->tls_policy, account->auth_policy);
|
||||
free(jid);
|
||||
account_free(account);
|
||||
g_timer_start(reconnect_timer);
|
||||
@@ -532,5 +540,6 @@ _session_free_saved_details(void)
|
||||
FREE_SET_NULL(saved_details.passwd);
|
||||
FREE_SET_NULL(saved_details.altdomain);
|
||||
FREE_SET_NULL(saved_details.tls_policy);
|
||||
FREE_SET_NULL(saved_details.auth_policy);
|
||||
}
|
||||
|
||||
|
||||
@@ -164,7 +164,7 @@ typedef struct prof_message_t {
|
||||
|
||||
void session_init(void);
|
||||
jabber_conn_status_t session_connect_with_details(const char *const jid, const char *const passwd,
|
||||
const char *const altdomain, const int port, const char *const tls_policy);
|
||||
const char *const altdomain, const int port, const char *const tls_policy, const char *const auth_policy);
|
||||
jabber_conn_status_t session_connect_with_account(const ProfAccount *const account);
|
||||
void session_disconnect(void);
|
||||
void session_shutdown(void);
|
||||
|
||||
Reference in New Issue
Block a user