33#include <sasl/saslutil.h>
49 sasl_conn_t *saslconn = NULL;
50 sasl_interact_t *interaction = NULL;
54 const char *mech = NULL;
55 const char *pc = NULL;
56 unsigned int len = 0, olen = 0;
79 sasl_dispose(&saslconn);
87 rc = sasl_client_start(saslconn,
"AUTH=ANONYMOUS", NULL, &pc, &olen, &mech);
93 sasl_dispose(&saslconn);
97 if ((rc != SASL_OK) && (rc != SASL_CONTINUE))
101 rc = sasl_client_start(saslconn, method, &interaction, &pc, &olen, &mech);
102 if (rc == SASL_INTERACT)
104 }
while (rc == SASL_INTERACT);
107 client_start = (olen > 0);
109 if ((rc != SASL_OK) && (rc != SASL_CONTINUE))
117 mutt_debug(
LL_DEBUG1,
"Failure starting authentication exchange. No shared mechanisms?\n");
121 sasl_dispose(&saslconn);
128 bufsize =
MAX((olen * 2), 1024);
131 snprintf(buf, bufsize,
"AUTHENTICATE %s", mech);
136 if (sasl_encode64(pc, olen, buf + len, bufsize - len, &olen) != SASL_OK)
141 client_start =
false;
148 while ((rc == SASL_CONTINUE) || (olen > 0))
161 if (adata->
buf[1] ==
'\0')
168 len = strlen(adata->
buf + 2);
176 if (sasl_decode64(adata->
buf + 2, len, buf, bufsize - 1, &len) != SASL_OK)
187 if (!client_start || buf[0])
191 rc = sasl_client_step(saslconn, buf, len, &interaction, &pc, &olen);
192 if (rc == SASL_INTERACT)
194 }
while (rc == SASL_INTERACT);
198 client_start =
false;
204 if ((olen * 2) > bufsize)
209 if (sasl_encode64(pc, olen, buf, bufsize, &olen) != SASL_OK)
250 sasl_dispose(&saslconn);
260 mutt_error(
_(
"%s authentication failed"),
"SASL ");
IMAP authenticator multiplexor.
ImapAuthRes
Results of IMAP Authentication.
@ IMAP_AUTH_FAILURE
Authentication failed.
@ IMAP_AUTH_SUCCESS
Authentication successful.
@ IMAP_AUTH_UNAVAIL
Authentication method not permitted.
int mutt_account_getuser(struct ConnAccount *cac)
Retrieve username into ConnAccount, if necessary.
enum ImapAuthRes imap_auth_sasl(struct ImapAccountData *adata, const char *method)
SASL authenticator - Implements ImapAuth::authenticate() -.
#define mutt_message(...)
#define mutt_debug(LEVEL,...)
int imap_cmd_start(struct ImapAccountData *adata, const char *cmdstr)
Given an IMAP command, send it to the server.
int imap_cmd_step(struct ImapAccountData *adata)
Reads server responses from an IMAP command.
bool imap_code(const char *s)
Was the command successful.
#define IMAP_RES_RESPOND
+
#define IMAP_RES_OK
<tag> OK ...
#define IMAP_CAP_AUTH_ANONYMOUS
AUTH=ANONYMOUS.
#define IMAP_RES_NO
<tag> NO ...
#define IMAP_CAP_SASL_IR
SASL initial response draft.
#define IMAP_RES_CONTINUE
* ...
#define IMAP_RES_BAD
<tag> BAD ...
@ LL_DEBUG2
Log at debug level 2.
@ LL_DEBUG1
Log at debug level 1.
#define MUTT_MEM_REALLOC(pptr, n, type)
#define MUTT_MEM_MALLOC(n, type)
Convenience wrapper for the library headers.
bool mutt_istr_equal(const char *a, const char *b)
Compare two strings, ignoring case.
size_t mutt_str_startswith(const char *str, const char *prefix)
Check whether a string starts with a prefix.
size_t mutt_str_len(const char *a)
Calculate the length of a string, safely.
size_t mutt_str_copy(char *dest, const char *src, size_t dsize)
Copy a string into a buffer (guaranteeing NUL-termination)
Pop-specific Account data.
int mutt_sasl_interact(sasl_interact_t *interaction)
Perform an SASL interaction with the user.
int mutt_sasl_client_new(struct Connection *conn, sasl_conn_t **saslconn)
Wrapper for sasl_client_new()
void mutt_sasl_setup_conn(struct Connection *conn, sasl_conn_t *saslconn)
Set up an SASL connection.
#define mutt_socket_send(conn, buf)
struct ConnAccount account
Account details: username, password, etc.
IMAP-specific Account data -.
ImapCapFlags capabilities
Capability flags.
char * capstr
Capability string from the server.
struct Connection * conn
Connection to IMAP server.