43#include <sasl/saslutil.h>
55 Gsasl_session *gsasl_session = NULL;
56 struct Buffer *output_buf = NULL;
57 struct Buffer *input_buf = NULL;
59 int gsasl_rc = GSASL_OK;
80 buf_printf(output_buf,
"AUTH %s\r\n", chosen_mech);
101 const char *pop_auth_data =
buf_string(input_buf) + 2;
102 char *gsasl_step_output = NULL;
103 gsasl_rc = gsasl_step64(gsasl_session, pop_auth_data, &gsasl_step_output);
104 if ((gsasl_rc == GSASL_NEEDS_MORE) || (gsasl_rc == GSASL_OK))
108 gsasl_free(gsasl_step_output);
113 gsasl_strerror(gsasl_rc));
115 }
while ((gsasl_rc == GSASL_NEEDS_MORE) || (gsasl_rc == GSASL_OK));
147 sasl_conn_t *saslconn = NULL;
148 sasl_interact_t *interaction = NULL;
150 char inbuf[1024] = { 0 };
151 const char *mech = NULL;
152 const char *pc = NULL;
153 unsigned int len = 0, olen = 0;
169 rc = sasl_client_start(saslconn, method, &interaction, &pc, &olen, &mech);
170 if (rc != SASL_INTERACT)
175 if ((rc != SASL_OK) && (rc != SASL_CONTINUE))
177 mutt_debug(
LL_DEBUG1,
"Failure starting authentication exchange. No shared mechanisms?\n");
180 sasl_dispose(&saslconn);
187 unsigned int client_start = olen;
192 size_t bufsize =
MAX((olen * 2), 1024);
195 snprintf(buf, bufsize,
"AUTH %s", mech);
205 sasl_dispose(&saslconn);
215 if (!client_start && (rc != SASL_CONTINUE))
219 (sasl_decode64(inbuf + 2, strlen(inbuf + 2), buf, bufsize - 1, &len) != SASL_OK))
234 rc = sasl_client_step(saslconn, buf, len, &interaction, &pc, &olen);
235 if (rc != SASL_INTERACT)
243 if ((rc != SASL_CONTINUE) && (rc != SASL_OK))
249 if ((olen * 2) > bufsize)
254 if (sasl_encode64(pc, olen, buf, bufsize, &olen) != SASL_OK)
273 sasl_dispose(&saslconn);
278 snprintf(buf, bufsize,
"*\r\n");
279 if (
pop_query(adata, buf, bufsize) == -1)
301 char *p1 = NULL, *p2 = NULL;
305 if ((p1 = strchr(buf,
'<')) && (p2 = strchr(p1,
'>')))
317 struct Md5Ctx md5ctx = { 0 };
318 unsigned char digest[16];
319 char hash[33] = { 0 };
320 char buf[1024] = { 0 };
345 snprintf(buf,
sizeof(buf),
"APOP %s %s\r\n", adata->
conn->
account.
user, hash);
347 switch (
pop_query(adata, buf,
sizeof(buf)))
374 char buf[1024] = { 0 };
376 int rc =
pop_query(adata, buf,
sizeof(buf));
393 _(
"Command USER is not supported by server"));
426 if (!method && !c_pop_oauth_refresh_command)
436 char *auth_cmd = NULL;
440 int rc =
pop_query_d(adata, auth_cmd, strlen(auth_cmd),
444 "AUTH OAUTHBEARER *\r\n" :
462 char decoded_err[1024] = { 0 };
466 decoded_err[len] =
'\0';
469 mutt_error(
"%s %s",
_(
"Authentication failed"), err);
481 { pop_auth_sasl, NULL },
484 { pop_auth_gsasl, NULL },
524 const struct PopAuth *authenticator = NULL;
535 if (c_pop_authenticators && (c_pop_authenticators->
count > 0))
bool mutt_addr_valid_msgid(const char *msgid)
Is this a valid Message ID?
int mutt_b64_decode(const char *in, char *out, size_t olen)
Convert null-terminated base64 string to raw bytes.
int buf_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
size_t buf_addstr(struct Buffer *buf, const char *s)
Add a string to a Buffer.
size_t buf_strcpy(struct Buffer *buf, const char *s)
Copy a string into a Buffer.
static const char * buf_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
const char * cs_subset_string(const struct ConfigSubset *sub, const char *name)
Get a string config item by name.
const struct Slist * cs_subset_slist(const struct ConfigSubset *sub, const char *name)
Get a string-list config item by name.
short cs_subset_number(const struct ConfigSubset *sub, const char *name)
Get a number config item by name.
bool cs_subset_bool(const struct ConfigSubset *sub, const char *name)
Get a boolean config item by name.
Convenience wrapper for the config headers.
int mutt_account_getpass(struct ConnAccount *cac)
Fetch password into ConnAccount, if necessary.
int mutt_account_getuser(struct ConnAccount *cac)
Retrieve username into ConnAccount, if necessary.
char * mutt_account_getoauthbearer(struct ConnAccount *cac, bool xoauth2)
Get an OAUTHBEARER/XOAUTH2 token.
Convenience wrapper for the core headers.
#define mutt_message(...)
#define mutt_debug(LEVEL,...)
const char * mutt_gsasl_get_mech(const char *requested_mech, const char *server_mechlist)
Pick a connection mechanism.
int mutt_gsasl_client_new(struct Connection *conn, const char *mech, Gsasl_session **sctx)
Create a new GNU SASL client.
void mutt_gsasl_client_finish(Gsasl_session **sctx)
Free a GNU SASL client.
@ LL_DEBUG2
Log at debug level 2.
@ LL_DEBUG1
Log at debug level 1.
void mutt_md5_process(const char *str, struct Md5Ctx *md5ctx)
Process a NULL-terminated string.
void mutt_md5_init_ctx(struct Md5Ctx *md5ctx)
Initialise the MD5 computation.
void * mutt_md5_finish_ctx(struct Md5Ctx *md5ctx, void *resbuf)
Process the remaining bytes in the buffer.
void mutt_md5_toascii(const void *digest, char *resbuf)
Convert a binary MD5 digest into ASCII Hexadecimal.
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.
#define mutt_array_size(x)
Convenience wrapper for the library headers.
bool mutt_istr_equal(const char *a, const char *b)
Compare two strings, ignoring case.
char * mutt_str_dup(const char *str)
Copy a string, safely.
int mutt_str_asprintf(char **strp, const char *fmt,...)
bool mutt_strn_equal(const char *a, const char *b, size_t num)
Check for equality of two strings (to a maximum), safely.
size_t mutt_str_startswith(const char *str, const char *prefix)
Check whether a string starts with a prefix.
size_t mutt_str_copy(char *dest, const char *src, size_t dsize)
Copy a string into a buffer (guaranteeing NUL-termination)
struct Buffer * buf_pool_get(void)
Get a Buffer from the pool.
void buf_pool_release(struct Buffer **ptr)
Return a Buffer to the pool.
Pop-specific Account data.
static enum PopAuthRes pop_auth_user(struct PopAccountData *adata, const char *method)
USER authenticator - Implements PopAuth::authenticate()
bool pop_auth_is_valid(const char *authenticator)
Check if string is a valid pop authentication method.
static const struct PopAuth PopAuthenticators[]
Accepted authentication methods.
static enum PopAuthRes pop_auth_apop(struct PopAccountData *adata, const char *method)
APOP authenticator - Implements PopAuth::authenticate()
void pop_apop_timestamp(struct PopAccountData *adata, char *buf)
Get the server timestamp for APOP authentication.
static enum PopAuthRes pop_auth_oauth(struct PopAccountData *adata, const char *method)
Authenticate a POP connection using OAUTHBEARER - Implements PopAuth::authenticate()
int pop_authenticate(struct PopAccountData *adata)
Authenticate with a POP server.
int pop_connect(struct PopAccountData *adata)
Open connection.
int pop_query_d(struct PopAccountData *adata, char *buf, size_t buflen, char *msg)
Send data from buffer and receive answer to the same buffer.
PopAuthRes
POP authentication responses.
@ POP_A_UNAVAIL
No valid authentication method.
@ POP_A_SUCCESS
Authenticated successfully.
@ POP_A_FAILURE
Authentication failed.
@ POP_A_SOCKET
Connection lost.
#define pop_query(adata, buf, buflen)
@ POP_DISCONNECTED
Disconnected from server.
#define STAILQ_FOREACH(var, head, field)
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.
int mutt_socket_readln_d(char *buf, size_t buflen, struct Connection *conn, int dbg)
Read a line from a socket.
#define MUTT_SOCK_LOG_FULL
#define mutt_socket_send(conn, buf)
#define mutt_socket_buffer_readln(buf, conn)
String manipulation buffer.
char * data
Pointer to data.
Login details for a remote server.
struct ConnAccount account
Account details: username, password, etc.
Cursor for the MD5 hashing.
Container for Accounts, Notifications.
struct ConfigSubset * sub
Inherited config items.
POP-specific Account data -.
char err_msg[POP_CMD_RESPONSE]
struct Connection * conn
Connection to POP server.
unsigned int cmd_user
optional command USER
struct Buffer auth_list
list of auth mechanisms
POP authentication multiplexor.
const char * method
Name of authentication method supported, NULL means variable.
enum PopAuthRes(* authenticate)(struct PopAccountData *adata, const char *method)
Authenticate a POP connection.
struct ListHead head
List containing values.
size_t count
Number of values in list.