NeoMutt  2025-12-11-276-g10b23b
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
sasl.c File Reference

SASL authentication support. More...

#include "config.h"
#include <errno.h>
#include <netdb.h>
#include <sasl/sasl.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <sys/socket.h>
#include <sys/types.h>
#include "mutt/lib.h"
#include "sasl.h"
#include "editor/lib.h"
#include "history/lib.h"
#include "connaccount.h"
#include "connection.h"
#include "globals.h"
+ Include dependency graph for sasl.c:

Go to the source code of this file.

Data Structures

struct  SaslSockData
 SASL authentication API -. More...
 

Macros

#define MUTT_SASL_MAXBUF   65536
 Maximum size for SASL protection buffer.
 
#define IP_PORT_BUFLEN   (NI_MAXHOST + NI_MAXSERV)
 Buffer size for "host;port" string (NI_MAXHOST + NI_MAXSERV)
 

Functions

bool sasl_auth_validator (const char *authenticator)
 Validate an auth method against Cyrus SASL methods.
 
static int getnameinfo_err (int rc)
 Convert a getaddrinfo() error code into an SASL error code.
 
static int iptostring (const struct sockaddr *addr, socklen_t addrlen, char *out, unsigned int outlen)
 Convert IP Address to string.
 
static int mutt_sasl_cb_log (void *context, int priority, const char *message)
 Callback to log SASL messages.
 
int mutt_sasl_start (void)
 Initialise SASL library.
 
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 int mutt_sasl_cb_pass (sasl_conn_t *conn, void *context, int id, sasl_secret_t **psecret)
 SASL callback function to get password.
 
static sasl_callback_t * mutt_sasl_get_callbacks (struct ConnAccount *cac)
 Get the SASL callback functions.
 
static int mutt_sasl_conn_open (struct Connection *conn)
 Empty wrapper for underlying open function - Implements Connection::open() -.
 
static int mutt_sasl_conn_close (struct Connection *conn)
 Close SASL connection - Implements Connection::close() -.
 
static int mutt_sasl_conn_read (struct Connection *conn, char *buf, size_t count)
 Read data from an SASL 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() -.
 
static int mutt_sasl_conn_poll (struct Connection *conn, time_t wait_secs)
 Check if any data is waiting on a socket - Implements Connection::poll() -.
 
int mutt_sasl_client_new (struct Connection *conn, sasl_conn_t **saslconn)
 Wrapper for sasl_client_new()
 
int mutt_sasl_interact (sasl_interact_t *interaction)
 Perform an SASL interaction with the user.
 
void mutt_sasl_setup_conn (struct Connection *conn, sasl_conn_t *saslconn)
 Set up an SASL connection.
 
void mutt_sasl_cleanup (void)
 Invoke when processing is complete.
 

Variables

static const char *const SaslAuthenticators []
 Authentication methods supported by Cyrus SASL.
 
static sasl_callback_t MuttSaslCallbacks [5]
 SASL callback functions, e.g. mutt_sasl_cb_authname(), mutt_sasl_cb_pass()
 
static sasl_secret_t * SecretPtr = NULL
 SASL secret, to store the password.
 

Detailed Description

SASL authentication support.

Authors
  • Richard Russon
  • Ian Zimmerman
  • Alejandro Colomar

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Definition in file sasl.c.

Macro Definition Documentation

◆ MUTT_SASL_MAXBUF

#define MUTT_SASL_MAXBUF   65536

Maximum size for SASL protection buffer.

Definition at line 115 of file sasl.c.

◆ IP_PORT_BUFLEN

#define IP_PORT_BUFLEN   (NI_MAXHOST + NI_MAXSERV)

Buffer size for "host;port" string (NI_MAXHOST + NI_MAXSERV)

Definition at line 118 of file sasl.c.

Function Documentation

◆ sasl_auth_validator()

bool sasl_auth_validator ( const char * authenticator)

Validate an auth method against Cyrus SASL methods.

Parameters
authenticatorName of the authenticator to validate
Return values
trueArgument matches an accepted auth method

Definition at line 131 of file sasl.c.

