NeoMutt  2022-04-29-247-gc6aae8
Teaching an old dog new tricks
auth.c File Reference

IMAP authenticator multiplexor. More...

#include "config.h"
#include <string.h>
#include "private.h"
#include "mutt/lib.h"
#include "config/lib.h"
#include "core/lib.h"
#include "auth.h"
+ Include dependency graph for auth.c:

Go to the source code of this file.

Data Structures

struct  ImapAuth
 IMAP authentication multiplexor. More...


bool imap_auth_is_valid (const char *authenticator)
 Check if string is a valid imap authentication method. More...
int imap_authenticate (struct ImapAccountData *adata)
 Authenticate to an IMAP server. More...


static const struct ImapAuth ImapAuthenticators []
 Accepted authentication methods. More...

Detailed Description

IMAP authenticator multiplexor.

  • Michael R. Elkins
  • Brandon Long
  • Brendan Cully

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

Definition in file auth.c.

Function Documentation

◆ imap_auth_is_valid()

bool imap_auth_is_valid ( const char *  authenticator)

Check if string is a valid imap authentication method.

authenticatorAuthenticator string to check
Return values
trueArgument is a valid auth method

Validate whether an input string is an accepted imap authentication method as defined by ImapAuthenticators.

Definition at line 90 of file auth.c.

92 for (size_t i = 0; i < mutt_array_size(ImapAuthenticators); i++)
93 {
94 const struct ImapAuth *auth = &ImapAuthenticators[i];
95 if (auth->method && mutt_istr_equal(auth->method, authenticator))
96 return true;
97 }
99 return false;
static const struct ImapAuth ImapAuthenticators[]
Accepted authentication methods.
Definition: auth.c:59
#define mutt_array_size(x)
Definition: memory.h:36
bool mutt_istr_equal(const char *a, const char *b)
Compare two strings, ignoring case.
Definition: string.c:819
IMAP authentication multiplexor.
Definition: auth.c:43
const char * method
Name of authentication method supported, NULL means variable.
Definition: auth.c:52
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ imap_authenticate()

int imap_authenticate ( struct ImapAccountData adata)

Authenticate to an IMAP server.

adataImap Account data
Return values
numResult, e.g. IMAP_AUTH_SUCCESS

Attempt to authenticate using either user-specified authentication method if specified, or any.

Definition at line 110 of file auth.c.

112 int rc = IMAP_AUTH_FAILURE;
114 const struct Slist *c_imap_authenticators = cs_subset_slist(NeoMutt->sub, "imap_authenticators");
115 if (c_imap_authenticators && (c_imap_authenticators->count > 0))
116 {
117 mutt_debug(LL_DEBUG2, "Trying user-defined imap_authenticators\n");
119 /* Try user-specified list of authentication methods */
120 struct ListNode *np = NULL;
121 STAILQ_FOREACH(np, &c_imap_authenticators->head, entries)
122 {
123 mutt_debug(LL_DEBUG2, "Trying method %s\n", np->data);
125 for (size_t i = 0; i < mutt_array_size(ImapAuthenticators); i++)
126 {
127 const struct ImapAuth *auth = &ImapAuthenticators[i];
128 if (!auth->method || mutt_istr_equal(auth->method, np->data))
129 {
130 rc = auth->authenticate(adata, np->data);
131 if (rc == IMAP_AUTH_SUCCESS)
132 {
133 return rc;
134 }
135 }
136 }
137 }
138 }
139 else
140 {
141 /* Fall back to default: any authenticator */
142 mutt_debug(LL_DEBUG2, "Trying pre-defined imap_authenticators\n");
144 for (size_t i = 0; i < mutt_array_size(ImapAuthenticators); i++)
145 {
146 rc = ImapAuthenticators[i].authenticate(adata, NULL);
147 if (rc == IMAP_AUTH_SUCCESS)
148 return rc;
149 }
150 }
152 mutt_error(_("No authenticators available or wrong credentials"));
153 return rc;
Authentication failed.
Definition: auth.h:40
Authentication successful.
Definition: auth.h:39
const struct Slist * cs_subset_slist(const struct ConfigSubset *sub, const char *name)
Get a string-list config item by name.
Definition: helpers.c:268
#define mutt_error(...)
Definition: logging.h:87
#define mutt_debug(LEVEL,...)
Definition: logging.h:84
Log at debug level 2.
Definition: logging.h:41
#define _(a)
Definition: message.h:28
#define STAILQ_FOREACH(var, head, field)
Definition: queue.h:352
enum ImapAuthRes(* authenticate)(struct ImapAccountData *adata, const char *method)
Authenticate an IMAP connection.
Definition: auth.c:50
A List node for strings.
Definition: list.h:35
char * data
Definition: list.h:36
Container for Accounts, Notifications.
Definition: neomutt.h:37
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:39
String list.
Definition: slist.h:47
struct ListHead head
List containing values.
Definition: slist.h:48
size_t count
Number of values in list.
Definition: slist.h:49
+ Here is the caller graph for this function:

Variable Documentation

◆ ImapAuthenticators

const struct ImapAuth ImapAuthenticators[]
Initial value:
= {
{ imap_auth_oauth, "oauthbearer" },
{ imap_auth_xoauth2, "xoauth2" },
{ imap_auth_plain, "plain" },
{ imap_auth_anon, "anonymous" },
{ imap_auth_gss, "gssapi" },
{ imap_auth_cram_md5, "cram-md5" },
{ imap_auth_login, "login" },
enum ImapAuthRes imap_auth_gss(struct ImapAccountData *adata, const char *method)
GSS Authentication support - Implements ImapAuth::authenticate()
Definition: auth_gss.c:104
enum ImapAuthRes imap_auth_login(struct ImapAccountData *adata, const char *method)
Plain LOGIN support - Implements ImapAuth::authenticate()
Definition: auth_login.c:44
enum ImapAuthRes imap_auth_cram_md5(struct ImapAccountData *adata, const char *method)
Authenticate using CRAM-MD5 - Implements ImapAuth::authenticate()
Definition: auth_cram.c:94
enum ImapAuthRes imap_auth_xoauth2(struct ImapAccountData *adata, const char *method)
Authenticate an IMAP connection using XOAUTH2 - Implements ImapAuth::authenticate()
Definition: auth_oauth.c:120
enum ImapAuthRes imap_auth_plain(struct ImapAccountData *adata, const char *method)
SASL PLAIN support - Implements ImapAuth::authenticate()
Definition: auth_plain.c:41
enum ImapAuthRes imap_auth_anon(struct ImapAccountData *adata, const char *method)
Authenticate anonymously - Implements ImapAuth::authenticate()
Definition: auth_anon.c:41
enum ImapAuthRes imap_auth_oauth(struct ImapAccountData *adata, const char *method)
Authenticate an IMAP connection using OAUTHBEARER - Implements ImapAuth::authenticate()
Definition: auth_oauth.c:112

Accepted authentication methods.

Definition at line 59 of file auth.c.