NeoMutt  2021-02-05-666-ge300cd
Teaching an old dog new tricks
DOXYGEN
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...
 

Functions

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...
 

Variables

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

Detailed Description

IMAP authenticator multiplexor.

Authors
  • 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 http://www.gnu.org/licenses/.

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.

Parameters
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 imap_authenticators.

Definition at line 87 of file auth.c.

88 {
89  for (size_t i = 0; i < mutt_array_size(imap_authenticators); i++)
90  {
91  const struct ImapAuth *auth = &imap_authenticators[i];
92  if (auth->method && mutt_istr_equal(auth->method, authenticator))
93  return true;
94  }
95 
96  return false;
97 }
const char * method
Name of authentication method supported, NULL means variable.
Definition: auth.c:52
#define mutt_array_size(x)
Definition: memory.h:33
static const struct ImapAuth imap_authenticators[]
Accepted authentication methods.
Definition: auth.c:59
bool mutt_istr_equal(const char *a, const char *b)
Compare two strings, ignoring case.
Definition: string.c:916
IMAP authentication multiplexor.
Definition: auth.c:42
+ 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.

Parameters
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 107 of file auth.c.

108 {
109  int rc = IMAP_AUTH_FAILURE;
110 
111  const struct Slist *c_imap_authenticators =
112  cs_subset_slist(NeoMutt->sub, "imap_authenticators");
113  if (c_imap_authenticators && (c_imap_authenticators->count > 0))
114  {
115  mutt_debug(LL_DEBUG2, "Trying user-defined imap_authenticators\n");
116 
117  /* Try user-specified list of authentication methods */
118  struct ListNode *np = NULL;
119  STAILQ_FOREACH(np, &c_imap_authenticators->head, entries)
120  {
121  mutt_debug(LL_DEBUG2, "Trying method %s\n", np->data);
122 
123  for (size_t i = 0; i < mutt_array_size(imap_authenticators); i++)
124  {
125  const struct ImapAuth *auth = &imap_authenticators[i];
126  if (!auth->method || mutt_istr_equal(auth->method, np->data))
127  {
128  rc = auth->authenticate(adata, np->data);
129  if (rc == IMAP_AUTH_SUCCESS)
130  {
131  return rc;
132  }
133  }
134  }
135  }
136  }
137  else
138  {
139  /* Fall back to default: any authenticator */
140  mutt_debug(LL_DEBUG2, "Trying pre-defined imap_authenticators\n");
141 
142  for (size_t i = 0; i < mutt_array_size(imap_authenticators); i++)
143  {
144  rc = imap_authenticators[i].authenticate(adata, NULL);
145  if (rc == IMAP_AUTH_SUCCESS)
146  return rc;
147  }
148  }
149 
150  mutt_error(_("No authenticators available or wrong credentials"));
151  return rc;
152 }
const char * method
Name of authentication method supported, NULL means variable.
Definition: auth.c:52
#define mutt_error(...)
Definition: logging.h:88
#define _(a)
Definition: message.h:28
String list.
Definition: slist.h:46
Container for Accounts, Notifications.
Definition: neomutt.h:36
#define mutt_array_size(x)
Definition: memory.h:33
Log at debug level 2.
Definition: logging.h:41
struct ListHead head
Definition: slist.h:48
Authentication failed.
Definition: auth.h:40
static const struct ImapAuth imap_authenticators[]
Accepted authentication methods.
Definition: auth.c:59
bool mutt_istr_equal(const char *a, const char *b)
Compare two strings, ignoring case.
Definition: string.c:916
size_t count
Definition: slist.h:49
enum ImapAuthRes(* authenticate)(struct ImapAccountData *adata, const char *method)
Authenticate an IMAP connection.
Definition: auth.c:50
#define STAILQ_FOREACH(var, head, field)
Definition: queue.h:352
#define mutt_debug(LEVEL,...)
Definition: logging.h:85
IMAP authentication multiplexor.
Definition: auth.c:42
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
char * data
String.
Definition: list.h:36
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:39
A List node for strings.
Definition: list.h:34
Authentication successful.
Definition: auth.h:39
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Variable Documentation

◆ imap_authenticators

const struct ImapAuth imap_authenticators[]
static
Initial value:
= {
{ imap_auth_oauth, "oauthbearer" },
{ imap_auth_plain, "plain" },
{ imap_auth_sasl, NULL },
{ imap_auth_gss, "gssapi" },
{ imap_auth_login, "login" },
}
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_plain(struct ImapAccountData *adata, const char *method)
SASL PLAIN support - Implements ImapAuth::authenticate()
Definition: auth_plain.c:42
enum ImapAuthRes imap_auth_sasl(struct ImapAccountData *adata, const char *method)
Default authenticator if available - Implements ImapAuth::authenticate()
Definition: auth_sasl.c:46
enum ImapAuthRes imap_auth_oauth(struct ImapAccountData *adata, const char *method)
Authenticate an IMAP connection using OAUTHBEARER - Implements ImapAuth::authenticate() ...
Definition: auth_oauth.c:45
enum ImapAuthRes imap_auth_gss(struct ImapAccountData *adata, const char *method)
GSS Authentication support - Implements ImapAuth::authenticate()
Definition: auth_gss.c:105

Accepted authentication methods.

Definition at line 59 of file auth.c.