132{
133 for (size_t i = 0; i < countof(SaslAuthenticators); i++)
134 {
135 const char *auth = SaslAuthenticators[i];
136 if (mutt_istr_equal(auth, authenticator))
137 return true;
138 }
139
140 return false;
141}
#define countof(x)
Definition memory.h:49
bool mutt_istr_equal(const char *a, const char *b)
Compare two strings, ignoring case.
Definition string.c:674
static const char *const SaslAuthenticators[]
Authentication methods supported by Cyrus SASL.
Definition sasl.c:105
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getnameinfo_err()

static int getnameinfo_err ( int rc)
static

Convert a getaddrinfo() error code into an SASL error code.

Parameters
rcgetaddrinfo() error code, e.g. EAI_AGAIN
Return values
numSASL error code, e.g. SASL_FAIL

Definition at line 148 of file sasl.c.

149{
150 int err;
151 mutt_debug(LL_DEBUG1, "getnameinfo: ");
152 switch (rc)
153 {
154 case EAI_AGAIN:
155 mutt_debug(LL_DEBUG1, "The name could not be resolved at this time. Future attempts may succeed\n");
156 err = SASL_TRYAGAIN;
157 break;
158 case EAI_BADFLAGS:
159 mutt_debug(LL_DEBUG1, "The flags had an invalid value\n");
160 err = SASL_BADPARAM;
161 break;
162 case EAI_FAIL:
163 mutt_debug(LL_DEBUG1, "A non-recoverable error occurred\n");
164 err = SASL_FAIL;
165 break;
166 case EAI_FAMILY:
167 mutt_debug(LL_DEBUG1, "The address family was not recognized or the address length was invalid for the specified family\n");
168 err = SASL_BADPROT;
169 break;
170 case EAI_MEMORY:
171 mutt_debug(LL_DEBUG1, "There was a memory allocation failure\n");
172 err = SASL_NOMEM;
173 break;
174 case EAI_NONAME:
175 mutt_debug(LL_DEBUG1, "The name does not resolve for the supplied parameters. "
176 "NI_NAMEREQD is set and the host's name can't be located, or both nodename and servname were null.\n");
177 err = SASL_FAIL; /* no real equivalent */
178 break;
179 case EAI_SYSTEM:
180 mutt_debug(LL_DEBUG1, "A system error occurred. The error code can be found in errno(%d,%s))\n",
181 errno, strerror(errno));
182 err = SASL_FAIL; /* no real equivalent */
183 break;
184 default:
185 mutt_debug(LL_DEBUG1, "Unknown error %d\n", rc);
186 err = SASL_FAIL; /* no real equivalent */
187 break;
188 }
189 return err;
190}
#define mutt_debug(LEVEL,...)
Definition logging2.h:91
@ LL_DEBUG1
Log at debug level 1.
Definition logging2.h:45
+ Here is the caller graph for this function:

◆ iptostring()

static int iptostring ( const struct sockaddr * addr,
socklen_t addrlen,
char * out,
unsigned int outlen )
static

Convert IP Address to string.

Parameters
addrIP address
addrlenSize of addr struct
outBuffer for result
outlenLength of buffer
Return values
numSASL error code, e.g. SASL_BADPARAM

utility function, copied from sasl2 sample code

Definition at line 202 of file sasl.c.

204{
205 char hbuf[NI_MAXHOST], pbuf[NI_MAXSERV];
206 int rc;
207
208 if (!addr || !out)
209 return SASL_BADPARAM;
210
211 rc = getnameinfo(addr, addrlen, hbuf, sizeof(hbuf), pbuf, sizeof(pbuf),
212 NI_NUMERICHOST |
213#ifdef NI_WITHSCOPEID
214 NI_WITHSCOPEID |
215#endif
216 NI_NUMERICSERV);
217 if (rc != 0)
218 return getnameinfo_err(rc);
219
220 if (outlen < strlen(hbuf) + strlen(pbuf) + 2)
221 return SASL_BUFOVER;
222
223 snprintf(out, outlen, "%s;%s", hbuf, pbuf);
224
225 return SASL_OK;
226}
static int getnameinfo_err(int rc)
Convert a getaddrinfo() error code into an SASL error code.
Definition sasl.c:148
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_sasl_cb_log()

static int mutt_sasl_cb_log ( void * context,
int priority,
const char * message )
static

Callback to log SASL messages.

Parameters
contextSupplied context, always NULL
priorityDebug level
messageMessage
Return values
numSASL_OK, always

Definition at line 235 of file sasl.c.

