NeoMutt  2024-03-23-147-g885fbc
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
sasl.c File Reference

SASL authentication support. More...

#include "config.h"
#include <stddef.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 "mutt.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
 
#define IP_PORT_BUFLEN   (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 []
 Authenticaion 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

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

Definition at line 118 of file sasl.c.

◆ IP_PORT_BUFLEN

#define IP_PORT_BUFLEN   (NI_MAXHOST + NI_MAXSERV)

Definition at line 123 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 136 of file sasl.c.

137{
138 for (size_t i = 0; i < mutt_array_size(SaslAuthenticators); i++)
139 {
140 const char *auth = SaslAuthenticators[i];
141 if (mutt_istr_equal(auth, authenticator))
142 return true;
143 }
144
145 return false;
146}
#define mutt_array_size(x)
Definition: memory.h:38
bool mutt_istr_equal(const char *a, const char *b)
Compare two strings, ignoring case.
Definition: string.c:721
static const char *const SaslAuthenticators[]
Authenticaion methods supported by Cyrus SASL.
Definition: sasl.c:106
+ 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 153 of file sasl.c.

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

209{
210 char hbuf[NI_MAXHOST], pbuf[NI_MAXSERV];
211 int rc;
212
213 if (!addr || !out)
214 return SASL_BADPARAM;
215
216 rc = getnameinfo(addr, addrlen, hbuf, sizeof(hbuf), pbuf, sizeof(pbuf),
217 NI_NUMERICHOST |
218#ifdef NI_WITHSCOPEID
219 NI_WITHSCOPEID |
220#endif
221 NI_NUMERICSERV);
222 if (rc != 0)
223 return getnameinfo_err(rc);
224
225 if (outlen < strlen(hbuf) + strlen(pbuf) + 2)
226 return SASL_BUFOVER;
227
228 snprintf(out, outlen, "%s;%s", hbuf, pbuf);
229
230 return SASL_OK;
231}
static int getnameinfo_err(int rc)
Convert a getaddrinfo() error code into an SASL error code.
Definition: sasl.c:153
+ 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 240 of file sasl.c.

241{
242 if (priority == SASL_LOG_NONE)
243 return SASL_OK;
244
245 int mutt_priority = 0;
246 switch (priority)
247 {
248 case SASL_LOG_TRACE:
249 case SASL_LOG_PASS:
250 mutt_priority = 5;
251 break;
252 case SASL_LOG_DEBUG:
253 case SASL_LOG_NOTE:
254 mutt_priority = 3;
255 break;
256 case SASL_LOG_FAIL:
257 case SASL_LOG_WARN:
258 mutt_priority = 2;
259 break;
260 case SASL_LOG_ERR:
261 mutt_priority = 1;
262 break;
263 default:
264 mutt_debug(LL_DEBUG1, "SASL unknown log priority: %s\n", message);
265 return SASL_OK;
266 }
267 mutt_debug(mutt_priority, "SASL: %s\n", message);
268 return SASL_OK;
269}
+ 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 277 of file sasl.c.

278{
279 static bool sasl_init = false;
280
281 static sasl_callback_t callbacks[2];
282 int rc;
283
284 if (sasl_init)
285 return SASL_OK;
286
287 /* set up default logging callback */
288 callbacks[0].id = SASL_CB_LOG;
289 callbacks[0].proc = (int (*)(void))(intptr_t) mutt_sasl_cb_log;
290 callbacks[0].context = NULL;
291
292 callbacks[1].id = SASL_CB_LIST_END;
293 callbacks[1].proc = NULL;
294 callbacks[1].context = NULL;
295
296 rc = sasl_client_init(callbacks);
297
298 if (rc != SASL_OK)
299 {
300 mutt_debug(LL_DEBUG1, "libsasl initialisation failed\n");
301 return SASL_FAIL;
302 }
303
304 sasl_init = true;
305
306 return SASL_OK;
307}
static int mutt_sasl_cb_log(void *context, int priority, const char *message)
Callback to log SASL messages.
Definition: sasl.c:240
+ 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 317 of file sasl.c.

