45#include <sasl/saslutil.h>
57 Gsasl_session *gsasl_session = NULL;
58 struct Buffer *output_buf = NULL;
59 struct Buffer *input_buf = NULL;
61 int gsasl_rc = GSASL_OK;
82 buf_printf(output_buf,
"AUTH %s\r\n", chosen_mech);
103 const char *pop_auth_data =
buf_string(input_buf) + 2;
104 char *gsasl_step_output = NULL;
105 gsasl_rc = gsasl_step64(gsasl_session, pop_auth_data, &gsasl_step_output);
106 if ((gsasl_rc == GSASL_NEEDS_MORE) || (gsasl_rc == GSASL_OK))
110 gsasl_free(gsasl_step_output);
115 gsasl_strerror(gsasl_rc));
117 }
while ((gsasl_rc == GSASL_NEEDS_MORE) || (gsasl_rc == GSASL_OK));
149 sasl_conn_t *saslconn = NULL;
150 sasl_interact_t *interaction = NULL;
152 char inbuf[1024] = { 0 };
153 const char *mech = NULL;
154 const char *pc = NULL;
155 unsigned int len = 0, olen = 0;
171 rc = sasl_client_start(saslconn, method, &interaction, &pc, &olen, &mech);
172 if (rc != SASL_INTERACT)
177 if ((rc != SASL_OK) && (rc != SASL_CONTINUE))
179 mutt_debug(
LL_DEBUG1,
"Failure starting authentication exchange. No shared mechanisms?\n");
182 sasl_dispose(&saslconn);
189 unsigned int client_start = olen;
194 size_t bufsize =
MAX((olen * 2), 1024);
197 snprintf(buf, bufsize,
"AUTH %s", mech);
207 sasl_dispose(&saslconn);
217 if (!client_start && (rc != SASL_CONTINUE))
221 (sasl_decode64(inbuf + 2, strlen(inbuf + 2), buf, bufsize - 1, &len) != SASL_OK))
236 rc = sasl_client_step(saslconn, buf, len, &interaction, &pc, &olen);
237 if (rc != SASL_INTERACT)
245 if ((rc != SASL_CONTINUE) && (rc != SASL_OK))
251 if ((olen * 2) > bufsize)
256 if (sasl_encode64(pc, olen, buf, bufsize, &olen) != SASL_OK)
275 sasl_dispose(&saslconn);
280 snprintf(buf, bufsize,
"*\r\n");
281 if (
pop_query(adata, buf, bufsize) == -1)
303 char *p1 = NULL, *p2 = NULL;
307 if ((p1 = strchr(buf,
'<')) && (p2 = strchr(p1,
'>')))
319 struct Md5Ctx md5ctx = { 0 };
320 unsigned char digest[16];
321 char hash[33] = { 0 };
322 char buf[1024] = { 0 };
347 snprintf(buf,
sizeof(buf),
"APOP %s %s\r\n", adata->
conn->
account.
user, hash);
349 switch (
pop_query(adata, buf,
sizeof(buf)))
376 char buf[1024] = { 0 };
378 int rc =
pop_query(adata, buf,
sizeof(buf));
395 _(
"Command USER is not supported by server"));
428 if (!method && !c_pop_oauth_refresh_command)
438 char *auth_cmd = NULL;
442 int rc =
pop_query_d(adata, auth_cmd, strlen(auth_cmd),
446 "AUTH OAUTHBEARER *\r\n" :
464 char decoded_err[1024] = { 0 };
468 decoded_err[len] =
'\0';
471 mutt_error(
"%s %s",
_(
"Authentication failed"), err);
483 { pop_auth_sasl, NULL },
486 { pop_auth_gsasl, NULL },
526 const struct PopAuth *authenticator = NULL;
537 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,...)
static enum PopAuthRes pop_auth_user(struct PopAccountData *adata, const char *method)
USER authenticator - Implements PopAuth::authenticate() -.
static enum PopAuthRes pop_auth_apop(struct PopAccountData *adata, const char *method)
APOP authenticator - Implements PopAuth::authenticate() -.
static enum PopAuthRes pop_auth_oauth(struct PopAccountData *adata, const char *method)
Authenticate a POP connection using OAUTHBEARER - Implements PopAuth::authenticate() -.
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.
#define MUTT_MEM_REALLOC(pptr, n, type)
#define MUTT_MEM_MALLOC(n, type)
#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.
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.
void pop_apop_timestamp(struct PopAccountData *adata, char *buf)
Get the server timestamp for APOP authentication.
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)
struct ListHead head
List containing values.
size_t count
Number of values in list.