NeoMutt  2020-11-20
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 "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
boolTrue if argument is a valid auth method

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

Definition at line 85 of file auth.c.

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

106 {
107  int rc = IMAP_AUTH_FAILURE;
108 
110  {
111  mutt_debug(LL_DEBUG2, "Trying user-defined imap_authenticators\n");
112 
113  /* Try user-specified list of authentication methods */
114  struct ListNode *np = NULL;
116  {
117  mutt_debug(LL_DEBUG2, "Trying method %s\n", np->data);
118 
119  for (size_t i = 0; i < mutt_array_size(imap_authenticators); i++)
120  {
121  const struct ImapAuth *auth = &imap_authenticators[i];
122  if (!auth->method || mutt_istr_equal(auth->method, np->data))
123  {
124  rc = auth->authenticate(adata, np->data);
125  if (rc == IMAP_AUTH_SUCCESS)
126  {
127  return rc;
128  }
129  }
130  }
131  }
132  }
133  else
134  {
135  /* Fall back to default: any authenticator */
136  mutt_debug(LL_DEBUG2, "Trying pre-defined imap_authenticators\n");
137 
138  for (size_t i = 0; i < mutt_array_size(imap_authenticators); i++)
139  {
140  rc = imap_authenticators[i].authenticate(adata, NULL);
141  if (rc == IMAP_AUTH_SUCCESS)
142  return rc;
143  }
144  }
145 
146  mutt_error(_("No authenticators available or wrong credentials"));
147  return rc;
148 }
const char * method
Name of authentication method supported, NULL means variable.
Definition: auth.c:50
struct Slist * C_ImapAuthenticators
Config: (imap) List of allowed IMAP authentication methods.
Definition: config.c:39
#define _(a)
Definition: message.h:28
#define mutt_array_size(x)
Definition: memory.h:33
Log at debug level 2.
Definition: logging.h:41
struct ListHead head
Definition: slist.h:47
Authentication failed.
Definition: auth.h:39
static const struct ImapAuth imap_authenticators[]
Accepted authentication methods.
Definition: auth.c:57
bool mutt_istr_equal(const char *a, const char *b)
Compare two strings, ignoring case.
Definition: string.c:883
size_t count
Definition: slist.h:48
enum ImapAuthRes(* authenticate)(struct ImapAccountData *adata, const char *method)
Authenticate an IMAP connection.
Definition: auth.c:48
#define STAILQ_FOREACH(var, head, field)
Definition: queue.h:349
IMAP authentication multiplexor.
Definition: auth.c:40
char * data
String.
Definition: list.h:36
#define mutt_error(...)
Definition: logging.h:84
#define mutt_debug(LEVEL,...)
Definition: logging.h:81
A List node for strings.
Definition: list.h:34
Authentication successful.
Definition: auth.h:38
+ 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:41
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_sasl(struct ImapAccountData *adata, const char *method)
Default authenticator if available - Implements ImapAuth::authenticate()
Definition: auth_sasl.c:45
enum ImapAuthRes imap_auth_oauth(struct ImapAccountData *adata, const char *method)
Authenticate an IMAP connection using OAUTHBEARER - Implements ImapAuth::authenticate() ...
Definition: auth_oauth.c:43
enum ImapAuthRes imap_auth_gss(struct ImapAccountData *adata, const char *method)
GSS Authentication support - Implements ImapAuth::authenticate()
Definition: auth_gss.c:103

Accepted authentication methods.

Definition at line 57 of file auth.c.