318{
319 if (!result)
320 return SASL_FAIL;
321
322 struct ConnAccount *cac = context;
323
324 *result = NULL;
325 if (len)
326 *len = 0;
327
328 if (!cac)
329 return SASL_BADPARAM;
330
331 mutt_debug(LL_DEBUG2, "getting %s for %s:%u\n",
332 (id == SASL_CB_AUTHNAME) ? "authname" : "user", cac->host, cac->port);
333
334 if (id == SASL_CB_AUTHNAME)
335 {
336 if (mutt_account_getlogin(cac) < 0)
337 return SASL_FAIL;
338 *result = cac->login;
339 }
340 else
341 {
342 if (mutt_account_getuser(cac) < 0)
343 return SASL_FAIL;
344 *result = cac->user;
345 }
346
347 if (len)
348 *len = strlen(*result);
349
350 return SASL_OK;
351}
int mutt_account_getuser(struct ConnAccount *cac)
Retrieve username into ConnAccount, if necessary.
Definition: connaccount.c:52
int mutt_account_getlogin(struct ConnAccount *cac)
Retrieve login info into ConnAccount, if necessary.
Definition: connaccount.c:101
@ LL_DEBUG2
Log at debug level 2.
Definition: logging2.h:44
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 361 of file sasl.c.

362{
363 struct ConnAccount *cac = context;
364 int len;
365
366 if (!cac || !psecret)
367 return SASL_BADPARAM;
368
369 mutt_debug(LL_DEBUG2, "getting password for %s@%s:%u\n", cac->login, cac->host, cac->port);
370
371 if (mutt_account_getpass(cac) < 0)
372 return SASL_FAIL;
373
374 len = strlen(cac->pass);
375
376 mutt_mem_realloc(&SecretPtr, sizeof(sasl_secret_t) + len);
377 memcpy((char *) SecretPtr->data, cac->pass, (size_t) len);
378 SecretPtr->len = len;
379 *psecret = SecretPtr;
380
381 return SASL_OK;
382}
int mutt_account_getpass(struct ConnAccount *cac)
Fetch password into ConnAccount, if necessary.
Definition: connaccount.c:131
void mutt_mem_realloc(void *ptr, size_t size)
Resize a block of memory on the heap.
Definition: memory.c:114
static sasl_secret_t * SecretPtr
SASL secret, to store the password.
Definition: sasl.c:129
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 389 of file sasl.c.

390{
391 sasl_callback_t *callback = MuttSaslCallbacks;
392
393 callback->id = SASL_CB_USER;
394 callback->proc = (int (*)(void))(intptr_t) mutt_sasl_cb_authname;
395 callback->context = cac;
396 callback++;
397
398 callback->id = SASL_CB_AUTHNAME;
399 callback->proc = (int (*)(void))(intptr_t) mutt_sasl_cb_authname;
400 callback->context = cac;
401 callback++;
402
403 callback->id = SASL_CB_PASS;
404 callback->proc = (int (*)(void))(intptr_t) mutt_sasl_cb_pass;
405 callback->context = cac;
406 callback++;
407
408 callback->id = SASL_CB_GETREALM;
409 callback->proc = NULL;
410 callback->context = NULL;
411 callback++;
412
413 callback->id = SASL_CB_LIST_END;
414 callback->proc = NULL;
415 callback->context = NULL;
416
417 return MuttSaslCallbacks;
418}
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:361
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:317
static sasl_callback_t MuttSaslCallbacks[5]
SASL callback functions, e.g. mutt_sasl_cb_authname(), mutt_sasl_cb_pass()
Definition: sasl.c:126
+ 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 606 of file sasl.c.