236{
237 if (priority == SASL_LOG_NONE)
238 return SASL_OK;
239
240 int mutt_priority = 0;
241 switch (priority)
242 {
243 case SASL_LOG_TRACE:
244 case SASL_LOG_PASS:
245 mutt_priority = 5;
246 break;
247 case SASL_LOG_DEBUG:
248 case SASL_LOG_NOTE:
249 mutt_priority = 3;
250 break;
251 case SASL_LOG_FAIL:
252 case SASL_LOG_WARN:
253 mutt_priority = 2;
254 break;
255 case SASL_LOG_ERR:
256 mutt_priority = 1;
257 break;
258 default:
259 mutt_debug(LL_DEBUG1, "SASL unknown log priority: %s\n", message);
260 return SASL_OK;
261 }
262 mutt_debug(mutt_priority, "SASL: %s\n", message);
263 return SASL_OK;
264}
+ Here is the caller graph for this function:

◆ mutt_sasl_start()

int mutt_sasl_start ( void )

Initialise SASL library.

Return values
numSASL error code, e.g. SASL_OK

Call before doing an SASL exchange (initialises library if necessary).

Definition at line 272 of file sasl.c.

273{
274 static bool sasl_init = false;
275
276 static sasl_callback_t callbacks[2];
277 int rc;
278
279 if (sasl_init)
280 return SASL_OK;
281
282 /* set up default logging callback */
283 callbacks[0].id = SASL_CB_LOG;
284 callbacks[0].proc = (int (*)(void))(intptr_t) mutt_sasl_cb_log;
285 callbacks[0].context = NULL;
286
287 callbacks[1].id = SASL_CB_LIST_END;
288 callbacks[1].proc = NULL;
289 callbacks[1].context = NULL;
290
291 rc = sasl_client_init(callbacks);
292
293 if (rc != SASL_OK)
294 {
295 mutt_debug(LL_DEBUG1, "libsasl initialisation failed\n");
296 return SASL_FAIL;
297 }
298
299 sasl_init = true;
300
301 return SASL_OK;
302}
static int mutt_sasl_cb_log(void *context, int priority, const char *message)
Callback to log SASL messages.
Definition sasl.c:235
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_sasl_cb_authname()

static int mutt_sasl_cb_authname ( void * context,
int id,
const char ** result,
unsigned int * len )
static

Callback to retrieve authname or user from ConnAccount.

Parameters
[in]contextConnAccount
[in]idField to get. SASL_CB_USER or SASL_CB_AUTHNAME
[out]resultResulting string
[out]lenLength of result
Return values
numSASL error code, e.g. SASL_FAIL

Definition at line 312 of file sasl.c.

313{
314 if (!result)
315 return SASL_FAIL;
316
317 struct ConnAccount *cac = context;
318
319 *result = NULL;
320 if (len)
321 *len = 0;
322
323 if (!cac)
324 return SASL_BADPARAM;
325
326 mutt_debug(LL_DEBUG2, "getting %s for %s:%u\n",
327 (id == SASL_CB_AUTHNAME) ? "authname" : "user", cac->host, cac->port);
328
329 if (id == SASL_CB_AUTHNAME)
330 {
331 if (mutt_account_getlogin(cac) < 0)
332 return SASL_FAIL;
333 *result = cac->login;
334 }
335 else
336 {
337 if (mutt_account_getuser(cac) < 0)
338 return SASL_FAIL;
339 *result = cac->user;
340 }
341
342 if (len)
343 *len = strlen(*result);
344
345 return SASL_OK;
346}
int mutt_account_getuser(struct ConnAccount *cac)
Retrieve username into ConnAccount, if necessary.
Definition connaccount.c:51
int mutt_account_getlogin(struct ConnAccount *cac)
Retrieve login info into ConnAccount, if necessary.
@ LL_DEBUG2
Log at debug level 2.
Definition logging2.h:46
Login details for a remote server.
Definition connaccount.h:53
char login[128]
Login name.
Definition connaccount.h:55
char user[128]
Username.
Definition connaccount.h:56
char host[128]
Server to login to.
Definition connaccount.h:54
unsigned short port
Port to connect to.
Definition connaccount.h:58
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_sasl_cb_pass()

static int mutt_sasl_cb_pass ( sasl_conn_t * conn,
void * context,
int id,
sasl_secret_t ** psecret )
static

