49#include <sys/socket.h>
64 const sasl_ssf_t *
ssf;
104 "ANONYMOUS",
"CRAM-MD5",
"DIGEST-MD5",
"EXTERNAL",
105 "GS2-IAKERB",
"GS2-KRB5",
"GSS-SPNEGO",
"GSSAPI",
106 "LOGIN",
"NTLM",
"OTP-MD4",
"OTP-MD5",
107 "OTP-SHA1",
"PASSDSS-3DES-1",
"PLAIN",
"SCRAM-SHA-1",
108 "SCRAM-SHA-224",
"SCRAM-SHA-256",
"SCRAM-SHA-384",
"SCRAM-SHA-512",
115#define MUTT_SASL_MAXBUF 65536
120#define IP_PORT_BUFLEN (NI_MAXHOST + NI_MAXSERV)
155 mutt_debug(
LL_DEBUG1,
"The name could not be resolved at this time. Future attempts may succeed\n");
167 mutt_debug(
LL_DEBUG1,
"The address family was not recognized or the address length was invalid for the specified family\n");
176 "NI_NAMEREQD is set and the host's name can't be located, or both nodename and servname were null.\n");
180 mutt_debug(
LL_DEBUG1,
"A system error occurred. The error code can be found in errno(%d,%s))\n",
181 errno, strerror(errno));
202static int iptostring(
const struct sockaddr *addr, socklen_t addrlen,
char *out,
205 char hbuf[NI_MAXHOST],
pbuf[NI_MAXSERV];
209 return SASL_BADPARAM;
211 rc = getnameinfo(addr, addrlen, hbuf,
sizeof(hbuf),
pbuf,
sizeof(
pbuf),
220 if (outlen < strlen(hbuf) + strlen(
pbuf) + 2)
223 snprintf(out, outlen,
"%s;%s", hbuf,
pbuf);
237 if (priority == SASL_LOG_NONE)
240 int mutt_priority = 0;
262 mutt_debug(mutt_priority,
"SASL: %s\n", message);
274 static bool sasl_init =
false;
276 static sasl_callback_t callbacks[2];
283 callbacks[0].id = SASL_CB_LOG;
285 callbacks[0].context = NULL;
287 callbacks[1].id = SASL_CB_LIST_END;
288 callbacks[1].proc = NULL;
289 callbacks[1].context = NULL;
291 rc = sasl_client_init(callbacks);
324 return SASL_BADPARAM;
327 (
id == SASL_CB_AUTHNAME) ?
"authname" :
"user", cac->
host, cac->
port);
329 if (
id == SASL_CB_AUTHNAME)
333 *result = cac->
login;
343 *len = strlen(*result);
361 if (!cac || !psecret)
362 return SASL_BADPARAM;
369 len = strlen(cac->
pass);
388 callback->id = SASL_CB_USER;
390 callback->context = cac;
393 callback->id = SASL_CB_AUTHNAME;
395 callback->context = cac;
398 callback->id = SASL_CB_PASS;
400 callback->context = cac;
403 callback->id = SASL_CB_GETREALM;
404 callback->proc = NULL;
405 callback->context = NULL;
408 callback->id = SASL_CB_LIST_END;
409 callback->proc = NULL;
410 callback->context = NULL;
426 int rc = sasldata->
open(conn);
455 int rc = conn->
close(conn);
471 if (sasldata->
blen > sasldata->
bpos)
473 olen = ((sasldata->
blen - sasldata->
bpos) > count) ?
477 memcpy(
buf, sasldata->
buf + sasldata->
bpos, olen);
478 sasldata->
bpos += olen;
489 if (*sasldata->
ssf != 0)
494 rc = sasldata->
read(conn,
buf, count);
504 }
while (sasldata->
blen == 0);
506 olen = ((sasldata->
blen - sasldata->
bpos) > count) ?
510 memcpy(
buf, sasldata->
buf, olen);
511 sasldata->
bpos += olen;
517 rc = sasldata->
read(conn,
buf, count);
532 const char *
pbuf = NULL;
533 unsigned int olen,
plen;
539 if (*sasldata->
ssf != 0)
559 }
while (count > *sasldata->
pbufsize);
564 rc = sasldata->
write(conn,
buf, count);
585 rc = sasldata->
poll(conn, wait_secs);
603 sasl_security_properties_t secprops;
604 struct sockaddr_storage local, remote;
620 size =
sizeof(local);
621 if (getsockname(conn->
fd, (
struct sockaddr *) &local, &size) == 0)
633 size =
sizeof(remote);
634 if (getpeername(conn->
fd, (
struct sockaddr *) &remote, &size) == 0)
657 memset(&secprops, 0,
sizeof(secprops));
659 secprops.max_ssf = 0x7fff;
661 if (sasl_setprop(*saslconn, SASL_SEC_PROPS, &secprops) != SASL_OK)
663 mutt_error(
_(
"Error setting SASL security properties"));
664 sasl_dispose(saslconn);
672 if (sasl_setprop(*saslconn, SASL_SSF_EXTERNAL, &conn->
ssf) != SASL_OK)
674 mutt_error(
_(
"Error setting SASL external security strength"));
675 sasl_dispose(saslconn);
682 if (sasl_setprop(*saslconn, SASL_AUTH_EXTERNAL, conn->
account.
user) != SASL_OK)
684 mutt_error(
_(
"Error setting SASL external user name"));
685 sasl_dispose(saslconn);
703 char prompt[128] = { 0 };
706 while (interaction->id != SASL_CB_LIST_END)
710 snprintf(prompt,
sizeof(prompt),
"%s: ", interaction->prompt);
714 false, NULL, NULL, NULL) != 0))
741 const void *tmp = NULL;
745 sasl_getprop(
saslconn, SASL_SSF, &tmp);
749 conn->
ssf += *sasldata->
ssf;
750 sasl_getprop(
saslconn, SASL_MAXOUTBUF, &tmp);
755 sasldata->
buf = NULL;
size_t mutt_buffer_len(const struct Buffer *buf)
Calculate the length of a Buffer.
void mutt_buffer_reset(struct Buffer *buf)
Reset an existing Buffer.
char * mutt_buffer_strdup(const struct Buffer *buf)
Copy a Buffer's string.
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.
int mutt_account_getlogin(struct ConnAccount *cac)
Retrieve login info into ConnAccount, if necessary.
int mutt_buffer_get_field(const char *field, struct Buffer *buf, CompletionFlags complete, bool multiple, struct Mailbox *m, char ***files, int *numfiles)
Ask the user for a string.
bool OptNoCurses
(pseudo) when sending in batch mode
static int mutt_sasl_conn_close(struct Connection *conn)
Close SASL connection - Implements Connection::close() -.
int(* close)(struct Connection *conn)
Close a socket Connection - Implements Connection::close() -.
int(* open)(struct Connection *conn)
Open a socket Connection - Implements Connection::open() -.
static int mutt_sasl_conn_open(struct Connection *conn)
Empty wrapper for underlying open function - Implements Connection::open() -.
int(* poll)(struct Connection *conn, time_t wait_secs)
Check whether a socket read would block - Implements Connection::poll() -.
static int mutt_sasl_conn_poll(struct Connection *conn, time_t wait_secs)
Check an SASL connection for data - Implements Connection::poll() -.
static int mutt_sasl_conn_read(struct Connection *conn, char *buf, size_t count)
Read data from an SASL connection - Implements Connection::read() -.
int(* read)(struct Connection *conn, char *buf, size_t count)
Read from a socket Connection - Implements Connection::read() -.
static int mutt_sasl_conn_write(struct Connection *conn, const char *buf, size_t count)
Write to an SASL connection - Implements Connection::write() -.
int(* write)(struct Connection *conn, const char *buf, size_t count)
Write to a socket Connection - Implements Connection::write() -.
#define mutt_debug(LEVEL,...)
@ LL_DEBUG3
Log at debug level 3.
@ 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.
#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.
Many unsorted constants and some structs.
#define MUTT_COMP_NO_FLAGS
No flags are set.
static unsigned char * pbuf
Cached PGP data packet.
static size_t plen
Length of cached packet.
void mutt_buffer_pool_release(struct Buffer **pbuf)
Free a Buffer from the pool.
struct Buffer * mutt_buffer_pool_get(void)
Get a Buffer from the pool.
static int mutt_sasl_cb_pass(sasl_conn_t *conn, void *context, int id, sasl_secret_t **psecret)
SASL callback function to get password.
static int mutt_sasl_cb_authname(void *context, int id, const char **result, unsigned int *len)
Callback to retrieve authname or user from ConnAccount.
static sasl_secret_t * secret_ptr
static int getnameinfo_err(int rc)
Convert a getaddrinfo() error code into an SASL error code.
int mutt_sasl_interact(sasl_interact_t *interaction)
Perform an SASL interaction with the user.
static int mutt_sasl_start(void)
Initialise SASL library.
static int mutt_sasl_cb_log(void *context, int priority, const char *message)
Callback to log SASL messages.
void mutt_sasl_done(void)
Invoke when processing is complete.
static sasl_callback_t * mutt_sasl_get_callbacks(struct ConnAccount *cac)
Get the SASL callback functions.
static const char *const SaslAuthenticators[]
Authenticaion methods supported by Cyrus SASL.
static sasl_callback_t MuttSaslCallbacks[5]
static int iptostring(const struct sockaddr *addr, socklen_t addrlen, char *out, unsigned int outlen)
Convert IP Address to string.
bool sasl_auth_validator(const char *authenticator)
Validate an auth method against Cyrus SASL methods.
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.
SASL authentication support.
String manipulation buffer.
Login details for a remote server.
char login[128]
Login name.
const char * service
Name of the service, e.g. "imap".
char host[128]
Server to login to.
unsigned short port
Port to connect to.
void * sockdata
Backend-specific socket data.
int(* poll)(struct Connection *conn, time_t wait_secs)
int(* write)(struct Connection *conn, const char *buf, size_t count)
unsigned int ssf
Security strength factor, in bits (see notes)
int(* close)(struct Connection *conn)
struct ConnAccount account
Account details: username, password, etc.
int(* open)(struct Connection *conn)
int fd
Socket file descriptor.
int(* read)(struct Connection *conn, char *buf, size_t count)
SASL authentication API -.
void * sockdata
Underlying socket data.
unsigned int blen
Size of the read buffer.
unsigned int bpos
Current read position.
const unsigned int * pbufsize
const char * buf
Buffer for data read from the connection.