607{
608 if (mutt_sasl_start() != SASL_OK)
609 return -1;
610
611 if (!conn->account.service)
612 {
613 mutt_error(_("Unknown SASL profile"));
614 return -1;
615 }
616
617 socklen_t size;
618
619 struct sockaddr_storage local = { 0 };
620 char iplocalport[IP_PORT_BUFLEN] = { 0 };
621 char *plp = NULL;
622 size = sizeof(local);
623 if (getsockname(conn->fd, (struct sockaddr *) &local, &size) == 0)
624 {
625 if (iptostring((struct sockaddr *) &local, size, iplocalport, IP_PORT_BUFLEN) == SASL_OK)
626 plp = iplocalport;
627 else
628 mutt_debug(LL_DEBUG2, "SASL failed to parse local IP address\n");
629 }
630 else
631 {
632 mutt_debug(LL_DEBUG2, "SASL failed to get local IP address\n");
633 }
634
635 struct sockaddr_storage remote = { 0 };
636 char ipremoteport[IP_PORT_BUFLEN] = { 0 };
637 char *prp = NULL;
638 size = sizeof(remote);
639 if (getpeername(conn->fd, (struct sockaddr *) &remote, &size) == 0)
640 {
641 if (iptostring((struct sockaddr *) &remote, size, ipremoteport, IP_PORT_BUFLEN) == SASL_OK)
642 prp = ipremoteport;
643 else
644 mutt_debug(LL_DEBUG2, "SASL failed to parse remote IP address\n");
645 }
646 else
647 {
648 mutt_debug(LL_DEBUG2, "SASL failed to get remote IP address\n");
649 }
650
651 mutt_debug(LL_DEBUG2, "SASL local ip: %s, remote ip:%s\n", NONULL(plp), NONULL(prp));
652
653 int rc = sasl_client_new(conn->account.service, conn->account.host, plp, prp,
654 mutt_sasl_get_callbacks(&conn->account), 0, saslconn);
655 if (rc != SASL_OK)
656 {
657 mutt_error(_("Error allocating SASL connection"));
658 return -1;
659 }
660
661 /* Work around a casting bug in the SASL krb4 module */
662 sasl_security_properties_t secprops = { 0 };
663 secprops.max_ssf = 0x7fff;
664 secprops.maxbufsize = MUTT_SASL_MAXBUF;
665 if (sasl_setprop(*saslconn, SASL_SEC_PROPS, &secprops) != SASL_OK)
666 {
667 mutt_error(_("Error setting SASL security properties"));
668 sasl_dispose(saslconn);
669 return -1;
670 }
671
672 if (conn->ssf != 0)
673 {
674 /* I'm not sure this actually has an effect, at least with SASLv2 */
675 mutt_debug(LL_DEBUG2, "External SSF: %d\n", conn->ssf);
676 if (sasl_setprop(*saslconn, SASL_SSF_EXTERNAL, &conn->ssf) != SASL_OK)
677 {
678 mutt_error(_("Error setting SASL external security strength"));
679 sasl_dispose(saslconn);
680 return -1;
681 }
682 }
683 if (conn->account.user[0])
684 {
685 mutt_debug(LL_DEBUG2, "External authentication name: %s\n", conn->account.user);
686 if (sasl_setprop(*saslconn, SASL_AUTH_EXTERNAL, conn->account.user) != SASL_OK)
687 {
688 mutt_error(_("Error setting SASL external user name"));
689 sasl_dispose(saslconn);
690 return -1;
691 }
692 }
693
694 return 0;
695}
#define mutt_error(...)
Definition: logging2.h:92
#define _(a)
Definition: message.h:28
#define MUTT_SASL_MAXBUF
Definition: sasl.c:118
#define IP_PORT_BUFLEN
Definition: sasl.c:123
int mutt_sasl_start(void)
Initialise SASL library.
Definition: sasl.c:277
static sasl_callback_t * mutt_sasl_get_callbacks(struct ConnAccount *cac)
Get the SASL callback functions.
Definition: sasl.c:389
static int iptostring(const struct sockaddr *addr, socklen_t addrlen, char *out, unsigned int outlen)
Convert IP Address to string.
Definition: sasl.c:207
#define NONULL(x)
Definition: string2.h:37
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 704 of file sasl.c.

705{
706 int rc = SASL_OK;
707 char prompt[128] = { 0 };
708 struct Buffer *resp = buf_pool_get();
709
710 while (interaction->id != SASL_CB_LIST_END)
711 {
712 mutt_debug(LL_DEBUG2, "filling in SASL interaction %ld\n", interaction->id);
713
714 snprintf(prompt, sizeof(prompt), "%s: ", interaction->prompt);
715 buf_reset(resp);
716
717 if (OptNoCurses ||
718 (mw_get_field(prompt, resp, MUTT_COMP_NO_FLAGS, HC_OTHER, NULL, NULL) != 0))
719 {
720 rc = SASL_FAIL;
721 break;
722 }
723
724 interaction->len = buf_len(resp) + 1;
725 interaction->result = buf_strdup(resp);
726 interaction++;
727 }
728
729 buf_pool_release(&resp);
730 return rc;
731}
size_t buf_len(const struct Buffer *buf)
Calculate the length of a Buffer.
Definition: buffer.c:490
void buf_reset(struct Buffer *buf)
Reset an existing Buffer.
Definition: buffer.c:75
char * buf_strdup(const struct Buffer *buf)
Copy a Buffer's string.
Definition: buffer.c:570
bool OptNoCurses
(pseudo) when sending in batch mode
Definition: globals.c:72
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:274
@ HC_OTHER
Miscellaneous strings.
Definition: lib.h:56
#define MUTT_COMP_NO_FLAGS
No flags are set.
Definition: mutt.h:56
struct Buffer * buf_pool_get(void)
Get a Buffer from the pool.
Definition: pool.c:81
void buf_pool_release(struct Buffer **ptr)
Return a Buffer to the pool.
Definition: pool.c:94
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 741 of file sasl.c.