SASL callback function to get password.

Parameters
[in]connConnection to a server
[in]contextConnAccount
[in]idSASL_CB_PASS
[out]psecretSASL secret
Return values
numSASL error code, e.g SASL_FAIL

Definition at line 356 of file sasl.c.

357{
358 struct ConnAccount *cac = context;
359 int len;
360
361 if (!cac || !psecret)
362 return SASL_BADPARAM;
363
364 mutt_debug(LL_DEBUG2, "getting password for %s@%s:%u\n", cac->login, cac->host, cac->port);
365
366 if (mutt_account_getpass(cac) < 0)
367 return SASL_FAIL;
368
369 len = strlen(cac->pass);
370
371 mutt_mem_realloc(&SecretPtr, sizeof(sasl_secret_t) + len);
372 memcpy((char *) SecretPtr->data, cac->pass, (size_t) len);
373 SecretPtr->len = len;
374 *psecret = SecretPtr;
375
376 return SASL_OK;
377}
int mutt_account_getpass(struct ConnAccount *cac)
Fetch password into ConnAccount, if necessary.
void mutt_mem_realloc(void *pptr, size_t size)
Resize a block of memory on the heap.
Definition memory.c:146
static sasl_secret_t * SecretPtr
SASL secret, to store the password.
Definition sasl.c:124
char pass[256]
Password.
Definition connaccount.h:57
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_sasl_get_callbacks()

static sasl_callback_t * mutt_sasl_get_callbacks ( struct ConnAccount * cac)
static

Get the SASL callback functions.

Parameters
cacConnAccount to associate with callbacks
Return values
ptrArray of callback functions

Definition at line 384 of file sasl.c.

385{
386 sasl_callback_t *callback = MuttSaslCallbacks;
387
388 callback->id = SASL_CB_USER;
389 callback->proc = (int (*)(void))(intptr_t) mutt_sasl_cb_authname;
390 callback->context = cac;
391 callback++;
392
393 callback->id = SASL_CB_AUTHNAME;
394 callback->proc = (int (*)(void))(intptr_t) mutt_sasl_cb_authname;
395 callback->context = cac;
396 callback++;
397
398 callback->id = SASL_CB_PASS;
399 callback->proc = (int (*)(void))(intptr_t) mutt_sasl_cb_pass;
400 callback->context = cac;
401 callback++;
402
403 callback->id = SASL_CB_GETREALM;
404 callback->proc = NULL;
405 callback->context = NULL;
406 callback++;
407
408 callback->id = SASL_CB_LIST_END;
409 callback->proc = NULL;
410 callback->context = NULL;
411
412 return MuttSaslCallbacks;
413}
static int mutt_sasl_cb_pass(sasl_conn_t *conn, void *context, int id, sasl_secret_t **psecret)
SASL callback function to get password.
Definition sasl.c:356
static int mutt_sasl_cb_authname(void *context, int id, const char **result, unsigned int *len)
Callback to retrieve authname or user from ConnAccount.
Definition sasl.c:312
static sasl_callback_t MuttSaslCallbacks[5]
SASL callback functions, e.g. mutt_sasl_cb_authname(), mutt_sasl_cb_pass()
Definition sasl.c:121
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_sasl_client_new()

int mutt_sasl_client_new ( struct Connection * conn,
sasl_conn_t ** saslconn )

Wrapper for sasl_client_new()

Parameters
[in]connConnection to a server
[out]saslconnSASL connection
Return values
0Success
-1Error

which also sets various security properties. If this turns out to be fine for POP too we can probably stop exporting mutt_sasl_get_callbacks().

Definition at line 601 of file sasl.c.

