32#include <sasl/saslutil.h>
47 sasl_conn_t *saslconn = NULL;
48 sasl_interact_t *interaction = NULL;
52 const char *mech = NULL;
53 const char *pc = NULL;
54 unsigned int len = 0, olen = 0;
77 sasl_dispose(&saslconn);
85 rc = sasl_client_start(saslconn,
"AUTH=ANONYMOUS", NULL, &pc, &olen, &mech);
91 sasl_dispose(&saslconn);
95 if ((rc != SASL_OK) && (rc != SASL_CONTINUE))
99 rc = sasl_client_start(saslconn, method, &interaction, &pc, &olen, &mech);
100 if (rc == SASL_INTERACT)
102 }
while (rc == SASL_INTERACT);
105 client_start = (olen > 0);
107 if ((rc != SASL_OK) && (rc != SASL_CONTINUE))
115 mutt_debug(
LL_DEBUG1,
"Failure starting authentication exchange. No shared mechanisms?\n");
119 sasl_dispose(&saslconn);
126 bufsize =
MAX((olen * 2), 1024);
129 snprintf(buf, bufsize,
"AUTHENTICATE %s", mech);
134 if (sasl_encode64(pc, olen, buf + len, bufsize - len, &olen) != SASL_OK)
139 client_start =
false;
146 while ((rc == SASL_CONTINUE) || (olen > 0))
159 if (adata->
buf[1] ==
'\0')
166 len = strlen(adata->
buf + 2);
174 if (sasl_decode64(adata->
buf + 2, len, buf, bufsize - 1, &len) != SASL_OK)
185 if (!client_start || buf[0])
189 rc = sasl_client_step(saslconn, buf, len, &interaction, &pc, &olen);
190 if (rc == SASL_INTERACT)
192 }
while (rc == SASL_INTERACT);
196 client_start =
false;
202 if ((olen * 2) > bufsize)
207 if (sasl_encode64(pc, olen, buf, bufsize, &olen) != SASL_OK)
248 sasl_dispose(&saslconn);
258 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.
void * mutt_mem_malloc(size_t size)
Allocate memory on the heap.
void mutt_mem_realloc(void *ptr, size_t size)
Resize a block of memory on the heap.
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.