742{
743 struct SaslSockData *sasldata = mutt_mem_malloc(sizeof(struct SaslSockData));
744 /* work around sasl_getprop aliasing issues */
745 const void *tmp = NULL;
746
747 sasldata->saslconn = saslconn;
748 /* get ssf so we know whether we have to (en|de)code read/write */
749 sasl_getprop(saslconn, SASL_SSF, &tmp);
750 sasldata->ssf = tmp;
751 mutt_debug(LL_DEBUG3, "SASL protection strength: %u\n", *sasldata->ssf);
752 /* Add SASL SSF to transport SSF */
753 conn->ssf += *sasldata->ssf;
754 sasl_getprop(saslconn, SASL_MAXOUTBUF, &tmp);
755 sasldata->pbufsize = tmp;
756 mutt_debug(LL_DEBUG3, "SASL protection buffer size: %u\n", *sasldata->pbufsize);
757
758 /* clear input buffer */
759 sasldata->buf = NULL;
760 sasldata->bpos = 0;
761 sasldata->blen = 0;
762
763 /* preserve old functions */
764 sasldata->sockdata = conn->sockdata;
765 sasldata->open = conn->open;
766 sasldata->read = conn->read;
767 sasldata->write = conn->write;
768 sasldata->poll = conn->poll;
769 sasldata->close = conn->close;
770
771 /* and set up new functions */
772 conn->sockdata = sasldata;
778}
static int mutt_sasl_conn_close(struct Connection *conn)
Close SASL connection - Implements Connection::close() -.
Definition: sasl.c:443
int(* close)(struct Connection *conn)
Close a socket Connection - Implements Connection::close() -.
Definition: sasl.c:100
int(* open)(struct Connection *conn)
Open a socket Connection - Implements Connection::open() -.
Definition: sasl.c:80
static int mutt_sasl_conn_open(struct Connection *conn)
Empty wrapper for underlying open function - Implements Connection::open() -.
Definition: sasl.c:427
int(* poll)(struct Connection *conn, time_t wait_secs)
Check if any data is waiting on a socket - Implements Connection::poll() -.
Definition: sasl.c:95
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:584
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:468
int(* read)(struct Connection *conn, char *buf, size_t count)
Read from a socket Connection - Implements Connection::read() -.
Definition: sasl.c:85
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:534
int(* write)(struct Connection *conn, const char *buf, size_t count)
Write to a socket Connection - Implements Connection::write() -.
Definition: sasl.c:90
@ LL_DEBUG3
Log at debug level 3.
Definition: logging2.h:45
void * mutt_mem_malloc(size_t size)
Allocate memory on the heap.
Definition: memory.c:90
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:65
void * sockdata
Underlying socket data.
Definition: sasl.c:75
unsigned int blen
Size of the read buffer.
Definition: sasl.c:72
unsigned int bpos
Current read position.
Definition: sasl.c:73
const sasl_ssf_t * ssf
Definition: sasl.c:67
const unsigned int * pbufsize
Definition: sasl.c:68
const char * buf
Buffer for data read from the connection.
Definition: sasl.c:71
sasl_conn_t * saslconn
Definition: sasl.c:66
+ 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 786 of file sasl.c.

787{
788 /* As we never use the server-side, the silently ignore the return value */
789 sasl_client_done();
790}
+ 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",
}

Authenticaion methods supported by Cyrus SASL.

Definition at line 106 of file sasl.c.

◆ MuttSaslCallbacks

sasl_callback_t MuttSaslCallbacks[5]
static

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

Definition at line 126 of file sasl.c.

◆ SecretPtr

sasl_secret_t* SecretPtr = NULL
static

SASL secret, to store the password.

Definition at line 129 of file sasl.c.