602{
603 if (mutt_sasl_start() != SASL_OK)
604 return -1;
605
606 if (!conn->account.service)
607 {
608 mutt_error(_("Unknown SASL profile"));
609 return -1;
610 }
611
612 socklen_t size;
613
614 struct sockaddr_storage local = { 0 };
615 char iplocalport[IP_PORT_BUFLEN] = { 0 };
616 char *plp = NULL;
617 size = sizeof(local);
618 if (getsockname(conn->fd, (struct sockaddr *) &local, &size) == 0)
619 {
620 if (iptostring((struct sockaddr *) &local, size, iplocalport, IP_PORT_BUFLEN) == SASL_OK)
621 plp = iplocalport;
622 else
623 mutt_debug(LL_DEBUG2, "SASL failed to parse local IP address\n");
624 }
625 else
626 {
627 mutt_debug(LL_DEBUG2, "SASL failed to get local IP address\n");
628 }
629
630 struct sockaddr_storage remote = { 0 };
631 char ipremoteport[IP_PORT_BUFLEN] = { 0 };
632 char *prp = NULL;
633 size = sizeof(remote);
634 if (getpeername(conn->fd, (struct sockaddr *) &remote, &size) == 0)
635 {
636 if (iptostring((struct sockaddr *) &remote, size, ipremoteport, IP_PORT_BUFLEN) == SASL_OK)
637 prp = ipremoteport;
638 else
639 mutt_debug(LL_DEBUG2, "SASL failed to parse remote IP address\n");
640 }
641 else
642 {
643 mutt_debug(LL_DEBUG2, "SASL failed to get remote IP address\n");
644 }
645
646 mutt_debug(LL_DEBUG2, "SASL local ip: %s, remote ip:%s\n", NONULL(plp), NONULL(prp));
647
648 int rc = sasl_client_new(conn->account.service, conn->account.host, plp, prp,
649 mutt_sasl_get_callbacks(&conn->account), 0, saslconn);
650 if (rc != SASL_OK)
651 {
652 mutt_error(_("Error allocating SASL connection"));
653 return -1;
654 }
655
656 /* Work around a casting bug in the SASL krb4 module */
657 sasl_security_properties_t secprops = { 0 };
658 secprops.max_ssf = 0x7fff;
659 secprops.maxbufsize = MUTT_SASL_MAXBUF;
660 if (sasl_setprop(*saslconn, SASL_SEC_PROPS, &secprops) != SASL_OK)
661 {
662 mutt_error(_("Error setting SASL security properties"));
663 sasl_dispose(saslconn);
664 return -1;
665 }
666
667 if (conn->ssf != 0)
668 {
669 /* I'm not sure this actually has an effect, at least with SASLv2 */
670 mutt_debug(LL_DEBUG2, "External SSF: %d\n", conn->ssf);
671 if (sasl_setprop(*saslconn, SASL_SSF_EXTERNAL, &conn->ssf) != SASL_OK)
672 {
673 mutt_error(_("Error setting SASL external security strength"));
674 sasl_dispose(saslconn);
675 return -1;
676 }
677 }
678 if (conn->account.user[0])
679 {
680 mutt_debug(LL_DEBUG2, "External authentication name: %s\n", conn->account.user);
681 if (sasl_setprop(*saslconn, SASL_AUTH_EXTERNAL, conn->account.user) != SASL_OK)
682 {
683 mutt_error(_("Error setting SASL external user name"));
684 sasl_dispose(saslconn);
685 return -1;
686 }
687 }
688
689 return 0;
690}
#define mutt_error(...)
Definition logging2.h:94
#define _(a)
Definition message.h:28
#define MUTT_SASL_MAXBUF
Maximum size for SASL protection buffer.
Definition sasl.c:115
#define IP_PORT_BUFLEN
Buffer size for "host;port" string (NI_MAXHOST + NI_MAXSERV)
Definition sasl.c:118
int mutt_sasl_start(void)
Initialise SASL library.
Definition sasl.c:272
static sasl_callback_t * mutt_sasl_get_callbacks(struct ConnAccount *cac)
Get the SASL callback functions.
Definition sasl.c:384
static int iptostring(const struct sockaddr *addr, socklen_t addrlen, char *out, unsigned int outlen)
Convert IP Address to string.
Definition sasl.c:202
#define NONULL(x)
Definition string2.h:44
const char * service
Name of the service, e.g. "imap".
Definition connaccount.h:61
unsigned int ssf
Security strength factor, in bits (see notes)
Definition connection.h:50
struct ConnAccount account
Account details: username, password, etc.
Definition connection.h:49
int fd
Socket file descriptor.
Definition connection.h:53
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_sasl_interact()

int mutt_sasl_interact ( sasl_interact_t * interaction)

Perform an SASL interaction with the user.

Parameters
interactionDetails of interaction
Return values
numSASL error code: SASL_OK or SASL_FAIL

An example interaction might be asking the user for a password.

Definition at line 699 of file sasl.c.

