33#include <sasl/saslutil.h>
48 sasl_conn_t *saslconn = NULL;
49 sasl_interact_t *interaction = NULL;
53 const char *mech = NULL;
54 const char *pc = NULL;
55 unsigned int len = 0, olen = 0;
78 sasl_dispose(&saslconn);
86 rc = sasl_client_start(saslconn,
"AUTH=ANONYMOUS", NULL, &pc, &olen, &mech);
92 sasl_dispose(&saslconn);
96 if ((rc != SASL_OK) && (rc != SASL_CONTINUE))
100 rc = sasl_client_start(saslconn, method, &interaction, &pc, &olen, &mech);
101 if (rc == SASL_INTERACT)
103 }
while (rc == SASL_INTERACT);
106 client_start = (olen > 0);
108 if ((rc != SASL_OK) && (rc != SASL_CONTINUE))
116 mutt_debug(
LL_DEBUG1,
"Failure starting authentication exchange. No shared mechanisms?\n");
120 sasl_dispose(&saslconn);
127 bufsize =
MAX((olen * 2), 1024);
130 snprintf(buf, bufsize,
"AUTHENTICATE %s", mech);
135 if (sasl_encode64(pc, olen, buf + len, bufsize - len, &olen) != SASL_OK)
140 client_start =
false;
147 while ((rc == SASL_CONTINUE) || (olen > 0))
160 if (adata->
buf[1] ==
'\0')
167 len = strlen(adata->
buf + 2);
175 if (sasl_decode64(adata->
buf + 2, len, buf, bufsize - 1, &len) != SASL_OK)
186 if (!client_start || buf[0])
190 rc = sasl_client_step(saslconn, buf, len, &interaction, &pc, &olen);
191 if (rc == SASL_INTERACT)
193 }
while (rc == SASL_INTERACT);
197 client_start =
false;
203 if ((olen * 2) > bufsize)
208 if (sasl_encode64(pc, olen, buf, bufsize, &olen) != SASL_OK)
249 sasl_dispose(&saslconn);
259 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,...)
Imap-specific Account data.
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.
Shared constants/structs that are private to IMAP.
#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 FREE(x)
Free memory and set the pointer to NULL.
#define MUTT_MEM_REALLOC(pptr, n, type)
#define MUTT_MEM_MALLOC(n, type)
#define MAX(a, b)
Return the maximum of two values.
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)
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.
char * buf
Command buffer.
struct Connection * conn
Connection to IMAP server.