700{
701 int rc = SASL_OK;
702 char prompt[128] = { 0 };
703 struct Buffer *resp = buf_pool_get();
704
705 while (interaction->id != SASL_CB_LIST_END)
706 {
707 mutt_debug(LL_DEBUG2, "filling in SASL interaction %ld\n", interaction->id);
708
709 snprintf(prompt, sizeof(prompt), "%s: ", interaction->prompt);
710 buf_reset(resp);
711
712 if (!OptGui ||
713 (mw_get_field(prompt, resp, MUTT_COMP_NO_FLAGS, HC_OTHER, NULL, NULL) != 0))
714 {
715 rc = SASL_FAIL;
716 break;
717 }
718
719 interaction->len = buf_len(resp) + 1;
720 interaction->result = buf_strdup(resp);
721 interaction++;
722 }
723
724 buf_pool_release(&resp);
725 return rc;
726}
size_t buf_len(const struct Buffer *buf)
Calculate the length of a Buffer.
Definition buffer.c:491
void buf_reset(struct Buffer *buf)
Reset an existing Buffer.
Definition buffer.c:76
char * buf_strdup(const struct Buffer *buf)
Copy a Buffer's string.
Definition buffer.c:571
#define MUTT_COMP_NO_FLAGS
No flags are set.
Definition wdata.h:42
bool OptGui
(pseudo) when the gui (and curses) are started
Definition globals.c:48
int mw_get_field(const char *prompt, struct Buffer *buf, CompletionFlags complete, enum HistoryClass hclass, const struct CompleteOps *comp_api, void *cdata)
Ask the user for a string -.
Definition window.c:271
@ HC_OTHER
Miscellaneous strings.
Definition lib.h:60
struct Buffer * buf_pool_get(void)
Get a Buffer from the pool.
Definition pool.c:91
void buf_pool_release(struct Buffer **ptr)
Return a Buffer to the pool.
Definition pool.c:111
String manipulation buffer.
Definition buffer.h:36
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_sasl_setup_conn()

void mutt_sasl_setup_conn ( struct Connection * conn,
sasl_conn_t * saslconn )

Set up an SASL connection.

Parameters
connConnection to a server
saslconnSASL connection

Replace connection methods, sockdata with SASL wrappers, for protection layers. Also get ssf, as a fastpath for the read/write methods.

Definition at line 736 of file sasl.c.

737{
738 struct SaslSockData *sasldata = MUTT_MEM_MALLOC(1, struct SaslSockData);
739 /* work around sasl_getprop aliasing issues */
740 const void *tmp = NULL;
741
742 sasldata->saslconn = saslconn;
743 /* get ssf so we know whether we have to (en|de)code read/write */
744 sasl_getprop(saslconn, SASL_SSF, &tmp);
745 sasldata->ssf = tmp;
746 mutt_debug(LL_DEBUG3, "SASL protection strength: %u\n", *sasldata->ssf);
747 /* Add SASL SSF to transport SSF */
748 conn->ssf += *sasldata->ssf;
749 sasl_getprop(saslconn, SASL_MAXOUTBUF, &tmp);
750 sasldata->pbufsize = tmp;
751 mutt_debug(LL_DEBUG3, "SASL protection buffer size: %u\n", *sasldata->pbufsize);
752
753 /* clear input buffer */
754 sasldata->buf = NULL;
755 sasldata->bpos = 0;
756 sasldata->blen = 0;
757
758 /* preserve old functions */
759 sasldata->sockdata = conn->sockdata;
760 sasldata->open = conn->open;
761 sasldata->read = conn->read;
762 sasldata->write = conn->write;
763 sasldata->poll = conn->poll;
764 sasldata->close = conn->close;
765
766 /* and set up new functions */
767 conn->sockdata = sasldata;
773}
static int mutt_sasl_conn_close(struct Connection *conn)
Close SASL connection - Implements Connection::close() -.
Definition sasl.c:438
int(* close)(struct Connection *conn)
Close a socket Connection - Implements Connection::close() -.
Definition sasl.c:99
int(* open)(struct Connection *conn)
Open a socket Connection - Implements Connection::open() -.
Definition sasl.c:79
static int mutt_sasl_conn_open(struct Connection *conn)
Empty wrapper for underlying open function - Implements Connection::open() -.
Definition sasl.c:422
int(* poll)(struct Connection *conn, time_t wait_secs)
Check if any data is waiting on a socket - Implements Connection::poll() -.
Definition sasl.c:94
static int mutt_sasl_conn_poll(struct Connection *conn, time_t wait_secs)
Check if any data is waiting on a socket - Implements Connection::poll() -.
Definition sasl.c:579
static int mutt_sasl_conn_read(struct Connection *conn, char *buf, size_t count)
Read data from an SASL connection - Implements Connection::read() -.
Definition sasl.c:463
int(* read)(struct Connection *conn, char *buf, size_t count)
Read from a socket Connection - Implements Connection::read() -.
Definition sasl.c:84
static int mutt_sasl_conn_write(struct Connection *conn, const char *buf, size_t count)
Write to an SASL connection - Implements Connection::write() -.
Definition sasl.c:529
int(* write)(struct Connection *conn, const char *buf, size_t count)
Write to a socket Connection - Implements Connection::write() -.
Definition sasl.c:89
@ LL_DEBUG3
Log at debug level 3.
Definition logging2.h:47
#define MUTT_MEM_MALLOC(n, type)
Definition memory.h:53
void * sockdata
Backend-specific socket data.
Definition connection.h:55
int(* poll)(struct Connection *conn, time_t wait_secs)
Definition connection.h:105
int(* write)(struct Connection *conn, const char *buf, size_t count)
Definition connection.h:92
int(* close)(struct Connection *conn)
Definition connection.h:116
int(* open)(struct Connection *conn)
Definition connection.h:66
int(* read)(struct Connection *conn, char *buf, size_t count)
Definition connection.h:79
SASL authentication API -.
Definition sasl.c:64
void * sockdata
Underlying socket data.
Definition sasl.c:74
unsigned int blen
Size of the read buffer.
Definition sasl.c:71
unsigned int bpos
Current read position.
Definition sasl.c:72
const sasl_ssf_t * ssf
Security strength factor, in bits.
Definition sasl.c:66
const unsigned int * pbufsize
Buffer size.
Definition sasl.c:67
const char * buf
Buffer for data read from the connection.
Definition sasl.c:70
sasl_conn_t * saslconn
Raw SASL connection.
Definition sasl.c:65
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_sasl_cleanup()

void mutt_sasl_cleanup ( void )

Invoke when processing is complete.

This is a cleanup function, used to free all memory used by the library. Invoke when processing is complete.

Definition at line 781 of file sasl.c.

782{
783 /* As we never use the server-side, the silently ignore the return value */
784 sasl_client_done();
785}
+ Here is the caller graph for this function:

Variable Documentation

◆ SaslAuthenticators

const char* const SaslAuthenticators[]
static
Initial value:
= {
"ANONYMOUS", "CRAM-MD5", "DIGEST-MD5", "EXTERNAL",
"GS2-IAKERB", "GS2-KRB5", "GSS-SPNEGO", "GSSAPI",
"LOGIN", "NTLM", "OTP-MD4", "OTP-MD5",
"OTP-SHA1", "PASSDSS-3DES-1", "PLAIN", "SCRAM-SHA-1",
"SCRAM-SHA-224", "SCRAM-SHA-256", "SCRAM-SHA-384", "SCRAM-SHA-512",
"SRP",
}

Authentication methods supported by Cyrus SASL.

Definition at line 105 of file sasl.c.

105 {
106 "ANONYMOUS", "CRAM-MD5", "DIGEST-MD5", "EXTERNAL",
107 "GS2-IAKERB", "GS2-KRB5", "GSS-SPNEGO", "GSSAPI",
108 "LOGIN", "NTLM", "OTP-MD4", "OTP-MD5",
109 "OTP-SHA1", "PASSDSS-3DES-1", "PLAIN", "SCRAM-SHA-1",
110 "SCRAM-SHA-224", "SCRAM-SHA-256", "SCRAM-SHA-384", "SCRAM-SHA-512",
111 "SRP",
112};

◆ MuttSaslCallbacks

sasl_callback_t MuttSaslCallbacks[5]
static

SASL callback functions, e.g. mutt_sasl_cb_authname(), mutt_sasl_cb_pass()

Definition at line 121 of file sasl.c.

◆ SecretPtr

sasl_secret_t* SecretPtr = NULL
static

SASL secret, to store the password.

Definition at line 124 of file sasl.c.